sentinelayer-cli 0.4.5 → 0.6.2

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 (149) hide show
  1. package/README.md +996 -998
  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 +63 -63
  6. package/src/agents/jules/config/definition.js +160 -209
  7. package/src/agents/jules/config/system-prompt.js +182 -175
  8. package/src/agents/jules/error-intake.js +51 -51
  9. package/src/agents/jules/fix-cycle.js +17 -377
  10. package/src/agents/jules/loop.js +450 -367
  11. package/src/agents/jules/pulse.js +10 -327
  12. package/src/agents/jules/stream.js +186 -186
  13. package/src/agents/jules/swarm/file-scanner.js +74 -74
  14. package/src/agents/jules/swarm/index.js +11 -11
  15. package/src/agents/jules/swarm/orchestrator.js +362 -362
  16. package/src/agents/jules/swarm/pattern-hunter.js +123 -123
  17. package/src/agents/jules/swarm/sub-agent.js +309 -308
  18. package/src/agents/jules/tools/aidenid-email.js +189 -0
  19. package/src/agents/jules/tools/auth-audit.js +1691 -557
  20. package/src/agents/jules/tools/dispatch.js +335 -327
  21. package/src/agents/jules/tools/file-edit.js +2 -180
  22. package/src/agents/jules/tools/file-read.js +2 -100
  23. package/src/agents/jules/tools/frontend-analyze.js +570 -570
  24. package/src/agents/jules/tools/glob.js +2 -168
  25. package/src/agents/jules/tools/grep.js +2 -228
  26. package/src/agents/jules/tools/index.js +29 -29
  27. package/src/agents/jules/tools/path-guards.js +2 -161
  28. package/src/agents/jules/tools/runtime-audit.js +507 -503
  29. package/src/agents/jules/tools/shell.js +2 -383
  30. package/src/agents/jules/tools/url-policy.js +100 -100
  31. package/src/agents/persona-visuals.js +61 -0
  32. package/src/agents/shared-tools/dispatch-core.js +315 -0
  33. package/src/agents/shared-tools/file-edit.js +180 -0
  34. package/src/agents/shared-tools/file-read.js +100 -0
  35. package/src/agents/shared-tools/glob.js +168 -0
  36. package/src/agents/shared-tools/grep.js +228 -0
  37. package/src/agents/shared-tools/index.js +46 -0
  38. package/src/agents/shared-tools/path-guards.js +161 -0
  39. package/src/agents/shared-tools/shell.js +383 -0
  40. package/src/ai/aidenid.js +1009 -972
  41. package/src/ai/client.js +553 -508
  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 -0
  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 +371 -126
  57. package/src/auth/http.js +611 -270
  58. package/src/auth/service.js +1106 -891
  59. package/src/auth/session-store.js +813 -359
  60. package/src/cli.js +252 -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 +1166 -1166
  67. package/src/commands/auth.js +419 -375
  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 -21
  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 -866
  87. package/src/commands/spec.js +716 -716
  88. package/src/commands/swarm.js +651 -651
  89. package/src/commands/telemetry.js +202 -202
  90. package/src/commands/watch.js +511 -510
  91. package/src/config/agent-dictionary.js +182 -182
  92. package/src/config/io.js +56 -56
  93. package/src/config/paths.js +18 -18
  94. package/src/config/schema.js +55 -55
  95. package/src/config/service.js +184 -184
  96. package/src/cost/budget.js +235 -235
  97. package/src/cost/history.js +188 -188
  98. package/src/cost/tracker.js +171 -171
  99. package/src/daemon/artifact-lineage.js +534 -534
  100. package/src/daemon/assignment-ledger.js +770 -770
  101. package/src/daemon/ast-parser-layer.js +258 -258
  102. package/src/daemon/budget-governor.js +633 -633
  103. package/src/daemon/callgraph-overlay.js +646 -646
  104. package/src/daemon/error-worker.js +626 -626
  105. package/src/daemon/fix-cycle.js +377 -0
  106. package/src/daemon/hybrid-mapper.js +929 -929
  107. package/src/daemon/jira-lifecycle.js +632 -632
  108. package/src/daemon/operator-control.js +657 -657
  109. package/src/daemon/pulse.js +327 -0
  110. package/src/daemon/reliability-lane.js +471 -471
  111. package/src/daemon/watchdog.js +971 -971
  112. package/src/guide/generator.js +316 -316
  113. package/src/ingest/engine.js +918 -918
  114. package/src/interactive/index.js +97 -95
  115. package/src/legacy-cli.js +2994 -2592
  116. package/src/mcp/registry.js +695 -695
  117. package/src/memory/blackboard.js +301 -301
  118. package/src/memory/retrieval.js +581 -581
  119. package/src/plugin/manifest.js +553 -553
  120. package/src/policy/packs.js +144 -144
  121. package/src/prompt/generator.js +118 -118
  122. package/src/review/ai-review.js +679 -669
  123. package/src/review/local-review.js +1305 -1295
  124. package/src/review/omargate-interactive.js +68 -0
  125. package/src/review/omargate-orchestrator.js +300 -0
  126. package/src/review/persona-prompts.js +296 -0
  127. package/src/review/replay.js +235 -235
  128. package/src/review/report.js +664 -664
  129. package/src/review/scan-modes.js +42 -0
  130. package/src/review/spec-binding.js +487 -487
  131. package/src/scaffold/generator.js +67 -67
  132. package/src/scaffold/templates.js +150 -150
  133. package/src/scan/generator.js +418 -418
  134. package/src/scan/gh-secrets.js +107 -107
  135. package/src/spec/generator.js +519 -519
  136. package/src/spec/regenerate.js +237 -237
  137. package/src/spec/templates.js +91 -91
  138. package/src/swarm/dashboard.js +247 -247
  139. package/src/swarm/factory.js +363 -363
  140. package/src/swarm/pentest.js +934 -934
  141. package/src/swarm/registry.js +419 -419
  142. package/src/swarm/report.js +158 -158
  143. package/src/swarm/runtime.js +576 -576
  144. package/src/swarm/scenario-dsl.js +272 -272
  145. package/src/telemetry/ledger.js +302 -302
  146. package/src/telemetry/session-tracker.js +234 -118
  147. package/src/telemetry/sync.js +203 -199
  148. package/src/ui/command-hints.js +13 -0
  149. package/src/ui/markdown.js +220 -220
