sentinelayer-cli 0.1.2 → 0.3.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 (127) hide show
  1. package/README.md +996 -996
  2. package/bin/create-sentinelayer.js +5 -5
  3. package/bin/sentinelayer-cli.js +4 -4
  4. package/bin/sl.js +5 -5
  5. package/package.json +62 -54
  6. package/src/agents/jules/config/definition.js +209 -209
  7. package/src/agents/jules/config/system-prompt.js +175 -175
  8. package/src/agents/jules/error-intake.js +51 -51
  9. package/src/agents/jules/fix-cycle.js +377 -377
  10. package/src/agents/jules/loop.js +367 -367
  11. package/src/agents/jules/pulse.js +319 -319
  12. package/src/agents/jules/stream.js +186 -186
  13. package/src/agents/jules/swarm/file-scanner.js +74 -74
  14. package/src/agents/jules/swarm/index.js +11 -11
  15. package/src/agents/jules/swarm/orchestrator.js +362 -362
  16. package/src/agents/jules/swarm/pattern-hunter.js +123 -123
  17. package/src/agents/jules/swarm/sub-agent.js +308 -308
  18. package/src/agents/jules/tools/auth-audit.js +226 -222
  19. package/src/agents/jules/tools/dispatch.js +327 -327
  20. package/src/agents/jules/tools/file-edit.js +180 -180
  21. package/src/agents/jules/tools/file-read.js +100 -100
  22. package/src/agents/jules/tools/frontend-analyze.js +570 -570
  23. package/src/agents/jules/tools/glob.js +168 -168
  24. package/src/agents/jules/tools/grep.js +228 -228
  25. package/src/agents/jules/tools/index.js +29 -29
  26. package/src/agents/jules/tools/path-guards.js +161 -161
  27. package/src/agents/jules/tools/runtime-audit.js +493 -493
  28. package/src/agents/jules/tools/shell.js +383 -383
  29. package/src/ai/aidenid.js +972 -945
  30. package/src/ai/client.js +508 -508
  31. package/src/ai/domain-target-store.js +268 -268
  32. package/src/ai/identity-store.js +270 -270
  33. package/src/ai/site-store.js +145 -145
  34. package/src/audit/agents/architecture.js +180 -180
  35. package/src/audit/agents/compliance.js +179 -179
  36. package/src/audit/agents/documentation.js +165 -165
  37. package/src/audit/agents/performance.js +145 -145
  38. package/src/audit/agents/security.js +215 -215
  39. package/src/audit/agents/testing.js +172 -172
  40. package/src/audit/orchestrator.js +557 -557
  41. package/src/audit/package.js +204 -204
  42. package/src/audit/registry.js +284 -284
  43. package/src/audit/replay.js +103 -103
  44. package/src/auth/http.js +113 -113
  45. package/src/auth/service.js +891 -848
  46. package/src/auth/session-store.js +359 -345
  47. package/src/cli.js +252 -252
  48. package/src/commands/ai/identity-lifecycle.js +1338 -1337
  49. package/src/commands/ai/provision-governance.js +1272 -1246
  50. package/src/commands/ai/shared.js +147 -147
  51. package/src/commands/ai.js +11 -11
  52. package/src/commands/apply.js +12 -12
  53. package/src/commands/audit.js +1166 -1166
  54. package/src/commands/auth.js +375 -366
  55. package/src/commands/chat.js +191 -191
  56. package/src/commands/config.js +184 -184
  57. package/src/commands/cost.js +311 -311
  58. package/src/commands/daemon/core.js +850 -850
  59. package/src/commands/daemon/extended.js +1048 -1048
  60. package/src/commands/daemon/shared.js +213 -213
  61. package/src/commands/daemon.js +11 -11
  62. package/src/commands/guide.js +174 -174
  63. package/src/commands/ingest.js +58 -58
  64. package/src/commands/init.js +55 -55
  65. package/src/commands/legacy-args.js +10 -10
  66. package/src/commands/mcp.js +461 -404
  67. package/src/commands/omargate.js +15 -15
  68. package/src/commands/persona.js +20 -20
  69. package/src/commands/plugin.js +260 -260
  70. package/src/commands/policy.js +132 -132
  71. package/src/commands/prompt.js +238 -238
  72. package/src/commands/review.js +704 -704
  73. package/src/commands/scan.js +866 -788
  74. package/src/commands/spec.js +716 -716
  75. package/src/commands/swarm.js +651 -651
  76. package/src/commands/telemetry.js +202 -202
  77. package/src/commands/watch.js +510 -510
  78. package/src/config/agent-dictionary.js +182 -182
  79. package/src/config/io.js +56 -56
  80. package/src/config/paths.js +18 -18
  81. package/src/config/schema.js +55 -55
  82. package/src/config/service.js +184 -184
  83. package/src/cost/budget.js +235 -235
  84. package/src/cost/history.js +188 -188
  85. package/src/cost/tracker.js +171 -171
  86. package/src/daemon/artifact-lineage.js +534 -534
  87. package/src/daemon/assignment-ledger.js +770 -770
  88. package/src/daemon/ast-parser-layer.js +258 -258
  89. package/src/daemon/budget-governor.js +633 -633
  90. package/src/daemon/callgraph-overlay.js +646 -646
  91. package/src/daemon/error-worker.js +626 -626
  92. package/src/daemon/hybrid-mapper.js +929 -929
  93. package/src/daemon/jira-lifecycle.js +632 -632
  94. package/src/daemon/operator-control.js +657 -657
  95. package/src/daemon/reliability-lane.js +471 -471
  96. package/src/daemon/watchdog.js +971 -971
  97. package/src/guide/generator.js +316 -316
  98. package/src/ingest/engine.js +918 -918
  99. package/src/legacy-cli.js +2548 -2435
  100. package/src/mcp/registry.js +695 -695
  101. package/src/memory/blackboard.js +301 -301
  102. package/src/memory/retrieval.js +581 -581
  103. package/src/plugin/manifest.js +553 -553
  104. package/src/policy/packs.js +144 -144
  105. package/src/prompt/generator.js +118 -106
  106. package/src/review/ai-review.js +669 -669
  107. package/src/review/local-review.js +1284 -1284
  108. package/src/review/replay.js +235 -235
  109. package/src/review/report.js +664 -664
  110. package/src/review/spec-binding.js +487 -487
  111. package/src/scaffold/generator.js +67 -0
  112. package/src/scaffold/templates.js +150 -0
  113. package/src/scan/generator.js +418 -351
  114. package/src/scan/gh-secrets.js +107 -0
  115. package/src/spec/generator.js +519 -519
  116. package/src/spec/regenerate.js +237 -237
  117. package/src/spec/templates.js +91 -91
  118. package/src/swarm/dashboard.js +247 -247
  119. package/src/swarm/factory.js +363 -363
  120. package/src/swarm/pentest.js +934 -934
  121. package/src/swarm/registry.js +419 -419
  122. package/src/swarm/report.js +158 -158
  123. package/src/swarm/runtime.js +576 -576
  124. package/src/swarm/scenario-dsl.js +272 -272
  125. package/src/telemetry/ledger.js +302 -302
  126. package/src/telemetry/sync.js +96 -59
  127. package/src/ui/markdown.js +220 -220
