@hy-sde-org/dsh-tool-codebase-memory 0.1.2-rc.1
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 +30 -0
- package/README.i18n.yaml +6 -0
- package/README.md +123 -0
- package/README.zh.md +129 -0
- package/cordis.patch.yml +34 -0
- package/dist/cli-check.d.ts +13 -0
- package/dist/cli-check.d.ts.map +1 -0
- package/dist/cli-check.js +28 -0
- package/dist/cli-check.js.map +1 -0
- package/dist/codebase-memory.d.ts +97 -0
- package/dist/codebase-memory.d.ts.map +1 -0
- package/dist/codebase-memory.js +459 -0
- package/dist/codebase-memory.js.map +1 -0
- package/dist/index.d.ts +39 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +33 -0
- package/dist/index.js.map +1 -0
- package/dist/invariant.d.ts +18 -0
- package/dist/invariant.d.ts.map +1 -0
- package/dist/invariant.js +34 -0
- package/dist/invariant.js.map +1 -0
- package/dist/prompt.d.ts +17 -0
- package/dist/prompt.d.ts.map +1 -0
- package/dist/prompt.js +30 -0
- package/dist/prompt.js.map +1 -0
- package/package.json +89 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 hy-sde
|
|
4
|
+
|
|
5
|
+
This package is a standalone port of `@deepseek-ai/dsh-tool-codebase-memory`
|
|
6
|
+
(the model-facing `codebase_*` CLI tools) onto the hy-sde npm scope. The
|
|
7
|
+
ported portions are distributed under the same MIT license with their original
|
|
8
|
+
copyright held by their respective authors:
|
|
9
|
+
|
|
10
|
+
Copyright (c) 2026 DeepSeek
|
|
11
|
+
|
|
12
|
+
See THIRD-PARTY-NOTICES.md at the repository root for full provenance.
|
|
13
|
+
|
|
14
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
15
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
16
|
+
in the Software without restriction, including without limitation the rights
|
|
17
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
18
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
19
|
+
furnished to do so, subject to the following conditions:
|
|
20
|
+
|
|
21
|
+
The above copyright notice and this permission notice shall be included in all
|
|
22
|
+
copies or substantial portions of the Software.
|
|
23
|
+
|
|
24
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
25
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
26
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
27
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
28
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
29
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
30
|
+
SOFTWARE.
|
package/README.i18n.yaml
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
# Bilingual-pair consistency record: the git blob hash of each side as of the
|
|
2
|
+
# last confirmed-consistent state. Both languages carry equal authority; after
|
|
3
|
+
# editing either side, bring the other along and re-record with:
|
|
4
|
+
# git hash-object README.md README.zh.md
|
|
5
|
+
README.md: fd586ae4e33b6d5e1a42812e612c2b7740838e78
|
|
6
|
+
README.zh.md: 4ca5becdfdd3cf709ecfb6f6e728afff1b764dcf
|
package/README.md
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: "Model-facing codebase-memory tools that run one-shot queries against the local codebase-memory daemon, spawning the CLI once per call and sharing the same daemon the stdio MCP client fronts."
|
|
3
|
+
kind: "package-reference"
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# @hy-sde-org/dsh-tool-codebase-memory
|
|
7
|
+
|
|
8
|
+
English | [中文](README.zh.md)
|
|
9
|
+
|
|
10
|
+
## Summary
|
|
11
|
+
|
|
12
|
+
`dsh-tool-codebase-memory` exposes the local codebase-memory daemon as model-facing `codebase_*` tools that run one-shot queries from the terminal. Each call spawns `codebase-memory-mcp cli --json <tool>` once and parses the raw MCP result envelope against the same daemon the MCP server fronts, so indexes, project mutation locks, and the index supervisor are fully shared — warm daemon calls cost ~0.2 s. Choose it over the stdio MCP client row when you want one process per call, tightened schemas, and per-preset configuration instead of a long-lived server inside every session, keeping the MCP row disabled as a zero-maintenance fallback. The main boundary is that the curated schemas are a hand-maintained mirror of the CLI's input schemas, so a codebase-memory release that adds tools needs this package updated.
|
|
13
|
+
|
|
14
|
+
## Table of Contents
|
|
15
|
+
|
|
16
|
+
- [Tool surface](#tool-surface)
|
|
17
|
+
- [Why CLI over MCP](#why-cli-over-mcp)
|
|
18
|
+
- [Configuration](#configuration)
|
|
19
|
+
- [Model Experience](#model-experience)
|
|
20
|
+
- [Known Limitations and Deferred Work](#known-limitations-and-deferred-work)
|
|
21
|
+
- [Dev Note](#dev-note)
|
|
22
|
+
|
|
23
|
+
-----
|
|
24
|
+
|
|
25
|
+
Model-facing [codebase-memory](https://github.com/DeusData/codebase-memory-mcp) tools that run one-shot queries against the local codebase-memory daemon from the terminal. The surface is the local alternative to the stdio MCP client row: instead of holding a long-lived MCP server inside every session, each call spawns `codebase-memory-mcp cli --json <tool>` once and parses the raw MCP result envelope — **the same daemon the MCP server fronts**, so indexes, project mutation locks and the index supervisor are fully shared. Warm daemon calls cost ~0.2 s on this machine (cold spawn ~1.3 s; `codebase-memory-mcp daemon start` keeps one warm).
|
|
26
|
+
|
|
27
|
+
## Tool surface
|
|
28
|
+
|
|
29
|
+
- `codebase_list_projects` — all indexed projects (name, root path, git state); the vocabulary source for `project` everywhere else.
|
|
30
|
+
- `codebase_index_repository [repoPath] [mode=full|moderate|fast|cross-repo-intelligence] [targetProjects] [name] [persistence]` — index a repo once, query it repeatedly.
|
|
31
|
+
- `codebase_index_status [project]` — node/edge counts, freshness, skipped & partially-parsed files, last run's logfile.
|
|
32
|
+
- `codebase_search_graph [query|namePattern|semanticQuery|label|filePattern|limit|offset|...]` — the primary finder: definitions, implementations, relationships; pages with `limit`/`offset` until `has_more` is false.
|
|
33
|
+
- `codebase_query_graph [query] [maxRows]` — raw Cypher over the graph (multi-hop, aggregation, cross-service), including complexity/loop hot-path properties.
|
|
34
|
+
- `codebase_trace_path [functionName] [direction] [depth] [mode=calls|data_flow|cross_service] [...]` — callers/callees, value flow, cross-service hops.
|
|
35
|
+
- `codebase_get_code_snippet [qualifiedName] [includeNeighbors]` — source of one symbol, no file hunting.
|
|
36
|
+
- `codebase_get_graph_schema [project]` — node labels + edge types (Cypher vocabulary).
|
|
37
|
+
- `codebase_get_architecture [path] [aspects]` — packages/services/dependencies + Leiden clusters over the call/import graph.
|
|
38
|
+
- `codebase_search_code [pattern] [mode=compact|full|files] [filePattern|pathFilter|limit]` — grep-augmented, deduped into containing functions, ranked.
|
|
39
|
+
- `codebase_detect_changes [baseBranch|since|depth|scope]` — git diff mapped onto the graph: what a change touches.
|
|
40
|
+
- `codebase_manage_adr [mode=get|update|sections] [content] [sections]` — read/write Architecture Decision Records.
|
|
41
|
+
- `codebase_ingest_traces [traces]` — fold `{caller, callee, count}` runtime traces into the graph.
|
|
42
|
+
- `codebase_delete_project [project]` — destructive; use only for superseded indexes.
|
|
43
|
+
|
|
44
|
+
## Why CLI over MCP
|
|
45
|
+
|
|
46
|
+
The MCP client row (`@deepseek-ai/dsh-mcp-client` with `command: codebase-memory-mcp`) works, but it keeps a long-lived stdio server running inside **every** session and exposes all tools verbatim with the `mcp__codebase__*` prefix. The CLI wrapper spawns per call and exits — nothing to recycle, nothing to crash, nothing warm in the session — with clean `codebase_*` names, tightened schemas, and per-preset configuration. Functionally identical: the `cli` mode executes through the same daemon (`main_local_cli_daemon_execute` → `cbm_daemon_application_client_tool`), which is exactly what made the logseq CLI-first pivot viable. Keep the MCP row around disabled if you want a zero-maintenance fallback.
|
|
47
|
+
|
|
48
|
+
## Configuration
|
|
49
|
+
|
|
50
|
+
```ts
|
|
51
|
+
import { Context } from '@deepseek-ai/cordis'
|
|
52
|
+
import toolCodebaseMemoryPackage from '@hy-sde-org/dsh-tool-codebase-memory'
|
|
53
|
+
|
|
54
|
+
const ctx = new Context()
|
|
55
|
+
ctx.plugin(toolCodebaseMemoryPackage, {
|
|
56
|
+
cliPath: 'codebase-memory-mcp', // CLI executable (default: on PATH)
|
|
57
|
+
project: 'deepseek-harness', // default project for tools that can omit it
|
|
58
|
+
timeoutMs: 60000, // per-call process timeout (index calls use indexTimeoutMs)
|
|
59
|
+
indexTimeoutMs: 600000, // timeout for codebase_index_repository
|
|
60
|
+
maxChars: 200000, // cap on rendered JSON payload before explicit truncation
|
|
61
|
+
})
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Setting `project` makes every call explicit about its graph target while still allowing overrides. The plugin activation invariant fails fast with an install hint when the CLI is missing. Verify at any time with `codebase-memory-mcp cli list_projects`.
|
|
65
|
+
|
|
66
|
+
## Model Experience
|
|
67
|
+
|
|
68
|
+
### Tool schemas
|
|
69
|
+
|
|
70
|
+
#### What the model sees
|
|
71
|
+
|
|
72
|
+
Fourteen hand-authored `codebase_*` schemas (see the [tool surface](#tool-surface)) encode the graph contract so the model prefers graph answers (`codebase_search_graph` / `codebase_trace_path` / `codebase_get_code_snippet`) over repeated grep/read cycles, pages with `limit`/`offset`, and indexes new repos before relying on answers.
|
|
73
|
+
|
|
74
|
+
#### Token effect
|
|
75
|
+
|
|
76
|
+
Fourteen static schemas are added once to the request prefix (~3–5 KB total), far smaller than streaming fifteen MCP schemas with their full paragraphs into every session; results are JSON payloads capped by `maxChars` (default 200000), so a runaway Cypher cannot blow the context.
|
|
77
|
+
|
|
78
|
+
#### KV Cache effect
|
|
79
|
+
|
|
80
|
+
All schemas are static; per-call args vary but never condition the request prefix. Cached prefixes stay valid across calls.
|
|
81
|
+
|
|
82
|
+
### Result values
|
|
83
|
+
|
|
84
|
+
#### What the model sees
|
|
85
|
+
|
|
86
|
+
Structured JSON payloads parsed out of the MCP result envelope (content text is JSON too — the wrapper re-parses it), so the model sees the same objects the MCP tools returned, e.g. `search_graph`'s `{total, results, has_more}` tree rows. Tool errors (`isError: true` in the envelope, exit 0 under `--json`) surface as `CodebaseMemoryCliError` with argv/exit code attached — never as fake success.
|
|
87
|
+
|
|
88
|
+
#### Token effect
|
|
89
|
+
|
|
90
|
+
Payloads are passed through and truncated only past the `maxChars` cap with an explicit marker; the CLI's own `limit`/`offset` paging is the primary cost control.
|
|
91
|
+
|
|
92
|
+
#### KV Cache effect
|
|
93
|
+
|
|
94
|
+
Results are per-call snapshots; no read-back that would change the model's rerun prefix.
|
|
95
|
+
|
|
96
|
+
### Prompt section
|
|
97
|
+
|
|
98
|
+
#### What the model sees
|
|
99
|
+
|
|
100
|
+
One `codebase:tools` card: index before asking, prefer graph answers over repeated greps, page with `limit`/`offset`, Cypher for what the curated tools cannot express, `codebase_delete_project` is destructive.
|
|
101
|
+
|
|
102
|
+
#### Token effect
|
|
103
|
+
|
|
104
|
+
Six short lines added once to the request prefix; negligible per turn.
|
|
105
|
+
|
|
106
|
+
#### KV Cache effect
|
|
107
|
+
|
|
108
|
+
Static section text — no invalidation.
|
|
109
|
+
|
|
110
|
+
## Known Limitations and Deferred Work
|
|
111
|
+
|
|
112
|
+
- The curated schemas are a hand-maintained mirror of the CLI's input schemas; a codebase-memory release that adds tools needs this package updated (the harness's MCP row auto-follows — a good reason to keep it as a disabled fallback).
|
|
113
|
+
- `check_index_coverage` is declared by the binary's tool table but not dispatchable through `cli` ("unknown tool"), so it is intentionally not wrapped.
|
|
114
|
+
- No host-plane service or GUI surface: the binary already ships a graph visualizer at `localhost:9749`; an in-GUI drawer (like the logseq wiki pane) is future work.
|
|
115
|
+
|
|
116
|
+
### Dev Note
|
|
117
|
+
|
|
118
|
+
<details>
|
|
119
|
+
<summary>Working context for maintainers — click to expand</summary>
|
|
120
|
+
|
|
121
|
+
None.
|
|
122
|
+
|
|
123
|
+
</details>
|
package/README.zh.md
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: "面向模型的 codebase-memory 工具:经 CLI 对本地 codebase-memory daemon 发起一次性查询,与 stdio MCP 客户端共享同一 daemon。"
|
|
3
|
+
kind: "package-reference"
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# @hy-sde-org/dsh-tool-codebase-memory
|
|
7
|
+
|
|
8
|
+
[English](README.md) | 中文
|
|
9
|
+
|
|
10
|
+
## 概述
|
|
11
|
+
|
|
12
|
+
`dsh-tool-codebase-memory` 把本地 codebase-memory daemon 暴露为模型侧的 `codebase_*` 工具,从终端发起一次性查询。每次调用派发一次 `codebase-memory-mcp cli --json <tool>` 并解析原始 MCP 结果信封,与 MCP server 前端的是同一个 daemon,因此索引、项目变更锁与索引 supervisor 完全共享——热 daemon 调用约 0.2 秒。与 stdio MCP 客户端行相比,选择它可获得每次调用一个进程、schema 精简、可按 preset 配置,而不是每个会话常驻一个长寿命 server;可把 MCP 行禁用挂起作为零维护备选。主要边界是精选 schema 是 CLI 输入 schema 的手工维护镜像,codebase-memory 发布新增工具时本包需要更新。
|
|
13
|
+
|
|
14
|
+
## 目录
|
|
15
|
+
|
|
16
|
+
- [工具面](#tool-surface)
|
|
17
|
+
- [为什么用 CLI 而不是 MCP](#why-cli-over-mcp)
|
|
18
|
+
- [配置](#configuration)
|
|
19
|
+
- [模型体验](#model-experience)
|
|
20
|
+
- [已知限制与待办工作](#known-limitations-and-deferred-work)
|
|
21
|
+
- [开发备注](#dev-note)
|
|
22
|
+
|
|
23
|
+
-----
|
|
24
|
+
|
|
25
|
+
基于 [codebase-memory](https://github.com/DeusData/codebase-memory-mcp) 的模型侧工具:从终端对本地 codebase-memory daemon 发起一次性查询。该工具面是 stdio MCP 客户端行(`@deepseek-ai/dsh-mcp-client` 配 `command: codebase-memory-mcp`)的本地替代方案——不在每个会话里常驻一个 MCP server,而是每次调用派发一次 `codebase-memory-mcp cli --json <tool>` 并解析原始 MCP 结果信封——**与 MCP server 前端的是同一个 daemon**,因此索引、项目变更锁与索引 supervisor 完全共享。本机实测热 daemon 调用约 0.2 秒(冷启动约 1.3 秒;`codebase-memory-mcp daemon start` 可保持常暖)。
|
|
26
|
+
|
|
27
|
+
<a id="tool-surface"></a>
|
|
28
|
+
## 工具面
|
|
29
|
+
|
|
30
|
+
- `codebase_list_projects` —— 列出全部已索引项目(名称、根路径、git 状态);是其他地方 `project` 词汇的来源。
|
|
31
|
+
- `codebase_index_repository [repoPath] [mode=full|moderate|fast|cross-repo-intelligence] [targetProjects] [name] [persistence]` —— 索引一次、反复查询。
|
|
32
|
+
- `codebase_index_status [project]` —— 节点/边数量、新鲜度、跳过与部分解析的文件、上次运行的日志文件。
|
|
33
|
+
- `codebase_search_graph [query|namePattern|semanticQuery|label|filePattern|limit|offset|...]` —— 主要查找器:定义、实现、关系;用 `limit`/`offset` 翻页直到 `has_more` 为假。
|
|
34
|
+
- `codebase_query_graph [query] [maxRows]` —— 对图执行原始 Cypher(多跳、聚合、跨服务),含复杂度/循环热点属性。
|
|
35
|
+
- `codebase_trace_path [functionName] [direction] [depth] [mode=calls|data_flow|cross_service] [...]` —— 调用者/被调者、值流、跨服务跳转。
|
|
36
|
+
- `codebase_get_code_snippet [qualifiedName] [includeNeighbors]` —— 单个符号的源码,无需翻文件。
|
|
37
|
+
- `codebase_get_graph_schema [project]` —— 节点标签 + 边类型(Cypher 词汇表)。
|
|
38
|
+
- `codebase_get_architecture [path] [aspects]` —— 包/服务/依赖 + 对调用/导入图做 Leiden 社区检测得到的 de-facto 模块。
|
|
39
|
+
- `codebase_search_code [pattern] [mode=compact|full|files] [filePattern|pathFilter|limit]` —— grep 增强、去重进包含函数并按结构重要性排序。
|
|
40
|
+
- `codebase_detect_changes [baseBranch|since|depth|scope]` —— 把 git diff 映射到图上:一次改动会波及什么。
|
|
41
|
+
- `codebase_manage_adr [mode=get|update|sections] [content] [sections]` —— 读写架构决策记录(ADR)。
|
|
42
|
+
- `codebase_ingest_traces [traces]` —— 把 `{caller, callee, count}` 运行时 trace 折入图。
|
|
43
|
+
- `codebase_delete_project [project]` —— 破坏性操作;仅用于清理被取代的索引。
|
|
44
|
+
|
|
45
|
+
<a id="why-cli-over-mcp"></a>
|
|
46
|
+
## 为什么用 CLI 而不是 MCP
|
|
47
|
+
|
|
48
|
+
MCP 客户端行(`@deepseek-ai/dsh-mcp-client` 配 `command: codebase-memory-mcp`)能工作,但会在**每个**会话里常驻一个 stdio server,且把所有工具原样暴露为 `mcp__codebase__*` 前缀。CLI 包装每次调用派发一次、随即退出——无需回收、不会崩、会话内无常驻进程——且工具名干净(`codebase_*`)、schema 精简、可按 preset 配置。功能上完全一致:`cli` 模式经由同一个 daemon 执行(`main_local_cli_daemon_execute` → `cbm_daemon_application_client_tool`),这正是当初 logseq 转向 CLI-first 得以成立的原因。若想保留零维护的备选,可把 MCP 行禁用挂起。
|
|
49
|
+
|
|
50
|
+
<a id="configuration"></a>
|
|
51
|
+
## 配置
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
import { Context } from '@deepseek-ai/cordis'
|
|
55
|
+
import toolCodebaseMemoryPackage from '@hy-sde-org/dsh-tool-codebase-memory'
|
|
56
|
+
|
|
57
|
+
const ctx = new Context()
|
|
58
|
+
ctx.plugin(toolCodebaseMemoryPackage, {
|
|
59
|
+
cliPath: 'codebase-memory-mcp', // CLI executable (default: on PATH)
|
|
60
|
+
project: 'deepseek-harness', // default project for tools that can omit it
|
|
61
|
+
timeoutMs: 60000, // per-call process timeout (index calls use indexTimeoutMs)
|
|
62
|
+
indexTimeoutMs: 600000, // timeout for codebase_index_repository
|
|
63
|
+
maxChars: 200000, // cap on rendered JSON payload before explicit truncation
|
|
64
|
+
})
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
设置 `project` 会让每次调用显式指向目标图,同时仍允许按调用覆盖。插件激活不变量在 CLI 缺失时快速失败并给出安装提示。可随时用 `codebase-memory-mcp cli list_projects` 验证。
|
|
68
|
+
|
|
69
|
+
<a id="model-experience"></a>
|
|
70
|
+
## 模型体验
|
|
71
|
+
|
|
72
|
+
### 工具 schema
|
|
73
|
+
|
|
74
|
+
#### 模型看到什么
|
|
75
|
+
|
|
76
|
+
十四个手写 `codebase_*` schema(见[工具面](#tool-surface))把图契约编码进去:模型优先用图答案(`codebase_search_graph` / `codebase_trace_path` / `codebase_get_code_snippet`)而非反复 grep/read,用 `limit`/`offset` 翻页,并在依赖答案前先索引新仓库。
|
|
77
|
+
|
|
78
|
+
#### Token 影响
|
|
79
|
+
|
|
80
|
+
十四个静态 schema 只加入请求前缀一次(合计约 3–5 KB),远小于把十五个 MCP schema 连同整段说明流进每个会话;结果以 JSON 载荷返回并受 `maxChars`(默认 200000)限制,失控的 Cypher 不会撑爆上下文。
|
|
81
|
+
|
|
82
|
+
#### KV 缓存影响
|
|
83
|
+
|
|
84
|
+
全部 schema 为静态;每次调用的参数不同但不会改变请求前缀。此前缀跨调用保持有效。
|
|
85
|
+
|
|
86
|
+
### 结果值
|
|
87
|
+
|
|
88
|
+
#### 模型看到什么
|
|
89
|
+
|
|
90
|
+
从 MCP 结果信封解析出的结构化 JSON 载荷(信封正文本身就是 JSON——包装器会二次解析),模型看到与 MCP 工具相同的对象,例如 `search_graph` 的 `{total, results, has_more}` 树行。工具错误(信封内 `isError: true`,`--json` 下进程退出码为 0)以带 argv/退出码的 `CodebaseMemoryCliError` 浮出——绝不会伪装成成功。
|
|
91
|
+
|
|
92
|
+
#### Token 影响
|
|
93
|
+
|
|
94
|
+
载荷原样透传,仅在超过 `maxChars` 上限时截断并带显式标记;CLI 自身的 `limit`/`offset` 分页是主要成本控制。
|
|
95
|
+
|
|
96
|
+
#### KV 缓存影响
|
|
97
|
+
|
|
98
|
+
结果为每次调用的快照,无读取回写改变模型的重复运行前缀。
|
|
99
|
+
|
|
100
|
+
### 提示段
|
|
101
|
+
|
|
102
|
+
#### 模型看到什么
|
|
103
|
+
|
|
104
|
+
一张 `codebase:tools` 卡片:先索引再提问、图答案优先于反复 grep、用 `limit`/`offset` 翻页、曲线工具表达不了的用 Cypher、`codebase_delete_project` 具破坏性。
|
|
105
|
+
|
|
106
|
+
#### Token 影响
|
|
107
|
+
|
|
108
|
+
六行短文本只加入请求前缀一次;每轮成本可忽略。
|
|
109
|
+
|
|
110
|
+
#### KV 缓存影响
|
|
111
|
+
|
|
112
|
+
静态段落文本——无失效。
|
|
113
|
+
|
|
114
|
+
<a id="known-limitations-and-deferred-work"></a>
|
|
115
|
+
## 已知限制与待办工作
|
|
116
|
+
|
|
117
|
+
- 精选 schema 是 CLI 输入 schema 的手工维护镜像;codebase-memory 发布新增工具时本包需要更新(harness 的 MCP 行会自动跟随——这也是保留其作为禁用备选的好理由)。
|
|
118
|
+
- `check_index_coverage` 虽在二进制的工具表中声明,但无法通过 `cli` 派发("unknown tool"),因此有意不包装它。
|
|
119
|
+
- 无主机面服务或 GUI 面:二进制自带 `localhost:9749` 图谱可视化;类 logseq wiki 面板的画中抽屉属未来工作。
|
|
120
|
+
|
|
121
|
+
<a id="dev-note"></a>
|
|
122
|
+
### 开发备注
|
|
123
|
+
|
|
124
|
+
<details>
|
|
125
|
+
<summary>维护者工作上下文 — 点击展开</summary>
|
|
126
|
+
|
|
127
|
+
无。
|
|
128
|
+
|
|
129
|
+
</details>
|
package/cordis.patch.yml
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# @hy-sde-org/dsh-tool-codebase-memory — a self-contained model-facing
|
|
2
|
+
# codebase-memory CLI tool surface.
|
|
3
|
+
#
|
|
4
|
+
# The plugin mounts as ONE plain agent-plane row, exactly like the official
|
|
5
|
+
# harness's own `tool-codebase-memory` row in the stock base bundle. It
|
|
6
|
+
# consumes the deployment's host services — `tools` and `systemPrompt` (stock
|
|
7
|
+
# base provides both via the agent bundle) — so it needs no service or
|
|
8
|
+
# filesystem realm of its own: each call spawns `codebase-memory-mcp cli
|
|
9
|
+
# --json <tool>` once against the same local daemon the stdio MCP client
|
|
10
|
+
# fronts, so indexes, mutation locks and index supervisors are shared.
|
|
11
|
+
#
|
|
12
|
+
# The row id carries the `hy-sde-` prefix to avoid clashing with any shipped
|
|
13
|
+
# row of the same name (a duplicate loader id fails the boot); if the
|
|
14
|
+
# deployment already mounts a `tool-codebase-memory` row of its own, disable
|
|
15
|
+
# this one or drop the insert and keep the stock row.
|
|
16
|
+
#
|
|
17
|
+
# Override per deployment (e.g. point at a non-PATH CLI binary) by patching
|
|
18
|
+
# the row by id:
|
|
19
|
+
#
|
|
20
|
+
# - id: hy-sde-cbm-tool-codebase-memory
|
|
21
|
+
# config:
|
|
22
|
+
# cliPath: /opt/codebase-memory-mcp/bin/codebase-memory-mcp
|
|
23
|
+
# project: my-monorepo
|
|
24
|
+
#
|
|
25
|
+
# The `codebase:tools` prompt section is registered by the same plugin, so no
|
|
26
|
+
# separate prompt row is needed.
|
|
27
|
+
- insert:
|
|
28
|
+
- id: hy-sde-cbm-tool-codebase-memory
|
|
29
|
+
name: '@hy-sde-org/dsh-tool-codebase-memory'
|
|
30
|
+
config:
|
|
31
|
+
cliPath: codebase-memory-mcp
|
|
32
|
+
timeoutMs: 60000
|
|
33
|
+
indexTimeoutMs: 600000
|
|
34
|
+
maxChars: 200000
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Standalone CLI availability probe for `@hy-sde-org/dsh-tool-codebase-memory`.
|
|
3
|
+
* Spawns `<cli> --version` once with an 8s budget.
|
|
4
|
+
* @module @hy-sde-org/dsh-tool-codebase-memory/cli-check
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Verify the `codebase-memory-mcp` CLI resolves and runs.
|
|
8
|
+
* @param cliPath - CLI executable to verify (default `codebase-memory-mcp` on PATH).
|
|
9
|
+
* @returns a promise settling once the probe succeeds.
|
|
10
|
+
* @throws a descriptive error with an install hint when the probe fails.
|
|
11
|
+
*/
|
|
12
|
+
export declare function checkCodebaseMemoryCli(cliPath?: string): Promise<void>;
|
|
13
|
+
//# sourceMappingURL=cli-check.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli-check.d.ts","sourceRoot":"","sources":["../src/cli-check.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,GAAE,MAA8B,GAAG,OAAO,CAAC,IAAI,CAAC,CAc7F"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Standalone CLI availability probe for `@hy-sde-org/dsh-tool-codebase-memory`.
|
|
3
|
+
* Spawns `<cli> --version` once with an 8s budget.
|
|
4
|
+
* @module @hy-sde-org/dsh-tool-codebase-memory/cli-check
|
|
5
|
+
*/
|
|
6
|
+
import { execFile } from 'node:child_process';
|
|
7
|
+
/**
|
|
8
|
+
* Verify the `codebase-memory-mcp` CLI resolves and runs.
|
|
9
|
+
* @param cliPath - CLI executable to verify (default `codebase-memory-mcp` on PATH).
|
|
10
|
+
* @returns a promise settling once the probe succeeds.
|
|
11
|
+
* @throws a descriptive error with an install hint when the probe fails.
|
|
12
|
+
*/
|
|
13
|
+
export function checkCodebaseMemoryCli(cliPath = 'codebase-memory-mcp') {
|
|
14
|
+
return new Promise((resolve, reject) => {
|
|
15
|
+
execFile(cliPath, ['--version'], { timeout: 8000, windowsHide: true }, (err, _stdout, stderr) => {
|
|
16
|
+
if (!err) {
|
|
17
|
+
resolve();
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const code = typeof err.code === 'number';
|
|
21
|
+
const hint = code
|
|
22
|
+
? `the \`${cliPath}\` CLI exited with code ${err.code}: ${(stderr || '').trim().slice(0, 200)}`
|
|
23
|
+
: `\`${cliPath}\` was not found on PATH`;
|
|
24
|
+
reject(new Error(`tool-codebase-memory: ${hint}. Install the codebase-memory CLI from the codebase-memory-mcp releases (https://github.com/DeusData/codebase-memory-mcp/releases): tar xzf then ./install.sh, or set config.cliPath.`));
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=cli-check.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli-check.js","sourceRoot":"","sources":["../src/cli-check.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAE7C;;;;;GAKG;AACH,MAAM,UAAU,sBAAsB,CAAC,UAAkB,qBAAqB;IAC5E,OAAO,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC3C,QAAQ,CAAC,OAAO,EAAE,CAAC,WAAW,CAAC,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE;YAC9F,IAAI,CAAC,GAAG,EAAE,CAAC;gBACT,OAAO,EAAE,CAAA;gBACT,OAAM;YACR,CAAC;YACD,MAAM,IAAI,GAAG,OAAQ,GAA0B,CAAC,IAAI,KAAK,QAAQ,CAAA;YACjE,MAAM,IAAI,GAAG,IAAI;gBACf,CAAC,CAAC,SAAS,OAAO,2BAA4B,GAAwB,CAAC,IAAI,KAAK,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE;gBACrH,CAAC,CAAC,KAAK,OAAO,0BAA0B,CAAA;YAC1C,MAAM,CAAC,IAAI,KAAK,CAAC,yBAAyB,IAAI,uLAAuL,CAAC,CAAC,CAAA;QACzO,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model-facing codebase-memory CLI tools over the `codebase-memory-mcp cli`
|
|
3
|
+
* one-shot mode: `codebase_list_projects`, `codebase_index_repository`,
|
|
4
|
+
* `codebase_index_status`, `codebase_search_graph`, `codebase_query_graph`,
|
|
5
|
+
* `codebase_trace_path`, `codebase_get_code_snippet`,
|
|
6
|
+
* `codebase_get_graph_schema`, `codebase_get_architecture`,
|
|
7
|
+
* `codebase_search_code`, `codebase_detect_changes`, `codebase_manage_adr`,
|
|
8
|
+
* `codebase_ingest_traces`, `codebase_delete_project`.
|
|
9
|
+
*
|
|
10
|
+
* Each call spawns `codebase-memory-mcp cli --json <tool>` once with a temp
|
|
11
|
+
* `--args-file` and parses the raw MCP result envelope — the same daemon the
|
|
12
|
+
* stdio MCP server fronts, so indexes, mutation locks and index supervisors
|
|
13
|
+
* are shared. Long-lived process: none; the daemon stays warm across calls.
|
|
14
|
+
* @module @hy-sde-org/dsh-tool-codebase-memory/codebase-memory
|
|
15
|
+
*/
|
|
16
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
17
|
+
/** Tool-level configuration (all optional; defaults apply). */
|
|
18
|
+
export interface CodebaseMemoryToolConfig {
|
|
19
|
+
/** CLI executable (default `codebase-memory-mcp` on PATH). */
|
|
20
|
+
cliPath?: string;
|
|
21
|
+
/** Default project name applied when a tool call omits `project`. */
|
|
22
|
+
project?: string;
|
|
23
|
+
/** Per-call process timeout in ms (default 60000). */
|
|
24
|
+
timeoutMs?: number;
|
|
25
|
+
/** Timeout for `codebase_index_repository` in ms (default 600000). */
|
|
26
|
+
indexTimeoutMs?: number;
|
|
27
|
+
/** Cap on rendered JSON payload chars before truncation (default 200000). */
|
|
28
|
+
maxChars?: number;
|
|
29
|
+
}
|
|
30
|
+
/** Raised when the CLI exits non-zero, the envelope reports isError, or the output is unreadable. */
|
|
31
|
+
export declare class CodebaseMemoryCliError extends Error {
|
|
32
|
+
/** CLI invocation that failed. */
|
|
33
|
+
readonly args: string[];
|
|
34
|
+
/** Captured stdout (may hold a partial MCP envelope). */
|
|
35
|
+
readonly stdout: string;
|
|
36
|
+
/** Captured stderr (mem.init/progress noise plus human errors). */
|
|
37
|
+
readonly stderr: string;
|
|
38
|
+
/** Process exit code, or null when no process ran (e.g. ENOENT). */
|
|
39
|
+
readonly exitCode: number | null;
|
|
40
|
+
/** Parsed error payload from the envelope, when available. */
|
|
41
|
+
readonly payload?: unknown;
|
|
42
|
+
constructor(message: string, args: string[], stdout: string, stderr: string, exitCode: number | null, payload?: unknown);
|
|
43
|
+
}
|
|
44
|
+
interface RunResult {
|
|
45
|
+
stdout: string;
|
|
46
|
+
stderr: string;
|
|
47
|
+
exitCode: number | null;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Run the CLI once; stdout/stderr/exit-code are returned as-is.
|
|
51
|
+
* @param cmd - CLI executable path.
|
|
52
|
+
* @param args - full argv (including `cli --json <tool>` and, when args exist, `--args-file`).
|
|
53
|
+
* @param options - run options (per-call timeout).
|
|
54
|
+
* @returns the captured stdout/stderr and exit code.
|
|
55
|
+
* @throws {@link CodebaseMemoryCliError} when the process fails or times out.
|
|
56
|
+
*/
|
|
57
|
+
export declare function runCli(cmd: string, args: string[], options: {
|
|
58
|
+
timeoutMs: number;
|
|
59
|
+
}): Promise<RunResult>;
|
|
60
|
+
interface Envelope {
|
|
61
|
+
/** The MCP envelope's text payload, re-parsed into a value. */
|
|
62
|
+
payload: unknown;
|
|
63
|
+
/** The envelope's text, verbatim (double-encoded JSON for structured tools). */
|
|
64
|
+
text: string;
|
|
65
|
+
/** Raw stdout captured from the CLI. */
|
|
66
|
+
stdout: string;
|
|
67
|
+
stderr: string;
|
|
68
|
+
exitCode: number | null;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Parse the raw MCP result envelope printed by `cli --json <tool>`.
|
|
72
|
+
*
|
|
73
|
+
* Under `--json` the CLI always exits 0 and reports tool errors inside the
|
|
74
|
+
* envelope (`{"content":[{"type":"text","text":...}],"isError":true}`), so the
|
|
75
|
+
* envelope — not the process exit code — is the source of truth.
|
|
76
|
+
* @param run - captured run output.
|
|
77
|
+
* @returns the parsed envelope.
|
|
78
|
+
* @throws {@link CodebaseMemoryCliError} when the envelope reports `isError`.
|
|
79
|
+
*/
|
|
80
|
+
export declare function parseEnvelope(run: RunResult): Envelope;
|
|
81
|
+
/**
|
|
82
|
+
* Render a JSON payload into the tool result text, truncating when it exceeds
|
|
83
|
+
* the cap so oversized graph payloads cannot blow the session context.
|
|
84
|
+
* @param payload - parsed envelope payload.
|
|
85
|
+
* @param maxChars - truncation cap.
|
|
86
|
+
* @returns the rendered text.
|
|
87
|
+
*/
|
|
88
|
+
export declare function renderPayload(payload: unknown, maxChars: number): string;
|
|
89
|
+
/**
|
|
90
|
+
* Register all fourteen codebase-memory tools (the prompt section is added by
|
|
91
|
+
* the index plugin; this stays separable for tests).
|
|
92
|
+
* @param ctx - Cordis context carrying `tools` and `systemPrompt`.
|
|
93
|
+
* @param config - tool-level configuration (CLI path/project/timeouts/caps).
|
|
94
|
+
*/
|
|
95
|
+
export declare function applyCodebaseMemoryTools(ctx: Context, config?: CodebaseMemoryToolConfig): void;
|
|
96
|
+
export {};
|
|
97
|
+
//# sourceMappingURL=codebase-memory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codebase-memory.d.ts","sourceRoot":"","sources":["../src/codebase-memory.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAOH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAqBlD,+DAA+D;AAC/D,MAAM,WAAW,wBAAwB;IACvC,8DAA8D;IAC9D,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,qEAAqE;IACrE,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,sDAAsD;IACtD,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,sEAAsE;IACtE,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,6EAA6E;IAC7E,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AAED,qGAAqG;AACrG,qBAAa,sBAAuB,SAAQ,KAAK;IAC/C,kCAAkC;IAClC,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,CAAA;IACvB,yDAAyD;IACzD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,mEAAmE;IACnE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,oEAAoE;IACpE,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;IAChC,8DAA8D;IAC9D,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAA;gBAEd,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,EAAE,OAAO,CAAC,EAAE,OAAO;CASxH;AAED,UAAU,SAAS;IACjB,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;CACxB;AAED;;;;;;;GAOG;AACH,wBAAsB,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,SAAS,CAAC,CAyB5G;AAED,UAAU,QAAQ;IAChB,+DAA+D;IAC/D,OAAO,EAAE,OAAO,CAAA;IAChB,gFAAgF;IAChF,IAAI,EAAE,MAAM,CAAA;IACZ,wCAAwC;IACxC,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;CACxB;AAWD;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,SAAS,GAAG,QAAQ,CAgCtD;AAWD;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAIxE;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,GAAE,wBAA6B,GAAG,IAAI,CA4TlG"}
|