@staix/agent-mem 0.26.1 → 0.26.2
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/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Curated memory with append-only JSONL logs, a derived SQLite index, short- and long-term tiers, a typed graph, goals with leases, and git sync between machines. Extracted from [agent-hub](https://github.com/STAIxBWLB/agent-hub), with compatible storage and entry IDs.
|
|
4
4
|
|
|
5
5
|
<!-- facts:version -->
|
|
6
|
-
Version: 0.26.
|
|
6
|
+
Version: 0.26.2. Requires Bun 1.4.2 or later; no runtime dependencies.
|
|
7
7
|
<!-- /facts:version -->
|
|
8
8
|
|
|
9
9
|
## Quick start
|
package/package.json
CHANGED
package/src/memory/bridge.ts
CHANGED
|
@@ -62,11 +62,13 @@ export class SegmentReader {
|
|
|
62
62
|
/** Optional inspection limits do not change ordinary incremental-reader semantics. */
|
|
63
63
|
readonly sourceByteLimit?: number;
|
|
64
64
|
readonly sourceFileLimit?: number;
|
|
65
|
+
private readonly sourceRowLimit?: number;
|
|
65
66
|
constructor(private remainingBytes = Infinity, limits: { maxSourceBytes?: number; maxRows?: number } = {}) {
|
|
66
67
|
for (const value of [remainingBytes, limits.maxSourceBytes ?? Infinity, limits.maxRows ?? Infinity]) if (value !== Infinity && (!Number.isSafeInteger(value) || value < 0)) failure();
|
|
67
68
|
this.sourceByteLimit = limits.maxSourceBytes;
|
|
68
69
|
this.remainingSourceBytes = limits.maxSourceBytes ?? Infinity;
|
|
69
70
|
this.remainingRows = limits.maxRows ?? Infinity;
|
|
71
|
+
this.sourceRowLimit = limits.maxRows;
|
|
70
72
|
this.sourceFileLimit = limits.maxRows;
|
|
71
73
|
this.remainingFiles = limits.maxRows ?? Infinity;
|
|
72
74
|
}
|
|
@@ -113,7 +115,7 @@ export class SegmentReader {
|
|
|
113
115
|
if (!read(end).equals(bytes) || fstatSync(fd, { bigint: true }).size < opened.size) failure();
|
|
114
116
|
// Count physical nonblank source rows before any canonical source map can grow.
|
|
115
117
|
if (this.remainingRows !== Infinity) for (const line of completeLines(bytes)) if (line.toString("utf8").trim()) {
|
|
116
|
-
if (this.remainingRows < 1) throw new SegmentReadBudgetError({ kind: "rows", limit: this.
|
|
118
|
+
if (this.remainingRows < 1) throw new SegmentReadBudgetError({ kind: "rows", limit: this.sourceRowLimit!, observed: this.sourceRows + 1 });
|
|
117
119
|
this.remainingRows--; this.sourceRows++;
|
|
118
120
|
}
|
|
119
121
|
const after = lstatSync(path, { bigint: true });
|
|
@@ -22,6 +22,19 @@ import { assertPlacementRuntime } from "./sync-placement-guard.ts";
|
|
|
22
22
|
import { activationSourceMarkers, assertPlacementActivationOwner, type PlacementActivationOwner, type PlacementActivationCaptureProof } from "./sync-placement-activation-proof.ts";
|
|
23
23
|
import { readEffectiveSyncPlacementWriters, writerBoundPlacementContextHash, writerInventoryEvidence, type EffectiveSyncPlacementWriters } from "./sync-placement-effective-writers.ts";
|
|
24
24
|
import { SharedWriterRevisionError } from "./sync-placement-writer-revision-format.ts";
|
|
25
|
+
import { inspectionBoundReceipt, type InspectionBound } from "./inspection-bound.ts";
|
|
26
|
+
|
|
27
|
+
/** Home-wide source capture ceilings. Every file is read twice (bytes, then a stable recheck), so the read budget is 2x. */
|
|
28
|
+
export const PLACEMENT_CAPTURE_MAX_SOURCE_BYTES = 64 * 1024 * 1024, PLACEMENT_CAPTURE_MAX_ROWS = 20000;
|
|
29
|
+
/** Source capture refusal before any effect. Code stays "bound" for existing callers; the message names the phase and bound. */
|
|
30
|
+
export class PlacementSourceBoundError extends SyncPlacementJournalError {
|
|
31
|
+
constructor(readonly bound?: InspectionBound) {
|
|
32
|
+
super("bound");
|
|
33
|
+
const detail = bound ? `${bound.kind} bound (observed ${bound.observed}, limit ${bound.limit})` : "read bound";
|
|
34
|
+
this.message = `Sync placement source capture exceeds its supported ${detail}; no journal, marker or source was changed. This is not journal corruption; retain the inputs and report this bound.`;
|
|
35
|
+
this.name = "PlacementSourceBoundError";
|
|
36
|
+
}
|
|
37
|
+
}
|
|
25
38
|
|
|
26
39
|
/** Host authentication/compatibility facts are re-read at every effect boundary, never inferred from a session marker. */
|
|
27
40
|
export interface PlacementCapturePort {
|
|
@@ -64,12 +77,14 @@ function ownedDirectory(dir: string): BigIntStats {
|
|
|
64
77
|
if (!s.isDirectory() || s.isSymbolicLink() || s.uid !== BigInt(process.getuid!()) || (s.mode & 0o022n) !== 0n) fail();
|
|
65
78
|
return s;
|
|
66
79
|
}
|
|
67
|
-
/** ponytail: capture
|
|
68
|
-
*
|
|
80
|
+
/** ponytail: capture holds the whole home in memory, capped at 256 metadata objects and 64 MiB/20000 source rows
|
|
81
|
+
* across all realms (#414 raised 8 MiB; a 23 MB/10,248-row home was refused). Larger homes need a reviewed
|
|
82
|
+
* chunked/streaming activation proof; no input is silently omitted at this ceiling. */
|
|
69
83
|
function sourcePreview(homeInput: string, selected?: readonly PlacementRealm[], pending: readonly PlacementPendingSource[] = [], policyVersion?: string, ownerProof?: PlacementActivationCaptureProof, sourceOwner?:PlacementActivationOwner): PlacementSourcePreview {
|
|
70
84
|
let selection: PlacementRealm[] | undefined;
|
|
71
85
|
if (selected !== undefined) {
|
|
72
|
-
if (!Array.isArray(selected) || types.isProxy(selected)
|
|
86
|
+
if (!Array.isArray(selected) || types.isProxy(selected)) fail();
|
|
87
|
+
if (selected.length > 256) throw new PlacementSourceBoundError({ kind: "source-files", limit: 256, observed: selected.length });
|
|
73
88
|
const copied = memoryPolicySnapshot(selected); if (!copied) fail();
|
|
74
89
|
selection = copied.map(realm => validatePlacementKey({ realm, id: "0".repeat(32), rowHash: "0".repeat(64) }).realm);
|
|
75
90
|
if (!selection.length || new Set(selection.map(realm => canonicalJSON(realm))).size !== selection.length) fail();
|
|
@@ -87,7 +102,9 @@ function sourcePreview(homeInput: string, selected?: readonly PlacementRealm[],
|
|
|
87
102
|
const bytes = (file: string, optional = false): Buffer | undefined => {
|
|
88
103
|
const before = lstatSync(file, { bigint: true, throwIfNoEntry: false });
|
|
89
104
|
if (!before) { if (!optional) fail(); facts.push([file, null]); sourceChecks.push(() => { if(lstatSync(file,{throwIfNoEntry:false})) fail(); }); return undefined; }
|
|
90
|
-
if (++metadataObjects > 256
|
|
105
|
+
if (++metadataObjects > 256) throw new PlacementSourceBoundError({ kind: "source-files", limit: 256, observed: metadataObjects });
|
|
106
|
+
if (before.size > 262144n) throw new PlacementSourceBoundError({ kind: "metadata-bytes", limit: 262144, observed: Number(before.size) });
|
|
107
|
+
if (metadataBytes + Number(before.size) > 8 * 1024 * 1024) throw new PlacementSourceBoundError({ kind: "metadata-bytes", limit: 8 * 1024 * 1024, observed: metadataBytes + Number(before.size) });
|
|
91
108
|
if (!before.isFile() || before.isSymbolicLink() || before.nlink !== 1n || before.uid !== root.uid || (before.mode & 0o022n) !== 0n) fail();
|
|
92
109
|
const fd = openSync(file, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
|
|
93
110
|
try {
|
|
@@ -137,7 +154,7 @@ function sourcePreview(homeInput: string, selected?: readonly PlacementRealm[],
|
|
|
137
154
|
if(name==="profile.lock"&&sourceOwner){assertPlacementActivationOwner(sourceOwner,home);continue;}
|
|
138
155
|
if (lstatSync(join(home,name),{throwIfNoEntry:false})) fail();
|
|
139
156
|
}
|
|
140
|
-
const reader = new SegmentReader(
|
|
157
|
+
const reader = new SegmentReader(2 * PLACEMENT_CAPTURE_MAX_SOURCE_BYTES, { maxSourceBytes: PLACEMENT_CAPTURE_MAX_SOURCE_BYTES, maxRows: PLACEMENT_CAPTURE_MAX_ROWS });
|
|
141
158
|
const rows = new Map<string, PlacementSourceRow>(), specialRows = new Map<string, PlacementSpecialSourceRow>(), sourceRowsByRealm = new Map<string, readonly PruneSourceRow[]>();
|
|
142
159
|
const directories = [home], prefixes: PlacementPublicationSource[] = [];
|
|
143
160
|
const realms: SyncPlacementActivationContext["realms"][number][] = [];
|
|
@@ -147,7 +164,7 @@ function sourcePreview(homeInput: string, selected?: readonly PlacementRealm[],
|
|
|
147
164
|
directoryFact(dir); const listStamp = lstatSync(dir,{bigint:true});
|
|
148
165
|
sourceChecks.push(() => { if(!same(listStamp,lstatSync(dir,{bigint:true}))) fail(); });
|
|
149
166
|
const iterator = opendirSync(dir), names: string[] = [];
|
|
150
|
-
try { for (;;) { const item = iterator.readSync(); if (!item) break; if (names.length >= 256)
|
|
167
|
+
try { for (;;) { const item = iterator.readSync(); if (!item) break; if (names.length >= 256) throw new PlacementSourceBoundError({ kind: "source-files", limit: 256, observed: names.length + 1 }); names.push(item.name); } }
|
|
151
168
|
finally { iterator.closeSync(); }
|
|
152
169
|
names.sort(); facts.push([dir, names]); return names;
|
|
153
170
|
};
|
|
@@ -300,7 +317,7 @@ function previewSources(home:string,owner?:PlacementActivationOwner):PlacementSo
|
|
|
300
317
|
catch (error) {
|
|
301
318
|
if (error && typeof error === "object" && !types.isProxy(error)) {
|
|
302
319
|
if (error instanceof SyncPlacementJournalError) throw error;
|
|
303
|
-
if (error instanceof SegmentReadBudgetError)
|
|
320
|
+
if (error instanceof SegmentReadBudgetError) throw new PlacementSourceBoundError(inspectionBoundReceipt(error));
|
|
304
321
|
}
|
|
305
322
|
return fail();
|
|
306
323
|
}
|
|
@@ -352,7 +369,7 @@ export function captureSyncPlacementContext(home: string, port: PlacementCapture
|
|
|
352
369
|
if (error && typeof error === "object" && !types.isProxy(error)) {
|
|
353
370
|
if(error instanceof SharedWriterRevisionError){const code=Object.getOwnPropertyDescriptor(error,"code")?.value;if(code==="staging"||code==="pending")throw new SharedWriterRevisionError(code);}
|
|
354
371
|
if (error instanceof SyncPlacementJournalError) throw error;
|
|
355
|
-
if (error instanceof SegmentReadBudgetError)
|
|
372
|
+
if (error instanceof SegmentReadBudgetError) throw new PlacementSourceBoundError(inspectionBoundReceipt(error));
|
|
356
373
|
}
|
|
357
374
|
return fail();
|
|
358
375
|
}
|
|
@@ -366,7 +383,7 @@ export function captureSyncPlacementActivationContext(home: string, port: Placem
|
|
|
366
383
|
} catch (error) {
|
|
367
384
|
if (error && typeof error === "object" && !types.isProxy(error)) {
|
|
368
385
|
if (error instanceof SyncPlacementJournalError) throw error;
|
|
369
|
-
if (error instanceof SegmentReadBudgetError)
|
|
386
|
+
if (error instanceof SegmentReadBudgetError) throw new PlacementSourceBoundError(inspectionBoundReceipt(error));
|
|
370
387
|
}
|
|
371
388
|
return fail();
|
|
372
389
|
}
|
|
@@ -64,7 +64,7 @@ const remedies: Record<SyncPlacementInspectionIncompleteReason, string> = {
|
|
|
64
64
|
"placement-not-active": "Placement is not active; complete the person-reviewed shard/public-prune migrations and separately authorized placement activation before inspecting placement.",
|
|
65
65
|
"binding-changed": "Selected placement bindings changed; inspect the retained activation to restore matching markers when required, then reopen the selected project/user handles and inspect again.",
|
|
66
66
|
"input-unavailable": "Selected source or placement-context inputs are unreadable, incomplete or unsupported; inspect retained source metadata and any recorded partial request, verify compatible writer pins, then inspect again.",
|
|
67
|
-
"input-bound": "Placement inspection exceeds its supported
|
|
67
|
+
"input-bound": "Placement inspection exceeds its supported 64 MiB/20000-row source-capture or retained-evidence bounds; request a person-reviewed bounded epoch transition before inspecting again.",
|
|
68
68
|
"input-changed": "The selected placement inspection context changed; wait for stable source, journal and policy bindings, then inspect again.",
|
|
69
69
|
"journal-unavailable": "The retained placement journal is incomplete or inconsistent; preserve it and resume its exact recorded request with a compatible runtime before inspecting again.",
|
|
70
70
|
"policy-unavailable": "The policy callback/version or configured/default-deny epoch is unavailable or changed; restore a stable policy and policyVersion before inspecting again.",
|