@omacode/micromanager 0.1.1 → 1.0.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 +7 -4
- package/THIRD_PARTY.md +100 -0
- package/decider/.python-version +1 -0
- package/decider/README.md +35 -0
- package/decider/decider/__init__.py +1 -0
- package/decider/decider/server.py +327 -0
- package/decider/pyproject.toml +34 -0
- package/decider/uv.lock +1255 -0
- package/dist/agenda.js +51 -0
- package/dist/agents.js +58 -0
- package/dist/artifact/handoff.js +281 -0
- package/dist/ask.js +200 -0
- package/dist/backends.js +219 -0
- package/dist/backlog.js +414 -0
- package/dist/bench.js +427 -0
- package/dist/board.js +1 -0
- package/dist/brief.js +202 -0
- package/dist/browser.js +679 -0
- package/dist/budget.js +61 -0
- package/dist/catalog.js +187 -0
- package/dist/checkchange.js +145 -0
- package/dist/checkpoint.js +94 -0
- package/dist/cli.js +764 -0
- package/dist/comfy-gate.js +258 -0
- package/dist/compact.js +142 -0
- package/dist/config.js +344 -0
- package/dist/context/capture.js +1 -0
- package/dist/context/digest.js +1 -0
- package/dist/context/embed.js +1 -0
- package/dist/context/index.js +2 -0
- package/dist/context/ledger.js +1 -0
- package/dist/context/manager.js +1 -0
- package/dist/context/memory.js +1 -0
- package/dist/context/policy.js +1 -0
- package/dist/context/prices.js +1 -0
- package/dist/context/recall.js +1 -0
- package/dist/context/rules.js +1 -0
- package/dist/context/search.js +1 -0
- package/dist/context/status.js +1 -0
- package/dist/context/store.js +1 -0
- package/dist/context/summary.js +1 -0
- package/dist/context/tokens.js +1 -0
- package/dist/context/tools.js +1 -0
- package/dist/continuation.js +184 -0
- package/dist/contract.js +294 -0
- package/dist/contractround.js +178 -0
- package/dist/control.js +1 -0
- package/dist/creative-tools.js +237 -0
- package/dist/dataset.js +175 -0
- package/dist/decide.js +676 -0
- package/dist/decider.js +171 -0
- package/dist/design-shell.js +448 -0
- package/dist/design.js +1410 -0
- package/dist/desktop.js +44 -0
- package/dist/egress.js +156 -0
- package/dist/eval.js +60 -0
- package/dist/evolver.js +302 -0
- package/dist/features.js +193 -0
- package/dist/followups.js +32 -0
- package/dist/forms.js +195 -0
- package/dist/gate.js +108 -0
- package/dist/gatebox.js +46 -0
- package/dist/grants.js +189 -0
- package/dist/graph.js +65 -0
- package/dist/guard/index.js +1 -0
- package/dist/guard/wire.js +1 -0
- package/dist/helpers.js +85 -0
- package/dist/hooks.js +158 -0
- package/dist/image-models.js +117 -0
- package/{src/integration.ts → dist/integration.js} +1 -2
- package/dist/journal.js +1 -0
- package/dist/look.js +363 -0
- package/dist/memory.js +1 -0
- package/dist/mode.js +97 -0
- package/dist/native.js +3348 -0
- package/dist/nogit.js +259 -0
- package/dist/outcomes.js +148 -0
- package/dist/permission.js +35 -0
- package/dist/pick.js +89 -0
- package/dist/pipelines.js +262 -0
- package/dist/plan.js +641 -0
- package/dist/plandoc.js +211 -0
- package/dist/plugin.js +4736 -0
- package/dist/policy.js +58 -0
- package/dist/pools.js +1 -0
- package/dist/preview.js +274 -0
- package/dist/profile.js +165 -0
- package/dist/progress.js +1 -0
- package/dist/promote.js +313 -0
- package/dist/redact.js +1 -0
- package/dist/registry.js +179 -0
- package/dist/riskscore.js +126 -0
- package/dist/roles.js +1 -0
- package/dist/routing.js +1 -0
- package/dist/runner.js +1892 -0
- package/{src/sandbox.ts → dist/sandbox.js} +1 -2
- package/dist/sandboxgate.js +90 -0
- package/dist/scheduler.js +170 -0
- package/dist/services-main.js +131 -0
- package/dist/services.js +265 -0
- package/dist/session.js +241 -0
- package/dist/setup.js +423 -0
- package/dist/shell/decide.js +1 -0
- package/dist/shell/index.js +2 -0
- package/dist/shell/sandbox.js +1 -0
- package/dist/shell/wire.js +1 -0
- package/dist/skills.js +103 -0
- package/dist/state.js +1 -0
- package/dist/store.js +1 -0
- package/dist/switcher.js +1 -0
- package/dist/synth.js +418 -0
- package/dist/tools.js +477 -0
- package/dist/trials.js +223 -0
- package/dist/usage.js +1 -0
- package/dist/wait.js +167 -0
- package/dist/watchdog.js +476 -0
- package/dist/web-guidance.js +43 -0
- package/dist/which.js +20 -0
- package/dist/worktree/git.js +545 -0
- package/dist/writeguard.js +311 -0
- package/package.json +36 -17
- package/skills/deck/SKILL.md +98 -0
- package/skills/design/SKILL.md +150 -0
- package/skills/image/SKILL.md +66 -0
- package/skills/orchestrator/SKILL.md +107 -0
- package/skills/video/SKILL.md +97 -0
- package/skills/web/SKILL.md +60 -0
- package/src/agenda.ts +0 -56
- package/src/agents.ts +0 -74
- package/src/ask.ts +0 -243
- package/src/backends.ts +0 -144
- package/src/backlog.ts +0 -436
- package/src/bench.ts +0 -163
- package/src/board.ts +0 -1
- package/src/brief.ts +0 -151
- package/src/browser.ts +0 -624
- package/src/budget.ts +0 -73
- package/src/catalog.ts +0 -214
- package/src/checkchange.ts +0 -180
- package/src/checkpoint.ts +0 -99
- package/src/cli.ts +0 -117
- package/src/compact.ts +0 -162
- package/src/config.ts +0 -340
- package/src/context/capture.ts +0 -1
- package/src/context/digest.ts +0 -1
- package/src/context/embed.ts +0 -1
- package/src/context/index.ts +0 -2
- package/src/context/ledger.ts +0 -1
- package/src/context/manager.ts +0 -1
- package/src/context/memory.ts +0 -1
- package/src/context/policy.ts +0 -1
- package/src/context/prices.ts +0 -1
- package/src/context/recall.ts +0 -1
- package/src/context/rules.ts +0 -1
- package/src/context/search.ts +0 -1
- package/src/context/status.ts +0 -1
- package/src/context/store.ts +0 -1
- package/src/context/summary.ts +0 -1
- package/src/context/tokens.ts +0 -1
- package/src/context/tools.ts +0 -1
- package/src/continuation.ts +0 -122
- package/src/contract.ts +0 -342
- package/src/contractround.ts +0 -225
- package/src/control.ts +0 -1
- package/src/dataset.ts +0 -133
- package/src/decide.ts +0 -690
- package/src/eval.ts +0 -66
- package/src/evolver.ts +0 -369
- package/src/followups.ts +0 -50
- package/src/forms.ts +0 -191
- package/src/gate.ts +0 -90
- package/src/grants.ts +0 -239
- package/src/graph.ts +0 -74
- package/src/guard/index.ts +0 -1
- package/src/guard/wire.ts +0 -1
- package/src/helpers.ts +0 -105
- package/src/hooks.ts +0 -199
- package/src/jev.ts +0 -141
- package/src/journal.ts +0 -1
- package/src/look.ts +0 -390
- package/src/memory.ts +0 -1
- package/src/native.ts +0 -2455
- package/src/nogit.ts +0 -112
- package/src/outcomes.ts +0 -210
- package/src/pick.ts +0 -112
- package/src/pipelines.ts +0 -252
- package/src/plan.ts +0 -449
- package/src/plugin.ts +0 -3187
- package/src/policy.ts +0 -84
- package/src/pools.ts +0 -1
- package/src/profile.ts +0 -186
- package/src/progress.ts +0 -1
- package/src/redact.ts +0 -1
- package/src/registry.ts +0 -207
- package/src/roles.ts +0 -1
- package/src/routing.ts +0 -1
- package/src/runner.ts +0 -1506
- package/src/scheduler.ts +0 -200
- package/src/session.ts +0 -269
- package/src/shell/decide.ts +0 -1
- package/src/shell/index.ts +0 -2
- package/src/shell/sandbox.ts +0 -1
- package/src/shell/wire.ts +0 -1
- package/src/skills.ts +0 -111
- package/src/state.ts +0 -1
- package/src/store.ts +0 -1
- package/src/switcher.ts +0 -1
- package/src/tools.ts +0 -480
- package/src/trials.ts +0 -247
- package/src/usage.ts +0 -1
- package/src/wait.ts +0 -180
- package/src/watchdog.ts +0 -498
- package/src/worktree/git.ts +0 -378
package/dist/features.js
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
// Installing omacode's optional parts, for every door: install.sh (through the CLI), the `install_feature` tool an agent
|
|
2
|
+
// calls, and the TUI's /setup dialog and welcome. One planner (setup.ts planFor) decides what a request needs; this
|
|
3
|
+
// module runs it, asynchronously and with every line of output handed to a log, so a ComfyUI install that takes
|
|
4
|
+
// minutes neither blocks OpenCode's server nor hides what it does.
|
|
5
|
+
//
|
|
6
|
+
// Parts in user space (the services, HyperFrames, ComfyUI, comfy-mcp, Manim, and uv from its own installer) are
|
|
7
|
+
// installed by any door. System packages (Chromium, ffmpeg, git, bubblewrap) need sudo, which only a terminal can
|
|
8
|
+
// answer: without `allowSudo` they are not run, and the result names the command for the user's terminal instead.
|
|
9
|
+
import { spawn } from "node:child_process";
|
|
10
|
+
import { existsSync } from "node:fs";
|
|
11
|
+
import { join } from "node:path";
|
|
12
|
+
import { findChromium } from "@omacode/core/chromium";
|
|
13
|
+
import { userConfigPath } from "@omacode/core/paths";
|
|
14
|
+
import { TELEMETRY_OFF } from "@omacode/core/telemetry";
|
|
15
|
+
import { addComfyMcp, comfyLaunch, comfyPython, comfyWorkspace, detect, gpus, home, installSteps, TOOL_INFO, torchChecks, } from "./creative-tools.js";
|
|
16
|
+
import { install as installServices, registerComfy, unitPath } from "./services.js";
|
|
17
|
+
import { isPresent, OFFERS, packageManager, planFor, realProbe, systemInstall } from "./setup.js";
|
|
18
|
+
import { exec } from "./worktree/git.js";
|
|
19
|
+
// The command runner the CLI and the plugin use, and the device list, for callers outside this package (the TUI).
|
|
20
|
+
export { exec, gpus };
|
|
21
|
+
// One command, its output handed to the log line by line as it comes. Never throws.
|
|
22
|
+
export function runStep(cmd, args, o) {
|
|
23
|
+
return new Promise((done) => {
|
|
24
|
+
let out = "";
|
|
25
|
+
let child;
|
|
26
|
+
try {
|
|
27
|
+
child = spawn(cmd, [...args], { cwd: o.cwd, env: { ...process.env, ...o.env, ...TELEMETRY_OFF }, stdio: ["ignore", "pipe", "pipe"] });
|
|
28
|
+
}
|
|
29
|
+
catch (err) {
|
|
30
|
+
o.log(`${cmd}: ${err instanceof Error ? err.message : String(err)}`);
|
|
31
|
+
return done({ ok: false, stdout: "" });
|
|
32
|
+
}
|
|
33
|
+
let pending = "";
|
|
34
|
+
const take = (chunk, keep) => {
|
|
35
|
+
const text = chunk.toString();
|
|
36
|
+
if (keep)
|
|
37
|
+
out += text;
|
|
38
|
+
if (o.quiet)
|
|
39
|
+
return;
|
|
40
|
+
pending += text.replace(/\r/g, "\n");
|
|
41
|
+
const lines = pending.split("\n");
|
|
42
|
+
pending = lines.pop() ?? "";
|
|
43
|
+
for (const line of lines)
|
|
44
|
+
if (line.trim())
|
|
45
|
+
o.log(` ${line}`);
|
|
46
|
+
};
|
|
47
|
+
child.stdout.on("data", (c) => take(c, true));
|
|
48
|
+
child.stderr.on("data", (c) => take(c, false));
|
|
49
|
+
child.on("error", (err) => {
|
|
50
|
+
o.log(`${cmd}: ${err.message}`);
|
|
51
|
+
done({ ok: false, stdout: out });
|
|
52
|
+
});
|
|
53
|
+
child.on("close", (code) => {
|
|
54
|
+
if (pending.trim() && !o.quiet)
|
|
55
|
+
o.log(` ${pending}`);
|
|
56
|
+
done({ ok: code === 0, stdout: out });
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
// What is on the machine now, for the planner.
|
|
61
|
+
export async function presentState(run) {
|
|
62
|
+
const probe = realProbe(run);
|
|
63
|
+
return { services: existsSync(unitPath()), which: probe.which, chromium: Boolean(findChromium()), tools: await detect(run) };
|
|
64
|
+
}
|
|
65
|
+
// A creative tool's own steps, then what it needs afterwards: comfy-mcp its OpenCode entry, ComfyUI its device check
|
|
66
|
+
// and its place in omacode-services.
|
|
67
|
+
export async function installTool(name, log, gpu) {
|
|
68
|
+
for (const s of installSteps(name, undefined, name === "comfyui" ? gpu : undefined)) {
|
|
69
|
+
log(`→ ${s.say}`);
|
|
70
|
+
const r = await runStep(s.cmd, s.args, { ...(s.cwd ? { cwd: s.cwd } : {}), ...(s.env ? { env: s.env } : {}), log });
|
|
71
|
+
if (!r.ok) {
|
|
72
|
+
log(`${TOOL_INFO[name].title}: "${s.say}" failed`);
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
if (name === "comfy-mcp") {
|
|
77
|
+
log(`comfy-mcp installed. ${addComfyMcp(userConfigPath("opencode.json")).say}`);
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
if (name === "web-guidance") {
|
|
81
|
+
log(`${TOOL_INFO[name].title} installed; agents get it as the skill modern-web-guidance after OpenCode restarts`);
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
if (name !== "comfyui") {
|
|
85
|
+
log(`${TOOL_INFO[name].title} installed`);
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
return registerComfyTool(log, gpu);
|
|
89
|
+
}
|
|
90
|
+
// After a ComfyUI install, or for one already there: check that its PyTorch sees the GPU, and add it to
|
|
91
|
+
// omacode-services on that GPU (or the CPU, when it does not).
|
|
92
|
+
export async function registerComfyTool(log, gpu, workspace = comfyWorkspace(home())) {
|
|
93
|
+
let env = {};
|
|
94
|
+
let seenGpu = false;
|
|
95
|
+
const checks = gpu ? torchChecks(gpu, home(), workspace) : [];
|
|
96
|
+
for (const [i, c] of checks.entries()) {
|
|
97
|
+
log(`→ ${c.say}`);
|
|
98
|
+
const r = await runStep(c.cmd, c.args, { ...(c.cwd ? { cwd: c.cwd } : {}), ...(c.env ? { env: c.env } : {}), log, quiet: true });
|
|
99
|
+
const seen = r.ok && r.stdout.startsWith("gpu");
|
|
100
|
+
log(` ${seen ? `yes: ${r.stdout.slice(4).trim()}` : "no"}`);
|
|
101
|
+
if (seen) {
|
|
102
|
+
env = c.env ?? {};
|
|
103
|
+
seenGpu = true;
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
if (i === checks.length - 1)
|
|
107
|
+
log(` ComfyUI is installed but will run on the CPU: its PyTorch does not see ${gpu.name}`);
|
|
108
|
+
}
|
|
109
|
+
const comfy = { python: comfyPython(home(), workspace), workspace, ...(gpu && gpu.id !== "cpu" && seenGpu ? { gpu: { id: gpu.id, name: gpu.name, ...(Object.keys(env).length ? { env } : {}) } } : {}) };
|
|
110
|
+
if (registerComfy(comfy)) {
|
|
111
|
+
const restarted = await runStep("systemctl", ["--user", "try-restart", "omacode-services.service"], { log, quiet: true });
|
|
112
|
+
log(`ComfyUI installed and added to omacode-services on :8188, started by its first request${restarted.ok ? "" : " (restart omacode-services to load it)"}; /services switches it`);
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
log(`ComfyUI installed; start it with:\n ${comfyLaunch(env)}\n(or install the local services and run this again to have it started on demand)`);
|
|
116
|
+
}
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
119
|
+
// Install the parts asked for, in the planner's order: system packages, the services, the creative tools.
|
|
120
|
+
export async function installParts(parts, o) {
|
|
121
|
+
const there = o.there ?? (await presentState(o.run));
|
|
122
|
+
const plan = planFor(parts, there);
|
|
123
|
+
const present = parts.filter((id) => isPresent(id, there)).map((id) => OFFERS[id].title);
|
|
124
|
+
const installed = [];
|
|
125
|
+
const failed = [];
|
|
126
|
+
let terminal;
|
|
127
|
+
// uv from its own installer when sudo cannot run: it needs none, and the services and Python tools need it.
|
|
128
|
+
// root (a container) needs no password, so system packages install from any door there
|
|
129
|
+
const sudo = o.allowSudo || process.getuid?.() === 0;
|
|
130
|
+
const sudoNeeds = plan.system.filter((n) => !(n === "uv" && !sudo));
|
|
131
|
+
const userNeeds = plan.system.filter((n) => n === "uv" && !sudo);
|
|
132
|
+
const manager = packageManager(realProbe(o.run));
|
|
133
|
+
if (sudoNeeds.length) {
|
|
134
|
+
const sys = systemInstall(manager, sudoNeeds);
|
|
135
|
+
if (sudo) {
|
|
136
|
+
for (const m of sys.manual) {
|
|
137
|
+
o.log(`install by hand: ${m}`);
|
|
138
|
+
failed.push(m);
|
|
139
|
+
}
|
|
140
|
+
for (const c of sys.commands)
|
|
141
|
+
(await runCommand(c, o.log)) ? installed.push(c.say) : failed.push(c.say);
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
terminal = [...sys.commands.map((c) => [c.cmd, ...c.args].join(" ")), ...sys.manual].join("; ");
|
|
145
|
+
o.log(`needs your terminal (sudo): ${terminal}`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if (userNeeds.length) {
|
|
149
|
+
for (const c of systemInstall(undefined, userNeeds).commands)
|
|
150
|
+
(await runCommand(c, o.log)) ? installed.push("uv") : failed.push("uv");
|
|
151
|
+
process.env.PATH = `${join(process.env.HOME ?? "", ".local", "bin")}:${process.env.PATH ?? ""}`;
|
|
152
|
+
}
|
|
153
|
+
if (plan.services) {
|
|
154
|
+
o.log("→ the local services (omacode-services: the decider and the embedding service)");
|
|
155
|
+
const r = await installServices(o.run, { log: (line) => o.log(` ${line}`) });
|
|
156
|
+
if (r.ok)
|
|
157
|
+
installed.push(OFFERS.services.title);
|
|
158
|
+
else {
|
|
159
|
+
o.log(` ${r.text}`);
|
|
160
|
+
failed.push(OFFERS.services.title);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
let gpu;
|
|
164
|
+
if (plan.tools.includes("comfyui")) {
|
|
165
|
+
const devices = await gpus(o.run);
|
|
166
|
+
gpu = typeof o.gpu === "string" ? devices.find((g) => g.id === o.gpu) : (o.gpu ?? devices[0]);
|
|
167
|
+
}
|
|
168
|
+
for (const name of plan.tools) {
|
|
169
|
+
const need = Object.values(OFFERS).find((x) => x.tool === name)?.buildNeeds;
|
|
170
|
+
if (need && terminal && sudoNeeds.includes(need)) {
|
|
171
|
+
o.log(`${TOOL_INFO[name].title} waits for its system libraries (the terminal command above); install them, then this part again`);
|
|
172
|
+
failed.push(`${TOOL_INFO[name].title} (needs its system libraries first)`);
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
;
|
|
176
|
+
(await installTool(name, o.log, name === "comfyui" ? gpu : undefined)) ? installed.push(TOOL_INFO[name].title) : failed.push(TOOL_INFO[name].title);
|
|
177
|
+
}
|
|
178
|
+
return { ok: failed.length === 0, installed, present, ...(terminal ? { terminal } : {}), failed };
|
|
179
|
+
}
|
|
180
|
+
async function runCommand(c, log) {
|
|
181
|
+
log(`→ ${c.say}`);
|
|
182
|
+
return (await runStep(c.cmd, c.args, { log })).ok;
|
|
183
|
+
}
|
|
184
|
+
// One sentence for a person or an agent: what happened, what is left for the terminal.
|
|
185
|
+
export function outcomeText(o) {
|
|
186
|
+
const parts = [
|
|
187
|
+
o.installed.length ? `Installed: ${o.installed.join(", ")}.` : "",
|
|
188
|
+
o.present.length ? `Already there: ${o.present.join(", ")}.` : "",
|
|
189
|
+
o.failed.length ? `Failed: ${o.failed.join(", ")}.` : "",
|
|
190
|
+
o.terminal ? `Needs sudo, so the user runs this in a terminal: ${o.terminal}` : "",
|
|
191
|
+
].filter(Boolean);
|
|
192
|
+
return parts.join(" ") || "Nothing to install.";
|
|
193
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// N7, a worker's follow-ups (design.md §8): what the decision model is asked, and how code turns its answers into
|
|
2
|
+
// a verdict per item. Pure, so the runner and the N7 bench (npm run bench-n7) decide the same way.
|
|
3
|
+
import { CHOICE_FLOOR, followUpQuestions, NOUL_FLOOR } from "./catalog.js";
|
|
4
|
+
export function n7State(ctx, items) {
|
|
5
|
+
return { goal: ctx.goal, acceptance: ctx.acceptance, task: ctx.task, otherTasks: ctx.otherTasks, followUps: items };
|
|
6
|
+
}
|
|
7
|
+
export const n7Questions = followUpQuestions;
|
|
8
|
+
const PRIORITY = { high: 1, normal: 3, low: 5 };
|
|
9
|
+
// answers: the model's, or empty (no model, or a rule preset). Without answers, files decide: a follow-up only on
|
|
10
|
+
// files of tasks still open is already planned, one on files of done tasks is in scope, anything else is not.
|
|
11
|
+
export function triage(answers, items, ctx) {
|
|
12
|
+
const noul = (q) => (answers[q]?.type === "noul" ? answers[q].noul : undefined);
|
|
13
|
+
return items.map((item, i) => {
|
|
14
|
+
const planned = noul(`planned.${i}`);
|
|
15
|
+
const onOpen = item.files.length > 0 && item.files.every((f) => ctx.openFiles.has(f));
|
|
16
|
+
if (planned !== undefined ? planned >= NOUL_FLOOR : onOpen)
|
|
17
|
+
return { kind: "planned" };
|
|
18
|
+
// "Needed or in scope" goes before "the user's call": on the N7 bench the latter is high for nearly everything
|
|
19
|
+
// outside the job's text (0.6 to 0.8), real work included, while needed and in_scope stay low for what is not.
|
|
20
|
+
const needed = noul(`needed.${i}`);
|
|
21
|
+
const inScope = noul(`in_scope.${i}`);
|
|
22
|
+
const take = needed !== undefined || inScope !== undefined
|
|
23
|
+
? Math.max(needed ?? 0, inScope ?? 0) >= NOUL_FLOOR
|
|
24
|
+
: item.files.length > 0 && item.files.every((f) => ctx.doneFiles.has(f));
|
|
25
|
+
if (!take)
|
|
26
|
+
return { kind: "later", reason: (noul(`user.${i}`) ?? 0) >= NOUL_FLOOR ? "user_should_decide" : "out_of_scope" };
|
|
27
|
+
if (item.files.length === 0)
|
|
28
|
+
return { kind: "later", reason: "no_files" };
|
|
29
|
+
const p = answers[`priority.${i}`];
|
|
30
|
+
return { kind: "task", priority: p?.type === "choice" && p.confidence >= CHOICE_FLOOR ? PRIORITY[p.choice] ?? 3 : 3 };
|
|
31
|
+
});
|
|
32
|
+
}
|
package/dist/forms.js
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
// Questions to the user as forms (the user, 2026-10-20: a question the micromanager writes as text scrolls away, and a
|
|
2
|
+
// job then waits for an answer nobody saw). The micromanager asks with OpenCode's question tool; the form stays in the
|
|
3
|
+
// TUI until it is answered, and the answer comes back as the tool's result, which the plugin reads (tool.execute.after).
|
|
4
|
+
//
|
|
5
|
+
// The plugin cannot open a form itself (its context has no form domain in opencode 2.0.18), so it hands the
|
|
6
|
+
// micromanager the exact input to pass, and recognises its forms by their headers. Spike, 2026-10-20: several
|
|
7
|
+
// questions go into one form, `multiple: true` makes a question a multi-select, a "Type your own answer" option is
|
|
8
|
+
// added by OpenCode, there are no default ticks, and the turn waits until the user submits. The answer arrives as one
|
|
9
|
+
// list of labels per question: [["Auto-continue", "Parallel"], ["Start"]].
|
|
10
|
+
import { DEFAULT_OPTIONS } from "@omacode/state/options";
|
|
11
|
+
export { DEFAULT_OPTIONS };
|
|
12
|
+
const H = { options: "Job options", start: "Start job", access: "Open a path", git: "No git repository", mode: "Switch mode" };
|
|
13
|
+
const OPTION = { auto: "Auto-continue", parallel: "Parallel", review: "Review per task", local: "Keep it local", optimize: "Optimize" };
|
|
14
|
+
const START = { start: "Start", change: "Change the plan", cancel: "Cancel" };
|
|
15
|
+
const ACCESS = { open: "Open it", closed: "Keep it closed" };
|
|
16
|
+
const ASK = { once: "Allow once", job: "Allow for this job", refuse: "Refuse" };
|
|
17
|
+
const GRANT = { job: "Allow for this job", refuse: "Refuse" };
|
|
18
|
+
export const GIT = { init: "Create a git repository", none: "Without isolation", repo: "Work in", cancel: "Cancel" };
|
|
19
|
+
export const MODE = { build: "Switch to build", plan: "Stay in plan" };
|
|
20
|
+
// The text the micromanager passes to the question tool, ready to copy.
|
|
21
|
+
export const formInput = (questions) => JSON.stringify({ questions });
|
|
22
|
+
// The start form: the job's options (ticked last time: said in the description, as a form has no default ticks) and
|
|
23
|
+
// the go. It doubles as the plan's approval: nothing that writes starts before "Start".
|
|
24
|
+
export function startForm(jobId, todos, startable, last = DEFAULT_OPTIONS) {
|
|
25
|
+
const was = (on) => (on ? " (on last time)" : "");
|
|
26
|
+
return [
|
|
27
|
+
{
|
|
28
|
+
header: H.options,
|
|
29
|
+
question: `How should ${jobId} run?`,
|
|
30
|
+
multiple: true,
|
|
31
|
+
options: [
|
|
32
|
+
{ label: OPTION.auto, description: `Work the todo list without stopping; pause only for questions to you${was(last.auto)}` },
|
|
33
|
+
{ label: OPTION.parallel, description: `Start every task that can start at once, not one after another${was(last.parallel)}` },
|
|
34
|
+
{ label: OPTION.review, description: `A reviewer checks each change before it counts as done${was(last.review)}` },
|
|
35
|
+
{ label: OPTION.local, description: "Sensitive tasks stay on local models; no cloud for this job (cloud is allowed by default, and the settings panel can change it at any time)" },
|
|
36
|
+
{ label: OPTION.optimize, description: `After the checks pass, one more pass inspects the merged changes for waste and removes it${was(last.optimize)}` },
|
|
37
|
+
],
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
header: H.start,
|
|
41
|
+
question: `The plan has ${todos} todo${todos === 1 ? "" : "s"}, ${startable} can start now. Start ${jobId}?`,
|
|
42
|
+
options: [
|
|
43
|
+
{ label: `${START.start} (Recommended)`, description: "Start the job with the options ticked above" },
|
|
44
|
+
{ label: START.change, description: "Say what to change; the plan comes back to you" },
|
|
45
|
+
{ label: START.cancel, description: "Drop the plan" },
|
|
46
|
+
],
|
|
47
|
+
},
|
|
48
|
+
];
|
|
49
|
+
}
|
|
50
|
+
// The question about a path only the user can open (request_access on a refused path).
|
|
51
|
+
export function accessForm(path, why, rule) {
|
|
52
|
+
return [{
|
|
53
|
+
header: H.access,
|
|
54
|
+
question: `A worker needs ${path}, which is refused by default (${rule}). What it needs there: ${why}. Open it for this job?`,
|
|
55
|
+
options: [
|
|
56
|
+
{ label: ACCESS.open, description: "The workers of this job may read and write there while this server runs" },
|
|
57
|
+
{ label: ACCESS.closed, description: "It stays closed for this job; the question will not come back" },
|
|
58
|
+
],
|
|
59
|
+
}];
|
|
60
|
+
}
|
|
61
|
+
// The question that leaves plan mode (set_mode). A form answer is the user's own word, so answering it switches; the
|
|
62
|
+
// orchestrator must not have to translate it back into a chat yes.
|
|
63
|
+
export function modeForm() {
|
|
64
|
+
return [{
|
|
65
|
+
header: H.mode,
|
|
66
|
+
question: "Leave plan mode? Build may start, merge and discard jobs from now on.",
|
|
67
|
+
options: [
|
|
68
|
+
{ label: MODE.build, description: "Switch this session to build, now and for later turns" },
|
|
69
|
+
{ label: MODE.plan, description: "Stay in plan mode: keep planning only" },
|
|
70
|
+
],
|
|
71
|
+
}];
|
|
72
|
+
}
|
|
73
|
+
// The question about a worker's paused permission request (src/ask.ts).
|
|
74
|
+
export function askForm(id, task, request, why) {
|
|
75
|
+
return [{
|
|
76
|
+
header: `Request ${id}`,
|
|
77
|
+
question: `Worker ${task} asks to run ${request}. ${why} Allow it?`,
|
|
78
|
+
options: [
|
|
79
|
+
{ label: ASK.once, description: "This one call" },
|
|
80
|
+
{ label: ASK.job, description: "This exact request for the rest of the job" },
|
|
81
|
+
{ label: ASK.refuse, description: "The worker carries on without it" },
|
|
82
|
+
],
|
|
83
|
+
}];
|
|
84
|
+
}
|
|
85
|
+
// The question about a variable or a host a worker asks for (src/grants.ts). A host asked for while the job's commands
|
|
86
|
+
// hold a secret names that secret: the two together are what it takes to send it away.
|
|
87
|
+
export function grantForm(id, kind, name, task, why, secrets = []) {
|
|
88
|
+
const what = kind === "env"
|
|
89
|
+
? `the variable ${name} in its shell commands (its value never reaches a model)`
|
|
90
|
+
: `to reach ${name} from its shell commands${secrets.length ? `. These commands already hold ${secrets.join(", ")}; with ${name} open they could send ${secrets.length > 1 ? "them" : "it"} there` : ""}`;
|
|
91
|
+
return [{
|
|
92
|
+
header: `Grant ${id}`,
|
|
93
|
+
question: `Worker ${task} asks for ${what}. Why: ${why.slice(0, 300)}. Allow it?`,
|
|
94
|
+
options: [
|
|
95
|
+
{ label: GRANT.job, description: kind === "env" ? "Every command of this job's workers gets it" : "Every command of this job's workers may reach it" },
|
|
96
|
+
{ label: GRANT.refuse, description: "The worker carries on without it; it will not ask again" },
|
|
97
|
+
],
|
|
98
|
+
}];
|
|
99
|
+
}
|
|
100
|
+
// The question about several grants of one worker session at once (src/grants.ts). The worker asked for a variable and a
|
|
101
|
+
// host while the first answer was still open; the user answers both in one form, each on its own.
|
|
102
|
+
export function grantBatchForm(items, task) {
|
|
103
|
+
return items.map((item) => ({
|
|
104
|
+
header: `Grant ${item.id}`,
|
|
105
|
+
question: `Worker ${task} asks for ${item.kind === "env" ? `the variable ${item.name} in its shell commands (its value never reaches a model)` : `to reach ${item.name} from its shell commands${item.secrets?.length ? `. These commands already hold ${item.secrets.join(", ")}; with ${item.name} open they could send ${item.secrets.length > 1 ? "them" : "it"} there` : ""}`}. Why: ${item.why.slice(0, 300)}. Allow it?`,
|
|
106
|
+
options: [
|
|
107
|
+
{ label: GRANT.job, description: item.kind === "env" ? "Every command of this job's workers gets it" : "Every command of this job's workers may reach it" },
|
|
108
|
+
{ label: GRANT.refuse, description: "The worker carries on without it; it will not ask again" },
|
|
109
|
+
],
|
|
110
|
+
}));
|
|
111
|
+
}
|
|
112
|
+
// The question when the project is no git repository (src/worktree/git.ts): the recommended way first.
|
|
113
|
+
export function gitForm(path, files, size, recommend, excluded, repos = []) {
|
|
114
|
+
const init = { label: `${GIT.init}${recommend === "init" ? " (Recommended)" : ""}`, description: `git init and a first commit${excluded.length ? `; left out: ${excluded.join(", ")}` : ""}` };
|
|
115
|
+
const none = { label: `${GIT.none}${recommend === "none" ? " (Recommended)" : ""}`, description: "Workers change the folder directly, one task after another; checks run, nothing is committed" };
|
|
116
|
+
const work = repos.slice(0, 4).map((repo) => {
|
|
117
|
+
const name = repo.replace(/\/$/, "");
|
|
118
|
+
return { label: `${GIT.repo} ${name}`, description: `This job's worktrees, checks and merge happen in ${name}/; the session and the job stay here, so the context still spans every repository` };
|
|
119
|
+
});
|
|
120
|
+
return [{
|
|
121
|
+
header: H.git,
|
|
122
|
+
question: `${path} is not a git repository (${files} files, ${size}). How should the workers work there?`,
|
|
123
|
+
options: [...work, ...(recommend === "init" ? [init, none] : [none, init]), { label: GIT.cancel, description: "Start nothing" }],
|
|
124
|
+
}];
|
|
125
|
+
}
|
|
126
|
+
const is = (answer, label) => answer.trim().toLowerCase().replace(/\s*\(recommended\)\s*$/, "") === label.toLowerCase();
|
|
127
|
+
const pick = (answers, labels) => {
|
|
128
|
+
for (const a of answers) {
|
|
129
|
+
const key = Object.keys(labels).find((k) => is(a, labels[k]));
|
|
130
|
+
if (key)
|
|
131
|
+
return { key };
|
|
132
|
+
}
|
|
133
|
+
const said = answers.find((a) => a.trim());
|
|
134
|
+
return said ? { said: said.trim() } : {};
|
|
135
|
+
};
|
|
136
|
+
export function readForm(questions, answers) {
|
|
137
|
+
const at = (header) => questions.findIndex((q) => q.header === header);
|
|
138
|
+
const of = (i) => (i >= 0 ? answers[i] ?? [] : []);
|
|
139
|
+
if (at(H.start) >= 0) {
|
|
140
|
+
const ticked = of(at(H.options));
|
|
141
|
+
const { key, said } = pick(of(at(H.start)), START);
|
|
142
|
+
const options = {
|
|
143
|
+
auto: ticked.some((a) => is(a, OPTION.auto)),
|
|
144
|
+
parallel: ticked.some((a) => is(a, OPTION.parallel)),
|
|
145
|
+
review: ticked.some((a) => is(a, OPTION.review)),
|
|
146
|
+
// Unticked is the default: cloud allowed. The box is an opt-out for sensitive work.
|
|
147
|
+
cloud: !ticked.some((a) => is(a, OPTION.local)),
|
|
148
|
+
optimize: ticked.some((a) => is(a, OPTION.optimize)),
|
|
149
|
+
};
|
|
150
|
+
return { kind: "start", options, ...(key ? { decision: key } : {}), ...(said ? { said } : {}) };
|
|
151
|
+
}
|
|
152
|
+
if (at(H.access) >= 0) {
|
|
153
|
+
const { key, said } = pick(of(at(H.access)), ACCESS);
|
|
154
|
+
return { kind: "access", question: questions[at(H.access)].question ?? "", ...(key ? { open: key === "open" } : {}), ...(said ? { said } : {}) };
|
|
155
|
+
}
|
|
156
|
+
if (at(H.mode) >= 0) {
|
|
157
|
+
const { key, said } = pick(of(at(H.mode)), MODE);
|
|
158
|
+
return { kind: "mode", ...(key === "build" ? { decision: "build" } : key === "plan" ? { decision: "stay" } : {}), ...(said ? { said } : {}) };
|
|
159
|
+
}
|
|
160
|
+
if (at(H.git) >= 0) {
|
|
161
|
+
const { key, said } = pick(of(at(H.git)), GIT);
|
|
162
|
+
const work = /^Work in (.+)$/i.exec(said ?? "");
|
|
163
|
+
if (work)
|
|
164
|
+
return { kind: "git", decision: "repo", repo: work[1].trim() };
|
|
165
|
+
return { kind: "git", ...(key ? { decision: key } : {}), ...(said ? { said } : {}) };
|
|
166
|
+
}
|
|
167
|
+
const grants = questions.map((q, i) => ({ q, i })).filter(({ q }) => /^Grant G\d+$/.test(q.header ?? ""));
|
|
168
|
+
if (grants.length) {
|
|
169
|
+
// One form with several grant questions is a batch (src/grants.ts): the user answered each of them on its own.
|
|
170
|
+
if (grants.length > 1) {
|
|
171
|
+
return {
|
|
172
|
+
kind: "grants",
|
|
173
|
+
answers: grants.map(({ q, i }) => {
|
|
174
|
+
const { key, said } = pick(of(i), GRANT);
|
|
175
|
+
return { id: q.header.split(" ")[1], ...(key ? { granted: key === "job" } : {}), ...(said ? { said } : {}) };
|
|
176
|
+
}),
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
const { q, i } = grants[0];
|
|
180
|
+
const { key, said } = pick(of(i), GRANT);
|
|
181
|
+
return { kind: "grant", id: q.header.split(" ")[1], ...(key ? { granted: key === "job" } : {}), ...(said ? { said } : {}) };
|
|
182
|
+
}
|
|
183
|
+
const ask = questions.findIndex((q) => /^Request A\d+$/.test(q.header ?? ""));
|
|
184
|
+
if (ask >= 0) {
|
|
185
|
+
const { key, said } = pick(of(ask), ASK);
|
|
186
|
+
return { kind: "ask", id: questions[ask].header.split(" ")[1], ...(key ? { decision: key } : {}), ...(said ? { said } : {}) };
|
|
187
|
+
}
|
|
188
|
+
return undefined;
|
|
189
|
+
}
|
|
190
|
+
// The answer lists out of the question tool's result: { output: { answers } } or { metadata: { answers } }.
|
|
191
|
+
export function answersOf(result) {
|
|
192
|
+
const r = result;
|
|
193
|
+
const a = r?.metadata?.answers ?? r?.output?.answers;
|
|
194
|
+
return Array.isArray(a) && a.every((x) => Array.isArray(x)) ? a.map((x) => x.map(String)) : undefined;
|
|
195
|
+
}
|
package/dist/gate.js
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
// G0, the local-first gate (design.md §20, §21): three guards on a job's or task's text, answered on the machine —
|
|
2
|
+
// injection and sensitive. Cloud mode may take them to the cloud only for a session whose user said so
|
|
3
|
+
// (A2-T5); otherwise they stay local.
|
|
4
|
+
//
|
|
5
|
+
// Until our own GLiNER fine-tune passes the guard bench, a "yes" never routes or blocks on its own: it asks the user
|
|
6
|
+
// (Phase A9 showed the available fine-tune flagging legitimate security work). The user's answer sets the
|
|
7
|
+
// job's flags: local only, uncensored allowed, or on as it is.
|
|
8
|
+
import { GUARD_FLOOR, GUARDS } from "./catalog.js";
|
|
9
|
+
// A long text is read in windows (P6-T1b): one classification pools its whole input into one judgement, so a short
|
|
10
|
+
// injection at the end of a long harmless text was diluted to nothing (measured 2026-11-18 on gliner-guard: +6.1 logit
|
|
11
|
+
// at 700 characters, +0.3 at 8 000, nothing from 16 000), and before this the client sent only the last 2 000
|
|
12
|
+
// characters anyway. Windows of 1 500 characters overlap by 200, so a sentence cut at one edge is whole in the next;
|
|
13
|
+
// the highest score per guard counts, because one window that is an injection makes the text one. Past MAX_WINDOWS the
|
|
14
|
+
// rest is not read, and the result says how much was left out.
|
|
15
|
+
export const WINDOW = 1500;
|
|
16
|
+
export const OVERLAP = 200;
|
|
17
|
+
export const MAX_WINDOWS = 24;
|
|
18
|
+
export function windows(text, size = WINDOW, overlap = OVERLAP, max = MAX_WINDOWS) {
|
|
19
|
+
if (text.length <= size)
|
|
20
|
+
return { parts: [text], unread: 0 };
|
|
21
|
+
const step = size - overlap;
|
|
22
|
+
const parts = [];
|
|
23
|
+
let at = 0;
|
|
24
|
+
for (; at < text.length && parts.length < max; at += step) {
|
|
25
|
+
parts.push(text.slice(at, at + size));
|
|
26
|
+
if (at + size >= text.length)
|
|
27
|
+
return { parts, unread: 0 };
|
|
28
|
+
}
|
|
29
|
+
return { parts, unread: Math.max(0, text.length - (at - step + size)) };
|
|
30
|
+
}
|
|
31
|
+
// The same text scored 0.59 and 2e-8 for injection in two runs of Phase D, so every text is scored twice and the
|
|
32
|
+
// higher score counts: a guard errs towards asking the user. Each window is scored that way.
|
|
33
|
+
export async function checkGuards(decider, text, job, task, repeats = 2, session) {
|
|
34
|
+
const scores = {};
|
|
35
|
+
let checked = false;
|
|
36
|
+
let decision;
|
|
37
|
+
const { parts, unread } = windows(text);
|
|
38
|
+
for (const part of parts) {
|
|
39
|
+
for (let i = 0; i < repeats; i++) {
|
|
40
|
+
const asked = await decider.ask("G0", { text: part }, GUARDS, { job, task, ...(session ? { session } : {}) });
|
|
41
|
+
decision ??= asked.id;
|
|
42
|
+
for (const g of Object.keys(GUARDS)) {
|
|
43
|
+
const a = asked.decision.answers[g];
|
|
44
|
+
if (a?.type === "noul")
|
|
45
|
+
scores[g] = Math.max(scores[g] ?? 0, a.noul);
|
|
46
|
+
}
|
|
47
|
+
checked ||= asked.backend !== "rules" && Object.keys(asked.decision.answers).length > 0;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return { flagged: Object.keys(scores).filter((g) => scores[g] >= GUARD_FLOOR), scores, checked, decision, ...(unread ? { unread } : {}) };
|
|
51
|
+
}
|
|
52
|
+
// Indirect injection (E2b): text a worker did not write but reads (web pages, research notes, a worker's question)
|
|
53
|
+
// is checked for injection alone, in the same windows, since an injection can hide anywhere in a long page. Returns
|
|
54
|
+
// the highest score, or undefined when nothing local answered.
|
|
55
|
+
//
|
|
56
|
+
// It runs on every tool result a worker reads. With GLiNER2.5 (1.6 s per window on the CPU) it read only seven windows;
|
|
57
|
+
// the tuned successor answers one question in about 40 ms, so it reads as many windows as the guards do: 24 windows,
|
|
58
|
+
// about 1 s for a 31 000-character page.
|
|
59
|
+
export const INJECTION_WINDOWS = MAX_WINDOWS;
|
|
60
|
+
export async function injectionScore(decider, text, job, task, session) {
|
|
61
|
+
let best;
|
|
62
|
+
for (const part of windows(text, WINDOW, OVERLAP, INJECTION_WINDOWS).parts) {
|
|
63
|
+
const asked = await decider.ask("G0.injection", { text: part }, { injection: GUARDS.injection }, { job, task, ...(session ? { session } : {}) });
|
|
64
|
+
const a = asked.decision.answers.injection;
|
|
65
|
+
if (asked.backend !== "rules" && a?.type === "noul")
|
|
66
|
+
best = Math.max(best ?? 0, a.noul);
|
|
67
|
+
}
|
|
68
|
+
return best;
|
|
69
|
+
}
|
|
70
|
+
export const injected = (score) => (score ?? 0) >= GUARD_FLOOR;
|
|
71
|
+
// mode "cloud": sensitive only chooses local models, and there are none; only injection asks the user.
|
|
72
|
+
// (The cloud decider on the guard bench, 2026-10-05: injection 100 % recall with 0 % false alarms, sensitive a false alarm
|
|
73
|
+
// on 92 % of harmless cases.)
|
|
74
|
+
export function flagsWithoutUser(result, unchecked = "local", mode = "local") {
|
|
75
|
+
if (!result.checked)
|
|
76
|
+
return unchecked === "user" ? "ask_user" : { localOnly: unchecked === "local", gate: result };
|
|
77
|
+
const asks = mode === "cloud" ? result.flagged.filter((g) => g === "injection") : result.flagged;
|
|
78
|
+
return asks.length === 0 ? { gate: result } : "ask_user";
|
|
79
|
+
}
|
|
80
|
+
// The question the micromanager puts to the user when the gate flagged something.
|
|
81
|
+
export function gateQuestion(result, mode = "local") {
|
|
82
|
+
const what = {
|
|
83
|
+
injection: "the text may try to change the agents' rules (injection)",
|
|
84
|
+
sensitive: "it may hold data that should stay on this machine",
|
|
85
|
+
};
|
|
86
|
+
const lines = result.flagged.map((g) => `- ${what[g]} (${(result.scores[g] ?? 0).toFixed(2)})`);
|
|
87
|
+
return [
|
|
88
|
+
"The local check flagged this job:",
|
|
89
|
+
...lines,
|
|
90
|
+
"The check is not calibrated yet, so you decide. Answer with one of:",
|
|
91
|
+
...(mode === "cloud"
|
|
92
|
+
? ['"continue" (go on as normal, in the cloud) or "stop". Local models are switched off for now.']
|
|
93
|
+
: ['"always local" (keep everything on this machine), "use uncensored" (local uncensored models only),', '"continue" (go on as normal), or "stop".']),
|
|
94
|
+
].join("\n");
|
|
95
|
+
}
|
|
96
|
+
// The user's answer to the gate question; exact phrases, matched before any model.
|
|
97
|
+
export function gateAnswer(text) {
|
|
98
|
+
const t = text.trim().toLowerCase().replace(/[.!"]+$/g, "").replace(/^"/, "");
|
|
99
|
+
if (t === "always local" || t === "only local")
|
|
100
|
+
return { localOnly: true };
|
|
101
|
+
if (t === "use uncensored" || t === "uncensored")
|
|
102
|
+
return { localOnly: true, uncensored: true };
|
|
103
|
+
if (t === "continue" || t === "go on")
|
|
104
|
+
return {};
|
|
105
|
+
if (t === "stop")
|
|
106
|
+
return "stop";
|
|
107
|
+
return undefined;
|
|
108
|
+
}
|
package/dist/gatebox.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// The sandbox a check or a contract's evaluator runs in (A1-T12). Both are host-side `sh -c` commands written by a
|
|
2
|
+
// worker (a task's Checks: lines) or by a contract that worker's job carries, and both used to run with the user's full
|
|
3
|
+
// rights outside the sandbox every other worker command goes through. A check is promoted from a worktree, so it gets
|
|
4
|
+
// the same rules as the worker that wrote it: its own worktree (the plan area for a plan job), the registries and the
|
|
5
|
+
// job's grants, and the cleaned environment.
|
|
6
|
+
//
|
|
7
|
+
// With no sandbox on the machine there is nothing to run a check under; the gate says why (`skip`) and the caller
|
|
8
|
+
// reports it instead of executing the command unsandboxed. The one exception is D23 (A1-T14): a job the user confirmed
|
|
9
|
+
// for exactly this runs its checks unwrapped, and every result says so (`unsandboxed`), so nothing reads like a
|
|
10
|
+
// sandboxed run that was not.
|
|
11
|
+
import { cleanEnv, planRules, rulesFor, tempDirFor, withTemp } from "./sandbox.js";
|
|
12
|
+
import { planRoot } from "./writeguard.js";
|
|
13
|
+
// The gate of one run. Built per check run (the rules depend on the worktree and the grants), and cheap when the
|
|
14
|
+
// sandbox is off: nothing is wrapped and the caller skips — unless the user confirmed this job for exactly that, in
|
|
15
|
+
// which case the command runs as it is, with the cleaned environment and the job's grants, marked `unsandboxed`.
|
|
16
|
+
export async function gateFor(deps, input) {
|
|
17
|
+
const box = await deps.box();
|
|
18
|
+
const off = deps.sandboxOff?.(input.project, input.jobId) === true;
|
|
19
|
+
if (!box.available || off) {
|
|
20
|
+
// The user's switch is itself the confirmation; on a machine without a box the D23 grant still has to cover it.
|
|
21
|
+
if (off || deps.unsandboxed?.(input.project, input.jobId) === true) {
|
|
22
|
+
const grants = deps.grants(input.project, input.jobId);
|
|
23
|
+
return { unsandboxed: true, wrap: async (c) => c, env: cleanEnv(process.env, grants.env) };
|
|
24
|
+
}
|
|
25
|
+
return {
|
|
26
|
+
skip: off ? "the sandbox is switched off for this job" : `no sandbox on this machine${box.reason ? ` (${box.reason})` : ""}`,
|
|
27
|
+
wrap: async (c) => c,
|
|
28
|
+
env: {},
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
const grants = deps.grants(input.project, input.jobId);
|
|
32
|
+
const temp = tempDirFor(`${input.jobId}\0${input.worktree}`);
|
|
33
|
+
const rules = input.plan
|
|
34
|
+
? planRules({ role: input.role, writer: true, dir: input.dir, worktree: planRoot(input.project), domains: grants.domains, frozen: input.frozen ?? [], temp })
|
|
35
|
+
: rulesFor({ role: input.role, writer: input.writer, dir: input.dir, worktree: input.worktree, domains: grants.domains, frozen: input.frozen ?? [], temp });
|
|
36
|
+
return {
|
|
37
|
+
wrap: (command) => box.wrap(withTemp(command, temp), rules),
|
|
38
|
+
env: cleanEnv(process.env, grants.env),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
// The words a stage line adds for a check that ran without a box (D23, A1-T14). The user's grant is named where the
|
|
42
|
+
// board is read, so an unwrapped run never looks like a sandboxed one.
|
|
43
|
+
export const UNSANDBOXED_NOTE = " (unsandboxed, confirmed by the user)";
|
|
44
|
+
export function unsandboxedNote(results) {
|
|
45
|
+
return results.some((r) => r.unsandboxed === true) ? UNSANDBOXED_NOTE : "";
|
|
46
|
+
}
|