stitchkit 0.130.1 → 0.131.0
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/CHANGELOG.md +42 -0
- package/dist/agent-executor/acp/v1-connect.d.ts +40 -26
- package/dist/agent-executor/acp/v1-connect.d.ts.map +1 -1
- package/dist/agent-executor/acp/v1-driver.d.ts +10 -4
- package/dist/agent-executor/acp/v1-driver.d.ts.map +1 -1
- package/dist/agent-executor/acp/v1-handlers.d.ts +6 -2
- package/dist/agent-executor/acp/v1-handlers.d.ts.map +1 -1
- package/dist/agent-executor/acp/v1-probe.d.ts +38 -0
- package/dist/agent-executor/acp/v1-probe.d.ts.map +1 -0
- package/dist/agent-executor/acp/v1-protocol.d.ts +15 -0
- package/dist/agent-executor/acp/v1-protocol.d.ts.map +1 -1
- package/dist/agent-executor/acp/v1-session.d.ts +9 -7
- package/dist/agent-executor/acp/v1-session.d.ts.map +1 -1
- package/dist/agent-executor/claude/cli-driver.d.ts +7 -7
- package/dist/agent-executor/claude/cli-driver.d.ts.map +1 -1
- package/dist/agent-executor/claude/limits.d.ts +6 -4
- package/dist/agent-executor/claude/limits.d.ts.map +1 -1
- package/dist/agent-executor/claude/session.d.ts +3 -3
- package/dist/agent-executor/claude/session.d.ts.map +1 -1
- package/dist/agent-executor/claude-sdk/controls.d.ts +1 -0
- package/dist/agent-executor/claude-sdk/controls.d.ts.map +1 -1
- package/dist/agent-executor/claude-sdk/driver.d.ts +51 -50
- package/dist/agent-executor/claude-sdk/driver.d.ts.map +1 -1
- package/dist/agent-executor/claude-sdk/probe.d.ts +3 -3
- package/dist/agent-executor/claude-sdk/probe.d.ts.map +1 -1
- package/dist/agent-executor/claude-sdk/query-loop.d.ts +2 -1
- package/dist/agent-executor/claude-sdk/query-loop.d.ts.map +1 -1
- package/dist/agent-executor/codex/classify.d.ts.map +1 -1
- package/dist/agent-executor/codex/connect.d.ts +7 -7
- package/dist/agent-executor/codex/connect.d.ts.map +1 -1
- package/dist/agent-executor/codex/control-client.d.ts +86 -99
- package/dist/agent-executor/codex/control-client.d.ts.map +1 -1
- package/dist/agent-executor/codex/control-read-methods.d.ts +7 -0
- package/dist/agent-executor/codex/control-read-methods.d.ts.map +1 -0
- package/dist/agent-executor/codex/driver.d.ts +29 -28
- package/dist/agent-executor/codex/driver.d.ts.map +1 -1
- package/dist/agent-executor/codex/event-routing.d.ts +14 -0
- package/dist/agent-executor/codex/event-routing.d.ts.map +1 -0
- package/dist/agent-executor/codex/handlers.d.ts +2 -2
- package/dist/agent-executor/codex/handlers.d.ts.map +1 -1
- package/dist/agent-executor/codex/limits.d.ts +9 -3
- package/dist/agent-executor/codex/limits.d.ts.map +1 -1
- package/dist/agent-executor/codex/notifications.d.ts +183 -0
- package/dist/agent-executor/codex/notifications.d.ts.map +1 -0
- package/dist/agent-executor/codex/pagination.d.ts +54 -0
- package/dist/agent-executor/codex/pagination.d.ts.map +1 -0
- package/dist/agent-executor/codex/protocol.d.ts +586 -148
- package/dist/agent-executor/codex/protocol.d.ts.map +1 -1
- package/dist/agent-executor/codex/request-answers.d.ts +4 -2
- package/dist/agent-executor/codex/request-answers.d.ts.map +1 -1
- package/dist/agent-executor/codex/responses.d.ts +855 -0
- package/dist/agent-executor/codex/responses.d.ts.map +1 -0
- package/dist/agent-executor/codex/session-bind.d.ts +410 -0
- package/dist/agent-executor/codex/session-bind.d.ts.map +1 -0
- package/dist/agent-executor/codex/session-controls.d.ts +19 -190
- package/dist/agent-executor/codex/session-controls.d.ts.map +1 -1
- package/dist/agent-executor/codex/session-types.d.ts +190 -0
- package/dist/agent-executor/codex/session-types.d.ts.map +1 -0
- package/dist/agent-executor/codex/session.d.ts +1 -1
- package/dist/agent-executor/codex/session.d.ts.map +1 -1
- package/dist/agent-executor/codex/shared-server.d.ts +4 -4
- package/dist/agent-executor/codex/shared-server.d.ts.map +1 -1
- package/dist/agent-executor/codex/shared-thread.d.ts +5 -5
- package/dist/agent-executor/codex/shared-thread.d.ts.map +1 -1
- package/dist/agent-executor/codex/thread-controls.d.ts +45 -36
- package/dist/agent-executor/codex/thread-controls.d.ts.map +1 -1
- package/dist/agent-executor/codex/thread-list-query.d.ts +5 -0
- package/dist/agent-executor/codex/thread-list-query.d.ts.map +1 -0
- package/dist/agent-executor/codex/thread-open.d.ts +20 -20
- package/dist/agent-executor/codex/thread-open.d.ts.map +1 -1
- package/dist/agent-executor/codex/turn-input.d.ts +4 -3
- package/dist/agent-executor/codex/turn-input.d.ts.map +1 -1
- package/dist/agent-executor/codex/unix-socket-target.d.ts +12 -3
- package/dist/agent-executor/codex/unix-socket-target.d.ts.map +1 -1
- package/dist/agent-executor/codex/ws-frame.d.ts +4 -1
- package/dist/agent-executor/codex/ws-frame.d.ts.map +1 -1
- package/dist/agent-executor/contract.d.ts +3 -1
- package/dist/agent-executor/contract.d.ts.map +1 -1
- package/dist/agent-executor/engine-process.d.ts +4 -4
- package/dist/agent-executor/engine-process.d.ts.map +1 -1
- package/dist/agent-executor/engine.d.ts +3 -3
- package/dist/agent-executor/engine.d.ts.map +1 -1
- package/dist/agent-executor/handoff.d.ts.map +1 -1
- package/dist/agent-executor/hello.d.ts +7 -0
- package/dist/agent-executor/hello.d.ts.map +1 -1
- package/dist/agent-executor/json-rpc-peer.d.ts +9 -4
- package/dist/agent-executor/json-rpc-peer.d.ts.map +1 -1
- package/dist/agent-executor/leases.d.ts +1 -1
- package/dist/agent-executor/leases.d.ts.map +1 -1
- package/dist/agent-executor/plan-limits.d.ts +12 -1
- package/dist/agent-executor/plan-limits.d.ts.map +1 -1
- package/dist/agent-executor/profile.d.ts +7 -0
- package/dist/agent-executor/profile.d.ts.map +1 -1
- package/dist/agent-executor/session-primitives.d.ts +8 -0
- package/dist/agent-executor/session-primitives.d.ts.map +1 -1
- package/dist/agent-executor/testing/consumer-stubs.d.ts +45 -0
- package/dist/agent-executor/testing/consumer-stubs.d.ts.map +1 -0
- package/dist/agent-executor/testing/fake-claude-sdk-query.d.ts +88 -0
- package/dist/agent-executor/testing/fake-claude-sdk-query.d.ts.map +1 -0
- package/dist/agent-executor/testing/fake-codex-app-server.d.ts +56 -0
- package/dist/agent-executor/testing/fake-codex-app-server.d.ts.map +1 -0
- package/dist/agent-executor/testing/fixtures.d.ts +26 -0
- package/dist/agent-executor/testing/fixtures.d.ts.map +1 -0
- package/dist/agent-executor/testing/replay-driver.d.ts +8 -8
- package/dist/agent-executor/testing/replay-driver.d.ts.map +1 -1
- package/dist/agent-executor/testing/replay-runner.d.ts +3 -2
- package/dist/agent-executor/testing/replay-runner.d.ts.map +1 -1
- package/dist/agent-executor/testing/replay-transcript.d.ts +5 -3
- package/dist/agent-executor/testing/replay-transcript.d.ts.map +1 -1
- package/dist/agent-runtime/branch-observations.d.ts +19 -19
- package/dist/agent-runtime/sql-rows.d.ts +10 -10
- package/dist/agent-runtime/store-conformance-lifecycle.d.ts +20 -20
- package/dist/agent-runtime/store-conformance-support.d.ts +10 -10
- package/dist/agent-runtime/terminal-commit.d.ts +10 -10
- package/dist/entrypoints/agent-executor/acp.d.ts +2 -1
- package/dist/entrypoints/agent-executor/acp.d.ts.map +1 -1
- package/dist/entrypoints/agent-executor/acp.js +284 -82
- package/dist/entrypoints/agent-executor/claude-sdk.d.ts +4 -0
- package/dist/entrypoints/agent-executor/claude-sdk.d.ts.map +1 -1
- package/dist/entrypoints/agent-executor/claude-sdk.js +58 -32
- package/dist/entrypoints/agent-executor/claude.d.ts +2 -2
- package/dist/entrypoints/agent-executor/claude.d.ts.map +1 -1
- package/dist/entrypoints/agent-executor/claude.js +25 -20
- package/dist/entrypoints/agent-executor/codex.d.ts +9 -5
- package/dist/entrypoints/agent-executor/codex.d.ts.map +1 -1
- package/dist/entrypoints/agent-executor/codex.js +1724 -1557
- package/dist/entrypoints/agent-executor/testing.d.ts +4 -0
- package/dist/entrypoints/agent-executor/testing.d.ts.map +1 -1
- package/dist/entrypoints/agent-executor/testing.js +880 -18
- package/dist/entrypoints/agent-executor.d.ts +3 -3
- package/dist/entrypoints/agent-executor.d.ts.map +1 -1
- package/dist/entrypoints/agent-executor.js +42 -8
- package/dist/entrypoints/process.js +3 -3
- package/dist/{index-jrn3prgm.js → index-32vaajec.js} +29 -4
- package/dist/{index-p1qmpq0p.js → index-64e9p079.js} +92 -56
- package/dist/{index-dbp6xemn.js → index-g2d9kws8.js} +199 -3
- package/dist/index-gm9yz82v.js +56 -0
- package/dist/index-j15dhkda.js +749 -0
- package/dist/{index-1q0n6zek.js → index-kwsr7j5k.js} +84 -44
- package/llms/agent-executor-acp.txt +5 -5
- package/llms/agent-executor-claude-sdk.txt +3 -1
- package/llms/agent-executor-claude.txt +2 -2
- package/llms/agent-executor-codex.txt +11 -8
- package/llms/agent-executor-testing.txt +5 -1
- package/llms/agent-executor.txt +4 -4
- package/llms/stitchkit.txt +75 -74
- package/llms/{upgrading-0.128.0-0.130.0.txt → upgrading-0.128.0-0.131.0.txt} +56 -3
- package/llms/upgrading.txt +1 -1
- package/llms-full.txt +158 -95
- package/llms.txt +8 -8
- package/package.json +3 -3
- package/dist/index-2s8sy57y.js +0 -229
|
@@ -7,38 +7,64 @@ import {
|
|
|
7
7
|
ExecutorThreadDispositionSchema2,
|
|
8
8
|
ExecutorStartupPhaseSchema2,
|
|
9
9
|
ExecutorErrorKindSchema2,
|
|
10
|
+
ExecutorDeltaSchema2,
|
|
10
11
|
InteractionReplySchema2,
|
|
11
12
|
ExecutorEngineSchema2,
|
|
12
13
|
ExecutorDriverCapabilitiesSchema2,
|
|
13
14
|
PlanWindowSchema2,
|
|
14
|
-
engineProfile
|
|
15
|
-
|
|
15
|
+
engineProfile,
|
|
16
|
+
createTurnDeltaChannel,
|
|
17
|
+
offerTurnDelta,
|
|
18
|
+
sessionAbort,
|
|
19
|
+
emitStartupPhase
|
|
20
|
+
} from "../../index-g2d9kws8.js";
|
|
21
|
+
import {
|
|
22
|
+
JsonRpcValueSchema2,
|
|
23
|
+
JsonRpcError2,
|
|
24
|
+
JSON_RPC_METHOD_NOT_FOUND2
|
|
25
|
+
} from "../../index-kwsr7j5k.js";
|
|
26
|
+
import {
|
|
27
|
+
CodexThreadSchema2,
|
|
28
|
+
validateCodexUnixSocketPath,
|
|
29
|
+
encodeUnmaskedWsFrame,
|
|
30
|
+
createWsFrameDecoder
|
|
31
|
+
} from "../../index-j15dhkda.js";
|
|
32
|
+
import"../../index-6kec3b14.js";
|
|
33
|
+
import"../../index-673drwkn.js";
|
|
34
|
+
import"../../index-vmbxj75t.js";
|
|
16
35
|
import"../../index-09f7w2qq.js";
|
|
17
36
|
import"../../index-v59pxmf1.js";
|
|
18
37
|
import"../../index-qa2jjb65.js";
|
|
19
|
-
import"../../index-6kec3b14.js";
|
|
20
38
|
import {
|
|
21
|
-
createTurnDeltaChannel,
|
|
22
|
-
offerTurnDelta,
|
|
23
|
-
sessionAbort,
|
|
24
|
-
emitStartupPhase,
|
|
25
39
|
holdEngineRequest,
|
|
26
40
|
answerEngineRequest,
|
|
27
41
|
drainEngineRequests,
|
|
28
42
|
endEngineTurn,
|
|
29
43
|
loseEngineTurn
|
|
30
|
-
} from "../../index-
|
|
31
|
-
import"../../index-pzhqydxb.js";
|
|
44
|
+
} from "../../index-gm9yz82v.js";
|
|
32
45
|
import {
|
|
33
46
|
dispatchTurn2,
|
|
34
47
|
projectExecutorDeltas2
|
|
35
48
|
} from "../../index-x5ayy5bn.js";
|
|
36
49
|
import {
|
|
37
50
|
mergeRateLimitEvent2
|
|
38
|
-
} from "../../index-
|
|
51
|
+
} from "../../index-32vaajec.js";
|
|
52
|
+
import"../../index-pzhqydxb.js";
|
|
53
|
+
import {
|
|
54
|
+
unlinkUnixSocketIfMatching,
|
|
55
|
+
assertPrivateUnixSocketDirectory,
|
|
56
|
+
bindUnixSocket2
|
|
57
|
+
} from "../../index-hab790s6.js";
|
|
39
58
|
import {
|
|
40
59
|
assertPositiveSafeInteger
|
|
41
60
|
} from "../../index-gr0kxymw.js";
|
|
61
|
+
import {
|
|
62
|
+
isRecord
|
|
63
|
+
} from "../../index-ps3djm8d.js";
|
|
64
|
+
import {
|
|
65
|
+
untilAborted,
|
|
66
|
+
linkAbortSignals
|
|
67
|
+
} from "../../index-rptj3qnc.js";
|
|
42
68
|
|
|
43
69
|
// src/agent-executor/testing/conformance.ts
|
|
44
70
|
import { randomUUID } from "node:crypto";
|
|
@@ -352,6 +378,244 @@ var checkInterrupts = async (turn, scenarios) => {
|
|
|
352
378
|
}
|
|
353
379
|
});
|
|
354
380
|
};
|
|
381
|
+
// src/agent-executor/testing/fixtures.ts
|
|
382
|
+
function makeExecutorDelta(delta) {
|
|
383
|
+
return ExecutorDeltaSchema2.parse({
|
|
384
|
+
...delta,
|
|
385
|
+
turnId: delta.turnId ?? "turn-1",
|
|
386
|
+
itemId: delta.itemId ?? "item-1",
|
|
387
|
+
raw: delta.raw ?? { source: "test", type: delta.type }
|
|
388
|
+
});
|
|
389
|
+
}
|
|
390
|
+
function makeCodexNotificationEvent(method, params, overrides) {
|
|
391
|
+
if (typeof method !== "string" || method.trim().length === 0) {
|
|
392
|
+
throw new TypeError("[stitchkit] makeCodexNotificationEvent: method must be a non-empty string");
|
|
393
|
+
}
|
|
394
|
+
const validatedParams = params !== undefined ? JsonRpcValueSchema2.parse(params) : undefined;
|
|
395
|
+
const validatedDeltas = (overrides?.deltas ?? []).map((delta) => ExecutorDeltaSchema2.parse(delta));
|
|
396
|
+
return {
|
|
397
|
+
method,
|
|
398
|
+
params: validatedParams,
|
|
399
|
+
duringActiveTurn: overrides?.duringActiveTurn ?? false,
|
|
400
|
+
deltas: validatedDeltas
|
|
401
|
+
};
|
|
402
|
+
}
|
|
403
|
+
function makeCodexThreadFixture(overrides) {
|
|
404
|
+
const base = {
|
|
405
|
+
id: "thread-1",
|
|
406
|
+
cwd: "/workspace",
|
|
407
|
+
preview: "",
|
|
408
|
+
status: { type: "idle" },
|
|
409
|
+
canAcceptDirectInput: true,
|
|
410
|
+
turns: []
|
|
411
|
+
};
|
|
412
|
+
if (overrides !== undefined) {
|
|
413
|
+
for (const [key, value] of Object.entries(overrides)) {
|
|
414
|
+
if (value !== undefined)
|
|
415
|
+
base[key] = value;
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
return CodexThreadSchema2.parse(base);
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
// src/agent-executor/testing/consumer-stubs.ts
|
|
422
|
+
var DEFAULT_CODEX_USER_AGENT = "codex/0.171.0";
|
|
423
|
+
var DEFAULT_SHARED_SERVER_CAPABILITIES = {
|
|
424
|
+
runtimePolicyEnforcement: "native",
|
|
425
|
+
sessionApproval: true,
|
|
426
|
+
interruptOnDeny: true,
|
|
427
|
+
updatedToolInput: false,
|
|
428
|
+
structuredInput: true,
|
|
429
|
+
steer: true,
|
|
430
|
+
fork: true,
|
|
431
|
+
revert: true,
|
|
432
|
+
compact: true,
|
|
433
|
+
injectItems: true,
|
|
434
|
+
backgroundWorkOutlivesTurn: false,
|
|
435
|
+
multiThreadPerProcess: true,
|
|
436
|
+
images: false,
|
|
437
|
+
planLimits: "pull"
|
|
438
|
+
};
|
|
439
|
+
function unexpected(stubName, methodName) {
|
|
440
|
+
return async () => {
|
|
441
|
+
throw new Error(`Unexpected call to ${stubName}.${methodName}()`);
|
|
442
|
+
};
|
|
443
|
+
}
|
|
444
|
+
var noopClose = async () => {
|
|
445
|
+
return;
|
|
446
|
+
};
|
|
447
|
+
function pickOptional(overrides, key, value, fallback) {
|
|
448
|
+
return overrides !== undefined && key in overrides ? value : fallback;
|
|
449
|
+
}
|
|
450
|
+
function toDeltaAsyncIterable(deltas) {
|
|
451
|
+
if (deltas === undefined) {
|
|
452
|
+
return {
|
|
453
|
+
async* [Symbol.asyncIterator]() {}
|
|
454
|
+
};
|
|
455
|
+
}
|
|
456
|
+
if (Symbol.asyncIterator in deltas) {
|
|
457
|
+
return deltas;
|
|
458
|
+
}
|
|
459
|
+
const items = [...deltas];
|
|
460
|
+
return {
|
|
461
|
+
async* [Symbol.asyncIterator]() {
|
|
462
|
+
for (const delta of items)
|
|
463
|
+
yield delta;
|
|
464
|
+
}
|
|
465
|
+
};
|
|
466
|
+
}
|
|
467
|
+
function buildCodexControlMethods(stubName, overrides) {
|
|
468
|
+
return {
|
|
469
|
+
readConfig: overrides?.readConfig ?? unexpected(stubName, "readConfig"),
|
|
470
|
+
readThread: overrides?.readThread ?? unexpected(stubName, "readThread"),
|
|
471
|
+
listCollaborationModes: overrides?.listCollaborationModes ?? unexpected(stubName, "listCollaborationModes"),
|
|
472
|
+
listTurns: overrides?.listTurns ?? unexpected(stubName, "listTurns"),
|
|
473
|
+
listItems: overrides?.listItems ?? unexpected(stubName, "listItems"),
|
|
474
|
+
listMcpServerStatus: overrides?.listMcpServerStatus ?? unexpected(stubName, "listMcpServerStatus"),
|
|
475
|
+
listSkills: overrides?.listSkills ?? unexpected(stubName, "listSkills"),
|
|
476
|
+
listModels: overrides?.listModels ?? unexpected(stubName, "listModels"),
|
|
477
|
+
readAccount: overrides?.readAccount ?? unexpected(stubName, "readAccount"),
|
|
478
|
+
readRateLimits: overrides?.readRateLimits ?? unexpected(stubName, "readRateLimits"),
|
|
479
|
+
revertThread: overrides?.revertThread ?? unexpected(stubName, "revertThread"),
|
|
480
|
+
injectItems: overrides?.injectItems ?? unexpected(stubName, "injectItems"),
|
|
481
|
+
unsubscribeThread: overrides?.unsubscribeThread ?? unexpected(stubName, "unsubscribeThread"),
|
|
482
|
+
listThreads: overrides?.listThreads ?? unexpected(stubName, "listThreads"),
|
|
483
|
+
listLoadedThreads: overrides?.listLoadedThreads ?? unexpected(stubName, "listLoadedThreads"),
|
|
484
|
+
archiveThread: overrides?.archiveThread ?? unexpected(stubName, "archiveThread"),
|
|
485
|
+
unarchiveThread: overrides?.unarchiveThread ?? unexpected(stubName, "unarchiveThread"),
|
|
486
|
+
updateThreadMetadata: overrides?.updateThreadMetadata ?? unexpected(stubName, "updateThreadMetadata"),
|
|
487
|
+
setThreadName: overrides?.setThreadName ?? unexpected(stubName, "setThreadName"),
|
|
488
|
+
resumeThread: overrides?.resumeThread ?? unexpected(stubName, "resumeThread"),
|
|
489
|
+
startThreadTurn: overrides?.startThreadTurn ?? unexpected(stubName, "startThreadTurn"),
|
|
490
|
+
interruptTurn: overrides?.interruptTurn ?? unexpected(stubName, "interruptTurn"),
|
|
491
|
+
steerTurn: overrides?.steerTurn ?? unexpected(stubName, "steerTurn"),
|
|
492
|
+
compactThread: overrides?.compactThread ?? unexpected(stubName, "compactThread")
|
|
493
|
+
};
|
|
494
|
+
}
|
|
495
|
+
function createStubCodexControlClient(overrides) {
|
|
496
|
+
return buildCodexControlMethods("StubCodexControlClient", overrides);
|
|
497
|
+
}
|
|
498
|
+
function createStubCodexControlConnection(overrides) {
|
|
499
|
+
const stubName = "StubCodexControlConnection";
|
|
500
|
+
return {
|
|
501
|
+
providerPid: pickOptional(overrides, "providerPid", overrides?.providerPid, undefined),
|
|
502
|
+
userAgent: pickOptional(overrides, "userAgent", overrides?.userAgent, DEFAULT_CODEX_USER_AGENT),
|
|
503
|
+
...buildCodexControlMethods(stubName, overrides),
|
|
504
|
+
respond: overrides?.respond ?? unexpected(stubName, "respond"),
|
|
505
|
+
close: overrides?.close ?? noopClose
|
|
506
|
+
};
|
|
507
|
+
}
|
|
508
|
+
function createStubCodexSession(overrides) {
|
|
509
|
+
const stubName = "StubCodexSession";
|
|
510
|
+
const nativeThreadId = overrides?.nativeThreadId ?? "stub-thread-1";
|
|
511
|
+
return {
|
|
512
|
+
nativeThreadId,
|
|
513
|
+
providerPid: pickOptional(overrides, "providerPid", overrides?.providerPid, undefined),
|
|
514
|
+
userAgent: pickOptional(overrides, "userAgent", overrides?.userAgent, DEFAULT_CODEX_USER_AGENT),
|
|
515
|
+
threadContext: overrides?.threadContext ?? {
|
|
516
|
+
thread: makeCodexThreadFixture({ id: nativeThreadId })
|
|
517
|
+
},
|
|
518
|
+
startTurn: overrides?.startTurn ?? unexpected(stubName, "startTurn"),
|
|
519
|
+
respond: overrides?.respond ?? unexpected(stubName, "respond"),
|
|
520
|
+
readConfig: overrides?.readConfig ?? unexpected(stubName, "readConfig"),
|
|
521
|
+
readThread: overrides?.readThread ?? unexpected(stubName, "readThread"),
|
|
522
|
+
listCollaborationModes: overrides?.listCollaborationModes ?? unexpected(stubName, "listCollaborationModes"),
|
|
523
|
+
listTurns: overrides?.listTurns ?? unexpected(stubName, "listTurns"),
|
|
524
|
+
listItems: overrides?.listItems ?? unexpected(stubName, "listItems"),
|
|
525
|
+
listMcpServerStatus: overrides?.listMcpServerStatus ?? unexpected(stubName, "listMcpServerStatus"),
|
|
526
|
+
listSkills: overrides?.listSkills ?? unexpected(stubName, "listSkills"),
|
|
527
|
+
listModels: overrides?.listModels ?? unexpected(stubName, "listModels"),
|
|
528
|
+
readAccount: overrides?.readAccount ?? unexpected(stubName, "readAccount"),
|
|
529
|
+
readRateLimits: overrides?.readRateLimits ?? unexpected(stubName, "readRateLimits"),
|
|
530
|
+
revertThread: overrides?.revertThread ?? unexpected(stubName, "revertThread"),
|
|
531
|
+
injectItems: overrides?.injectItems ?? unexpected(stubName, "injectItems"),
|
|
532
|
+
unsubscribeThread: overrides?.unsubscribeThread ?? unexpected(stubName, "unsubscribeThread"),
|
|
533
|
+
listThreads: overrides?.listThreads ?? unexpected(stubName, "listThreads"),
|
|
534
|
+
listLoadedThreads: overrides?.listLoadedThreads ?? unexpected(stubName, "listLoadedThreads"),
|
|
535
|
+
archiveThread: overrides?.archiveThread ?? unexpected(stubName, "archiveThread"),
|
|
536
|
+
unarchiveThread: overrides?.unarchiveThread ?? unexpected(stubName, "unarchiveThread"),
|
|
537
|
+
updateThreadMetadata: overrides?.updateThreadMetadata ?? unexpected(stubName, "updateThreadMetadata"),
|
|
538
|
+
setThreadName: overrides?.setThreadName ?? unexpected(stubName, "setThreadName"),
|
|
539
|
+
resumeThread: overrides?.resumeThread ?? unexpected(stubName, "resumeThread"),
|
|
540
|
+
startThreadTurn: overrides?.startThreadTurn ?? unexpected(stubName, "startThreadTurn"),
|
|
541
|
+
interruptTurn: overrides?.interruptTurn ?? unexpected(stubName, "interruptTurn"),
|
|
542
|
+
steerTurn: overrides?.steerTurn ?? unexpected(stubName, "steerTurn"),
|
|
543
|
+
forkThread: overrides?.forkThread ?? unexpected(stubName, "forkThread"),
|
|
544
|
+
compactThread: overrides?.compactThread ?? unexpected(stubName, "compactThread"),
|
|
545
|
+
close: overrides?.close ?? noopClose
|
|
546
|
+
};
|
|
547
|
+
}
|
|
548
|
+
function createStubCodexSharedServer(overrides) {
|
|
549
|
+
const stubName = "StubCodexSharedServer";
|
|
550
|
+
return {
|
|
551
|
+
providerPid: pickOptional(overrides, "providerPid", overrides?.providerPid, undefined),
|
|
552
|
+
userAgent: pickOptional(overrides, "userAgent", overrides?.userAgent, DEFAULT_CODEX_USER_AGENT),
|
|
553
|
+
maxThreads: overrides?.maxThreads ?? 32,
|
|
554
|
+
activeThreadCount: overrides?.activeThreadCount ?? 0,
|
|
555
|
+
capabilities: overrides?.capabilities ?? DEFAULT_SHARED_SERVER_CAPABILITIES,
|
|
556
|
+
...buildCodexControlMethods(stubName, overrides),
|
|
557
|
+
openThread: overrides?.openThread ?? unexpected(stubName, "openThread"),
|
|
558
|
+
close: overrides?.close ?? noopClose
|
|
559
|
+
};
|
|
560
|
+
}
|
|
561
|
+
function createStubAgentEngineTurn(overrides) {
|
|
562
|
+
const stubName = "StubAgentEngineTurn";
|
|
563
|
+
return {
|
|
564
|
+
deltas: toDeltaAsyncIterable(overrides?.deltas),
|
|
565
|
+
interrupt: overrides?.interrupt ?? unexpected(stubName, "interrupt"),
|
|
566
|
+
respond: overrides?.respond ?? unexpected(stubName, "respond")
|
|
567
|
+
};
|
|
568
|
+
}
|
|
569
|
+
function createStubCodexTurn(overrides) {
|
|
570
|
+
const stubName = "StubCodexTurn";
|
|
571
|
+
return {
|
|
572
|
+
nativeTurnId: overrides?.nativeTurnId ?? "stub-turn-1",
|
|
573
|
+
deltas: toDeltaAsyncIterable(overrides?.deltas),
|
|
574
|
+
interrupt: overrides?.interrupt ?? unexpected(stubName, "interrupt"),
|
|
575
|
+
respond: overrides?.respond ?? unexpected(stubName, "respond")
|
|
576
|
+
};
|
|
577
|
+
}
|
|
578
|
+
function createStubClaudeSdkSession(overrides) {
|
|
579
|
+
const stubName = "StubClaudeSdkSession";
|
|
580
|
+
return {
|
|
581
|
+
nativeThreadId: overrides?.nativeThreadId ?? "stub-session-1",
|
|
582
|
+
providerPid: pickOptional(overrides, "providerPid", overrides?.providerPid, undefined),
|
|
583
|
+
startTurn: overrides?.startTurn ?? unexpected(stubName, "startTurn"),
|
|
584
|
+
setModel: overrides?.setModel ?? unexpected(stubName, "setModel"),
|
|
585
|
+
setPermissionMode: overrides?.setPermissionMode ?? unexpected(stubName, "setPermissionMode"),
|
|
586
|
+
applyFlagSettings: overrides?.applyFlagSettings ?? unexpected(stubName, "applyFlagSettings"),
|
|
587
|
+
initializationResult: overrides?.initializationResult ?? unexpected(stubName, "initializationResult"),
|
|
588
|
+
supportedModels: overrides?.supportedModels ?? unexpected(stubName, "supportedModels"),
|
|
589
|
+
supportedCommands: overrides?.supportedCommands ?? unexpected(stubName, "supportedCommands"),
|
|
590
|
+
accountInfo: overrides?.accountInfo ?? unexpected(stubName, "accountInfo"),
|
|
591
|
+
getContextUsage: overrides?.getContextUsage ?? unexpected(stubName, "getContextUsage"),
|
|
592
|
+
readUsage: overrides?.readUsage ?? unexpected(stubName, "readUsage"),
|
|
593
|
+
mcpServerStatus: overrides?.mcpServerStatus ?? unexpected(stubName, "mcpServerStatus"),
|
|
594
|
+
setMcpServers: overrides?.setMcpServers ?? unexpected(stubName, "setMcpServers"),
|
|
595
|
+
toggleMcpServer: overrides?.toggleMcpServer ?? unexpected(stubName, "toggleMcpServer"),
|
|
596
|
+
reconnectMcpServer: overrides?.reconnectMcpServer ?? unexpected(stubName, "reconnectMcpServer"),
|
|
597
|
+
stopTask: overrides?.stopTask ?? unexpected(stubName, "stopTask"),
|
|
598
|
+
backgroundTasks: overrides?.backgroundTasks ?? unexpected(stubName, "backgroundTasks"),
|
|
599
|
+
rewindFiles: overrides?.rewindFiles ?? unexpected(stubName, "rewindFiles"),
|
|
600
|
+
close: overrides?.close ?? noopClose
|
|
601
|
+
};
|
|
602
|
+
}
|
|
603
|
+
function createStubAcpSession(overrides) {
|
|
604
|
+
const stubName = "StubAcpSession";
|
|
605
|
+
return {
|
|
606
|
+
nativeThreadId: overrides?.nativeThreadId ?? "stub-acp-1",
|
|
607
|
+
providerPid: pickOptional(overrides, "providerPid", overrides?.providerPid, undefined),
|
|
608
|
+
approvalEnforcement: overrides?.approvalEnforcement ?? "agent-initiated",
|
|
609
|
+
configOptions: overrides?.configOptions ?? [],
|
|
610
|
+
title: pickOptional(overrides, "title", overrides?.title, undefined),
|
|
611
|
+
commands: overrides?.commands ?? [],
|
|
612
|
+
startTurn: overrides?.startTurn ?? unexpected(stubName, "startTurn"),
|
|
613
|
+
setConfigOption: overrides?.setConfigOption ?? unexpected(stubName, "setConfigOption"),
|
|
614
|
+
respond: overrides?.respond ?? unexpected(stubName, "respond"),
|
|
615
|
+
steerTurn: overrides?.steerTurn ?? unexpected(stubName, "steerTurn"),
|
|
616
|
+
close: overrides?.close ?? noopClose
|
|
617
|
+
};
|
|
618
|
+
}
|
|
355
619
|
// src/agent-executor/testing/fake-claude-engine.ts
|
|
356
620
|
import { z as z2 } from "zod";
|
|
357
621
|
|
|
@@ -423,6 +687,586 @@ async function runFakeClaudeEngine(input) {
|
|
|
423
687
|
input.exit(0);
|
|
424
688
|
}
|
|
425
689
|
}
|
|
690
|
+
// src/agent-executor/testing/fake-claude-sdk-query.ts
|
|
691
|
+
function createRecordQueue(onFinish) {
|
|
692
|
+
const buffered = [];
|
|
693
|
+
let wake;
|
|
694
|
+
let done = false;
|
|
695
|
+
let failure;
|
|
696
|
+
const notify = () => {
|
|
697
|
+
const current = wake;
|
|
698
|
+
wake = undefined;
|
|
699
|
+
current?.();
|
|
700
|
+
};
|
|
701
|
+
return {
|
|
702
|
+
push(record) {
|
|
703
|
+
if (done)
|
|
704
|
+
return;
|
|
705
|
+
buffered.push(record);
|
|
706
|
+
notify();
|
|
707
|
+
},
|
|
708
|
+
end() {
|
|
709
|
+
if (done)
|
|
710
|
+
return;
|
|
711
|
+
done = true;
|
|
712
|
+
onFinish();
|
|
713
|
+
notify();
|
|
714
|
+
},
|
|
715
|
+
fail(error) {
|
|
716
|
+
if (done)
|
|
717
|
+
return;
|
|
718
|
+
done = true;
|
|
719
|
+
failure = { error };
|
|
720
|
+
onFinish();
|
|
721
|
+
notify();
|
|
722
|
+
},
|
|
723
|
+
async* [Symbol.asyncIterator]() {
|
|
724
|
+
for (;; ) {
|
|
725
|
+
if (buffered.length > 0) {
|
|
726
|
+
yield buffered.shift();
|
|
727
|
+
continue;
|
|
728
|
+
}
|
|
729
|
+
if (failure !== undefined)
|
|
730
|
+
throw failure.error;
|
|
731
|
+
if (done)
|
|
732
|
+
return;
|
|
733
|
+
await new Promise((resolve) => {
|
|
734
|
+
wake = resolve;
|
|
735
|
+
});
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
};
|
|
739
|
+
}
|
|
740
|
+
function buildCanUseToolOptions(signal, permOptions) {
|
|
741
|
+
const result = {
|
|
742
|
+
signal,
|
|
743
|
+
toolUseID: permOptions?.toolUseID ?? "tool-1",
|
|
744
|
+
requestId: permOptions?.requestId ?? "req-1"
|
|
745
|
+
};
|
|
746
|
+
if (permOptions?.decisionReason !== undefined)
|
|
747
|
+
result.decisionReason = permOptions.decisionReason;
|
|
748
|
+
if (permOptions?.blockedPath !== undefined)
|
|
749
|
+
result.blockedPath = permOptions.blockedPath;
|
|
750
|
+
if (permOptions?.title !== undefined)
|
|
751
|
+
result.title = permOptions.title;
|
|
752
|
+
if (permOptions?.displayName !== undefined)
|
|
753
|
+
result.displayName = permOptions.displayName;
|
|
754
|
+
if (permOptions?.description !== undefined)
|
|
755
|
+
result.description = permOptions.description;
|
|
756
|
+
if (permOptions?.agentID !== undefined)
|
|
757
|
+
result.agentID = permOptions.agentID;
|
|
758
|
+
if (permOptions?.defaultToNo !== undefined)
|
|
759
|
+
result.defaultToNo = permOptions.defaultToNo;
|
|
760
|
+
if (permOptions?.suppressAlwaysAllowRule !== undefined) {
|
|
761
|
+
result.suppressAlwaysAllowRule = permOptions.suppressAlwaysAllowRule;
|
|
762
|
+
}
|
|
763
|
+
return result;
|
|
764
|
+
}
|
|
765
|
+
function createFakeRunController(options, runMessages, output) {
|
|
766
|
+
return {
|
|
767
|
+
options,
|
|
768
|
+
promptMessages: runMessages,
|
|
769
|
+
emit(entry) {
|
|
770
|
+
output.push(entry);
|
|
771
|
+
},
|
|
772
|
+
async askPermission(toolName, input, permOptions) {
|
|
773
|
+
if (options?.canUseTool === undefined) {
|
|
774
|
+
throw new Error("[stitchkit] FakeClaudeSdkRunController.askPermission: driver did not supply canUseTool");
|
|
775
|
+
}
|
|
776
|
+
const abortController = new AbortController;
|
|
777
|
+
const forwardAbort = () => abortController.abort();
|
|
778
|
+
const parentSignal = options.abortController?.signal;
|
|
779
|
+
const customSignal = permOptions?.signal;
|
|
780
|
+
if (parentSignal?.aborted || customSignal?.aborted) {
|
|
781
|
+
abortController.abort();
|
|
782
|
+
} else {
|
|
783
|
+
parentSignal?.addEventListener("abort", forwardAbort, { once: true });
|
|
784
|
+
customSignal?.addEventListener("abort", forwardAbort, { once: true });
|
|
785
|
+
}
|
|
786
|
+
try {
|
|
787
|
+
return await options.canUseTool(toolName, input, buildCanUseToolOptions(abortController.signal, permOptions));
|
|
788
|
+
} finally {
|
|
789
|
+
parentSignal?.removeEventListener("abort", forwardAbort);
|
|
790
|
+
customSignal?.removeEventListener("abort", forwardAbort);
|
|
791
|
+
}
|
|
792
|
+
},
|
|
793
|
+
end() {
|
|
794
|
+
output.end();
|
|
795
|
+
},
|
|
796
|
+
fail(error) {
|
|
797
|
+
output.fail(error);
|
|
798
|
+
}
|
|
799
|
+
};
|
|
800
|
+
}
|
|
801
|
+
function createFakeRunObject(config, output, record, close) {
|
|
802
|
+
return {
|
|
803
|
+
[Symbol.asyncIterator]: () => output[Symbol.asyncIterator](),
|
|
804
|
+
async interrupt() {
|
|
805
|
+
record("interrupt", []);
|
|
806
|
+
},
|
|
807
|
+
close,
|
|
808
|
+
async setModel(model) {
|
|
809
|
+
record("setModel", [model]);
|
|
810
|
+
},
|
|
811
|
+
async setPermissionMode(mode) {
|
|
812
|
+
record("setPermissionMode", [mode]);
|
|
813
|
+
return config.onSetPermissionMode !== undefined ? config.onSetPermissionMode(mode) : { mode };
|
|
814
|
+
},
|
|
815
|
+
async applyFlagSettings(settings) {
|
|
816
|
+
record("applyFlagSettings", [settings]);
|
|
817
|
+
},
|
|
818
|
+
async initializationResult() {
|
|
819
|
+
record("initializationResult", []);
|
|
820
|
+
return config.initializationResult ?? {
|
|
821
|
+
commands: [...config.commands ?? []],
|
|
822
|
+
agents: [],
|
|
823
|
+
output_style: "default",
|
|
824
|
+
available_output_styles: ["default"],
|
|
825
|
+
models: [...config.models ?? []],
|
|
826
|
+
account: config.account ?? {}
|
|
827
|
+
};
|
|
828
|
+
},
|
|
829
|
+
async supportedModels() {
|
|
830
|
+
record("supportedModels", []);
|
|
831
|
+
return [...config.models ?? []];
|
|
832
|
+
},
|
|
833
|
+
async supportedCommands() {
|
|
834
|
+
record("supportedCommands", []);
|
|
835
|
+
return [...config.commands ?? []];
|
|
836
|
+
},
|
|
837
|
+
async accountInfo() {
|
|
838
|
+
record("accountInfo", []);
|
|
839
|
+
return config.account ?? {};
|
|
840
|
+
},
|
|
841
|
+
async getContextUsage(opts) {
|
|
842
|
+
record("getContextUsage", [opts]);
|
|
843
|
+
return config.contextUsage ?? {
|
|
844
|
+
categories: [],
|
|
845
|
+
totalTokens: 0,
|
|
846
|
+
maxTokens: 200000,
|
|
847
|
+
rawMaxTokens: 200000,
|
|
848
|
+
percentage: 0,
|
|
849
|
+
gridRows: [],
|
|
850
|
+
model: "claude-sonnet-4-6",
|
|
851
|
+
isAutoCompactEnabled: true,
|
|
852
|
+
memoryFiles: [],
|
|
853
|
+
mcpTools: [],
|
|
854
|
+
agents: [],
|
|
855
|
+
apiUsage: null
|
|
856
|
+
};
|
|
857
|
+
},
|
|
858
|
+
...config.usage !== undefined && {
|
|
859
|
+
async usage_EXPERIMENTAL_MAY_CHANGE_DO_NOT_RELY_ON_THIS_API_YET(opts) {
|
|
860
|
+
record("usage_EXPERIMENTAL_MAY_CHANGE_DO_NOT_RELY_ON_THIS_API_YET", [opts]);
|
|
861
|
+
const provider = config.usage;
|
|
862
|
+
if (typeof provider === "function")
|
|
863
|
+
return provider();
|
|
864
|
+
if (provider !== undefined)
|
|
865
|
+
return provider;
|
|
866
|
+
throw new Error("Fake usage provider missing");
|
|
867
|
+
}
|
|
868
|
+
},
|
|
869
|
+
async mcpServerStatus() {
|
|
870
|
+
record("mcpServerStatus", []);
|
|
871
|
+
return [...config.mcpServers ?? []];
|
|
872
|
+
},
|
|
873
|
+
async setMcpServers(servers) {
|
|
874
|
+
record("setMcpServers", [servers]);
|
|
875
|
+
return config.setMcpServersResult ?? { added: [], removed: [], errors: {} };
|
|
876
|
+
},
|
|
877
|
+
async toggleMcpServer(serverName, enabled) {
|
|
878
|
+
record("toggleMcpServer", [serverName, enabled]);
|
|
879
|
+
},
|
|
880
|
+
async reconnectMcpServer(serverName) {
|
|
881
|
+
record("reconnectMcpServer", [serverName]);
|
|
882
|
+
},
|
|
883
|
+
async stopTask(taskId) {
|
|
884
|
+
record("stopTask", [taskId]);
|
|
885
|
+
},
|
|
886
|
+
async backgroundTasks(toolUseId) {
|
|
887
|
+
record("backgroundTasks", [toolUseId]);
|
|
888
|
+
return true;
|
|
889
|
+
},
|
|
890
|
+
async rewindFiles(userMessageId, rewindOptions) {
|
|
891
|
+
record("rewindFiles", [userMessageId, rewindOptions]);
|
|
892
|
+
return config.rewindFilesResult ?? { canRewind: true };
|
|
893
|
+
}
|
|
894
|
+
};
|
|
895
|
+
}
|
|
896
|
+
function createFakeClaudeSdkQuery(config = {}) {
|
|
897
|
+
const calls = [];
|
|
898
|
+
const promptMessages = [];
|
|
899
|
+
const runs = [];
|
|
900
|
+
let turnCursor = 0;
|
|
901
|
+
const record = (method, args) => {
|
|
902
|
+
calls.push({ method, args });
|
|
903
|
+
};
|
|
904
|
+
const query = ({ prompt, options }) => {
|
|
905
|
+
const lifetime = new AbortController;
|
|
906
|
+
const input = linkAbortSignals(options?.abortController?.signal, lifetime.signal);
|
|
907
|
+
const output = createRecordQueue(() => {
|
|
908
|
+
lifetime.abort();
|
|
909
|
+
input.release();
|
|
910
|
+
});
|
|
911
|
+
const runMessages = [];
|
|
912
|
+
let closed = false;
|
|
913
|
+
const controller = createFakeRunController(options, runMessages, output);
|
|
914
|
+
runs.push(controller);
|
|
915
|
+
const signal = input.signal;
|
|
916
|
+
const close = () => {
|
|
917
|
+
if (closed)
|
|
918
|
+
return;
|
|
919
|
+
closed = true;
|
|
920
|
+
record("close", []);
|
|
921
|
+
output.end();
|
|
922
|
+
};
|
|
923
|
+
if (signal.aborted)
|
|
924
|
+
output.end();
|
|
925
|
+
else
|
|
926
|
+
signal.addEventListener("abort", () => output.end(), { once: true });
|
|
927
|
+
if (config.onRun !== undefined && !signal.aborted) {
|
|
928
|
+
Promise.resolve().then(() => signal.aborted ? undefined : config.onRun?.(controller)).catch((error) => output.fail(error));
|
|
929
|
+
}
|
|
930
|
+
(async () => {
|
|
931
|
+
if (signal.aborted)
|
|
932
|
+
return;
|
|
933
|
+
let iterator;
|
|
934
|
+
let exhausted = false;
|
|
935
|
+
try {
|
|
936
|
+
iterator = prompt[Symbol.asyncIterator]();
|
|
937
|
+
while (!signal.aborted) {
|
|
938
|
+
const next = await untilAborted(iterator.next(), signal);
|
|
939
|
+
if (next.aborted || signal.aborted)
|
|
940
|
+
break;
|
|
941
|
+
if (next.value.done) {
|
|
942
|
+
exhausted = true;
|
|
943
|
+
break;
|
|
944
|
+
}
|
|
945
|
+
const message = next.value.value;
|
|
946
|
+
runMessages.push(message);
|
|
947
|
+
promptMessages.push(message);
|
|
948
|
+
const scripted = config.turns?.[turnCursor];
|
|
949
|
+
turnCursor += 1;
|
|
950
|
+
if (scripted === undefined)
|
|
951
|
+
continue;
|
|
952
|
+
if (typeof scripted === "function") {
|
|
953
|
+
await untilAborted(Promise.resolve(scripted(message, controller)), signal);
|
|
954
|
+
} else {
|
|
955
|
+
for (const entry of scripted.records)
|
|
956
|
+
output.push(entry);
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
} catch (error) {
|
|
960
|
+
output.fail(error);
|
|
961
|
+
} finally {
|
|
962
|
+
if (!exhausted && iterator?.return) {
|
|
963
|
+
try {
|
|
964
|
+
await iterator.return();
|
|
965
|
+
} catch (error) {
|
|
966
|
+
output.fail(error);
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
}
|
|
970
|
+
})();
|
|
971
|
+
return createFakeRunObject(config, output, record, close);
|
|
972
|
+
};
|
|
973
|
+
return { query, calls, promptMessages, runs };
|
|
974
|
+
}
|
|
975
|
+
// src/agent-executor/testing/fake-codex-app-server.ts
|
|
976
|
+
import { createHash } from "node:crypto";
|
|
977
|
+
import { lstatSync } from "node:fs";
|
|
978
|
+
import { createServer } from "node:net";
|
|
979
|
+
var WS_GUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
|
|
980
|
+
var MAX_UPGRADE_HEADER_BYTES = 64 * 1024;
|
|
981
|
+
var DEFAULT_MAX_FRAME_BYTES = 16 * 1024 * 1024;
|
|
982
|
+
var DEFAULT_USER_AGENT = "codex/0.171.0";
|
|
983
|
+
var JSON_RPC_INTERNAL_ERROR = -32603;
|
|
984
|
+
function isRpcErrorOutcome(value) {
|
|
985
|
+
if (!isRecord(value))
|
|
986
|
+
return false;
|
|
987
|
+
const keys = Object.keys(value);
|
|
988
|
+
if (keys.length !== 1 || keys[0] !== "error")
|
|
989
|
+
return false;
|
|
990
|
+
const err = value.error;
|
|
991
|
+
return isRecord(err) && typeof err.code === "number" && typeof err.message === "string";
|
|
992
|
+
}
|
|
993
|
+
function requestKey(id) {
|
|
994
|
+
return `${typeof id}:${String(id)}`;
|
|
995
|
+
}
|
|
996
|
+
function writeTextFrame(socket, text) {
|
|
997
|
+
socket.write(encodeUnmaskedWsFrame(1, Buffer.from(text, "utf8")));
|
|
998
|
+
}
|
|
999
|
+
function extractUpgradeKey(headerBlock) {
|
|
1000
|
+
for (const line of headerBlock.split(`\r
|
|
1001
|
+
`)) {
|
|
1002
|
+
const colon = line.indexOf(":");
|
|
1003
|
+
if (colon <= 0)
|
|
1004
|
+
continue;
|
|
1005
|
+
if (line.slice(0, colon).trim().toLowerCase() === "sec-websocket-key") {
|
|
1006
|
+
const value = line.slice(colon + 1).trim();
|
|
1007
|
+
return value.length > 0 ? value : undefined;
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
1010
|
+
return;
|
|
1011
|
+
}
|
|
1012
|
+
function rejectPendingForSocket(state, socket, error) {
|
|
1013
|
+
for (const [key, entry] of [...state.pendingServerRequests]) {
|
|
1014
|
+
if (entry.socket !== socket)
|
|
1015
|
+
continue;
|
|
1016
|
+
state.pendingServerRequests.delete(key);
|
|
1017
|
+
entry.reject(error);
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
function handleClientMessage(state, socket, text) {
|
|
1021
|
+
let raw;
|
|
1022
|
+
try {
|
|
1023
|
+
raw = JSON.parse(text);
|
|
1024
|
+
} catch {
|
|
1025
|
+
return;
|
|
1026
|
+
}
|
|
1027
|
+
if (!isRecord(raw))
|
|
1028
|
+
return;
|
|
1029
|
+
const rawId = raw.id;
|
|
1030
|
+
const hasId = typeof rawId === "string" || typeof rawId === "number";
|
|
1031
|
+
const rawMethod = raw.method;
|
|
1032
|
+
const hasMethod = typeof rawMethod === "string";
|
|
1033
|
+
if (hasId && !hasMethod) {
|
|
1034
|
+
const key = requestKey(rawId);
|
|
1035
|
+
const pending = state.pendingServerRequests.get(key);
|
|
1036
|
+
if (pending === undefined || pending.socket !== socket)
|
|
1037
|
+
return;
|
|
1038
|
+
state.pendingServerRequests.delete(key);
|
|
1039
|
+
if (isRecord(raw.error) && typeof raw.error.code === "number") {
|
|
1040
|
+
const message = typeof raw.error.message === "string" ? raw.error.message : "RPC error";
|
|
1041
|
+
pending.reject(new JsonRpcError2(raw.error.code, message, raw.error.data));
|
|
1042
|
+
} else {
|
|
1043
|
+
const parsedResult = JsonRpcValueSchema2.safeParse(raw.result ?? null);
|
|
1044
|
+
pending.resolve(parsedResult.success ? parsedResult.data : null);
|
|
1045
|
+
}
|
|
1046
|
+
return;
|
|
1047
|
+
}
|
|
1048
|
+
if (!hasMethod || !hasId)
|
|
1049
|
+
return;
|
|
1050
|
+
const paramsParsed = raw.params === undefined ? undefined : JsonRpcValueSchema2.safeParse(raw.params);
|
|
1051
|
+
const params = paramsParsed?.success ? paramsParsed.data : undefined;
|
|
1052
|
+
const recorded = {
|
|
1053
|
+
id: rawId,
|
|
1054
|
+
method: rawMethod,
|
|
1055
|
+
...params !== undefined && { params }
|
|
1056
|
+
};
|
|
1057
|
+
state.requests.push(recorded);
|
|
1058
|
+
const handler = state.config.handlers?.[rawMethod];
|
|
1059
|
+
if (handler === undefined) {
|
|
1060
|
+
if (rawMethod === "initialize") {
|
|
1061
|
+
const result = state.userAgent !== undefined ? { userAgent: state.userAgent } : {};
|
|
1062
|
+
writeTextFrame(socket, JSON.stringify({ id: rawId, result }));
|
|
1063
|
+
return;
|
|
1064
|
+
}
|
|
1065
|
+
writeTextFrame(socket, JSON.stringify({
|
|
1066
|
+
id: rawId,
|
|
1067
|
+
error: {
|
|
1068
|
+
code: JSON_RPC_METHOD_NOT_FOUND2,
|
|
1069
|
+
message: `Fake Codex app-server has no handler for ${rawMethod}`
|
|
1070
|
+
}
|
|
1071
|
+
}));
|
|
1072
|
+
return;
|
|
1073
|
+
}
|
|
1074
|
+
Promise.resolve().then(() => handler(params, recorded)).then((outcome) => {
|
|
1075
|
+
if (outcome === "hang" || socket.destroyed || !state.upgradedSockets.has(socket))
|
|
1076
|
+
return;
|
|
1077
|
+
if (isRpcErrorOutcome(outcome)) {
|
|
1078
|
+
writeTextFrame(socket, JSON.stringify({ id: rawId, error: outcome.error }));
|
|
1079
|
+
return;
|
|
1080
|
+
}
|
|
1081
|
+
writeTextFrame(socket, JSON.stringify({ id: rawId, result: outcome }));
|
|
1082
|
+
}, (error) => {
|
|
1083
|
+
if (socket.destroyed || !state.upgradedSockets.has(socket))
|
|
1084
|
+
return;
|
|
1085
|
+
if (error instanceof JsonRpcError2) {
|
|
1086
|
+
writeTextFrame(socket, JSON.stringify({
|
|
1087
|
+
id: rawId,
|
|
1088
|
+
error: {
|
|
1089
|
+
code: error.code,
|
|
1090
|
+
message: error.message,
|
|
1091
|
+
...error.data !== undefined && { data: error.data }
|
|
1092
|
+
}
|
|
1093
|
+
}));
|
|
1094
|
+
return;
|
|
1095
|
+
}
|
|
1096
|
+
writeTextFrame(socket, JSON.stringify({
|
|
1097
|
+
id: rawId,
|
|
1098
|
+
error: {
|
|
1099
|
+
code: JSON_RPC_INTERNAL_ERROR,
|
|
1100
|
+
message: error instanceof Error ? error.message : String(error)
|
|
1101
|
+
}
|
|
1102
|
+
}));
|
|
1103
|
+
});
|
|
1104
|
+
}
|
|
1105
|
+
function attachClientSocket(state, socket) {
|
|
1106
|
+
state.activeSockets.add(socket);
|
|
1107
|
+
let upgradeBuffer = Buffer.alloc(0);
|
|
1108
|
+
let decoder;
|
|
1109
|
+
const detach = () => {
|
|
1110
|
+
state.activeSockets.delete(socket);
|
|
1111
|
+
state.upgradedSockets.delete(socket);
|
|
1112
|
+
if (state.latestClient === socket) {
|
|
1113
|
+
state.latestClient = [...state.upgradedSockets].at(-1);
|
|
1114
|
+
}
|
|
1115
|
+
rejectPendingForSocket(state, socket, new Error("Fake Codex app-server client disconnected"));
|
|
1116
|
+
};
|
|
1117
|
+
socket.once("close", detach);
|
|
1118
|
+
socket.on("error", () => {
|
|
1119
|
+
socket.destroy();
|
|
1120
|
+
});
|
|
1121
|
+
socket.on("data", (chunk) => {
|
|
1122
|
+
const buf = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
1123
|
+
if (decoder !== undefined) {
|
|
1124
|
+
decoder.push(buf);
|
|
1125
|
+
return;
|
|
1126
|
+
}
|
|
1127
|
+
upgradeBuffer = Buffer.concat([upgradeBuffer, buf]);
|
|
1128
|
+
const headerEnd = upgradeBuffer.indexOf(`\r
|
|
1129
|
+
\r
|
|
1130
|
+
`);
|
|
1131
|
+
if (headerEnd === -1) {
|
|
1132
|
+
if (upgradeBuffer.byteLength > MAX_UPGRADE_HEADER_BYTES)
|
|
1133
|
+
socket.destroy();
|
|
1134
|
+
return;
|
|
1135
|
+
}
|
|
1136
|
+
if (headerEnd > MAX_UPGRADE_HEADER_BYTES) {
|
|
1137
|
+
socket.destroy();
|
|
1138
|
+
return;
|
|
1139
|
+
}
|
|
1140
|
+
const headerBlock = upgradeBuffer.subarray(0, headerEnd).toString("utf8");
|
|
1141
|
+
const trailing = upgradeBuffer.subarray(headerEnd + 4);
|
|
1142
|
+
upgradeBuffer = Buffer.alloc(0);
|
|
1143
|
+
const wsKey = extractUpgradeKey(headerBlock);
|
|
1144
|
+
if (wsKey === undefined) {
|
|
1145
|
+
socket.end(`HTTP/1.1 400 Bad Request\r
|
|
1146
|
+
Connection: close\r
|
|
1147
|
+
\r
|
|
1148
|
+
`);
|
|
1149
|
+
return;
|
|
1150
|
+
}
|
|
1151
|
+
const accept = createHash("sha1").update(`${wsKey}${WS_GUID}`).digest("base64");
|
|
1152
|
+
socket.write(`HTTP/1.1 101 Switching Protocols\r
|
|
1153
|
+
Upgrade: websocket\r
|
|
1154
|
+
Connection: Upgrade\r
|
|
1155
|
+
Sec-WebSocket-Accept: ${accept}\r
|
|
1156
|
+
\r
|
|
1157
|
+
`);
|
|
1158
|
+
state.upgradedSockets.add(socket);
|
|
1159
|
+
state.latestClient = socket;
|
|
1160
|
+
decoder = createWsFrameDecoder({
|
|
1161
|
+
maxFrameBytes: state.maxFrameBytes,
|
|
1162
|
+
expectMasked: true,
|
|
1163
|
+
onMessage: (text) => handleClientMessage(state, socket, text),
|
|
1164
|
+
onPing: (payload) => {
|
|
1165
|
+
if (!socket.destroyed)
|
|
1166
|
+
socket.write(encodeUnmaskedWsFrame(10, payload));
|
|
1167
|
+
},
|
|
1168
|
+
onClose: () => {
|
|
1169
|
+
if (!socket.destroyed) {
|
|
1170
|
+
try {
|
|
1171
|
+
socket.write(encodeUnmaskedWsFrame(8, Buffer.alloc(0)));
|
|
1172
|
+
} catch {}
|
|
1173
|
+
socket.destroy();
|
|
1174
|
+
}
|
|
1175
|
+
},
|
|
1176
|
+
onProtocolError: () => {
|
|
1177
|
+
socket.destroy();
|
|
1178
|
+
}
|
|
1179
|
+
});
|
|
1180
|
+
if (trailing.byteLength > 0)
|
|
1181
|
+
decoder.push(trailing);
|
|
1182
|
+
});
|
|
1183
|
+
}
|
|
1184
|
+
async function createFakeCodexAppServer(config) {
|
|
1185
|
+
validateCodexUnixSocketPath(config.socketPath, "createFakeCodexAppServer");
|
|
1186
|
+
assertPrivateUnixSocketDirectory(config.socketPath, "createFakeCodexAppServer");
|
|
1187
|
+
assertPositiveSafeInteger("maxFrameBytes", config.maxFrameBytes);
|
|
1188
|
+
const state = {
|
|
1189
|
+
config,
|
|
1190
|
+
maxFrameBytes: config.maxFrameBytes ?? DEFAULT_MAX_FRAME_BYTES,
|
|
1191
|
+
userAgent: "userAgent" in config ? config.userAgent : DEFAULT_USER_AGENT,
|
|
1192
|
+
requests: [],
|
|
1193
|
+
activeSockets: new Set,
|
|
1194
|
+
upgradedSockets: new Set,
|
|
1195
|
+
pendingServerRequests: new Map,
|
|
1196
|
+
latestClient: undefined
|
|
1197
|
+
};
|
|
1198
|
+
let closePromise;
|
|
1199
|
+
const server = createServer((socket) => attachClientSocket(state, socket));
|
|
1200
|
+
const listening = new Promise((resolve, reject) => {
|
|
1201
|
+
server.once("error", reject);
|
|
1202
|
+
server.once("listening", resolve);
|
|
1203
|
+
});
|
|
1204
|
+
try {
|
|
1205
|
+
bindUnixSocket2({ path: config.socketPath, mode: 384 }, (boundPath) => server.listen(boundPath));
|
|
1206
|
+
} catch (error) {
|
|
1207
|
+
listening.catch(() => {
|
|
1208
|
+
return;
|
|
1209
|
+
});
|
|
1210
|
+
server.close();
|
|
1211
|
+
throw error;
|
|
1212
|
+
}
|
|
1213
|
+
await listening;
|
|
1214
|
+
const boundStats = lstatSync(config.socketPath);
|
|
1215
|
+
const boundInode = { dev: boundStats.dev, ino: boundStats.ino };
|
|
1216
|
+
const requireActiveClient = (caller) => {
|
|
1217
|
+
if (state.latestClient === undefined || state.latestClient.destroyed) {
|
|
1218
|
+
throw new Error(`[stitchkit] FakeCodexAppServer.${caller}: no client is connected`);
|
|
1219
|
+
}
|
|
1220
|
+
return state.latestClient;
|
|
1221
|
+
};
|
|
1222
|
+
return {
|
|
1223
|
+
socketPath: config.socketPath,
|
|
1224
|
+
requests: state.requests,
|
|
1225
|
+
sendNotification(method, params) {
|
|
1226
|
+
const client = requireActiveClient("sendNotification");
|
|
1227
|
+
writeTextFrame(client, JSON.stringify({ method, ...params !== undefined && { params } }));
|
|
1228
|
+
},
|
|
1229
|
+
async sendRequest(id, method, params) {
|
|
1230
|
+
const client = requireActiveClient("sendRequest");
|
|
1231
|
+
const key = requestKey(id);
|
|
1232
|
+
if (state.pendingServerRequests.has(key)) {
|
|
1233
|
+
throw new Error(`[stitchkit] FakeCodexAppServer.sendRequest: duplicate pending request id ${JSON.stringify(id)}`);
|
|
1234
|
+
}
|
|
1235
|
+
return new Promise((resolve, reject) => {
|
|
1236
|
+
state.pendingServerRequests.set(key, { socket: client, resolve, reject });
|
|
1237
|
+
try {
|
|
1238
|
+
writeTextFrame(client, JSON.stringify({ id, method, ...params !== undefined && { params } }));
|
|
1239
|
+
} catch (error) {
|
|
1240
|
+
state.pendingServerRequests.delete(key);
|
|
1241
|
+
reject(error);
|
|
1242
|
+
}
|
|
1243
|
+
});
|
|
1244
|
+
},
|
|
1245
|
+
sendRaw(text) {
|
|
1246
|
+
const client = requireActiveClient("sendRaw");
|
|
1247
|
+
writeTextFrame(client, text);
|
|
1248
|
+
},
|
|
1249
|
+
disconnect() {
|
|
1250
|
+
for (const socket of [...state.activeSockets]) {
|
|
1251
|
+
socket.destroy();
|
|
1252
|
+
}
|
|
1253
|
+
},
|
|
1254
|
+
close() {
|
|
1255
|
+
if (closePromise === undefined) {
|
|
1256
|
+
closePromise = (async () => {
|
|
1257
|
+
for (const socket of [...state.activeSockets]) {
|
|
1258
|
+
socket.destroy();
|
|
1259
|
+
}
|
|
1260
|
+
await new Promise((resolve) => {
|
|
1261
|
+
server.close(() => resolve());
|
|
1262
|
+
});
|
|
1263
|
+
unlinkUnixSocketIfMatching(config.socketPath, boundInode);
|
|
1264
|
+
})();
|
|
1265
|
+
}
|
|
1266
|
+
return closePromise;
|
|
1267
|
+
}
|
|
1268
|
+
};
|
|
1269
|
+
}
|
|
426
1270
|
// src/agent-executor/testing/replay-driver.ts
|
|
427
1271
|
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
428
1272
|
|
|
@@ -565,6 +1409,7 @@ async function runReplayTurnScript(context) {
|
|
|
565
1409
|
continue;
|
|
566
1410
|
}
|
|
567
1411
|
if (step.kind === "request") {
|
|
1412
|
+
turn.hostAnswered.delete(step.interactionId);
|
|
568
1413
|
const replyPromise = new Promise((resolve) => {
|
|
569
1414
|
holdEngineRequest(turn, {
|
|
570
1415
|
interactionId: step.interactionId,
|
|
@@ -598,6 +1443,7 @@ async function runReplayTurnScript(context) {
|
|
|
598
1443
|
throw new Error(`Replay expectReply(${step.interactionId}) has no matching preceding request`);
|
|
599
1444
|
}
|
|
600
1445
|
const reply = await pendingReply;
|
|
1446
|
+
turn.replyPromises.delete(step.interactionId);
|
|
601
1447
|
if (signal.aborted)
|
|
602
1448
|
throw new Error("Replay session aborted");
|
|
603
1449
|
if (!turn.state.interruptRequested && step.replyKind !== undefined && reply.kind !== step.replyKind) {
|
|
@@ -606,6 +1452,8 @@ async function runReplayTurnScript(context) {
|
|
|
606
1452
|
if (!turn.state.interruptRequested && step.scope !== undefined && (reply.kind !== "approve" || reply.scope !== step.scope)) {
|
|
607
1453
|
throw new Error(`Replay expectReply(${step.interactionId}) expected scope ${step.scope}`);
|
|
608
1454
|
}
|
|
1455
|
+
if (turn.hostAnswered.delete(step.interactionId))
|
|
1456
|
+
context.consumedReplies.add(step);
|
|
609
1457
|
continue;
|
|
610
1458
|
}
|
|
611
1459
|
if (step.kind === "usage") {
|
|
@@ -920,7 +1768,7 @@ function createReplayExecutorDriver(config) {
|
|
|
920
1768
|
const limits = new Map;
|
|
921
1769
|
const recordedInputs = new Map;
|
|
922
1770
|
const answeredIds = new Set;
|
|
923
|
-
const
|
|
1771
|
+
const consumedReplies = new Set;
|
|
924
1772
|
let nextTurnIndex = 0;
|
|
925
1773
|
let completedTurns = 0;
|
|
926
1774
|
const assertComplete = () => {
|
|
@@ -928,10 +1776,10 @@ function createReplayExecutorDriver(config) {
|
|
|
928
1776
|
throw new Error(`Replay driver incomplete: completed ${completedTurns} of ${transcripts.length} scripted turn(s)`);
|
|
929
1777
|
}
|
|
930
1778
|
const missingRequired = [];
|
|
931
|
-
for (const transcript of transcripts) {
|
|
932
|
-
for (const step of transcript.steps) {
|
|
933
|
-
if (step.kind === "expectReply" && step.required !== false && !
|
|
934
|
-
missingRequired.push(`expectReply:${step.interactionId}`);
|
|
1779
|
+
for (const [turnIndex, transcript] of transcripts.entries()) {
|
|
1780
|
+
for (const [stepIndex, step] of transcript.steps.entries()) {
|
|
1781
|
+
if (step.kind === "expectReply" && step.required !== false && !consumedReplies.has(step)) {
|
|
1782
|
+
missingRequired.push(`turn ${turnIndex + 1} step ${stepIndex + 1} expectReply:${step.interactionId}`);
|
|
935
1783
|
}
|
|
936
1784
|
}
|
|
937
1785
|
}
|
|
@@ -1003,7 +1851,8 @@ function createReplayExecutorDriver(config) {
|
|
|
1003
1851
|
channel: createTurnDeltaChannel(),
|
|
1004
1852
|
pending: new Map,
|
|
1005
1853
|
interruptWaiters: [],
|
|
1006
|
-
replyPromises: new Map
|
|
1854
|
+
replyPromises: new Map,
|
|
1855
|
+
hostAnswered: new Set
|
|
1007
1856
|
};
|
|
1008
1857
|
activeTurn = turn;
|
|
1009
1858
|
const runPromise = runReplayTurnScript({
|
|
@@ -1013,7 +1862,7 @@ function createReplayExecutorDriver(config) {
|
|
|
1013
1862
|
profileId: profile.profileId,
|
|
1014
1863
|
limits,
|
|
1015
1864
|
answeredIds,
|
|
1016
|
-
|
|
1865
|
+
consumedReplies,
|
|
1017
1866
|
...config.gate !== undefined && { gate: config.gate },
|
|
1018
1867
|
signal: linked.signal,
|
|
1019
1868
|
onTurnCompleted: () => {
|
|
@@ -1043,7 +1892,7 @@ function createReplayExecutorDriver(config) {
|
|
|
1043
1892
|
if (!parsed.success) {
|
|
1044
1893
|
throw new TypeError(`Invalid interaction reply: ${parsed.error.message}`);
|
|
1045
1894
|
}
|
|
1046
|
-
|
|
1895
|
+
turn.hostAnswered.add(interactionId);
|
|
1047
1896
|
answerEngineRequest(turn, interactionId, parsed.data);
|
|
1048
1897
|
}
|
|
1049
1898
|
};
|
|
@@ -1364,9 +2213,22 @@ export {
|
|
|
1364
2213
|
FakeEngineScenarioSchema,
|
|
1365
2214
|
FakeEngineStepSchema,
|
|
1366
2215
|
REPLAY_SCENARIOS,
|
|
2216
|
+
createFakeClaudeSdkQuery,
|
|
2217
|
+
createFakeCodexAppServer,
|
|
1367
2218
|
createReplayExecutorDriver,
|
|
1368
2219
|
createReplayGate,
|
|
2220
|
+
createStubAcpSession,
|
|
2221
|
+
createStubAgentEngineTurn,
|
|
2222
|
+
createStubClaudeSdkSession,
|
|
2223
|
+
createStubCodexControlClient,
|
|
2224
|
+
createStubCodexControlConnection,
|
|
2225
|
+
createStubCodexSession,
|
|
2226
|
+
createStubCodexSharedServer,
|
|
2227
|
+
createStubCodexTurn,
|
|
1369
2228
|
formatReplayTranscript,
|
|
2229
|
+
makeCodexNotificationEvent,
|
|
2230
|
+
makeCodexThreadFixture,
|
|
2231
|
+
makeExecutorDelta,
|
|
1370
2232
|
parseReplayTranscript,
|
|
1371
2233
|
replayDialectScenarios,
|
|
1372
2234
|
runAgentEngineConformance,
|