@praneeth_54/agentdoctor 1.1.1 → 2.0.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/CHANGELOG.md +164 -7
- package/README.md +263 -513
- package/dist/agents/aider/adapter.d.ts +1 -0
- package/dist/agents/aider/adapter.js +1 -0
- package/dist/agents/aider/detector.d.ts +14 -0
- package/dist/agents/aider/detector.js +120 -0
- package/dist/agents/copilot/adapter.d.ts +1 -0
- package/dist/agents/copilot/adapter.js +1 -0
- package/dist/agents/copilot/detector.d.ts +13 -0
- package/dist/agents/copilot/detector.js +113 -0
- package/dist/agents/gemini/adapter.d.ts +1 -0
- package/dist/agents/gemini/adapter.js +1 -0
- package/dist/agents/gemini/detector.d.ts +13 -0
- package/dist/agents/gemini/detector.js +151 -0
- package/dist/agents/registry.js +13 -1
- package/dist/agents/types.d.ts +1 -1
- package/dist/agents/windsurf/adapter.d.ts +1 -0
- package/dist/agents/windsurf/adapter.js +1 -0
- package/dist/agents/windsurf/detector.d.ts +14 -0
- package/dist/agents/windsurf/detector.js +119 -0
- package/dist/architecture/c4.d.ts +22 -0
- package/dist/architecture/c4.js +62 -0
- package/dist/architecture/contract.d.ts +64 -0
- package/dist/architecture/contract.js +373 -0
- package/dist/assurance/change.d.ts +211 -0
- package/dist/assurance/change.js +624 -0
- package/dist/assurance/proof.d.ts +136 -0
- package/dist/assurance/proof.js +338 -0
- package/dist/auth/index.d.ts +81 -0
- package/dist/auth/index.js +130 -0
- package/dist/auth/rbac.d.ts +9 -0
- package/dist/auth/rbac.js +26 -0
- package/dist/cli/commands/architecture.d.ts +6 -0
- package/dist/cli/commands/architecture.js +109 -0
- package/dist/cli/commands/assurance.d.ts +67 -0
- package/dist/cli/commands/assurance.js +210 -0
- package/dist/cli/commands/brain.d.ts +12 -0
- package/dist/cli/commands/brain.js +162 -0
- package/dist/cli/commands/complete.d.ts +23 -0
- package/dist/cli/commands/complete.js +232 -0
- package/dist/cli/commands/explain.js +1 -1
- package/dist/cli/commands/fix.js +22 -2
- package/dist/cli/commands/mcp.d.ts +8 -0
- package/dist/cli/commands/mcp.js +14 -0
- package/dist/cli/commands/platform.d.ts +17 -0
- package/dist/cli/commands/platform.js +195 -0
- package/dist/cli/commands/policy-graph-run.d.ts +40 -0
- package/dist/cli/commands/policy-graph-run.js +200 -0
- package/dist/cli/commands/v2.d.ts +55 -0
- package/dist/cli/commands/v2.js +278 -0
- package/dist/cli/commands/workspace.d.ts +9 -0
- package/dist/cli/commands/workspace.js +82 -0
- package/dist/cli/program.js +1328 -3
- package/dist/constants.d.ts +3 -2
- package/dist/constants.js +5 -1
- package/dist/contracts/adapters.d.ts +7 -0
- package/dist/contracts/adapters.js +60 -0
- package/dist/contracts/index.d.ts +162 -0
- package/dist/contracts/index.js +18 -0
- package/dist/core/baseline/store.d.ts +48 -0
- package/dist/core/baseline/store.js +163 -0
- package/dist/core/brain-cli/service.d.ts +26 -0
- package/dist/core/brain-cli/service.js +175 -0
- package/dist/core/brain-product/init.d.ts +45 -0
- package/dist/core/brain-product/init.js +235 -0
- package/dist/core/changes/analyze.d.ts +41 -0
- package/dist/core/changes/analyze.js +223 -0
- package/dist/core/context-health/analyze.d.ts +15 -0
- package/dist/core/context-health/analyze.js +234 -0
- package/dist/core/fix/apply.d.ts +21 -4
- package/dist/core/fix/apply.js +118 -18
- package/dist/core/fix/backup.d.ts +30 -0
- package/dist/core/fix/backup.js +193 -0
- package/dist/core/fix/plan.d.ts +6 -3
- package/dist/core/fix/plan.js +113 -9
- package/dist/core/fix/render.d.ts +2 -0
- package/dist/core/fix/render.js +36 -21
- package/dist/core/fix/run.js +5 -1
- package/dist/core/fix/safe-target.d.ts +14 -0
- package/dist/core/fix/safe-target.js +81 -0
- package/dist/core/fix/types.d.ts +12 -1
- package/dist/core/fix/types.js +2 -0
- package/dist/core/fix/writers/claude-settings.js +3 -1
- package/dist/core/fix/writers/codex-config.d.ts +3 -0
- package/dist/core/fix/writers/codex-config.js +24 -3
- package/dist/core/fix/writers/cursorignore.js +3 -1
- package/dist/core/fix/writers/simple-ignore.d.ts +16 -0
- package/dist/core/fix/writers/simple-ignore.js +68 -0
- package/dist/core/monorepo/detect.d.ts +13 -0
- package/dist/core/monorepo/detect.js +121 -0
- package/dist/core/rules/build-context.js +22 -3
- package/dist/core/rules/context/generated-directory.js +11 -1
- package/dist/core/rules/context/large-instruction-file.js +6 -0
- package/dist/core/rules/context/large-log-file.js +16 -1
- package/dist/core/rules/ignore.d.ts +11 -1
- package/dist/core/rules/ignore.js +22 -1
- package/dist/core/rules/instructions/empty-instructions.js +7 -0
- package/dist/core/rules/security/env-file-exposure.js +23 -2
- package/dist/core/rules/security/private-key-file.js +1 -1
- package/dist/core/scanner/scan.js +1 -1
- package/dist/core/schemas/validate.d.ts +6 -0
- package/dist/core/schemas/validate.js +62 -0
- package/dist/core/scoring/compute-scores.d.ts +1 -1
- package/dist/core/scoring/compute-scores.js +5 -1
- package/dist/core/scoring/placeholder.d.ts +1 -1
- package/dist/core/scoring/placeholder.js +5 -1
- package/dist/core/secrets/scan.d.ts +29 -0
- package/dist/core/secrets/scan.js +172 -0
- package/dist/coverage/cobertura.d.ts +6 -0
- package/dist/coverage/cobertura.js +52 -0
- package/dist/coverage/istanbul.d.ts +7 -0
- package/dist/coverage/istanbul.js +134 -0
- package/dist/coverage/lcov.d.ts +7 -0
- package/dist/coverage/lcov.js +59 -0
- package/dist/coverage/load.d.ts +9 -0
- package/dist/coverage/load.js +39 -0
- package/dist/coverage/types.d.ts +23 -0
- package/dist/coverage/types.js +5 -0
- package/dist/dashboard/server.d.ts +24 -0
- package/dist/dashboard/server.js +402 -0
- package/dist/enforcement/runner.d.ts +67 -0
- package/dist/enforcement/runner.js +460 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.js +25 -0
- package/dist/integrations/github/pr-analyze.d.ts +28 -0
- package/dist/integrations/github/pr-analyze.js +98 -0
- package/dist/integrations/local-ai/provider.d.ts +45 -0
- package/dist/integrations/local-ai/provider.js +104 -0
- package/dist/intelligence/git/analyze.d.ts +34 -0
- package/dist/intelligence/git/analyze.js +136 -0
- package/dist/intelligence/graph/build.d.ts +15 -0
- package/dist/intelligence/graph/build.js +259 -0
- package/dist/intelligence/graph/incremental.d.ts +68 -0
- package/dist/intelligence/graph/incremental.js +234 -0
- package/dist/intelligence/resolve/imports.d.ts +36 -0
- package/dist/intelligence/resolve/imports.js +245 -0
- package/dist/knowledge/store.d.ts +25 -0
- package/dist/knowledge/store.js +91 -0
- package/dist/languages/go.d.ts +9 -0
- package/dist/languages/go.js +45 -0
- package/dist/languages/index.d.ts +11 -0
- package/dist/languages/index.js +76 -0
- package/dist/languages/php.d.ts +7 -0
- package/dist/languages/php.js +193 -0
- package/dist/languages/python.d.ts +7 -0
- package/dist/languages/python.js +150 -0
- package/dist/languages/types.d.ts +42 -0
- package/dist/languages/types.js +26 -0
- package/dist/languages/typescript.d.ts +3 -0
- package/dist/languages/typescript.js +95 -0
- package/dist/mcp/agentdoctor/server.d.ts +16 -0
- package/dist/mcp/agentdoctor/server.js +67 -0
- package/dist/mcp/brain/session.js +7 -7
- package/dist/mcp/intelligence/handlers.d.ts +16 -0
- package/dist/mcp/intelligence/handlers.js +364 -0
- package/dist/mcp/intelligence/path-safety.d.ts +9 -0
- package/dist/mcp/intelligence/path-safety.js +63 -0
- package/dist/mcp/intelligence/registry.d.ts +8 -0
- package/dist/mcp/intelligence/registry.js +228 -0
- package/dist/ops/health.d.ts +18 -0
- package/dist/ops/health.js +51 -0
- package/dist/platform/ai-quality/analyze.d.ts +9 -0
- package/dist/platform/ai-quality/analyze.js +65 -0
- package/dist/platform/architecture/drift.d.ts +17 -0
- package/dist/platform/architecture/drift.js +74 -0
- package/dist/platform/auth/local.d.ts +15 -0
- package/dist/platform/auth/local.js +58 -0
- package/dist/platform/context-security/analyze.d.ts +6 -0
- package/dist/platform/context-security/analyze.js +97 -0
- package/dist/platform/firewall/evaluate.d.ts +57 -0
- package/dist/platform/firewall/evaluate.js +359 -0
- package/dist/platform/graph/build.d.ts +6 -0
- package/dist/platform/graph/build.js +189 -0
- package/dist/platform/health/analyze.d.ts +7 -0
- package/dist/platform/health/analyze.js +192 -0
- package/dist/platform/index.d.ts +27 -0
- package/dist/platform/index.js +89 -0
- package/dist/platform/knowledge/analyze.d.ts +20 -0
- package/dist/platform/knowledge/analyze.js +96 -0
- package/dist/platform/provenance/build.d.ts +44 -0
- package/dist/platform/provenance/build.js +65 -0
- package/dist/platform/readiness/scorecard.d.ts +5 -0
- package/dist/platform/readiness/scorecard.js +98 -0
- package/dist/platform/refactor/impact.d.ts +20 -0
- package/dist/platform/refactor/impact.js +60 -0
- package/dist/platform/reports/export.d.ts +12 -0
- package/dist/platform/reports/export.js +92 -0
- package/dist/platform/security/redact.d.ts +15 -0
- package/dist/platform/security/redact.js +87 -0
- package/dist/platform/sessions/store.d.ts +32 -0
- package/dist/platform/sessions/store.js +97 -0
- package/dist/platform/store.d.ts +6 -0
- package/dist/platform/store.js +57 -0
- package/dist/platform/test-impact/analyze.d.ts +50 -0
- package/dist/platform/test-impact/analyze.js +350 -0
- package/dist/platform/time-machine/compare.d.ts +17 -0
- package/dist/platform/time-machine/compare.js +62 -0
- package/dist/platform/tokens/plan.d.ts +28 -0
- package/dist/platform/tokens/plan.js +108 -0
- package/dist/platform/types.d.ts +120 -0
- package/dist/platform/types.js +5 -0
- package/dist/plugins/runtime.d.ts +36 -0
- package/dist/plugins/runtime.js +101 -0
- package/dist/plugins/sdk.d.ts +29 -0
- package/dist/plugins/sdk.js +114 -0
- package/dist/policy/compose.d.ts +34 -0
- package/dist/policy/compose.js +118 -0
- package/dist/policy/packs.d.ts +9 -0
- package/dist/policy/packs.js +91 -0
- package/dist/reporters/terminal/report.js +38 -5
- package/dist/security/paths.d.ts +21 -0
- package/dist/security/paths.js +105 -0
- package/dist/storage/postgres.d.ts +26 -0
- package/dist/storage/postgres.js +90 -0
- package/dist/storage/provider.d.ts +30 -0
- package/dist/storage/provider.js +109 -0
- package/dist/storage/sqlite.d.ts +33 -0
- package/dist/storage/sqlite.js +77 -0
- package/dist/team/auth.d.ts +35 -0
- package/dist/team/auth.js +70 -0
- package/dist/types/index.d.ts +5 -1
- package/dist/workspace/index.d.ts +69 -0
- package/dist/workspace/index.js +220 -0
- package/package.json +15 -5
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { evaluateAgentAction, EVALUATE_ONLY } from "../../platform/firewall/evaluate.js";
|
|
2
|
+
import { runControlledCommand } from "../../enforcement/runner.js";
|
|
3
|
+
import { graphBuild, graphRebuild, graphStatus, graphUpdate, } from "../../intelligence/graph/incremental.js";
|
|
4
|
+
import { buildIntelligenceGraph } from "../../intelligence/graph/build.js";
|
|
5
|
+
import { EXIT_CODES } from "../../types/index.js";
|
|
6
|
+
function emit(json, value, human) {
|
|
7
|
+
if (json) {
|
|
8
|
+
process.stdout.write(`${JSON.stringify(value, null, 2)}\n`);
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
process.stdout.write(`${human}\n`);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export async function runGraphSurfaceCommand(options) {
|
|
15
|
+
try {
|
|
16
|
+
const mode = options.mode ?? "auto";
|
|
17
|
+
if (options.action === "status") {
|
|
18
|
+
const status = await graphStatus({ root: options.root });
|
|
19
|
+
emit(Boolean(options.json), status, [
|
|
20
|
+
`Graph index ${status.present ? "present" : "missing"}`,
|
|
21
|
+
` path: ${status.path}`,
|
|
22
|
+
` nodes=${status.nodeCount} edges=${status.edgeCount} files=${status.fileCount}`,
|
|
23
|
+
` builder=${status.builder ?? "n/a"}`,
|
|
24
|
+
` stale=${status.staleFiles.length} missing=${status.missingFiles.length}`,
|
|
25
|
+
status.corrupt ? ` corrupt: ${status.error}` : "",
|
|
26
|
+
]
|
|
27
|
+
.filter(Boolean)
|
|
28
|
+
.join("\n"));
|
|
29
|
+
return EXIT_CODES.SUCCESS;
|
|
30
|
+
}
|
|
31
|
+
if (options.action === "update") {
|
|
32
|
+
const result = await graphUpdate({ root: options.root, mode });
|
|
33
|
+
emit(Boolean(options.json), result, `graph update rebuilt=${result.rebuilt} reason=${result.reason} changed=${result.changedFiles.length} nodes=${result.snapshot.nodes.length}`);
|
|
34
|
+
return EXIT_CODES.SUCCESS;
|
|
35
|
+
}
|
|
36
|
+
if (options.action === "rebuild") {
|
|
37
|
+
const result = await graphRebuild({ root: options.root, mode });
|
|
38
|
+
emit(Boolean(options.json), result, `graph rebuild nodes=${result.snapshot.nodes.length} edges=${result.snapshot.edges.length} builder=${result.snapshot.builder}`);
|
|
39
|
+
return EXIT_CODES.SUCCESS;
|
|
40
|
+
}
|
|
41
|
+
// build / show (backward-compat one-shot)
|
|
42
|
+
if (options.action === "show") {
|
|
43
|
+
const graph = await buildIntelligenceGraph({ root: options.root, mode });
|
|
44
|
+
emit(Boolean(options.json), graph, `graph builder=${graph.builder} nodes=${graph.nodes.length} edges=${graph.edges.length} astFiles=${graph.astFilesParsed}`);
|
|
45
|
+
return EXIT_CODES.SUCCESS;
|
|
46
|
+
}
|
|
47
|
+
const result = await graphBuild({ root: options.root, mode });
|
|
48
|
+
emit(Boolean(options.json), result, `graph build nodes=${result.snapshot.nodes.length} edges=${result.snapshot.edges.length} builder=${result.snapshot.builder} path=${result.path}`);
|
|
49
|
+
return EXIT_CODES.SUCCESS;
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
53
|
+
process.stderr.write(`Error: ${message}\n`);
|
|
54
|
+
return EXIT_CODES.INTERNAL_ERROR;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
export async function runPolicyCheckCommand(options) {
|
|
58
|
+
try {
|
|
59
|
+
const verdict = await evaluateAgentAction(options.root, {
|
|
60
|
+
actionId: `policy-check-${Date.now()}`,
|
|
61
|
+
agentId: "cli",
|
|
62
|
+
timestamp: new Date().toISOString(),
|
|
63
|
+
type: "shell",
|
|
64
|
+
params: { command: options.command },
|
|
65
|
+
repositoryRoot: options.root,
|
|
66
|
+
}, { failClosed: options.failClosed === true });
|
|
67
|
+
emit(Boolean(options.json), { ...verdict, notice: EVALUATE_ONLY }, `policy check decision=${verdict.decision} risk=${verdict.riskLevel}\n ${verdict.reason}\n ${EVALUATE_ONLY}`);
|
|
68
|
+
return EXIT_CODES.SUCCESS;
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
72
|
+
process.stderr.write(`Error: ${message}\n`);
|
|
73
|
+
return EXIT_CODES.INTERNAL_ERROR;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
export async function runPolicyExplainCommand(options) {
|
|
77
|
+
try {
|
|
78
|
+
const verdict = await evaluateAgentAction(options.root, {
|
|
79
|
+
actionId: `policy-explain-${Date.now()}`,
|
|
80
|
+
agentId: "cli",
|
|
81
|
+
timestamp: new Date().toISOString(),
|
|
82
|
+
type: "shell",
|
|
83
|
+
params: { command: options.command },
|
|
84
|
+
repositoryRoot: options.root,
|
|
85
|
+
}, { failClosed: options.failClosed === true });
|
|
86
|
+
const explanation = {
|
|
87
|
+
command: options.command,
|
|
88
|
+
decision: verdict.decision,
|
|
89
|
+
reason: verdict.reason,
|
|
90
|
+
policyId: verdict.policyId ?? null,
|
|
91
|
+
riskLevel: verdict.riskLevel,
|
|
92
|
+
approvalStatus: verdict.approvalStatus,
|
|
93
|
+
executionResult: verdict.executionResult,
|
|
94
|
+
notice: EVALUATE_ONLY,
|
|
95
|
+
meaning: verdict.decision === "allow"
|
|
96
|
+
? "Allowlisted or matched an allow rule — still evaluate-only unless agentdoctor run / enforce --execute is used."
|
|
97
|
+
: verdict.decision === "block" || verdict.decision === "deny-network"
|
|
98
|
+
? "Would be blocked by AgentDoctor-controlled runner if executed through it."
|
|
99
|
+
: "Requires human approval or further policy before controlled execution.",
|
|
100
|
+
};
|
|
101
|
+
emit(Boolean(options.json), explanation, [
|
|
102
|
+
`policy explain: ${options.command}`,
|
|
103
|
+
` decision: ${verdict.decision}`,
|
|
104
|
+
` policyId: ${verdict.policyId ?? "n/a"}`,
|
|
105
|
+
` risk: ${verdict.riskLevel}`,
|
|
106
|
+
` reason: ${verdict.reason}`,
|
|
107
|
+
` ${explanation.meaning}`,
|
|
108
|
+
].join("\n"));
|
|
109
|
+
return EXIT_CODES.SUCCESS;
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
113
|
+
process.stderr.write(`Error: ${message}\n`);
|
|
114
|
+
return EXIT_CODES.INTERNAL_ERROR;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
export async function runPolicyEnforceCommand(options) {
|
|
118
|
+
try {
|
|
119
|
+
const result = await runControlledCommand({
|
|
120
|
+
root: options.root,
|
|
121
|
+
command: options.command,
|
|
122
|
+
executeIfAllowed: options.execute === true,
|
|
123
|
+
failClosed: options.failClosed === true,
|
|
124
|
+
});
|
|
125
|
+
emit(Boolean(options.json), result, [
|
|
126
|
+
`policy enforce decision=${result.decision.decision} status=${result.decision.executionStatus}`,
|
|
127
|
+
` enforced=${result.enforced}`,
|
|
128
|
+
` ${result.notice}`,
|
|
129
|
+
].join("\n"));
|
|
130
|
+
return EXIT_CODES.SUCCESS;
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
134
|
+
process.stderr.write(`Error: ${message}\n`);
|
|
135
|
+
return EXIT_CODES.INTERNAL_ERROR;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
export async function runRunExplainCommand(options) {
|
|
139
|
+
try {
|
|
140
|
+
const { explainControlledRun } = await import("../../enforcement/runner.js");
|
|
141
|
+
const explanation = await explainControlledRun({
|
|
142
|
+
root: options.root,
|
|
143
|
+
command: options.command,
|
|
144
|
+
failClosed: options.failClosed === true,
|
|
145
|
+
useShell: options.shell === true,
|
|
146
|
+
});
|
|
147
|
+
emit(Boolean(options.json), explanation, [
|
|
148
|
+
`run explain: ${explanation.command}`,
|
|
149
|
+
` decision: ${explanation.decision}`,
|
|
150
|
+
` policyId: ${explanation.policyId ?? "n/a"}`,
|
|
151
|
+
` risk: ${explanation.riskLevel}`,
|
|
152
|
+
` wouldExecute: ${explanation.wouldExecute}`,
|
|
153
|
+
` ${explanation.meaning}`,
|
|
154
|
+
` ${explanation.notice}`,
|
|
155
|
+
].join("\n"));
|
|
156
|
+
return EXIT_CODES.SUCCESS;
|
|
157
|
+
}
|
|
158
|
+
catch (error) {
|
|
159
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
160
|
+
process.stderr.write(`Error: ${message}\n`);
|
|
161
|
+
return EXIT_CODES.INTERNAL_ERROR;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
export async function runRunCommand(options) {
|
|
165
|
+
try {
|
|
166
|
+
if (!options.argv.length) {
|
|
167
|
+
process.stderr.write("Error: provide a command after -- (e.g. agentdoctor run -- npm --version)\n");
|
|
168
|
+
return EXIT_CODES.USAGE_ERROR;
|
|
169
|
+
}
|
|
170
|
+
const result = await runControlledCommand({
|
|
171
|
+
root: options.root,
|
|
172
|
+
argv: options.argv,
|
|
173
|
+
executeIfAllowed: true,
|
|
174
|
+
useShell: options.shell === true,
|
|
175
|
+
...(options.timeoutMs !== undefined ? { timeoutMs: options.timeoutMs } : {}),
|
|
176
|
+
failClosed: options.failClosed === true,
|
|
177
|
+
});
|
|
178
|
+
emit(Boolean(options.json), result, [
|
|
179
|
+
`run decision=${result.decision.decision} status=${result.decision.executionStatus}`,
|
|
180
|
+
` exitCode=${result.exitCode ?? "n/a"} durationMs=${result.durationMs ?? "n/a"}`,
|
|
181
|
+
` ${result.notice}`,
|
|
182
|
+
result.stdout ? `--- stdout ---\n${result.stdout}` : "",
|
|
183
|
+
result.stderr ? `--- stderr ---\n${result.stderr}` : "",
|
|
184
|
+
]
|
|
185
|
+
.filter(Boolean)
|
|
186
|
+
.join("\n"));
|
|
187
|
+
if (result.decision.executionStatus === "blocked-by-enforcement") {
|
|
188
|
+
return EXIT_CODES.ISSUES_OR_THRESHOLD;
|
|
189
|
+
}
|
|
190
|
+
if (result.decision.executionStatus === "execution-failed") {
|
|
191
|
+
return EXIT_CODES.INTERNAL_ERROR;
|
|
192
|
+
}
|
|
193
|
+
return EXIT_CODES.SUCCESS;
|
|
194
|
+
}
|
|
195
|
+
catch (error) {
|
|
196
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
197
|
+
process.stderr.write(`Error: ${message}\n`);
|
|
198
|
+
return EXIT_CODES.INTERNAL_ERROR;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { type ExitCode } from "../../types/index.js";
|
|
2
|
+
export declare function runChangesCommand(options: {
|
|
3
|
+
root?: string;
|
|
4
|
+
since?: string;
|
|
5
|
+
impact?: boolean;
|
|
6
|
+
json?: boolean;
|
|
7
|
+
}): Promise<ExitCode>;
|
|
8
|
+
export declare function runContextHealthCommand(options: {
|
|
9
|
+
root?: string;
|
|
10
|
+
json?: boolean;
|
|
11
|
+
}): Promise<ExitCode>;
|
|
12
|
+
export declare function runSecretsCommand(options: {
|
|
13
|
+
root?: string;
|
|
14
|
+
json?: boolean;
|
|
15
|
+
}): Promise<ExitCode>;
|
|
16
|
+
export declare function runFixUndoCommand(options: {
|
|
17
|
+
root?: string;
|
|
18
|
+
auditId: string;
|
|
19
|
+
}): Promise<ExitCode>;
|
|
20
|
+
export declare function runFixHistoryCommand(options: {
|
|
21
|
+
root?: string;
|
|
22
|
+
json?: boolean;
|
|
23
|
+
}): Promise<ExitCode>;
|
|
24
|
+
export declare function runBaselineCommand(options: {
|
|
25
|
+
action: "save" | "list" | "diff" | "delete" | "trends";
|
|
26
|
+
name?: string;
|
|
27
|
+
root?: string;
|
|
28
|
+
json?: boolean;
|
|
29
|
+
}): Promise<ExitCode>;
|
|
30
|
+
export declare function runPackagesCommand(options: {
|
|
31
|
+
root?: string;
|
|
32
|
+
json?: boolean;
|
|
33
|
+
scan?: boolean;
|
|
34
|
+
}): Promise<ExitCode>;
|
|
35
|
+
export declare function runPrReviewCommand(options: {
|
|
36
|
+
root?: string;
|
|
37
|
+
base?: string;
|
|
38
|
+
json?: boolean;
|
|
39
|
+
}): Promise<ExitCode>;
|
|
40
|
+
export declare function runDashboardCommand(options: {
|
|
41
|
+
root?: string;
|
|
42
|
+
host?: string;
|
|
43
|
+
port?: number;
|
|
44
|
+
allowNonLoopback?: boolean;
|
|
45
|
+
}): Promise<ExitCode>;
|
|
46
|
+
export declare function runPluginsCommand(options: {
|
|
47
|
+
root?: string;
|
|
48
|
+
json?: boolean;
|
|
49
|
+
run?: boolean;
|
|
50
|
+
}): Promise<ExitCode>;
|
|
51
|
+
export declare function runLocalAiCommand(options: {
|
|
52
|
+
provider?: string;
|
|
53
|
+
prompt?: string;
|
|
54
|
+
json?: boolean;
|
|
55
|
+
}): Promise<ExitCode>;
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
import { EXIT_CODES } from "../../types/index.js";
|
|
2
|
+
import { resolveRepoRoot } from "../../utils/path.js";
|
|
3
|
+
import { analyzeChanges } from "../../core/changes/analyze.js";
|
|
4
|
+
import { analyzeContextHealth } from "../../core/context-health/analyze.js";
|
|
5
|
+
import { scanSecrets } from "../../core/secrets/scan.js";
|
|
6
|
+
import { listFixAudits, undoFix } from "../../core/fix/backup.js";
|
|
7
|
+
import { baselineFromScan, compareToBaseline, computeBaselineTrends, deleteNamedBaseline, listNamedBaselines, loadNamedBaseline, saveNamedBaseline, } from "../../core/baseline/store.js";
|
|
8
|
+
import { detectMonorepo } from "../../core/monorepo/detect.js";
|
|
9
|
+
import { analyzePullRequest } from "../../integrations/github/pr-analyze.js";
|
|
10
|
+
import { startDashboardServer } from "../../dashboard/server.js";
|
|
11
|
+
import { discoverPlugins } from "../../plugins/sdk.js";
|
|
12
|
+
import { runPluginAnalyzers } from "../../plugins/runtime.js";
|
|
13
|
+
import { createLocalAiProvider, } from "../../integrations/local-ai/provider.js";
|
|
14
|
+
import { scan } from "../../core/scanner/scan.js";
|
|
15
|
+
function printJson(value) {
|
|
16
|
+
process.stdout.write(`${JSON.stringify(value, null, 2)}\n`);
|
|
17
|
+
}
|
|
18
|
+
export async function runChangesCommand(options) {
|
|
19
|
+
const root = resolveRepoRoot(options.root ?? process.cwd());
|
|
20
|
+
const report = await analyzeChanges({
|
|
21
|
+
root,
|
|
22
|
+
...(options.since ? { since: options.since } : {}),
|
|
23
|
+
impact: options.impact === true,
|
|
24
|
+
});
|
|
25
|
+
if (options.json) {
|
|
26
|
+
printJson(report);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
process.stdout.write(`Changes (${report.gitAvailable ? "git" : "no-git"})\n files: ${report.files.length}\n added: ${report.summary.added} modified: ${report.summary.modified} deleted: ${report.summary.deleted}\n`);
|
|
30
|
+
for (const f of report.files.slice(0, 40)) {
|
|
31
|
+
const mods = f.modules?.length ? ` modules=${f.modules.join(",")}` : "";
|
|
32
|
+
process.stdout.write(` ${f.staged ? "S" : " "} ${f.kind.padEnd(10)} ${f.path}${mods}\n`);
|
|
33
|
+
}
|
|
34
|
+
if (report.impact) {
|
|
35
|
+
process.stdout.write(`Impact: ${report.impact.status} — ${report.impact.reason}\n edges: ${report.impact.edges.length}\n`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return EXIT_CODES.SUCCESS;
|
|
39
|
+
}
|
|
40
|
+
export async function runContextHealthCommand(options) {
|
|
41
|
+
const root = resolveRepoRoot(options.root ?? process.cwd());
|
|
42
|
+
const report = await analyzeContextHealth(root);
|
|
43
|
+
if (options.json)
|
|
44
|
+
printJson(report);
|
|
45
|
+
else {
|
|
46
|
+
process.stdout.write(`Context health\n instruction files: ${report.instructionFiles.length}\n conflicts: ${report.conflicts.length}\n`);
|
|
47
|
+
for (const c of report.conflicts) {
|
|
48
|
+
process.stdout.write(` [${c.severity}] ${c.kind}: ${c.message}\n`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return EXIT_CODES.SUCCESS;
|
|
52
|
+
}
|
|
53
|
+
export async function runSecretsCommand(options) {
|
|
54
|
+
const root = resolveRepoRoot(options.root ?? process.cwd());
|
|
55
|
+
const report = await scanSecrets({ root, enabled: true });
|
|
56
|
+
if (options.json)
|
|
57
|
+
printJson(report);
|
|
58
|
+
else {
|
|
59
|
+
process.stdout.write(`Secret scan (opt-in)\n files: ${report.filesScanned}\n findings: ${report.findings.length}\n`);
|
|
60
|
+
for (const f of report.findings.slice(0, 30)) {
|
|
61
|
+
process.stdout.write(` [${f.severity}] ${f.ruleId} ${f.file}:${f.line} ${f.redactedSnippet}\n`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return report.findings.some((f) => f.severity === "critical")
|
|
65
|
+
? EXIT_CODES.ISSUES_OR_THRESHOLD
|
|
66
|
+
: EXIT_CODES.SUCCESS;
|
|
67
|
+
}
|
|
68
|
+
export async function runFixUndoCommand(options) {
|
|
69
|
+
try {
|
|
70
|
+
const record = await undoFix({
|
|
71
|
+
root: resolveRepoRoot(options.root ?? process.cwd()),
|
|
72
|
+
auditId: options.auditId,
|
|
73
|
+
});
|
|
74
|
+
process.stdout.write(`Undid Safe Fix audit ${options.auditId} → undo audit ${record.id}\n`);
|
|
75
|
+
return EXIT_CODES.SUCCESS;
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
console.error(`Error: ${error instanceof Error ? error.message : String(error)}`);
|
|
79
|
+
return EXIT_CODES.INTERNAL_ERROR;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
export async function runFixHistoryCommand(options) {
|
|
83
|
+
const audits = await listFixAudits(resolveRepoRoot(options.root ?? process.cwd()));
|
|
84
|
+
if (options.json)
|
|
85
|
+
printJson({ audits });
|
|
86
|
+
else if (audits.length === 0)
|
|
87
|
+
process.stdout.write("No Safe Fix audits yet.\n");
|
|
88
|
+
else {
|
|
89
|
+
for (const a of audits) {
|
|
90
|
+
process.stdout.write(`${a.id} ${a.mode} ${a.createdAt} entries=${a.entries.length}\n`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return EXIT_CODES.SUCCESS;
|
|
94
|
+
}
|
|
95
|
+
export async function runBaselineCommand(options) {
|
|
96
|
+
const root = resolveRepoRoot(options.root ?? process.cwd());
|
|
97
|
+
try {
|
|
98
|
+
if (options.action === "list") {
|
|
99
|
+
const names = await listNamedBaselines(root);
|
|
100
|
+
if (options.json)
|
|
101
|
+
printJson({ baselines: names });
|
|
102
|
+
else
|
|
103
|
+
process.stdout.write(names.length ? `${names.join("\n")}\n` : "No named baselines.\n");
|
|
104
|
+
return EXIT_CODES.SUCCESS;
|
|
105
|
+
}
|
|
106
|
+
if (options.action === "trends") {
|
|
107
|
+
const trends = await computeBaselineTrends(root);
|
|
108
|
+
if (options.json)
|
|
109
|
+
printJson(trends);
|
|
110
|
+
else if (trends.points.length === 0) {
|
|
111
|
+
process.stdout.write("No baselines for trends.\n");
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
for (const p of trends.points) {
|
|
115
|
+
process.stdout.write(`${p.createdAt} ${p.name} total=${p.counts.total} critical=${p.counts.critical}\n`);
|
|
116
|
+
}
|
|
117
|
+
for (const d of trends.deltas) {
|
|
118
|
+
process.stdout.write(` Δ ${d.from}→${d.to}: total ${d.totalDelta >= 0 ? "+" : ""}${d.totalDelta}, critical ${d.criticalDelta >= 0 ? "+" : ""}${d.criticalDelta}\n`);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return EXIT_CODES.SUCCESS;
|
|
122
|
+
}
|
|
123
|
+
if (options.action === "save") {
|
|
124
|
+
if (!options.name) {
|
|
125
|
+
console.error("Error: --name required");
|
|
126
|
+
return EXIT_CODES.USAGE_ERROR;
|
|
127
|
+
}
|
|
128
|
+
const result = await scan({ cwd: root });
|
|
129
|
+
const baseline = baselineFromScan(options.name, result);
|
|
130
|
+
const file = await saveNamedBaseline(root, baseline);
|
|
131
|
+
process.stdout.write(`Saved baseline ${options.name} → ${file}\n`);
|
|
132
|
+
return EXIT_CODES.SUCCESS;
|
|
133
|
+
}
|
|
134
|
+
if (options.action === "delete") {
|
|
135
|
+
if (!options.name) {
|
|
136
|
+
console.error("Error: --name required");
|
|
137
|
+
return EXIT_CODES.USAGE_ERROR;
|
|
138
|
+
}
|
|
139
|
+
await deleteNamedBaseline(root, options.name);
|
|
140
|
+
process.stdout.write(`Deleted baseline ${options.name}\n`);
|
|
141
|
+
return EXIT_CODES.SUCCESS;
|
|
142
|
+
}
|
|
143
|
+
if (options.action === "diff") {
|
|
144
|
+
if (!options.name) {
|
|
145
|
+
console.error("Error: --name required");
|
|
146
|
+
return EXIT_CODES.USAGE_ERROR;
|
|
147
|
+
}
|
|
148
|
+
const baseline = await loadNamedBaseline(root, options.name);
|
|
149
|
+
if (!baseline) {
|
|
150
|
+
console.error(`Error: baseline not found: ${options.name}`);
|
|
151
|
+
return EXIT_CODES.USAGE_ERROR;
|
|
152
|
+
}
|
|
153
|
+
const result = await scan({ cwd: root });
|
|
154
|
+
const diff = compareToBaseline(baseline, result.findings);
|
|
155
|
+
if (options.json)
|
|
156
|
+
printJson(diff);
|
|
157
|
+
else {
|
|
158
|
+
process.stdout.write(`Baseline ${diff.name}\n added: ${diff.added.length}\n removed: ${diff.removed.length}\n recurring: ${diff.recurring.length}\n unchanged: ${diff.unchanged}\n`);
|
|
159
|
+
}
|
|
160
|
+
return EXIT_CODES.SUCCESS;
|
|
161
|
+
}
|
|
162
|
+
return EXIT_CODES.USAGE_ERROR;
|
|
163
|
+
}
|
|
164
|
+
catch (error) {
|
|
165
|
+
console.error(`Error: ${error instanceof Error ? error.message : String(error)}`);
|
|
166
|
+
return EXIT_CODES.USAGE_ERROR;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
export async function runPackagesCommand(options) {
|
|
170
|
+
const root = resolveRepoRoot(options.root ?? process.cwd());
|
|
171
|
+
const mono = await detectMonorepo(root);
|
|
172
|
+
if (!options.scan) {
|
|
173
|
+
if (options.json)
|
|
174
|
+
printJson(mono);
|
|
175
|
+
else {
|
|
176
|
+
process.stdout.write(`Monorepo: ${mono.isMonorepo ? "yes" : "no"} (${mono.tool})\n packages: ${mono.packages.length}\n`);
|
|
177
|
+
for (const p of mono.packages) {
|
|
178
|
+
process.stdout.write(` - ${p.name} (${p.relativePath})\n`);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return EXIT_CODES.SUCCESS;
|
|
182
|
+
}
|
|
183
|
+
const packageScans = [];
|
|
184
|
+
for (const pkg of mono.packages) {
|
|
185
|
+
const result = await scan({ cwd: pkg.absolutePath });
|
|
186
|
+
packageScans.push({
|
|
187
|
+
name: pkg.name,
|
|
188
|
+
path: pkg.relativePath,
|
|
189
|
+
summary: result.summary,
|
|
190
|
+
overall: result.scores?.overall ?? null,
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
if (options.json)
|
|
194
|
+
printJson({ monorepo: mono, packageScans });
|
|
195
|
+
else {
|
|
196
|
+
for (const p of packageScans) {
|
|
197
|
+
process.stdout.write(`${p.name}: score=${p.overall} findings=${p.summary.total} (c=${p.summary.critical} w=${p.summary.warning})\n`);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return EXIT_CODES.SUCCESS;
|
|
201
|
+
}
|
|
202
|
+
export async function runPrReviewCommand(options) {
|
|
203
|
+
const report = await analyzePullRequest({
|
|
204
|
+
root: resolveRepoRoot(options.root ?? process.cwd()),
|
|
205
|
+
dryRun: true,
|
|
206
|
+
...(options.base ? { baseRef: options.base } : {}),
|
|
207
|
+
});
|
|
208
|
+
if (options.json)
|
|
209
|
+
printJson(report);
|
|
210
|
+
else {
|
|
211
|
+
process.stdout.write(report.commentMarkdown);
|
|
212
|
+
process.stdout.write("\n(posted=false; local dry-run only)\n");
|
|
213
|
+
}
|
|
214
|
+
return EXIT_CODES.SUCCESS;
|
|
215
|
+
}
|
|
216
|
+
export async function runDashboardCommand(options) {
|
|
217
|
+
try {
|
|
218
|
+
const server = await startDashboardServer({
|
|
219
|
+
root: resolveRepoRoot(options.root ?? process.cwd()),
|
|
220
|
+
host: options.host ?? "127.0.0.1",
|
|
221
|
+
port: options.port ?? 8787,
|
|
222
|
+
readOnly: true,
|
|
223
|
+
allowNonLoopback: options.allowNonLoopback === true,
|
|
224
|
+
});
|
|
225
|
+
if (options.allowNonLoopback) {
|
|
226
|
+
process.stderr.write("WARNING: dashboard bound outside loopback with --allow-non-loopback. Local ?user= roles are not authentication.\n");
|
|
227
|
+
}
|
|
228
|
+
process.stdout.write(`AgentDoctor dashboard (read-only) at http://${server.host}:${server.port}/\nLocal ?user= is not authentication. Press Ctrl+C to stop.\n`);
|
|
229
|
+
await new Promise(() => {
|
|
230
|
+
/* keep process alive until signal */
|
|
231
|
+
});
|
|
232
|
+
return EXIT_CODES.SUCCESS;
|
|
233
|
+
}
|
|
234
|
+
catch (error) {
|
|
235
|
+
console.error(`Error: ${error instanceof Error ? error.message : String(error)}`);
|
|
236
|
+
return EXIT_CODES.USAGE_ERROR;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
export async function runPluginsCommand(options) {
|
|
240
|
+
const root = resolveRepoRoot(options.root ?? process.cwd());
|
|
241
|
+
const plugins = await discoverPlugins(root);
|
|
242
|
+
const analyzerResults = options.run ? await runPluginAnalyzers(root) : undefined;
|
|
243
|
+
if (options.json) {
|
|
244
|
+
printJson({ plugins, ...(analyzerResults ? { analyzerResults } : {}) });
|
|
245
|
+
}
|
|
246
|
+
else if (plugins.length === 0) {
|
|
247
|
+
process.stdout.write("No plugins discovered under .agentdoctor/plugins/\n");
|
|
248
|
+
}
|
|
249
|
+
else {
|
|
250
|
+
for (const p of plugins) {
|
|
251
|
+
process.stdout.write(`${p.ok ? "ok" : "ERR"} ${p.manifest.id}@${p.manifest.version} caps=${p.manifest.capabilities.join(",")}\n`);
|
|
252
|
+
for (const e of p.errors)
|
|
253
|
+
process.stdout.write(` ${e}\n`);
|
|
254
|
+
}
|
|
255
|
+
if (analyzerResults) {
|
|
256
|
+
for (const r of analyzerResults) {
|
|
257
|
+
process.stdout.write(`run ${r.ok ? "ok" : "ERR"} ${r.pluginId} notes=${r.notes.length}${r.error ? ` ${r.error}` : ""}\n`);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
return EXIT_CODES.SUCCESS;
|
|
262
|
+
}
|
|
263
|
+
export async function runLocalAiCommand(options) {
|
|
264
|
+
const id = (options.provider ?? "none");
|
|
265
|
+
const provider = createLocalAiProvider(id === "mock" || id === "ollama" || id === "none" ? id : "none");
|
|
266
|
+
const response = await provider.generate({
|
|
267
|
+
prompt: options.prompt ?? "Summarize repository agent readiness.",
|
|
268
|
+
context: [],
|
|
269
|
+
maxTokens: 128,
|
|
270
|
+
timeoutMs: 3000,
|
|
271
|
+
});
|
|
272
|
+
if (options.json)
|
|
273
|
+
printJson(response);
|
|
274
|
+
else {
|
|
275
|
+
process.stdout.write(`provider=${response.provider} aiGenerated=${response.aiGenerated}\n${response.text || response.error || "(empty)"}\n`);
|
|
276
|
+
}
|
|
277
|
+
return EXIT_CODES.SUCCESS;
|
|
278
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { EXIT_CODES } from "../../types/index.js";
|
|
2
|
+
import { addRepositoryToWorkspace, initWorkspace, listWorkspaces, removeWorkspace, workspaceStatus, } from "../../workspace/index.js";
|
|
3
|
+
function emit(json, value, human) {
|
|
4
|
+
if (json) {
|
|
5
|
+
process.stdout.write(`${JSON.stringify(value, null, 2)}\n`);
|
|
6
|
+
}
|
|
7
|
+
else {
|
|
8
|
+
process.stdout.write(`${human}\n`);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export async function runWorkspaceCommand(options) {
|
|
12
|
+
try {
|
|
13
|
+
const controlRoot = options.root;
|
|
14
|
+
switch (options.action) {
|
|
15
|
+
case "init": {
|
|
16
|
+
if (!options.name?.trim()) {
|
|
17
|
+
process.stderr.write("Error: workspace init requires --name\n");
|
|
18
|
+
return EXIT_CODES.USAGE_ERROR;
|
|
19
|
+
}
|
|
20
|
+
const ws = await initWorkspace({
|
|
21
|
+
controlRoot,
|
|
22
|
+
name: options.name,
|
|
23
|
+
...(options.id ? { id: options.id } : {}),
|
|
24
|
+
...(options.repositoryRoot ? { repositoryRoot: options.repositoryRoot } : {}),
|
|
25
|
+
allowCrossRead: options.allowCrossRead === true,
|
|
26
|
+
});
|
|
27
|
+
emit(Boolean(options.json), ws, `workspace init id=${ws.id} name=${ws.name} roots=${ws.repositoryRoots.length} allowCrossRead=${ws.allowCrossRead}`);
|
|
28
|
+
return EXIT_CODES.SUCCESS;
|
|
29
|
+
}
|
|
30
|
+
case "add": {
|
|
31
|
+
if (!options.id?.trim() || !options.repositoryRoot?.trim()) {
|
|
32
|
+
process.stderr.write("Error: workspace add requires --id and --repo\n");
|
|
33
|
+
return EXIT_CODES.USAGE_ERROR;
|
|
34
|
+
}
|
|
35
|
+
const ws = await addRepositoryToWorkspace({
|
|
36
|
+
controlRoot,
|
|
37
|
+
workspaceId: options.id,
|
|
38
|
+
repositoryRoot: options.repositoryRoot,
|
|
39
|
+
});
|
|
40
|
+
emit(Boolean(options.json), ws, `workspace add id=${ws.id} roots=${ws.repositoryRoots.join(", ")}`);
|
|
41
|
+
return EXIT_CODES.SUCCESS;
|
|
42
|
+
}
|
|
43
|
+
case "list": {
|
|
44
|
+
const list = await listWorkspaces(controlRoot);
|
|
45
|
+
emit(Boolean(options.json), { workspaces: list }, list.length === 0
|
|
46
|
+
? "No workspaces under .agentdoctor/workspaces/"
|
|
47
|
+
: list
|
|
48
|
+
.map((w) => `${w.id}\t${w.name}\troots=${w.repositoryRoots.length}\tcrossRead=${w.allowCrossRead}`)
|
|
49
|
+
.join("\n"));
|
|
50
|
+
return EXIT_CODES.SUCCESS;
|
|
51
|
+
}
|
|
52
|
+
case "status": {
|
|
53
|
+
if (!options.id?.trim()) {
|
|
54
|
+
process.stderr.write("Error: workspace status requires --id\n");
|
|
55
|
+
return EXIT_CODES.USAGE_ERROR;
|
|
56
|
+
}
|
|
57
|
+
const status = await workspaceStatus(controlRoot, options.id);
|
|
58
|
+
emit(Boolean(options.json), status, status.ok
|
|
59
|
+
? `workspace ${options.id} ok roots=${status.workspace?.repositoryRoots.length ?? 0}`
|
|
60
|
+
: `workspace ${options.id} ${status.error ?? "degraded"} missing=${status.missingRoots.join(", ") || "none"}`);
|
|
61
|
+
return status.ok ? EXIT_CODES.SUCCESS : EXIT_CODES.ISSUES_OR_THRESHOLD;
|
|
62
|
+
}
|
|
63
|
+
case "remove": {
|
|
64
|
+
if (!options.id?.trim()) {
|
|
65
|
+
process.stderr.write("Error: workspace remove requires --id\n");
|
|
66
|
+
return EXIT_CODES.USAGE_ERROR;
|
|
67
|
+
}
|
|
68
|
+
const removed = await removeWorkspace(controlRoot, options.id);
|
|
69
|
+
emit(Boolean(options.json), { removed, id: options.id }, removed ? `workspace removed ${options.id}` : `workspace not found ${options.id}`);
|
|
70
|
+
return removed ? EXIT_CODES.SUCCESS : EXIT_CODES.ISSUES_OR_THRESHOLD;
|
|
71
|
+
}
|
|
72
|
+
default:
|
|
73
|
+
process.stderr.write("Error: unknown workspace action\n");
|
|
74
|
+
return EXIT_CODES.USAGE_ERROR;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
79
|
+
process.stderr.write(`Error: ${message}\n`);
|
|
80
|
+
return EXIT_CODES.INTERNAL_ERROR;
|
|
81
|
+
}
|
|
82
|
+
}
|