cowork-flow 0.0.26 → 0.0.28

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 (55) hide show
  1. package/README.md +16 -8
  2. package/package.json +1 -1
  3. package/src/lib/copy-template.js +2 -2
  4. package/template/.agents/skills/before-dev/SKILL.md +1 -0
  5. package/template/.agents/skills/check/SKILL.md +1 -0
  6. package/template/.agents/skills/party-mode-v2/SKILL.md +75 -0
  7. package/template/.agents/skills/tdd/SKILL.md +61 -0
  8. package/template/.agents/skills/writing-plans/SKILL.md +1 -0
  9. package/template/.claude/agents/cowork-implement.md +153 -0
  10. package/template/.claude/hooks/inject-workflow-state.py +17 -8
  11. package/template/.claude/skills/before-dev/SKILL.md +1 -0
  12. package/template/.claude/skills/check/SKILL.md +1 -0
  13. package/template/.claude/skills/party-mode-v2/SKILL.md +75 -0
  14. package/template/.claude/skills/tdd/SKILL.md +61 -0
  15. package/template/.claude/skills/writing-plans/SKILL.md +1 -0
  16. package/template/.codex/agents/cowork-check.toml +2 -0
  17. package/template/.codex/agents/cowork-implement.toml +2 -0
  18. package/template/.codex/hooks/inject-workflow-state.py +17 -8
  19. package/template/.cowork-flow/.version +1 -1
  20. package/template/.cowork-flow/config.yaml +16 -0
  21. package/template/.cowork-flow/scripts/common/archive_utils.py +1 -1
  22. package/template/.cowork-flow/scripts/common/coding_standards.py +209 -0
  23. package/template/.cowork-flow/scripts/common/config.py +93 -0
  24. package/template/.cowork-flow/scripts/common/gates.py +66 -0
  25. package/template/.cowork-flow/scripts/common/git_snapshot.py +83 -0
  26. package/template/.cowork-flow/scripts/common/state_machine.py +57 -0
  27. package/template/.cowork-flow/scripts/common/tdd_evidence.py +301 -0
  28. package/template/.cowork-flow/scripts/common/test_intent.py +265 -0
  29. package/template/.cowork-flow/scripts/common/validate_coding_standards.py +181 -0
  30. package/template/.cowork-flow/scripts/common/validate_implementation.py +243 -0
  31. package/template/.cowork-flow/scripts/common/validate_rules.py +465 -0
  32. package/template/.cowork-flow/scripts/doctor.py +18 -36
  33. package/template/.cowork-flow/scripts/party_mode_v2.py +1162 -0
  34. package/template/.cowork-flow/scripts/run.py +3 -0
  35. package/template/.cowork-flow/scripts/task.py +190 -0
  36. package/template/.cowork-flow/spec/contracts/index.md +12 -0
  37. package/template/.cowork-flow/spec/contracts/party-mode-v2-board.md +68 -0
  38. package/template/.cowork-flow/spec/{subagent-dispatch.md → contracts/subagent-dispatch.md} +2 -0
  39. package/template/.cowork-flow/spec/{workflow-state-templates.md → contracts/workflow-state-templates.md} +1 -1
  40. package/template/.cowork-flow/spec/index.md +15 -0
  41. package/template/.cowork-flow/spec/{registry.json → runtime/contract-registry.json} +17 -4
  42. package/template/.cowork-flow/spec/runtime/index.md +10 -0
  43. package/template/.cowork-flow/spec/runtime/rules.json +173 -0
  44. package/template/.cowork-flow/spec/schemas/index.md +10 -0
  45. package/template/.cowork-flow/spec/schemas/party-mode-v2-actions.schema.json +90 -0
  46. package/template/.cowork-flow/spec/schemas/rules.schema.json +80 -0
  47. package/template/.cowork-flow/workflow.md +13 -7
  48. package/template/.opencode/agents/cowork-implement.md +153 -0
  49. package/template/.opencode/commands/party-mode-v2.md +26 -0
  50. package/template/.opencode/plugins/cowork-flow.js +18 -7
  51. package/template/AGENTS.md +2 -6
  52. package/template/.cowork-flow/scripts/common/entry_classifier.py +0 -122
  53. /package/template/.cowork-flow/spec/{capabilities.md → contracts/capabilities.md} +0 -0
  54. /package/template/.cowork-flow/spec/{entry-contract.md → contracts/entry-contract.md} +0 -0
  55. /package/template/.cowork-flow/spec/{adapter.schema.json → schemas/adapter.schema.json} +0 -0
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # cowork-flow
1
+ # cowork-flow
2
2
 
3
3
  cowork-flow 是一个用于新项目初始化协作流程的模板仓库。它把项目说明、任务流转、规格治理、开发计划和会话记录放在一套可复制的目录结构里,帮助团队在项目早期就建立清晰的工作闭环。
4
4
 
@@ -43,6 +43,12 @@ cowork-flow 是一个用于新项目初始化协作流程的模板仓库。它
43
43
  ├── workflow.md
44
44
  ├── scripts/
45
45
  ├── spec/
46
+ │ ├── contracts/
47
+ │ ├── runtime/
48
+ │ ├── schemas/
49
+ │ ├── backend/
50
+ │ ├── frontend/
51
+ │ └── guides/
46
52
  ├── changes/
47
53
  ├── plans/
48
54
  ├── tasks/
@@ -55,27 +61,29 @@ cowork-flow 是一个用于新项目初始化协作流程的模板仓库。它
55
61
  项目级协作入口,包含编码前思考、简单优先、外科手术式改动、验证优先等基础原则。接入项目后,应把项目名称、技术栈、运行命令、测试命令和提交策略补齐。
