@dsh-cc/memory-consolidation 0.8.0-rc.1 → 0.8.0-rc.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/lib/index.d.ts +3 -13
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +81 -163
- package/lib/index.js.map +1 -1
- package/lib/memory-job.d.ts +43 -0
- package/lib/memory-job.d.ts.map +1 -0
- package/lib/memory-job.js +115 -0
- package/lib/memory-job.js.map +1 -0
- package/lib/prompts.d.ts +4 -3
- package/lib/prompts.d.ts.map +1 -1
- package/lib/prompts.js +7 -6
- package/lib/prompts.js.map +1 -1
- package/lib/session-scan.d.ts +28 -0
- package/lib/session-scan.d.ts.map +1 -0
- package/lib/session-scan.js +166 -0
- package/lib/session-scan.js.map +1 -0
- package/package.json +2 -2
package/lib/index.d.ts
CHANGED
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
*/
|
|
18
18
|
import type { Context } from '@deepseek-ai/cordis';
|
|
19
19
|
import z from '@deepseek-ai/schemastery';
|
|
20
|
+
export { applyEntrypointFallback } from './memory-job.ts';
|
|
20
21
|
export { LOCK_FILE, LOCK_STALE_MS, readLastConsolidatedAt, rollbackLock, tryAcquireLock } from './lock.ts';
|
|
21
22
|
export { gatesPass, timeGatePasses, sessionGatePasses } from './gates.ts';
|
|
22
23
|
export type { ConsolidationGateInput } from './gates.ts';
|
|
@@ -45,21 +46,10 @@ export interface Config {
|
|
|
45
46
|
pressureCooldownMinutes?: number;
|
|
46
47
|
/** One-shot subagent provider for forks (default `fork`). */
|
|
47
48
|
subagentProviderName?: string;
|
|
49
|
+
/** Session store root the gates scan (default `<DSH_HOME>/sessions`). */
|
|
50
|
+
sessionsRoot?: string;
|
|
48
51
|
}
|
|
49
52
|
export declare const Config: z<Config>;
|
|
50
|
-
/**
|
|
51
|
-
* Design §2.4 fallback: if the reported payload carries an over-limit
|
|
52
|
-
* `MEMORY.md`, replace its content with the deterministic truncation output
|
|
53
|
-
* (capped body + visible in-file warning banner) instead of failing the job.
|
|
54
|
-
* Plain rejection would fail the dream, roll back the lock, and retry every
|
|
55
|
-
* turn-end forever with zero durable output. Topic-file writes pass through
|
|
56
|
-
* untouched; a compliant entrypoint is returned byte-identical. Takes the raw
|
|
57
|
-
* structured payload (the entrypoint gate inside `validateMemoryWrites`
|
|
58
|
-
* throws during validation, so the replacement must happen before it) and
|
|
59
|
-
* returns a payload of the same shape; malformed payloads pass through and
|
|
60
|
-
* are rejected by validation as usual.
|
|
61
|
-
*/
|
|
62
|
-
export declare function applyEntrypointFallback(payload: unknown): unknown;
|
|
63
53
|
/**
|
|
64
54
|
* Register the consolidation plugin.
|
|
65
55
|
* @param ctx - the host context with jobs, subagents, fs, and sessions.
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAIH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,CAAC,MAAM,0BAA0B,CAAA;AASxC,OAAO,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAA;AASzD,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,sBAAsB,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAC1G,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AACzE,YAAY,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAA;AACxD,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AACnE,OAAO,EAAE,wBAAwB,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAA;AAG9E,OAAO,EACL,oBAAoB,EACpB,wBAAwB,EACxB,mBAAmB,EACnB,yBAAyB,EACzB,iBAAiB,EACjB,oBAAoB,EACpB,gBAAgB,GACjB,MAAM,gBAAgB,CAAA;AACvB,YAAY,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAEpE,eAAO,MAAM,IAAI,yBAAyB,CAAA;AAC1C,uEAAuE;AACvE,eAAO,MAAM,MAAM,UAAwB,CAAA;AAE3C,0CAA0C;AAC1C,MAAM,WAAW,MAAM;IACrB,qEAAqE;IACrE,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,+CAA+C;IAC/C,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,gDAAgD;IAChD,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,yDAAyD;IACzD,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,0DAA0D;IAC1D,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,gEAAgE;IAChE,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,qEAAqE;IACrE,uBAAuB,CAAC,EAAE,MAAM,CAAA;IAChC,6DAA6D;IAC7D,oBAAoB,CAAC,EAAE,MAAM,CAAA;IAC7B,yEAAyE;IACzE,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB;AAED,eAAO,MAAM,MAAM,EAAE,CAAC,CAAC,MAAM,CAU3B,CAAA;AAIF;;;;GAIG;AACH,wBAAgB,KAAK,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,GAAE,MAAW,GAAG,IAAI,CAkF7D"}
|
package/lib/index.js
CHANGED
|
@@ -16,14 +16,17 @@
|
|
|
16
16
|
* @module @dsh-cc/memory-consolidation
|
|
17
17
|
*/
|
|
18
18
|
import { join } from 'node:path';
|
|
19
|
+
import * as zlib from 'node:zlib';
|
|
19
20
|
import z from '@deepseek-ai/schemastery';
|
|
20
21
|
import { delegationDepthOf } from '@deepseek-ai/dsh-subagent';
|
|
21
22
|
import { defaultDshHome } from '@deepseek-ai/dsh-home-paths';
|
|
22
|
-
import { MEMORY_TOOL_FILTER } from "./tools.js";
|
|
23
23
|
import { buildConsolidationPrompt, buildExtractionPrompt } from "./prompts.js";
|
|
24
|
-
import {
|
|
24
|
+
import { timeGatePasses, sessionGatePasses } from "./gates.js";
|
|
25
|
+
import { gateWindow, scanSessions } from "./session-scan.js";
|
|
25
26
|
import { readLastConsolidatedAt, rollbackLock, tryAcquireLock, LOCK_STALE_MS } from "./lock.js";
|
|
26
|
-
import {
|
|
27
|
+
import { startMemoryJob } from "./memory-job.js";
|
|
28
|
+
export { applyEntrypointFallback } from "./memory-job.js";
|
|
29
|
+
import { memoryWritePolicy, resolveWorkspaceMemoryDir, readPressure, markPressureForced, clearPressure, } from '@dsh-cc/memory';
|
|
27
30
|
export { LOCK_FILE, LOCK_STALE_MS, readLastConsolidatedAt, rollbackLock, tryAcquireLock } from "./lock.js";
|
|
28
31
|
export { gatesPass, timeGatePasses, sessionGatePasses } from "./gates.js";
|
|
29
32
|
export { MEMORY_AGENT_TOOLS, MEMORY_TOOL_FILTER } from "./tools.js";
|
|
@@ -43,113 +46,8 @@ export const Config = z.object({
|
|
|
43
46
|
lockStaleMs: z.number().default(LOCK_STALE_MS),
|
|
44
47
|
pressureCooldownMinutes: z.number().default(60),
|
|
45
48
|
subagentProviderName: z.string().default('fork'),
|
|
49
|
+
sessionsRoot: z.string(),
|
|
46
50
|
});
|
|
47
|
-
/**
|
|
48
|
-
* Over-limit measurement for the entrypoint, identical to the write-side gate
|
|
49
|
-
* semantics (trim → split('\n') → count; byteLength of the trimmed content).
|
|
50
|
-
* @param content - a reported `MEMORY.md` body.
|
|
51
|
-
*/
|
|
52
|
-
function entrypointOverLimit(content) {
|
|
53
|
-
const trimmed = content.trim();
|
|
54
|
-
return trimmed.split('\n').length > MAX_ENTRYPOINT_LINES
|
|
55
|
-
|| Buffer.byteLength(trimmed, 'utf8') > MAX_ENTRYPOINT_BYTES;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Design §2.4 fallback: if the reported payload carries an over-limit
|
|
59
|
-
* `MEMORY.md`, replace its content with the deterministic truncation output
|
|
60
|
-
* (capped body + visible in-file warning banner) instead of failing the job.
|
|
61
|
-
* Plain rejection would fail the dream, roll back the lock, and retry every
|
|
62
|
-
* turn-end forever with zero durable output. Topic-file writes pass through
|
|
63
|
-
* untouched; a compliant entrypoint is returned byte-identical. Takes the raw
|
|
64
|
-
* structured payload (the entrypoint gate inside `validateMemoryWrites`
|
|
65
|
-
* throws during validation, so the replacement must happen before it) and
|
|
66
|
-
* returns a payload of the same shape; malformed payloads pass through and
|
|
67
|
-
* are rejected by validation as usual.
|
|
68
|
-
*/
|
|
69
|
-
export function applyEntrypointFallback(payload) {
|
|
70
|
-
if (typeof payload !== 'object' || payload === null || Array.isArray(payload))
|
|
71
|
-
return payload;
|
|
72
|
-
const raw = payload.writes;
|
|
73
|
-
if (!Array.isArray(raw))
|
|
74
|
-
return payload;
|
|
75
|
-
const writes = raw.map((entry) => {
|
|
76
|
-
if (typeof entry !== 'object' || entry === null)
|
|
77
|
-
return entry;
|
|
78
|
-
const { path, content } = entry;
|
|
79
|
-
if (path !== ENTRYPOINT_NAME || typeof content !== 'string' || !entrypointOverLimit(content)) {
|
|
80
|
-
return entry;
|
|
81
|
-
}
|
|
82
|
-
return { ...entry, content: truncateEntrypointContent(content).content };
|
|
83
|
-
});
|
|
84
|
-
return { ...payload, writes };
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Start a memory-scoped forked subagent as a background job. The fork reports
|
|
88
|
-
* its file set via `outputSchema`; on settlement the plugin validates the
|
|
89
|
-
* batch and writes it host-side under a policy confined to `dir`. Resolves to
|
|
90
|
-
* a control object with an abort hook and a settle promise (true only when
|
|
91
|
-
* the reported writes were validated and persisted).
|
|
92
|
-
*/
|
|
93
|
-
async function startMemoryJob(ctx, agent, dir, provider, label, prompt) {
|
|
94
|
-
const jobs = ctx.get('jobs');
|
|
95
|
-
const subagents = ctx.get('subagents');
|
|
96
|
-
if (jobs === undefined || subagents === undefined) {
|
|
97
|
-
return { abort: () => { }, settled: Promise.resolve(false) };
|
|
98
|
-
}
|
|
99
|
-
const fs = ctx.get('fs');
|
|
100
|
-
const controller = new AbortController();
|
|
101
|
-
// `subagents.start` is async upstream — awaiting it is what exposes the run's
|
|
102
|
-
// `result` promise. Reading `run.result` on the un-awaited Promise throws
|
|
103
|
-
// "Cannot read properties of undefined (reading 'then')" and poisons the
|
|
104
|
-
// turn-stopping dispatch.
|
|
105
|
-
const run = await subagents.start(provider, {
|
|
106
|
-
label,
|
|
107
|
-
signal: controller.signal,
|
|
108
|
-
prompt: [{ type: 'text', text: prompt }],
|
|
109
|
-
parent: agent,
|
|
110
|
-
toolFilter: MEMORY_TOOL_FILTER,
|
|
111
|
-
// Defense-in-depth recursion cap: the top-level listener already gates on
|
|
112
|
-
// depth zero, so this fork's child never delegates. maxDepth is compared
|
|
113
|
-
// against the CHILD's resolved depth (parent + 1); a top-level parent's
|
|
114
|
-
// child resolves to 1 and passes, a grandchild to 2 is rejected.
|
|
115
|
-
maxDepth: 1,
|
|
116
|
-
outputSchema: MEMORY_WRITES_SCHEMA,
|
|
117
|
-
});
|
|
118
|
-
// Real job-done wiring: `done` maps the subagent outcome onto the JobHooks
|
|
119
|
-
// contract (must never reject). Aborted → killed (rolls back the dream
|
|
120
|
-
// lock); a non-completed stopReason, a missing/invalid payload, or a
|
|
121
|
-
// write-back failure → failed with detail; a validated, persisted batch →
|
|
122
|
-
// completed. All branches resolve.
|
|
123
|
-
const done = run.result.then(async (res) => {
|
|
124
|
-
if (controller.signal.aborted)
|
|
125
|
-
return { status: 'killed' };
|
|
126
|
-
if (res?.stopReason !== 'completed') {
|
|
127
|
-
return { status: 'failed', detail: `memory fork ended with stopReason ${String(res?.stopReason)}` };
|
|
128
|
-
}
|
|
129
|
-
if (fs === undefined) {
|
|
130
|
-
return { status: 'failed', detail: 'fs seam unavailable for memory write-back' };
|
|
131
|
-
}
|
|
132
|
-
try {
|
|
133
|
-
const writes = validateMemoryWrites(applyEntrypointFallback(res.structured));
|
|
134
|
-
await writeMemoryFiles(fs, dir, writes);
|
|
135
|
-
return { status: 'completed' };
|
|
136
|
-
}
|
|
137
|
-
catch (err) {
|
|
138
|
-
return { status: 'failed', detail: String(err) };
|
|
139
|
-
}
|
|
140
|
-
}, (err) => controller.signal.aborted ? { status: 'killed' } : { status: 'failed', detail: String(err) });
|
|
141
|
-
const settled = done.then(o => o.status === 'completed');
|
|
142
|
-
jobs.start({
|
|
143
|
-
kind: 'subagent',
|
|
144
|
-
label,
|
|
145
|
-
owner: agent,
|
|
146
|
-
run: () => ({
|
|
147
|
-
cancel: (reason) => { controller.abort(reason); },
|
|
148
|
-
done,
|
|
149
|
-
}),
|
|
150
|
-
});
|
|
151
|
-
return { abort: (reason) => { controller.abort(reason); }, settled };
|
|
152
|
-
}
|
|
153
51
|
/**
|
|
154
52
|
* Register the consolidation plugin.
|
|
155
53
|
* @param ctx - the host context with jobs, subagents, fs, and sessions.
|
|
@@ -164,11 +62,40 @@ export function apply(ctx, config = {}) {
|
|
|
164
62
|
const minHours = config.minHours ?? 24;
|
|
165
63
|
const minSessions = config.minSessions ?? 5;
|
|
166
64
|
const pressureCooldownMinutes = config.pressureCooldownMinutes ?? 60;
|
|
65
|
+
const sessionsRoot = config.sessionsRoot ?? join(defaultDshHome(), 'sessions');
|
|
167
66
|
// Per-session extraction single-flight. Keyed by session id so each top-level
|
|
168
67
|
// agent's in-flight flag and last-spawned event count are isolated.
|
|
169
68
|
const flight = new Map();
|
|
170
69
|
// One dream in flight across the whole plugin instance (per memory dir).
|
|
171
70
|
let dreamInFlight = false;
|
|
71
|
+
// Scan memo (plan §3.4): caches the RAW unfiltered SessionScanResult for
|
|
72
|
+
// SCAN_MEMO_MS; the lastAt filter/count/hints are recomputed per call. It
|
|
73
|
+
// bounds the failure-path scan storm (lock rolled back → time gate keeps
|
|
74
|
+
// passing → every turn-end would otherwise rescan the store).
|
|
75
|
+
let memo = null;
|
|
76
|
+
// Once-per-process warn state (plan §3.5).
|
|
77
|
+
let warnedRoot = false;
|
|
78
|
+
let warnedZstd = false;
|
|
79
|
+
const scan = async () => {
|
|
80
|
+
const now = Date.now();
|
|
81
|
+
if (memo !== null && now - memo.at < SCAN_MEMO_MS) {
|
|
82
|
+
ctx.logger.debug({ event: 'memory:scan-memo-hit' });
|
|
83
|
+
return memo.result;
|
|
84
|
+
}
|
|
85
|
+
if (typeof zlib.createZstdDecompress !== 'function' && !warnedZstd) {
|
|
86
|
+
warnedZstd = true;
|
|
87
|
+
ctx.logger.warn('memory-consolidation: node:zlib zstd capability missing; dream gates fail closed');
|
|
88
|
+
}
|
|
89
|
+
const t0 = Date.now();
|
|
90
|
+
const result = await scanSessions(sessionsRoot);
|
|
91
|
+
ctx.logger.debug({ event: 'memory:scan', scanned: result.scanned, unreadable: result.unreadable, count: result.sessions.length, ms: Date.now() - t0 });
|
|
92
|
+
if (result.scanned === 0 && !warnedRoot) {
|
|
93
|
+
warnedRoot = true;
|
|
94
|
+
ctx.logger.warn(`memory-consolidation: sessions root unreadable or empty at ${sessionsRoot}`);
|
|
95
|
+
}
|
|
96
|
+
memo = { at: Date.now(), result };
|
|
97
|
+
return result;
|
|
98
|
+
};
|
|
172
99
|
// Reset the flight state when this plugin fiber is disposed (hygiene / test
|
|
173
100
|
// isolation). cordis `ctx.on` is typed strictly to `keyof Events`, so cleanup
|
|
174
101
|
// is registered as a fiber effect rather than a 'dispose' listener.
|
|
@@ -201,13 +128,19 @@ export function apply(ctx, config = {}) {
|
|
|
201
128
|
if (config.dreamEnabled ?? true) {
|
|
202
129
|
if (!dreamInFlight) {
|
|
203
130
|
dreamInFlight = true;
|
|
204
|
-
void runDream(ctx, agent, home, provider, minHours, minSessions, pressureCooldownMinutes)
|
|
205
|
-
.catch(() => { })
|
|
131
|
+
void runDream(ctx, agent, home, provider, minHours, minSessions, pressureCooldownMinutes, sessionsRoot, scan)
|
|
132
|
+
.catch((err) => { ctx.logger.warn(`memory-consolidation: dream dispatch failed: ${String(err)}`); })
|
|
206
133
|
.finally(() => { dreamInFlight = false; });
|
|
207
134
|
}
|
|
208
135
|
}
|
|
209
136
|
});
|
|
210
137
|
}
|
|
138
|
+
/** Memo TTL for the raw session-scan result (plan §3.4). */
|
|
139
|
+
const SCAN_MEMO_MS = 30 * 60_000;
|
|
140
|
+
/** The agent's workspace cwd: where its memory directory is resolved from. */
|
|
141
|
+
function agentCwd(agent) {
|
|
142
|
+
return agent.session.header.cwd ?? process.cwd();
|
|
143
|
+
}
|
|
211
144
|
/**
|
|
212
145
|
* Whether an agent is top-level (not a delegated subagent). This is the root
|
|
213
146
|
* fix for the extraction/dream recursion: a subagent's own turn-end must never
|
|
@@ -231,7 +164,7 @@ const INDEX_TRUNCATED_MARKER = '(index truncated; rely on MEMORY.md in-dir for t
|
|
|
231
164
|
async function runExtraction(ctx, agent, home, provider) {
|
|
232
165
|
// The extraction writes into the turning agent's repository directory —
|
|
233
166
|
// the shared home root holds only explicitly-global memories.
|
|
234
|
-
const dir = resolveWorkspaceMemoryDir(home,
|
|
167
|
+
const dir = resolveWorkspaceMemoryDir(home, agentCwd(agent));
|
|
235
168
|
// Only model-visible surface events count toward the batch size.
|
|
236
169
|
const surfaceCount = agent.session.snapshotEvents().filter((e) => SURFACE_EVENT_TYPES.has(e.type)).length;
|
|
237
170
|
// The index read happens AFTER the in-flight/content gates (runExtraction is
|
|
@@ -302,45 +235,65 @@ async function readExistingIndex(ctx, dir) {
|
|
|
302
235
|
return '';
|
|
303
236
|
}
|
|
304
237
|
}
|
|
305
|
-
async function runDream(ctx, agent, home, provider, minHours, minSessions, pressureCooldownMinutes) {
|
|
238
|
+
async function runDream(ctx, agent, home, provider, minHours, minSessions, pressureCooldownMinutes, sessionsRoot, scan) {
|
|
306
239
|
const fs = ctx.get('fs');
|
|
307
240
|
if (fs === undefined)
|
|
308
241
|
return;
|
|
309
|
-
const dir = resolveWorkspaceMemoryDir(home,
|
|
242
|
+
const dir = resolveWorkspaceMemoryDir(home, agentCwd(agent));
|
|
310
243
|
const now = Date.now();
|
|
311
244
|
const policy = memoryWritePolicy(dir);
|
|
312
245
|
const pressure = await readPressure(fs, dir);
|
|
313
246
|
const lastAt = await readLastConsolidatedAt(fs, dir);
|
|
314
|
-
|
|
247
|
+
let hints;
|
|
315
248
|
if (pressure.armedAt > 0) {
|
|
316
249
|
// Pressure mode: an armed marker bypasses the time/session gates. The
|
|
317
250
|
// cooldown is measured from `lastForcedAt` (not `armedAt`) so a tight arm
|
|
318
251
|
// loop of rejecting saves cannot spin dreams faster than the knob;
|
|
319
252
|
// backwards clock skew (negative delta) counts as within-cooldown.
|
|
320
|
-
if (now - pressure.lastForcedAt < pressureCooldownMinutes * 60_000)
|
|
253
|
+
if (now - pressure.lastForcedAt < pressureCooldownMinutes * 60_000) {
|
|
254
|
+
ctx.logger.debug({ event: 'memory:dream-gates', mode: 'pressure', lastAt, count: 0, minSessions, pass: false, reason: 'cooldown' });
|
|
321
255
|
return;
|
|
256
|
+
}
|
|
322
257
|
// Stamp BEFORE acquiring the lock: consumes the cooldown slot even if the
|
|
323
258
|
// lock is held or the spawn never happens, making the crash-window spawn
|
|
324
259
|
// storm structurally impossible. Failure keeps the marker with this stamp
|
|
325
260
|
// so the next window retries.
|
|
326
261
|
await markPressureForced(fs, dir, pressure.armedAt, now, policy);
|
|
262
|
+
// Scan AFTER the stamp (plan §3.2/§3.3): a zero scan skips the spawn with
|
|
263
|
+
// the marker still armed — the lock was never acquired, so there is
|
|
264
|
+
// nothing to roll back and the next cooldown window retries.
|
|
265
|
+
const scanResult = await scan();
|
|
266
|
+
const window = gateWindow(scanResult.sessions, lastAt);
|
|
267
|
+
ctx.logger.debug({ event: 'memory:dream-gates', mode: 'pressure', lastAt, count: window.count, minSessions, pass: true });
|
|
268
|
+
if (scanResult.scanned === 0)
|
|
269
|
+
return;
|
|
270
|
+
hints = window.hints;
|
|
327
271
|
}
|
|
328
|
-
else
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
minHours
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
272
|
+
else {
|
|
273
|
+
// Periodic: the pure-arithmetic time gate runs FIRST, before any scan I/O;
|
|
274
|
+
// the session-count gate runs only on the scanned result.
|
|
275
|
+
if (!timeGatePasses(lastAt, now, minHours)) {
|
|
276
|
+
ctx.logger.debug({ event: 'memory:dream-gates', mode: 'periodic', lastAt, count: 0, minSessions, pass: false, reason: 'time' });
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
const scanResult = await scan();
|
|
280
|
+
const window = gateWindow(scanResult.sessions, lastAt);
|
|
281
|
+
const pass = sessionGatePasses(window.count, minSessions);
|
|
282
|
+
ctx.logger.debug({ event: 'memory:dream-gates', mode: 'periodic', lastAt, count: window.count, minSessions, pass });
|
|
283
|
+
if (!pass)
|
|
284
|
+
return;
|
|
285
|
+
hints = window.hints;
|
|
336
286
|
}
|
|
337
287
|
const priorAt = await tryAcquireLock(fs, dir, process.pid, now, policy);
|
|
338
|
-
if (priorAt === null)
|
|
288
|
+
if (priorAt === null) {
|
|
289
|
+
ctx.logger.warn(`memory-consolidation: consolidation lock held by a live holder in ${dir}`);
|
|
339
290
|
return;
|
|
340
|
-
|
|
291
|
+
}
|
|
292
|
+
const prompt = buildConsolidationPrompt(dir, sessionsRoot, hints);
|
|
341
293
|
const job = await startMemoryJob(ctx, agent, dir, provider, 'memory-consolidation', prompt);
|
|
342
|
-
void job.
|
|
343
|
-
|
|
294
|
+
void job.done.then((outcome) => {
|
|
295
|
+
ctx.logger.debug({ event: 'memory:dream-outcome', status: outcome.status, detail: outcome.status === 'failed' ? outcome.detail : undefined });
|
|
296
|
+
if (outcome.status !== 'completed') {
|
|
344
297
|
void rollbackLock(fs, dir, priorAt, policy);
|
|
345
298
|
return;
|
|
346
299
|
}
|
|
@@ -349,39 +302,4 @@ async function runDream(ctx, agent, home, provider, minHours, minSessions, press
|
|
|
349
302
|
void clearPressure(fs, dir, now, policy);
|
|
350
303
|
});
|
|
351
304
|
}
|
|
352
|
-
/** Live sessions are the transcripts available to review; absent sessions skip. */
|
|
353
|
-
function listNewSessions(ctx, lastAt) {
|
|
354
|
-
const sessions = ctx.get('sessions');
|
|
355
|
-
if (sessions === undefined)
|
|
356
|
-
return [];
|
|
357
|
-
return sessions
|
|
358
|
-
.list()
|
|
359
|
-
// Subagent sessions (validated delegationDepth > 0) are excluded from both
|
|
360
|
-
// the min-sessions count and the dream input: their content is already
|
|
361
|
-
// covered by turn-end extraction. Absent/invalid depth is treated as 0.
|
|
362
|
-
.filter(session => {
|
|
363
|
-
const d = session.header?.delegationDepth;
|
|
364
|
-
return !(Number.isSafeInteger(d) && d > 0);
|
|
365
|
-
})
|
|
366
|
-
.map(session => ({ id: session.id, at: sessionStartOf(session) }))
|
|
367
|
-
.filter(session => session.at > lastAt)
|
|
368
|
-
.sort((a, b) => a.at - b.at)
|
|
369
|
-
.map(session => session.id);
|
|
370
|
-
}
|
|
371
|
-
/**
|
|
372
|
-
* Session start epoch, defensively read from the header. The dream gate is
|
|
373
|
-
* skip-oriented, so an unreadable or absent timestamp conservatively counts as
|
|
374
|
-
* NEW (over-inclusion only costs a re-read). Accepted limitation: a session
|
|
375
|
-
* created before `lastAt` but still active after it is excluded from the dream
|
|
376
|
-
* input — turn-end extraction covers recent content; dream is a coarse
|
|
377
|
-
* periodic pass.
|
|
378
|
-
*/
|
|
379
|
-
function sessionStartOf(session) {
|
|
380
|
-
const at = session.header?.createdAt;
|
|
381
|
-
return Number.isSafeInteger(at) && at > 0 ? at : Number.MAX_SAFE_INTEGER;
|
|
382
|
-
}
|
|
383
|
-
/** The transcript directory is the agent's cwd. */
|
|
384
|
-
function sessionTranscriptDir(agent) {
|
|
385
|
-
return agent.session.header.cwd ?? process.cwd();
|
|
386
|
-
}
|
|
387
305
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 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AAsB,EAAE,MAAM,CAAC,CAAA;IAC3F,KAAK,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,sBAAsB,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC,CAAA;QAC7I,IAAI,OAAO,CAAC,MAAM,KAAK,WAAW,EAAE,CAAC;YACnC,KAAK,YAAY,CAAC,EAAE,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,CAAC,CAAA;YAC3C,OAAM;QACR,CAAC;QACD,sEAAsE;QACtE,2EAA2E;QAC3E,KAAK,aAAa,CAAC,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,CAAA;IAC1C,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The jobs-seam spawn helper for memory forks (extraction and dream): starts
|
|
3
|
+
* the one-shot subagent as a background job and maps the settled outcome onto
|
|
4
|
+
* the JobHooks contract.
|
|
5
|
+
* @module @dsh-cc/memory-consolidation/memory-job
|
|
6
|
+
*/
|
|
7
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
8
|
+
import type { Agent } from '@deepseek-ai/dsh-agent';
|
|
9
|
+
/** The job-done outcome: resolves only, per the JobHooks contract. */
|
|
10
|
+
export type JobOutcome = {
|
|
11
|
+
status: 'completed';
|
|
12
|
+
} | {
|
|
13
|
+
status: 'killed';
|
|
14
|
+
} | {
|
|
15
|
+
status: 'failed';
|
|
16
|
+
detail: string;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Design §2.4 fallback: if the reported payload carries an over-limit
|
|
20
|
+
* `MEMORY.md`, replace its content with the deterministic truncation output
|
|
21
|
+
* (capped body + visible in-file warning banner) instead of failing the job.
|
|
22
|
+
* Plain rejection would fail the dream, roll back the lock, and retry every
|
|
23
|
+
* turn-end forever with zero durable output. Topic-file writes pass through
|
|
24
|
+
* untouched; a compliant entrypoint is returned byte-identical. Takes the raw
|
|
25
|
+
* structured payload (the entrypoint gate inside `validateMemoryWrites`
|
|
26
|
+
* throws during validation, so the replacement must happen before it) and
|
|
27
|
+
* returns a payload of the same shape; malformed payloads pass through and
|
|
28
|
+
* are rejected by validation as usual.
|
|
29
|
+
*/
|
|
30
|
+
export declare function applyEntrypointFallback(payload: unknown): unknown;
|
|
31
|
+
/**
|
|
32
|
+
* Start a memory-scoped forked subagent as a background job. The fork reports
|
|
33
|
+
* its file set via `outputSchema`; on settlement the plugin validates the
|
|
34
|
+
* batch and writes it host-side under a policy confined to `dir`. Resolves to
|
|
35
|
+
* a control object with an abort hook and a settle promise (true only when
|
|
36
|
+
* the reported writes were validated and persisted).
|
|
37
|
+
*/
|
|
38
|
+
export declare function startMemoryJob(ctx: Context, agent: Agent, dir: string, provider: string, label: string, prompt: string): Promise<{
|
|
39
|
+
abort(reason?: string): void;
|
|
40
|
+
settled: Promise<boolean>;
|
|
41
|
+
done: Promise<JobOutcome>;
|
|
42
|
+
}>;
|
|
43
|
+
//# sourceMappingURL=memory-job.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory-job.d.ts","sourceRoot":"","sources":["../src/memory-job.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAA;AAgDnD,sEAAsE;AACtE,MAAM,MAAM,UAAU,GAAG;IAAE,MAAM,EAAE,WAAW,CAAA;CAAE,GAAG;IAAE,MAAM,EAAE,QAAQ,CAAA;CAAE,GAAG;IAAE,MAAM,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAA;AAc9G;;;;;;;;;;;GAWG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAajE;AAED;;;;;;GAMG;AACH,wBAAsB,cAAc,CAClC,GAAG,EAAE,OAAO,EACZ,KAAK,EAAE,KAAK,EACZ,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,GACb,OAAO,CAAC;IAAE,KAAK,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;IAAC,IAAI,EAAE,OAAO,CAAC,UAAU,CAAC,CAAA;CAAE,CAAC,CA6DjG"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The jobs-seam spawn helper for memory forks (extraction and dream): starts
|
|
3
|
+
* the one-shot subagent as a background job and maps the settled outcome onto
|
|
4
|
+
* the JobHooks contract.
|
|
5
|
+
* @module @dsh-cc/memory-consolidation/memory-job
|
|
6
|
+
*/
|
|
7
|
+
import { MEMORY_WRITES_SCHEMA, validateMemoryWrites, writeMemoryFiles, ENTRYPOINT_NAME, MAX_ENTRYPOINT_LINES, MAX_ENTRYPOINT_BYTES, truncateEntrypointContent, } from '@dsh-cc/memory';
|
|
8
|
+
import { MEMORY_TOOL_FILTER } from "./tools.js";
|
|
9
|
+
/**
|
|
10
|
+
* Over-limit measurement for the entrypoint, identical to the write-side gate
|
|
11
|
+
* semantics (trim → split('\n') → count; byteLength of the trimmed content).
|
|
12
|
+
* @param content - a reported `MEMORY.md` body.
|
|
13
|
+
*/
|
|
14
|
+
function entrypointOverLimit(content) {
|
|
15
|
+
const trimmed = content.trim();
|
|
16
|
+
return trimmed.split('\n').length > MAX_ENTRYPOINT_LINES
|
|
17
|
+
|| Buffer.byteLength(trimmed, 'utf8') > MAX_ENTRYPOINT_BYTES;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Design §2.4 fallback: if the reported payload carries an over-limit
|
|
21
|
+
* `MEMORY.md`, replace its content with the deterministic truncation output
|
|
22
|
+
* (capped body + visible in-file warning banner) instead of failing the job.
|
|
23
|
+
* Plain rejection would fail the dream, roll back the lock, and retry every
|
|
24
|
+
* turn-end forever with zero durable output. Topic-file writes pass through
|
|
25
|
+
* untouched; a compliant entrypoint is returned byte-identical. Takes the raw
|
|
26
|
+
* structured payload (the entrypoint gate inside `validateMemoryWrites`
|
|
27
|
+
* throws during validation, so the replacement must happen before it) and
|
|
28
|
+
* returns a payload of the same shape; malformed payloads pass through and
|
|
29
|
+
* are rejected by validation as usual.
|
|
30
|
+
*/
|
|
31
|
+
export function applyEntrypointFallback(payload) {
|
|
32
|
+
if (typeof payload !== 'object' || payload === null || Array.isArray(payload))
|
|
33
|
+
return payload;
|
|
34
|
+
const raw = payload.writes;
|
|
35
|
+
if (!Array.isArray(raw))
|
|
36
|
+
return payload;
|
|
37
|
+
const writes = raw.map((entry) => {
|
|
38
|
+
if (typeof entry !== 'object' || entry === null)
|
|
39
|
+
return entry;
|
|
40
|
+
const { path, content } = entry;
|
|
41
|
+
if (path !== ENTRYPOINT_NAME || typeof content !== 'string' || !entrypointOverLimit(content)) {
|
|
42
|
+
return entry;
|
|
43
|
+
}
|
|
44
|
+
return { ...entry, content: truncateEntrypointContent(content).content };
|
|
45
|
+
});
|
|
46
|
+
return { ...payload, writes };
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Start a memory-scoped forked subagent as a background job. The fork reports
|
|
50
|
+
* its file set via `outputSchema`; on settlement the plugin validates the
|
|
51
|
+
* batch and writes it host-side under a policy confined to `dir`. Resolves to
|
|
52
|
+
* a control object with an abort hook and a settle promise (true only when
|
|
53
|
+
* the reported writes were validated and persisted).
|
|
54
|
+
*/
|
|
55
|
+
export async function startMemoryJob(ctx, agent, dir, provider, label, prompt) {
|
|
56
|
+
const jobs = ctx.get('jobs');
|
|
57
|
+
const subagents = ctx.get('subagents');
|
|
58
|
+
if (jobs === undefined || subagents === undefined) {
|
|
59
|
+
return { abort: () => { }, settled: Promise.resolve(false), done: Promise.resolve({ status: 'failed', detail: 'jobs/subagents seam unavailable' }) };
|
|
60
|
+
}
|
|
61
|
+
const fs = ctx.get('fs');
|
|
62
|
+
const controller = new AbortController();
|
|
63
|
+
// `subagents.start` is async upstream — awaiting it is what exposes the run's
|
|
64
|
+
// `result` promise. Reading `run.result` on the un-awaited Promise throws
|
|
65
|
+
// "Cannot read properties of undefined (reading 'then')" and poisons the
|
|
66
|
+
// turn-stopping dispatch.
|
|
67
|
+
const run = await subagents.start(provider, {
|
|
68
|
+
label,
|
|
69
|
+
signal: controller.signal,
|
|
70
|
+
prompt: [{ type: 'text', text: prompt }],
|
|
71
|
+
parent: agent,
|
|
72
|
+
toolFilter: MEMORY_TOOL_FILTER,
|
|
73
|
+
// Defense-in-depth recursion cap: the top-level listener already gates on
|
|
74
|
+
// depth zero, so this fork's child never delegates. maxDepth is compared
|
|
75
|
+
// against the CHILD's resolved depth (parent + 1); a top-level parent's
|
|
76
|
+
// child resolves to 1 and passes, a grandchild to 2 is rejected.
|
|
77
|
+
maxDepth: 1,
|
|
78
|
+
outputSchema: MEMORY_WRITES_SCHEMA,
|
|
79
|
+
});
|
|
80
|
+
// Real job-done wiring: `done` maps the subagent outcome onto the JobHooks
|
|
81
|
+
// contract (must never reject). Aborted → killed (rolls back the dream
|
|
82
|
+
// lock); a non-completed stopReason, a missing/invalid payload, or a
|
|
83
|
+
// write-back failure → failed with detail; a validated, persisted batch →
|
|
84
|
+
// completed. All branches resolve.
|
|
85
|
+
const done = run.result.then(async (res) => {
|
|
86
|
+
if (controller.signal.aborted)
|
|
87
|
+
return { status: 'killed' };
|
|
88
|
+
if (res?.stopReason !== 'completed') {
|
|
89
|
+
return { status: 'failed', detail: `memory fork ended with stopReason ${String(res?.stopReason)}` };
|
|
90
|
+
}
|
|
91
|
+
if (fs === undefined) {
|
|
92
|
+
return { status: 'failed', detail: 'fs seam unavailable for memory write-back' };
|
|
93
|
+
}
|
|
94
|
+
try {
|
|
95
|
+
const writes = validateMemoryWrites(applyEntrypointFallback(res.structured));
|
|
96
|
+
await writeMemoryFiles(fs, dir, writes);
|
|
97
|
+
return { status: 'completed' };
|
|
98
|
+
}
|
|
99
|
+
catch (err) {
|
|
100
|
+
return { status: 'failed', detail: String(err) };
|
|
101
|
+
}
|
|
102
|
+
}, (err) => controller.signal.aborted ? { status: 'killed' } : { status: 'failed', detail: String(err) });
|
|
103
|
+
const settled = done.then(o => o.status === 'completed');
|
|
104
|
+
jobs.start({
|
|
105
|
+
kind: 'subagent',
|
|
106
|
+
label,
|
|
107
|
+
owner: agent,
|
|
108
|
+
run: () => ({
|
|
109
|
+
cancel: (reason) => { controller.abort(reason); },
|
|
110
|
+
done,
|
|
111
|
+
}),
|
|
112
|
+
});
|
|
113
|
+
return { abort: (reason) => { controller.abort(reason); }, settled, done };
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=memory-job.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory-job.js","sourceRoot":"","sources":["../src/memory-job.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EACpB,gBAAgB,EAChB,eAAe,EACf,oBAAoB,EACpB,oBAAoB,EACpB,yBAAyB,GAC1B,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAyC/C;;;;GAIG;AACH,SAAS,mBAAmB,CAAC,OAAe;IAC1C,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,EAAE,CAAA;IAC9B,OAAO,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,GAAG,oBAAoB;WACnD,MAAM,CAAC,UAAU,CAAC,OAAO,EAAE,MAAM,CAAC,GA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OAAO,EAAE,IAAI,EAAE,CAAA;AACpF,CAAC"}
|
package/lib/prompts.d.ts
CHANGED
|
@@ -22,9 +22,10 @@ export declare function buildExtractionPrompt(surfaceMessageCount: number, memor
|
|
|
22
22
|
* Build the <system-reminder> user prompt that reviews past sessions and
|
|
23
23
|
* consolidates them into the memory directory, returned as structured writes.
|
|
24
24
|
* @param memoryDir - the memory directory being rewritten.
|
|
25
|
-
* @param
|
|
26
|
-
* @param sessionHints -
|
|
25
|
+
* @param sessionsRoot - the real session store root the hint ids live under.
|
|
26
|
+
* @param sessionHints - session ids marking the consolidation window (provenance
|
|
27
|
+
* hints only; transcripts are zstd-compressed and not readable by the fork).
|
|
27
28
|
* @returns the prompt text.
|
|
28
29
|
*/
|
|
29
|
-
export declare function buildConsolidationPrompt(memoryDir: string,
|
|
30
|
+
export declare function buildConsolidationPrompt(memoryDir: string, sessionsRoot: string, sessionHints: readonly string[]): string;
|
|
30
31
|
//# sourceMappingURL=prompts.d.ts.map
|
package/lib/prompts.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompts.d.ts","sourceRoot":"","sources":["../src/prompts.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAOH;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,CACnC,mBAAmB,EAAE,MAAM,EAC3B,SAAS,EAAE,MAAM,EACjB,aAAa,EAAE,MAAM,GACpB,MAAM,CAeR;AAED
|
|
1
|
+
{"version":3,"file":"prompts.d.ts","sourceRoot":"","sources":["../src/prompts.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAOH;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,CACnC,mBAAmB,EAAE,MAAM,EAC3B,SAAS,EAAE,MAAM,EACjB,aAAa,EAAE,MAAM,GACpB,MAAM,CAeR;AAED;;;;;;;;GAQG;AACH,wBAAgB,wBAAwB,CACtC,SAAS,EAAE,MAAM,EACjB,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,SAAS,MAAM,EAAE,GAC9B,MAAM,CAgBR"}
|
package/lib/prompts.js
CHANGED
|
@@ -40,24 +40,25 @@ export function buildExtractionPrompt(surfaceMessageCount, memoryDir, existingIn
|
|
|
40
40
|
* Build the <system-reminder> user prompt that reviews past sessions and
|
|
41
41
|
* consolidates them into the memory directory, returned as structured writes.
|
|
42
42
|
* @param memoryDir - the memory directory being rewritten.
|
|
43
|
-
* @param
|
|
44
|
-
* @param sessionHints -
|
|
43
|
+
* @param sessionsRoot - the real session store root the hint ids live under.
|
|
44
|
+
* @param sessionHints - session ids marking the consolidation window (provenance
|
|
45
|
+
* hints only; transcripts are zstd-compressed and not readable by the fork).
|
|
45
46
|
* @returns the prompt text.
|
|
46
47
|
*/
|
|
47
|
-
export function buildConsolidationPrompt(memoryDir,
|
|
48
|
+
export function buildConsolidationPrompt(memoryDir, sessionsRoot, sessionHints) {
|
|
48
49
|
return [
|
|
49
|
-
`You are consolidating persistent memory from past sessions.
|
|
50
|
+
`You are consolidating persistent memory from past sessions. Distill durable facts and rewrite the memory directory \`${memoryDir}\`.`,
|
|
50
51
|
'The memory directory contains MEMORY.md (an index of topic files) and topic `.md` files with YAML frontmatter (name, description, type).',
|
|
51
52
|
'Return the complete rewritten file set via the `structured_output` tool as `{ "writes": [{ "path", "content" }] }` — flat `.md` filenames with complete bodies. Only the files you return are written; omitted files stay unchanged on disk.',
|
|
52
53
|
'Work in this order:',
|
|
53
54
|
`1. Orient: list \`${memoryDir}\`, then read ${ENTRYPOINT_NAME} and the topic files it points at — that is your primary review material.`,
|
|
54
55
|
'2. Verify against reality: the fork\'s working directory IS the session\'s workspace. Before keeping any load-bearing fact, check it against the current codebase (paths, commands, behavior) with read/grep/glob. On a contradiction between two memories, fix the wrong side. Delete facts referencing things that no longer exist.',
|
|
55
56
|
'3. Normalize dates: convert every relative date ("yesterday", "last week") to the absolute date it referred to.',
|
|
56
|
-
`4.
|
|
57
|
+
`4. Treat the session hints below as provenance only: they mark which sessions the consolidation window covers. The fork cannot read transcripts (zstd) — never attempt to open or grep them.`,
|
|
57
58
|
`5. Prune and index: rewrite ${ENTRYPOINT_NAME} as one line per topic, targeting under 140 lines (an index over 200 lines / 25 KB is rejected host-side, so stay well under). Move detail into topic files, organized by semantic topic, and keep still-true load-bearing facts.`,
|
|
58
59
|
`You may use only: ${MEMORY_AGENT_TOOLS.join(', ')}.`,
|
|
59
60
|
'',
|
|
60
|
-
|
|
61
|
+
`Session provenance hints (ids under \`${sessionsRoot}\`):`,
|
|
61
62
|
...sessionHints.map(id => `- ${id}`),
|
|
62
63
|
].join('\n');
|
|
63
64
|
}
|
package/lib/prompts.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompts.js","sourceRoot":"","sources":["../src/prompts.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAE/C,wEAAwE;AACxE,MAAM,eAAe,GAAG,WAAW,CAAA;AAEnC;;;;;;;;GAQG;AACH,MAAM,UAAU,qBAAqB,CACnC,mBAA2B,EAC3B,SAAiB,EACjB,aAAqB;IAErB,OAAO;QACL,0CAA0C,mBAAmB,oFAAoF;QACjJ,0GAA0G;QAC1G,sGAAsG,SAAS,iKAAiK;QAChR,mJAAmJ;QACnJ,yCAAyC,eAAe,iEAAiE;QACzH,sJAAsJ;QACtJ,qBAAqB,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,wBAAwB,SAAS,KAAK;QACxF,+HAA+H;QAC/H,gIAAgI;QAChI,EAAE;QACF,kBAAkB;QAClB,aAAa,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,YAAY;KACxD,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AACd,CAAC;AAED
|
|
1
|
+
{"version":3,"file":"prompts.js","sourceRoot":"","sources":["../src/prompts.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAE/C,wEAAwE;AACxE,MAAM,eAAe,GAAG,WAAW,CAAA;AAEnC;;;;;;;;GAQG;AACH,MAAM,UAAU,qBAAqB,CACnC,mBAA2B,EAC3B,SAAiB,EACjB,aAAqB;IAErB,OAAO;QACL,0CAA0C,mBAAmB,oFAAoF;QACjJ,0GAA0G;QAC1G,sGAAsG,SAAS,iKAAiK;QAChR,mJAAmJ;QACnJ,yCAAyC,eAAe,iEAAiE;QACzH,sJAAsJ;QACtJ,qBAAqB,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,wBAAwB,SAAS,KAAK;QACxF,+HAA+H;QAC/H,gIAAgI;QAChI,EAAE;QACF,kBAAkB;QAClB,aAAa,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,YAAY;KACxD,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AACd,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,wBAAwB,CACtC,SAAiB,EACjB,YAAoB,EACpB,YAA+B;IAE/B,OAAO;QACL,wHAAwH,SAAS,KAAK;QACtI,0IAA0I;QAC1I,8OAA8O;QAC9O,qBAAqB;QACrB,qBAAqB,SAAS,iBAAiB,eAAe,2EAA2E;QACzI,uUAAuU;QACvU,iHAAiH;QACjH,8LAA8L;QAC9L,+BAA+B,eAAe,mOAAmO;QACjR,qBAAqB,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG;QACrD,EAAE;QACF,yCAAyC,YAAY,MAAM;QAC3D,GAAG,YAAY,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC;KACrC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AACd,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/** One session directory's classification, unfiltered by any gate window. */
|
|
2
|
+
export interface ScannedSession {
|
|
3
|
+
id: string;
|
|
4
|
+
createdAt: number;
|
|
5
|
+
sub: boolean;
|
|
6
|
+
}
|
|
7
|
+
export interface SessionScanResult {
|
|
8
|
+
/** All classifiable sessions, so the memo can be shared across repos. */
|
|
9
|
+
sessions: ScannedSession[];
|
|
10
|
+
/** Session directories seen, classifiable or not. */
|
|
11
|
+
scanned: number;
|
|
12
|
+
/** Directories skipped because no readable stream/header was found. */
|
|
13
|
+
unreadable: number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Scan the session store: classify every depth-2 directory from its stream
|
|
17
|
+
* header. A missing/unreadable root yields a zeroed result, never an throw.
|
|
18
|
+
*/
|
|
19
|
+
export declare function scanSessions(sessionsRoot: string): Promise<SessionScanResult>;
|
|
20
|
+
/**
|
|
21
|
+
* The gate window: qualify (`!sub && createdAt > lastAt`), count all
|
|
22
|
+
* qualifying, and select up to 50 hint ids, most-recent first. Pure.
|
|
23
|
+
*/
|
|
24
|
+
export declare function gateWindow(sessions: readonly ScannedSession[], lastAt: number): {
|
|
25
|
+
count: number;
|
|
26
|
+
hints: string[];
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=session-scan.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-scan.d.ts","sourceRoot":"","sources":["../src/session-scan.ts"],"names":[],"mappings":"AAwBA,6EAA6E;AAC7E,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,GAAG,EAAE,OAAO,CAAC;CACd;AAED,MAAM,WAAW,iBAAiB;IAChC,yEAAyE;IACzE,QAAQ,EAAE,cAAc,EAAE,CAAC;IAC3B,qDAAqD;IACrD,OAAO,EAAE,MAAM,CAAC;IAChB,uEAAuE;IACvE,UAAU,EAAE,MAAM,CAAC;CACpB;AAiFD;;;GAGG;AACH,wBAAsB,YAAY,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAqCnF;AAED;;;GAGG;AACH,wBAAgB,UAAU,CACxB,QAAQ,EAAE,SAAS,cAAc,EAAE,EACnC,MAAM,EAAE,MAAM,GACb;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,EAAE,CAAA;CAAE,CAOpC"}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session-store scanner: walk the dsh-cc sessions store and classify each
|
|
3
|
+
* session directory from its header line, unfiltered by any gate window.
|
|
4
|
+
*
|
|
5
|
+
* Layout: `<sessionsRoot>/<projectKey>/<sessionId>/<stream>`; any directory at
|
|
6
|
+
* depth 2 is treated as a session dir. Stream resolution mirrors
|
|
7
|
+
* session-forensics/src/scan.ts: prefer `session.v3.jsonl.zstd`, fall back to
|
|
8
|
+
* the legacy `session.jsonl.zstd` (the writer emits exactly one format per
|
|
9
|
+
* dir). Only the header line is needed, so the read is a bounded prefix
|
|
10
|
+
* (256 KiB compressed → 16 KiB decompressed) via `node:fs`/`node:zlib`
|
|
11
|
+
* in-process zstd — no fs seam (prefix reads are impossible over it) and no
|
|
12
|
+
* `zstd` CLI (plan §3.1, cold-review blockers #1/#2).
|
|
13
|
+
*
|
|
14
|
+
* Every failure is classified, never thrown: unreadable dirs count toward
|
|
15
|
+
* `unreadable`, a missing root or absent zstd capability yields a zeroed
|
|
16
|
+
* result.
|
|
17
|
+
* @module @dsh-cc/memory-consolidation/session-scan
|
|
18
|
+
*/
|
|
19
|
+
import { createReadStream } from "node:fs";
|
|
20
|
+
import { readdir } from "node:fs/promises";
|
|
21
|
+
import { join } from "node:path";
|
|
22
|
+
import * as zlib from "node:zlib";
|
|
23
|
+
import { StringDecoder } from "node:string_decoder";
|
|
24
|
+
/** Compressed prefix window (bytes) read from the stream file. */
|
|
25
|
+
const READ_WINDOW = 256 * 1024;
|
|
26
|
+
/** Decompressed text budget: stop reading once the header must have surfaced. */
|
|
27
|
+
const TEXT_BUDGET = 16 * 1024;
|
|
28
|
+
const V3_STREAM = "session.v3.jsonl.zstd";
|
|
29
|
+
const LEGACY_STREAM = "session.jsonl.zstd";
|
|
30
|
+
function isSafeInt(value) {
|
|
31
|
+
return typeof value === "number" && Number.isSafeInteger(value);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Decompress a bounded prefix of the stream and return the first
|
|
35
|
+
* `type: "session"` JSONL header, or undefined when none surfaces within the
|
|
36
|
+
* budget / the stream is corrupt. Never rejects.
|
|
37
|
+
*/
|
|
38
|
+
function readHeader(streamPath) {
|
|
39
|
+
// Capability check (plan §3.1): undated/nonstandard Node without in-process
|
|
40
|
+
// zstd fails closed here.
|
|
41
|
+
if (typeof zlib.createZstdDecompress !== "function")
|
|
42
|
+
return Promise.resolve(undefined);
|
|
43
|
+
return new Promise((resolve) => {
|
|
44
|
+
let text = "";
|
|
45
|
+
let settled = false;
|
|
46
|
+
const finish = (header) => {
|
|
47
|
+
if (settled)
|
|
48
|
+
return;
|
|
49
|
+
settled = true;
|
|
50
|
+
source.destroy();
|
|
51
|
+
zstd.destroy();
|
|
52
|
+
resolve(header);
|
|
53
|
+
};
|
|
54
|
+
const findHeader = () => {
|
|
55
|
+
for (const line of text.split("\n")) {
|
|
56
|
+
if (!line.includes('"type":"session"'))
|
|
57
|
+
continue;
|
|
58
|
+
try {
|
|
59
|
+
const entry = JSON.parse(line);
|
|
60
|
+
if (entry?.type === "session")
|
|
61
|
+
return entry;
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
// torn or non-JSON line: keep scanning
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return undefined;
|
|
68
|
+
};
|
|
69
|
+
// StringDecoder (not chunk.toString) so a multibyte char split across
|
|
70
|
+
// streams can't inject U+FFFD and silently break the header JSON.parse.
|
|
71
|
+
const decoder = new StringDecoder("utf8");
|
|
72
|
+
const onChunk = (chunk) => {
|
|
73
|
+
text += decoder.write(chunk);
|
|
74
|
+
if (text.length >= TEXT_BUDGET)
|
|
75
|
+
finish(findHeader());
|
|
76
|
+
};
|
|
77
|
+
const source = createReadStream(streamPath, { start: 0, end: READ_WINDOW - 1 });
|
|
78
|
+
const zstd = zlib.createZstdDecompress();
|
|
79
|
+
source.pipe(zstd);
|
|
80
|
+
zstd.on("data", onChunk);
|
|
81
|
+
source.on("error", () => finish(undefined));
|
|
82
|
+
zstd.on("error", () => finish(undefined));
|
|
83
|
+
zstd.on("end", () => { text += decoder.end(); finish(findHeader()); });
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
/** Classify a header line per the pinned v3 contract, defensively. */
|
|
87
|
+
function classify(header, dirName) {
|
|
88
|
+
const data = header.data;
|
|
89
|
+
const createdRaw = header.createdAt ?? header.time ?? header.ts ?? header.timestamp;
|
|
90
|
+
// Missing/garbage timestamp counts as NEW (fails open to over-inclusion).
|
|
91
|
+
const createdAt = isSafeInt(createdRaw) ? createdRaw : Number.MAX_SAFE_INTEGER;
|
|
92
|
+
const depth = isSafeInt(header.delegationDepth)
|
|
93
|
+
? header.delegationDepth
|
|
94
|
+
: isSafeInt(data?.delegationDepth)
|
|
95
|
+
? data.delegationDepth
|
|
96
|
+
: 0;
|
|
97
|
+
const origin = header.origin ?? data?.origin;
|
|
98
|
+
return {
|
|
99
|
+
id: typeof header.id === "string" && header.id.length > 0 ? header.id : dirName,
|
|
100
|
+
createdAt,
|
|
101
|
+
sub: depth > 0 || origin === "subagent",
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Scan the session store: classify every depth-2 directory from its stream
|
|
106
|
+
* header. A missing/unreadable root yields a zeroed result, never an throw.
|
|
107
|
+
*/
|
|
108
|
+
export async function scanSessions(sessionsRoot) {
|
|
109
|
+
const zeroed = { sessions: [], scanned: 0, unreadable: 0 };
|
|
110
|
+
// Capability check (plan §3.1): undated/nonstandard Node without in-process
|
|
111
|
+
// zstd fails closed to a zeroed result.
|
|
112
|
+
if (typeof zlib.createZstdDecompress !== "function")
|
|
113
|
+
return zeroed;
|
|
114
|
+
try {
|
|
115
|
+
const projects = await readdir(sessionsRoot, { withFileTypes: true });
|
|
116
|
+
const sessions = [];
|
|
117
|
+
let scanned = 0;
|
|
118
|
+
let unreadable = 0;
|
|
119
|
+
for (const project of projects) {
|
|
120
|
+
if (!project.isDirectory())
|
|
121
|
+
continue;
|
|
122
|
+
const projectDir = join(sessionsRoot, project.name);
|
|
123
|
+
let entries;
|
|
124
|
+
try {
|
|
125
|
+
entries = await readdir(projectDir, { withFileTypes: true });
|
|
126
|
+
}
|
|
127
|
+
catch {
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
for (const entry of entries) {
|
|
131
|
+
if (!entry.isDirectory())
|
|
132
|
+
continue;
|
|
133
|
+
scanned++;
|
|
134
|
+
const sessionDir = join(projectDir, entry.name);
|
|
135
|
+
// Stream resolution mirrors session-forensics/src/scan.ts.
|
|
136
|
+
let header;
|
|
137
|
+
for (const stream of [V3_STREAM, LEGACY_STREAM]) {
|
|
138
|
+
header = await readHeader(join(sessionDir, stream));
|
|
139
|
+
if (header !== undefined)
|
|
140
|
+
break;
|
|
141
|
+
}
|
|
142
|
+
if (header === undefined)
|
|
143
|
+
unreadable++;
|
|
144
|
+
else
|
|
145
|
+
sessions.push(classify(header, entry.name));
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return { sessions, scanned, unreadable };
|
|
149
|
+
}
|
|
150
|
+
catch {
|
|
151
|
+
return zeroed;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* The gate window: qualify (`!sub && createdAt > lastAt`), count all
|
|
156
|
+
* qualifying, and select up to 50 hint ids, most-recent first. Pure.
|
|
157
|
+
*/
|
|
158
|
+
export function gateWindow(sessions, lastAt) {
|
|
159
|
+
const qualifying = sessions.filter((s) => !s.sub && s.createdAt > lastAt);
|
|
160
|
+
const hints = [...qualifying]
|
|
161
|
+
.sort((a, b) => b.createdAt - a.createdAt)
|
|
162
|
+
.slice(0, 50)
|
|
163
|
+
.map((s) => s.id);
|
|
164
|
+
return { count: qualifying.length, hints };
|
|
165
|
+
}
|
|
166
|
+
//# sourceMappingURL=session-scan.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-scan.js","sourceRoot":"","sources":["../src/session-scan.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAkBpD,kEAAkE;AAClE,MAAM,WAAW,GAAG,GAAG,GAAG,IAAI,CAAC;AAC/B,iFAAiF;AACjF,MAAM,WAAW,GAAG,EAAE,GAAG,IAAI,CAAC;AAE9B,MAAM,SAAS,GAAG,uBAAuB,CAAC;AAC1C,MAAM,aAAa,GAAG,oBAAoB,CAAC;AAE3C,SAAS,SAAS,CAAC,KAAc;IAC/B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;AAClE,CAAC;AAED;;;;GAIG;AACH,SAAS,UAAU,CAAC,UAAkB;IACpC,4EAA4E;IAC5E,0BAA0B;IAC1B,IAAI,OAAO,IAAI,CAAC,oBAAoB,KAAK,UAAU;QAAE,OAAO,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IACvF,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,IAAI,IAAI,GAAG,EAAE,CAAC;QACd,IAAI,OAAO,GAAG,KAAK,CAAC;QACpB,MAAM,MAAM,GAAG,CAAC,MAAuC,EAAE,EAAE;YACzD,IAAI,OAAO;gBAAE,OAAO;YACpB,OAAO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AC,EAAE,CAAC;oBAChD,MAAM,GAAG,MAAM,UAAU,CAAC,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC,CAAC;oBACpD,IAAI,MAAM,KAAK,SAAS;wBAAE,MAAM;gBAClC,CAAC;gBACD,IAAI,MAAM,KAAK,SAAS;oBAAE,UAAU,EAAE,CAAC;;oBAClC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;YACnD,CAAC;QACH,CAAC;QACD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC;IAC3C,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,MAAM,CAAC;IAChB,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,UAAU,CACxB,QAAmC,EACnC,MAAc;IAEd,MAAM,UAAU,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,SAAS,GAAG,MAAM,CAAC,CAAC;IAC1E,MAAM,KAAK,GAAG,CAAC,GAAG,UAAU,CAAC;SAC1B,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,GAAG,CAAC,CAAC,SAAS,CAAC;SACzC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC;SACZ,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IACpB,OAAO,EAAE,KAAK,EAAE,UAAU,CAAC,MAAM,EAAE,KAAK,EAAE,CAAC;AAC7C,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dsh-cc/memory-consolidation",
|
|
3
3
|
"description": "Background memory consolidation: turn-end extraction and three-gate dream rewrite",
|
|
4
|
-
"version": "0.8.0-rc.
|
|
4
|
+
"version": "0.8.0-rc.2",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/dsh-cc/dsh-cc.git",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"@deepseek-ai/schemastery": "^3.18.1"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@dsh-cc/memory": "^0.8.0-rc.
|
|
39
|
+
"@dsh-cc/memory": "^0.8.0-rc.2"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@deepseek-ai/cordis": "link:../../../../deepseek-harness/vendor/cordis",
|