@staix/agent-mem 0.29.0 → 0.30.0
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/.claude-plugin/plugin.json +1 -1
- package/README.md +9 -7
- package/package.json +3 -2
- package/src/cli.ts +69 -10
- package/src/commands-table.ts +4 -0
- package/src/mcp-memory.ts +36 -8
- package/src/memory/bridge.ts +26 -1
- package/src/memory/capacity.ts +5 -2
- package/src/memory/catalog.ts +10 -1
- package/src/memory/doctor.ts +17 -14
- package/src/memory/formats.ts +4 -3
- package/src/memory/intent-brief.ts +34 -6
- package/src/memory/metrics.ts +173 -14
- package/src/memory/shard-bridge.ts +18 -6
- package/src/memory/shard-sync-format.ts +18 -0
- package/src/memory/shard-sync.ts +52 -4
- package/src/memory/sync-placement-bound.ts +21 -4
- package/src/memory/sync-placement-cache.ts +16 -1
- package/src/memory/sync-placement-capture.ts +14 -2
- package/src/memory/sync-placement-checkpoint-format.ts +199 -0
- package/src/memory/sync-placement-checkpoint-person.ts +209 -0
- package/src/memory/sync-placement-checkpoint-prospective.ts +141 -0
- package/src/memory/sync-placement-checkpoint-storage.ts +218 -0
- package/src/memory/sync-placement-checkpoint.ts +234 -0
- package/src/memory/sync-placement-dependencies.ts +42 -9
- package/src/memory/sync-placement-effective-writers.ts +12 -6
- package/src/memory/sync-placement-git.ts +17 -7
- package/src/memory/sync-placement-inspection-evidence.ts +1 -1
- package/src/memory/sync-placement-inventory.ts +5 -0
- package/src/memory/sync-placement-journal-format.ts +4 -1
- package/src/memory/sync-placement-journal-storage.ts +129 -26
- package/src/memory/sync-placement-materialize.ts +33 -19
- package/src/memory/sync-placement-projection.ts +7 -1
- package/src/memory/sync-placement-publication-events.ts +42 -0
- package/src/memory/sync-placement-publication-plan.ts +18 -1
- package/src/memory/sync-placement-realm-admission.ts +20 -3
- package/src/memory/sync-placement-realm-discovery.ts +42 -0
- package/src/memory/sync-placement-remote-admission.ts +190 -0
- package/src/memory/sync-placement-remote-adoption-format.ts +54 -0
- package/src/memory/sync-placement-remote-materialization.ts +49 -0
- package/src/memory/sync-placement-remote-refusal.ts +21 -0
- package/src/memory/sync-placement-remote-stage.ts +275 -0
- package/src/memory/sync-placement-transport.ts +202 -51
- package/src/memory/sync-placement-writer-history.ts +75 -17
- package/src/memory/sync-placement-writer-renewal.ts +18 -10
- package/src/memory/sync-placement-writer-revision-format.ts +16 -13
- package/src/memory/sync-placement-yield.ts +14 -0
- package/src/memory/sync.ts +4 -1
- package/src/sync-placement-writer-context.ts +5 -5
- package/src/ui/plugin.ts +1 -1
|
@@ -10,10 +10,11 @@ import { readPlacementRuntimeMarkers } from "./sync-placement-guard.ts";
|
|
|
10
10
|
import { readActivePlacementBinding, type ActivePlacementBinding } from "./sync-placement-active.ts";
|
|
11
11
|
import { readInitialSyncPlacementWriterLocator } from "./sync-placement-writer-roots.ts";
|
|
12
12
|
import { readEffectiveSyncPlacementWriters } from "./sync-placement-effective-writers.ts";
|
|
13
|
-
import { readPlacementJournal, readPlacementWriterJournalAnchors, writerRenewalCapacity } from "./sync-placement-journal-storage.ts";
|
|
13
|
+
import { readPlacementJournal, readPlacementWriterJournalAnchors, writerRenewalCapacity, readPlacementPublicationMetadata, placementJournalObjectComposition, type PlacementJournalObjectComposition } from "./sync-placement-journal-storage.ts";
|
|
14
14
|
import { readWriterHistory, writeWriterRenewalIntent, writeWriterRevision, appendWriterCommit, clearWriterRenewalIntent, abandonWriterRenewal, abandonUnpublishedWriterStaging, type WriterHistoryPhase, type WriterHistoryRead } from "./sync-placement-writer-history.ts";
|
|
15
15
|
import { createWriterRevision, createWriterCommit, createWriterRenewalIntent, writerRevisionWriters, WRITER_REVISION_SCHEMA, WRITER_RENEWAL_INTENT_SCHEMA, WRITER_REVISION_LIMIT, WRITER_COMMIT_LOG, SharedWriterRevisionError, type WriterRenewalIntent } from "./sync-placement-writer-revision-format.ts";
|
|
16
16
|
import { requireWriterRenewalHomeFloor } from "./sync-placement-prerequisites.ts";
|
|
17
|
+
import { resolvePlacementWindow } from "./sync-placement-checkpoint-storage.ts";
|
|
17
18
|
import { withPlacementActivationFences } from "./sync-placement-activation-locks.ts";
|
|
18
19
|
import { assertPlacementActivationOwner, type PlacementActivationOwner } from "./sync-placement-activation-proof.ts";
|
|
19
20
|
import { previewSyncPlacementSources, previewOwnedSyncPlacementSources } from "./sync-placement-capture.ts";
|
|
@@ -43,6 +44,8 @@ const binding=(a:ActivePlacementBinding)=>({epochHash:a.profile.placementHead,ac
|
|
|
43
44
|
function list(dir:string,maximum:number):string[]{
|
|
44
45
|
const out:string[]=[],reader=opendirSync(dir);try{for(;;){const e=reader.readSync();if(!e)break;if(out.length>=maximum)throw new SharedWriterRevisionError("bound");out.push(e.name);}}finally{reader.closeSync();}return out.sort();
|
|
45
46
|
}
|
|
47
|
+
/** The fenced directories of one active placement: the home, every activated realm and every admitted project shard. */
|
|
48
|
+
export function placementFenceDirectories(home:string,a:ActivePlacementBinding):string[]{return directories(home,a);}
|
|
46
49
|
function directories(home:string,a:ActivePlacementBinding):string[]{
|
|
47
50
|
const out=[home];for(const r of a.activation.realms)out.push(r.scope==="user"?join(home,"user"):join(home,"projects",r.keyHash.slice(0,16)));
|
|
48
51
|
const checked=(dir:string)=>{const s=lstatSync(dir);if(!s.isDirectory()||s.isSymbolicLink()||s.uid!==process.getuid?.()||(s.mode&0o022)!==0)throw new WriterRenewalError("changed");};
|
|
@@ -107,12 +110,16 @@ export async function renewSyncPlacementWriters(options:PlacementActivationOptio
|
|
|
107
110
|
if(options.mode==="dry-run"){
|
|
108
111
|
if(history.pending)return{mode:options.mode,active:true,renewalSupported:true,pending:true,commitStarted:history.appendStarted,abandonable:!history.appendStarted,sequence:history.sequence,remainingRevisions:WRITER_REVISION_LIMIT-history.sequence};
|
|
109
112
|
const expected=readEffectiveSyncPlacementWriters(home);let floorReady=true;try{requireWriterRenewalHomeFloor(home);}catch{floorReady=false;}
|
|
110
|
-
let recoveryReady=true,objectSlotsRemaining:number|undefined;
|
|
111
|
-
|
|
113
|
+
let recoveryReady=true,objectSlotsRemaining:number|undefined,journalObjects:PlacementJournalObjectComposition|undefined;
|
|
114
|
+
// The preview's own composition (#288 step 1), read without a plan: `newPlan` is null here, and the epoch's one
|
|
115
|
+
// active.json slot is included exactly as the counted total includes it. A pending renewal intent lives outside the
|
|
116
|
+
// epoch directory, so `objectSlotsRemaining` can be smaller than the composition suggests.
|
|
117
|
+
try{journalClear(home,b.epochHash);pendingSources(home);objectSlotsRemaining=256-readPlacementJournal(home,b.epochHash).objects;
|
|
118
|
+
journalObjects=readPlacementPublicationMetadata(home,b.epochHash,io=>placementJournalObjectComposition({names:io.names()}));}catch{recoveryReady=false;}
|
|
112
119
|
const writers=previewActivePlacementWriters(home,options.ownRoot,options.writerRoots),remaining=WRITER_REVISION_LIMIT-history.sequence;
|
|
113
120
|
return{mode:options.mode,active:true,renewalSupported:true,forwardOnly:true,sequence:history.sequence,revisionHash:history.headHash,remainingRevisions:WRITER_REVISION_LIMIT-history.sequence,
|
|
114
121
|
quiescence:"deferred-to-apply",floorReady,requiredHomeFloor:"0.22.0",recoveryReady,...(recoveryReady?{}:{nextStep:new WriterRenewalError("pending").message}),
|
|
115
|
-
...(objectSlotsRemaining===undefined?{}:{objectSlotsRemaining}),...(remaining<=4?{capacityNotice:`${remaining} renewals remain before the 64-revision ceiling; the shared object budget may refuse earlier. Archival/checkpointing requires a separate reviewed protocol.`}:{}),
|
|
122
|
+
...(objectSlotsRemaining===undefined?{}:{objectSlotsRemaining}),...(journalObjects?{journalObjects}:{}),...(remaining<=4?{capacityNotice:`${remaining} renewals remain before the 64-revision ceiling; the shared object budget may refuse earlier. Archival/checkpointing requires a separate reviewed protocol.`}:{}),
|
|
116
123
|
writers,candidateMinimumVersion:"0.22.0",candidatesSupported:writers.complete&&writers.roots.every(r=>supported(r.version)),expectedWriterCount:expected.writers.length};
|
|
117
124
|
}
|
|
118
125
|
requireWriterRenewalHomeFloor(home);
|
|
@@ -128,8 +135,9 @@ export async function renewSyncPlacementWriters(options:PlacementActivationOptio
|
|
|
128
135
|
let intent=history.pending;
|
|
129
136
|
const cleanupOnly=!intent&&options.mode==="resume"&&!!history.current;
|
|
130
137
|
if(cleanupOnly){
|
|
131
|
-
|
|
132
|
-
|
|
138
|
+
// #288: the live window's own log: commits before it belong to frozen windows.
|
|
139
|
+
const local=history.commits.slice(history.commits.length-history.sequence),prefix=Buffer.from(local.slice(0,-1).map(row=>canonicalJSON(row)+"\n").join(""));
|
|
140
|
+
intent=createWriterRenewalIntent({schema:WRITER_RENEWAL_INTENT_SCHEMA,home,revision:history.current!,commit:history.commits.at(-1)!,previousLogBytes:prefix.length,previousLogHash:createHash("sha256").update(prefix).digest("hex")},history.genesis);
|
|
133
141
|
}
|
|
134
142
|
const locator=readInitialSyncPlacementWriterLocator(home);
|
|
135
143
|
const metadata=()=>{
|
|
@@ -148,14 +156,14 @@ export async function renewSyncPlacementWriters(options:PlacementActivationOptio
|
|
|
148
156
|
const current=readWriterHistory(home,{...b,initialLocatorHash:locator.seal});
|
|
149
157
|
if(current.sequence>=WRITER_REVISION_LIMIT)throw new SharedWriterRevisionError("cap");
|
|
150
158
|
const candidate=initialPlacementWriterContext(home,options.writerRoots,options.ownRoot);if(candidate.measurement.roots.some(r=>!supported(r.version)))throw new WriterRenewalError("candidate");
|
|
151
|
-
candidate.attest();const previous=current.current?writerRevisionWriters(current.current):initial.activation.writers;
|
|
159
|
+
candidate.attest();const previous=current.current?writerRevisionWriters(current.current,current.current.sequence===1?current.current.previousHash:undefined):initial.activation.writers;
|
|
152
160
|
if(canonicalJSON(previous)===canonicalJSON(candidate.measurement.writers))return{mode:options.mode,active:true,renewed:false,sequence:current.sequence,remainingRevisions:WRITER_REVISION_LIMIT-current.sequence};
|
|
153
161
|
const journal=readPlacementJournal(home,b.epochHash),revision=createWriterRevision({schema:WRITER_REVISION_SCHEMA,...b,initialLocatorHash:locator.seal,sequence:current.sequence+1,previousHash:current.headHash,
|
|
154
|
-
journal:{sequence:journal.sequence,headHash:journal.headHash},roots:candidate.measurement.roots,requestId:randomBytes(32).toString("hex")});
|
|
155
|
-
intent=createWriterRenewalIntent({schema:WRITER_RENEWAL_INTENT_SCHEMA,home,revision,commit:createWriterCommit(revision),previousLogBytes:current.logBytes,previousLogHash:current.logHash});
|
|
162
|
+
journal:{sequence:journal.sequence,headHash:journal.headHash},roots:candidate.measurement.roots,requestId:randomBytes(32).toString("hex")},current.genesis);
|
|
163
|
+
intent=createWriterRenewalIntent({schema:WRITER_RENEWAL_INTENT_SCHEMA,home,revision,commit:createWriterCommit(revision,current.genesis),previousLogBytes:current.logBytes,previousLogHash:current.logHash},current.genesis);
|
|
156
164
|
}
|
|
157
165
|
const fixed=intent;person(options,fixed);
|
|
158
|
-
const log=join(home,
|
|
166
|
+
const log=join(resolvePlacementWindow(home,b.epochHash).dir,WRITER_COMMIT_LOG);
|
|
159
167
|
const started=()=>{const s=lstatSync(log,{throwIfNoEntry:false});return!!s&&s.isFile()&&!s.isSymbolicLink()&&s.size>fixed.previousLogBytes;};
|
|
160
168
|
const check=()=>{
|
|
161
169
|
metadata();
|
|
@@ -5,6 +5,7 @@ import { types } from "node:util";
|
|
|
5
5
|
import { canonicalJSON, hashJSON } from "./generation.ts";
|
|
6
6
|
import { syncPlacementWriterId, type MeasuredSyncPlacementWriterRoot } from "./sync-placement-writers.ts";
|
|
7
7
|
import { PLACEMENT_FORMAT } from "./sync-placement-format.ts";
|
|
8
|
+
import { PLACEMENT_CHECKPOINT_PENDING_MESSAGE } from "./sync-placement-journal-format.ts";
|
|
8
9
|
import type { SyncPlacementWriterAttestation } from "./sync-placement-plan.ts";
|
|
9
10
|
|
|
10
11
|
export const WRITER_REVISION_MAX_BYTES=512*1024;
|
|
@@ -17,12 +18,13 @@ export const WRITER_REVISION_SCHEMA="agent-mem.sync-placement-writer-revision/v1
|
|
|
17
18
|
export const WRITER_COMMIT_SCHEMA="agent-mem.sync-placement-writer-commit/v1";
|
|
18
19
|
export const WRITER_RENEWAL_INTENT_SCHEMA="agent-mem.sync-placement-writer-renewal/v1";
|
|
19
20
|
|
|
20
|
-
export type SharedWriterRevisionErrorCode="invalid"|"bound"|"changed"|"pending"|"staging"|"cap";
|
|
21
|
+
export type SharedWriterRevisionErrorCode="invalid"|"bound"|"changed"|"pending"|"checkpoint-pending"|"staging"|"cap";
|
|
21
22
|
const messages:Record<SharedWriterRevisionErrorCode,string>={
|
|
22
23
|
invalid:"Writer renewal metadata is invalid or unsupported; have the person inspect the retained same-epoch inventory and rerun amem migrate --sync-placement --dry-run.",
|
|
23
24
|
bound:"Writer renewal metadata exceeds its supported bound; retain the existing inventory and request a separately reviewed archival/checkpoint before retrying.",
|
|
24
25
|
changed:"Writer renewal bindings changed; retain the existing inventory, inspect the same-epoch evidence and review a fresh dry-run before applying.",
|
|
25
26
|
pending:"Writer renewal is pending; preserve its exact intent and have the person run amem migrate --sync-placement --resume.",
|
|
27
|
+
"checkpoint-pending":PLACEMENT_CHECKPOINT_PENDING_MESSAGE,
|
|
26
28
|
staging:"Writer renewal has orphan staging without a registered final intent; have the person inspect it and run amem migrate --sync-placement --abandon, then amem migrate --sync-placement --dry-run before another apply.",
|
|
27
29
|
cap:"Writer revision capacity is exhausted (remaining 0); retain this epoch and request a separately reviewed archival/checkpoint before another renewal.",
|
|
28
30
|
};
|
|
@@ -88,35 +90,36 @@ export interface WriterCommitBody {schema:typeof WRITER_COMMIT_SCHEMA;epochHash:
|
|
|
88
90
|
export interface WriterCommit extends WriterCommitBody {seal:string}
|
|
89
91
|
export interface WriterRenewalIntentBody {schema:typeof WRITER_RENEWAL_INTENT_SCHEMA;home:string;revision:WriterRevision;commit:WriterCommit;previousLogBytes:number;previousLogHash:string}
|
|
90
92
|
export interface WriterRenewalIntent extends WriterRenewalIntentBody {seal:string}
|
|
91
|
-
function revision(input:unknown,sealed:boolean):WriterRevision {
|
|
93
|
+
function revision(input:unknown,sealed:boolean,genesis?:string):WriterRevision {
|
|
92
94
|
const v=object(input,["schema","epochHash","generation","homeHash","activationHash","initialLocatorHash","sequence","previousHash","journal","roots","requestId",...(sealed?["seal"]:[])]);
|
|
93
95
|
if(v.schema!==WRITER_REVISION_SCHEMA)fail();const journal=object(v.journal,["sequence","headHash"]);
|
|
94
96
|
const body:WriterRevisionBody={schema:WRITER_REVISION_SCHEMA,epochHash:hex(v.epochHash),generation:hex(v.generation,32),homeHash:hex(v.homeHash),activationHash:hex(v.activationHash),
|
|
95
97
|
initialLocatorHash:hex(v.initialLocatorHash),sequence:sequence(v.sequence),previousHash:hex(v.previousHash),journal:{sequence:integer(journal.sequence,0,20000),headHash:hex(journal.headHash)},roots:roots(v.roots),requestId:hex(v.requestId)};
|
|
96
|
-
|
|
98
|
+
// #288: window W > 0 starts from its own checkpoint genesis; window 0 keeps the epoch genesis.
|
|
99
|
+
if(body.sequence===1&&body.previousHash!==(genesis??writerInventoryGenesis(body.epochHash,body.activationHash)))fail();
|
|
97
100
|
const value={...body,seal:hashJSON(body)};if(sealed&&hex(v.seal)!==value.seal)fail();bounded(value,WRITER_REVISION_MAX_BYTES);return value;
|
|
98
101
|
}
|
|
99
|
-
export function createWriterRevision(body:WriterRevisionBody):WriterRevision {return safe(()=>revision(body,false));}
|
|
100
|
-
export function validateWriterRevision(value:unknown):WriterRevision {return safe(()=>revision(value,true));}
|
|
101
|
-
export function writerRevisionWriters(input:WriterRevision):SyncPlacementWriterAttestation[]{
|
|
102
|
-
return validateWriterRevision(input).roots.map<SyncPlacementWriterAttestation>(({writerId,version,pin})=>({writerId,version,pin,publicationFormat:PLACEMENT_FORMAT,compatible:true as const})).sort((a,b)=>a.writerId.localeCompare(b.writerId));
|
|
102
|
+
export function createWriterRevision(body:WriterRevisionBody,genesis?:string):WriterRevision {return safe(()=>revision(body,false,genesis===undefined?undefined:hex(genesis)));}
|
|
103
|
+
export function validateWriterRevision(value:unknown,genesis?:string):WriterRevision {return safe(()=>revision(value,true,genesis===undefined?undefined:hex(genesis)));}
|
|
104
|
+
export function writerRevisionWriters(input:WriterRevision,genesis?:string):SyncPlacementWriterAttestation[]{
|
|
105
|
+
return validateWriterRevision(input,genesis).roots.map<SyncPlacementWriterAttestation>(({writerId,version,pin})=>({writerId,version,pin,publicationFormat:PLACEMENT_FORMAT,compatible:true as const})).sort((a,b)=>a.writerId.localeCompare(b.writerId));
|
|
103
106
|
}
|
|
104
107
|
function commit(input:unknown,sealed:boolean):WriterCommit {
|
|
105
108
|
const v=object(input,["schema","epochHash","sequence","previousHash","revisionHash",...(sealed?["seal"]:[])]);if(v.schema!==WRITER_COMMIT_SCHEMA)fail();
|
|
106
109
|
const body:WriterCommitBody={schema:WRITER_COMMIT_SCHEMA,epochHash:hex(v.epochHash),sequence:sequence(v.sequence),previousHash:hex(v.previousHash),revisionHash:hex(v.revisionHash)};
|
|
107
110
|
const value={...body,seal:hashJSON(body)};if(sealed&&hex(v.seal)!==value.seal)fail();bounded(value,WRITER_COMMIT_MAX_BYTES);return value;
|
|
108
111
|
}
|
|
109
|
-
export function createWriterCommit(input:WriterRevision):WriterCommit {
|
|
110
|
-
const rev=validateWriterRevision(input);return safe(()=>commit({schema:WRITER_COMMIT_SCHEMA,epochHash:rev.epochHash,sequence:rev.sequence,previousHash:rev.previousHash,revisionHash:rev.seal},false));
|
|
112
|
+
export function createWriterCommit(input:WriterRevision,genesis?:string):WriterCommit {
|
|
113
|
+
const rev=validateWriterRevision(input,genesis);return safe(()=>commit({schema:WRITER_COMMIT_SCHEMA,epochHash:rev.epochHash,sequence:rev.sequence,previousHash:rev.previousHash,revisionHash:rev.seal},false));
|
|
111
114
|
}
|
|
112
115
|
export function validateWriterCommit(value:unknown):WriterCommit {return safe(()=>commit(value,true));}
|
|
113
|
-
function intent(input:unknown,sealed:boolean):WriterRenewalIntent {
|
|
116
|
+
function intent(input:unknown,sealed:boolean,genesis?:string):WriterRenewalIntent {
|
|
114
117
|
const v=object(input,["schema","home","revision","commit","previousLogBytes","previousLogHash",...(sealed?["seal"]:[])]);if(v.schema!==WRITER_RENEWAL_INTENT_SCHEMA)fail();
|
|
115
|
-
const rev=validateWriterRevision(v.revision),ack=validateWriterCommit(v.commit),previousLogBytes=integer(v.previousLogBytes,0,WRITER_COMMIT_MAX_BYTES),previousLogHash=hex(v.previousLogHash);
|
|
118
|
+
const rev=validateWriterRevision(v.revision,genesis),ack=validateWriterCommit(v.commit),previousLogBytes=integer(v.previousLogBytes,0,WRITER_COMMIT_MAX_BYTES),previousLogHash=hex(v.previousLogHash);
|
|
116
119
|
if(ack.epochHash!==rev.epochHash||ack.sequence!==rev.sequence||ack.previousHash!==rev.previousHash||ack.revisionHash!==rev.seal)fail();
|
|
117
120
|
if(rev.sequence===1&&(previousLogBytes!==0||previousLogHash!==createHash("sha256").update("").digest("hex")))fail();
|
|
118
121
|
const body:WriterRenewalIntentBody={schema:WRITER_RENEWAL_INTENT_SCHEMA,home:path(v.home),revision:rev,commit:ack,previousLogBytes,previousLogHash};
|
|
119
122
|
const value={...body,seal:hashJSON(body)};if(sealed&&hex(v.seal)!==value.seal)fail();bounded(value,WRITER_RENEWAL_INTENT_MAX_BYTES);return value;
|
|
120
123
|
}
|
|
121
|
-
export function createWriterRenewalIntent(body:WriterRenewalIntentBody):WriterRenewalIntent {return safe(()=>intent(body,false));}
|
|
122
|
-
export function validateWriterRenewalIntent(value:unknown):WriterRenewalIntent {return safe(()=>intent(value,true));}
|
|
124
|
+
export function createWriterRenewalIntent(body:WriterRenewalIntentBody,genesis?:string):WriterRenewalIntent {return safe(()=>intent(body,false,genesis));}
|
|
125
|
+
export function validateWriterRenewalIntent(value:unknown,genesis?:string):WriterRenewalIntent {return safe(()=>intent(value,true,genesis));}
|
|
@@ -28,3 +28,17 @@ export const yieldTurn = (): Promise<void> => new Promise<void>(resolve => setIm
|
|
|
28
28
|
|
|
29
29
|
/** Journal records per atomic batch append before the next turn; the on-disk layout is the same as one batch (greedy chunk fill). */
|
|
30
30
|
export const PLACEMENT_APPEND_SLICE = 50;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* #470: a heavy pure function is written once as a step generator and driven two ways, so the synchronous API keeps its
|
|
34
|
+
* signature and the placement sync awaits a turn between steps. `drainSteps` ignores the step boundaries;
|
|
35
|
+
* `drainStepsAsync` hands the caller's loop back at each one. A fence or proof inside the function runs in the same order
|
|
36
|
+
* either way, because only the scheduling between steps differs.
|
|
37
|
+
*/
|
|
38
|
+
export function drainSteps<T>(steps: Generator<void, T, void>): T {
|
|
39
|
+
let next = steps.next(); while (!next.done) next = steps.next(); return next.value;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export async function drainStepsAsync<T>(steps: Generator<void, T, void>, pause: CooperativeYield = cooperativeYield()): Promise<T> {
|
|
43
|
+
let next = steps.next(); while (!next.done) { await pause(); next = steps.next(); } return next.value;
|
|
44
|
+
}
|
package/src/memory/sync.ts
CHANGED
|
@@ -13,6 +13,7 @@ import { memoryHome } from "./home.ts";
|
|
|
13
13
|
import { outboundScreen, screenOutboundRows, screenOwnSegment, type RowScreen } from "./sync-screen.ts";
|
|
14
14
|
import { shardSyncBinding } from "./sync-binding.ts";
|
|
15
15
|
import type { PlacementSyncBound } from "./sync-placement-bound.ts";
|
|
16
|
+
import type { PlacementJournalObjectComposition } from "./sync-placement-journal-storage.ts";
|
|
16
17
|
import type { SyncProgress, SyncProgressPhase } from "./sync-progress.ts";
|
|
17
18
|
import type { PlacementRefusalCategory } from "./sync-placement-refusal.ts";
|
|
18
19
|
|
|
@@ -27,7 +28,7 @@ export type Visibility = "public" | "private" | "unknown";
|
|
|
27
28
|
* parsing `error` text. `bound` carries its numbers in `placementPublication.bound`; `refusal` carries its fixed
|
|
28
29
|
* category; `unavailable` is any other refusal before an attempt (activation, inventory or I/O).
|
|
29
30
|
*/
|
|
30
|
-
export const SYNC_FAILURE_CAUSES = ["bound", "refusal", "unknown-outcome", "writer-renewal", "remote", "stopped", "unavailable"] as const;
|
|
31
|
+
export const SYNC_FAILURE_CAUSES = ["bound", "refusal", "unknown-outcome", "writer-renewal", "remote", "stopped", "unavailable", "checkpoint-pending"] as const;
|
|
31
32
|
export type SyncFailureCause = typeof SYNC_FAILURE_CAUSES[number];
|
|
32
33
|
export interface SyncResult { ok: boolean; pushed: boolean; entries: number; warning?: string; error?: string;
|
|
33
34
|
/** #462: set on every failed placement sync; absent on success and on the legacy transports. */
|
|
@@ -38,6 +39,8 @@ export interface SyncResult { ok: boolean; pushed: boolean; entries: number; war
|
|
|
38
39
|
lastPolicyHash?: string; lastPolicyCheckUnixMs?: number; policyCheckSource?: "live" | "durable-intent"; policyCeiling: "last-positive-check-before-in-flight-push"; recovered?: boolean;
|
|
39
40
|
/** #419: an expected size refusal before any publication attempt; numbers only. */
|
|
40
41
|
bound?: PlacementSyncBound;
|
|
42
|
+
/** #288 step 1: what held the whole epoch's objects when the journal-objects bound was measured; numbers only. */
|
|
43
|
+
journalObjects?: PlacementJournalObjectComposition;
|
|
41
44
|
/** #426: the fixed category and phase of a refusal before any publication attempt; no path, row or secret. */
|
|
42
45
|
refusal?: { category: PlacementRefusalCategory; phase: SyncProgressPhase } };
|
|
43
46
|
pruneApplication?: {transport:"durable"|"unconfirmed";proofComplete:number;projectionActive:number|null;nativeApplied:number|null;held:number;phase:"preflight"|"prepared"|"active"|"complete"};
|
|
@@ -18,8 +18,8 @@ const failureDetails:Record<SyncPlacementWriterFailureDetail,string>={
|
|
|
18
18
|
"invalid-version":"package version is not a supported plain release", "invalid-inventory":"root inventory is invalid or duplicated", "unsafe-runtime":"runtime files have unsafe types or symlinks",
|
|
19
19
|
"missing-runtime":"required bin/amem.js or src/index.ts is missing",bound:"inventory exceeds a supported bound",changed:"install changed during measurement",
|
|
20
20
|
};
|
|
21
|
-
function writerContextMessage(category:PlacementWriterRootCategory,causeClass:"missing"|"changed"|"unavailable",phase:PlacementWriterContextPhase,detail?:SyncPlacementWriterFailureDetail,renewalState?:"pending"|"staging"):string {
|
|
22
|
-
if(category==="writer renewal")return new SharedWriterRevisionError(renewalState==="staging"?"staging":"pending").message;
|
|
21
|
+
function writerContextMessage(category:PlacementWriterRootCategory,causeClass:"missing"|"changed"|"unavailable",phase:PlacementWriterContextPhase,detail?:SyncPlacementWriterFailureDetail,renewalState?:"pending"|"staging"|"checkpoint-pending"):string {
|
|
22
|
+
if(category==="writer renewal")return new SharedWriterRevisionError(renewalState==="staging"?"staging":renewalState==="checkpoint-pending"?"checkpoint-pending":"pending").message;
|
|
23
23
|
if(category==="active locator") return `Sync placement initial root locator is ${causeClass} (active locator category); have the person inspect sync-placement-writer-roots.json and the matching activation metadata with a compatible recovery release, then run amem migrate --sync-placement --dry-run.`;
|
|
24
24
|
if(category==="home floor") return `Sync placement reader-floor proof is ${causeClass} (home floor category); have the person inspect formats.json and use a reader compatible with its recorded floor, then run amem migrate --sync-placement --dry-run.`;
|
|
25
25
|
const cause=detail?`; ${failureDetails[detail]}`:"";
|
|
@@ -27,13 +27,13 @@ function writerContextMessage(category:PlacementWriterRootCategory,causeClass:"m
|
|
|
27
27
|
return `Sync placement writer proof is ${causeClass} (${category} category${cause}); restore the inventoried install, or have the person run amem migrate --sync-placement --dry-run and --apply with the complete --writer-root inventory after installing the required 0.22.0 home floor.`;
|
|
28
28
|
}
|
|
29
29
|
export class PlacementWriterContextError extends Error {
|
|
30
|
-
constructor(readonly category: PlacementWriterRootCategory, readonly causeClass: "missing" | "changed" | "unavailable",readonly phase:PlacementWriterContextPhase="active",readonly detail?:SyncPlacementWriterFailureDetail,readonly renewalState?:"pending"|"staging") {
|
|
30
|
+
constructor(readonly category: PlacementWriterRootCategory, readonly causeClass: "missing" | "changed" | "unavailable",readonly phase:PlacementWriterContextPhase="active",readonly detail?:SyncPlacementWriterFailureDetail,readonly renewalState?:"pending"|"staging"|"checkpoint-pending") {
|
|
31
31
|
super(writerContextMessage(category,causeClass,phase,detail,renewalState)); this.name = "PlacementWriterContextError";
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
function safeRefusal(error: unknown, category: PlacementWriterRootCategory,phase:PlacementWriterContextPhase="active"): PlacementWriterContextError {
|
|
35
35
|
if (error && typeof error === "object" && !types.isProxy(error) && (error instanceof PlacementHomeFloorError || error instanceof FormatFloorError)) return new PlacementWriterContextError("home floor","unavailable",phase);
|
|
36
|
-
if(error&&typeof error==="object"&&!types.isProxy(error)&&error instanceof SharedWriterRevisionError){const code=Object.getOwnPropertyDescriptor(error,"code")?.value;if(code==="pending"||code==="staging")return new PlacementWriterContextError("writer renewal","unavailable",phase,undefined,code);}
|
|
36
|
+
if(error&&typeof error==="object"&&!types.isProxy(error)&&error instanceof SharedWriterRevisionError){const code=Object.getOwnPropertyDescriptor(error,"code")?.value;if(code==="pending"||code==="staging"||code==="checkpoint-pending")return new PlacementWriterContextError("writer renewal","unavailable",phase,undefined,code);}
|
|
37
37
|
if (error && typeof error === "object" && !types.isProxy(error) && error instanceof PlacementWriterContextError) {
|
|
38
38
|
const fields=Object.getOwnPropertyDescriptors(error),root=fields.category,cause=fields.causeClass,detail=fields.detail;
|
|
39
39
|
const category:unknown=root&&"value"in root?root.value:undefined,causeClass:unknown=cause&&"value"in cause?cause.value:undefined;
|
|
@@ -41,7 +41,7 @@ function safeRefusal(error: unknown, category: PlacementWriterRootCategory,phase
|
|
|
41
41
|
&& typeof causeClass==="string" && ["missing","changed","unavailable"].includes(causeClass)) {
|
|
42
42
|
const ownDetail=detail&&"value"in detail&&typeof detail.value==="string"&&Object.hasOwn(failureDetails,detail.value)?detail.value as SyncPlacementWriterFailureDetail:undefined;
|
|
43
43
|
const state=fields.renewalState?.value;
|
|
44
|
-
return new PlacementWriterContextError(category as PlacementWriterRootCategory,causeClass as PlacementWriterContextError["causeClass"],phase,ownDetail,state==="staging"||state==="pending"?state:undefined);
|
|
44
|
+
return new PlacementWriterContextError(category as PlacementWriterRootCategory,causeClass as PlacementWriterContextError["causeClass"],phase,ownDetail,state==="staging"||state==="pending"||state==="checkpoint-pending"?state:undefined);
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
return new PlacementWriterContextError(category,"unavailable",phase);
|
package/src/ui/plugin.ts
CHANGED
|
@@ -95,7 +95,7 @@ export const plugin = {
|
|
|
95
95
|
{ id: "timeline", title: "Timeline", order: 4 },
|
|
96
96
|
{ id: "work", title: "Work lists", order: 5 },
|
|
97
97
|
{ id: "goals", title: "Goals", order: 6 },
|
|
98
|
-
{ id: "capacity", title: "Capacity", order: 7 },
|
|
98
|
+
{ id: "capacity", title: "Capacity", order: 7, maxAgeMs: 15_000 },
|
|
99
99
|
],
|
|
100
100
|
commands: [
|
|
101
101
|
{ id: "gc", title: "Evict expired capture rows", hint: "amem gc", action: "gc" },
|