dsh-architecture-map 0.2.1 → 0.3.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/CHANGELOG.md CHANGED
@@ -1,3 +1,16 @@
1
+ ## 0.3.0 — 2026-11-23
2
+
3
+ ### Added
4
+
5
+ - Optional `node.position: {x, y}` in `graph.json`: a pinned top-left corner that the sidebar canvas and the SVG export honor. `arch_graph_patch` accepts `position` on `add_node`/`update_node`; `update_node` with `position: null` clears a pin; `arch_graph_get` shows the pin.
6
+ - Edge labels on the sidebar canvas; forward edges route straight, return edges bow around the row, and same-row edges detour around a node that blocks the line. Dependency edges are dashed.
7
+ - Width-aware node-title clipping so long CJK titles do not overflow the fixed node box.
8
+ - The SVG export applies pinned positions and shares the canvas routing/labels; Mermaid and Markdown stay position-agnostic.
9
+
10
+ ### Changed
11
+
12
+ - Layout precedence is local drag override > `node.position` pin > automatic layout. `Reset layout` clears local drags and returns to the pin/automatic layout.
13
+
1
14
  ## 0.2.1 — 2026-11-23
2
15
 
3
16
  ### Added
package/README.md CHANGED
@@ -4,7 +4,7 @@ English | [中文](README.zh.md)
4
4
 
5
5
  **中文名:架构地图** · An architecture workbench for DeepSeek Harness: a live semantic architecture graph, per-node side conversations, and incremental architecture memory.
6
6
 
7
- > Status: **0.2.1 developer preview.** The Host tools, sidebar canvas, architecture memory, per-node discussions, deterministic exports, built-in Mermaid rendering and read-only remote Linux repositories over SSH work today. Shared positions remain planned; remote auto-maintenance on an idle parent and pending-counter clearing are the known rough edges.
7
+ > Status: **0.3.0 developer preview.** The Host tools, sidebar canvas, architecture memory, per-node discussions, deterministic exports, built-in Mermaid rendering and read-only remote Linux repositories over SSH work today. Node positions can be pinned in `graph.json` and rendered by the canvas; remote auto-maintenance on an idle parent and pending-counter clearing are the known rough edges.
8
8
 
9
9
  ---
10
10
 
@@ -46,17 +46,17 @@ A static feature preview is included. A recorded 30-second demo GIF is not part
46
46
  ## Features (implemented today)
47
47
 
48
48
  - **Canonical architecture graph** — `.archmap/graph.json` with a revision number, schema validation, atomic writes and a one-step backup. The model reads and edits it through `arch_graph_get` / `arch_graph_patch`; `apply:false` previews without writing.
49
- - **Right-sidebar canvas** — reads the graph from the session workspace, renders nodes/edges as SVG with a layered (longest-path) layout, supports pan, wheel zoom, `Fit`, node dragging and `Reset layout`, and shows node details on click.
50
- - **Local layout memory** — only dragged node positions are kept, per workspace in browser storage; every other node keeps following the automatic layout, so a graph edit reflows it. `Reset layout` clears the local overrides. Shared positions are planned.
49
+ - **Right-sidebar canvas** — reads the graph from the session workspace, renders nodes/edges as SVG with a layered (longest-path) layout, draws edge labels, honors per-node `position` pins, supports pan, wheel zoom, `Fit`, node dragging and `Reset layout`, and shows node details on click.
50
+ - **Layout: pins + local drags** — a node's `position` in `graph.json` is a shared pin (set through `arch_graph_patch`); dragging a node keeps a browser-local override per workspace, so a refresh or a new session on the same machine keeps the view. `Reset layout` drops the local overrides and returns to the pinned/automatic layout.
51
51
  - **Incremental architecture memory with cosmetic detection** — `.archmap/manifest.json` records content hashes plus a normalized code signature; `arch_sync` reports only added/changed/deleted files, distinguishes code changes from format/comment-only changes, and lists the nodes whose anchors are affected. `markStale:true` marks those nodes stale (and bumps the graph rev); the default is report-only. Anchors may also store the file's normalized content signature; sync reports a node whose anchor hash no longer matches, and `arch_graph_patch` fills missing hashes or refreshes them with `refreshAnchors:true` after review. `arch_manifest_commit` records analyzed files, and `arch_doc_get` / `arch_doc_put` read and write `overview`, `modules/<id>` and `notes/<id>`.
