@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
package/dist/src/research.js
CHANGED
|
@@ -4,6 +4,7 @@ import { inspectFunctions } from './function-inspection.js';
|
|
|
4
4
|
import { entryRequest } from './function-entries.js';
|
|
5
5
|
import { inspectAnchors } from './string-anchors.js';
|
|
6
6
|
import { fail, id, object, text, digest, fieldKey } from './model.js';
|
|
7
|
+
import { failUnresolved, unresolvedGuidance, unresolvedAdvice, unknownOutcome, ownerNext, cliPrefix } from './unresolved-guidance.js';
|
|
7
8
|
import { verifyMutation } from './mutation-effects.js';
|
|
8
9
|
import { transferResult } from './cross-results.js';
|
|
9
10
|
import { CliError } from '@eyeauras/cli-factory';
|
|
@@ -58,6 +59,16 @@ function pageResult(value, key, limit, offset) {
|
|
|
58
59
|
fail('partial', 'Paged result has inconsistent items, counts or selectors.');
|
|
59
60
|
return { result, items: result[key], total: Number(result.total) };
|
|
60
61
|
}
|
|
62
|
+
/** A native step the coordinator proves was never sent (only Update/check-in report this). */
|
|
63
|
+
const notSent = (error) => error instanceof CliError && error.code === 'coordinator.notSent';
|
|
64
|
+
/** A not-sent request keeps its memory diagnosis in its saved result, not only in the first response. */
|
|
65
|
+
export const memoryOf = (error) => {
|
|
66
|
+
// A recorded not-sent refusal keeps what its replay needs: the phase, the cause and the memory diagnosis.
|
|
67
|
+
const result = object(error instanceof CliError ? error.result ?? {} : {}), cause = result.cause && typeof result.cause === 'object' && !Array.isArray(result.cause) ? object(result.cause) : {};
|
|
68
|
+
return { ...(result.phase === 'update' || result.phase === 'checkin' ? { phase: result.phase } : {}),
|
|
69
|
+
...(typeof cause.code === 'string' && typeof cause.message === 'string' ? { cause: { code: cause.code, message: cause.message.slice(0, 1000) } } : {}),
|
|
70
|
+
...(result.memory === 'exhausted' ? { memory: 'exhausted', memoryCause: result.memoryCause } : {}) };
|
|
71
|
+
};
|
|
61
72
|
/** One ordered working context per tuple, shared by every transport through the Factory owner. */
|
|
62
73
|
export class Research {
|
|
63
74
|
workspace;
|
|
@@ -117,8 +128,10 @@ export class Research {
|
|
|
117
128
|
if (!acknowledged)
|
|
118
129
|
fail('invalid', 'Explicit --acknowledge-unknown-effects is required.');
|
|
119
130
|
const context = this.workspace.context(selected), requests = this.workspace.unresolved(selected);
|
|
120
|
-
if (context.nativeCheckout)
|
|
121
|
-
|
|
131
|
+
if (context.nativeCheckout) {
|
|
132
|
+
const guidance = unresolvedGuidance(this.workspace, selected);
|
|
133
|
+
fail('unsupported', 'A native unknown outcome is reconciled on its original project, not abandoned. ' + unresolvedAdvice(guidance), guidance);
|
|
134
|
+
}
|
|
122
135
|
const request = this.workspace.scopedRequest(selected, requestId);
|
|
123
136
|
if (request?.state === 'failed' && object(request.result ?? {}).state === 'abandoned')
|
|
124
137
|
return request.result;
|
|
@@ -144,35 +157,63 @@ export class Research {
|
|
|
144
157
|
const opened = (value) => { const result = object(value); return Object.fromEntries(['session', 'target', 'state', 'baseRevision', 'sharedRevision', 'pendingChanges'].filter(key => Object.hasOwn(result, key)).map(key => [key, result[key]])); };
|
|
145
158
|
const retained = (state) => ({ session: reserved.context.session, target, state, ...(callerId ? { requestId: callerId } : {}) });
|
|
146
159
|
const next = [['sessions', 'status', reserved.context.session, '--target', target], ['ghidra', 'open', '--session', reserved.context.session, '--target', target]];
|
|
147
|
-
const openingFailure = (error, state
|
|
148
|
-
|
|
149
|
-
|
|
160
|
+
const openingFailure = (error, state, reconciling = false) => {
|
|
161
|
+
const detail = error instanceof CliError && error.result && typeof error.result === 'object' ? error.result : undefined;
|
|
162
|
+
const guidance = reconciling ? unresolvedGuidance(this.workspace, { session: reserved.context.session, target }) : undefined;
|
|
163
|
+
// An outcome owned by another session sends the agent to that owner, never back into this same refusal.
|
|
164
|
+
const owner = guidance?.owner ?? (detail && detail.owner && typeof detail.owner === 'object' ? detail.owner : undefined), follow = owner ? ownerNext({ owner }) : next;
|
|
165
|
+
// A plain error outside reconciliation is a setup failure (for example a missing runtime path), not an outcome.
|
|
166
|
+
const plain = reconciling ? 'Ghidra open did not complete; the context is retained for reconciliation.' : 'Ghidra open could not set up its runtime: ' + (error instanceof Error ? error.message : String(error));
|
|
167
|
+
return new CliError((error instanceof CliError ? error.message : plain) + (guidance ? ' ' + unresolvedAdvice(guidance, true) : ''), {
|
|
168
|
+
code: error instanceof CliError ? error.code : reconciling ? 'coordinator.unknown' : 'coordinator.launch', result: { ...retained(state), ...(detail ? { detail } : {}), ...(guidance ? { guidance } : {}) },
|
|
169
|
+
next: error instanceof CliError && error.code === 'coordinator.migration' ? [['ghidra', 'migrate', '--target', target, '--dry-run'], ['ghidra', 'migrate', '--target', target], ...follow] :
|
|
170
|
+
// A refusal that names its own ways out keeps them first.
|
|
171
|
+
error instanceof CliError && error.next?.length ? [...error.next, ...follow] : follow
|
|
172
|
+
});
|
|
173
|
+
};
|
|
150
174
|
return this.ordered(reserved.context, async () => {
|
|
151
175
|
if (this.workspace.request(reserved.request.id).state === 'applied')
|
|
152
176
|
return opened(this.workspace.request(reserved.request.id).result);
|
|
153
|
-
|
|
177
|
+
// A replayed open that failed at setup reports that recorded failure before any new setup runs.
|
|
178
|
+
const prior = this.workspace.request(reserved.request.id), setup = object(object(prior.result ?? {}).setupFailure ?? {});
|
|
179
|
+
if (reserved.replay && prior.state === 'failed' && typeof setup.code === 'string')
|
|
180
|
+
throw new CliError(`This open failed before any work: ${String(setup.message)} Open again with a new request ID.`, { code: setup.code, result: retained('failed'), next });
|
|
181
|
+
let backend, reconciling = false;
|
|
154
182
|
try {
|
|
155
183
|
backend = await this.backend();
|
|
156
|
-
|
|
184
|
+
// Reconciliation acts only on a retained publication or this context's own unresolved requests. Without
|
|
185
|
+
// either it has nothing to do, so the open does not wait behind another context's merge in the target lane.
|
|
186
|
+
const selected = { session: reserved.context.session, target };
|
|
187
|
+
const held = this.workspace.activePublication(target);
|
|
188
|
+
if (held || this.workspace.unresolved(selected).length) {
|
|
189
|
+
reconciling = true;
|
|
190
|
+
await this.sharedOrder(target, () => this.reconcile(selected, backend, true));
|
|
191
|
+
}
|
|
157
192
|
}
|
|
158
193
|
catch (error) {
|
|
159
|
-
const request = this.workspace.request(reserved.request.id);
|
|
194
|
+
const request = this.workspace.request(reserved.request.id), failure = openingFailure(error, 'failed', reconciling);
|
|
195
|
+
// A setup failure (before any reconciliation) is a plain failure of this request: its replay reports it as such.
|
|
196
|
+
// Recovery guidance applies only when an unresolved outcome prompted reconciliation, not to a setup failure.
|
|
160
197
|
if (request.state === 'accepted')
|
|
161
|
-
this.workspace.recordRequest(request.id, 'failed', retained('blocked'));
|
|
162
|
-
throw openingFailure(error, this.workspace.request(request.id).state);
|
|
198
|
+
this.workspace.recordRequest(request.id, 'failed', { ...retained('blocked'), ...(!reconciling ? { setupFailure: { code: failure.code, message: failure.message } } : {}) });
|
|
199
|
+
throw openingFailure(error, this.workspace.request(request.id).state, reconciling);
|
|
163
200
|
}
|
|
164
201
|
const request = this.workspace.request(reserved.request.id);
|
|
165
202
|
if (request.state === 'applied')
|
|
166
203
|
return opened(request.result);
|
|
167
|
-
if (reserved.replay && request.state !== 'accepted')
|
|
168
|
-
|
|
204
|
+
if (reserved.replay && request.state !== 'accepted') {
|
|
205
|
+
const guidance = unresolvedGuidance(this.workspace, reserved.context);
|
|
206
|
+
throw new CliError('This open retains an unproved outcome; inspect the retained context before continuing.', { code: 'coordinator.unknown', result: retained(request.state), next: guidance.targetHeld ? ownerNext(guidance) : next });
|
|
207
|
+
}
|
|
169
208
|
const unresolved = this.workspace.unresolved(reserved.context).filter(other => other.id !== request.id);
|
|
170
209
|
if (unresolved.length) {
|
|
171
210
|
const result = { session: reserved.context.session, target, state: 'blocked' };
|
|
172
211
|
this.workspace.recordRequest(request.id, 'failed', result);
|
|
173
|
-
const close = unresolved.find(other => other.operation === 'ghidra.close');
|
|
174
|
-
|
|
175
|
-
|
|
212
|
+
const close = unresolved.find(other => other.operation === 'ghidra.close'), guidance = unresolvedGuidance(this.workspace, reserved.context);
|
|
213
|
+
// An unfinished close is finished by its own command; anything else waits for a reconciliation that can prove it.
|
|
214
|
+
const advice = close ? `Finish it with \`${cliPrefix(this.workspace)} ghidra close --session ${reserved.context.session} --target ${target} --request-id ${close.callerId ?? close.id}\`; the saved project and its journals are retained.` : unresolvedAdvice(guidance, true);
|
|
215
|
+
throw new CliError('This context retains an unproved effect; continuation did not start a second operation. ' + advice, {
|
|
216
|
+
code: 'coordinator.blocked', result: { ...result, ...guidance }, next: close ? [['ghidra', 'close', '--session', reserved.context.session, '--target', target, '--request-id', close.callerId ?? close.id]] : ownerNext(guidance)
|
|
176
217
|
});
|
|
177
218
|
}
|
|
178
219
|
this.workspace.startRequest(request.id);
|
|
@@ -430,7 +471,7 @@ export class Research {
|
|
|
430
471
|
if (!backend.latest || !backend.fields)
|
|
431
472
|
fail('configuration', 'Resolution requires verified shared-state inspection.');
|
|
432
473
|
if (this.workspace.activePublication(selected.target) || this.workspace.model(selected.target).state === 'unknown')
|
|
433
|
-
|
|
474
|
+
failUnresolved(this.workspace, selected, 'Shared publication outcome must be reconciled before resolving a field.');
|
|
434
475
|
const shared = await backend.latest(selected.target);
|
|
435
476
|
this.workspace.observeShared(selected.target, shared.revision, shared.snapshot);
|
|
436
477
|
const current = (await backend.fields(shared.snapshot, [previous]))[fieldKey(previous)];
|
|
@@ -481,8 +522,19 @@ export class Research {
|
|
|
481
522
|
};
|
|
482
523
|
return this.ordered(selected, () => resolution ? this.sharedOrder(selected.target, action) : action());
|
|
483
524
|
}
|
|
525
|
+
/** A worker parked by native Update/check-in is reopened or stopped before the command ends, whatever its outcome. */
|
|
526
|
+
async resuming(selected, action) {
|
|
527
|
+
try {
|
|
528
|
+
return await action();
|
|
529
|
+
}
|
|
530
|
+
finally {
|
|
531
|
+
const backend = await this.backend().catch(() => undefined);
|
|
532
|
+
await backend?.resumeParked?.(selected).catch(() => { });
|
|
533
|
+
}
|
|
534
|
+
}
|
|
484
535
|
async sharedOrder(target, action) {
|
|
485
|
-
|
|
536
|
+
// The wait is attributed separately: a target lane held by another context's merge is not this command's work.
|
|
537
|
+
const key = 'shared:' + target, previous = this.tasks.get(key), task = timed('facade.queue', 'shared', async () => { await previous?.catch(() => { }); }).then(action);
|
|
486
538
|
this.tasks.set(key, task);
|
|
487
539
|
try {
|
|
488
540
|
return await task;
|
|
@@ -737,9 +789,13 @@ export class Research {
|
|
|
737
789
|
}
|
|
738
790
|
}
|
|
739
791
|
}
|
|
740
|
-
|
|
792
|
+
/**
|
|
793
|
+
* `close` releases the working copy after publication; otherwise the context continues at the published version.
|
|
794
|
+
* It only chooses what follows a publication, so it is not part of the request identity.
|
|
795
|
+
*/
|
|
796
|
+
async merge(selected, callerId, close = false) {
|
|
741
797
|
const reserved = this.workspace.reserveRequest(selected, 'ghidra.merge', {}, callerId);
|
|
742
|
-
return this.ordered(selected, () => this.sharedOrder(selected.target, async () => {
|
|
798
|
+
return this.ordered(selected, () => this.resuming(selected, () => this.sharedOrder(selected.target, async () => {
|
|
743
799
|
let request = this.workspace.request(reserved.request.id), backend;
|
|
744
800
|
if (reserved.replay && ['running', 'unknown'].includes(request.state)) {
|
|
745
801
|
backend = await this.backend();
|
|
@@ -752,7 +808,7 @@ export class Research {
|
|
|
752
808
|
fail(request.state === 'failed' ? 'conflict' : 'unknown', 'This merge retains its recorded outcome; it is never checked in blindly again.', request.result);
|
|
753
809
|
}
|
|
754
810
|
if (this.workspace.activePublication(selected.target) || this.workspace.model(selected.target).state === 'unknown')
|
|
755
|
-
|
|
811
|
+
failUnresolved(this.workspace, selected, 'Shared publication is unresolved; every working copy is retained.');
|
|
756
812
|
backend ??= await this.backend();
|
|
757
813
|
if (backend.nativeEngine !== 'native-checkout-v1' || !backend.updateNative || !backend.publishNative || !backend.dropNative || !backend.finishEmptyNative)
|
|
758
814
|
fail('configuration', 'The primary CLI requires native checkout/Update/check-in; scalar fallback is disabled.');
|
|
@@ -769,7 +825,9 @@ export class Research {
|
|
|
769
825
|
fail('conflict', 'Native conflict preserves the original working copy and checkout.', result);
|
|
770
826
|
}
|
|
771
827
|
if (update.state === 'empty') {
|
|
772
|
-
|
|
828
|
+
// Nothing to publish: a continuing context keeps its checkout exactly as Update left it.
|
|
829
|
+
if (close || !backend.continueNative)
|
|
830
|
+
await backend.finishEmptyNative(selected, request.id);
|
|
773
831
|
const current = this.workspace.context(selected);
|
|
774
832
|
const result = { ...selected, state: count(context) ? 'merged' : 'empty', applied: 0, pendingChanges: 0, sharedRevision: revision(update.revision), engine: 'ghidra-native' };
|
|
775
833
|
this.workspace.completeSavedRequest(selected, request.id, current.generation, {}, result);
|
|
@@ -790,25 +848,43 @@ export class Research {
|
|
|
790
848
|
}
|
|
791
849
|
const result = { ...selected, state: 'merged', sharedRevision: revision(published.revision), applied: count(context), pendingChanges: 0, engine: 'ghidra-native' };
|
|
792
850
|
this.workspace.finishPublication(publication.id, published.revision, result, published.snapshot);
|
|
851
|
+
// The publication is applied. Continuing is an optimization: when the kept checkout cannot be proved
|
|
852
|
+
// unchanged at the published version it is disposed exactly as before, and the next open checks out anew.
|
|
853
|
+
if (!close && backend.continueNative && published.observation)
|
|
854
|
+
try {
|
|
855
|
+
if (await backend.continueNative(selected, published.observation))
|
|
856
|
+
return result;
|
|
857
|
+
}
|
|
858
|
+
catch { /* Disposal below. */ }
|
|
793
859
|
await backend.dropNative(selected);
|
|
794
860
|
return result;
|
|
795
861
|
}
|
|
796
862
|
catch (error) {
|
|
797
863
|
const state = this.workspace.request(request.id).state;
|
|
864
|
+
// A native Update or check-in that provably never left this process: nothing was published.
|
|
865
|
+
if (notSent(error) && state !== 'applied' && state !== 'failed') {
|
|
866
|
+
const result = { ...selected, state: 'not_published', applied: 0, reason: 'not_sent', engine: 'ghidra-native', ...memoryOf(error) };
|
|
867
|
+
if (publication && ['preparing', 'commit_intent'].includes(this.workspace.publication(publication.id).state))
|
|
868
|
+
this.workspace.rejectPublication(publication.id, result);
|
|
869
|
+
else
|
|
870
|
+
this.workspace.recordRequest(request.id, 'failed', result);
|
|
871
|
+
throw error;
|
|
872
|
+
}
|
|
798
873
|
if (state !== 'applied' && state !== 'failed') {
|
|
799
874
|
// Proved empty-disposal retention already committed its terminal request atomically above.
|
|
800
875
|
// An uncertain release or any publication still follows the unknown-outcome path below.
|
|
801
876
|
if (publication && ['commit_intent', 'unknown'].includes(this.workspace.publication(publication.id).state))
|
|
802
877
|
this.workspace.unknownPublication(publication.id, { state: 'unknown', engine: 'ghidra-native' });
|
|
803
878
|
this.workspace.recordRequest(request.id, 'unknown', { ...selected, state: 'unknown', engine: 'ghidra-native' });
|
|
879
|
+
throw unknownOutcome(this.workspace, selected, error);
|
|
804
880
|
}
|
|
805
881
|
throw error;
|
|
806
882
|
}
|
|
807
|
-
}));
|
|
883
|
+
})));
|
|
808
884
|
}
|
|
809
885
|
async refresh(selected, callerId) {
|
|
810
886
|
const reserved = this.workspace.reserveRequest(selected, 'ghidra.refresh', {}, callerId);
|
|
811
|
-
return this.ordered(selected, () => this.sharedOrder(selected.target, async () => {
|
|
887
|
+
return this.ordered(selected, () => this.resuming(selected, () => this.sharedOrder(selected.target, async () => {
|
|
812
888
|
const request = this.workspace.request(reserved.request.id);
|
|
813
889
|
if (reserved.replay && request.state !== 'accepted') {
|
|
814
890
|
if (request.state === 'applied')
|
|
@@ -816,7 +892,7 @@ export class Research {
|
|
|
816
892
|
fail(request.state === 'failed' ? 'conflict' : 'unknown', 'Native Update retains its recorded outcome; its saved checkout is preserved.', request.result);
|
|
817
893
|
}
|
|
818
894
|
if (this.workspace.activePublication(selected.target) || this.workspace.model(selected.target).state === 'unknown')
|
|
819
|
-
|
|
895
|
+
failUnresolved(this.workspace, selected, 'Shared publication requires reconciliation before Update.');
|
|
820
896
|
const backend = await this.backend();
|
|
821
897
|
if (backend.nativeEngine !== 'native-checkout-v1' || !backend.updateNative)
|
|
822
898
|
fail('configuration', 'Native Update is required; scalar refresh fallback is disabled.');
|
|
@@ -837,11 +913,14 @@ export class Research {
|
|
|
837
913
|
return result;
|
|
838
914
|
}
|
|
839
915
|
catch (error) {
|
|
840
|
-
if (!['applied', 'failed'].includes(this.workspace.request(request.id).state))
|
|
841
|
-
this.workspace.recordRequest(request.id, 'unknown', { ...selected, state: 'unknown', engine: 'ghidra-native' });
|
|
916
|
+
if (!['applied', 'failed'].includes(this.workspace.request(request.id).state)) {
|
|
917
|
+
this.workspace.recordRequest(request.id, notSent(error) ? 'failed' : 'unknown', notSent(error) ? { ...selected, state: 'not_updated', receivedChanges: 0, reason: 'not_sent', engine: 'ghidra-native', ...memoryOf(error) } : { ...selected, state: 'unknown', engine: 'ghidra-native' });
|
|
918
|
+
if (!notSent(error))
|
|
919
|
+
throw unknownOutcome(this.workspace, selected, error);
|
|
920
|
+
}
|
|
842
921
|
throw error;
|
|
843
922
|
}
|
|
844
|
-
}));
|
|
923
|
+
})));
|
|
845
924
|
}
|
|
846
925
|
async mutate(selected, operation, parameters, verify, callerId, verifySaved) {
|
|
847
926
|
const reserved = this.workspace.reserveRequest(selected, operation, parameters, callerId);
|
package/dist/src/server.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { CommandContext } from '@eyeauras/cli-factory';
|
|
2
2
|
import { type ChildProcess } from 'node:child_process';
|
|
3
3
|
import { type NativeInputs } from './native-inputs.js';
|
|
4
|
+
import { NativeServices } from './native-service.js';
|
|
4
5
|
export interface ServerBinding {
|
|
5
6
|
mode: 'local' | 'external';
|
|
6
7
|
origin: string;
|
|
@@ -21,7 +22,6 @@ interface LocalServer extends ServerBinding {
|
|
|
21
22
|
phase: 'seeded' | 'initialized' | 'running' | 'stopped';
|
|
22
23
|
pid?: number;
|
|
23
24
|
}
|
|
24
|
-
/** A proven different process birth retires only the saved receipt, never the PID. */
|
|
25
25
|
export declare function retireReusedServer(directory: string, control: string, local: LocalServer): Promise<boolean>;
|
|
26
26
|
/** Own local startup; external profiles connect without taking ownership of their server. */
|
|
27
27
|
export declare class GhidraServer {
|
|
@@ -32,15 +32,47 @@ export declare class GhidraServer {
|
|
|
32
32
|
constructor(directory: string, inputs: NativeInputs, c: CommandContext, state?: {
|
|
33
33
|
initializing?: Promise<ServerBinding>;
|
|
34
34
|
child?: ChildProcess;
|
|
35
|
+
services?: NativeServices;
|
|
36
|
+
servicesClosed?: boolean;
|
|
35
37
|
});
|
|
36
38
|
fork(c: CommandContext): GhidraServer;
|
|
37
39
|
private root;
|
|
38
40
|
private run;
|
|
41
|
+
/**
|
|
42
|
+
* A helper that failed for lack of memory keeps its failure code (and so its sent/unknown meaning), but is
|
|
43
|
+
* reported as such: on a loaded machine it is retried once memory is available, not treated as a defect.
|
|
44
|
+
*/
|
|
45
|
+
private memoryExhausted;
|
|
46
|
+
/**
|
|
47
|
+
* True when no process that could still write a native checkout journal exists: every one-shot helper and publisher
|
|
48
|
+
* service launched for this profile has proved its exit, except publisher services this owner still tracks as
|
|
49
|
+
* serving. Those receive requests only from callers holding their target's lane, so none of them can be working on
|
|
50
|
+
* a request whose lane the caller holds. Profiles have one owner process; records of any other owner must be ended.
|
|
51
|
+
*/
|
|
52
|
+
nativeWritersSettled(): Promise<boolean>;
|
|
53
|
+
private runHelper;
|
|
54
|
+
/**
|
|
55
|
+
* A cancelled one-shot helper whose process provably never started: no supervisor record at all, or a record
|
|
56
|
+
* without a PID that never left its pre-spawn phases. Anything else may have run and keeps its cancellation.
|
|
57
|
+
*/
|
|
58
|
+
private neverSpawned;
|
|
59
|
+
/**
|
|
60
|
+
* Hot native operations run in a long-lived service of the same trusted helper code with the role's own
|
|
61
|
+
* credentials; a service that cannot be used leaves the one-shot helper in charge (nothing was sent).
|
|
62
|
+
*/
|
|
63
|
+
private viaService;
|
|
64
|
+
/** Owner disposal: close the services for good (in-flight requests end with their termination outcome). */
|
|
65
|
+
stopServices(): Promise<void>;
|
|
66
|
+
/** Maintenance: stop idle services now; false while a service is still running a request. */
|
|
67
|
+
stopIdleServices(): Promise<boolean>;
|
|
39
68
|
credentials(binding: ServerBinding, role: 'reader' | 'publisher'): Promise<Record<string, string>>;
|
|
40
69
|
fields(snapshot: string, selectors: string): Promise<Record<string, unknown>>;
|
|
41
70
|
nativeCheckout(binding: ServerBinding, request: Record<string, unknown>): Promise<Record<string, unknown>>;
|
|
71
|
+
private nativeCheckoutCall;
|
|
42
72
|
nativeMigration(binding: ServerBinding, request: Record<string, unknown>): Promise<Record<string, unknown>>;
|
|
73
|
+
private nativeMigrationCall;
|
|
43
74
|
nativeRead(binding: ServerBinding, request: Record<string, unknown>): Promise<Record<string, unknown>>;
|
|
75
|
+
private nativeReadCall;
|
|
44
76
|
inspect(snapshot: string, request: string): Promise<Record<string, unknown>>;
|
|
45
77
|
sdkFile(operation: string, p: Record<string, unknown>): Promise<Record<string, unknown>>;
|
|
46
78
|
traceInspect(snapshot: string): Promise<Record<string, unknown>>;
|
|
@@ -52,7 +84,12 @@ export declare class GhidraServer {
|
|
|
52
84
|
initialImport(root: string): Promise<Record<string, unknown>>;
|
|
53
85
|
initialPublication(binding: ServerBinding, root: string, operation?: 'stage' | 'verify-stage' | 'promote' | 'verify'): Promise<Record<string, unknown>>;
|
|
54
86
|
recoverPublication(binding: ServerBinding, path: string, snapshot: string, expected: number, request: string, journal: string, sourceSha: string): Promise<Record<string, unknown>>;
|
|
87
|
+
/**
|
|
88
|
+
* Repository roles of an owned local server are fixed at initialization and canonical ACL changes are refused,
|
|
89
|
+
* so one verification per authenticated server process suffices. Every native operation re-checks its role.
|
|
90
|
+
*/
|
|
55
91
|
private authority;
|
|
92
|
+
private verifyAuthority;
|
|
56
93
|
ensure(): Promise<ServerBinding>;
|
|
57
94
|
private initialize;
|
|
58
95
|
private identity;
|
package/dist/src/server.js
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import { ghidraBudget } from './budgets.js';
|
|
2
2
|
import { CliError } from '@eyeauras/cli-factory';
|
|
3
|
-
import { launchProcess, terminateProcess, processStatus } from './tool-runtime/supervisor.js';
|
|
3
|
+
import { launchProcess, terminateProcess, processStatus, listProcesses } from './tool-runtime/supervisor.js';
|
|
4
4
|
import { processIdentity } from './tool-runtime/identity.js';
|
|
5
5
|
import { runTool } from './tool-runtime/run.js';
|
|
6
6
|
import { randomUUID, randomBytes, createHash } from 'node:crypto';
|
|
7
|
-
import { readFile, mkdir, open, rename, readdir, stat, chmod, realpath } from 'node:fs/promises';
|
|
7
|
+
import { readFile, mkdir, open, rename, readdir, stat, chmod, realpath, rm } from 'node:fs/promises';
|
|
8
8
|
import { basename, delimiter, dirname, join, resolve } from 'node:path';
|
|
9
9
|
import { createServer } from 'node:net';
|
|
10
10
|
import { setTimeout as delay } from 'node:timers/promises';
|
|
11
11
|
import { fail, object, stable, text, digest } from './model.js';
|
|
12
12
|
import { nativeHelpers, nativeJvmDirectories, nativeExtensionArguments } from './native-inputs.js';
|
|
13
13
|
import { parseDomainJson } from './json.js';
|
|
14
|
+
import { timed } from './internal-timing.js';
|
|
15
|
+
import { NativeServices } from './native-service.js';
|
|
14
16
|
const live = (pid) => {
|
|
15
17
|
try {
|
|
16
18
|
process.kill(pid, 0);
|
|
@@ -23,6 +25,8 @@ const live = (pid) => {
|
|
|
23
25
|
}
|
|
24
26
|
};
|
|
25
27
|
/** A proven different process birth retires only the saved receipt, never the PID. */
|
|
28
|
+
/** A stopped or retired server's role proof never applies to another launch. */
|
|
29
|
+
async function forgetAuthority(directory) { await rm(join(directory, 'server', 'authority.json'), { force: true }); }
|
|
26
30
|
export async function retireReusedServer(directory, control, local) {
|
|
27
31
|
if (!local.pid || !local.toolProcessId)
|
|
28
32
|
return false;
|
|
@@ -37,8 +41,23 @@ export async function retireReusedServer(directory, control, local) {
|
|
|
37
41
|
delete local.pid;
|
|
38
42
|
delete local.toolProcessId;
|
|
39
43
|
await durable(join(directory, 'server', 'local.json'), local);
|
|
44
|
+
await forgetAuthority(directory);
|
|
40
45
|
return true;
|
|
41
46
|
}
|
|
47
|
+
/** Native operation names are code-defined; anything else is reported as a fixed category. */
|
|
48
|
+
function operationLabel(value) { return typeof value === 'string' && /^[a-z][a-z-]{0,39}$/.test(value) ? value : 'other'; }
|
|
49
|
+
/** Shared interpretation of one native helper result, from a one-shot helper or a service. */
|
|
50
|
+
/** JVM and native allocation failures: launch-time heap reservation, Java heap, native threads and commit limits. */
|
|
51
|
+
const outOfMemoryText = /OutOfMemoryError|Could not reserve enough space|insufficient memory for the Java Runtime|Native memory allocation \((m?malloc|mmap)\) failed|unable to create (new )?native thread|paging file is too small|errno=1455|os::commit_memory\(.*\) failed/i;
|
|
52
|
+
/** Roles of the processes that can write native checkout journals: the one-shot helper and the publisher service. */
|
|
53
|
+
const nativeWriterRoles = ['native-checkout', 'native-publisher'];
|
|
54
|
+
function interpret(result) {
|
|
55
|
+
if (result.state === 'unknown' && typeof result.reason === 'string')
|
|
56
|
+
fail(result.code === 'migration' ? 'migration' : 'unknown', result.reason, { diagnostic: result.diagnostic });
|
|
57
|
+
if (result.error || result.state === 'failed')
|
|
58
|
+
fail('authorization', 'Native server operation did not establish its outcome.');
|
|
59
|
+
return result;
|
|
60
|
+
}
|
|
42
61
|
async function durable(path, value) {
|
|
43
62
|
const temporary = path + '.new-' + randomUUID(), handle = await open(temporary, 'wx', 0o600);
|
|
44
63
|
try {
|
|
@@ -92,11 +111,62 @@ export class GhidraServer {
|
|
|
92
111
|
fork(c) { return new GhidraServer(this.directory, this.inputs, c, this.state); }
|
|
93
112
|
root() { return join(this.directory, 'server'); }
|
|
94
113
|
async run(label, main, args, environment = {}, input, acceptedCodes = [0], timeoutMilliseconds = 120000) {
|
|
114
|
+
// Each call is one cold helper JVM; its span attributes launch, Ghidra initialization and the native operation.
|
|
115
|
+
return timed('native.helper', label, () => this.runHelper(label, main, args, environment, input, acceptedCodes, timeoutMilliseconds).catch(error => this.memoryExhausted(error)));
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* A helper that failed for lack of memory keeps its failure code (and so its sent/unknown meaning), but is
|
|
119
|
+
* reported as such: on a loaded machine it is retried once memory is available, not treated as a defect.
|
|
120
|
+
*/
|
|
121
|
+
async memoryExhausted(error) {
|
|
122
|
+
if (!(error instanceof CliError) || error.code === 'tool.notSent')
|
|
123
|
+
throw error;
|
|
124
|
+
const result = object(error.result ?? {});
|
|
125
|
+
if (result.memory === 'exhausted')
|
|
126
|
+
throw error;
|
|
127
|
+
// Only this call's own output: the one-shot helper's stdout/stderr (HotSpot prints its fatal memory banner to
|
|
128
|
+
// stdout), or the service's output since this request was sent.
|
|
129
|
+
const evidence = [result.diagnostic, result.reason, result.stderr, result.stdout].filter(value => typeof value === 'string').join('\n');
|
|
130
|
+
if (!outOfMemoryText.test(evidence))
|
|
131
|
+
throw error;
|
|
132
|
+
// The most specific line names the cause (for example the commit failure), not only the generic banner.
|
|
133
|
+
const lines = evidence.split(/\r?\n/).map(line => line.replace(/^[#\s]+/, '').trim()).filter(line => outOfMemoryText.test(line));
|
|
134
|
+
const cause = (lines.find(line => /paging file|commit_memory|errno=/i.test(line)) ?? lines[0] ?? '').slice(0, 300);
|
|
135
|
+
throw new CliError(`The native helper ran out of memory (${cause}). Free memory or run fewer concurrent sessions.`, { code: error.code, cause: error, result: { ...result, memory: 'exhausted', reason: 'out_of_memory', memoryCause: cause } });
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* True when no process that could still write a native checkout journal exists: every one-shot helper and publisher
|
|
139
|
+
* service launched for this profile has proved its exit, except publisher services this owner still tracks as
|
|
140
|
+
* serving. Those receive requests only from callers holding their target's lane, so none of them can be working on
|
|
141
|
+
* a request whose lane the caller holds. Profiles have one owner process; records of any other owner must be ended.
|
|
142
|
+
*/
|
|
143
|
+
async nativeWritersSettled() {
|
|
144
|
+
const serving = this.state.services?.servingPids('publisher') ?? new Set();
|
|
145
|
+
for (const record of await listProcesses(this.c.appArguments.AppDataDirectory, { tool: 'ghidra' })) {
|
|
146
|
+
if (!nativeWriterRoles.includes(record.role) || ['exited', 'failed'].includes(record.state))
|
|
147
|
+
continue;
|
|
148
|
+
if (record.role === 'native-publisher' && record.ownerPid === process.pid && record.state === 'running' && record.pid !== undefined && serving.has(record.pid))
|
|
149
|
+
continue;
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
152
|
+
return true;
|
|
153
|
+
}
|
|
154
|
+
async runHelper(label, main, args, environment, input, acceptedCodes, timeoutMilliseconds) {
|
|
95
155
|
const root = join(this.root(), 'calls', label + '-' + randomUUID());
|
|
96
156
|
await mkdir(root, { recursive: true, mode: 0o700 });
|
|
97
157
|
const classes = await nativeHelpers(this.directory, this.inputs, this.c);
|
|
98
|
-
|
|
99
|
-
|
|
158
|
+
if (this.c.signal.aborted)
|
|
159
|
+
throw new CliError('Native operation was cancelled before it was sent.', { code: 'tool.notSent' });
|
|
160
|
+
let output;
|
|
161
|
+
try {
|
|
162
|
+
output = await runTool(this.c, { tool: 'ghidra', role: label, installation: this.inputs.fingerprint, executable: this.inputs.java, arguments: ['-Djava.awt.headless=true', '-Dghidra.home=' + this.inputs.ghidraHome,
|
|
163
|
+
...nativeJvmDirectories(root), ...nativeExtensionArguments(this.inputs), '-cp', classes + delimiter + this.inputs.classpath, main, ...args], cwd: root, environment, input, acceptedCodes, timeoutMs: timeoutMilliseconds, maxOutputBytes: 1024 * 1024 });
|
|
164
|
+
}
|
|
165
|
+
catch (error) {
|
|
166
|
+
if (await this.neverSpawned(error))
|
|
167
|
+
throw new CliError('Native operation was cancelled before it was sent.', { code: 'tool.notSent' });
|
|
168
|
+
throw error;
|
|
169
|
+
}
|
|
100
170
|
let result;
|
|
101
171
|
try {
|
|
102
172
|
result = object(parseDomainJson(output.stdout));
|
|
@@ -104,12 +174,57 @@ export class GhidraServer {
|
|
|
104
174
|
catch {
|
|
105
175
|
fail('malformed', 'Native server operation returned malformed content.');
|
|
106
176
|
}
|
|
107
|
-
|
|
108
|
-
fail(result.code === 'migration' ? 'migration' : 'unknown', result.reason, { diagnostic: result.diagnostic });
|
|
109
|
-
if (result.error || result.state === 'failed')
|
|
110
|
-
fail('authorization', 'Native server operation did not establish its outcome.');
|
|
111
|
-
return result;
|
|
177
|
+
return interpret(result);
|
|
112
178
|
}
|
|
179
|
+
/**
|
|
180
|
+
* A cancelled one-shot helper whose process provably never started: no supervisor record at all, or a record
|
|
181
|
+
* without a PID that never left its pre-spawn phases. Anything else may have run and keeps its cancellation.
|
|
182
|
+
*/
|
|
183
|
+
async neverSpawned(error) {
|
|
184
|
+
if (!(error instanceof CliError))
|
|
185
|
+
return error?.name === 'AbortError';
|
|
186
|
+
if (error.code !== 'tool.cancelled')
|
|
187
|
+
return false;
|
|
188
|
+
const id = object(error.result ?? {}).process;
|
|
189
|
+
if (typeof id !== 'string' || !/^[a-f0-9-]{36}$/.test(id))
|
|
190
|
+
return false;
|
|
191
|
+
try {
|
|
192
|
+
const record = object(JSON.parse(await readFile(join(this.c.appArguments.AppDataDirectory, 'runtime', 'processes', id + '.json'), 'utf8')));
|
|
193
|
+
return record.pid === undefined && ['reserved', 'preflight_failed', 'spawn_failed'].includes(String(record.phase));
|
|
194
|
+
}
|
|
195
|
+
catch (failure) {
|
|
196
|
+
return failure.code === 'ENOENT';
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Hot native operations run in a long-lived service of the same trusted helper code with the role's own
|
|
201
|
+
* credentials; a service that cannot be used leaves the one-shot helper in charge (nothing was sent).
|
|
202
|
+
*/
|
|
203
|
+
async viaService(role, label, main, requestFile, binding, timeoutMilliseconds) {
|
|
204
|
+
const credentials = await this.credentials(binding, role);
|
|
205
|
+
const key = digest({ origin: binding.origin, repository: binding.repository, user: credentials.GHIDRA_SERVER_USER, secret: role === 'reader' ? binding.readerSecret : binding.publisherSecret, runtime: this.inputs.fingerprint });
|
|
206
|
+
// After owner disposal no new service starts; such a late request runs as a one-shot helper.
|
|
207
|
+
const services = this.state.servicesClosed ? undefined : this.state.services ??= new NativeServices();
|
|
208
|
+
const value = await services?.call(role, key, async () => {
|
|
209
|
+
const root = join(this.root(), 'services', role + '-' + randomUUID());
|
|
210
|
+
const classes = await nativeHelpers(this.directory, this.inputs, this.c);
|
|
211
|
+
return { directory: this.c.appArguments.AppDataDirectory, installation: this.inputs.fingerprint, executable: this.inputs.java, root,
|
|
212
|
+
arguments: ['-Djava.awt.headless=true', '-Dghidra.home=' + this.inputs.ghidraHome, ...nativeJvmDirectories(root), ...nativeExtensionArguments(this.inputs), '-cp', classes + delimiter + this.inputs.classpath, 'InsightNativeService', role],
|
|
213
|
+
environment: { PATH: this.c.environment.PATH ?? process.env.PATH, HOME: root, TMPDIR: root, ...(process.platform === 'win32' ? { SystemRoot: process.env.SystemRoot, WINDIR: process.env.WINDIR, ComSpec: process.env.ComSpec, TEMP: root, TMP: root, USERPROFILE: root, LOCALAPPDATA: root, APPDATA: root } : {}), ...credentials } };
|
|
214
|
+
}, requestFile, timeoutMilliseconds, this.c.signal);
|
|
215
|
+
if (value === undefined)
|
|
216
|
+
return this.run(label, main, [requestFile], credentials, undefined, [0], timeoutMilliseconds);
|
|
217
|
+
try {
|
|
218
|
+
return interpret(object(value));
|
|
219
|
+
}
|
|
220
|
+
catch (error) {
|
|
221
|
+
return this.memoryExhausted(error);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
/** Owner disposal: close the services for good (in-flight requests end with their termination outcome). */
|
|
225
|
+
async stopServices() { this.state.servicesClosed = true; const services = this.state.services; this.state.services = undefined; await services?.stop(); }
|
|
226
|
+
/** Maintenance: stop idle services now; false while a service is still running a request. */
|
|
227
|
+
async stopIdleServices() { return await this.state.services?.stopIdle() ?? true; }
|
|
113
228
|
async credentials(binding, role) {
|
|
114
229
|
const url = new URL(binding.origin);
|
|
115
230
|
return { GHIDRA_SERVER_HOST: url.hostname, GHIDRA_SERVER_PORT: url.port || '13100',
|
|
@@ -120,13 +235,24 @@ export class GhidraServer {
|
|
|
120
235
|
return this.run('snapshot-fields', 'insight.nativecheckout.InsightSnapshotFields', [snapshot, selectors]);
|
|
121
236
|
}
|
|
122
237
|
async nativeCheckout(binding, request) {
|
|
238
|
+
return timed('native.call', 'checkout.' + operationLabel(request.operation), () => this.nativeCheckoutCall(binding, request));
|
|
239
|
+
}
|
|
240
|
+
async nativeCheckoutCall(binding, request) {
|
|
123
241
|
const root = join(this.root(), 'native-calls', randomUUID());
|
|
124
242
|
await mkdir(root, { recursive: true, mode: 0o700 });
|
|
125
243
|
const input = join(root, 'request.json');
|
|
126
244
|
await durable(input, request);
|
|
127
|
-
|
|
245
|
+
try {
|
|
246
|
+
return await this.viaService('publisher', 'native-checkout', 'InsightNativeCheckout', input, binding, ghidraBudget(this.c.profile.values, 'save'));
|
|
247
|
+
}
|
|
248
|
+
catch (error) {
|
|
249
|
+
return this.memoryExhausted(error);
|
|
250
|
+
}
|
|
128
251
|
}
|
|
129
252
|
async nativeMigration(binding, request) {
|
|
253
|
+
return timed('native.call', 'migration.' + operationLabel(request.operation), () => this.nativeMigrationCall(binding, request));
|
|
254
|
+
}
|
|
255
|
+
async nativeMigrationCall(binding, request) {
|
|
130
256
|
const root = join(this.root(), 'migration-calls', randomUUID());
|
|
131
257
|
await mkdir(root, { recursive: true, mode: 0o700 });
|
|
132
258
|
const input = join(root, 'request.json');
|
|
@@ -134,11 +260,14 @@ export class GhidraServer {
|
|
|
134
260
|
return this.run('native-migration', 'InsightNativeMigration', [input], ['snapshot', 'snapshots', 'quiescence'].includes(String(request.operation)) ? {} : await this.credentials(binding, 'publisher'), undefined, [0], ghidraBudget(this.c.profile.values, 'save'));
|
|
135
261
|
}
|
|
136
262
|
async nativeRead(binding, request) {
|
|
263
|
+
return timed('native.call', 'read.' + operationLabel(request.operation), () => this.nativeReadCall(binding, request));
|
|
264
|
+
}
|
|
265
|
+
async nativeReadCall(binding, request) {
|
|
137
266
|
const root = join(this.root(), 'native-reads', randomUUID());
|
|
138
267
|
await mkdir(root, { recursive: true, mode: 0o700 });
|
|
139
268
|
const input = join(root, 'request.json');
|
|
140
269
|
await durable(input, { ...request, repository: binding.repository });
|
|
141
|
-
return this.
|
|
270
|
+
return this.viaService('reader', 'native-read', 'InsightNativeRead', input, binding, ghidraBudget(this.c.profile.values, 'save'));
|
|
142
271
|
}
|
|
143
272
|
async inspect(snapshot, request) { return this.run('snapshot-inspect', 'insight.nativecheckout.InsightSnapshotInspect', [snapshot, request]); }
|
|
144
273
|
async sdkFile(operation, p) {
|
|
@@ -277,7 +406,26 @@ export class GhidraServer {
|
|
|
277
406
|
return this.run('recover-publication', 'db.InsightPublicationRecovery', [binding.repository, path, snapshot, String(expected), 'insight merge ' + request, journal, sourceSha], { ...await this.credentials(binding, 'reader'), INSIGHT_PUBLISHER_USER: binding.publisherUser,
|
|
278
407
|
INSIGHT_PUBLISHER_PASSWORD: await this.c.secrets.require(binding.publisherSecret) });
|
|
279
408
|
}
|
|
409
|
+
/**
|
|
410
|
+
* Repository roles of an owned local server are fixed at initialization and canonical ACL changes are refused,
|
|
411
|
+
* so one verification per authenticated server process suffices. Every native operation re-checks its role.
|
|
412
|
+
*/
|
|
280
413
|
async authority(binding) {
|
|
414
|
+
const local = binding.mode === 'local' && Number.isSafeInteger(binding.pid) ? binding : undefined;
|
|
415
|
+
const receipt = join(this.root(), 'authority.json');
|
|
416
|
+
// The launch identity (supervisor record) distinguishes a restarted server even when its PID is reused.
|
|
417
|
+
const proof = local?.toolProcessId ? { schema: 2, instance: local.instance, pid: local.pid, toolProcessId: local.toolProcessId, repository: local.repository, readerUser: local.readerUser, publisherUser: local.publisherUser } : undefined;
|
|
418
|
+
if (proof)
|
|
419
|
+
try {
|
|
420
|
+
if (stable(JSON.parse(await readFile(receipt, 'utf8'))) === stable(proof))
|
|
421
|
+
return;
|
|
422
|
+
}
|
|
423
|
+
catch { /* Absent or unreadable proof only means verification runs. */ }
|
|
424
|
+
await timed('server.authority', 'verify', () => this.verifyAuthority(binding));
|
|
425
|
+
if (proof)
|
|
426
|
+
await durable(receipt, proof);
|
|
427
|
+
}
|
|
428
|
+
async verifyAuthority(binding) {
|
|
281
429
|
for (const role of ['reader', 'publisher']) {
|
|
282
430
|
const result = await this.run('verify-' + role, 'InsightServerProbe', [binding.repository, role], await this.credentials(binding, role));
|
|
283
431
|
if (result.repository !== binding.repository || result.role !== role || (role === 'reader' ? result.permission !== 0 : ![1, 2].includes(Number(result.permission))))
|
|
@@ -441,7 +589,7 @@ export class GhidraServer {
|
|
|
441
589
|
}
|
|
442
590
|
}
|
|
443
591
|
identity(local) { return serverIdentity(local, this.c); }
|
|
444
|
-
async stop() { await stopLocalServer(this.directory, this.c); this.state.child = undefined; this.state.initializing = undefined; }
|
|
592
|
+
async stop() { await stopLocalServer(this.directory, this.c); this.state.child = undefined; this.state.initializing = undefined; await forgetAuthority(this.directory); }
|
|
445
593
|
}
|
|
446
594
|
export async function serverIdentity(local, c) {
|
|
447
595
|
const token = await c.secrets.require(local.tokenSecret);
|
package/dist/src/storage-gc.js
CHANGED
|
@@ -315,7 +315,7 @@ export async function collectStorage(workspace, port, dryRun, progress = () => {
|
|
|
315
315
|
if (workspace.unchangedNative(context))
|
|
316
316
|
await remove(project, category);
|
|
317
317
|
else
|
|
318
|
-
keep(checkout.root, '
|
|
318
|
+
keep(checkout.root, 'Ghidra did not report this checkout unmodified when it was last saved or observed; it may hold private work.');
|
|
319
319
|
continue;
|
|
320
320
|
}
|
|
321
321
|
const sizes = new Reclaimed();
|
package/dist/src/sync-policy.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { command, Permission } from '@eyeauras/cli-factory';
|
|
2
2
|
import { scope } from './research.js';
|
|
3
3
|
import { fail, id, object, text } from './model.js';
|
|
4
|
+
import { failUnresolved } from './unresolved-guidance.js';
|
|
4
5
|
import { selectedOptions } from './arguments.js';
|
|
5
6
|
export const manualPolicy = { publish: 'manual', refresh: 'manual' };
|
|
6
7
|
export function syncPolicy(value) {
|
|
@@ -28,7 +29,7 @@ export class Synchronization {
|
|
|
28
29
|
if (request.state !== 'accepted')
|
|
29
30
|
fail('unknown', 'Policy change has a retained outcome.');
|
|
30
31
|
if (this.workspace.unresolved(selected).length)
|
|
31
|
-
|
|
32
|
+
failUnresolved(this.workspace, selected, 'The context outcome is unresolved; its synchronization policy cannot change yet.');
|
|
32
33
|
const current = this.workspace.context(selected), result = { ...selected, state: 'configured', ...policy };
|
|
33
34
|
this.workspace.startRequest(request.id);
|
|
34
35
|
this.workspace.completeSavedRequest(selected, request.id, current.generation, { syncPolicy: policy }, result);
|