sentinelayer-cli 0.6.2 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (159) hide show
  1. package/README.md +996 -996
  2. package/bin/create-sentinelayer.js +5 -5
  3. package/bin/sentinelayer-cli.js +4 -4
  4. package/bin/sl.js +5 -5
  5. package/package.json +64 -63
  6. package/src/agents/jules/config/definition.js +160 -160
  7. package/src/agents/jules/config/system-prompt.js +182 -182
  8. package/src/agents/jules/error-intake.js +51 -51
  9. package/src/agents/jules/fix-cycle.js +17 -17
  10. package/src/agents/jules/loop.js +457 -450
  11. package/src/agents/jules/pulse.js +10 -10
  12. package/src/agents/jules/stream.js +187 -186
  13. package/src/agents/jules/swarm/file-scanner.js +74 -74
  14. package/src/agents/jules/swarm/index.js +11 -11
  15. package/src/agents/jules/swarm/orchestrator.js +362 -362
  16. package/src/agents/jules/swarm/pattern-hunter.js +123 -123
  17. package/src/agents/jules/swarm/sub-agent.js +311 -309
  18. package/src/agents/jules/tools/aidenid-email.js +189 -189
  19. package/src/agents/jules/tools/auth-audit.js +1699 -1691
  20. package/src/agents/jules/tools/dispatch.js +340 -335
  21. package/src/agents/jules/tools/file-edit.js +2 -2
  22. package/src/agents/jules/tools/file-read.js +2 -2
  23. package/src/agents/jules/tools/frontend-analyze.js +570 -570
  24. package/src/agents/jules/tools/glob.js +2 -2
  25. package/src/agents/jules/tools/grep.js +2 -2
  26. package/src/agents/jules/tools/index.js +29 -29
  27. package/src/agents/jules/tools/path-guards.js +2 -2
  28. package/src/agents/jules/tools/runtime-audit.js +507 -507
  29. package/src/agents/jules/tools/shell.js +2 -2
  30. package/src/agents/jules/tools/url-policy.js +100 -100
  31. package/src/agents/persona-visuals.js +64 -61
  32. package/src/agents/shared-tools/dispatch-core.js +320 -315
  33. package/src/agents/shared-tools/file-edit.js +180 -180
  34. package/src/agents/shared-tools/file-read.js +100 -100
  35. package/src/agents/shared-tools/glob.js +168 -168
  36. package/src/agents/shared-tools/grep.js +228 -228
  37. package/src/agents/shared-tools/index.js +46 -46
  38. package/src/agents/shared-tools/path-guards.js +161 -161
  39. package/src/agents/shared-tools/shell.js +383 -383
  40. package/src/ai/aidenid.js +1021 -1009
  41. package/src/ai/client.js +553 -553
  42. package/src/ai/domain-target-store.js +268 -268
  43. package/src/ai/identity-store.js +270 -270
  44. package/src/ai/proxy.js +137 -137
  45. package/src/ai/site-store.js +145 -145
  46. package/src/audit/agents/architecture.js +180 -180
  47. package/src/audit/agents/compliance.js +179 -179
  48. package/src/audit/agents/documentation.js +165 -165
  49. package/src/audit/agents/performance.js +145 -145
  50. package/src/audit/agents/security.js +215 -215
  51. package/src/audit/agents/testing.js +172 -172
  52. package/src/audit/orchestrator.js +557 -557
  53. package/src/audit/package.js +204 -204
  54. package/src/audit/registry.js +284 -284
  55. package/src/audit/replay.js +103 -103
  56. package/src/auth/gate.js +400 -371
  57. package/src/auth/http.js +681 -611
  58. package/src/auth/service.js +1106 -1106
  59. package/src/auth/session-store.js +813 -813
  60. package/src/cli.js +257 -252
  61. package/src/commands/ai/identity-lifecycle.js +1338 -1338
  62. package/src/commands/ai/provision-governance.js +1272 -1272
  63. package/src/commands/ai/shared.js +147 -147
  64. package/src/commands/ai.js +11 -11
  65. package/src/commands/apply.js +12 -12
  66. package/src/commands/audit.js +1171 -1166
  67. package/src/commands/auth.js +419 -419
  68. package/src/commands/chat.js +191 -191
  69. package/src/commands/config.js +184 -184
  70. package/src/commands/cost.js +311 -311
  71. package/src/commands/daemon/core.js +850 -850
  72. package/src/commands/daemon/extended.js +1048 -1048
  73. package/src/commands/daemon/shared.js +213 -213
  74. package/src/commands/daemon.js +11 -11
  75. package/src/commands/guide.js +174 -174
  76. package/src/commands/ingest.js +58 -58
  77. package/src/commands/init.js +55 -55
  78. package/src/commands/legacy-args.js +10 -10
  79. package/src/commands/mcp.js +461 -461
  80. package/src/commands/omargate.js +29 -29
  81. package/src/commands/persona.js +20 -20
  82. package/src/commands/plugin.js +260 -260
  83. package/src/commands/policy.js +132 -132
  84. package/src/commands/prompt.js +238 -238
  85. package/src/commands/review.js +704 -704
  86. package/src/commands/scan.js +872 -872
  87. package/src/commands/session.js +590 -0
  88. package/src/commands/spec.js +778 -716
  89. package/src/commands/swarm.js +651 -651
  90. package/src/commands/telemetry.js +202 -202
  91. package/src/commands/watch.js +511 -511
  92. package/src/config/agent-dictionary.js +182 -182
  93. package/src/config/io.js +56 -56
  94. package/src/config/paths.js +18 -18
  95. package/src/config/schema.js +55 -55
  96. package/src/config/service.js +184 -184
  97. package/src/cost/budget.js +235 -235
  98. package/src/cost/history.js +188 -188
  99. package/src/cost/tracker.js +171 -171
  100. package/src/daemon/artifact-lineage.js +534 -534
  101. package/src/daemon/assignment-ledger.js +966 -770
  102. package/src/daemon/ast-parser-layer.js +258 -258
  103. package/src/daemon/budget-governor.js +633 -633
  104. package/src/daemon/callgraph-overlay.js +646 -646
  105. package/src/daemon/error-worker.js +1209 -626
  106. package/src/daemon/fix-cycle.js +384 -377
  107. package/src/daemon/hybrid-mapper.js +929 -929
  108. package/src/daemon/ingest-refresh.js +10 -9
  109. package/src/daemon/jira-lifecycle.js +767 -632
  110. package/src/daemon/operator-control.js +657 -657
  111. package/src/daemon/pulse.js +327 -327
  112. package/src/daemon/reliability-lane.js +471 -471
  113. package/src/daemon/scope-engine.js +1068 -0
  114. package/src/daemon/watchdog.js +971 -971
  115. package/src/events/schema.js +190 -0
  116. package/src/guide/generator.js +316 -316
  117. package/src/ingest/engine.js +918 -918
  118. package/src/interactive/index.js +97 -97
  119. package/src/legacy-cli.js +3161 -2994
  120. package/src/mcp/registry.js +695 -695
  121. package/src/memory/blackboard.js +301 -301
  122. package/src/memory/retrieval.js +581 -581
  123. package/src/plugin/manifest.js +553 -553
  124. package/src/policy/packs.js +144 -144
  125. package/src/prompt/generator.js +136 -118
  126. package/src/review/ai-review.js +679 -679
  127. package/src/review/local-review.js +1351 -1305
  128. package/src/review/omargate-interactive.js +68 -68
  129. package/src/review/omargate-orchestrator.js +404 -300
  130. package/src/review/persona-prompts.js +296 -296
  131. package/src/review/replay.js +235 -235
  132. package/src/review/report.js +664 -664
  133. package/src/review/scan-modes.js +48 -42
  134. package/src/review/spec-binding.js +487 -487
  135. package/src/scaffold/generator.js +67 -67
  136. package/src/scaffold/templates.js +150 -150
  137. package/src/scan/generator.js +418 -418
  138. package/src/scan/gh-secrets.js +107 -107
  139. package/src/session/agent-registry.js +352 -0
  140. package/src/session/daemon.js +801 -0
  141. package/src/session/paths.js +33 -0
  142. package/src/session/runtime-bridge.js +739 -0
  143. package/src/session/store.js +388 -0
  144. package/src/session/stream.js +325 -0
  145. package/src/spec/generator.js +619 -519
  146. package/src/spec/regenerate.js +237 -237
  147. package/src/spec/templates.js +91 -91
  148. package/src/swarm/dashboard.js +247 -247
  149. package/src/swarm/factory.js +363 -363
  150. package/src/swarm/pentest.js +934 -934
  151. package/src/swarm/registry.js +419 -419
  152. package/src/swarm/report.js +158 -158
  153. package/src/swarm/runtime.js +576 -576
  154. package/src/swarm/scenario-dsl.js +272 -272
  155. package/src/telemetry/ledger.js +302 -302
  156. package/src/telemetry/session-tracker.js +234 -234
  157. package/src/telemetry/sync.js +203 -203
  158. package/src/ui/command-hints.js +13 -13
  159. package/src/ui/markdown.js +220 -220
