windows-exe-decompiler-mcp-server 0.1.0 → 0.1.3

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.
Files changed (134) hide show
  1. package/CLAUDE_INSTALLATION.md +129 -0
  2. package/CODEX_INSTALLATION.md +25 -1
  3. package/COPILOT_INSTALLATION.md +29 -1
  4. package/LICENSE +21 -21
  5. package/README.md +232 -110
  6. package/dist/analysis-provenance.d.ts +50 -2
  7. package/dist/analysis-provenance.js +1 -0
  8. package/dist/analysis-task-runner.js +92 -0
  9. package/dist/config.d.ts +35 -16
  10. package/dist/config.js +37 -3
  11. package/dist/database.js +115 -115
  12. package/dist/decompiler-worker.d.ts +10 -5
  13. package/dist/decompiler-worker.js +240 -58
  14. package/dist/dynamic-trace.d.ts +6 -0
  15. package/dist/dynamic-trace.js +52 -1
  16. package/dist/ghidra-config.js +17 -1
  17. package/dist/index.js +38 -8
  18. package/dist/pe-runtime-functions.d.ts +90 -0
  19. package/dist/pe-runtime-functions.js +452 -0
  20. package/dist/prompts/module-reconstruction-review.d.ts +5 -0
  21. package/dist/prompts/module-reconstruction-review.js +65 -0
  22. package/dist/runtime-correlation.d.ts +5 -0
  23. package/dist/runtime-correlation.js +179 -2
  24. package/dist/sample-workspace.d.ts +28 -0
  25. package/dist/sample-workspace.js +186 -0
  26. package/dist/semantic-name-suggestion-artifacts.d.ts +56 -0
  27. package/dist/semantic-name-suggestion-artifacts.js +87 -0
  28. package/dist/server.js +1 -1
  29. package/dist/setup-guidance.d.ts +73 -0
  30. package/dist/setup-guidance.js +211 -0
  31. package/dist/tools/artifact-read.d.ts +10 -10
  32. package/dist/tools/artifacts-diff.d.ts +8 -8
  33. package/dist/tools/artifacts-list.d.ts +16 -16
  34. package/dist/tools/attack-map.d.ts +8 -8
  35. package/dist/tools/binary-role-profile.d.ts +1197 -0
  36. package/dist/tools/binary-role-profile.js +575 -0
  37. package/dist/tools/code-function-explain-apply.d.ts +12 -12
  38. package/dist/tools/code-function-explain-prepare.d.ts +12 -12
  39. package/dist/tools/code-function-explain-review.d.ts +58 -58
  40. package/dist/tools/code-function-rename-apply.d.ts +12 -12
  41. package/dist/tools/code-function-rename-prepare.d.ts +14 -14
  42. package/dist/tools/code-function-rename-review.d.ts +66 -66
  43. package/dist/tools/code-functions-define.d.ts +337 -0
  44. package/dist/tools/code-functions-define.js +337 -0
  45. package/dist/tools/code-functions-list.js +1 -1
  46. package/dist/tools/code-functions-rank.js +1 -1
  47. package/dist/tools/code-functions-reconstruct.d.ts +368 -58
  48. package/dist/tools/code-functions-reconstruct.js +130 -10
  49. package/dist/tools/code-functions-smart-recover.d.ts +352 -0
  50. package/dist/tools/code-functions-smart-recover.js +190 -0
  51. package/dist/tools/code-module-review-apply.d.ts +233 -0
  52. package/dist/tools/code-module-review-apply.js +209 -0
  53. package/dist/tools/code-module-review-prepare.d.ts +756 -0
  54. package/dist/tools/code-module-review-prepare.js +343 -0
  55. package/dist/tools/code-module-review.d.ts +474 -0
  56. package/dist/tools/code-module-review.js +566 -0
  57. package/dist/tools/code-reconstruct-export.d.ts +193 -21
  58. package/dist/tools/code-reconstruct-export.js +578 -21
  59. package/dist/tools/code-reconstruct-plan.d.ts +20 -20
  60. package/dist/tools/com-role-profile.d.ts +353 -0
  61. package/dist/tools/com-role-profile.js +186 -0
  62. package/dist/tools/dll-export-profile.d.ts +625 -0
  63. package/dist/tools/dll-export-profile.js +230 -0
  64. package/dist/tools/dotnet-metadata-extract.d.ts +122 -122
  65. package/dist/tools/dotnet-reconstruct-export.d.ts +49 -49
  66. package/dist/tools/dotnet-types-list.d.ts +66 -66
  67. package/dist/tools/dynamic-dependencies.d.ts +144 -8
  68. package/dist/tools/dynamic-dependencies.js +20 -1
  69. package/dist/tools/dynamic-memory-import.js +105 -2
  70. package/dist/tools/ghidra-analyze.d.ts +20 -0
  71. package/dist/tools/ghidra-analyze.js +10 -2
  72. package/dist/tools/ghidra-health.d.ts +177 -0
  73. package/dist/tools/ghidra-health.js +28 -0
  74. package/dist/tools/ioc-export.d.ts +8 -8
  75. package/dist/tools/packer-detect.d.ts +14 -14
  76. package/dist/tools/packer-detect.js +6 -9
  77. package/dist/tools/pe-exports-extract.d.ts +8 -8
  78. package/dist/tools/pe-exports-extract.js +6 -9
  79. package/dist/tools/pe-fingerprint.d.ts +36 -36
  80. package/dist/tools/pe-imports-extract.d.ts +8 -8
  81. package/dist/tools/pe-imports-extract.js +6 -9
  82. package/dist/tools/pe-pdata-extract.d.ts +448 -0
  83. package/dist/tools/pe-pdata-extract.js +219 -0
  84. package/dist/tools/pe-symbols-recover.d.ts +227 -0
  85. package/dist/tools/pe-symbols-recover.js +316 -0
  86. package/dist/tools/report-generate.d.ts +15 -1
  87. package/dist/tools/report-generate.js +139 -16
  88. package/dist/tools/report-summarize.d.ts +2242 -8
  89. package/dist/tools/report-summarize.js +246 -10
  90. package/dist/tools/runtime-detect.d.ts +8 -8
  91. package/dist/tools/runtime-detect.js +2 -12
  92. package/dist/tools/rust-binary-analyze.d.ts +2047 -0
  93. package/dist/tools/rust-binary-analyze.js +443 -0
  94. package/dist/tools/sample-profile-get.d.ts +135 -16
  95. package/dist/tools/sample-profile-get.js +35 -32
  96. package/dist/tools/sandbox-execute.d.ts +10 -10
  97. package/dist/tools/strings-extract.d.ts +8 -8
  98. package/dist/tools/strings-extract.js +2 -12
  99. package/dist/tools/strings-floss-decode.d.ts +8 -8
  100. package/dist/tools/system-health.d.ts +172 -36
  101. package/dist/tools/system-health.js +14 -0
  102. package/dist/tools/system-setup-guide.d.ts +179 -0
  103. package/dist/tools/system-setup-guide.js +62 -0
  104. package/dist/tools/tool-help.d.ts +16 -16
  105. package/dist/tools/tool-help.js +172 -0
  106. package/dist/tools/yara-scan.d.ts +8 -8
  107. package/dist/types.d.ts +2 -0
  108. package/dist/workflows/function-explanation-review.d.ts +3034 -76
  109. package/dist/workflows/function-explanation-review.js +172 -42
  110. package/dist/workflows/function-index-recover.d.ts +333 -0
  111. package/dist/workflows/function-index-recover.js +291 -0
  112. package/dist/workflows/module-reconstruction-review.d.ts +3537 -0
  113. package/dist/workflows/module-reconstruction-review.js +354 -0
  114. package/dist/workflows/reconstruct.d.ts +2182 -223
  115. package/dist/workflows/reconstruct.js +575 -32
  116. package/dist/workflows/semantic-name-review.d.ts +1436 -85
  117. package/dist/workflows/semantic-name-review.js +150 -58
  118. package/dist/workflows/triage.d.ts +8 -8
  119. package/ghidra_scripts/DecompileFunction.java +487 -487
  120. package/ghidra_scripts/ExtractCFG.java +256 -256
  121. package/ghidra_scripts/ExtractFunctions.java +442 -442
  122. package/ghidra_scripts/README.md +112 -112
  123. package/ghidra_scripts/SearchFunctionReferences.java +380 -380
  124. package/helpers/DotNetMetadataProbe/DotNetMetadataProbe.csproj +9 -9
  125. package/helpers/DotNetMetadataProbe/Program.cs +566 -566
  126. package/install-to-claude.ps1 +432 -0
  127. package/install-to-codex.ps1 +256 -178
  128. package/install-to-copilot.ps1 +389 -303
  129. package/package.json +4 -2
  130. package/requirements.txt +9 -9
  131. package/workers/requirements-dynamic.txt +11 -11
  132. package/workers/requirements.txt +8 -8
  133. package/workers/speakeasy_compat.py +175 -175
  134. package/workers/static_worker.py +3474 -3474
