@0perator/operator 0.0.6 → 0.0.7
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/dist/cli.js +16 -4
- package/dist/mcp/index.js +5 -1
- package/dist/tools/executor.js +0 -0
- package/dist/tools/registry.js +44 -6
- package/dist/ui/App.js +5 -4
- package/dist/ui/InputRule.js +6 -0
- package/dist/ui/StatusRule.js +4 -6
- package/dist/ui/ThinkingSpinner.js +6 -5
- package/dist/ui/index.js +1 -0
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -11,15 +11,27 @@ import { Session } from "./session.js";
|
|
|
11
11
|
import { AuroraRouter } from "./router/router.js";
|
|
12
12
|
import { BackgroundAgents } from "./background/index.js";
|
|
13
13
|
import { loadSettings } from "./config/settings.js";
|
|
14
|
-
import { readFileSync, writeFileSync } from "node:fs";
|
|
14
|
+
import { readFileSync, writeFileSync, mkdirSync } from "node:fs";
|
|
15
15
|
import { join } from "node:path";
|
|
16
|
-
|
|
16
|
+
import { homedir } from "node:os";
|
|
17
|
+
import { createHash } from "node:crypto";
|
|
18
|
+
const VERSION = "0.0.7";
|
|
17
19
|
// operator/settings.json (override path via KODE_TSI_SETTINGS), env vars still win — see config/settings.ts.
|
|
18
20
|
const settings = loadSettings();
|
|
19
21
|
// Propagate the resolved sandbox mode to the tool layer (registry reads KODE_SANDBOX at exec time).
|
|
20
22
|
process.env.KODE_SANDBOX = settings.sandbox.mode;
|
|
21
|
-
// Session persistence: the conversation is auto-saved
|
|
22
|
-
|
|
23
|
+
// Session persistence: the conversation is auto-saved every turn and reloaded by `operator --resume`.
|
|
24
|
+
// It lives in a central per-workspace state dir — NEVER in the working directory, where it would be
|
|
25
|
+
// grepped back into the model's own context (self-poisoning → runaway ctx growth), committed by
|
|
26
|
+
// accident, or listed as project litter. One file per cwd (keyed by a short hash) so --resume stays
|
|
27
|
+
// scoped to the directory you launched in.
|
|
28
|
+
const SESSION_DIR = join(homedir(), ".axe", "operator", "sessions");
|
|
29
|
+
const SESSION_FILE = process.env.KODE_SESSION_FILE ??
|
|
30
|
+
join(SESSION_DIR, `${createHash("sha1").update(process.cwd()).digest("hex").slice(0, 16)}.json`);
|
|
31
|
+
try {
|
|
32
|
+
mkdirSync(SESSION_DIR, { recursive: true });
|
|
33
|
+
}
|
|
34
|
+
catch { /* best-effort; the write is guarded too */ }
|
|
23
35
|
const RESUME = process.argv.includes("--resume") || process.argv.includes("-r") || process.env.KODE_RESUME === "1";
|
|
24
36
|
// Build the endpoint router. ONE model now: Aurora at its native 1M context on :8097 — both `operator`
|
|
25
37
|
// and `operator+` serve the same single tier (the air/1m/saddle roster collapsed once Aurora ran true
|
package/dist/mcp/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { loadMcpConfig } from "./config.js";
|
|
2
2
|
import { McpHttpClient } from "./client.js";
|
|
3
3
|
import { McpStdioClient } from "./stdio.js";
|
|
4
|
+
import { capToolResult } from "../tools/executor.js";
|
|
4
5
|
const SEP = ":"; // namespace separator: "compose:compose_list"
|
|
5
6
|
/** Manages the fleet's MCP servers: lazy tool discovery, namespaced dispatch, health-gated. */
|
|
6
7
|
export class McpHub {
|
|
@@ -65,12 +66,15 @@ export class McpHub {
|
|
|
65
66
|
}));
|
|
66
67
|
}
|
|
67
68
|
/** Dispatch a namespaced remote call. Resolves to a string even on error (never rejects). */
|
|
69
|
+
// capToolResult here mirrors the local Executor's own cap (src/tools/executor.ts): the local
|
|
70
|
+
// registry always runs its results through Executor.execute, but a remote MCP tool answers here,
|
|
71
|
+
// bypassing that class entirely — so a huge remote result needs the exact same guard applied here.
|
|
68
72
|
async call(name, args) {
|
|
69
73
|
const t = this.tools.get(name);
|
|
70
74
|
if (!t)
|
|
71
75
|
return `error: unknown MCP tool ${name}`;
|
|
72
76
|
try {
|
|
73
|
-
return await t.client.callTool(t.def.name, args);
|
|
77
|
+
return capToolResult(await t.client.callTool(t.def.name, args));
|
|
74
78
|
}
|
|
75
79
|
catch (e) {
|
|
76
80
|
return `error calling ${name}: ${e instanceof Error ? e.message : String(e)}`;
|
package/dist/tools/executor.js
CHANGED
|
Binary file
|
package/dist/tools/registry.js
CHANGED
|
@@ -41,6 +41,13 @@ async function shellExec(args) {
|
|
|
41
41
|
return `(no output; exit ${e.code ?? "?"})`; // grep no-match etc. — honest, not alarming
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
|
+
// Un-ranged reads default to a bounded window (like the host Read tool) instead of dumping an entire
|
|
45
|
+
// file — a multi-MB log or generated file would otherwise blow up context in one call. FILE_READ_MAX_CHARS
|
|
46
|
+
// is a second, hard backstop for when even the (possibly explicit) line range is enormous (e.g. a few
|
|
47
|
+
// giant minified lines): the central executor cap (src/tools/executor.ts) also applies after this, but
|
|
48
|
+
// capping here first lets us tell the model specifically to use offset/limit rather than "narrow your query".
|
|
49
|
+
const FILE_READ_DEFAULT_LIMIT_LINES = 2000;
|
|
50
|
+
const FILE_READ_MAX_CHARS = 40_000;
|
|
44
51
|
async function fileRead(args) {
|
|
45
52
|
const path = str(args.path);
|
|
46
53
|
if (!path)
|
|
@@ -49,8 +56,16 @@ async function fileRead(args) {
|
|
|
49
56
|
const src = await readFile(path, "utf8");
|
|
50
57
|
const lines = src.split("\n");
|
|
51
58
|
const offset = Number(args.offset ?? 0);
|
|
52
|
-
const
|
|
53
|
-
|
|
59
|
+
const explicitLimit = args.limit !== undefined;
|
|
60
|
+
const limit = Number(args.limit ?? Math.min(lines.length, FILE_READ_DEFAULT_LIMIT_LINES));
|
|
61
|
+
let out = lines.slice(offset, offset + limit).map((l, i) => `${offset + i + 1}\t${l}`).join("\n");
|
|
62
|
+
if (out.length > FILE_READ_MAX_CHARS) {
|
|
63
|
+
out = `${out.slice(0, FILE_READ_MAX_CHARS)}\n…[result truncated: ${FILE_READ_MAX_CHARS} of ${out.length} chars — pass a smaller offset/limit]`;
|
|
64
|
+
}
|
|
65
|
+
else if (!explicitLimit && offset + limit < lines.length) {
|
|
66
|
+
out += `\n…[showing lines ${offset + 1}-${offset + limit} of ${lines.length} — pass offset/limit to see the rest]`;
|
|
67
|
+
}
|
|
68
|
+
return out;
|
|
54
69
|
}
|
|
55
70
|
catch (e) {
|
|
56
71
|
return `error: ${e.message}`;
|
|
@@ -103,12 +118,12 @@ async function grepSearch(args) {
|
|
|
103
118
|
const path = str(args.path, ".");
|
|
104
119
|
if (!pattern)
|
|
105
120
|
return "error: no pattern given";
|
|
106
|
-
const flags = ["-rn", "-I", "--exclude-dir=.git", "--exclude-dir=node_modules"];
|
|
121
|
+
const flags = ["-rn", "-I", "--exclude-dir=.git", "--exclude-dir=node_modules", "--exclude=.operator-session.json"];
|
|
107
122
|
if (args.glob)
|
|
108
123
|
flags.push(`--include=${str(args.glob)}`);
|
|
109
124
|
try {
|
|
110
125
|
const { stdout } = await pexecFile("grep", [...flags, "-E", pattern, path], { maxBuffer: 10 * 1024 * 1024 });
|
|
111
|
-
return stdout
|
|
126
|
+
return capMatches(stdout);
|
|
112
127
|
}
|
|
113
128
|
catch (e) {
|
|
114
129
|
if (e.code === 1)
|
|
@@ -116,11 +131,34 @@ async function grepSearch(args) {
|
|
|
116
131
|
return `error: ${e.stderr || e.message}`;
|
|
117
132
|
}
|
|
118
133
|
}
|
|
134
|
+
// Cap grep output so a single pathological line (minified JS, one-line JSON, a persisted session file)
|
|
135
|
+
// can never balloon the model's context. Per-line truncation is the load-bearing guard: a 300KB
|
|
136
|
+
// single-line match becomes ~500 chars, not 75K tokens. Total-line cap keeps broad matches sane too.
|
|
137
|
+
const GREP_MAXLINE = 500;
|
|
138
|
+
const GREP_MAXLINES = 200;
|
|
139
|
+
function capMatches(stdout) {
|
|
140
|
+
const lines = stdout.split("\n");
|
|
141
|
+
const shown = lines.slice(0, GREP_MAXLINES).map((l) => l.length > GREP_MAXLINE ? `${l.slice(0, GREP_MAXLINE)} …[line truncated, ${l.length - GREP_MAXLINE} more chars]` : l);
|
|
142
|
+
let out = shown.join("\n").trim();
|
|
143
|
+
if (!out)
|
|
144
|
+
return "(no matches)";
|
|
145
|
+
if (lines.length > GREP_MAXLINES)
|
|
146
|
+
out += `\n…[${lines.length - GREP_MAXLINES} more matching lines — narrow the pattern or pass a path/glob]`;
|
|
147
|
+
return out;
|
|
148
|
+
}
|
|
149
|
+
const LIST_DIR_MAX_ENTRIES = 1000; // a directory with 100k entries (node_modules, a data dump) should
|
|
150
|
+
// not dump one line each into context — this is a fan-out cap, independent of the executor's byte cap.
|
|
119
151
|
async function listDirectory(args) {
|
|
120
152
|
const path = str(args.path, ".");
|
|
121
153
|
try {
|
|
122
154
|
const entries = await readdir(path, { withFileTypes: true });
|
|
123
|
-
|
|
155
|
+
if (!entries.length)
|
|
156
|
+
return "(empty)";
|
|
157
|
+
const lines = entries.map(e => `${e.isDirectory() ? "d" : "f"} ${e.name}`);
|
|
158
|
+
if (lines.length > LIST_DIR_MAX_ENTRIES) {
|
|
159
|
+
return `${lines.slice(0, LIST_DIR_MAX_ENTRIES).join("\n")}\n…[${lines.length - LIST_DIR_MAX_ENTRIES} more entries not shown — narrow the path]`;
|
|
160
|
+
}
|
|
161
|
+
return lines.join("\n");
|
|
124
162
|
}
|
|
125
163
|
catch (e) {
|
|
126
164
|
return `error: ${e.message}`;
|
|
@@ -224,7 +262,7 @@ const TOOLS = [
|
|
|
224
262
|
},
|
|
225
263
|
{
|
|
226
264
|
name: "file_read", safe: true,
|
|
227
|
-
description: "Read a file, optionally a line range, with line numbers.",
|
|
265
|
+
description: "Read a file, optionally a line range, with line numbers. Without offset/limit, only the first 2000 lines are returned — pass offset/limit to page through a larger file.",
|
|
228
266
|
parameters: { type: "object", properties: {
|
|
229
267
|
path: { type: "string" }, offset: { type: "number" }, limit: { type: "number" },
|
|
230
268
|
}, required: ["path"] },
|
package/dist/ui/App.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Box } from "ink";
|
|
3
3
|
import { StatusRule } from "./StatusRule.js";
|
|
4
|
+
import { InputRule } from "./InputRule.js";
|
|
4
5
|
import { Transcript } from "./Transcript.js";
|
|
5
6
|
import { Composer } from "./Composer.js";
|
|
6
7
|
import { ThinkingSpinner } from "./ThinkingSpinner.js";
|
|
@@ -9,8 +10,8 @@ import { BgPanel } from "./BgPanel.js";
|
|
|
9
10
|
export function App(props) {
|
|
10
11
|
const { messages, live = null, status, thinkingVerb, verbs, stepLabel, route, ctxPct, version, build, metrics, authUser, bgAgents, onSubmit, onQueue, onInterrupt } = props;
|
|
11
12
|
const thinking = status === "thinking" || status === "streaming";
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
:
|
|
15
|
-
:
|
|
13
|
+
const showSpinner = status === "recovering" || status === "executing" || thinking;
|
|
14
|
+
return (_jsxs(Box, { flexDirection: "column", children: [_jsx(Transcript, { entries: messages, live: live }), showSpinner && (_jsx(Box, { marginTop: 1, marginBottom: 1, children: status === "recovering" ? _jsx(RecoverSpinner, { active: true, label: stepLabel })
|
|
15
|
+
: status === "executing" ? _jsx(StepSpinner, { active: true, label: stepLabel })
|
|
16
|
+
: _jsx(ThinkingSpinner, { active: true, verb: thinkingVerb, verbs: verbs, metrics: metrics }) })), _jsx(BgPanel, { agents: bgAgents }), _jsx(StatusRule, { route: route, ctxPct: ctxPct, version: version, build: build, user: authUser }), _jsx(InputRule, {}), _jsx(Composer, { onSubmit: onSubmit, onQueue: onQueue, onInterrupt: onInterrupt, disabled: status !== "idle" })] }));
|
|
16
17
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Box, Text } from "ink";
|
|
3
|
+
export function InputRule() {
|
|
4
|
+
const cols = process.stdout.columns ?? 80;
|
|
5
|
+
return (_jsx(Box, { children: _jsx(Text, { dimColor: true, children: "─".repeat(Math.max(1, cols - 1)) }) }));
|
|
6
|
+
}
|
package/dist/ui/StatusRule.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Box, Text } from "ink";
|
|
3
|
-
|
|
4
|
-
const BRAND_W = 10; // visible width of "✷ OPERATOR"
|
|
5
|
-
export function StatusRule({ route, ctxPct, version, build, metrics, user }) {
|
|
3
|
+
export function StatusRule({ route, ctxPct, version, build, user }) {
|
|
6
4
|
const who = user ? `⬤ ${user} · ` : "";
|
|
7
|
-
const tag = ` ${who}${route} · ${Math.round(ctxPct)}
|
|
5
|
+
const tag = ` ${who}${route} · ${Math.round(ctxPct)}% · Operator v${version}${build ? ` ·${build}` : ""} `;
|
|
8
6
|
const cols = process.stdout.columns ?? 80;
|
|
9
|
-
const fill = Math.max(1, cols -
|
|
10
|
-
return (_jsxs(Box, { children: [_jsx(Text, {
|
|
7
|
+
const fill = Math.max(1, cols - tag.length - 1);
|
|
8
|
+
return (_jsxs(Box, { children: [_jsx(Text, { dimColor: true, children: "─".repeat(fill) }), _jsx(Text, { dimColor: true, children: tag + "─" })] }));
|
|
11
9
|
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
1
|
+
import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
// AXE loading star — the "signal" heartbeat (SPEC §6): sun → collapse to a point → a beat of silence →
|
|
3
3
|
// re-ignite → bright burst, looping. Ported 1:1 from the reference star_signal.py (assets/star_signal.py):
|
|
4
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
|
|
5
|
+
// render in Menlo without tofu). A rotating amber verb sits beside it unless the engine pins one, and
|
|
6
|
+
// the live token/time metrics (formerly on StatusRule) ride beside that.
|
|
6
7
|
import { useEffect, useState } from "react";
|
|
7
|
-
import { Text } from "ink";
|
|
8
|
+
import { Box, Text } from "ink";
|
|
8
9
|
const DEFAULT_VERBS = [
|
|
9
10
|
"Thinking", "Reasoning", "Noodling", "Synthesizing", "Percolating", "Untangling", "Weighing",
|
|
10
11
|
];
|
|
@@ -37,7 +38,7 @@ export function expandStar(frames = FRAMES) {
|
|
|
37
38
|
return out;
|
|
38
39
|
}
|
|
39
40
|
const SEQUENCE = expandStar();
|
|
40
|
-
export function ThinkingSpinner({ active, verb, verbs = DEFAULT_VERBS, verbIntervalMs = 2000, tickMs = 110, }) {
|
|
41
|
+
export function ThinkingSpinner({ active, verb, verbs = DEFAULT_VERBS, verbIntervalMs = 2000, tickMs = 110, metrics, }) {
|
|
41
42
|
const [tick, setTick] = useState(0);
|
|
42
43
|
const [verbIdx, setVerbIdx] = useState(0);
|
|
43
44
|
useEffect(() => {
|
|
@@ -57,5 +58,5 @@ export function ThinkingSpinner({ active, verb, verbs = DEFAULT_VERBS, verbInter
|
|
|
57
58
|
const [tone, glyph] = SEQUENCE[tick];
|
|
58
59
|
const style = TONE_STYLE[tone];
|
|
59
60
|
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
|
+
return (_jsxs(Box, { children: [_jsxs(Text, { color: style.color, bold: style.bold, dimColor: style.dim, children: [glyph, " ", label, "\u2026"] }), metrics ? _jsx(Text, { dimColor: true, children: " " + metrics }) : null] }));
|
|
61
62
|
}
|
package/dist/ui/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { App } from "./App.js";
|
|
2
2
|
export { Transcript } from "./Transcript.js";
|
|
3
3
|
export { StatusRule } from "./StatusRule.js";
|
|
4
|
+
export { InputRule } from "./InputRule.js";
|
|
4
5
|
export { Composer } from "./Composer.js";
|
|
5
6
|
export { ThinkingSpinner } from "./ThinkingSpinner.js";
|
|
6
7
|
export { ToolStep } from "./ToolStep.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@0perator/operator",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"description": "Operator (KODE) — TypeScript + Ink terminal coding agent. Full-frame render, single-engine core shared across CLI/web/mobile; runs against a local Aurora model.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|