52
- - **Deterministic exports** — `arch_export` writes Mermaid flowchart source, a standalone SVG, or a Markdown dossier digest to `.archmap/export/`; graph revision and files stay unchanged.
52
+ - **Deterministic exports** — `arch_export` writes Mermaid flowchart source, a standalone SVG that honors pinned positions, or a Markdown dossier digest to `.archmap/export/`; graph revision and files stay unchanged.
53
53
  - **Built-in Mermaid rendering** — assistant ` ```mermaid ` fences render with a vendored Mermaid 12.2.0 runtime served from the plugin's own Host route. No CDN and no `dsh-mermaid-plus` dependency. Streaming keeps the code block; parse errors fall back to code plus an error line. `renderMermaid: false` disables it.
54
54
  - **Per-node side conversations** — `arch_discuss` starts a child for `node:<id>` or `edge:<id>`: `fork` inherits the main conversation's completed turns; `lite` starts fresh with the graph and dossier. Delivery is caller-only, so the main conversation is not polluted; conclusions go to `notes/<id>`. The node detail also has `Discuss (fork)` / `Lite` buttons that open the child in the right sidebar through the `subagentchat` resource; they pass the selected local or remote source to the host (a remote discussion needs remote content consent). Discussion children are prompt-constrained; shell and generic source-write calls are denied at execution (inherited tool schemas may remain visible in a fork). Graph changes still require approval.
55
55
  - **Remote Linux repositories (developer preview)** — `arch_remote_list/status/tree/read/grep` inspect a registered repository over SSH without cloning it. Content reads are consent-gated; remote `arch_sync`/`arch_manifest_commit` hash only analyzed files; change polling and `/arch remote ...` commands work; the panel switches local/remote sources; graph/dossier stay under `.archmap/projects/<id>/`; remote files are never modified.
56
56
 
57
57
  ## Planned next
58
58
 
59
- - Shared/persisted positions, direct export buttons in the panel, and a short animated demo (GIF).
59
+ - Direct export buttons in the panel, and a short animated demo (GIF).
60
60
  - Remote maintenance polish: start from an idle parent and clear the local pending counter after a run.
61
61
 
62
62
  ## What it is not
@@ -102,7 +102,7 @@ code blocks and the 5.2 MB runtime is not loaded. The default `auto` disables ou
102
102
  All graph, manifest, dossier and export data lives in `<workspace>/.archmap/`. The plugin installation
103
103
  directory contains only code, skill, vendor, docs and locale. The plugin does not modify a user project's
104
104
  `.gitignore`; commit `.archmap/` to share the map, or ignore it for local-only data. Uninstalling the plugin
105
- does not delete `.archmap/`. Node positions are browser-local and are not part of the graph.
105
+ does not delete `.archmap/`. `node.position` pins are part of the graph; dragged positions are browser-local overrides.
106
106
 
107
107
  ## Remote repositories (developer preview)
108
108
 
@@ -211,17 +211,27 @@ There is no separate "start" button or left-sidebar icon. The plugin adds a righ
211
211
  ## Limitations
212
212
 
213
213
  - The sidebar follows the **session workspace**; an explicit tool `workspace` can point at a different graph than the panel shows.
214
- - Node positions are stored in the browser locally, not in `graph.json`.
214
+ - Dragged node positions are browser-local; only `node.position` pins are stored in `graph.json`.
215
215
  - Fork discussions inherit the parent request prefix, so their tool schemas may still show `bash`/`write` even though calls are denied.
216
216
  - A parent-initiated `send_message` to a discussion child produces DSH's native settlement notice (including the child's closing text) in the parent conversation. The initial `arch_discuss` is caller-only and the child's full transcript never enters the main log; use the child's sidebar chat for narrative follow-ups.
217
- - The canvas is hand-written SVG with a layered layout, not React Flow. A cyclic graph falls back to a compact grid; the layered (longest-path) layout is used for acyclic graphs.
217
+ - The canvas is hand-written SVG with a layered layout, not React Flow. A cyclic graph with no `position` pins falls back to a compact grid; pin a layout when the reading order matters.
218
+ - Group metadata appears in the node subtitle/detail; the canvas does not draw group bands or resolve group titles yet (0.4).
218
219
  - Mermaid rendering is on by default (`auto`) but can be disabled with `renderMermaid: off`; a known `dsh-mermaid-plus` installation makes `auto` disable ours.
219
- - This is a 0.2.1 developer preview; the API and file schema can still change.
220
+ - This is a 0.3.0 developer preview; the API and file schema can still change.
220
221
  - Remote repositories are a developer preview: register, read, sync, polling, commands and maintenance are wired and were verified on a real Linux host; auto maintenance on an idle parent and pending-counter clearing remain rough edges.
221
222
 
222
223
  ## FAQ
223
224
 
224
- **Do I need `dsh-mermaid-plus`?** No. Mermaid 12.2.0 is vendored. With `dsh-mermaid-plus` enabled,
225
+ **How do I pin a layout?** Give a node a top-left corner in the graph:
226
+
227
+ ```json
228
+ { "op": "update_node", "id": "api", "patch": { "position": { "x": 120, "y": 40 } } }
229
+ ```
230
+
231
+ Unpinned nodes keep the automatic layout; `position: null` clears a pin. Dragging in the panel is a
232
+ browser-local override on top of the pins, and `Reset layout` drops the override.
233
+
234
+ **Do I need `dsh-mermaid-plus`? No. Mermaid 12.2.0 is vendored. With `dsh-mermaid-plus` enabled,
225
235
  `renderMermaid: auto` disables our renderer to avoid the shared `mermaid` fence key; `on` forces ours.
226
236
 
227
237
  **Why hand-written SVG instead of React Flow?** It keeps the client bundle self-contained and avoids a
@@ -251,7 +261,7 @@ session workspace by design. Open a session whose workspace is the graph you wan
251
261
  |---|---|
252
262
  | 0.1 | graph core and tools, sidebar canvas, node dragging, local position memory, `arch_sync` + manifest + dossier docs, cosmetic diff + stale marking, bundled architecture skill, `arch_discuss`, sidebar discussion buttons, `arch_export`, built-in Mermaid fence rendering |
253
263
  | 0.2 | read-only remote Linux repositories over SSH (source picker, consent, 60s polling, sync/commands, maintenance), release polish |
254
- | 0.3 | direct node→discussion bridge, shared/persisted positions, proposals, graph diff |
264
+ | 0.3 | direct node→discussion bridge, position pins, edge labels/routing, export pins, proposals, graph diff |
255
265
  | 0.4 | edge discussions, group collapse, Mermaid import, Office export |
256
266
  | 0.5 | multiple graphs, PR links, shared team maps |
257
267
  | 0.6 | multiple remote repositories in parallel, remote sharing/export polish |
package/README.zh.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  **DeepSeek Harness 的架构工作台:可交互的语义架构图、按节点开启的侧栏子对话、增量架构记忆。**
6
6
 
7
- > 状态:**0.2.1 开发者预览**。Host 工具、右侧栏画布、架构记忆、按节点子对话、确定性导出、内置 Mermaid 渲染和通过 SSH 只读查看远程 Linux 仓库都已可用;共享位置仍待实现,空闲父会话自动维护和 pending 清零是已知粗糙边缘。
7
+ > 状态:**0.3.0 开发者预览**。Host 工具、右侧栏画布、架构记忆、按节点子对话、确定性导出、内置 Mermaid 渲染和通过 SSH 只读查看远程 Linux 仓库都已可用;节点位置可以 pin 进 `graph.json` 并由画布渲染;空闲父会话自动维护和 pending 清零是已知粗糙边缘。
8
8
 
9
9
  ---
10
10
 
@@ -46,17 +46,17 @@ Architecture map 把「项目架构」变成 harness 里**可寻址的一等对
46
46
  ## 已实现
47
47
 
48
48
  - **Canonical 架构图**:`.archmap/graph.json`,带 rev、schema 校验、原子写入和单步备份。模型通过 `arch_graph_get` / `arch_graph_patch` 读写;`apply:false` 只预览不写入。
49
- - **右侧栏画布**:从当前会话 workspace 读取图,SVG 渲染节点/边,使用 longest-path 分层布局,支持平移、滚轮缩放、`Fit`、节点拖拽、`Reset layout`,点击节点看详情。
50
- - **位置本地记忆**:只保留拖动过的节点位置,按 workspace 存在浏览器本地;其余节点继续跟随自动布局,图变化后会重新分层。`Reset layout` 清掉本地覆盖。共享位置是后续计划。
49
+ - **右侧栏画布**:从当前会话 workspace 读取图,SVG 渲染节点/边和边标签,使用 longest-path 分层布局,优先采用节点 `position` pin,支持平移、滚轮缩放、`Fit`、节点拖拽、`Reset layout`,点击节点看详情。
50
+ - **位置:pin + 本地拖拽**:`graph.json` 里的 `position` 是共享布局(通过 `arch_graph_patch` 写入);拖动节点只在浏览器本地按 workspace 覆盖,刷新或同机新会话会保留;`Reset layout` 清掉本地覆盖,回到 pin/自动布局。
51
51
  - **增量架构记忆 + 格式改动识别**:`.archmap/manifest.json` 记录 hash 和归一化代码签名;`arch_sync` 只报告新增/修改/删除文件,区分代码改动和仅格式/注释改动,并列出受影响节点;`markStale:true` 会把这些节点标成 stale 并递增 graph rev,默认只报告不写图;anchor 还可以存文件的归一化内容签名,sync 会发现 hash 不匹配的节点,复盘后用 `arch_graph_patch` 的 `refreshAnchors:true` 刷新;`arch_manifest_commit` 记录已分析文件;`arch_doc_get` / `arch_doc_put` 读写 `overview`、`modules/<id>`、`notes/<id>`。
52
- - **确定性导出**:`arch_export` 把 Mermaid flowchart、独立 SVG 或 Markdown 档案摘要写到 `.archmap/export/`;不改变 graph rev,也不改源文件。
52
+ - **确定性导出**:`arch_export` 把 Mermaid flowchart、独立 SVG(跟随 `position` pin)或 Markdown 档案摘要写到 `.archmap/export/`;不改变 graph rev,也不改源文件。
53
53
  - **内置 Mermaid 渲染**:assistant 消息里的 ` ```mermaid ` 块用 vendored Mermaid 12.2.0 渲染,runtime 由本插件 Host 路由提供,不依赖 CDN,也不依赖 `dsh-mermaid-plus`。流式时保留代码块,语法错误回退代码块 + 错误行;`renderMermaid:false` 可关闭。
