@litfamily/litgravity 0.1.0 → 0.1.2

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 (248) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/README.md +72 -17
  3. package/README_ko-KR.md +72 -17
  4. package/package.json +1 -1
  5. package/plugin/hooks/lib/lanes.mjs +65 -0
  6. package/plugin/hooks/lib/motion.mjs +34 -5
  7. package/plugin/hooks/lib/reentry.mjs +7 -0
  8. package/plugin/hooks/lib/rewind/brief.mjs +332 -0
  9. package/plugin/hooks/lib/rewind/collect.mjs +328 -0
  10. package/plugin/hooks/lib/rewind/gauge.mjs +55 -0
  11. package/plugin/hooks/lib/rewind/next-step.mjs +77 -0
  12. package/plugin/hooks/lib/rewind/redact.mjs +60 -0
  13. package/plugin/hooks/lib/rewind/transcripts.mjs +211 -0
  14. package/plugin/hooks/lib/routes.mjs +79 -5
  15. package/plugin/hooks/lib/workflow-stack.mjs +213 -0
  16. package/plugin/hooks/post-tool-use.mjs +37 -1
  17. package/plugin/hooks/pre-invocation.mjs +91 -2
  18. package/plugin/hooks/session-start.mjs +26 -3
  19. package/plugin/hooks/stop.mjs +22 -2
  20. package/plugin/hud/looks.mjs +29 -0
  21. package/plugin/hud/render.mjs +234 -12
  22. package/plugin/plugin.json +1 -1
  23. package/plugin/skills/frontend-ui-ux/SKILL.md +12 -1
  24. package/plugin/skills/frontend-ui-ux/kit/components.css +417 -0
  25. package/plugin/skills/frontend-ui-ux/kit/fonts.json +22 -0
  26. package/plugin/skills/frontend-ui-ux/kit/layouts/landing.html +164 -0
  27. package/plugin/skills/frontend-ui-ux/kit/layouts/settings.html +114 -0
  28. package/plugin/skills/frontend-ui-ux/kit/layouts/workspace.html +115 -0
  29. package/plugin/skills/frontend-ui-ux/kit/styles/computational-brutalism.json +227 -0
  30. package/plugin/skills/frontend-ui-ux/kit/styles/field-notes.json +205 -0
  31. package/plugin/skills/frontend-ui-ux/kit/styles/graphite.json +200 -0
  32. package/plugin/skills/frontend-ui-ux/kit/styles/meadow.json +199 -0
  33. package/plugin/skills/frontend-ui-ux/kit/styles/neo-brutalism.json +222 -0
  34. package/plugin/skills/frontend-ui-ux/kit/ui.js +226 -0
  35. package/plugin/skills/frontend-ui-ux/references/house-styles.md +234 -0
  36. package/plugin/skills/frontend-ui-ux/scripts/design-lock.mjs +400 -0
  37. package/plugin/skills/frontend-ui-ux/scripts/interface-probe-lock.mjs +196 -0
  38. package/plugin/skills/frontend-ui-ux/scripts/interface-probe-page.mjs +30 -9
  39. package/plugin/skills/frontend-ui-ux/scripts/interface-probe-rules.mjs +20 -8
  40. package/plugin/skills/frontend-ui-ux/scripts/interface-probe.mjs +42 -9
  41. package/plugin/skills/frontend-ui-ux/scripts/pixel-art.mjs +60 -0
  42. package/plugin/skills/lit-adhd/SKILL.md +157 -0
  43. package/plugin/skills/lit-adhd/references/card-examples.md +101 -0
  44. package/plugin/skills/lit-adhd/references/status-taxonomy.md +32 -0
  45. package/plugin/skills/lit-adhd/scripts/rewind.mjs +5 -0
  46. package/plugin/skills/lit-diagram-drawer/SKILL.md +5 -3
  47. package/plugin/skills/lit-diagram-drawer/references/drawing-rules.md +1 -1
  48. package/plugin/skills/lit-diagram-drawer/references/style-guide.md +21 -12
  49. package/plugin/skills/lit-diagram-drawer/references/type-architecture.md +3 -3
  50. package/plugin/skills/lit-diagram-drawer/references/type-dependency.md +1 -1
  51. package/plugin/skills/lit-diagram-drawer/references/type-tree.md +3 -3
  52. package/plugin/skills/lit-diagram-drawer/references/type-wardley.md +1 -1
  53. package/plugin/skills/lit-diagram-drawer/scripts/diagram-craft-rules.mjs +1 -2
  54. package/plugin/skills/lit-diagram-drawer/scripts/visual-quality.mjs +1 -2
  55. package/plugin/skills/lit-docx/SKILL.md +3 -3
  56. package/plugin/skills/lit-handoff/SKILL.md +1 -0
  57. package/plugin/skills/lit-hijack/SKILL.md +263 -0
  58. package/plugin/skills/lit-hijack/references/capture-and-provenance.md +100 -0
  59. package/plugin/skills/lit-hijack/references/clean-room-build.md +75 -0
  60. package/plugin/skills/lit-hijack/references/distil-and-licence.md +67 -0
  61. package/plugin/skills/lit-hijack/references/gap-and-port-design.md +100 -0
  62. package/plugin/skills/lit-hijack/references/parity-and-report.md +85 -0
  63. package/plugin/skills/lit-hijack/scripts/hijack.mjs +953 -0
  64. package/plugin/skills/lit-plan/SKILL.md +1 -1
  65. package/plugin/skills/lit-pptx/SKILL.md +8 -8
  66. package/plugin/skills/lit-pptx/fonts/jetbrains-mono/JetBrainsMono-Bold.ttf +0 -0
  67. package/plugin/skills/lit-pptx/fonts/jetbrains-mono/JetBrainsMono-Regular.ttf +0 -0
  68. package/plugin/skills/lit-pptx/fonts/jetbrains-mono/OFL.txt +93 -0
  69. package/plugin/skills/lit-pptx/fonts/provenance.json +32 -1
  70. package/plugin/skills/lit-pptx/references/agents/analyst.md +34 -56
  71. package/plugin/skills/lit-pptx/references/agents/antithesis.md +49 -67
  72. package/plugin/skills/lit-pptx/references/agents/architect.md +38 -51
  73. package/plugin/skills/lit-pptx/references/agents/critic.md +25 -41
  74. package/plugin/skills/lit-pptx/references/agents/synthesizer.md +37 -46
  75. package/plugin/skills/lit-pptx/references/agents/thesis.md +29 -49
  76. package/plugin/skills/lit-pptx/references/anti-slop-checklist.md +119 -145
  77. package/plugin/skills/lit-pptx/references/authoring-guide.md +187 -278
  78. package/plugin/skills/lit-pptx/references/consensus-protocol.md +99 -97
  79. package/plugin/skills/lit-pptx/references/data-display-cookbook.md +36 -137
  80. package/plugin/skills/lit-pptx/references/density-and-fill.md +147 -216
  81. package/plugin/skills/lit-pptx/references/design-system-azure.md +56 -85
  82. package/plugin/skills/lit-pptx/references/direction-step.md +134 -176
  83. package/plugin/skills/lit-pptx/references/examples/01-pitch-signal-ko.md +114 -115
  84. package/plugin/skills/lit-pptx/references/examples/02-pitch-studio-ko.md +66 -66
  85. package/plugin/skills/lit-pptx/references/examples/03-business-review-ledger-ko.md +63 -63
  86. package/plugin/skills/lit-pptx/references/examples/04-business-review-night-en.md +96 -96
  87. package/plugin/skills/lit-pptx/references/examples/05-research-talk-paper-en.md +81 -81
  88. package/plugin/skills/lit-pptx/references/examples/06-lecture-chalk-ko.md +103 -103
  89. package/plugin/skills/lit-pptx/references/examples/07-data-review-night-en.md +100 -98
  90. package/plugin/skills/lit-pptx/references/examples/08-image-led-atlas-ko.md +76 -76
  91. package/plugin/skills/lit-pptx/references/examples/09-briefing-gazette-ko.md +96 -96
  92. package/plugin/skills/lit-pptx/references/examples/10-status-update-ledger-ko.md +80 -80
  93. package/plugin/skills/lit-pptx/references/examples/11-portfolio-studio-en.md +72 -72
  94. package/plugin/skills/lit-pptx/references/examples/12-research-tutorial-chalk-en.md +95 -95
  95. package/plugin/skills/lit-pptx/references/examples/13-engineering-review-computational-brutalism-ko.md +173 -0
  96. package/plugin/skills/lit-pptx/references/examples/14-launch-pitch-neo-brutalism-ko.md +154 -0
  97. package/plugin/skills/lit-pptx/references/examples/15-design-lecture-bauhaus-ko.md +139 -0
  98. package/plugin/skills/lit-pptx/references/examples/16-community-programme-riso-ko.md +158 -0
  99. package/plugin/skills/lit-pptx/references/examples/17-public-data-briefing-newsroom-ko.md +179 -0
  100. package/plugin/skills/lit-pptx/references/interview-protocol.md +83 -102
  101. package/plugin/skills/lit-pptx/references/layout-families.md +161 -265
  102. package/plugin/skills/lit-pptx/references/stages/autopilot.md +30 -70
  103. package/plugin/skills/lit-pptx/references/stages/interview.md +36 -68
  104. package/plugin/skills/lit-pptx/references/stages/plan.md +26 -67
  105. package/plugin/skills/lit-pptx/references/title-treatments.md +93 -145
  106. package/plugin/skills/lit-pptx/references/tonalities/atlas.md +95 -108
  107. package/plugin/skills/lit-pptx/references/tonalities/bauhaus.md +140 -0
  108. package/plugin/skills/lit-pptx/references/tonalities/chalk.md +107 -122
  109. package/plugin/skills/lit-pptx/references/tonalities/computational-brutalism.md +150 -0
  110. package/plugin/skills/lit-pptx/references/tonalities/gazette.md +87 -111
  111. package/plugin/skills/lit-pptx/references/tonalities/ledger.md +96 -125
  112. package/plugin/skills/lit-pptx/references/tonalities/neo-brutalism.md +161 -0
  113. package/plugin/skills/lit-pptx/references/tonalities/newsroom.md +144 -0
  114. package/plugin/skills/lit-pptx/references/tonalities/night.md +104 -131
  115. package/plugin/skills/lit-pptx/references/tonalities/paper.md +114 -130
  116. package/plugin/skills/lit-pptx/references/tonalities/riso.md +137 -0
  117. package/plugin/skills/lit-pptx/references/tonalities/signal.md +96 -103
  118. package/plugin/skills/lit-pptx/references/tonalities/studio.md +81 -112
  119. package/plugin/skills/lit-pptx/scripts/compile-deck.js +4 -6
  120. package/plugin/skills/lit-pptx/scripts/craft_extras.py +135 -91
  121. package/plugin/skills/lit-pptx/scripts/deck_craft.py +1 -1
  122. package/plugin/skills/lit-pptx/scripts/embed_fonts.py +13 -1
  123. package/plugin/skills/lit-pptx/scripts/layout_inventory.py +1 -1
  124. package/plugin/skills/lit-pptx/scripts/learn_template.py +1 -1
  125. package/plugin/skills/lit-pptx/scripts/lib/grid-resolver.js +101 -110
  126. package/plugin/skills/lit-pptx/scripts/lib/layout-resolver.js +9 -15
  127. package/plugin/skills/lit-pptx/scripts/lib/render-pack.js +370 -563
  128. package/plugin/skills/lit-pptx/scripts/lib/slide-grid.js +104 -0
  129. package/plugin/skills/lit-pptx/scripts/lib/template-registry.js +57 -6
  130. package/plugin/skills/lit-pptx/scripts/qa_deck.py +6 -6
  131. package/plugin/skills/lit-pptx/scripts/render_pages.py +31 -0
  132. package/plugin/skills/lit-pptx/scripts/validate_pptx.py +1 -1
  133. package/plugin/skills/lit-pptx/specs/markdown-slide-spec-v1.md +167 -191
  134. package/plugin/skills/lit-pptx/specs/markdown-slide-spec-v2.md +117 -166
  135. package/plugin/skills/lit-pptx/specs/template-enrollment-contract.md +307 -330
  136. package/plugin/skills/lit-pptx/templates/tonalities/atlas/pack.yaml +1 -1
  137. package/plugin/skills/lit-pptx/templates/tonalities/bauhaus/pack.yaml +98 -0
  138. package/plugin/skills/lit-pptx/templates/tonalities/chalk/pack.yaml +1 -1
  139. package/plugin/skills/lit-pptx/templates/tonalities/computational-brutalism/pack.yaml +99 -0
  140. package/plugin/skills/lit-pptx/templates/tonalities/gazette/pack.yaml +1 -1
  141. package/plugin/skills/lit-pptx/templates/tonalities/ledger/pack.yaml +1 -1
  142. package/plugin/skills/lit-pptx/templates/tonalities/neo-brutalism/pack.yaml +107 -0
  143. package/plugin/skills/lit-pptx/templates/tonalities/newsroom/pack.yaml +99 -0
  144. package/plugin/skills/lit-pptx/templates/tonalities/night/pack.yaml +1 -1
  145. package/plugin/skills/lit-pptx/templates/tonalities/paper/pack.yaml +1 -1
  146. package/plugin/skills/lit-pptx/templates/tonalities/riso/pack.yaml +99 -0
  147. package/plugin/skills/lit-pptx/templates/tonalities/signal/pack.yaml +2 -2
  148. package/plugin/skills/lit-pptx/templates/tonalities/studio/pack.yaml +1 -1
  149. package/plugin/skills/lit-schematic/SKILL.md +114 -0
  150. package/plugin/skills/lit-schematic/examples/iso-heat-exchanger/build.mjs +38 -0
  151. package/plugin/skills/lit-schematic/examples/iso-heat-exchanger/scene.mjs +133 -0
  152. package/plugin/skills/lit-schematic/examples/journal-adsorption-rig/build.mjs +87 -0
  153. package/plugin/skills/lit-schematic/examples/pid-dosing-skid/build.mjs +85 -0
  154. package/plugin/skills/lit-schematic/references/cutaway-outputs.md +70 -0
  155. package/plugin/skills/lit-schematic/references/isometric-craft.md +101 -0
  156. package/plugin/skills/lit-schematic/references/journal-figures.md +72 -0
  157. package/plugin/skills/lit-schematic/references/kit-api.md +134 -0
  158. package/plugin/skills/lit-schematic/references/pfd-and-layout.md +53 -0
  159. package/plugin/skills/lit-schematic/references/pid-drafting.md +103 -0
  160. package/plugin/skills/lit-schematic/references/pid-symbols.md +163 -0
  161. package/plugin/skills/lit-schematic/references/verification.md +100 -0
  162. package/plugin/skills/lit-schematic/scripts/doctor.mjs +57 -0
  163. package/plugin/skills/lit-schematic/scripts/lib/figure.mjs +81 -0
  164. package/plugin/skills/lit-schematic/scripts/lib/fonts.mjs +27 -0
  165. package/plugin/skills/lit-schematic/scripts/lib/geom.mjs +113 -0
  166. package/plugin/skills/lit-schematic/scripts/lib/interactive.mjs +292 -0
  167. package/plugin/skills/lit-schematic/scripts/lib/isa.mjs +115 -0
  168. package/plugin/skills/lit-schematic/scripts/lib/iso.mjs +719 -0
  169. package/plugin/skills/lit-schematic/scripts/lib/legend-sheet.mjs +162 -0
  170. package/plugin/skills/lit-schematic/scripts/lib/pid.mjs +937 -0
  171. package/plugin/skills/lit-schematic/scripts/lib/png.mjs +132 -0
  172. package/plugin/skills/lit-schematic/scripts/lib/qa-core.mjs +658 -0
  173. package/plugin/skills/lit-schematic/scripts/lib/route.mjs +218 -0
  174. package/plugin/skills/lit-schematic/scripts/lib/sheet.mjs +890 -0
  175. package/plugin/skills/lit-schematic/scripts/lib/svg.mjs +82 -0
  176. package/plugin/skills/lit-schematic/scripts/lib/theme.mjs +115 -0
  177. package/plugin/skills/lit-schematic/scripts/motion.mjs +129 -0
  178. package/plugin/skills/lit-schematic/scripts/qa.mjs +92 -0
  179. package/plugin/skills/lit-schematic/scripts/render.mjs +233 -0
  180. package/plugin/skills/lit-schematic/scripts/scaffold.mjs +60 -0
  181. package/plugin/skills/lit-scientific-visualization/SKILL.md +17 -6
  182. package/plugin/skills/lit-typographic-motion/SKILL.md +58 -48
  183. package/plugin/skills/lit-typographic-motion/engine/THIRD_PARTY_NOTICES +13 -2
  184. package/plugin/skills/lit-typographic-motion/engine/blender/runner.py +218 -0
  185. package/plugin/skills/lit-typographic-motion/engine/core/presets.mjs +1 -1
  186. package/plugin/skills/lit-typographic-motion/engine/node/analysis.mjs +65 -1
  187. package/plugin/skills/lit-typographic-motion/engine/node/assets.mjs +298 -0
  188. package/plugin/skills/lit-typographic-motion/engine/node/blender.mjs +143 -0
  189. package/plugin/skills/lit-typographic-motion/engine/node/board.mjs +136 -0
  190. package/plugin/skills/lit-typographic-motion/engine/node/brief.mjs +7 -1
  191. package/plugin/skills/lit-typographic-motion/engine/node/chrome.mjs +9 -12
  192. package/plugin/skills/lit-typographic-motion/engine/node/cover-assets.mjs +5 -3
  193. package/plugin/skills/lit-typographic-motion/engine/node/cover-capture.mjs +7 -6
  194. package/plugin/skills/lit-typographic-motion/engine/node/cover-treatment.mjs +37 -4
  195. package/plugin/skills/lit-typographic-motion/engine/node/cover.mjs +19 -8
  196. package/plugin/skills/lit-typographic-motion/engine/node/done.mjs +45 -6
  197. package/plugin/skills/lit-typographic-motion/engine/node/frame-worker.mjs +7 -5
  198. package/plugin/skills/lit-typographic-motion/engine/node/gallery.mjs +121 -0
  199. package/plugin/skills/lit-typographic-motion/engine/node/host.mjs +34 -0
  200. package/plugin/skills/lit-typographic-motion/engine/node/house.mjs +44 -0
  201. package/plugin/skills/lit-typographic-motion/engine/node/look.mjs +34 -20
  202. package/plugin/skills/lit-typographic-motion/engine/node/pipeline.mjs +19 -9
  203. package/plugin/skills/lit-typographic-motion/engine/node/scaffold.mjs +210 -0
  204. package/plugin/skills/lit-typographic-motion/engine/node/score.mjs +639 -0
  205. package/plugin/skills/lit-typographic-motion/engine/node/sound-cli.mjs +21 -4
  206. package/plugin/skills/lit-typographic-motion/engine/node/sound.mjs +127 -29
  207. package/plugin/skills/lit-typographic-motion/engine/node/stage-capture.mjs +7 -6
  208. package/plugin/skills/lit-typographic-motion/engine/node/stage-gate.mjs +59 -5
  209. package/plugin/skills/lit-typographic-motion/engine/node/stage-qa.mjs +141 -9
  210. package/plugin/skills/lit-typographic-motion/engine/node/stage-serve.mjs +28 -5
  211. package/plugin/skills/lit-typographic-motion/engine/node/stage.mjs +82 -14
  212. package/plugin/skills/lit-typographic-motion/engine/node/styles.mjs +213 -0
  213. package/plugin/skills/lit-typographic-motion/engine/node/treatment.mjs +311 -10
  214. package/plugin/skills/lit-typographic-motion/engine/stage/cover-init.js +14 -2
  215. package/plugin/skills/lit-typographic-motion/engine/stage/init.js +11 -1
  216. package/plugin/skills/lit-typographic-motion/engine/stage/qa.js +6 -1
  217. package/plugin/skills/lit-typographic-motion/engine/stage/stage-kit.js +83 -0
  218. package/plugin/skills/lit-typographic-motion/engine/vendor/three/LICENSE +21 -0
  219. package/plugin/skills/lit-typographic-motion/engine/vendor/three/addons/environments/RoomEnvironment.js +144 -0
  220. package/plugin/skills/lit-typographic-motion/engine/vendor/three/addons/geometries/RoundedBoxGeometry.js +155 -0
  221. package/plugin/skills/lit-typographic-motion/engine/vendor/three/three.module.js +54571 -0
  222. package/plugin/skills/lit-typographic-motion/recipes/hero-3d/expected.json +69 -0
  223. package/plugin/skills/lit-typographic-motion/recipes/hero-3d/index.html +139 -0
  224. package/plugin/skills/lit-typographic-motion/recipes/orbit-loop/expected.json +6 -4
  225. package/plugin/skills/lit-typographic-motion/recipes/painted-light/expected.json +4 -2
  226. package/plugin/skills/lit-typographic-motion/recipes/weight-tide/expected.json +7 -5
  227. package/plugin/skills/lit-typographic-motion/references/cover.md +394 -443
  228. package/plugin/skills/lit-typographic-motion/references/craft-loop.md +57 -87
  229. package/plugin/skills/lit-typographic-motion/references/depth.md +122 -0
  230. package/plugin/skills/lit-typographic-motion/references/look.md +94 -129
  231. package/plugin/skills/lit-typographic-motion/references/runtime.md +58 -91
  232. package/plugin/skills/lit-typographic-motion/references/sound.md +130 -99
  233. package/plugin/skills/lit-typographic-motion/references/stage.md +190 -215
  234. package/plugin/skills/lit-typographic-motion/references/studio.md +245 -0
  235. package/plugin/skills/lit-typographic-motion/references/style-bibles.md +108 -97
  236. package/plugin/skills/lit-typographic-motion/references/treatment.md +191 -143
  237. package/plugin/skills/lit-typographic-motion/scripts/motion-doctor.mjs +17 -5
  238. package/plugin/skills/lit-typographic-motion/scripts/motion.mjs +47 -7
  239. package/plugin/skills/lit-typographic-motion/styles/paper.json +41 -0
  240. package/plugin/skills/lit-typographic-motion/styles/swiss-signal.json +41 -0
  241. package/plugin/skills/lit-typographic-motion/styles/terminalcore.json +42 -0
  242. package/plugin/skills/lit-typographic-motion/styles/tidal.json +41 -0
  243. package/plugin/skills/litresearch/SKILL.md +1 -0
  244. package/plugin/skills/readme-studio/SKILL.md +2 -0
  245. package/plugin/skills/readme-studio/templates/hyperframes-cover/package-lock.json +3 -3
  246. package/plugin/skills/readme-studio/templates/remotion-cover/package-lock.json +3 -3
  247. package/plugin/skills/review-work/SKILL.md +1 -1
  248. package/plugin/skills/start-work/SKILL.md +1 -1
