@gobing-ai/ts-ai-runner 0.6.1 → 0.6.3
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 +5 -0
- package/dist/agents/shims.d.ts.map +1 -1
- package/dist/agents/shims.js +22 -12
- 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 +139 -0
- package/dist/turn-session.d.ts +2 -1
- package/dist/turn-session.d.ts.map +1 -1
- package/dist/turn-session.js +4 -1
- package/package.json +4 -4
- package/src/agents/shims.ts +22 -12
- package/src/turn-drivers/pi-rpc.ts +185 -0
- package/src/turn-session.ts +4 -1
package/README.md
CHANGED
|
@@ -934,6 +934,11 @@ 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.
|
|
937
942
|
- This package is a command adapter, not an agent orchestration framework.- It does not install agent CLIs or manage credentials.
|
|
938
943
|
- It does not parse agent responses beyond process result capture.
|
|
939
944
|
- 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,g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AAC;AAEF,kEAAkE;AAClE,MAAM,WAAW,sBAAsB;IACnC,oFAAoF;IACpF,QAAQ,CAAC,kBAAkB,EAAE,OAAO,CAAC;IACrC,oEAAoE;IACpE,QAAQ,CAAC,kBAAkB,EAAE,OAAO,CAAC;IACrC,2GAA2G;IAC3G,QAAQ,CAAC,uBAAuB,EAAE,OAAO,CAAC;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
|
@@ -168,17 +168,22 @@ const antigravityCliShim = {
|
|
|
168
168
|
getHelpCommand: () => ({ command: 'agy', args: ['--help'] }),
|
|
169
169
|
getVersionCommand: () => ({ command: 'agy', args: ['--version'] }),
|
|
170
170
|
getPromptCommand: (options) => {
|
|
171
|
-
// Print mode is headless: agy auto-denies any tool that would prompt
|
|
172
|
-
//
|
|
173
|
-
//
|
|
174
|
-
//
|
|
175
|
-
//
|
|
176
|
-
//
|
|
177
|
-
//
|
|
178
|
-
//
|
|
179
|
-
//
|
|
180
|
-
//
|
|
181
|
-
|
|
171
|
+
// Print mode is headless: agy auto-denies any tool that would prompt,
|
|
172
|
+
// so expectFile-style automation dead-ends without a permission
|
|
173
|
+
// affordance (spur 0689). `--mode accept-edits` alone proved too narrow
|
|
174
|
+
// in the field (spur task 1276 review lane, 2026-10-23): the sandbox
|
|
175
|
+
// (toolPermission=proceed-in-sandbox) blocked reads outside the
|
|
176
|
+
// workspace (~/.gitconfig) and hard-denied allowlisted-command
|
|
177
|
+
// variants (e.g. `bun <script>` vs the built-in `bun run` prefix),
|
|
178
|
+
// producing exit-0 empty answers from healthy models. The CLI's own
|
|
179
|
+
// documented remedy for headless automation is
|
|
180
|
+
// `--dangerously-skip-permissions` (auto-approve all tool permission
|
|
181
|
+
// requests, sandbox included). Trust assumption (0689, widened with
|
|
182
|
+
// operator sanction 2026-10-23): the dispatch is an operator-initiated,
|
|
183
|
+
// headless, workspace-scoped subprocess running agent-emitted commands
|
|
184
|
+
// under the caller's supervision; the flag is scoped to print mode
|
|
185
|
+
// only — interactive agy sessions keep their own permission flow.
|
|
186
|
+
const args = ['-p', options.input ?? '', '--mode', 'accept-edits', '--dangerously-skip-permissions'];
|
|
182
187
|
if (options.timeoutMs !== undefined)
|
|
183
188
|
args.push('--print-timeout', `${options.timeoutMs}ms`);
|
|
184
189
|
// Headless agy resolves relative file-tool paths against a scratch dir,
|
|
@@ -420,7 +425,12 @@ const AGENT_SESSION_CAPABILITY = {
|
|
|
420
425
|
supportsSessionDir: true,
|
|
421
426
|
supportsPersistentStdin: true,
|
|
422
427
|
supportsStructuredOutput: true,
|
|
423
|
-
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).
|
|
424
434
|
},
|
|
425
435
|
claude: {
|
|
426
436
|
supportsResumeById: true,
|
|
@@ -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,CA4HnB"}
|
|
@@ -0,0 +1,139 @@
|
|
|
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
|
+
kind: 'failure',
|
|
63
|
+
reason: `pi rejected the prompt command: ${record.error ?? 'unspecified error'}`,
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
];
|
|
67
|
+
}
|
|
68
|
+
// 1.4.0 reports `data.disposition`; "handled" means no run started for this prompt.
|
|
69
|
+
const disposition = record.data?.disposition;
|
|
70
|
+
if (disposition !== undefined && disposition !== 'started') {
|
|
71
|
+
return [
|
|
72
|
+
{
|
|
73
|
+
turnId: context.turnId,
|
|
74
|
+
type: 'terminal',
|
|
75
|
+
terminal: {
|
|
76
|
+
kind: 'failure',
|
|
77
|
+
reason: `pi prompt disposition '${disposition}' did not start a run`,
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
];
|
|
81
|
+
}
|
|
82
|
+
return [{ turnId: context.turnId, type: 'accepted' }];
|
|
83
|
+
}
|
|
84
|
+
// A parse response means one of OUR command records did not parse — framing broke.
|
|
85
|
+
if (record.type === 'response' && record.command === 'parse' && context !== undefined) {
|
|
86
|
+
return [
|
|
87
|
+
{
|
|
88
|
+
turnId: context.turnId,
|
|
89
|
+
type: 'terminal',
|
|
90
|
+
terminal: {
|
|
91
|
+
kind: 'failure',
|
|
92
|
+
reason: `pi failed to parse a command record: ${record.error ?? 'unspecified error'}`,
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
];
|
|
96
|
+
}
|
|
97
|
+
// The terminal: agent_settled is the only completion evidence (agent_end can precede
|
|
98
|
+
// retries). Session-level record — attributed to the active turn via context.
|
|
99
|
+
if (record.type === 'agent_settled') {
|
|
100
|
+
if (context === undefined)
|
|
101
|
+
return [];
|
|
102
|
+
const terminal = { kind: 'success' };
|
|
103
|
+
if (record.aborted === true) {
|
|
104
|
+
terminal.kind = 'failure';
|
|
105
|
+
terminal.reason = 'pi agent settled with aborted: true';
|
|
106
|
+
}
|
|
107
|
+
return [{ turnId: context.turnId, type: 'terminal', terminal }];
|
|
108
|
+
}
|
|
109
|
+
// Assistant final message → output (the consumer extracts final text/artifacts from
|
|
110
|
+
// the event stream; `agent_settled` carries no text payload).
|
|
111
|
+
if (record.type === 'message_end' && record.message?.role === 'assistant' && context !== undefined) {
|
|
112
|
+
return [{ turnId: context.turnId, type: 'output', data: record }];
|
|
113
|
+
}
|
|
114
|
+
// extension_ui_request / agent_start / turn_start|end / message_update|start /
|
|
115
|
+
// session_info_changed / tool_execution_* / auto_retry_* / abort response — noise.
|
|
116
|
+
return [];
|
|
117
|
+
},
|
|
118
|
+
encodeCancel: (_reason) =>
|
|
119
|
+
// Abort command (pi docs rpc-commands.md; observed 0.87.1: the active tool call ends
|
|
120
|
+
// with "Command aborted", the run settles, then the abort response arrives).
|
|
121
|
+
`${JSON.stringify({ type: 'abort' })}\n`,
|
|
122
|
+
handshake: async (pull) => {
|
|
123
|
+
// Readiness probe: drain up to the first parseable record so the extension startup
|
|
124
|
+
// has begun before the first turn is written. Any parseable protocol record proves
|
|
125
|
+
// the process is alive and speaking JSONL; startup noise is not otherwise needed.
|
|
126
|
+
for (let seen = 0; seen < 32; seen += 1) {
|
|
127
|
+
const line = await pull(2_000);
|
|
128
|
+
if (line === null)
|
|
129
|
+
return null; // EOF before the process spoke
|
|
130
|
+
try {
|
|
131
|
+
JSON.parse(line);
|
|
132
|
+
return {};
|
|
133
|
+
}
|
|
134
|
+
catch { }
|
|
135
|
+
}
|
|
136
|
+
return null;
|
|
137
|
+
},
|
|
138
|
+
};
|
|
139
|
+
}
|
package/dist/turn-session.d.ts
CHANGED
|
@@ -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,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;
|
|
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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S,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;AA4TD;;;;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;
|
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.3",
|
|
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.3",
|
|
55
|
+
"@gobing-ai/ts-runtime": "^0.6.3"
|
|
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.3"
|
|
60
60
|
},
|
|
61
61
|
"publishConfig": {
|
|
62
62
|
"access": "public"
|
package/src/agents/shims.ts
CHANGED
|
@@ -285,17 +285,22 @@ const antigravityCliShim: AgentShim = {
|
|
|
285
285
|
getHelpCommand: () => ({ command: 'agy', args: ['--help'] }),
|
|
286
286
|
getVersionCommand: () => ({ command: 'agy', args: ['--version'] }),
|
|
287
287
|
getPromptCommand: (options) => {
|
|
288
|
-
// Print mode is headless: agy auto-denies any tool that would prompt
|
|
289
|
-
//
|
|
290
|
-
//
|
|
291
|
-
//
|
|
292
|
-
//
|
|
293
|
-
//
|
|
294
|
-
//
|
|
295
|
-
//
|
|
296
|
-
//
|
|
297
|
-
//
|
|
298
|
-
|
|
288
|
+
// Print mode is headless: agy auto-denies any tool that would prompt,
|
|
289
|
+
// so expectFile-style automation dead-ends without a permission
|
|
290
|
+
// affordance (spur 0689). `--mode accept-edits` alone proved too narrow
|
|
291
|
+
// in the field (spur task 1276 review lane, 2026-10-23): the sandbox
|
|
292
|
+
// (toolPermission=proceed-in-sandbox) blocked reads outside the
|
|
293
|
+
// workspace (~/.gitconfig) and hard-denied allowlisted-command
|
|
294
|
+
// variants (e.g. `bun <script>` vs the built-in `bun run` prefix),
|
|
295
|
+
// producing exit-0 empty answers from healthy models. The CLI's own
|
|
296
|
+
// documented remedy for headless automation is
|
|
297
|
+
// `--dangerously-skip-permissions` (auto-approve all tool permission
|
|
298
|
+
// requests, sandbox included). Trust assumption (0689, widened with
|
|
299
|
+
// operator sanction 2026-10-23): the dispatch is an operator-initiated,
|
|
300
|
+
// headless, workspace-scoped subprocess running agent-emitted commands
|
|
301
|
+
// under the caller's supervision; the flag is scoped to print mode
|
|
302
|
+
// only — interactive agy sessions keep their own permission flow.
|
|
303
|
+
const args = ['-p', options.input ?? '', '--mode', 'accept-edits', '--dangerously-skip-permissions'];
|
|
299
304
|
if (options.timeoutMs !== undefined) args.push('--print-timeout', `${options.timeoutMs}ms`);
|
|
300
305
|
// Headless agy resolves relative file-tool paths against a scratch dir,
|
|
301
306
|
// not the process cwd; --add-dir re-roots them into the real workspace
|
|
@@ -543,7 +548,12 @@ const AGENT_SESSION_CAPABILITY: Readonly<Record<AgentName, AgentSessionCapabilit
|
|
|
543
548
|
supportsSessionDir: true,
|
|
544
549
|
supportsPersistentStdin: true,
|
|
545
550
|
supportsStructuredOutput: true,
|
|
546
|
-
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).
|
|
547
557
|
},
|
|
548
558
|
claude: {
|
|
549
559
|
supportsResumeById: true,
|
|
@@ -0,0 +1,185 @@
|
|
|
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
|
+
kind: 'failure',
|
|
112
|
+
reason: `pi rejected the prompt command: ${record.error ?? 'unspecified error'}`,
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
];
|
|
116
|
+
}
|
|
117
|
+
// 1.4.0 reports `data.disposition`; "handled" means no run started for this prompt.
|
|
118
|
+
const disposition = record.data?.disposition;
|
|
119
|
+
if (disposition !== undefined && disposition !== 'started') {
|
|
120
|
+
return [
|
|
121
|
+
{
|
|
122
|
+
turnId: context.turnId,
|
|
123
|
+
type: 'terminal',
|
|
124
|
+
terminal: {
|
|
125
|
+
kind: 'failure',
|
|
126
|
+
reason: `pi prompt disposition '${disposition}' did not start a run`,
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
];
|
|
130
|
+
}
|
|
131
|
+
return [{ turnId: context.turnId, type: 'accepted' }];
|
|
132
|
+
}
|
|
133
|
+
// A parse response means one of OUR command records did not parse — framing broke.
|
|
134
|
+
if (record.type === 'response' && record.command === 'parse' && context !== undefined) {
|
|
135
|
+
return [
|
|
136
|
+
{
|
|
137
|
+
turnId: context.turnId,
|
|
138
|
+
type: 'terminal',
|
|
139
|
+
terminal: {
|
|
140
|
+
kind: 'failure',
|
|
141
|
+
reason: `pi failed to parse a command record: ${record.error ?? 'unspecified error'}`,
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
];
|
|
145
|
+
}
|
|
146
|
+
// The terminal: agent_settled is the only completion evidence (agent_end can precede
|
|
147
|
+
// retries). Session-level record — attributed to the active turn via context.
|
|
148
|
+
if (record.type === 'agent_settled') {
|
|
149
|
+
if (context === undefined) return [];
|
|
150
|
+
const terminal: TurnWireTerminal = { kind: 'success' };
|
|
151
|
+
if (record.aborted === true) {
|
|
152
|
+
terminal.kind = 'failure';
|
|
153
|
+
terminal.reason = 'pi agent settled with aborted: true';
|
|
154
|
+
}
|
|
155
|
+
return [{ turnId: context.turnId, type: 'terminal', terminal }];
|
|
156
|
+
}
|
|
157
|
+
// Assistant final message → output (the consumer extracts final text/artifacts from
|
|
158
|
+
// the event stream; `agent_settled` carries no text payload).
|
|
159
|
+
if (record.type === 'message_end' && record.message?.role === 'assistant' && context !== undefined) {
|
|
160
|
+
return [{ turnId: context.turnId, type: 'output', data: record }];
|
|
161
|
+
}
|
|
162
|
+
// extension_ui_request / agent_start / turn_start|end / message_update|start /
|
|
163
|
+
// session_info_changed / tool_execution_* / auto_retry_* / abort response — noise.
|
|
164
|
+
return [];
|
|
165
|
+
},
|
|
166
|
+
encodeCancel: (_reason: string) =>
|
|
167
|
+
// Abort command (pi docs rpc-commands.md; observed 0.87.1: the active tool call ends
|
|
168
|
+
// with "Command aborted", the run settles, then the abort response arrives).
|
|
169
|
+
`${JSON.stringify({ type: 'abort' })}\n`,
|
|
170
|
+
handshake: async (pull: (timeoutMs: number) => Promise<string | null>): Promise<TurnHandshake> => {
|
|
171
|
+
// Readiness probe: drain up to the first parseable record so the extension startup
|
|
172
|
+
// has begun before the first turn is written. Any parseable protocol record proves
|
|
173
|
+
// the process is alive and speaking JSONL; startup noise is not otherwise needed.
|
|
174
|
+
for (let seen = 0; seen < 32; seen += 1) {
|
|
175
|
+
const line = await pull(2_000);
|
|
176
|
+
if (line === null) return null; // EOF before the process spoke
|
|
177
|
+
try {
|
|
178
|
+
JSON.parse(line) as PiRecord;
|
|
179
|
+
return {};
|
|
180
|
+
} catch {}
|
|
181
|
+
}
|
|
182
|
+
return null;
|
|
183
|
+
},
|
|
184
|
+
};
|
|
185
|
+
}
|
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,
|
|
@@ -173,10 +174,12 @@ export type OpenTurnSessionResult =
|
|
|
173
174
|
/**
|
|
174
175
|
* Built-in driver registry. Entries land only with recorded qualification evidence (anti-pattern:
|
|
175
176
|
* registration without evidence): claude 2.1.308 stream-json (task 1276, fixtures under
|
|
176
|
-
* `tests/fixtures/turn-drivers/claude`)
|
|
177
|
+
* `tests/fixtures/turn-drivers/claude`) and pi 0.87.1 rpc (task 1277, fixtures under
|
|
178
|
+
* `tests/fixtures/turn-drivers/pi`). 0.x shipped this empty by design.
|
|
177
179
|
*/
|
|
178
180
|
export const TURN_SESSION_DRIVERS: ReadonlyMap<AgentName, TurnSessionDriver> = new Map([
|
|
179
181
|
['claude', createClaudeTurnSessionDriver()],
|
|
182
|
+
['pi', createPiTurnSessionDriver()],
|
|
180
183
|
]);
|
|
181
184
|
|
|
182
185
|
/** How long `cancel()` waits for native terminal evidence before resolving `outcome-unknown`. */
|