@eyeauras/insight-cli 0.7.0 → 0.8.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.
Files changed (117) hide show
  1. package/.cli-package-build.json +1 -1
  2. package/SKILL.md +1 -1
  3. package/dist/src/activity-audit.d.ts +7 -0
  4. package/dist/src/activity-audit.js +14 -4
  5. package/dist/src/analysis-storage.d.ts +5 -1
  6. package/dist/src/analysis-storage.js +9 -2
  7. package/dist/src/audit-retention.d.ts +8 -2
  8. package/dist/src/audit-retention.js +68 -7
  9. package/dist/src/cli.js +19 -5
  10. package/dist/src/context-diagnostics.d.ts +1 -1
  11. package/dist/src/context-diagnostics.js +10 -2
  12. package/dist/src/contexts.d.ts +118 -10
  13. package/dist/src/contexts.js +851 -199
  14. package/dist/src/debugger.js +2 -1
  15. package/dist/src/diagnostic-error.js +1 -1
  16. package/dist/src/inline-script.js +3 -4
  17. package/dist/src/lifecycle.d.ts +11 -0
  18. package/dist/src/lifecycle.js +34 -6
  19. package/dist/src/native-inputs.d.ts +6 -0
  20. package/dist/src/native-inputs.js +30 -6
  21. package/dist/src/native-queries.js +1 -6
  22. package/dist/src/native-service.d.ts +40 -0
  23. package/dist/src/native-service.js +406 -0
  24. package/dist/src/research.d.ts +29 -1
  25. package/dist/src/research.js +106 -27
  26. package/dist/src/server.d.ts +38 -1
  27. package/dist/src/server.js +160 -12
  28. package/dist/src/storage-gc.js +1 -1
  29. package/dist/src/sync-policy.js +2 -1
  30. package/dist/src/timed-backend.js +8 -0
  31. package/dist/src/timing-report.d.ts +32 -0
  32. package/dist/src/timing-report.js +74 -0
  33. package/dist/src/tool-runtime/identity.js +86 -1
  34. package/dist/src/tool-runtime/supervisor.js +6 -5
  35. package/dist/src/transport.d.ts +35 -0
  36. package/dist/src/transport.js +77 -7
  37. package/dist/src/unresolved-guidance.d.ts +46 -0
  38. package/dist/src/unresolved-guidance.js +55 -0
  39. package/dist/src/windbg.d.ts +1 -1
  40. package/dist/src/worker-lease.d.ts +17 -0
  41. package/dist/src/worker-lease.js +50 -0
  42. package/dist/src/workspace.d.ts +3 -9
  43. package/dist/src/workspace.js +9 -41
  44. package/package.json +1 -1
  45. package/references/native/InsightHeadlessMain.java +9 -2
  46. package/references/native/InsightNativeCheckout.java +113 -43
  47. package/references/native/InsightNativeFingerprint.java +28 -1
  48. package/references/native/InsightNativeRead.java +32 -9
  49. package/references/native/InsightNativeService.java +43 -0
  50. package/references/native/InsightNativeView.java +17 -6
  51. package/references/native/InsightOwnedScripts.java +170 -0
  52. package/references/native/InsightWorkerLease.java +132 -0
  53. package/references/recovery.md +68 -3
  54. package/references/research.md +38 -4
  55. package/references/setup.md +5 -1
  56. package/skill-bundle/insight-artifacts/SKILL.md +1 -1
  57. package/skill-bundle/insight-artifacts/references/recovery.md +68 -3
  58. package/skill-bundle/insight-binary/SKILL.md +1 -1
  59. package/skill-bundle/insight-capture/SKILL.md +1 -1
  60. package/skill-bundle/insight-cli/SKILL.md +1 -1
  61. package/skill-bundle/insight-cli/references/recovery.md +68 -3
  62. package/skill-bundle/insight-cli/references/setup.md +5 -1
  63. package/skill-bundle/insight-die/SKILL.md +1 -1
  64. package/skill-bundle/insight-dnspy/SKILL.md +1 -1
  65. package/skill-bundle/insight-dotnet-dump/SKILL.md +1 -1
  66. package/skill-bundle/insight-dotnet-stack/SKILL.md +1 -1
  67. package/skill-bundle/insight-dotnet-trace/SKILL.md +1 -1
  68. package/skill-bundle/insight-frida/SKILL.md +1 -1
  69. package/skill-bundle/insight-ghidra/SKILL.md +1 -1
  70. package/skill-bundle/insight-ghidra/references/recovery.md +68 -3
  71. package/skill-bundle/insight-ghidra/references/research.md +38 -4
  72. package/skill-bundle/insight-ghidra/references/setup.md +5 -1
  73. package/skill-bundle/insight-ilspy/SKILL.md +1 -1
  74. package/skill-bundle/insight-interop/SKILL.md +1 -1
  75. package/skill-bundle/insight-lldb/SKILL.md +1 -1
  76. package/skill-bundle/insight-llvm/SKILL.md +1 -1
  77. package/skill-bundle/insight-managed-heap/SKILL.md +1 -1
  78. package/skill-bundle/insight-managed-metadata/SKILL.md +1 -1
  79. package/skill-bundle/insight-mitmproxy/SKILL.md +1 -1
  80. package/skill-bundle/insight-overview/SKILL.md +1 -1
  81. package/skill-bundle/insight-procmon/SKILL.md +1 -1
  82. package/skill-bundle/insight-re/SKILL.md +1 -1
  83. package/skill-bundle/insight-re/references/recovery.md +68 -3
  84. package/skill-bundle/insight-sevenzip/SKILL.md +1 -1
  85. package/skill-bundle/insight-strace/SKILL.md +1 -1
  86. package/skill-bundle/insight-tshark/SKILL.md +1 -1
  87. package/skill-bundle/insight-windbg/SKILL.md +1 -1
  88. package/skill-bundle/manifest.json +1 -1
  89. package/skills/insight-artifacts/SKILL.md +1 -1
  90. package/skills/insight-artifacts/references/recovery.md +68 -3
  91. package/skills/insight-binary/SKILL.md +1 -1
  92. package/skills/insight-capture/SKILL.md +1 -1
  93. package/skills/insight-die/SKILL.md +1 -1
  94. package/skills/insight-dnspy/SKILL.md +1 -1
  95. package/skills/insight-dotnet-dump/SKILL.md +1 -1
  96. package/skills/insight-dotnet-stack/SKILL.md +1 -1
  97. package/skills/insight-dotnet-trace/SKILL.md +1 -1
  98. package/skills/insight-frida/SKILL.md +1 -1
  99. package/skills/insight-ghidra/SKILL.md +1 -1
  100. package/skills/insight-ghidra/references/recovery.md +68 -3
  101. package/skills/insight-ghidra/references/research.md +38 -4
  102. package/skills/insight-ghidra/references/setup.md +5 -1
  103. package/skills/insight-ilspy/SKILL.md +1 -1
  104. package/skills/insight-interop/SKILL.md +1 -1
  105. package/skills/insight-lldb/SKILL.md +1 -1
  106. package/skills/insight-llvm/SKILL.md +1 -1
  107. package/skills/insight-managed-heap/SKILL.md +1 -1
  108. package/skills/insight-managed-metadata/SKILL.md +1 -1
  109. package/skills/insight-mitmproxy/SKILL.md +1 -1
  110. package/skills/insight-overview/SKILL.md +1 -1
  111. package/skills/insight-procmon/SKILL.md +1 -1
  112. package/skills/insight-re/SKILL.md +1 -1
  113. package/skills/insight-re/references/recovery.md +68 -3
  114. package/skills/insight-sevenzip/SKILL.md +1 -1
  115. package/skills/insight-strace/SKILL.md +1 -1
  116. package/skills/insight-tshark/SKILL.md +1 -1
  117. package/skills/insight-windbg/SKILL.md +1 -1
