@0perator/operator 0.1.359-next.0 → 0.1.360-next.0
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/dashboard/index.html +2 -2
- package/dist/autonomy/cloud-agent.js +2 -2
- package/dist/autonomy/headless.js +15 -6
- package/dist/autonomy/session-factory.js +2 -1
- package/dist/background/notices.js +1 -1
- package/dist/browser/session.js +7 -0
- package/dist/cli.js +94 -52
- package/dist/config/features.js +6 -5
- package/dist/config/persona.js +57 -40
- package/dist/config/settings.js +39 -55
- package/dist/engine/agent.js +72 -33
- package/dist/engine/aurora.js +24 -2
- package/dist/engine/compaction.js +27 -7
- package/dist/engine/decision-points.js +16 -4
- package/dist/engine/kv-slot.js +87 -0
- package/dist/engine/loop-guard.js +49 -18
- package/dist/engine/messages.js +8 -1
- package/dist/engine/progress-deadline.js +37 -0
- package/dist/engine/verify-gate.js +134 -9
- package/dist/enterprise/cli.js +13 -1
- package/dist/mcp/craft-server.js +5 -3
- package/dist/memory/live-progress.js +35 -6
- package/dist/permissions/policy.js +8 -0
- package/dist/permissions/signature.js +9 -0
- package/dist/products/artifact-library.js +47 -0
- package/dist/products/craft.js +58 -94
- package/dist/products/temple.js +230 -0
- package/dist/remote/host.js +28 -1
- package/dist/router/discovery.js +23 -6
- package/dist/router/models.js +29 -70
- package/dist/services/preflight.js +3 -41
- package/dist/session.js +121 -38
- package/dist/skills/catalogue.js +2 -0
- package/dist/skills/finder.js +1 -1
- package/dist/tools/background-result.js +26 -0
- package/dist/tools/chauffeur-native.js +6 -0
- package/dist/tools/craft.js +17 -6
- package/dist/tools/deferred.js +64 -30
- package/dist/tools/executor.js +4 -2
- package/dist/tools/paths.js +3 -3
- package/dist/tools/read-ledger.js +44 -0
- package/dist/tools/registry.js +218 -264
- package/dist/tools/sandbox.js +52 -39
- package/dist/tools/shell-context.js +5 -0
- package/dist/tools/shell-session.js +61 -29
- package/dist/tools/vision-gateway.js +79 -34
- package/dist/tools/wave-tools.js +2 -2
- package/dist/tools/wave2-tools.js +6 -6
- package/dist/ui/ArtifactPicker.js +2 -2
- package/dist/ui/Composer.js +9 -2
- package/dist/ui/StatusRule.js +1 -1
- package/dist/ui/modelPicker.js +1 -1
- package/dist/ui/nextStep.js +1 -0
- package/dist/ui/pending.js +10 -0
- package/dist/update.js +78 -4
- package/dist/util/retry.js +34 -0
- package/dist/util/slash.js +2 -1
- package/dist/vault/tool.js +3 -1
- package/mcp/powertools-toolbox.mjs +166 -1
- package/package.json +9 -13
- package/dashboard/README.md +0 -62
- package/dist/compose/client.js +0 -56
- package/mcp/README.md +0 -88
- package/mcp/powertools.md +0 -210
package/dist/update.js
CHANGED
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
// `operator update` — self-update (bareword, like a CLI self-updater). Two install shapes:
|
|
2
|
-
// •
|
|
3
|
-
// releases, the default and `--latest`) or
|
|
2
|
+
// • packaged → the published package. update = the channel's build from the public download URL (the one
|
|
3
|
+
// install.sh uses), sha256-verified: `latest` (main's releases, the default and `--latest`) or `next`
|
|
4
|
+
// (`--next`: 0.1.N-next.K prereleases from develop). When that URL can't be reached, the npm
|
|
5
|
+
// registry's dist-tag of the same name, as before.
|
|
4
6
|
// • source/dev → a git checkout linked via `npm link`; update = pull + rebuild.
|
|
5
7
|
// We detect the shape from where THIS module resolves: a checkout still has a .git above it;
|
|
6
8
|
// a global install lives under a node_modules tree with no repo around it.
|
|
7
9
|
import { spawnSync, execSync } from "node:child_process";
|
|
8
|
-
import {
|
|
10
|
+
import { createHash } from "node:crypto";
|
|
11
|
+
import { existsSync, mkdtempSync, readFileSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
|
|
12
|
+
import { homedir, tmpdir } from "node:os";
|
|
9
13
|
import { dirname, join, resolve } from "node:path";
|
|
10
14
|
import { fileURLToPath } from "node:url";
|
|
11
15
|
const PKG = "@0perator/operator"; // published (private) scope/name — keep in sync with package.json
|
|
16
|
+
const DIST_BASE = "https://0perator.co/dl"; // latest.txt, next.txt, SHA256SUMS, operator-<version>.tgz (docs/INSTALL-CURL.md)
|
|
17
|
+
// An install made by install.sh: <root>/releases/<version>/node_modules/@0perator/operator, linked into a bin folder.
|
|
18
|
+
const RELEASE_PKG = /^(.*)\/releases\/[^/]+\/node_modules\/@0perator\/operator\/package\.json$/;
|
|
12
19
|
/** `--next` or `--latest` (the default); `explicit` says a flag picked it. Both flags is a usage error. */
|
|
13
20
|
export function updateChannel(args) {
|
|
14
21
|
const next = args.includes("--next"), latest = args.includes("--latest");
|
|
@@ -98,6 +105,73 @@ export function installChannel(channel, pkgJson = fileURLToPath(new URL("../pack
|
|
|
98
105
|
process.stderr.write(`operator update: done — now v${now} (${channel}).\n`);
|
|
99
106
|
return 0;
|
|
100
107
|
}
|
|
108
|
+
async function download(url, ms) {
|
|
109
|
+
const res = await fetch(url, { signal: AbortSignal.timeout(ms) });
|
|
110
|
+
if (!res.ok)
|
|
111
|
+
throw new Error(`${url} answered ${res.status}`);
|
|
112
|
+
return Buffer.from(await res.arrayBuffer());
|
|
113
|
+
}
|
|
114
|
+
/** Packaged update from the public download URL: the channel's version, its tarball, and the sha256 that SHA256SUMS
|
|
115
|
+
* lists for it. A mismatch installs nothing and exits 1. An install.sh install gets a new release folder beside the
|
|
116
|
+
* old ones (kept for rollback) and its bin link moved; any other install is replaced in place by `npm install -g`.
|
|
117
|
+
* Returns null, having installed nothing, when the URL can't be reached and the registry can stand in (not for an
|
|
118
|
+
* install.sh install, which exits 1 instead). */
|
|
119
|
+
export async function installFromDist(channel, pkgJson = fileURLToPath(new URL("../package.json", import.meta.url)), base = process.env.OPERATOR_DIST_BASE || DIST_BASE) {
|
|
120
|
+
const current = versionAt(pkgJson) ?? "?";
|
|
121
|
+
const release = RELEASE_PKG.exec(pkgJson);
|
|
122
|
+
let target, tarball, sums;
|
|
123
|
+
try {
|
|
124
|
+
target = (await download(`${base}/${channel}.txt`, 15_000)).toString("utf8").trim();
|
|
125
|
+
if (!/^0\.1\.\d+(-next\.\d+)?$/.test(target))
|
|
126
|
+
throw new Error(`${base}/${channel}.txt is not a version`);
|
|
127
|
+
if (target === current) {
|
|
128
|
+
process.stderr.write(`operator update: already on v${current} (${channel}).\n`);
|
|
129
|
+
return 0;
|
|
130
|
+
}
|
|
131
|
+
[tarball, sums] = await Promise.all([
|
|
132
|
+
download(`${base}/operator-${target}.tgz`, 300_000),
|
|
133
|
+
download(`${base}/SHA256SUMS`, 15_000).then((b) => b.toString("utf8")),
|
|
134
|
+
]);
|
|
135
|
+
}
|
|
136
|
+
catch (e) {
|
|
137
|
+
// The registry would install somewhere else than an install.sh release folder, so only other installs fall back.
|
|
138
|
+
process.stderr.write(`operator update: can't download from ${base} (${e instanceof Error ? e.message : e}) — ${release ? "nothing installed" : "using the npm registry"}.\n`);
|
|
139
|
+
return release ? 1 : null;
|
|
140
|
+
}
|
|
141
|
+
const name = `operator-${target}.tgz`;
|
|
142
|
+
const want = sums.split("\n").map((l) => l.trim().split(/\s+/)).find((p) => p[1] === name)?.[0];
|
|
143
|
+
const got = createHash("sha256").update(tarball).digest("hex");
|
|
144
|
+
if (want !== got) {
|
|
145
|
+
process.stderr.write(`operator update: checksum mismatch for ${name} (expected ${want ?? "none published"}, got ${got}) — nothing installed.\n`);
|
|
146
|
+
return 1;
|
|
147
|
+
}
|
|
148
|
+
process.stderr.write(`operator update: v${current} (${channelOf(current)}) → v${target} (${channel}), checksum verified\n`);
|
|
149
|
+
const dest = release ? join(release[1], "releases", target) : "";
|
|
150
|
+
const tmp = mkdtempSync(join(tmpdir(), "operator-update-"));
|
|
151
|
+
let code;
|
|
152
|
+
try {
|
|
153
|
+
writeFileSync(join(tmp, name), tarball);
|
|
154
|
+
code = release
|
|
155
|
+
? run("npm", ["install", "--silent", "--no-fund", "--no-audit", "--prefix", dest, join(tmp, name)])
|
|
156
|
+
: run("npm", ["install", "-g", join(tmp, name)]);
|
|
157
|
+
}
|
|
158
|
+
finally {
|
|
159
|
+
rmSync(tmp, { recursive: true, force: true });
|
|
160
|
+
}
|
|
161
|
+
const installed = release ? join(dest, "node_modules", "@0perator", "operator", "package.json") : pkgJson;
|
|
162
|
+
const now = code === 0 ? versionAt(installed) : undefined;
|
|
163
|
+
if (now !== target) {
|
|
164
|
+
process.stderr.write(`operator update: failed — npm exited ${code} and ${dirname(installed)} is v${now ?? "?"}, not v${target}. This operator is unchanged.\n`);
|
|
165
|
+
return code || 1;
|
|
166
|
+
}
|
|
167
|
+
if (release) {
|
|
168
|
+
const link = join(process.env.OPERATOR_BIN_DIR || join(homedir(), ".local", "bin"), "operator");
|
|
169
|
+
rmSync(link, { force: true });
|
|
170
|
+
symlinkSync(join(dest, "node_modules", ".bin", "operator"), link);
|
|
171
|
+
}
|
|
172
|
+
process.stderr.write(`operator update: done — now v${now} (${channel}).\n`);
|
|
173
|
+
return 0;
|
|
174
|
+
}
|
|
101
175
|
export async function runUpdate(args = []) {
|
|
102
176
|
const pick = updateChannel(args);
|
|
103
177
|
if ("error" in pick) {
|
|
@@ -157,5 +231,5 @@ export async function runUpdate(args = []) {
|
|
|
157
231
|
}
|
|
158
232
|
return code;
|
|
159
233
|
}
|
|
160
|
-
return installChannel(pick.channel);
|
|
234
|
+
return (await installFromDist(pick.channel)) ?? installChannel(pick.channel);
|
|
161
235
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// Retry for a route that refuses instead of queueing: the router answers a full or restarting leg with an
|
|
2
|
+
// instant 503, and the next request a moment later succeeds. One helper for every capability route (vision
|
|
3
|
+
// today; voice, image and video next). Neutral: no node imports, time and randomness are injected.
|
|
4
|
+
/** Three attempts, waits of 1–2 s then 2–4 s: at most ~6 s on one target. */
|
|
5
|
+
export const ROUTE_RETRY = { attempts: 3, baseMs: 2_000, capMs: 4_000 };
|
|
6
|
+
export const realClock = { now: Date.now, sleep: (ms) => new Promise((r) => setTimeout(r, ms)), random: Math.random };
|
|
7
|
+
/** The wait after failed attempt `n` (1-based): capped exponential, jittered into its upper half so retries
|
|
8
|
+
* from several sessions spread out without ever collapsing to zero. */
|
|
9
|
+
export function backoffMs(n, p, random) {
|
|
10
|
+
const ceiling = Math.min(p.capMs, p.baseMs * 2 ** (n - 1));
|
|
11
|
+
return Math.round(ceiling * (0.5 + 0.5 * random));
|
|
12
|
+
}
|
|
13
|
+
/** A Retry-After header (seconds, or an HTTP date) as milliseconds from `now`; undefined when absent or unreadable. */
|
|
14
|
+
export function retryAfterMs(header, now) {
|
|
15
|
+
if (!header?.trim())
|
|
16
|
+
return undefined;
|
|
17
|
+
const seconds = Number(header);
|
|
18
|
+
const ms = Number.isFinite(seconds) ? seconds * 1_000 : Date.parse(header) - now;
|
|
19
|
+
return Number.isFinite(ms) ? Math.max(0, ms) : undefined;
|
|
20
|
+
}
|
|
21
|
+
/** Run `attempt` until it succeeds, fails for good, or the policy or `deadline` (epoch ms) ends it. A wait
|
|
22
|
+
* that would cross the deadline, or a Retry-After longer than the policy's cap, ends it at once: the caller
|
|
23
|
+
* has somewhere better to go than to sit out a target that said it will not be ready. */
|
|
24
|
+
export async function retry(attempt, o, clock = realClock) {
|
|
25
|
+
for (let n = 1;; n++) {
|
|
26
|
+
const result = await attempt(n);
|
|
27
|
+
if ("ok" in result || !result.retry || n >= o.attempts)
|
|
28
|
+
return { result, attempts: n };
|
|
29
|
+
const wait = result.retryAfterMs ?? backoffMs(n, o, clock.random());
|
|
30
|
+
if (wait > o.capMs || clock.now() + wait >= o.deadline)
|
|
31
|
+
return { result, attempts: n };
|
|
32
|
+
await clock.sleep(wait);
|
|
33
|
+
}
|
|
34
|
+
}
|
package/dist/util/slash.js
CHANGED
|
@@ -23,9 +23,10 @@ export function isSlashCommand(text) {
|
|
|
23
23
|
export const MIDTURN = {
|
|
24
24
|
help: "now", agents: "now", jobs: "now", stats: "now", endpoints: "now", audit: "now", memory: "now", skills: "now",
|
|
25
25
|
skill: "now", whoami: "now", monitor: "now", remember: "now", caffeinate: "now", caffeine: "now", bg: "now", dashboard: "now",
|
|
26
|
+
remote: "now", remotecontrol: "now", rc: "now", pair: "now",
|
|
26
27
|
think: "next", ultrathink: "next", context: "next", ctx: "next", mode: "next", plan: "next", allow: "next",
|
|
27
28
|
model: "after", new: "after", compact: "after", clear: "after", route: "after", mcp: "after", login: "after", logout: "after",
|
|
28
|
-
|
|
29
|
+
sessions: "after", artifacts: "after", services: "after",
|
|
29
30
|
"deep-research": "after", deepresearch: "after", research: "after", exit: "after", quit: "after",
|
|
30
31
|
};
|
|
31
32
|
/** The mid-turn class of a slash command line (its first token); "after" for anything unclassified — the safe side. */
|
package/dist/vault/tool.js
CHANGED
|
@@ -20,13 +20,15 @@ export async function runBrowserVault(args, deps) {
|
|
|
20
20
|
}
|
|
21
21
|
if (action === "fill") {
|
|
22
22
|
const handle = String(args.handle ?? "");
|
|
23
|
+
if (!handle)
|
|
24
|
+
return "vault fill needs `handle` — a handle from browser_vault list";
|
|
23
25
|
const item = vaultGet(handle);
|
|
24
26
|
if (!item)
|
|
25
27
|
return `vault: no item '${handle}' (see browser_vault list — never guess credentials)`;
|
|
26
28
|
const userSel = String(args.user_selector ?? "");
|
|
27
29
|
const passSel = String(args.password_selector ?? "");
|
|
28
30
|
if (!userSel || !passSel)
|
|
29
|
-
return "vault fill needs user_selector
|
|
31
|
+
return "vault fill needs `user_selector` and `password_selector` (CSS, e.g. \"#email\", \"#password\") — read the page first";
|
|
30
32
|
let href;
|
|
31
33
|
try {
|
|
32
34
|
href = await deps.activeHref();
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import { spawn } from "node:child_process";
|
|
6
6
|
import { createHash } from "node:crypto";
|
|
7
7
|
import { readdir, stat, readFile, mkdir } from "node:fs/promises";
|
|
8
|
+
import { homedir } from "node:os";
|
|
8
9
|
import { join, extname } from "node:path";
|
|
9
10
|
|
|
10
11
|
const MAX_TREE_FILES = 500;
|
|
@@ -87,7 +88,7 @@ export function buildToolbox(S) {
|
|
|
87
88
|
scp: ["/usr/bin/scp", "/opt/homebrew/bin/scp"],
|
|
88
89
|
launchctl: ["/bin/launchctl"],
|
|
89
90
|
systemctl: ["/usr/bin/systemctl", "/bin/systemctl"],
|
|
90
|
-
docker: ["/usr/bin/docker", "/usr/local/bin/docker", "
|
|
91
|
+
docker: ["/usr/bin/docker", "/usr/local/bin/docker", join(homedir(), ".docker/bin/docker"), "/opt/homebrew/bin/docker"],
|
|
91
92
|
podman: ["/usr/bin/podman", "/opt/homebrew/bin/podman"],
|
|
92
93
|
git: ["/usr/bin/git", "/opt/homebrew/bin/git", "/usr/local/bin/git"],
|
|
93
94
|
npm: ["/opt/homebrew/bin/npm", "/usr/local/bin/npm"],
|
|
@@ -96,6 +97,8 @@ export function buildToolbox(S) {
|
|
|
96
97
|
biome: ["/opt/homebrew/bin/biome", "/usr/local/bin/biome"],
|
|
97
98
|
ruff: ["/opt/homebrew/bin/ruff", "/usr/local/bin/ruff"],
|
|
98
99
|
eslint: ["/opt/homebrew/bin/eslint", "/usr/local/bin/eslint"],
|
|
100
|
+
fswatch: ["/opt/homebrew/bin/fswatch", "/usr/local/bin/fswatch"],
|
|
101
|
+
inotifywait: ["/usr/bin/inotifywait", "/usr/local/bin/inotifywait"],
|
|
99
102
|
};
|
|
100
103
|
|
|
101
104
|
// Resolve bins into a local map (caller also merges into main BIN)
|
|
@@ -695,6 +698,103 @@ export function buildToolbox(S) {
|
|
|
695
698
|
return okText(JSON.stringify({ url, expect, failures, results }, null, 2));
|
|
696
699
|
}
|
|
697
700
|
|
|
701
|
+
// ── tree_walk: recursive file listing with hashes ──────────────────────
|
|
702
|
+
async function handleTreeWalk(args) {
|
|
703
|
+
const r = await resolveUnderRoot(args?.path || ".");
|
|
704
|
+
if (r.error) return errText(r.error);
|
|
705
|
+
const maxDepth = clampInt(args?.max_depth, 1, 50);
|
|
706
|
+
const maxResults = clampInt(args?.max_results, 1, MAX_TREE_FILES);
|
|
707
|
+
const includeHidden = args?.include_hidden === true;
|
|
708
|
+
const results = [];
|
|
709
|
+
const seen = new Set();
|
|
710
|
+
|
|
711
|
+
async function walk(dir, depth) {
|
|
712
|
+
if (depth > maxDepth || results.length >= maxResults) return;
|
|
713
|
+
const entries = await readdir(dir, { withFileTypes: true });
|
|
714
|
+
for (const entry of entries) {
|
|
715
|
+
if (results.length >= maxResults) break;
|
|
716
|
+
if (entry.name.startsWith(".") && !includeHidden) continue;
|
|
717
|
+
if (entry.name === ".git" || entry.name === "node_modules" || entry.name === ".venv") continue;
|
|
718
|
+
const fullPath = join(dir, entry.name);
|
|
719
|
+
if (seen.has(fullPath)) continue;
|
|
720
|
+
seen.add(fullPath);
|
|
721
|
+
try {
|
|
722
|
+
const st = await stat(fullPath);
|
|
723
|
+
if (st.isFile()) {
|
|
724
|
+
const hash = createHash("sha256");
|
|
725
|
+
const data = await readFile(fullPath);
|
|
726
|
+
hash.update(data);
|
|
727
|
+
results.push({
|
|
728
|
+
path: fullPath,
|
|
729
|
+
size: st.size,
|
|
730
|
+
mtime: st.mtime.toISOString(),
|
|
731
|
+
hash: hash.digest("hex"),
|
|
732
|
+
});
|
|
733
|
+
} else if (st.isDirectory()) {
|
|
734
|
+
await walk(fullPath, depth + 1);
|
|
735
|
+
}
|
|
736
|
+
} catch (e) {
|
|
737
|
+
// skip unreadable entries
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
await walk(r.path, 0);
|
|
743
|
+
return okText(JSON.stringify({ files: results.length, results }, null, 2));
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
// ── file_watch: watch for filesystem changes ──────────────────────────
|
|
747
|
+
async function handleFileWatch(args) {
|
|
748
|
+
const r = await resolveUnderRoot(args?.path || ".");
|
|
749
|
+
if (r.error) return errText(r.error);
|
|
750
|
+
const timeout = clampInt(args?.timeout_ms, 1000, 60000);
|
|
751
|
+
const recursive = args?.recursive !== false;
|
|
752
|
+
|
|
753
|
+
if (process.platform === "darwin") {
|
|
754
|
+
// FSEvents via fswatch (brew install fswatch). fs_usage is a root-only syscall tracer, not a path watcher.
|
|
755
|
+
const miss = need("fswatch");
|
|
756
|
+
if (miss) return miss;
|
|
757
|
+
// --one-event returns on the first change batch; a directory is watched recursively by default.
|
|
758
|
+
return runCapped(B.fswatch, ["--one-event", r.path], { timeoutMs: timeout, okCodes: [0, 143] });
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
// Linux: inotifywait (inotify-tools). Exit 2 = clean timeout with no event (not an error).
|
|
762
|
+
const miss = need("inotifywait");
|
|
763
|
+
if (miss) return miss;
|
|
764
|
+
const flags = recursive ? ["-r"] : [];
|
|
765
|
+
return runCapped(
|
|
766
|
+
B.inotifywait,
|
|
767
|
+
[...flags, "-t", String(Math.ceil(timeout / 1000)), "-e", "modify,create,delete,move", r.path],
|
|
768
|
+
{ timeoutMs: timeout + 2000, okCodes: [0, 2] },
|
|
769
|
+
);
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
// ── container_exec: docker/podman exec/start/stop ─────────────────────
|
|
773
|
+
async function handleContainerExec(args) {
|
|
774
|
+
if (!mutateAllowed()) return errText("error: container_exec requires POWERTOOLS_ALLOW_MUTATE=1");
|
|
775
|
+
const container = String(args?.container || "");
|
|
776
|
+
const action = String(args?.action || "");
|
|
777
|
+
if (!CONTAINER_RE.test(container)) return errText("error: invalid container name");
|
|
778
|
+
if (!["exec", "start", "stop", "restart", "kill"].includes(action)) return errText("error: action must be exec|start|stop|restart|kill");
|
|
779
|
+
|
|
780
|
+
// Check container allowlist
|
|
781
|
+
const allow = parseAllowlist(process.env.POWERTOOLS_CONTAINERS);
|
|
782
|
+
if (!allow.size) return errText("error: POWERTOOLS_CONTAINERS allowlist required");
|
|
783
|
+
if (!allow.has(container)) return errText(`error: container '${container}' not in POWERTOOLS_CONTAINERS`);
|
|
784
|
+
|
|
785
|
+
const runtime = String(args?.runtime || "docker");
|
|
786
|
+
const bin = runtime === "podman" ? B.podman : B.docker;
|
|
787
|
+
if (!bin) return errText(`error: binary '${runtime}' not installed (soft-miss)`);
|
|
788
|
+
|
|
789
|
+
if (action === "exec") {
|
|
790
|
+
const cmd = String(args?.command || "sh");
|
|
791
|
+
// Wrap in sh -c so multi-word commands work (a bare argv execs a binary literally named e.g. "ls -la").
|
|
792
|
+
return runCapped(bin, ["exec", container, "sh", "-c", cmd], { okCodes: [0, 1] });
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
return runCapped(bin, [action, container], { okCodes: [0, 1] });
|
|
796
|
+
}
|
|
797
|
+
|
|
698
798
|
const toolDefs = [
|
|
699
799
|
{
|
|
700
800
|
name: "file_info",
|
|
@@ -1101,6 +1201,71 @@ export function buildToolbox(S) {
|
|
|
1101
1201
|
},
|
|
1102
1202
|
handler: handleWatchHealthLoop,
|
|
1103
1203
|
},
|
|
1204
|
+
// ── tree_walk: recursive file listing with hashes ──────────────────────
|
|
1205
|
+
{
|
|
1206
|
+
name: "tree_walk",
|
|
1207
|
+
needs: [],
|
|
1208
|
+
def: {
|
|
1209
|
+
name: "tree_walk",
|
|
1210
|
+
description:
|
|
1211
|
+
"Recursively list files under POWERTOOLS_ROOT with sha256 hashes. " +
|
|
1212
|
+
"Skips symlinks and hidden files by default. " + UNTRUSTED,
|
|
1213
|
+
inputSchema: {
|
|
1214
|
+
type: "object",
|
|
1215
|
+
required: ["path"],
|
|
1216
|
+
properties: {
|
|
1217
|
+
path: { type: "string" },
|
|
1218
|
+
max_depth: { type: "number" },
|
|
1219
|
+
max_results: { type: "number" },
|
|
1220
|
+
include_hidden: { type: "boolean" },
|
|
1221
|
+
},
|
|
1222
|
+
},
|
|
1223
|
+
},
|
|
1224
|
+
handler: handleTreeWalk,
|
|
1225
|
+
},
|
|
1226
|
+
// ── file_watch: watch for filesystem changes ──────────────────────────
|
|
1227
|
+
{
|
|
1228
|
+
name: "file_watch",
|
|
1229
|
+
needs: [],
|
|
1230
|
+
def: {
|
|
1231
|
+
name: "file_watch",
|
|
1232
|
+
description:
|
|
1233
|
+
"Watch a path under POWERTOOLS_ROOT for changes. Uses FSEvents on macOS, inotify on Linux. " +
|
|
1234
|
+
"Returns list of changed files after timeout. " + UNTRUSTED,
|
|
1235
|
+
inputSchema: {
|
|
1236
|
+
type: "object",
|
|
1237
|
+
required: ["path"],
|
|
1238
|
+
properties: {
|
|
1239
|
+
path: { type: "string" },
|
|
1240
|
+
timeout_ms: { type: "number" },
|
|
1241
|
+
recursive: { type: "boolean" },
|
|
1242
|
+
},
|
|
1243
|
+
},
|
|
1244
|
+
},
|
|
1245
|
+
handler: handleFileWatch,
|
|
1246
|
+
},
|
|
1247
|
+
// ── container_exec: docker/podman exec/start/stop ─────────────────────
|
|
1248
|
+
{
|
|
1249
|
+
name: "container_exec",
|
|
1250
|
+
needs: [],
|
|
1251
|
+
def: {
|
|
1252
|
+
name: "container_exec",
|
|
1253
|
+
description:
|
|
1254
|
+
"Execute commands in docker/podman containers. Requires POWERTOOLS_ALLOW_MUTATE=1 + POWERTOOLS_CONTAINERS allowlist. " +
|
|
1255
|
+
"Supports exec, start, stop, restart, kill. " + UNTRUSTED,
|
|
1256
|
+
inputSchema: {
|
|
1257
|
+
type: "object",
|
|
1258
|
+
required: ["container", "action"],
|
|
1259
|
+
properties: {
|
|
1260
|
+
container: { type: "string" },
|
|
1261
|
+
action: { type: "string", enum: ["exec", "start", "stop", "restart", "kill"] },
|
|
1262
|
+
command: { type: "string" },
|
|
1263
|
+
runtime: { type: "string", enum: ["docker", "podman"] },
|
|
1264
|
+
},
|
|
1265
|
+
},
|
|
1266
|
+
},
|
|
1267
|
+
handler: handleContainerExec,
|
|
1268
|
+
},
|
|
1104
1269
|
];
|
|
1105
1270
|
|
|
1106
1271
|
// Filter soft-miss: tools with needs that aren't present are omitted
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@0perator/operator",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.360-next.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"bin": {
|
|
6
6
|
"operator": "dist/cli.js",
|
|
@@ -8,9 +8,13 @@
|
|
|
8
8
|
},
|
|
9
9
|
"files": [
|
|
10
10
|
"dist",
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"
|
|
11
|
+
"!dist/**/*.bak*",
|
|
12
|
+
"!dist/**/*.orig",
|
|
13
|
+
"!dist/**/*.map",
|
|
14
|
+
"dashboard/index.html",
|
|
15
|
+
"dashboard/server.mjs",
|
|
16
|
+
"mcp/*.mjs",
|
|
17
|
+
"mcp/ocr-macos.swift"
|
|
14
18
|
],
|
|
15
19
|
"engines": {
|
|
16
20
|
"node": ">=20"
|
|
@@ -47,15 +51,7 @@
|
|
|
47
51
|
"tsx": "^4.19.1",
|
|
48
52
|
"typescript": "^5.6.2"
|
|
49
53
|
},
|
|
50
|
-
"
|
|
51
|
-
"type": "git",
|
|
52
|
-
"url": "git+https://github.com/memjar/kode.git",
|
|
53
|
-
"directory": "kode-tsi"
|
|
54
|
-
},
|
|
55
|
-
"homepage": "https://github.com/memjar/kode/tree/main/kode-tsi#readme",
|
|
56
|
-
"bugs": {
|
|
57
|
-
"url": "https://github.com/memjar/kode/issues"
|
|
58
|
-
},
|
|
54
|
+
"homepage": "https://0perator.co",
|
|
59
55
|
"main": "dist/index.js",
|
|
60
56
|
"license": "SEE LICENSE IN LICENSE",
|
|
61
57
|
"private": false,
|
package/dashboard/README.md
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
# Swarm Console
|
|
2
|
-
|
|
3
|
-
Live observability dashboard for Operator agent sessions. Renders the human-supervision
|
|
4
|
-
surface for a swarm of Operator sessions: tool activity, token/turn throughput, tier
|
|
5
|
-
denials (security), remote-control state, and service health — all from the frozen
|
|
6
|
-
`OperatorEvent` wire shape (v1) in `kode-tsi/src/telemetry/events.ts`.
|
|
7
|
-
|
|
8
|
-
Zero dependencies — Node.js standard library only. No `npm install` needed.
|
|
9
|
-
|
|
10
|
-
## Run it
|
|
11
|
-
|
|
12
|
-
```
|
|
13
|
-
cd kode-tsi/dashboard
|
|
14
|
-
node server.mjs
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
Listens on port 8899 by default. Override with `PORT`:
|
|
18
|
-
|
|
19
|
-
```
|
|
20
|
-
PORT=9000 node server.mjs
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
Open `http://127.0.0.1:8899/` in a browser.
|
|
24
|
-
|
|
25
|
-
## Point Operator at it
|
|
26
|
-
|
|
27
|
-
Operator's `EventSink` posts each `OperatorEvent` to `KODE_TELEMETRY_URL` (fire-and-forget)
|
|
28
|
-
and always appends to `~/.axe/operator/events.jsonl` regardless. Point the URL at this
|
|
29
|
-
server's `/events` endpoint:
|
|
30
|
-
|
|
31
|
-
```
|
|
32
|
-
KODE_TELEMETRY_URL=http://127.0.0.1:8899/events operator
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
The server also reads directly from `~/.axe/operator/events.jsonl` on boot (backfill), so
|
|
36
|
-
even without `KODE_TELEMETRY_URL` set, restarting the dashboard after Operator has been
|
|
37
|
-
running will repopulate recent history from that file. Override the file path with
|
|
38
|
-
`KODE_EVENTS_FILE` (or `KODE_AUDIT_FILE`), matching the env vars `EventSink` itself reads.
|
|
39
|
-
|
|
40
|
-
## Endpoints
|
|
41
|
-
|
|
42
|
-
- `POST /events` — receive one `OperatorEvent`, or a JSON array of them. Validates
|
|
43
|
-
`v === 1` and the required fields; malformed input returns `400` and is dropped
|
|
44
|
-
without affecting the server. Valid events are kept in a ~2000-event in-memory ring
|
|
45
|
-
buffer, appended to the JSONL file (best-effort, never blocks the response), and
|
|
46
|
-
broadcast to any connected SSE clients.
|
|
47
|
-
- `GET /events/stream` — Server-Sent Events. Replays the ring buffer, then streams new
|
|
48
|
-
events live as `event: operator-event` messages.
|
|
49
|
-
- `GET /api/state` — JSON snapshot: summary tiles, a per-session rollup (last activity,
|
|
50
|
-
current tool/activity, tier, surface, cumulative tokens, turn count, ctx%, remote-control
|
|
51
|
-
state), recent tier-denials (last hour), and service health.
|
|
52
|
-
- `GET /` — the dashboard page (`index.html`), self-contained (inline CSS/JS, no external
|
|
53
|
-
hosts).
|
|
54
|
-
|
|
55
|
-
## Notes
|
|
56
|
-
|
|
57
|
-
- The dashboard page shows clearly-marked example rows ("waiting for events") only when
|
|
58
|
-
it has received nothing live yet; the moment a real event arrives, the example data is
|
|
59
|
-
cleared.
|
|
60
|
-
- Session rollups (cumulative tokens, turn count, etc.) are kept in a persistent map that
|
|
61
|
-
is never evicted, so they survive past events rolling off the ~2000-event ring buffer
|
|
62
|
-
used for the live feed and short time-window stats (tools/min, active-sessions).
|
package/dist/compose/client.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
// Compose (compose.casa) HTTP client — the data source for the /artifacts browser. We talk to the
|
|
2
|
-
// properly-scoped HTTP API with Operator's existing AuthGate Bearer token (loadCredentials), NOT the
|
|
3
|
-
// compose MCP: that MCP is mounted unauthenticated and its list/search/delete have no ownership scoping
|
|
4
|
-
// (they act on every artifact in the system), so it is unsafe to build "Mine" on. `/api/mine` is
|
|
5
|
-
// owner-scoped; `/api/list?q=` is the scoped search (NOT `/api/search`, which is global + unscoped).
|
|
6
|
-
// Base is overridable for tests/local via KODE_COMPOSE_URL.
|
|
7
|
-
import { loadCredentials } from "../auth/store.js";
|
|
8
|
-
const BASE = (process.env.KODE_COMPOSE_URL ?? "https://compose.casa").replace(/\/+$/, "");
|
|
9
|
-
export class ComposeError extends Error {
|
|
10
|
-
status;
|
|
11
|
-
constructor(message, status) {
|
|
12
|
-
super(message);
|
|
13
|
-
this.status = status;
|
|
14
|
-
this.name = "ComposeError";
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
/** The public view/share URL for an artifact — a pure string, no network call (the "copy url" action). */
|
|
18
|
-
export function viewUrl(id) {
|
|
19
|
-
return `${BASE}/v/${id}`;
|
|
20
|
-
}
|
|
21
|
-
async function authHeader() {
|
|
22
|
-
const creds = await loadCredentials();
|
|
23
|
-
if (!creds?.token)
|
|
24
|
-
throw new ComposeError("not signed in — run /login to connect to compose.casa", 401);
|
|
25
|
-
return `Bearer ${creds.token}`;
|
|
26
|
-
}
|
|
27
|
-
async function request(method, path) {
|
|
28
|
-
let res;
|
|
29
|
-
try {
|
|
30
|
-
res = await fetch(`${BASE}${path}`, { method, headers: { Authorization: await authHeader(), Accept: "application/json" } });
|
|
31
|
-
}
|
|
32
|
-
catch (e) {
|
|
33
|
-
throw new ComposeError(`compose.casa unreachable: ${e.message}`);
|
|
34
|
-
}
|
|
35
|
-
if (!res.ok) {
|
|
36
|
-
const hint = res.status === 401 ? " — token expired? run /login" : "";
|
|
37
|
-
throw new ComposeError(`compose ${method} ${path} → ${res.status}${hint}`, res.status);
|
|
38
|
-
}
|
|
39
|
-
return res;
|
|
40
|
-
}
|
|
41
|
-
/** The owner's library — the real "Mine" tab (AuthGate-scoped). */
|
|
42
|
-
export async function listMine() {
|
|
43
|
-
return (await request("GET", "/api/mine").then((r) => r.json()));
|
|
44
|
-
}
|
|
45
|
-
/** Scoped title+content search (caller's own artifacts), via /api/list?q= — never the global /api/search. */
|
|
46
|
-
export async function search(q) {
|
|
47
|
-
return (await request("GET", `/api/list?q=${encodeURIComponent(q)}`).then((r) => r.json()));
|
|
48
|
-
}
|
|
49
|
-
/** One artifact's content + metadata (the "attach" fetch). */
|
|
50
|
-
export async function get(id) {
|
|
51
|
-
return (await request("GET", `/api/${encodeURIComponent(id)}`).then((r) => r.json()));
|
|
52
|
-
}
|
|
53
|
-
/** Delete one artifact (owner-checked server-side). */
|
|
54
|
-
export async function del(id) {
|
|
55
|
-
await request("DELETE", `/api/${encodeURIComponent(id)}`);
|
|
56
|
-
}
|
package/mcp/README.md
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
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.
|