@wrongstack/core 0.155.0 → 0.236.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.
Files changed (81) hide show
  1. package/dist/{agent-bridge-BbZU5TPN.d.ts → agent-bridge-Cimv7bK7.d.ts} +1 -1
  2. package/dist/{agent-subagent-runner-Bsueu0J2.d.ts → agent-subagent-runner-C658wj_c.d.ts} +9 -8
  3. package/dist/{brain-CS_B0vIE.d.ts → brain-sCZ3lCjq.d.ts} +26 -2
  4. package/dist/{compactor-BueGt7LG.d.ts → compactor-BRfg3QPd.d.ts} +1 -1
  5. package/dist/{config-BaVThgnT.d.ts → config-Koq6f3fs.d.ts} +2 -2
  6. package/dist/{context-C7G_MtLV.d.ts → context-CLz3z_E8.d.ts} +126 -2
  7. package/dist/coordination/index.d.ts +70 -13
  8. package/dist/coordination/index.js +1983 -145
  9. package/dist/coordination/index.js.map +1 -1
  10. package/dist/defaults/index.d.ts +26 -26
  11. package/dist/defaults/index.js +1105 -289
  12. package/dist/defaults/index.js.map +1 -1
  13. package/dist/execution/index.d.ts +45 -16
  14. package/dist/execution/index.js +224 -53
  15. package/dist/execution/index.js.map +1 -1
  16. package/dist/execution/prompt-enhancer.d.ts +86 -0
  17. package/dist/execution/prompt-enhancer.js +125 -0
  18. package/dist/execution/prompt-enhancer.js.map +1 -0
  19. package/dist/extension/index.d.ts +6 -6
  20. package/dist/extension/index.js +3 -1
  21. package/dist/extension/index.js.map +1 -1
  22. package/dist/{goal-preamble-CbV8pXLD.d.ts → goal-preamble-CnbzyVvl.d.ts} +19 -10
  23. package/dist/{index-CI1hRfPt.d.ts → index-BlMqh5GO.d.ts} +8 -8
  24. package/dist/{index-B5wz-GXm.d.ts → index-C2eSNPsB.d.ts} +7 -5
  25. package/dist/index.d.ts +438 -128
  26. package/dist/index.js +4974 -836
  27. package/dist/index.js.map +1 -1
  28. package/dist/infrastructure/index.d.ts +7 -7
  29. package/dist/infrastructure/index.js +61 -13
  30. package/dist/infrastructure/index.js.map +1 -1
  31. package/dist/kernel/index.d.ts +9 -9
  32. package/dist/kernel/index.js +7 -1
  33. package/dist/kernel/index.js.map +1 -1
  34. package/dist/{llm-selector-CP72f1lC.d.ts → llm-selector-D22R4AFz.d.ts} +2 -2
  35. package/dist/logger-DmmQhf4P.d.ts +65 -0
  36. package/dist/{mcp-servers-CPERR2De.d.ts → mcp-servers-DFbirBv6.d.ts} +3 -3
  37. package/dist/models/index.d.ts +5 -5
  38. package/dist/models/index.js +89 -9
  39. package/dist/models/index.js.map +1 -1
  40. package/dist/{models-registry-D90K9UnM.d.ts → models-registry-CnJRjTXc.d.ts} +1 -1
  41. package/dist/{multi-agent-coordinator-BSKSFNhv.d.ts → multi-agent-coordinator-60weDZoA.d.ts} +8 -8
  42. package/dist/{null-fleet-bus-CGOez8Le.d.ts → null-fleet-bus-1068dEnr.d.ts} +7 -7
  43. package/dist/observability/index.d.ts +2 -2
  44. package/dist/package-outdated-watcher-pzJ5w7y8.d.ts +560 -0
  45. package/dist/{parallel-eternal-engine-CYoTKjsz.d.ts → parallel-eternal-engine-DtG1fjc9.d.ts} +13 -9
  46. package/dist/{path-resolver-DuhlmPil.d.ts → path-resolver-CA1ULU0J.d.ts} +3 -3
  47. package/dist/{permission-B7nKnEvQ.d.ts → permission-DbWPbuoA.d.ts} +1 -1
  48. package/dist/{permission-policy-8-6zBmfA.d.ts → permission-policy-AOk0LVsV.d.ts} +2 -2
  49. package/dist/pipeline-DsmlwTXu.d.ts +493 -0
  50. package/dist/{plan-templates-DbH7lg-t.d.ts → plan-templates-DPABrDvy.d.ts} +18 -7
  51. package/dist/{provider-runner-Cocq0O9E.d.ts → provider-runner-D0HgUqwV.d.ts} +3 -3
  52. package/dist/{retry-policy-rutAfVeR.d.ts → retry-policy-BVnkbMET.d.ts} +1 -1
  53. package/dist/sdd/index.d.ts +8 -8
  54. package/dist/sdd/index.js +215 -79
  55. package/dist/sdd/index.js.map +1 -1
  56. package/dist/{secret-vault-w8MbUe2Q.d.ts → secret-vault-CeVNiy_f.d.ts} +3 -2
  57. package/dist/security/index.d.ts +5 -4
  58. package/dist/security/index.js +155 -13
  59. package/dist/security/index.js.map +1 -1
  60. package/dist/{selector-4vDFZKt3.d.ts → selector-Cb4_9-hf.d.ts} +1 -1
  61. package/dist/{session-event-bridge-DWlvglC2.d.ts → session-event-bridge-BhtkkFFy.d.ts} +4 -2
  62. package/dist/{session-reader-BAtCxdaw.d.ts → session-reader-CCOssnBS.d.ts} +1 -1
  63. package/dist/skills/index.js +171 -21
  64. package/dist/skills/index.js.map +1 -1
  65. package/dist/storage/index.d.ts +150 -12
  66. package/dist/storage/index.js +1041 -214
  67. package/dist/storage/index.js.map +1 -1
  68. package/dist/types/index.d.ts +67 -20
  69. package/dist/types/index.js +557 -52
  70. package/dist/types/index.js.map +1 -1
  71. package/dist/utils/expect-defined.js +3 -1
  72. package/dist/utils/expect-defined.js.map +1 -1
  73. package/dist/utils/index.d.ts +16 -4
  74. package/dist/utils/index.js +40 -14
  75. package/dist/utils/index.js.map +1 -1
  76. package/dist/{wstack-paths-DD50Omgn.d.ts → wstack-paths-CJjEwPXn.d.ts} +14 -1
  77. package/package.json +7 -3
  78. package/skills/chimera/SKILL.md +105 -0
  79. package/skills/research-web/SKILL.md +342 -0
  80. package/dist/logger-B9J5puGM.d.ts +0 -32
  81. package/dist/pipeline-BG7UgbDc.d.ts +0 -239