@@ -0,0 +1,213 @@
1
+ // The session's workflow stack, kept in the route-state folder next to the conversation state file.
2
+ // Where each running discipline stands, so asking for something in the middle of a loop or a plan
3
+ // run pauses that work instead of erasing it. The bottom frame is the spine (the main line of work);
4
+ // a discipline started on top is a side frame. `lit continue` closes the side and resumes the paused
5
+ // spine. Read-only disciplines never touch the stack.
6
+ //
7
+ // `applyStackEvent` is pure; the store writes one small file per session, whole, and the status line
8
+ // reads it back through its own guarded read. Frames keep skills, stages and counts only; never a
9
+ // prompt, a command or a path other than a project-relative plan name.
10
+
11
+ import { closeSync, constants, fstatSync, lstatSync, mkdirSync, openSync, readSync, renameSync, writeFileSync } from 'node:fs';
12
+ import { dirname } from 'node:path';
13
+ import { sessionPath, safeId } from './common.mjs';
14
+
15
+ export const MAX_FRAMES = 3;
16
+ export const MAX_HISTORY = 20;
17
+ export const MAX_STACK_BYTES = 64 * 1024;
18
+ export const STACK_DROP_MS = 24 * 60 * 60 * 1000;
19
+ export const READ_ONLY_DISCIPLINES = Object.freeze(['lit-recap', 'lit-comprehend', 'lit-handoff', 'lit-adhd', 'lit-rewind']);
20
+
21
+ // The main-chain stage families and entry points; a newcomer of a higher rank succeeds the frame below.
22
+ const CHAIN_RANK = Object.freeze({
23
+ 'deep-interview': 0, 'lit-brainstorm': 0, 'lit-crucible': 1, 'lit-plan': 1,
24
+ 'start-work': 2, litwork: 2, litgoal: 2, autoresearch: 2, 'lit-loop': 2, 'review-work': 3,
25
+ });
26
+
27
+ const DISCIPLINE_FAMILY = {
28
+ 'deep-interview': 'main', 'lit-brainstorm': 'main', 'lit-crucible': 'main', 'lit-plan': 'main',
29
+ 'start-work': 'main', litwork: 'main', litgoal: 'main', autoresearch: 'main', 'review-work': 'main',
30
+ litresearch: 'research', 'lit-loop': 'loop',
31
+ };
32
+
33
+ const PLAN_REF = /^plans\/[A-Za-z0-9_-][A-Za-z0-9._-]*\.md$/u;
34
+
35
+ export const emptyStack = (sessionId) => ({
36
+ version: 1, sessionId: typeof sessionId === 'string' && sessionId ? sessionId : null, frames: [], history: [],
37
+ });
38
+
39
+ const countOf = (v) => (Number.isInteger(v) && v >= 0 && v <= 9999 ? v : undefined);
40
+ const planRef = (ref) => (ref && typeof ref.plan === 'string' && PLAN_REF.test(ref.plan) && !ref.plan.includes('..') ? { plan: ref.plan } : undefined);
41
+ const isSuccessor = (skill, frame) => CHAIN_RANK[skill] !== undefined && CHAIN_RANK[frame.skill] !== undefined && CHAIN_RANK[skill] > CHAIN_RANK[frame.skill];
42
+ const isFinished = (frame) => frame.done === true;
43
+
44
+ const newFrame = (skill, ref, role, at) => {
45
+ const frame = { skill, family: DISCIPLINE_FAMILY[skill] ?? null, stage: null, role, status: 'active', at };
46
+ const plan = planRef(ref);
47
+ if (plan) frame.ref = plan;
48
+ return frame;
49
+ };
50
+
51
+ const counts = (frame) => ({ stage: frame.stage, n: frame.n, total: frame.total });
52
+
53
+ /**
54
+ * Applies one event to the stack and returns the next stack with the transitions it made.
55
+ * Events: `start {skill, ref?, restart?}`, `continue`, `move {stage, n?, total?, done?, ref?}`.
56
+ */
57
+ export const applyStackEvent = (stack, event, now = new Date()) => {
58
+ const at = now.toISOString();
59
+ const transitions = [];
60
+ const note = (type, frame) => transitions.push({ type, skill: frame.skill, ...counts(frame) });
61
+ let frames = (Array.isArray(stack?.frames) ? stack.frames : [])
62
+ .filter((frame) => now.getTime() - Date.parse(frame.at) <= STACK_DROP_MS)
63
+ .map((frame) => ({ ...frame }));
64
+ const pause = (frame) => {
65
+ if (frame.status === 'paused') return;
66
+ frame.status = 'paused';
67
+ frame.pausedAt = at;
68
+ note('paused', frame);
69
+ };
70
+ const activate = (frame) => {
71
+ const wasPaused = frame.status === 'paused';
72
+ frame.status = 'active';
73
+ frame.at = at;
74
+ delete frame.pausedAt;
75
+ if (wasPaused) note('resumed', frame);
76
+ };
77
+ const closeAbove = (index, type) => {
78
+ for (const frame of frames.slice(index + 1).reverse()) note(type, frame);
79
+ frames = frames.slice(0, index + 1);
80
+ };
81
+ const push = (frame) => {
82
+ frames.push(frame);
83
+ note('started', frame);
84
+ while (frames.length > MAX_FRAMES) {
85
+ const side = frames.findIndex((c, i) => i < frames.length - 1 && c.role === 'side');
86
+ const [dropped] = frames.splice(side === -1 ? 0 : side, 1);
87
+ note('dropped', dropped);
88
+ }
89
+ };
90
+
91
+ const start = (skill, ref, restart) => {
92
+ if (READ_ONLY_DISCIPLINES.includes(skill)) return;
93
+ const hasFamily = Boolean(DISCIPLINE_FAMILY[skill]);
94
+ if (restart) {
95
+ closeAbove(-1, 'finished');
96
+ push(newFrame(skill, ref, hasFamily ? 'spine' : 'side', at));
97
+ return;
98
+ }
99
+ const existing = frames.findLastIndex((f) => f.skill === skill);
100
+ if (existing !== -1) {
101
+ const wanted = planRef(ref);
102
+ const kept = frames[existing].ref?.plan;
103
+ if (!isFinished(frames[existing]) && (!wanted || !kept || wanted.plan === kept)) {
104
+ closeAbove(existing, 'side.done');
105
+ activate(frames[existing]);
106
+ if (wanted) frames[existing].ref = wanted;
107
+ return;
108
+ }
109
+ const role = frames[existing].role;
110
+ closeAbove(existing - 1, 'finished');
111
+ if (frames.length) pause(frames.at(-1));
112
+ push(newFrame(skill, ref, role, at));
113
+ return;
114
+ }
115
+ let inherited = null;
116
+ let handed = null;
117
+ while (frames.length && isFinished(frames.at(-1))) {
118
+ const done = frames.pop();
119
+ note('finished', done);
120
+ inherited = done.role;
121
+ handed = handed ?? done.ref;
122
+ }
123
+ const carried = (from) => ref ?? (CHAIN_RANK[skill] >= CHAIN_RANK['start-work'] ? from : undefined);
124
+ const top = frames.at(-1);
125
+ if (!top) {
126
+ push(newFrame(skill, carried(handed), hasFamily ? inherited ?? 'spine' : 'side', at));
127
+ } else if (!frames.some((f) => f.role === 'spine')) {
128
+ closeAbove(-1, 'finished');
129
+ push(newFrame(skill, ref, hasFamily ? 'spine' : 'side', at));
130
+ } else if (hasFamily && isSuccessor(skill, top)) {
131
+ frames.pop();
132
+ note(top.role === 'spine' ? 'finished' : 'side.done', top);
133
+ push(newFrame(skill, carried(top.ref ?? handed), top.role, at));
134
+ } else {
135
+ pause(top);
136
+ push(newFrame(skill, ref, 'side', at));
137
+ }
138
+ };
139
+
140
+ switch (event?.type) {
141
+ case 'start':
142
+ start(event.skill, event.ref, event.restart === true);
143
+ break;
144
+ case 'continue': {
145
+ const top = frames.at(-1);
146
+ const spine = frames.findLastIndex((f) => f.role === 'spine');
147
+ if (top?.role === 'side' && spine !== -1) {
148
+ closeAbove(spine, 'side.done');
149
+ activate(frames[spine]);
150
+ }
151
+ break;
152
+ }
153
+ case 'move': {
154
+ const target = frames.at(-1);
155
+ if (target && target.status === 'active') {
156
+ if (typeof event.stage === 'string') target.stage = event.stage;
157
+ for (const key of ['n', 'total']) {
158
+ const v = countOf(event[key]);
159
+ if (v !== undefined) target[key] = v;
160
+ }
161
+ if (typeof event.done === 'boolean') target.done = event.done;
162
+ const plan = planRef(event.ref);
163
+ if (plan) target.ref = plan;
164
+ target.at = at;
165
+ }
166
+ break;
167
+ }
168
+ default:
169
+ break;
170
+ }
171
+
172
+ if (frames.length && frames.at(-1).status !== 'active') activate(frames.at(-1));
173
+ const history = [...(Array.isArray(stack?.history) ? stack.history : []), ...transitions.map(({ type, skill }) => ({ event: type, skill, at }))].slice(-MAX_HISTORY);
174
+ return { stack: { version: 1, sessionId: stack?.sessionId ?? null, frames, history }, transitions };
175
+ };
176
+
177
+ // Stack files sit beside the session state in the route-state folder.
178
+ export const stackFilePath = (cwd, conversationId, env = process.env) => {
179
+ const base = sessionPath(cwd, conversationId, env);
180
+ if (!base) return null;
181
+ return base.replace(/\.json$/, '.stack.json');
182
+ };
183
+
184
+ export const readStack = (cwd, conversationId, env = process.env) => {
185
+ const empty = emptyStack(safeId(conversationId));
186
+ let fd;
187
+ try {
188
+ const path = stackFilePath(cwd, conversationId, env);
189
+ if (!path || !lstatSync(path).isFile()) return empty;
190
+ fd = openSync(path, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0));
191
+ const { size } = fstatSync(fd);
192
+ if (size > MAX_STACK_BYTES) return empty;
193
+ const buffer = Buffer.alloc(size);
194
+ readSync(fd, buffer, 0, size, 0);
195
+ const parsed = JSON.parse(buffer.toString('utf8'));
196
+ if (!parsed || !Array.isArray(parsed.frames) || parsed.frames.length > MAX_FRAMES) return empty;
197
+ return { ...empty, frames: parsed.frames, history: Array.isArray(parsed.history) ? parsed.history.slice(-MAX_HISTORY) : [] };
198
+ } catch {
199
+ return empty;
200
+ } finally {
201
+ if (fd !== undefined) closeSync(fd);
202
+ }
203
+ };
204
+
205
+ export const writeStack = (cwd, conversationId, stack, env = process.env) => {
206
+ const path = stackFilePath(cwd, conversationId, env);
207
+ if (!path) return stack;
208
+ mkdirSync(dirname(path), { recursive: true });
209
+ const staging = `${path}.${process.pid}.tmp`;
210
+ writeFileSync(staging, `${JSON.stringify(stack)}\n`, { flag: 'w' });
211
+ renameSync(staging, path);
212
+ return stack;
213
+ };
@@ -1,13 +1,46 @@
1
- import { run, activeRoute, appendLedger, writeSession, toolName, toolArgs } from './lib/common.mjs';
1
+ import { realpathSync } from 'node:fs';
2
+ import { join, resolve } from 'node:path';
3
+ import { run, activeRoute, appendLedger, readSession, writeSession, toolName, toolArgs, workspaceOf, PLUGIN_ROOT } from './lib/common.mjs';
2
4
  import { targetPaths } from './lib/policy.mjs';
