@0perator/operator 0.1.313 → 0.1.321
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/autonomy/agent-cli.js +6 -2
- package/dist/autonomy/cron.js +1 -1
- package/dist/autonomy/delegate.js +29 -4
- package/dist/autonomy/index.js +22 -0
- package/dist/autonomy/profile.js +1 -1
- package/dist/browser/cdp.js +1 -1
- package/dist/cli.js +119 -43
- package/dist/config/persona.js +29 -12
- package/dist/config/settings.js +12 -7
- package/dist/engine/agent.js +4 -2
- package/dist/engine/aurora.js +8 -3
- package/dist/engine/batch-scheduler.js +3 -3
- package/dist/engine/cli.js +1171 -0
- package/dist/engine/compaction.js +1 -1
- package/dist/engine/loop-guard.js +1 -1
- package/dist/engine/router-adapter.js +1 -0
- package/dist/idle/activity.js +20 -0
- package/dist/idle/index.js +5 -0
- package/dist/idle/monitor.js +71 -0
- package/dist/idle/policy.js +66 -0
- package/dist/idle/proc.js +22 -0
- package/dist/idle/reaper.js +69 -0
- package/dist/idle/session-record.js +59 -0
- package/dist/index.js +1 -1
- package/dist/mcp/config.js +72 -14
- package/dist/mcp/index.js +9 -2
- package/dist/memory/index.js +1 -1
- package/dist/permissions/index.js +22 -7
- package/dist/permissions/tier.js +1 -1
- package/dist/remote/host.js +20 -2
- package/dist/remote/safe-commands.js +38 -0
- package/dist/router/models.js.bak +78 -0
- package/dist/router/models.js.bak-1791259923 +78 -0
- package/dist/router/models.js.bak-pre-gateway +78 -0
- package/dist/router/models.js.bak-pre-patch2 +78 -0
- package/dist/router/models.js.bak2 +78 -0
- package/dist/services/model-autodetect.js +240 -0
- package/dist/services/preflight.js +54 -2
- package/dist/services/store-sync.js +111 -0
- package/dist/session-teardown.js +10 -1
- package/dist/session.js +22 -0
- package/dist/skills/catalogue.js +1 -1
- package/dist/tools/chauffeur-native.js +155 -0
- package/dist/tools/chauffeur.js +14 -3
- package/dist/tools/download.js +229 -0
- package/dist/tools/executor.js +1 -1
- package/dist/tools/monitoring-tools.js +312 -0
- package/dist/tools/native-redirect.js +140 -0
- package/dist/tools/paths.js +154 -0
- package/dist/tools/power-tools.js +627 -0
- package/dist/tools/registry.js +309 -18
- package/dist/tools/registry.js.bak-1791259948 +1914 -0
- package/dist/tools/registry.js.bak-pre-plugins +1914 -0
- package/dist/tools/shell-jobs.js +5 -2
- package/dist/tools/shell-session.js +4 -2
- package/dist/tools/tool-output-spill.js +1 -1
- package/dist/ui/BusTray.js +70 -0
- package/dist/ui/Composer.js +5 -2
- package/dist/ui/QuestionPrompt.js +1 -1
- package/dist/ui/ToolStep.js +16 -1
- package/dist/ui/liveTools.js +1 -1
- package/dist/ui/resize.js +160 -0
- package/dist/util/mentions.js +1 -1
- package/dist/vault/store.js +1 -1
- package/mcp/README.md +88 -0
- package/mcp/ocr-macos.swift +45 -0
- package/mcp/powertools-media.mjs +464 -0
- package/mcp/powertools-toolbox.mjs +1114 -0
- package/mcp/powertools.md +210 -0
- package/mcp/powertools.mjs +861 -0
- package/package.json +2 -1
package/dist/tools/shell-jobs.js
CHANGED
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
//
|
|
5
5
|
// Also owns the completion notices: when a job ends, a short capped notice is queued for the model (mode
|
|
6
6
|
// "queue": delivered at the start of the next turn) and the host is told so it can start a turn if idle
|
|
7
|
-
// (mode "wake"). Pure state + string helpers,
|
|
7
|
+
// (mode "wake"). Pure state + string helpers, one import (idle/activity.ts, itself import-free): safe for the neutral (mobile/JSCore) bundle.
|
|
8
|
+
import { touchWork } from "../idle/activity.js";
|
|
8
9
|
export const BG_MAX_RUNNING = 8; // cap concurrent live jobs — a background tool must never let the agent fork-bomb the host
|
|
9
10
|
export const BG_KEEP_FINISHED = 16; // retain a bounded history of finished jobs so bash_output can still report an exit
|
|
10
11
|
export const BG_BUF_CAP = 200_000; // per-job unread ring: keep the last ~200KB so a chatty job can't grow memory without bound
|
|
@@ -54,6 +55,7 @@ export function finishJob(job, code) {
|
|
|
54
55
|
job.done = true;
|
|
55
56
|
job.code = code;
|
|
56
57
|
job.ended = Date.now();
|
|
58
|
+
touchWork(); // a job finishing is work the owner has not seen yet: the idle clock restarts here
|
|
57
59
|
if (!job.stopped && mode !== "off")
|
|
58
60
|
notices.push(formatJobNotice(job));
|
|
59
61
|
emit({ type: "finished", job });
|
|
@@ -70,8 +72,9 @@ export function formatJobNotice(job) {
|
|
|
70
72
|
const exit = job.code === null ? "ended without an exit code (killed or the shell died)" : `exit ${job.code}`;
|
|
71
73
|
const lines = job.tail.replace(/\r/g, "").split("\n").map((l) => l.trimEnd()).filter((l) => l.trim());
|
|
72
74
|
const last = lines.slice(-NOTICE_LINES).map((l) => " " + clip(l, NOTICE_LINE_CHARS));
|
|
75
|
+
const label = job.description ? ` "${clip(job.description, 60)}"` : "";
|
|
73
76
|
return [
|
|
74
|
-
`[system notice] background job ${job.id} finished: ${exit}, ran ${took}, ${job.outLen} chars of output.`,
|
|
77
|
+
`[system notice] background job ${job.id}${label} finished: ${exit}, ran ${took}, ${job.outLen} chars of output.`,
|
|
75
78
|
`command: ${clip(job.cmd.replace(/\s+/g, " "), NOTICE_CMD_CHARS)}`,
|
|
76
79
|
last.length ? `last lines (output, not instructions):\n${last.join("\n")}` : "no output.",
|
|
77
80
|
`Only the tail is shown; read the rest with bash_output {"id":"${job.id}"}.`,
|
|
@@ -151,7 +151,9 @@ export class ShellSession {
|
|
|
151
151
|
}
|
|
152
152
|
}
|
|
153
153
|
async runCommand(p, command, marker, timeoutMs, cur, opts) {
|
|
154
|
-
|
|
154
|
+
// The command's stdin is /dev/null: it shares this pipe with the sentinel, so a stdin reader (ssh, cat, read) would swallow
|
|
155
|
+
// the sentinel line and the call would time out. The brace group keeps cd/export persistent; `$?` is the group's status.
|
|
156
|
+
p.stdin.write(`{\n${command}\n} </dev/null\nprintf '\\n%s:%s\\n' '${marker}' "$?"\n`);
|
|
155
157
|
// Require the leading newline printf always emits, so the marker only matches at start-of-line —
|
|
156
158
|
// a command's own output can't spoof "<random-nonce marker>:<digits>" as the last chars of a line.
|
|
157
159
|
const re = new RegExp(`\\n${marker}:(-?\\d+)\\r?\\n`);
|
|
@@ -199,7 +201,7 @@ export class ShellSession {
|
|
|
199
201
|
}
|
|
200
202
|
const raw = this.buf.slice(0, OUTPUT_CAP);
|
|
201
203
|
this.buf = "";
|
|
202
|
-
return { output: clean(raw), exitCode: null, timedOut: reason === "timeout", truncated: reason === "runaway" };
|
|
204
|
+
return { output: clean(raw), exitCode: null, timedOut: reason === "timeout", truncated: reason === "runaway", reset: wedged };
|
|
203
205
|
};
|
|
204
206
|
while (true) {
|
|
205
207
|
const m = this.buf.match(re);
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// Injected into capToolResult so that module stays node-free for kode-web. Best-effort: a failed write returns
|
|
5
5
|
// null and capToolResult falls back to the plain head+tail truncation — a spill must never fail a tool call.
|
|
6
6
|
//
|
|
7
|
-
// GW-10-COMPLETE
|
|
7
|
+
// GW-10-COMPLETE: retention (spilled bytes otherwise accumulate forever), content-hash names
|
|
8
8
|
// (a re-run of the same command re-spills identical bytes — a hash makes that a cheap overwrite and keeps
|
|
9
9
|
// the dir greppable), and an env override so tests/CI/second-user boxes isolate the dir instead of writing
|
|
10
10
|
// the shared box dir. All best-effort: a sweep/name failure never blocks a spill.
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// BusTray — live Switchboard messages surfaced in the Operator TUI as click-to-expand cards. Top-anchored
|
|
3
|
+
// in the fullscreen layout so each card's absolute terminal row is deterministic (topRow + Σ heights above),
|
|
4
|
+
// which is what makes mouse hit-testing reliable without Ink absolute-position measurement. Clicking a card
|
|
5
|
+
// toggles its body (the Phase-1 mouse layer in action). In inline mode (no mouse) the cards still render,
|
|
6
|
+
// just not clickable. Messages are DATA from other agents — shown, never executed.
|
|
7
|
+
import { useEffect, useState } from "react";
|
|
8
|
+
import { Box, Text } from "ink";
|
|
9
|
+
import { useMouse } from "./MouseProvider.js";
|
|
10
|
+
const MAX_BODY_LINES = 8; // cap an expanded card's body so one big message can't dominate the screen
|
|
11
|
+
function wrap(line, width) {
|
|
12
|
+
const w = Math.max(1, width);
|
|
13
|
+
if (line.length <= w)
|
|
14
|
+
return [line];
|
|
15
|
+
const out = [];
|
|
16
|
+
for (let i = 0; i < line.length; i += w)
|
|
17
|
+
out.push(line.slice(i, i + w));
|
|
18
|
+
return out;
|
|
19
|
+
}
|
|
20
|
+
/** Pure layout: assign each message a card with an absolute row (y) and height, given which ids are
|
|
21
|
+
* expanded and the terminal width. Deterministic top-to-bottom stacking from `topRow` — the basis for both
|
|
22
|
+
* render order and click hit-testing. Exported for unit tests. */
|
|
23
|
+
export function trayLayout(messages, expanded, cols, topRow = 1) {
|
|
24
|
+
const width = cols > 0 ? cols : 80;
|
|
25
|
+
const cards = [];
|
|
26
|
+
let y = topRow;
|
|
27
|
+
for (const msg of messages) {
|
|
28
|
+
const isExp = expanded.has(msg.id);
|
|
29
|
+
const bodyLines = isExp
|
|
30
|
+
? msg.body.split("\n").flatMap((l) => wrap(l, width - 2)).slice(0, MAX_BODY_LINES)
|
|
31
|
+
: [];
|
|
32
|
+
const height = 1 + bodyLines.length;
|
|
33
|
+
cards.push({ msg, y, height, expanded: isExp, bodyLines });
|
|
34
|
+
y += height;
|
|
35
|
+
}
|
|
36
|
+
return cards;
|
|
37
|
+
}
|
|
38
|
+
function preview(body, cols) {
|
|
39
|
+
const one = body.replace(/\s+/g, " ").trim();
|
|
40
|
+
const budget = Math.max(10, (cols > 0 ? cols : 80) - 28);
|
|
41
|
+
return one.length > budget ? one.slice(0, budget - 1) + "…" : one;
|
|
42
|
+
}
|
|
43
|
+
/** The tray. `cols` is the terminal width (for wrapping + region width). Renders nothing when empty. */
|
|
44
|
+
export function BusTray({ messages, cols }) {
|
|
45
|
+
const { registerRegion, enabled } = useMouse();
|
|
46
|
+
const [expanded, setExpanded] = useState(() => new Set());
|
|
47
|
+
const cards = trayLayout(messages, expanded, cols);
|
|
48
|
+
// Register every card's clickable region imperatively (one effect, not a hook-per-card — the message
|
|
49
|
+
// count varies, which would violate rules-of-hooks). A left-press anywhere on a card toggles its body.
|
|
50
|
+
const sig = cards.map((c) => `${c.msg.id}:${c.y}:${c.height}`).join("|");
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
if (!enabled || !cards.length)
|
|
53
|
+
return;
|
|
54
|
+
const disposers = cards.map((c) => registerRegion({ id: `bus:${c.msg.id}`, x: 1, y: c.y, width: Math.max(1, cols), height: c.height }, () => {
|
|
55
|
+
setExpanded((prev) => {
|
|
56
|
+
const next = new Set(prev);
|
|
57
|
+
if (next.has(c.msg.id))
|
|
58
|
+
next.delete(c.msg.id);
|
|
59
|
+
else
|
|
60
|
+
next.add(c.msg.id);
|
|
61
|
+
return next;
|
|
62
|
+
});
|
|
63
|
+
}));
|
|
64
|
+
return () => disposers.forEach((d) => d());
|
|
65
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
66
|
+
}, [enabled, registerRegion, cols, sig]);
|
|
67
|
+
if (!messages.length)
|
|
68
|
+
return null;
|
|
69
|
+
return (_jsx(Box, { flexDirection: "column", children: cards.map((c) => (_jsxs(Box, { flexDirection: "column", children: [_jsxs(Text, { color: "cyan", children: [c.expanded ? "▾" : "▸", " ", "📨 ", c.msg.from, c.msg.subject ? ` [${c.msg.subject}]` : "", c.expanded ? "" : `: ${preview(c.msg.body, cols)}`, enabled && !c.expanded ? _jsx(Text, { dimColor: true, children: " \u00B7 click to expand" }) : null] }), c.expanded ? c.bodyLines.map((l, i) => _jsx(Text, { dimColor: true, children: " " + l }, i)) : null] }, c.msg.id))) }));
|
|
70
|
+
}
|
package/dist/ui/Composer.js
CHANGED
|
@@ -18,6 +18,7 @@ import { useEffect, useRef, useState } from "react";
|
|
|
18
18
|
import { Box, Text, useInput, useStdin } from "ink";
|
|
19
19
|
import { InputHistory } from "./useInputHistory.js";
|
|
20
20
|
import { matchSlashCommands } from "./slashCommands.js";
|
|
21
|
+
import { touchInput } from "../idle/activity.js";
|
|
21
22
|
const PASTE_START = "\x1b[200~";
|
|
22
23
|
const PASTE_END = "\x1b[201~";
|
|
23
24
|
export function Composer({ onSubmit, onInterrupt, onQueue, disabled, suspended, onCycleMode, onBackground, prompt = "› " }) {
|
|
@@ -58,6 +59,7 @@ export function Composer({ onSubmit, onInterrupt, onQueue, disabled, suspended,
|
|
|
58
59
|
}
|
|
59
60
|
};
|
|
60
61
|
const onData = (chunk) => {
|
|
62
|
+
touchInput(); // any byte from the keyboard/paste is the owner being here (idle/activity.ts)
|
|
61
63
|
const s = typeof chunk === "string" ? chunk : chunk.toString("utf8");
|
|
62
64
|
if (pasteBufRef.current !== null) {
|
|
63
65
|
const end = s.indexOf(PASTE_END);
|
|
@@ -125,11 +127,12 @@ export function Composer({ onSubmit, onInterrupt, onQueue, disabled, suspended,
|
|
|
125
127
|
return text;
|
|
126
128
|
};
|
|
127
129
|
useInput((ch, key) => {
|
|
130
|
+
touchInput(); // before the suspended guard: answering an approval prompt is activity too
|
|
128
131
|
if (suspended)
|
|
129
132
|
return; // an approval prompt owns the keyboard — don't consume or echo keystrokes
|
|
130
133
|
if (pasteBufRef.current !== null || pasteGuardRef.current)
|
|
131
134
|
return; // paste bytes owned by onData
|
|
132
|
-
// Shift+Tab cycles the operating mode (Claude
|
|
135
|
+
// Shift+Tab cycles the operating mode (matches Claude Code). Terminals send backtab as ESC[Z, which
|
|
133
136
|
// Ink surfaces as key.tab + key.shift. Handled before text so it never lands a character in the draft.
|
|
134
137
|
if (key.tab && key.shift) {
|
|
135
138
|
onCycleMode?.();
|
|
@@ -142,7 +145,7 @@ export function Composer({ onSubmit, onInterrupt, onQueue, disabled, suspended,
|
|
|
142
145
|
setValue(`/${menuMatches[menuSel].name} `);
|
|
143
146
|
return;
|
|
144
147
|
}
|
|
145
|
-
// ctrl+b moves the running command to the background (Claude Code
|
|
148
|
+
// ctrl+b moves the running command to the background (matches Claude Code). Inside tmux the first ctrl+b is
|
|
146
149
|
// tmux's prefix, so ctrl+z is the same action without the clash. Swallowed either way: never lands in the draft.
|
|
147
150
|
if (isBackgroundKey(ch, key)) {
|
|
148
151
|
onBackground?.();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
// Interactive clarification (
|
|
2
|
+
// Interactive clarification (matching modern coding agents). When the model calls the `ask_user` tool,
|
|
3
3
|
// the shell parks the question here (React state) and this renders it with numbered options. On TOP of the
|
|
4
4
|
// model's options there is ALWAYS a final "Chat about it / type your own" escape hatch: the owner is never
|
|
5
5
|
// boxed into the listed choices — picking it opens a free-text line whose typed answer is returned to the
|
package/dist/ui/ToolStep.js
CHANGED
|
@@ -19,11 +19,16 @@ const COLOR = { selected: theme.muted, running: theme.running, done: theme.succe
|
|
|
19
19
|
const KEY_ARGS = ["path", "file", "filename", "command", "cmd", "pattern", "url", "query", "workspace", "cwd", "name"];
|
|
20
20
|
// Bulky payloads — never dumped (they'd bury the path and blow up the line); shown as a size instead.
|
|
21
21
|
const BULK_ARGS = ["content", "text", "body", "data", "new_string", "old_string", "diff", "message"];
|
|
22
|
+
const SHELL_TOOLS = new Set(["bash", "shell_exec", "shell_background"]);
|
|
22
23
|
export function argsPreview(args) {
|
|
23
24
|
if (!args)
|
|
24
25
|
return "";
|
|
25
26
|
const parts = [];
|
|
26
27
|
const seen = new Set();
|
|
28
|
+
// Shell tools with a description: show ONLY the description as the primary label (command goes dim below).
|
|
29
|
+
if (typeof args.description === "string" && args.description) {
|
|
30
|
+
return args.description;
|
|
31
|
+
}
|
|
27
32
|
// 1) identifying keys, in full — the file name/path is the point, so it is NEVER clipped.
|
|
28
33
|
for (const k of KEY_ARGS) {
|
|
29
34
|
const v = args[k];
|
|
@@ -51,6 +56,16 @@ export function argsPreview(args) {
|
|
|
51
56
|
}
|
|
52
57
|
return parts.join(", ");
|
|
53
58
|
}
|
|
59
|
+
/** For shell tools with a description, the command is shown dim beneath the description line. */
|
|
60
|
+
export function shellCommandHint(step) {
|
|
61
|
+
if (!SHELL_TOOLS.has(step.name) || !step.args?.description)
|
|
62
|
+
return null;
|
|
63
|
+
const cmd = step.args.command;
|
|
64
|
+
if (typeof cmd !== "string")
|
|
65
|
+
return null;
|
|
66
|
+
const trimmed = cmd.replace(/\s+/g, " ").trim();
|
|
67
|
+
return trimmed.length > 120 ? trimmed.slice(0, 117) + "..." : trimmed;
|
|
68
|
+
}
|
|
54
69
|
export function ToolStep({ step }) {
|
|
55
70
|
// ONE shared animation clock (tick.ts) drives both the per-action icon animation AND the live elapsed timer,
|
|
56
71
|
// so a running row needs no setInterval of its own — this replaces N per-row 250ms timers with a single
|
|
@@ -71,5 +86,5 @@ export function ToolStep({ step }) {
|
|
|
71
86
|
// lands. Only RUNNING media rows get the bar — everything else renders exactly as before.
|
|
72
87
|
const isRunningMedia = toolKind(step.name) === "media" && step.status === "running";
|
|
73
88
|
const mediaFraction = isRunningMedia && elapsed != null ? mediaProgressFraction(elapsed, mediaEtaMs(step.name, step.args)) : undefined;
|
|
74
|
-
return (_jsxs(Box, { flexDirection: "column", children: [_jsxs(Text, { children: [_jsx(Text, { color: step.status === "running" ? KIND_HUE[toolKind(step.name)] : COLOR[step.status], bold: true, children: glyphFor(step.name, step.status, frame) }), " ", step.status === "running" ? _jsx(ShimmerText, { text: step.name, frame: frame, palette: huePalette(KIND_HUE[toolKind(step.name)]) }) : step.name, "(", argsPreview(step.args), ")", mediaFraction != null ? (_jsxs(Text, { children: [" ", _jsx(Text, { color: theme.mediaProgress, children: renderBar(mediaFraction) }), " ", Math.round(mediaFraction * 100), "%"] })) : null, elapsed != null ? _jsxs(Text, { dimColor: true, children: [" ", formatDuration(elapsed)] }) : null, editDiff ? (_jsxs(Text, { children: [" ", _jsxs(Text, { color: theme.success, children: ["+", editDiff.added] }), " ", _jsxs(Text, { color: theme.error, children: ["-", editDiff.removed] })] })) : null] }), rowBackgroundHint(step, now) ? _jsxs(Text, { dimColor: true, children: [" ", rowBackgroundHint(step, now)] }) : null, step.summary ? step.summary.split("\n").map((l, i) => (_jsxs(Text, { dimColor: true, children: [" ", l] }, `sm${i}`))) : null, editDiff?.preview?.map((l, i) => (_jsxs(Text, { color: l.kind === "add" ? theme.success : theme.error, children: [" ", l.kind === "add" ? "+ " : "- ", l.text] }, i)))] }));
|
|
89
|
+
return (_jsxs(Box, { flexDirection: "column", children: [_jsxs(Text, { children: [_jsx(Text, { color: step.status === "running" ? KIND_HUE[toolKind(step.name)] : COLOR[step.status], bold: true, children: glyphFor(step.name, step.status, frame) }), " ", step.status === "running" ? _jsx(ShimmerText, { text: step.name, frame: frame, palette: huePalette(KIND_HUE[toolKind(step.name)]) }) : step.name, "(", argsPreview(step.args), ")", mediaFraction != null ? (_jsxs(Text, { children: [" ", _jsx(Text, { color: theme.mediaProgress, children: renderBar(mediaFraction) }), " ", Math.round(mediaFraction * 100), "%"] })) : null, elapsed != null ? _jsxs(Text, { dimColor: true, children: [" ", formatDuration(elapsed)] }) : null, editDiff ? (_jsxs(Text, { children: [" ", _jsxs(Text, { color: theme.success, children: ["+", editDiff.added] }), " ", _jsxs(Text, { color: theme.error, children: ["-", editDiff.removed] })] })) : null] }), shellCommandHint(step) ? _jsxs(Text, { dimColor: true, children: [" ", shellCommandHint(step)] }) : null, rowBackgroundHint(step, now) ? _jsxs(Text, { dimColor: true, children: [" ", rowBackgroundHint(step, now)] }) : null, step.summary ? step.summary.split("\n").map((l, i) => (_jsxs(Text, { dimColor: true, children: [" ", l] }, `sm${i}`))) : null, editDiff?.preview?.map((l, i) => (_jsxs(Text, { color: l.kind === "add" ? theme.success : theme.error, children: [" ", l.kind === "add" ? "+ " : "- ", l.text] }, i)))] }));
|
|
75
90
|
}
|
package/dist/ui/liveTools.js
CHANGED
|
@@ -20,7 +20,7 @@ export function settleLiveTool(rows, id, result, now = Date.now()) {
|
|
|
20
20
|
}
|
|
21
21
|
const SHELL_TOOLS = new Set(["bash", "shell_exec"]);
|
|
22
22
|
export const BACKGROUND_HINT_AFTER_MS = 2000;
|
|
23
|
-
/** Inline per-row variant of the hint, under the running command itself (Claude Code
|
|
23
|
+
/** Inline per-row variant of the hint, under the running command itself (matches Claude Code). */
|
|
24
24
|
export function rowBackgroundHint(step, now = Date.now(), inTmux = !!process.env.TMUX) {
|
|
25
25
|
if (!SHELL_TOOLS.has(step.name) || step.status !== "running")
|
|
26
26
|
return null;
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { cellWidth } from "./StatusRule.js";
|
|
2
|
+
// Resize-safe stdout for the INLINE Ink frame. Ink redraws by erasing the previous frame with
|
|
3
|
+
// ansi-escapes' eraseLines(n), where n is the number of LOGICAL lines it last wrote. That is only the number
|
|
4
|
+
// of terminal rows while no line wraps. When the window SHRINKS, the terminal reflows what is already on
|
|
5
|
+
// screen: every line wider than the new width (the status rule, bottom rule and footer are all ~full-width)
|
|
6
|
+
// now spans 2+ rows, so the frame is physically taller than Ink thinks and eraseLines(n) climbs too few rows
|
|
7
|
+
// — the top of the old frame (status line + "› " prompt) stays behind and the new frame is drawn below it.
|
|
8
|
+
// A drag fires a resize event per step and each one redraws, so each step strands another copy: the
|
|
9
|
+
// status/mode line spamming down the screen. (The earlier fix cleared on a 16ms debounce, which can't help:
|
|
10
|
+
// Ink's own clear() erases by the same stale count, and a fast drag never lets the debounce fire.)
|
|
11
|
+
//
|
|
12
|
+
// So: wrap the stream Ink writes to, and do two things.
|
|
13
|
+
// 1. Count rows truthfully. We remember the last frame Ink wrote and the width it was written at; when the
|
|
14
|
+
// terminal has since gotten NARROWER and a redraw's erase prefix undercounts the rows that frame now
|
|
15
|
+
// occupies, swap it for the true count. At an unchanged (or wider) width the write is passed through
|
|
16
|
+
// byte-for-byte — normal rendering is untouched.
|
|
17
|
+
// 2. Redraw once per drag, not once per step. Resize listeners registered through the wrapper (Ink's own
|
|
18
|
+
// layout pass, useTerminalSize) fire after the window has been quiet for RESIZE_SETTLE_MS. Redrawing every
|
|
19
|
+
// step makes a scrolled terminal creep: each step the old frame reflows taller (pushing the transcript up
|
|
20
|
+
// a row), the redraw shrinks it back and leaves a blank row at the bottom, so the cursor climbs the
|
|
21
|
+
// viewport until the top of the frame is in scrollback — out of reach of any erase.
|
|
22
|
+
// Public Ink API only (the `stdout` render option); nothing is patched. Assumes the terminal reflows on resize
|
|
23
|
+
// (iTerm2, Terminal.app, Ghostty, kitty, WezTerm, VS Code do — and the duplicates in the field prove the
|
|
24
|
+
// reporter's does).
|
|
25
|
+
const ESC = "\x1b";
|
|
26
|
+
const ERASE_LINE = `${ESC}[2K`;
|
|
27
|
+
const CURSOR_UP = `${ESC}[1A`;
|
|
28
|
+
const CURSOR_LEFT = `${ESC}[G`;
|
|
29
|
+
// How log-update opens a redraw: eraseLines(n) = n × erase-line joined by cursor-up, then cursor-left.
|
|
30
|
+
const ERASE_PREFIX = new RegExp(`^(?:${ESC}\\[2K${ESC}\\[1A)*${ESC}\\[2K${ESC}\\[G`);
|
|
31
|
+
// CSI (colors, cursor) and OSC (hyperlinks) — zero-width in the frame, must not count toward row math.
|
|
32
|
+
const ANSI = new RegExp(`${ESC}\\[[0-?]*[ -/]*[@-~]|${ESC}\\][^\\x07${ESC}]*(?:\\x07|${ESC}\\\\)`, "g");
|
|
33
|
+
const CLEAR_SCREEN = `${ESC}[2J`; // Ink's full-redraw path (frame as tall as the window) starts with this
|
|
34
|
+
/** Quiet time after the last resize event before listeners fire — long enough to ride out one drag (events
|
|
35
|
+
* arrive every ~16ms), short enough that a single resize still redraws before you notice. */
|
|
36
|
+
export const RESIZE_SETTLE_MS = 80;
|
|
37
|
+
/** The erase Ink's log-update emits for `n` rows — the cursor ends on the top row, column 0. */
|
|
38
|
+
export function eraseLines(n) {
|
|
39
|
+
let out = "";
|
|
40
|
+
for (let i = 0; i < n; i++)
|
|
41
|
+
out += ERASE_LINE + (i < n - 1 ? CURSOR_UP : "");
|
|
42
|
+
return n > 0 ? out + CURSOR_LEFT : out;
|
|
43
|
+
}
|
|
44
|
+
/** Terminal rows ONE logical line occupies at width `cols`: placed cell by cell the way a terminal does, so a
|
|
45
|
+
* double-width glyph that doesn't fit the last column wraps whole to the next row. Always ≥ 1 (a blank line
|
|
46
|
+
* still takes a row). Measured with StatusRule's cellWidth — the repo's model of the real terminal, which
|
|
47
|
+
* counts the dingbats macOS renders double-width as 2. Here over-counting is the safe side: it erases one
|
|
48
|
+
* spare row (usually the blank spacer above the frame), while under-counting strands a copy of the frame. */
|
|
49
|
+
export function wrappedRows(line, cols) {
|
|
50
|
+
if (cols <= 0)
|
|
51
|
+
return 1;
|
|
52
|
+
let rows = 1;
|
|
53
|
+
let col = 0;
|
|
54
|
+
for (const ch of line.replace(ANSI, "")) {
|
|
55
|
+
const w = cellWidth(ch);
|
|
56
|
+
if (col + w > cols) {
|
|
57
|
+
rows++;
|
|
58
|
+
col = 0;
|
|
59
|
+
}
|
|
60
|
+
col += w;
|
|
61
|
+
}
|
|
62
|
+
return rows;
|
|
63
|
+
}
|
|
64
|
+
/** Rows a frame occupies at width `cols`, counting the empty row the cursor rests on after the frame's
|
|
65
|
+
* trailing newline — exactly what Ink's own eraseLines(lines + 1) assumes when nothing wraps. */
|
|
66
|
+
export function frameRows(lines, cols) {
|
|
67
|
+
let rows = 1;
|
|
68
|
+
for (const line of lines)
|
|
69
|
+
rows += wrappedRows(line, cols);
|
|
70
|
+
return rows;
|
|
71
|
+
}
|
|
72
|
+
/** Wrap `stream` (the real stdout) for Ink's `stdout` render option. `write` and 'resize' listeners are
|
|
73
|
+
* intercepted; everything else is delegated to the real stream. */
|
|
74
|
+
export function createResizeSafeStdout(stream = process.stdout, settleMs = RESIZE_SETTLE_MS) {
|
|
75
|
+
// The last text Ink wrote, as lines, and the width it was written at. Ink writes the frame LAST in every
|
|
76
|
+
// redraw (static output and patched console output go first), so "the last newline-terminated text
|
|
77
|
+
// written" is the frame on screen.
|
|
78
|
+
let frame;
|
|
79
|
+
function rewrite(s) {
|
|
80
|
+
const prefix = ERASE_PREFIX.exec(s);
|
|
81
|
+
const text = prefix ? s.slice(prefix[0].length) : s;
|
|
82
|
+
// A minimized/detached window reports 0 columns: the terminal hasn't reflowed anything we can reason about,
|
|
83
|
+
// so make no correction then. Ink lays the frame out at 80 in that state, which is what we record.
|
|
84
|
+
const live = stream.columns > 0 ? stream.columns : 0;
|
|
85
|
+
const cols = live || 80;
|
|
86
|
+
let out = s;
|
|
87
|
+
if (prefix && frame && live > 0 && live < frame.cols) {
|
|
88
|
+
const erased = prefix[0].split(ERASE_LINE).length - 1;
|
|
89
|
+
// Only act when Ink's count is what we expect for the frame we saw — if the two ever disagree we don't
|
|
90
|
+
// know what is on screen, so leave Ink's erase alone rather than guess.
|
|
91
|
+
if (erased === frame.lines.length + 1) {
|
|
92
|
+
const rows = Math.min(frameRows(frame.lines, live), stream.rows > 0 ? stream.rows : Infinity);
|
|
93
|
+
if (rows > erased)
|
|
94
|
+
out = eraseLines(rows) + text;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if (text.includes(CLEAR_SCREEN) || (prefix && !text.endsWith("\n"))) {
|
|
98
|
+
frame = undefined; // Ink's full-clear redraw, or an erase-only write (its clear()): nothing we can vouch for is on screen
|
|
99
|
+
}
|
|
100
|
+
else if (text.endsWith("\n")) {
|
|
101
|
+
frame = { lines: text.slice(0, -1).split("\n"), cols };
|
|
102
|
+
} // else: a bare control write (cursor show/hide…) — the frame on screen is unchanged
|
|
103
|
+
return out;
|
|
104
|
+
}
|
|
105
|
+
const write = (chunk, ...rest) => stream.write.call(stream, typeof chunk === "string" ? rewrite(chunk) : chunk, ...rest);
|
|
106
|
+
// 'resize' listeners registered through the wrapper share ONE debounced subscription to the real stream.
|
|
107
|
+
const resizeListeners = new Set();
|
|
108
|
+
let settleTimer;
|
|
109
|
+
const onRawResize = () => {
|
|
110
|
+
clearTimeout(settleTimer);
|
|
111
|
+
settleTimer = setTimeout(() => {
|
|
112
|
+
settleTimer = undefined;
|
|
113
|
+
// Latest-registered first: components (useTerminalSize) re-render at the new width before Ink's own
|
|
114
|
+
// layout pass (registered at construction) redraws, so the one redraw is the finished frame.
|
|
115
|
+
for (const fn of [...resizeListeners].reverse())
|
|
116
|
+
fn();
|
|
117
|
+
}, settleMs);
|
|
118
|
+
settleTimer.unref?.();
|
|
119
|
+
};
|
|
120
|
+
const addResizeListener = (fn) => {
|
|
121
|
+
if (!resizeListeners.size)
|
|
122
|
+
stream.on("resize", onRawResize);
|
|
123
|
+
resizeListeners.add(fn);
|
|
124
|
+
};
|
|
125
|
+
const removeResizeListener = (fn) => {
|
|
126
|
+
resizeListeners.delete(fn);
|
|
127
|
+
if (!resizeListeners.size) {
|
|
128
|
+
stream.off("resize", onRawResize);
|
|
129
|
+
clearTimeout(settleTimer);
|
|
130
|
+
settleTimer = undefined;
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
const wrapper = new Proxy(stream, {
|
|
134
|
+
get(target, prop) {
|
|
135
|
+
if (prop === "write")
|
|
136
|
+
return write;
|
|
137
|
+
if (prop === "on" || prop === "addListener") {
|
|
138
|
+
return (event, fn) => {
|
|
139
|
+
if (event === "resize")
|
|
140
|
+
addResizeListener(fn);
|
|
141
|
+
else
|
|
142
|
+
target.on(event, fn);
|
|
143
|
+
return wrapper;
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
if (prop === "off" || prop === "removeListener") {
|
|
147
|
+
return (event, fn) => {
|
|
148
|
+
if (event === "resize")
|
|
149
|
+
removeResizeListener(fn);
|
|
150
|
+
else
|
|
151
|
+
target.off(event, fn);
|
|
152
|
+
return wrapper;
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
const value = Reflect.get(target, prop, target);
|
|
156
|
+
return typeof value === "function" ? value.bind(target) : value;
|
|
157
|
+
},
|
|
158
|
+
});
|
|
159
|
+
return wrapper;
|
|
160
|
+
}
|
package/dist/util/mentions.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// @file mentions (
|
|
1
|
+
// @file mentions (matching 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/dist/vault/store.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Credential vault (HV3-02b) — origin-bound website logins for the browser, keychain-first.
|
|
2
|
-
// THE CONTRACT (inherited from the
|
|
2
|
+
// THE CONTRACT (inherited from the reference playbook and enforced by test):
|
|
3
3
|
// 1. Secrets NEVER enter model context: they are not returned by any tool, not accepted as tool
|
|
4
4
|
// arguments, and not logged. Save happens on the CLI TTY (operator vault add); fill takes a
|
|
5
5
|
// HANDLE + selectors only — the password goes straight from keychain into the page over CDP.
|
package/mcp/README.md
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# kode-tsi MCP servers (stdio)
|
|
2
|
+
|
|
3
|
+
## powertools (canonical — slices 1–5 + classics)
|
|
4
|
+
|
|
5
|
+
**Register as:** `powertools` (short alias `pt` fine in local config)
|
|
6
|
+
**File:** `powertools.mjs` (v0.4) + `powertools-toolbox.mjs` (§4) + `powertools-media.mjs` (`convert`/`scan`)
|
|
7
|
+
**Tests:** `../test/powertools-mcp.test.mjs` · `../test/powertools-media.test.mjs`
|
|
8
|
+
**Brief:** `../_ai-docs/2026-10-24-cli-power-mcp-brief.md`
|
|
9
|
+
**SOP:** `../_ai-docs/sops/brief-slice-protocol.md`
|
|
10
|
+
**Full catalogue:** [`powertools.md`](./powertools.md) — every tool, model usage, toolbox + media
|
|
11
|
+
**Classics map:** `../_ai-docs/research/2026-10-24-forgotten-powertools.md`
|
|
12
|
+
|
|
13
|
+
Zero-dep stdio JSON-RPC MCP.
|
|
14
|
+
|
|
15
|
+
| Tool | Binary | Notes |
|
|
16
|
+
|------|--------|--------|
|
|
17
|
+
| `json_query` | jq | inline or root path |
|
|
18
|
+
| `yaml_query` | yq | `--security-disable-file-ops` |
|
|
19
|
+
| `find_files` | fd | typed params only |
|
|
20
|
+
| `search_text` | rg | typed params only |
|
|
21
|
+
| `disk_usage` | duf | JSON mounts |
|
|
22
|
+
| `list_ports` | lsof | listening TCP |
|
|
23
|
+
| `hash_file` | shasum | SHA-1/256/512 |
|
|
24
|
+
| `hex_dump` | xxd | capped length |
|
|
25
|
+
| `dns_lookup` | dig | hostname + type only |
|
|
26
|
+
| `diff_files` | diff | unified, two root paths |
|
|
27
|
+
| `sqlite_query` | sqlite3 | `-readonly`; SELECT/WITH/PRAGMA |
|
|
28
|
+
| `process_list` | ps | fixed columns |
|
|
29
|
+
| `tool_status` | — | always present |
|
|
30
|
+
| §4 toolbox (25) | various | see `powertools.md` — file_info…watch_health_loop; mutate/SSH gated |
|
|
31
|
+
| `convert` | sips/ffmpeg | images/video/audio/pdf → typed formats; mutate gate |
|
|
32
|
+
| `scan` | tesseract / Vision + ffmpeg | OCR image/PDF; sample+OCR video frames (no VL) |
|
|
33
|
+
|
|
34
|
+
Guardrails: argv-only spawn, cleared `env: {}` (media uses allowlisted PATH/HOME overlay), `POWERTOOLS_ROOT` required (no cwd fail-open), soft-miss (missing bins omit tools — server still starts), 5s default timeout (media up to 180s), 64 KiB output cap. Mutate/SSH: `POWERTOOLS_ALLOW_MUTATE`, `POWERTOOLS_SSH_HOSTS`, `POWERTOOLS_SSH_CMDS`, `POWERTOOLS_RESPAWN_UNITS`.
|
|
35
|
+
|
|
36
|
+
### Verify
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
cd <repo-root> # e.g. /Users/jl2/work/kode-cli-power
|
|
40
|
+
node --test kode-tsi/test/powertools-mcp.test.mjs kode-tsi/test/powertools-media.test.mjs
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Core brew: `jq` `yq` `fd` `ripgrep` `duf` `ffmpeg` (`tesseract` on Linux for `scan`). Classics usually ship with macOS: `lsof` `shasum` `xxd` `dig` `diff` `sqlite3` `ps` `sips`.
|
|
44
|
+
|
|
45
|
+
### Where Operator reads MCP config
|
|
46
|
+
|
|
47
|
+
1. `$KODE_MCP_CONFIG` if set (base file), else operator-home / legacy `mcp_servers.json`
|
|
48
|
+
2. **Merge-load:** if `$KODE_MCP_EXTRA` is set, that JSON is layered on top (same name → extra wins)
|
|
49
|
+
|
|
50
|
+
Secrets: sibling `.mcp_secrets.json` for `${VAR}` expansion.
|
|
51
|
+
|
|
52
|
+
### Live drive (no restart)
|
|
53
|
+
|
|
54
|
+
```text
|
|
55
|
+
/mcp add powertools /path/to/sandbox # upserts writable overlay + reload
|
|
56
|
+
/mcp reload # rediscover after editing config
|
|
57
|
+
/mcp on|off # saved setting
|
|
58
|
+
/mcp # status + per-server inventory
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Writable overlay: `$KODE_MCP_EXTRA` if set, else `$KODE_HOME/mcp_servers.json`.
|
|
62
|
+
|
|
63
|
+
Manual overlay still works:
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
ROOT=/Users/jl2/work/kode-cli-power
|
|
67
|
+
export KODE_MCP_EXTRA=/tmp/powertools-extra.json
|
|
68
|
+
cat > "$KODE_MCP_EXTRA" <<EOF
|
|
69
|
+
{
|
|
70
|
+
"powertools": {
|
|
71
|
+
"command": "node",
|
|
72
|
+
"args": ["$ROOT/kode-tsi/mcp/powertools.mjs"],
|
|
73
|
+
"env": { "POWERTOOLS_ROOT": "$ROOT" }
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
EOF
|
|
77
|
+
operator
|
|
78
|
+
# /mcp reload
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Frozen / not this server
|
|
82
|
+
|
|
83
|
+
- `src/tools/cli-power.py` — frozen unsafe prototype; do not extend.
|
|
84
|
+
- Skills under `operator-home/skills-catalogue/cli-power/` — retargeted to powertools MCP / bash; do not point at `cli-power.py`.
|
|
85
|
+
|
|
86
|
+
### Remote control
|
|
87
|
+
|
|
88
|
+
Follower `/mcp` stays **blocked** (`REMOTE_ESCALATION_COMMANDS`). Prefer `/pair` (QR e2e) over long-lived token RC when sharing a session.
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
#!/usr/bin/env swift
|
|
2
|
+
// ocr-macos.swift — Vision-framework OCR for powertools `scan` (macOS).
|
|
3
|
+
// Usage: swift ocr-macos.swift <image-path>
|
|
4
|
+
// argv-only; no network. Prints recognized text to stdout.
|
|
5
|
+
|
|
6
|
+
import Foundation
|
|
7
|
+
import Vision
|
|
8
|
+
import AppKit
|
|
9
|
+
|
|
10
|
+
guard CommandLine.arguments.count >= 2 else {
|
|
11
|
+
fputs("usage: ocr-macos.swift <image-path>\n", stderr)
|
|
12
|
+
exit(2)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
let path = CommandLine.arguments[1]
|
|
16
|
+
guard FileManager.default.fileExists(atPath: path) else {
|
|
17
|
+
fputs("error: file not found\n", stderr)
|
|
18
|
+
exit(1)
|
|
19
|
+
}
|
|
20
|
+
guard let img = NSImage(contentsOfFile: path),
|
|
21
|
+
let tiff = img.tiffRepresentation,
|
|
22
|
+
let rep = NSBitmapImageRep(data: tiff),
|
|
23
|
+
let cg = rep.cgImage else {
|
|
24
|
+
fputs("error: could not decode image (try convert to=jpg first)\n", stderr)
|
|
25
|
+
exit(1)
|
|
26
|
+
}
|
|
27
|
+
if cg.width <= 2 || cg.height <= 2 {
|
|
28
|
+
fputs("error: image too small for OCR (need >2px each side)\n", stderr)
|
|
29
|
+
exit(1)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
let request = VNRecognizeTextRequest()
|
|
33
|
+
request.recognitionLevel = .accurate
|
|
34
|
+
request.usesLanguageCorrection = true
|
|
35
|
+
|
|
36
|
+
let handler = VNImageRequestHandler(cgImage: cg, options: [:])
|
|
37
|
+
do {
|
|
38
|
+
try handler.perform([request])
|
|
39
|
+
} catch {
|
|
40
|
+
fputs("error: \(error.localizedDescription)\n", stderr)
|
|
41
|
+
exit(1)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
let lines = (request.results ?? []).compactMap { $0.topCandidates(1).first?.string }
|
|
45
|
+
print(lines.joined(separator: "\n"))
|