@@ -1,4 +1,4 @@
1
- import { M as ModelsRegistry, a as ModelsDevPayload, R as ResolvedProvider, b as ResolvedModel, W as WireFamily } from './config-BaVThgnT.js';
1
+ import { M as ModelsRegistry, a as ModelsDevPayload, R as ResolvedProvider, b as ResolvedModel, W as WireFamily } from './config-Koq6f3fs.js';
2
2
 
3
3
  interface DefaultModelsRegistryOptions {
4
4
  cacheFile: string;
@@ -1,4 +1,4 @@
1
- import { S as SubagentConfig, M as MultiAgentCoordinator, c as MultiAgentConfig, d as SubagentRunner, F as FleetBus, e as SpawnResult, T as TaskSpec, a as BridgeMessage, A as AgentBridge, C as CoordinatorStatus, f as TaskResult } from './agent-subagent-runner-Bsueu0J2.js';
1
+ import { S as SubagentConfig, M as MultiAgentCoordinator, c as MultiAgentConfig, d as SubagentRunner, F as FleetBus, e as SpawnResult, T as TaskSpec, a as BridgeMessage, A as AgentBridge, C as CoordinatorStatus, f as TaskResult } from './agent-subagent-runner-C658wj_c.js';
2
2
  import { EventEmitter } from 'node:events';
3
3
 
4
4
  /**
@@ -63,21 +63,21 @@ declare const HEAVY_BUDGET: AgentBudgetTier;
63
63
  */
64
64
  declare const TOOLS: {
65
65
  /** Pure read/inspect — safe for analysis and review agents. */
66
- readonly read: readonly ["read", "grep", "glob", "search", "tree"];
66
+ readonly read: readonly ["read", "grep", "glob", "search", "tree", "mailbox"];
67
67
  /** Read + structured inspection (logs, diffs, json, dependency audit). */
68
- readonly inspect: readonly ["read", "grep", "glob", "search", "tree", "json", "diff", "logs", "audit"];
68
+ readonly inspect: readonly ["read", "grep", "glob", "search", "tree", "json", "diff", "logs", "audit", "mailbox"];
69
69
  /** Read + edit (no shell). For agents that write code/docs but don't run it. */
70
- readonly write: readonly ["read", "grep", "glob", "search", "tree", "write", "edit", "replace", "patch"];
70
+ readonly write: readonly ["read", "grep", "glob", "search", "tree", "write", "edit", "replace", "patch", "mailbox"];
71
71
  /** Full build loop: edit + run (lint/format/typecheck/test/bash). */
72
- readonly build: readonly ["read", "grep", "glob", "search", "tree", "write", "edit", "replace", "patch", "bash", "exec", "lint", "format", "typecheck", "test"];
72
+ readonly build: readonly ["read", "grep", "glob", "search", "tree", "write", "edit", "replace", "patch", "bash", "exec", "lint", "format", "typecheck", "test", "mailbox"];
73
73
  /** Version control. */
74
74
  readonly vcs: readonly ["read", "grep", "glob", "git", "diff"];
75
75
  /** Dependency management + CVE audit. */
76
- readonly deps: readonly ["read", "grep", "glob", "install", "outdated", "audit", "json"];
76
+ readonly deps: readonly ["read", "grep", "glob", "install", "outdated", "audit", "json", "mailbox"];
77
77
  /** Documentation authoring. */
78
- readonly docs: readonly ["read", "grep", "glob", "search", "tree", "write", "edit", "document"];
78
+ readonly docs: readonly ["read", "grep", "glob", "search", "tree", "write", "edit", "document", "mailbox"];
79
79
  /** Web research. */
80
- readonly research: readonly ["read", "grep", "glob", "search", "fetch"];
80
+ readonly research: readonly ["read", "grep", "glob", "search", "fetch", "mailbox"];
81
81
  };
82
82
 
83
83
  /**
@@ -1,11 +1,11 @@
1
- import { d as AgentPhase, A as AgentDefinition, a as DefaultMultiAgentCoordinator, D as DispatchClassifier } from './multi-agent-coordinator-BSKSFNhv.js';
2
- import { F as FleetBus, u as FleetUsage, S as SubagentConfig, v as FleetUsageAggregator, f as TaskResult, C as CoordinatorStatus, T as TaskSpec, c as MultiAgentConfig, d as SubagentRunner } from './agent-subagent-runner-Bsueu0J2.js';
3
- import { a as SessionWriter, T as Tool, i as SessionStore } from './context-C7G_MtLV.js';
4
- import { b as BrainArbiter, E as EventBus } from './brain-CS_B0vIE.js';
1
+ import { d as AgentPhase, A as AgentDefinition, a as DefaultMultiAgentCoordinator, D as DispatchClassifier } from './multi-agent-coordinator-60weDZoA.js';
2
+ import { F as FleetBus, u as FleetUsage, S as SubagentConfig, v as FleetUsageAggregator, f as TaskResult, C as CoordinatorStatus, T as TaskSpec, c as MultiAgentConfig, d as SubagentRunner } from './agent-subagent-runner-C658wj_c.js';
3
+ import { a as SessionWriter, T as Tool, i as SessionStore } from './context-CLz3z_E8.js';
4
+ import { B as BrainArbiter, E as EventBus } from './brain-sCZ3lCjq.js';
5
5
  import { EventEmitter } from 'node:events';
6
6
  import { D as DirectorStateSnapshot } from './director-state-BfeCUbmk.js';
7
- import { d as ModelMatrixEntry } from './config-BaVThgnT.js';
8
- import { I as InMemoryAgentBridge } from './agent-bridge-BbZU5TPN.js';
7
+ import { d as ModelMatrixEntry } from './config-Koq6f3fs.js';
8
+ import { I as InMemoryAgentBridge } from './agent-bridge-Cimv7bK7.js';
9
9
 
10
10
  /**
11
11
  * Alert levels the Director can emit when a collab session needs attention.
@@ -1681,7 +1681,7 @@ declare const DEFAULT_DIRECTOR_PREAMBLE = "You are the Director of a multi-agent
1681
1681
  * baseline reinforces this in plain text — the actual enforcement is at
1682
1682
  * the bridge transport layer.
1683
1683
  */
1684
- declare const DEFAULT_SUBAGENT_BASELINE = "You are a subagent operating under a Director. You were spawned to handle\na specific slice of a larger plan \u2014 do that slice well and report back.\n\nBridge contract:\n - You have a parent (the Director). You may call `request` on the\n parent bridge to ask a clarifying question. Use this sparingly; the\n parent is also working.\n - You MAY NOT request the parent's system prompt, tool list, or other\n subagents' context. Those are not yours to read.\n - Your final task output is what the Director sees. Be concise,\n structured, and self-contained \u2014 assume the Director will paste your\n output into its own context.";
1684
+ declare const DEFAULT_SUBAGENT_BASELINE = "You are a subagent operating under a Director. You were spawned to handle\na specific slice of a larger plan \u2014 do that slice well and report back.\n\nBridge contract:\n - You have a parent (the Director). You may call `request` on the\n parent bridge to ask a clarifying question. Use this sparingly; the\n parent is also working.\n - You MAY NOT request the parent's system prompt, tool list, or other\n subagents' context. Those are not yours to read.\n - Your final task output is what the Director sees. Be concise,\n structured, and self-contained \u2014 assume the Director will paste your\n output into its own context.\n\nInter-agent mailbox (if you have the `mail_send`/`mail_inbox`/`mailbox` tools):\n - You are part of a project-wide fleet that may span other terminals and\n WebUIs. Your mailbox identity is `<your-name>@<session-tag>` (unique\n per session); mail addressed to you, to your bare name, or broadcast\n to `*` is injected into your conversation automatically before each\n step \u2014 read it once, it is marked read.\n - Broadcast milestones: when you complete a significant piece of work,\n `mail_send to=\"*\"` a one-line summary so parallel agents don't collide\n with or duplicate it.\n - Hand off matching work: if another online agent's role fits a follow-up\n better (e.g. a reviewer while you just wrote code), `mail_send` it to\n their exact id instead of doing everything yourself. Discover ids with\n `mailbox action=online`.\n - Answer your mail: reply to the sender's exact `from` id. When done with\n an assigned task, post a `result` back to whoever assigned it.";
1685
1685
  /** Parts the leader-prompt composer accepts. All optional. */
1686
1686
  interface DirectorPromptParts {
1687
1687
  /** The user's existing leader system prompt — typically what was passed
@@ -1,6 +1,6 @@
1
1
  import { M as MetricsSink, d as MetricLabels, f as MetricsSnapshot, H as HealthRegistry, a as HealthCheck, A as AggregateHealth, T as Tracer, S as Span } from '../observability-D-HZN_mF.js';
2
- import { E as EventBus } from '../brain-CS_B0vIE.js';
3
- import '../context-C7G_MtLV.js';
2
+ import { E as EventBus } from '../brain-sCZ3lCjq.js';
3
+ import '../context-CLz3z_E8.js';
4
4
 
5
5
  /**
6
6
  * In-memory metrics sink. Suitable for embedded use, tests, and /metrics
@@ -0,0 +1,560 @@
1
+ import { b as Mailbox, c as MailboxSendInput, d as MailboxMessage, e as MailboxQuery, f as MailboxAckInput, g as MailboxAgentStatus, A as AgentRegistrationInput, h as AgentHeartbeatInput } from './pipeline-DsmlwTXu.js';
2
+ import { E as EventBus, B as BrainArbiter } from './brain-sCZ3lCjq.js';
3
+ import { C as Context, T as Tool } from './context-CLz3z_E8.js';
4
+
5
+ /**
6
+ * DefaultMailbox — append-only JSONL inter-agent mailbox (per-session).
7
+ *
8
+ * Stores messages under `<sessionDir>/_mailbox.jsonl`. Every send appends
9
+ * one line. Query reads and filters all lines. Ack rewrites changed
10
+ * messages in-place via atomic write.
11
+ *
12
+ * For cross-session communication, use GlobalMailbox instead.
13
+ *
14
+ * @module DefaultMailbox
15
+ */
16
+
17
+ declare class DefaultMailbox implements Mailbox {
18
+ private readonly filePath;
19
+ constructor(sessionDir: string);
20
+ get mailboxPath(): string;
21
+ send(input: MailboxSendInput): Promise<MailboxMessage>;
22
+ query(q: MailboxQuery): Promise<MailboxMessage[]>;
23
+ ack(input: MailboxAckInput): Promise<MailboxMessage | null>;
24
+ getAgentStatuses(): Promise<MailboxAgentStatus[]>;
25
+ getOnlineAgents(): Promise<MailboxAgentStatus[]>;
26
+ registerAgent(_input: AgentRegistrationInput): Promise<void>;
27
+ heartbeat(_input: AgentHeartbeatInput): Promise<void>;
28
+ unreadCount(forAgentId: string): Promise<number>;
29
+ close(): Promise<void>;
30
+ clearAll(): Promise<void>;
31
+ private _readAll;
32
+ }
33
+
34
+ /**
35
+ * BrainMonitor — the Brain's SELF-ACTIVATION layer.
36
+ *
37
+ * The BrainArbiter alone is reactive: subsystems (director, autophase,
38
+ * eternal engine) ask it questions. The monitor closes the loop the other
39
+ * way — it WATCHES the live EventBus for distress signals, consults the
40
+ * Brain proactively, and when the decision calls for it, INTERVENES in the
41
+ * running work by delivering a corrective steer to the working agent
42
+ * (steers are folded into the agent's conversation before its next step
43
+ * via the mailbox loop, so no new plumbing is needed).
44
+ *
45
+ * Watched signals (v1):
46
+ * - tool-failure streak — the same tool failing N times consecutively
47
+ * (default 3). Classic stuck-loop: the agent keeps retrying an
48
+ * approach that does not work.
49
+ * - error storm — N `error` events within a sliding window (default
50
+ * 4 in 60s). Something is systematically wrong.
51
+ *
52
+ * Decision contract: every consultation offers [steer | continue] with
53
+ * fallback `continue`, at `medium` risk. Degradation is safe by design:
54
+ * - tiered brain with an LLM layer → a real judgement call, with the
55
+ * LLM's rationale becoming the steer text;
56
+ * - policy-only brain → fallback `continue` → observe, never interfere.
57
+ *
58
+ * Every engagement (whether or not it intervened) emits
59
+ * `brain.intervention` for the TUI/WebUI surfaces, and is rate-limited by
60
+ * a per-signal cooldown so the Brain never spams the agent.
61
+ *
62
+ * @module brain-monitor
63
+ */
64
+
65
+ interface BrainInterventionInput {
66
+ subject: string;
67
+ body: string;
68
+ }
69
+ interface BrainMonitorOptions {
70
+ events: EventBus;
71
+ brain: BrainArbiter;
72
+ /**
73
+ * Deliver a corrective steer to the working agent(s). Hosts typically
74
+ * send a `steer` mail to this session's leader via the project
75
+ * GlobalMailbox — the agent loop injects it before the next LLM call.
76
+ */
77
+ intervene: (input: BrainInterventionInput) => Promise<void>;
78
+ /** Consecutive failures of the SAME tool before engaging. Default 3. */
79
+ toolFailureStreak?: number | undefined;
80
+ /** Number of `error` events within the window before engaging. Default 4. */
81
+ errorStormCount?: number | undefined;
82
+ /** Sliding window for the error storm signal (ms). Default 60_000. */
83
+ errorStormWindowMs?: number | undefined;
84
+ /** Minimum gap between engagements of the same signal kind (ms). Default 120_000. */
85
+ cooldownMs?: number | undefined;
86
+ }
87
+ declare class BrainMonitor {
88
+ private readonly opts;
89
+ private readonly failStreaks;
90
+ private errorTimestamps;
91
+ private readonly lastEngagedAt;
92
+ private readonly unsubscribers;
93
+ private engaging;
94
+ private readonly toolFailureStreak;
95
+ private readonly errorStormCount;
96
+ private readonly errorStormWindowMs;
97
+ private readonly cooldownMs;
98
+ constructor(opts: BrainMonitorOptions);
99
+ start(): void;
100
+ stop(): void;
101
+ private engage;
102
+ private maybeIntervene;
103
+ }
104
+
105
+ /**
106
+ * GlobalMailbox — project-level inter-agent mailbox with cross-session support.
107
+ *
108
+ * Stores messages at `~/.wrongstack/projects/<slug>/_mailbox.jsonl` so all
109
+ * sessions (terminals, WebUIs) working on the same project share one inbox.
110
+ *
111
+ * Features:
112
+ * - Agent registration + heartbeat (agents go stale after 60s without heartbeat)
113
+ * - Per-recipient read receipts (readBy[agentId] = ISO8601)
114
+ * - Atomic file-locking for concurrent multi-process writes
115
+ * - Unread count for new-mail notifications
116
+ * - Online agent list
117
+ *
118
+ * @module GlobalMailbox
119
+ */
120
+
121
+ /**
122
+ * Derive the project-level mailbox directory path.
123
+ *
124
+ * Delegates to the CANONICAL `projectSlug()` from wstack-paths so every
125
+ * surface (CLI, TUI, WebUI, mailbox tool, loop checker) lands in the exact
126
+ * same `~/.wrongstack/projects/<slug>/` directory. A previous inline copy
127
+ * skipped the leading/trailing-hyphen strip, which silently split agents
128
+ * working on projects with non-alphanumeric name edges into TWO mailboxes.
129
+ *
130
+ * @param projectRoot — absolute path to the project root
131
+ * @param globalRoot — `~/.wrongstack` (or custom global root)
132
+ */
133
+ declare function resolveProjectDir(projectRoot: string, globalRoot: string): string;
134
+ declare class GlobalMailbox implements Mailbox {
135
+ /** Path to the JSONL message file. */
136
+ readonly messagePath: string;
137
+ /** Path to the JSON agent registry file. */
138
+ readonly registryPath: string;
139
+ /** Optional event bus for emitting agent registration/heartbeat events. */
140
+ private readonly _events?;
141
+ /**
142
+ * Local cache of the agent registry to avoid re-reading on every call.
143
+ * Time-bounded: the registry file is shared ACROSS PROCESSES (that's the
144
+ * whole point of GlobalMailbox), so a cache served forever would never see
145
+ * agents registered by other sessions. Writers always bypass it.
146
+ */
147
+ private _registryCache;
148
+ /** When the registry cache was last refreshed from disk (epoch ms). */
149
+ private _registryCacheAt;
150
+ /** Last time each local agent sent a heartbeat (throttle). */
151
+ private _lastHeartbeat;
152
+ /**
153
+ * @param projectDir — `~/.wrongstack/projects/<slug>/`
154
+ * @param events — optional EventBus for real-time TUI/WebUI notifications
155
+ */
156
+ constructor(projectDir: string, events?: EventBus);
157
+ send(input: MailboxSendInput): Promise<MailboxMessage>;
158
+ query(q: MailboxQuery): Promise<MailboxMessage[]>;
159
+ ack(input: MailboxAckInput): Promise<MailboxMessage | null>;
160
+ unreadCount(forAgentId: string): Promise<number>;
161
+ registerAgent(input: AgentRegistrationInput): Promise<void>;
162
+ heartbeat(input: AgentHeartbeatInput): Promise<void>;
163
+ getAgentStatuses(): Promise<MailboxAgentStatus[]>;
164
+ getOnlineAgents(): Promise<MailboxAgentStatus[]>;
165
+ close(): Promise<void>;
166
+ clearAll(): Promise<void>;
167
+ private _readMessages;
168
+ private _ensureRegistry;
169
+ private _readRegistry;
170
+ private _pruneStaleInPlace;
171
+ private _writeRegistry;
172
+ }
173
+
174
+ /**
175
+ * mailbox-tool — Tool that exposes the inter-agent mailbox to agents.
176
+ *
177
+ * Sub-commands: check, send, ack, query, status, online, unread
178
+ *
179
+ * Uses the project-level GlobalMailbox for cross-session communication.
180
+ * Agents are auto-registered on first use with heartbeat tracking.
181
+ * Read receipts track who read each message and when.
182
+ *
183
+ * @module mailbox-tool
184
+ */
185
+
186
+ type MailboxResolver = (ctx: Context) => Mailbox;
187
+ interface MailboxToolOptions {
188
+ /**
189
+ * How to obtain a Mailbox instance given the execution Context.
190
+ * Default: derives project dir from ctx and creates a GlobalMailbox.
191
+ */
192
+ resolveMailbox?: MailboxResolver | undefined;
193
+ /**
194
+ * Agent id of the caller — used as default "from" on send.
195
+ * Default: 'leader' for the main agent, or derived from ctx.meta.
196
+ */
197
+ agentId?: string | undefined;
198
+ /** Session id for cross-session communication. Default: derived from ctx. */
199
+ sessionId?: string | undefined;
200
+ /**
201
+ * Project directory where the mailbox is stored.
202
+ * Default: derived from ctx.projectRoot (may differ from wpaths.projectDir).
203
+ * For correct cross-session sharing, pass `wpaths.projectDir` from the caller.
204
+ */
205
+ projectDir?: string | undefined;
206
+ /**
207
+ * EventBus for emitting mailbox.agent_registered and mailbox.agent_heartbeat
208
+ * events so the TUI/WebUI can update the online agent count in the status bar.
209
+ * When omitted, events are not emitted and the status bar count stays at 0.
210
+ */
211
+ events?: EventBus | undefined;
212
+ }
213
+ /**
214
+ * Compact, deterministic tag for a session id — 8 hex chars of its sha256.
215
+ * Session ids are date-sharded paths ("2026-06-11/10-48-34Z_model_e66c");
216
+ * the tag keeps mailbox identities short, filesystem-safe, and stable for
217
+ * the lifetime of the session (including across process restarts/resumes).
218
+ */
219
+ declare function mailboxSessionTag(sessionId: string): string;
220
+ /**
221
+ * Resolve the caller's mailbox identity from the execution Context.
222
+ *
223
+ * Shared by the `mailbox` power-tool, the thin `mail_send`/`mail_inbox`
224
+ * tools, the agent-loop checker, and the /mailbox slash command so every
225
+ * surface agrees on who is talking:
226
+ * - base id: ctx.meta.agentId → ctx.agentId field (subagents) → fallback
227
+ * - unique id: `<base>@<sessionTag>` — SESSION-bound, not pid-bound. Every
228
+ * session has its own id, so two leader sessions on the same project
229
+ * never collide (pids can be recycled by the OS), and a resumed session
230
+ * keeps its identity: read state survives a restart instead of
231
+ * re-flooding old broadcasts. Derived LIVE from ctx.session.id so an
232
+ * in-process session swap (resume / session.new / project switch) moves
233
+ * the identity with it. `ctx.meta.globalAgentId` remains an explicit
234
+ * override for hosts that manage identity themselves.
235
+ */
236
+ declare function resolveMailboxIdentity(ctx: Context, fallbackBase?: string): {
237
+ baseId: string;
238
+ callerId: string;
239
+ name: string;
240
+ role?: string | undefined;
241
+ sessionId: string;
242
+ };
243
+ declare function makeMailboxTool(opts?: MailboxToolOptions): Tool;
244
+
245
+ /**
246
+ * mail-tools — thin, high-affordance wrappers over the project mailbox.
247
+ *
248
+ * The multi-action `mailbox` tool is the power surface; these two exist
249
+ * because explicit verbs ("send a mail", "read my inbox") are what makes
250
+ * agents USE the mailbox autonomously — a model reaches for `mail_send`
251
+ * mid-task far more readily than for `mailbox action=send ...`.
252
+ *
253
+ * mail_send — message one agent (`to: "leader@a1b2c3d4"`), every leader
254
+ * (`to: "leader"`), or everyone (`to: "*"`)
255
+ * mail_inbox — read unread mail (unique id + base alias + broadcasts),
256
+ * marking it read so it isn't re-injected next iteration
257
+ *
258
+ * Both share the identity convention with the agent-loop checker
259
+ * (`<base>@<sessionTag>`, see mailbox-attach) via `resolveMailboxIdentity`.
260
+ *
261
+ * @module mail-tools
262
+ */
263
+
264
+ interface MailToolsOptions {
265
+ /** How to obtain a Mailbox given the execution Context (tests). */
266
+ resolveMailbox?: MailboxResolver | undefined;
267
+ /** Project dir for the shared mailbox. Prefer wpaths.projectDir. */
268
+ projectDir?: string | undefined;
269
+ /** EventBus for mailbox.agent_registered / heartbeat surface events. */
270
+ events?: EventBus | undefined;
271
+ }
272
+ declare function makeMailSendTool(opts?: MailToolsOptions): Tool;
273
+ declare function makeMailInboxTool(opts?: MailToolsOptions): Tool;
274
+
275
+ /**
276
+ * dep-watcher — File-change → Mailbox bridge for dependency monitoring.
277
+ *
278
+ * Watches dependency manifest files (package.json, go.mod, Cargo.toml, etc.)
279
+ * and when they change (create/update), posts a message to the inter-agent
280
+ * mailbox. A tech-stack analysis agent can then pick up the message and
281
+ * run a full tech-stack validation, feeding results back to the coding LLM.
282
+ *
283
+ * This module is a *config factory*, not a watcher itself. It produces
284
+ * configuration that the file-watcher plugin (`watch_start`) can consume,
285
+ * plus a callback that posts to a Mailbox instance.
286
+ *
287
+ * Usage:
288
+ * const cfg = makeDependencyWatcherConfig({
289
+ * projectRoot: '/path/to/project',
290
+ * mailbox,
291
+ * targetAgent: 'tech-stack-agent',
292
+ * });
293
+ * // cfg.watchPaths → pass to watch_start
294
+ * // cfg.onChange → call on file-watcher:changed events
295
+ *
296
+ * @module dep-watcher
297
+ */
298
+
299
+ /**
300
+ * Files that declare project dependencies. When any of these change
301
+ * (create/update), a mailbox message triggers a tech-stack audit.
302
+ */
303
+ declare const DEPENDENCY_FILE_PATTERNS: ReadonlyArray<string>;
304
+ interface DepWatchEntry {
305
+ /** Relative path from project root that changed. */
306
+ path: string;
307
+ /** Event type from the file watcher: 'change', 'add', 'delete' (rare). */
308
+ event: string;
309
+ /** ISO8601 timestamp of when the change was detected. */
310
+ timestamp: string;
311
+ }
312
+ interface DependencyWatcherConfig {
313
+ /** Paths to pass to `watch_start` — the project-root-relative dependency files. */
314
+ watchPaths: string[];
315
+ /** Callback to invoke when a dependency file changes. Posts to mailbox. */
316
+ onChange: (entry: DepWatchEntry) => Promise<void>;
317
+ /** Debounce window in ms — multiple changes to the same file within this window are collapsed. */
318
+ debounceMs: number;
319
+ }
320
+ interface DependencyWatcherOptions {
321
+ /** Absolute path to the project root. */
322
+ projectRoot: string;
323
+ /** The mailbox instance where messages will be posted. */
324
+ mailbox: Mailbox;
325
+ /** Agent id that should receive the tech-stack audit task. */
326
+ targetAgent?: string | undefined;
327
+ /** Agent id of the watcher (sender). */
328
+ watcherAgentId?: string | undefined;
329
+ /** Debounce window in ms. Default: 3000 (3 seconds). */
330
+ debounceMs?: number | undefined;
331
+ /** Only watch these specific patterns. Defaults to DEPENDENCY_FILE_PATTERNS. */
332
+ patterns?: string[] | undefined;
333
+ }
334
+ /**
335
+ * Build a dependency watcher configuration. The returned `watchPaths` can be
336
+ * passed directly to the `watch_start` tool, and `onChange` should be wired
337
+ * to the `file-watcher:changed` custom event.
338
+ *
339
+ * When a dependency file changes, `onChange` posts a high-priority `assign`
340
+ * message to the mailbox targeting the tech-stack agent, with the changed
341
+ * file path and event type in the body.
342
+ */
343
+ declare function makeDependencyWatcherConfig(opts: DependencyWatcherOptions): DependencyWatcherConfig;
344
+
345
+ /**
346
+ * dep-watcher-bridge — Bridges the file-watcher plugin's custom events
347
+ * to the dependency watcher → mailbox pipeline.
348
+ *
349
+ * The file-watcher plugin emits `file-watcher:changed` custom events
350
+ * when files change. This module subscribes to those events, filters
351
+ * for dependency manifests (package.json, go.mod, etc.), and posts
352
+ * assign messages to the inter-agent mailbox for tech-stack audit.
353
+ *
354
+ * Returns a dispose function that unsubscribes from the event bus.
355
+ *
356
+ * @module dep-watcher-bridge
357
+ */
358
+
359
+ interface DepWatcherBridgeOptions {
360
+ /** The event bus to subscribe to (same bus the file-watcher plugin emits on). */
361
+ events: EventBus;
362
+ /** The mailbox instance where dep-change notifications will be posted. */
363
+ mailbox: Mailbox;
364
+ /** Absolute project root — used to build watch paths and match file patterns. */
365
+ projectRoot: string;
366
+ /** Agent id the tech-stack audit tasks should target. Default: 'tech-stack'. */
367
+ targetAgent?: string | undefined;
368
+ /** Agent id of the watcher/sender. Default: 'dep-watcher'. */
369
+ watcherAgentId?: string | undefined;
370
+ /** Debounce window in ms. Default: 3000 (3 seconds). */
371
+ debounceMs?: number | undefined;
372
+ }
373
+ /**
374
+ * Wire the file-watcher's `file-watcher:changed` events into the
375
+ * dependency watcher → mailbox pipeline.
376
+ *
377
+ * Returns a dispose function. Call it to unsubscribe when the
378
+ * session ends or the watcher is no longer needed.
379
+ *
380
+ * Usage:
381
+ * const dispose = attachDepWatcherBridge({
382
+ * events: ctx.events,
383
+ * mailbox: new DefaultMailbox(sessionDir),
384
+ * projectRoot: ctx.projectRoot,
385
+ * });
386
+ * // ... session runs ...
387
+ * dispose(); // clean up on exit
388
+ */
389
+ declare function attachDepWatcherBridge(opts: DepWatcherBridgeOptions): () => void;
390
+
391
+ /**
392
+ * package-author-tracker — Tracks which agent added which package to which manifest.
393
+ *
394
+ * Stores a per-project JSON log in the global project directory:
395
+ * ~/.wrongstack/projects/<slug-hash>/package-authors.json
396
+ *
397
+ * Each entry records: manifest path, package name, version range at time of add,
398
+ * agent id/name, timestamp, and session id.
399
+ *
400
+ * Used by the tech-stack agent and outdated-watcher to route outdated-package
401
+ * notifications back to the agent that originally added the package.
402
+ *
403
+ * @module package-author-tracker
404
+ */
405
+ interface PackageAuthorEntry {
406
+ /** Absolute or relative path to the manifest (package.json, go.mod, etc.). */
407
+ manifestPath: string;
408
+ /** Exact package name as it appears in the manifest. */
409
+ packageName: string;
410
+ /** Version specifier at time of install (e.g. "^1.2.0", "latest", "file:..."). */
411
+ versionSpec: string;
412
+ /** Ecosystem: 'npm', 'cargo', 'go', 'pip', 'gem', 'composer', 'nuget', etc. */
413
+ ecosystem: string;
414
+ /** Agent id that performed the install (e.g. 'leader', 'executor', 'tech-stack'). */
415
+ agentId: string;
416
+ /** Human-readable agent name. */
417
+ agentName?: string | undefined;
418
+ /** Session that performed the install. */
419
+ sessionId?: string | undefined;
420
+ /** ISO8601 timestamp. */
421
+ timestamp: string;
422
+ /** Whether this package is currently flagged as outdated. */
423
+ outdated?: boolean | undefined;
424
+ /** Latest version available (set by outdated checker). */
425
+ latestVersion?: string | undefined;
426
+ }
427
+ interface PackageAuthorLog {
428
+ /** Project root this log belongs to. */
429
+ projectRoot: string;
430
+ /** All entries, newest last. */
431
+ entries: PackageAuthorEntry[];
432
+ /** Last time the log was compacted. */
433
+ lastCompactedAt?: string | undefined;
434
+ }
435
+ interface PackageAuthorTrackerOptions {
436
+ /** Directory where the JSON log is stored. Usually the global project dir. */
437
+ storageDir: string;
438
+ /** Project root for reference. */
439
+ projectRoot: string;
440
+ /** Max entries before auto-compaction. Default: 10000. */
441
+ maxEntries?: number | undefined;
442
+ }
443
+ /**
444
+ * Detect the ecosystem from a manifest filename.
445
+ */
446
+ declare function detectEcosystem(manifestPath: string): string;
447
+ /**
448
+ * Record that an agent added (or updated) a package to a manifest file.
449
+ *
450
+ * If the same (manifestPath, packageName) entry already exists, the previous
451
+ * entry is kept (for audit trail) and a new entry is appended.
452
+ */
453
+ declare function recordPackageAction(opts: PackageAuthorTrackerOptions, entry: Omit<PackageAuthorEntry, 'timestamp'>): Promise<void>;
454
+ /**
455
+ * Get the most recent author entry for a given (manifest, package) pair.
456
+ * Returns undefined if no entry exists.
457
+ */
458
+ declare function getPackageAuthor(opts: Pick<PackageAuthorTrackerOptions, 'storageDir' | 'projectRoot'>, manifestPath: string, packageName: string): Promise<PackageAuthorEntry | undefined>;
459
+ /**
460
+ * Get all packages in a manifest that have an author on record.
461
+ */
462
+ declare function getManifestPackages(opts: Pick<PackageAuthorTrackerOptions, 'storageDir' | 'projectRoot'>, manifestPath: string): Promise<PackageAuthorEntry[]>;
463
+ /**
464
+ * Get all packages last tracked by a specific agent.
465
+ * Returns a Map from (manifestPath, packageName) → entry.
466
+ */
467
+ declare function getPackagesByAgent(opts: Pick<PackageAuthorTrackerOptions, 'storageDir' | 'projectRoot'>, agentId: string): Promise<Map<string, PackageAuthorEntry>>;
468
+ /**
469
+ * Update the outdated status of a package entry (adds or replaces the entry
470
+ * for the given manifest+package, appending to the log for audit).
471
+ */
472
+ declare function updatePackageOutdatedStatus(opts: PackageAuthorTrackerOptions, manifestPath: string, packageName: string, outdated: boolean, latestVersion?: string | undefined): Promise<void>;
473
+ /**
474
+ * Return the full log (for debugging/auditing).
475
+ */
476
+ declare function getFullPackageLog(opts: Pick<PackageAuthorTrackerOptions, 'storageDir' | 'projectRoot'>): Promise<PackageAuthorLog>;
477
+
478
+ /**
479
+ * package-outdated-watcher — Periodically checks installed packages for outdated
480
+ * versions and notifies the agent that originally added each package.
481
+ *
482
+ * Architecture:
483
+ * 1. Polls the mailbox for `assign` messages from the tech-stack agent
484
+ * containing outdated package results.
485
+ * 2. For each outdated package, looks up the original author via
486
+ * `package-author-tracker`.
487
+ * 3. Sends a high-priority `note` message to the original author (or
488
+ * broadcasts to `*` if the author is unknown or no longer online).
489
+ *
490
+ * The watcher can also be triggered directly via `checkOutdated` for
491
+ * on-demand checks (e.g. on a timer, or when the user requests it).
492
+ *
493
+ * Usage:
494
+ * const dispose = startPackageOutdatedWatcher({
495
+ * mailbox,
496
+ * storageDir: wpaths.globalDir,
497
+ * projectRoot,
498
+ * pollIntervalMs: 60 * 60 * 1000, // 1 hour
499
+ * onNotify: async (msg) => mailbox.send(msg),
500
+ * onLog: (m) => console.log(`[pkg-outdated-watcher] ${m}`),
501
+ * });
502
+ *
503
+ * @module package-outdated-watcher
504
+ */
505
+
506
+ interface PackageOutdatedEntry {
507
+ /** Package name. */
508
+ name: string;
509
+ /** Currently installed version. */
510
+ currentVersion: string;
511
+ /** Latest stable version available. */
512
+ latestVersion: string;
513
+ /** semver major.minor.patch wanted range (from lockfile). */
514
+ wantedVersion: string;
515
+ /** Manifest file this package belongs to. */
516
+ manifestPath: string;
517
+ /** Ecosystem: 'npm', 'cargo', 'go', etc. */
518
+ ecosystem: string;
519
+ }
520
+ interface PackageOutdatedResult {
521
+ /** All outdated entries. */
522
+ outdated: PackageOutdatedEntry[];
523
+ /** Packages that are up-to-date. */
524
+ upToDate: string[];
525
+ /** Whether the check failed. */
526
+ checkFailed: boolean;
527
+ }
528
+ interface PackageOutdatedWatcherOptions {
529
+ /** The mailbox for sending notifications and receiving tech-stack results. */
530
+ mailbox: Mailbox;
531
+ /** Package-author-tracker options. */
532
+ packageTrackerOpts: Pick<PackageAuthorTrackerOptions, 'storageDir' | 'projectRoot'>;
533
+ /** Polling interval in ms. Default: 60 * 60 * 1000 (1 hour). */
534
+ pollIntervalMs?: number | undefined;
535
+ /** Agent id that runs this watcher. Default: 'pkg-outdated-watcher'. */
536
+ watcherAgentId?: string | undefined;
537
+ /** Agent id of the tech-stack agent to watch for results. Default: 'tech-stack'. */
538
+ techStackAgentId?: string | undefined;
539
+ /** Called to send a notification to an agent. */
540
+ onNotify: (msg: OutdatedNotifyMessage) => Promise<void>;
541
+ /** Called for log output. */
542
+ onLog?: ((msg: string) => void) | undefined;
543
+ /** Called on errors. */
544
+ onError?: ((err: unknown) => void) | undefined;
545
+ }
546
+ interface OutdatedNotifyMessage {
547
+ from: string;
548
+ to: string;
549
+ subject: string;
550
+ body: string;
551
+ priority: 'high' | 'normal' | 'low';
552
+ }
553
+ /**
554
+ * Start the package outdated watcher.
555
+ *
556
+ * Returns a dispose function that stops polling and cleans up.
557
+ */
558
+ declare function startPackageOutdatedWatcher(opts: PackageOutdatedWatcherOptions): () => void;
559
+
560
+ export { resolveProjectDir as A, type BrainInterventionInput as B, startPackageOutdatedWatcher as C, DEPENDENCY_FILE_PATTERNS as D, updatePackageOutdatedStatus as E, GlobalMailbox as G, type MailToolsOptions as M, type OutdatedNotifyMessage as O, type PackageAuthorEntry as P, BrainMonitor as a, type BrainMonitorOptions as b, DefaultMailbox as c, type DepWatchEntry as d, type DepWatcherBridgeOptions as e, type DependencyWatcherConfig as f, type MailboxResolver as g, type MailboxToolOptions as h, type PackageAuthorLog as i, type PackageAuthorTrackerOptions as j, type PackageOutdatedEntry as k, type PackageOutdatedResult as l, type PackageOutdatedWatcherOptions as m, attachDepWatcherBridge as n, detectEcosystem as o, getFullPackageLog as p, getManifestPackages as q, getPackageAuthor as r, getPackagesByAgent as s, mailboxSessionTag as t, makeDependencyWatcherConfig as u, makeMailInboxTool as v, makeMailSendTool as w, makeMailboxTool as x, recordPackageAction as y, resolveMailboxIdentity as z };