aiwcli 0.10.2 → 0.11.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 (249) hide show
  1. package/bin/run.js +1 -1
  2. package/dist/commands/clear.d.ts +11 -6
  3. package/dist/commands/clear.js +229 -381
  4. package/dist/commands/init/index.d.ts +1 -17
  5. package/dist/commands/init/index.js +22 -107
  6. package/dist/lib/gitignore-manager.d.ts +32 -0
  7. package/dist/lib/gitignore-manager.js +141 -2
  8. package/dist/lib/template-installer.d.ts +7 -12
  9. package/dist/lib/template-installer.js +69 -193
  10. package/dist/lib/template-settings-reconstructor.d.ts +35 -0
  11. package/dist/lib/template-settings-reconstructor.js +130 -0
  12. package/dist/templates/CLAUDE.md +8 -8
  13. package/dist/templates/_shared/.claude/commands/handoff-resume.md +64 -0
  14. package/dist/templates/_shared/.claude/commands/handoff.md +16 -10
  15. package/dist/templates/_shared/.claude/settings.json +7 -7
  16. package/dist/templates/_shared/hooks-ts/_utils/git-state.ts +2 -0
  17. package/dist/templates/_shared/hooks-ts/archive_plan.ts +159 -0
  18. package/dist/templates/_shared/hooks-ts/context_monitor.ts +147 -0
  19. package/dist/templates/_shared/hooks-ts/file-suggestion.ts +130 -0
  20. package/dist/templates/_shared/hooks-ts/pre_compact.ts +49 -0
  21. package/dist/templates/_shared/hooks-ts/session_end.ts +104 -0
  22. package/dist/templates/_shared/hooks-ts/session_start.ts +144 -0
  23. package/dist/templates/_shared/hooks-ts/task_create_capture.ts +48 -0
  24. package/dist/templates/_shared/hooks-ts/task_update_capture.ts +74 -0
  25. package/dist/templates/_shared/hooks-ts/user_prompt_submit.ts +83 -0
  26. package/dist/templates/_shared/lib-ts/CLAUDE.md +318 -0
  27. package/dist/templates/_shared/lib-ts/base/atomic-write.ts +138 -0
  28. package/dist/templates/_shared/lib-ts/base/constants.ts +306 -0
  29. package/dist/templates/_shared/lib-ts/base/git-state.ts +58 -0
  30. package/dist/templates/_shared/lib-ts/base/hook-utils.ts +439 -0
  31. package/dist/templates/_shared/lib-ts/base/inference.ts +252 -0
  32. package/dist/templates/_shared/lib-ts/base/logger.ts +250 -0
  33. package/dist/templates/_shared/lib-ts/base/state-io.ts +116 -0
  34. package/dist/templates/_shared/lib-ts/base/stop-words.ts +184 -0
  35. package/dist/templates/_shared/lib-ts/base/subprocess-utils.ts +162 -0
  36. package/dist/templates/_shared/lib-ts/base/utils.ts +184 -0
  37. package/dist/templates/_shared/lib-ts/context/context-formatter.ts +438 -0
  38. package/dist/templates/_shared/lib-ts/context/context-selector.ts +515 -0
  39. package/dist/templates/_shared/lib-ts/context/context-store.ts +707 -0
  40. package/dist/templates/_shared/lib-ts/context/plan-manager.ts +316 -0
  41. package/dist/templates/_shared/lib-ts/context/task-tracker.ts +185 -0
  42. package/dist/templates/_shared/lib-ts/handoff/document-generator.ts +216 -0
  43. package/dist/templates/_shared/lib-ts/handoff/handoff-reader.ts +159 -0
  44. package/dist/templates/_shared/lib-ts/package.json +21 -0
  45. package/dist/templates/_shared/lib-ts/templates/formatters.ts +104 -0
  46. package/dist/templates/_shared/{lib/templates/plan_context.py → lib-ts/templates/plan-context.ts} +14 -22
  47. package/dist/templates/_shared/lib-ts/tsconfig.json +13 -0
  48. package/dist/templates/_shared/lib-ts/types.ts +164 -0
  49. package/dist/templates/_shared/scripts/resolve_context.ts +24 -0
  50. package/dist/templates/_shared/scripts/resume_handoff.ts +321 -0
  51. package/dist/templates/_shared/scripts/save_handoff.ts +359 -0
  52. package/dist/templates/_shared/scripts/status_line.ts +733 -0
  53. package/dist/templates/cc-native/.claude/settings.json +175 -185
  54. package/dist/templates/cc-native/TEMPLATE-SCHEMA.md +15 -17
  55. package/dist/templates/cc-native/_cc-native/agents/ARCH-EVOLUTION.md +63 -0
  56. package/dist/templates/cc-native/_cc-native/agents/ARCH-PATTERNS.md +62 -0
  57. package/dist/templates/cc-native/_cc-native/agents/ARCH-STRUCTURE.md +63 -0
  58. package/dist/templates/cc-native/_cc-native/agents/{ASSUMPTION-CHAIN-TRACER.md → ASSUMPTION-TRACER.md} +6 -10
  59. package/dist/templates/cc-native/_cc-native/agents/CLARITY-AUDITOR.md +6 -10
  60. package/dist/templates/cc-native/_cc-native/agents/CLAUDE.md +74 -3
  61. package/dist/templates/cc-native/_cc-native/agents/COMPLETENESS-FEASIBILITY.md +67 -0
  62. package/dist/templates/cc-native/_cc-native/agents/COMPLETENESS-GAPS.md +71 -0
  63. package/dist/templates/cc-native/_cc-native/agents/COMPLETENESS-ORDERING.md +63 -0
  64. package/dist/templates/cc-native/_cc-native/agents/CONSTRAINT-VALIDATOR.md +73 -0
  65. package/dist/templates/cc-native/_cc-native/agents/DESIGN-ADR-VALIDATOR.md +62 -0
  66. package/dist/templates/cc-native/_cc-native/agents/DESIGN-SCALE-MATCHER.md +65 -0
  67. package/dist/templates/cc-native/_cc-native/agents/DEVILS-ADVOCATE.md +6 -9
  68. package/dist/templates/cc-native/_cc-native/agents/DOCUMENTATION-PHILOSOPHY.md +87 -0
  69. package/dist/templates/cc-native/_cc-native/agents/HANDOFF-READINESS.md +5 -9
  70. package/dist/templates/cc-native/_cc-native/agents/{HIDDEN-COMPLEXITY-DETECTOR.md → HIDDEN-COMPLEXITY.md} +6 -10
  71. package/dist/templates/cc-native/_cc-native/agents/INCREMENTAL-DELIVERY.md +67 -0
  72. package/dist/templates/cc-native/_cc-native/agents/PLAN-ORCHESTRATOR.md +91 -18
  73. package/dist/templates/cc-native/_cc-native/agents/RISK-DEPENDENCY.md +63 -0
  74. package/dist/templates/cc-native/_cc-native/agents/RISK-FMEA.md +67 -0
  75. package/dist/templates/cc-native/_cc-native/agents/RISK-PREMORTEM.md +72 -0
  76. package/dist/templates/cc-native/_cc-native/agents/RISK-REVERSIBILITY.md +75 -0
  77. package/dist/templates/cc-native/_cc-native/agents/SCOPE-BOUNDARY.md +78 -0
  78. package/dist/templates/cc-native/_cc-native/agents/SIMPLICITY-GUARDIAN.md +5 -9
  79. package/dist/templates/cc-native/_cc-native/agents/SKEPTIC.md +16 -12
  80. package/dist/templates/cc-native/_cc-native/agents/TESTDRIVEN-BEHAVIOR-AUDITOR.md +62 -0
  81. package/dist/templates/cc-native/_cc-native/agents/TESTDRIVEN-CHARACTERIZATION.md +72 -0
  82. package/dist/templates/cc-native/_cc-native/agents/TESTDRIVEN-FIRST-VALIDATOR.md +62 -0
  83. package/dist/templates/cc-native/_cc-native/agents/TESTDRIVEN-PYRAMID-ANALYZER.md +62 -0
  84. package/dist/templates/cc-native/_cc-native/agents/TRADEOFF-COSTS.md +68 -0
  85. package/dist/templates/cc-native/_cc-native/agents/TRADEOFF-STAKEHOLDERS.md +66 -0
  86. package/dist/templates/cc-native/_cc-native/agents/VERIFY-COVERAGE.md +75 -0
  87. package/dist/templates/cc-native/_cc-native/agents/VERIFY-STRENGTH.md +70 -0
  88. package/dist/templates/cc-native/_cc-native/hooks/CLAUDE.md +109 -135
  89. package/dist/templates/cc-native/_cc-native/hooks/add_plan_context.ts +119 -0
  90. package/dist/templates/cc-native/_cc-native/hooks/cc-native-plan-review.ts +921 -0
  91. package/dist/templates/cc-native/_cc-native/hooks/plan_questions_early.ts +61 -0
  92. package/dist/templates/cc-native/_cc-native/lib-ts/aggregate-agents.ts +157 -0
  93. package/dist/templates/cc-native/_cc-native/lib-ts/artifacts.ts +709 -0
  94. package/dist/templates/cc-native/_cc-native/lib-ts/cc-native-state.ts +199 -0
  95. package/dist/templates/cc-native/_cc-native/lib-ts/cli-output-parser.ts +124 -0
  96. package/dist/templates/cc-native/_cc-native/lib-ts/config.ts +57 -0
  97. package/dist/templates/cc-native/_cc-native/lib-ts/constants.ts +83 -0
  98. package/dist/templates/cc-native/_cc-native/lib-ts/debug.ts +80 -0
  99. package/dist/templates/cc-native/_cc-native/lib-ts/index.ts +119 -0
  100. package/dist/templates/cc-native/_cc-native/lib-ts/json-parser.ts +162 -0
  101. package/dist/templates/cc-native/_cc-native/lib-ts/nul +3 -0
  102. package/dist/templates/cc-native/_cc-native/lib-ts/orchestrator.ts +249 -0
  103. package/dist/templates/cc-native/_cc-native/lib-ts/reviewers/agent.ts +155 -0
  104. package/dist/templates/cc-native/_cc-native/lib-ts/reviewers/codex.ts +130 -0
  105. package/dist/templates/cc-native/_cc-native/lib-ts/reviewers/gemini.ts +106 -0
  106. package/dist/templates/cc-native/_cc-native/lib-ts/reviewers/index.ts +10 -0
  107. package/dist/templates/cc-native/_cc-native/lib-ts/reviewers/types.ts +23 -0
  108. package/dist/templates/cc-native/_cc-native/lib-ts/state.ts +243 -0
  109. package/dist/templates/cc-native/_cc-native/lib-ts/tsconfig.json +18 -0
  110. package/dist/templates/cc-native/_cc-native/lib-ts/types.ts +310 -0
  111. package/dist/templates/cc-native/_cc-native/lib-ts/verdict.ts +72 -0
  112. package/dist/templates/cc-native/_cc-native/plan-review.config.json +12 -16
  113. package/oclif.manifest.json +1 -1
  114. package/package.json +1 -1
  115. package/dist/lib/template-merger.d.ts +0 -47
  116. package/dist/lib/template-merger.js +0 -162
  117. package/dist/templates/_shared/hooks/__init__.py +0 -16
  118. package/dist/templates/_shared/hooks/__pycache__/__init__.cpython-313.pyc +0 -0
  119. package/dist/templates/_shared/hooks/__pycache__/archive_plan.cpython-313.pyc +0 -0
  120. package/dist/templates/_shared/hooks/__pycache__/context_enforcer.cpython-313.pyc +0 -0
  121. package/dist/templates/_shared/hooks/__pycache__/context_monitor.cpython-313.pyc +0 -0
  122. package/dist/templates/_shared/hooks/__pycache__/file-suggestion.cpython-313.pyc +0 -0
  123. package/dist/templates/_shared/hooks/__pycache__/pre_compact.cpython-313.pyc +0 -0
  124. package/dist/templates/_shared/hooks/__pycache__/session_end.cpython-313.pyc +0 -0
  125. package/dist/templates/_shared/hooks/__pycache__/session_start.cpython-313.pyc +0 -0
  126. package/dist/templates/_shared/hooks/__pycache__/task_create_atomicity.cpython-313.pyc +0 -0
  127. package/dist/templates/_shared/hooks/__pycache__/task_create_capture.cpython-313.pyc +0 -0
  128. package/dist/templates/_shared/hooks/__pycache__/task_update_capture.cpython-313.pyc +0 -0
  129. package/dist/templates/_shared/hooks/__pycache__/user_prompt_submit.cpython-313.pyc +0 -0
  130. package/dist/templates/_shared/hooks/archive_plan.py +0 -169
  131. package/dist/templates/_shared/hooks/context_monitor.py +0 -270
  132. package/dist/templates/_shared/hooks/file-suggestion.py +0 -215
  133. package/dist/templates/_shared/hooks/pre_compact.py +0 -104
  134. package/dist/templates/_shared/hooks/session_end.py +0 -173
  135. package/dist/templates/_shared/hooks/session_start.py +0 -206
  136. package/dist/templates/_shared/hooks/task_create_capture.py +0 -108
  137. package/dist/templates/_shared/hooks/task_update_capture.py +0 -145
  138. package/dist/templates/_shared/hooks/user_prompt_submit.py +0 -139
  139. package/dist/templates/_shared/lib/__init__.py +0 -1
  140. package/dist/templates/_shared/lib/__pycache__/__init__.cpython-313.pyc +0 -0
  141. package/dist/templates/_shared/lib/base/__init__.py +0 -65
  142. package/dist/templates/_shared/lib/base/__pycache__/__init__.cpython-313.pyc +0 -0
  143. package/dist/templates/_shared/lib/base/__pycache__/atomic_write.cpython-313.pyc +0 -0
  144. package/dist/templates/_shared/lib/base/__pycache__/constants.cpython-313.pyc +0 -0
  145. package/dist/templates/_shared/lib/base/__pycache__/hook_utils.cpython-313.pyc +0 -0
  146. package/dist/templates/_shared/lib/base/__pycache__/inference.cpython-313.pyc +0 -0
  147. package/dist/templates/_shared/lib/base/__pycache__/logger.cpython-313.pyc +0 -0
  148. package/dist/templates/_shared/lib/base/__pycache__/stop_words.cpython-313.pyc +0 -0
  149. package/dist/templates/_shared/lib/base/__pycache__/subprocess_utils.cpython-313.pyc +0 -0
  150. package/dist/templates/_shared/lib/base/__pycache__/utils.cpython-313.pyc +0 -0
  151. package/dist/templates/_shared/lib/base/atomic_write.py +0 -180
  152. package/dist/templates/_shared/lib/base/constants.py +0 -358
  153. package/dist/templates/_shared/lib/base/hook_utils.py +0 -341
  154. package/dist/templates/_shared/lib/base/inference.py +0 -318
  155. package/dist/templates/_shared/lib/base/logger.py +0 -291
  156. package/dist/templates/_shared/lib/base/stop_words.py +0 -213
  157. package/dist/templates/_shared/lib/base/subprocess_utils.py +0 -46
  158. package/dist/templates/_shared/lib/base/utils.py +0 -242
  159. package/dist/templates/_shared/lib/context/__init__.py +0 -102
  160. package/dist/templates/_shared/lib/context/__pycache__/__init__.cpython-313.pyc +0 -0
  161. package/dist/templates/_shared/lib/context/__pycache__/cache.cpython-313.pyc +0 -0
  162. package/dist/templates/_shared/lib/context/__pycache__/context_extractor.cpython-313.pyc +0 -0
  163. package/dist/templates/_shared/lib/context/__pycache__/context_formatter.cpython-313.pyc +0 -0
  164. package/dist/templates/_shared/lib/context/__pycache__/context_manager.cpython-313.pyc +0 -0
  165. package/dist/templates/_shared/lib/context/__pycache__/context_selector.cpython-313.pyc +0 -0
  166. package/dist/templates/_shared/lib/context/__pycache__/context_store.cpython-313.pyc +0 -0
  167. package/dist/templates/_shared/lib/context/__pycache__/discovery.cpython-313.pyc +0 -0
  168. package/dist/templates/_shared/lib/context/__pycache__/event_log.cpython-313.pyc +0 -0
  169. package/dist/templates/_shared/lib/context/__pycache__/plan_archive.cpython-313.pyc +0 -0
  170. package/dist/templates/_shared/lib/context/__pycache__/plan_manager.cpython-313.pyc +0 -0
  171. package/dist/templates/_shared/lib/context/__pycache__/task_sync.cpython-313.pyc +0 -0
  172. package/dist/templates/_shared/lib/context/__pycache__/task_tracker.cpython-313.pyc +0 -0
  173. package/dist/templates/_shared/lib/context/context_formatter.py +0 -317
  174. package/dist/templates/_shared/lib/context/context_selector.py +0 -508
  175. package/dist/templates/_shared/lib/context/context_store.py +0 -653
  176. package/dist/templates/_shared/lib/context/plan_manager.py +0 -204
  177. package/dist/templates/_shared/lib/context/task_tracker.py +0 -188
  178. package/dist/templates/_shared/lib/handoff/__init__.py +0 -22
  179. package/dist/templates/_shared/lib/handoff/__pycache__/__init__.cpython-313.pyc +0 -0
  180. package/dist/templates/_shared/lib/handoff/__pycache__/document_generator.cpython-313.pyc +0 -0
  181. package/dist/templates/_shared/lib/handoff/document_generator.py +0 -278
  182. package/dist/templates/_shared/lib/templates/README.md +0 -206
  183. package/dist/templates/_shared/lib/templates/__init__.py +0 -36
  184. package/dist/templates/_shared/lib/templates/__pycache__/__init__.cpython-313.pyc +0 -0
  185. package/dist/templates/_shared/lib/templates/__pycache__/formatters.cpython-313.pyc +0 -0
  186. package/dist/templates/_shared/lib/templates/__pycache__/persona_questions.cpython-313.pyc +0 -0
  187. package/dist/templates/_shared/lib/templates/__pycache__/plan_context.cpython-313.pyc +0 -0
  188. package/dist/templates/_shared/lib/templates/formatters.py +0 -146
  189. package/dist/templates/_shared/scripts/__pycache__/save_handoff.cpython-313.pyc +0 -0
  190. package/dist/templates/_shared/scripts/__pycache__/status_line.cpython-313.pyc +0 -0
  191. package/dist/templates/_shared/scripts/save_handoff.py +0 -357
  192. package/dist/templates/_shared/scripts/status_line.py +0 -701
  193. package/dist/templates/cc-native/.claude/commands/cc-native/fresh-perspective.md +0 -8
  194. package/dist/templates/cc-native/.windsurf/workflows/cc-native/fresh-perspective.md +0 -8
  195. package/dist/templates/cc-native/MIGRATION.md +0 -86
  196. package/dist/templates/cc-native/_cc-native/agents/ACCESSIBILITY-TESTER.md +0 -79
  197. package/dist/templates/cc-native/_cc-native/agents/ARCHITECT-REVIEWER.md +0 -48
  198. package/dist/templates/cc-native/_cc-native/agents/CODE-REVIEWER.md +0 -70
  199. package/dist/templates/cc-native/_cc-native/agents/COMPLETENESS-CHECKER.md +0 -59
  200. package/dist/templates/cc-native/_cc-native/agents/CONTEXT-EXTRACTOR.md +0 -92
  201. package/dist/templates/cc-native/_cc-native/agents/DOCUMENTATION-REVIEWER.md +0 -51
  202. package/dist/templates/cc-native/_cc-native/agents/FEASIBILITY-ANALYST.md +0 -57
  203. package/dist/templates/cc-native/_cc-native/agents/FRESH-PERSPECTIVE.md +0 -54
  204. package/dist/templates/cc-native/_cc-native/agents/INCENTIVE-MAPPER.md +0 -61
  205. package/dist/templates/cc-native/_cc-native/agents/PENETRATION-TESTER.md +0 -79
  206. package/dist/templates/cc-native/_cc-native/agents/PERFORMANCE-ENGINEER.md +0 -75
  207. package/dist/templates/cc-native/_cc-native/agents/PRECEDENT-FINDER.md +0 -70
  208. package/dist/templates/cc-native/_cc-native/agents/REVERSIBILITY-ANALYST.md +0 -61
  209. package/dist/templates/cc-native/_cc-native/agents/RISK-ASSESSOR.md +0 -58
  210. package/dist/templates/cc-native/_cc-native/agents/SECOND-ORDER-ANALYST.md +0 -61
  211. package/dist/templates/cc-native/_cc-native/agents/STAKEHOLDER-ADVOCATE.md +0 -55
  212. package/dist/templates/cc-native/_cc-native/agents/TRADE-OFF-ILLUMINATOR.md +0 -204
  213. package/dist/templates/cc-native/_cc-native/hooks/__pycache__/add_plan_context.cpython-313.pyc +0 -0
  214. package/dist/templates/cc-native/_cc-native/hooks/__pycache__/cc-native-plan-review.cpython-313.pyc +0 -0
  215. package/dist/templates/cc-native/_cc-native/hooks/__pycache__/mark_questions_asked.cpython-313.pyc +0 -0
  216. package/dist/templates/cc-native/_cc-native/hooks/__pycache__/plan_accepted.cpython-313.pyc +0 -0
  217. package/dist/templates/cc-native/_cc-native/hooks/__pycache__/plan_questions_early.cpython-313.pyc +0 -0
  218. package/dist/templates/cc-native/_cc-native/hooks/__pycache__/suggest-fresh-perspective.cpython-313.pyc +0 -0
  219. package/dist/templates/cc-native/_cc-native/hooks/add_plan_context.py +0 -130
  220. package/dist/templates/cc-native/_cc-native/hooks/cc-native-plan-review.py +0 -869
  221. package/dist/templates/cc-native/_cc-native/hooks/plan_questions_early.py +0 -81
  222. package/dist/templates/cc-native/_cc-native/hooks/suggest-fresh-perspective.py +0 -340
  223. package/dist/templates/cc-native/_cc-native/lib/CLAUDE.md +0 -265
  224. package/dist/templates/cc-native/_cc-native/lib/__init__.py +0 -53
  225. package/dist/templates/cc-native/_cc-native/lib/__pycache__/__init__.cpython-313.pyc +0 -0
  226. package/dist/templates/cc-native/_cc-native/lib/__pycache__/atomic_write.cpython-313.pyc +0 -0
  227. package/dist/templates/cc-native/_cc-native/lib/__pycache__/constants.cpython-313.pyc +0 -0
  228. package/dist/templates/cc-native/_cc-native/lib/__pycache__/debug.cpython-313.pyc +0 -0
  229. package/dist/templates/cc-native/_cc-native/lib/__pycache__/orchestrator.cpython-313.pyc +0 -0
  230. package/dist/templates/cc-native/_cc-native/lib/__pycache__/state.cpython-313.pyc +0 -0
  231. package/dist/templates/cc-native/_cc-native/lib/__pycache__/utils.cpython-313.pyc +0 -0
  232. package/dist/templates/cc-native/_cc-native/lib/constants.py +0 -45
  233. package/dist/templates/cc-native/_cc-native/lib/debug.py +0 -139
  234. package/dist/templates/cc-native/_cc-native/lib/orchestrator.py +0 -362
  235. package/dist/templates/cc-native/_cc-native/lib/reviewers/__init__.py +0 -28
  236. package/dist/templates/cc-native/_cc-native/lib/reviewers/__pycache__/__init__.cpython-313.pyc +0 -0
  237. package/dist/templates/cc-native/_cc-native/lib/reviewers/__pycache__/agent.cpython-313.pyc +0 -0
  238. package/dist/templates/cc-native/_cc-native/lib/reviewers/__pycache__/base.cpython-313.pyc +0 -0
  239. package/dist/templates/cc-native/_cc-native/lib/reviewers/__pycache__/codex.cpython-313.pyc +0 -0
  240. package/dist/templates/cc-native/_cc-native/lib/reviewers/__pycache__/gemini.cpython-313.pyc +0 -0
  241. package/dist/templates/cc-native/_cc-native/lib/reviewers/agent.py +0 -215
  242. package/dist/templates/cc-native/_cc-native/lib/reviewers/base.py +0 -88
  243. package/dist/templates/cc-native/_cc-native/lib/reviewers/codex.py +0 -124
  244. package/dist/templates/cc-native/_cc-native/lib/reviewers/gemini.py +0 -108
  245. package/dist/templates/cc-native/_cc-native/lib/state.py +0 -268
  246. package/dist/templates/cc-native/_cc-native/lib/utils.py +0 -1027
  247. package/dist/templates/cc-native/_cc-native/scripts/__pycache__/aggregate_agents.cpython-313.pyc +0 -0
  248. package/dist/templates/cc-native/_cc-native/scripts/aggregate_agents.py +0 -168
  249. package/dist/templates/cc-native/_cc-native/workflows/fresh-perspective.md +0 -134
