sentinelayer-cli 0.1.2 → 0.4.4

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 (129) hide show
  1. package/README.md +998 -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 +63 -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 +327 -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 +557 -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 +503 -493
  28. package/src/agents/jules/tools/shell.js +383 -383
  29. package/src/agents/jules/tools/url-policy.js +100 -0
  30. package/src/ai/aidenid.js +972 -945
  31. package/src/ai/client.js +508 -508
  32. package/src/ai/domain-target-store.js +268 -268
  33. package/src/ai/identity-store.js +270 -270
  34. package/src/ai/site-store.js +145 -145
  35. package/src/audit/agents/architecture.js +180 -180
  36. package/src/audit/agents/compliance.js +179 -179
  37. package/src/audit/agents/documentation.js +165 -165
  38. package/src/audit/agents/performance.js +145 -145
  39. package/src/audit/agents/security.js +215 -215
  40. package/src/audit/agents/testing.js +172 -172
  41. package/src/audit/orchestrator.js +557 -557
  42. package/src/audit/package.js +204 -204
  43. package/src/audit/registry.js +284 -284
  44. package/src/audit/replay.js +103 -103
  45. package/src/auth/gate.js +45 -11
  46. package/src/auth/http.js +270 -113
  47. package/src/auth/service.js +891 -848
  48. package/src/auth/session-store.js +359 -345
  49. package/src/cli.js +252 -252
  50. package/src/commands/ai/identity-lifecycle.js +1338 -1337
  51. package/src/commands/ai/provision-governance.js +1272 -1246
  52. package/src/commands/ai/shared.js +147 -147
  53. package/src/commands/ai.js +11 -11
  54. package/src/commands/apply.js +12 -12
  55. package/src/commands/audit.js +1166 -1166
  56. package/src/commands/auth.js +375 -366
  57. package/src/commands/chat.js +191 -191
  58. package/src/commands/config.js +184 -184
  59. package/src/commands/cost.js +311 -311
  60. package/src/commands/daemon/core.js +850 -850
  61. package/src/commands/daemon/extended.js +1048 -1048
  62. package/src/commands/daemon/shared.js +213 -213
  63. package/src/commands/daemon.js +11 -11
  64. package/src/commands/guide.js +174 -174
  65. package/src/commands/ingest.js +58 -58
  66. package/src/commands/init.js +55 -55
  67. package/src/commands/legacy-args.js +10 -10
  68. package/src/commands/mcp.js +461 -404
  69. package/src/commands/omargate.js +15 -15
  70. package/src/commands/persona.js +20 -20
  71. package/src/commands/plugin.js +260 -260
  72. package/src/commands/policy.js +132 -132
  73. package/src/commands/prompt.js +238 -238
  74. package/src/commands/review.js +704 -704
  75. package/src/commands/scan.js +866 -788
  76. package/src/commands/spec.js +716 -716
  77. package/src/commands/swarm.js +651 -651
  78. package/src/commands/telemetry.js +202 -202
  79. package/src/commands/watch.js +510 -510
  80. package/src/config/agent-dictionary.js +182 -182
  81. package/src/config/io.js +56 -56
  82. package/src/config/paths.js +18 -18
  83. package/src/config/schema.js +55 -55
  84. package/src/config/service.js +184 -184
  85. package/src/cost/budget.js +235 -235
  86. package/src/cost/history.js +188 -188
  87. package/src/cost/tracker.js +171 -171
  88. package/src/daemon/artifact-lineage.js +534 -534
  89. package/src/daemon/assignment-ledger.js +770 -770
  90. package/src/daemon/ast-parser-layer.js +258 -258
  91. package/src/daemon/budget-governor.js +633 -633
  92. package/src/daemon/callgraph-overlay.js +646 -646
  93. package/src/daemon/error-worker.js +626 -626
  94. package/src/daemon/hybrid-mapper.js +929 -929
  95. package/src/daemon/jira-lifecycle.js +632 -632
  96. package/src/daemon/operator-control.js +657 -657
  97. package/src/daemon/reliability-lane.js +471 -471
  98. package/src/daemon/watchdog.js +971 -971
  99. package/src/guide/generator.js +316 -316
  100. package/src/ingest/engine.js +918 -918
  101. package/src/legacy-cli.js +2592 -2435
  102. package/src/mcp/registry.js +695 -695
  103. package/src/memory/blackboard.js +301 -301
  104. package/src/memory/retrieval.js +581 -581
  105. package/src/plugin/manifest.js +553 -553
  106. package/src/policy/packs.js +144 -144
  107. package/src/prompt/generator.js +118 -106
  108. package/src/review/ai-review.js +669 -669
  109. package/src/review/local-review.js +1295 -1284
  110. package/src/review/replay.js +235 -235
  111. package/src/review/report.js +664 -664
  112. package/src/review/spec-binding.js +487 -487
  113. package/src/scaffold/generator.js +67 -0
  114. package/src/scaffold/templates.js +150 -0
  115. package/src/scan/generator.js +418 -351
  116. package/src/scan/gh-secrets.js +107 -0
  117. package/src/spec/generator.js +519 -519
  118. package/src/spec/regenerate.js +237 -237
  119. package/src/spec/templates.js +91 -91
  120. package/src/swarm/dashboard.js +247 -247
  121. package/src/swarm/factory.js +363 -363
  122. package/src/swarm/pentest.js +934 -934
  123. package/src/swarm/registry.js +419 -419
  124. package/src/swarm/report.js +158 -158
  125. package/src/swarm/runtime.js +576 -576
  126. package/src/swarm/scenario-dsl.js +272 -272
  127. package/src/telemetry/ledger.js +302 -302
  128. package/src/telemetry/sync.js +107 -61
  129. package/src/ui/markdown.js +220 -220
