@eyeauras/insight-cli 0.8.3 → 0.8.4

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 (109) hide show
  1. package/.cli-package-build.json +1 -1
  2. package/SKILL.md +1 -1
  3. package/dist/src/administration.js +1 -1
  4. package/dist/src/archive.js +1 -1
  5. package/dist/src/artifacts.d.ts +2 -1
  6. package/dist/src/artifacts.js +6 -5
  7. package/dist/src/binary.js +1 -1
  8. package/dist/src/capture.js +3 -3
  9. package/dist/src/cli.js +17 -16
  10. package/dist/src/contexts.js +14 -17
  11. package/dist/src/cross.js +1 -1
  12. package/dist/src/debugger.js +1 -1
  13. package/dist/src/die.js +1 -1
  14. package/dist/src/dnspy.js +1 -1
  15. package/dist/src/dotnet-diagnostics.js +1 -1
  16. package/dist/src/ilspy.js +1 -1
  17. package/dist/src/lifecycle.js +5 -5
  18. package/dist/src/lldb.js +1 -1
  19. package/dist/src/llvm.js +1 -1
  20. package/dist/src/managed-heap.js +1 -1
  21. package/dist/src/managed-metadata.js +1 -1
  22. package/dist/src/mitmproxy.js +1 -1
  23. package/dist/src/model.d.ts +6 -1
  24. package/dist/src/model.js +9 -2
  25. package/dist/src/mutations.js +1 -1
  26. package/dist/src/projects.js +3 -3
  27. package/dist/src/prototype-cli.js +4 -4
  28. package/dist/src/research.js +1 -1
  29. package/dist/src/runtime-manager.d.ts +2 -2
  30. package/dist/src/runtime-manager.js +28 -4
  31. package/dist/src/sdk-files.js +3 -3
  32. package/dist/src/sdk.js +1 -1
  33. package/dist/src/server.d.ts +1 -0
  34. package/dist/src/server.js +17 -7
  35. package/dist/src/sevenzip.js +1 -1
  36. package/dist/src/strace.js +1 -1
  37. package/dist/src/sync-policy.js +4 -4
  38. package/dist/src/tool-runtime/identity.d.ts +7 -0
  39. package/dist/src/tool-runtime/identity.js +35 -0
  40. package/dist/src/tool-runtime/store.js +3 -0
  41. package/dist/src/tool-runtime/supervisor.d.ts +8 -0
  42. package/dist/src/tool-runtime/supervisor.js +58 -10
  43. package/dist/src/tshark.js +1 -1
  44. package/dist/src/ui.js +3 -3
  45. package/dist/src/version-tracking.js +2 -2
  46. package/dist/src/windbg.js +1 -1
  47. package/dist/src/work/backup.js +14 -2
  48. package/dist/src/work/commands.js +50 -13
  49. package/dist/src/work/model.d.ts +43 -1
  50. package/dist/src/work/model.js +128 -0
  51. package/dist/src/work/store.d.ts +34 -3
  52. package/dist/src/work/store.js +75 -18
  53. package/dist/src/work/timing.d.ts +9 -0
  54. package/dist/src/work/timing.js +10 -1
  55. package/package.json +1 -1
  56. package/references/native/InsightNativeCheckout.java +24 -8
  57. package/references/work-tracking.md +52 -0
  58. package/skill-bundle/insight-artifacts/SKILL.md +1 -1
  59. package/skill-bundle/insight-binary/SKILL.md +1 -1
  60. package/skill-bundle/insight-capture/SKILL.md +1 -1
  61. package/skill-bundle/insight-cli/SKILL.md +1 -1
  62. package/skill-bundle/insight-die/SKILL.md +1 -1
  63. package/skill-bundle/insight-dnspy/SKILL.md +1 -1
  64. package/skill-bundle/insight-dotnet-dump/SKILL.md +1 -1
  65. package/skill-bundle/insight-dotnet-stack/SKILL.md +1 -1
  66. package/skill-bundle/insight-dotnet-trace/SKILL.md +1 -1
  67. package/skill-bundle/insight-frida/SKILL.md +1 -1
  68. package/skill-bundle/insight-ghidra/SKILL.md +1 -1
  69. package/skill-bundle/insight-ilspy/SKILL.md +1 -1
  70. package/skill-bundle/insight-interop/SKILL.md +1 -1
  71. package/skill-bundle/insight-lldb/SKILL.md +1 -1
  72. package/skill-bundle/insight-llvm/SKILL.md +1 -1
  73. package/skill-bundle/insight-managed-heap/SKILL.md +1 -1
  74. package/skill-bundle/insight-managed-metadata/SKILL.md +1 -1
  75. package/skill-bundle/insight-mitmproxy/SKILL.md +1 -1
  76. package/skill-bundle/insight-overview/SKILL.md +1 -1
  77. package/skill-bundle/insight-procmon/SKILL.md +1 -1
  78. package/skill-bundle/insight-re/SKILL.md +1 -1
  79. package/skill-bundle/insight-re/references/work-tracking.md +52 -0
  80. package/skill-bundle/insight-sevenzip/SKILL.md +1 -1
  81. package/skill-bundle/insight-strace/SKILL.md +1 -1
  82. package/skill-bundle/insight-tshark/SKILL.md +1 -1
  83. package/skill-bundle/insight-windbg/SKILL.md +1 -1
  84. package/skill-bundle/manifest.json +1 -1
  85. package/skills/insight-artifacts/SKILL.md +1 -1
  86. package/skills/insight-binary/SKILL.md +1 -1
  87. package/skills/insight-capture/SKILL.md +1 -1
  88. package/skills/insight-die/SKILL.md +1 -1
  89. package/skills/insight-dnspy/SKILL.md +1 -1
  90. package/skills/insight-dotnet-dump/SKILL.md +1 -1
  91. package/skills/insight-dotnet-stack/SKILL.md +1 -1
  92. package/skills/insight-dotnet-trace/SKILL.md +1 -1
  93. package/skills/insight-frida/SKILL.md +1 -1
  94. package/skills/insight-ghidra/SKILL.md +1 -1
  95. package/skills/insight-ilspy/SKILL.md +1 -1
  96. package/skills/insight-interop/SKILL.md +1 -1
  97. package/skills/insight-lldb/SKILL.md +1 -1
  98. package/skills/insight-llvm/SKILL.md +1 -1
  99. package/skills/insight-managed-heap/SKILL.md +1 -1
  100. package/skills/insight-managed-metadata/SKILL.md +1 -1
  101. package/skills/insight-mitmproxy/SKILL.md +1 -1
  102. package/skills/insight-overview/SKILL.md +1 -1
  103. package/skills/insight-procmon/SKILL.md +1 -1
  104. package/skills/insight-re/SKILL.md +1 -1
  105. package/skills/insight-re/references/work-tracking.md +52 -0
  106. package/skills/insight-sevenzip/SKILL.md +1 -1
  107. package/skills/insight-strace/SKILL.md +1 -1
  108. package/skills/insight-tshark/SKILL.md +1 -1
  109. package/skills/insight-windbg/SKILL.md +1 -1
@@ -1 +1 @@
1
- {"version":1,"artifact":"39f4082a394ae17275f6edbfab438b30140d00026bcda57c8d6e1f0fc068ee58"}
1
+ {"version":1,"artifact":"b471fa238b3b427034aa4b28b9d99ce95cb05a493a77482a15c18bb3a8d920ba"}
package/SKILL.md CHANGED
@@ -3,7 +3,7 @@ name: insight-cli
3
3
  description: Choose and prepare reverse-engineering capabilities from the insight-cli toolbox for binary, managed-code and runtime investigations. Use to discover the appropriate tool or its packaged skill before installing native runtimes.
4
4
  ---
5
5
 
6
- # insight-cli 0.8.3
6
+ # insight-cli 0.8.4
7
7
 
8
8
  AppData/IPC access denied: follow [host execution permissions](references/agent-execution.md).
