sentinelayer-cli 0.1.0 → 0.1.1

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.
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "sentinelayer-cli",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Scaffold Sentinelayer spec/prompt/guide artifacts with secure browser auth and token bootstrap.",
5
5
  "type": "module",
6
6
  "scripts": {
7
- "check": "node --check bin/sentinelayer-cli.js && node --check bin/create-sentinelayer.js && node --check bin/sl.js && node --check src/cli.js && node --check src/legacy-cli.js && node --check src/commands/config.js && node --check src/commands/ingest.js && node --check src/commands/spec.js && node --check src/commands/prompt.js && node --check src/commands/scan.js && node --check src/commands/guide.js && node --check src/commands/cost.js && node --check src/commands/telemetry.js && node --check src/commands/auth.js && node --check src/commands/watch.js && node --check src/commands/mcp.js && node --check src/commands/plugin.js && node --check src/commands/ai.js && node --check src/commands/review.js && node --check src/commands/chat.js && node --check src/commands/policy.js && node --check src/commands/swarm.js && node --check src/commands/daemon.js && node --check src/commands/audit.js && node --check src/config/service.js && node --check src/ingest/engine.js && node --check src/spec/generator.js && node --check src/spec/regenerate.js && node --check src/spec/templates.js && node --check src/prompt/generator.js && node --check src/scan/generator.js && node --check src/guide/generator.js && node --check src/cost/tracker.js && node --check src/cost/history.js && node --check src/cost/budget.js && node --check src/ai/client.js && node --check src/ai/aidenid.js && node --check src/ai/identity-store.js && node --check src/ai/domain-target-store.js && node --check src/ai/site-store.js && node --check src/review/local-review.js && node --check src/review/ai-review.js && node --check src/review/report.js && node --check src/review/replay.js && node --check src/audit/registry.js && node --check src/audit/orchestrator.js && node --check src/audit/package.js && node --check src/audit/replay.js && node --check src/audit/agents/security.js && node --check src/audit/agents/architecture.js && node --check src/audit/agents/testing.js && node --check src/audit/agents/performance.js && node --check src/audit/agents/compliance.js && node --check src/audit/agents/documentation.js && node --check src/swarm/registry.js && node --check src/swarm/factory.js && node --check src/swarm/runtime.js && node --check src/swarm/scenario-dsl.js && node --check src/swarm/dashboard.js && node --check src/swarm/report.js && node --check src/swarm/pentest.js && node --check src/daemon/error-worker.js && node --check src/daemon/assignment-ledger.js && node --check src/daemon/jira-lifecycle.js && node --check src/daemon/budget-governor.js && node --check src/daemon/operator-control.js && node --check src/daemon/artifact-lineage.js && node --check src/daemon/ast-parser-layer.js && node --check src/daemon/callgraph-overlay.js && node --check src/daemon/hybrid-mapper.js && node --check src/daemon/reliability-lane.js && node --check src/daemon/watchdog.js && node --check src/telemetry/ledger.js && node --check src/auth/http.js && node --check src/auth/session-store.js && node --check src/auth/service.js && node --check src/mcp/registry.js && node --check src/memory/blackboard.js && node --check src/memory/retrieval.js && node --check src/plugin/manifest.js && node --check src/policy/packs.js && node --check src/ui/markdown.js && node --check src/ui/progress.js && node --check src/agents/jules/tools/file-read.js && node --check src/agents/jules/tools/grep.js && node --check src/agents/jules/tools/glob.js && node --check src/agents/jules/tools/shell.js && node --check src/agents/jules/tools/file-edit.js && node --check src/agents/jules/tools/dispatch.js && node --check src/agents/jules/tools/index.js && node --check src/agents/jules/tools/frontend-analyze.js && node --check src/agents/jules/swarm/sub-agent.js && node --check src/agents/jules/swarm/file-scanner.js && node --check src/agents/jules/swarm/pattern-hunter.js && node --check src/agents/jules/swarm/index.js && node --check src/agents/jules/swarm/orchestrator.js && node --check src/agents/jules/config/definition.js && node --check src/agents/jules/loop.js && node --check src/agents/jules/stream.js && node --check src/agents/jules/fix-cycle.js && node --check src/agents/jules/error-intake.js && node --check src/agents/jules/tools/runtime-audit.js && node --check src/agents/jules/config/system-prompt.js && node --check src/agents/jules/tools/auth-audit.js",
7
+ "check": "node --check bin/sentinelayer-cli.js && node --check bin/create-sentinelayer.js && node --check bin/sl.js && node --check src/cli.js && node --check src/legacy-cli.js && node --check src/commands/config.js && node --check src/commands/ingest.js && node --check src/commands/spec.js && node --check src/commands/prompt.js && node --check src/commands/scan.js && node --check src/commands/guide.js && node --check src/commands/cost.js && node --check src/commands/telemetry.js && node --check src/commands/auth.js && node --check src/commands/watch.js && node --check src/commands/mcp.js && node --check src/commands/plugin.js && node --check src/commands/ai.js && node --check src/commands/review.js && node --check src/commands/chat.js && node --check src/commands/policy.js && node --check src/commands/swarm.js && node --check src/commands/daemon.js && node --check src/commands/audit.js && node --check src/config/service.js && node --check src/ingest/engine.js && node --check src/spec/generator.js && node --check src/spec/regenerate.js && node --check src/spec/templates.js && node --check src/prompt/generator.js && node --check src/scan/generator.js && node --check src/guide/generator.js && node --check src/cost/tracker.js && node --check src/cost/history.js && node --check src/cost/budget.js && node --check src/ai/client.js && node --check src/ai/aidenid.js && node --check src/ai/identity-store.js && node --check src/ai/domain-target-store.js && node --check src/ai/site-store.js && node --check src/review/local-review.js && node --check src/review/ai-review.js && node --check src/review/report.js && node --check src/review/replay.js && node --check src/audit/registry.js && node --check src/audit/orchestrator.js && node --check src/audit/package.js && node --check src/audit/replay.js && node --check src/audit/agents/security.js && node --check src/audit/agents/architecture.js && node --check src/audit/agents/testing.js && node --check src/audit/agents/performance.js && node --check src/audit/agents/compliance.js && node --check src/audit/agents/documentation.js && node --check src/swarm/registry.js && node --check src/swarm/factory.js && node --check src/swarm/runtime.js && node --check src/swarm/scenario-dsl.js && node --check src/swarm/dashboard.js && node --check src/swarm/report.js && node --check src/swarm/pentest.js && node --check src/daemon/error-worker.js && node --check src/daemon/assignment-ledger.js && node --check src/daemon/jira-lifecycle.js && node --check src/daemon/budget-governor.js && node --check src/daemon/operator-control.js && node --check src/daemon/artifact-lineage.js && node --check src/daemon/ast-parser-layer.js && node --check src/daemon/callgraph-overlay.js && node --check src/daemon/hybrid-mapper.js && node --check src/daemon/reliability-lane.js && node --check src/daemon/watchdog.js && node --check src/telemetry/ledger.js && node --check src/auth/http.js && node --check src/auth/session-store.js && node --check src/auth/service.js && node --check src/mcp/registry.js && node --check src/memory/blackboard.js && node --check src/memory/retrieval.js && node --check src/plugin/manifest.js && node --check src/policy/packs.js && node --check src/ui/markdown.js && node --check src/ui/progress.js && node --check src/agents/jules/tools/file-read.js && node --check src/agents/jules/tools/grep.js && node --check src/agents/jules/tools/glob.js && node --check src/agents/jules/tools/shell.js && node --check src/agents/jules/tools/file-edit.js && node --check src/agents/jules/tools/dispatch.js && node --check src/agents/jules/tools/index.js && node --check src/agents/jules/tools/frontend-analyze.js && node --check src/agents/jules/swarm/sub-agent.js && node --check src/agents/jules/swarm/file-scanner.js && node --check src/agents/jules/swarm/pattern-hunter.js && node --check src/agents/jules/swarm/index.js && node --check src/agents/jules/swarm/orchestrator.js && node --check src/agents/jules/config/definition.js && node --check src/agents/jules/loop.js && node --check src/agents/jules/stream.js && node --check src/agents/jules/fix-cycle.js && node --check src/agents/jules/error-intake.js && node --check src/agents/jules/tools/runtime-audit.js && node --check src/agents/jules/config/system-prompt.js && node --check src/agents/jules/tools/auth-audit.js && node --check src/auth/gate.js",
8
8
  "test": "npm run test:unit && npm run test:e2e",
9
9
  "test:unit": "node --test tests/unit*.test.mjs",
10
10
  "test:e2e": "node --test tests/e2e.test.mjs",
@@ -18,7 +18,7 @@ const LIGHTHOUSE_TIMEOUT_MS = 120000;
18
18
  * @param {{ operation: string, url?: string, path?: string }} input
19
19
  * @returns {object} Structured result per operation
20
20
  */
21
- export function runtimeAudit(input) {
21
+ export async function runtimeAudit(input) {
22
22
  if (!RUNTIME_OPS.has(input.operation)) {
23
23
  throw new RuntimeAuditError(
24
24
  "Unknown operation: " + input.operation + ". Valid: " + [...RUNTIME_OPS].join(", "),
@@ -49,7 +49,7 @@ const RUNTIME_DISPATCH = {
49
49
  * Run Lighthouse via npx (no install required).
50
50
  * Returns performance, accessibility, best-practices, SEO scores + key metrics.
51
51
  */
52
- function lighthouseScan(input) {
52
+ async function lighthouseScan(input) {
53
53
  const url = input.url;
54
54
  if (!url) {
55
55
  throw new RuntimeAuditError("lighthouse_scan requires a url parameter");
@@ -58,6 +58,13 @@ function lighthouseScan(input) {
58
58
  throw new RuntimeAuditError("Invalid URL: " + url);
59
59
  }
60
60
 
61
+ // Prefer SentinelLayer API scanner (authenticated, server-side Lighthouse).
62
+ // Falls back to local npx lighthouse if API unavailable.
63
+ try {
64
+ const apiResult = await callScannerApi(url);
65
+ if (apiResult.available) return apiResult;
66
+ } catch { /* API unavailable — fall back to local */ }
67
+
61
68
  try {
62
69
  const outputPath = path.join(
63
70
  input.path || process.cwd(),
@@ -76,6 +83,7 @@ function lighthouseScan(input) {
76
83
  encoding: "utf-8",
77
84
  timeout: LIGHTHOUSE_TIMEOUT_MS,
78
85
  stdio: ["pipe", "pipe", "pipe"],
86
+ shell: true, // Windows: npx is npx.cmd, needs shell resolution
79
87
  });
80
88
 
81
89
  if (!fs.existsSync(outputPath)) {
@@ -401,6 +409,82 @@ function sanitizeUrlForShell(url) {
401
409
  }
402
410
  }
403
411
 
412
+ /**
413
+ * Call the SentinelLayer API scanner endpoint for server-side Lighthouse.
414
+ * Requires authenticated session (token from sl auth login).
415
+ * Returns structured result or throws if unavailable.
416
+ */
417
+ async function callScannerApi(url) {
418
+ let session;
419
+ try {
420
+ const { readStoredSession } = await import("../../../auth/session-store.js");
421
+ session = await readStoredSession();
422
+ } catch { /* session read failed */ }
423
+
424
+ if (!session || !session.token) {
425
+ return { available: false, reason: "Not authenticated — run sl auth login" };
426
+ }
427
+
428
+ const apiUrl = session.apiUrl || "https://api.sentinelayer.com";
429
+ const scanEndpoint = apiUrl + "/api/v1/scan/url";
430
+
431
+ // Submit scan
432
+ const submitResponse = await fetch(scanEndpoint, {
433
+ method: "POST",
434
+ headers: {
435
+ "Content-Type": "application/json",
436
+ "Authorization": "Bearer " + session.token,
437
+ },
438
+ body: JSON.stringify({ url, scan_type: "lighthouse" }),
439
+ signal: AbortSignal.timeout(15000),
440
+ });
441
+
442
+ if (!submitResponse.ok) {
443
+ return { available: false, reason: "Scanner API returned " + submitResponse.status };
444
+ }
445
+
446
+ const submitData = await submitResponse.json();
447
+ const scanId = submitData.scan_id || submitData.id;
448
+ if (!scanId) {
449
+ return { available: false, reason: "Scanner did not return scan_id" };
450
+ }
451
+
452
+ // Poll for completion (max 90s)
453
+ const pollUrl = apiUrl + "/api/v1/scan/url/" + scanId;
454
+ for (let attempt = 0; attempt < 30; attempt++) {
455
+ await new Promise(r => setTimeout(r, 3000));
456
+ try {
457
+ const pollResponse = await fetch(pollUrl, {
458
+ headers: { "Authorization": "Bearer " + session.token },
459
+ signal: AbortSignal.timeout(10000),
460
+ });
461
+ if (!pollResponse.ok) continue;
462
+ const pollData = await pollResponse.json();
463
+ if (pollData.status === "completed" || pollData.status === "complete") {
464
+ const scores = pollData.scores || pollData.lighthouse_scores || {};
465
+ return {
466
+ available: true,
467
+ source: "sentinelayer-api",
468
+ scanId,
469
+ reportPath: null,
470
+ scores: {
471
+ performance: scores.performance ?? null,
472
+ accessibility: scores.accessibility ?? null,
473
+ bestPractices: scores.best_practices ?? scores.bestPractices ?? null,
474
+ seo: scores.seo ?? null,
475
+ },
476
+ metrics: pollData.metrics || {},
477
+ opportunities: pollData.opportunities || [],
478
+ };
479
+ }
480
+ if (pollData.status === "failed" || pollData.status === "error") {
481
+ return { available: false, reason: "Scanner reported failure: " + (pollData.error || pollData.status) };
482
+ }
483
+ } catch { /* poll failed, retry */ }
484
+ }
485
+ return { available: false, reason: "Scanner timed out after 90s" };
486
+ }
487
+
404
488
  export class RuntimeAuditError extends Error {
405
489
  constructor(message) {
406
490
  super(message);
@@ -0,0 +1,92 @@
1
+ import process from "node:process";
2
+ import pc from "picocolors";
3
+ import { readStoredSession } from "./session-store.js";
4
+
5
+ /**
6
+ * Auth gate — ensures user is logged in before running any command.
7
+ *
8
+ * Commands that bypass auth:
9
+ * - auth login, auth status, auth --help
10
+ * - --help, --version, -h, -v
11
+ * - config (read-only config inspection)
12
+ *
13
+ * All other commands require a valid session.
14
+ * If not authenticated, prints instructions and exits.
15
+ */
16
+
17
+ const AUTH_BYPASS_COMMANDS = new Set([
18
+ "auth", // auth subcommands handle their own auth
19
+ "--help",
20
+ "-h",
21
+ "--version",
22
+ "-v",
23
+ ]);
24
+
25
+ // Commands that work without auth (read-only, no API calls)
26
+ const NO_AUTH_REQUIRED = new Set([
27
+ "config", // local config inspection
28
+ ]);
29
+
30
+ /**
31
+ * Check if the current command requires authentication.
32
+ * Returns true if auth is required but user is not logged in.
33
+ *
34
+ * @param {string[]} args - CLI arguments (after normalization)
35
+ * @returns {Promise<{ authenticated: boolean, session: object|null, bypassReason: string|null }>}
36
+ */
37
+ export async function checkAuthGate(args) {
38
+ const first = String(args[0] || "").trim().toLowerCase();
39
+
40
+ // Bypass commands
41
+ if (!first || AUTH_BYPASS_COMMANDS.has(first)) {
42
+ return { authenticated: true, session: null, bypassReason: "auth_bypass_command" };
43
+ }
44
+
45
+ if (NO_AUTH_REQUIRED.has(first)) {
46
+ return { authenticated: true, session: null, bypassReason: "no_auth_required" };
47
+ }
48
+
49
+ // CI/test bypass — allows automated testing without auth
50
+ if (process.env.SENTINELAYER_CLI_SKIP_AUTH === "1" || process.env.CI === "true") {
51
+ return { authenticated: true, session: null, bypassReason: "env_bypass" };
52
+ }
53
+
54
+ // Check for stored session
55
+ try {
56
+ const session = await readStoredSession();
57
+ if (session && session.token) {
58
+ // Check if token is expired
59
+ if (session.tokenExpiresAt) {
60
+ const expiresAt = new Date(session.tokenExpiresAt).getTime();
61
+ if (expiresAt < Date.now()) {
62
+ return { authenticated: false, session: null, bypassReason: null };
63
+ }
64
+ }
65
+ return { authenticated: true, session, bypassReason: null };
66
+ }
67
+ } catch {
68
+ // Session read failed — treat as not authenticated
69
+ }
70
+
71
+ return { authenticated: false, session: null, bypassReason: null };
72
+ }
73
+
74
+ /**
75
+ * Print auth required message and exit.
76
+ */
77
+ export function printAuthRequired() {
78
+ console.error("");
79
+ console.error(pc.bold(pc.red("Authentication required.")));
80
+ console.error("");
81
+ console.error(" Log in to SentinelLayer to use CLI commands:");
82
+ console.error("");
83
+ console.error(" " + pc.cyan("sl auth login"));
84
+ console.error("");
85
+ console.error(" This opens your browser to authenticate via GitHub or Google.");
86
+ console.error(" Your session is encrypted and stored locally.");
87
+ console.error("");
88
+ console.error(" " + pc.gray("Why? All CLI operations sync to your SentinelLayer account —"));
89
+ console.error(" " + pc.gray("audit reports, findings, cost tracking, and run history."));
90
+ console.error("");
91
+ process.exitCode = 1;
92
+ }
package/src/cli.js CHANGED
@@ -230,6 +230,14 @@ export async function runCli(rawArgs = process.argv.slice(2)) {
230
230
  // Normalize slash commands (/omargate → omargate, /audit → audit, etc.)
231
231
  const normalizedArgs = normalizeSlashArgs(rawArgs);
232
232
 
233
+ // Auth gate — require login for all commands except auth/help/version/config
234
+ const { checkAuthGate, printAuthRequired } = await import("./auth/gate.js");
235
+ const authResult = await checkAuthGate(normalizedArgs);
236
+ if (!authResult.authenticated) {
237
+ printAuthRequired();
238
+ return;
239
+ }
240
+
233
241
  if (shouldBypassCommander(normalizedArgs)) {
234
242
  await runLegacyCliWithErrorHandling(normalizedArgs);
235
243
  return;