@0perator/operator 0.1.28 → 0.1.30

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 CHANGED
@@ -18,7 +18,7 @@ import { readFileSync, writeFileSync, mkdirSync } from "node:fs";
18
18
  import { join } from "node:path";
19
19
  import { homedir, hostname } from "node:os";
20
20
  import { createHash } from "node:crypto";
21
- const VERSION = "0.1.28";
21
+ const VERSION = "0.1.30";
22
22
  // operator/settings.json (override path via KODE_TSI_SETTINGS), env vars still win — see config/settings.ts.
23
23
  const settings = loadSettings();
24
24
  // Propagate the resolved sandbox mode to the tool layer (registry reads KODE_SANDBOX at exec time).
@@ -143,6 +143,7 @@ const HELP = [
143
143
  " /model current endpoint (aurora · 1M), context %, turn count",
144
144
  " /endpoints show the aurora endpoint + live health",
145
145
  " /services ensure/inspect the service lever (aurora+autopilot+searxng); /services stop",
146
+ " /audit [n] recent tool + control-plane events from the audit trail (default 15)",
146
147
  " /compact force-compact the conversation now",
147
148
  " /remember <note> store a note to recall in future sessions",
148
149
  " /memory [query] show remembered notes (all, or matching query)",
@@ -544,6 +545,36 @@ function Root() {
544
545
  sys("endpoints:\n" + s.endpoints().map((e) => ` ${h[e.name] ? "●" : "○"} ${e.name} ${e.base} ${e.model} ctx ${e.ctxWindow.toLocaleString()}`).join("\n"));
545
546
  break;
546
547
  }
548
+ case "audit": {
549
+ // The human-supervisor view of the frozen event stream: recent tool decisions + control events
550
+ // (tier denials, signature lines, RC) straight from the audit JSONL. Read-only.
551
+ const n = Math.max(1, Math.min(50, Number(arg) || 15));
552
+ const file = (process.env.KODE_EVENTS_FILE || process.env.KODE_AUDIT_FILE || join(homedir(), ".axe", "operator", "events.jsonl"));
553
+ let lines = [];
554
+ try {
555
+ lines = readFileSync(file, "utf8").trim().split("\n").filter(Boolean);
556
+ }
557
+ catch { /* no audit yet */ }
558
+ if (!lines.length) {
559
+ sys(`no audit events yet (${settings.permissions.tier ?? "admin"} tier, ${settings.permissions.mode} mode). Events record once enforcement is on.`);
560
+ break;
561
+ }
562
+ const rows = lines.slice(-n).map((l) => { try {
563
+ return JSON.parse(l);
564
+ }
565
+ catch {
566
+ return null;
567
+ } }).filter(Boolean)
568
+ .filter((e) => e.kind === "tool" || e.kind === "control")
569
+ .map((e) => {
570
+ const t = new Date(e.ts).toLocaleTimeString();
571
+ if (e.kind === "tool")
572
+ return ` ${t} ${e.tool.decision === "deny" ? "✗" : e.tool.approved === false ? "⃠" : "●"} ${e.tool.name} [${e.tool.outcome}]${e.tool.args ? " " + String(e.tool.args).slice(0, 60) : ""}`;
573
+ return ` ${t} ⚑ ${e.control.event}${e.control.detail ? " " + e.control.detail : ""}`;
574
+ });
575
+ sys(rows.length ? `audit (last ${rows.length}):\n` + rows.join("\n") : "no tool/control events in the audit log yet");
576
+ break;
577
+ }
547
578
  case "services": {
548
579
  // The lever, on demand: `/services` probes + starts any down launchd service; `/services stop`
549
580
  // tears down only the session-scoped SearXNG (Aurora/autopilot are shared and stay up).
@@ -656,7 +687,7 @@ function Root() {
656
687
  const liveMetrics = active
657
688
  ? `${SPIN[Math.floor(elapsed * 4) % SPIN.length]} ${fmtMeta(elapsed, liveTok)}`
658
689
  : metrics;
659
- return (_jsx(App, { messages: entries, live: live, status: status, stepLabel: stepLabel, route: route, ctxPct: ctxPct, version: VERSION, metrics: liveMetrics, authUser: authUser, verbs: settings.verbs, bgAgents: bgAgents, onSubmit: onSubmit, onQueue: onQueue, onInterrupt: onInterrupt, approval: approval, onApprovalDecide: (allow, always) => {
690
+ return (_jsx(App, { messages: entries, live: live, status: status, stepLabel: stepLabel, route: route, ctxPct: ctxPct, version: VERSION, metrics: liveMetrics, authUser: authUser, tier: EVENT_ACTOR.tier, verbs: settings.verbs, bgAgents: bgAgents, onSubmit: onSubmit, onQueue: onQueue, onInterrupt: onInterrupt, approval: approval, onApprovalDecide: (allow, always) => {
660
691
  const cur = approval;
661
692
  if (cur)
662
693
  settleApproval(cur.id, allow, always); // first-wins with any remote follower answer
@@ -28,6 +28,11 @@ export function withPermissions(inner, policy, opts = {}) {
28
28
  }
29
29
  let approved;
30
30
  if (decision === "ask") {
31
+ // A human-signature line (money/prod/destructive) surfaces as its own control event so a dashboard/
32
+ // mobile flags WHY a human was pulled in — and a background sub-agent (no approver) is denied below.
33
+ const line = policy.signatureLineFor(name, args);
34
+ if (line)
35
+ sink?.emit({ kind: "control", session, actor, control: { event: "signature_required", detail: `${line}: ${name}` } });
31
36
  approved = opts.approve ? await opts.approve(name, args) : false; // no approver ⇒ fail-safe deny
32
37
  if (!approved) {
33
38
  tool({ name, args: digest, decision, outcome: "denied", approved: false });
@@ -4,6 +4,7 @@
4
4
  // unchanged until they deliberately turn enforcement on. Enterprise deployments flip mode to "gated"
5
5
  // (mutating tools require approval) or tighten `rules`; "audit" allows-but-records (see audit.ts).
6
6
  import { tierAllows } from "./tier.js";
7
+ import { signatureLine } from "./signature.js";
7
8
  // Read-only tools (registry `safe: true`) — never gated unless a rule says otherwise.
8
9
  const DEFAULT_SAFE = ["file_read", "grep_search", "list_directory", "memory_search", "web_fetch"];
9
10
  // Genuinely destructive shell shapes — in "gated" these escalate a would-be "allow" to "ask" even for
@@ -55,11 +56,19 @@ export class PermissionPolicy {
55
56
  allowsTool(name) {
56
57
  return tierAllows(this.tier, name);
57
58
  }
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. */
59
+ /** Which human-signature line a call crosses (money/prod/destructive), or null. Live only while
60
+ * enforcing (never for the fully-inert local owner). The wrapper reports this on an approval. */
61
+ signatureLineFor(name, args) {
62
+ return this.inert ? null : signatureLine(name, args);
63
+ }
64
+ /** The decision for one tool call. Precedence: tier ceiling (a denied tool can't be granted by any
65
+ * rule) → human-signature line (money/prod/destructive always ask, beating a rule/mode) → per-tool
66
+ * rule → mode. */
60
67
  decide(name, args) {
61
68
  if (!this.allowsTool(name))
62
69
  return "deny"; // tier ceiling — absolute, above rules and mode
70
+ if (this.signatureLineFor(name, args))
71
+ return "ask"; // human-signature line — always a human, beats rules
63
72
  const rule = this.rules[name];
64
73
  if (rule)
65
74
  return rule; // explicit override within the tier
@@ -0,0 +1,57 @@
1
+ // Human-signature lines — the org control plane's hard floor (AURORA_1PCT_AI_ORG_MAP.md §4). A class of
2
+ // actions that ALWAYS require a human, regardless of permission mode, and that a background sub-agent (no
3
+ // approver) can therefore NEVER cross alone. These are the irreversible / high-stakes moves where the cost
4
+ // of a wrong call is asymmetric: moving money, changing production, and destroying data. In the abstract
5
+ // org map the four lines are money / prod / legal / hiring; only the first three map to a tool Operator
6
+ // can call (legal + hiring are human-process, not a tool), so those are what we gate here.
7
+ //
8
+ // Precedence: a signature line beats a per-tool "allow" rule and the mode — it can only ever be relaxed by
9
+ // the policy being fully inert (the local owner in bypass+admin+no-rules, where the wrapper is skipped
10
+ // entirely). The moment any enforcement is on (a tier, audit/gated mode, or a rule), the lines are live.
11
+ // Tool-NAME patterns: money-moving integrations (mostly MCP tools) — pay/charge/refund/payout/transfer/
12
+ // wire/invoice/billing/subscription changes. Conservative: a false positive just adds one approval.
13
+ const MONEY_NAME = /(pay(ment|out|ee)?|charge|refund|transfer|wire|invoice|billing|subscription|checkout|stripe|disburse)/i;
14
+ // Command/arg patterns for a production-affecting change (deploys, infra mutation, orchestration).
15
+ const PROD_CMD = [
16
+ /\bterraform\s+(apply|destroy)\b/i,
17
+ /\bkubectl\s+(apply|delete|drain|cordon|scale)\b/i,
18
+ /\bhelm\s+(install|upgrade|uninstall|rollback)\b/i,
19
+ /\bsystemctl\s+(restart|stop|disable|mask)\b/i,
20
+ /\b(launchctl)\s+(bootout|unload|disable)\b/i,
21
+ /\bdocker\s+(compose\s+)?(down|rm|stop|kill)\b/i,
22
+ /\bgit\s+push\b[^\n]*\b(--force|-f)\b|\b(--force|-f)\b[^\n]*\bgit\s+push\b/i,
23
+ /\bgit\s+push\b[^\n]*\b(origin\s+)?(main|master|prod(uction)?|release)\b/i,
24
+ /\bnpm\s+publish\b|\byarn\s+publish\b/i,
25
+ ];
26
+ // Command/arg patterns for irreversible destruction (data / disk / filesystem).
27
+ const DESTRUCTIVE_CMD = [
28
+ /\brm\s+-[a-z]*r[a-z]*f?\b/i, // rm -rf …
29
+ /\b(mkfs|dd)\b/i,
30
+ /\bshutdown\b|\breboot\b/i,
31
+ /:\(\)\s*\{.*\}\s*;/, // fork bomb
32
+ /\bchmod\s+-R\s+0?00\b/i,
33
+ />\s*\/dev\/sd[a-z]/i,
34
+ /\b(drop\s+(database|table|schema)|truncate\s+table|delete\s+from)\b/i, // SQL data loss
35
+ ];
36
+ function blob(args) {
37
+ const cmd = typeof args.command === "string" ? args.command : "";
38
+ // git_command passes the subcommand array (["push","--force",...]) with no leading "git" — prepend it so
39
+ // the git patterns match, mirroring how the audit digest renders git calls.
40
+ const gitArgs = Array.isArray(args.args) ? `git ${args.args.join(" ")}` : "";
41
+ const query = typeof args.query === "string" ? args.query : typeof args.sql === "string" ? args.sql : "";
42
+ return `${cmd} ${gitArgs} ${query}`.trim();
43
+ }
44
+ /** Which signature line a call crosses, or null. Checked on every gated call: null lets the normal
45
+ * policy decide; a non-null value forces approval (and, absent an approver, a deny). */
46
+ export function signatureLine(name, args) {
47
+ if (MONEY_NAME.test(name))
48
+ return "money";
49
+ const b = blob(args);
50
+ if (b) {
51
+ if (DESTRUCTIVE_CMD.some((re) => re.test(b)))
52
+ return "destructive";
53
+ if (PROD_CMD.some((re) => re.test(b)))
54
+ return "prod";
55
+ }
56
+ return null;
57
+ }
@@ -16,6 +16,7 @@ export class EventSink {
16
16
  file;
17
17
  url;
18
18
  onEvent;
19
+ lastWrite = Promise.resolve(); // chained so appends land in emit order (an audit log must be ordered)
19
20
  constructor(opts = {}) {
20
21
  this.file = opts.file ?? process.env.KODE_EVENTS_FILE ?? process.env.KODE_AUDIT_FILE ?? "~/.axe/operator/events.jsonl";
21
22
  this.url = opts.url ?? process.env.KODE_TELEMETRY_URL;
@@ -33,9 +34,14 @@ export class EventSink {
33
34
  this.onEvent?.(full);
34
35
  }
35
36
  catch { /* a host listener must never break a turn */ }
36
- void this.write(full);
37
+ this.lastWrite = this.lastWrite.then(() => this.write(full)); // serialized: ordered append, awaitable via flushed()
37
38
  void this.post(full);
38
39
  }
40
+ /** Resolves once all queued file appends have landed. The app never awaits this (the sink is
41
+ * best-effort, off the hot path); it makes the JSONL deterministically testable without sleeping. */
42
+ flushed() {
43
+ return this.lastWrite;
44
+ }
39
45
  async write(e) {
40
46
  try {
41
47
  const [{ appendFile, mkdir }, os, { join, dirname }] = await Promise.all([
package/dist/ui/App.js CHANGED
@@ -9,10 +9,10 @@ import { StepSpinner, RecoverSpinner } from "./ActivitySpinner.js";
9
9
  import { BgPanel } from "./BgPanel.js";
10
10
  import { ApprovalPrompt } from "./ApprovalPrompt.js";
11
11
  export function App(props) {
12
- const { messages, live = null, status, thinkingVerb, verbs, stepLabel, route, ctxPct, version, build, metrics, authUser, bgAgents, onSubmit, onQueue, onInterrupt, approval = null, onApprovalDecide } = props;
12
+ const { messages, live = null, status, thinkingVerb, verbs, stepLabel, route, ctxPct, version, build, metrics, authUser, tier, bgAgents, onSubmit, onQueue, onInterrupt, approval = null, onApprovalDecide } = props;
13
13
  const thinking = status === "thinking" || status === "streaming";
14
14
  const showSpinner = status === "recovering" || status === "executing" || thinking;
15
15
  return (_jsxs(Box, { flexDirection: "column", children: [_jsx(Transcript, { entries: messages, live: live }), showSpinner && (_jsx(Box, { marginTop: 1, marginBottom: 1, children: status === "recovering" ? _jsx(RecoverSpinner, { active: true, label: stepLabel })
16
16
  : status === "executing" ? _jsx(StepSpinner, { active: true, label: stepLabel })
17
- : _jsx(ThinkingSpinner, { active: true, verb: thinkingVerb, verbs: verbs, metrics: metrics }) })), _jsx(BgPanel, { agents: bgAgents }), _jsx(ApprovalPrompt, { approval: approval, onDecide: onApprovalDecide ?? (() => { }) }), _jsx(StatusRule, { route: route, ctxPct: ctxPct, version: version, build: build, user: authUser }), _jsx(Composer, { onSubmit: onSubmit, onQueue: onQueue, onInterrupt: onInterrupt, disabled: status !== "idle", suspended: !!approval }), _jsx(InputRule, {})] }));
17
+ : _jsx(ThinkingSpinner, { active: true, verb: thinkingVerb, verbs: verbs, metrics: metrics }) })), _jsx(BgPanel, { agents: bgAgents }), _jsx(ApprovalPrompt, { approval: approval, onDecide: onApprovalDecide ?? (() => { }) }), _jsx(StatusRule, { route: route, ctxPct: ctxPct, version: version, build: build, user: authUser, tier: tier }), _jsx(Composer, { onSubmit: onSubmit, onQueue: onQueue, onInterrupt: onInterrupt, disabled: status !== "idle", suspended: !!approval }), _jsx(InputRule, {})] }));
18
18
  }
@@ -1,9 +1,10 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Box, Text } from "ink";
3
- export function StatusRule({ route, ctxPct, version, build, user }) {
3
+ export function StatusRule({ route, ctxPct, version, build, user, tier }) {
4
4
  const who = user ? `⬤ ${user} · ` : "";
5
- // Info block: identity · route · ctx% · version. Kept as one string so the width math is exact.
6
- const info = `${who}${route} · ${Math.round(ctxPct)}% · v${version}${build ? ` ·${build}` : ""}`;
5
+ const seat = tier && tier !== "admin" ? `⛨ ${tier} · ` : ""; // a narrowed seat is visible; the owner's admin is not
6
+ // Info block: seat · identity · route · ctx% · version. Kept as one string so the width math is exact.
7
+ const info = `${seat}${who}${route} · ${Math.round(ctxPct)}% · v${version}${build ? ` ·${build}` : ""}`;
7
8
  // The full right-hand content, styled below in segments (✷ magenta, OPERATOR bold, info dim). This
8
9
  // plain string is only used to measure width so the leading rule fills precisely.
9
10
  const right = `✷ OPERATOR · ${info} ─`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0perator/operator",
3
- "version": "0.1.28",
3
+ "version": "0.1.30",
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": {