@litfamily/litcodex 1.0.30 → 1.0.32

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 (394) hide show
  1. package/README-Ko-KR.md +13 -12
  2. package/README.md +13 -12
  3. package/TRADEMARK.md +12 -0
  4. package/dist/install/generated-skill-payload-hashes.d.ts +188 -82
  5. package/dist/install/generated-skill-payload-hashes.js +188 -82
  6. package/dist/install/skill-catalog.d.ts +1 -1
  7. package/dist/install/skill-catalog.js +12 -1
  8. package/dist/install/skill-resource-hashes.d.ts +1 -1
  9. package/dist/install/skill-resource-hashes.js +1 -1
  10. package/marketplace/plugins/litcodex/.codex-plugin/plugin.json +1 -1
  11. package/marketplace/plugins/litcodex/components/auto-update/package.json +1 -1
  12. package/marketplace/plugins/litcodex/components/comment-checker/package.json +1 -1
  13. package/marketplace/plugins/litcodex/components/git-bash/package.json +1 -1
  14. package/marketplace/plugins/litcodex/components/lit-loop/directive.md +10 -4
  15. package/marketplace/plugins/litcodex/components/lit-loop/directives/lit-adhd.md +194 -0
  16. package/marketplace/plugins/litcodex/components/lit-loop/directives/lit-handoff.md +2 -0
  17. package/marketplace/plugins/litcodex/components/lit-loop/directives/lit-hijack.md +219 -0
  18. package/marketplace/plugins/litcodex/components/lit-loop/directives/lit-plan.md +2 -1
  19. package/marketplace/plugins/litcodex/components/lit-loop/directives/lit-recap.md +2 -0
  20. package/marketplace/plugins/litcodex/components/lit-loop/directives/lit-schematic.md +199 -0
  21. package/marketplace/plugins/litcodex/components/lit-loop/directives/litwork.md +2 -1
  22. package/marketplace/plugins/litcodex/components/lit-loop/dist/adhd-suggest.d.ts +10 -0
  23. package/marketplace/plugins/litcodex/components/lit-loop/dist/adhd-suggest.js +67 -0
  24. package/marketplace/plugins/litcodex/components/lit-loop/dist/card-html.d.ts +1 -1
  25. package/marketplace/plugins/litcodex/components/lit-loop/dist/card-html.js +128 -8
  26. package/marketplace/plugins/litcodex/components/lit-loop/dist/card-looks.d.ts +19 -0
  27. package/marketplace/plugins/litcodex/components/lit-loop/dist/card-looks.js +58 -0
  28. package/marketplace/plugins/litcodex/components/lit-loop/dist/card-status.d.ts +30 -0
  29. package/marketplace/plugins/litcodex/components/lit-loop/dist/card-status.js +97 -7
  30. package/marketplace/plugins/litcodex/components/lit-loop/dist/cli.js +13 -3
  31. package/marketplace/plugins/litcodex/components/lit-loop/dist/codex-hook.d.ts +2 -0
  32. package/marketplace/plugins/litcodex/components/lit-loop/dist/codex-hook.js +8 -9
  33. package/marketplace/plugins/litcodex/components/lit-loop/dist/control-chars.d.ts +5 -0
  34. package/marketplace/plugins/litcodex/components/lit-loop/dist/control-chars.js +23 -0
  35. package/marketplace/plugins/litcodex/components/lit-loop/dist/hook-cli.d.ts +8 -0
  36. package/marketplace/plugins/litcodex/components/lit-loop/dist/hook-cli.js +126 -13
  37. package/marketplace/plugins/litcodex/components/lit-loop/dist/hud.d.ts +1 -1
  38. package/marketplace/plugins/litcodex/components/lit-loop/dist/hud.js +29 -13
  39. package/marketplace/plugins/litcodex/components/lit-loop/dist/lane-events.d.ts +13 -0
  40. package/marketplace/plugins/litcodex/components/lit-loop/dist/lane-events.js +85 -0
  41. package/marketplace/plugins/litcodex/components/lit-loop/dist/lane-state.d.ts +55 -0
  42. package/marketplace/plugins/litcodex/components/lit-loop/dist/lane-state.js +227 -0
  43. package/marketplace/plugins/litcodex/components/lit-loop/dist/live-step.d.ts +5 -1
  44. package/marketplace/plugins/litcodex/components/lit-loop/dist/live-step.js +17 -1
  45. package/marketplace/plugins/litcodex/components/lit-loop/dist/markers.d.ts +6 -0
  46. package/marketplace/plugins/litcodex/components/lit-loop/dist/markers.js +6 -0
  47. package/marketplace/plugins/litcodex/components/lit-loop/dist/modes.d.ts +1 -1
  48. package/marketplace/plugins/litcodex/components/lit-loop/dist/modes.js +25 -1
  49. package/marketplace/plugins/litcodex/components/lit-loop/dist/motion-gate.d.ts +79 -0
  50. package/marketplace/plugins/litcodex/components/lit-loop/dist/motion-gate.js +310 -0
  51. package/marketplace/plugins/litcodex/components/lit-loop/dist/motion-route.js +5 -1
  52. package/marketplace/plugins/litcodex/components/lit-loop/dist/plan-persistence.d.ts +1 -1
  53. package/marketplace/plugins/litcodex/components/lit-loop/dist/plan-persistence.js +38 -2
  54. package/marketplace/plugins/litcodex/components/lit-loop/dist/plan-scope-roots.d.ts +7 -0
  55. package/marketplace/plugins/litcodex/components/lit-loop/dist/plan-scope-roots.js +76 -0
  56. package/marketplace/plugins/litcodex/components/lit-loop/dist/redaction.js +18 -0
  57. package/marketplace/plugins/litcodex/components/lit-loop/dist/reentry.d.ts +15 -0
  58. package/marketplace/plugins/litcodex/components/lit-loop/dist/reentry.js +46 -9
  59. package/marketplace/plugins/litcodex/components/lit-loop/dist/restart-chip.d.ts +6 -0
  60. package/marketplace/plugins/litcodex/components/lit-loop/dist/restart-chip.js +59 -0
  61. package/marketplace/plugins/litcodex/components/lit-loop/dist/rewind-cli.d.ts +10 -0
  62. package/marketplace/plugins/litcodex/components/lit-loop/dist/rewind-cli.js +88 -0
  63. package/marketplace/plugins/litcodex/components/lit-loop/dist/rewind-go.d.ts +20 -0
  64. package/marketplace/plugins/litcodex/components/lit-loop/dist/rewind-go.js +94 -0
  65. package/marketplace/plugins/litcodex/components/lit-loop/dist/rewind-look.d.ts +6 -0
  66. package/marketplace/plugins/litcodex/components/lit-loop/dist/rewind-look.js +41 -0
  67. package/marketplace/plugins/litcodex/components/lit-loop/dist/rewind-redact.d.ts +3 -0
  68. package/marketplace/plugins/litcodex/components/lit-loop/dist/rewind-redact.js +40 -0
  69. package/marketplace/plugins/litcodex/components/lit-loop/dist/rewind-rollout.d.ts +48 -0
  70. package/marketplace/plugins/litcodex/components/lit-loop/dist/rewind-rollout.js +292 -0
  71. package/marketplace/plugins/litcodex/components/lit-loop/dist/rewind.d.ts +168 -0
  72. package/marketplace/plugins/litcodex/components/lit-loop/dist/rewind.js +867 -0
  73. package/marketplace/plugins/litcodex/components/lit-loop/dist/route-heads.js +45 -3
  74. package/marketplace/plugins/litcodex/components/lit-loop/dist/run-panel.js +1 -0
  75. package/marketplace/plugins/litcodex/components/lit-loop/dist/schematic-route.d.ts +6 -0
  76. package/marketplace/plugins/litcodex/components/lit-loop/dist/schematic-route.js +35 -0
  77. package/marketplace/plugins/litcodex/components/lit-loop/dist/screen-card.d.ts +3 -0
  78. package/marketplace/plugins/litcodex/components/lit-loop/dist/screen-card.js +15 -5
  79. package/marketplace/plugins/litcodex/components/lit-loop/dist/session-liveness.d.ts +16 -0
  80. package/marketplace/plugins/litcodex/components/lit-loop/dist/session-liveness.js +90 -0
  81. package/marketplace/plugins/litcodex/components/lit-loop/dist/skill-mention-scope.js +6 -0
  82. package/marketplace/plugins/litcodex/components/lit-loop/dist/stack-hook.d.ts +8 -0
  83. package/marketplace/plugins/litcodex/components/lit-loop/dist/stack-hook.js +57 -0
  84. package/marketplace/plugins/litcodex/components/lit-loop/dist/statusline.js +8 -3
  85. package/marketplace/plugins/litcodex/components/lit-loop/dist/threads.d.ts +50 -0
  86. package/marketplace/plugins/litcodex/components/lit-loop/dist/threads.js +183 -0
  87. package/marketplace/plugins/litcodex/components/lit-loop/dist/trigger.d.ts +1 -1
  88. package/marketplace/plugins/litcodex/components/lit-loop/dist/trigger.js +29 -5
  89. package/marketplace/plugins/litcodex/components/lit-loop/dist/workflow-map.d.ts +10 -0
  90. package/marketplace/plugins/litcodex/components/lit-loop/dist/workflow-map.js +11 -1
  91. package/marketplace/plugins/litcodex/components/lit-loop/dist/workflow-stack.d.ts +139 -0
  92. package/marketplace/plugins/litcodex/components/lit-loop/dist/workflow-stack.js +518 -0
  93. package/marketplace/plugins/litcodex/components/lit-loop/package.json +1 -1
  94. package/marketplace/plugins/litcodex/components/lsp/package.json +1 -1
  95. package/marketplace/plugins/litcodex/components/rules/package.json +1 -1
  96. package/marketplace/plugins/litcodex/components/start-work-continuation/dist/codex-hook.d.ts +6 -0
  97. package/marketplace/plugins/litcodex/components/start-work-continuation/dist/codex-hook.js +65 -0
  98. package/marketplace/plugins/litcodex/components/start-work-continuation/package.json +1 -1
  99. package/marketplace/plugins/litcodex/components/telemetry/package.json +1 -1
  100. package/marketplace/plugins/litcodex/components/wikify-knowledge/package.json +1 -1
  101. package/marketplace/plugins/litcodex/hooks/hooks.json +24 -0
  102. package/marketplace/plugins/litcodex/skills/frontend-ui-ux/SKILL.md +6 -0
  103. package/marketplace/plugins/litcodex/skills/frontend-ui-ux/kit/components.css +414 -0
  104. package/marketplace/plugins/litcodex/skills/frontend-ui-ux/kit/fonts.json +22 -0
  105. package/marketplace/plugins/litcodex/skills/frontend-ui-ux/kit/layouts/landing.html +164 -0
  106. package/marketplace/plugins/litcodex/skills/frontend-ui-ux/kit/layouts/settings.html +114 -0
  107. package/marketplace/plugins/litcodex/skills/frontend-ui-ux/kit/layouts/workspace.html +115 -0
  108. package/marketplace/plugins/litcodex/skills/frontend-ui-ux/kit/styles/computational-brutalism.json +227 -0
  109. package/marketplace/plugins/litcodex/skills/frontend-ui-ux/kit/styles/field-notes.json +205 -0
  110. package/marketplace/plugins/litcodex/skills/frontend-ui-ux/kit/styles/graphite.json +200 -0
  111. package/marketplace/plugins/litcodex/skills/frontend-ui-ux/kit/styles/meadow.json +199 -0
  112. package/marketplace/plugins/litcodex/skills/frontend-ui-ux/kit/styles/neo-brutalism.json +222 -0
  113. package/marketplace/plugins/litcodex/skills/frontend-ui-ux/kit/ui.js +228 -0
  114. package/marketplace/plugins/litcodex/skills/frontend-ui-ux/references/brand-and-imagery.md +1 -1
  115. package/marketplace/plugins/litcodex/skills/frontend-ui-ux/references/complete-contract.md +1 -0
  116. package/marketplace/plugins/litcodex/skills/frontend-ui-ux/references/craft-floor.md +2 -2
  117. package/marketplace/plugins/litcodex/skills/frontend-ui-ux/references/default-editorial-pixel.json +15 -8
  118. package/marketplace/plugins/litcodex/skills/frontend-ui-ux/references/design-choice.md +19 -0
  119. package/marketplace/plugins/litcodex/skills/frontend-ui-ux/references/house-styles.md +235 -0
  120. package/marketplace/plugins/litcodex/skills/frontend-ui-ux/references/motion-guide.md +2 -2
  121. package/marketplace/plugins/litcodex/skills/frontend-ui-ux/references/probe-and-review.md +6 -0
  122. package/marketplace/plugins/litcodex/skills/frontend-ui-ux/references/production-interview.md +2 -0
  123. package/marketplace/plugins/litcodex/skills/frontend-ui-ux/references/slop-register.md +4 -4
  124. package/marketplace/plugins/litcodex/skills/frontend-ui-ux/scripts/design-lock.mjs +400 -0
  125. package/marketplace/plugins/litcodex/skills/frontend-ui-ux/scripts/lock-probe.mjs +196 -0
  126. package/marketplace/plugins/litcodex/skills/frontend-ui-ux/scripts/page-probe.mjs +22 -4
  127. package/marketplace/plugins/litcodex/skills/frontend-ui-ux/scripts/pixel-art.mjs +60 -0
  128. package/marketplace/plugins/litcodex/skills/frontend-ui-ux/scripts/probe.mjs +59 -13
  129. package/marketplace/plugins/litcodex/skills/frontend-ui-ux/scripts/rule-data.mjs +38 -4
  130. package/marketplace/plugins/litcodex/skills/lit-adhd/SKILL.md +185 -0
  131. package/marketplace/plugins/litcodex/skills/lit-adhd/agents/openai.yaml +6 -0
  132. package/marketplace/plugins/litcodex/skills/lit-adhd/references/card-examples.md +163 -0
  133. package/marketplace/plugins/litcodex/skills/lit-adhd/references/status-taxonomy.md +45 -0
  134. package/marketplace/plugins/litcodex/skills/lit-diagram-drawer/SKILL.md +18 -7
  135. package/marketplace/plugins/litcodex/skills/lit-diagram-drawer/references/style-guide.md +20 -11
  136. package/marketplace/plugins/litcodex/skills/lit-diagram-drawer/references/type-architecture.md +3 -3
  137. package/marketplace/plugins/litcodex/skills/lit-diagram-drawer/references/type-dependency.md +1 -1
  138. package/marketplace/plugins/litcodex/skills/lit-diagram-drawer/references/type-swimlane.md +1 -1
  139. package/marketplace/plugins/litcodex/skills/lit-diagram-drawer/references/type-tree-block-decomposition.md +1 -1
  140. package/marketplace/plugins/litcodex/skills/lit-diagram-drawer/references/type-tree.md +3 -3
  141. package/marketplace/plugins/litcodex/skills/lit-diagram-drawer/references/type-wardley.md +1 -1
  142. package/marketplace/plugins/litcodex/skills/lit-diagram-drawer/references/verifier-guide.md +1 -0
  143. package/marketplace/plugins/litcodex/skills/lit-diagram-drawer/scripts/diagram-craft-rules.mjs +1 -2
  144. package/marketplace/plugins/litcodex/skills/lit-diagram-drawer/scripts/visual-quality.mjs +1 -2
  145. package/marketplace/plugins/litcodex/skills/lit-docx/SKILL.md +12 -3
  146. package/marketplace/plugins/litcodex/skills/lit-docx/references/direction-step.md +6 -3
  147. package/marketplace/plugins/litcodex/skills/lit-hijack/SKILL.md +449 -0
  148. package/marketplace/plugins/litcodex/skills/lit-hijack/agents/openai.yaml +6 -0
  149. package/marketplace/plugins/litcodex/skills/lit-hijack/references/capture-and-provenance.md +100 -0
  150. package/marketplace/plugins/litcodex/skills/lit-hijack/references/clean-room-build.md +111 -0
  151. package/marketplace/plugins/litcodex/skills/lit-hijack/references/distil-and-licence.md +102 -0
  152. package/marketplace/plugins/litcodex/skills/lit-hijack/references/gap-and-port-design.md +125 -0
  153. package/marketplace/plugins/litcodex/skills/lit-hijack/references/parity-and-report.md +108 -0
  154. package/marketplace/plugins/litcodex/skills/lit-hijack/scripts/hijack.mjs +1050 -0
  155. package/marketplace/plugins/litcodex/skills/lit-loop/SKILL.md +13 -4
  156. package/marketplace/plugins/litcodex/skills/lit-plan/SKILL.md +9 -2
  157. package/marketplace/plugins/litcodex/skills/lit-plan/references/full-workflow.md +2 -1
  158. package/marketplace/plugins/litcodex/skills/lit-pptx/NOTICE +1 -0
  159. package/marketplace/plugins/litcodex/skills/lit-pptx/SKILL.md +35 -8
  160. package/marketplace/plugins/litcodex/skills/lit-pptx/fonts/jetbrains-mono/JetBrainsMono-Bold.ttf +0 -0
  161. package/marketplace/plugins/litcodex/skills/lit-pptx/fonts/jetbrains-mono/JetBrainsMono-Regular.ttf +0 -0
  162. package/marketplace/plugins/litcodex/skills/lit-pptx/fonts/jetbrains-mono/OFL.txt +93 -0
  163. package/marketplace/plugins/litcodex/skills/lit-pptx/fonts/jetbrains-mono/SOURCE.md +21 -0
  164. package/marketplace/plugins/litcodex/skills/lit-pptx/references/anti-slop-checklist.md +5 -2
  165. package/marketplace/plugins/litcodex/skills/lit-pptx/references/authoring-guide.md +3 -4
  166. package/marketplace/plugins/litcodex/skills/lit-pptx/references/density-and-fill.md +20 -6
  167. package/marketplace/plugins/litcodex/skills/lit-pptx/references/direction-step.md +26 -8
  168. package/marketplace/plugins/litcodex/skills/lit-pptx/references/examples/14-engineering-review-computational-brutalism-ko.md +173 -0
  169. package/marketplace/plugins/litcodex/skills/lit-pptx/references/examples/15-launch-pitch-neo-brutalism-ko.md +154 -0
  170. package/marketplace/plugins/litcodex/skills/lit-pptx/references/examples/16-design-lecture-bauhaus-ko.md +139 -0
  171. package/marketplace/plugins/litcodex/skills/lit-pptx/references/examples/17-community-programme-riso-ko.md +158 -0
  172. package/marketplace/plugins/litcodex/skills/lit-pptx/references/examples/18-public-data-briefing-newsroom-ko.md +179 -0
  173. package/marketplace/plugins/litcodex/skills/lit-pptx/references/layout-families.md +42 -27
  174. package/marketplace/plugins/litcodex/skills/lit-pptx/references/title-treatments.md +31 -27
  175. package/marketplace/plugins/litcodex/skills/lit-pptx/references/tonalities/bauhaus.md +136 -0
  176. package/marketplace/plugins/litcodex/skills/lit-pptx/references/tonalities/chalk.md +1 -1
  177. package/marketplace/plugins/litcodex/skills/lit-pptx/references/tonalities/computational-brutalism.md +145 -0
  178. package/marketplace/plugins/litcodex/skills/lit-pptx/references/tonalities/neo-brutalism.md +155 -0
  179. package/marketplace/plugins/litcodex/skills/lit-pptx/references/tonalities/newsroom.md +141 -0
  180. package/marketplace/plugins/litcodex/skills/lit-pptx/references/tonalities/riso.md +133 -0
  181. package/marketplace/plugins/litcodex/skills/lit-pptx/references/tonalities/signal.md +1 -1
  182. package/marketplace/plugins/litcodex/skills/lit-pptx/references/tonalities/studio.md +1 -1
  183. package/marketplace/plugins/litcodex/skills/lit-pptx/scripts/compile-deck.js +1 -1
  184. package/marketplace/plugins/litcodex/skills/lit-pptx/scripts/craft_extras.py +136 -94
  185. package/marketplace/plugins/litcodex/skills/lit-pptx/scripts/embed_fonts.py +13 -1
  186. package/marketplace/plugins/litcodex/skills/lit-pptx/scripts/lib/grid-resolver.js +101 -110
  187. package/marketplace/plugins/litcodex/skills/lit-pptx/scripts/lib/layout-resolver.js +9 -15
  188. package/marketplace/plugins/litcodex/skills/lit-pptx/scripts/lib/render-pack.js +386 -579
  189. package/marketplace/plugins/litcodex/skills/lit-pptx/scripts/lib/slide-grid.js +104 -0
  190. package/marketplace/plugins/litcodex/skills/lit-pptx/scripts/lib/template-registry.js +57 -6
  191. package/marketplace/plugins/litcodex/skills/lit-pptx/scripts/office-run.mjs +2 -1
  192. package/marketplace/plugins/litcodex/skills/lit-pptx/scripts/qa_deck.py +7 -13
  193. package/marketplace/plugins/litcodex/skills/lit-pptx/scripts/render_pages.py +124 -0
  194. package/marketplace/plugins/litcodex/skills/lit-pptx/templates/tonalities/atlas/pack.yaml +1 -1
  195. package/marketplace/plugins/litcodex/skills/lit-pptx/templates/tonalities/bauhaus/pack.yaml +98 -0
  196. package/marketplace/plugins/litcodex/skills/lit-pptx/templates/tonalities/chalk/pack.yaml +1 -1
  197. package/marketplace/plugins/litcodex/skills/lit-pptx/templates/tonalities/computational-brutalism/pack.yaml +100 -0
  198. package/marketplace/plugins/litcodex/skills/lit-pptx/templates/tonalities/gazette/pack.yaml +1 -1
  199. package/marketplace/plugins/litcodex/skills/lit-pptx/templates/tonalities/ledger/pack.yaml +1 -1
  200. package/marketplace/plugins/litcodex/skills/lit-pptx/templates/tonalities/neo-brutalism/pack.yaml +107 -0
  201. package/marketplace/plugins/litcodex/skills/lit-pptx/templates/tonalities/newsroom/pack.yaml +99 -0
  202. package/marketplace/plugins/litcodex/skills/lit-pptx/templates/tonalities/night/pack.yaml +1 -1
  203. package/marketplace/plugins/litcodex/skills/lit-pptx/templates/tonalities/paper/pack.yaml +1 -1
  204. package/marketplace/plugins/litcodex/skills/lit-pptx/templates/tonalities/riso/pack.yaml +99 -0
  205. package/marketplace/plugins/litcodex/skills/lit-pptx/templates/tonalities/signal/pack.yaml +2 -2
  206. package/marketplace/plugins/litcodex/skills/lit-pptx/templates/tonalities/studio/pack.yaml +1 -1
  207. package/marketplace/plugins/litcodex/skills/lit-recap/SKILL.md +2 -0
  208. package/marketplace/plugins/litcodex/skills/lit-schematic/SKILL.md +198 -0
  209. package/marketplace/plugins/litcodex/skills/lit-schematic/agents/openai.yaml +6 -0
  210. package/marketplace/plugins/litcodex/skills/lit-schematic/examples/iso-heat-exchanger/build.mjs +38 -0
  211. package/marketplace/plugins/litcodex/skills/lit-schematic/examples/iso-heat-exchanger/scene.mjs +133 -0
  212. package/marketplace/plugins/litcodex/skills/lit-schematic/examples/journal-adsorption-rig/build.mjs +87 -0
  213. package/marketplace/plugins/litcodex/skills/lit-schematic/examples/pid-dosing-skid/build.mjs +85 -0
  214. package/marketplace/plugins/litcodex/skills/lit-schematic/references/cutaway-outputs.md +70 -0
  215. package/marketplace/plugins/litcodex/skills/lit-schematic/references/isometric-craft.md +101 -0
  216. package/marketplace/plugins/litcodex/skills/lit-schematic/references/journal-figures.md +72 -0
  217. package/marketplace/plugins/litcodex/skills/lit-schematic/references/kit-api.md +134 -0
  218. package/marketplace/plugins/litcodex/skills/lit-schematic/references/pfd-and-layout.md +53 -0
  219. package/marketplace/plugins/litcodex/skills/lit-schematic/references/pid-drafting.md +103 -0
  220. package/marketplace/plugins/litcodex/skills/lit-schematic/references/pid-symbols.md +163 -0
  221. package/marketplace/plugins/litcodex/skills/lit-schematic/references/verification.md +100 -0
  222. package/marketplace/plugins/litcodex/skills/lit-schematic/scripts/doctor.mjs +57 -0
  223. package/marketplace/plugins/litcodex/skills/lit-schematic/scripts/lib/figure.mjs +81 -0
  224. package/marketplace/plugins/litcodex/skills/lit-schematic/scripts/lib/fonts.mjs +28 -0
  225. package/marketplace/plugins/litcodex/skills/lit-schematic/scripts/lib/geom.mjs +113 -0
  226. package/marketplace/plugins/litcodex/skills/lit-schematic/scripts/lib/interactive.mjs +292 -0
  227. package/marketplace/plugins/litcodex/skills/lit-schematic/scripts/lib/isa.mjs +115 -0
  228. package/marketplace/plugins/litcodex/skills/lit-schematic/scripts/lib/iso.mjs +719 -0
  229. package/marketplace/plugins/litcodex/skills/lit-schematic/scripts/lib/legend-sheet.mjs +162 -0
  230. package/marketplace/plugins/litcodex/skills/lit-schematic/scripts/lib/pid.mjs +937 -0
  231. package/marketplace/plugins/litcodex/skills/lit-schematic/scripts/lib/png.mjs +132 -0
  232. package/marketplace/plugins/litcodex/skills/lit-schematic/scripts/lib/qa-core.mjs +658 -0
  233. package/marketplace/plugins/litcodex/skills/lit-schematic/scripts/lib/route.mjs +218 -0
  234. package/marketplace/plugins/litcodex/skills/lit-schematic/scripts/lib/sheet.mjs +890 -0
  235. package/marketplace/plugins/litcodex/skills/lit-schematic/scripts/lib/svg.mjs +82 -0
  236. package/marketplace/plugins/litcodex/skills/lit-schematic/scripts/lib/theme.mjs +115 -0
  237. package/marketplace/plugins/litcodex/skills/lit-schematic/scripts/motion.mjs +129 -0
  238. package/marketplace/plugins/litcodex/skills/lit-schematic/scripts/qa.mjs +92 -0
  239. package/marketplace/plugins/litcodex/skills/lit-schematic/scripts/render.mjs +233 -0
  240. package/marketplace/plugins/litcodex/skills/lit-schematic/scripts/scaffold.mjs +60 -0
  241. package/marketplace/plugins/litcodex/skills/lit-scientific-visualization/SKILL.md +34 -8
  242. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/SKILL.md +18 -14
  243. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/THIRD_PARTY_NOTICES +12 -0
  244. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/assets.mjs +388 -0
  245. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/blender/runner.py +221 -0
  246. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/blender.mjs +132 -0
  247. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/board.mjs +142 -0
  248. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/constants.mjs +6 -0
  249. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/cover-assets.mjs +7 -4
  250. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/cover-capture.mjs +8 -7
  251. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/cover-init.js +14 -2
  252. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/cover-treatment.mjs +38 -3
  253. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/cover.mjs +19 -4
  254. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/driver.mjs +8 -8
  255. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/gallery.mjs +147 -0
  256. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/house.mjs +45 -0
  257. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/image.mjs +89 -0
  258. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/look.mjs +58 -25
  259. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/runtime.mjs +59 -14
  260. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/safe-read.mjs +32 -0
  261. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/scaffold.mjs +208 -0
  262. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/score.mjs +668 -0
  263. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/sound.mjs +174 -31
  264. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/stage-gate.mjs +45 -3
  265. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/stage-kit.js +99 -1
  266. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/stage-qa.js +8 -1
  267. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/stage-qa.mjs +180 -11
  268. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/stage-render.mjs +42 -12
  269. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/stage-worker.mjs +7 -4
  270. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/stage.mjs +96 -10
  271. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/styles.mjs +233 -0
  272. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/treatment.mjs +291 -14
  273. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/vendor/three/LICENSE +21 -0
  274. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/vendor/three/addons/environments/RoomEnvironment.js +144 -0
  275. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/vendor/three/addons/geometries/RoundedBoxGeometry.js +155 -0
  276. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/vendor/three/three.module.js +54571 -0
  277. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/recipes/hero-3d/expected.json +33 -0
  278. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/recipes/hero-3d/index.html +139 -0
  279. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/references/cover.md +44 -7
  280. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/references/depth.md +156 -0
  281. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/references/design-choice.md +22 -0
  282. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/references/quality-gate.md +29 -7
  283. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/references/runtime.md +1 -1
  284. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/references/sound.md +87 -0
  285. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/references/stage.md +19 -7
  286. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/references/studio.md +246 -0
  287. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/references/style-bibles.md +2 -2
  288. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/references/treatment.md +41 -21
  289. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/scripts/render.mjs +51 -4
  290. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/styles/paper.json +185 -0
  291. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/styles/swiss-signal.json +188 -0
  292. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/styles/terminalcore.json +182 -0
  293. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/styles/tidal.json +187 -0
  294. package/marketplace/plugins/litcodex/skills/litresearch/SKILL.md +7 -0
  295. package/marketplace/plugins/litcodex/skills/litwork/SKILL.md +2 -1
  296. package/marketplace/plugins/litcodex/skills/readme-studio/SKILL.md +10 -0
  297. package/marketplace/plugins/litcodex/skills/review-work/SKILL.md +7 -1
  298. package/marketplace/plugins/litcodex/skills/start-work/SKILL.md +11 -1
  299. package/node_modules/@litcodex/lit-loop/directive.md +10 -4
  300. package/node_modules/@litcodex/lit-loop/directives/lit-adhd.md +194 -0
  301. package/node_modules/@litcodex/lit-loop/directives/lit-handoff.md +2 -0
  302. package/node_modules/@litcodex/lit-loop/directives/lit-hijack.md +219 -0
  303. package/node_modules/@litcodex/lit-loop/directives/lit-plan.md +2 -1
  304. package/node_modules/@litcodex/lit-loop/directives/lit-recap.md +2 -0
  305. package/node_modules/@litcodex/lit-loop/directives/lit-schematic.md +199 -0
  306. package/node_modules/@litcodex/lit-loop/directives/litwork.md +2 -1
  307. package/node_modules/@litcodex/lit-loop/dist/adhd-suggest.d.ts +10 -0
  308. package/node_modules/@litcodex/lit-loop/dist/adhd-suggest.js +67 -0
  309. package/node_modules/@litcodex/lit-loop/dist/card-html.d.ts +1 -1
  310. package/node_modules/@litcodex/lit-loop/dist/card-html.js +128 -8
  311. package/node_modules/@litcodex/lit-loop/dist/card-looks.d.ts +19 -0
  312. package/node_modules/@litcodex/lit-loop/dist/card-looks.js +58 -0
  313. package/node_modules/@litcodex/lit-loop/dist/card-status.d.ts +30 -0
  314. package/node_modules/@litcodex/lit-loop/dist/card-status.js +97 -7
  315. package/node_modules/@litcodex/lit-loop/dist/cli.js +13 -3
  316. package/node_modules/@litcodex/lit-loop/dist/codex-hook.d.ts +2 -0
  317. package/node_modules/@litcodex/lit-loop/dist/codex-hook.js +8 -9
  318. package/node_modules/@litcodex/lit-loop/dist/control-chars.d.ts +5 -0
  319. package/node_modules/@litcodex/lit-loop/dist/control-chars.js +23 -0
  320. package/node_modules/@litcodex/lit-loop/dist/hook-cli.d.ts +8 -0
  321. package/node_modules/@litcodex/lit-loop/dist/hook-cli.js +126 -13
  322. package/node_modules/@litcodex/lit-loop/dist/hud.d.ts +1 -1
  323. package/node_modules/@litcodex/lit-loop/dist/hud.js +29 -13
  324. package/node_modules/@litcodex/lit-loop/dist/lane-events.d.ts +13 -0
  325. package/node_modules/@litcodex/lit-loop/dist/lane-events.js +85 -0
  326. package/node_modules/@litcodex/lit-loop/dist/lane-state.d.ts +55 -0
  327. package/node_modules/@litcodex/lit-loop/dist/lane-state.js +227 -0
  328. package/node_modules/@litcodex/lit-loop/dist/live-step.d.ts +5 -1
  329. package/node_modules/@litcodex/lit-loop/dist/live-step.js +17 -1
  330. package/node_modules/@litcodex/lit-loop/dist/markers.d.ts +6 -0
  331. package/node_modules/@litcodex/lit-loop/dist/markers.js +6 -0
  332. package/node_modules/@litcodex/lit-loop/dist/modes.d.ts +1 -1
  333. package/node_modules/@litcodex/lit-loop/dist/modes.js +25 -1
  334. package/node_modules/@litcodex/lit-loop/dist/motion-gate.d.ts +79 -0
  335. package/node_modules/@litcodex/lit-loop/dist/motion-gate.js +310 -0
  336. package/node_modules/@litcodex/lit-loop/dist/motion-route.js +5 -1
  337. package/node_modules/@litcodex/lit-loop/dist/plan-persistence.d.ts +1 -1
  338. package/node_modules/@litcodex/lit-loop/dist/plan-persistence.js +38 -2
  339. package/node_modules/@litcodex/lit-loop/dist/plan-scope-roots.d.ts +7 -0
  340. package/node_modules/@litcodex/lit-loop/dist/plan-scope-roots.js +76 -0
  341. package/node_modules/@litcodex/lit-loop/dist/redaction.js +18 -0
  342. package/node_modules/@litcodex/lit-loop/dist/reentry.d.ts +15 -0
  343. package/node_modules/@litcodex/lit-loop/dist/reentry.js +46 -9
  344. package/node_modules/@litcodex/lit-loop/dist/restart-chip.d.ts +6 -0
  345. package/node_modules/@litcodex/lit-loop/dist/restart-chip.js +59 -0
  346. package/node_modules/@litcodex/lit-loop/dist/rewind-cli.d.ts +10 -0
  347. package/node_modules/@litcodex/lit-loop/dist/rewind-cli.js +88 -0
  348. package/node_modules/@litcodex/lit-loop/dist/rewind-go.d.ts +20 -0
  349. package/node_modules/@litcodex/lit-loop/dist/rewind-go.js +94 -0
  350. package/node_modules/@litcodex/lit-loop/dist/rewind-look.d.ts +6 -0
  351. package/node_modules/@litcodex/lit-loop/dist/rewind-look.js +41 -0
  352. package/node_modules/@litcodex/lit-loop/dist/rewind-redact.d.ts +3 -0
  353. package/node_modules/@litcodex/lit-loop/dist/rewind-redact.js +40 -0
  354. package/node_modules/@litcodex/lit-loop/dist/rewind-rollout.d.ts +48 -0
  355. package/node_modules/@litcodex/lit-loop/dist/rewind-rollout.js +292 -0
  356. package/node_modules/@litcodex/lit-loop/dist/rewind.d.ts +168 -0
  357. package/node_modules/@litcodex/lit-loop/dist/rewind.js +867 -0
  358. package/node_modules/@litcodex/lit-loop/dist/route-heads.js +45 -3
  359. package/node_modules/@litcodex/lit-loop/dist/run-panel.js +1 -0
  360. package/node_modules/@litcodex/lit-loop/dist/schematic-route.d.ts +6 -0
  361. package/node_modules/@litcodex/lit-loop/dist/schematic-route.js +35 -0
  362. package/node_modules/@litcodex/lit-loop/dist/screen-card.d.ts +3 -0
  363. package/node_modules/@litcodex/lit-loop/dist/screen-card.js +15 -5
  364. package/node_modules/@litcodex/lit-loop/dist/session-liveness.d.ts +16 -0
  365. package/node_modules/@litcodex/lit-loop/dist/session-liveness.js +90 -0
  366. package/node_modules/@litcodex/lit-loop/dist/skill-mention-scope.js +6 -0
  367. package/node_modules/@litcodex/lit-loop/dist/stack-hook.d.ts +8 -0
  368. package/node_modules/@litcodex/lit-loop/dist/stack-hook.js +57 -0
  369. package/node_modules/@litcodex/lit-loop/dist/statusline.js +8 -3
  370. package/node_modules/@litcodex/lit-loop/dist/threads.d.ts +50 -0
  371. package/node_modules/@litcodex/lit-loop/dist/threads.js +183 -0
  372. package/node_modules/@litcodex/lit-loop/dist/trigger.d.ts +1 -1
  373. package/node_modules/@litcodex/lit-loop/dist/trigger.js +29 -5
  374. package/node_modules/@litcodex/lit-loop/dist/workflow-map.d.ts +10 -0
  375. package/node_modules/@litcodex/lit-loop/dist/workflow-map.js +11 -1
  376. package/node_modules/@litcodex/lit-loop/dist/workflow-stack.d.ts +139 -0
  377. package/node_modules/@litcodex/lit-loop/dist/workflow-stack.js +518 -0
  378. package/node_modules/@litcodex/lit-loop/package.json +1 -1
  379. package/node_modules/@litcodex/lit-loop/skills/lit-adhd/SKILL.md +185 -0
  380. package/node_modules/@litcodex/lit-loop/skills/lit-hijack/SKILL.md +449 -0
  381. package/node_modules/@litcodex/lit-loop/skills/lit-loop/SKILL.md +13 -4
  382. package/node_modules/@litcodex/lit-loop/skills/lit-plan/SKILL.md +9 -2
  383. package/node_modules/@litcodex/lit-loop/skills/lit-recap/SKILL.md +2 -0
  384. package/node_modules/@litcodex/lit-loop/skills/lit-schematic/SKILL.md +198 -0
  385. package/node_modules/@litcodex/lit-loop/skills/lit-scientific-visualization/SKILL.md +34 -8
  386. package/node_modules/@litcodex/lit-loop/skills/litresearch/SKILL.md +7 -0
  387. package/node_modules/@litcodex/lit-loop/skills/litwork/SKILL.md +2 -1
  388. package/node_modules/@litcodex/lit-loop/skills/review-work/SKILL.md +7 -1
  389. package/node_modules/@litcodex/lit-loop/skills/start-work/SKILL.md +11 -1
  390. package/package.json +3 -2
  391. package/readme-assets/badge-version.svg +1 -1
  392. package/readme-assets/skills/lit-adhd.webp +0 -0
  393. package/readme-assets/skills/lit-hijack.webp +0 -0
  394. package/readme-assets/skills/lit-schematic.webp +0 -0
