monomind 2.1.0 → 2.1.3

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 (49) hide show
  1. package/README.md +74 -92
  2. package/package.json +3 -3
  3. package/packages/@monomind/cli/.claude/helpers/handlers/capture-handler.cjs +24 -10
  4. package/packages/@monomind/cli/.claude/helpers/handlers/gates-handler.cjs +2 -2
  5. package/packages/@monomind/cli/.claude/helpers/handlers/route-handler.cjs +29 -0
  6. package/packages/@monomind/cli/.claude/helpers/handlers/session-handler.cjs +35 -23
  7. package/packages/@monomind/cli/.claude/helpers/hook-handler.cjs +21 -0
  8. package/packages/@monomind/cli/.claude/helpers/utils/monograph.cjs +73 -2
  9. package/packages/@monomind/cli/README.md +74 -92
  10. package/packages/@monomind/cli/dist/src/browser/workflow/store.d.ts +2 -2
  11. package/packages/@monomind/cli/dist/src/commands/browse.d.ts +1 -1
  12. package/packages/@monomind/cli/dist/src/commands/doctor-env-checks.js +5 -0
  13. package/packages/@monomind/cli/dist/src/commands/org.js +46 -29
  14. package/packages/@monomind/cli/dist/src/commands/platforms.d.ts +1 -1
  15. package/packages/@monomind/cli/dist/src/init/executor.js +30 -6
  16. package/packages/@monomind/cli/dist/src/mcp-tools/auto-install.d.ts +8 -8
  17. package/packages/@monomind/cli/dist/src/mcp-tools/coherence/types.d.ts +31 -31
  18. package/packages/@monomind/cli/dist/src/mcp-tools/hive-mind-tools.js +5 -1
  19. package/packages/@monomind/cli/dist/src/mcp-tools/monograph-tools.js +28 -3
  20. package/packages/@monomind/cli/dist/src/mcp-tools/quality/coverage-analysis/prioritize-gaps.d.ts +36 -36
  21. package/packages/@monomind/cli/dist/src/mcp-tools/quality/security-compliance/detect-secrets.d.ts +4 -4
  22. package/packages/@monomind/cli/dist/src/memory/ewc-consolidation.d.ts +12 -0
  23. package/packages/@monomind/cli/dist/src/memory/sona-optimizer.d.ts +12 -0
  24. package/packages/@monomind/cli/dist/src/orgrt/broker.d.ts +3 -1
  25. package/packages/@monomind/cli/dist/src/orgrt/broker.js +8 -3
  26. package/packages/@monomind/cli/dist/src/orgrt/bus.d.ts +5 -1
  27. package/packages/@monomind/cli/dist/src/orgrt/bus.js +5 -1
  28. package/packages/@monomind/cli/dist/src/orgrt/daemon.d.ts +17 -1
  29. package/packages/@monomind/cli/dist/src/orgrt/daemon.js +115 -21
  30. package/packages/@monomind/cli/dist/src/orgrt/forwarder.js +41 -8
  31. package/packages/@monomind/cli/dist/src/orgrt/inbox.d.ts +11 -0
  32. package/packages/@monomind/cli/dist/src/orgrt/inbox.js +56 -0
  33. package/packages/@monomind/cli/dist/src/orgrt/policy.d.ts +5 -1
  34. package/packages/@monomind/cli/dist/src/orgrt/policy.js +58 -5
  35. package/packages/@monomind/cli/dist/src/orgrt/server.d.ts +3 -2
  36. package/packages/@monomind/cli/dist/src/orgrt/server.js +7 -40
  37. package/packages/@monomind/cli/dist/src/orgrt/session.d.ts +10 -1
  38. package/packages/@monomind/cli/dist/src/orgrt/session.js +24 -1
  39. package/packages/@monomind/cli/dist/src/orgrt/test-loop.js +8 -8
  40. package/packages/@monomind/cli/dist/src/orgrt/types.d.ts +52 -52
  41. package/packages/@monomind/cli/dist/src/output.d.ts +29 -29
  42. package/packages/@monomind/cli/dist/src/output.js +10 -2
  43. package/packages/@monomind/cli/dist/src/types.d.ts +2 -2
  44. package/packages/@monomind/cli/dist/src/ui/dashboard.html +203 -9
  45. package/packages/@monomind/cli/dist/src/ui/orgs-files.js +192 -0
  46. package/packages/@monomind/cli/dist/src/ui/orgs.html +21 -52
  47. package/packages/@monomind/cli/dist/src/ui/server.mjs +42 -6
  48. package/packages/@monomind/cli/package.json +12 -16
  49. package/packages/@monomind/cli/dist/src/orgrt/live.html +0 -56
