@litfamily/litcodex 1.0.27 → 1.0.29

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 (204) hide show
  1. package/README-Ko-KR.md +10 -10
  2. package/README.md +10 -10
  3. package/dist/cli.d.ts +3 -2
  4. package/dist/cli.js +73 -4
  5. package/dist/config-migration/cli.js +11 -3
  6. package/dist/install/generated-skill-payload-hashes.d.ts +58 -30
  7. package/dist/install/generated-skill-payload-hashes.js +58 -30
  8. package/dist/install/index.js +1 -1
  9. package/dist/install/motion-runtime.d.ts +4 -1
  10. package/dist/install/motion-runtime.js +15 -4
  11. package/dist/install/office-runtime.d.ts +10 -11
  12. package/dist/install/office-runtime.js +8 -3
  13. package/dist/install/skill-catalog.d.ts +1 -1
  14. package/dist/install/skill-catalog.js +1 -0
  15. package/dist/postinstall.js +16 -3
  16. package/dist/pty-helper.d.ts +7 -0
  17. package/dist/pty-helper.js +45 -0
  18. package/dist/run.d.ts +57 -0
  19. package/dist/run.js +354 -0
  20. package/marketplace/plugins/litcodex/.codex-plugin/plugin.json +1 -1
  21. package/marketplace/plugins/litcodex/components/auto-update/dist/auto-update.d.ts +12 -0
  22. package/marketplace/plugins/litcodex/components/auto-update/dist/auto-update.js +31 -2
  23. package/marketplace/plugins/litcodex/components/auto-update/package.json +1 -1
  24. package/marketplace/plugins/litcodex/components/comment-checker/package.json +1 -1
  25. package/marketplace/plugins/litcodex/components/git-bash/package.json +1 -1
  26. package/marketplace/plugins/litcodex/components/lit-loop/directive.md +2 -1
  27. package/marketplace/plugins/litcodex/components/lit-loop/directives/deep-interview.md +2 -0
  28. package/marketplace/plugins/litcodex/components/lit-loop/directives/lit-brainstorm.md +216 -0
  29. package/marketplace/plugins/litcodex/components/lit-loop/directives/litgoal.md +8 -1
  30. package/marketplace/plugins/litcodex/components/lit-loop/directives/review-work.md +12 -4
  31. package/marketplace/plugins/litcodex/components/lit-loop/dist/card-status.d.ts +8 -3
  32. package/marketplace/plugins/litcodex/components/lit-loop/dist/card-status.js +11 -6
  33. package/marketplace/plugins/litcodex/components/lit-loop/dist/codex-hook.d.ts +6 -1
  34. package/marketplace/plugins/litcodex/components/lit-loop/dist/codex-hook.js +16 -5
  35. package/marketplace/plugins/litcodex/components/lit-loop/dist/guards.d.ts +3 -1
  36. package/marketplace/plugins/litcodex/components/lit-loop/dist/guards.js +5 -2
  37. package/marketplace/plugins/litcodex/components/lit-loop/dist/hook-cli.d.ts +2 -0
  38. package/marketplace/plugins/litcodex/components/lit-loop/dist/hook-cli.js +53 -17
  39. package/marketplace/plugins/litcodex/components/lit-loop/dist/hud-cli.d.ts +38 -0
  40. package/marketplace/plugins/litcodex/components/lit-loop/dist/hud-cli.js +155 -0
  41. package/marketplace/plugins/litcodex/components/lit-loop/dist/hud.d.ts +42 -0
  42. package/marketplace/plugins/litcodex/components/lit-loop/dist/hud.js +297 -0
  43. package/marketplace/plugins/litcodex/components/lit-loop/dist/markers.d.ts +2 -0
  44. package/marketplace/plugins/litcodex/components/lit-loop/dist/markers.js +2 -0
  45. package/marketplace/plugins/litcodex/components/lit-loop/dist/modes.d.ts +1 -1
  46. package/marketplace/plugins/litcodex/components/lit-loop/dist/modes.js +9 -1
  47. package/marketplace/plugins/litcodex/components/lit-loop/dist/motion-route.js +2 -0
  48. package/marketplace/plugins/litcodex/components/lit-loop/dist/plan-persistence.d.ts +2 -0
  49. package/marketplace/plugins/litcodex/components/lit-loop/dist/plan-persistence.js +8 -0
  50. package/marketplace/plugins/litcodex/components/lit-loop/dist/reentry.d.ts +56 -0
  51. package/marketplace/plugins/litcodex/components/lit-loop/dist/reentry.js +171 -0
  52. package/marketplace/plugins/litcodex/components/lit-loop/dist/route-context.js +5 -2
  53. package/marketplace/plugins/litcodex/components/lit-loop/dist/route-heads.js +35 -15
  54. package/marketplace/plugins/litcodex/components/lit-loop/dist/run-filter.d.ts +23 -0
  55. package/marketplace/plugins/litcodex/components/lit-loop/dist/run-filter.js +142 -0
  56. package/marketplace/plugins/litcodex/components/lit-loop/dist/run-panel.d.ts +29 -0
  57. package/marketplace/plugins/litcodex/components/lit-loop/dist/run-panel.js +102 -0
  58. package/marketplace/plugins/litcodex/components/lit-loop/dist/screen-card.d.ts +24 -0
  59. package/marketplace/plugins/litcodex/components/lit-loop/dist/screen-card.js +104 -0
  60. package/marketplace/plugins/litcodex/components/lit-loop/dist/screen-status.d.ts +24 -0
  61. package/marketplace/plugins/litcodex/components/lit-loop/dist/screen-status.js +110 -0
  62. package/marketplace/plugins/litcodex/components/lit-loop/dist/skill-mention-scope.js +2 -0
  63. package/marketplace/plugins/litcodex/components/lit-loop/dist/statusline.d.ts +17 -0
  64. package/marketplace/plugins/litcodex/components/lit-loop/dist/statusline.js +113 -0
  65. package/marketplace/plugins/litcodex/components/lit-loop/dist/trigger.d.ts +2 -2
  66. package/marketplace/plugins/litcodex/components/lit-loop/dist/trigger.js +15 -5
  67. package/marketplace/plugins/litcodex/components/lit-loop/dist/workflow-map.d.ts +7 -0
  68. package/marketplace/plugins/litcodex/components/lit-loop/dist/workflow-map.js +59 -10
  69. package/marketplace/plugins/litcodex/components/lit-loop/package.json +1 -1
  70. package/marketplace/plugins/litcodex/components/lsp/package.json +1 -1
  71. package/marketplace/plugins/litcodex/components/rules/bundled-rules/lit-humanizer.md +2 -0
  72. package/marketplace/plugins/litcodex/components/rules/dist/deliverable-hedge-guard.d.ts +8 -0
  73. package/marketplace/plugins/litcodex/components/rules/dist/deliverable-hedge-guard.js +381 -39
  74. package/marketplace/plugins/litcodex/components/rules/dist/model-metadata.d.ts +16 -0
  75. package/marketplace/plugins/litcodex/components/rules/dist/model-metadata.js +37 -1
  76. package/marketplace/plugins/litcodex/components/rules/package.json +1 -1
  77. package/marketplace/plugins/litcodex/components/start-work-continuation/package.json +1 -1
  78. package/marketplace/plugins/litcodex/components/telemetry/package.json +1 -1
  79. package/marketplace/plugins/litcodex/components/wikify-knowledge/package.json +1 -1
  80. package/marketplace/plugins/litcodex/skills/browser-drive/scripts/capability-probe.mjs +24 -4
  81. package/marketplace/plugins/litcodex/skills/deep-interview/SKILL.md +3 -1
  82. package/marketplace/plugins/litcodex/skills/lit-brainstorm/SKILL.md +271 -0
  83. package/marketplace/plugins/litcodex/skills/lit-brainstorm/agents/openai.yaml +6 -0
  84. package/marketplace/plugins/litcodex/skills/lit-diagram-drawer/scripts/doctor.mjs +4 -3
  85. package/marketplace/plugins/litcodex/skills/lit-diagram-drawer/scripts/export.mjs +6 -5
  86. package/marketplace/plugins/litcodex/skills/lit-diagram-drawer/scripts/runtime-probes.mjs +25 -0
  87. package/marketplace/plugins/litcodex/skills/lit-docx/scripts/convert_md_to_pdf.py +31 -1
  88. package/marketplace/plugins/litcodex/skills/lit-docx/templates/latex/acs/template.tex +2 -0
  89. package/marketplace/plugins/litcodex/skills/lit-docx/templates/latex/elsevier/template.tex +2 -0
  90. package/marketplace/plugins/litcodex/skills/lit-docx/templates/latex/ieee/template.tex +2 -0
  91. package/marketplace/plugins/litcodex/skills/lit-docx/templates/latex/korean-generic/template.tex +2 -0
  92. package/marketplace/plugins/litcodex/skills/lit-docx/templates/latex/nature/template.tex +2 -0
  93. package/marketplace/plugins/litcodex/skills/lit-humanizer/SKILL.md +4 -0
  94. package/marketplace/plugins/litcodex/skills/lit-humanizer/scripts/core.mjs +5 -1
  95. package/marketplace/plugins/litcodex/skills/lit-loop/SKILL.md +10 -2
  96. package/marketplace/plugins/litcodex/skills/lit-pptx/scripts/office-run.mjs +42 -10
  97. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/SKILL.md +11 -9
  98. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/agents/openai.yaml +3 -0
  99. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/THIRD_PARTY_NOTICES +4 -0
  100. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/constants.mjs +38 -0
  101. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/cover-assets.mjs +113 -0
  102. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/cover-capture.mjs +161 -0
  103. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/cover-gate.mjs +327 -0
  104. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/cover-image.mjs +136 -0
  105. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/cover-init.js +43 -0
  106. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/cover-sheet.mjs +69 -0
  107. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/cover-treatment.mjs +102 -0
  108. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/cover-worker.mjs +21 -0
  109. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/cover.mjs +352 -0
  110. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/driver.mjs +19 -1
  111. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/fonts.mjs +11 -0
  112. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/look.mjs +128 -2
  113. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/loop-kit.js +104 -0
  114. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/runtime.mjs +92 -18
  115. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/stage.mjs +2 -0
  116. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/treatment.mjs +3 -2
  117. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/webp.mjs +140 -0
  118. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/fonts/jetbrains-mono/JetBrainsMono-wght-latin.woff2 +0 -0
  119. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/fonts/jetbrains-mono/OFL.txt +93 -0
  120. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/recipes/negatives/card-scenes/expected.json +16 -0
  121. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/recipes/negatives/card-scenes/index.html +42 -0
  122. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/recipes/negatives/reset-sweep/expected.json +16 -0
  123. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/recipes/negatives/reset-sweep/index.html +27 -0
  124. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/recipes/negatives/still-glow/expected.json +17 -0
  125. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/recipes/negatives/still-glow/index.html +29 -0
  126. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/recipes/negatives/title-slam/expected.json +17 -0
  127. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/recipes/negatives/title-slam/index.html +44 -0
  128. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/recipes/orbit-loop/expected.json +67 -0
  129. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/recipes/orbit-loop/index.html +182 -0
  130. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/recipes/painted-light/expected.json +95 -0
  131. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/recipes/painted-light/index.html +231 -0
  132. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/recipes/weight-tide/expected.json +67 -0
  133. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/recipes/weight-tide/index.html +103 -0
  134. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/references/cover.md +389 -0
  135. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/references/quality-gate.md +4 -0
  136. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/references/runtime.md +7 -6
  137. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/references/stage.md +3 -1
  138. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/references/treatment.md +2 -0
  139. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/scripts/render.mjs +37 -5
  140. package/marketplace/plugins/litcodex/skills/lit-typographic-motion/scripts/runtime.mjs +1 -1
  141. package/marketplace/plugins/litcodex/skills/litgoal/SKILL.md +8 -3
  142. package/marketplace/plugins/litcodex/skills/lsp-setup/scripts/verify-lsp.ts +43 -7
  143. package/marketplace/plugins/litcodex/skills/review-work/SKILL.md +21 -4
  144. package/node_modules/@litcodex/lit-loop/CHANGELOG.md +7 -0
  145. package/node_modules/@litcodex/lit-loop/README.md +6 -0
  146. package/node_modules/@litcodex/lit-loop/directive.md +2 -1
  147. package/node_modules/@litcodex/lit-loop/directives/deep-interview.md +2 -0
  148. package/node_modules/@litcodex/lit-loop/directives/lit-brainstorm.md +216 -0
  149. package/node_modules/@litcodex/lit-loop/directives/litgoal.md +8 -1
  150. package/node_modules/@litcodex/lit-loop/directives/review-work.md +12 -4
  151. package/node_modules/@litcodex/lit-loop/dist/card-status.d.ts +8 -3
  152. package/node_modules/@litcodex/lit-loop/dist/card-status.js +11 -6
  153. package/node_modules/@litcodex/lit-loop/dist/codex-hook.d.ts +6 -1
  154. package/node_modules/@litcodex/lit-loop/dist/codex-hook.js +16 -5
  155. package/node_modules/@litcodex/lit-loop/dist/guards.d.ts +3 -1
  156. package/node_modules/@litcodex/lit-loop/dist/guards.js +5 -2
  157. package/node_modules/@litcodex/lit-loop/dist/hook-cli.d.ts +2 -0
  158. package/node_modules/@litcodex/lit-loop/dist/hook-cli.js +53 -17
  159. package/node_modules/@litcodex/lit-loop/dist/hud-cli.d.ts +38 -0
  160. package/node_modules/@litcodex/lit-loop/dist/hud-cli.js +155 -0
  161. package/node_modules/@litcodex/lit-loop/dist/hud.d.ts +42 -0
  162. package/node_modules/@litcodex/lit-loop/dist/hud.js +297 -0
  163. package/node_modules/@litcodex/lit-loop/dist/markers.d.ts +2 -0
  164. package/node_modules/@litcodex/lit-loop/dist/markers.js +2 -0
  165. package/node_modules/@litcodex/lit-loop/dist/modes.d.ts +1 -1
  166. package/node_modules/@litcodex/lit-loop/dist/modes.js +9 -1
  167. package/node_modules/@litcodex/lit-loop/dist/motion-route.js +2 -0
  168. package/node_modules/@litcodex/lit-loop/dist/plan-persistence.d.ts +2 -0
  169. package/node_modules/@litcodex/lit-loop/dist/plan-persistence.js +8 -0
  170. package/node_modules/@litcodex/lit-loop/dist/reentry.d.ts +56 -0
  171. package/node_modules/@litcodex/lit-loop/dist/reentry.js +171 -0
  172. package/node_modules/@litcodex/lit-loop/dist/route-context.js +5 -2
  173. package/node_modules/@litcodex/lit-loop/dist/route-heads.js +35 -15
  174. package/node_modules/@litcodex/lit-loop/dist/run-filter.d.ts +23 -0
  175. package/node_modules/@litcodex/lit-loop/dist/run-filter.js +142 -0
  176. package/node_modules/@litcodex/lit-loop/dist/run-panel.d.ts +29 -0
  177. package/node_modules/@litcodex/lit-loop/dist/run-panel.js +102 -0
  178. package/node_modules/@litcodex/lit-loop/dist/screen-card.d.ts +24 -0
  179. package/node_modules/@litcodex/lit-loop/dist/screen-card.js +104 -0
  180. package/node_modules/@litcodex/lit-loop/dist/screen-status.d.ts +24 -0
  181. package/node_modules/@litcodex/lit-loop/dist/screen-status.js +110 -0
  182. package/node_modules/@litcodex/lit-loop/dist/skill-mention-scope.js +2 -0
  183. package/node_modules/@litcodex/lit-loop/dist/statusline.d.ts +17 -0
  184. package/node_modules/@litcodex/lit-loop/dist/statusline.js +113 -0
  185. package/node_modules/@litcodex/lit-loop/dist/trigger.d.ts +2 -2
  186. package/node_modules/@litcodex/lit-loop/dist/trigger.js +15 -5
  187. package/node_modules/@litcodex/lit-loop/dist/workflow-map.d.ts +7 -0
  188. package/node_modules/@litcodex/lit-loop/dist/workflow-map.js +59 -10
  189. package/node_modules/@litcodex/lit-loop/package.json +1 -1
  190. package/node_modules/@litcodex/lit-loop/skills/browser-drive/scripts/capability-probe.mjs +24 -4
  191. package/node_modules/@litcodex/lit-loop/skills/deep-interview/SKILL.md +3 -1
  192. package/node_modules/@litcodex/lit-loop/skills/lit-brainstorm/SKILL.md +271 -0
  193. package/node_modules/@litcodex/lit-loop/skills/lit-humanizer/SKILL.md +4 -0
  194. package/node_modules/@litcodex/lit-loop/skills/lit-humanizer/scripts/core.mjs +5 -1
  195. package/node_modules/@litcodex/lit-loop/skills/lit-loop/SKILL.md +10 -2
  196. package/node_modules/@litcodex/lit-loop/skills/litgoal/SKILL.md +8 -3
  197. package/node_modules/@litcodex/lit-loop/skills/review-work/SKILL.md +21 -4
  198. package/package.json +5 -2
  199. package/readme-assets/badge-version.svg +1 -1
  200. package/readme-assets/cover-motion-still.webp +0 -0
  201. package/readme-assets/cover-motion.webp +0 -0
  202. package/readme-assets/cover.webp +0 -0
  203. package/readme-assets/litfamily-machines.png +0 -0
  204. package/readme-assets/skills/lit-brainstorm.webp +0 -0