@@ -0,0 +1,867 @@
1
+ // src/rewind.ts — the lit-adhd collector: where the work stands across sessions and worktrees.
2
+ //
3
+ // Reads Codex session records (rewind-rollout.ts), `git worktree list`, and each worktree's own saved
4
+ // state (workflow stacks, the start-work record, plan checkboxes, lit-loop goals, a HANDOFF heading). It
5
+ // writes one file, the next-step note `.litcodex/adhd/next-<session>.json` that a following `go` consumes,
6
+ // and nothing else. Every string that leaves is redacted and stripped of control characters; a source it
7
+ // cannot read is named `unknown` instead of guessed. The brief itself is composed by the model from the
8
+ // JSON; `renderBrief` is the Markdown draft of the same parts: a three-line opener (done so far, doing now, next),
9
+ // session cards, one table row for each ended session, a roadmap and one boxed next step.
10
+ import { execFileSync } from "node:child_process";
11
+ import { existsSync, lstatSync, mkdirSync, readdirSync, readFileSync, rmSync } from "node:fs";
12
+ import { homedir } from "node:os";
13
+ import { basename, isAbsolute, join, relative } from "node:path";
14
+ import { clean, cleanDeep, cleanLines } from "./control-chars.js";
15
+ import { displayWidth, fit } from "./hud.js";
16
+ import { codexHomeFrom, plainDirsOrMissing, readSmallJson, writeFileAtomic } from "./live-step.js";
17
+ import { makeRedactor } from "./rewind-redact.js";
18
+ import { listRollouts, newBudget, readRollout, TOTAL_BYTES, } from "./rewind-rollout.js";
19
+ import { readLiveness } from "./session-liveness.js";
20
+ import { normalizeSessionId } from "./state-paths.js";
21
+ import { countPlanRows, planProgress, planRows, readWorkflowSignals } from "./workflow-map.js";
22
+ import { frameLabel, frameNote, pausedSpine, readStack, STACK_DIR, stackGauge, } from "./workflow-stack.js";
23
+ export const ADHD_DIR = ".litcodex/adhd";
24
+ /** A session written to in the last quarter hour is still running. */
25
+ export const ACTIVE_MS = 15 * 60 * 1000;
26
+ /** How long a briefed next step stays runnable by `go`. */
27
+ export const GO_WINDOW_MS = 30 * 60 * 1000;
28
+ export const DEFAULT_SINCE_MS = 7 * 24 * 60 * 60 * 1000;
29
+ export const DEFAULT_MAX = 12;
30
+ const MAX_WORKTREES = 12;
31
+ const MAX_STATE_BYTES = 1_000_000;
32
+ const MAX_HANDOFF_BYTES = 16 * 1024;
33
+ const GIT_TIMEOUT_MS = 3000;
34
+ export const runGit = (cwd, args) => {
35
+ try {
36
+ return execFileSync("git", ["-C", cwd, ...args], {
37
+ encoding: "utf8",
38
+ timeout: GIT_TIMEOUT_MS,
39
+ stdio: ["ignore", "pipe", "ignore"],
40
+ env: { ...process.env, GIT_OPTIONAL_LOCKS: "0" },
41
+ maxBuffer: 1_000_000,
42
+ });
43
+ }
44
+ catch {
45
+ return null;
46
+ }
47
+ };
48
+ /** `7d`, `36h`, `90m` as milliseconds; null for anything else. */
49
+ export function parseSince(text) {
50
+ const match = /^(\d{1,4})([dhm])$/u.exec(text.trim());
51
+ if (match?.[1] === undefined || match[2] === undefined)
52
+ return null;
53
+ const unit = match[2] === "d" ? 86_400_000 : match[2] === "h" ? 3_600_000 : 60_000;
54
+ return Number(match[1]) * unit;
55
+ }
56
+ function isRecord(value) {
57
+ return typeof value === "object" && value !== null && !Array.isArray(value);
58
+ }
59
+ function insideDir(path, dir) {
60
+ const rel = relative(dir, path);
61
+ return rel === "" || (!rel.startsWith("..") && !isAbsolute(rel));
62
+ }
63
+ // ── Sessions ─────────────────────────────────────────────────────────────────
64
+ /** The last words ask the person something: a closing question, or a request to approve, confirm or deny. */
65
+ const ASKS = /[??]\s*$|`?lit approve`?|`?lit deny`?|승인해\s*주|확인해\s*주|괜찮을까요|할까요/iu;
66
+ function statusOf(facts, mtimeMs, now) {
67
+ const last = facts.lastAt ?? mtimeMs;
68
+ if (facts.last === null && facts.lastAt === null)
69
+ return "unknown";
70
+ // A turn that has finished and asks something no longer runs, however recent it is.
71
+ if (facts.last === "complete" && ASKS.test(facts.lastAgent ?? ""))
72
+ return "waiting-on-user";
73
+ if (now - Math.max(last, mtimeMs) < ACTIVE_MS)
74
+ return "active";
75
+ // A finished turn that asks nothing is history, not something that waits.
76
+ if ((facts.last === "complete" || facts.last === "agent") && ASKS.test(facts.lastAgent ?? ""))
77
+ return "waiting-on-user";
78
+ return "ended";
79
+ }
80
+ function snippet(redact, text, width) {
81
+ if (text === null)
82
+ return null;
83
+ const flat = clean(redact(text)).replace(/\s+/gu, " ").trim();
84
+ return flat === "" ? null : fit(flat, width);
85
+ }
86
+ /** UUIDv7 ids open with a timestamp, so sessions started minutes apart share the first 8 characters; use the random tail then. */
87
+ export function shortIdOf(id) {
88
+ return /^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-/iu.test(id) ? id.slice(-8) : id.slice(0, 8);
89
+ }
90
+ function worktreesOf(folders, git) {
91
+ const trees = new Map();
92
+ let gitState = "ok";
93
+ const listed = new Set();
94
+ for (const folder of folders) {
95
+ if (!existsSync(folder))
96
+ continue;
97
+ if ([...trees.keys()].some((known) => insideDir(folder, known)))
98
+ continue;
99
+ const top = git(folder, ["rev-parse", "--show-toplevel"]);
100
+ if (top === null) {
101
+ // A folder that is simply not a repository is not a git failure; only a git that cannot run is.
102
+ if (git(folder, ["--version"]) === null)
103
+ gitState = "unknown";
104
+ if (!trees.has(folder))
105
+ trees.set(folder, { path: folder, branch: null });
106
+ continue;
107
+ }
108
+ const root = top.trim();
109
+ if (listed.has(root))
110
+ continue;
111
+ listed.add(root);
112
+ const porcelain = git(root, ["worktree", "list", "--porcelain"]);
113
+ if (porcelain === null) {
114
+ trees.set(root, { path: root, branch: null });
115
+ continue;
116
+ }
117
+ for (const block of porcelain.split(/\n\n+/u)) {
118
+ const path = /^worktree (.+)$/mu.exec(block)?.[1];
119
+ if (path === undefined)
120
+ continue;
121
+ const branch = /^branch refs\/heads\/(.+)$/mu.exec(block)?.[1] ?? null;
122
+ trees.set(path, { path, branch });
123
+ listed.add(path);
124
+ }
125
+ }
126
+ // A repo with many worktrees must not push the folders the sessions ran in past the cap.
127
+ const holds = (tree) => folders.some((folder) => insideDir(folder, tree.path));
128
+ const ordered = [...trees.values()];
129
+ return {
130
+ trees: [...ordered.filter(holds), ...ordered.filter((tree) => !holds(tree))].slice(0, MAX_WORKTREES),
131
+ gitState,
132
+ };
133
+ }
134
+ function listDir(dir, suffix, limit) {
135
+ try {
136
+ const lst = lstatSync(dir);
137
+ if (!lst.isDirectory())
138
+ return [];
139
+ return readdirSync(dir)
140
+ .filter((name) => name.endsWith(suffix))
141
+ .sort()
142
+ .slice(0, limit);
143
+ }
144
+ catch {
145
+ return [];
146
+ }
147
+ }
148
+ /** A plan scaffold nobody filled in: a row that is still a `<placeholder>`, or every row the same. */
149
+ function isTemplate(rows) {
150
+ return (rows.some((row) => /<[^<>]{1,40}>/u.test(row.label)) ||
151
+ (rows.length > 1 && new Set(rows.map((row) => row.label.trim())).size === 1));
152
+ }
153
+ function plansOf(path) {
154
+ const scan = { open: [], finished: [], skipped: [] };
155
+ if (!plainDirsOrMissing(path, ".litcodex/plans"))
156
+ return scan;
157
+ for (const file of listDir(join(path, ".litcodex/plans"), ".md", 40)) {
158
+ try {
159
+ const full = join(path, ".litcodex/plans", file);
160
+ const stat = lstatSync(full);
161
+ if (!stat.isFile())
162
+ continue;
163
+ if (stat.size > MAX_STATE_BYTES) {
164
+ scan.skipped.push({ name: file, done: 0, total: 0, gauge: null, changedMs: stat.mtimeMs });
165
+ continue;
166
+ }
167
+ const text = readFileSync(full, "utf8");
168
+ const rows = countPlanRows(text);
169
+ if (rows.total === 0 || isTemplate(planRows(text)))
170
+ continue;
171
+ const plan = {
172
+ name: file,
173
+ done: rows.done,
174
+ total: rows.total,
175
+ gauge: stackGauge({ n: rows.done, total: rows.total }),
176
+ changedMs: stat.mtimeMs,
177
+ };
178
+ (rows.done < rows.total ? scan.open : scan.finished).push(plan);
179
+ }
180
+ catch {
181
+ // An unreadable plan is left out.
182
+ }
183
+ }
184
+ return scan;
185
+ }
186
+ function openPlansOf(path) {
187
+ return plansOf(path).open;
188
+ }
189
+ /** The open plan `name` (a file under `.litcodex/plans`), or null when it is finished, a scaffold or missing. */
190
+ export function openPlanNamed(cwd, name) {
191
+ return openPlansOf(cwd).find((plan) => plan.name === name) ?? null;
192
+ }
193
+ function pausedFramesOf(path) {
194
+ if (!plainDirsOrMissing(path, STACK_DIR))
195
+ return [];
196
+ const out = [];
197
+ for (const file of listDir(join(path, STACK_DIR), ".json", 20)) {
198
+ const session = file.slice(0, -".json".length);
199
+ for (const frame of readStack(path, session).frames)
200
+ if (frame.status === "paused")
201
+ out.push({ session, frame });
202
+ }
203
+ return out;
204
+ }
205
+ /** The first 16 KiB of this folder's HANDOFF note, or null. */
206
+ function handoffText(path) {
207
+ for (const name of listDir(path, ".md", 200)
208
+ .filter((file) => /^HANDOFF/iu.test(file))
209
+ .slice(0, 1)) {
210
+ try {
211
+ const full = join(path, name);
212
+ const stat = lstatSync(full);
213
+ if (!stat.isFile())
214
+ continue;
215
+ return readFileSync(full, "utf8").slice(0, MAX_HANDOFF_BYTES);
216
+ }
217
+ catch {
218
+ return null;
219
+ }
220
+ }
221
+ return null;
222
+ }
223
+ function handoffHeading(path) {
224
+ const text = handoffText(path);
225
+ return text === null ? null : (/^#{1,3}\s+(.+)$/mu.exec(text)?.[1]?.trim() ?? null);
226
+ }
227
+ /** The first item under the HANDOFF note's `## Next` that is not ticked off, or null. */
228
+ function handoffNext(path) {
229
+ const text = handoffText(path);
230
+ const body = text === null ? undefined : /^##\s+Next\b[^\n]*\n([\s\S]*?)(?=^#{1,2}\s|(?![\s\S]))/imu.exec(text)?.[1];
231
+ for (const line of (body ?? "").split("\n")) {
232
+ if (/^\s*[-*+]\s+\[[xX]\]/u.test(line))
233
+ continue;
234
+ const item = line
235
+ .replace(/^\s*(?:[-*+]|\d+[.)])\s+(?:\[ \]\s+)?/u, "")
236
+ .replace(/\s+/gu, " ")
237
+ .trim();
238
+ if (item !== "")
239
+ return fit(item, 160);
240
+ }
241
+ return null;
242
+ }
243
+ /** The session finished what it ran: its top frame is a closed start-work, or the plan it carries is all ticked. */
244
+ function sessionFinished(cwd, sessionId) {
245
+ const top = readStack(cwd, sessionId).frames.at(-1);
246
+ if (top === undefined)
247
+ return false;
248
+ if (top.done === true && (top.skill === "start-work" || top.skill === "litwork"))
249
+ return true;
250
+ const plan = top.ref === undefined ? null : planProgress(cwd, top.ref.plan);
251
+ return plan !== null && plan.done >= plan.total;
252
+ }
253
+ // ── Session and timeline words ───────────────────────────────────────────────
254
+ /** `6m`, `2h 5m`, `3d` for a length of time. */
255
+ function spanWords(ms) {
256
+ const minutes = Math.max(1, Math.round(ms / 60_000));
257
+ if (minutes < 60)
258
+ return `${minutes}m`;
259
+ if (minutes < 48 * 60)
260
+ return minutes % 60 === 0 ? `${minutes / 60}h` : `${Math.floor(minutes / 60)}h ${minutes % 60}m`;
261
+ return `${Math.round(minutes / 1440)}d`;
262
+ }
263
+ /** What a session's records show, in words: `12 steps · 4m · last: apply_patch`. Empty when they show nothing. */
264
+ function sessionFacts(facts, redact) {
265
+ const parts = [];
266
+ if (facts.steps > 0)
267
+ parts.push(`${facts.steps}${facts.stepsPartial ? "+" : ""} step${facts.steps === 1 ? "" : "s"}`);
268
+ if (facts.startedAt !== null && facts.lastAt !== null && facts.lastAt > facts.startedAt)
269
+ parts.push(spanWords(facts.lastAt - facts.startedAt));
270
+ if (facts.lastTool !== null)
271
+ parts.push(`last: ${clean(redact(facts.lastTool))}`);
272
+ return parts.join(" · ");
273
+ }
274
+ /** What this session needs from the person, in plain words. */
275
+ function needsOf(status, doing) {
276
+ if (status === "waiting-on-user")
277
+ return "answer its question";
278
+ if (status === "done")
279
+ return "review what it finished";
280
+ if (status === "idle")
281
+ return "its turn is over; it waits for your next message";
282
+ if (status === "active")
283
+ return doing === null ? "nothing yet; it is still working" : `now: ${doing}`;
284
+ if (status === "ended")
285
+ return "pick it up again, or leave it";
286
+ return "unknown; open it to see";
287
+ }
288
+ /** What a session reported, else what it did without a report: files edited, or the tools it used most. */
289
+ function doneOf(facts, lastAgent, tools, redact) {
290
+ if (lastAgent !== null)
291
+ return lastAgent;
292
+ if (facts.edited.length > 0) {
293
+ const names = facts.edited.slice(0, 3).map((name) => clean(redact(name)));
294
+ return `edited ${plural(facts.edited.length, "file")}${facts.stepsPartial ? " or more" : ""}: ${names.join(", ")}`;
295
+ }
296
+ return tools.length > 0 ? `no edits yet; used ${tools.join(", ")}` : null;
297
+ }
298
+ const OPEN_ROWS_SHOWN = 2;
299
+ /** A worktree's timeline: recent commits (done, dated), the step under way, then the next open plan rows. */
300
+ function milestonesOf(path, git, paused, plans, now) {
301
+ const out = [];
302
+ const log = git(path, ["log", "-3", "--format=%cs%x09%s"]);
303
+ if (log !== null) {
304
+ const commits = log
305
+ .split("\n")
306
+ .map((line) => /^(\d{4}-\d{2}-\d{2})\t(.+)$/u.exec(line))
307
+ .filter((match) => match !== null)
308
+ .map((match) => ({ state: "done", label: match[2] ?? "", date: match[1] ?? null }))
309
+ .reverse();
310
+ out.push(...commits);
311
+ }
312
+ const today = new Date(now).toISOString().slice(0, 10);
313
+ for (const label of paused)
314
+ out.push({ state: "now", label: `paused: ${label}`, date: today });
315
+ const rows = [];
316
+ for (const plan of plans.slice(0, 1)) {
317
+ try {
318
+ const full = join(path, ".litcodex/plans", plan.name);
319
+ const stat = lstatSync(full);
320
+ if (!stat.isFile() || stat.size > MAX_STATE_BYTES)
321
+ continue;
322
+ for (const row of planRows(readFileSync(full, "utf8")))
323
+ rows.push({ ...row, plan: plan.name });
324
+ }
325
+ catch {
326
+ // An unreadable plan adds no rows.
327
+ }
328
+ }
329
+ const open = rows.filter((row) => !row.done);
330
+ const current = open[0];
331
+ if (current !== undefined && paused.length === 0)
332
+ out.push({ state: "now", label: current.label, date: today });
333
+ const ahead = paused.length === 0 ? open.slice(1) : open;
334
+ for (const row of ahead.slice(0, OPEN_ROWS_SHOWN))
335
+ out.push({ state: "later", label: row.label, date: null });
336
+ return out;
337
+ }
338
+ // ── Next step ────────────────────────────────────────────────────────────────
339
+ /** A paused start-work record waiting on a boundary answer, read from the workspace state file. */
340
+ function pendingBoundary(cwd) {
341
+ if (!plainDirsOrMissing(cwd, ".litcodex/start-work"))
342
+ return false;
343
+ const state = readSmallJson(join(cwd, ".litcodex/start-work/state.json"), MAX_STATE_BYTES);
344
+ if (!isRecord(state) || !isRecord(state["works"]))
345
+ return false;
346
+ return Object.values(state["works"])
347
+ .filter(isRecord)
348
+ .some((work) => work["status"] === "paused" && isRecord(work["pending_boundary"]));
349
+ }
350
+ /**
351
+ * The one step worth taking next, in priority order: the paused frame of this session's stack, then a boundary
352
+ * waiting for an answer (shown, never started), then work already under way, then the single open plan.
353
+ */
354
+ export function chooseNext(cwd, sessionId) {
355
+ return cleanDeep(chooseNextRaw(cwd, sessionId));
356
+ }
357
+ function chooseNextRaw(cwd, sessionId) {
358
+ if (sessionId !== null) {
359
+ const spine = pausedSpine(readStack(cwd, sessionId));
360
+ if (spine !== null) {
361
+ return {
362
+ kind: "resume-frame",
363
+ text: `resume the paused ${frameLabel(spine)} with \`lit continue\``,
364
+ skill: spine.skill ?? "work",
365
+ stage: spine.stage,
366
+ ...(spine.n === undefined ? {} : { n: spine.n }),
367
+ ...(spine.total === undefined ? {} : { total: spine.total }),
368
+ };
369
+ }
370
+ }
371
+ if (pendingBoundary(cwd)) {
372
+ return {
373
+ kind: "approve-boundary",
374
+ text: "start-work waits at a boundary: answer `lit approve` or `lit deny` yourself",
375
+ };
376
+ }
377
+ const signals = readWorkflowSignals(cwd, sessionId);
378
+ const work = signals.work;
379
+ if (work !== null && work.status !== "completed" && work.done < work.total) {
380
+ return {
381
+ kind: "continue-work",
382
+ text: `continue the ${work.status} start-work plan, ${work.done} of ${work.total} tasks done`,
383
+ };
384
+ }
385
+ if (signals.goals !== null && signals.goals.done < signals.goals.total) {
386
+ return {
387
+ kind: "continue-work",
388
+ text: `continue the open lit-loop goals, ${signals.goals.done} of ${signals.goals.total} done`,
389
+ };
390
+ }
391
+ const open = openPlansOf(cwd);
392
+ const only = open[0];
393
+ if (open.length === 1 && only !== undefined && (work === null || work.status === "completed")) {
394
+ return {
395
+ kind: "start-plan",
396
+ text: `start work on ${only.name}, ${only.done} of ${only.total} tasks done`,
397
+ plan: only.name,
398
+ };
399
+ }
400
+ const handoff = open.length === 0 ? handoffNext(cwd) : null;
401
+ if (handoff !== null)
402
+ return { kind: "handoff", text: `from the handoff: ${handoff}` };
403
+ return { kind: "none", text: "no single next step stands out; say what to work on" };
404
+ }
405
+ function nextPath(cwd, sessionId) {
406
+ const id = normalizeSessionId(sessionId);
407
+ return id === null || !isAbsolute(cwd) ? null : join(cwd, ADHD_DIR, `next-${id}.json`);
408
+ }
409
+ /** Save the briefed step for `go`, or remove a stale one when there is nothing to run. Never throws. */
410
+ export function writeNext(cwd, sessionId, next, now) {
411
+ const path = nextPath(cwd, sessionId);
412
+ if (path === null)
413
+ return;
414
+ try {
415
+ if (!plainDirsOrMissing(cwd, ADHD_DIR))
416
+ return;
417
+ if (next.kind === "none" || next.kind === "handoff") {
418
+ rmSync(path, { force: true });
419
+ return;
420
+ }
421
+ mkdirSync(join(cwd, ADHD_DIR), { recursive: true });
422
+ const record = { version: 1, sessionId, at: now, ...next };
423
+ writeFileAtomic(path, `${JSON.stringify(record)}\n`);
424
+ }
425
+ catch {
426
+ // Without the note `go` simply finds nothing to run.
427
+ }
428
+ }
429
+ // ── Collect ──────────────────────────────────────────────────────────────────
430
+ export function collectRewind(options) {
431
+ const now = options.now ?? Date.now();
432
+ const env = options.env;
433
+ const home = env["HOME"] ?? homedir();
434
+ const redact = makeRedactor(env, home);
435
+ const git = options.git ?? runGit;
436
+ const codexHome = options.codexHome ?? codexHomeFrom(env);
437
+ const sinceMs = options.sinceMs ?? DEFAULT_SINCE_MS;
438
+ const max = Math.max(1, Math.min(options.max ?? DEFAULT_MAX, 50));
439
+ const sessionId = options.sessionId === undefined || options.sessionId === null ? null : normalizeSessionId(options.sessionId);
440
+ const limit = options.budgetBytes ?? TOTAL_BYTES;
441
+ const budget = newBudget(limit);
442
+ let sessionsState = codexHome === null ? "unknown" : "ok";
443
+ const sessions = [];
444
+ if (codexHome !== null) {
445
+ const files = listRollouts(codexHome).filter((file) => now - file.mtimeMs <= sinceMs);
446
+ for (const file of files) {
447
+ if (sessions.length >= max)
448
+ break;
449
+ const facts = readRollout(file, budget);
450
+ if (facts === null) {
451
+ if (budget.exhausted)
452
+ break;
453
+ continue;
454
+ }
455
+ if (facts.subagent)
456
+ continue;
457
+ if (options.here === true && (facts.cwd === null || !insideDir(facts.cwd, options.cwd)))
458
+ continue;
459
+ const top = facts.cwd === null ? undefined : readStack(facts.cwd, facts.id).frames.at(-1);
460
+ const seen = statusOf(facts, file.mtimeMs, now);
461
+ // What the workspace recorded outranks a guess from the record's age: finished work, then a closed turn.
462
+ const status = facts.cwd !== null && sessionFinished(facts.cwd, facts.id)
463
+ ? "done"
464
+ : seen !== "waiting-on-user" &&
465
+ facts.cwd !== null &&
466
+ readLiveness(facts.cwd, facts.id, now)?.state === "idle"
467
+ ? "idle"
468
+ : seen;
469
+ const lastAgent = snippet(redact, facts.lastAgent, 160);
470
+ const gauge = stackGauge(top ?? {});
471
+ const noted = top === undefined ? "" : frameNote(top);
472
+ const facted = sessionFacts(facts, redact);
473
+ const tools = facts.tools.slice(0, 3).map(([name]) => clean(redact(name)));
474
+ const tool = facts.lastTool === null ? null : clean(redact(facts.lastTool));
475
+ const doing = tool === null ? null : facts.lastTarget === null ? tool : `${tool} “${clean(redact(facts.lastTarget))}”`;
476
+ sessions.push({
477
+ id: facts.id,
478
+ shortId: shortIdOf(facts.id),
479
+ current: sessionId !== null && normalizeSessionId(facts.id) === sessionId,
480
+ cwd: facts.cwd === null ? null : redact(facts.cwd),
481
+ status,
482
+ lastAt: facts.lastAt ?? file.mtimeMs,
483
+ tree: null,
484
+ gauge,
485
+ facts: [noted, facted].filter((part) => part !== "").join(" · "),
486
+ title: snippet(redact, facts.firstUser, 80),
487
+ lastUser: snippet(redact, facts.lastUser, 120),
488
+ lastAgent,
489
+ done: doneOf(facts, lastAgent, tools, redact),
490
+ needs: needsOf(status, doing),
491
+ tools,
492
+ edited: facts.edited.length,
493
+ doing,
494
+ });
495
+ }
496
+ if (files.length === 0 && listRollouts(codexHome).length === 0)
497
+ sessionsState = "unknown";
498
+ }
499
+ const folders = [
500
+ options.cwd,
501
+ ...sessions.flatMap((session) => {
502
+ const found = session.cwd === null ? undefined : session.cwd.replace(/^~(?=$|\/)/u, home);
503
+ return found === undefined ? [] : [found];
504
+ }),
505
+ ];
506
+ const unique = [...new Set(folders)].filter((folder) => isAbsolute(folder));
507
+ const { trees, gitState } = worktreesOf(unique, git);
508
+ const worktrees = trees.map((tree) => {
509
+ const signals = readWorkflowSignals(tree.path, null, now);
510
+ const subject = git(tree.path, ["log", "-1", "--format=%s"]);
511
+ const work = signals.work === null
512
+ ? null
513
+ : {
514
+ status: signals.work.status,
515
+ done: signals.work.done,
516
+ total: signals.work.total,
517
+ gauge: stackGauge({ n: signals.work.done, total: signals.work.total }),
518
+ };
519
+ const goals = signals.goals === null
520
+ ? null
521
+ : {
522
+ done: signals.goals.done,
523
+ total: signals.goals.total,
524
+ gauge: stackGauge({ n: signals.goals.done, total: signals.goals.total }),
525
+ };
526
+ // Every plan, this worktree's too, counts only if it changed inside the window.
527
+ const inWindow = (plan) => plan.changedMs !== null && now - plan.changedMs <= sinceMs;
528
+ const scan = plansOf(tree.path);
529
+ const openPlans = scan.open.filter(inWindow).slice(0, 4);
530
+ const pausedHere = pausedFramesOf(tree.path);
531
+ return {
532
+ path: redact(tree.path),
533
+ branch: tree.branch,
534
+ lastCommit: snippet(redact, subject, 80),
535
+ gauge: work?.gauge ?? goals?.gauge ?? null,
536
+ work,
537
+ goals,
538
+ openPlans,
539
+ finishedPlans: scan.finished
540
+ .filter(inWindow)
541
+ .map((plan) => plan.name)
542
+ .slice(0, 4),
543
+ skippedPlans: scan.skipped.filter(inWindow).length,
544
+ milestones: milestonesOf(tree.path, git, pausedHere.map(({ frame }) => redact(frameLabel(frame))), openPlans, now).map((milestone) => ({ ...milestone, label: snippet(redact, milestone.label, 80) ?? "" })),
545
+ paused: pausedHere.map(({ session, frame }) => ({
546
+ session: session.slice(0, 8),
547
+ label: frameLabel(frame),
548
+ })),
549
+ handoff: snippet(redact, handoffHeading(tree.path), 80),
550
+ };
551
+ });
552
+ const homed = (path) => path.replace(/^~(?=$|\/)/u, home);
553
+ const placed = sessions.map((session) => {
554
+ const where = session.cwd === null ? undefined : homed(session.cwd);
555
+ const owner = where === undefined
556
+ ? undefined
557
+ : [...worktrees]
558
+ .sort((a, b) => b.path.length - a.path.length)
559
+ .find((tree) => insideDir(where, homed(tree.path)));
560
+ return { ...session, tree: owner?.path ?? null };
561
+ });
562
+ const next = chooseNext(options.cwd, sessionId);
563
+ if (sessionId !== null)
564
+ writeNext(options.cwd, sessionId, next, now);
565
+ // Commit subjects, branch names, plan rows and names, goals and paths are record text: none of it may carry a control.
566
+ return cleanDeep({
567
+ generatedAt: new Date(now).toISOString(),
568
+ codexHome: codexHome === null ? null : redact(codexHome),
569
+ sessions: placed,
570
+ worktrees,
571
+ next,
572
+ suggestion: suggestionOf(placed, worktrees),
573
+ scope: { sinceMs, worktrees: worktrees.length },
574
+ sources: { sessions: sessionsState, git: gitState, state: "ok" },
575
+ budget: { limit, used: limit - budget.remaining, exhausted: budget.exhausted },
576
+ });
577
+ }
578
+ // ── Suggestion ───────────────────────────────────────────────────────────────
579
+ const homeless = (path) => (path === null ? "unknown" : basename(path));
580
+ /** The worktree folder a session runs in, else the folder it started in, as a short name. */
581
+ function placeOf(session) {
582
+ return homeless(session.tree ?? session.cwd);
583
+ }
584
+ /** The last sentence of a session's final words that ends in a question mark, clipped. */
585
+ function lastQuestion(text) {
586
+ const found = [...(text ?? "").matchAll(/[^.!?。?\n]{4,}[??]/gu)].at(-1)?.[0];
587
+ return found === undefined ? null : fit(found.replace(/\s+/gu, " ").trim(), 90);
588
+ }
589
+ /**
590
+ * The step to recommend when nothing can run on `go`, so the brief never ends on "nothing". In order: a session
591
+ * that waits on the user, a paused workflow, the open plan item of a worktree where a session is live, any
592
+ * open plan item, the latest other active session, the latest other ended one. It is shown, never recorded.
593
+ */
594
+ export function suggestionOf(sessions, worktrees) {
595
+ const others = sessions.filter((session) => !session.current);
596
+ const waiting = others.find((session) => session.status === "waiting-on-user");
597
+ if (waiting !== undefined) {
598
+ const question = lastQuestion(waiting.lastAgent);
599
+ return `answer ${waiting.shortId} in ${placeOf(waiting)}${question === null ? "" : `: “${question}”`}`;
600
+ }
601
+ // Finished work is reviewed, never picked up again as if it were still to do.
602
+ const finished = others.find((session) => session.status === "done");
603
+ if (finished !== undefined)
604
+ return `review what ${finished.shortId} finished in ${placeOf(finished)}: ${fit(finished.title ?? "no first request", 50)}`;
605
+ for (const tree of worktrees) {
606
+ const paused = tree.paused[0];
607
+ if (paused !== undefined)
608
+ return `resume ${paused.label} in ${paused.session} (${homeless(tree.path)})`;
609
+ }
610
+ const liveTrees = new Set(sessions
611
+ .filter((session) => session.status !== "ended" && session.status !== "done")
612
+ .map((session) => session.tree));
613
+ const withItem = worktrees
614
+ .filter((tree) => tree.openPlans.length > 0 && tree.milestones.some((item) => item.state === "now"))
615
+ .sort((a, b) => Number(liveTrees.has(b.path)) - Number(liveTrees.has(a.path)));
616
+ const tree = withItem[0];
617
+ const item = tree?.milestones.find((milestone) => milestone.state === "now");
618
+ if (tree !== undefined && item !== undefined)
619
+ return `next in ${tree.openPlans[0]?.name ?? "the open plan"} (${homeless(tree.path)}): ${item.label}`;
620
+ const active = others.find((session) => session.status === "active" || session.status === "idle");
621
+ if (active !== undefined)
622
+ return `check on ${active.shortId} in ${placeOf(active)} (${fit(active.title ?? "no first request", 50)})${active.doing === null ? "" : `, now ${active.doing}`}`;
623
+ const ended = others.find((session) => session.status === "ended");
624
+ if (ended !== undefined)
625
+ return `pick up ${ended.shortId} in ${placeOf(ended)}: ${fit(ended.title ?? "no first request", 50)}`;
626
+ return "no session or plan in this window: say what to start";
627
+ }
628
+ // ── Brief ────────────────────────────────────────────────────────────────────
629
+ function pad(text, width) {
630
+ const cut = fit(text, width);
631
+ return cut + " ".repeat(Math.max(0, width - displayWidth(cut)));
632
+ }
633
+ function ago(from, now) {
634
+ if (from === null)
635
+ return "a while ago";
636
+ const minutes = Math.max(0, Math.round((now - from) / 60_000));
637
+ if (minutes < 1)
638
+ return "just now";
639
+ if (minutes < 60)
640
+ return `${minutes}m ago`;
641
+ if (minutes < 48 * 60)
642
+ return `${Math.round(minutes / 60)}h ago`;
643
+ return `${Math.round(minutes / 1440)}d ago`;
644
+ }
645
+ /** The age in its largest unit only (`20m`, `14h`, `3d`), short enough for a table cell. */
646
+ function agoShort(from, now) {
647
+ if (from === null)
648
+ return "·";
649
+ const minutes = Math.max(0, Math.round((now - from) / 60_000));
650
+ if (minutes < 60)
651
+ return `${minutes}m`;
652
+ if (minutes < 48 * 60)
653
+ return `${Math.round(minutes / 60)}h`;
654
+ return `${Math.round(minutes / 1440)}d`;
655
+ }
656
+ const BADGE = {
657
+ "waiting-on-user": "🟡 **WAITS ON YOU**",
658
+ active: "🟢 **RUNNING**",
659
+ idle: "💤 **IDLE**",
660
+ done: "✅ **DONE**",
661
+ ended: "⚪ **ENDED**",
662
+ unknown: "⚫ **NO RECORD**",
663
+ };
664
+ const MARK = { done: "✓", now: "▶", later: "○" };
665
+ function plural(count, one, many = `${one}s`) {
666
+ return `${count} ${count === 1 ? one : many}`;
667
+ }
668
+ /** The headline's step: the recorded `next`, else the suggestion drawn from the records. */
669
+ function stepOf(result) {
670
+ return result.next.kind === "none" ? result.suggestion : result.next.text;
671
+ }
672
+ /** The opener's three parts: what is finished, what is under way, and the one next step. */
673
+ function openerOf(result) {
674
+ const count = (status) => result.sessions.filter((session) => session.status === status).length;
675
+ const plans = result.worktrees.reduce((sum, tree) => sum + tree.finishedPlans.length, 0);
676
+ const finished = [
677
+ plans > 0 ? `${plural(plans, "plan")} finished` : "",
678
+ count("done") > 0 ? `${plural(count("done"), "session")} done` : "",
679
+ ].filter((part) => part !== "");
680
+ const waiting = count("waiting-on-user");
681
+ const paused = result.worktrees.reduce((sum, tree) => sum + tree.paused.length, 0);
682
+ const doing = [
683
+ count("active") > 0 ? `${count("active")} running` : "",
684
+ count("idle") > 0 ? `${count("idle")} idle` : "",
685
+ paused > 0 ? `${paused} paused` : "",
686
+ ].filter((part) => part !== "");
687
+ if (doing.length === 0)
688
+ doing.push("nothing running");
689
+ doing.push(waiting === 0 ? "nothing waits on you" : `${waiting} ${waiting === 1 ? "waits" : "wait"} on you`);
690
+ return {
691
+ done: finished.length === 0 ? "nothing finished in this window" : finished.join(" · "),
692
+ doing: doing.join(" · "),
693
+ next: stepOf(result),
694
+ };
695
+ }
696
+ /** The three-line opener in plain words: done so far, doing now, next. */
697
+ export function briefHeadline(result) {
698
+ const opener = openerOf(result);
699
+ return [`done so far: ${opener.done}`, `doing now: ${opener.doing}`, `next: ${opener.next}`].join("\n");
700
+ }
701
+ // Markdown words: record text is inert data, so every character that would turn it into markup is neutralised.
702
+ const GAUGE = /\[[▉░]{1,10}\] \d+\/\d+/gu;
703
+ const bare = (text) => text.replace(/\s+/gu, " ").trim();
704
+ const escapeMd = (text) => text
705
+ .replace(/[<>`]/gu, (char) => (char === "<" ? "‹" : char === ">" ? "›" : "'"))
706
+ .replace(/[*|[\]\\]|(?<![\p{L}\p{N}])_|_(?![\p{L}\p{N}])/gu, (char) => `\\${char}`);
707
+ const code = (text) => `\`${bare(text).replaceAll("`", "'")}\``;
708
+ /** Record text as Markdown; a gauge inside it stays whole in a code span instead of being escaped. */
709
+ function rich(text) {
710
+ const flat = bare(text);
711
+ let out = "";
712
+ let from = 0;
713
+ for (const match of flat.matchAll(GAUGE)) {
714
+ out += escapeMd(flat.slice(from, match.index)) + code(match[0]);
715
+ from = match.index + match[0].length;
716
+ }
717
+ return out + escapeMd(flat.slice(from));
718
+ }
719
+ function sessionCard(session, now) {
720
+ const mark = session.current ? " · this session" : "";
721
+ const progress = [session.gauge === null ? "" : code(session.gauge), rich(session.facts)].filter((part) => part !== "");
722
+ const lines = [
723
+ `${BADGE[session.status]} · ${code(session.shortId)} · ${ago(session.lastAt, now)}${mark}`,
724
+ `**${rich(session.title ?? "no first request recorded")}**`,
725
+ `⏳ ${progress.length === 0 ? "no activity recorded" : progress.join(" · ")}`,
726
+ `✅ Done: ${session.done === null ? "nothing on record" : rich(session.done)}`,
727
+ `▶ Next: ${rich(session.needs)}`,
728
+ ];
729
+ return lines.map((line, index) => (index === 0 ? `- ${line}` : ` ${line}`)).join(" \n");
730
+ }
731
+ /** A worktree's roadmap; without a live session here, only when something in it is still open. */
732
+ function roadmapBlock(tree, live) {
733
+ const lines = [];
734
+ const gauge = tree.gauge === null ? "" : ` ${code(tree.gauge)}`;
735
+ const parts = [
736
+ tree.work === null
737
+ ? null
738
+ : `start-work ${rich(tree.work.status)}${tree.work.gauge === null ? "" : ` ${code(tree.work.gauge)}`}`,
739
+ tree.goals === null ? null : `goals${tree.goals.gauge === null ? "" : ` ${code(tree.goals.gauge)}`}`,
740
+ ...tree.openPlans.map((plan) => `plan ${code(plan.name)}${plan.gauge === null ? "" : ` ${code(plan.gauge)}`}`),
741
+ ...tree.finishedPlans.map((name) => `plan ${code(name)} finished`),
742
+ ].filter((part) => part !== null);
743
+ const open = parts.length > 0 || tree.milestones.some((item) => item.state !== "done");
744
+ if (!open && !(live && (tree.milestones.length > 0 || tree.handoff !== null)))
745
+ return lines;
746
+ lines.push(`🗺️ **Roadmap**${gauge}`, "");
747
+ if (parts.length > 0)
748
+ lines.push(`- 📌 open: ${parts.join(" · ")}`);
749
+ for (const milestone of tree.milestones) {
750
+ const when = milestone.date ?? (milestone.state === "later" ? "later" : "");
751
+ lines.push(`- ${MARK[milestone.state]} ${when === "" ? "" : `${code(when)} · `}${rich(milestone.label)}`);
752
+ }
753
+ if (tree.handoff !== null)
754
+ lines.push(`- 📝 handoff note: ${rich(tree.handoff)}`);
755
+ return lines;
756
+ }
757
+ const ENDED_ROWS = 8;
758
+ /** Ended sessions, one table row each, newest first: they are history, so no card. One line per row at 120 columns. */
759
+ export function endedTable(sessions, now, width = 96) {
760
+ const goalWidth = Math.max(16, Math.min(44, width - 74));
761
+ const cell = (text) => escapeMd(bare(text)) || "·";
762
+ const rows = sessions.slice(0, ENDED_ROWS).map((session) => {
763
+ const done = session.edited > 0 ? plural(session.edited, "file") : "·";
764
+ const place = fit(session.tree === null && session.cwd === null ? "unknown" : placeOf(session), 20);
765
+ return `| ${code(session.shortId)} | ${cell(place)} | ${cell(fit(bare(session.title ?? "no first request"), goalWidth))} | ${agoShort(session.lastAt, now)} | ${cell(done)} |`;
766
+ });
767
+ const more = sessions.length > ENDED_ROWS ? ["", `*…and ${sessions.length - ENDED_ROWS} more ended*`] : [];
768
+ return ["| id | where | goal | ago | done |", "|---|---|---|---|---|", ...rows, ...more];
769
+ }
770
+ /** A step cut at word breaks to the box, three lines at most, the last one clipped. */
771
+ function wrap(text, width, limit = 3) {
772
+ const out = [""];
773
+ for (const word of bare(text).split(" ")) {
774
+ const joined = out.at(-1) === "" ? word : `${out.at(-1)} ${word}`;
775
+ if (displayWidth(joined) <= width || out.at(-1) === "")
776
+ out[out.length - 1] = joined;
777
+ else
778
+ out.push(word);
779
+ }
780
+ const kept = out.slice(0, limit);
781
+ if (out.length > limit)
782
+ kept[limit - 1] = `${kept[limit - 1]} ${out.slice(limit).join(" ")}`;
783
+ return kept.map((line) => fit(line, width));
784
+ }
785
+ function nextBox(result, width) {
786
+ const inner = Math.min(Math.max(28, width - 4), 76);
787
+ const say = result.next.kind === "none"
788
+ ? "nothing runs on its own here: open that session, or say what to do"
789
+ : result.next.kind === "approve-boundary"
790
+ ? "answer `lit approve` or `lit deny` yourself"
791
+ : result.next.kind === "handoff"
792
+ ? "a step from the handoff note; `go` does not run it, so say what to do"
793
+ : "say `go` to run it";
794
+ const box = (text) => `│ ${pad(text, inner)} │`;
795
+ return [
796
+ "```",
797
+ `╭─ Recommended next step ${"─".repeat(Math.max(1, inner - 22))}╮`,
798
+ ...wrap(stepOf(result), inner).map(box),
799
+ ...wrap(say, inner, 2).map(box),
800
+ `╰${"─".repeat(inner + 2)}╯`,
801
+ "```",
802
+ ];
803
+ }
804
+ /** `7d`, `36h`, `90m` for the window read. */
805
+ function windowWords(ms) {
806
+ if (ms % 86_400_000 === 0)
807
+ return `${ms / 86_400_000}d`;
808
+ if (ms % 3_600_000 === 0)
809
+ return `${ms / 3_600_000}h`;
810
+ return `${Math.max(1, Math.round(ms / 60_000))}m`;
811
+ }
812
+ /**
813
+ * The brief as Markdown limited to what the Codex terminal draws: bold, emoji, lists, a table and a fenced box.
814
+ * Never `#` headings or `>` quotes, which it prints as raw marks. A three-line opener, a card for every session
815
+ * that has not ended, grouped by worktree with each worktree's roadmap (done ✓ with its date, now ▶, later ○), one table
816
+ * row for every ended session, and the one recommended next step in a box. A progress gauge appears only when
817
+ * both counts are real; otherwise the known facts are written out in words.
818
+ */
819
+ export function renderBrief(result, width = 96) {
820
+ const now = Date.parse(result.generatedAt);
821
+ const opener = openerOf(result);
822
+ const lines = [
823
+ `**✅ Done so far:** ${rich(opener.done)} `,
824
+ `**▶ Doing now:** ${rich(opener.doing)} `,
825
+ `**⏭ Next:** ${rich(opener.next)}`,
826
+ ];
827
+ lines.push(`*last ${windowWords(result.scope.sinceMs)} · ${plural(result.sessions.length, "session")} · ${plural(Math.max(1, result.scope.worktrees), "worktree")}*`);
828
+ if (result.sessions.length === 0)
829
+ lines.push("", "No Codex session records in range.");
830
+ const live = result.sessions.filter((session) => session.status !== "ended");
831
+ const ended = result.sessions.filter((session) => session.status === "ended");
832
+ const groups = new Map();
833
+ for (const session of live)
834
+ groups.set(session.tree ?? "", [...(groups.get(session.tree ?? "") ?? []), session]);
835
+ const known = new Set(result.worktrees.map((tree) => tree.path));
836
+ const order = [...result.worktrees.map((tree) => tree.path), ...[...groups.keys()].filter((key) => !known.has(key))];
837
+ for (const key of order) {
838
+ const tree = result.worktrees.find((candidate) => candidate.path === key);
839
+ const here = groups.get(key) ?? [];
840
+ const roadmap = tree === undefined ? [] : roadmapBlock(tree, here.length > 0);
841
+ if (here.length === 0 && roadmap.length === 0)
842
+ continue;
843
+ const name = tree === undefined ? "folder unknown" : escapeMd(basename(tree.path));
844
+ const branch = tree?.branch == null ? "" : `${code(tree.branch)} · `;
845
+ lines.push("", `🌿 ${branch}**${name}**`);
846
+ for (const session of here)
847
+ lines.push("", sessionCard(session, now));
848
+ if (roadmap.length > 0)
849
+ lines.push("", ...roadmap);
850
+ }
851
+ if (ended.length > 0)
852
+ lines.push("", `⚪ **Ended · ${ended.length}**`, "", ...endedTable(ended, now, width));
853
+ if (result.worktrees.length === 0 && result.sessions.length === 0)
854
+ lines.push("", "No worktree found.");
855
+ lines.push("", ...nextBox(result, width));
856
+ const unknown = Object.entries(result.sources)
857
+ .filter(([, state]) => state === "unknown")
858
+ .map(([name]) => name);
859
+ if (unknown.length > 0)
860
+ lines.push("", `*not readable: ${unknown.join(", ")}*`);
861
+ const skipped = result.worktrees.reduce((sum, tree) => sum + tree.skippedPlans, 0);
862
+ if (skipped > 0)
863
+ lines.push("", `*${skipped === 1 ? "1 plan" : `${skipped} plans`} too large to read, left out*`);
864
+ if (result.budget.exhausted)
865
+ lines.push("", "*older sessions were not read (read budget spent)*");
866
+ return cleanLines(lines.join("\n"));
867
+ }