@@ -69,8 +69,8 @@ export declare const CoherenceInputSchema: z.ZodObject<{
69
69
  vectors: z.ZodArray<z.ZodArray<z.ZodNumber, "many">, "many">;
70
70
  threshold: z.ZodDefault<z.ZodNumber>;
71
71
  }, "strip", z.ZodTypeAny, {
72
- threshold: number;
73
72
  vectors: number[][];
73
+ threshold: number;
74
74
  }, {
75
75
  vectors: number[][];
76
76
  threshold?: number | undefined;
@@ -98,10 +98,10 @@ export declare const SpectralInputSchema: z.ZodObject<{
98
98
  analyzeType: z.ZodDefault<z.ZodEnum<["stability", "clustering", "connectivity"]>>;
99
99
  }, "strip", z.ZodTypeAny, {
100
100
  matrix: number[][];
101
- analyzeType: "stability" | "clustering" | "connectivity";
101
+ analyzeType: "clustering" | "connectivity" | "stability";
102
102
  }, {
103
103
  matrix: number[][];
104
- analyzeType?: "stability" | "clustering" | "connectivity" | undefined;
104
+ analyzeType?: "clustering" | "connectivity" | "stability" | undefined;
105
105
  }>;
106
106
  export type SpectralInput = z.infer<typeof SpectralInputSchema>;
107
107
  export interface SpectralResult {
@@ -150,15 +150,15 @@ export declare const CausalInputSchema: z.ZodObject<{
150
150
  nodes: string[];
151
151
  edges: [string, string][];
152
152
  };
153
- outcome: string;
154
153
  intervention: string;
154
+ outcome: string;
155
155
  }, {
156
156
  graph: {
157
157
  nodes: string[];
158
158
  edges: [string, string][];
159
159
  };
160
- outcome: string;
161
160
  intervention: string;
161
+ outcome: string;
162
162
  }>;
163
163
  export type CausalInput = z.infer<typeof CausalInputSchema>;
164
164
  export interface CausalResult {
@@ -185,13 +185,13 @@ export declare const AgentStateSchema: z.ZodObject<{
185
185
  }, "strip", z.ZodTypeAny, {
186
186
  agentId: string;
187
187
  embedding: number[];
188
- metadata?: Record<string, unknown> | undefined;
189
188
  vote?: string | undefined;
189
+ metadata?: Record<string, unknown> | undefined;
190
190
  }, {
191
191
  agentId: string;
192
192
  embedding: number[];
193
- metadata?: Record<string, unknown> | undefined;
194
193
  vote?: string | undefined;
194
+ metadata?: Record<string, unknown> | undefined;
195
195
  }>;
196
196
  export type AgentState = z.infer<typeof AgentStateSchema>;
197
197
  export declare const ConsensusInputSchema: z.ZodObject<{
@@ -203,29 +203,29 @@ export declare const ConsensusInputSchema: z.ZodObject<{
203
203
  }, "strip", z.ZodTypeAny, {
204
204
  agentId: string;
205
205
  embedding: number[];
206
- metadata?: Record<string, unknown> | undefined;
207
206
  vote?: string | undefined;
207
+ metadata?: Record<string, unknown> | undefined;
208
208
  }, {
209
209
  agentId: string;
210
210
  embedding: number[];
211
- metadata?: Record<string, unknown> | undefined;
212
211
  vote?: string | undefined;
212
+ metadata?: Record<string, unknown> | undefined;
213
213
  }>, "many">;
214
214
  threshold: z.ZodDefault<z.ZodNumber>;
215
215
  }, "strip", z.ZodTypeAny, {
216
- threshold: number;
217
216
  agentStates: {
218
217
  agentId: string;
219
218
  embedding: number[];
220
- metadata?: Record<string, unknown> | undefined;
221
219
  vote?: string | undefined;
220
+ metadata?: Record<string, unknown> | undefined;
222
221
  }[];
222
+ threshold: number;
223
223
  }, {
224
224
  agentStates: {
225
225
  agentId: string;
226
226
  embedding: number[];
227
- metadata?: Record<string, unknown> | undefined;
228
227
  vote?: string | undefined;
228
+ metadata?: Record<string, unknown> | undefined;
229
229
  }[];
230
230
  threshold?: number | undefined;
231
231
  }>;
@@ -247,11 +247,11 @@ export declare const SimplexSchema: z.ZodObject<{
247
247
  vertices: z.ZodArray<z.ZodNumber, "many">;
248
248
  dimension: z.ZodNumber;
249
249
  }, "strip", z.ZodTypeAny, {
250
- dimension: number;
251
250
  vertices: number[];
252
- }, {
253
251
  dimension: number;
252
+ }, {
254
253
  vertices: number[];
254
+ dimension: number;
255
255
  }>;
256
256
  export type Simplex = z.infer<typeof SimplexSchema>;
257
257
  export declare const SimplicialComplexSchema: z.ZodObject<{
@@ -260,25 +260,25 @@ export declare const SimplicialComplexSchema: z.ZodObject<{
260
260
  vertices: z.ZodArray<z.ZodNumber, "many">;
261
261
  dimension: z.ZodNumber;
262
262
  }, "strip", z.ZodTypeAny, {
263
- dimension: number;
264
263
  vertices: number[];
265
- }, {
266
264
  dimension: number;
265
+ }, {
267
266
  vertices: number[];
267
+ dimension: number;
268
268
  }>, "many">>;
269
269
  maxDimension: z.ZodDefault<z.ZodNumber>;
270
270
  }, "strip", z.ZodTypeAny, {
271
271
  vertices: number[][];
272
- maxDimension: number;
273
272
  simplices?: {
274
- dimension: number;
275
273
  vertices: number[];
274
+ dimension: number;
276
275
  }[] | undefined;
276
+ maxDimension: number;
277
277
  }, {
278
278
  vertices: number[][];
279
279
  simplices?: {
280
- dimension: number;
281
280
  vertices: number[];
281
+ dimension: number;
282
282
  }[] | undefined;
283
283
  maxDimension?: number | undefined;
284
284
  }>;
@@ -290,43 +290,43 @@ export declare const TopologyInputSchema: z.ZodObject<{
290
290
  vertices: z.ZodArray<z.ZodNumber, "many">;
291
291
  dimension: z.ZodNumber;
292
292
  }, "strip", z.ZodTypeAny, {
293
- dimension: number;
294
293
  vertices: number[];
295
- }, {
296
294
  dimension: number;
295
+ }, {
297
296
  vertices: number[];
297
+ dimension: number;
298
298
  }>, "many">>;
299
299
  maxDimension: z.ZodDefault<z.ZodNumber>;
300
300
  }, "strip", z.ZodTypeAny, {
301
301
  vertices: number[][];
302
- maxDimension: number;
303
302
  simplices?: {
304
- dimension: number;
305
303
  vertices: number[];
304
+ dimension: number;
306
305
  }[] | undefined;
306
+ maxDimension: number;
307
307
  }, {
308
308
  vertices: number[][];
309
309
  simplices?: {
310
- dimension: number;
311
310
  vertices: number[];
311
+ dimension: number;
312
312
  }[] | undefined;
313
313
  maxDimension?: number | undefined;
314
314
  }>;
315
315
  }, "strip", z.ZodTypeAny, {
316
316
  complex: {
317
317
  vertices: number[][];
318
- maxDimension: number;
319
318
  simplices?: {
320
- dimension: number;
321
319
  vertices: number[];
320
+ dimension: number;
322
321
  }[] | undefined;
322
+ maxDimension: number;
323
323
  };
324
324
  }, {
325
325
  complex: {
326
326
  vertices: number[][];
327
327
  simplices?: {
328
- dimension: number;
329
328
  vertices: number[];
329
+ dimension: number;
330
330
  }[] | undefined;
331
331
  maxDimension?: number | undefined;
332
332
  };
@@ -362,27 +362,27 @@ export declare const MemoryGateInputSchema: z.ZodObject<{
362
362
  reject: z.ZodDefault<z.ZodNumber>;
363
363
  warn: z.ZodDefault<z.ZodNumber>;
364
364
  }, "strip", z.ZodTypeAny, {
365
- warn: number;
366
365
  reject: number;
366
+ warn: number;
367
367
  }, {
368
- warn?: number | undefined;
369
368
  reject?: number | undefined;
369
+ warn?: number | undefined;
370
370
  }>>;
371
371
  }, "strip", z.ZodTypeAny, {
372
372
  key: string;
373
373
  value?: unknown;
374
374
  existingVectors?: number[][] | undefined;
375
375
  thresholds?: {
376
- warn: number;
377
376
  reject: number;
377
+ warn: number;
378
378
  } | undefined;
379
379
  }, {
380
380
  key: string;
381
381
  value?: unknown;
382
382
  existingVectors?: number[][] | undefined;
383
383
  thresholds?: {
384
- warn?: number | undefined;
385
384
  reject?: number | undefined;
385
+ warn?: number | undefined;
386
386
  } | undefined;
387
387
  }>;