@@ -0,0 +1,199 @@
1
+ /**
2
+ * CC-native state accessor for context state.json.
3
+ * Deduplicates state access patterns for cc-native hooks.
4
+ * See cc-native-plan-review-spec.md §4.5
5
+ */
6
+
7
+ import type {
8
+ CcNativeState,
9
+ IterationState,
10
+ PlanReviewState,
11
+ QuestionsAskedState as _QuestionsAskedState,
12
+ } from "./types.js";
13
+ import { logInfo, logWarn } from "../../_shared/lib-ts/base/logger.js";
14
+ import { nowIso } from "../../_shared/lib-ts/base/utils.js";
15
+ import { getContextBySessionId, saveState } from "../../_shared/lib-ts/context/context-store.js";
16
+ import type { ContextState } from "../../_shared/lib-ts/types.js";
17
+
18
+ /**
19
+ * ContextState extended with the cc_native method-specific data.
20
+ * ContextState doesn't include cc_native in its type definition because it's
21
+ * a shared type. This local extension bridges the gap for cc-native code.
22
+ */
23
+ type CcNativeContextState = ContextState & { cc_native?: CcNativeState };
24
+
25
+ // ---------------------------------------------------------------------------
26
+ // Core State Access
27
+ // ---------------------------------------------------------------------------
28
+
29
+ /**
30
+ * Get cc_native state from context state.json.
31
+ * Returns the cc_native dict or null if not found.
32
+ */
33
+ export function getCcNativeState(
34
+ sessionId: string,
35
+ projectRoot: string,
36
+ ): CcNativeState | null {
37
+ try {
38
+ const state = getContextBySessionId(sessionId, projectRoot) as CcNativeContextState | null;
39
+ if (state?.cc_native && typeof state.cc_native === "object") {
40
+ return state.cc_native;
41
+ }
42
+ } catch {
43
+ // Fail-safe: return null
44
+ }
45
+
46
+ return null;
47
+ }
48
+
49
+ /**
50
+ * Save cc_native state to context state.json.
51
+ * Returns true on success, false on failure.
52
+ */
53
+ export function saveCcNativeState(
54
+ sessionId: string,
55
+ projectRoot: string,
56
+ ccNativeData: CcNativeState,
57
+ ): boolean {
58
+ try {
59
+ const state = getContextBySessionId(sessionId, projectRoot) as CcNativeContextState | null;
60
+ if (state) {
61
+ state.cc_native = ccNativeData;
62
+ saveState(state.id, state, projectRoot);
63
+ return true;
64
+ }
65
+ } catch (error: unknown) {
66
+ logWarn("utils", `Failed to save cc_native state: ${error}`);
67
+ }
68
+
69
+ return false;
70
+ }
71
+
72
+ // ---------------------------------------------------------------------------
73
+ // Plan Review State
74
+ // ---------------------------------------------------------------------------
75
+
76
+ /**
77
+ * Check if this exact plan has already been reviewed in this session.
78
+ */
79
+ export function isPlanAlreadyReviewed(
80
+ sessionId: string,
81
+ planHash: string,
82
+ projectRoot: string,
83
+ ): boolean {
84
+ const ccNative = getCcNativeState(sessionId, projectRoot);
85
+ if (!ccNative) return false;
86
+ const reviewState = ccNative.plan_review;
87
+ return reviewState?.plan_hash === planHash;
88
+ }
89
+
90
+ /**
91
+ * Check if this plan hash was previously reviewed and denied.
92
+ * Matches any deny variant: "deny", "hook_deny_iteration", "hook_deny_final".
93
+ */
94
+ export function wasPlanPreviouslyDenied(
95
+ sessionId: string,
96
+ planHash: string,
97
+ projectRoot: string,
98
+ ): boolean {
99
+ const ccNative = getCcNativeState(sessionId, projectRoot);
100
+ if (!ccNative) return false;
101
+ const reviewState = ccNative.plan_review;
102
+ if (reviewState?.plan_hash !== planHash) return false;
103
+ const decision = reviewState.decision ?? "";
104
+ return decision === "deny" || decision.startsWith("hook_deny");
105
+ }
106
+
107
+ /**
108
+ * Mark this plan as reviewed (stores hash and decision in state.json).
109
+ */
110
+ export function markPlanReviewed(
111
+ sessionId: string,
112
+ planHash: string,
113
+ projectRoot: string,
114
+ hookName = "cc-native",
115
+ iterationState?: IterationState,
116
+ decision = "allow",
117
+ ): void {
118
+ try {
119
+ const ccNative = getCcNativeState(sessionId, projectRoot) ?? {};
120
+
121
+ const reviewData: PlanReviewState = {
122
+ plan_hash: planHash,
123
+ reviewed_at: nowIso(),
124
+ decision,
125
+ };
126
+
127
+ if (iterationState) {
128
+ reviewData.iteration = {
129
+ current: iterationState.current ?? 1,
130
+ max: iterationState.max ?? 1,
131
+ complexity: iterationState.complexity ?? "unknown",
132
+ };
133
+ const {history} = iterationState;
134
+ if (history && history.length > 0) {
135
+ const lastEntry = history.at(-1);
136
+ if (lastEntry) {
137
+ reviewData.iteration.latest_verdict = lastEntry.verdict ?? "unknown";
138
+ }
139
+ }
140
+ }
141
+
142
+ ccNative.plan_review = reviewData;
143
+
144
+ if (saveCcNativeState(sessionId, projectRoot, ccNative)) {
145
+ const iterInfo = iterationState
146
+ ? ` (iteration ${reviewData.iteration?.current ?? "?"}/${reviewData.iteration?.max ?? "?"})`
147
+ : "";
148
+ logInfo(hookName, `Saved plan review state (hash: ${planHash})${iterInfo}`);
149
+ } else {
150
+ logWarn(
151
+ hookName,
152
+ `Failed to save plan review state for session ${sessionId}`,
153
+ );
154
+ }
155
+ } catch (error: unknown) {
156
+ logWarn(hookName, `Failed to mark plan reviewed: ${error}`);
157
+ }
158
+ }
159
+
160
+ // ---------------------------------------------------------------------------
161
+ // Questions Asked State
162
+ // ---------------------------------------------------------------------------
163
+
164
+ /**
165
+ * Check if AskUserQuestion was called this session.
166
+ * Returns false on any error (fail-safe: allow feature to work).
167
+ */
168
+ export function wasQuestionsAsked(
169
+ sessionId: string,
170
+ projectRoot: string,
171
+ ): boolean {
172
+ const ccNative = getCcNativeState(sessionId, projectRoot);
173
+ if (!ccNative) return false;
174
+ return ccNative.questions_asked?.asked === true;
175
+ }
176
+
177
+ /**
178
+ * Mark that AskUserQuestion was called. Returns true on success.
179
+ * Only stores timestamp, no user data.
180
+ */
181
+ export function markQuestionsAsked(
182
+ sessionId: string,
183
+ projectRoot: string,
184
+ ): boolean {
185
+ try {
186
+ const ccNative = getCcNativeState(sessionId, projectRoot) ?? {};
187
+
188
+ ccNative.questions_asked = {
189
+ asked: true,
190
+ asked_at: nowIso(),
191
+ };
192
+
193
+ return saveCcNativeState(sessionId, projectRoot, ccNative);
194
+ } catch (error: unknown) {
195
+ logWarn("utils", `Failed to mark questions asked: ${error}`);
196
+ return false;
197
+ }
198
+ }
199
+
@@ -0,0 +1,124 @@
1
+ /**
2
+ * Unified Claude CLI output parser.
3
+ * Deduplicates identical logic from orchestrator.py and reviewers/agent.py.
4
+ * See cc-native-plan-review-spec.md §4.6
5
+ */
6
+
7
+ import { parseJsonMaybe } from "./json-parser.js";
8
+ import { logDebug, logError, logWarn } from "../../_shared/lib-ts/base/logger.js";
9
+
10
+ /**
11
+ * Parse Claude CLI JSON output, handling various formats.
12
+ *
13
+ * Claude CLI can output in several formats:
14
+ * - Direct structured_output dict
15
+ * - Assistant message with StructuredOutput tool use
16
+ * - List of events with assistant messages
17
+ * - Raw text with embedded JSON (heuristic fallback)
18
+ *
19
+ * @param raw - Raw stdout from Claude CLI
20
+ * @param requireFields - Optional fields to validate in heuristic fallback
21
+ * @returns Parsed JSON dict or null if parsing failed
22
+ */
23
+ export function parseCliOutput(
24
+ raw: string,
25
+ requireFields?: string[],
26
+ ): null | Record<string, unknown> {
27
+ try {
28
+ const result: unknown = JSON.parse(raw);
29
+
30
+ if (result !== null && typeof result === "object" && !Array.isArray(result)) {
31
+ const dict = result as Record<string, unknown>;
32
+
33
+ // Strategy 1: Direct structured_output key
34
+ if ("structured_output" in dict) {
35
+ logDebug("cli_parser", "Found structured_output in root dict");
36
+ return dict.structured_output as Record<string, unknown>;
37
+ }
38
+
39
+ // Strategy 2: Assistant message with StructuredOutput tool use
40
+ if (dict.type === "assistant") {
41
+ const message = dict.message as Record<string, unknown> | undefined;
42
+ const content = message?.content;
43
+ if (Array.isArray(content)) {
44
+ for (const item of content) {
45
+ if (
46
+ item !== null &&
47
+ typeof item === "object" &&
48
+ (item as Record<string, unknown>).name === "StructuredOutput"
49
+ ) {
50
+ logDebug(
51
+ "cli_parser",
52
+ "Found StructuredOutput in assistant message content",
53
+ );
54
+ return (item as Record<string, unknown>).input as Record<
55
+ string,
56
+ unknown
57
+ >;
58
+ }
59
+ }
60
+ }
61
+
62
+ logDebug(
63
+ "cli_parser",
64
+ "Assistant message found but no StructuredOutput tool use in content",
65
+ );
66
+ }
67
+ } else if (Array.isArray(result)) {
68
+ // Strategy 3: List of events with assistant messages
69
+ logDebug(
70
+ "cli_parser",
71
+ `Received list of ${(result as unknown[]).length} events, searching for assistant message`,
72
+ );
73
+ for (let i = 0; i < (result as unknown[]).length; i++) {
74
+ const event = (result as unknown[])[i];
75
+ if (event === null || typeof event !== "object") continue;
76
+
77
+ const dict = event as Record<string, unknown>;
78
+ if (dict.type === "assistant") {
79
+ const message = dict.message as Record<string, unknown> | undefined;
80
+ const content = message?.content;
81
+ if (Array.isArray(content)) {
82
+ for (const item of content) {
83
+ if (
84
+ item !== null &&
85
+ typeof item === "object" &&
86
+ (item as Record<string, unknown>).name === "StructuredOutput"
87
+ ) {
88
+ logDebug(
89
+ "cli_parser",
90
+ `Found StructuredOutput in event[${i}] assistant message`,
91
+ );
92
+ return (item as Record<string, unknown>).input as Record<
93
+ string,
94
+ unknown
95
+ >;
96
+ }
97
+ }
98
+ }
99
+ }
100
+ }
101
+
102
+ logDebug(
103
+ "cli_parser",
104
+ "No StructuredOutput found in any assistant message in event list",
105
+ );
106
+ }
107
+ } catch (error: unknown) {
108
+ if (error instanceof SyntaxError) {
109
+ logWarn("cli_parser", `JSON decode error: ${error.message}`);
110
+ } else {
111
+ logError(
112
+ "cli_parser",
113
+ `Unexpected error during structured parsing: ${error}`,
114
+ );
115
+ }
116
+ }
117
+
118
+ // Strategy 4: Heuristic {…} extraction fallback
119
+ logDebug(
120
+ "cli_parser",
121
+ "No structured output found, falling back to heuristic JSON extraction",
122
+ );
123
+ return parseJsonMaybe(raw, requireFields);
124
+ }
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Configuration loading for cc-native plan review.
3
+ * See cc-native-plan-review-spec.md §4.4
4
+ */
5
+
6
+ import * as fs from "node:fs";
7
+ import * as path from "node:path";
8
+
9
+ import type { DisplaySettings, PlanReviewConfig } from "./types.js";
10
+ import { DEFAULT_DISPLAY } from "./types.js";
11
+ import { logWarn } from "../../_shared/lib-ts/base/logger.js";
12
+
13
+ /**
14
+ * Load full CC-Native config from _cc-native/plan-review.config.json.
15
+ */
16
+ export function loadConfig(projectDir: string): PlanReviewConfig {
17
+ const settingsPath = path.join(
18
+ projectDir,
19
+ "_cc-native",
20
+ "plan-review.config.json",
21
+ );
22
+
23
+ if (!fs.existsSync(settingsPath)) {
24
+ return {};
25
+ }
26
+
27
+ try {
28
+ const raw = fs.readFileSync(settingsPath, "utf8");
29
+ return JSON.parse(raw) as PlanReviewConfig;
30
+ } catch (error: unknown) {
31
+ logWarn("cc-native", `Failed to load config: ${error}`);
32
+ return {};
33
+ }
34
+ }
35
+
36
+ /**
37
+ * Get display settings, checking section-specific first, then root.
38
+ */
39
+ export function getDisplaySettings(
40
+ config: PlanReviewConfig,
41
+ section: string,
42
+ ): DisplaySettings {
43
+ const sectionConfig = config[section];
44
+ const sectionDisplay =
45
+ sectionConfig && typeof sectionConfig === "object"
46
+ ? ((sectionConfig as Record<string, unknown>).display as
47
+ | Partial<DisplaySettings>
48
+ | undefined) ?? {}
49
+ : {};
50
+ const rootDisplay = config.display ?? {};
51
+
52
+ return {
53
+ ...DEFAULT_DISPLAY,
54
+ ...rootDisplay,
55
+ ...sectionDisplay,
56
+ };
57
+ }
@@ -0,0 +1,83 @@
1
+ /**
2
+ * Security and configuration constants for cc-native plan review.
3
+ * See cc-native-plan-review-spec.md §4.15
4
+ */
5
+
6
+ import * as os from "node:os";
7
+ import * as path from "node:path";
8
+
9
+ // ---------------------------------------------------------------------------
10
+ // Feature Flags
11
+ // ---------------------------------------------------------------------------
12
+
13
+ /** Enable atomic writes for plan state files (env: CC_NATIVE_ROBUST_WRITES) */
14
+ export const ENABLE_ROBUST_PLAN_WRITES =
15
+ (process.env.CC_NATIVE_ROBUST_WRITES ?? "true").toLowerCase() === "true";
16
+
17
+ /** Enable plan review notifications (env: CC_NATIVE_NOTIFICATIONS) */
18
+ export const ENABLE_PLAN_NOTIFICATIONS =
19
+ (process.env.CC_NATIVE_NOTIFICATIONS ?? "false").toLowerCase() === "true";
20
+
21
+ // ---------------------------------------------------------------------------
22
+ // Security Constants
23
+ // ---------------------------------------------------------------------------
24
+
25
+ /** Default plans directory */
26
+ export const PLANS_DIR = path.join(os.homedir(), ".claude", "plans");
27
+
28
+ /** Maximum plan path length */
29
+ export const MAX_PLAN_PATH_LENGTH = 4096;
30
+
31
+ /** Maximum error file size (10KB) */
32
+ export const MAX_ERROR_FILE_SIZE = 10 * 1024;
33
+
34
+ // ---------------------------------------------------------------------------
35
+ // Performance Constants
36
+ // ---------------------------------------------------------------------------
37
+
38
+ /** Fast-fail: 2 attempts max */
39
+ export const MAX_RETRY_ATTEMPTS = 2;
40
+
41
+ /** Backoff schedule: 0.5s, 1s */
42
+ export const RETRY_BACKOFF_MS = [500, 1000];
43
+
44
+ /** 3 seconds total, well under 5s hook timeout */
45
+ export const MAX_TOTAL_RETRY_TIME_MS = 3000;
46
+
47
+ // ---------------------------------------------------------------------------
48
+ // Path Validation
49
+ // ---------------------------------------------------------------------------
50
+
51
+ /**
52
+ * Validate and sanitize plan path to prevent traversal attacks.
53
+ * Throws ValueError if path is invalid, too long, or outside allowed directory.
54
+ */
55
+ export function validatePlanPath(planPath: string): string {
56
+ // Input validation
57
+ if (!planPath || planPath.length > MAX_PLAN_PATH_LENGTH) {
58
+ throw new Error(
59
+ `Invalid plan path length: ${planPath ? planPath.length : 0}`,
60
+ );
61
+ }
62
+
63
+ if (planPath.includes("\u0000")) {
64
+ throw new Error("Null bytes not allowed in path");
65
+ }
66
+
67
+ // Normalize and resolve to absolute canonical path
68
+ let resolved: string;
69
+ try {
70
+ resolved = path.resolve(planPath);
71
+ } catch (error: unknown) {
72
+ throw new Error(`Path resolution failed: ${error}`);
73
+ }
74
+
75
+ // Verify path is within allowed directory (case-insensitive on Windows)
76
+ const resolvedLower = resolved.toLowerCase().replaceAll('\\', "/");
77
+ const plansDirLower = PLANS_DIR.toLowerCase().replaceAll('\\', "/");
78
+ if (!resolvedLower.startsWith(plansDirLower)) {
79
+ throw new Error(`Path outside allowed directory: ${PLANS_DIR}`);
80
+ }
81
+
82
+ return resolved;
83
+ }
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Per-context debug logging for cc-native hooks.
3
+ * Thin delegation layer over the unified logger.
4
+ * See cc-native-plan-review-spec.md §4.13
5
+ *
6
+ * Can be disabled via CCNATIVE_DEBUG_DISABLE=1 environment variable.
7
+ */
8
+
9
+ import * as fs from "node:fs";
10
+ import * as path from "node:path";
11
+
12
+ import { hookLog } from "../../_shared/lib-ts/base/logger.js";
13
+
14
+ /** Feature flag — set CCNATIVE_DEBUG_DISABLE=1 to turn off */
15
+ const DEBUG_ENABLED = !["1", "true", "yes"].includes(
16
+ (process.env.CCNATIVE_DEBUG_DISABLE ?? "").toLowerCase(),
17
+ );
18
+
19
+ /**
20
+ * Get or create debug directory within context folder.
21
+ */
22
+ export function getDebugDir(contextPath: string): string {
23
+ const debugDir = path.join(contextPath, "debug");
24
+ fs.mkdirSync(debugDir, { recursive: true });
25
+ return debugDir;
26
+ }
27
+
28
+ /**
29
+ * Write a debug log entry. Delegates to unified logger.
30
+ */
31
+ export function debugLog(
32
+ contextPath: string,
33
+ sessionName: string,
34
+ component: string,
35
+ message: string,
36
+ data?: unknown,
37
+ ): void {
38
+ if (!DEBUG_ENABLED) return;
39
+
40
+ hookLog("debug", sessionName, message, {
41
+ component,
42
+ data,
43
+ });
44
+ }
45
+
46
+ /**
47
+ * Log raw output (stdout, stderr, etc). Delegates to unified logger.
48
+ */
49
+ export function debugRaw(
50
+ contextPath: string,
51
+ sessionName: string,
52
+ component: string,
53
+ label: string,
54
+ raw: string,
55
+ maxLen = 10_000,
56
+ ): void {
57
+ if (!DEBUG_ENABLED) return;
58
+
59
+ const truncated = raw.length > maxLen ? raw.slice(0, maxLen) : raw;
60
+ const suffix =
61
+ raw.length > maxLen ? ` [TRUNCATED from ${raw.length} chars]` : "";
62
+
63
+ hookLog("debug", sessionName, `${label}${suffix}: ${truncated}`, {
64
+ component,
65
+ });
66
+ }
67
+
68
+ /**
69
+ * Remove debug folder during context archive.
70
+ */
71
+ export function cleanupDebugFolder(contextPath: string): void {
72
+ try {
73
+ const debugDir = path.join(contextPath, "debug");
74
+ if (fs.existsSync(debugDir)) {
75
+ fs.rmSync(debugDir, { recursive: true, force: true });
76
+ }
77
+ } catch {
78
+ // Best effort cleanup
79
+ }
80
+ }
@@ -0,0 +1,119 @@
1
+ /**
2
+ * CC-Native plan review library — package entry point.
3
+ * Re-exports the public API from all modules.
4
+ */
5
+
6
+ // Agent aggregation
7
+ export {
8
+ aggregateAgents,
9
+ extractBody,
10
+ extractFrontmatter,
11
+ } from "./aggregate-agents.js";
12
+
13
+ // Artifacts
14
+ export {
15
+ buildCombinedJson,
16
+ buildHighIssuesDocument,
17
+ buildInlineReviewSummary,
18
+ extractTopIssuesText,
19
+ formatCombinedMarkdown,
20
+ formatReviewMarkdown,
21
+ generateReviewIndex,
22
+ writeCombinedArtifacts,
23
+ } from "./artifacts.js";
24
+
25
+ // CC-native state
26
+ export {
27
+ getCcNativeState,
28
+ isPlanAlreadyReviewed,
29
+ markPlanReviewed,
30
+ markQuestionsAsked,
31
+ saveCcNativeState,
32
+ wasPlanPreviouslyDenied,
33
+ wasQuestionsAsked,
34
+ } from "./cc-native-state.js";
35
+
36
+ // CLI output parsing
37
+ export { parseCliOutput } from "./cli-output-parser.js";
38
+
39
+ // Configuration
40
+ export { getDisplaySettings, loadConfig } from "./config.js";
41
+
42
+ // Constants & security
43
+ export {
44
+ ENABLE_PLAN_NOTIFICATIONS,
45
+ ENABLE_ROBUST_PLAN_WRITES,
46
+ MAX_ERROR_FILE_SIZE,
47
+ MAX_PLAN_PATH_LENGTH,
48
+ MAX_RETRY_ATTEMPTS,
49
+ MAX_TOTAL_RETRY_TIME_MS,
50
+ PLANS_DIR,
51
+ RETRY_BACKOFF_MS,
52
+ validatePlanPath,
53
+ } from "./constants.js";
54
+
55
+ // Debug logging
56
+ export { cleanupDebugFolder, debugLog, debugRaw, getDebugDir } from "./debug.js";
57
+
58
+ // JSON parsing
59
+ export { coerceToReview, parseJsonMaybe } from "./json-parser.js";
60
+
61
+ // Orchestrator
62
+ export { buildOrchestratorSchema, runOrchestrator } from "./orchestrator.js";
63
+
64
+ // Reviewers
65
+ export {
66
+ AgentReviewer,
67
+ CodexReviewer,
68
+ GeminiReviewer,
69
+ runAgentReview,
70
+ runCodexReview,
71
+ runGeminiReview,
72
+ } from "./reviewers/index.js";
73
+
74
+ // Iteration state
75
+ export {
76
+ deleteState,
77
+ getIterationState,
78
+ getStateFilePath,
79
+ loadState,
80
+ saveStateToPlan,
81
+ shouldContinueIterating,
82
+ updateIterationState,
83
+ } from "./state.js";
84
+
85
+ // Types & schemas
86
+ export type {
87
+ AgentConfig,
88
+ CcNativeState,
89
+ CombinedReviewResult,
90
+ ComplexityCategory,
91
+ DisplaySettings,
92
+ IterationEntry,
93
+ IterationState,
94
+ OrchestratorConfig,
95
+ OrchestratorResult,
96
+ PlanReviewConfig,
97
+ PlanReviewState,
98
+ QuestionsAskedState,
99
+ ReviewData,
100
+ ReviewDecision,
101
+ ReviewDecisionResult,
102
+ Reviewer,
103
+ ReviewerResult,
104
+ ReviewIssue,
105
+ ReviewOptions,
106
+ Verdict,
107
+ } from "./types.js";
108
+
109
+ export {
110
+ AGENT_REVIEW_PROMPT_PREFIX,
111
+ DEFAULT_DISPLAY,
112
+ DEFAULT_SANITIZATION,
113
+ ORCHESTRATOR_SCHEMA,
114
+ REVIEW_PROMPT_PREFIX,
115
+ REVIEW_SCHEMA,
116
+ } from "./types.js";
117
+
118
+ // Verdict aggregation
119
+ export { computeReviewDecision, worstVerdict } from "./verdict.js";