@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.
Files changed (90) hide show
  1. package/README.md +82 -0
  2. package/docs/consumer-capability-matrix.md +374 -0
  3. package/package.json +17 -10
  4. package/scripts/generate-codex-protocol.ts +711 -0
  5. package/src/agents/agent-operation.ts +8 -0
  6. package/src/agents/agent-provider.ts +3 -0
  7. package/src/agents/agent-run.ts +14 -2
  8. package/src/agents/agent-runtime-error.ts +28 -0
  9. package/src/agents/agent-session-events.ts +33 -0
  10. package/src/agents/agent-tool-runner.ts +12 -11
  11. package/src/agents/agent-tool.ts +12 -4
  12. package/src/agents/author-context.ts +1 -1
  13. package/src/agents/claude/claude-auth.ts +40 -0
  14. package/src/agents/claude/claude-browser-turn-metadata.ts +70 -0
  15. package/src/agents/claude/claude-code-process.ts +98 -0
  16. package/src/agents/claude/claude-command-mapper.ts +63 -3
  17. package/src/agents/claude/claude-desktop.ts +55 -0
  18. package/src/agents/claude/claude-event-mapper.ts +876 -124
  19. package/src/agents/claude/claude-file-change.ts +128 -0
  20. package/src/agents/claude/claude-provider.ts +344 -29
  21. package/src/agents/claude/claude-run.ts +922 -91
  22. package/src/agents/claude/claude-selected-repository-instructions.ts +91 -0
  23. package/src/agents/claude/claude-skill-catalog.ts +75 -0
  24. package/src/agents/claude/claude-steered-notifications.ts +180 -0
  25. package/src/agents/claude/claude-tool-mapper.ts +81 -2
  26. package/src/agents/claude/claude-workspace-skills.ts +87 -0
  27. package/src/agents/claude/index.ts +2 -0
  28. package/src/agents/codex/codex-auth-mapper.ts +27 -0
  29. package/src/agents/codex/codex-auth.ts +19 -0
  30. package/src/agents/codex/codex-browser-auth-broker.ts +320 -0
  31. package/src/agents/codex/codex-browser-auth-status.ts +55 -0
  32. package/src/agents/codex/codex-command-mapper.ts +38 -3
  33. package/src/agents/codex/codex-event-mapper.ts +375 -64
  34. package/src/agents/codex/codex-json-rpc-client.ts +66 -21
  35. package/src/agents/codex/codex-provider.ts +118 -236
  36. package/src/agents/codex/codex-run-auth.ts +113 -0
  37. package/src/agents/codex/codex-run.ts +428 -48
  38. package/src/agents/codex/codex-tool-mapper.ts +2 -2
  39. package/src/agents/codex/codex.errors.ts +8 -0
  40. package/src/agents/codex/generated/meta.gen.ts +144 -6
  41. package/src/agents/codex/generated/namespaces.gen.ts +92 -3
  42. package/src/agents/codex/generated/schema.gen.ts +24698 -15638
  43. package/src/agents/codex/lazy-codex-run-auth.ts +47 -0
  44. package/src/agents/index.ts +5 -0
  45. package/src/agents/input-attachment-preparation.ts +13 -0
  46. package/src/agents/mcp-tool-content.ts +82 -0
  47. package/src/agents/model-rebinding-run.ts +14 -3
  48. package/src/agents/selected-repository-instructions.ts +202 -0
  49. package/src/agents/session-context.ts +41 -0
  50. package/src/agents/subscription-token-refresh.ts +73 -0
  51. package/src/agents/user-input-request.ts +19 -20
  52. package/src/errors/index.ts +1 -1
  53. package/src/errors/validation-error.ts +6 -0
  54. package/src/protocol/agent-catalog.ts +159 -0
  55. package/src/protocol/agent-command.ts +54 -7
  56. package/src/protocol/agent-content.ts +36 -16
  57. package/src/protocol/agent-event.ts +210 -73
  58. package/src/protocol/agent-identity.ts +29 -0
  59. package/src/protocol/agent-json.ts +122 -8
  60. package/src/protocol/agent-metadata.ts +2 -2
  61. package/src/protocol/agent-model.ts +13 -1
  62. package/src/protocol/agent-notification.ts +110 -0
  63. package/src/protocol/agent-presentation.ts +71 -20
  64. package/src/protocol/agent-tool.ts +66 -10
  65. package/src/protocol/agent-usage.ts +4 -1
  66. package/src/protocol/agent-user-input.ts +4 -4
  67. package/src/protocol/agent-work.ts +12 -10
  68. package/src/protocol/index.ts +2 -0
  69. package/src/protocol/rejected-keys.ts +11 -0
  70. package/src/provenance.gen.ts +3 -3
  71. package/src/steps/contract.ts +4 -1
  72. package/src/steps/projector.ts +17 -1
  73. package/src/supervisor/agent-provider-factory.ts +60 -5
  74. package/src/supervisor/bootstrap-binder.ts +3 -2
  75. package/src/supervisor/index.ts +1 -1
  76. package/src/supervisor/persistence/supervisor-store.ts +22 -8
  77. package/src/supervisor/runtime-handler.ts +30 -2
  78. package/src/supervisor-protocol/agent-event-wrapper.ts +30 -0
  79. package/src/supervisor-protocol/bootstrap.ts +4 -1
  80. package/src/supervisor-protocol/command-body.ts +4 -1
  81. package/src/supervisor-protocol/envelopes/supervisor-to-control-plane.ts +1 -0
  82. package/src/testing/in-memory-runtime-control-plane.ts +118 -12
  83. package/src/testing/index.ts +1 -1
  84. package/src/worker-runtime-client/command-pump.ts +85 -10
  85. package/src/worker-runtime-client/connection-attempt.ts +95 -20
  86. package/src/worker-runtime-client/frame-processor.ts +242 -58
  87. package/src/worker-runtime-client/index.ts +8 -2
  88. package/src/worker-runtime-client/ports.ts +34 -2
  89. package/src/worker-runtime-client/rpc-request-manager.ts +152 -107
  90. 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
- readLines(this.child.stdout, (line) => {
134
- if (this.stopped)
135
- return
136
- try {
137
- const parsed = JSON.parse(line) as CodexJsonRpcMessage
138
- this.handleMessage(parsed, options.onMessage)
139
- }
140
- catch (error) {
141
- if (!this.stopped)
142
- options.onInvalidLine(line, error)
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(this.child.stderr, (line) => {
146
- if (!this.stopped)
147
- options.onStderr(line)
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
- await endWritable(this.child.stdin)
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: NodeJS.ReadableStream, onLine: (line: string) => void): void {
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()