56
62
 
57
63
  `template/.agents/skills/`
58
- 本地技能入口,覆盖 start、before-dev、brainstorming、party-mode、writing-plans、check、finish-work、continue、meta、python-design、update-spec 和 break-loop 等协作动作。这里的 skill 应保持通用,不承载某个业务项目的一次性细节。
64
+ 本地技能入口,覆盖 start、before-dev、brainstorming、party-mode、party-mode-v2、writing-plans、check、finish-work、continue、meta、python-design、update-spec 和 break-loop 等协作动作。这里的 skill 应保持通用,不承载某个业务项目的一次性细节。
59
65
 
60
- `party-mode` 是用户手动调用的 advisory roundtable。它通过当前 Host Adapter 协调真实子代理讨论,而不是模拟人设;默认 `max_agents=3`、`max_rounds=3`,配置优先级为本次调用、task/change、本地配置、skill 默认值。Party Mode 只产出建议、证据、分歧和验收信号,不能推进任务状态,也不能替代 `cowork-implement` 或 `cowork-check`。
66
+ `party-mode` 是用户手动调用的 advisory roundtable。它通过当前 Host Adapter 协调真实子代理讨论,而不是模拟人设;默认 `max_agents=3`、`max_rounds=5`,配置优先级为本次调用、task/change、本地配置、skill 默认值。Party Mode 只产出建议、证据、分歧和验收信号,不能推进任务状态,也不能替代 `cowork-implement` 或 `cowork-check`。
67
+
68
+ `party-mode-v2` 是 runtime board controlled advisory workflow。Python runtime 管理看板、当前轮视图、schema 校验、轮次上限和最终报告;子代理通过 board API 交流,主持人只监控和纠偏,不转发或综合观点。
61
69
 
62
70
  `template/.codex/agents/`
63
71
  固定角色 agent 定义,包含 `cowork-research`、`cowork-implement` 和 `cowork-check`,以及对 Codex 默认 `worker`、`default`、`explorer` 的项目级防漂移约束。主会话负责计划与收口,并通过 host adapter 派发固定 agent;正式派发必须先创建 runtime context,再把 `cowork_runtime_context_id` 和 `cowork_host_context_key` 传给子代理。
64
72
 
65
73
  `template/.codex/config.toml`、`template/.codex/hooks.json`、`template/.codex/hooks/`
66
- Codex 项目级配置与每轮上下文注入入口。hook 会先用共享 entry classifier 判定当前输入,再读取当前 session task、`.cowork-flow/spec/workflow-state-templates.md` 中的 `workflow-state` 片段和 `codex.dispatch_mode`,把流程状态注入到当前轮对话。注入的 `codex-dispatch-mode` 只是主会话调度提示,不代表当前线程身份。
74
+ Codex 项目级配置与每轮上下文注入入口。hook 会先解析 runtime context,再读取当前 session task、`.cowork-flow/spec/contracts/workflow-state-templates.md` 中的 `workflow-state` 片段和 `codex.dispatch_mode`,把流程状态注入到当前轮对话。注入的 `codex-dispatch-mode` 只是主会话调度提示,不代表当前线程身份。
67
75
 
68
76
  `template/CLAUDE.md`、`template/.claude/settings.json`、`template/.claude/agents/`、`template/.claude/skills/`、`template/.claude/commands/`、`template/.claude/hooks/`
69
77
  Claude Code 项目级记忆、hook、固定 agent、skills 和 slash command。`CLAUDE.md` 显式导入 `AGENTS.md`。`.claude/settings.json` 注册 `UserPromptSubmit` 和 `SessionStart` hook,注入当前 workflow state 与 contract digest。固定 agent 通过 `.cowork-flow/run subagent init` 生成 runtime context,并在 prompt、env 或 metadata transport 中传递 `cowork_runtime_context_id`;hook 绑定成功后才进入叶子执行,绑定失败则 fail closed,避免被项目 bootstrap 或无任务首屏上下文拉偏。Claude Code 不自动加载 `.agents/skills/`,所以项目技能要放进 `.claude/skills/`。
70
78
 
71
79
  `template/.opencode/agents/`、`template/.opencode/commands/`、`template/.opencode/plugins/`
72
- OpenCode 项目级固定 agent、slash command 和系统上下文注入插件。插件会读取 `.cowork-flow/spec/registry.json`,注入短 contract digest。
80
+ OpenCode 项目级固定 agent、slash command 和系统上下文注入插件。插件会读取 `.cowork-flow/spec/runtime/contract-registry.json`,注入短 contract digest。
73
81
 
74
82
  `template/.cowork-flow/`
75
83
  工作流目录,包含流程说明、任务状态、开发者工作区、项目规范、行为变更规格、实现计划和辅助脚本。`.cowork-flow/config.yaml` 只承载真实接线的 session/journal, Codex hint, and task lifecycle hook settings。
76
84
 
77
85
  `template/.cowork-flow/spec/`
78
- 项目规范目录,预置了 backend、frontend 和 guides 三类说明。接入时应按项目事实保留、改写或删除对应规范。
86
+ 项目规范目录。`contracts/` 存人读 workflow/host/agent 合同,`runtime/` 存运行时读取的规则和 contract registry,`schemas/` 存 JSON Schema,`backend/`、`frontend/`、`guides/` 存工程规范和思考指引。接入时应按项目事实保留、改写或删除对应规范。
79
87
 
80
88
  `template/.cowork-flow/changes/`
