cladogram 0.6.0-beta.2 → 0.6.0-beta.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/bin/clado.js +34 -2
- package/docs/release.md +8 -0
- package/package.json +1 -1
- package/plugins/agent/index.js +826 -106
- package/plugins/agent/style.css +448 -38
- package/src/agent/clado-tools.js +437 -103
- package/src/agent/pi-bridge.js +517 -42
- package/src/agent/pi-config.js +367 -31
- package/src/html/canvas-chain.js +26 -2
- package/src/html/canvas-focus.js +19 -13
- package/src/html/canvas-live-diff.js +927 -0
- package/src/html/canvas-ui.css +365 -0
- package/src/html/canvas-wires.js +5 -1
- package/src/html/page.js +1 -1
- package/src/html/runtime-api.js +140 -10
- package/src/html/runtime.js +93 -26
- package/src/server/agent.js +40 -8
- package/src/server/assets/library-canvas.js +240 -5
- package/src/server/assets/library.css +416 -0
- package/src/server/assets/library.html +2 -0
- package/src/server/assets/library.js +703 -14
- package/src/server/code-inspect.js +183 -0
- package/src/server/mcp.js +4 -4
- package/src/server/workspace.js +260 -18
- package/src/workspace/graph-snapshot.js +695 -0
- package/src/workspace/service.js +11 -1
package/src/agent/pi-config.js
CHANGED
|
@@ -22,6 +22,40 @@ import {
|
|
|
22
22
|
SettingsManager,
|
|
23
23
|
} from '@earendil-works/pi-coding-agent';
|
|
24
24
|
|
|
25
|
+
export const CLADO_CANVAS_MASTERY_GUIDE = [
|
|
26
|
+
'## Clado 空间画布精通指南(所有角色必守)',
|
|
27
|
+
'',
|
|
28
|
+
'### 1. Markdown 即画布结构(整体规划、一次落图)',
|
|
29
|
+
'- `# 一级标题`(L1)= 画布上的一张独立卡片;`##`–`######`(L2–L6)= 卡内包含小节。',
|
|
30
|
+
'- **卡片模式(默认主视图)**:通过跨卡 Markdown 内链自动从左到右排布成「有向无环网状流(DAG)」;**脑图模式**按标题层级展开为树;**文档模式**按文章流阅读。',
|
|
31
|
+
'- **整体规划、一次落图**:新建或大幅重构画布时,**严禁一张一张创建空卡后再逐个补线**!先在脑中设计好完整的 3–5 列单向流(通常 4–9 张核心卡片),再用 `clado_create` 或 `clado_update` **一次性写出带完整正文、语义 Tag 与克制正向连线的完整画布**;`clado_nodes` / `clado_links` 仅用于局部微调已有画布。',
|
|
32
|
+
'',
|
|
33
|
+
'### 2. 流向与克制连线铁律(顺滑单向网,拒绝蜘蛛网与尾连头)',
|
|
34
|
+
'- **严格单向流(从左至右、从上至下 DAG)**:一张画布必须有清晰明确的起止过程——左侧入口触发/契约卡(Col 0)→ 中间编排/路由卡(适度扇出 2–3 路并行分支)→ 领域处理/核心能力卡 → 右侧汇聚/持久化/外部边界终点卡(Col N)。',
|
|
35
|
+
'- **绝对禁止反向回环与尾连头**:**严禁把终点卡/下游卡连回入口卡或任何上游卡,严禁两张卡双向互连(A → B 且 B → A)**!异步回调、状态回写或最终确认用正文说明或语义 Tag 标注即可,绝不能用反向连线把整张图的列序搅成死循环。',
|
|
36
|
+
'- **克制连线(设计高级感的底线)**:**不要「觉得两张卡有概念关联就顺手连一条线」**!跨卡连线只表达**真实发生的下一步流转、调用流向或主干数据流**:',
|
|
37
|
+
' - **拒绝跨层捷径**:既然已经有 `A → B → C`,就不要再多此一举连一条 `A → C`。',
|
|
38
|
+
' - **控制单卡出度**:每张卡片发出的跨卡连线建议 **1–3 条**(严格不超过 **4 条**),整张图平均每张卡约 **1.0–1.8 条**跨卡连线;该分叉处分叉、该汇聚处汇聚,整体一眼顺畅通透,绝不画成密密麻麻的蜘蛛网。',
|
|
39
|
+
' - **无孤立卡片**:多卡画布中每张核心卡都必须处于主干流的合理位置,不留下脱离流程的游离卡片。',
|
|
40
|
+
'',
|
|
41
|
+
'### 3. 跨卡连线语法与六色语义 Tag(二元连线模型)',
|
|
42
|
+
'- **连卡片**:`[说明文字](目标卡片标题)`(目标须与某张 `# 标题` 一字不差)。',
|
|
43
|
+
'- **连小节**:`[说明文字](目标卡片标题#小节标题)`。',
|
|
44
|
+
'- **语义 Tag 锚点(文档内 `#id` 必须唯一)**:',
|
|
45
|
+
' - 正文/列表/表格:`[新增]{#id .green}`、`[修改]{#id .amber}`、`[风险]{#id .red}`、`[契约]{#id .blue}`、`[说明]{#id .purple}`,或无字圆点 `[]{#id .green}`。',
|
|
46
|
+
' - 代码块行尾注释(保持代码可直接编译):`verifySign(req); // {#verify-sign .blue}`。',
|
|
47
|
+
' - Mermaid 注释:`%% {#NODE_ID .green}`。',
|
|
48
|
+
' - 精准连到 Tag:`[触发验签](#verify-sign)` 或 `[触发验签](目标卡片标题#verify-sign)`。',
|
|
49
|
+
'- **连线落在真实位置**:把连线直接写在调用/流转发生的具体 `##` 步骤、代码行或表格行内,避免在卡片末尾堆裸链接;自连、外链网址(`https://`)和跨文档链接不计入本画布卡片连线。单块正文保持精炼(建议 ≤ 400 字),善用 `##`/`###` 拆层。',
|
|
50
|
+
'',
|
|
51
|
+
'### 4. 像读 DOM 树一样自检画布(`clado_graph` 闭环)',
|
|
52
|
+
'- 新建或修改画布前,先用 `clado_list` / `clado_graph` / `clado_templates` 了解现有画布和模板约束(如 `call-chain`、`business-flow`、`requirement-overview`、`data-design`、`test-cases`、`system-state`)。',
|
|
53
|
+
'- 每次调用 `clado_create` / `clado_update` / `clado_nodes` / `clado_links` 都会附带渲染后的 `graphCheck`,且画布会自动原生呈现红删绿增的实时变更并展开新连线;**交付前必须调用 `clado_graph`** 复核实际连出来的列布局、端到端链路、Tag 与体检结果,确认:**0 反向回环、0 孤立卡、0 未解析断链、0 语法错误、无单卡出度过载或连线过密警告**。',
|
|
54
|
+
'',
|
|
55
|
+
'### 5. 工具失败强感知铁律',
|
|
56
|
+
'- 只要任何工具返回错误(`isError: true` 或包含 `[TOOL_ERROR]`),或者 `graphCheck` / `clado_graph` 提示 `actionRequired`(存在反向回环、孤立卡、断链或语法错误),**严禁忽略或向用户宣称已完成**!必须立即阅读错误信息、回环边清单与行号,修正画布后重试,直到 `clado_graph` 显示 `healthy: true` 且流向顺畅克制后再总结汇报。',
|
|
57
|
+
].join('\n');
|
|
58
|
+
|
|
25
59
|
export const BUILTIN_ROLES = [
|
|
26
60
|
{
|
|
27
61
|
id: 'architect',
|
|
@@ -29,11 +63,15 @@ export const BUILTIN_ROLES = [
|
|
|
29
63
|
phase: '设计阶段',
|
|
30
64
|
tone: 'sky',
|
|
31
65
|
builtin: true,
|
|
32
|
-
description: '
|
|
66
|
+
description: '分析老代码、梳理方案边界、在卡片画布上构建从左至右克制顺滑的单向网状架构图并反复迭代定稿。',
|
|
33
67
|
systemPrompt: [
|
|
34
|
-
'你是 Clado
|
|
35
|
-
'
|
|
36
|
-
'
|
|
68
|
+
'你是 Clado 工作台中的「主架构师」角色,也是 Clado 空间画布最熟练的专家。',
|
|
69
|
+
'你的核心工作流程:',
|
|
70
|
+
'1. **摸清现状**:先用 `read`/`bash` 扫描仓库真实源码与入口边界,并用 `clado_list`、`clado_graph`、`clado_templates` 查看已有画布与推荐模板(接口/调用链优先 `call-chain`,业务流用 `business-flow`,需求概览用 `requirement-overview`,数据设计用 `data-design`)。',
|
|
71
|
+
'2. **整体规划、一次落图**:先在脑中规划好 3–5 列从左到右、从上到下的单向业务/调用流(左侧入口契约卡 → 中间编排与适度并行分支卡 → 汇聚服务卡 → 右侧数据/外部边界终点卡),然后优先用 `clado_create` / `clado_update` 一次性写出带完整内容、语义 Tag(`.green` 新增 / `.amber` 修改 / `.red` 风险 / `.blue` 契约 / `.purple` 说明)与克制正向连线的画布——**不要一张一张画空卡再回头乱连线**。',
|
|
72
|
+
'3. **克制连线、严禁回环**:跨卡连线只保留真实下一步执行流/数据流(单卡出度 1–3 条、最多 4 条,绝不画尾连头反向边、双向互连、概念联想边或跨层捷径边)。',
|
|
73
|
+
'4. **必做拓扑验收**:每次落图或改图后,立即检查返回的 `graphCheck` 并调用 `clado_graph` 读取实际列布局与端到端链路;若存在反向回环、孤立卡、断链或出度过密警告,当场修好再复查,确认 `healthy: true` 且整张网顺滑清爽。',
|
|
74
|
+
'5. **关键决策确认**:遇到多个合理架构方案或核心边界需要拍板时,先完整阐述分析与权衡,再在最后调用 `ask_user` 给出 2–4 个清晰选项卡片让用户确认。',
|
|
37
75
|
].join('\n'),
|
|
38
76
|
},
|
|
39
77
|
{
|
|
@@ -42,11 +80,14 @@ export const BUILTIN_ROLES = [
|
|
|
42
80
|
phase: '交付阶段',
|
|
43
81
|
tone: 'emerald',
|
|
44
82
|
builtin: true,
|
|
45
|
-
description: '
|
|
83
|
+
description: '读取画布网状契约与语义 Tag,精准落地代码、运行校验并同步回写画布。',
|
|
46
84
|
systemPrompt: [
|
|
47
85
|
'你是 Clado 工作台中的「开发落地」角色。',
|
|
48
|
-
'
|
|
49
|
-
'
|
|
86
|
+
'你的核心工作流程:',
|
|
87
|
+
'1. **先读画布契约**:开工前先调用 `clado_graph` 和 `clado_read` 完整理解当前画布的单向拓扑流、入口契约、调用路径与语义 Tag(尤其是 `[新增]`/`[修改]`/`[风险]` 标注)。',
|
|
88
|
+
'2. **精准编码与验证**:直接使用 `read` / `edit` / `write` / `bash` 完成真实代码实现、编译与测试校验,改动克制精准。',
|
|
89
|
+
'3. **同步画布与复核**:若实现细节、文件或调用关系较原设计有调整,使用 `clado_nodes` / `clado_links` / `clado_update` 同步回写画布,保持严格单向克制连线,并用 `clado_graph` 确认 0 反向回环、0 孤立卡、0 断链;任何工具报错都必须立即定位修复。',
|
|
90
|
+
'4. **清晰交付**:完成后向用户清晰汇报修改了哪些文件、测试校验结果以及画布同步情况。',
|
|
50
91
|
].join('\n'),
|
|
51
92
|
},
|
|
52
93
|
{
|
|
@@ -55,10 +96,13 @@ export const BUILTIN_ROLES = [
|
|
|
55
96
|
phase: '验收阶段',
|
|
56
97
|
tone: 'violet',
|
|
57
98
|
builtin: true,
|
|
58
|
-
description: '
|
|
99
|
+
description: '沿画布调用网状路径生成单测与回归矩阵,执行验证并将结果回写画布。',
|
|
59
100
|
systemPrompt: [
|
|
60
101
|
'你是 Clado 工作台中的「测试验证」角色。',
|
|
61
|
-
'
|
|
102
|
+
'你的核心工作流程:',
|
|
103
|
+
'1. **沿网状路径查漏**:先调用 `clado_graph` 与 `clado_read`,沿着入口卡 → 分叉/汇聚节点 → 终点卡梳理每一条成功路径、并发边界与失败出口。',
|
|
104
|
+
'2. **编写与执行验证**:对照画布契约编写或补充单元测试、集成测试与异常回归用例,用 `bash` 实际运行测试并核对真实输出(未执行的验证绝不可写成通过)。',
|
|
105
|
+
'3. **画布可视化回写**:可按 `test-cases` 模板用 `clado_create` / `clado_update` 一次性产出单向清晰的测试矩阵画布,或用语义 Tag / `canvas_objects_upsert` 便签把验收结果与未覆盖风险标回画布,并调用 `clado_graph` 确认 0 回环、0 断链、0 孤立卡。',
|
|
62
106
|
].join('\n'),
|
|
63
107
|
},
|
|
64
108
|
{
|
|
@@ -67,25 +111,144 @@ export const BUILTIN_ROLES = [
|
|
|
67
111
|
phase: '文档阶段',
|
|
68
112
|
tone: 'amber',
|
|
69
113
|
builtin: true,
|
|
70
|
-
description: '
|
|
114
|
+
description: '盘点全部画布拓扑与落地事实,沉淀为高质量归档画布、README / ADR 与变更记录。',
|
|
71
115
|
systemPrompt: [
|
|
72
116
|
'你是 Clado 工作台中的「归档整理」角色。',
|
|
73
|
-
'
|
|
117
|
+
'你的核心工作流程:',
|
|
118
|
+
'1. **全局盘点**:先调用 `clado_graph`(省略 file)读取整个工作区全部画布的拓扑总览与跨文档导航关系,排查反向回环、孤立卡与断链。',
|
|
119
|
+
'2. **事实核对**:结合真实源码与测试结果,严格区分「已落地现状」与「设计提案」,绝不把未实现的提案写成已上线事实。',
|
|
120
|
+
'3. **结构化沉淀**:可使用 `system-state` 模板整理归档画布或更新 README / ADR / 变更记录;修改画布后必须用 `clado_graph` 复核单向流健康且跨卡与跨文档连线全部可解析。',
|
|
74
121
|
].join('\n'),
|
|
75
122
|
},
|
|
76
123
|
];
|
|
77
124
|
|
|
78
125
|
export const PROVIDER_CATALOG = [
|
|
79
|
-
{
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
126
|
+
{
|
|
127
|
+
id: 'deepseek',
|
|
128
|
+
name: 'DeepSeek',
|
|
129
|
+
api: 'openai-completions',
|
|
130
|
+
defaultBaseUrl: 'https://api.deepseek.com',
|
|
131
|
+
envKey: 'DEEPSEEK_API_KEY',
|
|
132
|
+
defaultModel: 'deepseek-flash',
|
|
133
|
+
defaultContextWindow: 1000000,
|
|
134
|
+
defaultMaxTokens: 384000,
|
|
135
|
+
hint: 'deepseek-flash (V4.1 · 1M) / deepseek-v4-pro (1M)',
|
|
136
|
+
recommendedModels: [
|
|
137
|
+
{ id: 'deepseek-flash', label: 'DeepSeek V4.1 Flash (1M · 思考/视觉)', contextWindow: 1000000, maxTokens: 384000, reasoning: true },
|
|
138
|
+
{ id: 'deepseek-v4-pro', label: 'DeepSeek V4 Pro (1M · 深度推理)', contextWindow: 1000000, maxTokens: 384000, reasoning: true },
|
|
139
|
+
],
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
id: 'anthropic',
|
|
143
|
+
name: 'Anthropic · Claude',
|
|
144
|
+
api: 'anthropic-messages',
|
|
145
|
+
defaultBaseUrl: 'https://api.anthropic.com',
|
|
146
|
+
envKey: 'ANTHROPIC_API_KEY',
|
|
147
|
+
defaultModel: 'claude-sonnet-5-5',
|
|
148
|
+
defaultContextWindow: 1000000,
|
|
149
|
+
defaultMaxTokens: 128000,
|
|
150
|
+
hint: 'claude-sonnet-5-5 / claude-opus-5-5 / claude-fable-5-2 / claude-haiku-5-5',
|
|
151
|
+
recommendedModels: [
|
|
152
|
+
{ id: 'claude-sonnet-5-5', label: 'Claude Sonnet 5.5 (1M · 速度与智能平衡)', contextWindow: 1000000, maxTokens: 128000, reasoning: true },
|
|
153
|
+
{ id: 'claude-opus-5-5', label: 'Claude Opus 5.5 (1M · 长程编码主力)', contextWindow: 1000000, maxTokens: 128000, reasoning: true },
|
|
154
|
+
{ id: 'claude-fable-5-2', label: 'Claude Fable 5.2 (1M · 旗舰推理)', contextWindow: 1000000, maxTokens: 128000, reasoning: true },
|
|
155
|
+
{ id: 'claude-haiku-5-5', label: 'Claude Haiku 5.5 (1M · 极速轻量)', contextWindow: 1000000, maxTokens: 128000, reasoning: true },
|
|
156
|
+
],
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
id: 'openai',
|
|
160
|
+
name: 'OpenAI',
|
|
161
|
+
api: 'openai-responses',
|
|
162
|
+
defaultBaseUrl: 'https://api.openai.com/v1',
|
|
163
|
+
envKey: 'OPENAI_API_KEY',
|
|
164
|
+
defaultModel: 'gpt-6.2-sol',
|
|
165
|
+
defaultContextWindow: 1050000,
|
|
166
|
+
defaultMaxTokens: 128000,
|
|
167
|
+
hint: 'gpt-6.2-sol / gpt-6.2-astra / gpt-5.4',
|
|
168
|
+
recommendedModels: [
|
|
169
|
+
{ id: 'gpt-6.2-sol', label: 'GPT-6.2 Sol (1.05M · 均衡主力)', contextWindow: 1050000, maxTokens: 128000, reasoning: true },
|
|
170
|
+
{ id: 'gpt-6.2-astra', label: 'GPT-6.2 Astra (1.05M · 旗舰编码推理)', contextWindow: 1050000, maxTokens: 128000, reasoning: true },
|
|
171
|
+
{ id: 'gpt-5.4', label: 'GPT-5.4 (1.05M)', contextWindow: 1050000, maxTokens: 128000, reasoning: true },
|
|
172
|
+
],
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
id: 'google',
|
|
176
|
+
name: 'Google · Gemini',
|
|
177
|
+
api: 'google-generative-ai',
|
|
178
|
+
defaultBaseUrl: 'https://generativelanguage.googleapis.com/v1beta',
|
|
179
|
+
envKey: 'GEMINI_API_KEY',
|
|
180
|
+
defaultModel: 'gemini-4-carbon',
|
|
181
|
+
defaultContextWindow: 1000000,
|
|
182
|
+
defaultMaxTokens: 65536,
|
|
183
|
+
hint: 'gemini-4-carbon / gemini-3.6-flash / gemini-2.5-pro',
|
|
184
|
+
recommendedModels: [
|
|
185
|
+
{ id: 'gemini-4-carbon', label: 'Gemini 4 Carbon (1M · 旗舰多模态)', contextWindow: 1000000, maxTokens: 65536, reasoning: true },
|
|
186
|
+
{ id: 'gemini-3.6-flash', label: 'Gemini 3.6 Flash (1M · 极速高吞吐)', contextWindow: 1000000, maxTokens: 65536, reasoning: true },
|
|
187
|
+
{ id: 'gemini-2.5-pro', label: 'Gemini 2.5 Pro (1M)', contextWindow: 1000000, maxTokens: 65536, reasoning: true },
|
|
188
|
+
],
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
id: 'openrouter',
|
|
192
|
+
name: 'OpenRouter',
|
|
193
|
+
api: 'openai-completions',
|
|
194
|
+
defaultBaseUrl: 'https://openrouter.ai/api/v1',
|
|
195
|
+
envKey: 'OPENROUTER_API_KEY',
|
|
196
|
+
defaultModel: 'anthropic/claude-sonnet-5.5',
|
|
197
|
+
defaultContextWindow: 1000000,
|
|
198
|
+
defaultMaxTokens: 128000,
|
|
199
|
+
hint: '多模型统一聚合网关(anthropic/deepseek/openai)',
|
|
200
|
+
recommendedModels: [
|
|
201
|
+
{ id: 'anthropic/claude-sonnet-5.5', label: 'Claude Sonnet 5.5 (1M)', contextWindow: 1000000, maxTokens: 128000, reasoning: true },
|
|
202
|
+
{ id: 'deepseek/deepseek-v4.1-flash', label: 'DeepSeek V4.1 Flash (1M)', contextWindow: 1000000, maxTokens: 128000, reasoning: true },
|
|
203
|
+
{ id: 'openai/gpt-6.2-sol', label: 'GPT-6.2 Sol (1.05M)', contextWindow: 1050000, maxTokens: 128000, reasoning: true },
|
|
204
|
+
],
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
id: 'ollama',
|
|
208
|
+
name: '本地模型 · Ollama',
|
|
209
|
+
api: 'openai-completions',
|
|
210
|
+
defaultBaseUrl: 'http://127.0.0.1:11434/v1',
|
|
211
|
+
envKey: '',
|
|
212
|
+
defaultModel: 'qwen2.5-coder:14b',
|
|
213
|
+
defaultContextWindow: 128000,
|
|
214
|
+
defaultMaxTokens: 16384,
|
|
215
|
+
hint: 'http://127.0.0.1:11434/v1 · 离线零延迟',
|
|
216
|
+
keyless: true,
|
|
217
|
+
recommendedModels: [
|
|
218
|
+
{ id: 'qwen2.5-coder:14b', label: 'Qwen2.5-Coder 14B (128K)', contextWindow: 128000, maxTokens: 16384, reasoning: false },
|
|
219
|
+
{ id: 'deepseek-r1:14b', label: 'DeepSeek-R1 14B (128K · 推理)', contextWindow: 128000, maxTokens: 16384, reasoning: true },
|
|
220
|
+
],
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
id: 'custom-openai',
|
|
224
|
+
name: '自定义代理(OpenAI 兼容)',
|
|
225
|
+
api: 'openai-completions',
|
|
226
|
+
defaultBaseUrl: '',
|
|
227
|
+
envKey: '',
|
|
228
|
+
defaultModel: '',
|
|
229
|
+
defaultContextWindow: 200000,
|
|
230
|
+
defaultMaxTokens: 32768,
|
|
231
|
+
hint: '填写任意中转站或自建网关 Base URL 与模型 ID',
|
|
232
|
+
recommendedModels: [],
|
|
233
|
+
},
|
|
234
|
+
{
|
|
235
|
+
id: 'custom-anthropic',
|
|
236
|
+
name: '自定义代理(Anthropic 兼容)',
|
|
237
|
+
api: 'anthropic-messages',
|
|
238
|
+
defaultBaseUrl: '',
|
|
239
|
+
envKey: '',
|
|
240
|
+
defaultModel: '',
|
|
241
|
+
defaultContextWindow: 200000,
|
|
242
|
+
defaultMaxTokens: 32768,
|
|
243
|
+
hint: '填写 Anthropic 协议中转站 Base URL(如 DeepSeek Anthropic 端点)',
|
|
244
|
+
recommendedModels: [],
|
|
245
|
+
},
|
|
87
246
|
];
|
|
88
247
|
|
|
248
|
+
export const THINKING_LEVELS = ['off', 'minimal', 'low', 'medium', 'high', 'xhigh', 'max'];
|
|
249
|
+
export const TRANSPORT_MODES = ['auto', 'sse', 'websocket', 'websocket-cached'];
|
|
250
|
+
export const CACHE_WARMING_MODES = ['off', 'streaming', 'idle'];
|
|
251
|
+
|
|
89
252
|
export function resolvePiAgentDir() {
|
|
90
253
|
const dir = process.env.CLADO_PI_AGENT_DIR
|
|
91
254
|
? resolve(process.env.CLADO_PI_AGENT_DIR)
|
|
@@ -141,6 +304,21 @@ export async function createCladoModelRuntime(agentDir = resolvePiAgentDir()) {
|
|
|
141
304
|
});
|
|
142
305
|
}
|
|
143
306
|
|
|
307
|
+
function clampInt(val, min, max, fallback) {
|
|
308
|
+
const n = Number(val);
|
|
309
|
+
if (!Number.isFinite(n) || n <= 0) return fallback;
|
|
310
|
+
return Math.max(min, Math.min(max, Math.round(n)));
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
function lookupRecommendedSpec(preset, modelId) {
|
|
314
|
+
if (!preset || !Array.isArray(preset.recommendedModels)) return null;
|
|
315
|
+
return preset.recommendedModels.find(m => m.id === modelId) || null;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
function inferReasoning(modelId) {
|
|
319
|
+
return /reason|r1|o1|o3|o4|thinking|sonnet-4|opus-4|sonnet-5|opus-5|fable-5|haiku-5|gpt-5|gpt-6|deepseek-flash|deepseek-v4|gemini-3|gemini-4|gemini-2\.5/i.test(String(modelId || ''));
|
|
320
|
+
}
|
|
321
|
+
|
|
144
322
|
export function saveProviderConfig({
|
|
145
323
|
providerId,
|
|
146
324
|
apiKey,
|
|
@@ -148,6 +326,9 @@ export function saveProviderConfig({
|
|
|
148
326
|
api,
|
|
149
327
|
models,
|
|
150
328
|
defaultModel,
|
|
329
|
+
contextWindow,
|
|
330
|
+
maxTokens,
|
|
331
|
+
reasoning,
|
|
151
332
|
setAsDefault = false,
|
|
152
333
|
}, agentDir = resolvePiAgentDir(), workspace = process.cwd()) {
|
|
153
334
|
const cleanId = String(providerId || '').trim().toLowerCase().replace(/[^a-z0-9._-]/g, '-');
|
|
@@ -164,16 +345,22 @@ export function saveProviderConfig({
|
|
|
164
345
|
writeJsonSafe(authPath, auth);
|
|
165
346
|
}
|
|
166
347
|
|
|
167
|
-
// Update models.json if baseUrl / custom models / custom provider
|
|
348
|
+
// Update models.json if baseUrl / custom models / limits / custom provider / recommended preset models
|
|
168
349
|
const cleanBaseUrl = typeof baseUrl === 'string' ? baseUrl.trim().replace(/\/+$/, '') : '';
|
|
169
350
|
const modelIds = Array.isArray(models)
|
|
170
351
|
? models.map(m => (typeof m === 'string' ? m.trim() : String(m?.id || '').trim())).filter(Boolean)
|
|
171
352
|
: [];
|
|
172
353
|
const chosenModel = String(defaultModel || modelIds[0] || preset?.defaultModel || '').trim();
|
|
354
|
+
const hasExplicitLimits = Boolean(Number(contextWindow) > 0 || Number(maxTokens) > 0 || typeof reasoning === 'boolean');
|
|
173
355
|
|
|
174
|
-
if (cleanBaseUrl || modelIds.length || !preset || preset.keyless || cleanId.startsWith('custom-')) {
|
|
356
|
+
if (cleanBaseUrl || modelIds.length || hasExplicitLimits || chosenModel || !preset || preset.keyless || cleanId.startsWith('custom-')) {
|
|
175
357
|
const cfg = readPiModelsConfig(agentDir);
|
|
176
358
|
const prev = cfg.providers[cleanId] || {};
|
|
359
|
+
const prevById = new Map(
|
|
360
|
+
(Array.isArray(prev.models) ? prev.models : [])
|
|
361
|
+
.filter(m => m && typeof m === 'object' && m.id)
|
|
362
|
+
.map(m => [m.id, m]),
|
|
363
|
+
);
|
|
177
364
|
const resolvedApi = api || prev.api || preset?.api || 'openai-completions';
|
|
178
365
|
const nextEntry = {
|
|
179
366
|
...prev,
|
|
@@ -181,20 +368,36 @@ export function saveProviderConfig({
|
|
|
181
368
|
...(cleanBaseUrl ? { baseUrl: cleanBaseUrl } : prev.baseUrl ? { baseUrl: prev.baseUrl } : preset?.defaultBaseUrl ? { baseUrl: preset.defaultBaseUrl } : {}),
|
|
182
369
|
};
|
|
183
370
|
if (preset?.keyless && !nextEntry.apiKey) nextEntry.apiKey = 'ollama';
|
|
371
|
+
const recommendedIds = (preset?.recommendedModels || []).map(m => m.id);
|
|
184
372
|
const mergedIds = [...new Set([
|
|
185
373
|
...(chosenModel ? [chosenModel] : []),
|
|
186
374
|
...modelIds,
|
|
375
|
+
...recommendedIds,
|
|
187
376
|
...((Array.isArray(prev.models) ? prev.models : []).map(m => (typeof m === 'string' ? m : m?.id)).filter(Boolean)),
|
|
188
377
|
])];
|
|
189
378
|
if (mergedIds.length) {
|
|
190
|
-
nextEntry.models = mergedIds.map(id =>
|
|
191
|
-
id
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
379
|
+
nextEntry.models = mergedIds.map(id => {
|
|
380
|
+
const prevItem = prevById.get(id);
|
|
381
|
+
const recSpec = lookupRecommendedSpec(preset, id);
|
|
382
|
+
const isTarget = id === chosenModel;
|
|
383
|
+
const resolvedCtx = isTarget && Number(contextWindow) > 0
|
|
384
|
+
? clampInt(contextWindow, 4096, 4000000, preset?.defaultContextWindow || 128000)
|
|
385
|
+
: (prevItem?.contextWindow || recSpec?.contextWindow || preset?.defaultContextWindow || 128000);
|
|
386
|
+
const resolvedMaxOut = isTarget && Number(maxTokens) > 0
|
|
387
|
+
? clampInt(maxTokens, 1024, Math.max(4096, resolvedCtx), preset?.defaultMaxTokens || 16384)
|
|
388
|
+
: (prevItem?.maxTokens || recSpec?.maxTokens || preset?.defaultMaxTokens || 16384);
|
|
389
|
+
const resolvedReasoning = isTarget && typeof reasoning === 'boolean'
|
|
390
|
+
? reasoning
|
|
391
|
+
: (typeof prevItem?.reasoning === 'boolean' ? prevItem.reasoning : (typeof recSpec?.reasoning === 'boolean' ? recSpec.reasoning : inferReasoning(id)));
|
|
392
|
+
return {
|
|
393
|
+
id,
|
|
394
|
+
name: recSpec?.label || prevItem?.name || id,
|
|
395
|
+
reasoning: resolvedReasoning,
|
|
396
|
+
input: prevItem?.input || ['text'],
|
|
397
|
+
contextWindow: resolvedCtx,
|
|
398
|
+
maxTokens: resolvedMaxOut,
|
|
399
|
+
};
|
|
400
|
+
});
|
|
198
401
|
}
|
|
199
402
|
cfg.providers[cleanId] = nextEntry;
|
|
200
403
|
writeJsonSafe(modelsPath, cfg);
|
|
@@ -261,13 +464,36 @@ export async function listProvidersAndModels(workspace = process.cwd(), agentDir
|
|
|
261
464
|
const envHasKey = Boolean(preset?.envKey && process.env[preset.envKey]);
|
|
262
465
|
const hasAuth = Boolean(authEntry?.key || authEntry?.access || envHasKey || mr.hasConfiguredAuth(id) || (preset?.keyless && customEntry?.baseUrl));
|
|
263
466
|
const runtimeModels = mr.getModels(id) || [];
|
|
264
|
-
const
|
|
467
|
+
const customModelObjs = Array.isArray(customEntry?.models) ? customEntry.models : [];
|
|
468
|
+
const customById = new Map(customModelObjs.filter(m => m && typeof m === 'object' && m.id).map(m => [m.id, m]));
|
|
469
|
+
const runtimeById = new Map(runtimeModels.map(m => [m.id, m]));
|
|
470
|
+
const customModelIds = customModelObjs.map(m => (typeof m === 'string' ? m : m?.id)).filter(Boolean);
|
|
471
|
+
const recommendedIds = (preset?.recommendedModels || []).map(m => m.id);
|
|
265
472
|
const modelList = [...new Set([
|
|
266
473
|
...customModelIds,
|
|
474
|
+
...recommendedIds,
|
|
267
475
|
...runtimeModels.map(m => m.id),
|
|
268
476
|
...(preset?.defaultModel ? [preset.defaultModel] : []),
|
|
269
477
|
])].slice(0, 40);
|
|
270
478
|
|
|
479
|
+
const activeModelId = (defaultProvider === id && defaultModel)
|
|
480
|
+
? defaultModel
|
|
481
|
+
: (customModelIds[0] || preset?.defaultModel || modelList[0] || '');
|
|
482
|
+
|
|
483
|
+
const resolveSpecs = mId => {
|
|
484
|
+
const cObj = customById.get(mId);
|
|
485
|
+
const rObj = runtimeById.get(mId);
|
|
486
|
+
const rec = lookupRecommendedSpec(preset, mId);
|
|
487
|
+
const ctx = cObj?.contextWindow || rObj?.contextWindow || rec?.contextWindow || preset?.defaultContextWindow || 128000;
|
|
488
|
+
const maxOut = cObj?.maxTokens || rObj?.maxTokens || rec?.maxTokens || preset?.defaultMaxTokens || 16384;
|
|
489
|
+
const reas = typeof cObj?.reasoning === 'boolean'
|
|
490
|
+
? cObj.reasoning
|
|
491
|
+
: (typeof rObj?.reasoning === 'boolean' ? rObj.reasoning : (typeof rec?.reasoning === 'boolean' ? rec.reasoning : inferReasoning(mId)));
|
|
492
|
+
return { contextWindow: ctx, maxTokens: maxOut, reasoning: reas };
|
|
493
|
+
};
|
|
494
|
+
|
|
495
|
+
const activeSpecs = resolveSpecs(activeModelId);
|
|
496
|
+
|
|
271
497
|
providers.push({
|
|
272
498
|
id,
|
|
273
499
|
name: preset?.name || id,
|
|
@@ -278,33 +504,143 @@ export async function listProvidersAndModels(workspace = process.cwd(), agentDir
|
|
|
278
504
|
configured: hasAuth,
|
|
279
505
|
authSource: authEntry?.key ? 'auth.json' : authEntry?.access ? 'oauth' : envHasKey ? 'env' : preset?.keyless && customEntry ? 'local' : '',
|
|
280
506
|
maskedKey: authEntry?.key ? maskSecret(authEntry.key) : '',
|
|
281
|
-
defaultModel:
|
|
507
|
+
defaultModel: activeModelId,
|
|
508
|
+
contextWindow: activeSpecs.contextWindow,
|
|
509
|
+
maxTokens: activeSpecs.maxTokens,
|
|
510
|
+
reasoning: activeSpecs.reasoning,
|
|
511
|
+
recommendedModels: preset?.recommendedModels || [],
|
|
282
512
|
models: modelList,
|
|
283
513
|
});
|
|
284
514
|
|
|
285
515
|
if (hasAuth) {
|
|
286
516
|
for (const mId of modelList.slice(0, 12)) {
|
|
517
|
+
const specs = resolveSpecs(mId);
|
|
287
518
|
configuredModels.push({
|
|
288
519
|
id: `${id}/${mId}`,
|
|
289
520
|
provider: id,
|
|
290
521
|
model: mId,
|
|
291
522
|
label: `${mId}`,
|
|
292
523
|
providerName: preset?.name || id,
|
|
524
|
+
contextWindow: specs.contextWindow,
|
|
525
|
+
maxTokens: specs.maxTokens,
|
|
526
|
+
reasoning: specs.reasoning,
|
|
293
527
|
});
|
|
294
528
|
}
|
|
295
529
|
}
|
|
296
530
|
}
|
|
297
531
|
|
|
532
|
+
const activeEntry = configuredModels.find(m => m.provider === defaultProvider && m.model === defaultModel)
|
|
533
|
+
|| providers.find(p => p.id === defaultProvider)
|
|
534
|
+
|| configuredModels[0]
|
|
535
|
+
|| null;
|
|
536
|
+
|
|
298
537
|
return {
|
|
299
538
|
agentDir,
|
|
300
539
|
defaultProvider,
|
|
301
540
|
defaultModel,
|
|
302
541
|
activeModelLabel: defaultModel || configuredModels[0]?.model || '未配置模型',
|
|
542
|
+
activeContextWindow: activeEntry?.contextWindow || 128000,
|
|
543
|
+
activeMaxTokens: activeEntry?.maxTokens || 16384,
|
|
303
544
|
providers,
|
|
304
545
|
configuredModels,
|
|
305
546
|
};
|
|
306
547
|
}
|
|
307
548
|
|
|
549
|
+
// ============================================================================
|
|
550
|
+
// 1.5 Runtime & Compaction Settings (Pi settings.json + clado-runtime.json)
|
|
551
|
+
// ============================================================================
|
|
552
|
+
|
|
553
|
+
export function readRuntimeSettings(workspace = process.cwd(), agentDir = resolvePiAgentDir(), activeContextWindow = 128000) {
|
|
554
|
+
const sm = SettingsManager.create(workspace, agentDir);
|
|
555
|
+
const sidecar = readJsonSafe(join(agentDir, 'clado-runtime.json'), {});
|
|
556
|
+
const comp = sm.getCompactionSettings();
|
|
557
|
+
const retry = sm.getRetrySettings();
|
|
558
|
+
const thinkingLevel = sm.getDefaultThinkingLevel() || 'medium';
|
|
559
|
+
const transport = sm.getTransport() || 'auto';
|
|
560
|
+
const hideThinkingBlock = Boolean(sm.getHideThinkingBlock());
|
|
561
|
+
const cacheWarming = sm.getCacheWarmingMode() || 'off';
|
|
562
|
+
const keepRecentTokens = clampInt(comp?.keepRecentTokens, 2048, 256000, 20000);
|
|
563
|
+
const reserveTokens = clampInt(comp?.reserveTokens, 4096, 1000000, 16384);
|
|
564
|
+
const inferredPct = activeContextWindow > 0
|
|
565
|
+
? Math.max(50, Math.min(95, Math.round((1 - reserveTokens / activeContextWindow) * 100)))
|
|
566
|
+
: 85;
|
|
567
|
+
const compactionTriggerPercent = typeof sidecar?.compactionTriggerPercent === 'number'
|
|
568
|
+
? Math.max(50, Math.min(95, Math.round(sidecar.compactionTriggerPercent)))
|
|
569
|
+
: inferredPct;
|
|
570
|
+
|
|
571
|
+
return {
|
|
572
|
+
thinkingLevel: THINKING_LEVELS.includes(thinkingLevel) ? thinkingLevel : 'medium',
|
|
573
|
+
transport: TRANSPORT_MODES.includes(transport) ? transport : 'auto',
|
|
574
|
+
hideThinkingBlock,
|
|
575
|
+
compactionEnabled: comp?.enabled !== false,
|
|
576
|
+
compactionTriggerPercent,
|
|
577
|
+
reserveTokens,
|
|
578
|
+
keepRecentTokens,
|
|
579
|
+
retryEnabled: retry?.enabled !== false,
|
|
580
|
+
maxRetries: clampInt(retry?.maxRetries, 0, 10, 3),
|
|
581
|
+
cacheWarming: CACHE_WARMING_MODES.includes(cacheWarming) ? cacheWarming : 'off',
|
|
582
|
+
};
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
export async function saveRuntimeSettings(input = {}, workspace = process.cwd(), agentDir = resolvePiAgentDir(), activeContextWindow = 128000) {
|
|
586
|
+
const sm = SettingsManager.create(workspace, agentDir);
|
|
587
|
+
const settingsPath = join(agentDir, 'settings.json');
|
|
588
|
+
const sidecarPath = join(agentDir, 'clado-runtime.json');
|
|
589
|
+
const current = readRuntimeSettings(workspace, agentDir, activeContextWindow);
|
|
590
|
+
|
|
591
|
+
const thinkingLevel = THINKING_LEVELS.includes(input.thinkingLevel) ? input.thinkingLevel : current.thinkingLevel;
|
|
592
|
+
const transport = TRANSPORT_MODES.includes(input.transport) ? input.transport : current.transport;
|
|
593
|
+
const hideThinkingBlock = typeof input.hideThinkingBlock === 'boolean' ? input.hideThinkingBlock : current.hideThinkingBlock;
|
|
594
|
+
const compactionEnabled = typeof input.compactionEnabled === 'boolean' ? input.compactionEnabled : current.compactionEnabled;
|
|
595
|
+
const compactionTriggerPercent = input.compactionTriggerPercent !== undefined
|
|
596
|
+
? Math.max(50, Math.min(95, Math.round(Number(input.compactionTriggerPercent) || 85)))
|
|
597
|
+
: current.compactionTriggerPercent;
|
|
598
|
+
const keepRecentTokens = input.keepRecentTokens !== undefined
|
|
599
|
+
? clampInt(input.keepRecentTokens, 2048, 256000, current.keepRecentTokens)
|
|
600
|
+
: current.keepRecentTokens;
|
|
601
|
+
const retryEnabled = typeof input.retryEnabled === 'boolean' ? input.retryEnabled : current.retryEnabled;
|
|
602
|
+
const maxRetries = input.maxRetries !== undefined
|
|
603
|
+
? clampInt(input.maxRetries, 0, 10, current.maxRetries)
|
|
604
|
+
: current.maxRetries;
|
|
605
|
+
const cacheWarming = CACHE_WARMING_MODES.includes(input.cacheWarming) ? input.cacheWarming : current.cacheWarming;
|
|
606
|
+
|
|
607
|
+
const ctxWin = clampInt(input.activeContextWindow || activeContextWindow, 8192, 4000000, 128000);
|
|
608
|
+
const reserveTokens = Math.max(4096, Math.round(ctxWin * (1 - compactionTriggerPercent / 100)));
|
|
609
|
+
|
|
610
|
+
// Persist Pi-native fields via SettingsManager + atomic settings.json merge for nested compaction/retry numbers
|
|
611
|
+
sm.setDefaultThinkingLevel(thinkingLevel);
|
|
612
|
+
sm.setTransport(transport);
|
|
613
|
+
sm.setHideThinkingBlock(hideThinkingBlock);
|
|
614
|
+
sm.setCompactionEnabled(compactionEnabled);
|
|
615
|
+
sm.setRetryEnabled(retryEnabled);
|
|
616
|
+
sm.setCacheWarmingMode(cacheWarming);
|
|
617
|
+
await sm.flush();
|
|
618
|
+
|
|
619
|
+
const rawSettings = readJsonSafe(settingsPath, {});
|
|
620
|
+
rawSettings.defaultThinkingLevel = thinkingLevel;
|
|
621
|
+
rawSettings.transport = transport;
|
|
622
|
+
rawSettings.hideThinkingBlock = hideThinkingBlock;
|
|
623
|
+
rawSettings.cacheWarming = cacheWarming;
|
|
624
|
+
rawSettings.compaction = {
|
|
625
|
+
...(rawSettings.compaction && typeof rawSettings.compaction === 'object' ? rawSettings.compaction : {}),
|
|
626
|
+
enabled: compactionEnabled,
|
|
627
|
+
reserveTokens,
|
|
628
|
+
keepRecentTokens,
|
|
629
|
+
};
|
|
630
|
+
rawSettings.retry = {
|
|
631
|
+
...(rawSettings.retry && typeof rawSettings.retry === 'object' ? rawSettings.retry : {}),
|
|
632
|
+
enabled: retryEnabled,
|
|
633
|
+
maxRetries,
|
|
634
|
+
};
|
|
635
|
+
writeJsonSafe(settingsPath, rawSettings);
|
|
636
|
+
|
|
637
|
+
const sidecar = readJsonSafe(sidecarPath, {});
|
|
638
|
+
sidecar.compactionTriggerPercent = compactionTriggerPercent;
|
|
639
|
+
writeJsonSafe(sidecarPath, sidecar);
|
|
640
|
+
|
|
641
|
+
return readRuntimeSettings(workspace, agentDir, ctxWin);
|
|
642
|
+
}
|
|
643
|
+
|
|
308
644
|
// ============================================================================
|
|
309
645
|
// 2. Roles (Built-in 4 Roles + Custom Roles in ~/.pi/agent/clado-roles.json)
|
|
310
646
|
// ============================================================================
|
package/src/html/canvas-chain.js
CHANGED
|
@@ -114,8 +114,24 @@ function canvasChainPrepareTitles() {
|
|
|
114
114
|
title.title = window.__CLADO_CHAIN__ ? '双击或 Enter 聚焦' : '双击或 Enter 聚焦,长按或 Shift+Enter 查看独立链路';
|
|
115
115
|
});
|
|
116
116
|
}
|
|
117
|
+
function canvasChainHasContentMutation(records) {
|
|
118
|
+
for (var i = 0; i < records.length; i++) {
|
|
119
|
+
var t = records[i].target;
|
|
120
|
+
if (!t || !t.closest) continue;
|
|
121
|
+
if (t.id === 'wires' || t.id === 'mwires' || t.closest('#wires,#mwires,.port,.clado-obj')) continue;
|
|
122
|
+
return true;
|
|
123
|
+
}
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
var canvasChainPrepRaf = 0;
|
|
117
127
|
canvasChainPrepareTitles();
|
|
118
|
-
new MutationObserver(
|
|
128
|
+
new MutationObserver(function (records) {
|
|
129
|
+
if (!canvasChainHasContentMutation(records) || canvasChainPrepRaf) return;
|
|
130
|
+
canvasChainPrepRaf = requestAnimationFrame(function () {
|
|
131
|
+
canvasChainPrepRaf = 0;
|
|
132
|
+
canvasChainPrepareTitles();
|
|
133
|
+
});
|
|
134
|
+
}).observe($('#world'), { childList: true, subtree: true });
|
|
119
135
|
document.addEventListener('pointerdown', function (event) {
|
|
120
136
|
if (!event.isPrimary) { canvasChainCancelGesture(true); return; }
|
|
121
137
|
if (window.__CLADO_CHAIN__ || canvasChainIsOpen() || event.button !== 0) return;
|
|
@@ -215,7 +231,15 @@ if (window.__CLADO_CHAIN__) {
|
|
|
215
231
|
} catch (_) {}
|
|
216
232
|
});
|
|
217
233
|
}
|
|
218
|
-
|
|
234
|
+
var chainResRaf = 0;
|
|
235
|
+
chainResources();
|
|
236
|
+
new MutationObserver(function (records) {
|
|
237
|
+
if (!canvasChainHasContentMutation(records) || chainResRaf) return;
|
|
238
|
+
chainResRaf = requestAnimationFrame(function () {
|
|
239
|
+
chainResRaf = 0;
|
|
240
|
+
chainResources();
|
|
241
|
+
});
|
|
242
|
+
}).observe($('#world'), { childList: true, subtree: true });
|
|
219
243
|
// 弹窗对提取出的卡片重新排布。
|
|
220
244
|
if (document.body.dataset.mode === 'cards') {
|
|
221
245
|
openEdge = {}; DOC.edges.forEach(function (edge) { openEdge[edgeKey(edge[0], edge[1])] = 1; });
|
package/src/html/canvas-focus.js
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
// 三视图共用内容 ID、聚焦范围与标题手势。
|
|
2
2
|
var canvasRecords = {}, canvasDocPaths = {}, canvasMindPaths = {}, canvasFocusId = null;
|
|
3
|
-
|
|
3
|
+
var canvasOut = {}, canvasIn = {};
|
|
4
|
+
function canvasRebuildFocusIndex() {
|
|
5
|
+
canvasRecords = {};
|
|
6
|
+
canvasDocPaths = {};
|
|
7
|
+
canvasMindPaths = {};
|
|
8
|
+
canvasOut = {};
|
|
9
|
+
canvasIn = {};
|
|
4
10
|
function add(n, docPath, parent, card) {
|
|
5
11
|
var r = { id: n.id, title: n.title, markdown: n.md, parent: parent, card: card, docPath: docPath, mindPath: '0.' + docPath, kids: [] };
|
|
6
12
|
r.titlePath = parent ? canvasRecords[parent].titlePath.concat(n.title) : [n.title];
|
|
@@ -9,19 +15,19 @@ var canvasRecords = {}, canvasDocPaths = {}, canvasMindPaths = {}, canvasFocusId
|
|
|
9
15
|
(n.nodes || n.kids || []).forEach(function (child, i) { r.kids.push(child.id); add(child, docPath + '.' + i, r.id, card); });
|
|
10
16
|
}
|
|
11
17
|
DOC.cards.forEach(function (card, i) { add(card, String(i), null, card.id); });
|
|
12
|
-
|
|
13
|
-
var
|
|
14
|
-
$$('
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
(canvasIn[target.id] || (canvasIn[target.id] = new Set())).add(source.id);
|
|
18
|
+
$$('#article .slice[data-path]').forEach(function (section) {
|
|
19
|
+
var source = canvasDocPaths[section.dataset.path]; if (!source) return;
|
|
20
|
+
$$('a.edge', section).forEach(function (link) {
|
|
21
|
+
var target = canvasRecords[link.dataset.edge]; if (!target) return;
|
|
22
|
+
if (link.dataset.anchorId) target = canvasRecords[link.dataset.anchorId] || target;
|
|
23
|
+
else if (link.dataset.anchor) target = Object.values(canvasRecords).find(function (r) { return r.card === target.card && r.title === link.dataset.anchor; }) || target;
|
|
24
|
+
if (source.id === target.id) return;
|
|
25
|
+
(canvasOut[source.id] || (canvasOut[source.id] = new Set())).add(target.id);
|
|
26
|
+
(canvasIn[target.id] || (canvasIn[target.id] = new Set())).add(source.id);
|
|
27
|
+
});
|
|
23
28
|
});
|
|
24
|
-
}
|
|
29
|
+
}
|
|
30
|
+
canvasRebuildFocusIndex();
|
|
25
31
|
function canvasFocusSet(selected) {
|
|
26
32
|
if (!selected) return null;
|
|
27
33
|
if (selected === '__document') return new Set(Object.keys(canvasRecords));
|