@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,8 +1,8 @@
1
1
  import { type CommandContext, type CommandDefinition } from '@eyeauras/cli-factory';
2
2
  import { atomicWrite } from './tool-runtime/store.js';
3
3
  export declare const runtimeWrite: typeof atomicWrite;
4
- /** Passive, conservative inventory: a reused PID blocks deletion; it never grants kill authority. */
5
- export declare function runtimeProcesses(directory: string): Promise<Record<string, unknown>[]>;
4
+ /** Passive, conservative inventory: an unproved PID blocks deletion; it never grants kill authority. */
5
+ export declare function runtimeProcesses(directory: string, control?: string): Promise<Record<string, unknown>[]>;
6
6
  export declare function externalGhidra(path: string): Promise<string>;
7
7
  export declare class RuntimeManager {
8
8
  private readonly c;
@@ -13,6 +13,7 @@ import { GhidraServer, stopLocalServer } from './server.js';
13
13
  import { fail, text, digest, object } from './model.js';
14
14
  import { atomicWrite, installationStage, removeInstallation, withToolLock, assertUnused } from './tool-runtime/store.js';
15
15
  import { lifecycleCommands as sharedLifecycle } from './tool-runtime/definition.js';
16
+ import { recordedProcessGone } from './tool-runtime/supervisor.js';
16
17
  import { managedGhidraDebugger, ghidraDebuggerInstaller, prepareGhidraDebugger } from './ghidra-debugger-runtime.js';
17
18
  const suffix = process.platform === 'win32' ? '.exe' : '';
18
19
  export const runtimeWrite = atomicWrite;
@@ -26,8 +27,30 @@ catch (error) {
26
27
  return false;
27
28
  throw error;
28
29
  } };
