@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,26 @@
|
|
|
1
|
+
import { type DatabaseSync } from 'node:sqlite';
|
|
2
|
+
export declare function timingReport(db: DatabaseSync, project: string, selected?: string[]): {
|
|
3
|
+
rows: {
|
|
4
|
+
function: string;
|
|
5
|
+
authorTask: string;
|
|
6
|
+
authorStatus: "queued" | "cancelled" | "leased" | "submitted";
|
|
7
|
+
reviewTask: string | null;
|
|
8
|
+
authorMs: number | null;
|
|
9
|
+
waitForCompletedReviewMs: number | null;
|
|
10
|
+
reviewMs: number | null;
|
|
11
|
+
toDecisionMs: number | null;
|
|
12
|
+
approved: boolean | null;
|
|
13
|
+
decisionAt: number | null;
|
|
14
|
+
firstApprovalAt: number | null;
|
|
15
|
+
}[];
|
|
16
|
+
queue: Record<string, import("node:sqlite").SQLOutputValue>[];
|
|
17
|
+
selectedTasks: number;
|
|
18
|
+
batchToDecisionMs: number | null;
|
|
19
|
+
byFunction: {
|
|
20
|
+
[k: string]: {
|
|
21
|
+
firstVerdict: boolean;
|
|
22
|
+
firstDecisionAt: number;
|
|
23
|
+
firstApprovalAt: number | null;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { fail, identifier } from './model.js';
|
|
2
|
+
// Report only the selected reconstruction attempts. A review names a version for
|
|
3
|
+
// each function separately, even when author and reviewer grouped them differently.
|
|
4
|
+
export function timingReport(db, project, selected) {
|
|
5
|
+
if (selected && (!selected.length || selected.length > 100 || new Set(selected).size !== selected.length))
|
|
6
|
+
fail('invalid', 'Select 1 to 100 distinct reconstruction task IDs.');
|
|
7
|
+
const taskQuery = db.prepare('SELECT data FROM tasks WHERE project=? AND id=? AND json_extract(data,\'$.kind\')=\'reconstruct\'');
|
|
8
|
+
const authors = selected ? selected.map(id => {
|
|
9
|
+
const row = taskQuery.get(project, identifier(id));
|
|
10
|
+
if (!row)
|
|
11
|
+
fail('notFound', 'Reconstruction task is absent from this project: ' + id);
|
|
12
|
+
return JSON.parse(String(row.data));
|
|
13
|
+
}) : db.prepare("SELECT data FROM tasks WHERE project=? AND json_extract(data,'$.kind')='reconstruct' ORDER BY rowid DESC LIMIT 10")
|
|
14
|
+
.all(project).reverse().map(row => JSON.parse(String(row.data)));
|
|
15
|
+
const taskEvents = db.prepare(`SELECT kind,json_extract(data,'$.at') AS at FROM events
|
|
16
|
+
WHERE project=? AND json_extract(data,'$.task')=? AND kind IN ('task.claimed','reconstruction.submitted','review.submitted') ORDER BY seq`);
|
|
17
|
+
const clocks = new Map();
|
|
18
|
+
function taskClock(id) {
|
|
19
|
+
const cached = clocks.get(id);
|
|
20
|
+
if (cached)
|
|
21
|
+
return cached;
|
|
22
|
+
const clock = {};
|
|
23
|
+
for (const row of taskEvents.iterate(project, id)) {
|
|
24
|
+
if (row.kind === 'task.claimed') {
|
|
25
|
+
clock.firstClaim ??= Number(row.at);
|
|
26
|
+
clock.claim = Number(row.at);
|
|
27
|
+
}
|
|
28
|
+
else
|
|
29
|
+
clock.submitted = Number(row.at);
|
|
30
|
+
}
|
|
31
|
+
clocks.set(id, clock);
|
|
32
|
+
return clock;
|
|
33
|
+
}
|
|
34
|
+
// Version history identifies the originating request, including comparisons
|
|
35
|
+
// and explicit reopenings between author submission and independent review.
|
|
36
|
+
// Unary + drops the TEXT column affinity without changing the request value;
|
|
37
|
+
// SQLite can then seek both parts of the JSON expression index.
|
|
38
|
+
const history = db.prepare(`SELECT e.kind,json_extract(e.data,'$.task') AS task,
|
|
39
|
+
json_extract(v.data,'$.review.approved') AS approved
|
|
40
|
+
FROM function_versions v CROSS JOIN events e
|
|
41
|
+
WHERE v.project=? AND v.id=? AND v.version>? AND e.project=v.project
|
|
42
|
+
AND json_extract(e.data,'$.request')=+v.request AND e.kind IN ('reconstruction.submitted','review.submitted')
|
|
43
|
+
ORDER BY v.version`);
|
|
44
|
+
function decisions(task, id) {
|
|
45
|
+
const found = [];
|
|
46
|
+
for (const row of history.iterate(project, id, task.versions[id] + 1)) {
|
|
47
|
+
if (row.kind === 'reconstruction.submitted')
|
|
48
|
+
break;
|
|
49
|
+
const reviewTask = String(row.task);
|
|
50
|
+
found.push({ reviewTask, clock: taskClock(reviewTask), approved: row.approved === 1 });
|
|
51
|
+
}
|
|
52
|
+
return found;
|
|
53
|
+
}
|
|
54
|
+
const elapsed = (start, end) => start === undefined || end === undefined ? null : end - start;
|
|
55
|
+
let start, end, complete = true;
|
|
56
|
+
const rows = authors.flatMap(task => task.functions.map(id => {
|
|
57
|
+
const author = taskClock(task.id);
|
|
58
|
+
const history = author.submitted === undefined ? [] : decisions(task, id), verdict = history[0];
|
|
59
|
+
const review = verdict?.clock;
|
|
60
|
+
if (author.firstClaim !== undefined)
|
|
61
|
+
start = Math.min(start ?? Infinity, author.firstClaim);
|
|
62
|
+
if (review?.submitted === undefined)
|
|
63
|
+
complete = false;
|
|
64
|
+
else
|
|
65
|
+
end = Math.max(end ?? -Infinity, review.submitted);
|
|
66
|
+
return { function: id, authorTask: task.id, authorStatus: task.status, reviewTask: verdict?.reviewTask ?? null,
|
|
67
|
+
authorMs: elapsed(author.claim, author.submitted), waitForCompletedReviewMs: elapsed(author.submitted, review?.claim),
|
|
68
|
+
reviewMs: elapsed(review?.claim, review?.submitted), toDecisionMs: elapsed(author.firstClaim, review?.submitted),
|
|
69
|
+
approved: verdict?.approved ?? null, decisionAt: review?.submitted ?? null, firstApprovalAt: history.find(v => v.approved)?.clock.submitted ?? null };
|
|
70
|
+
}));
|
|
71
|
+
const byFunction = new Map();
|
|
72
|
+
for (const row of rows.filter(r => r.decisionAt !== null).sort((a, b) => a.decisionAt - b.decisionAt)) {
|
|
73
|
+
const summary = byFunction.get(row.function) ?? { firstVerdict: row.approved, firstDecisionAt: row.decisionAt, firstApprovalAt: null };
|
|
74
|
+
if (row.firstApprovalAt !== null)
|
|
75
|
+
summary.firstApprovalAt = Math.min(summary.firstApprovalAt ?? Infinity, row.firstApprovalAt);
|
|
76
|
+
byFunction.set(row.function, summary);
|
|
77
|
+
}
|
|
78
|
+
const queue = db.prepare("SELECT json_extract(data,'$.kind') AS kind,status,count(*) AS count FROM tasks WHERE project=? AND status IN ('queued','leased') GROUP BY kind,status ORDER BY kind,status").all(project);
|
|
79
|
+
return { rows, queue, selectedTasks: authors.length, batchToDecisionMs: complete ? elapsed(start, end) : null, byFunction: Object.fromEntries(byFunction) };
|
|
80
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** Must stay well below the worker's hold expiry (three minutes). */
|
|
2
|
+
export declare const leaseHeartbeatMs = 60000;
|
|
3
|
+
export declare function withWorkerLeases<T>(action: () => Promise<T>): Promise<T>;
|
|
4
|
+
export declare function inWorkerLeaseScope(): boolean;
|
|
5
|
+
export declare function workerLeaseHeld(key: string): boolean;
|
|
6
|
+
/** The worker-side identity of this command's hold, when it has one. */
|
|
7
|
+
export declare function workerLeaseHolder(key: string): string | undefined;
|
|
8
|
+
/** Keep a worker held for the rest of the current command. Outside a command nothing is retained. */
|
|
9
|
+
export declare function holdWorkerLease(key: string, lease: {
|
|
10
|
+
renew: () => Promise<unknown>;
|
|
11
|
+
release: () => Promise<unknown>;
|
|
12
|
+
holder?: string;
|
|
13
|
+
}): void;
|
|
14
|
+
/** Release this command's hold now (for example before asking the worker to stop). */
|
|
15
|
+
export declare function releaseWorkerLease(key: string): Promise<void>;
|
|
16
|
+
/** A stopped worker needs no further renewal or release in this command. */
|
|
17
|
+
export declare function dropWorkerLease(key: string): void;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
|
+
const scope = new AsyncLocalStorage();
|
|
3
|
+
/** Must stay well below the worker's hold expiry (three minutes). */
|
|
4
|
+
export const leaseHeartbeatMs = 60000;
|
|
5
|
+
export async function withWorkerLeases(action) {
|
|
6
|
+
const held = new Map();
|
|
7
|
+
try {
|
|
8
|
+
return await scope.run(held, action);
|
|
9
|
+
}
|
|
10
|
+
finally {
|
|
11
|
+
for (const lease of held.values())
|
|
12
|
+
clearInterval(lease.timer);
|
|
13
|
+
await Promise.all([...held.values()].map(lease => lease.release().catch(() => { })));
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export function inWorkerLeaseScope() { return scope.getStore() !== undefined; }
|
|
17
|
+
export function workerLeaseHeld(key) { return scope.getStore()?.has(key) === true; }
|
|
18
|
+
/** The worker-side identity of this command's hold, when it has one. */
|
|
19
|
+
export function workerLeaseHolder(key) { return scope.getStore()?.get(key)?.holder; }
|
|
20
|
+
/** Keep a worker held for the rest of the current command. Outside a command nothing is retained. */
|
|
21
|
+
export function holdWorkerLease(key, lease) {
|
|
22
|
+
const held = scope.getStore();
|
|
23
|
+
if (!held)
|
|
24
|
+
return;
|
|
25
|
+
const previous = held.get(key);
|
|
26
|
+
if (previous) {
|
|
27
|
+
clearInterval(previous.timer);
|
|
28
|
+
void previous.release().catch(() => { });
|
|
29
|
+
}
|
|
30
|
+
const timer = setInterval(() => { void lease.renew().catch(() => { }); }, leaseHeartbeatMs);
|
|
31
|
+
timer.unref();
|
|
32
|
+
held.set(key, { ...lease, timer });
|
|
33
|
+
}
|
|
34
|
+
/** Release this command's hold now (for example before asking the worker to stop). */
|
|
35
|
+
export async function releaseWorkerLease(key) {
|
|
36
|
+
const held = scope.getStore(), lease = held?.get(key);
|
|
37
|
+
if (!lease)
|
|
38
|
+
return;
|
|
39
|
+
clearInterval(lease.timer);
|
|
40
|
+
held.delete(key);
|
|
41
|
+
await lease.release().catch(() => { });
|
|
42
|
+
}
|
|
43
|
+
/** A stopped worker needs no further renewal or release in this command. */
|
|
44
|
+
export function dropWorkerLease(key) {
|
|
45
|
+
const held = scope.getStore(), lease = held?.get(key);
|
|
46
|
+
if (!lease)
|
|
47
|
+
return;
|
|
48
|
+
clearInterval(lease.timer);
|
|
49
|
+
held.delete(key);
|
|
50
|
+
}
|
package/dist/src/workspace.d.ts
CHANGED
|
@@ -62,8 +62,6 @@ export interface NativeCheckout {
|
|
|
62
62
|
request: string;
|
|
63
63
|
message: string;
|
|
64
64
|
};
|
|
65
|
-
/** Saved buffers proved to hold no private work although Ghidra rewrote them on open; the release accepts only these. */
|
|
66
|
-
opened?: string;
|
|
67
65
|
}
|
|
68
66
|
export interface GhidraContext extends Scope {
|
|
69
67
|
/** Internal storage key, never a caller's backend selector. */
|
|
@@ -190,15 +188,11 @@ export declare class Workspace {
|
|
|
190
188
|
private giveUp;
|
|
191
189
|
/** An abandoned or otherwise unknown terminal effect keeps all of its native evidence. */
|
|
192
190
|
uncertainOutcome(scope: Scope): boolean;
|
|
193
|
-
/** Receipt-only comparison; native state is verified separately before any release. */
|
|
194
|
-
unchangedNative(context: GhidraContext): boolean;
|
|
195
191
|
/**
|
|
196
|
-
*
|
|
197
|
-
*
|
|
192
|
+
* Whether the working copy holds no private work, as Ghidra itself reported it when the copy was last saved or
|
|
193
|
+
* observed (`modifiedSinceCheckout`). Native state is observed again before any release.
|
|
198
194
|
*/
|
|
199
|
-
|
|
200
|
-
/** Saved buffers of pristine checkouts of one shared version, as each was left by its worker's own open. */
|
|
201
|
-
openedReferences(target: string, base: Record<string, unknown>): Set<string>;
|
|
195
|
+
unchangedNative(context: GhidraContext): boolean;
|
|
202
196
|
/** Another context's unresolved operation may still need this checkout's private view. */
|
|
203
197
|
checkoutReferenced(context: GhidraContext, root?: string | undefined): boolean;
|
|
204
198
|
/** Applied requests keep their results; their superseded before-images are not recovery inputs. */
|
|
@@ -213,6 +207,8 @@ export declare class Workspace {
|
|
|
213
207
|
replay: boolean;
|
|
214
208
|
};
|
|
215
209
|
administrationByCaller(callerId: string): AdministrationRequest | undefined;
|
|
210
|
+
/** Synchronous metadata snapshot; consumers must not perform remote work in this callback. */
|
|
211
|
+
withAdministrationSnapshot<T>(prefix: string, read: (records: Iterable<AdministrationRequest>) => T): T;
|
|
216
212
|
requestByCaller(callerId: string): ResearchRequest | undefined;
|
|
217
213
|
administration(request: string): AdministrationRequest;
|
|
218
214
|
unresolvedAdministration(): AdministrationRequest[];
|
package/dist/src/workspace.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DatabaseSync } from 'node:sqlite';
|
|
2
2
|
import { auditEvent, bindAudit, auditHash } from './activity-audit.js';
|
|
3
|
-
import { chmodSync, mkdirSync, readFileSync,
|
|
3
|
+
import { chmodSync, mkdirSync, readFileSync, realpathSync } from 'node:fs';
|
|
4
4
|
import { basename, join } from 'node:path';
|
|
5
5
|
import { randomUUID } from 'node:crypto';
|
|
6
6
|
import { Artifacts } from './artifacts.js';
|
|
@@ -336,55 +336,23 @@ export class Workspace {
|
|
|
336
336
|
return this.db.prepare("SELECT data FROM requests WHERE context=? AND state='failed'").all(this.context(scope).id).map(row => JSON.parse(String(row.data)))
|
|
337
337
|
.some(row => !row.dropped && row.result?.outcome === 'unknown');
|
|
338
338
|
}
|
|
339
|
-
/**
|
|
339
|
+
/**
|
|
340
|
+
* Whether the working copy holds no private work, as Ghidra itself reported it when the copy was last saved or
|
|
341
|
+
* observed (`modifiedSinceCheckout`). Native state is observed again before any release.
|
|
342
|
+
*/
|
|
340
343
|
unchangedNative(context) {
|
|
341
344
|
if (context.nativeCheckout?.state === 'verified')
|
|
342
345
|
return true;
|
|
343
|
-
if (context.workingSnapshot?.kind !== 'native'
|
|
346
|
+
if (context.workingSnapshot?.kind !== 'native')
|
|
344
347
|
return false;
|
|
345
348
|
try {
|
|
346
|
-
const
|
|
347
|
-
return
|
|
349
|
+
const local = JSON.parse(readFileSync(this.artifacts.path(context.workingSnapshot), 'utf8'));
|
|
350
|
+
return local.source === 'checkout' && local.modified === false;
|
|
348
351
|
}
|
|
349
352
|
catch {
|
|
350
353
|
return false;
|
|
351
354
|
}
|
|
352
355
|
}
|
|
353
|
-
/**
|
|
354
|
-
* Saved buffers hold no private work when they equal the shared base, or equal what Ghidra itself wrote when a
|
|
355
|
-
* worker opened a pristine checkout of that base. Equal bytes are the proof; what Ghidra rewrote is irrelevant.
|
|
356
|
-
*/
|
|
357
|
-
unchangedBuffers(target, base, fingerprint) {
|
|
358
|
-
if (typeof fingerprint !== 'string' || !/^[a-f0-9]{64}$/.test(fingerprint) || base.source !== 'server' || typeof base.fingerprint !== 'string')
|
|
359
|
-
return false;
|
|
360
|
-
return fingerprint === base.fingerprint || this.openedReferences(target, base).has(fingerprint);
|
|
361
|
-
}
|
|
362
|
-
/** Saved buffers of pristine checkouts of one shared version, as each was left by its worker's own open. */
|
|
363
|
-
openedReferences(target, base) {
|
|
364
|
-
const revision = Number(base.version);
|
|
365
|
-
const found = new Set(), root = join(this.directory, 'ghidra-native', 'shared-views', id(target), 'opened');
|
|
366
|
-
let names;
|
|
367
|
-
try {
|
|
368
|
-
names = readdirSync(root);
|
|
369
|
-
}
|
|
370
|
-
catch {
|
|
371
|
-
return found;
|
|
372
|
-
}
|
|
373
|
-
for (const name of names) {
|
|
374
|
-
const match = /^v(\d+)-([a-f0-9]{64})\.json$/.exec(name);
|
|
375
|
-
if (!match || Number(match[1]) !== revision)
|
|
376
|
-
continue;
|
|
377
|
-
try {
|
|
378
|
-
const row = JSON.parse(readFileSync(join(root, name), 'utf8'));
|
|
379
|
-
// Earlier receipts inferred pristine state from control metadata alone; they cannot authorize deletion.
|
|
380
|
-
if (row.schema === 2 && row.preOpen?.fingerprint === base.fingerprint && row.preOpen.fileId === base.fileId && row.preOpen.baseVersion === revision &&
|
|
381
|
-
Number.isSafeInteger(row.preOpen.checkoutId) && row.preOpen.checkoutId >= 0 && row.target === target && row.version === revision && row.fileId === base.fileId && row.base === base.fingerprint && row.origin === base.origin && row.repository === base.repository && row.opened === match[2])
|
|
382
|
-
found.add(match[2]);
|
|
383
|
-
}
|
|
384
|
-
catch { }
|
|
385
|
-
}
|
|
386
|
-
return found;
|
|
387
|
-
}
|
|
388
356
|
/** Another context's unresolved operation may still need this checkout's private view. */
|
|
389
357
|
checkoutReferenced(context, root = context.nativeCheckout?.root) {
|
|
390
358
|
const seen = new Set();
|
|
@@ -475,6 +443,17 @@ export class Workspace {
|
|
|
475
443
|
});
|
|
476
444
|
}
|
|
477
445
|
administrationByCaller(callerId) { const row = this.db.prepare('SELECT id FROM administration_requests WHERE caller_id=?').get(id(callerId)); return row ? this.administration(String(row.id)) : undefined; }
|
|
446
|
+
/** Synchronous metadata snapshot; consumers must not perform remote work in this callback. */
|
|
447
|
+
withAdministrationSnapshot(prefix, read) {
|
|
448
|
+
if (!/^[a-z]+\.$/.test(prefix))
|
|
449
|
+
fail('invalid', 'A literal administration namespace is required.');
|
|
450
|
+
return this.transaction(() => {
|
|
451
|
+
const rows = this.db.prepare("SELECT data FROM administration_requests WHERE json_extract(data,'$.operation') LIKE ? ORDER BY id").iterate(prefix + '%');
|
|
452
|
+
function* records() { for (const row of rows)
|
|
453
|
+
yield JSON.parse(String(row.data)); }
|
|
454
|
+
return read(records());
|
|
455
|
+
});
|
|
456
|
+
}
|
|
478
457
|
requestByCaller(callerId) { const row = this.db.prepare('SELECT id FROM requests WHERE caller_id=?').get(id(callerId)); return row ? this.request(String(row.id)) : undefined; }
|
|
479
458
|
administration(request) {
|
|
480
459
|
const row = this.db.prepare('SELECT data FROM administration_requests WHERE id=?').get(id(request));
|
|
@@ -702,7 +681,7 @@ export class Workspace {
|
|
|
702
681
|
const context = this.context(scope);
|
|
703
682
|
if (checkout.state !== 'verified' || stable(context.nativeCheckout) !== stable(checkout))
|
|
704
683
|
fail('binding', 'Native disposal ownership changed before retention.');
|
|
705
|
-
const
|
|
684
|
+
const active = { ...checkout, state: 'active' };
|
|
706
685
|
this.knownSnapshot(snapshot);
|
|
707
686
|
const saved = object(JSON.parse(readFileSync(this.artifacts.path(snapshot), 'utf8')));
|
|
708
687
|
if (snapshot.kind !== 'native' || saved.engine !== 'native-checkout-v1' || saved.source !== 'checkout' || stable(saved.checkout) !== stable(active) ||
|
package/package.json
CHANGED
|
@@ -3,9 +3,16 @@ import com.xebyte.headless.GhidraMCPHeadlessServer;
|
|
|
3
3
|
|
|
4
4
|
/** Preserve caller-selected names in the owned facade, including structure fields. */
|
|
5
5
|
class InsightHeadlessMain {
|
|
6
|
-
public static void main(String[] args) {
|
|
6
|
+
public static void main(String[] args) throws Exception {
|
|
7
7
|
insight.nativecheckout.InsightOfflineAuthenticator.install();
|
|
8
|
+
InsightWorkerLease.start();
|
|
8
9
|
NamingPolicy.getInstance().setStrictNamingEnforcement(false, "insight facade");
|
|
9
|
-
GhidraMCPHeadlessServer.main
|
|
10
|
+
// The steps of GhidraMCPHeadlessServer.main, keeping the instance so that owned helper scripts can run in-process.
|
|
11
|
+
GhidraMCPHeadlessServer server=new GhidraMCPHeadlessServer();
|
|
12
|
+
InsightOwnedScripts.bind(server);
|
|
13
|
+
try{server.launch(new ghidra.GhidraApplicationLayout(),args);}
|
|
14
|
+
catch(Exception failure){
|
|
15
|
+
System.err.println("Failed to launch headless server: "+failure.getMessage());failure.printStackTrace();System.exit(1);
|
|
16
|
+
}
|
|
10
17
|
}
|
|
11
18
|
}
|