aibroker 0.10.0 → 0.12.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/README.md CHANGED
@@ -152,7 +152,39 @@ For callers with no session and no mailbox — a launchd poller checking whether
152
152
 
153
153
  Every probe of an idle session does inject a message that stays in that session's context, so keep the text short and probe rarely.
154
154
 
155
- ### 7. Connect an adapter
155
+ ### 7. File work from your phone or watch (optional)
156
+
157
+ ```bash
158
+ tailscale funnel --bg --https=8443 http://127.0.0.1:8766
159
+ ```
160
+
161
+ Add a task in Todoist and it reaches the session that owns it — no polling, because Todoist pushes. Set a **reminder** rather than a due date to schedule work: `reminder:fired` is a webhook event, a task merely becoming due is not.
162
+
163
+ This is an execution ingress, so it is narrow by construction: every request must carry a valid HMAC signature, only explicitly allowlisted projects can reach a session, and an empty allowlist accepts nothing rather than everything. Todoist's Inbox cannot be shared, which is what makes quick capture from a watch safe.
164
+
165
+ Full setup, routing rules and the security model: **[docs/todoist.md](docs/todoist.md)**.
166
+
167
+ ### 8. Audit what one session did to another
168
+
169
+ ```bash
170
+ aibroker audit # recent cross-session activity
171
+ aibroker audit --session Youdrill # everything touching one session
172
+ aibroker audit --trace <id> # follow one causation chain
173
+ aibroker audit --bodies # full message bodies
174
+ aibroker audit --json # raw JSONL, for piping
175
+ ```
176
+
177
+ Every daemon-mediated cross-session action — `send`, `dispatch`, `ask`, `launch`, and refusals — is appended to `~/.aibroker/audit.jsonl`, one JSON object per line, **before and independently of whatever the acting agent later reports**.
178
+
179
+ That distinction is the point. Sessions can now message each other, dispatch work, spawn new sessions and probe for liveness, and chains form that nobody designed: an observation in one project reaching a second session which relays it to a third. Without a record, the only account of any of it is each participant's own — a session that acts and does not mention it leaves no trace, and a session that ends takes its side of the story with it.
180
+
181
+ Bodies are stored in full, because a summary of a message is exactly the self-report this replaces. Refusals are stored too: "the hub declined to type this into a shell" is part of the history.
182
+
183
+ `--trace` walks a chain in both directions — what led to an event, and what it led to. Causation is inferred from the last message an actor received, which reconstructs `A→B→C` correctly in the ordinary case but is a heuristic, not proof: an agent may act for reasons of its own.
184
+
185
+ The format is deliberately plain JSONL: greppable with the tools already on the machine, appendable by any other tool that wants to contribute events, and a torn final line costs one record rather than the file. Set `AIBROKER_AUDIT_FILE` to relocate it.
186
+
187
+ ### 9. Connect an adapter
156
188
 