54
54
  - **按节点子对话**:`arch_discuss` 为 `node:<id>` 或 `edge:<id>` 开子会话;`fork` 继承主对话已完成轮次,`lite` 只靠图和档案。结果只走 caller,不污染主对话;结论写进 `notes/<id>`。节点详情里还有 `Discuss (fork)` / `Lite` 按钮,通过 `subagentchat` resource 在右侧栏打开子会话;按钮会把当前选中的本地/远程来源传给 Host(远程讨论需要远程内容授权)。子会话受提示词约束;shell 和通用源码写调用在执行时会被拒绝(fork 可能仍显示继承的工具 schema);改图仍需你确认。
55
55
  - **远程 Linux 仓库(开发者预览)**:`arch_remote_list/status/tree/read/grep` 通过 SSH 查看已登记仓库,不 clone;读内容前要授权,远程 `arch_sync`/`arch_manifest_commit` 只哈希已分析文件,变更轮询和 `/arch remote ...` 命令可用,面板可切换本地/远程来源,图和档案留在 `.archmap/projects/<id>/`,远程文件不被修改。
56
56
 
57
57
  ## 下一步计划
58
58
 
59
- - 位置共享/写回图数据、右侧栏导出按钮、短视频演示(GIF)。
59
+ - 右侧栏导出按钮、短视频演示(GIF)。
60
60
  - 远程维护打磨:空闲父会话自动启动,维护后清零本地 pending。
61
61
 
62
62
  ## 不是什么
@@ -84,7 +84,7 @@ Architecture map 把「项目架构」变成 harness 里**可寻址的一等对
84
84
 
85
85
  架构图、manifest、档案和导出都在 `<workspace>/.archmap/`;插件安装目录只有代码、skill、vendor、文档和 locale。
86
86
  插件不会修改用户项目的 `.gitignore`;想共享就提交 `.archmap/`,想只留本地就自己忽略。卸载插件不会删除
87
- `.archmap/`。节点位置只存在浏览器本地,不属于图数据。
87
+ `.archmap/`。`node.position` pin 属于图数据;拖动位置只是浏览器本地覆盖。
88
88
 
89
89
  ## 远程仓库(开发者预览)
90
90
 
@@ -176,12 +176,13 @@ npm pack --dry-run
176
176
  ## 限制
177
177
 
178
178
  - 右侧栏跟随**会话 workspace**;工具参数里的显式 `workspace` 可能和面板显示的图不同。
179
- - 节点位置只存在浏览器本地,不在 `graph.json`。
179
+ - 拖动的节点位置只存在浏览器本地;只有 `node.position` pin 写进 `graph.json`。
180
180
  - fork 讨论继承父对话 request prefix,工具列表里可能仍显示 `bash`/`write`,但执行层会拒绝。
181
181
  - 父对话主动 `send_message` 给讨论子会话时,DSH 会在主对话里投递 native settlement notice(含子会话 closing text)。初次 `arch_discuss` 是 caller-only,子会话完整 transcript 不会进主日志;需要继续聊请在子会话侧栏里发。
182
- - 画布是手写 SVG + 分层布局,不是 React Flow。带环的图会退化为紧凑网格;分层布局用于无环图。
182
+ - 画布是手写 SVG + 分层布局,不是 React Flow。带环且没有 `position` pin 的图会退化为紧凑网格;在意阅读顺序时请 pin 布局。
183
+ - 分组只以节点副标题/详情显示;画布不画分组带,也不解析分组标题(0.4)。
183
184
  - Mermaid 默认 `auto` 开启;`renderMermaid: off` 可关;检测到已知的 `dsh-mermaid-plus` 时 `auto` 会关闭本插件渲染。
184
- - 这是 0.2.1 开发者预览,API 和文件 schema 仍可能变化。
185
+ - 这是 0.3.0 开发者预览,API 和文件 schema 仍可能变化。
185
186
  - 远程仓库是开发者预览:登记、读取、同步、轮询、命令和维护都已接上,并在真实 Linux 主机上验收;空闲父会话的自动维护和 pending 清零仍是粗糙边缘。
186
187
 
187
188
  ## 安装
@@ -203,6 +204,15 @@ npm pack --dry-run
203
204
 
204
205
  ## 常见问题
205
206
 
207
+ **怎么 pin 布局?** 给节点一个左上角坐标:
208
+
209
+ ```json
210
+ { "op": "update_node", "id": "api", "patch": { "position": { "x": 120, "y": 40 } } }
211
+ ```
212
+
213
+ 未 pin 的节点继续走自动布局;`position: null` 清除 pin。面板里拖动是叠加在 pin 之上的浏览器本地覆盖,
214
+ `Reset layout` 只清本地覆盖。
215
+
206
216
  **需要 `dsh-mermaid-plus` 吗?** 不需要,Mermaid 12.2.0 已 vendored。如果启用了 `dsh-mermaid-plus`,
207
217
  `renderMermaid: auto` 会关闭本插件渲染,避免共用 `mermaid` fence key;`on` 强制开启本插件。
208
218
 
@@ -233,7 +243,7 @@ React Flow 仍可作为后续可选升级。
233
243
  |---|---|
234
244
  | 0.1 | 图核心与工具、右侧栏画布、节点拖拽、位置本地记忆、`arch_sync` + manifest + dossier、格式改动识别 + stale、内置 architecture skill、`arch_discuss`、右侧栏讨论按钮、`arch_export`、内置 Mermaid fence 渲染 |
235
245
  | 0.2 | 通过 SSH 只读查看远程 Linux 仓库(来源选择、授权、60 秒轮询、sync/命令、维护)+ 发布打磨 |
236
- | 0.3 | 节点直连讨论、位置共享/写回图、提案、图 diff |
246
+ | 0.3 | 节点直连讨论、位置 pin、边标签/路由、导出 pin、提案、图 diff |
237
247
  | 0.4 | 边讨论、分组折叠、Mermaid 导入、Office 导出 |
238
248
  | 0.5 | 多图、PR 关联、团队共享 |
239
249
  | 0.6 | 多远程仓库并行、远程共享/导出打磨 |
