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,316 @@
1
+ /**
2
+ * Plan lifecycle management — archival, lookup, and path extraction.
3
+ * See SPEC.md §9
4
+ *
5
+ * Provides pure-data operations on plan files:
6
+ * - archivePlan: copy plan to context plans/ folder, compute hash + signature
7
+ * - findLatestPlan: locate the most relevant plan for a context
8
+ * - extractPlanPathFromResult: parse plan path from ExitPlanMode output
9
+ */
10
+
11
+ import * as crypto from "node:crypto";
12
+ import * as fs from "node:fs";
13
+ import * as path from "node:path";
14
+
15
+ import { atomicWrite } from "../base/atomic-write.js";
16
+ import { getContextDir as _getContextDir, getContextPlansDir, sanitizeTitle } from "../base/constants.js";
17
+ import { logDebug, logError, logInfo, logWarn } from "../base/logger.js";
18
+ import { readStateJson } from "../base/state-io.js";
19
+ import { generateSlug } from "../base/utils.js";
20
+ import type { ContextState as _ContextState } from "../types.js";
21
+
22
+ // ---------------------------------------------------------------------------
23
+ // Plan archival
24
+ // ---------------------------------------------------------------------------
25
+
26
+ /**
27
+ * Archive a plan file to the context's plans/ folder.
28
+ * Computes a content hash and signature.
29
+ * Does NOT modify state.json or mode.
30
+ * See SPEC.md §9.2
31
+ *
32
+ * Returns [archivedPath, planHash, planSignature] on success,
33
+ * or [null, null, null] on error.
34
+ */
35
+ export async function archivePlan(
36
+ planPath: string,
37
+ contextId: string,
38
+ projectRoot?: string,
39
+ ): Promise<[null | string, null | string, null | string]> {
40
+ if (!fs.existsSync(planPath)) {
41
+ logWarn("plan_manager", `Plan file not found: ${planPath}`);
42
+ return [null, null, null];
43
+ }
44
+
45
+ let content: string;
46
+ try {
47
+ content = fs.readFileSync(planPath, "utf8");
48
+ } catch (error_: any) {
49
+ logError("plan_manager", `Failed to read plan: ${error_}`);
50
+ return [null, null, null];
51
+ }
52
+
53
+ // Compute hash and signature
54
+ const planHash = crypto.createHash("sha256").update(content, "utf-8").digest("hex").slice(0, 12);
55
+ const planSignature = content.slice(0, 200);
56
+
57
+ // Ensure plans directory exists
58
+ const plansDir = getContextPlansDir(contextId, projectRoot);
59
+ fs.mkdirSync(plansDir, { recursive: true });
60
+
61
+ // Generate archive filename: YYYY-MM-DD-HHMM-<slug>.md
62
+ const now = new Date();
63
+ const dateStr = [
64
+ now.getFullYear(),
65
+ "-",
66
+ String(now.getMonth() + 1).padStart(2, "0"),
67
+ "-",
68
+ String(now.getDate()).padStart(2, "0"),
69
+ "-",
70
+ String(now.getHours()).padStart(2, "0"),
71
+ String(now.getMinutes()).padStart(2, "0"),
72
+ ].join("");
73
+
74
+ // Extract a clean summary from plan content for slug generation.
75
+ // Headings describe the plan's intent better than raw markdown body.
76
+ const summary = extractPlanSummary(content);
77
+ const slug = generateSlug(summary, 60, sanitizeTitle(
78
+ path.basename(planPath, path.extname(planPath)), 30,
79
+ ));
80
+
81
+ let archiveName = `${dateStr}-${slug}.md`;
82
+ let archivePath = path.join(plansDir, archiveName);
83
+
84
+ // Handle filename collisions
85
+ let counter = 2;
86
+ while (fs.existsSync(archivePath)) {
87
+ archiveName = `${dateStr}-${slug}-${counter}.md`;
88
+ archivePath = path.join(plansDir, archiveName);
89
+ counter++;
90
+ }
91
+
92
+ // Write archived plan atomically
93
+ const [success, error] = atomicWrite(archivePath, content);
94
+ if (!success) {
95
+ logError("plan_manager", `Failed to write archive: ${error}`);
96
+ return [null, null, null];
97
+ }
98
+
99
+ logInfo("plan_manager", `Archived plan to: ${archivePath}`);
100
+ return [archivePath, planHash, planSignature];
101
+ }
102
+
103
+ /**
104
+ * Extract a human-readable summary from plan markdown content.
105
+ * Pulls headings and the first substantial paragraph, producing
106
+ * text suitable for the AI slug generator (which expects conversational input).
107
+ */
108
+ function extractPlanSummary(content: string): string {
109
+ const lines = content.split("\n");
110
+ const parts: string[] = [];
111
+ let firstParagraph = "";
112
+
113
+ for (const line of lines) {
114
+ const trimmed = line.trim();
115
+ // Collect markdown headings (strip # prefix)
116
+ if (trimmed.startsWith("#")) {
117
+ const heading = trimmed.replace(/^#+\s*/, "");
118
+ if (heading.length > 2) parts.push(heading);
119
+ }
120
+
121
+ // Grab first substantial non-heading line as context
122
+ if (!firstParagraph && !trimmed.startsWith("#") && trimmed.length > 20) {
123
+ firstParagraph = trimmed.slice(0, 120);
124
+ }
125
+
126
+ // Enough material for the AI
127
+ if (parts.length >= 5) break;
128
+ }
129
+
130
+ if (firstParagraph) parts.push(firstParagraph);
131
+ return parts.join(" ").slice(0, 500) || content.slice(0, 500);
132
+ }
133
+
134
+ // ---------------------------------------------------------------------------
135
+ // Plan lookup
136
+ // ---------------------------------------------------------------------------
137
+
138
+ /**
139
+ * Find the most relevant plan file for a context.
140
+ * Priority: state.json plan_path > most recent .md in plans/ dir.
141
+ * See SPEC.md §9.3
142
+ */
143
+ export function findLatestPlan(
144
+ contextId: string,
145
+ projectRoot?: string,
146
+ ): null | string {
147
+ // 1. Check state.json plan_path first
148
+ try {
149
+ const state = readStateJson(contextId, projectRoot);
150
+ if (state?.plan_path && fs.existsSync(state.plan_path)) {
151
+ return state.plan_path;
152
+ }
153
+ } catch (error: any) {
154
+ logWarn("plan_manager", `Failed to check state.json plan_path: ${error}`);
155
+ }
156
+
157
+ // 2. Fall back to most recent .md in plans/ dir
158
+ const plansDir = getContextPlansDir(contextId, projectRoot);
159
+ if (fs.existsSync(plansDir)) {
160
+ try {
161
+ const files = fs.readdirSync(plansDir)
162
+ .filter(f => f.endsWith(".md"))
163
+ .map(f => {
164
+ const fullPath = path.join(plansDir, f);
165
+ return { path: fullPath, mtime: fs.statSync(fullPath).mtimeMs };
166
+ })
167
+ .sort((a, b) => b.mtime - a.mtime);
168
+
169
+ if (files.length > 0) {
170
+ return files[0]!.path;
171
+ }
172
+ } catch { /* ignore */ }
173
+ }
174
+
175
+ return null;
176
+ }
177
+
178
+ // ---------------------------------------------------------------------------
179
+ // Plan identification and normalization
180
+ // ---------------------------------------------------------------------------
181
+
182
+ /**
183
+ * Generate a short unique plan identifier (8 hex chars).
184
+ * See SPEC.md §9.4
185
+ */
186
+ export function generatePlanId(): string {
187
+ return crypto.randomUUID().replaceAll('-', "").slice(0, 8);
188
+ }
189
+
190
+ /**
191
+ * Aggressively normalize plan content for hashing.
192
+ * Strips all XML/HTML tags and collapses whitespace.
193
+ * See SPEC.md §9.5
194
+ */
195
+ export function normalizePlanContent(text: string): string {
196
+ let result = text.replaceAll(/<[^>]+>/g, "");
197
+ result = result.replaceAll(/\s+/g, " ").trim();
198
+ return result;
199
+ }
200
+
201
+ /**
202
+ * Extract structural anchors from plan content.
203
+ * Returns markdown headings + first substantial paragraph as short strings.
204
+ * See SPEC.md §9.6
205
+ */
206
+ export function extractPlanAnchors(content: string, maxAnchors = 5): string[] {
207
+ const anchors: string[] = [];
208
+ for (const line of content.split("\n")) {
209
+ const trimmed = line.trim();
210
+ if (trimmed.startsWith("#") && trimmed.length > 3) {
211
+ anchors.push(trimmed.slice(0, 80));
212
+ } else if (anchors.length === 0 && trimmed.length > 20) {
213
+ anchors.push(trimmed.slice(0, 80));
214
+ }
215
+
216
+ if (anchors.length >= maxAnchors) break;
217
+ }
218
+
219
+ return anchors;
220
+ }
221
+
222
+ // ---------------------------------------------------------------------------
223
+ // Transcript-based plan path extraction
224
+ // ---------------------------------------------------------------------------
225
+
226
+ const MAX_TRANSCRIPT_SIZE = 50 * 1024 * 1024; // 50 MB
227
+
228
+ /**
229
+ * Find the plan file path by parsing the session transcript JSONL.
230
+ * Searches in reverse for the most recent Write tool call targeting .claude/plans/.
231
+ * See SPEC.md §9.7
232
+ */
233
+ export function findPlanPathInTranscript(transcriptPath: string): null | string {
234
+ if (!transcriptPath) return null;
235
+
236
+ if (!fs.existsSync(transcriptPath)) {
237
+ logDebug("plan_manager", `Transcript not found: ${transcriptPath}`);
238
+ return null;
239
+ }
240
+
241
+ let size: number;
242
+ try {
243
+ size = fs.statSync(transcriptPath).size;
244
+ } catch {
245
+ return null;
246
+ }
247
+
248
+ if (size > MAX_TRANSCRIPT_SIZE) {
249
+ logWarn("plan_manager", `Transcript too large (${size} bytes), skipping`);
250
+ return null;
251
+ }
252
+
253
+ let lines: string[];
254
+ try {
255
+ lines = fs.readFileSync(transcriptPath, "utf8").split("\n");
256
+ } catch (error: any) {
257
+ logWarn("plan_manager", `Failed to read transcript: ${error}`);
258
+ return null;
259
+ }
260
+
261
+ for (let i = lines.length - 1; i >= 0; i--) {
262
+ const line = lines[i]!.trim();
263
+ if (!line) continue;
264
+
265
+ let data: any;
266
+ try {
267
+ data = JSON.parse(line);
268
+ } catch {
269
+ continue;
270
+ }
271
+
272
+ let contentArr: any;
273
+ try {
274
+ contentArr = data.message?.content;
275
+ } catch {
276
+ continue;
277
+ }
278
+
279
+ if (!Array.isArray(contentArr)) continue;
280
+
281
+ for (const block of contentArr) {
282
+ if (typeof block !== "object" || block === null) continue;
283
+ if (block.type !== "tool_use" || block.name !== "Write") continue;
284
+
285
+ const filePath = block.input?.file_path;
286
+ if (!filePath) continue;
287
+
288
+ // Check if path contains .claude/plans/ as consecutive parts
289
+ const parts = filePath.replaceAll('\\', "/").split("/");
290
+ for (let j = 0; j < parts.length - 1; j++) {
291
+ if (parts[j] === ".claude" && parts[j + 1] === "plans") {
292
+ logInfo("plan_manager", `Extracted plan path from transcript: ${filePath}`);
293
+ return filePath;
294
+ }
295
+ }
296
+ }
297
+ }
298
+
299
+ logDebug("plan_manager", "No plan Write found in transcript");
300
+ return null;
301
+ }
302
+
303
+ // ---------------------------------------------------------------------------
304
+ // Path extraction from tool output
305
+ // ---------------------------------------------------------------------------
306
+
307
+ /**
308
+ * Extract plan file path from ExitPlanMode tool result.
309
+ * Parses the pattern: "Your plan has been saved to: <path>"
310
+ * See SPEC.md §9.8
311
+ */
312
+ export function extractPlanPathFromResult(toolResult: string): null | string {
313
+ if (!toolResult) return null;
314
+ const match = toolResult.match(/Your plan has been saved to:\s*(.+\.md)/);
315
+ return match ? match[1]!.trim() : null;
316
+ }
@@ -0,0 +1,185 @@
1
+ /**
2
+ * Task tracker — direct state.json CRUD for tasks.
3
+ * See SPEC.md §10
4
+ *
5
+ * Writes tasks directly to the tasks[] array in state.json.
6
+ * Uses state-io for I/O to avoid circular imports with context-store.
7
+ */
8
+
9
+ import { logWarn } from "../base/logger.js";
10
+ import { readStateJson, toDict as _toDict, writeStateJson } from "../base/state-io.js";
11
+ import { nowIso } from "../base/utils.js";
12
+ import type { ContextState as _ContextState, Task } from "../types.js";
13
+
14
+ // ---------------------------------------------------------------------------
15
+ // Public API
16
+ // ---------------------------------------------------------------------------
17
+
18
+ /**
19
+ * Scan tasks[] for highest aiw-N, return aiw-(N+1).
20
+ * See SPEC.md §10.2
21
+ */
22
+ export function generateNextTaskId(contextId: string, projectRoot?: string): string {
23
+ const state = readStateJson(contextId, projectRoot);
24
+ const tasks = state?.tasks ?? [];
25
+
26
+ let maxNum = 0;
27
+ for (const t of tasks) {
28
+ const match = /^aiw-(\d+)$/.exec(t.id);
29
+ if (match) {
30
+ const num = Number.parseInt(match[1]!, 10);
31
+ if (num > maxNum) maxNum = num;
32
+ }
33
+ }
34
+
35
+ return `aiw-${maxNum + 1}`;
36
+ }
37
+
38
+ /**
39
+ * Add a new task to state.json tasks[] and return the task object.
40
+ * See SPEC.md §10.3
41
+ */
42
+ export function addTask(
43
+ contextId: string,
44
+ subject: string,
45
+ description = "",
46
+ activeForm = "",
47
+ sessionId = "",
48
+ projectRoot?: string,
49
+ ): null | Task {
50
+ const state = readStateJson(contextId, projectRoot);
51
+ if (!state) return null;
52
+
53
+ const taskId = generateNextTaskId(contextId, projectRoot);
54
+ const task: Task = {
55
+ id: taskId,
56
+ subject,
57
+ description,
58
+ active_form: activeForm,
59
+ status: "pending",
60
+ created_at: nowIso(),
61
+ completed_at: null,
62
+ evidence: "",
63
+ work_summary: "",
64
+ files_changed: [],
65
+ session_id: sessionId,
66
+ };
67
+
68
+ state.tasks.push(task);
69
+ state.last_active = nowIso();
70
+
71
+ const [success] = writeStateJson(contextId, state, projectRoot);
72
+ return success ? task : null;
73
+ }
74
+
75
+ /**
76
+ * Find task by task_id in tasks[], update fields, return true on success.
77
+ * See SPEC.md §10.4
78
+ */
79
+ export function updateTask(
80
+ contextId: string,
81
+ taskId: string,
82
+ opts?: {
83
+ evidence?: string;
84
+ files_changed?: string[];
85
+ session_id?: string;
86
+ status?: string;
87
+ work_summary?: string;
88
+ },
89
+ projectRoot?: string,
90
+ ): boolean {
91
+ const state = readStateJson(contextId, projectRoot);
92
+ if (!state) return false;
93
+
94
+ for (const task of state.tasks) {
95
+ if (task.id === taskId) {
96
+ if (opts?.status !== undefined) {
97
+ task.status = opts.status as Task["status"];
98
+ if (opts.status === "completed") {
99
+ task.completed_at = nowIso();
100
+ }
101
+ }
102
+
103
+ if (opts?.evidence) task.evidence = opts.evidence;
104
+ if (opts?.work_summary) task.work_summary = opts.work_summary;
105
+ if (opts?.files_changed !== undefined) task.files_changed = opts.files_changed;
106
+ if (opts?.session_id) task.session_id = opts.session_id;
107
+ state.last_active = nowIso();
108
+ const [success] = writeStateJson(contextId, state, projectRoot);
109
+ return success;
110
+ }
111
+ }
112
+
113
+ logWarn("task_tracker", `Task '${taskId}' not found in context '${contextId}'`);
114
+ return false;
115
+ }
116
+
117
+ /**
118
+ * Remove task from tasks[] and return true on success.
119
+ * See SPEC.md §10.5
120
+ */
121
+ export function deleteTask(
122
+ contextId: string,
123
+ taskId: string,
124
+ projectRoot?: string,
125
+ ): boolean {
126
+ const state = readStateJson(contextId, projectRoot);
127
+ if (!state) return false;
128
+
129
+ const originalLen = state.tasks.length;
130
+ state.tasks = state.tasks.filter(t => t.id !== taskId);
131
+
132
+ if (state.tasks.length === originalLen) {
133
+ logWarn("task_tracker", `Task '${taskId}' not found in context '${contextId}'`);
134
+ return false;
135
+ }
136
+
137
+ state.last_active = nowIso();
138
+ const [success] = writeStateJson(contextId, state, projectRoot);
139
+ return success;
140
+ }
141
+
142
+ /**
143
+ * Return tasks[] from state.json.
144
+ * See SPEC.md §10.6
145
+ */
146
+ export function getTasks(contextId: string, projectRoot?: string): Task[] {
147
+ const state = readStateJson(contextId, projectRoot);
148
+ if (!state) return [];
149
+ return state.tasks;
150
+ }
151
+
152
+ /**
153
+ * Partition tasks and format as markdown checklist.
154
+ * See SPEC.md §10.7
155
+ */
156
+ export function generateTaskSummary(contextId: string, projectRoot?: string): string {
157
+ const tasks = getTasks(contextId, projectRoot);
158
+ if (tasks.length === 0) return "No tasks in this context.";
159
+
160
+ const completed = tasks.filter(t => t.status === "completed");
161
+ const inProgress = tasks.filter(t => t.status === "in_progress");
162
+ const pending = tasks.filter(t => t.status === "pending");
163
+ const blocked = tasks.filter(t => t.status === "blocked");
164
+
165
+ const lines: string[] = [`### Tasks (${tasks.length} total)`, ""];
166
+
167
+ for (const t of completed) {
168
+ const ws = t.work_summary ? `\n Work: ${t.work_summary}` : "";
169
+ lines.push(`- [x] ${t.id}: ${t.subject}${ws}`);
170
+ }
171
+
172
+ for (const t of inProgress) {
173
+ lines.push(`- [~] ${t.id}: ${t.subject}`);
174
+ }
175
+
176
+ for (const t of pending) {
177
+ lines.push(`- [ ] ${t.id}: ${t.subject}`);
178
+ }
179
+
180
+ for (const t of blocked) {
181
+ lines.push(`- [!] ${t.id}: ${t.subject}`);
182
+ }
183
+
184
+ return lines.join("\n");
185
+ }