sentinelayer-cli 0.1.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (133) hide show
  1. package/README.md +996 -996
  2. package/bin/create-sentinelayer.js +5 -5
  3. package/bin/sentinelayer-cli.js +4 -4
  4. package/bin/sl.js +5 -5
  5. package/package.json +62 -54
  6. package/src/agents/jules/config/definition.js +209 -209
  7. package/src/agents/jules/config/system-prompt.js +175 -175
  8. package/src/agents/jules/error-intake.js +51 -51
  9. package/src/agents/jules/fix-cycle.js +377 -377
  10. package/src/agents/jules/loop.js +367 -367
  11. package/src/agents/jules/pulse.js +319 -319
  12. package/src/agents/jules/stream.js +186 -186
  13. package/src/agents/jules/swarm/file-scanner.js +74 -74
  14. package/src/agents/jules/swarm/index.js +11 -11
  15. package/src/agents/jules/swarm/orchestrator.js +362 -362
  16. package/src/agents/jules/swarm/pattern-hunter.js +123 -123
  17. package/src/agents/jules/swarm/sub-agent.js +308 -308
  18. package/src/agents/jules/tools/auth-audit.js +226 -222
  19. package/src/agents/jules/tools/dispatch.js +327 -327
  20. package/src/agents/jules/tools/file-edit.js +180 -180
  21. package/src/agents/jules/tools/file-read.js +100 -100
  22. package/src/agents/jules/tools/frontend-analyze.js +570 -570
  23. package/src/agents/jules/tools/glob.js +168 -168
  24. package/src/agents/jules/tools/grep.js +228 -228
  25. package/src/agents/jules/tools/index.js +29 -29
  26. package/src/agents/jules/tools/path-guards.js +161 -161
  27. package/src/agents/jules/tools/runtime-audit.js +493 -493
  28. package/src/agents/jules/tools/shell.js +383 -383
  29. package/src/ai/aidenid.js +972 -945
  30. package/src/ai/client.js +508 -508
  31. package/src/ai/domain-target-store.js +268 -268
  32. package/src/ai/identity-store.js +270 -270
  33. package/src/ai/site-store.js +145 -145
  34. package/src/audit/agents/architecture.js +180 -180
  35. package/src/audit/agents/compliance.js +179 -179
  36. package/src/audit/agents/documentation.js +165 -165
  37. package/src/audit/agents/performance.js +145 -145
  38. package/src/audit/agents/security.js +215 -215
  39. package/src/audit/agents/testing.js +172 -172
  40. package/src/audit/orchestrator.js +557 -557
  41. package/src/audit/package.js +204 -204
  42. package/src/audit/registry.js +284 -284
  43. package/src/audit/replay.js +103 -103
  44. package/src/auth/http.js +113 -113
  45. package/src/auth/service.js +891 -848
  46. package/src/auth/session-store.js +359 -345
  47. package/src/cli.js +252 -252
  48. package/src/commands/ai/identity-lifecycle.js +1338 -1337
  49. package/src/commands/ai/provision-governance.js +1272 -1246
  50. package/src/commands/ai/shared.js +147 -147
  51. package/src/commands/ai.js +11 -11
  52. package/src/commands/apply.js +12 -12
  53. package/src/commands/audit.js +1166 -1147
  54. package/src/commands/auth.js +375 -366
  55. package/src/commands/chat.js +191 -191
  56. package/src/commands/config.js +184 -184
  57. package/src/commands/cost.js +311 -311
  58. package/src/commands/daemon/core.js +850 -850
  59. package/src/commands/daemon/extended.js +1048 -1048
  60. package/src/commands/daemon/shared.js +213 -213
  61. package/src/commands/daemon.js +11 -11
  62. package/src/commands/guide.js +174 -174
  63. package/src/commands/ingest.js +58 -58
  64. package/src/commands/init.js +55 -55
  65. package/src/commands/legacy-args.js +10 -10
  66. package/src/commands/mcp.js +461 -404
  67. package/src/commands/omargate.js +15 -15
  68. package/src/commands/persona.js +20 -20
  69. package/src/commands/plugin.js +260 -260
  70. package/src/commands/policy.js +132 -132
  71. package/src/commands/prompt.js +238 -238
  72. package/src/commands/review.js +704 -704
  73. package/src/commands/scan.js +866 -788
  74. package/src/commands/spec.js +716 -716
  75. package/src/commands/swarm.js +651 -651
  76. package/src/commands/telemetry.js +202 -202
  77. package/src/commands/watch.js +510 -510
  78. package/src/config/agent-dictionary.js +182 -182
  79. package/src/config/io.js +56 -56
  80. package/src/config/paths.js +18 -18
  81. package/src/config/schema.js +55 -55
  82. package/src/config/service.js +184 -184
  83. package/src/cost/budget.js +235 -235
  84. package/src/cost/history.js +188 -188
  85. package/src/cost/tracker.js +171 -171
  86. package/src/daemon/artifact-lineage.js +534 -534
  87. package/src/daemon/assignment-ledger.js +770 -770
  88. package/src/daemon/ast-parser-layer.js +258 -258
  89. package/src/daemon/budget-governor.js +633 -633
  90. package/src/daemon/callgraph-overlay.js +646 -646
  91. package/src/daemon/error-worker.js +626 -626
  92. package/src/daemon/hybrid-mapper.js +929 -929
  93. package/src/daemon/ingest-refresh.js +195 -0
  94. package/src/daemon/jira-lifecycle.js +632 -632
  95. package/src/daemon/operator-control.js +657 -657
  96. package/src/daemon/reliability-lane.js +471 -471
  97. package/src/daemon/watchdog.js +971 -971
  98. package/src/guide/generator.js +316 -316
  99. package/src/ingest/engine.js +918 -918
  100. package/src/interactive/action-menu.js +132 -0
  101. package/src/interactive/auto-ingest.js +111 -0
  102. package/src/interactive/index.js +95 -0
  103. package/src/interactive/workspace.js +92 -0
  104. package/src/legacy-cli.js +2548 -2435
  105. package/src/mcp/registry.js +695 -695
  106. package/src/memory/blackboard.js +301 -301
  107. package/src/memory/retrieval.js +581 -581
  108. package/src/plugin/manifest.js +553 -553
  109. package/src/policy/packs.js +144 -144
  110. package/src/prompt/generator.js +118 -106
  111. package/src/review/ai-review.js +669 -669
  112. package/src/review/local-review.js +1284 -1284
  113. package/src/review/replay.js +235 -235
  114. package/src/review/report.js +664 -664
  115. package/src/review/spec-binding.js +487 -487
  116. package/src/scaffold/generator.js +67 -0
  117. package/src/scaffold/templates.js +150 -0
  118. package/src/scan/generator.js +418 -351
  119. package/src/scan/gh-secrets.js +107 -0
  120. package/src/spec/generator.js +519 -519
  121. package/src/spec/regenerate.js +237 -237
  122. package/src/spec/templates.js +91 -91
  123. package/src/swarm/dashboard.js +247 -247
  124. package/src/swarm/factory.js +363 -363
  125. package/src/swarm/pentest.js +934 -934
  126. package/src/swarm/registry.js +419 -419
  127. package/src/swarm/report.js +158 -158
  128. package/src/swarm/runtime.js +576 -576
  129. package/src/swarm/scenario-dsl.js +272 -272
  130. package/src/telemetry/ledger.js +302 -302
  131. package/src/telemetry/session-tracker.js +118 -0
  132. package/src/telemetry/sync.js +190 -0
  133. package/src/ui/markdown.js +220 -220
@@ -1,21 +1,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 checks");
7
-
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
8
  omargate
9
9
  .command("deep")
10
10
  .description("Run local credential/policy scan")
11
11
  .option("--path <path>", "Target repository path")
12
12
  .option("--output-dir <path>", "Artifact root for report output")
13
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
- }
14
+ .action(async (options, command) => {
15
+ const legacyArgs = buildLegacyArgs(["/omargate", "deep"], {
16
+ commandOptions: options,
17
+ command,
18
+ });
19
+ await invokeLegacy(legacyArgs);
20
+ });
21
+ }
@@ -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
+ }