@@ -0,0 +1,297 @@
1
+ // src/hud.ts — the LIT card for a second terminal window (`litcodex hud`).
2
+ //
3
+ // Every LIT session leaves a thread pointer in the Codex home (live-step.ts) naming its project folder, so
4
+ // the HUD can run from any directory. A pointer is written once per session, so the session to follow is
5
+ // the one with the newest LIT activity: the pointer time or the times its live step and workflow record
6
+ // carry, which the hooks rewrite on every prompt and tool. Files are re-parsed only after their `lstat`
7
+ // identity (inode, size, times) changes, so an idle HUD costs a few `lstat` calls a tick. The card itself is
8
+ // the one `cardStatusText` prints, read with `rollout: false` so no Codex rollout file is ever opened.
9
+ // Nothing here writes. A record that exists but cannot be read becomes one "cannot read" line instead
10
+ // of a quiet "ready". Record text is data: control characters and escapes are stripped before printing.
11
+ import { lstatSync, readdirSync } from "node:fs";
12
+ import { join } from "node:path";
13
+ import { cardStatusText, readCardStatus } from "./card-status.js";
14
+ import { codexHomeFrom, liveStepPath, plainDirsOrMissing, readLiveStep, readSmallJson, readThreadPointer, threadPointerPath, } from "./live-step.js";
15
+ import { LIT_LOOP_DIR, LIT_LOOP_GOALS, normalizeSessionId } from "./state-paths.js";
16
+ import { workflowTurn } from "./workflow-map.js";
17
+ const POINTER_DIR = "litcodex/lit-loop/threads";
18
+ const MAX_LIVE_STEP_BYTES = 4_096;
19
+ /** The cap the workflow map itself reads its state files under. */
20
+ const MAX_STATE_BYTES = 1_000_000;
21
+ const SHORT_ID = 8;
22
+ /** Past this, the session is likely gone; the header says when it was last seen instead. */
23
+ const LAST_SEEN_MS = 10 * 60 * 1000;
24
+ /** Parsed files keyed by reader and path, kept while the file's `lstat` identity stays the same. */
25
+ const parsed = new Map();
26
+ /** `read()` for `path`, re-run only when the file's inode, size or times changed since `reader` last read it. */
27
+ function cachedRead(reader, path, read) {
28
+ let key;
29
+ try {
30
+ const stat = lstatSync(path, { throwIfNoEntry: false });
31
+ key = stat === undefined ? "missing" : `${stat.ino}:${stat.size}:${stat.mtimeMs}:${stat.ctimeMs}`;
32
+ }
33
+ catch {
34
+ return read();
35
+ }
36
+ const slot = `${reader}\0${path}`;
37
+ const hit = parsed.get(slot);
38
+ if (hit !== undefined && hit.key === key)
39
+ return hit.value;
40
+ const value = read();
41
+ parsed.set(slot, { key, value });
42
+ return value;
43
+ }
44
+ function mtimeOf(path) {
45
+ try {
46
+ return lstatSync(path, { throwIfNoEntry: false })?.mtimeMs ?? 0;
47
+ }
48
+ catch {
49
+ return 0;
50
+ }
51
+ }
52
+ /** The newest time the session's live step or workflow record carries; null when neither has one. */
53
+ function activityAt(cwd, id) {
54
+ const stepPath = liveStepPath(cwd, id);
55
+ const step = stepPath === null ? null : cachedRead("live step", stepPath, () => readLiveStep(cwd, id));
56
+ const turn = cachedRead("turn", join(cwd, ".litcodex/workflow-map", `${id}.json`), () => workflowTurn(cwd, id));
57
+ const times = [step?.turnStartedAt, step?.turnEndedAt, step?.startedAt, step?.endedAt, turn?.startedAt];
58
+ const known = times.filter((time) => typeof time === "number");
59
+ return known.length === 0 ? null : Math.max(...known);
60
+ }
61
+ function scanPointers(env) {
62
+ const home = codexHomeFrom(env);
63
+ if (home === null)
64
+ return { sessions: [], brokenAt: null };
65
+ if (!plainDirsOrMissing(home, POINTER_DIR))
66
+ return { sessions: [], brokenAt: Number.POSITIVE_INFINITY };
67
+ let names;
68
+ try {
69
+ names = readdirSync(join(home, POINTER_DIR)).filter((name) => name.endsWith(".json"));
70
+ }
71
+ catch (error) {
72
+ const missing = error.code === "ENOENT";
73
+ return { sessions: [], brokenAt: missing ? null : Number.POSITIVE_INFINITY };
74
+ }
75
+ const sessions = [];
76
+ let brokenAt = null;
77
+ for (const name of names) {
78
+ const id = name.slice(0, -".json".length);
79
+ const path = threadPointerPath(env, id);
80
+ if (path === null || normalizeSessionId(id) !== id)
81
+ continue;
82
+ const pointer = cachedRead("pointer", path, () => readThreadPointer(env, id));
83
+ const pointerMtime = mtimeOf(path);
84
+ if (pointer === null) {
85
+ brokenAt = Math.max(brokenAt ?? 0, pointerMtime);
86
+ continue;
87
+ }
88
+ const activity = activityAt(pointer.cwd, id);
89
+ const activeAt = Math.max(pointer.updatedAt, activity ?? pointer.updatedAt);
90
+ sessions.push({ id, cwd: pointer.cwd, updatedAt: pointer.updatedAt, activeAt, pointerMtime });
91
+ }
92
+ sessions.sort((a, b) => b.activeAt - a.activeAt || a.id.localeCompare(b.id));
93
+ return { sessions, brokenAt };
94
+ }
95
+ /** Every session with a readable pointer, newest LIT activity first. */
96
+ export function listSessions(env) {
97
+ return scanPointers(env).sessions.map(({ id, cwd, updatedAt, activeAt }) => ({ id, cwd, updatedAt, activeAt }));
98
+ }
99
+ function choose(sessions, wanted) {
100
+ if (wanted === null || wanted === undefined || wanted === "") {
101
+ const newest = sessions[0] ?? null;
102
+ return { session: newest, matches: newest === null ? 0 : 1 };
103
+ }
104
+ const exact = sessions.find((session) => session.id === wanted);
105
+ if (exact !== undefined)
106
+ return { session: exact, matches: 1 };
107
+ const found = sessions.filter((session) => session.id.startsWith(wanted));
108
+ return { session: found.length === 1 ? (found[0] ?? null) : null, matches: found.length };
109
+ }
110
+ /** The most recently active session, or the one `wanted` names by exact id or unique prefix; else null. */
111
+ export function pickSession(env, wanted) {
112
+ return choose(listSessions(env), wanted).session;
113
+ }
114
+ /** True when a record exists at `base/rel/name` but is not a small, regular, parseable file. */
115
+ function unreadableRecord(base, rel, name, maxBytes) {
116
+ if (!plainDirsOrMissing(base, rel))
117
+ return true;
118
+ const path = join(base, rel, name);
119
+ try {
120
+ const stat = lstatSync(path, { throwIfNoEntry: false });
121
+ if (stat === undefined)
122
+ return false;
123
+ if (!stat.isFile() || stat.size > maxBytes)
124
+ return true;
125
+ }
126
+ catch {
127
+ return true;
128
+ }
129
+ return cachedRead(`unreadable ${maxBytes}`, path, () => readSmallJson(path, maxBytes) === null);
130
+ }
131
+ /** Every record the card reads, with the name the "cannot read" line gives it. */
132
+ function recordsOf(id) {
133
+ return [
134
+ ["live step", ".litcodex/live-step", `${id}.json`, MAX_LIVE_STEP_BYTES],
135
+ ["workflow record", ".litcodex/workflow-map", `${id}.json`, MAX_STATE_BYTES],
136
+ ["start-work state", ".litcodex/start-work", "state.json", MAX_STATE_BYTES],
137
+ ["session goals", `${LIT_LOOP_DIR}/${id}`, LIT_LOOP_GOALS, MAX_STATE_BYTES],
138
+ ["shared goals", LIT_LOOP_DIR, LIT_LOOP_GOALS, MAX_STATE_BYTES],
139
+ ["lit-plan record", ".litcodex/lit-plan", `${id}.json`, MAX_STATE_BYTES],
140
+ ];
141
+ }
142
+ function unreadableRecords(cwd, id) {
143
+ if (!plainDirsOrMissing(cwd, ".litcodex"))
144
+ return ["project records (.litcodex)"];
145
+ return recordsOf(id)
146
+ .filter(([, rel, name, maxBytes]) => unreadableRecord(cwd, rel, name, maxBytes))
147
+ .map(([label]) => label);
148
+ }
149
+ function tilde(path, home) {
150
+ if (home === undefined || home === "" || home === "/")
151
+ return path;
152
+ if (path === home)
153
+ return "~";
154
+ return path.startsWith(`${home}/`) ? `~${path.slice(home.length)}` : path;
155
+ }
156
+ /** Everything one frame needs, read once. Never throws and never writes. */
157
+ export function readHud(env, wanted, now) {
158
+ try {
159
+ const { sessions, brokenAt } = scanPointers(env);
160
+ const { session, matches } = choose(sessions, wanted);
161
+ if (session === null) {
162
+ return {
163
+ wanted,
164
+ session: null,
165
+ status: null,
166
+ unreadable: brokenAt !== null ? ["session pointer"] : [],
167
+ matches,
168
+ };
169
+ }
170
+ const status = readCardStatus(session.id, env, now, { rollout: false });
171
+ const lastSeen = Math.min(now, session.activeAt);
172
+ // A broken pointer written after the chosen one may be the session the user is actually in.
173
+ const pointer = brokenAt !== null && brokenAt > session.pointerMtime ? ["session pointer"] : [];
174
+ const unreadable = [...pointer, ...unreadableRecords(session.cwd, session.id)];
175
+ return {
176
+ wanted,
177
+ session: { id: session.id, folder: tilde(session.cwd, env["HOME"]), lastSeen },
178
+ status,
179
+ unreadable,
180
+ };
181
+ }
182
+ catch {
183
+ return { wanted, session: null, status: null, unreadable: ["LIT records"] };
184
+ }
185
+ }
186
+ /** C0/C1 controls (ESC, CSI, BEL among them) plus zero-width and bidi format characters. */
187
+ const CONTROL = /[\u0000-\u001f\u007f-\u009f\u200b-\u200f\u202a-\u202e\u2066-\u2069]/gu;
188
+ export function clean(text) {
189
+ return text.replace(CONTROL, "");
190
+ }
191
+ /** The card with every record-derived string stripped of control characters. */
192
+ export function cleanStatus(status) {
193
+ return {
194
+ ...status,
195
+ mode: status.mode === null ? null : clean(status.mode),
196
+ step: status.step === null ? null : { ...status.step, tool: clean(status.step.tool) },
197
+ map: status.map === null ? null : { ...status.map, next: status.map.next === null ? null : clean(status.map.next) },
198
+ };
199
+ }
200
+ const MARK = /^\p{M}$/u;
201
+ const WIDE_EMOJI = /^\p{Emoji_Presentation}$/u;
202
+ function charWidth(char) {
203
+ const code = char.codePointAt(0) ?? 0;
204
+ if (MARK.test(char) || (code >= 0x200b && code <= 0x200f) || (code >= 0xfe00 && code <= 0xfe0f))
205
+ return 0;
206
+ if (WIDE_EMOJI.test(char))
207
+ return 2;
208
+ if ((code >= 0x1100 && code <= 0x115f) ||
209
+ (code >= 0x2e80 && code <= 0xa4cf) ||
210
+ (code >= 0xac00 && code <= 0xd7a3) ||
211
+ (code >= 0xf900 && code <= 0xfaff) ||
212
+ (code >= 0xfe30 && code <= 0xfe4f) ||
213
+ (code >= 0xff00 && code <= 0xff60) ||
214
+ (code >= 0xffe0 && code <= 0xffe6) ||
215
+ (code >= 0x20000 && code <= 0x3fffd))
216
+ return 2;
217
+ return 1;
218
+ }
219
+ /** The string as terminal cells; a narrow character followed by U+FE0F (emoji presentation) takes two. */
220
+ function cells(text) {
221
+ const out = [];
222
+ for (const char of text) {
223
+ const previous = out.at(-1);
224
+ if (char === "\ufe0f" && previous !== undefined) {
225
+ previous.text += char;
226
+ previous.width = Math.max(previous.width, 2);
227
+ continue;
228
+ }
229
+ out.push({ text: char, width: charWidth(char) });
230
+ }
231
+ return out;
232
+ }
233
+ /** Terminal cells a plain string takes: CJK and emoji take two, combining marks none. */
234
+ export function displayWidth(text) {
235
+ return cells(text).reduce((sum, cell) => sum + cell.width, 0);
236
+ }
237
+ /** The line cut to `width` terminal cells, ending in `…` when anything was cut. */
238
+ export function fit(line, width) {
239
+ if (displayWidth(line) <= width)
240
+ return line;
241
+ let out = "";
242
+ let used = 0;
243
+ for (const cell of cells(line)) {
244
+ if (used + cell.width > width - 1)
245
+ break;
246
+ out += cell.text;
247
+ used += cell.width;
248
+ }
249
+ return `${out}…`;
250
+ }
251
+ function age(lastSeen, now) {
252
+ const seconds = Math.max(0, Math.floor((now - lastSeen) / 1000));
253
+ if (now - lastSeen > LAST_SEEN_MS)
254
+ return `last seen ${Math.floor(seconds / 60)} min ago`;
255
+ return seconds < 60 ? `updated ${seconds}s ago` : `updated ${Math.floor(seconds / 60)} min ago`;
256
+ }
257
+ const BOLD = "\u001b[1m";
258
+ const DIM = "\u001b[2m";
259
+ const RESET = "\u001b[0m";
260
+ /** One frame as text: a header, the card, and at most one "cannot read" line. Pure. */
261
+ export function renderHud(view, options) {
262
+ const width = Math.max(10, Math.floor(options.width));
263
+ const lines = [];
264
+ if ((view.session === null || view.status === null) && view.wanted !== null && (view.matches ?? 0) > 1) {
265
+ lines.push({ text: "🔥 LIT · which session?", style: BOLD });
266
+ lines.push({
267
+ text: `--session ${clean(view.wanted)} matches ${view.matches} sessions; give more of the id`,
268
+ style: DIM,
269
+ });
270
+ }
271
+ else if (view.session === null || view.status === null) {
272
+ lines.push({ text: "🔥 LIT · waiting for a LIT session", style: BOLD });
273
+ lines.push({
274
+ text: view.wanted === null
275
+ ? "Start `codex` in a project and type `lit <task>`."
276
+ : `waiting for session ${clean(view.wanted)}`,
277
+ style: DIM,
278
+ });
279
+ }
280
+ else {
281
+ const { id, folder, lastSeen } = view.session;
282
+ lines.push({ text: `${id.slice(0, SHORT_ID)} · ${clean(folder)} · ${age(lastSeen, options.now)}`, style: DIM });
283
+ cardStatusText(cleanStatus(view.status))
284
+ .split("\n")
285
+ .forEach((text, index) => {
286
+ lines.push({ text, style: index === 0 ? BOLD : "" });
287
+ });
288
+ }
289
+ if (view.unreadable.length > 0)
290
+ lines.push({ text: `cannot read ${view.unreadable.join(", ")}`, style: DIM });
291
+ return lines
292
+ .map(({ text, style }) => {
293
+ const line = fit(clean(text), width);
294
+ return options.color && style !== "" ? `${style}${line}${RESET}` : line;
295
+ })
296
+ .join("\n");
297
+ }
@@ -28,4 +28,6 @@ export declare const BROWSER_DRIVE_DIRECTIVE_MARKER: "<browser-drive-mode>";
28
28
  export declare const BROWSER_DRIVE_DIRECTIVE_CLOSE: "</browser-drive-mode>";
