windows-exe-decompiler-mcp-server 0.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/CODEX_INSTALLATION.md +69 -0
- package/COPILOT_INSTALLATION.md +77 -0
- package/LICENSE +21 -0
- package/README.md +314 -0
- package/bin/windows-exe-decompiler-mcp-server.js +3 -0
- package/dist/analysis-provenance.d.ts +184 -0
- package/dist/analysis-provenance.js +74 -0
- package/dist/analysis-task-runner.d.ts +31 -0
- package/dist/analysis-task-runner.js +160 -0
- package/dist/artifact-inventory.d.ts +23 -0
- package/dist/artifact-inventory.js +175 -0
- package/dist/cache-manager.d.ts +128 -0
- package/dist/cache-manager.js +454 -0
- package/dist/confidence-semantics.d.ts +66 -0
- package/dist/confidence-semantics.js +122 -0
- package/dist/config.d.ts +335 -0
- package/dist/config.js +193 -0
- package/dist/database.d.ts +227 -0
- package/dist/database.js +601 -0
- package/dist/decompiler-worker.d.ts +441 -0
- package/dist/decompiler-worker.js +1962 -0
- package/dist/dynamic-trace.d.ts +95 -0
- package/dist/dynamic-trace.js +629 -0
- package/dist/env-validator.d.ts +15 -0
- package/dist/env-validator.js +249 -0
- package/dist/error-handler.d.ts +28 -0
- package/dist/error-handler.example.d.ts +22 -0
- package/dist/error-handler.example.js +141 -0
- package/dist/error-handler.js +139 -0
- package/dist/ghidra-analysis-status.d.ts +49 -0
- package/dist/ghidra-analysis-status.js +178 -0
- package/dist/ghidra-config.d.ts +134 -0
- package/dist/ghidra-config.js +464 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +200 -0
- package/dist/job-queue.d.ts +169 -0
- package/dist/job-queue.js +407 -0
- package/dist/logger.d.ts +106 -0
- package/dist/logger.js +176 -0
- package/dist/policy-guard.d.ts +115 -0
- package/dist/policy-guard.js +243 -0
- package/dist/process-output.d.ts +15 -0
- package/dist/process-output.js +90 -0
- package/dist/prompts/function-explanation-review.d.ts +5 -0
- package/dist/prompts/function-explanation-review.js +64 -0
- package/dist/prompts/semantic-name-review.d.ts +5 -0
- package/dist/prompts/semantic-name-review.js +63 -0
- package/dist/runtime-correlation.d.ts +34 -0
- package/dist/runtime-correlation.js +279 -0
- package/dist/runtime-paths.d.ts +3 -0
- package/dist/runtime-paths.js +11 -0
- package/dist/selection-diff.d.ts +667 -0
- package/dist/selection-diff.js +53 -0
- package/dist/semantic-name-suggestion-artifacts.d.ts +116 -0
- package/dist/semantic-name-suggestion-artifacts.js +314 -0
- package/dist/server.d.ts +129 -0
- package/dist/server.js +578 -0
- package/dist/tools/artifact-read.d.ts +235 -0
- package/dist/tools/artifact-read.js +317 -0
- package/dist/tools/artifacts-diff.d.ts +728 -0
- package/dist/tools/artifacts-diff.js +304 -0
- package/dist/tools/artifacts-list.d.ts +515 -0
- package/dist/tools/artifacts-list.js +389 -0
- package/dist/tools/attack-map.d.ts +290 -0
- package/dist/tools/attack-map.js +519 -0
- package/dist/tools/cache-observability.d.ts +4 -0
- package/dist/tools/cache-observability.js +36 -0
- package/dist/tools/code-function-cfg.d.ts +50 -0
- package/dist/tools/code-function-cfg.js +102 -0
- package/dist/tools/code-function-decompile.d.ts +55 -0
- package/dist/tools/code-function-decompile.js +103 -0
- package/dist/tools/code-function-disassemble.d.ts +43 -0
- package/dist/tools/code-function-disassemble.js +185 -0
- package/dist/tools/code-function-explain-apply.d.ts +255 -0
- package/dist/tools/code-function-explain-apply.js +225 -0
- package/dist/tools/code-function-explain-prepare.d.ts +535 -0
- package/dist/tools/code-function-explain-prepare.js +276 -0
- package/dist/tools/code-function-explain-review.d.ts +397 -0
- package/dist/tools/code-function-explain-review.js +589 -0
- package/dist/tools/code-function-rename-apply.d.ts +248 -0
- package/dist/tools/code-function-rename-apply.js +220 -0
- package/dist/tools/code-function-rename-prepare.d.ts +506 -0
- package/dist/tools/code-function-rename-prepare.js +279 -0
- package/dist/tools/code-function-rename-review.d.ts +574 -0
- package/dist/tools/code-function-rename-review.js +761 -0
- package/dist/tools/code-functions-list.d.ts +37 -0
- package/dist/tools/code-functions-list.js +91 -0
- package/dist/tools/code-functions-rank.d.ts +34 -0
- package/dist/tools/code-functions-rank.js +90 -0
- package/dist/tools/code-functions-reconstruct.d.ts +2725 -0
- package/dist/tools/code-functions-reconstruct.js +2807 -0
- package/dist/tools/code-functions-search.d.ts +39 -0
- package/dist/tools/code-functions-search.js +90 -0
- package/dist/tools/code-reconstruct-export.d.ts +1212 -0
- package/dist/tools/code-reconstruct-export.js +4002 -0
- package/dist/tools/code-reconstruct-plan.d.ts +274 -0
- package/dist/tools/code-reconstruct-plan.js +342 -0
- package/dist/tools/dotnet-metadata-extract.d.ts +541 -0
- package/dist/tools/dotnet-metadata-extract.js +355 -0
- package/dist/tools/dotnet-reconstruct-export.d.ts +567 -0
- package/dist/tools/dotnet-reconstruct-export.js +1151 -0
- package/dist/tools/dotnet-types-list.d.ts +325 -0
- package/dist/tools/dotnet-types-list.js +201 -0
- package/dist/tools/dynamic-dependencies.d.ts +115 -0
- package/dist/tools/dynamic-dependencies.js +213 -0
- package/dist/tools/dynamic-memory-import.d.ts +10 -0
- package/dist/tools/dynamic-memory-import.js +567 -0
- package/dist/tools/dynamic-trace-import.d.ts +10 -0
- package/dist/tools/dynamic-trace-import.js +235 -0
- package/dist/tools/entrypoint-fallback-disasm.d.ts +30 -0
- package/dist/tools/entrypoint-fallback-disasm.js +89 -0
- package/dist/tools/ghidra-analyze.d.ts +88 -0
- package/dist/tools/ghidra-analyze.js +208 -0
- package/dist/tools/ghidra-health.d.ts +37 -0
- package/dist/tools/ghidra-health.js +212 -0
- package/dist/tools/ioc-export.d.ts +209 -0
- package/dist/tools/ioc-export.js +542 -0
- package/dist/tools/packer-detect.d.ts +165 -0
- package/dist/tools/packer-detect.js +284 -0
- package/dist/tools/pe-exports-extract.d.ts +175 -0
- package/dist/tools/pe-exports-extract.js +253 -0
- package/dist/tools/pe-fingerprint.d.ts +234 -0
- package/dist/tools/pe-fingerprint.js +269 -0
- package/dist/tools/pe-imports-extract.d.ts +105 -0
- package/dist/tools/pe-imports-extract.js +245 -0
- package/dist/tools/report-generate.d.ts +157 -0
- package/dist/tools/report-generate.js +457 -0
- package/dist/tools/report-summarize.d.ts +2131 -0
- package/dist/tools/report-summarize.js +596 -0
- package/dist/tools/runtime-detect.d.ts +135 -0
- package/dist/tools/runtime-detect.js +247 -0
- package/dist/tools/sample-ingest.d.ts +94 -0
- package/dist/tools/sample-ingest.js +327 -0
- package/dist/tools/sample-profile-get.d.ts +183 -0
- package/dist/tools/sample-profile-get.js +121 -0
- package/dist/tools/sandbox-execute.d.ts +441 -0
- package/dist/tools/sandbox-execute.js +392 -0
- package/dist/tools/strings-extract.d.ts +375 -0
- package/dist/tools/strings-extract.js +314 -0
- package/dist/tools/strings-floss-decode.d.ts +143 -0
- package/dist/tools/strings-floss-decode.js +259 -0
- package/dist/tools/system-health.d.ts +434 -0
- package/dist/tools/system-health.js +446 -0
- package/dist/tools/task-cancel.d.ts +21 -0
- package/dist/tools/task-cancel.js +70 -0
- package/dist/tools/task-status.d.ts +27 -0
- package/dist/tools/task-status.js +106 -0
- package/dist/tools/task-sweep.d.ts +22 -0
- package/dist/tools/task-sweep.js +77 -0
- package/dist/tools/tool-help.d.ts +340 -0
- package/dist/tools/tool-help.js +261 -0
- package/dist/tools/yara-scan.d.ts +554 -0
- package/dist/tools/yara-scan.js +313 -0
- package/dist/types.d.ts +266 -0
- package/dist/types.js +41 -0
- package/dist/worker-pool.d.ts +204 -0
- package/dist/worker-pool.js +650 -0
- package/dist/workflows/deep-static.d.ts +104 -0
- package/dist/workflows/deep-static.js +276 -0
- package/dist/workflows/function-explanation-review.d.ts +655 -0
- package/dist/workflows/function-explanation-review.js +440 -0
- package/dist/workflows/reconstruct.d.ts +2053 -0
- package/dist/workflows/reconstruct.js +666 -0
- package/dist/workflows/semantic-name-review.d.ts +2418 -0
- package/dist/workflows/semantic-name-review.js +521 -0
- package/dist/workflows/triage.d.ts +659 -0
- package/dist/workflows/triage.js +1374 -0
- package/dist/workspace-manager.d.ts +150 -0
- package/dist/workspace-manager.js +411 -0
- package/ghidra_scripts/DecompileFunction.java +487 -0
- package/ghidra_scripts/DecompileFunction.py +150 -0
- package/ghidra_scripts/ExtractCFG.java +256 -0
- package/ghidra_scripts/ExtractCFG.py +233 -0
- package/ghidra_scripts/ExtractFunctions.java +442 -0
- package/ghidra_scripts/ExtractFunctions.py +101 -0
- package/ghidra_scripts/README.md +125 -0
- package/ghidra_scripts/SearchFunctionReferences.java +380 -0
- package/helpers/DotNetMetadataProbe/DotNetMetadataProbe.csproj +9 -0
- package/helpers/DotNetMetadataProbe/Program.cs +566 -0
- package/install-to-codex.ps1 +178 -0
- package/install-to-copilot.ps1 +303 -0
- package/package.json +101 -0
- package/requirements.txt +9 -0
- package/workers/requirements-dynamic.txt +11 -0
- package/workers/requirements.txt +8 -0
- package/workers/speakeasy_compat.py +175 -0
- package/workers/static_worker.py +5183 -0
- package/workers/yara_rules/default.yar +33 -0
- package/workers/yara_rules/malware_families.yar +93 -0
- package/workers/yara_rules/packers.yar +80 -0
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import type { ToolArgs, ToolDefinition, WorkerResult } from '../types.js';
|
|
3
|
+
import type { WorkspaceManager } from '../workspace-manager.js';
|
|
4
|
+
import type { DatabaseManager } from '../database.js';
|
|
5
|
+
export declare const codeFunctionExplainApplyInputSchema: z.ZodObject<{
|
|
6
|
+
sample_id: z.ZodString;
|
|
7
|
+
explanations: z.ZodArray<z.ZodEffects<z.ZodObject<{
|
|
8
|
+
address_or_function: z.ZodOptional<z.ZodString>;
|
|
9
|
+
address: z.ZodOptional<z.ZodString>;
|
|
10
|
+
function: z.ZodOptional<z.ZodString>;
|
|
11
|
+
summary: z.ZodString;
|
|
12
|
+
behavior: z.ZodString;
|
|
13
|
+
confidence: z.ZodNumber;
|
|
14
|
+
assumptions: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodString, "many">>>;
|
|
15
|
+
evidence_used: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodString, "many">>>;
|
|
16
|
+
rewrite_guidance: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
|
|
17
|
+
}, "strip", z.ZodTypeAny, {
|
|
18
|
+
summary: string;
|
|
19
|
+
confidence: number;
|
|
20
|
+
evidence_used: string[];
|
|
21
|
+
behavior: string;
|
|
22
|
+
assumptions: string[];
|
|
23
|
+
function?: string | undefined;
|
|
24
|
+
address?: string | undefined;
|
|
25
|
+
rewrite_guidance?: string | string[] | undefined;
|
|
26
|
+
address_or_function?: string | undefined;
|
|
27
|
+
}, {
|
|
28
|
+
summary: string;
|
|
29
|
+
confidence: number;
|
|
30
|
+
behavior: string;
|
|
31
|
+
function?: string | undefined;
|
|
32
|
+
address?: string | undefined;
|
|
33
|
+
evidence_used?: string[] | undefined;
|
|
34
|
+
assumptions?: string[] | undefined;
|
|
35
|
+
rewrite_guidance?: string | string[] | undefined;
|
|
36
|
+
address_or_function?: string | undefined;
|
|
37
|
+
}>, {
|
|
38
|
+
summary: string;
|
|
39
|
+
confidence: number;
|
|
40
|
+
evidence_used: string[];
|
|
41
|
+
behavior: string;
|
|
42
|
+
assumptions: string[];
|
|
43
|
+
function?: string | undefined;
|
|
44
|
+
address?: string | undefined;
|
|
45
|
+
rewrite_guidance?: string | string[] | undefined;
|
|
46
|
+
address_or_function?: string | undefined;
|
|
47
|
+
}, {
|
|
48
|
+
summary: string;
|
|
49
|
+
confidence: number;
|
|
50
|
+
behavior: string;
|
|
51
|
+
function?: string | undefined;
|
|
52
|
+
address?: string | undefined;
|
|
53
|
+
evidence_used?: string[] | undefined;
|
|
54
|
+
assumptions?: string[] | undefined;
|
|
55
|
+
rewrite_guidance?: string | string[] | undefined;
|
|
56
|
+
address_or_function?: string | undefined;
|
|
57
|
+
}>, "many">;
|
|
58
|
+
client_name: z.ZodOptional<z.ZodString>;
|
|
59
|
+
model_name: z.ZodOptional<z.ZodString>;
|
|
60
|
+
prepare_artifact_id: z.ZodOptional<z.ZodString>;
|
|
61
|
+
session_tag: z.ZodOptional<z.ZodString>;
|
|
62
|
+
}, "strip", z.ZodTypeAny, {
|
|
63
|
+
sample_id: string;
|
|
64
|
+
explanations: {
|
|
65
|
+
summary: string;
|
|
66
|
+
confidence: number;
|
|
67
|
+
evidence_used: string[];
|
|
68
|
+
behavior: string;
|
|
69
|
+
assumptions: string[];
|
|
70
|
+
function?: string | undefined;
|
|
71
|
+
address?: string | undefined;
|
|
72
|
+
rewrite_guidance?: string | string[] | undefined;
|
|
73
|
+
address_or_function?: string | undefined;
|
|
74
|
+
}[];
|
|
75
|
+
session_tag?: string | undefined;
|
|
76
|
+
client_name?: string | undefined;
|
|
77
|
+
model_name?: string | undefined;
|
|
78
|
+
prepare_artifact_id?: string | undefined;
|
|
79
|
+
}, {
|
|
80
|
+
sample_id: string;
|
|
81
|
+
explanations: {
|
|
82
|
+
summary: string;
|
|
83
|
+
confidence: number;
|
|
84
|
+
behavior: string;
|
|
85
|
+
function?: string | undefined;
|
|
86
|
+
address?: string | undefined;
|
|
87
|
+
evidence_used?: string[] | undefined;
|
|
88
|
+
assumptions?: string[] | undefined;
|
|
89
|
+
rewrite_guidance?: string | string[] | undefined;
|
|
90
|
+
address_or_function?: string | undefined;
|
|
91
|
+
}[];
|
|
92
|
+
session_tag?: string | undefined;
|
|
93
|
+
client_name?: string | undefined;
|
|
94
|
+
model_name?: string | undefined;
|
|
95
|
+
prepare_artifact_id?: string | undefined;
|
|
96
|
+
}>;
|
|
97
|
+
export declare const codeFunctionExplainApplyOutputSchema: z.ZodObject<{
|
|
98
|
+
ok: z.ZodBoolean;
|
|
99
|
+
data: z.ZodOptional<z.ZodObject<{
|
|
100
|
+
sample_id: z.ZodString;
|
|
101
|
+
accepted_count: z.ZodNumber;
|
|
102
|
+
rejected_count: z.ZodNumber;
|
|
103
|
+
accepted_explanations: z.ZodArray<z.ZodObject<{
|
|
104
|
+
address: z.ZodNullable<z.ZodString>;
|
|
105
|
+
function: z.ZodNullable<z.ZodString>;
|
|
106
|
+
behavior: z.ZodString;
|
|
107
|
+
confidence: z.ZodNumber;
|
|
108
|
+
rewrite_guidance_count: z.ZodNumber;
|
|
109
|
+
}, "strip", z.ZodTypeAny, {
|
|
110
|
+
function: string | null;
|
|
111
|
+
address: string | null;
|
|
112
|
+
confidence: number;
|
|
113
|
+
behavior: string;
|
|
114
|
+
rewrite_guidance_count: number;
|
|
115
|
+
}, {
|
|
116
|
+
function: string | null;
|
|
117
|
+
address: string | null;
|
|
118
|
+
confidence: number;
|
|
119
|
+
behavior: string;
|
|
120
|
+
rewrite_guidance_count: number;
|
|
121
|
+
}>, "many">;
|
|
122
|
+
artifact: z.ZodObject<{
|
|
123
|
+
id: z.ZodString;
|
|
124
|
+
type: z.ZodLiteral<"semantic_function_explanations">;
|
|
125
|
+
path: z.ZodString;
|
|
126
|
+
sha256: z.ZodString;
|
|
127
|
+
mime: z.ZodOptional<z.ZodString>;
|
|
128
|
+
}, "strip", z.ZodTypeAny, {
|
|
129
|
+
path: string;
|
|
130
|
+
type: "semantic_function_explanations";
|
|
131
|
+
id: string;
|
|
132
|
+
sha256: string;
|
|
133
|
+
mime?: string | undefined;
|
|
134
|
+
}, {
|
|
135
|
+
path: string;
|
|
136
|
+
type: "semantic_function_explanations";
|
|
137
|
+
id: string;
|
|
138
|
+
sha256: string;
|
|
139
|
+
mime?: string | undefined;
|
|
140
|
+
}>;
|
|
141
|
+
next_steps: z.ZodArray<z.ZodString, "many">;
|
|
142
|
+
}, "strip", z.ZodTypeAny, {
|
|
143
|
+
sample_id: string;
|
|
144
|
+
artifact: {
|
|
145
|
+
path: string;
|
|
146
|
+
type: "semantic_function_explanations";
|
|
147
|
+
id: string;
|
|
148
|
+
sha256: string;
|
|
149
|
+
mime?: string | undefined;
|
|
150
|
+
};
|
|
151
|
+
accepted_count: number;
|
|
152
|
+
rejected_count: number;
|
|
153
|
+
next_steps: string[];
|
|
154
|
+
accepted_explanations: {
|
|
155
|
+
function: string | null;
|
|
156
|
+
address: string | null;
|
|
157
|
+
confidence: number;
|
|
158
|
+
behavior: string;
|
|
159
|
+
rewrite_guidance_count: number;
|
|
160
|
+
}[];
|
|
161
|
+
}, {
|
|
162
|
+
sample_id: string;
|
|
163
|
+
artifact: {
|
|
164
|
+
path: string;
|
|
165
|
+
type: "semantic_function_explanations";
|
|
166
|
+
id: string;
|
|
167
|
+
sha256: string;
|
|
168
|
+
mime?: string | undefined;
|
|
169
|
+
};
|
|
170
|
+
accepted_count: number;
|
|
171
|
+
rejected_count: number;
|
|
172
|
+
next_steps: string[];
|
|
173
|
+
accepted_explanations: {
|
|
174
|
+
function: string | null;
|
|
175
|
+
address: string | null;
|
|
176
|
+
confidence: number;
|
|
177
|
+
behavior: string;
|
|
178
|
+
rewrite_guidance_count: number;
|
|
179
|
+
}[];
|
|
180
|
+
}>>;
|
|
181
|
+
warnings: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
182
|
+
errors: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
183
|
+
artifacts: z.ZodOptional<z.ZodArray<z.ZodAny, "many">>;
|
|
184
|
+
metrics: z.ZodOptional<z.ZodObject<{
|
|
185
|
+
elapsed_ms: z.ZodNumber;
|
|
186
|
+
tool: z.ZodString;
|
|
187
|
+
}, "strip", z.ZodTypeAny, {
|
|
188
|
+
elapsed_ms: number;
|
|
189
|
+
tool: string;
|
|
190
|
+
}, {
|
|
191
|
+
elapsed_ms: number;
|
|
192
|
+
tool: string;
|
|
193
|
+
}>>;
|
|
194
|
+
}, "strip", z.ZodTypeAny, {
|
|
195
|
+
ok: boolean;
|
|
196
|
+
metrics?: {
|
|
197
|
+
elapsed_ms: number;
|
|
198
|
+
tool: string;
|
|
199
|
+
} | undefined;
|
|
200
|
+
data?: {
|
|
201
|
+
sample_id: string;
|
|
202
|
+
artifact: {
|
|
203
|
+
path: string;
|
|
204
|
+
type: "semantic_function_explanations";
|
|
205
|
+
id: string;
|
|
206
|
+
sha256: string;
|
|
207
|
+
mime?: string | undefined;
|
|
208
|
+
};
|
|
209
|
+
accepted_count: number;
|
|
210
|
+
rejected_count: number;
|
|
211
|
+
next_steps: string[];
|
|
212
|
+
accepted_explanations: {
|
|
213
|
+
function: string | null;
|
|
214
|
+
address: string | null;
|
|
215
|
+
confidence: number;
|
|
216
|
+
behavior: string;
|
|
217
|
+
rewrite_guidance_count: number;
|
|
218
|
+
}[];
|
|
219
|
+
} | undefined;
|
|
220
|
+
warnings?: string[] | undefined;
|
|
221
|
+
errors?: string[] | undefined;
|
|
222
|
+
artifacts?: any[] | undefined;
|
|
223
|
+
}, {
|
|
224
|
+
ok: boolean;
|
|
225
|
+
metrics?: {
|
|
226
|
+
elapsed_ms: number;
|
|
227
|
+
tool: string;
|
|
228
|
+
} | undefined;
|
|
229
|
+
data?: {
|
|
230
|
+
sample_id: string;
|
|
231
|
+
artifact: {
|
|
232
|
+
path: string;
|
|
233
|
+
type: "semantic_function_explanations";
|
|
234
|
+
id: string;
|
|
235
|
+
sha256: string;
|
|
236
|
+
mime?: string | undefined;
|
|
237
|
+
};
|
|
238
|
+
accepted_count: number;
|
|
239
|
+
rejected_count: number;
|
|
240
|
+
next_steps: string[];
|
|
241
|
+
accepted_explanations: {
|
|
242
|
+
function: string | null;
|
|
243
|
+
address: string | null;
|
|
244
|
+
confidence: number;
|
|
245
|
+
behavior: string;
|
|
246
|
+
rewrite_guidance_count: number;
|
|
247
|
+
}[];
|
|
248
|
+
} | undefined;
|
|
249
|
+
warnings?: string[] | undefined;
|
|
250
|
+
errors?: string[] | undefined;
|
|
251
|
+
artifacts?: any[] | undefined;
|
|
252
|
+
}>;
|
|
253
|
+
export declare const codeFunctionExplainApplyToolDefinition: ToolDefinition;
|
|
254
|
+
export declare function createCodeFunctionExplainApplyHandler(workspaceManager: WorkspaceManager, database: DatabaseManager): (args: ToolArgs) => Promise<WorkerResult>;
|
|
255
|
+
//# sourceMappingURL=code-function-explain-apply.d.ts.map
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { persistSemanticFunctionExplanationsArtifact, SEMANTIC_FUNCTION_EXPLANATIONS_ARTIFACT_TYPE, } from '../semantic-name-suggestion-artifacts.js';
|
|
3
|
+
const TOOL_NAME = 'code.function.explain.apply';
|
|
4
|
+
const ExplanationSuggestionInputSchema = z
|
|
5
|
+
.object({
|
|
6
|
+
address_or_function: z
|
|
7
|
+
.string()
|
|
8
|
+
.optional()
|
|
9
|
+
.describe('Optional combined identifier when the reviewing client returns a single address_or_function field'),
|
|
10
|
+
address: z.string().optional().describe('Optional function address for precise matching'),
|
|
11
|
+
function: z.string().optional().describe('Optional function symbol/name for fallback matching'),
|
|
12
|
+
summary: z.string().min(1).max(1200).describe('Evidence-grounded plain-language explanation of the function'),
|
|
13
|
+
behavior: z.string().min(1).max(160).describe('Short behavior label, such as resolve_dynamic_imports or dispatch_exported_command'),
|
|
14
|
+
confidence: z.number().min(0).max(1).describe('Heuristic support score for the explanation'),
|
|
15
|
+
assumptions: z.array(z.string()).optional().default([]).describe('Assumptions that must hold for the explanation to remain valid'),
|
|
16
|
+
evidence_used: z.array(z.string()).optional().default([]).describe('Evidence sources used by the external LLM'),
|
|
17
|
+
rewrite_guidance: z
|
|
18
|
+
.union([z.string().min(1), z.array(z.string().min(1))])
|
|
19
|
+
.optional()
|
|
20
|
+
.describe('One or more rewrite-oriented guidance items derived from the evidence'),
|
|
21
|
+
})
|
|
22
|
+
.refine((value) => Boolean(value.address_or_function?.trim()) ||
|
|
23
|
+
Boolean(value.address?.trim()) ||
|
|
24
|
+
Boolean(value.function?.trim()), {
|
|
25
|
+
message: 'Each explanation must provide at least one of `address_or_function`, `address`, or `function`.',
|
|
26
|
+
});
|
|
27
|
+
function normalizeExplanationIdentifier(explanation) {
|
|
28
|
+
const normalizedAddress = explanation.address?.trim() || null;
|
|
29
|
+
const normalizedFunction = explanation.function?.trim() || null;
|
|
30
|
+
if (normalizedAddress || normalizedFunction) {
|
|
31
|
+
return {
|
|
32
|
+
address: normalizedAddress,
|
|
33
|
+
function: normalizedFunction,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
const identifier = explanation.address_or_function?.trim();
|
|
37
|
+
if (!identifier) {
|
|
38
|
+
return {
|
|
39
|
+
address: null,
|
|
40
|
+
function: null,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
if (/^(0x)?[0-9a-f]+$/i.test(identifier)) {
|
|
44
|
+
return {
|
|
45
|
+
address: identifier,
|
|
46
|
+
function: null,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
address: null,
|
|
51
|
+
function: identifier,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function normalizeRewriteGuidance(input) {
|
|
55
|
+
if (!input) {
|
|
56
|
+
return [];
|
|
57
|
+
}
|
|
58
|
+
const values = Array.isArray(input) ? input : [input];
|
|
59
|
+
return values.map((item) => item.trim()).filter((item) => item.length > 0).slice(0, 8);
|
|
60
|
+
}
|
|
61
|
+
export const codeFunctionExplainApplyInputSchema = z.object({
|
|
62
|
+
sample_id: z.string().describe('Sample ID (format: sha256:<hex>)'),
|
|
63
|
+
explanations: z
|
|
64
|
+
.array(ExplanationSuggestionInputSchema)
|
|
65
|
+
.min(1)
|
|
66
|
+
.describe('Structured explanation outputs returned by an external MCP client / LLM'),
|
|
67
|
+
client_name: z
|
|
68
|
+
.string()
|
|
69
|
+
.optional()
|
|
70
|
+
.describe('Optional client identifier, such as claude-desktop or codex-cli'),
|
|
71
|
+
model_name: z
|
|
72
|
+
.string()
|
|
73
|
+
.optional()
|
|
74
|
+
.describe('Optional model identifier for provenance only'),
|
|
75
|
+
prepare_artifact_id: z
|
|
76
|
+
.string()
|
|
77
|
+
.optional()
|
|
78
|
+
.describe('Optional semantic_explanation_prepare_bundle artifact ID that produced this review task'),
|
|
79
|
+
session_tag: z
|
|
80
|
+
.string()
|
|
81
|
+
.optional()
|
|
82
|
+
.describe('Optional semantic explanation session tag used for artifact grouping'),
|
|
83
|
+
});
|
|
84
|
+
export const codeFunctionExplainApplyOutputSchema = z.object({
|
|
85
|
+
ok: z.boolean(),
|
|
86
|
+
data: z
|
|
87
|
+
.object({
|
|
88
|
+
sample_id: z.string(),
|
|
89
|
+
accepted_count: z.number().int().nonnegative(),
|
|
90
|
+
rejected_count: z.number().int().nonnegative(),
|
|
91
|
+
accepted_explanations: z.array(z.object({
|
|
92
|
+
address: z.string().nullable(),
|
|
93
|
+
function: z.string().nullable(),
|
|
94
|
+
behavior: z.string(),
|
|
95
|
+
confidence: z.number().min(0).max(1),
|
|
96
|
+
rewrite_guidance_count: z.number().int().nonnegative(),
|
|
97
|
+
})),
|
|
98
|
+
artifact: z.object({
|
|
99
|
+
id: z.string(),
|
|
100
|
+
type: z.literal(SEMANTIC_FUNCTION_EXPLANATIONS_ARTIFACT_TYPE),
|
|
101
|
+
path: z.string(),
|
|
102
|
+
sha256: z.string(),
|
|
103
|
+
mime: z.string().optional(),
|
|
104
|
+
}),
|
|
105
|
+
next_steps: z.array(z.string()),
|
|
106
|
+
})
|
|
107
|
+
.optional(),
|
|
108
|
+
warnings: z.array(z.string()).optional(),
|
|
109
|
+
errors: z.array(z.string()).optional(),
|
|
110
|
+
artifacts: z.array(z.any()).optional(),
|
|
111
|
+
metrics: z
|
|
112
|
+
.object({
|
|
113
|
+
elapsed_ms: z.number(),
|
|
114
|
+
tool: z.string(),
|
|
115
|
+
})
|
|
116
|
+
.optional(),
|
|
117
|
+
});
|
|
118
|
+
export const codeFunctionExplainApplyToolDefinition = {
|
|
119
|
+
name: TOOL_NAME,
|
|
120
|
+
description: 'Persist structured function explanations returned by any external MCP client / LLM so export and report layers can consume them.',
|
|
121
|
+
inputSchema: codeFunctionExplainApplyInputSchema,
|
|
122
|
+
outputSchema: codeFunctionExplainApplyOutputSchema,
|
|
123
|
+
};
|
|
124
|
+
export function createCodeFunctionExplainApplyHandler(workspaceManager, database) {
|
|
125
|
+
return async (args) => {
|
|
126
|
+
const startTime = Date.now();
|
|
127
|
+
try {
|
|
128
|
+
const input = codeFunctionExplainApplyInputSchema.parse(args);
|
|
129
|
+
const sample = database.findSample(input.sample_id);
|
|
130
|
+
if (!sample) {
|
|
131
|
+
return {
|
|
132
|
+
ok: false,
|
|
133
|
+
errors: [`Sample not found: ${input.sample_id}`],
|
|
134
|
+
metrics: {
|
|
135
|
+
elapsed_ms: Date.now() - startTime,
|
|
136
|
+
tool: TOOL_NAME,
|
|
137
|
+
},
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
const acceptedExplanations = [];
|
|
141
|
+
const acceptedSummary = [];
|
|
142
|
+
const warnings = [];
|
|
143
|
+
for (const explanation of input.explanations) {
|
|
144
|
+
const normalizedIdentifier = normalizeExplanationIdentifier(explanation);
|
|
145
|
+
const rewriteGuidance = normalizeRewriteGuidance(explanation.rewrite_guidance);
|
|
146
|
+
const summary = explanation.summary.trim();
|
|
147
|
+
const behavior = explanation.behavior.trim();
|
|
148
|
+
if (summary.length === 0 || behavior.length === 0) {
|
|
149
|
+
warnings.push(`Rejected explanation for ${normalizedIdentifier.address || normalizedIdentifier.function || explanation.address_or_function || 'unknown'} because summary or behavior was empty after normalization.`);
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
acceptedExplanations.push({
|
|
153
|
+
address: normalizedIdentifier.address,
|
|
154
|
+
function: normalizedIdentifier.function,
|
|
155
|
+
summary,
|
|
156
|
+
behavior,
|
|
157
|
+
confidence: explanation.confidence,
|
|
158
|
+
assumptions: explanation.assumptions || [],
|
|
159
|
+
evidence_used: explanation.evidence_used || [],
|
|
160
|
+
rewrite_guidance: rewriteGuidance,
|
|
161
|
+
});
|
|
162
|
+
acceptedSummary.push({
|
|
163
|
+
address: normalizedIdentifier.address,
|
|
164
|
+
function: normalizedIdentifier.function,
|
|
165
|
+
behavior,
|
|
166
|
+
confidence: explanation.confidence,
|
|
167
|
+
rewrite_guidance_count: rewriteGuidance.length,
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
if (acceptedExplanations.length === 0) {
|
|
171
|
+
return {
|
|
172
|
+
ok: false,
|
|
173
|
+
errors: ['No explanations were accepted after normalization.'],
|
|
174
|
+
warnings: warnings.length > 0 ? warnings : undefined,
|
|
175
|
+
metrics: {
|
|
176
|
+
elapsed_ms: Date.now() - startTime,
|
|
177
|
+
tool: TOOL_NAME,
|
|
178
|
+
},
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
const payload = {
|
|
182
|
+
schema_version: 1,
|
|
183
|
+
sample_id: input.sample_id,
|
|
184
|
+
created_at: new Date().toISOString(),
|
|
185
|
+
session_tag: input.session_tag || null,
|
|
186
|
+
client_name: input.client_name || null,
|
|
187
|
+
model_name: input.model_name || null,
|
|
188
|
+
prepare_artifact_id: input.prepare_artifact_id || null,
|
|
189
|
+
explanations: acceptedExplanations,
|
|
190
|
+
};
|
|
191
|
+
const artifact = await persistSemanticFunctionExplanationsArtifact(workspaceManager, database, payload);
|
|
192
|
+
return {
|
|
193
|
+
ok: true,
|
|
194
|
+
data: {
|
|
195
|
+
sample_id: input.sample_id,
|
|
196
|
+
accepted_count: acceptedExplanations.length,
|
|
197
|
+
rejected_count: input.explanations.length - acceptedExplanations.length,
|
|
198
|
+
accepted_explanations: acceptedSummary,
|
|
199
|
+
artifact,
|
|
200
|
+
next_steps: [
|
|
201
|
+
'rerun code.reconstruct.export to propagate explanation summaries and rewrite guidance into rewrite output',
|
|
202
|
+
'rerun report.generate or report.summarize if you want explanation artifacts reflected in higher-level analyst output',
|
|
203
|
+
],
|
|
204
|
+
},
|
|
205
|
+
warnings: warnings.length > 0 ? warnings : undefined,
|
|
206
|
+
artifacts: [artifact],
|
|
207
|
+
metrics: {
|
|
208
|
+
elapsed_ms: Date.now() - startTime,
|
|
209
|
+
tool: TOOL_NAME,
|
|
210
|
+
},
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
catch (error) {
|
|
214
|
+
return {
|
|
215
|
+
ok: false,
|
|
216
|
+
errors: [error instanceof Error ? error.message : String(error)],
|
|
217
|
+
metrics: {
|
|
218
|
+
elapsed_ms: Date.now() - startTime,
|
|
219
|
+
tool: TOOL_NAME,
|
|
220
|
+
},
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
//# sourceMappingURL=code-function-explain-apply.js.map
|