repo-harness 0.1.3 → 0.1.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.
Files changed (81) hide show
  1. package/AGENTS.md +1 -1
  2. package/CLAUDE.md +1 -1
  3. package/README.md +11 -10
  4. package/README.zh-CN.md +8 -8
  5. package/SKILL.md +2 -1
  6. package/assets/hooks/codex.hooks.template.json +1 -1
  7. package/assets/hooks/lib/workflow-state.sh +105 -12
  8. package/assets/hooks/run-hook.sh +22 -0
  9. package/assets/hooks/session-start-context.sh +16 -1
  10. package/assets/hooks/settings.template.json +1 -1
  11. package/assets/hooks/stop-orchestrator.sh +140 -0
  12. package/assets/initializer-question-pack.v4.json +26 -8
  13. package/assets/partials/07-footer.partial.md +3 -3
  14. package/assets/partials/08-orchestration.partial.md +1 -1
  15. package/assets/partials-agents/04-task-protocol.partial.md +4 -4
  16. package/assets/partials-agents/06-quality-safety.partial.md +2 -2
  17. package/assets/plan-map.json +1 -1
  18. package/assets/project-structures/ai-native-collaborative-editor.txt +25 -0
  19. package/assets/reference-configs/agentic-development-flow.md +3 -2
  20. package/assets/reference-configs/evaluator-rubric.md +1 -1
  21. package/assets/reference-configs/external-tooling.md +1 -1
  22. package/assets/reference-configs/harness-overview.md +9 -9
  23. package/assets/reference-configs/hook-operations.md +14 -0
  24. package/assets/reference-configs/sprint-contracts.md +2 -2
  25. package/assets/skill-commands/manifest.json +11 -4
  26. package/assets/skill-commands/repo-harness-autoplan/SKILL.md +14 -7
  27. package/assets/skill-commands/repo-harness-ship/SKILL.md +26 -0
  28. package/assets/templates/contract.template.md +8 -8
  29. package/assets/templates/helpers/architecture-event.ts +2 -1
  30. package/assets/templates/helpers/archive-workflow.sh +57 -1
  31. package/assets/templates/helpers/capability-resolver.ts +2 -1
  32. package/assets/templates/helpers/capture-plan.sh +42 -13
  33. package/assets/templates/helpers/check-task-workflow.sh +32 -2
  34. package/assets/templates/helpers/codex-handoff-resume.sh +91 -9
  35. package/assets/templates/helpers/context-contract-sync.sh +2 -1
  36. package/assets/templates/helpers/contract-worktree.sh +73 -2
  37. package/assets/templates/helpers/ensure-task-workflow.sh +23 -21
  38. package/assets/templates/helpers/migrate-project-template.sh +1 -1
  39. package/assets/templates/helpers/new-plan.sh +20 -12
  40. package/assets/templates/helpers/plan-to-todo.sh +116 -19
  41. package/assets/templates/helpers/prepare-codex-handoff.sh +84 -1
  42. package/assets/templates/helpers/select-agent-context-blocks.sh +4 -3
  43. package/assets/templates/helpers/ship-worktrees.sh +559 -0
  44. package/assets/templates/plan.template.md +11 -11
  45. package/assets/workflow-contract.v1.json +2 -0
  46. package/docs/reference-configs/agentic-development-flow.md +3 -3
  47. package/docs/reference-configs/evaluator-rubric.md +1 -1
  48. package/docs/reference-configs/external-tooling.md +1 -1
  49. package/docs/reference-configs/handoff-protocol.md +8 -7
  50. package/docs/reference-configs/harness-overview.md +9 -9
  51. package/docs/reference-configs/hook-operations.md +5 -0
  52. package/docs/reference-configs/sprint-contracts.md +2 -2
  53. package/package.json +1 -1
  54. package/scripts/architecture-event.ts +2 -1
  55. package/scripts/archive-workflow.sh +57 -1
  56. package/scripts/capability-resolver.ts +2 -1
  57. package/scripts/capture-plan.sh +42 -13
  58. package/scripts/check-brain-manifest.sh +127 -70
  59. package/scripts/check-skill-version.ts +2 -3
  60. package/scripts/check-task-workflow.sh +32 -2
  61. package/scripts/codex-handoff-resume.sh +91 -9
  62. package/scripts/context-contract-sync.sh +2 -1
  63. package/scripts/contract-worktree.sh +73 -2
  64. package/scripts/create-project-dirs.sh +2 -2
  65. package/scripts/ensure-task-workflow.sh +23 -21
  66. package/scripts/init-project.sh +6 -6
  67. package/scripts/lib/project-init-lib.sh +91 -46
  68. package/scripts/migrate-project-template.sh +3 -3
  69. package/scripts/new-plan.sh +20 -12
  70. package/scripts/plan-to-todo.sh +116 -19
  71. package/scripts/prepare-codex-handoff.sh +84 -1
  72. package/scripts/repo-harness.sh +2 -2
  73. package/scripts/select-agent-context-blocks.sh +4 -3
  74. package/scripts/setup-plugins.sh +1 -1
  75. package/scripts/ship-worktrees.sh +559 -0
  76. package/scripts/sync-brain-docs.sh +83 -165
  77. package/src/cli/commands/status.ts +1 -1
  78. package/src/cli/hook/route-registry.ts +1 -1
  79. package/src/cli/hook/runtime.ts +37 -2
  80. package/src/cli/index.ts +1 -1
  81. package/src/cli/installer/targets/codex.ts +39 -3
