@litfamily/litgravity 0.1.1 → 0.1.3

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 (251) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/README.md +19 -3
  3. package/README_ko-KR.md +19 -3
  4. package/TRADEMARK.md +12 -0
  5. package/package.json +3 -2
  6. package/plugin/hooks/lib/lanes.mjs +65 -0
  7. package/plugin/hooks/lib/liveness.mjs +81 -0
  8. package/plugin/hooks/lib/motion.mjs +34 -5
  9. package/plugin/hooks/lib/reentry.mjs +7 -0
  10. package/plugin/hooks/lib/rewind/brief.mjs +364 -0
  11. package/plugin/hooks/lib/rewind/collect.mjs +359 -0
  12. package/plugin/hooks/lib/rewind/gauge.mjs +55 -0
  13. package/plugin/hooks/lib/rewind/next-step.mjs +77 -0
  14. package/plugin/hooks/lib/rewind/redact.mjs +60 -0
  15. package/plugin/hooks/lib/rewind/transcripts.mjs +214 -0
  16. package/plugin/hooks/lib/routes.mjs +79 -5
  17. package/plugin/hooks/lib/workflow-stack.mjs +213 -0
  18. package/plugin/hooks/post-tool-use.mjs +39 -1
  19. package/plugin/hooks/pre-invocation.mjs +93 -2
  20. package/plugin/hooks/session-start.mjs +26 -3
  21. package/plugin/hooks/stop.mjs +55 -6
  22. package/plugin/hud/looks.mjs +29 -0
  23. package/plugin/hud/render.mjs +277 -12
  24. package/plugin/plugin.json +1 -1
  25. package/plugin/skills/frontend-ui-ux/SKILL.md +12 -1
  26. package/plugin/skills/frontend-ui-ux/kit/components.css +417 -0
  27. package/plugin/skills/frontend-ui-ux/kit/fonts.json +22 -0
  28. package/plugin/skills/frontend-ui-ux/kit/layouts/landing.html +164 -0
  29. package/plugin/skills/frontend-ui-ux/kit/layouts/settings.html +114 -0
  30. package/plugin/skills/frontend-ui-ux/kit/layouts/workspace.html +115 -0
  31. package/plugin/skills/frontend-ui-ux/kit/styles/computational-brutalism.json +227 -0
  32. package/plugin/skills/frontend-ui-ux/kit/styles/field-notes.json +205 -0
  33. package/plugin/skills/frontend-ui-ux/kit/styles/graphite.json +200 -0
  34. package/plugin/skills/frontend-ui-ux/kit/styles/meadow.json +199 -0
  35. package/plugin/skills/frontend-ui-ux/kit/styles/neo-brutalism.json +222 -0
  36. package/plugin/skills/frontend-ui-ux/kit/ui.js +226 -0
  37. package/plugin/skills/frontend-ui-ux/references/house-styles.md +234 -0
  38. package/plugin/skills/frontend-ui-ux/scripts/design-lock.mjs +400 -0
  39. package/plugin/skills/frontend-ui-ux/scripts/interface-probe-lock.mjs +196 -0
  40. package/plugin/skills/frontend-ui-ux/scripts/interface-probe-page.mjs +30 -9
  41. package/plugin/skills/frontend-ui-ux/scripts/interface-probe-rules.mjs +20 -8
  42. package/plugin/skills/frontend-ui-ux/scripts/interface-probe.mjs +42 -9
  43. package/plugin/skills/frontend-ui-ux/scripts/pixel-art.mjs +60 -0
  44. package/plugin/skills/lit-adhd/SKILL.md +160 -0
  45. package/plugin/skills/lit-adhd/references/card-examples.md +107 -0
  46. package/plugin/skills/lit-adhd/references/status-taxonomy.md +34 -0
  47. package/plugin/skills/lit-adhd/scripts/rewind.mjs +5 -0
  48. package/plugin/skills/lit-diagram-drawer/SKILL.md +5 -3
  49. package/plugin/skills/lit-diagram-drawer/references/drawing-rules.md +1 -1
  50. package/plugin/skills/lit-diagram-drawer/references/style-guide.md +21 -12
  51. package/plugin/skills/lit-diagram-drawer/references/type-architecture.md +3 -3
  52. package/plugin/skills/lit-diagram-drawer/references/type-dependency.md +1 -1
  53. package/plugin/skills/lit-diagram-drawer/references/type-tree.md +3 -3
  54. package/plugin/skills/lit-diagram-drawer/references/type-wardley.md +1 -1
  55. package/plugin/skills/lit-diagram-drawer/scripts/diagram-craft-rules.mjs +1 -2
  56. package/plugin/skills/lit-diagram-drawer/scripts/visual-quality.mjs +1 -2
  57. package/plugin/skills/lit-docx/SKILL.md +3 -3
  58. package/plugin/skills/lit-handoff/SKILL.md +1 -0
  59. package/plugin/skills/lit-hijack/SKILL.md +263 -0
  60. package/plugin/skills/lit-hijack/references/capture-and-provenance.md +100 -0
  61. package/plugin/skills/lit-hijack/references/clean-room-build.md +75 -0
  62. package/plugin/skills/lit-hijack/references/distil-and-licence.md +67 -0
  63. package/plugin/skills/lit-hijack/references/gap-and-port-design.md +100 -0
  64. package/plugin/skills/lit-hijack/references/parity-and-report.md +85 -0
  65. package/plugin/skills/lit-hijack/scripts/hijack.mjs +953 -0
  66. package/plugin/skills/lit-plan/SKILL.md +3 -2
  67. package/plugin/skills/lit-plan/references/plan-contract.md +12 -1
  68. package/plugin/skills/lit-plan/scripts/check-plan.mjs +39 -3
  69. package/plugin/skills/lit-plan/templates/plan.md +3 -0
  70. package/plugin/skills/lit-pptx/SKILL.md +8 -8
  71. package/plugin/skills/lit-pptx/fonts/jetbrains-mono/JetBrainsMono-Bold.ttf +0 -0
  72. package/plugin/skills/lit-pptx/fonts/jetbrains-mono/JetBrainsMono-Regular.ttf +0 -0
  73. package/plugin/skills/lit-pptx/fonts/jetbrains-mono/OFL.txt +93 -0
  74. package/plugin/skills/lit-pptx/fonts/provenance.json +32 -1
  75. package/plugin/skills/lit-pptx/references/agents/analyst.md +34 -56
  76. package/plugin/skills/lit-pptx/references/agents/antithesis.md +49 -67
  77. package/plugin/skills/lit-pptx/references/agents/architect.md +38 -51
  78. package/plugin/skills/lit-pptx/references/agents/critic.md +25 -41
  79. package/plugin/skills/lit-pptx/references/agents/synthesizer.md +37 -46
  80. package/plugin/skills/lit-pptx/references/agents/thesis.md +29 -49
  81. package/plugin/skills/lit-pptx/references/anti-slop-checklist.md +119 -145
  82. package/plugin/skills/lit-pptx/references/authoring-guide.md +187 -278
  83. package/plugin/skills/lit-pptx/references/consensus-protocol.md +99 -97
  84. package/plugin/skills/lit-pptx/references/data-display-cookbook.md +36 -137
  85. package/plugin/skills/lit-pptx/references/density-and-fill.md +147 -216
  86. package/plugin/skills/lit-pptx/references/design-system-azure.md +56 -85
  87. package/plugin/skills/lit-pptx/references/direction-step.md +134 -176
  88. package/plugin/skills/lit-pptx/references/examples/01-pitch-signal-ko.md +114 -115
  89. package/plugin/skills/lit-pptx/references/examples/02-pitch-studio-ko.md +66 -66
  90. package/plugin/skills/lit-pptx/references/examples/03-business-review-ledger-ko.md +63 -63
  91. package/plugin/skills/lit-pptx/references/examples/04-business-review-night-en.md +96 -96
  92. package/plugin/skills/lit-pptx/references/examples/05-research-talk-paper-en.md +81 -81
  93. package/plugin/skills/lit-pptx/references/examples/06-lecture-chalk-ko.md +103 -103
  94. package/plugin/skills/lit-pptx/references/examples/07-data-review-night-en.md +100 -98
  95. package/plugin/skills/lit-pptx/references/examples/08-image-led-atlas-ko.md +76 -76
  96. package/plugin/skills/lit-pptx/references/examples/09-briefing-gazette-ko.md +96 -96
  97. package/plugin/skills/lit-pptx/references/examples/10-status-update-ledger-ko.md +80 -80
  98. package/plugin/skills/lit-pptx/references/examples/11-portfolio-studio-en.md +72 -72
  99. package/plugin/skills/lit-pptx/references/examples/12-research-tutorial-chalk-en.md +95 -95
  100. package/plugin/skills/lit-pptx/references/examples/13-engineering-review-computational-brutalism-ko.md +173 -0
  101. package/plugin/skills/lit-pptx/references/examples/14-launch-pitch-neo-brutalism-ko.md +154 -0
  102. package/plugin/skills/lit-pptx/references/examples/15-design-lecture-bauhaus-ko.md +139 -0
  103. package/plugin/skills/lit-pptx/references/examples/16-community-programme-riso-ko.md +158 -0
  104. package/plugin/skills/lit-pptx/references/examples/17-public-data-briefing-newsroom-ko.md +179 -0
  105. package/plugin/skills/lit-pptx/references/interview-protocol.md +83 -102
  106. package/plugin/skills/lit-pptx/references/layout-families.md +161 -265
  107. package/plugin/skills/lit-pptx/references/stages/autopilot.md +30 -70
  108. package/plugin/skills/lit-pptx/references/stages/interview.md +36 -68
  109. package/plugin/skills/lit-pptx/references/stages/plan.md +26 -67
  110. package/plugin/skills/lit-pptx/references/title-treatments.md +93 -145
  111. package/plugin/skills/lit-pptx/references/tonalities/atlas.md +95 -108
  112. package/plugin/skills/lit-pptx/references/tonalities/bauhaus.md +140 -0
  113. package/plugin/skills/lit-pptx/references/tonalities/chalk.md +107 -122
  114. package/plugin/skills/lit-pptx/references/tonalities/computational-brutalism.md +150 -0
  115. package/plugin/skills/lit-pptx/references/tonalities/gazette.md +87 -111
  116. package/plugin/skills/lit-pptx/references/tonalities/ledger.md +96 -125
  117. package/plugin/skills/lit-pptx/references/tonalities/neo-brutalism.md +161 -0
  118. package/plugin/skills/lit-pptx/references/tonalities/newsroom.md +144 -0
  119. package/plugin/skills/lit-pptx/references/tonalities/night.md +104 -131
  120. package/plugin/skills/lit-pptx/references/tonalities/paper.md +114 -130
  121. package/plugin/skills/lit-pptx/references/tonalities/riso.md +137 -0
  122. package/plugin/skills/lit-pptx/references/tonalities/signal.md +96 -103
  123. package/plugin/skills/lit-pptx/references/tonalities/studio.md +81 -112
  124. package/plugin/skills/lit-pptx/scripts/compile-deck.js +4 -6
  125. package/plugin/skills/lit-pptx/scripts/craft_extras.py +135 -91
  126. package/plugin/skills/lit-pptx/scripts/deck_craft.py +1 -1
  127. package/plugin/skills/lit-pptx/scripts/embed_fonts.py +13 -1
  128. package/plugin/skills/lit-pptx/scripts/layout_inventory.py +1 -1
  129. package/plugin/skills/lit-pptx/scripts/learn_template.py +1 -1
  130. package/plugin/skills/lit-pptx/scripts/lib/grid-resolver.js +101 -110
  131. package/plugin/skills/lit-pptx/scripts/lib/layout-resolver.js +9 -15
  132. package/plugin/skills/lit-pptx/scripts/lib/render-pack.js +370 -563
  133. package/plugin/skills/lit-pptx/scripts/lib/slide-grid.js +104 -0
  134. package/plugin/skills/lit-pptx/scripts/lib/template-registry.js +57 -6
  135. package/plugin/skills/lit-pptx/scripts/qa_deck.py +6 -6
  136. package/plugin/skills/lit-pptx/scripts/render_pages.py +31 -0
  137. package/plugin/skills/lit-pptx/scripts/validate_pptx.py +1 -1
  138. package/plugin/skills/lit-pptx/specs/markdown-slide-spec-v1.md +167 -191
  139. package/plugin/skills/lit-pptx/specs/markdown-slide-spec-v2.md +117 -166
  140. package/plugin/skills/lit-pptx/specs/template-enrollment-contract.md +307 -330
  141. package/plugin/skills/lit-pptx/templates/tonalities/atlas/pack.yaml +1 -1
  142. package/plugin/skills/lit-pptx/templates/tonalities/bauhaus/pack.yaml +98 -0
  143. package/plugin/skills/lit-pptx/templates/tonalities/chalk/pack.yaml +1 -1
  144. package/plugin/skills/lit-pptx/templates/tonalities/computational-brutalism/pack.yaml +99 -0
  145. package/plugin/skills/lit-pptx/templates/tonalities/gazette/pack.yaml +1 -1
  146. package/plugin/skills/lit-pptx/templates/tonalities/ledger/pack.yaml +1 -1
  147. package/plugin/skills/lit-pptx/templates/tonalities/neo-brutalism/pack.yaml +107 -0
  148. package/plugin/skills/lit-pptx/templates/tonalities/newsroom/pack.yaml +99 -0
  149. package/plugin/skills/lit-pptx/templates/tonalities/night/pack.yaml +1 -1
  150. package/plugin/skills/lit-pptx/templates/tonalities/paper/pack.yaml +1 -1
  151. package/plugin/skills/lit-pptx/templates/tonalities/riso/pack.yaml +99 -0
  152. package/plugin/skills/lit-pptx/templates/tonalities/signal/pack.yaml +2 -2
  153. package/plugin/skills/lit-pptx/templates/tonalities/studio/pack.yaml +1 -1
  154. package/plugin/skills/lit-schematic/SKILL.md +114 -0
  155. package/plugin/skills/lit-schematic/examples/iso-heat-exchanger/build.mjs +38 -0
  156. package/plugin/skills/lit-schematic/examples/iso-heat-exchanger/scene.mjs +133 -0
  157. package/plugin/skills/lit-schematic/examples/journal-adsorption-rig/build.mjs +87 -0
  158. package/plugin/skills/lit-schematic/examples/pid-dosing-skid/build.mjs +85 -0
  159. package/plugin/skills/lit-schematic/references/cutaway-outputs.md +70 -0
  160. package/plugin/skills/lit-schematic/references/isometric-craft.md +101 -0
  161. package/plugin/skills/lit-schematic/references/journal-figures.md +72 -0
  162. package/plugin/skills/lit-schematic/references/kit-api.md +134 -0
  163. package/plugin/skills/lit-schematic/references/pfd-and-layout.md +53 -0
  164. package/plugin/skills/lit-schematic/references/pid-drafting.md +103 -0
  165. package/plugin/skills/lit-schematic/references/pid-symbols.md +163 -0
  166. package/plugin/skills/lit-schematic/references/verification.md +100 -0
  167. package/plugin/skills/lit-schematic/scripts/doctor.mjs +57 -0
  168. package/plugin/skills/lit-schematic/scripts/lib/figure.mjs +81 -0
  169. package/plugin/skills/lit-schematic/scripts/lib/fonts.mjs +27 -0
  170. package/plugin/skills/lit-schematic/scripts/lib/geom.mjs +113 -0
  171. package/plugin/skills/lit-schematic/scripts/lib/interactive.mjs +292 -0
  172. package/plugin/skills/lit-schematic/scripts/lib/isa.mjs +115 -0
  173. package/plugin/skills/lit-schematic/scripts/lib/iso.mjs +719 -0
  174. package/plugin/skills/lit-schematic/scripts/lib/legend-sheet.mjs +162 -0
  175. package/plugin/skills/lit-schematic/scripts/lib/pid.mjs +937 -0
  176. package/plugin/skills/lit-schematic/scripts/lib/png.mjs +132 -0
  177. package/plugin/skills/lit-schematic/scripts/lib/qa-core.mjs +658 -0
  178. package/plugin/skills/lit-schematic/scripts/lib/route.mjs +218 -0
  179. package/plugin/skills/lit-schematic/scripts/lib/sheet.mjs +890 -0
  180. package/plugin/skills/lit-schematic/scripts/lib/svg.mjs +82 -0
  181. package/plugin/skills/lit-schematic/scripts/lib/theme.mjs +115 -0
  182. package/plugin/skills/lit-schematic/scripts/motion.mjs +129 -0
  183. package/plugin/skills/lit-schematic/scripts/qa.mjs +92 -0
  184. package/plugin/skills/lit-schematic/scripts/render.mjs +233 -0
  185. package/plugin/skills/lit-schematic/scripts/scaffold.mjs +60 -0
  186. package/plugin/skills/lit-scientific-visualization/SKILL.md +17 -6
  187. package/plugin/skills/lit-typographic-motion/SKILL.md +58 -48
  188. package/plugin/skills/lit-typographic-motion/engine/THIRD_PARTY_NOTICES +13 -2
  189. package/plugin/skills/lit-typographic-motion/engine/blender/runner.py +218 -0
  190. package/plugin/skills/lit-typographic-motion/engine/core/presets.mjs +1 -1
  191. package/plugin/skills/lit-typographic-motion/engine/node/analysis.mjs +65 -1
  192. package/plugin/skills/lit-typographic-motion/engine/node/assets.mjs +298 -0
  193. package/plugin/skills/lit-typographic-motion/engine/node/blender.mjs +143 -0
  194. package/plugin/skills/lit-typographic-motion/engine/node/board.mjs +136 -0
  195. package/plugin/skills/lit-typographic-motion/engine/node/brief.mjs +7 -1
  196. package/plugin/skills/lit-typographic-motion/engine/node/chrome.mjs +9 -12
  197. package/plugin/skills/lit-typographic-motion/engine/node/cover-assets.mjs +5 -3
  198. package/plugin/skills/lit-typographic-motion/engine/node/cover-capture.mjs +7 -6
  199. package/plugin/skills/lit-typographic-motion/engine/node/cover-treatment.mjs +37 -4
  200. package/plugin/skills/lit-typographic-motion/engine/node/cover.mjs +19 -8
  201. package/plugin/skills/lit-typographic-motion/engine/node/done.mjs +45 -6
  202. package/plugin/skills/lit-typographic-motion/engine/node/frame-worker.mjs +7 -5
  203. package/plugin/skills/lit-typographic-motion/engine/node/gallery.mjs +121 -0
  204. package/plugin/skills/lit-typographic-motion/engine/node/host.mjs +34 -0
  205. package/plugin/skills/lit-typographic-motion/engine/node/house.mjs +44 -0
  206. package/plugin/skills/lit-typographic-motion/engine/node/look.mjs +34 -20
  207. package/plugin/skills/lit-typographic-motion/engine/node/pipeline.mjs +19 -9
  208. package/plugin/skills/lit-typographic-motion/engine/node/scaffold.mjs +210 -0
  209. package/plugin/skills/lit-typographic-motion/engine/node/score.mjs +639 -0
  210. package/plugin/skills/lit-typographic-motion/engine/node/sound-cli.mjs +21 -4
  211. package/plugin/skills/lit-typographic-motion/engine/node/sound.mjs +127 -29
  212. package/plugin/skills/lit-typographic-motion/engine/node/stage-capture.mjs +7 -6
  213. package/plugin/skills/lit-typographic-motion/engine/node/stage-gate.mjs +59 -5
  214. package/plugin/skills/lit-typographic-motion/engine/node/stage-qa.mjs +141 -9
  215. package/plugin/skills/lit-typographic-motion/engine/node/stage-serve.mjs +28 -5
  216. package/plugin/skills/lit-typographic-motion/engine/node/stage.mjs +82 -14
  217. package/plugin/skills/lit-typographic-motion/engine/node/styles.mjs +213 -0
  218. package/plugin/skills/lit-typographic-motion/engine/node/treatment.mjs +311 -10
  219. package/plugin/skills/lit-typographic-motion/engine/stage/cover-init.js +14 -2
  220. package/plugin/skills/lit-typographic-motion/engine/stage/init.js +11 -1
  221. package/plugin/skills/lit-typographic-motion/engine/stage/qa.js +6 -1
  222. package/plugin/skills/lit-typographic-motion/engine/stage/stage-kit.js +83 -0
  223. package/plugin/skills/lit-typographic-motion/engine/vendor/three/LICENSE +21 -0
  224. package/plugin/skills/lit-typographic-motion/engine/vendor/three/addons/environments/RoomEnvironment.js +144 -0
  225. package/plugin/skills/lit-typographic-motion/engine/vendor/three/addons/geometries/RoundedBoxGeometry.js +155 -0
  226. package/plugin/skills/lit-typographic-motion/engine/vendor/three/three.module.js +54571 -0
  227. package/plugin/skills/lit-typographic-motion/recipes/hero-3d/expected.json +69 -0
  228. package/plugin/skills/lit-typographic-motion/recipes/hero-3d/index.html +139 -0
  229. package/plugin/skills/lit-typographic-motion/recipes/orbit-loop/expected.json +6 -4
  230. package/plugin/skills/lit-typographic-motion/recipes/painted-light/expected.json +4 -2
  231. package/plugin/skills/lit-typographic-motion/recipes/weight-tide/expected.json +7 -5
  232. package/plugin/skills/lit-typographic-motion/references/cover.md +394 -443
  233. package/plugin/skills/lit-typographic-motion/references/craft-loop.md +57 -87
  234. package/plugin/skills/lit-typographic-motion/references/depth.md +122 -0
  235. package/plugin/skills/lit-typographic-motion/references/look.md +94 -129
  236. package/plugin/skills/lit-typographic-motion/references/runtime.md +58 -91
  237. package/plugin/skills/lit-typographic-motion/references/sound.md +130 -99
  238. package/plugin/skills/lit-typographic-motion/references/stage.md +190 -215
  239. package/plugin/skills/lit-typographic-motion/references/studio.md +245 -0
  240. package/plugin/skills/lit-typographic-motion/references/style-bibles.md +108 -97
  241. package/plugin/skills/lit-typographic-motion/references/treatment.md +191 -143
  242. package/plugin/skills/lit-typographic-motion/scripts/motion-doctor.mjs +17 -5
  243. package/plugin/skills/lit-typographic-motion/scripts/motion.mjs +47 -7
  244. package/plugin/skills/lit-typographic-motion/styles/paper.json +41 -0
  245. package/plugin/skills/lit-typographic-motion/styles/swiss-signal.json +41 -0
  246. package/plugin/skills/lit-typographic-motion/styles/terminalcore.json +42 -0
  247. package/plugin/skills/lit-typographic-motion/styles/tidal.json +41 -0
  248. package/plugin/skills/litresearch/SKILL.md +1 -0
  249. package/plugin/skills/readme-studio/SKILL.md +2 -0
  250. package/plugin/skills/review-work/SKILL.md +1 -1
  251. package/plugin/skills/start-work/SKILL.md +2 -2
