@sparkelf/dsh-knowledge-base 0.1.24 → 0.1.26
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/client.js +1944 -815
- package/lib/client.js.map +1 -1
- package/lib/index.js +507 -2
- package/lib/types/api.d.ts +15 -0
- package/lib/types/client/KnowledgeFilePreview.d.ts +32 -0
- package/lib/types/client/graph/KnowledgeGraphTree.d.ts +43 -0
- package/lib/types/client/graph/KnowledgeGraphView.d.ts +37 -0
- package/lib/types/client/graph/KnowledgeScopeTabs.d.ts +35 -0
- package/lib/types/client/graph/useKnowledgeGraph.d.ts +41 -0
- package/lib/types/client/locales.d.ts +15 -0
- package/lib/types/graph.d.ts +126 -0
- package/lib/types/graphCanvas.d.ts +16 -0
- package/lib/types/graphTools.d.ts +32 -0
- package/lib/types/graphTypes.d.ts +170 -0
- package/lib/types/index.d.ts +4 -0
- package/lib/types/views.d.ts +10 -0
- package/package.json +1 -1
- package/skills/knowledge-graph/SKILL.md +96 -0
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The read-only knowledge-graph shape shared by the Host scanner and the browser.
|
|
3
|
+
*
|
|
4
|
+
* A graph is an ordinary knowledge folder: `<scope>/知识图谱/<graph>/` with one
|
|
5
|
+
* visible sub-folder per topic and the relation documents under `.kg/links/`. The
|
|
6
|
+
* graph tab therefore speaks a DOMAIN model (scope → graph → topic) rather than the
|
|
7
|
+
* file tree's path model. Keeping the shape in one dependency-free module is what
|
|
8
|
+
* lets the Host build it and the canvas page render it without a second translation
|
|
9
|
+
* layer that could disagree about a field name.
|
|
10
|
+
*
|
|
11
|
+
* Paths here are VIEW-relative (`global/知识图谱/…`, `department/…`,
|
|
12
|
+
* `personal/知识图谱/…`): the personal owner segment is deliberately absent, exactly
|
|
13
|
+
* as the file tree shows it. The Host resolves the authoritative path first; the
|
|
14
|
+
* browser never needs to know the caller's uid.
|
|
15
|
+
*
|
|
16
|
+
* @module @sparkelf/dsh-knowledge-base/graph-types
|
|
17
|
+
*/
|
|
18
|
+
/** The folder name that marks a knowledge graph inside a scope. */
|
|
19
|
+
export declare const KNOWLEDGE_GRAPH_FOLDER = "\u77E5\u8BC6\u56FE\u8C31";
|
|
20
|
+
/** The hidden folder inside a graph that holds the relation documents. */
|
|
21
|
+
export declare const KNOWLEDGE_GRAPH_META_FOLDER = ".kg";
|
|
22
|
+
/** The trash folder `kg_del` moves topics into; never a topic itself. */
|
|
23
|
+
export declare const KNOWLEDGE_GRAPH_TRASH_FOLDER = "_trash";
|
|
24
|
+
/** One document inside a topic folder, as the detail panel lists it. */
|
|
25
|
+
export interface KnowledgeGraphDocument {
|
|
26
|
+
/** Human title: the document's first H1, else the file name without extension. */
|
|
27
|
+
title: string;
|
|
28
|
+
/** File name alone, relative to the topic folder. */
|
|
29
|
+
file: string;
|
|
30
|
+
/** View-relative path, for opening the document from a future write surface. */
|
|
31
|
+
path: string;
|
|
32
|
+
/** ISO-8601 date (`YYYY-MM-DD`) from the file's modification instant. */
|
|
33
|
+
date?: string;
|
|
34
|
+
/** First paragraph after the H1, when the file has one. */
|
|
35
|
+
summary?: string;
|
|
36
|
+
}
|
|
37
|
+
/** One topic: a visible folder whose `index.md` is its card. */
|
|
38
|
+
export interface KnowledgeGraphTopic {
|
|
39
|
+
/** Identity the relation documents reference. Front matter `id`, else folder name. */
|
|
40
|
+
id: string;
|
|
41
|
+
/** Card title. Front matter `title`, else the folder name. */
|
|
42
|
+
title: string;
|
|
43
|
+
/** Lifecycle state the prototype's cards colour. */
|
|
44
|
+
status: string;
|
|
45
|
+
/** 1–5 progress dots on the card. */
|
|
46
|
+
depth: number;
|
|
47
|
+
/** Optional grouping label shown as the first tag. */
|
|
48
|
+
domain?: string;
|
|
49
|
+
/** Remaining card tags. */
|
|
50
|
+
tags: string[];
|
|
51
|
+
/** First paragraph after the H1, shown on the card and in the detail panel. */
|
|
52
|
+
summary: string;
|
|
53
|
+
/** Free body from the card, H1 and summary removed; the detail panel renders it. */
|
|
54
|
+
body: string;
|
|
55
|
+
/** Visible folder name. */
|
|
56
|
+
folder: string;
|
|
57
|
+
/** View-relative topic folder path. */
|
|
58
|
+
path: string;
|
|
59
|
+
/** Documents beside `index.md`. */
|
|
60
|
+
documents: KnowledgeGraphDocument[];
|
|
61
|
+
}
|
|
62
|
+
/** One relation document under `<graph>/.kg/links/`. */
|
|
63
|
+
export interface KnowledgeGraphLink {
|
|
64
|
+
/** Topic id at one end. */
|
|
65
|
+
a: string;
|
|
66
|
+
/** Topic id at the other end. */
|
|
67
|
+
b: string;
|
|
68
|
+
/** Short edge label; the canvas falls back to `a ↔ b` when absent. */
|
|
69
|
+
label?: string;
|
|
70
|
+
/** ISO-8601 date from front matter or the file. */
|
|
71
|
+
updated?: string;
|
|
72
|
+
/** First body paragraph, shown when the relation pill is opened. */
|
|
73
|
+
body: string;
|
|
74
|
+
/** File name under `<graph>/.kg/links/`, used by the Host-side del tool. */
|
|
75
|
+
file?: string;
|
|
76
|
+
}
|
|
77
|
+
/** One graph node under a scope. */
|
|
78
|
+
export interface KnowledgeGraphNode {
|
|
79
|
+
/** Stable view-relative folder path; unique across the tree. */
|
|
80
|
+
id: string;
|
|
81
|
+
/** Display name: the graph folder's name. */
|
|
82
|
+
name: string;
|
|
83
|
+
/** Scope the graph lives in. */
|
|
84
|
+
scope: KnowledgeGraphScopeKey;
|
|
85
|
+
/** View-relative graph folder path. */
|
|
86
|
+
path: string;
|
|
87
|
+
/** Department display chain for a department graph, empty for the other scopes. */
|
|
88
|
+
group: string;
|
|
89
|
+
/** Topics in folder order. */
|
|
90
|
+
topics: KnowledgeGraphTopic[];
|
|
91
|
+
/** Relations whose two ends both resolve to topics in this graph. */
|
|
92
|
+
links: KnowledgeGraphLink[];
|
|
93
|
+
/** What the header states beside the breadcrumb. */
|
|
94
|
+
counts: {
|
|
95
|
+
topics: number;
|
|
96
|
+
links: number;
|
|
97
|
+
documents: number;
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* Authoritative path relative to the knowledge root, used by Host-side graph
|
|
101
|
+
* tools. Stripped before the tree is sent to the browser.
|
|
102
|
+
*/
|
|
103
|
+
actualPath?: string;
|
|
104
|
+
}
|
|
105
|
+
/** One group inside a scope: the department chain for 部门, empty elsewhere. */
|
|
106
|
+
export interface KnowledgeGraphGroup {
|
|
107
|
+
/** Stable key (the department code chain), empty for a flat scope. */
|
|
108
|
+
key: string;
|
|
109
|
+
/** Display label (department names, joined by ` / `). */
|
|
110
|
+
label: string;
|
|
111
|
+
/** Graphs directly in this group. */
|
|
112
|
+
graphs: KnowledgeGraphNode[];
|
|
113
|
+
}
|
|
114
|
+
/** One of the three knowledge scopes. */
|
|
115
|
+
export type KnowledgeGraphScopeKey = 'global' | 'department' | 'personal';
|
|
116
|
+
/** One scope level of the graph tree. */
|
|
117
|
+
export interface KnowledgeGraphScope {
|
|
118
|
+
key: KnowledgeGraphScopeKey;
|
|
119
|
+
/** Groups under the scope; a flat scope carries one group with an empty key. */
|
|
120
|
+
groups: KnowledgeGraphGroup[];
|
|
121
|
+
}
|
|
122
|
+
/** The caller identity the tree names, without credentials. */
|
|
123
|
+
export interface KnowledgeGraphCaller {
|
|
124
|
+
/** Stable user id, for tests and for a future owner label. */
|
|
125
|
+
userId: string;
|
|
126
|
+
/** Human label from DataOps. */
|
|
127
|
+
label: string;
|
|
128
|
+
/** The caller's organization chain, root first, when the backend reported one. */
|
|
129
|
+
departmentPathCodes?: string[];
|
|
130
|
+
/** Index-aligned display names for {@link departmentPathCodes}. */
|
|
131
|
+
departmentPathNames?: string[];
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* What `GET /knowledge-base/api/graph` answers.
|
|
135
|
+
*
|
|
136
|
+
* `scanned` counts graph folders the Host saw on disk; `visible` counts the ones
|
|
137
|
+
* that passed `canReadPath`; `denied` is the difference. The names of denied graphs
|
|
138
|
+
* never leave the Host, which is why this is counts rather than a refused list.
|
|
139
|
+
*/
|
|
140
|
+
export interface KnowledgeGraphTree {
|
|
141
|
+
scopes: KnowledgeGraphScope[];
|
|
142
|
+
caller: KnowledgeGraphCaller;
|
|
143
|
+
/**
|
|
144
|
+
* Authoritative knowledge root the scanner read.
|
|
145
|
+
*
|
|
146
|
+
* Returned for a future write surface that must reuse the Host's own resolver
|
|
147
|
+
* instead of building `personal/<uid>/…` in the browser. The panel already shows
|
|
148
|
+
* this value in its status header, so naming it here adds no disclosure.
|
|
149
|
+
*/
|
|
150
|
+
actualRoot: string;
|
|
151
|
+
scanned: number;
|
|
152
|
+
visible: number;
|
|
153
|
+
denied: number;
|
|
154
|
+
}
|
|
155
|
+
/** An empty tree, for the loading and failure states. */
|
|
156
|
+
export declare function emptyKnowledgeGraphTree(): KnowledgeGraphTree;
|
|
157
|
+
/** Flatten the tree into the list the canvas page consumes. */
|
|
158
|
+
export declare function knowledgeGraphsOf(tree: KnowledgeGraphTree): KnowledgeGraphNode[];
|
|
159
|
+
/**
|
|
160
|
+
* Whether a graph or one of its topics matches the tree's in-place filter.
|
|
161
|
+
*
|
|
162
|
+
* This narrows what the Host already returned; it is not a permission filter and
|
|
163
|
+
* must never be used as one. Exported so the rule can be tested without rendering
|
|
164
|
+
* the tree.
|
|
165
|
+
*
|
|
166
|
+
* @param graph - one permission-filtered graph.
|
|
167
|
+
* @param needle - already lower-cased filter term.
|
|
168
|
+
* @returns true when the graph name or a topic title contains the term.
|
|
169
|
+
*/
|
|
170
|
+
export declare function knowledgeGraphMatches(graph: KnowledgeGraphNode, needle: string): boolean;
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1044,6 +1044,8 @@ export declare const KNOWLEDGE_SKILL_NAME = "knowledge-base";
|
|
|
1044
1044
|
export declare const KB_SUMMARIZE_SKILL_NAME = "kb-summarize";
|
|
1045
1045
|
/** Third bundled skill: explicit document/directory vectorization. */
|
|
1046
1046
|
export declare const KB_VECTORIZE_SKILL_NAME = "kb-vectorize";
|
|
1047
|
+
export declare const KNOWLEDGE_GRAPH_SKILL_NAME = "knowledge-graph";
|
|
1048
|
+
export declare const KNOWLEDGE_GRAPH_SKILL_DESCRIPTION = "\u8BFB\u5199\u56E2\u961F\u77E5\u8BC6\u5E93\u91CC\u7684\u77E5\u8BC6\u56FE\u8C31\uFF1A\u4E3B\u9898\u5361\u3001\u5173\u7CFB\u6587\u6863\u4E0E\u56DB\u4E2A\u52A8\u4F5C\u3002";
|
|
1047
1049
|
/**
|
|
1048
1050
|
* Short description shown in the skill list.
|
|
1049
1051
|
*
|
|
@@ -1084,6 +1086,8 @@ export declare function knowledgeSkillPath(): string;
|
|
|
1084
1086
|
export declare function kbSummarizeSkillPath(): string;
|
|
1085
1087
|
/** Where the bundled `kb-vectorize` skill lives. */
|
|
1086
1088
|
export declare function kbVectorizeSkillPath(): string;
|
|
1089
|
+
/** Where the bundled `knowledge-graph` skill lives. */
|
|
1090
|
+
export declare function knowledgeGraphSkillPath(): string;
|
|
1087
1091
|
/**
|
|
1088
1092
|
* Where this package's tutorial document lives, from either build layout.
|
|
1089
1093
|
*
|
package/lib/types/views.d.ts
CHANGED
|
@@ -838,6 +838,16 @@ export interface KnowledgeAuditEntry {
|
|
|
838
838
|
relPath: string;
|
|
839
839
|
/** For a move, the destination path. */
|
|
840
840
|
toRelPath?: string;
|
|
841
|
+
/** Model-facing tool that performed the action, when one did. */
|
|
842
|
+
tool?: string;
|
|
843
|
+
/** Graph the action belongs to, when the action is a graph operation. */
|
|
844
|
+
graphId?: string;
|
|
845
|
+
/** Topic id inside the graph, when the action names one. */
|
|
846
|
+
topicId?: string;
|
|
847
|
+
/** Short human intent (`new topic`, `move-to-trash`, ...). */
|
|
848
|
+
intent?: string;
|
|
849
|
+
/** One-line description of what changed, for review. */
|
|
850
|
+
diffSummary?: string;
|
|
841
851
|
/**
|
|
842
852
|
* Extra detail for actions that have more than one flavour.
|
|
843
853
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sparkelf/dsh-knowledge-base",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.26",
|
|
4
4
|
"description": "DataOps-backed knowledge base for DeepSeek Harness: a left-sidebar destination, Settings configuration, and index tooling over a mounted NAS view.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: knowledge-graph
|
|
3
|
+
description: 读写团队知识库里的知识图谱:主题卡、关系文档、四个动作和五个剧本。
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# knowledge-graph
|
|
7
|
+
|
|
8
|
+
知识图谱是知识库的导航层,不是第二套文档库。它只有三样东西:**图谱**(一个可见文件夹)、**主题**(图谱下的可见子文件夹 + `index.md` 卡)、**关系**(`index.md` 之间的一篇文档)。
|
|
9
|
+
|
|
10
|
+
## 1. 目录长什么样
|
|
11
|
+
|
|
12
|
+
```text
|
|
13
|
+
<scope>/知识图谱/<graph>/
|
|
14
|
+
<主题>/
|
|
15
|
+
index.md # 主题卡:front-matter + 摘要 + 自由正文
|
|
16
|
+
<document>.md # 文档,知识库能搜、能预览、能分享
|
|
17
|
+
.kg/
|
|
18
|
+
links/<a>--<b>.md # 关系文档,点开头,KB 文件树和 FTS 跳过
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
- `<scope>` 是 `global` / `department/<部门链>` / `personal/<uid>`;个人路径由 Host 解析,**不要让模型拼 uid**。
|
|
22
|
+
- 主题文件夹名可读、可改;关系引用 `index.md` 里的 `id`,不引用文件夹名,所以改名不断边。
|
|
23
|
+
- 一个图谱一条 grant,覆盖主题文档与 `.kg`;写操作走 `kg_add` / `kg_set` / `kg_del`,不要用 shell 直接写文件。
|
|
24
|
+
|
|
25
|
+
## 2. 主题卡与关系文档
|
|
26
|
+
|
|
27
|
+
主题卡好例子:
|
|
28
|
+
|
|
29
|
+
```markdown
|
|
30
|
+
---
|
|
31
|
+
id: task-bus
|
|
32
|
+
title: 任务总线
|
|
33
|
+
status: active
|
|
34
|
+
depth: 4
|
|
35
|
+
domain: dsh
|
|
36
|
+
tags: [任务, 状态机]
|
|
37
|
+
updated: 2026-10-31
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
# 任务总线
|
|
41
|
+
|
|
42
|
+
DSH 的跨来源任务底座,任务卡是唯一状态载体。
|
|
43
|
+
|
|
44
|
+
## 现在
|
|
45
|
+
v0.1 设计稿评审完,正在拆实现任务。
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
坏例子:没有 `id`(关系会指向文件夹名,改名断边);把全部正文塞进摘要(卡片会变成一堵墙);`status` 写成自由文本(画布只能识别 active/paused/done)。
|
|
49
|
+
|
|
50
|
+
关系文档好例子:
|
|
51
|
+
|
|
52
|
+
```markdown
|
|
53
|
+
---
|
|
54
|
+
a: task-bus
|
|
55
|
+
b: group-chat
|
|
56
|
+
label: 任务来源
|
|
57
|
+
updated: 2026-10-31
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
# 任务来源
|
|
61
|
+
|
|
62
|
+
群聊把讨论转成任务;任务总线承接状态,不反向写群聊。
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
坏例子:`a`/`b` 指向不存在的 id(画布会丢弃这条边);一篇文档写三段互不相关的关系(关系文档只表达两端之间的一件事)。
|
|
66
|
+
|
|
67
|
+
## 3. 四个动作
|
|
68
|
+
|
|
69
|
+
工具名与 `kg.py` 对齐:`kg_add` / `kg_get` / `kg_set` / `kg_del`。所有写动作**先返回草稿**,把草稿给用户看,用户确认后再带 `confirm: true` 调用。
|
|
70
|
+
|
|
71
|
+
| 动作 | 做什么 |
|
|
72
|
+
|---|---|
|
|
73
|
+
| `kg_add` | `kind: topic` 新增一条线(文件夹 + 卡);`kind: link` 新增一条关系 |
|
|
74
|
+
| `kg_get` | 不带 `graph`/`id` 返回全部图谱总览;带 `graph` 返回该图谱;带 `graph`+`id` 返回卡、文档、关系 |
|
|
75
|
+
| `kg_set` | 改一个主题的 `status` / `depth` / `title` / `domain` / 摘要 / 正文 |
|
|
76
|
+
| `kg_del` | 把主题移到 `<graph>/_trash/`;有关联关系时需 `force: true` 一并移走,**不真删** |
|
|
77
|
+
|
|
78
|
+
### 五个剧本
|
|
79
|
+
|
|
80
|
+
1. **新建一条线**:`kg_get` 看当前图谱 → `kg_add {kind:"topic"}` 草稿 → 用户确认 → `confirm:true`。
|
|
81
|
+
2. **接续**:`kg_get {graph,id}` 读卡与关系 → 更新正文/摘要 → `kg_set` 草稿 → 确认。
|
|
82
|
+
3. **寻址**:`kg_get` 不带 id 看总览 → 按名称找 graph → `kg_get {graph,id}` 读一条线;不要用 `find`/`map` 另造工具。
|
|
83
|
+
4. **沉淀**:把一次会话的结论写成文档(`kb_file_write` 到主题文件夹),再用 `kg_set` 更新卡摘要;图谱不复制文档内容。
|
|
84
|
+
5. **复盘**:`kg_get` 总览 → 对每条线读 `kg_get {graph,id}` → 把 `status`/`depth` 调整回真实状态;`kg_del` 只移 `_trash`,不删。
|
|
85
|
+
|
|
86
|
+
## 4. 扫历史会话(shell,不配工具)
|
|
87
|
+
|
|
88
|
+
需要从旧会话里找线索时,直接读会话日志,不要新建 `scan` 工具:
|
|
89
|
+
|
|
90
|
+
```sh
|
|
91
|
+
zstd -dc ~/.dsh/sessions/<session>.jsonl.zst \
|
|
92
|
+
| rg -i '任务总线|group-chat|kg' \
|
|
93
|
+
| head -80
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
把命中的原文片段带回当前对话,再由 agent 写成主题卡或文档;工具只负责图谱的四个动作,不负责扫描历史。
|