29
29
  export declare const LIT_COMPREHEND_DIRECTIVE_MARKER: "<lit-comprehend-mode>";
30
30
  export declare const LIT_COMPREHEND_DIRECTIVE_CLOSE: "</lit-comprehend-mode>";
31
+ export declare const LIT_BRAINSTORM_DIRECTIVE_MARKER: "<lit-brainstorm-mode>";
32
+ export declare const LIT_BRAINSTORM_DIRECTIVE_CLOSE: "</lit-brainstorm-mode>";
31
33
  export type LitLoopDirectiveMarker = typeof LIT_LOOP_DIRECTIVE_MARKER;
@@ -34,3 +34,5 @@ export const BROWSER_DRIVE_DIRECTIVE_MARKER = "<browser-drive-mode>";
34
34
  export const BROWSER_DRIVE_DIRECTIVE_CLOSE = "</browser-drive-mode>";
35
35
  export const LIT_COMPREHEND_DIRECTIVE_MARKER = "<lit-comprehend-mode>";
36
36
  export const LIT_COMPREHEND_DIRECTIVE_CLOSE = "</lit-comprehend-mode>";
37
+ export const LIT_BRAINSTORM_DIRECTIVE_MARKER = "<lit-brainstorm-mode>";
38
+ export const LIT_BRAINSTORM_DIRECTIVE_CLOSE = "</lit-brainstorm-mode>";
@@ -1,7 +1,7 @@
1
1
  import type { RenamedSkillId } from "./skill-renames.js";
