Skip to content

Commit e1739f6

Browse files
committed
fix(pty): replace moment with native Date timestamps
Remove runtime moment usage to avoid CommonJS default-export interop failures in ESM mode. Update session typing, health payload, tests, and dependency manifests; closes #29.
1 parent c3d80ef commit e1739f6

9 files changed

Lines changed: 13 additions & 22 deletions

File tree

.opencode/opencode.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
22
"$schema": "https://opencode.ai/config.json",
3-
"instructions": ["README.md"]
3+
"instructions": ["README.md"],
4+
"plugin": ["../index.ts"]
45
}

bun.lock

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@
8383
"@opencode-ai/plugin": "^1.3.13",
8484
"@opencode-ai/sdk": "^1.3.13",
8585
"bun-pty": "^0.4.8",
86-
"moment": "^2.30.1",
8786
"open": "^11.0.0"
8887
}
8988
}

src/plugin/pty/session-lifecycle.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { spawn, type IPty } from 'bun-pty'
22
import { RingBuffer } from './buffer.ts'
33
import type { PTYSession, PTYSessionInfo, SpawnOptions } from './types.ts'
44
import { DEFAULT_TERMINAL_COLS, DEFAULT_TERMINAL_ROWS } from '../constants.ts'
5-
import moment from 'moment'
65

76
const SESSION_ID_BYTE_LENGTH = 4
87

@@ -34,7 +33,7 @@ export class SessionLifecycleManager {
3433
env: opts.env,
3534
status: 'running',
3635
pid: 0, // will be set after spawn
37-
createdAt: moment(),
36+
createdAt: new Date(),
3837
parentSessionId: opts.parentSessionId,
3938
parentAgent: opts.parentAgent,
4039
notifyOnExit: opts.notifyOnExit ?? false,
@@ -154,7 +153,7 @@ export class SessionLifecycleManager {
154153
exitCode: session.exitCode,
155154
exitSignal: session.exitSignal,
156155
pid: session.pid,
157-
createdAt: session.createdAt.toISOString(true),
156+
createdAt: session.createdAt.toISOString(),
158157
lineCount: session.buffer.length,
159158
}
160159
}

src/plugin/pty/types.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type { IPty } from 'bun-pty'
22
import type { RingBuffer } from './buffer.ts'
3-
import type moment from 'moment'
43

54
export type PTYStatus = 'running' | 'exited' | 'killing' | 'killed'
65

@@ -16,7 +15,7 @@ export interface PTYSession {
1615
exitCode?: number
1716
exitSignal?: number | string
1817
pid: number
19-
createdAt: moment.Moment
18+
createdAt: Date
2019
parentSessionId: string
2120
parentAgent?: string
2221
notifyOnExit: boolean

src/web/server/handlers/health.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import moment from 'moment'
21
import { manager } from '../../../plugin/pty/manager.ts'
32
import { JsonResponse } from './responses.ts'
43
import type { HealthResponse } from '../../shared/types.ts'
@@ -13,7 +12,7 @@ export function handleHealth(server: Bun.Server<undefined>) {
1312

1413
const healthResponse: HealthResponse = {
1514
status: 'healthy',
16-
timestamp: moment().toISOString(true),
15+
timestamp: new Date().toISOString(),
1716
uptime: process.uptime(),
1817
sessions: {
1918
total: totalSessions,

test/notification-manager.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { describe, expect, it, mock } from 'bun:test'
22
import type { OpencodeClient } from '@opencode-ai/sdk'
3-
import moment from 'moment'
43
import { RingBuffer } from '../src/plugin/pty/buffer.ts'
54
import { NotificationManager } from '../src/plugin/pty/notification-manager.ts'
65
import type { PTYSession } from '../src/plugin/pty/types.ts'
@@ -26,7 +25,7 @@ function createSession(overrides: Partial<PTYSession> = {}): PTYSession {
2625
workdir: '/tmp',
2726
status: 'running',
2827
pid: 12345,
29-
createdAt: moment(),
28+
createdAt: new Date(),
3029
parentSessionId: 'parent-session-id',
3130
parentAgent: 'agent-two',
3231
notifyOnExit: true,

test/pty-tools.test.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { ptyRead } from '../src/plugin/pty/tools/read.ts'
44
import { ptyList } from '../src/plugin/pty/tools/list.ts'
55
import { RingBuffer } from '../src/plugin/pty/buffer.ts'
66
import { manager } from '../src/plugin/pty/manager.ts'
7-
import moment from 'moment'
87

98
describe('PTY Tools', () => {
109
afterAll(() => {
@@ -20,7 +19,7 @@ describe('PTY Tools', () => {
2019
workdir: opts.workdir || '/tmp',
2120
pid: 12345,
2221
status: 'running',
23-
createdAt: moment().toISOString(true),
22+
createdAt: new Date().toISOString(),
2423
lineCount: 0,
2524
}))
2625
})
@@ -116,7 +115,7 @@ describe('PTY Tools', () => {
116115
workdir: '/tmp',
117116
status: 'running',
118117
pid: 12345,
119-
createdAt: moment().toISOString(true),
118+
createdAt: new Date().toISOString(),
120119
lineCount: 2,
121120
})
122121
spyOn(manager, 'read').mockReturnValue({
@@ -228,7 +227,7 @@ describe('PTY Tools', () => {
228227
pid: 12345,
229228
lineCount: 10,
230229
workdir: '/tmp',
231-
createdAt: moment('2023-01-01T00:00:00Z').toISOString(true),
230+
createdAt: new Date('2023-01-01T00:00:00Z').toISOString(),
232231
},
233232
]
234233
spyOn(manager, 'list').mockReturnValue(mockSessions)

test/types.test.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
type WSMessageServerSessionList,
77
} from '../src/web/shared/types.ts'
88
import type { PTYSessionInfo } from '../src/plugin/pty/types.ts'
9-
import moment from 'moment'
109

1110
describe('Web Types', () => {
1211
describe('WSMessage', () => {
@@ -29,7 +28,7 @@ describe('Web Types', () => {
2928
status: 'running',
3029
pid: 1234,
3130
lineCount: 5,
32-
createdAt: moment().toISOString(true),
31+
createdAt: new Date().toISOString(),
3332
args: ['hello'],
3433
workdir: '/home/user',
3534
},
@@ -65,7 +64,7 @@ describe('Web Types', () => {
6564
exitCode: 0,
6665
pid: 1234,
6766
lineCount: 2,
68-
createdAt: moment().toISOString(true),
67+
createdAt: new Date().toISOString(),
6968
args: ['Hello, World!'],
7069
workdir: '/home/user',
7170
}
@@ -88,7 +87,7 @@ describe('Web Types', () => {
8887
status: 'running',
8988
pid: 5678,
9089
lineCount: 0,
91-
createdAt: moment('2026-01-21T10:00:00.000Z').toISOString(true),
90+
createdAt: new Date('2026-01-21T10:00:00.000Z').toISOString(),
9291
args: ['Hello, World!'],
9392
workdir: '/home/user',
9493
}

0 commit comments

Comments
 (0)