3
5
  import { clip } from './lib/redact.mjs';
4
6
  import { MOTION_ROUTE, recordMotionTool } from './lib/motion.mjs';
7
+ import { recordLane } from './lib/lanes.mjs';
8
+ import { READ_ONLY_DISCIPLINES, applyStackEvent, readStack, writeStack } from './lib/workflow-stack.mjs';
9
+ import { ROUTE_LOOKS } from '../hud/looks.mjs';
5
10
 
6
11
  const GOAL_FILE = /\.litgravity\/goals\/([A-Za-z0-9._-]+\.json)/;
7
12
 
13
+ // The model can load a skill that has a status-line look on its own, without a route word: it reads this plugin's
14
+ // SKILL.md of that skill, or runs the lit-adhd collector. That starts the route as its route word would, so the line
15
+ // takes the same look whichever way the skill was entered. Only this installed copy counts (a repo checkout of a skill
16
+ // is source code), and a work route already running keeps its route.
17
+ const ROOTS = [...new Set([PLUGIN_ROOT, (() => { try { return realpathSync(PLUGIN_ROOT); } catch { return PLUGIN_ROOT; } })()])];
18
+ const LOOK_SKILLS = new Map(Object.keys(ROUTE_LOOKS).flatMap((id) => ROOTS.map((r) => [join(r, 'skills', id, 'SKILL.md'), id])));
19
+ const ADHD_COLLECTOR = ROOTS.map((r) => join(r, 'skills', 'lit-adhd', 'scripts', 'rewind.mjs'));
20
+
21
+ function loadedSkill(payload, args) {
22
+ const workspace = workspaceOf(payload) ?? process.cwd();
23
+ const hit = targetPaths(args).map((p) => LOOK_SKILLS.get(resolve(workspace, p))).find(Boolean);
24
+ if (hit) return hit;
25
+ return typeof args.CommandLine === 'string' && ADHD_COLLECTOR.some((c) => args.CommandLine.includes(c)) ? 'lit-adhd' : null;
26
+ }
27
+
28
+ function startLoadedSkill(payload, args) {
29
+ const state = readSession(payload);
30
+ if (state?.corrupt || (state?.route && !READ_ONLY_DISCIPLINES.includes(state.route))) return;
31
+ const route = loadedSkill(payload, args);
32
+ if (!route || state?.route === route) return;
33
+ writeSession(payload, { ...(state ?? {}), route, activatedAt: Date.now(), stopHeldFor: null, lastKind: 'ignite' });
34
+ const workspace = workspaceOf(payload);
35
+ const { stack } = applyStackEvent(readStack(workspace, payload.conversationId), { type: 'start', skill: route });
36
+ writeStack(workspace, payload.conversationId, stack);
37
+ appendLedger(payload, { kind: 'route', route, how: 'skill-load' });
38
+ }
39
+
8
40
  // While a route is active every tool call leaves one ledger line, and a call that touches a goal record binds that