package/src/cli.js CHANGED
@@ -1,252 +1,257 @@
1
- import process from "node:process";
2
- import { Command } from "commander";
3
-
4
- import { CLI_VERSION, runLegacyCliWithErrorHandling } from "./legacy-cli.js";
5
-
6
- const COMMAND_REGISTRARS = {
7
- init: {
8
- loader: () => import("./commands/init.js"),
9
- exportName: "registerInitCommand",
10
- needsLegacy: true,
11
- },
12
- omargate: {
13
- loader: () => import("./commands/omargate.js"),
14
- exportName: "registerOmarGateCommand",
15
- needsLegacy: true,
16
- },
17
- audit: {
18
- loader: () => import("./commands/audit.js"),
19
- exportName: "registerAuditCommand",
20
- needsLegacy: true,
21
- },
22
- persona: {
23
- loader: () => import("./commands/persona.js"),
24
- exportName: "registerPersonaCommand",
25
- needsLegacy: true,
26
- },
27
- apply: {
28
- loader: () => import("./commands/apply.js"),
29
- exportName: "registerApplyCommand",
30
- needsLegacy: true,
31
- },
32
- config: {
33
- loader: () => import("./commands/config.js"),
34
- exportName: "registerConfigCommand",
35
- needsLegacy: false,
36
- },
37
- ingest: {
38
- loader: () => import("./commands/ingest.js"),
39
- exportName: "registerIngestCommand",
40
- needsLegacy: false,
41
- },
42
- spec: {
43
- loader: () => import("./commands/spec.js"),
44
- exportName: "registerSpecCommand",
45
- needsLegacy: false,
46
- },
47
- prompt: {
48
- loader: () => import("./commands/prompt.js"),
49
- exportName: "registerPromptCommand",
50
- needsLegacy: false,
51
- },
52
- scan: {
53
- loader: () => import("./commands/scan.js"),
54
- exportName: "registerScanCommand",
55
- needsLegacy: false,
56
- },
57
- guide: {
58
- loader: () => import("./commands/guide.js"),
59
- exportName: "registerGuideCommand",
60
- needsLegacy: false,
61
- },
62
- cost: {
63
- loader: () => import("./commands/cost.js"),
64
- exportName: "registerCostCommand",
65
- needsLegacy: false,
66
- },
67
- telemetry: {
68
- loader: () => import("./commands/telemetry.js"),
69
- exportName: "registerTelemetryCommand",
70
- needsLegacy: false,
71
- },
72
- auth: {
73
- loader: () => import("./commands/auth.js"),
74
- exportName: "registerAuthCommand",
75
- needsLegacy: false,
76
- },
77
- watch: {
78
- loader: () => import("./commands/watch.js"),
79
- exportName: "registerWatchCommand",
80
- needsLegacy: false,
81
- },
82
- mcp: {
83
- loader: () => import("./commands/mcp.js"),
84
- exportName: "registerMcpCommand",
85
- needsLegacy: false,
86
- },
87
- plugin: {
88
- loader: () => import("./commands/plugin.js"),
89
- exportName: "registerPluginCommand",
90
- needsLegacy: false,
91
- },
92
- ai: {
93
- loader: () => import("./commands/ai.js"),
94
- exportName: "registerAiCommand",
95
- needsLegacy: false,
96
- },
97
- review: {
98
- loader: () => import("./commands/review.js"),
99
- exportName: "registerReviewCommand",
100
- needsLegacy: false,
101
- },
102
- chat: {
103
- loader: () => import("./commands/chat.js"),
104
- exportName: "registerChatCommand",
105
- needsLegacy: false,
106
- },
107
- policy: {
108
- loader: () => import("./commands/policy.js"),
109
- exportName: "registerPolicyCommand",
110
- needsLegacy: false,
111
- },
112
- swarm: {
113
- loader: () => import("./commands/swarm.js"),
114
- exportName: "registerSwarmCommand",
115
- needsLegacy: false,
116
- },
117
- daemon: {
118
- loader: () => import("./commands/daemon.js"),
119
- exportName: "registerDaemonCommand",
120
- needsLegacy: false,
121
- },
122
- };
123
-
124
- const COMMAND_SET = new Set(Object.keys(COMMAND_REGISTRARS));
125
-
126
- // Map slash-prefixed commands to their Commander equivalents.
127
- // /omargate → omargate, /audit → audit local, etc.
128
- // Only remap /omargate to Commander. The others (/audit, /persona, /apply)
129
- // stay on the legacy path for backward compatibility (different output format).
130
- const SLASH_TO_COMMANDER = {
131
- "/omargate": "omargate",
132
- };
133
-
134
- function normalizeSlashArgs(rawArgs) {
135
- if (!Array.isArray(rawArgs) || rawArgs.length === 0) return rawArgs;
136
- const first = String(rawArgs[0] || "").trim();
137
-
138
- // Direct slash match: /omargate → omargate
139
- const mapped = SLASH_TO_COMMANDER[first];
140
- if (mapped) {
141
- return [mapped, ...rawArgs.slice(1)];
142
- }
143
-
144
- // Windows Git Bash path mangling fix: /omargate gets converted to
145
- // "C:/Program Files/Git/omargate" by MSYS. Detect and recover.
146
- for (const [slash, cmd] of Object.entries(SLASH_TO_COMMANDER)) {
147
- const suffix = slash.slice(1); // "omargate" from "/omargate"
148
- if (first.endsWith("/" + suffix) || first.endsWith("\\" + suffix)) {
149
- return [cmd, ...rawArgs.slice(1)];
150
- }
151
- }
152
-
153
- return rawArgs;
154
- }
155
-
156
- function shouldBypassCommander(rawArgs) {
157
- if (!Array.isArray(rawArgs) || rawArgs.length === 0) {
158
- return true;
159
- }
160
-
161
- const first = String(rawArgs[0] || "").trim();
162
- if (!first) {
163
- return true;
164
- }
165
-
166
- // Slash commands are now handled by normalizeSlashArgs before this check
167
- if (first.startsWith("/") && !SLASH_TO_COMMANDER[first]) {
168
- return true;
169
- }
170
-
171
- if (first === "--help" || first === "-h" || first === "help" || first === "--version" || first === "-v") {
172
- return true;
173
- }
174
-
175
- if (first.startsWith("-")) {
176
- return true;
177
- }
178
-
179
- const resolved = SLASH_TO_COMMANDER[first] || first;
180
- return !COMMAND_SET.has(resolved);
181
- }
182
-
183
- async function registerCommands(program, { invokeLegacy, onlyCommand } = {}) {
184
- const commandNames =
185
- onlyCommand && COMMAND_REGISTRARS[onlyCommand]
186
- ? [onlyCommand]
187
- : Object.keys(COMMAND_REGISTRARS);
188
-
189
- for (const commandName of commandNames) {
190
- const descriptor = COMMAND_REGISTRARS[commandName];
191
- const loaded = await descriptor.loader();
192
- const registerFn = loaded[descriptor.exportName];
193
- if (typeof registerFn !== "function") {
194
- throw new Error(
195
- `Command registrar '${descriptor.exportName}' was not exported by '${commandName}' loader.`
196
- );
197
- }
198
- if (descriptor.needsLegacy) {
199
- registerFn(program, invokeLegacy);
200
- } else {
201
- registerFn(program);
202
- }
203
- }
204
- }
205
-
206
- export async function buildCliProgram({
207
- invokeLegacy = runLegacyCliWithErrorHandling,
208
- onlyCommand = null,
209
- } = {}) {
210
- const program = new Command();
211
-
212
- program
213
- .name("sentinelayer-cli")
214
- .description("Sentinelayer CLI")
215
- .version(CLI_VERSION)
216
- .option("--verbose", "Verbose execution logs")
217
- .option("--quiet", "Suppress progress indicators and terminal notifications")
218
- .option("--json", "Emit machine-readable output when supported")
219
- .showHelpAfterError();
220
-
221
- await registerCommands(program, {
222
- invokeLegacy,
223
- onlyCommand: onlyCommand && COMMAND_SET.has(onlyCommand) ? onlyCommand : null,
224
- });
225
-
226
- return program;
227
- }
228
-
229
- export async function runCli(rawArgs = process.argv.slice(2)) {
230
- // Normalize slash commands (/omargate → omargate, /audit → audit, etc.)
231
- const normalizedArgs = normalizeSlashArgs(rawArgs);
232
-
233
- // Auth gate — require login for all commands except auth/help/version/config
234
- const { checkAuthGate, printAuthRequired } = await import("./auth/gate.js");
235
- const authResult = await checkAuthGate(normalizedArgs);
236
- if (!authResult.authenticated) {
237
- printAuthRequired();
238
- return;
239
- }
240
-
241
- if (shouldBypassCommander(normalizedArgs)) {
242
- await runLegacyCliWithErrorHandling(normalizedArgs);
243
- return;
244
- }
245
-
246
- const program = await buildCliProgram({
247
- invokeLegacy: runLegacyCliWithErrorHandling,
248
- onlyCommand: normalizedArgs[0],
249
- });
250
- await program.parseAsync(["node", "sentinelayer-cli", ...normalizedArgs]);
251
- }
252
-
1
+ import process from "node:process";
2
+ import { Command } from "commander";
3
+
4
+ import { CLI_VERSION, runLegacyCliWithErrorHandling } from "./legacy-cli.js";
5
+
6
+ const COMMAND_REGISTRARS = {
7
+ init: {
8
+ loader: () => import("./commands/init.js"),
9
+ exportName: "registerInitCommand",
10
+ needsLegacy: true,
11
+ },
12
+ omargate: {
13
+ loader: () => import("./commands/omargate.js"),
14
+ exportName: "registerOmarGateCommand",
15
+ needsLegacy: true,
16
+ },
17
+ audit: {
18
+ loader: () => import("./commands/audit.js"),
19
+ exportName: "registerAuditCommand",
20
+ needsLegacy: true,
21
+ },
22
+ persona: {
23
+ loader: () => import("./commands/persona.js"),
24
+ exportName: "registerPersonaCommand",
25
+ needsLegacy: true,
26
+ },
27
+ apply: {
28
+ loader: () => import("./commands/apply.js"),
29
+ exportName: "registerApplyCommand",
30
+ needsLegacy: true,
31
+ },
32
+ config: {
33
+ loader: () => import("./commands/config.js"),
34
+ exportName: "registerConfigCommand",
35
+ needsLegacy: false,
36
+ },
37
+ ingest: {
38
+ loader: () => import("./commands/ingest.js"),
39
+ exportName: "registerIngestCommand",
40
+ needsLegacy: false,
41
+ },
42
+ spec: {
43
+ loader: () => import("./commands/spec.js"),
44
+ exportName: "registerSpecCommand",
45
+ needsLegacy: false,
46
+ },
47
+ prompt: {
48
+ loader: () => import("./commands/prompt.js"),
49
+ exportName: "registerPromptCommand",
50
+ needsLegacy: false,
51
+ },
52
+ scan: {
53
+ loader: () => import("./commands/scan.js"),
54
+ exportName: "registerScanCommand",
55
+ needsLegacy: false,
56
+ },
57
+ guide: {
58
+ loader: () => import("./commands/guide.js"),
59
+ exportName: "registerGuideCommand",
60
+ needsLegacy: false,
61
+ },
62
+ cost: {
63
+ loader: () => import("./commands/cost.js"),
64
+ exportName: "registerCostCommand",
65
+ needsLegacy: false,
66
+ },
67
+ telemetry: {
68
+ loader: () => import("./commands/telemetry.js"),
69
+ exportName: "registerTelemetryCommand",
70
+ needsLegacy: false,
71
+ },
72
+ auth: {
73
+ loader: () => import("./commands/auth.js"),
74
+ exportName: "registerAuthCommand",
75
+ needsLegacy: false,
76
+ },
77
+ watch: {
78
+ loader: () => import("./commands/watch.js"),
79
+ exportName: "registerWatchCommand",
80
+ needsLegacy: false,
81
+ },
82
+ mcp: {
83
+ loader: () => import("./commands/mcp.js"),
84
+ exportName: "registerMcpCommand",
85
+ needsLegacy: false,
86
+ },
87
+ plugin: {
88
+ loader: () => import("./commands/plugin.js"),
89
+ exportName: "registerPluginCommand",
90
+ needsLegacy: false,
91
+ },
92
+ ai: {
93
+ loader: () => import("./commands/ai.js"),
94
+ exportName: "registerAiCommand",
95
+ needsLegacy: false,
96
+ },
97
+ review: {
98
+ loader: () => import("./commands/review.js"),
99
+ exportName: "registerReviewCommand",
100
+ needsLegacy: false,
101
+ },
102
+ chat: {
103
+ loader: () => import("./commands/chat.js"),
104
+ exportName: "registerChatCommand",
105
+ needsLegacy: false,
106
+ },
107
+ policy: {
108
+ loader: () => import("./commands/policy.js"),
109
+ exportName: "registerPolicyCommand",
110
+ needsLegacy: false,
111
+ },
112
+ swarm: {
113
+ loader: () => import("./commands/swarm.js"),
114
+ exportName: "registerSwarmCommand",
115
+ needsLegacy: false,
116
+ },
117
+ daemon: {
118
+ loader: () => import("./commands/daemon.js"),
119
+ exportName: "registerDaemonCommand",
120
+ needsLegacy: false,
121
+ },
122
+ session: {
123
+ loader: () => import("./commands/session.js"),
124
+ exportName: "registerSessionCommand",
125
+ needsLegacy: false,
126
+ },
127
+ };
128
+
129
+ const COMMAND_SET = new Set(Object.keys(COMMAND_REGISTRARS));
130
+
131
+ // Map slash-prefixed commands to their Commander equivalents.
132
+ // /omargate → omargate, /audit → audit local, etc.
133
+ // Only remap /omargate to Commander. The others (/audit, /persona, /apply)
134
+ // stay on the legacy path for backward compatibility (different output format).
135
+ const SLASH_TO_COMMANDER = {
136
+ "/omargate": "omargate",
137
+ };
138
+
139
+ function normalizeSlashArgs(rawArgs) {
140
+ if (!Array.isArray(rawArgs) || rawArgs.length === 0) return rawArgs;
141
+ const first = String(rawArgs[0] || "").trim();
142
+
143
+ // Direct slash match: /omargate → omargate
144
+ const mapped = SLASH_TO_COMMANDER[first];
145
+ if (mapped) {
146
+ return [mapped, ...rawArgs.slice(1)];
147
+ }
148
+
149
+ // Windows Git Bash path mangling fix: /omargate gets converted to
150
+ // "C:/Program Files/Git/omargate" by MSYS. Detect and recover.
151
+ for (const [slash, cmd] of Object.entries(SLASH_TO_COMMANDER)) {
152
+ const suffix = slash.slice(1); // "omargate" from "/omargate"
153
+ if (first.endsWith("/" + suffix) || first.endsWith("\\" + suffix)) {
154
+ return [cmd, ...rawArgs.slice(1)];
155
+ }
156
+ }
157
+
158
+ return rawArgs;
159
+ }
160
+
161
+ function shouldBypassCommander(rawArgs) {
162
+ if (!Array.isArray(rawArgs) || rawArgs.length === 0) {
163
+ return true;
164
+ }
165
+
166
+ const first = String(rawArgs[0] || "").trim();
167
+ if (!first) {
168
+ return true;
169
+ }
170
+
171
+ // Slash commands are now handled by normalizeSlashArgs before this check
172
+ if (first.startsWith("/") && !SLASH_TO_COMMANDER[first]) {
173
+ return true;
174
+ }
175
+
176
+ if (first === "--help" || first === "-h" || first === "help" || first === "--version" || first === "-v") {
177
+ return true;
178
+ }
179
+
180
+ if (first.startsWith("-")) {
181
+ return true;
182
+ }
183
+
184
+ const resolved = SLASH_TO_COMMANDER[first] || first;
185
+ return !COMMAND_SET.has(resolved);
186
+ }
187
+
188
+ async function registerCommands(program, { invokeLegacy, onlyCommand } = {}) {
189
+ const commandNames =
190
+ onlyCommand && COMMAND_REGISTRARS[onlyCommand]
191
+ ? [onlyCommand]
192
+ : Object.keys(COMMAND_REGISTRARS);
193
+
194
+ for (const commandName of commandNames) {
195
+ const descriptor = COMMAND_REGISTRARS[commandName];
196
+ const loaded = await descriptor.loader();
197
+ const registerFn = loaded[descriptor.exportName];
198
+ if (typeof registerFn !== "function") {
199
+ throw new Error(
200
+ `Command registrar '${descriptor.exportName}' was not exported by '${commandName}' loader.`
201
+ );
202
+ }
203
+ if (descriptor.needsLegacy) {
204
+ registerFn(program, invokeLegacy);
205
+ } else {
206
+ registerFn(program);
207
+ }
208
+ }
209
+ }
210
+
211
+ export async function buildCliProgram({
212
+ invokeLegacy = runLegacyCliWithErrorHandling,
213
+ onlyCommand = null,
214
+ } = {}) {
215
+ const program = new Command();
216
+
217
+ program
218
+ .name("sentinelayer-cli")
219
+ .description("Sentinelayer CLI")
220
+ .version(CLI_VERSION)
221
+ .option("--verbose", "Verbose execution logs")
222
+ .option("--quiet", "Suppress progress indicators and terminal notifications")
223
+ .option("--json", "Emit machine-readable output when supported")
224
+ .showHelpAfterError();
225
+
226
+ await registerCommands(program, {
227
+ invokeLegacy,
228
+ onlyCommand: onlyCommand && COMMAND_SET.has(onlyCommand) ? onlyCommand : null,
229
+ });
230
+
231
+ return program;
232
+ }
233
+
234
+ export async function runCli(rawArgs = process.argv.slice(2)) {
235
+ // Normalize slash commands (/omargate → omargate, /audit → audit, etc.)
236
+ const normalizedArgs = normalizeSlashArgs(rawArgs);
237
+
238
+ // Auth gate — require login for all commands except auth/help/version/config
239
+ const { checkAuthGate, printAuthRequired } = await import("./auth/gate.js");
240
+ const authResult = await checkAuthGate(normalizedArgs);
241
+ if (!authResult.authenticated) {
242
+ printAuthRequired();
243
+ return;
244
+ }
245
+
246
+ if (shouldBypassCommander(normalizedArgs)) {
247
+ await runLegacyCliWithErrorHandling(normalizedArgs);
248
+ return;
249
+ }
250
+
251
+ const program = await buildCliProgram({
252
+ invokeLegacy: runLegacyCliWithErrorHandling,
253
+ onlyCommand: normalizedArgs[0],
254
+ });
255
+ await program.parseAsync(["node", "sentinelayer-cli", ...normalizedArgs]);
256
+ }
257
+