@@ -2,6 +2,7 @@ import { command, Permission } from '@eyeauras/cli-factory';
2
2
  import { resolve } from 'node:path';
3
3
  import { scope, address, number } from './research.js';
4
4
  import { id, text, object, fail } from './model.js';
5
+ import { failUnresolved } from './unresolved-guidance.js';
5
6
  import { selectedOptions } from './arguments.js';
6
7
  import { debuggerResult, debuggerExecutionSettled, debuggerProgramMetadata as metadata } from './debugger-results.js';
7
8
  import { setTimeout as delay } from 'node:timers/promises';
@@ -45,7 +46,7 @@ export class Debugger {
45
46
  fail('configuration', 'Selected backend lacks debugger support.');
46
47
  if (unresolved.length) {
47
48
  if (!reading || unresolved.some(request => object(request.execution ?? {}).kind !== 'debugger'))
48
- fail('blocked', 'Selected context retains an unresolved operation.');
49
+ failUnresolved(this.workspace, selected, 'Selected context retains an unresolved operation.');
49
50
  }
50
51
  else {
51
52
  await backend.open(selected);
@@ -16,7 +16,7 @@ const errorCodes = new Set([
16
16
  'coordinator.limit', 'coordinator.schema', 'coordinator.binding', 'coordinator.unknown', 'coordinator.blocked',
17
17
  'coordinator.busy', 'coordinator.conflict', 'coordinator.launch', 'coordinator.capacity', 'coordinator.invalid',
18
18
  'coordinator.migration', 'coordinator.configuration', 'coordinator.notFound', 'permission.denied', 'usage',
19
- 'tool.timeout', 'tool.cancelled', 'tool.output.limit', 'tool.exit.code', 'tool.launch',
19
+ 'tool.timeout', 'tool.cancelled', 'tool.output.limit', 'tool.exit.code', 'tool.launch', 'tool.notSent', 'coordinator.notSent', 'tool.termination.unverified',
20
20
  ]);
21
21
  function field(value, key) {
22
22
  try {
@@ -1,5 +1,5 @@
1
1
  import { createHash, randomUUID } from 'node:crypto';
2
- import { mkdir, writeFile, readFile, open } from 'node:fs/promises';
2
+ import { mkdir, writeFile, open } from 'node:fs/promises';
3
3
  import { constants } from 'node:fs';
4
4
  import { join } from 'node:path';
5
5
  import { object, fail } from './model.js';
@@ -32,9 +32,8 @@ export async function runInline(http, program, root, parameters, requestId) {
32
32
  await mkdir(directory, { recursive: true, mode: 0o700 });
33
33
  const request = join(directory, 'request.json');
34
34
  await writeFile(request, JSON.stringify({ attemptId, requestId, sourceSha256, code: parameters.code, args: parameters.args ?? '' }), { mode: 0o600, flag: 'wx' });
35
- const name = 'InsightInlineScript_' + randomUUID().replaceAll('-', ''), source = await readFile(new URL('../../references/native/InsightInlineScript.java', import.meta.url), 'utf8');
36
- // Only this fixed shim enters the upstream provider. User source is compiled separately.
37
- const ack = object(await http.call('/run_script_inline', { program, code: source.replace('public class InsightInlineScript ', 'public class ' + name + ' '), args: Buffer.from(request, 'utf8').toString('base64') }));
35
+ // Only this fixed shim enters the worker (in-process, or through the upstream provider). User source is compiled separately.
36
+ const ack = object(await http.script(program, 'InsightInlineScript', Buffer.from(request, 'utf8').toString('base64')));
38
37
  if (ack.success !== true || typeof ack.console_output !== 'string' || !ack.console_output.includes('INSIGHT_INLINE_COMPLETE'))
39
38
  fail('partial', 'Native inline-script executor did not acknowledge its completed attempt.');
40
39
  const handle = await open(join(directory, 'receipt.json'), constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0));
@@ -57,6 +57,17 @@ export declare class Lifecycle {
57
57
  }>;
58
58
  change(selected: Scope, operation: 'save' | 'close', callerId?: string): Promise<unknown>;
59
59
  discard(selected: Scope, callerId?: string): Promise<unknown>;
60
+ /**
61
+ * Settles what an interrupted Ghidra session left unsaved in the checkout. Ghidra's own recovery does the work and the
62
+ * command is safe to repeat, so it keeps no request of its own.
63
+ */
64
+ unsaved(selected: Scope, keep: boolean): Promise<{
65
+ state: "discarded" | "absent" | "recovered";
66
+ unpublishedChanges: boolean;
67
+ pendingChanges: number;
68
+ session: string;
69
+ target: string;
70
+ }>;
60
71
  /** Gives up detached work that has no native continuation. Nothing is replayed or published; a journal keeps its identity. */
61
72
  discardLegacy(selected: Scope, acknowledged: boolean, callerId?: string): Promise<unknown>;
62
73
  /** Gives up a native checkout whose project no longer exists. Only its exact server checkout is ended. */
@@ -2,6 +2,7 @@ import { command, Permission, CliError } from '@eyeauras/cli-factory';
2
2
  import { scope } from './research.js';
3
3
  import { legacyDiscardOperation, missingDiscardOperation } from './workspace.js';
4
4
  import { id, fail, object, digest } from './model.js';
5
+ import { failUnresolved } from './unresolved-guidance.js';
5
6
  import { selectedOptions } from './arguments.js';
6
7
  import { mkdir } from 'node:fs/promises';
7
8
  import { join } from 'node:path';
@@ -54,14 +55,18 @@ export class Lifecycle {
54
55
  const unresolved = this.workspace.unresolved(selected);
55
56
  const closingExternal = operation === 'close' && unresolved.length > 0 && unresolved.every(intent => ['debugger', 'ui'].includes(String(object(intent.execution ?? {}).kind)));
56
57
  const alreadyEnded = closingExternal && backend.closed ? await backend.closed(selected) : false;
57
- if (!closingExternal)
58
+ // A stopped worker left nothing unsaved (work is saved at acknowledgement): closing it needs no relaunch.
59
+ const stoppedWorker = operation === 'close' && !closingExternal && !unresolved.length && !settled.debugger?.connected && settled.workingSnapshot !== undefined &&
60
+ backend.closed ? await backend.closed(selected) : false;
61
+ if (!closingExternal && !stoppedWorker)
58
62
  await backend.open(selected);
59
63
  const before = this.workspace.context(selected);
60
64
  this.workspace.startRequest(request.id, { kind: operation, generation: before.generation, workingSnapshot: before.workingSnapshot });
61
65
  let savedSnapshot, checkout;
62
66
  try {
63
67
  if (operation === 'close' && !alreadyEnded) {
64
- await backend.close(selected);
68
+ if (!stoppedWorker)
69
+ await backend.close(selected);
65
70
  // The close is already complete. An unproved release only keeps the saved checkout.
66
71
  if (!unresolved.length && backend.releaseUnchanged)
67
72
  try {
@@ -149,6 +154,27 @@ export class Lifecycle {
149
154
  return result;
150
155
  });
151
156
  }
157
+ /**
158
+ * Settles what an interrupted Ghidra session left unsaved in the checkout. Ghidra's own recovery does the work and the
159
+ * command is safe to repeat, so it keeps no request of its own.
160
+ */
161
+ async unsaved(selected, keep) {
162
+ return this.research.ordered(selected, async () => {
163
+ const context = this.workspace.context(selected);
164
+ if (!context.nativeCheckout)
165
+ fail('unsupported', 'This context has no native checkout.');
166
+ // An edit or open whose outcome is unknown is settled by reading the program back, which needs these changes settled first.
167
+ if (this.workspace.unresolved(selected).some(intent => ['ghidra.merge', 'ghidra.refresh', 'ghidra.changes.discard'].includes(intent.operation)))
168
+ failUnresolved(this.workspace, selected, 'This context retains an unresolved native operation; settle it first.');
169
+ if (context.debugger?.connected)
170
+ fail('busy', 'Close the live debugger context first.');
171
+ const backend = await this.backend();
172
+ if (!backend.settleUnsaved)
173
+ fail('unsupported', 'The selected backend cannot settle unsaved changes of an interrupted session.');
174
+ const settled = await backend.settleUnsaved(selected, keep), current = this.workspace.context(selected);
175
+ return { ...selected, state: settled.state, unpublishedChanges: settled.modified, pendingChanges: current.scalars.length + current.complexChanges.length };
176
+ });
177
+ }
152
178
  /** Gives up detached work that has no native continuation. Nothing is replayed or published; a journal keeps its identity. */
153
179
  async discardLegacy(selected, acknowledged, callerId) {
154
180
  if (!acknowledged)
@@ -165,9 +191,9 @@ export class Lifecycle {
165
191
  if (current.nativeCheckout)
166
192
  fail('unsupported', 'This context uses a native checkout; use ghidra changes discard.');
167
193
  if (this.workspace.activePublication(selected.target))
168
- fail('blocked', 'Publication must be reconciled before discarding detached work.');
194
+ failUnresolved(this.workspace, selected, 'Publication must be reconciled before discarding detached work.');
169
195
  if (this.workspace.model(selected.target).state !== 'ready')
170
- fail('blocked', 'Initial publication of this model must be reconciled before discarding detached work.');
196
+ failUnresolved(this.workspace, selected, 'Initial publication of this model must be reconciled before discarding detached work.');
171
197
  if (current.debugger?.connected)
172
198
  fail('busy', 'Close the live debugger context before discarding it.');
173
199
  const backend = await this.backend();
@@ -199,9 +225,9 @@ export class Lifecycle {
199
225
  let checkout;
200
226
  try {
201
227
  if (this.workspace.activePublication(selected.target))
202
- fail('blocked', 'Publication must be reconciled before discarding a missing checkout.');
228
+ failUnresolved(this.workspace, selected, 'Publication must be reconciled before discarding a missing checkout.');
203
229
  if (this.workspace.model(selected.target).state !== 'ready')
204
- fail('blocked', 'Initial publication of this model must be reconciled before discarding a missing checkout.');
230
+ failUnresolved(this.workspace, selected, 'Initial publication of this model must be reconciled before discarding a missing checkout.');
205
231
  if (current.debugger?.connected)
206
232
  fail('busy', 'Close the live debugger context before discarding it.');
207
233
  if (this.workspace.checkoutReferenced(current))
@@ -272,6 +298,8 @@ export class Lifecycle {
272
298
  export function lifecycleCommands(service, runtimeStatus) {
273
299
  return [command('changes', 'Manage unpublished edits in the selected context', [
274
300
  command('discard', 'Retain native keep data, discard private edits and check out the current server version', ({ options: o }, c) => service(c).discard(scope(o), o.requestId === undefined ? undefined : id(o.requestId)), { permission: 'Destructive', options: [...selectedOptions, { flags: '--request-id <id>', description: 'Retrieve the same local discard result' }] }),
301
+ command('recover-unsaved', 'Restore and save the unsaved changes an interrupted Ghidra session left in the working copy', ({ options: o }, c) => service(c).unsaved(scope(o), true), { permission: Permission.Update, options: selectedOptions }),
302
+ command('discard-unsaved', 'Drop the unsaved changes an interrupted Ghidra session left in the working copy; saved work is kept', ({ options: o }, c) => service(c).unsaved(scope(o), false), { permission: 'Destructive', options: selectedOptions }),
275
303
  command('discard-legacy', 'Give up detached work of an older engine; gc then reclaims it and the next open starts a native checkout', ({ options: o }, c) => service(c).discardLegacy(scope(o), Boolean(o.acknowledgeLostWork), o.requestId === undefined ? undefined : id(o.requestId)), { permission: 'Destructive', options: [...selectedOptions, { flags: '--acknowledge-lost-work', description: 'Accept that unpublished edits and unknown outcomes of this context are dropped' }, { flags: '--request-id <id>', description: 'Retrieve the same discard result' }] }),
276
304
  command('discard-missing', 'Give up a native checkout whose project directory no longer exists and end its server checkout; the next open starts a new one', ({ options: o }, c) => service(c).discardMissing(scope(o), Boolean(o.acknowledgeLostWork), o.requestId === undefined ? undefined : id(o.requestId)), { permission: 'Destructive', options: [...selectedOptions, { flags: '--acknowledge-lost-work', description: 'Accept that unpublished edits and unknown outcomes of this context are lost' }, { flags: '--request-id <id>', description: 'Retrieve the same discard result' }] })
277
305
  ]),
@@ -24,6 +24,12 @@ export interface NativeRuntimeFile {
24
24
  export declare function nativeRuntimeFiles(ghidraHome: string, java: string): Promise<NativeRuntimeFile[]>;
25
25
  export declare function nativeRuntimeFingerprint(ghidraVersion: string, files: NativeRuntimeFile[]): Promise<string>;
26
26
  export declare function nativeInputs(values: Record<string, unknown>, directory?: string, c?: RunContext): Promise<NativeInputs>;
27
+ /**
28
+ * Identity of this package's helper sources as they are on disk now (never cached: a package can be replaced
29
+ * under a running owner). Compiled helper classes record the identity of the sources they were compiled from,
30
+ * and a worker runs its precompiled helper scripts only for a caller with that same identity.
31
+ */
32
+ export declare function helperSourcesKey(): Promise<string>;
27
33
  /** Compile packaged helper sources against the selected installation, never an author checkout. */
28
34
  export declare function nativeHelpers(directory: string, inputs: NativeInputs, c?: RunContext): Promise<string>;
29
35
  export declare const nativeExtensionArguments: (inputs: NativeInputs) => string[];
@@ -132,15 +132,30 @@ export async function nativeInputs(values, directory, c) {
132
132
  const fingerprint = modules.length ? await nativeRuntimeFingerprint(ghidraVersion, files) : baseFingerprint;
133
133
  return { java, ghidraHome, mcpJar, jars, classpath: jars.join(delimiter), ghidraVersion, fingerprint, debuggerWheels, extensionRoots: modules.map(m => m.root), serverClasspath: baseJars.join(delimiter) };
134
134
  }
135
- /** Compile packaged helper sources against the selected installation, never an author checkout. */
136
- export async function nativeHelpers(directory, inputs, c) {
135
+ async function helperSources() {
137
136
  const sources = fileURLToPath(new URL('../../references/native/', import.meta.url));
138
137
  const names = [...(await readdir(sources)).filter(name => name.endsWith('.java')), '../InsightRepositoryProbe.java'].sort();
139
138
  if (!names.length)
140
139
  fail('configuration', 'Installed package omitted its native helper sources.');
141
- const hashes = [];
142
- for (const name of names)
143
- hashes.push(await sha(join(sources, name)));
140
+ // Each source is read once: the bytes that are hashed are the bytes that are compiled.
141
+ const hashes = [], contents = [];
142
+ for (const name of names) {
143
+ const bytes = await readFile(join(sources, name));
144
+ contents.push(bytes);
145
+ hashes.push(createHash('sha256').update(bytes).digest('hex'));
146
+ }
147
+ return { names, hashes, contents };
148
+ }
149
+ const sourcesKey = (names, hashes) => createHash('sha256').update(stable([names, hashes])).digest('hex');
150
+ /**
151
+ * Identity of this package's helper sources as they are on disk now (never cached: a package can be replaced
152
+ * under a running owner). Compiled helper classes record the identity of the sources they were compiled from,
153
+ * and a worker runs its precompiled helper scripts only for a caller with that same identity.
154
+ */
155
+ export async function helperSourcesKey() { const { names, hashes } = await helperSources(); return sourcesKey(names, hashes); }
156
+ /** Compile packaged helper sources against the selected installation, never an author checkout. */
157
+ export async function nativeHelpers(directory, inputs, c) {
158
+ const { names, hashes, contents } = await helperSources();
144
159
  const mergeSources = await nativeMergeSources(inputs.ghidraHome);
145
160
  const key = createHash('sha256').update(stable([inputs.fingerprint, names, hashes, mergeSources.map(({ name, sha256 }) => ({ name, sha256 }))])).digest('hex');
146
161
  const parent = join(directory, 'native-helpers');
@@ -164,12 +179,21 @@ export async function nativeHelpers(directory, inputs, c) {
164
179
  await writeFile(path, item.source, { flag: 'wx' });
165
180
  patched.push(path);
166
181
  }
182
+ const packaged = [];
183
+ await mkdir(join(temporary, 'package-sources'), { mode: 0o700 });
184
+ for (const [index, name] of names.entries()) {
185
+ const path = join(temporary, 'package-sources', basename(name));
186
+ await writeFile(path, contents[index], { flag: 'wx' });
187
+ packaged.push(path);
188
+ }
167
189
  await writeFile(join(temporary, 'native-merge-provenance.json'), stable(mergeSources.map(({ source, ...item }) => item)), { flag: 'wx' });
168
- const executable = join(dirname(inputs.java), 'javac' + (process.platform === 'win32' ? '.exe' : '')), args = ['-proc:none', '-cp', inputs.classpath, '-d', temporary, ...names.map(name => join(sources, name)), ...patched];
190
+ const executable = join(dirname(inputs.java), 'javac' + (process.platform === 'win32' ? '.exe' : '')), args = ['-proc:none', '-cp', inputs.classpath, '-d', temporary, ...packaged, ...patched];
169
191
  if (c)
170
192
  await runTool(c, { tool: 'ghidra', role: 'compile-helpers', installation: inputs.fingerprint, executable, arguments: args, timeoutMs: 60000, maxOutputBytes: 262144 });
171
193
  else
172
194
  await run(executable, await javaClasspathArguments(temporary, 'ghidra', executable, args), { timeout: 60000, maxBuffer: 262144 });
195
+ // Recorded from the very hashes that name this directory: the worker compares a caller's sources with it.
196
+ await writeFile(join(temporary, 'helper-sources'), sourcesKey(names, hashes), { flag: 'wx', mode: 0o600 });
173
197
  const complete = await open(join(temporary, 'complete'), 'wx', 0o600);
174
198
  try {
175
199
  await complete.writeFile(key);
@@ -1,12 +1,7 @@
1
- import { readFile } from 'node:fs/promises';
2
- import { randomUUID } from 'node:crypto';
3
1
  import { object, fail } from './model.js';
4
2
  export async function nativeQuery(http, program, operation, parameters, write = false) {
5
3
  const base = operation === '/code_references' ? 'InsightCodeReferences' : operation.startsWith('/sdk/') ? 'InsightSdkScript' : operation.startsWith('/emulate_') ? 'InsightEmulation' : 'InsightResearchQueries';
6
- const name = base + '_' + randomUUID().replaceAll('-', '');
7
- const source = await readFile(new URL('../../references/native/' + base + '.java', import.meta.url), 'utf8');
8
- const response = object(await http.call('/run_script_inline', { program, code: source.replace('public class ' + base + ' ', 'public class ' + name + ' '),
9
- args: Buffer.from(JSON.stringify({ operation, parameters, ...(write ? { write: true } : {}) }), 'utf8').toString('base64') }));
4
+ const response = object(await http.script(program, base, Buffer.from(JSON.stringify({ operation, parameters, ...(write ? { write: true } : {}) }), 'utf8').toString('base64')));
10
5
  if (response.success !== true || typeof response.console_output !== 'string')
11
6
  fail('partial', 'Native research helper did not complete.');
12
7
  const matches = [...response.console_output.matchAll(/^INSIGHT_QUERY:(.+)$/gm)];
@@ -0,0 +1,40 @@
1
+ export type ServiceRole = 'publisher' | 'reader';
2
+ export interface ServiceLaunch {
3
+ directory: string;
4
+ installation: string;
5
+ executable: string;
6
+ arguments: string[];
7
+ environment: Record<string, string | undefined>;
8
+ root: string;
9
+ }
10
+ export interface ServiceOptions {
11
+ readyMs?: number;
12
+ queueMs?: number;
13
+ terminateMs?: number;
14
+ }
15
+ /**
16
+ * Long-lived native services of one profile owner: per role and credential key at most two services, requests
17
+ * per service in order. Undefined from `call` means nothing was sent and a one-shot helper must run it.
18
+ */
19
+ export declare class NativeServices {
20
+ private readonly options;
21
+ private readonly pools;
22
+ private readonly starting;
23
+ private closed;
24
+ private failures;
25
+ private disabledUntil;
26
+ /** Services out of rotation (dead, draining) whose exit is not proved yet; still tracked until it is. */
27
+ private readonly retired;
28
+ constructor(options?: ServiceOptions);
29
+ call(role: ServiceRole, key: string, launch: () => Promise<ServiceLaunch>, requestFile: string, timeoutMs: number, signal: AbortSignal): Promise<Record<string, unknown> | undefined>;
30
+ private pick;
31
+ /**
32
+ * Stop idle services now and await their proved exit; true only when nothing remains running or starting.
33
+ * Busy services are left untouched (no draining), so a refused maintenance attempt costs nothing later.
34
+ */
35
+ /** Process IDs of this owner's services that are tracked and still serving; every other service must prove its exit. */
36
+ servingPids(role: ServiceRole): Set<number>;
37
+ stopIdle(): Promise<boolean>;
38
+ /** Close for good: no further requests are accepted and every service terminates. */
39
+ stop(): Promise<void>;
40
+ }