@gobing-ai/ts-ai-runner 0.6.2 → 0.6.4
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 +11 -0
- package/dist/agents/shims.d.ts.map +1 -1
- package/dist/agents/shims.js +6 -1
- package/dist/testing/fake-turn-agent.js +1 -1
- package/dist/testing/fake-turn-driver.d.ts +1 -1
- package/dist/testing/fake-turn-driver.d.ts.map +1 -1
- package/dist/testing/fake-turn-driver.js +5 -1
- package/dist/turn-drivers/pi-rpc.d.ts +18 -0
- package/dist/turn-drivers/pi-rpc.d.ts.map +1 -0
- package/dist/turn-drivers/pi-rpc.js +142 -0
- package/dist/turn-session.d.ts +3 -2
- package/dist/turn-session.d.ts.map +1 -1
- package/dist/turn-session.js +7 -6
- package/package.json +4 -4
- package/src/agents/shims.ts +6 -1
- package/src/testing/fake-turn-agent.ts +2 -2
- package/src/testing/fake-turn-driver.ts +7 -2
- package/src/turn-drivers/pi-rpc.ts +188 -0
- package/src/turn-session.ts +10 -7
package/README.md
CHANGED
|
@@ -934,6 +934,17 @@ safe to call more than once; the maker is not usable afterwards.
|
|
|
934
934
|
policy, receipts and validation. `TURN_SESSION_DRIVERS` registers a driver only with recorded
|
|
935
935
|
`verifiedAgainst` qualification evidence; the scripted fake in `@gobing-ai/ts-ai-runner/testing`
|
|
936
936
|
is for consumer tests, never library code.
|
|
937
|
+
- Registered drivers (evidence in `tests/fixtures/turn-drivers/<agent>/`): `claude` 2.1.308
|
|
938
|
+
stream-json (task 1276) and `pi` 0.87.1 rpc (task 1277 — probed live 2026-10-23 against the
|
|
939
|
+
repository dependency; the PATH 1.4.0 binary speaks the same family but is not the spawn
|
|
940
|
+
target, so `qualify()` pins 0.87.1 only). Any other version refuses `unqualified-version` and
|
|
941
|
+
the consumer falls back to resume/one-shot — never a guessed protocol.
|
|
942
|
+
- Outcome classification (task 1277 escalation Q2): a definite pre-acceptance end settles
|
|
943
|
+
`not-started`, uniformly across the process-exit path and decoder terminals (pi's prompt
|
|
944
|
+
rejection before acceptance). `failure` is reserved for definite post-acceptance ends. The pi
|
|
945
|
+
fixtures could not capture a live pre-acceptance rejection (0.87.1 accepted every inducement:
|
|
946
|
+
empty message, unknown model), so the shape is decoder-unit-tested with synthetic lines and
|
|
947
|
+
facade-tested through the scripted fake.
|
|
937
948
|
- This package is a command adapter, not an agent orchestration framework.- It does not install agent CLIs or manage credentials.
|
|
938
949
|
- It does not parse agent responses beyond process result capture.
|
|
939
950
|
- It keeps subprocess launching behind `ProcessExecutor` / `PipeProcess`, so tests can stay deterministic.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shims.d.ts","sourceRoot":"","sources":["../../src/agents/shims.ts"],"names":[],"mappings":"AAIA,gEAAgE;AAChE,MAAM,MAAM,SAAS,GACf,QAAQ,GACR,OAAO,GACP,QAAQ,GACR,IAAI,GACJ,UAAU,GACV,iBAAiB,GACjB,UAAU,GACV,QAAQ,GACR,KAAK,GACL,MAAM,GACN,UAAU,GACV,IAAI,CAAC;AAEX,0CAA0C;AAC1C,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,MAAM,CAAC;AAEzC,mEAAmE;AACnE,MAAM,WAAW,WAAW;IACxB,4BAA4B;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,2CAA2C;IAC3C,IAAI,EAAE,MAAM,EAAE,CAAC;CAClB;AAED,4CAA4C;AAC5C,MAAM,WAAW,aAAa;IAC1B,yDAAyD;IACzD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,8DAA8D;IAC9D,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;;;OAKG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,wDAAwD;IACxD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,mDAAmD;IACnD,IAAI,CAAC,EAAE,UAAU,CAAC;IAClB,8EAA8E;IAC9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IAC1C,oEAAoE;IACpE,QAAQ,CAAC,wBAAwB,EAAE,OAAO,CAAC;IAC3C,sGAAsG;IACtG,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IACjC,4GAA4G;IAC5G,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;CAC1B;AA+HD,6EAA6E;AAC7E,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,SAAS,GAAG,sBAAsB,CAElF;AAED,mEAAmE;AACnE,eAAO,MAAM,cAAc,EAAE,SAAS,SAAS,EAU9C,CAAC;AAEF,kDAAkD;AAClD,eAAO,MAAM,aAAa,EAAE,SAAS,SAAS,EAa7C,CAAC;AAEF,6CAA6C;AAC7C,eAAO,MAAM,YAAY,EAAE,WAAW,CAAC,SAAS,CAAyB,CAAC;AAU1E;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS,CAQrE;AAED;mEACmE;AACnE,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAElD;AAED,6EAA6E;AAC7E,wBAAgB,YAAY,CAAC,KAAK,EAAE,SAAS,GAAG,SAAS,CAMxD"}
|
package/dist/agents/shims.js
CHANGED
|
@@ -425,7 +425,12 @@ const AGENT_SESSION_CAPABILITY = {
|
|
|
425
425
|
supportsSessionDir: true,
|
|
426
426
|
supportsPersistentStdin: true,
|
|
427
427
|
supportsStructuredOutput: true,
|
|
428
|
-
verifiedAgainst: '0.87.
|
|
428
|
+
verifiedAgainst: '0.87.1',
|
|
429
|
+
// Persistent stdin re-verified with a live two-turn capture on 2026-10-23 (task 1277):
|
|
430
|
+
// `--mode rpc --no-session` served two keyed turns in one process with per-turn prompt
|
|
431
|
+
// response + agent_settled. Resume-by-id/session-dir surface carried from the 0.87.0
|
|
432
|
+
// probe (patch-level dependency bump 0.87.0 → 0.87.1, unchanged CLI surface); the
|
|
433
|
+
// turn-session driver pins the same 0.87.1 version (turn-drivers/pi-rpc.ts).
|
|
429
434
|
},
|
|
430
435
|
claude: {
|
|
431
436
|
supportsResumeById: true,
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* Protocol (child → parent):
|
|
10
10
|
* {"ctl":"ready","nativeSessionId":...} handshake (auto-emitted at startup)
|
|
11
11
|
* {"turn":T,"type":"accepted"} | {"turn":T,"type":"output","data":...}
|
|
12
|
-
* {"turn":T,"type":"terminal","kind":"success"|"failure",...}
|
|
12
|
+
* {"turn":T,"type":"terminal","kind":"success"|"failure"|"not-started",...}
|
|
13
13
|
* {"ctl":"exit"} echoes are the raw scripted `stray` lines.
|
|
14
14
|
*/
|
|
15
15
|
import { createInterface } from 'node:readline';
|
|
@@ -10,7 +10,7 @@ export interface FakeTurnAction {
|
|
|
10
10
|
op: 'ready' | 'accept' | 'output' | 'terminal' | 'stray' | 'sleep' | 'ignore-cancel' | 'flood' | 'exit';
|
|
11
11
|
nativeSessionId?: string;
|
|
12
12
|
data?: string;
|
|
13
|
-
kind?: 'success' | 'failure';
|
|
13
|
+
kind?: 'success' | 'failure' | 'not-started';
|
|
14
14
|
nativeTurnId?: string;
|
|
15
15
|
finalText?: string;
|
|
16
16
|
line?: Record<string, unknown>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fake-turn-driver.d.ts","sourceRoot":"","sources":["../../src/testing/fake-turn-driver.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAA6B,iBAAiB,EAAoC,MAAM,iBAAiB,CAAC;AAGtH,mFAAmF;AACnF,MAAM,WAAW,cAAc;IAC3B,EAAE,EAAE,OAAO,GAAG,QAAQ,GAAG,QAAQ,GAAG,UAAU,GAAG,OAAO,GAAG,OAAO,GAAG,eAAe,GAAG,OAAO,GAAG,MAAM,CAAC;IACxG,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,SAAS,GAAG,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"fake-turn-driver.d.ts","sourceRoot":"","sources":["../../src/testing/fake-turn-driver.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAA6B,iBAAiB,EAAoC,MAAM,iBAAiB,CAAC;AAGtH,mFAAmF;AACnF,MAAM,WAAW,cAAc;IAC3B,EAAE,EAAE,OAAO,GAAG,QAAQ,GAAG,QAAQ,GAAG,UAAU,GAAG,OAAO,GAAG,OAAO,GAAG,eAAe,GAAG,OAAO,GAAG,MAAM,CAAC;IACxG,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,SAAS,GAAG,SAAS,GAAG,aAAa,CAAC;IAC7C,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,MAAM,CAAC;CACjB;AAsBD,gHAAgH;AAChH,wBAAgB,2BAA2B,CACvC,OAAO,EAAE,cAAc,EAAE,EACzB,SAAS,GAAE,OAAO,CAAC,IAAI,CAAC,iBAAiB,EAAE,SAAS,GAAG,OAAO,CAAC,CAAM,GACtE,iBAAiB,CAyDnB"}
|
|
@@ -47,7 +47,11 @@ export function createFakeTurnSessionDriver(actions, overrides = {}) {
|
|
|
47
47
|
...(frame.type === 'terminal'
|
|
48
48
|
? {
|
|
49
49
|
terminal: {
|
|
50
|
-
kind: frame.kind === 'failure'
|
|
50
|
+
kind: frame.kind === 'failure'
|
|
51
|
+
? 'failure'
|
|
52
|
+
: frame.kind === 'not-started'
|
|
53
|
+
? 'not-started'
|
|
54
|
+
: 'success',
|
|
51
55
|
...(frame.nativeTurnId !== undefined ? { nativeTurnId: frame.nativeTurnId } : {}),
|
|
52
56
|
...(frame.nativeSessionId !== undefined
|
|
53
57
|
? { nativeSessionId: frame.nativeSessionId }
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { TurnSessionDriver } from '../turn-session';
|
|
2
|
+
/**
|
|
3
|
+
* Pi version this driver's protocol was qualified against: the repository dependency probed live
|
|
4
|
+
* on 2026-10-23 (PATH binary 1.4.0 speaks the same protocol family but is NOT the spawn target —
|
|
5
|
+
* exact provenance recorded here and in the fixtures README).
|
|
6
|
+
*/
|
|
7
|
+
export declare const PI_TURN_VERIFIED_VERSION = "0.87.1";
|
|
8
|
+
/**
|
|
9
|
+
* Build the driver. `spawn` overrides the child argv for tests (the registry instance spawns the
|
|
10
|
+
* real `pi` binary); production callers use `TURN_SESSION_DRIVERS.get('pi')`.
|
|
11
|
+
*/
|
|
12
|
+
export declare function createPiTurnSessionDriver(options?: {
|
|
13
|
+
spawn?: {
|
|
14
|
+
command: string;
|
|
15
|
+
args: string[];
|
|
16
|
+
};
|
|
17
|
+
}): TurnSessionDriver;
|
|
18
|
+
//# sourceMappingURL=pi-rpc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pi-rpc.d.ts","sourceRoot":"","sources":["../../src/turn-drivers/pi-rpc.ts"],"names":[],"mappings":"AA0BA,OAAO,KAAK,EAIR,iBAAiB,EAIpB,MAAM,iBAAiB,CAAC;AAEzB;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,WAAW,CAAC;AAajD;;;GAGG;AACH,wBAAgB,yBAAyB,CACrC,OAAO,GAAE;IAAE,KAAK,CAAC,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,EAAE,CAAA;KAAE,CAAA;CAAO,GAC9D,iBAAiB,CA+HnB"}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pi version this driver's protocol was qualified against: the repository dependency probed live
|
|
3
|
+
* on 2026-10-23 (PATH binary 1.4.0 speaks the same protocol family but is NOT the spawn target —
|
|
4
|
+
* exact provenance recorded here and in the fixtures README).
|
|
5
|
+
*/
|
|
6
|
+
export const PI_TURN_VERIFIED_VERSION = '0.87.1';
|
|
7
|
+
/**
|
|
8
|
+
* Build the driver. `spawn` overrides the child argv for tests (the registry instance spawns the
|
|
9
|
+
* real `pi` binary); production callers use `TURN_SESSION_DRIVERS.get('pi')`.
|
|
10
|
+
*/
|
|
11
|
+
export function createPiTurnSessionDriver(options = {}) {
|
|
12
|
+
return {
|
|
13
|
+
agent: 'pi',
|
|
14
|
+
qualify: (binary) => binary.version === PI_TURN_VERIFIED_VERSION
|
|
15
|
+
? { qualified: true }
|
|
16
|
+
: {
|
|
17
|
+
qualified: false,
|
|
18
|
+
reason: `pi ${binary.version ?? '<no version>'} is not the qualified rpc version ${PI_TURN_VERIFIED_VERSION}`,
|
|
19
|
+
},
|
|
20
|
+
spawnArgv: (_binary, policy) => options.spawn ?? {
|
|
21
|
+
command: 'pi',
|
|
22
|
+
args: [
|
|
23
|
+
'--mode',
|
|
24
|
+
'rpc',
|
|
25
|
+
'--no-session',
|
|
26
|
+
...(policy.model !== undefined ? ['--model', policy.model] : []),
|
|
27
|
+
],
|
|
28
|
+
},
|
|
29
|
+
// No handshake: pi has no startup session record — the prompt command id carries the
|
|
30
|
+
// correlation, and early stdin writes are processed after extension startup (observed:
|
|
31
|
+
// a command written during startup noise is answered in order).
|
|
32
|
+
encodeTurn: (input) =>
|
|
33
|
+
// The id echoes on the acceptance response — self-attributing protocol (R3).
|
|
34
|
+
`${JSON.stringify({ id: input.turnId, type: 'prompt', message: input.prompt })}\n`,
|
|
35
|
+
decode: (line, context) => {
|
|
36
|
+
let record;
|
|
37
|
+
try {
|
|
38
|
+
record = JSON.parse(line);
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
// Plain Error, not TurnProtocolError: importing the class would make this module
|
|
42
|
+
// a runtime dependency of turn-session.ts (which registers this driver). The pump
|
|
43
|
+
// settles contract-violation for ANY decoder throw, which is the real contract.
|
|
44
|
+
const error = new Error(`pi rpc: malformed JSON line: ${line.slice(0, 80)}`);
|
|
45
|
+
error.name = 'TurnProtocolError';
|
|
46
|
+
throw error;
|
|
47
|
+
}
|
|
48
|
+
// Acceptance/failure for the turn whose prompt command this response answers.
|
|
49
|
+
if (record.type === 'response' && record.command === 'prompt') {
|
|
50
|
+
if (context === undefined || record.id !== context.turnId)
|
|
51
|
+
return [];
|
|
52
|
+
// Acceptance echoes once per prompt command; an already-accepted turn gets no
|
|
53
|
+
// duplicate frame (pump contract, same as claude's repeated init).
|
|
54
|
+
if (context.accepted && record.success === true)
|
|
55
|
+
return [];
|
|
56
|
+
if (record.success !== true) {
|
|
57
|
+
return [
|
|
58
|
+
{
|
|
59
|
+
turnId: context.turnId,
|
|
60
|
+
type: 'terminal',
|
|
61
|
+
terminal: {
|
|
62
|
+
// Pre-acceptance rejection = the turn never started (uniform
|
|
63
|
+
// session rule, same classification as the process-exit path);
|
|
64
|
+
// post-acceptance is a definite failure.
|
|
65
|
+
kind: context.accepted ? 'failure' : 'not-started',
|
|
66
|
+
reason: `pi rejected the prompt command: ${record.error ?? 'unspecified error'}`,
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
];
|
|
70
|
+
}
|
|
71
|
+
// 1.4.0 reports `data.disposition`; "handled" means no run started for this prompt.
|
|
72
|
+
const disposition = record.data?.disposition;
|
|
73
|
+
if (disposition !== undefined && disposition !== 'started') {
|
|
74
|
+
return [
|
|
75
|
+
{
|
|
76
|
+
turnId: context.turnId,
|
|
77
|
+
type: 'terminal',
|
|
78
|
+
terminal: {
|
|
79
|
+
kind: 'failure',
|
|
80
|
+
reason: `pi prompt disposition '${disposition}' did not start a run`,
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
];
|
|
84
|
+
}
|
|
85
|
+
return [{ turnId: context.turnId, type: 'accepted' }];
|
|
86
|
+
}
|
|
87
|
+
// A parse response means one of OUR command records did not parse — framing broke.
|
|
88
|
+
if (record.type === 'response' && record.command === 'parse' && context !== undefined) {
|
|
89
|
+
return [
|
|
90
|
+
{
|
|
91
|
+
turnId: context.turnId,
|
|
92
|
+
type: 'terminal',
|
|
93
|
+
terminal: {
|
|
94
|
+
kind: 'failure',
|
|
95
|
+
reason: `pi failed to parse a command record: ${record.error ?? 'unspecified error'}`,
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
];
|
|
99
|
+
}
|
|
100
|
+
// The terminal: agent_settled is the only completion evidence (agent_end can precede
|
|
101
|
+
// retries). Session-level record — attributed to the active turn via context.
|
|
102
|
+
if (record.type === 'agent_settled') {
|
|
103
|
+
if (context === undefined)
|
|
104
|
+
return [];
|
|
105
|
+
const terminal = { kind: 'success' };
|
|
106
|
+
if (record.aborted === true) {
|
|
107
|
+
terminal.kind = 'failure';
|
|
108
|
+
terminal.reason = 'pi agent settled with aborted: true';
|
|
109
|
+
}
|
|
110
|
+
return [{ turnId: context.turnId, type: 'terminal', terminal }];
|
|
111
|
+
}
|
|
112
|
+
// Assistant final message → output (the consumer extracts final text/artifacts from
|
|
113
|
+
// the event stream; `agent_settled` carries no text payload).
|
|
114
|
+
if (record.type === 'message_end' && record.message?.role === 'assistant' && context !== undefined) {
|
|
115
|
+
return [{ turnId: context.turnId, type: 'output', data: record }];
|
|
116
|
+
}
|
|
117
|
+
// extension_ui_request / agent_start / turn_start|end / message_update|start /
|
|
118
|
+
// session_info_changed / tool_execution_* / auto_retry_* / abort response — noise.
|
|
119
|
+
return [];
|
|
120
|
+
},
|
|
121
|
+
encodeCancel: (_reason) =>
|
|
122
|
+
// Abort command (pi docs rpc-commands.md; observed 0.87.1: the active tool call ends
|
|
123
|
+
// with "Command aborted", the run settles, then the abort response arrives).
|
|
124
|
+
`${JSON.stringify({ type: 'abort' })}\n`,
|
|
125
|
+
handshake: async (pull) => {
|
|
126
|
+
// Readiness probe: drain up to the first parseable record so the extension startup
|
|
127
|
+
// has begun before the first turn is written. Any parseable protocol record proves
|
|
128
|
+
// the process is alive and speaking JSONL; startup noise is not otherwise needed.
|
|
129
|
+
for (let seen = 0; seen < 32; seen += 1) {
|
|
130
|
+
const line = await pull(2_000);
|
|
131
|
+
if (line === null)
|
|
132
|
+
return null; // EOF before the process spoke
|
|
133
|
+
try {
|
|
134
|
+
JSON.parse(line);
|
|
135
|
+
return {};
|
|
136
|
+
}
|
|
137
|
+
catch { }
|
|
138
|
+
}
|
|
139
|
+
return null;
|
|
140
|
+
},
|
|
141
|
+
};
|
|
142
|
+
}
|
package/dist/turn-session.d.ts
CHANGED
|
@@ -100,7 +100,7 @@ export interface TurnBinary {
|
|
|
100
100
|
}
|
|
101
101
|
/** A wire-level terminal extracted from one decoded line. */
|
|
102
102
|
export interface TurnWireTerminal {
|
|
103
|
-
kind: 'success' | 'failure';
|
|
103
|
+
kind: 'success' | 'failure' | 'not-started';
|
|
104
104
|
nativeTurnId?: string;
|
|
105
105
|
nativeSessionId?: string;
|
|
106
106
|
finalText?: string;
|
|
@@ -179,7 +179,8 @@ export type OpenTurnSessionResult = {
|
|
|
179
179
|
/**
|
|
180
180
|
* Built-in driver registry. Entries land only with recorded qualification evidence (anti-pattern:
|
|
181
181
|
* registration without evidence): claude 2.1.308 stream-json (task 1276, fixtures under
|
|
182
|
-
* `tests/fixtures/turn-drivers/claude`)
|
|
182
|
+
* `tests/fixtures/turn-drivers/claude`) and pi 0.87.1 rpc (task 1277, fixtures under
|
|
183
|
+
* `tests/fixtures/turn-drivers/pi`). 0.x shipped this empty by design.
|
|
183
184
|
*/
|
|
184
185
|
export declare const TURN_SESSION_DRIVERS: ReadonlyMap<AgentName, TurnSessionDriver>;
|
|
185
186
|
/** How long `cancel()` waits for native terminal evidence before resolving `outcome-unknown`. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"turn-session.d.ts","sourceRoot":"","sources":["../src/turn-session.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAe,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC1E,OAA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CAClB,CAAC;AAER;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,EAAE,WAAW,CAAC,SAAS,EAAE,iBAAiB,CAGzE,CAAC;AAEH,iGAAiG;AACjG,eAAO,MAAM,oBAAoB,OAAQ,CAAC;AAC1C,6CAA6C;AAC7C,eAAO,MAAM,yBAAyB,QAAS,CAAC;AAChD,2EAA2E;AAC3E,eAAO,MAAM,mBAAmB,QAAc,CAAC;AAE/C,6EAA6E;AAC7E,qBAAa,oBAAqB,SAAQ,KAAK;gBAC/B,MAAM,EAAE,MAAM;CAI7B;AAED,uCAAuC;AACvC,qBAAa,sBAAuB,SAAQ,KAAK;;CAKhD;AAED,uGAAuG;AACvG,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,iBAAiB,GAAG,MAAM,CAezE;AAED;;;;GAIG;AACH,wBAAuB,SAAS,CAAC,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC,GAAG,cAAc,CAAC,MAAM,CAAC,CAyB3F;AA0TD;;;;GAIG;AACH,wBAAsB,yBAAyB,CAAC,OAAO,EAAE;IACrD,KAAK,EAAE,SAAS,CAAC;IACjB,MAAM,EAAE,iBAAiB,GAAG,SAAS,CAAC;IACtC,MAAM,EAAE,iBAAiB,CAAC;IAC1B,MAAM,EAAE,UAAU,CAAC;IACnB,eAAe,EAAE,eAAe,CAAC;IACjC,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC/B,GAAG,OAAO,CAAC,qBAAqB,CAAC,CA0EjC"}
|
package/dist/turn-session.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createHash, randomUUID } from 'node:crypto';
|
|
2
2
|
import { createClaudeTurnSessionDriver } from './turn-drivers/claude-stream-json.js';
|
|
3
|
+
import { createPiTurnSessionDriver } from './turn-drivers/pi-rpc.js';
|
|
3
4
|
/** Thrown by `TurnSessionDriver.decode` on a malformed frame — settles the turn `contract-violation`. */
|
|
4
5
|
export class TurnProtocolError extends Error {
|
|
5
6
|
constructor(message) {
|
|
@@ -10,10 +11,12 @@ export class TurnProtocolError extends Error {
|
|
|
10
11
|
/**
|
|
11
12
|
* Built-in driver registry. Entries land only with recorded qualification evidence (anti-pattern:
|
|
12
13
|
* registration without evidence): claude 2.1.308 stream-json (task 1276, fixtures under
|
|
13
|
-
* `tests/fixtures/turn-drivers/claude`)
|
|
14
|
+
* `tests/fixtures/turn-drivers/claude`) and pi 0.87.1 rpc (task 1277, fixtures under
|
|
15
|
+
* `tests/fixtures/turn-drivers/pi`). 0.x shipped this empty by design.
|
|
14
16
|
*/
|
|
15
17
|
export const TURN_SESSION_DRIVERS = new Map([
|
|
16
18
|
['claude', createClaudeTurnSessionDriver()],
|
|
19
|
+
['pi', createPiTurnSessionDriver()],
|
|
17
20
|
]);
|
|
18
21
|
/** How long `cancel()` waits for native terminal evidence before resolving `outcome-unknown`. */
|
|
19
22
|
export const TURN_CANCEL_GRACE_MS = 5_000;
|
|
@@ -309,11 +312,9 @@ class TurnSessionImpl {
|
|
|
309
312
|
return;
|
|
310
313
|
}
|
|
311
314
|
if (wire.type === 'terminal' && wire.terminal !== undefined) {
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
? 'success'
|
|
316
|
-
: 'failure';
|
|
315
|
+
// Decoder terminals carry their own pre-acceptance classification (`not-started`);
|
|
316
|
+
// cancel precedence still wins over whatever the wire reported.
|
|
317
|
+
const kind = turn.cancelRequested ? 'interrupted' : wire.terminal.kind;
|
|
317
318
|
turn.settle({
|
|
318
319
|
kind,
|
|
319
320
|
...(wire.terminal.nativeTurnId !== undefined ? { nativeTurnId: wire.terminal.nativeTurnId } : {}),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gobing-ai/ts-ai-runner",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.4",
|
|
4
4
|
"description": "@gobing-ai/ts-ai-runner — Coding-agent shims, detection, doctor checks, and prompt execution.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -51,12 +51,12 @@
|
|
|
51
51
|
"release": "echo 'Manual publish is disabled. Releases go through GitHub Actions via Trusted Publishing — push a tag: git tag @gobing-ai/ts-ai-runner-v<version> && git push --tags' && exit 1"
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"@gobing-ai/ts-infra": "^0.6.
|
|
55
|
-
"@gobing-ai/ts-runtime": "^0.6.
|
|
54
|
+
"@gobing-ai/ts-infra": "^0.6.4",
|
|
55
|
+
"@gobing-ai/ts-runtime": "^0.6.4"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"@types/bun": "1.4.3",
|
|
59
|
-
"@gobing-ai/ts-db": "^0.6.
|
|
59
|
+
"@gobing-ai/ts-db": "^0.6.4"
|
|
60
60
|
},
|
|
61
61
|
"publishConfig": {
|
|
62
62
|
"access": "public"
|
package/src/agents/shims.ts
CHANGED
|
@@ -548,7 +548,12 @@ const AGENT_SESSION_CAPABILITY: Readonly<Record<AgentName, AgentSessionCapabilit
|
|
|
548
548
|
supportsSessionDir: true,
|
|
549
549
|
supportsPersistentStdin: true,
|
|
550
550
|
supportsStructuredOutput: true,
|
|
551
|
-
verifiedAgainst: '0.87.
|
|
551
|
+
verifiedAgainst: '0.87.1',
|
|
552
|
+
// Persistent stdin re-verified with a live two-turn capture on 2026-10-23 (task 1277):
|
|
553
|
+
// `--mode rpc --no-session` served two keyed turns in one process with per-turn prompt
|
|
554
|
+
// response + agent_settled. Resume-by-id/session-dir surface carried from the 0.87.0
|
|
555
|
+
// probe (patch-level dependency bump 0.87.0 → 0.87.1, unchanged CLI surface); the
|
|
556
|
+
// turn-session driver pins the same 0.87.1 version (turn-drivers/pi-rpc.ts).
|
|
552
557
|
},
|
|
553
558
|
claude: {
|
|
554
559
|
supportsResumeById: true,
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* Protocol (child → parent):
|
|
10
10
|
* {"ctl":"ready","nativeSessionId":...} handshake (auto-emitted at startup)
|
|
11
11
|
* {"turn":T,"type":"accepted"} | {"turn":T,"type":"output","data":...}
|
|
12
|
-
* {"turn":T,"type":"terminal","kind":"success"|"failure",...}
|
|
12
|
+
* {"turn":T,"type":"terminal","kind":"success"|"failure"|"not-started",...}
|
|
13
13
|
* {"ctl":"exit"} echoes are the raw scripted `stray` lines.
|
|
14
14
|
*/
|
|
15
15
|
import { createInterface } from 'node:readline';
|
|
@@ -18,7 +18,7 @@ interface FakeAction {
|
|
|
18
18
|
op: 'ready' | 'accept' | 'output' | 'terminal' | 'stray' | 'sleep' | 'ignore-cancel' | 'flood' | 'exit';
|
|
19
19
|
nativeSessionId?: string;
|
|
20
20
|
data?: string;
|
|
21
|
-
kind?: 'success' | 'failure';
|
|
21
|
+
kind?: 'success' | 'failure' | 'not-started';
|
|
22
22
|
nativeTurnId?: string;
|
|
23
23
|
finalText?: string;
|
|
24
24
|
line?: Record<string, unknown>;
|
|
@@ -12,7 +12,7 @@ export interface FakeTurnAction {
|
|
|
12
12
|
op: 'ready' | 'accept' | 'output' | 'terminal' | 'stray' | 'sleep' | 'ignore-cancel' | 'flood' | 'exit';
|
|
13
13
|
nativeSessionId?: string;
|
|
14
14
|
data?: string;
|
|
15
|
-
kind?: 'success' | 'failure';
|
|
15
|
+
kind?: 'success' | 'failure' | 'not-started';
|
|
16
16
|
nativeTurnId?: string;
|
|
17
17
|
finalText?: string;
|
|
18
18
|
line?: Record<string, unknown>;
|
|
@@ -80,7 +80,12 @@ export function createFakeTurnSessionDriver(
|
|
|
80
80
|
...(frame.type === 'terminal'
|
|
81
81
|
? {
|
|
82
82
|
terminal: {
|
|
83
|
-
kind:
|
|
83
|
+
kind:
|
|
84
|
+
frame.kind === 'failure'
|
|
85
|
+
? 'failure'
|
|
86
|
+
: frame.kind === 'not-started'
|
|
87
|
+
? 'not-started'
|
|
88
|
+
: 'success',
|
|
84
89
|
...(frame.nativeTurnId !== undefined ? { nativeTurnId: frame.nativeTurnId } : {}),
|
|
85
90
|
...(frame.nativeSessionId !== undefined
|
|
86
91
|
? { nativeSessionId: frame.nativeSessionId }
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pi RPC turn-session driver (task 1277, design `fleet-task-turn-execution.md` §5). Speaks the
|
|
3
|
+
* protocol observed on the repository dependency `pi` 0.87.1 binary (captured 2026-10-23 via live
|
|
4
|
+
* single-turn, two-turn and mid-run-abort probes; fixtures under `tests/fixtures/turn-drivers/pi`):
|
|
5
|
+
*
|
|
6
|
+
* - `pi --mode rpc --no-session` keeps ONE process alive; commands are JSONL on stdin and every
|
|
7
|
+
* command may carry an `id` that its `response` echoes. The driver uses the runner turn id as
|
|
8
|
+
* the prompt command id, so acceptance is self-attributing (unlike claude stream-json).
|
|
9
|
+
* - A prompt `response` (success) means ACCEPTANCE, never completion: `agent_end` can be followed
|
|
10
|
+
* by retries/compaction; the turn terminal is `agent_settled`.
|
|
11
|
+
* - Startup and inter-turn noise is `extension_ui_request` rows (powerline/status extensions) and
|
|
12
|
+
* can interleave anywhere; tolerated and ignored.
|
|
13
|
+
* - Failure signals are response-level: a `success: false` prompt response, a `parse` response
|
|
14
|
+
* (our command record did not parse), or `agent_settled` with `aborted: true` (observed on the
|
|
15
|
+
* 1.4.0 PATH binary; 0.87.1 settles aborts without the field — the facade's cancel-requested
|
|
16
|
+
* path classifies those as `interrupted`, and mid-run provider failures settle success-shaped
|
|
17
|
+
* with the error visible in the event stream, where the consumer's artifact validation acts).
|
|
18
|
+
* - Version differences observed between the qualified 0.87.1 and the PATH 1.4.0 binary: 1.4.0
|
|
19
|
+
* adds `data.disposition` on the prompt response and `aborted` on `agent_settled`. The decoder
|
|
20
|
+
* tolerates both shapes; qualification pins 0.87.1 (the binary the Spur warm seam spawns).
|
|
21
|
+
*
|
|
22
|
+
* Protocol records echo no payload turn id beyond the command id, so `decode` attributes frames
|
|
23
|
+
* by `record.id` when present and falls back to the facade-provided active turn for session-level
|
|
24
|
+
* records (`agent_settled` carries no id).
|
|
25
|
+
*/
|
|
26
|
+
import type { AgentName } from '../agents/shims';
|
|
27
|
+
import type {
|
|
28
|
+
TurnBinary,
|
|
29
|
+
TurnDecodeContext,
|
|
30
|
+
TurnHandshake,
|
|
31
|
+
TurnSessionDriver,
|
|
32
|
+
TurnSessionPolicy,
|
|
33
|
+
TurnWireEvent,
|
|
34
|
+
TurnWireTerminal,
|
|
35
|
+
} from '../turn-session';
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Pi version this driver's protocol was qualified against: the repository dependency probed live
|
|
39
|
+
* on 2026-10-23 (PATH binary 1.4.0 speaks the same protocol family but is NOT the spawn target —
|
|
40
|
+
* exact provenance recorded here and in the fixtures README).
|
|
41
|
+
*/
|
|
42
|
+
export const PI_TURN_VERIFIED_VERSION = '0.87.1';
|
|
43
|
+
|
|
44
|
+
interface PiRecord {
|
|
45
|
+
type?: string;
|
|
46
|
+
id?: string;
|
|
47
|
+
command?: string;
|
|
48
|
+
success?: boolean;
|
|
49
|
+
error?: string;
|
|
50
|
+
aborted?: boolean;
|
|
51
|
+
data?: { disposition?: string };
|
|
52
|
+
message?: { role?: string };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Build the driver. `spawn` overrides the child argv for tests (the registry instance spawns the
|
|
57
|
+
* real `pi` binary); production callers use `TURN_SESSION_DRIVERS.get('pi')`.
|
|
58
|
+
*/
|
|
59
|
+
export function createPiTurnSessionDriver(
|
|
60
|
+
options: { spawn?: { command: string; args: string[] } } = {},
|
|
61
|
+
): TurnSessionDriver {
|
|
62
|
+
return {
|
|
63
|
+
agent: 'pi' as AgentName,
|
|
64
|
+
qualify: (binary: TurnBinary) =>
|
|
65
|
+
binary.version === PI_TURN_VERIFIED_VERSION
|
|
66
|
+
? { qualified: true }
|
|
67
|
+
: {
|
|
68
|
+
qualified: false,
|
|
69
|
+
reason: `pi ${binary.version ?? '<no version>'} is not the qualified rpc version ${PI_TURN_VERIFIED_VERSION}`,
|
|
70
|
+
},
|
|
71
|
+
spawnArgv: (_binary: TurnBinary, policy: TurnSessionPolicy) =>
|
|
72
|
+
options.spawn ?? {
|
|
73
|
+
command: 'pi',
|
|
74
|
+
args: [
|
|
75
|
+
'--mode',
|
|
76
|
+
'rpc',
|
|
77
|
+
'--no-session',
|
|
78
|
+
...(policy.model !== undefined ? ['--model', policy.model] : []),
|
|
79
|
+
],
|
|
80
|
+
},
|
|
81
|
+
// No handshake: pi has no startup session record — the prompt command id carries the
|
|
82
|
+
// correlation, and early stdin writes are processed after extension startup (observed:
|
|
83
|
+
// a command written during startup noise is answered in order).
|
|
84
|
+
encodeTurn: (input: { turnId: string; prompt: string }) =>
|
|
85
|
+
// The id echoes on the acceptance response — self-attributing protocol (R3).
|
|
86
|
+
`${JSON.stringify({ id: input.turnId, type: 'prompt', message: input.prompt })}\n`,
|
|
87
|
+
decode: (line: string, context?: TurnDecodeContext): TurnWireEvent[] => {
|
|
88
|
+
let record: PiRecord;
|
|
89
|
+
try {
|
|
90
|
+
record = JSON.parse(line) as PiRecord;
|
|
91
|
+
} catch {
|
|
92
|
+
// Plain Error, not TurnProtocolError: importing the class would make this module
|
|
93
|
+
// a runtime dependency of turn-session.ts (which registers this driver). The pump
|
|
94
|
+
// settles contract-violation for ANY decoder throw, which is the real contract.
|
|
95
|
+
const error = new Error(`pi rpc: malformed JSON line: ${line.slice(0, 80)}`);
|
|
96
|
+
error.name = 'TurnProtocolError';
|
|
97
|
+
throw error;
|
|
98
|
+
}
|
|
99
|
+
// Acceptance/failure for the turn whose prompt command this response answers.
|
|
100
|
+
if (record.type === 'response' && record.command === 'prompt') {
|
|
101
|
+
if (context === undefined || record.id !== context.turnId) return [];
|
|
102
|
+
// Acceptance echoes once per prompt command; an already-accepted turn gets no
|
|
103
|
+
// duplicate frame (pump contract, same as claude's repeated init).
|
|
104
|
+
if (context.accepted && record.success === true) return [];
|
|
105
|
+
if (record.success !== true) {
|
|
106
|
+
return [
|
|
107
|
+
{
|
|
108
|
+
turnId: context.turnId,
|
|
109
|
+
type: 'terminal',
|
|
110
|
+
terminal: {
|
|
111
|
+
// Pre-acceptance rejection = the turn never started (uniform
|
|
112
|
+
// session rule, same classification as the process-exit path);
|
|
113
|
+
// post-acceptance is a definite failure.
|
|
114
|
+
kind: context.accepted ? 'failure' : 'not-started',
|
|
115
|
+
reason: `pi rejected the prompt command: ${record.error ?? 'unspecified error'}`,
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
];
|
|
119
|
+
}
|
|
120
|
+
// 1.4.0 reports `data.disposition`; "handled" means no run started for this prompt.
|
|
121
|
+
const disposition = record.data?.disposition;
|
|
122
|
+
if (disposition !== undefined && disposition !== 'started') {
|
|
123
|
+
return [
|
|
124
|
+
{
|
|
125
|
+
turnId: context.turnId,
|
|
126
|
+
type: 'terminal',
|
|
127
|
+
terminal: {
|
|
128
|
+
kind: 'failure',
|
|
129
|
+
reason: `pi prompt disposition '${disposition}' did not start a run`,
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
];
|
|
133
|
+
}
|
|
134
|
+
return [{ turnId: context.turnId, type: 'accepted' }];
|
|
135
|
+
}
|
|
136
|
+
// A parse response means one of OUR command records did not parse — framing broke.
|
|
137
|
+
if (record.type === 'response' && record.command === 'parse' && context !== undefined) {
|
|
138
|
+
return [
|
|
139
|
+
{
|
|
140
|
+
turnId: context.turnId,
|
|
141
|
+
type: 'terminal',
|
|
142
|
+
terminal: {
|
|
143
|
+
kind: 'failure',
|
|
144
|
+
reason: `pi failed to parse a command record: ${record.error ?? 'unspecified error'}`,
|
|
145
|
+
},
|
|
146
|
+
},
|
|
147
|
+
];
|
|
148
|
+
}
|
|
149
|
+
// The terminal: agent_settled is the only completion evidence (agent_end can precede
|
|
150
|
+
// retries). Session-level record — attributed to the active turn via context.
|
|
151
|
+
if (record.type === 'agent_settled') {
|
|
152
|
+
if (context === undefined) return [];
|
|
153
|
+
const terminal: TurnWireTerminal = { kind: 'success' };
|
|
154
|
+
if (record.aborted === true) {
|
|
155
|
+
terminal.kind = 'failure';
|
|
156
|
+
terminal.reason = 'pi agent settled with aborted: true';
|
|
157
|
+
}
|
|
158
|
+
return [{ turnId: context.turnId, type: 'terminal', terminal }];
|
|
159
|
+
}
|
|
160
|
+
// Assistant final message → output (the consumer extracts final text/artifacts from
|
|
161
|
+
// the event stream; `agent_settled` carries no text payload).
|
|
162
|
+
if (record.type === 'message_end' && record.message?.role === 'assistant' && context !== undefined) {
|
|
163
|
+
return [{ turnId: context.turnId, type: 'output', data: record }];
|
|
164
|
+
}
|
|
165
|
+
// extension_ui_request / agent_start / turn_start|end / message_update|start /
|
|
166
|
+
// session_info_changed / tool_execution_* / auto_retry_* / abort response — noise.
|
|
167
|
+
return [];
|
|
168
|
+
},
|
|
169
|
+
encodeCancel: (_reason: string) =>
|
|
170
|
+
// Abort command (pi docs rpc-commands.md; observed 0.87.1: the active tool call ends
|
|
171
|
+
// with "Command aborted", the run settles, then the abort response arrives).
|
|
172
|
+
`${JSON.stringify({ type: 'abort' })}\n`,
|
|
173
|
+
handshake: async (pull: (timeoutMs: number) => Promise<string | null>): Promise<TurnHandshake> => {
|
|
174
|
+
// Readiness probe: drain up to the first parseable record so the extension startup
|
|
175
|
+
// has begun before the first turn is written. Any parseable protocol record proves
|
|
176
|
+
// the process is alive and speaking JSONL; startup noise is not otherwise needed.
|
|
177
|
+
for (let seen = 0; seen < 32; seen += 1) {
|
|
178
|
+
const line = await pull(2_000);
|
|
179
|
+
if (line === null) return null; // EOF before the process spoke
|
|
180
|
+
try {
|
|
181
|
+
JSON.parse(line) as PiRecord;
|
|
182
|
+
return {};
|
|
183
|
+
} catch {}
|
|
184
|
+
}
|
|
185
|
+
return null;
|
|
186
|
+
},
|
|
187
|
+
};
|
|
188
|
+
}
|
package/src/turn-session.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { createHash, randomUUID } from 'node:crypto';
|
|
|
2
2
|
import type { PipeProcess, ProcessExecutor } from '@gobing-ai/ts-runtime';
|
|
3
3
|
import type { AgentName } from './agents/shims';
|
|
4
4
|
import { createClaudeTurnSessionDriver } from './turn-drivers/claude-stream-json';
|
|
5
|
+
import { createPiTurnSessionDriver } from './turn-drivers/pi-rpc';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Correlated warm-turn session facade (task 1284, design `fleet-task-turn-execution.md` §4–5,
|
|
@@ -99,7 +100,9 @@ export interface TurnBinary {
|
|
|
99
100
|
|
|
100
101
|
/** A wire-level terminal extracted from one decoded line. */
|
|
101
102
|
export interface TurnWireTerminal {
|
|
102
|
-
|
|
103
|
+
// `not-started` is the pre-acceptance definite-end classification (e.g. pi rejecting the
|
|
104
|
+
// prompt command before any run started) — it must survive the facade mapping unchanged.
|
|
105
|
+
kind: 'success' | 'failure' | 'not-started';
|
|
103
106
|
nativeTurnId?: string;
|
|
104
107
|
nativeSessionId?: string;
|
|
105
108
|
finalText?: string;
|
|
@@ -173,10 +176,12 @@ export type OpenTurnSessionResult =
|
|
|
173
176
|
/**
|
|
174
177
|
* Built-in driver registry. Entries land only with recorded qualification evidence (anti-pattern:
|
|
175
178
|
* registration without evidence): claude 2.1.308 stream-json (task 1276, fixtures under
|
|
176
|
-
* `tests/fixtures/turn-drivers/claude`)
|
|
179
|
+
* `tests/fixtures/turn-drivers/claude`) and pi 0.87.1 rpc (task 1277, fixtures under
|
|
180
|
+
* `tests/fixtures/turn-drivers/pi`). 0.x shipped this empty by design.
|
|
177
181
|
*/
|
|
178
182
|
export const TURN_SESSION_DRIVERS: ReadonlyMap<AgentName, TurnSessionDriver> = new Map([
|
|
179
183
|
['claude', createClaudeTurnSessionDriver()],
|
|
184
|
+
['pi', createPiTurnSessionDriver()],
|
|
180
185
|
]);
|
|
181
186
|
|
|
182
187
|
/** How long `cancel()` waits for native terminal evidence before resolving `outcome-unknown`. */
|
|
@@ -497,11 +502,9 @@ class TurnSessionImpl implements TurnSession {
|
|
|
497
502
|
return;
|
|
498
503
|
}
|
|
499
504
|
if (wire.type === 'terminal' && wire.terminal !== undefined) {
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
? 'success'
|
|
504
|
-
: 'failure';
|
|
505
|
+
// Decoder terminals carry their own pre-acceptance classification (`not-started`);
|
|
506
|
+
// cancel precedence still wins over whatever the wire reported.
|
|
507
|
+
const kind: TurnOutcomeKind = turn.cancelRequested ? 'interrupted' : wire.terminal.kind;
|
|
505
508
|
turn.settle({
|
|
506
509
|
kind,
|
|
507
510
|
...(wire.terminal.nativeTurnId !== undefined ? { nativeTurnId: wire.terminal.nativeTurnId } : {}),
|