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,250 @@
1
+ /**
2
+ * Unified logging for all hooks and libraries.
3
+ *
4
+ * Log format: JSONL (one JSON object per line)
5
+ * Log location: _output/hook-log.jsonl (global, all sessions)
6
+ * Filter by session using the "sid" field.
7
+ *
8
+ * stderr is OPT-IN: convenience functions (logDebug, logInfo, logWarn, logError)
9
+ * write to file only by default. To also write to stderr (visible to Claude Code
10
+ * as "hook error"), pass { stderr: true } or use logBlocking().
11
+ * logHookError() always writes to stderr (unhandled errors must be visible).
12
+ *
13
+ * Environment variables:
14
+ * - HOOK_LOG_DISABLE=1: Disable all file logging
15
+ * - HOOK_LOG_LEVEL=warn: Minimum level to log (default: debug)
16
+ * - HOOK_ERROR_LOG_DISABLE=1: Legacy alias for HOOK_LOG_DISABLE
17
+ *
18
+ * Never throws. No buffering. Stdlib only.
19
+ * See SPEC.md §3
20
+ */
21
+
22
+ import * as fs from "node:fs";
23
+ import * as path from "node:path";
24
+
25
+ const LEVELS: Record<string, number> = {
26
+ debug: 0,
27
+ info: 1,
28
+ warn: 2,
29
+ error: 3,
30
+ };
31
+
32
+ const MAX_LOG_LINES = 10_000; // Max lines in global log before pruning
33
+
34
+ // Module-level session ID cache
35
+ let _cachedSessionId: null | string = null;
36
+
37
+ // Module-level context path cache (kept for external callers)
38
+ let _cachedContextPath: null | string = null;
39
+ let _contextResolved = false;
40
+
41
+ /**
42
+ * Set the session ID for this process. All subsequent log calls include it.
43
+ */
44
+ export function setSessionId(sessionId: null | string): void {
45
+ _cachedSessionId = sessionId;
46
+ }
47
+
48
+ /**
49
+ * Set the context path for this process. Kept for external callers.
50
+ */
51
+ export function setContextPath(contextPath: null | string): void {
52
+ _cachedContextPath = contextPath;
53
+ _contextResolved = true;
54
+ }
55
+
56
+ export function getContextPath(): null | string {
57
+ if (!_contextResolved) {
58
+ _contextResolved = true; // Don't retry
59
+ }
60
+
61
+ return _cachedContextPath;
62
+ }
63
+
64
+ function getMinLevel(): number {
65
+ const env = (process.env.HOOK_LOG_LEVEL ?? "debug").toLowerCase();
66
+ return LEVELS[env] ?? 0;
67
+ }
68
+
69
+ function isDisabled(): boolean {
70
+ return (
71
+ process.env.HOOK_LOG_DISABLE === "1" ||
72
+ process.env.HOOK_ERROR_LOG_DISABLE === "1" ||
73
+ process.env.CCNATIVE_DEBUG_DISABLE === "1"
74
+ );
75
+ }
76
+
77
+ function getProjectRoot(): string {
78
+ return process.env.CLAUDE_PROJECT_DIR || process.cwd();
79
+ }
80
+
81
+ /**
82
+ * Write a structured log entry to the global hook log.
83
+ *
84
+ * All entries go to _output/hook-log.jsonl. Use the "sid" field
85
+ * (set via setSessionId) to filter by session.
86
+ */
87
+ export function hookLog(
88
+ level: string,
89
+ hookName: string,
90
+ message: string,
91
+ opts?: {
92
+ component?: string;
93
+ data?: any;
94
+ stderr?: boolean;
95
+ traceback_str?: string;
96
+ },
97
+ ): void {
98
+ try {
99
+ const levelLower = level.toLowerCase();
100
+ const levelNum = LEVELS[levelLower] ?? 0;
101
+ const component = opts?.component ?? "";
102
+ const tracebackStr = opts?.traceback_str ?? "";
103
+ const stderrEnabled = opts?.stderr === true;
104
+
105
+ // Write to stderr
106
+ if (stderrEnabled) {
107
+ const prefix = component
108
+ ? `[${hookName}:${component}]`
109
+ : `[${hookName}]`;
110
+ process.stderr.write(`${prefix} ${message}\n`);
111
+ if (tracebackStr) {
112
+ process.stderr.write(tracebackStr + "\n");
113
+ }
114
+ }
115
+
116
+ // Check if file logging is enabled
117
+ if (isDisabled()) return;
118
+
119
+ // Check minimum level
120
+ if (levelNum < getMinLevel()) return;
121
+
122
+ // Build JSONL entry
123
+ const now = new Date();
124
+ const ts = now.toISOString().replace("Z", "").slice(0, 23);
125
+ const entry: Record<string, any> = {
126
+ ts,
127
+ level: levelLower,
128
+ hook: hookName,
129
+ msg: message,
130
+ };
131
+ if (_cachedSessionId) entry.sid = _cachedSessionId;
132
+ if (component) entry.component = component;
133
+ if (opts?.data !== undefined && opts.data !== null) {
134
+ try {
135
+ JSON.stringify(opts.data);
136
+ entry.data = opts.data;
137
+ } catch {
138
+ entry.data = String(opts.data);
139
+ }
140
+ }
141
+
142
+ if (tracebackStr) entry.tb = tracebackStr.trimEnd();
143
+
144
+ const line = JSON.stringify(entry) + "\n";
145
+
146
+ // Always write to global log
147
+ const logPath = path.join(getProjectRoot(), "_output", "hook-log.jsonl");
148
+
149
+ // Ensure directory exists
150
+ const dir = path.dirname(logPath);
151
+ fs.mkdirSync(dir, { recursive: true });
152
+
153
+ // Line-count guard: prune to last MAX_LOG_LINES
154
+ try {
155
+ if (fs.existsSync(logPath)) {
156
+ const content = fs.readFileSync(logPath, "utf8");
157
+ const lines = content.split("\n");
158
+ if (lines.length > MAX_LOG_LINES) {
159
+ fs.writeFileSync(
160
+ logPath,
161
+ lines.slice(lines.length - MAX_LOG_LINES).join("\n"),
162
+ "utf-8",
163
+ );
164
+ }
165
+ }
166
+ } catch {
167
+ // ignore
168
+ }
169
+
170
+ fs.appendFileSync(logPath, line, "utf-8");
171
+ } catch {
172
+ // Never crash
173
+ }
174
+ }
175
+
176
+ export function logDebug(hookName: string, message: string, opts?: Record<string, any>): void {
177
+ hookLog("debug", hookName, message, opts);
178
+ }
179
+
180
+ export function logInfo(hookName: string, message: string, opts?: Record<string, any>): void {
181
+ hookLog("info", hookName, message, opts);
182
+ }
183
+
184
+ export function logWarn(hookName: string, message: string, opts?: Record<string, any>): void {
185
+ hookLog("warn", hookName, message, opts);
186
+ }
187
+
188
+ export function logError(hookName: string, message: string, opts?: Record<string, any>): void {
189
+ hookLog("error", hookName, message, opts);
190
+ }
191
+
192
+ /**
193
+ * Log an error that SHOULD be visible to user/model via stderr.
194
+ * Use for real problems needing attention, not routine diagnostics.
195
+ */
196
+ export function logBlocking(hookName: string, message: string, opts?: Record<string, any>): void {
197
+ hookLog("error", hookName, message, { ...opts, stderr: true });
198
+ }
199
+
200
+ /**
201
+ * Log a structured diagnostic entry at a hook decision point.
202
+ * See SPEC.md §3.8
203
+ */
204
+ export function logDiagnostic(
205
+ hookName: string,
206
+ phase: string,
207
+ summary: string,
208
+ opts?: {
209
+ component?: string;
210
+ data?: any;
211
+ decision?: any;
212
+ inputs?: any;
213
+ reasoning?: any;
214
+ },
215
+ ): void {
216
+ const diagData: Record<string, any> = { phase };
217
+ if (opts?.inputs !== undefined) diagData.inputs = opts.inputs;
218
+ if (opts?.decision !== undefined) diagData.decision = opts.decision;
219
+ if (opts?.reasoning !== undefined) diagData.reasoning = opts.reasoning;
220
+ if (opts?.data && typeof opts.data === "object") {
221
+ Object.assign(diagData, opts.data);
222
+ }
223
+
224
+ hookLog("debug", hookName, `[DIAG:${phase}] ${summary}`, {
225
+ component: opts?.component ?? "diag",
226
+ data: diagData,
227
+ });
228
+ }
229
+
230
+ /**
231
+ * Backward-compatible wrapper matching old hook_utils.log_hook_error signature.
232
+ * See SPEC.md §3.6
233
+ */
234
+ export function logHookError(
235
+ hookName: string,
236
+ error: Error | string,
237
+ hookEvent = "unknown",
238
+ tracebackStr = "",
239
+ ): void {
240
+ const errStr = typeof error === "string" ? error : String(error);
241
+ const msg = errStr.replaceAll(/[\n\r]/g, " ").slice(0, 200);
242
+ const errType =
243
+ typeof error === "object" && error !== null
244
+ ? error.constructor.name
245
+ : "Error";
246
+ hookLog("error", hookName, `[${hookEvent}] ${errType}: ${msg}`, {
247
+ traceback_str: tracebackStr,
248
+ stderr: true,
249
+ });
250
+ }
@@ -0,0 +1,116 @@
1
+ /**
2
+ * Shared I/O for state.json — read, write, serialize.
3
+ * Extracted to avoid circular deps between context-store and task-tracker.
4
+ * See SPEC.md §7.1
5
+ */
6
+
7
+ import * as fs from "node:fs";
8
+ import * as path from "node:path";
9
+
10
+ import { atomicWrite } from "./atomic-write.js";
11
+ import { getContextDir } from "./constants.js";
12
+ import { logWarn } from "./logger.js";
13
+ import type { ContextState, Mode } from "../types.js";
14
+
15
+ /** Mode migration from legacy context_manager values. */
16
+ const MODE_MIGRATION: Record<string, Mode> = {
17
+ none: "idle",
18
+ planning: "idle",
19
+ pending_implementation: "has_plan",
20
+ implementing: "active",
21
+ };
22
+
23
+ /**
24
+ * Serialize a ContextState for JSON output.
25
+ * Omits null/undefined keys but keeps false, 0, empty string, and empty arrays.
26
+ */
27
+ export function toDict(state: ContextState): Record<string, unknown> {
28
+ const result: Record<string, unknown> = {};
29
+ for (const [key, value] of Object.entries(state)) {
30
+ if (value !== null && value !== undefined) {
31
+ result[key] = value;
32
+ }
33
+ }
34
+
35
+ return result;
36
+ }
37
+
38
+ /**
39
+ * Get path to state.json for a context.
40
+ */
41
+ export function statePath(contextId: string, projectRoot?: string): string {
42
+ return path.join(getContextDir(contextId, projectRoot), "state.json");
43
+ }
44
+
45
+ /**
46
+ * Read and parse state.json for a context.
47
+ * Applies legacy mode migration. Returns null if file doesn't exist or is corrupt.
48
+ */
49
+ export function readStateJson(
50
+ contextId: string,
51
+ projectRoot?: string,
52
+ ): ContextState | null {
53
+ const sp = statePath(contextId, projectRoot);
54
+ if (!fs.existsSync(sp)) return null;
55
+
56
+ try {
57
+ const raw = fs.readFileSync(sp, "utf8");
58
+ const data = JSON.parse(raw) as Record<string, any>;
59
+ return dictToState(data);
60
+ } catch (error: any) {
61
+ logWarn("state_io", `Failed to read state.json for '${contextId}': ${error}`);
62
+ return null;
63
+ }
64
+ }
65
+
66
+ /**
67
+ * Atomically write state.json for a context.
68
+ * Returns [success, error].
69
+ */
70
+ export function writeStateJson(
71
+ contextId: string,
72
+ state: ContextState,
73
+ projectRoot?: string,
74
+ ): [boolean, null | string] {
75
+ const sp = statePath(contextId, projectRoot);
76
+ const dir = path.dirname(sp);
77
+ fs.mkdirSync(dir, { recursive: true });
78
+
79
+ const content = JSON.stringify(toDict(state), null, 2);
80
+ return atomicWrite(sp, content);
81
+ }
82
+
83
+ /**
84
+ * Construct a ContextState from a dict, migrating old mode names.
85
+ * Only includes fields that are present in the source data (preserves null-stripping).
86
+ */
87
+ export function dictToState(data: Record<string, any>): ContextState {
88
+ const rawMode: string = data.mode ?? "idle";
89
+ const mode: Mode = (MODE_MIGRATION[rawMode] ?? rawMode) as Mode;
90
+
91
+ const state: any = {
92
+ id: data.id,
93
+ status: data.status ?? "active",
94
+ summary: data.summary ?? "",
95
+ method: data.method ?? "",
96
+ tags: data.tags ?? [],
97
+ created_at: data.created_at ?? "",
98
+ last_active: data.last_active ?? "",
99
+ mode,
100
+ plan_anchors: data.plan_anchors ?? [],
101
+ plan_consumed: data.plan_consumed ?? false,
102
+ handoff_consumed: data.handoff_consumed ?? false,
103
+ session_ids: data.session_ids ?? [],
104
+ tasks: data.tasks ?? [],
105
+ };
106
+
107
+ // Only set nullable fields if they exist in the source data
108
+ if ("plan_path" in data) state.plan_path = data.plan_path;
109
+ if ("plan_hash" in data) state.plan_hash = data.plan_hash;
110
+ if ("plan_signature" in data) state.plan_signature = data.plan_signature;
111
+ if ("plan_id" in data) state.plan_id = data.plan_id;
112
+ if ("handoff_path" in data) state.handoff_path = data.handoff_path;
113
+ if ("last_session" in data) state.last_session = data.last_session;
114
+
115
+ return state as ContextState;
116
+ }
@@ -0,0 +1,184 @@
1
+ /**
2
+ * Stop words for context ID generation.
3
+ *
4
+ * Generated from analysis of 1,424 prompts, context summaries, and plan files.
5
+ * Words that appear frequently but don't help identify the specific task.
6
+ *
7
+ * ACTION VERBS ARE INTENTIONALLY EXCLUDED:
8
+ * add, fix, update, create, implement, refactor, migrate, debug, remove, change,
9
+ * move, rename, delete, build, test, deploy, verify, analyze, modify, write, run,
10
+ * check, replace, save, sync, load, extract, install, clean, merge, etc.
11
+ *
12
+ * See SPEC.md §14.1
13
+ */
14
+
15
+ export const STOP_WORDS: ReadonlySet<string> = new Set([
16
+ // ARTICLES
17
+ "a", "about", "above",
18
+
19
+ "absolutely", "accordingly", "across", "active", "actually", "after", "afterwards", "against", "ago", "ah",
20
+ "aiw", "all", "allow", "almost", "along", "already", "alright", "also",
21
+ "alternatively", "although", "always", // AUXILIARY/MODAL VERBS
22
+ "am", "among", "an", // CONJUNCTIONS
23
+ "and", "another",
24
+ "any", "anybody", "anyone", "anything", "anyway", "anyways", "apparently", "appear",
25
+ "are", "aren", "arent", "args", "around", "as", "ask",
26
+ "assert", "async", "at", // SINGLE LETTERS
27
+ "b",
28
+
29
+ "based", "basic", "basically", "bat", "be", "because", "become",
30
+ "been", "before", "begin", "behind", "being",
31
+ "below", "below", "beside", "besides", "between", "beyond", "block",
32
+
33
+ "both", "but", "by", "c", "can", "cant", "case",
34
+ "cases", "cause", "cc", "certainly", "chunk",
35
+
36
+ "clarification", "class", "clearly", "come",
37
+
38
+ "complete", "completely", "consequently", "consider",
39
+
40
+ "const", "contain", "contains", "continue", "conversely", "correct",
41
+ "correctly", "could", "couldn", "couldnt", "critical", "current",
42
+ "currently", "d",
43
+
44
+ "def", "definitely", "dict", "did", "didn", "didnt", "different", "directory",
45
+ "do", "does", "doesn", "doesn",
46
+ "doesnt", "doing", "don", "done", "dont",
47
+ "down", "during", "e", "each", "eh", "eight", "either", "elif", "else",
48
+
49
+ "empty", "end", "enough", "entirely", "eprint", "er",
50
+ "essentially", // SHORT NOISE
51
+ "etc", "eventually", "every", "everybody", "everyone", "everything",
52
+ "exactly", "example", "examples", "except", "exe",
53
+
54
+ "existing", "expect", "expected", "f", "false",
55
+
56
+ "feature", "features", "feel", "few", "finally", "find", "first",
57
+ "five", "folder", "follow", "following", "footer", "for", "format",
58
+ "four", "from", "full", "furthermore", "g",
59
+ "general", "get", "getting", "give",
60
+
61
+ // COMMON NON-ACTION VERBS
62
+ "go", "going", "gonna", "gotta",
63
+ "group", "h", "had", "hadn", "hadnt", "has", "hasn",
64
+ "hasnt", "have", "haven", "havent", "having", "he", "header",
65
+
66
+ "hello", "help", "hence", "her", "her", // ADVERBS OF PLACE/TIME
67
+ "here", "heres", "hers", "herself",
68
+ "hes", "hey", "hi", // GENERIC ADJECTIVES
69
+ "high", "him", "himself", "his", "hm",
70
+ "hmm", "how",
71
+
72
+ // LINKING/TRANSITION WORDS
73
+ "however", "huh", // PRONOUNS - Personal
74
+ "i", "id", "if", "ill", // CONTRACTED FORMS
75
+ "im",
76
+ "immediately", "import", "important", "in", "include", "index", // GENERIC TECHNICAL NOUNS
77
+ "information",
78
+ "inside", "instead", "into", "is", "isn",
79
+ "isnt", "issue", "it", "item", "items", "its",
80
+ "itself", "ive", "j", "js", "json",
81
+
82
+ // FILLER/HEDGE WORDS
83
+ "just", "k", "keep", "kind", "kinda", "know", "l", "lambda", "last",
84
+ "later", "least", "len", "less", "let", "lets", "level", "like",
85
+ "likewise", "line", "lines", "list", "literally",
86
+ "ll", "look", "looking", "low", "m", "main",
87
+
88
+ "make", "making", "manual", "many", "may", "maybe", "md",
89
+ "me", "mean", "meanwhile", "method", "might", "mine", "mode",
90
+ "more", "moreover", "most", "much", "multiple", "must",
91
+
92
+ // PRONOUNS - Possessive
93
+ "my", "myself", "n", "nah", "near", "nearly", "need", "needed",
94
+ "neither", "never", "nevertheless", "new", "next", "nine", // NEGATION
95
+ "no", "nobody",
96
+ "none", "none", "nonetheless", "no one", "nope", "nor",
97
+ "not", "nothing", "now", "o", "obviously", "of",
98
+ "off", "often",
99
+
100
+ "oh", "ok", "okay", "on", "one", "ones",
101
+ "only", "onto", "option", "optional", "options",
102
+ "or", "other", "otherwise", "our", "ours",
103
+
104
+ "ourselves", "out", "outside", "over", "overall", "p", "part", "parts", "pass",
105
+
106
+ "per", "perhaps", "phase",
107
+ "pl", "please",
108
+ "point", "points", "possibly", "pretty", "previously", "primary", "probably",
109
+ "process", "proper", "provide", "provided", "purpose",
110
+ "put", // FILE EXTENSIONS
111
+ "py", "q", "question", // QUERY LANGUAGE
112
+ "questions",
113
+ "quite", "r", "rather",
114
+
115
+ // FRAGMENT WORDS
116
+ "re", "real", "really", "recently",
117
+
118
+ "region", "remain", "require",
119
+
120
+ "required", "result", "return", "right", "s", "same", "say",
121
+ "secondary", // DOCUMENT/CODE STRUCTURE
122
+ "section", "see", "seem",
123
+ // PROGRAMMING KEYWORDS
124
+ "self", "set", "seven", "several",
125
+ "shall", "she", "shes", "should",
126
+ "shouldn", "shouldnt", "show", "similarly", "simple",
127
+
128
+ "simply", "since", "single", "six", "so", // QUANTIFIERS
129
+ "some", "somebody", // PRONOUNS - Indefinite
130
+ "someone",
131
+ "something", "sometimes", "somewhat", "soon", "sorta", "source", "specific", "stable",
132
+ "start", "state", "status", "stay", // STRUCTURAL WORDS
133
+ "step", "steps",
134
+
135
+ "still", "str", "stuff", "such", "sys", "t",
136
+ "take", "tell", "ten", "that", "thats", "the",
137
+ "their", "theirs", "them", "themselves", "then", "there",
138
+
139
+ "therefore", "theres", "these", "they", "theyre", "theyve",
140
+ // OVERLY GENERIC TERMS
141
+ "thing", "things", "think", // PRONOUNS - Demonstrative
142
+ "this", "those", "though", "three",
143
+ "through", "thus", "time", "times",
144
+
145
+ // PREPOSITIONS
146
+ "to", "today", "toml", "tomorrow", // SHORT FILLER
147
+ "too", "totally",
148
+ "toward", "towards", "true", "try", "trying", "ts",
149
+
150
+ // NUMBER WORDS
151
+ "two", "type", "types", "u", "uh", // SPEECH-TO-TEXT FILLERS (STT artifacts from voice input)
152
+ "um", "under", "unless",
153
+
154
+ "until", "up", "upon", "us", "used", "uses", // COMMON CODING TERMS
155
+ "using",
156
+ "v", "value", "ve", "version", "very", "via", "w",
157
+ "wanna", // COMMON REQUEST PHRASES
158
+ "want", "was", "wasn", "wasnt", "way", "ways",
159
+ "we", "well", "were", "weren", "werent", "weve", // QUESTION WORDS
160
+ "what",
161
+ "whats", "when", "whenever", "where", "whereas",
162
+
163
+ "wherever", "whether", "which", "while",
164
+
165
+ // PRONOUNS - Relative
166
+ "who", "whom", "whos", "whose", "why", "will", "with", "within", "without",
167
+
168
+ "won", "wont", "work", "working", "works", "would", "wouldn", "wouldnt", "x", "y", "yaml", "yeah", "yep", "yes",
169
+ "yesterday", "yet", "yield", "you", "youll", "your", "youre", "yours",
170
+
171
+ "yourself", "youve", "yup", "z",
172
+ ]);
173
+
174
+ /**
175
+ * Filter stop words from text.
176
+ * Splits on whitespace, removes words in STOP_WORDS set and single-char words.
177
+ * See SPEC.md §6.4
178
+ */
179
+ export function filterStopWords(text: string): string {
180
+ return text
181
+ .split(/\s+/)
182
+ .filter((word) => word.length > 1 && !STOP_WORDS.has(word.toLowerCase()))
183
+ .join(" ");
184
+ }