@eyeauras/insight-cli 0.8.2 → 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.
- package/.cli-package-build.json +1 -1
- package/README.md +53 -7
- package/SKILL.md +4 -8
- package/dist/src/administration.js +1 -1
- package/dist/src/archive.js +1 -1
- package/dist/src/artifacts.d.ts +2 -1
- package/dist/src/artifacts.js +6 -5
- package/dist/src/binary.js +1 -1
- package/dist/src/capture.js +3 -3
- package/dist/src/cli.js +17 -16
- package/dist/src/contexts.js +14 -17
- package/dist/src/cross.js +1 -1
- package/dist/src/debugger.js +1 -1
- package/dist/src/die.js +1 -1
- package/dist/src/dnspy.js +1 -1
- package/dist/src/dotnet-diagnostics.js +1 -1
- package/dist/src/ilspy.js +1 -1
- package/dist/src/lifecycle.js +5 -5
- package/dist/src/lldb.js +1 -1
- package/dist/src/llvm.js +1 -1
- package/dist/src/managed-heap.js +1 -1
- package/dist/src/managed-metadata.js +1 -1
- package/dist/src/mitmproxy.js +1 -1
- package/dist/src/model.d.ts +6 -1
- package/dist/src/model.js +9 -2
- package/dist/src/mutations.js +1 -1
- package/dist/src/projects.js +3 -3
- package/dist/src/prototype-cli.js +4 -4
- package/dist/src/research.js +1 -1
- package/dist/src/runtime-manager.d.ts +2 -2
- package/dist/src/runtime-manager.js +28 -4
- package/dist/src/sdk-files.js +3 -3
- package/dist/src/sdk.js +1 -1
- package/dist/src/server.d.ts +1 -0
- package/dist/src/server.js +17 -7
- package/dist/src/sevenzip.js +1 -1
- package/dist/src/strace.js +1 -1
- package/dist/src/sync-policy.js +4 -4
- package/dist/src/tool-runtime/identity.d.ts +7 -0
- package/dist/src/tool-runtime/identity.js +35 -0
- package/dist/src/tool-runtime/store.js +3 -0
- package/dist/src/tool-runtime/supervisor.d.ts +8 -0
- package/dist/src/tool-runtime/supervisor.js +58 -10
- package/dist/src/tshark.js +1 -1
- package/dist/src/ui.js +3 -3
- package/dist/src/version-tracking.js +2 -2
- package/dist/src/windbg.js +1 -1
- package/dist/src/work/backup.js +17 -5
- package/dist/src/work/commands.js +51 -14
- package/dist/src/work/model.d.ts +43 -1
- package/dist/src/work/model.js +128 -0
- package/dist/src/work/store.d.ts +34 -3
- package/dist/src/work/store.js +78 -21
- package/dist/src/work/timing.d.ts +9 -0
- package/dist/src/work/timing.js +10 -1
- package/package.json +1 -1
- package/references/agent-setup.md +2 -11
- package/references/debugger.md +1 -1
- package/references/managed-runtime.md +1 -2
- package/references/native/InsightNativeCheckout.java +24 -8
- package/references/recovery.md +2 -34
- package/references/research.md +5 -5
- package/references/setup.md +0 -4
- package/references/work-tracking.md +61 -3
- package/skill-bundle/insight-artifacts/SKILL.md +3 -7
- package/skill-bundle/insight-artifacts/references/recovery.md +2 -34
- package/skill-bundle/insight-binary/SKILL.md +3 -7
- package/skill-bundle/insight-capture/SKILL.md +3 -7
- package/skill-bundle/insight-cli/SKILL.md +4 -8
- package/skill-bundle/insight-cli/references/agent-setup.md +2 -11
- package/skill-bundle/insight-cli/references/managed-runtime.md +1 -2
- package/skill-bundle/insight-cli/references/recovery.md +2 -34
- package/skill-bundle/insight-cli/references/setup.md +0 -4
- package/skill-bundle/insight-die/SKILL.md +3 -7
- package/skill-bundle/insight-dnspy/SKILL.md +3 -7
- package/skill-bundle/insight-dotnet-dump/SKILL.md +3 -7
- package/skill-bundle/insight-dotnet-stack/SKILL.md +3 -7
- package/skill-bundle/insight-dotnet-trace/SKILL.md +3 -7
- package/skill-bundle/insight-frida/SKILL.md +3 -7
- package/skill-bundle/insight-ghidra/SKILL.md +13 -36
- package/skill-bundle/insight-ghidra/references/debugger.md +1 -1
- package/skill-bundle/insight-ghidra/references/managed-runtime.md +1 -2
- package/skill-bundle/insight-ghidra/references/recovery.md +2 -34
- package/skill-bundle/insight-ghidra/references/research.md +5 -5
- package/skill-bundle/insight-ghidra/references/setup.md +0 -4
- package/skill-bundle/insight-ilspy/SKILL.md +3 -7
- package/skill-bundle/insight-interop/SKILL.md +3 -7
- package/skill-bundle/insight-lldb/SKILL.md +3 -7
- package/skill-bundle/insight-llvm/SKILL.md +3 -7
- package/skill-bundle/insight-managed-heap/SKILL.md +3 -7
- package/skill-bundle/insight-managed-metadata/SKILL.md +3 -7
- package/skill-bundle/insight-mitmproxy/SKILL.md +3 -7
- package/skill-bundle/insight-overview/SKILL.md +3 -7
- package/skill-bundle/insight-procmon/SKILL.md +3 -7
- package/skill-bundle/insight-re/SKILL.md +4 -8
- package/skill-bundle/insight-re/references/recovery.md +2 -34
- package/skill-bundle/insight-re/references/work-tracking.md +61 -3
- package/skill-bundle/insight-sevenzip/SKILL.md +3 -7
- package/skill-bundle/insight-strace/SKILL.md +3 -7
- package/skill-bundle/insight-tshark/SKILL.md +3 -7
- package/skill-bundle/insight-windbg/SKILL.md +3 -7
- package/skill-bundle/manifest.json +1 -1
- package/skills/insight-artifacts/SKILL.md +3 -7
- package/skills/insight-artifacts/references/recovery.md +2 -34
- package/skills/insight-binary/SKILL.md +3 -7
- package/skills/insight-capture/SKILL.md +3 -7
- package/skills/insight-die/SKILL.md +3 -7
- package/skills/insight-dnspy/SKILL.md +3 -7
- package/skills/insight-dotnet-dump/SKILL.md +3 -7
- package/skills/insight-dotnet-stack/SKILL.md +3 -7
- package/skills/insight-dotnet-trace/SKILL.md +3 -7
- package/skills/insight-frida/SKILL.md +3 -7
- package/skills/insight-ghidra/SKILL.md +13 -36
- package/skills/insight-ghidra/references/debugger.md +1 -1
- package/skills/insight-ghidra/references/managed-runtime.md +1 -2
- package/skills/insight-ghidra/references/recovery.md +2 -34
- package/skills/insight-ghidra/references/research.md +5 -5
- package/skills/insight-ghidra/references/setup.md +0 -4
- package/skills/insight-ilspy/SKILL.md +3 -7
- package/skills/insight-interop/SKILL.md +3 -7
- package/skills/insight-lldb/SKILL.md +3 -7
- package/skills/insight-llvm/SKILL.md +3 -7
- package/skills/insight-managed-heap/SKILL.md +3 -7
- package/skills/insight-managed-metadata/SKILL.md +3 -7
- package/skills/insight-mitmproxy/SKILL.md +3 -7
- package/skills/insight-overview/SKILL.md +3 -7
- package/skills/insight-procmon/SKILL.md +3 -7
- package/skills/insight-re/SKILL.md +4 -8
- package/skills/insight-re/references/recovery.md +2 -34
- package/skills/insight-re/references/work-tracking.md +61 -3
- package/skills/insight-sevenzip/SKILL.md +3 -7
- package/skills/insight-strace/SKILL.md +3 -7
- package/skills/insight-tshark/SKILL.md +3 -7
- package/skills/insight-windbg/SKILL.md +3 -7
package/dist/src/work/backup.js
CHANGED
|
@@ -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) {
|
|
@@ -33,7 +33,7 @@ function references(value, refs, depth = 0) {
|
|
|
33
33
|
fail('backup', 'Conflicting artifact declarations.');
|
|
34
34
|
refs.set(a.id, a);
|
|
35
35
|
if (refs.size > artifactLimit)
|
|
36
|
-
fail('limit', '
|
|
36
|
+
fail('limit', 'Work backup exceeds 100000 artifact references.');
|
|
37
37
|
}
|
|
38
38
|
if (r.record === 'row') {
|
|
39
39
|
const row = object(r.row);
|
|
@@ -76,11 +76,11 @@ async function scanState(path, expected, visit) {
|
|
|
76
76
|
const line = pending.slice(0, index);
|
|
77
77
|
pending = pending.slice(index + 1);
|
|
78
78
|
if (!line || Buffer.byteLength(line) > lineLimit)
|
|
79
|
-
fail('limit', 'State record exceeds the
|
|
79
|
+
fail('limit', 'State record exceeds the backup record budget.');
|
|
80
80
|
visit(object(JSON.parse(line)));
|
|
81
81
|
}
|
|
82
82
|
if (Buffer.byteLength(pending) > lineLimit)
|
|
83
|
-
fail('limit', 'State record exceeds the
|
|
83
|
+
fail('limit', 'State record exceeds the backup record budget.');
|
|
84
84
|
}
|
|
85
85
|
if (pending || size !== expected.size || hash.digest('hex') !== expected.sha256)
|
|
86
86
|
fail('backup', 'State is incomplete or its hash changed.');
|
|
@@ -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 (!
|
|
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.');
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { command, Permission } from '@eyeauras/cli-factory';
|
|
2
2
|
import { basename, dirname, resolve } from 'node:path';
|
|
3
3
|
import { lstat, readFile, mkdir, copyFile, writeFile } from 'node:fs/promises';
|
|
4
|
-
import { array, fail, identifier, integer, object, parseLease, passport, rva, sha, string } from './model.js';
|
|
4
|
+
import { array, discoverLimits, discoverScope, fail, identifier, integer, object, parseLease, passport, rva, sha, string } from './model.js';
|
|
5
5
|
import { packageVersion } from '../package-version.js';
|
|
6
6
|
import { WorkStore } from './store.js';
|
|
7
7
|
import { saveDashboard } from './dashboard.js';
|
|
@@ -31,18 +31,35 @@ function leaseOf(o) {
|
|
|
31
31
|
return { task: identifier(o.task), worker: identifier(o.worker), fence: integer(o.fence, 1, Number.MAX_SAFE_INTEGER), ...(o.epoch === undefined ? {} : { epoch: identifier(o.epoch) }) };
|
|
32
32
|
}
|
|
33
33
|
const functionId = { flags: '--function <id>', description: 'Exact full-hash/RVA function identity', required: true };
|
|
34
|
+
const kindOption = { flags: '--kind <kind>', description: 'reconstruct, review or discover', defaultValue: 'reconstruct' };
|
|
35
|
+
/** Traversal of a discover task; --functions names its roots. */
|
|
36
|
+
const traversal = [
|
|
37
|
+
{ flags: '--strategy <strategy>', description: 'discover: breadth (BFS, default) or depth (DFS)' },
|
|
38
|
+
{ flags: '--direction <direction>', description: 'discover: callees (default), callers or both' },
|
|
39
|
+
{ flags: '--max-depth <n>', description: `discover: deepest level, roots are 0 (default 2, at most ${discoverLimits.maxDepth})` },
|
|
40
|
+
{ flags: '--max-functions <n>', description: `discover: most visited functions including roots (default 50, at most ${discoverLimits.maxFunctions})` }
|
|
41
|
+
];
|
|
42
|
+
function traversalOf(o) {
|
|
43
|
+
const given = [o.strategy, o.direction, o.maxDepth, o.maxFunctions].some(value => value !== undefined);
|
|
44
|
+
if (o.kind !== 'discover') {
|
|
45
|
+
if (given)
|
|
46
|
+
fail('invalid', '--strategy, --direction, --max-depth and --max-functions apply only to --kind discover.');
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
return discoverScope(o);
|
|
50
|
+
}
|
|
34
51
|
const pageLimit = { flags: '--limit <n>', description: 'Maximum rows (1..1000)', defaultValue: 100 };
|
|
35
52
|
async function capture(workspace, path, max) {
|
|
36
53
|
const info = await lstat(path);
|
|
37
54
|
if (!info.isFile() || info.isSymbolicLink() || info.size < 1 || info.size > max)
|
|
38
55
|
fail('limit', `An ordinary nonempty file of at most ${max} bytes is required.`);
|
|
39
|
-
const artifact = await workspace.artifacts.capture(path, 'input');
|
|
56
|
+
const artifact = await workspace.artifacts.capture(path, 'input', max);
|
|
40
57
|
if (artifact.size > max)
|
|
41
58
|
fail('limit', 'Captured input exceeds this command limit.');
|
|
42
59
|
return { ...artifact, name: basename(path) };
|
|
43
60
|
}
|
|
44
|
-
async function json(workspace, path) {
|
|
45
|
-
const artifact = await capture(workspace, path,
|
|
61
|
+
async function json(workspace, path, max = 8 * 1024 * 1024) {
|
|
62
|
+
const artifact = await capture(workspace, path, max);
|
|
46
63
|
const saved = workspace.artifacts.path({ ...artifact, kind: 'input' });
|
|
47
64
|
let value;
|
|
48
65
|
try {
|
|
@@ -60,6 +77,15 @@ async function json(workspace, path) {
|
|
|
60
77
|
async function materialize(w, handoff, directory) {
|
|
61
78
|
await mkdir(directory, { recursive: false });
|
|
62
79
|
const task = handoff.task, files = [], rows = [];
|
|
80
|
+
if (task.kind === 'discover') {
|
|
81
|
+
// A report skeleton: roots already at depth 0 with their xrefs still to be observed.
|
|
82
|
+
const manifest = resolve(directory, 'discovery-report.json');
|
|
83
|
+
await writeFile(manifest, JSON.stringify({ schema: 1, kind: 'discovery-report', task: task.id, binarySha256: handoff.project.binarySha256,
|
|
84
|
+
discover: task.discover, model: { source: 'ghidra', revision: null },
|
|
85
|
+
visited: handoff.functions.map(fn => ({ function: fn.id, name: fn.name, depth: 0, xrefs: { source: null, complete: null } })),
|
|
86
|
+
edges: [], frontier: [], summary: null, recommended: [] }, null, 1) + '\n', { flag: 'wx' });
|
|
87
|
+
return { directory, manifest, files: 0, next: 'Fill model, visited, edges, frontier and summary within discover, then: work submit --lease LEASE --file ' + manifest };
|
|
88
|
+
}
|
|
63
89
|
for (const fn of handoff.functions) {
|
|
64
90
|
const label = fn.rva.toString(16).padStart(8, '0'), folder = resolve(directory, label);
|
|
65
91
|
await mkdir(folder);
|
|
@@ -139,7 +165,7 @@ export function workCommands(access) {
|
|
|
139
165
|
const input = await json(w, resolve(c.cwd, string(o.file)));
|
|
140
166
|
return { input: { project: o.project, artifact: input.artifact, epoch: o.epoch }, project: identifier(o.project), apply: () => s.importInventory(identifier(o.project), input.value, input.artifact, o.epoch === undefined ? undefined : identifier(o.epoch)) };
|
|
141
167
|
}),
|
|
142
|
-
changing('import-graph', 'Add dependencies; new evidence conservatively invalidates
|
|
168
|
+
changing('import-graph', 'Add dependencies; new evidence conservatively invalidates affected scopes', [project, file, epoch], async (s, w, o, c) => {
|
|
143
169
|
const input = await json(w, resolve(c.cwd, string(o.file)));
|
|
144
170
|
return { input: { project: o.project, artifact: input.artifact, epoch: o.epoch }, project: identifier(o.project), apply: () => s.importGraph(identifier(o.project), input.value, input.artifact, o.epoch === undefined ? undefined : identifier(o.epoch)) };
|
|
145
171
|
}),
|
|
@@ -202,17 +228,23 @@ export function workCommands(access) {
|
|
|
202
228
|
{ flags: '--reason <text>', description: 'Retained evidence/reason for reopening approval', required: true }], async (s, w, o, c) => ({ input: o, project: identifier(o.project),
|
|
203
229
|
apply: () => s.reopenReview(identifier(o.project), string(o.function, 256), sha(o.sourceSha256), integer(o.expectVersion, 1, Number.MAX_SAFE_INTEGER), string(o.reason, 2000), o.epoch === undefined ? undefined : identifier(o.epoch)) })),
|
|
204
230
|
changing('plan', 'Reserve a small nonoverlapping reconstruction or independent-review slice', [project, revision, epoch,
|
|
205
|
-
{ flags: '--count <n>', description: 'Maximum functions, 1..50', defaultValue: 10 },
|
|
206
|
-
{ flags: '--functions <ids>', description: 'Optional comma-separated exact function IDs' },
|
|
207
|
-
{ flags: '--after-rva <hex>', description: 'Continue beyond a bounded frontier' }], async (s, w, o, c) =>
|
|
208
|
-
|
|
231
|
+
{ flags: '--count <n>', description: 'Maximum functions, 1..50', defaultValue: 10 }, kindOption,
|
|
232
|
+
{ flags: '--functions <ids>', description: 'Optional comma-separated exact function IDs; for discover, the roots' },
|
|
233
|
+
{ flags: '--after-rva <hex>', description: 'Continue beyond a bounded frontier' }, ...traversal], async (s, w, o, c) => {
|
|
234
|
+
const scope = traversalOf(o);
|
|
235
|
+
return { input: o, project: identifier(o.project),
|
|
236
|
+
apply: () => s.plan(identifier(o.project), integer(o.expectRevision, 1, Number.MAX_SAFE_INTEGER), integer(o.count, 1, 50), string(o.kind), o.functions === undefined ? undefined : string(o.functions, 16000).split(','), o.afterRva === undefined ? -1 : rva(o.afterRva), o.epoch === undefined ? undefined : identifier(o.epoch), undefined, scope) };
|
|
237
|
+
}),
|
|
209
238
|
changing('claim', 'Claim queued or expired work and obtain a fresh fence', [task, worker, ttl], async (s, w, o, c) => ({ input: o, project: s.handoff(identifier(o.task)).project.id,
|
|
210
239
|
apply: () => s.claim(identifier(o.task), identifier(o.worker), integer(o.ttl, 30, 3600)) })),
|
|
211
240
|
changing('next', 'Plan and claim the next slice atomically; returns a lease token', [project, epoch,
|
|
212
241
|
{ flags: '--worker <id>', description: 'Cooperative worker label, not authenticated identity', required: true }, ttl,
|
|
213
|
-
{ flags: '--count <n>', description: 'Maximum functions, 1..50', defaultValue: 10 },
|
|
214
|
-
{ flags: '--functions <ids>', description: 'Optional exact function IDs, e.g. the retry list of work.taskCancelled' }], async (s, w, o, c) =>
|
|
215
|
-
|
|
242
|
+
{ flags: '--count <n>', description: 'Maximum functions, 1..50', defaultValue: 10 }, kindOption,
|
|
243
|
+
{ flags: '--functions <ids>', description: 'Optional exact function IDs, e.g. the retry list of work.taskCancelled; for discover, the roots' }, ...traversal], async (s, w, o, c) => {
|
|
244
|
+
const scope = traversalOf(o);
|
|
245
|
+
return { input: o, project: identifier(o.project),
|
|
246
|
+
apply: () => s.next(identifier(o.project), identifier(o.worker), integer(o.count, 1, 50), string(o.kind), integer(o.ttl, 30, 3600), o.epoch === undefined ? undefined : identifier(o.epoch), o.functions === undefined ? undefined : string(o.functions, 16000).split(','), scope) };
|
|
247
|
+
}),
|
|
216
248
|
changing('heartbeat', 'Extend a still-current lease', [...held, ttl], async (s, w, o, c) => {
|
|
217
249
|
const l = leaseOf(o);
|
|
218
250
|
return { input: o, project: s.handoff(l.task).project.id,
|
|
@@ -232,8 +264,13 @@ export function workCommands(access) {
|
|
|
232
264
|
return { ...result, materialized: await materialize(w, result, resolve(c.cwd, string(o.materialize, 4096))) };
|
|
233
265
|
}), { permission: Permission.ReadOnly, options: [{ ...task, required: false }, leaseOption,
|
|
234
266
|
{ flags: '--materialize <dir>', description: 'New directory: retained source/contract per function plus a ready submission or review manifest' }] }),
|
|
235
|
-
changing('submit', 'Retain exact reconstruction source and passport for the whole leased slice', [...held, file], async (s, w, o, c) => {
|
|
236
|
-
const l = leaseOf(o), path = resolve(c.cwd, string(o.file)),
|
|
267
|
+
changing('submit', 'Retain exact reconstruction source and passport for the whole leased slice, or the discovery report of a discover task', [...held, file], async (s, w, o, c) => {
|
|
268
|
+
const l = leaseOf(o), path = resolve(c.cwd, string(o.file)), discovery = s.handoff(l.task).task.kind === 'discover';
|
|
269
|
+
const manifest = await json(w, path, discovery ? discoverLimits.reportBytes : undefined), body = object(manifest.value);
|
|
270
|
+
if (discovery) {
|
|
271
|
+
return { input: { task: o.task, worker: o.worker, fence: o.fence, epoch: o.epoch, lease: o.lease, report: manifest.artifact }, project: s.handoff(l.task).project.id,
|
|
272
|
+
apply: () => s.submitDiscovery(l.task, l.worker, l.fence, manifest.value, manifest.artifact, l.epoch) };
|
|
273
|
+
}
|
|
237
274
|
const entries = [];
|
|
238
275
|
for (const [index, value] of array(body.functions, 50).entries()) {
|
|
239
276
|
const row = object(value), sourcePath = resolve(dirname(path), string(row.source)), contractPath = resolve(dirname(path), string(row.contract));
|
package/dist/src/work/model.d.ts
CHANGED
|
@@ -69,7 +69,7 @@ export interface Project {
|
|
|
69
69
|
export interface Task {
|
|
70
70
|
id: string;
|
|
71
71
|
project: string;
|
|
72
|
-
kind:
|
|
72
|
+
kind: TaskKind;
|
|
73
73
|
status: 'queued' | 'leased' | 'submitted' | 'cancelled';
|
|
74
74
|
functions: string[];
|
|
75
75
|
versions: Record<string, number>;
|
|
@@ -80,7 +80,49 @@ export interface Task {
|
|
|
80
80
|
createdAt: number;
|
|
81
81
|
result?: unknown;
|
|
82
82
|
epoch?: string;
|
|
83
|
+
/** Traversal parameters of a discover task; its functions are the roots. */
|
|
84
|
+
discover?: DiscoverScope;
|
|
83
85
|
}
|
|
86
|
+
export type TaskKind = 'reconstruct' | 'review' | 'discover';
|
|
87
|
+
export declare const taskKinds: readonly TaskKind[];
|
|
88
|
+
export interface DiscoverScope {
|
|
89
|
+
strategy: 'breadth' | 'depth';
|
|
90
|
+
direction: 'callees' | 'callers' | 'both';
|
|
91
|
+
maxDepth: number;
|
|
92
|
+
maxFunctions: number;
|
|
93
|
+
}
|
|
94
|
+
export declare const discoverLimits: {
|
|
95
|
+
maxDepth: number;
|
|
96
|
+
maxFunctions: number;
|
|
97
|
+
edges: number;
|
|
98
|
+
frontier: number;
|
|
99
|
+
recommended: number;
|
|
100
|
+
reportBytes: number;
|
|
101
|
+
};
|
|
102
|
+
/** Traversal parameters; defaults are breadth-first callees, depth 2, at most 50 functions. Roots are at depth 0. */
|
|
103
|
+
export declare function discoverScope(value: Record<string, unknown>): DiscoverScope;
|
|
104
|
+
/**
|
|
105
|
+
* Validates a discovery report against its task. The traversal itself happened outside Work (Ghidra xrefs or a
|
|
106
|
+
* pinned graph inventory): this checks shape, identity and bounds, not that the graph is complete. Every visited
|
|
107
|
+
* function appears once, roots and only roots sit at depth 0, and each function states where its xrefs came from
|
|
108
|
+
* and whether that observation was complete, so an empty xref list is never read as proof of no calls.
|
|
109
|
+
*/
|
|
110
|
+
export declare function discoveryReport(value: unknown, expected: {
|
|
111
|
+
task: string;
|
|
112
|
+
binarySha256: string;
|
|
113
|
+
roots: string[];
|
|
114
|
+
scope: DiscoverScope;
|
|
115
|
+
}): {
|
|
116
|
+
model: {
|
|
117
|
+
source: string;
|
|
118
|
+
revision: string;
|
|
119
|
+
};
|
|
120
|
+
visited: number;
|
|
121
|
+
edges: number;
|
|
122
|
+
frontier: number;
|
|
123
|
+
maxDepthReached: number;
|
|
124
|
+
recommended: string[];
|
|
125
|
+
};
|
|
84
126
|
export interface Snapshot {
|
|
85
127
|
project: Project;
|
|
86
128
|
counts: Record<Stage, number>;
|
package/dist/src/work/model.js
CHANGED
|
@@ -54,6 +54,134 @@ export function rva(value) {
|
|
|
54
54
|
fail('invalid', 'String RVAs require 0x-prefixed hexadecimal.');
|
|
55
55
|
return integer(value, 0, 0xffffffff);
|
|
56
56
|
}
|
|
57
|
+
export const taskKinds = ['reconstruct', 'review', 'discover'];
|
|
58
|
+
export const discoverLimits = { maxDepth: 16, maxFunctions: 500, edges: 10000, frontier: 5000, recommended: 50, reportBytes: 2 * 1024 * 1024 };
|
|
59
|
+
/** Traversal parameters; defaults are breadth-first callees, depth 2, at most 50 functions. Roots are at depth 0. */
|
|
60
|
+
export function discoverScope(value) {
|
|
61
|
+
const strategy = value.strategy ?? 'breadth', direction = value.direction ?? 'callees';
|
|
62
|
+
if (strategy !== 'breadth' && strategy !== 'depth')
|
|
63
|
+
fail('invalid', 'Discovery strategy is breadth or depth.');
|
|
64
|
+
if (direction !== 'callees' && direction !== 'callers' && direction !== 'both')
|
|
65
|
+
fail('invalid', 'Discovery direction is callees, callers or both.');
|
|
66
|
+
return { strategy, direction, maxDepth: integer(value.maxDepth ?? 2, 0, discoverLimits.maxDepth), maxFunctions: integer(value.maxFunctions ?? 50, 1, discoverLimits.maxFunctions) };
|
|
67
|
+
}
|
|
68
|
+
const functionPattern = /^fn:([a-f0-9]{64}):([0-9a-f]{8})$/;
|
|
69
|
+
/** A full module hash plus RVA, in the form work import gives it; the module must be the project's. */
|
|
70
|
+
function discoveredFunction(value, binarySha, field) {
|
|
71
|
+
const id = string(value, 256), match = functionPattern.exec(id);
|
|
72
|
+
if (!match)
|
|
73
|
+
fail('invalid', `${field} must be fn:<full module sha256>:<8-digit rva>.`, { field });
|
|
74
|
+
if (match[1] !== binarySha)
|
|
75
|
+
fail('binding', `${field} names another module; record calls into other modules as external frontier.`, { field });
|
|
76
|
+
return id;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Validates a discovery report against its task. The traversal itself happened outside Work (Ghidra xrefs or a
|
|
80
|
+
* pinned graph inventory): this checks shape, identity and bounds, not that the graph is complete. Every visited
|
|
81
|
+
* function appears once, roots and only roots sit at depth 0, and each function states where its xrefs came from
|
|
82
|
+
* and whether that observation was complete, so an empty xref list is never read as proof of no calls.
|
|
83
|
+
*/
|
|
84
|
+
export function discoveryReport(value, expected) {
|
|
85
|
+
const report = object(value);
|
|
86
|
+
if (report.schema !== 1 || report.kind !== 'discovery-report')
|
|
87
|
+
fail('invalid', 'Discovery report needs schema 1 and kind discovery-report.');
|
|
88
|
+
if (report.task !== expected.task)
|
|
89
|
+
fail('binding', 'Discovery report names another task.');
|
|
90
|
+
if (sha(report.binarySha256) !== expected.binarySha256)
|
|
91
|
+
fail('binding', 'Discovery report names another module.');
|
|
92
|
+
const model = object(report.model);
|
|
93
|
+
string(model.source, 128);
|
|
94
|
+
string(model.revision, 128);
|
|
95
|
+
const visited = array(report.visited, expected.scope.maxFunctions).map((row, i) => {
|
|
96
|
+
const entry = object(row), field = `visited[${i}]`, id = discoveredFunction(entry.function, expected.binarySha256, field + '.function');
|
|
97
|
+
const depth = integer(entry.depth, 0, expected.scope.maxDepth), xrefs = object(entry.xrefs);
|
|
98
|
+
string(xrefs.source, 256);
|
|
99
|
+
if (typeof xrefs.complete !== 'boolean')
|
|
100
|
+
fail('invalid', `${field}.xrefs.complete must be a JSON boolean.`, { field: field + '.xrefs.complete' });
|
|
101
|
+
if (entry.name !== undefined)
|
|
102
|
+
string(entry.name, 512);
|
|
103
|
+
return { id, depth };
|
|
104
|
+
});
|
|
105
|
+
const seen = new Set(visited.map(v => v.id));
|
|
106
|
+
if (seen.size !== visited.length)
|
|
107
|
+
fail('invalid', 'Each function is visited once; deduplicate by module hash and RVA.');
|
|
108
|
+
for (const root of expected.roots)
|
|
109
|
+
if (visited.find(v => v.id === root)?.depth !== 0)
|
|
110
|
+
fail('scope', 'Every root is visited at depth 0.', { root });
|
|
111
|
+
if (visited.some(v => v.depth === 0 && !expected.roots.includes(v.id)))
|
|
112
|
+
fail('scope', 'Only the assigned roots sit at depth 0.');
|
|
113
|
+
const edgeKeys = new Set();
|
|
114
|
+
const edges = array(report.edges, discoverLimits.edges).map((row, i) => {
|
|
115
|
+
const edge = object(row), field = `edges[${i}]`, source = discoveredFunction(edge.source, expected.binarySha256, field + '.source');
|
|
116
|
+
const target = discoveredFunction(edge.target, expected.binarySha256, field + '.target');
|
|
117
|
+
if (edge.kind !== 'direct' && edge.kind !== 'indirect')
|
|
118
|
+
fail('invalid', `${field}.kind is direct or indirect.`);
|
|
119
|
+
string(edge.evidence, 4000);
|
|
120
|
+
if (!seen.has(source) && !seen.has(target))
|
|
121
|
+
fail('scope', `${field} touches no visited function.`);
|
|
122
|
+
const key = source + '>' + target + '>' + edge.kind;
|
|
123
|
+
if (edgeKeys.has(key))
|
|
124
|
+
fail('invalid', `${field} repeats an edge.`);
|
|
125
|
+
edgeKeys.add(key);
|
|
126
|
+
return edge;
|
|
127
|
+
});
|
|
128
|
+
const reasons = ['depth-limit', 'function-limit', 'unresolved-indirect', 'external'];
|
|
129
|
+
const frontier = array(report.frontier, discoverLimits.frontier).map((row, i) => {
|
|
130
|
+
const entry = object(row), field = `frontier[${i}]`;
|
|
131
|
+
if (typeof entry.reason !== 'string' || !reasons.includes(entry.reason))
|
|
132
|
+
fail('invalid', `${field}.reason is one of ${reasons.join(', ')}.`);
|
|
133
|
+
const from = discoveredFunction(entry.from, expected.binarySha256, field + '.from');
|
|
134
|
+
if (!seen.has(from))
|
|
135
|
+
fail('scope', `${field}.from must be a visited function.`);
|
|
136
|
+
if (entry.reason === 'depth-limit' || entry.reason === 'function-limit')
|
|
137
|
+
discoveredFunction(entry.function, expected.binarySha256, field + '.function');
|
|
138
|
+
else if (entry.reason === 'external')
|
|
139
|
+
string(entry.function, 512);
|
|
140
|
+
else if (entry.function !== undefined)
|
|
141
|
+
string(entry.function, 512);
|
|
142
|
+
string(entry.evidence, 4000);
|
|
143
|
+
return entry;
|
|
144
|
+
});
|
|
145
|
+
// Every non-root visit is reached by a reported edge from the level above, in the assigned direction. Breadth-first
|
|
146
|
+
// depths are also the shortest such distance from the roots; a depth-first walk may reach a function by a longer path.
|
|
147
|
+
const depth = new Map(visited.map(v => [v.id, v.depth])), next = new Map();
|
|
148
|
+
const step = (from, to) => { if (!next.has(from))
|
|
149
|
+
next.set(from, []); next.get(from).push(to); };
|
|
150
|
+
for (const edge of edges) {
|
|
151
|
+
const source = String(edge.source), target = String(edge.target);
|
|
152
|
+
if (expected.scope.direction !== 'callers')
|
|
153
|
+
step(source, target);
|
|
154
|
+
if (expected.scope.direction !== 'callees')
|
|
155
|
+
step(target, source);
|
|
156
|
+
}
|
|
157
|
+
for (const v of visited)
|
|
158
|
+
if (v.depth > 0 && !visited.some(u => u.depth === v.depth - 1 && next.get(u.id)?.includes(v.id)))
|
|
159
|
+
fail('scope', `Visited ${v.id} at depth ${v.depth} is not reached by an edge from depth ${v.depth - 1} in direction ${expected.scope.direction}.`, { function: v.id });
|
|
160
|
+
if (expected.scope.strategy === 'breadth') {
|
|
161
|
+
const distance = new Map(expected.roots.map(root => [root, 0])), queue = [...expected.roots];
|
|
162
|
+
// Over every reported edge, also through functions the report did not visit: their edges still shorten the path.
|
|
163
|
+
for (let i = 0; i < queue.length; i++)
|
|
164
|
+
for (const to of next.get(queue[i]) ?? [])
|
|
165
|
+
if (!distance.has(to)) {
|
|
166
|
+
distance.set(to, distance.get(queue[i]) + 1);
|
|
167
|
+
queue.push(to);
|
|
168
|
+
}
|
|
169
|
+
for (const v of visited)
|
|
170
|
+
if (distance.get(v.id) !== v.depth)
|
|
171
|
+
fail('scope', `Breadth-first depth of ${v.id} is ${distance.get(v.id)} by the reported edges, not ${v.depth}.`, { function: v.id });
|
|
172
|
+
}
|
|
173
|
+
for (const [i, entry] of frontier.entries()) {
|
|
174
|
+
const field = `frontier[${i}]`;
|
|
175
|
+
if (entry.reason === 'depth-limit' && depth.get(String(entry.from)) !== expected.scope.maxDepth)
|
|
176
|
+
fail('scope', `${field}: a depth limit is reached only from depth ${expected.scope.maxDepth}.`);
|
|
177
|
+
if (entry.reason === 'function-limit' && visited.length !== expected.scope.maxFunctions)
|
|
178
|
+
fail('scope', `${field}: a function limit is reached only with ${expected.scope.maxFunctions} visited functions.`);
|
|
179
|
+
}
|
|
180
|
+
string(report.summary, 8000);
|
|
181
|
+
const recommended = array(report.recommended ?? [], discoverLimits.recommended).map((x, i) => discoveredFunction(x, expected.binarySha256, `recommended[${i}]`));
|
|
182
|
+
return { model: { source: String(model.source), revision: String(model.revision) }, visited: visited.length, edges: edges.length, frontier: frontier.length,
|
|
183
|
+
maxDepthReached: Math.max(...visited.map(v => v.depth)), recommended };
|
|
184
|
+
}
|
|
57
185
|
export function functionIdentity(binarySha, at) {
|
|
58
186
|
return `fn:${binarySha}:${at.toString(16).padStart(8, '0')}`;
|
|
59
187
|
}
|
package/dist/src/work/store.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DatabaseSync } from 'node:sqlite';
|
|
2
2
|
import { type Workspace } from '../workspace.js';
|
|
3
|
-
import { type Attachment, type Project, type Snapshot, type Task, type WorkFunction } from './model.js';
|
|
3
|
+
import { type DiscoverScope, type TaskKind, type Attachment, type Project, type Snapshot, type Task, type WorkFunction } from './model.js';
|
|
4
4
|
export declare const workTableColumns: {
|
|
5
5
|
readonly projects: readonly ["id", "data"];
|
|
6
6
|
readonly functions: readonly ["project", "id", "rva", "stage", "data"];
|
|
@@ -41,6 +41,7 @@ export declare class WorkStore {
|
|
|
41
41
|
private cancelled;
|
|
42
42
|
private planning;
|
|
43
43
|
private lease;
|
|
44
|
+
/** `reservations`: the cause concerns reserved packages or resources only, which a discovery never holds. */
|
|
44
45
|
private invalidateTasks;
|
|
45
46
|
/**
|
|
46
47
|
* Only a writer edge reserves its target exclusively. Calls/reads are read dependencies: they are
|
|
@@ -114,17 +115,22 @@ export declare class WorkStore {
|
|
|
114
115
|
private static needsRework;
|
|
115
116
|
private static reviewable;
|
|
116
117
|
private static readonly reworkSql;
|
|
117
|
-
plan(projectId: string, expectedRevision: number, count: number, kind:
|
|
118
|
+
plan(projectId: string, expectedRevision: number, count: number, kind: TaskKind, selected?: string[], afterRva?: number, epoch?: string, excludeAuthor?: string, discover?: DiscoverScope): {
|
|
118
119
|
task: Task;
|
|
119
120
|
revision: number;
|
|
120
121
|
};
|
|
122
|
+
/**
|
|
123
|
+
* A discovery task reads the call graph around explicit roots and changes no function, so it reserves nothing:
|
|
124
|
+
* reconstruction and review of the same functions continue meanwhile.
|
|
125
|
+
*/
|
|
126
|
+
private planDiscovery;
|
|
121
127
|
claim(taskId: string, worker: string, ttl: number): {
|
|
122
128
|
task: Task;
|
|
123
129
|
revision: number;
|
|
124
130
|
lease: string;
|
|
125
131
|
};
|
|
126
132
|
/** Plan and claim one slice atomically at the current state; no observed revision is needed. */
|
|
127
|
-
next(projectId: string, worker: string, count: number, kind:
|
|
133
|
+
next(projectId: string, worker: string, count: number, kind: TaskKind, ttl: number, epoch?: string, selected?: string[], discover?: DiscoverScope): {
|
|
128
134
|
task: Task;
|
|
129
135
|
revision: number;
|
|
130
136
|
lease: string;
|
|
@@ -151,6 +157,15 @@ export declare class WorkStore {
|
|
|
151
157
|
revision: number;
|
|
152
158
|
accepted1to1: boolean;
|
|
153
159
|
};
|
|
160
|
+
/**
|
|
161
|
+
* Retains the discovery report of a leased discover task and completes it. Function stages and packages are
|
|
162
|
+
* untouched; newly found functions are registered only through an explicit work import.
|
|
163
|
+
*/
|
|
164
|
+
submitDiscovery(taskId: string, worker: string, fence: number, report: unknown, artifact: Attachment, epoch?: string): {
|
|
165
|
+
task: Task;
|
|
166
|
+
revision: number;
|
|
167
|
+
accepted1to1: boolean;
|
|
168
|
+
};
|
|
154
169
|
review(taskId: string, worker: string, fence: number, decisions: {
|
|
155
170
|
id: string;
|
|
156
171
|
sourceSha256: string;
|
|
@@ -223,6 +238,15 @@ export declare class WorkStore {
|
|
|
223
238
|
firstApprovalAt: number | null;
|
|
224
239
|
};
|
|
225
240
|
};
|
|
241
|
+
discovery: {
|
|
242
|
+
task: string;
|
|
243
|
+
status: "queued" | "cancelled" | "leased" | "submitted";
|
|
244
|
+
roots: number;
|
|
245
|
+
scope: DiscoverScope | undefined;
|
|
246
|
+
discoverMs: number | null;
|
|
247
|
+
visited: {} | null;
|
|
248
|
+
frontier: {} | null;
|
|
249
|
+
}[];
|
|
226
250
|
project: {
|
|
227
251
|
id: string;
|
|
228
252
|
target: string;
|
|
@@ -286,10 +310,17 @@ export declare class WorkStore {
|
|
|
286
310
|
complete: boolean;
|
|
287
311
|
};
|
|
288
312
|
handoff(taskId: string): {
|
|
313
|
+
project: Project;
|
|
314
|
+
task: Task;
|
|
315
|
+
functions: WorkFunction[];
|
|
316
|
+
discover: DiscoverScope | undefined;
|
|
317
|
+
instructions: string[];
|
|
318
|
+
} | {
|
|
289
319
|
project: Project;
|
|
290
320
|
task: Task;
|
|
291
321
|
functions: WorkFunction[];
|
|
292
322
|
instructions: string[];
|
|
323
|
+
discover?: undefined;
|
|
293
324
|
};
|
|
294
325
|
snapshot(projectId: string, limit?: number): Snapshot;
|
|
295
326
|
/** Full work metadata only: native contexts/configuration are deliberately outside this snapshot. */
|