@sanqianx/claude-ai-workbench 0.13.2 → 0.13.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.
Files changed (120) hide show
  1. package/LICENSE +201 -201
  2. package/README.md +156 -156
  3. package/apps/agent-terminal/app.css +636 -613
  4. package/apps/agent-terminal/app.js +125 -65
  5. package/apps/agent-terminal/conversation-composer.js +44 -0
  6. package/apps/agent-terminal/index.html +171 -170
  7. package/apps/agent-terminal/panel-host-proof.html +152 -152
  8. package/apps/agent-terminal/panel-proof-content.html +41 -41
  9. package/apps/agent-terminal/right-workspace-dock.css +187 -159
  10. package/apps/agent-terminal/right-workspace-dock.js +623 -519
  11. package/apps/ai-profile-settings-host/index.html +25 -25
  12. package/apps/ai-profile-settings-host/page.css +1 -1
  13. package/apps/ai-profile-settings-host/page.js +113 -113
  14. package/apps/minimal-test-host/README.md +15 -15
  15. package/apps/minimal-test-host/host.css +2 -2
  16. package/apps/minimal-test-host/host.js +35 -35
  17. package/apps/minimal-test-host/index.html +58 -58
  18. package/apps/minimal-test-host/optional-mock/fault-injection.js +15 -15
  19. package/docs/sdk/FILE_LAYOUT.md +31 -31
  20. package/docs/sdk/INTEGRATION.md +126 -126
  21. package/docs/sdk/README.md +21 -21
  22. package/docs/sdk/SESSION_EVENTS.md +13 -13
  23. package/docs/sdk/openapi.yaml +8 -1
  24. package/package.json +1 -1
  25. package/packages/client/README.md +29 -29
  26. package/packages/client/index.d.ts +122 -122
  27. package/packages/client/index.js +260 -260
  28. package/packages/client/package.json +2 -2
  29. package/packages/contracts/README.md +9 -9
  30. package/packages/contracts/index.d.ts +519 -517
  31. package/packages/contracts/index.js +312 -312
  32. package/packages/contracts/package.json +1 -1
  33. package/packages/core/README.md +8 -8
  34. package/packages/core/index.d.ts +76 -76
  35. package/packages/core/index.js +222 -222
  36. package/packages/core/package.json +2 -2
  37. package/packages/server/README.md +17 -17
  38. package/packages/server/bin/agent-terminal-server.js +42 -42
  39. package/packages/server/bin/claude-workbench.js +225 -225
  40. package/packages/server/index.d.ts +171 -171
  41. package/packages/server/index.js +230 -230
  42. package/packages/server/lib/agent-discovery.js +133 -133
  43. package/packages/server/lib/agent-registry.js +143 -143
  44. package/packages/server/lib/agent-spawn-env.js +17 -17
  45. package/packages/server/lib/attachment-store.js +78 -78
  46. package/packages/server/lib/bridges/app-server-bridge.js +373 -373
  47. package/packages/server/lib/bridges/opencode-server-bridge.js +506 -506
  48. package/packages/server/lib/capture-settings-store.js +35 -35
  49. package/packages/server/lib/claude-history-recovery.js +87 -87
  50. package/packages/server/lib/cli-session-recovery.js +28 -28
  51. package/packages/server/lib/context-resolver.js +55 -55
  52. package/packages/server/lib/conversation-capture.js +51 -51
  53. package/packages/server/lib/delegation-phase-store.js +357 -357
  54. package/packages/server/lib/delegation-store.js +474 -468
  55. package/packages/server/lib/diagnostics.js +32 -32
  56. package/packages/server/lib/drivers/cli-json-runner.js +974 -974
  57. package/packages/server/lib/drivers/codex-driver.js +1442 -1442
  58. package/packages/server/lib/drivers/opencode-driver.js +1554 -1554
  59. package/packages/server/lib/drivers/zcode-driver.js +1250 -1250
  60. package/packages/server/lib/drivers/zcode-profile-runtime.js +71 -71
  61. package/packages/server/lib/event-stream.js +138 -138
  62. package/packages/server/lib/folder-picker.js +623 -623
  63. package/packages/server/lib/http-handler.js +339 -339
  64. package/packages/server/lib/json-file.js +26 -26
  65. package/packages/server/lib/knowledge-context.js +33 -33
  66. package/packages/server/lib/model-detection.js +295 -295
  67. package/packages/server/lib/parent-context.js +44 -0
  68. package/packages/server/lib/profile-store.js +283 -283
  69. package/packages/server/lib/project-store.js +102 -102
  70. package/packages/server/lib/runtime-loader.js +120 -120
  71. package/packages/server/lib/session-archive-store.js +53 -53
  72. package/packages/server/lib/session-history.js +612 -612
  73. package/packages/server/lib/system-doctor.js +125 -125
  74. package/packages/server/lib/ui-preferences-store.js +48 -48
  75. package/packages/server/lib/workbench-service.js +1696 -1675
  76. package/packages/server/package.json +2 -2
  77. package/packages/ui/README.md +30 -30
  78. package/packages/ui/ai-profile-settings.d.ts +45 -45
  79. package/packages/ui/ai-profile-settings.js +283 -283
  80. package/packages/ui/claude-terminal.d.ts +31 -31
  81. package/packages/ui/claude-terminal.js +343 -343
  82. package/packages/ui/index.d.ts +18 -18
  83. package/packages/ui/index.js +51 -51
  84. package/packages/ui/package.json +2 -2
  85. package/packages/ui/theme.css +13 -13
  86. package/src/assets/claude-prompts.json +21 -21
  87. package/src/backend/http/ai-profile-routes.js +61 -61
  88. package/src/backend/http/claude-routes.js +170 -170
  89. package/src/backend/http/node-helpers.js +45 -45
  90. package/src/backend/index.js +21 -21
  91. package/src/backend/lib/ai-adapter.js +144 -144
  92. package/src/backend/lib/ai-profile-store.js +259 -259
  93. package/src/backend/lib/ai-vendor-presets.js +83 -83
  94. package/src/backend/lib/ai-workspace.js +140 -140
  95. package/src/backend/lib/automation-config.js +253 -253
  96. package/src/backend/lib/claude-cli-runner.js +2392 -2392
  97. package/src/backend/lib/data-dir.js +169 -169
  98. package/src/backend/lib/llm-client.js +176 -176
  99. package/src/backend/lib/model-context-windows.js +82 -82
  100. package/src/backend/lib/native-task-control.js +217 -217
  101. package/src/backend/lib/native-task-history-index.js +475 -475
  102. package/src/backend/lib/native-task-history-reader.js +526 -526
  103. package/src/backend/lib/native-task-messages.js +457 -457
  104. package/src/backend/lib/native-task-registry.js +325 -325
  105. package/src/backend/lib/native-task-runtime.js +242 -242
  106. package/src/backend/lib/native-task-trace.js +440 -440
  107. package/src/backend/lib/native-task-transcript.js +393 -393
  108. package/src/backend/lib/prompt-registry.js +166 -166
  109. package/src/backend/lib/runtime-config.js +121 -121
  110. package/src/backend/lib/sdk-session-stream.js +143 -143
  111. package/src/backend/lib/sdk-turn-stream.js +16 -16
  112. package/src/backend/lib/store-scope.js +131 -131
  113. package/src/backend/lib/task-identity.js +104 -104
  114. package/src/backend/lib/task-state-projection.js +58 -58
  115. package/src/index.js +7 -7
  116. package/src/sdk-wave-a.ts +1 -1
  117. package/src/sdk-wave-b.ts +1 -1
  118. package/src/sdk-wave-c.ts +1 -1
  119. package/src/sdk-wave-d.ts +1 -1
  120. package/src/sdk-wave-e.ts +1 -1
