aiwcli 0.9.0

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 (204) hide show
  1. package/README.md +1248 -0
  2. package/bin/dev.cmd +3 -0
  3. package/bin/dev.js +16 -0
  4. package/bin/run.cmd +3 -0
  5. package/bin/run.js +19 -0
  6. package/dist/commands/branch.d.ts +45 -0
  7. package/dist/commands/branch.js +488 -0
  8. package/dist/commands/clean.d.ts +34 -0
  9. package/dist/commands/clean.js +186 -0
  10. package/dist/commands/clear.d.ts +51 -0
  11. package/dist/commands/clear.js +835 -0
  12. package/dist/commands/init/index.d.ts +107 -0
  13. package/dist/commands/init/index.js +565 -0
  14. package/dist/commands/launch.d.ts +21 -0
  15. package/dist/commands/launch.js +108 -0
  16. package/dist/index.d.ts +1 -0
  17. package/dist/index.js +1 -0
  18. package/dist/lib/base-command.d.ts +114 -0
  19. package/dist/lib/base-command.js +153 -0
  20. package/dist/lib/bmad-installer.d.ts +38 -0
  21. package/dist/lib/bmad-installer.js +145 -0
  22. package/dist/lib/claude-settings-types.d.ts +102 -0
  23. package/dist/lib/claude-settings-types.js +5 -0
  24. package/dist/lib/config.d.ts +25 -0
  25. package/dist/lib/config.js +46 -0
  26. package/dist/lib/debug.d.ts +39 -0
  27. package/dist/lib/debug.js +74 -0
  28. package/dist/lib/env-compat.d.ts +26 -0
  29. package/dist/lib/env-compat.js +35 -0
  30. package/dist/lib/errors.d.ts +126 -0
  31. package/dist/lib/errors.js +145 -0
  32. package/dist/lib/generic-merge.d.ts +74 -0
  33. package/dist/lib/generic-merge.js +105 -0
  34. package/dist/lib/git/branch.d.ts +67 -0
  35. package/dist/lib/git/branch.js +155 -0
  36. package/dist/lib/git/index.d.ts +11 -0
  37. package/dist/lib/git/index.js +13 -0
  38. package/dist/lib/git/safety-checks.d.ts +44 -0
  39. package/dist/lib/git/safety-checks.js +102 -0
  40. package/dist/lib/git/types.d.ts +31 -0
  41. package/dist/lib/git/types.js +6 -0
  42. package/dist/lib/git/worktree.d.ts +67 -0
  43. package/dist/lib/git/worktree.js +220 -0
  44. package/dist/lib/gitignore-manager.d.ts +10 -0
  45. package/dist/lib/gitignore-manager.js +60 -0
  46. package/dist/lib/hooks-merger.d.ts +28 -0
  47. package/dist/lib/hooks-merger.js +94 -0
  48. package/dist/lib/ide-path-resolver.d.ts +102 -0
  49. package/dist/lib/ide-path-resolver.js +129 -0
  50. package/dist/lib/index.d.ts +13 -0
  51. package/dist/lib/index.js +22 -0
  52. package/dist/lib/output.d.ts +51 -0
  53. package/dist/lib/output.js +76 -0
  54. package/dist/lib/paths.d.ts +66 -0
  55. package/dist/lib/paths.js +136 -0
  56. package/dist/lib/quiet.d.ts +12 -0
  57. package/dist/lib/quiet.js +17 -0
  58. package/dist/lib/settings-hierarchy.d.ts +42 -0
  59. package/dist/lib/settings-hierarchy.js +105 -0
  60. package/dist/lib/spawn.d.ts +105 -0
  61. package/dist/lib/spawn.js +157 -0
  62. package/dist/lib/spinner.d.ts +19 -0
  63. package/dist/lib/spinner.js +34 -0
  64. package/dist/lib/stdin.d.ts +48 -0
  65. package/dist/lib/stdin.js +60 -0
  66. package/dist/lib/template-installer.d.ts +92 -0
  67. package/dist/lib/template-installer.js +375 -0
  68. package/dist/lib/template-linter.d.ts +49 -0
  69. package/dist/lib/template-linter.js +173 -0
  70. package/dist/lib/template-merger.d.ts +47 -0
  71. package/dist/lib/template-merger.js +173 -0
  72. package/dist/lib/template-resolver.d.ts +20 -0
  73. package/dist/lib/template-resolver.js +60 -0
  74. package/dist/lib/terminal.d.ts +102 -0
  75. package/dist/lib/terminal.js +245 -0
  76. package/dist/lib/tty-detection.d.ts +62 -0
  77. package/dist/lib/tty-detection.js +83 -0
  78. package/dist/lib/user-utils.d.ts +5 -0
  79. package/dist/lib/user-utils.js +23 -0
  80. package/dist/lib/version.d.ts +99 -0
  81. package/dist/lib/version.js +144 -0
  82. package/dist/lib/watch-templates.d.ts +6 -0
  83. package/dist/lib/watch-templates.js +73 -0
  84. package/dist/lib/windsurf-hooks-hierarchy.d.ts +30 -0
  85. package/dist/lib/windsurf-hooks-hierarchy.js +66 -0
  86. package/dist/lib/windsurf-hooks-merger.d.ts +26 -0
  87. package/dist/lib/windsurf-hooks-merger.js +53 -0
  88. package/dist/lib/windsurf-hooks-types.d.ts +33 -0
  89. package/dist/lib/windsurf-hooks-types.js +5 -0
  90. package/dist/templates/CLAUDE.md +174 -0
  91. package/dist/templates/_shared/.claude/commands/handoff.md +14 -0
  92. package/dist/templates/_shared/.claude/settings.json +61 -0
  93. package/dist/templates/_shared/.codex/workflows/handoff.md +14 -0
  94. package/dist/templates/_shared/.windsurf/workflows/handoff.md +14 -0
  95. package/dist/templates/_shared/hooks/__init__.py +16 -0
  96. package/dist/templates/_shared/hooks/archive_plan.py +270 -0
  97. package/dist/templates/_shared/hooks/context_enforcer.py +621 -0
  98. package/dist/templates/_shared/hooks/context_monitor.py +322 -0
  99. package/dist/templates/_shared/hooks/file-suggestion.py +188 -0
  100. package/dist/templates/_shared/hooks/task_create_capture.py +194 -0
  101. package/dist/templates/_shared/hooks/task_update_capture.py +254 -0
  102. package/dist/templates/_shared/hooks/user_prompt_submit.py +157 -0
  103. package/dist/templates/_shared/lib/__init__.py +1 -0
  104. package/dist/templates/_shared/lib/base/__init__.py +49 -0
  105. package/dist/templates/_shared/lib/base/__pycache__/constants.cpython-313.pyc +0 -0
  106. package/dist/templates/_shared/lib/base/atomic_write.py +180 -0
  107. package/dist/templates/_shared/lib/base/constants.py +299 -0
  108. package/dist/templates/_shared/lib/base/inference.py +189 -0
  109. package/dist/templates/_shared/lib/base/utils.py +216 -0
  110. package/dist/templates/_shared/lib/context/__init__.py +119 -0
  111. package/dist/templates/_shared/lib/context/__pycache__/__init__.cpython-313.pyc +0 -0
  112. package/dist/templates/_shared/lib/context/__pycache__/cache.cpython-313.pyc +0 -0
  113. package/dist/templates/_shared/lib/context/__pycache__/context_manager.cpython-313.pyc +0 -0
  114. package/dist/templates/_shared/lib/context/__pycache__/event_log.cpython-313.pyc +0 -0
  115. package/dist/templates/_shared/lib/context/cache.py +446 -0
  116. package/dist/templates/_shared/lib/context/context_manager.py +1171 -0
  117. package/dist/templates/_shared/lib/context/discovery.py +486 -0
  118. package/dist/templates/_shared/lib/context/event_log.py +308 -0
  119. package/dist/templates/_shared/lib/context/plan_archive.py +247 -0
  120. package/dist/templates/_shared/lib/context/task_sync.py +367 -0
  121. package/dist/templates/_shared/lib/handoff/__init__.py +22 -0
  122. package/dist/templates/_shared/lib/handoff/document_generator.py +307 -0
  123. package/dist/templates/_shared/lib/templates/README.md +215 -0
  124. package/dist/templates/_shared/lib/templates/__init__.py +40 -0
  125. package/dist/templates/_shared/lib/templates/formatters.py +147 -0
  126. package/dist/templates/_shared/lib/templates/plan_context.py +119 -0
  127. package/dist/templates/_shared/scripts/save_handoff.py +99 -0
  128. package/dist/templates/_shared/workflows/handoff.md +212 -0
  129. package/dist/templates/cc-native/.claude/agents/cc-native/ACCESSIBILITY-TESTER.md +80 -0
  130. package/dist/templates/cc-native/.claude/agents/cc-native/ARCHITECT-REVIEWER.md +75 -0
  131. package/dist/templates/cc-native/.claude/agents/cc-native/ASSUMPTION-CHAIN-TRACER.md +239 -0
  132. package/dist/templates/cc-native/.claude/agents/cc-native/CLARITY-AUDITOR.md +109 -0
  133. package/dist/templates/cc-native/.claude/agents/cc-native/CODE-REVIEWER.md +71 -0
  134. package/dist/templates/cc-native/.claude/agents/cc-native/COMPLETENESS-CHECKER.md +104 -0
  135. package/dist/templates/cc-native/.claude/agents/cc-native/CONTEXT-EXTRACTOR.md +93 -0
  136. package/dist/templates/cc-native/.claude/agents/cc-native/DEVILS-ADVOCATE.md +223 -0
  137. package/dist/templates/cc-native/.claude/agents/cc-native/DOCUMENTATION-REVIEWER.md +73 -0
  138. package/dist/templates/cc-native/.claude/agents/cc-native/FEASIBILITY-ANALYST.md +93 -0
  139. package/dist/templates/cc-native/.claude/agents/cc-native/FRESH-PERSPECTIVE.md +103 -0
  140. package/dist/templates/cc-native/.claude/agents/cc-native/HANDOFF-READINESS.md +145 -0
  141. package/dist/templates/cc-native/.claude/agents/cc-native/HIDDEN-COMPLEXITY-DETECTOR.md +248 -0
  142. package/dist/templates/cc-native/.claude/agents/cc-native/INCENTIVE-MAPPER.md +235 -0
  143. package/dist/templates/cc-native/.claude/agents/cc-native/PENETRATION-TESTER.md +80 -0
  144. package/dist/templates/cc-native/.claude/agents/cc-native/PERFORMANCE-ENGINEER.md +76 -0
  145. package/dist/templates/cc-native/.claude/agents/cc-native/PLAN-ORCHESTRATOR.md +141 -0
  146. package/dist/templates/cc-native/.claude/agents/cc-native/PRECEDENT-FINDER.md +240 -0
  147. package/dist/templates/cc-native/.claude/agents/cc-native/REVERSIBILITY-ANALYST.md +211 -0
  148. package/dist/templates/cc-native/.claude/agents/cc-native/RISK-ASSESSOR.md +101 -0
  149. package/dist/templates/cc-native/.claude/agents/cc-native/SECOND-ORDER-ANALYST.md +197 -0
  150. package/dist/templates/cc-native/.claude/agents/cc-native/SIMPLICITY-GUARDIAN.md +97 -0
  151. package/dist/templates/cc-native/.claude/agents/cc-native/SKEPTIC.md +349 -0
  152. package/dist/templates/cc-native/.claude/agents/cc-native/STAKEHOLDER-ADVOCATE.md +106 -0
  153. package/dist/templates/cc-native/.claude/agents/cc-native/TRADE-OFF-ILLUMINATOR.md +205 -0
  154. package/dist/templates/cc-native/.claude/commands/cc-native/fresh-perspective.md +8 -0
  155. package/dist/templates/cc-native/.claude/commands/cc-native/specdev.md +10 -0
  156. package/dist/templates/cc-native/.claude/settings.json +119 -0
  157. package/dist/templates/cc-native/.windsurf/workflows/cc-native/fix.md +8 -0
  158. package/dist/templates/cc-native/.windsurf/workflows/cc-native/fresh-perspective.md +8 -0
  159. package/dist/templates/cc-native/.windsurf/workflows/cc-native/implement.md +8 -0
  160. package/dist/templates/cc-native/.windsurf/workflows/cc-native/research.md +8 -0
  161. package/dist/templates/cc-native/CC-NATIVE-README.md +192 -0
  162. package/dist/templates/cc-native/MIGRATION.md +86 -0
  163. package/dist/templates/cc-native/TEMPLATE-SCHEMA.md +331 -0
  164. package/dist/templates/cc-native/_cc-native/docs/PERMISSION_REQUEST_VERIFICATION.md +147 -0
  165. package/dist/templates/cc-native/_cc-native/hooks/__pycache__/add_plan_context.cpython-313.pyc +0 -0
  166. package/dist/templates/cc-native/_cc-native/hooks/__pycache__/archive_plan.cpython-313.pyc +0 -0
  167. package/dist/templates/cc-native/_cc-native/hooks/__pycache__/cc-native-agent-review.cpython-313.pyc +0 -0
  168. package/dist/templates/cc-native/_cc-native/hooks/__pycache__/cc-native-plan-review.cpython-313.pyc +0 -0
  169. package/dist/templates/cc-native/_cc-native/hooks/__pycache__/test_permission_request.cpython-313.pyc +0 -0
  170. package/dist/templates/cc-native/_cc-native/hooks/add_plan_context.py +150 -0
  171. package/dist/templates/cc-native/_cc-native/hooks/cc-native-plan-review.py +746 -0
  172. package/dist/templates/cc-native/_cc-native/hooks/suggest-fresh-perspective.py +339 -0
  173. package/dist/templates/cc-native/_cc-native/lib/__init__.py +57 -0
  174. package/dist/templates/cc-native/_cc-native/lib/__pycache__/__init__.cpython-313.pyc +0 -0
  175. package/dist/templates/cc-native/_cc-native/lib/__pycache__/orchestrator.cpython-313.pyc +0 -0
  176. package/dist/templates/cc-native/_cc-native/lib/__pycache__/state.cpython-313.pyc +0 -0
  177. package/dist/templates/cc-native/_cc-native/lib/__pycache__/utils.cpython-313.pyc +0 -0
  178. package/dist/templates/cc-native/_cc-native/lib/async_archive.py +68 -0
  179. package/dist/templates/cc-native/_cc-native/lib/atomic_write.py +98 -0
  180. package/dist/templates/cc-native/_cc-native/lib/constants.py +45 -0
  181. package/dist/templates/cc-native/_cc-native/lib/orchestrator.py +273 -0
  182. package/dist/templates/cc-native/_cc-native/lib/reviewers/__init__.py +28 -0
  183. package/dist/templates/cc-native/_cc-native/lib/reviewers/__pycache__/__init__.cpython-313.pyc +0 -0
  184. package/dist/templates/cc-native/_cc-native/lib/reviewers/__pycache__/agent.cpython-313.pyc +0 -0
  185. package/dist/templates/cc-native/_cc-native/lib/reviewers/__pycache__/base.cpython-313.pyc +0 -0
  186. package/dist/templates/cc-native/_cc-native/lib/reviewers/__pycache__/codex.cpython-313.pyc +0 -0
  187. package/dist/templates/cc-native/_cc-native/lib/reviewers/__pycache__/gemini.cpython-313.pyc +0 -0
  188. package/dist/templates/cc-native/_cc-native/lib/reviewers/agent.py +164 -0
  189. package/dist/templates/cc-native/_cc-native/lib/reviewers/base.py +89 -0
  190. package/dist/templates/cc-native/_cc-native/lib/reviewers/codex.py +119 -0
  191. package/dist/templates/cc-native/_cc-native/lib/reviewers/gemini.py +103 -0
  192. package/dist/templates/cc-native/_cc-native/lib/state.py +251 -0
  193. package/dist/templates/cc-native/_cc-native/lib/utils.py +830 -0
  194. package/dist/templates/cc-native/_cc-native/plan-review.config.json +76 -0
  195. package/dist/templates/cc-native/_cc-native/scripts/__pycache__/aggregate_agents.cpython-313.pyc +0 -0
  196. package/dist/templates/cc-native/_cc-native/scripts/aggregate_agents.py +151 -0
  197. package/dist/templates/cc-native/_cc-native/workflows/fresh-perspective.md +134 -0
  198. package/dist/templates/cc-native/_cc-native/workflows/specdev.md +9 -0
  199. package/dist/types/exit-codes.d.ts +11 -0
  200. package/dist/types/exit-codes.js +10 -0
  201. package/dist/types/index.d.ts +5 -0
  202. package/dist/types/index.js +7 -0
  203. package/oclif.manifest.json +405 -0
  204. package/package.json +109 -0
