@0perator/operator 0.1.360-next.2 → 0.2.1
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/commands.js +7 -3
- package/dist/auth/identity.js +1 -0
- package/dist/auth/staff.js +55 -0
- package/dist/autonomy/delegate-mode.js +159 -0
- package/dist/autonomy/delegate.js +42 -15
- package/dist/autonomy/headless.js +7 -4
- package/dist/autonomy/index.js +2 -4
- 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 +336 -45
- 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/resume.js +125 -0
- package/dist/background/synthesis.js +25 -0
- package/dist/browser/engine.js +163 -0
- package/dist/browser/session.js +130 -140
- package/dist/bus/inbox.js +150 -6
- package/dist/cli.js +343 -86
- package/dist/config/features.js +3 -3
- package/dist/config/persona.js +29 -3
- package/dist/config/settings.js +262 -21
- package/dist/config/staff-prompt.js +12 -0
- package/dist/engine/agent.js +52 -41
- package/dist/engine/aurora.js +40 -8
- package/dist/engine/batch-scheduler.js +4 -13
- package/dist/engine/compaction.js +2 -2
- package/dist/engine/continuation.js +30 -32
- package/dist/engine/decision-points.js +2 -3
- package/dist/engine/fanout.js +16 -0
- package/dist/engine/loop-guard.js +26 -83
- package/dist/engine/messages.js +2 -2
- package/dist/engine/moa.js +18 -2
- package/dist/engine/native-vision-node.js +72 -0
- package/dist/engine/native-vision.js +103 -0
- package/dist/engine/selfheal.js +1 -1
- package/dist/engine/toolcalls.js +6 -6
- package/dist/engine/verify-gate.js +37 -7
- package/dist/gateway-cli.js +14 -3
- package/dist/index.js +3 -0
- package/dist/mcp/phone-server.js +30 -0
- package/dist/memory/live-progress.js +4 -5
- 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 +33 -17
- package/dist/permissions/signature.js +5 -0
- package/dist/permissions/tier.js +4 -2
- package/dist/phone-cli.js +65 -0
- package/dist/products/craft.js +2 -2
- package/dist/remote/grants.js +119 -0
- package/dist/remote/host.js +63 -6
- package/dist/router/models.js +29 -29
- package/dist/selfimprove/index.js +9 -7
- package/dist/services/preflight.js +35 -91
- package/dist/session.js +173 -46
- 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/classes.js +103 -0
- package/dist/tools/contract.js +1 -1
- package/dist/tools/craft.js +13 -2
- package/dist/tools/deferred.js +1 -0
- package/dist/tools/device/android.js +227 -0
- package/dist/tools/device/classify.js +127 -0
- package/dist/tools/device/deps.js +69 -0
- package/dist/tools/device/desktop.js +82 -0
- package/dist/tools/device/harness.js +262 -0
- package/dist/tools/device/iphone.js +206 -0
- package/dist/tools/device/mirroring-jxa.js +146 -0
- package/dist/tools/device/setup.js +90 -0
- package/dist/tools/device/tools.js +70 -0
- package/dist/tools/device/types.js +19 -0
- package/dist/tools/executor.js +25 -15
- package/dist/tools/generation-gateway.js +94 -0
- package/dist/tools/registry.js +95 -155
- package/dist/ui/App.js +18 -6
- package/dist/ui/ApprovalPrompt.js +10 -4
- package/dist/ui/BgPanel.js +17 -12
- package/dist/ui/Header.js +1 -6
- package/dist/ui/StatusRule.js +18 -7
- package/dist/ui/ToolStep.js +3 -3
- package/dist/ui/Transcript.js +36 -14
- package/dist/ui/UpdatePrompt.js +40 -0
- 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 +1 -1
- package/dist/ui/opsMode.js +20 -0
- package/dist/ui/slashCommands.js +1 -0
- package/dist/ui/types.js +0 -2
- package/dist/update-check.js +145 -0
- package/dist/update.js +59 -15
- package/dist/util/slash.js +2 -2
- package/package.json +4 -2
- package/src/tools/device/NOTICE +37 -0
- package/dist/browser/cdp.js +0 -271
- package/dist/tools/mutating.js +0 -15
package/dist/config/features.js
CHANGED
|
@@ -71,11 +71,11 @@ export const FEATURES = {
|
|
|
71
71
|
},
|
|
72
72
|
/** craft product (products/craft.ts): the hosted, account-owned, shareable surface (page/deck/doc/board/app)
|
|
73
73
|
* on the shared product rails — the promotion of artifact_create into a first-class owned, versioned product.
|
|
74
|
-
*
|
|
75
|
-
*
|
|
74
|
+
* The library tools (craft_list/get/update/delete) are on for every seat since 2026-11-29 (registry.ts
|
|
75
|
+
* craftToolsFor); this flag now adds only craft_create, which duplicates artifact_create. SPEC: products-craft-mdoc. */
|
|
76
76
|
craft: {
|
|
77
77
|
default: false,
|
|
78
|
-
description: "
|
|
78
|
+
description: "Add craft_create (a second way to make an artifact; artifact_create is the stock one). The artifact library tools are always on",
|
|
79
79
|
},
|
|
80
80
|
};
|
|
81
81
|
/** Env var that overrides one feature: camelCase → UPPER_SNAKE, e.g. classifierGate → KODE_FEATURE_CLASSIFIER_GATE. */
|
package/dist/config/persona.js
CHANGED
|
@@ -6,7 +6,7 @@ import { readFileSync, appendFileSync, mkdirSync, existsSync, writeFileSync, ren
|
|
|
6
6
|
import { join, dirname } from "node:path";
|
|
7
7
|
import { operatorPath, globalMemoriesPath } from "./home.js";
|
|
8
8
|
import { renderHarnessContext } from "./operator-harness.js";
|
|
9
|
-
import { renderToolCatalogue, registry } from "../tools/registry.js";
|
|
9
|
+
import { renderToolCatalogue, registry, cloudAgentToolsFor, mdocToolsFor, craftToolsFor } from "../tools/registry.js";
|
|
10
10
|
import { isFeatureEnabled } from "./features.js";
|
|
11
11
|
import { renderSkillsIndex } from "./skills-index.js";
|
|
12
12
|
import { decisionPointsEnabled } from "../engine/decision-points.js";
|
|
@@ -126,6 +126,24 @@ export function loadMemories(cwd = process.cwd()) {
|
|
|
126
126
|
}
|
|
127
127
|
return renderMemories(global, project);
|
|
128
128
|
}
|
|
129
|
+
/** What the memory budget left out of the prompt, read from the rendered block itself (so the owner and the model are
|
|
130
|
+
* told the same thing): one entry per file, e.g. `"Notes", 2 older notes — not loaded from .operator/memories.md`.
|
|
131
|
+
* The owner-facing counterpart of Claude Code's large-CLAUDE.md warning and Codex's AGENTS.md size cap. Pure. */
|
|
132
|
+
export function memoryOmissions(rendered) {
|
|
133
|
+
const out = [];
|
|
134
|
+
for (const m of rendered.matchAll(/\((\d+) older lessons? left out for the memory budget — all of them are in (.+?)\)/g)) {
|
|
135
|
+
out.push(`${m[1]} older lesson${m[1] === "1" ? "" : "s"} — not loaded from ${m[2]}`);
|
|
136
|
+
}
|
|
137
|
+
for (const m of rendered.matchAll(/\(left out for the memory budget: (.+?) — read (.+?) for them\)/g)) {
|
|
138
|
+
out.push(`${m[1]} — not loaded from ${m[2]}`);
|
|
139
|
+
}
|
|
140
|
+
return out;
|
|
141
|
+
}
|
|
142
|
+
/** The owner's one-line startup note when memory didn't fit its budget, or null. */
|
|
143
|
+
export function memoryBudgetNote(cwd = process.cwd()) {
|
|
144
|
+
const gone = memoryOmissions(loadMemories(cwd));
|
|
145
|
+
return gone.length ? `memory over budget: ${gone.join("; ")}. Move what matters into lessons or shorten the file.` : null;
|
|
146
|
+
}
|
|
129
147
|
/** Where a `/remember` note goes in a memories file: its end — or, when the file ends in the lessons section (the
|
|
130
148
|
* self-improvement loop creates it at the end, selfimprove/lessons.ts), just before that section's heading, so a note
|
|
131
149
|
* never lands among the lessons, where it would load under their heading. A char offset. */
|
|
@@ -297,7 +315,7 @@ export function basePersona(_cwd = process.cwd(), opts = {}) {
|
|
|
297
315
|
`go.mod is), in the foreground. A failing check is never ` +
|
|
298
316
|
`"expected": report it as failing, find out why, fix or re-run it properly, then call the work done. ` +
|
|
299
317
|
`A document deliverable has runnable checks too (a link check, \`docker compose config\` on an ` +
|
|
300
|
-
`embedded compose block, a script that sums the tables, a linter); a "checked <date>" stamp is written only ` +
|
|
318
|
+
`embedded compose block, a script that sums the tables, a linter); for a prose report, reading the file back is the check; a "checked <date>" stamp is written only ` +
|
|
301
319
|
`in the turn that opened that page.` +
|
|
302
320
|
`\n## How I work — the AXE self-check\nFor a bug I state the ROOT CAUSE in one line (not the symptom) and how ` +
|
|
303
321
|
`I confirmed it; I reuse the nearest existing pattern (a new pattern needs a reason); I stay scoped to what was ` +
|
|
@@ -549,9 +567,17 @@ export function composeSystemPrompt(o) {
|
|
|
549
567
|
renderHarnessContext(cwd) +
|
|
550
568
|
(lean ? LEAN_NOTE : loadHandoff()) +
|
|
551
569
|
(skillsIdx ? `\n\n## Skills installed locally (skill_fetch, on demand: <name> loads one; skill_fetch <name> <file_path> reads its references/templates/scripts)\n${skillsIdx}` : "") +
|
|
552
|
-
renderToolCatalogue(
|
|
570
|
+
renderToolCatalogue(sessionTools(o.settings), { lean, deferred }) +
|
|
553
571
|
(interactive ? renderEmbodimentGuide(!!o.settings.computer?.enabled, o.chauffeurReady ?? !!o.settings.mcp) : ""));
|
|
554
572
|
}
|
|
573
|
+
// The registry plus the product tools a Session merges in from the same settings (session.ts), so a flag-off
|
|
574
|
+
// catalogue names every tool the session can run (the artifact library is always on since 2026-11-29).
|
|
575
|
+
function sessionTools(settings) {
|
|
576
|
+
const tools = new Map(registry);
|
|
577
|
+
for (const t of [...cloudAgentToolsFor(settings), ...mdocToolsFor(settings), ...craftToolsFor(settings)])
|
|
578
|
+
tools.set(t.name, t);
|
|
579
|
+
return tools;
|
|
580
|
+
}
|
|
555
581
|
/** A background sub-agent's system prompt: Operator's lean behavioural core plus its ROLE — never a clone of the
|
|
556
582
|
* owner's session. No SOUL, owner memories, handoff or skills index; the repo's project context only for repo
|
|
557
583
|
* roles inside a git repo that is not the home folder (the home AGENTS.md is the owner's own project list, which
|
package/dist/config/settings.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
// operator/settings.json — a user configuration layer (backlog #49), same shape as a typical coding
|
|
2
2
|
// agent's settings.json. Loaded once at startup by cli.tsx. Precedence: env var > settings.json > built-in
|
|
3
|
-
// default.
|
|
4
|
-
//
|
|
5
|
-
|
|
3
|
+
// default. loadSettings never throws: a missing file means defaults; a broken one means the last good copy
|
|
4
|
+
// (settings.json.last-good) or defaults, with a warning from settingsLoadProblems(). saveSettings is atomic,
|
|
5
|
+
// locked, and throws when it cannot save.
|
|
6
|
+
import { readFileSync, mkdirSync, openSync, writeSync, fsyncSync, closeSync, fchmodSync, renameSync, unlinkSync, statSync, realpathSync } from "node:fs";
|
|
7
|
+
import { randomBytes } from "node:crypto";
|
|
6
8
|
import { dirname } from "node:path";
|
|
7
9
|
import { operatorPath } from "./home.js";
|
|
8
10
|
import { applyManagedPolicy, loadManagedPolicy } from "./managed.js";
|
|
@@ -73,7 +75,7 @@ const DEFAULTS = {
|
|
|
73
75
|
vision: { autostart: false, launchdLabel: "co.0perator.vision", plistPath: "~/Library/LaunchAgents/co.0perator.vision.plist", legacyLabels: ["axe.vision-bot"], url: "http://127.0.0.1:7788" },
|
|
74
76
|
stopOnExit: { searxng: true }, // aurora/autopilot are shared + never stopped; only the SearXNG container is
|
|
75
77
|
},
|
|
76
|
-
// MOA (2026-10-31, James): a planner/specialist team
|
|
78
|
+
// MOA (2026-10-31, James): a planner/specialist team — Cortana plans, delegates each step to a
|
|
77
79
|
// gpt-oss-20b sub-agent, checks the result and writes the answer (and reads images). Both on JL1 through the gateway.
|
|
78
80
|
// Was parallel drafts (gpt-oss-20b + Cortana) merged by Cortana (10/30). settings.moa replaces it wholesale.
|
|
79
81
|
moa: {
|
|
@@ -114,14 +116,143 @@ function deepMerge(base, override) {
|
|
|
114
116
|
}
|
|
115
117
|
return out;
|
|
116
118
|
}
|
|
117
|
-
|
|
119
|
+
function shapeOf(v) {
|
|
120
|
+
return v === null ? "null" : Array.isArray(v) ? "array" : typeof v;
|
|
121
|
+
}
|
|
122
|
+
/** Enumerated settings where a wrong value silently changes what the agent may do. */
|
|
123
|
+
const ENUMS = {
|
|
124
|
+
"permissions.mode": ["bypass", "audit", "gated"],
|
|
125
|
+
"sandbox.mode": ["off", "workspace", "strict"],
|
|
126
|
+
};
|
|
127
|
+
/** The file's values, minus any whose shape differs from the default's (a string where the default is an object,
|
|
128
|
+
* …) or that is not one of an ENUMS value. Each drop is reported in `problems`. Keys with no default pass through
|
|
129
|
+
* unchanged, so a newer build's settings keep working on an older one. */
|
|
130
|
+
function dropMistyped(base, file, problems, at = "") {
|
|
131
|
+
const out = {};
|
|
132
|
+
for (const [k, v] of Object.entries(file)) {
|
|
133
|
+
const key = at ? `${at}.${k}` : k;
|
|
134
|
+
const def = isPlainObject(base) ? base[k] : undefined;
|
|
135
|
+
if (def !== undefined && shapeOf(v) !== shapeOf(def)) {
|
|
136
|
+
problems.push(`settings.${key} ignored: expected ${shapeOf(def)}, got ${shapeOf(v)}`);
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
if (ENUMS[key] && !ENUMS[key].includes(v)) {
|
|
140
|
+
problems.push(`settings.${key} ignored: ${JSON.stringify(v)} is not one of ${ENUMS[key].join(" | ")}`);
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
out[k] = isPlainObject(v) && isPlainObject(def) ? dropMistyped(def, v, problems, key) : v;
|
|
144
|
+
}
|
|
145
|
+
return out;
|
|
146
|
+
}
|
|
147
|
+
/** "line L column C" for a JSON.parse error that only gives a position. */
|
|
148
|
+
function parseErrorReason(text, e) {
|
|
149
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
150
|
+
const m = /at position (\d+)/.exec(msg);
|
|
151
|
+
if (!m || /line \d+/.test(msg))
|
|
152
|
+
return msg;
|
|
153
|
+
const before = text.slice(0, Number(m[1])).split("\n");
|
|
154
|
+
return `${msg} (line ${before.length} column ${before[before.length - 1].length + 1})`;
|
|
155
|
+
}
|
|
118
156
|
function readSettingsFile(path) {
|
|
157
|
+
let text;
|
|
158
|
+
try {
|
|
159
|
+
text = readFileSync(path, "utf8");
|
|
160
|
+
}
|
|
161
|
+
catch (e) {
|
|
162
|
+
if (e.code === "ENOENT")
|
|
163
|
+
return { kind: "missing" };
|
|
164
|
+
return { kind: "broken", reason: e instanceof Error ? e.message : String(e) };
|
|
165
|
+
}
|
|
166
|
+
let value;
|
|
167
|
+
try {
|
|
168
|
+
value = JSON.parse(text);
|
|
169
|
+
}
|
|
170
|
+
catch (e) {
|
|
171
|
+
return { kind: "broken", reason: parseErrorReason(text, e) };
|
|
172
|
+
}
|
|
173
|
+
if (!isPlainObject(value))
|
|
174
|
+
return { kind: "broken", reason: `the top level is ${shapeOf(value)}, not an object` };
|
|
175
|
+
return { kind: "ok", value, text };
|
|
176
|
+
}
|
|
177
|
+
const lastGoodPath = (path) => `${path}.last-good`;
|
|
178
|
+
/** Write `text` to `path` atomically: a temp file in the same directory, fsync, rename. A symlinked settings file
|
|
179
|
+
* keeps its link: the write lands on the target. */
|
|
180
|
+
function writeFileAtomic(path, text, mode) {
|
|
181
|
+
let target = path;
|
|
182
|
+
try {
|
|
183
|
+
target = realpathSync(path);
|
|
184
|
+
}
|
|
185
|
+
catch { /* not there yet */ }
|
|
186
|
+
const tmp = `${target}.${process.pid}.${randomBytes(4).toString("hex")}.tmp`;
|
|
187
|
+
const fd = openSync(tmp, "wx", mode);
|
|
188
|
+
try {
|
|
189
|
+
writeSync(fd, text);
|
|
190
|
+
fchmodSync(fd, mode);
|
|
191
|
+
fsyncSync(fd);
|
|
192
|
+
}
|
|
193
|
+
catch (e) {
|
|
194
|
+
closeSync(fd);
|
|
195
|
+
try {
|
|
196
|
+
unlinkSync(tmp);
|
|
197
|
+
}
|
|
198
|
+
catch { /* already gone */ }
|
|
199
|
+
throw e;
|
|
200
|
+
}
|
|
201
|
+
closeSync(fd);
|
|
202
|
+
try {
|
|
203
|
+
renameSync(tmp, target);
|
|
204
|
+
}
|
|
205
|
+
catch (e) {
|
|
206
|
+
try {
|
|
207
|
+
unlinkSync(tmp);
|
|
208
|
+
}
|
|
209
|
+
catch { /* already gone */ }
|
|
210
|
+
throw e;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
function fileMode(path, fallback) {
|
|
119
214
|
try {
|
|
120
|
-
return
|
|
215
|
+
return statSync(path).mode & 0o777;
|
|
121
216
|
}
|
|
122
217
|
catch {
|
|
218
|
+
return fallback;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
/** Keep settings.json.last-good equal to the newest copy that parsed. A failure here costs only the fallback copy,
|
|
222
|
+
* so it is not an error for the caller. */
|
|
223
|
+
function refreshLastGood(path, text) {
|
|
224
|
+
const lg = lastGoodPath(path);
|
|
225
|
+
try {
|
|
226
|
+
if (readFileSync(lg, "utf8") === text)
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
catch { /* no copy yet */ }
|
|
230
|
+
try {
|
|
231
|
+
writeFileAtomic(lg, text, fileMode(path, 0o600));
|
|
232
|
+
}
|
|
233
|
+
catch { /* see above */ }
|
|
234
|
+
}
|
|
235
|
+
let loadProblems = [];
|
|
236
|
+
/** What the last loadSettings() could not use: an unreadable settings file, values it dropped. Empty when clean.
|
|
237
|
+
* cli.tsx prints these at boot. */
|
|
238
|
+
export function settingsLoadProblems() {
|
|
239
|
+
return loadProblems;
|
|
240
|
+
}
|
|
241
|
+
/** The settings file's usable values: the file, else its last good copy, else nothing. Problems go in `problems`. */
|
|
242
|
+
function readUsableSettings(path, problems) {
|
|
243
|
+
const read = readSettingsFile(path);
|
|
244
|
+
if (read.kind === "missing")
|
|
123
245
|
return undefined;
|
|
246
|
+
if (read.kind === "ok") {
|
|
247
|
+
refreshLastGood(path, read.text);
|
|
248
|
+
return read.value;
|
|
124
249
|
}
|
|
250
|
+
const lg = readSettingsFile(lastGoodPath(path));
|
|
251
|
+
const fallback = lg.kind === "ok"
|
|
252
|
+
? `using the last good copy ${lastGoodPath(path)}`
|
|
253
|
+
: "no last good copy, running on built-in defaults (permissions, models and routes are NOT yours)";
|
|
254
|
+
problems.push(`${path} is unreadable: ${read.reason} — ${fallback}. Fix the file; it was left as it is`);
|
|
255
|
+
return lg.kind === "ok" ? lg.value : undefined;
|
|
125
256
|
}
|
|
126
257
|
/** Fold env vars over the file+default merge — the top layer of the precedence stack. Only an env
|
|
127
258
|
* var that's actually set overrides; an unset one leaves the file/default value alone. */
|
|
@@ -135,6 +266,14 @@ function applyEnv(s) {
|
|
|
135
266
|
const base = process.env.KODE_AURORA ?? process.env.KODE_1M; // KODE_1M kept as a back-compat alias for the base override
|
|
136
267
|
if (base)
|
|
137
268
|
out.endpoints = { ...out.endpoints, aurora: { ...out.endpoints.aurora, base } };
|
|
269
|
+
// OPERATOR_FLEET_NODES — env lane for fleet.auroraNodes (which discovery.ts probes + auto-catalogs),
|
|
270
|
+
// alongside settings.json, for launchd/deployment config: "http://host:port,http://host:port".
|
|
271
|
+
const fleetNodes = process.env.OPERATOR_FLEET_NODES ?? process.env.KODE_FLEET_NODES;
|
|
272
|
+
if (fleetNodes) {
|
|
273
|
+
const nodes = fleetNodes.split(",").map((s) => s.trim()).filter(Boolean);
|
|
274
|
+
if (nodes.length)
|
|
275
|
+
out.fleet = { ...out.fleet, auroraNodes: nodes };
|
|
276
|
+
}
|
|
138
277
|
const pin = parseContextArg(process.env.KODE_CONTEXT); // context cap: 300k|600k|1m sets it, "auto" clears the file's pin
|
|
139
278
|
if (pin === null)
|
|
140
279
|
out.contextPin = undefined;
|
|
@@ -399,11 +538,12 @@ export function buildEndpointChain(s) {
|
|
|
399
538
|
seen.add(key);
|
|
400
539
|
chain.push(ep);
|
|
401
540
|
};
|
|
402
|
-
// 11/25: the built-in primary is the local router's `main` capability
|
|
403
|
-
//
|
|
541
|
+
// 11/25: the built-in primary is the local router's `main` capability. The shipped literal is retired Aurora's port,
|
|
542
|
+
// so it is no leg at all (11/30); an owner's own endpoints.aurora (or the gateway's discovered port) stays first.
|
|
404
543
|
if (isDefaultAuroraLiteral(aurora))
|
|
405
544
|
add({ ...ROUTER_MAIN });
|
|
406
|
-
|
|
545
|
+
else
|
|
546
|
+
add({ name: "operator-1m", base: aurora.base, model: aurora.model, ctxLimit: aurora.ctxWindow, token: resolveEndpointApiKey(aurora), loopbackAuth: true });
|
|
407
547
|
for (const base of (s.fleet?.auroraNodes ?? []).filter(Boolean)) {
|
|
408
548
|
const cfg = { base, model: aurora.model, ctxWindow: aurora.ctxWindow };
|
|
409
549
|
add({ name: `fleet-${hostLabel(base)}`, base, model: aurora.model, ctxLimit: aurora.ctxWindow, token: resolveEndpointApiKey(cfg) });
|
|
@@ -449,7 +589,10 @@ export function applySandboxFloor(s, sandboxPinned) {
|
|
|
449
589
|
return ownerPrivate ? s : { ...s, sandbox: { ...s.sandbox, mode: "workspace" } };
|
|
450
590
|
}
|
|
451
591
|
export function loadSettings() {
|
|
452
|
-
const
|
|
592
|
+
const problems = [];
|
|
593
|
+
const raw = readUsableSettings(settingsPath(), problems);
|
|
594
|
+
const file = raw ? dropMistyped(DEFAULTS, raw, problems) : undefined;
|
|
595
|
+
loadProblems = problems;
|
|
453
596
|
// structuredClone the base so a returned settings object never aliases the module-level DEFAULTS —
|
|
454
597
|
// deepMerge only recurses into keys the override touches, so an untouched nested endpoint would
|
|
455
598
|
// otherwise flow through by reference and a later mutation would corrupt defaults process-wide.
|
|
@@ -478,19 +621,117 @@ export function loadSettings() {
|
|
|
478
621
|
out = applySandboxFloor(out, sandboxPinned);
|
|
479
622
|
return resolveModelMode(out);
|
|
480
623
|
}
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
const current = readSettingsFile(path);
|
|
488
|
-
const merged = deepMerge(isPlainObject(current) ? current : {}, patch);
|
|
624
|
+
const LOCK_WAIT_MS = 2000;
|
|
625
|
+
const LOCK_STALE_MS = 10_000;
|
|
626
|
+
function sleepMs(ms) {
|
|
627
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
|
628
|
+
}
|
|
629
|
+
function lockIsStale(lock, body) {
|
|
489
630
|
try {
|
|
490
|
-
|
|
491
|
-
|
|
631
|
+
const { pid, at } = JSON.parse(body);
|
|
632
|
+
if (typeof at === "number" && Date.now() - at > LOCK_STALE_MS)
|
|
633
|
+
return true;
|
|
634
|
+
if (typeof pid === "number" && pid !== process.pid) {
|
|
635
|
+
try {
|
|
636
|
+
process.kill(pid, 0);
|
|
637
|
+
}
|
|
638
|
+
catch (e) {
|
|
639
|
+
if (e.code === "ESRCH")
|
|
640
|
+
return true;
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
return false;
|
|
492
644
|
}
|
|
493
645
|
catch {
|
|
494
|
-
|
|
646
|
+
try {
|
|
647
|
+
return Date.now() - statSync(lock).mtimeMs > LOCK_STALE_MS;
|
|
648
|
+
}
|
|
649
|
+
catch {
|
|
650
|
+
return false;
|
|
651
|
+
}
|
|
495
652
|
}
|
|
496
653
|
}
|
|
654
|
+
/** Run `fn` holding settings.json.lock (O_EXCL create; pid + timestamp inside). A lock older than LOCK_STALE_MS, or
|
|
655
|
+
* whose holder is gone, is broken; otherwise wait up to LOCK_WAIT_MS, then throw. */
|
|
656
|
+
function withSettingsLock(path, fn) {
|
|
657
|
+
const lock = `${path}.lock`;
|
|
658
|
+
const body = JSON.stringify({ pid: process.pid, at: Date.now(), id: randomBytes(6).toString("hex") });
|
|
659
|
+
const deadline = Date.now() + LOCK_WAIT_MS;
|
|
660
|
+
for (;;) {
|
|
661
|
+
try {
|
|
662
|
+
const fd = openSync(lock, "wx", 0o600);
|
|
663
|
+
try {
|
|
664
|
+
writeSync(fd, body);
|
|
665
|
+
}
|
|
666
|
+
finally {
|
|
667
|
+
closeSync(fd);
|
|
668
|
+
}
|
|
669
|
+
break;
|
|
670
|
+
}
|
|
671
|
+
catch (e) {
|
|
672
|
+
if (e.code !== "EEXIST")
|
|
673
|
+
throw e;
|
|
674
|
+
}
|
|
675
|
+
let held = "";
|
|
676
|
+
try {
|
|
677
|
+
held = readFileSync(lock, "utf8");
|
|
678
|
+
}
|
|
679
|
+
catch {
|
|
680
|
+
continue;
|
|
681
|
+
}
|
|
682
|
+
if (lockIsStale(lock, held)) {
|
|
683
|
+
// Move it aside and check it is still the lock judged stale; a fresh one taken meanwhile is put back.
|
|
684
|
+
const aside = `${lock}.${process.pid}.${randomBytes(4).toString("hex")}.stale`;
|
|
685
|
+
try {
|
|
686
|
+
renameSync(lock, aside);
|
|
687
|
+
}
|
|
688
|
+
catch {
|
|
689
|
+
continue;
|
|
690
|
+
}
|
|
691
|
+
let moved = "";
|
|
692
|
+
try {
|
|
693
|
+
moved = readFileSync(aside, "utf8");
|
|
694
|
+
}
|
|
695
|
+
catch { /* gone */ }
|
|
696
|
+
try {
|
|
697
|
+
if (moved !== held)
|
|
698
|
+
renameSync(aside, lock);
|
|
699
|
+
else
|
|
700
|
+
unlinkSync(aside);
|
|
701
|
+
}
|
|
702
|
+
catch { /* its owner finished, or it is gone */ }
|
|
703
|
+
continue;
|
|
704
|
+
}
|
|
705
|
+
if (Date.now() >= deadline)
|
|
706
|
+
throw new Error(`${path} is locked by another Operator (${lock}: ${held.trim()}); not saved`);
|
|
707
|
+
sleepMs(25);
|
|
708
|
+
}
|
|
709
|
+
try {
|
|
710
|
+
return fn();
|
|
711
|
+
}
|
|
712
|
+
finally {
|
|
713
|
+
try {
|
|
714
|
+
if (readFileSync(lock, "utf8") === body)
|
|
715
|
+
unlinkSync(lock);
|
|
716
|
+
}
|
|
717
|
+
catch { /* already gone */ }
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
/** Persist a partial settings patch onto what is on disk NOW: under settings.json.lock it re-reads the file, deep-merges
|
|
721
|
+
* the patch (file values win for anything it does not touch) and writes it atomically, keeping the file's mode. A
|
|
722
|
+
* function patch is given the current file, for a change that depends on it (a list to append to). Throws when the
|
|
723
|
+
* file cannot be saved, including when it is unreadable (it is never written over). */
|
|
724
|
+
export function saveSettings(patch) {
|
|
725
|
+
const path = settingsPath();
|
|
726
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
727
|
+
withSettingsLock(path, () => {
|
|
728
|
+
const current = readSettingsFile(path);
|
|
729
|
+
if (current.kind === "broken")
|
|
730
|
+
throw new Error(`${path} is unreadable (${current.reason}); not saved over it — fix the file first`);
|
|
731
|
+
const base = current.kind === "ok" ? current.value : {};
|
|
732
|
+
const text = JSON.stringify(deepMerge(base, typeof patch === "function" ? patch(base) : patch), null, 2) + "\n";
|
|
733
|
+
const mode = fileMode(path, 0o600);
|
|
734
|
+
writeFileAtomic(path, text, mode);
|
|
735
|
+
refreshLastGood(path, text);
|
|
736
|
+
});
|
|
737
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// Operating standards added to the system prompt for staff ("op") only. Not shipped to anyone else: the wiring calls
|
|
2
|
+
// staffPromptAddition(userType()), which is empty for an external user. Plain operating rules, no internal names.
|
|
3
|
+
import { userTypeAtLeast } from "../auth/staff.js";
|
|
4
|
+
export const STAFF_PROMPT = [
|
|
5
|
+
"Staff operating standards:",
|
|
6
|
+
"- Write no comments unless the reason is genuinely non-obvious.",
|
|
7
|
+
"- Verify before you say it is done: run the real check, and report a failure as a failure.",
|
|
8
|
+
"- Keep the text between tool calls short; keep a final summary short and concrete.",
|
|
9
|
+
"- Do exactly what was asked and stop; mention, do not do, anything adjacent.",
|
|
10
|
+
"- If a request rests on a misconception, say so plainly before acting.",
|
|
11
|
+
].join("\n");
|
|
12
|
+
export const staffPromptAddition = (type) => (userTypeAtLeast(type, "op") ? STAFF_PROMPT : "");
|