@robiteame/dsh-pi-agent-session-tree 0.1.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.
@@ -0,0 +1,6 @@
1
+ # Bilingual-pair consistency record (docs/i18n/README.md): the git blob hash of each
2
+ # side as of the last confirmed-consistent state. Both languages carry equal authority;
3
+ # after editing either side, bring the other along and re-record with:
4
+ # pnpm run verify-translation-pairing --write packages/extensions/pi-agent-session-tree/README.md
5
+ README.md: 1864e58240ef360b3ad3fde0cb93d7b602b1f0d5
6
+ README.zh.md: 55027174b3aef4c3d4abc4e8b3dd2c9ecf386a45
package/README.md ADDED
@@ -0,0 +1,98 @@
1
+ # pi_agent_session_tree
2
+
3
+ English | [中文](README.zh.md)
4
+
5
+ Append-only multi-branch conversation trees for DeepSeek-Harness: the agent's
6
+ sole conversation history is a tree keyed by agent session, forkable at any
7
+ historical node, with standard LLM message reconstruction, JSON snapshots, and
8
+ an embedded WebUI tree panel.
9
+
10
+ ## Surface
11
+
12
+ | Surface | Name | Notes |
13
+ |---|---|---|
14
+ | Tool | `session_tree` | one tree per agent session; operations below |
15
+ | Command | `/tree` | `list`, `branches`, `tree`, `context`, `jump <nodeId>`, `branch <nodeId> <name>`, `snapshot save`, `snapshot load <json>` |
16
+ | Commands | `/fork`, `/clone`, `/session` | fork in-tree, clone the active path to a separate session, inspect tree status |
17
+ | Remote service | `sessionTree` | `list(agent)`, `jump(agent, nodeId)`, `fork(agent, nodeId, branch)`, `session(agent)` — drives the browser panel |
18
+ | Browser slot | `conversation.details.panel` / `shell.overlay` | native details seat in a patched checkout, additive drawer in an official Bundle; click a node to jump |
19
+
20
+ ## Tool operations
21
+
22
+ `create`, `append`, `list`, `branches`, `tree`, `jump`, `fork`, `clone`,
23
+ `context`, `session`, `branch`, `branch.summary`, `snapshot.save`,
24
+ `snapshot.load`, `sessions`.
25
+
26
+ - `context` returns `{cursor, messages}` where `messages` is the standard LLM
27
+ messages array for the root→cursor path.
28
+ - `branch` parks the cursor at an existing node and names the next append's
29
+ branch; `branch.summary` additionally appends a summary node. Historical
30
+ nodes are never modified or deleted.
31
+ - `snapshot.save` returns the versioned tree snapshot; `snapshot.load` restores
32
+ it under the same sessionId (see `SNAPSHOT_VERSION` versioning:
33
+ `version: 1`).
34
+
35
+ Every operation answers `{ok: true, value}` or `{ok: false, error: {code, message}}`
36
+ with codes `INVALID_ARGUMENT` | `SESSION_NOT_FOUND` | `SESSION_ALREADY_EXISTS` |
37
+ `NODE_NOT_FOUND` | `INVALID_SNAPSHOT` | `NOT_FOUND`,
38
+ so tool and Remote results are always lossless JSON.
39
+
40
+ ## Tool examples
41
+
42
+ ```json
43
+ {"operation":"create","sessionId":"demo"}
44
+ {"operation":"append","sessionId":"demo","message":{"role":"user","content":"Explore option A"}}
45
+ {"operation":"append","sessionId":"demo","message":{"role":"assistant","content":"Baseline answer"}}
46
+ {"operation":"branch","sessionId":"demo","nodeId":"<root-nodeId>","branch":"option-b"}
47
+ {"operation":"append","sessionId":"demo","message":{"role":"user","content":"Explore option B"},"branch":"option-b"}
48
+ {"operation":"context","sessionId":"demo"}
49
+ {"operation":"snapshot.save","sessionId":"demo"}
50
+ {"operation":"snapshot.load","sessionId":"demo","snapshot":{"version":1,"sessionId":"demo","cursor":null,"activeBranch":"main","nodes":[]}}
51
+ ```
52
+
53
+ ## Composition
54
+
55
+ Add the host row to the active Cordis composition (the standalone Bundle's
56
+ `cordis.patch.yml` already carries it):
57
+
58
+ ```yaml
59
+ - id: pi-agent-session-tree
60
+ name: '@robiteame/dsh-pi-agent-session-tree'
61
+ ```
62
+
63
+ The browser panel ships as `@robiteame/dsh-client-ui-session-tree`. A patched
64
+ checkout mounts it as `conversation.details.panel`; an official Bundle mounts
65
+ it as the additive `shell.overlay`. See `SYSTEM_PROMPT.md` for the
66
+ system-prompt fragment this plugin installs.
67
+
68
+ ## Implementation notes
69
+
70
+ - The store is process-wide and shared by the tool, the command, and the
71
+ Remote service, so model appends appear in the panel immediately.
72
+ - Harness `Session` events are the durable source of truth; the tree is an
73
+ incrementally synchronized projection. Explicit `snapshot.save`/`snapshot.load`
74
+ events remain available for export and full-tree restore.
75
+ - A patched checkout persists tree markers as `session-tree/*` events. An
76
+ official Bundle appends an official empty-content `assistant/message` with a
77
+ `replace` surface operation when the cursor moves, and stores branch
78
+ metadata in the sidecar under
79
+ `$DSH_HOME/storages/session-tree/<sessionId>.json`. Earlier events are never
80
+ rewritten or deleted.
81
+ - Model-visible ⇔ logged: native Harness message events always synchronize
82
+ into tree nodes; the tree does not synthesize history that was never logged.
83
+
84
+ ## Model Experience
85
+
86
+ ### Model-facing surface
87
+
88
+ #### What the model sees
89
+
90
+ The domain service registers no prompt, schema, or result of its own: the model-facing surface is entirely owned by `@robiteame/dsh-tool-session-tree` (tool, `/tree` command, system-prompt section). The Remote methods this package exposes serve the browser panel only and never enter model context.
91
+
92
+ #### Token effect
93
+
94
+ None — this package contributes no model-visible text.
95
+
96
+ #### KV Cache effect
97
+
98
+ None — nothing from this package joins the model request prefix.
package/README.zh.md ADDED
@@ -0,0 +1,72 @@
1
+ # pi_agent_session_tree
2
+
3
+ [English](README.md) | 中文
4
+
5
+ 面向 DeepSeek-Harness 的只追加多分支会话树:agent 的唯一会话历史是按 agent 会话为键的树,可在任意历史节点分叉,支持标准 LLM 消息重建、JSON 快照,以及嵌入 WebUI 的树面板。
6
+
7
+ ## 表面
8
+
9
+ | 表面 | 名称 | 说明 |
10
+ |---|---|---|
11
+ | 工具 | `session_tree` | 每个 agent 会话一棵树;操作见下 |
12
+ | 命令 | `/tree` | `list`、`branches`、`tree`、`context`、`jump <nodeId>`、`branch <nodeId> <name>`、`snapshot save`、`snapshot load <json>` |
13
+ | 命令 | `/fork`、`/clone`、`/session` | 在树内 fork、复制到独立 session、查看当前树状态 |
14
+ | Remote 服务 | `sessionTree` | `list(agent)`、`jump(agent, nodeId)`、`fork(agent, nodeId, branch)`、`session(agent)`——驱动浏览器面板 |
15
+ | 浏览器插槽 | `conversation.details.panel` / `shell.overlay` | 补丁集成使用原生详情栏,官方 Bundle 使用叠加式抽屉;点击节点即跳转 |
16
+
17
+ ## 工具操作
18
+
19
+ `create`、`append`、`list`、`branches`、`tree`、`jump`、`fork`、`clone`、`context`、`session`、`branch`、`branch.summary`、`snapshot.save`、`snapshot.load`、`sessions`。
20
+
21
+ - `context` 返回 `{cursor, messages}`,其中 `messages` 是根→光标路径的标准 LLM messages 数组。
22
+ - `branch` 把光标停在已有节点并命名下一次 append 的分支;`branch.summary` 额外追加一个摘要节点。历史节点永不被修改或删除。
23
+ - `snapshot.save` 返回版本化树快照;`snapshot.load` 在同一 sessionId 下恢复(`SNAPSHOT_VERSION` 版本化:`version: 1`)。
24
+
25
+ 每次操作都返回 `{ok: true, value}` 或 `{ok: false, error: {code, message}}`,错误码为 `INVALID_ARGUMENT` | `SESSION_NOT_FOUND` | `SESSION_ALREADY_EXISTS` | `NODE_NOT_FOUND` | `INVALID_SNAPSHOT` | `NOT_FOUND`,因此工具与 Remote 结果始终是无损 JSON。
26
+
27
+ ## 工具示例
28
+
29
+ ```json
30
+ {"operation":"create","sessionId":"demo"}
31
+ {"operation":"append","sessionId":"demo","message":{"role":"user","content":"Explore option A"}}
32
+ {"operation":"append","sessionId":"demo","message":{"role":"assistant","content":"Baseline answer"}}
33
+ {"operation":"branch","sessionId":"demo","nodeId":"<root-nodeId>","branch":"option-b"}
34
+ {"operation":"append","sessionId":"demo","message":{"role":"user","content":"Explore option B"},"branch":"option-b"}
35
+ {"operation":"context","sessionId":"demo"}
36
+ {"operation":"snapshot.save","sessionId":"demo"}
37
+ {"operation":"snapshot.load","sessionId":"demo","snapshot":{"version":1,"sessionId":"demo","cursor":null,"activeBranch":"main","nodes":[]}}
38
+ ```
39
+
40
+ ## 组合
41
+
42
+ 把主机行加入当前 Cordis 组合(独立 Bundle 的 `cordis.patch.yml` 已携带):
43
+
44
+ ```yaml
45
+ - id: pi-agent-session-tree
46
+ name: '@robiteame/dsh-pi-agent-session-tree'
47
+ ```
48
+
49
+ 浏览器面板以 `@robiteame/dsh-client-ui-session-tree` 提供。补丁集成把它挂载为 `conversation.details.panel`,官方 Bundle 把它挂载为叠加式 `shell.overlay`。本插件安装的 system-prompt 片段见 `SYSTEM_PROMPT.md`。
50
+
51
+ ## 实现说明
52
+
53
+ - 存储为进程级共享,工具、命令与 Remote 服务共用,因此模型追加的内容立即可见于面板。
54
+ - Harness `Session` 事件是持久化真源;树是增量同步的投影。显式 `snapshot.save`/`snapshot.load` 事件仍可用于整树导出与恢复。
55
+ - 补丁集成把树标记持久化为 `session-tree/*` 事件。官方 Bundle 在光标移动时追加一条空内容官方 `assistant/message`,携带 `replace` surface 操作,并把分支元数据保存到 `$DSH_HOME/storages/session-tree/<sessionId>.json`。较早的事件不会被改写或删除。
56
+ - 模型可见 ⇔ 已记录:原生 Harness 消息事件始终同步为树节点;树不会合成从未记录过的历史。
57
+
58
+ ## 模型体验
59
+
60
+ ### 模型面
61
+
62
+ #### 模型看到什么
63
+
64
+ 领域服务本身不注册任何提示、schema 或结果:模型面完全由 `@robiteame/dsh-tool-session-tree`(工具、`/tree` 命令、system-prompt 片段)承担。本包暴露的 Remote 方法只服务浏览器面板,绝不进入模型上下文。
65
+
66
+ #### Token 影响
67
+
68
+ 无——本包不贡献任何模型可见文本。
69
+
70
+ #### KV 缓存影响
71
+
72
+ 无——本包没有任何内容进入模型请求前缀。