@0perator/operator 0.1.28 → 0.1.29

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.29";
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).
@@ -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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0perator/operator",
3
- "version": "0.1.28",
3
+ "version": "0.1.29",
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": {