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.
- package/README.md +1009 -996
- package/bin/create-sentinelayer.js +5 -5
- package/bin/sentinelayer-cli.js +4 -4
- package/bin/sl.js +5 -5
- package/package.json +64 -63
- package/src/agents/ai-governance/index.js +12 -0
- package/src/agents/ai-governance/tools/base.js +171 -0
- package/src/agents/ai-governance/tools/eval-regression.js +47 -0
- package/src/agents/ai-governance/tools/hitl-audit.js +81 -0
- package/src/agents/ai-governance/tools/index.js +52 -0
- package/src/agents/ai-governance/tools/prompt-drift.js +42 -0
- package/src/agents/ai-governance/tools/provenance-check.js +69 -0
- package/src/agents/backend/index.js +12 -0
- package/src/agents/backend/tools/base.js +189 -0
- package/src/agents/backend/tools/circuit-breaker-check.js +123 -0
- package/src/agents/backend/tools/idempotency-audit.js +105 -0
- package/src/agents/backend/tools/index.js +87 -0
- package/src/agents/backend/tools/retry-audit.js +132 -0
- package/src/agents/backend/tools/timeout-audit.js +144 -0
- package/src/agents/code-quality/index.js +12 -0
- package/src/agents/code-quality/tools/base.js +159 -0
- package/src/agents/code-quality/tools/complexity-measure.js +197 -0
- package/src/agents/code-quality/tools/coupling-analysis.js +81 -0
- package/src/agents/code-quality/tools/cycle-detect.js +49 -0
- package/src/agents/code-quality/tools/dep-graph.js +196 -0
- package/src/agents/code-quality/tools/index.js +89 -0
- package/src/agents/data-layer/index.js +12 -0
- package/src/agents/data-layer/tools/base.js +181 -0
- package/src/agents/data-layer/tools/index-audit.js +165 -0
- package/src/agents/data-layer/tools/index.js +83 -0
- package/src/agents/data-layer/tools/migration-scan.js +135 -0
- package/src/agents/data-layer/tools/query-explain.js +120 -0
- package/src/agents/data-layer/tools/tenancy-scan.js +166 -0
- package/src/agents/documentation/index.js +12 -0
- package/src/agents/documentation/tools/api-diff.js +91 -0
- package/src/agents/documentation/tools/base.js +151 -0
- package/src/agents/documentation/tools/dead-link-check.js +58 -0
- package/src/agents/documentation/tools/docstring-coverage.js +78 -0
- package/src/agents/documentation/tools/index.js +52 -0
- package/src/agents/documentation/tools/readme-freshness.js +61 -0
- package/src/agents/envelope/fix-cycle.js +45 -0
- package/src/agents/envelope/index.js +31 -0
- package/src/agents/envelope/loop.js +150 -0
- package/src/agents/envelope/pulse.js +18 -0
- package/src/agents/envelope/stream.js +40 -0
- package/src/agents/infrastructure/index.js +12 -0
- package/src/agents/infrastructure/tools/base.js +171 -0
- package/src/agents/infrastructure/tools/checkov-run.js +32 -0
- package/src/agents/infrastructure/tools/drift-detect.js +59 -0
- package/src/agents/infrastructure/tools/iam-least-priv-check.js +78 -0
- package/src/agents/infrastructure/tools/index.js +52 -0
- package/src/agents/infrastructure/tools/tflint-run.js +31 -0
- package/src/agents/jules/config/definition.js +160 -160
- package/src/agents/jules/config/system-prompt.js +182 -182
- package/src/agents/jules/error-intake.js +51 -51
- package/src/agents/jules/fix-cycle.js +17 -17
- package/src/agents/jules/loop.js +460 -450
- package/src/agents/jules/pulse.js +10 -10
- package/src/agents/jules/stream.js +187 -186
- package/src/agents/jules/swarm/file-scanner.js +74 -74
- package/src/agents/jules/swarm/index.js +11 -11
- package/src/agents/jules/swarm/orchestrator.js +362 -362
- package/src/agents/jules/swarm/pattern-hunter.js +123 -123
- package/src/agents/jules/swarm/sub-agent.js +315 -309
- package/src/agents/jules/tools/aidenid-email.js +189 -189
- package/src/agents/jules/tools/auth-audit.js +1708 -1691
- package/src/agents/jules/tools/dispatch.js +340 -335
- package/src/agents/jules/tools/file-edit.js +2 -2
- package/src/agents/jules/tools/file-read.js +2 -2
- package/src/agents/jules/tools/frontend-analyze.js +570 -570
- package/src/agents/jules/tools/glob.js +2 -2
- package/src/agents/jules/tools/grep.js +2 -2
- package/src/agents/jules/tools/index.js +29 -29
- package/src/agents/jules/tools/path-guards.js +2 -2
- package/src/agents/jules/tools/runtime-audit.js +507 -507
- package/src/agents/jules/tools/shell.js +2 -2
- package/src/agents/jules/tools/url-policy.js +100 -100
- package/src/agents/mode.js +113 -0
- package/src/agents/observability/index.js +12 -0
- package/src/agents/observability/tools/alert-audit.js +39 -0
- package/src/agents/observability/tools/base.js +181 -0
- package/src/agents/observability/tools/dashboard-gap.js +42 -0
- package/src/agents/observability/tools/index.js +54 -0
- package/src/agents/observability/tools/log-schema-check.js +74 -0
- package/src/agents/observability/tools/span-coverage.js +74 -0
- package/src/agents/persona-visuals.js +102 -61
- package/src/agents/release/index.js +12 -0
- package/src/agents/release/tools/base.js +181 -0
- package/src/agents/release/tools/changelog-diff.js +86 -0
- package/src/agents/release/tools/feature-flag-audit.js +126 -0
- package/src/agents/release/tools/index.js +61 -0
- package/src/agents/release/tools/rollback-verify.js +129 -0
- package/src/agents/release/tools/semver-check.js +109 -0
- package/src/agents/reliability/index.js +12 -0
- package/src/agents/reliability/tools/backpressure-check.js +129 -0
- package/src/agents/reliability/tools/base.js +181 -0
- package/src/agents/reliability/tools/chaos-probe.js +109 -0
- package/src/agents/reliability/tools/graceful-degradation-check.js +114 -0
- package/src/agents/reliability/tools/health-check-audit.js +111 -0
- package/src/agents/reliability/tools/index.js +87 -0
- package/src/agents/run-persona.js +109 -0
- package/src/agents/security/index.js +12 -0
- package/src/agents/security/tools/authz-audit.js +134 -0
- package/src/agents/security/tools/base.js +190 -0
- package/src/agents/security/tools/crypto-review.js +175 -0
- package/src/agents/security/tools/index.js +97 -0
- package/src/agents/security/tools/sast-scan.js +175 -0
- package/src/agents/security/tools/secrets-scan.js +216 -0
- package/src/agents/shared-tools/dispatch-core.js +320 -315
- package/src/agents/shared-tools/file-edit.js +180 -180
- package/src/agents/shared-tools/file-read.js +100 -100
- package/src/agents/shared-tools/glob.js +168 -168
- package/src/agents/shared-tools/grep.js +228 -228
- package/src/agents/shared-tools/index.js +46 -46
- package/src/agents/shared-tools/path-guards.js +161 -161
- package/src/agents/shared-tools/shell.js +383 -383
- package/src/agents/supply-chain/index.js +12 -0
- package/src/agents/supply-chain/tools/attestation-check.js +42 -0
- package/src/agents/supply-chain/tools/base.js +151 -0
- package/src/agents/supply-chain/tools/index.js +52 -0
- package/src/agents/supply-chain/tools/lockfile-integrity.js +73 -0
- package/src/agents/supply-chain/tools/package-verify.js +56 -0
- package/src/agents/supply-chain/tools/sbom-diff.js +34 -0
- package/src/agents/testing/index.js +12 -0
- package/src/agents/testing/tools/base.js +202 -0
- package/src/agents/testing/tools/coverage-gap.js +144 -0
- package/src/agents/testing/tools/flake-detect.js +125 -0
- package/src/agents/testing/tools/index.js +85 -0
- package/src/agents/testing/tools/mutation-test.js +143 -0
- package/src/agents/testing/tools/snapshot-diff.js +103 -0
- package/src/ai/aidenid.js +1021 -1009
- package/src/ai/client.js +553 -553
- package/src/ai/domain-target-store.js +268 -268
- package/src/ai/identity-store.js +270 -270
- package/src/ai/proxy.js +137 -137
- package/src/ai/site-store.js +145 -145
- package/src/audit/agents/architecture.js +180 -180
- package/src/audit/agents/compliance.js +179 -179
- package/src/audit/agents/documentation.js +165 -165
- package/src/audit/agents/performance.js +145 -145
- package/src/audit/agents/security.js +215 -215
- package/src/audit/agents/testing.js +172 -172
- package/src/audit/orchestrator.js +557 -557
- package/src/audit/package.js +204 -204
- package/src/audit/registry.js +284 -284
- package/src/audit/replay.js +103 -103
- package/src/auth/gate.js +428 -371
- package/src/auth/http.js +681 -611
- package/src/auth/service.js +1106 -1106
- package/src/auth/session-store.js +813 -813
- package/src/cli.js +257 -252
- package/src/commands/ai/identity-lifecycle.js +1338 -1338
- package/src/commands/ai/provision-governance.js +1272 -1272
- package/src/commands/ai/shared.js +147 -147
- package/src/commands/ai.js +11 -11
- package/src/commands/apply.js +12 -12
- package/src/commands/audit.js +1171 -1166
- package/src/commands/auth.js +419 -419
- package/src/commands/chat.js +184 -191
- package/src/commands/config.js +184 -184
- package/src/commands/cost.js +311 -311
- package/src/commands/daemon/core.js +850 -850
- package/src/commands/daemon/extended.js +1048 -1048
- package/src/commands/daemon/shared.js +213 -213
- package/src/commands/daemon.js +11 -11
- package/src/commands/guide.js +174 -174
- package/src/commands/ingest.js +58 -58
- package/src/commands/init.js +55 -55
- package/src/commands/legacy-args.js +20 -10
- package/src/commands/mcp.js +461 -461
- package/src/commands/omargate.js +63 -29
- package/src/commands/persona.js +65 -20
- package/src/commands/plugin.js +260 -260
- package/src/commands/policy.js +132 -132
- package/src/commands/prompt.js +238 -238
- package/src/commands/review.js +704 -704
- package/src/commands/scan.js +865 -872
- package/src/commands/session.js +1238 -0
- package/src/commands/spec.js +771 -716
- package/src/commands/swarm.js +651 -651
- package/src/commands/telemetry.js +202 -202
- package/src/commands/watch.js +511 -511
- package/src/config/agent-dictionary.js +182 -182
- package/src/config/io.js +56 -56
- package/src/config/paths.js +18 -18
- package/src/config/schema.js +55 -55
- package/src/config/service.js +184 -184
- package/src/coord/events-log.js +141 -0
- package/src/coord/handshake.js +719 -0
- package/src/coord/index.js +35 -0
- package/src/coord/paths.js +84 -0
- package/src/coord/priority.js +62 -0
- package/src/coord/tarjan.js +157 -0
- package/src/cost/budget.js +235 -235
- package/src/cost/history.js +188 -188
- package/src/cost/tokenizer.js +160 -0
- package/src/cost/tracker.js +232 -171
- package/src/daemon/artifact-lineage.js +896 -534
- package/src/daemon/assignment-ledger.js +1083 -770
- package/src/daemon/ast-drift.js +496 -0
- package/src/daemon/ast-parser-layer.js +258 -258
- package/src/daemon/budget-governor.js +633 -633
- package/src/daemon/callgraph-overlay.js +646 -646
- package/src/daemon/error-worker.js +1209 -626
- package/src/daemon/fix-cycle.js +384 -377
- package/src/daemon/hybrid-mapper.js +929 -929
- package/src/daemon/ingest-refresh.js +79 -11
- package/src/daemon/jira-lifecycle.js +767 -632
- package/src/daemon/operator-control.js +657 -657
- package/src/daemon/pulse.js +327 -327
- package/src/daemon/reliability-lane.js +471 -471
- package/src/daemon/scope-engine.js +1068 -0
- package/src/daemon/watchdog.js +971 -971
- package/src/events/schema.js +190 -0
- package/src/guide/generator.js +316 -316
- package/src/ingest/engine.js +933 -918
- package/src/ingest/ownership.js +380 -0
- package/src/interactive/index.js +97 -97
- package/src/legacy-cli.js +3228 -2994
- package/src/mcp/registry.js +695 -695
- package/src/memory/blackboard.js +301 -301
- package/src/memory/retrieval.js +581 -581
- package/src/orchestrator/kai-chen.js +126 -0
- package/src/plugin/manifest.js +553 -553
- package/src/policy/packs.js +144 -144
- package/src/prompt/generator.js +136 -118
- package/src/review/ai-review.js +672 -679
- package/src/review/compliance-pack.js +389 -0
- package/src/review/investor-dd-config.js +54 -0
- package/src/review/investor-dd-file-loop.js +303 -0
- package/src/review/investor-dd-file-router.js +406 -0
- package/src/review/investor-dd-html-report.js +233 -0
- package/src/review/investor-dd-notification.js +120 -0
- package/src/review/investor-dd-orchestrator.js +405 -0
- package/src/review/investor-dd-persona-runner.js +275 -0
- package/src/review/live-validator.js +253 -0
- package/src/review/local-review.js +1351 -1305
- package/src/review/omargate-interactive.js +68 -68
- package/src/review/omargate-orchestrator.js +492 -300
- package/src/review/persona-prompts.js +484 -296
- package/src/review/reconciliation-rules.js +329 -0
- package/src/review/replay.js +235 -235
- package/src/review/report.js +664 -664
- package/src/review/reproducibility-chain.js +136 -0
- package/src/review/scan-modes.js +147 -42
- package/src/review/spec-binding.js +487 -487
- package/src/scaffold/generator.js +67 -67
- package/src/scaffold/templates.js +150 -150
- package/src/scan/generator.js +418 -418
- package/src/scan/gh-secrets.js +107 -107
- package/src/session/agent-registry.js +359 -0
- package/src/session/analytics.js +479 -0
- package/src/session/daemon.js +1396 -0
- package/src/session/file-locks.js +666 -0
- package/src/session/paths.js +37 -0
- package/src/session/recap.js +567 -0
- package/src/session/redact.js +82 -0
- package/src/session/runtime-bridge.js +762 -0
- package/src/session/scoring.js +406 -0
- package/src/session/setup-guides.js +304 -0
- package/src/session/store.js +704 -0
- package/src/session/stream.js +333 -0
- package/src/session/sync.js +753 -0
- package/src/session/tasks.js +1054 -0
- package/src/session/templates.js +188 -0
- package/src/spec/generator.js +619 -519
- package/src/spec/regenerate.js +237 -237
- package/src/spec/templates.js +91 -91
- package/src/swarm/dashboard.js +247 -247
- package/src/swarm/factory.js +363 -363
- package/src/swarm/pentest.js +934 -934
- package/src/swarm/registry.js +419 -419
- package/src/swarm/report.js +158 -158
- package/src/swarm/runtime.js +569 -576
- package/src/swarm/scenario-dsl.js +272 -272
- package/src/telemetry/ledger.js +302 -302
- package/src/telemetry/session-tracker.js +234 -234
- package/src/telemetry/sync.js +203 -203
- package/src/ui/command-hints.js +13 -13
- package/src/ui/markdown.js +220 -220
|
@@ -1,632 +1,767 @@
|
|
|
1
|
-
import fsp from "node:fs/promises";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
return
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
.
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
const
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
const
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
}
|
|
270
|
-
const
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
);
|
|
370
|
-
|
|
371
|
-
const
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
const
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
const
|
|
602
|
-
const
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
1
|
+
import fsp from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
|
|
4
|
+
import { createAgentEvent } from "../events/schema.js";
|
|
5
|
+
import { appendToStream } from "../session/stream.js";
|
|
6
|
+
import { resolveAssignmentLedgerStorage } from "./assignment-ledger.js";
|
|
7
|
+
import { resolveErrorDaemonStorage } from "./error-worker.js";
|
|
8
|
+
|
|
9
|
+
const LIFECYCLE_SCHEMA_VERSION = "1.0.0";
|
|
10
|
+
const QUEUE_SCHEMA_VERSION = "1.0.0";
|
|
11
|
+
|
|
12
|
+
export const JIRA_STATUSES = Object.freeze([
|
|
13
|
+
"OPEN",
|
|
14
|
+
"IN_PROGRESS",
|
|
15
|
+
"BLOCKED",
|
|
16
|
+
"DONE",
|
|
17
|
+
"CANCELLED",
|
|
18
|
+
]);
|
|
19
|
+
|
|
20
|
+
const JIRA_STATUS_SET = new Set(JIRA_STATUSES);
|
|
21
|
+
const JIRA_LIFECYCLE_PHASES = new Set([
|
|
22
|
+
"create",
|
|
23
|
+
"plan_comment",
|
|
24
|
+
"in_progress",
|
|
25
|
+
"checkpoint",
|
|
26
|
+
"blocked",
|
|
27
|
+
"resolved",
|
|
28
|
+
]);
|
|
29
|
+
|
|
30
|
+
function normalizeString(value) {
|
|
31
|
+
return String(value || "").trim();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function normalizeIsoTimestamp(value, fallbackIso = new Date().toISOString()) {
|
|
35
|
+
const normalized = normalizeString(value);
|
|
36
|
+
if (!normalized) {
|
|
37
|
+
return fallbackIso;
|
|
38
|
+
}
|
|
39
|
+
const epoch = Date.parse(normalized);
|
|
40
|
+
if (!Number.isFinite(epoch)) {
|
|
41
|
+
return fallbackIso;
|
|
42
|
+
}
|
|
43
|
+
return new Date(epoch).toISOString();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function normalizeStatus(value, fallbackValue = "OPEN") {
|
|
47
|
+
const normalized = normalizeString(value).toUpperCase();
|
|
48
|
+
if (JIRA_STATUS_SET.has(normalized)) {
|
|
49
|
+
return normalized;
|
|
50
|
+
}
|
|
51
|
+
return fallbackValue;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function normalizeJiraLifecyclePhase(value) {
|
|
55
|
+
const normalized = normalizeString(value).toLowerCase();
|
|
56
|
+
if (!JIRA_LIFECYCLE_PHASES.has(normalized)) {
|
|
57
|
+
throw new Error(`phase must be one of: ${[...JIRA_LIFECYCLE_PHASES].join(", ")}.`);
|
|
58
|
+
}
|
|
59
|
+
return normalized;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function resolveTransitionPhase(status) {
|
|
63
|
+
const normalized = normalizeStatus(status, "OPEN");
|
|
64
|
+
if (normalized === "IN_PROGRESS") return "in_progress";
|
|
65
|
+
if (normalized === "BLOCKED") return "blocked";
|
|
66
|
+
if (normalized === "DONE" || normalized === "CANCELLED") return "resolved";
|
|
67
|
+
return "checkpoint";
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function normalizeLabels(labels = []) {
|
|
71
|
+
if (!Array.isArray(labels)) {
|
|
72
|
+
return [];
|
|
73
|
+
}
|
|
74
|
+
const deduped = new Set();
|
|
75
|
+
for (const label of labels) {
|
|
76
|
+
const normalized = normalizeString(label);
|
|
77
|
+
if (normalized) {
|
|
78
|
+
deduped.add(normalized);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return [...deduped];
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function normalizeComment(comment = {}, nowIso = new Date().toISOString()) {
|
|
85
|
+
return {
|
|
86
|
+
at: normalizeIsoTimestamp(comment.at, nowIso),
|
|
87
|
+
actor: normalizeString(comment.actor) || "omar-daemon",
|
|
88
|
+
type: normalizeString(comment.type) || "note",
|
|
89
|
+
message: normalizeString(comment.message),
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function normalizeTransition(transition = {}, nowIso = new Date().toISOString()) {
|
|
94
|
+
return {
|
|
95
|
+
at: normalizeIsoTimestamp(transition.at, nowIso),
|
|
96
|
+
actor: normalizeString(transition.actor) || "omar-daemon",
|
|
97
|
+
from: normalizeStatus(transition.from, "OPEN"),
|
|
98
|
+
to: normalizeStatus(transition.to, "OPEN"),
|
|
99
|
+
reason: normalizeString(transition.reason) || null,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function normalizeIssue(issue = {}, nowIso = new Date().toISOString()) {
|
|
104
|
+
const createdAt = normalizeIsoTimestamp(issue.createdAt, nowIso);
|
|
105
|
+
return {
|
|
106
|
+
workItemId: normalizeString(issue.workItemId),
|
|
107
|
+
issueKey: normalizeString(issue.issueKey),
|
|
108
|
+
summary: normalizeString(issue.summary) || "Daemon work item remediation",
|
|
109
|
+
description: normalizeString(issue.description),
|
|
110
|
+
status: normalizeStatus(issue.status, "OPEN"),
|
|
111
|
+
labels: normalizeLabels(issue.labels),
|
|
112
|
+
assignee: normalizeString(issue.assignee) || null,
|
|
113
|
+
createdAt,
|
|
114
|
+
updatedAt: normalizeIsoTimestamp(issue.updatedAt, createdAt),
|
|
115
|
+
latestCommentAt: issue.latestCommentAt ? normalizeIsoTimestamp(issue.latestCommentAt, createdAt) : null,
|
|
116
|
+
comments: Array.isArray(issue.comments)
|
|
117
|
+
? issue.comments.map((comment) => normalizeComment(comment, createdAt)).filter((comment) => comment.message)
|
|
118
|
+
: [],
|
|
119
|
+
transitions: Array.isArray(issue.transitions)
|
|
120
|
+
? issue.transitions
|
|
121
|
+
.map((transition) => normalizeTransition(transition, createdAt))
|
|
122
|
+
.filter((transition) => transition.to)
|
|
123
|
+
: [],
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function createInitialLifecycle(nowIso = new Date().toISOString()) {
|
|
128
|
+
return {
|
|
129
|
+
schemaVersion: LIFECYCLE_SCHEMA_VERSION,
|
|
130
|
+
generatedAt: normalizeIsoTimestamp(nowIso, nowIso),
|
|
131
|
+
issueCounter: 0,
|
|
132
|
+
issues: [],
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function normalizeIssueKeyPrefix(value) {
|
|
137
|
+
const cleaned = normalizeString(value)
|
|
138
|
+
.toUpperCase()
|
|
139
|
+
.replace(/[^A-Z0-9]+/g, "");
|
|
140
|
+
if (!cleaned) {
|
|
141
|
+
return "SLD";
|
|
142
|
+
}
|
|
143
|
+
return cleaned.slice(0, 12);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function parseCsv(rawValue) {
|
|
147
|
+
if (!rawValue) {
|
|
148
|
+
return [];
|
|
149
|
+
}
|
|
150
|
+
return String(rawValue)
|
|
151
|
+
.split(",")
|
|
152
|
+
.map((item) => item.trim())
|
|
153
|
+
.filter(Boolean);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
async function loadJsonFile(filePath, defaultFactory) {
|
|
157
|
+
try {
|
|
158
|
+
const raw = await fsp.readFile(filePath, "utf-8");
|
|
159
|
+
return JSON.parse(raw);
|
|
160
|
+
} catch (error) {
|
|
161
|
+
if (error && typeof error === "object" && error.code === "ENOENT") {
|
|
162
|
+
return defaultFactory();
|
|
163
|
+
}
|
|
164
|
+
throw error;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
async function writeJsonFile(filePath, payload = {}) {
|
|
169
|
+
await fsp.mkdir(path.dirname(filePath), { recursive: true });
|
|
170
|
+
await fsp.writeFile(filePath, `${JSON.stringify(payload, null, 2)}\n`, "utf-8");
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
async function appendEvent(filePath, payload = {}) {
|
|
174
|
+
await fsp.mkdir(path.dirname(filePath), { recursive: true });
|
|
175
|
+
await fsp.appendFile(filePath, `${JSON.stringify(payload)}\n`, "utf-8");
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
async function loadQueue(queuePath, nowIso = new Date().toISOString()) {
|
|
179
|
+
const parsed = await loadJsonFile(queuePath, () => ({
|
|
180
|
+
schemaVersion: QUEUE_SCHEMA_VERSION,
|
|
181
|
+
generatedAt: normalizeIsoTimestamp(nowIso, nowIso),
|
|
182
|
+
items: [],
|
|
183
|
+
}));
|
|
184
|
+
return {
|
|
185
|
+
schemaVersion: normalizeString(parsed.schemaVersion) || QUEUE_SCHEMA_VERSION,
|
|
186
|
+
generatedAt: normalizeIsoTimestamp(parsed.generatedAt, nowIso),
|
|
187
|
+
items: Array.isArray(parsed.items) ? parsed.items : [],
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
async function loadLifecycle(lifecyclePath, nowIso = new Date().toISOString()) {
|
|
192
|
+
const parsed = await loadJsonFile(lifecyclePath, () => createInitialLifecycle(nowIso));
|
|
193
|
+
return {
|
|
194
|
+
schemaVersion: normalizeString(parsed.schemaVersion) || LIFECYCLE_SCHEMA_VERSION,
|
|
195
|
+
generatedAt: normalizeIsoTimestamp(parsed.generatedAt, nowIso),
|
|
196
|
+
issueCounter: Number(parsed.issueCounter || 0),
|
|
197
|
+
issues: Array.isArray(parsed.issues)
|
|
198
|
+
? parsed.issues.map((issue) => normalizeIssue(issue, nowIso)).filter((issue) => issue.workItemId && issue.issueKey)
|
|
199
|
+
: [],
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
async function writeLifecycle(lifecyclePath, lifecycle = {}, nowIso = new Date().toISOString()) {
|
|
204
|
+
const normalized = {
|
|
205
|
+
schemaVersion: LIFECYCLE_SCHEMA_VERSION,
|
|
206
|
+
generatedAt: normalizeIsoTimestamp(nowIso, nowIso),
|
|
207
|
+
issueCounter: Math.max(0, Number(lifecycle.issueCounter || 0)),
|
|
208
|
+
issues: Array.isArray(lifecycle.issues)
|
|
209
|
+
? lifecycle.issues
|
|
210
|
+
.map((issue) => normalizeIssue(issue, nowIso))
|
|
211
|
+
.filter((issue) => issue.workItemId && issue.issueKey)
|
|
212
|
+
: [],
|
|
213
|
+
};
|
|
214
|
+
await writeJsonFile(lifecyclePath, normalized);
|
|
215
|
+
return normalized;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function findIssueIndex(lifecycle = {}, { workItemId = "", issueKey = "" } = {}) {
|
|
219
|
+
const normalizedWorkItemId = normalizeString(workItemId);
|
|
220
|
+
const normalizedIssueKey = normalizeString(issueKey);
|
|
221
|
+
return lifecycle.issues.findIndex((issue) => {
|
|
222
|
+
if (normalizedIssueKey && issue.issueKey === normalizedIssueKey) {
|
|
223
|
+
return true;
|
|
224
|
+
}
|
|
225
|
+
if (normalizedWorkItemId && issue.workItemId === normalizedWorkItemId) {
|
|
226
|
+
return true;
|
|
227
|
+
}
|
|
228
|
+
return false;
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function buildDefaultSummary(queueItem = {}, workItemId = "") {
|
|
233
|
+
const service = normalizeString(queueItem.service) || "unknown-service";
|
|
234
|
+
const endpoint = normalizeString(queueItem.endpoint) || "unknown-endpoint";
|
|
235
|
+
const errorCode = normalizeString(queueItem.errorCode) || "UNKNOWN_ERROR";
|
|
236
|
+
return `[${workItemId}] ${service} ${endpoint} ${errorCode}`.trim();
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
function buildDefaultDescription(queueItem = {}) {
|
|
240
|
+
const lines = [
|
|
241
|
+
`service: ${normalizeString(queueItem.service) || "unknown-service"}`,
|
|
242
|
+
`endpoint: ${normalizeString(queueItem.endpoint) || "unknown-endpoint"}`,
|
|
243
|
+
`error_code: ${normalizeString(queueItem.errorCode) || "UNKNOWN_ERROR"}`,
|
|
244
|
+
`severity: ${normalizeString(queueItem.severity) || "UNKNOWN"}`,
|
|
245
|
+
`message: ${normalizeString(queueItem.message) || "n/a"}`,
|
|
246
|
+
`fingerprint: ${normalizeString(queueItem.fingerprint) || "n/a"}`,
|
|
247
|
+
];
|
|
248
|
+
return lines.join("\n");
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
async function syncIssueKeyToAssignment({
|
|
252
|
+
targetPath,
|
|
253
|
+
outputDir,
|
|
254
|
+
workItemId,
|
|
255
|
+
issueKey,
|
|
256
|
+
nowIso,
|
|
257
|
+
env,
|
|
258
|
+
homeDir,
|
|
259
|
+
} = {}) {
|
|
260
|
+
const assignmentStorage = await resolveAssignmentLedgerStorage({
|
|
261
|
+
targetPath,
|
|
262
|
+
outputDir,
|
|
263
|
+
env,
|
|
264
|
+
homeDir,
|
|
265
|
+
});
|
|
266
|
+
const rawLedger = await loadJsonFile(assignmentStorage.ledgerPath, () => null);
|
|
267
|
+
if (!rawLedger || !Array.isArray(rawLedger.assignments)) {
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
const assignments = rawLedger.assignments.map((record) => ({
|
|
271
|
+
...record,
|
|
272
|
+
workItemId: normalizeString(record.workItemId),
|
|
273
|
+
}));
|
|
274
|
+
const index = assignments.findIndex((record) => record.workItemId === workItemId);
|
|
275
|
+
if (index < 0) {
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
assignments[index] = {
|
|
279
|
+
...assignments[index],
|
|
280
|
+
jiraIssueKey: issueKey,
|
|
281
|
+
updatedAt: nowIso,
|
|
282
|
+
};
|
|
283
|
+
await writeJsonFile(assignmentStorage.ledgerPath, {
|
|
284
|
+
...rawLedger,
|
|
285
|
+
generatedAt: nowIso,
|
|
286
|
+
assignments,
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
export async function resolveJiraLifecycleStorage({
|
|
291
|
+
targetPath = ".",
|
|
292
|
+
outputDir = "",
|
|
293
|
+
env,
|
|
294
|
+
homeDir,
|
|
295
|
+
} = {}) {
|
|
296
|
+
const daemonStorage = await resolveErrorDaemonStorage({
|
|
297
|
+
targetPath,
|
|
298
|
+
outputDir,
|
|
299
|
+
env,
|
|
300
|
+
homeDir,
|
|
301
|
+
});
|
|
302
|
+
return {
|
|
303
|
+
...daemonStorage,
|
|
304
|
+
lifecyclePath: path.join(daemonStorage.baseDir, "jira-lifecycle.json"),
|
|
305
|
+
eventsPath: path.join(daemonStorage.baseDir, "jira-events.ndjson"),
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
export async function emitJiraLifecycleEvent(
|
|
310
|
+
sessionId,
|
|
311
|
+
{
|
|
312
|
+
phase,
|
|
313
|
+
ticketKey,
|
|
314
|
+
workItemId,
|
|
315
|
+
payload = {},
|
|
316
|
+
targetPath = ".",
|
|
317
|
+
nowIso = new Date().toISOString(),
|
|
318
|
+
} = {}
|
|
319
|
+
) {
|
|
320
|
+
const normalizedSessionId = normalizeString(sessionId);
|
|
321
|
+
if (!normalizedSessionId) {
|
|
322
|
+
throw new Error("sessionId is required.");
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
const normalizedPayload =
|
|
326
|
+
payload && typeof payload === "object" && !Array.isArray(payload) ? { ...payload } : {};
|
|
327
|
+
const normalizedWorkItemId = normalizeString(workItemId);
|
|
328
|
+
const normalizedTicketKey = normalizeString(ticketKey);
|
|
329
|
+
const normalizedPhase = normalizeJiraLifecyclePhase(phase);
|
|
330
|
+
const normalizedNow = normalizeIsoTimestamp(nowIso, new Date().toISOString());
|
|
331
|
+
const resolvedTargetPath = path.resolve(String(targetPath || "."));
|
|
332
|
+
|
|
333
|
+
const event = createAgentEvent({
|
|
334
|
+
event: "jira_lifecycle",
|
|
335
|
+
agentId: "omar-orchestrator",
|
|
336
|
+
sessionId: normalizedSessionId,
|
|
337
|
+
workItemId: normalizedWorkItemId || undefined,
|
|
338
|
+
ts: normalizedNow,
|
|
339
|
+
payload: {
|
|
340
|
+
phase: normalizedPhase,
|
|
341
|
+
ticketKey: normalizedTicketKey || null,
|
|
342
|
+
workItemId: normalizedWorkItemId || null,
|
|
343
|
+
...normalizedPayload,
|
|
344
|
+
},
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
await appendToStream(normalizedSessionId, event, {
|
|
348
|
+
targetPath: resolvedTargetPath,
|
|
349
|
+
});
|
|
350
|
+
return event;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
export async function openJiraIssue({
|
|
354
|
+
targetPath = ".",
|
|
355
|
+
outputDir = "",
|
|
356
|
+
sessionId = "",
|
|
357
|
+
workItemId,
|
|
358
|
+
summary = "",
|
|
359
|
+
description = "",
|
|
360
|
+
labels = [],
|
|
361
|
+
assignee = "",
|
|
362
|
+
issueKey = "",
|
|
363
|
+
issueKeyPrefix = "SLD",
|
|
364
|
+
actor = "omar-daemon",
|
|
365
|
+
env,
|
|
366
|
+
homeDir,
|
|
367
|
+
nowIso = new Date().toISOString(),
|
|
368
|
+
} = {}) {
|
|
369
|
+
const normalizedNow = normalizeIsoTimestamp(nowIso, new Date().toISOString());
|
|
370
|
+
const normalizedWorkItemId = normalizeString(workItemId);
|
|
371
|
+
const normalizedSessionId = normalizeString(sessionId);
|
|
372
|
+
if (!normalizedWorkItemId) {
|
|
373
|
+
throw new Error("workItemId is required.");
|
|
374
|
+
}
|
|
375
|
+
const storage = await resolveJiraLifecycleStorage({
|
|
376
|
+
targetPath,
|
|
377
|
+
outputDir,
|
|
378
|
+
env,
|
|
379
|
+
homeDir,
|
|
380
|
+
});
|
|
381
|
+
const [queue, lifecycle] = await Promise.all([
|
|
382
|
+
loadQueue(storage.queuePath, normalizedNow),
|
|
383
|
+
loadLifecycle(storage.lifecyclePath, normalizedNow),
|
|
384
|
+
]);
|
|
385
|
+
const queueItem = queue.items.find((item) => normalizeString(item.workItemId) === normalizedWorkItemId);
|
|
386
|
+
if (!queueItem) {
|
|
387
|
+
throw new Error(`Work item '${normalizedWorkItemId}' was not found in daemon queue.`);
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
const existingIndex = findIssueIndex(lifecycle, { workItemId: normalizedWorkItemId });
|
|
391
|
+
if (existingIndex >= 0) {
|
|
392
|
+
const existing = lifecycle.issues[existingIndex];
|
|
393
|
+
if (normalizedSessionId) {
|
|
394
|
+
await emitJiraLifecycleEvent(normalizedSessionId, {
|
|
395
|
+
phase: "checkpoint",
|
|
396
|
+
ticketKey: existing.issueKey,
|
|
397
|
+
workItemId: normalizedWorkItemId,
|
|
398
|
+
payload: {
|
|
399
|
+
status: existing.status,
|
|
400
|
+
reused: true,
|
|
401
|
+
},
|
|
402
|
+
targetPath,
|
|
403
|
+
nowIso: normalizedNow,
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
await syncIssueKeyToAssignment({
|
|
407
|
+
targetPath,
|
|
408
|
+
outputDir,
|
|
409
|
+
workItemId: normalizedWorkItemId,
|
|
410
|
+
issueKey: existing.issueKey,
|
|
411
|
+
nowIso: normalizedNow,
|
|
412
|
+
env,
|
|
413
|
+
homeDir,
|
|
414
|
+
});
|
|
415
|
+
return {
|
|
416
|
+
...storage,
|
|
417
|
+
issue: existing,
|
|
418
|
+
created: false,
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
let normalizedIssueKey = normalizeString(issueKey);
|
|
423
|
+
if (!normalizedIssueKey) {
|
|
424
|
+
const prefix = normalizeIssueKeyPrefix(issueKeyPrefix);
|
|
425
|
+
lifecycle.issueCounter = Math.max(0, Number(lifecycle.issueCounter || 0)) + 1;
|
|
426
|
+
normalizedIssueKey = `${prefix}-${lifecycle.issueCounter}`;
|
|
427
|
+
}
|
|
428
|
+
const duplicateIssueKey = lifecycle.issues.some((issue) => issue.issueKey === normalizedIssueKey);
|
|
429
|
+
if (duplicateIssueKey) {
|
|
430
|
+
throw new Error(`issueKey '${normalizedIssueKey}' already exists in jira lifecycle registry.`);
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
const issue = normalizeIssue(
|
|
434
|
+
{
|
|
435
|
+
workItemId: normalizedWorkItemId,
|
|
436
|
+
issueKey: normalizedIssueKey,
|
|
437
|
+
summary: normalizeString(summary) || buildDefaultSummary(queueItem, normalizedWorkItemId),
|
|
438
|
+
description: normalizeString(description) || buildDefaultDescription(queueItem),
|
|
439
|
+
status: "OPEN",
|
|
440
|
+
labels: normalizeLabels([
|
|
441
|
+
"sentinelayer",
|
|
442
|
+
"omar-daemon",
|
|
443
|
+
`severity-${normalizeString(queueItem.severity || "unknown").toLowerCase()}`,
|
|
444
|
+
...labels,
|
|
445
|
+
]),
|
|
446
|
+
assignee: normalizeString(assignee) || null,
|
|
447
|
+
createdAt: normalizedNow,
|
|
448
|
+
updatedAt: normalizedNow,
|
|
449
|
+
latestCommentAt: null,
|
|
450
|
+
comments: [],
|
|
451
|
+
transitions: [],
|
|
452
|
+
},
|
|
453
|
+
normalizedNow
|
|
454
|
+
);
|
|
455
|
+
lifecycle.issues.push(issue);
|
|
456
|
+
const savedLifecycle = await writeLifecycle(storage.lifecyclePath, lifecycle, normalizedNow);
|
|
457
|
+
await appendEvent(storage.eventsPath, {
|
|
458
|
+
timestamp: normalizedNow,
|
|
459
|
+
eventType: "create_issue",
|
|
460
|
+
actor: normalizeString(actor) || "omar-daemon",
|
|
461
|
+
workItemId: normalizedWorkItemId,
|
|
462
|
+
issueKey: normalizedIssueKey,
|
|
463
|
+
status: "OPEN",
|
|
464
|
+
});
|
|
465
|
+
await syncIssueKeyToAssignment({
|
|
466
|
+
targetPath,
|
|
467
|
+
outputDir,
|
|
468
|
+
workItemId: normalizedWorkItemId,
|
|
469
|
+
issueKey: normalizedIssueKey,
|
|
470
|
+
nowIso: normalizedNow,
|
|
471
|
+
env,
|
|
472
|
+
homeDir,
|
|
473
|
+
});
|
|
474
|
+
if (normalizedSessionId) {
|
|
475
|
+
await emitJiraLifecycleEvent(normalizedSessionId, {
|
|
476
|
+
phase: "create",
|
|
477
|
+
ticketKey: normalizedIssueKey,
|
|
478
|
+
workItemId: normalizedWorkItemId,
|
|
479
|
+
payload: {
|
|
480
|
+
status: issue.status,
|
|
481
|
+
summary: issue.summary,
|
|
482
|
+
},
|
|
483
|
+
targetPath,
|
|
484
|
+
nowIso: normalizedNow,
|
|
485
|
+
});
|
|
486
|
+
}
|
|
487
|
+
return {
|
|
488
|
+
...storage,
|
|
489
|
+
lifecycle: savedLifecycle,
|
|
490
|
+
issue,
|
|
491
|
+
created: true,
|
|
492
|
+
};
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
export async function commentJiraIssue({
|
|
496
|
+
targetPath = ".",
|
|
497
|
+
outputDir = "",
|
|
498
|
+
sessionId = "",
|
|
499
|
+
workItemId = "",
|
|
500
|
+
issueKey = "",
|
|
501
|
+
actor = "omar-daemon",
|
|
502
|
+
type = "note",
|
|
503
|
+
message,
|
|
504
|
+
env,
|
|
505
|
+
homeDir,
|
|
506
|
+
nowIso = new Date().toISOString(),
|
|
507
|
+
} = {}) {
|
|
508
|
+
const normalizedNow = normalizeIsoTimestamp(nowIso, new Date().toISOString());
|
|
509
|
+
const normalizedMessage = normalizeString(message);
|
|
510
|
+
const normalizedSessionId = normalizeString(sessionId);
|
|
511
|
+
if (!normalizedMessage) {
|
|
512
|
+
throw new Error("message is required.");
|
|
513
|
+
}
|
|
514
|
+
const storage = await resolveJiraLifecycleStorage({
|
|
515
|
+
targetPath,
|
|
516
|
+
outputDir,
|
|
517
|
+
env,
|
|
518
|
+
homeDir,
|
|
519
|
+
});
|
|
520
|
+
const lifecycle = await loadLifecycle(storage.lifecyclePath, normalizedNow);
|
|
521
|
+
const issueIndex = findIssueIndex(lifecycle, { workItemId, issueKey });
|
|
522
|
+
if (issueIndex < 0) {
|
|
523
|
+
throw new Error("No jira lifecycle issue found for the provided workItemId/issueKey.");
|
|
524
|
+
}
|
|
525
|
+
const existing = lifecycle.issues[issueIndex];
|
|
526
|
+
const comment = normalizeComment(
|
|
527
|
+
{
|
|
528
|
+
at: normalizedNow,
|
|
529
|
+
actor,
|
|
530
|
+
type,
|
|
531
|
+
message: normalizedMessage,
|
|
532
|
+
},
|
|
533
|
+
normalizedNow
|
|
534
|
+
);
|
|
535
|
+
existing.comments = [...existing.comments, comment];
|
|
536
|
+
existing.latestCommentAt = normalizedNow;
|
|
537
|
+
existing.updatedAt = normalizedNow;
|
|
538
|
+
lifecycle.issues[issueIndex] = normalizeIssue(existing, normalizedNow);
|
|
539
|
+
const savedLifecycle = await writeLifecycle(storage.lifecyclePath, lifecycle, normalizedNow);
|
|
540
|
+
await appendEvent(storage.eventsPath, {
|
|
541
|
+
timestamp: normalizedNow,
|
|
542
|
+
eventType: "comment",
|
|
543
|
+
actor: normalizeString(actor) || "omar-daemon",
|
|
544
|
+
workItemId: existing.workItemId,
|
|
545
|
+
issueKey: existing.issueKey,
|
|
546
|
+
type: comment.type,
|
|
547
|
+
message: comment.message,
|
|
548
|
+
});
|
|
549
|
+
if (normalizedSessionId) {
|
|
550
|
+
await emitJiraLifecycleEvent(normalizedSessionId, {
|
|
551
|
+
phase: comment.type === "plan" ? "plan_comment" : "checkpoint",
|
|
552
|
+
ticketKey: existing.issueKey,
|
|
553
|
+
workItemId: existing.workItemId,
|
|
554
|
+
payload: {
|
|
555
|
+
commentType: comment.type,
|
|
556
|
+
status: lifecycle.issues[issueIndex].status,
|
|
557
|
+
message: comment.message,
|
|
558
|
+
},
|
|
559
|
+
targetPath,
|
|
560
|
+
nowIso: normalizedNow,
|
|
561
|
+
});
|
|
562
|
+
}
|
|
563
|
+
return {
|
|
564
|
+
...storage,
|
|
565
|
+
lifecycle: savedLifecycle,
|
|
566
|
+
issue: lifecycle.issues[issueIndex],
|
|
567
|
+
comment,
|
|
568
|
+
};
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
export async function transitionJiraIssue({
|
|
572
|
+
targetPath = ".",
|
|
573
|
+
outputDir = "",
|
|
574
|
+
sessionId = "",
|
|
575
|
+
workItemId = "",
|
|
576
|
+
issueKey = "",
|
|
577
|
+
toStatus,
|
|
578
|
+
actor = "omar-daemon",
|
|
579
|
+
reason = "",
|
|
580
|
+
env,
|
|
581
|
+
homeDir,
|
|
582
|
+
nowIso = new Date().toISOString(),
|
|
583
|
+
} = {}) {
|
|
584
|
+
const normalizedNow = normalizeIsoTimestamp(nowIso, new Date().toISOString());
|
|
585
|
+
const nextStatus = normalizeStatus(toStatus, "");
|
|
586
|
+
const normalizedSessionId = normalizeString(sessionId);
|
|
587
|
+
if (!nextStatus) {
|
|
588
|
+
throw new Error(`toStatus must be one of: ${JIRA_STATUSES.join(", ")}.`);
|
|
589
|
+
}
|
|
590
|
+
const storage = await resolveJiraLifecycleStorage({
|
|
591
|
+
targetPath,
|
|
592
|
+
outputDir,
|
|
593
|
+
env,
|
|
594
|
+
homeDir,
|
|
595
|
+
});
|
|
596
|
+
const lifecycle = await loadLifecycle(storage.lifecyclePath, normalizedNow);
|
|
597
|
+
const issueIndex = findIssueIndex(lifecycle, { workItemId, issueKey });
|
|
598
|
+
if (issueIndex < 0) {
|
|
599
|
+
throw new Error("No jira lifecycle issue found for the provided workItemId/issueKey.");
|
|
600
|
+
}
|
|
601
|
+
const existing = lifecycle.issues[issueIndex];
|
|
602
|
+
const transition = normalizeTransition(
|
|
603
|
+
{
|
|
604
|
+
at: normalizedNow,
|
|
605
|
+
actor,
|
|
606
|
+
from: existing.status,
|
|
607
|
+
to: nextStatus,
|
|
608
|
+
reason,
|
|
609
|
+
},
|
|
610
|
+
normalizedNow
|
|
611
|
+
);
|
|
612
|
+
existing.status = nextStatus;
|
|
613
|
+
existing.transitions = [...existing.transitions, transition];
|
|
614
|
+
existing.updatedAt = normalizedNow;
|
|
615
|
+
lifecycle.issues[issueIndex] = normalizeIssue(existing, normalizedNow);
|
|
616
|
+
const savedLifecycle = await writeLifecycle(storage.lifecyclePath, lifecycle, normalizedNow);
|
|
617
|
+
await appendEvent(storage.eventsPath, {
|
|
618
|
+
timestamp: normalizedNow,
|
|
619
|
+
eventType: "transition",
|
|
620
|
+
actor: normalizeString(actor) || "omar-daemon",
|
|
621
|
+
workItemId: existing.workItemId,
|
|
622
|
+
issueKey: existing.issueKey,
|
|
623
|
+
from: transition.from,
|
|
624
|
+
to: transition.to,
|
|
625
|
+
reason: transition.reason,
|
|
626
|
+
});
|
|
627
|
+
if (normalizedSessionId) {
|
|
628
|
+
await emitJiraLifecycleEvent(normalizedSessionId, {
|
|
629
|
+
phase: resolveTransitionPhase(nextStatus),
|
|
630
|
+
ticketKey: existing.issueKey,
|
|
631
|
+
workItemId: existing.workItemId,
|
|
632
|
+
payload: {
|
|
633
|
+
from: transition.from,
|
|
634
|
+
to: transition.to,
|
|
635
|
+
reason: transition.reason,
|
|
636
|
+
status: lifecycle.issues[issueIndex].status,
|
|
637
|
+
},
|
|
638
|
+
targetPath,
|
|
639
|
+
nowIso: normalizedNow,
|
|
640
|
+
});
|
|
641
|
+
}
|
|
642
|
+
return {
|
|
643
|
+
...storage,
|
|
644
|
+
lifecycle: savedLifecycle,
|
|
645
|
+
issue: lifecycle.issues[issueIndex],
|
|
646
|
+
transition,
|
|
647
|
+
};
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
export async function startJiraLifecycle({
|
|
651
|
+
targetPath = ".",
|
|
652
|
+
outputDir = "",
|
|
653
|
+
sessionId = "",
|
|
654
|
+
workItemId,
|
|
655
|
+
actor = "omar-daemon",
|
|
656
|
+
assignee = "",
|
|
657
|
+
summary = "",
|
|
658
|
+
description = "",
|
|
659
|
+
labels = [],
|
|
660
|
+
planMessage,
|
|
661
|
+
issueKey = "",
|
|
662
|
+
issueKeyPrefix = "SLD",
|
|
663
|
+
env,
|
|
664
|
+
homeDir,
|
|
665
|
+
nowIso = new Date().toISOString(),
|
|
666
|
+
} = {}) {
|
|
667
|
+
const opened = await openJiraIssue({
|
|
668
|
+
targetPath,
|
|
669
|
+
outputDir,
|
|
670
|
+
sessionId,
|
|
671
|
+
workItemId,
|
|
672
|
+
actor,
|
|
673
|
+
assignee,
|
|
674
|
+
summary,
|
|
675
|
+
description,
|
|
676
|
+
labels,
|
|
677
|
+
issueKey,
|
|
678
|
+
issueKeyPrefix,
|
|
679
|
+
env,
|
|
680
|
+
homeDir,
|
|
681
|
+
nowIso,
|
|
682
|
+
});
|
|
683
|
+
const normalizedPlanMessage = normalizeString(planMessage);
|
|
684
|
+
let comment = null;
|
|
685
|
+
if (normalizedPlanMessage) {
|
|
686
|
+
const commented = await commentJiraIssue({
|
|
687
|
+
targetPath,
|
|
688
|
+
outputDir,
|
|
689
|
+
sessionId,
|
|
690
|
+
workItemId,
|
|
691
|
+
issueKey: opened.issue.issueKey,
|
|
692
|
+
actor,
|
|
693
|
+
type: "plan",
|
|
694
|
+
message: normalizedPlanMessage,
|
|
695
|
+
env,
|
|
696
|
+
homeDir,
|
|
697
|
+
nowIso,
|
|
698
|
+
});
|
|
699
|
+
comment = commented.comment;
|
|
700
|
+
}
|
|
701
|
+
const transitioned = await transitionJiraIssue({
|
|
702
|
+
targetPath,
|
|
703
|
+
outputDir,
|
|
704
|
+
sessionId,
|
|
705
|
+
workItemId,
|
|
706
|
+
issueKey: opened.issue.issueKey,
|
|
707
|
+
toStatus: "IN_PROGRESS",
|
|
708
|
+
actor,
|
|
709
|
+
reason: "Agent accepted work item and started remediation plan.",
|
|
710
|
+
env,
|
|
711
|
+
homeDir,
|
|
712
|
+
nowIso,
|
|
713
|
+
});
|
|
714
|
+
return {
|
|
715
|
+
...transitioned,
|
|
716
|
+
created: opened.created,
|
|
717
|
+
comment,
|
|
718
|
+
};
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
export async function listJiraIssues({
|
|
722
|
+
targetPath = ".",
|
|
723
|
+
outputDir = "",
|
|
724
|
+
workItemId = "",
|
|
725
|
+
issueKey = "",
|
|
726
|
+
statuses = [],
|
|
727
|
+
limit = 50,
|
|
728
|
+
env,
|
|
729
|
+
homeDir,
|
|
730
|
+
nowIso = new Date().toISOString(),
|
|
731
|
+
} = {}) {
|
|
732
|
+
const normalizedNow = normalizeIsoTimestamp(nowIso, new Date().toISOString());
|
|
733
|
+
const normalizedLimit = Math.max(1, Math.floor(Number(limit || 50)));
|
|
734
|
+
const normalizedWorkItemId = normalizeString(workItemId);
|
|
735
|
+
const normalizedIssueKey = normalizeString(issueKey);
|
|
736
|
+
const statusFilter = new Set(parseCsv(statuses).map((status) => normalizeStatus(status, "")).filter(Boolean));
|
|
737
|
+
const storage = await resolveJiraLifecycleStorage({
|
|
738
|
+
targetPath,
|
|
739
|
+
outputDir,
|
|
740
|
+
env,
|
|
741
|
+
homeDir,
|
|
742
|
+
});
|
|
743
|
+
const lifecycle = await loadLifecycle(storage.lifecyclePath, normalizedNow);
|
|
744
|
+
const filtered = lifecycle.issues.filter((issue) => {
|
|
745
|
+
if (normalizedWorkItemId && issue.workItemId !== normalizedWorkItemId) {
|
|
746
|
+
return false;
|
|
747
|
+
}
|
|
748
|
+
if (normalizedIssueKey && issue.issueKey !== normalizedIssueKey) {
|
|
749
|
+
return false;
|
|
750
|
+
}
|
|
751
|
+
if (statusFilter.size > 0 && !statusFilter.has(issue.status)) {
|
|
752
|
+
return false;
|
|
753
|
+
}
|
|
754
|
+
return true;
|
|
755
|
+
});
|
|
756
|
+
const sorted = [...filtered].sort((left, right) => {
|
|
757
|
+
const leftEpoch = Date.parse(String(left.updatedAt || "")) || 0;
|
|
758
|
+
const rightEpoch = Date.parse(String(right.updatedAt || "")) || 0;
|
|
759
|
+
return rightEpoch - leftEpoch;
|
|
760
|
+
});
|
|
761
|
+
return {
|
|
762
|
+
...storage,
|
|
763
|
+
totalCount: lifecycle.issues.length,
|
|
764
|
+
visibleCount: sorted.length,
|
|
765
|
+
issues: sorted.slice(0, normalizedLimit),
|
|
766
|
+
};
|
|
767
|
+
}
|