@meistrari/agent-core 0.2.0-experimental.0 → 0.2.0-experimental.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +82 -0
- package/docs/consumer-capability-matrix.md +374 -0
- package/package.json +17 -10
- package/scripts/generate-codex-protocol.ts +711 -0
- package/src/agents/agent-operation.ts +8 -0
- package/src/agents/agent-provider.ts +3 -0
- package/src/agents/agent-run.ts +14 -2
- package/src/agents/agent-runtime-error.ts +28 -0
- package/src/agents/agent-session-events.ts +33 -0
- package/src/agents/agent-tool-runner.ts +12 -11
- package/src/agents/agent-tool.ts +12 -4
- package/src/agents/author-context.ts +1 -1
- package/src/agents/claude/claude-auth.ts +40 -0
- package/src/agents/claude/claude-browser-turn-metadata.ts +70 -0
- package/src/agents/claude/claude-code-process.ts +98 -0
- package/src/agents/claude/claude-command-mapper.ts +63 -3
- package/src/agents/claude/claude-desktop.ts +55 -0
- package/src/agents/claude/claude-event-mapper.ts +876 -124
- package/src/agents/claude/claude-file-change.ts +128 -0
- package/src/agents/claude/claude-provider.ts +344 -29
- package/src/agents/claude/claude-run.ts +922 -91
- package/src/agents/claude/claude-selected-repository-instructions.ts +91 -0
- package/src/agents/claude/claude-skill-catalog.ts +75 -0
- package/src/agents/claude/claude-steered-notifications.ts +180 -0
- package/src/agents/claude/claude-tool-mapper.ts +81 -2
- package/src/agents/claude/claude-workspace-skills.ts +87 -0
- package/src/agents/claude/index.ts +2 -0
- package/src/agents/codex/codex-auth-mapper.ts +27 -0
- package/src/agents/codex/codex-auth.ts +19 -0
- package/src/agents/codex/codex-browser-auth-broker.ts +320 -0
- package/src/agents/codex/codex-browser-auth-status.ts +55 -0
- package/src/agents/codex/codex-command-mapper.ts +38 -3
- package/src/agents/codex/codex-event-mapper.ts +375 -64
- package/src/agents/codex/codex-json-rpc-client.ts +66 -21
- package/src/agents/codex/codex-provider.ts +118 -236
- package/src/agents/codex/codex-run-auth.ts +113 -0
- package/src/agents/codex/codex-run.ts +428 -48
- package/src/agents/codex/codex-tool-mapper.ts +2 -2
- package/src/agents/codex/codex.errors.ts +8 -0
- package/src/agents/codex/generated/meta.gen.ts +144 -6
- package/src/agents/codex/generated/namespaces.gen.ts +92 -3
- package/src/agents/codex/generated/schema.gen.ts +24698 -15638
- package/src/agents/codex/lazy-codex-run-auth.ts +47 -0
- package/src/agents/index.ts +5 -0
- package/src/agents/input-attachment-preparation.ts +13 -0
- package/src/agents/mcp-tool-content.ts +82 -0
- package/src/agents/model-rebinding-run.ts +14 -3
- package/src/agents/selected-repository-instructions.ts +202 -0
- package/src/agents/session-context.ts +41 -0
- package/src/agents/subscription-token-refresh.ts +73 -0
- package/src/agents/user-input-request.ts +19 -20
- package/src/errors/index.ts +1 -1
- package/src/errors/validation-error.ts +6 -0
- package/src/protocol/agent-catalog.ts +159 -0
- package/src/protocol/agent-command.ts +54 -7
- package/src/protocol/agent-content.ts +36 -16
- package/src/protocol/agent-event.ts +210 -73
- package/src/protocol/agent-identity.ts +29 -0
- package/src/protocol/agent-json.ts +122 -8
- package/src/protocol/agent-metadata.ts +2 -2
- package/src/protocol/agent-model.ts +13 -1
- package/src/protocol/agent-notification.ts +110 -0
- package/src/protocol/agent-presentation.ts +71 -20
- package/src/protocol/agent-tool.ts +66 -10
- package/src/protocol/agent-usage.ts +4 -1
- package/src/protocol/agent-user-input.ts +4 -4
- package/src/protocol/agent-work.ts +12 -10
- package/src/protocol/index.ts +2 -0
- package/src/protocol/rejected-keys.ts +11 -0
- package/src/provenance.gen.ts +3 -3
- package/src/steps/contract.ts +4 -1
- package/src/steps/projector.ts +17 -1
- package/src/supervisor/agent-provider-factory.ts +60 -5
- package/src/supervisor/bootstrap-binder.ts +3 -2
- package/src/supervisor/index.ts +1 -1
- package/src/supervisor/persistence/supervisor-store.ts +22 -8
- package/src/supervisor/runtime-handler.ts +30 -2
- package/src/supervisor-protocol/agent-event-wrapper.ts +30 -0
- package/src/supervisor-protocol/bootstrap.ts +4 -1
- package/src/supervisor-protocol/command-body.ts +4 -1
- package/src/supervisor-protocol/envelopes/supervisor-to-control-plane.ts +1 -0
- package/src/testing/in-memory-runtime-control-plane.ts +118 -12
- package/src/testing/index.ts +1 -1
- package/src/worker-runtime-client/command-pump.ts +85 -10
- package/src/worker-runtime-client/connection-attempt.ts +95 -20
- package/src/worker-runtime-client/frame-processor.ts +242 -58
- package/src/worker-runtime-client/index.ts +8 -2
- package/src/worker-runtime-client/ports.ts +34 -2
- package/src/worker-runtime-client/rpc-request-manager.ts +152 -107
- package/src/worker-runtime-client/sandbox-connection-runtime.ts +72 -35
|
@@ -10,6 +10,7 @@ import type {
|
|
|
10
10
|
ServerRequestMethod,
|
|
11
11
|
ServerRequestParamsByMethod,
|
|
12
12
|
} from './codex-protocol'
|
|
13
|
+
import { Buffer } from 'node:buffer'
|
|
13
14
|
import { spawn } from 'node:child_process'
|
|
14
15
|
import { createInterface } from 'node:readline'
|
|
15
16
|
import { CodexJsonRpcResponseError, CodexJsonRpcTransportClosedError } from './codex.errors'
|
|
@@ -74,6 +75,7 @@ export class CodexJsonRpcClient {
|
|
|
74
75
|
onMessage: (message: CodexJsonRpcMessage) => void
|
|
75
76
|
onInvalidLine: (line: string, error: unknown) => void
|
|
76
77
|
onStderr: (line: string) => void
|
|
78
|
+
maxLineBytes?: number
|
|
77
79
|
},
|
|
78
80
|
) {
|
|
79
81
|
this.child = spawn(executable, ['app-server', '--listen', 'stdio://', ...(options.configOverrides ?? []).flatMap(value => ['-c', value])], {
|
|
@@ -130,21 +132,32 @@ export class CodexJsonRpcClient {
|
|
|
130
132
|
this.pending.clear()
|
|
131
133
|
})
|
|
132
134
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
135
|
+
const lineLimit = options.maxLineBytes === undefined
|
|
136
|
+
? undefined
|
|
137
|
+
: { maxBytes: options.maxLineBytes, onOversize: () => options.onInvalidLine('', new Error('Codex transport line exceeded limit.')) }
|
|
138
|
+
readLines({
|
|
139
|
+
stream: this.child.stdout,
|
|
140
|
+
limit: lineLimit,
|
|
141
|
+
onLine: (line) => {
|
|
142
|
+
if (this.stopped)
|
|
143
|
+
return
|
|
144
|
+
try {
|
|
145
|
+
const parsed = JSON.parse(line) as CodexJsonRpcMessage
|
|
146
|
+
this.handleMessage(parsed, options.onMessage)
|
|
147
|
+
}
|
|
148
|
+
catch (error) {
|
|
149
|
+
if (!this.stopped)
|
|
150
|
+
options.onInvalidLine(line, error)
|
|
151
|
+
}
|
|
152
|
+
},
|
|
144
153
|
})
|
|
145
|
-
readLines(
|
|
146
|
-
|
|
147
|
-
|
|
154
|
+
readLines({
|
|
155
|
+
stream: this.child.stderr,
|
|
156
|
+
limit: lineLimit,
|
|
157
|
+
onLine: (line) => {
|
|
158
|
+
if (!this.stopped)
|
|
159
|
+
options.onStderr(line)
|
|
160
|
+
},
|
|
148
161
|
})
|
|
149
162
|
}
|
|
150
163
|
|
|
@@ -217,7 +230,8 @@ export class CodexJsonRpcClient {
|
|
|
217
230
|
|
|
218
231
|
async closeInputAndStop(): Promise<void> {
|
|
219
232
|
if (this.stopped) {
|
|
220
|
-
await this.closed
|
|
233
|
+
if (!await waitForClosed(this.closed, PROCESS_SHUTDOWN_GRACE_MS))
|
|
234
|
+
await terminateChild(this.child, this.closed)
|
|
221
235
|
return
|
|
222
236
|
}
|
|
223
237
|
this.stopped = true
|
|
@@ -225,7 +239,9 @@ export class CodexJsonRpcClient {
|
|
|
225
239
|
waiter.reject(closedClientError(waiter.method, 'possible_write'))
|
|
226
240
|
}
|
|
227
241
|
this.pending.clear()
|
|
228
|
-
|
|
242
|
+
// EOF/drain and process exit share one grace window. Never wait separately for a
|
|
243
|
+
// buffered stdin write: a child that stops reading must still reach signal escalation.
|
|
244
|
+
this.child.stdin.end()
|
|
229
245
|
if (await waitForClosed(this.closed, PROCESS_SHUTDOWN_GRACE_MS))
|
|
230
246
|
return
|
|
231
247
|
await terminateChild(this.child, this.closed)
|
|
@@ -272,10 +288,6 @@ export class CodexJsonRpcClient {
|
|
|
272
288
|
}
|
|
273
289
|
}
|
|
274
290
|
|
|
275
|
-
async function endWritable(stream: NodeJS.WritableStream): Promise<void> {
|
|
276
|
-
await new Promise<void>(resolve => stream.end(resolve))
|
|
277
|
-
}
|
|
278
|
-
|
|
279
291
|
async function terminateChild(child: ChildProcessWithoutNullStreams, closed: Promise<void>): Promise<void> {
|
|
280
292
|
if (child.exitCode !== null || child.signalCode !== null) {
|
|
281
293
|
await closed
|
|
@@ -317,7 +329,40 @@ function closedClientError(method: ClientRequestMethod, writeState: 'before_writ
|
|
|
317
329
|
return new CodexJsonRpcTransportClosedError({ method, writeState, message: 'Codex app-server client is closed.' })
|
|
318
330
|
}
|
|
319
331
|
|
|
320
|
-
function readLines(stream
|
|
332
|
+
function readLines({ stream, onLine, limit }: {
|
|
333
|
+
stream: NodeJS.ReadableStream
|
|
334
|
+
onLine: (line: string) => void
|
|
335
|
+
limit: { maxBytes: number, onOversize: () => void } | undefined
|
|
336
|
+
}): void {
|
|
337
|
+
if (limit) {
|
|
338
|
+
let buffer = Buffer.alloc(0)
|
|
339
|
+
let failed = false
|
|
340
|
+
stream.on('data', (chunk: Buffer) => {
|
|
341
|
+
if (failed)
|
|
342
|
+
return
|
|
343
|
+
let start = 0
|
|
344
|
+
for (let index = 0; index <= chunk.length; index += 1) {
|
|
345
|
+
if (index !== chunk.length && chunk[index] !== 10)
|
|
346
|
+
continue
|
|
347
|
+
const part = chunk.subarray(start, index)
|
|
348
|
+
if (buffer.length + part.length > limit.maxBytes) {
|
|
349
|
+
failed = true
|
|
350
|
+
buffer = Buffer.alloc(0)
|
|
351
|
+
limit.onOversize()
|
|
352
|
+
return
|
|
353
|
+
}
|
|
354
|
+
buffer = Buffer.concat([buffer, part])
|
|
355
|
+
if (index !== chunk.length) {
|
|
356
|
+
const line = buffer.toString('utf8').trim()
|
|
357
|
+
buffer = Buffer.alloc(0)
|
|
358
|
+
if (line)
|
|
359
|
+
onLine(line)
|
|
360
|
+
}
|
|
361
|
+
start = index + 1
|
|
362
|
+
}
|
|
363
|
+
})
|
|
364
|
+
return
|
|
365
|
+
}
|
|
321
366
|
const rl = createInterface({ input: stream })
|
|
322
367
|
rl.on('line', (line) => {
|
|
323
368
|
const trimmed = line.trim()
|