@@ -1,31 +1,31 @@
1
- # SDK 文件布局
2
-
3
- ```text
4
- claude-ai-workbench/
5
- ├─ packages/ # 可发布 SDK 源码
6
- │ ├─ contracts/ # 公共类型、常量和输入标准化
7
- │ ├─ client/ # 浏览器/Node REST + SSE Client
8
- │ ├─ core/ # 终端状态机、上下文隔离、会话生命周期
9
- │ ├─ ui/
10
- │ │ ├─ ai-profile-settings.js # AI Profile 默认入口
11
- │ │ ├─ ai-profile-settings.d.ts
12
- │ │ ├─ claude-terminal.js # 产品级 Claude Code 终端入口
13
- │ │ ├─ claude-terminal.d.ts
14
- │ │ └─ theme.css
15
- │ └─ server/ # REST/SSE Server 与 CLI
16
- ├─ apps/
17
- │ ├─ ai-profile-settings-host/ # AI Profile 独立接入示例
18
- │ ├─ claude-terminal-host/ # 无调试面板的终端接入示例
19
- │ └─ minimal-test-host/ # 内部验收、故障注入和原始事件检查
20
- ├─ docs/sdk/ # 对外文档和 OpenAPI
21
- ├─ scripts/ # 校验与 SDK 打包
22
- └─ dist/sdk/ # 自动生成的 tgz 与 SHA-256 manifest
23
- ```
24
-
25
- ## 边界规则
26
-
27
- 1. 产品宿主只使用 `contracts`、`client`、`core`、`ui` 的公共入口,不复制组件源码。
28
- 2. `claude-terminal` 不创建 Client、不写死 API 地址、不读取凭据;宿主注入 Client 和 `WorkbenchContext`。
29
- 3. `minimal-test-host` 是内部 QA 工具,不是产品界面;运行指标、Raw SSE、故障注入不得进入终端组件。
30
- 4. API Key 只通过 credential 接口或临时测试请求进入 Server,公开 Profile 永不返回明文。
31
- 5. `dist/sdk/` 每次发布重新生成,不手工修改。
1
+ # SDK 文件布局
2
+
3
+ ```text
4
+ claude-ai-workbench/
5
+ ├─ packages/ # 可发布 SDK 源码
6
+ │ ├─ contracts/ # 公共类型、常量和输入标准化
7
+ │ ├─ client/ # 浏览器/Node REST + SSE Client
8
+ │ ├─ core/ # 终端状态机、上下文隔离、会话生命周期
9
+ │ ├─ ui/
10
+ │ │ ├─ ai-profile-settings.js # AI Profile 默认入口
11
+ │ │ ├─ ai-profile-settings.d.ts
12
+ │ │ ├─ claude-terminal.js # 产品级 Claude Code 终端入口
13
+ │ │ ├─ claude-terminal.d.ts
14
+ │ │ └─ theme.css
15
+ │ └─ server/ # REST/SSE Server 与 CLI
16
+ ├─ apps/
17
+ │ ├─ ai-profile-settings-host/ # AI Profile 独立接入示例
18
+ │ ├─ claude-terminal-host/ # 无调试面板的终端接入示例
19
+ │ └─ minimal-test-host/ # 内部验收、故障注入和原始事件检查
20
+ ├─ docs/sdk/ # 对外文档和 OpenAPI
21
+ ├─ scripts/ # 校验与 SDK 打包
22
+ └─ dist/sdk/ # 自动生成的 tgz 与 SHA-256 manifest
23
+ ```
24
+
25
+ ## 边界规则
26
+
27
+ 1. 产品宿主只使用 `contracts`、`client`、`core`、`ui` 的公共入口,不复制组件源码。
28
+ 2. `claude-terminal` 不创建 Client、不写死 API 地址、不读取凭据;宿主注入 Client 和 `WorkbenchContext`。
29
+ 3. `minimal-test-host` 是内部 QA 工具,不是产品界面;运行指标、Raw SSE、故障注入不得进入终端组件。
30
+ 4. API Key 只通过 credential 接口或临时测试请求进入 Server,公开 Profile 永不返回明文。
31
+ 5. `dist/sdk/` 每次发布重新生成,不手工修改。
@@ -1,126 +1,126 @@
1
- # SDK 接入说明
2
-
3
- ## 1. 安装
4
-
5
- ```bash
6
- npm install @claude-ai-workbench/contracts@0.2.0 \
7
- @claude-ai-workbench/client@0.2.0 \
8
- @claude-ai-workbench/core@0.2.0 \
9
- @claude-ai-workbench/ui@0.2.0
10
- ```
11
-
12
- 运行服务的机器另行安装:
13
-
14
- ```bash
15
- npm install @claude-ai-workbench/server@0.2.0
16
- ```
17
-
18
- ## 2. 启动 Server
19
-
20
- ```powershell
21
- $env:CLAUDE_AI_WORKBENCH_DATA_DIR = 'D:\data\claude-workbench'
22
- $env:CLAUDE_WORKBENCH_PORT = '5760'
23
- npx claude-workbench-server
24
- ```
25
-
26
- Node.js 也可直接嵌入:
27
-
28
- ```js
29
- const { createWorkbenchServer } = require("@claude-ai-workbench/server");
30
- const app = createWorkbenchServer({ dataDir: "D:/data/claude-workbench", serveHost: false });
31
- app.server.listen(5760, "127.0.0.1");
32
- ```
33
-
34
- ## 3. 接入 Claude Code 终端
35
-
36
- ```js
37
- import "@claude-ai-workbench/ui/theme.css";
38
- import "@claude-ai-workbench/ui/claude-terminal";
39
- import { createClaudeWorkbenchClient } from "@claude-ai-workbench/client";
40
-
41
- const client = createClaudeWorkbenchClient({
42
- apiBase: "http://127.0.0.1:5760/api/claude-workbench/v1",
43
- });
44
- const terminal = document.querySelector("#terminal");
45
-
46
- terminal.client = client;
47
- terminal.context = {
48
- contextId: "project-42",
49
- contextType: "project",
50
- displayName: "知识库项目",
51
- workspaceRef: "registered-workspace-42",
52
- aiProfileId: "claude-sonnet",
53
- };
54
-
55
- terminal.addEventListener("terminal-error", ({ detail }) => console.error(detail));
56
- terminal.addEventListener("terminal-command", event => {
57
- if (event.detail.command === "config") {
58
- event.preventDefault();
59
- openHostSettings();
60
- }
61
- });
62
- window.addEventListener("beforeunload", () => {
63
- terminal.destroy();
64
- client.destroy();
65
- });
66
- ```
67
-
68
- ```html
69
- <claude-workbench-pane id="terminal"></claude-workbench-pane>
70
- ```
71
-
72
- `workspaceRef` 是 Server 白名单中注册的工作区标识,不能由浏览器传入任意绝对路径。切换项目时只需重新赋值 `terminal.context`;Core 会中止旧请求、关闭旧 SSE,并隔离新旧上下文事件。
73
-
74
- 快捷命令不是前端常量。Core 会调用 `GET /sessions/{sessionId}/commands`,从当前 Claude Code 运行时读取内置命令、Skills、Plugins 和 MCP 命令;输入 `/` 后可搜索,选中后仍可补充参数再发送。`terminal-command` 是可取消事件,宿主只在确实需要接管某个命令时调用 `preventDefault()`。
75
-
76
- 图片默认支持点击选择、拖入和从剪贴板粘贴,格式为 JPEG、PNG、GIF、WebP;单张上限 10 MiB,一次最多 20 张且总计不超过 20 MiB。组件将 Base64 图片交给 Client,Server 验证真实文件签名并保存到产品数据目录的 `attachments/`,会话事件只保存可读取的附件 URL,不保存用户图片的 Base64 副本。宿主要使用自有文件选择器时可拦截:
77
-
78
- ```js
79
- terminal.addEventListener("terminal-attach-request", async event => {
80
- event.preventDefault();
81
- const files = await openHostImagePicker();
82
- await event.detail.addFiles(files);
83
- });
84
- ```
85
-
86
- 不使用 UI 时,可直接调用同一公共 API:
87
-
88
- ```js
89
- const commands = await client.listCommands(sessionId);
90
- await client.send({
91
- sessionId,
92
- text: "说明这张图",
93
- attachments: [{ name: "screen.png", mediaType: "image/png", data: base64 }],
94
- });
95
- ```
96
-
97
- ## 4. 接入 AI Profile UI
98
-
99
- ```js
100
- import "@claude-ai-workbench/ui";
101
- import "@claude-ai-workbench/ui/theme.css";
102
- ```
103
-
104
- ```html
105
- <ai-profile-list id="profileList"></ai-profile-list>
106
- <ai-profile-editor id="profileEditor"></ai-profile-editor>
107
- ```
108
-
109
- AI Profile UI 只发布 `profile-save`、`profile-test`、`profile-edit`、`profile-delete` 等 DOM 事件,宿主用 Client 完成持久化。测试连接不会保存;只有 `saveProfile` 和 `setCredential` 会写入产品数据目录。
110
-
111
- ## 5. 不使用 npm 的浏览器接入
112
-
113
- 按以下顺序加载静态文件:
114
-
115
- ```html
116
- <link rel="stylesheet" href="/vendor/claude-workbench/ui/theme.css">
117
- <script src="/vendor/claude-workbench/client/index.js"></script>
118
- <script src="/vendor/claude-workbench/core/index.js"></script>
119
- <script src="/vendor/claude-workbench/ui/claude-terminal.js"></script>
120
- ```
121
-
122
- 加载后可使用全局函数 `createClaudeWorkbenchClient`、全局对象 `ClaudeWorkbenchCore` 和 `<claude-workbench-pane>`。
123
-
124
- ## 6. 非 JavaScript 程序接入
125
-
126
- C++、C#、Java 等程序直接按 [openapi.yaml](openapi.yaml) 调用 JSON REST API。OpenAPI 相当于语言无关的接口头文件;UI 仍由 WebView 或浏览器宿主加载。
1
+ # SDK 接入说明
2
+
3
+ ## 1. 安装
4
+
5
+ ```bash
6
+ npm install @claude-ai-workbench/contracts@0.2.0 \
7
+ @claude-ai-workbench/client@0.2.0 \
8
+ @claude-ai-workbench/core@0.2.0 \
9
+ @claude-ai-workbench/ui@0.2.0
10
+ ```
11
+
12
+ 运行服务的机器另行安装:
13
+
14
+ ```bash
15
+ npm install @claude-ai-workbench/server@0.2.0
16
+ ```
17
+
18
+ ## 2. 启动 Server
19
+
20
+ ```powershell
21
+ $env:CLAUDE_AI_WORKBENCH_DATA_DIR = 'D:\data\claude-workbench'
22
+ $env:CLAUDE_WORKBENCH_PORT = '5760'
23
+ npx claude-workbench-server
24
+ ```
25
+
26
+ Node.js 也可直接嵌入:
27
+
28
+ ```js
29
+ const { createWorkbenchServer } = require("@claude-ai-workbench/server");
30
+ const app = createWorkbenchServer({ dataDir: "D:/data/claude-workbench", serveHost: false });
31
+ app.server.listen(5760, "127.0.0.1");
32
+ ```
33
+
34
+ ## 3. 接入 Claude Code 终端
35
+
36
+ ```js
37
+ import "@claude-ai-workbench/ui/theme.css";
38
+ import "@claude-ai-workbench/ui/claude-terminal";
39
+ import { createClaudeWorkbenchClient } from "@claude-ai-workbench/client";
40
+
41
+ const client = createClaudeWorkbenchClient({
42
+ apiBase: "http://127.0.0.1:5760/api/claude-workbench/v1",
43
+ });
44
+ const terminal = document.querySelector("#terminal");
45
+
46
+ terminal.client = client;
47
+ terminal.context = {
48
+ contextId: "project-42",
49
+ contextType: "project",
50
+ displayName: "知识库项目",
51
+ workspaceRef: "registered-workspace-42",
52
+ aiProfileId: "claude-sonnet",
53
+ };
54
+
55
+ terminal.addEventListener("terminal-error", ({ detail }) => console.error(detail));
56
+ terminal.addEventListener("terminal-command", event => {
57
+ if (event.detail.command === "config") {
58
+ event.preventDefault();
59
+ openHostSettings();
60
+ }
61
+ });
62
+ window.addEventListener("beforeunload", () => {
63
+ terminal.destroy();
64
+ client.destroy();
65
+ });
66
+ ```
67
+
68
+ ```html
69
+ <claude-workbench-pane id="terminal"></claude-workbench-pane>
70
+ ```
71
+
72
+ `workspaceRef` 是 Server 白名单中注册的工作区标识,不能由浏览器传入任意绝对路径。切换项目时只需重新赋值 `terminal.context`;Core 会中止旧请求、关闭旧 SSE,并隔离新旧上下文事件。
73
+
74
+ 快捷命令不是前端常量。Core 会调用 `GET /sessions/{sessionId}/commands`,从当前 Claude Code 运行时读取内置命令、Skills、Plugins 和 MCP 命令;输入 `/` 后可搜索,选中后仍可补充参数再发送。`terminal-command` 是可取消事件,宿主只在确实需要接管某个命令时调用 `preventDefault()`。
75
+
76
+ 图片默认支持点击选择、拖入和从剪贴板粘贴,格式为 JPEG、PNG、GIF、WebP;单张上限 10 MiB,一次最多 20 张且总计不超过 20 MiB。组件将 Base64 图片交给 Client,Server 验证真实文件签名并保存到产品数据目录的 `attachments/`,会话事件只保存可读取的附件 URL,不保存用户图片的 Base64 副本。宿主要使用自有文件选择器时可拦截:
77
+
78
+ ```js
79
+ terminal.addEventListener("terminal-attach-request", async event => {
80
+ event.preventDefault();
81
+ const files = await openHostImagePicker();
82
+ await event.detail.addFiles(files);
83
+ });
84
+ ```
85
+
86
+ 不使用 UI 时,可直接调用同一公共 API:
87
+
88
+ ```js
89
+ const commands = await client.listCommands(sessionId);
90
+ await client.send({
91
+ sessionId,
92
+ text: "说明这张图",
93
+ attachments: [{ name: "screen.png", mediaType: "image/png", data: base64 }],
94
+ });
95
+ ```
96
+
97
+ ## 4. 接入 AI Profile UI
98
+
99
+ ```js
100
+ import "@claude-ai-workbench/ui";
101
+ import "@claude-ai-workbench/ui/theme.css";
102
+ ```
103
+
104
+ ```html
105
+ <ai-profile-list id="profileList"></ai-profile-list>
106
+ <ai-profile-editor id="profileEditor"></ai-profile-editor>
107
+ ```
108
+
109
+ AI Profile UI 只发布 `profile-save`、`profile-test`、`profile-edit`、`profile-delete` 等 DOM 事件,宿主用 Client 完成持久化。测试连接不会保存;只有 `saveProfile` 和 `setCredential` 会写入产品数据目录。
110
+
111
+ ## 5. 不使用 npm 的浏览器接入
112
+
113
+ 按以下顺序加载静态文件:
114
+
115
+ ```html
116
+ <link rel="stylesheet" href="/vendor/claude-workbench/ui/theme.css">
117
+ <script src="/vendor/claude-workbench/client/index.js"></script>
118
+ <script src="/vendor/claude-workbench/core/index.js"></script>
119
+ <script src="/vendor/claude-workbench/ui/claude-terminal.js"></script>
120
+ ```
121
+
122
+ 加载后可使用全局函数 `createClaudeWorkbenchClient`、全局对象 `ClaudeWorkbenchCore` 和 `<claude-workbench-pane>`。
123
+
124
+ ## 6. 非 JavaScript 程序接入
125
+
126
+ C++、C#、Java 等程序直接按 [openapi.yaml](openapi.yaml) 调用 JSON REST API。OpenAPI 相当于语言无关的接口头文件;UI 仍由 WebView 或浏览器宿主加载。
@@ -1,21 +1,21 @@
1
- # Claude AI Workbench SDK
2
-
3
- SDK 由五个同版本 npm 包组成:
4
-
5
- | 包 | 职责 | 类比 C++ |
6
- |---|---|---|
7
- | `@claude-ai-workbench/contracts` | 公共数据类型与常量 | 公共头文件 |
8
- | `@claude-ai-workbench/client` | REST/SSE Client | 调用封装库 |
9
- | `@claude-ai-workbench/core` | 终端状态机与会话生命周期 | 无 UI 业务内核 |
10
- | `@claude-ai-workbench/ui` | AI Profile 与 Claude Terminal Web Components | UI 控件库 |
11
- | `@claude-ai-workbench/server` | REST/SSE 服务与 CLI | 后台服务进程 |
12
-
13
- API 固定使用版本前缀 `/api/claude-workbench/v1`。执行:
14
-
15
- ```bash
16
- npm run sdk:check
17
- npm run sdk:pack
18
- npm run verify
19
- ```
20
-
21
- 详细接入见 [INTEGRATION.md](INTEGRATION.md),文件职责见 [FILE_LAYOUT.md](FILE_LAYOUT.md),语言无关接口见 [openapi.yaml](openapi.yaml)。
1
+ # Claude AI Workbench SDK
2
+
3
+ SDK 由五个同版本 npm 包组成:
4
+
5
+ | 包 | 职责 | 类比 C++ |
6
+ |---|---|---|
7
+ | `@claude-ai-workbench/contracts` | 公共数据类型与常量 | 公共头文件 |
8
+ | `@claude-ai-workbench/client` | REST/SSE Client | 调用封装库 |
9
+ | `@claude-ai-workbench/core` | 终端状态机与会话生命周期 | 无 UI 业务内核 |
10
+ | `@claude-ai-workbench/ui` | AI Profile 与 Claude Terminal Web Components | UI 控件库 |
11
+ | `@claude-ai-workbench/server` | REST/SSE 服务与 CLI | 后台服务进程 |
12
+
13
+ API 固定使用版本前缀 `/api/claude-workbench/v1`。执行:
14
+
15
+ ```bash
16
+ npm run sdk:check
17
+ npm run sdk:pack
18
+ npm run verify
19
+ ```
20
+
21
+ 详细接入见 [INTEGRATION.md](INTEGRATION.md),文件职责见 [FILE_LAYOUT.md](FILE_LAYOUT.md),语言无关接口见 [openapi.yaml](openapi.yaml)。
@@ -1,13 +1,13 @@
1
- # Session activity subscriptions
2
-
3
- `GET /sessions/changes?contextId=<id>&after=<revision>` streams SSE session summaries. The client exposes `subscribeSessionChanges(contextId, callback, onError, { afterRevision })`. Embedded hosts may supply their existing EventSource-compatible WebSocket transport; standalone pages use native SSE.
4
-
5
- An initial `workbench/sessions-snapshot` contains `sessions` (including archived records) and `revision`. Subsequent `workbench/session-changed` messages contain `session`, `contextId`, and `revision`; `deleted: true` removes that session. Cursors outside the retained revision window produce `workbench/resync`. Re-read one full snapshot after that marker. Reconnection does not resend input.
6
-
7
- Session summaries include `tasks` and `backgroundTaskCount`. Task records use actual SDK task IDs, `parentSessionId`, optional `toolUseId`, `description`, `status`, `summary`, `usage`, and `lastToolName`. The per-session stream persists `claude/task-started`, `claude/task-progress`, `claude/task-updated`, and `claude/task-notification` events. Parent tool IDs distinguish child output from foreground output. Terminal task statuses cannot be reopened by late running events.
8
-
9
- `claude/turn-end` closes the foreground reply. For Claude SDK streaming input this may occur at `end_turn` before its aggregate `result`, which can wait for background tasks. The input queue and event reader remain alive while tasks run. When foreground and tasks are both idle, the query is collected after 30 seconds; the next input resumes the same native session. Changing provider/model while a task runs is rejected.
10
-
11
- Bound native agent tasks also persist evidence rows in the same journal: `claude/native-trace` (sanitized in-process hook facts), `claude/native-task-state` (ownership/status projections) and `claude/native-task-transcript` (a snapshot of a bound agent's transcript read through the SDK's public `getSubagentMessages` at a real terminal signal, or at the bounded turn-end sweep). Transcript rows carry `source: "sdk-public-read"`, fixed content-free `read` reason codes when a read cannot happen honestly, byte-bounded `chunk` markers, and normalized redacted entries/tool steps/usage - a snapshot read, never a claim of per-token streaming. These rows are part of the single-session stream's named event vocabulary: the standalone client subscribes to `claude/native-trace`, `claude/native-task-state`, `claude/native-task-transcript` and `claude/task-interrupted` like every other chat event, so SDK consumers receive the native facts in real time. They are additionally read back through the two read-only native-task history APIs (`GET /sessions/:id/native-tasks`, `POST /sessions/:id/native-tasks/history`), which page them without dispatching input.
12
-
13
- Set `inputOrigin: "agent-delegation"` explicitly when creating a Leader-dispatched session and on its input options. A delegated session cannot reclassify itself as human. Browser composers identify human input; unmarked legacy/API records remain unknown. This provenance follows the durable capture event key through the event bridge. No task is inferred from prose claiming that an agent is running. Drivers advertise `capabilities.backgroundTasks`; unsupported drivers show the limitation explicitly.
1
+ # Session activity subscriptions
2
+
3
+ `GET /sessions/changes?contextId=<id>&after=<revision>` streams SSE session summaries. The client exposes `subscribeSessionChanges(contextId, callback, onError, { afterRevision })`. Embedded hosts may supply their existing EventSource-compatible WebSocket transport; standalone pages use native SSE.
4
+
5
+ An initial `workbench/sessions-snapshot` contains `sessions` (including archived records) and `revision`. Subsequent `workbench/session-changed` messages contain `session`, `contextId`, and `revision`; `deleted: true` removes that session. Cursors outside the retained revision window produce `workbench/resync`. Re-read one full snapshot after that marker. Reconnection does not resend input.
6
+
7
+ Session summaries include `tasks` and `backgroundTaskCount`. Task records use actual SDK task IDs, `parentSessionId`, optional `toolUseId`, `description`, `status`, `summary`, `usage`, and `lastToolName`. The per-session stream persists `claude/task-started`, `claude/task-progress`, `claude/task-updated`, and `claude/task-notification` events. Parent tool IDs distinguish child output from foreground output. Terminal task statuses cannot be reopened by late running events.
8
+
9
+ `claude/turn-end` closes the foreground reply. For Claude SDK streaming input this may occur at `end_turn` before its aggregate `result`, which can wait for background tasks. The input queue and event reader remain alive while tasks run. When foreground and tasks are both idle, the query is collected after 30 seconds; the next input resumes the same native session. Changing provider/model while a task runs is rejected.
10
+
11
+ Bound native agent tasks also persist evidence rows in the same journal: `claude/native-trace` (sanitized in-process hook facts), `claude/native-task-state` (ownership/status projections) and `claude/native-task-transcript` (a snapshot of a bound agent's transcript read through the SDK's public `getSubagentMessages` at a real terminal signal, or at the bounded turn-end sweep). Transcript rows carry `source: "sdk-public-read"`, fixed content-free `read` reason codes when a read cannot happen honestly, byte-bounded `chunk` markers, and normalized redacted entries/tool steps/usage - a snapshot read, never a claim of per-token streaming. These rows are part of the single-session stream's named event vocabulary: the standalone client subscribes to `claude/native-trace`, `claude/native-task-state`, `claude/native-task-transcript` and `claude/task-interrupted` like every other chat event, so SDK consumers receive the native facts in real time. They are additionally read back through the two read-only native-task history APIs (`GET /sessions/:id/native-tasks`, `POST /sessions/:id/native-tasks/history`), which page them without dispatching input.
12
+
13
+ Set `inputOrigin: "agent-delegation"` explicitly when creating a Leader-dispatched session and on its input options. A delegated session cannot reclassify itself as human. Browser composers identify human input; unmarked legacy/API records remain unknown. This provenance follows the durable capture event key through the event bridge. No task is inferred from prose claiming that an agent is running. Drivers advertise `capabilities.backgroundTasks`; unsupported drivers show the limitation explicitly.
@@ -1,7 +1,7 @@
1
1
  openapi: 3.1.0