package/AGENTS.md CHANGED
@@ -21,7 +21,7 @@ This repository self-hosts the `repo-harness` contract, formerly `repo-harness-s
21
21
  ## Operating Rules
22
22
 
23
23
  - Sync `tasks/` whenever substantive repo changes are made.
24
- - Use `tasks/notes/<slug>.notes.md` only for non-obvious slice decisions, deviations, tradeoffs, and open questions; do not use notes as durable memory or a task log, and archive/promote them deliberately when the slice closes.
24
+ - Use `tasks/notes/<plan-stem>.notes.md` only for non-obvious slice decisions, deviations, tradeoffs, and open questions; `<plan-stem>` is the active plan filename without `plan-` and `.md` (for example `20260531-0045-governance-workflow`). Do not use notes as durable memory or a task log, and archive/promote them deliberately when the slice closes.
25
25
  - Treat `.ai/hooks/` as the shared repo-local hook implementation; user-level `~/.claude/settings.json` and `~/.codex/hooks.json` are the host adapters.
26
26
  - Keep the umbrella hierarchy explicit: architecture owns stable truth, capability contracts own local agent context, `tasks/workstreams/<domain>/<capability>/` owns durable progress, and `tasks/todo.md` owns only deferred medium/long-term goals with tradeoff and revisit trigger.
27
27
  - Treat `.ai/context/capabilities.json` as the source of truth for capability prefixes; `agent-context-blocks.txt` and nested agent files are compatibility inputs only.
package/CLAUDE.md CHANGED
@@ -21,7 +21,7 @@ This repository self-hosts the `repo-harness` contract, formerly `repo-harness-s
21
21
  ## Operating Rules
22
22
 
23
23
  - Sync `tasks/` whenever substantive repo changes are made.
24
- - Use `tasks/notes/<slug>.notes.md` only for non-obvious slice decisions, deviations, tradeoffs, and open questions; do not use notes as durable memory or a task log, and archive/promote them deliberately when the slice closes.
24
+ - Use `tasks/notes/<plan-stem>.notes.md` only for non-obvious slice decisions, deviations, tradeoffs, and open questions; `<plan-stem>` is the active plan filename without `plan-` and `.md` (for example `20260531-0045-governance-workflow`). Do not use notes as durable memory or a task log, and archive/promote them deliberately when the slice closes.
25
25
  - Treat `.ai/hooks/` as the shared repo-local hook implementation; user-level `~/.claude/settings.json` and `~/.codex/hooks.json` are the host adapters.
26
26
  - Keep the umbrella hierarchy explicit: architecture owns stable truth, capability contracts own local agent context, `tasks/workstreams/<domain>/<capability>/` owns durable progress, and `tasks/todo.md` owns only deferred medium/long-term goals with tradeoff and revisit trigger.
27
27
  - Treat `.ai/context/capabilities.json` as the source of truth for capability prefixes; `agent-context-blocks.txt` and nested agent files are compatibility inputs only.
package/README.md CHANGED
@@ -77,9 +77,9 @@ flowchart TD
77
77
 
78
78
  Approve --> Project["Project plan into execution<br/>capture-plan.sh --execute<br/>or plan-to-todo.sh --plan"]
79
79
  Project --> Active["Active markers<br/>.ai/harness/active-plan<br/>.ai/harness/active-worktree"]
80
- Project --> Contract["Sprint contract<br/>tasks/contracts/task-slug.contract.md"]
81
- Project --> ReviewFile["Review file<br/>tasks/reviews/task-slug.review.md"]
82
- Project --> Notes["Task notes<br/>tasks/notes/task-slug.notes.md"]
80
+ Project --> Contract["Sprint contract<br/>tasks/contracts/YYYYMMDD-HHMM-task-slug.contract.md"]
81
+ Project --> ReviewFile["Review file<br/>tasks/reviews/YYYYMMDD-HHMM-task-slug.review.md"]
82
+ Project --> Notes["Task notes<br/>tasks/notes/YYYYMMDD-HHMM-task-slug.notes.md"]
83
83
 
84
84
  Contract --> WorktreePolicy{"Contract worktree required?"}
85
85
  WorktreePolicy -->|yes| Checkout["Checkout isolated worktree<br/>contract-worktree.sh start --plan<br/>branch codex/task-slug"]
@@ -121,12 +121,13 @@ npx -y repo-harness init
121
121
  ```
122
122
 
123
123
  The npm package release line is `0.1.x`; generated workflow compatibility is
124
- tracked separately as the `5.x` model line. The `0.1.3` package publishes the
124
+ tracked separately as the `5.x` model line. The `0.1.5` package publishes the
125
125
  renamed `repo-harness` CLI, user-level Claude/Codex hook adapter bootstrap,
126
- AI-native scaffold overlays, the typed prompt-guard decision engine, Waza
127
- runtime skill sync, `diagram-design` sync, and the release gate used by
128
- maintainers before npm publish. When working from a source checkout instead of
129
- npm, run:
126
+ AI-native scaffold overlays, the typed prompt-guard decision engine, plan-stem
127
+ task artifact naming, `REPO_HARNESS_*` runtime aliases, repo-harness generated
128
+ markers, Waza runtime skill sync, `diagram-design` sync, and the release gate
129
+ used by maintainers before npm publish. When working from a source
130
+ checkout instead of npm, run:
130
131
 
131
132
  ```bash
132
133
  git clone https://github.com/Ancienttwo/repo-harness.git ~/Projects/repo-harness
@@ -250,7 +251,7 @@ Most common guards:
250
251
 
251
252
  ## Current Release
252
253
 
253
- - npm package: `repo-harness@0.1.3`
254
+ - npm package: `repo-harness@0.1.5`
254
255
  - Generated workflow compatibility: `5.2.3`
255
256
  - GitHub repository: `Ancienttwo/repo-harness`
256
257
  - Release history: [`docs/CHANGELOG.md`](docs/CHANGELOG.md)
@@ -322,7 +323,7 @@ the public surface action-style while sharing the same router, contract, scripts
322
323
  and tests:
323
324
 
324
325
  - Planning and review: `repo-harness-plan`, `repo-harness-review`, `repo-harness-autoplan`
