@capyclaw/capyclaw-workbench 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -20,18 +20,17 @@ CapyClaw 子会话工作台运行时:让 AI 在同一宿主进程内发起、
20
20
 
21
21
  ## 承载形态
22
22
 
23
- 宿主进程内插件(foundation ABI):有 `ctx.webServer` 时挂宿主路由前缀,不单独占端口;工具经 `tools.registry` / `tools.descriptors` 能力注册。公共胶水收敛在 `@capyclaw/suite-kit/host` 的 `mountSuiteWorkbench`;`lib/host.mjs` 只保留 capyclaw 差异(sessionPort/session-watch 装配 + 两个 drain 端点)。
23
+ 宿主进程内插件(foundation ABI):有 `ctx.webServer` 时挂宿主路由前缀,不单独占端口;工具经 `tools.registry` / `tools.descriptors` 能力注册。公共胶水收敛在 `@capyclaw/suite-kit/host` 的 `mountSuiteWorkbench`;`lib/host.mjs` 只保留 capyclaw 差异(sessionPort 装配 + agent-pending drain 端点 + 工作区补登记)。
24
24
 
25
25
  ## 顶栏标签通道(宿主 → 客户端 keeper)
26
26
 
27
- 顶栏标签由 `@capyclaw/session-keeper` 按来源白名单纳入。本工作台提供两条固定 drain 端点(路径独立于 mountPath,GET 返回 `{ ids }`,取走即清空,`no-store`):
27
+ 顶栏标签由 `@capyclaw/session-keeper` 按来源白名单(`user-open`/`user-create`/`agent`)纳入。本工作台提供一条固定 drain 端点(路径独立于 mountPath,GET 返回 `{ ids }`,取走即清空,`no-store`):
28
28
 
29
29
  | 端点 | 来源 | 喂入方 |
30
30
  | --- | --- | --- |
31
31
  | `/capyclaw/session-tabs/agent-pending` | `agent` | `session-port.createSession`(AI 派发创建的会话) |
32
- | `/capyclaw/session-tabs/host-pending` | `host` | `lib/session-watch.mjs` 周期差分宿主会话列表 |
33
32
 
34
- `session-watch`(规则④)每 5s 差分 `sessionQuery.listSessions()`,把**运行中(live)的非子代理会话**入队——覆盖远程 LiveShare fork、定时任务等不走 `createSession` 的路径,含启动前就在跑的会话;冷会话不纳入,变 live 时再纳入;子代理(`header.origin==='subagent'`)不占标签。没有 `sessionQuery` 时不启动。keeper 取走后以 `host` 来源纳入顶栏(enroll 会 retain,连带把会话 materialize 进客户端目录,会话记录可见性一并解决)。
33
+ **2026-11-24:`host-pending`/`session-watch`(曾称规则④)已移除。** 它把每个运行中的非子代理会话(后台/定时/远程/别窗,含启动前已在跑的)自动入队加成顶栏标签,违背「标签只经用户点开/创建/AI 特定接口加入」的规则(用户再次投诉「不经过我就冒出来」)。远程/后台会话需要进顶栏时,由用户从侧栏点开或经 AI 特定接口派发。工作区成员补登记(下节)不加标签,保留。
35
34
 
36
35
  ## 工作区登记(规则⑤)
37
36
 