package/client.js CHANGED
@@ -244,6 +244,20 @@ window.__ModuleLoader__.load({
244
244
  return value.length <= max ? value : `${value.slice(0, max - 1)}…`
245
245
  }
246
246
 
247
+ /** Clip to a pixel budget (CJK counts as a full em, ASCII as ~0.58 em). */
248
+ function clipWidth(text, maxWidth, fontSize = 13) {
249
+ const value = String(text ?? '')
250
+ let width = 0
251
+ let out = ''
252
+ for (const char of value) {
253
+ const charWidth = char.charCodeAt(0) > 255 ? fontSize : fontSize * 0.58
254
+ if (width + charWidth > maxWidth - fontSize) return `${out}…`
255
+ out += char
256
+ width += charWidth
257
+ }
258
+ return out
259
+ }
260
+
247
261
  /**
248
262
  * A local drag only replaces the x/y of the automatic layout box; width,
249
263
  * height and every undragged node still come from the layout.
@@ -489,8 +503,9 @@ window.__ModuleLoader__.load({
489
503
  /**
490
504
  * Layered layout: longest-path levels for a DAG. Cyclic graphs fall back to
491
505
  * the grid so a bad edge cannot collapse the canvas into one column.
506
+ * Pinned `node.position` values are applied afterwards by `layout`.
492
507
  */
493
- function layout(graph) {
508
+ function autoLayout(graph) {
494
509
  const nodes = Array.isArray(graph?.nodes) ? graph.nodes : []
495
510
  if (nodes.length === 0) return { positions: new Map(), width: 0, height: 96 }
496
511
  const ids = new Set(nodes.map(node => node.id))
@@ -552,6 +567,126 @@ window.__ModuleLoader__.load({
552
567
  return { positions, width, height }
553
568
  }
554
569
 
570
+ function pinnedPosition(node) {
571
+ const position = node?.position
572
+ if (!position || !Number.isFinite(position.x) || !Number.isFinite(position.y)) return null
573
+ return { x: position.x, y: position.y }
574
+ }
575
+
576
+ /**
577
+ * Automatic layout with optional manual pins. A node with a finite
578
+ * `position` keeps that top-left corner; everything else is placed by the
579
+ * layered/grid fallback. Local drags still override both in the panel.
580
+ */
581
+ function layout(graph) {
582
+ const view = autoLayout(graph)
583
+ const nodes = Array.isArray(graph?.nodes) ? graph.nodes : []
584
+ let width = view.width
585
+ let height = view.height
586
+ let pinned = 0
587
+ for (const node of nodes) {
588
+ const position = pinnedPosition(node)
589
+ if (!position) continue
590
+ const base = view.positions.get(node.id) ?? { x: 0, y: 0, w: 196, h: 64 }
591
+ const box = { ...base, x: position.x, y: position.y }
592
+ view.positions.set(node.id, box)
593
+ pinned += 1
594
+ width = Math.max(width, box.x + box.w + 24)
595
+ height = Math.max(height, box.y + box.h + 24)
596
+ }
597
+ return { positions: view.positions, width, height, pinned }
598
+ }
599
+
600
+ /**
601
+ * Straight or curved edge geometry. Forward edges leave the right side and
602
+ * enter the left side; backward edges leave the left side and enter the
603
+ * right side as return paths. Same-row forward edges detour around a node
604
+ * that blocks the straight line.
605
+ */
606
+ function edgeRoute(from, to, boxes = []) {
607
+ const fx = from.x + from.w / 2
608
+ const fy = from.y + from.h / 2
609
+ const tx = to.x + to.w / 2
610
+ const ty = to.y + to.h / 2
611
+ const dx = tx - fx
612
+ const dy = ty - fy
613
+ const horizontal = Math.abs(dx) >= (from.w + to.w) / 2 - 8
614
+ if (horizontal && dx >= 0) {
615
+ const start = { x: from.x + from.w, y: fy }
616
+ const end = { x: to.x, y: ty }
617
+ // Same-row edges can be blocked by a node between the two boxes. Route
618
+ // above or below the blocker instead of drawing through its title.
619
+ const blockers = Math.abs(dy) > 4 ? [] : boxes.filter(box => {
620
+ if (box === from || box === to) return false
621
+ return box.x < end.x
622
+ && box.x + box.w > start.x
623
+ && box.y < fy
624
+ && box.y + box.h > fy
625
+ })
626
+ if (blockers.length > 0) {
627
+ const top = Math.min(fy, ...blockers.map(box => box.y)) - 26
628
+ const bottom = Math.max(fy, ...blockers.map(box => box.y + box.h)) + 18
629
+ const lane = top >= 12 && fy - top <= bottom - fy ? top : bottom
630
+ const inner = 10
631
+ const d = [
632
+ `M ${start.x} ${start.y}`,
633
+ `L ${start.x + inner} ${start.y}`,
634
+ `L ${start.x + inner} ${lane}`,
635
+ `L ${end.x - inner} ${lane}`,
636
+ `L ${end.x - inner} ${end.y}`,
637
+ `L ${end.x} ${end.y}`,
638
+ ].join(' ')
639
+ return {
640
+ d,
641
+ label: { x: (start.x + end.x) / 2, y: lane - 7 },
642
+ }
643
+ }
644
+ return {
645
+ d: `M ${start.x} ${start.y} L ${end.x} ${end.y}`,
646
+ label: { x: (start.x + end.x) / 2, y: (start.y + end.y) / 2 - 7 },
647
+ gap: to.x - (from.x + from.w),
648
+ above: Math.max(12, Math.min(from.y, to.y) - 12),
649
+ }
650
+ }
651
+ if (horizontal) {
652
+ const start = { x: from.x, y: fy }
653
+ const end = { x: to.x + to.w, y: ty }
654
+ const bow = 70 + Math.min(60, Math.abs(dx) * 0.08)
655
+ // A diagonal return edge should pass between the two rows, not dip
656
+ // through whatever sits below the target row.
657
+ const controlY = Math.abs(dy) < 24
658
+ ? Math.max(start.y, end.y) + bow
659
+ : (start.y + end.y) / 2
660
+ const control = { x: (start.x + end.x) / 2, y: controlY }
661
+ return {
662
+ d: `M ${start.x} ${start.y} Q ${control.x} ${control.y} ${end.x} ${end.y}`,
663
+ label: {
664
+ x: 0.25 * start.x + 0.5 * control.x + 0.25 * end.x,
665
+ y: 0.25 * start.y + 0.5 * control.y + 0.25 * end.y,
666
+ },
667
+ }
668
+ }
669
+ const start = { x: fx, y: dy >= 0 ? from.y + from.h : from.y }
670
+ const end = { x: tx, y: dy >= 0 ? to.y : to.y + to.h }
671
+ return {
672
+ d: `M ${start.x} ${start.y} L ${end.x} ${end.y}`,
673
+ label: { x: (start.x + end.x) / 2, y: (start.y + end.y) / 2 - 7 },
674
+ }
675
+ }
676
+
677
+ function edgeLabelWidth(text) {
678
+ let width = 0
679
+ for (const char of text) width += char.charCodeAt(0) > 255 ? 10 : 6
680
+ return width + 10
681
+ }
682
+
683
+ function edgeStyle(kind) {
684
+ if (kind === 'dependency') return { width: 1.2, opacity: 0.45, dash: '4 3' }
685
+ if (kind === 'containment') return { width: 1.2, opacity: 0.4, dash: '1 4' }
686
+ if (kind === 'data') return { width: 1.3, opacity: 0.5 }
687
+ return { width: 1.4, opacity: 0.6 }
688
+ }
689
+
555
690
  function readAll(ctx, sessionId, filePath, signal) {
556
691
  return (async () => {
557
692
  let offset = 1
@@ -596,7 +731,7 @@ window.__ModuleLoader__.load({
596
731
  }),
597
732
  h('text', {
598
733
  x: x + 12, y: y + 24, fill: 'currentColor', fontSize: 13, fontWeight: 600,
599
- }, clip(node.title ?? node.id, 22)),
734
+ }, clipWidth(node.title ?? node.id, 170)),
600
735
  h('text', {
601
736
  x: x + 12, y: y + 44, fill: 'currentColor', fontSize: 11, opacity: 0.65,
602
737
  }, `${node.kind ?? 'module'}${node.group ? ` · ${node.group}` : ''}${node.status === 'stale' ? ` · ${t('legend.stale')}` : ''}`),
@@ -752,7 +887,8 @@ window.__ModuleLoader__.load({
752
887
  ? edges.filter(edge => edge.from === selected.id || edge.to === selected.id)
753
888
  : []
754
889
  const layoutView = layout(graph)
755
- // positions only holds local drag overrides; the automatic layout stays the base.
890
+ // Local drags are overrides on top of the graph's own (possibly pinned)
891
+ // positions. Keeping only x/y here means a graph repin still shows up.
756
892
  const positionOf = id => overlayPosition(layoutView.positions.get(id), positions[id])
757
893
 
758
894
  const fitBoxes = boxes => {
@@ -969,11 +1105,18 @@ window.__ModuleLoader__.load({
969
1105
  type: 'button',
970
1106
  style: styles.button,
971
1107
  onClick: resetLayout,
972
- title: 'Reset node positions to the automatic layout',
1108
+ title: 'Clear local drags and return to the pinned or automatic layout',
973
1109
  }, t('panel.reset')),
974
1110
  h('span', { style: styles.meta }, `${Math.round(view.zoom * 100)}%`),
975
1111
  h('span', { style: { ...styles.meta, opacity: 0.55 } }, t('panel.hint')))
976
1112
 
1113
+ const boxes = nodes.map(node => positionOf(node.id)).filter(Boolean)
1114
+ const edgeViews = edges.flatMap(edge => {
1115
+ const from = positionOf(edge.from)
1116
+ const to = positionOf(edge.to)
1117
+ return from && to ? [{ edge, route: edgeRoute(from, to, boxes) }] : []
1118
+ })
1119
+
977
1120
  const canvas = nodes.length === 0
978
1121
  ? h('div', { style: styles.empty },
979
1122
  h('div', { style: { fontWeight: 600, marginBottom: '6px' } },
@@ -1008,17 +1151,17 @@ window.__ModuleLoader__.load({
1008
1151
  orient: 'auto-start-reverse',
1009
1152
  }, h('path', { d: 'M 0 0 L 10 5 L 0 10 z', fill: 'var(--dsw-alias-text-secondary, #888)' }))),
1010
1153
  h('g', { transform: `translate(${view.x} ${view.y}) scale(${view.zoom})` },
1011
- edges.map(edge => {
1012
- const from = positionOf(edge.from)
1013
- const to = positionOf(edge.to)
1014
- if (!from || !to) return null
1015
- return h('line', {
1154
+ edgeViews.map(({ edge, route }) => {
1155
+ const style = edgeStyle(edge.kind)
1156
+ return h('path', {
1016
1157
  key: `edge:${edge.id}`,
1017
- x1: from.x + from.w, y1: from.y + from.h / 2,
1018
- x2: to.x, y2: to.y + to.h / 2,
1158
+ d: route.d,
1159
+ fill: 'none',
1019
1160
  stroke: 'var(--dsw-alias-text-secondary, #888)',
1020
- strokeWidth: 1.2,
1021
- strokeOpacity: 0.6,
1161
+ strokeWidth: style.width,
1162
+ strokeOpacity: style.opacity,
1163
+ strokeDasharray: style.dash,
1164
+ strokeLinecap: 'round',
1022
1165
  markerEnd: 'url(#archmap-arrow)',
1023
1166
  })
1024
1167
  }),
@@ -1032,6 +1175,30 @@ window.__ModuleLoader__.load({
1032
1175
  })
1033
1176
  : null
1034
1177
  }),
1178
+ edgeViews.map(({ edge, route }) => {
1179
+ const label = clip(edge.label, 24).trim()
1180
+ if (!label) return null
1181
+ const width = edgeLabelWidth(label)
1182
+ const tight = route.gap !== undefined && width + 6 > route.gap
1183
+ const labelY = tight ? route.above : route.label.y
1184
+ return h('g', { key: `label:${edge.id}`, style: { pointerEvents: 'none' } },
1185
+ h('rect', {
1186
+ x: route.label.x - width / 2,
1187
+ y: labelY - 9,
1188
+ width,
1189
+ height: 15,
1190
+ rx: 3,
1191
+ fill: 'var(--dsw-alias-bg-primary, #ffffff)',
1192
+ opacity: 0.9,
1193
+ }),
1194
+ h('text', {
1195
+ x: route.label.x,
1196
+ y: labelY + 2,
1197
+ textAnchor: 'middle',
1198
+ fontSize: 10.5,
1199
+ fill: 'var(--dsw-alias-text-secondary, #888)',
1200
+ }, label))
1201
+ }),
1035
1202
  ),
1036
1203
  )
1037
1204
 
package/docs/DETAIL.md CHANGED
@@ -7,10 +7,10 @@ A live, addressable architecture graph for DeepSeek Harness. The model writes no
7
7
  ## What you get
8
8
 
9
9
  - **Canonical graph** — `.archmap/graph.json` with a revision, schema validation, atomic writes and a one-step backup.
10
- - **Right-sidebar canvas** — layered SVG layout, pan/zoom/Fit, node dragging, reset layout and node details.
10
+ - **Right-sidebar canvas** — layered SVG layout with edge labels, `node.position` pins, pan/zoom/Fit, node dragging, reset layout and node details.
11
11
  - **Architecture memory** — a manifest of analyzed files, incremental `arch_sync`, code-vs-cosmetic detection, stale marking and a Markdown dossier (`overview`, `modules/<id>`, `notes/<id>`).
12
12
  - **Per-node discussions** — `arch_discuss` starts a fork (inherits completed turns) or lite (fresh from graph/dossier) child; the sidebar opens it; conclusions go to `notes/<id>`. The sidebar's Discuss/Lite buttons pass the selected local or remote source; a remote discussion requires remote content consent.
13
- - **Exports** — deterministic Mermaid, SVG and Markdown files under `.archmap/export/`.
13
+ - **Exports** — deterministic Mermaid, SVG (pinned positions honored) and Markdown files under `.archmap/export/`.
14
14
  - **Built-in Mermaid** — assistant ` ```mermaid ` fences render with a vendored runtime served by the plugin; no CDN and no extra Mermaid plugin.
15
15
  - **Bundled skill** — `architecture-map` explains the sync → read → patch → dossier → commit loop.
16
16
  - **Remote Linux repositories (developer preview)** — register a repository over SSH without cloning; the panel switches local/remote sources, content reads are consent-gated, and a 60-second fingerprint poll marks affected nodes stale while the graph/dossier stay local.
@@ -48,7 +48,7 @@ The model can also use the bundled `architecture-map` skill in a new session.
48
48
 
49
49
  ## Data and permissions
50
50
 
51
- - Reads/writes local state only under `<workspace>/.archmap/` (plus the browser's local position preference).
51
+ - Reads/writes local state only under `<workspace>/.archmap/` (plus the browser's local drag overrides).
52
52
  - No telemetry and no external network requests; Mermaid is served from the plugin's own Host route.
53
53
  - Graph/dossier writes are bounded and atomic; source files are never edited by `arch_graph_patch` or `arch_doc_put`.
54
54
  - Discussion children are prompt-constrained; shell and generic source-write calls are denied at execution (a fork may still display inherited tool schemas).
@@ -57,8 +57,9 @@ The model can also use the bundled `architecture-map` skill in a new session.
57
57
 
58
58
  ## Known limitations
59
59
 
60
- - The canvas is a hand-written SVG implementation, not React Flow.
61
- - Dragged node positions are local to the browser; shared positions are not implemented yet. A cyclic graph falls back to a compact grid; the layered layout is for acyclic graphs.
60
+ - The canvas is a hand-written SVG implementation, not React Flow. A cyclic graph without `position` pins falls back to a compact grid; pin a layout when the reading order matters.
61
+ - Group metadata appears in the node subtitle/detail; the canvas does not draw group bands or resolve group titles yet (0.4).
62
+ - Dragged node positions are local to the browser; `node.position` pins are stored in the graph.
62
63
  - The sidebar follows the **session workspace**; it does not show a graph from an explicit `workspace` argument when the two differ.
63
64
  - Fork discussions inherit the parent request prefix, so their tool list can still show schemas that are denied at execution.
64
65
  - If the parent agent uses `send_message` to continue a child, DSH posts a native settlement notice (with the child's closing text) in the parent conversation. The initial `arch_discuss` result is caller-only; the child transcript is not copied into the main log.
@@ -73,4 +74,4 @@ The model can also use the bundled `architecture-map` skill in a new session.
73
74
 
74
75
  ## Status
75
76
 
76
- 0.2.1 developer preview. `npm test` covers graph, layout override, memory, stale-hash, export, remote content/SSH, consent, sync, polling, commands and maintenance policy (68 tests); CI runs syntax checks, tests and `npm pack --dry-run`.
77
+ 0.3.0 developer preview. `npm test` covers graph validation and positions, layout pins and edge routing, memory, stale-hash, export, remote content/SSH, consent, sync, polling, commands and maintenance policy (77 tests); CI runs syntax checks, tests and `npm pack --dry-run`.
package/docs/DETAIL.zh.md CHANGED
@@ -7,10 +7,10 @@
7
7
  ## 功能
8
8
 
9
9
  - **Canonical 图**:`.archmap/graph.json`,带 rev、schema 校验、原子写入和单步备份。
10
- - **右侧栏画布**:分层 SVG 布局、平移/缩放/Fit、节点拖拽、Reset layout、节点详情。
10
+ - **右侧栏画布**:分层 SVG 布局、边标签、`node.position` pin、平移/缩放/Fit、节点拖拽、Reset layout、节点详情。
11
11
  - **架构记忆**:manifest、增量 `arch_sync`、代码/格式改动识别、stale 标记和 Markdown dossier(`overview`、`modules/<id>`、`notes/<id>`)。
12
12
  - **按节点讨论**:`arch_discuss` 开 fork(继承已完成轮次)或 lite(只靠图和档案);侧栏打开子会话;结论写到 `notes/<id>`。面板的 Discuss/Lite 会把当前选中的本地/远程来源传给 Host;远程讨论需要远程内容授权。
13
- - **导出**:确定性的 Mermaid、SVG、Markdown,落在 `.archmap/export/`。
13
+ - **导出**:确定性的 Mermaid、SVG(跟随 position pin)、Markdown,落在 `.archmap/export/`。
14
14
  - **内置 Mermaid**:assistant 消息里的 ` ```mermaid ` 用本插件自带的 runtime 渲染,不访问 CDN,不依赖额外 Mermaid 插件。
15
15
  - **随包 skill**:`architecture-map` 指导 sync → 读变更 → 改图 → 档案 → commit 的循环。
16
16
  - **远程 Linux 仓库(开发者预览)**:通过 SSH 登记仓库,不 clone;面板可切换本地/远程来源,读内容前要授权;60 秒指纹轮询把受影响节点标 stale,图和档案留在本地。
@@ -48,7 +48,7 @@
48
48
 
49
49
  ## 数据与权限
50
50
 
51
- - 本地状态只读写 `<workspace>/.archmap/`(以及浏览器本地的节点位置偏好)。
51
+ - 本地状态只读写 `<workspace>/.archmap/`(以及浏览器本地的拖拽覆盖)。
52
52
  - 无遥测、无外部网络请求;Mermaid 由插件自己的 Host 路由提供。
53
53
  - 图和档案写入有上限、原子落盘;`arch_graph_patch` / `arch_doc_put` 不修改源码。
54
54
  - 讨论子会话受提示词约束;shell 和通用源码写调用在执行层被拒绝(fork 可能仍显示继承的工具 schema)。
@@ -57,8 +57,9 @@
57
57
 
58
58
  ## 已知限制
59
59
 
60
- - 画布是手写 SVG,不是 React Flow。
61
- - 拖动的节点位置只存在浏览器本地;共享位置还没做。带环的图会退化为紧凑网格;分层布局用于无环图。
60
+ - 画布是手写 SVG,不是 React Flow。带环且没有 `position` pin 的图会退化为紧凑网格;在意阅读顺序时请 pin 布局。
61
+ - 分组只以节点副标题/详情显示;画布不画分组带,也不解析分组标题(0.4)。
62
+ - 拖动的节点位置只存在浏览器本地;`node.position` pin 存在图里。
62
63
  - 右侧栏跟随**会话 workspace**;工具参数里的显式 `workspace` 不同时,面板不会显示那张图。
63
64
  - fork 讨论会继承父对话 request prefix,工具列表里可能仍显示执行层已拒绝的 schema。
64
65
  - 父 agent 用 `send_message` 继续子会话时,DSH 会在主对话里投递 settlement notice(含子会话 closing text);初次 `arch_discuss` 是 caller-only,子会话 transcript 不会复制进主日志。
@@ -73,4 +74,4 @@
73
74
 
74
75
  ## 状态
75
76
 
76
- 0.2.1 开发者预览。`npm test` 覆盖图、布局覆盖层、记忆、stale-hash、导出、远程内容/SSH、授权、同步、轮询、命令和维护策略(68 个测试);CI 跑语法检查、测试和 `npm pack --dry-run`。
77
+ 0.3.0 开发者预览。`npm test` 覆盖图校验与位置、布局 pin 与连线路由、记忆、stale-hash、导出、远程内容/SSH、授权、同步、轮询、命令和维护策略(77 个测试);CI 跑语法检查、测试和 `npm pack --dry-run`。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-architecture-map",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
4
4
  "description": "Architecture map for DeepSeek Harness: a semantic architecture graph with per-node side conversations, incremental architecture memory and read-only remote repositories over SSH.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -30,6 +30,7 @@ All data lives under `<workspace>/.archmap/`. Do not invent another store.
30
30
  "group": "g-core",
31
31
  "summary": "User request enters the agent and dispatches tools.",
32
32
  "status": "fresh",
33
+ "position": { "x": 40, "y": 40 },
33
34
  "anchors": [{ "path": "src/host/plugin.js", "symbol": "apply" }]
34
35
  }
35
36
  ],
@@ -44,8 +45,9 @@ All data lives under `<workspace>/.archmap/`. Do not invent another store.
44
45
  - **status**: `fresh`, `stale`, `proposed`.
45
46
  - **anchor**: workspace-relative POSIX `path`, optional `symbol`, optional `hash` (the normalized content signature: comments/whitespace ignored for code); no `..`, absolute paths, backslashes or empty segments. `arch_graph_patch` fills a missing hash from disk and preserves an existing hash unless `refreshAnchors:true` is passed.
46
47
  - **group**: optional group id; groups have `id` and `title`.
48
+ - **position**: optional `{x, y}` (finite numbers, ±1000000); the node's top-left corner in canvas coordinates. A pinned node keeps that spot; unpinned nodes are placed automatically.
47
49
  - **edge**: `from`/`to` must be existing node ids; `kind` common values `call`, `data`, `dependency`, `next`, `contains`.
48
- - `layout.mode` is advisory for the client; the current client uses its own grid + local positions.
50
+ - `layout.mode` is advisory for the client; the current client uses its own layered/grid layout, `node.position` pins and browser-local drag overrides.
49
51
 
50
52
  `rev` increments on every successful write. Pass the latest `rev` as `baseRev`; a mismatch returns `STALE_REV`. `apply:false` validates and returns a diff without writing. `refreshAnchors:true` recomputes all anchor hashes after review; without it, only missing hashes are filled.
51
53
 
@@ -53,7 +55,7 @@ All data lives under `<workspace>/.archmap/`. Do not invent another store.
53
55
 
54
56
  ```
55
57
  add_node { node }
56
- update_node { id, patch }
58
+ update_node { id, patch } # patch.position={x,y} pins; patch.position=null clears
57
59
  remove_node { id, cascade? }
58
60
  add_edge { edge }
59
61
  update_edge { id, patch }
@@ -91,4 +93,4 @@ Exports never modify `graph.json` or the manifest.
91
93
  - Paths are realpath-checked and must stay inside the workspace.
92
94
  - Writes are atomic (temp file + rename); a failed write must be reported, never silently retried.
93
95
  - The UI polls the graph every 2s; a successful patch becomes visible within ~3s.
94
- - Node positions are a **local view preference** (browser localStorage), not part of `graph.json`. Only dragged nodes are stored as overrides; the automatic layout stays the base, so a graph revision reflows undragged nodes. A cyclic graph falls back to a compact grid; the layered layout is for acyclic graphs.
96
+ - `position` is part of `graph.json` (shared pin). Dragging a node only writes a browser-local override; `Reset layout` drops the override and returns to the pin/automatic layout. A cyclic graph with no pins falls back to a compact grid, so pin positions when the reading order matters.
@@ -143,9 +143,86 @@ function gridLayout(graph) {
143
143
  h: NODE_H,
144
144
  })
145
145
  })
146
- const width = PAD * 2 + cols * NODE_W + (cols - 1) * GAP_X
147
- const height = PAD * 2 + rows * NODE_H + (rows - 1) * GAP_Y
148
- return { positions, width, height }
146
+ let width = PAD * 2 + cols * NODE_W + (cols - 1) * GAP_X
147
+ let height = PAD * 2 + rows * NODE_H + (rows - 1) * GAP_Y
148
+ // A pinned position is a top-left corner in graph coordinates; the grid is
149
+ // only the fallback for nodes that do not carry one.
150
+ for (const node of nodes) {
151
+ const position = node.position
152
+ if (!position || !Number.isFinite(position.x) || !Number.isFinite(position.y)) continue
153
+ const box = positions.get(node.id)
154
+ box.x = position.x
155
+ box.y = position.y
156
+ width = Math.max(width, box.x + box.w + PAD)
157
+ height = Math.max(height, box.y + box.h + PAD)
158
+ }
159
+ return { positions, width: Math.ceil(width), height: Math.ceil(height) }
160
+ }
161
+
162
+ function edgeRoute(from, to, boxes = []) {
163
+ const fx = from.x + from.w / 2
164
+ const fy = from.y + from.h / 2
165
+ const tx = to.x + to.w / 2
166
+ const ty = to.y + to.h / 2
167
+ const dx = tx - fx
168
+ const dy = ty - fy
169
+ const horizontal = Math.abs(dx) >= (from.w + to.w) / 2 - 8
170
+ if (horizontal && dx >= 0) {
171
+ const start = { x: from.x + from.w, y: fy }
172
+ const end = { x: to.x, y: ty }
173
+ const blockers = Math.abs(dy) > 4 ? [] : boxes.filter(box => {
174
+ if (box === from || box === to) return false
175
+ return box.x < end.x
176
+ && box.x + box.w > start.x
177
+ && box.y < fy
178
+ && box.y + box.h > fy
179
+ })
180
+ if (blockers.length > 0) {
181
+ const top = Math.min(fy, ...blockers.map(box => box.y)) - 26
182
+ const bottom = Math.max(fy, ...blockers.map(box => box.y + box.h)) + 18
183
+ const lane = top >= 12 && fy - top <= bottom - fy ? top : bottom
184
+ const inner = 10
185
+ return {
186
+ d: [
187
+ `M ${start.x} ${start.y}`,
188
+ `L ${start.x + inner} ${start.y}`,
189
+ `L ${start.x + inner} ${lane}`,
190
+ `L ${end.x - inner} ${lane}`,
191
+ `L ${end.x - inner} ${end.y}`,
192
+ `L ${end.x} ${end.y}`,
193
+ ].join(' '),
194
+ label: { x: (start.x + end.x) / 2, y: lane - 6 },
195
+ }
196
+ }
197
+ return {
198
+ d: `M ${start.x} ${start.y} L ${end.x} ${end.y}`,
199
+ label: { x: (start.x + end.x) / 2, y: (start.y + end.y) / 2 - 6 },
200
+ gap: to.x - (from.x + from.w),
201
+ above: Math.max(12, Math.min(from.y, to.y) - 12),
202
+ }
203
+ }
204
+ if (horizontal) {
205
+ const start = { x: from.x, y: fy }
206
+ const end = { x: to.x + to.w, y: ty }
207
+ const bow = 70 + Math.min(60, Math.abs(dx) * 0.08)
208
+ const controlY = Math.abs(dy) < 24
209
+ ? Math.max(start.y, end.y) + bow
210
+ : (start.y + end.y) / 2
211
+ const control = { x: (start.x + end.x) / 2, y: controlY }
212
+ return {
213
+ d: `M ${start.x} ${start.y} Q ${control.x} ${control.y} ${end.x} ${end.y}`,
214
+ label: {
215
+ x: 0.25 * start.x + 0.5 * control.x + 0.25 * end.x,
216
+ y: 0.25 * start.y + 0.5 * control.y + 0.25 * end.y,
217
+ },
218
+ }
219
+ }
220
+ const start = { x: fx, y: dy >= 0 ? from.y + from.h : from.y }
221
+ const end = { x: tx, y: dy >= 0 ? to.y : to.y + to.h }
222
+ return {
223
+ d: `M ${start.x} ${start.y} L ${end.x} ${end.y}`,
224
+ label: { x: (start.x + end.x) / 2, y: (start.y + end.y) / 2 - 6 },
225
+ }
149
226
  }
150
227
 
151
228
  function svgSource(graph) {
@@ -166,17 +243,20 @@ function svgSource(graph) {
166
243
  ' </defs>',
167
244
  ` <rect width="${width}" height="${height}" fill="#ffffff"/>`,
168
245
  ]
246
+ const boxes = [...positions.values()]
169
247
  for (const edge of edges) {
170
248
  const from = positions.get(edge.from)
171
249
  const to = positions.get(edge.to)
172
250
  if (!from || !to) continue
173
- const x1 = from.x + from.w
174
- const y1 = from.y + from.h / 2
175
- const x2 = to.x
176
- const y2 = to.y + to.h / 2
177
- lines.push(` <line x1="${x1}" y1="${y1}" x2="${x2}" y2="${y2}" stroke="#7b8794" stroke-width="1.4" stroke-opacity="0.7" marker-end="url(#arrow)"/>`)
251
+ const route = edgeRoute(from, to, boxes)
252
+ lines.push(` <path d="${route.d}" fill="none" stroke="#7b8794" stroke-width="1.4" stroke-opacity="0.7" stroke-linecap="round" marker-end="url(#arrow)"/>`)
178
253
  if (edge.label) {
179
- lines.push(` <text x="${(x1 + x2) / 2}" y="${(y1 + y2) / 2 - 5}" text-anchor="middle" font-family="sans-serif" font-size="10" fill="#52606d">${xml(edge.label)}</text>`)
254
+ const label = String(edge.label)
255
+ const labelWidth = [...label].reduce((sum, char) => sum + (char.charCodeAt(0) > 255 ? 10 : 6), 0) + 8
256
+ const tight = route.gap !== undefined && labelWidth + 6 > route.gap
257
+ const labelY = tight ? route.above : route.label.y
258
+ lines.push(` <rect x="${(route.label.x - labelWidth / 2).toFixed(1)}" y="${(labelY - 9).toFixed(1)}" width="${labelWidth}" height="14" rx="3" fill="#ffffff" opacity="0.92"/>`)
259
+ lines.push(` <text x="${route.label.x.toFixed(1)}" y="${(labelY + 2).toFixed(1)}" text-anchor="middle" font-family="sans-serif" font-size="10" fill="#52606d">${xml(label)}</text>`)
180
260
  }
181
261
  }
182
262
  for (const node of nodes) {
package/src/host/graph.js CHANGED
@@ -20,8 +20,9 @@ const NODE_KINDS = new Set(['entry', 'module', 'service', 'store', 'external', '
20
20
  const EDGE_KINDS = new Set(['call', 'data', 'dependency', 'containment'])
21
21
  const STATUSES = new Set(['fresh', 'stale', 'proposed'])
22
22
 
23
- const NODE_FIELDS = new Set(['id', 'title', 'kind', 'group', 'summary', 'anchors', 'status', 'style', 'notes'])
24
- const NODE_PATCH_FIELDS = new Set(['title', 'kind', 'group', 'summary', 'anchors', 'status', 'style', 'notes'])
23
+ const NODE_FIELDS = new Set(['id', 'title', 'kind', 'group', 'summary', 'anchors', 'status', 'style', 'notes', 'position'])
24
+ const NODE_PATCH_FIELDS = new Set(['title', 'kind', 'group', 'summary', 'anchors', 'status', 'style', 'notes', 'position'])
25
+ const POSITION_FIELDS = new Set(['x', 'y'])
25
26
  const EDGE_FIELDS = new Set(['id', 'from', 'to', 'label', 'kind', 'status'])
26
27
  const EDGE_PATCH_FIELDS = new Set(['from', 'to', 'label', 'kind', 'status'])
27
28
  const GROUP_FIELDS = new Set(['id', 'title', 'kind'])
@@ -82,6 +83,21 @@ function assertKnownKeys(value, allowed, where) {
82
83
  }
83
84
  }
84
85
 
86
+ function assertPosition(position, where) {
87
+ if (!isPlainObject(position)) {
88
+ fail('INVALID_GRAPH', `${where} must be an object { x, y } with finite numbers`)
89
+ }
90
+ assertKnownKeys(position, POSITION_FIELDS, where)
91
+ for (const axis of ['x', 'y']) {
92
+ if (!Number.isFinite(position[axis])) {
93
+ fail('INVALID_GRAPH', `${where}.${axis} must be a finite number`)
94
+ }
95
+ if (Math.abs(position[axis]) > 1000000) {
96
+ fail('LIMIT_EXCEEDED', `${where}.${axis} must be within ±1000000`)
97
+ }
98
+ }
99
+ }
100
+
85
101
  function assertRelativeAnchor(anchor, where) {
86
102
  if (!isPlainObject(anchor)) fail('INVALID_GRAPH', `${where} must be an object { path, symbol?, hash? }`)
87
103
  if (typeof anchor.path !== 'string' || anchor.path.trim() === '') {
@@ -115,6 +131,7 @@ function normalizeNode(raw, where = 'node') {
115
131
  status: raw.status ?? 'fresh',
116
132
  ...(raw.style === undefined ? {} : { style: raw.style }),
117
133
  ...(raw.notes === undefined ? {} : { notes: raw.notes }),
134
+ ...(raw.position === undefined ? {} : { position: raw.position }),
118
135
  }
119
136
  }
120
137
 
@@ -225,6 +242,9 @@ export function validateGraph(graph, limits = DEFAULTS) {
225
242
  if (node.notes !== undefined && typeof node.notes !== 'string') {
226
243
  fail('INVALID_GRAPH', `node ${node.id}.notes must be a string when present`)
227
244
  }
245
+ if (node.position !== undefined) {
246
+ assertPosition(node.position, `node ${node.id}.position`)
247
+ }
228
248
  }
229
249
 
230
250
  for (const edge of graph.edges) {
@@ -291,6 +311,8 @@ export function applyOps(graph, ops, limits = DEFAULTS) {
291
311
  }
292
312
  assertKnownKeys(op.patch, NODE_PATCH_FIELDS, `${where}.patch`)
293
313
  Object.assign(node, op.patch)
314
+ // position:null clears a pin; other fields keep their normal merge.
315
+ if (op.patch.position === null) delete node.position
294
316
  break
295
317
  }
296
318
  case 'remove_node': {
@@ -443,6 +465,7 @@ function renderOverview(graph, limit, include) {
443
465
  const parts = [` ${node.id} "${node.title}"`, node.kind]
444
466
  if (node.group !== undefined) parts.push(`group ${node.group}`)
445
467
  parts.push(node.status)
468
+ if (node.position) parts.push(`pin ${node.position.x},${node.position.y}`)
446
469
  lines.push(parts.join(' · '))
447
470
  if (include.includes('summary') && node.summary) lines.push(` ${clip(node.summary, 160)}`)
448
471
  }
@@ -467,6 +490,7 @@ function renderNode(graph, node, options) {
467
490
  `rev ${graph.rev} · node ${node.id} "${node.title}"`,
468
491
  `kind: ${node.kind}${node.group ? ` · group: ${node.group}` : ''} · status: ${node.status}`,
469
492
  ]
493
+ if (node.position) lines.push(`pinned: ${node.position.x},${node.position.y}`)
470
494
  if (include.includes('summary') && node.summary) lines.push(`summary: ${clip(node.summary, 600)}`)
471
495
  if (include.includes('anchors') && node.anchors.length > 0) {
472
496
  lines.push('anchors:')
@@ -449,7 +449,7 @@ export function apply(ctx, config = {}) {
449
449
  ops: {
450
450
  type: 'array',
451
451
  items: { type: 'object', additionalProperties: true },
452
- description: 'Ordered operations. Shapes: {op:"add_node", node:{id,title,kind,summary?,anchors?:[{path,symbol?,hash?}]}}; {op:"update_node", id, patch:{...}}; {op:"remove_node", id, cascade?}; {op:"add_edge", edge:{id,from,to,label?,kind?}}; {op:"update_edge", id, patch:{...}}; {op:"remove_edge", id}; {op:"set_group", group:{id,title}}; {op:"remove_group", id}.',
452
+ description: 'Ordered operations. Shapes: {op:"add_node", node:{id,title,kind,summary?,anchors?:[{path,symbol?,hash?}],position?:{x,y}}}; {op:"update_node", id, patch:{...}} (patch.position={x,y} pins the top-left corner; patch.position=null clears it); {op:"remove_node", id, cascade?}; {op:"add_edge", edge:{id,from,to,label?,kind?}}; {op:"update_edge", id, patch:{...}}; {op:"remove_edge", id}; {op:"set_group", group:{id,title}}; {op:"remove_group", id}.',
453
453
  },
454
454
  apply: {
455
455
  type: 'boolean',