325
- - Repo workflow actions: `repo-harness-init`, `repo-harness-migrate`, `repo-harness-upgrade`, `repo-harness-capability`, `repo-harness-architecture`, `repo-harness-handoff`, `repo-harness-deploy`, `repo-harness-repair`, `repo-harness-check`
326
+ - Repo workflow actions: `repo-harness-ship`, `repo-harness-init`, `repo-harness-migrate`, `repo-harness-upgrade`, `repo-harness-capability`, `repo-harness-architecture`, `repo-harness-handoff`, `repo-harness-deploy`, `repo-harness-repair`, `repo-harness-check`
326
327
  - Project creation: `repo-harness-scaffold`
327
328
 
328
329
  `repo-harness-init` is for an existing repo; `repo-harness-scaffold` creates a new
package/README.zh-CN.md CHANGED
@@ -69,9 +69,9 @@ flowchart TD
69
69
 
70
70
  Approve --> Project["投射到执行面<br/>capture-plan.sh --execute<br/>或 plan-to-todo.sh --plan"]
71
71
  Project --> Active["Active markers<br/>.ai/harness/active-plan<br/>.ai/harness/active-worktree"]
72
- Project --> Contract["Sprint contract<br/>tasks/contracts/task-slug.contract.md"]
73
- Project --> ReviewFile["Review file<br/>tasks/reviews/task-slug.review.md"]
74
- Project --> Notes["Task notes<br/>tasks/notes/task-slug.notes.md"]
72
+ Project --> Contract["Sprint contract<br/>tasks/contracts/YYYYMMDD-HHMM-task-slug.contract.md"]
73
+ Project --> ReviewFile["Review file<br/>tasks/reviews/YYYYMMDD-HHMM-task-slug.review.md"]
74
+ Project --> Notes["Task notes<br/>tasks/notes/YYYYMMDD-HHMM-task-slug.notes.md"]
75
75
 
76
76
  Contract --> WorktreePolicy{"是否需要 contract worktree?"}
77
77
  WorktreePolicy -->|是| Checkout["Checkout 隔离 worktree<br/>contract-worktree.sh start --plan<br/>branch codex/task-slug"]