@@ -1,351 +1,418 @@
1
- import YAML from "yaml";
2
-
3
- export const DEFAULT_SCAN_WORKFLOW_PATH = ".github/workflows/omar-gate.yml";
4
- export const DEFAULT_SCAN_SECRET_NAME = "SENTINELAYER_TOKEN";
5
- export const SENTINELAYER_ACTION_REF = "mrrCarter/sentinelayer-v1-action@55a2c158f637d7d92e26ab0ef3ba81db791da4be";
6
- export const SUPPORTED_E2E_HINTS = Object.freeze(["auto", "yes", "no"]);
7
- export const SUPPORTED_PLAYWRIGHT_MODES = Object.freeze(["auto", "off", "baseline", "audit"]);
8
-
9
- const CHECKOUT_ACTION_REF = "actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683";
10
- const SETUP_NODE_ACTION_REF = "actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020";
11
- const SECRET_NAME_REGEX = /^[A-Z][A-Z0-9_]*$/;
12
- const REPO_SLUG_REGEX = /^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/;
13
-
14
- function normalizeChoice(rawValue, allowed, label) {
15
- const normalized = String(rawValue || "").trim().toLowerCase();
16
- if (!normalized) {
17
- return allowed[0];
18
- }
19
- if (!allowed.includes(normalized)) {
20
- throw new Error(
21
- `Invalid ${label} '${rawValue}'. Allowed values: ${allowed.join(", ")}`
22
- );
23
- }
24
- return normalized;
25
- }
26
-
27
- function normalizeSeverityGate(rawValue) {
28
- const normalized = String(rawValue || "").trim().toUpperCase();
29
- if (!normalized) {
30
- return "";
31
- }
32
- if (normalized === "NONE") {
33
- return "none";
34
- }
35
- if (normalized === "P0" || normalized === "P1" || normalized === "P2") {
36
- return normalized;
37
- }
38
- return normalized;
39
- }
40
-
41
- function normalizeMode(rawValue, fallback) {
42
- const normalized = String(rawValue || "").trim().toLowerCase();
43
- return normalized || fallback;
44
- }
45
-
46
- function hasAnyKeyword(text, keywords) {
47
- return keywords.some((keyword) => text.includes(keyword));
48
- }
49
-
50
- function computeRiskScore(text) {
51
- const weightedSignals = [
52
- ["auth", 2],
53
- ["authorization", 2],
54
- ["oauth", 2],
55
- ["token", 2],
56
- ["payment", 3],
57
- ["billing", 2],
58
- ["pii", 3],
59
- ["compliance", 2],
60
- ["encryption", 2],
61
- ["secrets", 2],
62
- ["supply_chain", 2],
63
- ["supply chain", 2],
64
- ["dependency", 1],
65
- ["admin", 1],
66
- ["tenant", 1],
67
- ["security checklist", 1],
68
- ["critical", 1],
69
- ];
70
-
71
- return weightedSignals.reduce(
72
- (score, [keyword, weight]) => (text.includes(keyword) ? score + weight : score),
73
- 0
74
- );
75
- }
76
-
77
- function parseSecretReference(rawValue) {
78
- const text = String(rawValue || "");
79
- const match = text.match(/\$\{\{\s*secrets\.([A-Za-z0-9_]+)\s*\}\}/);
80
- return match ? String(match[1]).toUpperCase() : "";
81
- }
82
-
83
- export function sanitizeSecretName(secretName) {
84
- const normalized = String(secretName || "")
85
- .trim()
86
- .toUpperCase();
87
- return SECRET_NAME_REGEX.test(normalized) ? normalized : DEFAULT_SCAN_SECRET_NAME;
88
- }
89
-
90
- export function inferScanProfile({ specMarkdown, hasE2ETests = "auto", playwrightMode = "auto" } = {}) {
91
- const specText = String(specMarkdown || "").trim().toLowerCase();
92
- if (!specText) {
93
- throw new Error("Spec content is empty. Generate or provide a spec before configuring scan workflow.");
94
- }
95
-
96
- const normalizedE2EHint = normalizeChoice(hasE2ETests, SUPPORTED_E2E_HINTS, "has-e2e-tests");
97
- const normalizedPlaywrightMode = normalizeChoice(
98
- playwrightMode,
99
- SUPPORTED_PLAYWRIGHT_MODES,
100
- "playwright-mode"
101
- );
102
-
103
- const inferredHasE2E = hasAnyKeyword(specText, [
104
- "e2e",
105
- "end-to-end",
106
- "playwright",
107
- "cypress",
108
- "integration test",
109
- ]);
110
- const riskScore = computeRiskScore(specText);
111
- const deepScanRecommended = riskScore >= 7;
112
-
113
- const scanMode = deepScanRecommended ? "deep" : "baseline";
114
- const severityGate = deepScanRecommended ? "P2" : "P1";
115
-
116
- const hasSupplyChainSignal = hasAnyKeyword(specText, [
117
- "supply_chain",
118
- "supply chain",
119
- "dependency",
120
- "dependencies",
121
- "sbom",
122
- ]);
123
- const sbomMode = hasSupplyChainSignal ? (deepScanRecommended ? "audit" : "baseline") : "off";
124
-
125
- let resolvedPlaywrightMode = "off";
126
- if (normalizedPlaywrightMode !== "auto") {
127
- resolvedPlaywrightMode = normalizedPlaywrightMode;
128
- } else if (normalizedE2EHint === "yes") {
129
- resolvedPlaywrightMode = deepScanRecommended ? "audit" : "baseline";
130
- } else if (normalizedE2EHint === "auto" && inferredHasE2E) {
131
- resolvedPlaywrightMode = deepScanRecommended ? "audit" : "baseline";
132
- }
133
-
134
- return {
135
- scanMode,
136
- severityGate,
137
- playwrightMode: resolvedPlaywrightMode,
138
- sbomMode,
139
- riskScore,
140
- inferredHasE2E,
141
- hasE2ETests: normalizedE2EHint,
142
- };
143
- }
144
-
145
- export function buildSecurityReviewWorkflow({ secretName = DEFAULT_SCAN_SECRET_NAME, profile } = {}) {
146
- if (!profile) {
147
- throw new Error("Scan profile is required to build workflow config.");
148
- }
149
- const normalizedSecret = sanitizeSecretName(secretName);
150
-
151
- const document = {
152
- name: "Omar Gate",
153
- on: {
154
- pull_request: {
155
- types: ["opened", "synchronize", "reopened"],
156
- },
157
- workflow_dispatch: {},
158
- },
159
- permissions: {
160
- contents: "read",
161
- "pull-requests": "write",
162
- checks: "write",
163
- },
164
- jobs: {
165
- omar_gate: {
166
- name: "Omar Gate",
167
- "runs-on": "ubuntu-22.04",
168
- "timeout-minutes": 20,
169
- steps: [
170
- {
171
- name: "Checkout",
172
- uses: CHECKOUT_ACTION_REF,
173
- },
174
- {
175
- name: "Setup Node",
176
- uses: SETUP_NODE_ACTION_REF,
177
- with: {
178
- "node-version": "20",
179
- cache: "npm",
180
- },
181
- },
182
- {
183
- name: "Install dependencies",
184
- run: "npm ci",
185
- },
186
- {
187
- name: "Run repository verification",
188
- run: "npm run verify",
189
- },
190
- {
191
- name: "Run Omar Gate",
192
- uses: SENTINELAYER_ACTION_REF,
193
- with: {
194
- sentinelayer_token: `\${{ secrets.${normalizedSecret} }}`,
195
- scan_mode: profile.scanMode,
196
- severity_gate: profile.severityGate,
197
- playwright_mode: profile.playwrightMode,
198
- sbom_mode: profile.sbomMode,
199
- wait_for_completion: "true",
200
- },
201
- },
202
- ],
203
- },
204
- },
205
- };
206
-
207
- return YAML.stringify(document, { lineWidth: 0 });
208
- }
209
-
210
- export function extractScanActionStep(workflowMarkdown) {
211
- const parsed = YAML.parse(String(workflowMarkdown || "")) || {};
212
- const jobs = parsed.jobs && typeof parsed.jobs === "object" ? parsed.jobs : {};
213
-
214
- for (const [jobId, job] of Object.entries(jobs)) {
215
- const steps = Array.isArray(job?.steps) ? job.steps : [];
216
- for (let stepIndex = 0; stepIndex < steps.length; stepIndex += 1) {
217
- const step = steps[stepIndex] || {};
218
- const uses = String(step.uses || "").trim();
219
- if (uses.includes("mrrCarter/sentinelayer-v1-action")) {
220
- return {
221
- jobId,
222
- stepIndex,
223
- uses,
224
- with: step.with && typeof step.with === "object" ? step.with : {},
225
- };
226
- }
227
- }
228
- }
229
-
230
- return null;
231
- }
232
-
233
- export function validateSecurityReviewWorkflow({
234
- workflowMarkdown,
235
- expectedProfile,
236
- expectedSecretName = DEFAULT_SCAN_SECRET_NAME,
237
- } = {}) {
238
- if (!expectedProfile) {
239
- throw new Error("Expected scan profile is required for validation.");
240
- }
241
-
242
- const actionStep = extractScanActionStep(workflowMarkdown);
243
- const expected = {
244
- action: "mrrCarter/sentinelayer-v1-action",
245
- scan_mode: normalizeMode(expectedProfile.scanMode, "deep"),
246
- severity_gate: normalizeSeverityGate(expectedProfile.severityGate),
247
- playwright_mode: normalizeMode(expectedProfile.playwrightMode, "off"),
248
- sbom_mode: normalizeMode(expectedProfile.sbomMode, "off"),
249
- secret_name: sanitizeSecretName(expectedSecretName),
250
- };
251
-
252
- if (!actionStep) {
253
- return {
254
- aligned: false,
255
- expected,
256
- actual: null,
257
- mismatches: [
258
- {
259
- field: "action",
260
- expected: expected.action,
261
- actual: "not found",
262
- message: "Workflow does not include mrrCarter/sentinelayer-v1-action step.",
263
- },
264
- ],
265
- };
266
- }
267
-
268
- const withConfig = actionStep.with || {};
269
- const actual = {
270
- action: actionStep.uses,
271
- scan_mode: normalizeMode(withConfig.scan_mode, ""),
272
- severity_gate: normalizeSeverityGate(withConfig.severity_gate),
273
- playwright_mode: normalizeMode(withConfig.playwright_mode, "off"),
274
- sbom_mode: normalizeMode(withConfig.sbom_mode, "off"),
275
- secret_name: parseSecretReference(withConfig.sentinelayer_token),
276
- };
277
-
278
- const mismatches = [];
279
-
280
- if (actual.scan_mode !== expected.scan_mode) {
281
- mismatches.push({
282
- field: "scan_mode",
283
- expected: expected.scan_mode,
284
- actual: actual.scan_mode || "(missing)",
285
- message: "scan_mode does not match spec-derived recommendation.",
286
- });
287
- }
288
- if (actual.severity_gate !== expected.severity_gate) {
289
- mismatches.push({
290
- field: "severity_gate",
291
- expected: expected.severity_gate,
292
- actual: actual.severity_gate || "(missing)",
293
- message: "severity_gate does not match spec-derived recommendation.",
294
- });
295
- }
296
- if (actual.playwright_mode !== expected.playwright_mode) {
297
- mismatches.push({
298
- field: "playwright_mode",
299
- expected: expected.playwright_mode,
300
- actual: actual.playwright_mode || "(missing)",
301
- message: "playwright_mode does not match e2e/spec profile.",
302
- });
303
- }
304
- if (actual.sbom_mode !== expected.sbom_mode) {
305
- mismatches.push({
306
- field: "sbom_mode",
307
- expected: expected.sbom_mode,
308
- actual: actual.sbom_mode || "(missing)",
309
- message: "sbom_mode does not match supply-chain profile.",
310
- });
311
- }
312
- if (actual.secret_name !== expected.secret_name) {
313
- mismatches.push({
314
- field: "sentinelayer_token",
315
- expected: `\${{ secrets.${expected.secret_name} }}`,
316
- actual: actual.secret_name ? `\${{ secrets.${actual.secret_name} }}` : "(missing)",
317
- message: "sentinelayer_token secret binding does not match expected secret name.",
318
- });
319
- }
320
-
321
- return {
322
- aligned: mismatches.length === 0,
323
- expected,
324
- actual,
325
- mismatches,
326
- location: {
327
- jobId: actionStep.jobId,
328
- stepIndex: actionStep.stepIndex,
329
- },
330
- };
331
- }
332
-
333
- export function buildSecretSetupInstructions(
334
- secretName = DEFAULT_SCAN_SECRET_NAME,
335
- { repoSlug = "" } = {}
336
- ) {
337
- const normalizedSecret = sanitizeSecretName(secretName);
338
- const normalizedRepoSlug = String(repoSlug || "").trim();
339
- const resolvedRepoSlug = REPO_SLUG_REGEX.test(normalizedRepoSlug)
340
- ? normalizedRepoSlug
341
- : "<owner/repo>";
342
- return [
343
- "Set the Sentinelayer token secret before relying on this workflow in PR checks:",
344
- `- gh secret set ${normalizedSecret} --repo ${resolvedRepoSlug}`,
345
- `- Verify secret visibility: gh secret list --repo ${resolvedRepoSlug}`,
346
- "- Commit and push .github/workflows/omar-gate.yml",
347
- "- For manual setup: https://sentinelayer.com/docs/getting-started/install-workflow",
348
- ];
349
- }
350
-
351
-
1
+ import YAML from "yaml";
2
+
3
+ export const DEFAULT_SCAN_WORKFLOW_PATH = ".github/workflows/omar-gate.yml";
4
+ export const DEFAULT_SCAN_SECRET_NAME = "SENTINELAYER_TOKEN";
5
+ export const SENTINELAYER_ACTION_REF = "mrrCarter/sentinelayer-v1-action@55a2c158f637d7d92e26ab0ef3ba81db791da4be";
6
+ export const SUPPORTED_E2E_HINTS = Object.freeze(["auto", "yes", "no"]);
7
+ export const SUPPORTED_PLAYWRIGHT_MODES = Object.freeze(["auto", "off", "baseline", "audit"]);
8
+
9
+ const CHECKOUT_ACTION_REF = "actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683";
10
+ const SETUP_NODE_ACTION_REF = "actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020";
11
+ const SECRET_NAME_REGEX = /^[A-Z][A-Z0-9_]*$/;
12
+ const REPO_SLUG_REGEX = /^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/;
13
+
14
+ function normalizeChoice(rawValue, allowed, label) {
15
+ const normalized = String(rawValue || "").trim().toLowerCase();
16
+ if (!normalized) {
17
+ return allowed[0];
18
+ }
19
+ if (!allowed.includes(normalized)) {
20
+ throw new Error(
21
+ `Invalid ${label} '${rawValue}'. Allowed values: ${allowed.join(", ")}`
22
+ );
23
+ }
24
+ return normalized;
25
+ }
26
+
27
+ function normalizeSeverityGate(rawValue) {
28
+ const normalized = String(rawValue || "").trim().toUpperCase();
29
+ if (!normalized) {
30
+ return "";
31
+ }
32
+ if (normalized === "NONE") {
33
+ return "none";
34
+ }
35
+ if (normalized === "P0" || normalized === "P1" || normalized === "P2") {
36
+ return normalized;
37
+ }
38
+ return normalized;
39
+ }
40
+
41
+ function normalizeMode(rawValue, fallback) {
42
+ const normalized = String(rawValue || "").trim().toLowerCase();
43
+ return normalized || fallback;
44
+ }
45
+
46
+ function hasAnyKeyword(text, keywords) {
47
+ return keywords.some((keyword) => text.includes(keyword));
48
+ }
49
+
50
+ function computeRiskScore(text) {
51
+ const weightedSignals = [
52
+ ["auth", 2],
53
+ ["authorization", 2],
54
+ ["oauth", 2],
55
+ ["token", 2],
56
+ ["payment", 3],
57
+ ["billing", 2],
58
+ ["pii", 3],
59
+ ["compliance", 2],
60
+ ["encryption", 2],
61
+ ["secrets", 2],
62
+ ["supply_chain", 2],
63
+ ["supply chain", 2],
64
+ ["dependency", 1],
65
+ ["admin", 1],
66
+ ["tenant", 1],
67
+ ["security checklist", 1],
68
+ ["critical", 1],
69
+ ];
70
+
71
+ return weightedSignals.reduce(
72
+ (score, [keyword, weight]) => (text.includes(keyword) ? score + weight : score),
73
+ 0
74
+ );
75
+ }
76
+
77
+ function parseSecretReference(rawValue) {
78
+ const text = String(rawValue || "");
79
+ const match = text.match(/\$\{\{\s*secrets\.([A-Za-z0-9_]+)\s*\}\}/);
80
+ return match ? String(match[1]).toUpperCase() : "";
81
+ }
82
+
83
+ export function sanitizeSecretName(secretName) {
84
+ const normalized = String(secretName || "")
85
+ .trim()
86
+ .toUpperCase();
87
+ return SECRET_NAME_REGEX.test(normalized) ? normalized : DEFAULT_SCAN_SECRET_NAME;
88
+ }
89
+
90
+ export function inferScanProfile({ specMarkdown, hasE2ETests = "auto", playwrightMode = "auto" } = {}) {
91
+ const specText = String(specMarkdown || "").trim().toLowerCase();
92
+ if (!specText) {
93
+ throw new Error("Spec content is empty. Generate or provide a spec before configuring scan workflow.");
94
+ }
95
+
96
+ const normalizedE2EHint = normalizeChoice(hasE2ETests, SUPPORTED_E2E_HINTS, "has-e2e-tests");
97
+ const normalizedPlaywrightMode = normalizeChoice(
98
+ playwrightMode,
99
+ SUPPORTED_PLAYWRIGHT_MODES,
100
+ "playwright-mode"
101
+ );
102
+
103
+ const inferredHasE2E = hasAnyKeyword(specText, [
104
+ "e2e",
105
+ "end-to-end",
106
+ "playwright",
107
+ "cypress",
108
+ "integration test",
109
+ ]);
110
+ const riskScore = computeRiskScore(specText);
111
+ const deepScanRecommended = riskScore >= 7;
112
+
113
+ const scanMode = deepScanRecommended ? "deep" : "baseline";
114
+ const severityGate = deepScanRecommended ? "P2" : "P1";
115
+
116
+ const hasSupplyChainSignal = hasAnyKeyword(specText, [
117
+ "supply_chain",
118
+ "supply chain",
119
+ "dependency",
120
+ "dependencies",
121
+ "sbom",
122
+ ]);
123
+ const sbomMode = hasSupplyChainSignal ? (deepScanRecommended ? "audit" : "baseline") : "off";
124
+
125
+ let resolvedPlaywrightMode = "off";
126
+ if (normalizedPlaywrightMode !== "auto") {
127
+ resolvedPlaywrightMode = normalizedPlaywrightMode;
128
+ } else if (normalizedE2EHint === "yes") {
129
+ resolvedPlaywrightMode = deepScanRecommended ? "audit" : "baseline";
130
+ } else if (normalizedE2EHint === "auto" && inferredHasE2E) {
131
+ resolvedPlaywrightMode = deepScanRecommended ? "audit" : "baseline";
132
+ }
133
+
134
+ return {
135
+ scanMode,
136
+ severityGate,
137
+ playwrightMode: resolvedPlaywrightMode,
138
+ sbomMode,
139
+ riskScore,
140
+ inferredHasE2E,
141
+ hasE2ETests: normalizedE2EHint,
142
+ };
143
+ }
144
+
145
+ export function buildSecurityReviewWorkflow({ secretName = DEFAULT_SCAN_SECRET_NAME, profile } = {}) {
146
+ if (!profile) {
147
+ throw new Error("Scan profile is required to build workflow config.");
148
+ }
149
+ const normalizedSecret = sanitizeSecretName(secretName);
150
+
151
+ const document = {
152
+ name: "Omar Gate",
153
+ on: {
154
+ pull_request: {
155
+ types: ["opened", "synchronize", "reopened"],
156
+ },
157
+ workflow_dispatch: {
158
+ inputs: {
159
+ scan_mode: {
160
+ description: "Sentinelayer scan profile",
161
+ required: false,
162
+ default: profile.scanMode || "deep",
163
+ type: "choice",
164
+ options: ["deep", "nightly"],
165
+ },
166
+ severity_gate: {
167
+ description: "Severity threshold that blocks merge",
168
+ required: false,
169
+ default: profile.severityGate || "P1",
170
+ type: "choice",
171
+ options: ["P0", "P1", "P2", "none"],
172
+ },
173
+ p2_max_allowed: {
174
+ description: "Maximum allowed P2 findings",
175
+ required: false,
176
+ default: "5",
177
+ type: "string",
178
+ },
179
+ },
180
+ },
181
+ },
182
+ permissions: {
183
+ contents: "read",
184
+ "pull-requests": "write",
185
+ checks: "write",
186
+ "id-token": "write",
187
+ },
188
+ env: {
189
+ FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: "true",
190
+ },
191
+ jobs: {
192
+ omar_gate: {
193
+ name: "Omar Gate",
194
+ "runs-on": "ubuntu-latest",
195
+ "timeout-minutes": 20,
196
+ permissions: {
197
+ contents: "read",
198
+ checks: "write",
199
+ "pull-requests": "write",
200
+ "id-token": "write",
201
+ },
202
+ steps: [
203
+ {
204
+ name: "Checkout",
205
+ uses: CHECKOUT_ACTION_REF,
206
+ },
207
+ {
208
+ name: "Validate Sentinelayer token",
209
+ shell: "bash",
210
+ env: {
211
+ SENTINELAYER_TOKEN: `\${{ secrets.${normalizedSecret} }}`,
212
+ },
213
+ run: [
214
+ 'set -euo pipefail',
215
+ 'if [ -z "${SENTINELAYER_TOKEN}" ]; then',
216
+ ` echo "::warning::${normalizedSecret} not set. Run: gh secret set ${normalizedSecret} --body <token>"`,
217
+ ' echo "Skipping run locally: npx sentinelayer-cli@latest /omargate deep --path ."',
218
+ ' exit 0',
219
+ 'fi',
220
+ ].join("\n"),
221
+ },
222
+ {
223
+ name: "Run Omar Gate",
224
+ id: "omar",
225
+ uses: SENTINELAYER_ACTION_REF,
226
+ with: {
227
+ sentinelayer_token: `\${{ secrets.${normalizedSecret} }}`,
228
+ scan_mode: profile.scanMode || "deep",
229
+ severity_gate: profile.severityGate || "P1",
230
+ playwright_mode: profile.playwrightMode || "off",
231
+ sbom_mode: profile.sbomMode || "off",
232
+ wait_for_completion: "true",
233
+ },
234
+ },
235
+ {
236
+ name: "Enforce merge thresholds",
237
+ shell: "bash",
238
+ env: {
239
+ P0_COUNT: "${{ steps.omar.outputs.p0_count || '0' }}",
240
+ P1_COUNT: "${{ steps.omar.outputs.p1_count || '0' }}",
241
+ P2_COUNT: "${{ steps.omar.outputs.p2_count || '0' }}",
242
+ P2_MAX: "${{ github.event_name == 'workflow_dispatch' && inputs.p2_max_allowed || '5' }}",
243
+ },
244
+ run: [
245
+ 'set -euo pipefail',
246
+ 'p0="$(echo "${P0_COUNT}" | tr -d \'\\r\' | xargs)"',
247
+ 'p1="$(echo "${P1_COUNT}" | tr -d \'\\r\' | xargs)"',
248
+ 'p2="$(echo "${P2_COUNT}" | tr -d \'\\r\' | xargs)"',
249
+ 'p2_max="$(echo "${P2_MAX}" | tr -d \'\\r\' | xargs)"',
250
+ 'if [ "${p0:-0}" -gt 0 ] || [ "${p1:-0}" -gt 0 ]; then',
251
+ ' echo "::error::Omar Gate blocked: P0=${p0}, P1=${p1}"',
252
+ ' exit 1',
253
+ 'fi',
254
+ 'if [ "${p2:-0}" -gt "${p2_max:-5}" ]; then',
255
+ ' echo "::error::Omar Gate blocked: P2=${p2} exceeds max ${p2_max}"',
256
+ ' exit 1',
257
+ 'fi',
258
+ ].join("\n"),
259
+ },
260
+ {
261
+ name: "Omar summary",
262
+ shell: "bash",
263
+ run: [
264
+ 'echo "## Omar Gate" >> "$GITHUB_STEP_SUMMARY"',
265
+ 'echo "- gate: \\`${{ steps.omar.outputs.gate_status }}\\`" >> "$GITHUB_STEP_SUMMARY"',
266
+ 'echo "- findings: P0=${{ steps.omar.outputs.p0_count }} P1=${{ steps.omar.outputs.p1_count }} P2=${{ steps.omar.outputs.p2_count }} P3=${{ steps.omar.outputs.p3_count }}" >> "$GITHUB_STEP_SUMMARY"',
267
+ ].join("\n"),
268
+ },
269
+ ],
270
+ },
271
+ },
272
+ };
273
+
274
+ return YAML.stringify(document, { lineWidth: 0 });
275
+ }
276
+
277
+ export function extractScanActionStep(workflowMarkdown) {
278
+ const parsed = YAML.parse(String(workflowMarkdown || "")) || {};
279
+ const jobs = parsed.jobs && typeof parsed.jobs === "object" ? parsed.jobs : {};
280
+
281
+ for (const [jobId, job] of Object.entries(jobs)) {
282
+ const steps = Array.isArray(job?.steps) ? job.steps : [];
283
+ for (let stepIndex = 0; stepIndex < steps.length; stepIndex += 1) {
284
+ const step = steps[stepIndex] || {};
285
+ const uses = String(step.uses || "").trim();
286
+ if (uses.includes("mrrCarter/sentinelayer-v1-action")) {
287
+ return {
288
+ jobId,
289
+ stepIndex,
290
+ uses,
291
+ with: step.with && typeof step.with === "object" ? step.with : {},
292
+ };
293
+ }
294
+ }
295
+ }
296
+
297
+ return null;
298
+ }
299
+
300
+ export function validateSecurityReviewWorkflow({
301
+ workflowMarkdown,
302
+ expectedProfile,
303
+ expectedSecretName = DEFAULT_SCAN_SECRET_NAME,
304
+ } = {}) {
305
+ if (!expectedProfile) {
306
+ throw new Error("Expected scan profile is required for validation.");
307
+ }
308
+
309
+ const actionStep = extractScanActionStep(workflowMarkdown);
310
+ const expected = {
311
+ action: "mrrCarter/sentinelayer-v1-action",
312
+ scan_mode: normalizeMode(expectedProfile.scanMode, "deep"),
313
+ severity_gate: normalizeSeverityGate(expectedProfile.severityGate),
314
+ playwright_mode: normalizeMode(expectedProfile.playwrightMode, "off"),
315
+ sbom_mode: normalizeMode(expectedProfile.sbomMode, "off"),
316
+ secret_name: sanitizeSecretName(expectedSecretName),
317
+ };
318
+
319
+ if (!actionStep) {
320
+ return {
321
+ aligned: false,
322
+ expected,
323
+ actual: null,
324
+ mismatches: [
325
+ {
326
+ field: "action",
327
+ expected: expected.action,
328
+ actual: "not found",
329
+ message: "Workflow does not include mrrCarter/sentinelayer-v1-action step.",
330
+ },
331
+ ],
332
+ };
333
+ }
334
+
335
+ const withConfig = actionStep.with || {};
336
+ const actual = {
337
+ action: actionStep.uses,
338
+ scan_mode: normalizeMode(withConfig.scan_mode, ""),
339
+ severity_gate: normalizeSeverityGate(withConfig.severity_gate),
340
+ playwright_mode: normalizeMode(withConfig.playwright_mode, "off"),
341
+ sbom_mode: normalizeMode(withConfig.sbom_mode, "off"),
342
+ secret_name: parseSecretReference(withConfig.sentinelayer_token),
343
+ };
344
+
345
+ const mismatches = [];
346
+
347
+ if (actual.scan_mode !== expected.scan_mode) {
348
+ mismatches.push({
349
+ field: "scan_mode",
350
+ expected: expected.scan_mode,
351
+ actual: actual.scan_mode || "(missing)",
352
+ message: "scan_mode does not match spec-derived recommendation.",
353
+ });
354
+ }
355
+ if (actual.severity_gate !== expected.severity_gate) {
356
+ mismatches.push({
357
+ field: "severity_gate",
358
+ expected: expected.severity_gate,
359
+ actual: actual.severity_gate || "(missing)",
360
+ message: "severity_gate does not match spec-derived recommendation.",
361
+ });
362
+ }
363
+ if (actual.playwright_mode !== expected.playwright_mode) {
364
+ mismatches.push({
365
+ field: "playwright_mode",
366
+ expected: expected.playwright_mode,
367
+ actual: actual.playwright_mode || "(missing)",
368
+ message: "playwright_mode does not match e2e/spec profile.",
369
+ });
370
+ }
371
+ if (actual.sbom_mode !== expected.sbom_mode) {
372
+ mismatches.push({
373
+ field: "sbom_mode",
374
+ expected: expected.sbom_mode,
375
+ actual: actual.sbom_mode || "(missing)",
376
+ message: "sbom_mode does not match supply-chain profile.",
377
+ });
378
+ }
379
+ if (actual.secret_name !== expected.secret_name) {
380
+ mismatches.push({
381
+ field: "sentinelayer_token",
382
+ expected: `\${{ secrets.${expected.secret_name} }}`,
383
+ actual: actual.secret_name ? `\${{ secrets.${actual.secret_name} }}` : "(missing)",
384
+ message: "sentinelayer_token secret binding does not match expected secret name.",
385
+ });
386
+ }
387
+
388
+ return {
389
+ aligned: mismatches.length === 0,
390
+ expected,
391
+ actual,
392
+ mismatches,
393
+ location: {
394
+ jobId: actionStep.jobId,
395
+ stepIndex: actionStep.stepIndex,
396
+ },
397
+ };
398
+ }
399
+
400
+ export function buildSecretSetupInstructions(
401
+ secretName = DEFAULT_SCAN_SECRET_NAME,
402
+ { repoSlug = "" } = {}
403
+ ) {
404
+ const normalizedSecret = sanitizeSecretName(secretName);
405
+ const normalizedRepoSlug = String(repoSlug || "").trim();
406
+ const resolvedRepoSlug = REPO_SLUG_REGEX.test(normalizedRepoSlug)
407
+ ? normalizedRepoSlug
408
+ : "<owner/repo>";
409
+ return [
410
+ "Set the Sentinelayer token secret before relying on this workflow in PR checks:",
411
+ `- gh secret set ${normalizedSecret} --repo ${resolvedRepoSlug}`,
412
+ `- Verify secret visibility: gh secret list --repo ${resolvedRepoSlug}`,
413
+ "- Commit and push .github/workflows/omar-gate.yml",
414
+ "- For manual setup: https://sentinelayer.com/docs/getting-started/install-workflow",
415
+ ];
416
+ }
417
+
418
+