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.
- package/README.md +996 -996
- package/bin/create-sentinelayer.js +5 -5
- package/bin/sentinelayer-cli.js +4 -4
- package/bin/sl.js +5 -5
- package/package.json +62 -54
- package/src/agents/jules/config/definition.js +209 -209
- package/src/agents/jules/config/system-prompt.js +175 -175
- package/src/agents/jules/error-intake.js +51 -51
- package/src/agents/jules/fix-cycle.js +377 -377
- package/src/agents/jules/loop.js +367 -367
- package/src/agents/jules/pulse.js +319 -319
- package/src/agents/jules/stream.js +186 -186
- package/src/agents/jules/swarm/file-scanner.js +74 -74
- package/src/agents/jules/swarm/index.js +11 -11
- package/src/agents/jules/swarm/orchestrator.js +362 -362
- package/src/agents/jules/swarm/pattern-hunter.js +123 -123
- package/src/agents/jules/swarm/sub-agent.js +308 -308
- package/src/agents/jules/tools/auth-audit.js +226 -222
- package/src/agents/jules/tools/dispatch.js +327 -327
- package/src/agents/jules/tools/file-edit.js +180 -180
- package/src/agents/jules/tools/file-read.js +100 -100
- package/src/agents/jules/tools/frontend-analyze.js +570 -570
- package/src/agents/jules/tools/glob.js +168 -168
- package/src/agents/jules/tools/grep.js +228 -228
- package/src/agents/jules/tools/index.js +29 -29
- package/src/agents/jules/tools/path-guards.js +161 -161
- package/src/agents/jules/tools/runtime-audit.js +493 -493
- package/src/agents/jules/tools/shell.js +383 -383
- package/src/ai/aidenid.js +972 -945
- package/src/ai/client.js +508 -508
- package/src/ai/domain-target-store.js +268 -268
- package/src/ai/identity-store.js +270 -270
- package/src/ai/site-store.js +145 -145
- package/src/audit/agents/architecture.js +180 -180
- package/src/audit/agents/compliance.js +179 -179
- package/src/audit/agents/documentation.js +165 -165
- package/src/audit/agents/performance.js +145 -145
- package/src/audit/agents/security.js +215 -215
- package/src/audit/agents/testing.js +172 -172
- package/src/audit/orchestrator.js +557 -557
- package/src/audit/package.js +204 -204
- package/src/audit/registry.js +284 -284
- package/src/audit/replay.js +103 -103
- package/src/auth/http.js +113 -113
- package/src/auth/service.js +891 -848
- package/src/auth/session-store.js +359 -345
- package/src/cli.js +252 -252
- package/src/commands/ai/identity-lifecycle.js +1338 -1337
- package/src/commands/ai/provision-governance.js +1272 -1246
- package/src/commands/ai/shared.js +147 -147
- package/src/commands/ai.js +11 -11
- package/src/commands/apply.js +12 -12
- package/src/commands/audit.js +1166 -1147
- package/src/commands/auth.js +375 -366
- package/src/commands/chat.js +191 -191
- package/src/commands/config.js +184 -184
- package/src/commands/cost.js +311 -311
- package/src/commands/daemon/core.js +850 -850
- package/src/commands/daemon/extended.js +1048 -1048
- package/src/commands/daemon/shared.js +213 -213
- package/src/commands/daemon.js +11 -11
- package/src/commands/guide.js +174 -174
- package/src/commands/ingest.js +58 -58
- package/src/commands/init.js +55 -55
- package/src/commands/legacy-args.js +10 -10
- package/src/commands/mcp.js +461 -404
- package/src/commands/omargate.js +15 -15
- package/src/commands/persona.js +20 -20
- package/src/commands/plugin.js +260 -260
- package/src/commands/policy.js +132 -132
- package/src/commands/prompt.js +238 -238
- package/src/commands/review.js +704 -704
- package/src/commands/scan.js +866 -788
- package/src/commands/spec.js +716 -716
- package/src/commands/swarm.js +651 -651
- package/src/commands/telemetry.js +202 -202
- package/src/commands/watch.js +510 -510
- package/src/config/agent-dictionary.js +182 -182
- package/src/config/io.js +56 -56
- package/src/config/paths.js +18 -18
- package/src/config/schema.js +55 -55
- package/src/config/service.js +184 -184
- package/src/cost/budget.js +235 -235
- package/src/cost/history.js +188 -188
- package/src/cost/tracker.js +171 -171
- package/src/daemon/artifact-lineage.js +534 -534
- package/src/daemon/assignment-ledger.js +770 -770
- package/src/daemon/ast-parser-layer.js +258 -258
- package/src/daemon/budget-governor.js +633 -633
- package/src/daemon/callgraph-overlay.js +646 -646
- package/src/daemon/error-worker.js +626 -626
- package/src/daemon/hybrid-mapper.js +929 -929
- package/src/daemon/ingest-refresh.js +195 -0
- package/src/daemon/jira-lifecycle.js +632 -632
- package/src/daemon/operator-control.js +657 -657
- package/src/daemon/reliability-lane.js +471 -471
- package/src/daemon/watchdog.js +971 -971
- package/src/guide/generator.js +316 -316
- package/src/ingest/engine.js +918 -918
- package/src/interactive/action-menu.js +132 -0
- package/src/interactive/auto-ingest.js +111 -0
- package/src/interactive/index.js +95 -0
- package/src/interactive/workspace.js +92 -0
- package/src/legacy-cli.js +2548 -2435
- package/src/mcp/registry.js +695 -695
- package/src/memory/blackboard.js +301 -301
- package/src/memory/retrieval.js +581 -581
- package/src/plugin/manifest.js +553 -553
- package/src/policy/packs.js +144 -144
- package/src/prompt/generator.js +118 -106
- package/src/review/ai-review.js +669 -669
- package/src/review/local-review.js +1284 -1284
- package/src/review/replay.js +235 -235
- package/src/review/report.js +664 -664
- package/src/review/spec-binding.js +487 -487
- package/src/scaffold/generator.js +67 -0
- package/src/scaffold/templates.js +150 -0
- package/src/scan/generator.js +418 -351
- package/src/scan/gh-secrets.js +107 -0
- package/src/spec/generator.js +519 -519
- package/src/spec/regenerate.js +237 -237
- package/src/spec/templates.js +91 -91
- package/src/swarm/dashboard.js +247 -247
- package/src/swarm/factory.js +363 -363
- package/src/swarm/pentest.js +934 -934
- package/src/swarm/registry.js +419 -419
- package/src/swarm/report.js +158 -158
- package/src/swarm/runtime.js +576 -576
- package/src/swarm/scenario-dsl.js +272 -272
- package/src/telemetry/ledger.js +302 -302
- package/src/telemetry/session-tracker.js +118 -0
- package/src/telemetry/sync.js +190 -0
- package/src/ui/markdown.js +220 -220
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import prompts from "prompts";
|
|
2
|
+
import pc from "picocolors";
|
|
3
|
+
|
|
4
|
+
import { PERSONA_VISUALS, listPersonaIds } from "../agents/jules/config/definition.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Interactive action menu — presented after ingest completes.
|
|
8
|
+
* Arrow-key navigation for primary actions + submenus.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Present the main action menu.
|
|
13
|
+
*
|
|
14
|
+
* @returns {Promise<{ action: string, subAction?: string, input?: string }>}
|
|
15
|
+
*/
|
|
16
|
+
export async function showActionMenu() {
|
|
17
|
+
const response = await prompts({
|
|
18
|
+
type: "select",
|
|
19
|
+
name: "action",
|
|
20
|
+
message: "What would you like to do?",
|
|
21
|
+
choices: [
|
|
22
|
+
{ title: pc.red("🔍 Audit"), value: "audit", description: "Run security + quality audit (baseline + personas)" },
|
|
23
|
+
{ title: pc.yellow("📝 Review"), value: "review", description: "Quick review of current changes" },
|
|
24
|
+
{ title: pc.green("🏗️ Add Feature"), value: "feature", description: "Describe a feature and generate spec + prompt" },
|
|
25
|
+
{ title: pc.blue("🆕 Create Project"), value: "create", description: "Scaffold a new project with spec + Omar Gate" },
|
|
26
|
+
{ title: pc.gray("⚙️ More options..."), value: "more", description: "Config, cost, telemetry, watch, plugins" },
|
|
27
|
+
],
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
if (!response.action) return { action: "exit" };
|
|
31
|
+
|
|
32
|
+
// Route to submenu
|
|
33
|
+
if (response.action === "audit") return showAuditMenu();
|
|
34
|
+
if (response.action === "review") return showReviewMenu();
|
|
35
|
+
if (response.action === "feature") return showFeaturePrompt();
|
|
36
|
+
if (response.action === "more") return showMoreMenu();
|
|
37
|
+
|
|
38
|
+
return { action: response.action };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Audit submenu — all 13 personas + full audit.
|
|
43
|
+
*/
|
|
44
|
+
async function showAuditMenu() {
|
|
45
|
+
const personaIds = listPersonaIds();
|
|
46
|
+
const choices = [
|
|
47
|
+
{
|
|
48
|
+
title: pc.bold("🎯 Full Audit (all 13 personas in parallel)"),
|
|
49
|
+
value: { action: "audit", subAction: "deep" },
|
|
50
|
+
description: "Omar baseline → 13 specialist agents → reconciliation",
|
|
51
|
+
},
|
|
52
|
+
];
|
|
53
|
+
|
|
54
|
+
for (const id of personaIds) {
|
|
55
|
+
const visual = PERSONA_VISUALS[id];
|
|
56
|
+
if (!visual) continue;
|
|
57
|
+
choices.push({
|
|
58
|
+
title: (visual.avatar || "") + " " + visual.fullName + pc.gray(" (" + id + ")"),
|
|
59
|
+
value: { action: "audit", subAction: id },
|
|
60
|
+
description: visual.specialty ? visual.specialty.slice(0, 80) : visual.domain || id,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const response = await prompts({
|
|
65
|
+
type: "select",
|
|
66
|
+
name: "choice",
|
|
67
|
+
message: "Which audit?",
|
|
68
|
+
choices,
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
return response.choice || { action: "exit" };
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Review submenu.
|
|
76
|
+
*/
|
|
77
|
+
async function showReviewMenu() {
|
|
78
|
+
const response = await prompts({
|
|
79
|
+
type: "select",
|
|
80
|
+
name: "choice",
|
|
81
|
+
message: "Review mode?",
|
|
82
|
+
choices: [
|
|
83
|
+
{ title: "📋 Full review", value: { action: "review", subAction: "full" }, description: "Scan entire codebase (22-rule deterministic + AI)" },
|
|
84
|
+
{ title: "📝 Diff review", value: { action: "review", subAction: "diff" }, description: "Review only uncommitted changes" },
|
|
85
|
+
{ title: "📌 Staged review", value: { action: "review", subAction: "staged" }, description: "Review only staged files" },
|
|
86
|
+
],
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
return response.choice || { action: "exit" };
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Feature description prompt.
|
|
94
|
+
*/
|
|
95
|
+
async function showFeaturePrompt() {
|
|
96
|
+
const response = await prompts({
|
|
97
|
+
type: "text",
|
|
98
|
+
name: "description",
|
|
99
|
+
message: "Describe the feature you want to add:",
|
|
100
|
+
validate: v => (v && v.trim().length > 5) ? true : "Please describe the feature (at least a few words)",
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
if (!response.description) return { action: "exit" };
|
|
104
|
+
|
|
105
|
+
return {
|
|
106
|
+
action: "feature",
|
|
107
|
+
input: response.description.trim(),
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* More options submenu.
|
|
113
|
+
*/
|
|
114
|
+
async function showMoreMenu() {
|
|
115
|
+
const response = await prompts({
|
|
116
|
+
type: "select",
|
|
117
|
+
name: "choice",
|
|
118
|
+
message: "More options:",
|
|
119
|
+
choices: [
|
|
120
|
+
{ title: "📊 Cost & usage summary", value: { action: "cost" }, description: "View token usage and cost tracking" },
|
|
121
|
+
{ title: "📈 Telemetry", value: { action: "telemetry" }, description: "View run event telemetry" },
|
|
122
|
+
{ title: "⚙️ Config", value: { action: "config" }, description: "View and edit configuration" },
|
|
123
|
+
{ title: "👤 Auth status", value: { action: "auth-status" }, description: "Check authentication" },
|
|
124
|
+
{ title: "🔌 Plugins", value: { action: "plugins" }, description: "List installed plugins" },
|
|
125
|
+
{ title: "📡 Watch events", value: { action: "watch" }, description: "Stream runtime events" },
|
|
126
|
+
{ title: "🤖 AI identity", value: { action: "ai" }, description: "AIdenID provisioning" },
|
|
127
|
+
{ title: "🐛 Daemon status", value: { action: "daemon" }, description: "Error queue and budget status" },
|
|
128
|
+
],
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
return response.choice || { action: "exit" };
|
|
132
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import pc from "picocolors";
|
|
4
|
+
|
|
5
|
+
import { collectCodebaseIngest, generateCodebaseIngest } from "../ingest/engine.js";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Auto-ingest with live progress output.
|
|
9
|
+
*
|
|
10
|
+
* Checks if CODEBASE_INGEST.json exists and is fresh.
|
|
11
|
+
* If stale or missing, runs ingest with real-time status updates.
|
|
12
|
+
* Returns the ingest result.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
const STALE_THRESHOLD_MS = 300_000; // 5 minutes
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Check if ingest exists and is fresh enough.
|
|
19
|
+
*
|
|
20
|
+
* @param {string} targetPath - Repository root
|
|
21
|
+
* @returns {{ exists: boolean, stale: boolean, age: number|null, path: string }}
|
|
22
|
+
*/
|
|
23
|
+
export function checkIngestFreshness(targetPath) {
|
|
24
|
+
const ingestPath = path.join(targetPath, ".sentinelayer", "CODEBASE_INGEST.json");
|
|
25
|
+
if (!fs.existsSync(ingestPath)) {
|
|
26
|
+
return { exists: false, stale: true, age: null, path: ingestPath };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
const stat = fs.statSync(ingestPath);
|
|
31
|
+
const age = Date.now() - stat.mtimeMs;
|
|
32
|
+
return {
|
|
33
|
+
exists: true,
|
|
34
|
+
stale: age > STALE_THRESHOLD_MS,
|
|
35
|
+
age,
|
|
36
|
+
path: ingestPath,
|
|
37
|
+
};
|
|
38
|
+
} catch {
|
|
39
|
+
return { exists: false, stale: true, age: null, path: ingestPath };
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Run auto-ingest with live progress output to stderr.
|
|
45
|
+
* If ingest exists and is fresh, reads from cache.
|
|
46
|
+
* Otherwise runs full ingest with status updates.
|
|
47
|
+
*
|
|
48
|
+
* @param {string} targetPath
|
|
49
|
+
* @param {object} [options]
|
|
50
|
+
* @param {boolean} [options.force] - Force re-ingest even if fresh
|
|
51
|
+
* @param {boolean} [options.quiet] - Suppress progress output
|
|
52
|
+
* @returns {Promise<object>} Ingest result
|
|
53
|
+
*/
|
|
54
|
+
export async function autoIngestWithProgress(targetPath, options = {}) {
|
|
55
|
+
const freshness = checkIngestFreshness(targetPath);
|
|
56
|
+
|
|
57
|
+
if (freshness.exists && !freshness.stale && !options.force) {
|
|
58
|
+
if (!options.quiet) {
|
|
59
|
+
const ageSec = Math.floor((freshness.age || 0) / 1000);
|
|
60
|
+
process.stderr.write(pc.gray("Using cached ingest (" + ageSec + "s old)\n"));
|
|
61
|
+
}
|
|
62
|
+
try {
|
|
63
|
+
const cached = JSON.parse(fs.readFileSync(freshness.path, "utf-8"));
|
|
64
|
+
return cached;
|
|
65
|
+
} catch { /* fall through to re-ingest */ }
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Run ingest with progress
|
|
69
|
+
if (!options.quiet) {
|
|
70
|
+
process.stderr.write(pc.cyan("⟳") + " Indexing codebase...\n");
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const startMs = Date.now();
|
|
74
|
+
|
|
75
|
+
if (!options.quiet) {
|
|
76
|
+
process.stderr.write(pc.gray(" ├─ Scanning files and directories\n"));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
let ingest;
|
|
80
|
+
try {
|
|
81
|
+
ingest = await generateCodebaseIngest({
|
|
82
|
+
rootPath: targetPath,
|
|
83
|
+
outputDir: path.join(targetPath, ".sentinelayer"),
|
|
84
|
+
refresh: true,
|
|
85
|
+
});
|
|
86
|
+
} catch {
|
|
87
|
+
ingest = await collectCodebaseIngest({ rootPath: targetPath });
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const durationMs = Date.now() - startMs;
|
|
91
|
+
|
|
92
|
+
if (!options.quiet) {
|
|
93
|
+
const files = ingest?.summary?.filesScanned || 0;
|
|
94
|
+
const loc = ingest?.summary?.totalLoc || 0;
|
|
95
|
+
const surfaces = (ingest?.riskSurfaces || []).length;
|
|
96
|
+
const frameworks = (ingest?.frameworks || []).join(", ") || "none";
|
|
97
|
+
|
|
98
|
+
process.stderr.write(pc.gray(" ├─ Building AST + import graph\n"));
|
|
99
|
+
process.stderr.write(pc.gray(" ├─ Assigning domain surfaces\n"));
|
|
100
|
+
process.stderr.write(pc.gray(" └─ ") + pc.green("Done") + pc.gray(" (" + (durationMs / 1000).toFixed(1) + "s)\n"));
|
|
101
|
+
process.stderr.write("\n");
|
|
102
|
+
process.stderr.write(pc.bold(" Codebase Summary\n"));
|
|
103
|
+
process.stderr.write(pc.gray(" Files: ") + pc.white(String(files)) + "\n");
|
|
104
|
+
process.stderr.write(pc.gray(" LOC: ") + pc.white(String(loc)) + "\n");
|
|
105
|
+
process.stderr.write(pc.gray(" Frameworks: ") + pc.white(frameworks) + "\n");
|
|
106
|
+
process.stderr.write(pc.gray(" Risk surfaces: ") + pc.white(String(surfaces)) + "\n");
|
|
107
|
+
process.stderr.write("\n");
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return ingest;
|
|
111
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import pc from "picocolors";
|
|
2
|
+
import { selectRepo } from "./workspace.js";
|
|
3
|
+
import { autoIngestWithProgress } from "./auto-ingest.js";
|
|
4
|
+
import { showActionMenu } from "./action-menu.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Interactive CLI mode — the "sl" experience with no args.
|
|
8
|
+
*
|
|
9
|
+
* Flow:
|
|
10
|
+
* 1. Detect repos in workspace → select if multiple
|
|
11
|
+
* 2. Auto-ingest with live progress
|
|
12
|
+
* 3. Present action menu
|
|
13
|
+
* 4. Route to the selected command
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Run the interactive flow.
|
|
18
|
+
*
|
|
19
|
+
* @param {object} [options]
|
|
20
|
+
* @param {function} [options.executeCommand] - Command executor (receives action + args)
|
|
21
|
+
* @returns {Promise<void>}
|
|
22
|
+
*/
|
|
23
|
+
export async function runInteractiveMode(options = {}) {
|
|
24
|
+
console.error("");
|
|
25
|
+
console.error(pc.bold(" SentinelLayer CLI") + pc.gray(" — security-first development platform"));
|
|
26
|
+
console.error("");
|
|
27
|
+
|
|
28
|
+
// Step 1: Repo selection
|
|
29
|
+
const repo = await selectRepo();
|
|
30
|
+
if (!repo) {
|
|
31
|
+
console.error(pc.yellow("No repository selected. Run sl --help for available commands."));
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Step 2: Auto-ingest
|
|
36
|
+
const ingest = await autoIngestWithProgress(repo.path);
|
|
37
|
+
|
|
38
|
+
// Step 3: Action menu
|
|
39
|
+
const choice = await showActionMenu();
|
|
40
|
+
if (choice.action === "exit") {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Step 4: Route to command
|
|
45
|
+
console.error("");
|
|
46
|
+
if (options.executeCommand) {
|
|
47
|
+
await options.executeCommand(choice, repo, ingest);
|
|
48
|
+
} else {
|
|
49
|
+
// Print the equivalent CLI command for the user
|
|
50
|
+
const cmd = buildEquivalentCommand(choice, repo);
|
|
51
|
+
if (cmd) {
|
|
52
|
+
console.error(pc.gray(" Equivalent command: ") + pc.cyan(cmd));
|
|
53
|
+
console.error("");
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Build the equivalent CLI command string for a menu choice.
|
|
60
|
+
*/
|
|
61
|
+
function buildEquivalentCommand(choice, repo) {
|
|
62
|
+
const pathFlag = " --path " + repo.path;
|
|
63
|
+
|
|
64
|
+
switch (choice.action) {
|
|
65
|
+
case "audit":
|
|
66
|
+
if (choice.subAction === "deep") return "sl audit" + pathFlag + " --json";
|
|
67
|
+
return "sl audit " + choice.subAction + pathFlag + " --stream";
|
|
68
|
+
case "review":
|
|
69
|
+
if (choice.subAction === "diff") return "sl review scan --mode diff" + pathFlag + " --json";
|
|
70
|
+
if (choice.subAction === "staged") return "sl review scan --mode staged" + pathFlag + " --json";
|
|
71
|
+
return "sl review scan --mode full" + pathFlag + " --json";
|
|
72
|
+
case "feature":
|
|
73
|
+
return "sl spec generate --description \"" + (choice.input || "").slice(0, 50) + "...\"" + pathFlag;
|
|
74
|
+
case "create":
|
|
75
|
+
return "sl init";
|
|
76
|
+
case "cost":
|
|
77
|
+
return "sl cost show" + pathFlag + " --json";
|
|
78
|
+
case "telemetry":
|
|
79
|
+
return "sl telemetry show" + pathFlag + " --json";
|
|
80
|
+
case "config":
|
|
81
|
+
return "sl config list --json";
|
|
82
|
+
case "auth-status":
|
|
83
|
+
return "sl auth status --json";
|
|
84
|
+
case "plugins":
|
|
85
|
+
return "sl plugin list --json";
|
|
86
|
+
case "watch":
|
|
87
|
+
return "sl watch history" + pathFlag + " --json";
|
|
88
|
+
case "ai":
|
|
89
|
+
return "sl ai provision-email --json";
|
|
90
|
+
case "daemon":
|
|
91
|
+
return "sl daemon budget status" + pathFlag + " --json";
|
|
92
|
+
default:
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import prompts from "prompts";
|
|
4
|
+
import pc from "picocolors";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Multi-repo workspace detection + interactive repo selection.
|
|
8
|
+
*
|
|
9
|
+
* Scans the current directory and parent for git repositories.
|
|
10
|
+
* If multiple found, presents arrow-key selector.
|
|
11
|
+
* If single found, auto-selects it.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Detect git repositories in the workspace.
|
|
16
|
+
* Scans cwd and one level up for directories containing .git.
|
|
17
|
+
*
|
|
18
|
+
* @param {string} [startPath] - Starting directory (default: cwd)
|
|
19
|
+
* @returns {{ repos: Array<{name, path, isCurrentDir}>, parentDir: string }}
|
|
20
|
+
*/
|
|
21
|
+
export function detectRepos(startPath) {
|
|
22
|
+
const cwd = path.resolve(startPath || process.cwd());
|
|
23
|
+
const parentDir = path.dirname(cwd);
|
|
24
|
+
const repos = [];
|
|
25
|
+
|
|
26
|
+
// Check if cwd itself is a git repo
|
|
27
|
+
if (fs.existsSync(path.join(cwd, ".git"))) {
|
|
28
|
+
repos.push({
|
|
29
|
+
name: path.basename(cwd),
|
|
30
|
+
path: cwd,
|
|
31
|
+
isCurrentDir: true,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Scan parent directory for sibling repos
|
|
36
|
+
try {
|
|
37
|
+
const siblings = fs.readdirSync(parentDir, { withFileTypes: true });
|
|
38
|
+
for (const entry of siblings) {
|
|
39
|
+
if (!entry.isDirectory()) continue;
|
|
40
|
+
const siblingPath = path.join(parentDir, entry.name);
|
|
41
|
+
if (siblingPath === cwd) continue; // skip self (already added if it's a repo)
|
|
42
|
+
if (fs.existsSync(path.join(siblingPath, ".git"))) {
|
|
43
|
+
repos.push({
|
|
44
|
+
name: entry.name,
|
|
45
|
+
path: siblingPath,
|
|
46
|
+
isCurrentDir: false,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
} catch { /* parent unreadable — only current dir */ }
|
|
51
|
+
|
|
52
|
+
return { repos, parentDir };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Interactive repo selector.
|
|
57
|
+
* If single repo: auto-selects.
|
|
58
|
+
* If multiple: presents arrow-key menu.
|
|
59
|
+
* If none: returns null.
|
|
60
|
+
*
|
|
61
|
+
* @param {object} [options]
|
|
62
|
+
* @param {string} [options.startPath]
|
|
63
|
+
* @returns {Promise<{name, path}|null>}
|
|
64
|
+
*/
|
|
65
|
+
export async function selectRepo(options = {}) {
|
|
66
|
+
const { repos } = detectRepos(options.startPath);
|
|
67
|
+
|
|
68
|
+
if (repos.length === 0) {
|
|
69
|
+
console.error(pc.yellow("No git repositories found in this workspace."));
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (repos.length === 1) {
|
|
74
|
+
console.error(pc.gray("Repository: " + repos[0].name + " (" + repos[0].path + ")"));
|
|
75
|
+
return repos[0];
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Multiple repos — present selection
|
|
79
|
+
console.error(pc.bold("Multiple repositories detected:"));
|
|
80
|
+
const response = await prompts({
|
|
81
|
+
type: "select",
|
|
82
|
+
name: "repo",
|
|
83
|
+
message: "Which repository?",
|
|
84
|
+
choices: repos.map(r => ({
|
|
85
|
+
title: r.name + (r.isCurrentDir ? pc.gray(" (current)") : ""),
|
|
86
|
+
value: r,
|
|
87
|
+
description: r.path,
|
|
88
|
+
})),
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
return response.repo || null;
|
|
92
|
+
}
|