388
388
  export type MemoryGateInput = z.infer<typeof MemoryGateInputSchema>;
@@ -406,7 +406,11 @@ export const hiveMindTools = [
406
406
  id: w,
407
407
  type: agent?.agentType || 'worker',
408
408
  status: agent?.status || 'unknown',
409
- currentTask: agent?.currentTask || null,
409
+ // AgentRecord has no currentTask field — always null. Kept in the
410
+ // response shape for API stability; was already dead before this
411
+ // (the previous `as unknown as Record<string, unknown>` cast hid
412
+ // that `agent?.currentTask` never matched a real field).
413
+ currentTask: null,
410
414
  tasksCompleted: agent?.taskCount || 0,
411
415
  };
412
416
  }),
@@ -744,7 +744,10 @@ async function computeCommitsBehind(repoPath) {
744
744
  const dbPath = getDbPath(repoPath);
745
745
  if (!_isValidDb(dbPath))
746
746
  return null;
747
- const db = openDb(dbPath, { fileMustExist: true });
747
+ // openDb's fileMustExist option isn't in the currently-published
748
+ // @monoes/monograph release this CLI depends on — _isValidDb above is the
749
+ // real guard against openDb silently creating an empty DB at a missing path.
750
+ const db = openDb(dbPath);
748
751
  try {
749
752
  const meta = db.prepare("SELECT value FROM index_meta WHERE key = 'last_commit_hash'").get() ?? db.prepare("SELECT value FROM index_meta WHERE key = 'lastCommit'").get();
750
753
  const lastCommit = meta?.value ?? null;
@@ -1761,9 +1764,15 @@ const monographInstallSkillsTool = {
1761
1764
  }
1762
1765
  // Load community data from graph
1763
1766
  const dbPath = getDbPath(repoPath);
1767
+ // openDb's fileMustExist option isn't in the currently-published
1768
+ // @monoes/monograph release this CLI depends on — check validity
1769
+ // ourselves so a missing DB doesn't get silently auto-created empty.
1770
+ if (!_isValidDb(dbPath)) {
1771
+ return text('Graph not built yet. Run monograph_build first.');
1772
+ }
1764
1773
  let db;
1765
1774
  try {
1766
- db = openDb(dbPath, { fileMustExist: true });
1775
+ db = openDb(dbPath);
1767
1776
  }
1768
1777
  catch {
1769
1778
  return text('Graph not built yet. Run monograph_build first.');
@@ -1974,9 +1983,25 @@ const monographDeadCodeTool = {
1974
1983
  const cats = input.categories ?? ['dead-functions', 'orphan-files', 'stale-dist'];
1975
1984
  const result = {};
1976
1985
  const dbPath = getDbPath(repoPath);
1986
+ // openDb's fileMustExist option isn't in the currently-published
1987
+ // @monoes/monograph release this CLI depends on — check validity
1988
+ // ourselves so a missing DB doesn't get silently auto-created empty.
1989
+ if (!_isValidDb(dbPath)) {
1990
+ return text(JSON.stringify({ error: 'No monograph index found. Run monograph_build first.' }));
1991
+ }
1977
1992
  let db = null;
1978
1993
  try {
1979
- db = openDb(dbPath, { fileMustExist: true });
1994
+ db = openDb(dbPath);
1995
+ // _isValidDb's size check can't distinguish a real index from an
1996
+ // empty-but-schema-migrated DB (better-sqlite3 auto-creates + migrates
1997
+ // on open, and other unguarded openDb() call sites in this file can
1998
+ // create exactly that as a side effect of an unrelated tool call before
1999
+ // monograph_build ever runs). Verify actual content post-open so this
2000
+ // reports "never built" instead of a misleading "0 dead functions found".
2001
+ const { count } = db.prepare('SELECT COUNT(*) as count FROM nodes').get();
2002
+ if (count === 0) {
2003
+ return text(JSON.stringify({ error: 'No monograph index found. Run monograph_build first.' }));
2004
+ }
1980
2005
  }
1981
2006
  catch {
1982
2007
  return text(JSON.stringify({ error: 'No monograph index found. Run monograph_build first.' }));
@@ -13,14 +13,14 @@ export declare const PrioritizeGapsInputSchema: z.ZodObject<{
13
13
  startLine: z.ZodNumber;
14
14
  endLine: z.ZodNumber;
15
15
  }, "strip", z.ZodTypeAny, {
16
- type: "function" | "line" | "branch";
17
16
  id: string;
17
+ type: "branch" | "function" | "line";
18
18
  file: string;
19
19
  startLine: number;
20
20
  endLine: number;
21
21
  }, {
22
- type: "function" | "line" | "branch";
23
22
  id: string;
23
+ type: "branch" | "function" | "line";
24
24
  file: string;
25
25
  startLine: number;
26
26
  endLine: number;
@@ -52,9 +52,15 @@ export declare const PrioritizeGapsInputSchema: z.ZodObject<{
52
52
  limit: z.ZodDefault<z.ZodNumber>;
53
53
  groupBy: z.ZodDefault<z.ZodEnum<["risk", "file", "type", "none"]>>;
54
54
  }, "strip", z.ZodTypeAny, {
55
- limit: number;
56
- factors: ("complexity" | "change-frequency" | "defect-history" | "business-critical" | "dependency-count" | "test-difficulty")[];
57
- groupBy: "type" | "none" | "file" | "risk";
55
+ gaps?: {
56
+ id: string;
57
+ type: "branch" | "function" | "line";
58
+ file: string;
59
+ startLine: number;
60
+ endLine: number;
61
+ }[] | undefined;
62
+ targetPath?: string | undefined;
63
+ factors: ("business-critical" | "change-frequency" | "complexity" | "defect-history" | "dependency-count" | "test-difficulty")[];
58
64
  weights?: {
59
65
  complexity: number;
60
66
  changeFrequency: number;
@@ -63,16 +69,18 @@ export declare const PrioritizeGapsInputSchema: z.ZodObject<{
63
69
  dependencyCount: number;
64
70
  testDifficulty: number;
65
71
  } | undefined;
72
+ limit: number;
73
+ groupBy: "file" | "none" | "risk" | "type";
74
+ }, {
66
75
  gaps?: {
67
- type: "function" | "line" | "branch";
68
76
  id: string;
77
+ type: "branch" | "function" | "line";
69
78
  file: string;
70
79
  startLine: number;
71
80
  endLine: number;
72
81
  }[] | undefined;
73
82
  targetPath?: string | undefined;
74
- }, {
75
- limit?: number | undefined;
83
+ factors?: ("business-critical" | "change-frequency" | "complexity" | "defect-history" | "dependency-count" | "test-difficulty")[] | undefined;
76
84
  weights?: {
77
85
  complexity?: number | undefined;
78
86
  changeFrequency?: number | undefined;
@@ -81,16 +89,8 @@ export declare const PrioritizeGapsInputSchema: z.ZodObject<{
81
89
  dependencyCount?: number | undefined;
82
90
  testDifficulty?: number | undefined;
83
91
  } | undefined;
84
- gaps?: {
85
- type: "function" | "line" | "branch";
86
- id: string;
87
- file: string;
88
- startLine: number;
89
- endLine: number;
90
- }[] | undefined;
91
- targetPath?: string | undefined;
92
- factors?: ("complexity" | "change-frequency" | "defect-history" | "business-critical" | "dependency-count" | "test-difficulty")[] | undefined;
93
- groupBy?: "type" | "none" | "file" | "risk" | undefined;
92
+ limit?: number | undefined;
93
+ groupBy?: "file" | "none" | "risk" | "type" | undefined;
94
94
  }>;
95
95
  export type PrioritizeGapsInput = z.infer<typeof PrioritizeGapsInputSchema>;
96
96
  export interface PrioritizeGapsOutput {
@@ -176,14 +176,14 @@ export declare const toolDefinition: {
176
176
  startLine: z.ZodNumber;
177
177
  endLine: z.ZodNumber;
178
178
  }, "strip", z.ZodTypeAny, {
179
- type: "function" | "line" | "branch";
180
179
  id: string;
180
+ type: "branch" | "function" | "line";
181
181
  file: string;
182
182
  startLine: number;
183
183
  endLine: number;
184
184
  }, {
185
- type: "function" | "line" | "branch";
186
185
  id: string;
186
+ type: "branch" | "function" | "line";
187
187
  file: string;
188
188
  startLine: number;
189
189
  endLine: number;
@@ -215,9 +215,15 @@ export declare const toolDefinition: {
215
215
  limit: z.ZodDefault<z.ZodNumber>;
216
216
  groupBy: z.ZodDefault<z.ZodEnum<["risk", "file", "type", "none"]>>;
217
217
  }, "strip", z.ZodTypeAny, {
218
- limit: number;
219
- factors: ("complexity" | "change-frequency" | "defect-history" | "business-critical" | "dependency-count" | "test-difficulty")[];
220
- groupBy: "type" | "none" | "file" | "risk";
218
+ gaps?: {
219
+ id: string;
220
+ type: "branch" | "function" | "line";
221
+ file: string;
222
+ startLine: number;
223
+ endLine: number;
224
+ }[] | undefined;
225
+ targetPath?: string | undefined;
226
+ factors: ("business-critical" | "change-frequency" | "complexity" | "defect-history" | "dependency-count" | "test-difficulty")[];
221
227
  weights?: {
222
228
  complexity: number;
223
229
  changeFrequency: number;
@@ -226,16 +232,18 @@ export declare const toolDefinition: {
226
232
  dependencyCount: number;
227
233
  testDifficulty: number;
228
234
  } | undefined;
235
+ limit: number;
236
+ groupBy: "file" | "none" | "risk" | "type";
237
+ }, {
229
238
  gaps?: {
230
- type: "function" | "line" | "branch";
231
239
  id: string;
240
+ type: "branch" | "function" | "line";
232
241
  file: string;
233
242
  startLine: number;
234
243
  endLine: number;
235
244
  }[] | undefined;
236
245
  targetPath?: string | undefined;
237
- }, {
238
- limit?: number | undefined;
246
+ factors?: ("business-critical" | "change-frequency" | "complexity" | "defect-history" | "dependency-count" | "test-difficulty")[] | undefined;
239
247
  weights?: {
240
248
  complexity?: number | undefined;
241
249
  changeFrequency?: number | undefined;
@@ -244,16 +252,8 @@ export declare const toolDefinition: {
244
252
  dependencyCount?: number | undefined;
245
253
  testDifficulty?: number | undefined;
246
254
  } | undefined;
247
- gaps?: {
248
- type: "function" | "line" | "branch";
249
- id: string;
250
- file: string;
251
- startLine: number;
252
- endLine: number;
253
- }[] | undefined;
254
- targetPath?: string | undefined;
255
- factors?: ("complexity" | "change-frequency" | "defect-history" | "business-critical" | "dependency-count" | "test-difficulty")[] | undefined;
256
- groupBy?: "type" | "none" | "file" | "risk" | undefined;
255
+ limit?: number | undefined;
256
+ groupBy?: "file" | "none" | "risk" | "type" | undefined;
257
257
  }>;
258
258
  handler: typeof handler;
259
259
  };
@@ -15,16 +15,16 @@ export declare const DetectSecretsInputSchema: z.ZodObject<{
15
15
  scanHistory: z.ZodDefault<z.ZodBoolean>;
16
16
  }, "strip", z.ZodTypeAny, {
17
17
  targetPath: string;
18
+ secretTypes: ("api-key" | "aws-key" | "aws-secret" | "azure-key" | "certificate" | "connection-string" | "gcp-key" | "generic" | "password" | "private-key" | "token")[];
18
19
  excludePatterns: string[];
19
- secretTypes: ("password" | "token" | "api-key" | "private-key" | "connection-string" | "certificate" | "aws-key" | "aws-secret" | "gcp-key" | "azure-key" | "generic")[];
20
20
  includeEntropy: boolean;
21
21
  entropyThreshold: number;
22
22
  verifySecrets: boolean;
23
23
  scanHistory: boolean;
24
24
  }, {
25
25
  targetPath: string;
26
+ secretTypes?: ("api-key" | "aws-key" | "aws-secret" | "azure-key" | "certificate" | "connection-string" | "gcp-key" | "generic" | "password" | "private-key" | "token")[] | undefined;
26
27
  excludePatterns?: string[] | undefined;
27
- secretTypes?: ("password" | "token" | "api-key" | "private-key" | "connection-string" | "certificate" | "aws-key" | "aws-secret" | "gcp-key" | "azure-key" | "generic")[] | undefined;
28
28
  includeEntropy?: boolean | undefined;
29
29
  entropyThreshold?: number | undefined;
30
30
  verifySecrets?: boolean | undefined;
@@ -116,16 +116,16 @@ export declare const toolDefinition: {
116
116
  scanHistory: z.ZodDefault<z.ZodBoolean>;
117
117
  }, "strip", z.ZodTypeAny, {
118
118
  targetPath: string;
119
+ secretTypes: ("api-key" | "aws-key" | "aws-secret" | "azure-key" | "certificate" | "connection-string" | "gcp-key" | "generic" | "password" | "private-key" | "token")[];
119
120
  excludePatterns: string[];
120
- secretTypes: ("password" | "token" | "api-key" | "private-key" | "connection-string" | "certificate" | "aws-key" | "aws-secret" | "gcp-key" | "azure-key" | "generic")[];
121
121
  includeEntropy: boolean;
122
122
  entropyThreshold: number;
123
123
  verifySecrets: boolean;
124
124
  scanHistory: boolean;
125
125
  }, {
126
126
  targetPath: string;
127
+ secretTypes?: ("api-key" | "aws-key" | "aws-secret" | "azure-key" | "certificate" | "connection-string" | "gcp-key" | "generic" | "password" | "private-key" | "token")[] | undefined;
127
128
  excludePatterns?: string[] | undefined;
128
- secretTypes?: ("password" | "token" | "api-key" | "private-key" | "connection-string" | "certificate" | "aws-key" | "aws-secret" | "gcp-key" | "azure-key" | "generic")[] | undefined;
129
129
  includeEntropy?: boolean | undefined;
130
130
  entropyThreshold?: number | undefined;
131
131
  verifySecrets?: boolean | undefined;
@@ -127,6 +127,12 @@ export declare class EWCConsolidator {
127
127
  private globalFisher;
128
128
  private consolidationHistory;
129
129
  private initialized;
130
+ /** Dirty flag: true when in-memory state diverges from disk */
131
+ private dirty;
132
+ /** Pending debounced write timer */
133
+ private saveTimer;
134
+ /** Debounce window for disk writes (ms) */
135
+ private static readonly SAVE_DEBOUNCE_MS;
130
136
  constructor(config?: Partial<EWCConfig>);
131
137
  /**
132
138
  * Initialize the consolidator by loading persisted state
@@ -237,6 +243,12 @@ export declare class EWCConsolidator {
237
243
  * Prune old, low-importance patterns to stay within limit
238
244
  */
239
245
  private pruneOldPatterns;
246
+ /**
247
+ * Schedule a debounced disk flush.
248
+ * Multiple calls within SAVE_DEBOUNCE_MS coalesce into one write,
249
+ * preventing blocking I/O on every consolidation or gradient event.
250
+ */
251
+ private scheduleSave;
240
252
  /**
241
253
  * Save state to disk
242
254
  */
@@ -94,6 +94,12 @@ export declare class SONAOptimizer {
94
94
  private failedRoutings;
95
95
  private lastUpdate;
96
96
  private persistencePath;
97
+ /** Set when in-memory state diverges from disk — triggers next debounced write */
98
+ private dirty;
99
+ /** NodeJS timeout handle for debounced disk flush */
100
+ private saveTimer;
101
+ /** Debounce window for disk writes (ms) — batches rapid trajectory bursts */
102
+ private static readonly SAVE_DEBOUNCE_MS;
97
103
  constructor(options?: {
98
104
  persistencePath?: string;
99
105
  });
@@ -182,6 +188,12 @@ export declare class SONAOptimizer {
182
188
  * Load patterns from disk
183
189
  */
184
190
  private loadFromDisk;
191
+ /**
192
+ * Schedule a debounced disk flush.
193
+ * Multiple calls within SAVE_DEBOUNCE_MS coalesce into a single write,
194
+ * preventing blocking I/O on every trajectory event during swarm bursts.
195
+ */
196
+ private scheduleSave;
185
197
  /**
186
198
  * Save patterns to disk
187
199
  */
@@ -4,7 +4,9 @@ export interface BrokerEntry {
4
4
  updatedAt: number;
5
5
  }
6
6
  export declare function defaultRegistryDir(): string;
7
- /** Publish that this process hosts org `name`, reachable via `url`. Call again periodically (heartbeat) — see BrokerLease. */
7
+ /** Publish that this process hosts org `name`, reachable via `url`. Call again periodically (heartbeat) — see BrokerLease.
8
+ * Writes via tmp+rename (same-directory rename is atomic on POSIX/NTFS) so a concurrent lookupOrg() never observes a
9
+ * partially-written entry — this file is rewritten every heartbeat (default 20s) while other processes may read it. */
8
10
  export declare function registerOrg(name: string, url: string, dir?: string): void;
9
11
  /** Remove this process's registration for `name` (best effort). */
10
12
  export declare function unregisterOrg(name: string, dir?: string): void;
@@ -2,7 +2,7 @@
2
2
  // monolean: file-based local broker for cross-process org discovery (different
3
3
  // `monomind org` processes / project directories, same machine). Upgrade path:
4
4
  // a real network registry when cross-machine discovery is needed.
5
- import { mkdirSync, writeFileSync, readFileSync, unlinkSync } from 'node:fs';
5
+ import { mkdirSync, writeFileSync, readFileSync, unlinkSync, renameSync } from 'node:fs';
6
6
  import { join } from 'node:path';
7
7
  import { homedir } from 'node:os';
8
8
  const SAFE_NAME = /^[a-z0-9][a-z0-9_-]*$/i;
@@ -15,11 +15,16 @@ function entryPath(name, dir) {
15
15
  throw new Error(`invalid org name for broker registry: ${name}`);
16
16
  return join(dir, `${name}.json`);
17
17
  }
18
- /** Publish that this process hosts org `name`, reachable via `url`. Call again periodically (heartbeat) — see BrokerLease. */
18
+ /** Publish that this process hosts org `name`, reachable via `url`. Call again periodically (heartbeat) — see BrokerLease.
19
+ * Writes via tmp+rename (same-directory rename is atomic on POSIX/NTFS) so a concurrent lookupOrg() never observes a
20
+ * partially-written entry — this file is rewritten every heartbeat (default 20s) while other processes may read it. */
19
21
  export function registerOrg(name, url, dir = defaultRegistryDir()) {
20
22
  mkdirSync(dir, { recursive: true });
21
23
  const entry = { url, pid: process.pid, updatedAt: Date.now() };
22
- writeFileSync(entryPath(name, dir), JSON.stringify(entry));
24
+ const dest = entryPath(name, dir);
25
+ const tmp = `${dest}.${process.pid}.tmp`;
26
+ writeFileSync(tmp, JSON.stringify(entry));
27
+ renameSync(tmp, dest);
23
28
  }
24
29
  /** Remove this process's registration for `name` (best effort). */
25
30
  export function unregisterOrg(name, dir = defaultRegistryDir()) {
@@ -15,7 +15,11 @@ export declare class OrgBus {
15
15
  constructor(org: string, run: string, dir: string);
16
16
  subscribe(fn: Listener): () => void;
17
17
  emit(partial: Omit<BusEvent, 'id' | 'ts' | 'org' | 'run'>): BusEvent;
18
- /** await all queued disk writes (tests, shutdown) */
18
+ /** Await all queued disk writes (tests, shutdown). Listeners registered via subscribe() run
19
+ * synchronously inside emit() — flush() has no visibility into any async work they schedule
20
+ * off of that (e.g. the forwarder's HTTP POSTs). A caller that needs an async subscriber's
21
+ * work to have settled too must await that subscriber's own completion signal separately
22
+ * (see daemon.ts stopOrg(), which awaits forwarder.settle() alongside bus.flush()). */
19
23
  flush(): Promise<void>;
20
24
  static readHistory(dir: string): BusEvent[];
21
25
  }
@@ -45,7 +45,11 @@ export class OrgBus {
45
45
  }
46
46
  return e;
47
47
  }
48
- /** await all queued disk writes (tests, shutdown) */
48
+ /** Await all queued disk writes (tests, shutdown). Listeners registered via subscribe() run
49
+ * synchronously inside emit() — flush() has no visibility into any async work they schedule
50
+ * off of that (e.g. the forwarder's HTTP POSTs). A caller that needs an async subscriber's
51
+ * work to have settled too must await that subscriber's own completion signal separately
52
+ * (see daemon.ts stopOrg(), which awaits forwarder.settle() alongside bus.flush()). */
49
53
  flush() { return this.pending; }
50
54
  static readHistory(dir) {
51
55
  const f = join(dir, 'bus.jsonl');
@@ -33,11 +33,14 @@ export interface DaemonOpts {
33
33
  inboxUrl?: string;
34
34
  /** Override the broker's file registry directory (tests only). */
35
35
  brokerDir?: string;
36
+ /** Override how long stopOrg() waits for agent sessions before proceeding anyway (tests only; default 15000ms). */
37
+ stopWaitMs?: number;
36
38
  }
37
39
  export declare class OrgDaemon {
38
40
  private root;
39
41
  private opts;
40
42
  private orgs;
43
+ private waking;
41
44
  private globalSubscribers;
42
45
  private leases;
43
46
  private forwarders;
@@ -49,9 +52,18 @@ export declare class OrgDaemon {
49
52
  listOrgs(): RunningOrg[];
50
53
  getOrg(name: string): RunningOrg | undefined;
51
54
  startOrg(name: string, taskOverride?: string): Promise<RunningOrg>;
55
+ /**
56
+ * Resolves an org_send `to` address ("role" for same-org, "org:role" for
57
+ * cross-org) into its parts. Centralizes the one addressing rule that
58
+ * matters (an "own-org:role" self-prefix is intra-org, not cross-org) so
59
+ * deliver()/deliverRemote() don't each re-derive it — the qualified `to`
60
+ * string returned is always the canonical display form for that address.
61
+ */
62
+ private resolveAddress;
52
63
  /** Route a message. to = "role" (same org) or "org:role" (cross-org). Returns a receipt string. */
53
64
  deliver(fromOrg: string, fromRole: string, to: string, subject: string, body: string): Promise<string>;
54
- /** Cross-process leg of deliver(): ask the machine-local broker who hosts targetOrgName, then POST over HTTP. */
65
+ /** Cross-process leg of deliver(): ask the machine-local broker who hosts targetOrgName, then POST over HTTP.
66
+ * `to` here is always the fully-qualified "org:role" display form (resolveAddress already normalized it). */
55
67
  private deliverRemote;
56
68
  /** Inbound handler for cross-process delivery — called by the server's POST /api/xdeliver route
57
69
  * when ANOTHER process's deliverRemote() reaches this daemon. Pushes straight into the target
@@ -63,6 +75,10 @@ export declare class OrgDaemon {
63
75
  ok: false;
64
76
  error: string;
65
77
  };
78
+ private hasOrgDef;
79
+ /** Start an offline org in the background so queued messages get drained.
80
+ * Fire-and-forget — errors are logged but don't propagate to the sender. */
81
+ private autoWake;
66
82
  stopOrg(name: string): Promise<void>;
67
83
  stopAll(): Promise<void>;
68
84
  private persistState;