@0perator/operator 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +73 -0
- package/dist/auth/client.js +94 -0
- package/dist/auth/commands.js +99 -0
- package/dist/auth/store.js +99 -0
- package/dist/background/index.js +64 -0
- package/dist/cli.js +407 -0
- package/dist/config/settings.js +85 -0
- package/dist/engine/agent.js +232 -0
- package/dist/engine/aurora.js +213 -0
- package/dist/engine/compaction.js +111 -0
- package/dist/engine/contract.js +8 -0
- package/dist/engine/messages.js +85 -0
- package/dist/engine/router-adapter.js +29 -0
- package/dist/engine/selfheal.js +46 -0
- package/dist/engine/toolcalls.js +164 -0
- package/dist/index.browser.js +22 -0
- package/dist/index.js +23 -0
- package/dist/mcp/client.js +95 -0
- package/dist/mcp/config.js +73 -0
- package/dist/mcp/index.js +101 -0
- package/dist/mcp/stdio.js +149 -0
- package/dist/memory/index.js +0 -0
- package/dist/observability/index.js +60 -0
- package/dist/permissions/audit.js +50 -0
- package/dist/permissions/index.js +48 -0
- package/dist/permissions/policy.js +54 -0
- package/dist/router/router.js +94 -0
- package/dist/session.js +265 -0
- package/dist/tools/executor.js +0 -0
- package/dist/tools/registry.js +380 -0
- package/dist/tools/sandbox.js +90 -0
- package/dist/ui/ActivitySpinner.js +48 -0
- package/dist/ui/App.js +16 -0
- package/dist/ui/AuthScreen.js +17 -0
- package/dist/ui/BgPanel.js +24 -0
- package/dist/ui/Composer.js +119 -0
- package/dist/ui/Header.js +22 -0
- package/dist/ui/StatusRule.js +11 -0
- package/dist/ui/ThinkingSpinner.js +61 -0
- package/dist/ui/ToolStep.js +32 -0
- package/dist/ui/Transcript.js +22 -0
- package/dist/ui/format.js +6 -0
- package/dist/ui/index.js +9 -0
- package/dist/ui/types.js +3 -0
- package/dist/ui/useInputHistory.js +97 -0
- package/dist/update.js +57 -0
- package/package.json +47 -0
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// Sandboxed execution (SPEC §11 / enterprise hardening). Two independent, defense-in-depth layers,
|
|
2
|
+
// BOTH off by default (KODE_SANDBOX unset / "off") so the owner's local experience is unchanged — an
|
|
3
|
+
// enterprise deployment turns them on:
|
|
4
|
+
//
|
|
5
|
+
// 1. Portable JS write-guards (deniedWrite) — deny writes to credential/key/system paths on ANY OS,
|
|
6
|
+
// wired into file_write/file_edit. In "strict" mode, writes are also confined to an allowlist
|
|
7
|
+
// (workspace + home + tmp). Pure path math, unit-tested, no platform dependency.
|
|
8
|
+
// 2. OS process sandbox (wrapShell) — on macOS, run shell_exec/git under `sandbox-exec` (seatbelt) so
|
|
9
|
+
// even a shell command can't write outside the policy (and, in strict, can't reach the network).
|
|
10
|
+
// Falls back to a no-op where sandbox-exec is unavailable (the JS guards still apply to file tools).
|
|
11
|
+
//
|
|
12
|
+
// Mode: KODE_SANDBOX = "off" (default) | "workspace" (deny sensitive writes, allow network) | "strict"
|
|
13
|
+
// (confine writes to workspace/tmp, deny network).
|
|
14
|
+
import { homedir } from "node:os";
|
|
15
|
+
import { resolve } from "node:path";
|
|
16
|
+
export function sandboxMode() {
|
|
17
|
+
const m = (process.env.KODE_SANDBOX ?? "off").toLowerCase();
|
|
18
|
+
return m === "workspace" || m === "strict" ? m : "off";
|
|
19
|
+
}
|
|
20
|
+
const HOME = homedir();
|
|
21
|
+
// Never writable when the sandbox is on, even inside home — protects credentials/keys/shell rc from an
|
|
22
|
+
// errant model action. (Reads are unaffected; only writes are blocked.)
|
|
23
|
+
const DENY_WRITE_SUBPATHS = [
|
|
24
|
+
`${HOME}/.ssh`, `${HOME}/.aws`, `${HOME}/.gnupg`, `${HOME}/.config/gcloud`,
|
|
25
|
+
`${HOME}/.axe/secrets`, `${HOME}/.kube`, `${HOME}/.docker`,
|
|
26
|
+
"/etc", "/usr", "/bin", "/sbin", "/System", "/Library", "/private/etc",
|
|
27
|
+
];
|
|
28
|
+
const DENY_WRITE_FILES = [
|
|
29
|
+
`${HOME}/.zshrc`, `${HOME}/.zshenv`, `${HOME}/.zprofile`, `${HOME}/.bashrc`,
|
|
30
|
+
`${HOME}/.bash_profile`, `${HOME}/.profile`, `${HOME}/.netrc`, `${HOME}/.git-credentials`,
|
|
31
|
+
];
|
|
32
|
+
// In strict mode, writes must land under one of these roots.
|
|
33
|
+
function allowedWriteRoots() {
|
|
34
|
+
return [process.cwd(), HOME + "/.axe/operator", "/tmp", "/private/tmp", process.env.TMPDIR ?? "/tmp"].map((p) => resolve(p));
|
|
35
|
+
}
|
|
36
|
+
/** Return an error string if `path` is a forbidden write target under the active mode, else null.
|
|
37
|
+
* Resolves `..`/sym* to a real path first so a traversal can't slip past the check. */
|
|
38
|
+
export function deniedWrite(path) {
|
|
39
|
+
if (sandboxMode() === "off")
|
|
40
|
+
return null;
|
|
41
|
+
const p = resolve(path);
|
|
42
|
+
const under = (root) => p === root || p.startsWith(root.endsWith("/") ? root : root + "/");
|
|
43
|
+
for (const f of DENY_WRITE_FILES)
|
|
44
|
+
if (p === resolve(f))
|
|
45
|
+
return `sandbox: writing ${path} is blocked (protected file)`;
|
|
46
|
+
for (const d of DENY_WRITE_SUBPATHS)
|
|
47
|
+
if (under(resolve(d)))
|
|
48
|
+
return `sandbox: writing under ${d} is blocked (protected path)`;
|
|
49
|
+
if (sandboxMode() === "strict" && !allowedWriteRoots().some(under)) {
|
|
50
|
+
return `sandbox(strict): writes are confined to the workspace + tmp — ${path} is outside`;
|
|
51
|
+
}
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
/** Build a macOS seatbelt profile string for the active mode (workspace = deny-list, strict = deny writes
|
|
55
|
+
* outside the workspace + deny network). */
|
|
56
|
+
export function seatbeltProfile(mode) {
|
|
57
|
+
const q = (s) => s.replace(/"/g, '\\"');
|
|
58
|
+
const denySub = DENY_WRITE_SUBPATHS.map((d) => `(subpath "${q(d)}")`).join(" ");
|
|
59
|
+
const denyFiles = DENY_WRITE_FILES.map((f) => `(literal "${q(f)}")`).join(" ");
|
|
60
|
+
if (mode === "strict") {
|
|
61
|
+
const allow = allowedWriteRoots().concat("/dev").map((r) => `(subpath "${q(r)}")`).join(" ");
|
|
62
|
+
return `(version 1)(allow default)(deny file-write*)(allow file-write* ${allow})(deny network*)`;
|
|
63
|
+
}
|
|
64
|
+
return `(version 1)(allow default)(deny file-write* ${denySub} ${denyFiles})`;
|
|
65
|
+
}
|
|
66
|
+
let _sbExec = null; // cache: is sandbox-exec present on this host?
|
|
67
|
+
async function hasSandboxExec() {
|
|
68
|
+
if (_sbExec !== null)
|
|
69
|
+
return _sbExec;
|
|
70
|
+
if (process.platform !== "darwin")
|
|
71
|
+
return (_sbExec = false);
|
|
72
|
+
try {
|
|
73
|
+
const { execFile } = await import("node:child_process");
|
|
74
|
+
await new Promise((res, rej) => execFile("/usr/bin/sandbox-exec", ["-p", "(version 1)(allow default)", "true"], (e) => (e ? rej(e) : res())));
|
|
75
|
+
return (_sbExec = true);
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
return (_sbExec = false);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/** Wrap a shell command for `execFile` under the OS sandbox. Returns the argv to run: under an active
|
|
82
|
+
* sandbox on macOS it's `sandbox-exec -p <profile> /bin/bash -c <command>`; otherwise the plain bash
|
|
83
|
+
* invocation (the JS write-guards still protect the file tools). */
|
|
84
|
+
export async function wrapShell(command) {
|
|
85
|
+
const mode = sandboxMode();
|
|
86
|
+
if (mode !== "off" && (await hasSandboxExec())) {
|
|
87
|
+
return { file: "/usr/bin/sandbox-exec", args: ["-p", seatbeltProfile(mode), "/bin/bash", "-c", command] };
|
|
88
|
+
}
|
|
89
|
+
return { file: "/bin/bash", args: ["-c", command] };
|
|
90
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
// The two non-"thinking" activity animations, kept visually distinct from the amber star heartbeat
|
|
3
|
+
// (ThinkingSpinner) so a glance tells you WHICH mode the agent is in — SPEC §6, matching the Python
|
|
4
|
+
// core's three-state footer. Glyphs are all Braille / Geometric-Shapes so they render in Menlo without
|
|
5
|
+
// tofu (same font-safety rule as the star).
|
|
6
|
+
// • StepSpinner — a tool batch is executing (braille run-spinner, cyan)
|
|
7
|
+
// • OrbitSpinner — a background sub-agent is working (rotating arc, violet)
|
|
8
|
+
import { useEffect, useState } from "react";
|
|
9
|
+
import { Text } from "ink";
|
|
10
|
+
function useFrame(frames, active, tickMs) {
|
|
11
|
+
const [i, setI] = useState(0);
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
if (!active)
|
|
14
|
+
return;
|
|
15
|
+
const id = setInterval(() => setI((n) => (n + 1) % frames.length), tickMs);
|
|
16
|
+
return () => clearInterval(id);
|
|
17
|
+
}, [active, frames, tickMs]);
|
|
18
|
+
return frames[i];
|
|
19
|
+
}
|
|
20
|
+
const BRAILLE = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]; // classic run-spinner
|
|
21
|
+
const ORBIT = ["◜", "◠", "◝", "◞", "◡", "◟"]; // a dot orbiting a ring — "something running elsewhere"
|
|
22
|
+
const SETTLE = ["◐", "◓", "◑", "◒"]; // a filling/turning disc — "adjusting, working it out" (NOT an error)
|
|
23
|
+
/** Tools are executing this turn. Distinct from the star: a cyan braille run-spinner + the tool name(s). */
|
|
24
|
+
export function StepSpinner({ active, label, tickMs = 80 }) {
|
|
25
|
+
const glyph = useFrame(BRAILLE, active, tickMs);
|
|
26
|
+
if (!active)
|
|
27
|
+
return null;
|
|
28
|
+
return (_jsxs(Text, { color: "#5ec8e8", children: [glyph, " ", label ? `${label}…` : "running…"] }));
|
|
29
|
+
}
|
|
30
|
+
/** A background sub-agent is working. Distinct again: a violet rotating arc + the agent label. */
|
|
31
|
+
export function OrbitSpinner({ active, label, tickMs = 120 }) {
|
|
32
|
+
const glyph = useFrame(ORBIT, active, tickMs);
|
|
33
|
+
if (!active)
|
|
34
|
+
return null;
|
|
35
|
+
return (_jsxs(Text, { color: "#b98cff", children: [glyph, " ", label ?? "sub-agent working", "\u2026"] }));
|
|
36
|
+
}
|
|
37
|
+
/** Just the animated orbit glyph (violet), for embedding in the bg-agents list beside a working agent. */
|
|
38
|
+
export function OrbitGlyph({ tickMs = 120 }) {
|
|
39
|
+
return _jsx(Text, { color: "#b98cff", children: useFrame(ORBIT, true, tickMs) });
|
|
40
|
+
}
|
|
41
|
+
/** Self-heal in progress (context compaction / reconnect). Shown INSTEAD of a raw "http 400" so a
|
|
42
|
+
* recovery reads as the agent working it out, not an error — amber turning disc + a calm label. */
|
|
43
|
+
export function RecoverSpinner({ active, label, tickMs = 130 }) {
|
|
44
|
+
const glyph = useFrame(SETTLE, active, tickMs);
|
|
45
|
+
if (!active)
|
|
46
|
+
return null;
|
|
47
|
+
return (_jsxs(Text, { color: "#e8a33d", children: [glyph, " ", label ?? "adjusting", "\u2026"] }));
|
|
48
|
+
}
|
package/dist/ui/App.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Box } from "ink";
|
|
3
|
+
import { StatusRule } from "./StatusRule.js";
|
|
4
|
+
import { Transcript } from "./Transcript.js";
|
|
5
|
+
import { Composer } from "./Composer.js";
|
|
6
|
+
import { ThinkingSpinner } from "./ThinkingSpinner.js";
|
|
7
|
+
import { StepSpinner, RecoverSpinner } from "./ActivitySpinner.js";
|
|
8
|
+
import { BgPanel } from "./BgPanel.js";
|
|
9
|
+
export function App(props) {
|
|
10
|
+
const { messages, live = null, status, thinkingVerb, verbs, stepLabel, route, ctxPct, version, build, metrics, authUser, bgAgents, onSubmit, onQueue, onInterrupt } = props;
|
|
11
|
+
const thinking = status === "thinking" || status === "streaming";
|
|
12
|
+
return (_jsxs(Box, { flexDirection: "column", children: [_jsx(Transcript, { entries: messages, live: live }), status === "recovering" ? _jsx(RecoverSpinner, { active: true, label: stepLabel })
|
|
13
|
+
: status === "executing" ? _jsx(StepSpinner, { active: true, label: stepLabel })
|
|
14
|
+
: thinking ? _jsx(ThinkingSpinner, { active: true, verb: thinkingVerb, verbs: verbs })
|
|
15
|
+
: null, _jsx(BgPanel, { agents: bgAgents }), _jsx(StatusRule, { route: route, ctxPct: ctxPct, version: version, build: build, metrics: metrics, user: authUser }), _jsx(Composer, { onSubmit: onSubmit, onQueue: onQueue, onInterrupt: onInterrupt, disabled: status !== "idle" })] }));
|
|
16
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { Box, Text, useInput } from "ink";
|
|
3
|
+
import { Header } from "./Header.js";
|
|
4
|
+
export function AuthScreen({ version, ctxWindow, authBase, pending, error, onChoice }) {
|
|
5
|
+
useInput((input, key) => {
|
|
6
|
+
if (pending)
|
|
7
|
+
return; // while a sign-in is polling, keys are inert (Esc cancels via the app)
|
|
8
|
+
const c = input.toLowerCase();
|
|
9
|
+
if (c === "s")
|
|
10
|
+
onChoice("signin");
|
|
11
|
+
else if (c === "u" || c === "c")
|
|
12
|
+
onChoice("signup");
|
|
13
|
+
else if (key.return || c === "g")
|
|
14
|
+
onChoice("guest");
|
|
15
|
+
});
|
|
16
|
+
return (_jsxs(Box, { flexDirection: "column", children: [_jsx(Header, { version: version, ctxWindow: ctxWindow }), _jsx(Box, { marginTop: 1, flexDirection: "column", paddingLeft: 1, children: pending ? (_jsxs(_Fragment, { children: [_jsxs(Text, { children: ["Signing in \u2014 open ", _jsx(Text, { color: "cyanBright", children: pending.url })] }), _jsxs(Text, { children: ["and enter code ", _jsx(Text, { bold: true, color: "whiteBright", children: pending.userCode })] }), _jsx(Text, { dimColor: true, children: "Waiting for approval in your browser\u2026 (Esc to cancel)" })] })) : (_jsxs(_Fragment, { children: [_jsx(Text, { color: "whiteBright", children: "Welcome to Operator." }), _jsx(Text, { dimColor: true, children: "A local terminal coding agent on your own Aurora model." }), _jsxs(Box, { marginTop: 1, flexDirection: "column", children: [_jsxs(Text, { children: [_jsx(Text, { color: "magentaBright", bold: true, children: " s" }), " Sign in ", _jsx(Text, { dimColor: true, children: "\u2014 connect your account (browser approval)" })] }), _jsxs(Text, { children: [_jsx(Text, { color: "magentaBright", bold: true, children: " u" }), " Create account ", _jsxs(Text, { dimColor: true, children: ["\u2014 register at ", authBase.replace(/^https?:\/\//, "")] })] }), _jsxs(Text, { children: [_jsx(Text, { color: "magentaBright", bold: true, children: " \u21B5" }), " Continue as guest ", _jsx(Text, { dimColor: true, children: "\u2014 no account needed; sign in later with /login" })] })] }), error ? _jsx(Box, { marginTop: 1, children: _jsx(Text, { color: "red", children: error }) }) : null] })) })] }));
|
|
17
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Box, Text } from "ink";
|
|
3
|
+
import { OrbitGlyph } from "./ActivitySpinner.js";
|
|
4
|
+
const GLYPH = { working: "●", idle: "○", stopped: "✗" };
|
|
5
|
+
const COLOR = { working: "#e8a33d", idle: "gray", stopped: "red" };
|
|
6
|
+
const toks = (n) => (n >= 1000 ? `${(n / 1000).toFixed(1)}k` : `${n}`);
|
|
7
|
+
// Live per-agent metrics: tokens generated + elapsed. While working, elapsed is derived from
|
|
8
|
+
// startedAt at render time (updates each round tick); once finished, the wall time is frozen.
|
|
9
|
+
function metrics(a) {
|
|
10
|
+
const parts = [];
|
|
11
|
+
if (a.tokens != null && a.tokens > 0)
|
|
12
|
+
parts.push(`${toks(a.tokens)} tok`);
|
|
13
|
+
const ms = a.status === "working"
|
|
14
|
+
? (a.startedAt != null ? Date.now() - a.startedAt : undefined)
|
|
15
|
+
: a.durationMs;
|
|
16
|
+
if (ms != null)
|
|
17
|
+
parts.push(`${(ms / 1000).toFixed(ms < 10000 ? 1 : 0)}s`);
|
|
18
|
+
return parts.join(" · ");
|
|
19
|
+
}
|
|
20
|
+
export function BgPanel({ agents, title = "background" }) {
|
|
21
|
+
if (agents.length === 0)
|
|
22
|
+
return null;
|
|
23
|
+
return (_jsxs(Box, { flexDirection: "column", borderStyle: "round", borderColor: "gray", paddingX: 1, children: [_jsxs(Text, { dimColor: true, children: [title, " (", agents.length, ")"] }), agents.map((a) => (_jsxs(Box, { justifyContent: "space-between", children: [_jsxs(Text, { children: [a.status === "working" ? _jsx(OrbitGlyph, {}) : _jsx(Text, { color: COLOR[a.status], children: GLYPH[a.status] }), " ", a.label, a.round != null ? ` · round ${a.round}` : ""] }), _jsx(Text, { dimColor: true, children: (() => { const m = metrics(a); return m ? `${m} · ${a.status}` : a.status; })() })] }, a.id)))] }));
|
|
24
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
// Sticky multi-line input (SPEC §6). Three behaviors that are easy to get wrong and are
|
|
3
|
+
// explicitly called out in the contract:
|
|
4
|
+
// 1. Bracketed paste: the terminal wraps a paste in \x1b[200~ ... \x1b[201~. We intercept the
|
|
5
|
+
// raw stdin bytes (below Ink's own per-keystroke useInput dispatch) so a paste lands as ONE
|
|
6
|
+
// collapsed "[Pasted #N]" token instead of flooding useInput with one call per character.
|
|
7
|
+
// 2. Non-bracketed paste: on a terminal without bracketed-paste, a multi-line paste arrives as
|
|
8
|
+
// plain bytes, each embedded "\n" indistinguishable from the user pressing Enter. Submitting
|
|
9
|
+
// on the first embedded newline would send a fraction of the paste. Fix: on Enter, peek
|
|
10
|
+
// whether stdin still has bytes queued (readableLength > 0) — if so this newline is mid-paste,
|
|
11
|
+
// insert it instead of submitting; only submit once the stream has actually drained.
|
|
12
|
+
// 3. Interrupt: ESC / Ctrl-C must fire even while `disabled` (mid-turn) — checked before the
|
|
13
|
+
// disabled/queue branch below, never gated behind it.
|
|
14
|
+
import { useEffect, useRef, useState } from "react";
|
|
15
|
+
import { Box, Text, useInput, useStdin } from "ink";
|
|
16
|
+
import { InputHistory } from "./useInputHistory.js";
|
|
17
|
+
const PASTE_START = "\x1b[200~";
|
|
18
|
+
const PASTE_END = "\x1b[201~";
|
|
19
|
+
export function Composer({ onSubmit, onInterrupt, onQueue, disabled, prompt = "› " }) {
|
|
20
|
+
const [value, setValue] = useState("");
|
|
21
|
+
const pasteCountRef = useRef(0);
|
|
22
|
+
const pasteBufRef = useRef(null); // non-null while inside a bracketed paste
|
|
23
|
+
const historyRef = useRef(null);
|
|
24
|
+
if (!historyRef.current)
|
|
25
|
+
historyRef.current = new InputHistory();
|
|
26
|
+
const { stdin, isRawModeSupported } = useStdin();
|
|
27
|
+
useEffect(() => { void historyRef.current.load(); }, []);
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
if (!isRawModeSupported || !stdin)
|
|
30
|
+
return;
|
|
31
|
+
process.stdout.write("\x1b[?2004h"); // enable bracketed paste mode
|
|
32
|
+
const onData = (chunk) => {
|
|
33
|
+
const s = typeof chunk === "string" ? chunk : chunk.toString("utf8");
|
|
34
|
+
if (pasteBufRef.current !== null) {
|
|
35
|
+
const end = s.indexOf(PASTE_END);
|
|
36
|
+
if (end === -1) {
|
|
37
|
+
pasteBufRef.current += s;
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
pasteBufRef.current += s.slice(0, end);
|
|
41
|
+
commitPaste();
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const start = s.indexOf(PASTE_START);
|
|
45
|
+
if (start === -1)
|
|
46
|
+
return;
|
|
47
|
+
const buf = s.slice(start + PASTE_START.length);
|
|
48
|
+
const end = buf.indexOf(PASTE_END);
|
|
49
|
+
pasteBufRef.current = end !== -1 ? buf.slice(0, end) : buf;
|
|
50
|
+
if (end !== -1)
|
|
51
|
+
commitPaste();
|
|
52
|
+
};
|
|
53
|
+
const commitPaste = () => {
|
|
54
|
+
pasteBufRef.current = null;
|
|
55
|
+
pasteCountRef.current += 1;
|
|
56
|
+
setValue((v) => `${v}[Pasted #${pasteCountRef.current}]`);
|
|
57
|
+
};
|
|
58
|
+
stdin.on("data", onData);
|
|
59
|
+
return () => {
|
|
60
|
+
stdin.off("data", onData);
|
|
61
|
+
process.stdout.write("\x1b[?2004l");
|
|
62
|
+
};
|
|
63
|
+
}, [stdin, isRawModeSupported]);
|
|
64
|
+
useInput((ch, key) => {
|
|
65
|
+
if (pasteBufRef.current !== null)
|
|
66
|
+
return; // raw paste bytes are owned by the data handler above
|
|
67
|
+
if ((key.ctrl && ch === "c") || key.escape) {
|
|
68
|
+
onInterrupt();
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
if (key.return) {
|
|
72
|
+
if (key.shift) {
|
|
73
|
+
setValue((v) => `${v}\n`);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
if (stdin && (stdin.readableLength ?? 0) > 0) {
|
|
77
|
+
setValue((v) => `${v}\n`); // more bytes queued — this Enter is mid-paste, not a real submit
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
if (!value.trim())
|
|
81
|
+
return;
|
|
82
|
+
const text = value;
|
|
83
|
+
setValue("");
|
|
84
|
+
historyRef.current.push(text);
|
|
85
|
+
if (disabled && onQueue)
|
|
86
|
+
onQueue(text);
|
|
87
|
+
else
|
|
88
|
+
onSubmit(text);
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
// History recall (shell-style): only on a single-line buffer, so ↑/↓ stay free for navigating
|
|
92
|
+
// a multi-line draft instead of clobbering it. See useInputHistory.ts for the ring/draft model.
|
|
93
|
+
if ((key.upArrow || key.downArrow) && !value.includes("\n")) {
|
|
94
|
+
const recalled = key.upArrow ? historyRef.current.prev(value) : historyRef.current.next();
|
|
95
|
+
if (recalled !== null)
|
|
96
|
+
setValue(recalled);
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
if (key.backspace || key.delete) {
|
|
100
|
+
setValue((v) => {
|
|
101
|
+
const next = v.slice(0, -1);
|
|
102
|
+
if (historyRef.current.recalling)
|
|
103
|
+
historyRef.current.resetToLive(next);
|
|
104
|
+
return next;
|
|
105
|
+
});
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if (ch) {
|
|
109
|
+
setValue((v) => {
|
|
110
|
+
const next = v + ch;
|
|
111
|
+
if (historyRef.current.recalling)
|
|
112
|
+
historyRef.current.resetToLive(next);
|
|
113
|
+
return next;
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
const lines = value.length ? value.split("\n") : [""];
|
|
118
|
+
return (_jsx(Box, { flexDirection: "column", children: lines.map((line, i) => (_jsxs(Text, { children: [i === 0 ? prompt : " ", line, i === lines.length - 1 ? "▌" : ""] }, i))) }));
|
|
119
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Box, Text } from "ink";
|
|
3
|
+
const STAR = "✷"; // ✷ — the AXE signal star (brand glyph, matches ThinkingSpinner)
|
|
4
|
+
function tierLabel(ctx) {
|
|
5
|
+
if (!ctx)
|
|
6
|
+
return "";
|
|
7
|
+
if (ctx >= 1_000_000)
|
|
8
|
+
return "1M";
|
|
9
|
+
if (ctx >= 1000)
|
|
10
|
+
return `${Math.round(ctx / 1000)}K`;
|
|
11
|
+
return String(ctx);
|
|
12
|
+
}
|
|
13
|
+
export function Header({ version, route = "aurora", ctxWindow, user, build }) {
|
|
14
|
+
const cols = process.stdout.columns ?? 80;
|
|
15
|
+
const tier = tierLabel(ctxWindow);
|
|
16
|
+
const model = `${route}${tier ? ` · ${tier}` : ""}`; // aurora · 1M
|
|
17
|
+
const who = user ? `⬤ ${user}` : "guest"; // ⬤ email | guest
|
|
18
|
+
const left = ` ${STAR} OPERATOR`;
|
|
19
|
+
const right = `${model} · v${version}${build ? ` ·${build}` : ""} · ${who} `;
|
|
20
|
+
const gap = Math.max(1, cols - left.length - right.length);
|
|
21
|
+
return (_jsxs(Box, { flexDirection: "column", children: [_jsxs(Box, { children: [_jsx(Text, { color: "magentaBright", bold: true, children: ` ${STAR} ` }), _jsx(Text, { bold: true, color: "whiteBright", children: "OPERATOR" }), _jsx(Text, { children: " ".repeat(gap) }), _jsx(Text, { dimColor: true, children: `${model} · v${version}${build ? ` ·${build}` : ""} · ` }), _jsx(Text, { color: user ? "green" : undefined, dimColor: !user, children: who + " " })] }), _jsx(Text, { dimColor: true, children: "─".repeat(cols) })] }));
|
|
22
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Box, Text } from "ink";
|
|
3
|
+
const STAR = "✷"; // AXE signal star (brand glyph)
|
|
4
|
+
const BRAND_W = 10; // visible width of "✷ OPERATOR"
|
|
5
|
+
export function StatusRule({ route, ctxPct, version, build, metrics, user }) {
|
|
6
|
+
const who = user ? `⬤ ${user} · ` : "";
|
|
7
|
+
const tag = ` ${who}${route} · ${Math.round(ctxPct)}%${metrics ? ` · ${metrics}` : ""} · KODE v${version}${build ? ` ·${build}` : ""} `;
|
|
8
|
+
const cols = process.stdout.columns ?? 80;
|
|
9
|
+
const fill = Math.max(1, cols - BRAND_W - tag.length - 1);
|
|
10
|
+
return (_jsxs(Box, { children: [_jsx(Text, { color: "magentaBright", bold: true, children: STAR }), _jsx(Text, { bold: true, color: "whiteBright", children: " OPERATOR" }), _jsx(Text, { dimColor: true, children: " " + "─".repeat(fill) }), _jsx(Text, { dimColor: true, children: tag + "─" })] }));
|
|
11
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// AXE loading star — the "signal" heartbeat (SPEC §6): sun → collapse to a point → a beat of silence →
|
|
3
|
+
// re-ignite → bright burst, looping. Ported 1:1 from the reference star_signal.py (assets/star_signal.py):
|
|
4
|
+
// same 10-phase FRAMES, same tones, same 110ms tick, same glyph set (all Dingbats/geometric so they
|
|
5
|
+
// render in Menlo without tofu). A rotating amber verb sits beside it unless the engine pins one.
|
|
6
|
+
import { useEffect, useState } from "react";
|
|
7
|
+
import { Text } from "ink";
|
|
8
|
+
const DEFAULT_VERBS = [
|
|
9
|
+
"Thinking", "Reasoning", "Noodling", "Synthesizing", "Percolating", "Untangling", "Weighing",
|
|
10
|
+
];
|
|
11
|
+
// Ink render props per tone — the truecolor equivalents of star_signal.py's ANSI TONES.
|
|
12
|
+
const TONE_STYLE = {
|
|
13
|
+
amber: { color: "#e8a33d" },
|
|
14
|
+
bright: { color: "#ffe2a0", bold: true },
|
|
15
|
+
dim: { color: "#e8a33d", dim: true },
|
|
16
|
+
faint: { dim: true },
|
|
17
|
+
};
|
|
18
|
+
// (tone, glyph, ticks) — ticks is how many beats the frame holds. Sun → point → silence → burst.
|
|
19
|
+
const FRAMES = [
|
|
20
|
+
["amber", "✷", 3],
|
|
21
|
+
["amber", "✦", 1],
|
|
22
|
+
["dim", "∙", 1],
|
|
23
|
+
["faint", "·", 3],
|
|
24
|
+
["dim", "∙", 1],
|
|
25
|
+
["amber", "✦", 1],
|
|
26
|
+
["amber", "✷", 3],
|
|
27
|
+
["amber", "✹", 1],
|
|
28
|
+
["bright", "✺", 1],
|
|
29
|
+
["amber", "✹", 1],
|
|
30
|
+
];
|
|
31
|
+
/** Flatten (tone, glyph, ticks) into one (tone, glyph) per tick — mirrors star_signal.py expand(). */
|
|
32
|
+
export function expandStar(frames = FRAMES) {
|
|
33
|
+
const out = [];
|
|
34
|
+
for (const [tone, glyph, ticks] of frames)
|
|
35
|
+
for (let i = 0; i < ticks; i++)
|
|
36
|
+
out.push([tone, glyph]);
|
|
37
|
+
return out;
|
|
38
|
+
}
|
|
39
|
+
const SEQUENCE = expandStar();
|
|
40
|
+
export function ThinkingSpinner({ active, verb, verbs = DEFAULT_VERBS, verbIntervalMs = 2000, tickMs = 110, }) {
|
|
41
|
+
const [tick, setTick] = useState(0);
|
|
42
|
+
const [verbIdx, setVerbIdx] = useState(0);
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
if (!active)
|
|
45
|
+
return;
|
|
46
|
+
const id = setInterval(() => setTick((t) => (t + 1) % SEQUENCE.length), tickMs);
|
|
47
|
+
return () => clearInterval(id);
|
|
48
|
+
}, [active, tickMs]);
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
if (!active || verb)
|
|
51
|
+
return; // fixed verb supplied — nothing to rotate
|
|
52
|
+
const id = setInterval(() => setVerbIdx((i) => (i + 1) % verbs.length), verbIntervalMs);
|
|
53
|
+
return () => clearInterval(id);
|
|
54
|
+
}, [active, verb, verbs, verbIntervalMs]);
|
|
55
|
+
if (!active)
|
|
56
|
+
return null;
|
|
57
|
+
const [tone, glyph] = SEQUENCE[tick];
|
|
58
|
+
const style = TONE_STYLE[tone];
|
|
59
|
+
const label = verb ?? verbs[verbIdx % verbs.length];
|
|
60
|
+
return (_jsxs(Text, { color: style.color, bold: style.bold, dimColor: style.dim, children: [glyph, " ", label, "\u2026"] }));
|
|
61
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// Per-tool card: select -> run -> done/error, with a live sub-second timer while running
|
|
3
|
+
// (SPEC §3: real timers, never rounded to 0.0s).
|
|
4
|
+
import { useEffect, useState } from "react";
|
|
5
|
+
import { Box, Text } from "ink";
|
|
6
|
+
import { formatDuration } from "./format.js";
|
|
7
|
+
const GLYPH = { selected: "○", running: "◐", done: "✓", error: "✗" };
|
|
8
|
+
const COLOR = { selected: "gray", running: "#e8a33d", done: "green", error: "red" };
|
|
9
|
+
function argsPreview(args) {
|
|
10
|
+
if (!args)
|
|
11
|
+
return "";
|
|
12
|
+
const s = Object.entries(args)
|
|
13
|
+
.map(([k, v]) => `${k}=${JSON.stringify(v)}`)
|
|
14
|
+
.join(", ");
|
|
15
|
+
return s.length > 60 ? `${s.slice(0, 57)}...` : s;
|
|
16
|
+
}
|
|
17
|
+
export function ToolStep({ step }) {
|
|
18
|
+
const [now, setNow] = useState(() => Date.now());
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
if (step.status !== "running" || !step.startedAt)
|
|
21
|
+
return;
|
|
22
|
+
const id = setInterval(() => setNow(Date.now()), 100);
|
|
23
|
+
return () => clearInterval(id);
|
|
24
|
+
}, [step.status, step.startedAt]);
|
|
25
|
+
const elapsed = step.durationMs ??
|
|
26
|
+
(step.status === "running" && step.startedAt
|
|
27
|
+
? now - step.startedAt
|
|
28
|
+
: step.endedAt && step.startedAt
|
|
29
|
+
? step.endedAt - step.startedAt
|
|
30
|
+
: undefined);
|
|
31
|
+
return (_jsxs(Box, { flexDirection: "column", children: [_jsxs(Text, { children: [_jsx(Text, { color: COLOR[step.status], children: GLYPH[step.status] }), " ", step.name, "(", argsPreview(step.args), ")", elapsed != null ? _jsxs(Text, { dimColor: true, children: [" ", formatDuration(elapsed)] }) : null] }), step.summary ? _jsxs(Text, { dimColor: true, children: [" ", step.summary] }) : null] }));
|
|
32
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Box, Static, Text } from "ink";
|
|
3
|
+
import { ToolStep } from "./ToolStep.js";
|
|
4
|
+
function entryKey(entry) {
|
|
5
|
+
return entry.kind === "message" ? entry.message.id : entry.step.id;
|
|
6
|
+
}
|
|
7
|
+
function renderEntry(entry) {
|
|
8
|
+
if (entry.kind === "message") {
|
|
9
|
+
const { message } = entry;
|
|
10
|
+
if (message.role === "user") {
|
|
11
|
+
return _jsxs(Text, { children: ["❯ ", message.content] });
|
|
12
|
+
}
|
|
13
|
+
if (message.role === "system") {
|
|
14
|
+
return _jsx(Text, { dimColor: true, children: message.content }); // slash-command output / status notes
|
|
15
|
+
}
|
|
16
|
+
return (_jsxs(Box, { flexDirection: "column", marginBottom: 1, children: [_jsx(Text, { children: message.content }), message.reasoning ? _jsx(Text, { dimColor: true, children: message.reasoning }) : null] }));
|
|
17
|
+
}
|
|
18
|
+
return _jsx(ToolStep, { step: entry.step });
|
|
19
|
+
}
|
|
20
|
+
export function Transcript({ entries, live }) {
|
|
21
|
+
return (_jsxs(Box, { flexDirection: "column", children: [_jsx(Static, { items: entries, children: (entry) => _jsx(Box, { children: renderEntry(entry) }, entryKey(entry)) }), live ? _jsx(Box, { children: renderEntry(live) }) : null] }));
|
|
22
|
+
}
|
package/dist/ui/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { App } from "./App.js";
|
|
2
|
+
export { Transcript } from "./Transcript.js";
|
|
3
|
+
export { StatusRule } from "./StatusRule.js";
|
|
4
|
+
export { Composer } from "./Composer.js";
|
|
5
|
+
export { ThinkingSpinner } from "./ThinkingSpinner.js";
|
|
6
|
+
export { ToolStep } from "./ToolStep.js";
|
|
7
|
+
export { BgPanel } from "./BgPanel.js";
|
|
8
|
+
export * from "./types.js";
|
|
9
|
+
export { formatDuration } from "./format.js";
|
package/dist/ui/types.js
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// Shell-style input history (↑/↓ recall). Plain class (not a React hook) so the navigation logic
|
|
2
|
+
// is unit-testable without mounting Ink — Composer.tsx wraps it in a useRef.
|
|
3
|
+
//
|
|
4
|
+
// Model: a ring of past submissions plus one "live" draft slot at index `entries.length`. Cursor
|
|
5
|
+
// starts pointing at the live slot. ↑ walks toward index 0 (oldest), ↓ walks back toward the live
|
|
6
|
+
// slot. Typing anything after a recall snaps the cursor back to the live slot and edits it (bash's
|
|
7
|
+
// "any edit forks a fresh draft" behavior) rather than mutating the recalled history entry in place.
|
|
8
|
+
import { appendFile, mkdir, readFile } from "node:fs/promises";
|
|
9
|
+
import { dirname, join } from "node:path";
|
|
10
|
+
import { homedir } from "node:os";
|
|
11
|
+
const DEFAULT_FILE = process.env.KODE_HISTORY_FILE ?? join(homedir(), ".axe", "operator", "history");
|
|
12
|
+
const MAX_ENTRIES = 200;
|
|
13
|
+
export class InputHistory {
|
|
14
|
+
file;
|
|
15
|
+
cap;
|
|
16
|
+
entries = [];
|
|
17
|
+
cursor = 0; // index into entries; entries.length == live draft
|
|
18
|
+
draft = ""; // preserved in-progress text, restored when ↓ returns to the live slot
|
|
19
|
+
lastPersist = Promise.resolve(); // the most recent fire-and-forget write (for flushed())
|
|
20
|
+
constructor(file = DEFAULT_FILE, cap = MAX_ENTRIES) {
|
|
21
|
+
this.file = file;
|
|
22
|
+
this.cap = cap;
|
|
23
|
+
}
|
|
24
|
+
/** Load persisted history (newline-delimited, best-effort — a missing/corrupt file is just empty). */
|
|
25
|
+
async load() {
|
|
26
|
+
try {
|
|
27
|
+
const raw = await readFile(this.file, "utf8");
|
|
28
|
+
this.entries = raw.split("\n").filter((l) => l.length > 0).slice(-this.cap);
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
this.entries = [];
|
|
32
|
+
}
|
|
33
|
+
this.cursor = this.entries.length;
|
|
34
|
+
}
|
|
35
|
+
/** Record a submitted prompt. De-dupes consecutive identical entries; resets recall cursor. */
|
|
36
|
+
push(entry) {
|
|
37
|
+
const text = entry.replace(/\n/g, " ").trim();
|
|
38
|
+
if (!text) {
|
|
39
|
+
this.cursor = this.entries.length;
|
|
40
|
+
this.draft = "";
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (this.entries[this.entries.length - 1] !== text) {
|
|
44
|
+
this.entries.push(text);
|
|
45
|
+
if (this.entries.length > this.cap)
|
|
46
|
+
this.entries.shift();
|
|
47
|
+
// Chain persists so two rapid pushes append in order (concurrent appendFile calls can otherwise
|
|
48
|
+
// land out of order) — and so flushed() awaiting the tail awaits every pending write.
|
|
49
|
+
this.lastPersist = this.lastPersist.then(() => this.persist(text));
|
|
50
|
+
}
|
|
51
|
+
this.cursor = this.entries.length;
|
|
52
|
+
this.draft = "";
|
|
53
|
+
}
|
|
54
|
+
/** Resolves once every pending push's fire-and-forget persist has settled. The UI never awaits this
|
|
55
|
+
* (persistence is best-effort), but it makes persistence deterministically testable without sleeping. */
|
|
56
|
+
flushed() {
|
|
57
|
+
return this.lastPersist;
|
|
58
|
+
}
|
|
59
|
+
/** Best-effort append to the history file; a write failure never surfaces to the caller. */
|
|
60
|
+
async persist(text) {
|
|
61
|
+
try {
|
|
62
|
+
await mkdir(dirname(this.file), { recursive: true });
|
|
63
|
+
await appendFile(this.file, text + "\n", "utf8");
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
/* history persistence is best-effort */
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/** ↑ — recall the previous entry. `current` is the composer's live text, captured as the draft
|
|
70
|
+
* the first time recall moves off it. Returns null at the oldest entry (no-op). */
|
|
71
|
+
prev(current) {
|
|
72
|
+
if (this.cursor === this.entries.length)
|
|
73
|
+
this.draft = current;
|
|
74
|
+
if (this.cursor === 0)
|
|
75
|
+
return null;
|
|
76
|
+
this.cursor -= 1;
|
|
77
|
+
return this.entries[this.cursor] ?? null;
|
|
78
|
+
}
|
|
79
|
+
/** ↓ — walk forward. Returns the draft (and resets to the live slot) once past the newest entry;
|
|
80
|
+
* returns null if already at the live slot (no-op). */
|
|
81
|
+
next() {
|
|
82
|
+
if (this.cursor >= this.entries.length)
|
|
83
|
+
return null;
|
|
84
|
+
this.cursor += 1;
|
|
85
|
+
return this.cursor === this.entries.length ? this.draft : this.entries[this.cursor] ?? null;
|
|
86
|
+
}
|
|
87
|
+
/** True once the cursor has moved off the live slot — Composer uses this to know whether the
|
|
88
|
+
* current text is a recalled entry (so a fresh keystroke should fork a new draft first). */
|
|
89
|
+
get recalling() {
|
|
90
|
+
return this.cursor !== this.entries.length;
|
|
91
|
+
}
|
|
92
|
+
/** Any edit while recalling forks a new draft: caller re-seeds the draft and snaps back to live. */
|
|
93
|
+
resetToLive(current) {
|
|
94
|
+
this.cursor = this.entries.length;
|
|
95
|
+
this.draft = current;
|
|
96
|
+
}
|
|
97
|
+
}
|