2
2
  info:
3
3
  title: Claude AI Workbench API
4
- version: 0.13.2
4
+ version: 0.13.3
5
5
  description: Versioned local API for AI Profile, credential and Claude Code session management.
6
6
  servers:
7
7
  - url: http://127.0.0.1:5760/api/claude-workbench/v1
@@ -482,6 +482,7 @@ paths:
482
482
  storeScope: { type: string, format: uuid }
483
483
  contextId: { type: string, pattern: "^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$" }
484
484
  requestId: { type: string, maxLength: 256, description: Caller-chosen idempotency key for this command within the scope. }
485
+ contextMode: { type: string, enum: [parent-snapshot], description: Freeze parent conversation context on first acceptance; retries reuse the private snapshot. }
485
486
  text: { type: string, minLength: 1, maxLength: 200000, description: The command text. Trimmed server-side; the hash of the normalized command covers every execution-affecting choice. }
486
487
  agentId: { type: string, description: Defaults to claude-code; agents without a reserved-identity driver answer 501 before anything is reserved. }
487
488
  aiProfileId: { type: [string, "null"], description: Omitted inherits the parent's profile; null explicitly selects the agent's own login. }
@@ -1116,6 +1117,12 @@ components:
1116
1117
  type: object
1117
1118
  required: [delegation, phase, outcome, dispatch, child]
