@0perator/operator 0.1.62 → 0.1.154
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1035 -0
- package/LICENSE +19 -0
- package/dist/acp/agent.js +103 -0
- package/dist/acp/run.js +23 -0
- package/dist/auth/client.js +4 -1
- package/dist/auth/login-intent.js +12 -0
- package/dist/autonomy/board-run.js +65 -0
- package/dist/autonomy/board.js +83 -0
- package/dist/autonomy/dream.js +71 -0
- package/dist/autonomy/headless.js +70 -0
- package/dist/autonomy/index.js +260 -0
- package/dist/autonomy/keepawake.js +84 -0
- package/dist/autonomy/loop.js +82 -0
- package/dist/autonomy/reporter.js +54 -0
- package/dist/autonomy/routine-run.js +25 -0
- package/dist/autonomy/routines.js +173 -0
- package/dist/autonomy/session-factory.js +61 -0
- package/dist/background/index.js +275 -20
- package/dist/background/worktree.js +62 -0
- package/dist/cli.js +518 -95
- package/dist/config/brand.js +81 -0
- package/dist/config/operator-harness.js +86 -0
- package/dist/config/persona.js +174 -0
- package/dist/config/settings.js +98 -9
- package/dist/engine/agent.js +447 -51
- package/dist/engine/aurora.js +180 -64
- package/dist/engine/compaction.js +97 -5
- package/dist/engine/grandmaster.js +69 -10
- package/dist/engine/router-adapter.js +3 -0
- package/dist/engine/selfheal.js +35 -0
- package/dist/engine/verify-gate.js +81 -0
- package/dist/mcp/index.js +1 -1
- package/dist/permissions/index.js +13 -7
- package/dist/router/models.js +1 -1
- package/dist/router/router.js +46 -7
- package/dist/selfimprove/index.js +88 -0
- package/dist/services/preflight.js +42 -1
- package/dist/session.js +239 -22
- package/dist/telemetry/events.js +9 -0
- package/dist/tools/executor.js +62 -24
- package/dist/tools/git-status.js +71 -0
- package/dist/tools/mutating.js +9 -0
- package/dist/tools/registry.js +247 -26
- package/dist/tools/result-cap.js +23 -0
- package/dist/tools/searxng.js +42 -2
- package/dist/tools/shell-context.js +17 -0
- package/dist/ui/ActivitySpinner.js +6 -5
- package/dist/ui/App.js +23 -5
- package/dist/ui/AuthScreen.js +1 -1
- package/dist/ui/BgPanel.js +60 -5
- package/dist/ui/Composer.js +135 -13
- package/dist/ui/Header.js +6 -4
- package/dist/ui/InputRule.js +2 -1
- package/dist/ui/Markdown.js +69 -10
- package/dist/ui/Masthead.js +6 -4
- package/dist/ui/PlanPane.js +23 -0
- package/dist/ui/QuestionPrompt.js +22 -8
- package/dist/ui/StatsCard.js +15 -0
- package/dist/ui/StatusRule.js +13 -4
- package/dist/ui/SummaryCard.js +18 -0
- package/dist/ui/Table.js +114 -0
- package/dist/ui/ThinkingSpinner.js +6 -4
- package/dist/ui/ToolBatch.js +12 -0
- package/dist/ui/ToolStep.js +12 -4
- package/dist/ui/Transcript.js +30 -6
- package/dist/ui/chart.js +34 -0
- package/dist/ui/editdiff.js +84 -0
- package/dist/ui/highlight.js +89 -0
- package/dist/ui/osc.js +32 -0
- package/dist/ui/planExit.js +26 -0
- package/dist/ui/term.js +16 -0
- package/dist/ui/theme.js +60 -0
- package/dist/ui/tree.js +71 -0
- package/dist/util/slash.js +15 -0
- package/dist/util/throttle.js +28 -0
- package/package.json +11 -2
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// Single-source Operator brand. The canonical brand lives in the AuthGate "operator" tenant
|
|
2
|
+
// (GET /api/apps/operator/brand); this is the ONE client-side accessor the CLI (and ACP/gateway) read, so
|
|
3
|
+
// the terminal's identity text matches the web/gate/mobile surfaces. Offline-first by construction: the
|
|
4
|
+
// render reads a SYNCHRONOUS cache/default and a background refresh updates the cache for next launch, so a
|
|
5
|
+
// boot never waits on the network and works fully offline.
|
|
6
|
+
//
|
|
7
|
+
// Platform brand decision (Option B, James 2026-09-27): natives adopt the NAME/identity text only. The CLI
|
|
8
|
+
// keeps its own product accent — violet #b98cff — so `brand_color` from the endpoint (tenant teal #5cc9a0)
|
|
9
|
+
// is deliberately IGNORED here. Only brand_name / gate_title / domain / logo are adopted. Best-effort,
|
|
10
|
+
// never throws.
|
|
11
|
+
import { readFileSync, writeFileSync, mkdirSync } from "node:fs";
|
|
12
|
+
import { homedir } from "node:os";
|
|
13
|
+
import { join, dirname } from "node:path";
|
|
14
|
+
// CLI defaults — used offline and on first run. brand_color is the CLI's violet accent, NOT the tenant teal.
|
|
15
|
+
export const BRAND_DEFAULT = {
|
|
16
|
+
brand_name: "Operator",
|
|
17
|
+
gate_title: "Sign in with Operator",
|
|
18
|
+
brand_color: "#b98cff",
|
|
19
|
+
brand_logo_url: "",
|
|
20
|
+
brand_domain: "0perator.co",
|
|
21
|
+
};
|
|
22
|
+
const BRAND_URL = process.env.AXE_BRAND_URL ?? "https://authgate.cloud/api/apps/operator/brand";
|
|
23
|
+
const CACHE_TTL_MS = 60 * 60 * 1000; // 1h — brand rarely changes; keeps launch-time refreshes rare
|
|
24
|
+
const FETCH_TIMEOUT_MS = 4000;
|
|
25
|
+
function cachePath() { return join(homedir(), ".axe", "operator", "brand-cache.json"); }
|
|
26
|
+
function readCache() {
|
|
27
|
+
try {
|
|
28
|
+
return JSON.parse(readFileSync(cachePath(), "utf8"));
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function writeCache(brand) {
|
|
35
|
+
try {
|
|
36
|
+
const p = cachePath();
|
|
37
|
+
mkdirSync(dirname(p), { recursive: true });
|
|
38
|
+
writeFileSync(p, JSON.stringify({ brand, at: Date.now() }));
|
|
39
|
+
}
|
|
40
|
+
catch { /* best-effort */ }
|
|
41
|
+
}
|
|
42
|
+
// Merge only the fields the tenant is authoritative for (Option B: name/title/domain/logo text). The CLI's
|
|
43
|
+
// own accent is kept — a raw brand_color is never adopted here. Pure + exported so it's unit-testable.
|
|
44
|
+
export function adoptBrand(raw) {
|
|
45
|
+
const r = raw ?? {};
|
|
46
|
+
return {
|
|
47
|
+
...BRAND_DEFAULT,
|
|
48
|
+
brand_name: r.brand_name?.trim() || BRAND_DEFAULT.brand_name,
|
|
49
|
+
gate_title: r.gate_title?.trim() || BRAND_DEFAULT.gate_title,
|
|
50
|
+
brand_domain: r.brand_domain?.trim() || BRAND_DEFAULT.brand_domain,
|
|
51
|
+
brand_logo_url: typeof r.brand_logo_url === "string" ? r.brand_logo_url : BRAND_DEFAULT.brand_logo_url,
|
|
52
|
+
// brand_color intentionally NOT taken from `raw` — the CLI stays violet (Option B).
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
// Synchronous, boot-safe: the cached brand (or the default). NEVER touches the network — this is what the
|
|
56
|
+
// masthead/status render at startup.
|
|
57
|
+
export function brandSync() {
|
|
58
|
+
const c = readCache();
|
|
59
|
+
return c?.brand ? adoptBrand(c.brand) : BRAND_DEFAULT;
|
|
60
|
+
}
|
|
61
|
+
// Background refresh: fetch the tenant brand and cache it for the NEXT launch. Best-effort, short timeout,
|
|
62
|
+
// never throws, never blocks; skips the network while the cache is still fresh. Fire-and-forget at startup.
|
|
63
|
+
export async function refreshBrand() {
|
|
64
|
+
const c = readCache();
|
|
65
|
+
if (c && Date.now() - c.at < CACHE_TTL_MS)
|
|
66
|
+
return adoptBrand(c.brand);
|
|
67
|
+
try {
|
|
68
|
+
const ctrl = new AbortController();
|
|
69
|
+
const timer = setTimeout(() => ctrl.abort(), FETCH_TIMEOUT_MS);
|
|
70
|
+
const res = await fetch(BRAND_URL, { signal: ctrl.signal });
|
|
71
|
+
clearTimeout(timer);
|
|
72
|
+
if (!res.ok)
|
|
73
|
+
return brandSync();
|
|
74
|
+
const brand = adoptBrand((await res.json()));
|
|
75
|
+
writeCache(brand);
|
|
76
|
+
return brand;
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
return brandSync();
|
|
80
|
+
}
|
|
81
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// Repo-local harness: `.operator/agents/*.md` (named sub-agent personas) and `.operator/commands/*.md`
|
|
2
|
+
// (named command playbooks). The vendor-neutral analog of a `.claude/agents|commands` directory — a repo
|
|
3
|
+
// SHIPS its own agents and commands so every Operator session working in it has them, instead of them
|
|
4
|
+
// living in one operator's home directory. Pure, best-effort, never throws — a missing dir is normal.
|
|
5
|
+
//
|
|
6
|
+
// A def file is markdown with optional YAML-ish frontmatter:
|
|
7
|
+
// ---
|
|
8
|
+
// name: code-reviewer
|
|
9
|
+
// description: Reviews a diff for correctness, security, and repo conventions.
|
|
10
|
+
// ---
|
|
11
|
+
// <body — the persona/system prompt for an agent, or the playbook for a command>
|
|
12
|
+
// `name` defaults to the filename (sans .md); `description` defaults to empty.
|
|
13
|
+
import { readFileSync, readdirSync } from "node:fs";
|
|
14
|
+
import { join } from "node:path";
|
|
15
|
+
/** Parse one def file: split optional frontmatter, pull name/description, keep the body. */
|
|
16
|
+
export function parseHarnessDef(file, raw) {
|
|
17
|
+
const base = (file.split("/").pop() ?? file).replace(/\.md$/i, "");
|
|
18
|
+
let name = base;
|
|
19
|
+
let description = "";
|
|
20
|
+
let body = raw.trim();
|
|
21
|
+
const m = raw.match(/^?---\r?\n([\s\S]*?)\r?\n---\r?\n?([\s\S]*)$/);
|
|
22
|
+
if (m) {
|
|
23
|
+
const fm = m[1];
|
|
24
|
+
const nm = fm.match(/^\s*name:\s*(.+?)\s*$/m);
|
|
25
|
+
if (nm)
|
|
26
|
+
name = nm[1].trim().replace(/^["']|["']$/g, "");
|
|
27
|
+
const dm = fm.match(/^\s*description:\s*(.+?)\s*$/m);
|
|
28
|
+
if (dm)
|
|
29
|
+
description = dm[1].trim().replace(/^["']|["']$/g, "");
|
|
30
|
+
body = m[2].trim();
|
|
31
|
+
}
|
|
32
|
+
return { name, description, body, file };
|
|
33
|
+
}
|
|
34
|
+
function loadDir(dir) {
|
|
35
|
+
let files;
|
|
36
|
+
try {
|
|
37
|
+
files = readdirSync(dir);
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
return [];
|
|
41
|
+
} // dir absent → no defs (normal)
|
|
42
|
+
const out = [];
|
|
43
|
+
for (const f of files.sort()) {
|
|
44
|
+
if (!f.toLowerCase().endsWith(".md") || f.startsWith("."))
|
|
45
|
+
continue;
|
|
46
|
+
try {
|
|
47
|
+
const d = parseHarnessDef(join(dir, f), readFileSync(join(dir, f), "utf8"));
|
|
48
|
+
if (d.body)
|
|
49
|
+
out.push(d);
|
|
50
|
+
}
|
|
51
|
+
catch { /* unreadable — skip */ }
|
|
52
|
+
}
|
|
53
|
+
return out;
|
|
54
|
+
}
|
|
55
|
+
export function loadOperatorAgents(cwd = process.cwd()) {
|
|
56
|
+
return loadDir(join(cwd, ".operator", "agents"));
|
|
57
|
+
}
|
|
58
|
+
export function loadOperatorCommands(cwd = process.cwd()) {
|
|
59
|
+
return loadDir(join(cwd, ".operator", "commands"));
|
|
60
|
+
}
|
|
61
|
+
/** The compact system-prompt section listing this repo's agents + commands so the model knows they exist
|
|
62
|
+
* and how to use them. Only names + descriptions (never the full bodies) — the bodies load on demand. */
|
|
63
|
+
export function renderHarnessContext(cwd = process.cwd()) {
|
|
64
|
+
const agents = loadOperatorAgents(cwd);
|
|
65
|
+
const commands = loadOperatorCommands(cwd);
|
|
66
|
+
if (!agents.length && !commands.length)
|
|
67
|
+
return "";
|
|
68
|
+
let out = "\n\n## Repo-local harness (.operator/ — ships with this repo)";
|
|
69
|
+
if (agents.length) {
|
|
70
|
+
out += "\n### Sub-agent personas\nSpawn one for a focused sub-task by passing its name as `spawn_agent`'s `agent` argument — its persona then guides that sub-agent:\n"
|
|
71
|
+
+ agents.map((a) => `- **${a.name}** — ${a.description || "(no description)"}`).join("\n");
|
|
72
|
+
}
|
|
73
|
+
if (commands.length) {
|
|
74
|
+
out += "\n### Commands\nRepo playbooks. When the user invokes one (e.g. `/" + commands[0].name + "`) or the work matches it, read `.operator/commands/<name>.md` and follow it:\n"
|
|
75
|
+
+ commands.map((c) => `- **/${c.name}** — ${c.description || "(no description)"}`).join("\n");
|
|
76
|
+
}
|
|
77
|
+
return out;
|
|
78
|
+
}
|
|
79
|
+
/** The persona body for a named repo-local agent (for spawn_agent). "" when there is no such agent. */
|
|
80
|
+
export function operatorAgentPersona(name, cwd = process.cwd()) {
|
|
81
|
+
const want = name.trim().toLowerCase();
|
|
82
|
+
if (!want)
|
|
83
|
+
return "";
|
|
84
|
+
const a = loadOperatorAgents(cwd).find((x) => x.name.toLowerCase() === want || x.file.toLowerCase().endsWith(`/${want}.md`));
|
|
85
|
+
return a?.body ?? "";
|
|
86
|
+
}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
// Persona helpers shared by the interactive shell (cli.tsx) and the headless autonomy runners
|
|
2
|
+
// (autonomy/session-factory.ts). Extracted here so an unattended `operator run/loop/board/dream`
|
|
3
|
+
// picks up the SAME project context + handoff the TUI does, without importing cli.tsx (which mounts
|
|
4
|
+
// Ink and refuses a non-TTY). Pure, best-effort, never throws — a missing file is normal.
|
|
5
|
+
import { readFileSync, appendFileSync, mkdirSync } from "node:fs";
|
|
6
|
+
import { homedir } from "node:os";
|
|
7
|
+
import { join, dirname } from "node:path";
|
|
8
|
+
// Project context: auto-load a per-repo instructions file (AGENTS.md / CLAUDE.md / .operator/AGENTS.md)
|
|
9
|
+
// from `cwd` and append it to the system prompt, so Operator picks up house rules, conventions and build
|
|
10
|
+
// commands the way modern coding agents do. First match wins; capped so a huge file can't blow the prompt.
|
|
11
|
+
export function loadProjectContext(cwd = process.cwd()) {
|
|
12
|
+
for (const name of ["AGENTS.md", "CLAUDE.md", ".operator/AGENTS.md", "OPERATOR.md"]) {
|
|
13
|
+
try {
|
|
14
|
+
const t = readFileSync(join(cwd, name), "utf8").trim();
|
|
15
|
+
if (t)
|
|
16
|
+
return `\n\n## Project context (${name}, auto-loaded from the working directory)\n${t.slice(0, 8000)}`;
|
|
17
|
+
}
|
|
18
|
+
catch { /* not present — try the next */ }
|
|
19
|
+
}
|
|
20
|
+
return "";
|
|
21
|
+
}
|
|
22
|
+
// Memory files (memories.md) — Operator's flat, always-loaded memory layer, mirroring how a modern coding
|
|
23
|
+
// agent loads a GLOBAL user memory (every project) PLUS a PROJECT memory (this repo) verbatim at session
|
|
24
|
+
// start. Distinct from the semantic recall store (Session.memory, which surfaces notes by relevance): this
|
|
25
|
+
// is plain, human-editable markdown injected AS-IS, so a fact written once sits in front of the model every
|
|
26
|
+
// session. Global lives beside operator/settings.json (~/.axe/operator/memories.md; override with
|
|
27
|
+
// KODE_MEMORIES_FILE); project is .operator/memories.md, or a repo-root memories.md. Global is emitted
|
|
28
|
+
// FIRST and project LAST, so a repo-specific note overrides a global one — the same more-specific-wins
|
|
29
|
+
// precedence as the settings layer (and as the CLAUDE.md chain in comparable agents). Capped so a huge file
|
|
30
|
+
// can't blow the prompt; best-effort, never throws — a missing file is normal.
|
|
31
|
+
const MEMORIES_CAP = 6000;
|
|
32
|
+
export function globalMemoriesPath() {
|
|
33
|
+
return process.env.KODE_MEMORIES_FILE ?? join(homedir(), ".axe", "operator", "memories.md");
|
|
34
|
+
}
|
|
35
|
+
export function projectMemoriesPath(cwd = process.cwd()) {
|
|
36
|
+
return join(cwd, ".operator", "memories.md");
|
|
37
|
+
}
|
|
38
|
+
export function loadMemories(cwd = process.cwd()) {
|
|
39
|
+
let out = "";
|
|
40
|
+
try {
|
|
41
|
+
const t = readFileSync(globalMemoriesPath(), "utf8").trim();
|
|
42
|
+
if (t)
|
|
43
|
+
out += `\n\n## Global memory (memories.md — applies to every project)\n${t.slice(0, MEMORIES_CAP)}`;
|
|
44
|
+
}
|
|
45
|
+
catch { /* none yet */ }
|
|
46
|
+
for (const name of [".operator/memories.md", "memories.md"]) {
|
|
47
|
+
try {
|
|
48
|
+
const t = readFileSync(join(cwd, name), "utf8").trim();
|
|
49
|
+
if (t) {
|
|
50
|
+
out += `\n\n## Project memory (${name} — this repo)\n${t.slice(0, MEMORIES_CAP)}`;
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
catch { /* try the next */ }
|
|
55
|
+
}
|
|
56
|
+
return out;
|
|
57
|
+
}
|
|
58
|
+
// The write half of loadMemories — append one note to a memories.md so `/remember` keeps the flat file
|
|
59
|
+
// living, the way a `#`-style quick-add does in comparable agents. scope "global" targets
|
|
60
|
+
// ~/.axe/operator/memories.md (every project); "project" (default) targets ./.operator/memories.md. Creates
|
|
61
|
+
// the file (with a heading) and its parent dir on first write. Returns the path written, or "" on failure
|
|
62
|
+
// (best-effort, never throws).
|
|
63
|
+
export function appendMemory(text, scope = "project", cwd = process.cwd()) {
|
|
64
|
+
const note = text.trim();
|
|
65
|
+
if (!note)
|
|
66
|
+
return "";
|
|
67
|
+
const path = scope === "global" ? globalMemoriesPath() : projectMemoriesPath(cwd);
|
|
68
|
+
try {
|
|
69
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
70
|
+
let header = "";
|
|
71
|
+
try {
|
|
72
|
+
readFileSync(path, "utf8");
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
header = `# Operator memories\n\n> Always-loaded notes for ${scope === "global" ? "this user (every project)" : "this repo"}. One fact per line.\n\n`;
|
|
76
|
+
}
|
|
77
|
+
appendFileSync(path, `${header}- ${note}\n`);
|
|
78
|
+
return path;
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
return "";
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
// Session handoff: the note the previous session in THIS directory wrote for its future self (via the
|
|
85
|
+
// session_handoff tool), pointed at by KODE_HANDOFF_FILE. Auto-loaded so the agent resumes seamlessly.
|
|
86
|
+
export function loadHandoff() {
|
|
87
|
+
try {
|
|
88
|
+
const t = readFileSync(process.env.KODE_HANDOFF_FILE ?? "", "utf8").trim();
|
|
89
|
+
// The handoff grows by APPEND (auto-compaction adds a block each time context fills, newest last),
|
|
90
|
+
// so resume from the TAIL — the freshest state, not a stale head.
|
|
91
|
+
if (t) {
|
|
92
|
+
const tail = t.length > 6000 ? "…\n" + t.slice(-6000) : t;
|
|
93
|
+
return `\n\n## Handoff from your previous session here (continue from where it leaves off)\n${tail}\n\nResume seamlessly, and update it with session_handoff before you finish.`;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
catch { /* none yet */ }
|
|
97
|
+
return "";
|
|
98
|
+
}
|
|
99
|
+
// The base Operator persona (vendor-neutral, AXE-branded), independent of the TUI's embodiment guide.
|
|
100
|
+
// cli.tsx composes its full SYSTEM_PROMPT from settings.systemPrompt ?? this, plus loadProjectContext +
|
|
101
|
+
// loadHandoff + the embodiment guide; the headless factory reuses the same base + project/handoff so an
|
|
102
|
+
// unattended run behaves like the interactive one.
|
|
103
|
+
export function basePersona(cwd = process.cwd()) {
|
|
104
|
+
return (`You are Operator, AXE's terminal coding agent — built by AXE, running on AXE's own model. Refer to ` +
|
|
105
|
+
`yourself as Operator and to the platform as AXE; never call yourself or the platform Claude, ` +
|
|
106
|
+
`Anthropic, or any other vendor. When you encounter files or directories on disk named "claude", ` +
|
|
107
|
+
`".claude", "anthropic", etc., describe them neutrally (by their literal path, or as "AI tooling ` +
|
|
108
|
+
`files") — do not attribute them to a vendor. Use your tools to inspect and edit the ` +
|
|
109
|
+
`workspace; prefer doing over explaining. Answer concisely.` +
|
|
110
|
+
`\n## Fix what you find — don't stop to ask\nWhen you discover a bug or defect while doing or ` +
|
|
111
|
+
`testing your own work, FIX it, then re-run the check that proves the fix. Finding problems is not a ` +
|
|
112
|
+
`stopping point and a list of bugs is a to-do list, not a question. Fix every clear, mechanical, or ` +
|
|
113
|
+
`high-severity defect (syntax errors, broken references, stale or inconsistent data, wrong paths) on ` +
|
|
114
|
+
`your own initiative, then report "found N, fixed M" with the diff. Do NOT pause to ask "should I fix ` +
|
|
115
|
+
`these?", and do NOT move on to the next phase or task while known bugs from the current one are still ` +
|
|
116
|
+
`unfixed — that risks leaving them unfixed forever. Bring back to the user ONLY genuine judgment calls: ` +
|
|
117
|
+
`design decisions, real tradeoffs, or destructive/irreversible actions — never routine fixes. When in ` +
|
|
118
|
+
`doubt on a low-risk fix, make it and note what you did.` +
|
|
119
|
+
`\n## Verify by running before you claim done\nNever report that something works, passes, or is ` +
|
|
120
|
+
`complete on the strength of your own reasoning — RUN it and read the result first. Execute the actual ` +
|
|
121
|
+
`command, CLI, or code path you are claiming works; a task is done only when the check that proves it ` +
|
|
122
|
+
`has passed in front of you. Tests must assert BEHAVIOR (the CLI runs, a dependency resolves, the ` +
|
|
123
|
+
`output is correct), not merely that files exist — green tests that assert nothing are not proof, and ` +
|
|
124
|
+
`"all tests pass" while the program is broken is the worst possible report. If you did not run it, say ` +
|
|
125
|
+
`so plainly instead of calling it done.` +
|
|
126
|
+
`\n## How I work — the AXE self-check\nBefore acting: for a bug I state the ROOT CAUSE in one line ` +
|
|
127
|
+
`(not the symptom) and how I confirmed it; I reuse the nearest existing pattern (a new pattern needs a ` +
|
|
128
|
+
`reason); I stay scoped to exactly what was asked and don't touch the data layer or infra unless asked. ` +
|
|
129
|
+
`While building I match the surrounding code — naming, idioms, comment density — so my work is ` +
|
|
130
|
+
`indistinguishable from the repo owner's. (Finishing is governed by the two rules above: fix what I ` +
|
|
131
|
+
`find, and verify by running.) I record the non-obvious WHY in the repo's _ai-docs/, and commit clean: ` +
|
|
132
|
+
`a conventional \`type(scope): subject\` with explicit paths (never a blanket add in a shared checkout) ` +
|
|
133
|
+
`and no AI / Co-Authored-By / Claude-Session trailers.` +
|
|
134
|
+
`\n## This machine\nWorking dir: ${cwd}` +
|
|
135
|
+
`\nContext window: 307,200 tokens (300K) — you run on AXE's model served locally with a real 300K-token ` +
|
|
136
|
+
`context. You can hold large files and long histories; do not claim a different limit.` +
|
|
137
|
+
`\n## Running scripts — never inline a multi-line script\nFor anything more than a ONE-LINE snippet, write ` +
|
|
138
|
+
`the script to a file with file_write and run the file (\`python3 /tmp/probe.py\`). Do NOT embed a ` +
|
|
139
|
+
`multi-line program inside \`python3 -c "…"\` or \`bash -c "…"\`: the newlines, \`#\` comments and quotes ` +
|
|
140
|
+
`have to be escaped inside the tool-call JSON, and a slip there breaks the whole call (\`500: missing ` +
|
|
141
|
+
`closing quote\`) and wastes the turn. A short one-liner inline is fine; a real script goes to a file first.` +
|
|
142
|
+
`\n## Narrate as you work — keep the user with you\nYou run many tool calls per turn; do NOT go silent for ` +
|
|
143
|
+
`round after round and then dump everything at the end. Alongside a batch of tool calls, write ONE short ` +
|
|
144
|
+
`line (about a dozen words) on what you're about to do and why. After a batch that reveals something worth ` +
|
|
145
|
+
`knowing — a test result, a bug you found, a surprising file, a decision you just made — write ONE short ` +
|
|
146
|
+
`line on what you found and what's next. This is a running commentary that lets the user follow your ` +
|
|
147
|
+
`thinking in REAL TIME: terse, high-signal, one line, not an essay, and only when it adds understanding ` +
|
|
148
|
+
`(skip it for trivial reads). Silence for many rounds followed by a wall of text at the very end is the ` +
|
|
149
|
+
`exact failure mode to avoid — the user should feel like they are watching you think, not waiting on you. ` +
|
|
150
|
+
`Keep it to ONE short line and put your tool calls in the SAME message right after it — narration must ` +
|
|
151
|
+
`NEVER delay, crowd out, or replace the actual tool call, and never grow long enough to push a big ` +
|
|
152
|
+
`tool-call argument late in your output where it can get cut off.` +
|
|
153
|
+
`\n## Parallel tool calls\nWhen the next few steps are INDEPENDENT of each other, issue them as ` +
|
|
154
|
+
`multiple tool calls in a SINGLE message so they run in parallel. Only serialize when one call's ` +
|
|
155
|
+
`output feeds the next call's input. When you need the contents of several files, use the ` +
|
|
156
|
+
`read_files tool with all paths in ONE call — it reads them in parallel and is far more efficient ` +
|
|
157
|
+
`than issuing many sequential file_read calls.` +
|
|
158
|
+
`\n## Finding things\nTo search file CONTENTS use the search tool (ripgrep) scoped to a directory; ` +
|
|
159
|
+
`never run an unbounded \`find\` over the whole home directory. Narrow first.` +
|
|
160
|
+
`\n## HTTP requests (curl)\nTo call an HTTP endpoint, prefer the http_request tool (set method, headers, ` +
|
|
161
|
+
`body, timeout) — or web_fetch to READ a page, web_search to FIND one. These run NATIVELY and do NOT go ` +
|
|
162
|
+
`through the shell, so they keep working even when bash is failing or sandboxed. You can also use curl ` +
|
|
163
|
+
`via bash for anything special — custom headers (\`-H\`), methods (\`-X POST\`), following redirects ` +
|
|
164
|
+
`(\`-L\`), form/file uploads; a quick GET is \`curl -sS <url>\`, a JSON POST is \`curl -sS -X POST -H ` +
|
|
165
|
+
`'Content-Type: application/json' -d '<json>' <url>\`. Never conclude you "can't reach a URL" or have "no ` +
|
|
166
|
+
`way to make the request" without trying http_request — if bash won't run curl, http_request is your ` +
|
|
167
|
+
`no-shell fallback for the same call.` +
|
|
168
|
+
`\n## Git\nRead repo state with the git_status tool — ONE structured read (branch, ahead/behind, ` +
|
|
169
|
+
`staged/unstaged/untracked). Do not loop re-running raw \`git status\`/\`git add\` to work out state; ` +
|
|
170
|
+
`a clean tree means "nothing to commit", which is success, not a problem to investigate. Commit via ` +
|
|
171
|
+
`git_command (explicit paths, conventional message) or the checkpoint tool.` +
|
|
172
|
+
`\n## Scratchpad & handoff\nUse the scratchpad tool for private working notes; before finishing a ` +
|
|
173
|
+
`substantial task call session_handoff to record what you did, the state, and next steps.`);
|
|
174
|
+
}
|
package/dist/config/settings.js
CHANGED
|
@@ -6,22 +6,31 @@ import { readFileSync, writeFileSync, mkdirSync } from "node:fs";
|
|
|
6
6
|
import { homedir } from "node:os";
|
|
7
7
|
import { join, dirname } from "node:path";
|
|
8
8
|
import { DEFAULT_MODEL_ID } from "../router/models.js";
|
|
9
|
-
// The sole endpoint: Aurora on :8097 at its REAL served context —
|
|
10
|
-
//
|
|
11
|
-
//
|
|
9
|
+
// The sole endpoint: Aurora on :8097 at its REAL served context — 307,200 tokens (300K; the llama-server
|
|
10
|
+
// runs --ctx-size 307200 with q8_0 KV cache, standardized on JL1+JL2 2026-09-27). ctxWindow MUST match the
|
|
11
|
+
// server's real --ctx-size: an inflated value (it was 1048576/"1M") makes compaction fire far too late — the
|
|
12
|
+
// server's real ceiling is hit first, forcing a failover. Override base/model in settings.json for any
|
|
13
|
+
// OpenAI-compatible server.
|
|
12
14
|
const DEFAULTS = {
|
|
13
15
|
endpoints: {
|
|
14
|
-
aurora: { base: "http://127.0.0.1:8097", ctxWindow:
|
|
15
|
-
//
|
|
16
|
-
//
|
|
17
|
-
|
|
16
|
+
aurora: { base: "http://127.0.0.1:8097", ctxWindow: 307200, model: "aurora-code-1" },
|
|
17
|
+
// HA hot-standby: JL2 (64GB) serving Aurora @ 300K on the LAN — task #50, replaces the old
|
|
18
|
+
// dolphin3-tools:8b "8k trap". Same model + same real window as primary, so a failover holds any live
|
|
19
|
+
// session instead of truncating it. Point elsewhere / omit to disable.
|
|
20
|
+
failover: { base: "http://192.168.1.146:8097", ctxWindow: 307200, model: "aurora-code-1" },
|
|
18
21
|
},
|
|
22
|
+
modelMode: "local", // default: this node uses its own local model (endpoints.aurora); set "aurora" to use the shared fleet
|
|
23
|
+
fleet: { auroraNodes: ["http://192.168.1.103:8097", "http://192.168.1.146:8097"] }, // JL1, JL2 — the live Aurora serving nodes (priority order)
|
|
19
24
|
maxTokens: 32768, // generous per-reply output cap — 1M ctx has ample room; clampMaxTokens still trims
|
|
20
25
|
// to the space left after the prompt so a reply never overflows. A small cap (was
|
|
21
26
|
// 2048) forced the model to truncate + work around; this lets full files/answers land.
|
|
22
27
|
temperature: 0.7,
|
|
23
28
|
mcp: false,
|
|
24
29
|
memory: { recall: true },
|
|
30
|
+
selfImprove: { flywheel: true, memory: false, skills: false, reflect: false }, // trajectory capture ON; memory/skills/reflect sinks staged
|
|
31
|
+
verifyGate: { enabled: true, maxNudges: 1 }, // verify-before-done ON; KODE_VERIFY_GATE=0 to run the raw model
|
|
32
|
+
background: { maxConcurrent: 2, worktree: true }, // ≤2 bg agents at once (KODE_BG_MAX); file-editing ones isolate in a git worktree (KODE_BG_WORKTREE=0 to disable)
|
|
33
|
+
ui: { fullscreen: false }, // inline by default (native scrollback + the masthead boot); --fullscreen / KODE_FULLSCREEN=1 opt in (its alt-screen boot render still needs work before it can be default)
|
|
25
34
|
permissions: { mode: "bypass" }, // zero gates by default — enforcement is opt-in
|
|
26
35
|
telemetry: { enabled: true }, // local-only metrics (silent JSONL); remote sink opt-in via KODE_TELEMETRY_URL
|
|
27
36
|
sandbox: { mode: "off" }, // no isolation by default — enterprise turns it on (KODE_SANDBOX / settings)
|
|
@@ -35,6 +44,14 @@ const DEFAULTS = {
|
|
|
35
44
|
stopOnExit: { searxng: true }, // aurora/autopilot are shared + never stopped; only the SearXNG container is
|
|
36
45
|
},
|
|
37
46
|
activeModel: DEFAULT_MODEL_ID, // /model default — the 1M endpoint, unchanged from before /model existed
|
|
47
|
+
// Autonomy: everything conservative. keepAwake off; dream OFF and read-mostly with a board-only
|
|
48
|
+
// allowlist. An interactive owner never touches any of this until they run an autonomy subcommand.
|
|
49
|
+
autonomy: {
|
|
50
|
+
keepAwake: false,
|
|
51
|
+
maxRounds: 40,
|
|
52
|
+
loop: { maxTurns: 25, maxWallClockSec: 3600, stallAfter: 3 },
|
|
53
|
+
dream: { enabled: false, allow: ["board"], permissions: "readonly", maxTasks: 3 },
|
|
54
|
+
},
|
|
38
55
|
};
|
|
39
56
|
function settingsPath() {
|
|
40
57
|
return process.env.KODE_TSI_SETTINGS ?? join(homedir(), ".axe", "operator", "settings.json");
|
|
@@ -65,9 +82,12 @@ function readSettingsFile(path) {
|
|
|
65
82
|
/** Fold env vars over the file+default merge — the top layer of the precedence stack. Only an env
|
|
66
83
|
* var that's actually set overrides; an unset one leaves the file/default value alone. */
|
|
67
84
|
function applyEnv(s) {
|
|
68
|
-
const out = { ...s, endpoints: { ...s.endpoints }, memory: { ...s.memory }, permissions: { ...s.permissions }, telemetry: { ...s.telemetry }, sandbox: { ...s.sandbox }, computer: { ...s.computer }, search: { ...s.search }, services: s.services ? structuredClone(s.services) : undefined };
|
|
85
|
+
const out = { ...s, endpoints: { ...s.endpoints }, memory: { ...s.memory }, selfImprove: { ...s.selfImprove }, verifyGate: { ...s.verifyGate }, background: { ...s.background }, ui: { ...s.ui }, permissions: { ...s.permissions }, telemetry: { ...s.telemetry }, sandbox: { ...s.sandbox }, computer: { ...s.computer }, search: { ...s.search }, services: s.services ? structuredClone(s.services) : undefined, compaction: s.compaction ? { ...s.compaction } : undefined };
|
|
69
86
|
if (process.env.KODE_MODEL)
|
|
70
87
|
out.endpoints = { ...out.endpoints, aurora: { ...out.endpoints.aurora, model: process.env.KODE_MODEL } }; // AI-agnostic quick-swap (keeps failover)
|
|
88
|
+
const mm = process.env.KODE_MODEL_MODE; // local | aurora — env override of the node's model source
|
|
89
|
+
if (mm === "local" || mm === "aurora")
|
|
90
|
+
out.modelMode = mm;
|
|
71
91
|
const base = process.env.KODE_AURORA ?? process.env.KODE_1M; // KODE_1M kept as a back-compat alias for the base override
|
|
72
92
|
if (base)
|
|
73
93
|
out.endpoints = { ...out.endpoints, aurora: { ...out.endpoints.aurora, base } };
|
|
@@ -81,6 +101,18 @@ function applyEnv(s) {
|
|
|
81
101
|
const tier = process.env.KODE_TIER; // identity tool-tier ceiling (admin=full fleet, enterprise=core+skills, readonly=inspect)
|
|
82
102
|
if (tier === "admin" || tier === "enterprise" || tier === "readonly")
|
|
83
103
|
out.permissions = { ...out.permissions, tier };
|
|
104
|
+
const ct = Number(process.env.KODE_COMPACTION_THRESHOLD); // compact-sooner knob for long-session speed
|
|
105
|
+
if (Number.isFinite(ct))
|
|
106
|
+
out.compaction = { ...out.compaction, threshold: ct };
|
|
107
|
+
const cct = Number(process.env.KODE_COMPACTION_CEILING_TOKENS); // absolute-token compact-sooner knob (big window / small HW)
|
|
108
|
+
if (Number.isFinite(cct))
|
|
109
|
+
out.compaction = { ...out.compaction, ceilingTokens: cct };
|
|
110
|
+
const rcAuto = process.env.KODE_RC_AUTOSTART; // RC host auto-start on boot (opt-in)
|
|
111
|
+
if (rcAuto === "1" || rcAuto === "0")
|
|
112
|
+
out.remote = { ...out.remote, autostart: rcAuto === "1" };
|
|
113
|
+
const mtt = Number(process.env.KODE_TURN_MAX_TOKENS); // opt-in per-turn cost ceiling (total tokens)
|
|
114
|
+
if (Number.isFinite(mtt) && mtt > 0)
|
|
115
|
+
out.maxTurnTokens = Math.floor(mtt);
|
|
84
116
|
if (process.env.KODE_TELEMETRY === "0")
|
|
85
117
|
out.telemetry = { ...out.telemetry, enabled: false };
|
|
86
118
|
const sb = process.env.KODE_SANDBOX;
|
|
@@ -102,6 +134,16 @@ function applyEnv(s) {
|
|
|
102
134
|
out.services = { ...out.services, stopOnExit: { ...out.services.stopOnExit, searxng: false } };
|
|
103
135
|
}
|
|
104
136
|
}
|
|
137
|
+
// Autonomy env overrides. KODE_KEEP_AWAKE=1 forces keep-awake for the run; KODE_AUTONOMY_DREAM=0/1
|
|
138
|
+
// is the hard dream off/on switch that overrides the file. Both only act when actually set.
|
|
139
|
+
if (out.autonomy) {
|
|
140
|
+
if (process.env.KODE_KEEP_AWAKE === "1")
|
|
141
|
+
out.autonomy = { ...out.autonomy, keepAwake: true };
|
|
142
|
+
const dreamEnv = process.env.KODE_AUTONOMY_DREAM;
|
|
143
|
+
if (dreamEnv === "0" || dreamEnv === "1") {
|
|
144
|
+
out.autonomy = { ...out.autonomy, dream: { ...out.autonomy.dream, enabled: dreamEnv === "1" } };
|
|
145
|
+
}
|
|
146
|
+
}
|
|
105
147
|
if (process.env.KODE_AUTOPILOT_URL || process.env.KODE_SEARXNG_URL) {
|
|
106
148
|
out.search = {
|
|
107
149
|
...out.search,
|
|
@@ -111,14 +153,61 @@ function applyEnv(s) {
|
|
|
111
153
|
}
|
|
112
154
|
return out;
|
|
113
155
|
}
|
|
156
|
+
/** The proactive-compaction trigger to hand runTurn: settings.compaction.threshold (env-overridden in
|
|
157
|
+
* loadSettings), clamped to a sane [0.3, 0.95]. Out-of-range or unset → undefined, so runTurn keeps its
|
|
158
|
+
* own 0.85 default. Kept here (not inline at the call sites) so the CLI, headless, and ACP surfaces all
|
|
159
|
+
* resolve it identically. */
|
|
160
|
+
export function compactionThreshold(s) {
|
|
161
|
+
const t = s.compaction?.threshold;
|
|
162
|
+
return typeof t === "number" && t >= 0.3 && t <= 0.95 ? t : undefined;
|
|
163
|
+
}
|
|
164
|
+
/** The absolute-token proactive-compaction ceiling to hand runTurn: settings.compaction.ceilingTokens
|
|
165
|
+
* (env-overridden in loadSettings). Validated to a sane floor of 8000 tokens — below that compaction would
|
|
166
|
+
* thrash, since system+tools alone are ~5k — with no upper cap. Out-of-range or unset → undefined, so
|
|
167
|
+
* runTurn applies no ceiling and only the window-fraction threshold governs. Resolved here (not inline at
|
|
168
|
+
* the call sites) so the CLI, headless, and ACP surfaces all read it identically. */
|
|
169
|
+
export function compactionCeilingTokens(s) {
|
|
170
|
+
const t = s.compaction?.ceilingTokens;
|
|
171
|
+
return typeof t === "number" && Number.isFinite(t) && t >= 8000 ? Math.floor(t) : undefined;
|
|
172
|
+
}
|
|
173
|
+
/** Whether to auto-start a Remote Control host on session boot. An explicit setting/env wins
|
|
174
|
+
* (settings.remote.autostart / KODE_RC_AUTOSTART=1/0). Otherwise it is FEATURE-FLAGGED to the admin/VIP
|
|
175
|
+
* tier only (owner decision, James 2026-09-28): auto-RC ships ON for admin accounts and OFF for everyone
|
|
176
|
+
* else, so it isn't shared broadly until Operator is reliable enough to warrant it — widen the gate here to
|
|
177
|
+
* roll it out further. Still token-gated at boot (no sign-in → silently starts nothing). Resolved here so
|
|
178
|
+
* every surface reads it identically. */
|
|
179
|
+
export function rcAutostart(s) {
|
|
180
|
+
if (typeof s.remote?.autostart === "boolean")
|
|
181
|
+
return s.remote.autostart; // explicit opt-in/out wins
|
|
182
|
+
return s.permissions?.tier === "admin"; // default: admin/VIP only for now
|
|
183
|
+
}
|
|
114
184
|
/** Load operator settings: built-in defaults <- ~/.axe/operator/settings.json (override path via
|
|
115
185
|
* KODE_TSI_SETTINGS) <- env vars. Never throws. */
|
|
186
|
+
/** Resolve the model MODE into the concrete `endpoints` chain the router consumes. "aurora" points the
|
|
187
|
+
* primary + failover at the shared fleet Aurora nodes (JL1/JL2 hybrid). "local" (default) keeps this
|
|
188
|
+
* node's own primary and, only when no failover is configured, backstops with the first DIFFERENT fleet
|
|
189
|
+
* node so a node with no local model still degrades to the fleet. Pure + backward-compatible: with no
|
|
190
|
+
* modelMode/fleet and an explicit failover already set, it returns the settings unchanged. The model id +
|
|
191
|
+
* ctx window carry over from `endpoints.aurora`, so a mode switch never re-hardcodes a model. */
|
|
192
|
+
function resolveModelMode(s) {
|
|
193
|
+
const nodes = (s.fleet?.auroraNodes ?? []).filter(Boolean);
|
|
194
|
+
const { model, ctxWindow } = s.endpoints.aurora;
|
|
195
|
+
if (s.modelMode === "aurora" && nodes.length) {
|
|
196
|
+
return { ...s, endpoints: { aurora: { base: nodes[0], model, ctxWindow }, failover: nodes[1] ? { base: nodes[1], model, ctxWindow } : undefined } };
|
|
197
|
+
}
|
|
198
|
+
if (!s.endpoints.failover) {
|
|
199
|
+
const backstop = nodes.find((b) => b !== s.endpoints.aurora.base);
|
|
200
|
+
if (backstop)
|
|
201
|
+
return { ...s, endpoints: { ...s.endpoints, failover: { base: backstop, model, ctxWindow } } };
|
|
202
|
+
}
|
|
203
|
+
return s;
|
|
204
|
+
}
|
|
116
205
|
export function loadSettings() {
|
|
117
206
|
const file = readSettingsFile(settingsPath());
|
|
118
207
|
// structuredClone the base so a returned settings object never aliases the module-level DEFAULTS —
|
|
119
208
|
// deepMerge only recurses into keys the override touches, so an untouched nested endpoint would
|
|
120
209
|
// otherwise flow through by reference and a later mutation would corrupt defaults process-wide.
|
|
121
|
-
return applyEnv(deepMerge(structuredClone(DEFAULTS), file));
|
|
210
|
+
return resolveModelMode(applyEnv(deepMerge(structuredClone(DEFAULTS), file)));
|
|
122
211
|
}
|
|
123
212
|
/** Persist a partial settings patch onto whatever's on disk (deep-merged, file values win over
|
|
124
213
|
* defaults for anything the patch doesn't touch), so a runtime choice like /model survives a
|