@staix/agent-mem 0.33.0 → 0.34.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 +2 -2
- package/package.json +1 -1
- package/src/amem-read-tools.ts +20 -0
- package/src/cli.ts +13 -4
- package/src/hook-jcode-journal.ts +8 -2
- package/src/hook-spool.ts +5 -0
- package/src/hooks.ts +16 -3
- package/src/mcp-memory.ts +50 -6
- package/src/mcp.ts +2 -2
- package/src/memory/binding-read-set.ts +18 -0
- package/src/memory/commands.ts +19 -7
- package/src/memory/doctor.ts +26 -2
- package/src/memory/home-binding-fence.ts +97 -0
- package/src/memory/intent-brief.ts +26 -11
- package/src/memory/intent-node-matcher.ts +62 -0
- package/src/memory/metrics.ts +4 -1
- package/src/memory/public-prune-input-chain.ts +4 -1
- package/src/memory/public-prune-view.ts +6 -1
- package/src/memory/recall-staleness.ts +18 -7
- package/src/memory/sync-placement-active.ts +4 -1
- package/src/memory/sync-placement-capture.ts +17 -6
- package/src/memory/sync-placement-guard.ts +16 -1
- package/src/session-brief.ts +47 -7
- package/src/setup.ts +32 -4
- package/src/sync-placement-writer-context.ts +86 -14
- package/src/ui/plugin.ts +1 -1
|
@@ -4,6 +4,7 @@ import { fileURLToPath } from "node:url";
|
|
|
4
4
|
import { canonicalPath, realPath } from "./memory/platform.ts";
|
|
5
5
|
import { canonicalJSON } from "./memory/generation.ts";
|
|
6
6
|
import { readSetupWriterRoots, SETUP_TARGETS, setupReceiptRemedy, SetupWriterRootsError, type SetupTarget } from "./setup.ts";
|
|
7
|
+
import { placementMarkerState } from "./memory/sync-placement-guard.ts";
|
|
7
8
|
import { measureSyncPlacementWriters, extractSyncPlacementWriterFailure, type SyncPlacementWriterFailureDetail, type SyncPlacementWriterMeasurement } from "./memory/sync-placement-writers.ts";
|
|
8
9
|
import { readEffectiveSyncPlacementWriters } from "./memory/sync-placement-effective-writers.ts";
|
|
9
10
|
import { PlacementHomeFloorError, requirePlacementHomeFloor } from "./memory/sync-placement-prerequisites.ts";
|
|
@@ -19,14 +20,18 @@ const failureDetails:Record<SyncPlacementWriterFailureDetail,string>={
|
|
|
19
20
|
"missing-runtime":"required bin/amem.js or src/index.ts is missing",bound:"inventory exceeds a supported bound",changed:"install changed during measurement",
|
|
20
21
|
};
|
|
21
22
|
function writerContextMessage(category:PlacementWriterRootCategory,causeClass:"missing"|"changed"|"unavailable",phase:PlacementWriterContextPhase,detail?:SyncPlacementWriterFailureDetail,renewalState?:"pending"|"staging"|"checkpoint-pending",setupTarget?:SetupTarget):string {
|
|
22
|
-
|
|
23
|
+
// #551 AC1: the shared revision text names neither this category nor its cause class, so both are printed here and the
|
|
24
|
+
// shared text (which carries its own remedy) follows. The checkpoint message is still reproduced verbatim, never replaced.
|
|
25
|
+
if(category==="writer renewal")return `Sync placement ${phase==="initial"?"initial ":""}writer proof is ${causeClass} (writer renewal category); ${new SharedWriterRevisionError(renewalState==="staging"?"staging":renewalState==="checkpoint-pending"?"checkpoint-pending":"pending").message}`;
|
|
23
26
|
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
27
|
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
28
|
const cause=detail?`; ${failureDetails[detail]}`:"";
|
|
26
|
-
// #520: a receipt whose recorded install root is gone names its target and remedy, never the recorded path.
|
|
29
|
+
// #520: a receipt whose recorded install root is gone names its target and remedy, never the recorded path. #551 keeps that
|
|
30
|
+
// sentence - its cause marker, its remedy and its next step - behind the fixed category and cause class, so both surfaces
|
|
31
|
+
// print one sentence and neither loses the established remedy.
|
|
27
32
|
const receipt=category==="setup receipt"&&setupTarget?setupReceiptRemedy(setupTarget):undefined;
|
|
28
33
|
if(phase==="initial")return `Sync placement initial writer proof is ${causeClass} (${category} category${cause}); ${receipt??(category==="setup receipt"?"upgrade or repair the managed amem install and its host exact pin, then rerun amem setup <target> --apply":"upgrade or repair the amem install and its host exact pin")}. Declare the complete writer roots and rerun amem migrate --sync-placement --dry-run.`;
|
|
29
|
-
if(receipt)return `Sync placement writer proof is ${causeClass} (${category} category${cause}); ${receipt}; then rerun the sync.`;
|
|
34
|
+
if(receipt)return `Sync placement writer proof is ${causeClass} (${category} category${cause}); Placement sync refused [cause: setup_receipt_missing_install]: ${receipt}; then rerun the sync.`;
|
|
30
35
|
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.`;
|
|
31
36
|
}
|
|
32
37
|
export class PlacementWriterContextError extends Error {
|
|
@@ -46,20 +51,85 @@ export function placementSyncFailure(refusal: PlacementWriterContextError, failu
|
|
|
46
51
|
* #520: the fixed-data text a marked session gets when a placement refusal comes from an applied setup receipt whose
|
|
47
52
|
* recorded amem install no longer exists. Fields are read as own properties and validated against closed sets, so a
|
|
48
53
|
* caught message, a recorded path or a forged target never reaches the text; every other failure returns undefined and
|
|
49
|
-
* keeps the generic masked refusal.
|
|
54
|
+
* keeps the generic masked refusal. #551 AC1: the sentence is the shared one, so it carries the fixed category and cause
|
|
55
|
+
* class in front of #520's marker, remedy and next step.
|
|
50
56
|
*/
|
|
51
57
|
export function markedSetupReceiptRefusal(error: unknown): string | undefined {
|
|
52
|
-
const
|
|
53
|
-
return
|
|
58
|
+
const receipt = setupReceiptRefusal(error);
|
|
59
|
+
return receipt === undefined ? undefined : writerContextMessage("setup receipt","unavailable",receipt.phase,receipt.detail,undefined,receipt.target);
|
|
54
60
|
}
|
|
55
|
-
function
|
|
61
|
+
function setupReceiptRefusal(error: unknown): { target: SetupTarget; phase: PlacementWriterContextPhase; detail?: SyncPlacementWriterFailureDetail } | undefined {
|
|
56
62
|
if (!error || typeof error !== "object" || types.isProxy(error)) return undefined;
|
|
57
|
-
const carried = Object.getOwnPropertyDescriptor(error, "placementRefusal")?.value;
|
|
63
|
+
const carried: unknown = Object.getOwnPropertyDescriptor(error, "placementRefusal")?.value;
|
|
58
64
|
const refusal: unknown = carried && typeof carried === "object" && !types.isProxy(carried) ? carried : error;
|
|
59
65
|
if (refusal === null || typeof refusal !== "object") return undefined;
|
|
60
|
-
const fields = Object.getOwnPropertyDescriptors(refusal), target: unknown = fields.setupTarget?.value;
|
|
61
|
-
|
|
62
|
-
|
|
66
|
+
const fields = Object.getOwnPropertyDescriptors(refusal), target: unknown = fields.setupTarget?.value, detail: unknown = fields.detail?.value;
|
|
67
|
+
if (fields.category?.value !== "setup receipt" || fields.causeClass?.value !== "unavailable") return undefined;
|
|
68
|
+
if (typeof target !== "string" || !(SETUP_TARGETS as readonly string[]).includes(target)) return undefined;
|
|
69
|
+
return { target: target as SetupTarget, phase: fields.phase?.value === "initial" ? "initial" : "active",
|
|
70
|
+
...(typeof detail === "string" && Object.hasOwn(failureDetails, detail) ? { detail: detail as SyncPlacementWriterFailureDetail } : {}) };
|
|
71
|
+
}
|
|
72
|
+
const WRITER_ROOT_CATEGORIES=["running CLI","host package","setup receipt","declared writer","active locator","home floor","writer renewal"] as const satisfies readonly PlacementWriterRootCategory[];
|
|
73
|
+
const WRITER_CAUSE_CLASSES=["missing","changed","unavailable"] as const;
|
|
74
|
+
/**
|
|
75
|
+
* #551 AC1: the refusal as fixed own data for a person-facing surface. A real PlacementWriterContextError - or the one a
|
|
76
|
+
* later sync failure carries as `placementRefusal` - is rebuilt from its own validated fields, so a tampered message, a
|
|
77
|
+
* forged category or a recorded path never reaches the text; anything else returns undefined and keeps its own handling.
|
|
78
|
+
* A proxy is refused before any instanceof, prototype or property inspection, including a proxy carried as
|
|
79
|
+
* `placementRefusal`, so a throwing trap can never run here.
|
|
80
|
+
* Module-internal: the two surfaces reach it through `placementWriterRefusalText` and `placementWriterVerification` only.
|
|
81
|
+
*/
|
|
82
|
+
function placementWriterRefusal(error: unknown): PlacementWriterContextError | undefined {
|
|
83
|
+
if (!error || typeof error !== "object" || types.isProxy(error)) return undefined;
|
|
84
|
+
const carried: unknown = Object.getOwnPropertyDescriptor(error, "placementRefusal")?.value;
|
|
85
|
+
const candidate: unknown = carried !== null && typeof carried === "object" && !types.isProxy(carried) && carried instanceof PlacementWriterContextError ? carried : error;
|
|
86
|
+
if (!(candidate instanceof PlacementWriterContextError)) return undefined;
|
|
87
|
+
const fields = Object.getOwnPropertyDescriptors(candidate), category = fields.category?.value, causeClass = fields.causeClass?.value;
|
|
88
|
+
if (typeof category !== "string" || !(WRITER_ROOT_CATEGORIES as readonly string[]).includes(category)) return undefined;
|
|
89
|
+
if (typeof causeClass !== "string" || !(WRITER_CAUSE_CLASSES as readonly string[]).includes(causeClass)) return undefined;
|
|
90
|
+
const detail = fields.detail?.value, state = fields.renewalState?.value, target = fields.setupTarget?.value;
|
|
91
|
+
return new PlacementWriterContextError(category as PlacementWriterRootCategory, causeClass as PlacementWriterContextError["causeClass"],
|
|
92
|
+
fields.phase?.value === "initial" ? "initial" : "active",
|
|
93
|
+
typeof detail === "string" && Object.hasOwn(failureDetails, detail) ? detail as SyncPlacementWriterFailureDetail : undefined,
|
|
94
|
+
state === "staging" || state === "pending" || state === "checkpoint-pending" ? state : undefined,
|
|
95
|
+
typeof target === "string" && (SETUP_TARGETS as readonly string[]).includes(target) ? target as SetupTarget : undefined);
|
|
96
|
+
}
|
|
97
|
+
/** #551: no category is claimed here, because the state could not be read far enough to name one. */
|
|
98
|
+
const PLACEMENT_WRITER_UNVERIFIED_TEXT = "Placement writer verification could not establish a category: the retained writer inventory or its history could not be read far enough to name one; have the person inspect the home with a compatible release, then run amem migrate --sync-placement --dry-run.";
|
|
99
|
+
/** An inventory state that could not be proven: never reported as a missing root, and never given an invented category. */
|
|
100
|
+
class UnprovenWriterInventory extends Error { constructor(){ super(PLACEMENT_WRITER_UNVERIFIED_TEXT); this.name="UnprovenWriterInventory"; } }
|
|
101
|
+
/** A shared writer-history code outside the three renewal states: `safeRefusal` would otherwise assert the locator category for it. */
|
|
102
|
+
function unprovenWriterHistory(error: unknown): boolean {
|
|
103
|
+
if (!error || typeof error !== "object" || types.isProxy(error) || !(error instanceof SharedWriterRevisionError)) return false;
|
|
104
|
+
const code = Object.getOwnPropertyDescriptor(error, "code")?.value;
|
|
105
|
+
return code !== "pending" && code !== "staging" && code !== "checkpoint-pending";
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* #551 AC1: the fixed text `amem sync` and `amem doctor` report, one sentence per category, rebuilt rather than echoed.
|
|
109
|
+
* #520's receipt case rides inside that same sentence - its cause marker, its target's remedy and its next step - so a
|
|
110
|
+
* marked and an unmarked run print one text instead of two, and its shape-only entry point stays the fallback for a
|
|
111
|
+
* refusal built by another copy of this module.
|
|
112
|
+
*/
|
|
113
|
+
export function placementWriterRefusalText(error: unknown): string | undefined {
|
|
114
|
+
if (!types.isProxy(error) && error instanceof UnprovenWriterInventory) return PLACEMENT_WRITER_UNVERIFIED_TEXT;
|
|
115
|
+
return placementWriterRefusal(error)?.message ?? markedSetupReceiptRefusal(error);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* #551: the writer verification a sync on this home would perform, as data. `missing` is reported only after the inventory
|
|
119
|
+
* was read and compared, so an unreadable one never claims a root is absent; an unproven state asserts no category at all.
|
|
120
|
+
*/
|
|
121
|
+
export function placementWriterVerification(home: string, ownRoot: string):
|
|
122
|
+
{ writers: number; refusal?: undefined; unverified?: undefined }
|
|
123
|
+
| { writers?: undefined; refusal: PlacementWriterContextError; unverified?: undefined }
|
|
124
|
+
| { writers?: undefined; refusal?: undefined; unverified: string } {
|
|
125
|
+
// #551: a marker this home cannot prove proves no category either, so it is unverified before any measurement is attempted.
|
|
126
|
+
if (placementMarkerState(home) === "unverified") return { unverified: PLACEMENT_WRITER_UNVERIFIED_TEXT };
|
|
127
|
+
try { return { writers: activePlacementWriterContext(home, ownRoot).measurement.writers.length }; }
|
|
128
|
+
catch (error) {
|
|
129
|
+
if (!types.isProxy(error) && error instanceof UnprovenWriterInventory) return { unverified: PLACEMENT_WRITER_UNVERIFIED_TEXT };
|
|
130
|
+
const refusal = placementWriterRefusal(error);
|
|
131
|
+
return refusal ? { refusal } : { unverified: PLACEMENT_WRITER_UNVERIFIED_TEXT };
|
|
132
|
+
}
|
|
63
133
|
}
|
|
64
134
|
function safeRefusal(error: unknown, category: PlacementWriterRootCategory,phase:PlacementWriterContextPhase="active"): PlacementWriterContextError {
|
|
65
135
|
if (error && typeof error === "object" && !types.isProxy(error) && (error instanceof PlacementHomeFloorError || error instanceof FormatFloorError)) return new PlacementWriterContextError("home floor","unavailable",phase);
|
|
@@ -67,8 +137,8 @@ function safeRefusal(error: unknown, category: PlacementWriterRootCategory,phase
|
|
|
67
137
|
if (error && typeof error === "object" && !types.isProxy(error) && error instanceof PlacementWriterContextError) {
|
|
68
138
|
const fields=Object.getOwnPropertyDescriptors(error),root=fields.category,cause=fields.causeClass,detail=fields.detail;
|
|
69
139
|
const category:unknown=root&&"value"in root?root.value:undefined,causeClass:unknown=cause&&"value"in cause?cause.value:undefined;
|
|
70
|
-
if (typeof category==="string" &&
|
|
71
|
-
&& typeof causeClass==="string" && [
|
|
140
|
+
if (typeof category==="string" && (WRITER_ROOT_CATEGORIES as readonly string[]).includes(category)
|
|
141
|
+
&& typeof causeClass==="string" && (WRITER_CAUSE_CLASSES as readonly string[]).includes(causeClass)) {
|
|
72
142
|
const ownDetail=detail&&"value"in detail&&typeof detail.value==="string"&&Object.hasOwn(failureDetails,detail.value)?detail.value as SyncPlacementWriterFailureDetail:undefined;
|
|
73
143
|
const state=fields.renewalState?.value,target=fields.setupTarget?.value;
|
|
74
144
|
return new PlacementWriterContextError(category as PlacementWriterRootCategory,causeClass as PlacementWriterContextError["causeClass"],phase,ownDetail,state==="staging"||state==="pending"||state==="checkpoint-pending"?state:undefined,
|
|
@@ -133,7 +203,9 @@ export function activePlacementWriterContext(home: string, ownRoot: string): Pla
|
|
|
133
203
|
const read = () => {
|
|
134
204
|
try { requirePlacementHomeFloor(home); } catch (error) { throw safeRefusal(error,"home floor"); }
|
|
135
205
|
let effective: ReturnType<typeof readEffectiveSyncPlacementWriters>;
|
|
136
|
-
try { effective=readEffectiveSyncPlacementWriters(home); }
|
|
206
|
+
try { effective=readEffectiveSyncPlacementWriters(home); }
|
|
207
|
+
// #551: an unreadable writer history proves no category, so it is never reported as a missing or unreadable locator.
|
|
208
|
+
catch (error) { if (unprovenWriterHistory(error)) throw new UnprovenWriterInventory(); throw safeRefusal(error,"active locator"); }
|
|
137
209
|
const roots=effective.roots;if(!roots)return fail("active locator","unavailable");
|
|
138
210
|
const needed = required(home,ownRoot);
|
|
139
211
|
if(!roots.includes(needed.own))return fail("running CLI","missing");
|
package/src/ui/plugin.ts
CHANGED
|
@@ -282,7 +282,7 @@ export const plugin = {
|
|
|
282
282
|
if (!q) return { q: "", hits: [] };
|
|
283
283
|
return { q, ...(await read(project, "amem_search", { ...args, query: q }) as Args) };
|
|
284
284
|
}
|
|
285
|
-
case "timeline": return { entries: await read(project, "amem_timeline", args) };
|
|
285
|
+
case "timeline": return { entries: await read(project, "amem_timeline", { ...args, expand: true }) }; // #544: the panel lists raw rows; capture-run summaries are for MCP and agent reads.
|
|
286
286
|
case "work": return { lists: await read(project, "amem_work_state_read", args) };
|
|
287
287
|
case "goals": {
|
|
288
288
|
const store = openCuratedForRead(base, project), p = policy();
|