@eyeauras/insight-cli 0.7.0 → 0.8.1
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/SKILL.md +1 -1
- package/dist/src/activity-audit.d.ts +7 -0
- package/dist/src/activity-audit.js +14 -4
- package/dist/src/analysis-storage.d.ts +5 -1
- package/dist/src/analysis-storage.js +9 -2
- package/dist/src/audit-retention.d.ts +8 -2
- package/dist/src/audit-retention.js +68 -7
- package/dist/src/cli.js +21 -5
- package/dist/src/context-diagnostics.d.ts +1 -1
- package/dist/src/context-diagnostics.js +10 -2
- package/dist/src/contexts.d.ts +118 -10
- package/dist/src/contexts.js +851 -199
- package/dist/src/debugger.js +2 -1
- package/dist/src/diagnostic-error.js +1 -1
- package/dist/src/inline-script.js +3 -4
- package/dist/src/lifecycle.d.ts +11 -0
- package/dist/src/lifecycle.js +34 -6
- package/dist/src/native-inputs.d.ts +6 -0
- package/dist/src/native-inputs.js +30 -6
- package/dist/src/native-queries.js +1 -6
- package/dist/src/native-service.d.ts +40 -0
- package/dist/src/native-service.js +406 -0
- package/dist/src/research.d.ts +29 -1
- package/dist/src/research.js +106 -27
- package/dist/src/server.d.ts +38 -1
- package/dist/src/server.js +160 -12
- package/dist/src/storage-gc.js +1 -1
- package/dist/src/sync-policy.js +2 -1
- package/dist/src/timed-backend.js +8 -0
- package/dist/src/timing-report.d.ts +32 -0
- package/dist/src/timing-report.js +74 -0
- package/dist/src/tool-runtime/identity.js +86 -1
- package/dist/src/tool-runtime/supervisor.js +6 -5
- package/dist/src/transport.d.ts +35 -0
- package/dist/src/transport.js +77 -7
- package/dist/src/unresolved-guidance.d.ts +46 -0
- package/dist/src/unresolved-guidance.js +55 -0
- package/dist/src/windbg.d.ts +1 -1
- package/dist/src/work/backup.d.ts +66 -0
- package/dist/src/work/backup.js +434 -0
- package/dist/src/work/commands.d.ts +5 -0
- package/dist/src/work/commands.js +277 -0
- package/dist/src/work/dashboard.d.ts +12 -0
- package/dist/src/work/dashboard.js +103 -0
- package/dist/src/work/model.d.ts +131 -0
- package/dist/src/work/model.js +124 -0
- package/dist/src/work/store.d.ts +368 -0
- package/dist/src/work/store.js +1050 -0
- package/dist/src/work/timing.d.ts +26 -0
- package/dist/src/work/timing.js +80 -0
- package/dist/src/worker-lease.d.ts +17 -0
- package/dist/src/worker-lease.js +50 -0
- package/dist/src/workspace.d.ts +5 -9
- package/dist/src/workspace.js +20 -41
- package/package.json +1 -1
- package/references/native/InsightHeadlessMain.java +9 -2
- package/references/native/InsightNativeCheckout.java +113 -43
- package/references/native/InsightNativeFingerprint.java +28 -1
- package/references/native/InsightNativeRead.java +32 -9
- package/references/native/InsightNativeService.java +43 -0
- package/references/native/InsightNativeView.java +17 -6
- package/references/native/InsightOwnedScripts.java +170 -0
- package/references/native/InsightWorkerLease.java +132 -0
- package/references/recovery.md +68 -3
- package/references/research.md +38 -4
- package/references/setup.md +5 -1
- package/references/work-tracking.md +203 -0
- package/runtime/toolbox.json +1 -0
- package/skill-bundle/insight-artifacts/SKILL.md +1 -1
- package/skill-bundle/insight-artifacts/references/recovery.md +68 -3
- package/skill-bundle/insight-binary/SKILL.md +1 -1
- package/skill-bundle/insight-capture/SKILL.md +1 -1
- package/skill-bundle/insight-cli/SKILL.md +1 -1
- package/skill-bundle/insight-cli/references/recovery.md +68 -3
- package/skill-bundle/insight-cli/references/setup.md +5 -1
- package/skill-bundle/insight-die/SKILL.md +1 -1
- package/skill-bundle/insight-dnspy/SKILL.md +1 -1
- package/skill-bundle/insight-dotnet-dump/SKILL.md +1 -1
- package/skill-bundle/insight-dotnet-stack/SKILL.md +1 -1
- package/skill-bundle/insight-dotnet-trace/SKILL.md +1 -1
- package/skill-bundle/insight-frida/SKILL.md +1 -1
- package/skill-bundle/insight-ghidra/SKILL.md +1 -1
- package/skill-bundle/insight-ghidra/references/recovery.md +68 -3
- package/skill-bundle/insight-ghidra/references/research.md +38 -4
- package/skill-bundle/insight-ghidra/references/setup.md +5 -1
- package/skill-bundle/insight-ilspy/SKILL.md +1 -1
- package/skill-bundle/insight-interop/SKILL.md +1 -1
- package/skill-bundle/insight-lldb/SKILL.md +1 -1
- package/skill-bundle/insight-llvm/SKILL.md +1 -1
- package/skill-bundle/insight-managed-heap/SKILL.md +1 -1
- package/skill-bundle/insight-managed-metadata/SKILL.md +1 -1
- package/skill-bundle/insight-mitmproxy/SKILL.md +1 -1
- package/skill-bundle/insight-overview/SKILL.md +1 -1
- package/skill-bundle/insight-procmon/SKILL.md +1 -1
- package/skill-bundle/insight-re/SKILL.md +5 -1
- package/skill-bundle/insight-re/references/recovery.md +68 -3
- package/skill-bundle/insight-re/references/work-tracking.md +203 -0
- package/skill-bundle/insight-sevenzip/SKILL.md +1 -1
- package/skill-bundle/insight-strace/SKILL.md +1 -1
- package/skill-bundle/insight-tshark/SKILL.md +1 -1
- package/skill-bundle/insight-windbg/SKILL.md +1 -1
- package/skill-bundle/manifest.json +1 -1
- package/skills/insight-artifacts/SKILL.md +1 -1
- package/skills/insight-artifacts/references/recovery.md +68 -3
- package/skills/insight-binary/SKILL.md +1 -1
- package/skills/insight-capture/SKILL.md +1 -1
- package/skills/insight-die/SKILL.md +1 -1
- package/skills/insight-dnspy/SKILL.md +1 -1
- package/skills/insight-dotnet-dump/SKILL.md +1 -1
- package/skills/insight-dotnet-stack/SKILL.md +1 -1
- package/skills/insight-dotnet-trace/SKILL.md +1 -1
- package/skills/insight-frida/SKILL.md +1 -1
- package/skills/insight-ghidra/SKILL.md +1 -1
- package/skills/insight-ghidra/references/recovery.md +68 -3
- package/skills/insight-ghidra/references/research.md +38 -4
- package/skills/insight-ghidra/references/setup.md +5 -1
- package/skills/insight-ilspy/SKILL.md +1 -1
- package/skills/insight-interop/SKILL.md +1 -1
- package/skills/insight-lldb/SKILL.md +1 -1
- package/skills/insight-llvm/SKILL.md +1 -1
- package/skills/insight-managed-heap/SKILL.md +1 -1
- package/skills/insight-managed-metadata/SKILL.md +1 -1
- package/skills/insight-mitmproxy/SKILL.md +1 -1
- package/skills/insight-overview/SKILL.md +1 -1
- package/skills/insight-procmon/SKILL.md +1 -1
- package/skills/insight-re/SKILL.md +5 -1
- package/skills/insight-re/references/recovery.md +68 -3
- package/skills/insight-re/references/work-tracking.md +203 -0
- package/skills/insight-sevenzip/SKILL.md +1 -1
- package/skills/insight-strace/SKILL.md +1 -1
- package/skills/insight-tshark/SKILL.md +1 -1
- package/skills/insight-windbg/SKILL.md +1 -1
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
import { command, Permission } from '@eyeauras/cli-factory';
|
|
2
|
+
import { basename, dirname, resolve } from 'node:path';
|
|
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';
|
|
5
|
+
import { packageVersion } from '../package-version.js';
|
|
6
|
+
import { WorkStore } from './store.js';
|
|
7
|
+
import { saveDashboard } from './dashboard.js';
|
|
8
|
+
import { backupWork, verifyWorkBackup, prepareWorkRestore, loadManifest } from './backup.js';
|
|
9
|
+
const project = { flags: '--project <id>', description: 'Project in this explicit profile', required: true };
|
|
10
|
+
const request = { flags: '--request-id <id>', description: 'Required durable changing-intent ID; reuse only for the same intent', required: true };
|
|
11
|
+
const file = { flags: '--file <path>', description: 'Bounded JSON input captured immutably before use', required: true };
|
|
12
|
+
const task = { flags: '--task <id>', description: 'Assigned work item', required: true };
|
|
13
|
+
const worker = { flags: '--worker <id>', description: 'Cooperative worker label, not authenticated identity', required: true };
|
|
14
|
+
const fence = { flags: '--fence <n>', description: 'Current monotonic lease fence', required: true };
|
|
15
|
+
const ttl = { flags: '--ttl <seconds>', description: 'Lease lifetime, 30..3600 seconds', defaultValue: 600 };
|
|
16
|
+
const revision = { flags: '--expect-revision <n>', description: 'Observed revision; only intervening planning changes conflict', required: true };
|
|
17
|
+
const epoch = { flags: '--epoch <id>', description: 'Optional project incarnation from brief; a mismatch is rejected' };
|
|
18
|
+
const leaseOption = { flags: '--lease <token>', description: 'Lease token from work next/claim; replaces --task, --worker, --fence and --epoch' };
|
|
19
|
+
/** Lease-holding commands accept one token or the explicit task/worker/fence triple. */
|
|
20
|
+
const held = [leaseOption, { ...task, required: false }, { ...worker, required: false }, { ...fence, required: false }, epoch];
|
|
21
|
+
function leaseOf(o) {
|
|
22
|
+
if (o.lease !== undefined) {
|
|
23
|
+
const l = parseLease(o.lease);
|
|
24
|
+
for (const [key, value] of [['task', l.task], ['worker', l.worker], ['fence', l.fence], ['epoch', l.epoch]])
|
|
25
|
+
if (o[key] !== undefined && value !== undefined && String(o[key]) !== String(value))
|
|
26
|
+
fail('invalid', `--lease disagrees with explicit --${key}.`);
|
|
27
|
+
return { ...l, epoch: o.epoch === undefined ? l.epoch : identifier(o.epoch) };
|
|
28
|
+
}
|
|
29
|
+
if (o.task === undefined || o.worker === undefined || o.fence === undefined)
|
|
30
|
+
fail('invalid', 'Pass --lease, or all of --task, --worker and --fence.');
|
|
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
|
+
}
|
|
33
|
+
const functionId = { flags: '--function <id>', description: 'Exact full-hash/RVA function identity', required: true };
|
|
34
|
+
const pageLimit = { flags: '--limit <n>', description: 'Maximum rows (1..1000)', defaultValue: 100 };
|
|
35
|
+
async function capture(workspace, path, max) {
|
|
36
|
+
const info = await lstat(path);
|
|
37
|
+
if (!info.isFile() || info.isSymbolicLink() || info.size < 1 || info.size > max)
|
|
38
|
+
fail('limit', `An ordinary nonempty file of at most ${max} bytes is required.`);
|
|
39
|
+
const artifact = await workspace.artifacts.capture(path, 'input');
|
|
40
|
+
if (artifact.size > max)
|
|
41
|
+
fail('limit', 'Captured input exceeds this command limit.');
|
|
42
|
+
return { ...artifact, name: basename(path) };
|
|
43
|
+
}
|
|
44
|
+
async function json(workspace, path) {
|
|
45
|
+
const artifact = await capture(workspace, path, 8 * 1024 * 1024);
|
|
46
|
+
const saved = workspace.artifacts.path({ ...artifact, kind: 'input' });
|
|
47
|
+
let value;
|
|
48
|
+
try {
|
|
49
|
+
value = JSON.parse(await readFile(saved, 'utf8'));
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
fail('invalid', 'Input must be valid UTF-8 JSON.');
|
|
53
|
+
}
|
|
54
|
+
return { value, artifact };
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Writes a new directory with the retained source/contract of every assigned function and a manifest
|
|
58
|
+
* skeleton whose paths are relative to it. Review manifests leave approved=null; it must be decided.
|
|
59
|
+
*/
|
|
60
|
+
async function materialize(w, handoff, directory) {
|
|
61
|
+
await mkdir(directory, { recursive: false });
|
|
62
|
+
const task = handoff.task, files = [], rows = [];
|
|
63
|
+
for (const fn of handoff.functions) {
|
|
64
|
+
const label = fn.rva.toString(16).padStart(8, '0'), folder = resolve(directory, label);
|
|
65
|
+
await mkdir(folder);
|
|
66
|
+
const copy = async (attachment, name) => {
|
|
67
|
+
if (!attachment)
|
|
68
|
+
return undefined;
|
|
69
|
+
const target = resolve(folder, name);
|
|
70
|
+
await copyFile(await w.artifacts.verify({ id: 'input:' + attachment.sha256, kind: 'input', sha256: attachment.sha256, size: attachment.size }), target);
|
|
71
|
+
files.push(target);
|
|
72
|
+
return label + '/' + name;
|
|
73
|
+
};
|
|
74
|
+
const source = await copy(fn.source, 'source' + (fn.source?.name?.match(/\.[A-Za-z0-9]{1,8}$/)?.[0] ?? '.cpp'));
|
|
75
|
+
const contract = await copy(fn.contract, 'contract.json');
|
|
76
|
+
// Rework needs the reason: the retained review note and the corpus comparison summary, when present.
|
|
77
|
+
const review = fn.review;
|
|
78
|
+
const reviewNote = review?.note?.sha256 ? await copy(review.note, 'previous-review.md') : undefined;
|
|
79
|
+
const comparison = fn.comparison;
|
|
80
|
+
if (review || comparison || fn.reviewRequired) {
|
|
81
|
+
const target = resolve(folder, 'rework-reason.json');
|
|
82
|
+
await writeFile(target, JSON.stringify({ review: review ? { approved: review.approved, worker: review.worker,
|
|
83
|
+
reviewedSourceSha256: review.sourceSha256, note: reviewNote ?? null } : null,
|
|
84
|
+
reviewRequired: fn.reviewRequired ?? null,
|
|
85
|
+
comparison: comparison ? { cases: comparison.cases, mismatches: comparison.mismatches,
|
|
86
|
+
firstMismatchInputs: comparison.firstMismatchInputs ?? null, sourceSha256: comparison.sourceSha256 } : null }, null, 1) + '\n', { flag: 'wx' });
|
|
87
|
+
files.push(target);
|
|
88
|
+
}
|
|
89
|
+
if (task.kind === 'review') {
|
|
90
|
+
if (!fn.source)
|
|
91
|
+
fail('invalid', 'A review assignment names a function without source.');
|
|
92
|
+
rows.push({ id: fn.id, sourceSha256: fn.source.sha256, approved: null, note: label + '/review.md', source, contract });
|
|
93
|
+
}
|
|
94
|
+
else
|
|
95
|
+
rows.push({ id: fn.id, source: label + '/' + label + '.cpp', contract: label + '/' + label + '.contract.json', ...(source ? { previousSource: source, previousContract: contract } : {}) });
|
|
96
|
+
}
|
|
97
|
+
const manifest = resolve(directory, task.kind === 'review' ? 'review-manifest.json' : 'submission.json');
|
|
98
|
+
await writeFile(manifest, JSON.stringify({ functions: rows }, null, 1) + '\n', { flag: 'wx' });
|
|
99
|
+
return { directory, manifest, files: files.length,
|
|
100
|
+
next: task.kind === 'review' ? 'Write each note, set approved true/false, then: work review --lease LEASE --file ' + manifest
|
|
101
|
+
: 'Write each .cpp and .contract.json named in the manifest (rework: read <rva>/rework-reason.json and previous-review.md first), '
|
|
102
|
+
+ 'then: work submit --lease LEASE --file ' + manifest };
|
|
103
|
+
}
|
|
104
|
+
export function workCommands(access) {
|
|
105
|
+
const run = (c, action, readOnly = true) => access(c, async (workspace) => {
|
|
106
|
+
const store = new WorkStore(workspace, Date.now, readOnly);
|
|
107
|
+
try {
|
|
108
|
+
return await action(store, workspace);
|
|
109
|
+
}
|
|
110
|
+
finally {
|
|
111
|
+
store.close();
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
const changing = (name, description, options, action) => command(name, description, async ({ options: o }, c) => run(c, async (s, w) => {
|
|
115
|
+
const prepared = await action(s, w, o, c);
|
|
116
|
+
const result = s.mutate(name, prepared.input, string(o.requestId), prepared.apply);
|
|
117
|
+
// Saved workflow state is authoritative even if the derived view cannot be refreshed.
|
|
118
|
+
let dashboard = { state: "deferred", project: prepared.project };
|
|
119
|
+
if (o.refreshDashboard)
|
|
120
|
+
try {
|
|
121
|
+
dashboard = await saveDashboard(w, s, prepared.project);
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
dashboard = { state: 'stale', message: error instanceof Error ? error.message : 'View unavailable; rerun work dashboard' };
|
|
125
|
+
}
|
|
126
|
+
return { result, dashboard };
|
|
127
|
+
}, false), { permission: Permission.Update, options: [...options, request, { flags: "--refresh-dashboard", description: "Also regenerate the profile HTML view" }] });
|
|
128
|
+
return [command('work', 'Shared strict-reconstruction ledger, fenced assignments and read-only progress views', [
|
|
129
|
+
command('migrate', 'Initialize or migrate this profile ledger', (_, c) => run(c, s => ({ schema: 2, epoch: s.incarnation }), false), { permission: Permission.Update }),
|
|
130
|
+
command('timing', 'Measure reconstruction and independent review from recorded server events', ({ options: o }, c) => run(c, s => s.timing(identifier(o.project), o.tasks === undefined ? undefined : String(o.tasks).split(','))), { permission: Permission.ReadOnly, options: [project, { flags: '--tasks <ids>', description: 'Comma-separated reconstruction IDs; default latest ten' }] }),
|
|
131
|
+
command('context', 'Identify the CLI, profile and selected project', ({ options: o }, c) => run(c, (s, w) => ({
|
|
132
|
+
cliVersion: packageVersion, profile: w.profile, workSchema: 2, project: o.project === undefined ? null : s.context(identifier(o.project)),
|
|
133
|
+
registrationOrder: ['import', 'plan', 'claim'], atomicAssignment: 'next'
|
|
134
|
+
})), { permission: Permission.ReadOnly, options: [{ ...project, required: false }] }),
|
|
135
|
+
command('projects', 'List projects in this profile', (_, c) => run(c, s => ({ projects: s.projects() })), { permission: Permission.ReadOnly }),
|
|
136
|
+
changing('create', 'Bind an RE project to an existing immutable target', [project, { flags: '--target <id>', required: true, description: 'Immutable Workspace target' },
|
|
137
|
+
{ flags: '--name <name>', required: true, description: 'Display name' }], async (s, w, o, c) => ({ input: { project: o.project, target: o.target, name: o.name }, project: identifier(o.project), apply: () => s.create(identifier(o.project), string(o.target), string(o.name)) })),
|
|
138
|
+
changing('import', 'Add bounded function definitions; never promote unwind regions', [project, file, epoch], async (s, w, o, c) => {
|
|
139
|
+
const input = await json(w, resolve(c.cwd, string(o.file)));
|
|
140
|
+
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
|
+
}),
|
|
142
|
+
changing('import-graph', 'Add dependencies; new evidence conservatively invalidates M0 scopes', [project, file, epoch], async (s, w, o, c) => {
|
|
143
|
+
const input = await json(w, resolve(c.cwd, string(o.file)));
|
|
144
|
+
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
|
+
}),
|
|
146
|
+
changing('revise-definition', 'Retain a definition revision and invalidate affected assignments', [project, functionId, file, epoch, { flags: '--expect-version <n>', description: 'Current function/package version', required: true }], async (s, w, o, c) => {
|
|
147
|
+
const input = await json(w, resolve(c.cwd, string(o.file)));
|
|
148
|
+
return { input: { project: o.project, function: o.function, version: o.expectVersion, artifact: input.artifact, epoch: o.epoch }, project: identifier(o.project),
|
|
149
|
+
apply: () => s.reviseDefinition(identifier(o.project), string(o.function, 256), integer(o.expectVersion, 1, Number.MAX_SAFE_INTEGER), input.value, input.artifact, o.epoch === undefined ? undefined : identifier(o.epoch)) };
|
|
150
|
+
}),
|
|
151
|
+
command('history', 'Page retained package and definition versions', ({ options: o }, c) => run(c, s => s.history(identifier(o.project), string(o.function, 256), integer(o.afterVersion, 0, Number.MAX_SAFE_INTEGER), integer(o.limit, 1, 1000))), { permission: Permission.ReadOnly, options: [project, functionId, pageLimit, { flags: '--after-version <n>', description: 'Exclusive retained version', defaultValue: 0 }] }),
|
|
152
|
+
command('backup', 'Copy work metadata and referenced payloads to an exclusive new directory', ({ options: o }, c) => run(c, (s, w) => backupWork(s, w, resolve(c.cwd, string(o.output)))), { permission: Permission.Update, options: [{ flags: '--output <path>', description: 'New directory outside the source workspace', required: true }] }),
|
|
153
|
+
command('verify-backup', 'Verify metadata and retained work artifact availability', async ({ options: o }, c) => {
|
|
154
|
+
const verified = await verifyWorkBackup(resolve(c.cwd, string(o.directory)));
|
|
155
|
+
return { path: verified.root, backupId: verified.manifest.id, manifestSha256: verified.sha256, ...verified.summary, scope: verified.manifest.scope, accepted1to1: 0 };
|
|
156
|
+
}, { permission: Permission.ReadOnly, options: [{ flags: '--directory <path>', description: 'Backup root containing manifest.json', required: true }] }),
|
|
157
|
+
command('restore', 'Restore into empty work storage with a fresh epoch and cancelled historical leases', ({ options: o }, c) => run(c, async (s, w) => {
|
|
158
|
+
s.assertCurrentRequestId(identifier(o.requestId));
|
|
159
|
+
const directory = resolve(c.cwd, string(o.directory)), verified = await loadManifest(directory);
|
|
160
|
+
const intent = { backupId: verified.manifest.id, manifestSha256: verified.sha256, stateSha256: verified.manifest.state.sha256 };
|
|
161
|
+
const reservation = w.reserveAdministration('work.restore', intent, identifier(o.requestId));
|
|
162
|
+
if (reservation.request.state === 'failed')
|
|
163
|
+
s.mutate('restore', intent, identifier(o.requestId), () => { throw Error('retained failure'); });
|
|
164
|
+
if (s.request(identifier(o.requestId)).receipt)
|
|
165
|
+
return { result: s.mutate('restore', intent, identifier(o.requestId), () => { throw Error('receipt must replay'); }), cleanup: { state: 'not-needed' } };
|
|
166
|
+
let prepared;
|
|
167
|
+
try {
|
|
168
|
+
prepared = await prepareWorkRestore(s, w, verified);
|
|
169
|
+
}
|
|
170
|
+
catch (error) {
|
|
171
|
+
w.administrationState(reservation.request.id, 'failed', { metadataCommitted: false, stagedImmutableMaterialsMayRemain: true, message: String(error) });
|
|
172
|
+
throw error;
|
|
173
|
+
}
|
|
174
|
+
let result, cleanup;
|
|
175
|
+
try {
|
|
176
|
+
result = s.mutate('restore', intent, identifier(o.requestId), () => s.restoreState(prepared.stage, prepared.targets, prepared.origin));
|
|
177
|
+
}
|
|
178
|
+
finally {
|
|
179
|
+
try {
|
|
180
|
+
await prepared.cleanup();
|
|
181
|
+
cleanup = { state: 'confirmed' };
|
|
182
|
+
}
|
|
183
|
+
catch (error) {
|
|
184
|
+
cleanup = { state: 'incomplete', message: String(error) };
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return { result, cleanup };
|
|
188
|
+
}, false), { permission: Permission.Update, options: [request, { flags: '--directory <path>', description: 'Verified backup; work storage must be empty', required: true }] }),
|
|
189
|
+
command('brief', 'Current consistent overview with bounded rows and explicit limits', ({ options: o }, c) => run(c, s => s.snapshot(identifier(o.project), integer(o.limit, 1, 1000))), { permission: Permission.ReadOnly, options: [project, pageLimit] }),
|
|
190
|
+
command('request', 'Recover a saved work intent and its local transaction receipt', ({ options: o }, c) => run(c, s => s.request(identifier(o.requestId))), { permission: Permission.ReadOnly, options: [request] }),
|
|
191
|
+
command('events', 'Keyset page of durable project events and originating request references', ({ options: o }, c) => run(c, s => s.events(identifier(o.project), integer(o.after, 0, Number.MAX_SAFE_INTEGER), integer(o.limit, 1, 1000))), { permission: Permission.ReadOnly, options: [project, pageLimit, { flags: '--after <seq>', description: 'Exclusive global event sequence', defaultValue: 0 }] }),
|
|
192
|
+
command('export', 'Stream a consistent project checkpoint to a new JSONL file', ({ options: o }, c) => run(c, s => s.export(identifier(o.project), resolve(c.cwd, string(o.output)))), { permission: Permission.ReadOnly, options: [project, { flags: '--output <path>', description: 'New JSONL checkpoint; immutable artifact payloads stay separate', required: true }] }),
|
|
193
|
+
command('functions', 'Keyset page of functions; retain revision when paging', ({ options: o }, c) => run(c, s => s.functions(identifier(o.project), o.afterRva === undefined ? -1 : rva(o.afterRva), integer(o.limit, 1, 1000))), { permission: Permission.ReadOnly, options: [project, pageLimit, { flags: '--after-rva <hex>', description: 'Exclusive RVA cursor, 0x-prefixed' }] }),
|
|
194
|
+
command('graph', 'Keyset page of dependency nodes or edges', ({ options: o }, c) => run(c, s => {
|
|
195
|
+
if (o.kind !== 'nodes' && o.kind !== 'edges')
|
|
196
|
+
fail('invalid', 'Graph kind is nodes or edges.');
|
|
197
|
+
return s.graph(identifier(o.project), o.after === undefined ? '' : string(o.after, 256), integer(o.limit, 1, 1000), o.kind);
|
|
198
|
+
}), { permission: Permission.ReadOnly, options: [project, pageLimit, { flags: '--kind <kind>', description: 'nodes or edges', defaultValue: 'edges' }, { flags: '--after <id>', description: 'Exclusive ID cursor' }] }),
|
|
199
|
+
changing('reopen-review', 'Withdraw the current approval and require another review; retain its history', [project, functionId, epoch,
|
|
200
|
+
{ flags: '--source-sha256 <sha>', description: 'Exact current reconstruction hash', required: true },
|
|
201
|
+
{ flags: '--expect-version <n>', description: 'Observed package version, including its passport', required: true },
|
|
202
|
+
{ flags: '--reason <text>', description: 'Retained evidence/reason for reopening approval', required: true }], async (s, w, o, c) => ({ input: o, project: identifier(o.project),
|
|
203
|
+
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
|
+
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 }, { flags: '--kind <kind>', description: 'reconstruct or review', defaultValue: 'reconstruct' },
|
|
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) => ({ input: o, project: identifier(o.project),
|
|
208
|
+
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)) })),
|
|
209
|
+
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
|
+
apply: () => s.claim(identifier(o.task), identifier(o.worker), integer(o.ttl, 30, 3600)) })),
|
|
211
|
+
changing('next', 'Plan and claim the next slice atomically; returns a lease token', [project, epoch,
|
|
212
|
+
{ flags: '--worker <id>', description: 'Cooperative worker label, not authenticated identity', required: true }, ttl,
|
|
213
|
+
{ flags: '--count <n>', description: 'Maximum functions, 1..50', defaultValue: 10 }, { flags: '--kind <kind>', description: 'reconstruct or review', defaultValue: 'reconstruct' },
|
|
214
|
+
{ flags: '--functions <ids>', description: 'Optional exact function IDs, e.g. the retry list of work.taskCancelled' }], async (s, w, o, c) => ({ input: o, project: identifier(o.project),
|
|
215
|
+
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(',')) })),
|
|
216
|
+
changing('heartbeat', 'Extend a still-current lease', [...held, ttl], async (s, w, o, c) => {
|
|
217
|
+
const l = leaseOf(o);
|
|
218
|
+
return { input: o, project: s.handoff(l.task).project.id,
|
|
219
|
+
apply: () => s.heartbeat(l.task, l.worker, l.fence, integer(o.ttl, 30, 3600), l.epoch) };
|
|
220
|
+
}),
|
|
221
|
+
changing('release', 'Return a current lease to the queue, keeping its reserved scope', held, async (s, w, o, c) => {
|
|
222
|
+
const l = leaseOf(o);
|
|
223
|
+
return { input: o, project: s.handoff(l.task).project.id,
|
|
224
|
+
apply: () => s.release(l.task, l.worker, l.fence, l.epoch) };
|
|
225
|
+
}),
|
|
226
|
+
changing('cancel', 'Cancel an outstanding task and fence it off before replanning', [task, revision, epoch, { flags: '--reason <text>', description: 'Retained cancellation reason', required: true }], async (s, w, o, c) => ({ input: o, project: s.handoff(identifier(o.task)).project.id,
|
|
227
|
+
apply: () => s.cancel(identifier(o.task), integer(o.expectRevision, 1, Number.MAX_SAFE_INTEGER), string(o.reason, 2000), o.epoch === undefined ? undefined : identifier(o.epoch)) })),
|
|
228
|
+
command('handoff', 'Exact assigned versions, evidence and lease for a subagent; --materialize writes files and a manifest skeleton', ({ options: o }, c) => run(c, async (s, w) => {
|
|
229
|
+
const result = s.handoff(o.lease !== undefined ? parseLease(o.lease).task : identifier(o.task));
|
|
230
|
+
if (o.materialize === undefined)
|
|
231
|
+
return result;
|
|
232
|
+
return { ...result, materialized: await materialize(w, result, resolve(c.cwd, string(o.materialize, 4096))) };
|
|
233
|
+
}), { permission: Permission.ReadOnly, options: [{ ...task, required: false }, leaseOption,
|
|
234
|
+
{ 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)), manifest = await json(w, path), body = object(manifest.value);
|
|
237
|
+
const entries = [];
|
|
238
|
+
for (const [index, value] of array(body.functions, 50).entries()) {
|
|
239
|
+
const row = object(value), sourcePath = resolve(dirname(path), string(row.source)), contractPath = resolve(dirname(path), string(row.contract));
|
|
240
|
+
const source = await capture(w, sourcePath, 16 * 1024 * 1024), contract = await json(w, contractPath);
|
|
241
|
+
entries.push({ id: string(row.id, 256), source, contract: contract.artifact, passport: passport(contract.value, `functions[${index}].contract`) });
|
|
242
|
+
}
|
|
243
|
+
return { input: { task: o.task, worker: o.worker, fence: o.fence, epoch: o.epoch, lease: o.lease, manifest: manifest.artifact, entries: entries.map(({ passport, ...binding }) => binding) }, project: s.handoff(l.task).project.id,
|
|
244
|
+
apply: () => s.submit(l.task, l.worker, l.fence, entries, l.epoch) };
|
|
245
|
+
}),
|
|
246
|
+
changing('review', 'Submit a separate reviewer decision bound to current source hashes', [...held, file], async (s, w, o, c) => {
|
|
247
|
+
const l = leaseOf(o), path = resolve(c.cwd, string(o.file)), manifest = await json(w, path), entries = [];
|
|
248
|
+
for (const value of array(object(manifest.value).functions, 50)) {
|
|
249
|
+
const row = object(value);
|
|
250
|
+
if (typeof row.approved !== 'boolean')
|
|
251
|
+
fail('invalid', 'approved must be a JSON boolean (replace the null left by handoff --materialize).', { field: 'functions[].approved', id: row.id });
|
|
252
|
+
entries.push({ id: string(row.id, 256), sourceSha256: sha(row.sourceSha256), approved: row.approved,
|
|
253
|
+
note: await capture(w, resolve(dirname(path), string(row.note)), 2 * 1024 * 1024) });
|
|
254
|
+
}
|
|
255
|
+
return { input: { task: o.task, worker: o.worker, fence: o.fence, epoch: o.epoch, lease: o.lease, manifest: manifest.artifact, entries }, project: s.handoff(l.task).project.id,
|
|
256
|
+
apply: () => s.review(l.task, l.worker, l.fence, entries, l.epoch) };
|
|
257
|
+
}),
|
|
258
|
+
changing('compare', 'Compare supplied observation corpora exactly; never certify universal 1:1', [project, epoch,
|
|
259
|
+
{ flags: '--function <id>', description: 'Exact function ID', required: true }, { flags: '--source-sha256 <sha>', description: 'Current reconstruction hash', required: true },
|
|
260
|
+
{ flags: '--original <path>', description: 'Original observations JSON', required: true }, { flags: '--reconstruction <path>', description: 'Reconstruction observations JSON', required: true },
|
|
261
|
+
{ flags: '--layout <path>', description: 'Retained observation-layout JSON named by every outcome hash', required: true }], async (s, w, o, c) => {
|
|
262
|
+
const original = await json(w, resolve(c.cwd, string(o.original))), reconstruction = await json(w, resolve(c.cwd, string(o.reconstruction)));
|
|
263
|
+
const layout = await json(w, resolve(c.cwd, string(o.layout))), schema = object(layout.value);
|
|
264
|
+
if (schema.schema !== 1 || schema.kind !== 'observation-layout')
|
|
265
|
+
fail('invalid', 'Layout needs schema 1 and kind observation-layout.');
|
|
266
|
+
string(schema.description, 8000);
|
|
267
|
+
return { input: { project: o.project, function: o.function, sourceSha256: o.sourceSha256, epoch: o.epoch, original: original.artifact, reconstruction: reconstruction.artifact, layout: layout.artifact }, project: identifier(o.project),
|
|
268
|
+
apply: () => s.compare(identifier(o.project), string(o.function, 256), sha(o.sourceSha256), original.value, reconstruction.value, [original.artifact, reconstruction.artifact], layout.artifact, o.epoch === undefined ? undefined : identifier(o.epoch)) };
|
|
269
|
+
}),
|
|
270
|
+
command('certify', 'Fail closed: no supported exhaustive/formal verifier is available', (_, c) => run(c, s => s.certify()), { permission: Permission.Update }),
|
|
271
|
+
command('dashboard', 'Generate a consistent self-contained read-only HTML projection', ({ options: o }, c) => run(c, async (s, w) => saveDashboard(w, s, identifier(o.project), o.output === undefined ? undefined : resolve(c.cwd, string(o.output)))), { permission: Permission.ReadOnly, options: [project, { flags: '--output <path>', description: 'Optional new snapshot HTML file; existing files are never overwritten' }] }),
|
|
272
|
+
command('evidence', 'Verify and locate a retained content-addressed work attachment', ({ options: o }, c) => run(c, async (s, w) => {
|
|
273
|
+
const digest = sha(o.sha256), size = integer(o.size, 1, 4 * 1024 * 1024 * 1024), path = await w.artifacts.verify({ id: 'input:' + digest, kind: 'input', sha256: digest, size });
|
|
274
|
+
return { sha256: digest, size, path };
|
|
275
|
+
}), { permission: Permission.ReadOnly, options: [{ flags: '--sha256 <sha>', description: 'Retained attachment hash', required: true }, { flags: '--size <bytes>', description: 'Retained attachment size', required: true }] }),
|
|
276
|
+
])];
|
|
277
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type Workspace } from '../workspace.js';
|
|
2
|
+
import { type Snapshot } from './model.js';
|
|
3
|
+
import { type WorkStore } from './store.js';
|
|
4
|
+
/** A passive projection: this document has no mutation API, network dependency or evidence promotion. */
|
|
5
|
+
export declare function dashboardHtml(snapshot: Snapshot, live?: boolean): string;
|
|
6
|
+
export declare function saveDashboard(workspace: Workspace, store: WorkStore, projectId: string, output?: string): Promise<{
|
|
7
|
+
path: string;
|
|
8
|
+
revision: number;
|
|
9
|
+
generatedAt: number;
|
|
10
|
+
readOnly: boolean;
|
|
11
|
+
snapshot: boolean;
|
|
12
|
+
}>;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { lstat, mkdir, realpath, rename, unlink, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { join, resolve } from 'node:path';
|
|
3
|
+
import { randomUUID } from 'node:crypto';
|
|
4
|
+
import { fail, identifier } from './model.js';
|
|
5
|
+
const queues = new WeakMap();
|
|
6
|
+
const escape = (value) => value.replaceAll('&', '&').replaceAll('<', '<').replaceAll('>', '>').replaceAll('"', '"');
|
|
7
|
+
/** A passive projection: this document has no mutation API, network dependency or evidence promotion. */
|
|
8
|
+
export function dashboardHtml(snapshot, live = false) {
|
|
9
|
+
const data = JSON.stringify(snapshot).replaceAll('<', '\\u003c').replaceAll('\u2028', '\\u2028').replaceAll('\u2029', '\\u2029');
|
|
10
|
+
const nonce = randomUUID();
|
|
11
|
+
return `<!doctype html><html lang="en"><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
|
12
|
+
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src 'nonce-${nonce}'; style-src 'unsafe-inline'; img-src data:; base-uri 'none'; form-action 'none'">
|
|
13
|
+
<title>${escape(snapshot.project.name)} · RE ledger</title>
|
|
14
|
+
<style>
|
|
15
|
+
:root{color-scheme:dark;--bg:var(--background,#11151b);--surface:var(--card,#171d25);--ink:var(--foreground,#e5e9ef);--dim:var(--muted-foreground,#93a0b2);--line:var(--border,#2b3441);--work-accent:var(--warning,#e5b975);--soft:var(--secondary,#222c38);--bad:var(--destructive,#ec9992);--ok:var(--success,#9bc2aa);font-family:var(--font-sans,Segoe UI,system-ui,sans-serif);font-size:13px}
|
|
16
|
+
*{box-sizing:border-box}body{margin:0;background:transparent;color:var(--ink)}button,input,select{font:inherit}button{cursor:pointer}button:focus-visible,input:focus-visible,select:focus-visible{outline:2px solid var(--work-accent);outline-offset:2px}.app{background:var(--bg);min-height:760px}header{height:58px;display:flex;gap:14px;align-items:center;padding:0 22px;border-bottom:1px solid var(--line)}.mark{color:var(--work-accent);font:600 20px Consolas,monospace}.brand{font-weight:600}.crumb{color:var(--dim)}header .rev{margin-left:auto;font:12px Consolas,monospace;color:var(--dim)}.intro{display:flex;align-items:center;gap:18px;padding:22px 22px 16px}.intro h1{font-size:22px;letter-spacing:-.5px;font-weight:550;margin:0}.phase{font-size:11px;color:var(--work-accent);letter-spacing:1px;text-transform:uppercase}.sub{margin:6px 0 0;color:var(--dim);font-size:12px;line-height:1.6}.sub code{font-family:Consolas,monospace}.scope{margin-left:auto;text-align:right}.stats{display:grid;grid-template-columns:repeat(6,1fr);margin:0 22px 22px;border-top:1px solid var(--line);border-bottom:1px solid var(--line)}.stat{padding:16px 14px 16px 0}.stat span{display:block;font-size:11px;color:var(--dim);margin-bottom:8px}.stat b{font-weight:500;font-size:24px;font-variant-numeric:tabular-nums}.stat small{margin-left:6px;color:var(--dim);font-size:11px}.stat.strict{border-left:1px solid var(--line);padding-left:18px}.strict b{color:var(--work-accent)}.workspace{border-top:1px solid var(--line)}.tabs{padding:0 22px;display:flex;align-items:center;gap:26px;border-bottom:1px solid var(--line)}.tabs button{color:var(--dim);background:none;border:0;padding:14px 0 12px;border-bottom:2px solid transparent}.tabs button.active{color:var(--ink);border-color:var(--work-accent)}.tabs .mode{margin-left:auto;color:var(--dim);font-size:11px}.content{display:grid;grid-template-columns:minmax(0,1fr) 310px;min-height:440px}.main{min-width:0}aside{border-left:1px solid var(--line);background:var(--surface);padding:20px;overflow-wrap:anywhere}.toolbar{display:flex;gap:10px;align-items:center;padding:14px 22px;border-bottom:1px solid var(--line)}input,select{color:var(--ink);background:var(--surface);border:1px solid var(--line);border-radius:4px;padding:8px 10px;min-width:0}input{width:230px}select{max-width:170px}.toolbar small{margin-left:auto;color:var(--dim)}.tablewrap{overflow:auto;max-height:420px}table{width:100%;border-collapse:collapse;text-align:left;font-size:12px}th{font-weight:400;color:var(--dim);font-size:10px;letter-spacing:.8px;text-transform:uppercase;padding:11px 14px;border-bottom:1px solid var(--line);white-space:nowrap}td{padding:13px 14px;border-bottom:1px solid var(--line);vertical-align:top}td:first-child,th:first-child{padding-left:22px}tr.selectable{cursor:pointer}tr.selectable:hover{background:#1b232e}tr.selected{background:var(--soft)}.mono{font:11px/1.6 Consolas,monospace}.muted{color:var(--dim)}.name{font-weight:500;white-space:nowrap}.badge{display:inline-flex;gap:6px;align-items:center;white-space:nowrap;font-size:11px}.badge:before{content:'';width:5px;height:5px;border-radius:50%;background:var(--dim)}.badge.partial:before,.badge.queued:before{background:var(--work-accent)}.badge.reviewed:before,.badge.corpus_match:before{background:var(--ok)}.badge.mismatch:before{background:var(--bad)}.badge.leased:before{background:var(--ok)}aside h2{font-size:15px;font-weight:550;margin:8px 0 6px}aside h3{font-size:10px;color:var(--dim);text-transform:uppercase;letter-spacing:1px;margin:24px 0 10px}aside p{line-height:1.7;font-size:12px;margin:8px 0}.eyebrow{font-size:10px;letter-spacing:1px;text-transform:uppercase;color:var(--dim)}.proof{border-left:2px solid var(--work-accent);padding-left:12px;margin-top:20px}.proof strong{color:var(--work-accent);font-size:12px;font-weight:500}dl{margin:0}dt{color:var(--dim);font-size:11px;margin-top:12px}dd{margin:4px 0 0;line-height:1.6;font-size:12px}.empty{padding:45px 22px;color:var(--dim);line-height:1.8}.empty strong{font-weight:500;color:var(--ink)}.note{padding:13px 22px;font-size:11px;color:var(--dim);line-height:1.7;border-bottom:1px solid var(--line)}.graph{padding:12px 22px}.graph svg{width:100%;min-height:150px}.graph rect{fill:var(--surface);stroke:var(--line)}.graph text{fill:var(--ink);font:11px Consolas,monospace}.graph path{stroke:var(--work-accent);stroke-opacity:.55;fill:none}.events{padding:4px 22px}.event{padding:13px 0;border-bottom:1px solid var(--line);display:flex;gap:14px}.event code{color:var(--work-accent)}.event small{color:var(--dim)}footer{display:flex;gap:15px;padding:12px 22px;border-top:1px solid var(--line);font-size:10px;color:var(--dim);line-height:1.7}footer span:last-child{margin-left:auto}details{margin-top:14px}summary{cursor:pointer;color:var(--dim);font-size:11px}pre{white-space:pre-wrap;word-break:break-word;font:11px/1.7 Consolas,monospace}
|
|
17
|
+
@media(max-width:1000px){.content{grid-template-columns:minmax(0,1fr) 270px}.secondary{display:none}.toolbar{flex-wrap:wrap}.scope{display:none}}@media(max-width:760px){.content{display:block}aside{border-left:0;border-top:1px solid var(--line)}.stats{grid-template-columns:repeat(3,1fr)}.stat:nth-child(n+4){border-top:1px solid var(--line)}.stat.strict{border-left:0;padding-left:0}.intro{padding-top:18px}.tabs{gap:22px}.tabs .mode{display:none}header,footer{padding-left:16px;padding-right:16px}header .crumb{display:none}.stats{margin-left:16px;margin-right:16px}.toolbar small{display:none}input{flex:1;width:140px}select{max-width:150px}footer{flex-wrap:wrap}footer span:last-child{margin-left:0}.intro h1{font-size:20px}.app{min-height:700px}}
|
|
18
|
+
</style><div class="app"><header><div class="mark">⌘</div><span class="brand">insight</span><span class="crumb">/ Research ledger</span><span class="rev" id="revision"></span></header>
|
|
19
|
+
<section class="intro"><div><div class="phase">Reverse engineering</div><h1 id="project"></h1><p class="sub" id="identity"></p></div><div class="scope"><div class="eyebrow">Scope</div><p class="sub">Pinned executable<br>Discovery remains open</p></div></section>
|
|
20
|
+
<section class="stats" id="stats"></section><section class="workspace"><nav class="tabs" aria-label="Ledger views"><button data-tab="functions" class="active">Functions</button><button data-tab="tasks">Assignments</button><button data-tab="graph">Dependencies</button><button data-tab="events">Journal</button><span class="mode">READ ONLY</span></nav>
|
|
21
|
+
<div class="content"><main class="main"><div class="toolbar"><input id="search" aria-label="Search functions" placeholder="Search name or RVA…"><select id="stage" aria-label="Filter reconstruction stage"><option value="">All RE stages<option value="discovered">Discovered</option><option value="partial">Partial</option><option value="reconstructed">Reconstructed</option><option value="corpus_match">Corpus match</option><option value="reviewed">Reviewed</option><option value="mismatch">Mismatch</option></select><small id="slice"></small></div><div id="surface"></div></main><aside id="inspector"></aside></div></section>
|
|
22
|
+
<footer><span id="stamp"></span><span>Snapshot of shared state · no edits from this view</span><span>1:1 acceptance is locked</span></footer></div>
|
|
23
|
+
<script type="application/json" id="ledger" nonce="${nonce}">${data}</script><script nonce="${nonce}">
|
|
24
|
+
'use strict';
|
|
25
|
+
const S=JSON.parse(document.getElementById('ledger').textContent),$=id=>document.getElementById(id),E=v=>String(v??'').replaceAll('&','&').replaceAll('<','<').replaceAll('>','>').replaceAll('"','"').replaceAll("'",''');
|
|
26
|
+
const labels={discovered:'Discovered',partial:'Partial',reconstructed:'Reconstructed',corpus_match:'Corpus match',reviewed:'Reviewed',mismatch:'Mismatch'};
|
|
27
|
+
const hex=n=>'0x'+n.toString(16).padStart(8,'0'),short=s=>String(s).slice(0,12),time=n=>new Date(n).toLocaleTimeString([], {hour:'2-digit',minute:'2-digit'}),badge=s=>'<span class="badge '+E(s)+'">'+E(labels[s]||s)+'</span>';
|
|
28
|
+
let tab='functions',selected=S.functions[0]?.id;
|
|
29
|
+
$('project').textContent=S.project.name;$('revision').textContent='REV '+S.project.revision;$('identity').textContent='SHA-256 '+short(S.project.binarySha256)+'… · '+S.project.id;$('identity').title=S.project.binarySha256;
|
|
30
|
+
$('stamp').textContent=new Date(S.generatedAt).toLocaleString()+' · '+(${live}&&location.protocol==='file:'?'refreshes every 8s':'exported snapshot');
|
|
31
|
+
const stats=[['Tracked functions',S.trackedFunctions,''],['Reconstructed',S.counts.reconstructed,'unreviewed'],['Corpus match',S.counts.corpus_match,'finite cases'],['Reviewed',S.counts.reviewed,'separate author'],['Open / mismatched',S.counts.discovered+S.counts.partial+S.counts.mismatch,''],['Proven 1:1',0,'locked']];
|
|
32
|
+
$('stats').innerHTML=stats.map((a,i)=>'<div class="stat '+(i===5?'strict':'')+'"><span>'+E(a[0])+'</span><b>'+a[1]+'</b><small>'+E(a[2])+'</small></div>').join('');
|
|
33
|
+
function table(head,rows){return '<div class="tablewrap"><table><thead><tr>'+head.map((h,i)=>'<th'+(i>2?' class="secondary"':'')+'>'+E(h)+'</th>').join('')+'</tr></thead><tbody>'+rows.join('')+'</tbody></table></div>';}
|
|
34
|
+
function inspector(fn){
|
|
35
|
+
const task=S.tasks.find(t=>t.functions.includes(fn?.id)&&['queued','leased'].includes(t.status));
|
|
36
|
+
if(!fn){$('inspector').innerHTML='<div class="eyebrow">Inspection</div><h2>No selected function</h2><p class="muted">Import an evidence-linked function inventory to begin.</p><div class="proof"><strong>Strict 1:1</strong><p>No universal proof verifier is available. Acceptance remains locked.</p></div>';return;}
|
|
37
|
+
const passport=fn.passport;
|
|
38
|
+
$('inspector').innerHTML='<div class="eyebrow">Function · version '+fn.version+'</div><h2>'+E(fn.name)+'</h2><div class="mono muted">'+hex(fn.rva)+'</div><p>'+badge(fn.stage)+'</p><h3>Assignment</h3><p>'+(task?E(task.worker||'Queued for assignment')+'<br><span class="mono muted">'+E(task.id)+'</span><br>Fence '+task.fence+' · '+(task.status==='leased'?(task.leaseUntil>Date.now()?'lease until '+time(task.leaseUntil):'lease expired'):E(task.status)):'No outstanding assignment')+'</p><h3>Contract & evidence</h3>'+(passport?'<p>'+E(passport.signature)+'</p><dl><dt>ABI</dt><dd>'+E(passport.abi)+'</dd><dt>Open questions</dt><dd>'+E(passport.unknowns.length?passport.unknowns.join('; '):'None declared by author; review is still required')+'</dd></dl>':'<p class="muted">Contract, ABI, effects and branch coverage have not been reconstructed.</p>')+'<dl><dt>Risk</dt><dd>'+E(fn.risk)+'</dd><dt>Shared resource reservations</dt><dd>'+E(fn.resources.join(', ')||'No resource keys declared; closure is unknown')+'</dd><dt>Reconstruction source</dt><dd class="mono">'+E(fn.source?fn.source.name+' · '+fn.source.sha256:'Not submitted')+'</dd></dl><div class="proof"><strong>1:1 acceptance · locked</strong><p>Reconstruction, finite corpus equality and review do not prove all permitted executions. No supported exhaustive/formal verifier is installed.</p></div><details><summary>Identity & retained record</summary><pre>'+E(JSON.stringify(fn,null,2))+'</pre></details>';
|
|
39
|
+
}
|
|
40
|
+
function render(){
|
|
41
|
+
$('search').disabled=tab!=='functions';$('stage').disabled=tab!=='functions';
|
|
42
|
+
document.querySelectorAll('[data-tab]').forEach(b=>{b.classList.toggle('active',b.dataset.tab===tab);b.setAttribute('aria-selected',String(b.dataset.tab===tab));});
|
|
43
|
+
if(tab==='functions'){
|
|
44
|
+
const q=$('search').value.toLowerCase(),stage=$('stage').value,rows=S.functions.filter(f=>(!stage||f.stage===stage)&&(!q||[f.name,f.id,hex(f.rva)].some(x=>x.toLowerCase().includes(q))));
|
|
45
|
+
$('slice').textContent=rows.length+' / '+S.trackedFunctions+' tracked';
|
|
46
|
+
$('surface').innerHTML=rows.length?table(['Function','RE stage','RVA','Owner','Risk'],rows.map(f=>{const t=S.tasks.find(t=>t.functions.includes(f.id)&&['queued','leased'].includes(t.status));return '<tr tabindex="0" class="selectable '+(f.id===selected?'selected':'')+'" data-function="'+E(f.id)+'"><td class="name">'+E(f.name)+'</td><td>'+badge(f.stage)+'</td><td class="mono">'+hex(f.rva)+'</td><td class="secondary muted">'+E(t?.worker||f.author||'—')+'</td><td class="secondary muted">'+E(f.risk)+'</td></tr>';})):'<div class="empty"><strong>No matching functions</strong><br>Change the filter or import a bounded inventory.</div>';
|
|
47
|
+
$('surface').insertAdjacentHTML('beforeend','<div class="note">Showing a bounded slice of '+S.functions.length+' functions. Reported upstream count: '+E(S.project.inventory.reportedTotal??'unknown')+'. Inventory completeness is not established.</div>');
|
|
48
|
+
document.querySelectorAll('[data-function]').forEach(el=>{const choose=()=>{selected=el.dataset.function;render();};el.addEventListener('click',choose);el.addEventListener('keydown',e=>{if(e.key==='Enter')choose();});});
|
|
49
|
+
}else if(tab==='tasks'){
|
|
50
|
+
$('slice').textContent='Latest '+S.tasks.length;
|
|
51
|
+
$('surface').innerHTML=S.tasks.length?table(['Assignment','Status','Scope','Worker','Fence'],S.tasks.map(t=>'<tr><td><span class="mono">'+E(short(t.id))+'…</span><br><span class="muted">'+E(t.kind)+'</span></td><td>'+badge(t.status==='leased'&&t.leaseUntil<=Date.now()?'expired':t.status)+'</td><td>'+t.functions.length+' functions</td><td class="secondary">'+E(t.worker||'unassigned')+'</td><td class="secondary mono">'+t.fence+'</td></tr>')):'<div class="empty"><strong>No assignments yet</strong><br>Plan a small slice from the current project revision.</div>';
|
|
52
|
+
}else if(tab==='graph'){
|
|
53
|
+
$('slice').textContent=S.graph.nodeCount+' nodes · '+S.graph.edgeCount+' edges';
|
|
54
|
+
const names=new Map([...S.functions.map(f=>[f.id,f.name]),...S.graph.nodes.map(n=>[n.id,n.label])]),edges=S.graph.edges.slice(0,12);
|
|
55
|
+
if(!edges.length)$('surface').innerHTML='<div class="empty"><strong>No dependency edges imported</strong><br>Calls, indirect dispatch, globals, types and initialization dependencies remain unmapped. An empty graph does not mean an empty dependency set.</div>';
|
|
56
|
+
else{const nodes=[...new Set(edges.flatMap(e=>[e.source,e.target]))].slice(0,16),width=640,height=Math.max(190,Math.ceil(nodes.length/2)*58),xy=new Map(nodes.map((n,i)=>[n,[i%2?420:20,24+Math.floor(i/2)*58]]));
|
|
57
|
+
const paths=edges.filter(e=>xy.has(e.source)&&xy.has(e.target)).map(e=>{const a=xy.get(e.source),b=xy.get(e.target);return '<path d="M '+(a[0]+90)+' '+(a[1]+14)+' Q 320 '+(a[1]+b[1])/2+' '+(b[0]+90)+' '+(b[1]+14)+'"/>';}).join('');
|
|
58
|
+
const boxes=nodes.map(n=>{const p=xy.get(n);return '<g><title>'+E(n)+'</title><rect x="'+p[0]+'" y="'+p[1]+'" width="190" height="30" rx="4"/><text x="'+(p[0]+9)+'" y="'+(p[1]+19)+'">'+E(String(names.get(n)||n).slice(0,24))+'</text></g>';}).join('');
|
|
59
|
+
$('surface').innerHTML='<div class="graph"><svg role="img" aria-label="Bounded dependency graph" viewBox="0 0 '+width+' '+height+'">'+paths+boxes+'</svg></div>'+table(['Relationship','Source → target','Evidence'],edges.map(e=>'<tr><td>'+E(e.kind)+'<br><small class="muted">'+E(e.confidence)+'</small></td><td>'+E(names.get(e.source)||e.source)+' → '+E(names.get(e.target)||e.target)+'</td><td>'+E(e.evidence)+'</td></tr>'));}
|
|
60
|
+
$('surface').insertAdjacentHTML('beforeend','<div class="note">Partial evidence graph. This view draws at most 12 edges / 16 nodes. No closure or call-graph completeness is inferred.</div>');
|
|
61
|
+
}else{
|
|
62
|
+
$('slice').textContent='Latest '+S.events.length;
|
|
63
|
+
$('surface').innerHTML='<div class="events">'+S.events.map(e=>'<div class="event"><small>R'+e.revision+'</small><div><code>'+E(e.kind)+'</code><br><small>'+E(e.data.worker||e.data.task||e.data.function||'Shared project state')+'</small></div><small style="margin-left:auto">'+time(e.data.at)+'</small></div>').join('')+'</div>';
|
|
64
|
+
}
|
|
65
|
+
inspector(S.functions.find(f=>f.id===selected));
|
|
66
|
+
}
|
|
67
|
+
document.querySelectorAll('[data-tab]').forEach(b=>b.addEventListener('click',()=>{tab=b.dataset.tab;render();}));$('search').addEventListener('input',render);$('stage').addEventListener('change',render);render();
|
|
68
|
+
if(${live}&&location.protocol==='file:')setTimeout(()=>location.reload(),8000);
|
|
69
|
+
</script></html>`;
|
|
70
|
+
}
|
|
71
|
+
export async function saveDashboard(workspace, store, projectId, output) {
|
|
72
|
+
identifier(projectId);
|
|
73
|
+
const previous = queues.get(workspace) ?? Promise.resolve();
|
|
74
|
+
const pending = previous.catch(() => { }).then(async () => {
|
|
75
|
+
const snapshot = store.snapshot(projectId), directory = join(workspace.directory, 'work-views');
|
|
76
|
+
await mkdir(directory, { recursive: true, mode: 0o700 });
|
|
77
|
+
if ((await lstat(directory)).isSymbolicLink() || await realpath(directory) !== resolve(directory))
|
|
78
|
+
fail('storage', 'Dashboard directory is not profile-owned.');
|
|
79
|
+
const path = output ?? join(directory, projectId + '.html');
|
|
80
|
+
if (output)
|
|
81
|
+
await writeFile(path, dashboardHtml(snapshot), { flag: 'wx', mode: 0o600 });
|
|
82
|
+
else {
|
|
83
|
+
const temporary = path + '.pending-' + randomUUID();
|
|
84
|
+
try {
|
|
85
|
+
await writeFile(temporary, dashboardHtml(snapshot, true), { flag: 'wx', mode: 0o600 });
|
|
86
|
+
await rename(temporary, path);
|
|
87
|
+
}
|
|
88
|
+
finally {
|
|
89
|
+
await unlink(temporary).catch(error => { if (error.code !== 'ENOENT')
|
|
90
|
+
throw error; });
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return { path, revision: snapshot.project.revision, generatedAt: snapshot.generatedAt, readOnly: true, snapshot: Boolean(output) };
|
|
94
|
+
});
|
|
95
|
+
queues.set(workspace, pending);
|
|
96
|
+
try {
|
|
97
|
+
return await pending;
|
|
98
|
+
}
|
|
99
|
+
finally {
|
|
100
|
+
if (queues.get(workspace) === pending)
|
|
101
|
+
queues.delete(workspace);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { digest, stable } from '../model.js';
|
|
2
|
+
export { digest, stable };
|
|
3
|
+
export declare function fail(code: string, message: string, result?: unknown): never;
|
|
4
|
+
export declare function string(value: unknown, max?: number): string;
|
|
5
|
+
export declare function identifier(value: unknown): string;
|
|
6
|
+
export declare function integer(value: unknown, min: number, max: number): number;
|
|
7
|
+
export declare function object(value: unknown): Record<string, unknown>;
|
|
8
|
+
export declare function array(value: unknown, max: number): unknown[];
|
|
9
|
+
/** A caller label may have outcomes from several restored incarnations. Never choose one silently. */
|
|
10
|
+
export declare function archivedOutcomes(value: unknown): Record<string, unknown>[];
|
|
11
|
+
export declare function sha(value: unknown): string;
|
|
12
|
+
export declare function rva(value: unknown): number;
|
|
13
|
+
export type Stage = 'discovered' | 'partial' | 'reconstructed' | 'corpus_match' | 'reviewed' | 'mismatch';
|
|
14
|
+
export interface WorkFunction {
|
|
15
|
+
id: string;
|
|
16
|
+
rva: number;
|
|
17
|
+
name: string;
|
|
18
|
+
risk: 'normal' | 'high' | 'unknown';
|
|
19
|
+
resources: string[];
|
|
20
|
+
stage: Stage;
|
|
21
|
+
version: number;
|
|
22
|
+
definition: Record<string, unknown>;
|
|
23
|
+
definitionRevision?: number;
|
|
24
|
+
definitionSha256?: string;
|
|
25
|
+
packageDefinitionRevision?: number;
|
|
26
|
+
invalidated?: {
|
|
27
|
+
reason: string;
|
|
28
|
+
at: number;
|
|
29
|
+
request?: string;
|
|
30
|
+
};
|
|
31
|
+
author?: string;
|
|
32
|
+
source?: Attachment;
|
|
33
|
+
contract?: Attachment;
|
|
34
|
+
passport?: Record<string, unknown>;
|
|
35
|
+
comparison?: Record<string, unknown>;
|
|
36
|
+
review?: Record<string, unknown>;
|
|
37
|
+
reviewRequired?: {
|
|
38
|
+
reason: string;
|
|
39
|
+
at: number;
|
|
40
|
+
sourceSha256: string;
|
|
41
|
+
contractSha256: string;
|
|
42
|
+
request?: string;
|
|
43
|
+
};
|
|
44
|
+
accepted1to1: false;
|
|
45
|
+
}
|
|
46
|
+
export interface Attachment {
|
|
47
|
+
id: string;
|
|
48
|
+
sha256: string;
|
|
49
|
+
size: number;
|
|
50
|
+
name: string;
|
|
51
|
+
}
|
|
52
|
+
export interface Project {
|
|
53
|
+
id: string;
|
|
54
|
+
target: string;
|
|
55
|
+
binarySha256: string;
|
|
56
|
+
name: string;
|
|
57
|
+
revision: number;
|
|
58
|
+
phase: 'reverse-engineering';
|
|
59
|
+
planningRevision?: number;
|
|
60
|
+
epoch?: string;
|
|
61
|
+
epochRequired?: boolean;
|
|
62
|
+
inventory: {
|
|
63
|
+
complete: false;
|
|
64
|
+
reportedTotal: number | null;
|
|
65
|
+
sources: Attachment[];
|
|
66
|
+
};
|
|
67
|
+
createdAt: number;
|
|
68
|
+
}
|
|
69
|
+
export interface Task {
|
|
70
|
+
id: string;
|
|
71
|
+
project: string;
|
|
72
|
+
kind: 'reconstruct' | 'review';
|
|
73
|
+
status: 'queued' | 'leased' | 'submitted' | 'cancelled';
|
|
74
|
+
functions: string[];
|
|
75
|
+
versions: Record<string, number>;
|
|
76
|
+
resources: string[];
|
|
77
|
+
worker?: string;
|
|
78
|
+
fence: number;
|
|
79
|
+
leaseUntil: number;
|
|
80
|
+
createdAt: number;
|
|
81
|
+
result?: unknown;
|
|
82
|
+
epoch?: string;
|
|
83
|
+
}
|
|
84
|
+
export interface Snapshot {
|
|
85
|
+
project: Project;
|
|
86
|
+
counts: Record<Stage, number>;
|
|
87
|
+
trackedFunctions: number;
|
|
88
|
+
accepted1to1: 0;
|
|
89
|
+
functions: WorkFunction[];
|
|
90
|
+
tasks: Task[];
|
|
91
|
+
events: unknown[];
|
|
92
|
+
generatedAt: number;
|
|
93
|
+
functionLimit: number;
|
|
94
|
+
limits: string[];
|
|
95
|
+
graph: {
|
|
96
|
+
nodes: Record<string, unknown>[];
|
|
97
|
+
edges: Record<string, unknown>[];
|
|
98
|
+
nodeCount: number;
|
|
99
|
+
edgeCount: number;
|
|
100
|
+
complete: false;
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
export declare function functionIdentity(binarySha: string, at: number): string;
|
|
104
|
+
export declare function definition(value: unknown, binarySha: string): WorkFunction;
|
|
105
|
+
export declare const passportTextFields: string[];
|
|
106
|
+
export declare const passportListFields: string[];
|
|
107
|
+
/** Validates a passport and names the failing field path, e.g. functions[2].contract.inputs. */
|
|
108
|
+
export declare function passport(value: unknown, at?: string): Record<string, unknown>;
|
|
109
|
+
/** Derived review status of the current package: none, approved, rejected or stale (review of an older
|
|
110
|
+
* source, or a package retained under an older definition revision after `revise-definition`). */
|
|
111
|
+
export declare function reviewState(fn: {
|
|
112
|
+
source?: {
|
|
113
|
+
sha256: string;
|
|
114
|
+
};
|
|
115
|
+
contract?: {
|
|
116
|
+
sha256: string;
|
|
117
|
+
};
|
|
118
|
+
review?: Record<string, unknown>;
|
|
119
|
+
invalidated?: unknown;
|
|
120
|
+
reviewRequired?: unknown;
|
|
121
|
+
definitionRevision?: number;
|
|
122
|
+
packageDefinitionRevision?: number;
|
|
123
|
+
}): 'none' | 'approved' | 'rejected' | 'stale';
|
|
124
|
+
/** Opaque convenience handle for one lease: task, worker, fence and epoch. Not a secret or authentication. */
|
|
125
|
+
export declare function leaseToken(task: Task): string;
|
|
126
|
+
export declare function parseLease(value: unknown): {
|
|
127
|
+
task: string;
|
|
128
|
+
worker: string;
|
|
129
|
+
fence: number;
|
|
130
|
+
epoch?: string;
|
|
131
|
+
};
|