@dsh-cc/memory-consolidation 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/prompts.js ADDED
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Prompt builders for the extraction and dream forks. Both are pure text
3
+ * assembly so they are unit-testable and stable model-visible contracts.
4
+ *
5
+ * The forks hold no write tools: they report their file set through the
6
+ * driver-injected `structured_output` tool, and the plugin writes the files
7
+ * host-side (see `writeback.ts`). The prompts below are the model-facing half
8
+ * of that contract.
9
+ * @module @dsh-cc/memory-consolidation/prompts
10
+ */
11
+ import { MEMORY_AGENT_TOOLS } from "./tools.js";
12
+ /** The always-loaded index filename (mirrors `dsh-memory`'s export). */
13
+ const ENTRYPOINT_NAME = 'MEMORY.md';
14
+ /**
15
+ * Build the <system-reminder> user prompt that extracts durable facts from a
16
+ * batch of recent model-visible messages into structured memory writes.
17
+ * @param surfaceMessageCount - how many model-visible surface events (user/message
18
+ * + assistant/message + tool/result) this run reviews.
19
+ * @param memoryDir - the memory directory the reported files belong to.
20
+ * @param existingIndex - a prior topic manifest, if any.
21
+ * @returns the prompt text.
22
+ */
23
+ export function buildExtractionPrompt(surfaceMessageCount, memoryDir, existingIndex) {
24
+ return [
25
+ `Extract durable memories from the last ${surfaceMessageCount} messages of this conversation and report them via the \`structured_output\` tool.`,
26
+ 'A memory is a fact or preference that will be useful in FUTURE conversations, not ephemeral task detail.',
27
+ `Return \`{ "writes": [{ "path", "content" }] }\`: each entry is one file in the memory directory \`${memoryDir}\` — \`path\` is a flat \`.md\` filename (no directories), \`content\` is the complete file body. The plugin writes the files for you; you have no write tools.`,
28
+ 'Write each memory to its own `.md` topic file with YAML frontmatter: name, description, and type (`user` | `feedback` | `project` | `reference`).',
29
+ `Add or update a one-line pointer in \`${ENTRYPOINT_NAME}\` for each topic (.md). Do not put memory bodies in the index.`,
30
+ 'Never duplicate a topic listed under "Existing topics" below; prefer updating the matching topic file instead of creating a new one (read it first).',
31
+ `You may use only: ${MEMORY_AGENT_TOOLS.join(', ')}. Read only inside \`${memoryDir}\`.`,
32
+ 'The conversation to review is already in your context — do not open files or browse directories outside the memory directory.',
33
+ 'If the reviewed messages contain no new durable fact worth remembering, return an empty `writes` array and finish immediately.',
34
+ '',
35
+ 'Existing topics:',
36
+ existingIndex.length > 0 ? existingIndex : '(none yet)',
37
+ ].join('\n');
38
+ }
39
+ /**
40
+ * Build the <system-reminder> user prompt that reviews past sessions and
41
+ * consolidates them into the memory directory, returned as structured writes.
42
+ * @param memoryDir - the memory directory being rewritten.
43
+ * @param transcriptDir - the directory holding past session transcripts.
44
+ * @param sessionHints - a list of session ids to review.
45
+ * @returns the prompt text.
46
+ */
47
+ export function buildConsolidationPrompt(memoryDir, transcriptDir, sessionHints) {
48
+ return [
49
+ `You are consolidating persistent memory from past sessions. Review the sessions listed below (transcripts in \`${transcriptDir}\`), distill durable facts, and rewrite the memory directory \`${memoryDir}\`.`,
50
+ 'The memory directory contains MEMORY.md (an index of topic files) and topic `.md` files with YAML frontmatter (name, description, type).',
51
+ '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
+ `Rewrite \`${ENTRYPOINT_NAME}\` to be a concise index (one line per topic) and keep topic files organized by semantic topic, not chronology.`,
53
+ 'Remove memories that are wrong or outdated from the index. Do not drop a fact that is still load-bearing.',
54
+ `You may use only: ${MEMORY_AGENT_TOOLS.join(', ')}.`,
55
+ '',
56
+ 'Sessions since the last consolidation:',
57
+ ...sessionHints.map(id => `- ${id}`),
58
+ ].join('\n');
59
+ }
60
+ //# sourceMappingURL=prompts.js.map
@@ -0,0 +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;;;;;;;GAOG;AACH,MAAM,UAAU,wBAAwB,CACtC,SAAiB,EACjB,aAAqB,EACrB,YAA+B;IAE/B,OAAO;QACL,kHAAkH,aAAa,kEAAkE,SAAS,KAAK;QAC/M,0IAA0I;QAC1I,8OAA8O;QAC9O,aAAa,eAAe,iHAAiH;QAC7I,2GAA2G;QAC3G,qBAAqB,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG;QACrD,EAAE;QACF,wCAAwC;QACxC,GAAG,YAAY,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC;KACrC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AACd,CAAC"}
package/lib/tools.d.ts ADDED
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Model-facing tool restrictions for memory subagents.
3
+ *
4
+ * Extraction and dream forks REVIEW broadly but hold no write capability: the
5
+ * memory directory lives outside the session workspace, so model-side writes
6
+ * are fenced by the fs sandbox with no escalation path from a background job.
7
+ * Instead the forks report their file set through the driver-injected
8
+ * `structured_output` tool and the plugin performs the writes host-side (see
9
+ * `writeback.ts`). `structured_output` is allow-listed defensively: the driver
10
+ * installs it AFTER the tool filter is applied, so a name-level filter must
11
+ * not shadow it.
12
+ *
13
+ * `read_image` pairs with `read` to mirror Claude Code's `Read`, which covers
14
+ * both text and images (the harness splits image reading into its own tool).
15
+ * @module @dsh-cc/memory-consolidation/tools
16
+ */
17
+ /** Harness tool names a memory subagent may exercise. */
18
+ export declare const MEMORY_AGENT_TOOLS: readonly string[];
19
+ /** A `toolFilter` value usable as a subagent-start request restriction. */
20
+ export declare const MEMORY_TOOL_FILTER: {
21
+ allow: readonly string[];
22
+ };
23
+ //# sourceMappingURL=tools.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,yDAAyD;AACzD,eAAO,MAAM,kBAAkB,EAAE,SAAS,MAAM,EAM/C,CAAA;AAED,2EAA2E;AAC3E,eAAO,MAAM,kBAAkB,EAAE;IAAE,KAAK,EAAE,SAAS,MAAM,EAAE,CAAA;CAE1D,CAAA"}
package/lib/tools.js ADDED
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Model-facing tool restrictions for memory subagents.
3
+ *
4
+ * Extraction and dream forks REVIEW broadly but hold no write capability: the
5
+ * memory directory lives outside the session workspace, so model-side writes
6
+ * are fenced by the fs sandbox with no escalation path from a background job.
7
+ * Instead the forks report their file set through the driver-injected
8
+ * `structured_output` tool and the plugin performs the writes host-side (see
9
+ * `writeback.ts`). `structured_output` is allow-listed defensively: the driver
10
+ * installs it AFTER the tool filter is applied, so a name-level filter must
11
+ * not shadow it.
12
+ *
13
+ * `read_image` pairs with `read` to mirror Claude Code's `Read`, which covers
14
+ * both text and images (the harness splits image reading into its own tool).
15
+ * @module @dsh-cc/memory-consolidation/tools
16
+ */
17
+ /** Harness tool names a memory subagent may exercise. */
18
+ export const MEMORY_AGENT_TOOLS = [
19
+ 'read',
20
+ 'read_image',
21
+ 'grep',
22
+ 'glob',
23
+ 'structured_output',
24
+ ];
25
+ /** A `toolFilter` value usable as a subagent-start request restriction. */
26
+ export const MEMORY_TOOL_FILTER = {
27
+ allow: MEMORY_AGENT_TOOLS,
28
+ };
29
+ //# sourceMappingURL=tools.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tools.js","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,yDAAyD;AACzD,MAAM,CAAC,MAAM,kBAAkB,GAAsB;IACnD,MAAM;IACN,YAAY;IACZ,MAAM;IACN,MAAM;IACN,mBAAmB;CACpB,CAAA;AAED,2EAA2E;AAC3E,MAAM,CAAC,MAAM,kBAAkB,GAAiC;IAC9D,KAAK,EAAE,kBAAkB;CAC1B,CAAA"}
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "@dsh-cc/memory-consolidation",
3
+ "description": "Background memory consolidation: turn-end extraction and three-gate dream rewrite",
4
+ "version": "0.5.0",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/dsh-cc/dsh-cc.git",
8
+ "directory": "packages/memory/memory-consolidation"
9
+ },
10
+ "type": "module",
11
+ "exports": {
12
+ ".": {
13
+ "types": "./lib/index.d.ts",
14
+ "default": "./lib/index.js"
15
+ },
16
+ "./invariant": {
17
+ "types": "./lib/invariant.d.ts",
18
+ "default": "./lib/invariant.js"
19
+ },
20
+ "./src/*": "./src/*",
21
+ "./package.json": "./package.json"
22
+ },
23
+ "files": [
24
+ "lib"
25
+ ],
26
+ "license": "Apache-2.0",
27
+ "peerDependencies": {
28
+ "@deepseek-ai/dsh-agent": ">=0.1.1-rc.2",
29
+ "@deepseek-ai/dsh-fs": ">=0.1.1-rc.2",
30
+ "@deepseek-ai/dsh-home-paths": ">=0.1.1-rc.2",
31
+ "@deepseek-ai/dsh-invariants": ">=0.1.1-rc.2",
32
+ "@deepseek-ai/dsh-jobs": ">=0.1.1-rc.2",
33
+ "@deepseek-ai/dsh-session": ">=0.1.1-rc.2",
34
+ "@deepseek-ai/dsh-subagent": ">=0.1.1-rc.2",
35
+ "@deepseek-ai/cordis": ">=0.1.1-rc.2",
36
+ "@deepseek-ai/schemastery": "^3.18.1"
37
+ },
38
+ "dependencies": {
39
+ "@dsh-cc/memory": "^0.5.0"
40
+ },
41
+ "devDependencies": {
42
+ "@deepseek-ai/cordis": "link:../../../../deepseek-harness/vendor/cordis",
43
+ "@deepseek-ai/dsh-invariants": "link:../../../../deepseek-harness/packages/runtime-diagnostics/invariants",
44
+ "@deepseek-ai/schemastery": "link:../../../../deepseek-harness/vendor/schemastery",
45
+ "@deepseek-ai/dsh-agent": "link:../../../../deepseek-harness/packages/core/agent",
46
+ "@deepseek-ai/dsh-fs": "link:../../../../deepseek-harness/packages/fs/fs",
47
+ "@deepseek-ai/dsh-home-paths": "link:../../../../deepseek-harness/packages/util/home-paths",
48
+ "@deepseek-ai/dsh-jobs": "link:../../../../deepseek-harness/packages/jobs/jobs",
49
+ "@deepseek-ai/dsh-session": "link:../../../../deepseek-harness/packages/core/session",
50
+ "@deepseek-ai/dsh-subagent": "link:../../../../deepseek-harness/packages/subagent/subagent"
51
+ },
52
+ "publishConfig": {
53
+ "access": "public"
54
+ }
55
+ }