@0perator/operator 0.1.285 → 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/README.md +24 -2
- package/dist/acp/agent.js +2 -1
- package/dist/acp/config-options.js +3 -1
- package/dist/acp/tool-map.js +2 -1
- package/dist/auth/commands.js +69 -13
- package/dist/autonomy/agent-cli.js +308 -0
- package/dist/autonomy/cloud-agent.js +439 -0
- package/dist/autonomy/cron-lifecycle.js +78 -0
- package/dist/autonomy/cron-lock.js +121 -0
- package/dist/autonomy/cron.js +217 -44
- package/dist/autonomy/delegate.js +34 -5
- package/dist/autonomy/incidents.js +135 -0
- package/dist/autonomy/index.js +22 -0
- package/dist/autonomy/profile.js +1 -1
- package/dist/autonomy/session-factory.js +25 -16
- package/dist/background/index.js +40 -0
- package/dist/browser/cdp.js +1 -1
- package/dist/bus/inbox.js +20 -0
- package/dist/classifier/config.js +47 -0
- package/dist/classifier/modes.js +41 -0
- package/dist/classifier/types.js +1 -0
- package/dist/cli.js +645 -93
- package/dist/config/features.js +69 -0
- package/dist/config/persona.js +143 -107
- package/dist/config/scaffold.js +15 -0
- package/dist/config/settings.js +107 -12
- package/dist/consolidation/sleep.js +73 -11
- package/dist/engine/agent.js +279 -20
- package/dist/engine/anthropic-chat.js +343 -0
- package/dist/engine/aurora.js +109 -16
- package/dist/engine/batch-scheduler.js +41 -9
- package/dist/engine/classifier.js +85 -0
- package/dist/engine/compaction.js +25 -6
- package/dist/engine/fast-start.js +25 -0
- package/dist/engine/loop-guard.js +448 -0
- package/dist/engine/net-error.js +24 -0
- package/dist/engine/repetition-guard.js +180 -0
- package/dist/engine/router-adapter.js +1 -0
- package/dist/engine/selfheal.js +8 -0
- package/dist/engine/toolcalls.js +51 -1
- package/dist/engine/verify-gate.js +2 -0
- package/dist/flywheel/processor.js +78 -31
- package/dist/flywheel/srft.js +13 -0
- package/dist/hooks/index.js +196 -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 +93 -15
- package/dist/mcp/index.js +9 -2
- package/dist/memory/index.js +0 -0
- package/dist/memory/providers.js +210 -0
- package/dist/memory/session-catalog.js +422 -0
- package/dist/memory/session-providers.js +121 -0
- package/dist/memory/session-sources.js +335 -0
- package/dist/memory/skylark.js +131 -0
- package/dist/models/bench.js +103 -0
- package/dist/models/registry.js +144 -0
- package/dist/models/switch.js +69 -0
- package/dist/observability/blackbox.js +37 -0
- package/dist/permissions/index.js +22 -7
- package/dist/permissions/policy.js +31 -6
- 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/discovery.js +127 -0
- package/dist/router/models.js +107 -16
- package/dist/router/portal.js +100 -0
- package/dist/router/router.js +1 -1
- package/dist/services/preflight.js +108 -8
- package/dist/services/store-sync.js +111 -0
- package/dist/session-teardown.js +10 -1
- package/dist/session.js +338 -46
- package/dist/skills/catalogue.js +1 -1
- package/dist/tools/chauffeur-native.js +155 -0
- package/dist/tools/chauffeur.js +26 -3
- package/dist/tools/download.js +229 -0
- package/dist/tools/executor.js +19 -9
- package/dist/tools/find-files.js +483 -0
- package/dist/tools/git-pr.js +94 -0
- package/dist/tools/incident-tools.js +82 -0
- package/dist/tools/memory.js +12 -2
- package/dist/tools/monitoring-tools.js +312 -0
- package/dist/tools/paths.js +154 -0
- package/dist/tools/registry.js +582 -95
- package/dist/tools/semantic-compress.js +124 -0
- package/dist/tools/shell-context.js +1 -0
- package/dist/tools/shell-jobs.js +163 -0
- package/dist/tools/shell-session.js +174 -6
- package/dist/tools/tool-output-spill.js +1 -1
- package/dist/tools/wave-tools.js +609 -0
- package/dist/tools/wave2-tools.js +411 -0
- package/dist/ui/App.js +15 -4
- package/dist/ui/BgPanel.js +30 -6
- package/dist/ui/Composer.js +15 -2
- package/dist/ui/QuestionPrompt.js +32 -12
- package/dist/ui/SessionPicker.js +86 -0
- package/dist/ui/StatusRule.js +5 -5
- package/dist/ui/ToolStep.js +17 -1
- package/dist/ui/Transcript.js +17 -1
- package/dist/ui/index.js +1 -1
- package/dist/ui/liveTools.js +21 -3
- package/dist/ui/slashCommands.js +2 -0
- package/dist/util/mentions.js +1 -1
- package/dist/util/screenshots.js +74 -8
- package/dist/util/slash.js +2 -2
- 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 +9 -2
package/dist/tools/memory.js
CHANGED
|
@@ -78,6 +78,7 @@ export async function runMemoryTool(args) {
|
|
|
78
78
|
text = fs.readFileSync(fp, "utf8");
|
|
79
79
|
}
|
|
80
80
|
catch { /* file may not exist yet */ }
|
|
81
|
+
const before = text.length; // headroom is computed against what was ALREADY there, not the op's own size
|
|
81
82
|
for (const op of ops) {
|
|
82
83
|
switch (op.action) {
|
|
83
84
|
case "add":
|
|
@@ -105,8 +106,17 @@ export async function runMemoryTool(args) {
|
|
|
105
106
|
}
|
|
106
107
|
text = text.replace(/\n{3,}/g, "\n\n").trim() + "\n";
|
|
107
108
|
const budget = BUDGETS[target];
|
|
108
|
-
if (text.length > budget)
|
|
109
|
-
|
|
109
|
+
if (text.length > budget) {
|
|
110
|
+
// A retry that only trims the ADD's own content can never converge when the file was
|
|
111
|
+
// already near the cap — the error must say so, or an agent loops shrinking the wrong
|
|
112
|
+
// number forever (lived bug: MEMORY.md sat at 2164/2200, 8 retries, all still "too big").
|
|
113
|
+
const headroom = Math.max(0, budget - before);
|
|
114
|
+
const overBy = text.length - budget;
|
|
115
|
+
return `error: result is ${text.length} chars, exceeds ${target} budget of ${budget} by ${overBy} — ` +
|
|
116
|
+
`${TARGETS[target]} already holds ${before}/${budget} chars (${headroom} headroom before this op). ` +
|
|
117
|
+
`Shrinking only the new content will not be enough unless it fits in ${headroom} chars — ` +
|
|
118
|
+
`free room with action:"remove"/"replace" on a stale entry first, or write this elsewhere (it's unbounded there).`;
|
|
119
|
+
}
|
|
110
120
|
fs.mkdirSync(path.dirname(fp), { recursive: true });
|
|
111
121
|
fs.writeFileSync(fp, text);
|
|
112
122
|
return `wrote ${TARGETS[target]} (${text.length}/${budget} chars, ${ops.length} op${ops.length === 1 ? "" : "s"} applied)`;
|
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
import { expandPath } from "./paths.js";
|
|
2
|
+
import { pexecFile } from "./exec.js";
|
|
3
|
+
const nodeImport = (m) => import(/* @vite-ignore */ m);
|
|
4
|
+
const BODY_CAP = 2 * 1024; // 2 KiB
|
|
5
|
+
const DEFAULT_TIMEOUT_MS = 3_000;
|
|
6
|
+
const MAX_TIMEOUT_MS = 15_000;
|
|
7
|
+
const DEFAULT_TAIL_LINES = 80;
|
|
8
|
+
const HARD_TAIL_LINES = 500;
|
|
9
|
+
const DEFAULT_PS_MAX = 50;
|
|
10
|
+
const HARD_PS_MAX = 200;
|
|
11
|
+
const TITLE_CAP = 100;
|
|
12
|
+
const BODY_NOTIFY_CAP = 500;
|
|
13
|
+
const PS_ARGV = ["-axo", "pid=,ppid=,user=,pcpu=,pmem=,state=,comm="];
|
|
14
|
+
const PS_BINS = ["/bin/ps", "/usr/bin/ps"];
|
|
15
|
+
const SENSITIVE_PATHS = [
|
|
16
|
+
"/etc/shadow",
|
|
17
|
+
"/etc/passwd",
|
|
18
|
+
"/etc/master.passwd",
|
|
19
|
+
"/etc/sudoers",
|
|
20
|
+
];
|
|
21
|
+
function str(v, fallback = "") {
|
|
22
|
+
return v === undefined || v === null ? fallback : String(v);
|
|
23
|
+
}
|
|
24
|
+
function clampInt(v, fallback, hardMax, hardMin = 1) {
|
|
25
|
+
const n = Number(v);
|
|
26
|
+
if (!Number.isFinite(n) || n < hardMin)
|
|
27
|
+
return fallback;
|
|
28
|
+
return Math.min(Math.floor(n), hardMax);
|
|
29
|
+
}
|
|
30
|
+
function underRoot(realPath, root) {
|
|
31
|
+
return realPath === root || realPath.startsWith(root.endsWith("/") ? root : root + "/");
|
|
32
|
+
}
|
|
33
|
+
/** Resolve allowed sandbox roots for log_tail: $HOME (or cwd if home unavailable), plus
|
|
34
|
+
* POWERTOOLS_ROOT / KODE_HOME when set. */
|
|
35
|
+
async function logAllowedRoots() {
|
|
36
|
+
const { realpath } = await nodeImport("node:fs/promises");
|
|
37
|
+
const pathMod = await nodeImport("node:path");
|
|
38
|
+
const roots = [];
|
|
39
|
+
const push = async (raw) => {
|
|
40
|
+
if (!raw || typeof raw !== "string" || !raw.trim())
|
|
41
|
+
return;
|
|
42
|
+
const abs = pathMod.resolve(raw);
|
|
43
|
+
try {
|
|
44
|
+
roots.push(await realpath(abs));
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
roots.push(abs);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
const home = process.env.HOME || process.env.USERPROFILE;
|
|
51
|
+
if (home)
|
|
52
|
+
await push(home);
|
|
53
|
+
else
|
|
54
|
+
await push(process.cwd());
|
|
55
|
+
await push(process.env.POWERTOOLS_ROOT || process.env.CLI_POWER_ROOT);
|
|
56
|
+
await push(process.env.KODE_HOME);
|
|
57
|
+
return [...new Set(roots)];
|
|
58
|
+
}
|
|
59
|
+
async function resolveLogPath(userPath) {
|
|
60
|
+
if (!userPath.trim())
|
|
61
|
+
return { error: "error: path required" };
|
|
62
|
+
const pathMod = await nodeImport("node:path");
|
|
63
|
+
const { realpath } = await nodeImport("node:fs/promises");
|
|
64
|
+
const expanded = expandPath(userPath.trim());
|
|
65
|
+
const abs = pathMod.resolve(expanded);
|
|
66
|
+
const norm = pathMod.normalize(abs);
|
|
67
|
+
for (const bad of SENSITIVE_PATHS) {
|
|
68
|
+
if (norm === bad || norm.endsWith(bad)) {
|
|
69
|
+
return { error: `error: refused sensitive path: ${userPath}` };
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
let real;
|
|
73
|
+
try {
|
|
74
|
+
real = await realpath(abs);
|
|
75
|
+
}
|
|
76
|
+
catch (e) {
|
|
77
|
+
return { error: `error: cannot resolve path: ${userPath} — ${e.message || e}` };
|
|
78
|
+
}
|
|
79
|
+
for (const bad of SENSITIVE_PATHS) {
|
|
80
|
+
if (real === bad || real.endsWith(bad)) {
|
|
81
|
+
return { error: `error: refused sensitive path: ${userPath}` };
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
const roots = await logAllowedRoots();
|
|
85
|
+
if (!roots.some((r) => underRoot(real, r))) {
|
|
86
|
+
return { error: `error: path escape: ${userPath} is outside allowed roots (your home, the powertools root, or the Operator home)` };
|
|
87
|
+
}
|
|
88
|
+
return { path: real };
|
|
89
|
+
}
|
|
90
|
+
function applescriptString(s) {
|
|
91
|
+
return `"${s.replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"`;
|
|
92
|
+
}
|
|
93
|
+
// ── health_check ─────────────────────────────────────────────────────────────
|
|
94
|
+
async function healthCheck(args) {
|
|
95
|
+
const url = str(args.url).trim();
|
|
96
|
+
if (!url)
|
|
97
|
+
return JSON.stringify({ ok: false, error: "url required" });
|
|
98
|
+
if (!/^https?:\/\//i.test(url)) {
|
|
99
|
+
return JSON.stringify({ ok: false, error: "only http(s) URLs allowed", url });
|
|
100
|
+
}
|
|
101
|
+
const expectStatus = Number(args.expect_status ?? 200);
|
|
102
|
+
const expect = Number.isFinite(expectStatus) ? Math.floor(expectStatus) : 200;
|
|
103
|
+
let timeoutMs = Number(args.timeout_ms ?? DEFAULT_TIMEOUT_MS);
|
|
104
|
+
if (!Number.isFinite(timeoutMs) || timeoutMs <= 0)
|
|
105
|
+
timeoutMs = DEFAULT_TIMEOUT_MS;
|
|
106
|
+
timeoutMs = Math.min(Math.floor(timeoutMs), MAX_TIMEOUT_MS);
|
|
107
|
+
const ctrl = new AbortController();
|
|
108
|
+
const timer = setTimeout(() => ctrl.abort(), timeoutMs);
|
|
109
|
+
const started = Date.now();
|
|
110
|
+
try {
|
|
111
|
+
const res = await fetch(url, {
|
|
112
|
+
method: "GET",
|
|
113
|
+
signal: ctrl.signal,
|
|
114
|
+
redirect: "follow",
|
|
115
|
+
headers: { "User-Agent": "operator/health_check" },
|
|
116
|
+
});
|
|
117
|
+
const latency_ms = Date.now() - started;
|
|
118
|
+
const raw = await res.text().catch(() => "");
|
|
119
|
+
const truncated = raw.length > BODY_CAP;
|
|
120
|
+
const body = truncated ? raw.slice(0, BODY_CAP) : raw;
|
|
121
|
+
const ok = res.status === expect;
|
|
122
|
+
return JSON.stringify({
|
|
123
|
+
ok,
|
|
124
|
+
status: res.status,
|
|
125
|
+
expect_status: expect,
|
|
126
|
+
latency_ms,
|
|
127
|
+
truncated,
|
|
128
|
+
body,
|
|
129
|
+
...(ok ? {} : { error: `expected status ${expect}, got ${res.status}` }),
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
catch (e) {
|
|
133
|
+
const latency_ms = Date.now() - started;
|
|
134
|
+
const m = e instanceof Error ? e.message : String(e);
|
|
135
|
+
const timedOut = /abort/i.test(m);
|
|
136
|
+
return JSON.stringify({
|
|
137
|
+
ok: false,
|
|
138
|
+
error: timedOut ? `timed out after ${timeoutMs}ms` : m,
|
|
139
|
+
url,
|
|
140
|
+
latency_ms,
|
|
141
|
+
expect_status: expect,
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
finally {
|
|
145
|
+
clearTimeout(timer);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
// ── log_tail ─────────────────────────────────────────────────────────────────
|
|
149
|
+
async function logTail(args) {
|
|
150
|
+
const userPath = str(args.path);
|
|
151
|
+
const lines = clampInt(args.lines, DEFAULT_TAIL_LINES, HARD_TAIL_LINES);
|
|
152
|
+
const resolved = await resolveLogPath(userPath);
|
|
153
|
+
if ("error" in resolved)
|
|
154
|
+
return resolved.error;
|
|
155
|
+
try {
|
|
156
|
+
const fs = await nodeImport("node:fs/promises");
|
|
157
|
+
const text = await fs.readFile(resolved.path, "utf8");
|
|
158
|
+
const all = text.split(/\r?\n/);
|
|
159
|
+
if (all.length && all[all.length - 1] === "")
|
|
160
|
+
all.pop();
|
|
161
|
+
const slice = all.slice(-lines);
|
|
162
|
+
return slice.join("\n") || "(empty)";
|
|
163
|
+
}
|
|
164
|
+
catch (e) {
|
|
165
|
+
return `error: cannot read ${userPath}: ${e.message || e}`;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
// ── process_snapshot ─────────────────────────────────────────────────────────
|
|
169
|
+
async function findPs() {
|
|
170
|
+
const { access } = await nodeImport("node:fs/promises");
|
|
171
|
+
const { constants } = await nodeImport("node:fs");
|
|
172
|
+
for (const bin of PS_BINS) {
|
|
173
|
+
try {
|
|
174
|
+
await access(bin, constants.X_OK);
|
|
175
|
+
return bin;
|
|
176
|
+
}
|
|
177
|
+
catch { /* next */ }
|
|
178
|
+
}
|
|
179
|
+
return null;
|
|
180
|
+
}
|
|
181
|
+
async function processSnapshot(args) {
|
|
182
|
+
const name = args.name != null ? str(args.name) : "";
|
|
183
|
+
if (name && (name.length > 64 || /[\0\n]/.test(name))) {
|
|
184
|
+
return "error: name must be a short string (no newlines)";
|
|
185
|
+
}
|
|
186
|
+
const limit = clampInt(args.max_results, DEFAULT_PS_MAX, HARD_PS_MAX);
|
|
187
|
+
const bin = await findPs();
|
|
188
|
+
if (!bin)
|
|
189
|
+
return "error: ps binary not found";
|
|
190
|
+
try {
|
|
191
|
+
const { stdout } = await pexecFile(bin, [...PS_ARGV], {
|
|
192
|
+
encoding: "utf8",
|
|
193
|
+
env: {}, // cleared — no secret exfil via child env
|
|
194
|
+
maxBuffer: 2 * 1024 * 1024,
|
|
195
|
+
timeout: 10_000,
|
|
196
|
+
});
|
|
197
|
+
let rows = String(stdout || "").split("\n").filter((l) => l.trim());
|
|
198
|
+
if (name) {
|
|
199
|
+
const needle = name.toLowerCase();
|
|
200
|
+
rows = rows.filter((l) => l.toLowerCase().includes(needle));
|
|
201
|
+
}
|
|
202
|
+
const truncated = rows.length > limit;
|
|
203
|
+
if (truncated)
|
|
204
|
+
rows = rows.slice(0, limit);
|
|
205
|
+
const body = rows.join("\n") || "(no matching processes)";
|
|
206
|
+
return truncated ? `${body}\n[truncated: showing ${limit} lines]` : body;
|
|
207
|
+
}
|
|
208
|
+
catch (e) {
|
|
209
|
+
return `error: ps failed: ${e.message || e.stderr || e}`;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
// ── notify_local ─────────────────────────────────────────────────────────────
|
|
213
|
+
async function notifyLocal(args) {
|
|
214
|
+
let title = str(args.title, "Operator").trim() || "Operator";
|
|
215
|
+
let body = str(args.body).trim();
|
|
216
|
+
if (!body)
|
|
217
|
+
return "error: body required";
|
|
218
|
+
if (title.length > TITLE_CAP)
|
|
219
|
+
title = title.slice(0, TITLE_CAP);
|
|
220
|
+
if (body.length > BODY_NOTIFY_CAP)
|
|
221
|
+
body = body.slice(0, BODY_NOTIFY_CAP);
|
|
222
|
+
if (process.platform === "darwin") {
|
|
223
|
+
const script = `display notification ${applescriptString(body)} with title ${applescriptString(title)}`;
|
|
224
|
+
try {
|
|
225
|
+
await pexecFile("/usr/bin/osascript", ["-e", script], {
|
|
226
|
+
encoding: "utf8",
|
|
227
|
+
env: {},
|
|
228
|
+
timeout: 5_000,
|
|
229
|
+
});
|
|
230
|
+
return `notified (macos): ${title}`;
|
|
231
|
+
}
|
|
232
|
+
catch (e) {
|
|
233
|
+
// fall through to log on osascript failure
|
|
234
|
+
const msg = e.message || String(e);
|
|
235
|
+
return appendNotifyLog(title, body, `osascript failed (${msg}); logged`);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
return appendNotifyLog(title, body, "logged");
|
|
239
|
+
}
|
|
240
|
+
async function appendNotifyLog(title, body, how) {
|
|
241
|
+
const { operatorPath } = await import("../config/home.js");
|
|
242
|
+
const fs = await nodeImport("node:fs/promises");
|
|
243
|
+
const file = operatorPath("notifications.log");
|
|
244
|
+
const line = `${new Date().toISOString()}\t${title}\t${body.replace(/\n/g, " ")}\n`;
|
|
245
|
+
try {
|
|
246
|
+
await fs.mkdir(await (await nodeImport("node:path")).dirname(file), { recursive: true });
|
|
247
|
+
await fs.appendFile(file, line, "utf8");
|
|
248
|
+
return `notified (${how}): ${title} → ${file}`;
|
|
249
|
+
}
|
|
250
|
+
catch (e) {
|
|
251
|
+
return `error: notify log write failed: ${e.message || e}`;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
export const MONITORING_TOOLS = [
|
|
255
|
+
{
|
|
256
|
+
name: "health_check", safe: true,
|
|
257
|
+
description: "HTTP(S) GET health probe of a URL. Returns JSON with status, latency_ms, and a truncated body (2 KiB). " +
|
|
258
|
+
"Default timeout 3s (max 15s). Optional expect_status (default 200). Rejects non-http(s) URLs.",
|
|
259
|
+
parameters: {
|
|
260
|
+
type: "object",
|
|
261
|
+
properties: {
|
|
262
|
+
url: { type: "string", description: "http(s) URL to GET" },
|
|
263
|
+
expect_status: { type: "number", description: "expected HTTP status (default 200)" },
|
|
264
|
+
timeout_ms: { type: "number", description: "timeout in ms (default 3000, max 15000)" },
|
|
265
|
+
},
|
|
266
|
+
required: ["url"],
|
|
267
|
+
},
|
|
268
|
+
run: healthCheck,
|
|
269
|
+
},
|
|
270
|
+
{
|
|
271
|
+
name: "log_tail", safe: true,
|
|
272
|
+
description: "Read the last N lines of a log file (default 80, hard cap 500). Path is realpath'd and must stay " +
|
|
273
|
+
"under $HOME (or cwd), or under the powertools root or the Operator home when set. No shell. Sensitive system paths refused.",
|
|
274
|
+
parameters: {
|
|
275
|
+
type: "object",
|
|
276
|
+
properties: {
|
|
277
|
+
path: { type: "string", description: "file path to tail" },
|
|
278
|
+
lines: { type: "number", description: "lines from end (default 80, max 500)" },
|
|
279
|
+
},
|
|
280
|
+
required: ["path"],
|
|
281
|
+
},
|
|
282
|
+
run: logTail,
|
|
283
|
+
},
|
|
284
|
+
{
|
|
285
|
+
name: "process_snapshot", safe: true,
|
|
286
|
+
description: "Process table snapshot via ps with fixed columns (pid,ppid,user,pcpu,pmem,state,comm). " +
|
|
287
|
+
"Optional case-insensitive name substring filter applied in-process. max_results default 50 (hard 200). " +
|
|
288
|
+
"Native — works without the powertools MCP.",
|
|
289
|
+
parameters: {
|
|
290
|
+
type: "object",
|
|
291
|
+
properties: {
|
|
292
|
+
name: { type: "string", description: "optional case-insensitive substring of command name" },
|
|
293
|
+
max_results: { type: "number", description: "max lines after filter (default 50, hard 200)" },
|
|
294
|
+
},
|
|
295
|
+
},
|
|
296
|
+
run: processSnapshot,
|
|
297
|
+
},
|
|
298
|
+
{
|
|
299
|
+
name: "notify_local", safe: false,
|
|
300
|
+
description: "Local notification — macOS Notification Center via osascript, or append to operator notifications.log. " +
|
|
301
|
+
"Title/body length capped. Gated (safe:false).",
|
|
302
|
+
parameters: {
|
|
303
|
+
type: "object",
|
|
304
|
+
properties: {
|
|
305
|
+
title: { type: "string", description: "notification title (default Operator, max 100)" },
|
|
306
|
+
body: { type: "string", description: "notification body (required, max 500)" },
|
|
307
|
+
},
|
|
308
|
+
required: ["body"],
|
|
309
|
+
},
|
|
310
|
+
run: notifyLocal,
|
|
311
|
+
},
|
|
312
|
+
];
|
package/dist/tools/paths.js
CHANGED
|
@@ -17,3 +17,157 @@ export function expandPath(p) {
|
|
|
17
17
|
return home + p.slice(1);
|
|
18
18
|
return p;
|
|
19
19
|
}
|
|
20
|
+
/** Strip trailing slashes; keep "/" as "/". */
|
|
21
|
+
function normPath(p) {
|
|
22
|
+
if (!p)
|
|
23
|
+
return p;
|
|
24
|
+
const n = p.replace(/\/+$/, "");
|
|
25
|
+
return n || "/";
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Resolve a search path to an absolute string without node:path (neutral-safe).
|
|
29
|
+
* Relative paths join against `cwd` (default process.cwd()).
|
|
30
|
+
*/
|
|
31
|
+
export function resolveSearchPath(raw, cwd) {
|
|
32
|
+
const expanded = expandPath(raw || ".");
|
|
33
|
+
if (expanded.startsWith("/") || /^[A-Za-z]:[\\/]/.test(expanded))
|
|
34
|
+
return normPath(expanded);
|
|
35
|
+
const base = normPath(cwd ?? (typeof process !== "undefined" ? process.cwd() : ".")) || ".";
|
|
36
|
+
if (expanded === "." || expanded === "")
|
|
37
|
+
return base;
|
|
38
|
+
return normPath(`${base}/${expanded}`);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Hard gate for content search (`search` / `grep_search`): refuse scopes that walk the whole
|
|
42
|
+
* machine or the owner's home. Soft "never search ~" in the tool description is not enough —
|
|
43
|
+
* models still pass path=$HOME and hang for minutes (300s tool timeout). Point them at
|
|
44
|
+
* find_files (name index) or a narrow subtree instead.
|
|
45
|
+
*
|
|
46
|
+
* Returns an error string to surface to the model, or null when the scope is OK.
|
|
47
|
+
*/
|
|
48
|
+
export function assertContentSearchScope(rawPath, cwd) {
|
|
49
|
+
const abs = resolveSearchPath(rawPath || ".", cwd);
|
|
50
|
+
const home = normPath(process.env.HOME ?? process.env.USERPROFILE ?? "");
|
|
51
|
+
// Top-level roots that always mean "search the world".
|
|
52
|
+
const BROAD = new Set([
|
|
53
|
+
"/",
|
|
54
|
+
"/Users",
|
|
55
|
+
"/home",
|
|
56
|
+
"/private",
|
|
57
|
+
"/var",
|
|
58
|
+
"/private/var",
|
|
59
|
+
"/tmp",
|
|
60
|
+
"/private/tmp",
|
|
61
|
+
"/System",
|
|
62
|
+
"/Library",
|
|
63
|
+
"/Applications",
|
|
64
|
+
]);
|
|
65
|
+
if (BROAD.has(abs) || (home && abs === home)) {
|
|
66
|
+
return (`error: content search refused at "${rawPath || "."}" (resolves to ${abs}) — that scope is ` +
|
|
67
|
+
`home/machine-wide and will hang for minutes. For a FILE/PROJECT NAME use find_files ` +
|
|
68
|
+
`{"query":"…"}. For CONTENT, pass a narrow path (cwd subtree, ~/work/<repo>, ~/.axe/repos/<name>). ` +
|
|
69
|
+
`For a fleet host/box (e.g. acropolis): read ~/.ssh/config, \`gh repo view\`, AGENTS.md — ` +
|
|
70
|
+
`do not ripgrep $HOME.`);
|
|
71
|
+
}
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
const SHELL_REFUSE_MSG = "error: shell content search refused — recursive grep/rg/find over $HOME (or /, /Users, /tmp) " +
|
|
75
|
+
"hangs for minutes. Use the `search` tool with a narrow path, or find_files for names. " +
|
|
76
|
+
"For a fleet host/box: ~/.ssh/config → gh repo view → AGENTS.md. Do not bypass with bash.";
|
|
77
|
+
/**
|
|
78
|
+
* Heuristic gate for bash / shell_exec / shell_background: catch the common bypass where the model
|
|
79
|
+
* is refused by `search(path=$HOME)` and retries via `grep -r … ~` / `rg … $HOME` / unbounded `find ~`.
|
|
80
|
+
* Conservative — only fires on recursive content tools aimed at a broad root, not every mention of HOME.
|
|
81
|
+
*/
|
|
82
|
+
export function assertShellHomeWideSearch(command) {
|
|
83
|
+
if (!command || !command.trim())
|
|
84
|
+
return null;
|
|
85
|
+
const home = normPath(process.env.HOME ?? process.env.USERPROFILE ?? "");
|
|
86
|
+
// Normalize absolute home + ~ + $HOME spellings so one matcher covers all.
|
|
87
|
+
let c = command;
|
|
88
|
+
if (home) {
|
|
89
|
+
// Escape for literal split; replace all occurrences with the token $HOME.
|
|
90
|
+
c = c.split(home).join("$HOME");
|
|
91
|
+
}
|
|
92
|
+
c = c.replace(/(^|[\s"'=(])~(?=\/|[\s"')|;&#`$]|$)/g, "$1$HOME");
|
|
93
|
+
c = c.replace(/\$\{HOME\}/g, "$HOME");
|
|
94
|
+
// Bare roots only — `$HOME/work/foo` must still be allowed. Trailing slash OK; a subpath is not.
|
|
95
|
+
// (Avoid template literals here — a backtick in the char class would terminate them.)
|
|
96
|
+
const bare = "(?:^|[\\s\"'=(])(?:\\$HOME|/Users|/home|/tmp|/)\\/?(?=[\\s\"')|;&#`]|$)";
|
|
97
|
+
const hasBareBroadRoot = new RegExp(bare).test(c);
|
|
98
|
+
if (!hasBareBroadRoot)
|
|
99
|
+
return null;
|
|
100
|
+
// grep/egrep/fgrep with a recursive flag (-r, -R, or combined like -rn / -rni).
|
|
101
|
+
const isRecursiveGrep = /\b(?:grep|egrep|fgrep|ggrep)\b/.test(c) &&
|
|
102
|
+
/(?:^|\s)-[A-Za-z0-9-]*[rR][A-Za-z0-9-]*(?:\s|=|$)/.test(c);
|
|
103
|
+
const isRg = /\brg\b/.test(c);
|
|
104
|
+
// find $HOME / /Users without a tight maxdepth (1–3) — the classic hang.
|
|
105
|
+
const isFindHome = /\bfind\b/.test(c) &&
|
|
106
|
+
!/-maxdepth\s+[123]\b/.test(c);
|
|
107
|
+
if (isRecursiveGrep || isRg || isFindHome)
|
|
108
|
+
return SHELL_REFUSE_MSG;
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
export const BLIND_DOWNLOAD_MSG = "refused: `curl … -o/-O <file>` without `-f` / `--fail` (or `--fail-with-body`) saves an HTTP error page as if it were the file, and " +
|
|
112
|
+
"a silent `-s` hides that it happened — the 0-byte / HTML-instead-of-ISO failure. Use the `download_file` tool " +
|
|
113
|
+
"(fails loudly, resumes, retries, verifies size/sha256, never leaves a half file), or add `-f` (and `--retry 5 -C -`) " +
|
|
114
|
+
"and check the size afterwards. Run long transfers with shell_background or download_file, one at a time.";
|
|
115
|
+
/**
|
|
116
|
+
* Hard gate for bash / shell_exec / shell_background: a `curl` that writes to a FILE without failing on HTTP errors.
|
|
117
|
+
* Soft persona guidance did not stop the model; this does. Conservative — a response written to /dev/null or stdout,
|
|
118
|
+
* `curl … | jq`, and `curl -fsSL -o f url` all pass.
|
|
119
|
+
*/
|
|
120
|
+
export function assertShellBlindDownload(command) {
|
|
121
|
+
if (!command || !/\bcurl\b/.test(command))
|
|
122
|
+
return null;
|
|
123
|
+
// Split on shell separators so `curl -f … && curl -o f …` is judged per command.
|
|
124
|
+
for (const seg of command.split(/&&|\|\||;|\||\n|&(?!>)/)) {
|
|
125
|
+
const toks = seg.trim().split(/\s+/);
|
|
126
|
+
// The command word: skip `VAR=val`, sudo/nohup/time/command and `timeout N` so `echo "use curl -o x"` is not mistaken for a curl.
|
|
127
|
+
let k = 0;
|
|
128
|
+
while (k < toks.length && (/^[A-Za-z_][A-Za-z0-9_]*=/.test(toks[k]) || ["sudo", "nohup", "time", "command", "exec"].includes(toks[k]) || (toks[k] === "timeout" && ++k)))
|
|
129
|
+
k++;
|
|
130
|
+
if (!(toks[k] === "curl" || toks[k]?.endsWith("/curl")))
|
|
131
|
+
continue;
|
|
132
|
+
const args = toks.slice(k + 1);
|
|
133
|
+
let toFile = false;
|
|
134
|
+
let fails = false;
|
|
135
|
+
for (let i = 0; i < args.length; i++) {
|
|
136
|
+
const a = args[i];
|
|
137
|
+
if (a === "-O" || a === "--remote-name" || a === "--remote-name-all") {
|
|
138
|
+
toFile = true;
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
if (a === "-o" || a === "--output") {
|
|
142
|
+
const target = args[i + 1] ?? "";
|
|
143
|
+
if (target !== "/dev/null" && target !== "-" && target !== "NUL")
|
|
144
|
+
toFile = true;
|
|
145
|
+
i++;
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
if (/^--output=/.test(a)) {
|
|
149
|
+
if (!/^--output=(\/dev\/null|-|NUL)$/.test(a))
|
|
150
|
+
toFile = true;
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
if (a === "--fail" || a === "--fail-with-body" || a === "--fail-early") {
|
|
154
|
+
fails = true;
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
// combined short flags: -fsSL, -sfL, -fL … ; an arg that is -o/-O fused (-sLo file) also writes to a file
|
|
158
|
+
if (/^-[A-Za-z]+$/.test(a)) {
|
|
159
|
+
if (a.includes("f"))
|
|
160
|
+
fails = true;
|
|
161
|
+
if (a.includes("O"))
|
|
162
|
+
toFile = true;
|
|
163
|
+
if (a.endsWith("o") && a.length > 2) {
|
|
164
|
+
toFile = !/^(\/dev\/null|-|NUL)$/.test(args[i + 1] ?? "");
|
|
165
|
+
i++;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
if (toFile && !fails)
|
|
170
|
+
return BLIND_DOWNLOAD_MSG;
|
|
171
|
+
}
|
|
172
|
+
return null;
|
|
173
|
+
}
|