sentinelayer-cli 0.4.4 → 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,418 +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
- 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
-
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: ["baseline", "deep", "audit", "full-depth"],
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
+