@jacklika/dsh-tool-memory-graph 0.1.0-alpha.2 → 0.1.0-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -51,7 +51,7 @@ It resolves the same vault root per call as `tool-memory-filesystem`: an explici
51
51
  <a id="understand-the-implementation"></a>
52
52
  ## Understand the implementation
53
53
 
54
- The package is a single Cordis function plugin that registers `wiki_graph` on `ctx.tools`. Per call it resolves the vault root through the shared `resolveMemoryVaultRoot` helper, lists notes through the shared `listNotePaths` walker, and extracts `[[link]]` targets through `extractLinks`/`resolveLinkTarget`. A breadth-first walk selects the node set first; edges are then collected from every selected node so boundary-node outgoing edges are not dropped. Output is `{ nodes: [{ id, title, backlinks }], edges: [{ from, to }] }`.
54
+ The package is a single Cordis function plugin that registers `wiki_graph` on `ctx.tools`. Per call it resolves the vault root through the shared `resolveMemoryVaultRoot` helper, lists notes through the shared `listNotePaths` walker, and extracts `[[link]]` targets through `extractLinks`/`resolveLinkTarget`. Targets resolve with the same Obsidian-style tiers as `wiki_read` — exact vault-relative path, then path suffix, then basename anywhere in the vault, with deterministic ambiguity handling. A breadth-first walk selects the node set first; edges are then collected from every selected node so boundary-node outgoing edges are not dropped. Output is `{ nodes: [{ id, title, backlinks }], edges: [{ from, to }] }`.
55
55
 
56
56
  -----
57
57
 
