@mrciphersmith/keryx 0.4.13 → 0.4.15
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/dist/cli.js +101 -77
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -24305,7 +24305,7 @@ var package_default;
|
|
|
24305
24305
|
var init_package = __esm(() => {
|
|
24306
24306
|
package_default = {
|
|
24307
24307
|
name: "@mrciphersmith/keryx",
|
|
24308
|
-
version: "0.4.
|
|
24308
|
+
version: "0.4.15",
|
|
24309
24309
|
description: "Version-controlled project context for AI coding agents: code graph, architecture wiki, project memory, relevant tests, quality signals, and task flows.",
|
|
24310
24310
|
private: false,
|
|
24311
24311
|
publishConfig: {
|
|
@@ -294739,7 +294739,9 @@ class MachineLedger {
|
|
|
294739
294739
|
CREATE TABLE IF NOT EXISTS machine_native_leases(token TEXT PRIMARY KEY,daemonId TEXT NOT NULL,sessionId TEXT NOT NULL);
|
|
294740
294740
|
CREATE TABLE IF NOT EXISTS machine_run_recovery(id TEXT PRIMARY KEY,digest TEXT NOT NULL,runId TEXT NOT NULL,step TEXT NOT NULL,phase TEXT NOT NULL,result TEXT);
|
|
294741
294741
|
CREATE TABLE IF NOT EXISTS machine_run_terminal(stream TEXT PRIMARY KEY,terminalAt INTEGER NOT NULL);
|
|
294742
|
-
CREATE TABLE IF NOT EXISTS machine_retired_logs(stream TEXT NOT NULL,fromSeq INTEGER NOT NULL,toSeq INTEGER NOT NULL,digest TEXT NOT NULL,bytes INTEGER NOT NULL,retiredAt INTEGER NOT NULL,PRIMARY KEY(stream,fromSeq))
|
|
294742
|
+
CREATE TABLE IF NOT EXISTS machine_retired_logs(stream TEXT NOT NULL,fromSeq INTEGER NOT NULL,toSeq INTEGER NOT NULL,digest TEXT NOT NULL,bytes INTEGER NOT NULL,retiredAt INTEGER NOT NULL,PRIMARY KEY(stream,fromSeq));
|
|
294743
|
+
CREATE INDEX IF NOT EXISTS machine_events_unacknowledged ON machine_events(stream,seq) WHERE acked=0;
|
|
294744
|
+
CREATE INDEX IF NOT EXISTS machine_discarded_logs_unacknowledged ON machine_discarded_logs(stream,seq) WHERE acked=0;`);
|
|
294743
294745
|
const version = this.db.query("SELECT value FROM machine_meta WHERE key='version'").get();
|
|
294744
294746
|
if (version && version.value !== "1" && version.value !== "2" && version.value !== "3" && version.value !== "4" && version.value !== "5" && version.value !== "6" && version.value !== "7") {
|
|
294745
294747
|
this.db.close();
|
|
@@ -295061,8 +295063,8 @@ class MachineLedger {
|
|
|
295061
295063
|
this.db.query("UPDATE machine_discarded_logs SET sent=0 WHERE stream=? AND acked=0").run(stream);
|
|
295062
295064
|
}).immediate();
|
|
295063
295065
|
}
|
|
295064
|
-
unsentEvents(
|
|
295065
|
-
return this.db.query("SELECT seq,payload FROM machine_events WHERE
|
|
295066
|
+
unsentEvents(limit) {
|
|
295067
|
+
return this.db.query("SELECT stream,seq,payload FROM machine_events WHERE acked=0 AND sent=0 ORDER BY stream,seq LIMIT ?").all(limit).map((row) => ({ ...row, payload: JSON.parse(row.payload) }));
|
|
295066
295068
|
}
|
|
295067
295069
|
pendingEvents(stream) {
|
|
295068
295070
|
return this.db.query("SELECT seq,payload FROM machine_events WHERE stream=? AND acked=0 ORDER BY seq LIMIT 500").all(stream).map((r) => ({ seq: r.seq, payload: JSON.parse(r.payload) }));
|
|
@@ -295129,10 +295131,10 @@ class MachineLedger {
|
|
|
295129
295131
|
}
|
|
295130
295132
|
ackEvents(stream, seq) {
|
|
295131
295133
|
this.db.transaction(() => {
|
|
295132
|
-
if (!Number.isSafeInteger(seq) || seq < 0 || seq > this.highest(stream) || this.db.query("SELECT
|
|
295134
|
+
if (!Number.isSafeInteger(seq) || seq < 0 || seq > this.highest(stream) || this.db.query("SELECT 1 FROM machine_events WHERE stream=? AND seq<=? AND acked=0 AND sent=0 LIMIT 1").get(stream, seq) || this.db.query("SELECT 1 FROM machine_discarded_logs WHERE stream=? AND seq<=? AND acked=0 AND sent=0 LIMIT 1").get(stream, seq))
|
|
295133
295135
|
throw new MachineError("unsent-event-ack");
|
|
295134
|
-
this.db.query("UPDATE machine_events SET acked=1 WHERE stream=? AND seq<=?").run(stream, seq);
|
|
295135
|
-
this.db.query("UPDATE machine_discarded_logs SET acked=1 WHERE stream=? AND seq<=?").run(stream, seq);
|
|
295136
|
+
this.db.query("UPDATE machine_events SET acked=1 WHERE stream=? AND seq<=? AND acked=0").run(stream, seq);
|
|
295137
|
+
this.db.query("UPDATE machine_discarded_logs SET acked=1 WHERE stream=? AND seq<=? AND acked=0").run(stream, seq);
|
|
295136
295138
|
}).immediate();
|
|
295137
295139
|
}
|
|
295138
295140
|
reconcileCursor(stream, remote) {
|
|
@@ -297623,7 +297625,7 @@ var init_native_coverage_generated = __esm(() => {
|
|
|
297623
297625
|
registryDigest: "286041ef4394afd4de97b4da37e31ccb2728c485cd32488c737a2686c244fbca",
|
|
297624
297626
|
contractDigest: "43cd83cfbd494ce63e1f6c86a5a0c057a160f4a537d8119358e0f262412a96c9",
|
|
297625
297627
|
subjectCatalogueDigest: "819a324bfef3387bf464f5c78d4831751b03c9c4f3cb636471e2d8f4bd88d6cc",
|
|
297626
|
-
inventoryDigest: "
|
|
297628
|
+
inventoryDigest: "3b511b4103523ed7d7a43acfe8bb142baf7fe65d63fbb10a23a4907c2aca0ca2",
|
|
297627
297629
|
releaseReady: true,
|
|
297628
297630
|
counts: {
|
|
297629
297631
|
registeredCommands: 74,
|
|
@@ -297901,7 +297903,7 @@ var init_native_coverage_generated = __esm(() => {
|
|
|
297901
297903
|
"workspace.navigate"
|
|
297902
297904
|
],
|
|
297903
297905
|
otherBlockers: [],
|
|
297904
|
-
descriptorDigest: "
|
|
297906
|
+
descriptorDigest: "4c0cb7f45d35dfad8bd25c2093d7fa50a174e767b2e1570b16f9eb8fa3b0c222"
|
|
297905
297907
|
};
|
|
297906
297908
|
});
|
|
297907
297909
|
|
|
@@ -339519,7 +339521,6 @@ async function createSessionHost(options) {
|
|
|
339519
339521
|
decisionJournal: { session: questionJournal.session, lastDecisionId: questionJournal.lastDecisionId },
|
|
339520
339522
|
restriction,
|
|
339521
339523
|
...rewindPort === undefined ? {} : { rewind: rewindPort },
|
|
339522
|
-
close: closeForCommand,
|
|
339523
339524
|
record,
|
|
339524
339525
|
catalogue: catalogue(),
|
|
339525
339526
|
runtime: options.runtime,
|
|
@@ -339732,30 +339733,37 @@ async function createSessionHost(options) {
|
|
|
339732
339733
|
throw new SessionHostError("recovery-required");
|
|
339733
339734
|
if (active !== undefined || request.expectedSessionVersion !== record.version || request.expectedHistoryVersion !== record.historyVersion || request.expectedWorkspaceBaseline !== record.workspaceBaseline)
|
|
339734
339735
|
throw new SessionHostError("stale-resume-pins");
|
|
339735
|
-
const
|
|
339736
|
-
|
|
339737
|
-
|
|
339738
|
-
|
|
339739
|
-
|
|
339740
|
-
|
|
339741
|
-
|
|
339742
|
-
|
|
339743
|
-
|
|
339744
|
-
|
|
339745
|
-
|
|
339746
|
-
|
|
339747
|
-
|
|
339748
|
-
|
|
339749
|
-
|
|
339750
|
-
|
|
339751
|
-
|
|
339752
|
-
|
|
339753
|
-
|
|
339754
|
-
|
|
339755
|
-
|
|
339756
|
-
|
|
339757
|
-
|
|
339736
|
+
const reacquired = options.workspace.checkoutLease?.reacquire();
|
|
339737
|
+
try {
|
|
339738
|
+
const verified = await options.workspace.verify(record.workspaceBaseline);
|
|
339739
|
+
if (!verified.ok)
|
|
339740
|
+
throw new SessionHostError("workspace-conflict");
|
|
339741
|
+
if (opened.lease.checkLost())
|
|
339742
|
+
throw new SessionHostError("native-lease-lost");
|
|
339743
|
+
if (opened.lease.released) {
|
|
339744
|
+
const reopened = openLeasedSession({ cwd: options.cwd, resumeId: nativeId, ...options.dataDir === undefined ? {} : { dataDir: options.dataDir } });
|
|
339745
|
+
unwatchLease();
|
|
339746
|
+
opened = reopened;
|
|
339747
|
+
handle = reopened.handle;
|
|
339748
|
+
options.onNativeLease?.({ token: opened.lease.owner.token, nativeSessionId: handle.summary.id });
|
|
339749
|
+
history.splice(0, history.length, ...reopened.history);
|
|
339750
|
+
archive.splice(0, archive.length, ...reopened.archive);
|
|
339751
|
+
archiveCursor = history.length;
|
|
339752
|
+
options.runtime.bindSessionDir(handle.dir);
|
|
339753
|
+
unwatchLease = opened.lease.onLost(onLeaseLost);
|
|
339754
|
+
try {
|
|
339755
|
+
await attachSessionServices();
|
|
339756
|
+
} catch {
|
|
339757
|
+
lostResumable = false;
|
|
339758
|
+
record.state = "recovery-required";
|
|
339759
|
+
state();
|
|
339760
|
+
throw new SessionHostError("recovery-required");
|
|
339761
|
+
}
|
|
339758
339762
|
}
|
|
339763
|
+
} catch (cause) {
|
|
339764
|
+
if (reacquired && opened.lease.released)
|
|
339765
|
+
options.workspace.checkoutLease?.release();
|
|
339766
|
+
throw cause;
|
|
339759
339767
|
}
|
|
339760
339768
|
lostRun = undefined;
|
|
339761
339769
|
lostResumable = false;
|
|
@@ -339873,16 +339881,25 @@ async function createSessionHost(options) {
|
|
|
339873
339881
|
state();
|
|
339874
339882
|
throw new SessionHostError("native-lease-lost");
|
|
339875
339883
|
}
|
|
339876
|
-
|
|
339877
|
-
if (!
|
|
339878
|
-
|
|
339879
|
-
|
|
339880
|
-
|
|
339881
|
-
|
|
339884
|
+
try {
|
|
339885
|
+
if (!opened.lease.released) {
|
|
339886
|
+
for (const abort of inspections.keys())
|
|
339887
|
+
abort.abort(new SessionHostError("session-closed"));
|
|
339888
|
+
const stopped = await options.runtime.stop();
|
|
339889
|
+
const settled = await within4(Promise.allSettled([...inspections.values()]).then(() => true), false, SETTLE_BOUND_MS);
|
|
339890
|
+
if (stopped.status !== "stopped" || !settled || !await closeSessionServices() || opened.lease.checkLost()) {
|
|
339891
|
+
throw new SessionHostError("recovery-required");
|
|
339892
|
+
}
|
|
339893
|
+
syncHistory();
|
|
339894
|
+
await options.runtime.preserveSession();
|
|
339895
|
+
releaseSessionLease(opened.lease);
|
|
339882
339896
|
}
|
|
339883
|
-
|
|
339884
|
-
|
|
339885
|
-
|
|
339897
|
+
options.workspace.checkoutLease?.release();
|
|
339898
|
+
} catch {
|
|
339899
|
+
record.state = "recovery-required";
|
|
339900
|
+
state();
|
|
339901
|
+
fenceLease();
|
|
339902
|
+
return { status: "recovery-required" };
|
|
339886
339903
|
}
|
|
339887
339904
|
for (const item of queueItems)
|
|
339888
339905
|
if (item.state === "queued") {
|
|
@@ -340404,6 +340421,10 @@ async function createSessionHost(options) {
|
|
|
340404
340421
|
let outcome;
|
|
340405
340422
|
try {
|
|
340406
340423
|
const context = commandContext(operation.operationId, undefined, inspection.context);
|
|
340424
|
+
context.close = () => {
|
|
340425
|
+
inspection.close();
|
|
340426
|
+
return closeForCommand();
|
|
340427
|
+
};
|
|
340407
340428
|
if (options.lifecycle !== undefined) {
|
|
340408
340429
|
context.lifecycle = options.lifecycle;
|
|
340409
340430
|
context.lifecycleInput = lifecycleInput;
|
|
@@ -341001,6 +341022,8 @@ function acquireCheckoutLease(cwd, owner) {
|
|
|
341001
341022
|
};
|
|
341002
341023
|
return { get nonce() {
|
|
341003
341024
|
return nonce;
|
|
341025
|
+
}, get released() {
|
|
341026
|
+
return released;
|
|
341004
341027
|
}, assertOwnership, reacquire() {
|
|
341005
341028
|
if (!released)
|
|
341006
341029
|
throw new MachineError("lease-owner-mismatch");
|
|
@@ -344121,26 +344144,22 @@ class MachineBridge {
|
|
|
344121
344144
|
this.flushingOutbox = true;
|
|
344122
344145
|
let pending = false;
|
|
344123
344146
|
try {
|
|
344124
|
-
|
|
344125
|
-
|
|
344126
|
-
|
|
344127
|
-
|
|
344128
|
-
|
|
344129
|
-
|
|
344130
|
-
|
|
344131
|
-
|
|
344132
|
-
|
|
344133
|
-
|
|
344134
|
-
}
|
|
344135
|
-
throw cause;
|
|
344147
|
+
const batchSize = 500;
|
|
344148
|
+
const events = this.ledger.unsentEvents(batchSize);
|
|
344149
|
+
for (const { stream, seq, payload } of events) {
|
|
344150
|
+
const frame = stream.startsWith("session:") ? this.envelope("session-event", payload) : this.envelope("run-event", payload);
|
|
344151
|
+
try {
|
|
344152
|
+
this.send(frame);
|
|
344153
|
+
} catch (cause) {
|
|
344154
|
+
if (cause instanceof MachineError && ["quota-exceeded", "machine-offline"].includes(cause.code)) {
|
|
344155
|
+
pending = true;
|
|
344156
|
+
break;
|
|
344136
344157
|
}
|
|
344137
|
-
|
|
344158
|
+
throw cause;
|
|
344138
344159
|
}
|
|
344139
|
-
|
|
344140
|
-
pending = true;
|
|
344141
|
-
if (pending)
|
|
344142
|
-
break;
|
|
344160
|
+
this.ledger.markSent(stream, seq);
|
|
344143
344161
|
}
|
|
344162
|
+
pending ||= events.length === batchSize;
|
|
344144
344163
|
} catch (cause) {
|
|
344145
344164
|
this.notice(cause);
|
|
344146
344165
|
this.connection?.close();
|
|
@@ -344187,8 +344206,8 @@ class MachineBridge {
|
|
|
344187
344206
|
return;
|
|
344188
344207
|
}
|
|
344189
344208
|
if (frame.type === "run-event-ack") {
|
|
344190
|
-
this.flushOutbox();
|
|
344191
344209
|
this.ledger.ackEvents(`run:${frame.payload.runId}`, frame.payload.localSeq);
|
|
344210
|
+
this.flushOutbox();
|
|
344192
344211
|
const run = this.runs.get(frame.payload.runId);
|
|
344193
344212
|
if (run?.terminalSeq && frame.payload.localSeq >= run.terminalSeq && !run.publishing) {
|
|
344194
344213
|
run.publishing = true;
|
|
@@ -344696,17 +344715,11 @@ class MachineBridge {
|
|
|
344696
344715
|
const request = validateControl("SessionResume", Object.fromEntries(Object.entries(args).filter(([key]) => key !== "sessionId")));
|
|
344697
344716
|
if (!request.ok || !verifyBaseline(mapping.cwd, hosted.workspace.baseline()))
|
|
344698
344717
|
throw new MachineError("workspace-conflict");
|
|
344699
|
-
if (hosted.
|
|
344700
|
-
|
|
344701
|
-
|
|
344702
|
-
|
|
344703
|
-
|
|
344704
|
-
source.lease.release(source.lease.nonce);
|
|
344705
|
-
source.leaseReleased = true;
|
|
344706
|
-
}
|
|
344707
|
-
this.lifecycleContext(input);
|
|
344708
|
-
hosted.lease.reacquire();
|
|
344709
|
-
hosted.leaseReleased = false;
|
|
344718
|
+
if (hosted.lease.released && source !== hosted && source.mapping.cwd === mapping.cwd && !source.lease.released) {
|
|
344719
|
+
const closed = await input.releaseSource();
|
|
344720
|
+
if (closed.state !== "closed")
|
|
344721
|
+
throw new MachineError("recovery-required");
|
|
344722
|
+
source.lease.release(source.lease.nonce);
|
|
344710
344723
|
}
|
|
344711
344724
|
this.lifecycleContext(input);
|
|
344712
344725
|
let actual;
|
|
@@ -344745,7 +344758,6 @@ class MachineBridge {
|
|
|
344745
344758
|
throw new MachineError("recovery-required");
|
|
344746
344759
|
this.lifecycleContext(input);
|
|
344747
344760
|
source.lease.release(source.lease.nonce);
|
|
344748
|
-
source.leaseReleased = true;
|
|
344749
344761
|
}
|
|
344750
344762
|
this.lifecycleContext(input);
|
|
344751
344763
|
const lease = acquireCheckoutLease(mapping.cwd, { hubId: this.options.enrollment.hubId, runId: record.sessionId, daemonId: this.daemonId });
|
|
@@ -344828,7 +344840,19 @@ class MachineBridge {
|
|
|
344828
344840
|
}
|
|
344829
344841
|
return this.connection?.connected ? readSessionActionAuthority({ hubUrl: this.options.enrollment.hubUrl, secret: readMachineSecret(this.options.enrollment), action }) : Promise.resolve(false);
|
|
344830
344842
|
},
|
|
344831
|
-
workspace: { ...workspace,
|
|
344843
|
+
workspace: { ...workspace, checkoutLease: {
|
|
344844
|
+
release: () => {
|
|
344845
|
+
if (!lease.released)
|
|
344846
|
+
lease.release(lease.nonce);
|
|
344847
|
+
},
|
|
344848
|
+
reacquire: () => {
|
|
344849
|
+
if (lease.released) {
|
|
344850
|
+
lease.reacquire();
|
|
344851
|
+
return true;
|
|
344852
|
+
}
|
|
344853
|
+
return false;
|
|
344854
|
+
}
|
|
344855
|
+
}, rewind: {
|
|
344832
344856
|
ownership: () => {
|
|
344833
344857
|
lease.assertOwnership();
|
|
344834
344858
|
const baseline = workspace.baseline();
|
|
@@ -345051,7 +345075,7 @@ class MachineBridge {
|
|
|
345051
345075
|
for (const [id, hosted] of this.hosted) {
|
|
345052
345076
|
if (sessionId !== undefined && id !== sessionId)
|
|
345053
345077
|
continue;
|
|
345054
|
-
let checkoutOwned = hosted.
|
|
345078
|
+
let checkoutOwned = !hosted.lease.released;
|
|
345055
345079
|
try {
|
|
345056
345080
|
if (checkoutOwned)
|
|
345057
345081
|
hosted.lease.assertOwnership();
|
|
@@ -345357,7 +345381,7 @@ class MachineBridge {
|
|
|
345357
345381
|
if (runs.some((run) => run.terminal?.outcome === "unknown") || unresolved.length >= 1000 || unresolved.some((row) => row.checkout === hosted.mapping.checkoutId))
|
|
345358
345382
|
return settle(ownerRefusal("recovery-required"), true);
|
|
345359
345383
|
try {
|
|
345360
|
-
if (hosted.
|
|
345384
|
+
if (hosted.lease.released)
|
|
345361
345385
|
throw new MachineError("lease-owner-mismatch");
|
|
345362
345386
|
hosted.lease.assertOwnership();
|
|
345363
345387
|
} catch (cause) {
|
|
@@ -345396,9 +345420,9 @@ class MachineBridge {
|
|
|
345396
345420
|
hosted.host.setConnected(false);
|
|
345397
345421
|
await hosted.host.dispose("machine-stop");
|
|
345398
345422
|
const state = await hosted.host.inspect();
|
|
345399
|
-
if (!hosted.
|
|
345423
|
+
if (!hosted.lease.released && (state.state === "idle" || state.state === "closed" || hosted.host.resumableAfterLost()))
|
|
345400
345424
|
hosted.lease.release(hosted.lease.nonce);
|
|
345401
|
-
else if (!hosted.
|
|
345425
|
+
else if (!hosted.lease.released)
|
|
345402
345426
|
provenStop = false;
|
|
345403
345427
|
}
|
|
345404
345428
|
this.hosted.clear();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mrciphersmith/keryx",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.15",
|
|
4
4
|
"description": "Version-controlled project context for AI coding agents: code graph, architecture wiki, project memory, relevant tests, quality signals, and task flows.",
|
|
5
5
|
"private": false,
|
|
6
6
|
"publishConfig": {
|