agent-recall-core 3.4.51 → 3.5.3
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 +670 -330
- package/dist/digest/match.d.ts +2 -0
- package/dist/digest/match.d.ts.map +1 -1
- package/dist/digest/match.js +5 -0
- package/dist/digest/match.js.map +1 -1
- package/dist/digest/store.d.ts.map +1 -1
- package/dist/digest/store.js +2 -3
- package/dist/digest/store.js.map +1 -1
- package/dist/embeddings/config.d.ts.map +1 -1
- package/dist/embeddings/config.js +17 -4
- package/dist/embeddings/config.js.map +1 -1
- package/dist/helpers/alignment-patterns.d.ts +46 -0
- package/dist/helpers/alignment-patterns.d.ts.map +1 -1
- package/dist/helpers/alignment-patterns.js +103 -2
- package/dist/helpers/alignment-patterns.js.map +1 -1
- package/dist/helpers/journal-files.d.ts +12 -6
- package/dist/helpers/journal-files.d.ts.map +1 -1
- package/dist/helpers/journal-files.js +13 -7
- package/dist/helpers/journal-files.js.map +1 -1
- package/dist/index.d.ts +23 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +23 -5
- package/dist/index.js.map +1 -1
- package/dist/palace/rooms.d.ts +7 -0
- package/dist/palace/rooms.d.ts.map +1 -1
- package/dist/palace/rooms.js +13 -0
- package/dist/palace/rooms.js.map +1 -1
- package/dist/prompts/consolidation-prompt.js +14 -14
- package/dist/retrieval/candidates.d.ts +17 -0
- package/dist/retrieval/candidates.d.ts.map +1 -1
- package/dist/retrieval/candidates.js +4 -2
- package/dist/retrieval/candidates.js.map +1 -1
- package/dist/retrieval/contradiction.d.ts +42 -0
- package/dist/retrieval/contradiction.d.ts.map +1 -1
- package/dist/retrieval/contradiction.js +126 -7
- package/dist/retrieval/contradiction.js.map +1 -1
- package/dist/retrieval/lexical-index.d.ts +150 -0
- package/dist/retrieval/lexical-index.d.ts.map +1 -0
- package/dist/retrieval/lexical-index.js +516 -0
- package/dist/retrieval/lexical-index.js.map +1 -0
- package/dist/retrieval/query-memory.d.ts +17 -7
- package/dist/retrieval/query-memory.d.ts.map +1 -1
- package/dist/retrieval/query-memory.js +279 -71
- package/dist/retrieval/query-memory.js.map +1 -1
- package/dist/storage/classification.d.ts.map +1 -1
- package/dist/storage/classification.js +6 -1
- package/dist/storage/classification.js.map +1 -1
- package/dist/storage/content-guard.d.ts +32 -0
- package/dist/storage/content-guard.d.ts.map +1 -1
- package/dist/storage/content-guard.js +467 -48
- package/dist/storage/content-guard.js.map +1 -1
- package/dist/storage/corrections.d.ts +3 -1
- package/dist/storage/corrections.d.ts.map +1 -1
- package/dist/storage/corrections.js +52 -67
- package/dist/storage/corrections.js.map +1 -1
- package/dist/storage/cwd-allowlist.d.ts +30 -2
- package/dist/storage/cwd-allowlist.d.ts.map +1 -1
- package/dist/storage/cwd-allowlist.js +105 -22
- package/dist/storage/cwd-allowlist.js.map +1 -1
- package/dist/storage/deferred-bookkeeping.d.ts +34 -0
- package/dist/storage/deferred-bookkeeping.d.ts.map +1 -0
- package/dist/storage/deferred-bookkeeping.js +201 -0
- package/dist/storage/deferred-bookkeeping.js.map +1 -0
- package/dist/storage/filelock.d.ts +26 -8
- package/dist/storage/filelock.d.ts.map +1 -1
- package/dist/storage/filelock.js +202 -26
- package/dist/storage/filelock.js.map +1 -1
- package/dist/storage/frontmatter.d.ts +14 -0
- package/dist/storage/frontmatter.d.ts.map +1 -0
- package/dist/storage/frontmatter.js +22 -0
- package/dist/storage/frontmatter.js.map +1 -0
- package/dist/storage/fs-utils.d.ts +53 -0
- package/dist/storage/fs-utils.d.ts.map +1 -1
- package/dist/storage/fs-utils.js +140 -2
- package/dist/storage/fs-utils.js.map +1 -1
- package/dist/storage/hook-session.d.ts +9 -0
- package/dist/storage/hook-session.d.ts.map +1 -0
- package/dist/storage/hook-session.js +49 -0
- package/dist/storage/hook-session.js.map +1 -0
- package/dist/storage/identity-card.d.ts +27 -0
- package/dist/storage/identity-card.d.ts.map +1 -0
- package/dist/storage/identity-card.js +86 -0
- package/dist/storage/identity-card.js.map +1 -0
- package/dist/storage/lifecycle-telemetry.d.ts +1 -1
- package/dist/storage/lifecycle-telemetry.d.ts.map +1 -1
- package/dist/storage/lifecycle-telemetry.js +2 -2
- package/dist/storage/lifecycle-telemetry.js.map +1 -1
- package/dist/storage/memory-protocol.js +55 -55
- package/dist/storage/paths.d.ts.map +1 -1
- package/dist/storage/paths.js +7 -2
- package/dist/storage/paths.js.map +1 -1
- package/dist/storage/pending.d.ts +39 -3
- package/dist/storage/pending.d.ts.map +1 -1
- package/dist/storage/pending.js +126 -20
- package/dist/storage/pending.js.map +1 -1
- package/dist/storage/project.d.ts.map +1 -1
- package/dist/storage/project.js +34 -9
- package/dist/storage/project.js.map +1 -1
- package/dist/storage/session.d.ts.map +1 -1
- package/dist/storage/session.js +43 -16
- package/dist/storage/session.js.map +1 -1
- package/dist/storage/state-card.d.ts +59 -0
- package/dist/storage/state-card.d.ts.map +1 -0
- package/dist/storage/state-card.js +162 -0
- package/dist/storage/state-card.js.map +1 -0
- package/dist/storage/store-manifest.js +57 -57
- package/dist/storage/unclaimed.js +2 -2
- package/dist/storage/unclaimed.js.map +1 -1
- package/dist/supabase/config.d.ts.map +1 -1
- package/dist/supabase/config.js +7 -1
- package/dist/supabase/config.js.map +1 -1
- package/dist/supabase/embedding.d.ts.map +1 -1
- package/dist/supabase/embedding.js +7 -0
- package/dist/supabase/embedding.js.map +1 -1
- package/dist/supabase/sync.d.ts.map +1 -1
- package/dist/supabase/sync.js +42 -18
- package/dist/supabase/sync.js.map +1 -1
- package/dist/tools-logic/bootstrap.d.ts.map +1 -1
- package/dist/tools-logic/bootstrap.js +4 -2
- package/dist/tools-logic/bootstrap.js.map +1 -1
- package/dist/tools-logic/check.d.ts +69 -2
- package/dist/tools-logic/check.d.ts.map +1 -1
- package/dist/tools-logic/check.js +280 -57
- package/dist/tools-logic/check.js.map +1 -1
- package/dist/tools-logic/dream-admission.js +29 -29
- package/dist/tools-logic/recall-backend.d.ts.map +1 -1
- package/dist/tools-logic/recall-backend.js +11 -1
- package/dist/tools-logic/recall-backend.js.map +1 -1
- package/dist/tools-logic/session-end.d.ts +18 -1
- package/dist/tools-logic/session-end.d.ts.map +1 -1
- package/dist/tools-logic/session-end.js +36 -5
- package/dist/tools-logic/session-end.js.map +1 -1
- package/dist/tools-logic/session-start-render.d.ts +35 -0
- package/dist/tools-logic/session-start-render.d.ts.map +1 -0
- package/dist/tools-logic/session-start-render.js +240 -0
- package/dist/tools-logic/session-start-render.js.map +1 -0
- package/dist/tools-logic/session-start.d.ts +21 -0
- package/dist/tools-logic/session-start.d.ts.map +1 -1
- package/dist/tools-logic/session-start.js +279 -225
- package/dist/tools-logic/session-start.js.map +1 -1
- package/dist/tools-logic/smart-recall.d.ts +60 -0
- package/dist/tools-logic/smart-recall.d.ts.map +1 -1
- package/dist/tools-logic/smart-recall.js +221 -31
- package/dist/tools-logic/smart-recall.js.map +1 -1
- package/dist/tools-logic/smart-remember-vector.d.ts +3 -1
- package/dist/tools-logic/smart-remember-vector.d.ts.map +1 -1
- package/dist/tools-logic/smart-remember-vector.js +3 -1
- package/dist/tools-logic/smart-remember-vector.js.map +1 -1
- package/dist/tools-logic/smart-remember.d.ts.map +1 -1
- package/dist/tools-logic/smart-remember.js +8 -5
- package/dist/tools-logic/smart-remember.js.map +1 -1
- package/dist/types.d.ts +98 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +164 -3
- package/dist/types.js.map +1 -1
- package/dist/vector/embedding.d.ts +20 -1
- package/dist/vector/embedding.d.ts.map +1 -1
- package/dist/vector/embedding.js +30 -1
- package/dist/vector/embedding.js.map +1 -1
- package/dist/vector/local-vector-backend.d.ts +4 -1
- package/dist/vector/local-vector-backend.d.ts.map +1 -1
- package/dist/vector/local-vector-backend.js +7 -3
- package/dist/vector/local-vector-backend.js.map +1 -1
- package/package.json +59 -59
package/dist/storage/fs-utils.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import * as fs from "node:fs";
|
|
5
5
|
import * as path from "node:path";
|
|
6
|
+
import { randomBytes } from "node:crypto";
|
|
6
7
|
export function ensureDir(dir) {
|
|
7
8
|
if (!fs.existsSync(dir)) {
|
|
8
9
|
fs.mkdirSync(dir, { recursive: true });
|
|
@@ -24,6 +25,26 @@ export function todayISO() {
|
|
|
24
25
|
export function safeIsoDateOrToday(date) {
|
|
25
26
|
return date && /^\d{4}-\d{2}-\d{2}$/.test(date) ? date : todayISO();
|
|
26
27
|
}
|
|
28
|
+
/** True when the file's content starts with a JSON array bracket — the
|
|
29
|
+
* legacy whole-array format of the append-only NDJSON stores (A14:
|
|
30
|
+
* alignment-log.json, feedback-log.json). Reads 16 bytes, not the file. */
|
|
31
|
+
export function isLegacyJsonArrayFile(p) {
|
|
32
|
+
let fd;
|
|
33
|
+
try {
|
|
34
|
+
fd = fs.openSync(p, "r");
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
try {
|
|
40
|
+
const buf = Buffer.alloc(16);
|
|
41
|
+
const n = fs.readSync(fd, buf, 0, 16, 0);
|
|
42
|
+
return buf.subarray(0, n).toString("utf-8").trimStart().startsWith("[");
|
|
43
|
+
}
|
|
44
|
+
finally {
|
|
45
|
+
fs.closeSync(fd);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
27
48
|
export function readJsonSafe(filePath) {
|
|
28
49
|
if (!fs.existsSync(filePath))
|
|
29
50
|
return null;
|
|
@@ -34,11 +55,112 @@ export function readJsonSafe(filePath) {
|
|
|
34
55
|
return null;
|
|
35
56
|
}
|
|
36
57
|
}
|
|
58
|
+
/** Synchronous bounded sleep without CPU spin (Atomics.wait on a throwaway
|
|
59
|
+
* buffer). Only ever reached on win32 transient rename retries (≤
|
|
60
|
+
* RENAME_RETRY_BUDGET_MS total) — never a lock-wait primitive (fix9 retired
|
|
61
|
+
* those deliberately). */
|
|
62
|
+
function sleepSyncMs(ms) {
|
|
63
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* A14 diagnostics channel (2026-10-12, CI run 38255969731): one NDJSON line
|
|
67
|
+
* per event on stderr, prefix "ARLOCKDBG", gated on AGENT_RECALL_LOCK_DEBUG=1.
|
|
68
|
+
* Shared by filelock.ts (acquire path / reclaim decision / contention /
|
|
69
|
+
* release failure) and renameAtomic (retry storms) so a failing concurrency
|
|
70
|
+
* run on an unreachable CI runner tells us WHICH mechanism lost the records
|
|
71
|
+
* instead of only how many. Read lazily (not at module load) so tests that
|
|
72
|
+
* set the env after import still get the stream. Never throws.
|
|
73
|
+
*/
|
|
74
|
+
export function lockDebug(ev, fields) {
|
|
75
|
+
if (process.env.AGENT_RECALL_LOCK_DEBUG !== "1")
|
|
76
|
+
return;
|
|
77
|
+
try {
|
|
78
|
+
process.stderr.write("ARLOCKDBG " + JSON.stringify({ ev, pid: process.pid, t: Date.now(), ...fields }) + "\n");
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
/* diagnostics must never break the caller */
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Total win32 transient-rename retry budget. 5s, not the original ~1s (A13,
|
|
86
|
+
* CI run 38251553161): on a loaded 2-vCPU GitHub runner, a holder that
|
|
87
|
+
* intended a ~400ms window kept the destination open past the entire ~1s
|
|
88
|
+
* backoff (the rename-retry test's own PowerShell reader — its close drifted
|
|
89
|
+
* >600ms under scheduler pressure; even idle on a fast desktop the drift
|
|
90
|
+
* measures ~80ms). Real-world holders are no gentler: antivirus/indexer
|
|
91
|
+
* scans commonly pin a just-written file for 100ms–2s. The 5s worst case is
|
|
92
|
+
* only ever PAID when the rename is genuinely blocked the whole time —
|
|
93
|
+
* uncontended renames (the overwhelmingly common case) succeed on the first
|
|
94
|
+
* attempt and never sleep — and after the budget the original error still
|
|
95
|
+
* surfaces (exported so the regression test derives its assertions from the
|
|
96
|
+
* real value instead of a copy that can drift).
|
|
97
|
+
*/
|
|
98
|
+
export const RENAME_RETRY_BUDGET_MS = 5_000;
|
|
99
|
+
/** Backoff cap: 10 → 250ms doubling, then flat 250ms until the budget is
|
|
100
|
+
* spent — early retries catch ms-scale reader windows quickly, the cap keeps
|
|
101
|
+
* the write's landing latency ≤250ms once a long holder finally releases. */
|
|
102
|
+
const RENAME_RETRY_MAX_DELAY_MS = 250;
|
|
103
|
+
/**
|
|
104
|
+
* renameSync with a BOUNDED win32-only retry for transient sharing-violation
|
|
105
|
+
* errors (CI/parallel-suite flake, 2026-10-12): every atomic write here is
|
|
106
|
+
* tmp-write + rename, and readers of these files are deliberately LOCK-FREE
|
|
107
|
+
* (readAlignmentLog in session_start, readCorrections on hot paths, check()'s
|
|
108
|
+
* similar-past-deltas scan). On NTFS, renaming OVER a destination that any
|
|
109
|
+
* process holds open without FILE_SHARE_DELETE — a concurrent lock-free
|
|
110
|
+
* reader, an antivirus/indexer scan — fails with EPERM/EACCES/EBUSY for the
|
|
111
|
+
* few ms the handle lives. That is a TRANSIENT, not a permission problem
|
|
112
|
+
* (same NTFS semantics as filelock.ts's A10 delete-pending EPERM note), and
|
|
113
|
+
* it intermittently failed alignment-log-concurrency under full-suite load:
|
|
114
|
+
* EPERM: operation not permitted, rename '…alignment-log.json.tmp.N' →
|
|
115
|
+
* '…alignment-log.json'
|
|
116
|
+
* Exponential backoff 10→250ms (capped), 5s total (see
|
|
117
|
+
* RENAME_RETRY_BUDGET_MS for why ~1s lost to a slow CI runner), then rethrow
|
|
118
|
+
* — anything outlasting the budget is a real environment problem the caller
|
|
119
|
+
* must see. The budget counts REQUESTED sleep, not wall clock, so a
|
|
120
|
+
* descheduled process still waits at least the full budget. POSIX renames
|
|
121
|
+
* over open files simply succeed, so the retry path is unreachable there
|
|
122
|
+
* (hence "atomic on POSIX" never needed this).
|
|
123
|
+
*/
|
|
124
|
+
export function renameAtomic(oldPath, newPath) {
|
|
125
|
+
let delayMs = 10;
|
|
126
|
+
let sleptMs = 0;
|
|
127
|
+
let retries = 0;
|
|
128
|
+
let lastCode;
|
|
129
|
+
for (;;) {
|
|
130
|
+
try {
|
|
131
|
+
fs.renameSync(oldPath, newPath);
|
|
132
|
+
if (retries > 0) {
|
|
133
|
+
lockDebug("rename-retry", {
|
|
134
|
+
dest: path.basename(newPath), retries, slept_ms: sleptMs, last_errno: lastCode, outcome: "ok",
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
catch (err) {
|
|
140
|
+
const code = err.code;
|
|
141
|
+
const transient = process.platform === "win32" && (code === "EPERM" || code === "EACCES" || code === "EBUSY");
|
|
142
|
+
if (!transient || sleptMs >= RENAME_RETRY_BUDGET_MS) {
|
|
143
|
+
if (retries > 0 || transient) {
|
|
144
|
+
lockDebug("rename-retry", {
|
|
145
|
+
dest: path.basename(newPath), retries, slept_ms: sleptMs, last_errno: code, outcome: "gave-up",
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
throw err;
|
|
149
|
+
}
|
|
150
|
+
lastCode = code;
|
|
151
|
+
retries += 1;
|
|
152
|
+
const napMs = Math.min(delayMs, RENAME_RETRY_MAX_DELAY_MS, RENAME_RETRY_BUDGET_MS - sleptMs);
|
|
153
|
+
sleepSyncMs(napMs);
|
|
154
|
+
sleptMs += napMs;
|
|
155
|
+
delayMs *= 2;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
37
159
|
export function writeJsonAtomic(filePath, data) {
|
|
38
160
|
ensureDir(path.dirname(filePath));
|
|
39
161
|
const tmp = filePath + ".tmp." + process.pid;
|
|
40
162
|
fs.writeFileSync(tmp, JSON.stringify(data, null, 2), "utf-8");
|
|
41
|
-
|
|
163
|
+
renameAtomic(tmp, filePath); // atomic on POSIX; win32 transient-EPERM retry
|
|
42
164
|
}
|
|
43
165
|
/**
|
|
44
166
|
* Atomic PRE-SERIALIZED text write (tmp + rename) — for callers that must
|
|
@@ -52,7 +174,23 @@ export function writeTextAtomic(filePath, text) {
|
|
|
52
174
|
ensureDir(path.dirname(filePath));
|
|
53
175
|
const tmp = filePath + ".tmp." + process.pid;
|
|
54
176
|
fs.writeFileSync(tmp, text, "utf-8");
|
|
55
|
-
|
|
177
|
+
renameAtomic(tmp, filePath); // atomic on POSIX; win32 transient-EPERM retry
|
|
178
|
+
}
|
|
179
|
+
/** Cards v1 — unique tmp (pid+random) so concurrent writers never share one; tmp removed if the rename fails. */
|
|
180
|
+
export function writeTextAtomicPrivate(filePath, text) {
|
|
181
|
+
ensureDir(path.dirname(filePath));
|
|
182
|
+
const tmp = `${filePath}.tmp.${process.pid}.${randomBytes(4).toString("hex")}`;
|
|
183
|
+
fs.writeFileSync(tmp, text, { encoding: "utf-8", mode: 0o600 });
|
|
184
|
+
try {
|
|
185
|
+
renameAtomic(tmp, filePath);
|
|
186
|
+
}
|
|
187
|
+
catch (err) {
|
|
188
|
+
try {
|
|
189
|
+
fs.rmSync(tmp, { force: true });
|
|
190
|
+
}
|
|
191
|
+
catch { /* best effort */ }
|
|
192
|
+
throw err;
|
|
193
|
+
}
|
|
56
194
|
}
|
|
57
195
|
// ---------------------------------------------------------------------------
|
|
58
196
|
// M8 (review fix, 2026-07-31) — shared UTF-8-safe byte-boundary helpers.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fs-utils.js","sourceRoot":"","sources":["../../src/storage/fs-utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"fs-utils.js","sourceRoot":"","sources":["../../src/storage/fs-utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,C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AM,GAAG,GAAG,mBAAmB,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;IAC/C,OAAO,GAAG,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;AAChD,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Cards v1 (G1) — one session-id resolver for every CLI hook. Core getSessionId() is unchanged. */
|
|
2
|
+
import type { Readable } from "node:stream";
|
|
3
|
+
export declare function resolveHookSessionId(stdinPayload: Record<string, unknown> | undefined, env?: NodeJS.ProcessEnv): string | undefined;
|
|
4
|
+
export declare function hookLockKey(sid: string | undefined, now?: Date): string;
|
|
5
|
+
/** TTY → {} at once; a stream that never ends → {} after timeoutMs (stream destroyed). Invalid/non-object JSON → {}. */
|
|
6
|
+
export declare function readHookStdin(stream?: Readable & {
|
|
7
|
+
isTTY?: boolean;
|
|
8
|
+
}, timeoutMs?: number): Promise<Record<string, unknown>>;
|
|
9
|
+
//# sourceMappingURL=hook-session.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hook-session.d.ts","sourceRoot":"","sources":["../../src/storage/hook-session.ts"],"names":[],"mappings":"AAAA,oGAAoG;AACpG,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAM5C,wBAAgB,oBAAoB,CAAC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,EAAE,GAAG,GAAE,MAAM,CAAC,UAAwB,GAAG,MAAM,GAAG,SAAS,CAMhJ;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,EAAE,GAAG,GAAE,IAAiB,GAAG,MAAM,CAEnF;AAED,wHAAwH;AACxH,wBAAgB,aAAa,CAAC,MAAM,GAAE,QAAQ,GAAG;IAAE,KAAK,CAAC,EAAE,OAAO,CAAA;CAAkB,EAAE,SAAS,SAAO,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAuBxI"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
const ENV_KEYS = ["CLAUDE_CODE_SESSION_ID", "CLAUDE_SESSION_ID", "SESSION_ID"];
|
|
2
|
+
const clean = (v) => typeof v === "number" && Number.isFinite(v) ? String(v) : typeof v === "string" && v.trim() ? v.trim() : undefined;
|
|
3
|
+
export function resolveHookSessionId(stdinPayload, env = process.env) {
|
|
4
|
+
for (const v of [stdinPayload?.["session_id"], ...ENV_KEYS.map((k) => env[k])]) {
|
|
5
|
+
const s = clean(v);
|
|
6
|
+
if (s)
|
|
7
|
+
return s;
|
|
8
|
+
}
|
|
9
|
+
return undefined;
|
|
10
|
+
}
|
|
11
|
+
export function hookLockKey(sid, now = new Date()) {
|
|
12
|
+
return sid ?? `nosid-${now.toISOString().slice(0, 13)}`;
|
|
13
|
+
}
|
|
14
|
+
/** TTY → {} at once; a stream that never ends → {} after timeoutMs (stream destroyed). Invalid/non-object JSON → {}. */
|
|
15
|
+
export function readHookStdin(stream = process.stdin, timeoutMs = 2000) {
|
|
16
|
+
if (stream.isTTY)
|
|
17
|
+
return Promise.resolve({});
|
|
18
|
+
return new Promise((resolve) => {
|
|
19
|
+
const chunks = [];
|
|
20
|
+
let timer;
|
|
21
|
+
let done = false;
|
|
22
|
+
const onData = (c) => { chunks.push(typeof c === "string" ? Buffer.from(c, "utf-8") : c); };
|
|
23
|
+
const finish = (timedOut) => {
|
|
24
|
+
if (done)
|
|
25
|
+
return;
|
|
26
|
+
done = true;
|
|
27
|
+
clearTimeout(timer);
|
|
28
|
+
stream.off("data", onData);
|
|
29
|
+
if (timedOut) {
|
|
30
|
+
try {
|
|
31
|
+
stream.destroy();
|
|
32
|
+
}
|
|
33
|
+
catch { /* best effort */ }
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
const v = JSON.parse(Buffer.concat(chunks).toString("utf-8").trim() || "{}");
|
|
37
|
+
resolve(v !== null && typeof v === "object" && !Array.isArray(v) ? v : {});
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
resolve({});
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
stream.on("data", onData);
|
|
44
|
+
stream.once("end", () => finish(false));
|
|
45
|
+
stream.once("error", () => finish(false));
|
|
46
|
+
timer = setTimeout(() => finish(true), timeoutMs);
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=hook-session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hook-session.js","sourceRoot":"","sources":["../../src/storage/hook-session.ts"],"names":[],"mappings":"AAGA,MAAM,QAAQ,GAAG,CAAC,wBAAwB,EAAE,mBAAmB,EAAE,YAAY,CAAU,CAAC;AACxF,MAAM,KAAK,GAAG,CAAC,CAAU,EAAsB,EAAE,CAC/C,OAAO,CAAC,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;AAErH,MAAM,UAAU,oBAAoB,CAAC,YAAiD,EAAE,MAAyB,OAAO,CAAC,GAAG;IAC1H,KAAK,MAAM,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC,YAAY,CAAC,EAAE,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAC/E,MAAM,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QACnB,IAAI,CAAC;YAAE,OAAO,CAAC,CAAC;IAClB,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,GAA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IAAI,IAAI,CAAC,CAAC;gBACtF,OAAO,CAAC,CAAC,KAAK,IAAI,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAE,CAA6B,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;YAC1G,CAAC;YAAC,MAAM,CAAC;gBAAC,OAAO,CAAC,EAAE,CAAC,CAAC;YAAC,CAAC;QAC1B,CAAC,CAAC;QACF,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAC1B,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QACxC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QAC1C,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,SAAS,CAAC,CAAC;IACpD,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export declare const IDENTITY_BODY_CAP = 1600;
|
|
2
|
+
export interface IdentityCard {
|
|
3
|
+
version: number;
|
|
4
|
+
updated: string;
|
|
5
|
+
body: string;
|
|
6
|
+
}
|
|
7
|
+
export declare class IdentityCardError extends Error {
|
|
8
|
+
readonly code: "empty" | "too_long" | "secret" | "binary";
|
|
9
|
+
constructor(code: "empty" | "too_long" | "secret" | "binary", message: string);
|
|
10
|
+
}
|
|
11
|
+
export declare const identityCardPath: () => string;
|
|
12
|
+
/** The on-disk form — what `write` stores and `ar identity show` prints, so a shown card feeds straight back into `set`. */
|
|
13
|
+
export declare const serializeIdentityCard: (c: IdentityCard) => string;
|
|
14
|
+
export declare function parseIdentityCard(text: string): {
|
|
15
|
+
card: IdentityCard;
|
|
16
|
+
malformed: boolean;
|
|
17
|
+
};
|
|
18
|
+
export declare function readIdentityCard(): IdentityCard | null;
|
|
19
|
+
export declare function writeIdentityCard(body: string, now?: Date): IdentityCard & {
|
|
20
|
+
path: string;
|
|
21
|
+
};
|
|
22
|
+
/** Shared renderer (MCP terse/verbose, CLI hook-start). */
|
|
23
|
+
export declare const formatOwnerSection: (o: {
|
|
24
|
+
version: number;
|
|
25
|
+
body: string;
|
|
26
|
+
}) => string[];
|
|
27
|
+
//# sourceMappingURL=identity-card.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identity-card.d.ts","sourceRoot":"","sources":["../../src/storage/identity-card.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,iBAAiB,OAAO,CAAC;AACtC,MAAM,WAAW,YAAY;IAAG,OAAO,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE;AAChF,qBAAa,iBAAkB,SAAQ,KAAK;aACd,IAAI,EAAE,OAAO,GAAG,UAAU,GAAG,QAAQ,GAAG,QAAQ;gBAAhD,IAAI,EAAE,OAAO,GAAG,UAAU,GAAG,QAAQ,GAAG,QAAQ,EAAE,OAAO,EAAE,MAAM;CAC9F;AACD,eAAO,MAAM,gBAAgB,QAAO,MAAkD,CAAC;AAGvF,4HAA4H;AAC5H,eAAO,MAAM,qBAAqB,GAAI,GAAG,YAAY,KAAG,MAAoG,CAAC;AAE7J,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,SAAS,EAAE,OAAO,CAAA;CAAE,CAO1F;AAED,wBAAgB,gBAAgB,IAAI,YAAY,GAAG,IAAI,CAmBtD;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,GAAE,IAAiB,GAAG,YAAY,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAavG;AAED,2DAA2D;AAC3D,eAAO,MAAM,kBAAkB,GAAI,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,KAAG,MAAM,EAAqD,CAAC"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/** Cards v1 (G2) — <root>/identity-card.md. Personal tier, never synced; the CLI is the only writer. Reads never throw. */
|
|
2
|
+
import * as fs from "node:fs";
|
|
3
|
+
import * as path from "node:path";
|
|
4
|
+
import { getRoot } from "../types.js";
|
|
5
|
+
import { writeTextAtomicPrivate } from "./fs-utils.js";
|
|
6
|
+
import { scrubSecretContent } from "./content-guard.js";
|
|
7
|
+
import { normalizeCardText, parseFrontmatter } from "./frontmatter.js";
|
|
8
|
+
export const IDENTITY_BODY_CAP = 1600;
|
|
9
|
+
export class IdentityCardError extends Error {
|
|
10
|
+
code;
|
|
11
|
+
constructor(code, message) {
|
|
12
|
+
super(message);
|
|
13
|
+
this.code = code;
|
|
14
|
+
this.name = "IdentityCardError";
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export const identityCardPath = () => path.join(getRoot(), "identity-card.md");
|
|
18
|
+
const warn = (msg) => { try {
|
|
19
|
+
process.stderr.write(`[AgentRecall] identity-card.md: ${msg}\n`);
|
|
20
|
+
}
|
|
21
|
+
catch { /* never throw */ } };
|
|
22
|
+
/** The on-disk form — what `write` stores and `ar identity show` prints, so a shown card feeds straight back into `set`. */
|
|
23
|
+
export const serializeIdentityCard = (c) => `---\nkind: identity-card\nversion: ${c.version}\nupdated: ${c.updated}\n---\n${c.body}\n`;
|
|
24
|
+
export function parseIdentityCard(text) {
|
|
25
|
+
const fm = parseFrontmatter(text), version = fm?.fields.get("version") ?? "";
|
|
26
|
+
// `version` must be a plain integer: "3.0", "1e1", "0x3" or "007" are hand edits the bump in writeIdentityCard would mangle.
|
|
27
|
+
if (fm && fm.fields.get("kind") === "identity-card" && /^(0|[1-9]\d*)$/.test(version) && Number.isSafeInteger(Number(version))) {
|
|
28
|
+
return { card: { version: Number(version), updated: fm.fields.get("updated") ?? "", body: fm.body.replace(/^\n+/, "").trimEnd() }, malformed: false };
|
|
29
|
+
}
|
|
30
|
+
return { card: { version: 0, updated: "", body: normalizeCardText(text).trimEnd() }, malformed: true };
|
|
31
|
+
}
|
|
32
|
+
export function readIdentityCard() {
|
|
33
|
+
let raw;
|
|
34
|
+
try {
|
|
35
|
+
if (!fs.existsSync(identityCardPath()))
|
|
36
|
+
return null;
|
|
37
|
+
raw = fs.readFileSync(identityCardPath(), "utf-8");
|
|
38
|
+
}
|
|
39
|
+
catch (err) {
|
|
40
|
+
warn(`unreadable (${String(err)}) — skipped`);
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
if (raw.includes("\u0000")) {
|
|
44
|
+
warn("binary content — skipped");
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
if (!raw.trim()) {
|
|
48
|
+
warn("empty file — skipped");
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
const { card, malformed } = parseIdentityCard(raw);
|
|
52
|
+
if (malformed)
|
|
53
|
+
warn("malformed frontmatter — whole file used as body");
|
|
54
|
+
else if (card.body.length > IDENTITY_BODY_CAP)
|
|
55
|
+
warn(`body over ${IDENTITY_BODY_CAP} chars — truncated for this load`);
|
|
56
|
+
// `set` rejects secrets, but a hand-edited live file bypasses it and is injected into every session.
|
|
57
|
+
const scan = scrubSecretContent(card.body);
|
|
58
|
+
if (scan.redactedCount > 0) {
|
|
59
|
+
card.body = scan.content;
|
|
60
|
+
warn(`contains a secret (${scan.labels[0] ?? "secret pattern"}) — redacted for this load; remove it from the file`);
|
|
61
|
+
}
|
|
62
|
+
if (card.body.length > IDENTITY_BODY_CAP)
|
|
63
|
+
card.body = card.body.slice(0, IDENTITY_BODY_CAP - 1) + "…";
|
|
64
|
+
return card;
|
|
65
|
+
}
|
|
66
|
+
export function writeIdentityCard(body, now = new Date()) {
|
|
67
|
+
const clean = body.replace(/\r\n/g, "\n").trim();
|
|
68
|
+
if (!clean)
|
|
69
|
+
throw new IdentityCardError("empty", "identity card body is empty — nothing written");
|
|
70
|
+
// A UTF-16 file read as UTF-8 (PowerShell 5.1 redirection) arrives NUL-laden; stored, it would be skipped as binary on every read.
|
|
71
|
+
if (clean.includes("\u0000"))
|
|
72
|
+
throw new IdentityCardError("binary", "identity card body contains NUL bytes (a UTF-16 file read as UTF-8?) — nothing written");
|
|
73
|
+
if (clean.length > IDENTITY_BODY_CAP)
|
|
74
|
+
throw new IdentityCardError("too_long", `identity card body is ${clean.length} chars; cap is ${IDENTITY_BODY_CAP} — nothing written`);
|
|
75
|
+
const scan = scrubSecretContent(clean);
|
|
76
|
+
if (scan.redactedCount > 0)
|
|
77
|
+
throw new IdentityCardError("secret", `identity card body contains a secret (${scan.labels[0] ?? "secret pattern"}) — nothing written`);
|
|
78
|
+
// Unlocked read-then-write: two concurrent `ar identity set` runs can both read version N and both store N+1. The last atomic
|
|
79
|
+
// rename wins and `version` is informational (one owner, CLI-only writer), so no lock is taken for it.
|
|
80
|
+
const card = { version: (readIdentityCard()?.version ?? 0) + 1, updated: now.toISOString(), body: clean };
|
|
81
|
+
writeTextAtomicPrivate(identityCardPath(), serializeIdentityCard(card));
|
|
82
|
+
return { ...card, path: identityCardPath() };
|
|
83
|
+
}
|
|
84
|
+
/** Shared renderer (MCP terse/verbose, CLI hook-start). */
|
|
85
|
+
export const formatOwnerSection = (o) => [`Owner (identity card v${o.version})`, o.body];
|
|
86
|
+
//# sourceMappingURL=identity-card.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identity-card.js","sourceRoot":"","sources":["../../src/storage/identity-card.ts"],"names":[],"mappings":"AAAA,2HAA2H;AAC3H,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,C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kBAAkB,iBAAiB,oBAAoB,CAAC,CAAC;IAC5K,MAAM,IAAI,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAAC;IACvC,IAAI,IAAI,CAAC,aAAa,GAAG,CAAC;QAAE,MAAM,IAAI,iBAAiB,CAAC,QAAQ,EAAE,yCAAyC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,gBAAgB,qBAAqB,CAAC,CAAC;IACpK,8HAA8H;IAC9H,uGAAuG;IACvG,MAAM,IAAI,GAAG,EAAE,OAAO,EAAE,CAAC,gBAAgB,EAAE,EAAE,OAAO,IAAI,CAAC,CAAC,GAAG,CAAC,EAAE,OAAO,EAAE,GAAG,CAAC,WAAW,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;IAC1G,sBAAsB,CAAC,gBAAgB,EAAE,EAAE,qBAAqB,CAAC,IAAI,CAAC,CAAC,CAAC;IACxE,OAAO,EAAE,GAAG,IAAI,EAAE,IAAI,EAAE,gBAAgB,EAAE,EAAE,CAAC;AAC/C,CAAC;AAED,2DAA2D;AAC3D,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,CAAoC,EAAY,EAAE,CAAC,CAAC,yBAAyB,CAAC,CAAC,OAAO,GAAG,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC"}
|
|
@@ -52,7 +52,7 @@ export interface LifecycleTelemetryRow {
|
|
|
52
52
|
* Append one lifecycle event row. Best-effort: NEVER throws into the caller —
|
|
53
53
|
* telemetry must never break a lifecycle tool call.
|
|
54
54
|
*/
|
|
55
|
-
export declare function recordLifecycleEvent(event: LifecycleEvent, sessionId: string, project: string, dup: boolean): void;
|
|
55
|
+
export declare function recordLifecycleEvent(event: LifecycleEvent, sessionId: string, project: string, dup: boolean, at?: string): void;
|
|
56
56
|
export interface LifecycleStats {
|
|
57
57
|
total: number;
|
|
58
58
|
byEvent: Record<LifecycleEvent, number>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lifecycle-telemetry.d.ts","sourceRoot":"","sources":["../../src/storage/lifecycle-telemetry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAQH,MAAM,MAAM,cAAc,GAAG,eAAe,GAAG,aAAa,GAAG,UAAU,GAAG,OAAO,CAAC;AAEpF,MAAM,WAAW,qBAAqB;IACpC,KAAK,EAAE,cAAc,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB;;;;;OAKG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB,iCAAiC;IACjC,EAAE,EAAE,MAAM,CAAC;IACX,kEAAkE;IAClE,GAAG,EAAE,OAAO,CAAC;CACd;AAoCD;;;GAGG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,cAAc,EACrB,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,EACf,GAAG,EAAE,OAAO,
|
|
1
|
+
{"version":3,"file":"lifecycle-telemetry.d.ts","sourceRoot":"","sources":["../../src/storage/lifecycle-telemetry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAQH,MAAM,MAAM,cAAc,GAAG,eAAe,GAAG,aAAa,GAAG,UAAU,GAAG,OAAO,CAAC;AAEpF,MAAM,WAAW,qBAAqB;IACpC,KAAK,EAAE,cAAc,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB;;;;;OAKG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB,iCAAiC;IACjC,EAAE,EAAE,MAAM,CAAC;IACX,kEAAkE;IAClE,GAAG,EAAE,OAAO,CAAC;CACd;AAoCD;;;GAGG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,cAAc,EACrB,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,EACf,GAAG,EAAE,OAAO,EACZ,EAAE,GAAE,MAAiC,GACpC,IAAI,CAkBN;AAED,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC;IACxC,QAAQ,EAAE,MAAM,CAAC;IACjB,kEAAkE;IAClE,OAAO,EAAE,MAAM,CAAC;CACjB;AAWD;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,cAAc,CA0B/D"}
|
|
@@ -73,7 +73,7 @@ function rotateIfNeeded(p) {
|
|
|
73
73
|
* Append one lifecycle event row. Best-effort: NEVER throws into the caller —
|
|
74
74
|
* telemetry must never break a lifecycle tool call.
|
|
75
75
|
*/
|
|
76
|
-
export function recordLifecycleEvent(event, sessionId, project, dup) {
|
|
76
|
+
export function recordLifecycleEvent(event, sessionId, project, dup, at = new Date().toISOString()) {
|
|
77
77
|
try {
|
|
78
78
|
const dir = telemetryDir();
|
|
79
79
|
ensureDir(dir);
|
|
@@ -84,7 +84,7 @@ export function recordLifecycleEvent(event, sessionId, project, dup) {
|
|
|
84
84
|
sessionId,
|
|
85
85
|
project,
|
|
86
86
|
host_tier: resolveHostProfile().tier,
|
|
87
|
-
at
|
|
87
|
+
at,
|
|
88
88
|
dup,
|
|
89
89
|
};
|
|
90
90
|
fs.appendFileSync(p, JSON.stringify(row) + "\n", "utf-8");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lifecycle-telemetry.js","sourceRoot":"","sources":["../../src/storage/lifecycle-telemetry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,kBAAkB,EAAE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YAClC,CAAC;YACD,IAAI,OAAO,IAAI,GAAG,CAAC,OAAO,KAAK,OAAO;gBAAE,SAAS;YACjD,IAAI,CAAC,CAAC,GAAG,CAAC,KAAK,IAAI,KAAK,CAAC,OAAO,CAAC;gBAAE,SAAS;YAC5C,KAAK,CAAC,KAAK,EAAE,CAAC;YACd,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;YAC3B,IAAI,GAAG,CAAC,GAAG;gBAAE,KAAK,CAAC,QAAQ,EAAE,CAAC;QAChC,CAAC;QACD,KAAK,CAAC,OAAO,GAAG,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,QAAQ,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACxF,OAAO,KAAK,CAAC;IACf,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,UAAU,EAAE,CAAC;IACtB,CAAC;AACH,CAAC"}
|
|
@@ -22,61 +22,61 @@ const PROTOCOL_FILENAME = "MEMORY-PROTOCOL.md";
|
|
|
22
22
|
function projectRoot(project) {
|
|
23
23
|
return projectSubPath(project);
|
|
24
24
|
}
|
|
25
|
-
const PROTOCOL_BODY = `# AgentRecall — Memory Protocol
|
|
26
|
-
|
|
27
|
-
> Self-describing, substrate-independent memory layout. A cold agent (no MCP)
|
|
28
|
-
> can read and write this folder by convention alone. Local-first; an optional
|
|
29
|
-
> local git commit substrate may sit on top, but **no remote push** is wired
|
|
30
|
-
> until the privacy split is proven.
|
|
31
|
-
|
|
32
|
-
## Two-tier memory with a bridge
|
|
33
|
-
|
|
34
|
-
\`\`\`
|
|
35
|
-
journal/archive/raw/ ← MECHANICAL ARCHIVE (lossless, verbatim, never lost)
|
|
36
|
-
appended on EVERY session end, zero judgment.
|
|
37
|
-
awareness / palace skills ← QUALITY COMPRESSION (lossy, reasoned)
|
|
38
|
-
distilled by the async dreaming loop, NOT in the Stop turn.
|
|
39
|
-
\`\`\`
|
|
40
|
-
|
|
41
|
-
When the compressed tier is **not confident**, retrieval drills DOWN into the
|
|
42
|
-
lossless archive instead of answering thinly (the bridge).
|
|
43
|
-
|
|
44
|
-
## Folder layout
|
|
45
|
-
|
|
46
|
-
- \`journal/\` — curated session stream (capped excerpts; the working narrative).
|
|
47
|
-
- \`journal/archive/raw/<date>--<sessionId>.md\` — verbatim session dumps. Each
|
|
48
|
-
file has small frontmatter (\`project, sessionId, savedAt, source\`) then the
|
|
49
|
-
raw transcript head+tail. **Never** synced to any remote.
|
|
50
|
-
- \`journal/archive/raw/.consumed.json\` — \`{ lastConsumedOffset, lastConsumedAt }\`.
|
|
51
|
-
The dreaming loop advances this marker as it distills raw segments upward.
|
|
52
|
-
- \`journal/archive/index.md\` — one append-only line per dump.
|
|
53
|
-
- \`palace/\` — rooms (project knowledge), skills (procedural memory), pipeline,
|
|
54
|
-
awareness (behavioral layer — PERSONAL, sync-excluded by default).
|
|
55
|
-
- \`corrections/\` — human corrections (PERSONAL, never synced).
|
|
56
|
-
|
|
57
|
-
## Consume seam (async dreaming)
|
|
58
|
-
|
|
59
|
-
Raw dumps are queued for compression, never compressed inside the Stop turn:
|
|
60
|
-
|
|
61
|
-
\`\`\`
|
|
62
|
-
../../.consolidation-queue/<date>.jsonl ← one JSON job per line, relative
|
|
63
|
-
to this file (../.. = the store
|
|
64
|
-
root, two levels up from
|
|
65
|
-
projects/<slug>/)
|
|
66
|
-
\`\`\`
|
|
67
|
-
|
|
68
|
-
A job looks like \`{ "project", "sessionId", "reason", "at", "done"? }\`.
|
|
69
|
-
Drain the queue out-of-band (e.g. \`ar consolidate-async\`): run consolidation
|
|
70
|
-
per job, mark each line \`done:true\`. One bad job must never block the rest.
|
|
71
|
-
|
|
72
|
-
## Cold-agent read/write rules
|
|
73
|
-
|
|
74
|
-
1. To **read**: prefer the curated \`journal/\` + \`palace/\`. If a hit is
|
|
75
|
-
low-confidence, open the matching \`journal/archive/raw/\` file verbatim.
|
|
76
|
-
2. To **write a session**: append a verbatim file under \`journal/archive/raw/\`
|
|
77
|
-
keyed on the session UUID (idempotent), then enqueue a consolidation job.
|
|
78
|
-
3. **Never** sync \`awareness\`, \`corrections\`, \`personal/\`, or \`_global\` palace
|
|
79
|
-
to any remote without an explicit \`sync_personal=true\` opt-in.
|
|
25
|
+
const PROTOCOL_BODY = `# AgentRecall — Memory Protocol
|
|
26
|
+
|
|
27
|
+
> Self-describing, substrate-independent memory layout. A cold agent (no MCP)
|
|
28
|
+
> can read and write this folder by convention alone. Local-first; an optional
|
|
29
|
+
> local git commit substrate may sit on top, but **no remote push** is wired
|
|
30
|
+
> until the privacy split is proven.
|
|
31
|
+
|
|
32
|
+
## Two-tier memory with a bridge
|
|
33
|
+
|
|
34
|
+
\`\`\`
|
|
35
|
+
journal/archive/raw/ ← MECHANICAL ARCHIVE (lossless, verbatim, never lost)
|
|
36
|
+
appended on EVERY session end, zero judgment.
|
|
37
|
+
awareness / palace skills ← QUALITY COMPRESSION (lossy, reasoned)
|
|
38
|
+
distilled by the async dreaming loop, NOT in the Stop turn.
|
|
39
|
+
\`\`\`
|
|
40
|
+
|
|
41
|
+
When the compressed tier is **not confident**, retrieval drills DOWN into the
|
|
42
|
+
lossless archive instead of answering thinly (the bridge).
|
|
43
|
+
|
|
44
|
+
## Folder layout
|
|
45
|
+
|
|
46
|
+
- \`journal/\` — curated session stream (capped excerpts; the working narrative).
|
|
47
|
+
- \`journal/archive/raw/<date>--<sessionId>.md\` — verbatim session dumps. Each
|
|
48
|
+
file has small frontmatter (\`project, sessionId, savedAt, source\`) then the
|
|
49
|
+
raw transcript head+tail. **Never** synced to any remote.
|
|
50
|
+
- \`journal/archive/raw/.consumed.json\` — \`{ lastConsumedOffset, lastConsumedAt }\`.
|
|
51
|
+
The dreaming loop advances this marker as it distills raw segments upward.
|
|
52
|
+
- \`journal/archive/index.md\` — one append-only line per dump.
|
|
53
|
+
- \`palace/\` — rooms (project knowledge), skills (procedural memory), pipeline,
|
|
54
|
+
awareness (behavioral layer — PERSONAL, sync-excluded by default).
|
|
55
|
+
- \`corrections/\` — human corrections (PERSONAL, never synced).
|
|
56
|
+
|
|
57
|
+
## Consume seam (async dreaming)
|
|
58
|
+
|
|
59
|
+
Raw dumps are queued for compression, never compressed inside the Stop turn:
|
|
60
|
+
|
|
61
|
+
\`\`\`
|
|
62
|
+
../../.consolidation-queue/<date>.jsonl ← one JSON job per line, relative
|
|
63
|
+
to this file (../.. = the store
|
|
64
|
+
root, two levels up from
|
|
65
|
+
projects/<slug>/)
|
|
66
|
+
\`\`\`
|
|
67
|
+
|
|
68
|
+
A job looks like \`{ "project", "sessionId", "reason", "at", "done"? }\`.
|
|
69
|
+
Drain the queue out-of-band (e.g. \`ar consolidate-async\`): run consolidation
|
|
70
|
+
per job, mark each line \`done:true\`. One bad job must never block the rest.
|
|
71
|
+
|
|
72
|
+
## Cold-agent read/write rules
|
|
73
|
+
|
|
74
|
+
1. To **read**: prefer the curated \`journal/\` + \`palace/\`. If a hit is
|
|
75
|
+
low-confidence, open the matching \`journal/archive/raw/\` file verbatim.
|
|
76
|
+
2. To **write a session**: append a verbatim file under \`journal/archive/raw/\`
|
|
77
|
+
keyed on the session UUID (idempotent), then enqueue a consolidation job.
|
|
78
|
+
3. **Never** sync \`awareness\`, \`corrections\`, \`personal/\`, or \`_global\` palace
|
|
79
|
+
to any remote without an explicit \`sync_personal=true\` opt-in.
|
|
80
80
|
`;
|
|
81
81
|
/**
|
|
82
82
|
* Write the project's MEMORY-PROTOCOL.md if it is absent (write-once).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../../src/storage/paths.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAYH;;;;;;;;;;GAUG;AACH,eAAO,MAAM,iBAAiB,eAAe,CAAC;AAE9C;;;;;;;;;;GAUG;AACH,eAAO,MAAM,i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AQjG;AAkBD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,gBAAgB,aAAa,CAAC;AAE3C;;;;;;;;GAQG;AACH,wBAAgB,eAAe,IAAI,MAAM,CAExC;AAED;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,QAAQ,EAAE,MAAM,EAAE,GAAG,MAAM,CAwB7E;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAElD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,cAAc,UAAQ,GAAG,MAAM,EAAE,CAuC7E;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEjD;AAED;;GAEG;AACH,wBAAgB,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAKjE;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAOlD;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEjD;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAErD;AAED;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEnD;AAED;;GAEG;AACH,wBAAgB,eAAe,IAAI,MAAM,CAExC"}
|
package/dist/storage/paths.js
CHANGED
|
@@ -175,8 +175,13 @@ export function listCaseVariantForks(root) {
|
|
|
175
175
|
* "/foo/bar" being inside "/foo/ba"). Throws if not.
|
|
176
176
|
*/
|
|
177
177
|
function assertInsideRoot(resolved, root, project) {
|
|
178
|
-
|
|
179
|
-
|
|
178
|
+
// `resolved` comes out of path.resolve() (native, normalized separators);
|
|
179
|
+
// `root` is the raw getRoot() string, which on Windows may carry mixed
|
|
180
|
+
// separators (e.g. an AGENT_RECALL_ROOT set from a POSIX-style shell).
|
|
181
|
+
// Resolve it too, or the startsWith jail rejects every legitimate path.
|
|
182
|
+
const normRoot = path.resolve(root);
|
|
183
|
+
const rootWithSep = normRoot.endsWith(path.sep) ? normRoot : normRoot + path.sep;
|
|
184
|
+
if (!resolved.startsWith(rootWithSep) && resolved !== normRoot) {
|
|
180
185
|
throw new Error(`Invalid project name (path escape): ${project}`);
|
|
181
186
|
}
|
|
182
187
|
}
|