code-workspace-zhuiyi 0.1.0-beta.3 → 0.1.0-beta.5
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 +48 -6
- package/README.zh-CN.md +46 -6
- package/artifacts/manifest.json +12 -1
- package/artifacts/templates/claude/task-coordination-settings.json +13 -0
- package/artifacts/templates/codex/task-coordination-hooks.json +12 -0
- package/bin/code-workspace-task-hook.js +38 -0
- package/docs/extension-architecture.zh-CN.md +4 -0
- package/package.json +4 -2
- package/schemas/extension-manifest-v3.json +26 -1
- package/spec/extension/v1/specification.en-US.md +36 -0
- package/spec/extension/v1/specification.zh-CN.md +34 -0
- package/src/cli/commands/extension.js +2 -0
- package/src/cli/commands/init.js +3 -0
- package/src/cli/commands/project-branch.js +2 -2
- package/src/cli/commands/task.js +75 -0
- package/src/cli/commands/update.js +32 -5
- package/src/cli/registry.js +18 -2
- package/src/cli.js +2 -0
- package/src/core/config.js +72 -31
- package/src/core/doctor.js +22 -3
- package/src/core/extension-artifacts.js +7 -1
- package/src/core/extensions.js +58 -8
- package/src/core/hooks.js +253 -0
- package/src/core/init.js +3 -0
- package/src/core/initializer.js +44 -7
- package/src/core/managed-files.js +58 -11
- package/src/core/project-configuration.js +3 -2
- package/src/core/task-coordination-managed.js +140 -0
- package/src/core/task-coordination-protocol.js +226 -0
- package/src/core/task-coordination.js +1077 -0
- package/src/hooks/adapters/claude.js +66 -0
- package/src/hooks/adapters/codex.js +63 -0
- package/src/hooks/adapters/common.js +49 -0
- package/src/hooks/adapters/index.js +18 -0
- package/src/hooks/claude-task-coordination.js +3 -0
- package/src/hooks/codex-task-coordination.js +3 -0
- package/src/hooks/index.js +7 -0
- package/src/index.js +10 -0
package/README.md
CHANGED
|
@@ -34,14 +34,15 @@ code-workspace init . \
|
|
|
34
34
|
```
|
|
35
35
|
|
|
36
36
|
Use `--tools claude`, `--tools codex`, or `--tools none` to override the default tool selection. Codex monitoring is enabled by default when Codex is selected; use `--no-monitor` to disable it.
|
|
37
|
+
Pass `--coordination` to install the write-coordination Hooks into the selected providers' native configuration.
|
|
37
38
|
|
|
38
39
|
Initialization writes only Workspace-owned state and integrations:
|
|
39
40
|
|
|
40
|
-
- `.code-workspace/config.yaml`, `.code-workspace/config-projects.yaml
|
|
41
|
+
- `.code-workspace/config.yaml`, its referenced project configuration file (default: `.code-workspace/config-projects.yaml`), and `.code-workspace/state.json`
|
|
41
42
|
- `USER_GUIDE.md`
|
|
42
43
|
- `CLAUDE.md` and/or `AGENTS.md`
|
|
43
44
|
- Workspace-specific commands and skills whose names start with `code-workspace-` or use the `/code-workspace` namespace
|
|
44
|
-
- `.codex/hooks.json` when monitoring is enabled
|
|
45
|
+
- `.codex/hooks.json` when monitoring or Codex coordination is enabled, and `.claude/settings.json` when Claude coordination is enabled
|
|
45
46
|
|
|
46
47
|
It does not create `openspec/`, install native `/opsx` commands, or install native `openspec-*` skills.
|
|
47
48
|
|
|
@@ -67,7 +68,12 @@ The bundled `zhuiyi-jira-mcp` extension configures the Jira MCP service for the
|
|
|
67
68
|
|
|
68
69
|
Extension entries run in separate Node processes and generate files in temporary staging directories. The host rejects undeclared, missing, symbolic-link, non-file, path-escaping, conflicting, and checksum-mismatched artifacts before transactionally installing them. Per-Workspace state is stored in `.code-workspace/ext-manifest.json`. A failed extension is reported as a warning and does not roll back successful core initialization or stop later extensions; a failed upgrade restores and retains the previous installed version.
|
|
69
70
|
|
|
70
|
-
Extensions may own complete files or
|
|
71
|
+
Extensions may own complete files or declare Host-managed abstract Hooks. Codex and Claude
|
|
72
|
+
adaptors render those declarations into each provider's native configuration and dynamically plug
|
|
73
|
+
or unplug them during extension install, upgrade, and uninstall. Shared targets are composed and
|
|
74
|
+
verified by Code Workspace; extensions never patch the real Workspace directly. Uninstall uses
|
|
75
|
+
recorded installed state and does not execute extension code. Unknown changes to extension-owned
|
|
76
|
+
files or contributions stop the operation instead of being overwritten.
|
|
71
77
|
|
|
72
78
|
This is fault isolation, not a malicious-code security sandbox. The experimental release trusts only extension code shipped with Code Workspace; network sources, external extension directories, dependencies, arbitrary patches, force uninstall, disable commands, and automatic extension updates through `code-w update` are not supported. The developer contract is in `docs/extensions.md`.
|
|
73
79
|
|
|
@@ -93,7 +99,7 @@ code-workspace project add --projects-file projects.json --yes --json
|
|
|
93
99
|
|
|
94
100
|
The registry stores each project's name, real location, registered branch, type, and context. The registered branch is the Code Workspace expected state; the actual branch is observed from the selected Git worktree. Workspace never guesses a path from a conversation or automatically decides which branch is authoritative.
|
|
95
101
|
|
|
96
|
-
Project registration is always stored in
|
|
102
|
+
Project registration is always stored in a separate file in the `.code-workspace` directory. Initialization uses `config-projects.yaml` by default, while `projects.ref` may name any safe regular filename in that directory:
|
|
97
103
|
|
|
98
104
|
```yaml
|
|
99
105
|
# .code-workspace/config.yaml
|
|
@@ -115,7 +121,9 @@ projects:
|
|
|
115
121
|
Service ownership and navigation context.
|
|
116
122
|
```
|
|
117
123
|
|
|
118
|
-
`projects.ref` is resolved relative to `config.yaml
|
|
124
|
+
`projects.ref` is resolved relative to `config.yaml`. It must be one safe regular filename in the same `.code-workspace` directory; URLs, globs, absolute paths, path traversal, and inline `projects` arrays are not supported. All project commands keep their existing CLI semantics; they read and write the referenced project file. The `.code-workspace/` directory is ignored by default, so Git history for this local registry requires an explicit repository policy.
|
|
125
|
+
|
|
126
|
+
For example, `ref: team-projects.yaml` makes the project registry `.code-workspace/team-projects.yaml`; the default remains `config-projects.yaml`.
|
|
119
127
|
|
|
120
128
|
## Daily commands
|
|
121
129
|
|
|
@@ -141,7 +149,7 @@ The two reconciliation directions are deliberately separate:
|
|
|
141
149
|
|
|
142
150
|
Both commands detect plan drift and verify postconditions. `project branch update-latest` is the separate, opt-in path for projects with `updateLatest: true`; it only fetches the configured upstream and fast-forwards a clean matching branch. Code Workspace never creates or downloads a branch and never performs stash, reset, rebase, non-fast-forward merge, production-code edits, or conflict resolution.
|
|
143
151
|
|
|
144
|
-
Users may manually set the optional project policy in `.code-workspace/config-projects.yaml
|
|
152
|
+
Users may manually set the optional project policy in the file named by `projects.ref` (default: `.code-workspace/config-projects.yaml`):
|
|
145
153
|
|
|
146
154
|
```yaml
|
|
147
155
|
# .code-workspace/config-projects.yaml
|
|
@@ -160,11 +168,45 @@ AI/Agent must not directly edit this file. They may read the policy and invoke t
|
|
|
160
168
|
|
|
161
169
|
`permissions apply` shows the complete authorization plan for the selected Agent tools, requires confirmation when changes are needed, applies and verifies the requested grants, and reports the result per tool. Agent directory access remains a user authorization. The command adds missing registered-project access but does not revoke additional directories; use `project remove` or edit the Agent settings explicitly to revoke access.
|
|
162
170
|
|
|
171
|
+
## Coordinate concurrent Agent writes
|
|
172
|
+
|
|
173
|
+
When trusted Codex or Claude Hooks are installed, Code Workspace keeps the coordination ledger outside the Workspace and reserves write ranges before a supported tool runs. Different files in one project can proceed after an explicit project-parallel approval; overlapping files are denied without a force override.
|
|
174
|
+
|
|
175
|
+
Inspect tasks, claims, and pending recovery decisions:
|
|
176
|
+
|
|
177
|
+
```bash
|
|
178
|
+
code-workspace task list --json
|
|
179
|
+
code-workspace task show <task-id> --json
|
|
180
|
+
code-workspace task lock list --json
|
|
181
|
+
code-workspace task decision show <request-id> --json
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
Resolve a pending decision only after reviewing its evidence. Planned-write commands require confirmation; automation must pass `--yes` and always retry the original Agent operation after a successful decision:
|
|
185
|
+
|
|
186
|
+
```bash
|
|
187
|
+
code-workspace task decision keep <request-id> --yes --json
|
|
188
|
+
code-workspace task decision approve <request-id> --yes --json
|
|
189
|
+
code-workspace task decision release <request-id> --yes --json
|
|
190
|
+
code-workspace task decision abandon <request-id> --yes --json
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
`ACTIVE` file conflicts cannot be overridden. `UNKNOWN` reservations remain protected until the user keeps them or abandons the entire generation; a known live process blocks abandon. The mechanism covers only trusted, enabled, supported Agent Hooks and is not an OS-level sandbox for editors, shells, or external processes.
|
|
194
|
+
|
|
195
|
+
Hook support matrix (schema v1):
|
|
196
|
+
|
|
197
|
+
| Provider | Lifecycle events | Write events | Target handling |
|
|
198
|
+
| --- | --- | --- | --- |
|
|
199
|
+
| Codex | `SessionStart`, `UserPromptSubmit`, `PermissionRequest`, `Stop`, `SessionEnd` | `PreToolUse`, `PostToolUse` and available failure events | Known Edit/Write-style tools use exact files; unknown shell/tools use `PROJECT_WIDE` |
|
|
200
|
+
| Claude | `SessionStart`, `UserPromptSubmit`, `PermissionRequest`, `Stop`, `StopFailure`, `SessionEnd` | `PreToolUse`, `PostToolUse`, `PostToolUseFailure` | Same normalized core decisions and scope rules as Codex |
|
|
201
|
+
|
|
202
|
+
The adapters are versioned fixtures rather than a promise that future Agent releases keep identical native fields. New or unrecognized tools fail closed as possible writes; Hook enforcement does not cover bypassed or disabled Hooks, external editors, or arbitrary OS processes.
|
|
203
|
+
|
|
163
204
|
## Update and language
|
|
164
205
|
|
|
165
206
|
```bash
|
|
166
207
|
code-workspace update --json
|
|
167
208
|
code-workspace update --language zh-CN --json
|
|
209
|
+
code-workspace update --coordination --json
|
|
168
210
|
code-workspace language --json
|
|
169
211
|
```
|
|
170
212
|
|
package/README.zh-CN.md
CHANGED
|
@@ -34,14 +34,15 @@ code-workspace init . \
|
|
|
34
34
|
```
|
|
35
35
|
|
|
36
36
|
可用 `--tools claude`、`--tools codex` 或 `--tools none` 覆盖默认工具选择。选择 Codex 时默认启用监控;可传 `--no-monitor` 关闭。
|
|
37
|
+
传入 `--coordination` 可把与 Monitor 独立的写入协调 Hook 安装到选中工具的原生配置中。
|
|
37
38
|
|
|
38
39
|
初始化只写入 Workspace 自有状态和集成:
|
|
39
40
|
|
|
40
|
-
- `.code-workspace/config.yaml
|
|
41
|
+
- `.code-workspace/config.yaml`、其引用的项目配置文件(默认:`.code-workspace/config-projects.yaml`)与 `.code-workspace/state.json`
|
|
41
42
|
- `USER_GUIDE.md`
|
|
42
43
|
- `CLAUDE.md` 和/或 `AGENTS.md`
|
|
43
44
|
- 名称以 `code-workspace-` 开头或使用 `/code-workspace` 命名空间的 Workspace 专用命令与 Skill
|
|
44
|
-
-
|
|
45
|
+
- 启用监控或 Codex 协调时的 `.codex/hooks.json`,以及启用 Claude 协调时的 `.claude/settings.json`
|
|
45
46
|
|
|
46
47
|
它不会创建 `openspec/`,不会安装原生 `/opsx` 命令,也不会安装原生 `openspec-*` Skill。
|
|
47
48
|
|
|
@@ -67,7 +68,10 @@ code-w extension uninstall zhuiyi-jira-mcp --yes
|
|
|
67
68
|
|
|
68
69
|
扩展入口在独立 Node 进程中运行,只向临时 staging 目录生成文件。Host 会在事务安装前拒绝未声明、缺失、符号链接、非文件、路径逃逸、目标冲突和 hash 不匹配的制品。Workspace 状态存放在 `.code-workspace/ext-manifest.json`。扩展失败以 warning 报告,不回滚已成功的核心初始化,也不阻止后续扩展;升级失败会恢复并保留旧的已安装版本。
|
|
69
70
|
|
|
70
|
-
|
|
71
|
+
扩展可以独占完整文件,也可以声明由 Host 管理的抽象 Hook。Host 通过 Codex/Claude adaptor
|
|
72
|
+
把声明转换为各自的原生配置,并在扩展安装、升级和卸载时动态插拔;共享目标由 Code
|
|
73
|
+
Workspace 合成和验证,扩展不会直接 patch 真实 Workspace。卸载只使用已安装状态,不执行
|
|
74
|
+
扩展代码;扩展所有的文件或贡献存在未知修改时会拒绝覆盖或删除。
|
|
71
75
|
|
|
72
76
|
这是故障隔离,不是恶意代码安全沙箱。试验版本只信任随 Code Workspace 发布的扩展代码;暂不支持网络源、外部扩展目录、扩展依赖、任意 patch、强制卸载、禁用命令,也不会通过 `code-w update` 自动更新扩展。开发契约见 `docs/extensions.zh-CN.md`。
|
|
73
77
|
|
|
@@ -93,7 +97,7 @@ code-workspace project add --projects-file projects.json --yes --json
|
|
|
93
97
|
|
|
94
98
|
注册表保存项目名称、真实路径、注册分支、类型和上下文。注册分支是 Code Workspace 的期望状态,实际分支是从选中 Git worktree 观测到的状态。Workspace 不会根据对话猜测路径,也不会自动判断哪一侧分支更权威。
|
|
95
99
|
|
|
96
|
-
项目注册配置始终独立保存于 `.code-workspace
|
|
100
|
+
项目注册配置始终独立保存于 `.code-workspace` 目录下的单独文件。初始化默认使用 `config-projects.yaml`,但 `projects.ref` 可以引用该目录下任意安全的普通文件名:
|
|
97
101
|
|
|
98
102
|
```yaml
|
|
99
103
|
# .code-workspace/config.yaml
|
|
@@ -115,7 +119,9 @@ projects:
|
|
|
115
119
|
服务职责和代码导航上下文。
|
|
116
120
|
```
|
|
117
121
|
|
|
118
|
-
`projects.ref` 相对于 `config.yaml`
|
|
122
|
+
`projects.ref` 相对于 `config.yaml` 解析,必须是同一 `.code-workspace` 目录下的安全普通文件名。不支持 URL、glob、绝对路径、路径逃逸或内联 `projects` 数组。所有项目 CLI 的语义保持不变,只是改为读取和写入引用文件。`.code-workspace/` 默认被忽略;如需 Git 历史,需要显式制定仓库策略。
|
|
123
|
+
|
|
124
|
+
例如,`ref: team-projects.yaml` 会将项目注册表放在 `.code-workspace/team-projects.yaml`;默认名称仍为 `config-projects.yaml`。
|
|
119
125
|
|
|
120
126
|
## 日常命令
|
|
121
127
|
|
|
@@ -141,7 +147,7 @@ code-workspace doctor --json
|
|
|
141
147
|
|
|
142
148
|
两条命令都会检查计划漂移并验证后置条件。`project branch update-latest` 是独立的显式配置路径:仅当项目 `updateLatest: true` 时,才对干净且分支一致的 worktree fetch upstream 并 fast-forward。Code Workspace 不会创建或下载分支,也不会执行 stash、reset、rebase、非 fast-forward merge、生产代码编辑或冲突处理。
|
|
143
149
|
|
|
144
|
-
用户可以手动在
|
|
150
|
+
用户可以手动在 `projects.ref` 指定的文件(默认:`.code-workspace/config-projects.yaml`)中设置项目策略:
|
|
145
151
|
|
|
146
152
|
```yaml
|
|
147
153
|
# .code-workspace/config-projects.yaml
|
|
@@ -160,11 +166,45 @@ AI/Agent 不得直接编辑该文件;可以读取策略并调用已注册的 C
|
|
|
160
166
|
|
|
161
167
|
`permissions apply` 会展示选中 Agent 工具的完整授权计划,在需要修改时要求确认,实施并验证请求的授权,并按工具报告结果。Agent 目录访问仍属于用户授权。该命令只补齐已注册项目缺失的访问权限,不撤销额外目录;如需撤销,请使用 `project remove` 或显式编辑 Agent 设置。
|
|
162
168
|
|
|
169
|
+
## 协调并行 Agent 写入
|
|
170
|
+
|
|
171
|
+
安装并信任 Codex 或 Claude 协调 Hook 后,Code Workspace 会把协调台账保存在 Workspace 外部,并在受支持工具真正运行前预约写入范围。同一项目写不同文件时,经过一次明确的项目并行确认即可继续;范围重叠时强制拒绝,不提供强制覆盖。
|
|
172
|
+
|
|
173
|
+
查询任务、范围 claim 和待处理裁决:
|
|
174
|
+
|
|
175
|
+
```bash
|
|
176
|
+
code-workspace task list --json
|
|
177
|
+
code-workspace task show <task-id> --json
|
|
178
|
+
code-workspace task lock list --json
|
|
179
|
+
code-workspace task decision show <request-id> --json
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
查看证据后再处理裁决。写入型命令需要确认;自动化场景必须传 `--yes`,裁决成功后始终重新执行原 Agent 操作:
|
|
183
|
+
|
|
184
|
+
```bash
|
|
185
|
+
code-workspace task decision keep <request-id> --yes --json
|
|
186
|
+
code-workspace task decision approve <request-id> --yes --json
|
|
187
|
+
code-workspace task decision release <request-id> --yes --json
|
|
188
|
+
code-workspace task decision abandon <request-id> --yes --json
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
`ACTIVE` 文件冲突不能覆盖。`UNKNOWN` reservation 必须由用户选择保留,或放弃整个 generation;已知旧进程仍存活时不能 abandon。该机制只覆盖已信任、已启用且受支持的 Agent Hook,不是编辑器、Shell 或外部进程的 OS 级沙箱。
|
|
192
|
+
|
|
193
|
+
Hook 支持矩阵(schema v1):
|
|
194
|
+
|
|
195
|
+
| Provider | 生命周期事件 | 写入事件 | 目标处理 |
|
|
196
|
+
| --- | --- | --- | --- |
|
|
197
|
+
| Codex | `SessionStart`、`UserPromptSubmit`、`PermissionRequest`、`Stop`、`SessionEnd` | `PreToolUse`、`PostToolUse` 及可用失败事件 | 已知 Edit/Write 类工具使用 exact 文件;未知 Shell/工具使用 `PROJECT_WIDE` |
|
|
198
|
+
| Claude | `SessionStart`、`UserPromptSubmit`、`PermissionRequest`、`Stop`、`StopFailure`、`SessionEnd` | `PreToolUse`、`PostToolUse`、`PostToolUseFailure` | 与 Codex 使用相同的归一化核心决策和范围规则 |
|
|
199
|
+
|
|
200
|
+
适配器通过版本化 fixture 固化输入,而不是承诺未来 Agent 版本保持相同原生字段。新增或无法识别的工具按可能写入处理并 fail closed;Hook 强制范围不包含被绕过或禁用的 Hook、外部编辑器或任意 OS 进程。
|
|
201
|
+
|
|
163
202
|
## 更新与语言
|
|
164
203
|
|
|
165
204
|
```bash
|
|
166
205
|
code-workspace update --json
|
|
167
206
|
code-workspace update --language en-US --json
|
|
207
|
+
code-workspace update --coordination --json
|
|
168
208
|
code-workspace language --json
|
|
169
209
|
```
|
|
170
210
|
|
package/artifacts/manifest.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": 2,
|
|
3
|
-
"releaseVersion": "0.1.0-beta.
|
|
3
|
+
"releaseVersion": "0.1.0-beta.5",
|
|
4
4
|
"requirements": {
|
|
5
5
|
"node": ">=20.19.0"
|
|
6
6
|
},
|
|
@@ -22,6 +22,17 @@
|
|
|
22
22
|
"sha256": "4dc207305a3975ab7272addedf3bc2930054e860c2b0b2b6e0e102f4457f5cc0"
|
|
23
23
|
}
|
|
24
24
|
],
|
|
25
|
+
"coordinationArtifacts": {
|
|
26
|
+
"schemaVersion": 1,
|
|
27
|
+
"sources": [
|
|
28
|
+
{ "id": "task-coordination-codex-hooks", "path": "templates/codex/task-coordination-hooks.json", "sha256": "68fcefa83f75294fd270713e07eb3ea3f266e63dc9d2be4ba77fe8af7596742f" },
|
|
29
|
+
{ "id": "task-coordination-claude-settings", "path": "templates/claude/task-coordination-settings.json", "sha256": "4faedcc67a78c8e7e61e44dc34571e55d0d3a2ce1ce7aa636222e1813505ca29" }
|
|
30
|
+
],
|
|
31
|
+
"managedFiles": [
|
|
32
|
+
{ "id": "task-coordination-codex-hooks", "target": ".codex/task-coordination-hooks.json", "tool": "codex" },
|
|
33
|
+
{ "id": "task-coordination-claude-settings", "target": ".claude/task-coordination-settings.json", "tool": "claude" }
|
|
34
|
+
]
|
|
35
|
+
},
|
|
25
36
|
"managedFiles": [
|
|
26
37
|
{
|
|
27
38
|
"id": "workspace-user-guide",
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"hooks": {
|
|
3
|
+
"SessionStart": [{ "hooks": [{ "type": "command", "command": "code-workspace-task-hook claude", "timeout": 2 }] }],
|
|
4
|
+
"UserPromptSubmit": [{ "hooks": [{ "type": "command", "command": "code-workspace-task-hook claude", "timeout": 2 }] }],
|
|
5
|
+
"PermissionRequest": [{ "hooks": [{ "type": "command", "command": "code-workspace-task-hook claude", "timeout": 2 }] }],
|
|
6
|
+
"PreToolUse": [{ "matcher": "*", "hooks": [{ "type": "command", "command": "code-workspace-task-hook claude", "timeout": 2 }] }],
|
|
7
|
+
"PostToolUse": [{ "matcher": "*", "hooks": [{ "type": "command", "command": "code-workspace-task-hook claude", "timeout": 2 }] }],
|
|
8
|
+
"PostToolUseFailure": [{ "matcher": "*", "hooks": [{ "type": "command", "command": "code-workspace-task-hook claude", "timeout": 2 }] }],
|
|
9
|
+
"Stop": [{ "hooks": [{ "type": "command", "command": "code-workspace-task-hook claude", "timeout": 2 }] }],
|
|
10
|
+
"StopFailure": [{ "hooks": [{ "type": "command", "command": "code-workspace-task-hook claude", "timeout": 2 }] }],
|
|
11
|
+
"SessionEnd": [{ "hooks": [{ "type": "command", "command": "code-workspace-task-hook claude", "timeout": 2 }] }]
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"description": "Coordinate supported Codex writes before tools execute. This Hook is independent from Monitor reporting.",
|
|
3
|
+
"hooks": {
|
|
4
|
+
"SessionStart": [{ "hooks": [{ "type": "command", "command": "code-workspace-task-hook codex", "timeout": 2 }] }],
|
|
5
|
+
"UserPromptSubmit": [{ "hooks": [{ "type": "command", "command": "code-workspace-task-hook codex", "timeout": 2 }] }],
|
|
6
|
+
"PermissionRequest": [{ "hooks": [{ "type": "command", "command": "code-workspace-task-hook codex", "timeout": 2 }] }],
|
|
7
|
+
"PreToolUse": [{ "matcher": "*", "hooks": [{ "type": "command", "command": "code-workspace-task-hook codex", "timeout": 2 }] }],
|
|
8
|
+
"PostToolUse": [{ "matcher": "*", "hooks": [{ "type": "command", "command": "code-workspace-task-hook codex", "timeout": 2 }] }],
|
|
9
|
+
"Stop": [{ "hooks": [{ "type": "command", "command": "code-workspace-task-hook codex", "timeout": 2 }] }],
|
|
10
|
+
"SessionEnd": [{ "hooks": [{ "type": "command", "command": "code-workspace-task-hook codex", "timeout": 2 }] }]
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
const { runHookStdin } = require("../src/core/task-coordination-protocol");
|
|
5
|
+
|
|
6
|
+
const provider = String(process.argv[2] || "").toLowerCase();
|
|
7
|
+
let workspaceRoot = process.cwd();
|
|
8
|
+
for (let index = 3; index < process.argv.length; index += 1) {
|
|
9
|
+
const argument = process.argv[index];
|
|
10
|
+
if (argument === "--workspace-root-b64") {
|
|
11
|
+
const encoded = process.argv[++index];
|
|
12
|
+
try {
|
|
13
|
+
workspaceRoot = Buffer.from(String(encoded || ""), "base64url").toString("utf8");
|
|
14
|
+
if (!workspaceRoot) throw new Error("empty path");
|
|
15
|
+
} catch {
|
|
16
|
+
process.stdout.write(JSON.stringify({ decision: "block", reason: "Invalid task coordination Hook workspace root." }) + "\n");
|
|
17
|
+
process.exitCode = 2;
|
|
18
|
+
break;
|
|
19
|
+
}
|
|
20
|
+
} else if (argument === "--workspace-root") {
|
|
21
|
+
workspaceRoot = String(process.argv[++index] || "");
|
|
22
|
+
} else {
|
|
23
|
+
process.stdout.write(JSON.stringify({ decision: "block", reason: `Unsupported task coordination Hook option: ${argument}` }) + "\n");
|
|
24
|
+
process.exitCode = 2;
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
if (!["codex", "claude"].includes(provider)) {
|
|
29
|
+
process.stdout.write(JSON.stringify({ decision: "block", reason: "Unsupported task coordination Hook provider." }) + "\n");
|
|
30
|
+
process.exitCode = 2;
|
|
31
|
+
} else if (process.exitCode !== 2) {
|
|
32
|
+
runHookStdin(provider, { workspaceRoot })
|
|
33
|
+
.then((output) => process.stdout.write(`${JSON.stringify(output)}\n`))
|
|
34
|
+
.catch((error) => {
|
|
35
|
+
process.stdout.write(`${JSON.stringify({ decision: "block", reason: `Task coordination Hook failed closed: ${error.message}` })}\n`);
|
|
36
|
+
process.exitCode = 1;
|
|
37
|
+
});
|
|
38
|
+
}
|
|
@@ -64,6 +64,10 @@ Host 是 Code Workspace 中负责扩展生命周期治理的核心实现。Host
|
|
|
64
64
|
|
|
65
65
|
扩展仓库是 Code Workspace 发布包中用于保存内置扩展的目录集合。基础版不从网络发现或安装扩展定义。
|
|
66
66
|
|
|
67
|
+
扩展还可以通过 manifest 的 `hooks` 声明抽象 Workspace Hook。Hook 声明由 Host 通过
|
|
68
|
+
Codex/Claude adaptor 转换为原生配置,并随扩展安装、升级和卸载动态插拔;扩展不得把
|
|
69
|
+
Provider 原生事件名直接写入公共合同。
|
|
70
|
+
|
|
67
71
|
### 4.3 扩展包
|
|
68
72
|
|
|
69
73
|
扩展包是一个符合扩展协议的、具有明确 id 和版本的可执行目录:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "code-workspace-zhuiyi",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.5",
|
|
4
4
|
"description": "Local multi-project registry and safety layer for AI coding workspaces",
|
|
5
5
|
"author": "icebearx-ai",
|
|
6
6
|
"license": "MIT",
|
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
},
|
|
14
14
|
"bin": {
|
|
15
15
|
"code-workspace": "bin/code-workspace.js",
|
|
16
|
-
"code-w": "bin/code-workspace.js"
|
|
16
|
+
"code-w": "bin/code-workspace.js",
|
|
17
|
+
"code-workspace-task-hook": "bin/code-workspace-task-hook.js"
|
|
17
18
|
},
|
|
18
19
|
"files": [
|
|
19
20
|
"assets",
|
|
@@ -22,6 +23,7 @@
|
|
|
22
23
|
"src/cli",
|
|
23
24
|
"src/index.js",
|
|
24
25
|
"src/core",
|
|
26
|
+
"src/hooks",
|
|
25
27
|
"src/i18n",
|
|
26
28
|
"src/init",
|
|
27
29
|
"src/monitor",
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"title": "Code Workspace Extension Spec v1 manifest schema v3",
|
|
5
5
|
"type": "object",
|
|
6
6
|
"additionalProperties": false,
|
|
7
|
-
"required": ["schemaVersion", "extensionSpecVersion", "experimental", "id", "name", "version", "entry", "entrySha256", "timeoutMs"
|
|
7
|
+
"required": ["schemaVersion", "extensionSpecVersion", "experimental", "id", "name", "version", "entry", "entrySha256", "timeoutMs"],
|
|
8
8
|
"properties": {
|
|
9
9
|
"schemaVersion": { "const": 3 },
|
|
10
10
|
"extensionSpecVersion": { "const": 1 },
|
|
@@ -69,8 +69,33 @@
|
|
|
69
69
|
}
|
|
70
70
|
]
|
|
71
71
|
}
|
|
72
|
+
},
|
|
73
|
+
"hooks": {
|
|
74
|
+
"type": "array",
|
|
75
|
+
"items": {
|
|
76
|
+
"type": "object",
|
|
77
|
+
"additionalProperties": false,
|
|
78
|
+
"required": ["id", "event", "command"],
|
|
79
|
+
"properties": {
|
|
80
|
+
"id": { "$ref": "#/$defs/id" },
|
|
81
|
+
"event": { "enum": ["task.started", "task.activity", "write.before", "write.after", "task.turn-ended", "task.ended", "task.subagent-started", "task.subagent-ended", "session.start", "session.activity", "session.end", "turn.end", "subagent.start", "subagent.end", "pre-write", "post-write"] },
|
|
82
|
+
"command": { "type": "string", "minLength": 1, "maxLength": 4096, "pattern": "^[^\\r\\n]+$" },
|
|
83
|
+
"tools": {
|
|
84
|
+
"type": "array",
|
|
85
|
+
"minItems": 1,
|
|
86
|
+
"uniqueItems": true,
|
|
87
|
+
"items": { "enum": ["claude", "codex"] }
|
|
88
|
+
},
|
|
89
|
+
"matcher": { "type": "string", "minLength": 1, "maxLength": 1024, "pattern": "^[^\\r\\n]+$" },
|
|
90
|
+
"timeoutMs": { "type": "integer", "minimum": 1, "maximum": 300000 }
|
|
91
|
+
}
|
|
92
|
+
}
|
|
72
93
|
}
|
|
73
94
|
},
|
|
95
|
+
"anyOf": [
|
|
96
|
+
{ "required": ["outputs"], "properties": { "outputs": { "minItems": 1 } } },
|
|
97
|
+
{ "required": ["hooks"], "properties": { "hooks": { "minItems": 1 } } }
|
|
98
|
+
],
|
|
74
99
|
"$defs": {
|
|
75
100
|
"id": { "type": "string", "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$" },
|
|
76
101
|
"sha256": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
|
|
@@ -134,6 +134,42 @@ Spec v1 supports four output kinds:
|
|
|
134
134
|
|
|
135
135
|
Public output kinds MUST NOT encode private business concepts such as Jira, MCP, npm, archive formats, or individual Agent products.
|
|
136
136
|
|
|
137
|
+
### 7.1 Abstract Hook declarations
|
|
138
|
+
|
|
139
|
+
An extension MAY declare pluggable Workspace Hooks. Hooks are not extension output files and
|
|
140
|
+
MUST NOT declare Provider-native names such as `PreToolUse` or `SessionStart`. The optional
|
|
141
|
+
manifest `hooks` array contains entries with at least `id`, `event`, and `command`:
|
|
142
|
+
|
|
143
|
+
```json
|
|
144
|
+
{
|
|
145
|
+
"hooks": [
|
|
146
|
+
{
|
|
147
|
+
"id": "audit-task",
|
|
148
|
+
"event": "task.activity",
|
|
149
|
+
"command": "code-workspace-plugin-audit",
|
|
150
|
+
"tools": ["codex", "claude"],
|
|
151
|
+
"matcher": "*",
|
|
152
|
+
"timeoutMs": 2
|
|
153
|
+
}
|
|
154
|
+
]
|
|
155
|
+
}
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
Supported abstract events are `task.started`, `task.activity`, `write.before`, `write.after`,
|
|
159
|
+
`task.turn-ended`, `task.ended`, `task.subagent-started`, and `task.subagent-ended`.
|
|
160
|
+
The aliases `session.start`, `session.activity`, `session.end`, `turn.end`, `subagent.start`,
|
|
161
|
+
`subagent.end`, `pre-write`, and `post-write` are accepted and normalized to those events.
|
|
162
|
+
When `tools` is omitted, the declaration applies to every tool supported by the Host.
|
|
163
|
+
`command` is a trusted extension Hook entry point. The Host validates the declaration, renders
|
|
164
|
+
it through a Provider adaptor, and governs its lifecycle; it does not interpret arbitrary native
|
|
165
|
+
configuration fragments.
|
|
166
|
+
|
|
167
|
+
Codex and Claude adaptors map one abstract event to their native events and compose only the
|
|
168
|
+
extension-owned entries. Install, upgrade, and uninstall use installed Workspace state;
|
|
169
|
+
uninstall does not execute extension code and preserves user and other-extension Hooks. If an
|
|
170
|
+
installed contribution is missing, duplicated, or modified, the Host MUST fail closed and roll
|
|
171
|
+
back the transaction.
|
|
172
|
+
|
|
137
173
|
## 8. Staging Verification
|
|
138
174
|
|
|
139
175
|
An extension MUST generate candidate content only inside the staging directory supplied by the Host. The Host MUST:
|
|
@@ -133,6 +133,40 @@ Spec v1 支持四种输出:
|
|
|
133
133
|
|
|
134
134
|
公共输出不得包含 Jira、MCP、npm、归档或特定 Agent 产品的业务类型。
|
|
135
135
|
|
|
136
|
+
### 7.1 抽象 Hook 声明
|
|
137
|
+
|
|
138
|
+
扩展可以声明可插拔的 Workspace Hook。Hook 不是扩展输出文件,也不得直接声明
|
|
139
|
+
`PreToolUse`、`SessionStart` 等 Provider 原生名称。manifest 的 `hooks` 是一个可选数组,
|
|
140
|
+
每项至少包含 `id`、`event` 和 `command`:
|
|
141
|
+
|
|
142
|
+
```json
|
|
143
|
+
{
|
|
144
|
+
"hooks": [
|
|
145
|
+
{
|
|
146
|
+
"id": "audit-task",
|
|
147
|
+
"event": "task.activity",
|
|
148
|
+
"command": "code-workspace-plugin-audit",
|
|
149
|
+
"tools": ["codex", "claude"],
|
|
150
|
+
"matcher": "*",
|
|
151
|
+
"timeoutMs": 2
|
|
152
|
+
}
|
|
153
|
+
]
|
|
154
|
+
}
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
支持的抽象事件为 `task.started`、`task.activity`、`write.before`、`write.after`、
|
|
158
|
+
`task.turn-ended`、`task.ended`、`task.subagent-started` 和 `task.subagent-ended`。
|
|
159
|
+
`session.start`、`session.activity`、`session.end`、`turn.end`、`subagent.start`、
|
|
160
|
+
`subagent.end`、`pre-write` 和 `post-write` 作为兼容别名会被规范化为上述事件。
|
|
161
|
+
`tools` 缺省时表示适用于 Host 支持的全部工具。`command` 是可信扩展提供的 Hook
|
|
162
|
+
执行入口;Host 只负责声明校验、适配器渲染和生命周期治理,不把它解释为任意原生
|
|
163
|
+
配置片段。
|
|
164
|
+
|
|
165
|
+
Codex 与 Claude 的适配器会把一个抽象事件映射到各自的原生事件,并只合成扩展拥有的
|
|
166
|
+
局部 entry。安装、升级和卸载均依据 Workspace 中的 installed 状态完成;卸载不执行
|
|
167
|
+
扩展代码,并保留用户及其他扩展的 Hook。扩展 Hook 被手动删除、重复或修改时,Host
|
|
168
|
+
必须 fail closed 并回滚本次事务。
|
|
169
|
+
|
|
136
170
|
## 8. Staging 验证
|
|
137
171
|
|
|
138
172
|
扩展只能在 Host 提供的 staging 目录生成候选内容。Host 必须:
|
|
@@ -32,6 +32,7 @@ function formatInstallPlan(plans) {
|
|
|
32
32
|
` ${plan.id}@${plan.version} [Extension Spec ${plan.extensionSpecVersion}] (manifest ${plan.manifestSha256})`,
|
|
33
33
|
...(plan.capabilities.networkHosts || []).map((host) => ` NETWORK https://${host}`),
|
|
34
34
|
...plan.artifacts.map((artifact) => ` WRITE ${artifact.target} (${artifact.kind})`),
|
|
35
|
+
...(plan.hooks || []).map((hook) => ` HOOK ${hook.id} (${hook.event}${hook.tools?.length ? ` · ${hook.tools.join(",")}` : ""}) -> ${hook.command}`),
|
|
35
36
|
]),
|
|
36
37
|
].join("\n");
|
|
37
38
|
}
|
|
@@ -69,6 +70,7 @@ function installResultEntry(entry) {
|
|
|
69
70
|
extensionSpecVersion: entry.extensionSpecVersion,
|
|
70
71
|
...(entry.reason ? { reason: entry.reason } : {}),
|
|
71
72
|
...(entry.artifacts ? { artifacts: entry.artifacts } : {}),
|
|
73
|
+
...(entry.hooks ? { hooks: entry.hooks } : {}),
|
|
72
74
|
...(entry.code ? { code: entry.code } : {}),
|
|
73
75
|
...(entry.message ? { message: entry.message } : {}),
|
|
74
76
|
...(entry.statePersisted !== undefined ? { statePersisted: entry.statePersisted } : {}),
|
package/src/cli/commands/init.js
CHANGED
|
@@ -111,6 +111,7 @@ async function executeInitUnlocked(invocation, root) {
|
|
|
111
111
|
const extensionPreparation = prepareExtensionPlans(extensionCatalogResult, requestedExtensions, { tools, state: extensionState, stateError: extensionStateInspection.error });
|
|
112
112
|
const extensionPlans = extensionPreparation.plans;
|
|
113
113
|
const toolSelection = { tools, source: plan ? (options.tools !== undefined ? "cli" : "interactive") : resolvedTools.source };
|
|
114
|
+
const coordination = options.coordination === true || existingState?.coordination === true;
|
|
114
115
|
const result = await initializeWorkspace(root, {
|
|
115
116
|
run,
|
|
116
117
|
tools,
|
|
@@ -120,6 +121,7 @@ async function executeInitUnlocked(invocation, root) {
|
|
|
120
121
|
workspaceUuid: plan?.workspace.uuid,
|
|
121
122
|
monitor: plan?.monitor.enable ?? (options.monitor === true ? true : options["no-monitor"] === true ? false : undefined),
|
|
122
123
|
monitorUrl: plan?.monitor.url || options["monitor-url"],
|
|
124
|
+
coordination,
|
|
123
125
|
language: plan?.language || options.language,
|
|
124
126
|
interactive: false,
|
|
125
127
|
initPlan: plan,
|
|
@@ -172,6 +174,7 @@ async function executeInitUnlocked(invocation, root) {
|
|
|
172
174
|
monitor: result.workspaceConfig.monitor,
|
|
173
175
|
language: result.language,
|
|
174
176
|
tools: toolSelection,
|
|
177
|
+
coordination,
|
|
175
178
|
migration: migrationData(result.migration),
|
|
176
179
|
permissions: result.permissions,
|
|
177
180
|
verification: result.verification,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const { configPath, loadConfigProjection,
|
|
1
|
+
const { configPath, loadConfigProjection, resolveProjectConfigPath, updateProjectBranch } = require("../../core/config");
|
|
2
2
|
const { WorkspaceError } = require("../../core/errors");
|
|
3
3
|
const {
|
|
4
4
|
assertRegisteredBranchSwitchAvailable,
|
|
@@ -54,7 +54,7 @@ function applyAcceptActual(root, plan, options = {}) {
|
|
|
54
54
|
const currentConfig = load(root, ["projects"]);
|
|
55
55
|
assertAcceptPlanCurrent(plan, inspect(currentConfig, plan.project.name, options));
|
|
56
56
|
|
|
57
|
-
const transaction = createFileTransaction([configPath(root),
|
|
57
|
+
const transaction = createFileTransaction([configPath(root), resolveProjectConfigPath(root)]);
|
|
58
58
|
try {
|
|
59
59
|
(options.updateProjectBranch || updateProjectBranch)(root, {
|
|
60
60
|
name: plan.project.name,
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const yaml = require("js-yaml");
|
|
4
|
+
|
|
5
|
+
const { WorkspaceError } = require("../../core/errors");
|
|
6
|
+
const coordination = require("../../core/task-coordination");
|
|
7
|
+
const { confirm } = require("../confirmation");
|
|
8
|
+
const { success } = require("../result");
|
|
9
|
+
|
|
10
|
+
function commandFor(path) {
|
|
11
|
+
return path.join(".");
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function context(invocation) {
|
|
15
|
+
const workspaceUuid = invocation.config?.workspace?.uuid;
|
|
16
|
+
if (!workspaceUuid) throw new WorkspaceError("WORKSPACE_IDENTITY_INVALID", "Workspace identity is required for task coordination commands.", { remediation: "Run code-w doctor --json and repair workspace identity." });
|
|
17
|
+
return {
|
|
18
|
+
workspaceRoot: invocation.root,
|
|
19
|
+
workspaceUuid,
|
|
20
|
+
stateDirectory: invocation.options?.stateDirectory,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function textBlock(value) {
|
|
25
|
+
return yaml.dump(value, { lineWidth: -1, noRefs: true, sortKeys: false });
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async function executeDecision(action, requestId, invocation) {
|
|
29
|
+
const options = invocation.options || {};
|
|
30
|
+
const base = context(invocation);
|
|
31
|
+
const plan = coordination.planDecision(requestId, action, base);
|
|
32
|
+
if (!(await confirm(`Apply task decision ${action} to ${requestId}?`, options))) throw new WorkspaceError("CLI_CANCELLED", "Task decision cancelled.");
|
|
33
|
+
const applied = await coordination.applyDecision(plan, base);
|
|
34
|
+
const inspected = coordination.inspectDecision(requestId, base);
|
|
35
|
+
if (inspected.decision.status !== "RESOLVED" || inspected.decision.resolution !== action) {
|
|
36
|
+
throw new WorkspaceError("TASK_DECISION_POSTCONDITION_FAILED", "Task decision was not fully persisted and verified.", { decisionRequestId: requestId, action, remediation: "Run task decision show and retry after inspecting the ledger." });
|
|
37
|
+
}
|
|
38
|
+
const retry = applied.retryRequired ? " Retry the original Agent operation." : "";
|
|
39
|
+
return success(commandFor(["task", "decision", action]), { ...applied, inspected }, `Applied task decision ${action} for ${requestId}.${retry}`);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async function executeTask(invocation) {
|
|
43
|
+
const path = invocation.definition.path;
|
|
44
|
+
const action = path[1];
|
|
45
|
+
const base = context(invocation);
|
|
46
|
+
if (action === "list") {
|
|
47
|
+
const result = coordination.inspectTasks(base);
|
|
48
|
+
const text = result.tasks.length === 0 ? "No coordinated tasks." : result.tasks.map((task) => `${task.taskId}\t${task.provider}\t${task.status}\t${task.phase}\t${task.lastSeenAt}`).join("\n");
|
|
49
|
+
return success("task.list", result, text);
|
|
50
|
+
}
|
|
51
|
+
if (action === "show") {
|
|
52
|
+
const task = coordination.inspectTask(invocation.args[0], base);
|
|
53
|
+
return success("task.show", { task }, textBlock(task));
|
|
54
|
+
}
|
|
55
|
+
if (action === "lock" && path[2] === "list") {
|
|
56
|
+
const result = coordination.inspectLocks(base);
|
|
57
|
+
const text = result.claims.length === 0 ? "No active task claims." : result.claims.filter((claim) => claim.enforcement).map((claim) => `${claim.claimId}\t${claim.type}\t${claim.taskId}\t${claim.scope.type}\t${claim.scope.path}`).join("\n");
|
|
58
|
+
return success("task.lock.list", result, text);
|
|
59
|
+
}
|
|
60
|
+
if (action === "decision") {
|
|
61
|
+
const verb = path[2];
|
|
62
|
+
const requestId = invocation.args[0];
|
|
63
|
+
if (verb === "show") {
|
|
64
|
+
const result = coordination.inspectDecision(requestId, base);
|
|
65
|
+
return success("task.decision.show", result, textBlock(result));
|
|
66
|
+
}
|
|
67
|
+
if (["keep", "approve", "release", "abandon"].includes(verb)) {
|
|
68
|
+
const map = { keep: "KEEP", approve: "APPROVE_PROJECT_PARALLEL", release: "RELEASE_CLAIM", abandon: "ABANDON_TASK_AND_RELEASE" };
|
|
69
|
+
return executeDecision(map[verb], requestId, invocation);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
throw new WorkspaceError("CLI_UNKNOWN_COMMAND", `Unknown task command: ${path.join(" ")}`);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
module.exports = { executeTask };
|