sentinelayer-cli 0.6.2 → 0.8.1

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 (280) hide show
  1. package/README.md +1009 -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 +64 -63
  6. package/src/agents/ai-governance/index.js +12 -0
  7. package/src/agents/ai-governance/tools/base.js +171 -0
  8. package/src/agents/ai-governance/tools/eval-regression.js +47 -0
  9. package/src/agents/ai-governance/tools/hitl-audit.js +81 -0
  10. package/src/agents/ai-governance/tools/index.js +52 -0
  11. package/src/agents/ai-governance/tools/prompt-drift.js +42 -0
  12. package/src/agents/ai-governance/tools/provenance-check.js +69 -0
  13. package/src/agents/backend/index.js +12 -0
  14. package/src/agents/backend/tools/base.js +189 -0
  15. package/src/agents/backend/tools/circuit-breaker-check.js +123 -0
  16. package/src/agents/backend/tools/idempotency-audit.js +105 -0
  17. package/src/agents/backend/tools/index.js +87 -0
  18. package/src/agents/backend/tools/retry-audit.js +132 -0
  19. package/src/agents/backend/tools/timeout-audit.js +144 -0
  20. package/src/agents/code-quality/index.js +12 -0
  21. package/src/agents/code-quality/tools/base.js +159 -0
  22. package/src/agents/code-quality/tools/complexity-measure.js +197 -0
  23. package/src/agents/code-quality/tools/coupling-analysis.js +81 -0
  24. package/src/agents/code-quality/tools/cycle-detect.js +49 -0
  25. package/src/agents/code-quality/tools/dep-graph.js +196 -0
  26. package/src/agents/code-quality/tools/index.js +89 -0
  27. package/src/agents/data-layer/index.js +12 -0
  28. package/src/agents/data-layer/tools/base.js +181 -0
  29. package/src/agents/data-layer/tools/index-audit.js +165 -0
  30. package/src/agents/data-layer/tools/index.js +83 -0
  31. package/src/agents/data-layer/tools/migration-scan.js +135 -0
  32. package/src/agents/data-layer/tools/query-explain.js +120 -0
  33. package/src/agents/data-layer/tools/tenancy-scan.js +166 -0
  34. package/src/agents/documentation/index.js +12 -0
  35. package/src/agents/documentation/tools/api-diff.js +91 -0
  36. package/src/agents/documentation/tools/base.js +151 -0
  37. package/src/agents/documentation/tools/dead-link-check.js +58 -0
  38. package/src/agents/documentation/tools/docstring-coverage.js +78 -0
  39. package/src/agents/documentation/tools/index.js +52 -0
  40. package/src/agents/documentation/tools/readme-freshness.js +61 -0
  41. package/src/agents/envelope/fix-cycle.js +45 -0
  42. package/src/agents/envelope/index.js +31 -0
  43. package/src/agents/envelope/loop.js +150 -0
  44. package/src/agents/envelope/pulse.js +18 -0
  45. package/src/agents/envelope/stream.js +40 -0
  46. package/src/agents/infrastructure/index.js +12 -0
  47. package/src/agents/infrastructure/tools/base.js +171 -0
  48. package/src/agents/infrastructure/tools/checkov-run.js +32 -0
  49. package/src/agents/infrastructure/tools/drift-detect.js +59 -0
  50. package/src/agents/infrastructure/tools/iam-least-priv-check.js +78 -0
  51. package/src/agents/infrastructure/tools/index.js +52 -0
  52. package/src/agents/infrastructure/tools/tflint-run.js +31 -0
  53. package/src/agents/jules/config/definition.js +160 -160
  54. package/src/agents/jules/config/system-prompt.js +182 -182
  55. package/src/agents/jules/error-intake.js +51 -51
  56. package/src/agents/jules/fix-cycle.js +17 -17
  57. package/src/agents/jules/loop.js +460 -450
  58. package/src/agents/jules/pulse.js +10 -10
  59. package/src/agents/jules/stream.js +187 -186
  60. package/src/agents/jules/swarm/file-scanner.js +74 -74
  61. package/src/agents/jules/swarm/index.js +11 -11
  62. package/src/agents/jules/swarm/orchestrator.js +362 -362
  63. package/src/agents/jules/swarm/pattern-hunter.js +123 -123
  64. package/src/agents/jules/swarm/sub-agent.js +315 -309
  65. package/src/agents/jules/tools/aidenid-email.js +189 -189
  66. package/src/agents/jules/tools/auth-audit.js +1708 -1691
  67. package/src/agents/jules/tools/dispatch.js +340 -335
  68. package/src/agents/jules/tools/file-edit.js +2 -2
  69. package/src/agents/jules/tools/file-read.js +2 -2
  70. package/src/agents/jules/tools/frontend-analyze.js +570 -570
  71. package/src/agents/jules/tools/glob.js +2 -2
  72. package/src/agents/jules/tools/grep.js +2 -2
  73. package/src/agents/jules/tools/index.js +29 -29
  74. package/src/agents/jules/tools/path-guards.js +2 -2
  75. package/src/agents/jules/tools/runtime-audit.js +507 -507
  76. package/src/agents/jules/tools/shell.js +2 -2
  77. package/src/agents/jules/tools/url-policy.js +100 -100
  78. package/src/agents/mode.js +113 -0
  79. package/src/agents/observability/index.js +12 -0
  80. package/src/agents/observability/tools/alert-audit.js +39 -0
  81. package/src/agents/observability/tools/base.js +181 -0
  82. package/src/agents/observability/tools/dashboard-gap.js +42 -0
  83. package/src/agents/observability/tools/index.js +54 -0
  84. package/src/agents/observability/tools/log-schema-check.js +74 -0
  85. package/src/agents/observability/tools/span-coverage.js +74 -0
  86. package/src/agents/persona-visuals.js +102 -61
  87. package/src/agents/release/index.js +12 -0
  88. package/src/agents/release/tools/base.js +181 -0
  89. package/src/agents/release/tools/changelog-diff.js +86 -0
  90. package/src/agents/release/tools/feature-flag-audit.js +126 -0
  91. package/src/agents/release/tools/index.js +61 -0
  92. package/src/agents/release/tools/rollback-verify.js +129 -0
  93. package/src/agents/release/tools/semver-check.js +109 -0
  94. package/src/agents/reliability/index.js +12 -0
  95. package/src/agents/reliability/tools/backpressure-check.js +129 -0
  96. package/src/agents/reliability/tools/base.js +181 -0
  97. package/src/agents/reliability/tools/chaos-probe.js +109 -0
  98. package/src/agents/reliability/tools/graceful-degradation-check.js +114 -0
  99. package/src/agents/reliability/tools/health-check-audit.js +111 -0
  100. package/src/agents/reliability/tools/index.js +87 -0
  101. package/src/agents/run-persona.js +109 -0
  102. package/src/agents/security/index.js +12 -0
  103. package/src/agents/security/tools/authz-audit.js +134 -0
  104. package/src/agents/security/tools/base.js +190 -0
  105. package/src/agents/security/tools/crypto-review.js +175 -0
  106. package/src/agents/security/tools/index.js +97 -0
  107. package/src/agents/security/tools/sast-scan.js +175 -0
  108. package/src/agents/security/tools/secrets-scan.js +216 -0
  109. package/src/agents/shared-tools/dispatch-core.js +320 -315
  110. package/src/agents/shared-tools/file-edit.js +180 -180
  111. package/src/agents/shared-tools/file-read.js +100 -100
  112. package/src/agents/shared-tools/glob.js +168 -168
  113. package/src/agents/shared-tools/grep.js +228 -228
  114. package/src/agents/shared-tools/index.js +46 -46
  115. package/src/agents/shared-tools/path-guards.js +161 -161
  116. package/src/agents/shared-tools/shell.js +383 -383
  117. package/src/agents/supply-chain/index.js +12 -0
  118. package/src/agents/supply-chain/tools/attestation-check.js +42 -0
  119. package/src/agents/supply-chain/tools/base.js +151 -0
  120. package/src/agents/supply-chain/tools/index.js +52 -0
  121. package/src/agents/supply-chain/tools/lockfile-integrity.js +73 -0
  122. package/src/agents/supply-chain/tools/package-verify.js +56 -0
  123. package/src/agents/supply-chain/tools/sbom-diff.js +34 -0
  124. package/src/agents/testing/index.js +12 -0
  125. package/src/agents/testing/tools/base.js +202 -0
  126. package/src/agents/testing/tools/coverage-gap.js +144 -0
  127. package/src/agents/testing/tools/flake-detect.js +125 -0
  128. package/src/agents/testing/tools/index.js +85 -0
  129. package/src/agents/testing/tools/mutation-test.js +143 -0
  130. package/src/agents/testing/tools/snapshot-diff.js +103 -0
  131. package/src/ai/aidenid.js +1021 -1009
  132. package/src/ai/client.js +553 -553
  133. package/src/ai/domain-target-store.js +268 -268
  134. package/src/ai/identity-store.js +270 -270
  135. package/src/ai/proxy.js +137 -137
  136. package/src/ai/site-store.js +145 -145
  137. package/src/audit/agents/architecture.js +180 -180
  138. package/src/audit/agents/compliance.js +179 -179
  139. package/src/audit/agents/documentation.js +165 -165
  140. package/src/audit/agents/performance.js +145 -145
  141. package/src/audit/agents/security.js +215 -215
  142. package/src/audit/agents/testing.js +172 -172
  143. package/src/audit/orchestrator.js +557 -557
  144. package/src/audit/package.js +204 -204
  145. package/src/audit/registry.js +284 -284
  146. package/src/audit/replay.js +103 -103
  147. package/src/auth/gate.js +428 -371
  148. package/src/auth/http.js +681 -611
  149. package/src/auth/service.js +1106 -1106
  150. package/src/auth/session-store.js +813 -813
  151. package/src/cli.js +257 -252
  152. package/src/commands/ai/identity-lifecycle.js +1338 -1338
  153. package/src/commands/ai/provision-governance.js +1272 -1272
  154. package/src/commands/ai/shared.js +147 -147
  155. package/src/commands/ai.js +11 -11
  156. package/src/commands/apply.js +12 -12
  157. package/src/commands/audit.js +1171 -1166
  158. package/src/commands/auth.js +419 -419
  159. package/src/commands/chat.js +184 -191
  160. package/src/commands/config.js +184 -184
  161. package/src/commands/cost.js +311 -311
  162. package/src/commands/daemon/core.js +850 -850
  163. package/src/commands/daemon/extended.js +1048 -1048
  164. package/src/commands/daemon/shared.js +213 -213
  165. package/src/commands/daemon.js +11 -11
  166. package/src/commands/guide.js +174 -174
  167. package/src/commands/ingest.js +58 -58
  168. package/src/commands/init.js +55 -55
  169. package/src/commands/legacy-args.js +20 -10
  170. package/src/commands/mcp.js +461 -461
  171. package/src/commands/omargate.js +63 -29
  172. package/src/commands/persona.js +65 -20
  173. package/src/commands/plugin.js +260 -260
  174. package/src/commands/policy.js +132 -132
  175. package/src/commands/prompt.js +238 -238
  176. package/src/commands/review.js +704 -704
  177. package/src/commands/scan.js +865 -872
  178. package/src/commands/session.js +1238 -0
  179. package/src/commands/spec.js +771 -716
  180. package/src/commands/swarm.js +651 -651
  181. package/src/commands/telemetry.js +202 -202
  182. package/src/commands/watch.js +511 -511
  183. package/src/config/agent-dictionary.js +182 -182
  184. package/src/config/io.js +56 -56
  185. package/src/config/paths.js +18 -18
  186. package/src/config/schema.js +55 -55
  187. package/src/config/service.js +184 -184
  188. package/src/coord/events-log.js +141 -0
  189. package/src/coord/handshake.js +719 -0
  190. package/src/coord/index.js +35 -0
  191. package/src/coord/paths.js +84 -0
  192. package/src/coord/priority.js +62 -0
  193. package/src/coord/tarjan.js +157 -0
  194. package/src/cost/budget.js +235 -235
  195. package/src/cost/history.js +188 -188
  196. package/src/cost/tokenizer.js +160 -0
  197. package/src/cost/tracker.js +232 -171
  198. package/src/daemon/artifact-lineage.js +896 -534
  199. package/src/daemon/assignment-ledger.js +1083 -770
  200. package/src/daemon/ast-drift.js +496 -0
  201. package/src/daemon/ast-parser-layer.js +258 -258
  202. package/src/daemon/budget-governor.js +633 -633
  203. package/src/daemon/callgraph-overlay.js +646 -646
  204. package/src/daemon/error-worker.js +1209 -626
  205. package/src/daemon/fix-cycle.js +384 -377
  206. package/src/daemon/hybrid-mapper.js +929 -929
  207. package/src/daemon/ingest-refresh.js +79 -11
  208. package/src/daemon/jira-lifecycle.js +767 -632
  209. package/src/daemon/operator-control.js +657 -657
  210. package/src/daemon/pulse.js +327 -327
  211. package/src/daemon/reliability-lane.js +471 -471
  212. package/src/daemon/scope-engine.js +1068 -0
  213. package/src/daemon/watchdog.js +971 -971
  214. package/src/events/schema.js +190 -0
  215. package/src/guide/generator.js +316 -316
  216. package/src/ingest/engine.js +933 -918
  217. package/src/ingest/ownership.js +380 -0
  218. package/src/interactive/index.js +97 -97
  219. package/src/legacy-cli.js +3228 -2994
  220. package/src/mcp/registry.js +695 -695
  221. package/src/memory/blackboard.js +301 -301
  222. package/src/memory/retrieval.js +581 -581
  223. package/src/orchestrator/kai-chen.js +126 -0
  224. package/src/plugin/manifest.js +553 -553
  225. package/src/policy/packs.js +144 -144
  226. package/src/prompt/generator.js +136 -118
  227. package/src/review/ai-review.js +672 -679
  228. package/src/review/compliance-pack.js +389 -0
  229. package/src/review/investor-dd-config.js +54 -0
  230. package/src/review/investor-dd-file-loop.js +303 -0
  231. package/src/review/investor-dd-file-router.js +406 -0
  232. package/src/review/investor-dd-html-report.js +233 -0
  233. package/src/review/investor-dd-notification.js +120 -0
  234. package/src/review/investor-dd-orchestrator.js +405 -0
  235. package/src/review/investor-dd-persona-runner.js +275 -0
  236. package/src/review/live-validator.js +253 -0
  237. package/src/review/local-review.js +1351 -1305
  238. package/src/review/omargate-interactive.js +68 -68
  239. package/src/review/omargate-orchestrator.js +492 -300
  240. package/src/review/persona-prompts.js +484 -296
  241. package/src/review/reconciliation-rules.js +329 -0
  242. package/src/review/replay.js +235 -235
  243. package/src/review/report.js +664 -664
  244. package/src/review/reproducibility-chain.js +136 -0
  245. package/src/review/scan-modes.js +147 -42
  246. package/src/review/spec-binding.js +487 -487
  247. package/src/scaffold/generator.js +67 -67
  248. package/src/scaffold/templates.js +150 -150
  249. package/src/scan/generator.js +418 -418
  250. package/src/scan/gh-secrets.js +107 -107
  251. package/src/session/agent-registry.js +359 -0
  252. package/src/session/analytics.js +479 -0
  253. package/src/session/daemon.js +1396 -0
  254. package/src/session/file-locks.js +666 -0
  255. package/src/session/paths.js +37 -0
  256. package/src/session/recap.js +567 -0
  257. package/src/session/redact.js +82 -0
  258. package/src/session/runtime-bridge.js +762 -0
  259. package/src/session/scoring.js +406 -0
  260. package/src/session/setup-guides.js +304 -0
  261. package/src/session/store.js +704 -0
  262. package/src/session/stream.js +333 -0
  263. package/src/session/sync.js +753 -0
  264. package/src/session/tasks.js +1054 -0
  265. package/src/session/templates.js +188 -0
  266. package/src/spec/generator.js +619 -519
  267. package/src/spec/regenerate.js +237 -237
  268. package/src/spec/templates.js +91 -91
  269. package/src/swarm/dashboard.js +247 -247
  270. package/src/swarm/factory.js +363 -363
  271. package/src/swarm/pentest.js +934 -934
  272. package/src/swarm/registry.js +419 -419
  273. package/src/swarm/report.js +158 -158
  274. package/src/swarm/runtime.js +569 -576
  275. package/src/swarm/scenario-dsl.js +272 -272
  276. package/src/telemetry/ledger.js +302 -302
  277. package/src/telemetry/session-tracker.js +234 -234
  278. package/src/telemetry/sync.js +203 -203
  279. package/src/ui/command-hints.js +13 -13
  280. 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
+ }