@@ -112,10 +112,10 @@ npx -y repo-harness init
112
112
  ```
113
113
 
114
114
  npm package release line 是 `0.1.x`;生成的 workflow compatibility model line
115
- 单独以 `5.x` 追踪。`repo-harness@0.1.3` 发布的是改名后的 CLI、Claude/Codex
115
+ 单独以 `5.x` 追踪。`repo-harness@0.1.4` 发布的是改名后的 CLI、Claude/Codex
116
116
  user-level hook adapter bootstrap、AI-native scaffold overlays、typed prompt-guard
117
- decision engine、Waza runtime skill sync、`diagram-design` sync,以及 maintainer
118
- 发布 npm 前使用的 release gate。
117
+ decision engine、plan-stem task artifact 命名、Waza runtime skill sync
118
+ `diagram-design` sync,以及 maintainer 发布 npm 前使用的 release gate。
119
119
 
120
120
  如果从源码 checkout 工作:
121
121
 
@@ -235,7 +235,7 @@ hook block 工作时,先看 terminal 里的结构化输出。核心字段是
235
235
 
236
236
  ## 当前 Release
237
237
 
238
- - npm package:`repo-harness@0.1.3`
238
+ - npm package:`repo-harness@0.1.4`
239
239
  - Generated workflow compatibility:`5.2.3`
240
240
  - GitHub repository:`Ancienttwo/repo-harness`
241
241
  - Release history:[`docs/CHANGELOG.md`](docs/CHANGELOG.md)
@@ -264,7 +264,7 @@ hook block 工作时,先看 terminal 里的结构化输出。核心字段是
264
264
  公共 command skill facades 在 `assets/skill-commands/`:
265
265
 
266
266
  - Planning / review:`repo-harness-plan`、`repo-harness-review`、`repo-harness-autoplan`
267
- - Repo workflow actions:`repo-harness-init`、`repo-harness-migrate`、`repo-harness-upgrade`、`repo-harness-capability`、`repo-harness-architecture`、`repo-harness-handoff`、`repo-harness-deploy`、`repo-harness-repair`、`repo-harness-check`
267
+ - Repo workflow actions:`repo-harness-ship`、`repo-harness-init`、`repo-harness-migrate`、`repo-harness-upgrade`、`repo-harness-capability`、`repo-harness-architecture`、`repo-harness-handoff`、`repo-harness-deploy`、`repo-harness-repair`、`repo-harness-check`
268
268
  - Project creation:`repo-harness-scaffold`
269
269
 
270
270
  `repo-harness-init` 用于已有仓库;`repo-harness-scaffold` 用于创建新项目或模块。
package/SKILL.md CHANGED
@@ -103,7 +103,8 @@ the same engine. Use action-style names for discoverability:
103
103
 
104
104
  - `repo-harness-plan`: interactive planning; no repo mutation by default
105
105
  - `repo-harness-review`: plan review across product, engineering, design, and DevEx
106
- - `repo-harness-autoplan`: automatic plan -> review -> decision summary pipeline
106
+ - `repo-harness-autoplan`: automatic plan -> self-review twice -> implementation -> check -> ship pipeline
107
+ - `repo-harness-ship`: validate finished worktrees, push branches, and create PRs by default
107
108
  - `repo-harness-init`: install or refresh the harness in an existing repo
108
109
  - `repo-harness-scaffold`: create a new project or module scaffold, then attach the harness
109
110
  - `repo-harness-migrate`: migrate legacy workflow docs and stale harness artifacts
@@ -50,7 +50,7 @@
50
50
  "Stop": [
51
51
  {
52
52
  "hooks": [
53
- { "type": "command", "command": "repo=$(git rev-parse --show-toplevel 2>/dev/null) || exit 0; HOOK_HOST=codex HOOK_REPO_ROOT=\"$repo\" bash \"$repo/.ai/hooks/run-hook.sh\" finalize-handoff.sh" }
53
+ { "type": "command", "command": "repo=$(git rev-parse --show-toplevel 2>/dev/null) || exit 0; HOOK_HOST=codex HOOK_REPO_ROOT=\"$repo\" bash \"$repo/.ai/hooks/run-hook.sh\" stop-orchestrator.sh" }
54
54
  ]
55
55
  }
56
56
  ]
@@ -275,7 +275,7 @@ get_todo_source_plan() {
275
275
  awk -F': ' '/^\> \*\*Source Plan\*\*:/ {print $2; exit}' tasks/todo.md | xargs
276
276
  }
277
277
 
278
- derive_contract_path() {
278
+ workflow_plan_slug_from_path() {
279
279
  local plan_file="$1"
280
280
  local base slug
281
281
 
@@ -286,7 +286,93 @@ derive_contract_path() {
286
286
  return 1
287
287
  fi
288
288
 
289
- printf 'tasks/contracts/%s.contract.md' "$slug"
289
+ printf '%s' "$slug"
290
+ }
291
+
292
+ workflow_plan_original_artifact_stem_from_path() {
293
+ local plan_file="$1"
294
+ local base stem
295
+
296
+ base="$(basename "$plan_file")"
297
+ stem="$(printf '%s' "$base" | sed -E 's/^plan-//; s/\.md$//')"
298
+ if [[ "$stem" =~ ^[0-9]{8}-[0-9]{4}-.+ ]]; then
299
+ printf '%s' "$stem"
300
+ return 0
301
+ fi
302
+
303
+ workflow_plan_slug_from_path "$plan_file"
304
+ }
305
+
306
+ workflow_is_transient_plan_slug() {
307
+ case "$1" in
308
+ think-plan-[0-9]*|codex-plan-[0-9]*|approved-plan-[0-9]*)
309
+ return 0
310
+ ;;
311
+ esac
312
+ return 1
313
+ }
314
+
315
+ workflow_plan_title_slug_from_file() {
316
+ local plan_file="$1"
317
+ local title slug
318
+
319
+ [[ -f "$plan_file" ]] || return 1
320
+ title="$(awk '
321
+ /^# Plan:[[:space:]]*/ {
322
+ sub(/^# Plan:[[:space:]]*/, "")
323
+ print
324
+ exit
325
+ }
326
+ ' "$plan_file" | xargs)"
327
+ [[ -n "$title" ]] || return 1
328
+
329
+ slug="$(printf '%s' "$title" | tr '[:upper:]' '[:lower:]' | sed -E 's/[^a-z0-9]+/-/g; s/^-+//; s/-+$//; s/-{2,}/-/g')"
330
+ [[ -n "$slug" ]] || return 1
331
+ printf '%s' "$slug"
332
+ }
333
+
334
+ workflow_plan_artifact_stem_from_path() {
335
+ local plan_file="$1"
336
+ local stem stamp slug title_slug
337
+
338
+ stem="$(workflow_plan_original_artifact_stem_from_path "$plan_file" || true)"
339
+ if [[ "$stem" =~ ^[0-9]{8}-[0-9]{4}-.+ ]]; then
340
+ stamp="$(printf '%s' "$stem" | sed -E 's/^([0-9]{8}-[0-9]{4})-.+$/\1/')"
341
+ slug="$(printf '%s' "$stem" | sed -E 's/^[0-9]{8}-[0-9]{4}-//')"
342
+ if workflow_is_transient_plan_slug "$slug"; then
343
+ title_slug="$(workflow_plan_title_slug_from_file "$plan_file" || true)"
344
+ if [[ -n "$title_slug" && "$title_slug" != "$slug" ]]; then
345
+ printf '%s-%s' "$stamp" "$title_slug"
346
+ return 0
347
+ fi
348
+ fi
349
+ printf '%s' "$stem"
350
+ return 0
351
+ fi
352
+
353
+ workflow_plan_slug_from_path "$plan_file"
354
+ }
355
+
356
+ workflow_preferred_or_legacy_path() {
357
+ local preferred="$1"
358
+ local legacy="$2"
359
+
360
+ if [[ -f "$preferred" ]] || [[ ! -f "$legacy" ]]; then
361
+ printf '%s' "$preferred"
362
+ else
363
+ printf '%s' "$legacy"
364
+ fi
365
+ }
366
+
367
+ derive_contract_path() {
368
+ local plan_file="$1"
369
+ local stem slug
370
+
371
+ stem="$(workflow_plan_artifact_stem_from_path "$plan_file" || true)"
372
+ slug="$(workflow_plan_slug_from_path "$plan_file" || true)"
373
+ [[ -n "$stem" && -n "$slug" ]] || return 1
374
+
375
+ workflow_preferred_or_legacy_path "tasks/contracts/${stem}.contract.md" "tasks/contracts/${slug}.contract.md"
290
376
  }
291
377
 
292
378
  workflow_plan_slug() {
@@ -296,7 +382,7 @@ workflow_plan_slug() {
296
382
  return 1
297
383
  fi
298
384
 
299
- slug="$(basename "$active_plan" | sed -E 's/^plan-[0-9]{8}-[0-9]{4}-//; s/\.md$//')"
385
+ slug="$(workflow_plan_slug_from_path "$active_plan" || true)"
300
386
  if [[ -n "$slug" ]]; then
301
387
  printf '%s' "$slug"
302
388
  return 0
@@ -930,7 +1016,7 @@ workflow_contract_slug() {
930
1016
  local active_plan slug
931
1017
  active_plan="$(get_active_plan || true)"
932
1018
  [[ -n "$active_plan" ]] || return 1
933
- slug="$(basename "$active_plan" | sed -E 's/^plan-[0-9]{8}-[0-9]{4}-//; s/\.md$//')"
1019
+ slug="$(workflow_plan_slug_from_path "$active_plan" || true)"
934
1020
  [[ -n "$slug" ]] || return 1
935
1021
  printf '%s' "$slug"
936
1022
  }
@@ -945,18 +1031,25 @@ workflow_active_contract() {
945
1031
  }
946
1032
 
947
1033
  workflow_active_review() {
948
- local slug
949
- slug="$(workflow_contract_slug || true)"
950
- [[ -n "$slug" ]] || return 1
951
- printf 'tasks/reviews/%s.review.md' "$slug"
1034
+ local active_plan stem slug reviews_dir
1035
+ active_plan="$(get_active_plan || true)"
1036
+ [[ -n "$active_plan" ]] || return 1
1037
+ stem="$(workflow_plan_artifact_stem_from_path "$active_plan" || true)"
1038
+ slug="$(workflow_plan_slug_from_path "$active_plan" || true)"
1039
+ [[ -n "$stem" && -n "$slug" ]] || return 1
1040
+ reviews_dir="$(workflow_repo_relative_path "$(workflow_policy_get '.tasks.reviews_dir' 'tasks/reviews')" 'tasks/reviews' 'tasks/')"
1041
+ workflow_preferred_or_legacy_path "${reviews_dir}/${stem}.review.md" "${reviews_dir}/${slug}.review.md"
952
1042
  }
953
1043
 
954
1044
  workflow_active_notes() {
955
- local slug notes_dir
956
- slug="$(workflow_contract_slug || true)"
957
- [[ -n "$slug" ]] || return 1
1045
+ local active_plan stem slug notes_dir
1046
+ active_plan="$(get_active_plan || true)"
1047
+ [[ -n "$active_plan" ]] || return 1
1048
+ stem="$(workflow_plan_artifact_stem_from_path "$active_plan" || true)"
1049
+ slug="$(workflow_plan_slug_from_path "$active_plan" || true)"
1050
+ [[ -n "$stem" && -n "$slug" ]] || return 1
958
1051
  notes_dir="$(workflow_repo_relative_path "$(workflow_policy_get '.tasks.notes_dir' 'tasks/notes')" 'tasks/notes' 'tasks/')"
959
- printf '%s/%s.notes.md' "$notes_dir" "$slug"
1052
+ workflow_preferred_or_legacy_path "${notes_dir}/${stem}.notes.md" "${notes_dir}/${slug}.notes.md"
960
1053
  }
961
1054
 
962
1055
  workflow_checks_file() {
@@ -23,6 +23,28 @@ fi
23
23
  export HOOK_REPO_ROOT="$REPO_ROOT"
24
24
  cd "$REPO_ROOT"
25
25
 
26
+ if [[ "${HOOK_HOST:-}" == "codex" && "$HOOK_NAME" == "stop-orchestrator.sh" ]]; then
27
+ tmp_stdout="$(mktemp)"
28
+ tmp_stderr="$(mktemp)"
29
+ if bash "$HOOK_PATH" "$@" >"$tmp_stdout" 2>"$tmp_stderr"; then
30
+ if grep -q '"decision"[[:space:]]*:' "$tmp_stdout"; then
31
+ cat "$tmp_stdout"
32
+ fi
33
+ rm -f "$tmp_stdout" "$tmp_stderr"
34
+ exit 0
35
+ else
36
+ hook_status=$?
37
+ if [[ -s "$tmp_stderr" ]]; then
38
+ cat "$tmp_stderr" >&2
39
+ fi
40
+ if [[ -s "$tmp_stdout" ]]; then
41
+ grep -v '^{"guard":' "$tmp_stdout" >&2 || true
42
+ fi
43
+ rm -f "$tmp_stdout" "$tmp_stderr"
44
+ exit "$hook_status"
45
+ fi
46
+ fi
47
+
26
48
  if [[ "${HOOK_HOST:-}" == "codex" && "$HOOK_NAME" != "session-start-context.sh" ]]; then
27
49
  tmp_stdout="$(mktemp)"
28
50
  tmp_stderr="$(mktemp)"
@@ -13,7 +13,10 @@ resume_file="$(workflow_resume_packet_file)"
13
13
 
14
14
  resume_available() {
15
15
  [[ -f "$resume_file" ]] || return 1
16
- grep -Fq "<!-- generated-by: project-initializer codex-handoff-resume v1 -->" "$resume_file" || return 1
16
+ {
17
+ grep -Fq "<!-- generated-by: repo-harness codex-handoff-resume v1 -->" "$resume_file" ||
18
+ grep -Fq "<!-- generated-by: project-initializer codex-handoff-resume v1 -->" "$resume_file"
19
+ } || return 1
17
20
  grep -Fq "## Resume Prompt" "$resume_file"
18
21
  }
19
22
 
@@ -254,6 +257,14 @@ EOF_CONTEXT
254
257
  fi
255
258
  }
256
259
 
260
+ input_priority_context() {
261
+ cat <<'EOF_CONTEXT'
262
+ # Input Priority
263
+
264
+ If the current user message mentions `# Files mentioned by the user`, `pasted-text.txt`, or an explicit attachment/file path, read those current-input files first. Treat handoff, resume, and `tasks/current.md` as recovery context only.
265
+ EOF_CONTEXT
266
+ }
267
+
257
268
  context=""