9
9
  A lost mutation reply needs request/status recovery, never a blind retry.
@@ -118,7 +118,7 @@ export function administrationCommands(service, unconfiguredStatus) {
118
118
  fail('invalid', 'Access must be read_only, write or admin.');
119
119
  parameters.access = access;
120
120
  }
121
- return changing ? service(c).change(leaf.operation, parameters, o.requestId === undefined ? undefined : id(o.requestId)) : service(c).read(leaf.operation, parameters);
121
+ return changing ? service(c).change(leaf.operation, parameters, o.requestId === undefined ? undefined : id(o.requestId, '--request-id')) : service(c).read(leaf.operation, parameters);
122
122
  }, { permission: leaf.gate, options: [...leaf.params.map(option), ...(changing ? [{ flags: '--request-id <id>', description: 'Retrieve this administration outcome after a lost response' }] : [])] });
123
123
  if (leaf.names.length === 1)
124
124
  children.push(definition);
@@ -108,7 +108,7 @@ export function archiveCommands(service) {
108
108
  p.limit = number(o.limit, 100000);
109
109
  p.skip_default_named = !o.includeDefaultNamed;
110
110
  }
111
- return service(c).ingest(scope(o), operation, p, o.requestId === undefined ? undefined : id(o.requestId));
111
+ return service(c).ingest(scope(o), operation, p, o.requestId === undefined ? undefined : id(o.requestId, '--request-id'));
112
112
  }, { permission: Permission.Update, options: [...selectedOptions,
113
113
  ...(operation === 'function' ? [{ flags: '--address <address>', description: 'Selected function entry point', required: true }] : [{ flags: '--limit <count>', description: 'Maximum visited functions (0 means all, at most 100000)', defaultValue: 0 }, { flags: '--include-default-named', description: 'Include auto-named functions' }]),
114
114
  { flags: '--version-label <name>', description: 'Archive version label', defaultValue: 'unknown' }, { flags: '--dry-run', description: 'Validate payloads without sending documentation' },
@@ -13,5 +13,6 @@ export declare class Artifacts {
13
13
  private ownedDirectory;
14
14
  private syncDirectory;
15
15
  verify(value: Artifact): Promise<string>;
16
- capture(source: string, kind: ArtifactKind): Promise<Artifact>;
16
+ /** `limit` bounds the file as it is opened, so a file replaced after an earlier size check is never retained. */
17
+ capture(source: string, kind: ArtifactKind, limit?: number): Promise<Artifact>;
17
18
  }
@@ -62,7 +62,8 @@ export class Artifacts {
62
62
  await handle.close();
63
63
  }
64
64
  }
65
- async capture(source, kind) {
65
+ /** `limit` bounds the file as it is opened, so a file replaced after an earlier size check is never retained. */
66
+ async capture(source, kind, limit = maximumBytes) {
66
67
  if (!['input', 'snapshot', 'native'].includes(kind))
67
68
  fail('artifact', 'Unsupported artifact kind.');
68
69
  const directory = await this.ownedDirectory();
@@ -71,15 +72,15 @@ export class Artifacts {
71
72
  let output;
72
73
  try {
73
74
  const info = await input.stat({ bigint: true });
74
- if (!info.isFile() || info.size < 1n || info.size > BigInt(maximumBytes))
75
- fail('limit', 'Input must be a nonempty regular file of at most 4 GiB.');
75
+ if (!info.isFile() || info.size < 1n || info.size > BigInt(Math.min(limit, maximumBytes)))
76
+ fail('limit', limit < maximumBytes ? `Input must be a nonempty regular file of at most ${limit} bytes.` : 'Input must be a nonempty regular file of at most 4 GiB.');
76
77
  output = await open(temporary, 'wx', 0o600);
77
78
  const hash = createHash('sha256');
78
79
  let size = 0;
79
80
  for await (const chunk of input.createReadStream({ autoClose: false })) {
80
81
  size += chunk.length;
81
- if (size > maximumBytes)
82
- fail('limit', 'Input exceeds 4 GiB.');
82
+ if (size > Math.min(limit, maximumBytes))
83
+ fail('limit', 'Input exceeds its size limit.');
83
84
  hash.update(chunk);
84
85
  await output.writeFile(chunk);
85
86
  }
@@ -20,7 +20,7 @@ export function binaryCommands(workspace) {
20
20
  const view = mode === 'query' ? text(o.view ?? 'overview', 16) : undefined;
21
21
  if (view && !['overview', 'sections', 'libraries', 'imports', 'exports'].includes(view))
22
22
  fail('invalid', 'Use overview, sections, libraries, imports or exports.');
23
- const limit = number(o.limit ?? 50, 500, 1), offset = number(o.offset ?? 0, 1000000), w = workspace(c), target = args.input ? await w.importTarget(resolve(c.cwd, text(args.input, 4096))) : w.target(id(o.target));
23
+ const limit = number(o.limit ?? 50, 500, 1), offset = number(o.offset ?? 0, 1000000), w = workspace(c), target = args.input ? await w.importTarget(resolve(c.cwd, text(args.input, 4096))) : w.target(id(o.target, '--target'));
24
24
  if (target.input.size > 64 * 1024 ** 2)
25
25
  fail('limit', 'Structured binary input exceeds 64 MiB.');
26
26
  const input = await w.artifacts.verify(target.input);
@@ -105,7 +105,7 @@ export function captureCommands(workspace) {
105
105
  fail('unsupported', 'Process capture is verified on macOS14+ ARM64 thin native executables.');
106
106
  if (Boolean(args.input) === Boolean(o.target))
107
107
  fail('invalid', 'Supply one native program or --target.');
108
- const w = workspace(c), target = args.input ? await w.importTarget(resolve(c.cwd, text(args.input, 4096))) : w.target(id(o.target)), input = await w.artifacts.verify(target.input);
108
+ const w = workspace(c), target = args.input ? await w.importTarget(resolve(c.cwd, text(args.input, 4096))) : w.target(id(o.target, '--target')), input = await w.artifacts.verify(target.input);
109
109
  if (target.input.size > 64 * 1024 ** 2)
110
110
  fail('limit', 'Owned executable exceeds 64 MiB.');
111
111
  const header = (await boundedFile(input, 64 * 1024 ** 2)).subarray(0, 32);
@@ -126,7 +126,7 @@ export function captureCommands(workspace) {
126
126
  files.push({ name, sha256: sha(data), bytes: data.length, data });
127
127
  }
128
128
  const stdin = o.stdinFile ? await boundedFile(resolve(c.cwd, text(o.stdinFile, 4096)), 1024 ** 2) : Buffer.alloc(0);
129
- if (o.output && !(o.requestId && w.administrationByCaller(id(o.requestId))))
129
+ if (o.output && !(o.requestId && w.administrationByCaller(id(o.requestId, '--request-id'))))
130
130
  try {
131
131
  await lstat(resolve(c.cwd, text(o.output, 4096)));
132
132
  fail('invalid', 'Capture output already exists.');
@@ -136,7 +136,7 @@ export function captureCommands(workspace) {
136
136
  throw error;
137
137
  }
138
138
  const intent = { target: target.id, inputSha256: target.binarySha256, arguments: argv, inputs: files.map(({ data, ...f }) => f), stdin: { sha256: sha(stdin), bytes: stdin.length }, watch: watched, timeoutMs, output: o.output ? resolve(c.cwd, text(o.output, 4096)) : undefined };
139
- const reservation = w.reserveAdministration('capture.run', intent, o.requestId === undefined ? undefined : id(o.requestId)), request = reservation.request.id;
139
+ const reservation = w.reserveAdministration('capture.run', intent, o.requestId === undefined ? undefined : id(o.requestId, '--request-id')), request = reservation.request.id;
140
140
  if (reservation.replay) {
141
141
  const previous = await receiptFor(c, w, request);
142
142
  if (reservation.request.state === 'applied' && 'kind' in previous) {
package/dist/src/cli.js CHANGED
@@ -172,7 +172,7 @@ class Owner {
172
172
  await (await selected.backend()).quiesce?.();
173
173
  // A missing private-worker receipt does not prove an interrupted native helper stopped.
174
174
  const helpers = await migrationProcessBlockers(c.appArguments.AppDataDirectory);
175
- const workers = (await runtimeProcesses(analysisDirectory(c))).filter(p => p.kind !== 'server');
175
+ const workers = (await runtimeProcesses(analysisDirectory(c), c.appArguments.AppDataDirectory)).filter(p => p.kind !== 'server');
176
176
  if (helpers.length || workers.length)
177
177
  fail('busy', 'Stop or reconcile retained Ghidra workers and native helpers before ' + name + '; no takeover is performed.', { helpers, workers });
178
178
  return await action(await selected.backend());
@@ -441,15 +441,15 @@ export function createDefinition(options = {}) {
441
441
  const items = owner.selected(c).workspace.targets(number(o.limit, 100, 1), number(o.offset, 2147483647));
442
442
  return { items: items.map(targetView), offset: o.offset, limit: o.limit, truncated: items.length === o.limit };
443
443
  }, { permission: Permission.ReadOnly, options: paged }),
444
- command('show <target>', 'Show an input identity', ({ args }, c) => targetView(owner.selected(c).workspace.target(id(args.target))), { permission: Permission.ReadOnly }),
444
+ command('show <target>', 'Show an input identity', ({ args }, c) => targetView(owner.selected(c).workspace.target(id(args.target, 'target'))), { permission: Permission.ReadOnly }),
445
445
  ]),
446
446
  command('sessions', 'Inspect durable sessions', [
447
447
  command('list', 'List independent sessions', ({ options: o }, c) => { const items = owner.selected(c).workspace.sessions(number(o.limit, 100, 1), number(o.offset, 2147483647)); return { items, offset: o.offset, limit: o.limit, truncated: items.length === Number(o.limit) }; }, { permission: Permission.ReadOnly, options: paged }),
448
448
  command('status <session>', 'Inspect saved work and unresolved outcomes', ({ args, options: o }, c) => {
449
- const selected = owner.selected(c), session = id(args.session);
449
+ const selected = owner.selected(c), session = id(args.session, 'session');
450
450
  selected.workspace.session(session);
451
451
  if (o.target)
452
- return selected.research.status({ session, target: id(o.target) });
452
+ return selected.research.status({ session, target: id(o.target, '--target') });
453
453
  const limit = number(o.limit, 100, 1), offset = number(o.offset, 2147483647), contexts = selected.workspace.contexts(session, limit, offset);
454
454
  return { session, contexts: contexts.map(context => selected.research.status(context)), limit, offset, truncated: contexts.length === limit };
455
455
  }, { permission: Permission.ReadOnly, options: [{ flags: '--target <id>', description: 'Inspect one target context' }, ...paged] }),
@@ -458,7 +458,7 @@ export function createDefinition(options = {}) {
458
458
  command('migrate', 'Explicitly migrate retained legacy models; repeat to resume', ({ options: o }, c) => {
459
459
  if (Boolean(o.target) === Boolean(o.all))
460
460
  fail('invalid', 'Select exactly one --target or --all.');
461
- return owner.migrate(c, o.target === undefined ? undefined : id(o.target), Boolean(o.dryRun));
461
+ return owner.migrate(c, o.target === undefined ? undefined : id(o.target, '--target'), Boolean(o.dryRun));
462
462
  }, { permission: Permission.ReadOnly, options: [{ flags: '--target <id>', description: 'Migrate one immutable target' }, { flags: '--all', description: 'Inspect or migrate every Ghidra target in this profile' }, { flags: '--dry-run', description: 'Inspect without checkout, check-in or context changes' }] }),
463
463
  command('gc', 'Reclaim redundant copies: unreferenced snapshots, duplicate exports, stopped detached projects and unchanged checkouts', ({ options: o }, c) => owner.collect(c, Boolean(o.dryRun)), { permission: Permission.ReadOnly, options: [{ flags: '--dry-run', description: 'Report reclaimable and retained storage without changing it' }] }),
464
464
  command('progress', 'Read initial-model import/publication progress without starting Ghidra', async ({ options: o }, c) => {
@@ -481,14 +481,14 @@ export function createDefinition(options = {}) {
481
481
  }, { permission: Permission.Update, options: [{ flags: '--initial-import-seconds <seconds>', description: 'Initial import/analysis: 1–86400 seconds' },
482
482
  { flags: '--save-seconds <seconds>', description: 'Native save/export: 1–3600 seconds' }] })
483
483
  ]),
484
- command('abandon', 'Retain an uncertain legacy detached program attempt and resume its previous saved view', ({ options: o }, c) => owner.selected(c).research.abandon(scope(o), id(o.requestId), Boolean(o.acknowledgeUnknownEffects)), { permission: 'Destructive', options: [...scoped, { flags: '--request-id <id>', description: 'Original unresolved request ID from `insight-cli sessions status <session> --target <target>`', required: true }, { flags: '--acknowledge-unknown-effects', description: 'Acknowledge that the abandoned effect remains unknown; no script is replayed' }] }),
485
- command('refresh', 'Receive safe shared changes while retaining local conflicts', ({ options: o }, c) => owner.selected(c).research.refresh(scope(o), o.requestId === undefined ? undefined : id(o.requestId)), { permission: Permission.Update, options: [...scoped, request] }),
486
- command('merge', 'Publish the complete selected context or retain every conflict; the context stays open at the published version', ({ options: o }, c) => owner.selected(c).research.merge(scope(o), o.requestId === undefined ? undefined : id(o.requestId), Boolean(o.close)), { permission: Permission.Update, options: [...scoped, request, { flags: '--close', description: 'Release the working copy after publishing instead of continuing in it' }] }),
484
+ command('abandon', 'Retain an uncertain legacy detached program attempt and resume its previous saved view', ({ options: o }, c) => owner.selected(c).research.abandon(scope(o), id(o.requestId, '--request-id'), Boolean(o.acknowledgeUnknownEffects)), { permission: 'Destructive', options: [...scoped, { flags: '--request-id <id>', description: 'Original unresolved request ID from `insight-cli sessions status <session> --target <target>`', required: true }, { flags: '--acknowledge-unknown-effects', description: 'Acknowledge that the abandoned effect remains unknown; no script is replayed' }] }),
485
+ command('refresh', 'Receive safe shared changes while retaining local conflicts', ({ options: o }, c) => owner.selected(c).research.refresh(scope(o), o.requestId === undefined ? undefined : id(o.requestId, '--request-id')), { permission: Permission.Update, options: [...scoped, request] }),
486
+ command('merge', 'Publish the complete selected context or retain every conflict; the context stays open at the published version', ({ options: o }, c) => owner.selected(c).research.merge(scope(o), o.requestId === undefined ? undefined : id(o.requestId, '--request-id'), Boolean(o.close)), { permission: Permission.Update, options: [...scoped, request, { flags: '--close', description: 'Release the working copy after publishing instead of continuing in it' }] }),
487
487
  command('open [input]', 'Start independent work or continue a context', async ({ args, options: o }, c) => {
488
488
  if (Boolean(args.input) === Boolean(o.target))
489
489
  fail('invalid', 'Supply exactly one input path or --target.');
490
490
  return owner.openCommand(c, async (selected) => {
491
- const target = args.input ? (await selected.workspace.importTarget(resolve(c.cwd, text(args.input, 4096)))).id : id(o.target);
491
+ const target = args.input ? (await selected.workspace.importTarget(resolve(c.cwd, text(args.input, 4096)))).id : id(o.target, '--target');
492
492
  let previous;
493
493
  try {
494
494
  previous = selected.workspace.model(target).settings;
@@ -501,7 +501,8 @@ export function createDefinition(options = {}) {
501
501
  ...(o.language ? { language: text(o.language) } : {}), ...(o.compilerSpec ? { compilerSpec: text(o.compilerSpec) } : {}),
502
502
  ...(o.imageBase ? { imageBase: text(o.imageBase) } : {}), ...(o.loader ? { loader: text(o.loader, 512) } : {}),
503
503
  ...(o.loaderOptions !== undefined ? { loaderOptions: object(parseDomainJson(text(o.loaderOptions, 16000))) } : {}) };
504
- return selected.research.open(target, text(o.session), settings, o.requestId === undefined ? undefined : id(o.requestId), mode(o.mode));
504
+ const session = text(o.session);
505
+ return selected.research.open(target, session === 'new' ? session : id(session, '--session'), settings, o.requestId === undefined ? undefined : id(o.requestId, '--request-id'), mode(o.mode));
505
506
  });
506
507
  }, { permission: Permission.Update, options: [{ flags: '--session <id>', description: 'Use new for independent work, or an existing session', required: true },
507
508
  { flags: '--target <id>', description: 'Continue existing input instead of supplying a file' }, request,
@@ -526,7 +527,7 @@ export function createDefinition(options = {}) {
526
527
  const selected = owner.selected(c), who = scope(o), name = text(o.name, 512), fields = structureFields(o.fields);
527
528
  if (o.replacePlaceholder) {
528
529
  const parameters = { path: name.startsWith('/') ? name : '/' + name, fields, packing: -1, alignment: 0, replace_placeholder: true };
529
- return selected.research.mutate(who, '/sdk/type-structure', parameters, async () => ({}), o.requestId === undefined ? undefined : id(o.requestId), (backend, snapshot, response) => verifyMutation(backend, snapshot, '/sdk/type-structure', parameters, response));
530
+ return selected.research.mutate(who, '/sdk/type-structure', parameters, async () => ({}), o.requestId === undefined ? undefined : id(o.requestId, '--request-id'), (backend, snapshot, response) => verifyMutation(backend, snapshot, '/sdk/type-structure', parameters, response));
530
531
  }
531
532
  return selected.research.mutate(who, '/create_struct', { name, fields }, async (backend) => {
532
533
  const result = object(await backend.call(who, '/get_struct_layout', { struct_name: name }));
@@ -536,7 +537,7 @@ export function createDefinition(options = {}) {
536
537
  if (object(result.fields[i]).name !== fields[i].name)
537
538
  fail('partial', 'Structure readback changed a field name.');
538
539
  return result;
539
- }, o.requestId === undefined ? undefined : id(o.requestId));
540
+ }, o.requestId === undefined ? undefined : id(o.requestId, '--request-id'));
540
541
  }, { permission: Permission.Update, options: [...scoped, { flags: '--name <name>', description: 'New structure name', required: true },
541
542
  { flags: '--fields <json>', description: 'Array of {name,type,offset?}', required: true }, { flags: '--replace-placeholder', description: 'Replace only an existing empty structure, with independently verified saved layout' }, request] }),
542
543
  ]),
@@ -550,7 +551,7 @@ export function createDefinition(options = {}) {
550
551
  fill_byte: o.fillByte === undefined ? 0 : number(o.fillByte, 255), ...(o.bytesHex === undefined ? {} : { bytes_hex: o.bytesHex }), ...(o.bytesBase64 === undefined ? {} : { bytes_base64: o.bytesBase64 }) };
551
552
  const expected = blockContent(parameters);
552
553
  parameters.size = expected.size;
553
- return selected.research.mutate(who, '/create_memory_block', parameters, async () => ({}), o.requestId === undefined ? undefined : id(o.requestId), (backend, snapshot, response) => verifyMutation(backend, snapshot, '/create_memory_block', parameters, response));
554
+ return selected.research.mutate(who, '/create_memory_block', parameters, async () => ({}), o.requestId === undefined ? undefined : id(o.requestId, '--request-id'), (backend, snapshot, response) => verifyMutation(backend, snapshot, '/create_memory_block', parameters, response));
554
555
  }, { permission: Permission.Update, options: [...scoped, at, { flags: '--name <name>', description: 'Memory block name', required: true },
555
556
  { flags: '--size <bytes>', description: 'Positive size up to 16 MiB; defaults to content length' },
556
557
  { flags: '--bytes-hex <hex>', description: 'Initial bytes in hexadecimal; remainder uses fill-byte' },
@@ -573,7 +574,7 @@ export function createDefinition(options = {}) {
573
574
  command('set-function-prototype', 'Set a C prototype and optional explicit compiler-supported calling convention', ({ options: o }, c) => {
574
575
  const selected = owner.selected(c), who = scope(o), parameters = { function_address: address(o.address), prototype: text(o.prototype, 16000),
575
576
  ...(o.callingConvention === undefined ? {} : { calling_convention: text(o.callingConvention, 512) }) };
576
- return selected.research.mutate(who, '/set_function_prototype', parameters, async () => ({}), o.requestId === undefined ? undefined : id(o.requestId), (backend, snapshot, response) => verifyMutation(backend, snapshot, '/set_function_prototype', parameters, response));
577
+ return selected.research.mutate(who, '/set_function_prototype', parameters, async () => ({}), o.requestId === undefined ? undefined : id(o.requestId, '--request-id'), (backend, snapshot, response) => verifyMutation(backend, snapshot, '/set_function_prototype', parameters, response));
577
578
  }, { permission: Permission.Update, options: [...scoped, at, { flags: '--prototype <signature>', description: 'Complete C prototype', required: true },
578
579
  { flags: '--calling-convention <name>', description: 'Explicit convention supported by the selected compiler specification' }, request] }),
579
580
  command('get', 'Read a function and entry comments', ({ options: o }, c) => owner.selected(c).research.function(scope(o), address(o.address)), { permission: Permission.ReadOnly, options: [...scoped, at] }),
@@ -582,7 +583,7 @@ export function createDefinition(options = {}) {
582
583
  const name = text(o.name, 512);
583
584
  if (name !== name.trim())
584
585
  fail('invalid', 'Function name may not have leading or trailing whitespace.');
585
- return owner.selected(c).research.edit(scope(o), address(o.address), 'function.name', name, o.requestId === undefined ? undefined : id(o.requestId), resolution(o));
586
+ return owner.selected(c).research.edit(scope(o), address(o.address), 'function.name', name, o.requestId === undefined ? undefined : id(o.requestId, '--request-id'), resolution(o));
586
587
  }, { permission: Permission.Update, options: [...scoped, at, { flags: '--name <name>', description: 'Desired function name', required: true }, request, ...resolveOptions] }),
587
588
  ]),
588
589
  command('comments', 'Read or edit listing comments', [
@@ -590,7 +591,7 @@ export function createDefinition(options = {}) {
590
591
  command('set', 'Record a saved private comment or clear it', ({ options: o }, c) => {
591
592
  if (Boolean(o.clear) === (o.text !== undefined))
592
593
  fail('invalid', 'Supply exactly one --text or --clear.');
593
- return owner.selected(c).research.edit(scope(o), address(o.address), 'comment.' + commentKind(o.kind), o.clear ? null : scalarText(o.text), o.requestId === undefined ? undefined : id(o.requestId), resolution(o));
594
+ return owner.selected(c).research.edit(scope(o), address(o.address), 'comment.' + commentKind(o.kind), o.clear ? null : scalarText(o.text), o.requestId === undefined ? undefined : id(o.requestId, '--request-id'), resolution(o));
594
595
  }, { permission: Permission.Update, options: [...scoped, at, { flags: '--kind <kind>', description: 'eol, pre, post, plate or repeatable', required: true },
595
596
  { flags: '--text <text>', description: 'Desired text; empty text clears to null' }, { flags: '--clear', description: 'Clear this comment to null' }, request, ...resolveOptions] }),
596
597
  ]),
@@ -5,10 +5,9 @@ import { ownedDirectory, projectPathWithin, sameDirectory } from './directory-id
5
5
  import { releaseStoppedContextCredential, launchContextCredential } from './context-credential.js';
6
6
  import { recordLifecycle } from './context-diagnostics.js';
7
7
  import { ghidraBudget } from './budgets.js';
8
- import { launchProcess, terminateProcess, processStatus } from './tool-runtime/supervisor.js';
8
+ import { launchProcess, terminateProcess, processStatus, recordedProcessGone, validEnd } from './tool-runtime/supervisor.js';
9
9
  import { runTool } from './tool-runtime/run.js';
10
10
  import { verifyGhidraProcess } from './ghidra-processes.js';
11
- import { processIdentity } from './tool-runtime/identity.js';
12
11
  import { CliError } from '@eyeauras/cli-factory';
13
12
  import { runtimeProcesses } from './runtime-manager.js';
14
13
  import { randomUUID, randomBytes, createHash } from 'node:crypto';
@@ -198,7 +197,7 @@ export class GhidraContexts {
198
197
  if (operation === 'stop') {
199
198
  if (this.c.profile.values.server)
200
199
  fail('authorization', 'External server lifecycle is owned by its operator. Use server disconnect.');
201
- const processes = await runtimeProcesses(dirname(this.workspace.directory));
200
+ const processes = await runtimeProcesses(dirname(this.workspace.directory), this.c.appArguments?.AppDataDirectory);
202
201
  if (processes.some(p => p.kind !== 'server'))
203
202
  fail('busy', 'Close active Ghidra contexts before stopping their server.');
204
203
  }
@@ -1190,7 +1189,7 @@ export class GhidraContexts {
1190
1189
  if (pending || context.nativeCheckout)
1191
1190
  fail('blocked', 'A native checkout belongs to this context; it is not detached work.');
1192
1191
  // A worker whose owner died before its current receipt is still found by its process receipt.
1193
- if ((await runtimeProcesses(dirname(this.workspace.directory))).some(p => p.kind !== 'server' && (p.sessionContext ?? context.id) === context.id))
1192
+ if ((await runtimeProcesses(dirname(this.workspace.directory), this.c.appArguments?.AppDataDirectory)).some(p => p.kind !== 'server' && (p.sessionContext ?? context.id) === context.id))
1194
1193
  return false;
1195
1194
  return this.neverStartedOrClosed(context);
1196
1195
  }
@@ -1245,7 +1244,7 @@ export class GhidraContexts {
1245
1244
  }
1246
1245
  // This owner's own idle native services are not foreign helpers; busy ones refuse.
1247
1246
  await this.requireIdleServices();
1248
- const process = await runtimeProcesses(dirname(this.workspace.directory));
1247
+ const process = await runtimeProcesses(dirname(this.workspace.directory), this.c.appArguments?.AppDataDirectory);
1249
1248
  if (this.capacity.slots.has(context.id) || process.some(p => p.kind !== 'server') || (await migrationProcessBlockers(this.c.appArguments.AppDataDirectory)).length)
1250
1249
  fail('busy', 'Stop or reconcile every Ghidra worker and native helper before giving up a missing checkout.');
1251
1250
  return checkout;
@@ -2785,21 +2784,19 @@ public class ${name} extends GhidraScript {
2785
2784
  if (!binding.toolProcessId)
2786
2785
  return false;
2787
2786
  try {
2788
- const row = await processStatus(this.c.appArguments.AppDataDirectory, binding.toolProcessId);
2789
2787
  // Read-only retirement evidence: old locators may no longer exist. Exact
2790
2788
  // persisted locator equality is sufficient here; it never authorizes a signal.
2791
- if (row.id !== binding.toolProcessId || row.tool !== 'ghidra' || row.role !== binding.kind ||
2792
- row.pid !== binding.pid || row.target !== binding.target || row.session !== binding.session ||
2793
- row.installation !== binding.runtimeFingerprint || row.strongIdentity !== true ||
2794
- typeof row.identity !== 'string' || !row.identity || typeof row.metadata?.contextRoot !== 'string' ||
2795
- resolve(row.metadata.contextRoot) !== resolve(binding.root))
2796
- return false;
2797
- if (['exited', 'failed'].includes(row.state) && typeof row.endedAt === 'string' && Number.isFinite(Date.parse(row.endedAt)))
2789
+ const matches = (row) => row.id === binding.toolProcessId && row.tool === 'ghidra' && row.role === binding.kind &&
2790
+ row.pid === binding.pid && row.target === binding.target && row.session === binding.session &&
2791
+ row.installation === binding.runtimeFingerprint && typeof row.identity === 'string' && Boolean(row.identity) && typeof row.metadata?.contextRoot === 'string' &&
2792
+ resolve(row.metadata.contextRoot) === resolve(binding.root);
2793
+ const row = await processStatus(this.c.appArguments.AppDataDirectory, binding.toolProcessId);
2794
+ // A strongly identified receipt with an exactly recorded end, as before.
2795
+ if (matches(row) && ['exited', 'failed'].includes(row.state) && row.strongIdentity === true && validEnd(row.endedAt))
2798
2796
  return true;
2799
- if (row.phase !== 'pid_identity_changed')
2800
- return false;
2801
- const current = await processIdentity(binding.pid);
2802
- return current?.strong === true && current.birth !== row.identity;
2797
+ // Otherwise proved freshly from the PID's current holder, on the same receipt snapshot that is validated.
2798
+ const gone = await recordedProcessGone(this.c.appArguments.AppDataDirectory, binding.toolProcessId);
2799
+ return gone !== undefined && matches(gone);
2803
2800
  }
2804
2801
  catch {
2805
2802
  return false;
package/dist/src/cross.js CHANGED
@@ -34,7 +34,7 @@ export function crossCommands(research) {
34
34
  const documentation = groups.get('documentation');
35
35
  documentation.push(command('transfer', 'Copy documentation into a saved private destination; publish with explicit merge', ({ options: o }, c) => {
36
36
  const selected = scope(o), source = { session: o.sourceSession === undefined ? selected.session : id(o.sourceSession), target: id(o.sourceTarget) };
37
- return research(c).transfer(selected, source, Boolean(o.dryRun), o.requestId === undefined ? undefined : id(o.requestId));
37
+ return research(c).transfer(selected, source, Boolean(o.dryRun), o.requestId === undefined ? undefined : id(o.requestId, '--request-id'));
38
38
  }, { permission: 'Destructive', options: [...selectedOptions, { flags: '--source-target <id>', description: 'Documentation source target', required: true },
39
39
  { flags: '--source-session <id>', description: 'Source context session (defaults to --session)' },
40
40
  { flags: '--dry-run', description: 'Preview transfer counts without applying documentation' },
@@ -271,7 +271,7 @@ export function debuggerCommands(service) {
271
271
  }
272
272
  }
273
273
  const selected = scope(o), selectedTrace = o.trace === undefined ? undefined : id(o.trace);
274
- return changing ? service(c).change(selected, operation, p, o.requestId === undefined ? undefined : id(o.requestId), selectedTrace) : service(c).read(selected, operation, p, selectedTrace);
274
+ return changing ? service(c).change(selected, operation, p, o.requestId === undefined ? undefined : id(o.requestId, '--request-id'), selectedTrace) : service(c).read(selected, operation, p, selectedTrace);
275
275
  }, { permission: operation === 'remove_breakpoint' || liveWrites.has(operation) ? 'Destructive' : changing ? Permission.Update : Permission.ReadOnly, options }));
276
276
  }
277
277
  return [command('debugger', 'Debug the selected immutable target in an owned GUI', leaves)];
package/dist/src/die.js CHANGED
@@ -103,7 +103,7 @@ export function dieCommands(workspace) {
103
103
  if (Boolean(args.input) === Boolean(o.target))
104
104
  fail('invalid', 'Supply exactly one input path or --target.');
105
105
  const limit = number(o.limit, 400, 1), offset = number(o.offset, 1000000, 0), timeoutMs = number(o.timeoutSeconds, 600, 1) * 1000;
106
- const w = workspace(c), target = args.input ? await w.importTarget(resolve(c.cwd, text(args.input, 4096))) : w.target(id(o.target)), input = await w.artifacts.verify(target.input);
106
+ const w = workspace(c), target = args.input ? await w.importTarget(resolve(c.cwd, text(args.input, 4096))) : w.target(id(o.target, '--target')), input = await w.artifacts.verify(target.input);
107
107
  return dieInstaller(c).use(async (selected) => {
108
108
  const database = join(contents(selected.executable), 'Resources/db'), calls = [];
109
109
  for (const mode of ['info', 'scan']) {
package/dist/src/dnspy.js CHANGED
@@ -71,7 +71,7 @@ export function dnspyCommands(workspace) {
71
71
  fail('invalid', 'Supply exactly one input path or --target.');
72
72
  if (mode === 'edit-constant' && !o.output)
73
73
  fail('invalid', 'A new --output assembly path is required.');
74
- const limit = number(o.limit ?? 32, 64, 1), offset = number(o.offset ?? 0, 64), plan = dnspyPlan(o, mode), w = workspace(c), target = args.input ? await w.importTarget(resolve(c.cwd, text(args.input, 4096))) : w.target(id(o.target)), source = await w.artifacts.verify(target.input), name = basename(args.input ? text(args.input, 4096) : target.name ?? 'input.exe');
74
+ const limit = number(o.limit ?? 32, 64, 1), offset = number(o.offset ?? 0, 64), plan = dnspyPlan(o, mode), w = workspace(c), target = args.input ? await w.importTarget(resolve(c.cwd, text(args.input, 4096))) : w.target(id(o.target, '--target')), source = await w.artifacts.verify(target.input), name = basename(args.input ? text(args.input, 4096) : target.name ?? 'input.exe');
75
75
  if ((!nativeFilename(name) || !/\.(?:exe|dll)$/i.test(name)))
76
76
  fail('invalid', 'Input must have an ordinary .exe or .dll filename.');
77
77
  const directory = join(c.appArguments.AppDataDirectory, 'runtime/dnspy/queries', randomUUID()), inputDirectory = join(directory, 'input'), extension = join(directory, 'extension');
@@ -60,7 +60,7 @@ export function diagnosticsCommands(workspace) {
60
60
  return { ...base, content: lines.slice(offset, offset + limit).join('\n'), offset, limit, totalLines: lines.length, truncated: offset + limit < lines.length };
61
61
  };
62
62
  const input = async (args, o, c) => { if (Boolean(args.input) === Boolean(o.target))
63
- fail('invalid', 'Supply exactly one input file or --target.'); const w = workspace(c), target = args.input ? await w.importTarget(resolve(c.cwd, text(args.input, 4096))) : w.target(id(o.target)); return { w, target, path: await w.artifacts.verify(target.input) }; };
63
+ fail('invalid', 'Supply exactly one input file or --target.'); const w = workspace(c), target = args.input ? await w.importTarget(resolve(c.cwd, text(args.input, 4096))) : w.target(id(o.target, '--target')); return { w, target, path: await w.artifacts.verify(target.input) }; };
64
64
  const staged = async (c) => { const directory = join(c.appArguments.AppDataDirectory, 'runtime/exports', randomUUID()); await mkdir(directory, { recursive: true, mode: 0o700 }); return directory; };
65
65
  const publish = async (path, o, c) => { const info = await stat(path); if (!info.isFile() || info.size < 1 || info.size > 4 * 1024 ** 3)
66
66
  fail('limit', 'Capture/export must be a nonempty regular file below four GiB.'); const w = workspace(c), target = await w.importTarget(path), output = resolve(c.cwd, text(o.output, 4096)); await mkdir(dirname(output), { recursive: true, mode: 0o700 }); await copyFile(path, output, constants.COPYFILE_EXCL); return { output, bytes: info.size, target: target.id, inputSha256: target.binarySha256 }; };
package/dist/src/ilspy.js CHANGED
@@ -66,7 +66,7 @@ export function ilspyCommands(workspace) {
66
66
  const timeout = Number(o.timeoutSeconds);
67
67
  if (!Number.isSafeInteger(timeout) || timeout < 1 || timeout > 1800)
68
68
  fail('invalid', 'timeout-seconds must be from 1 to 1800.');
69
- const w = workspace(c), target = args.input ? await w.importTarget(resolve(c.cwd, text(args.input, 4096))) : w.target(id(o.target)), session = o.session === undefined ? undefined : w.session(id(o.session)).id, input = await w.artifacts.verify(target.input);
69
+ const w = workspace(c), target = args.input ? await w.importTarget(resolve(c.cwd, text(args.input, 4096))) : w.target(id(o.target, '--target')), session = o.session === undefined ? undefined : w.session(id(o.session, '--session')).id, input = await w.artifacts.verify(target.input);
70
70
  const directory = operation === 'project' || operation === 'resource';
71
71
  if (directory && !o.output)
72
72
  fail('invalid', 'This operation requires --output DIRECTORY.');
@@ -297,13 +297,13 @@ export class Lifecycle {
297
297
  }
298
298
  export function lifecycleCommands(service, runtimeStatus) {
299
299
  return [command('changes', 'Manage unpublished edits in the selected context', [
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' }] }),
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, '--request-id')), { permission: 'Destructive', options: [...selectedOptions, { flags: '--request-id <id>', description: 'Retrieve the same local discard result' }] }),
301
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
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 }),
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' }] }),
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' }] })
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, '--request-id')), { 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' }] }),
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, '--request-id')), { 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' }] })
305
305
  ]),
306
- command('save-all', 'Save every Ghidra context in the explicit session; outcomes are per context', ({ options: o }, c) => service(c).saveAll(id(o.session), o.requestId === undefined ? undefined : id(o.requestId)), { permission: Permission.Update, options: [{ flags: '--session <id>', description: 'Explicit session whose contexts are saved', required: true }, { flags: '--request-id <id>', description: 'Retrieve the recorded session save outcomes' }] }),
306
+ command('save-all', 'Save every Ghidra context in the explicit session; outcomes are per context', ({ options: o }, c) => service(c).saveAll(id(o.session, '--session'), o.requestId === undefined ? undefined : id(o.requestId, '--request-id')), { permission: Permission.Update, options: [{ flags: '--session <id>', description: 'Explicit session whose contexts are saved', required: true }, { flags: '--request-id <id>', description: 'Retrieve the recorded session save outcomes' }] }),
307
307
  command('status', 'Inspect the installed runtime, or verify a selected context', ({ options: o }, c) => {
308
308
  if (o.session === undefined && o.target === undefined && runtimeStatus)
309
309
  return runtimeStatus(c);
@@ -311,5 +311,5 @@ export function lifecycleCommands(service, runtimeStatus) {
311
311
  fail('invalid', 'Context status requires both --session and --target.');
312
312
  return service(c).health(scope(o));
313
313
  }, { permission: Permission.ReadOnly, options: selectedOptions.map(option => ({ ...option, required: false })) }),
314
- ...['save', 'close'].map(name => command(name, name === 'save' ? 'Save private work without publication' : 'Save and release the owned context; reopen retains local work', ({ options: o }, c) => service(c).change(scope(o), name, o.requestId === undefined ? undefined : id(o.requestId)), { permission: Permission.Update, options: [...selectedOptions, { flags: '--request-id <id>', description: 'Retrieve the lifecycle outcome after a lost response' }] }))];
314
+ ...['save', 'close'].map(name => command(name, name === 'save' ? 'Save private work without publication' : 'Save and release the owned context; reopen retains local work', ({ options: o }, c) => service(c).change(scope(o), name, o.requestId === undefined ? undefined : id(o.requestId, '--request-id')), { permission: Permission.Update, options: [...selectedOptions, { flags: '--request-id <id>', description: 'Retrieve the lifecycle outcome after a lost response' }] }))];
315
315
  }
package/dist/src/lldb.js CHANGED
@@ -55,7 +55,7 @@ export function lldbCommands(workspace) {
55
55
  if (Boolean(args.input) === Boolean(o.target))
56
56
  fail('invalid', 'Supply exactly one input path or --target.');
57
57
  const commands = lldbPlan(o), limit = number(o.limit ?? 200, 1000, 1), offset = number(o.offset ?? 0, 1000000), timeoutMs = number(o.timeoutSeconds ?? 30, 600, 1) * 1000;
58
- const w = workspace(c), target = args.input ? await w.importTarget(resolve(c.cwd, text(args.input, 4096))) : w.target(id(o.target)), input = await w.artifacts.verify(target.input), header = Buffer.alloc(32), handle = await open(input, 'r');
58
+ const w = workspace(c), target = args.input ? await w.importTarget(resolve(c.cwd, text(args.input, 4096))) : w.target(id(o.target, '--target')), input = await w.artifacts.verify(target.input), header = Buffer.alloc(32), handle = await open(input, 'r');
59
59
  try {
60
60
  await handle.read(header, 0, 32, 0);
61
61
  }
package/dist/src/llvm.js CHANGED
@@ -62,7 +62,7 @@ export function llvmCommands(workspace) {
62
62
  const operation = (name, options = []) => command(name + ' [input]', 'Native ' + name + ' through pinned LLVM utilities', async ({ args, options: o }, c) => {
63
63
  if (Boolean(args.input) === Boolean(o.target))
64
64
  fail('invalid', 'Supply exactly one input path or --target.');
65
- const w = workspace(c), target = args.input ? await w.importTarget(resolve(c.cwd, text(args.input, 4096))) : w.target(id(o.target)), input = await w.artifacts.verify(target.input);
65
+ const w = workspace(c), target = args.input ? await w.importTarget(resolve(c.cwd, text(args.input, 4096))) : w.target(id(o.target, '--target')), input = await w.artifacts.verify(target.input);
66
66
  const kind = await format(input), timeoutMs = number(o.timeoutSeconds, 600, 1) * 1000, limit = number(o.limit, 400, 1), offset = number(o.offset, 10000000, 0);
67
67
  const calls = [];
68
68
  if (name === 'headers' || name === 'sections')
@@ -25,7 +25,7 @@ export function managedHeapCommand(workspace, installer) {
25
25
  if (o.thread !== undefined && view !== 'stacks')
26
26
  fail('invalid', '--thread selects an OS thread in stacks view.');
27
27
  const limit = number(o.limit ?? 50, 500, 1), offset = number(o.offset ?? 0, 1000000), maxObjects = number(o.maxObjects ?? 1000000, 1000000, 1), runtime = number(o.runtimeIndex ?? 0, 15);
28
- const w = workspace(c), target = args.input ? await w.importTarget(resolve(c.cwd, text(args.input, 4096))) : w.target(id(o.target)), input = await w.artifacts.verify(target.input);
28
+ const w = workspace(c), target = args.input ? await w.importTarget(resolve(c.cwd, text(args.input, 4096))) : w.target(id(o.target, '--target')), input = await w.artifacts.verify(target.input);
29
29
  if (target.input.size > 4 * 1024 ** 3)
30
30
  fail('limit', 'Dump input exceeds four GiB.');
31
31
  return installer(c).use(async (selected) => {
@@ -13,7 +13,7 @@ const helper = fileURLToPath(new URL('../../runtime/managed/insight-managed/Insi
13
13
  export function metadataToken(value) { const token = text(value, 16); if (!/^0x06[0-9a-fA-F]{6}$/.test(token) || Number(token) === 0x06000000)
14
14
  fail('invalid', 'Select a nonzero MethodDef token (0x060000NN) from this exact managed target.'); return Number(token); }
15
15
  async function input(c, w, path, target) { if (Boolean(path) === Boolean(target))
16
- fail('invalid', 'Supply one managed input path or --target.'); const value = path ? await w.importTarget(resolve(c.cwd, text(path, 4096))) : w.target(id(target)); if (value.input.size > 64 * 1024 ** 2)
16
+ fail('invalid', 'Supply one managed input path or --target.'); const value = path ? await w.importTarget(resolve(c.cwd, text(path, 4096))) : w.target(id(target, '--target')); if (value.input.size > 64 * 1024 ** 2)
17
17
  fail('limit', 'Static managed input exceeds 64 MiB.'); return { path: await w.artifacts.verify(value.input), target: value.id, sha256: value.binarySha256 }; }
18
18
  export async function runManagedMetadata(c, selected, plan, externalHost) {
19
19
  let launch;
@@ -135,7 +135,7 @@ async function captureInput(c, w, path, targetId) { if (Boolean(path) === Boolea
135
135
  fail('binding', 'Empty archive changed while being captured.');
136
136
  return { path: copy, sha256: await fileSha256(copy), target: undefined };
137
137
  }
138
- } const target = path ? await w.importTarget(resolve(c.cwd, text(path, 4096))) : w.target(id(targetId)); if (target.input.size > 64 * 1024 ** 2)
138
+ } const target = path ? await w.importTarget(resolve(c.cwd, text(path, 4096))) : w.target(id(targetId, '--target')); if (target.input.size > 64 * 1024 ** 2)
139
139
  fail('limit', 'Native flow input exceeds 64 MiB.'); return { path: await w.artifacts.verify(target.input), target: target.id, sha256: target.binarySha256 }; }
140
140
  async function ordinary(c, path, value) { const output = resolve(c.cwd, text(path, 4096)), content = JSON.stringify(value, null, 2) + '\n'; await mkdir(dirname(output), { recursive: true, mode: 0o700 }); await writeFile(output, content, { flag: 'wx', mode: 0o600 }); return { output, bytes: Buffer.byteLength(content) }; }
141
141
  export function mitmproxyCommands(workspace) {
@@ -67,7 +67,12 @@ export declare const digest: (value: unknown) => string;
67
67
  export declare function fail(code: string, message: string, result?: unknown): never;
68
68
  export declare function object(value: unknown): Record<string, unknown>;
69
69
  export declare function text(value: unknown, max?: number): string;
70
- export declare function id(value: unknown): string;
70
+ /**
71
+ * A validated identifier. `option` names the command-line option it came from, so a refusal says which value was
72
+ * wrong and shows it: a caller's script that passes the wrong variable sees what it actually sent. The value appears only
73
+ * in the message, which Factory redacts; the structured result names the option alone.
74
+ */
75
+ export declare function id(value: unknown, option?: string): string;
71
76
  export declare function version(value: unknown): number;
72
77
  export declare function identity(value: unknown): Identity;
73
78
  export declare function assertIdentity(actual: Identity, expected: Identity): void;
package/dist/src/model.js CHANGED
@@ -17,10 +17,17 @@ export function text(value, max = 512) {
17
17
  fail('invalid', 'Expected a bounded non-empty string.');
18
18
  return value;
19
19
  }
20
- export function id(value) {
20
+ /**
21
+ * A validated identifier. `option` names the command-line option it came from, so a refusal says which value was
22
+ * wrong and shows it: a caller's script that passes the wrong variable sees what it actually sent. The value appears only
23
+ * in the message, which Factory redacts; the structured result names the option alone.
24
+ */
25
+ export function id(value, option) {
26
+ if (option && typeof value === 'string' && value.length > 128)
27
+ fail('invalid', `${option} is longer than 128 characters.`, { option });
21
28
  const result = text(value, 128);
22
29
  if (!/^[a-zA-Z0-9][a-zA-Z0-9_.-]*$/.test(result))
23
- fail('invalid', 'ID must use letters, digits, dot, underscore or hyphen.');
30
+ fail('invalid', `${option ?? 'ID'} must use letters, digits, dot, underscore or hyphen; received ${JSON.stringify(result)}.`, option ? { option } : undefined);
24
31
  return result;
25
32
  }
26
33
  export function version(value) {
@@ -41,7 +41,7 @@ export function mutationCommands(research) {
41
41
  parsed({ name: 'address', type: 'string', required: true, semantic: 'address' }, item.address);
42
42
  }
43
43
  }
44
- const selected = scope(o), request = o.requestId === undefined ? undefined : id(o.requestId);
44
+ const selected = scope(o), request = o.requestId === undefined ? undefined : id(o.requestId, '--request-id');
45
45
  mutationInputs(m.path, values);
46
46
  if (['/set_program_option', '/remove_program_option'].includes(m.path) && values.group === 'Program Information' && values.name === 'Executable SHA256')
47
47
  fail('binding', 'The immutable consumed input identity cannot be rewritten as a program option.');
@@ -292,11 +292,11 @@ export function projectCommands(service) {
292
292
  for (const key of ['input', 'output'])
293
293
  if (o[key] !== undefined)
294
294
  p[key] = resolve(c.cwd, text(o[key], 4096));
295
- return changing ? service(c).change(op, projectName(o.project), p, o.requestId === undefined ? undefined : id(o.requestId)) : service(c).read(op, projectName(o.project), p);
295
+ return changing ? service(c).change(op, projectName(o.project), p, o.requestId === undefined ? undefined : id(o.requestId, '--request-id')) : service(c).read(op, projectName(o.project), p);
296
296
  }, { permission, options }));
297
297
  }
298
298
  return [command('projects', 'Manage isolated Ghidra projects in the selected profile', leaves), command('program', 'Program files', [
299
- command('export', 'Export the selected private program to a new GZF file', ({ options: o }, c) => service(c).export(scope(o), resolve(c.cwd, text(o.output, 4096)), o.requestId === undefined ? undefined : id(o.requestId)), { permission: Permission.Update, options: [...selectedOptions, { flags: '--output <file>', description: 'New output file; existing files are preserved', required: true }, requestOption] }),
300
- command('import', 'Import a GZF into a managed project', ({ options: o }, c) => service(c).change('import', projectName(o.project), { input: resolve(c.cwd, text(o.input, 4096)), path: repositoryPath(o.path) }, o.requestId === undefined ? undefined : id(o.requestId)), { permission: Permission.Update, options: [projectOption, { flags: '--input <file>', description: 'Saved Ghidra program file', required: true }, { flags: '--path <path>', description: 'New file path inside the project', required: true }, requestOption] }),
299
+ command('export', 'Export the selected private program to a new GZF file', ({ options: o }, c) => service(c).export(scope(o), resolve(c.cwd, text(o.output, 4096)), o.requestId === undefined ? undefined : id(o.requestId, '--request-id')), { permission: Permission.Update, options: [...selectedOptions, { flags: '--output <file>', description: 'New output file; existing files are preserved', required: true }, requestOption] }),
300
+ command('import', 'Import a GZF into a managed project', ({ options: o }, c) => service(c).change('import', projectName(o.project), { input: resolve(c.cwd, text(o.input, 4096)), path: repositoryPath(o.path) }, o.requestId === undefined ? undefined : id(o.requestId, '--request-id')), { permission: Permission.Update, options: [projectOption, { flags: '--input <file>', description: 'Saved Ghidra program file', required: true }, { flags: '--path <path>', description: 'New file path inside the project', required: true }, requestOption] }),
301
301
  ])];
302
302
  }
@@ -110,11 +110,11 @@ export function createDefinition(options = {}) {
110
110
  command('targets', 'Select versioned programs', [
111
111
  command('register', 'Register a complete program identity', async ({ options: o }, c) => owner.selected(c).store.register(await jsonFile(c, o.file)), { permission: Permission.Update, options: fileOption }),
112
112
  command('list', 'List registered program identities', (_i, c) => owner.selected(c).store.targets(), { permission: Permission.ReadOnly }),
113
- command('show <target>', 'Show a registered program identity', ({ args }, c) => owner.selected(c).store.target(id(args.target)), { permission: Permission.ReadOnly }),
113
+ command('show <target>', 'Show a registered program identity', ({ args }, c) => owner.selected(c).store.target(id(args.target, 'target')), { permission: Permission.ReadOnly }),
114
114
  ]),
115
115
  command('workers', 'Manage independent reader processes', [
116
116
  command('start <target> <worker>', 'Start a reader and dedicated bridge', async ({ args }, c) => {
117
- const selected = owner.selected(c), target = selected.store.target(id(args.target)), worker = id(args.worker);
117
+ const selected = owner.selected(c), target = selected.store.target(id(args.target, 'target')), worker = id(args.worker);
118
118
  if (selected.store.workers().some(w => w.id === worker))
119
119
  fail('workerExists', 'Worker ID is already registered.');
120
120
  const binding = await selected.ghidra.startReader(target, worker);
@@ -143,10 +143,10 @@ export function createDefinition(options = {}) {
143
143
  }, { permission: Permission.ReadOnly, options: [{ flags: '--functions <selectors>', description: 'Select up to eight function references', required: true }] }),
144
144
  command('findings', 'Journal scoped comment proposals', [
145
145
  command('submit', 'Persist an idempotent finding proposal', async ({ options: o }, c) => owner.selected(c).store.submit(await jsonFile(c, o.file)), { permission: Permission.Update, options: fileOption }),
146
- command('list', 'List durable findings', ({ options: o }, c) => owner.selected(c).store.findings(o.target ? id(o.target) : undefined), { permission: Permission.ReadOnly, options: [{ flags: '--target <id>', description: 'Filter by registered target' }] }),
146
+ command('list', 'List durable findings', ({ options: o }, c) => owner.selected(c).store.findings(o.target ? id(o.target, '--target') : undefined), { permission: Permission.ReadOnly, options: [{ flags: '--target <id>', description: 'Filter by registered target' }] }),
147
147
  command('show <finding>', 'Show a finding and its outcome', ({ args }, c) => owner.selected(c).store.getFinding(id(args.finding)), { permission: Permission.ReadOnly }),
148
148
  ]),
149
- command('integrate <target>', 'Publish queued comments for one program', ({ args }, c) => owner.selected(c).coordinator.integrate(id(args.target)), { permission: Permission.Update }),
149
+ command('integrate <target>', 'Publish queued comments for one program', ({ args }, c) => owner.selected(c).coordinator.integrate(id(args.target, 'target')), { permission: Permission.Update }),
150
150
  command('status', 'Show durable publication state', (_i, c) => { const selected = owner.selected(c); return { ownerPid: process.pid, profile: c.profile.name, targets: selected.store.targets(), workers: selected.store.workers(), batches: selected.store.batches() }; }, { permission: Permission.ReadOnly }),
151
151
  command('recover <batch>', 'Reconcile an interrupted publication batch', ({ args, options: o }, c) => owner.selected(c).coordinator.recover(id(args.batch), Boolean(o.abandonStaged)), { permission: Permission.Update, options: [{ flags: '--abandon-staged', description: 'Abandon a stopped pre-publication stage' }] }),
152
152
  ],
@@ -40,7 +40,7 @@ export function number(value, maximum, minimum = 0) {
40
40
  fail('invalid', 'Numeric argument is outside its declared range.');
41
41
  return result;
42
42
  }
43
- export function scope(options) { return { session: id(options.session), target: id(options.target) }; }
43
+ export function scope(options) { return { session: id(options.session, '--session'), target: id(options.target, '--target') }; }
44
44
  const count = (context) => context.scalars.length + context.complexChanges.length;
45
45
  const revision = (value) => value === undefined ? undefined : 'R' + value;
46
46
  function comments(value) {