pi-cowboy 0.9.0 → 0.10.0
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/agents/agent-template.js +3 -3
- package/dist/agents/harness/claude/index.js +3 -1
- package/dist/agents/harness/codex.js +3 -1
- package/dist/agents/harness/opencode/definition.js +7 -9
- package/dist/agents/harness/opencode/index.js +99 -35
- package/dist/agents/harness/opencode/permissions.js +25 -25
- package/dist/agents/harness/opencode/staging.js +2 -7
- package/dist/agents/harness/opencode/version.js +43 -0
- package/dist/agents/harness/pane-launcher.js +2 -2
- package/dist/agents/harness/pi-compatible.js +3 -1
- package/dist/agents/harness/registry.js +1 -1
- package/dist/cow-support-launch.js +7 -7
- package/dist/events.js +5 -0
- package/dist/harness-availability-launch.js +42 -10
- package/dist/index.js +5 -5
- package/dist/infrastructure/exec-sync.js +30 -0
- package/dist/ui/menu/menu-agent-settings.js +3 -2
- package/package.json +2 -2
- package/dist/agents/harness/opencode/npm-seed.js +0 -74
|
@@ -46,11 +46,11 @@ const PiHarnessSchema = z.strictObject(PI_HARNESS_SHAPE);
|
|
|
46
46
|
const OpencodeHarnessSchema = z.strictObject({
|
|
47
47
|
/** A model key in opencode's catalogue, as "provider/model-id". */
|
|
48
48
|
model: z.string().optional(),
|
|
49
|
-
/** The reasoning-effort variant
|
|
49
|
+
/** The reasoning-effort variant, joined to this agent's model as "provider/model#variant". */
|
|
50
50
|
variant: z.string().optional(),
|
|
51
|
-
/** Tools available to an opencode launch, as opencode's permission
|
|
51
|
+
/** Tools available to an opencode launch, as opencode's permission actions. */
|
|
52
52
|
tools: z.array(z.string()).optional(),
|
|
53
|
-
/** Tools withheld from an opencode launch, as opencode's permission
|
|
53
|
+
/** Tools withheld from an opencode launch, as opencode's permission actions. */
|
|
54
54
|
exclude_tools: z.array(z.string()).optional(),
|
|
55
55
|
});
|
|
56
56
|
/**
|
|
@@ -156,7 +156,9 @@ const CLAUDE_MODELS = [
|
|
|
156
156
|
export const claudeHarness = {
|
|
157
157
|
id: "claude",
|
|
158
158
|
agentMuxKind: "claude",
|
|
159
|
-
|
|
159
|
+
availability: () => commandPath("claude") === undefined
|
|
160
|
+
? { status: "unavailable" }
|
|
161
|
+
: { status: "available" },
|
|
160
162
|
/**
|
|
161
163
|
* Stage the config directory, install the launcher that points claude at it
|
|
162
164
|
* and appends the task, and prove the pane sees the staged state behind it.
|
|
@@ -191,7 +191,9 @@ function fetchModels(pi) {
|
|
|
191
191
|
export const codexHarness = {
|
|
192
192
|
id: "codex",
|
|
193
193
|
agentMuxKind: "codex",
|
|
194
|
-
|
|
194
|
+
availability: () => commandPath("codex") === undefined
|
|
195
|
+
? { status: "unavailable" }
|
|
196
|
+
: { status: "available" },
|
|
195
197
|
/**
|
|
196
198
|
* Install the launcher that appends the task as the TUI's positional
|
|
197
199
|
* prompt. The launcher is the whole of the pane state this harness needs,
|
|
@@ -23,21 +23,19 @@ const AGENT_FILE_SUFFIX = ".md";
|
|
|
23
23
|
/**
|
|
24
24
|
* The frontmatter opencode reads, in the order it is written.
|
|
25
25
|
*
|
|
26
|
-
* `mode: primary` is load-bearing: opencode
|
|
27
|
-
*
|
|
28
|
-
* `description` carries the spawn identity, which stays visible
|
|
29
|
-
*
|
|
26
|
+
* `mode: primary` is load-bearing: opencode drops back to its own default agent
|
|
27
|
+
* — no prompt at all, no rules — for a name that is not a primary agent.
|
|
28
|
+
* `description` carries the spawn identity, which stays visible wherever
|
|
29
|
+
* definitions are listed.
|
|
30
30
|
*
|
|
31
|
-
* `lineWidth: 0` writes each
|
|
32
|
-
* is
|
|
33
|
-
* emitted style depend on how long it happens to be.
|
|
31
|
+
* `lineWidth: 0` writes each rule on one line whatever a template's action name
|
|
32
|
+
* is, so the name's length cannot decide how the emitter splits a rule.
|
|
34
33
|
*/
|
|
35
34
|
function frontmatter(input) {
|
|
36
35
|
return stringify({
|
|
37
36
|
description: subagentTokenFor(input.subagentId),
|
|
38
37
|
mode: "primary",
|
|
39
|
-
|
|
40
|
-
...(input.variant === null ? {} : { variant: input.variant }),
|
|
38
|
+
permissions: opencodePermissions(input.toolSelection),
|
|
41
39
|
}, { lineWidth: 0 });
|
|
42
40
|
}
|
|
43
41
|
/** The agent definition: YAML frontmatter between its delimiters, then the prompt. */
|
|
@@ -24,31 +24,42 @@
|
|
|
24
24
|
* settings menu must never fail to open when a list command misbehaves. The
|
|
25
25
|
* integration test is what keeps the verified shape true as opencode changes.
|
|
26
26
|
*
|
|
27
|
-
* The strict `[harness.opencode]` table carries `variant`, which
|
|
28
|
-
*
|
|
29
|
-
*
|
|
27
|
+
* The strict `[harness.opencode]` table carries `variant`, which joins the model
|
|
28
|
+
* reference on the argv: a variant has no flag of its own, so `buildArgs`
|
|
29
|
+
* appends it to the model key as `provider/model#variant`.
|
|
30
30
|
*/
|
|
31
|
-
import { commandPath } from "../../../infrastructure/exec-path.js";
|
|
32
31
|
import { parseModelKey } from "../../../utils.js";
|
|
33
|
-
import { installPaneLauncher, singleQuoteShellWord, } from "../pane-launcher.js";
|
|
32
|
+
import { installPaneLauncher, singleQuoteShellWord, splitMarker, } from "../pane-launcher.js";
|
|
34
33
|
import { removeOpencodeStaging, writeOpencodeStaging } from "./staging.js";
|
|
34
|
+
import { probeOpencode } from "./version.js";
|
|
35
35
|
/** Budget for the list command; a hung CLI must not hold a menu open. */
|
|
36
36
|
const LIST_MODELS_TIMEOUT_MS = 10_000;
|
|
37
37
|
/**
|
|
38
|
-
* Budget for the pane's
|
|
39
|
-
* is slower than a shell builtin but answers in
|
|
38
|
+
* Budget for the pane's definition proof. The probe boots the CLI and a private
|
|
39
|
+
* server, so it is slower than a shell builtin but answers in a few seconds.
|
|
40
40
|
*/
|
|
41
|
-
const
|
|
41
|
+
const DEFINITION_PROOF_TIMEOUT_MS = 30_000;
|
|
42
42
|
/** The command herdr types into the pane; the launcher is installed under it. */
|
|
43
43
|
const OPENCODE_COMMAND = "opencode";
|
|
44
44
|
/** Signature carried by this launcher, so pane verification proves which launcher landed. */
|
|
45
45
|
const LAUNCHER_SIGNATURE = "OPENCODE_LAUNCHER_7d3e91";
|
|
46
46
|
/** Token the verify command echoes once the launcher body is confirmed. */
|
|
47
47
|
const LAUNCHER_READY_MARKER = "OPENCODE_VERIFIED";
|
|
48
|
+
/** Token the definition proof echoes once the staged definition is confirmed. */
|
|
49
|
+
const DEFINITION_READY_MARKER = "OPENCODE_DEFINITION_VERIFIED";
|
|
48
50
|
/**
|
|
49
|
-
* The
|
|
50
|
-
*
|
|
51
|
-
|
|
51
|
+
* The model the definition proof asks for: a key no catalogue can resolve, so
|
|
52
|
+
* the probe is answered by the model rather than by a request.
|
|
53
|
+
*/
|
|
54
|
+
const PROOF_MODEL = "pi-cowboy/opencode-definition-proof";
|
|
55
|
+
/** The message the proof submits; it is never sent, because the model is not. */
|
|
56
|
+
const PROOF_MESSAGE = "definition probe";
|
|
57
|
+
/** What opencode reports when it resolved the agent but not the model. */
|
|
58
|
+
const MODEL_FAILURE = "Model unavailable";
|
|
59
|
+
/**
|
|
60
|
+
* The launcher body: opencode's config directory and the switch that keeps a
|
|
61
|
+
* spawn from reading anyone else's configuration, then the real binary with the
|
|
62
|
+
* pane's own arguments and the task on stdin.
|
|
52
63
|
*
|
|
53
64
|
* Bare `opencode` keeps the pane's `PATH` the authority on which binary runs,
|
|
54
65
|
* and `command` bypasses this very function. The redirect is what delivers a
|
|
@@ -60,7 +71,6 @@ function launcherBody(configDir, taskFile) {
|
|
|
60
71
|
return [
|
|
61
72
|
`export OPENCODE_CONFIG_DIR=${singleQuoteShellWord(configDir)}`,
|
|
62
73
|
"export OPENCODE_DISABLE_PROJECT_CONFIG=1",
|
|
63
|
-
"export OPENCODE_DISABLE_CLAUDE_CODE_PROMPT=1",
|
|
64
74
|
`command opencode "$@" < ${singleQuoteShellWord(taskFile)}`,
|
|
65
75
|
].join("; ");
|
|
66
76
|
}
|
|
@@ -68,25 +78,44 @@ function launcherBody(configDir, taskFile) {
|
|
|
68
78
|
* The proof that the staged definition is live, read back through the launcher
|
|
69
79
|
* the pane just took.
|
|
70
80
|
*
|
|
71
|
-
* opencode
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
* launch's argv or exit status
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
81
|
+
* opencode runs its own default agent — no system prompt, no permission rules —
|
|
82
|
+
* when the named agent is missing or is not a primary agent, and mini reports
|
|
83
|
+
* that by drawing the requested name over the default agent rather than by
|
|
84
|
+
* failing: nothing in the launch's argv or exit status says one happened. The
|
|
85
|
+
* proof asks a private server to resolve the agent, which is the only place the
|
|
86
|
+
* answer can be read. `--standalone` is load-bearing here: without it the CLI
|
|
87
|
+
* answers from the shared background server, which was started with another
|
|
88
|
+
* config directory and does not hold this definition at all.
|
|
89
|
+
*
|
|
90
|
+
* The probe names a model no catalogue can resolve, so a definition opencode
|
|
91
|
+
* read is reported by the model's failure and one it did not read is reported by
|
|
92
|
+
* the agent's, in that order, without a model request ever being made. The
|
|
93
|
+
* marker rides split, because the pane echoes the command line it was typed and
|
|
94
|
+
* that echo must not be able to answer the proof.
|
|
80
95
|
*/
|
|
81
96
|
function definitionProof(subagentId) {
|
|
82
|
-
const
|
|
97
|
+
const command = [
|
|
98
|
+
`${OPENCODE_COMMAND} run --standalone`,
|
|
99
|
+
`--agent ${singleQuoteShellWord(subagentId)}`,
|
|
100
|
+
`--model ${singleQuoteShellWord(PROOF_MODEL)}`,
|
|
101
|
+
`${singleQuoteShellWord(PROOF_MESSAGE)} 2>&1`,
|
|
102
|
+
`| grep -q ${singleQuoteShellWord(MODEL_FAILURE)}`,
|
|
103
|
+
`&& echo ${splitMarker(DEFINITION_READY_MARKER)}`,
|
|
104
|
+
].join(" ");
|
|
83
105
|
return {
|
|
84
|
-
command
|
|
85
|
-
output:
|
|
86
|
-
timeoutMs:
|
|
87
|
-
failure: `failed to prepare the pane: \`${OPENCODE_COMMAND} agent
|
|
106
|
+
command,
|
|
107
|
+
output: DEFINITION_READY_MARKER,
|
|
108
|
+
timeoutMs: DEFINITION_PROOF_TIMEOUT_MS,
|
|
109
|
+
failure: `failed to prepare the pane: \`${OPENCODE_COMMAND} run --standalone --agent ${subagentId}\` never reported the staged definition — the definition staged for ${subagentId} is missing, unreadable, or not a primary agent, and opencode would run its own default agent instead. The agent did not start.`,
|
|
88
110
|
};
|
|
89
111
|
}
|
|
112
|
+
/**
|
|
113
|
+
* The model reference opencode takes: the key, with the variant joined to it when
|
|
114
|
+
* one was requested.
|
|
115
|
+
*/
|
|
116
|
+
function modelReference(modelKey, variant) {
|
|
117
|
+
return variant === null ? modelKey : `${modelKey}#${variant}`;
|
|
118
|
+
}
|
|
90
119
|
/** Warns with the `[subagents]` prefix every other config-plane warning carries. */
|
|
91
120
|
function warnListModels(reason) {
|
|
92
121
|
console.warn(`[subagents] Could not list the opencode models: ${reason}. The OpenCode Default Model row offers no models until the command answers.`);
|
|
@@ -116,7 +145,7 @@ function parseOpencodeModels(stdout) {
|
|
|
116
145
|
async function listOpencodeModels(pi) {
|
|
117
146
|
let stdout;
|
|
118
147
|
try {
|
|
119
|
-
const result = await pi.exec("opencode", ["models"], {
|
|
148
|
+
const result = await pi.exec("opencode", ["models", "--standalone"], {
|
|
120
149
|
timeout: LIST_MODELS_TIMEOUT_MS,
|
|
121
150
|
});
|
|
122
151
|
if (result.code !== 0) {
|
|
@@ -164,10 +193,38 @@ function fetchModels(pi) {
|
|
|
164
193
|
});
|
|
165
194
|
return fetch;
|
|
166
195
|
}
|
|
196
|
+
/**
|
|
197
|
+
* Whether this machine's opencode is one this harness can launch, and the line
|
|
198
|
+
* the human needs when it is not: the argv this harness builds is OpenCode 2's,
|
|
199
|
+
* so a binary of another major answers it with a usage dump rather than an
|
|
200
|
+
* agent. An opencode that is simply not installed stays quiet — the settings row
|
|
201
|
+
* omitting it already says so — while one that is there but reports nothing this
|
|
202
|
+
* can read says that much, because a binary that disappears from the offer with
|
|
203
|
+
* no reason given is worse than the reason itself.
|
|
204
|
+
*/
|
|
205
|
+
function opencodeAvailability() {
|
|
206
|
+
const probe = probeOpencode();
|
|
207
|
+
switch (probe.kind) {
|
|
208
|
+
case "supported":
|
|
209
|
+
return { status: "available" };
|
|
210
|
+
case "unsupported":
|
|
211
|
+
return {
|
|
212
|
+
status: "unavailable",
|
|
213
|
+
notice: `You seem to have opencode version ${probe.version} installed, pi-cowboy only supports v2.x.x.`,
|
|
214
|
+
};
|
|
215
|
+
case "unreadable":
|
|
216
|
+
return {
|
|
217
|
+
status: "unavailable",
|
|
218
|
+
notice: "Could not parse the version the opencode on your PATH reports, pi-cowboy only supports v2.x.x.",
|
|
219
|
+
};
|
|
220
|
+
case "absent":
|
|
221
|
+
return { status: "unavailable" };
|
|
222
|
+
}
|
|
223
|
+
}
|
|
167
224
|
export const opencodeHarness = {
|
|
168
225
|
id: "opencode",
|
|
169
226
|
agentMuxKind: "opencode",
|
|
170
|
-
|
|
227
|
+
availability: opencodeAvailability,
|
|
171
228
|
/**
|
|
172
229
|
* Stage the config directory, install the launcher that points opencode at it
|
|
173
230
|
* and feeds it the task, and prove the staged definition is live behind it. A
|
|
@@ -178,7 +235,6 @@ export const opencodeHarness = {
|
|
|
178
235
|
const configDir = writeOpencodeStaging({
|
|
179
236
|
subagentId: launch.subagentId,
|
|
180
237
|
systemPromptFile: launch.systemPromptFile,
|
|
181
|
-
variant: launch.variant,
|
|
182
238
|
toolSelection: launch.toolSelection,
|
|
183
239
|
});
|
|
184
240
|
await installPaneLauncher(pi, paneId, {
|
|
@@ -190,15 +246,23 @@ export const opencodeHarness = {
|
|
|
190
246
|
});
|
|
191
247
|
},
|
|
192
248
|
/**
|
|
193
|
-
*
|
|
249
|
+
* `mini` is the minimal *interactive* UI and is load-bearing: `opencode run`
|
|
194
250
|
* exits when the session goes idle and never reads the terminal again, so a
|
|
195
|
-
* later steer would be typed into the pane's shell.
|
|
196
|
-
*
|
|
251
|
+
* later steer would be typed into the pane's shell. `--standalone` is
|
|
252
|
+
* load-bearing for the same reason the argv names a subcommand at all: a
|
|
253
|
+
* launch without it reads the shared background server's config directory,
|
|
254
|
+
* where the staged definition is not. A variant has no flag of its own — it
|
|
255
|
+
* joins the model key after `#`.
|
|
197
256
|
*/
|
|
198
257
|
buildArgs(request) {
|
|
199
|
-
const args = ["
|
|
200
|
-
if (request.modelKey
|
|
201
|
-
|
|
258
|
+
const args = ["mini", "--standalone", "--agent", request.subagentId];
|
|
259
|
+
if (request.modelKey === null) {
|
|
260
|
+
if (request.variant !== null) {
|
|
261
|
+
throw new Error(`the opencode variant ${JSON.stringify(request.variant)} has no model to attach to: opencode takes a variant as part of a model reference (\`provider/model#variant\`), and this launch resolved no model. Give the agent an opencode model, or drop the variant.`);
|
|
262
|
+
}
|
|
263
|
+
return args;
|
|
264
|
+
}
|
|
265
|
+
args.push("--model", modelReference(request.modelKey, request.variant));
|
|
202
266
|
return args;
|
|
203
267
|
},
|
|
204
268
|
// opencode reads its own catalog; the injected pi catalog is the pi family's,
|
|
@@ -1,48 +1,48 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* opencode/permissions.ts — this launch's tool selection as opencode's
|
|
3
|
-
* permission
|
|
2
|
+
* opencode/permissions.ts — this launch's tool selection as opencode's ordered
|
|
3
|
+
* permission rules.
|
|
4
4
|
*
|
|
5
5
|
* Names arrive in opencode's own vocabulary — each family's slice is written in
|
|
6
6
|
* the catalogue that defines it, so a launch reads only its own family's — and
|
|
7
|
-
* become
|
|
7
|
+
* become rule actions as written, with no translation.
|
|
8
8
|
*
|
|
9
|
-
* opencode decides whether a tool may run by the last
|
|
10
|
-
*
|
|
11
|
-
*
|
|
9
|
+
* opencode decides whether a tool may run by the last rule that matches, so the
|
|
10
|
+
* order is part of the answer: the catch-all leads and every specific rule
|
|
11
|
+
* follows it.
|
|
12
12
|
*/
|
|
13
|
-
/** opencode's catch-all
|
|
13
|
+
/** opencode's catch-all action; every specific rule follows it. */
|
|
14
14
|
const ALL_TOOLS = "*";
|
|
15
|
+
/** Every rule this harness writes matches every resource. */
|
|
16
|
+
const ALL_RESOURCES = "*";
|
|
15
17
|
/** opencode's permission for asking the user a question. */
|
|
16
18
|
const QUESTION = "question";
|
|
19
|
+
/** One rule, over every resource. */
|
|
20
|
+
function rule(action, effect) {
|
|
21
|
+
return { action, resource: ALL_RESOURCES, effect };
|
|
22
|
+
}
|
|
17
23
|
/**
|
|
18
|
-
* `ToolSelection` -> opencode's permission
|
|
24
|
+
* `ToolSelection` -> opencode's permission rules.
|
|
19
25
|
*
|
|
20
26
|
* `question` is denied wherever the catch-all allows — nobody can answer an
|
|
21
27
|
* approval in a background pane, and opencode's mini mode would wait for one
|
|
22
28
|
* forever — while a denied catch-all already covers questions.
|
|
23
29
|
*/
|
|
24
30
|
export function opencodePermissions(toolSelection) {
|
|
25
|
-
const permissions = {};
|
|
26
31
|
switch (toolSelection.kind) {
|
|
27
32
|
case "default":
|
|
28
|
-
|
|
29
|
-
permissions[QUESTION] = "deny";
|
|
30
|
-
return permissions;
|
|
33
|
+
return [rule(ALL_TOOLS, "allow"), rule(QUESTION, "deny")];
|
|
31
34
|
case "none":
|
|
32
|
-
|
|
33
|
-
return permissions;
|
|
35
|
+
return [rule(ALL_TOOLS, "deny")];
|
|
34
36
|
case "include":
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
return permissions;
|
|
37
|
+
return [
|
|
38
|
+
rule(ALL_TOOLS, "deny"),
|
|
39
|
+
...toolSelection.names.map((name) => rule(name, "allow")),
|
|
40
|
+
];
|
|
40
41
|
case "exclude":
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
return permissions;
|
|
42
|
+
return [
|
|
43
|
+
rule(ALL_TOOLS, "allow"),
|
|
44
|
+
rule(QUESTION, "deny"),
|
|
45
|
+
...toolSelection.names.map((name) => rule(name, "deny")),
|
|
46
|
+
];
|
|
47
47
|
}
|
|
48
48
|
}
|
|
@@ -4,15 +4,13 @@
|
|
|
4
4
|
*
|
|
5
5
|
* opencode launches with `OPENCODE_CONFIG_DIR` naming this directory and with
|
|
6
6
|
* project config disabled, so everything the spawn gets is what lands here: the
|
|
7
|
-
* definition its prompt is read from (definition.ts)
|
|
8
|
-
* opencode from installing its plugin (npm-seed.ts). Nothing here launches
|
|
7
|
+
* definition its prompt is read from (definition.ts). Nothing here launches
|
|
9
8
|
* anything or knows which pane the process will live in.
|
|
10
9
|
*/
|
|
11
10
|
import fs from "node:fs";
|
|
12
11
|
import * as path from "node:path";
|
|
13
12
|
import { subagentResultDirFor } from "../../../paths.js";
|
|
14
13
|
import { removeAgentDefinition, writeAgentDefinition } from "./definition.js";
|
|
15
|
-
import { removeNpmSeed, writeNpmSeed } from "./npm-seed.js";
|
|
16
14
|
/** The config directory's name inside a spawn's staging directory. */
|
|
17
15
|
const CONFIG_DIR_NAME = "opencode";
|
|
18
16
|
/**
|
|
@@ -26,7 +24,7 @@ export function opencodeConfigDir(subagentId) {
|
|
|
26
24
|
*
|
|
27
25
|
* The system prompt is read before anything is created, so an unreadable prompt
|
|
28
26
|
* file fails the spawn without leaving a half-built tree behind. A definition
|
|
29
|
-
* file already in place is overwritten
|
|
27
|
+
* file already in place is overwritten.
|
|
30
28
|
*/
|
|
31
29
|
export function writeOpencodeStaging(input) {
|
|
32
30
|
const systemPrompt = fs.readFileSync(input.systemPromptFile, "utf-8");
|
|
@@ -34,10 +32,8 @@ export function writeOpencodeStaging(input) {
|
|
|
34
32
|
writeAgentDefinition(configDir, {
|
|
35
33
|
subagentId: input.subagentId,
|
|
36
34
|
systemPrompt,
|
|
37
|
-
variant: input.variant,
|
|
38
35
|
toolSelection: input.toolSelection,
|
|
39
36
|
});
|
|
40
|
-
writeNpmSeed(configDir);
|
|
41
37
|
return configDir;
|
|
42
38
|
}
|
|
43
39
|
/**
|
|
@@ -48,7 +44,6 @@ export function writeOpencodeStaging(input) {
|
|
|
48
44
|
export function removeOpencodeStaging(subagentId) {
|
|
49
45
|
const configDir = opencodeConfigDir(subagentId);
|
|
50
46
|
removeAgentDefinition(configDir, subagentId);
|
|
51
|
-
removeNpmSeed(configDir);
|
|
52
47
|
removeConfigDir(configDir);
|
|
53
48
|
}
|
|
54
49
|
/** Remove the directory the staged files lived in. Best effort. */
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* opencode/version.ts — what the installed binary reports, and whether this
|
|
3
|
+
* harness speaks it.
|
|
4
|
+
*
|
|
5
|
+
* The harness launches OpenCode 2's CLI (`mini`, `--standalone`, `--model` with
|
|
6
|
+
* a `#variant`), which another major refuses outright. A machine whose
|
|
7
|
+
* `opencode` is not 2.x is therefore not a machine this harness can launch on,
|
|
8
|
+
* and the reason it cannot is the version itself — so the read is judged here,
|
|
9
|
+
* once, and both the verdict and any line for the human come from it.
|
|
10
|
+
*/
|
|
11
|
+
import { commandPath } from "../../../infrastructure/exec-path.js";
|
|
12
|
+
import { runSync } from "../../../infrastructure/exec-sync.js";
|
|
13
|
+
/** The major this harness launches: the CLI surface its argv is built against. */
|
|
14
|
+
const SUPPORTED_MAJOR = "2";
|
|
15
|
+
/** `opencode --version` prints one line: the program, a `v`, then the version. */
|
|
16
|
+
const VERSION_LINE = /^opencode v(\d+\.\d+\.\d+)/;
|
|
17
|
+
/** Budget for the read: a binary that hangs must not hold the session's probe. */
|
|
18
|
+
const VERSION_TIMEOUT_MS = 5_000;
|
|
19
|
+
/**
|
|
20
|
+
* The version a `--version` output names, or undefined when it is not that line.
|
|
21
|
+
* Nothing else about the output is read, so a banner added around it costs
|
|
22
|
+
* nothing.
|
|
23
|
+
*/
|
|
24
|
+
export function parseOpencodeVersion(output) {
|
|
25
|
+
return VERSION_LINE.exec(output.trim())?.[1];
|
|
26
|
+
}
|
|
27
|
+
/** Whether a parsed version's CLI is the one this harness builds argv against. */
|
|
28
|
+
export function isSupportedOpencodeVersion(version) {
|
|
29
|
+
return version.startsWith(`${SUPPORTED_MAJOR}.`);
|
|
30
|
+
}
|
|
31
|
+
/** Read the installed binary's version. Total: every outcome is one member. */
|
|
32
|
+
export function probeOpencode() {
|
|
33
|
+
const bin = commandPath("opencode");
|
|
34
|
+
if (bin === undefined)
|
|
35
|
+
return { kind: "absent" };
|
|
36
|
+
const output = runSync(bin, ["--version"], VERSION_TIMEOUT_MS);
|
|
37
|
+
const version = output === undefined ? undefined : parseOpencodeVersion(output);
|
|
38
|
+
if (version === undefined)
|
|
39
|
+
return { kind: "unreadable" };
|
|
40
|
+
return isSupportedOpencodeVersion(version)
|
|
41
|
+
? { kind: "supported", version }
|
|
42
|
+
: { kind: "unsupported", version };
|
|
43
|
+
}
|
|
@@ -33,11 +33,11 @@ const INSTALL_MAX_ATTEMPTS = 5;
|
|
|
33
33
|
const INSTALL_OUTPUT_TIMEOUT_MS = 2_000;
|
|
34
34
|
const INSTALL_RETRY_DELAY_MS = 250;
|
|
35
35
|
/**
|
|
36
|
-
*
|
|
36
|
+
* Split a marker with a `""` so that only the shell's evaluation of a command —
|
|
37
37
|
* not the command line's own echo, which `wait-output` also sees — produces the
|
|
38
38
|
* contiguous token.
|
|
39
39
|
*/
|
|
40
|
-
function splitMarker(marker) {
|
|
40
|
+
export function splitMarker(marker) {
|
|
41
41
|
const at = marker.indexOf("_");
|
|
42
42
|
return at === -1
|
|
43
43
|
? marker
|
|
@@ -89,7 +89,9 @@ export function createPiCompatibleHarness(spec) {
|
|
|
89
89
|
// The launcher runs `spec.binary` inside the pane, so a machine without it
|
|
90
90
|
// can never launch this harness — however well the preparation itself would
|
|
91
91
|
// go.
|
|
92
|
-
|
|
92
|
+
availability: () => commandPath(spec.binary) === undefined
|
|
93
|
+
? { status: "unavailable" }
|
|
94
|
+
: { status: "available" },
|
|
93
95
|
// The binary is pi behind the shell trick, so the argv is pi's; only a
|
|
94
96
|
// harness that stages filesystem state before launch has teardown work —
|
|
95
97
|
// the launcher dies with the pane and the staged files belong to the
|
|
@@ -21,7 +21,7 @@ import { claudeHarness } from "./claude/index.js";
|
|
|
21
21
|
const piHarness = {
|
|
22
22
|
id: "pi",
|
|
23
23
|
agentMuxKind: "pi",
|
|
24
|
-
|
|
24
|
+
availability: () => ({ status: "available" }),
|
|
25
25
|
prepare: async () => { },
|
|
26
26
|
buildArgs: buildPiLaunchArgs,
|
|
27
27
|
listModels: piFamilyListModels,
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
* cow-support-launch.ts — ask the worktree volume, once per session, which
|
|
3
3
|
* materializations it can honor, and let the shell answer for every later reader.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
5
|
+
* Awaited at `session_start`, so the probe's `finally rm` always runs while
|
|
6
|
+
* this process lives: a session that exits mid-probe would otherwise orphan
|
|
7
|
+
* its `.cow-probe-*` directory. The block is one small clone (~100ms), once
|
|
8
|
+
* per session. Each probe carries a claim, so a slow one cannot overwrite the
|
|
9
9
|
* answer of a newer probe about a different volume.
|
|
10
10
|
*/
|
|
11
11
|
import { detectCowAvailability, probeTargetFor } from "./spawn/cow-support.js";
|
|
@@ -16,7 +16,7 @@ function execOf(pi) {
|
|
|
16
16
|
return (command, args, options) => pi.exec(command, args, options);
|
|
17
17
|
}
|
|
18
18
|
export function startCowSupportProbe(pi) {
|
|
19
|
-
probe(pi, beginCowAvailabilityProbe());
|
|
19
|
+
return probe(pi, beginCowAvailabilityProbe());
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
22
22
|
* Ask again, because the worktree root can move to another volume. The answer
|
|
@@ -26,7 +26,7 @@ export function startCowSupportProbe(pi) {
|
|
|
26
26
|
export function refreshCowSupportProbe(pi) {
|
|
27
27
|
const claim = beginCowAvailabilityProbe();
|
|
28
28
|
setCowAvailability(claim, unprobed());
|
|
29
|
-
probe(pi, claim);
|
|
29
|
+
return probe(pi, claim);
|
|
30
30
|
}
|
|
31
31
|
/**
|
|
32
32
|
* Run one probe and record its verdict under the claim it was opened with. An
|
|
@@ -35,7 +35,7 @@ export function refreshCowSupportProbe(pi) {
|
|
|
35
35
|
*/
|
|
36
36
|
function probe(pi, claim) {
|
|
37
37
|
const target = probeTargetFor(getStore().agent.worktreeRoot);
|
|
38
|
-
|
|
38
|
+
return detectCowAvailability(execOf(pi), target).then((availability) => {
|
|
39
39
|
setCowAvailability(claim, availability);
|
|
40
40
|
}, () => {
|
|
41
41
|
setCowAvailability(claim, probed(["checkout"]));
|
package/dist/events.js
CHANGED
|
@@ -14,6 +14,7 @@ import { ACTIVE_AGENT_PHASES } from "./types.js";
|
|
|
14
14
|
import { SpawnCoordinator } from "./spawn/spawn-coordinator.js";
|
|
15
15
|
import { toolCallListener } from "./agents/tool-execution.js";
|
|
16
16
|
import { activateExtension, deactivateExtension } from "./registration.js";
|
|
17
|
+
import { startCowSupportProbe } from "./cow-support-launch.js";
|
|
17
18
|
import { isExtensionEnabled } from "./extension-toggle.js";
|
|
18
19
|
import { hideExtensionIndicator } from "./ui/indicator.js";
|
|
19
20
|
import { createSessionTemplates, getManagerOrNull, getCoordinatorOrNull, getStore, setSessionCtx, setManager, setCoordinator, setRuntime, setSessionTemplates, } from "./shell.js";
|
|
@@ -98,6 +99,10 @@ export function setupEventListeners(pi) {
|
|
|
98
99
|
pi.on("session_start", async (_event, ctx) => {
|
|
99
100
|
setSessionCtx(ctx);
|
|
100
101
|
await loadSessionConfig(ctx);
|
|
102
|
+
// Awaited: one small clone (~100ms), and awaiting is what guarantees the
|
|
103
|
+
// probe's `finally rm` runs — a fire-and-forget probe orphaned its
|
|
104
|
+
// `.cow-probe-*` directory whenever a quick session exited mid-probe.
|
|
105
|
+
await startCowSupportProbe(pi);
|
|
101
106
|
if (isExtensionEnabled()) {
|
|
102
107
|
activateExtension(ctx.ui);
|
|
103
108
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* harness-availability-launch.ts — ask
|
|
3
|
-
*
|
|
4
|
-
* warm the slow model lists through each harness's own hook.
|
|
2
|
+
* harness-availability-launch.ts — ask each harness what this machine can do
|
|
3
|
+
* with it, once at launch, and let the shell answer for every later reader;
|
|
4
|
+
* then warm the slow model lists through each harness's own hook.
|
|
5
5
|
*
|
|
6
6
|
* The scan is synchronous, so the answer is in the shell before the first menu can
|
|
7
7
|
* open and there is no claim to defend: unlike the volume probe, this verdict
|
|
@@ -9,21 +9,53 @@
|
|
|
9
9
|
* probe is never awaited: a launch must not block on a CLI. Where a warmed
|
|
10
10
|
* fetch lives is each harness's own business — this module names no harness
|
|
11
11
|
* beyond iterating the runnable ones, and holds no model state itself.
|
|
12
|
+
*
|
|
13
|
+
* A harness whose binary is installed but cannot be launched answers with a line
|
|
14
|
+
* for the human. That line is shown once the UI exists, so the pass over the
|
|
15
|
+
* vocabulary happens here — once — and its notices are carried to the session
|
|
16
|
+
* that can display them.
|
|
12
17
|
*/
|
|
13
18
|
import { HARNESS_IDS, runnableHarnessIds, } from "./agents/harness.js";
|
|
14
19
|
import { harnessFor } from "./agents/harness/registry.js";
|
|
15
20
|
import { probed } from "./availability.js";
|
|
16
21
|
import { getHarnessAvailability, setHarnessAvailability } from "./shell.js";
|
|
17
22
|
/**
|
|
18
|
-
* What this machine can
|
|
19
|
-
*
|
|
20
|
-
*
|
|
23
|
+
* What this machine can do with each harness, in the vocabulary's own order. One
|
|
24
|
+
* question per harness, so a verdict and the line explaining it can never come
|
|
25
|
+
* from two different reads of the same binary.
|
|
21
26
|
*/
|
|
22
|
-
export function
|
|
23
|
-
|
|
27
|
+
export function probeHarnessAvailability() {
|
|
28
|
+
const available = [];
|
|
29
|
+
const notices = [];
|
|
30
|
+
for (const id of HARNESS_IDS) {
|
|
31
|
+
const answer = harnessFor(id).availability();
|
|
32
|
+
if (answer.status === "available")
|
|
33
|
+
available.push(id);
|
|
34
|
+
else if (answer.notice !== undefined)
|
|
35
|
+
notices.push(answer.notice);
|
|
36
|
+
}
|
|
37
|
+
return { availability: probed(available), notices };
|
|
38
|
+
}
|
|
39
|
+
/** Record the probe's answer for every later reader, and queue what it has to say. */
|
|
40
|
+
export function startHarnessAvailabilityProbe(pi) {
|
|
41
|
+
const { availability, notices } = probeHarnessAvailability();
|
|
42
|
+
setHarnessAvailability(availability);
|
|
43
|
+
reportNotices(pi, notices);
|
|
24
44
|
}
|
|
25
|
-
|
|
26
|
-
|
|
45
|
+
/**
|
|
46
|
+
* Show each line once the UI exists. The entry point has no context, so the
|
|
47
|
+
* session event is the first moment there is somewhere to put it; a run without
|
|
48
|
+
* a UI has nowhere to show a notice and drops it.
|
|
49
|
+
*/
|
|
50
|
+
function reportNotices(pi, notices) {
|
|
51
|
+
if (notices.length === 0)
|
|
52
|
+
return;
|
|
53
|
+
pi.on("session_start", (_event, ctx) => {
|
|
54
|
+
if (!ctx.hasUI)
|
|
55
|
+
return;
|
|
56
|
+
for (const notice of notices)
|
|
57
|
+
ctx.ui.notify(notice, "warning");
|
|
58
|
+
});
|
|
27
59
|
}
|
|
28
60
|
/**
|
|
29
61
|
* Warm every runnable harness's slow model list, without naming any harness.
|
package/dist/index.js
CHANGED
|
@@ -9,7 +9,8 @@ import { missingCloneProgramReport } from "./infrastructure/git/cow-clone.js";
|
|
|
9
9
|
import { isInsideGitRepository } from "./infrastructure/git-client.js";
|
|
10
10
|
import { registerCowboyCommand, registerTools, registerUnavailableCowboyCommand, } from "./registration.js";
|
|
11
11
|
import { setupEventListeners } from "./events.js";
|
|
12
|
-
|
|
12
|
+
// What the worktree volume can do is probed at session_start (awaited there),
|
|
13
|
+
// once the session config has reloaded the worktree root.
|
|
13
14
|
import { prefetchHarnessModels, startHarnessAvailabilityProbe, } from "./harness-availability-launch.js";
|
|
14
15
|
/** The one reason the extension is unavailable when the session is not inside a git repository. */
|
|
15
16
|
const NOT_INSIDE_GIT_REPOSITORY = "pi-cowboy needs a git repository: this directory is not inside one, so pi-cowboy stays inactive";
|
|
@@ -55,10 +56,9 @@ export default function (pi) {
|
|
|
55
56
|
registerTools(pi);
|
|
56
57
|
registerCowboyCommand(pi);
|
|
57
58
|
setupEventListeners(pi);
|
|
58
|
-
//
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
startHarnessAvailabilityProbe();
|
|
59
|
+
// Which harnesses are on PATH — and spoken by a version this extension
|
|
60
|
+
// launches — decides which stay on offer.
|
|
61
|
+
startHarnessAvailabilityProbe(pi);
|
|
62
62
|
// Slow model lists start warming now, never awaited; every later listing
|
|
63
63
|
// joins whatever its harness started.
|
|
64
64
|
prefetchHarnessModels(pi);
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* exec-sync.ts — the one place this extension waits for a child process.
|
|
3
|
+
*
|
|
4
|
+
* The harness availability probe is synchronous by design: its verdict is in the
|
|
5
|
+
* shell before the first menu can open, and a binary's version is part of that
|
|
6
|
+
* verdict. Everything else shells out asynchronously through `pi.exec`, so
|
|
7
|
+
* children inherit the session environment; nothing here needs that, because a
|
|
8
|
+
* version read is one word of output from a binary PATH has already resolved.
|
|
9
|
+
*/
|
|
10
|
+
import { execFileSync } from "node:child_process";
|
|
11
|
+
/**
|
|
12
|
+
* Run a command and wait for its output, or undefined when it did not answer: a
|
|
13
|
+
* missing binary, a non-zero exit and a timeout are one answer here, because a
|
|
14
|
+
* caller that needs a successful run has no use for a failure's exit code.
|
|
15
|
+
*
|
|
16
|
+
* Stdin is discarded rather than inherited, so a command that reads it cannot
|
|
17
|
+
* wait on a terminal that is not there.
|
|
18
|
+
*/
|
|
19
|
+
export function runSync(command, args, timeoutMs) {
|
|
20
|
+
try {
|
|
21
|
+
return execFileSync(command, [...args], {
|
|
22
|
+
encoding: "utf8",
|
|
23
|
+
timeout: timeoutMs,
|
|
24
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -85,8 +85,9 @@ export async function showSpawnOptionsMenu(ctx) {
|
|
|
85
85
|
const trimmed = value.trim();
|
|
86
86
|
store.mutate.agent.setWorktreeRoot(trimmed || undefined);
|
|
87
87
|
// The new root may sit on another volume; the launch probe answered
|
|
88
|
-
// for the old one, and nothing else refreshes it.
|
|
89
|
-
|
|
88
|
+
// for the old one, and nothing else refreshes it. Not awaited: the
|
|
89
|
+
// interactive session outlives this ~100ms probe, so its cleanup runs.
|
|
90
|
+
void refreshCowSupportProbe(getPiInstance());
|
|
90
91
|
ctx.ui.notify(trimmed
|
|
91
92
|
? `Worktree root set to ${trimmed}`
|
|
92
93
|
: "Worktree root cleared (default)", "info");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-cowboy",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"packageManager": "pnpm@12.9.1",
|
|
6
6
|
"description": "Agent orchestrator for pi: can manage Codex, Claude Code, OpenCode, pi, pig and pi-bolt as subagents. Runs subagents in background Herdr panes, isolated in copy-on-write Git worktrees.",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"test:integration": "pnpm run build && vitest run --project integration-no-cow --project integration-cow",
|
|
57
57
|
"test:integration-no-cow": "pnpm run build && vitest run --project integration-no-cow",
|
|
58
58
|
"test:integration-cow": "pnpm run build && vitest run --project integration-cow",
|
|
59
|
-
"dev:install": "
|
|
59
|
+
"dev:install": "pi remove . 2>/dev/null; pi install ./dev",
|
|
60
60
|
"lint": "oxlint",
|
|
61
61
|
"lint:fix": "oxlint --fix",
|
|
62
62
|
"commitlint": "commitlint",
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* opencode/npm-seed.ts — the fake npm project that keeps opencode from
|
|
3
|
-
* installing its plugin into every config directory it loads.
|
|
4
|
-
*
|
|
5
|
-
* opencode treats a config directory as an npm project: on every load it asks
|
|
6
|
-
* npm for `@opencode-ai/plugin`, which is 61 MB of `node_modules` per spawn
|
|
7
|
-
* (measured on 1.18.35). The seed is a workaround for that check — an
|
|
8
|
-
* undocumented dependency test inside someone else's binary — so it lives alone
|
|
9
|
-
* here, with the rule it was derived from, rather than beside anything that
|
|
10
|
-
* reads a config directory for its own sake.
|
|
11
|
-
*/
|
|
12
|
-
import fs from "node:fs";
|
|
13
|
-
import * as path from "node:path";
|
|
14
|
-
import { ensureResultDir, writeResultFile, } from "../../result-file-permissions.js";
|
|
15
|
-
/** Where opencode resolves a config directory's dependencies from. */
|
|
16
|
-
const NODE_MODULES_DIR_NAME = "node_modules";
|
|
17
|
-
/** The npm project opencode's check reads. */
|
|
18
|
-
const PACKAGE_FILE_NAME = "package.json";
|
|
19
|
-
const LOCK_FILE_NAME = "package-lock.json";
|
|
20
|
-
/** The package opencode installs into every config directory it loads. */
|
|
21
|
-
const PLUGIN_PACKAGE = "@opencode-ai/plugin";
|
|
22
|
-
/**
|
|
23
|
-
* The version the seed declares for `PLUGIN_PACKAGE`.
|
|
24
|
-
*
|
|
25
|
-
* opencode's check runs its install only when `<configDir>/node_modules` is
|
|
26
|
-
* missing, or when `package-lock.json`'s root package (`packages[""]`) names
|
|
27
|
-
* none of the dependencies that `package.json` and opencode's own `add` list
|
|
28
|
-
* declare. Neither file's version is compared — a seed declaring `0.0.1`, or
|
|
29
|
-
* `*`, short-circuits exactly like this one — so this pin can fall behind an
|
|
30
|
-
* upgraded opencode without costing anything. Should opencode start comparing
|
|
31
|
-
* versions, the check fails and opencode installs the version it pins, rewriting
|
|
32
|
-
* both files: the same one-time install a directory with no seed at all pays.
|
|
33
|
-
*/
|
|
34
|
-
const PLUGIN_VERSION = "1.18.35";
|
|
35
|
-
/**
|
|
36
|
-
* The seed manifest: exactly what a real install leaves, without the installed
|
|
37
|
-
* bytes.
|
|
38
|
-
*/
|
|
39
|
-
const PACKAGE_JSON = `${JSON.stringify({ dependencies: { [PLUGIN_PACKAGE]: PLUGIN_VERSION } }, null, 2)}\n`;
|
|
40
|
-
/**
|
|
41
|
-
* The seed lock for a directory. opencode's check reads one thing out of it —
|
|
42
|
-
* the root package's declared dependency names — so it carries no resolved tree;
|
|
43
|
-
* a real install rewrites it in full. The name is the directory's own, as npm
|
|
44
|
-
* writes it.
|
|
45
|
-
*/
|
|
46
|
-
function packageLockJson(configDir) {
|
|
47
|
-
return `${JSON.stringify({
|
|
48
|
-
name: path.basename(configDir),
|
|
49
|
-
lockfileVersion: 3,
|
|
50
|
-
requires: true,
|
|
51
|
-
packages: { "": { dependencies: { [PLUGIN_PACKAGE]: PLUGIN_VERSION } } },
|
|
52
|
-
}, null, 2)}\n`;
|
|
53
|
-
}
|
|
54
|
-
/** Write the seed into a config directory, creating the module directory it names. */
|
|
55
|
-
export function writeNpmSeed(configDir) {
|
|
56
|
-
ensureResultDir(path.join(configDir, NODE_MODULES_DIR_NAME));
|
|
57
|
-
writeResultFile(path.join(configDir, PACKAGE_FILE_NAME), PACKAGE_JSON);
|
|
58
|
-
writeResultFile(path.join(configDir, LOCK_FILE_NAME), packageLockJson(configDir));
|
|
59
|
-
}
|
|
60
|
-
/** Remove the seed. Best effort, and safe when it is already gone. */
|
|
61
|
-
export function removeNpmSeed(configDir) {
|
|
62
|
-
try {
|
|
63
|
-
fs.rmSync(path.join(configDir, NODE_MODULES_DIR_NAME), {
|
|
64
|
-
recursive: true,
|
|
65
|
-
force: true,
|
|
66
|
-
});
|
|
67
|
-
fs.rmSync(path.join(configDir, PACKAGE_FILE_NAME), { force: true });
|
|
68
|
-
fs.rmSync(path.join(configDir, LOCK_FILE_NAME), { force: true });
|
|
69
|
-
}
|
|
70
|
-
catch {
|
|
71
|
-
// Best effort: the seed is a temp-dir artifact, like the rest of the spawn's
|
|
72
|
-
// staging files.
|
|
73
|
-
}
|
|
74
|
-
}
|