@0perator/operator 0.1.39 → 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/dist/cli.js +1 -1
- package/dist/tools/paths.js +19 -0
- package/dist/tools/registry.js +9 -8
- package/dist/ui/StatusRule.js +59 -14
- package/package.json +1 -1
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).
|
|
@@ -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
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
const nodeImport = (m) => import(m);
|
|
8
8
|
import { MemoryStore } from "../memory/index.js";
|
|
9
9
|
import { pexecFile } from "./exec.js";
|
|
10
|
+
import { expandPath } from "./paths.js";
|
|
10
11
|
import { deniedWriteAsync, deniedReadAsync, wrapShell } from "./sandbox.js";
|
|
11
12
|
import { ensureSearxng, noteSearxngUsed } from "./searxng.js";
|
|
12
13
|
// execFile helper lives in ./exec (shared with computer.ts — one copy, not two).
|
|
@@ -17,7 +18,7 @@ async function shellExec(args) {
|
|
|
17
18
|
const command = str(args.command);
|
|
18
19
|
if (!command)
|
|
19
20
|
return "error: no command given";
|
|
20
|
-
const cwd = args.cwd ? str(args.cwd) : undefined;
|
|
21
|
+
const cwd = args.cwd ? expandPath(str(args.cwd)) : undefined;
|
|
21
22
|
const timeout = Number(args.timeout_ms ?? 120_000);
|
|
22
23
|
const MAXBUF = 64 * 1024 * 1024; // 64MB — big greps/finds no longer hard-fail on a 10MB cap
|
|
23
24
|
// Run under the OS sandbox when KODE_SANDBOX is on (macOS sandbox-exec); otherwise plain bash. The
|
|
@@ -52,7 +53,7 @@ async function shellExec(args) {
|
|
|
52
53
|
const FILE_READ_DEFAULT_LIMIT_LINES = 2000;
|
|
53
54
|
const FILE_READ_MAX_CHARS = 40_000;
|
|
54
55
|
async function fileRead(args) {
|
|
55
|
-
const path = str(args.path);
|
|
56
|
+
const path = expandPath(str(args.path));
|
|
56
57
|
if (!path)
|
|
57
58
|
return "error: no path given";
|
|
58
59
|
const blocked = await deniedReadAsync(path); // sandbox on: refuse reads of credential paths (exfil guard)
|
|
@@ -79,7 +80,7 @@ async function fileRead(args) {
|
|
|
79
80
|
}
|
|
80
81
|
}
|
|
81
82
|
async function fileWrite(args) {
|
|
82
|
-
const path = str(args.path);
|
|
83
|
+
const path = expandPath(str(args.path));
|
|
83
84
|
if (!path)
|
|
84
85
|
return "error: no path given";
|
|
85
86
|
const blocked = await deniedWriteAsync(path); // async: realpath closes the symlink-laundering gap
|
|
@@ -97,7 +98,7 @@ async function fileWrite(args) {
|
|
|
97
98
|
}
|
|
98
99
|
}
|
|
99
100
|
async function fileEdit(args) {
|
|
100
|
-
const path = str(args.path);
|
|
101
|
+
const path = expandPath(str(args.path));
|
|
101
102
|
const oldStr = str(args.old_string);
|
|
102
103
|
const newStr = str(args.new_string);
|
|
103
104
|
const replaceAll = Boolean(args.replace_all);
|
|
@@ -125,7 +126,7 @@ async function fileEdit(args) {
|
|
|
125
126
|
}
|
|
126
127
|
async function grepSearch(args) {
|
|
127
128
|
const pattern = str(args.pattern);
|
|
128
|
-
const path = str(args.path, ".");
|
|
129
|
+
const path = expandPath(str(args.path, "."));
|
|
129
130
|
if (!pattern)
|
|
130
131
|
return "error: no pattern given";
|
|
131
132
|
// -s suppresses errors for unreadable/special files (sockets, FIFOs, permission-denied) that a
|
|
@@ -191,7 +192,7 @@ async function listDirectory(args) {
|
|
|
191
192
|
}
|
|
192
193
|
async function gitCommand(args) {
|
|
193
194
|
const gitArgs = Array.isArray(args.args) ? args.args.map(String) : [];
|
|
194
|
-
const cwd = args.cwd ? str(args.cwd) : undefined;
|
|
195
|
+
const cwd = args.cwd ? expandPath(str(args.cwd)) : undefined;
|
|
195
196
|
if (!gitArgs.length)
|
|
196
197
|
return "error: no args given";
|
|
197
198
|
try {
|
|
@@ -228,7 +229,7 @@ async function checkpoint(args) {
|
|
|
228
229
|
const summary = str(args.summary);
|
|
229
230
|
if (!summary)
|
|
230
231
|
return "error: no summary given";
|
|
231
|
-
const workspace = args.workspace ? str(args.workspace) : process.cwd();
|
|
232
|
+
const workspace = args.workspace ? expandPath(str(args.workspace)) : process.cwd();
|
|
232
233
|
const push = Boolean(args.push);
|
|
233
234
|
try {
|
|
234
235
|
await pexecFile("git", ["add", "-A"], { cwd: workspace });
|
|
@@ -363,7 +364,7 @@ async function shellBackground(args) {
|
|
|
363
364
|
const running = [...bgJobs.values()].filter((j) => !j.done).length;
|
|
364
365
|
if (running >= BG_MAX_RUNNING)
|
|
365
366
|
return `error: ${BG_MAX_RUNNING} background jobs already running — bash_kill one before starting another`;
|
|
366
|
-
const cwd = args.cwd ? str(args.cwd) : undefined;
|
|
367
|
+
const cwd = args.cwd ? expandPath(str(args.cwd)) : undefined;
|
|
367
368
|
const { spawn } = await nodeImport("node:child_process");
|
|
368
369
|
const { file, args: argv } = await wrapShell(command); // same OS sandbox wrap as shell_exec
|
|
369
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/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": {
|