@@ -0,0 +1,214 @@
1
+ // agy conversation transcripts for the lit-adhd collector. agy stores one JSONL file per conversation
2
+ // under `~/.gemini/antigravity-cli/brain/<id>/`. Each step has `step_index`, `source`, `type`,
3
+ // `status`, `content` and `created_at`. Files are read as head + tail only, under a shared budget,
4
+ // through descriptors opened without following links.
5
+
6
+ import { closeSync, constants, fstatSync, lstatSync, openSync, readSync, readdirSync } from 'node:fs';
7
+ import { join, relative } from 'node:path';
8
+
9
+ export const HEAD_BYTES = 64 * 1024;
10
+ export const TAIL_BYTES = 256 * 1024;
11
+ export const TOTAL_BUDGET_BYTES = 8 * 1024 * 1024;
12
+ const ACTIVE_MS = 15 * 60 * 1000;
13
+
14
+ export const makeBudget = (limit = TOTAL_BUDGET_BYTES) => ({ limit, used: 0, exhausted: false });
15
+
16
+ const readSlice = (fd, position, length, budget) => {
17
+ const allowed = Math.min(length, budget.limit - budget.used);
18
+ if (allowed <= 0) { budget.exhausted = true; return ''; }
19
+ const buffer = Buffer.alloc(allowed);
20
+ const read = readSync(fd, buffer, 0, allowed, position);
21
+ budget.used += read;
22
+ if (allowed < length) budget.exhausted = true;
23
+ return buffer.subarray(0, read).toString('utf8');
24
+ };
25
+
26
+ export const readTranscriptLines = (path, budget, { head = HEAD_BYTES, tail = TAIL_BYTES } = {}) => {
27
+ let fd;
28
+ try {
29
+ if (!lstatSync(path).isFile()) return null;
30
+ fd = openSync(path, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0));
31
+ const { size } = fstatSync(fd);
32
+ const chunks = size <= head + tail
33
+ ? [readSlice(fd, 0, size, budget)]
34
+ : [readSlice(fd, 0, head, budget), readSlice(fd, size - tail, tail, budget)];
35
+ const lines = [];
36
+ for (const chunk of chunks) {
37
+ for (const line of chunk.split('\n')) {
38
+ if (!line.trim()) continue;
39
+ try {
40
+ const parsed = JSON.parse(line);
41
+ if (parsed && typeof parsed === 'object') lines.push(parsed);
42
+ } catch {
43
+ // Partial or malformed line at a slice edge is skipped.
44
+ }
45
+ }
46
+ }
47
+ return lines;
48
+ } catch {
49
+ return null;
50
+ } finally {
51
+ if (fd !== undefined) closeSync(fd);
52
+ }
53
+ };
54
+
55
+ // agy 1.4.4 writes each conversation's steps to
56
+ // `~/.gemini/antigravity-cli/brain/<conversationId>/.system_generated/logs/transcript.jsonl` (the file the hook
57
+ // payload names as `transcriptPath`); `conversations/<id>.db` holds the host's own database and is never read.
58
+ // The transcript carries no workspace, so the collector passes the conversation ids it knows belong to the
59
+ // workspace (the route-state files under `$XDG_STATE_HOME/litgravity/sessions/<workspace hash>/`) and only those
60
+ // transcripts are opened. Without ids every conversation folder is listed.
61
+ export const transcriptPathOf = (geminiDir, id) => join(geminiDir, 'brain', id, '.system_generated', 'logs', 'transcript.jsonl');
62
+
63
+ export const findTranscripts = (geminiDir, ids = null) => {
64
+ let names = ids;
65
+ if (!names) {
66
+ try {
67
+ names = readdirSync(join(geminiDir, 'brain'), { withFileTypes: true }).filter((e) => e.isDirectory()).map((e) => e.name);
68
+ } catch {
69
+ return { status: 'unknown', files: [] };
70
+ }
71
+ }
72
+ const files = [];
73
+ for (const id of names) {
74
+ const path = transcriptPathOf(geminiDir, id);
75
+ try {
76
+ const st = lstatSync(path);
77
+ if (st.isFile()) files.push({ id, path, mtimeMs: st.mtimeMs });
78
+ } catch {
79
+ // This conversation has no transcript yet.
80
+ }
81
+ }
82
+ files.sort((a, b) => b.mtimeMs - a.mtimeMs);
83
+ return { status: files.length ? 'ok' : 'unknown', files };
84
+ };
85
+
86
+ // Tool arguments in the transcript are JSON-encoded strings (`"Path":"\"/a/b\""`); decode them once.
87
+ const argValue = (value) => {
88
+ if (typeof value !== 'string') return value;
89
+ try {
90
+ const parsed = JSON.parse(value);
91
+ return typeof parsed === 'string' ? parsed : value;
92
+ } catch {
93
+ return value;
94
+ }
95
+ };
96
+
97
+ const clip = (text, max) => {
98
+ const flat = String(text).replace(/\s+/gu, ' ').trim();
99
+ return flat.length > max ? `${flat.slice(0, max - 1)}…` : flat;
100
+ };
101
+
102
+ function extractRequest(content) {
103
+ if (typeof content !== 'string') return null;
104
+ const m = /<USER_REQUEST>\r?\n?([\s\S]*?)\r?\n?<\/USER_REQUEST>/.exec(content);
105
+ return (m ? m[1] : content).trim();
106
+ }
107
+
108
+ const WRITE_TOOLS = new Set(['write_file', 'write_to_file', 'replace_file_content', 'multi_replace_file_content']);
109
+ // What a tool call was about, in a few words: a file's base name or a subagent's type. Never a command
110
+ // line, a search query or file contents.
111
+ const actionTarget = (args) => {
112
+ const path = argValue(args?.Path ?? args?.TargetFile ?? args?.AbsolutePath);
113
+ if (typeof path === 'string' && path) return path.split(/[\\/]/u).at(-1);
114
+ const type = argValue(args?.TypeName);
115
+ return typeof type === 'string' && type ? type : null;
116
+ };
117
+ const WAITING_TEXT = /[??]\s*$|`?lit approve`?|`?lit deny`?|승인해\s*주|확인해\s*주|괜찮을까요|할까요/iu;
118
+ const APPROVAL_TEXT = /`?lit approve`?|`?lit deny`?|승인해\s*주/iu;
119
+ const BLOCKED_TEXT = /^\s*BLOCKED\b/mu;
120
+
121
+ // Why the newest turn ends waiting on the user, read from the steps after the last prompt: `question` when it called
122
+ // ask_question, `BLOCKED` for a blocked report, `approve` when it asks for a typed approval, `asked` for any other
123
+ // closing question, else null. The status line shows it; the brief marks the same turns waiting-on-user.
124
+ export const waitingReason = (lines) => {
125
+ if (!Array.isArray(lines)) return null;
126
+ const from = lines.findLastIndex((l) => l?.type === 'USER_INPUT');
127
+ let text = null;
128
+ let asked = false;
129
+ for (const line of lines.slice(from + 1)) {
130
+ if (line?.type !== 'PLANNER_RESPONSE') continue;
131
+ if (Array.isArray(line.tool_calls) && line.tool_calls.length) asked = line.tool_calls.some((c) => /ask_question/i.test(String(c?.name ?? '')));
132
+ if (typeof line.content === 'string' && line.content.trim()) text = line.content;
133
+ }
134
+ if (asked) return 'question';
135
+ if (!text) return null;
136
+ const tail = text.slice(-400);
137
+ if (BLOCKED_TEXT.test(text)) return 'BLOCKED';
138
+ if (APPROVAL_TEXT.test(tail)) return 'approve';
139
+ return WAITING_TEXT.test(tail) ? 'asked' : null;
140
+ };
141
+
142
+ // One session's record from its agy transcript lines.
143
+ export const sessionRecord = (lines, { redact = (t) => t, now = Date.now(), cwd: workspace = null, live = null, finished = false } = {}) => {
144
+ if (!lines || !lines.length) return null;
145
+ let cwd = workspace;
146
+ let started = null;
147
+ let last = null;
148
+ let lastEntry = null;
149
+ const prompts = [];
150
+ const tools = {};
151
+ const files = [];
152
+ let result = null;
153
+ let lastAction = null;
154
+ for (const line of lines) {
155
+ if (typeof line.cwd === 'string') cwd ??= line.cwd;
156
+ const at = Date.parse(line.created_at);
157
+ if (Number.isFinite(at)) {
158
+ started = started === null ? at : Math.min(started, at);
159
+ last = last === null ? at : Math.max(last, at);
160
+ }
161
+ if (line.type === 'USER_INPUT' && typeof line.content === 'string') {
162
+ const text = extractRequest(line.content);
163
+ if (text) {
164
+ prompts.push(text);
165
+ lastEntry = { role: 'user', text };
166
+ }
167
+ }
168
+ if (line.type === 'PLANNER_RESPONSE' && typeof line.content === 'string' && line.content.trim()) {
169
+ result = line.content;
170
+ lastEntry = { role: 'assistant', text: line.content };
171
+ }
172
+ if (line.type === 'PLANNER_RESPONSE' && Array.isArray(line.tool_calls)) {
173
+ for (const call of line.tool_calls) {
174
+ if (typeof call?.name !== 'string') continue;
175
+ tools[call.name] = (tools[call.name] ?? 0) + 1;
176
+ const path = argValue(call.args?.Path ?? call.args?.TargetFile);
177
+ if (WRITE_TOOLS.has(call.name) && typeof path === 'string') files.push(path);
178
+ const target = actionTarget(call.args);
179
+ lastAction = { tool: call.name, ...(target ? { target } : {}) };
180
+ lastEntry = { role: 'tool' };
181
+ }
182
+ }
183
+ }
184
+ const relativeFile = (path) => {
185
+ if (!cwd) return path;
186
+ const inside = relative(cwd, path);
187
+ return inside && !inside.startsWith('..') ? inside : path;
188
+ };
189
+ const changed = [...new Set(files.reverse())].slice(0, 5).map((p) => redact(relativeFile(p)));
190
+ const asked = [...new Set([prompts[0], prompts.at(-1)].filter(Boolean))].slice(0, 2).map((t) => clip(redact(t), 160));
191
+ const waiting = lastEntry?.role === 'assistant' && WAITING_TEXT.test(lastEntry.text.slice(-400));
192
+ // A question on record wins; then a finished plan; then the hooks' liveness record (`alive`, `idle`); the
193
+ // transcript's own clock decides only when neither says more.
194
+ const clock = last === null ? 'unknown' : now - last < ACTIVE_MS ? 'active' : 'ended';
195
+ const status = waiting ? 'waiting-on-user' : finished ? 'done' : live === 'alive' ? 'active' : live === 'idle' ? 'idle' : clock;
196
+ // agy does not carry a sessionId in the transcript; use the conversation folder name if available.
197
+ const sessionId = lines.find((l) => typeof l.conversation_id === 'string')?.conversation_id ?? null;
198
+ return {
199
+ sessionId,
200
+ id8: sessionId ? sessionId.slice(0, 8) : 'unknown',
201
+ worktree: cwd ? redact(cwd) : 'unknown',
202
+ cwd,
203
+ started: started === null ? 'unknown' : new Date(started).toISOString(),
204
+ last: last === null ? 'unknown' : new Date(last).toISOString(),
205
+ lastMs: last,
206
+ title: clip(redact(prompts[0] ?? 'unknown'), 80),
207
+ asked: asked.length ? asked : ['unknown'],
208
+ done: { tools, files: changed, commits: [] },
209
+ lastAction: lastAction ? { tool: clip(redact(lastAction.tool), 40), ...(lastAction.target ? { target: clip(redact(lastAction.target), 60) } : {}) } : null,
210
+ result: result ? clip(redact(result), 240) : 'unknown',
211
+ status,
212
+ ...(waiting ? { waitingReason: 'asked the user' } : {}),
213
+ };
214
+ };
@@ -5,6 +5,7 @@ export const SKILL_ROUTES = [
5
5
  { id: 'lit-loop', when: 'bare `lit`, or a multi-step task that needs criteria, tests and proof' },
6
6
  { id: 'litgoal', when: 'set, check or close a finish line that outlives this conversation' },
7
7
  { id: 'litwork', when: 'ship one contained change with proof: implement, fix, land' },
8
+ { id: 'lit-hijack', when: 'port the know-how from someone else\'s published work into your own skill or system, clean-room' },
8
9
  { id: 'lit-plan', when: 'plan before code; the turn writes plans/<slug>.md and nothing else' },
9
10
  { id: 'lit-brainstorm', when: 'open ideation: spread out on options, score a shortlist, hand off' },
10
11
  { id: 'deep-interview', when: 'the request is vague or broad and needs questions first' },
@@ -30,12 +31,14 @@ export const SKILL_ROUTES = [
30
31
  { id: 'readme-studio', when: 'write or refresh a README from repository facts' },
31
32
  { id: 'lit-docx', when: 'a Word document, or DOCX/PDF converted to Markdown (needs Python)' },
32
33
  { id: 'lit-pptx', when: 'a slide deck (needs Python)' },
34
+ { id: 'lit-schematic', when: 'a P&ID, PFD, equipment layout, journal apparatus figure or isometric cutaway of real hardware' },
33
35
  { id: 'lit-scientific-visualization', when: 'a publication-ready figure from data' },
34
36
  { id: 'lit-diagram-drawer', when: 'an architecture, workflow or timeline diagram' },
35
37
  { id: 'lit-typographic-motion', when: 'a short film, kinetic type, lyric video or a seamless README cover loop' },
36
38
  { id: 'autoresearch', when: 'a budgeted experiment loop against a metric' },
37
39
  { id: 'structural-search', when: 'find or rewrite code by syntax shape' },
38
40
  { id: 'browser-drive', when: 'the answer only exists inside a running web page' },
41
+ { id: 'lit-adhd', when: 'cross-session brief: what each recent session was asked, did and waits on, with progress gauges' },
39
42
  { id: 'lit-team', when: 'two or more child agents behind one durable team packet' },
40
43
  { id: 'autoconference', when: 'a budgeted research conference: parallel researchers, review, synthesis' },
41
44
  { id: 'rules', when: 'which rules, AGENTS.md files and skills agy loads, and in what order' },
@@ -44,11 +47,18 @@ export const SKILL_ROUTES = [
44
47
  ];
45
48
 
46
49
  export const SKILL_IDS = new Set(SKILL_ROUTES.map((r) => r.id));
50
+ // Skill ids that are another name for a skill: typed whole, slashed or after `lit`, they take its route.
51
+ export const SKILL_ALIASES = { 'lit-rewind': 'lit-adhd' };
52
+ const skillId = (word) => (SKILL_IDS.has(word) ? word : SKILL_ALIASES[word]);
47
53
 
48
54
  // The word after a leading `lit` picks the route: a word below, or any skill id typed whole (`lit debugging …`,
49
55
  // `lit comment-checker …`); anything else falls back to lit-loop.
50
56
  export const KEYWORD_ROUTES = {
51
57
  loop: 'lit-loop',
58
+ hijack: 'lit-hijack',
59
+ hijacking: 'lit-hijack',
60
+ '하이재킹': 'lit-hijack',
61
+ '하이잭': 'lit-hijack',
52
62
  plan: 'lit-plan',
53
63
  work: 'litwork',
54
64
  goal: 'litgoal',
@@ -73,6 +83,8 @@ export const KEYWORD_ROUTES = {
73
83
  ideate: 'lit-brainstorm',
74
84
  idea: 'lit-brainstorm',
75
85
  ideas: 'lit-brainstorm',
86
+ adhd: 'lit-adhd',
87
+ rewind: 'lit-adhd',
76
88
  team: 'lit-team',
77
89
  conference: 'autoconference',
78
90
  rules: 'rules',
@@ -93,11 +105,21 @@ export const KEYWORD_ROUTES = {
93
105
  pptx: 'lit-pptx',
94
106
  ppt: 'lit-pptx',
95
107
  docx: 'lit-docx',
108
+ schematic: 'lit-schematic',
109
+ pid: 'lit-schematic',
110
+ pfd: 'lit-schematic',
111
+ cutaway: 'lit-schematic',
112
+ '계통도': 'lit-schematic',
113
+ '공정도': 'lit-schematic',
114
+ '모식도': 'lit-schematic',
115
+ '장치도': 'lit-schematic',
96
116
  diagram: 'lit-diagram-drawer',
97
117
  '다이어그램': 'lit-diagram-drawer',
98
118
  '도식': 'lit-diagram-drawer',
99
119
  figure: 'lit-scientific-visualization',
100
120
  plot: 'lit-scientific-visualization',
121
+ frontend: 'frontend-ui-ux',
122
+ ui: 'frontend-ui-ux',
101
123
  code: 'lit-code',
102
124
  tdd: 'lit-code',
103
125
  structural: 'structural-search',
@@ -128,8 +150,54 @@ export function motionIntent(task) {
128
150
  return FILM_COMPOUND.test(text) || (VIDEO_NOUN.test(text) && MAKE_VERB.test(text));
129
151
  }
130
152
 
153
+ // Physical schematics: P&IDs, PFDs, apparatus figures, isometric cutaways. A strong noun names a drawing and routes
154
+ // alone; a weak noun needs a draw or make verb. Interface deliverables and chart nouns stay with their owners.
155
+ const SCHEMATIC_STRONG = /\bp\s?&\s?i\s?ds?\b|\bpfds?\b|\bbfds?\b|piping\s+(?:and|&)\s+instrumentation|process\s+flow\s+(?:diagram|sheet)s?|block\s+flow\s+diagrams?|\bplot\s+plans?\b|equipment\s+layouts?|experimental\s+(?:set\s?up|apparatus)|\bcut\s?aways?\b|컷어웨이|배관\s?계장도|계장도|공정\s?흐름도|공정도|모식도|장치도|실험\s?장치|피앤아이디|배치도|계통도|단면도/iu;
156
+ const SCHEMATIC_WEAK = /\bschematics?\b|\bisometric\b|\bapparatus\b|사시도|개략도|아이소메트릭|도면/iu;
157
+ const SCHEMATIC_CHART = /차트|그래프|\b(?:charts?|graphs?|plots?(?!\s+plans?\b))\b/iu;
158
+ const SCHEMATIC_DRAW_VERB = /\b(?:draw|drawing|drew|sketch|sketching|illustrate|illustrating|render|rendering|redraw)\b|그려|그리|그림|도식|작도/iu;
159
+ const SCHEMATIC_INTERFACE = /\b(?:dashboards?|landing\s?pages?|web\s?pages?|websites?|homepages?|web\s?apps?|apps?|screens?|admin\s?(?:panel|console)|user\s?interface|ui)\b|대시보드|웹사이트|랜딩|페이지|화면|앱/iu;
160
+ const SCHEMATIC_MAKE_VERB = /\b(?:make|making|create|creating|design|designing|build|lay\s?out)\b|만들|만드/iu;
161
+ const SCHEMATIC_OFFICE = /보고서|발표자료|슬라이드|문서|\b(?:reports?|slides?|presentations?|documents?)\b/iu;
162
+ export function schematicIntent(task) {
163
+ const text = String(task ?? '');
164
+ if (SCHEMATIC_CHART.test(text)) return false;
165
+ if (SCHEMATIC_INTERFACE.test(text) && !SCHEMATIC_DRAW_VERB.test(text)) return false;
166
+ if (SCHEMATIC_OFFICE.test(text) && !SCHEMATIC_DRAW_VERB.test(text)) return false;
167
+ if (SCHEMATIC_STRONG.test(text)) return true;
168
+ return SCHEMATIC_WEAK.test(text) && (SCHEMATIC_DRAW_VERB.test(text) || SCHEMATIC_MAKE_VERB.test(text));
169
+ }
170
+
171
+ // A slide count beside a slide noun ("덱 10장", "a 10-slide deck") asks for the deck without a making verb.
172
+ const SLIDE_COUNT = /\d+\s?장|\b\d+[\s-]?slides?\b/u;
173
+ const SLIDE_NOUN = /덱|슬라이드|발표자료|프레젠테이션|피티|\bdecks?\b|\bslides?\b|\bpresentations?\b/iu;
174
+ const OFFICE_VERB = /만들|작성|써|쓰|뽑아|정리|\b(?:make|create|write|draft|prepare|build)\b/iu;
175
+ const PHOTO_NOT_SLIDE = /사진|이미지|보정|편집|촬영|\bphotos?\b|\bimages?\b/iu;
176
+ export function deckIntent(task) {
177
+ const text = String(task ?? '');
178
+ if (PHOTO_NOT_SLIDE.test(text)) return false;
179
+ const counted = SLIDE_COUNT.test(text) && SLIDE_NOUN.test(text);
180
+ return counted || (SLIDE_NOUN.test(text) && OFFICE_VERB.test(text));
181
+ }
182
+
183
+ // An English build-intent task ("build a landing page", "create a dashboard") goes to frontend-ui-ux.
184
+ // The verb and noun halves are both required so "build an API" or "design the schema" stay inert.
185
+ // Korean verbs (만들, 디자인, 꾸미, etc.) with a surface noun (화면, 페이지, 대시보드, 인터페이스) also route.
186
+ const UI_BUILD_VERB = /\b(?:build|create|make(?!\s+sure\b)|implement|code|develop)\b/u;
187
+ const UI_PAGE_NOUN = /\b(?:landing\s?page|web\s?page|website|web\s?site|homepage|home\s?page|dashboard|admin\s?(?:panel|console|ui)|settings\s?(?:page|screen)|(?:sign\s?up|log\s?in|checkout|pricing|profile|onboarding)\s?(?:page|screen|form|flow)|user\s?interface|web\s?ui|front\s?end|ui)\b/u;
188
+ const UI_DESIGN_VERB = /\b(?:re)?(?:design(?:ing|ed)?|styl(?:e|ing|ed)|skin(?:ning)?|theme|theming)\b|\b(?:mock\s?-?up|lay\s?out|polish(?:ing)?|revamp)\b|디자인|만들|만드|개편|꾸미|꾸며|다듬|배치|구성/u;
189
+ const UI_SURFACE_NOUN = /\b(?:ui|ux|interface|screen|page|view|component|layout|dashboard|css|styling|stylesheet|typography|palette|dark\s?mode|responsive)\b|화면|페이지|인터페이스|레이아웃|대시보드|컴포넌트|스타일|테마|다크\s?모드|반응형|디자인\s?시스템|사이드바|푸터|툴바|위젯/u;
190
+ const NON_INTERFACE_BUILD = /\b(?:grafana|kibana|datadog|metabase|looker|tableau|power\s?bi|backend|back\s?end|api|endpoint|docker|image|cli|migration|schema)\b/iu;
191
+ export function frontendIntent(task) {
192
+ const text = String(task ?? '');
193
+ if (NON_INTERFACE_BUILD.test(text)) return false;
194
+ if (UI_BUILD_VERB.test(text) && UI_PAGE_NOUN.test(text)) return true;
195
+ return UI_DESIGN_VERB.test(text) && UI_SURFACE_NOUN.test(text);
196
+ }
197
+
131
198
  const RESTART_WORDS = new Set(['new', 'restart']);
132
199
  const CONTINUE_WORDS = new Set(['continue', 'resume']);
200
+ const APPROVE_WORDS = new Set(['approve', 'deny']);
133
201
  const SEPARATORS = /^[\s:,.!?]+/;
134
202
  const firstWord = (s) => (/^([^\s:,.!?]+)/.exec(s)?.[1] ?? '').toLowerCase();
135
203
 
@@ -157,17 +225,23 @@ export function detectRoute(prompt) {
157
225
  word = firstWord(rest);
158
226
  }
159
227
  const resume = !restart && CONTINUE_WORDS.has(word);
228
+ const approve = !restart && !resume && APPROVE_WORDS.has(word);
160
229
  const bare = !restart && (word === '' || (resume && rest.slice(word.length).trim() === ''));
161
- const route = KEYWORD_ROUTES[word] ?? (SKILL_IDS.has(word) ? word : undefined);
162
- const base = { keyword: route ? word : null, bare, resume, restart, direct: false, empty: word === '' || (resume && rest.slice(word.length).trim() === '') };
163
- if (!route && !bare && !resume && motionIntent(rest)) return { route: 'lit-typographic-motion', ...base, keyword: null };
230
+ const route = KEYWORD_ROUTES[word] ?? skillId(word);
231
+ const base = { keyword: route ? word : null, bare, resume, restart, approve: approve ? word : null, direct: false, empty: word === '' || (resume && rest.slice(word.length).trim() === '') };
232
+ if (!route && !bare && !resume) {
233
+ if (schematicIntent(rest)) return { route: 'lit-schematic', ...base, keyword: null };
234
+ if (motionIntent(rest)) return { route: 'lit-typographic-motion', ...base, keyword: null };
235
+ if (deckIntent(rest)) return { route: 'lit-pptx', ...base, keyword: null };
236
+ if (frontendIntent(rest)) return { route: 'frontend-ui-ux', ...base, keyword: null };
237
+ }
164
238
  const hit = { route: route ?? 'lit-loop', ...base };
165
239
  if (hit.route === 'review-work') {
166
240
  hit.reviewMode = REVIEW_MODES[firstWord(rest.slice(word.length).replace(SEPARATORS, ''))] ?? null;
167
241
  }
168
242
  return hit;
169
243
  }
170
- if (lower.startsWith('lit') && SKILL_IDS.has(lower)) return { route: lower, keyword: null, bare: false, resume: false, restart: false, direct: true, empty: false };
171
- if (SKILL_IDS.has(lower) && slash) return { route: lower, keyword: null, bare: false, resume: false, restart: false, direct: true, empty: false };
244
+ const id = skillId(lower);
245
+ if (id && (lower.startsWith('lit') || slash)) return { route: id, keyword: null, bare: false, resume: false, restart: false, direct: true, empty: false };
172
246
  return null;
173
247
  }
@@ -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,48 @@
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 { markLive } from './lib/liveness.mjs';
9
+ import { READ_ONLY_DISCIPLINES, applyStackEvent, readStack, writeStack } from './lib/workflow-stack.mjs';
10
+ import { ROUTE_LOOKS } from '../hud/looks.mjs';
5
11
 
6
12
  const GOAL_FILE = /\.litgravity\/goals\/([A-Za-z0-9._-]+\.json)/;
7
13
 
14
+ // The model can load a skill that has a status-line look on its own, without a route word: it reads this plugin's
15
+ // SKILL.md of that skill, or runs the lit-adhd collector. That starts the route as its route word would, so the line
16
+ // takes the same look whichever way the skill was entered. Only this installed copy counts (a repo checkout of a skill
17
+ // is source code), and a work route already running keeps its route.
18
+ const ROOTS = [...new Set([PLUGIN_ROOT, (() => { try { return realpathSync(PLUGIN_ROOT); } catch { return PLUGIN_ROOT; } })()])];
19
+ const LOOK_SKILLS = new Map(Object.keys(ROUTE_LOOKS).flatMap((id) => ROOTS.map((r) => [join(r, 'skills', id, 'SKILL.md'), id])));
20
+ const ADHD_COLLECTOR = ROOTS.map((r) => join(r, 'skills', 'lit-adhd', 'scripts', 'rewind.mjs'));
21
+
22
+ function loadedSkill(payload, args) {
23
+ const workspace = workspaceOf(payload) ?? process.cwd();
24
+ const hit = targetPaths(args).map((p) => LOOK_SKILLS.get(resolve(workspace, p))).find(Boolean);
25
+ if (hit) return hit;
26
+ return typeof args.CommandLine === 'string' && ADHD_COLLECTOR.some((c) => args.CommandLine.includes(c)) ? 'lit-adhd' : null;
27
+ }
28
+
29
+ function startLoadedSkill(payload, args) {
30
+ const state = readSession(payload);
31
+ if (state?.corrupt || (state?.route && !READ_ONLY_DISCIPLINES.includes(state.route))) return;
32
+ const route = loadedSkill(payload, args);
33
+ if (!route || state?.route === route) return;
34
+ writeSession(payload, { ...(state ?? {}), route, activatedAt: Date.now(), stopHeldFor: null, lastKind: 'ignite' });
35
+ const workspace = workspaceOf(payload);
36
+ const { stack } = applyStackEvent(readStack(workspace, payload.conversationId), { type: 'start', skill: route });
37
+ writeStack(workspace, payload.conversationId, stack);
38
+ appendLedger(payload, { kind: 'route', route, how: 'skill-load' });
39
+ }
40
+
8
41
  // While a route is active every tool call leaves one ledger line, and a call that touches a goal record binds that
9
42
  // record to this conversation, which is what lets the Stop hook hold the turn on its open criteria.
10
43
  run((payload) => {
44
+ try { markLive(workspaceOf(payload), payload.conversationId, 'alive'); } catch { /* liveness never blocks */ }
45
+ if (toolName(payload)) startLoadedSkill(payload, toolArgs(payload));
11
46
  const state = activeRoute(payload);
12
47
  if (!state || state.corrupt) return {};
13
48
  const tool = toolName(payload);
@@ -26,5 +61,8 @@ run((payload) => {
26
61
  if (state.goalPath !== goalPath) writeSession(payload, { ...state, goalPath });
27
62
  }
28
63
  if (state.route === MOTION_ROUTE) recordMotionTool(payload);
64
+ if (/invoke_subagent|define_subagent/i.test(tool)) {
65
+ try { recordLane(workspaceOf(payload), payload.conversationId, payload); } catch { /* lane tracking never blocks */ }
66
+ }
29
67
  return {};
30
68
  });