feat(#2102): make pi a first-class installable runtime + fix its dispatch (ADR-1239)

Net-new EoS/pi installable runtime — purely additive (no prior runtime==='pi'
branches). pi is a bun-runtime programmatic-CLI whose /gsd command is registered
by a native ExtensionAPI extension and dispatches through the embedded engine.

Stage 1 (install plumbing):
- capabilities/pi/capability.json: full hostIntegration descriptor (imperative /
  slash-programmatic / active-model / native-extension / bun) + hostBehaviors
  {nativePlugin, pluginOnlyInstall}.
- --pi flag + interactive-menu renumber (All 17->18); pi added to RUNTIME_FLAG_IDS,
  RUNTIME_LABELS, RUNTIME_META, allRuntimes/runtimeMap, model-catalog defaults.
- Install mirrors OpenCode: pi installs the gsd.cjs extension + the shared engine
  payload (gsd-core + scripts + config markers) + the shared hooks bundle (spawned
  by the extension at lifecycle events, like OpenCode's plugin). pluginOnlyInstall
  EXCLUDES declarative command/agent/skill markdown, which pi has no host-read
  surface for (its /gsd is programmatic). _installNativePluginIfDeclared (extracted
  from the opencode-family path) copies pi/gsd.cjs -> ~/.pi/agent/extensions/gsd.cjs
  (global) / .pi/extensions/ (local). pi added to package.json files.
- Golden: new pi.json (320 files: extension + engine + 27-file hooks bundle, no
  markdown); the 16 other fixtures + claude-local change only by the shared
  model-catalog hash line.

Stage 2 (real dispatch + upgrades):
- Shared dispatchGsdCommand() (shell-command-projection): bounded, no-throw
  subprocess-shim to gsd-tools.cjs (the only full-surface dispatch path; no
  in-process full-hub factory exists). Fixes pi/gsd.cjs's createHub()-no-args bug
  (every dispatch was UnknownCommand) AND the identical bug in mcp-server.cts's
  gsd_invoke_command, which a vacuous unknown-family-only test had masked (now has
  a real dispatch regression test).
- pi/gsd.cjs: /gsd handler now (args, ctx) - tokenizes (quote-aware, via the
  shipped hooks/lib/git-cmd.js) + dispatches real family/subcommand (not hardcoded
  query/help); gsd_invoke gets a TypeBox (JSON-schema-fallback) parameters schema +
  consumes params; getArgumentCompletions; before_provider_request active-model
  steering (fail-open on null resolution); functional session_start /
  before_agent_start / session_before_compact hook bridges (spawn the shipped GSD
  hook scripts).
- EXTENSION_EVENT_SURFACES.pi expanded from ['tool_call'] to the full 30-event
  vocabulary.

Docs (host-integration matrix + how-to) + changeset (Added).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Tom Boucher
2026-07-11 19:34:23 -04:00
parent 246f566ee1
commit 79d7657eff
49 changed files with 1771 additions and 198 deletions

View File

@@ -15,6 +15,10 @@
* now hermes, and the "All" shortcut moved from 17 to 16.
*
* #1925: ZCode (Z.ai) added as option 16; the "All" shortcut moved from 16 to 17.
*
* #2102: pi added as option 13 (alphabetical slot between opencode and qwen) —
* qwen/trae/windsurf/zcode each shift up one slot (14/15/16/17), and the "All"
* shortcut moves from 17 to 18.
*/
process.env.GSD_TEST_MODE = '1';
@@ -76,39 +80,43 @@ describe('multi-runtime selection parsing', () => {
assert.deepStrictEqual(parseRuntimeInput('12'), ['opencode']);
});
test('single choice for pi', () => {
assert.deepStrictEqual(parseRuntimeInput('13'), ['pi']);
});
test('single choice for qwen', () => {
assert.deepStrictEqual(parseRuntimeInput('13'), ['qwen']);
assert.deepStrictEqual(parseRuntimeInput('14'), ['qwen']);
});
test('single choice for trae', () => {
assert.deepStrictEqual(parseRuntimeInput('14'), ['trae']);
assert.deepStrictEqual(parseRuntimeInput('15'), ['trae']);
});
test('single choice for windsurf', () => {
assert.deepStrictEqual(parseRuntimeInput('15'), ['windsurf']);
assert.deepStrictEqual(parseRuntimeInput('16'), ['windsurf']);
});
test('single choice for zcode', () => {
assert.deepStrictEqual(parseRuntimeInput('16'), ['zcode']);
assert.deepStrictEqual(parseRuntimeInput('17'), ['zcode']);
});
test('single choice for kimi', () => {
assert.deepStrictEqual(parseRuntimeInput('10'), ['kimi']);
});
test('choice 17 returns all runtimes', () => {
assert.deepStrictEqual(parseRuntimeInput('17'), allRuntimes);
test('choice 18 returns all runtimes', () => {
assert.deepStrictEqual(parseRuntimeInput('18'), allRuntimes);
});
test('choice 17 returns all runtimes when mixed with separators or other tokens', () => {
// CR feedback: tokenized inputs that include 17 (e.g. trailing comma, or
test('choice 18 returns all runtimes when mixed with separators or other tokens', () => {
// CR feedback: tokenized inputs that include 18 (e.g. trailing comma, or
// alongside other choices) must still expand to all-runtimes — previously
// only the bare all-runtimes option matched, so "17," or "17 1" silently installed a
// only the bare all-runtimes option matched, so "18," or "18 1" silently installed a
// subset.
assert.deepStrictEqual(parseRuntimeInput('17,'), allRuntimes);
assert.deepStrictEqual(parseRuntimeInput('17 1'), allRuntimes);
assert.deepStrictEqual(parseRuntimeInput('1,17'), allRuntimes);
assert.deepStrictEqual(parseRuntimeInput(' 17 '), allRuntimes);
assert.deepStrictEqual(parseRuntimeInput('18,'), allRuntimes);
assert.deepStrictEqual(parseRuntimeInput('18 1'), allRuntimes);
assert.deepStrictEqual(parseRuntimeInput('1,18'), allRuntimes);
assert.deepStrictEqual(parseRuntimeInput(' 18 '), allRuntimes);
});
test('empty input defaults to claude', () => {
@@ -117,13 +125,13 @@ describe('multi-runtime selection parsing', () => {
});
test('invalid choices are ignored, falls back to claude if all invalid', () => {
assert.deepStrictEqual(parseRuntimeInput('18'), ['claude']);
assert.deepStrictEqual(parseRuntimeInput('19'), ['claude']);
assert.deepStrictEqual(parseRuntimeInput('0'), ['claude']);
assert.deepStrictEqual(parseRuntimeInput('abc'), ['claude']);
});
test('invalid choices mixed with valid are filtered out', () => {
assert.deepStrictEqual(parseRuntimeInput('1,18,7'), ['claude', 'copilot']);
assert.deepStrictEqual(parseRuntimeInput('1,19,7'), ['claude', 'copilot']);
assert.deepStrictEqual(parseRuntimeInput('abc 3 xyz'), ['augment']);
});
@@ -152,14 +160,15 @@ describe('install.js exports multi-select runtime metadata', () => {
'10': 'kimi',
'11': 'kilo',
'12': 'opencode',
'13': 'qwen',
'14': 'trae',
'15': 'windsurf',
'16': 'zcode',
'13': 'pi',
'14': 'qwen',
'15': 'trae',
'16': 'windsurf',
'17': 'zcode',
};
const expectedRuntimes = [
'claude', 'antigravity', 'augment', 'cline', 'codebuddy', 'codex',
'copilot', 'cursor', 'hermes', 'kimi', 'kilo', 'opencode',
'copilot', 'cursor', 'hermes', 'kimi', 'kilo', 'opencode', 'pi',
'qwen', 'trae', 'windsurf', 'zcode',
];
@@ -177,8 +186,8 @@ describe('install.js exports multi-select runtime metadata', () => {
'allRuntimes has no duplicates');
});
test('"All" shortcut (option 17) selects every runtime', () => {
assert.deepStrictEqual(parseRuntimeInput('17'), allRuntimes);
test('"All" shortcut (option 18) selects every runtime', () => {
assert.deepStrictEqual(parseRuntimeInput('18'), allRuntimes);
});
test('--kimi flag selects Kimi without interactive prompt', () => {
@@ -189,6 +198,10 @@ describe('install.js exports multi-select runtime metadata', () => {
assert.deepStrictEqual(selectRuntimesFromArgs(['--zcode']), ['zcode']);
});
test('--pi flag selects pi without interactive prompt', () => {
assert.deepStrictEqual(selectRuntimesFromArgs(['--pi']), ['pi']);
});
test('--all flag includes Kimi exactly once', () => {
const selected = selectRuntimesFromArgs(['--all']);
assert.ok(selected.includes('kimi'), '--all includes kimi');
@@ -203,7 +216,14 @@ describe('install.js exports multi-select runtime metadata', () => {
'--all includes zcode exactly once');
});
test('prompt lists ZCode (16), and All (17)', () => {
test('--all flag includes pi exactly once', () => {
const selected = selectRuntimesFromArgs(['--all']);
assert.ok(selected.includes('pi'), '--all includes pi');
assert.strictEqual(selected.filter((runtime) => runtime === 'pi').length, 1,
'--all includes pi exactly once');
});
test('prompt lists pi (13), ZCode (17), and All (18)', () => {
const prompt = stripAnsi(buildRuntimePromptText());
assert.ok(/\b9\)\s*Hermes Agent\b/.test(prompt),
'prompt lists Hermes Agent as option 9');
@@ -211,14 +231,16 @@ describe('install.js exports multi-select runtime metadata', () => {
'prompt lists Kimi as option 10');
assert.ok(/Kimi\s+\(~\/\.config\/agents, then ~\/\.agents if existing\)/.test(prompt),
'prompt shows the Kimi first-existing generic root policy');
assert.ok(/\b13\)\s*Qwen Code\b/.test(prompt),
'prompt lists Qwen Code as option 13');
assert.ok(/\b14\)\s*Trae\b/.test(prompt),
'prompt lists Trae as option 14');
assert.ok(/\b16\)\s*ZCode\b/.test(prompt),
'prompt lists ZCode as option 16');
assert.ok(/\b17\)\s*All\b/.test(prompt),
'prompt lists All as option 17');
assert.ok(/\b13\)\s*pi\b/.test(prompt),
'prompt lists pi as option 13');
assert.ok(/\b14\)\s*Qwen Code\b/.test(prompt),
'prompt lists Qwen Code as option 14');
assert.ok(/\b15\)\s*Trae\b/.test(prompt),
'prompt lists Trae as option 15');
assert.ok(/\b17\)\s*ZCode\b/.test(prompt),
'prompt lists ZCode as option 17');
assert.ok(/\b18\)\s*All\b/.test(prompt),
'prompt lists All as option 18');
});
test('prompt does not list Gemini (removed #1928)', () => {