@0perator/operator 0.2.0 → 0.2.2-next.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/README.md +5 -4
- package/dist/auth/byo.js +1 -1
- package/dist/auth/commands.js +15 -5
- package/dist/auth/identity.js +1 -0
- package/dist/auth/staff.js +55 -0
- package/dist/autonomy/agent-cli.js +1 -1
- package/dist/autonomy/delegate-mode.js +2 -2
- package/dist/autonomy/delegate.js +41 -14
- package/dist/autonomy/headless.js +37 -10
- package/dist/autonomy/index.js +2 -4
- package/dist/autonomy/pr-isolation.js +92 -0
- package/dist/autonomy/pr-preflight.js +474 -0
- package/dist/autonomy/session-factory.js +13 -12
- package/dist/autonomy/subagent-model.js +17 -7
- package/dist/background/capacity.js +136 -0
- package/dist/background/evidence.js +42 -0
- package/dist/background/index.js +311 -44
- package/dist/background/lane-phase.js +60 -0
- package/dist/background/lane-summary.js +151 -0
- package/dist/background/notices.js +12 -3
- package/dist/background/synthesis.js +25 -0
- package/dist/browser/capture.js +505 -0
- package/dist/browser/engine.js +4 -3
- package/dist/browser/page-capture.js +167 -0
- package/dist/browser/png.js +116 -0
- package/dist/browser/visual-compare.js +229 -0
- package/dist/bus/beam-drop.js +55 -0
- package/dist/bus/inbox.js +157 -7
- package/dist/cli.js +316 -120
- package/dist/config/features.js +3 -3
- package/dist/config/managed.js +40 -1
- package/dist/config/persona.js +80 -29
- package/dist/config/product-hosts.js +2 -0
- package/dist/config/settings.js +289 -31
- package/dist/config/skills-index.js +37 -14
- package/dist/config/staff-prompt.js +12 -0
- package/dist/engine/agent.js +52 -41
- package/dist/engine/aurora.js +54 -13
- package/dist/engine/batch-scheduler.js +4 -13
- package/dist/engine/compaction.js +1 -1
- package/dist/engine/continuation.js +66 -32
- package/dist/engine/decision-points.js +2 -3
- package/dist/engine/fanout.js +16 -0
- package/dist/engine/identity.js +42 -0
- package/dist/engine/loop-guard.js +26 -83
- package/dist/engine/messages.js +2 -2
- package/dist/engine/moa.js +23 -1
- package/dist/engine/native-vision-node.js +72 -0
- package/dist/engine/native-vision.js +103 -0
- package/dist/engine/net-error.js +15 -0
- package/dist/engine/rolling-summary.js +142 -93
- package/dist/engine/verify-gate.js +37 -7
- package/dist/engine/waterfall.js +33 -0
- package/dist/gateway-cli.js +24 -4
- package/dist/memory/live-progress.js +4 -5
- package/dist/memory/session-index.js +3 -3
- package/dist/moa/codeact-lane.js +98 -0
- package/dist/moa/codeact-sandbox.js +409 -0
- package/dist/moa/codeact.js +140 -0
- package/dist/permissions/artifact-visibility.js +10 -0
- package/dist/permissions/index.js +2 -1
- package/dist/permissions/policy.js +9 -2
- package/dist/permissions/tier.js +13 -3
- package/dist/products/craft.js +92 -3
- package/dist/products/temple.js +20 -1
- package/dist/products/voice.js +112 -0
- package/dist/remote/grants.js +119 -0
- package/dist/remote/host.js +33 -5
- package/dist/router/free-models.js +5 -9
- package/dist/router/models.js +80 -26
- package/dist/router/provider-models.js +78 -0
- package/dist/router/router.js +15 -3
- package/dist/selfimprove/index.js +8 -6
- package/dist/selfimprove/lessons.js +23 -0
- package/dist/services/preflight.js +35 -91
- package/dist/session.js +316 -125
- package/dist/skills/catalogue.js +5 -2
- package/dist/skills/finder.js +4 -4
- package/dist/skills/install-guard.js +68 -0
- package/dist/skills/install.js +67 -0
- package/dist/toolchain/manifest.json +13 -13
- package/dist/tools/background-result.js +1 -1
- package/dist/tools/beam.js +246 -0
- package/dist/tools/classes.js +103 -0
- package/dist/tools/contract.js +1 -1
- package/dist/tools/craft.js +36 -2
- package/dist/tools/deferred.js +7 -3
- package/dist/tools/doc-text.js +1 -1
- package/dist/tools/executor.js +25 -15
- package/dist/tools/generation-gateway.js +94 -0
- package/dist/tools/registry.js +135 -158
- package/dist/tools/sandbox.js +6 -6
- package/dist/ui/App.js +17 -6
- package/dist/ui/ApprovalPrompt.js +1 -1
- package/dist/ui/BgPanel.js +15 -10
- package/dist/ui/Composer.js +44 -2
- package/dist/ui/Header.js +1 -6
- package/dist/ui/StatusRule.js +20 -8
- package/dist/ui/ToolStep.js +3 -3
- package/dist/ui/Transcript.js +41 -14
- package/dist/ui/batchLine.js +4 -4
- package/dist/ui/editdiff.js +2 -4
- package/dist/ui/format.js +4 -20
- package/dist/ui/liveTools.js +3 -3
- package/dist/ui/modelPicker.js +10 -6
- package/dist/ui/opsMode.js +20 -0
- package/dist/ui/phase.js +4 -2
- package/dist/ui/slashCommands.js +1 -0
- package/dist/ui/types.js +0 -2
- package/dist/ui/voice.js +185 -0
- package/dist/update-check.js +17 -6
- package/dist/update.js +1 -2
- package/dist/util/audio-io.js +82 -0
- package/dist/util/slash.js +2 -2
- package/dist/vision/pairs.js +239 -0
- package/package.json +1 -1
- package/dist/tools/mutating.js +0 -15
package/README.md
CHANGED
|
@@ -74,16 +74,17 @@ operator --resume # reload the last conversation in this dir
|
|
|
74
74
|
Dev: `npm install && npm run dev`, or `scripts/operator-dev.sh` installed as `operator-dev` for unreleased `develop`.
|
|
75
75
|
|
|
76
76
|
### Headless — `operator run`
|
|
77
|
-
One task, no terminal UI, for SSH, CI, cron and other agents (the shape of `codex exec`
|
|
77
|
+
One task, no terminal UI, for SSH, CI, cron and other agents (the shape of `codex exec`):
|
|
78
78
|
```
|
|
79
79
|
operator run "fix the failing test" # progress on stderr, the answer on stdout
|
|
80
80
|
echo "summarise CHANGELOG.md" | operator run - # task from stdin (also when stdin is a pipe and no task is given)
|
|
81
|
-
operator run --output json "…" # one result object: {type, ok, exitCode, result, rounds, toolCalls, durationMs}
|
|
81
|
+
operator run --output json "…" # one result object: {type, ok, exitCode, result, rounds, toolCalls, durationMs, stopKind?}
|
|
82
82
|
operator run --output stream-json "…" # one JSON event per line (= --json)
|
|
83
83
|
```
|
|
84
84
|
Flags: `--model ID`, `--permissions gated|audit|bypass` (headless has no one to approve, so `gated` denies),
|
|
85
85
|
`--cwd DIR`, `--max-turns N`, `--max-seconds S`, `--loop`, `--log FILE`, `--keep-awake`.
|
|
86
|
-
Exit codes: 0 done, 1 the task failed
|
|
86
|
+
Exit codes: 0 done, 1 the task failed or the engine stopped the turn (`stopKind` in the json: `repetition`, `rounds`,
|
|
87
|
+
`unanswered`, …), 2 bad command line, 130 interrupted.
|
|
87
88
|
Sign-in without a keychain (SSH, CI): export the token as `OPERATOR_TOKEN`.
|
|
88
89
|
|
|
89
90
|
### Environment
|
|
@@ -94,7 +95,7 @@ Variables use the `OPERATOR_` prefix: `OPERATOR_MODEL`, `OPERATOR_PERMISSIONS`,
|
|
|
94
95
|
runtime's home (`~/.operator`). Fleet defaults belong in settings.json `env` / `envFiles`.
|
|
95
96
|
|
|
96
97
|
### Local model runtime
|
|
97
|
-
`operator gateway start [-d] | stop | status | health | logs` (was `operator-gw`, which now forwards here).
|
|
98
|
+
`operator gateway start [-d] [--force] | stop | status | health | logs` (`start` refuses without `--force` while its model, Aurora, is retired) (was `operator-gw`, which now forwards here).
|
|
98
99
|
|
|
99
100
|
## Knowledge base
|
|
100
101
|
|
package/dist/auth/byo.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// the gateway). Distinct keychain SERVICE from the operator token ("axe-operator") so a vendor key can
|
|
5
5
|
// never be read/mistaken for the operator bearer by any client — the separation IS the leak guard.
|
|
6
6
|
// Env override per account: KODE_BYO_<ACCOUNT> (uppercase, non-alnum → "_") for CI/headless. The vendor's own
|
|
7
|
-
// variable (ByoPreset.envAlias: ANTHROPIC_API_KEY,
|
|
7
|
+
// variable (ByoPreset.envAlias: ANTHROPIC_API_KEY, OPENAI_API_KEY, …) is the LAST resort, after the stored key, and
|
|
8
8
|
// only for a request going to that preset's own host — an ambient org key must never shadow a key the owner pasted,
|
|
9
9
|
// nor ride to a proxy row that shares the account name. KODE_NO_KEYCHAIN=1 forces the 0600 JSON file (same
|
|
10
10
|
// convention as auth/store.ts).
|
package/dist/auth/commands.js
CHANGED
|
@@ -22,7 +22,7 @@ import { listByoAccounts, hasByoToken, deleteByoToken, setByoTokenInteractive }
|
|
|
22
22
|
import { ghInstalled, ghAuthStatus, ghLogin, ghSwitch } from "./gh-account.js";
|
|
23
23
|
import { auditControl } from "../telemetry/lifecycle.js";
|
|
24
24
|
import { loadSettings, saveSettings } from "../config/settings.js";
|
|
25
|
-
import { BYO_PRESETS } from "../router/models.js";
|
|
25
|
+
import { BYO_PRESETS, replacedProvider } from "../router/models.js";
|
|
26
26
|
// Credential-lifecycle audit (inert unless the seat is audited — see telemetry/lifecycle.ts). Module-level
|
|
27
27
|
// because every login path ends in the same few exits; runAuth sets it once from the CLI's settings.
|
|
28
28
|
let auditCfg;
|
|
@@ -207,7 +207,13 @@ async function byoModel(rest) {
|
|
|
207
207
|
return 0;
|
|
208
208
|
}
|
|
209
209
|
const presetName = flagValue(rest, "--preset");
|
|
210
|
-
const
|
|
210
|
+
const old = replacedProvider(presetName);
|
|
211
|
+
const preset = presetName ? BYO_PRESETS[old?.by ?? presetName] : undefined;
|
|
212
|
+
if (preset?.signIn) {
|
|
213
|
+
// A sign-in provider has no key to paste and no row to register: the Operator sign-in is its key, /model lists its rows.
|
|
214
|
+
console.log(`${old ? `${old.label} is no longer offered — ` : ""}${preset.label} uses your Operator sign-in (operator auth login); /model lists its models`);
|
|
215
|
+
return 0;
|
|
216
|
+
}
|
|
211
217
|
if (presetName && !preset) {
|
|
212
218
|
console.error(`unknown preset "${presetName}" — choices: ${Object.keys(BYO_PRESETS).join(", ")}`);
|
|
213
219
|
return 1;
|
|
@@ -226,9 +232,13 @@ async function byoModel(rest) {
|
|
|
226
232
|
return 1;
|
|
227
233
|
}
|
|
228
234
|
const profile = { id, label: label ?? id, kind: "single", desc: `BYO ${label ?? id} — your key`, endpoint: base, model, ctx, byo: account, transport: dialect, ...(preset?.chatPath && base === preset.endpoint ? { chatPath: preset.chatPath } : {}), ...(preset?.maxOutput && model === preset.model ? { maxOutput: preset.maxOutput } : {}) };
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
235
|
+
try {
|
|
236
|
+
saveSettings((cur) => ({ models: [...(Array.isArray(cur.models) ? cur.models : []).filter((m) => m.id !== id), profile] }));
|
|
237
|
+
}
|
|
238
|
+
catch (e) {
|
|
239
|
+
console.error(`✗ model "${id}" not registered: ${e instanceof Error ? e.message : String(e)}`);
|
|
240
|
+
return 1;
|
|
241
|
+
}
|
|
232
242
|
console.log(`✓ model "${id}" registered (${model} @ ${base}, key account "${account}")`);
|
|
233
243
|
if (setByoTokenInteractive(account)) {
|
|
234
244
|
console.log(`✓ ${account} key stored — /model now offers "${id}"`);
|
package/dist/auth/identity.js
CHANGED
|
@@ -31,6 +31,7 @@ export function claimsFromVerify(account, raw = {}) {
|
|
|
31
31
|
roles: [...strList(pick("roles")), ...strList(pick("role"))],
|
|
32
32
|
groups: strList(pick("groups")),
|
|
33
33
|
scopes: strList(pick("scope")),
|
|
34
|
+
...(typeof pick("tier") === "string" ? { accountTier: pick("tier") } : {}),
|
|
34
35
|
};
|
|
35
36
|
}
|
|
36
37
|
/** Claims -> a tier ceiling (or undefined = the claims say nothing about tiers). Every source that is present
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/** Groups AuthGate puts in the verify response: every accepted member of its staff org, and its owners and admins. */
|
|
2
|
+
export const STAFF_GROUP = "axe-staff";
|
|
3
|
+
export const EXEC_GROUP = "axe-exec";
|
|
4
|
+
const RANK = { external: 0, op: 1, axe: 2 };
|
|
5
|
+
/** True when `type` is at least `min` (an "axe" user passes every "op" check). */
|
|
6
|
+
export const userTypeAtLeast = (type, min) => RANK[type] >= RANK[min];
|
|
7
|
+
/** "axe" for a founder account or the exec group, "op" for the staff group or role, otherwise "external". A founder
|
|
8
|
+
* is an owner identity AuthGate already marks today, before the groups are emitted. */
|
|
9
|
+
export function userTypeFromClaims(c) {
|
|
10
|
+
if (!c)
|
|
11
|
+
return "external";
|
|
12
|
+
if (c.accountTier === "founder" || c.groups.includes(EXEC_GROUP) || c.roles.includes("exec"))
|
|
13
|
+
return "axe";
|
|
14
|
+
if (c.groups.includes(STAFF_GROUP) || c.roles.includes("staff"))
|
|
15
|
+
return "op";
|
|
16
|
+
return "external";
|
|
17
|
+
}
|
|
18
|
+
let resolved = "external";
|
|
19
|
+
let inflight = null;
|
|
20
|
+
let forToken = "";
|
|
21
|
+
/** The user type resolved so far this process. "external" until a verification has said otherwise. */
|
|
22
|
+
export const userType = () => resolved;
|
|
23
|
+
/** Staff of any rank: "op" or "axe". */
|
|
24
|
+
export const isOp = () => userTypeAtLeast(resolved, "op");
|
|
25
|
+
export const isAxe = () => resolved === "axe";
|
|
26
|
+
/** Verify the signed-in token once per token and remember the answer in memory only. Concurrent callers share one
|
|
27
|
+
* lookup; a different token re-resolves; a failure leaves the answer "external". Safe to call and not await. */
|
|
28
|
+
export function resolveUserType(token, deps = {}) {
|
|
29
|
+
if (!token) {
|
|
30
|
+
resolved = "external";
|
|
31
|
+
forToken = "";
|
|
32
|
+
return Promise.resolve("external");
|
|
33
|
+
}
|
|
34
|
+
if (inflight && forToken === token)
|
|
35
|
+
return inflight;
|
|
36
|
+
if (!inflight && forToken === token)
|
|
37
|
+
return Promise.resolve(resolved);
|
|
38
|
+
forToken = token;
|
|
39
|
+
inflight = (async () => {
|
|
40
|
+
try {
|
|
41
|
+
const verify = deps.verify ?? (await import("./client.js")).verifyTokenDetailed;
|
|
42
|
+
const toClaims = deps.claims ?? (await import("./identity.js")).claimsFromVerify;
|
|
43
|
+
const r = await verify(token, deps.timeoutMs ?? 3000);
|
|
44
|
+
resolved = r.state === "ok" ? userTypeFromClaims(toClaims(r.account, (r.raw ?? {}))) : "external";
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
resolved = "external";
|
|
48
|
+
}
|
|
49
|
+
inflight = null;
|
|
50
|
+
return resolved;
|
|
51
|
+
})();
|
|
52
|
+
return inflight;
|
|
53
|
+
}
|
|
54
|
+
/** Test seam: forget everything. */
|
|
55
|
+
export function resetUserType() { resolved = "external"; inflight = null; forToken = ""; }
|
|
@@ -146,7 +146,7 @@ async function defaultResolveBin(bin) {
|
|
|
146
146
|
}
|
|
147
147
|
/** The SYNCHRONOUS bin resolver powering the tool description at module load (no I/O awaited there, same
|
|
148
148
|
* idiom as registry.ownedMcpNote): uses process.getBuiltinModule so it's a no-op in the neutral bundle. */
|
|
149
|
-
function resolveBinSync(bin) {
|
|
149
|
+
export function resolveBinSync(bin) {
|
|
150
150
|
try {
|
|
151
151
|
const proc = globalThis.process;
|
|
152
152
|
const fs = proc?.getBuiltinModule?.("node:fs");
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { SHELL_ANY } from "../tools/classes.js";
|
|
1
2
|
const env = () => globalThis.process?.env ?? {};
|
|
2
3
|
let live = {};
|
|
3
4
|
/** The guard settings every session in this process reads per call: set at startup from settings.delegate and again
|
|
@@ -19,7 +20,6 @@ const DEPLOY = new RegExp("\\b(systemctl\\s+(restart|start|stop)|launchctl\\s+(k
|
|
|
19
20
|
"|docker\\s+compose\\s+up|docker-compose\\s+up|docker\\s+stack\\s+deploy" +
|
|
20
21
|
"|wrangler\\s+(deploy|publish)|fly(ctl)?\\s+deploy|kamal\\s+deploy|cap\\s+\\w+\\s+deploy|vercel\\s+(--prod|deploy\\s+--prod)" +
|
|
21
22
|
"|npm\\s+publish|cargo\\s+publish|twine\\s+upload)\\b", "i");
|
|
22
|
-
const SHELL_TOOLS = new Set(["bash", "shell_exec", "shell_background", "shell_task_start"]);
|
|
23
23
|
const WRITE_TOOLS = { file_write: "path", file_edit: "path", file_create: "path", file_delete: "path", download_file: "dest" };
|
|
24
24
|
function expand(p, e) {
|
|
25
25
|
return p === "~" || p.startsWith("~/") ? `${e.HOME ?? ""}${p.slice(1)}` : p;
|
|
@@ -67,7 +67,7 @@ export function delegateGuardReason(name, args, ctx) {
|
|
|
67
67
|
if (!delegateGuardOn(e, s))
|
|
68
68
|
return null;
|
|
69
69
|
const pushOk = !!s.allowPush;
|
|
70
|
-
if (
|
|
70
|
+
if (SHELL_ANY.has(name)) {
|
|
71
71
|
const cmd = String(args.command ?? "");
|
|
72
72
|
if (PUSH.test(cmd) && !pushOk)
|
|
73
73
|
return "git push is blocked — set delegate.allowPush (or `/delegate push on`) to let this task push";
|
|
@@ -12,8 +12,12 @@
|
|
|
12
12
|
import { modelRegistry, selectModel, endpointBase } from "../router/models.js";
|
|
13
13
|
import { MemoryStore } from "../memory/index.js";
|
|
14
14
|
import { delegateBrief, inferType, roleForBrief, SUBAGENT_ROLES } from "../engine/grandmaster.js";
|
|
15
|
+
import { engineEnded } from "../engine/continuation.js";
|
|
15
16
|
import { suggestSkillsBlock } from "./subagent-amplifier.js";
|
|
16
17
|
import { subagentModelFor, DEFAULT_SUBAGENT_MODEL } from "./subagent-model.js";
|
|
18
|
+
import { codeActConfig, codeActEligibility, codeActReport, pickLanguage } from "../moa/codeact.js";
|
|
19
|
+
import { CODEACT_STEP_TOOLS, codeActBrief, codeActStepFromArgs, codeActTraceLine, makeCodeActTool } from "../moa/codeact-lane.js";
|
|
20
|
+
import { FILE_WRITE, LOOKUP, SHELL_ANY } from "../tools/classes.js";
|
|
17
21
|
const nodeImport = (m) => import(/* @vite-ignore */ m);
|
|
18
22
|
/** Model a delegation lands on when the planner names none — the fast local tier. */
|
|
19
23
|
export const DEFAULT_DELEGATE_MODEL = DEFAULT_SUBAGENT_MODEL; // kept for importers; the one default lives in subagent-model.ts
|
|
@@ -116,11 +120,6 @@ async function briefFor(task, settings) {
|
|
|
116
120
|
const block = await suggestSkillsBlock(roleTitle, task, { signal: AbortSignal.timeout(4000) });
|
|
117
121
|
return block ? `${base}\n\n${block}` : base;
|
|
118
122
|
}
|
|
119
|
-
/** The turn loop hands back its OWN "no answer" notes as ordinary `content`: `[stopped …]` / `[paused …]` (the
|
|
120
|
-
* flywheel-prefix contract, _ai-docs/conventions) and the two parenthesized empty-reply notes in engine/agent.ts.
|
|
121
|
-
* Returned verbatim they would reach the planner AS the sub-agent's answer — seen live: Scout on a tool task
|
|
122
|
-
* emitted whitespace twice and the planner would have been told "(the model returned an empty response…)". */
|
|
123
|
-
const NO_ANSWER = /^\s*(\[(stopped|paused|no answer|no reply came back from the model|declined by the provider)\b|\((the model returned an empty response|hit the output limit before an answer landed))/;
|
|
124
123
|
let _seq = 0;
|
|
125
124
|
const TIMED_OUT = Symbol("delegate-timeout");
|
|
126
125
|
const progressListeners = new Set();
|
|
@@ -136,9 +135,6 @@ function emitProgress(p) {
|
|
|
136
135
|
catch { /* a bad listener never touches the delegation */ }
|
|
137
136
|
}
|
|
138
137
|
}
|
|
139
|
-
const WRITE_TOOLS = new Set(["file_write", "file_edit", "multi_edit", "apply_patch", "notebook_edit"]);
|
|
140
|
-
const CMD_TOOLS = new Set(["bash", "shell_exec", "shell_background"]);
|
|
141
|
-
const READ_TOOLS = /^(file_read|read_files|list_directory|find_files|glob|grep|grep_search|search|code_search|web_search|web_fetch|browser_read|deep_research)$/;
|
|
142
138
|
function shortArg(args) {
|
|
143
139
|
const v = args?.path ?? args?.file ?? args?.pattern ?? args?.query ?? args?.command ?? args?.url;
|
|
144
140
|
return typeof v === "string" ? v.replace(/\s+/g, " ").slice(0, 60) : undefined;
|
|
@@ -150,11 +146,11 @@ export function progressHandlers(p) {
|
|
|
150
146
|
onToolBatch: (events) => {
|
|
151
147
|
p.round += 1;
|
|
152
148
|
for (const e of events) {
|
|
153
|
-
if (
|
|
149
|
+
if (FILE_WRITE.has(e.name))
|
|
154
150
|
p.writes += 1;
|
|
155
|
-
else if (
|
|
151
|
+
else if (SHELL_ANY.has(e.name))
|
|
156
152
|
p.commands += 1;
|
|
157
|
-
else if (
|
|
153
|
+
else if (LOOKUP.has(e.name))
|
|
158
154
|
p.reads += 1;
|
|
159
155
|
}
|
|
160
156
|
p.tool = undefined;
|
|
@@ -221,6 +217,9 @@ export async function runDelegateTask(args, deps = defaultDeps) {
|
|
|
221
217
|
if (dyn)
|
|
222
218
|
auroraOverride = dyn.replace(/\/v1\/?$/, "");
|
|
223
219
|
}
|
|
220
|
+
// The CodeAct lane (moa/codeact.ts): a step that asks for it and passes the check in code gets `codeact_run` and the
|
|
221
|
+
// lane's brief; one that fails runs on tools as always, and the planner is told why. The author is the sub-agent model.
|
|
222
|
+
const lane = await codeActLane(args, task, profile.id, settings);
|
|
224
223
|
const id = `delegate-${profile.id}-${Date.now().toString(36)}-${++_seq}`;
|
|
225
224
|
// Isolation: the child never writes the owner's live memory / rolling summary (see autonomy/profile.ts).
|
|
226
225
|
const { tmpdir } = (await nodeImport("node:os"));
|
|
@@ -235,6 +234,7 @@ export async function runDelegateTask(args, deps = defaultDeps) {
|
|
|
235
234
|
rollingSummaryPath: `${dir}/summary.md`,
|
|
236
235
|
maxRoundsHard: DELEGATE_MAX_ROUNDS,
|
|
237
236
|
sleepConsolidation: { enabled: false }, // a short-lived child must not consolidate the owner's knowledge base
|
|
237
|
+
...(lane.tool ? { extraTools: [lane.tool], toolAllow: CODEACT_STEP_TOOLS } : {}), // a lane step reads; codeact_run computes
|
|
238
238
|
},
|
|
239
239
|
});
|
|
240
240
|
}
|
|
@@ -251,7 +251,7 @@ export async function runDelegateTask(args, deps = defaultDeps) {
|
|
|
251
251
|
emitProgress(progress);
|
|
252
252
|
let outcome;
|
|
253
253
|
try {
|
|
254
|
-
const brief = await briefFor(task, settings);
|
|
254
|
+
const brief = await briefFor(lane.task, settings);
|
|
255
255
|
outcome = await sendWithTimeout(store.run(depth + 1, () => session.send(brief, progressHandlers(progress))), timeoutMs, () => session.interrupt());
|
|
256
256
|
}
|
|
257
257
|
finally {
|
|
@@ -263,10 +263,17 @@ export async function runDelegateTask(args, deps = defaultDeps) {
|
|
|
263
263
|
if (outcome.interrupted)
|
|
264
264
|
return `error: delegate_task: the sub-agent on ${profile.id} was interrupted before it finished`;
|
|
265
265
|
const text = String(outcome.content ?? "").trim();
|
|
266
|
-
|
|
266
|
+
// The engine's own hand-back ([stopped …], [paused …], the output-limit note) is no answer: the planner must not get it as one.
|
|
267
|
+
if (!text || engineEnded(outcome)) {
|
|
267
268
|
return `error: delegate_task: the sub-agent on ${profile.id} produced no answer (${outcome.rounds} rounds, ${outcome.toolCalls} tool calls)${text ? ` — it reported: ${text.slice(0, 300)}` : ""}. Retry with a smaller, clearer subtask or a stronger model.`;
|
|
268
269
|
}
|
|
269
|
-
|
|
270
|
+
if (lane.note)
|
|
271
|
+
return `${lane.note}\n${text}`;
|
|
272
|
+
if (!lane.tool)
|
|
273
|
+
return text;
|
|
274
|
+
// The program's own result goes back verbatim: the executor's closing words may paraphrase or drop the data.
|
|
275
|
+
const last = lane.results[lane.results.length - 1];
|
|
276
|
+
return `${text}${last?.ok ? `\n${codeActReport(last)}` : ""}\n${codeActTraceLine(lane.results)}`;
|
|
270
277
|
}
|
|
271
278
|
catch (e) {
|
|
272
279
|
return `error: delegate_task: the sub-agent on ${profile.id} failed — ${msg(e)}`;
|
|
@@ -278,3 +285,23 @@ export async function runDelegateTask(args, deps = defaultDeps) {
|
|
|
278
285
|
catch { /* already down */ }
|
|
279
286
|
}
|
|
280
287
|
}
|
|
288
|
+
/** The lane a delegated step runs on: `codeact_run` + the lane brief when it asked for the CodeAct lane and passed the
|
|
289
|
+
* check, a one-line note when it asked and failed, nothing when it did not ask. */
|
|
290
|
+
async function codeActLane(args, task, author, settings) {
|
|
291
|
+
const step = codeActStepFromArgs(args, author);
|
|
292
|
+
const results = [];
|
|
293
|
+
if (!step)
|
|
294
|
+
return { task, results };
|
|
295
|
+
const [{ homedir }, { existsSync }, { get_operator_home }] = await Promise.all([
|
|
296
|
+
nodeImport("node:os"),
|
|
297
|
+
nodeImport("node:fs"),
|
|
298
|
+
import("../config/home.js"),
|
|
299
|
+
]);
|
|
300
|
+
const cfg = settings.moa?.codeact;
|
|
301
|
+
const check = codeActEligibility(step, cfg, { home: homedir(), cwd: process.cwd(), operatorHome: get_operator_home() });
|
|
302
|
+
if (!check.eligible)
|
|
303
|
+
return { task, note: `[lane: ${check.detail}]`, results };
|
|
304
|
+
const language = pickLanguage(codeActConfig(cfg).language, check.targets, existsSync);
|
|
305
|
+
const tool = makeCodeActTool({ targets: check.targets, language, settings: cfg, onResult: (r) => results.push(r) });
|
|
306
|
+
return { task: codeActBrief(task, check.targets, language), tool, results };
|
|
307
|
+
}
|
|
@@ -8,6 +8,11 @@ import { runLoop } from "./loop.js";
|
|
|
8
8
|
import { makeReporter } from "./reporter.js";
|
|
9
9
|
import { recordLiveProgress, roundProgressed, settleLiveProgress, touchedPaths } from "../memory/live-progress.js";
|
|
10
10
|
import { getAgentTasks } from "../tools/registry.js";
|
|
11
|
+
import { engineEnded } from "../engine/continuation.js";
|
|
12
|
+
import { pollBus, selfAgent } from "../bus/inbox.js";
|
|
13
|
+
import { beamDrop, beamDropHint, beamDropLine } from "../bus/beam-drop.js";
|
|
14
|
+
import { shownModel, shownModelLabel } from "../engine/identity.js";
|
|
15
|
+
import { shownFailure } from "../engine/net-error.js";
|
|
11
16
|
const newJournal = (prompt) => ({ session: `headless-${process.pid}`, prompt, touched: [], written: false });
|
|
12
17
|
function settleJournal(j, how) {
|
|
13
18
|
if (j.written)
|
|
@@ -18,11 +23,11 @@ function settleJournal(j, how) {
|
|
|
18
23
|
function handlersFor(reporter, json, prompt = "", onDelta, journal = newJournal(prompt)) {
|
|
19
24
|
const { touched, session } = journal;
|
|
20
25
|
return {
|
|
21
|
-
onRoute: (label, ctxPct) => reporter.event("route", { route: label, ctxPct }),
|
|
22
|
-
onServed: (s) => reporter.event("fallback", { from: s.fallbackFrom, servedBy: s.backend
|
|
26
|
+
onRoute: (label, ctxPct) => reporter.event("route", { route: shownModelLabel(label), ctxPct }),
|
|
27
|
+
onServed: (s) => reporter.event("fallback", { from: shownModel(s.fallbackFrom, "selected"), servedBy: s.backend ? shownModel(s.backend, "backup") : null }), // the selected model was down; another box answered
|
|
23
28
|
onAutoContinue: (round) => reporter.event("auto_continue", { round }),
|
|
24
29
|
onSelfHeal: (kind, attempt) => reporter.event("self_heal", { kind, attempt }),
|
|
25
|
-
onFallback: (e) => reporter.event("model_fallback", { from: e.from, servedBy: e.to, reason: e.reason, note: e.line }), // every leg of the model failed; its fallback answered
|
|
30
|
+
onFallback: (e) => reporter.event("model_fallback", { from: shownModel(e.from, "primary"), servedBy: shownModel(e.to, "backup"), reason: e.reason, note: e.line }), // every leg of the model failed; its fallback answered
|
|
26
31
|
onLoopCompaction: (e) => reporter.event("loop_compaction", { ...e }),
|
|
27
32
|
onLoopRecovery: (e) => reporter.event("loop_recovery", { attempt: e.attempt, max: e.max, rounds: e.rounds, replaced: e.replaced, calls: e.repeated.length }),
|
|
28
33
|
onToolBatch: (events, durationMs) => {
|
|
@@ -41,8 +46,27 @@ function handlersFor(reporter, json, prompt = "", onDelta, journal = newJournal(
|
|
|
41
46
|
onDelta: json ? undefined : onDelta ?? ((chunk) => process.stdout.write(chunk)),
|
|
42
47
|
};
|
|
43
48
|
}
|
|
49
|
+
/** One `beam_drop` event per beam drop addressed to this run's agent that arrives while it runs. It peeks, so each
|
|
50
|
+
* message stays in the inbox for the TUI, `switch` and `beam inbox`. Returns the stop function. */
|
|
51
|
+
export function watchBeamDrops(reporter, agent = selfAgent(), everyMs = 3000) {
|
|
52
|
+
const since = Date.now();
|
|
53
|
+
const seen = new Set();
|
|
54
|
+
const tick = () => {
|
|
55
|
+
for (const m of pollBus(agent, { peek: true })) {
|
|
56
|
+
const d = beamDrop(m);
|
|
57
|
+
if (!d || seen.has(d.id) || Date.parse(m.ts) < since)
|
|
58
|
+
continue;
|
|
59
|
+
seen.add(d.id);
|
|
60
|
+
reporter.event("beam_drop", { id: d.id, from: d.from, name: d.name, size: d.size, line: beamDropLine(d), hint: beamDropHint(d) });
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
const timer = setInterval(tick, everyMs);
|
|
64
|
+
timer.unref?.();
|
|
65
|
+
return () => clearInterval(timer);
|
|
66
|
+
}
|
|
44
67
|
/**
|
|
45
|
-
* Run `prompt` headless. Returns a process exit code: 0
|
|
68
|
+
* Run `prompt` headless. Returns a process exit code: 0 an answer, 1 an error or an engine stop (the json result names
|
|
69
|
+
* it in `stopKind`), 130 interrupted. Wires SIGINT
|
|
46
70
|
* to interrupt the in-flight turn so Ctrl-C stops cleanly (and the caller's keep-awake teardown runs).
|
|
47
71
|
*/
|
|
48
72
|
export async function runHeadless(settings, prompt, opts = {}) {
|
|
@@ -87,7 +111,8 @@ export async function runHeadless(settings, prompt, opts = {}) {
|
|
|
87
111
|
catch { /* idle */ } };
|
|
88
112
|
process.on("SIGINT", onSig);
|
|
89
113
|
process.on("SIGTERM", onSig);
|
|
90
|
-
reporter.event("start", { mode: opts.loop ? "loop" : "headless", model: settings.endpoints.aurora.model });
|
|
114
|
+
reporter.event("start", { mode: opts.loop ? "loop" : "headless", model: shownModelLabel(settings.endpoints.aurora.model) });
|
|
115
|
+
const stopBeamWatch = watchBeamDrops(reporter);
|
|
91
116
|
try {
|
|
92
117
|
if (opts.loop) {
|
|
93
118
|
const res = await runLoop(session, prompt, {
|
|
@@ -106,8 +131,9 @@ export async function runHeadless(settings, prompt, opts = {}) {
|
|
|
106
131
|
return finish(res.reason === "error" ? 1 : res.reason === "interrupted" ? 130 : 0);
|
|
107
132
|
}
|
|
108
133
|
const outcome = await session.send(prompt, handlers);
|
|
109
|
-
|
|
110
|
-
|
|
134
|
+
const stop = outcome.stopKind ?? (outcome.stopReason === "content_filter" ? "declined" : undefined); // the engine's stop, never parsed from the text
|
|
135
|
+
reporter.event("done", { rounds: outcome.rounds, toolCalls: outcome.toolCalls, interrupted: outcome.interrupted, durationMs: Math.round(outcome.durationMs ?? 0), ...(stop ? { stopKind: stop } : {}) });
|
|
136
|
+
result = { rounds: outcome.rounds, toolCalls: outcome.toolCalls, interrupted: outcome.interrupted, durationMs: Math.round(outcome.durationMs ?? 0), ...(stop ? { stopKind: stop } : {}) };
|
|
111
137
|
if (outcome.display) {
|
|
112
138
|
streamed = "";
|
|
113
139
|
if (output === "text")
|
|
@@ -116,15 +142,16 @@ export async function runHeadless(settings, prompt, opts = {}) {
|
|
|
116
142
|
answer(outcome.display ?? outcome.content);
|
|
117
143
|
settleJournal(journal, outcome.interrupted ? "stopped" : "completed");
|
|
118
144
|
await session.flushRouteShadow(); // MOA phase-0: headless one-shot exits before fire-and-forget would land
|
|
119
|
-
return finish(outcome.interrupted ? 130 : outcome
|
|
145
|
+
return finish(outcome.interrupted ? 130 : engineEnded(outcome) && outcome.stopKind !== "yield" ? 1 : 0); // the engine ended it (no answer, a cut or withheld one, a guard stop): a failed run; a yield handed work to sub-agents
|
|
120
146
|
}
|
|
121
147
|
catch (e) {
|
|
122
148
|
const message = e instanceof Error ? e.message : String(e);
|
|
123
|
-
reporter.event("error", { message });
|
|
124
|
-
result = { ...result, error: message };
|
|
149
|
+
reporter.event("error", { message: shownFailure(message) });
|
|
150
|
+
result = { ...result, error: shownFailure(message) };
|
|
125
151
|
return finish(1);
|
|
126
152
|
}
|
|
127
153
|
finally {
|
|
154
|
+
stopBeamWatch();
|
|
128
155
|
process.off("SIGINT", onSig);
|
|
129
156
|
process.off("SIGTERM", onSig);
|
|
130
157
|
session.shutdown();
|
package/dist/autonomy/index.js
CHANGED
|
@@ -279,15 +279,13 @@ export async function dispatchAutonomy(argv, settings) {
|
|
|
279
279
|
// Headless paths skip the interactive preflight (cli.tsx's ensureServices), which RESOLVES the dynamic Aurora
|
|
280
280
|
// endpoint from the operator-runtime server.json. Mirror it here — the same EnsureCfg (aurora launchd cfg +
|
|
281
281
|
// optional services) — so a headless `operator run/loop/board/routine` never sends to a baseless
|
|
282
|
-
// "/v1/chat/completions" (Failed to parse URL).
|
|
283
|
-
//
|
|
284
|
-
// Guarded to the empty-base case (the only time we must discover/start), and gateway-aware: carry the
|
|
282
|
+
// "/v1/chat/completions" (Failed to parse URL). It only resolves and reports: Aurora is retired, nothing starts it.
|
|
283
|
+
// Guarded to the empty-base case (the only time we must discover), and gateway-aware: carry the
|
|
285
284
|
// gateway's published api_key (server.json) onto the endpoint config so the router authenticates to it.
|
|
286
285
|
if (!settings.endpoints.aurora.base) {
|
|
287
286
|
const auroraCfg = { base: settings.endpoints.aurora.base, ...settings.services?.aurora };
|
|
288
287
|
await ensureServices({
|
|
289
288
|
aurora: auroraCfg,
|
|
290
|
-
auroraOnDemand: true, // resolve the endpoint only: a run on Aurora loads it at its first turn
|
|
291
289
|
autopilot: settings.services?.autopilot,
|
|
292
290
|
vision: settings.services?.vision,
|
|
293
291
|
onProgress: (m) => process.stderr.write(`[services] ${m}\n`),
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// What isolation this box can confirm for the PR preflight (pr-preflight.ts). A backend counts only when a real run
|
|
2
|
+
// proves it: the same profile the held command would get runs a trivial command, and a write outside its roots is
|
|
3
|
+
// refused. Anything short of that is "not confirmed" and the preflight fails closed. VM and container CLIs (Apple's
|
|
4
|
+
// `container`, `tart`, /dev/kvm, a docker daemon) are reported to the owner but never driven or installed.
|
|
5
|
+
// node-only, loaded lazily (variable specifier) like tools/sandbox.ts.
|
|
6
|
+
import { seatbeltProfile, bwrapArgs } from "../tools/sandbox.js";
|
|
7
|
+
const nodeImport = (m) => import(/* @vite-ignore */ m);
|
|
8
|
+
/** True when `bin` is an executable file on PATH (no spawn: the VM CLIs are only reported, never run). */
|
|
9
|
+
async function onPath(bin) {
|
|
10
|
+
const { access, constants } = await nodeImport("node:fs/promises");
|
|
11
|
+
const { join, delimiter } = await nodeImport("node:path");
|
|
12
|
+
for (const dir of (process.env.PATH ?? "").split(delimiter)) {
|
|
13
|
+
if (!dir)
|
|
14
|
+
continue;
|
|
15
|
+
try {
|
|
16
|
+
await access(join(dir, bin), constants.X_OK);
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
catch { /* not here */ }
|
|
20
|
+
}
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
async function defaultRun(file, args) {
|
|
24
|
+
const { execFile } = await nodeImport("node:child_process");
|
|
25
|
+
// bins: sandbox-exec bwrap docker
|
|
26
|
+
return new Promise((res) => execFile(file, args, { timeout: 5000 }, (e, stdout, stderr) => res({ ok: !e, out: `${stdout ?? ""}${stderr ?? ""}`.trim() })));
|
|
27
|
+
}
|
|
28
|
+
const CHECK = 'echo ok > "$1/probe" && ! (echo x > "$2") 2>/dev/null && test ! -e "$2"';
|
|
29
|
+
export async function probeIsolation(platform = process.platform, run = defaultRun) {
|
|
30
|
+
const fs = await nodeImport("node:fs");
|
|
31
|
+
const os = await nodeImport("node:os");
|
|
32
|
+
const path = await nodeImport("node:path");
|
|
33
|
+
const root = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), "op-pr-probe-"))); // seatbelt matches real paths (/private/var, not /var)
|
|
34
|
+
const outside = path.join(os.homedir(), `.op-pr-probe-${process.pid}`);
|
|
35
|
+
const out = { reportOnly: [], detail: [] };
|
|
36
|
+
const scope = { writeRoots: [root], network: false };
|
|
37
|
+
try {
|
|
38
|
+
if (platform === "darwin") {
|
|
39
|
+
const r = await run("/usr/bin/sandbox-exec", ["-p", seatbeltProfile("strict", scope), "/bin/bash", "-c", CHECK, "_", root, outside]);
|
|
40
|
+
if (r.ok && fs.existsSync(path.join(root, "probe"))) {
|
|
41
|
+
out.backend = "seatbelt";
|
|
42
|
+
out.label = "macOS seatbelt (sandbox-exec)";
|
|
43
|
+
out.detail.push("seatbelt: confirmed");
|
|
44
|
+
}
|
|
45
|
+
else
|
|
46
|
+
out.detail.push(`seatbelt: not confirmed${r.out ? ` (${r.out.slice(0, 120)})` : ""}`);
|
|
47
|
+
for (const bin of ["container", "tart"])
|
|
48
|
+
if (await onPath(bin))
|
|
49
|
+
out.reportOnly.push(bin === "container" ? "Apple container (VM)" : "tart (VM)");
|
|
50
|
+
}
|
|
51
|
+
else if (platform === "linux") {
|
|
52
|
+
const r = await run("bwrap", [...bwrapArgs("strict", scope), "/bin/sh", "-c", CHECK, "_", root, outside]);
|
|
53
|
+
if (r.ok && fs.existsSync(path.join(root, "probe"))) {
|
|
54
|
+
out.backend = "bwrap";
|
|
55
|
+
out.label = "bubblewrap (bwrap)";
|
|
56
|
+
out.detail.push("bwrap: confirmed");
|
|
57
|
+
}
|
|
58
|
+
else
|
|
59
|
+
out.detail.push(`bwrap: not confirmed${r.out ? ` (${r.out.slice(0, 120)})` : ""}`);
|
|
60
|
+
try {
|
|
61
|
+
fs.accessSync("/dev/kvm", fs.constants.R_OK | fs.constants.W_OK);
|
|
62
|
+
out.reportOnly.push("/dev/kvm (VM capable)");
|
|
63
|
+
}
|
|
64
|
+
catch { /* no KVM for this user */ }
|
|
65
|
+
if ((await run("docker", ["info", "--format", "{{.ServerVersion}}"])).ok)
|
|
66
|
+
out.reportOnly.push("docker");
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
out.detail.push(`no isolation backend on ${platform}`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
finally {
|
|
73
|
+
try {
|
|
74
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
75
|
+
}
|
|
76
|
+
catch { /* temp dir */ }
|
|
77
|
+
try {
|
|
78
|
+
if (fs.existsSync(outside)) {
|
|
79
|
+
fs.rmSync(outside, { force: true });
|
|
80
|
+
out.backend = undefined;
|
|
81
|
+
out.detail.push("a write outside the roots landed: not confined");
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
catch { /* nothing there */ }
|
|
85
|
+
}
|
|
86
|
+
return out;
|
|
87
|
+
}
|
|
88
|
+
/** `git <args>` in `cwd` for the preflight's bookkeeping: trimmed stdout, or null on any failure. */
|
|
89
|
+
export async function prGit(cwd, args) {
|
|
90
|
+
const { execFile } = await nodeImport("node:child_process");
|
|
91
|
+
return new Promise((res) => execFile("git", ["-C", cwd, ...args], { timeout: 5000 }, (e, stdout) => res(e ? null : String(stdout).trim() || null)));
|
|
92
|
+
}
|