258
269
  if resume_current_for_handoff; then
259
270
  if context_budget_active \
@@ -293,6 +304,10 @@ if [[ -n "$current_status_context" ]]; then
293
304
  fi
294
305
  fi
295
306
 
307
+ if [[ -n "$context" ]]; then
308
+ context="$(input_priority_context)"$'\n'"${context}"
309
+ fi
310
+
296
311
  # Cross-review availability for Codex. The dispatcher swallows prompt-guard's
297
312
  # success stdout on Codex, so attach a short reminder only when SessionStart is
298
313
  # already injecting actionable context.
@@ -50,7 +50,7 @@
50
50
  "Stop": [
51
51
  {
52
52
  "hooks": [
53
- { "type": "command", "command": "repo=$(git rev-parse --show-toplevel 2>/dev/null) || exit 0; HOOK_REPO_ROOT=\"$repo\" bash \"$repo/.ai/hooks/run-hook.sh\" finalize-handoff.sh" }
53
+ { "type": "command", "command": "repo=$(git rev-parse --show-toplevel 2>/dev/null) || exit 0; HOOK_REPO_ROOT=\"$repo\" bash \"$repo/.ai/hooks/run-hook.sh\" stop-orchestrator.sh" }
54
54
  ]
55
55
  }
56
56
  ]