@@ -0,0 +1,86 @@
1
+ # CC-Native v1.5.0 Migration Guide
2
+
3
+ ## Breaking Change: Context-Integrated Plan Review
4
+
5
+ **Before (v1.4.0):** Reviews stored in `_output/cc-native/plans/{date}/{slug}/reviews/`
6
+ **After (v1.5.0):** Reviews stored in `_output/contexts/{context_id}/reviews/`
7
+
8
+ ### What Changed
9
+
10
+ 1. **Removed `set_plan_state.py`** - No longer needed. Plan review now integrates with the shared context system.
11
+
12
+ 2. **Iteration state** - Now stored in `_output/contexts/{context_id}/reviews/iteration.json` instead of `~/.claude/plans/*.state.json`
13
+
14
+ 3. **Review output** - Written to context reviews folder when a context is active, with legacy fallback for backward compatibility.
15
+
16
+ ### Migration Steps
17
+
18
+ **Automatic migration** - No action required. The hook will:
19
+ - Use context reviews folder when an active context exists
20
+ - Fall back to legacy path if no context found
21
+ - Existing reviews remain in their original locations
22
+
23
+ ---
24
+
25
+ ## v1.4.0 Migration (Previous)
26
+
27
+ ### Configuration File Rename
28
+
29
+ **Before (v1.3.0):** `_cc-native/config.json`
30
+ **After (v1.4.0):** `_cc-native/plan-review.config.json`
31
+
32
+ ```bash
33
+ cd _cc-native
34
+ mv config.json plan-review.config.json
35
+ ```
36
+
37
+ ---
38
+
39
+ ## Features
40
+
41
+ ### Context-Integrated Reviews (v1.5.0)
42
+ - Reviews written to `_output/contexts/{context_id}/reviews/`
43
+ - Iteration state persists across sessions in context folder
44
+ - Automatic context discovery via session_id or single in-flight context
45
+
46
+ ### Atomic Writes
47
+ - Cross-platform atomic file writes (Windows + POSIX)
48
+ - Retry logic with backoff
49
+ - Error markers for debugging
50
+
51
+ **No action required** - Enabled by default via `CC_NATIVE_ROBUST_WRITES=true`.
52
+
53
+ ---
54
+
55
+ ## Upgrade Checklist
56
+
57
+ - [ ] Test plan workflow: exit plan mode → review → archive
58
+ - [ ] Verify reviews appear in `_output/contexts/{context_id}/reviews/`
59
+ - [ ] Check iteration tracking persists across plan revisions
60
+
61
+ ---
62
+
63
+ ## Rollback
64
+
65
+ If you need to revert to v1.4.0:
66
+
67
+ ```bash
68
+ git checkout v1.4.0 -- _cc-native/
69
+ ```
70
+
71
+ **Note:** Existing reviews in context folders will remain but won't be used.
72
+
73
+ ---
74
+
75
+ ## What Stays the Same
76
+
77
+ - Workflow files (`_cc-native/workflows/*.md`)
78
+ - Agent definitions (`.claude/agents/cc-native/`)
79
+ - All slash commands (`/cc-native:*`)
80
+ - Plan archiving behavior (`archive_plan.py`)
81
+
82
+ ---
83
+
84
+ ## Questions?
85
+
86
+ See TEMPLATE-SCHEMA.md for full documentation or report issues at the project repository.
@@ -0,0 +1,331 @@
1
+ # CC-Native Template Schema
2
+
3
+ ## Philosophy
4
+
5
+ CC-Native uses Claude Code's native tools with minimal workflow overhead. Plan review runs automatically via external CLIs (Codex/Gemini) and parallel Claude Code agents when exiting plan mode.
6
+
7
+ ---
8
+
9
+ ## Directory Structure
10
+
11
+ ```
12
+ packages/cli/src/templates/cc-native/
13
+ ├── _shared/ # SHARED: Cross-method infrastructure (Phase 1)
14
+ │ ├── lib/
15
+ │ │ ├── base/ # Base utilities
16
+ │ │ │ ├── atomic_write.py # Cross-platform atomic file writes
17
+ │ │ │ ├── constants.py # Security and configuration constants
18
+ │ │ │ └── utils.py # Common functions
19
+ │ │ └── context/ # Context management
20
+ │ │ ├── context_manager.py # Context CRUD operations
21
+ │ │ ├── event_log.py # JSONL append/read utilities
22
+ │ │ └── cache.py # Cache rebuild utilities
23
+ │ └── hooks/
24
+ │ └── session_start.py # SessionStart hook (context discovery)
25
+ ├── _cc-native/ # METHOD-SPECIFIC: CC-Native template code
26
+ │ ├── workflows/*.md # Workflow definitions
27
+ │ ├── hooks/ # Hook scripts
28
+ │ │ ├── cc-native-plan-review.py # Unified plan review (CLI + agents)
29
+ │ │ └── archive_plan.py # Archives approved plans
30
+ │ ├── lib/ # CC-Native specific utilities
31
+ │ │ ├── utils.py # Common functions for hooks
32
+ │ │ ├── atomic_write.py # Cross-platform atomic file writes
33
+ │ │ ├── async_archive.py # Non-blocking plan archival
34
+ │ │ └── constants.py # Security and configuration constants
35
+ │ ├── scripts/ # Utility scripts
36
+ │ │ └── aggregate_agents.py # Auto-detect agents from frontmatter
37
+ │ └── plan-review.config.json # Plan review configuration
38
+ ├── .claude/commands/cc-native/ # Claude Code slash commands
39
+ ├── .claude/agents/cc-native/ # Agent definitions for plan review
40
+ ├── .claude/settings.json # Hook wiring
41
+ ├── .windsurf/workflows/cc-native/ # Windsurf workflows
42
+ ├── .gitignore # Ignores _output/
43
+ ├── CC-NATIVE-README.md # User documentation
44
+ └── TEMPLATE-SCHEMA.md # This file
45
+ ```
46
+
47
+ ---
48
+
49
+ ## Native Tools Used
50
+
51
+ | Tool | Purpose |
52
+ |------|---------|
53
+ | `AskUserQuestion` | Clarify requirements before exploration |
54
+ | `Task` (Explore) | Gather codebase context via subagents |
55
+ | `Task` (general-purpose) | Execute complex subtasks |
56
+ | `EnterPlanMode` | Native planning with user approval |
57
+ | `Write` | Persist findings to scratch file (optional) |
58
+
59
+ ---
60
+
61
+ ## Workflows
62
+
63
+ | Workflow | Purpose |
64
+ |----------|---------|
65
+ | fix | Clarify → Explore → Plan → Execute |
66
+ | research | Clarify → Explore → Write findings |
67
+ | implement | Clarify → Explore → Plan → Execute (for new features) |
68
+
69
+ ---
70
+
71
+ ## Output Structure
72
+
73
+ All outputs in `_output/`:
74
+
75
+ ```
76
+ _output/
77
+ ├── index.json # Global context cache
78
+ ├── contexts/ # Context folders (method-agnostic)
79
+ │ └── {context-id}/
80
+ │ ├── context.json # Context state cache
81
+ │ ├── events.jsonl # Event log (source of truth)
82
+ │ └── plans/ # Archived plans for this context
83
+ │ └── YYYY-MM-DD-{slug}.md
84
+ ├── cc-native/ # CC-Native specific outputs
85
+ │ ├── findings.md # Research findings (optional)
86
+ │ ├── reviews/ # Combined review artifacts (CLI + agents)
87
+ │ │ └── YYYY-MM-DD/
88
+ │ │ ├── HHMMSS-session-{id}-plan.md # Copy of plan
89
+ │ │ ├── HHMMSS-session-{id}-review.json # Combined JSON
90
+ │ │ └── HHMMSS-session-{id}-review.md # Combined Markdown
91
+ │ └── scratch/ # Working notes
92
+ ```
93
+
94
+ ---
95
+
96
+ ## Configuration (`_cc-native/plan-review.config.json`)
97
+
98
+ CC-Native settings are stored in `_cc-native/plan-review.config.json`:
99
+
100
+ ```json
101
+ {
102
+ "planReview": {
103
+ "enabled": true,
104
+ "reviewers": {
105
+ "codex": { "enabled": true, "model": "", "timeout": 120 },
106
+ "gemini": { "enabled": false, "model": "", "timeout": 120 }
107
+ },
108
+ "blockOnFail": false
109
+ },
110
+ "agentReview": {
111
+ "enabled": true,
112
+ "timeout": 120,
113
+ "blockOnFail": true,
114
+ "orchestrator": {
115
+ "enabled": true,
116
+ "model": "haiku",
117
+ "timeout": 30
118
+ },
119
+ "agentSelection": {
120
+ "simple": { "min": 0, "max": 0 },
121
+ "medium": { "min": 1, "max": 2 },
122
+ "high": { "min": 2, "max": 4 },
123
+ "fallbackCount": 2
124
+ }
125
+ }
126
+ }
127
+ ```
128
+
129
+ ### Plan Review Settings (External CLIs)
130
+
131
+ | Setting | Purpose | Default |
132
+ |---------|---------|---------|
133
+ | `planReview.enabled` | Master switch for external CLI review | `true` |
134
+ | `planReview.reviewers.codex.enabled` | Use Codex CLI for review | `true` |
135
+ | `planReview.reviewers.gemini.enabled` | Use Gemini CLI for review | `false` |
136
+ | `planReview.reviewers.*.model` | Model override | `""` (use default) |
137
+ | `planReview.reviewers.*.timeout` | Seconds before timeout | `120` |
138
+ | `planReview.blockOnFail` | Block Claude if review fails | `false` |
139
+
140
+ ### Agent Review Settings (Claude Code Agents)
141
+
142
+ | Setting | Purpose | Default |
143
+ |---------|---------|---------|
144
+ | `agentReview.enabled` | Master switch for agent review | `true` |
145
+ | `agentReview.timeout` | Seconds per agent before timeout | `120` |
146
+ | `agentReview.blockOnFail` | Block Claude if any agent fails | `true` |
147
+ | `agentReview.orchestrator.enabled` | Use orchestrator for complexity analysis | `true` |
148
+ | `agentReview.orchestrator.model` | Model for orchestrator | `haiku` |
149
+ | `agentReview.agentSelection.simple` | Agent count for simple plans | `0-0` |
150
+ | `agentReview.agentSelection.medium` | Agent count for medium plans | `1-2` |
151
+ | `agentReview.agentSelection.high` | Agent count for complex plans | `2-4` |
152
+
153
+ ### Environment Variables
154
+
155
+ | Variable | Purpose | Default |
156
+ |----------|---------|---------|
157
+ | `CC_NATIVE_ROBUST_WRITES` | Enable atomic writes and retry logic | `true` |
158
+ | `CC_NATIVE_NOTIFICATIONS` | Enable voice/visual notifications | `false` |
159
+
160
+ ---
161
+
162
+ ## Context Management (Phase 1 - Event Sourced)
163
+
164
+ CC-Native uses **shared infrastructure** for cross-session context persistence:
165
+
166
+ ```
167
+ _output/
168
+ ├── index.json # CACHE: Aggregates all contexts
169
+ └── contexts/ # All contexts (method-agnostic)
170
+ ├── feature-auth/
171
+ │ ├── context.json # CACHE: Derived from events
172
+ │ ├── events.jsonl # SOURCE OF TRUTH (append-only)
173
+ │ └── plans/ # Archived plans for this context
174
+ │ └── 2026-01-25-auth.md
175
+ └── another-context/
176
+ ├── context.json
177
+ └── events.jsonl
178
+ ```
179
+
180
+ ### Data Hierarchy
181
+
182
+ | Level | File | Role | Recovery |
183
+ |-------|------|------|----------|
184
+ | 1 (Truth) | `events.jsonl` | Append-only event log | Cannot be rebuilt |
185
+ | 2 (Cache) | `context.json` | Current state snapshot | Rebuild from events |
186
+ | 3 (Cache) | `index.json` | Global context index | Rebuild from context files |
187
+
188
+ ### Context Schema
189
+
190
+ ```json
191
+ {
192
+ "id": "feature-auth",
193
+ "status": "active",
194
+ "summary": "JWT authentication system",
195
+ "method": "cc-native",
196
+ "created_at": "2026-01-20T10:00:00Z",
197
+ "last_active": "2026-01-25T09:00:00Z",
198
+ "in_flight": {
199
+ "mode": "implementing",
200
+ "artifact_path": "_output/contexts/feature-auth/plans/2026-01-25-auth.md",
201
+ "artifact_hash": "a1b2c3d4",
202
+ "started_at": "2026-01-25T09:00:00Z"
203
+ }
204
+ }
205
+ ```
206
+
207
+ ### In-Flight Mode Values
208
+
209
+ | Mode | Meaning | SessionStart Behavior |
210
+ |------|---------|----------------------|
211
+ | `none` | Normal context | Show in context picker |
212
+ | `planning` | In plan mode | Continue planning |
213
+ | `pending_implementation` | Plan approved | Auto-continue implementation |
214
+ | `implementing` | Implementation active | Continue implementation |
215
+
216
+ ### Event Types
217
+
218
+ ```jsonl
219
+ {"event":"context_created","timestamp":"2026-01-20T10:00:00Z","summary":"JWT auth","method":"cc-native"}
220
+ {"event":"task_added","task_id":"aiw-1","subject":"Add JWT middleware","timestamp":"..."}
221
+ {"event":"task_completed","task_id":"aiw-1","evidence":"tests pass","timestamp":"..."}
222
+ {"event":"plan_created","path":"_output/contexts/.../plans/...","hash":"a1b2c3","timestamp":"..."}
223
+ {"event":"context_completed","timestamp":"..."}
224
+ ```
225
+
226
+ ### Robust Writes
227
+
228
+ When `CC_NATIVE_ROBUST_WRITES=true` (default):
229
+
230
+ 1. **Atomic writes** - Uses temp file + rename (POSIX) or MoveFileExW (Windows)
231
+ 2. **Retry logic** - 2 attempts with 500ms, 1s backoff (max 1.5s retry window)
232
+ 3. **Crash safety** - If process dies mid-write, original file remains intact
233
+
234
+ **Why atomic writes?**
235
+ - Prevents corruption if hook killed mid-write
236
+ - Guarantees readers see complete file or nothing
237
+ - Cross-platform (Windows + POSIX)
238
+
239
+ ---
240
+
241
+ ## Hooks (`_cc-native/hooks/`)
242
+
243
+ Hook scripts live in `_cc-native/hooks/`. IDE-specific wiring in `.claude/settings.json`:
244
+
245
+ ```json
246
+ {
247
+ "hooks": {
248
+ "PreToolUse": [{
249
+ "matcher": "ExitPlanMode",
250
+ "hooks": [
251
+ { "type": "command", "command": "python _cc-native/hooks/cc-native-plan-review.py", "timeout": 600000 }
252
+ ]
253
+ }]
254
+ }
255
+ }
256
+ ```
257
+
258
+ **Hook order matters:** Reviews run first; archive runs on Edit/Write/Bash. If a review blocks, the plan is not archived. Only plans that pass all reviews get archived.
259
+
260
+ | Hook | Trigger | Purpose |
261
+ |------|---------|---------|
262
+ | `cc-native-plan-review.py` | ExitPlanMode | Unified review: CLI + orchestrator + agents |
263
+ | `archive_plan.py` | Edit/Write/Bash | Archives approved plans when implementation starts |
264
+
265
+ ### Claude Feedback Mechanism
266
+
267
+ The unified review hook returns structured JSON to Claude Code:
268
+
269
+ ```json
270
+ {
271
+ "hookSpecificOutput": {
272
+ "hookEventName": "PreToolUse",
273
+ "additionalContext": "Review results and recommendations..."
274
+ },
275
+ "decision": "block", // Optional: blocks Claude if review fails
276
+ "reason": "Reason for blocking..."
277
+ }
278
+ ```
279
+
280
+ When a plan fails review and `blockOnFail` is enabled, Claude is blocked from proceeding until the plan is revised.
281
+
282
+ ### Unified Review Pipeline
283
+
284
+ The `cc-native-plan-review.py` hook runs 4 phases:
285
+
286
+ 1. **Phase 1: CLI Reviewers** - Sends plan to Codex/Gemini for external review
287
+ 2. **Phase 2: Orchestrator** - Analyzes plan complexity and selects appropriate agents
288
+ 3. **Phase 3: Agent Reviews** - Spawns selected Claude Code agents in parallel
289
+ 4. **Phase 4: Combined Output** - Generates single JSON + Markdown output file
290
+
291
+ #### Orchestrator Details
292
+
293
+ The orchestrator uses a fast model (Haiku) to:
294
+ - Classify plan complexity (simple/medium/high)
295
+ - Categorize the plan (code/infrastructure/documentation/life/business/design/research)
296
+ - Select appropriate agents based on complexity and category
297
+
298
+ Simple plans skip agent review entirely. Medium/high complexity plans get 1-4 agents based on configuration.
299
+
300
+ #### Agent Execution
301
+
302
+ Each selected agent:
303
+ 1. Runs as a headless Claude Code instance with `--agent` flag
304
+ 2. Executes in parallel via ThreadPoolExecutor
305
+ 3. Uses `--permission-mode bypassPermissions` and `--max-turns 3`
306
+ 4. Returns structured JSON verdict (pass/warn/fail)
307
+
308
+ ---
309
+
310
+ ## Key Principles
311
+
312
+ 1. **Native tools first** - AskUserQuestion, Task, EnterPlanMode, Write
313
+ 2. **Minimal implicit behavior** - Only plan review runs automatically
314
+ 3. **Context efficiency** - Explore subagents discard context, findings persist
315
+ 4. **User control** - Clarification before action, plan approval before execution
316
+ 5. **Composable** - Each workflow is independent, no interdependencies
317
+ 6. **Multi-layer validation** - Plans reviewed by external CLIs + orchestrator + agents
318
+ 7. **Selective archival** - Only plans passing all reviews get archived
319
+ 8. **Single output** - One JSON + one Markdown file per review (no duplication)
320
+
321
+ ---
322
+
323
+ ## Version History
324
+
325
+ | Version | Changes |
326
+ |---------|---------|
327
+ | 1.4.0 | **Phase 1 Shared Infrastructure**: Event-sourced context management in `_shared/`, contexts in `_output/contexts/`, atomic writes. **BREAKING**: Renamed config.json → plan-review.config.json |
328
+ | 1.3.0 | Consolidated CLI + agent review into single unified hook with combined output |
329
+ | 1.2.0 | Added multi-agent plan review via Claude Code agents, reordered hooks (archive last) |
330
+ | 1.1.0 | Added plan review via Codex/Gemini with Claude feedback, config.json |
331
+ | 1.0.0 | Initial release with fix, research, implement workflows |
@@ -0,0 +1,147 @@
1
+ # PermissionRequest Hook Verification Plan
2
+
3
+ ## Objective
4
+
5
+ Verify that `PermissionRequest` event can be used for plan archiving instead of the current `PreToolUse` + state file approach.
6
+
7
+ ## Current Implementation (v1.5.0+)
8
+
9
+ ```
10
+ PreToolUse: ExitPlanMode
11
+ └── cc-native-plan-review.py (runs agent reviews, saves to context reviews folder)
12
+
13
+ PostToolUse: ExitPlanMode
14
+ └── archive_plan.py (archives plan to context plans folder)
15
+ ```
16
+
17
+ **Note:** As of v1.5.0, `set_plan_state.py` has been removed. Plan review now integrates with the shared context system, storing reviews in `_output/contexts/{context_id}/reviews/`.
18
+
19
+ ## Original Proposed Simplification (Historical)
20
+
21
+ ```
22
+ PreToolUse: ExitPlanMode
23
+ └── cc-native-plan-review.py (runs reviews, saves to context folder)
24
+
25
+ PermissionRequest: ExitPlanMode ← Tested approach
26
+ └── archive_plan.py (archives immediately after reviews complete)
27
+ ```
28
+
29
+ ## Verification Steps
30
+
31
+ ### Step 1: Deploy Test Hook
32
+
33
+ The test hook has been added:
34
+ - **Hook:** `_cc-native/hooks/test_permission_request.py`
35
+ - **Config:** `PermissionRequest` entry in `.claude/settings.json`
36
+ - **Output:** `~/.claude/permission_request_payload.json`
37
+
38
+ ### Step 2: Trigger Plan Mode
39
+
40
+ 1. Start Claude Code with cc-native template:
41
+ ```bash
42
+ cd /path/to/project-with-cc-native
43
+ claude --plan
44
+ ```
45
+
46
+ 2. Create a simple plan (any task works)
47
+
48
+ 3. When plan is ready, Claude calls `ExitPlanMode`
49
+
50
+ ### Step 3: Check Results
51
+
52
+ After Claude calls `ExitPlanMode`, check:
53
+
54
+ ```bash
55
+ # Check if payload was logged
56
+ cat ~/.claude/permission_request_payload.json
57
+ ```
58
+
59
+ Expected output:
60
+ ```json
61
+ {
62
+ "received_at": "2026-01-20T...",
63
+ "payload": {
64
+ "tool_name": "ExitPlanMode",
65
+ "session_id": "...",
66
+ "cwd": "...",
67
+ "tool_input": {...}
68
+ },
69
+ "analysis": {
70
+ "has_tool_name": true,
71
+ "has_session_id": true,
72
+ "has_cwd": true,
73
+ "has_tool_input": true,
74
+ "tool_name": "ExitPlanMode",
75
+ "payload_keys": ["tool_name", "session_id", "cwd", "tool_input", ...]
76
+ }
77
+ }
78
+ ```
79
+
80
+ ### Step 4: Verify Timing
81
+
82
+ Check stderr logs during plan mode exit:
83
+
84
+ ```
85
+ [cc-native-plan-review] Unified hook started (PreToolUse)
86
+ [cc-native-plan-review] Using context reviews dir: ...
87
+ [cc-native-plan-review] Review complete...
88
+ [test_permission_request] Hook started (PermissionRequest) ← Should appear AFTER reviews
89
+ [test_permission_request] SUCCESS: All required fields present
90
+ ```
91
+
92
+ **Critical timing requirement:** PermissionRequest must fire:
93
+ 1. AFTER PreToolUse hooks complete (reviews done)
94
+ 2. BEFORE user sees the approval prompt
95
+
96
+ ## Decision Checklist
97
+
98
+ After verification, update this checklist:
99
+
100
+ - [ ] PermissionRequest fires for ExitPlanMode
101
+ - [ ] Payload contains `tool_name`
102
+ - [ ] Payload contains `session_id`
103
+ - [ ] Payload contains `cwd`
104
+ - [ ] Timing: fires AFTER PreToolUse
105
+ - [ ] Timing: fires BEFORE user prompt shown
106
+ - [ ] `archive_plan.py` works with PermissionRequest payload (or minimal changes needed)
107
+
108
+ ## Phase 2: Migration (if verified)
109
+
110
+ If all checks pass:
111
+
112
+ 1. Modify `archive_plan.py` if needed for PermissionRequest payload
113
+ 2. Add production PermissionRequest entry for archive_plan.py
114
+ 3. Remove `Edit|Write|Bash` PreToolUse entry for archive_plan.py
115
+ 4. Remove `Stop` entry for archive_plan.py
116
+ 5. Remove test_permission_request.py hook
117
+ 6. Test full flow end-to-end
118
+
119
+ ## Potential Issues
120
+
121
+ ### Issue 1: PermissionRequest may not fire for ExitPlanMode
122
+
123
+ ExitPlanMode is a special tool that shows the plan approval prompt. It's possible that:
124
+ - PermissionRequest only fires for dangerous tools (Bash, Write, etc.)
125
+ - ExitPlanMode uses a different permission flow
126
+
127
+ **Mitigation:** The test hook will confirm whether it fires or not.
128
+
129
+ ### Issue 2: Different payload structure
130
+
131
+ PermissionRequest may have different fields than PreToolUse.
132
+
133
+ **Mitigation:** The test hook logs all payload keys for analysis.
134
+
135
+ ### Issue 3: Timing may be wrong
136
+
137
+ PermissionRequest might fire BEFORE PreToolUse hooks complete (before reviews).
138
+
139
+ **Mitigation:** Check stderr log ordering during test.
140
+
141
+ ## Cleanup
142
+
143
+ After verification:
144
+ 1. Remove `test_permission_request.py` hook
145
+ 2. Remove PermissionRequest test entry from settings.json
146
+ 3. Delete `~/.claude/permission_request_payload.json`
147
+ 4. Document findings in this file