157
189
  ```bash
158
190
  # WhatsApp
@@ -393,6 +425,7 @@ Addressing is explicit: `hub:machine-b/session:abc` routes through the bridge to
393
425
  | [mcp-tools.md](docs/mcp-tools.md) | All 42 MCP tools with parameters |
394
426
  | [adapters.md](docs/adapters.md) | Adapter development guide |
395
427
  | [pailot.md](docs/pailot.md) | PAILot iOS app integration |
428
+ | [todoist.md](docs/todoist.md) | Todoist inbound channel: webhook setup, routing, security model |
396
429
  | [mesh.md](docs/mesh.md) | Multi-machine mesh networking |
397
430
  | [ipc.md](docs/ipc.md) | IPC protocol and message format |
398
431
  | [tts-stt.md](docs/tts-stt.md) | Voice pipeline details |
@@ -0,0 +1,2 @@
1
+ export declare function runAudit(args: string[]): Promise<void>;
2
+ //# sourceMappingURL=audit-cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audit-cli.d.ts","sourceRoot":"","sources":["../../src/daemon/audit-cli.ts"],"names":[],"mappings":"AAoDA,wBAAsB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAqC5D"}
@@ -0,0 +1,90 @@
1
+ /**
2
+ * daemon/audit-cli.ts — `aibroker audit` — read the cross-session trail.
3
+ *
4
+ * Reads the file directly rather than going through the daemon: an audit trail
5
+ * you cannot inspect when the daemon is down is not much of an audit trail.
6
+ */
7
+ import { readAudit, auditPath } from "./audit.js";
8
+ function usage() {
9
+ console.log(`aibroker audit — what one session did to another
10
+
11
+ aibroker audit [--session NAME] [--action A] [--trace ID]
12
+ [--since ISO] [--limit N] [--bodies] [--json]
13
+
14
+ --session NAME only events where NAME acted or was acted upon
15
+ --action A send | dispatch | ask | launch | refuse
16
+ --trace ID follow one causation chain, both directions
17
+ --since ISO events at or after this timestamp (e.g. 2026-08-01)
18
+ --limit N last N events (default 40)
19
+ --bodies print full message bodies, not one-line previews
20
+ --json raw JSONL, for piping
21
+
22
+ Log: ${auditPath()}
23
+
24
+ Causation (--trace) is a heuristic: an action is attributed to the last
25
+ message its actor received. It reconstructs A→B→C chains in the ordinary
26
+ case; it is not proof that the message caused the action.`);
27
+ }
28
+ const ICON = {
29
+ send: "→", dispatch: "⇒", ask: "?", launch: "+", refuse: "✗",
30
+ };
31
+ function oneLine(s, max = 100) {
32
+ const flat = s.replace(/\s+/g, " ").trim();
33
+ return flat.length > max ? `${flat.slice(0, max - 1)}…` : flat;
34
+ }
35
+ function render(e, bodies) {
36
+ const time = e.ts.slice(11, 19);
37
+ const icon = ICON[e.action] ?? "·";
38
+ const chain = e.causedBy ? ` ⟵${e.causedBy}` : "";
39
+ console.log(`${time} [${e.id}]${chain} ${e.actor} ${icon} ${e.target} ${e.action}:${e.outcome}`);
40
+ if (e.reason)
41
+ console.log(` ${oneLine(e.reason, 110)}`);
42
+ if (e.body) {
43
+ if (bodies)
44
+ for (const l of e.body.split("\n"))
45
+ console.log(` | ${l}`);
46
+ else
47
+ console.log(` | ${oneLine(e.body)}`);
48
+ }
49
+ const reply = e.meta?.reply;
50
+ if (typeof reply === "string")
51
+ console.log(` < ${bodies ? reply : oneLine(reply)}`);
52
+ }
53
+ export async function runAudit(args) {
54
+ const has = (f) => args.includes(f);
55
+ const val = (f) => { const i = args.indexOf(f); return i >= 0 ? args[i + 1] : undefined; };
56
+ if (has("--help") || has("-h")) {
57
+ usage();
58
+ return;
59
+ }
60
+ const rawLimit = val("--limit");
61
+ const limit = rawLimit !== undefined ? Number(rawLimit) : 40;
62
+ if (!Number.isFinite(limit) || limit < 0) {
63
+ console.error(`--limit expects a non-negative number, got "${rawLimit}"`);
64
+ process.exitCode = 2;
65
+ return;
66
+ }
67
+ const events = readAudit({
68
+ session: val("--session"),
69
+ action: val("--action"),
70
+ trace: val("--trace"),
71
+ since: val("--since"),
72
+ // A trace is a whole chain; truncating it to the tail would hide the origin,
73
+ // which is the part you opened it for.
74
+ limit: has("--trace") ? undefined : limit,
75
+ });
76
+ if (has("--json")) {
77
+ for (const e of events)
78
+ console.log(JSON.stringify(e));
79
+ return;
80
+ }
81
+ if (events.length === 0) {
82
+ console.log(`No matching events in ${auditPath()}`);
83
+ return;
84
+ }
85
+ const bodies = has("--bodies");
86
+ for (const e of events)
87
+ render(e, bodies);
88
+ console.log(`\n${events.length} event(s). Follow a chain with: aibroker audit --trace <id>`);
89
+ }
90
+ //# sourceMappingURL=audit-cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audit-cli.js","sourceRoot":"","sources":["../../src/daemon/audit-cli.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,SAAS,EAAE,SAAS,EAAmB,MAAM,YAAY,CAAC;AAEnE,SAAS,KAAK;IACZ,OAAO,CAAC,GAAG,CAAC;;;;;;;;;;;;;OAaP,SAAS,EAAE;;;;0DAIwC,CAAC,CAAC;AAC5D,CAAC;AAED,MAAM,IAAI,GAA2B;IACnC,IAAI,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG;CAC7D,CAAC;AAEF,SAAS,OAAO,CAAC,CAAS,EAAE,GAAG,GAAG,GAAG;IACnC,MAAM,IAAI,GAAG,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;IAC3C,OAAO,IAAI,CAAC,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC;AACjE,CAAC;AAED,SAAS,MAAM,C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I,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;QAClB,KAAK,MAAM,CAAC,IAAI,MAAM;YAAE,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;QACvD,OAAO;IACT,CAAC;IAED,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxB,OAAO,CAAC,GAAG,CAAC,yBAAyB,SAAS,EAAE,EAAE,CAAC,CAAC;QACpD,OAAO;IACT,CAAC;IAED,MAAM,MAAM,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC;IAC/B,KAAK,MAAM,CAAC,IAAI,MAAM;QAAE,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;IAC1C,OAAO,CAAC,GAAG,CAAC,KAAK,MAAM,CAAC,MAAM,6DAA6D,CAAC,CAAC;AAC/F,CAAC"}
@@ -0,0 +1,82 @@
1
+ /**
2
+ * daemon/audit.ts — append-only record of what one session did to another.
3
+ *
4
+ * Cross-session action is now routine: a session can message another, dispatch
5
+ * work to it, probe it, launch a new one, or rename it. Chains form that nobody
6
+ * designed — an observation in one project reached a second session, which
7
+ * relayed it to a third that happened to be fixing exactly that defect. Useful,
8
+ * and entirely unplanned.
9
+ *
10
+ * The problem is that today the only record of any of it is each participant's
11
+ * own account. A session that acts on another and does not mention it leaves no
12
+ * trace; a session that ends takes its side of the story with it. "Why did work
13
+ * happen in a project nobody had touched for two weeks" was answerable only
14
+ * because the agent involved chose to say so. That is self-report, not audit.
15
+ *
16
+ * So: every daemon-mediated cross-session action is appended here as one JSON
17
+ * object per line, before and independently of whatever the actor later says
18
+ * about it.
19
+ *
20
+ * Design notes:
21
+ *
22
+ * - JSONL, not a database. Greppable with the tools already on the machine,
23
+ * appendable by anything (other agents and MCP servers can write their own
24
+ * events into the same file), and a truncated final line costs one record
25
+ * rather than the file.
26
+ * - Bodies are recorded in full. The body IS the "why" — a summary of a message
27
+ * is exactly the self-report this exists to replace.
28
+ * - Failures and REFUSALS are recorded too. "The hub declined to type this into
29
+ * a shell" is as much a part of the history as a delivery.
30
+ * - Causation is tracked but honestly labelled. Each session's most recent
31
+ * inbound message is remembered, and outgoing actions reference it as
32
+ * `causedBy`. That reconstructs A→B→C chains correctly in the common case and
33
+ * is a heuristic, not proof: an agent may act for reasons of its own.
34
+ */
35
+ export interface AuditEvent {
36
+ /** Unique id for this event; referenced by `causedBy` on downstream events. */
37
+ id: string;
38
+ ts: string;
39
+ /** What happened: send | dispatch | ask | launch | rename | refuse. */
40
+ action: string;
41
+ /** Who acted. Session label where known, else the raw caller id. */
42
+ actor: string;
43
+ /** What was acted upon. */
44
+ target: string;
45
+ /** delivered | spawned | refused | failed | … — verbatim from the operation. */
46
+ outcome: string;
47
+ /** Full message body, where the action carried one. */
48
+ body?: string;
49
+ /** Why it failed or was refused. */
50
+ reason?: string;
51
+ /** The inbound event this actor was most recently handed. Heuristic. */
52
+ causedBy?: string;
53
+ /** Anything action-specific. */
54
+ meta?: Record<string, unknown>;
55
+ }
56
+ /**
57
+ * Append one event. Never throws: auditing must not be able to break the
58
+ * operation it is recording.
59
+ */
60
+ export declare function audit(e: Omit<AuditEvent, "id" | "ts"> & {
61
+ id?: string;
62
+ }): string;
63
+ /**
64
+ * Note that `target` has just been handed something, so their next outgoing
65
+ * action can be attributed to it. This is what turns isolated events into a
66
+ * chain.
67
+ */
68
+ export declare function noteInbound(target: string, eventId: string): void;
69
+ export interface AuditQuery {
70
+ /** Only events where this string is the actor or the target. */
71
+ session?: string;
72
+ /** Only this action type. */
73
+ action?: string;
74
+ /** Follow a causation chain from this event id, in both directions. */
75
+ trace?: string;
76
+ /** ISO timestamp lower bound. */
77
+ since?: string;
78
+ limit?: number;
79
+ }
80
+ export declare function readAudit(q?: AuditQuery): AuditEvent[];
81
+ export declare function auditPath(): string;
82
+ //# sourceMappingURL=audit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audit.d.ts","sourceRoot":"","sources":["../../src/da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"}
@@ -0,0 +1,143 @@
1
+ /**
2
+ * daemon/audit.ts — append-only record of what one session did to another.
3
+ *
4
+ * Cross-session action is now routine: a session can message another, dispatch
5
+ * work to it, probe it, launch a new one, or rename it. Chains form that nobody
6
+ * designed — an observation in one project reached a second session, which
7
+ * relayed it to a third that happened to be fixing exactly that defect. Useful,
8
+ * and entirely unplanned.
9
+ *
10
+ * The problem is that today the only record of any of it is each participant's
11
+ * own account. A session that acts on another and does not mention it leaves no
12
+ * trace; a session that ends takes its side of the story with it. "Why did work
13
+ * happen in a project nobody had touched for two weeks" was answerable only
14
+ * because the agent involved chose to say so. That is self-report, not audit.
15
+ *
16
+ * So: every daemon-mediated cross-session action is appended here as one JSON
17
+ * object per line, before and independently of whatever the actor later says
18
+ * about it.
19
+ *
20
+ * Design notes:
21
+ *
22
+ * - JSONL, not a database. Greppable with the tools already on the machine,
23
+ * appendable by anything (other agents and MCP servers can write their own
24
+ * events into the same file), and a truncated final line costs one record
25
+ * rather than the file.
26
+ * - Bodies are recorded in full. The body IS the "why" — a summary of a message
27
+ * is exactly the self-report this exists to replace.
28
+ * - Failures and REFUSALS are recorded too. "The hub declined to type this into
29
+ * a shell" is as much a part of the history as a delivery.
30
+ * - Causation is tracked but honestly labelled. Each session's most recent
31
+ * inbound message is remembered, and outgoing actions reference it as
32
+ * `causedBy`. That reconstructs A→B→C chains correctly in the common case and
33
+ * is a heuristic, not proof: an agent may act for reasons of its own.
34
+ */
35
+ import { appendFileSync, mkdirSync, existsSync, statSync, renameSync, readFileSync } from "node:fs";
36
+ import { homedir } from "node:os";
37
+ import { join, dirname } from "node:path";
38
+ import { randomUUID } from "node:crypto";
39
+ import { log } from "../core/log.js";
40
+ /**
41
+ * Overridable so tests never append to the real trail. An audit log polluted
42
+ * with fixtures is one you stop trusting, which defeats the purpose.
43
+ */
44
+ const AUDIT_FILE = process.env.AIBROKER_AUDIT_FILE
45
+ ?? join(homedir(), ".aibroker", "audit.jsonl");
46
+ const AUDIT_DIR = dirname(AUDIT_FILE);
47
+ /** Rotate past this so the live file stays greppable. */
48
+ const MAX_BYTES = 32 * 1024 * 1024;
49
+ /** actor -> id of the last message delivered TO them, for causation chaining. */
50
+ const lastInbound = new Map();
51
+ function rotateIfNeeded() {
52
+ try {
53
+ if (existsSync(AUDIT_FILE) && statSync(AUDIT_FILE).size > MAX_BYTES) {
54
+ renameSync(AUDIT_FILE, `${AUDIT_FILE}.1`);
55
+ }
56
+ }
57
+ catch { /* rotation is best effort; never block the write */ }
58
+ }
59
+ /**
60
+ * Append one event. Never throws: auditing must not be able to break the
61
+ * operation it is recording.
62
+ */
63
+ export function audit(e) {
64
+ const id = e.id ?? randomUUID().slice(0, 8);
65
+ const event = {
66
+ id,
67
+ ts: new Date().toISOString(),
68
+ ...e,
69
+ causedBy: e.causedBy ?? lastInbound.get(e.actor),
70
+ };
71
+ try {
72
+ mkdirSync(AUDIT_DIR, { recursive: true });
73
+ rotateIfNeeded();
74
+ appendFileSync(AUDIT_FILE, JSON.stringify(event) + "\n", "utf-8");
75
+ }
76
+ catch (err) {
77
+ log(`audit: failed to record ${e.action} (${err instanceof Error ? err.message : String(err)})`);
78
+ }
79
+ return id;
80
+ }
81
+ /**
82
+ * Note that `target` has just been handed something, so their next outgoing
83
+ * action can be attributed to it. This is what turns isolated events into a
84
+ * chain.
85
+ */
86
+ export function noteInbound(target, eventId) {
87
+ if (target)
88
+ lastInbound.set(target, eventId);
89
+ }
90
+ export function readAudit(q = {}) {
91
+ if (!existsSync(AUDIT_FILE))
92
+ return [];
93
+ let events;
94
+ try {
95
+ events = readFileSync(AUDIT_FILE, "utf-8")
96
+ .split("\n")
97
+ .filter((l) => l.trim().length > 0)
98
+ .map((l) => { try {
99
+ return JSON.parse(l);
100
+ }
101
+ catch {
102
+ return null;
103
+ } })
104
+ .filter((e) => e !== null);
105
+ }
106
+ catch {
107
+ return [];
108
+ }
109
+ if (q.trace) {
110
+ // Walk the chain both ways: what led here, and what this led to.
111
+ const byId = new Map(events.map((e) => [e.id, e]));
112
+ const keep = new Set();
113
+ let cur = byId.get(q.trace);
114
+ while (cur) {
115
+ keep.add(cur.id);
116
+ cur = cur.causedBy ? byId.get(cur.causedBy) : undefined;
117
+ }
118
+ let grew = true;
119
+ while (grew) {
120
+ grew = false;
121
+ for (const e of events) {
122
+ if (e.causedBy && keep.has(e.causedBy) && !keep.has(e.id)) {
123
+ keep.add(e.id);
124
+ grew = true;
125
+ }
126
+ }
127
+ }
128
+ events = events.filter((e) => keep.has(e.id));
129
+ }
130
+ const lower = q.session?.toLowerCase();
131
+ events = events.filter((e) => {
132
+ if (q.action && e.action !== q.action)
133
+ return false;
134
+ if (q.since && e.ts < q.since)
135
+ return false;
136
+ if (lower && !e.actor.toLowerCase().includes(lower) && !e.target.toLowerCase().includes(lower))
137
+ return false;
138
+ return true;
139
+ });
140
+ return q.limit ? events.slice(-q.limit) : events;
141
+ }
142
+ export function auditPath() { return AUDIT_FILE; }
143
+ //# sourceMappingURL=audit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audit.js","sourceRoot":"","sources":["../../src/daemon/audit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEH,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACpG,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAErC;;;GAGG;AACH,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,mBAAmB;OAC7C,IAAI,CAAC,OAAO,EAAE,EAAE,WAAW,EAAE,aAAa,CAAC,CAAC;AACjD,MAAM,SAAS,GAAG,O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CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC;YAAE,OAAO,KAAK,CAAC;QAC7G,OAAO,IAAI,CAAC;IACd,CAAC,CAAC,CAAC;IAEH,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;AACnD,CAAC;AAED,MAAM,UAAU,SAAS,KAAa,OAAO,UAAU,CAAC,CAAC,CAAC"}
@@ -135,6 +135,11 @@ switch (command) {
135
135
  await runAsk(rest);
136
136
  break;
137
137
  }
138
+ case "audit": {
139
+ const { runAudit } = await import("./audit-cli.js");
140
+ await runAudit(rest);
141
+ break;
142
+ }
138
143
  case "create-adapter": {
139
144
  // Parse arguments: name, --display-name <Name>, --output <dir>
140
145
  const adapterName = rest.find((a) => !a.startsWith("--"));
@@ -168,13 +173,14 @@ switch (command) {
168
173
  console.log(" sessions <sub> Session backup: snapshot|restore|checkpoint|list|install");
169
174
  console.log(" dispatch <project> Deliver a work order to a project's session (--stdin --json)");
170
175
  console.log(" ask <project> Ask a session a question and wait for its reply (--stdin --json)");
176
+ console.log(" audit What one session did to another (--session|--trace|--bodies)");
171
177
  console.log(" help Show this help");
172
178
  console.log("\nFlags:");
173
179
  console.log(" --version, -v Show version");
174
180
  break;
175
181
  default:
176
182
  console.error(`Unknown command: ${command}`);
177
- console.error("Usage: aibroker [start|status|stop|ping|create-adapter|ota|sessions|dispatch|ask|help]");
183
+ console.error("Usage: aibroker [start|status|stop|ping|create-adapter|ota|sessions|dispatch|ask|audit|help]");
178
184
  process.exit(1);
179
185
  }
180
186
  //# sourceMappingURL=cli.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/daemon/cli.ts"],"names":[],"mappings":";AACA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO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AAK,CAAC,8FAA8F,CAAC,CAAC;QAC9G,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACpB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"core-handlers.d.ts","sourceRoot":"","sources":["../../src/daemon/core-handlers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAqC9D,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,SAAS,EACjB,QAAQ,EAAE,eAAe,EACzB,WAAW,EAAE,UAAU,EACvB,OAAO,EAAE,oBAAoB,GAC5B,IAAI,CA2tCN"}
1
+ {"version":3,"file":"core-handlers.d.ts","sourceRoot":"","sources":["../../src/daemon/core-handlers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AA0D9D,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,SAAS,EACjB,QAAQ,EAAE,eAAe,EACzB,WAAW,EAAE,UAAU,EACvB,OAAO,EAAE,oBAAoB,GAC5B,IAAI,CA8wCN"}
@@ -31,6 +31,7 @@ import { readSessionContent, readAllSessionContent } from "./session-content.js"
31
31
  import { statusCache, hashContent } from "../core/status-cache.js";
32
32
  import { clearAllPaiNames } from "../adapters/iterm/core.js";
33
33
  import { snapshotAllSessions, typeIntoSession, setSessionTitle, itermViewerSessionId, aibrokerIdForPane, isClaudeSession } from "../transport/sync-facade.js";
34
+ import { audit, noteInbound } from "./audit.js";
34
35
  import { setItermSessionVar, setItermTabName, setItermBadge } from "../adapters/iterm/sessions.js";
35
36
  import { log } from "../core/log.js";
36
37
  import { readFileSync } from "node:fs";
@@ -48,6 +49,24 @@ function getPackageVersion() {
48
49
  }
49
50
  }
50
51
  const HUB_VERSION = getPackageVersion();
52
+ /**
53
+ * Best human-readable identity for whoever made this call, for the audit trail.
54
+ *
55
+ * Falls back through raw ids rather than to "unknown": an unattributed action
56
+ * is the thing the audit log exists to prevent, so a GUID beats a blank.
57
+ */
58
+ function callerLabel(req) {
59
+ const raw = req.itermSessionId;
60
+ const id = raw ? (raw.includes(":") ? raw.split(":").pop() : raw) : undefined;
61
+ if (id) {
62
+ const snap = snapshotAllSessions().find((s) => s.id === id);
63
+ if (snap) {
64
+ const paiName = lookupPersistentName(getAllPersistentSessionNames(), snap.id, snap.aibrokerId);
65
+ return paiName ?? snap.name;
66
+ }
67
+ }
68
+ return id ?? req.tmuxPane ?? req.sessionId ?? "unknown";
69
+ }
51
70
  export function registerCoreHandlers(server, registry, _apiBackend, manager) {
52
71
  server.on("register_adapter", async (req) => {
53
72
  const { name, socketPath } = req.params;
@@ -294,12 +313,24 @@ export function registerCoreHandlers(server, registry, _apiBackend, manager) {
294
313
  if (!message)
295
314
  return { ok: false, error: "message is required" };
296
315
  const { dispatch } = await import("./dispatch.js");
316
+ const actor = callerLabel(req);
297
317
  try {
298
318
  const result = await dispatch(project, message, { noSpawn, budgetMs, spawnTimeoutMs, deliverTimeoutMs });
319
+ const eventId = audit({
320
+ action: "dispatch", actor, target: result.session || project,
321
+ outcome: result.outcome, body: message,
322
+ reason: result.reason || undefined,
323
+ meta: { project: result.project },
324
+ });
325
+ if (result.outcome === "delivered" || result.outcome === "spawned") {
326
+ noteInbound(result.session, eventId);
327
+ }
299
328
  return { ok: true, result: { ...result } };
300
329
  }
301
330
  catch (err) {
302
- return { ok: false, error: err instanceof Error ? err.message : String(err) };
331
+ const reason = err instanceof Error ? err.message : String(err);
332
+ audit({ action: "dispatch", actor, target: project, outcome: "failed", body: message, reason });
333
+ return { ok: false, error: reason };
303
334
  }
304
335
  });
305
336
  /**
@@ -315,12 +346,23 @@ export function registerCoreHandlers(server, registry, _apiBackend, manager) {
315
346
  if (!question)
316
347
  return { ok: false, error: "question is required" };
317
348
  const { ask } = await import("./ask.js");
349
+ const actor = callerLabel(req);
318
350
  try {
319
351
  const result = await ask(project, question, { timeoutMs });
352
+ audit({
353
+ action: "ask", actor, target: result.session || project,
354
+ outcome: result.state, body: question,
355
+ reason: result.reason || undefined,
356
+ // The answer is the substance of the exchange; without it the record
357
+ // shows that a question was asked but not what came back.
358
+ meta: result.reply ? { reply: result.reply } : undefined,
359
+ });
320
360
  return { ok: true, result: { ...result } };
321
361
  }
322
362
  catch (err) {
323
- return { ok: false, error: err instanceof Error ? err.message : String(err) };
363
+ const reason = err instanceof Error ? err.message : String(err);
364
+ audit({ action: "ask", actor, target: project, outcome: "failed", body: question, reason });
365
+ return { ok: false, error: reason };
324
366
  }
325
367
  });
326
368
  server.on("pai_launch", async (req) => {
@@ -333,8 +375,16 @@ export function registerCoreHandlers(server, registry, _apiBackend, manager) {
333
375
  ({ itermSessionId, sessionId } = await launchPaiProject(name));
334
376
  }
335
377
  catch (err) {
336
- return { ok: false, error: err instanceof Error ? err.message : String(err) };
378
+ const reason = err instanceof Error ? err.message : String(err);
379
+ audit({ action: "launch", actor: callerLabel(req), target: name, outcome: "failed", reason });
380
+ return { ok: false, error: reason };
337
381
  }
382
+ // Creating a session is a cross-session action: it puts a new agent on the
383
+ // machine, in a directory, doing work nobody may be watching.
384
+ audit({
385
+ action: "launch", actor: callerLabel(req), target: name, outcome: "spawned",
386
+ meta: { itermSessionId },
387
+ });
338
388
  // Register the visual session with HybridSessionManager
339
389
  const project = await findPaiProject(name);
340
390
  const displayName = project?.displayName || project?.name || name;
@@ -770,6 +820,14 @@ export function registerCoreHandlers(server, registry, _apiBackend, manager) {
770
820
  // is not merely undeliverable, it is executable. Say so plainly rather than
771
821
  // reporting a generic write failure.
772
822
  if (!isClaudeSession(itermSessionId)) {
823
+ // Recorded: a refusal is part of the history too, and "the hub declined
824
+ // to type this into a shell" is exactly the kind of thing that otherwise
825
+ // leaves no trace anywhere.
826
+ audit({
827
+ action: "refuse", actor: senderLabel, target: resolvedName ?? target,
828
+ outcome: "refused", body: message,
829
+ reason: "target terminal is a shell, not a live Claude prompt",
830
+ });
773
831
  return {
774
832
  ok: false,
775
833
  error: `Session "${resolvedName}" is not running Claude — its terminal is at a shell prompt, ` +
@@ -785,8 +843,19 @@ export function registerCoreHandlers(server, registry, _apiBackend, manager) {
785
843
  // Also type into the terminal (ensures text appears even if target isn't polling mailbox)
786
844
  const success = typeIntoSession(itermSessionId, prefixedMessage);
787
845
  if (!success) {
846
+ audit({
847
+ action: "send", actor: senderLabel, target: resolvedName ?? target,
848
+ outcome: "failed", body: message, reason: "write to session failed",
849
+ });
788
850
  return { ok: false, error: `Failed to type into session "${resolvedName}" (${itermSessionId})` };
789
851
  }
852
+ const eventId = audit({
853
+ action: "send", actor: senderLabel, target: resolvedName ?? target,
854
+ outcome: "delivered", body: message,
855
+ });
856
+ // The recipient's next outgoing action can now be attributed to this one,
857
+ // which is what turns isolated events into a traceable chain.
858
+ noteInbound(resolvedName ?? target, eventId);
790
859
  return { ok: true, result: { sent: true, sessionId: itermSessionId, name: resolvedName } };
791
860
  });
792
861
  /**