@@ -0,0 +1,140 @@
1
+ #!/bin/bash
2
+ # Stop Orchestrator Hook - Stop
3
+ # Refreshes handoff state and, for pending planning discussions, forces one
4
+ # self-review pass before the agent stops.
5
+
6
+ set -euo pipefail
7
+
8
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
9
+ # shellcheck source=/dev/null
10
+ . "$SCRIPT_DIR/hook-input.sh"
11
+ # shellcheck source=/dev/null
12
+ . "$SCRIPT_DIR/lib/workflow-state.sh"
13
+
14
+ plan_completeness_state_file() {
15
+ workflow_repo_relative_path \
16
+ "$(workflow_policy_get '.planning.completeness_state_file' '.ai/harness/planning/plan-completeness.json')" \
17
+ '.ai/harness/planning/plan-completeness.json' \
18
+ '.ai/harness/'
19
+ }
20
+
21
+ plan_completeness_signature() {
22
+ local kind prompt_slug draft_path source_ref created_at
23
+
24
+ kind="$(workflow_pending_orchestration_field kind 2>/dev/null || true)"
25
+ prompt_slug="$(workflow_pending_orchestration_field prompt_slug 2>/dev/null || true)"
26
+ draft_path="$(workflow_pending_orchestration_field draft_plan_path 2>/dev/null || true)"
27
+ source_ref="$(workflow_pending_orchestration_field source_ref 2>/dev/null || true)"
28
+ created_at="$(workflow_pending_orchestration_field created_at 2>/dev/null || true)"
29
+
30
+ printf '%s|%s|%s|%s|%s' \
31
+ "${kind:-unknown}" \
32
+ "${prompt_slug:-planning}" \
33
+ "${draft_path:-none}" \
34
+ "${source_ref:-none}" \
35
+ "${created_at:-unknown}"
36
+ }
37
+
38
+ plan_completeness_last_signature() {
39
+ local state_file value
40
+ state_file="$(plan_completeness_state_file)"
41
+ [[ -f "$state_file" ]] || return 1
42
+
43
+ if command -v jq >/dev/null 2>&1; then
44
+ value="$(jq -r '.last_signature // empty' "$state_file" 2>/dev/null || true)"
45
+ else
46
+ value="$(
47
+ awk '
48
+ /"last_signature"/ {
49
+ line = $0
50
+ sub(/^[^:]*:[[:space:]]*"/, "", line)
51
+ sub(/"[[:space:]]*,?[[:space:]]*$/, "", line)
52
+ print line
53
+ exit
54
+ }
55
+ ' "$state_file"
56
+ )"
57
+ fi
58
+
59
+ [[ -n "$value" ]] || return 1
60
+ printf '%s' "$value"
61
+ }
62
+
63
+ plan_completeness_record_signature() {
64
+ local signature="$1"
65
+ local state_file
66
+ state_file="$(plan_completeness_state_file)"
67
+ mkdir -p "$(dirname "$state_file")"
68
+
69
+ if command -v jq >/dev/null 2>&1; then
70
+ jq -nc \
71
+ --arg signature "$signature" \
72
+ --arg updated_at "$(date '+%Y-%m-%dT%H:%M:%S%z')" \
73
+ '{version:1,last_signature:$signature,updated_at:$updated_at}' > "$state_file"
74
+ return 0
75
+ fi
76
+
77
+ cat > "$state_file" <<EOF_STATE
78
+ {"version":1,"last_signature":"$(workflow_json_escape "$signature")","updated_at":"$(workflow_json_escape "$(date '+%Y-%m-%dT%H:%M:%S%z')")"}
79
+ EOF_STATE
80
+ }
81
+
82
+ assistant_message_looks_like_plan() {
83
+ local message="$1"
84
+ local length
85
+
86
+ length="$(printf '%s' "$message" | wc -c | tr -d ' ')"
87
+ [[ "${length:-0}" -ge 240 ]] || return 1
88
+
89
+ printf '%s\n' "$message" | grep -qEi \
90
+ '(Approved design summary|Building|Not building|Approach|Key decisions|Unknowns|Task Breakdown|Evidence Contract|P1|P2|P3|plan|design|方案|计划|设计)'
91
+ }
92
+
93
+ emit_stop_block_json() {
94
+ local reason="$1"
95
+
96
+ if command -v jq >/dev/null 2>&1; then
97
+ jq -nc --arg reason "$reason" '{decision:"block",reason:$reason}'
98
+ return 0
99
+ fi
100
+
101
+ printf '{"decision":"block","reason":"%s"}\n' "$(workflow_json_escape "$reason")"
102
+ }
103
+
104
+ refresh_handoff() {
105
+ workflow_write_handoff "session-stop"
106
+ echo "[FinalizeHandoff] Refreshed $(workflow_handoff_file)." >&2
107
+ }
108
+
109
+ should_run_plan_completeness_gate() {
110
+ local stop_active="$1"
111
+ local last_message="$2"
112
+ local active_plan
113
+
114
+ [[ "$stop_active" != "true" ]] || return 1
115
+ workflow_pending_orchestration_is_fresh || return 1
116
+
117
+ # If a repo plan is already active, the normal plan status gates own the next
118
+ # transition. This gate only covers host planning output that still needs
119
+ # capture.
120
+ active_plan="$(get_active_plan || true)"
121
+ [[ -z "$active_plan" || ! -f "$active_plan" ]] || return 1
122
+
123
+ assistant_message_looks_like_plan "$last_message"
124
+ }
125
+
126
+ refresh_handoff
127
+
128
+ stop_hook_active="$(hook_json_get '.stop_hook_active' 'false')"
129
+ last_assistant_message="$(hook_json_get '.last_assistant_message' '')"
130
+
131
+ if should_run_plan_completeness_gate "$stop_hook_active" "$last_assistant_message"; then
132
+ signature="$(plan_completeness_signature)"
133
+ if [[ "$(plan_completeness_last_signature 2>/dev/null || true)" != "$signature" ]]; then
134
+ plan_completeness_record_signature "$signature"
135
+ summary="$(workflow_pending_orchestration_summary)"
136
+ emit_stop_block_json "[PlanCompletenessGate] A first planning answer was produced while pending orchestration is still open: ${summary}
137
+
138
+ Before stopping, run one self-review pass on the plan. Do not implement. Check for missing goal/success criteria, constraints, P1 component map, P2 traced path, P3 decision rationale, fragile assumption, rejected alternative, tests, rollback/failure handling, and no placeholders. If the plan is already complete, say so explicitly and keep the revision concise. Then stop and wait for user approval."
139
+ fi
140
+ fi
@@ -50,7 +50,7 @@
50
50
  "title": "AI-Native Profile",
51
51
  "batch": 2,
52
52
  "questions": [
53
- "Choose AI-native overlay: none (default), chat-agent, runtime-console, product-copilot, workflow-agent, generative-ui-agent, browser-agent, research-agent, coding-agent, enterprise-agent-platform, voice-agent, or sidecar-kernel",
53
+ "Choose AI-native overlay: none (default), chat-agent, collaborative-editor, runtime-console, product-copilot, workflow-agent, generative-ui-agent, browser-agent, research-agent, coding-agent, enterprise-agent-platform, voice-agent, or sidecar-kernel",
54
54
  "Confirm whether generated structure should add AG-UI, assistant-ui or CopilotKit, Bun/Hono gateway, MCP/tool, sidecar, and observability boundaries"
55
55
  ],
56
56
  "required": false
@@ -278,17 +278,35 @@
278
278
  "description": "Ordinary AI chat, RAG, or help assistant inside the selected app plan.",
279
279
  "frontend": "Vite 8 + assistant-ui or the selected plan UI",
280
280
  "runtimeProtocol": "AI SDK UI stream or AG-UI lite",
281
- "backend": "Bun/Hono gateway or existing API boundary",
281
+ "backend": "Bun/Hono gateway or Mastra/Hono runtime behind the existing API boundary",
282
282
  "stateDefault": "TanStack Query + Zustand",
283
283
  "sidecarPolicy": "Python only when the model framework needs it",
284
284
  "uiSchema": "Hardcoded React components",
285
285
  "techStackRows": [
286
286
  "| AI UI | assistant-ui chat surface |",
287
287
  "| Agent stream | AI SDK UI stream or AG-UI lite |",
288
- "| Agent gateway | Bun/Hono or existing API |",
288
+ "| Agent runtime | Bun/Hono by default; Mastra when TS agents need memory, tools, workflows, or evals |",
289
289
  "| Agent state | TanStack Query + Zustand |"
290
290
  ]
291
291
  },