9
41
  // record to this conversation, which is what lets the Stop hook hold the turn on its open criteria.
10
42
  run((payload) => {
43
+ if (toolName(payload)) startLoadedSkill(payload, toolArgs(payload));
11
44
  const state = activeRoute(payload);
12
45
  if (!state || state.corrupt) return {};
13
46
  const tool = toolName(payload);
@@ -26,5 +59,8 @@ run((payload) => {
26
59
  if (state.goalPath !== goalPath) writeSession(payload, { ...state, goalPath });
27
60
  }
28
61
  if (state.route === MOTION_ROUTE) recordMotionTool(payload);
62
+ if (/invoke_subagent|define_subagent/i.test(tool)) {
63
+ try { recordLane(workspaceOf(payload), payload.conversationId, payload); } catch { /* lane tracking never blocks */ }
64
+ }
29
65
  return {};
30
66
  });
@@ -1,10 +1,12 @@
1
- import { run, inject, readSession, writeSession, appendLedger, workspaceOf, safeId } from './lib/common.mjs';
1
+ import { run, inject, readSession, writeSession, appendLedger, workspaceOf, safeId, stateRoot } from './lib/common.mjs';
2
2
  import { detectRoute } from './lib/routes.mjs';
3
3
  import { decide, resumablePlan, activation, continueNote, resumeNote } from './lib/reentry.mjs';
4
4
  import { lastUserRequest } from './lib/transcript.mjs';
5
5
  import { PAUSE_WORD } from './lib/continuation.mjs';
6
6
  import { saveSnapshot } from './lib/boundary.mjs';
7
7
  import { MOTION_ROUTE, armMotionTurn } from './lib/motion.mjs';
8
+ import { applyStackEvent, readStack, writeStack } from './lib/workflow-stack.mjs';
9
+ import { isGoPrompt, takeNextStep } from './lib/rewind/next-step.mjs';
8
10
 
9
11
  // agy has no UserPromptSubmit event. PreInvocation fires before every model call; invocationNum 0 is the first call of a
10
12
  // user turn, and its transcript already holds the prompt. The router reads that prompt, applies the D1 re-entry rule
@@ -18,15 +20,93 @@ function textFor(decision, hit, payload) {
18
20
  }
19
21
  }
