master-orchestrator 0.1.0 → 0.2.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/CHANGELOG.md +8 -0
- package/README.md +18 -16
- package/package.json +1 -1
- package/src/adapters/agy.ts +1 -1
- package/src/adapters/claude.ts +1 -1
- package/src/adapters/codex.ts +1 -1
- package/src/adapters/dsh.ts +1 -1
- package/src/adapters/gemini.ts +20 -6
- package/src/adapters/grok.ts +1 -1
- package/src/adapters/omp.ts +1 -1
- package/src/adapters/opencode.ts +1 -1
- package/src/adapters/pi.ts +1 -1
- package/src/adapters/registry.ts +0 -4
- package/src/config/schema.ts +2 -2
- package/src/engine/runner.ts +52 -6
- package/src/adapters/cursor.ts +0 -242
- package/src/adapters/muse.ts +0 -281
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
- Removed the Muse Code and Cursor Agent adapters. A profile with `agent: "muse"` or `agent: "cursor"` is now a configuration error, and `debate.minParticipants` is at most 9.
|
|
6
|
+
- Cancelling or timing out a run now also stops the processes the agent moved into a session of its own; Gemini CLI's shell tool did, and its commands outlived the run.
|
|
7
|
+
- Gemini CLI: a warning explains "Invalid auth method selected" when `GOOGLE_GEMINI_BASE_URL` is set.
|
|
8
|
+
- Gemini CLI: runs set `NO_BROWSER`, so Google login without cached credentials fails at once as `auth_required`. Before, the CLI asked for consent on stdin, read the first line of the prompt as the answer, and could open a browser.
|
|
9
|
+
- Live checks: Gemini CLI now passes analyze, implement, follow-up and cancellation; the nine agents that ran live also stop cleanly at the timeout (`MO_LIVE_TIMEOUT=1`).
|
|
10
|
+
|
|
3
11
|
## 0.1.0
|
|
4
12
|
|
|
5
13
|
First release.
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# master-orchestrator
|
|
2
2
|
|
|
3
|
-
A [pi](https://www.npmjs.com/package/@earendil-works/pi-coding-agent) package that turns pi into an orchestrator of other coding agents. Pi delegates assignments to Codex, Claude Code, OpenCode, pi, oh-my-pi, Antigravity, Grok Build,
|
|
3
|
+
A [pi](https://www.npmjs.com/package/@earendil-works/pi-coding-agent) package that turns pi into an orchestrator of other coding agents. Pi delegates assignments to Codex, Claude Code, OpenCode, pi, oh-my-pi, Antigravity, Grok Build, DeepSeek Harness and Gemini CLI, moderates debates between them, and plans and executes multi-step work with per-block review.
|
|
4
4
|
|
|
5
5
|
## Read this first: what the workers can do
|
|
6
6
|
|
|
@@ -125,7 +125,7 @@ A project file cannot loosen `approval` and cannot set `agents.*.bin`, `agents.*
|
|
|
125
125
|
}
|
|
126
126
|
```
|
|
127
127
|
|
|
128
|
-
Bounds: `timeoutMinutes` 1–720, `maxParallel` 1–16, `artifactRetentionDays` 1–365, `debate.maxRounds` 0–5, `debate.minParticipants` 2–
|
|
128
|
+
Bounds: `timeoutMinutes` 1–720, `maxParallel` 1–16, `artifactRetentionDays` 1–365, `debate.maxRounds` 0–5, `debate.minParticipants` 2–9, `planning.maxRevisions` 0–3, `maxFixAttempts` 0–5.
|
|
129
129
|
|
|
130
130
|
Every detected agent also has an implicit profile named after it, with no model or effort, so the agent uses its own defaults: a fresh install delegates with zero configuration. Roles have no built-in mapping; a workflow that needs an unconfigured role asks you to pick profiles and offers to save the choice. Models and effort levels are passed as configured, never invented.
|
|
131
131
|
|
|
@@ -133,25 +133,25 @@ Every detected agent also has an implicit profile named after it, with no model
|
|
|
133
133
|
|
|
134
134
|
| Agent | Binary | Tested versions | Full-access invocation | Live-checked (2026-11-25) |
|
|
135
135
|
|---|---|---|---|---|
|
|
136
|
-
| Codex | `codex` | >=0.163.0 <0.200.0 | `-a never --sandbox danger-full-access` | 0.172.0: analyze, implement, follow-up, cancel, auth failure |
|
|
137
|
-
| Claude Code | `claude` | >=2.1.305 <2.2.0 | `--permission-mode bypassPermissions`, sandbox disabled through `--settings` | 2.1.328: analyze, implement, follow-up, cancel, auth failure |
|
|
138
|
-
| OpenCode | `opencode` | >=2.1.3 <2.4.0 | `--auto` | 2.3.0: analyze, implement, follow-up, cancel |
|
|
139
|
-
| pi | `pi` | >=1.4.0 <1.7.0 | none needed | 1.6.1: analyze, implement, follow-up, cancel, auth failure |
|
|
140
|
-
| oh-my-pi | `omp` | >=18.11.1 <20.0.0 | `--auto-approve` (a per-run overlay also turns off auto-resume) | 19.1.1: analyze, implement, follow-up, cancel, auth failure |
|
|
141
|
-
| Antigravity | `agy` | >=1.4.4 <1.6.0 | `--dangerously-skip-permissions` | 1.5.17: analyze, implement, follow-up, cancel |
|
|
142
|
-
| Grok Build | `grok` | >=1.0.62 <1.1.0 | `--always-approve`, `GROK_SANDBOX` unset | 1.0.77: analyze, implement, follow-up, cancel, auth failure |
|
|
143
|
-
|
|
|
144
|
-
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
136
|
+
| Codex | `codex` | >=0.163.0 <0.200.0 | `-a never --sandbox danger-full-access` | 0.172.0: analyze, implement, follow-up, cancel, timeout, auth failure |
|
|
137
|
+
| Claude Code | `claude` | >=2.1.305 <2.2.0 | `--permission-mode bypassPermissions`, sandbox disabled through `--settings` | 2.1.328: analyze, implement, follow-up, cancel, timeout, auth failure |
|
|
138
|
+
| OpenCode | `opencode` | >=2.1.3 <2.4.0 | `--auto` | 2.3.0: analyze, implement, follow-up, cancel, timeout |
|
|
139
|
+
| pi | `pi` | >=1.4.0 <1.7.0 | none needed | 1.6.1: analyze, implement, follow-up, cancel, timeout, auth failure |
|
|
140
|
+
| oh-my-pi | `omp` | >=18.11.1 <20.0.0 | `--auto-approve` (a per-run overlay also turns off auto-resume) | 19.1.1: analyze, implement, follow-up, cancel, timeout, auth failure |
|
|
141
|
+
| Antigravity | `agy` | >=1.4.4 <1.6.0 | `--dangerously-skip-permissions` | 1.5.17: analyze, implement, follow-up, cancel, timeout |
|
|
142
|
+
| Grok Build | `grok` | >=1.0.62 <1.1.0 | `--always-approve`, `GROK_SANDBOX` unset | 1.0.77: analyze, implement, follow-up, cancel, timeout, auth failure |
|
|
143
|
+
| DeepSeek Harness | `dsh` | >=0.2.1-rc.3 <0.3.0-0 | `DSH_PERMISSION_MODE=danger-full-access` | 0.2.2-rc.3: analyze, implement, follow-up, cancel, timeout, auth failure |
|
|
144
|
+
| Gemini CLI | `gemini` | >=0.51.0 <0.60.0 | `--approval-mode yolo`, `GEMINI_SANDBOX=false` | 0.51.0: analyze, implement, follow-up, cancel, timeout, auth failure (trusted project) |
|
|
145
|
+
|
|
146
|
+
Every adapter is still `experimental`: the verification pass also asks how a denial and a quota failure appear, and those were not observed live for any agent. A timeout was: every agent above stopped cleanly on its stop signal, and the run reports `timeout` even when the agent then exits 0 (Claude Code, DeepSeek Harness and Gemini CLI do). The recorded runs are in `test/fixtures/<agent>/live-*.json`. `/orchestrator doctor` shows what was checked, and every run on an experimental adapter carries a warning. Outside the tested range an agent still runs, with a warning, unless `allowUntestedVersion` is false.
|
|
147
|
+
|
|
148
|
+
Gemini CLI keeps yolo only in a trusted folder: in an untrusted one it falls back to its default approval mode and refuses tool calls that need approval, and the run carries a warning. Trust the project in pi, which passes `--skip-trust`. To use your Google login, sign in once by running `gemini` in a terminal and choosing "Sign in with Google"; delegated runs reuse the cached credentials. A delegated run never opens a browser: without a valid cached login it ends as `auth_required` at once. With `GOOGLE_GEMINI_BASE_URL` set and no auth type selected, Gemini CLI 0.51.0 selects its `gateway` auth type and its headless check rejects it ("Invalid auth method selected"); set `security.auth.selectedType` in `~/.gemini/settings.json`, or set `"GOOGLE_GEMINI_BASE_URL": ""` in `agents.gemini.env` to use the Gemini API directly.
|
|
149
149
|
|
|
150
150
|
DeepSeek Harness runs its `headless` profile, which has no model flag. A provider declared only in another dsh profile is not visible there: put its `llm-pi-ai` row in a patch file, point the profile's `options.patchFile` at it, and set `model` to `<provider>/<model>`.
|
|
151
151
|
|
|
152
152
|
What still applies inside a run is whatever you configured in the agent itself: deny rules, policies and hooks. A run can end on a denial, and the result reports it.
|
|
153
153
|
|
|
154
|
-
When the pi session trusts the project, adapters pass their agent's per-run trust flag so it loads project rules (`--approve` for pi, `--
|
|
154
|
+
When the pi session trusts the project, adapters pass their agent's per-run trust flag so it loads project rules (`--approve` for pi, `--skip-trust` for Gemini CLI). Grok Build's `--trust` persists the grant in its configuration and is passed only with `agents.grok.persistTrust: true`.
|
|
155
155
|
|
|
156
156
|
## Data handling
|
|
157
157
|
|
|
@@ -168,6 +168,8 @@ npm run check # tsc --noEmit
|
|
|
168
168
|
MO_LIVE_AGENTS=codex,claude node --test --experimental-strip-types test/live/smoke.test.ts # spends tokens
|
|
169
169
|
```
|
|
170
170
|
|
|
171
|
+
The live tests take per-agent overrides: `MO_LIVE_MODEL_<AGENT>`, `MO_LIVE_OPTIONS_<AGENT>` (profile options as JSON), `MO_LIVE_ENV_<AGENT>` (agent env as JSON), `MO_LIVE_TRUSTED=1` to run as a trusted project, and `MO_LIVE_TIMEOUT=1` to add a timeout test that takes over a minute per agent.
|
|
172
|
+
|
|
171
173
|
The specification is in [`docs/SPEC.md`](docs/SPEC.md).
|
|
172
174
|
|
|
173
175
|
## License
|
package/package.json
CHANGED
package/src/adapters/agy.ts
CHANGED
|
@@ -60,7 +60,7 @@ export const agyAdapter: AgentAdapter = {
|
|
|
60
60
|
binary: "agy",
|
|
61
61
|
testedVersions: ">=1.4.4 <1.6.0",
|
|
62
62
|
stability: "experimental",
|
|
63
|
-
liveChecked: "1.5.17 on 2026-11-25: analyze, implement, follow-up, cancellation",
|
|
63
|
+
liveChecked: "1.5.17 on 2026-11-25: analyze, implement, follow-up, cancellation, timeout",
|
|
64
64
|
stopSignal: "SIGINT",
|
|
65
65
|
capabilities: {
|
|
66
66
|
resume: true,
|
package/src/adapters/claude.ts
CHANGED
|
@@ -79,7 +79,7 @@ export const claudeAdapter: AgentAdapter = {
|
|
|
79
79
|
binary: "claude",
|
|
80
80
|
testedVersions: ">=2.1.305 <2.2.0",
|
|
81
81
|
stability: "experimental",
|
|
82
|
-
liveChecked: "2.1.328 on 2026-11-25: analyze, implement, follow-up, cancellation, auth failure",
|
|
82
|
+
liveChecked: "2.1.328 on 2026-11-25: analyze, implement, follow-up, cancellation, timeout, auth failure",
|
|
83
83
|
stopSignal: "SIGINT",
|
|
84
84
|
capabilities: {
|
|
85
85
|
resume: true,
|
package/src/adapters/codex.ts
CHANGED
|
@@ -27,7 +27,7 @@ export const codexAdapter: AgentAdapter = {
|
|
|
27
27
|
binary: "codex",
|
|
28
28
|
testedVersions: ">=0.163.0 <0.200.0",
|
|
29
29
|
stability: "experimental",
|
|
30
|
-
liveChecked: "codex-cli 0.172.0 on 2026-11-25: analyze, implement, follow-up, cancellation, auth failure, capacity reconnects",
|
|
30
|
+
liveChecked: "codex-cli 0.172.0 on 2026-11-25: analyze, implement, follow-up, cancellation, timeout, auth failure, capacity reconnects",
|
|
31
31
|
stopSignal: "SIGINT",
|
|
32
32
|
capabilities: {
|
|
33
33
|
resume: true,
|
package/src/adapters/dsh.ts
CHANGED
|
@@ -103,7 +103,7 @@ export const dshAdapter: AgentAdapter = {
|
|
|
103
103
|
binary: "dsh",
|
|
104
104
|
testedVersions: ">=0.2.1-rc.3 <0.3.0-0",
|
|
105
105
|
stability: "experimental",
|
|
106
|
-
liveChecked: "0.2.2-rc.3 on 2026-11-25: analyze, implement, follow-up, cancellation, auth failure (route from a patchFile)",
|
|
106
|
+
liveChecked: "0.2.2-rc.3 on 2026-11-25: analyze, implement, follow-up, cancellation, timeout, auth failure (route from a patchFile)",
|
|
107
107
|
stopSignal: "SIGTERM",
|
|
108
108
|
optionsSchema,
|
|
109
109
|
capabilities: {
|
package/src/adapters/gemini.ts
CHANGED
|
@@ -33,6 +33,8 @@ const BLOCKED = /^Agent execution blocked:/;
|
|
|
33
33
|
const MAX_TURNS = /^Maximum session turns exceeded/;
|
|
34
34
|
/** Notices printed at every start; never the reason a run failed. */
|
|
35
35
|
const APPROVAL_OVERRIDDEN = /^Approval mode overridden to "?(\w+)"? because the current folder is not trusted/m;
|
|
36
|
+
/** 0.51.0 picks the "gateway" auth type when GOOGLE_GEMINI_BASE_URL is set, then its headless check rejects it. */
|
|
37
|
+
const GATEWAY_REJECTED = /^Invalid auth method selected\./m;
|
|
36
38
|
const STARTUP_NOTICE = /^(YOLO mode is enabled|Approval mode overridden|Loaded cached credentials|Data collection is disabled)/;
|
|
37
39
|
|
|
38
40
|
interface GeminiExtra {
|
|
@@ -56,7 +58,7 @@ export const geminiAdapter: AgentAdapter = {
|
|
|
56
58
|
binary: "gemini",
|
|
57
59
|
testedVersions: ">=0.51.0 <0.60.0",
|
|
58
60
|
stability: "experimental",
|
|
59
|
-
liveChecked: "0.51.0 on 2026-11-25: auth failure
|
|
61
|
+
liveChecked: "0.51.0 on 2026-11-25: analyze, implement, follow-up, cancellation, timeout, auth failure (trusted project, Gemini API key)",
|
|
60
62
|
stopSignal: "SIGTERM",
|
|
61
63
|
capabilities: {
|
|
62
64
|
resume: true,
|
|
@@ -83,8 +85,11 @@ export const geminiAdapter: AgentAdapter = {
|
|
|
83
85
|
return {
|
|
84
86
|
args,
|
|
85
87
|
cwd: req.workspace,
|
|
86
|
-
// GEMINI_SANDBOX overrides both argv and settings: no relaunch inside docker or podman.
|
|
87
|
-
|
|
88
|
+
// GEMINI_SANDBOX overrides both argv and settings: no relaunch inside docker or podman. NO_BROWSER: with
|
|
89
|
+
// Google login selected and no valid cached credentials, the CLI otherwise asks "Do you want to continue?
|
|
90
|
+
// [Y/n]" on stdin, takes the first line of the prompt as the answer and may open a browser; with it set, the
|
|
91
|
+
// run fails at once as an auth failure. Cached credentials are used before this setting is consulted.
|
|
92
|
+
env: { ...req.env, GEMINI_SANDBOX: "false", NO_BROWSER: "true" },
|
|
88
93
|
stdin: req.prompt,
|
|
89
94
|
files: [],
|
|
90
95
|
outputFiles: {},
|
|
@@ -152,10 +157,19 @@ export const geminiAdapter: AgentAdapter = {
|
|
|
152
157
|
|
|
153
158
|
finalize(raw, state) {
|
|
154
159
|
const outcome = finalizeRun(raw, state);
|
|
160
|
+
const warnings = [...(outcome.warnings ?? [])];
|
|
155
161
|
const overridden = APPROVAL_OVERRIDDEN.exec(raw.stderr);
|
|
156
|
-
if (
|
|
157
|
-
|
|
158
|
-
|
|
162
|
+
if (overridden) {
|
|
163
|
+
warnings.push(
|
|
164
|
+
`Gemini CLI ran in its "${overridden[1]}" approval mode because the folder is not trusted: tool calls that need approval are refused. Trusting the project in pi passes --skip-trust.`,
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
if (outcome.status === "auth_required" && GATEWAY_REJECTED.test(raw.stderr)) {
|
|
168
|
+
warnings.push(
|
|
169
|
+
'Gemini CLI picks the "gateway" auth type when GOOGLE_GEMINI_BASE_URL is set and rejects it in headless mode: set security.auth.selectedType in its settings.json, or set GOOGLE_GEMINI_BASE_URL to "" in agents.gemini.env.',
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
return warnings.length > 0 ? { ...outcome, warnings } : outcome;
|
|
159
173
|
},
|
|
160
174
|
};
|
|
161
175
|
|
package/src/adapters/grok.ts
CHANGED
|
@@ -60,7 +60,7 @@ export const grokAdapter: AgentAdapter = {
|
|
|
60
60
|
binary: "grok",
|
|
61
61
|
testedVersions: ">=1.0.62 <1.1.0",
|
|
62
62
|
stability: "experimental",
|
|
63
|
-
liveChecked: "1.0.77 on 2026-11-25: analyze, implement, follow-up, cancellation, auth failure",
|
|
63
|
+
liveChecked: "1.0.77 on 2026-11-25: analyze, implement, follow-up, cancellation, timeout, auth failure",
|
|
64
64
|
stopSignal: "SIGINT",
|
|
65
65
|
watchStderr(stderr) {
|
|
66
66
|
// Without a stored login, grok prints a sign-in URL or device code and waits for the browser.
|
package/src/adapters/omp.ts
CHANGED
|
@@ -40,7 +40,7 @@ export const ompAdapter: AgentAdapter = {
|
|
|
40
40
|
binary: "omp",
|
|
41
41
|
testedVersions: ">=18.11.1 <20.0.0",
|
|
42
42
|
stability: "experimental",
|
|
43
|
-
liveChecked: "19.1.1 on 2026-11-25: analyze, implement, follow-up, cancellation, auth failure",
|
|
43
|
+
liveChecked: "19.1.1 on 2026-11-25: analyze, implement, follow-up, cancellation, timeout, auth failure",
|
|
44
44
|
stopSignal: "SIGTERM",
|
|
45
45
|
capabilities: {
|
|
46
46
|
resume: true,
|
package/src/adapters/opencode.ts
CHANGED
|
@@ -53,7 +53,7 @@ export const opencodeAdapter: AgentAdapter = {
|
|
|
53
53
|
binary: "opencode",
|
|
54
54
|
testedVersions: ">=2.1.3 <2.4.0",
|
|
55
55
|
stability: "experimental",
|
|
56
|
-
liveChecked: "2.3.0 on 2026-11-25: analyze, implement, follow-up, cancellation",
|
|
56
|
+
liveChecked: "2.3.0 on 2026-11-25: analyze, implement, follow-up, cancellation, timeout",
|
|
57
57
|
stopSignal: "SIGINT",
|
|
58
58
|
capabilities: {
|
|
59
59
|
resume: true,
|
package/src/adapters/pi.ts
CHANGED
|
@@ -70,7 +70,7 @@ export const piAdapter: AgentAdapter = {
|
|
|
70
70
|
binary: "pi",
|
|
71
71
|
testedVersions: ">=1.4.0 <1.7.0",
|
|
72
72
|
stability: "experimental",
|
|
73
|
-
liveChecked: "1.6.1 on 2026-11-25: analyze, implement, follow-up, cancellation, auth failure",
|
|
73
|
+
liveChecked: "1.6.1 on 2026-11-25: analyze, implement, follow-up, cancellation, timeout, auth failure",
|
|
74
74
|
stopSignal: "SIGTERM",
|
|
75
75
|
trustFlag: "--approve",
|
|
76
76
|
capabilities: {
|
package/src/adapters/registry.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { agyAdapter } from "./agy.ts";
|
|
2
2
|
import { claudeAdapter } from "./claude.ts";
|
|
3
3
|
import { codexAdapter } from "./codex.ts";
|
|
4
|
-
import { cursorAdapter } from "./cursor.ts";
|
|
5
4
|
import { dshAdapter } from "./dsh.ts";
|
|
6
5
|
import { geminiAdapter } from "./gemini.ts";
|
|
7
6
|
import { grokAdapter } from "./grok.ts";
|
|
8
|
-
import { museAdapter } from "./muse.ts";
|
|
9
7
|
import { ompAdapter } from "./omp.ts";
|
|
10
8
|
import { opencodeAdapter } from "./opencode.ts";
|
|
11
9
|
import { piAdapter } from "./pi.ts";
|
|
@@ -20,10 +18,8 @@ export const BUILTIN_ADAPTERS: readonly AgentAdapter[] = [
|
|
|
20
18
|
ompAdapter,
|
|
21
19
|
agyAdapter,
|
|
22
20
|
grokAdapter,
|
|
23
|
-
museAdapter,
|
|
24
21
|
dshAdapter,
|
|
25
22
|
geminiAdapter,
|
|
26
|
-
cursorAdapter,
|
|
27
23
|
];
|
|
28
24
|
|
|
29
25
|
export function adapterMap(adapters: readonly AgentAdapter[] = BUILTIN_ADAPTERS): Map<string, AgentAdapter> {
|
package/src/config/schema.ts
CHANGED
|
@@ -28,7 +28,7 @@ export const AgentSettingsSchema = Type.Object(
|
|
|
28
28
|
|
|
29
29
|
export const ProfileSchema = Type.Object(
|
|
30
30
|
{
|
|
31
|
-
agent: NonEmpty("Agent id (codex, claude, opencode, pi, agy, grok,
|
|
31
|
+
agent: NonEmpty("Agent id (codex, claude, opencode, pi, agy, grok, dsh, gemini, omp)"),
|
|
32
32
|
model: Type.Optional(NonEmpty("Model id passed verbatim to the agent")),
|
|
33
33
|
effort: Type.Optional(NonEmpty("Effort or thinking level, validated against the adapter's levels")),
|
|
34
34
|
timeoutMinutes: Type.Optional(Int(1, 720, "Run timeout")),
|
|
@@ -81,7 +81,7 @@ export const ConfigFileSchema = Type.Object(
|
|
|
81
81
|
{
|
|
82
82
|
maxRounds: Type.Optional(Int(0, 5, "Rebuttal rounds after the opening")),
|
|
83
83
|
anonymize: Type.Optional(Type.Boolean()),
|
|
84
|
-
minParticipants: Type.Optional(Int(2,
|
|
84
|
+
minParticipants: Type.Optional(Int(2, 9, "Minimum debaters")),
|
|
85
85
|
},
|
|
86
86
|
{ additionalProperties: false },
|
|
87
87
|
),
|
package/src/engine/runner.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { spawn } from "node:child_process";
|
|
1
|
+
import { execFileSync, spawn } from "node:child_process";
|
|
2
2
|
import { createWriteStream } from "node:fs";
|
|
3
3
|
|
|
4
4
|
export interface ProcessSpec {
|
|
@@ -40,7 +40,9 @@ const CLOSE_WAIT_MS = 3_000;
|
|
|
40
40
|
* buffered and flushed at the end) and copied verbatim to `eventsPath`; stderr goes to `stderrPath`.
|
|
41
41
|
*
|
|
42
42
|
* Stop sequence (timeout or abort): `stopSignal` to the group, SIGTERM after `graceMs` when the first signal was not
|
|
43
|
-
* SIGTERM, SIGKILL after a further `graceMs`. Whatever is left in the group after the child exits is killed.
|
|
43
|
+
* SIGTERM, SIGKILL after a further `graceMs`. Whatever is left in the group after the child exits is killed. The stop
|
|
44
|
+
* sequence also reaches descendants that moved to a group of their own (Gemini CLI runs its shell tool under setsid):
|
|
45
|
+
* they are listed before each signal, because once the child is gone they are reparented and cannot be traced to it.
|
|
44
46
|
*/
|
|
45
47
|
export function runProcess(spec: ProcessSpec): Promise<ProcessOutcome> {
|
|
46
48
|
const startedAt = Date.now();
|
|
@@ -79,12 +81,17 @@ export function runProcess(spec: ProcessSpec): Promise<ProcessOutcome> {
|
|
|
79
81
|
stdio: [spec.stdin === undefined ? "ignore" : "pipe", "pipe", "pipe"],
|
|
80
82
|
});
|
|
81
83
|
|
|
84
|
+
// Groups of descendants that left the child's group, collected while stopping.
|
|
85
|
+
const foreignGroups = new Set<number>();
|
|
82
86
|
const killGroup = (signal: NodeJS.Signals) => {
|
|
83
87
|
if (child.pid === undefined) return;
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
+
if (stopping && !exited) for (const group of descendantGroups(child.pid)) foreignGroups.add(group);
|
|
89
|
+
for (const group of [child.pid, ...foreignGroups]) {
|
|
90
|
+
try {
|
|
91
|
+
process.kill(-group, signal);
|
|
92
|
+
} catch {
|
|
93
|
+
// ESRCH: the group is already gone.
|
|
94
|
+
}
|
|
88
95
|
}
|
|
89
96
|
};
|
|
90
97
|
|
|
@@ -201,3 +208,42 @@ export function runProcess(spec: ProcessSpec): Promise<ProcessOutcome> {
|
|
|
201
208
|
});
|
|
202
209
|
});
|
|
203
210
|
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Process groups of `root`'s descendants other than `root`'s own group, read from `ps`. Our own group and init's are
|
|
214
|
+
* never returned. Empty when `ps` is unavailable.
|
|
215
|
+
*/
|
|
216
|
+
export function descendantGroups(root: number): number[] {
|
|
217
|
+
let table: string;
|
|
218
|
+
try {
|
|
219
|
+
table = execFileSync("ps", ["-A", "-o", "pid=,ppid=,pgid="], { encoding: "utf8", timeout: 5_000 });
|
|
220
|
+
} catch {
|
|
221
|
+
return [];
|
|
222
|
+
}
|
|
223
|
+
const children = new Map<number, number[]>();
|
|
224
|
+
const groupOf = new Map<number, number>();
|
|
225
|
+
for (const line of table.split("\n")) {
|
|
226
|
+
const [pid, ppid, pgid] = line.trim().split(/\s+/).map(Number);
|
|
227
|
+
if (!pid || ppid === undefined || pgid === undefined || Number.isNaN(ppid) || Number.isNaN(pgid)) continue;
|
|
228
|
+
groupOf.set(pid, pgid);
|
|
229
|
+
const siblings = children.get(ppid);
|
|
230
|
+
if (siblings) siblings.push(pid);
|
|
231
|
+
else children.set(ppid, [pid]);
|
|
232
|
+
}
|
|
233
|
+
const excluded = new Set([root, 0, 1, groupOf.get(process.pid) ?? process.pid]);
|
|
234
|
+
const groups = new Set<number>();
|
|
235
|
+
const queue = [...(children.get(root) ?? [])];
|
|
236
|
+
const seen = new Set<number>(queue);
|
|
237
|
+
while (queue.length > 0) {
|
|
238
|
+
const pid = queue.shift() as number;
|
|
239
|
+
const group = groupOf.get(pid);
|
|
240
|
+
if (group !== undefined && !excluded.has(group)) groups.add(group);
|
|
241
|
+
for (const next of children.get(pid) ?? []) {
|
|
242
|
+
if (!seen.has(next)) {
|
|
243
|
+
seen.add(next);
|
|
244
|
+
queue.push(next);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
return [...groups];
|
|
249
|
+
}
|
package/src/adapters/cursor.ts
DELETED
|
@@ -1,242 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
clip,
|
|
3
|
-
detectByVersion,
|
|
4
|
-
getNumber,
|
|
5
|
-
getString,
|
|
6
|
-
isObject,
|
|
7
|
-
parseJsonLine,
|
|
8
|
-
recordDenied,
|
|
9
|
-
recordSession,
|
|
10
|
-
recordText,
|
|
11
|
-
recordUsage,
|
|
12
|
-
standardFinalize,
|
|
13
|
-
} from "./common.ts";
|
|
14
|
-
import type { AgentAdapter, AuthStatus, HostEnv, Invocation, NormalizedEvent, ParserState, RunRequest, RunStatus } from "./types.ts";
|
|
15
|
-
|
|
16
|
-
/** Startup refusals printed to stderr (exit 1, no stream event) that no other profile setting can fix. */
|
|
17
|
-
const STARTUP_FAILURES: Array<{ pattern: RegExp; status: RunStatus; code: string }> = [
|
|
18
|
-
{ pattern: /Workspace Trust Required/, status: "unavailable", code: "untrusted_workspace" },
|
|
19
|
-
{ pattern: /administrator has disabled headless Cursor CLI usage/, status: "unavailable", code: "headless_disabled" },
|
|
20
|
-
{ pattern: /Sandbox mode is enabled but not available/, status: "unavailable", code: "sandbox_unavailable" },
|
|
21
|
-
];
|
|
22
|
-
const ANSI = /\u001b\[[0-9;?]*[ -/]*[@-~]/g;
|
|
23
|
-
|
|
24
|
-
interface CursorExtra {
|
|
25
|
-
/** Assistant text since the last tool call. */
|
|
26
|
-
segment?: string;
|
|
27
|
-
sawResult?: boolean;
|
|
28
|
-
thinking?: string;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Cursor Agent (`cursor-agent -p --output-format stream-json`). Event schema: `src/headless.ts` of the
|
|
33
|
-
* 2026.11.22 bundle (system/init, user, assistant, thinking, tool_call started/completed, result, retry,
|
|
34
|
-
* connection). Failures are not stream events: the CLI prints the error to stderr and exits 1.
|
|
35
|
-
* The prompt goes on stdin: with no positional prompt and a non-TTY stdin, `build-prompt.ts` reads stdin to EOF.
|
|
36
|
-
* SIGTERM exits 143 after cleanup, without a result event.
|
|
37
|
-
*/
|
|
38
|
-
export const cursorAdapter: AgentAdapter = {
|
|
39
|
-
id: "cursor",
|
|
40
|
-
displayName: "Cursor Agent",
|
|
41
|
-
binary: "cursor-agent",
|
|
42
|
-
testedVersions: ">=2026.11.22-0 <2027.0.0-0",
|
|
43
|
-
stability: "experimental",
|
|
44
|
-
liveChecked: "2026.11.22 on 2026-11-25: auth failure only (not logged in)",
|
|
45
|
-
stopSignal: "SIGTERM",
|
|
46
|
-
capabilities: {
|
|
47
|
-
resume: true,
|
|
48
|
-
structuredOutput: false,
|
|
49
|
-
listModels: true,
|
|
50
|
-
reportsCost: false,
|
|
51
|
-
},
|
|
52
|
-
trustFlag: "--trust",
|
|
53
|
-
|
|
54
|
-
detect(env: HostEnv) {
|
|
55
|
-
return detectByVersion(env, this.testedVersions);
|
|
56
|
-
},
|
|
57
|
-
|
|
58
|
-
async checkAuth(env: HostEnv): Promise<AuthStatus> {
|
|
59
|
-
const result = await env.exec(env.bin, ["status", "--format", "json"], { timeoutMs: 20_000 });
|
|
60
|
-
if (result.error) return { state: "unknown", detail: result.error };
|
|
61
|
-
let status: unknown;
|
|
62
|
-
try {
|
|
63
|
-
status = JSON.parse(result.stdout) as unknown;
|
|
64
|
-
} catch {
|
|
65
|
-
return { state: "unknown", detail: clip(`${result.stdout}\n${result.stderr}`.replace(ANSI, ""), 120) || "no output" };
|
|
66
|
-
}
|
|
67
|
-
if (getString(status, "status") === "authenticated") return { state: "ok", detail: "logged in" };
|
|
68
|
-
// `status` reports only the stored login; a CURSOR_API_KEY in the environment authenticates runs too.
|
|
69
|
-
if (env.env.CURSOR_API_KEY) return { state: "unknown", detail: "no stored login; CURSOR_API_KEY is set" };
|
|
70
|
-
const message = getString(status, "message") ?? "not logged in";
|
|
71
|
-
if (getString(status, "status") === "error") return { state: "unknown", detail: clip(message, 120) };
|
|
72
|
-
return { state: "missing", detail: `${clip(message, 80)} (run \`cursor-agent login\` or set CURSOR_API_KEY)` };
|
|
73
|
-
},
|
|
74
|
-
|
|
75
|
-
async listModels(env: HostEnv): Promise<string[]> {
|
|
76
|
-
const result = await env.exec(env.bin, ["models"], { timeoutMs: 30_000 });
|
|
77
|
-
if (result.error) throw new Error(result.error);
|
|
78
|
-
if (result.code !== 0) {
|
|
79
|
-
throw new Error(`cursor-agent models exited with ${result.code}: ${clip(result.stderr.replace(ANSI, "") || result.stdout, 160)}`);
|
|
80
|
-
}
|
|
81
|
-
return parseModelList(result.stdout);
|
|
82
|
-
},
|
|
83
|
-
|
|
84
|
-
buildInvocation(req: RunRequest): Invocation {
|
|
85
|
-
// `--force` runs every command not explicitly denied and also skips the headless workspace-trust gate;
|
|
86
|
-
// `--sandbox disabled` keeps commands out of the sandbox a user or server default may enable.
|
|
87
|
-
const args = ["-p", "--output-format", "stream-json", "--workspace", req.workspace, "--force", "--sandbox", "disabled"];
|
|
88
|
-
// `--trust` persists the grant: it writes a `.workspace-trusted` marker in Cursor's per-project directory.
|
|
89
|
-
if (req.projectTrusted) args.push("--trust");
|
|
90
|
-
// Chats are stored per workspace directory, so a follow-up must run in the same workspace.
|
|
91
|
-
if (req.sessionId) args.push("--resume", req.sessionId);
|
|
92
|
-
if (req.model) args.push("--model", modelWithEffort(req.model, req.effort));
|
|
93
|
-
args.push(...(req.extraArgs ?? []));
|
|
94
|
-
return {
|
|
95
|
-
args,
|
|
96
|
-
cwd: req.workspace,
|
|
97
|
-
env: req.env,
|
|
98
|
-
stdin: req.prompt,
|
|
99
|
-
files: [],
|
|
100
|
-
outputFiles: {},
|
|
101
|
-
};
|
|
102
|
-
},
|
|
103
|
-
|
|
104
|
-
parseEvent(line: string, state: ParserState): NormalizedEvent[] {
|
|
105
|
-
const event = parseJsonLine(line);
|
|
106
|
-
if (!event) {
|
|
107
|
-
if (line.trim()) state.nonJsonLines++;
|
|
108
|
-
return [];
|
|
109
|
-
}
|
|
110
|
-
const extra = state.extra as CursorExtra;
|
|
111
|
-
switch (getString(event, "type")) {
|
|
112
|
-
case "system":
|
|
113
|
-
return getString(event, "subtype") === "init" ? recordSession(state, getString(event, "session_id")) : [];
|
|
114
|
-
case "assistant": {
|
|
115
|
-
const text = messageText(event.message);
|
|
116
|
-
extra.segment = (extra.segment ?? "") + text;
|
|
117
|
-
return recordText(state, text);
|
|
118
|
-
}
|
|
119
|
-
case "thinking": {
|
|
120
|
-
if (getString(event, "subtype") === "delta") {
|
|
121
|
-
extra.thinking = (extra.thinking ?? "") + (getString(event, "text") ?? "");
|
|
122
|
-
return [];
|
|
123
|
-
}
|
|
124
|
-
const thinking = extra.thinking ?? "";
|
|
125
|
-
extra.thinking = "";
|
|
126
|
-
return thinking.trim() ? [{ type: "activity", kind: "thinking", summary: clip(thinking) }] : [];
|
|
127
|
-
}
|
|
128
|
-
case "tool_call":
|
|
129
|
-
return parseToolCall(event, state, extra);
|
|
130
|
-
case "retry": {
|
|
131
|
-
if (getString(event, "subtype") !== "starting") return [];
|
|
132
|
-
const message = `retrying the model request (attempt ${getNumber(event, "attempt") ?? "?"})`;
|
|
133
|
-
state.warnings.push(message);
|
|
134
|
-
return [{ type: "warning", message }];
|
|
135
|
-
}
|
|
136
|
-
case "connection": {
|
|
137
|
-
if (getString(event, "subtype") !== "reconnecting") return [];
|
|
138
|
-
const message = `connection lost, reconnecting (attempt ${getNumber(event, "attempt") ?? "?"})`;
|
|
139
|
-
state.warnings.push(message);
|
|
140
|
-
return [{ type: "warning", message }];
|
|
141
|
-
}
|
|
142
|
-
case "result": {
|
|
143
|
-
extra.sawResult = true;
|
|
144
|
-
state.usage.turns = (state.usage.turns ?? 0) + 1;
|
|
145
|
-
const ok = getString(event, "subtype") === "success" && event.is_error !== true;
|
|
146
|
-
state.terminal = ok ? { ok: true } : { ok: false, reason: getString(event, "result") ?? "the run reported an error" };
|
|
147
|
-
// `result.result` concatenates every text delta of the run; the answer is the text after the last tool call.
|
|
148
|
-
state.finalText = extra.segment ?? getString(event, "result") ?? "";
|
|
149
|
-
if (!isObject(event.usage)) return [];
|
|
150
|
-
return [
|
|
151
|
-
recordUsage(
|
|
152
|
-
state,
|
|
153
|
-
{ inputTokens: getNumber(event, "usage", "inputTokens"), outputTokens: getNumber(event, "usage", "outputTokens") },
|
|
154
|
-
"replace",
|
|
155
|
-
),
|
|
156
|
-
];
|
|
157
|
-
}
|
|
158
|
-
default:
|
|
159
|
-
return [];
|
|
160
|
-
}
|
|
161
|
-
},
|
|
162
|
-
|
|
163
|
-
finalize(raw, state) {
|
|
164
|
-
const extra = state.extra as CursorExtra;
|
|
165
|
-
if (raw.spawnError) return standardFinalize(raw, state);
|
|
166
|
-
const stderr = raw.stderr.replace(ANSI, "");
|
|
167
|
-
if (!extra.sawResult) {
|
|
168
|
-
const lastLine = stderr.split(/\r?\n/).filter((line) => line.trim()).at(-1);
|
|
169
|
-
state.terminal = { ok: false, reason: lastLine ? clip(lastLine, 200) : "no result event: the CLI stopped before the run finished" };
|
|
170
|
-
}
|
|
171
|
-
const outcome = standardFinalize({ ...raw, stderr }, state, { finalText: state.finalText ?? "" });
|
|
172
|
-
if (outcome.status === "completed" || state.sessionId) return outcome;
|
|
173
|
-
for (const { pattern, status, code } of STARTUP_FAILURES) {
|
|
174
|
-
const line = stderr.split(/\r?\n/).find((candidate) => pattern.test(candidate));
|
|
175
|
-
if (line) return { ...outcome, status, reason: `${code}: ${clip(line.trim(), 200)}` };
|
|
176
|
-
}
|
|
177
|
-
return outcome;
|
|
178
|
-
},
|
|
179
|
-
};
|
|
180
|
-
|
|
181
|
-
function parseToolCall(event: Record<string, unknown>, state: ParserState, extra: CursorExtra): NormalizedEvent[] {
|
|
182
|
-
const call = toolCall(event.tool_call);
|
|
183
|
-
const subtype = getString(event, "subtype");
|
|
184
|
-
if (subtype === "started") {
|
|
185
|
-
extra.segment = "";
|
|
186
|
-
return [{ type: "activity", kind: "tool", summary: call.summary }];
|
|
187
|
-
}
|
|
188
|
-
if (subtype !== "completed") return [];
|
|
189
|
-
// `rejected` is the result of a call a deny rule, hook or the user refused; `permissionDenied` is an OS error.
|
|
190
|
-
const rejected = isObject(call.result) ? call.result.rejected : undefined;
|
|
191
|
-
if (!isObject(rejected)) return [];
|
|
192
|
-
const reason = getString(rejected, "reason");
|
|
193
|
-
return [recordDenied(state, `${clip(call.summary, 120)}${reason ? `: ${clip(reason, 120)}` : ""}`)];
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
/** The proto3 JSON form of an `agent.v1.ToolCall`: one `<name>ToolCall` key with `args` and, once completed, `result`. */
|
|
197
|
-
function toolCall(value: unknown): { summary: string; result: unknown } {
|
|
198
|
-
if (!isObject(value)) return { summary: "tool", result: undefined };
|
|
199
|
-
const key = Object.keys(value).find((name) => name.endsWith("ToolCall")) ?? Object.keys(value)[0];
|
|
200
|
-
if (!key) return { summary: "tool", result: undefined };
|
|
201
|
-
const body = value[key];
|
|
202
|
-
const name = key.replace(/ToolCall$/, "");
|
|
203
|
-
const args = isObject(body) ? body.args : undefined;
|
|
204
|
-
const command = getString(args, "command");
|
|
205
|
-
const path = getString(args, "path") ?? getString(args, "filePath");
|
|
206
|
-
const pattern = getString(args, "pattern") ?? getString(args, "globPattern") ?? getString(args, "query");
|
|
207
|
-
let summary = name;
|
|
208
|
-
if (command) summary = `$ ${clip(command, 90)}`;
|
|
209
|
-
else if (path) summary = `${name} ${clip(path, 90)}`;
|
|
210
|
-
else if (pattern) summary = `${name} ${clip(pattern, 80)}`;
|
|
211
|
-
return { summary, result: isObject(body) ? body.result : undefined };
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
function messageText(message: unknown): string {
|
|
215
|
-
const content = isObject(message) && Array.isArray(message.content) ? message.content : [];
|
|
216
|
-
return content.map((part) => (getString(part, "type") === "text" ? (getString(part, "text") ?? "") : "")).join("");
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
/**
|
|
220
|
-
* Parameterized models take overrides in brackets (`claude-opus-4-8[context=1m,effort=high]`); the effort
|
|
221
|
-
* is added there unless the model id already sets one. Without a model there is nothing to parameterize.
|
|
222
|
-
*/
|
|
223
|
-
function modelWithEffort(model: string, effort: string | undefined): string {
|
|
224
|
-
if (!effort || /[[,]\s*effort\s*=/.test(model)) return model;
|
|
225
|
-
if (model.endsWith("]") && model.includes("[")) {
|
|
226
|
-
const inner = model.slice(model.lastIndexOf("[") + 1, -1).trim();
|
|
227
|
-
return `${model.slice(0, model.lastIndexOf("[") + 1)}${inner ? `${inner},` : ""}effort=${effort}]`;
|
|
228
|
-
}
|
|
229
|
-
return `${model}[effort=${effort}]`;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
/** Parses `cursor-agent models`: a heading, one `<id> - <name> (current, default)` line per model, a tip. */
|
|
233
|
-
export function parseModelList(stdout: string): string[] {
|
|
234
|
-
const ids: string[] = [];
|
|
235
|
-
for (const raw of stdout.replace(ANSI, "").split(/\r?\n/)) {
|
|
236
|
-
const line = raw.trim();
|
|
237
|
-
if (!line || /^(Available models|No models available|Tip:)/.test(line)) continue;
|
|
238
|
-
const id = line.split(/\s+/)[0];
|
|
239
|
-
if (id) ids.push(id);
|
|
240
|
-
}
|
|
241
|
-
return ids;
|
|
242
|
-
}
|
package/src/adapters/muse.ts
DELETED
|
@@ -1,281 +0,0 @@
|
|
|
1
|
-
import { join } from "node:path";
|
|
2
|
-
import {
|
|
3
|
-
classifyFailureText,
|
|
4
|
-
clip,
|
|
5
|
-
detectByVersion,
|
|
6
|
-
getNumber,
|
|
7
|
-
getString,
|
|
8
|
-
isObject,
|
|
9
|
-
parseJsonAnswer,
|
|
10
|
-
parseJsonLine,
|
|
11
|
-
recordDenied,
|
|
12
|
-
recordSession,
|
|
13
|
-
recordUsage,
|
|
14
|
-
standardFinalize,
|
|
15
|
-
} from "./common.ts";
|
|
16
|
-
import type {
|
|
17
|
-
AdapterOutcome,
|
|
18
|
-
AgentAdapter,
|
|
19
|
-
HostEnv,
|
|
20
|
-
Invocation,
|
|
21
|
-
InvocationFile,
|
|
22
|
-
NormalizedEvent,
|
|
23
|
-
ParserState,
|
|
24
|
-
RawRunResult,
|
|
25
|
-
RunRequest,
|
|
26
|
-
RunStatus,
|
|
27
|
-
} from "./types.ts";
|
|
28
|
-
|
|
29
|
-
const EFFORT_LEVELS = ["none", "minimal", "low", "medium", "high", "xhigh", "max", "ultra"] as const;
|
|
30
|
-
|
|
31
|
-
/** The launcher updates the binary in the background at most once an hour; this keeps the installed build. */
|
|
32
|
-
const NO_AUTO_UPDATE = { MUSE_NO_AUTO_UPDATE: "1" };
|
|
33
|
-
|
|
34
|
-
/** Failure texts the shared classifier does not recognize, in status precedence order. */
|
|
35
|
-
const MUSE_FAILURE_PATTERNS: Array<{ status: RunStatus; code: string; pattern: RegExp }> = [
|
|
36
|
-
{ status: "unavailable", code: "unknown_profile", pattern: /profile does not exist/i },
|
|
37
|
-
{
|
|
38
|
-
status: "unavailable",
|
|
39
|
-
code: "unsupported_flag",
|
|
40
|
-
pattern: /cannot be used with|may only be provided once|cannot be combined with|unknown effort tier|unknown option/i,
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
status: "unavailable",
|
|
44
|
-
code: "model_unavailable",
|
|
45
|
-
pattern: /unsupported_provider_or_model|does not exist or you lack access|no matching model|model catalog has no visible models/i,
|
|
46
|
-
},
|
|
47
|
-
{
|
|
48
|
-
status: "auth_required",
|
|
49
|
-
code: "auth_required",
|
|
50
|
-
pattern: /API error 40[13]\b|muse login|run \/login|starting logged out|saved Meta credentials|no longer authorizes/i,
|
|
51
|
-
},
|
|
52
|
-
{ status: "quota", code: "quota", pattern: /API error 402\b|billing_error|no_allowance/i },
|
|
53
|
-
];
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Muse Code (`muse exec --json`). Stdout is JSONL; every record is an envelope with `stream`, `payload_type` and
|
|
57
|
-
* `payload`. The session id is `stream.id` of the records whose `stream.kind` is `session`. The first
|
|
58
|
-
* `run.lifecycle.started` is the assignment's run; only its `run.terminal.*` record decides the outcome (background
|
|
59
|
-
* wakes start further runs). Exit 0 only with a `completed` terminal; 1 for failed or cancelled runs, 2 for usage
|
|
60
|
-
* errors. Needs SIGTERM to stop.
|
|
61
|
-
*/
|
|
62
|
-
export const museAdapter: AgentAdapter = {
|
|
63
|
-
id: "muse",
|
|
64
|
-
displayName: "Muse Code",
|
|
65
|
-
binary: "muse",
|
|
66
|
-
testedVersions: ">=1.4.11 <1.5.0",
|
|
67
|
-
stability: "experimental",
|
|
68
|
-
liveChecked: "1.4.25 on 2026-11-25: auth failure and billing failure only (no working account)",
|
|
69
|
-
stopSignal: "SIGTERM",
|
|
70
|
-
trustFlag: "--trust-workspace",
|
|
71
|
-
capabilities: {
|
|
72
|
-
resume: true,
|
|
73
|
-
structuredOutput: true,
|
|
74
|
-
listModels: true,
|
|
75
|
-
effortLevels: EFFORT_LEVELS,
|
|
76
|
-
reportsCost: false,
|
|
77
|
-
},
|
|
78
|
-
|
|
79
|
-
detect(env: HostEnv) {
|
|
80
|
-
return detectByVersion(withoutAutoUpdate(env), this.testedVersions);
|
|
81
|
-
},
|
|
82
|
-
|
|
83
|
-
/** `muse exec --list-models` prints the provider's discoverable model ids and exits without a turn. */
|
|
84
|
-
async listModels(env: HostEnv): Promise<string[]> {
|
|
85
|
-
const result = await withoutAutoUpdate(env).exec(env.bin, ["exec", "--list-models"], { timeoutMs: 30_000 });
|
|
86
|
-
if (result.error) throw new Error(result.error);
|
|
87
|
-
if (result.code !== 0) {
|
|
88
|
-
throw new Error(`muse exec --list-models exited with ${result.code}: ${clip(`${result.stderr}\n${result.stdout}`, 200)}`);
|
|
89
|
-
}
|
|
90
|
-
const models = parseModelList(result.stdout);
|
|
91
|
-
if (models.length === 0) throw new Error(`no model ids in muse exec --list-models output: ${clip(result.stdout, 200)}`);
|
|
92
|
-
return models;
|
|
93
|
-
},
|
|
94
|
-
|
|
95
|
-
buildInvocation(req: RunRequest): Invocation {
|
|
96
|
-
const promptFile = join(req.runDir, "muse-prompt.md");
|
|
97
|
-
const files: InvocationFile[] = [{ path: promptFile, content: req.prompt }];
|
|
98
|
-
// A profile is always passed: without one the run uses the user's remembered or configured default.
|
|
99
|
-
const args = [
|
|
100
|
-
"exec", "--json",
|
|
101
|
-
"--workspace", req.workspace,
|
|
102
|
-
"--permission-profile", ":unrestricted",
|
|
103
|
-
"--disable-sandbox",
|
|
104
|
-
];
|
|
105
|
-
if (req.projectTrusted) args.push("--trust-workspace");
|
|
106
|
-
// A follow-up must use the same workspace: Muse refuses to resume a session in another one.
|
|
107
|
-
if (req.sessionId) args.push("--session-id", req.sessionId);
|
|
108
|
-
if (req.model) args.push("--model", req.model);
|
|
109
|
-
if (req.effort) args.push("--reasoning-effort", req.effort);
|
|
110
|
-
if (req.outputSchema) {
|
|
111
|
-
const schemaPath = join(req.runDir, "output-schema.json");
|
|
112
|
-
files.push({ path: schemaPath, content: JSON.stringify(req.outputSchema, null, 2) });
|
|
113
|
-
args.push("--output-schema", schemaPath);
|
|
114
|
-
}
|
|
115
|
-
args.push("--prompt-file", promptFile, ...(req.extraArgs ?? []));
|
|
116
|
-
return {
|
|
117
|
-
args,
|
|
118
|
-
cwd: req.workspace,
|
|
119
|
-
env: { ...req.env, ...NO_AUTO_UPDATE },
|
|
120
|
-
files,
|
|
121
|
-
};
|
|
122
|
-
},
|
|
123
|
-
|
|
124
|
-
parseEvent(line: string, state: ParserState): NormalizedEvent[] {
|
|
125
|
-
const record = parseJsonLine(line);
|
|
126
|
-
if (!record) {
|
|
127
|
-
if (line.trim()) state.nonJsonLines++;
|
|
128
|
-
return [];
|
|
129
|
-
}
|
|
130
|
-
const events: NormalizedEvent[] = [];
|
|
131
|
-
if (getString(record, "stream", "kind") === "session") {
|
|
132
|
-
events.push(...recordSession(state, getString(record, "stream", "id")));
|
|
133
|
-
}
|
|
134
|
-
const type = getString(record, "payload_type") ?? "";
|
|
135
|
-
const payload = isObject(record.payload) ? record.payload : {};
|
|
136
|
-
const runId = runStreamId(payload);
|
|
137
|
-
|
|
138
|
-
if (type === "run.lifecycle.started") {
|
|
139
|
-
if (state.extra.runId === undefined && runId) state.extra.runId = runId;
|
|
140
|
-
return events;
|
|
141
|
-
}
|
|
142
|
-
if (type.startsWith("run.terminal.")) {
|
|
143
|
-
if (!isAssignmentRun(state, runId)) return events;
|
|
144
|
-
const kind = type.slice("run.terminal.".length);
|
|
145
|
-
const reason = field(payload, "reason");
|
|
146
|
-
state.finalText = field(payload, "text") ?? "";
|
|
147
|
-
state.extra.terminalKind = kind;
|
|
148
|
-
if (kind === "completed") {
|
|
149
|
-
state.terminal = { ok: true };
|
|
150
|
-
} else {
|
|
151
|
-
const message = reason ?? `run ${kind}`;
|
|
152
|
-
state.terminal = { ok: false, reason: `${kind}: ${message}` };
|
|
153
|
-
state.errors.push(message);
|
|
154
|
-
}
|
|
155
|
-
return events;
|
|
156
|
-
}
|
|
157
|
-
switch (type) {
|
|
158
|
-
case "run.model.configured": {
|
|
159
|
-
const model = field(payload, "model_id");
|
|
160
|
-
if (model) state.extra.model = model;
|
|
161
|
-
break;
|
|
162
|
-
}
|
|
163
|
-
case "run.usage":
|
|
164
|
-
if (isAssignmentRun(state, runId, true)) events.push(...parseUsage(payload, state));
|
|
165
|
-
break;
|
|
166
|
-
case "task.lifecycle.side_effect_intent": {
|
|
167
|
-
const operation = field(payload, "operation") ?? "tool";
|
|
168
|
-
const decision = field(payload, "policy_decision");
|
|
169
|
-
if (decision?.startsWith("deny")) {
|
|
170
|
-
state.extra.deniedOperation = operation;
|
|
171
|
-
events.push(recordDenied(state, clip(`${operation}: ${decision}`, 200)));
|
|
172
|
-
} else {
|
|
173
|
-
events.push({ type: "activity", kind: "tool", summary: clip(operation, 100) });
|
|
174
|
-
}
|
|
175
|
-
break;
|
|
176
|
-
}
|
|
177
|
-
case "task.lifecycle.rejected": {
|
|
178
|
-
const reason = field(payload, "reason") ?? "rejected";
|
|
179
|
-
events.push(recordDenied(state, clip(`${taskLabel(payload)}: ${reason}`, 200)));
|
|
180
|
-
break;
|
|
181
|
-
}
|
|
182
|
-
case "task.lifecycle.failed": {
|
|
183
|
-
// Failed tasks of background reminder agents do not fail the run, so they are warnings, not errors.
|
|
184
|
-
const reason = field(payload, "reason") ?? "task failed";
|
|
185
|
-
const kind = field(payload, "failure_kind");
|
|
186
|
-
if (kind && /^policy_?denied$/i.test(kind)) {
|
|
187
|
-
// The denied intent of the same operation was already recorded.
|
|
188
|
-
const label = taskLabel(payload);
|
|
189
|
-
if (state.extra.deniedOperation === label) state.extra.deniedOperation = undefined;
|
|
190
|
-
else events.push(recordDenied(state, clip(`${label}: ${reason}`, 200)));
|
|
191
|
-
} else {
|
|
192
|
-
const message = `task failed: ${reason}`;
|
|
193
|
-
state.warnings.push(message);
|
|
194
|
-
events.push({ type: "warning", message: clip(message, 200) });
|
|
195
|
-
}
|
|
196
|
-
break;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
return events;
|
|
200
|
-
},
|
|
201
|
-
|
|
202
|
-
finalize(raw: RawRunResult, state: ParserState): AdapterOutcome {
|
|
203
|
-
let effective = state;
|
|
204
|
-
if (!state.terminal && raw.exitCode === 0) {
|
|
205
|
-
effective = { ...state, terminal: { ok: false, reason: "no terminal record for the assignment run" } };
|
|
206
|
-
}
|
|
207
|
-
let outcome = standardFinalize(raw, effective);
|
|
208
|
-
outcome = refineFailure(outcome, [...state.errors, effective.terminal?.reason ?? "", raw.stderr].join("\n"));
|
|
209
|
-
if (outcome.status === "failed" && raw.exitCode === 2 && state.extra.runId === undefined) {
|
|
210
|
-
// Usage errors (an unknown or conflicting flag) exit 2 before any run starts.
|
|
211
|
-
const line = raw.stderr.split(/\r?\n/).find((candidate) => candidate.trim());
|
|
212
|
-
outcome = { ...outcome, status: "unavailable", reason: `usage_error: ${clip(line ?? "exit code 2", 200)}` };
|
|
213
|
-
}
|
|
214
|
-
const structured = parseJsonAnswer(outcome.finalText);
|
|
215
|
-
if (structured !== undefined) outcome.structuredOutput = structured;
|
|
216
|
-
return outcome;
|
|
217
|
-
},
|
|
218
|
-
};
|
|
219
|
-
|
|
220
|
-
function withoutAutoUpdate(env: HostEnv): HostEnv {
|
|
221
|
-
return {
|
|
222
|
-
...env,
|
|
223
|
-
exec: (command, args, options) => env.exec(command, args, { ...options, env: { ...options?.env, ...NO_AUTO_UPDATE } }),
|
|
224
|
-
};
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
/** Payload fields sit at the top level, or under `event` or `record` in some record types. */
|
|
228
|
-
function field(payload: Record<string, unknown>, key: string): string | undefined {
|
|
229
|
-
return getString(payload, key) ?? getString(payload, "event", key) ?? getString(payload, "record", key);
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
function runStreamId(payload: Record<string, unknown>): string | undefined {
|
|
233
|
-
return (
|
|
234
|
-
getString(payload, "run_stream", "id") ??
|
|
235
|
-
getString(payload, "event", "run_stream", "id") ??
|
|
236
|
-
getString(payload, "record", "run_stream", "id")
|
|
237
|
-
);
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
/** Whether a record belongs to the assignment's run. Records without a run id count only when `lenient`. */
|
|
241
|
-
function isAssignmentRun(state: ParserState, runId: string | undefined, lenient = false): boolean {
|
|
242
|
-
const assignment = state.extra.runId as string | undefined;
|
|
243
|
-
if (!runId || !assignment) return lenient || state.extra.terminalKind === undefined;
|
|
244
|
-
return runId === assignment;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
function taskLabel(payload: Record<string, unknown>): string {
|
|
248
|
-
return field(payload, "operation") ?? field(payload, "task_kind") ?? field(payload, "tool_name") ?? "task";
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
/** `run.usage` carries `input_tokens`, `cached_tokens` and `output_tokens` for the run so far. */
|
|
252
|
-
function parseUsage(payload: Record<string, unknown>, state: ParserState): NormalizedEvent[] {
|
|
253
|
-
const source = isObject(payload.record) ? payload.record : payload;
|
|
254
|
-
const input = getNumber(source, "input_tokens") ?? getNumber(source, "usage", "input_tokens");
|
|
255
|
-
const output = getNumber(source, "output_tokens") ?? getNumber(source, "usage", "output_tokens");
|
|
256
|
-
if (input === undefined && output === undefined) return [];
|
|
257
|
-
return [recordUsage(state, { inputTokens: input, outputTokens: output }, "replace")];
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
/** Second classification pass for failures the shared patterns left as `failed` (or as an answerless denial). */
|
|
261
|
-
function refineFailure(outcome: AdapterOutcome, text: string): AdapterOutcome {
|
|
262
|
-
const unclassified = outcome.status === "failed" || (outcome.status === "denied" && !outcome.finalText);
|
|
263
|
-
if (!unclassified || !text.trim()) return outcome;
|
|
264
|
-
const lines = text.split(/\r?\n/).filter((line) => line.trim());
|
|
265
|
-
for (const { status, code, pattern } of MUSE_FAILURE_PATTERNS) {
|
|
266
|
-
const line = lines.find((candidate) => pattern.test(candidate));
|
|
267
|
-
if (line) return { ...outcome, status, reason: `${code}: ${clip(line, 200)}` };
|
|
268
|
-
}
|
|
269
|
-
const cls = classifyFailureText(text);
|
|
270
|
-
return cls ? { ...outcome, status: cls.status, reason: `${cls.code}: ${cls.line}` } : outcome;
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
/** One model id per line, optionally bulleted or followed by a parenthesized note; anything else is ignored. */
|
|
274
|
-
function parseModelList(stdout: string): string[] {
|
|
275
|
-
const models: string[] = [];
|
|
276
|
-
for (const line of stdout.split(/\r?\n/)) {
|
|
277
|
-
const match = line.match(/^\s*(?:[*-]\s+)?([A-Za-z0-9][\w.:/@-]*)\s*(?:\([^)]*\))?\s*$/);
|
|
278
|
-
if (match) models.push(match[1]);
|
|
279
|
-
}
|
|
280
|
-
return [...new Set(models)];
|
|
281
|
-
}
|