@@ -62,7 +62,7 @@ The package is a single Cordis function plugin that registers `wiki_graph` on `c
62
62
 
63
63
  #### What the model sees
64
64
 
65
- The model sees the generated `wiki_graph` schema in the [tool catalog](../../../docs/tool-catalog.md#deepseek-aidsh-tool-memory-graph). The description states that the graph is read-only and derived from `[[link]]` references.
65
+ The model sees the generated `wiki_graph` schema. The description states that the graph is read-only and derived from `[[link]]` references.
66
66
 
67
67
  ##### Verbatim description for `wiki_graph`
68
68
 
package/README.zh.md CHANGED
@@ -51,7 +51,7 @@ kind: "package-reference"
51
51
  <a id="understand-the-implementation"></a>
52
52
  ## 实现说明
53
53
 
54
- 本包是单个 Cordis 函数插件,在 `ctx.tools` 上注册 `wiki_graph`。每次调用通过共享的 `resolveMemoryVaultRoot` 解析仓库根,用 `listNotePaths` 遍历笔记,用 `extractLinks`/`resolveLinkTarget` 提取 `[[link]]` 目标。先用广度优先遍历确定节点集合,再从所有已选节点收集边,因此边界节点的出边不会丢失。输出为 `{ nodes: [{ id, title, backlinks }], edges: [{ from, to }] }`。
54
+ 本包是单个 Cordis 函数插件,在 `ctx.tools` 上注册 `wiki_graph`。每次调用通过共享的 `resolveMemoryVaultRoot` 解析仓库根,用 `listNotePaths` 遍历笔记,用 `extractLinks`/`resolveLinkTarget` 提取 `[[link]]` 目标。目标按与 `wiki_read` 相同的 Obsidian 语义解析——先精确仓库相对路径,再路径后缀,最后全仓库 basename 匹配,多重命中按确定性规则选择。先用广度优先遍历确定节点集合,再从所有已选节点收集边,因此边界节点的出边不会丢失。输出为 `{ nodes: [{ id, title, backlinks }], edges: [{ from, to }] }`。
55
55
 
56
56
  -----
57
57
 
@@ -62,7 +62,7 @@ kind: "package-reference"
62
62
 
63
63
  #### 模型可见内容
64
64
 
65
- 模型在[工具目录](../../../docs/tool-catalog.zh.md#deepseek-aidsh-tool-memory-graph)中看到生成的 `wiki_graph` schema。描述声明该图是只读的,由 `[[link]]` 引用推导。
65
+ 模型看到生成的 `wiki_graph` schema。描述声明该图是只读的,由 `[[link]]` 引用推导。
66
66
 
67
67
  ##### `wiki_graph` 的原文描述
68
68
 
package/lib/index.js CHANGED
@@ -8,7 +8,7 @@
8
8
  import { readFile } from 'node:fs/promises';
9
9
  import z from '@deepseek-ai/schemastery';
10
10
  import { defineTool } from '@deepseek-ai/dsh-tools';
11
- import { containedPathReal, extractLinks, listNotePaths, resolveLinkTarget, resolveMemoryVaultRoot, splitFrontmatter, vaultRelativeId, } from '@jacklika/dsh-tool-memory-filesystem';
11
+ import { containedPathReal, createLinkResolver, extractLinks, listNotePaths, resolveLinkTarget, resolveMemoryVaultRoot, splitFrontmatter, vaultRelativeId, } from '@jacklika/dsh-tool-memory-filesystem';
12
12
  /** Cordis plugin name used by loader diagnostics. */
13
13
  export const name = 'tool-memory-graph';
14
14
  /** Services required by the wiki graph tool. */
@@ -42,6 +42,7 @@ async function noteTitle(absolutePath, id) {
42
42
  async function buildGraph(root, resolved) {
43
43
  const paths = await listNotePaths(root, resolved.extensions, resolved.indexHiddenDirs);
44
44
  const entries = paths.map(path => [vaultRelativeId(root, path), path]);
45
+ const linkResolver = createLinkResolver(entries.map(([id]) => id));
45
46
  const truncated = entries.length > resolved.maxNodes;
46
47
  const capped = entries.slice(0, resolved.maxNodes);
47
48
  const nodes = [];
@@ -52,7 +53,7 @@ async function buildGraph(root, resolved) {
52
53
  for (const [id, path] of capped) {
53
54
  const text = await readFile(path, 'utf8');
54
55
  for (const link of extractLinks(text)) {
55
- const targetPath = await resolveLinkTarget(root, resolved.extensions, link);
56
+ const targetPath = await resolveLinkTarget(root, resolved.extensions, link, linkResolver);
56
57
  if (targetPath === undefined)
57
58
  continue;
58
59
  const targetId = vaultRelativeId(root, targetPath);
@@ -73,6 +74,8 @@ async function buildGraph(root, resolved) {
73
74
  */
74
75
  async function buildSubgraph(root, resolved, startId, depth) {
75
76
  const startPath = await containedPathReal(root, startId);
77
+ const linkResolver = createLinkResolver((await listNotePaths(root, resolved.extensions, resolved.indexHiddenDirs))
78
+ .map(path => vaultRelativeId(root, path)));
76
79
  const visited = new Map([[vaultRelativeId(root, startPath), startPath]]);
77
80
  let frontier = [startPath];
78
81
  for (let level = 0; level < depth && frontier.length > 0; level += 1) {
@@ -80,7 +83,7 @@ async function buildSubgraph(root, resolved, startId, depth) {
80
83
  for (const path of frontier) {
81
84
  const text = await readFile(path, 'utf8');
82
85
  for (const link of extractLinks(text)) {
83
- const targetPath = await resolveLinkTarget(root, resolved.extensions, link);
86
+ const targetPath = await resolveLinkTarget(root, resolved.extensions, link, linkResolver);
84
87
  if (targetPath === undefined)
85
88
  continue;
86
89
  const toId = vaultRelativeId(root, targetPath);
@@ -102,7 +105,7 @@ async function buildSubgraph(root, resolved, startId, depth) {
102
105
  nodes.push({ id, title: await noteTitle(path, id) });
103
106
  const text = await readFile(path, 'utf8');
104
107
  for (const link of extractLinks(text)) {
105
- const targetPath = await resolveLinkTarget(root, resolved.extensions, link);
108
+ const targetPath = await resolveLinkTarget(root, resolved.extensions, link, linkResolver);
106
109
  if (targetPath === undefined)
107
110
  continue;
108
111
  const toId = vaultRelativeId(root, targetPath);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@jacklika/dsh-tool-memory-graph",
3
3
  "description": "Model-facing link-graph tool over a Markdown memory vault: returns note nodes and [[link]] edges, or the subgraph reachable from one note.",
4
- "version": "0.1.0-alpha.2",
4
+ "version": "0.1.0-alpha.3",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -32,7 +32,7 @@
32
32
  "license": "MIT",
33
33
  "dependencies": {
34
34
  "@deepseek-ai/schemastery": "3.18.4",
35
- "@jacklika/dsh-tool-memory-filesystem": "^0.1.3-alpha.4"
35
+ "@jacklika/dsh-tool-memory-filesystem": "^0.1.3-alpha.5"
36
36
  },
37
37
  "peerDependencies": {
38
38
  "@deepseek-ai/cordis": "4.0.4",