292
+ "collaborative-editor": {
293
+ "label": "Collaborative editor",
294
+ "description": "AI-aware document, CMS, or knowledge workspace with local-first collaboration and explicit sync ownership.",
295
+ "frontend": "Vite 8 + React 19 + Plate + shadcn/ui",
296
+ "runtimeProtocol": "Loro CRDT document events; AI SDK or AG-UI only for user-visible agent runs",
297
+ "backend": "Bun/Hono sync and agent gateway, or existing API boundary",
298
+ "stateDefault": "Loro document state + TanStack Query server cache + Zustand UI state",
299
+ "sidecarPolicy": "None by default; Python or Go sidecars only for extraction, indexing, or heavy sync workers",
300
+ "uiSchema": "Plate node/plugin schema plus app-owned document contracts",
301
+ "projectStructureFile": "assets/project-structures/ai-native-collaborative-editor.txt",
302
+ "techStackRows": [
303
+ "| Editor UI | Plate + shadcn/ui in a Vite 8 React surface |",
304
+ "| Collaboration | Loro CRDT document state and sync contracts |",
305
+ "| Agent runtime | AI SDK or AG-UI only for user-visible assistant/document actions |",
306
+ "| Sync gateway | Bun/Hono or existing API boundary owns persistence and auth |",
307
+ "| State split | Loro for document replicas; TanStack Query for server cache; Zustand for UI chrome |"
308
+ ]
309
+ },
292
310
  "runtime-console": {
293
311
  "label": "Runtime console",
294
312
  "description": "Agent runtime console with trace, replay, prompt playground, approvals, artifacts, and tool-call visibility.",
@@ -332,12 +350,12 @@
332
350
  "runtimeProtocol": "AG-UI",
333
351
  "backend": "Bun/Hono gateway",
334
352
  "stateDefault": "Jotai + Zustand + TanStack Query",
335
- "sidecarPolicy": "LangGraph, Temporal, Inngest, or BullMQ only when execution needs them",
353
+ "sidecarPolicy": "Mastra, LangGraph, Temporal, Inngest, or BullMQ only when execution needs workflow durability or orchestration",
336
354
  "uiSchema": "A2UI optional experiment",
337
355
  "techStackRows": [
338
356
  "| Workflow UI | React Flow/xyflow + Monaco |",
339
357
  "| Agent protocol | AG-UI workflow/run events |",
340
- "| Executor | Bun/Hono gateway with optional workflow engine |",
358
+ "| Executor | Bun/Hono gateway with optional Mastra or durable workflow engine |",
341
359
  "| Agent state | Jotai + Zustand + TanStack Query |"
342
360
  ]
343
361
  },
