@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
package/dist/cli.js
CHANGED
|
@@ -8,23 +8,37 @@ import { useCallback, useEffect, useRef, useState } from "react";
|
|
|
8
8
|
import { render, Box, Text, useApp } from "ink";
|
|
9
9
|
import { App } from "./ui/index.js";
|
|
10
10
|
import { mastheadLines } from "./ui/Masthead.js";
|
|
11
|
+
import { shouldPromptPlanExit, resolvePlanExit, PLAN_EXIT_OPTIONS } from "./ui/planExit.js";
|
|
11
12
|
import { RemoteHost } from "./remote/host.js";
|
|
12
13
|
import { isErrorResult } from "./ui/format.js";
|
|
13
14
|
import { seedLiveTools, settleLiveTool } from "./ui/liveTools.js";
|
|
14
15
|
import { Session } from "./session.js";
|
|
15
16
|
import { AuroraRouter } from "./router/router.js";
|
|
16
17
|
import { BackgroundAgents } from "./background/index.js";
|
|
17
|
-
import { loadSettings, saveSettings } from "./config/settings.js";
|
|
18
|
-
import {
|
|
18
|
+
import { loadSettings, saveSettings, compactionThreshold, compactionCeilingTokens, rcAutostart } from "./config/settings.js";
|
|
19
|
+
import { loadProjectContext, loadMemories, appendMemory, loadHandoff } from "./config/persona.js";
|
|
20
|
+
import { renderHarnessContext } from "./config/operator-harness.js";
|
|
21
|
+
import { disposeShellSession, getAgentTasks } from "./tools/registry.js";
|
|
19
22
|
import { EventSink } from "./telemetry/events.js";
|
|
20
23
|
import { readFileSync, writeFileSync, mkdirSync } from "node:fs";
|
|
21
24
|
import { expandFileMentions } from "./util/mentions.js";
|
|
25
|
+
import { throttle } from "./util/throttle.js";
|
|
26
|
+
import { isSlashCommand } from "./util/slash.js";
|
|
22
27
|
import { join, dirname } from "node:path";
|
|
23
28
|
import { homedir, hostname } from "node:os";
|
|
24
29
|
import { createHash } from "node:crypto";
|
|
25
30
|
// RELEASE CHECKLIST (every bump): update this + package.json "version", ADD A CHANGELOG.md ENTRY
|
|
26
31
|
// (improvements / fixes / tests), run the suite, then publish to npm + push both remotes.
|
|
27
|
-
|
|
32
|
+
// Single source of truth = package.json, read at runtime — so the splash/statusline can never drift
|
|
33
|
+
// from the published version again (the "update said 0.63 but it shows 0.62" bug).
|
|
34
|
+
const VERSION = (() => {
|
|
35
|
+
try {
|
|
36
|
+
return JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8")).version;
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return "0.0.0";
|
|
40
|
+
}
|
|
41
|
+
})();
|
|
28
42
|
// operator/settings.json (override path via KODE_TSI_SETTINGS), env vars still win — see config/settings.ts.
|
|
29
43
|
const settings = loadSettings();
|
|
30
44
|
// Propagate the resolved sandbox mode to the tool layer (registry reads KODE_SANDBOX at exec time).
|
|
@@ -34,6 +48,23 @@ process.env.KODE_SANDBOX = settings.sandbox.mode;
|
|
|
34
48
|
// folded any real env var into settings.search (env wins), so this never clobbers an explicit export.
|
|
35
49
|
if (settings.search?.autopilotUrl)
|
|
36
50
|
process.env.KODE_AUTOPILOT_URL = settings.search.autopilotUrl;
|
|
51
|
+
if (settings.selfImprove?.flywheel === false)
|
|
52
|
+
process.env.KODE_SELFIMPROVE = "0"; // opt out of turn-capture
|
|
53
|
+
if (settings.selfImprove?.memory)
|
|
54
|
+
process.env.KODE_SELFIMPROVE_MEMORY = "1"; // closed loop: a stuck session leaves a durable lesson in .operator/memories.md (opt-in)
|
|
55
|
+
if (settings.verifyGate?.enabled === false)
|
|
56
|
+
process.env.KODE_VERIFY_GATE = "0"; // opt out of verify-before-done
|
|
57
|
+
if (settings.verifyGate?.maxNudges != null)
|
|
58
|
+
process.env.KODE_VERIFY_GATE_MAX = String(settings.verifyGate.maxNudges);
|
|
59
|
+
if (settings.background?.maxConcurrent != null)
|
|
60
|
+
process.env.KODE_BG_MAX = String(settings.background.maxConcurrent); // cap concurrent bg sub-agents
|
|
61
|
+
if (settings.background?.worktree === false)
|
|
62
|
+
process.env.KODE_BG_WORKTREE = "0"; // opt out of bg-agent git-worktree isolation
|
|
63
|
+
// Inline (native scrollback + the masthead boot) is the DEFAULT. Fullscreen (alt-screen; composer pinned
|
|
64
|
+
// bottom) is OPT-IN via --fullscreen / KODE_FULLSCREEN=1 / settings.ui.fullscreen:true — its alt-screen
|
|
65
|
+
// redraws the whole frame on every tick (extra flashing) and its boot render doubles the masthead/services
|
|
66
|
+
// lines; both need fixing before it can be default again.
|
|
67
|
+
const FULLSCREEN = process.argv.includes("--fullscreen") || process.env.KODE_FULLSCREEN === "1" || settings.ui?.fullscreen === true;
|
|
37
68
|
if (settings.search?.searxngUrl)
|
|
38
69
|
process.env.KODE_SEARXNG_URL = settings.search.searxngUrl;
|
|
39
70
|
if (settings.search?.searxngEngines)
|
|
@@ -154,33 +185,35 @@ function buildRouter() {
|
|
|
154
185
|
eps.push({ name: "failover", base: fo.base, model: fo.model, ctxLimit: fo.ctxWindow });
|
|
155
186
|
return new AuroraRouter(eps);
|
|
156
187
|
}
|
|
157
|
-
//
|
|
158
|
-
//
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
function loadProjectContext() {
|
|
162
|
-
for (const name of ["AGENTS.md", "CLAUDE.md", ".operator/AGENTS.md", "OPERATOR.md"]) {
|
|
163
|
-
try {
|
|
164
|
-
const t = readFileSync(join(process.cwd(), name), "utf8").trim();
|
|
165
|
-
if (t)
|
|
166
|
-
return `\n\n## Project context (${name}, auto-loaded from the working directory)\n${t.slice(0, 8000)}`;
|
|
167
|
-
}
|
|
168
|
-
catch { /* not present — try the next */ }
|
|
169
|
-
}
|
|
170
|
-
return "";
|
|
188
|
+
// One-line status for a sub-agent — shared by /bg (human) and the agent_status tool (model), so both
|
|
189
|
+
// surfaces agree on what "status" means instead of drifting into two formats.
|
|
190
|
+
function formatAgentLine(a) {
|
|
191
|
+
return `${a.id} [${a.status}]${a.round ? ` round ${a.round}` : ""} ${a.label}`;
|
|
171
192
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
193
|
+
const DISPLAY_STATUS = { queued: "queued", working: "running", idle: "done", stopped: "errored" };
|
|
194
|
+
function formatAgentDetail(a) {
|
|
195
|
+
const ds = DISPLAY_STATUS[a.status] ?? a.status;
|
|
196
|
+
const parts = [`${a.id} [${ds}]`];
|
|
197
|
+
if (a.round)
|
|
198
|
+
parts.push(`round ${a.round}`);
|
|
199
|
+
parts.push(a.label);
|
|
200
|
+
const metrics = [];
|
|
201
|
+
if (a.tokens != null && a.tokens > 0)
|
|
202
|
+
metrics.push(`${a.tokens >= 1000 ? `${(a.tokens / 1000).toFixed(1)}k` : a.tokens} tok`);
|
|
203
|
+
const ms = a.status === "working" ? (a.startedAt != null ? Date.now() - a.startedAt : undefined) : a.durationMs;
|
|
204
|
+
if (ms != null)
|
|
205
|
+
metrics.push(`${(ms / 1000).toFixed(ms < 10000 ? 1 : 0)}s`);
|
|
206
|
+
if (metrics.length)
|
|
207
|
+
parts.push(`(${metrics.join(" · ")})`);
|
|
208
|
+
if (a.status === "idle")
|
|
209
|
+
parts.push("— result posted");
|
|
210
|
+
if (a.status === "stopped")
|
|
211
|
+
parts.push("— errored");
|
|
212
|
+
return parts.join(" ");
|
|
183
213
|
}
|
|
214
|
+
// Project context + session handoff loaders live in config/persona.ts, shared with the headless
|
|
215
|
+
// autonomy runners (autonomy/session-factory.ts) so an unattended `operator run/loop` picks up the
|
|
216
|
+
// same AGENTS.md/CLAUDE.md + handoff the TUI does. See that module for the details.
|
|
184
217
|
// Embodiment guidance, appended only when computer control is on. It steers Aurora to READ the screen
|
|
185
218
|
// with chauffeur's textual accessibility tree instead of hand-rolling osascript — the exact loop that
|
|
186
219
|
// failed on Slack (AppleScript can't read Electron UIs). chauffeur is reachable either via the scoped
|
|
@@ -221,8 +254,8 @@ const SYSTEM_PROMPT = (settings.systemPrompt ??
|
|
|
221
254
|
`".claude", "anthropic", etc., describe them neutrally (by their literal path, or as "AI tooling ` +
|
|
222
255
|
`files") — do not attribute them to a vendor. Use your tools to inspect and edit the ` +
|
|
223
256
|
`workspace; prefer doing over explaining. Answer concisely.\n## This machine\nWorking dir: ${process.cwd()}` +
|
|
224
|
-
`\nContext window:
|
|
225
|
-
`
|
|
257
|
+
`\nContext window: 307,200 tokens (300K) — you run on AXE's model served locally with a real 300K-token ` +
|
|
258
|
+
`context. You can hold large files and long histories; do not claim a different limit.` +
|
|
226
259
|
`\n## Parallel tool calls\nWhen the next few steps are INDEPENDENT of each other — reading several ` +
|
|
227
260
|
`files, running several greps/checks, inspecting multiple unrelated things — issue them as multiple ` +
|
|
228
261
|
`tool calls in a SINGLE message so they run in parallel, instead of one call, waiting, then the next. ` +
|
|
@@ -251,8 +284,7 @@ const SYSTEM_PROMPT = (settings.systemPrompt ??
|
|
|
251
284
|
`results — think there, not in the workspace or your reply. Before you finish a substantial task, or ` +
|
|
252
285
|
`when you're running low on context, call session_handoff to record what you did, the state, and the ` +
|
|
253
286
|
`next steps: your next session in this directory loads it automatically, so write it for your future self.`) +
|
|
254
|
-
loadProjectContext() + loadHandoff() + EMBODIMENT_GUIDE;
|
|
255
|
-
const MAX_BG = 4; // concurrent background sub-agents — all share the single Aurora 1M endpoint, so cap fan-out
|
|
287
|
+
loadProjectContext() + loadMemories() + renderHarnessContext() + loadHandoff() + EMBODIMENT_GUIDE;
|
|
256
288
|
const HELP = [
|
|
257
289
|
"commands:",
|
|
258
290
|
" /help this list",
|
|
@@ -260,6 +292,8 @@ const HELP = [
|
|
|
260
292
|
" /endpoints show the Operator endpoint + live health",
|
|
261
293
|
" /services ensure/inspect the service lever (Operator+autopilot+searxng); /services stop",
|
|
262
294
|
" /audit [n] recent tool + control-plane events from the audit trail (default 15)",
|
|
295
|
+
" /monitor live event stream — tool decisions, turns, control events (/monitor off)",
|
|
296
|
+
" /stats session dashboard: turns · tools · tokens · throughput trend · context fill",
|
|
263
297
|
" /dashboard launch the live swarm console (watches every Operator session)",
|
|
264
298
|
" /plan plan mode: read-only research + propose a plan (/plan again to execute)",
|
|
265
299
|
" /mode [plan|manual|auto] set operating mode (plan · manual · autonomous); also Shift+Tab to cycle",
|
|
@@ -269,7 +303,8 @@ const HELP = [
|
|
|
269
303
|
" /remember <note> store a note to recall in future sessions",
|
|
270
304
|
" /memory [query] show remembered notes (all, or matching query)",
|
|
271
305
|
" /mcp count of fleet MCP tools this session (KODE_TSI_MCP=1)",
|
|
272
|
-
" /login
|
|
306
|
+
" /login <email> · /logout · /whoami sign in by 6-digit email code (then /login <code>); /login <token> or --browser",
|
|
307
|
+
" /agents detailed sub-agent status: running/queued/done/errored + metrics",
|
|
273
308
|
" /bg <task|stop id> spawn a background sub-agent, list, or stop one",
|
|
274
309
|
" /new start a fresh conversation",
|
|
275
310
|
" /clear clear the screen (keeps the conversation)",
|
|
@@ -302,6 +337,8 @@ const REMOTE_SAFE_COMMANDS = [
|
|
|
302
337
|
{ name: "memory", description: "show remembered notes", args: "[query]" },
|
|
303
338
|
{ name: "mcp", description: "count of fleet MCP tools this session" },
|
|
304
339
|
{ name: "whoami", description: "show signed-in identity" },
|
|
340
|
+
{ name: "agents", description: "detailed sub-agent status with metrics" },
|
|
341
|
+
{ name: "monitor", description: "toggle live event stream (tool decisions, turns, control)" },
|
|
305
342
|
{ name: "bg", description: "spawn a background sub-agent, list, or stop one", args: "<task|stop id>" },
|
|
306
343
|
{ name: "new", description: "start a fresh conversation" },
|
|
307
344
|
{ name: "clear", description: "clear the screen (keeps the conversation)" },
|
|
@@ -333,6 +370,7 @@ function Root() {
|
|
|
333
370
|
// status rule as tokens stream (each SSE delta ≈ 1 token). Zero extra renders: it rides the per-delta
|
|
334
371
|
// setLive re-render that already happens, so there's no performance cost and no animation timer.
|
|
335
372
|
const [bgAgents, setBgAgents] = useState([]);
|
|
373
|
+
const [tasks, setTasks] = useState([]); // session TODO list for the plan pane, refreshed after task_* tools
|
|
336
374
|
const [authUser, setAuthUser] = useState(""); // signed-in identity for the status rule
|
|
337
375
|
const [planMode, setPlanMode] = useState(false); // /plan: read-only research + propose, shown as a status badge
|
|
338
376
|
// Operating mode, cycled with Shift+Tab (like Claude Code): auto (no gate) → manual (approve mutations)
|
|
@@ -371,7 +409,18 @@ function Root() {
|
|
|
371
409
|
// /model picker: same QuestionPrompt UI pattern as ask_user, but purely local (never relayed) —
|
|
372
410
|
// it's a session setting, not something the model is asking.
|
|
373
411
|
const [modelPicker, setModelPicker] = useState(null);
|
|
412
|
+
// Plan-mode "Approve & run": true once an assistant turn has completed while still in plan mode
|
|
413
|
+
// (i.e. the model actually proposed something), reset whenever a fresh plan-mode session starts.
|
|
414
|
+
// Gates the exit-time picker below — plan mode toggled on/off with no proposal stays silent.
|
|
415
|
+
const planProposedRef = useRef(false);
|
|
416
|
+
const [planExitPicker, setPlanExitPicker] = useState(null);
|
|
374
417
|
const alwaysAllowRef = useRef(new Set());
|
|
418
|
+
// Remembers the email a `/login <email>` sent a 6-digit code to, so the follow-up `/login <code>`
|
|
419
|
+
// knows which address to verify against — the in-session twin of the shell's email-code login.
|
|
420
|
+
const pendingLoginEmailRef = useRef(null);
|
|
421
|
+
// Set when a bare `/login` (no arg) shows the email prompt; a SECOND consecutive bare `/login` then
|
|
422
|
+
// escalates to the browser device-grant. So pressing `/login`↵ twice opens the browser without --browser.
|
|
423
|
+
const loginEmptyRetryRef = useRef(false);
|
|
375
424
|
// Pending gated approvals by id. Both the local keystroke and a remote follower's approval_response
|
|
376
425
|
// route through settleApproval — FIRST answer wins (§7); the map delete makes it idempotent.
|
|
377
426
|
const pendingApprovals = useRef(new Map());
|
|
@@ -407,6 +456,10 @@ function Root() {
|
|
|
407
456
|
mcp: settings.mcp,
|
|
408
457
|
mcpHub: embodimentHub, // scoped chauffeur hub when embodiment is on (undefined otherwise → no change)
|
|
409
458
|
maxTokens: settings.maxTokens,
|
|
459
|
+
maxTurnTokens: settings.maxTurnTokens, // opt-in per-turn cost ceiling (total tokens); undefined → no cap
|
|
460
|
+
maxRounds: settings.autonomy?.maxRounds, // soft per-turn round budget (default 40) — a real build isn't cut off at 10
|
|
461
|
+
compactionThreshold: compactionThreshold(settings), // settings.compaction.threshold / KODE_COMPACTION_THRESHOLD; undefined → 0.85
|
|
462
|
+
compactionCeilingTokens: compactionCeilingTokens(settings), // settings.compaction.ceilingTokens / KODE_COMPACTION_CEILING_TOKENS; undefined → no ceiling
|
|
410
463
|
temperature: settings.temperature,
|
|
411
464
|
recall: settings.memory.recall,
|
|
412
465
|
models: settings.models, // /model registry overrides (router/models.ts has the built-in defaults)
|
|
@@ -418,16 +471,74 @@ function Root() {
|
|
|
418
471
|
telemetry: settings.telemetry, // local-only metrics by default
|
|
419
472
|
eventSink, eventActor: EVENT_ACTOR, sessionId: SESSION_ID, // frozen event stream (tool/control audit)
|
|
420
473
|
// Foreground only: lets Aurora delegate via spawn_agent. The bg factory below OMITS this, so a
|
|
421
|
-
// sub-agent can't spawn more (no fork bombs).
|
|
422
|
-
//
|
|
474
|
+
// sub-agent can't spawn more (no fork bombs). BackgroundAgents itself is the single source of truth
|
|
475
|
+
// for the cap (running + queued) — it refuses ("") past it, so there's exactly one number to keep in
|
|
476
|
+
// sync, not a second constant here that can drift from the manager's own.
|
|
423
477
|
spawnAgent: (task) => {
|
|
424
478
|
const mgr = bgRef.current;
|
|
425
479
|
if (!mgr)
|
|
426
480
|
return "background manager not ready yet — retry in a moment";
|
|
427
|
-
if (mgr.activeCount() >= MAX_BG)
|
|
428
|
-
return `at capacity: ${MAX_BG} sub-agents already running on the single Operator 1M endpoint — wait for one to finish (see the background panel) before spawning more`;
|
|
429
481
|
const id = mgr.spawn(task);
|
|
430
|
-
|
|
482
|
+
if (!id)
|
|
483
|
+
return mgr.capacityLine();
|
|
484
|
+
// Deliberately does NOT invite polling — a prior wording ("watch its ... time") read as "you can
|
|
485
|
+
// check on this", and the model reached for bash_output (the shell_background poll tool) with this
|
|
486
|
+
// id, got "no background job", and concluded the sub-agent had been evicted — then re-spawned a
|
|
487
|
+
// duplicate onto the one shared endpoint (the actual live bug, 09-26). State the auto-post + the
|
|
488
|
+
// real status path plainly instead.
|
|
489
|
+
return `spawned background sub-agent ${id}. Its result auto-posts to THIS conversation when done — ` +
|
|
490
|
+
`keep working, do not poll it. Do NOT call bash_output/bash_kill on ${id} (that's for shell_background ` +
|
|
491
|
+
`jobs only and will just error). Use agent_status to check on it, or message_agent to nudge it. ` +
|
|
492
|
+
`Never re-spawn ${id}'s task assuming it was lost — it wasn't.`;
|
|
493
|
+
},
|
|
494
|
+
// The reverse channel: message a RUNNING sub-agent mid-flight (steer it / answer its question).
|
|
495
|
+
messageAgent: (id, text) => {
|
|
496
|
+
const mgr = bgRef.current;
|
|
497
|
+
if (!mgr)
|
|
498
|
+
return "background manager not ready yet — retry in a moment";
|
|
499
|
+
return mgr.sendToAgent(id, text)
|
|
500
|
+
? `message queued for ${id} — it'll pick it up as a follow-up turn (watch the background panel).`
|
|
501
|
+
: `${id} isn't a running sub-agent (already finished, unknown, or a stopped/queued state that can't take a message) — check agent_status before re-spawning.`;
|
|
502
|
+
},
|
|
503
|
+
// The legit status-check path (agent_status tool): list every known sub-agent, or look one up by id,
|
|
504
|
+
// so the model has a real answer instead of inferring "evicted" from a bash_output error.
|
|
505
|
+
agentStatus: (id) => {
|
|
506
|
+
const mgr = bgRef.current;
|
|
507
|
+
if (!mgr)
|
|
508
|
+
return "background manager not ready yet — retry in a moment";
|
|
509
|
+
const list = mgr.list();
|
|
510
|
+
const retired = mgr.retiredList(); // finished/errored agents that already decommissioned this session
|
|
511
|
+
if (id) {
|
|
512
|
+
const a = list.find((x) => x.id === id) ?? retired.find((x) => x.id === id);
|
|
513
|
+
const everIds = [...list, ...retired].map((x) => x.id).join(", ") || "none";
|
|
514
|
+
return a
|
|
515
|
+
? formatAgentLine(a)
|
|
516
|
+
: `no sub-agent ${id} (ran this session: ${everIds}) — it may have already finished and decommissioned; its result was posted to the conversation when it did.`;
|
|
517
|
+
}
|
|
518
|
+
if (list.length)
|
|
519
|
+
return list.map(formatAgentLine).join("\n");
|
|
520
|
+
// No LIVE agents — but say so honestly: report any that ran and decommissioned rather than the
|
|
521
|
+
// misleading "none spawned" (live 09-27: two errored agents decommissioned, then agent_status wrongly
|
|
522
|
+
// said none were ever spawned). Their results are already in the conversation.
|
|
523
|
+
if (retired.length) {
|
|
524
|
+
return `no sub-agents are currently active. ${retired.length} ran earlier this session and decommissioned (${retired.map((r) => `${r.id}: ${r.status}`).join(", ")}) — their results were posted to the conversation when they finished.`;
|
|
525
|
+
}
|
|
526
|
+
return "no sub-agents spawned this session yet.";
|
|
527
|
+
},
|
|
528
|
+
// stop_agent: cancel one sub-agent (a real id) or every running/queued one (undefined = "all").
|
|
529
|
+
// BackgroundAgents.requestStop(All) already posts the "[stopped by user]" note via onDone — this
|
|
530
|
+
// handler just relays whether there was anything to stop.
|
|
531
|
+
stopAgent: (id) => {
|
|
532
|
+
const mgr = bgRef.current;
|
|
533
|
+
if (!mgr)
|
|
534
|
+
return "background manager not ready yet — retry in a moment";
|
|
535
|
+
if (!id) {
|
|
536
|
+
const stopped = mgr.requestStopAll();
|
|
537
|
+
return stopped.length ? `stopped ${stopped.length} sub-agent(s): ${stopped.join(", ")}.` : "no running or queued sub-agents to stop.";
|
|
538
|
+
}
|
|
539
|
+
return mgr.requestStop(id)
|
|
540
|
+
? `stopped ${id} — a "[stopped by user]" note replaces its result.`
|
|
541
|
+
: `${id} isn't a running or queued sub-agent (already finished, unknown, or never existed) — nothing to stop.`;
|
|
431
542
|
},
|
|
432
543
|
});
|
|
433
544
|
}
|
|
@@ -436,24 +547,42 @@ function Root() {
|
|
|
436
547
|
// foreground — one model, one context tier.
|
|
437
548
|
const bgRef = useRef(null);
|
|
438
549
|
if (!bgRef.current) {
|
|
439
|
-
bgRef.current = new BackgroundAgents(() => new Session({
|
|
550
|
+
bgRef.current = new BackgroundAgents((cwd) => new Session({
|
|
440
551
|
systemPrompt: SYSTEM_PROMPT,
|
|
441
552
|
router: new AuroraRouter([
|
|
442
553
|
{ name: "operator-1m", base: settings.endpoints.aurora.base, model: settings.endpoints.aurora.model, ctxLimit: settings.endpoints.aurora.ctxWindow },
|
|
443
554
|
]),
|
|
444
555
|
maxTokens: settings.maxTokens,
|
|
556
|
+
maxTurnTokens: settings.maxTurnTokens, // opt-in per-turn cost ceiling also bounds a sub-agent's spend
|
|
557
|
+
maxRoundsHard: 50, // a focused delegated sub-agent that hits 50 rounds isn't converging — cap it well below the foreground's 200 so a review/fix agent can't run away to round 40+ burning the shared Aurora (seen live 09-26)
|
|
558
|
+
background: true, // endpoint gate: this is a sub-agent — its Aurora requests yield the shared single slot to the interactive main turn (fixes the sub-agent-contention crawl + "4 min for a prompt")
|
|
559
|
+
cwd, // isolation: a code-editing bg agent gets its own worktree dir here so it can't touch the foreground tree
|
|
445
560
|
temperature: settings.temperature,
|
|
446
561
|
// Sub-agents may NOT drive the computer: they have no approval prompt, so any computer_* call is
|
|
447
562
|
// denied outright. (No-op when computer control is off.) Everything else runs as normal.
|
|
448
563
|
permissions: settings.computer.enabled ? { mode: "bypass", rules: computerDenyRules } : undefined,
|
|
449
|
-
}), () => setBgAgents(bgRef.current.list()),
|
|
564
|
+
}), throttle(() => setBgAgents(bgRef.current.list()), 90), // coalesce per-update churn: a 3+ agent swarm streaming at once would otherwise redraw the whole frame dozens×/s (flicker). Final state lands via the immediate setBgAgents on the done path below.
|
|
565
|
+
(agent, result) => {
|
|
450
566
|
setEntries((prev) => [...prev, { kind: "message", message: { id: nextId(), role: "system", content: `⤷ ${agent.id} (${agent.label}) done:\n${result.slice(0, 500)}` } }]);
|
|
451
567
|
setBgAgents(bgRef.current.list());
|
|
452
|
-
}, settings.endpoints.aurora.model)
|
|
568
|
+
}, settings.endpoints.aurora.model, // model name recorded on each child for UI surfacing (grandmaster §5)
|
|
569
|
+
() => setTasks(getAgentTasks()));
|
|
453
570
|
}
|
|
454
571
|
const bg = bgRef.current;
|
|
572
|
+
const tokHist = useRef([]); // per-turn decode tok/s, for the /stats throughput sparkline
|
|
573
|
+
const toolTotal = useRef(0); // cumulative tool calls this session, for /stats
|
|
455
574
|
const liveText = useRef("");
|
|
456
575
|
const liveReasoning = useRef(""); // current completion's reasoning ("thinking"), shown dim + above the answer
|
|
576
|
+
const liveTokRef = useRef(0); // per-token count accumulated by the stream; flushed to liveTok on the throttled tick
|
|
577
|
+
// Coalesced live-frame update: applies the accumulated stream refs in ONE render, rate-limited to ~15fps,
|
|
578
|
+
// so a fast reply or a multi-agent swarm can't flicker the frame with a per-token redraw storm. Resolves
|
|
579
|
+
// to setLive(null) when the refs are empty (turn/tool-batch end clears them), so a trailing tick after a
|
|
580
|
+
// clear is correct, never a stale re-show.
|
|
581
|
+
const flushLive = useRef(throttle(() => {
|
|
582
|
+
const has = liveText.current.length > 0 || liveReasoning.current.length > 0;
|
|
583
|
+
setLive(has ? { kind: "message", message: { id: "live", role: "assistant", content: liveText.current, reasoning: liveReasoning.current || undefined } } : null);
|
|
584
|
+
setLiveTok(liveTokRef.current);
|
|
585
|
+
}, 64)).current;
|
|
457
586
|
const queued = useRef("");
|
|
458
587
|
const statusRef = useRef("idle");
|
|
459
588
|
// Remote-control host (SPEC/remote-session.md): non-null only while /remotecontrol is active. Every
|
|
@@ -469,6 +598,7 @@ function Root() {
|
|
|
469
598
|
// below. Session-scoped by design — a fresh session starts with an empty list, matching /model's own
|
|
470
599
|
// lack of persistence across sessions.
|
|
471
600
|
const skillsRef = useRef(new Map());
|
|
601
|
+
const monitorRef = useRef(null);
|
|
472
602
|
// Assembles RemoteCapabilities from the real registries at call time — commands (the remote-safe
|
|
473
603
|
// allowlist above), skills (skillsRef), MCP servers (session.mcpServers() — empty until first-turn
|
|
474
604
|
// discovery has run, see session.ts maybeRecall), models (session.modelRegistry()), permission mode,
|
|
@@ -545,8 +675,27 @@ function Root() {
|
|
|
545
675
|
}
|
|
546
676
|
// Confirm, once in scrollback, what the lever did (started = it was down and we brought it up).
|
|
547
677
|
const line = reports.map((r) => `${r.name} ${r.state === "up" ? "✓" : r.state === "started" ? "✓ started" : "✗"}`).join(" · ");
|
|
548
|
-
if (line)
|
|
549
|
-
|
|
678
|
+
if (line) {
|
|
679
|
+
// SearXNG is lazy (starts on first web_search), but if a backend is ALREADY reachable — an explicit
|
|
680
|
+
// KODE_SEARXNG_URL, or a container still up from a prior session — show ✓ instead of a misleading
|
|
681
|
+
// "lazy". Read-only probe: never starts one here.
|
|
682
|
+
const { probeSearxng } = await import("./tools/searxng.js");
|
|
683
|
+
const sxUp = await probeSearxng().catch(() => false);
|
|
684
|
+
push({ kind: "message", message: { id: nextId(), role: "system", content: `services: ${line} · searxng ${sxUp ? "✓" : "lazy"}` } });
|
|
685
|
+
}
|
|
686
|
+
// Remote-control auto-start (rcAutostart: explicit remote.autostart / KODE_RC_AUTOSTART wins, else
|
|
687
|
+
// ON for admin/VIP tier only — feature-flagged rollout). When enabled and this box is signed in, bring
|
|
688
|
+
// up an RC host on boot by driving the EXACT /remotecontrol path
|
|
689
|
+
// (submitRef → handleSlash) — never a second connect implementation. Token-gated with a SILENT skip
|
|
690
|
+
// when unsigned, so a no-token box is never spammed with the sign-in hint every launch; and guarded on
|
|
691
|
+
// remoteRef so it never double-starts an already-live host. The owner can still /remotecontrol to stop.
|
|
692
|
+
if (rcAutostart(settings) && !remoteRef.current) {
|
|
693
|
+
const { loadCredentials } = await import("./auth/store.js");
|
|
694
|
+
const creds = await loadCredentials().catch(() => null);
|
|
695
|
+
const token = process.env.KODE_OPERATOR_TOKEN || creds?.token || "";
|
|
696
|
+
if (token)
|
|
697
|
+
submitRef.current("/remotecontrol");
|
|
698
|
+
}
|
|
550
699
|
})();
|
|
551
700
|
}, []);
|
|
552
701
|
// Show who's signed in (best-effort, non-blocking): load stored creds, verify against the backend.
|
|
@@ -571,6 +720,7 @@ function Root() {
|
|
|
571
720
|
remoteRef.current?.turnStart(); // allocate this turn's assistant id (stable stream→final)
|
|
572
721
|
liveText.current = "";
|
|
573
722
|
liveReasoning.current = "";
|
|
723
|
+
liveTokRef.current = 0;
|
|
574
724
|
setLive(null);
|
|
575
725
|
setLiveTok(0); // reset the live counter at the start of the turn
|
|
576
726
|
turnStartRef.current = Date.now();
|
|
@@ -581,9 +731,9 @@ function Root() {
|
|
|
581
731
|
onRoute: (label, pct) => { setRoute(label); setCtxPct(pct); remoteRef.current?.setStatus(pct, label); },
|
|
582
732
|
onDelta: (chunk) => {
|
|
583
733
|
liveText.current += chunk;
|
|
584
|
-
|
|
734
|
+
liveTokRef.current += 1; // ≈1 token per streamed delta; flushed to the counter on the throttled tick
|
|
585
735
|
setStat("streaming");
|
|
586
|
-
|
|
736
|
+
flushLive(); // coalesced live-frame update (~15fps) — no per-token redraw storm / flicker
|
|
587
737
|
remoteRef.current?.streamAssistant(liveText.current, liveReasoning.current || undefined);
|
|
588
738
|
},
|
|
589
739
|
onReasoning: (chunk) => {
|
|
@@ -591,12 +741,14 @@ function Root() {
|
|
|
591
741
|
// (renderEntry renders `reasoning` above the answer, dimColor). Distinct from onDelta so the
|
|
592
742
|
// thought process reads at lower opacity than the real answer, per the requested look.
|
|
593
743
|
liveReasoning.current += chunk;
|
|
594
|
-
|
|
744
|
+
liveTokRef.current += 1; // reasoning tokens ARE generated tokens — count them so the live
|
|
595
745
|
// counter + tok/s keep moving during a long thinking phase (they were frozen before content).
|
|
596
746
|
setStat("thinking");
|
|
597
|
-
|
|
747
|
+
flushLive(); // coalesced (~15fps) — throttled so a long thinking stream doesn't flicker the frame
|
|
598
748
|
remoteRef.current?.streamAssistant(liveText.current, liveReasoning.current || undefined);
|
|
599
749
|
},
|
|
750
|
+
onTokens: (t) => { liveTokRef.current = t; setLiveTok(t); }, // authoritative per-round count — corrects the ≈1/delta animation to
|
|
751
|
+
// the real llama.cpp total (which includes tool-call-arg + reasoning tokens the delta stream misses)
|
|
600
752
|
onAutoContinue: (round) => {
|
|
601
753
|
push({ kind: "message", message: { id: nextId(), role: "assistant", content: `↻ still working — auto-continuing past ${round} tool rounds`, reasoning: "" } });
|
|
602
754
|
},
|
|
@@ -607,6 +759,14 @@ function Root() {
|
|
|
607
759
|
setStat("recovering");
|
|
608
760
|
},
|
|
609
761
|
onToolStart: (calls) => {
|
|
762
|
+
// Clear the just-streamed interstitial narration BEFORE the batch runs. Keeping it in the live
|
|
763
|
+
// frame while N parallel tools settle one-by-one re-renders a tall frame (narration + the N-row
|
|
764
|
+
// tool box) that Ink can mis-erase, stamping the same "let me check…" line once per tool — the
|
|
765
|
+
// redundancy. The prose already showed while it streamed; during execution we show the tool rows,
|
|
766
|
+
// not a re-rendered copy of it. (onToolBatch also clears these once the batch fully settles.)
|
|
767
|
+
liveText.current = "";
|
|
768
|
+
liveReasoning.current = "";
|
|
769
|
+
setLive(null);
|
|
610
770
|
setStepLabel(calls.map((c) => c.name).join(", "));
|
|
611
771
|
setStat("executing");
|
|
612
772
|
setLiveTools(seedLiveTools(calls));
|
|
@@ -615,13 +775,14 @@ function Root() {
|
|
|
615
775
|
setLiveTools((rows) => settleLiveTool(rows, id, result));
|
|
616
776
|
},
|
|
617
777
|
onToolBatch: (events, durationMs) => {
|
|
778
|
+
const steps = [];
|
|
618
779
|
for (const ev of events) {
|
|
619
780
|
const step = {
|
|
620
781
|
id: nextId(), name: ev.name, args: ev.args,
|
|
621
782
|
status: isErrorResult(ev.result) ? "error" : "done",
|
|
622
783
|
durationMs, summary: firstLine(ev.result),
|
|
623
784
|
};
|
|
624
|
-
push(
|
|
785
|
+
steps.push(step);
|
|
625
786
|
remoteRef.current?.toolStep(step);
|
|
626
787
|
// Track skills this session has actually pulled in, for RemoteCapabilities.skills (see
|
|
627
788
|
// skillsRef above) — the description is synthetic (this codebase has no skill metadata to
|
|
@@ -639,13 +800,26 @@ function Root() {
|
|
|
639
800
|
}
|
|
640
801
|
}
|
|
641
802
|
}
|
|
803
|
+
// >1 tool in one round ran CONCURRENTLY (executeParallel) — box them so the parallelism reads at
|
|
804
|
+
// a glance instead of as a flat sequential list; a lone call stays a plain row.
|
|
805
|
+
if (steps.length > 1)
|
|
806
|
+
push({ kind: "toolBatch", id: nextId(), steps, durationMs });
|
|
807
|
+
else if (steps.length === 1)
|
|
808
|
+
push({ kind: "tool", step: steps[0] });
|
|
642
809
|
liveText.current = "";
|
|
643
810
|
liveReasoning.current = "";
|
|
644
811
|
setLive(null);
|
|
645
812
|
setLiveTools([]); // batch settled — the per-call rows are now in the settled transcript above
|
|
813
|
+
toolTotal.current += events.length; // session tool-call tally for /stats
|
|
814
|
+
if (events.some((ev) => ev.name.startsWith("task_")))
|
|
815
|
+
setTasks(getAgentTasks()); // refresh the plan pane
|
|
646
816
|
setStat("thinking");
|
|
647
817
|
},
|
|
648
818
|
});
|
|
819
|
+
// A completed (not interrupted) turn while still in plan mode counts as "a plan was proposed" —
|
|
820
|
+
// arms the exit-time Approve & run picker (see applyMode).
|
|
821
|
+
if (!outcome.interrupted && session.inPlanMode())
|
|
822
|
+
planProposedRef.current = true;
|
|
649
823
|
if (outcome.interrupted) {
|
|
650
824
|
push({ kind: "message", message: { id: nextId(), role: "assistant", content: "⎋ interrupted — output above kept" } });
|
|
651
825
|
remoteRef.current?.system("⎋ interrupted — output above kept");
|
|
@@ -670,11 +844,18 @@ function Root() {
|
|
|
670
844
|
const durationMs = outcome.durationMs ?? 0;
|
|
671
845
|
const secs = durationMs / 1000;
|
|
672
846
|
const tps = outcome.genMs && outcome.genMs > 0 ? Math.round(tok / (outcome.genMs / 1000)) : 0;
|
|
847
|
+
if (tps > 0)
|
|
848
|
+
tokHist.current = [...tokHist.current, tps].slice(-40); // keep the last 40 turns' throughput
|
|
673
849
|
const prefill = outcome.promptTokens ?? 0;
|
|
674
850
|
const parts = [fmtDuration(secs), `${fmtTokens(tok).replace(/ tokens?$/, " tok")}${tps ? ` @ ${tps} tok/s` : ""}`];
|
|
675
851
|
if (prefill)
|
|
676
852
|
parts.push(`${fmtTokens(prefill).replace(/ tokens?$/, "")} prefill`);
|
|
677
853
|
setMetrics(`(${parts.join(" · ")})`);
|
|
854
|
+
// Enterprise summary card (SPEC §6) — a compact end-of-turn card in the transcript, but only for a
|
|
855
|
+
// turn that actually did work (used tools). A pure Q&A turn just shows its answer, no card noise.
|
|
856
|
+
if (outcome.toolCalls > 0) {
|
|
857
|
+
push({ kind: "summary", summary: { id: nextId(), durationMs, tokens: tok, tps: tps || undefined, prefill: prefill || undefined, rounds: outcome.rounds, tools: outcome.toolCalls, unverified: outcome.unverified } });
|
|
858
|
+
}
|
|
678
859
|
// Feed the same numbers to the frozen event stream (dashboard + mobile). Gated on telemetry.enabled.
|
|
679
860
|
if (emitTelemetry) {
|
|
680
861
|
eventSink.emit({ kind: "turn", session: SESSION_ID, actor: EVENT_ACTOR,
|
|
@@ -691,6 +872,9 @@ function Root() {
|
|
|
691
872
|
setLiveTools([]); // an interrupt/error mid-batch must not leave stale "running" rows on screen
|
|
692
873
|
setCtxPct(session.ctxPct());
|
|
693
874
|
setStat("idle");
|
|
875
|
+
const live = bg.list().filter((a) => a.status === "working" || a.status === "queued");
|
|
876
|
+
if (live.length)
|
|
877
|
+
push({ kind: "message", message: { id: nextId(), role: "system", content: `${live.length} sub-agent${live.length > 1 ? "s" : ""} still running — results post when done. /agents for status` } });
|
|
694
878
|
try {
|
|
695
879
|
writeFileSync(SESSION_FILE, JSON.stringify(session.snapshot()));
|
|
696
880
|
}
|
|
@@ -708,14 +892,14 @@ function Root() {
|
|
|
708
892
|
push({ kind: "message", message: { id: nextId(), role: "system", content: text } });
|
|
709
893
|
remoteRef.current?.system(text);
|
|
710
894
|
}, []);
|
|
711
|
-
//
|
|
712
|
-
//
|
|
713
|
-
//
|
|
714
|
-
|
|
715
|
-
const applyMode = useCallback((next, quiet) => {
|
|
895
|
+
// The actual mode switch — policy, plan flag, status badge, and follower-facing capabilities, all in
|
|
896
|
+
// lockstep. Factored out of applyMode so the plan-exit picker below can perform it from a resolve
|
|
897
|
+
// callback without re-entering (and re-gating) applyMode itself.
|
|
898
|
+
const performModeSwitch = useCallback((next, quiet) => {
|
|
716
899
|
if (next === "plan") {
|
|
717
900
|
session.setPlanMode(true);
|
|
718
|
-
|
|
901
|
+
planProposedRef.current = false;
|
|
902
|
+
} // fresh plan-mode session
|
|
719
903
|
else {
|
|
720
904
|
session.setPlanMode(false);
|
|
721
905
|
session.setPermissionMode(next === "auto" ? "bypass" : "gated");
|
|
@@ -731,6 +915,36 @@ function Root() {
|
|
|
731
915
|
: "◔ mode → PLAN — read-only research + a proposed plan; nothing runs (shift+tab to cycle)");
|
|
732
916
|
remoteRef.current?.setCapabilities(buildCapabilities()); // re-sync attached followers' mode selector
|
|
733
917
|
}, [sys]);
|
|
918
|
+
// Single code path for a mode change — Shift+Tab (onCycleMode), the /mode slash command (local or
|
|
919
|
+
// driven by a remote follower), and /plan all funnel here so the policy, the plan flag, the status
|
|
920
|
+
// badge, and the follower-facing capabilities stay in lockstep. auto=Autonomous (bypass policy, no
|
|
921
|
+
// approvals), manual=gated (mutations ask), plan=read-only research (session plan mode).
|
|
922
|
+
//
|
|
923
|
+
// Leaving plan mode after the model actually proposed a plan doesn't switch silently — it parks an
|
|
924
|
+
// Approve & run / Keep planning / Cancel picker (reusing QuestionPrompt) and defers the real switch
|
|
925
|
+
// to the owner's choice. Toggling plan mode with no proposal yet falls straight through to
|
|
926
|
+
// performModeSwitch, unchanged from before.
|
|
927
|
+
const applyMode = useCallback((next, quiet) => {
|
|
928
|
+
if (shouldPromptPlanExit(opModeRef.current, next, planProposedRef.current)) {
|
|
929
|
+
setPlanExitPicker({
|
|
930
|
+
question: "A plan was proposed — approve and run it?",
|
|
931
|
+
options: PLAN_EXIT_OPTIONS,
|
|
932
|
+
resolve: (answer) => {
|
|
933
|
+
setPlanExitPicker(null);
|
|
934
|
+
const outcome = resolvePlanExit(answer);
|
|
935
|
+
if (!outcome.performSwitch)
|
|
936
|
+
return; // "Keep planning" (or the free-text escape) — stay put
|
|
937
|
+
planProposedRef.current = false;
|
|
938
|
+
performModeSwitch(next, true); // quiet — this resolver gives its own message below
|
|
939
|
+
sys(outcome.message);
|
|
940
|
+
if (outcome.submitText)
|
|
941
|
+
submitRef.current(outcome.submitText);
|
|
942
|
+
},
|
|
943
|
+
});
|
|
944
|
+
return;
|
|
945
|
+
}
|
|
946
|
+
performModeSwitch(next, quiet);
|
|
947
|
+
}, [performModeSwitch, sys]);
|
|
734
948
|
const handleSlash = useCallback(async (cmd) => {
|
|
735
949
|
const [name, ...rest] = cmd.slice(1).split(/\s+/);
|
|
736
950
|
const arg = rest.join(" ").trim();
|
|
@@ -749,6 +963,9 @@ function Root() {
|
|
|
749
963
|
setEntries([]);
|
|
750
964
|
setLive(null);
|
|
751
965
|
break;
|
|
966
|
+
case "stats":
|
|
967
|
+
push({ kind: "stats", id: nextId(), stats: { turns: s.turnCount(), toolCalls: toolTotal.current, tokens: s.sessionTokens(), ctxPct: s.ctxPct(), tokPerSec: tokHist.current } });
|
|
968
|
+
break;
|
|
752
969
|
case "new":
|
|
753
970
|
s.reset();
|
|
754
971
|
setEntries([]);
|
|
@@ -796,18 +1013,46 @@ function Root() {
|
|
|
796
1013
|
sys(`unknown endpoint "${arg}" — see /endpoints`);
|
|
797
1014
|
break;
|
|
798
1015
|
case "compact": {
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
1016
|
+
// compactNow() runs the Aurora summarizer — several seconds with NO feedback before this fix, so
|
|
1017
|
+
// a user who saw nothing happen pressed /compact again and it ran twice (double-freed, screenshot
|
|
1018
|
+
// 2026-09-26). Guard on the synchronous statusRef mirror (set before the await yields) so a second
|
|
1019
|
+
// /compact while one is in flight is a no-op, and drive the amber RecoverSpinner ("compacting
|
|
1020
|
+
// context…") so it's visibly happening — then report the before→after ctx% so "done" is unmistakable.
|
|
1021
|
+
if (statusRef.current === "compacting") {
|
|
1022
|
+
sys("compaction already in progress…");
|
|
1023
|
+
break;
|
|
1024
|
+
}
|
|
1025
|
+
const beforePct = s.ctxPct();
|
|
1026
|
+
setStepLabel("compacting context");
|
|
1027
|
+
setStat("compacting");
|
|
1028
|
+
try {
|
|
1029
|
+
const n = await s.compactNow();
|
|
1030
|
+
sys(n > 0
|
|
1031
|
+
? `compacted · freed ~${n.toLocaleString()} tokens · ctx ${beforePct}%→${s.ctxPct()}%`
|
|
1032
|
+
: "already minimal — nothing to shed");
|
|
1033
|
+
}
|
|
1034
|
+
finally {
|
|
1035
|
+
setStepLabel("");
|
|
1036
|
+
setStat("idle");
|
|
1037
|
+
setCtxPct(s.ctxPct());
|
|
1038
|
+
}
|
|
802
1039
|
break;
|
|
803
1040
|
}
|
|
804
|
-
case "remember":
|
|
805
|
-
|
|
806
|
-
|
|
1041
|
+
case "remember": {
|
|
1042
|
+
// Write to the flat memories.md (always-loaded next session) AND the semantic recall store. A
|
|
1043
|
+
// leading --global targets ~/.axe/operator/memories.md (every project) instead of this repo's
|
|
1044
|
+
// .operator/memories.md.
|
|
1045
|
+
const global = /^--global\b/.test(arg ?? "");
|
|
1046
|
+
const note = (arg ?? "").replace(/^--global\s*/, "").trim();
|
|
1047
|
+
if (!note) {
|
|
1048
|
+
sys("usage: /remember [--global] <note> — add a note to memories.md (loaded every session)");
|
|
807
1049
|
break;
|
|
808
1050
|
}
|
|
809
|
-
|
|
1051
|
+
const path = appendMemory(note, global ? "global" : "project");
|
|
1052
|
+
await s.remember(note);
|
|
1053
|
+
sys(path ? `remembered → ${path}` : "could not write that note");
|
|
810
1054
|
break;
|
|
1055
|
+
}
|
|
811
1056
|
case "memory": {
|
|
812
1057
|
const m = await s.memoryText(arg || undefined, 10);
|
|
813
1058
|
sys(m || "(no memories yet — /remember <note> to add one)");
|
|
@@ -824,43 +1069,109 @@ function Root() {
|
|
|
824
1069
|
break;
|
|
825
1070
|
}
|
|
826
1071
|
case "login": {
|
|
827
|
-
//
|
|
828
|
-
//
|
|
829
|
-
//
|
|
830
|
-
|
|
1072
|
+
// In-session sign-in mirrors the SHELL `operator auth login` DEFAULT: email + a 6-digit code, NOT
|
|
1073
|
+
// the RFC 8628 browser device-grant. auth/commands.ts documents the terminal→browser dance as janky
|
|
1074
|
+
// (it dead-ends at "token copied" and never completes in-session), so email is the default there too.
|
|
1075
|
+
// /login <email> sends a 6-digit code (remembered in pendingLoginEmailRef)
|
|
1076
|
+
// /login <6 digits> verifies the code for that email and signs in
|
|
1077
|
+
// /login <token> pastes a personal access token (unchanged)
|
|
1078
|
+
// /login --browser the explicit device-grant fallback (unchanged behaviour)
|
|
1079
|
+
const a = (arg ?? "").trim();
|
|
1080
|
+
const { signupStart, signupVerify, verifyToken, authBase } = await import("./auth/client.js");
|
|
1081
|
+
const { classifyLoginArg } = await import("./auth/login-intent.js");
|
|
1082
|
+
const { saveCredentials } = await import("./auth/store.js");
|
|
1083
|
+
const { setOperatorToken } = await import("./engine/aurora.js");
|
|
1084
|
+
const intent = classifyLoginArg(a);
|
|
1085
|
+
if (intent !== "empty")
|
|
1086
|
+
loginEmptyRetryRef.current = false;
|
|
1087
|
+
const runBrowserLogin = async () => {
|
|
831
1088
|
const { requestDeviceCode, awaitApproval } = await import("./auth/client.js");
|
|
832
1089
|
const { openBrowser } = await import("./auth/commands.js");
|
|
833
|
-
const { saveCredentials } = await import("./auth/store.js");
|
|
834
|
-
const { setOperatorToken } = await import("./engine/aurora.js");
|
|
835
1090
|
try {
|
|
836
1091
|
const dc = await requestDeviceCode();
|
|
837
|
-
const
|
|
838
|
-
|
|
839
|
-
sys(`◔ sign-in: ${opened ? "opened" : "open"} ${dc.verification_uri} and approve with code \x1b[1m${dc.user_code}\x1b[0m — waiting…`);
|
|
1092
|
+
const opened = openBrowser(dc.verification_uri_complete ?? dc.verification_uri);
|
|
1093
|
+
sys(`◔ sign-in: ${opened ? "opened the browser to" : "open"} ${dc.verification_uri} and approve with code \x1b[1m${dc.user_code}\x1b[0m — waiting… (if no browser opened, open that URL yourself)`);
|
|
840
1094
|
const r = await awaitApproval(dc);
|
|
841
1095
|
if (r.state === "approved") {
|
|
842
|
-
await saveCredentials({ token: r.token, user: r.account.external_id, issuedAt: Date.now() });
|
|
843
|
-
setOperatorToken(r.token);
|
|
1096
|
+
await saveCredentials({ token: r.token, user: r.account.external_id, host: authBase(), issuedAt: Date.now() });
|
|
1097
|
+
setOperatorToken(r.token);
|
|
844
1098
|
setAuthUser(r.account.email ?? r.account.external_id);
|
|
845
1099
|
sys(`✓ Authenticated as ${r.account.email ?? r.account.external_id}`);
|
|
846
1100
|
}
|
|
847
|
-
else
|
|
848
|
-
sys(`sign-in ${r.state} — /login to
|
|
849
|
-
}
|
|
1101
|
+
else
|
|
1102
|
+
sys(`sign-in ${r.state} — try /login <email> to sign in by code instead`);
|
|
850
1103
|
}
|
|
851
1104
|
catch (e) {
|
|
852
|
-
sys(`sign-in failed: ${e instanceof Error ? e.message : String(e)} — /login
|
|
1105
|
+
sys(`sign-in failed: ${e instanceof Error ? e.message : String(e)} — try /login <email>`);
|
|
853
1106
|
}
|
|
1107
|
+
};
|
|
1108
|
+
if (intent === "browser") {
|
|
1109
|
+
await runBrowserLogin();
|
|
854
1110
|
break;
|
|
855
1111
|
}
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
1112
|
+
if (intent === "empty") {
|
|
1113
|
+
// A second consecutive bare /login escalates to the browser device-grant.
|
|
1114
|
+
if (loginEmptyRetryRef.current) {
|
|
1115
|
+
loginEmptyRetryRef.current = false;
|
|
1116
|
+
await runBrowserLogin();
|
|
1117
|
+
break;
|
|
1118
|
+
}
|
|
1119
|
+
loginEmptyRetryRef.current = true;
|
|
1120
|
+
sys(pendingLoginEmailRef.current
|
|
1121
|
+
? `a code was sent to ${pendingLoginEmailRef.current} — enter it with /login <6-digit code> (or press /login again to open the browser)`
|
|
1122
|
+
: "usage: /login <email> — sends a 6-digit sign-in code (then /login <code>). Press /login again to open the browser; /login <token> pastes a PAT.");
|
|
1123
|
+
break;
|
|
1124
|
+
}
|
|
1125
|
+
if (intent === "code") { // a 6-digit code completes a pending email sign-in
|
|
1126
|
+
const email = pendingLoginEmailRef.current;
|
|
1127
|
+
if (!email) {
|
|
1128
|
+
sys("no code pending — run /login <email> first to get one");
|
|
1129
|
+
break;
|
|
1130
|
+
}
|
|
1131
|
+
const v = await signupVerify(email, a);
|
|
1132
|
+
if (v.ok) {
|
|
1133
|
+
await saveCredentials({ token: v.token, user: v.account.external_id, host: authBase(), issuedAt: Date.now() });
|
|
1134
|
+
setOperatorToken(v.token);
|
|
1135
|
+
setAuthUser(v.account.email ?? v.account.external_id);
|
|
1136
|
+
pendingLoginEmailRef.current = null;
|
|
1137
|
+
sys(`✓ signed in as ${v.account.email ?? v.account.external_id}`);
|
|
1138
|
+
}
|
|
1139
|
+
else if (v.error === "invalid_code")
|
|
1140
|
+
sys("wrong code — /login <code> to try again");
|
|
1141
|
+
else if (v.error === "no_pending_code") {
|
|
1142
|
+
pendingLoginEmailRef.current = null;
|
|
1143
|
+
sys("that code expired — /login <email> for a fresh one");
|
|
1144
|
+
}
|
|
1145
|
+
else if (v.error === "too_many_attempts") {
|
|
1146
|
+
pendingLoginEmailRef.current = null;
|
|
1147
|
+
sys("too many wrong tries — /login <email> for a fresh code");
|
|
1148
|
+
}
|
|
1149
|
+
else
|
|
1150
|
+
sys(`sign-in failed (${v.error}) — /login <email> to retry`);
|
|
1151
|
+
break;
|
|
1152
|
+
}
|
|
1153
|
+
if (intent === "email") { // an email address starts the code flow
|
|
1154
|
+
const started = await signupStart(a);
|
|
1155
|
+
if (started.ok) {
|
|
1156
|
+
pendingLoginEmailRef.current = a;
|
|
1157
|
+
sys(`✓ code sent to ${a} (valid 10 min) — enter it with /login <6-digit code>`);
|
|
1158
|
+
}
|
|
1159
|
+
else if (started.error === "invalid_email")
|
|
1160
|
+
sys(`"${a}" doesn't look like a valid email`);
|
|
1161
|
+
else if (started.error === "too_many_requests")
|
|
1162
|
+
sys("too many codes requested — wait a few minutes, then /login <email> again");
|
|
1163
|
+
else
|
|
1164
|
+
sys(`couldn't start sign-in (${started.error})`);
|
|
1165
|
+
break;
|
|
1166
|
+
}
|
|
1167
|
+
// Otherwise treat it as a pasted personal access token.
|
|
1168
|
+
const acct = await verifyToken(a);
|
|
859
1169
|
if (!acct) {
|
|
860
|
-
sys("that token was rejected");
|
|
1170
|
+
sys("that token was rejected — did you mean /login <email>?");
|
|
861
1171
|
break;
|
|
862
1172
|
}
|
|
863
|
-
await saveCredentials({ token:
|
|
1173
|
+
await saveCredentials({ token: a, user: acct.external_id, host: authBase(), issuedAt: Date.now() });
|
|
1174
|
+
setOperatorToken(a);
|
|
864
1175
|
setAuthUser(acct.email ?? acct.external_id);
|
|
865
1176
|
sys(`signed in as ${acct.email ?? acct.external_id}`);
|
|
866
1177
|
break;
|
|
@@ -877,10 +1188,15 @@ function Root() {
|
|
|
877
1188
|
}
|
|
878
1189
|
case "plan": {
|
|
879
1190
|
const on = !s.inPlanMode();
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
1191
|
+
const next = on ? "plan" : "auto";
|
|
1192
|
+
// A plan was proposed → applyMode parks the Approve & run picker instead of switching, and its
|
|
1193
|
+
// own resolve() gives the exit message — this command's custom line would be premature/wrong.
|
|
1194
|
+
const gated = shouldPromptPlanExit(opModeRef.current, next, planProposedRef.current);
|
|
1195
|
+
applyMode(next, true); // policy + follower caps sync; custom message below (unless gated)
|
|
1196
|
+
if (!gated)
|
|
1197
|
+
sys(on
|
|
1198
|
+
? "◔ plan mode ON — I'll research read-only and propose a plan; writes/edits/shell mutations are blocked. /plan again to approve + execute."
|
|
1199
|
+
: "plan mode OFF — back to normal execution.");
|
|
884
1200
|
break;
|
|
885
1201
|
}
|
|
886
1202
|
case "mode": {
|
|
@@ -944,6 +1260,42 @@ function Root() {
|
|
|
944
1260
|
sys(rows.length ? `audit (last ${rows.length}):\n` + rows.join("\n") : "no tool/control events in the audit log yet");
|
|
945
1261
|
break;
|
|
946
1262
|
}
|
|
1263
|
+
case "monitor": {
|
|
1264
|
+
if (arg === "off" && monitorRef.current) {
|
|
1265
|
+
eventSink.unsubscribe(monitorRef.current);
|
|
1266
|
+
monitorRef.current = null;
|
|
1267
|
+
sys("monitor off");
|
|
1268
|
+
break;
|
|
1269
|
+
}
|
|
1270
|
+
if (monitorRef.current) {
|
|
1271
|
+
sys("monitor already on — /monitor off to stop");
|
|
1272
|
+
break;
|
|
1273
|
+
}
|
|
1274
|
+
const listener = (e) => {
|
|
1275
|
+
const t = new Date(e.ts).toLocaleTimeString();
|
|
1276
|
+
let line;
|
|
1277
|
+
if (e.kind === "tool" && e.tool) {
|
|
1278
|
+
const g = e.tool.decision === "deny" ? "✗" : e.tool.approved === false ? "⃠" : "●";
|
|
1279
|
+
line = `${t} ${g} ${e.tool.name} [${e.tool.outcome}]${e.tool.durationMs ? ` ${e.tool.durationMs}ms` : ""}${e.tool.args ? " " + String(e.tool.args).slice(0, 60) : ""}`;
|
|
1280
|
+
}
|
|
1281
|
+
else if (e.kind === "turn" && e.turn) {
|
|
1282
|
+
line = `${t} ↻ turn ${e.turn.tokens} tok ctx ${e.turn.ctxPct}% ${e.turn.route}${e.turn.durationMs ? ` ${(e.turn.durationMs / 1000).toFixed(1)}s` : ""}`;
|
|
1283
|
+
}
|
|
1284
|
+
else if (e.kind === "control" && e.control) {
|
|
1285
|
+
line = `${t} ⚑ ${e.control.event}${e.control.detail ? " " + e.control.detail : ""}`;
|
|
1286
|
+
}
|
|
1287
|
+
else if (e.kind === "service" && e.service) {
|
|
1288
|
+
line = `${t} ◈ ${e.service.name} ${e.service.state}`;
|
|
1289
|
+
}
|
|
1290
|
+
else
|
|
1291
|
+
return;
|
|
1292
|
+
setEntries((prev) => [...prev, { kind: "message", message: { id: nextId(), role: "system", content: `[monitor] ${line}` } }]);
|
|
1293
|
+
};
|
|
1294
|
+
monitorRef.current = listener;
|
|
1295
|
+
eventSink.subscribe(listener);
|
|
1296
|
+
sys("monitor on — live event stream active. /monitor off to stop");
|
|
1297
|
+
break;
|
|
1298
|
+
}
|
|
947
1299
|
case "dashboard": {
|
|
948
1300
|
// Launch the live swarm console (dashboard/server.mjs) if it isn't already up. It live-tails
|
|
949
1301
|
// ~/.axe/operator/events.jsonl, so it shows EVERY Operator session with zero per-session config.
|
|
@@ -992,13 +1344,35 @@ function Root() {
|
|
|
992
1344
|
aurora: { base: settings.endpoints.aurora.base, ...settings.services?.aurora },
|
|
993
1345
|
autopilot: settings.services?.autopilot,
|
|
994
1346
|
});
|
|
995
|
-
|
|
1347
|
+
const { searxngStatus, probeSearxng } = await import("./tools/searxng.js");
|
|
1348
|
+
const sxActive = searxngStatus() === "active";
|
|
1349
|
+
const sxUp = sxActive || await probeSearxng().catch(() => false);
|
|
1350
|
+
const sxText = sxActive
|
|
1351
|
+
? "● searxng ✓ active (served a search this session)"
|
|
1352
|
+
: sxUp
|
|
1353
|
+
? "● searxng ✓ up (reachable; serves web_search)"
|
|
1354
|
+
: "○ searxng lazy (starts on first web_search, stops on idle/exit)";
|
|
1355
|
+
sys("services:\n" + reports.map((r) => ` ${r.state === "up" || r.state === "started" ? "●" : "○"} ${r.name} ${r.state}${r.detail ? " " + r.detail : ""}`).join("\n") + "\n " + sxText);
|
|
1356
|
+
break;
|
|
1357
|
+
}
|
|
1358
|
+
case "agents": {
|
|
1359
|
+
const l = bg.list();
|
|
1360
|
+
if (!l.length) {
|
|
1361
|
+
sys("no sub-agents spawned this session");
|
|
1362
|
+
break;
|
|
1363
|
+
}
|
|
1364
|
+
const running = l.filter((a) => a.status === "working").length;
|
|
1365
|
+
const queued = l.filter((a) => a.status === "queued").length;
|
|
1366
|
+
const done = l.filter((a) => a.status === "idle").length;
|
|
1367
|
+
const errored = l.filter((a) => a.status === "stopped").length;
|
|
1368
|
+
const counts = [running ? `${running} running` : "", queued ? `${queued} queued` : "", done ? `${done} done` : "", errored ? `${errored} errored` : ""].filter(Boolean).join(" · ");
|
|
1369
|
+
sys(`sub-agents (${counts}):\n` + l.map((a) => ` ${formatAgentDetail(a)}`).join("\n"));
|
|
996
1370
|
break;
|
|
997
1371
|
}
|
|
998
1372
|
case "bg":
|
|
999
1373
|
if (!arg) {
|
|
1000
1374
|
const l = bg.list();
|
|
1001
|
-
sys(l.length ? "background agents:\n" + l.map((a) => ` ${a
|
|
1375
|
+
sys(l.length ? "background agents:\n" + l.map((a) => ` ${formatAgentLine(a)}`).join("\n") : "no background agents (spawn: /bg <task>)");
|
|
1002
1376
|
}
|
|
1003
1377
|
else if (arg.startsWith("stop ")) {
|
|
1004
1378
|
const id = arg.slice(5).trim();
|
|
@@ -1006,7 +1380,7 @@ function Root() {
|
|
|
1006
1380
|
}
|
|
1007
1381
|
else {
|
|
1008
1382
|
const id = bg.spawn(arg);
|
|
1009
|
-
sys(`spawned ${id} in the background — /bg to list · /bg stop ${id} to cancel`);
|
|
1383
|
+
sys(id ? `spawned ${id} in the background — /bg to list · /bg stop ${id} to cancel` : bg.capacityLine());
|
|
1010
1384
|
}
|
|
1011
1385
|
break;
|
|
1012
1386
|
case "remotecontrol":
|
|
@@ -1078,9 +1452,8 @@ function Root() {
|
|
|
1078
1452
|
}
|
|
1079
1453
|
}, [exit, sys, bg, authUser, approval, settleApproval, settleQuestion, applyMode]);
|
|
1080
1454
|
const onSubmit = useCallback((text) => {
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
void handleSlash(t);
|
|
1455
|
+
if (isSlashCommand(text)) {
|
|
1456
|
+
void handleSlash(text.trim());
|
|
1084
1457
|
return;
|
|
1085
1458
|
}
|
|
1086
1459
|
void sendTurn(text);
|
|
@@ -1111,7 +1484,7 @@ function Root() {
|
|
|
1111
1484
|
const active = status === "thinking" || status === "streaming" || status === "executing" || status === "recovering";
|
|
1112
1485
|
if (!active)
|
|
1113
1486
|
return;
|
|
1114
|
-
const id = setInterval(() => setElapsed((Date.now() - turnStartRef.current) / 1000),
|
|
1487
|
+
const id = setInterval(() => setElapsed((Date.now() - turnStartRef.current) / 1000), 500); // 500ms: the elapsed readout shows whole/half seconds; 250ms doubled the whole-frame re-render rate (flashing)
|
|
1115
1488
|
return () => clearInterval(id);
|
|
1116
1489
|
}, [status]);
|
|
1117
1490
|
if (boot === "checking")
|
|
@@ -1133,7 +1506,7 @@ function Root() {
|
|
|
1133
1506
|
? `${spin} reading your prompt… (${fmtDuration(elapsed)})`
|
|
1134
1507
|
: `${spin} ${fmtMeta(elapsed, liveTok)}`
|
|
1135
1508
|
: metrics;
|
|
1136
|
-
return (_jsx(App, { messages: entries, live: live, status: status, stepLabel: stepLabel, liveTools: liveTools, route: route, ctxPct: ctxPct, version: VERSION, metrics: liveMetrics, sessionTokens: session.sessionTokens() + liveTok, authUser: authUser, tier: EVENT_ACTOR.tier, planMode: planMode, thinkMode: thinkMode, verbs: settings.verbs, bgAgents: bgAgents, onSubmit: onSubmit, onQueue: onQueue, onInterrupt: onInterrupt, onCycleMode: onCycleMode, opMode: opMode, approval: approval, question: question, modelPicker: modelPicker, onApprovalDecide: (allow, always) => {
|
|
1509
|
+
return (_jsx(App, { messages: entries, live: live, status: status, stepLabel: stepLabel, liveTools: liveTools, route: route, ctxPct: ctxPct, version: VERSION, fullscreen: FULLSCREEN, metrics: liveMetrics, sessionTokens: session.sessionTokens() + liveTok, authUser: authUser, tier: EVENT_ACTOR.tier, planMode: planMode, thinkMode: thinkMode, verbs: settings.verbs, bgAgents: bgAgents, tasks: tasks, onSubmit: onSubmit, onQueue: onQueue, onInterrupt: onInterrupt, onCycleMode: onCycleMode, opMode: opMode, approval: approval, question: question, modelPicker: modelPicker, planExitPicker: planExitPicker, onApprovalDecide: (allow, always) => {
|
|
1137
1510
|
const cur = approval;
|
|
1138
1511
|
if (cur)
|
|
1139
1512
|
settleApproval(cur.id, allow, always); // first-wins with any remote follower answer
|
|
@@ -1141,6 +1514,16 @@ function Root() {
|
|
|
1141
1514
|
}
|
|
1142
1515
|
// `operator auth …` runs as a plain CLI before the Ink shell — no TTY needed, so PAT login works
|
|
1143
1516
|
// headless (CI / SSH). Anything else falls through to the interactive REPL below.
|
|
1517
|
+
// Fast paths that must NOT mount Ink/React (so `operator --version` works with no TTY and returns instantly).
|
|
1518
|
+
if (process.argv.includes("--version") || process.argv.includes("-V")) {
|
|
1519
|
+
process.stdout.write(VERSION + "\n");
|
|
1520
|
+
process.exit(0);
|
|
1521
|
+
}
|
|
1522
|
+
if (process.argv.includes("--help")) {
|
|
1523
|
+
process.stdout.write(mastheadLines(`300K · v${VERSION}`).join("\n") +
|
|
1524
|
+
"\n\nUsage:\n operator start the interactive session\n operator --resume resume the last session in this directory\n operator --update update to the latest build (git fast-forward)\n operator --fullscreen fullscreen layout: composer pinned to the bottom (or settings.ui.fullscreen)\n operator auth sign in / manage your AXE account\n operator run <task> run one task headless\n operator --version print the version\n");
|
|
1525
|
+
process.exit(0);
|
|
1526
|
+
}
|
|
1144
1527
|
if (process.argv[2] === "auth") {
|
|
1145
1528
|
const { runAuth } = await import("./auth/commands.js");
|
|
1146
1529
|
process.exit(await runAuth(process.argv.slice(3)));
|
|
@@ -1150,6 +1533,16 @@ if (process.argv[2] === "update" || process.argv.includes("--update")) {
|
|
|
1150
1533
|
const { runUpdate } = await import("./update.js");
|
|
1151
1534
|
process.exit(await runUpdate());
|
|
1152
1535
|
}
|
|
1536
|
+
// Autonomous operation (autonomy/**): `operator run/loop/board/routine/dream` run headless, WITHOUT the
|
|
1537
|
+
// Ink TUI — the same pre-shell dispatch pattern as auth/update above. dispatchAutonomy returns an exit
|
|
1538
|
+
// code when it handled the argv, or null to fall through to the interactive REPL. Dynamic import so the
|
|
1539
|
+
// autonomy stack (Session, keep-awake, schedulers) is only loaded when actually invoked.
|
|
1540
|
+
{
|
|
1541
|
+
const { dispatchAutonomy } = await import("./autonomy/index.js");
|
|
1542
|
+
const code = await dispatchAutonomy(process.argv, settings);
|
|
1543
|
+
if (code !== null)
|
|
1544
|
+
process.exit(code);
|
|
1545
|
+
}
|
|
1153
1546
|
// The Ink shell needs a real terminal (raw-mode keyboard). Fail clearly instead of crashing deep
|
|
1154
1547
|
// in useInput when piped/non-interactive — for scripted use, drive Session (src/session.ts) directly.
|
|
1155
1548
|
if (!process.stdin.isTTY) {
|
|
@@ -1158,5 +1551,35 @@ if (!process.stdin.isTTY) {
|
|
|
1158
1551
|
}
|
|
1159
1552
|
// Boot masthead (design #29) — printed ONCE to stdout before Ink mounts, so the big gradient wordmark
|
|
1160
1553
|
// lives in permanent scrollback and never enters Ink's dynamic-frame redraw (reflow-safe by construction).
|
|
1161
|
-
|
|
1162
|
-
|
|
1554
|
+
// Fullscreen instead switches to the ALTERNATE screen buffer first (the scrollback masthead trick can't
|
|
1555
|
+
// survive an alt-screen swap), so the banner is skipped there — the status rule carries the branding. On
|
|
1556
|
+
// exit we always restore the main buffer, so the terminal comes back exactly as it was (vim/less style).
|
|
1557
|
+
const leaveAltScreen = () => { try {
|
|
1558
|
+
process.stdout.write("\x1b[?1049l");
|
|
1559
|
+
}
|
|
1560
|
+
catch { } };
|
|
1561
|
+
if (FULLSCREEN) {
|
|
1562
|
+
process.stdout.write("\x1b[?1049h\x1b[H"); // enter alt-screen + cursor home
|
|
1563
|
+
process.on("exit", leaveAltScreen);
|
|
1564
|
+
for (const sig of ["SIGINT", "SIGTERM", "SIGHUP"])
|
|
1565
|
+
process.once(sig, () => { leaveAltScreen(); process.exit(0); });
|
|
1566
|
+
}
|
|
1567
|
+
else {
|
|
1568
|
+
process.stdout.write(mastheadLines(`300K · v${VERSION}`).join("\n") + "\n");
|
|
1569
|
+
}
|
|
1570
|
+
const inkInstance = render(_jsx(Root, {}));
|
|
1571
|
+
if (FULLSCREEN)
|
|
1572
|
+
void inkInstance.waitUntilExit().then(leaveAltScreen);
|
|
1573
|
+
// Ink erases the previous frame by line COUNT, computed from the terminal width at draw time. When the
|
|
1574
|
+
// window is minimized or resized, a resize event with a changed/zero width desyncs that count, so every
|
|
1575
|
+
// later re-render (a keystroke, the 250ms clock) APPENDS the status rule instead of overwriting it — the
|
|
1576
|
+
// "a new line every time I type" screen-fill. Force a full clear on each resize so Ink re-syncs to the
|
|
1577
|
+
// real terminal and redraws from a clean slate instead of stacking stale frames.
|
|
1578
|
+
let resizeClear;
|
|
1579
|
+
process.stdout.on?.("resize", () => {
|
|
1580
|
+
clearTimeout(resizeClear);
|
|
1581
|
+
resizeClear = setTimeout(() => { try {
|
|
1582
|
+
inkInstance.clear();
|
|
1583
|
+
}
|
|
1584
|
+
catch { /* stdout detached */ } }, 16);
|
|
1585
|
+
});
|