@fonlan/dsh-gitmemo 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 fonlan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,139 @@
1
+ # dsh-gitmemo
2
+
3
+ **English** | [**简体中文**](README.zh.md)
4
+
5
+ **Git-backed long-term memory for DeepSeek Harness (dsh)** — a Cordis plugin mirroring
6
+ [GitMemo](https://github.com/fonlan/gitmemo). The agent stores completed task outcomes as
7
+ markdown entries in a local **`.mem`** Git repository and searches them before starting new
8
+ work. Git is the only dependency, and no manual memory commands are ever needed.
9
+
10
+ ## Key Characteristics
11
+
12
+ - **Extremely simple** — once installed, no manual memory commands in day-to-day tasks
13
+ - **Fully automated** — the agent runs `init`, `search`, `read`, `write`, `delete` as part of its normal task flow
14
+ - **Local-only & offline** — memory lives in a local `.mem` Git repository; no cloud dependency
15
+ - **Git-only** — no runtime dependency beyond the `git` CLI
16
+ - **Token-efficient** — reuses prior conclusions via `mem_search` instead of re-injecting context
17
+ - **Prevents context bloat** — search-first workflow; the skill caps reads at 5 relevant memories
18
+ - **Auditable** — every memory action is a commit in `.mem`'s Git history
19
+ - **Traceable** — each memory can be traced and replayed from commit history
20
+ - **Branch-aligned** — the `.mem` branch follows the project's current branch on writes
21
+
22
+ ## What the Plugin Provides
23
+
24
+ | Piece | Description |
25
+ | --- | --- |
26
+ | `mem_init` | Initialize the `.mem` repository (all other tools auto-initialize) |
27
+ | `mem_search` | Search memories: `keywords` (comma-separated), `skip` (pagination), `mode` (`and` / `or` / `auto` — AND first, OR fallback). Returns up to 20 hits as `hash\|title\|date` |
28
+ | `mem_read` | Read one memory entry by commit hash (full markdown) |
29
+ | `mem_write` | Store a task outcome: `title` + `content` (or `content_file` / `file`), optional `body` / `body_file`. Commits `.mem/entries/<timestamp>-<slug>.md` and aligns the `.mem` branch |
30
+ | `mem_delete` | Delete a memory entry by commit hash (then redo and rewrite) |
31
+ | Always-on rules section | The complete workflow rules (gitmemo's `agents-template.md` equivalent) are injected into **every** session's system prompt — no skill load needed |
32
+ | Session-start injection | On every new **root** agent session, the N most recent memory titles (`hash\|title\|date`) are automatically injected into that session's system prompt, so prior-session context is visible before any tool call; subagents are skipped and the lookup never creates `.mem` |
33
+
34
+ ## Installation
35
+
36
+ Requires dsh ≥ 0.1.0-rc.6 and the `git` CLI.
37
+
38
+ From the npm registry (once published):
39
+
40
+ ```bash
41
+ dsh plugin --profile web add @fonlan/dsh-gitmemo
42
+ ```
43
+
44
+ From a local checkout (development / unpublished):
45
+
46
+ ```bash
47
+ dsh plugin --profile web add /path/to/dsh-gitmemo
48
+ ```
49
+
50
+ Then restart the dsh profile (e.g. restart the `dsh web` process). The plugin registers on the
51
+ host plane, so every agent session in that profile sees the tools and the skill.
52
+
53
+ ### Configuration
54
+
55
+ The bundle patch ships with sensible defaults; override them in the profile's
56
+ `cordis.patch.yml`:
57
+
58
+ ```yaml
59
+ - id: dsh-gitmemo
60
+ config:
61
+ memDirName: .mem # memory repo directory name at the project root
62
+ searchLimit: 20 # max hits per mem_search call
63
+ branchAlign: true # .mem branch follows the project branch on write
64
+ recentContextLimit: 5 # recent memory titles injected into each new session's system prompt (0 disables)
65
+ projectRoot: null # optional explicit project root (defaults to the session cwd)
66
+ ```
67
+
68
+ ## Memory Location
69
+
70
+ The `.mem` repository lives at the **project root** of the calling session's workspace
71
+ (`git rev-parse --show-toplevel`, falling back to the working directory). Entries are
72
+ markdown files under `.mem/entries/`; every operation is a commit, so the whole memory is
73
+ readable with plain `git`:
74
+
75
+ ```bash
76
+ git -C .mem log --oneline
77
+ git -C .mem show <commit-hash>
78
+ ```
79
+
80
+ > Tip: add `.mem/` to your project's `.gitignore` so the memory repository never mixes into project commits.
81
+
82
+ ## Agent Workflow (always-on rules)
83
+
84
+ 1. **Before work — search.** Extract 3-5 keywords from the request → `mem_search`. If more
85
+ than 5 hits are relevant, read only the 5 most likely (`mem_read`). Paginate with `skip`
86
+ 20, 40, … when nothing relevant appears.
87
+ 2. **User unsatisfied — delete and rewrite.** `mem_delete <hash>` → redo from feedback →
88
+ `mem_write` a corrected entry.
89
+ 3. **End-of-session checkpoint — the only write path.** When the conversation is ending, review
90
+ the whole session and `mem_write` every completed repo-related task that still lacks a memory
91
+ and whose outcome is **valuable/reusable** (or was explicitly asked to be remembered). Never
92
+ duplicate an already-written entry; if a stored outcome is outdated, `mem_delete` it first,
93
+ then write the corrected entry. Never write for pure Q&A, incomplete tasks, non-repo work, or
94
+ purely operational git actions. Write all pending memories before closing the conversation.
95
+
96
+ ## Entry Format
97
+
98
+ ```markdown
99
+ ---
100
+ date: 2026-02-19T15:10:10Z
101
+ status: done
102
+ repo_branch: main
103
+ repo_commit: 9f3e1a2
104
+ mem_branch: main
105
+ related_paths: [src/auth/login.ts]
106
+ tags: [auth, security]
107
+ ---
108
+ ### Original User Request
109
+ (verbatim)
110
+ ### AI Understanding
111
+ - Goal: / Constraints: / Out of scope:
112
+ ### Final Outcome
113
+ - Changes/outputs summary
114
+ ```
115
+
116
+ ## Development
117
+
118
+ ```bash
119
+ npm install
120
+ npm run build # tsc → lib/
121
+ npm test # build + engine/plugin unit tests (node:test)
122
+ ```
123
+
124
+ ## Layout
125
+
126
+ ```
127
+ dsh-gitmemo/
128
+ ├── package.json # npm package; dsh.bundle.patch wires the profile layer
129
+ ├── cordis.patch.yml # composition layer: the dsh-gitmemo row
130
+ ├── src/
131
+ │ ├── index.ts # Cordis plugin: mem_* tools + gitmemo skill + prompt section
132
+ │ └── mem.ts # core engine (port of gitmemo scripts/mem.sh)
133
+ ├── lib/ # built output (committed; used by file:/git installs)
134
+ └── test/mem.test.mjs # engine + plugin unit tests
135
+ ```
136
+
137
+ ## License
138
+
139
+ MIT
package/README.zh.md ADDED
@@ -0,0 +1,133 @@
1
+ # dsh-gitmemo
2
+
3
+ [**English**](README.md) | **简体中文**
4
+
5
+ **基于 Git 的 DeepSeek Harness (dsh) 长期记忆插件** —— 一个镜像
6
+ [GitMemo](https://github.com/fonlan/gitmemo) 功能的 Cordis 插件。Agent 会把已完成任务的结论以
7
+ markdown 条目存入项目根目录的本地 **`.mem`** Git 仓库,并在开始新任务前先搜索既往记忆。唯一依赖
8
+ 是 Git,日常使用完全无需手动记忆命令。
9
+
10
+ ## 核心特性
11
+
12
+ - **极其简单** —— 安装后日常任务无需任何手动记忆命令
13
+ - **全自动** —— Agent 在正常任务流程中自动执行 `init` / `search` / `read` / `write` / `delete`
14
+ - **纯本地、可离线** —— 记忆存于本地 `.mem` Git 仓库,无云端依赖
15
+ - **仅依赖 Git** —— 除 `git` CLI 外无任何运行时依赖
16
+ - **省 token** —— 通过 `mem_search` 复用既有结论,而非反复注入上下文
17
+ - **防止上下文膨胀** —— 先搜索后工作的流程,技能规定最多只读 5 条最相关记忆
18
+ - **可审计** —— 每次记忆操作都是 `.mem` Git 历史中的一次提交
19
+ - **可追溯** —— 每条记忆都能从提交历史中回溯与重放
20
+ - **分支对齐** —— 写入时 `.mem` 分支跟随项目当前分支
21
+
22
+ ## 插件提供的内容
23
+
24
+ | 内容 | 说明 |
25
+ | --- | --- |
26
+ | `mem_init` | 初始化 `.mem` 仓库(其余工具都会自动初始化) |
27
+ | `mem_search` | 搜索记忆:`keywords`(逗号分隔)、`skip`(分页)、`mode`(`and` / `or` / `auto`,auto 先 AND 后 OR 兜底)。每次最多返回 20 条 `hash\|title\|date` |
28
+ | `mem_read` | 按提交哈希读取一条记忆的完整 markdown |
29
+ | `mem_write` | 存储任务结论:`title` + `content`(或 `content_file` / `file`),可选 `body` / `body_file`。提交为 `.mem/entries/<时间戳>-<slug>.md` 并对齐 `.mem` 分支 |
30
+ | `mem_delete` | 按提交哈希删除记忆条目(然后重做并重写) |
31
+ | 常驻规则片段 | 完整工作流规则(相当于 gitmemo 的 `agents-template.md`)注入**每个**会话的系统提示词——无需加载技能即可生效 |
32
+ | 会话开始注入 | 每个新**根** Agent 会话开始时,自动把最近 N 条记忆标题(`hash\|title\|date`)注入该系统提示词,跨会话上下文在调用任何工具前即可见;子代理被跳过,且该查询只读、绝不创建 `.mem` |
33
+
34
+ ## 安装
35
+
36
+ 需要 dsh ≥ 0.1.0-rc.6 与 `git` CLI。
37
+
38
+ 从 npm 仓库(发布后):
39
+
40
+ ```bash
41
+ dsh plugin --profile web add @fonlan/dsh-gitmemo
42
+ ```
43
+
44
+ 从本地源码目录(开发/未发布):
45
+
46
+ ```bash
47
+ dsh plugin --profile web add /path/to/dsh-gitmemo
48
+ ```
49
+
50
+ 然后重启对应的 dsh profile(例如重启 `dsh web` 进程)。插件注册在宿主平面,该 profile 下所有
51
+ Agent 会话都能看到这些工具与技能。
52
+
53
+ ### 配置
54
+
55
+ bundle patch 自带合理默认值,可在 profile 的 `cordis.patch.yml` 中覆盖:
56
+
57
+ ```yaml
58
+ - id: dsh-gitmemo
59
+ config:
60
+ memDirName: .mem # 项目根目录下记忆仓库的目录名
61
+ searchLimit: 20 # 每次 mem_search 返回的最大条数
62
+ branchAlign: true # 写入时 .mem 分支跟随项目分支
63
+ recentContextLimit: 5 # 注入每个新会话系统提示词的最近记忆条数(0 表示关闭)
64
+ projectRoot: null # 可选:显式项目根目录(默认取会话工作目录)
65
+ ```
66
+
67
+ ## 记忆存放位置
68
+
69
+ `.mem` 仓库位于调用会话工作区的**项目根目录**(`git rev-parse --show-toplevel`,找不到时退回
70
+ 工作目录)。条目是 `.mem/entries/` 下的 markdown 文件;每次操作都是一次提交,整个记忆可以用
71
+ 普通 `git` 命令查看:
72
+
73
+ ```bash
74
+ git -C .mem log --oneline
75
+ git -C .mem show <commit-hash>
76
+ ```
77
+
78
+ > 提示:建议把 `.mem/` 加入项目的 `.gitignore`,避免记忆仓库混入项目提交。
79
+
80
+ ## Agent 工作流(常驻规则)
81
+
82
+ 1. **开工前 —— 搜索。** 从请求中提取 3-5 个关键词 → `mem_search`。若相关结果超过 5 条,只
83
+ `mem_read` 最可能相关的 5 条。无相关结果时用 `skip` 20、40… 翻页。
84
+ 2. **用户不满意 —— 删除重写。** `mem_delete <hash>` → 按反馈重做 → `mem_write` 更正后的条目。
85
+ 3. **会话结束检查点 —— 唯一的写入路径。** 对话即将结束时,回顾整个会话,用 `mem_write` 写入
86
+ **每一条**已完成、与仓库相关、且结论**有价值/可复用**(或用户明确要求记住)但还没有记忆的任务。
87
+ 绝不重复写已存在的条目;若已存结论已过时,先 `mem_delete` 再写更正条目。纯问答、未完成任务、
88
+ 与仓库无关的工作、纯操作性的 git 动作一律不写。关闭会话前写完所有待写记忆。
89
+
90
+ ## 条目格式
91
+
92
+ ```markdown
93
+ ---
94
+ date: 2026-02-19T15:10:10Z
95
+ status: done
96
+ repo_branch: main
97
+ repo_commit: 9f3e1a2
98
+ mem_branch: main
99
+ related_paths: [src/auth/login.ts]
100
+ tags: [auth, security]
101
+ ---
102
+ ### Original User Request
103
+ (verbatim)
104
+ ### AI Understanding
105
+ - Goal: / Constraints: / Out of scope:
106
+ ### Final Outcome
107
+ - Changes/outputs summary
108
+ ```
109
+
110
+ ## 开发
111
+
112
+ ```bash
113
+ npm install
114
+ npm run build # tsc → lib/
115
+ npm test # 构建 + 引擎/插件单元测试(node:test)
116
+ ```
117
+
118
+ ## 目录结构
119
+
120
+ ```
121
+ dsh-gitmemo/
122
+ ├── package.json # npm 包;dsh.bundle.patch 接入 profile 层
123
+ ├── cordis.patch.yml # 组合层:dsh-gitmemo 行
124
+ ├── src/
125
+ │ ├── index.ts # Cordis 插件:mem_* 工具 + gitmemo 技能 + 提示词片段
126
+ │ └── mem.ts # 核心引擎(gitmemo scripts/mem.sh 的移植)
127
+ ├── lib/ # 构建产物(已提交,供 file:/git 安装使用)
128
+ └── test/mem.test.mjs # 引擎 + 插件单元测试
129
+ ```
130
+
131
+ ## License
132
+
133
+ MIT
@@ -0,0 +1,14 @@
1
+ # dsh-gitmemo — bundle patch layer.
2
+ #
3
+ # Installing this package into a profile (`dsh plugin --profile <name> add @fonlan/dsh-gitmemo`)
4
+ # appends it to `dsh.profile.bundles`; this patch is then applied as that
5
+ # bundle's layer. The row below loads the package's main entry as a host-plane
6
+ # plugin: it registers the `mem_init` / `mem_search` / `mem_read` /
7
+ # `mem_write` / `mem_delete` tools on the shared tool registry, a runtime
8
+ # `gitmemo` skill, and a system-prompt section pointing at the memory workflow.
9
+ - insert:
10
+ - id: dsh-gitmemo
11
+ name: dsh-gitmemo
12
+ config:
13
+ memDirName: .mem
14
+ searchLimit: 20
package/lib/index.d.ts ADDED
@@ -0,0 +1,94 @@
1
+ /**
2
+ * dsh-gitmemo — Git-backed long-term memory for DeepSeek Harness.
3
+ *
4
+ * A Cordis plugin mirroring gitmemo (https://github.com/fonlan/gitmemo):
5
+ * the agent stores completed task outcomes as markdown entries in a local
6
+ * `.mem` git repository and searches them before starting new work.
7
+ *
8
+ * This plugin registers on the host plane:
9
+ * - five model-facing tools: `mem_init`, `mem_search`, `mem_read`,
10
+ * `mem_write`, `mem_delete` (backed by {@link GitMemo});
11
+ * - an always-on system-prompt section with the full memory workflow rules;
12
+ * - a per-session seed of the most recent memory titles.
13
+ *
14
+ * @module dsh-gitmemo
15
+ */
16
+ import z from "@deepseek-ai/schemastery";
17
+ /** Cordis plugin name. */
18
+ declare const name = "dsh-gitmemo";
19
+ /** Host services this plugin needs. */
20
+ declare const inject: string[];
21
+ /** Plugin configuration (all optional). */
22
+ declare const Config: z<Schemastery.ObjectS<{
23
+ /** Name of the memory repo directory at the project root. Default ".mem". */
24
+ memDirName: z<string, string>;
25
+ /** Max search hits per mem_search call. Default 20. */
26
+ searchLimit: z<number, number>;
27
+ /** Align the .mem branch with the project branch on writes. Default true. */
28
+ branchAlign: z<boolean, boolean>;
29
+ /** Number of most recent memory titles injected into each new session's system prompt (0 disables). Default 5. */
30
+ recentContextLimit: z<number, number>;
31
+ /** Optional explicit project root; defaults to the calling session's cwd. */
32
+ projectRoot: z<string, string>;
33
+ }>, Schemastery.ObjectT<{
34
+ /** Name of the memory repo directory at the project root. Default ".mem". */
35
+ memDirName: z<string, string>;
36
+ /** Max search hits per mem_search call. Default 20. */
37
+ searchLimit: z<number, number>;
38
+ /** Align the .mem branch with the project branch on writes. Default true. */
39
+ branchAlign: z<boolean, boolean>;
40
+ /** Number of most recent memory titles injected into each new session's system prompt (0 disables). Default 5. */
41
+ recentContextLimit: z<number, number>;
42
+ /** Optional explicit project root; defaults to the calling session's cwd. */
43
+ projectRoot: z<string, string>;
44
+ }>>;
45
+ interface ResolvedConfig {
46
+ memDirName: string;
47
+ searchLimit: number;
48
+ branchAlign: boolean;
49
+ recentContextLimit: number;
50
+ projectRoot?: string;
51
+ }
52
+ /** Shape of the agent payload received by an `agent/created` listener. */
53
+ interface CreatedAgent {
54
+ id: string;
55
+ session?: {
56
+ header?: {
57
+ cwd?: string;
58
+ delegationDepth?: number;
59
+ };
60
+ };
61
+ ctx: {
62
+ systemPrompt: {
63
+ context(section: {
64
+ name: string;
65
+ order: number;
66
+ text: string;
67
+ }): unknown;
68
+ };
69
+ };
70
+ }
71
+ /**
72
+ * Register the plugin: tools, always-on rules, and session-start seed.
73
+ * @param ctx - registrant context carrying the host tool/prompt services.
74
+ * @param config - plugin configuration (defaults applied by the loader).
75
+ */
76
+ declare function apply(ctx: {
77
+ tools: {
78
+ register(tool: unknown): unknown;
79
+ };
80
+ systemPrompt: {
81
+ section(section: {
82
+ name: string;
83
+ order: number;
84
+ text: string;
85
+ }): unknown;
86
+ };
87
+ on(event: string, handler: (payload: {
88
+ agent: CreatedAgent;
89
+ }) => void): unknown;
90
+ logger: {
91
+ warn(message: string): void;
92
+ };
93
+ }, config?: Partial<ResolvedConfig>): Promise<void>;
94
+ export { Config, apply, inject, name };