@0perator/operator 0.1.27 → 0.1.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +31 -2
- package/dist/config/settings.js +3 -0
- package/dist/observability/index.js +7 -16
- package/dist/permissions/audit.js +4 -35
- package/dist/permissions/index.js +21 -11
- package/dist/permissions/policy.js +27 -6
- package/dist/permissions/tier.js +28 -0
- package/dist/session.js +7 -1
- package/dist/telemetry/events.js +68 -0
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -13,11 +13,12 @@ import { Session } from "./session.js";
|
|
|
13
13
|
import { AuroraRouter } from "./router/router.js";
|
|
14
14
|
import { BackgroundAgents } from "./background/index.js";
|
|
15
15
|
import { loadSettings } from "./config/settings.js";
|
|
16
|
+
import { EventSink } from "./telemetry/events.js";
|
|
16
17
|
import { readFileSync, writeFileSync, mkdirSync } from "node:fs";
|
|
17
18
|
import { join } from "node:path";
|
|
18
19
|
import { homedir, hostname } from "node:os";
|
|
19
20
|
import { createHash } from "node:crypto";
|
|
20
|
-
const VERSION = "0.1.
|
|
21
|
+
const VERSION = "0.1.28";
|
|
21
22
|
// operator/settings.json (override path via KODE_TSI_SETTINGS), env vars still win — see config/settings.ts.
|
|
22
23
|
const settings = loadSettings();
|
|
23
24
|
// Propagate the resolved sandbox mode to the tool layer (registry reads KODE_SANDBOX at exec time).
|
|
@@ -79,6 +80,15 @@ try {
|
|
|
79
80
|
}
|
|
80
81
|
catch { /* best-effort; the write is guarded too */ }
|
|
81
82
|
const RESUME = process.argv.includes("--resume") || process.argv.includes("-r") || process.env.KODE_RESUME === "1";
|
|
83
|
+
// Shared frozen-OperatorEvent stream (telemetry/events.ts) — the ONE sink for the whole session: tool +
|
|
84
|
+
// control events (emitted by the permission wrapper when enforcing), plus turn / service / remote-control
|
|
85
|
+
// events emitted below. Writes local JSONL + POSTs to KODE_TELEMETRY_URL if set (the dashboard's feed).
|
|
86
|
+
// The sink always exists so the audit trail works even with telemetry off; turn/service events are gated
|
|
87
|
+
// on telemetry.enabled so the metrics stream honors the off switch.
|
|
88
|
+
const SESSION_ID = createHash("sha1").update(`${process.cwd()}:${Date.now()}`).digest("hex").slice(0, 12);
|
|
89
|
+
const EVENT_ACTOR = { tier: settings.permissions.tier ?? "admin", surface: "cli" };
|
|
90
|
+
const eventSink = new EventSink();
|
|
91
|
+
const emitTelemetry = settings.telemetry.enabled !== false;
|
|
82
92
|
// Build the endpoint router. ONE model now: Aurora at its native 1M context on :8097 — both `operator`
|
|
83
93
|
// and `operator+` serve the same single tier (the air/1m/saddle roster collapsed once Aurora ran true
|
|
84
94
|
// 1,048,576-token context at full speed). No size-based routing decision remains.
|
|
@@ -216,6 +226,7 @@ function Root() {
|
|
|
216
226
|
permissions: fgPermissions, // owner's policy + computer tools forced to "ask" when enabled (else bypass)
|
|
217
227
|
approve: approveFn, // renders the in-TUI approval prompt for any "ask" decision
|
|
218
228
|
telemetry: settings.telemetry, // local-only metrics by default
|
|
229
|
+
eventSink, eventActor: EVENT_ACTOR, sessionId: SESSION_ID, // frozen event stream (tool/control audit)
|
|
219
230
|
// Foreground only: lets Aurora delegate via spawn_agent. The bg factory below OMITS this, so a
|
|
220
231
|
// sub-agent can't spawn more (no fork bombs). Cap at MAX_BG — all sub-agents share the one Aurora
|
|
221
232
|
// endpoint, so past the cap we refuse with guidance rather than thrash the shared KV cache.
|
|
@@ -305,6 +316,13 @@ function Root() {
|
|
|
305
316
|
}
|
|
306
317
|
catch { /* no saved session to resume */ }
|
|
307
318
|
}
|
|
319
|
+
// Feed the service-lever outcome to the frozen event stream (dashboard service-health tiles).
|
|
320
|
+
if (emitTelemetry) {
|
|
321
|
+
for (const r of reports) {
|
|
322
|
+
const state = r.state === "started" ? "started" : r.state === "up" ? "up" : "down";
|
|
323
|
+
eventSink.emit({ kind: "service", session: SESSION_ID, actor: EVENT_ACTOR, service: { name: r.name, state } });
|
|
324
|
+
}
|
|
325
|
+
}
|
|
308
326
|
// Confirm, once in scrollback, what the lever did (started = it was down and we brought it up).
|
|
309
327
|
const line = reports.map((r) => `${r.name} ${r.state === "up" ? "✓" : r.state === "started" ? "✓ started" : "✗"}`).join(" · ");
|
|
310
328
|
if (line)
|
|
@@ -404,8 +422,14 @@ function Root() {
|
|
|
404
422
|
// Surface the turn's real generation metrics in the status rule: tokens · gen tok/s · wall time.
|
|
405
423
|
if (!outcome.interrupted && (outcome.tokens || outcome.durationMs)) {
|
|
406
424
|
const tok = outcome.tokens ?? 0;
|
|
407
|
-
const
|
|
425
|
+
const durationMs = outcome.durationMs ?? 0;
|
|
426
|
+
const secs = durationMs / 1000;
|
|
408
427
|
setMetrics(fmtMeta(secs, tok));
|
|
428
|
+
// Feed the same numbers to the frozen event stream (dashboard + mobile). Gated on telemetry.enabled.
|
|
429
|
+
if (emitTelemetry) {
|
|
430
|
+
eventSink.emit({ kind: "turn", session: SESSION_ID, actor: EVENT_ACTOR,
|
|
431
|
+
turn: { tokens: tok, tokPerSec: secs > 0 ? Math.round(tok / secs) : undefined, ctxPct: session.ctxPct(), route: session.currentRoute(), durationMs } });
|
|
432
|
+
}
|
|
409
433
|
}
|
|
410
434
|
}
|
|
411
435
|
catch (e) {
|
|
@@ -575,6 +599,11 @@ function Root() {
|
|
|
575
599
|
sys(`remote control error: ${detail ?? "connection lost"} — /remotecontrol to retry`);
|
|
576
600
|
else if (st === "closed")
|
|
577
601
|
sys("remote control disconnected");
|
|
602
|
+
// Frozen event stream: the persistent RC indicator + dashboard read these control events.
|
|
603
|
+
if (st === "live")
|
|
604
|
+
eventSink.emit({ kind: "control", session: SESSION_ID, actor: EVENT_ACTOR, control: { event: "rc_connected", detail: rh.id ?? undefined } });
|
|
605
|
+
else if (st === "closed" || st === "error")
|
|
606
|
+
eventSink.emit({ kind: "control", session: SESSION_ID, actor: EVENT_ACTOR, control: { event: "rc_disconnected", detail } });
|
|
578
607
|
},
|
|
579
608
|
});
|
|
580
609
|
remoteRef.current = rh;
|
package/dist/config/settings.js
CHANGED
|
@@ -76,6 +76,9 @@ function applyEnv(s) {
|
|
|
76
76
|
const pm = process.env.KODE_PERMISSIONS;
|
|
77
77
|
if (pm === "bypass" || pm === "audit" || pm === "gated")
|
|
78
78
|
out.permissions = { ...out.permissions, mode: pm };
|
|
79
|
+
const tier = process.env.KODE_TIER; // identity tool-tier ceiling (admin=full fleet, enterprise=core+skills, readonly=inspect)
|
|
80
|
+
if (tier === "admin" || tier === "enterprise" || tier === "readonly")
|
|
81
|
+
out.permissions = { ...out.permissions, tier };
|
|
79
82
|
if (process.env.KODE_TELEMETRY === "0")
|
|
80
83
|
out.telemetry = { ...out.telemetry, enabled: false };
|
|
81
84
|
const sb = process.env.KODE_SANDBOX;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
// Operator observability — SPEC §12. Records METRICS ONLY (never prompt/response content): turn counts,
|
|
2
2
|
// tool-batch sizes + durations, self-heal events, and errors — the "is it healthy, what breaks" signal an
|
|
3
|
-
// enterprise deployment needs.
|
|
4
|
-
//
|
|
5
|
-
//
|
|
3
|
+
// enterprise deployment needs. LOCAL-ONLY: a silent append-only JSONL on the user's own disk (zero
|
|
4
|
+
// network, best-effort — never throws, never blocks a turn); disable with telemetry.enabled=false. The
|
|
5
|
+
// REMOTE sink is now the frozen OperatorEvent stream (telemetry/events.ts, EventSink) which is the single
|
|
6
|
+
// poster to KODE_TELEMETRY_URL — one wire shape for mobile, the dashboard, and the audit log; this module
|
|
7
|
+
// no longer POSTs its own ad-hoc shape to that URL (that would collide with the frozen stream).
|
|
6
8
|
import { appendFile, mkdir } from "node:fs/promises";
|
|
7
9
|
import { homedir } from "node:os";
|
|
8
10
|
import { join, dirname } from "node:path";
|
|
@@ -11,13 +13,13 @@ const DEFAULT_FILE = process.env.KODE_TELEMETRY_FILE ?? join(homedir(), ".axe",
|
|
|
11
13
|
export class Telemetry {
|
|
12
14
|
enabled;
|
|
13
15
|
file;
|
|
14
|
-
endpoint;
|
|
15
16
|
session = randomUUID();
|
|
16
17
|
lastWrite = Promise.resolve(); // serialized so events land in order + flushed() awaits all
|
|
17
18
|
constructor(cfg = {}) {
|
|
18
19
|
this.enabled = cfg.enabled ?? true;
|
|
19
20
|
this.file = cfg.file ?? DEFAULT_FILE;
|
|
20
|
-
|
|
21
|
+
// cfg.endpoint / KODE_TELEMETRY_URL are intentionally NOT read here anymore — the remote sink is the
|
|
22
|
+
// frozen OperatorEvent stream (EventSink), the single poster to that URL. This module stays local-only.
|
|
21
23
|
}
|
|
22
24
|
/** Record one metrics event. Best-effort: a disabled telemetry or any I/O failure is a silent no-op. */
|
|
23
25
|
record(ev) {
|
|
@@ -39,17 +41,6 @@ export class Telemetry {
|
|
|
39
41
|
catch {
|
|
40
42
|
/* local telemetry is best-effort */
|
|
41
43
|
}
|
|
42
|
-
if (this.endpoint) {
|
|
43
|
-
try {
|
|
44
|
-
const ctrl = new AbortController();
|
|
45
|
-
const t = setTimeout(() => ctrl.abort(), 3000);
|
|
46
|
-
await fetch(this.endpoint, { method: "POST", signal: ctrl.signal, headers: { "content-type": "application/json" }, body: JSON.stringify(line) }).catch(() => { });
|
|
47
|
-
clearTimeout(t);
|
|
48
|
-
}
|
|
49
|
-
catch {
|
|
50
|
-
/* remote sink is fire-and-forget; a down endpoint never affects the turn */
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
44
|
}
|
|
54
45
|
/** The Error's class (name) or first token — NEVER the message (which could carry paths/data). */
|
|
55
46
|
static errorClass(e) {
|
|
@@ -1,17 +1,7 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
// node:fs/os/path are imported LAZILY inside record() (not at module top) so this module stays node-free
|
|
6
|
-
// at load time — that keeps it safe to export from the browser/JSCore engine bundle (index.browser.ts),
|
|
7
|
-
// where a client injects its own audit sink and never hits the file path. Only the Node CLI writes files.
|
|
8
|
-
//
|
|
9
|
-
// The specifier MUST route through this indirection, never a literal import("node:fs/promises"): esbuild
|
|
10
|
-
// --platform=neutral (the SPEC/conformance run-jsc.sh gate) statically resolves a literal import() at
|
|
11
|
-
// build time and fails the node-free bundle. A variable specifier is opaque to that analysis, so esbuild
|
|
12
|
-
// leaves it a true runtime import — the node branch never runs in JSCore, so the browser bundle stays clean.
|
|
13
|
-
const nodeImport = (m) => import(/* @vite-ignore */ m);
|
|
14
|
-
const DEFAULT_FILE = process.env.KODE_AUDIT_FILE ?? "~/.axe/operator/audit.jsonl";
|
|
1
|
+
// Safe argument digest for the audit trail. The permission wrapper (index.ts) records one OperatorEvent
|
|
2
|
+
// per tool call (telemetry/events.ts is the sink + wire shape); this keeps the argument-summarizing that
|
|
3
|
+
// a "who did what" review needs while never leaking secrets or bloating the line. Pure + node-free, so it
|
|
4
|
+
// is safe to import from any bundle (the CLI and the JSCore/browser engine alike).
|
|
15
5
|
/** Summarize args for the log without leaking secrets or bloating the line. Keeps the shape a reviewer
|
|
16
6
|
* needs (which path, which command head) and drops values that could be sensitive. */
|
|
17
7
|
export function digestArgs(_name, args) {
|
|
@@ -27,24 +17,3 @@ export function digestArgs(_name, args) {
|
|
|
27
17
|
const keys = Object.keys(args);
|
|
28
18
|
return keys.length ? `{${keys.join(",")}}` : "";
|
|
29
19
|
}
|
|
30
|
-
export class AuditLog {
|
|
31
|
-
file;
|
|
32
|
-
constructor(file = DEFAULT_FILE) {
|
|
33
|
-
this.file = file;
|
|
34
|
-
}
|
|
35
|
-
/** Append one entry. Never throws (best-effort observability, not a gate). node:fs is imported here,
|
|
36
|
-
* lazily, so the module is node-free at load (browser/JSCore bundle safe). */
|
|
37
|
-
async record(entry) {
|
|
38
|
-
try {
|
|
39
|
-
const [{ appendFile, mkdir }, os, { join, dirname }] = await Promise.all([
|
|
40
|
-
nodeImport("node:fs/promises"), nodeImport("node:os"), nodeImport("node:path"),
|
|
41
|
-
]);
|
|
42
|
-
const file = this.file.startsWith("~/") ? join(os.homedir(), this.file.slice(2)) : this.file;
|
|
43
|
-
await mkdir(dirname(file), { recursive: true });
|
|
44
|
-
await appendFile(file, JSON.stringify(entry) + "\n", "utf8");
|
|
45
|
-
}
|
|
46
|
-
catch {
|
|
47
|
-
/* audit is best-effort — no fs (browser) or a write failure must never break a turn */
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
@@ -1,23 +1,36 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { digestArgs } from "./audit.js";
|
|
2
|
+
import { EventSink } from "../telemetry/events.js";
|
|
2
3
|
export { PermissionPolicy } from "./policy.js";
|
|
3
4
|
const DENIED = (name) => `Permission denied: "${name}" was refused by the operator permission policy. ` +
|
|
4
5
|
`Ask the user to approve it, or run in a mode that allows it.`;
|
|
6
|
+
const TIER_DENIED = (name, tier) => `Permission denied: "${name}" is not available on the "${tier}" tier. ` +
|
|
7
|
+
`This seat has a narrowed toolset; a full-access (admin) seat is required for this tool.`;
|
|
5
8
|
export function withPermissions(inner, policy, opts = {}) {
|
|
6
9
|
if (policy.inert)
|
|
7
|
-
return inner; // bypass + no rules → nothing to enforce or log; skip
|
|
8
|
-
const
|
|
10
|
+
return inner; // bypass + admin tier + no rules → nothing to enforce or log; skip entirely
|
|
11
|
+
const sink = policy.audits ? opts.sink ?? new EventSink() : undefined;
|
|
12
|
+
const actor = opts.actor ?? { tier: policy.currentTier(), surface: "cli" };
|
|
13
|
+
const session = opts.session ?? "";
|
|
14
|
+
const tool = (t) => sink?.emit({ kind: "tool", session, actor, tool: t });
|
|
9
15
|
async function gate(name, args, exec) {
|
|
16
|
+
const digest = digestArgs(name, args);
|
|
10
17
|
const decision = policy.decide(name, args);
|
|
11
18
|
const t0 = performance.now();
|
|
12
19
|
if (decision === "deny") {
|
|
13
|
-
|
|
20
|
+
// Distinguish a tier-ceiling denial (this seat can't have the tool at all) from a rule/mode denial.
|
|
21
|
+
if (!policy.allowsTool(name)) {
|
|
22
|
+
sink?.emit({ kind: "control", session, actor, control: { event: "tool_denied_by_tier", detail: `${name} @ ${actor.tier}` } });
|
|
23
|
+
tool({ name, args: digest, decision, outcome: "denied", approved: false });
|
|
24
|
+
return TIER_DENIED(name, actor.tier);
|
|
25
|
+
}
|
|
26
|
+
tool({ name, args: digest, decision, outcome: "denied", approved: false });
|
|
14
27
|
return DENIED(name);
|
|
15
28
|
}
|
|
16
29
|
let approved;
|
|
17
30
|
if (decision === "ask") {
|
|
18
31
|
approved = opts.approve ? await opts.approve(name, args) : false; // no approver ⇒ fail-safe deny
|
|
19
32
|
if (!approved) {
|
|
20
|
-
|
|
33
|
+
tool({ name, args: digest, decision, outcome: "denied", approved: false });
|
|
21
34
|
return DENIED(name);
|
|
22
35
|
}
|
|
23
36
|
}
|
|
@@ -27,22 +40,19 @@ export function withPermissions(inner, policy, opts = {}) {
|
|
|
27
40
|
}
|
|
28
41
|
catch (e) {
|
|
29
42
|
// The inner executor's contract is resolve-not-reject; if one ever throws, record + surface as a string.
|
|
30
|
-
|
|
43
|
+
tool({ name, args: digest, decision, outcome: "error", approved, durationMs: performance.now() - t0 });
|
|
31
44
|
return `error: ${e instanceof Error ? e.message : String(e)}`;
|
|
32
45
|
}
|
|
33
46
|
const outcome = /^error/i.test(result.trim()) ? "error" : "ok";
|
|
34
|
-
|
|
47
|
+
tool({ name, args: digest, decision, outcome, approved, durationMs: performance.now() - t0 });
|
|
35
48
|
return result;
|
|
36
49
|
}
|
|
37
50
|
return {
|
|
38
51
|
execute: (name, args) => gate(name, args, () => inner.execute(name, args)),
|
|
39
52
|
executeParallel: (calls) =>
|
|
40
|
-
// Gate each call individually (its own decision +
|
|
53
|
+
// Gate each call individually (its own decision + event), preserving order. We can't hand a
|
|
41
54
|
// pre-denied call to inner.executeParallel, so route per-call through execute (the executor's
|
|
42
55
|
// own read-only/mutating parallelism still applies to the ones that reach it via execute).
|
|
43
56
|
Promise.all(calls.map((c) => gate(c.name, c.args, () => inner.execute(c.name, c.args)))),
|
|
44
57
|
};
|
|
45
58
|
}
|
|
46
|
-
function mk(tool, args, decision, outcome, extra) {
|
|
47
|
-
return { ts: new Date().toISOString(), tool, args: digestArgs(tool, args), decision, outcome, ...extra };
|
|
48
|
-
}
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
// Operator permission policy — SPEC §11 (agent safety). Decides, per tool call, whether it may run,
|
|
2
|
+
// must be approved, or is refused. DESIGNED TO BE INERT BY DEFAULT: mode "bypass" (the default) allows
|
|
3
|
+
// everything with no prompt and no log — zero gates, zero overhead — so the owner's experience is
|
|
4
|
+
// unchanged until they deliberately turn enforcement on. Enterprise deployments flip mode to "gated"
|
|
5
|
+
// (mutating tools require approval) or tighten `rules`; "audit" allows-but-records (see audit.ts).
|
|
6
|
+
import { tierAllows } from "./tier.js";
|
|
1
7
|
// Read-only tools (registry `safe: true`) — never gated unless a rule says otherwise.
|
|
2
8
|
const DEFAULT_SAFE = ["file_read", "grep_search", "list_directory", "memory_search", "web_fetch"];
|
|
3
9
|
// Genuinely destructive shell shapes — in "gated" these escalate a would-be "allow" to "ask" even for
|
|
@@ -21,27 +27,42 @@ export class PermissionPolicy {
|
|
|
21
27
|
mode;
|
|
22
28
|
rules;
|
|
23
29
|
safe;
|
|
30
|
+
tier;
|
|
24
31
|
constructor(cfg = {}) {
|
|
25
32
|
this.mode = cfg.mode ?? "bypass";
|
|
26
33
|
this.rules = cfg.rules ?? {};
|
|
27
34
|
this.safe = new Set(cfg.safeTools ?? DEFAULT_SAFE);
|
|
35
|
+
this.tier = cfg.tier ?? "admin";
|
|
28
36
|
}
|
|
29
|
-
/** True when the policy can never block or
|
|
37
|
+
/** True when the policy can never block, prompt, or log — lets the wrapper skip itself entirely (no
|
|
38
|
+
* overhead). Requires the full-access owner tier: a narrowed tier is always enforced, even in bypass. */
|
|
30
39
|
get inert() {
|
|
31
|
-
return this.mode === "bypass" && Object.keys(this.rules).length === 0;
|
|
40
|
+
return this.mode === "bypass" && this.tier === "admin" && Object.keys(this.rules).length === 0;
|
|
32
41
|
}
|
|
33
|
-
/** Whether tool actions should be recorded
|
|
42
|
+
/** Whether tool actions should be recorded. On in audit/gated, or whenever a tier is enforced (a
|
|
43
|
+
* multi-tenant seat is always audited — "who did what" is the point of a seat). */
|
|
34
44
|
get audits() {
|
|
35
|
-
return this.mode !== "bypass";
|
|
45
|
+
return this.mode !== "bypass" || this.tier !== "admin";
|
|
36
46
|
}
|
|
37
47
|
currentMode() {
|
|
38
48
|
return this.mode;
|
|
39
49
|
}
|
|
40
|
-
|
|
50
|
+
currentTier() {
|
|
51
|
+
return this.tier;
|
|
52
|
+
}
|
|
53
|
+
/** True iff `name` is within this identity's tier ceiling. A tool outside it can never run, even with a
|
|
54
|
+
* per-tool "allow" rule — the tier is the security boundary, rules only narrow within it. */
|
|
55
|
+
allowsTool(name) {
|
|
56
|
+
return tierAllows(this.tier, name);
|
|
57
|
+
}
|
|
58
|
+
/** The decision for one tool call. Tier ceiling first (a denied tool can't be granted by any rule),
|
|
59
|
+
* then an explicit per-tool rule, then mode. */
|
|
41
60
|
decide(name, args) {
|
|
61
|
+
if (!this.allowsTool(name))
|
|
62
|
+
return "deny"; // tier ceiling — absolute, above rules and mode
|
|
42
63
|
const rule = this.rules[name];
|
|
43
64
|
if (rule)
|
|
44
|
-
return rule; // explicit override
|
|
65
|
+
return rule; // explicit override within the tier
|
|
45
66
|
if (this.mode === "bypass" || this.mode === "audit")
|
|
46
67
|
return "allow"; // audit records but never blocks
|
|
47
68
|
// "gated": read-only tools run; mutating tools ask; a dangerous shell shape always asks.
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Enterprise seat: core coding + skills hub. An ALLOWLIST by design — anything not named here (fleet MCP
|
|
2
|
+
// tools mcp__*, computer_* control, future privileged tools) is denied, so new tools are safe-by-default.
|
|
3
|
+
const ENTERPRISE_ALLOW = new Set([
|
|
4
|
+
"file_read", "file_write", "file_edit", "grep_search", "list_directory",
|
|
5
|
+
"shell_exec", "shell_background", "bash_output", "bash_kill",
|
|
6
|
+
"git_command", "checkpoint", "task_add", "task_list", "task_update",
|
|
7
|
+
"memory_search", "memory_store", "web_fetch", "web_search",
|
|
8
|
+
"skill_list", "skill_fetch", "skill_save",
|
|
9
|
+
]);
|
|
10
|
+
// Readonly seat: inspection only (a superset-safe subset of the enterprise allowlist).
|
|
11
|
+
const READONLY_ALLOW = new Set([
|
|
12
|
+
"file_read", "grep_search", "list_directory", "bash_output", "task_list",
|
|
13
|
+
"memory_search", "web_fetch", "web_search", "skill_list", "skill_fetch",
|
|
14
|
+
]);
|
|
15
|
+
export const TIERS = ["admin", "enterprise", "readonly"];
|
|
16
|
+
export function isTier(v) {
|
|
17
|
+
return v === "admin" || v === "enterprise" || v === "readonly";
|
|
18
|
+
}
|
|
19
|
+
/** Whether `tool` is within `tier`'s grant. admin = everything; the others are explicit allowlists so any
|
|
20
|
+
* unlisted tool (including every dynamically-named MCP fleet tool) is denied by default. */
|
|
21
|
+
export function tierAllows(tier, tool) {
|
|
22
|
+
switch (tier) {
|
|
23
|
+
case "admin": return true;
|
|
24
|
+
case "enterprise": return ENTERPRISE_ALLOW.has(tool);
|
|
25
|
+
case "readonly": return READONLY_ALLOW.has(tool);
|
|
26
|
+
default: return false;
|
|
27
|
+
}
|
|
28
|
+
}
|
package/dist/session.js
CHANGED
|
@@ -51,6 +51,9 @@ export class Session {
|
|
|
51
51
|
policy;
|
|
52
52
|
approve;
|
|
53
53
|
telemetry;
|
|
54
|
+
eventSink;
|
|
55
|
+
eventActor;
|
|
56
|
+
sessionId;
|
|
54
57
|
mcpSchemas = []; // merged in after first-turn discovery (empty until then)
|
|
55
58
|
wantMcp;
|
|
56
59
|
systemPrompt;
|
|
@@ -80,6 +83,9 @@ export class Session {
|
|
|
80
83
|
this.policy = new PermissionPolicy(cfg.permissions);
|
|
81
84
|
this.approve = cfg.approve;
|
|
82
85
|
this.telemetry = new Telemetry(cfg.telemetry);
|
|
86
|
+
this.eventSink = cfg.eventSink;
|
|
87
|
+
this.eventActor = cfg.eventActor;
|
|
88
|
+
this.sessionId = cfg.sessionId;
|
|
83
89
|
this.tools = this.buildTools(); // local-only until first-turn MCP discovery rebinds it
|
|
84
90
|
}
|
|
85
91
|
/** The effective system prompt: the base persona plus any memory recalled this session. Injected as
|
|
@@ -92,7 +98,7 @@ export class Session {
|
|
|
92
98
|
/** Compose the tool executor: local tools + MCP (composite) with the permission/audit layer on top.
|
|
93
99
|
* withPermissions returns the composite UNCHANGED when the policy is inert (bypass) — zero overhead. */
|
|
94
100
|
buildTools() {
|
|
95
|
-
return withPermissions(withMcp(this.executor, this.hub), this.policy, { approve: this.approve });
|
|
101
|
+
return withPermissions(withMcp(this.executor, this.hub), this.policy, { approve: this.approve, sink: this.eventSink, actor: this.eventActor, session: this.sessionId });
|
|
96
102
|
}
|
|
97
103
|
/** Is the currently-selected endpoint reachable? Lets the shell fail clearly before a turn. */
|
|
98
104
|
health() {
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// Operator event stream — the ONE frozen wire shape (v1) for everything a supervising human or dashboard
|
|
2
|
+
// needs to watch the agent swarm: tool calls (the audit trail), turns (telemetry), control-plane
|
|
3
|
+
// decisions (tier grants/denials, remote-control state), and service-lever transitions. Mobile, the live
|
|
4
|
+
// dashboard, and the on-disk audit log all render the SAME envelope, so there is exactly one contract to
|
|
5
|
+
// agree on. FROZEN v1: add fields, never repurpose or remove one; bump `v` for a breaking change.
|
|
6
|
+
//
|
|
7
|
+
// CLI-only sink, node-lazy (opaque specifier, same discipline as audit.ts/searxng.ts) so this module is
|
|
8
|
+
// node-free at load and safe to import from the JSCore/browser bundle — there the file/HTTP branches are
|
|
9
|
+
// simply never reached (a mobile host injects its own sink). Best-effort by construction: a sink failure
|
|
10
|
+
// never blocks or fails a turn — observability is not a gate.
|
|
11
|
+
const nodeImport = (m) => import(/* @vite-ignore */ m);
|
|
12
|
+
export const EVENT_V = 1;
|
|
13
|
+
/** Emits OperatorEvents to a local JSONL file and, if configured, an HTTP sink. Both best-effort. The
|
|
14
|
+
* HTTP POST is fire-and-forget with a short timeout so a slow/down sink never stalls a turn. */
|
|
15
|
+
export class EventSink {
|
|
16
|
+
file;
|
|
17
|
+
url;
|
|
18
|
+
onEvent;
|
|
19
|
+
constructor(opts = {}) {
|
|
20
|
+
this.file = opts.file ?? process.env.KODE_EVENTS_FILE ?? process.env.KODE_AUDIT_FILE ?? "~/.axe/operator/events.jsonl";
|
|
21
|
+
this.url = opts.url ?? process.env.KODE_TELEMETRY_URL;
|
|
22
|
+
// In-process callback bridge — the ONLY path that works on mobile (JSCore has no fs and the phone is
|
|
23
|
+
// not a KODE_TELEMETRY_URL backend), same pattern as the bg-agents host bridge. A native/web host sets
|
|
24
|
+
// this to marshal each event into its own store and render the control-plane surface.
|
|
25
|
+
this.onEvent = opts.onEvent;
|
|
26
|
+
}
|
|
27
|
+
/** Fill in envelope boilerplate and dispatch. Callers pass kind + the matching payload + actor. */
|
|
28
|
+
emit(e) {
|
|
29
|
+
const full = { v: EVENT_V, ts: new Date().toISOString(), ...e };
|
|
30
|
+
// In-process listener first (synchronous, never throws out) so a host callback sees every event even
|
|
31
|
+
// where fs/HTTP are absent (mobile). Then fire-and-forget the file + HTTP sinks off the hot path.
|
|
32
|
+
try {
|
|
33
|
+
this.onEvent?.(full);
|
|
34
|
+
}
|
|
35
|
+
catch { /* a host listener must never break a turn */ }
|
|
36
|
+
void this.write(full);
|
|
37
|
+
void this.post(full);
|
|
38
|
+
}
|
|
39
|
+
async write(e) {
|
|
40
|
+
try {
|
|
41
|
+
const [{ appendFile, mkdir }, os, { join, dirname }] = await Promise.all([
|
|
42
|
+
nodeImport("node:fs/promises"), nodeImport("node:os"), nodeImport("node:path"),
|
|
43
|
+
]);
|
|
44
|
+
const file = this.file.startsWith("~/") ? join(os.homedir(), this.file.slice(2)) : this.file;
|
|
45
|
+
await mkdir(dirname(file), { recursive: true });
|
|
46
|
+
await appendFile(file, JSON.stringify(e) + "\n", "utf8");
|
|
47
|
+
}
|
|
48
|
+
catch { /* best-effort: no fs (mobile) or a write failure must never break a turn */ }
|
|
49
|
+
}
|
|
50
|
+
async post(e) {
|
|
51
|
+
if (!this.url)
|
|
52
|
+
return;
|
|
53
|
+
const ctrl = new AbortController();
|
|
54
|
+
const t = setTimeout(() => ctrl.abort(), 3000);
|
|
55
|
+
try {
|
|
56
|
+
await fetch(this.url, {
|
|
57
|
+
method: "POST",
|
|
58
|
+
headers: { "content-type": "application/json" },
|
|
59
|
+
body: JSON.stringify(e),
|
|
60
|
+
signal: ctrl.signal,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
catch { /* remote sink down/slow — local JSONL still has it; never block the turn */ }
|
|
64
|
+
finally {
|
|
65
|
+
clearTimeout(t);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@0perator/operator",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.28",
|
|
4
4
|
"description": "Operator (KODE) — TypeScript + Ink terminal coding agent. Full-frame render, single-engine core shared across CLI/web/mobile; runs against a local Aurora model.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|