@@ -51,7 +50,6 @@ npm test
51
50
  ```
52
51
 
53
52
  - `test/workbench.test.mjs`:核心工具面 / HTTP / MCP / 描述符 / 呈现面。
54
- - `test/session-port.test.mjs`:会话端口 + 两条标签队列(入队/去重/上限/drain)+ 创建时工作区登记。
55
- - `test/session-watch.test.mjs`:宿主探测(live 纳入 / 冷转 live / 子代理跳过 / 容错 / 防重入)。
53
+ - `test/session-port.test.mjs`:会话端口 + AI 标签队列(入队/去重/上限/drain)+ 创建时工作区登记。
56
54
  - `test/workspace-attach.test.mjs`:工作区登记(路径匹配 / 幂等 / 只登记已存在 / 补登记跳过规则 / 周期运行器 + handled / 懒解析)。
57
- - `test/host.test.mjs`:宿主装配(两个 drain 端点 / watch 接线 / 工作区补登记接线 / __host__ / 释放)。
55
+ - `test/host.test.mjs`:宿主装配(agent-pending 端点 / host-pending 不再注册 / 工作区补登记接线 / __host__ / 释放)。
package/lib/host.mjs CHANGED
@@ -2,11 +2,10 @@
2
2
  * capyclaw-workbench cordis 宿主入口:把可单测核心接进 DSH。
3
3
  * 公共胶水(safeGet/断言/缺服务降级/probe 兜底/__host__/portal/工具注册/描述符/逆序释放)
4
4
  * 收敛到 @capyclaw/suite-kit/host 的 mountSuiteWorkbench(P1-9);本文件只保留 capyclaw 差异:
5
- * sessionPort/session-watch 装配、两个固定 session-tabs drain 端点、__host__.available 字段。
5
+ * sessionPort 装配、AI 派发 session-tabs drain 端点、__host__.available 字段。
6
6
  */
7
7
  import { mountSuiteWorkbench } from '@capyclaw/suite-kit/host'
8
8
  import { createSessionPort } from './session-port.mjs'
9
- import { createSessionWatch } from './session-watch.mjs'
10
9
  import { createWorkspaceReconcile } from './workspace-attach.mjs'
11
10
  import { createCapyclawWorkbench } from './workbench.mjs'
12
11
  import { CAPYCLAW_DESCRIPTORS } from './descriptors.mjs'
@@ -34,16 +33,9 @@ export function apply(ctx, config = {}) {
34
33
  workspaceRegistry: () => safeGet(ctx, 'workspaceRegistry'),
35
34
  })
36
35
 
37
- // 规则④(宿主新会话探测):周期差分宿主会话列表,把运行中(live)的非子代理会话
38
- // (远程 LiveShare fork、定时任务等不走 createSession 的路径,含启动前就在跑的)
39
- // 入队,供下方 host-pending 端点取走。sessionQuery 晚注册也无妨——listSessions
40
- // 懒解析,未就绪时抛错被 watch 捕获、下一拍重试。
41
- const sessionWatch = createSessionWatch({
42
- listSessions: () => sessionPort.listSessions(),
43
- enqueue: (ids) => sessionPort.noteHostTabs(ids),
44
- })
45
- sessionWatch.start()
46
- push(() => sessionWatch.stop())
36
+ // 规则先行(2026-11-24):曾短暂装配的 session-watch(规则④ host 探测)已移除——
37
+ // 它把每个运行中的后台/定时/远程会话都自动加成顶栏标签,违背「标签只经
38
+ // 用户点开/创建/AI 特定接口加入」的规则。顶栏纳入只留 agent-pending 一条宿主通道。
47
39
 
48
40
  // 工作区登记(周期补登记):远程「只传 cwd」创建的会话 DSH 不登记工作区成员,
49
41
  // 落「未分组」、不出现在对应工作区清单。这里把运行中、非子代理、未被任何工作区
@@ -84,23 +76,6 @@ export function apply(ctx, config = {}) {
84
76
  },
85
77
  })
86
78
  if (typeof offAgent === 'function') push(offAgent)
87
-
88
- // 规则④(宿主新会话探测)宿主→客户端固定端点:与 agent-pending 同构。客户端 keeper
89
- // 以固定路径周期轮询,取走宿主探测到的新会话 id(远程 fork/定时任务等)并以 'host'
90
- // 来源纳入顶栏标签。GET 返回 { ids }(取走即清空)。
91
- const offHost = webServer.register({
92
- kind: 'exact', path: '/capyclaw/session-tabs/host-pending',
93
- handler: (req, res) => {
94
- if (req.method !== 'GET') {
95
- res.writeHead(405, { 'content-type': 'application/json' })
96
- res.end(JSON.stringify({ error: 'GET only' }))
97
- return
98
- }
99
- res.writeHead(200, { 'content-type': 'application/json', 'cache-control': 'no-store' })
100
- res.end(JSON.stringify(sessionPort.drainHostTabs()))
101
- },
102
- })
103
- if (typeof offHost === 'function') push(offHost)
104
79
  },
105
80
  })
106
81
  }
@@ -11,9 +11,10 @@
11
11
  * - 纯函数端口,服务全部注入(可在测试里用 fake 替换),不 import 任何 DSH 包。
12
12
  * - 优雅降级:宿主没有对应服务时返回明确的 unavailable 错误,而不是静默假成功。
13
13
  * - GUI 无会话深链(recon 结论):这里只负责「创建/驱动/查询」会话这一控制面;
14
- * 「呈现哪个会话」是 UI 层的事。经 createSession 新建的会话走 agent-pending 通道;
15
- * 不经此端口的新建会话(远程 LiveShare fork、定时任务等)由 session-watch 差分
16
- * 发现后走 host-pending 通道(规则④),两条通道都供客户端 keeper 纳入顶栏。
14
+ * 「呈现哪个会话」是 UI 层的事。经 createSession 新建的会话走 agent-pending 通道,
15
+ * 供客户端 keeper 以 'agent' 来源纳入顶栏——这是宿主侧唯一的加标签通道。
16
+ * (2026-11-24:曾短暂加入的 session-watch/host-pending「规则④」已移除——它把每个
17
+ * 运行中的后台/定时/远程会话都自动加成标签,违背「只经用户/AI 特定接口加标签」的规则。)
17
18
  * - 工作区登记:DSH 只给传 workspaceId 的创建登记工作区成员,只传 cwd 不登记
18
19
  * (会话落「未分组」)。createSession 成功后按 cwd 补登记进匹配的已存在工作区
19
20
  * (workspace-attach,best-effort,不新建工作区)。
@@ -50,14 +51,6 @@ export function createSessionPort(services = {}) {
50
51
  const AGENT_TAB_QUEUE_CAP = 200
51
52
  const pendingAgentTabs = []
52
53
 
53
- /* 规则④(宿主新会话探测)宿主侧待取队列:session-watch 差分宿主会话列表,把
54
- 「运行中(live)的非子代理会话」(远程 LiveShare fork、定时任务等不走 createSession
55
- 的路径,含启动前就在跑的)记入这里,由 host.mjs 固定端点
56
- /capyclaw/session-tabs/host-pending 供客户端 keeper 周期取走、以 'host' 来源纳入顶栏。
57
- 上限/去重口径与 AI 队列一致。 */
58
- const HOST_TAB_QUEUE_CAP = 200
59
- const pendingHostTabs = []
60
-
61
54
  return {
62
55
  get available() { return !!controller() },
63
56
  get services() {
@@ -100,22 +93,6 @@ export function createSessionPort(services = {}) {
100
93
  return { ids: pendingAgentTabs.splice(0, pendingAgentTabs.length) }
101
94
  },
102
95
 
103
- /** 记入宿主探测到的新会话 id(session-watch 调用)。去重 + 上限防无界增长。 */
104
- noteHostTabs(ids) {
105
- if (!Array.isArray(ids)) return
106
- for (const id of ids) {
107
- if (typeof id === 'string' && id && pendingHostTabs.indexOf(id) < 0) pendingHostTabs.push(id)
108
- }
109
- if (pendingHostTabs.length > HOST_TAB_QUEUE_CAP) {
110
- pendingHostTabs.splice(0, pendingHostTabs.length - HOST_TAB_QUEUE_CAP)
111
- }
112
- },
113
-
114
- /** 取走并清空宿主新会话标签请求(规则④宿主→客户端通道的 drain 端)。返回 { ids }。 */
115
- drainHostTabs() {
116
- return { ids: pendingHostTabs.splice(0, pendingHostTabs.length) }
117
- },
118
-
119
96
  /** 向会话发一条用户消息,启动一轮(mode: queue|steer)。 */
120
97
  async prompt({ sessionId, text, mode = 'queue' } = {}) {
121
98
  const sessionController = controller()
@@ -102,7 +102,7 @@ export async function reconcileWorkspaceMembership({ listSessions, workspaceRegi
102
102
  return { attached, ready: true }
103
103
  }
104
104
 
105
- /** 补登记运行器的重试间隔(与 session-watch 同口径)。 */
105
+ /** 补登记运行器的重试间隔。 */
106
106
  export const WORKSPACE_RECONCILE_INTERVAL_MS = 5000
107
107
 
108
108
  /**
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capyclaw/foundation",
3
- "version": "0.1.10",
3
+ "version": "0.1.11",
4
4
  "description": "dsh 插件基石层:接口 ABI、插件加载器与内核服务 ctx.os。应用插件只声明接口,不写装配代码。",
5
5
  "type": "module",
6
6
  "main": "./lib/host.mjs",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capyclaw/plugin-kit",
3
- "version": "0.2.7",
3
+ "version": "0.2.8",
4
4
  "description": "DSH 插件基础设施标准件:HTTP/MCP、单实例锁、参数校验、技能 provider、journal 存储、编辑器传输与租约。",
5
5
  "type": "module",
6
6
  "main": "./src/index.mjs",
@@ -7,7 +7,7 @@
7
7
  "packages": {
8
8
  "@capyclaw/service-host": {
9
9
  "role": "provider",
10
- "version": "^0.1.6",
10
+ "version": "^0.1.7",
11
11
  "path": ".",
12
12
  "provides": {
13
13
  "services": [
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capyclaw/service-host",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "description": "DSH 公共服务宿主插件:统一 HTTP 路由、健康检查、指标、单实例锁、端口复用与静态资源,向插件提供 ctx.serviceHost。",
5
5
  "type": "module",
6
6
  "main": "./lib/host.mjs",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capyclaw/suite-kit",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "DSH suite/domain 标准件(双重身份:构建期库 + 运行时库,暂不拆包,见 README「双重身份」)。构建期:manifest 校验、compose、profile 生成、domain 解析、artifact 打包;运行时:统一能力描述符、编排闸/授权、嵌入握手与 surface 挂载。",
5
5
  "type": "module",
6
6
  "main": "./src/index.mjs",
@@ -7,7 +7,7 @@
7
7
  "packages": {
8
8
  "@capyclaw/tool-host": {
9
9
  "role": "provider",
10
- "version": "^0.3.1",
10
+ "version": "^0.3.2",
11
11
  "path": ".",
12
12
  "provides": {
13
13
  "services": [
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capyclaw/tool-host",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "description": "DSH 公共工具面插件:能力 DSL、工具注册表、参数校验、契约报告、MCP 协议壳与 instructions 模板,向插件提供 ctx.toolHost。",
5
5
  "type": "module",
6
6
  "main": "./lib/host.mjs",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capyclaw/capyclaw-workbench",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "CapyClaw 子会话工作台运行时:7 个 capyclaw_* 工具(创建/驱动/查询/关闭 DSH 子会话 + 读写设置)+ 俄罗斯套娃控制台(同源嵌入 DSH GUI)。挂在 dsh 的 /capyclaw/capyclaw。",
5
5
  "type": "module",
6
6
  "main": "./plugin.mjs",
@@ -1,82 +0,0 @@
1
- /**
2
- * 宿主会话探测(规则④):周期差分宿主会话列表,把「运行中(live)的非子代理会话」入队。
3
- *
4
- * 背景(2026-11-23):远程 LiveShare viewer fork、定时任务等路径创建的会话不经工作台
5
- * createSession,进不了 agent-pending 队列,顶栏 keeper 的来源白名单也不认识它们——
6
- * 于是这些会话在宿主后台真实运行,却不出现在顶栏标签里(用户报告的会话管理漏洞)。
7
- * 这里周期差分 sessionQuery.listSessions()(宿主权威会话语料,含未激活的持久会话),
8
- * 把运行中的会话喂给 session-port 的 host 队列,客户端 keeper 经固定端点
9
- * /capyclaw/session-tabs/host-pending 取走、以 'host' 来源纳入顶栏(enroll 会 retain,
10
- * 连带把会话 materialize 进宿主客户端目录,会话记录可见性一并解决)。
11
- *
12
- * 设计口径(用户规则:所有会话不管前台后台都遵循同一套管理规则):
13
- * - 纯函数,listSessions/enqueue 全部注入(测试可 fake),不 import 任何 DSH 包。
14
- * - 纳入判据 = record.live !== false(运行中/已激活),不看创建时间:启动前就在跑的
15
- * 远程会话首拍即纳入;冷会话(live:false)不纳入,日后被远程唤醒变 live 时再纳入。
16
- * (第一版「首拍只 seed」会漏掉重启前已存在的运行中远程会话,2026-11-23 已废弃。)
17
- * - 子代理(header.origin==='subagent',DSH 官方分类器;parentSession 存在本身不能
18
- * 分类子代理)不占顶栏标签(它们嵌套展示在父会话里)。
19
- * - enrolled 记录已入队 id,每拍修剪到当前语料 id,内存有界。用户关掉的标签只要会话
20
- * 还在语料里就一直留在 enrolled,不会被重新入队——尊重「关闭只由用户、不自动加回」。
21
- * - busy 防重入;查询失败容错,下一拍再试,绝不崩宿主。
22
- */
23
-
24
- export const HOST_WATCH_INTERVAL_MS = 5000
25
-
26
- /**
27
- * @param {{ listSessions: () => Promise<Array<object>>, enqueue: (ids: string[]) => void, intervalMs?: number }} opts
28
- * listSessions 返回宿主会话记录(SessionRecord[]:{header:{id,origin,...},live,persisted};
29
- * 兼容无 header 包装、直接带 id/sessionId 的活会话列表——无 live 字段视为 live)。
30
- */
31
- export function createSessionWatch({ listSessions, enqueue, intervalMs = HOST_WATCH_INTERVAL_MS } = {}) {
32
- if (typeof listSessions !== 'function') throw new Error('createSessionWatch 需要 listSessions 函数')
33
- if (typeof enqueue !== 'function') throw new Error('createSessionWatch 需要 enqueue 函数')
34
- const enrolled = new Set()
35
- let busy = false
36
- let stopped = false
37
- let timer = null
38
-
39
- async function tick() {
40
- if (stopped || busy) return
41
- busy = true
42
- try {
43
- const records = await listSessions()
44
- const items = Array.isArray(records) ? records : []
45
- const current = new Set()
46
- const fresh = []
47
- for (const record of items) {
48
- const header = record && record.header ? record.header : record
49
- const id = header && (header.id ?? header.sessionId)
50
- if (typeof id !== 'string' || !id) continue
51
- current.add(id)
52
- /* 子代理不占顶栏标签(嵌套展示在父会话里)。 */
53
- if (header.origin === 'subagent') continue
54
- /* 只纳入运行中/已激活的会话;冷持久会话等它变 live 再说。
55
- 无 live 字段的兼容形态(活会话列表)视为 live。 */
56
- if (record && record.live === false) continue
57
- if (enrolled.has(id)) continue
58
- enrolled.add(id)
59
- fresh.push(id)
60
- }
61
- /* enrolled 修剪到当前语料:内存有界;仍在语料里的 id 保留,
62
- 用户关掉的标签不会被自动加回。 */
63
- for (const id of enrolled) { if (!current.has(id)) enrolled.delete(id) }
64
- if (fresh.length) enqueue(fresh)
65
- } catch { /* 宿主查询失败:下一拍再试 */ }
66
- finally { busy = false }
67
- }
68
-
69
- function start() {
70
- if (timer || stopped) return
71
- void tick()
72
- timer = setInterval(() => { void tick() }, intervalMs)
73
- if (timer && typeof timer.unref === 'function') timer.unref()
74
- }
75
-
76
- function stop() {
77
- stopped = true
78
- if (timer) { clearInterval(timer); timer = null }
79
- }
80
-
81
- return { start, stop, tick }
82
- }