@@ -444,14 +462,14 @@
444
462
  "runtimeProtocol": "AG-UI when user-visible agent runs exist; MCP/HTTP for sidecars",
445
463
  "backend": "Bun/Hono gateway owns app-facing API",
446
464
  "stateDefault": "TanStack Query + Zustand, plus domain stores as needed",
447
- "sidecarPolicy": "Python for model/eval/data pipelines, Go for workers, Rust for low-latency parsing/indexing/sandboxing",
465
+ "sidecarPolicy": "Python ADK/FastAPI for model/eval/data pipelines, Go/Gin for high-concurrency workers or infra adapters, Rust for low-latency parsing/indexing/sandboxing",
448
466
  "uiSchema": "None by default",
449
467
  "projectStructureFile": "assets/project-structures/ai-native-sidecar-kernel.txt",
450
468
  "techStackRows": [
451
469
  "| App gateway | Bun/Hono owns app-facing API |",
452
470
  "| Sidecar protocol | MCP tools or narrow HTTP jobs |",
453
- "| Python sidecar | Model frameworks, evals, data science |",
454
- "| Go sidecar | High-concurrency workers and infra adapters |",
471
+ "| Python sidecar | Google ADK/FastAPI, model frameworks, evals, data science |",
472
+ "| Go sidecar | Gin workers, Supabase REST adapters, high-concurrency infra jobs |",
455
473
  "| Rust sidecar | Parsing, indexing, sandboxing, native kernels |"
456
474
  ]
457
475
  }
@@ -14,9 +14,9 @@ CLAUDE.md is a routing card. Keep context minimal and load only what the current
14
14
  |---------|----------------|
15
15
  | Deep codebase investigation | `tasks/research.md` |
16
16
  | Active implementation planning | `plans/plan-*.md` |
17
- | Sprint done definition | `tasks/contracts/<slug>.contract.md` |
18
- | Evaluator verdict | `tasks/reviews/<slug>.review.md` |
19
- | Implementation notes | `tasks/notes/<slug>.notes.md` |
17
+ | Sprint done definition | `tasks/contracts/<plan-stem>.contract.md` |
18
+ | Evaluator verdict | `tasks/reviews/<plan-stem>.review.md` |
19
+ | Implementation notes | `tasks/notes/<plan-stem>.notes.md` |
20
20
  | Latest verification evidence | `.ai/harness/checks/latest.json` |
21
21
  | Historical implementation context | `plans/archive/` and `tasks/archive/` |
22
22
  | Agentic skill routing | `docs/reference-configs/agentic-development-flow.md` |
@@ -36,7 +36,7 @@
36
36
  - Define per-sprint contract files in `tasks/contracts/`.
37
37
  - Verify contract exit criteria before claiming completion.
38
38
  - Require Waza `/check` to produce the matching evaluator review before any done/completed response.
39
- - Use `scripts/verify-contract.sh --contract tasks/contracts/{slug}.contract.md --strict`.
39
+ - Use `scripts/verify-contract.sh --contract tasks/contracts/{plan-stem}.contract.md --strict`.
40
40
 
41
41
  ### 7. Balanced Elegance
42
42
  - Redesign hacky non-trivial fixes before shipping.
@@ -29,16 +29,16 @@ RULES:
29
29
  - Keep multiple active plans in parallel worktrees when tasks diverge; fill workflow inventory before implementation: active plan, owning worktree, contract, review, notes, deferred ledger, checks, runs, scope owner, switching rule, and worktree path
30
30
  - Process annotation notes before implementing
31
31
  - Extract approved plan tasks into tasks/todo.md
32
- - Define task contracts in tasks/contracts/{slug}.contract.md
33
- - Fill tasks/reviews/{slug}.review.md from Waza /check after verification
34
- - Record only non-obvious implementation decisions, deviations, tradeoffs, and open questions in tasks/notes/{slug}.notes.md
32
+ - Define task contracts in tasks/contracts/{plan-stem}.contract.md
33
+ - Fill tasks/reviews/{plan-stem}.review.md from Waza /check after verification
34
+ - Record only non-obvious implementation decisions, deviations, tradeoffs, and open questions in tasks/notes/{plan-stem}.notes.md
35
35
  - Verify contracts before claiming completion
36
36
  - Require review pass before claiming completion
37
37
  - Keep tasks/todo.md limited to deferred medium/long-term goals, with tradeoff and revisit trigger; do not duplicate plan Task Breakdown
38
38
  - Record correction-derived prevention rules in tasks/lessons.md
39
39
  - Distill repeated corrections into tasks/lessons.md instead of keeping them in tasks/todo.md
40
40
  - Capture deep findings and hidden contracts in tasks/research.md
41
- - Keep sprint-level verification notes, behavior diffs, and residual risks in tasks/reviews/{slug}.review.md
41
+ - Keep sprint-level verification notes, behavior diffs, and residual risks in tasks/reviews/{plan-stem}.review.md
42
42
  - Do not use implementation notes as durable memory or task logs; archive them on close and promote only after evidence shows the rule should outlive the sprint
43
43
  - Promote implementation-ready follow-up work into a new plans/plan-{timestamp}-{slug}.md file; keep deferred goals in tasks/todo.md only when intentionally postponed
44
44
  - Treat `.ai/hooks/` as the shared automation entrypoint when repo scripts reference hook-backed workflow checks