1118
1119
  properties:
1120
+ context:
1121
+ type: object
1122
+ required: [mode, truncated]
1123
+ properties:
1124
+ mode: { type: string, const: parent-snapshot }
1125
+ truncated: { type: boolean }
1119
1126
  delegation: { $ref: "#/components/schemas/DelegationCommandRecord" }
1120
1127
  phase: { type: string, enum: [reserved, child-created, child-create-failed, dispatching, dispatched, dispatch-unknown] }
1121
1128
  outcome: { type: string, enum: [not-started, not-dispatched, pending, dispatched, unknown] }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanqianx/claude-ai-workbench",
3
- "version": "0.13.2",
3
+ "version": "0.13.3",
4
4
  "description": "Shared Claude Code terminal and Anthropic-compatible AI profile modules for local developer tools.",
5
5
  "type": "commonjs",
6
6
  "main": "src/index.js",
@@ -1,29 +1,29 @@
1
- # @claude-ai-workbench/client
2
-
3
- 浏览器和 Node.js 使用的 HTTP/SSE Client SDK。
4
-
5
- ```js
6
- const { createClaudeWorkbenchClient } = require("@claude-ai-workbench/client");
7
- const client = createClaudeWorkbenchClient({ apiBase: "http://127.0.0.1:5760/api/claude-workbench/v1" });
8
- const profiles = await client.listProfiles();
9
- ```
10
-
11
- 浏览器也可直接加载 `index.js`,然后使用全局函数 `createClaudeWorkbenchClient`。
12
-
13
- ## 原生任务历史(只读)
14
-
15
- ```js
16
- const page = await client.listNativeTasks(sessionId, { storeScope, contextId });
17
- const ref = page.tasks.find((t) => t.taskRef)?.taskRef; // null = 尚未建立归属
18
- if (ref) {
19
- let events = await client.loadNativeTaskHistory(sessionId, { taskRef: ref });
20
- while (events.hasMore) {
21
- events = await client.loadNativeTaskHistory(sessionId, { taskRef: ref, cursor: events.nextCursor });
22
- }
23
- }
24
- ```
25
-
26
- - `listNativeTasks` 必须传服务端身份(health 的 `taskIdentity.storeScope`)与该会话真实 `contextId`,逐项比对不符即 409。
27
- - `loadNativeTaskHistory` 需要列表页返回的完整 `NativeTaskRef`(含全部身份字段),不能缩成 taskId;cursor 只回传上一页的 `nextCursor`,不得自行构造。
28
- - 两个方法均为纯读取:不派发输入、不停止任务、不自动重试。响应中的 `incomplete`/`diagnostics` 如实反映日志扫描的已知缺口。
29
- - 失败抛出的 Error 带 `status` 与 `body`,服务器提供时还带 `code`(如 `SCOPE_MISMATCH`、`HISTORY_NOT_FOUND`、写失败闩锁的具体原因)与 `resync: true`(409:从任务列表重新同步);503 表示历史暂不可读或写失败已闩锁,原文件保持不动。
1
+ # @claude-ai-workbench/client
2
+
3
+ 浏览器和 Node.js 使用的 HTTP/SSE Client SDK。
4
+
5
+ ```js
6
+ const { createClaudeWorkbenchClient } = require("@claude-ai-workbench/client");
7
+ const client = createClaudeWorkbenchClient({ apiBase: "http://127.0.0.1:5760/api/claude-workbench/v1" });
8
+ const profiles = await client.listProfiles();
9
+ ```
10
+
11
+ 浏览器也可直接加载 `index.js`,然后使用全局函数 `createClaudeWorkbenchClient`。
12
+
13
+ ## 原生任务历史(只读)
14
+
15
+ ```js
16
+ const page = await client.listNativeTasks(sessionId, { storeScope, contextId });
17
+ const ref = page.tasks.find((t) => t.taskRef)?.taskRef; // null = 尚未建立归属
18
+ if (ref) {
19
+ let events = await client.loadNativeTaskHistory(sessionId, { taskRef: ref });
20
+ while (events.hasMore) {
21
+ events = await client.loadNativeTaskHistory(sessionId, { taskRef: ref, cursor: events.nextCursor });
22
+ }
23
+ }
24
+ ```
25
+
26
+ - `listNativeTasks` 必须传服务端身份(health 的 `taskIdentity.storeScope`)与该会话真实 `contextId`,逐项比对不符即 409。
27
+ - `loadNativeTaskHistory` 需要列表页返回的完整 `NativeTaskRef`(含全部身份字段),不能缩成 taskId;cursor 只回传上一页的 `nextCursor`,不得自行构造。
28
+ - 两个方法均为纯读取:不派发输入、不停止任务、不自动重试。响应中的 `incomplete`/`diagnostics` 如实反映日志扫描的已知缺口。
29
+ - 失败抛出的 Error 带 `status` 与 `body`,服务器提供时还带 `code`(如 `SCOPE_MISMATCH`、`HISTORY_NOT_FOUND`、写失败闩锁的具体原因)与 `resync: true`(409:从任务列表重新同步);503 表示历史暂不可读或写失败已闩锁,原文件保持不动。