81
89
  由 `change.py` 管理 proposal、design、behavior specs 和归档,不维护实现 checklist。
@@ -161,7 +169,7 @@ cowork-flow sync .
161
169
  cowork-flow sync . --dry-run
162
170
  ```
163
171
 
164
- `sync` 会自动识别目标项目已安装的 host 目录:只有 `.codex/` 时只同步 Codex 资产,只有 `.opencode/` 时只同步 OpenCode 资产,两者都有时同步两者;对应 `.cowork-flow/adapters/<host>/` 也按识别出的平台同步。检测到 Codex 或 OpenCode 时会刷新 `.agents/skills/`;Claude Code-only 项目只刷新 `.claude/settings.json`、`.claude/hooks/`、`.claude/skills/`,不会创建 `.agents/skills/`。通用部分默认刷新 `.cowork-flow/scripts/`、`.cowork-flow/spec/workflow-state-templates.md`,以及 `AGENTS.md` 和 `CLAUDE.md` 中的 `<!-- COWORK-FLOW:START --> ... <!-- COWORK-FLOW:END -->` 托管块,保留托管块之外的项目自定义内容。`.cowork-flow/config.yaml`、`.cowork-flow/workflow.md`、除 `workflow-state-templates.md` 外的 `.cowork-flow/spec/`、任务、计划、变更和 workspace 记录默认受保护。只有明确传入 `--force` 时才整文件覆盖保护文件。
172
+ `sync` 会自动识别目标项目已安装的 host 目录:只有 `.codex/` 时只同步 Codex 资产,只有 `.opencode/` 时只同步 OpenCode 资产,两者都有时同步两者;对应 `.cowork-flow/adapters/<host>/` 也按识别出的平台同步。检测到 Codex 或 OpenCode 时会刷新 `.agents/skills/`;Claude Code-only 项目只刷新 `.claude/settings.json`、`.claude/hooks/`、`.claude/skills/`,不会创建 `.agents/skills/`。通用部分默认刷新 `.cowork-flow/scripts/`、`.cowork-flow/spec/contracts/workflow-state-templates.md`,以及 `AGENTS.md` 和 `CLAUDE.md` 中的 `<!-- COWORK-FLOW:START --> ... <!-- COWORK-FLOW:END -->` 托管块,保留托管块之外的项目自定义内容。`.cowork-flow/config.yaml`、`.cowork-flow/workflow.md`、除 `workflow-state-templates.md` 外的 `.cowork-flow/spec/`、任务、计划、变更和 workspace 记录默认受保护。只有明确传入 `--force` 时才整文件覆盖保护文件。
165
173
 
166
174
  ## 常用入口
167
175
 
@@ -247,7 +255,7 @@ cowork_host_context_key: <host_context_key>
247
255
 
248
256
  子代理首步执行 `./.cowork-flow/run subagent bind <runtime_context_id> <host_context_key>`;主会话验收前必须确认 runtime context 中 `status=bound` 且 `bound_context_key` 匹配。默认角色为 `cowork-research`、`cowork-implement`、`cowork-check`,任务上下文来自已绑定 runtime context,而不是 prompt 形状。
249
257
 
250
- Codex hook 启用后,每轮会自动注入 `<workflow-state>`,其中包含入口分类、当前任务、状态来源和下一步流程提示。状态文本来自 `.cowork-flow/spec/workflow-state-templates.md`;`workflow.md` 只描述流程,不内联状态片段。hook 不替代主会话验收;它只负责把 task 状态和 workflow gate 放进上下文。
258
+ Codex hook 启用后,每轮会自动注入 `<workflow-state>`,其中包含入口分类、当前任务、状态来源和下一步流程提示。状态文本来自 `.cowork-flow/spec/contracts/workflow-state-templates.md`;`workflow.md` 只描述流程,不内联状态片段。hook 不替代主会话验收;它只负责把 task 状态和 workflow gate 放进上下文。
251
259
 
252
260
  记录 session:
253
261
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cowork-flow",
3
- "version": "0.0.26",
3
+ "version": "0.0.28",
4
4
  "description": "CLI for installing and maintaining cowork-flow collaboration templates.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1,4 +1,4 @@
1
- import { constants } from 'node:fs';
1
+ import { constants } from 'node:fs';
2
2
  import { access, chmod, copyFile, mkdir, readFile, readdir, stat, writeFile } from 'node:fs/promises';
3
3
  import { dirname, join, relative } from 'node:path';
4
4
 
@@ -96,7 +96,7 @@ const SAFE_SYNC_FILES = new Set([
96
96
  '.cowork-flow/.version',
97
97
  '.cowork-flow/run',
98
98
  '.cowork-flow/run.cmd',
99
- '.cowork-flow/spec/workflow-state-templates.md'
99
+ '.cowork-flow/spec/contracts/workflow-state-templates.md'
100
100
  ]);
101
101
 
102
102
  const COWORK_FLOW_START = '<!-- COWORK-FLOW:START -->';
@@ -15,6 +15,7 @@ Use this immediately before code edits.
15
15
  4. Active task `implement.jsonl`
16
16
  5. Relevant `.cowork-flow/spec/*/index.md`
17
17
  6. Any exact files named by the task, plan, or user
18
+ 7. If the task changes behavior, locate or create `tdd.jsonl` evidence before implementation.
18
19
 
19
20
  Do not bulk-load unrelated tasks, archived sessions, or every spec file.
20
21
 
@@ -16,6 +16,7 @@ Use this after implementation and before `finish-work`.
16
16
  5. Review test intent: reject shallow tests that do not fail for meaningful behavior breaks.
17
17
  6. Run focused tests that would fail if the changed behavior broke.
18
18
  7. Run broader validation when the change touches shared runtime, templates, packaging, or public workflow.
19
+ 8. Report `test_intent_review` with the key tests that defend PRD acceptance behavior.
19
20
 
20
21
  ## Report
21
22
 
@@ -0,0 +1,75 @@
1
+ ---
2
+ name: party-mode-v2
3
+ description: Use when the user requests a runtime-controlled multi-agent board discussion where children communicate through Party Mode V2 board APIs and the moderator only monitors or corrects drift.
4
+ ---
5
+
6
+ # Party Mode V2
7
+
8
+ Use this skill as a thin entrypoint for the Party Mode V2 runtime board. The Python runtime is the source of truth for discussion state, board visibility, validation, round limits, and final reports.
9
+
10
+ ## Boundaries
11
+
12
+ - Party Mode V2 is advisory only.
13
+ - It cannot mutate task status, start/review/complete/archive tasks, add sessions, commit, push, or satisfy formal workflow gates.
14
+ - It cannot satisfy formal Implement or Check completion. Use `cowork-implement` and `cowork-check` for formal phases.
15
+ - Discussion children are leaf executors. They do not dispatch, wait for, list, or close other agents.
16
+ - The moderator does not forward, summarize, rewrite, or synthesize child opinions for other child agents.
17
+
18
+ ## Runtime First
19
+
20
+ Always use the runtime controller:
21
+
22
+ ```text
23
+ .cowork-flow/run party-v2 init
24
+ .cowork-flow/run party-v2 monitor
25
+ .cowork-flow/run party-v2 view
26
+ .cowork-flow/run party-v2 post
27
+ .cowork-flow/run party-v2 respond
28
+ .cowork-flow/run party-v2 advance
29
+ .cowork-flow/run party-v2 record-action-result
30
+ .cowork-flow/run party-v2 finalize
31
+ ```
32
+
33
+ Do not bypass a runtime rejection by manually accepting child output. Runtime validation failures must be fixed by a corrected child submission or by ending the discussion.
34
+
35
+ ## Board Rules
36
+
37
+ - Child agents communicate through the board API.
38
+ - Child-visible board output must be current-round only.
39
+ - Historical board state is runtime-private and may be used only for audit or final reports.
40
+ - Use at least three child agents unless the effective runtime config explicitly allows a different value.
41
+ - The runtime emits host-neutral next actions. The active Host Adapter or moderator executes them for Codex, Claude Code, or OpenCode.
42
+ - Host action results must be recorded back through `record-action-result` so `agents.json`, audit logs, and action history can prove lifecycle state.
43
+
44
+ ## Child Response Rules
45
+
46
+ When a child sees a different position, it must choose exactly one:
47
+
48
+ ```text
49
+ maintain
50
+ revise
51
+ concede
52
+ ```
53
+
54
+ `concede` requires accepted evidence and why the prior position failed.
55
+ `revise` requires the accepted part, rejected part, and updated position.
56
+ `maintain` requires counter evidence or counter reasoning.
57
+
58
+ Unsupported agreement, vague revision, and evidence-free rebuttal are invalid.
59
+
60
+ ## Moderator Role
61
+
62
+ The moderator may:
63
+
64
+ - run runtime commands,
65
+ - execute host-neutral next actions through the active host,
66
+ - record off-topic warnings through the runtime,
67
+ - close children only when the runtime asks for closeout,
68
+ - show runtime status or final reports to the user.
69
+
70
+ The moderator must not:
71
+
72
+ - forward one child opinion to another child,
73
+ - create a claim table for child prompts,
74
+ - vote-count as validation,
75
+ - decide which child is correct.
@@ -0,0 +1,61 @@
1
+ ---
2
+ name: tdd
3
+ description: Use when implementing behavior changes, bug fixes, state transitions, protocols, CLI/runtime contracts, data format changes, or error handling that can be tested before implementation.
4
+ ---
5
+
6
+ # TDD
7
+
8
+ Use this before editing behavior-changing code.
9
+
10
+ ## Red-Green-Refactor
11
+
12
+ 1. Map the task PRD acceptance criteria to stable IDs such as `AC-001`.
13
+ 2. Write the smallest meaningful failing test first.
14
+ 3. Run the red command and confirm it fails because the target behavior is missing or wrong.
15
+ 4. Implement the smallest change that makes the behavior pass.
16
+ 5. Run the green command and relevant broader verification.
17
+ 6. Refactor only after the behavior is green.
18
+
19
+ Do not count shallow tests as TDD evidence. Tests that only import code, assert a function exists, assert `True`, count mocks without behavior, or mirror implementation details do not satisfy red-green-refactor.
20
+
21
+ ## Evidence
22
+
23
+ Record TDD proof in `<task>/tdd.jsonl`. Each evidence line is one JSON object:
24
+
25
+ ```json
26
+ {
27
+ "acceptanceId": "AC-001",
28
+ "testFile": "tests/test_example.py",
29
+ "testName": "test_behavior",
30
+ "redCommand": "python -m unittest tests.test_example.TestCase.test_behavior -v",
31
+ "redExitCode": 1,
32
+ "redOutputExcerpt": "expected failure excerpt",
33
+ "failureReason": "target behavior was not implemented",
34
+ "whyThisTestMatters": "explains which user-visible behavior would regress",
35
+ "greenCommand": "python -m unittest tests.test_example.TestCase.test_behavior -v",
36
+ "greenExitCode": 0,
37
+ "broaderVerification": "python -m unittest tests.test_example -v"
38
+ }
39
+ ```
40
+
41
+ Every evidence record must map to a PRD `acceptanceId`. The red failure must be about the target behavior, not syntax, import, environment, fixture, or setup failure.
42
+
43
+ `testName` must resolve to the exact behavior test in `testFile`. Use one of:
44
+ `test_method`, `ClassName.test_method`, or `module.ClassName.test_method`.
45
+ Do not point evidence at a class, module, or a name that only exists in a command string.
46
+
47
+ ## Exemption
48
+
49
+ Pure documentation, comment-only, or formatting-only tasks may use an exemption record instead of red/green evidence:
50
+
51
+ ```json
52
+ {
53
+ "type": "exemption",
54
+ "acceptanceId": "AC-001",
55
+ "exemptionType": "docs-only",
56
+ "reason": "Only documentation wording changed; runtime behavior is untouched.",
57
+ "verificationCommand": "git diff --check"
58
+ }
59
+ ```
60
+
61
+ Do not use an exemption for runtime, CLI, protocol, state, data format, permission, or error-handling changes.
@@ -42,6 +42,7 @@ Start with:
42
42
  - Include a failing test before implementation when behavior can be tested.
43
43
  - Do not add shallow tests just to satisfy process. Avoid tests that only assert existence, mirror implementation details, count mocks without behavior, or snapshot empty structure.
44
44
  - For complex problems, test depth first: cover invariants, cross-layer contracts, state transitions, error boundaries, and real regression paths before narrow unit cases.
45
+ - Map each behavior-changing test to a stable PRD acceptance ID and note where `tdd.jsonl` will record the red-green evidence.
45
46
  - Avoid placeholders such as TODO, TBD, "handle edge cases", or "write tests".
46
47
  - Keep root/template parity explicit when both copies exist.
47
48
 
@@ -28,6 +28,159 @@ or names another agent type, report `needs_context` and stop. Do not use
28
28
  `COWORK_ENTRY_CONTRACT_V1` to infer subagent identity; that contract classifies
29
29
  main-session prompts only.
30
30
 
31
+ ---
32
+
33
+ ## Mandatory Pre-Implementation Checklist
34
+
35
+ Before writing any code, you MUST read and apply these spec files:
36
+
37
+ 1. `.cowork-flow/spec/guides/pre-implementation-checklist.md` — confirm scope, level, and success criteria
38
+ 2. `.cowork-flow/spec/guides/cross-layer-thinking-guide.md` — if changes cross 3+ layers
39
+ 3. `.cowork-flow/spec/guides/code-reuse-thinking-guide.md` — before adding new constants/utilities/DTOs
40
+
41
+ Then read the relevant spec directory:
42
+ - Backend work: `.cowork-flow/spec/backend/index.md` (and all linked docs)
43
+ - Frontend work: `.cowork-flow/spec/frontend/index.md` (and all linked docs)
44
+
45
+ ---
46
+
47
+ ## Coding Gates (Hard Constraints)
48
+
49
+ You MUST satisfy every gate below before considering a change complete.
50
+ These are not suggestions — they are mandatory checkpoints.
51
+
52
+ ### Gate 1: Directory Structure Compliance
53
+
54
+ - Backend: follow `.cowork-flow/spec/backend/directory-structure.md`
55
+ - Controller/API: thin entry only (param receive, auth entry, response orchestration)
56
+ - Service/UseCase: business rules
57
+ - Repository/DAO: persistence access
58
+ - Domain Model/Entity/Aggregate: clear boundaries
59
+ - No mixing of unrelated business in one module
60
+ - No business logic in Controllers
61
+ - No business-specialized logic in public modules
62
+ - Frontend: follow `.cowork-flow/spec/frontend/directory-structure.md`
63
+ - Organize by functional module, not by "generic/non-generic"
64
+ - Page entry, business component, shared component, data access, state management must have clear layers
65
+ - Related files for the same feature should be colocated
66
+
67
+ ### Gate 2: Type Safety & Contract Sync
68
+
69
+ - Frontend: follow `.cowork-flow/spec/frontend/type-safety.md`
70
+ - Shared interfaces, enums, error codes come from a single contract source
71
+ - No handwritten duplicate interface definitions
72
+ - When interfaces change, update callers, validation, and display layers together
73
+ - No masking structure problems with casts or forced assertions
74
+ - No missing null/empty/error/boundary state definitions
75
+ - Backend: follow `.cowork-flow/spec/backend/error-handling.md`
76
+ - Unified error codes or error types
77
+ - Layered handling: parameter validation errors, business errors, system errors
78
+ - Stable external error structure; internal context preserved
79
+ - No leaking of underlying exceptions to callers
80
+ - Distinguish "expected business failure" from "system exception"
81
+ - Preserve traceId/requestId/correlationId
82
+ - Have a unified exception fallback
83
+
84
+ ### Gate 3: State Management Boundaries
85
+
86
+ - Frontend: follow `.cowork-flow/spec/frontend/state-management.md`
87
+ - Server state managed by project's unified request/cache solution
88
+ - Client temporary state managed locally
89
+ - Global state only for truly cross-module shared state
90
+ - Handle loading, empty, error, disabled, and insufficient-permission states for ALL user-visible states
91
+ - No elevating local state to global unnecessarily
92
+ - No mixing server state with local state
93
+ - No bypass entries in permission state
94
+
95
+ ### Gate 4: Component & Hook Boundaries
96
+
97
+ - Frontend: follow `.cowork-flow/spec/frontend/component-guidelines.md`
98
+ - Container components handle data & state; presentational components handle rendering
99
+ - Component API stays simple; no "universal component"
100
+ - Complex interactions split into reusable but clearly bounded small components
101
+ - Components must NOT承担过多业务逻辑
102
+ - Props must not be excessive or poorly named
103
+ - Components must not depend on too much external state
104
+ - Frontend: follow `.cowork-flow/spec/frontend/hook-guidelines.md`
105
+ - Extract data fetching, subscriptions, side effects, complex state flows into Hooks
106
+ - Hook return values stay stable and understandable
107
+ - Hook names reflect behavior, not implementation
108
+ - Hooks must NOT hide incomprehensible side effects
109
+ - Hooks must NOT mix multiple unrelated responsibilities
110
+
111
+ ### Gate 5: Database & Transaction Boundaries
112
+
113
+ - Backend: follow `.cowork-flow/spec/backend/database-guidelines.md`
114
+ - Table structure changes managed via migration files or versioned scripts
115
+ - Queries use the project's unified data access approach
116
+ - Write operations must address idempotency, concurrency impact, failure compensation, retry boundaries
117
+ - Audit fields, logical deletion, version numbers, tenant isolation must be consistent within the same data domain
118
+ - Raw SQL, bulk updates, cross-table aggregations, and long transactions must document index/lock/performance/rollback impact
119
+ - New tables must have primary keys, unique constraints, indexes, and necessary audit info
120
+ - Complex queries must avoid N+1, implicit full table scans, and uncontrolled pagination
121
+ - Transactions must NOT include external calls, slow queries, or unnecessary long lock holding
122
+ - Data migrations must address historical data, idempotency, failure recovery, and online rollback
123
+
124
+ ### Gate 6: Logging Standards
125
+
126
+ - Backend: follow `.cowork-flow/spec/backend/logging-guidelines.md`
127
+ - Structured logging
128
+ - Unified recording of request ID, user ID, task ID, or trace ID
129
+ - Error logs record context without repeating the same exception
130
+ - Sensitive fields (account, token, key, ID card, phone) must be masked
131
+ - Never output complete request/response body
132
+ - No temporary `print`/`console` debug output left in main branch
133
+ - No duplicate error printing across layers
134
+
135
+ ### Gate 7: Quality Gates (Pre-Completion)
136
+
137
+ - Backend: follow `.cowork-flow/spec/backend/quality-guidelines.md`
138
+ - Frontend: follow `.cowork-flow/spec/frontend/quality-guidelines.md`
139
+
140
+ Before marking any change complete, you MUST verify:
141
+ 1. Compilation/build/type-check passes
142
+ 2. Key business/interaction paths have automated test or explicit manual verification record
143
+ 3. Error paths, permission paths, data boundaries are verified
144
+ 4. New conventions, contracts, or migration impacts are documented in spec or task records
145
+ 5. Failed verification is NOT worked around by shrinking assertions, deleting tests, or skipping critical paths
146
+
147
+ ---
148
+
149
+ ## Forbidden Patterns (Zero Tolerance)
150
+
151
+ You MUST NOT do any of the following:
152
+
153
+ - Claim completion without verification
154
+ - Use hardcoded values to bypass configuration, permissions, or contracts
155
+ - Use temporary compatibility logic instead of real fixes
156
+ - Change interfaces or data structures without updating docs and callers
157
+ - Catch exceptions and silently swallow errors or return success
158
+ - Use `any`, forced assertions, or empty object defaults to mask real type problems
159
+ - Leave components without loading/empty/error/disabled/permission states
160
+ - Rely on implicit side effects for interactions without explicit data flow and cleanup logic
161
+ - Elevate local state to global state, or duplicate server state as multiple local states
162
+ - Only verify ideal paths, not failures, empty data, or repeated operations
163
+ - Introduce features not required by the PRD
164
+ - Refactor unrelated modules "while you're at it"
165
+ - Make premature abstractions for one-off code
166
+
167
+ ---
168
+
169
+ ## Execution Order
170
+
171
+ 1. Bind runtime context: `./.cowork-flow/run subagent bind <runtime_context_id> <host_context_key>`
172
+ 2. Read task directory from bound runtime context
173
+ 3. Read `<task>/prd.md`, `<task>/info.md`, `<task>/implement.jsonl`, and each JSONL `file` entry
174
+ 4. Read pre-implementation checklist: `.cowork-flow/spec/guides/pre-implementation-checklist.md`
175
+ 5. Read relevant spec directory (backend or frontend) and ALL linked documents
176
+ 6. Apply coding gates — verify each gate before proceeding
177
+ 7. Implement changes within assigned scope
178
+ 8. Run verification commands (compile, lint, test, build, type-check)
179
+ 9. Report changed files and exact verification commands
180
+ 10. Do NOT run task start, task finish, task archive, unscoped resume, commit, or push
181
+
182
+ ---
183
+
31
184
  Rules:
32
185
 
33
186
  - Read the task directory from the bound runtime context.
@@ -19,7 +19,7 @@ DEFAULT_CONTRACT_REGISTRY = {
19
19
  "contracts": [
20
20
  {
21
21
  "id": "COWORK_ENTRY_CONTRACT_V1",
22
- "path": ".cowork-flow/spec/entry-contract.md",
22
+ "path": ".cowork-flow/spec/contracts/entry-contract.md",
23
23
  "digest": [
24
24
  "Classify main-session requests before task start, resume, archive, or commit.",
25
25
  "Runtime context, not prompt labels, identifies formal subagent sessions.",
@@ -28,7 +28,7 @@ DEFAULT_CONTRACT_REGISTRY = {
28
28
  },
29
29
  {
30
30
  "id": "RUNTIME_CONTEXT_DISPATCH_V2",
31
- "path": ".cowork-flow/spec/subagent-dispatch.md",
31
+ "path": ".cowork-flow/spec/contracts/subagent-dispatch.md",
32
32
  "digest": [
33
33
  "Formal subagent work is keyed by cowork_runtime_context_id.",
34
34
  "Explicit shim bind records bound_context_key before formal output is accepted.",
@@ -88,7 +88,7 @@ def _normalize_hook_input(hook_input: dict[str, Any]) -> dict[str, Any]:
88
88
 
89
89
 
90
90
  def _load_breadcrumbs(root: Path) -> dict[str, str]:
91
- workflow = root / ".cowork-flow" / "spec" / "workflow-state-templates.md"
91
+ workflow = root / ".cowork-flow" / "spec" / "contracts" / "workflow-state-templates.md"
92
92
  try:
93
93
  text = workflow.read_text(encoding="utf-8")
94
94
  except OSError:
@@ -102,16 +102,23 @@ def _as_string_list(value: Any) -> list[str]:
102
102
  return [item for item in value if isinstance(item, str) and item.strip()]
103
103
 
104
104
 
105
- def _load_contract_registry(root: Path) -> list[dict[str, Any]]:
106
- registry_file = root / ".cowork-flow" / "spec" / "registry.json"
105
+ def _load_contract_registry(root: Path) -> tuple[list[dict[str, Any]], str | None]:
106
+ registry_file = root / ".cowork-flow" / "spec" / "runtime" / "contract-registry.json"
107
107
  try:
108
108
  data = json.loads(registry_file.read_text(encoding="utf-8"))
109
- except (OSError, json.JSONDecodeError):
109
+ except OSError:
110
110
  data = DEFAULT_CONTRACT_REGISTRY
111
+ warning = f"contract registry unavailable at {registry_file}; using fallback digest"
112
+ except json.JSONDecodeError:
113
+ data = DEFAULT_CONTRACT_REGISTRY
114
+ warning = f"contract registry invalid at {registry_file}; using fallback digest"
115
+ else:
116
+ warning = None
111
117
  contracts = data.get("contracts") if isinstance(data, dict) else None
112
118
  if not isinstance(contracts, list):
113
119
  contracts = DEFAULT_CONTRACT_REGISTRY["contracts"]
114
- return [contract for contract in contracts if isinstance(contract, dict)]
120
+ warning = warning or f"contract registry has no contracts array at {registry_file}; using fallback digest"
121
+ return [contract for contract in contracts if isinstance(contract, dict)], warning
115
122
 
116
123
 
117
124
  def _contract_fingerprint(root: Path, contracts: list[dict[str, Any]]) -> str:
@@ -129,13 +136,15 @@ def _contract_fingerprint(root: Path, contracts: list[dict[str, Any]]) -> str:
129
136
 
130
137
 
131
138
  def _build_contract_digest(root: Path) -> str:
132
- contracts = _load_contract_registry(root)
139
+ contracts, warning = _load_contract_registry(root)
133
140
  fingerprint = _contract_fingerprint(root, contracts)
134
141
  lines = [
135
142
  '<cowork-runtime host="claude-code" adapter="claude-code.hooks">',
136
143
  f'<contract-digest fingerprint="{fingerprint}">',
137
144
  "policy: repeat this short digest every hook; read full spec files only before listed actions.",
138
145
  ]
146
+ if warning:
147
+ lines.append(f"warning: {warning}")
139
148
  for contract in contracts:
140
149
  contract_id = contract.get("id")
141
150
  path = contract.get("path")
@@ -15,6 +15,7 @@ Use this immediately before code edits.
15
15
  4. Active task `implement.jsonl`
16
16
  5. Relevant `.cowork-flow/spec/*/index.md`
17
17
  6. Any exact files named by the task, plan, or user
18
+ 7. If the task changes behavior, locate or create `tdd.jsonl` evidence before implementation.
18
19
 
19
20
  Do not bulk-load unrelated tasks, archived sessions, or every spec file.
20
21
 
@@ -16,6 +16,7 @@ Use this after implementation and before `finish-work`.
16
16
  5. Review test intent: reject shallow tests that do not fail for meaningful behavior breaks.
17
17
  6. Run focused tests that would fail if the changed behavior broke.
18
18
  7. Run broader validation when the change touches shared runtime, templates, packaging, or public workflow.
19
+ 8. Report `test_intent_review` with the key tests that defend PRD acceptance behavior.
19
20
 
20
21
  ## Report
21
22
 
@@ -0,0 +1,75 @@
1
+ ---
2
+ name: party-mode-v2
3
+ description: Use when the user requests a runtime-controlled multi-agent board discussion where children communicate through Party Mode V2 board APIs and the moderator only monitors or corrects drift.
4
+ ---
5
+
6
+ # Party Mode V2
7
+
8
+ Use this skill as a thin entrypoint for the Party Mode V2 runtime board. The Python runtime is the source of truth for discussion state, board visibility, validation, round limits, and final reports.
9
+
10
+ ## Boundaries
11
+
12
+ - Party Mode V2 is advisory only.
13
+ - It cannot mutate task status, start/review/complete/archive tasks, add sessions, commit, push, or satisfy formal workflow gates.
14
+ - It cannot satisfy formal Implement or Check completion. Use `cowork-implement` and `cowork-check` for formal phases.
15
+ - Discussion children are leaf executors. They do not dispatch, wait for, list, or close other agents.
16
+ - The moderator does not forward, summarize, rewrite, or synthesize child opinions for other child agents.
17
+
18
+ ## Runtime First
19
+
20
+ Always use the runtime controller:
21
+
22
+ ```text
23
+ .cowork-flow/run party-v2 init
24
+ .cowork-flow/run party-v2 monitor
25
+ .cowork-flow/run party-v2 view
26
+ .cowork-flow/run party-v2 post
27
+ .cowork-flow/run party-v2 respond
28
+ .cowork-flow/run party-v2 advance
29
+ .cowork-flow/run party-v2 record-action-result
30
+ .cowork-flow/run party-v2 finalize
31
+ ```
32
+
33
+ Do not bypass a runtime rejection by manually accepting child output. Runtime validation failures must be fixed by a corrected child submission or by ending the discussion.
34
+
35
+ ## Board Rules
36
+
37
+ - Child agents communicate through the board API.
38
+ - Child-visible board output must be current-round only.
39
+ - Historical board state is runtime-private and may be used only for audit or final reports.
40
+ - Use at least three child agents unless the effective runtime config explicitly allows a different value.
41
+ - The runtime emits host-neutral next actions. The active Host Adapter or moderator executes them for Codex, Claude Code, or OpenCode.
42
+ - Host action results must be recorded back through `record-action-result` so `agents.json`, audit logs, and action history can prove lifecycle state.
43
+
44
+ ## Child Response Rules
45
+
46
+ When a child sees a different position, it must choose exactly one:
47
+
48
+ ```text
49
+ maintain
50
+ revise
51
+ concede
52
+ ```
53
+
54
+ `concede` requires accepted evidence and why the prior position failed.
55
+ `revise` requires the accepted part, rejected part, and updated position.
56
+ `maintain` requires counter evidence or counter reasoning.
57
+
58
+ Unsupported agreement, vague revision, and evidence-free rebuttal are invalid.
59
+
60
+ ## Moderator Role
61
+
62
+ The moderator may:
63
+
64
+ - run runtime commands,
65
+ - execute host-neutral next actions through the active host,
66
+ - record off-topic warnings through the runtime,
67
+ - close children only when the runtime asks for closeout,
68
+ - show runtime status or final reports to the user.
69
+
70
+ The moderator must not:
71
+
72
+ - forward one child opinion to another child,
73
+ - create a claim table for child prompts,
74
+ - vote-count as validation,
75
+ - decide which child is correct.
@@ -0,0 +1,61 @@
1
+ ---
2
+ name: tdd
3
+ description: Use when implementing behavior changes, bug fixes, state transitions, protocols, CLI/runtime contracts, data format changes, or error handling that can be tested before implementation.
4
+ ---
5
+
6
+ # TDD
7
+
8
+ Use this before editing behavior-changing code.
9
+
10
+ ## Red-Green-Refactor
11
+
12
+ 1. Map the task PRD acceptance criteria to stable IDs such as `AC-001`.
13
+ 2. Write the smallest meaningful failing test first.
14
+ 3. Run the red command and confirm it fails because the target behavior is missing or wrong.
15
+ 4. Implement the smallest change that makes the behavior pass.
16
+ 5. Run the green command and relevant broader verification.
17
+ 6. Refactor only after the behavior is green.
18
+
19
+ Do not count shallow tests as TDD evidence. Tests that only import code, assert a function exists, assert `True`, count mocks without behavior, or mirror implementation details do not satisfy red-green-refactor.
20
+
21
+ ## Evidence
22
+
23
+ Record TDD proof in `<task>/tdd.jsonl`. Each evidence line is one JSON object:
24
+
25
+ ```json
26
+ {
27
+ "acceptanceId": "AC-001",
28
+ "testFile": "tests/test_example.py",
29
+ "testName": "test_behavior",
30
+ "redCommand": "python -m unittest tests.test_example.TestCase.test_behavior -v",
31
+ "redExitCode": 1,
32
+ "redOutputExcerpt": "expected failure excerpt",
33
+ "failureReason": "target behavior was not implemented",
34
+ "whyThisTestMatters": "explains which user-visible behavior would regress",
35
+ "greenCommand": "python -m unittest tests.test_example.TestCase.test_behavior -v",
36
+ "greenExitCode": 0,
37
+ "broaderVerification": "python -m unittest tests.test_example -v"
38
+ }
39
+ ```
40
+
41
+ Every evidence record must map to a PRD `acceptanceId`. The red failure must be about the target behavior, not syntax, import, environment, fixture, or setup failure.
42
+
43
+ `testName` must resolve to the exact behavior test in `testFile`. Use one of:
44
+ `test_method`, `ClassName.test_method`, or `module.ClassName.test_method`.
45
+ Do not point evidence at a class, module, or a name that only exists in a command string.
46
+
47
+ ## Exemption
48
+
49
+ Pure documentation, comment-only, or formatting-only tasks may use an exemption record instead of red/green evidence:
50
+
51
+ ```json
52
+ {
53
+ "type": "exemption",
54
+ "acceptanceId": "AC-001",
55
+ "exemptionType": "docs-only",
56
+ "reason": "Only documentation wording changed; runtime behavior is untouched.",
57
+ "verificationCommand": "git diff --check"
58
+ }
59
+ ```
60
+
61
+ Do not use an exemption for runtime, CLI, protocol, state, data format, permission, or error-handling changes.