pi-cowboy 0.15.2 → 0.17.2
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 +12 -9
- package/dist/agents/agent-assets.d.ts +114 -0
- package/dist/agents/agent-assets.js +42 -29
- package/dist/agents/agent-cleanup.d.ts +82 -0
- package/dist/agents/agent-cleanup.js +6 -6
- package/dist/agents/agent-discovery.d.ts +22 -0
- package/dist/agents/agent-discovery.js +7 -3
- package/dist/agents/agent-host.d.ts +212 -0
- package/dist/agents/agent-host.js +6 -3
- package/dist/agents/agent-manager.d.ts +99 -0
- package/dist/agents/agent-manager.js +21 -9
- package/dist/agents/agent-reviver.d.ts +38 -0
- package/dist/agents/agent-runner.d.ts +51 -0
- package/dist/agents/agent-runner.js +22 -31
- package/dist/agents/agent-spawn-store.d.ts +39 -0
- package/dist/agents/agent-template.d.ts +118 -0
- package/dist/agents/agent-template.js +7 -3
- package/dist/agents/agent-types.d.ts +59 -0
- package/dist/agents/agent-types.js +22 -6
- package/dist/agents/batch.d.ts +63 -0
- package/dist/agents/cleanup-policy.d.ts +288 -0
- package/dist/agents/cleanup-policy.js +2 -2
- package/dist/agents/cleanup-report.d.ts +14 -0
- package/dist/agents/default-agents.d.ts +8 -0
- package/dist/agents/harness/claude/index.d.ts +41 -0
- package/dist/agents/harness/claude/index.js +49 -7
- package/dist/agents/harness/claude/staging.d.ts +46 -0
- package/dist/agents/harness/claude/staging.js +3 -2
- package/dist/agents/harness/codex.d.ts +42 -0
- package/dist/agents/harness/codex.js +3 -4
- package/dist/agents/harness/harness-registry.d.ts +126 -0
- package/dist/agents/harness/harness-registry.js +272 -0
- package/dist/agents/harness/opencode/config.d.ts +39 -0
- package/dist/agents/harness/opencode/config.js +85 -0
- package/dist/agents/harness/opencode/definition.d.ts +21 -0
- package/dist/agents/harness/opencode/index.d.ts +33 -0
- package/dist/agents/harness/opencode/index.js +22 -7
- package/dist/agents/harness/opencode/permissions.d.ts +27 -0
- package/dist/agents/harness/opencode/staging.d.ts +50 -0
- package/dist/agents/harness/opencode/staging.js +17 -3
- package/dist/agents/harness/opencode/user-config.d.ts +36 -0
- package/dist/agents/harness/opencode/user-config.js +172 -0
- package/dist/agents/harness/opencode/version.d.ts +36 -0
- package/dist/agents/harness/pane-launcher.d.ts +89 -0
- package/dist/agents/harness/pane-launcher.js +23 -22
- package/dist/agents/harness/pi-bolt.d.ts +9 -0
- package/dist/agents/harness/pi-bolt.js +0 -1
- package/dist/agents/harness/pi-compatible.d.ts +48 -0
- package/dist/agents/harness/pi-compatible.js +3 -4
- package/dist/agents/harness/pig.d.ts +10 -0
- package/dist/agents/harness/pig.js +0 -1
- package/dist/agents/harness.d.ts +459 -0
- package/dist/agents/harness.js +46 -57
- package/dist/agents/multiplexer-registry.d.ts +101 -0
- package/dist/agents/multiplexer-registry.js +125 -0
- package/dist/agents/result-file-permissions.d.ts +19 -0
- package/dist/agents/run-state.d.ts +144 -0
- package/dist/agents/schemas/cleanup-batch.schema.d.ts +17 -0
- package/dist/agents/schemas/cowboy-agents.schema.d.ts +51 -0
- package/dist/agents/schemas/cowboy-agents.schema.js +1 -1
- package/dist/agents/schemas/merge-batch.schema.d.ts +21 -0
- package/dist/agents/schemas/steer-batch.schema.d.ts +19 -0
- package/dist/agents/schemas/stop-batch.schema.d.ts +16 -0
- package/dist/agents/spawn-defaults.d.ts +48 -0
- package/dist/agents/spawn-defaults.js +22 -21
- package/dist/agents/subagent-session.d.ts +161 -0
- package/dist/agents/subagent-session.js +10 -5
- package/dist/agents/tool-cleanup.d.ts +43 -0
- package/dist/agents/tool-execution.d.ts +61 -0
- package/dist/agents/tool-merge.d.ts +64 -0
- package/dist/agents/tool-result.d.ts +21 -0
- package/dist/agents/tool-steer.d.ts +40 -0
- package/dist/agents/types.d.ts +94 -0
- package/dist/availability.d.ts +42 -0
- package/dist/concurrency-pools.d.ts +168 -0
- package/dist/concurrency-pools.js +11 -9
- package/dist/config/concurrency-limit.d.ts +12 -0
- package/dist/config/config-io.d.ts +59 -0
- package/dist/config/config-io.js +12 -20
- package/dist/config/config-store.d.ts +201 -0
- package/dist/config/config-store.js +89 -42
- package/dist/config/config-validation.d.ts +7 -0
- package/dist/config/config-validation.js +90 -63
- package/dist/config/layered-config.d.ts +47 -0
- package/dist/config/layered-config.js +4 -0
- package/dist/config/types.d.ts +8 -0
- package/dist/cow-support-launch.d.ts +18 -0
- package/dist/events.d.ts +9 -0
- package/dist/events.js +71 -19
- package/dist/extension-toggle.d.ts +13 -0
- package/dist/harness-availability-launch.d.ts +47 -0
- package/dist/harness-availability-launch.js +48 -33
- package/dist/host-multiplexer.d.ts +42 -0
- package/dist/host-multiplexer.js +62 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +5 -16
- package/dist/infrastructure/exec-path.d.ts +13 -0
- package/dist/infrastructure/exec-sync.d.ts +18 -0
- package/dist/infrastructure/git/cow-clone.d.ts +111 -0
- package/dist/infrastructure/git/git-materializer.d.ts +146 -0
- package/dist/infrastructure/git/git-merger.d.ts +111 -0
- package/dist/infrastructure/git/git-merger.js +1 -1
- package/dist/infrastructure/git/git-retention.d.ts +21 -0
- package/dist/infrastructure/git/git-runner.d.ts +89 -0
- package/dist/infrastructure/git/git-worktree.d.ts +86 -0
- package/dist/infrastructure/git/index.d.ts +11 -0
- package/dist/infrastructure/git-client.d.ts +11 -0
- package/dist/infrastructure/herdr/agent-stopper.d.ts +33 -0
- package/dist/infrastructure/herdr/agents.d.ts +124 -0
- package/dist/infrastructure/herdr/agents.js +1 -1
- package/dist/infrastructure/herdr/herdr-client.d.ts +23 -0
- package/dist/infrastructure/herdr/herdr-transport.d.ts +57 -0
- package/dist/infrastructure/herdr/index.d.ts +15 -0
- package/dist/infrastructure/herdr/panes.d.ts +82 -0
- package/dist/infrastructure/herdr/polling.d.ts +41 -0
- package/dist/infrastructure/herdr/worktrees.d.ts +32 -0
- package/dist/infrastructure/herdr-client.d.ts +6 -0
- package/dist/infrastructure/herdr-host.d.ts +11 -0
- package/dist/infrastructure/herdr-host.js +55 -5
- package/dist/logger.d.ts +13 -0
- package/dist/models/foreign-model-resolver.d.ts +39 -0
- package/dist/models/model-groups.d.ts +56 -0
- package/dist/models/model-precedence.d.ts +135 -0
- package/dist/models/model-precedence.js +20 -7
- package/dist/models/model-request-types.d.ts +51 -0
- package/dist/models/model-request.d.ts +47 -0
- package/dist/models/pi-model-resolver.d.ts +35 -0
- package/dist/orchestrators/briefing-section.d.ts +9 -0
- package/dist/orchestrators/context.d.ts +143 -0
- package/dist/orchestrators/context.js +7 -1
- package/dist/orchestrators/cues.d.ts +31 -0
- package/dist/orchestrators/default-orchestrators.d.ts +10 -0
- package/dist/orchestrators/default-orchestrators.js +7 -2
- package/dist/orchestrators/orchestrator-discovery.d.ts +27 -0
- package/dist/orchestrators/orchestrator-template.d.ts +22 -0
- package/dist/orchestrators/orchestrator-types.d.ts +30 -0
- package/dist/orchestrators/protocol.d.ts +119 -0
- package/dist/orchestrators/protocol.js +7 -5
- package/dist/orchestrators/types.d.ts +18 -0
- package/dist/paths.d.ts +49 -0
- package/dist/paths.js +1 -1
- package/dist/pi-settings.d.ts +3 -0
- package/dist/plugin/contract.d.ts +56 -0
- package/dist/plugin/contract.js +17 -0
- package/dist/plugin/discovery.d.ts +59 -0
- package/dist/plugin/discovery.js +67 -0
- package/dist/plugin/index.d.ts +16 -0
- package/dist/plugin/index.js +14 -0
- package/dist/plugin/loader.d.ts +52 -0
- package/dist/plugin/loader.js +181 -0
- package/dist/plugin/manifest.d.ts +25 -0
- package/dist/plugin/manifest.js +47 -0
- package/dist/predicates.d.ts +18 -0
- package/dist/prompt/prompts.d.ts +40 -0
- package/dist/prompt/skill-loader.d.ts +28 -0
- package/dist/prompt/subagent-system-prompt.d.ts +50 -0
- package/dist/registration.d.ts +43 -0
- package/dist/registration.js +15 -3
- package/dist/session-runtime.d.ts +43 -0
- package/dist/session-runtime.js +92 -0
- package/dist/shell.d.ts +151 -0
- package/dist/shell.js +30 -5
- package/dist/spawn/cow-support.d.ts +26 -0
- package/dist/spawn/crockford-base32.d.ts +46 -0
- package/dist/spawn/crockford-base32.js +2 -2
- package/dist/spawn/herdr-launcher.d.ts +33 -0
- package/dist/spawn/repo-lock.d.ts +21 -0
- package/dist/spawn/sandbox.d.ts +130 -0
- package/dist/spawn/sandbox.js +3 -3
- package/dist/spawn/spawn-coordinator.d.ts +80 -0
- package/dist/spawn/spawn-coordinator.js +1 -1
- package/dist/spawn/spawn-id.d.ts +23 -0
- package/dist/spawn/worktree-policy.d.ts +68 -0
- package/dist/status-note.d.ts +7 -0
- package/dist/subagent/deliverable.d.ts +40 -0
- package/dist/subagent/pane-supervisor.d.ts +33 -0
- package/dist/subagent/pane-supervisor.js +1 -1
- package/dist/subagent/result-artifacts.d.ts +16 -0
- package/dist/subagent/supervisor.d.ts +157 -0
- package/dist/subagent/supervisor.js +4 -4
- package/dist/task-registry.d.ts +88 -0
- package/dist/task-registry.js +3 -3
- package/dist/templates/template-files.d.ts +35 -0
- package/dist/templates/template-files.js +8 -4
- package/dist/types.d.ts +268 -0
- package/dist/ui/action-report.d.ts +29 -0
- package/dist/ui/format.d.ts +17 -0
- package/dist/ui/indicator.d.ts +194 -0
- package/dist/ui/menu/helpers.d.ts +95 -0
- package/dist/ui/menu/menu-agent-settings.d.ts +8 -0
- package/dist/ui/menu/menu-agent-settings.js +18 -10
- package/dist/ui/menu/menu-agent-status-cleanup.d.ts +46 -0
- package/dist/ui/menu/menu-agent-status.d.ts +20 -0
- package/dist/ui/menu/menu-concurrency.d.ts +8 -0
- package/dist/ui/menu/menu-concurrency.js +11 -8
- package/dist/ui/menu/menu-model-settings.d.ts +30 -0
- package/dist/ui/menu/menu-model-settings.js +7 -5
- package/dist/ui/menu/menu-spawn-defaults.d.ts +20 -0
- package/dist/ui/menu/menu-spawn-wizard.d.ts +7 -0
- package/dist/ui/menu/menu-spawn-worktree.d.ts +46 -0
- package/dist/ui/menu/menu-system-prompt.d.ts +6 -0
- package/dist/ui/menu/menu-worktree-command.d.ts +17 -0
- package/dist/ui/menu/menus.d.ts +23 -0
- package/dist/ui/menu/model-picker.d.ts +19 -0
- package/dist/ui/menu/model-picker.js +2 -3
- package/dist/ui/menu/screen-host.d.ts +88 -0
- package/dist/ui/menu/submenus/confirm.d.ts +27 -0
- package/dist/ui/menu/submenus/model-select.d.ts +38 -0
- package/dist/ui/menu/submenus/name-field.d.ts +30 -0
- package/dist/ui/menu/submenus/numeric-input.d.ts +26 -0
- package/dist/ui/menu/submenus/target-select.d.ts +92 -0
- package/dist/ui/menu/submenus/text-editor.d.ts +42 -0
- package/dist/ui/menu/submenus/worktree-command-name.d.ts +40 -0
- package/dist/ui/menu/submenus/worktree-name.d.ts +39 -0
- package/dist/ui/menu/wrappers/settings-list.d.ts +41 -0
- package/dist/ui/searchable-select.d.ts +38 -0
- package/dist/ui/types.d.ts +7 -0
- package/dist/utils.d.ts +39 -0
- package/package.json +4 -2
- package/dist/agents/harness/registry.js +0 -76
- package/dist/agents/harness-family.js +0 -23
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* harness/claude/index.ts — the claude harness: a binary of its own, staged
|
|
3
|
+
* and launched behind the pane's `claude`.
|
|
4
|
+
*
|
|
5
|
+
* claude is not a pi-compatible binary: its task cannot ride the argv at all
|
|
6
|
+
* (herdr rejects multi-line arguments, and a task is multi-line text), so the
|
|
7
|
+
* launcher appends it as the positional initial prompt — past a `--` that ends
|
|
8
|
+
* option parsing, `"$(cat '<taskFile>')"` expands inside the pane's shell, where herdr's single-line
|
|
9
|
+
* argv encoding never reaches. `prepare` stages the config directory claude is
|
|
10
|
+
* pointed at (staging.ts), installs that launcher into the pane, and then
|
|
11
|
+
* proves the pane can see the staged files and resolve the binary; `buildArgs`
|
|
12
|
+
* is claude's interactive CLI with the task deliberately absent;
|
|
13
|
+
* `teardown` removes the staged tree.
|
|
14
|
+
*
|
|
15
|
+
* `listModels` is a curated constant: claude has no CLI enumeration, and a
|
|
16
|
+
* wrong list is worse than a short one, so it names only the aliases a real
|
|
17
|
+
* run was seen to answer (`haiku`, `sonnet`, `opus`) and nothing it was seen
|
|
18
|
+
* to refuse.
|
|
19
|
+
*
|
|
20
|
+
* The strict `[harness.claude]` table carries only `model` and the tool pair,
|
|
21
|
+
* both in claude's own vocabulary: the tool names ride `--tools` /
|
|
22
|
+
* `--disallowedTools` exactly as written, with no translation, and the model
|
|
23
|
+
* key's `anthropic/` prefix is stripped at the argv boundary because the CLI
|
|
24
|
+
* takes a bare alias or full model name.
|
|
25
|
+
*/
|
|
26
|
+
import type { ClaudeLaunchRequest, Harness } from "../../harness.js";
|
|
27
|
+
/**
|
|
28
|
+
* The value a spawn exports for its credential store.
|
|
29
|
+
*
|
|
30
|
+
* macOS keeps credentials in the Keychain, and the service name is
|
|
31
|
+
* `Claude Code-credentials` for an empty value and
|
|
32
|
+
* `Claude Code-credentials-<sha256(value)[:8]>` otherwise. The value is hashed
|
|
33
|
+
* verbatim, so the parent's value is forwarded unchanged; substituting
|
|
34
|
+
* `~/.claude` would select a different, empty item.
|
|
35
|
+
*
|
|
36
|
+
* Linux keeps `.credentials.json` under the value, so an empty value means
|
|
37
|
+
* `~/.claude` and the parent's directory is resolved. The value itself is not
|
|
38
|
+
* tilde-expanded, so the expansion happens here.
|
|
39
|
+
*/
|
|
40
|
+
export declare function spawnCredentialStore(platform: NodeJS.Platform): string;
|
|
41
|
+
export declare const claudeHarness: Harness<ClaudeLaunchRequest>;
|
|
@@ -23,8 +23,10 @@
|
|
|
23
23
|
* key's `anthropic/` prefix is stripped at the argv boundary because the CLI
|
|
24
24
|
* takes a bare alias or full model name.
|
|
25
25
|
*/
|
|
26
|
+
import { homedir } from "node:os";
|
|
27
|
+
import * as path from "node:path";
|
|
26
28
|
import { commandPath } from "../../../infrastructure/exec-path.js";
|
|
27
|
-
import { subagentTokenFor } from "../../../paths.js";
|
|
29
|
+
import { expandTilde, subagentTokenFor } from "../../../paths.js";
|
|
28
30
|
import { installPaneLauncher } from "../pane-launcher.js";
|
|
29
31
|
import { claudeSettingsFile, removeClaudeStaging, writeClaudeStaging, } from "./staging.js";
|
|
30
32
|
/** Budget for the pane's staged-state proof; shell builtins, no CLI boot. */
|
|
@@ -37,6 +39,42 @@ const LAUNCHER_SIGNATURE = "CLAUDE_LAUNCHER_3f7a1d";
|
|
|
37
39
|
const LAUNCHER_READY_MARKER = "CLAUDE_VERIFIED";
|
|
38
40
|
/** Token the staged-state proof echoes once the pane sees the launch state. */
|
|
39
41
|
const STAGED_MARKER = "CLAUDE_STAGED";
|
|
42
|
+
/**
|
|
43
|
+
* The credential store the parent session is using, as claude derives it.
|
|
44
|
+
* An explicitly empty `CLAUDE_SECURESTORAGE_CONFIG_DIR` is meaningful — it
|
|
45
|
+
* pins the default store — so `??` is required here rather than `||`.
|
|
46
|
+
*/
|
|
47
|
+
function parentCredentialStore() {
|
|
48
|
+
return (process.env.CLAUDE_SECURESTORAGE_CONFIG_DIR ??
|
|
49
|
+
process.env.CLAUDE_CONFIG_DIR ??
|
|
50
|
+
"");
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The value a spawn exports for its credential store.
|
|
54
|
+
*
|
|
55
|
+
* macOS keeps credentials in the Keychain, and the service name is
|
|
56
|
+
* `Claude Code-credentials` for an empty value and
|
|
57
|
+
* `Claude Code-credentials-<sha256(value)[:8]>` otherwise. The value is hashed
|
|
58
|
+
* verbatim, so the parent's value is forwarded unchanged; substituting
|
|
59
|
+
* `~/.claude` would select a different, empty item.
|
|
60
|
+
*
|
|
61
|
+
* Linux keeps `.credentials.json` under the value, so an empty value means
|
|
62
|
+
* `~/.claude` and the parent's directory is resolved. The value itself is not
|
|
63
|
+
* tilde-expanded, so the expansion happens here.
|
|
64
|
+
*/
|
|
65
|
+
export function spawnCredentialStore(platform) {
|
|
66
|
+
const parent = parentCredentialStore();
|
|
67
|
+
switch (platform) {
|
|
68
|
+
case "darwin":
|
|
69
|
+
return parent;
|
|
70
|
+
case "linux": {
|
|
71
|
+
const dir = parent === "" ? path.join(homedir(), ".claude") : expandTilde(parent);
|
|
72
|
+
return path.isAbsolute(dir) ? dir : path.resolve(dir);
|
|
73
|
+
}
|
|
74
|
+
default:
|
|
75
|
+
return parent;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
40
78
|
/**
|
|
41
79
|
* The launcher body: the credential rename first, then claude's config
|
|
42
80
|
* directory and the memory suppression a spawn needs (pi-cowboy renders
|
|
@@ -67,12 +105,17 @@ const STAGED_MARKER = "CLAUDE_STAGED";
|
|
|
67
105
|
* ends option parsing: `--tools` / `--disallowedTools` are variadic and would
|
|
68
106
|
* otherwise swallow the task as another tool name (and a task starting with
|
|
69
107
|
* `-` would parse as a flag), leaving the TUI idle with no initial prompt.
|
|
108
|
+
*
|
|
109
|
+
* `CLAUDE_SECURESTORAGE_CONFIG_DIR` is exported before `CLAUDE_CONFIG_DIR` so
|
|
110
|
+
* the credential store stays the parent's while the config dir is the staging
|
|
111
|
+
* dir. An empty value is written as `''`, which pins the default store.
|
|
70
112
|
*/
|
|
71
|
-
function launcherBody(configDir, taskFile) {
|
|
113
|
+
function launcherBody(configDir, taskFile, credentialStore) {
|
|
72
114
|
const settings = singleQuote(claudeSettingsFile(configDir));
|
|
73
115
|
const trimmed = singleQuote(`${claudeSettingsFile(configDir)}.tmp`);
|
|
74
116
|
return [
|
|
75
117
|
`if [ -n "\${ANTHROPIC_API_KEY:-}" ]; then export COWBOY_API_KEY="$ANTHROPIC_API_KEY"; unset ANTHROPIC_API_KEY; else grep -v '"apiKeyHelper"' ${settings} > ${trimmed} && mv ${trimmed} ${settings}; fi`,
|
|
118
|
+
`export CLAUDE_SECURESTORAGE_CONFIG_DIR=${singleQuote(credentialStore)}`,
|
|
76
119
|
`export CLAUDE_CONFIG_DIR=${singleQuote(configDir)}`,
|
|
77
120
|
"export CLAUDE_CODE_DISABLE_CLAUDE_MDS=1",
|
|
78
121
|
`command claude "$@" -- "$(cat ${singleQuote(taskFile)})"`,
|
|
@@ -154,8 +197,7 @@ const CLAUDE_MODELS = [
|
|
|
154
197
|
{ key: "anthropic/opus", label: "opus" },
|
|
155
198
|
];
|
|
156
199
|
export const claudeHarness = {
|
|
157
|
-
|
|
158
|
-
agentMuxKind: "claude",
|
|
200
|
+
agentMultiplexerKind: "claude",
|
|
159
201
|
availability: () => commandPath("claude") === undefined
|
|
160
202
|
? { status: "unavailable" }
|
|
161
203
|
: { status: "available" },
|
|
@@ -165,14 +207,14 @@ export const claudeHarness = {
|
|
|
165
207
|
* A launch reaches the CLI through this pane state alone, so it is verified
|
|
166
208
|
* here rather than assumed.
|
|
167
209
|
*/
|
|
168
|
-
async prepare({
|
|
210
|
+
async prepare({ pane, paneId, cwd, launch, }) {
|
|
169
211
|
const configDir = writeClaudeStaging({
|
|
170
212
|
subagentId: launch.subagentId,
|
|
171
213
|
cwd,
|
|
172
214
|
});
|
|
173
|
-
await installPaneLauncher(
|
|
215
|
+
await installPaneLauncher(pane, paneId, {
|
|
174
216
|
commandName: CLAUDE_COMMAND,
|
|
175
|
-
body: launcherBody(configDir, launch.taskFile),
|
|
217
|
+
body: launcherBody(configDir, launch.taskFile, spawnCredentialStore(process.platform)),
|
|
176
218
|
signature: LAUNCHER_SIGNATURE,
|
|
177
219
|
readyMarker: LAUNCHER_READY_MARKER,
|
|
178
220
|
proof: stagedProof(configDir, launch.taskFile),
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* claude/staging.ts — the config directory a spawn is pointed at: its path,
|
|
3
|
+
* its assembly, and its removal.
|
|
4
|
+
*
|
|
5
|
+
* claude launches with `CLAUDE_CONFIG_DIR` naming this directory, so every
|
|
6
|
+
* answers-everything dialog the interactive TUI would otherwise park at is
|
|
7
|
+
* decided here, before the pane exists: the theme picker (`theme`), the
|
|
8
|
+
* first-run bypass-permissions acceptance (`skipDangerousModePermissionPrompt`,
|
|
9
|
+
* the persisted half of `--dangerously-skip-permissions`), the onboarding
|
|
10
|
+
* marker (`hasCompletedOnboarding`), and the workspace trust for the spawn's
|
|
11
|
+
* own directory (`hasTrustDialogAccepted`). claude resolves the workspace to
|
|
12
|
+
* its real path before the trust lookup (`/tmp` reads as `/private/tmp`), so
|
|
13
|
+
* the seeded entry is keyed by the canonical path, and trust is inherited
|
|
14
|
+
* downward — one entry covers the spawn whatever its worktree is named.
|
|
15
|
+
* Nothing here launches anything or knows which pane the process will live in.
|
|
16
|
+
*
|
|
17
|
+
* What is deliberately absent is the custom-API-key approval
|
|
18
|
+
* (`customApiKeyResponses`): it names the tail of the `ANTHROPIC_API_KEY` in
|
|
19
|
+
* the launching environment, and the harness neither sets nor reads
|
|
20
|
+
* credentials — a spawn inherits whatever environment the parent session has.
|
|
21
|
+
* A session that authenticates through that variable therefore still meets the
|
|
22
|
+
* consent dialog once per spawn; OAuth/keychain sessions have no such dialog,
|
|
23
|
+
* because the launcher pins their credential store independently of the
|
|
24
|
+
* staged config directory.
|
|
25
|
+
*/
|
|
26
|
+
/**
|
|
27
|
+
* `<subagentResultDirFor(id)>/claude` — the config dir claude is pointed at.
|
|
28
|
+
*/
|
|
29
|
+
export declare function claudeConfigDir(subagentId: string): string;
|
|
30
|
+
/** The staged user settings file inside a config directory. */
|
|
31
|
+
export declare function claudeSettingsFile(configDir: string): string;
|
|
32
|
+
/**
|
|
33
|
+
* Write the whole staging tree and return the config dir. Nothing here is
|
|
34
|
+
* best-effort: every write throws, so a spawn that cannot stage its answers
|
|
35
|
+
* fails its launch instead of starting into the dialogs the staging exists
|
|
36
|
+
* to skip.
|
|
37
|
+
*/
|
|
38
|
+
export declare function writeClaudeStaging(input: {
|
|
39
|
+
subagentId: string;
|
|
40
|
+
cwd: string;
|
|
41
|
+
}): string;
|
|
42
|
+
/**
|
|
43
|
+
* Remove the staging tree. Best effort and idempotent — a no-op when its
|
|
44
|
+
* target is already gone (a launch that failed before prepare staged nothing).
|
|
45
|
+
*/
|
|
46
|
+
export declare function removeClaudeStaging(subagentId: string): void;
|
|
@@ -19,8 +19,9 @@
|
|
|
19
19
|
* the launching environment, and the harness neither sets nor reads
|
|
20
20
|
* credentials — a spawn inherits whatever environment the parent session has.
|
|
21
21
|
* A session that authenticates through that variable therefore still meets the
|
|
22
|
-
* consent dialog once per spawn; OAuth/keychain sessions have no such dialog
|
|
23
|
-
*
|
|
22
|
+
* consent dialog once per spawn; OAuth/keychain sessions have no such dialog,
|
|
23
|
+
* because the launcher pins their credential store independently of the
|
|
24
|
+
* staged config directory.
|
|
24
25
|
*/
|
|
25
26
|
import fs from "node:fs";
|
|
26
27
|
import * as path from "node:path";
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* harness/codex.ts — the codex harness: a binary of its own, launched as the
|
|
3
|
+
* interactive TUI behind the pane's `codex`.
|
|
4
|
+
*
|
|
5
|
+
* codex is not a pi-compatible binary, so nothing here can reuse the
|
|
6
|
+
* pi-compatible factory: it takes no system prompt on its argv (the prompt is
|
|
7
|
+
* read from the file `model_instructions_file` names), and its task arrives
|
|
8
|
+
* differently too. A multi-line task cannot ride the argv — herdr
|
|
9
|
+
* single-quotes every argument it passes and refuses multi-line ones outright —
|
|
10
|
+
* so the launcher appends it as the positional prompt the TUI starts its
|
|
11
|
+
* session with. The stdin form is unusable here: the TUI exits when stdin
|
|
12
|
+
* reaches EOF instead of reopening the terminal for input, so the task must
|
|
13
|
+
* not ride a redirect.
|
|
14
|
+
*
|
|
15
|
+
* The launch is the minimal *interactive* UI and is load-bearing: `codex exec`
|
|
16
|
+
* exits when its turn ends and never reads the terminal again, so a later
|
|
17
|
+
* steer would be typed into a pty nobody reads. Steering stays possible
|
|
18
|
+
* because the TUI keeps reading the pane.
|
|
19
|
+
*
|
|
20
|
+
* `prepare` installs that launcher into the pane and nothing else: every
|
|
21
|
+
* switch the launch needs rides the argv as a flag, so there is no staged
|
|
22
|
+
* directory to prove live and nothing to remove in `teardown`. `prepare`
|
|
23
|
+
* proves no system-prompt state either — a missing or empty instructions file
|
|
24
|
+
* is a loud `codex` hard error at boot, not a silent fallback, so there is no
|
|
25
|
+
* quiet mislaunch to catch early.
|
|
26
|
+
*
|
|
27
|
+
* `listModels` shells `codex debug models --bundled` through `pi.exec`
|
|
28
|
+
* (children inherit the session environment, as every other child here does)
|
|
29
|
+
* and parses the output defensively. The real format — verified against the
|
|
30
|
+
* installed CLI by test/codex-harness.integration.test.ts — is a JSON object
|
|
31
|
+
* with a `models` array of `{ slug, visibility, display_name }` entries. Only
|
|
32
|
+
* `visibility: "list"` entries are offered; any other shape resolves to an
|
|
33
|
+
* empty list with a warning rather than an exception, because a settings menu
|
|
34
|
+
* must never fail to open when a list command misbehaves. The integration
|
|
35
|
+
* test is what keeps the verified shape true as codex changes.
|
|
36
|
+
*
|
|
37
|
+
* The strict `[harness.codex]` table carries `model` alone: codex has no tools
|
|
38
|
+
* flag, so there is no tool pair to stage, and the shared `toolSelection` a
|
|
39
|
+
* codex launch receives is left unread.
|
|
40
|
+
*/
|
|
41
|
+
import type { CodexLaunchRequest, Harness } from "../harness.js";
|
|
42
|
+
export declare const codexHarness: Harness<CodexLaunchRequest>;
|
|
@@ -189,8 +189,7 @@ function fetchModels(pi) {
|
|
|
189
189
|
return fetch;
|
|
190
190
|
}
|
|
191
191
|
export const codexHarness = {
|
|
192
|
-
|
|
193
|
-
agentMuxKind: "codex",
|
|
192
|
+
agentMultiplexerKind: "codex",
|
|
194
193
|
availability: () => commandPath("codex") === undefined
|
|
195
194
|
? { status: "unavailable" }
|
|
196
195
|
: { status: "available" },
|
|
@@ -199,8 +198,8 @@ export const codexHarness = {
|
|
|
199
198
|
* prompt. The launcher is the whole of the pane state this harness needs,
|
|
200
199
|
* so its verification is the whole of the preparation.
|
|
201
200
|
*/
|
|
202
|
-
async prepare({
|
|
203
|
-
await installPaneLauncher(
|
|
201
|
+
async prepare({ pane, paneId, launch, }) {
|
|
202
|
+
await installPaneLauncher(pane, paneId, {
|
|
204
203
|
commandName: CODEX_COMMAND,
|
|
205
204
|
body: launcherBody(launch.taskFile),
|
|
206
205
|
signature: LAUNCHER_SIGNATURE,
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* harness-registry.ts — the one module that knows every harness.
|
|
3
|
+
*
|
|
4
|
+
* `createHarnessRegistry()` builds the id → implementation lookup a session
|
|
5
|
+
* uses. Its built-ins are seeded at construction, and a plugin harness is added
|
|
6
|
+
* by `register` at session start; both become the same `RegisteredHarness`, so
|
|
7
|
+
* no caller can tell a built-in from a plugin by how it arrived. Because the map
|
|
8
|
+
* is a closure of the object, its lifetime is the object's: a session installs a
|
|
9
|
+
* fresh registry, and the previous session's plugin entries cannot outlive it.
|
|
10
|
+
*
|
|
11
|
+
* Registration is id-keyed and first-wins — the first registration for an id is
|
|
12
|
+
* kept and a later one is refused with a warning — so a plugin can never
|
|
13
|
+
* displace a built-in, and two plugins claiming one id do not race: the plugin
|
|
14
|
+
* loader sorts by package name, so the same one wins every load.
|
|
15
|
+
*
|
|
16
|
+
* A built-in keeps its per-family typing behind the wall
|
|
17
|
+
* (`Harness<LaunchRequestFor<K>>`); the wall narrows a launch to the built-in's
|
|
18
|
+
* own request by its `family` tag, which the caller built from the same id (see
|
|
19
|
+
* agent-runner.buildLaunchRequest). A plugin is the same `Harness` contract
|
|
20
|
+
* over the shared inputs, so it is stored as it registered. Everything above
|
|
21
|
+
* the wall holds a `RegisteredHarness` and never branches on origin.
|
|
22
|
+
*/
|
|
23
|
+
import { type Availability } from "../../availability.js";
|
|
24
|
+
import { type AnyHarnessId, type Harness, type HarnessConfigIssue, type HarnessFamily, type HarnessLaunch, type HarnessListModelsRequest, type PluginHarness } from "../harness.js";
|
|
25
|
+
/**
|
|
26
|
+
* Everything one launch needs that a harness can be handed without knowing its
|
|
27
|
+
* origin: the one contract every implementation presents, plus the identity the
|
|
28
|
+
* registry keys it by. A caller holds this, never the underlying `Harness` or
|
|
29
|
+
* `PluginHarness`.
|
|
30
|
+
*/
|
|
31
|
+
export interface RegisteredHarness extends Harness<HarnessLaunch> {
|
|
32
|
+
readonly id: AnyHarnessId;
|
|
33
|
+
readonly displayName: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* One session's harness vocabulary: the built-ins plus whatever that session's
|
|
37
|
+
* plugins registered.
|
|
38
|
+
*/
|
|
39
|
+
export interface HarnessRegistry {
|
|
40
|
+
/**
|
|
41
|
+
* Register a plugin harness, answering whether it was accepted. The first
|
|
42
|
+
* registration for an id is kept: a plugin that claims a built-in's id, or an
|
|
43
|
+
* id another plugin already claimed in this session, is refused with a warning
|
|
44
|
+
* and answered `false`.
|
|
45
|
+
*/
|
|
46
|
+
register(harness: PluginHarness): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Forget one plugin harness — the undo a plugin's own load needs when its
|
|
49
|
+
* factory throws after registering. A built-in id is never removed, and
|
|
50
|
+
* neither is an id this registry did not register.
|
|
51
|
+
*/
|
|
52
|
+
unregister(id: AnyHarnessId): void;
|
|
53
|
+
/** Every registered id, built-in ids first then plugins in registration order. */
|
|
54
|
+
ids(): readonly AnyHarnessId[];
|
|
55
|
+
/** The harness for one id, or undefined for an id nothing registered. */
|
|
56
|
+
get(id: AnyHarnessId): RegisteredHarness | undefined;
|
|
57
|
+
/**
|
|
58
|
+
* Validate every registered harness's configuration section against the
|
|
59
|
+
* session's raw layers, recording the value its launch reads. A codec that
|
|
60
|
+
* declares no project scope receives no project slice; one that throws takes
|
|
61
|
+
* its harness out of the session's vocabulary instead of ending startup.
|
|
62
|
+
*/
|
|
63
|
+
validateConfigs(layers: {
|
|
64
|
+
readonly global: Readonly<Record<string, Readonly<Record<string, unknown>>>>;
|
|
65
|
+
readonly project: Readonly<Record<string, Readonly<Record<string, unknown>>>>;
|
|
66
|
+
}, report: (id: AnyHarnessId, issue: HarnessConfigIssue) => void): void;
|
|
67
|
+
/**
|
|
68
|
+
* The harness for one id. A caller that reaches here has already narrowed the
|
|
69
|
+
* id to a registered one (config resolve, request refusal), so an unregistered
|
|
70
|
+
* id is a bug to name, not a state to branch on.
|
|
71
|
+
*/
|
|
72
|
+
require(id: AnyHarnessId): RegisteredHarness;
|
|
73
|
+
/** The display form of one harness; an unregistered id shows as itself. */
|
|
74
|
+
displayName(id: AnyHarnessId): string;
|
|
75
|
+
/**
|
|
76
|
+
* The harnesses a spawn here can really use: built-in ids first (in
|
|
77
|
+
* `HARNESS_IDS` order), then plugin ids (in registration order). pi runs the
|
|
78
|
+
* pane it would launch in, so the family answers always; any other harness —
|
|
79
|
+
* built-in or plugin — needs the probe to have confirmed it.
|
|
80
|
+
*/
|
|
81
|
+
runnable(availability: Availability<AnyHarnessId>): AnyHarnessId[];
|
|
82
|
+
/** The value this harness's codec validated, or undefined when it has none. */
|
|
83
|
+
config(id: AnyHarnessId): unknown;
|
|
84
|
+
/**
|
|
85
|
+
* Which harness a spawn launches under: the configured one when it is both
|
|
86
|
+
* registered and launchable here, pi otherwise. Registration is checked as
|
|
87
|
+
* well as availability because config may name a plugin harness that is not
|
|
88
|
+
* installed, and while the probe is `unprobed` every id reads as "available" —
|
|
89
|
+
* so availability alone would hand a spawn an id that `require` then refuses.
|
|
90
|
+
*/
|
|
91
|
+
resolve(configured: AnyHarnessId, availability: Availability<AnyHarnessId>): AnyHarnessId;
|
|
92
|
+
/**
|
|
93
|
+
* One model list per runnable harness, each answering for itself, read once
|
|
94
|
+
* when a menu tree opens so every picker under it selects from the same
|
|
95
|
+
* answer. A harness whose list could not be produced is present with an empty
|
|
96
|
+
* list: "no models" belongs to that harness alone.
|
|
97
|
+
*/
|
|
98
|
+
listModelOptions(request: HarnessListModelsRequest, availability: Availability<AnyHarnessId>): Promise<HarnessModelOptions>;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* The harness vocabulary one session runs with. The built-in entries are built
|
|
102
|
+
* here, so each registry owns its own wrappers — a stale registry cannot answer
|
|
103
|
+
* with an entry another session replaced.
|
|
104
|
+
*/
|
|
105
|
+
export declare function createHarnessRegistry(): HarnessRegistry;
|
|
106
|
+
/**
|
|
107
|
+
* The family whose template table this harness's launch reads: the built-in
|
|
108
|
+
* family the id maps to, or undefined when the id is a plugin harness's own.
|
|
109
|
+
* A plugin's family is its id, which keys no template table, so the caller
|
|
110
|
+
* reads no slice rather than another family's.
|
|
111
|
+
*/
|
|
112
|
+
export declare function harnessFamilyOf(id: AnyHarnessId): HarnessFamily | undefined;
|
|
113
|
+
/**
|
|
114
|
+
* The model keys each harness this machine can run offers, keyed by harness.
|
|
115
|
+
* A harness whose list could not be produced is present with an empty list:
|
|
116
|
+
* "no models" belongs to that harness alone and is never filled in from
|
|
117
|
+
* another's.
|
|
118
|
+
*/
|
|
119
|
+
export type HarnessModelOptions = ReadonlyMap<AnyHarnessId, readonly string[]>;
|
|
120
|
+
/**
|
|
121
|
+
* The one merged view of the per-harness structure: every harness's keys, once
|
|
122
|
+
* each, in registration order. Only the concurrency menu asks for it — its
|
|
123
|
+
* slots are keyed by model key across harnesses, so it must offer every key a
|
|
124
|
+
* spawn could carry.
|
|
125
|
+
*/
|
|
126
|
+
export declare function mergeHarnessModelOptions(options: HarnessModelOptions): string[];
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* harness-registry.ts — the one module that knows every harness.
|
|
3
|
+
*
|
|
4
|
+
* `createHarnessRegistry()` builds the id → implementation lookup a session
|
|
5
|
+
* uses. Its built-ins are seeded at construction, and a plugin harness is added
|
|
6
|
+
* by `register` at session start; both become the same `RegisteredHarness`, so
|
|
7
|
+
* no caller can tell a built-in from a plugin by how it arrived. Because the map
|
|
8
|
+
* is a closure of the object, its lifetime is the object's: a session installs a
|
|
9
|
+
* fresh registry, and the previous session's plugin entries cannot outlive it.
|
|
10
|
+
*
|
|
11
|
+
* Registration is id-keyed and first-wins — the first registration for an id is
|
|
12
|
+
* kept and a later one is refused with a warning — so a plugin can never
|
|
13
|
+
* displace a built-in, and two plugins claiming one id do not race: the plugin
|
|
14
|
+
* loader sorts by package name, so the same one wins every load.
|
|
15
|
+
*
|
|
16
|
+
* A built-in keeps its per-family typing behind the wall
|
|
17
|
+
* (`Harness<LaunchRequestFor<K>>`); the wall narrows a launch to the built-in's
|
|
18
|
+
* own request by its `family` tag, which the caller built from the same id (see
|
|
19
|
+
* agent-runner.buildLaunchRequest). A plugin is the same `Harness` contract
|
|
20
|
+
* over the shared inputs, so it is stored as it registered. Everything above
|
|
21
|
+
* the wall holds a `RegisteredHarness` and never branches on origin.
|
|
22
|
+
*/
|
|
23
|
+
import { assertNever, errorMessage } from "../../utils.js";
|
|
24
|
+
import { isAvailable, isProven, } from "../../availability.js";
|
|
25
|
+
import { DEFAULT_HARNESS, HARNESS_IDS, isPiFamilyHarness, parseHarnessId, } from "../harness.js";
|
|
26
|
+
import { buildPiLaunchArgs, piFamilyListModels } from "./pi-compatible.js";
|
|
27
|
+
import { pigHarness } from "./pig.js";
|
|
28
|
+
import { piBoltHarness } from "./pi-bolt.js";
|
|
29
|
+
import { opencodeHarness } from "./opencode/index.js";
|
|
30
|
+
import { codexHarness } from "./codex.js";
|
|
31
|
+
import { claudeHarness } from "./claude/index.js";
|
|
32
|
+
/**
|
|
33
|
+
* Real pi is already the pane shell's `pi`: it is always launchable, and there
|
|
34
|
+
* is nothing to prepare or tear down. Its argv is the family's shared
|
|
35
|
+
* assembly — pi is the family's namesake — and its model list is the family's
|
|
36
|
+
* shared catalog.
|
|
37
|
+
*/
|
|
38
|
+
const piHarness = {
|
|
39
|
+
agentMultiplexerKind: "pi",
|
|
40
|
+
availability: () => ({ status: "available" }),
|
|
41
|
+
prepare: async () => { },
|
|
42
|
+
buildArgs: buildPiLaunchArgs,
|
|
43
|
+
listModels: piFamilyListModels,
|
|
44
|
+
// The catalog is local: nothing to warm.
|
|
45
|
+
prefetchModels: () => { },
|
|
46
|
+
teardown: async () => { },
|
|
47
|
+
};
|
|
48
|
+
/** Keyed by id, so a harness added to `HARNESS_IDS` without an implementation fails to compile. */
|
|
49
|
+
const BUILTIN_HARNESSES = {
|
|
50
|
+
pi: piHarness,
|
|
51
|
+
pig: pigHarness,
|
|
52
|
+
"pi-bolt": piBoltHarness,
|
|
53
|
+
opencode: opencodeHarness,
|
|
54
|
+
codex: codexHarness,
|
|
55
|
+
claude: claudeHarness,
|
|
56
|
+
};
|
|
57
|
+
/** How a built-in's own settings row is labeled. */
|
|
58
|
+
const BUILTIN_DISPLAY_NAMES = {
|
|
59
|
+
pi: "Pi",
|
|
60
|
+
pig: "PiG",
|
|
61
|
+
"pi-bolt": "Pi-Bolt",
|
|
62
|
+
opencode: "OpenCode",
|
|
63
|
+
codex: "Codex",
|
|
64
|
+
claude: "Claude",
|
|
65
|
+
};
|
|
66
|
+
/** The catalogue a built-in's model keys belong to; keyed, so a new id without a family fails to compile. */
|
|
67
|
+
const BUILTIN_FAMILIES = {
|
|
68
|
+
pi: "pi",
|
|
69
|
+
pig: "pi",
|
|
70
|
+
"pi-bolt": "pi",
|
|
71
|
+
opencode: "opencode",
|
|
72
|
+
codex: "codex",
|
|
73
|
+
claude: "claude",
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Dispatch a built-in launch to the built-in the plan selected, with the request
|
|
77
|
+
* narrowed to that harness's own family request. The switch is exhaustive over
|
|
78
|
+
* `HarnessId`, and each arm pairs the harness with the narrowing that belongs to
|
|
79
|
+
* it — the guarantee the uniform `RegisteredHarness` would otherwise erase, so a
|
|
80
|
+
* pi-family implementation can never be handed an opencode request (which would
|
|
81
|
+
* compile, with its missing fields silently `undefined`).
|
|
82
|
+
*
|
|
83
|
+
* The dispatch is per *id*, not per family: the pi family shares one launch
|
|
84
|
+
* request but its three harnesses prepare differently, so the family alone does
|
|
85
|
+
* not name the implementation.
|
|
86
|
+
*/
|
|
87
|
+
function withBuiltin(id, launch, run) {
|
|
88
|
+
switch (id) {
|
|
89
|
+
case "pi":
|
|
90
|
+
return run(BUILTIN_HARNESSES.pi, familyRequest(launch, "pi"));
|
|
91
|
+
case "pig":
|
|
92
|
+
return run(BUILTIN_HARNESSES.pig, familyRequest(launch, "pi"));
|
|
93
|
+
case "pi-bolt":
|
|
94
|
+
return run(BUILTIN_HARNESSES["pi-bolt"], familyRequest(launch, "pi"));
|
|
95
|
+
case "opencode":
|
|
96
|
+
return run(BUILTIN_HARNESSES.opencode, familyRequest(launch, "opencode"));
|
|
97
|
+
case "codex":
|
|
98
|
+
return run(BUILTIN_HARNESSES.codex, familyRequest(launch, "codex"));
|
|
99
|
+
case "claude":
|
|
100
|
+
return run(BUILTIN_HARNESSES.claude, familyRequest(launch, "claude"));
|
|
101
|
+
default:
|
|
102
|
+
return assertNever(id);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* The launch narrowed to one built-in family's request. The guard is the point:
|
|
107
|
+
* the pair is built at one site (agent-runner.buildLaunchRequest), so a mismatch
|
|
108
|
+
* is a bug there, and naming it here is what lets each built-in stay typed to
|
|
109
|
+
* its own request instead of the erased union. The plugin arm's `"plugin"` tag
|
|
110
|
+
* can never equal a built-in family, so this one check covers both arms — one
|
|
111
|
+
* guarded cast, not a blanket one.
|
|
112
|
+
*/
|
|
113
|
+
function familyRequest(launch, family) {
|
|
114
|
+
if (launch.family !== family) {
|
|
115
|
+
throw new Error(`a "${launch.family}" launch reached the "${family}" harness`);
|
|
116
|
+
}
|
|
117
|
+
return launch;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Adapter for a built-in: its implementation is typed to its own family's
|
|
121
|
+
* request, so the uniform registry entry narrows by id. A plugin needs no
|
|
122
|
+
* adapter — it is the same contract over the shared inputs.
|
|
123
|
+
*/
|
|
124
|
+
function wrapBuiltin(id) {
|
|
125
|
+
const harness = BUILTIN_HARNESSES[id];
|
|
126
|
+
return {
|
|
127
|
+
id,
|
|
128
|
+
displayName: BUILTIN_DISPLAY_NAMES[id],
|
|
129
|
+
// The codec is what `validateConfigs` reads for a built-in too, so the
|
|
130
|
+
// uniform entry carries it.
|
|
131
|
+
config: harness.config,
|
|
132
|
+
agentMultiplexerKind: harness.agentMultiplexerKind,
|
|
133
|
+
availability: () => harness.availability(),
|
|
134
|
+
prepare: (request) => withBuiltin(id, request.launch, (typed, launch) => typed.prepare({
|
|
135
|
+
pi: request.pi,
|
|
136
|
+
pane: request.pane,
|
|
137
|
+
paneId: request.paneId,
|
|
138
|
+
cwd: request.cwd,
|
|
139
|
+
launch,
|
|
140
|
+
config: request.config,
|
|
141
|
+
})),
|
|
142
|
+
buildArgs: (launch) => withBuiltin(id, launch, (typed, request) => typed.buildArgs(request)),
|
|
143
|
+
teardown: (request) => harness.teardown(request),
|
|
144
|
+
listModels: (request) => harness.listModels(request),
|
|
145
|
+
prefetchModels: (pi) => harness.prefetchModels(pi),
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* The harness vocabulary one session runs with. The built-in entries are built
|
|
150
|
+
* here, so each registry owns its own wrappers — a stale registry cannot answer
|
|
151
|
+
* with an entry another session replaced.
|
|
152
|
+
*/
|
|
153
|
+
export function createHarnessRegistry() {
|
|
154
|
+
const registered = new Map(HARNESS_IDS.map((id) => [id, wrapBuiltin(id)]));
|
|
155
|
+
/** The ids this registry's plugins own, so `unregister` cannot remove another's. */
|
|
156
|
+
const owned = new Set();
|
|
157
|
+
/** Each harness's validated configuration, stored beside the entry. */
|
|
158
|
+
const configs = new Map();
|
|
159
|
+
const registry = {
|
|
160
|
+
register(harness) {
|
|
161
|
+
const refusal = parseHarnessId(harness.id) !== undefined
|
|
162
|
+
? "a built-in harness owns that id"
|
|
163
|
+
: registered.has(harness.id)
|
|
164
|
+
? "another plugin already registered that id in this load"
|
|
165
|
+
: undefined;
|
|
166
|
+
if (refusal !== undefined) {
|
|
167
|
+
console.warn(`[subagents] Ignoring harness "${harness.id}": ${refusal}`);
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
170
|
+
registered.set(harness.id, harness);
|
|
171
|
+
owned.add(harness.id);
|
|
172
|
+
return true;
|
|
173
|
+
},
|
|
174
|
+
unregister(id) {
|
|
175
|
+
if (!owned.has(id))
|
|
176
|
+
return;
|
|
177
|
+
registered.delete(id);
|
|
178
|
+
owned.delete(id);
|
|
179
|
+
configs.delete(id);
|
|
180
|
+
},
|
|
181
|
+
ids() {
|
|
182
|
+
return [...registered.keys()];
|
|
183
|
+
},
|
|
184
|
+
get(id) {
|
|
185
|
+
return registered.get(id);
|
|
186
|
+
},
|
|
187
|
+
validateConfigs(layers, report) {
|
|
188
|
+
for (const [id, harness] of registered) {
|
|
189
|
+
const codec = harness.config;
|
|
190
|
+
if (codec === undefined)
|
|
191
|
+
continue;
|
|
192
|
+
const project = codec.scope === "project" ? layers.project[id] : undefined;
|
|
193
|
+
try {
|
|
194
|
+
configs.set(id, codec.parse({ global: layers.global[id], project }, (issue) => report(id, issue)));
|
|
195
|
+
}
|
|
196
|
+
catch (error) {
|
|
197
|
+
// `parse` is plugin code. A harness whose codec cannot answer would
|
|
198
|
+
// hand `prepare` no config at all, so it leaves the session's
|
|
199
|
+
// vocabulary instead of ending session startup.
|
|
200
|
+
registered.delete(id);
|
|
201
|
+
owned.delete(id);
|
|
202
|
+
configs.delete(id);
|
|
203
|
+
console.warn(`[subagents] Disabling harness "${id}": its configuration codec failed to parse it (${errorMessage(error)}).`);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
},
|
|
207
|
+
require(id) {
|
|
208
|
+
const harness = registered.get(id);
|
|
209
|
+
if (harness === undefined) {
|
|
210
|
+
throw new Error(`no harness registered for "${id}"`);
|
|
211
|
+
}
|
|
212
|
+
return harness;
|
|
213
|
+
},
|
|
214
|
+
displayName(id) {
|
|
215
|
+
return registered.get(id)?.displayName ?? id;
|
|
216
|
+
},
|
|
217
|
+
runnable(availability) {
|
|
218
|
+
return registry
|
|
219
|
+
.ids()
|
|
220
|
+
.filter((id) => isPiFamilyHarness(id) || isProven(id, availability));
|
|
221
|
+
},
|
|
222
|
+
config(id) {
|
|
223
|
+
return configs.get(id);
|
|
224
|
+
},
|
|
225
|
+
resolve(configured, availability) {
|
|
226
|
+
return registered.has(configured) && isAvailable(configured, availability)
|
|
227
|
+
? configured
|
|
228
|
+
: DEFAULT_HARNESS;
|
|
229
|
+
},
|
|
230
|
+
async listModelOptions(request, availability) {
|
|
231
|
+
const entries = await Promise.all(registry
|
|
232
|
+
.runnable(availability)
|
|
233
|
+
.map(async (id) => {
|
|
234
|
+
try {
|
|
235
|
+
const models = await registry.require(id).listModels(request);
|
|
236
|
+
return [id, models.map((entry) => entry.key)];
|
|
237
|
+
}
|
|
238
|
+
catch {
|
|
239
|
+
// `listModels` is not supposed to throw; one that does costs its
|
|
240
|
+
// own list, never the others'.
|
|
241
|
+
return [id, []];
|
|
242
|
+
}
|
|
243
|
+
}));
|
|
244
|
+
return new Map(entries);
|
|
245
|
+
},
|
|
246
|
+
};
|
|
247
|
+
return registry;
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* The family whose template table this harness's launch reads: the built-in
|
|
251
|
+
* family the id maps to, or undefined when the id is a plugin harness's own.
|
|
252
|
+
* A plugin's family is its id, which keys no template table, so the caller
|
|
253
|
+
* reads no slice rather than another family's.
|
|
254
|
+
*/
|
|
255
|
+
export function harnessFamilyOf(id) {
|
|
256
|
+
const builtin = parseHarnessId(id);
|
|
257
|
+
return builtin === undefined ? undefined : BUILTIN_FAMILIES[builtin];
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* The one merged view of the per-harness structure: every harness's keys, once
|
|
261
|
+
* each, in registration order. Only the concurrency menu asks for it — its
|
|
262
|
+
* slots are keyed by model key across harnesses, so it must offer every key a
|
|
263
|
+
* spawn could carry.
|
|
264
|
+
*/
|
|
265
|
+
export function mergeHarnessModelOptions(options) {
|
|
266
|
+
const keys = new Set();
|
|
267
|
+
for (const list of options.values()) {
|
|
268
|
+
for (const key of list)
|
|
269
|
+
keys.add(key);
|
|
270
|
+
}
|
|
271
|
+
return [...keys];
|
|
272
|
+
}
|