@@ -1,21 +1,29 @@
1
- import { buildLegacyArgs } from "./legacy-args.js";
2
-
3
- export function registerOmarGateCommand(program, invokeLegacy) {
4
- const omargate = program
5
- .command("omargate")
6
- .description("Run local Omar Gate checks");
7
-
8
- omargate
9
- .command("deep")
10
- .description("Run local credential/policy scan")
11
- .option("--path <path>", "Target repository path")
12
- .option("--output-dir <path>", "Artifact root for report output")
13
- .option("--json", "Emit machine-readable output")
14
- .action(async (options, command) => {
15
- const legacyArgs = buildLegacyArgs(["/omargate", "deep"], {
16
- commandOptions: options,
17
- command,
18
- });
19
- await invokeLegacy(legacyArgs);
20
- });
21
- }
1
+ import { buildLegacyArgs } from "./legacy-args.js";
2
+
3
+ export function registerOmarGateCommand(program, invokeLegacy) {
4
+ const omargate = program
5
+ .command("omargate")
6
+ .description("Run local Omar Gate security analysis (deterministic + AI persona swarm)");
7
+
8
+ omargate
9
+ .command("deep")
10
+ .description("Run full Omar Gate deep scan with 22-rule deterministic + multi-persona AI analysis")
11
+ .option("--path <path>", "Target repository path")
12
+ .option("--output-dir <path>", "Artifact root for report output")
13
+ .option("--no-ai", "Skip AI review layer (deterministic only)")
14
+ .option("--ai-dry-run", "Run AI layer in dry-run mode (no LLM call)")
15
+ .option("--scan-mode <mode>", "Scan depth: baseline (1 persona), deep (6), full-depth (13)")
16
+ .option("--max-parallel <n>", "Max concurrent persona calls (default: 4)")
17
+ .option("--model <id>", "LLM model override (default: gpt-5.3-codex)")
18
+ .option("--provider <name>", "LLM provider: sentinelayer, openai, anthropic, google")
19
+ .option("--max-cost <usd>", "Maximum AI layer cost in USD (default: 5.0)")
20
+ .option("--stream", "Emit NDJSON events to stdout as personas run")
21
+ .option("--json", "Emit machine-readable output")
22
+ .action(async (options, command) => {
23
+ const legacyArgs = buildLegacyArgs(["/omargate", "deep"], {
24
+ commandOptions: options,
25
+ command,
26
+ });
27
+ await invokeLegacy(legacyArgs);
28
+ });
29
+ }
@@ -1,10 +1,10 @@
1
- import { buildLegacyArgs } from "./legacy-args.js";
2
-
3
- export function registerPersonaCommand(program, invokeLegacy) {
4
- const persona = program
5
- .command("persona")
6
- .description("Generate orchestrator persona context");
7
-
1
+ import { buildLegacyArgs } from "./legacy-args.js";
2
+
3
+ export function registerPersonaCommand(program, invokeLegacy) {
4
+ const persona = program
5
+ .command("persona")
6
+ .description("Generate orchestrator persona context");
7
+
8
8
  persona
9
9
  .command("orchestrator")
10
10
  .description("Generate mode-specific orchestrator report")
@@ -12,16 +12,16 @@ export function registerPersonaCommand(program, invokeLegacy) {
12
12
  .option("--path <path>", "Target repository path")
13
13
  .option("--output-dir <path>", "Artifact root for report output")
14
14
  .option("--json", "Emit machine-readable output")
15
- .action(async (options, command) => {
16
- const legacyArgs = buildLegacyArgs([
17
- "/persona",
18
- "orchestrator",
19
- "--mode",
20
- String(options.mode || "builder"),
21
- ], {
22
- commandOptions: options,
23
- command,
24
- });
25
- await invokeLegacy(legacyArgs);
26
- });
27
- }
15
+ .action(async (options, command) => {
16
+ const legacyArgs = buildLegacyArgs([
17
+ "/persona",
18
+ "orchestrator",
19
+ "--mode",
20
+ String(options.mode || "builder"),
21
+ ], {
22
+ commandOptions: options,
23
+ command,
24
+ });
25
+ await invokeLegacy(legacyArgs);
26
+ });
27
+ }
@@ -1,260 +1,260 @@
1
- import path from "node:path";
2
- import process from "node:process";
3
-
4
- import pc from "picocolors";
5
-
6
- import {
7
- buildPluginManifestTemplate,
8
- computePluginLoadOrder,
9
- listPluginManifests,
10
- normalizePluginId,
11
- normalizePluginLoadStage,
12
- normalizePluginPackType,
13
- PLUGIN_LOAD_STAGES,
14
- PLUGIN_PACK_TYPES,
15
- readJsonFile,
16
- resolveDefaultPluginManifestPath,
17
- summarizePluginValidationError,
18
- validatePluginManifest,
19
- writeJsonFile,
20
- } from "../plugin/manifest.js";
21
-
22
- function shouldEmitJson(options, command) {
23
- const local = Boolean(options && options.json);
24
- const globalFromCommand =
25
- command && command.optsWithGlobals ? Boolean(command.optsWithGlobals().json) : false;
26
- return local || globalFromCommand;
27
- }
28
-
29
- function normalizeOutputPath(rawValue, fallbackPath) {
30
- const candidate = String(rawValue || "").trim();
31
- if (!candidate) {
32
- return fallbackPath;
33
- }
34
- return path.resolve(process.cwd(), candidate);
35
- }
36
-
37
- export function registerPluginCommand(program) {
38
- const plugin = program
39
- .command("plugin")
40
- .description("Manage Sentinelayer plugin manifests and extension-pack contracts");
41
-
42
- plugin
43
- .command("init")
44
- .description("Initialize a deterministic plugin manifest scaffold")
45
- .requiredOption("--id <plugin-id>", "Unique plugin id (lowercase)")
46
- .option(
47
- "--pack-type <type>",
48
- `Pack boundary type (${PLUGIN_PACK_TYPES.join("|")})`,
49
- "plugin"
50
- )
51
- .option(
52
- "--stage <stage>",
53
- `Load-order stage (${PLUGIN_LOAD_STAGES.join("|")})`,
54
- "scan"
55
- )
56
- .option("--path <path>", "Destination file path override")
57
- .option("--output-dir <path>", "Optional artifact output root override")
58
- .option("--force", "Overwrite destination file if it already exists")
59
- .option("--json", "Emit machine-readable output")
60
- .action(async (options, command) => {
61
- const pluginId = normalizePluginId(options.id);
62
- const packType = normalizePluginPackType(options.packType);
63
- const stage = normalizePluginLoadStage(options.stage);
64
- const defaultPath = await resolveDefaultPluginManifestPath({
65
- cwd: process.cwd(),
66
- outputDir: options.outputDir,
67
- env: process.env,
68
- pluginId,
69
- });
70
- const outputPath = normalizeOutputPath(options.path, defaultPath);
71
- const template = buildPluginManifestTemplate({
72
- pluginId,
73
- packType,
74
- stage,
75
- });
76
- const manifest = validatePluginManifest(template);
77
- const writtenPath = await writeJsonFile(outputPath, manifest, { force: Boolean(options.force) });
78
-
79
- const payload = {
80
- command: "plugin init",
81
- pluginId,
82
- packType: manifest.pack_type,
83
- stage: manifest.load_order.stage,
84
- outputPath: writtenPath,
85
- schemaVersion: manifest.schema_version,
86
- kind: manifest.kind,
87
- };
88
- if (shouldEmitJson(options, command)) {
89
- console.log(JSON.stringify(payload, null, 2));
90
- return;
91
- }
92
-
93
- console.log(pc.green(`Wrote plugin manifest: ${writtenPath}`));
94
- console.log(pc.gray(`Plugin id: ${pluginId}`));
95
- console.log(pc.gray(`Pack type: ${manifest.pack_type}`));
96
- console.log(pc.gray(`Stage: ${manifest.load_order.stage}`));
97
- console.log(pc.gray("Next: edit capabilities/security/load_order and validate before use."));
98
- });
99
-
100
- plugin
101
- .command("validate")
102
- .description("Validate a plugin manifest against Sentinelayer contract")
103
- .requiredOption("--file <path>", "Manifest file to validate")
104
- .option("--json", "Emit machine-readable output")
105
- .action(async (options, command) => {
106
- const inputPath = path.resolve(process.cwd(), String(options.file || "").trim());
107
- const loaded = await readJsonFile(inputPath);
108
- try {
109
- const manifest = validatePluginManifest(loaded.data);
110
- const payload = {
111
- command: "plugin validate",
112
- valid: true,
113
- filePath: loaded.path,
114
- pluginId: manifest.id,
115
- version: manifest.version,
116
- packType: manifest.pack_type,
117
- stage: manifest.load_order.stage,
118
- };
119
- if (shouldEmitJson(options, command)) {
120
- console.log(JSON.stringify(payload, null, 2));
121
- return;
122
- }
123
-
124
- console.log(pc.green(`Manifest valid (${manifest.id}@${manifest.version})`));
125
- console.log(pc.gray(`File: ${loaded.path}`));
126
- } catch (error) {
127
- const payload = {
128
- command: "plugin validate",
129
- valid: false,
130
- filePath: loaded.path,
131
- error: summarizePluginValidationError(error),
132
- };
133
- if (shouldEmitJson(options, command)) {
134
- console.log(JSON.stringify(payload, null, 2));
135
- } else {
136
- console.log(pc.red(`Manifest invalid: ${payload.error}`));
137
- console.log(pc.gray(`File: ${loaded.path}`));
138
- }
139
- process.exitCode = 2;
140
- }
141
- });
142
-
143
- plugin
144
- .command("list")
145
- .description("List plugin manifests discovered under local artifact root")
146
- .option("--path <path>", "Workspace path for config resolution", ".")
147
- .option("--output-dir <path>", "Optional artifact output root override")
148
- .option("--json", "Emit machine-readable output")
149
- .action(async (options, command) => {
150
- const targetPath = path.resolve(process.cwd(), String(options.path || "."));
151
- const listing = await listPluginManifests({
152
- cwd: targetPath,
153
- outputDir: options.outputDir,
154
- env: process.env,
155
- });
156
-
157
- const payload = {
158
- command: "plugin list",
159
- pluginsRoot: listing.pluginsRoot,
160
- pluginCount: listing.plugins.length,
161
- invalidCount: listing.invalid.length,
162
- plugins: listing.plugins,
163
- invalid: listing.invalid,
164
- };
165
-
166
- if (shouldEmitJson(options, command)) {
167
- console.log(JSON.stringify(payload, null, 2));
168
- } else {
169
- console.log(pc.bold("Plugin manifests"));
170
- console.log(pc.gray(`Root: ${listing.pluginsRoot}`));
171
- if (!listing.plugins.length && !listing.invalid.length) {
172
- console.log(pc.gray("(no plugin manifests found)"));
173
- return;
174
- }
175
-
176
- for (const pluginEntry of listing.plugins) {
177
- console.log(
178
- `${pluginEntry.id}@${pluginEntry.version} | type=${pluginEntry.packType} | stage=${pluginEntry.stage} | commands=${pluginEntry.commandCount} | templates=${pluginEntry.templateCount} | policies=${pluginEntry.policyCount}`
179
- );
180
- console.log(pc.gray(` ${pluginEntry.path}`));
181
- }
182
-
183
- for (const invalidEntry of listing.invalid) {
184
- console.log(pc.yellow(`invalid manifest: ${invalidEntry.path}`));
185
- console.log(pc.gray(` ${invalidEntry.error}`));
186
- }
187
- }
188
-
189
- if (listing.invalid.length > 0) {
190
- process.exitCode = 2;
191
- }
192
- });
193
-
194
- plugin
195
- .command("order")
196
- .description("Resolve deterministic plugin load order by stage")
197
- .option("--path <path>", "Workspace path for config resolution", ".")
198
- .option(
199
- "--stage <stage>",
200
- `Optional single-stage filter (${PLUGIN_LOAD_STAGES.join("|")})`
201
- )
202
- .option("--output-dir <path>", "Optional artifact output root override")
203
- .option("--json", "Emit machine-readable output")
204
- .action(async (options, command) => {
205
- const targetPath = path.resolve(process.cwd(), String(options.path || "."));
206
- const stage = options.stage ? normalizePluginLoadStage(options.stage) : "";
207
- const ordering = await computePluginLoadOrder({
208
- cwd: targetPath,
209
- outputDir: options.outputDir,
210
- env: process.env,
211
- stage,
212
- });
213
-
214
- const payload = {
215
- command: "plugin order",
216
- pluginsRoot: ordering.pluginsRoot,
217
- invalidCount: ordering.invalidCount,
218
- hasBlockingIssues: ordering.hasBlockingIssues,
219
- stages: ordering.stages,
220
- invalid: ordering.invalid,
221
- };
222
-
223
- if (shouldEmitJson(options, command)) {
224
- console.log(JSON.stringify(payload, null, 2));
225
- } else {
226
- console.log(pc.bold("Plugin load order"));
227
- console.log(pc.gray(`Root: ${ordering.pluginsRoot}`));
228
- for (const stageEntry of ordering.stages) {
229
- console.log(
230
- `${stageEntry.stage}: plugins=${stageEntry.pluginCount} cycle=${stageEntry.cycleDetected ? "yes" : "no"}`
231
- );
232
- if (stageEntry.order.length > 0) {
233
- console.log(pc.gray(` order: ${stageEntry.order.join(" -> ")}`));
234
- }
235
- if (stageEntry.unresolvedReferences.length > 0) {
236
- for (const unresolved of stageEntry.unresolvedReferences) {
237
- console.log(
238
- pc.yellow(
239
- ` unresolved ${unresolved.relation}: ${unresolved.pluginId} -> ${unresolved.dependencyId}`
240
- )
241
- );
242
- }
243
- }
244
- if (stageEntry.cycleNodes.length > 0) {
245
- console.log(pc.red(` cycle nodes: ${stageEntry.cycleNodes.join(", ")}`));
246
- }
247
- }
248
- if (ordering.invalid.length > 0) {
249
- for (const invalidEntry of ordering.invalid) {
250
- console.log(pc.yellow(`invalid manifest: ${invalidEntry.path}`));
251
- console.log(pc.gray(` ${invalidEntry.error}`));
252
- }
253
- }
254
- }
255
-
256
- if (ordering.hasBlockingIssues) {
257
- process.exitCode = 2;
258
- }
259
- });
260
- }
1
+ import path from "node:path";
2
+ import process from "node:process";
3
+
4
+ import pc from "picocolors";
5
+
6
+ import {
7
+ buildPluginManifestTemplate,
8
+ computePluginLoadOrder,
9
+ listPluginManifests,
10
+ normalizePluginId,
11
+ normalizePluginLoadStage,
12
+ normalizePluginPackType,
13
+ PLUGIN_LOAD_STAGES,
14
+ PLUGIN_PACK_TYPES,
15
+ readJsonFile,
16
+ resolveDefaultPluginManifestPath,
17
+ summarizePluginValidationError,
18
+ validatePluginManifest,
19
+ writeJsonFile,
20
+ } from "../plugin/manifest.js";
21
+
22
+ function shouldEmitJson(options, command) {
23
+ const local = Boolean(options && options.json);
24
+ const globalFromCommand =
25
+ command && command.optsWithGlobals ? Boolean(command.optsWithGlobals().json) : false;
26
+ return local || globalFromCommand;
27
+ }
28
+
29
+ function normalizeOutputPath(rawValue, fallbackPath) {
30
+ const candidate = String(rawValue || "").trim();
31
+ if (!candidate) {
32
+ return fallbackPath;
33
+ }
34
+ return path.resolve(process.cwd(), candidate);
35
+ }
36
+
37
+ export function registerPluginCommand(program) {
38
+ const plugin = program
39
+ .command("plugin")
40
+ .description("Manage Sentinelayer plugin manifests and extension-pack contracts");
41
+
42
+ plugin
43
+ .command("init")
44
+ .description("Initialize a deterministic plugin manifest scaffold")
45
+ .requiredOption("--id <plugin-id>", "Unique plugin id (lowercase)")
46
+ .option(
47
+ "--pack-type <type>",
48
+ `Pack boundary type (${PLUGIN_PACK_TYPES.join("|")})`,
49
+ "plugin"
50
+ )
51
+ .option(
52
+ "--stage <stage>",
53
+ `Load-order stage (${PLUGIN_LOAD_STAGES.join("|")})`,
54
+ "scan"
55
+ )
56
+ .option("--path <path>", "Destination file path override")
57
+ .option("--output-dir <path>", "Optional artifact output root override")
58
+ .option("--force", "Overwrite destination file if it already exists")
59
+ .option("--json", "Emit machine-readable output")
60
+ .action(async (options, command) => {
61
+ const pluginId = normalizePluginId(options.id);
62
+ const packType = normalizePluginPackType(options.packType);
63
+ const stage = normalizePluginLoadStage(options.stage);
64
+ const defaultPath = await resolveDefaultPluginManifestPath({
65
+ cwd: process.cwd(),
66
+ outputDir: options.outputDir,
67
+ env: process.env,
68
+ pluginId,
69
+ });
70
+ const outputPath = normalizeOutputPath(options.path, defaultPath);
71
+ const template = buildPluginManifestTemplate({
72
+ pluginId,
73
+ packType,
74
+ stage,
75
+ });
76
+ const manifest = validatePluginManifest(template);
77
+ const writtenPath = await writeJsonFile(outputPath, manifest, { force: Boolean(options.force) });
78
+
79
+ const payload = {
80
+ command: "plugin init",
81
+ pluginId,
82
+ packType: manifest.pack_type,
83
+ stage: manifest.load_order.stage,
84
+ outputPath: writtenPath,
85
+ schemaVersion: manifest.schema_version,
86
+ kind: manifest.kind,
87
+ };
88
+ if (shouldEmitJson(options, command)) {
89
+ console.log(JSON.stringify(payload, null, 2));
90
+ return;
91
+ }
92
+
93
+ console.log(pc.green(`Wrote plugin manifest: ${writtenPath}`));
94
+ console.log(pc.gray(`Plugin id: ${pluginId}`));
95
+ console.log(pc.gray(`Pack type: ${manifest.pack_type}`));
96
+ console.log(pc.gray(`Stage: ${manifest.load_order.stage}`));
97
+ console.log(pc.gray("Next: edit capabilities/security/load_order and validate before use."));
98
+ });
99
+
100
+ plugin
101
+ .command("validate")
102
+ .description("Validate a plugin manifest against Sentinelayer contract")
103
+ .requiredOption("--file <path>", "Manifest file to validate")
104
+ .option("--json", "Emit machine-readable output")
105
+ .action(async (options, command) => {
106
+ const inputPath = path.resolve(process.cwd(), String(options.file || "").trim());
107
+ const loaded = await readJsonFile(inputPath);
108
+ try {
109
+ const manifest = validatePluginManifest(loaded.data);
110
+ const payload = {
111
+ command: "plugin validate",
112
+ valid: true,
113
+ filePath: loaded.path,
114
+ pluginId: manifest.id,
115
+ version: manifest.version,
116
+ packType: manifest.pack_type,
117
+ stage: manifest.load_order.stage,
118
+ };
119
+ if (shouldEmitJson(options, command)) {
120
+ console.log(JSON.stringify(payload, null, 2));
121
+ return;
122
+ }
123
+
124
+ console.log(pc.green(`Manifest valid (${manifest.id}@${manifest.version})`));
125
+ console.log(pc.gray(`File: ${loaded.path}`));
126
+ } catch (error) {
127
+ const payload = {
128
+ command: "plugin validate",
129
+ valid: false,
130
+ filePath: loaded.path,
131
+ error: summarizePluginValidationError(error),
132
+ };
133
+ if (shouldEmitJson(options, command)) {
134
+ console.log(JSON.stringify(payload, null, 2));
135
+ } else {
136
+ console.log(pc.red(`Manifest invalid: ${payload.error}`));
137
+ console.log(pc.gray(`File: ${loaded.path}`));
138
+ }
139
+ process.exitCode = 2;
140
+ }
141
+ });
142
+
143
+ plugin
144
+ .command("list")
145
+ .description("List plugin manifests discovered under local artifact root")
146
+ .option("--path <path>", "Workspace path for config resolution", ".")
147
+ .option("--output-dir <path>", "Optional artifact output root override")
148
+ .option("--json", "Emit machine-readable output")
149
+ .action(async (options, command) => {
150
+ const targetPath = path.resolve(process.cwd(), String(options.path || "."));
151
+ const listing = await listPluginManifests({
152
+ cwd: targetPath,
153
+ outputDir: options.outputDir,
154
+ env: process.env,
155
+ });
156
+
157
+ const payload = {
158
+ command: "plugin list",
159
+ pluginsRoot: listing.pluginsRoot,
160
+ pluginCount: listing.plugins.length,
161
+ invalidCount: listing.invalid.length,
162
+ plugins: listing.plugins,
163
+ invalid: listing.invalid,
164
+ };
165
+
166
+ if (shouldEmitJson(options, command)) {
167
+ console.log(JSON.stringify(payload, null, 2));
168
+ } else {
169
+ console.log(pc.bold("Plugin manifests"));
170
+ console.log(pc.gray(`Root: ${listing.pluginsRoot}`));
171
+ if (!listing.plugins.length && !listing.invalid.length) {
172
+ console.log(pc.gray("(no plugin manifests found)"));
173
+ return;
174
+ }
175
+
176
+ for (const pluginEntry of listing.plugins) {
177
+ console.log(
178
+ `${pluginEntry.id}@${pluginEntry.version} | type=${pluginEntry.packType} | stage=${pluginEntry.stage} | commands=${pluginEntry.commandCount} | templates=${pluginEntry.templateCount} | policies=${pluginEntry.policyCount}`
179
+ );
180
+ console.log(pc.gray(` ${pluginEntry.path}`));
181
+ }
182
+
183
+ for (const invalidEntry of listing.invalid) {
184
+ console.log(pc.yellow(`invalid manifest: ${invalidEntry.path}`));
185
+ console.log(pc.gray(` ${invalidEntry.error}`));
186
+ }
187
+ }
188
+
189
+ if (listing.invalid.length > 0) {
190
+ process.exitCode = 2;
191
+ }
192
+ });
193
+
194
+ plugin
195
+ .command("order")
196
+ .description("Resolve deterministic plugin load order by stage")
197
+ .option("--path <path>", "Workspace path for config resolution", ".")
198
+ .option(
199
+ "--stage <stage>",
200
+ `Optional single-stage filter (${PLUGIN_LOAD_STAGES.join("|")})`
201
+ )
202
+ .option("--output-dir <path>", "Optional artifact output root override")
203
+ .option("--json", "Emit machine-readable output")
204
+ .action(async (options, command) => {
205
+ const targetPath = path.resolve(process.cwd(), String(options.path || "."));
206
+ const stage = options.stage ? normalizePluginLoadStage(options.stage) : "";
207
+ const ordering = await computePluginLoadOrder({
208
+ cwd: targetPath,
209
+ outputDir: options.outputDir,
210
+ env: process.env,
211
+ stage,
212
+ });
213
+
214
+ const payload = {
215
+ command: "plugin order",
216
+ pluginsRoot: ordering.pluginsRoot,
217
+ invalidCount: ordering.invalidCount,
218
+ hasBlockingIssues: ordering.hasBlockingIssues,
219
+ stages: ordering.stages,
220
+ invalid: ordering.invalid,
221
+ };
222
+
223
+ if (shouldEmitJson(options, command)) {
224
+ console.log(JSON.stringify(payload, null, 2));
225
+ } else {
226
+ console.log(pc.bold("Plugin load order"));
227
+ console.log(pc.gray(`Root: ${ordering.pluginsRoot}`));
228
+ for (const stageEntry of ordering.stages) {
229
+ console.log(
230
+ `${stageEntry.stage}: plugins=${stageEntry.pluginCount} cycle=${stageEntry.cycleDetected ? "yes" : "no"}`
231
+ );
232
+ if (stageEntry.order.length > 0) {
233
+ console.log(pc.gray(` order: ${stageEntry.order.join(" -> ")}`));
234
+ }
235
+ if (stageEntry.unresolvedReferences.length > 0) {
236
+ for (const unresolved of stageEntry.unresolvedReferences) {
237
+ console.log(
238
+ pc.yellow(
239
+ ` unresolved ${unresolved.relation}: ${unresolved.pluginId} -> ${unresolved.dependencyId}`
240
+ )
241
+ );
242
+ }
243
+ }
244
+ if (stageEntry.cycleNodes.length > 0) {
245
+ console.log(pc.red(` cycle nodes: ${stageEntry.cycleNodes.join(", ")}`));
246
+ }
247
+ }
248
+ if (ordering.invalid.length > 0) {
249
+ for (const invalidEntry of ordering.invalid) {
250
+ console.log(pc.yellow(`invalid manifest: ${invalidEntry.path}`));
251
+ console.log(pc.gray(` ${invalidEntry.error}`));
252
+ }
253
+ }
254
+ }
255
+
256
+ if (ordering.hasBlockingIssues) {
257
+ process.exitCode = 2;
258
+ }
259
+ });
260
+ }