@praneeth_54/agentdoctor 2.0.0 → 2.1.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/CHANGELOG.md +141 -4
- package/README.md +329 -153
- package/dist/agent/approvals.d.ts +24 -0
- package/dist/agent/approvals.js +64 -0
- package/dist/agent/chat/index.d.ts +7 -0
- package/dist/agent/chat/index.js +5 -0
- package/dist/agent/chat/memory.d.ts +44 -0
- package/dist/agent/chat/memory.js +103 -0
- package/dist/agent/chat/project-summary.d.ts +16 -0
- package/dist/agent/chat/project-summary.js +70 -0
- package/dist/agent/chat/prompts.d.ts +6 -0
- package/dist/agent/chat/prompts.js +39 -0
- package/dist/agent/chat/response.d.ts +19 -0
- package/dist/agent/chat/response.js +109 -0
- package/dist/agent/chat/service.d.ts +42 -0
- package/dist/agent/chat/service.js +252 -0
- package/dist/agent/chat/types.d.ts +48 -0
- package/dist/agent/chat/types.js +1 -0
- package/dist/agent/context/retrieve.d.ts +21 -0
- package/dist/agent/context/retrieve.js +117 -0
- package/dist/agent/context/truth.d.ts +6 -0
- package/dist/agent/context/truth.js +19 -0
- package/dist/agent/context/types.d.ts +23 -0
- package/dist/agent/context/types.js +4 -0
- package/dist/agent/index.d.ts +26 -0
- package/dist/agent/index.js +14 -0
- package/dist/agent/loop.d.ts +51 -0
- package/dist/agent/loop.js +222 -0
- package/dist/agent/modes.d.ts +18 -0
- package/dist/agent/modes.js +102 -0
- package/dist/agent/plan.d.ts +30 -0
- package/dist/agent/plan.js +121 -0
- package/dist/agent/runtime.d.ts +67 -0
- package/dist/agent/runtime.js +180 -0
- package/dist/agent/state.d.ts +30 -0
- package/dist/agent/state.js +95 -0
- package/dist/agent/student.d.ts +56 -0
- package/dist/agent/student.js +230 -0
- package/dist/agent/tools/execute.d.ts +18 -0
- package/dist/agent/tools/execute.js +355 -0
- package/dist/agent/tools/index.d.ts +6 -0
- package/dist/agent/tools/index.js +5 -0
- package/dist/agent/tools/registry.d.ts +7 -0
- package/dist/agent/tools/registry.js +212 -0
- package/dist/agent/tools/run.d.ts +24 -0
- package/dist/agent/tools/run.js +44 -0
- package/dist/agent/tools/types.d.ts +32 -0
- package/dist/agent/tools/types.js +10 -0
- package/dist/agent/tools/write.d.ts +24 -0
- package/dist/agent/tools/write.js +121 -0
- package/dist/agent/verify.d.ts +29 -0
- package/dist/agent/verify.js +210 -0
- package/dist/ai/config.d.ts +22 -0
- package/dist/ai/config.js +68 -0
- package/dist/ai/index.d.ts +17 -0
- package/dist/ai/index.js +52 -0
- package/dist/ai/providers/mock.d.ts +20 -0
- package/dist/ai/providers/mock.js +84 -0
- package/dist/ai/providers/none.d.ts +6 -0
- package/dist/ai/providers/none.js +23 -0
- package/dist/ai/providers/openai-compatible.d.ts +21 -0
- package/dist/ai/providers/openai-compatible.js +151 -0
- package/dist/ai/redact.d.ts +8 -0
- package/dist/ai/redact.js +21 -0
- package/dist/ai/types.d.ts +71 -0
- package/dist/ai/types.js +6 -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/agent.d.ts +27 -0
- package/dist/cli/commands/agent.js +153 -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/chat.d.ts +14 -0
- package/dist/cli/commands/chat.js +155 -0
- package/dist/cli/commands/complete.js +2 -2
- package/dist/cli/commands/learn.d.ts +12 -0
- package/dist/cli/commands/learn.js +107 -0
- package/dist/cli/commands/platform.d.ts +2 -0
- package/dist/cli/commands/platform.js +5 -1
- 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/workspace.d.ts +9 -0
- package/dist/cli/commands/workspace.js +82 -0
- package/dist/cli/program.js +627 -17
- package/dist/constants.d.ts +1 -1
- package/dist/constants.js +1 -1
- package/dist/contracts/index.d.ts +1 -1
- package/dist/contracts/index.js +2 -2
- package/dist/core/brain-product/init.js +5 -2
- package/dist/core/secrets/scan.d.ts +7 -1
- package/dist/core/secrets/scan.js +9 -9
- 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 +7 -1
- package/dist/dashboard/server.js +110 -6
- package/dist/enforcement/runner.d.ts +52 -3
- package/dist/enforcement/runner.js +467 -16
- package/dist/index.d.ts +36 -2
- package/dist/index.js +23 -2
- package/dist/intelligence/graph/build.d.ts +2 -0
- package/dist/intelligence/graph/build.js +49 -5
- 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/languages/go.d.ts +9 -0
- package/dist/languages/go.js +50 -0
- package/dist/languages/index.d.ts +11 -0
- package/dist/languages/index.js +76 -0
- package/dist/languages/php.d.ts +8 -0
- package/dist/languages/php.js +202 -0
- package/dist/languages/python.d.ts +11 -0
- package/dist/languages/python.js +180 -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/agent/registry.d.ts +13 -0
- package/dist/mcp/agent/registry.js +234 -0
- package/dist/mcp/agentdoctor/server.js +8 -1
- package/dist/mcp/intelligence/handlers.d.ts +5 -0
- package/dist/mcp/intelligence/handlers.js +229 -40
- package/dist/mcp/intelligence/path-safety.d.ts +2 -4
- package/dist/mcp/intelligence/path-safety.js +25 -44
- package/dist/mcp/intelligence/registry.d.ts +1 -1
- package/dist/mcp/intelligence/registry.js +69 -1
- package/dist/platform/firewall/evaluate.d.ts +6 -3
- package/dist/platform/firewall/evaluate.js +66 -15
- package/dist/platform/graph/build.js +19 -23
- package/dist/platform/health/analyze.js +23 -17
- package/dist/platform/index.js +2 -0
- package/dist/platform/test-impact/analyze.d.ts +21 -3
- package/dist/platform/test-impact/analyze.js +214 -28
- package/dist/platform/tokens/plan.js +39 -20
- package/dist/platform/types.d.ts +9 -0
- package/dist/policy/compose.d.ts +34 -0
- package/dist/policy/compose.js +118 -0
- package/dist/policy/packs.js +33 -1
- package/dist/security/paths.d.ts +21 -0
- package/dist/security/paths.js +133 -0
- package/dist/storage/postgres.d.ts +26 -0
- package/dist/storage/postgres.js +90 -0
- package/dist/storage/provider.d.ts +2 -7
- package/dist/storage/provider.js +22 -16
- package/dist/storage/sqlite.d.ts +33 -0
- package/dist/storage/sqlite.js +77 -0
- package/dist/team/auth.js +1 -1
- package/dist/workspace/index.d.ts +69 -0
- package/dist/workspace/index.js +220 -0
- package/package.json +9 -3
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Role-based access control for AgentDoctor surfaces.
|
|
3
|
+
* Not enterprise SSO — roles are applied after a verified identity (local session or OIDC JWT).
|
|
4
|
+
*/
|
|
5
|
+
export const RBAC_ROLE_RANK = {
|
|
6
|
+
viewer: 1,
|
|
7
|
+
developer: 2,
|
|
8
|
+
reviewer: 3,
|
|
9
|
+
"policy-admin": 4,
|
|
10
|
+
admin: 5,
|
|
11
|
+
};
|
|
12
|
+
const PERMISSION_MIN_ROLE = {
|
|
13
|
+
"read-findings": "viewer",
|
|
14
|
+
"read-audit": "viewer",
|
|
15
|
+
"export-reports": "developer",
|
|
16
|
+
"approve-actions": "reviewer",
|
|
17
|
+
"manage-policies": "policy-admin",
|
|
18
|
+
"admin-settings": "admin",
|
|
19
|
+
};
|
|
20
|
+
export function hasRbacPermission(role, permission) {
|
|
21
|
+
const required = PERMISSION_MIN_ROLE[permission];
|
|
22
|
+
return (RBAC_ROLE_RANK[role] ?? 0) >= (RBAC_ROLE_RANK[required] ?? 99);
|
|
23
|
+
}
|
|
24
|
+
export function roleAtLeast(role, required) {
|
|
25
|
+
return (RBAC_ROLE_RANK[role] ?? 0) >= (RBAC_ROLE_RANK[required] ?? 99);
|
|
26
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type ExitCode } from "../../types/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* agentdoctor plan — produce an implementation plan (no writes unless --apply elsewhere).
|
|
4
|
+
*/
|
|
5
|
+
export declare function runPlanCommand(options: {
|
|
6
|
+
goal: string;
|
|
7
|
+
root?: string;
|
|
8
|
+
json?: boolean;
|
|
9
|
+
approve?: boolean;
|
|
10
|
+
}): Promise<ExitCode>;
|
|
11
|
+
/**
|
|
12
|
+
* agentdoctor agent — inspect, plan, and (with --approve) mutate via controlled tools.
|
|
13
|
+
*/
|
|
14
|
+
export declare function runAgentCommand(options: {
|
|
15
|
+
root?: string;
|
|
16
|
+
goal?: string;
|
|
17
|
+
tool?: string;
|
|
18
|
+
toolArgs?: Record<string, unknown>;
|
|
19
|
+
listTools?: boolean;
|
|
20
|
+
json?: boolean;
|
|
21
|
+
approve?: boolean;
|
|
22
|
+
apply?: boolean;
|
|
23
|
+
/** JSON array of {name, arguments} for deterministic apply */
|
|
24
|
+
applyOpsJson?: string;
|
|
25
|
+
verify?: boolean;
|
|
26
|
+
runTests?: boolean;
|
|
27
|
+
}): Promise<ExitCode>;
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { approvePlan, buildAgentPlan, formatAgentPlan } from "../../agent/plan.js";
|
|
2
|
+
import { evaluateApproval, formatApprovalPrompt } from "../../agent/approvals.js";
|
|
3
|
+
import { runCodingLoop } from "../../agent/loop.js";
|
|
4
|
+
import { executeAgentTool, getToolSpec, listAgentToolSpecs, newToolCall, } from "../../agent/tools/index.js";
|
|
5
|
+
import { EXIT_CODES } from "../../types/index.js";
|
|
6
|
+
import { resolveRepoRoot } from "../../utils/path.js";
|
|
7
|
+
import { colors } from "../../utils/colors.js";
|
|
8
|
+
/**
|
|
9
|
+
* agentdoctor plan — produce an implementation plan (no writes unless --apply elsewhere).
|
|
10
|
+
*/
|
|
11
|
+
export async function runPlanCommand(options) {
|
|
12
|
+
const root = resolveRepoRoot(options.root ?? process.cwd());
|
|
13
|
+
const plan = await buildAgentPlan({ root, goal: options.goal });
|
|
14
|
+
if (options.approve) {
|
|
15
|
+
const approved = approvePlan(plan, true);
|
|
16
|
+
if (options.json) {
|
|
17
|
+
process.stdout.write(`${JSON.stringify({ ...approved, note: "Approval recorded; use agent --apply to mutate" }, null, 2)}\n`);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
process.stdout.write(formatAgentPlan(approved));
|
|
21
|
+
process.stdout.write(`${colors.yellow('\nApproval recorded. Use: agentdoctor agent --goal "..." --approve --apply\n')}\n`);
|
|
22
|
+
}
|
|
23
|
+
return EXIT_CODES.SUCCESS;
|
|
24
|
+
}
|
|
25
|
+
if (options.json) {
|
|
26
|
+
process.stdout.write(`${JSON.stringify(plan, null, 2)}\n`);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
process.stdout.write(formatAgentPlan(plan));
|
|
30
|
+
}
|
|
31
|
+
return EXIT_CODES.SUCCESS;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* agentdoctor agent — inspect, plan, and (with --approve) mutate via controlled tools.
|
|
35
|
+
*/
|
|
36
|
+
export async function runAgentCommand(options) {
|
|
37
|
+
const root = resolveRepoRoot(options.root ?? process.cwd());
|
|
38
|
+
const approvedByHuman = options.approve === true;
|
|
39
|
+
if (options.listTools) {
|
|
40
|
+
const tools = listAgentToolSpecs({ includeWrite: true, includeExecute: true });
|
|
41
|
+
if (options.json) {
|
|
42
|
+
process.stdout.write(`${JSON.stringify(tools, null, 2)}\n`);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
process.stdout.write(`\n${colors.bold("AgentDoctor tools")}\n\n`);
|
|
46
|
+
for (const t of tools) {
|
|
47
|
+
process.stdout.write(` [${t.risk}] ${t.name} (${t.category}) — ${t.description}\n`);
|
|
48
|
+
}
|
|
49
|
+
process.stdout.write("\n");
|
|
50
|
+
}
|
|
51
|
+
return EXIT_CODES.SUCCESS;
|
|
52
|
+
}
|
|
53
|
+
if (options.tool) {
|
|
54
|
+
const name = options.tool;
|
|
55
|
+
const spec = getToolSpec(name);
|
|
56
|
+
if (!spec) {
|
|
57
|
+
process.stderr.write(`Unknown tool: ${name}\n`);
|
|
58
|
+
return EXIT_CODES.USAGE_ERROR;
|
|
59
|
+
}
|
|
60
|
+
const approval = evaluateApproval({ action: `tool:${name}`, risk: spec.risk, toolName: name }, { approvedByHuman });
|
|
61
|
+
if (approval.needsHumanApproval) {
|
|
62
|
+
process.stderr.write(formatApprovalPrompt({ action: `tool:${name}`, risk: approval.risk, toolName: name }, approval));
|
|
63
|
+
process.stderr.write("Re-run with --approve for write/execute tools.\n");
|
|
64
|
+
return EXIT_CODES.USAGE_ERROR;
|
|
65
|
+
}
|
|
66
|
+
const call = newToolCall("cli-agent", name, options.toolArgs ?? {});
|
|
67
|
+
const result = await executeAgentTool(root, call, {
|
|
68
|
+
allowWrite: approvedByHuman,
|
|
69
|
+
allowExecute: approvedByHuman,
|
|
70
|
+
approvedByHuman,
|
|
71
|
+
});
|
|
72
|
+
if (options.json) {
|
|
73
|
+
process.stdout.write(`${JSON.stringify(result, null, 2)}\n`);
|
|
74
|
+
}
|
|
75
|
+
else if (result.ok) {
|
|
76
|
+
process.stdout.write(`${JSON.stringify(result.data, null, 2)}\n`);
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
process.stderr.write(`Tool failed: ${result.error?.code} — ${result.error?.message}\n`);
|
|
80
|
+
return EXIT_CODES.INTERNAL_ERROR;
|
|
81
|
+
}
|
|
82
|
+
return EXIT_CODES.SUCCESS;
|
|
83
|
+
}
|
|
84
|
+
if (options.goal && options.apply) {
|
|
85
|
+
if (!approvedByHuman) {
|
|
86
|
+
process.stderr.write("Refusing --apply without --approve (human approval required).\n");
|
|
87
|
+
return EXIT_CODES.USAGE_ERROR;
|
|
88
|
+
}
|
|
89
|
+
let toolCalls;
|
|
90
|
+
if (options.applyOpsJson) {
|
|
91
|
+
try {
|
|
92
|
+
const parsed = JSON.parse(options.applyOpsJson);
|
|
93
|
+
if (!Array.isArray(parsed))
|
|
94
|
+
throw new Error("expected array");
|
|
95
|
+
toolCalls = parsed.map((item) => {
|
|
96
|
+
const row = item;
|
|
97
|
+
if (!row.name || typeof row.name !== "string")
|
|
98
|
+
throw new Error("ops need name");
|
|
99
|
+
return {
|
|
100
|
+
name: row.name,
|
|
101
|
+
arguments: row.arguments ?? {},
|
|
102
|
+
};
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
process.stderr.write(`Invalid --apply-ops JSON: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
107
|
+
return EXIT_CODES.USAGE_ERROR;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
const result = await runCodingLoop({
|
|
111
|
+
root,
|
|
112
|
+
goal: options.goal,
|
|
113
|
+
approvedByHuman: true,
|
|
114
|
+
...(toolCalls ? { toolCalls } : {}),
|
|
115
|
+
verify: options.verify !== false,
|
|
116
|
+
runTests: options.runTests === true,
|
|
117
|
+
});
|
|
118
|
+
if (options.json) {
|
|
119
|
+
process.stdout.write(`${JSON.stringify(result, null, 2)}\n`);
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
process.stdout.write(result.responseText);
|
|
123
|
+
}
|
|
124
|
+
if (result.stoppedReason === "awaiting-approval")
|
|
125
|
+
return EXIT_CODES.USAGE_ERROR;
|
|
126
|
+
if (result.stoppedReason === "failed" || result.stoppedReason === "limit") {
|
|
127
|
+
return EXIT_CODES.INTERNAL_ERROR;
|
|
128
|
+
}
|
|
129
|
+
return EXIT_CODES.SUCCESS;
|
|
130
|
+
}
|
|
131
|
+
if (options.goal) {
|
|
132
|
+
return runPlanCommand({
|
|
133
|
+
goal: options.goal,
|
|
134
|
+
root,
|
|
135
|
+
...(options.json !== undefined ? { json: options.json } : {}),
|
|
136
|
+
...(approvedByHuman ? { approve: true } : {}),
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
process.stderr.write([
|
|
140
|
+
"",
|
|
141
|
+
"AgentDoctor agent (Milestone 4)",
|
|
142
|
+
"",
|
|
143
|
+
"Usage:",
|
|
144
|
+
" agentdoctor agent --list-tools",
|
|
145
|
+
" agentdoctor agent --tool inspect_project [path]",
|
|
146
|
+
' agentdoctor plan "Add registration" [path]',
|
|
147
|
+
" agentdoctor agent --goal \"Add registration\" --approve --apply --apply-ops '[...]' [path]",
|
|
148
|
+
"",
|
|
149
|
+
"Writes require --approve. Unrestricted shell is never exposed.",
|
|
150
|
+
"",
|
|
151
|
+
].join("\n"));
|
|
152
|
+
return EXIT_CODES.USAGE_ERROR;
|
|
153
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { EXIT_CODES } from "../../types/index.js";
|
|
2
|
+
import { resolveRepoRoot } from "../../utils/path.js";
|
|
3
|
+
import { buildIntelligenceGraph } from "../../intelligence/graph/build.js";
|
|
4
|
+
import { buildC4Views } from "../../architecture/c4.js";
|
|
5
|
+
import { checkArchitectureAtRoot, explainArchitecture, initArchitecture, loadArchitectureContract, } from "../../architecture/contract.js";
|
|
6
|
+
function printJson(value) {
|
|
7
|
+
process.stdout.write(`${JSON.stringify(value, null, 2)}\n`);
|
|
8
|
+
}
|
|
9
|
+
export async function runArchitectureCommand(options) {
|
|
10
|
+
const root = resolveRepoRoot(options.root ?? process.cwd());
|
|
11
|
+
try {
|
|
12
|
+
switch (options.action) {
|
|
13
|
+
case "init": {
|
|
14
|
+
const written = await initArchitecture(root);
|
|
15
|
+
if (options.json)
|
|
16
|
+
printJson({ path: written, createdOrExisting: true });
|
|
17
|
+
else
|
|
18
|
+
process.stdout.write(`Architecture contract at ${written}\n`);
|
|
19
|
+
return EXIT_CODES.SUCCESS;
|
|
20
|
+
}
|
|
21
|
+
case "analyze": {
|
|
22
|
+
const graph = await buildIntelligenceGraph({ root, mode: "auto" });
|
|
23
|
+
const views = buildC4Views(graph);
|
|
24
|
+
const loaded = await loadArchitectureContract(root);
|
|
25
|
+
const check = await checkArchitectureAtRoot(root, graph);
|
|
26
|
+
const payload = {
|
|
27
|
+
c4: {
|
|
28
|
+
levels: views.map((v) => v.level),
|
|
29
|
+
views,
|
|
30
|
+
label: "Inferred/proposed from graph evidence — not approved architecture facts",
|
|
31
|
+
},
|
|
32
|
+
contract: loaded
|
|
33
|
+
? {
|
|
34
|
+
path: loaded.path,
|
|
35
|
+
version: loaded.contract.version,
|
|
36
|
+
layerCount: loaded.contract.layers.length,
|
|
37
|
+
forbiddenCount: loaded.contract.forbidden.length,
|
|
38
|
+
allowedCount: loaded.contract.allowed.length,
|
|
39
|
+
}
|
|
40
|
+
: null,
|
|
41
|
+
check: {
|
|
42
|
+
violations: check.violations.length,
|
|
43
|
+
importEdgesChecked: check.importEdgesChecked,
|
|
44
|
+
limitations: check.limitations,
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
if (options.json)
|
|
48
|
+
printJson(payload);
|
|
49
|
+
else {
|
|
50
|
+
process.stdout.write([
|
|
51
|
+
"AgentDoctor architecture analyze",
|
|
52
|
+
` C4 views: ${views.map((v) => v.level).join(", ")} (inferred)`,
|
|
53
|
+
loaded
|
|
54
|
+
? ` contract: ${loaded.path} (layers=${loaded.contract.layers.length}, forbidden=${loaded.contract.forbidden.length})`
|
|
55
|
+
: " contract: none (run architecture init)",
|
|
56
|
+
` check violations: ${check.violations.length} (edges=${check.importEdgesChecked})`,
|
|
57
|
+
].join("\n") + "\n");
|
|
58
|
+
}
|
|
59
|
+
return EXIT_CODES.SUCCESS;
|
|
60
|
+
}
|
|
61
|
+
case "check": {
|
|
62
|
+
const graph = await buildIntelligenceGraph({ root, mode: "auto" });
|
|
63
|
+
const check = await checkArchitectureAtRoot(root, graph);
|
|
64
|
+
if (options.json)
|
|
65
|
+
printJson(check);
|
|
66
|
+
else {
|
|
67
|
+
process.stdout.write([
|
|
68
|
+
"AgentDoctor architecture check",
|
|
69
|
+
` contract: ${check.contractPath ?? "none"}`,
|
|
70
|
+
` import edges checked: ${check.importEdgesChecked}`,
|
|
71
|
+
` violations: ${check.violations.length}`,
|
|
72
|
+
...check.violations
|
|
73
|
+
.slice(0, 30)
|
|
74
|
+
.map((v) => ` - [${v.kind}] ${v.ruleId}: ${v.fromPath} → ${v.toPath} (${v.fromLayer}→${v.toLayer})`),
|
|
75
|
+
...check.limitations.map((l) => ` limitation: ${l}`),
|
|
76
|
+
].join("\n") + "\n");
|
|
77
|
+
}
|
|
78
|
+
if (check.violations.some((v) => v.kind === "forbidden")) {
|
|
79
|
+
return EXIT_CODES.ISSUES_OR_THRESHOLD;
|
|
80
|
+
}
|
|
81
|
+
return EXIT_CODES.SUCCESS;
|
|
82
|
+
}
|
|
83
|
+
case "explain": {
|
|
84
|
+
const loaded = await loadArchitectureContract(root);
|
|
85
|
+
const graph = await buildIntelligenceGraph({ root, mode: "auto" });
|
|
86
|
+
const check = await checkArchitectureAtRoot(root, graph);
|
|
87
|
+
if (options.json) {
|
|
88
|
+
printJson({
|
|
89
|
+
contract: loaded?.contract ?? null,
|
|
90
|
+
path: loaded?.path ?? null,
|
|
91
|
+
check,
|
|
92
|
+
explanation: explainArchitecture(loaded?.contract ?? null, check),
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
process.stdout.write(explainArchitecture(loaded?.contract ?? null, check));
|
|
97
|
+
}
|
|
98
|
+
return EXIT_CODES.SUCCESS;
|
|
99
|
+
}
|
|
100
|
+
default:
|
|
101
|
+
console.error(`Error: unknown architecture action`);
|
|
102
|
+
return EXIT_CODES.USAGE_ERROR;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
console.error(`Error: ${error instanceof Error ? error.message : String(error)}`);
|
|
107
|
+
return EXIT_CODES.INTERNAL_ERROR;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
export declare function runChangeAnalyzeCommand(options: {
|
|
2
|
+
root: string;
|
|
3
|
+
since?: string;
|
|
4
|
+
coverage?: string;
|
|
5
|
+
json?: boolean;
|
|
6
|
+
}): Promise<number>;
|
|
7
|
+
export declare function runChangeVerifyCommand(options: {
|
|
8
|
+
root: string;
|
|
9
|
+
since?: string;
|
|
10
|
+
changeId?: string;
|
|
11
|
+
coverage?: string;
|
|
12
|
+
json?: boolean;
|
|
13
|
+
}): Promise<number>;
|
|
14
|
+
export declare function runChangeExplainCommand(options: {
|
|
15
|
+
root: string;
|
|
16
|
+
since?: string;
|
|
17
|
+
changeId?: string;
|
|
18
|
+
coverage?: string;
|
|
19
|
+
json?: boolean;
|
|
20
|
+
}): Promise<number>;
|
|
21
|
+
export declare function runChangeDiffCommand(options: {
|
|
22
|
+
root: string;
|
|
23
|
+
since?: string;
|
|
24
|
+
changeId?: string;
|
|
25
|
+
json?: boolean;
|
|
26
|
+
}): Promise<number>;
|
|
27
|
+
export declare function runChangeStatusCommand(options: {
|
|
28
|
+
root: string;
|
|
29
|
+
changeId?: string;
|
|
30
|
+
json?: boolean;
|
|
31
|
+
}): Promise<number>;
|
|
32
|
+
export declare function runEvidenceInspectCommand(options: {
|
|
33
|
+
root: string;
|
|
34
|
+
changeId: string;
|
|
35
|
+
json?: boolean;
|
|
36
|
+
}): Promise<number>;
|
|
37
|
+
export declare function runEvidenceVerifyCommand(options: {
|
|
38
|
+
root: string;
|
|
39
|
+
changeId: string;
|
|
40
|
+
json?: boolean;
|
|
41
|
+
}): Promise<number>;
|
|
42
|
+
export declare function runProofBuildCommand(options: {
|
|
43
|
+
root: string;
|
|
44
|
+
changeId: string;
|
|
45
|
+
json?: boolean;
|
|
46
|
+
}): Promise<number>;
|
|
47
|
+
export declare function runProofInspectCommand(options: {
|
|
48
|
+
root: string;
|
|
49
|
+
id: string;
|
|
50
|
+
json?: boolean;
|
|
51
|
+
}): Promise<number>;
|
|
52
|
+
export declare function runProofExplainCommand(options: {
|
|
53
|
+
root: string;
|
|
54
|
+
id: string;
|
|
55
|
+
json?: boolean;
|
|
56
|
+
}): Promise<number>;
|
|
57
|
+
export declare function runProofVerifyCommand(options: {
|
|
58
|
+
root: string;
|
|
59
|
+
id: string;
|
|
60
|
+
json?: boolean;
|
|
61
|
+
}): Promise<number>;
|
|
62
|
+
export declare function runProofExportCommand(options: {
|
|
63
|
+
root: string;
|
|
64
|
+
id: string;
|
|
65
|
+
out: string;
|
|
66
|
+
json?: boolean;
|
|
67
|
+
}): Promise<number>;
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { analyzeChange, changeStatus, diffChange, explainChange, inspectEvidence, verifyChange, verifyEvidence, } from "../../assurance/change.js";
|
|
2
|
+
import { buildProofFromEvidence, explainProof, exportProof, inspectProof, verifyProof, } from "../../assurance/proof.js";
|
|
3
|
+
import { EXIT_CODES } from "../../types/index.js";
|
|
4
|
+
function emit(json, value, human) {
|
|
5
|
+
if (json) {
|
|
6
|
+
process.stdout.write(`${JSON.stringify(value, null, 2)}\n`);
|
|
7
|
+
}
|
|
8
|
+
else {
|
|
9
|
+
process.stdout.write(`${human}\n`);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export async function runChangeAnalyzeCommand(options) {
|
|
13
|
+
try {
|
|
14
|
+
const assessment = await analyzeChange({
|
|
15
|
+
root: options.root,
|
|
16
|
+
...(options.since ? { since: options.since } : {}),
|
|
17
|
+
...(options.coverage ? { coveragePath: options.coverage } : {}),
|
|
18
|
+
});
|
|
19
|
+
emit(Boolean(options.json), assessment, [
|
|
20
|
+
`Change assessment ${assessment.changeId}`,
|
|
21
|
+
` files: ${assessment.changedFiles.length}`,
|
|
22
|
+
` symbols: ${assessment.changedSymbols.length}`,
|
|
23
|
+
` testImpact: ${assessment.testImpact.mode} (${assessment.testImpact.confidence})`,
|
|
24
|
+
` verificationStatus: ${assessment.verificationStatus}`,
|
|
25
|
+
` Next: agentdoctor change verify${options.since ? ` --since ${options.since}` : ""}`,
|
|
26
|
+
].join("\n"));
|
|
27
|
+
return EXIT_CODES.SUCCESS;
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
31
|
+
process.stderr.write(`Error: ${message}\n`);
|
|
32
|
+
return EXIT_CODES.INTERNAL_ERROR;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
export async function runChangeVerifyCommand(options) {
|
|
36
|
+
try {
|
|
37
|
+
const { assessment, manifest } = await verifyChange({
|
|
38
|
+
root: options.root,
|
|
39
|
+
...(options.since ? { since: options.since } : {}),
|
|
40
|
+
...(options.changeId ? { changeId: options.changeId } : {}),
|
|
41
|
+
...(options.coverage ? { coveragePath: options.coverage } : {}),
|
|
42
|
+
});
|
|
43
|
+
emit(Boolean(options.json), { assessment, manifest }, [
|
|
44
|
+
`Evidence produced for ${assessment.changeId}`,
|
|
45
|
+
` directory: ${assessment.evidence.directory}`,
|
|
46
|
+
` files: ${assessment.evidence.files?.join(", ") ?? ""}`,
|
|
47
|
+
` verificationStatus: ${assessment.verificationStatus}`,
|
|
48
|
+
` Next: agentdoctor evidence verify ${assessment.changeId}`,
|
|
49
|
+
].join("\n"));
|
|
50
|
+
return EXIT_CODES.SUCCESS;
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
54
|
+
process.stderr.write(`Error: ${message}\n`);
|
|
55
|
+
return EXIT_CODES.INTERNAL_ERROR;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
export async function runChangeExplainCommand(options) {
|
|
59
|
+
try {
|
|
60
|
+
const assessment = await analyzeChange({
|
|
61
|
+
root: options.root,
|
|
62
|
+
...(options.since ? { since: options.since } : {}),
|
|
63
|
+
...(options.changeId ? { changeId: options.changeId } : {}),
|
|
64
|
+
...(options.coverage ? { coveragePath: options.coverage } : {}),
|
|
65
|
+
});
|
|
66
|
+
const text = explainChange(assessment);
|
|
67
|
+
emit(Boolean(options.json), { assessment, explanation: text }, text);
|
|
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 runChangeDiffCommand(options) {
|
|
77
|
+
try {
|
|
78
|
+
const diff = await diffChange({
|
|
79
|
+
root: options.root,
|
|
80
|
+
...(options.since ? { since: options.since } : {}),
|
|
81
|
+
...(options.changeId ? { changeId: options.changeId } : {}),
|
|
82
|
+
});
|
|
83
|
+
emit(Boolean(options.json), diff, [
|
|
84
|
+
`Change diff${diff.changeId ? ` (${diff.changeId})` : ""}`,
|
|
85
|
+
` base → target: ${diff.baseRevision ?? "(wt)"} → ${diff.targetRevision ?? "?"}`,
|
|
86
|
+
` files: +${diff.summary.added} ~${diff.summary.modified} -${diff.summary.deleted} ?${diff.summary.untracked}`,
|
|
87
|
+
diff.stat ? `\n${diff.stat}` : " (no git --stat output)",
|
|
88
|
+
].join("\n"));
|
|
89
|
+
return EXIT_CODES.SUCCESS;
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
93
|
+
process.stderr.write(`Error: ${message}\n`);
|
|
94
|
+
return EXIT_CODES.INTERNAL_ERROR;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
export async function runChangeStatusCommand(options) {
|
|
98
|
+
try {
|
|
99
|
+
const status = await changeStatus({
|
|
100
|
+
root: options.root,
|
|
101
|
+
...(options.changeId ? { changeId: options.changeId } : {}),
|
|
102
|
+
});
|
|
103
|
+
emit(Boolean(options.json), status, [
|
|
104
|
+
`Change status${status.changeId ? `: ${status.changeId}` : " (no evidence)"}`,
|
|
105
|
+
` evidence: ${status.evidencePresent ? status.evidenceDirectory : "none"}`,
|
|
106
|
+
` verificationStatus: ${status.verificationStatus}`,
|
|
107
|
+
` proof: ${status.proofPresent ? status.proofId : "none"}`,
|
|
108
|
+
` note: ${status.integrityNote}`,
|
|
109
|
+
].join("\n"));
|
|
110
|
+
return EXIT_CODES.SUCCESS;
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
114
|
+
process.stderr.write(`Error: ${message}\n`);
|
|
115
|
+
return EXIT_CODES.INTERNAL_ERROR;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
export async function runEvidenceInspectCommand(options) {
|
|
119
|
+
const result = await inspectEvidence({ root: options.root, changeId: options.changeId });
|
|
120
|
+
if (!result.ok) {
|
|
121
|
+
process.stderr.write(`Error: ${result.error ?? "evidence not found"}\n`);
|
|
122
|
+
return EXIT_CODES.USAGE_ERROR;
|
|
123
|
+
}
|
|
124
|
+
emit(Boolean(options.json), result, [
|
|
125
|
+
`Evidence ${options.changeId}`,
|
|
126
|
+
` directory: ${result.directory}`,
|
|
127
|
+
` files: ${result.presentFiles.join(", ")}`,
|
|
128
|
+
` manifestStatus: ${result.manifest?.verificationStatus ?? "missing"}`,
|
|
129
|
+
].join("\n"));
|
|
130
|
+
return EXIT_CODES.SUCCESS;
|
|
131
|
+
}
|
|
132
|
+
export async function runEvidenceVerifyCommand(options) {
|
|
133
|
+
const result = await verifyEvidence({ root: options.root, changeId: options.changeId });
|
|
134
|
+
emit(Boolean(options.json), result, [
|
|
135
|
+
`Evidence verify ${options.changeId}`,
|
|
136
|
+
` status: ${result.verificationStatus}`,
|
|
137
|
+
...result.checked.map((c) => ` ${c.match ? "OK" : "FAIL"} ${c.name}`),
|
|
138
|
+
].join("\n"));
|
|
139
|
+
if (!result.ok) {
|
|
140
|
+
return EXIT_CODES.ISSUES_OR_THRESHOLD;
|
|
141
|
+
}
|
|
142
|
+
return EXIT_CODES.SUCCESS;
|
|
143
|
+
}
|
|
144
|
+
export async function runProofBuildCommand(options) {
|
|
145
|
+
try {
|
|
146
|
+
const proof = await buildProofFromEvidence(options.root, options.changeId);
|
|
147
|
+
emit(Boolean(options.json), proof, [
|
|
148
|
+
`ChangeProof ${proof.proofId}`,
|
|
149
|
+
` changeId: ${proof.changeId}`,
|
|
150
|
+
` integrityStatus: ${proof.integrityStatus}`,
|
|
151
|
+
` engineeringChecksStatus: ${proof.engineeringChecksStatus}`,
|
|
152
|
+
` verificationState: ${proof.verificationState}`,
|
|
153
|
+
` correctnessStatus: ${proof.correctnessStatus}`,
|
|
154
|
+
].join("\n"));
|
|
155
|
+
return EXIT_CODES.SUCCESS;
|
|
156
|
+
}
|
|
157
|
+
catch (error) {
|
|
158
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
159
|
+
process.stderr.write(`Error: ${message}\n`);
|
|
160
|
+
return EXIT_CODES.INTERNAL_ERROR;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
export async function runProofInspectCommand(options) {
|
|
164
|
+
const result = await inspectProof(options.root, options.id);
|
|
165
|
+
if (!result.ok || !result.proof) {
|
|
166
|
+
process.stderr.write(`Error: ${result.error ?? "proof not found"}\n`);
|
|
167
|
+
return EXIT_CODES.USAGE_ERROR;
|
|
168
|
+
}
|
|
169
|
+
emit(Boolean(options.json), result, [
|
|
170
|
+
`Proof ${result.proof.proofId}`,
|
|
171
|
+
` changeId: ${result.proof.changeId}`,
|
|
172
|
+
` integrityStatus: ${result.proof.integrityStatus}`,
|
|
173
|
+
` engineeringChecksStatus: ${result.proof.engineeringChecksStatus}`,
|
|
174
|
+
` verificationState: ${result.proof.verificationState}`,
|
|
175
|
+
` correctnessStatus: ${result.proof.correctnessStatus}`,
|
|
176
|
+
` path: ${result.path}`,
|
|
177
|
+
].join("\n"));
|
|
178
|
+
return EXIT_CODES.SUCCESS;
|
|
179
|
+
}
|
|
180
|
+
export async function runProofExplainCommand(options) {
|
|
181
|
+
const result = await inspectProof(options.root, options.id);
|
|
182
|
+
if (!result.ok || !result.proof) {
|
|
183
|
+
process.stderr.write(`Error: ${result.error ?? "proof not found"}\n`);
|
|
184
|
+
return EXIT_CODES.USAGE_ERROR;
|
|
185
|
+
}
|
|
186
|
+
const text = explainProof(result.proof);
|
|
187
|
+
emit(Boolean(options.json), { proof: result.proof, explanation: text }, text);
|
|
188
|
+
return EXIT_CODES.SUCCESS;
|
|
189
|
+
}
|
|
190
|
+
export async function runProofVerifyCommand(options) {
|
|
191
|
+
const result = await verifyProof(options.root, options.id);
|
|
192
|
+
emit(Boolean(options.json), result, [
|
|
193
|
+
`Proof verify ${options.id}`,
|
|
194
|
+
` integrityStatus: ${result.integrityStatus}`,
|
|
195
|
+
` engineeringChecksStatus: ${result.engineeringChecksStatus}`,
|
|
196
|
+
` verificationState: ${result.verificationState}`,
|
|
197
|
+
` correctnessStatus: ${result.correctnessStatus}`,
|
|
198
|
+
...result.checked.map((c) => ` ${c.match ? "OK" : "FAIL"} ${c.name}`),
|
|
199
|
+
].join("\n"));
|
|
200
|
+
return result.ok ? EXIT_CODES.SUCCESS : EXIT_CODES.ISSUES_OR_THRESHOLD;
|
|
201
|
+
}
|
|
202
|
+
export async function runProofExportCommand(options) {
|
|
203
|
+
const result = await exportProof(options.root, options.id, options.out);
|
|
204
|
+
if (!result.ok) {
|
|
205
|
+
process.stderr.write(`Error: ${result.error ?? "export failed"}\n`);
|
|
206
|
+
return EXIT_CODES.USAGE_ERROR;
|
|
207
|
+
}
|
|
208
|
+
emit(Boolean(options.json), result, `Exported proof to ${result.path}`);
|
|
209
|
+
return EXIT_CODES.SUCCESS;
|
|
210
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type ExitCode } from "../../types/index.js";
|
|
2
|
+
export declare function runAskCommand(options: {
|
|
3
|
+
question: string;
|
|
4
|
+
root?: string;
|
|
5
|
+
json?: boolean;
|
|
6
|
+
/** Test-only: force mock provider */
|
|
7
|
+
useMock?: boolean;
|
|
8
|
+
}): Promise<ExitCode>;
|
|
9
|
+
export declare function runChatCommand(options: {
|
|
10
|
+
root?: string;
|
|
11
|
+
/** Non-interactive scripted lines (tests) */
|
|
12
|
+
scriptedInputs?: string[];
|
|
13
|
+
useMock?: boolean;
|
|
14
|
+
}): Promise<ExitCode>;
|