@@ -1,1048 +1,1048 @@
1
- import path from "node:path";
2
-
3
- import pc from "picocolors";
4
-
5
- import {
6
- WORK_ITEM_STATUSES,
7
- appendAdminErrorEvent,
8
- listErrorQueue,
9
- runErrorDaemonWorker,
10
- } from "../../daemon/error-worker.js";
11
- import { buildArtifactLineageIndex, listArtifactLineage } from "../../daemon/artifact-lineage.js";
12
- import {
13
- buildHybridScopeMap,
14
- buildHybridHandoffPackage,
15
- listHybridHandoffs,
16
- listHybridScopeMaps,
17
- showHybridHandoff,
18
- showHybridScopeMap,
19
- } from "../../daemon/hybrid-mapper.js";
20
- import {
21
- RELIABILITY_CHECK_IDS,
22
- getReliabilityLaneStatus,
23
- runReliabilityLane,
24
- setMaintenanceBillboard,
25
- } from "../../daemon/reliability-lane.js";
26
- import { getWatchdogStatus, runWatchdogTick } from "../../daemon/watchdog.js";
27
- import {
28
- parseBoolean,
29
- parseCsv,
30
- parseMetadata,
31
- parsePositiveInteger,
32
- printHybridMapSummary,
33
- printLineageSummary,
34
- printQueueSummary,
35
- printReliabilitySummary,
36
- shouldEmitJson,
37
- } from "./shared.js";
38
-
39
- export function registerDaemonExtendedCommands(daemon) {
40
- const lineage = daemon
41
- .command("lineage")
42
- .description("Build and inspect deterministic observability artifact lineage by work item");
43
-
44
- lineage
45
- .option("--path <path>", "Workspace path for artifact/config resolution", ".")
46
- .option("--output-dir <path>", "Optional output dir override for daemon artifacts")
47
- .option(
48
- "--status <csv>",
49
- `Optional queue status filter (${WORK_ITEM_STATUSES.join(", ")})`
50
- )
51
- .option("--work-item-id <id>", "Filter to a specific work item id")
52
- .option("--limit <n>", "Maximum work items to return", "50")
53
- .option("--json", "Emit machine-readable output")
54
- .action(async (options, command) => {
55
- const targetPath = path.resolve(process.cwd(), String(options.path || "."));
56
- const listed = await listArtifactLineage({
57
- targetPath,
58
- outputDir: options.outputDir,
59
- statuses: parseCsv(options.status),
60
- workItemId: options.workItemId,
61
- limit: parsePositiveInteger(options.limit, "limit", 50),
62
- });
63
- const payload = {
64
- command: "daemon lineage",
65
- targetPath,
66
- indexPath: listed.lineageIndexPath,
67
- eventPath: listed.lineageEventsPath,
68
- generatedAt: listed.generatedAt,
69
- lineageRunId: listed.lineageRunId,
70
- summary: listed.summary,
71
- totalCount: listed.totalCount,
72
- visibleCount: listed.workItems.length,
73
- workItems: listed.workItems,
74
- runs: listed.runs,
75
- };
76
- if (shouldEmitJson(options, command)) {
77
- console.log(JSON.stringify(payload, null, 2));
78
- return;
79
- }
80
- printLineageSummary(payload);
81
- });
82
-
83
- lineage
84
- .command("build")
85
- .description("Rebuild deterministic artifact lineage index from daemon observability artifacts")
86
- .option("--path <path>", "Workspace path for artifact/config resolution", ".")
87
- .option("--output-dir <path>", "Optional output dir override for daemon artifacts")
88
- .option("--now-iso <timestamp>", "Optional deterministic timestamp override")
89
- .option("--json", "Emit machine-readable output")
90
- .action(async (options, command) => {
91
- const targetPath = path.resolve(process.cwd(), String(options.path || "."));
92
- const built = await buildArtifactLineageIndex({
93
- targetPath,
94
- outputDir: options.outputDir,
95
- nowIso: options.nowIso,
96
- });
97
- const payload = {
98
- command: "daemon lineage build",
99
- targetPath,
100
- indexPath: built.indexPath,
101
- eventPath: built.eventPath,
102
- lineageRunId: built.lineageRunId,
103
- summary: built.summary,
104
- totalCount: built.workItems.length,
105
- visibleCount: Math.min(built.workItems.length, 20),
106
- workItems: built.workItems.slice(0, 20),
107
- };
108
- if (shouldEmitJson(options, command)) {
109
- console.log(JSON.stringify(payload, null, 2));
110
- return;
111
- }
112
- printLineageSummary(payload);
113
- });
114
-
115
- lineage
116
- .command("list")
117
- .description("List lineage work-item records from the latest lineage index")
118
- .option("--path <path>", "Workspace path for artifact/config resolution", ".")
119
- .option("--output-dir <path>", "Optional output dir override for daemon artifacts")
120
- .option(
121
- "--status <csv>",
122
- `Optional queue status filter (${WORK_ITEM_STATUSES.join(", ")})`
123
- )
124
- .option("--work-item-id <id>", "Filter to a specific work item id")
125
- .option("--limit <n>", "Maximum work items to return", "50")
126
- .option("--json", "Emit machine-readable output")
127
- .action(async (options, command) => {
128
- const targetPath = path.resolve(process.cwd(), String(options.path || "."));
129
- const listed = await listArtifactLineage({
130
- targetPath,
131
- outputDir: options.outputDir,
132
- statuses: parseCsv(options.status),
133
- workItemId: options.workItemId,
134
- limit: parsePositiveInteger(options.limit, "limit", 50),
135
- });
136
- const payload = {
137
- command: "daemon lineage list",
138
- targetPath,
139
- indexPath: listed.lineageIndexPath,
140
- eventPath: listed.lineageEventsPath,
141
- generatedAt: listed.generatedAt,
142
- lineageRunId: listed.lineageRunId,
143
- summary: listed.summary,
144
- totalCount: listed.totalCount,
145
- visibleCount: listed.workItems.length,
146
- workItems: listed.workItems,
147
- };
148
- if (shouldEmitJson(options, command)) {
149
- console.log(JSON.stringify(payload, null, 2));
150
- return;
151
- }
152
- printLineageSummary(payload);
153
- });
154
-
155
- lineage
156
- .command("show")
157
- .description("Show one lineage work-item record by id")
158
- .argument("<workItemId>", "Queue work item id")
159
- .option("--path <path>", "Workspace path for artifact/config resolution", ".")
160
- .option("--output-dir <path>", "Optional output dir override for daemon artifacts")
161
- .option("--json", "Emit machine-readable output")
162
- .action(async (workItemId, options, command) => {
163
- const targetPath = path.resolve(process.cwd(), String(options.path || "."));
164
- const listed = await listArtifactLineage({
165
- targetPath,
166
- outputDir: options.outputDir,
167
- workItemId,
168
- limit: 1,
169
- });
170
- const record = listed.workItems[0] || null;
171
- if (!record) {
172
- throw new Error(`No lineage record found for work item '${workItemId}'.`);
173
- }
174
- const payload = {
175
- command: "daemon lineage show",
176
- targetPath,
177
- indexPath: listed.lineageIndexPath,
178
- eventPath: listed.lineageEventsPath,
179
- generatedAt: listed.generatedAt,
180
- lineageRunId: listed.lineageRunId,
181
- workItem: record,
182
- };
183
- if (shouldEmitJson(options, command)) {
184
- console.log(JSON.stringify(payload, null, 2));
185
- return;
186
- }
187
- console.log(pc.bold("OMAR artifact lineage record"));
188
- console.log(pc.gray(`Index: ${listed.lineageIndexPath}`));
189
- console.log(
190
- `${record.workItemId} status=${record.workItemStatus} jira=${record.links?.jiraIssueKey || "n/a"} agent=${record.links?.agentIdentity || "unassigned"}`
191
- );
192
- });
193
-
194
- const map = daemon
195
- .command("map")
196
- .description("Hybrid deterministic + semantic codebase mapping overlay for work-item impact scope");
197
-
198
- map
199
- .option("--path <path>", "Workspace path for artifact/config resolution", ".")
200
- .option("--output-dir <path>", "Optional output dir override for daemon artifacts")
201
- .option("--work-item-id <id>", "Optional work item filter")
202
- .option("--limit <n>", "Maximum map entries to return", "50")
203
- .option("--json", "Emit machine-readable output")
204
- .action(async (options, command) => {
205
- const targetPath = path.resolve(process.cwd(), String(options.path || "."));
206
- const listed = await listHybridScopeMaps({
207
- targetPath,
208
- outputDir: options.outputDir,
209
- workItemId: options.workItemId,
210
- limit: parsePositiveInteger(options.limit, "limit", 50),
211
- });
212
- const payload = {
213
- command: "daemon map",
214
- targetPath,
215
- mapIndexPath: listed.mapIndexPath,
216
- mapEventsPath: listed.mapEventsPath,
217
- generatedAt: listed.generatedAt,
218
- totalCount: listed.totalCount,
219
- visibleCount: listed.maps.length,
220
- maps: listed.maps,
221
- };
222
- if (shouldEmitJson(options, command)) {
223
- console.log(JSON.stringify(payload, null, 2));
224
- return;
225
- }
226
- printHybridMapSummary(payload);
227
- });
228
-
229
- map
230
- .command("scope")
231
- .description("Build one hybrid scope map for a daemon work item")
232
- .argument("<workItemId>", "Queue work item id")
233
- .option("--path <path>", "Workspace path for artifact/config resolution", ".")
234
- .option("--output-dir <path>", "Optional output dir override for daemon artifacts")
235
- .option("--max-files <n>", "Maximum scoped files to emit", "40")
236
- .option("--graph-depth <n>", "Import-graph expansion depth", "2")
237
- .option("--now-iso <timestamp>", "Optional deterministic timestamp override")
238
- .option("--json", "Emit machine-readable output")
239
- .action(async (workItemId, options, command) => {
240
- const targetPath = path.resolve(process.cwd(), String(options.path || "."));
241
- const mapped = await buildHybridScopeMap({
242
- targetPath,
243
- outputDir: options.outputDir,
244
- workItemId,
245
- maxFiles: parsePositiveInteger(options.maxFiles, "max-files", 40),
246
- graphDepth: parsePositiveInteger(options.graphDepth, "graph-depth", 2),
247
- nowIso: options.nowIso,
248
- });
249
- const payload = {
250
- command: "daemon map scope",
251
- targetPath,
252
- runId: mapped.runId,
253
- runPath: mapped.runPath,
254
- mapIndexPath: mapped.mapIndexPath,
255
- mapEventsPath: mapped.mapEventsPath,
256
- strategy: mapped.strategy,
257
- summary: mapped.summary,
258
- workItem: mapped.workItem,
259
- scopedFiles: mapped.scopedFiles,
260
- importGraph: mapped.importGraph,
261
- };
262
- if (shouldEmitJson(options, command)) {
263
- console.log(JSON.stringify(payload, null, 2));
264
- return;
265
- }
266
- console.log(pc.bold("Hybrid scope map generated"));
267
- console.log(pc.gray(`Run: ${mapped.runId}`));
268
- console.log(pc.gray(`Artifact: ${mapped.runPath}`));
269
- console.log(
270
- `${mapped.workItem.workItemId} scoped_files=${mapped.summary.scopedFileCount} graph_nodes=${mapped.summary.graphNodeCount}`
271
- );
272
- });
273
-
274
- map
275
- .command("list")
276
- .description("List hybrid scope map records")
277
- .option("--path <path>", "Workspace path for artifact/config resolution", ".")
278
- .option("--output-dir <path>", "Optional output dir override for daemon artifacts")
279
- .option("--work-item-id <id>", "Optional work item filter")
280
- .option("--limit <n>", "Maximum map entries to return", "50")
281
- .option("--json", "Emit machine-readable output")
282
- .action(async (options, command) => {
283
- const targetPath = path.resolve(process.cwd(), String(options.path || "."));
284
- const listed = await listHybridScopeMaps({
285
- targetPath,
286
- outputDir: options.outputDir,
287
- workItemId: options.workItemId,
288
- limit: parsePositiveInteger(options.limit, "limit", 50),
289
- });
290
- const payload = {
291
- command: "daemon map list",
292
- targetPath,
293
- mapIndexPath: listed.mapIndexPath,
294
- mapEventsPath: listed.mapEventsPath,
295
- generatedAt: listed.generatedAt,
296
- totalCount: listed.totalCount,
297
- visibleCount: listed.maps.length,
298
- maps: listed.maps,
299
- };
300
- if (shouldEmitJson(options, command)) {
301
- console.log(JSON.stringify(payload, null, 2));
302
- return;
303
- }
304
- printHybridMapSummary(payload);
305
- });
306
-
307
- map
308
- .command("show")
309
- .description("Show one hybrid scope map artifact by work item (or explicit run)")
310
- .argument("<workItemId>", "Queue work item id")
311
- .option("--path <path>", "Workspace path for artifact/config resolution", ".")
312
- .option("--output-dir <path>", "Optional output dir override for daemon artifacts")
313
- .option("--run-id <id>", "Optional explicit map run id")
314
- .option("--json", "Emit machine-readable output")
315
- .action(async (workItemId, options, command) => {
316
- const targetPath = path.resolve(process.cwd(), String(options.path || "."));
317
- const shown = await showHybridScopeMap({
318
- targetPath,
319
- outputDir: options.outputDir,
320
- workItemId,
321
- runId: options.runId,
322
- });
323
- const payload = {
324
- command: "daemon map show",
325
- targetPath,
326
- mapIndexPath: shown.mapIndexPath,
327
- mapEventsPath: shown.mapEventsPath,
328
- mapPath: shown.mapPath,
329
- map: shown.map,
330
- payload: shown.payload,
331
- };
332
- if (shouldEmitJson(options, command)) {
333
- console.log(JSON.stringify(payload, null, 2));
334
- return;
335
- }
336
- console.log(pc.bold("Hybrid scope map"));
337
- console.log(pc.gray(`Artifact: ${shown.mapPath}`));
338
- console.log(
339
- `${shown.payload.workItem.workItemId} scoped_files=${shown.payload.summary?.scopedFileCount || 0} run=${shown.payload.runId}`
340
- );
341
- });
342
-
343
- map
344
- .command("handoff")
345
- .description("Build deterministic handoff package from hybrid map scope for one work item")
346
- .argument("<workItemId>", "Queue work item id")
347
- .option("--path <path>", "Workspace path for artifact/config resolution", ".")
348
- .option("--output-dir <path>", "Optional output dir override for daemon artifacts")
349
- .option("--run-id <id>", "Optional explicit source map run id")
350
- .option("--assignee <identity>", "Primary target agent identity", "omar")
351
- .option("--max-files <n>", "Maximum scoped files to include in handoff package", "24")
352
- .option("--now-iso <timestamp>", "Optional deterministic timestamp override")
353
- .option("--json", "Emit machine-readable output")
354
- .action(async (workItemId, options, command) => {
355
- const targetPath = path.resolve(process.cwd(), String(options.path || "."));
356
- const handoff = await buildHybridHandoffPackage({
357
- targetPath,
358
- outputDir: options.outputDir,
359
- workItemId,
360
- mapRunId: options.runId,
361
- assignee: options.assignee,
362
- maxFiles: parsePositiveInteger(options.maxFiles, "max-files", 24),
363
- nowIso: options.nowIso,
364
- });
365
- const payload = {
366
- command: "daemon map handoff",
367
- targetPath,
368
- handoffRunId: handoff.handoffRunId,
369
- handoffPath: handoff.handoffPath,
370
- handoffIndexPath: handoff.handoffIndexPath,
371
- handoffEventsPath: handoff.handoffEventsPath,
372
- summary: handoff.summary,
373
- payload: handoff.payload,
374
- };
375
- if (shouldEmitJson(options, command)) {
376
- console.log(JSON.stringify(payload, null, 2));
377
- return;
378
- }
379
- console.log(pc.bold("Hybrid handoff package generated"));
380
- console.log(pc.gray(`Run: ${handoff.handoffRunId}`));
381
- console.log(pc.gray(`Artifact: ${handoff.handoffPath}`));
382
- console.log(
383
- `${handoff.payload.workItem.workItemId} assignee=${handoff.payload.assignee.primary} files=${handoff.summary.scopedFileCount} tokens=${handoff.summary.estimatedInputTokens}`
384
- );
385
- });
386
-
387
- map
388
- .command("handoff-list")
389
- .description("List hybrid handoff package records")
390
- .option("--path <path>", "Workspace path for artifact/config resolution", ".")
391
- .option("--output-dir <path>", "Optional output dir override for daemon artifacts")
392
- .option("--work-item-id <id>", "Optional work item filter")
393
- .option("--limit <n>", "Maximum handoff records to return", "50")
394
- .option("--json", "Emit machine-readable output")
395
- .action(async (options, command) => {
396
- const targetPath = path.resolve(process.cwd(), String(options.path || "."));
397
- const listed = await listHybridHandoffs({
398
- targetPath,
399
- outputDir: options.outputDir,
400
- workItemId: options.workItemId,
401
- limit: parsePositiveInteger(options.limit, "limit", 50),
402
- });
403
- const payload = {
404
- command: "daemon map handoff-list",
405
- targetPath,
406
- handoffIndexPath: listed.handoffIndexPath,
407
- handoffEventsPath: listed.handoffEventsPath,
408
- generatedAt: listed.generatedAt,
409
- totalCount: listed.totalCount,
410
- visibleCount: listed.handoffs.length,
411
- handoffs: listed.handoffs,
412
- };
413
- if (shouldEmitJson(options, command)) {
414
- console.log(JSON.stringify(payload, null, 2));
415
- return;
416
- }
417
- console.log(pc.bold("Hybrid handoff packages"));
418
- console.log(pc.gray(`Index: ${listed.handoffIndexPath}`));
419
- console.log(pc.gray(`Events: ${listed.handoffEventsPath}`));
420
- console.log(pc.gray(`visible=${listed.handoffs.length} total=${listed.totalCount}`));
421
- for (const entry of listed.handoffs) {
422
- console.log(
423
- `- ${entry.handoffRunId} | work_item=${entry.workItemId} | assignee=${entry.assignee} | files=${entry.scopedFileCount}`
424
- );
425
- }
426
- });
427
-
428
- map
429
- .command("handoff-show")
430
- .description("Show one hybrid handoff package artifact by work item (or explicit run)")
431
- .argument("<workItemId>", "Queue work item id")
432
- .option("--path <path>", "Workspace path for artifact/config resolution", ".")
433
- .option("--output-dir <path>", "Optional output dir override for daemon artifacts")
434
- .option("--handoff-run-id <id>", "Optional explicit handoff run id")
435
- .option("--json", "Emit machine-readable output")
436
- .action(async (workItemId, options, command) => {
437
- const targetPath = path.resolve(process.cwd(), String(options.path || "."));
438
- const shown = await showHybridHandoff({
439
- targetPath,
440
- outputDir: options.outputDir,
441
- workItemId,
442
- handoffRunId: options.handoffRunId,
443
- });
444
- const payload = {
445
- command: "daemon map handoff-show",
446
- targetPath,
447
- handoffIndexPath: shown.handoffIndexPath,
448
- handoffEventsPath: shown.handoffEventsPath,
449
- handoffPath: shown.handoffPath,
450
- handoff: shown.handoff,
451
- payload: shown.payload,
452
- };
453
- if (shouldEmitJson(options, command)) {
454
- console.log(JSON.stringify(payload, null, 2));
455
- return;
456
- }
457
- console.log(pc.bold("Hybrid handoff package"));
458
- console.log(pc.gray(`Artifact: ${shown.handoffPath}`));
459
- console.log(
460
- `${shown.payload.workItem.workItemId} assignee=${shown.payload.assignee.primary} files=${shown.payload.files.length}`
461
- );
462
- });
463
-
464
- const reliability = daemon
465
- .command("reliability")
466
- .description("Midnight reliability lane controls and maintenance-billboard automation");
467
-
468
- const watchdog = daemon
469
- .command("watchdog")
470
- .description("Stuck-agent watchdog heuristics with state-change alerts and channel dispatch");
471
-
472
- watchdog
473
- .option("--path <path>", "Workspace path for artifact/config resolution", ".")
474
- .option("--output-dir <path>", "Optional output dir override for daemon artifacts")
475
- .option("--limit <n>", "Maximum recent runs to return", "10")
476
- .option("--json", "Emit machine-readable output")
477
- .action(async (options, command) => {
478
- const targetPath = path.resolve(process.cwd(), String(options.path || "."));
479
- const status = await getWatchdogStatus({
480
- targetPath,
481
- outputDir: options.outputDir,
482
- limit: parsePositiveInteger(options.limit, "limit", 10),
483
- });
484
- const payload = {
485
- command: "daemon watchdog",
486
- targetPath,
487
- configPath: status.configPath,
488
- statePath: status.statePath,
489
- eventsPath: status.eventsPath,
490
- runCount: status.runCount,
491
- activeAlertCount: status.activeAlertCount,
492
- activeAlerts: status.activeAlerts,
493
- recentRuns: status.recentRuns,
494
- config: status.config,
495
- };
496
- if (shouldEmitJson(options, command)) {
497
- console.log(JSON.stringify(payload, null, 2));
498
- return;
499
- }
500
- console.log(pc.bold("OMAR watchdog status"));
501
- console.log(pc.gray(`Config: ${status.configPath}`));
502
- console.log(pc.gray(`State: ${status.statePath}`));
503
- console.log(pc.gray(`Events: ${status.eventsPath}`));
504
- console.log(
505
- pc.gray(
506
- `active_alerts=${status.activeAlertCount} run_count=${status.runCount} channels=${status.config.channels.length}`
507
- )
508
- );
509
- for (const alert of status.activeAlerts) {
510
- console.log(
511
- `- ${alert.alertId} | ${alert.eventType} | ${alert.agentIdentity || "unassigned"} | ${alert.message}`
512
- );
513
- }
514
- });
515
-
516
- watchdog
517
- .command("run")
518
- .description("Run one watchdog evaluation tick and optionally dispatch channel alerts")
519
- .option("--path <path>", "Workspace path for artifact/config resolution", ".")
520
- .option("--output-dir <path>", "Optional output dir override for daemon artifacts")
521
- .option("--no-tool-call-seconds <n>", "Idle threshold for no tool calls", "60")
522
- .option(
523
- "--repeated-file-reads-threshold <n>",
524
- "Consecutive repeated file-read threshold",
525
- "3"
526
- )
527
- .option(
528
- "--budget-warning-threshold <ratio>",
529
- "Budget warning ratio threshold (0-1)",
530
- "0.9"
531
- )
532
- .option("--turn-stall-turns <n>", "Turn-stall threshold", "5")
533
- .option("--limit <n>", "Maximum records to inspect", "200")
534
- .option("--execute <bool>", "Dispatch alerts to channels (true/false)", "false")
535
- .option("--now-iso <timestamp>", "Optional deterministic timestamp override")
536
- .option("--json", "Emit machine-readable output")
537
- .action(async (options, command) => {
538
- const targetPath = path.resolve(process.cwd(), String(options.path || "."));
539
- const budgetThreshold = Number(options.budgetWarningThreshold || 0.9);
540
- if (!Number.isFinite(budgetThreshold) || budgetThreshold < 0 || budgetThreshold > 1) {
541
- throw new Error("budget-warning-threshold must be a number between 0 and 1.");
542
- }
543
- const executed = await runWatchdogTick({
544
- targetPath,
545
- outputDir: options.outputDir,
546
- noToolCallSeconds: parsePositiveInteger(
547
- options.noToolCallSeconds,
548
- "no-tool-call-seconds",
549
- 60
550
- ),
551
- repeatedFileReadsThreshold: parsePositiveInteger(
552
- options.repeatedFileReadsThreshold,
553
- "repeated-file-reads-threshold",
554
- 3
555
- ),
556
- budgetWarningThreshold: budgetThreshold,
557
- turnStallTurns: parsePositiveInteger(options.turnStallTurns, "turn-stall-turns", 5),
558
- limit: parsePositiveInteger(options.limit, "limit", 200),
559
- execute: parseBoolean(options.execute, false),
560
- nowIso: options.nowIso,
561
- });
562
- const payload = {
563
- command: "daemon watchdog run",
564
- targetPath,
565
- runId: executed.runId,
566
- runPath: executed.runPath,
567
- configPath: executed.configPath,
568
- statePath: executed.statePath,
569
- eventsPath: executed.eventsPath,
570
- configExists: executed.configExists,
571
- summary: executed.summary,
572
- detections: executed.detections,
573
- activatedAlerts: executed.activatedAlerts,
574
- recoveredAlerts: executed.recoveredAlerts,
575
- notifications: executed.notifications,
576
- };
577
- if (shouldEmitJson(options, command)) {
578
- console.log(JSON.stringify(payload, null, 2));
579
- return;
580
- }
581
- console.log(pc.bold("OMAR watchdog tick complete"));
582
- console.log(pc.gray(`Run: ${executed.runId}`));
583
- console.log(pc.gray(`Artifact: ${executed.runPath}`));
584
- console.log(
585
- `detections=${executed.summary.detectionCount} activated=${executed.summary.activatedCount} recovered=${executed.summary.recoveredCount} notifications=${executed.summary.notificationCount}`
586
- );
587
- for (const alert of executed.activatedAlerts) {
588
- console.log(`- activated ${alert.alertId} | ${alert.eventType} | ${alert.message}`);
589
- }
590
- for (const alert of executed.recoveredAlerts) {
591
- console.log(`- recovered ${alert.alertId} | ${alert.message}`);
592
- }
593
- });
594
-
595
- watchdog
596
- .command("status")
597
- .description("Show watchdog state and recent run summaries")
598
- .option("--path <path>", "Workspace path for artifact/config resolution", ".")
599
- .option("--output-dir <path>", "Optional output dir override for daemon artifacts")
600
- .option("--limit <n>", "Maximum recent runs to return", "10")
601
- .option("--json", "Emit machine-readable output")
602
- .action(async (options, command) => {
603
- const targetPath = path.resolve(process.cwd(), String(options.path || "."));
604
- const status = await getWatchdogStatus({
605
- targetPath,
606
- outputDir: options.outputDir,
607
- limit: parsePositiveInteger(options.limit, "limit", 10),
608
- });
609
- const payload = {
610
- command: "daemon watchdog status",
611
- targetPath,
612
- configPath: status.configPath,
613
- statePath: status.statePath,
614
- eventsPath: status.eventsPath,
615
- runCount: status.runCount,
616
- activeAlertCount: status.activeAlertCount,
617
- activeAlerts: status.activeAlerts,
618
- recentRuns: status.recentRuns,
619
- config: status.config,
620
- };
621
- if (shouldEmitJson(options, command)) {
622
- console.log(JSON.stringify(payload, null, 2));
623
- return;
624
- }
625
- console.log(pc.bold("OMAR watchdog status"));
626
- console.log(pc.gray(`Config: ${status.configPath}`));
627
- console.log(pc.gray(`State: ${status.statePath}`));
628
- console.log(pc.gray(`Events: ${status.eventsPath}`));
629
- console.log(
630
- pc.gray(
631
- `active_alerts=${status.activeAlertCount} run_count=${status.runCount} recent_runs=${status.recentRuns.length}`
632
- )
633
- );
634
- for (const run of status.recentRuns) {
635
- console.log(
636
- `- ${run.runId} | detections=${run.detectionCount} | activated=${run.activatedCount} | recovered=${run.recoveredCount}`
637
- );
638
- }
639
- });
640
-
641
- reliability
642
- .option("--path <path>", "Workspace path for artifact/config resolution", ".")
643
- .option("--output-dir <path>", "Optional output dir override for daemon artifacts")
644
- .option("--limit <n>", "Maximum recent runs to return", "10")
645
- .option("--json", "Emit machine-readable output")
646
- .action(async (options, command) => {
647
- const targetPath = path.resolve(process.cwd(), String(options.path || "."));
648
- const status = await getReliabilityLaneStatus({
649
- targetPath,
650
- outputDir: options.outputDir,
651
- limit: parsePositiveInteger(options.limit, "limit", 10),
652
- });
653
- const payload = {
654
- command: "daemon reliability",
655
- targetPath,
656
- configPath: status.configPath,
657
- billboardPath: status.billboardPath,
658
- eventsPath: status.eventsPath,
659
- config: status.config,
660
- billboard: status.billboard,
661
- runCount: status.runCount,
662
- recentRuns: status.recentRuns,
663
- };
664
- if (shouldEmitJson(options, command)) {
665
- console.log(JSON.stringify(payload, null, 2));
666
- return;
667
- }
668
- printReliabilitySummary(payload);
669
- });
670
-
671
- reliability
672
- .command("run")
673
- .description("Run one synthetic midnight reliability lane tick")
674
- .option("--path <path>", "Workspace path for artifact/config resolution", ".")
675
- .option("--output-dir <path>", "Optional output dir override for daemon artifacts")
676
- .option("--region <region>", "Target AWS region identifier", "us-east-1")
677
- .option("--timezone <timezone>", "Timezone label for run metadata", "UTC")
678
- .option(
679
- "--simulate-failure <csv>",
680
- `Simulate check failures (${RELIABILITY_CHECK_IDS.join(", ")})`
681
- )
682
- .option("--checks <csv>", "Optional subset of checks to run")
683
- .option(
684
- "--maintenance-auto-open <bool>",
685
- "Automatically enable maintenance billboard on lane failures (true/false)",
686
- "true"
687
- )
688
- .option(
689
- "--clear-maintenance-on-pass <bool>",
690
- "Clear reliability-lane maintenance billboard on passing run (true/false)",
691
- "true"
692
- )
693
- .option("--now-iso <timestamp>", "Optional deterministic timestamp override")
694
- .option("--json", "Emit machine-readable output")
695
- .action(async (options, command) => {
696
- const targetPath = path.resolve(process.cwd(), String(options.path || "."));
697
- const executed = await runReliabilityLane({
698
- targetPath,
699
- outputDir: options.outputDir,
700
- region: options.region,
701
- timezone: options.timezone,
702
- simulateFailures: parseCsv(options.simulateFailure),
703
- checks: parseCsv(options.checks),
704
- autoOpenMaintenance: parseBoolean(options.maintenanceAutoOpen, true),
705
- clearMaintenanceOnPass: parseBoolean(options.clearMaintenanceOnPass, true),
706
- nowIso: options.nowIso,
707
- });
708
- const payload = {
709
- command: "daemon reliability run",
710
- targetPath,
711
- runId: executed.runId,
712
- runPath: executed.runPath,
713
- configPath: executed.configPath,
714
- billboardPath: executed.billboardPath,
715
- eventsPath: executed.eventsPath,
716
- overallStatus: executed.overallStatus,
717
- checkCount: executed.checkCount,
718
- failureCount: executed.failureCount,
719
- checks: executed.checks,
720
- maintenance: executed.maintenance,
721
- worker: executed.worker,
722
- };
723
- if (shouldEmitJson(options, command)) {
724
- console.log(JSON.stringify(payload, null, 2));
725
- return;
726
- }
727
- console.log(pc.bold("Reliability lane run complete"));
728
- console.log(
729
- `${executed.runId} status=${executed.overallStatus} failures=${executed.failureCount} maintenance=${executed.maintenance.enabled ? "ON" : "OFF"}`
730
- );
731
- console.log(pc.gray(`Run artifact: ${executed.runPath}`));
732
- });
733
-
734
- reliability
735
- .command("status")
736
- .description("Show reliability lane status, config, billboard, and recent runs")
737
- .option("--path <path>", "Workspace path for artifact/config resolution", ".")
738
- .option("--output-dir <path>", "Optional output dir override for daemon artifacts")
739
- .option("--limit <n>", "Maximum recent runs to return", "10")
740
- .option("--json", "Emit machine-readable output")
741
- .action(async (options, command) => {
742
- const targetPath = path.resolve(process.cwd(), String(options.path || "."));
743
- const status = await getReliabilityLaneStatus({
744
- targetPath,
745
- outputDir: options.outputDir,
746
- limit: parsePositiveInteger(options.limit, "limit", 10),
747
- });
748
- const payload = {
749
- command: "daemon reliability status",
750
- targetPath,
751
- configPath: status.configPath,
752
- billboardPath: status.billboardPath,
753
- eventsPath: status.eventsPath,
754
- config: status.config,
755
- billboard: status.billboard,
756
- runCount: status.runCount,
757
- recentRuns: status.recentRuns,
758
- };
759
- if (shouldEmitJson(options, command)) {
760
- console.log(JSON.stringify(payload, null, 2));
761
- return;
762
- }
763
- printReliabilitySummary(payload);
764
- });
765
-
766
- const maintenance = daemon
767
- .command("maintenance")
768
- .description("Manual maintenance billboard controls for operator HITL visibility");
769
-
770
- maintenance
771
- .option("--path <path>", "Workspace path for artifact/config resolution", ".")
772
- .option("--output-dir <path>", "Optional output dir override for daemon artifacts")
773
- .option("--json", "Emit machine-readable output")
774
- .action(async (options, command) => {
775
- const targetPath = path.resolve(process.cwd(), String(options.path || "."));
776
- const status = await getReliabilityLaneStatus({
777
- targetPath,
778
- outputDir: options.outputDir,
779
- limit: 1,
780
- });
781
- const payload = {
782
- command: "daemon maintenance",
783
- targetPath,
784
- billboardPath: status.billboardPath,
785
- eventsPath: status.eventsPath,
786
- billboard: status.billboard,
787
- };
788
- if (shouldEmitJson(options, command)) {
789
- console.log(JSON.stringify(payload, null, 2));
790
- return;
791
- }
792
- console.log(pc.bold("OMAR maintenance billboard"));
793
- console.log(pc.gray(`Billboard: ${status.billboardPath}`));
794
- console.log(
795
- `enabled=${status.billboard.enabled ? "true" : "false"} source=${status.billboard.source || "n/a"} updated=${status.billboard.lastUpdatedAt || "n/a"}`
796
- );
797
- if (status.billboard.message) {
798
- console.log(status.billboard.message);
799
- }
800
- });
801
-
802
- maintenance
803
- .command("status")
804
- .description("Show current maintenance billboard state")
805
- .option("--path <path>", "Workspace path for artifact/config resolution", ".")
806
- .option("--output-dir <path>", "Optional output dir override for daemon artifacts")
807
- .option("--json", "Emit machine-readable output")
808
- .action(async (options, command) => {
809
- const targetPath = path.resolve(process.cwd(), String(options.path || "."));
810
- const status = await getReliabilityLaneStatus({
811
- targetPath,
812
- outputDir: options.outputDir,
813
- limit: 1,
814
- });
815
- const payload = {
816
- command: "daemon maintenance status",
817
- targetPath,
818
- billboardPath: status.billboardPath,
819
- eventsPath: status.eventsPath,
820
- billboard: status.billboard,
821
- };
822
- if (shouldEmitJson(options, command)) {
823
- console.log(JSON.stringify(payload, null, 2));
824
- return;
825
- }
826
- console.log(pc.bold("OMAR maintenance billboard"));
827
- console.log(pc.gray(`Billboard: ${status.billboardPath}`));
828
- console.log(
829
- `enabled=${status.billboard.enabled ? "true" : "false"} source=${status.billboard.source || "n/a"} updated=${status.billboard.lastUpdatedAt || "n/a"}`
830
- );
831
- if (status.billboard.message) {
832
- console.log(status.billboard.message);
833
- }
834
- });
835
-
836
- maintenance
837
- .command("on")
838
- .description("Enable maintenance billboard manually")
839
- .option("--path <path>", "Workspace path for artifact/config resolution", ".")
840
- .option("--output-dir <path>", "Optional output dir override for daemon artifacts")
841
- .option("--reason <text>", "Reason for maintenance mode", "Manual maintenance window")
842
- .option("--message <text>", "Billboard message")
843
- .option("--actor <identity>", "Operator identity", "omar-operator")
844
- .option("--json", "Emit machine-readable output")
845
- .action(async (options, command) => {
846
- const targetPath = path.resolve(process.cwd(), String(options.path || "."));
847
- const updated = await setMaintenanceBillboard({
848
- targetPath,
849
- outputDir: options.outputDir,
850
- enabled: true,
851
- source: "manual",
852
- actor: options.actor,
853
- reason: options.reason,
854
- message:
855
- options.message ||
856
- "Maintenance mode is active while reliability lane findings are being remediated.",
857
- });
858
- const payload = {
859
- command: "daemon maintenance on",
860
- targetPath,
861
- billboardPath: updated.billboardPath,
862
- eventsPath: updated.eventsPath,
863
- billboard: updated.billboard,
864
- };
865
- if (shouldEmitJson(options, command)) {
866
- console.log(JSON.stringify(payload, null, 2));
867
- return;
868
- }
869
- console.log(pc.bold("Maintenance billboard enabled"));
870
- console.log(pc.gray(`Billboard: ${updated.billboardPath}`));
871
- });
872
-
873
- maintenance
874
- .command("off")
875
- .description("Disable maintenance billboard manually")
876
- .option("--path <path>", "Workspace path for artifact/config resolution", ".")
877
- .option("--output-dir <path>", "Optional output dir override for daemon artifacts")
878
- .option("--reason <text>", "Reason for leaving maintenance mode", "Maintenance complete")
879
- .option("--message <text>", "Optional final message to persist")
880
- .option("--actor <identity>", "Operator identity", "omar-operator")
881
- .option("--json", "Emit machine-readable output")
882
- .action(async (options, command) => {
883
- const targetPath = path.resolve(process.cwd(), String(options.path || "."));
884
- const updated = await setMaintenanceBillboard({
885
- targetPath,
886
- outputDir: options.outputDir,
887
- enabled: false,
888
- source: "manual",
889
- actor: options.actor,
890
- reason: options.reason,
891
- message: options.message || "",
892
- });
893
- const payload = {
894
- command: "daemon maintenance off",
895
- targetPath,
896
- billboardPath: updated.billboardPath,
897
- eventsPath: updated.eventsPath,
898
- billboard: updated.billboard,
899
- };
900
- if (shouldEmitJson(options, command)) {
901
- console.log(JSON.stringify(payload, null, 2));
902
- return;
903
- }
904
- console.log(pc.bold("Maintenance billboard disabled"));
905
- console.log(pc.gray(`Billboard: ${updated.billboardPath}`));
906
- });
907
-
908
- const error = daemon
909
- .command("error")
910
- .description("Record, route, and inspect admin error events for OMAR daemon processing");
911
-
912
- error
913
- .command("record")
914
- .description("Record one admin error event into daemon intake stream")
915
- .option("--path <path>", "Workspace path for artifact/config resolution", ".")
916
- .option("--output-dir <path>", "Optional output dir override for daemon artifacts")
917
- .option("--source <source>", "Error source label", "admin_error_log")
918
- .option("--service <service>", "Service identifier", "sentinelayer-api")
919
- .option("--endpoint <endpoint>", "Endpoint or route", "unknown-endpoint")
920
- .option("--error-code <code>", "Error code", "UNKNOWN_ERROR")
921
- .option("--severity <severity>", "Severity (P0/P1/P2/P3)", "P2")
922
- .option("--message <message>", "Error summary message", "Unhandled runtime error")
923
- .option("--stack <stack>", "Optional stack trace text")
924
- .option("--commit-sha <sha>", "Optional commit sha")
925
- .option("--metadata-json <json>", "Optional metadata object as JSON string")
926
- .option("--json", "Emit machine-readable output")
927
- .action(async (options, command) => {
928
- const targetPath = path.resolve(process.cwd(), String(options.path || "."));
929
- const recorded = await appendAdminErrorEvent({
930
- targetPath,
931
- outputDir: options.outputDir,
932
- event: {
933
- source: options.source,
934
- service: options.service,
935
- endpoint: options.endpoint,
936
- errorCode: options.errorCode,
937
- severity: options.severity,
938
- message: options.message,
939
- stackTrace: options.stack,
940
- commitSha: options.commitSha,
941
- metadata: parseMetadata(options.metadataJson),
942
- },
943
- });
944
- const payload = {
945
- command: "daemon error record",
946
- targetPath,
947
- streamPath: recorded.streamPath,
948
- intakePath: recorded.intakePath,
949
- event: recorded.event,
950
- };
951
- if (shouldEmitJson(options, command)) {
952
- console.log(JSON.stringify(payload, null, 2));
953
- return;
954
- }
955
-
956
- console.log(pc.bold("OMAR daemon error event recorded"));
957
- console.log(pc.gray(`Stream: ${recorded.streamPath}`));
958
- console.log(pc.gray(`Intake artifact: ${recorded.intakePath}`));
959
- console.log(
960
- `event=${recorded.event.eventId} severity=${recorded.event.severity} fingerprint=${recorded.event.fingerprint}`
961
- );
962
- });
963
-
964
- error
965
- .command("worker")
966
- .description("Run one daemon worker tick over queued admin error stream events")
967
- .option("--path <path>", "Workspace path for artifact/config resolution", ".")
968
- .option("--output-dir <path>", "Optional output dir override for daemon artifacts")
969
- .option("--max-events <n>", "Maximum stream events to process this tick", "200")
970
- .option("--json", "Emit machine-readable output")
971
- .action(async (options, command) => {
972
- const targetPath = path.resolve(process.cwd(), String(options.path || "."));
973
- const execution = await runErrorDaemonWorker({
974
- targetPath,
975
- outputDir: options.outputDir,
976
- maxEvents: parsePositiveInteger(options.maxEvents, "max-events", 200),
977
- });
978
- const payload = {
979
- command: "daemon error worker",
980
- targetPath,
981
- runId: execution.runId,
982
- runPath: execution.runPath,
983
- streamPath: execution.streamPath,
984
- queuePath: execution.queuePath,
985
- statePath: execution.statePath,
986
- maxEvents: execution.maxEvents,
987
- startOffset: execution.startOffset,
988
- endOffset: execution.endOffset,
989
- streamLength: execution.streamLength,
990
- processedCount: execution.processedCount,
991
- queuedCount: execution.queuedCount,
992
- dedupedCount: execution.dedupedCount,
993
- parseErrorCount: execution.parseErrorCount,
994
- queueDepth: execution.queueDepth,
995
- workerState: execution.state,
996
- };
997
-
998
- if (shouldEmitJson(options, command)) {
999
- console.log(JSON.stringify(payload, null, 2));
1000
- return;
1001
- }
1002
-
1003
- console.log(pc.bold("OMAR daemon worker tick completed"));
1004
- console.log(pc.gray(`Run artifact: ${execution.runPath}`));
1005
- console.log(
1006
- `processed=${execution.processedCount} queued=${execution.queuedCount} deduped=${execution.dedupedCount} queue_depth=${execution.queueDepth}`
1007
- );
1008
- });
1009
-
1010
- error
1011
- .command("queue")
1012
- .description("Inspect routed daemon queue items")
1013
- .option("--path <path>", "Workspace path for artifact/config resolution", ".")
1014
- .option("--output-dir <path>", "Optional output dir override for daemon artifacts")
1015
- .option(
1016
- "--status <csv>",
1017
- `Optional queue status filter (${WORK_ITEM_STATUSES.join(", ")})`
1018
- )
1019
- .option("--limit <n>", "Maximum queue items to return", "50")
1020
- .option("--json", "Emit machine-readable output")
1021
- .action(async (options, command) => {
1022
- const targetPath = path.resolve(process.cwd(), String(options.path || "."));
1023
- const statuses = parseCsv(options.status);
1024
- const listed = await listErrorQueue({
1025
- targetPath,
1026
- outputDir: options.outputDir,
1027
- statuses,
1028
- limit: parsePositiveInteger(options.limit, "limit", 50),
1029
- });
1030
- const payload = {
1031
- command: "daemon error queue",
1032
- targetPath,
1033
- statuses,
1034
- queuePath: listed.queuePath,
1035
- statePath: listed.statePath,
1036
- streamPath: listed.streamPath,
1037
- totalCount: listed.totalCount,
1038
- visibleCount: listed.items.length,
1039
- items: listed.items,
1040
- workerState: listed.state,
1041
- };
1042
- if (shouldEmitJson(options, command)) {
1043
- console.log(JSON.stringify(payload, null, 2));
1044
- return;
1045
- }
1046
- printQueueSummary(payload);
1047
- });
1048
- }
1
+ import path from "node:path";
2
+
3
+ import pc from "picocolors";
4
+
5
+ import {
6
+ WORK_ITEM_STATUSES,
7
+ appendAdminErrorEvent,
8
+ listErrorQueue,
9
+ runErrorDaemonWorker,
10
+ } from "../../daemon/error-worker.js";
11
+ import { buildArtifactLineageIndex, listArtifactLineage } from "../../daemon/artifact-lineage.js";
12
+ import {
13
+ buildHybridScopeMap,
14
+ buildHybridHandoffPackage,
15
+ listHybridHandoffs,
16
+ listHybridScopeMaps,
17
+ showHybridHandoff,
18
+ showHybridScopeMap,
19
+ } from "../../daemon/hybrid-mapper.js";
20
+ import {
21
+ RELIABILITY_CHECK_IDS,
22
+ getReliabilityLaneStatus,
23
+ runReliabilityLane,
24
+ setMaintenanceBillboard,
25
+ } from "../../daemon/reliability-lane.js";
26
+ import { getWatchdogStatus, runWatchdogTick } from "../../daemon/watchdog.js";
27
+ import {
28
+ parseBoolean,
29
+ parseCsv,
30
+ parseMetadata,
31
+ parsePositiveInteger,
32
+ printHybridMapSummary,
33
+ printLineageSummary,
34
+ printQueueSummary,
35
+ printReliabilitySummary,
36
+ shouldEmitJson,
37
+ } from "./shared.js";
38
+
39
+ export function registerDaemonExtendedCommands(daemon) {
40
+ const lineage = daemon
41
+ .command("lineage")
42
+ .description("Build and inspect deterministic observability artifact lineage by work item");
43
+
44
+ lineage
45
+ .option("--path <path>", "Workspace path for artifact/config resolution", ".")
46
+ .option("--output-dir <path>", "Optional output dir override for daemon artifacts")
47
+ .option(
48
+ "--status <csv>",
49
+ `Optional queue status filter (${WORK_ITEM_STATUSES.join(", ")})`
50
+ )
51
+ .option("--work-item-id <id>", "Filter to a specific work item id")
52
+ .option("--limit <n>", "Maximum work items to return", "50")
53
+ .option("--json", "Emit machine-readable output")
54
+ .action(async (options, command) => {
55
+ const targetPath = path.resolve(process.cwd(), String(options.path || "."));
56
+ const listed = await listArtifactLineage({
57
+ targetPath,
58
+ outputDir: options.outputDir,
59
+ statuses: parseCsv(options.status),
60
+ workItemId: options.workItemId,
61
+ limit: parsePositiveInteger(options.limit, "limit", 50),
62
+ });
63
+ const payload = {
64
+ command: "daemon lineage",
65
+ targetPath,
66
+ indexPath: listed.lineageIndexPath,
67
+ eventPath: listed.lineageEventsPath,
68
+ generatedAt: listed.generatedAt,
69
+ lineageRunId: listed.lineageRunId,
70
+ summary: listed.summary,
71
+ totalCount: listed.totalCount,
72
+ visibleCount: listed.workItems.length,
73
+ workItems: listed.workItems,
74
+ runs: listed.runs,
75
+ };
76
+ if (shouldEmitJson(options, command)) {
77
+ console.log(JSON.stringify(payload, null, 2));
78
+ return;
79
+ }
80
+ printLineageSummary(payload);
81
+ });
82
+
83
+ lineage
84
+ .command("build")
85
+ .description("Rebuild deterministic artifact lineage index from daemon observability artifacts")
86
+ .option("--path <path>", "Workspace path for artifact/config resolution", ".")
87
+ .option("--output-dir <path>", "Optional output dir override for daemon artifacts")
88
+ .option("--now-iso <timestamp>", "Optional deterministic timestamp override")
89
+ .option("--json", "Emit machine-readable output")
90
+ .action(async (options, command) => {
91
+ const targetPath = path.resolve(process.cwd(), String(options.path || "."));
92
+ const built = await buildArtifactLineageIndex({
93
+ targetPath,
94
+ outputDir: options.outputDir,
95
+ nowIso: options.nowIso,
96
+ });
97
+ const payload = {
98
+ command: "daemon lineage build",
99
+ targetPath,
100
+ indexPath: built.indexPath,
101
+ eventPath: built.eventPath,
102
+ lineageRunId: built.lineageRunId,
103
+ summary: built.summary,
104
+ totalCount: built.workItems.length,
105
+ visibleCount: Math.min(built.workItems.length, 20),
106
+ workItems: built.workItems.slice(0, 20),
107
+ };
108
+ if (shouldEmitJson(options, command)) {
109
+ console.log(JSON.stringify(payload, null, 2));
110
+ return;
111
+ }
112
+ printLineageSummary(payload);
113
+ });
114
+
115
+ lineage
116
+ .command("list")
117
+ .description("List lineage work-item records from the latest lineage index")
118
+ .option("--path <path>", "Workspace path for artifact/config resolution", ".")
119
+ .option("--output-dir <path>", "Optional output dir override for daemon artifacts")
120
+ .option(
121
+ "--status <csv>",
122
+ `Optional queue status filter (${WORK_ITEM_STATUSES.join(", ")})`
123
+ )
124
+ .option("--work-item-id <id>", "Filter to a specific work item id")
125
+ .option("--limit <n>", "Maximum work items to return", "50")
126
+ .option("--json", "Emit machine-readable output")
127
+ .action(async (options, command) => {
128
+ const targetPath = path.resolve(process.cwd(), String(options.path || "."));
129
+ const listed = await listArtifactLineage({
130
+ targetPath,
131
+ outputDir: options.outputDir,
132
+ statuses: parseCsv(options.status),
133
+ workItemId: options.workItemId,
134
+ limit: parsePositiveInteger(options.limit, "limit", 50),
135
+ });
136
+ const payload = {
137
+ command: "daemon lineage list",
138
+ targetPath,
139
+ indexPath: listed.lineageIndexPath,
140
+ eventPath: listed.lineageEventsPath,
141
+ generatedAt: listed.generatedAt,
142
+ lineageRunId: listed.lineageRunId,
143
+ summary: listed.summary,
144
+ totalCount: listed.totalCount,
145
+ visibleCount: listed.workItems.length,
146
+ workItems: listed.workItems,
147
+ };
148
+ if (shouldEmitJson(options, command)) {
149
+ console.log(JSON.stringify(payload, null, 2));
150
+ return;
151
+ }
152
+ printLineageSummary(payload);
153
+ });
154
+
155
+ lineage
156
+ .command("show")
157
+ .description("Show one lineage work-item record by id")
158
+ .argument("<workItemId>", "Queue work item id")
159
+ .option("--path <path>", "Workspace path for artifact/config resolution", ".")
160
+ .option("--output-dir <path>", "Optional output dir override for daemon artifacts")
161
+ .option("--json", "Emit machine-readable output")
162
+ .action(async (workItemId, options, command) => {
163
+ const targetPath = path.resolve(process.cwd(), String(options.path || "."));
164
+ const listed = await listArtifactLineage({
165
+ targetPath,
166
+ outputDir: options.outputDir,
167
+ workItemId,
168
+ limit: 1,
169
+ });
170
+ const record = listed.workItems[0] || null;
171
+ if (!record) {
172
+ throw new Error(`No lineage record found for work item '${workItemId}'.`);
173
+ }
174
+ const payload = {
175
+ command: "daemon lineage show",
176
+ targetPath,
177
+ indexPath: listed.lineageIndexPath,
178
+ eventPath: listed.lineageEventsPath,
179
+ generatedAt: listed.generatedAt,
180
+ lineageRunId: listed.lineageRunId,
181
+ workItem: record,
182
+ };
183
+ if (shouldEmitJson(options, command)) {
184
+ console.log(JSON.stringify(payload, null, 2));
185
+ return;
186
+ }
187
+ console.log(pc.bold("OMAR artifact lineage record"));
188
+ console.log(pc.gray(`Index: ${listed.lineageIndexPath}`));
189
+ console.log(
190
+ `${record.workItemId} status=${record.workItemStatus} jira=${record.links?.jiraIssueKey || "n/a"} agent=${record.links?.agentIdentity || "unassigned"}`
191
+ );
192
+ });
193
+
194
+ const map = daemon
195
+ .command("map")
196
+ .description("Hybrid deterministic + semantic codebase mapping overlay for work-item impact scope");
197
+
198
+ map
199
+ .option("--path <path>", "Workspace path for artifact/config resolution", ".")
200
+ .option("--output-dir <path>", "Optional output dir override for daemon artifacts")
201
+ .option("--work-item-id <id>", "Optional work item filter")
202
+ .option("--limit <n>", "Maximum map entries to return", "50")
203
+ .option("--json", "Emit machine-readable output")
204
+ .action(async (options, command) => {
205
+ const targetPath = path.resolve(process.cwd(), String(options.path || "."));
206
+ const listed = await listHybridScopeMaps({
207
+ targetPath,
208
+ outputDir: options.outputDir,
209
+ workItemId: options.workItemId,
210
+ limit: parsePositiveInteger(options.limit, "limit", 50),
211
+ });
212
+ const payload = {
213
+ command: "daemon map",
214
+ targetPath,
215
+ mapIndexPath: listed.mapIndexPath,
216
+ mapEventsPath: listed.mapEventsPath,
217
+ generatedAt: listed.generatedAt,
218
+ totalCount: listed.totalCount,
219
+ visibleCount: listed.maps.length,
220
+ maps: listed.maps,
221
+ };
222
+ if (shouldEmitJson(options, command)) {
223
+ console.log(JSON.stringify(payload, null, 2));
224
+ return;
225
+ }
226
+ printHybridMapSummary(payload);
227
+ });
228
+
229
+ map
230
+ .command("scope")
231
+ .description("Build one hybrid scope map for a daemon work item")
232
+ .argument("<workItemId>", "Queue work item id")
233
+ .option("--path <path>", "Workspace path for artifact/config resolution", ".")
234
+ .option("--output-dir <path>", "Optional output dir override for daemon artifacts")
235
+ .option("--max-files <n>", "Maximum scoped files to emit", "40")
236
+ .option("--graph-depth <n>", "Import-graph expansion depth", "2")
237
+ .option("--now-iso <timestamp>", "Optional deterministic timestamp override")
238
+ .option("--json", "Emit machine-readable output")
239
+ .action(async (workItemId, options, command) => {
240
+ const targetPath = path.resolve(process.cwd(), String(options.path || "."));
241
+ const mapped = await buildHybridScopeMap({
242
+ targetPath,
243
+ outputDir: options.outputDir,
244
+ workItemId,
245
+ maxFiles: parsePositiveInteger(options.maxFiles, "max-files", 40),
246
+ graphDepth: parsePositiveInteger(options.graphDepth, "graph-depth", 2),
247
+ nowIso: options.nowIso,
248
+ });
249
+ const payload = {
250
+ command: "daemon map scope",
251
+ targetPath,
252
+ runId: mapped.runId,
253
+ runPath: mapped.runPath,
254
+ mapIndexPath: mapped.mapIndexPath,
255
+ mapEventsPath: mapped.mapEventsPath,
256
+ strategy: mapped.strategy,
257
+ summary: mapped.summary,
258
+ workItem: mapped.workItem,
259
+ scopedFiles: mapped.scopedFiles,
260
+ importGraph: mapped.importGraph,
261
+ };
262
+ if (shouldEmitJson(options, command)) {
263
+ console.log(JSON.stringify(payload, null, 2));
264
+ return;
265
+ }
266
+ console.log(pc.bold("Hybrid scope map generated"));
267
+ console.log(pc.gray(`Run: ${mapped.runId}`));
268
+ console.log(pc.gray(`Artifact: ${mapped.runPath}`));
269
+ console.log(
270
+ `${mapped.workItem.workItemId} scoped_files=${mapped.summary.scopedFileCount} graph_nodes=${mapped.summary.graphNodeCount}`
271
+ );
272
+ });
273
+
274
+ map
275
+ .command("list")
276
+ .description("List hybrid scope map records")
277
+ .option("--path <path>", "Workspace path for artifact/config resolution", ".")
278
+ .option("--output-dir <path>", "Optional output dir override for daemon artifacts")
279
+ .option("--work-item-id <id>", "Optional work item filter")
280
+ .option("--limit <n>", "Maximum map entries to return", "50")
281
+ .option("--json", "Emit machine-readable output")
282
+ .action(async (options, command) => {
283
+ const targetPath = path.resolve(process.cwd(), String(options.path || "."));
284
+ const listed = await listHybridScopeMaps({
285
+ targetPath,
286
+ outputDir: options.outputDir,
287
+ workItemId: options.workItemId,
288
+ limit: parsePositiveInteger(options.limit, "limit", 50),
289
+ });
290
+ const payload = {
291
+ command: "daemon map list",
292
+ targetPath,
293
+ mapIndexPath: listed.mapIndexPath,
294
+ mapEventsPath: listed.mapEventsPath,
295
+ generatedAt: listed.generatedAt,
296
+ totalCount: listed.totalCount,
297
+ visibleCount: listed.maps.length,
298
+ maps: listed.maps,
299
+ };
300
+ if (shouldEmitJson(options, command)) {
301
+ console.log(JSON.stringify(payload, null, 2));
302
+ return;
303
+ }
304
+ printHybridMapSummary(payload);
305
+ });
306
+
307
+ map
308
+ .command("show")
309
+ .description("Show one hybrid scope map artifact by work item (or explicit run)")
310
+ .argument("<workItemId>", "Queue work item id")
311
+ .option("--path <path>", "Workspace path for artifact/config resolution", ".")
312
+ .option("--output-dir <path>", "Optional output dir override for daemon artifacts")
313
+ .option("--run-id <id>", "Optional explicit map run id")
314
+ .option("--json", "Emit machine-readable output")
315
+ .action(async (workItemId, options, command) => {
316
+ const targetPath = path.resolve(process.cwd(), String(options.path || "."));
317
+ const shown = await showHybridScopeMap({
318
+ targetPath,
319
+ outputDir: options.outputDir,
320
+ workItemId,
321
+ runId: options.runId,
322
+ });
323
+ const payload = {
324
+ command: "daemon map show",
325
+ targetPath,
326
+ mapIndexPath: shown.mapIndexPath,
327
+ mapEventsPath: shown.mapEventsPath,
328
+ mapPath: shown.mapPath,
329
+ map: shown.map,
330
+ payload: shown.payload,
331
+ };
332
+ if (shouldEmitJson(options, command)) {
333
+ console.log(JSON.stringify(payload, null, 2));
334
+ return;
335
+ }
336
+ console.log(pc.bold("Hybrid scope map"));
337
+ console.log(pc.gray(`Artifact: ${shown.mapPath}`));
338
+ console.log(
339
+ `${shown.payload.workItem.workItemId} scoped_files=${shown.payload.summary?.scopedFileCount || 0} run=${shown.payload.runId}`
340
+ );
341
+ });
342
+
343
+ map
344
+ .command("handoff")
345
+ .description("Build deterministic handoff package from hybrid map scope for one work item")
346
+ .argument("<workItemId>", "Queue work item id")
347
+ .option("--path <path>", "Workspace path for artifact/config resolution", ".")
348
+ .option("--output-dir <path>", "Optional output dir override for daemon artifacts")
349
+ .option("--run-id <id>", "Optional explicit source map run id")
350
+ .option("--assignee <identity>", "Primary target agent identity", "omar")
351
+ .option("--max-files <n>", "Maximum scoped files to include in handoff package", "24")
352
+ .option("--now-iso <timestamp>", "Optional deterministic timestamp override")
353
+ .option("--json", "Emit machine-readable output")
354
+ .action(async (workItemId, options, command) => {
355
+ const targetPath = path.resolve(process.cwd(), String(options.path || "."));
356
+ const handoff = await buildHybridHandoffPackage({
357
+ targetPath,
358
+ outputDir: options.outputDir,
359
+ workItemId,
360
+ mapRunId: options.runId,
361
+ assignee: options.assignee,
362
+ maxFiles: parsePositiveInteger(options.maxFiles, "max-files", 24),
363
+ nowIso: options.nowIso,
364
+ });
365
+ const payload = {
366
+ command: "daemon map handoff",
367
+ targetPath,
368
+ handoffRunId: handoff.handoffRunId,
369
+ handoffPath: handoff.handoffPath,
370
+ handoffIndexPath: handoff.handoffIndexPath,
371
+ handoffEventsPath: handoff.handoffEventsPath,
372
+ summary: handoff.summary,
373
+ payload: handoff.payload,
374
+ };
375
+ if (shouldEmitJson(options, command)) {
376
+ console.log(JSON.stringify(payload, null, 2));
377
+ return;
378
+ }
379
+ console.log(pc.bold("Hybrid handoff package generated"));
380
+ console.log(pc.gray(`Run: ${handoff.handoffRunId}`));
381
+ console.log(pc.gray(`Artifact: ${handoff.handoffPath}`));
382
+ console.log(
383
+ `${handoff.payload.workItem.workItemId} assignee=${handoff.payload.assignee.primary} files=${handoff.summary.scopedFileCount} tokens=${handoff.summary.estimatedInputTokens}`
384
+ );
385
+ });
386
+
387
+ map
388
+ .command("handoff-list")
389
+ .description("List hybrid handoff package records")
390
+ .option("--path <path>", "Workspace path for artifact/config resolution", ".")
391
+ .option("--output-dir <path>", "Optional output dir override for daemon artifacts")
392
+ .option("--work-item-id <id>", "Optional work item filter")
393
+ .option("--limit <n>", "Maximum handoff records to return", "50")
394
+ .option("--json", "Emit machine-readable output")
395
+ .action(async (options, command) => {
396
+ const targetPath = path.resolve(process.cwd(), String(options.path || "."));
397
+ const listed = await listHybridHandoffs({
398
+ targetPath,
399
+ outputDir: options.outputDir,
400
+ workItemId: options.workItemId,
401
+ limit: parsePositiveInteger(options.limit, "limit", 50),
402
+ });
403
+ const payload = {
404
+ command: "daemon map handoff-list",
405
+ targetPath,
406
+ handoffIndexPath: listed.handoffIndexPath,
407
+ handoffEventsPath: listed.handoffEventsPath,
408
+ generatedAt: listed.generatedAt,
409
+ totalCount: listed.totalCount,
410
+ visibleCount: listed.handoffs.length,
411
+ handoffs: listed.handoffs,
412
+ };
413
+ if (shouldEmitJson(options, command)) {
414
+ console.log(JSON.stringify(payload, null, 2));
415
+ return;
416
+ }
417
+ console.log(pc.bold("Hybrid handoff packages"));
418
+ console.log(pc.gray(`Index: ${listed.handoffIndexPath}`));
419
+ console.log(pc.gray(`Events: ${listed.handoffEventsPath}`));
420
+ console.log(pc.gray(`visible=${listed.handoffs.length} total=${listed.totalCount}`));
421
+ for (const entry of listed.handoffs) {
422
+ console.log(
423
+ `- ${entry.handoffRunId} | work_item=${entry.workItemId} | assignee=${entry.assignee} | files=${entry.scopedFileCount}`
424
+ );
425
+ }
426
+ });
427
+
428
+ map
429
+ .command("handoff-show")
430
+ .description("Show one hybrid handoff package artifact by work item (or explicit run)")
431
+ .argument("<workItemId>", "Queue work item id")
432
+ .option("--path <path>", "Workspace path for artifact/config resolution", ".")
433
+ .option("--output-dir <path>", "Optional output dir override for daemon artifacts")
434
+ .option("--handoff-run-id <id>", "Optional explicit handoff run id")
435
+ .option("--json", "Emit machine-readable output")
436
+ .action(async (workItemId, options, command) => {
437
+ const targetPath = path.resolve(process.cwd(), String(options.path || "."));
438
+ const shown = await showHybridHandoff({
439
+ targetPath,
440
+ outputDir: options.outputDir,
441
+ workItemId,
442
+ handoffRunId: options.handoffRunId,
443
+ });
444
+ const payload = {
445
+ command: "daemon map handoff-show",
446
+ targetPath,
447
+ handoffIndexPath: shown.handoffIndexPath,
448
+ handoffEventsPath: shown.handoffEventsPath,
449
+ handoffPath: shown.handoffPath,
450
+ handoff: shown.handoff,
451
+ payload: shown.payload,
452
+ };
453
+ if (shouldEmitJson(options, command)) {
454
+ console.log(JSON.stringify(payload, null, 2));
455
+ return;
456
+ }
457
+ console.log(pc.bold("Hybrid handoff package"));
458
+ console.log(pc.gray(`Artifact: ${shown.handoffPath}`));
459
+ console.log(
460
+ `${shown.payload.workItem.workItemId} assignee=${shown.payload.assignee.primary} files=${shown.payload.files.length}`
461
+ );
462
+ });
463
+
464
+ const reliability = daemon
465
+ .command("reliability")
466
+ .description("Midnight reliability lane controls and maintenance-billboard automation");
467
+
468
+ const watchdog = daemon
469
+ .command("watchdog")
470
+ .description("Stuck-agent watchdog heuristics with state-change alerts and channel dispatch");
471
+
472
+ watchdog
473
+ .option("--path <path>", "Workspace path for artifact/config resolution", ".")
474
+ .option("--output-dir <path>", "Optional output dir override for daemon artifacts")
475
+ .option("--limit <n>", "Maximum recent runs to return", "10")
476
+ .option("--json", "Emit machine-readable output")
477
+ .action(async (options, command) => {
478
+ const targetPath = path.resolve(process.cwd(), String(options.path || "."));
479
+ const status = await getWatchdogStatus({
480
+ targetPath,
481
+ outputDir: options.outputDir,
482
+ limit: parsePositiveInteger(options.limit, "limit", 10),
483
+ });
484
+ const payload = {
485
+ command: "daemon watchdog",
486
+ targetPath,
487
+ configPath: status.configPath,
488
+ statePath: status.statePath,
489
+ eventsPath: status.eventsPath,
490
+ runCount: status.runCount,
491
+ activeAlertCount: status.activeAlertCount,
492
+ activeAlerts: status.activeAlerts,
493
+ recentRuns: status.recentRuns,
494
+ config: status.config,
495
+ };
496
+ if (shouldEmitJson(options, command)) {
497
+ console.log(JSON.stringify(payload, null, 2));
498
+ return;
499
+ }
500
+ console.log(pc.bold("OMAR watchdog status"));
501
+ console.log(pc.gray(`Config: ${status.configPath}`));
502
+ console.log(pc.gray(`State: ${status.statePath}`));
503
+ console.log(pc.gray(`Events: ${status.eventsPath}`));
504
+ console.log(
505
+ pc.gray(
506
+ `active_alerts=${status.activeAlertCount} run_count=${status.runCount} channels=${status.config.channels.length}`
507
+ )
508
+ );
509
+ for (const alert of status.activeAlerts) {
510
+ console.log(
511
+ `- ${alert.alertId} | ${alert.eventType} | ${alert.agentIdentity || "unassigned"} | ${alert.message}`
512
+ );
513
+ }
514
+ });
515
+
516
+ watchdog
517
+ .command("run")
518
+ .description("Run one watchdog evaluation tick and optionally dispatch channel alerts")
519
+ .option("--path <path>", "Workspace path for artifact/config resolution", ".")
520
+ .option("--output-dir <path>", "Optional output dir override for daemon artifacts")
521
+ .option("--no-tool-call-seconds <n>", "Idle threshold for no tool calls", "60")
522
+ .option(
523
+ "--repeated-file-reads-threshold <n>",
524
+ "Consecutive repeated file-read threshold",
525
+ "3"
526
+ )
527
+ .option(
528
+ "--budget-warning-threshold <ratio>",
529
+ "Budget warning ratio threshold (0-1)",
530
+ "0.9"
531
+ )
532
+ .option("--turn-stall-turns <n>", "Turn-stall threshold", "5")
533
+ .option("--limit <n>", "Maximum records to inspect", "200")
534
+ .option("--execute <bool>", "Dispatch alerts to channels (true/false)", "false")
535
+ .option("--now-iso <timestamp>", "Optional deterministic timestamp override")
536
+ .option("--json", "Emit machine-readable output")
537
+ .action(async (options, command) => {
538
+ const targetPath = path.resolve(process.cwd(), String(options.path || "."));
539
+ const budgetThreshold = Number(options.budgetWarningThreshold || 0.9);
540
+ if (!Number.isFinite(budgetThreshold) || budgetThreshold < 0 || budgetThreshold > 1) {
541
+ throw new Error("budget-warning-threshold must be a number between 0 and 1.");
542
+ }
543
+ const executed = await runWatchdogTick({
544
+ targetPath,
545
+ outputDir: options.outputDir,
546
+ noToolCallSeconds: parsePositiveInteger(
547
+ options.noToolCallSeconds,
548
+ "no-tool-call-seconds",
549
+ 60
550
+ ),
551
+ repeatedFileReadsThreshold: parsePositiveInteger(
552
+ options.repeatedFileReadsThreshold,
553
+ "repeated-file-reads-threshold",
554
+ 3
555
+ ),
556
+ budgetWarningThreshold: budgetThreshold,
557
+ turnStallTurns: parsePositiveInteger(options.turnStallTurns, "turn-stall-turns", 5),
558
+ limit: parsePositiveInteger(options.limit, "limit", 200),
559
+ execute: parseBoolean(options.execute, false),
560
+ nowIso: options.nowIso,
561
+ });
562
+ const payload = {
563
+ command: "daemon watchdog run",
564
+ targetPath,
565
+ runId: executed.runId,
566
+ runPath: executed.runPath,
567
+ configPath: executed.configPath,
568
+ statePath: executed.statePath,
569
+ eventsPath: executed.eventsPath,
570
+ configExists: executed.configExists,
571
+ summary: executed.summary,
572
+ detections: executed.detections,
573
+ activatedAlerts: executed.activatedAlerts,
574
+ recoveredAlerts: executed.recoveredAlerts,
575
+ notifications: executed.notifications,
576
+ };
577
+ if (shouldEmitJson(options, command)) {
578
+ console.log(JSON.stringify(payload, null, 2));
579
+ return;
580
+ }
581
+ console.log(pc.bold("OMAR watchdog tick complete"));
582
+ console.log(pc.gray(`Run: ${executed.runId}`));
583
+ console.log(pc.gray(`Artifact: ${executed.runPath}`));
584
+ console.log(
585
+ `detections=${executed.summary.detectionCount} activated=${executed.summary.activatedCount} recovered=${executed.summary.recoveredCount} notifications=${executed.summary.notificationCount}`
586
+ );
587
+ for (const alert of executed.activatedAlerts) {
588
+ console.log(`- activated ${alert.alertId} | ${alert.eventType} | ${alert.message}`);
589
+ }
590
+ for (const alert of executed.recoveredAlerts) {
591
+ console.log(`- recovered ${alert.alertId} | ${alert.message}`);
592
+ }
593
+ });
594
+
595
+ watchdog
596
+ .command("status")
597
+ .description("Show watchdog state and recent run summaries")
598
+ .option("--path <path>", "Workspace path for artifact/config resolution", ".")
599
+ .option("--output-dir <path>", "Optional output dir override for daemon artifacts")
600
+ .option("--limit <n>", "Maximum recent runs to return", "10")
601
+ .option("--json", "Emit machine-readable output")
602
+ .action(async (options, command) => {
603
+ const targetPath = path.resolve(process.cwd(), String(options.path || "."));
604
+ const status = await getWatchdogStatus({
605
+ targetPath,
606
+ outputDir: options.outputDir,
607
+ limit: parsePositiveInteger(options.limit, "limit", 10),
608
+ });
609
+ const payload = {
610
+ command: "daemon watchdog status",
611
+ targetPath,
612
+ configPath: status.configPath,
613
+ statePath: status.statePath,
614
+ eventsPath: status.eventsPath,
615
+ runCount: status.runCount,
616
+ activeAlertCount: status.activeAlertCount,
617
+ activeAlerts: status.activeAlerts,
618
+ recentRuns: status.recentRuns,
619
+ config: status.config,
620
+ };
621
+ if (shouldEmitJson(options, command)) {
622
+ console.log(JSON.stringify(payload, null, 2));
623
+ return;
624
+ }
625
+ console.log(pc.bold("OMAR watchdog status"));
626
+ console.log(pc.gray(`Config: ${status.configPath}`));
627
+ console.log(pc.gray(`State: ${status.statePath}`));
628
+ console.log(pc.gray(`Events: ${status.eventsPath}`));
629
+ console.log(
630
+ pc.gray(
631
+ `active_alerts=${status.activeAlertCount} run_count=${status.runCount} recent_runs=${status.recentRuns.length}`
632
+ )
633
+ );
634
+ for (const run of status.recentRuns) {
635
+ console.log(
636
+ `- ${run.runId} | detections=${run.detectionCount} | activated=${run.activatedCount} | recovered=${run.recoveredCount}`
637
+ );
638
+ }
639
+ });
640
+
641
+ reliability
642
+ .option("--path <path>", "Workspace path for artifact/config resolution", ".")
643
+ .option("--output-dir <path>", "Optional output dir override for daemon artifacts")
644
+ .option("--limit <n>", "Maximum recent runs to return", "10")
645
+ .option("--json", "Emit machine-readable output")
646
+ .action(async (options, command) => {
647
+ const targetPath = path.resolve(process.cwd(), String(options.path || "."));
648
+ const status = await getReliabilityLaneStatus({
649
+ targetPath,
650
+ outputDir: options.outputDir,
651
+ limit: parsePositiveInteger(options.limit, "limit", 10),
652
+ });
653
+ const payload = {
654
+ command: "daemon reliability",
655
+ targetPath,
656
+ configPath: status.configPath,
657
+ billboardPath: status.billboardPath,
658
+ eventsPath: status.eventsPath,
659
+ config: status.config,
660
+ billboard: status.billboard,
661
+ runCount: status.runCount,
662
+ recentRuns: status.recentRuns,
663
+ };
664
+ if (shouldEmitJson(options, command)) {
665
+ console.log(JSON.stringify(payload, null, 2));
666
+ return;
667
+ }
668
+ printReliabilitySummary(payload);
669
+ });
670
+
671
+ reliability
672
+ .command("run")
673
+ .description("Run one synthetic midnight reliability lane tick")
674
+ .option("--path <path>", "Workspace path for artifact/config resolution", ".")
675
+ .option("--output-dir <path>", "Optional output dir override for daemon artifacts")
676
+ .option("--region <region>", "Target AWS region identifier", "us-east-1")
677
+ .option("--timezone <timezone>", "Timezone label for run metadata", "UTC")
678
+ .option(
679
+ "--simulate-failure <csv>",
680
+ `Simulate check failures (${RELIABILITY_CHECK_IDS.join(", ")})`
681
+ )
682
+ .option("--checks <csv>", "Optional subset of checks to run")
683
+ .option(
684
+ "--maintenance-auto-open <bool>",
685
+ "Automatically enable maintenance billboard on lane failures (true/false)",
686
+ "true"
687
+ )
688
+ .option(
689
+ "--clear-maintenance-on-pass <bool>",
690
+ "Clear reliability-lane maintenance billboard on passing run (true/false)",
691
+ "true"
692
+ )
693
+ .option("--now-iso <timestamp>", "Optional deterministic timestamp override")
694
+ .option("--json", "Emit machine-readable output")
695
+ .action(async (options, command) => {
696
+ const targetPath = path.resolve(process.cwd(), String(options.path || "."));
697
+ const executed = await runReliabilityLane({
698
+ targetPath,
699
+ outputDir: options.outputDir,
700
+ region: options.region,
701
+ timezone: options.timezone,
702
+ simulateFailures: parseCsv(options.simulateFailure),
703
+ checks: parseCsv(options.checks),
704
+ autoOpenMaintenance: parseBoolean(options.maintenanceAutoOpen, true),
705
+ clearMaintenanceOnPass: parseBoolean(options.clearMaintenanceOnPass, true),
706
+ nowIso: options.nowIso,
707
+ });
708
+ const payload = {
709
+ command: "daemon reliability run",
710
+ targetPath,
711
+ runId: executed.runId,
712
+ runPath: executed.runPath,
713
+ configPath: executed.configPath,
714
+ billboardPath: executed.billboardPath,
715
+ eventsPath: executed.eventsPath,
716
+ overallStatus: executed.overallStatus,
717
+ checkCount: executed.checkCount,
718
+ failureCount: executed.failureCount,
719
+ checks: executed.checks,
720
+ maintenance: executed.maintenance,
721
+ worker: executed.worker,
722
+ };
723
+ if (shouldEmitJson(options, command)) {
724
+ console.log(JSON.stringify(payload, null, 2));
725
+ return;
726
+ }
727
+ console.log(pc.bold("Reliability lane run complete"));
728
+ console.log(
729
+ `${executed.runId} status=${executed.overallStatus} failures=${executed.failureCount} maintenance=${executed.maintenance.enabled ? "ON" : "OFF"}`
730
+ );
731
+ console.log(pc.gray(`Run artifact: ${executed.runPath}`));
732
+ });
733
+
734
+ reliability
735
+ .command("status")
736
+ .description("Show reliability lane status, config, billboard, and recent runs")
737
+ .option("--path <path>", "Workspace path for artifact/config resolution", ".")
738
+ .option("--output-dir <path>", "Optional output dir override for daemon artifacts")
739
+ .option("--limit <n>", "Maximum recent runs to return", "10")
740
+ .option("--json", "Emit machine-readable output")
741
+ .action(async (options, command) => {
742
+ const targetPath = path.resolve(process.cwd(), String(options.path || "."));
743
+ const status = await getReliabilityLaneStatus({
744
+ targetPath,
745
+ outputDir: options.outputDir,
746
+ limit: parsePositiveInteger(options.limit, "limit", 10),
747
+ });
748
+ const payload = {
749
+ command: "daemon reliability status",
750
+ targetPath,
751
+ configPath: status.configPath,
752
+ billboardPath: status.billboardPath,
753
+ eventsPath: status.eventsPath,
754
+ config: status.config,
755
+ billboard: status.billboard,
756
+ runCount: status.runCount,
757
+ recentRuns: status.recentRuns,
758
+ };
759
+ if (shouldEmitJson(options, command)) {
760
+ console.log(JSON.stringify(payload, null, 2));
761
+ return;
762
+ }
763
+ printReliabilitySummary(payload);
764
+ });
765
+
766
+ const maintenance = daemon
767
+ .command("maintenance")
768
+ .description("Manual maintenance billboard controls for operator HITL visibility");
769
+
770
+ maintenance
771
+ .option("--path <path>", "Workspace path for artifact/config resolution", ".")
772
+ .option("--output-dir <path>", "Optional output dir override for daemon artifacts")
773
+ .option("--json", "Emit machine-readable output")
774
+ .action(async (options, command) => {
775
+ const targetPath = path.resolve(process.cwd(), String(options.path || "."));
776
+ const status = await getReliabilityLaneStatus({
777
+ targetPath,
778
+ outputDir: options.outputDir,
779
+ limit: 1,
780
+ });
781
+ const payload = {
782
+ command: "daemon maintenance",
783
+ targetPath,
784
+ billboardPath: status.billboardPath,
785
+ eventsPath: status.eventsPath,
786
+ billboard: status.billboard,
787
+ };
788
+ if (shouldEmitJson(options, command)) {
789
+ console.log(JSON.stringify(payload, null, 2));
790
+ return;
791
+ }
792
+ console.log(pc.bold("OMAR maintenance billboard"));
793
+ console.log(pc.gray(`Billboard: ${status.billboardPath}`));
794
+ console.log(
795
+ `enabled=${status.billboard.enabled ? "true" : "false"} source=${status.billboard.source || "n/a"} updated=${status.billboard.lastUpdatedAt || "n/a"}`
796
+ );
797
+ if (status.billboard.message) {
798
+ console.log(status.billboard.message);
799
+ }
800
+ });
801
+
802
+ maintenance
803
+ .command("status")
804
+ .description("Show current maintenance billboard state")
805
+ .option("--path <path>", "Workspace path for artifact/config resolution", ".")
806
+ .option("--output-dir <path>", "Optional output dir override for daemon artifacts")
807
+ .option("--json", "Emit machine-readable output")
808
+ .action(async (options, command) => {
809
+ const targetPath = path.resolve(process.cwd(), String(options.path || "."));
810
+ const status = await getReliabilityLaneStatus({
811
+ targetPath,
812
+ outputDir: options.outputDir,
813
+ limit: 1,
814
+ });
815
+ const payload = {
816
+ command: "daemon maintenance status",
817
+ targetPath,
818
+ billboardPath: status.billboardPath,
819
+ eventsPath: status.eventsPath,
820
+ billboard: status.billboard,
821
+ };
822
+ if (shouldEmitJson(options, command)) {
823
+ console.log(JSON.stringify(payload, null, 2));
824
+ return;
825
+ }
826
+ console.log(pc.bold("OMAR maintenance billboard"));
827
+ console.log(pc.gray(`Billboard: ${status.billboardPath}`));
828
+ console.log(
829
+ `enabled=${status.billboard.enabled ? "true" : "false"} source=${status.billboard.source || "n/a"} updated=${status.billboard.lastUpdatedAt || "n/a"}`
830
+ );
831
+ if (status.billboard.message) {
832
+ console.log(status.billboard.message);
833
+ }
834
+ });
835
+
836
+ maintenance
837
+ .command("on")
838
+ .description("Enable maintenance billboard manually")
839
+ .option("--path <path>", "Workspace path for artifact/config resolution", ".")
840
+ .option("--output-dir <path>", "Optional output dir override for daemon artifacts")
841
+ .option("--reason <text>", "Reason for maintenance mode", "Manual maintenance window")
842
+ .option("--message <text>", "Billboard message")
843
+ .option("--actor <identity>", "Operator identity", "omar-operator")
844
+ .option("--json", "Emit machine-readable output")
845
+ .action(async (options, command) => {
846
+ const targetPath = path.resolve(process.cwd(), String(options.path || "."));
847
+ const updated = await setMaintenanceBillboard({
848
+ targetPath,
849
+ outputDir: options.outputDir,
850
+ enabled: true,
851
+ source: "manual",
852
+ actor: options.actor,
853
+ reason: options.reason,
854
+ message:
855
+ options.message ||
856
+ "Maintenance mode is active while reliability lane findings are being remediated.",
857
+ });
858
+ const payload = {
859
+ command: "daemon maintenance on",
860
+ targetPath,
861
+ billboardPath: updated.billboardPath,
862
+ eventsPath: updated.eventsPath,
863
+ billboard: updated.billboard,
864
+ };
865
+ if (shouldEmitJson(options, command)) {
866
+ console.log(JSON.stringify(payload, null, 2));
867
+ return;
868
+ }
869
+ console.log(pc.bold("Maintenance billboard enabled"));
870
+ console.log(pc.gray(`Billboard: ${updated.billboardPath}`));
871
+ });
872
+
873
+ maintenance
874
+ .command("off")
875
+ .description("Disable maintenance billboard manually")
876
+ .option("--path <path>", "Workspace path for artifact/config resolution", ".")
877
+ .option("--output-dir <path>", "Optional output dir override for daemon artifacts")
878
+ .option("--reason <text>", "Reason for leaving maintenance mode", "Maintenance complete")
879
+ .option("--message <text>", "Optional final message to persist")
880
+ .option("--actor <identity>", "Operator identity", "omar-operator")
881
+ .option("--json", "Emit machine-readable output")
882
+ .action(async (options, command) => {
883
+ const targetPath = path.resolve(process.cwd(), String(options.path || "."));
884
+ const updated = await setMaintenanceBillboard({
885
+ targetPath,
886
+ outputDir: options.outputDir,
887
+ enabled: false,
888
+ source: "manual",
889
+ actor: options.actor,
890
+ reason: options.reason,
891
+ message: options.message || "",
892
+ });
893
+ const payload = {
894
+ command: "daemon maintenance off",
895
+ targetPath,
896
+ billboardPath: updated.billboardPath,
897
+ eventsPath: updated.eventsPath,
898
+ billboard: updated.billboard,
899
+ };
900
+ if (shouldEmitJson(options, command)) {
901
+ console.log(JSON.stringify(payload, null, 2));
902
+ return;
903
+ }
904
+ console.log(pc.bold("Maintenance billboard disabled"));
905
+ console.log(pc.gray(`Billboard: ${updated.billboardPath}`));
906
+ });
907
+
908
+ const error = daemon
909
+ .command("error")
910
+ .description("Record, route, and inspect admin error events for OMAR daemon processing");
911
+
912
+ error
913
+ .command("record")
914
+ .description("Record one admin error event into daemon intake stream")
915
+ .option("--path <path>", "Workspace path for artifact/config resolution", ".")
916
+ .option("--output-dir <path>", "Optional output dir override for daemon artifacts")
917
+ .option("--source <source>", "Error source label", "admin_error_log")
918
+ .option("--service <service>", "Service identifier", "sentinelayer-api")
919
+ .option("--endpoint <endpoint>", "Endpoint or route", "unknown-endpoint")
920
+ .option("--error-code <code>", "Error code", "UNKNOWN_ERROR")
921
+ .option("--severity <severity>", "Severity (P0/P1/P2/P3)", "P2")
922
+ .option("--message <message>", "Error summary message", "Unhandled runtime error")
923
+ .option("--stack <stack>", "Optional stack trace text")
924
+ .option("--commit-sha <sha>", "Optional commit sha")
925
+ .option("--metadata-json <json>", "Optional metadata object as JSON string")
926
+ .option("--json", "Emit machine-readable output")
927
+ .action(async (options, command) => {
928
+ const targetPath = path.resolve(process.cwd(), String(options.path || "."));
929
+ const recorded = await appendAdminErrorEvent({
930
+ targetPath,
931
+ outputDir: options.outputDir,
932
+ event: {
933
+ source: options.source,
934
+ service: options.service,
935
+ endpoint: options.endpoint,
936
+ errorCode: options.errorCode,
937
+ severity: options.severity,
938
+ message: options.message,
939
+ stackTrace: options.stack,
940
+ commitSha: options.commitSha,
941
+ metadata: parseMetadata(options.metadataJson),
942
+ },
943
+ });
944
+ const payload = {
945
+ command: "daemon error record",
946
+ targetPath,
947
+ streamPath: recorded.streamPath,
948
+ intakePath: recorded.intakePath,
949
+ event: recorded.event,
950
+ };
951
+ if (shouldEmitJson(options, command)) {
952
+ console.log(JSON.stringify(payload, null, 2));
953
+ return;
954
+ }
955
+
956
+ console.log(pc.bold("OMAR daemon error event recorded"));
957
+ console.log(pc.gray(`Stream: ${recorded.streamPath}`));
958
+ console.log(pc.gray(`Intake artifact: ${recorded.intakePath}`));
959
+ console.log(
960
+ `event=${recorded.event.eventId} severity=${recorded.event.severity} fingerprint=${recorded.event.fingerprint}`
961
+ );
962
+ });
963
+
964
+ error
965
+ .command("worker")
966
+ .description("Run one daemon worker tick over queued admin error stream events")
967
+ .option("--path <path>", "Workspace path for artifact/config resolution", ".")
968
+ .option("--output-dir <path>", "Optional output dir override for daemon artifacts")
969
+ .option("--max-events <n>", "Maximum stream events to process this tick", "200")
970
+ .option("--json", "Emit machine-readable output")
971
+ .action(async (options, command) => {
972
+ const targetPath = path.resolve(process.cwd(), String(options.path || "."));
973
+ const execution = await runErrorDaemonWorker({
974
+ targetPath,
975
+ outputDir: options.outputDir,
976
+ maxEvents: parsePositiveInteger(options.maxEvents, "max-events", 200),
977
+ });
978
+ const payload = {
979
+ command: "daemon error worker",
980
+ targetPath,
981
+ runId: execution.runId,
982
+ runPath: execution.runPath,
983
+ streamPath: execution.streamPath,
984
+ queuePath: execution.queuePath,
985
+ statePath: execution.statePath,
986
+ maxEvents: execution.maxEvents,
987
+ startOffset: execution.startOffset,
988
+ endOffset: execution.endOffset,
989
+ streamLength: execution.streamLength,
990
+ processedCount: execution.processedCount,
991
+ queuedCount: execution.queuedCount,
992
+ dedupedCount: execution.dedupedCount,
993
+ parseErrorCount: execution.parseErrorCount,
994
+ queueDepth: execution.queueDepth,
995
+ workerState: execution.state,
996
+ };
997
+
998
+ if (shouldEmitJson(options, command)) {
999
+ console.log(JSON.stringify(payload, null, 2));
1000
+ return;
1001
+ }
1002
+
1003
+ console.log(pc.bold("OMAR daemon worker tick completed"));
1004
+ console.log(pc.gray(`Run artifact: ${execution.runPath}`));
1005
+ console.log(
1006
+ `processed=${execution.processedCount} queued=${execution.queuedCount} deduped=${execution.dedupedCount} queue_depth=${execution.queueDepth}`
1007
+ );
1008
+ });
1009
+
1010
+ error
1011
+ .command("queue")
1012
+ .description("Inspect routed daemon queue items")
1013
+ .option("--path <path>", "Workspace path for artifact/config resolution", ".")
1014
+ .option("--output-dir <path>", "Optional output dir override for daemon artifacts")
1015
+ .option(
1016
+ "--status <csv>",
1017
+ `Optional queue status filter (${WORK_ITEM_STATUSES.join(", ")})`
1018
+ )
1019
+ .option("--limit <n>", "Maximum queue items to return", "50")
1020
+ .option("--json", "Emit machine-readable output")
1021
+ .action(async (options, command) => {
1022
+ const targetPath = path.resolve(process.cwd(), String(options.path || "."));
1023
+ const statuses = parseCsv(options.status);
1024
+ const listed = await listErrorQueue({
1025
+ targetPath,
1026
+ outputDir: options.outputDir,
1027
+ statuses,
1028
+ limit: parsePositiveInteger(options.limit, "limit", 50),
1029
+ });
1030
+ const payload = {
1031
+ command: "daemon error queue",
1032
+ targetPath,
1033
+ statuses,
1034
+ queuePath: listed.queuePath,
1035
+ statePath: listed.statePath,
1036
+ streamPath: listed.streamPath,
1037
+ totalCount: listed.totalCount,
1038
+ visibleCount: listed.items.length,
1039
+ items: listed.items,
1040
+ workerState: listed.state,
1041
+ };
1042
+ if (shouldEmitJson(options, command)) {
1043
+ console.log(JSON.stringify(payload, null, 2));
1044
+ return;
1045
+ }
1046
+ printQueueSummary(payload);
1047
+ });
1048
+ }