2
2
  import type { LitTriggerToken } from "./trigger.js";
3
3
  /** Lit-family modes. Multiple tokens may map to one mode (lit/litcodex/lit-loop → lit-loop). */
4
- export type LitMode = RenamedSkillId | "browser-drive" | "lit-handoff" | "lit-scientific-visualization" | "deep-interview" | "lit-crucible" | "lit-init" | "lit-loop" | "litwork" | "lit-plan" | "litgoal" | "review-work" | "litresearch" | "start-work" | "lit-recap" | "lit-comprehend";
4
+ export type LitMode = RenamedSkillId | "browser-drive" | "lit-handoff" | "lit-scientific-visualization" | "deep-interview" | "lit-crucible" | "lit-init" | "lit-loop" | "litwork" | "lit-plan" | "litgoal" | "review-work" | "litresearch" | "start-work" | "lit-recap" | "lit-comprehend" | "lit-brainstorm";
5
5
  /** Per-mode routing spec: its marker pair (guard) + resolved directive path (loader). */
6
6
  export interface LitModeSpec {
7
7
  readonly mode: LitMode;
@@ -15,7 +15,7 @@
15
15
  // Imports markers + the trigger token type only (no cycle: hook → modes → {markers, trigger}).
16
16
  import { existsSync } from "node:fs";
17
17
  import { fileURLToPath } from "node:url";
18
- import { BROWSER_DRIVE_DIRECTIVE_CLOSE, BROWSER_DRIVE_DIRECTIVE_MARKER, DEEP_INTERVIEW_DIRECTIVE_CLOSE, DEEP_INTERVIEW_DIRECTIVE_MARKER, HANDOFF_DIRECTIVE_CLOSE, HANDOFF_DIRECTIVE_MARKER, LIT_COMPREHEND_DIRECTIVE_CLOSE, LIT_COMPREHEND_DIRECTIVE_MARKER, LIT_CRUCIBLE_DIRECTIVE_CLOSE, LIT_CRUCIBLE_DIRECTIVE_MARKER, LIT_INIT_DIRECTIVE_CLOSE, LIT_INIT_DIRECTIVE_MARKER, LIT_LOOP_DIRECTIVE_CLOSE, LIT_LOOP_DIRECTIVE_MARKER, LIT_PLAN_DIRECTIVE_CLOSE, LIT_PLAN_DIRECTIVE_MARKER, LIT_RECAP_DIRECTIVE_CLOSE, LIT_RECAP_DIRECTIVE_MARKER, LITGOAL_DIRECTIVE_CLOSE, LITGOAL_DIRECTIVE_MARKER, LITRESEARCH_DIRECTIVE_CLOSE, LITRESEARCH_DIRECTIVE_MARKER, LITWORK_DIRECTIVE_CLOSE, LITWORK_DIRECTIVE_MARKER, REVIEW_WORK_DIRECTIVE_CLOSE, REVIEW_WORK_DIRECTIVE_MARKER, SCIENTIFIC_VISUALIZATION_DIRECTIVE_CLOSE, SCIENTIFIC_VISUALIZATION_DIRECTIVE_MARKER, START_WORK_DIRECTIVE_CLOSE, START_WORK_DIRECTIVE_MARKER, } from "./markers.js";
18
+ import { BROWSER_DRIVE_DIRECTIVE_CLOSE, BROWSER_DRIVE_DIRECTIVE_MARKER, DEEP_INTERVIEW_DIRECTIVE_CLOSE, DEEP_INTERVIEW_DIRECTIVE_MARKER, HANDOFF_DIRECTIVE_CLOSE, HANDOFF_DIRECTIVE_MARKER, LIT_BRAINSTORM_DIRECTIVE_CLOSE, LIT_BRAINSTORM_DIRECTIVE_MARKER, LIT_COMPREHEND_DIRECTIVE_CLOSE, LIT_COMPREHEND_DIRECTIVE_MARKER, LIT_CRUCIBLE_DIRECTIVE_CLOSE, LIT_CRUCIBLE_DIRECTIVE_MARKER, LIT_INIT_DIRECTIVE_CLOSE, LIT_INIT_DIRECTIVE_MARKER, LIT_LOOP_DIRECTIVE_CLOSE, LIT_LOOP_DIRECTIVE_MARKER, LIT_PLAN_DIRECTIVE_CLOSE, LIT_PLAN_DIRECTIVE_MARKER, LIT_RECAP_DIRECTIVE_CLOSE, LIT_RECAP_DIRECTIVE_MARKER, LITGOAL_DIRECTIVE_CLOSE, LITGOAL_DIRECTIVE_MARKER, LITRESEARCH_DIRECTIVE_CLOSE, LITRESEARCH_DIRECTIVE_MARKER, LITWORK_DIRECTIVE_CLOSE, LITWORK_DIRECTIVE_MARKER, REVIEW_WORK_DIRECTIVE_CLOSE, REVIEW_WORK_DIRECTIVE_MARKER, SCIENTIFIC_VISUALIZATION_DIRECTIVE_CLOSE, SCIENTIFIC_VISUALIZATION_DIRECTIVE_MARKER, START_WORK_DIRECTIVE_CLOSE, START_WORK_DIRECTIVE_MARKER, } from "./markers.js";
19
19
  /** Resolve a path relative to this module (percent-decoding, space/#/Hangul-safe). */
20
20
  function resolveFromHere(rel) {
21
21
  return fileURLToPath(new URL(rel, import.meta.url));
@@ -160,6 +160,14 @@ export const MODE_BY_TOKEN = Object.freeze({
160
160
  skillName: "lit-comprehend",
161
161
  skillPath: resolveSkillPath("lit-comprehend"),
162
162
  }),
163
+ "lit-brainstorm": Object.freeze({
164
+ mode: "lit-brainstorm",
165
+ openMarker: LIT_BRAINSTORM_DIRECTIVE_MARKER,
166
+ closeMarker: LIT_BRAINSTORM_DIRECTIVE_CLOSE,
167
+ directivePath: resolveFromHere("../directives/lit-brainstorm.md"),
168
+ skillName: "lit-brainstorm",
169
+ skillPath: resolveSkillPath("lit-brainstorm"),
170
+ }),
163
171
  });