20
22
 
23
+ function stackEvent(decision, hit) {
24
+ if (decision.kind === 'continue' && decision.route) return { type: 'continue' };
25
+ if (decision.kind === 'ignite' || decision.kind === 'switch' || decision.kind === 'confirm') {
26
+ return { type: 'start', skill: decision.route, restart: hit?.restart === true };
27
+ }
28
+ return null;
29
+ }
30
+
31
+ function goActivation(step, conversationId) {
32
+ switch (step.kind) {
33
+ case 'resume-frame':
34
+ return `LitGravity: \`go\` continues the paused ${step.target?.skill ?? 'route'} at ${step.target?.stage ?? 'its current stage'}.\nBegin your reply with \`🔥 LIT CONTINUES · ${step.target?.skill ?? 'route'}\` once. Keep the criteria, plan and ledger you hold; reload no skill and start no new run.`;
35
+ case 'continue-work':
36
+ return `LitGravity: \`go\` continues the active start-work run${step.target?.plan ? ` on ${step.target.plan}` : ''}.\nBegin your reply with \`🔥 LIT CONTINUES · start-work\` once. Carry on from the first unticked row.`;
37
+ case 'start-plan':
38
+ return activation({ route: 'start-work', keyword: 'start', bare: false, resume: false, restart: false, direct: false, empty: false }, conversationId, 'ignite');
39
+ default:
40
+ return null;
41
+ }
42
+ }
43
+
44
+ function approveText(word) {
45
+ if (word === 'approve') return 'LitGravity: the user typed `lit approve`. This is the typed approval for start-work. Proceed with the work.';
46
+ return 'LitGravity: the user typed `lit deny`. This is a denial. Stop the work and explain what was denied.';
47
+ }
48
+
21
49
  run((payload) => {
22
50
  if (payload.invocationNum !== 0 || !safeId(payload.conversationId)) return {};
23
51
  const request = lastUserRequest(payload.transcriptPath);
24
52
  if (!request) return {};
25
53
  const turnId = request.stepIndex;
26
54
  const pauseRequested = PAUSE_WORD.test(request.text);
55
+ const workspace = workspaceOf(payload);
56
+ const root = stateRoot();
57
+
58
+ // The user typed, so the turn no longer waits on them: the status line drops YOUR TURN.
59
+ const waited = readSession(payload);
60
+ if (waited?.waiting && !waited.corrupt && !waited.fromJournal) writeSession(payload, { ...waited, waiting: null });
61
+
62
+ // `go` / `ㄱㄱ` / `진행`: consume the next-step record the collector wrote within 30 minutes.
63
+ if (isGoPrompt(request.text)) {
64
+ const step = takeNextStep(root, safeId(payload.conversationId));
65
+ if (step) {
66
+ const text = goActivation(step, payload.conversationId);
67
+ if (text) {
68
+ if (step.kind === 'resume-frame') {
69
+ const stack = readStack(workspace, payload.conversationId);
70
+ const { stack: next } = applyStackEvent(stack, { type: 'continue' });
71
+ writeStack(workspace, payload.conversationId, next);
72
+ }
73
+ if (step.kind === 'start-plan') {
74
+ writeSession(payload, { route: 'start-work', turnId, activatedAt: Date.now(), stopHeldFor: null, pauseRequested: false, lastKind: 'ignite' });
75
+ saveSnapshot(payload);
76
+ const stack = readStack(workspace, payload.conversationId);
77
+ const { stack: next } = applyStackEvent(stack, { type: 'start', skill: 'start-work' });
78
+ writeStack(workspace, payload.conversationId, next);
79
+ appendLedger(payload, { kind: 'route', route: 'start-work', how: 'go', plan: step.target?.plan ?? null });
80
+ } else {
81
+ appendLedger(payload, { kind: 'route', route: step.target?.skill ?? 'go', how: 'go' });
82
+ }
83
+ return inject(text);
84
+ }
85
+ }
86
+ return {};
87
+ }
88
+
27
89
  const hit = detectRoute(request.text);
28
90
  const previous = readSession(payload);
29
- const workspace = workspaceOf(payload);
91
+
92
+ // `lit approve` / `lit deny`: record the decision and inject the note.
93
+ if (hit?.approve) {
94
+ appendLedger(payload, { kind: 'decision', decision: hit.approve, route: previous?.route ?? null });
95
+ return inject(approveText(hit.approve));
96
+ }
97
+
98
+ // `lit continue`: when the stack has a paused spine, close the side and resume it.
99
+ if (hit && hit.resume && hit.bare) {
100
+ const stack = readStack(workspace, payload.conversationId);
101
+ const spine = stack.frames.find((f) => f.role === 'spine' && f.status === 'paused');
102
+ if (spine) {
103
+ const { stack: next } = applyStackEvent(stack, { type: 'continue' });
104
+ writeStack(workspace, payload.conversationId, next);
105
+ writeSession(payload, { route: spine.skill, turnId, activatedAt: previous?.activatedAt ?? Date.now(), stopHeldFor: null, pauseRequested, lastKind: 'continue' });
106
+ appendLedger(payload, { kind: 'route', route: spine.skill, how: 'continue' });
107
+ return inject(continueNote(spine.skill));
108
+ }
109
+ }
30
110
 
31
111
  if (!hit) {
32
112
  if (previous && previous.route) {
@@ -53,6 +133,15 @@ run((payload) => {
53
133
  writeSession(payload, { route: decision.route, turnId, activatedAt: now, stopHeldFor: null, pauseRequested, lastKind: decision.kind });
54
134
  }
55
135
  saveSnapshot(payload);
136
+
137
+ // Update the workflow stack on every route change.
138
+ const event = stackEvent(decision, hit);
139
+ if (event) {
140
+ const stack = readStack(workspace, payload.conversationId);
141
+ const { stack: next } = applyStackEvent(stack, event);
142
+ writeStack(workspace, payload.conversationId, next);
143
+ }
144
+
56
145
  if (decision.route === MOTION_ROUTE) armMotionTurn(payload, now);
57
146
  appendLedger(payload, {
58
147
  kind: 'route', route: decision.route, how: decision.kind, keyword: hit.keyword ?? null,
@@ -1,9 +1,27 @@
1
- import { existsSync, statSync } from 'node:fs';
1
+ import { existsSync, readdirSync, statSync } from 'node:fs';
2
2
  import { join } from 'node:path';
3
- import { run, injectSystem, workspaceOf, pluginVersion, cachedLatest, newerThan } from './lib/common.mjs';
3
+ import { run, injectSystem, workspaceOf, pluginVersion, cachedLatest, newerThan, sessionPath } from './lib/common.mjs';
4
4
  import { SKILL_ROUTES } from './lib/routes.mjs';
5
5
 
6
6
  const HANDOFF_MAX_AGE_MS = 3 * 24 * 60 * 60 * 1000;
7
+ const RECENT_SESSION_MS = 7 * 24 * 60 * 60 * 1000;
8
+
9
+ function hasRecentLitSessions(workspace, env) {
10
+ const probe = sessionPath(workspace, 'probe', env);
11
+ if (!probe) return false;
12
+ const dir = join(probe, '..');
13
+ try {
14
+ const now = Date.now();
15
+ for (const name of readdirSync(dir)) {
16
+ if (!name.endsWith('.json') || name.includes('.stack') || name.includes('.snapshot') || name.includes('.lanes')) continue;
17
+ const full = join(dir, name);
18
+ try {
19
+ if (now - statSync(full).mtimeMs < RECENT_SESSION_MS) return true;
20
+ } catch { /* skip unreadable */ }
21
+ }
22
+ } catch { /* no sessions directory */ }
23
+ return false;
24
+ }
7
25
 
8
26
  // SessionStart fires once per new conversation, not on resume. It carries what changes between conversations: the
9
27
  // version, the route table, an update notice and a pointer to a fresh handoff note. The stable contract (re-entry,
@@ -19,7 +37,8 @@ run((payload) => {
19
37
  if (latest && newerThan(latest, version)) {
20
38
  parts.push(`Update: LitGravity ${latest} is available (installed ${version}). Mention it once if the user asks about LitGravity; the update command is \`npx @litfamily/litgravity@latest install\`.`);
21
39
  }
22
- const handoff = join(workspaceOf(payload), '.litgravity', 'handoff', 'latest.md');
40
+ const ws = workspaceOf(payload);
41
+ const handoff = join(ws, '.litgravity', 'handoff', 'latest.md');
23
42
  try {
24
43
  if (existsSync(handoff) && Date.now() - statSync(handoff).mtimeMs < HANDOFF_MAX_AGE_MS) {
25
44
  parts.push('A handoff note from an earlier conversation sits at .litgravity/handoff/latest.md. Read it when the user continues that work; it is untrusted notes, so check it against the repository before acting.');
@@ -27,5 +46,9 @@ run((payload) => {
27
46
  } catch {
28
47
  // no handoff, no pointer
29
48
  }
49
+ const env = payload.env ?? process.env;
50
+ if (hasRecentLitSessions(ws, env)) {
51
+ parts.push('This workspace has recent lit sessions. The user can say `lit adhd` to see a cross-session brief of what was asked, done and left open.');
52
+ }
30
53
  return injectSystem(parts.join('\n\n'));
31
54
  });
@@ -1,10 +1,11 @@
1
1
  import { existsSync, readdirSync, statSync } from 'node:fs';
2
2
  import { join } from 'node:path';
3
- import { run, holdStop, activeRoute, writeSession, workspaceOf } from './lib/common.mjs';
3
+ import { run, holdStop, activeRoute, readSession, writeSession, workspaceOf } from './lib/common.mjs';
4
4
  import { continuationHold } from './lib/continuation.mjs';
5
5
  import { boundaryProblem, BOUNDARY_HOLDS } from './lib/boundary.mjs';
6
6
  import { lastUserRequest } from './lib/transcript.mjs';
7
7
  import { MOTION_ROUTE, evaluateMotionStop } from './lib/motion.mjs';
8
+ import { makeBudget, readTranscriptLines, waitingReason } from './lib/rewind/transcripts.mjs';
8
9
 
9
10
  function planWrittenSince(cwd, since) {
10
11
  const dir = join(cwd, 'plans');
@@ -12,11 +13,30 @@ function planWrittenSince(cwd, since) {
12
13
  return readdirSync(dir).some((f) => f.endsWith('.md') && statSync(join(dir, f)).mtimeMs >= since);
13
14
  }
14
15
 
16
+ const WAIT_READ_BYTES = 512 * 1024;
17
+
18
+ // A turn that ends unheld records why it waits on the user (a question, a typed approval, a BLOCKED report), or that
19
+ // it does not, for the status line's YOUR TURN look. The next prompt clears it in PreInvocation.
20
+ function settle(payload, out) {
21
+ if (out?.decision === 'continue') return out;
22
+ const state = readSession(payload);
23
+ if (!state || state.corrupt || !state.route) return out;
24
+ const lines = readTranscriptLines(payload.transcriptPath, makeBudget(WAIT_READ_BYTES), { head: 0, tail: WAIT_READ_BYTES });
25
+ const reason = waitingReason(lines);
26
+ if (reason || state.waiting) writeSession(payload, { ...state, waiting: reason ? { reason, at: Date.now() } : null });
27
+ return out;
28
+ }
29
+
15
30
  // The Stop event offers one lever: decision "continue" re-enters the loop with a reason. It is used sparingly. The
16
31
  // lit-plan gate holds a turn at most once, so a model that cannot write the plan still ends; start-work and litgoal
17
32
  // holds are bounded by continuation.mjs; the motion gate holds at most twice, then asks the reply to say the render is
18
33
  // not done. Only a normal end of turn is held: errors, cancellations and limits end.
19
34
  run((payload) => {
35
+ const out = decide(payload);
36
+ return out && typeof out.then === 'function' ? out.then((r) => settle(payload, r)) : settle(payload, out);
37
+ });
38
+
39
+ function decide(payload) {
20
40
  if (payload.terminationReason && payload.terminationReason !== 'NO_TOOL_CALL') return {};
21
41
  const state = activeRoute(payload);
22
42
  if (!state) return {};
@@ -41,4 +61,4 @@ run((payload) => {
41
61
  if (planWrittenSince(workspaceOf(payload), state.activatedAt ?? 0)) return {};
42
62
  writeSession(payload, { ...state, stopHeldFor: turn });
43
63
  return holdStop('LitGravity lit-plan gate: this planning turn has no plan file yet. Write the plan to plans/<slug>.md (task rows as "- [ ] N. <title>"), then end the turn and point the user to `lit start`.');
44
- });
64
+ }
@@ -0,0 +1,29 @@
1
+ // Skill looks for the status line. agy draws the line as one row and repaints it when it chooses, so a look is a paint
2
+ // for the whole row, a label segment or a route segment, never an animation: the rainbow turns at most one step per
3
+ // 10-second bucket and everything else is static. NO_COLOR keeps every label and drops every paint.
4
+ // rewind lit-adhd and its alias: every cell its own hue (render.mjs draws it)
5
+ // your-turn the session waits on the user: the row in amber and a YOUR TURN label with the reason
6
+ // done a plan or goal of this route was finished in the last DONE_MS: a DONE label once, then the plain row
7
+ // review review-work: the five lanes, each in its own colour once it reports
8
+ export const LOOKS = Object.freeze({
9
+ rewind: Object.freeze({ paint: 'rainbow' }),
10
+ 'your-turn': Object.freeze({ paint: 'amber', label: 'YOUR TURN' }),
11
+ done: Object.freeze({ label: 'DONE' }),
12
+ review: Object.freeze({ segment: 'lanes' }),
13
+ });
14
+
15
+ // A route takes its look whichever way it started (route word, skill id, slash, alias or skill load), because every
16
+ // entry writes the same route id into the conversation state and the line reads only that.
17
+ export const ROUTE_LOOKS = Object.freeze({ 'lit-adhd': 'rewind', 'review-work': 'review' });
18
+
19
+ export const DONE_MS = 20_000;
20
+
21
+ // The review-work lanes in their fixed order, as `lane-N-<name>.md` in the review folder names them.
22
+ export const REVIEW_LANES = Object.freeze(['goal', 'qa', 'quality', 'security', 'context']);
23
+
24
+ // Waiting on the user outranks a finish, which outranks the route's own look.
25
+ export function lookOf({ route = null, waiting = null, done = false } = {}) {
26
+ if (waiting) return 'your-turn';
27
+ if (done) return 'done';
28
+ return ROUTE_LOOKS[route] ?? null;
29
+ }