@litfamily/litcodex 1.0.28 → 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.
- package/README-Ko-KR.md +10 -10
- package/README.md +10 -10
- package/dist/cli.js +1 -1
- package/dist/config-migration/cli.js +11 -3
- package/dist/install/generated-skill-payload-hashes.d.ts +56 -28
- package/dist/install/generated-skill-payload-hashes.js +56 -28
- package/dist/install/index.js +1 -1
- package/dist/install/motion-runtime.d.ts +4 -1
- package/dist/install/motion-runtime.js +15 -4
- package/dist/install/office-runtime.d.ts +10 -11
- package/dist/install/office-runtime.js +8 -3
- package/dist/install/skill-catalog.d.ts +1 -1
- package/dist/install/skill-catalog.js +1 -0
- package/dist/postinstall.js +4 -2
- package/marketplace/plugins/litcodex/.codex-plugin/plugin.json +1 -1
- package/marketplace/plugins/litcodex/components/auto-update/dist/auto-update.d.ts +12 -0
- package/marketplace/plugins/litcodex/components/auto-update/dist/auto-update.js +31 -2
- package/marketplace/plugins/litcodex/components/auto-update/package.json +1 -1
- package/marketplace/plugins/litcodex/components/comment-checker/package.json +1 -1
- package/marketplace/plugins/litcodex/components/git-bash/package.json +1 -1
- package/marketplace/plugins/litcodex/components/lit-loop/directive.md +2 -1
- package/marketplace/plugins/litcodex/components/lit-loop/directives/deep-interview.md +2 -0
- package/marketplace/plugins/litcodex/components/lit-loop/directives/lit-brainstorm.md +216 -0
- package/marketplace/plugins/litcodex/components/lit-loop/directives/litgoal.md +8 -1
- package/marketplace/plugins/litcodex/components/lit-loop/directives/review-work.md +12 -4
- package/marketplace/plugins/litcodex/components/lit-loop/dist/codex-hook.d.ts +6 -1
- package/marketplace/plugins/litcodex/components/lit-loop/dist/codex-hook.js +16 -5
- package/marketplace/plugins/litcodex/components/lit-loop/dist/guards.d.ts +3 -1
- package/marketplace/plugins/litcodex/components/lit-loop/dist/guards.js +5 -2
- package/marketplace/plugins/litcodex/components/lit-loop/dist/hook-cli.d.ts +2 -0
- package/marketplace/plugins/litcodex/components/lit-loop/dist/hook-cli.js +26 -8
- package/marketplace/plugins/litcodex/components/lit-loop/dist/markers.d.ts +2 -0
- package/marketplace/plugins/litcodex/components/lit-loop/dist/markers.js +2 -0
- package/marketplace/plugins/litcodex/components/lit-loop/dist/modes.d.ts +1 -1
- package/marketplace/plugins/litcodex/components/lit-loop/dist/modes.js +9 -1
- package/marketplace/plugins/litcodex/components/lit-loop/dist/motion-route.js +2 -0
- package/marketplace/plugins/litcodex/components/lit-loop/dist/plan-persistence.d.ts +2 -0
- package/marketplace/plugins/litcodex/components/lit-loop/dist/plan-persistence.js +8 -0
- package/marketplace/plugins/litcodex/components/lit-loop/dist/reentry.d.ts +56 -0
- package/marketplace/plugins/litcodex/components/lit-loop/dist/reentry.js +171 -0
- package/marketplace/plugins/litcodex/components/lit-loop/dist/route-context.js +5 -2
- package/marketplace/plugins/litcodex/components/lit-loop/dist/route-heads.js +35 -15
- package/marketplace/plugins/litcodex/components/lit-loop/dist/skill-mention-scope.js +2 -0
- package/marketplace/plugins/litcodex/components/lit-loop/dist/trigger.d.ts +2 -2
- package/marketplace/plugins/litcodex/components/lit-loop/dist/trigger.js +15 -5
- package/marketplace/plugins/litcodex/components/lit-loop/dist/workflow-map.js +1 -0
- package/marketplace/plugins/litcodex/components/lit-loop/package.json +1 -1
- package/marketplace/plugins/litcodex/components/lsp/package.json +1 -1
- package/marketplace/plugins/litcodex/components/rules/dist/model-metadata.d.ts +16 -0
- package/marketplace/plugins/litcodex/components/rules/dist/model-metadata.js +37 -1
- package/marketplace/plugins/litcodex/components/rules/package.json +1 -1
- package/marketplace/plugins/litcodex/components/start-work-continuation/package.json +1 -1
- package/marketplace/plugins/litcodex/components/telemetry/package.json +1 -1
- package/marketplace/plugins/litcodex/components/wikify-knowledge/package.json +1 -1
- package/marketplace/plugins/litcodex/skills/browser-drive/scripts/capability-probe.mjs +24 -4
- package/marketplace/plugins/litcodex/skills/deep-interview/SKILL.md +3 -1
- package/marketplace/plugins/litcodex/skills/lit-brainstorm/SKILL.md +271 -0
- package/marketplace/plugins/litcodex/skills/lit-brainstorm/agents/openai.yaml +6 -0
- package/marketplace/plugins/litcodex/skills/lit-diagram-drawer/scripts/doctor.mjs +4 -3
- package/marketplace/plugins/litcodex/skills/lit-diagram-drawer/scripts/export.mjs +6 -5
- package/marketplace/plugins/litcodex/skills/lit-diagram-drawer/scripts/runtime-probes.mjs +25 -0
- package/marketplace/plugins/litcodex/skills/lit-docx/scripts/convert_md_to_pdf.py +31 -1
- package/marketplace/plugins/litcodex/skills/lit-docx/templates/latex/acs/template.tex +2 -0
- package/marketplace/plugins/litcodex/skills/lit-docx/templates/latex/elsevier/template.tex +2 -0
- package/marketplace/plugins/litcodex/skills/lit-docx/templates/latex/ieee/template.tex +2 -0
- package/marketplace/plugins/litcodex/skills/lit-docx/templates/latex/korean-generic/template.tex +2 -0
- package/marketplace/plugins/litcodex/skills/lit-docx/templates/latex/nature/template.tex +2 -0
- package/marketplace/plugins/litcodex/skills/lit-loop/SKILL.md +8 -1
- package/marketplace/plugins/litcodex/skills/lit-pptx/scripts/office-run.mjs +42 -10
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/SKILL.md +11 -9
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/agents/openai.yaml +3 -0
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/THIRD_PARTY_NOTICES +4 -0
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/constants.mjs +38 -0
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/cover-assets.mjs +113 -0
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/cover-capture.mjs +161 -0
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/cover-gate.mjs +327 -0
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/cover-image.mjs +136 -0
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/cover-init.js +43 -0
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/cover-sheet.mjs +69 -0
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/cover-treatment.mjs +102 -0
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/cover-worker.mjs +21 -0
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/cover.mjs +352 -0
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/driver.mjs +19 -1
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/fonts.mjs +11 -0
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/look.mjs +128 -2
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/loop-kit.js +104 -0
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/runtime.mjs +92 -18
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/stage.mjs +2 -0
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/treatment.mjs +3 -2
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/engine/webp.mjs +140 -0
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/fonts/jetbrains-mono/JetBrainsMono-wght-latin.woff2 +0 -0
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/fonts/jetbrains-mono/OFL.txt +93 -0
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/recipes/negatives/card-scenes/expected.json +16 -0
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/recipes/negatives/card-scenes/index.html +42 -0
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/recipes/negatives/reset-sweep/expected.json +16 -0
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/recipes/negatives/reset-sweep/index.html +27 -0
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/recipes/negatives/still-glow/expected.json +17 -0
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/recipes/negatives/still-glow/index.html +29 -0
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/recipes/negatives/title-slam/expected.json +17 -0
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/recipes/negatives/title-slam/index.html +44 -0
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/recipes/orbit-loop/expected.json +67 -0
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/recipes/orbit-loop/index.html +182 -0
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/recipes/painted-light/expected.json +95 -0
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/recipes/painted-light/index.html +231 -0
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/recipes/weight-tide/expected.json +67 -0
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/recipes/weight-tide/index.html +103 -0
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/references/cover.md +389 -0
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/references/quality-gate.md +4 -0
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/references/runtime.md +7 -6
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/references/stage.md +3 -1
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/references/treatment.md +2 -0
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/scripts/render.mjs +37 -5
- package/marketplace/plugins/litcodex/skills/lit-typographic-motion/scripts/runtime.mjs +1 -1
- package/marketplace/plugins/litcodex/skills/litgoal/SKILL.md +8 -3
- package/marketplace/plugins/litcodex/skills/lsp-setup/scripts/verify-lsp.ts +43 -7
- package/marketplace/plugins/litcodex/skills/review-work/SKILL.md +21 -4
- package/node_modules/@litcodex/lit-loop/CHANGELOG.md +7 -0
- package/node_modules/@litcodex/lit-loop/README.md +6 -0
- package/node_modules/@litcodex/lit-loop/directive.md +2 -1
- package/node_modules/@litcodex/lit-loop/directives/deep-interview.md +2 -0
- package/node_modules/@litcodex/lit-loop/directives/lit-brainstorm.md +216 -0
- package/node_modules/@litcodex/lit-loop/directives/litgoal.md +8 -1
- package/node_modules/@litcodex/lit-loop/directives/review-work.md +12 -4
- package/node_modules/@litcodex/lit-loop/dist/codex-hook.d.ts +6 -1
- package/node_modules/@litcodex/lit-loop/dist/codex-hook.js +16 -5
- package/node_modules/@litcodex/lit-loop/dist/guards.d.ts +3 -1
- package/node_modules/@litcodex/lit-loop/dist/guards.js +5 -2
- package/node_modules/@litcodex/lit-loop/dist/hook-cli.d.ts +2 -0
- package/node_modules/@litcodex/lit-loop/dist/hook-cli.js +26 -8
- package/node_modules/@litcodex/lit-loop/dist/markers.d.ts +2 -0
- package/node_modules/@litcodex/lit-loop/dist/markers.js +2 -0
- package/node_modules/@litcodex/lit-loop/dist/modes.d.ts +1 -1
- package/node_modules/@litcodex/lit-loop/dist/modes.js +9 -1
- package/node_modules/@litcodex/lit-loop/dist/motion-route.js +2 -0
- package/node_modules/@litcodex/lit-loop/dist/plan-persistence.d.ts +2 -0
- package/node_modules/@litcodex/lit-loop/dist/plan-persistence.js +8 -0
- package/node_modules/@litcodex/lit-loop/dist/reentry.d.ts +56 -0
- package/node_modules/@litcodex/lit-loop/dist/reentry.js +171 -0
- package/node_modules/@litcodex/lit-loop/dist/route-context.js +5 -2
- package/node_modules/@litcodex/lit-loop/dist/route-heads.js +35 -15
- package/node_modules/@litcodex/lit-loop/dist/skill-mention-scope.js +2 -0
- package/node_modules/@litcodex/lit-loop/dist/trigger.d.ts +2 -2
- package/node_modules/@litcodex/lit-loop/dist/trigger.js +15 -5
- package/node_modules/@litcodex/lit-loop/dist/workflow-map.js +1 -0
- package/node_modules/@litcodex/lit-loop/package.json +1 -1
- package/node_modules/@litcodex/lit-loop/skills/browser-drive/scripts/capability-probe.mjs +24 -4
- package/node_modules/@litcodex/lit-loop/skills/deep-interview/SKILL.md +3 -1
- package/node_modules/@litcodex/lit-loop/skills/lit-brainstorm/SKILL.md +271 -0
- package/node_modules/@litcodex/lit-loop/skills/lit-loop/SKILL.md +8 -1
- package/node_modules/@litcodex/lit-loop/skills/litgoal/SKILL.md +8 -3
- package/node_modules/@litcodex/lit-loop/skills/review-work/SKILL.md +21 -4
- package/package.json +2 -2
- package/readme-assets/badge-version.svg +1 -1
- package/readme-assets/cover-motion-still.webp +0 -0
- package/readme-assets/cover-motion.webp +0 -0
- package/readme-assets/cover.webp +0 -0
- package/readme-assets/litfamily-machines.png +0 -0
- package/readme-assets/skills/lit-brainstorm.webp +0 -0
|
@@ -25,6 +25,7 @@ import { isExactBareHandoffPrompt, shouldSuppressHandoffInjection } from "./hand
|
|
|
25
25
|
import { activationMessage } from "./lit-mark.js";
|
|
26
26
|
import { BROWSER_DRIVE_MODE_SPEC, HANDOFF_MODE_SPEC, modeForToken, resolveSkillPath, SCIENTIFIC_VISUALIZATION_MODE_SPEC, } from "./modes.js";
|
|
27
27
|
import { motionRouteContext } from "./motion-route.js";
|
|
28
|
+
import { continueContext, enterRoute, entryNotes, NO_REENTRY } from "./reentry.js";
|
|
28
29
|
import { loadRouteContext, loadSkillInvocationContext } from "./route-context.js";
|
|
29
30
|
import { isExactBareScientificVisualizationPrompt, isScientificVisualizationWhitespaceNearMiss, shouldSuppressScientificVisualizationInjection, } from "./scientific-visualization-route.js";
|
|
30
31
|
import { matchRenamedSkillInvocation, skillRenameNote } from "./skill-renames.js";
|
|
@@ -153,8 +154,11 @@ function loadDirectiveForModeFailSilent(mode) {
|
|
|
153
154
|
* (guard 0) → resolve the mode → run guards 1-3 against the MATCHED mode's marker (RC1) → load that
|
|
154
155
|
* mode's directive fail-silent. Returns { kind:"noop" } for a wrong-shape value, no trigger, a guard
|
|
155
156
|
* veto, or a fail-silent empty directive; { kind:"inject", stdout } only on a real activation.
|
|
157
|
+
*
|
|
158
|
+
* `reentry` is read only once a lit-family route has matched. A route whose contract this session
|
|
159
|
+
* already holds gets the short continue context (`entry: "continue"`) instead of the full activation.
|
|
156
160
|
*/
|
|
157
|
-
export function runUserPromptSubmitHook(input) {
|
|
161
|
+
export function runUserPromptSubmitHook(input, reentry = () => NO_REENTRY) {
|
|
158
162
|
if (!isLitUserPromptSubmitInput(input)) {
|
|
159
163
|
return { kind: "noop" };
|
|
160
164
|
}
|
|
@@ -217,22 +221,29 @@ export function runUserPromptSubmitHook(input) {
|
|
|
217
221
|
return { kind: "noop" };
|
|
218
222
|
}
|
|
219
223
|
const mode = modeForToken(match.token);
|
|
220
|
-
|
|
224
|
+
// Whether this session already holds the contract comes from the session's saved state (reentry.ts), not the transcript.
|
|
225
|
+
const decision = shouldSuppressInjection(input.prompt, transcriptPath, mode.openMarker, { transcriptDedupe: false });
|
|
221
226
|
if (decision.suppress) {
|
|
222
227
|
return { kind: "noop" };
|
|
223
228
|
}
|
|
224
|
-
const
|
|
229
|
+
const entry = enterRoute(input.prompt, mode.mode, reentry());
|
|
230
|
+
const keeps = entry.kind === "continue" || (entry.kind === "resume" && entry.active);
|
|
231
|
+
const route = entry.kind === "first" ? mode.mode : entry.route;
|
|
232
|
+
const context = keeps ? continueContext(route, entry) : loadDirectiveForModeFailSilent(mode);
|
|
225
233
|
const stdout = context === ""
|
|
226
234
|
? ""
|
|
227
235
|
: formatAdditionalContextOutput([
|
|
228
236
|
context,
|
|
237
|
+
...(keeps ? [] : entryNotes(entry)),
|
|
229
238
|
mode.skillName === "lit-loop" ? motionRouteContext(mode.skillPath, input.prompt) : "",
|
|
230
239
|
skillRenameNote(match.raw),
|
|
231
240
|
]
|
|
232
241
|
.filter(Boolean)
|
|
233
|
-
.join("\n"),
|
|
242
|
+
.join("\n"), route);
|
|
234
243
|
if (stdout === "") {
|
|
235
244
|
return { kind: "noop" };
|
|
236
245
|
}
|
|
237
|
-
return
|
|
246
|
+
return keeps
|
|
247
|
+
? { kind: "inject", stdout, mode: route, entry: "continue" }
|
|
248
|
+
: { kind: "inject", stdout, mode: mode.mode };
|
|
238
249
|
}
|
|
@@ -68,6 +68,8 @@ export declare function transcriptHasContextPressureMarker(transcriptPath: Guard
|
|
|
68
68
|
* GuardTranscriptInput path (the only throw is the non-string prompt defensive guard).
|
|
69
69
|
* @throws TypeError only if `prompt` is not a string (M06 type-guards this upstream).
|
|
70
70
|
*/
|
|
71
|
-
export declare function shouldSuppressInjection(prompt: string, transcriptPath: GuardTranscriptInput, openMarker: string
|
|
71
|
+
export declare function shouldSuppressInjection(prompt: string, transcriptPath: GuardTranscriptInput, openMarker: string, options?: {
|
|
72
|
+
readonly transcriptDedupe?: boolean;
|
|
73
|
+
}): LitLoopGuardDecision;
|
|
72
74
|
/** Lit-loop entry point (backward-compatible) — the generic decision bound to the lit-loop marker. */
|
|
73
75
|
export declare function shouldSuppressLitLoopInjection(prompt: string, transcriptPath: GuardTranscriptInput): LitLoopGuardDecision;
|
|
@@ -189,7 +189,7 @@ export function transcriptHasContextPressureMarker(transcriptPath) {
|
|
|
189
189
|
* GuardTranscriptInput path (the only throw is the non-string prompt defensive guard).
|
|
190
190
|
* @throws TypeError only if `prompt` is not a string (M06 type-guards this upstream).
|
|
191
191
|
*/
|
|
192
|
-
export function shouldSuppressInjection(prompt, transcriptPath, openMarker) {
|
|
192
|
+
export function shouldSuppressInjection(prompt, transcriptPath, openMarker, options = {}) {
|
|
193
193
|
if (typeof prompt !== "string") {
|
|
194
194
|
throw new TypeError(PROMPT_NOT_A_STRING);
|
|
195
195
|
}
|
|
@@ -201,7 +201,10 @@ export function shouldSuppressInjection(prompt, transcriptPath, openMarker) {
|
|
|
201
201
|
}
|
|
202
202
|
// RC1: guard 2 checks the MATCHED mode's marker only — re-injecting the SAME mode is suppressed,
|
|
203
203
|
// switching modes (e.g. `lit` after `litwork`) is allowed.
|
|
204
|
-
|
|
204
|
+
// Guard 2 matches a top-level hook envelope line. Codex records a hook's context as a developer message
|
|
205
|
+
// instead, so on a real host it never matched; the multi-mode hook turns it off and keeps its own
|
|
206
|
+
// per-session state (reentry.ts), which also survives a compaction that leaves the transcript intact.
|
|
207
|
+
if (options.transcriptDedupe !== false && transcriptHasDirectiveMarker(transcriptPath, openMarker)) {
|
|
205
208
|
return { suppress: true, reason: "already-injected" };
|
|
206
209
|
}
|
|
207
210
|
if (transcriptHasContextPressureMarker(transcriptPath)) {
|
|
@@ -25,6 +25,8 @@ export interface AutoHandoffHookOptions {
|
|
|
25
25
|
* instead of scrolling away with the first one. In the terminal `codex` the same tool returns the map as text.
|
|
26
26
|
*/
|
|
27
27
|
export declare const CARD_OFFER_CONTEXT = "LIT card: if the `lit_card` tool (litcodex MCP server) is available, call the `lit_card` tool once now, with no arguments, so the user sees the live LIT card for this turn. It replaces the previous turn's card, which folds itself into one line. Do not call it again in this turn; it updates by itself.";
|
|
28
|
+
/** The card request for a continued discipline: the model already read the full one when it was activated. */
|
|
29
|
+
export declare const CARD_OFFER_CONTINUE_CONTEXT = "LIT card: if the `lit_card` tool is available, call it once now with no arguments; it updates by itself.";
|
|
28
30
|
/** Enforce lit-plan persistence when a Stop hook event arrives. */
|
|
29
31
|
export declare function runStopPlanPersistenceHookCli(stdin: NodeJS.ReadableStream, stdout: NodeJS.WritableStream, stderr: NodeJS.WritableStream, repoRoot?: string, auto?: AutoHandoffHookOptions): Promise<number>;
|
|
30
32
|
/** SessionStart: after a compaction inside a turn, bring this session's fresh handoff back once. */
|
|
@@ -12,7 +12,8 @@ import { claimReloadContext, evaluateAutoHandoffStop, recordCompaction, takeRelo
|
|
|
12
12
|
import { applyAutoHandoffRoute, clearManagedCompactionWhenOff, parseAutoHandoffRoute, } from "./auto-handoff-settings.js";
|
|
13
13
|
import { applyPreToolUseCreateGoalGuard, isLitUserPromptSubmitInput, runUserPromptSubmitHook } from "./codex-hook.js";
|
|
14
14
|
import { endLiveStep, recordLiveStepEnd, recordLiveStepStart, recordTurnStart, writeThreadPointer, } from "./live-step.js";
|
|
15
|
-
import { evaluatePlanPersistence, formatStopBlockOutput, recordLitPlanActivation } from "./plan-persistence.js";
|
|
15
|
+
import { evaluatePlanPersistence, formatStopBlockOutput, rearmLitPlanIfSatisfied, recordLitPlanActivation, } from "./plan-persistence.js";
|
|
16
|
+
import { clearActiveRoute, isBareLit, readActiveRoute, readResumeWork, recordActiveRoute } from "./reentry.js";
|
|
16
17
|
import { workflowCard } from "./screen-card.js";
|
|
17
18
|
import { screenColor } from "./screen-status.js";
|
|
18
19
|
import { recordWorkflowTurn, workflowStopLine, workflowTurn } from "./workflow-map.js";
|
|
@@ -102,20 +103,31 @@ export async function runUserPromptSubmitHookCli(stdin, stdout, stderr, repoRoot
|
|
|
102
103
|
}
|
|
103
104
|
clearManagedCompactionWhenOff(hookCwd(parsed, repoRoot), auto.env ?? process.env);
|
|
104
105
|
const pointer = hookSessionScope(parsed, repoRoot);
|
|
105
|
-
const decision = runUserPromptSubmitHook(parsed)
|
|
106
|
+
const decision = runUserPromptSubmitHook(parsed, () => ({
|
|
107
|
+
active: pointer === null ? null : readActiveRoute(pointer.cwd, pointer.sessionId),
|
|
108
|
+
resume: pointer === null ? null : readResumeWork(pointer.cwd, pointer.sessionId),
|
|
109
|
+
}));
|
|
110
|
+
if (pointer !== null && decision.kind === "inject")
|
|
111
|
+
recordActiveRoute(pointer.cwd, pointer.sessionId, decision.mode);
|
|
106
112
|
// Only a LIT thread gets a pointer: this prompt ignites LIT, or an earlier one already did.
|
|
107
113
|
if (pointer !== null && (decision.kind === "inject" || workflowTurn(pointer.cwd, pointer.sessionId) !== null)) {
|
|
108
114
|
writeThreadPointer(auto.env ?? process.env, pointer.sessionId, pointer.cwd, auto.now);
|
|
109
115
|
recordTurnStart(pointer.cwd, pointer.sessionId, auto.now);
|
|
110
116
|
}
|
|
117
|
+
// A continued lit-plan keeps its persistence gate as it is. A fresh activation arms it again, and so does an
|
|
118
|
+
// explicit `lit plan …` once the previous plan was saved (a bare `lit` carries on and never re-arms).
|
|
111
119
|
if (decision.kind === "inject" && decision.mode === "lit-plan") {
|
|
112
120
|
const scope = hookSessionScope(parsed, repoRoot);
|
|
113
|
-
if (scope !== null)
|
|
114
|
-
|
|
121
|
+
if (scope !== null) {
|
|
122
|
+
if (decision.entry !== "continue")
|
|
123
|
+
recordLitPlanActivation(scope.cwd, scope.sessionId);
|
|
124
|
+
else if (isLitUserPromptSubmitInput(parsed) && !isBareLit(parsed.prompt))
|
|
125
|
+
rearmLitPlanIfSatisfied(scope.cwd, scope.sessionId);
|
|
126
|
+
}
|
|
115
127
|
}
|
|
116
128
|
const env = auto.env ?? process.env;
|
|
117
129
|
const own = decision.kind === "inject"
|
|
118
|
-
? withCardOffer(withWorkflowMap(decision.stdout, parsed, decision.mode, env), pointer, auto)
|
|
130
|
+
? withCardOffer(withWorkflowMap(decision.stdout, parsed, decision.mode, env), pointer, auto, decision.entry === "continue")
|
|
119
131
|
: "";
|
|
120
132
|
const output = withAutoHandoffReload(own, parsed, repoRoot, auto);
|
|
121
133
|
if (output !== "")
|
|
@@ -209,14 +221,17 @@ function withWorkflowMap(stdout, parsed, mode, env) {
|
|
|
209
221
|
* instead of scrolling away with the first one. In the terminal `codex` the same tool returns the map as text.
|
|
210
222
|
*/
|
|
211
223
|
export const CARD_OFFER_CONTEXT = "LIT card: if the `lit_card` tool (litcodex MCP server) is available, call the `lit_card` tool once now, with no arguments, so the user sees the live LIT card for this turn. It replaces the previous turn's card, which folds itself into one line. Do not call it again in this turn; it updates by itself.";
|
|
224
|
+
/** The card request for a continued discipline: the model already read the full one when it was activated. */
|
|
225
|
+
export const CARD_OFFER_CONTINUE_CONTEXT = "LIT card: if the `lit_card` tool is available, call it once now with no arguments; it updates by itself.";
|
|
212
226
|
/**
|
|
213
227
|
* Add the card request to every LIT activation, right under the banner line so it stays inside the part
|
|
214
228
|
* of the context Codex always shows, and remember when it was last made.
|
|
215
229
|
*/
|
|
216
|
-
function withCardOffer(stdout, scope, auto) {
|
|
230
|
+
function withCardOffer(stdout, scope, auto, continued = false) {
|
|
217
231
|
if (scope === null || stdout === "")
|
|
218
232
|
return stdout;
|
|
219
|
-
const
|
|
233
|
+
const offer = continued ? CARD_OFFER_CONTINUE_CONTEXT : CARD_OFFER_CONTEXT;
|
|
234
|
+
const merged = withContextAfterBanner(stdout, offer) ?? withReloadContext(stdout, offer);
|
|
220
235
|
if (merged === null)
|
|
221
236
|
return stdout;
|
|
222
237
|
writeThreadPointer(auto.env ?? process.env, scope.sessionId, scope.cwd, auto.now, { cardOffered: true });
|
|
@@ -374,8 +389,11 @@ export async function runPostCompactHookCli(stdin, _stdout, stderr, repoRoot = p
|
|
|
374
389
|
return event.exit;
|
|
375
390
|
clearManagedCompactionWhenOff(hookCwd(event.parsed, repoRoot), auto.env ?? process.env);
|
|
376
391
|
const scope = hookSessionScope(event.parsed, repoRoot);
|
|
377
|
-
if (scope !== null)
|
|
392
|
+
if (scope !== null) {
|
|
378
393
|
recordCompaction(scope.cwd, scope.sessionId);
|
|
394
|
+
// The activation text may be gone from the model's context, so the next lit prompt sends it in full.
|
|
395
|
+
clearActiveRoute(scope.cwd, scope.sessionId);
|
|
396
|
+
}
|
|
379
397
|
return 0;
|
|
380
398
|
}
|
|
381
399
|
export async function runPreToolUseCreateGoalGuardCli(stdin, stdout, stderr) {
|
|
@@ -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,
|
|
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
|
|
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
|
/**
|