164
172
  /** The mode spec for a matched token. Total over the token union (every token has a spec). */
165
173
  export function modeForToken(token) {
@@ -66,6 +66,7 @@ export function typeLedCue(prompt) {
66
66
  }
67
67
  export const FILM_SUBCOMMANDS = Object.freeze([
68
68
  "stage [--stills-only]",
69
+ "cover [--window t0,t1]",
69
70
  "film [--stills-only]",
70
71
  "sound",
71
72
  "look --round N --answers <file>",
@@ -89,6 +90,7 @@ export function motionRouteContext(litLoopSkillPath, prompt) {
89
90
  "Film context: this is a film request. Load SKILL.md from the skill folder above the renderer's scripts/ and write treatment.json in the output directory before any render.",
90
91
  "Path rule: the type path only when the words themselves are the film (kinetic type, a lyric or quote video, a title sequence, typographic motion, or supplied words with no other subject) at 16:9. Every other film, and every 9:16 film, takes the stage path: you author the visuals in HTML, CSS, SVG or Canvas and the renderer captures them.",
91
92
  "Hand-encoded films are not the deliverable; every frame and track goes through the renderer.",
93
+ "A README, hero or banner loop takes cover mode: references/cover.md.",
92
94
  `Renderer: node "${renderer}" <subcommand> --out <dir>; subcommands: ${FILM_SUBCOMMANDS.join(", ")}.`,
93
95
  ...(cue ? [`type-led cue found: ${cue}`] : []),
94
96
  ].join("\n");
@@ -10,6 +10,8 @@ export type PlanPersistenceDecision = {
10
10
  };
11
11
  /** Record (or re-record) a lit-plan activation for `sessionId`. Fail-open: never throws. */
12
12
  export declare function recordLitPlanActivation(repoRoot: string, sessionId: string, now?: number): void;
13
+ /** A new plan after a saved one needs its own persistence check: re-arm the gate when the last one was satisfied. */
14
+ export declare function rearmLitPlanIfSatisfied(repoRoot: string, sessionId: string, now?: number): void;
13
15
  /**
14
16
  * Decide whether the Stop for `sessionId` may end. Pass when no activation exists, when the guard is
15
17
  * already satisfied, or when the block cap is spent; otherwise block until a checkbox plan newer than
@@ -67,6 +67,14 @@ export function recordLitPlanActivation(repoRoot, sessionId, now = Date.now()) {
67
67
  // A state write failure only disables the guard for this session.
68
68
  }
69
69
  }
70
+ /** A new plan after a saved one needs its own persistence check: re-arm the gate when the last one was satisfied. */
71
+ export function rearmLitPlanIfSatisfied(repoRoot, sessionId, now = Date.now()) {
72
+ const path = statePath(repoRoot, sessionId);
73
+ if (path === null)
74
+ return;
75
+ if (readState(path)?.satisfied === true)
76
+ recordLitPlanActivation(repoRoot, sessionId, now);
77
+ }
70
78
  /** Newest `.litcodex/plans/*.md` modified at or after `since`, or null when none exists. */
71
79
  function newestPlanSince(repoRoot, since) {
72
80
  const dir = join(repoRoot, PLAN_PERSISTENCE_PLANS_DIR);
@@ -0,0 +1,56 @@
1
+ import { type LitMode } from "./modes.js";
2
+ export declare const REENTRY_DIR = ".litcodex/lit-reentry";
3
+ /** Work this session could pick up again, worded for the one-line resume note. */
4
+ export interface ResumeWork {
5
+ readonly text: string;
6
+ }
7
+ /** Saved state a route decision needs; read lazily, only when a lit-family route matched. */
8
+ export interface ReentryContext {
9
+ /** The route this session last sent an activation for; null when none is saved. */
10
+ readonly active: string | null;
11
+ /** Approved or running work a bare `lit` should resume; null when there is none. */
12
+ readonly resume: ResumeWork | null;
13
+ }
14
+ export declare const NO_REENTRY: ReentryContext;
15
+ export type Entry = {
16
+ readonly kind: "first";
17
+ readonly confirm: boolean;
18
+ } | {
19
+ readonly kind: "continue";
20
+ readonly confirm: boolean;
21
+ readonly route: LitMode;
22
+ } | {
23
+ readonly kind: "resume";
24
+ readonly work: ResumeWork;
25
+ readonly active: boolean;
26
+ readonly route: LitMode;
27
+ };
28
+ /** The route this session last sent an activation for, or null when nothing readable is saved. */
29
+ export declare function readActiveRoute(cwd: string, sessionId: string): string | null;
30
+ /** Remember that `mode`'s activation reached this session. Never throws. */
31
+ export declare function recordActiveRoute(cwd: string, sessionId: string, mode: string, now?: number): void;
32
+ /** Forget the saved route, so the next lit prompt sends the full activation again. Never throws. */
33
+ export declare function clearActiveRoute(cwd: string, sessionId: string): void;
34
+ /**
35
+ * Approved or running work for this session, from the same saved state the LIT card reads: a start-work
36
+ * plan that is active or paused, a plan this session published through lit-plan and has not started,
37
+ * or lit-loop goals that are not all complete. A finished plan resumes nothing.
38
+ */
39
+ export declare function readResumeWork(cwd: string, sessionId: string): ResumeWork | null;
40
+ /** True for a bare `lit` or `lit continue`: the prompt carries no task and no route of its own. */
41
+ export declare function isBareLit(prompt: string): boolean;
42
+ /**
43
+ * How a matched lit-family route enters. start-work always gets its full activation: its prompt carries
44
+ * the write grant. `lit new …` and `lit restart …` start again. A bare `lit` or `lit continue` carries on
45
+ * whichever route the session holds (resuming approved or running work when there is some), so it never
46
+ * switches; only an explicit `lit <other route>` does. The same route as the saved one continues; anything
47
+ * else is a first activation. Only a bare `lit` with no task and nothing active or in flight asks what to start.
48
+ */
49
+ export declare function enterRoute(prompt: string, mode: LitMode, context: ReentryContext): Entry;
50
+ /** Lines a resume or confirmation adds to a full activation. */
51
+ export declare function entryNotes(entry: Entry): string[];
52
+ /**
53
+ * The short context a repeated prompt gets while its contract is still loaded: no skill or directive
54
+ * files to read, the visible banner line, and a one-line reminder where the contract guards writes.
55
+ */
56
+ export declare function continueContext(mode: LitMode, entry: Entry): string;
@@ -0,0 +1,171 @@
1
+ // src/reentry.ts — what a repeated `lit …` prompt does in a session that already ignited a discipline.
2
+ //
3
+ // The first `lit …` of a session sends the route's full activation. After that the model already holds
4
+ // the contract, so the same discipline continues with a short note, a different discipline switches with
5
+ // its full activation, a bare `lit` over approved or running work resumes it, and `lit new …` or
6
+ // `lit restart …` starts again in full. "Active" is only what this module saved for the session when it
7
+ // last sent an activation (never model text): one small file per session id under `.litcodex/lit-reentry/`.
8
+ // A compaction drops the contract from the model's context, so PostCompact deletes the file. A missing,
9
+ // linked or malformed file means "nothing active", which is the full activation: every read fails open.
10
+ import { lstatSync, mkdirSync, readFileSync, rmSync } from "node:fs";
11
+ import { isAbsolute, join } from "node:path";
12
+ import { plainDirsOrMissing, writeFileAtomic } from "./live-step.js";
13
+ import { MODE_BY_TOKEN } from "./modes.js";
14
+ import { normalizeSessionId } from "./state-paths.js";
15
+ import { maskMarkdownCode } from "./trigger.js";
16
+ import { readWorkflowSignals } from "./workflow-map.js";
17
+ export const REENTRY_DIR = ".litcodex/lit-reentry";
18
+ const STATE_VERSION = 1;
19
+ const MAX_STATE_BYTES = 4_096;
20
+ export const NO_REENTRY = Object.freeze({ active: null, resume: null });
21
+ // ── Saved state ──────────────────────────────────────────────────────────────
22
+ function statePath(cwd, sessionId) {
23
+ const id = normalizeSessionId(sessionId);
24
+ if (id === null || !isAbsolute(cwd))
25
+ return null;
26
+ return join(cwd, REENTRY_DIR, `${id}.json`);
27
+ }
28
+ /** The route this session last sent an activation for, or null when nothing readable is saved. */
29
+ export function readActiveRoute(cwd, sessionId) {
30
+ const path = statePath(cwd, sessionId);
31
+ if (path === null)
32
+ return null;
33
+ try {
34
+ if (!plainDirsOrMissing(cwd, REENTRY_DIR))
35
+ return null;
36
+ const stat = lstatSync(path);
37
+ if (!stat.isFile() || stat.size > MAX_STATE_BYTES)
38
+ return null;
39
+ const record = JSON.parse(readFileSync(path, "utf8"));
40
+ if (typeof record !== "object" || record === null || Array.isArray(record))
41
+ return null;
42
+ const { version, mode } = record;
43
+ return version === STATE_VERSION && typeof mode === "string" && mode !== "" ? mode : null;
44
+ }
45
+ catch {
46
+ return null;
47
+ }
48
+ }
49
+ /** Remember that `mode`'s activation reached this session. Never throws. */
50
+ export function recordActiveRoute(cwd, sessionId, mode, now = Date.now()) {
51
+ const path = statePath(cwd, sessionId);
52
+ if (path === null)
53
+ return;
54
+ try {
55
+ if (!plainDirsOrMissing(cwd, REENTRY_DIR))
56
+ return;
57
+ mkdirSync(join(cwd, REENTRY_DIR), { recursive: true });
58
+ writeFileAtomic(path, `${JSON.stringify({ version: STATE_VERSION, mode, at: now })}\n`);
59
+ }
60
+ catch {
61
+ // Without the file the next lit prompt simply gets the full activation.
62
+ }
63
+ }
64
+ /** Forget the saved route, so the next lit prompt sends the full activation again. Never throws. */
65
+ export function clearActiveRoute(cwd, sessionId) {
66
+ const path = statePath(cwd, sessionId);
67
+ if (path === null)
68
+ return;
69
+ try {
70
+ if (plainDirsOrMissing(cwd, REENTRY_DIR))
71
+ rmSync(path, { force: true });
72
+ }
73
+ catch {
74
+ // A file that cannot be removed only keeps the shorter continue note going.
75
+ }
76
+ }
77
+ // ── Work a bare lit resumes ──────────────────────────────────────────────────
78
+ /**
79
+ * Approved or running work for this session, from the same saved state the LIT card reads: a start-work
80
+ * plan that is active or paused, a plan this session published through lit-plan and has not started,
81
+ * or lit-loop goals that are not all complete. A finished plan resumes nothing.
82
+ */
83
+ export function readResumeWork(cwd, sessionId) {
84
+ const signals = readWorkflowSignals(cwd, sessionId);
85
+ const { work, plan, goals } = signals;
86
+ if (work !== null && work.status !== "completed") {
87
+ return { text: `the ${work.status} start-work plan, ${work.done} of ${work.total} tasks done` };
88
+ }
89
+ if (work === null && plan === "published")
90
+ return { text: "the plan this session published" };
91
+ if (goals !== null && goals.done < goals.total) {
92
+ return { text: `the open lit-loop goals, ${goals.done} of ${goals.total} done` };
93
+ }
94
+ return null;
95
+ }
96
+ // ── Reading the prompt ───────────────────────────────────────────────────────
97
+ const BARE = /^\s*(?:lit|lit-loop|litcodex)\s*[.!?]*\s*$/iu;
98
+ const BARE_CONTINUE = /^\s*(?:lit|lit-loop|litcodex)\s+continue\s*[.!?]*\s*$/iu;
99
+ const RESTART = /(?:^|[^\p{L}\p{N}_])(?:lit|lit-loop|litcodex)[ \t]+(?:new|restart)(?![\p{L}\p{N}_-])/iu;
100
+ /** True for a bare `lit` or `lit continue`: the prompt carries no task and no route of its own. */
101
+ export function isBareLit(prompt) {
102
+ return BARE.test(prompt) || BARE_CONTINUE.test(prompt);
103
+ }
104
+ /** Routes whose contract a bare `lit` can carry on: every lit-family route except start-work. */
105
+ const CARRIED_ON = new Set(Object.values(MODE_BY_TOKEN)
106
+ .map((spec) => spec.mode)
107
+ .filter((mode) => mode !== "start-work"));
108
+ /**
109
+ * How a matched lit-family route enters. start-work always gets its full activation: its prompt carries
110
+ * the write grant. `lit new …` and `lit restart …` start again. A bare `lit` or `lit continue` carries on
111
+ * whichever route the session holds (resuming approved or running work when there is some), so it never
112
+ * switches; only an explicit `lit <other route>` does. The same route as the saved one continues; anything
113
+ * else is a first activation. Only a bare `lit` with no task and nothing active or in flight asks what to start.
114
+ */
115
+ export function enterRoute(prompt, mode, context) {
116
+ if (mode === "start-work" || RESTART.test(maskMarkdownCode(prompt)))
117
+ return { kind: "first", confirm: false };
118
+ const bare = BARE.test(prompt);
119
+ const held = context.active !== null && CARRIED_ON.has(context.active) ? context.active : null;
120
+ if (mode === "lit-loop" && isBareLit(prompt)) {
121
+ const route = held ?? mode;
122
+ if (context.resume !== null)
123
+ return { kind: "resume", work: context.resume, active: held !== null, route };
124
+ if (held !== null)
125
+ return { kind: "continue", confirm: false, route };
126
+ }
127
+ const active = context.active === mode;
128
+ return active
129
+ ? { kind: "continue", confirm: false, route: mode }
130
+ : { kind: "first", confirm: bare && mode === "lit-loop" };
131
+ }
132
+ // ── What the model is told ───────────────────────────────────────────────────
133
+ const CONFIRM_LINE = "The prompt is only `lit`, with no task and no work in flight: ask the user one question, whether they meant to start a lit-loop and on what task, and do no work until they answer.";
134
+ /** Lines a resume or confirmation adds to a full activation. */
135
+ export function entryNotes(entry) {
136
+ if (entry.kind === "resume")
137
+ return [resumeLine(entry.work)];
138
+ return entry.confirm ? [CONFIRM_LINE] : [];
139
+ }
140
+ function resumeLine(work) {
141
+ return `Existing work is resuming: ${work.text}. Pick it up where it stopped; do not create a new plan or restart it.`;
142
+ }
143
+ /**
144
+ * The short context a repeated prompt gets while its contract is still loaded: no skill or directive
145
+ * files to read, the visible banner line, and a one-line reminder where the contract guards writes.
146
+ */
147
+ export function continueContext(mode, entry) {
148
+ const body = entry.kind === "resume"
149
+ ? [resumeLine(entry.work)]
150
+ : entry.confirm
151
+ ? [CONFIRM_LINE]
152
+ : [
153
+ "Carry on from where this session left off; do not restart the workflow, reset its stage or reload its files.",
154
+ ];
155
+ return [
156
+ `<${mode}-continue>`,
157
+ `LIT is already active in this session: continuing ${mode} under the contract loaded earlier.`,
158
+ "First user-visible line this turn MUST be exactly:",
159
+ `🔥 **LIT IGNITED · ${mode}** 🔥`,
160
+ ...body,
161
+ ...(mode === "lit-plan"
162
+ ? ["Planning only: edit no source, and wait for the user's okay before publishing the plan."]
163
+ : []),
164
+ ...(mode === "lit-brainstorm"
165
+ ? [
166
+ "Ideas only: implement nothing, write only notes under `.litcodex/lit-brainstorm/`, and wait for the user's pick.",
167
+ ]
168
+ : []),
169
+ `</${mode}-continue>`,
170
+ ].join("\n");
171
+ }
@@ -19,15 +19,18 @@ function routeFiles(skillName, skillPath, directive) {
19
19
  }
20
20
  /**
21
21
  * Fill `{skill:<name>}` with the installed SKILL.md path, or the skill's catalog name when this package
22
- * layout does not ship that skill, and `{root}` with the folder that holds `skills/`.
22
+ * layout does not ship that skill, `{skills}` with the folder that holds every skill, and `{root}` with
23
+ * the folder that holds `skills/`.
23
24
  */
24
25
  function resolveHeadPaths(head) {
25
- const root = dirname(dirname(dirname(resolveSkillPath("lit-loop"))));
26
+ const skills = dirname(dirname(resolveSkillPath("lit-loop")));
27
+ const root = dirname(skills);
26
28
  return head
27
29
  .replace(/\{skill:([a-z-]+)\}/gu, (_match, name) => {
28
30
  const path = resolveSkillPath(name);
29
31
  return existsSync(path) ? `\`${path}\`` : `the \`${name}\` skill from the Codex skill catalog`;
30
32
  })
33
+ .replaceAll("{skills}", skills)
31
34
  .replaceAll("{root}", root);
32
35
  }
33
36
  /**