@@ -0,0 +1,190 @@
1
+ import { z } from 'zod';
2
+ import { generateCacheKey } from '../cache-manager.js';
3
+ import { lookupCachedResult, formatCacheWarning } from './cache-observability.js';
4
+ import { smartRecoverFunctionsFromPE } from '../pe-runtime-functions.js';
5
+ import { resolvePrimarySamplePath } from '../sample-workspace.js';
6
+ const TOOL_NAME = 'code.functions.smart_recover';
7
+ const TOOL_VERSION = '0.1.0';
8
+ const CACHE_TTL_MS = 30 * 24 * 60 * 60 * 1000;
9
+ export const codeFunctionsSmartRecoverInputSchema = z.object({
10
+ sample_id: z.string().describe('Sample ID (format: sha256:<hex>)'),
11
+ force_refresh: z
12
+ .boolean()
13
+ .optional()
14
+ .default(false)
15
+ .describe('Bypass cache lookup and recompute from source sample'),
16
+ });
17
+ export const codeFunctionsSmartRecoverOutputSchema = z.object({
18
+ ok: z.boolean(),
19
+ data: z
20
+ .object({
21
+ machine: z.number(),
22
+ machine_name: z.string(),
23
+ image_base: z.number(),
24
+ entry_point_rva: z.number(),
25
+ strategy: z.array(z.string()),
26
+ count: z.number(),
27
+ functions: z.array(z.object({
28
+ address: z.string(),
29
+ va: z.number(),
30
+ rva: z.number(),
31
+ size: z.number(),
32
+ name: z.string(),
33
+ name_source: z.enum(['entry_point', 'export', 'synthetic_sub']),
34
+ confidence: z.number(),
35
+ source: z.enum(['pdata_runtime_function', 'entry_point_only']),
36
+ section_name: z.string().nullable(),
37
+ executable_section: z.boolean(),
38
+ is_entry_point: z.boolean(),
39
+ is_exported: z.boolean(),
40
+ export_name: z.string().optional(),
41
+ evidence: z.array(z.string()),
42
+ unwind: z
43
+ .object({
44
+ version: z.number(),
45
+ flags: z.number(),
46
+ flag_names: z.array(z.string()),
47
+ prolog_size: z.number(),
48
+ unwind_code_count: z.number(),
49
+ frame_register: z.string().nullable(),
50
+ frame_register_id: z.number(),
51
+ frame_offset: z.number(),
52
+ handler_rva: z.number().optional(),
53
+ chained_runtime_function: z
54
+ .object({
55
+ begin_rva: z.number(),
56
+ end_rva: z.number(),
57
+ unwind_info_rva: z.number(),
58
+ })
59
+ .optional(),
60
+ })
61
+ .nullable()
62
+ .optional(),
63
+ })),
64
+ warnings: z.array(z.string()),
65
+ })
66
+ .optional(),
67
+ warnings: z.array(z.string()).optional(),
68
+ errors: z.array(z.string()).optional(),
69
+ metrics: z
70
+ .object({
71
+ elapsed_ms: z.number(),
72
+ tool: z.string(),
73
+ })
74
+ .optional(),
75
+ });
76
+ export const codeFunctionsSmartRecoverToolDefinition = {
77
+ name: TOOL_NAME,
78
+ description: 'Recover function candidates heuristically from PE runtime metadata such as .pdata / exception directory, exports, and entry point.',
79
+ inputSchema: codeFunctionsSmartRecoverInputSchema,
80
+ outputSchema: codeFunctionsSmartRecoverOutputSchema,
81
+ };
82
+ export function createCodeFunctionsSmartRecoverHandler(workspaceManager, database, cacheManager) {
83
+ return async (args) => {
84
+ const input = args;
85
+ const startTime = Date.now();
86
+ try {
87
+ const sample = database.findSample(input.sample_id);
88
+ if (!sample) {
89
+ return {
90
+ ok: false,
91
+ errors: [`Sample not found: ${input.sample_id}`],
92
+ };
93
+ }
94
+ const cacheKey = generateCacheKey({
95
+ sampleSha256: sample.sha256,
96
+ toolName: TOOL_NAME,
97
+ toolVersion: TOOL_VERSION,
98
+ args: {},
99
+ });
100
+ if (!input.force_refresh) {
101
+ const cachedLookup = await lookupCachedResult(cacheManager, cacheKey);
102
+ if (cachedLookup) {
103
+ return {
104
+ ok: true,
105
+ data: cachedLookup.data,
106
+ warnings: ['Result from cache', formatCacheWarning(cachedLookup.metadata)],
107
+ metrics: {
108
+ elapsed_ms: Date.now() - startTime,
109
+ tool: TOOL_NAME,
110
+ cached: true,
111
+ cache_key: cachedLookup.metadata.key,
112
+ cache_tier: cachedLookup.metadata.tier,
113
+ cache_created_at: cachedLookup.metadata.createdAt,
114
+ cache_expires_at: cachedLookup.metadata.expiresAt,
115
+ cache_hit_at: cachedLookup.metadata.fetchedAt,
116
+ },
117
+ };
118
+ }
119
+ }
120
+ const { samplePath } = await resolvePrimarySamplePath(workspaceManager, input.sample_id);
121
+ const result = smartRecoverFunctionsFromPE(samplePath);
122
+ const normalized = {
123
+ machine: result.machine,
124
+ machine_name: result.machineName,
125
+ image_base: result.imageBase,
126
+ entry_point_rva: result.entryPointRva,
127
+ strategy: result.strategy,
128
+ count: result.count,
129
+ functions: result.functions.map((item) => ({
130
+ address: item.address,
131
+ va: item.va,
132
+ rva: item.rva,
133
+ size: item.size,
134
+ name: item.name,
135
+ name_source: item.nameSource,
136
+ confidence: item.confidence,
137
+ source: item.source,
138
+ section_name: item.sectionName,
139
+ executable_section: item.executableSection,
140
+ is_entry_point: item.isEntryPoint,
141
+ is_exported: item.isExported,
142
+ export_name: item.exportName,
143
+ evidence: item.evidence,
144
+ unwind: item.unwind
145
+ ? {
146
+ version: item.unwind.version,
147
+ flags: item.unwind.flags,
148
+ flag_names: item.unwind.flagNames,
149
+ prolog_size: item.unwind.prologSize,
150
+ unwind_code_count: item.unwind.unwindCodeCount,
151
+ frame_register: item.unwind.frameRegister,
152
+ frame_register_id: item.unwind.frameRegisterId,
153
+ frame_offset: item.unwind.frameOffset,
154
+ handler_rva: item.unwind.handlerRva,
155
+ chained_runtime_function: item.unwind.chainedRuntimeFunction
156
+ ? {
157
+ begin_rva: item.unwind.chainedRuntimeFunction.beginRva,
158
+ end_rva: item.unwind.chainedRuntimeFunction.endRva,
159
+ unwind_info_rva: item.unwind.chainedRuntimeFunction.unwindInfoRva,
160
+ }
161
+ : undefined,
162
+ }
163
+ : null,
164
+ })),
165
+ warnings: result.warnings,
166
+ };
167
+ await cacheManager.setCachedResult(cacheKey, normalized, CACHE_TTL_MS, sample.sha256);
168
+ return {
169
+ ok: true,
170
+ data: normalized,
171
+ warnings: result.warnings.length > 0 ? result.warnings : undefined,
172
+ metrics: {
173
+ elapsed_ms: Date.now() - startTime,
174
+ tool: TOOL_NAME,
175
+ },
176
+ };
177
+ }
178
+ catch (error) {
179
+ return {
180
+ ok: false,
181
+ errors: [error instanceof Error ? error.message : String(error)],
182
+ metrics: {
183
+ elapsed_ms: Date.now() - startTime,
184
+ tool: TOOL_NAME,
185
+ },
186
+ };
187
+ }
188
+ };
189
+ }
190
+ //# sourceMappingURL=code-functions-smart-recover.js.map
@@ -0,0 +1,233 @@
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 codeModuleReviewApplyInputSchema: z.ZodObject<{
6
+ sample_id: z.ZodString;
7
+ reviews: z.ZodArray<z.ZodObject<{
8
+ module_name: z.ZodString;
9
+ refined_name: z.ZodOptional<z.ZodString>;
10
+ summary: z.ZodString;
11
+ role_hint: z.ZodOptional<z.ZodString>;
12
+ confidence: z.ZodNumber;
13
+ assumptions: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodString, "many">>>;
14
+ evidence_used: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodString, "many">>>;
15
+ rewrite_guidance: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
16
+ focus_areas: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodString, "many">>>;
17
+ priority_functions: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodString, "many">>>;
18
+ }, "strip", z.ZodTypeAny, {
19
+ summary: string;
20
+ confidence: number;
21
+ module_name: string;
22
+ evidence_used: string[];
23
+ assumptions: string[];
24
+ focus_areas: string[];
25
+ priority_functions: string[];
26
+ role_hint?: string | undefined;
27
+ refined_name?: string | undefined;
28
+ rewrite_guidance?: string | string[] | undefined;
29
+ }, {
30
+ summary: string;
31
+ confidence: number;
32
+ module_name: string;
33
+ evidence_used?: string[] | undefined;
34
+ role_hint?: string | undefined;
35
+ refined_name?: string | undefined;
36
+ assumptions?: string[] | undefined;
37
+ rewrite_guidance?: string | string[] | undefined;
38
+ focus_areas?: string[] | undefined;
39
+ priority_functions?: string[] | undefined;
40
+ }>, "many">;
41
+ client_name: z.ZodOptional<z.ZodString>;
42
+ model_name: z.ZodOptional<z.ZodString>;
43
+ prepare_artifact_id: z.ZodOptional<z.ZodString>;
44
+ session_tag: z.ZodOptional<z.ZodString>;
45
+ }, "strip", z.ZodTypeAny, {
46
+ sample_id: string;
47
+ reviews: {
48
+ summary: string;
49
+ confidence: number;
50
+ module_name: string;
51
+ evidence_used: string[];
52
+ assumptions: string[];
53
+ focus_areas: string[];
54
+ priority_functions: string[];
55
+ role_hint?: string | undefined;
56
+ refined_name?: string | undefined;
57
+ rewrite_guidance?: string | string[] | undefined;
58
+ }[];
59
+ session_tag?: string | undefined;
60
+ client_name?: string | undefined;
61
+ model_name?: string | undefined;
62
+ prepare_artifact_id?: string | undefined;
63
+ }, {
64
+ sample_id: string;
65
+ reviews: {
66
+ summary: string;
67
+ confidence: number;
68
+ module_name: string;
69
+ evidence_used?: string[] | undefined;
70
+ role_hint?: string | undefined;
71
+ refined_name?: string | undefined;
72
+ assumptions?: string[] | undefined;
73
+ rewrite_guidance?: string | string[] | undefined;
74
+ focus_areas?: string[] | undefined;
75
+ priority_functions?: string[] | undefined;
76
+ }[];
77
+ session_tag?: string | undefined;
78
+ client_name?: string | undefined;
79
+ model_name?: string | undefined;
80
+ prepare_artifact_id?: string | undefined;
81
+ }>;
82
+ export declare const codeModuleReviewApplyOutputSchema: z.ZodObject<{
83
+ ok: z.ZodBoolean;
84
+ data: z.ZodOptional<z.ZodObject<{
85
+ sample_id: z.ZodString;
86
+ accepted_count: z.ZodNumber;
87
+ rejected_count: z.ZodNumber;
88
+ accepted_reviews: z.ZodArray<z.ZodObject<{
89
+ module_name: z.ZodString;
90
+ refined_name: z.ZodNullable<z.ZodString>;
91
+ confidence: z.ZodNumber;
92
+ rewrite_guidance_count: z.ZodNumber;
93
+ }, "strip", z.ZodTypeAny, {
94
+ confidence: number;
95
+ module_name: string;
96
+ refined_name: string | null;
97
+ rewrite_guidance_count: number;
98
+ }, {
99
+ confidence: number;
100
+ module_name: string;
101
+ refined_name: string | null;
102
+ rewrite_guidance_count: number;
103
+ }>, "many">;
104
+ artifact: z.ZodObject<{
105
+ id: z.ZodString;
106
+ type: z.ZodLiteral<"semantic_module_reviews">;
107
+ path: z.ZodString;
108
+ sha256: z.ZodString;
109
+ mime: z.ZodOptional<z.ZodString>;
110
+ }, "strip", z.ZodTypeAny, {
111
+ path: string;
112
+ type: "semantic_module_reviews";
113
+ id: string;
114
+ sha256: string;
115
+ mime?: string | undefined;
116
+ }, {
117
+ path: string;
118
+ type: "semantic_module_reviews";
119
+ id: string;
120
+ sha256: string;
121
+ mime?: string | undefined;
122
+ }>;
123
+ next_steps: z.ZodArray<z.ZodString, "many">;
124
+ }, "strip", z.ZodTypeAny, {
125
+ sample_id: string;
126
+ artifact: {
127
+ path: string;
128
+ type: "semantic_module_reviews";
129
+ id: string;
130
+ sha256: string;
131
+ mime?: string | undefined;
132
+ };
133
+ next_steps: string[];
134
+ accepted_count: number;
135
+ rejected_count: number;
136
+ accepted_reviews: {
137
+ confidence: number;
138
+ module_name: string;
139
+ refined_name: string | null;
140
+ rewrite_guidance_count: number;
141
+ }[];
142
+ }, {
143
+ sample_id: string;
144
+ artifact: {
145
+ path: string;
146
+ type: "semantic_module_reviews";
147
+ id: string;
148
+ sha256: string;
149
+ mime?: string | undefined;
150
+ };
151
+ next_steps: string[];
152
+ accepted_count: number;
153
+ rejected_count: number;
154
+ accepted_reviews: {
155
+ confidence: number;
156
+ module_name: string;
157
+ refined_name: string | null;
158
+ rewrite_guidance_count: number;
159
+ }[];
160
+ }>>;
161
+ warnings: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
162
+ errors: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
163
+ artifacts: z.ZodOptional<z.ZodArray<z.ZodAny, "many">>;
164
+ metrics: z.ZodOptional<z.ZodObject<{
165
+ elapsed_ms: z.ZodNumber;
166
+ tool: z.ZodString;
167
+ }, "strip", z.ZodTypeAny, {
168
+ elapsed_ms: number;
169
+ tool: string;
170
+ }, {
171
+ elapsed_ms: number;
172
+ tool: string;
173
+ }>>;
174
+ }, "strip", z.ZodTypeAny, {
175
+ ok: boolean;
176
+ data?: {
177
+ sample_id: string;
178
+ artifact: {
179
+ path: string;
180
+ type: "semantic_module_reviews";
181
+ id: string;
182
+ sha256: string;
183
+ mime?: string | undefined;
184
+ };
185
+ next_steps: string[];
186
+ accepted_count: number;
187
+ rejected_count: number;
188
+ accepted_reviews: {
189
+ confidence: number;
190
+ module_name: string;
191
+ refined_name: string | null;
192
+ rewrite_guidance_count: number;
193
+ }[];
194
+ } | undefined;
195
+ metrics?: {
196
+ elapsed_ms: number;
197
+ tool: string;
198
+ } | undefined;
199
+ warnings?: string[] | undefined;
200
+ errors?: string[] | undefined;
201
+ artifacts?: any[] | undefined;
202
+ }, {
203
+ ok: boolean;
204
+ data?: {
205
+ sample_id: string;
206
+ artifact: {
207
+ path: string;
208
+ type: "semantic_module_reviews";
209
+ id: string;
210
+ sha256: string;
211
+ mime?: string | undefined;
212
+ };
213
+ next_steps: string[];
214
+ accepted_count: number;
215
+ rejected_count: number;
216
+ accepted_reviews: {
217
+ confidence: number;
218
+ module_name: string;
219
+ refined_name: string | null;
220
+ rewrite_guidance_count: number;
221
+ }[];
222
+ } | undefined;
223
+ metrics?: {
224
+ elapsed_ms: number;
225
+ tool: string;
226
+ } | undefined;
227
+ warnings?: string[] | undefined;
228
+ errors?: string[] | undefined;
229
+ artifacts?: any[] | undefined;
230
+ }>;
231
+ export declare const codeModuleReviewApplyToolDefinition: ToolDefinition;
232
+ export declare function createCodeModuleReviewApplyHandler(workspaceManager: WorkspaceManager, database: DatabaseManager): (args: ToolArgs) => Promise<WorkerResult>;
233
+ //# sourceMappingURL=code-module-review-apply.d.ts.map
@@ -0,0 +1,209 @@
1
+ import { z } from 'zod';
2
+ import { persistSemanticModuleReviewsArtifact, SEMANTIC_MODULE_REVIEWS_ARTIFACT_TYPE, } from '../semantic-name-suggestion-artifacts.js';
3
+ const TOOL_NAME = 'code.module.review.apply';
4
+ const ModuleReviewInputSchema = z.object({
5
+ module_name: z.string().min(1).max(120).describe('Module name as returned by code.reconstruct.export'),
6
+ refined_name: z
7
+ .string()
8
+ .min(1)
9
+ .max(120)
10
+ .optional()
11
+ .describe('Optional refined human-readable module display name'),
12
+ summary: z.string().min(1).max(1600).describe('Evidence-grounded plain-language explanation of the module'),
13
+ role_hint: z
14
+ .string()
15
+ .min(1)
16
+ .max(240)
17
+ .optional()
18
+ .describe('Optional refined module role hint, such as export dispatch or COM activation'),
19
+ confidence: z.number().min(0).max(1).describe('Heuristic support score for the module review'),
20
+ assumptions: z.array(z.string()).optional().default([]).describe('Assumptions that must hold for the review to remain valid'),
21
+ evidence_used: z.array(z.string()).optional().default([]).describe('Evidence sources used by the external LLM'),
22
+ rewrite_guidance: z
23
+ .union([z.string().min(1), z.array(z.string().min(1))])
24
+ .optional()
25
+ .describe('One or more rewrite-oriented guidance items derived from the evidence'),
26
+ focus_areas: z
27
+ .array(z.string().min(1))
28
+ .optional()
29
+ .default([])
30
+ .describe('Optional high-value focus areas inside the module'),
31
+ priority_functions: z
32
+ .array(z.string().min(1))
33
+ .optional()
34
+ .default([])
35
+ .describe('Optional function names or addresses that should be prioritized inside the module'),
36
+ });
37
+ function normalizeStringArray(input, limit = 12) {
38
+ if (!input) {
39
+ return [];
40
+ }
41
+ const values = Array.isArray(input) ? input : [input];
42
+ return values.map((item) => item.trim()).filter((item) => item.length > 0).slice(0, limit);
43
+ }
44
+ export const codeModuleReviewApplyInputSchema = z.object({
45
+ sample_id: z.string().describe('Sample ID (format: sha256:<hex>)'),
46
+ reviews: z
47
+ .array(ModuleReviewInputSchema)
48
+ .min(1)
49
+ .describe('Structured module review outputs returned by an external MCP client / LLM'),
50
+ client_name: z
51
+ .string()
52
+ .optional()
53
+ .describe('Optional client identifier, such as claude-desktop or codex-cli'),
54
+ model_name: z
55
+ .string()
56
+ .optional()
57
+ .describe('Optional model identifier for provenance only'),
58
+ prepare_artifact_id: z
59
+ .string()
60
+ .optional()
61
+ .describe('Optional semantic_module_review_prepare_bundle artifact ID that produced this review task'),
62
+ session_tag: z
63
+ .string()
64
+ .optional()
65
+ .describe('Optional semantic module review session tag used for artifact grouping'),
66
+ });
67
+ export const codeModuleReviewApplyOutputSchema = z.object({
68
+ ok: z.boolean(),
69
+ data: z
70
+ .object({
71
+ sample_id: z.string(),
72
+ accepted_count: z.number().int().nonnegative(),
73
+ rejected_count: z.number().int().nonnegative(),
74
+ accepted_reviews: z.array(z.object({
75
+ module_name: z.string(),
76
+ refined_name: z.string().nullable(),
77
+ confidence: z.number().min(0).max(1),
78
+ rewrite_guidance_count: z.number().int().nonnegative(),
79
+ })),
80
+ artifact: z.object({
81
+ id: z.string(),
82
+ type: z.literal(SEMANTIC_MODULE_REVIEWS_ARTIFACT_TYPE),
83
+ path: z.string(),
84
+ sha256: z.string(),
85
+ mime: z.string().optional(),
86
+ }),
87
+ next_steps: z.array(z.string()),
88
+ })
89
+ .optional(),
90
+ warnings: z.array(z.string()).optional(),
91
+ errors: z.array(z.string()).optional(),
92
+ artifacts: z.array(z.any()).optional(),
93
+ metrics: z
94
+ .object({
95
+ elapsed_ms: z.number(),
96
+ tool: z.string(),
97
+ })
98
+ .optional(),
99
+ });
100
+ export const codeModuleReviewApplyToolDefinition = {
101
+ name: TOOL_NAME,
102
+ description: 'Persist structured module review outputs returned by any external MCP client / LLM so export and workflow layers can consume them.',
103
+ inputSchema: codeModuleReviewApplyInputSchema,
104
+ outputSchema: codeModuleReviewApplyOutputSchema,
105
+ };
106
+ export function createCodeModuleReviewApplyHandler(workspaceManager, database) {
107
+ return async (args) => {
108
+ const startTime = Date.now();
109
+ try {
110
+ const input = codeModuleReviewApplyInputSchema.parse(args);
111
+ const sample = database.findSample(input.sample_id);
112
+ if (!sample) {
113
+ return {
114
+ ok: false,
115
+ errors: [`Sample not found: ${input.sample_id}`],
116
+ metrics: {
117
+ elapsed_ms: Date.now() - startTime,
118
+ tool: TOOL_NAME,
119
+ },
120
+ };
121
+ }
122
+ const acceptedReviews = [];
123
+ const acceptedSummary = [];
124
+ const warnings = [];
125
+ for (const review of input.reviews) {
126
+ const moduleName = review.module_name.trim();
127
+ const summary = review.summary.trim();
128
+ if (moduleName.length === 0 || summary.length === 0) {
129
+ warnings.push('Rejected module review because module_name or summary was empty after normalization.');
130
+ continue;
131
+ }
132
+ const rewriteGuidance = normalizeStringArray(review.rewrite_guidance, 10);
133
+ const focusAreas = normalizeStringArray(review.focus_areas, 10);
134
+ const priorityFunctions = normalizeStringArray(review.priority_functions, 16);
135
+ acceptedReviews.push({
136
+ module_name: moduleName,
137
+ refined_name: review.refined_name?.trim() || null,
138
+ summary,
139
+ role_hint: review.role_hint?.trim() || null,
140
+ confidence: review.confidence,
141
+ assumptions: review.assumptions || [],
142
+ evidence_used: review.evidence_used || [],
143
+ rewrite_guidance: rewriteGuidance,
144
+ focus_areas: focusAreas,
145
+ priority_functions: priorityFunctions,
146
+ });
147
+ acceptedSummary.push({
148
+ module_name: moduleName,
149
+ refined_name: review.refined_name?.trim() || null,
150
+ confidence: review.confidence,
151
+ rewrite_guidance_count: rewriteGuidance.length,
152
+ });
153
+ }
154
+ if (acceptedReviews.length === 0) {
155
+ return {
156
+ ok: false,
157
+ errors: ['No module reviews were accepted after normalization.'],
158
+ warnings: warnings.length > 0 ? warnings : undefined,
159
+ metrics: {
160
+ elapsed_ms: Date.now() - startTime,
161
+ tool: TOOL_NAME,
162
+ },
163
+ };
164
+ }
165
+ const payload = {
166
+ schema_version: 1,
167
+ sample_id: input.sample_id,
168
+ created_at: new Date().toISOString(),
169
+ session_tag: input.session_tag || null,
170
+ client_name: input.client_name || null,
171
+ model_name: input.model_name || null,
172
+ prepare_artifact_id: input.prepare_artifact_id || null,
173
+ reviews: acceptedReviews,
174
+ };
175
+ const artifact = await persistSemanticModuleReviewsArtifact(workspaceManager, database, payload);
176
+ return {
177
+ ok: true,
178
+ data: {
179
+ sample_id: input.sample_id,
180
+ accepted_count: acceptedReviews.length,
181
+ rejected_count: input.reviews.length - acceptedReviews.length,
182
+ accepted_reviews: acceptedSummary,
183
+ artifact,
184
+ next_steps: [
185
+ 'rerun code.reconstruct.export to propagate module review summaries and rewrite guidance into rewrite output',
186
+ 'rerun workflow.reconstruct if you want refreshed role-aware export output',
187
+ ],
188
+ },
189
+ warnings: warnings.length > 0 ? warnings : undefined,
190
+ artifacts: [artifact],
191
+ metrics: {
192
+ elapsed_ms: Date.now() - startTime,
193
+ tool: TOOL_NAME,
194
+ },
195
+ };
196
+ }
197
+ catch (error) {
198
+ return {
199
+ ok: false,
200
+ errors: [error instanceof Error ? error.message : String(error)],
201
+ metrics: {
202
+ elapsed_ms: Date.now() - startTime,
203
+ tool: TOOL_NAME,
204
+ },
205
+ };
206
+ }
207
+ };
208
+ }
209
+ //# sourceMappingURL=code-module-review-apply.js.map