@0perator/operator 0.1.38 → 0.1.40
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 +1 -1
- package/dist/cli.js +1 -1
- package/dist/permissions/signature.js +4 -1
- package/dist/tools/computer.js +1 -9
- package/dist/tools/exec.js +14 -0
- package/dist/tools/paths.js +19 -0
- package/dist/tools/registry.js +11 -19
- package/dist/ui/StatusRule.js +59 -14
- package/dist/util/mentions.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
The TypeScript + [Ink](https://github.com/vadimdemedes/ink) port of KODE: an Aurora-backed agentic
|
|
4
4
|
terminal coding agent, built to the frozen `SPEC/` contract shared with the Python core (`kode`/`kode+`).
|
|
5
|
-
Launched as **`operator`** (1M-only) / **`operator+`** (Air⇄1M) —
|
|
5
|
+
Launched as **`operator`** (1M-only) / **`operator+`** (Air⇄1M) — AXE's agentic terminal, built on the Aurora model.
|
|
6
6
|
|
|
7
7
|
The port's reason to exist: a **full-frame React reconciler + Ink `<Static>`** render, which makes the
|
|
8
8
|
scroll / echo / prompt-overwrite bug class of the ANSI-cursor Python REPL *structurally impossible*.
|
package/dist/cli.js
CHANGED
|
@@ -19,7 +19,7 @@ import { expandFileMentions } from "./util/mentions.js";
|
|
|
19
19
|
import { join } from "node:path";
|
|
20
20
|
import { homedir, hostname } from "node:os";
|
|
21
21
|
import { createHash } from "node:crypto";
|
|
22
|
-
const VERSION = "0.1.
|
|
22
|
+
const VERSION = "0.1.40";
|
|
23
23
|
// operator/settings.json (override path via KODE_TSI_SETTINGS), env vars still win — see config/settings.ts.
|
|
24
24
|
const settings = loadSettings();
|
|
25
25
|
// Propagate the resolved sandbox mode to the tool layer (registry reads KODE_SANDBOX at exec time).
|
|
@@ -25,7 +25,10 @@ const PROD_CMD = [
|
|
|
25
25
|
];
|
|
26
26
|
// Command/arg patterns for irreversible destruction (data / disk / filesystem).
|
|
27
27
|
const DESTRUCTIVE_CMD = [
|
|
28
|
-
|
|
28
|
+
// Recursive/forced rm in ANY flag form: -rf, -fr, -r -f, --recursive, --force (split flags used to slip
|
|
29
|
+
// the floor as an ordinary "ask"). A recursive OR forced delete is irreversible enough to need a human.
|
|
30
|
+
/\brm\b[^|;&\n]*\s-{1,2}[a-z]*r/i, // rm … -r / -rf / --recursive
|
|
31
|
+
/\brm\b[^|;&\n]*\s-{1,2}[a-z]*f/i, // rm … -f / --force
|
|
29
32
|
/\b(mkfs|dd)\b/i,
|
|
30
33
|
/\bshutdown\b|\breboot\b/i,
|
|
31
34
|
/:\(\)\s*\{.*\}\s*;/, // fork bomb
|
package/dist/tools/computer.js
CHANGED
|
@@ -1,18 +1,10 @@
|
|
|
1
|
+
import { pexecFile } from "./exec.js";
|
|
1
2
|
const nodeImport = (m) => import(m);
|
|
2
3
|
// Module-level enable flag: flipped once at startup from settings/env. Tools read it on every call so a
|
|
3
4
|
// registry entry that somehow outlives a disable can never act.
|
|
4
5
|
let ENABLED = false;
|
|
5
6
|
export function setComputerEnabled(on) { ENABLED = on; }
|
|
6
7
|
export function computerEnabled() { return ENABLED; }
|
|
7
|
-
let _pexec = null;
|
|
8
|
-
async function pexecFile(file, args, opts) {
|
|
9
|
-
if (!_pexec) {
|
|
10
|
-
const { execFile } = await nodeImport("node:child_process");
|
|
11
|
-
const { promisify } = await nodeImport("node:util");
|
|
12
|
-
_pexec = promisify(execFile);
|
|
13
|
-
}
|
|
14
|
-
return _pexec(file, args, opts);
|
|
15
|
-
}
|
|
16
8
|
function str(v, fallback = "") {
|
|
17
9
|
return v === undefined || v === null ? fallback : String(v);
|
|
18
10
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// Shared lazy execFile helper (node-only). Same contract as promisify(execFile): resolves
|
|
2
|
+
// {stdout,stderr}, rejects with the error object (stdout/stderr attached) on non-zero exit. Imports are
|
|
3
|
+
// LAZY via an opaque specifier so this stays node-free at module load — safe to import from any bundle;
|
|
4
|
+
// the CLI tools (registry.ts, computer.ts) share this one copy instead of each carrying its own.
|
|
5
|
+
const nodeImport = (m) => import(/* @vite-ignore */ m);
|
|
6
|
+
let _pexec = null;
|
|
7
|
+
export async function pexecFile(file, args, opts) {
|
|
8
|
+
if (!_pexec) {
|
|
9
|
+
const { execFile } = await nodeImport("node:child_process");
|
|
10
|
+
const { promisify } = await nodeImport("node:util");
|
|
11
|
+
_pexec = promisify(execFile);
|
|
12
|
+
}
|
|
13
|
+
return _pexec(file, args, opts);
|
|
14
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Home-relative path expansion for the file tools. `shell_exec` runs through a shell, which expands a
|
|
2
|
+
// leading `~` itself; the file tools (file_read/file_write/file_edit/grep_search) call fs directly, so
|
|
3
|
+
// without this a path like "~/Downloads/x.md" is treated as RELATIVE to cwd — it lands in a literal
|
|
4
|
+
// folder named "~" under the working directory, the tool reports success, and the user never sees the
|
|
5
|
+
// file where they asked for it. Expanding here makes the file tools agree with the shell.
|
|
6
|
+
//
|
|
7
|
+
// Node-free by construction (reads process.env only, no imports) so the tools module still loads in the
|
|
8
|
+
// headless conformance runner. Only a LEADING ~ is a home reference: bare "~" and "~/rest"; "~user" (a
|
|
9
|
+
// different account's home) and a ~ anywhere but the first character are left untouched, matching the shell.
|
|
10
|
+
export function expandPath(p) {
|
|
11
|
+
const home = process.env.HOME ?? process.env.USERPROFILE ?? "";
|
|
12
|
+
if (!home)
|
|
13
|
+
return p;
|
|
14
|
+
if (p === "~")
|
|
15
|
+
return home;
|
|
16
|
+
if (p.startsWith("~/"))
|
|
17
|
+
return home + p.slice(1);
|
|
18
|
+
return p;
|
|
19
|
+
}
|
package/dist/tools/registry.js
CHANGED
|
@@ -6,19 +6,11 @@
|
|
|
6
6
|
// mobile app runs tools natively in Swift. nodeImport() keeps esbuild from statically resolving them.
|
|
7
7
|
const nodeImport = (m) => import(m);
|
|
8
8
|
import { MemoryStore } from "../memory/index.js";
|
|
9
|
+
import { pexecFile } from "./exec.js";
|
|
10
|
+
import { expandPath } from "./paths.js";
|
|
9
11
|
import { deniedWriteAsync, deniedReadAsync, wrapShell } from "./sandbox.js";
|
|
10
12
|
import { ensureSearxng, noteSearxngUsed } from "./searxng.js";
|
|
11
|
-
//
|
|
12
|
-
// {stdout,stderr}, rejects with the error object (stdout/stderr attached) on non-zero exit.
|
|
13
|
-
let _pexec = null;
|
|
14
|
-
async function pexecFile(file, args, opts) {
|
|
15
|
-
if (!_pexec) {
|
|
16
|
-
const { execFile } = await nodeImport("node:child_process");
|
|
17
|
-
const { promisify } = await nodeImport("node:util");
|
|
18
|
-
_pexec = promisify(execFile);
|
|
19
|
-
}
|
|
20
|
-
return _pexec(file, args, opts);
|
|
21
|
-
}
|
|
13
|
+
// execFile helper lives in ./exec (shared with computer.ts — one copy, not two).
|
|
22
14
|
function str(v, fallback = "") {
|
|
23
15
|
return v === undefined || v === null ? fallback : String(v);
|
|
24
16
|
}
|
|
@@ -26,7 +18,7 @@ async function shellExec(args) {
|
|
|
26
18
|
const command = str(args.command);
|
|
27
19
|
if (!command)
|
|
28
20
|
return "error: no command given";
|
|
29
|
-
const cwd = args.cwd ? str(args.cwd) : undefined;
|
|
21
|
+
const cwd = args.cwd ? expandPath(str(args.cwd)) : undefined;
|
|
30
22
|
const timeout = Number(args.timeout_ms ?? 120_000);
|
|
31
23
|
const MAXBUF = 64 * 1024 * 1024; // 64MB — big greps/finds no longer hard-fail on a 10MB cap
|
|
32
24
|
// Run under the OS sandbox when KODE_SANDBOX is on (macOS sandbox-exec); otherwise plain bash. The
|
|
@@ -61,7 +53,7 @@ async function shellExec(args) {
|
|
|
61
53
|
const FILE_READ_DEFAULT_LIMIT_LINES = 2000;
|
|
62
54
|
const FILE_READ_MAX_CHARS = 40_000;
|
|
63
55
|
async function fileRead(args) {
|
|
64
|
-
const path = str(args.path);
|
|
56
|
+
const path = expandPath(str(args.path));
|
|
65
57
|
if (!path)
|
|
66
58
|
return "error: no path given";
|
|
67
59
|
const blocked = await deniedReadAsync(path); // sandbox on: refuse reads of credential paths (exfil guard)
|
|
@@ -88,7 +80,7 @@ async function fileRead(args) {
|
|
|
88
80
|
}
|
|
89
81
|
}
|
|
90
82
|
async function fileWrite(args) {
|
|
91
|
-
const path = str(args.path);
|
|
83
|
+
const path = expandPath(str(args.path));
|
|
92
84
|
if (!path)
|
|
93
85
|
return "error: no path given";
|
|
94
86
|
const blocked = await deniedWriteAsync(path); // async: realpath closes the symlink-laundering gap
|
|
@@ -106,7 +98,7 @@ async function fileWrite(args) {
|
|
|
106
98
|
}
|
|
107
99
|
}
|
|
108
100
|
async function fileEdit(args) {
|
|
109
|
-
const path = str(args.path);
|
|
101
|
+
const path = expandPath(str(args.path));
|
|
110
102
|
const oldStr = str(args.old_string);
|
|
111
103
|
const newStr = str(args.new_string);
|
|
112
104
|
const replaceAll = Boolean(args.replace_all);
|
|
@@ -134,7 +126,7 @@ async function fileEdit(args) {
|
|
|
134
126
|
}
|
|
135
127
|
async function grepSearch(args) {
|
|
136
128
|
const pattern = str(args.pattern);
|
|
137
|
-
const path = str(args.path, ".");
|
|
129
|
+
const path = expandPath(str(args.path, "."));
|
|
138
130
|
if (!pattern)
|
|
139
131
|
return "error: no pattern given";
|
|
140
132
|
// -s suppresses errors for unreadable/special files (sockets, FIFOs, permission-denied) that a
|
|
@@ -200,7 +192,7 @@ async function listDirectory(args) {
|
|
|
200
192
|
}
|
|
201
193
|
async function gitCommand(args) {
|
|
202
194
|
const gitArgs = Array.isArray(args.args) ? args.args.map(String) : [];
|
|
203
|
-
const cwd = args.cwd ? str(args.cwd) : undefined;
|
|
195
|
+
const cwd = args.cwd ? expandPath(str(args.cwd)) : undefined;
|
|
204
196
|
if (!gitArgs.length)
|
|
205
197
|
return "error: no args given";
|
|
206
198
|
try {
|
|
@@ -237,7 +229,7 @@ async function checkpoint(args) {
|
|
|
237
229
|
const summary = str(args.summary);
|
|
238
230
|
if (!summary)
|
|
239
231
|
return "error: no summary given";
|
|
240
|
-
const workspace = args.workspace ? str(args.workspace) : process.cwd();
|
|
232
|
+
const workspace = args.workspace ? expandPath(str(args.workspace)) : process.cwd();
|
|
241
233
|
const push = Boolean(args.push);
|
|
242
234
|
try {
|
|
243
235
|
await pexecFile("git", ["add", "-A"], { cwd: workspace });
|
|
@@ -372,7 +364,7 @@ async function shellBackground(args) {
|
|
|
372
364
|
const running = [...bgJobs.values()].filter((j) => !j.done).length;
|
|
373
365
|
if (running >= BG_MAX_RUNNING)
|
|
374
366
|
return `error: ${BG_MAX_RUNNING} background jobs already running — bash_kill one before starting another`;
|
|
375
|
-
const cwd = args.cwd ? str(args.cwd) : undefined;
|
|
367
|
+
const cwd = args.cwd ? expandPath(str(args.cwd)) : undefined;
|
|
376
368
|
const { spawn } = await nodeImport("node:child_process");
|
|
377
369
|
const { file, args: argv } = await wrapShell(command); // same OS sandbox wrap as shell_exec
|
|
378
370
|
const id = `sh${++bgSeq}`;
|
package/dist/ui/StatusRule.js
CHANGED
|
@@ -1,20 +1,65 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Box, Text } from "ink";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
3
|
+
// Conservative terminal cell width: ASCII, Latin punctuation (·), and the box-drawing block (─, ≤ U+257F)
|
|
4
|
+
// are one cell; anything above the box-drawing block is a symbol/dingbat/geometric glyph the terminal
|
|
5
|
+
// font is free to render two cells wide, so we count it as 2. Over-estimating is safe (a shorter rule);
|
|
6
|
+
// under-estimating wraps the line and creeps the frame. See ruleFill for why this must not lie.
|
|
7
|
+
export function cellWidth(s) {
|
|
8
|
+
let w = 0;
|
|
9
|
+
for (const ch of s)
|
|
10
|
+
w += (ch.codePointAt(0) ?? 0) >= 0x2580 ? 2 : 1;
|
|
11
|
+
return w;
|
|
12
|
+
}
|
|
13
|
+
// Truncate `s` to at most `max` terminal cells, measured with cellWidth (so a double-width glyph counts
|
|
14
|
+
// for two), appending a single-cell ellipsis when anything was cut. Whole code points only — never split
|
|
15
|
+
// one, which would leave a stray surrogate and a torn glyph.
|
|
16
|
+
export function truncateToWidth(s, max) {
|
|
17
|
+
if (max <= 0)
|
|
18
|
+
return "";
|
|
19
|
+
if (cellWidth(s) <= max)
|
|
20
|
+
return s;
|
|
21
|
+
let w = 0, out = "";
|
|
22
|
+
for (const ch of s) {
|
|
23
|
+
const cw = cellWidth(ch);
|
|
24
|
+
if (w + cw > max - 1)
|
|
25
|
+
break; // reserve one cell for the ellipsis
|
|
26
|
+
out += ch;
|
|
27
|
+
w += cw;
|
|
28
|
+
}
|
|
29
|
+
return out + "…";
|
|
30
|
+
}
|
|
31
|
+
// The dim `info` string (right of the wordmark) and the full measured `right` line, kept as one pure
|
|
32
|
+
// function so the width math is testable without a render. `info` = think · plan · seat · identity ·
|
|
33
|
+
// route · ctx% · version; `right` prefixes the ✷ OPERATOR wordmark and suffixes the trailing " ─". When
|
|
34
|
+
// the terminal is too narrow to hold every badge, `info` is truncated so cellWidth(right) ≤ cols-3 —
|
|
35
|
+
// which keeps the leading fill ≥ 1 and the whole line at cols-1, so the rule never becomes the line that
|
|
36
|
+
// wraps (the creep bug) no matter how many badges are lit or how narrow the window.
|
|
37
|
+
export function statusRight(p, cols) {
|
|
38
|
+
const who = p.user ? `⬤ ${p.user} · ` : "";
|
|
39
|
+
const seat = p.tier && p.tier !== "admin" ? `⛨ ${p.tier} · ` : ""; // a narrowed seat shows; owner's admin doesn't
|
|
40
|
+
const plan = p.planMode ? `◔ plan · ` : ""; // read-only research mode is visible while active
|
|
41
|
+
const think = p.thinkMode === "ultrathink" ? `✲✲ ultrathink · ` : p.thinkMode === "think" ? `✲ think · ` : "";
|
|
42
|
+
let info = `${think}${plan}${seat}${who}${p.route} · ${Math.round(p.ctxPct)}% · v${p.version}${p.build ? ` ·${p.build}` : ""}`;
|
|
43
|
+
let right = `✷ OPERATOR · ${info} ─`;
|
|
44
|
+
const maxRight = cols - 3; // leaves fill ≥ 1 and total = cols-1
|
|
45
|
+
if (cellWidth(right) > maxRight) {
|
|
46
|
+
const framing = cellWidth(right) - cellWidth(info); // the wordmark + separators + trailing " ─"
|
|
47
|
+
info = truncateToWidth(info, maxRight - framing);
|
|
48
|
+
right = `✷ OPERATOR · ${info} ─`;
|
|
49
|
+
}
|
|
50
|
+
return { info, right };
|
|
51
|
+
}
|
|
52
|
+
// Leading-dash count so the whole line renders at cols-1, NEVER cols. A line exactly the terminal width
|
|
53
|
+
// auto-wraps to a 2nd physical row Ink's height accounting misses, so its per-render erase is off by one
|
|
54
|
+
// and the whole dynamic frame (incl. the input) creeps UP the screen on each keystroke. Total rendered =
|
|
55
|
+
// fill + 1 (space) + cellWidth(right); solving fill so that equals cols-1 gives cols - cellWidth(right) - 2.
|
|
56
|
+
export function ruleFill(right, cols) {
|
|
57
|
+
return Math.max(1, cols - cellWidth(right) - 2);
|
|
58
|
+
}
|
|
59
|
+
export function StatusRule(props) {
|
|
13
60
|
const cols = process.stdout.columns ?? 80;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
// one and the whole dynamic frame (incl. the input) creeps UP the screen on each keystroke.
|
|
17
|
-
const fill = Math.max(1, cols - right.length - 2);
|
|
61
|
+
const { info, right } = statusRight(props, cols);
|
|
62
|
+
const fill = ruleFill(right, cols);
|
|
18
63
|
// Enterprise header: a dim rule sweeping to a magenta ✷ mark + bright OPERATOR wordmark + dim info,
|
|
19
64
|
// sitting just above the composer (the input is bounded between this and the InputRule below).
|
|
20
65
|
return (_jsxs(Box, { children: [_jsx(Text, { dimColor: true, children: "─".repeat(fill) + " " }), _jsx(Text, { color: "magenta", children: "\u2737 " }), _jsx(Text, { bold: true, children: "OPERATOR" }), _jsx(Text, { dimColor: true, children: ` · ${info} ─` })] }));
|
package/dist/util/mentions.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// @file mentions (
|
|
1
|
+
// @file mentions (parity with modern coding agents): when the owner types `@path`, inline that file's content into the
|
|
2
2
|
// SENT prompt (the visible message keeps the @path as typed). Only tokens that resolve to a real file are
|
|
3
3
|
// expanded — `@someone` that isn't a path is left untouched — and each file is bounded + oversized/dir
|
|
4
4
|
// paths are skipped, so a stray `@node_modules/...` can't blow the context. Matched at a word boundary so
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@0perator/operator",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.40",
|
|
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": {
|