29
- /** Passive, conservative inventory: a reused PID blocks deletion; it never grants kill authority. */
30
- export async function runtimeProcesses(directory) {
30
+ /**
31
+ * A Ghidra binding bound to a supervisor receipt is settled by that receipt when it is the same Ghidra role, PID and
32
+ * root and has provably ended (including a proven PID reuse). Bindings without a matching receipt stay conservative.
33
+ * Receipts live in the Factory control directory, which can differ from the scanned analysis directory.
34
+ */
35
+ async function supervisorEnded(control, binding, role, root, rootKey) {
36
+ if (typeof binding.toolProcessId !== 'string')
37
+ return false;
38
+ try {
39
+ // The binding's PID is alive: only a fresh proof, on one validated receipt snapshot, settles it.
40
+ const row = await recordedProcessGone(control, binding.toolProcessId), recorded = row?.metadata?.[rootKey];
41
+ if (!row || row.tool !== 'ghidra' || row.role !== role || row.pid !== binding.pid || typeof recorded !== 'string')
42
+ return false;
43
+ const scanned = await realpath(root);
44
+ if (typeof binding.root === 'string' && await realpath(binding.root) !== scanned)
45
+ return false;
46
+ return await realpath(recorded) === scanned;
47
+ }
48
+ catch {
49
+ return false;
50
+ }
51
+ }
52
+ /** Passive, conservative inventory: an unproved PID blocks deletion; it never grants kill authority. */
53
+ export async function runtimeProcesses(directory, control = directory) {
31
54
  const items = [];
32
55
  async function walk(path, depth = 0) {
33
56
  if (depth > 6)
@@ -56,7 +79,8 @@ export async function runtimeProcesses(directory) {
56
79
  if (error.code !== 'ENOENT')
57
80
  throw error;
58
81
  }
59
- if (!stopped && live(p.pid))
82
+ // A GUI worker can own debugger state; it is settled only with debugger cleanup evidence (#153).
83
+ if (!stopped && live(p.pid) && (p.mode === 'gui' || !await supervisorEnded(control, p, String(p.kind), path, 'contextRoot')))
60
84
  items.push({ kind: p.kind, pid: p.pid, sessionContext: p.context, ...(typeof p.session === 'string' ? { session: p.session } : {}), target: p.target, mode: p.mode });
61
85
  }
62
86
  }
@@ -64,7 +88,7 @@ export async function runtimeProcesses(directory) {
64
88
  await walk(join(directory, 'workspace', 'ghidra-native'));
65
89
  try {
66
90
  const s = object(JSON.parse(await readFile(join(directory, 'workspace/server/local.json'), 'utf8')));
67
- if (live(s.pid))
91
+ if (live(s.pid) && !await supervisorEnded(control, s, 'server', join(directory, 'workspace'), 'serverDirectory'))
68
92
  items.push({ kind: 'server', pid: s.pid });
69
93
  }
70
94
  catch (error) {
@@ -202,7 +202,7 @@ export function sdkFileCommands(service) {
202
202
  { flags: '--request-id <id>', description: 'Retrieve retained export bytes without repeating native export' }];
203
203
  const databases = [];
204
204
  for (const kind of ['fid', 'bsim']) {
205
- databases.push(command('build-' + kind, 'Build a genuine native ' + kind + ' database from the saved private snapshot', ({ options: o }, c) => service(c).export(scope(o), kind + '-build', { library: text(o.library, 512), ...(kind === 'fid' ? { version: text(o.libraryVersion, 128) } : {}) }, resolve(c.cwd, text(o.outputDirectory, 4096)), o.requestId === undefined ? undefined : id(o.requestId)), { permission: Permission.Update, options: [...outputs, { flags: '--library <name>', description: 'Native library/database name', required: true }, ...(kind === 'fid' ? [{ flags: '--library-version <version>', description: 'Native library version', required: true }] : [])] }));
205
+ databases.push(command('build-' + kind, 'Build a genuine native ' + kind + ' database from the saved private snapshot', ({ options: o }, c) => service(c).export(scope(o), kind + '-build', { library: text(o.library, 512), ...(kind === 'fid' ? { version: text(o.libraryVersion, 128) } : {}) }, resolve(c.cwd, text(o.outputDirectory, 4096)), o.requestId === undefined ? undefined : id(o.requestId, '--request-id')), { permission: Permission.Update, options: [...outputs, { flags: '--library <name>', description: 'Native library/database name', required: true }, ...(kind === 'fid' ? [{ flags: '--library-version <version>', description: 'Native library version', required: true }] : [])] }));
206
206
  databases.push(command(kind + '-query', 'Query one explicitly consumed native ' + kind + ' database with provenance and no-match semantics', ({ options: o }, c) => {
207
207
  const p = { limit: number(o.limit, 1000, 1) };
208
208
  if (o.function !== undefined)
@@ -236,14 +236,14 @@ export function sdkFileCommands(service) {
236
236
  fail('invalid', 'Export ranges require 1–64 start/end objects.');
237
237
  p.ranges = ranges;
238
238
  }
239
- return service(c).export(scope(o), 'export', p, resolve(c.cwd, text(o.outputDirectory, 4096)), o.requestId === undefined ? undefined : id(o.requestId));
239
+ return service(c).export(scope(o), 'export', p, resolve(c.cwd, text(o.outputDirectory, 4096)), o.requestId === undefined ? undefined : id(o.requestId, '--request-id'));
240
240
  }, { permission: Permission.Update, options: [...outputs, { flags: '--exporter <id>', description: 'Explicit native exporter name/ID', required: true }, { flags: '--options <json>', description: 'Named primitive native options', defaultValue: '{}' }, { flags: '--ranges <json>', description: 'Address ranges with start/end; exporter must support restricted output' }] }),
241
241
  ]), command('types', 'Native type archives', [
242
242
  command('archive-export', 'Export 1–256 explicit type paths to a native GDT with checked layout', ({ options: o }, c) => {
243
243
  const types = json(o.types);
244
244
  if (!Array.isArray(types) || !types.length || types.length > 256 || types.some(v => typeof v !== 'string' || !v.startsWith('/')))
245
245
  fail('invalid', 'Types must be 1–256 absolute type paths.');
246
- return service(c).export(scope(o), 'archive-export', { types }, resolve(c.cwd, text(o.outputDirectory, 4096)), o.requestId === undefined ? undefined : id(o.requestId));
246
+ return service(c).export(scope(o), 'archive-export', { types }, resolve(c.cwd, text(o.outputDirectory, 4096)), o.requestId === undefined ? undefined : id(o.requestId, '--request-id'));
247
247
  }, { permission: Permission.Update, options: [...outputs, { flags: '--types <json>', description: 'Selected native type paths', required: true }] }),
248
248
  ])];
249
249
  }
package/dist/src/sdk.js CHANGED
@@ -111,7 +111,7 @@ export function sdkCommands(research) {
111
111
  p.archive = archive;
112
112
  }
113
113
  if (entry.write)
114
- return api.mutate(selected, operation, p, async () => ({}), o.requestId === undefined ? undefined : id(o.requestId), (backend, snapshot, response) => verifyMutation(backend, snapshot, operation, p, response));
114
+ return api.mutate(selected, operation, p, async () => ({}), o.requestId === undefined ? undefined : id(o.requestId, '--request-id'), (backend, snapshot, response) => verifyMutation(backend, snapshot, operation, p, response));
115
115
  const other = entry.pair ? { session: o.otherSession === undefined ? selected.session : id(o.otherSession), target: id(o.otherTarget) } : undefined;
116
116
  const value = object(other ? await api.crossRead(selected, other, operation, p) : await api.read(selected, operation, p));
117
117
  if (Buffer.byteLength(JSON.stringify(value)) > 1048576)
@@ -23,6 +23,7 @@ interface LocalServer extends ServerBinding {
23
23
  pid?: number;
24
24
  }
25
25
  export declare function retireReusedServer(directory: string, control: string, local: LocalServer): Promise<boolean>;
26
+ export declare function interpret(result: Record<string, unknown>): Record<string, unknown>;
26
27
  /** Own local startup; external profiles connect without taking ownership of their server. */
27
28
  export declare class GhidraServer {
28
29
  readonly directory: string;
@@ -1,6 +1,6 @@
1
1
  import { ghidraBudget } from './budgets.js';
2
2
  import { CliError } from '@eyeauras/cli-factory';
3
- import { launchProcess, terminateProcess, processStatus, listProcesses } from './tool-runtime/supervisor.js';
3
+ import { launchProcess, terminateProcess, listProcesses, recordedProcessGone } from './tool-runtime/supervisor.js';
4
4
  import { processIdentity } from './tool-runtime/identity.js';
5
5
  import { runTool } from './tool-runtime/run.js';
6
6
  import { randomUUID, randomBytes, createHash } from 'node:crypto';
@@ -30,13 +30,20 @@ async function forgetAuthority(directory) { await rm(join(directory, 'server', '
30
30
  export async function retireReusedServer(directory, control, local) {
31
31
  if (!local.pid || !local.toolProcessId)
32
32
  return false;
33
- const row = await processStatus(control, local.toolProcessId);
34
- if (row.phase !== 'pid_identity_changed' || row.tool !== 'ghidra' || row.role !== 'server' || row.pid !== local.pid || !row.strongIdentity || typeof row.identity !== 'string' || typeof row.metadata?.serverDirectory !== 'string' || await realpath(row.metadata.serverDirectory) !== await realpath(directory))
33
+ // Proved freshly from the PID's current holder on one validated receipt snapshot, never from its stored state or phase.
34
+ const row = await recordedProcessGone(control, local.toolProcessId);
35
+ if (!row || row.tool !== 'ghidra' || row.role !== 'server' || row.pid !== local.pid || typeof row.metadata?.serverDirectory !== 'string')
35
36
  return false;
36
- const observed = await processIdentity(local.pid);
37
- if (!observed?.strong || observed.birth === row.identity)
37
+ // A missing historical directory proves nothing; the authenticated stop path decides instead.
38
+ try {
39
+ if (await realpath(row.metadata.serverDirectory) !== await realpath(directory))
40
+ return false;
41
+ }
42
+ catch {
38
43
  return false;
39
- await durable(join(directory, 'server', 'retired-local-' + randomUUID() + '.json'), { schema: 1, reason: 'Original server birth is no longer alive; reused PID was not signaled.', local: { ...local }, process: row, observedBirth: observed.birth });
44
+ }
45
+ const observed = await processIdentity(local.pid);
46
+ await durable(join(directory, 'server', 'retired-local-' + randomUUID() + '.json'), { schema: 1, reason: 'Original server birth is no longer alive; reused PID was not signaled.', local: { ...local }, process: row, observedBirth: observed?.birth ?? null });
40
47
  local.phase = 'stopped';
41
48
  delete local.pid;
42
49
  delete local.toolProcessId;
@@ -51,7 +58,10 @@ function operationLabel(value) { return typeof value === 'string' && /^[a-z][a-z
51
58
  const outOfMemoryText = /OutOfMemoryError|Could not reserve enough space|insufficient memory for the Java Runtime|Native memory allocation \((m?malloc|mmap)\) failed|unable to create (new )?native thread|paging file is too small|errno=1455|os::commit_memory\(.*\) failed/i;
52
59
  /** Roles of the processes that can write native checkout journals: the one-shot helper and the publisher service. */
53
60
  const nativeWriterRoles = ['native-checkout', 'native-publisher'];
54
- function interpret(result) {
61
+ export function interpret(result) {
62
+ // The helper refused before writing the operation journal, so Ghidra was never called.
63
+ if (result.state === 'unknown' && result.code === 'not-sent' && typeof result.reason === 'string')
64
+ throw new CliError(result.reason, { code: 'tool.notSent', result: { diagnostic: result.diagnostic } });
55
65
  if (result.state === 'unknown' && typeof result.reason === 'string')
56
66
  fail(result.code === 'migration' ? 'migration' : 'unknown', result.reason, { diagnostic: result.diagnostic });
57
67
  if (result.error || result.state === 'failed')
@@ -61,7 +61,7 @@ export function sevenzipCommands(workspace) {
61
61
  const operation = (name) => command(name + ' [input]', name === 'list' ? 'Inspect a bounded archive inventory' : name === 'test' ? 'Check container integrity without extracting' : 'Recover regular files into a new ordinary directory', async ({ args, options: o }, c) => {
62
62
  if (Boolean(args.input) === Boolean(o.target))
63
63
  fail('invalid', 'Supply exactly one input path or --target.');
64
- const w = workspace(c), target = args.input ? await w.importTarget(resolve(c.cwd, text(args.input, 4096))) : w.target(id(o.target));
64
+ const w = workspace(c), target = args.input ? await w.importTarget(resolve(c.cwd, text(args.input, 4096))) : w.target(id(o.target, '--target'));
65
65
  const input = await w.artifacts.verify(target.input), timeoutMs = number(o.timeoutSeconds, 600, 1) * 1000;
66
66
  return sevenzipInstaller(c).use(async (selected) => {
67
67
  const invoke = (role, parameters, extra = {}) => runTool(c, { tool: 'sevenzip', role, installation: selected.id, executable: selected.executable, arguments: [...selected.arguments, ...parameters], environment: selected.environment, target: target.id, timeoutMs, ...extra });
@@ -41,7 +41,7 @@ export function straceCommands(workspace) {
41
41
  if (o.path)
42
42
  o = { ...o, path: resolve(c.cwd, text(o.path, 4096)) };
43
43
  const plan = stracePlan(o), limit = number(o.limit ?? 200, 1000, 1), offset = number(o.offset ?? 0, 1000000), timeoutMs = number(o.timeoutSeconds ?? 30, 600, 1) * 1000;
44
- 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(64), handle = await open(input, 'r');
44
+ 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(64), handle = await open(input, 'r');
45
45
  try {
46
46
  const { bytesRead } = await handle.read(header, 0, 64, 0);
47
47
  if (bytesRead < 64 || header.subarray(0, 4).toString('hex') !== '7f454c46' || header[4] !== 2 || header[5] !== 1 || header.readUInt16LE(18) !== 62)
@@ -40,13 +40,13 @@ export class Synchronization {
40
40
  * research queues remain unchanged, including their cross-context ordering and shared lane. */
41
41
  async execute(selected, path, input, run) {
42
42
  const configured = this.workspace.context(selected).syncPolicy ?? manualPolicy;
43
- const caller = input.requestId === undefined ? undefined : id(input.requestId);
43
+ const caller = input.requestId === undefined ? undefined : id(input.requestId, '--request-id');
44
44
  const recorded = caller ? this.workspace.scopedRequest(selected, caller) : undefined;
45
45
  if (caller && recorded?.id === caller)
46
46
  return run(caller);
47
47
  const previous = caller ? this.workspace.administrationByCaller(caller) : undefined;
48
- if (!previous && (configured.publish === 'manual' && configured.refresh === 'manual' || input.requestId !== undefined && this.workspace.requestByCaller(id(input.requestId))))
49
- return run(input.requestId === undefined ? '' : id(input.requestId));
48
+ if (!previous && (configured.publish === 'manual' && configured.refresh === 'manual' || input.requestId !== undefined && this.workspace.requestByCaller(id(input.requestId, '--request-id'))))
49
+ return run(input.requestId === undefined ? '' : id(input.requestId, '--request-id'));
50
50
  if (previous && previous.operation !== 'ghidra.automatic')
51
51
  fail('idempotency', 'Request ID already identifies another profile administration operation.');
52
52
  const policy = previous ? syncPolicy(object(object(previous.intent).parameters).policy) : configured;
@@ -123,7 +123,7 @@ export class Synchronization {
123
123
  export function synchronizationCommands(service) {
124
124
  return [command('sync-policy', 'Configure opt-in synchronization for one saved tool context', [
125
125
  command('get', 'Read the persisted policy; default is manual', ({ options: o }, c) => service(c).get(scope(o)), { permission: Permission.ReadOnly, options: selectedOptions }),
126
- command('set', 'Choose manual, publication after edit/save and optional refresh before edit', ({ options: o }, c) => service(c).set(scope(o), syncPolicy({ publish: text(o.publish), refresh: text(o.refresh) }), o.requestId === undefined ? undefined : id(o.requestId)), { permission: Permission.Update, options: [...selectedOptions,
126
+ command('set', 'Choose manual, publication after edit/save and optional refresh before edit', ({ options: o }, c) => service(c).set(scope(o), syncPolicy({ publish: text(o.publish), refresh: text(o.refresh) }), o.requestId === undefined ? undefined : id(o.requestId, '--request-id')), { permission: Permission.Update, options: [...selectedOptions,
127
127
  { flags: '--publish <mode>', description: 'manual, after-edit or after-save', required: true }, { flags: '--refresh <mode>', description: 'manual or before-edit', required: true }, { flags: '--request-id <id>', description: 'Retrieve the recorded policy change' }] }),
128
128
  ])];
129
129
  }
@@ -3,4 +3,11 @@ export interface ProcessIdentity {
3
3
  strong: boolean;
4
4
  group?: number;
5
5
  }
6
+ /** Exactly what this platform's probe emits; placeholders and foreign, malformed or non-canonical values never compare. */
7
+ export declare function comparableBirth(birth: unknown): birth is string;
8
+ /**
9
+ * The process now at a recorded PID has a different start identity of the same comparable shape: the recorded
10
+ * process ended and the PID was reused. This proves absence only; it never grants authority over the new holder.
11
+ */
12
+ export declare function birthChanged(recorded: unknown, current: ProcessIdentity | undefined): boolean;
6
13
  export declare function processIdentity(pid: number): Promise<ProcessIdentity | undefined>;
@@ -11,6 +11,41 @@ catch (e) {
11
11
  if (e.code === 'ESRCH')
12
12
  return;
13
13
  } return { birth: 'unavailable', strong: false }; }
14
+ const weekdays = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'], months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
15
+ /** macOS `ps -o lstart` in the C locale and UTC, e.g. `Thu Dec 3 21:56:45 2026`, naming a real instant. */
16
+ function canonicalDarwinBirth(birth) {
17
+ const m = /^([A-Z][a-z]{2}) ([A-Z][a-z]{2}) ([ 1-3]\d) (\d{2}):(\d{2}):(\d{2}) (\d{4})$/.exec(birth);
18
+ if (!m)
19
+ return false;
20
+ const [, weekday, monthName, day, hours, minutes, seconds, year] = m, month = months.indexOf(monthName);
21
+ if (month < 0)
22
+ return false;
23
+ const at = new Date(Date.UTC(Number(year), month, Number(day), Number(hours), Number(minutes), Number(seconds)));
24
+ return at.getUTCFullYear() === Number(year) && at.getUTCMonth() === month && at.getUTCDate() === Number(day) && at.getUTCHours() === Number(hours) &&
25
+ at.getUTCMinutes() === Number(minutes) && at.getUTCSeconds() === Number(seconds) && weekdays[at.getUTCDay()] === weekday && String(Number(day)).padStart(2, ' ') === day;
26
+ }
27
+ /** Exactly what this platform's probe emits; placeholders and foreign, malformed or non-canonical values never compare. */
28
+ export function comparableBirth(birth) {
29
+ if (typeof birth !== 'string')
30
+ return false;
31
+ const counter = (value, max) => /^(0|[1-9]\d{0,19})$/.test(value) && BigInt(value) <= max;
32
+ if (process.platform === 'linux') { // boot ID : start ticks (unsigned 64-bit)
33
+ const m = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}:(\d+)$/.exec(birth);
34
+ return Boolean(m && counter(m[1], 18446744073709551615n));
35
+ }
36
+ if (process.platform === 'win32')
37
+ return counter(birth, 3155378975999999999n); // UTC creation ticks up to DateTime.MaxValue
38
+ if (process.platform === 'darwin')
39
+ return canonicalDarwinBirth(birth);
40
+ return false;
41
+ }
42
+ /**
43
+ * The process now at a recorded PID has a different start identity of the same comparable shape: the recorded
44
+ * process ended and the PID was reused. This proves absence only; it never grants authority over the new holder.
45
+ */
46
+ export function birthChanged(recorded, current) {
47
+ return comparableBirth(recorded) && current !== undefined && comparableBirth(current.birth) && current.birth !== recorded;
48
+ }
14
49
  export async function processIdentity(pid) {
15
50
  return timed('tool.identity', process.platform, () => probeIdentity(pid));
16
51
  }
@@ -118,6 +118,9 @@ export async function assertUnused(directory, tool) {
118
118
  const { processStatus } = await import('./supervisor.js'), record = await processStatus(directory, name.slice(0, -5));
119
119
  if (['exited', 'failed'].includes(record.state))
120
120
  continue;
121
+ // A moved collector's helper receipts cannot be inspected; its own PID says nothing about its helpers.
122
+ if (record.phase === 'profile_binding_changed' && record.metadata?.nativeChildDeadlines === true)
123
+ fail('busy', 'Tool has a moved collector whose native helpers cannot be inspected; inspect its retained records before changing installations.');
121
124
  if (record.phase === 'native_children_pending' || record.phase === 'native_children_unverified')
122
125
  fail('busy', 'Tool has an active or unverified native helper; inspect its retained records before changing installations.');
123
126
  if (!record.pid) {
@@ -26,6 +26,14 @@ export interface TrackedChild extends ChildProcess {
26
26
  toolClosed: Promise<void>;
27
27
  }
28
28
  export type OwnershipVerifier = (record: ProcessRecord) => Promise<boolean | undefined>;
29
+ /**
30
+ * The process a receipt recorded is gone from its PID, proved freshly and never from the receipt's stored state or
31
+ * phase: no process holds the PID, or its holder has a different canonical birth. A child this owner still holds
32
+ * alive is never gone. Grants no authority over the PID's current holder.
33
+ */
34
+ export declare function recordedProcessGone(directory: string, id: string): Promise<ProcessRecord | undefined>;
35
+ /** Exactly what the receipt writer emits (`Date#toISOString`); impossible dates are not normalized into evidence. */
36
+ export declare function validEnd(value: unknown): boolean;
29
37
  export declare function launchProcess(directory: string, spec: ProcessSpec, executable: string, args: string[], options?: SpawnOptions, control?: {
30
38
  id?: string;
31
39
  finalize?: boolean;
@@ -8,12 +8,57 @@ import { randomUUID } from 'node:crypto';
8
8
  import { setTimeout as delay } from 'node:timers/promises';
9
9
  import { CliError } from '@eyeauras/cli-factory';
10
10
  import { atomicWrite, readJson, toolRoot, withToolLock, prepareRunRoot } from './store.js';
11
- import { processIdentity } from './identity.js';
11
+ import { processIdentity, birthChanged } from './identity.js';
12
12
  import { javaClasspathArguments } from './java-arguments.js';
13
13
  import { digest } from '../model.js';
14
14
  import { timed } from '../internal-timing.js';
15
15
  const owned = new Map();
16
16
  const ownedKey = (directory, id) => resolve(directory) + '\0' + id;
17
+ /**
18
+ * The process a receipt recorded is gone from its PID, proved freshly and never from the receipt's stored state or
19
+ * phase: no process holds the PID, or its holder has a different canonical birth. A child this owner still holds
20
+ * alive is never gone. Grants no authority over the PID's current holder.
21
+ */
22
+ export async function recordedProcessGone(directory, id) {
23
+ if (!/^[a-f0-9-]{36}$/.test(id))
24
+ return undefined;
25
+ // One snapshot: the receipt whose profile is checked is the one whose birth is compared, and callers validate
26
+ // their own fields (tool, role, PID, root) on this returned snapshot.
27
+ const stored = await readJson(join(directory, 'runtime/processes', id + '.json'));
28
+ if (!stored || stored.id !== id || !Number.isSafeInteger(stored.pid) || Number(stored.pid) < 1 || heldByThisOwner(id) || !ownedByProfile(directory, id, stored))
29
+ return undefined;
30
+ // A stored terminal state without its exact recorded end is ambiguous; a stored phase is never proof.
31
+ if (['exited', 'failed'].includes(stored.state) && !validEnd(stored.endedAt))
32
+ return undefined;
33
+ const current = await processIdentity(Number(stored.pid));
34
+ return !current || birthChanged(stored.identity, current) ? stored : undefined;
35
+ }
36
+ /** The receipt belongs to this profile directory, directly or through a proven alias of it. */
37
+ function ownedByProfile(directory, id, record) {
38
+ if (record.root === join(directory, 'runtime/runs', id) && record.profileBinding === digest(resolve(directory)))
39
+ return true;
40
+ try {
41
+ const recorded = resolve(record.root, '../../..');
42
+ return record.root === join(recorded, 'runtime/runs', id) && record.profileBinding === digest(recorded) && sameDirectory(recorded, directory);
43
+ }
44
+ catch {
45
+ return false;
46
+ }
47
+ }
48
+ /** Exactly what the receipt writer emits (`Date#toISOString`); impossible dates are not normalized into evidence. */
49
+ export function validEnd(value) {
50
+ if (typeof value !== 'string')
51
+ return false;
52
+ const at = Date.parse(value);
53
+ return Number.isFinite(at) && new Date(at).toISOString() === value;
54
+ }
55
+ /** This owner launched the record's process and still holds it alive, whatever the record or its path spelling now says. */
56
+ function heldByThisOwner(id) {
57
+ for (const current of owned.values())
58
+ if (current.record.id === id && current.child.exitCode === null && current.child.signalCode === null)
59
+ return true;
60
+ return false;
61
+ }
17
62
  /** Receipts report pending lifetime only; they never authorize a signal to another PID. */
18
63
  async function nativeChildren(record) {
19
64
  if (record.metadata?.nativeChildDeadlines !== true)
@@ -195,13 +240,8 @@ export async function processStatus(directory, id, verify) {
195
240
  throw new CliError('Unknown tool process.', { code: 'tool.process.missing' });
196
241
  if (record.root !== join(directory, 'runtime/runs', id) || record.profileBinding !== digest(resolve(directory))) {
197
242
  // Retain the recorded spelling/digest, but prove its owner is this same directory.
198
- let alias = false;
199
- try {
200
- const recorded = resolve(record.root, '../../..');
201
- alias = record.root === join(recorded, 'runtime/runs', id) && record.profileBinding === digest(recorded) && sameDirectory(recorded, directory);
202
- }
203
- catch { }
204
- if (!alias)
243
+ // A moved or copied receipt grants no authority and stays unresolved; storage migration has its own stricter proof.
244
+ if (!ownedByProfile(directory, id, record))
205
245
  return { ...record, state: 'unverified', phase: 'profile_binding_changed' };
206
246
  }
207
247
  const finishing = owned.get(ownedKey(directory, id));
@@ -232,8 +272,13 @@ export async function processStatus(directory, id, verify) {
232
272
  const identity = await processIdentity(record.pid);
233
273
  if (!identity)
234
274
  return { ...observed, state: pending ? 'unverified' : 'exited', phase: pending ? 'native_children_pending' : 'observed_exit', outcome: 'unknown' };
235
- if (identity.birth !== record.identity)
236
- return { ...record, state: 'unverified', phase: 'pid_identity_changed' };
275
+ if (identity.birth !== record.identity) {
276
+ // A different comparable birth proves the recorded process ended and its PID was reused. The new holder is never
277
+ // adopted or signalled; pending native helpers keep the record unresolved.
278
+ if (!pending && !heldByThisOwner(record.id) && birthChanged(record.identity, identity))
279
+ return { ...observed, state: 'exited', phase: 'pid_identity_changed', outcome: record.outcome ?? 'unknown' };
280
+ return { ...observed, state: 'unverified', phase: pending ? 'native_children_pending' : 'pid_identity_changed' };
281
+ }
237
282
  const current = owned.get(ownedKey(directory, id)), local = current?.child.pid === record.pid && current.record.identity === record.identity && current.child.exitCode === null && current.child.signalCode === null;
238
283
  const proof = verify ? await verify(record) : undefined;
239
284
  if (local || proof === true || proof === undefined && record.strongIdentity && identity.strong)
@@ -270,6 +315,9 @@ export async function terminateProcess(directory, id, force, verify, graceful) {
270
315
  if (!force && graceful)
271
316
  await graceful(record);
272
317
  let current = await processStatus(directory, id, verify);
318
+ // The PID was proven reused before any signal: report the ended process without claiming a stop or kill.
319
+ if (current.state === 'exited' && current.phase === 'pid_identity_changed')
320
+ return { process: id, state: 'already_exited' };
273
321
  if (!['exited', 'failed'].includes(current.state)) {
274
322
  if (current.state !== 'running' || current.pid !== record.pid)
275
323
  throw new CliError('Process identity changed during stop.', { code: 'tool.process.unverified' });
@@ -94,7 +94,7 @@ export function tsharkCommands(workspace) {
94
94
  const transport = view === 'follow' ? text(o.transport, 8) : undefined, stream = view === 'follow' ? number(o.stream, 1000000) : undefined;
95
95
  if (transport && !['tcp', 'udp'].includes(transport))
96
96
  fail('invalid', 'Follow transport must be tcp or udp.');
97
- 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);
97
+ 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);
98
98
  if (target.input.size > 64 * 1024 ** 2)
99
99
  fail('limit', 'Capture input exceeds 64 MiB.');
100
100
  const file = await open(input, 'r'), header = Buffer.alloc(4);
package/dist/src/ui.js CHANGED
@@ -69,12 +69,12 @@ export function uiCommands(service) {
69
69
  return service(c).read(scope(o), 'cursor', type);
70
70
  }, { permission: Permission.ReadOnly, options: [...selectedOptions, { flags: '--type <facet>', description: 'Cursor facet or all', defaultValue: 'all' }] }),
71
71
  command('tools', 'Read tools in the owned GUI context', ({ options: o }, c) => service(c).read(scope(o), 'tools'), { permission: Permission.ReadOnly, options: selectedOptions }),
72
- command('goto', 'Navigate the owned browser and verify the cursor', ({ options: o }, c) => service(c).change(scope(o), 'goto', { address: address(o.address) }, o.requestId === undefined ? undefined : id(o.requestId)), { permission: Permission.Update, options: [...selectedOptions, { flags: '--address <address>', description: 'Explicit address', required: true }, request] }),
72
+ command('goto', 'Navigate the owned browser and verify the cursor', ({ options: o }, c) => service(c).change(scope(o), 'goto', { address: address(o.address) }, o.requestId === undefined ? undefined : id(o.requestId, '--request-id')), { permission: Permission.Update, options: [...selectedOptions, { flags: '--address <address>', description: 'Explicit address', required: true }, request] }),
73
73
  command('prompt-policy', 'Temporarily control the owned GUI prompt policy', ({ options: o }, c) => {
74
74
  const action = text(o.action);
75
75
  if (!['status', 'enable', 'disable'].includes(action))
76
76
  fail('invalid', 'Prompt policy action must be status, enable or disable.');
77
- return service(c).change(scope(o), 'prompt_policy', { action, reason: text(o.reason, 512), seconds: number(o.seconds, 300, 1) }, o.requestId === undefined ? undefined : id(o.requestId));
77
+ return service(c).change(scope(o), 'prompt_policy', { action, reason: text(o.reason, 512), seconds: number(o.seconds, 300, 1) }, o.requestId === undefined ? undefined : id(o.requestId, '--request-id'));
78
78
  }, { permission: Permission.Update, options: [...selectedOptions, { flags: '--action <action>', description: 'status, enable or disable', defaultValue: 'status' },
79
79
  { flags: '--reason <text>', description: 'Recorded policy reason', defaultValue: 'automation' }, { flags: '--seconds <count>', description: 'Requested duration (1–300 seconds)', defaultValue: 120 }, request] }),
80
80
  ])];
@@ -83,6 +83,6 @@ export function pluginCommands(service) {
83
83
  return [command('plugins', 'Configure plugins from enabled managed modules in an owned GUI', [
84
84
  command('list', 'Read enabled managed plugins in this GUI tool', ({ options: o }, c) => service(c).read(scope(o), 'plugins_list'), { permission: Permission.ReadOnly, options: selectedOptions }),
85
85
  command('set', 'Enable or disable one installed managed plugin with immediate readback', ({ options: o }, c) => { if (o.enabled !== 'true' && o.enabled !== 'false')
86
- fail('invalid', 'enabled must be true or false.'); return service(c).change(scope(o), 'plugins_set', { plugin: text(o.plugin, 512), enabled: o.enabled === 'true' }, o.requestId === undefined ? undefined : id(o.requestId)); }, { permission: 'Destructive', options: [...selectedOptions, { flags: '--plugin <class>', description: 'Managed plugin ID from extensions capabilities', required: true }, { flags: '--enabled <boolean>', description: 'true or false', required: true }, { flags: '--request-id <id>', description: 'Retrieve the original plugin outcome without replay' }] })
86
+ fail('invalid', 'enabled must be true or false.'); return service(c).change(scope(o), 'plugins_set', { plugin: text(o.plugin, 512), enabled: o.enabled === 'true' }, o.requestId === undefined ? undefined : id(o.requestId, '--request-id')); }, { permission: 'Destructive', options: [...selectedOptions, { flags: '--plugin <class>', description: 'Managed plugin ID from extensions capabilities', required: true }, { flags: '--enabled <boolean>', description: 'true or false', required: true }, { flags: '--request-id <id>', description: 'Retrieve the original plugin outcome without replay' }] })
87
87
  ])];
88
88
  }
@@ -187,7 +187,7 @@ export function trackingCommands(service) {
187
187
  command('list', 'List VT objects owned by this destination research scope, including retained creation stages', ({ options: o }, c) => service(c).list(scope(o), number(o.offset, 1000000), number(o.limit, 1000, 1)), { permission: Permission.ReadOnly, options: [...selectedOptions, { flags: '--limit <count>', description: 'Maximum returned owned VT objects', defaultValue: 100 }, { flags: '--offset <count>', description: 'Inventory offset; use nextOffset after a partial scan', defaultValue: 0 }] }),
188
188
  command('create', 'Correlate immutable source/destination snapshots in a persistent owned native VT project', ({ options: o }, c) => {
189
189
  const selected = scope(o), source = { session: o.sourceSession === undefined ? selected.session : id(o.sourceSession), target: id(o.sourceTarget) };
190
- return service(c).create(selected, source, o.requestId === undefined ? undefined : id(o.requestId));
190
+ return service(c).create(selected, source, o.requestId === undefined ? undefined : id(o.requestId, '--request-id'));
191
191
  }, { permission: Permission.Update, options: [...selectedOptions, { flags: '--source-target <id>', description: 'Source immutable target', required: true }, { flags: '--source-session <id>', description: 'Source research session (default destination session)' }, request] }),
192
192
  command('matches', 'Read native match sets and correlator-specific scores from the saved VT object', ({ options: o }, c) => service(c).read(scope(o), id(o.tracking), 'matches', { limit: number(o.limit, 1000, 1), offset: number(o.offset, 100000) }), { permission: Permission.ReadOnly, options: [...selectedOptions, tracking, { flags: '--limit <count>', description: 'Match page size 1–1000', defaultValue: 100 }, { flags: '--offset <count>', description: 'Page offset', defaultValue: 0 }] }),
193
193
  command('markup', 'Inspect native markup values for one association before agent-directed edits', ({ options: o }, c) => service(c).read(scope(o), id(o.tracking), 'markup', { source_address: address(o.sourceAddress), destination_address: address(o.destinationAddress) }), { permission: Permission.ReadOnly, options: [...selectedOptions, tracking, ...association] }),
@@ -195,7 +195,7 @@ export function trackingCommands(service) {
195
195
  const decision = text(o.decision);
196
196
  if (!['accepted', 'rejected', 'available'].includes(decision))
197
197
  fail('invalid', 'Decision must be accepted, rejected or available.');
198
- return service(c).decide(scope(o), id(o.tracking), { source_address: address(o.sourceAddress), destination_address: address(o.destinationAddress), decision }, o.requestId === undefined ? undefined : id(o.requestId));
198
+ return service(c).decide(scope(o), id(o.tracking), { source_address: address(o.sourceAddress), destination_address: address(o.destinationAddress), decision }, o.requestId === undefined ? undefined : id(o.requestId, '--request-id'));
199
199
  }, { permission: Permission.Update, options: [...selectedOptions, tracking, ...association, { flags: '--decision <state>', description: 'accepted, rejected or available', required: true }, request] }),
200
200
  ])];
201
201
  }
@@ -86,7 +86,7 @@ export function windbgCommands(workspace) {
86
86
  if (Boolean(args.input) === Boolean(o.target))
87
87
  fail('invalid', 'Supply exactly one dump path or --target.');
88
88
  const nonce = randomUUID().replaceAll('-', ''), plan = windbgPlan(o, nonce), limit = number(o.limit ?? 200, 1000, 1), offset = number(o.offset ?? 0, 1000000), timeoutMs = number(o.timeoutSeconds ?? 30, 600, 1) * 1000;
89
- 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');
89
+ 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');
90
90
  try {
91
91
  const { bytesRead } = await handle.read(header, 0, 32, 0);
92
92
  if (bytesRead < 32 || header.subarray(0, 4).toString('ascii') !== 'MDMP')
@@ -5,7 +5,7 @@ import { open, lstat, mkdir, realpath, link, unlink, rmdir } from 'node:fs/promi
5
5
  import { resolve, dirname, basename, join, relative, isAbsolute, sep } from 'node:path';
6
6
  import { Artifacts } from '../artifacts.js';
7
7
  import { workSchema, workTableColumns } from './store.js';
8
- import { archivedOutcomes, array, definition, digest, fail, identifier, integer, object, sha, stable, string } from './model.js';
8
+ import { archivedOutcomes, array, definition, digest, fail, identifier, integer, object, sha, stable, string, discoverLimits, discoverScope, taskKinds } from './model.js';
9
9
  const manifestLimit = 32 * 1024 * 1024, stateLimit = 2 * 1024 * 1024 * 1024, lineLimit = 16 * 1024 * 1024, artifactLimit = 100000;
10
10
  const stages = ['discovered', 'partial', 'reconstructed', 'corpus_match', 'reviewed', 'mismatch'];
11
11
  function artifact(value) {
@@ -320,8 +320,20 @@ function validateStage(db, targets, incarnation) {
320
320
  identifier(task.id);
321
321
  integer(task.fence, 0, Number.MAX_SAFE_INTEGER);
322
322
  integer(task.leaseUntil, 0, Number.MAX_SAFE_INTEGER);
323
- if (!['reconstruct', 'review'].includes(task.kind) || task.epoch !== projects.get(task.project)?.epoch)
323
+ if (!taskKinds.includes(task.kind) || task.epoch !== projects.get(task.project)?.epoch)
324
324
  fail('backup', 'Invalid task kind/epoch.');
325
+ if (task.kind === 'discover') {
326
+ const scope = discoverScope(object(task.discover));
327
+ if (stable(scope) !== stable(task.discover) || array(task.functions, 50).length > scope.maxFunctions)
328
+ fail('backup', 'Invalid discovery scope.');
329
+ if (task.status === 'submitted') {
330
+ const report = artifact(object(object(task.result).report));
331
+ if (report.kind !== 'input' || report.size > discoverLimits.reportBytes)
332
+ fail('backup', 'Invalid discovery report reference.');
333
+ }
334
+ }
335
+ else if (task.discover !== undefined)
336
+ fail('backup', 'Traversal scope belongs to discover tasks only.');
325
337
  const ids = array(task.functions, 50).map(x => string(x, 256));
326
338
  if (!ids.length || new Set(ids).size !== ids.length)
327
339
  fail('backup', 'Invalid frozen scope.');