instar 1.3.342 → 1.3.344
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/dist/commands/init.d.ts +4 -4
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/server.d.ts.map +1 -1
- package/dist/commands/server.js +47 -0
- package/dist/commands/server.js.map +1 -1
- package/dist/commands/setup.d.ts +1 -1
- package/dist/commands/setup.d.ts.map +1 -1
- package/dist/commands/setup.js.map +1 -1
- package/dist/core/Config.d.ts +12 -3
- package/dist/core/Config.d.ts.map +1 -1
- package/dist/core/Config.js +40 -6
- package/dist/core/Config.js.map +1 -1
- package/dist/core/FrameworkSessionStore.d.ts +1 -1
- package/dist/core/FrameworkSessionStore.d.ts.map +1 -1
- package/dist/core/PiCliIntelligenceProvider.d.ts +52 -0
- package/dist/core/PiCliIntelligenceProvider.d.ts.map +1 -0
- package/dist/core/PiCliIntelligenceProvider.js +71 -0
- package/dist/core/PiCliIntelligenceProvider.js.map +1 -0
- package/dist/core/PostUpdateMigrator.d.ts.map +1 -1
- package/dist/core/PostUpdateMigrator.js +14 -0
- package/dist/core/PostUpdateMigrator.js.map +1 -1
- package/dist/core/PreCompactionFlush.d.ts +1 -1
- package/dist/core/PreCompactionFlush.d.ts.map +1 -1
- package/dist/core/ResumeValidator.d.ts +1 -1
- package/dist/core/ResumeValidator.d.ts.map +1 -1
- package/dist/core/SessionManager.d.ts.map +1 -1
- package/dist/core/SessionManager.js +35 -1
- package/dist/core/SessionManager.js.map +1 -1
- package/dist/core/TopicFrameworksStore.d.ts.map +1 -1
- package/dist/core/TopicFrameworksStore.js +3 -0
- package/dist/core/TopicFrameworksStore.js.map +1 -1
- package/dist/core/frameworkInjectionProcesses.d.ts.map +1 -1
- package/dist/core/frameworkInjectionProcesses.js +4 -0
- package/dist/core/frameworkInjectionProcesses.js.map +1 -1
- package/dist/core/frameworkSessionLaunch.d.ts +8 -0
- package/dist/core/frameworkSessionLaunch.d.ts.map +1 -1
- package/dist/core/frameworkSessionLaunch.js +73 -0
- package/dist/core/frameworkSessionLaunch.js.map +1 -1
- package/dist/core/intelligenceProviderFactory.d.ts +15 -1
- package/dist/core/intelligenceProviderFactory.d.ts.map +1 -1
- package/dist/core/intelligenceProviderFactory.js +39 -1
- package/dist/core/intelligenceProviderFactory.js.map +1 -1
- package/dist/core/types.d.ts +18 -7
- package/dist/core/types.d.ts.map +1 -1
- package/dist/core/types.js.map +1 -1
- package/dist/messaging/shared/telegramRelayPrompt.d.ts +1 -1
- package/dist/messaging/shared/telegramRelayPrompt.d.ts.map +1 -1
- package/dist/monitoring/SessionReaper.d.ts +1 -1
- package/dist/monitoring/SessionReaper.d.ts.map +1 -1
- package/dist/monitoring/SessionReaper.js.map +1 -1
- package/dist/monitoring/frameworkActivitySignals.d.ts.map +1 -1
- package/dist/monitoring/frameworkActivitySignals.js +21 -0
- package/dist/monitoring/frameworkActivitySignals.js.map +1 -1
- package/dist/monitoring/frameworkProcessSignals.d.ts.map +1 -1
- package/dist/monitoring/frameworkProcessSignals.js +22 -0
- package/dist/monitoring/frameworkProcessSignals.js.map +1 -1
- package/dist/providers/adapters/pi-cli/capabilities.d.ts +31 -0
- package/dist/providers/adapters/pi-cli/capabilities.d.ts.map +1 -0
- package/dist/providers/adapters/pi-cli/capabilities.js +40 -0
- package/dist/providers/adapters/pi-cli/capabilities.js.map +1 -0
- package/dist/providers/adapters/pi-cli/config.d.ts +65 -0
- package/dist/providers/adapters/pi-cli/config.d.ts.map +1 -0
- package/dist/providers/adapters/pi-cli/config.js +43 -0
- package/dist/providers/adapters/pi-cli/config.js.map +1 -0
- package/dist/providers/adapters/pi-cli/control/piHardKill.d.ts +19 -0
- package/dist/providers/adapters/pi-cli/control/piHardKill.d.ts.map +1 -0
- package/dist/providers/adapters/pi-cli/control/piHardKill.js +67 -0
- package/dist/providers/adapters/pi-cli/control/piHardKill.js.map +1 -0
- package/dist/providers/adapters/pi-cli/errors.d.ts +43 -0
- package/dist/providers/adapters/pi-cli/errors.d.ts.map +1 -0
- package/dist/providers/adapters/pi-cli/errors.js +71 -0
- package/dist/providers/adapters/pi-cli/errors.js.map +1 -0
- package/dist/providers/adapters/pi-cli/index.d.ts +39 -0
- package/dist/providers/adapters/pi-cli/index.d.ts.map +1 -0
- package/dist/providers/adapters/pi-cli/index.js +69 -0
- package/dist/providers/adapters/pi-cli/index.js.map +1 -0
- package/dist/providers/adapters/pi-cli/observability/sessionId.d.ts +27 -0
- package/dist/providers/adapters/pi-cli/observability/sessionId.d.ts.map +1 -0
- package/dist/providers/adapters/pi-cli/observability/sessionId.js +53 -0
- package/dist/providers/adapters/pi-cli/observability/sessionId.js.map +1 -0
- package/dist/providers/adapters/pi-cli/policy.d.ts +44 -0
- package/dist/providers/adapters/pi-cli/policy.d.ts.map +1 -0
- package/dist/providers/adapters/pi-cli/policy.js +74 -0
- package/dist/providers/adapters/pi-cli/policy.js.map +1 -0
- package/dist/providers/adapters/pi-cli/transport/agenticSessionRpc.d.ts +34 -0
- package/dist/providers/adapters/pi-cli/transport/agenticSessionRpc.d.ts.map +1 -0
- package/dist/providers/adapters/pi-cli/transport/agenticSessionRpc.js +194 -0
- package/dist/providers/adapters/pi-cli/transport/agenticSessionRpc.js.map +1 -0
- package/dist/providers/adapters/pi-cli/transport/oneShotCompletion.d.ts +33 -0
- package/dist/providers/adapters/pi-cli/transport/oneShotCompletion.d.ts.map +1 -0
- package/dist/providers/adapters/pi-cli/transport/oneShotCompletion.js +166 -0
- package/dist/providers/adapters/pi-cli/transport/oneShotCompletion.js.map +1 -0
- package/dist/providers/adapters/pi-cli/transport/piSpawn.d.ts +87 -0
- package/dist/providers/adapters/pi-cli/transport/piSpawn.d.ts.map +1 -0
- package/dist/providers/adapters/pi-cli/transport/piSpawn.js +242 -0
- package/dist/providers/adapters/pi-cli/transport/piSpawn.js.map +1 -0
- package/dist/providers/adapters/pi-cli/transport/rpcClient.d.ts +103 -0
- package/dist/providers/adapters/pi-cli/transport/rpcClient.d.ts.map +1 -0
- package/dist/providers/adapters/pi-cli/transport/rpcClient.js +238 -0
- package/dist/providers/adapters/pi-cli/transport/rpcClient.js.map +1 -0
- package/dist/providers/bootRegistration.d.ts +38 -0
- package/dist/providers/bootRegistration.d.ts.map +1 -1
- package/dist/providers/bootRegistration.js +52 -0
- package/dist/providers/bootRegistration.js.map +1 -1
- package/dist/providers/parity/rules/skillParityRule.d.ts.map +1 -1
- package/dist/providers/parity/rules/skillParityRule.js +6 -0
- package/dist/providers/parity/rules/skillParityRule.js.map +1 -1
- package/dist/redteam/ScenarioPack.d.ts +161 -0
- package/dist/redteam/ScenarioPack.d.ts.map +1 -0
- package/dist/redteam/ScenarioPack.js +200 -0
- package/dist/redteam/ScenarioPack.js.map +1 -0
- package/dist/scaffold/templates.js +1 -1
- package/package.json +1 -1
- package/src/data/builtin-manifest.json +20 -20
- package/src/scaffold/templates.ts +1 -1
- package/upgrades/1.3.343.md +49 -0
- package/upgrades/1.3.344.md +46 -0
- package/upgrades/side-effects/pi-harness-integration.md +82 -0
- package/upgrades/side-effects/redteam-harness-phase1-core.md +53 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"frameworkProcessSignals.js","sourceRoot":"","sources":["../../src/monitoring/frameworkProcessSignals.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAoCH,MAAM,kBAAkB,GAA2B;IACjD,SAAS,EAAE,aAAa;IACxB,WAAW,EAAE,QAAQ;IACrB,YAAY,EAAE,UAAU;IACxB,aAAa,EAAE,oBAAoB;IACnC,WAAW,EAAE,6CAA6C;IAC1D,mBAAmB,EAAE;QACnB,kBAAkB;QAClB,YAAY;QACZ,gBAAgB;QAChB,YAAY;QACZ,SAAS;QACT,cAAc;KACf;CACF,CAAC;AAEF,MAAM,gBAAgB,GAA2B;IAC/C,SAAS,EAAE,WAAW;IACtB,WAAW,EAAE,OAAO;IACpB,YAAY,EAAE,SAAS;IACvB,aAAa,EAAE,mBAAmB;IAClC,8DAA8D;IAC9D,oEAAoE;IACpE,WAAW,EAAE,8CAA8C;IAC3D,mBAAmB,EAAE;QACnB,WAAW;QACX,mEAAmE;QACnE,qEAAqE;QACrE,uDAAuD;QACvD,cAAc;KACf;CACF,CAAC;AAEF,MAAM,iBAAiB,GAA2B;IAChD,SAAS,EAAE,YAAY;IACvB,WAAW,EAAE,QAAQ;IACrB,YAAY,EAAE,UAAU;IACxB,aAAa,EAAE,oBAAoB;IACnC,2EAA2E;IAC3E,yEAAyE;IACzE,WAAW,EAAE,2CAA2C;IACxD,mBAAmB,EAAE;QACnB,qEAAqE;QACrE,mEAAmE;QACnE,YAAY;KACb;CACF,CAAC;AAEF,MAAM,eAAe,GAA0D;IAC7E,aAAa,EAAE,kBAAkB;IACjC,WAAW,EAAE,gBAAgB;IAC7B,YAAY,EAAE,iBAAiB;
|
|
1
|
+
{"version":3,"file":"frameworkProcessSignals.js","sourceRoot":"","sources":["../../src/monitoring/frameworkProcessSignals.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAoCH,MAAM,kBAAkB,GAA2B;IACjD,SAAS,EAAE,aAAa;IACxB,WAAW,EAAE,QAAQ;IACrB,YAAY,EAAE,UAAU;IACxB,aAAa,EAAE,oBAAoB;IACnC,WAAW,EAAE,6CAA6C;IAC1D,mBAAmB,EAAE;QACnB,kBAAkB;QAClB,YAAY;QACZ,gBAAgB;QAChB,YAAY;QACZ,SAAS;QACT,cAAc;KACf;CACF,CAAC;AAEF,MAAM,gBAAgB,GAA2B;IAC/C,SAAS,EAAE,WAAW;IACtB,WAAW,EAAE,OAAO;IACpB,YAAY,EAAE,SAAS;IACvB,aAAa,EAAE,mBAAmB;IAClC,8DAA8D;IAC9D,oEAAoE;IACpE,WAAW,EAAE,8CAA8C;IAC3D,mBAAmB,EAAE;QACnB,WAAW;QACX,mEAAmE;QACnE,qEAAqE;QACrE,uDAAuD;QACvD,cAAc;K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E,CAAC;QAC7B,IAAI,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;YAC3E,IAAI,MAAM,CAAC,mBAAmB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;gBAAE,SAAS;YACxE,OAAO,MAAM,CAAC;QAChB,CAAC;IACH,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,kBAAkB;IAChC,OAAQ,MAAM,CAAC,IAAI,CAAC,eAAe,CAA6B,CAAC,GAAG,CAClE,CAAC,CAAC,EAAE,CAAC,eAAe,CAAC,CAAC,CAAC,CACxB,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAAC,SAAgC;IAC/D,OAAO,eAAe,CAAC,SAAS,CAAC,IAAI,IAAI,CAAC;AAC5C,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,yBAAyB;IACvC,OAAO,uBAAuB,CAAC;AACjC,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Capability declaration for the pi-cli adapter
|
|
3
|
+
* (PI-HARNESS-INTEGRATION-SPEC §4.2).
|
|
4
|
+
*
|
|
5
|
+
* Per the honest-declaration contract (the parity harness's stub-vs-real
|
|
6
|
+
* check — the rule the openai-codex and gemini-cli adapters follow), this
|
|
7
|
+
* declares ONLY the primitives the factory actually wires. Declared-but-
|
|
8
|
+
* stubbed is a capability-declaration lie.
|
|
9
|
+
*
|
|
10
|
+
* SHIPPED (every fact eval-verified against pi 0.78.1 — see
|
|
11
|
+
* docs/specs/_drafts/pi-eval-report.md):
|
|
12
|
+
* - OneShotCompletion : `pi -p --mode json` spawn-and-parse (usage + cost
|
|
13
|
+
* come back on message_end — richer than gemini's).
|
|
14
|
+
* - AgenticSessionRpc : pi's NATIVE `--mode rpc` stdio JSONL channel —
|
|
15
|
+
* prompt / mid-stream steer / abort / resume. This
|
|
16
|
+
* is the adapter's differentiator: the first
|
|
17
|
+
* framework with a structured control channel
|
|
18
|
+
* instead of a scraped TUI.
|
|
19
|
+
* - SessionId : binds SessionHandles to pi session UUIDs.
|
|
20
|
+
* - HardKill : SIGTERM→SIGKILL on the spawned pid.
|
|
21
|
+
*
|
|
22
|
+
* NOT declared (deliberate):
|
|
23
|
+
* - AgenticSessionInteractive: interactive pi sessions are launched through
|
|
24
|
+
* the SessionManager tmux path (frameworkSessionLaunch piCliBuilder),
|
|
25
|
+
* not through the provider registry — same split every framework has.
|
|
26
|
+
* - HookEventReceiver / CompactionLifecycle: pi has extension hooks and
|
|
27
|
+
* `compact`, but their live return-contracts are uncharacterized; wiring
|
|
28
|
+
* them half-probed would overclaim (the gemini Step-2 lesson).
|
|
29
|
+
*/
|
|
30
|
+
export declare const piCliCapabilities: import("../../capabilities.js").CapabilitySet;
|
|
31
|
+
//# sourceMappingURL=capabilities.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capabilities.d.ts","sourceRoot":"","sources":["../../../../src/providers/adapters/pi-cli/capabilities.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAIH,eAAO,MAAM,iBAAiB,+CAU5B,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Capability declaration for the pi-cli adapter
|
|
3
|
+
* (PI-HARNESS-INTEGRATION-SPEC §4.2).
|
|
4
|
+
*
|
|
5
|
+
* Per the honest-declaration contract (the parity harness's stub-vs-real
|
|
6
|
+
* check — the rule the openai-codex and gemini-cli adapters follow), this
|
|
7
|
+
* declares ONLY the primitives the factory actually wires. Declared-but-
|
|
8
|
+
* stubbed is a capability-declaration lie.
|
|
9
|
+
*
|
|
10
|
+
* SHIPPED (every fact eval-verified against pi 0.78.1 — see
|
|
11
|
+
* docs/specs/_drafts/pi-eval-report.md):
|
|
12
|
+
* - OneShotCompletion : `pi -p --mode json` spawn-and-parse (usage + cost
|
|
13
|
+
* come back on message_end — richer than gemini's).
|
|
14
|
+
* - AgenticSessionRpc : pi's NATIVE `--mode rpc` stdio JSONL channel —
|
|
15
|
+
* prompt / mid-stream steer / abort / resume. This
|
|
16
|
+
* is the adapter's differentiator: the first
|
|
17
|
+
* framework with a structured control channel
|
|
18
|
+
* instead of a scraped TUI.
|
|
19
|
+
* - SessionId : binds SessionHandles to pi session UUIDs.
|
|
20
|
+
* - HardKill : SIGTERM→SIGKILL on the spawned pid.
|
|
21
|
+
*
|
|
22
|
+
* NOT declared (deliberate):
|
|
23
|
+
* - AgenticSessionInteractive: interactive pi sessions are launched through
|
|
24
|
+
* the SessionManager tmux path (frameworkSessionLaunch piCliBuilder),
|
|
25
|
+
* not through the provider registry — same split every framework has.
|
|
26
|
+
* - HookEventReceiver / CompactionLifecycle: pi has extension hooks and
|
|
27
|
+
* `compact`, but their live return-contracts are uncharacterized; wiring
|
|
28
|
+
* them half-probed would overclaim (the gemini Step-2 lesson).
|
|
29
|
+
*/
|
|
30
|
+
import { CapabilityFlag, capabilitySet } from '../../capabilities.js';
|
|
31
|
+
export const piCliCapabilities = capabilitySet([
|
|
32
|
+
// ── TRANSPORT ────────────────────────────────────────────────────────
|
|
33
|
+
CapabilityFlag.OneShotCompletion,
|
|
34
|
+
CapabilityFlag.AgenticSessionRpc,
|
|
35
|
+
// ── OBSERVABILITY ────────────────────────────────────────────────────
|
|
36
|
+
CapabilityFlag.SessionId,
|
|
37
|
+
// ── CONTROL ──────────────────────────────────────────────────────────
|
|
38
|
+
CapabilityFlag.HardKill,
|
|
39
|
+
]);
|
|
40
|
+
//# sourceMappingURL=capabilities.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capabilities.js","sourceRoot":"","sources":["../../../../src/providers/adapters/pi-cli/capabilities.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAEtE,MAAM,CAAC,MAAM,iBAAiB,GAAG,aAAa,CAAC;IAC7C,wEAAwE;IACxE,cAAc,CAAC,iBAAiB;IAChC,cAAc,CAAC,iBAAiB;IAEhC,wEAAwE;IACxE,cAAc,CAAC,SAAS;IAExB,wEAAwE;IACxE,cAAc,CAAC,QAAQ;CACxB,CAAC,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration shape for the pi-cli adapter.
|
|
3
|
+
*
|
|
4
|
+
* Pi auth (per the P0.1 hands-on eval, pi 0.78.1 — docs/specs/_drafts/
|
|
5
|
+
* pi-eval-report.md):
|
|
6
|
+
* - pi reads `~/.pi/agent/auth.json` (subscription OAuth — Codex/ChatGPT,
|
|
7
|
+
* Claude Pro/Max, GitHub Copilot) and `~/.pi/agent/models.json` (custom
|
|
8
|
+
* provider definitions, e.g. an openai-completions endpoint). THESE ARE
|
|
9
|
+
* THE ALLOWED auth paths. Pi owns the provider quirks; we only pin HOME
|
|
10
|
+
* so pi can find them (see transport/piSpawn.ts).
|
|
11
|
+
* - A billing-capable provider key inherited from the parent env
|
|
12
|
+
* (ANTHROPIC_API_KEY, OPENAI_API_KEY, …) could silently route spend onto
|
|
13
|
+
* an API account. The env-allowlist (piSpawn.ts) unconditionally deletes
|
|
14
|
+
* those billing-capable vars from the child env — the no-API-keys rule.
|
|
15
|
+
*
|
|
16
|
+
* The Anthropic-provider SUBSCRIPTION GUARD (allowAnthropicProviders below) is
|
|
17
|
+
* the §4.3 structural flag; its ENFORCEMENT lives in policy.ts (a separate
|
|
18
|
+
* file written in parallel), NOT here. This file only carries the flag.
|
|
19
|
+
*/
|
|
20
|
+
export interface PiCliConfig {
|
|
21
|
+
/** Absolute path to the `pi` CLI binary. */
|
|
22
|
+
piPath: string;
|
|
23
|
+
/**
|
|
24
|
+
* Default model pattern. A pi `provider/id` pattern (or bare id) passed
|
|
25
|
+
* through to the CLI `--model <pattern>` flag. When unset, pi's OWN
|
|
26
|
+
* configured default provider/model applies — tier vocabulary lives inside
|
|
27
|
+
* the configured provider for pi (see transport/oneShotCompletion.ts).
|
|
28
|
+
*/
|
|
29
|
+
model?: string;
|
|
30
|
+
/** Default timeout for one-shot calls (ms). */
|
|
31
|
+
timeoutMs?: number;
|
|
32
|
+
/** Hard cap on captured stdout/stderr bytes per stream. */
|
|
33
|
+
maxOutputBytes?: number;
|
|
34
|
+
/**
|
|
35
|
+
* SUBSCRIPTION GUARD (PI-HARNESS-INTEGRATION-SPEC §4.3). When FALSE (the
|
|
36
|
+
* default), constructing a pi call against an Anthropic/Claude provider is
|
|
37
|
+
* structurally DENIED — routing Claude work through pi bills as per-token
|
|
38
|
+
* EXTRA USAGE, not plan limits. Set TRUE in `.instar/config.json` to opt in
|
|
39
|
+
* (the call is then audit-logged with a cost warning). The enforcement of
|
|
40
|
+
* this flag lives in policy.ts; this field is only the input to it.
|
|
41
|
+
*/
|
|
42
|
+
allowAnthropicProviders?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Override for pi's session-file directory (`--session-dir`). Pin this into
|
|
45
|
+
* the agent-home state dir for durability + reap-log coherence (eval caveat
|
|
46
|
+
* 4: session files are per-cwd-keyed by default). One-shot calls run
|
|
47
|
+
* `--no-session` and do not touch it.
|
|
48
|
+
*/
|
|
49
|
+
sessionDir?: string;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Build a config from environment variables, with sensible defaults.
|
|
53
|
+
*
|
|
54
|
+
* Binary detection: when `PI_CLI_PATH` is not set, falls back to
|
|
55
|
+
* `detectPiPath()` (the existing `detectFrameworkBinary('pi')` wrapper, which
|
|
56
|
+
* probes the standard install locations). NEVER hardcode developer-specific
|
|
57
|
+
* paths here — a verified box-local path is a fact for THIS box, not a value
|
|
58
|
+
* to bake in.
|
|
59
|
+
*
|
|
60
|
+
* `allowAnthropicProviders` defaults to FALSE — the §4.3 subscription guard is
|
|
61
|
+
* deny-by-default and the override is intentionally NOT env-settable (it must
|
|
62
|
+
* be an explicit `.instar/config.json` line; see policy.ts).
|
|
63
|
+
*/
|
|
64
|
+
export declare function configFromEnv(env?: NodeJS.ProcessEnv): PiCliConfig;
|
|
65
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../../src/providers/adapters/pi-cli/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAIH,MAAM,WAAW,WAAW;IAC1B,4CAA4C;IAC5C,MAAM,EAAE,MAAM,CAAC;IACf;;;;;OAKG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,+CAA+C;IAC/C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,2DAA2D;IAC3D,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;;;;;OAOG;IACH,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAClC;;;;;OAKG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CAAC,GAAG,GAAE,MAAM,CAAC,UAAwB,GAAG,WAAW,CAQ/E"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration shape for the pi-cli adapter.
|
|
3
|
+
*
|
|
4
|
+
* Pi auth (per the P0.1 hands-on eval, pi 0.78.1 — docs/specs/_drafts/
|
|
5
|
+
* pi-eval-report.md):
|
|
6
|
+
* - pi reads `~/.pi/agent/auth.json` (subscription OAuth — Codex/ChatGPT,
|
|
7
|
+
* Claude Pro/Max, GitHub Copilot) and `~/.pi/agent/models.json` (custom
|
|
8
|
+
* provider definitions, e.g. an openai-completions endpoint). THESE ARE
|
|
9
|
+
* THE ALLOWED auth paths. Pi owns the provider quirks; we only pin HOME
|
|
10
|
+
* so pi can find them (see transport/piSpawn.ts).
|
|
11
|
+
* - A billing-capable provider key inherited from the parent env
|
|
12
|
+
* (ANTHROPIC_API_KEY, OPENAI_API_KEY, …) could silently route spend onto
|
|
13
|
+
* an API account. The env-allowlist (piSpawn.ts) unconditionally deletes
|
|
14
|
+
* those billing-capable vars from the child env — the no-API-keys rule.
|
|
15
|
+
*
|
|
16
|
+
* The Anthropic-provider SUBSCRIPTION GUARD (allowAnthropicProviders below) is
|
|
17
|
+
* the §4.3 structural flag; its ENFORCEMENT lives in policy.ts (a separate
|
|
18
|
+
* file written in parallel), NOT here. This file only carries the flag.
|
|
19
|
+
*/
|
|
20
|
+
import { detectPiPath } from '../../../core/Config.js';
|
|
21
|
+
/**
|
|
22
|
+
* Build a config from environment variables, with sensible defaults.
|
|
23
|
+
*
|
|
24
|
+
* Binary detection: when `PI_CLI_PATH` is not set, falls back to
|
|
25
|
+
* `detectPiPath()` (the existing `detectFrameworkBinary('pi')` wrapper, which
|
|
26
|
+
* probes the standard install locations). NEVER hardcode developer-specific
|
|
27
|
+
* paths here — a verified box-local path is a fact for THIS box, not a value
|
|
28
|
+
* to bake in.
|
|
29
|
+
*
|
|
30
|
+
* `allowAnthropicProviders` defaults to FALSE — the §4.3 subscription guard is
|
|
31
|
+
* deny-by-default and the override is intentionally NOT env-settable (it must
|
|
32
|
+
* be an explicit `.instar/config.json` line; see policy.ts).
|
|
33
|
+
*/
|
|
34
|
+
export function configFromEnv(env = process.env) {
|
|
35
|
+
return {
|
|
36
|
+
piPath: env['PI_CLI_PATH'] || detectPiPath() || 'pi',
|
|
37
|
+
// Undefined → pi's own configured default provider/model applies.
|
|
38
|
+
model: env['PI_CLI_MODEL'],
|
|
39
|
+
timeoutMs: 60_000,
|
|
40
|
+
allowAnthropicProviders: false,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../../../src/providers/adapters/pi-cli/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAkCvD;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,aAAa,CAAC,MAAyB,OAAO,CAAC,GAAG;IAChE,OAAO;QACL,MAAM,EAAE,GAAG,CAAC,aAAa,CAAC,IAAI,YAAY,EAAE,IAAI,IAAI;QACpD,kEAAkE;QAClE,KAAK,EAAE,GAAG,CAAC,cAAc,CAAC;QAC1B,SAAS,EAAE,MAAM;QACjB,uBAAuB,EAAE,KAAK;KAC/B,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HardKill implementation for pi-cli.
|
|
3
|
+
*
|
|
4
|
+
* SIGTERM→SIGKILL escalation on a process pid — the framework-agnostic
|
|
5
|
+
* process-level kill (mirrors gemini-cli/control/geminiHardKill.ts). The
|
|
6
|
+
* minimal pi one-shot body runs spawns directly (the agentic TUI/RPC paths
|
|
7
|
+
* run inside tmux and are handled by their own control surface), so the honest
|
|
8
|
+
* unit of force-termination here is the child process pid, encoded in the
|
|
9
|
+
* SessionHandle as `pi-cli/pid-<n>` (see sessionId.pidHandle).
|
|
10
|
+
*
|
|
11
|
+
* A handle that is not a pid handle resolves to a no-op (nothing to kill) —
|
|
12
|
+
* the adapter never claims to kill a session it has no process for.
|
|
13
|
+
*/
|
|
14
|
+
import type { SessionHandle } from '../../../types.js';
|
|
15
|
+
import type { HardKill } from '../../../primitives/control/hardKill.js';
|
|
16
|
+
/** Extract the pid from a `pi-cli/pid-<n>` handle, or null. */
|
|
17
|
+
export declare function pidFromHandle(session: SessionHandle): number | null;
|
|
18
|
+
export declare function createHardKill(): HardKill;
|
|
19
|
+
//# sourceMappingURL=piHardKill.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"piHardKill.d.ts","sourceRoot":"","sources":["../../../../../src/providers/adapters/pi-cli/control/piHardKill.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,KAAK,EAAE,QAAQ,EAAmB,MAAM,yCAAyC,CAAC;AAMzF,+DAA+D;AAC/D,wBAAgB,aAAa,CAAC,OAAO,EAAE,aAAa,GAAG,MAAM,GAAG,IAAI,CAKnE;AA4CD,wBAAgB,cAAc,IAAI,QAAQ,CAEzC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HardKill implementation for pi-cli.
|
|
3
|
+
*
|
|
4
|
+
* SIGTERM→SIGKILL escalation on a process pid — the framework-agnostic
|
|
5
|
+
* process-level kill (mirrors gemini-cli/control/geminiHardKill.ts). The
|
|
6
|
+
* minimal pi one-shot body runs spawns directly (the agentic TUI/RPC paths
|
|
7
|
+
* run inside tmux and are handled by their own control surface), so the honest
|
|
8
|
+
* unit of force-termination here is the child process pid, encoded in the
|
|
9
|
+
* SessionHandle as `pi-cli/pid-<n>` (see sessionId.pidHandle).
|
|
10
|
+
*
|
|
11
|
+
* A handle that is not a pid handle resolves to a no-op (nothing to kill) —
|
|
12
|
+
* the adapter never claims to kill a session it has no process for.
|
|
13
|
+
*/
|
|
14
|
+
import { CapabilityFlag } from '../../../capabilities.js';
|
|
15
|
+
import { PI_CLI_ID } from '../errors.js';
|
|
16
|
+
const PID_PREFIX = `${PI_CLI_ID}/pid-`;
|
|
17
|
+
/** Extract the pid from a `pi-cli/pid-<n>` handle, or null. */
|
|
18
|
+
export function pidFromHandle(session) {
|
|
19
|
+
const s = String(session);
|
|
20
|
+
if (!s.startsWith(PID_PREFIX))
|
|
21
|
+
return null;
|
|
22
|
+
const n = Number(s.slice(PID_PREFIX.length));
|
|
23
|
+
return Number.isInteger(n) && n > 0 ? n : null;
|
|
24
|
+
}
|
|
25
|
+
function isAlive(pid) {
|
|
26
|
+
try {
|
|
27
|
+
process.kill(pid, 0);
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
class PiCliHardKill {
|
|
35
|
+
capability = CapabilityFlag.HardKill;
|
|
36
|
+
async kill(session, options) {
|
|
37
|
+
const pid = pidFromHandle(session);
|
|
38
|
+
if (pid === null) {
|
|
39
|
+
// No process bound to this handle — nothing to kill (honest no-op).
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const graceMs = options?.graceMs ?? 5000;
|
|
43
|
+
if (!isAlive(pid))
|
|
44
|
+
return;
|
|
45
|
+
try {
|
|
46
|
+
process.kill(pid, 'SIGTERM');
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
// Already gone between the liveness check and the signal — fine.
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
// Grace period, then verify + escalate.
|
|
53
|
+
await new Promise((resolve) => setTimeout(resolve, graceMs).unref?.() ?? resolve());
|
|
54
|
+
if (isAlive(pid)) {
|
|
55
|
+
try {
|
|
56
|
+
process.kill(pid, 'SIGKILL');
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
// Raced to death — fine.
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
export function createHardKill() {
|
|
65
|
+
return new PiCliHardKill();
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=piHardKill.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"piHardKill.js","sourceRoot":"","sources":["../../../../../src/providers/adapters/pi-cli/control/piHardKill.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MA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AAO,CAAO,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE,IAAI,OAAO,EAAE,CAAC,CAAC;QAE1F,IAAI,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;YACjB,IAAI,CAAC;gBACH,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC;YAC/B,CAAC;YAAC,MAAM,CAAC;gBACP,yBAAyB;YAC3B,CAAC;QACH,CAAC;IACH,CAAC;CACF;AAED,MAAM,UAAU,cAAc;IAC5B,OAAO,IAAI,aAAa,EAAE,CAAC;AAC7B,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adapter-specific error helpers for pi-cli.
|
|
3
|
+
*
|
|
4
|
+
* Maps raw failures (pi CLI non-zero exit, timeout/abort) to the canonical
|
|
5
|
+
* ProviderError hierarchy. Mirrors gemini-cli/errors.ts 1:1 but scoped to pi,
|
|
6
|
+
* plus the one pi-specific error class the subscription guard needs
|
|
7
|
+
* (`PiAnthropicRouteError`, PI-HARNESS-INTEGRATION-SPEC §4.3 — thrown by
|
|
8
|
+
* policy.ts, NOT this file).
|
|
9
|
+
*/
|
|
10
|
+
import { AuthError, ProviderError } from '../../errors.js';
|
|
11
|
+
import { type ProviderId } from '../../types.js';
|
|
12
|
+
/** Stable provider id for the pi coding agent adapter. */
|
|
13
|
+
export declare const PI_CLI_ID: ProviderId;
|
|
14
|
+
/**
|
|
15
|
+
* The subscription-guard error (PI-HARNESS-INTEGRATION-SPEC §4.3).
|
|
16
|
+
*
|
|
17
|
+
* Thrown by `policy.ts` (`assertPiProviderAllowed`) — NOT by this file's
|
|
18
|
+
* `mapExecError` — when a pi call is constructed against an Anthropic/Claude
|
|
19
|
+
* provider without the explicit `piCli.allowAnthropicProviders` override.
|
|
20
|
+
* Routing Claude work through pi bills as per-token EXTRA USAGE rather than
|
|
21
|
+
* counting against plan limits, so the default is structural DENY. It lives
|
|
22
|
+
* in the error hierarchy (an `AuthError` subclass — a credential/route
|
|
23
|
+
* authorization refusal, distinct from a quota/rate failure) so callers that
|
|
24
|
+
* already branch on `AuthError` surface it uniformly.
|
|
25
|
+
*/
|
|
26
|
+
export declare class PiAnthropicRouteError extends AuthError {
|
|
27
|
+
/** The offending `--model` pattern (a `provider/id` string or bare id). */
|
|
28
|
+
readonly modelPattern?: string;
|
|
29
|
+
constructor(modelPattern?: string);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Map a raw spawn-style error from spawning `pi` into a canonical provider
|
|
33
|
+
* error. Stderr is inspected for auth / rate-limit / quota / network
|
|
34
|
+
* signatures (the same classification shape gemini/codex use) so the circuit
|
|
35
|
+
* breaker's rate-limit classifier can see usage/limit language.
|
|
36
|
+
*/
|
|
37
|
+
export declare function mapExecError(err: Error & {
|
|
38
|
+
code?: string | number;
|
|
39
|
+
signal?: string;
|
|
40
|
+
killed?: boolean;
|
|
41
|
+
path?: string;
|
|
42
|
+
}, stderr?: string): ProviderError;
|
|
43
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../../src/providers/adapters/pi-cli/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAEL,SAAS,EAET,aAAa,EAKd,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAc,KAAK,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE7D,0DAA0D;AAC1D,eAAO,MAAM,SAAS,EAAE,UAAiC,CAAC;AAE1D;;;;;;;;;;;GAWG;AACH,qBAAa,qBAAsB,SAAQ,SAAS;IAClD,2EAA2E;IAC3E,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;gBAEnB,YAAY,CAAC,EAAE,MAAM;CAalC;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAC1B,GAAG,EAAE,KAAK,GAAG;IAAE,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,EACzF,MAAM,SAAK,GACV,aAAa,CAiCf"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adapter-specific error helpers for pi-cli.
|
|
3
|
+
*
|
|
4
|
+
* Maps raw failures (pi CLI non-zero exit, timeout/abort) to the canonical
|
|
5
|
+
* ProviderError hierarchy. Mirrors gemini-cli/errors.ts 1:1 but scoped to pi,
|
|
6
|
+
* plus the one pi-specific error class the subscription guard needs
|
|
7
|
+
* (`PiAnthropicRouteError`, PI-HARNESS-INTEGRATION-SPEC §4.3 — thrown by
|
|
8
|
+
* policy.ts, NOT this file).
|
|
9
|
+
*/
|
|
10
|
+
import { AbortError, AuthError, NetworkError, QuotaError, RateLimitError, TimeoutError, UnexpectedError, } from '../../errors.js';
|
|
11
|
+
import { providerId } from '../../types.js';
|
|
12
|
+
/** Stable provider id for the pi coding agent adapter. */
|
|
13
|
+
export const PI_CLI_ID = providerId('pi-cli');
|
|
14
|
+
/**
|
|
15
|
+
* The subscription-guard error (PI-HARNESS-INTEGRATION-SPEC §4.3).
|
|
16
|
+
*
|
|
17
|
+
* Thrown by `policy.ts` (`assertPiProviderAllowed`) — NOT by this file's
|
|
18
|
+
* `mapExecError` — when a pi call is constructed against an Anthropic/Claude
|
|
19
|
+
* provider without the explicit `piCli.allowAnthropicProviders` override.
|
|
20
|
+
* Routing Claude work through pi bills as per-token EXTRA USAGE rather than
|
|
21
|
+
* counting against plan limits, so the default is structural DENY. It lives
|
|
22
|
+
* in the error hierarchy (an `AuthError` subclass — a credential/route
|
|
23
|
+
* authorization refusal, distinct from a quota/rate failure) so callers that
|
|
24
|
+
* already branch on `AuthError` surface it uniformly.
|
|
25
|
+
*/
|
|
26
|
+
export class PiAnthropicRouteError extends AuthError {
|
|
27
|
+
/** The offending `--model` pattern (a `provider/id` string or bare id). */
|
|
28
|
+
modelPattern;
|
|
29
|
+
constructor(modelPattern) {
|
|
30
|
+
super(`pi-cli refuses to route to an Anthropic/Claude provider` +
|
|
31
|
+
(modelPattern ? ` (model=${modelPattern})` : '') +
|
|
32
|
+
`: third-party-harness usage bills as Anthropic EXTRA USAGE (per-token), ` +
|
|
33
|
+
`not plan limits — use claude-code instead, or set ` +
|
|
34
|
+
`piCli.allowAnthropicProviders=true to opt in.`, PI_CLI_ID);
|
|
35
|
+
this.name = 'PiAnthropicRouteError';
|
|
36
|
+
this.modelPattern = modelPattern;
|
|
37
|
+
Object.setPrototypeOf(this, PiAnthropicRouteError.prototype);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Map a raw spawn-style error from spawning `pi` into a canonical provider
|
|
42
|
+
* error. Stderr is inspected for auth / rate-limit / quota / network
|
|
43
|
+
* signatures (the same classification shape gemini/codex use) so the circuit
|
|
44
|
+
* breaker's rate-limit classifier can see usage/limit language.
|
|
45
|
+
*/
|
|
46
|
+
export function mapExecError(err, stderr = '') {
|
|
47
|
+
if (err.name === 'AbortError') {
|
|
48
|
+
return new AbortError('Pi exec aborted', PI_CLI_ID, err);
|
|
49
|
+
}
|
|
50
|
+
if (err.signal === 'SIGTERM' || err.killed) {
|
|
51
|
+
return new TimeoutError(`pi CLI killed: ${err.message}`, PI_CLI_ID, 0, { cause: err });
|
|
52
|
+
}
|
|
53
|
+
if (err.code === 'ENOENT') {
|
|
54
|
+
return new UnexpectedError(`pi CLI binary not found: ${err.path ?? '(unknown)'}`, PI_CLI_ID, err);
|
|
55
|
+
}
|
|
56
|
+
const message = stderr ? stderr.slice(0, 500) : err.message;
|
|
57
|
+
if (/unauthor|forbidden|invalid.*token|invalid.*key|401|403/i.test(stderr)) {
|
|
58
|
+
return new AuthError(message, PI_CLI_ID, err);
|
|
59
|
+
}
|
|
60
|
+
if (/rate.?limit|429|too many requests|resource.?exhausted/i.test(stderr)) {
|
|
61
|
+
return new RateLimitError(message, PI_CLI_ID, { cause: err });
|
|
62
|
+
}
|
|
63
|
+
if (/quota|usage.?limit/i.test(stderr)) {
|
|
64
|
+
return new QuotaError(message, PI_CLI_ID, { limitKind: 'unknown', cause: err });
|
|
65
|
+
}
|
|
66
|
+
if (/network|ECONN|ETIMEDOUT|dns/i.test(stderr)) {
|
|
67
|
+
return new NetworkError(message, PI_CLI_ID, err);
|
|
68
|
+
}
|
|
69
|
+
return new UnexpectedError(message, PI_CLI_ID, err);
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../../src/providers/adapters/pi-cli/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EACL,UAAU,EACV,SAAS,EACT,YAAY,EAEZ,UAAU,EACV,cAAc,EACd,YAAY,EACZ,eAAe,GAChB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,UAAU,EAAmB,MAAM,gBAAgB,CAAC;AAE7D,0DAA0D;AAC1D,MAAM,CAAC,MAAM,SAAS,GAAe,UAAU,CAAC,QAAQ,CAAC,CAAC;AAE1D;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,qBAAsB,SAAQ,SAAS;IAClD,2EAA2E;IAClE,YAAY,CAAU;IAE/B,YAAY,YAAqB;QAC/B,KAAK,CACH,yDAAyD;YACvD,CAAC,YAAY,CAAC,CAAC,CAAC,WAAW,YAAY,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;YAChD,0EAA0E;YAC1E,oDAAoD;YACpD,+CAA+C,EACjD,SAAS,CACV,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;QACpC,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,MAAM,CAAC,cAAc,CAAC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OAAO,EAAE,SAAS,EAAE,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC;IAClF,CAAC;IACD,IAAI,8BAA8B,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;QAChD,OAAO,IAAI,YAAY,CAAC,OAAO,EAAE,SAAS,EAAE,GAAG,CAAC,CAAC;IACnD,CAAC;IACD,OAAO,IAAI,eAAe,CAAC,OAAO,EAAE,SAAS,EAAE,GAAG,CAAC,CAAC;AACtD,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* pi-cli adapter — entry point (PI-HARNESS-INTEGRATION-SPEC §4.2).
|
|
3
|
+
*
|
|
4
|
+
* Mirrors the gemini-cli/openai-codex adapter shape: a factory that builds an
|
|
5
|
+
* `impls` map and returns a `ProviderAdapter`. Declares the honest capability
|
|
6
|
+
* floor (capabilities.ts) — every wired primitive was verified hands-on in
|
|
7
|
+
* the P0.1 eval (pi 0.78.1, docs/specs/_drafts/pi-eval-report.md).
|
|
8
|
+
*
|
|
9
|
+
* THE GUARD (spec §4.3): both transports enforce `assertPiProviderAllowed`
|
|
10
|
+
* at call/session construction — an Anthropic/Claude-routed model pattern
|
|
11
|
+
* throws `PiAnthropicRouteError` unless `allowAnthropicProviders` is
|
|
12
|
+
* explicitly set in config (and even then it is audit-logged). A config with
|
|
13
|
+
* NO model pinned is also denied at call time: pi's ambient default model
|
|
14
|
+
* could be an Anthropic login from interactive use, so explicitness is the
|
|
15
|
+
* floor. Justin's additive-only constraint, enforced structurally.
|
|
16
|
+
*
|
|
17
|
+
* Registration: `registerPiAdapters()` (bootRegistration.ts) — gated on
|
|
18
|
+
* `enabledFrameworks` containing 'pi-cli' AND the binary being detectable.
|
|
19
|
+
* Ships dark: no opt-in, no registration, zero behavior change.
|
|
20
|
+
*
|
|
21
|
+
* Usage:
|
|
22
|
+
*
|
|
23
|
+
* import { createPiCliAdapter } from './providers/adapters/pi-cli/index.js';
|
|
24
|
+
* import { registry } from './providers/registry.js';
|
|
25
|
+
*
|
|
26
|
+
* await registry.register(createPiCliAdapter({ model: 'openai-codex/gpt-5.5' }));
|
|
27
|
+
*/
|
|
28
|
+
import type { ProviderAdapter } from '../../registry.js';
|
|
29
|
+
import { type PiCliConfig } from './config.js';
|
|
30
|
+
/**
|
|
31
|
+
* Create the pi-cli adapter with the given config (or environment defaults
|
|
32
|
+
* if omitted).
|
|
33
|
+
*/
|
|
34
|
+
export declare function createPiCliAdapter(partialConfig?: Partial<PiCliConfig>): ProviderAdapter;
|
|
35
|
+
export type { PiCliConfig } from './config.js';
|
|
36
|
+
export { configFromEnv } from './config.js';
|
|
37
|
+
export { PI_CLI_ID, PiAnthropicRouteError } from './errors.js';
|
|
38
|
+
export { assertPiProviderAllowed, isAnthropicRoutedModelPattern } from './policy.js';
|
|
39
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/providers/adapters/pi-cli/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAGH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAIzD,OAAO,EAAiB,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AAS9D;;;GAGG;AACH,wBAAgB,kBAAkB,CAChC,aAAa,GAAE,OAAO,CAAC,WAAW,CAAM,GACvC,eAAe,CA6BjB;AAED,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAC/D,OAAO,EAAE,uBAAuB,EAAE,6BAA6B,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* pi-cli adapter — entry point (PI-HARNESS-INTEGRATION-SPEC §4.2).
|
|
3
|
+
*
|
|
4
|
+
* Mirrors the gemini-cli/openai-codex adapter shape: a factory that builds an
|
|
5
|
+
* `impls` map and returns a `ProviderAdapter`. Declares the honest capability
|
|
6
|
+
* floor (capabilities.ts) — every wired primitive was verified hands-on in
|
|
7
|
+
* the P0.1 eval (pi 0.78.1, docs/specs/_drafts/pi-eval-report.md).
|
|
8
|
+
*
|
|
9
|
+
* THE GUARD (spec §4.3): both transports enforce `assertPiProviderAllowed`
|
|
10
|
+
* at call/session construction — an Anthropic/Claude-routed model pattern
|
|
11
|
+
* throws `PiAnthropicRouteError` unless `allowAnthropicProviders` is
|
|
12
|
+
* explicitly set in config (and even then it is audit-logged). A config with
|
|
13
|
+
* NO model pinned is also denied at call time: pi's ambient default model
|
|
14
|
+
* could be an Anthropic login from interactive use, so explicitness is the
|
|
15
|
+
* floor. Justin's additive-only constraint, enforced structurally.
|
|
16
|
+
*
|
|
17
|
+
* Registration: `registerPiAdapters()` (bootRegistration.ts) — gated on
|
|
18
|
+
* `enabledFrameworks` containing 'pi-cli' AND the binary being detectable.
|
|
19
|
+
* Ships dark: no opt-in, no registration, zero behavior change.
|
|
20
|
+
*
|
|
21
|
+
* Usage:
|
|
22
|
+
*
|
|
23
|
+
* import { createPiCliAdapter } from './providers/adapters/pi-cli/index.js';
|
|
24
|
+
* import { registry } from './providers/registry.js';
|
|
25
|
+
*
|
|
26
|
+
* await registry.register(createPiCliAdapter({ model: 'openai-codex/gpt-5.5' }));
|
|
27
|
+
*/
|
|
28
|
+
import { UnsupportedCapabilityError } from '../../errors.js';
|
|
29
|
+
import { piCliCapabilities } from './capabilities.js';
|
|
30
|
+
import { PI_CLI_ID } from './errors.js';
|
|
31
|
+
import { configFromEnv } from './config.js';
|
|
32
|
+
import { createOneShotCompletion } from './transport/oneShotCompletion.js';
|
|
33
|
+
import { createPiAgenticSessionRpc } from './transport/agenticSessionRpc.js';
|
|
34
|
+
import { createSessionId } from './observability/sessionId.js';
|
|
35
|
+
import { createHardKill } from './control/piHardKill.js';
|
|
36
|
+
import { CapabilityFlag as Cap } from '../../capabilities.js';
|
|
37
|
+
/**
|
|
38
|
+
* Create the pi-cli adapter with the given config (or environment defaults
|
|
39
|
+
* if omitted).
|
|
40
|
+
*/
|
|
41
|
+
export function createPiCliAdapter(partialConfig = {}) {
|
|
42
|
+
const config = {
|
|
43
|
+
...configFromEnv(),
|
|
44
|
+
...partialConfig,
|
|
45
|
+
};
|
|
46
|
+
const impls = new Map();
|
|
47
|
+
// Transport
|
|
48
|
+
impls.set(Cap.OneShotCompletion, createOneShotCompletion(config));
|
|
49
|
+
impls.set(Cap.AgenticSessionRpc, createPiAgenticSessionRpc(config));
|
|
50
|
+
// Observability
|
|
51
|
+
impls.set(Cap.SessionId, createSessionId());
|
|
52
|
+
// Control
|
|
53
|
+
impls.set(Cap.HardKill, createHardKill());
|
|
54
|
+
return {
|
|
55
|
+
id: PI_CLI_ID,
|
|
56
|
+
capabilities: piCliCapabilities,
|
|
57
|
+
primitive(capability) {
|
|
58
|
+
const impl = impls.get(capability);
|
|
59
|
+
if (impl === undefined) {
|
|
60
|
+
throw new UnsupportedCapabilityError(capability, PI_CLI_ID);
|
|
61
|
+
}
|
|
62
|
+
return impl;
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
export { configFromEnv } from './config.js';
|
|
67
|
+
export { PI_CLI_ID, PiAnthropicRouteError } from './errors.js';
|
|
68
|
+
export { assertPiProviderAllowed, isAnthropicRoutedModelPattern } from './policy.js';
|
|
69
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/providers/adapters/pi-cli/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAIH,OAAO,EAAE,0BAA0B,EAAE,MAAM,iBAAiB,CAAC;AAC7D,OA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,EAAE,SAAS,CAAC,CAAC;YAC9D,CAAC;YACD,OAAO,IAAI,CAAC;QACd,CAAC;KACF,CAAC;AACJ,CAAC;AAGD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAC/D,OAAO,EAAE,uBAAuB,EAAE,6BAA6B,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SessionId implementation for pi-cli.
|
|
3
|
+
*
|
|
4
|
+
* Pi assigns a session id to each session (the `sessionId` field in its RPC
|
|
5
|
+
* `get_state` response and in its on-disk session file under `--session-dir`).
|
|
6
|
+
* Pi session ids are UUIDv7 strings drawn from pi's session files. The
|
|
7
|
+
* adapter's SessionHandle binds to that pi-side session id. This primitive
|
|
8
|
+
* provides the binding both directions.
|
|
9
|
+
*
|
|
10
|
+
* Mirrors gemini-cli/observability/sessionId.ts: an in-memory bidirectional
|
|
11
|
+
* map, populated when the adapter observes a session's id, plus a synthetic
|
|
12
|
+
* handle for a known session id without a live process.
|
|
13
|
+
*/
|
|
14
|
+
import type { SessionHandle } from '../../../types.js';
|
|
15
|
+
import type { SessionId } from '../../../primitives/observability/sessionId.js';
|
|
16
|
+
/** Bind a pi session id (UUIDv7) to a SessionHandle. */
|
|
17
|
+
export declare function bindPiSessionId(handle: SessionHandle, sessionId: string): void;
|
|
18
|
+
/** Look up the SessionHandle for a pi session id (UUIDv7). */
|
|
19
|
+
export declare function handleForPiSession(sessionId: string): SessionHandle | null;
|
|
20
|
+
/** Construct a session handle for a known pi session without a live process. */
|
|
21
|
+
export declare function syntheticHandleForPiSession(sessionId: string): SessionHandle;
|
|
22
|
+
/** Construct a process-pid handle for a live one-shot spawn (used by HardKill). */
|
|
23
|
+
export declare function pidHandle(pid: number): SessionHandle;
|
|
24
|
+
export declare function createSessionId(): SessionId;
|
|
25
|
+
/** Test-only: clear the in-memory session-id binding maps. */
|
|
26
|
+
export declare function _resetPiSessionIdMaps(): void;
|
|
27
|
+
//# sourceMappingURL=sessionId.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sessionId.d.ts","sourceRoot":"","sources":["../../../../../src/providers/adapters/pi-cli/observability/sessionId.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAuB,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAE5E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gDAAgD,CAAC;AAmBhF,wDAAwD;AACxD,wBAAgB,eAAe,CAAC,MAAM,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI,CAG9E;AAED,8DAA8D;AAC9D,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,aAAa,GAAG,IAAI,CAE1E;AAED,gFAAgF;AAChF,wBAAgB,2BAA2B,CAAC,SAAS,EAAE,MAAM,GAAG,aAAa,CAE5E;AAED,mFAAmF;AACnF,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,aAAa,CAEpD;AAED,wBAAgB,eAAe,IAAI,SAAS,CAE3C;AAED,8DAA8D;AAC9D,wBAAgB,qBAAqB,IAAI,IAAI,CAG5C"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SessionId implementation for pi-cli.
|
|
3
|
+
*
|
|
4
|
+
* Pi assigns a session id to each session (the `sessionId` field in its RPC
|
|
5
|
+
* `get_state` response and in its on-disk session file under `--session-dir`).
|
|
6
|
+
* Pi session ids are UUIDv7 strings drawn from pi's session files. The
|
|
7
|
+
* adapter's SessionHandle binds to that pi-side session id. This primitive
|
|
8
|
+
* provides the binding both directions.
|
|
9
|
+
*
|
|
10
|
+
* Mirrors gemini-cli/observability/sessionId.ts: an in-memory bidirectional
|
|
11
|
+
* map, populated when the adapter observes a session's id, plus a synthetic
|
|
12
|
+
* handle for a known session id without a live process.
|
|
13
|
+
*/
|
|
14
|
+
import { sessionHandle } from '../../../types.js';
|
|
15
|
+
import { CapabilityFlag } from '../../../capabilities.js';
|
|
16
|
+
import { PI_CLI_ID } from '../errors.js';
|
|
17
|
+
const handleToSession = new Map();
|
|
18
|
+
const sessionToHandle = new Map();
|
|
19
|
+
class PiCliSessionId {
|
|
20
|
+
capability = CapabilityFlag.SessionId;
|
|
21
|
+
async providerIdFor(session, _options) {
|
|
22
|
+
return handleToSession.get(session) ?? null;
|
|
23
|
+
}
|
|
24
|
+
async handleFor(providerSessionId, _options) {
|
|
25
|
+
return sessionToHandle.get(providerSessionId) ?? null;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/** Bind a pi session id (UUIDv7) to a SessionHandle. */
|
|
29
|
+
export function bindPiSessionId(handle, sessionId) {
|
|
30
|
+
handleToSession.set(handle, sessionId);
|
|
31
|
+
sessionToHandle.set(sessionId, handle);
|
|
32
|
+
}
|
|
33
|
+
/** Look up the SessionHandle for a pi session id (UUIDv7). */
|
|
34
|
+
export function handleForPiSession(sessionId) {
|
|
35
|
+
return sessionToHandle.get(sessionId) ?? null;
|
|
36
|
+
}
|
|
37
|
+
/** Construct a session handle for a known pi session without a live process. */
|
|
38
|
+
export function syntheticHandleForPiSession(sessionId) {
|
|
39
|
+
return sessionHandle(`${PI_CLI_ID}/session-${sessionId}`);
|
|
40
|
+
}
|
|
41
|
+
/** Construct a process-pid handle for a live one-shot spawn (used by HardKill). */
|
|
42
|
+
export function pidHandle(pid) {
|
|
43
|
+
return sessionHandle(`${PI_CLI_ID}/pid-${pid}`);
|
|
44
|
+
}
|
|
45
|
+
export function createSessionId() {
|
|
46
|
+
return new PiCliSessionId();
|
|
47
|
+
}
|
|
48
|
+
/** Test-only: clear the in-memory session-id binding maps. */
|
|
49
|
+
export function _resetPiSessionIdMaps() {
|
|
50
|
+
handleToSession.clear();
|
|
51
|
+
sessionToHandle.clear();
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=sessionId.js.map
|