@litfamily/litclaude 1.0.34 → 1.0.36
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/CHANGELOG.md +59 -44
- package/README.md +8 -8
- package/README_ko-KR.md +8 -8
- package/bin/litclaude-ai.js +24 -11
- package/docs/agents.md +5 -0
- package/docs/assets/cover-motion-still.webp +0 -0
- package/docs/assets/cover-motion.webp +0 -0
- package/docs/assets/cover.webp +0 -0
- package/docs/assets/litfamily-machines.png +0 -0
- package/docs/assets/readme/ascii-readme.svg +1 -1
- package/docs/assets/readme/badge-version.svg +1 -1
- package/docs/assets/skills/lit-brainstorm.webp +0 -0
- package/docs/hooks.md +77 -14
- package/docs/migration.md +2 -2
- package/package.json +2 -1
- package/plugins/litclaude/.claude-plugin/plugin.json +1 -1
- package/plugins/litclaude/bin/litclaude-hook.js +166 -17
- package/plugins/litclaude/bin/litclaude-lsp-doctor.js +10 -3
- package/plugins/litclaude/bin/litclaude-mcp.js +1 -1
- package/plugins/litclaude/bundled-rules/lit-humanizer.md +1 -0
- package/plugins/litclaude/commands/deep-interview.md +4 -0
- package/plugins/litclaude/commands/lit-brainstorm.md +108 -0
- package/plugins/litclaude/commands/litgoal.md +1 -1
- package/plugins/litclaude/commands/review-work.md +13 -4
- package/plugins/litclaude/hooks/lit-band-client.mjs +7 -4
- package/plugins/litclaude/hooks/lit-mod.mjs +35 -10
- package/plugins/litclaude/lib/automatic-update.mjs +15 -4
- package/plugins/litclaude/lib/canonical-skill-catalog.mjs +1 -0
- package/plugins/litclaude/lib/canonical-skill-resources.mjs +72 -38
- package/plugins/litclaude/lib/deliverable-hedge-guard.mjs +173 -48
- package/plugins/litclaude/lib/lit-activation.mjs +60 -0
- package/plugins/litclaude/lib/lit-mark.mjs +1 -1
- package/plugins/litclaude/lib/mod/frame.mjs +24 -7
- package/plugins/litclaude/lib/mod/motion.mjs +2 -1
- package/plugins/litclaude/lib/mod/skills.mjs +1 -0
- package/plugins/litclaude/lib/mod/svg-card.mjs +2 -2
- package/plugins/litclaude/lib/mod/timeline.mjs +12 -0
- package/plugins/litclaude/lib/mod/toasts.mjs +89 -0
- package/plugins/litclaude/lib/mod/view.mjs +16 -10
- package/plugins/litclaude/lib/mod/workflow.mjs +1 -0
- package/plugins/litclaude/lib/motion-render-gate.mjs +9 -4
- package/plugins/litclaude/lib/npm-invocation.mjs +64 -0
- package/plugins/litclaude/lib/office-runtime.mjs +40 -14
- package/plugins/litclaude/lib/office_runtime_bootstrap.py +13 -1
- package/plugins/litclaude/lib/rules/engine.mjs +23 -5
- package/plugins/litclaude/lib/start-work-lifecycle.mjs +125 -9
- package/plugins/litclaude/skills/deep-interview/SKILL.md +1 -1
- package/plugins/litclaude/skills/lit-brainstorm/SKILL.md +430 -0
- package/plugins/litclaude/skills/lit-brainstorm/references/idea-lenses.md +192 -0
- package/plugins/litclaude/skills/lit-brainstorm/references/scoring-and-convergence.md +149 -0
- package/plugins/litclaude/skills/lit-brainstorm/references/session-notes-template.md +106 -0
- package/plugins/litclaude/skills/lit-diagram-drawer/scripts/export.mjs +3 -4
- package/plugins/litclaude/skills/lit-diagram-drawer/scripts/renderer.mjs +10 -2
- package/plugins/litclaude/skills/lit-docx/SKILL.md +1 -1
- package/plugins/litclaude/skills/lit-docx/scripts/convert_md_to_pdf.py +23 -0
- package/plugins/litclaude/skills/lit-docx/templates/latex/acs/template.tex +14 -0
- package/plugins/litclaude/skills/lit-docx/templates/latex/elsevier/template.tex +14 -0
- package/plugins/litclaude/skills/lit-docx/templates/latex/ieee/template.tex +14 -0
- package/plugins/litclaude/skills/lit-docx/templates/latex/korean-generic/template.tex +14 -0
- package/plugins/litclaude/skills/lit-docx/templates/latex/nature/template.tex +14 -0
- package/plugins/litclaude/skills/lit-humanizer/SKILL.md +4 -0
- package/plugins/litclaude/skills/lit-humanizer/scripts/core.mjs +94 -1
- package/plugins/litclaude/skills/lit-humanizer/scripts/detect.mjs +3 -2
- package/plugins/litclaude/skills/lit-humanizer/scripts/scan-input.mjs +15 -2
- package/plugins/litclaude/skills/lit-loop/SKILL.md +11 -0
- package/plugins/litclaude/skills/lit-plan/SKILL.md +2 -1
- package/plugins/litclaude/skills/lit-typographic-motion/SKILL.md +14 -5
- package/plugins/litclaude/skills/lit-typographic-motion/engine/THIRD_PARTY_NOTICES +6 -0
- package/plugins/litclaude/skills/lit-typographic-motion/engine/core/constants.mjs +35 -0
- package/plugins/litclaude/skills/lit-typographic-motion/engine/node/chrome.mjs +3 -7
- package/plugins/litclaude/skills/lit-typographic-motion/engine/node/cover-assets.mjs +102 -0
- package/plugins/litclaude/skills/lit-typographic-motion/engine/node/cover-capture.mjs +210 -0
- package/plugins/litclaude/skills/lit-typographic-motion/engine/node/cover-gate.mjs +346 -0
- package/plugins/litclaude/skills/lit-typographic-motion/engine/node/cover-image.mjs +141 -0
- package/plugins/litclaude/skills/lit-typographic-motion/engine/node/cover-sheet.mjs +76 -0
- package/plugins/litclaude/skills/lit-typographic-motion/engine/node/cover-treatment.mjs +106 -0
- package/plugins/litclaude/skills/lit-typographic-motion/engine/node/cover-worker.mjs +32 -0
- package/plugins/litclaude/skills/lit-typographic-motion/engine/node/cover.mjs +373 -0
- package/plugins/litclaude/skills/lit-typographic-motion/engine/node/done.mjs +68 -2
- package/plugins/litclaude/skills/lit-typographic-motion/engine/node/encode.mjs +3 -5
- package/plugins/litclaude/skills/lit-typographic-motion/engine/node/host.mjs +31 -0
- package/plugins/litclaude/skills/lit-typographic-motion/engine/node/look.mjs +53 -17
- package/plugins/litclaude/skills/lit-typographic-motion/engine/node/runtime.mjs +42 -12
- package/plugins/litclaude/skills/lit-typographic-motion/engine/node/stage-capture.mjs +2 -1
- package/plugins/litclaude/skills/lit-typographic-motion/engine/node/stage-serve.mjs +6 -1
- package/plugins/litclaude/skills/lit-typographic-motion/engine/node/stage.mjs +2 -2
- package/plugins/litclaude/skills/lit-typographic-motion/engine/node/treatment.mjs +2 -1
- package/plugins/litclaude/skills/lit-typographic-motion/engine/node/webp.mjs +145 -0
- package/plugins/litclaude/skills/lit-typographic-motion/engine/stage/cover-init.js +37 -0
- package/plugins/litclaude/skills/lit-typographic-motion/engine/stage/loop-kit.js +106 -0
- package/plugins/litclaude/skills/lit-typographic-motion/fonts/jetbrains-mono/JetBrainsMono-wght-latin.woff2 +0 -0
- package/plugins/litclaude/skills/lit-typographic-motion/fonts/jetbrains-mono/OFL.txt +93 -0
- package/plugins/litclaude/skills/lit-typographic-motion/fonts/manifest.json +18 -0
- package/plugins/litclaude/skills/lit-typographic-motion/recipes/negatives/card-scenes/expected.json +16 -0
- package/plugins/litclaude/skills/lit-typographic-motion/recipes/negatives/card-scenes/index.html +27 -0
- package/plugins/litclaude/skills/lit-typographic-motion/recipes/negatives/reset-sweep/expected.json +16 -0
- package/plugins/litclaude/skills/lit-typographic-motion/recipes/negatives/reset-sweep/index.html +17 -0
- package/plugins/litclaude/skills/lit-typographic-motion/recipes/negatives/still-glow/expected.json +17 -0
- package/plugins/litclaude/skills/lit-typographic-motion/recipes/negatives/still-glow/index.html +18 -0
- package/plugins/litclaude/skills/lit-typographic-motion/recipes/negatives/title-slam/expected.json +17 -0
- package/plugins/litclaude/skills/lit-typographic-motion/recipes/negatives/title-slam/index.html +30 -0
- package/plugins/litclaude/skills/lit-typographic-motion/recipes/orbit-loop/expected.json +67 -0
- package/plugins/litclaude/skills/lit-typographic-motion/recipes/orbit-loop/index.html +152 -0
- package/plugins/litclaude/skills/lit-typographic-motion/recipes/painted-light/expected.json +95 -0
- package/plugins/litclaude/skills/lit-typographic-motion/recipes/painted-light/index.html +202 -0
- package/plugins/litclaude/skills/lit-typographic-motion/recipes/weight-tide/expected.json +67 -0
- package/plugins/litclaude/skills/lit-typographic-motion/recipes/weight-tide/index.html +100 -0
- package/plugins/litclaude/skills/lit-typographic-motion/references/cover.md +372 -0
- package/plugins/litclaude/skills/lit-typographic-motion/references/look.md +2 -1
- package/plugins/litclaude/skills/lit-typographic-motion/references/runtime.md +4 -3
- package/plugins/litclaude/skills/lit-typographic-motion/references/stage.md +1 -0
- package/plugins/litclaude/skills/lit-typographic-motion/references/treatment.md +4 -0
- package/plugins/litclaude/skills/lit-typographic-motion/scripts/motion-doctor.mjs +26 -6
- package/plugins/litclaude/skills/lit-typographic-motion/scripts/motion.mjs +43 -10
- package/plugins/litclaude/skills/litgoal/SKILL.md +9 -1
- package/plugins/litclaude/skills/lsp-setup/scripts/verify-lsp.ts +47 -6
- package/plugins/litclaude/skills/review-work/SKILL.md +37 -1
- package/plugins/litclaude/skills/start-work/SKILL.md +5 -0
- package/scripts/doctor.mjs +2 -2
- package/scripts/qa-cover-recipes.mjs +172 -0
- package/scripts/validate-plugin.mjs +12 -2
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { lstatSync } from "node:fs";
|
|
1
|
+
import { existsSync, lstatSync, statSync } from "node:fs";
|
|
2
2
|
import { spawnSync } from "node:child_process";
|
|
3
|
-
import { extname, isAbsolute, relative, resolve } from "node:path";
|
|
3
|
+
import { dirname, extname, isAbsolute, join, relative, resolve } from "node:path";
|
|
4
4
|
|
|
5
5
|
import { extractCreatedDocumentPaths, extractMutatedFilePaths } from "./mutated-file-paths.mjs";
|
|
6
6
|
import { readRegularStable } from "./secure-path-read.mjs";
|
|
7
7
|
import { extractArtifactText } from "../skills/lit-humanizer/scripts/artifact-text.mjs";
|
|
8
|
+
import { NEGATION_CLUSTER_MESSAGE } from "../skills/lit-humanizer/scripts/core.mjs";
|
|
8
9
|
|
|
9
10
|
const MAX_ARTIFACT_BYTES = 512 * 1024;
|
|
10
11
|
const MAX_AGGREGATE_BYTES = 2 * 1024 * 1024;
|
|
@@ -39,12 +40,33 @@ const internalPath = (cwd, path) => {
|
|
|
39
40
|
|| /\.jsonl$/iu.test(basename);
|
|
40
41
|
};
|
|
41
42
|
|
|
42
|
-
const
|
|
43
|
+
const outside = (root, path) => {
|
|
44
|
+
const rel = relative(root, path);
|
|
45
|
+
return isAbsolute(rel) || rel.split(/[\\/]/u)[0] === "..";
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
// The session's project: the project directory the host gives the hook (Claude Code sets
|
|
49
|
+
// CLAUDE_PROJECT_DIR), else the git toplevel above cwd, else cwd itself.
|
|
50
|
+
const projectRootFor = (cwd, projectDir) => {
|
|
51
|
+
if (typeof projectDir === "string" && projectDir.length > 0
|
|
52
|
+
&& statSync(resolve(projectDir), { throwIfNoEntry: false })?.isDirectory() === true) return resolve(projectDir);
|
|
53
|
+
for (let current = cwd; ; current = dirname(current)) {
|
|
54
|
+
if (existsSync(join(current, ".git"))) return current;
|
|
55
|
+
if (dirname(current) === current) return cwd;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
// The absolute path and the root it is judged and read against. A path under the reported cwd keeps
|
|
60
|
+
// cwd as its root. The host reports a subfolder as cwd after a shell `cd`, so a path outside cwd but
|
|
61
|
+
// inside the project is judged against the project root. Anything else, such as host config, memory
|
|
62
|
+
// or temp notes, is not a project deliverable and is skipped.
|
|
63
|
+
const locate = (cwd, path, projectDir) => {
|
|
43
64
|
if (typeof cwd !== "string" || typeof path !== "string" || cwd.length === 0 || path.length === 0) return null;
|
|
44
|
-
const
|
|
45
|
-
const absolutePath = isAbsolute(path) ? resolve(path) : resolve(
|
|
46
|
-
|
|
47
|
-
|
|
65
|
+
const base = resolve(cwd);
|
|
66
|
+
const absolutePath = isAbsolute(path) ? resolve(path) : resolve(base, path);
|
|
67
|
+
if (!outside(base, absolutePath)) return { path: absolutePath, root: base };
|
|
68
|
+
const project = projectRootFor(base, projectDir);
|
|
69
|
+
return outside(project, absolutePath) ? null : { path: absolutePath, root: project };
|
|
48
70
|
};
|
|
49
71
|
|
|
50
72
|
const toolArtifacts = (input) => {
|
|
@@ -60,7 +82,8 @@ const toolArtifacts = (input) => {
|
|
|
60
82
|
const text = typeof toolInput.new_string === "string" ? toolInput.new_string : toolInput.newString;
|
|
61
83
|
const before = typeof toolInput.old_string === "string" ? toolInput.old_string : toolInput.oldString;
|
|
62
84
|
if (!path || typeof text !== "string") return { artifacts: [], skipped: true };
|
|
63
|
-
|
|
85
|
+
const all = toolInput.replace_all === true || toolInput.replaceAll === true;
|
|
86
|
+
return { artifacts: [{ path, text, ...(typeof before === "string" ? { before, all } : {}) }], skipped: false };
|
|
64
87
|
}
|
|
65
88
|
if (toolName !== "multiedit" && toolName !== "multi_edit") return { artifacts: [], skipped: false };
|
|
66
89
|
if (path && Array.isArray(toolInput.edits)) {
|
|
@@ -70,7 +93,8 @@ const toolArtifacts = (input) => {
|
|
|
70
93
|
const text = typeof edit.new_string === "string" ? edit.new_string : edit.newString;
|
|
71
94
|
const before = typeof edit.old_string === "string" ? edit.old_string : edit.oldString;
|
|
72
95
|
if (typeof text !== "string") return { artifacts: [], skipped: true };
|
|
73
|
-
|
|
96
|
+
const all = edit.replace_all === true || edit.replaceAll === true;
|
|
97
|
+
artifacts.push({ path, text, ...(typeof before === "string" ? { before, all } : {}) });
|
|
74
98
|
}
|
|
75
99
|
return { artifacts, skipped: false };
|
|
76
100
|
}
|
|
@@ -87,8 +111,11 @@ const toolArtifacts = (input) => {
|
|
|
87
111
|
return { artifacts, skipped: false };
|
|
88
112
|
};
|
|
89
113
|
|
|
90
|
-
const
|
|
91
|
-
|
|
114
|
+
const splitLines = (text) => text.split(/\r?\n/u);
|
|
115
|
+
|
|
116
|
+
// Line diff of `before` against `after`: `added` holds the indexes of new lines, `from` maps each kept
|
|
117
|
+
// line of `after` to its line in `before`. Returns null when the diff exceeds its bounds.
|
|
118
|
+
const diffLines = (before, after) => {
|
|
92
119
|
const oldLines = before.split(/\r?\n/u);
|
|
93
120
|
const newLines = after.split(/\r?\n/u);
|
|
94
121
|
if (oldLines.length > MAX_DIFF_LINES || newLines.length > MAX_DIFF_LINES) return null;
|
|
@@ -99,8 +126,15 @@ const changedLines = (before, after) => {
|
|
|
99
126
|
&& oldLines[oldLines.length - suffix - 1] === newLines[newLines.length - suffix - 1]) suffix += 1;
|
|
100
127
|
const oldMiddle = oldLines.slice(prefix, oldLines.length - suffix);
|
|
101
128
|
const newMiddle = newLines.slice(prefix, newLines.length - suffix);
|
|
102
|
-
|
|
103
|
-
|
|
129
|
+
const added = new Set();
|
|
130
|
+
const from = new Map();
|
|
131
|
+
for (let index = 0; index < prefix; index += 1) from.set(index, index);
|
|
132
|
+
for (let index = 1; index <= suffix; index += 1) from.set(newLines.length - index, oldLines.length - index);
|
|
133
|
+
if (oldMiddle.length === 0) {
|
|
134
|
+
newMiddle.forEach((_, index) => added.add(prefix + index));
|
|
135
|
+
return { added, from };
|
|
136
|
+
}
|
|
137
|
+
if (newMiddle.length === 0) return { added, from };
|
|
104
138
|
|
|
105
139
|
const n = oldMiddle.length;
|
|
106
140
|
const m = newMiddle.length;
|
|
@@ -130,7 +164,6 @@ const changedLines = (before, after) => {
|
|
|
130
164
|
if (work > MAX_DIFF_WORK) return null;
|
|
131
165
|
if (nextX < n || nextY < m) continue;
|
|
132
166
|
|
|
133
|
-
const added = [];
|
|
134
167
|
let backX = n;
|
|
135
168
|
let backY = m;
|
|
136
169
|
for (let backDistance = distance; backDistance >= 0; backDistance -= 1) {
|
|
@@ -146,21 +179,115 @@ const changedLines = (before, after) => {
|
|
|
146
179
|
while (backX > previousX && backY > previousY) {
|
|
147
180
|
backX -= 1;
|
|
148
181
|
backY -= 1;
|
|
182
|
+
from.set(prefix + backY, prefix + backX);
|
|
149
183
|
}
|
|
150
184
|
if (backDistance === 0) break;
|
|
151
185
|
if (backX === previousX) {
|
|
152
|
-
added.
|
|
186
|
+
added.add(prefix + backY - 1);
|
|
153
187
|
backY -= 1;
|
|
154
188
|
} else {
|
|
155
189
|
backX -= 1;
|
|
156
190
|
}
|
|
157
191
|
}
|
|
158
|
-
return added
|
|
192
|
+
return { added, from };
|
|
159
193
|
}
|
|
160
194
|
}
|
|
161
195
|
return null;
|
|
162
196
|
};
|
|
163
197
|
|
|
198
|
+
// Applies one Edit to the proposed text and carries a per-line "changed" mark through it. Returns false
|
|
199
|
+
// when old_string is not in the text (the host refuses that edit too) and null when the diff is too large.
|
|
200
|
+
const applyEdit = (state, before, after, all) => {
|
|
201
|
+
const index = state.text.indexOf(before);
|
|
202
|
+
if (index === -1) return false;
|
|
203
|
+
if (all) {
|
|
204
|
+
const text = state.text.split(before).join(after);
|
|
205
|
+
const diff = diffLines(state.text, text);
|
|
206
|
+
if (diff === null) return null;
|
|
207
|
+
state.marks = splitLines(text).map((_, line) => diff.added.has(line)
|
|
208
|
+
|| (diff.from.has(line) && state.marks[diff.from.get(line)] === true));
|
|
209
|
+
state.text = text;
|
|
210
|
+
return true;
|
|
211
|
+
}
|
|
212
|
+
const diff = diffLines(before, after);
|
|
213
|
+
if (diff === null) return null;
|
|
214
|
+
const startLine = state.text.slice(0, index).split("\n").length - 1;
|
|
215
|
+
const region = splitLines(after).map((_, line) => diff.added.has(line)
|
|
216
|
+
|| (diff.from.has(line) && state.marks[startLine + diff.from.get(line)] === true));
|
|
217
|
+
state.marks = [...state.marks.slice(0, startLine), ...region, ...state.marks.slice(startLine + splitLines(before).length)];
|
|
218
|
+
state.text = `${state.text.slice(0, index)}${after}${state.text.slice(index + before.length)}`;
|
|
219
|
+
return true;
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
const changedRanges = (marks) => {
|
|
223
|
+
const ranges = [];
|
|
224
|
+
marks.forEach((marked, index) => {
|
|
225
|
+
if (!marked) return;
|
|
226
|
+
const last = ranges.at(-1);
|
|
227
|
+
if (last && last[1] === index) last[1] = index + 1;
|
|
228
|
+
else ranges.push([index + 1, index + 1]);
|
|
229
|
+
});
|
|
230
|
+
return ranges;
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
// The text each edited path is scanned as. Edits are applied to the file on disk so the detector sees
|
|
234
|
+
// fences, quotes and blank lines around the change; when the file cannot be read, or an old_string is not
|
|
235
|
+
// in it, each replacement text is scanned on its own, separated by a blank line.
|
|
236
|
+
const proposedChange = (root, path, candidates) => {
|
|
237
|
+
let state = null;
|
|
238
|
+
const edits = [];
|
|
239
|
+
for (const candidate of candidates) {
|
|
240
|
+
if (typeof candidate.before === "string") {
|
|
241
|
+
edits.push(candidate);
|
|
242
|
+
continue;
|
|
243
|
+
}
|
|
244
|
+
edits.length = 0;
|
|
245
|
+
state = { text: candidate.text, marks: splitLines(candidate.text).map(() => true) };
|
|
246
|
+
if (!candidate.readBefore) continue;
|
|
247
|
+
let exists;
|
|
248
|
+
try { exists = lstatSync(path, { throwIfNoEntry: false }); } catch {
|
|
249
|
+
return { failure: "existing text could not be checked safely" };
|
|
250
|
+
}
|
|
251
|
+
if (!exists) continue;
|
|
252
|
+
const read = readRegularStable(root, path, undefined, { maxBytes: MAX_ARTIFACT_BYTES });
|
|
253
|
+
if (read.failure) return { failure: "existing text could not be read safely" };
|
|
254
|
+
const diff = diffLines(read.bytes.toString("utf8"), candidate.text);
|
|
255
|
+
if (diff === null) return { failure: "changed-text diff exceeded the check limit" };
|
|
256
|
+
state.marks = state.marks.map((_, index) => diff.added.has(index));
|
|
257
|
+
}
|
|
258
|
+
if (edits.length === 0) return state;
|
|
259
|
+
if (state === null) {
|
|
260
|
+
const read = readRegularStable(root, path, undefined, { maxBytes: MAX_ARTIFACT_BYTES });
|
|
261
|
+
if (!read.failure) {
|
|
262
|
+
const text = read.bytes.toString("utf8");
|
|
263
|
+
state = { text, marks: splitLines(text).map(() => false) };
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
for (const edit of edits) {
|
|
267
|
+
if (state === null) break;
|
|
268
|
+
if (edit.before.length === 0) {
|
|
269
|
+
state = state.text.length === 0 ? { text: edit.text, marks: splitLines(edit.text).map(() => true) } : null;
|
|
270
|
+
continue;
|
|
271
|
+
}
|
|
272
|
+
const applied = applyEdit(state, edit.before, edit.text, edit.all);
|
|
273
|
+
if (applied === null) return { failure: "changed-text diff exceeded the check limit" };
|
|
274
|
+
if (!applied) state = null;
|
|
275
|
+
}
|
|
276
|
+
if (state !== null && Buffer.byteLength(state.text, "utf8") <= MAX_ARTIFACT_BYTES) return state;
|
|
277
|
+
const fallback = { text: "", marks: [] };
|
|
278
|
+
for (const edit of edits) {
|
|
279
|
+
const diff = diffLines(edit.before, edit.text);
|
|
280
|
+
if (diff === null) return { failure: "changed-text diff exceeded the check limit" };
|
|
281
|
+
if (fallback.marks.length > 0) {
|
|
282
|
+
fallback.text += "\n\n";
|
|
283
|
+
fallback.marks.push(false);
|
|
284
|
+
}
|
|
285
|
+
fallback.text += edit.text;
|
|
286
|
+
fallback.marks.push(...splitLines(edit.text).map((_, index) => diff.added.has(index)));
|
|
287
|
+
}
|
|
288
|
+
return fallback;
|
|
289
|
+
};
|
|
290
|
+
|
|
164
291
|
const runScanner = (artifacts, pluginRoot, execute = spawnSync) => {
|
|
165
292
|
const script = resolve(pluginRoot, "skills/lit-humanizer/scripts/scan-input.mjs");
|
|
166
293
|
const request = JSON.stringify({ artifacts });
|
|
@@ -203,7 +330,7 @@ export const scanHumanizerText = async (text, file = "<stdin>", pluginRoot) => {
|
|
|
203
330
|
return scanned.findings;
|
|
204
331
|
};
|
|
205
332
|
|
|
206
|
-
const evaluateDeliverableHedgeGuardInternal = ({ input, pluginRoot, phase = "pre-write", execute = spawnSync }) => {
|
|
333
|
+
const evaluateDeliverableHedgeGuardInternal = ({ input, pluginRoot, projectDir, phase = "pre-write", execute = spawnSync }) => {
|
|
207
334
|
if (!isRecord(input) || typeof pluginRoot !== "string") return cleanResult;
|
|
208
335
|
const cwd = typeof input.cwd === "string" ? input.cwd : process.cwd();
|
|
209
336
|
|
|
@@ -212,15 +339,17 @@ const evaluateDeliverableHedgeGuardInternal = ({ input, pluginRoot, phase = "pre
|
|
|
212
339
|
&& (input.tool_response.isError === true || input.tool_response.is_error === true
|
|
213
340
|
|| input.tool_response.error === true || input.tool_response.status === "error");
|
|
214
341
|
if (failed) return cleanResult;
|
|
215
|
-
const
|
|
216
|
-
.map((path) =>
|
|
217
|
-
.filter((
|
|
342
|
+
const located = [...new Set([...extractMutatedFilePaths(input), ...extractCreatedDocumentPaths(input)])]
|
|
343
|
+
.map((path) => locate(cwd, path, projectDir))
|
|
344
|
+
.filter((entry) => entry !== null && !internalPath(entry.root, entry.path) && DOCUMENT_EXTENSIONS.has(extensionOf(entry.path)));
|
|
345
|
+
const roots = new Map(located.map(({ path, root }) => [path, root]));
|
|
346
|
+
const paths = [...roots.keys()];
|
|
218
347
|
if (paths.length === 0) return cleanResult;
|
|
219
348
|
if (paths.length > 2) return { status: "unavailable", reason: "document count exceeded the check limit", findings: [], paths: [] };
|
|
220
349
|
const artifacts = [];
|
|
221
350
|
let aggregateBytes = 0;
|
|
222
351
|
for (const path of paths) {
|
|
223
|
-
const read = readRegularStable(
|
|
352
|
+
const read = readRegularStable(roots.get(path), path, undefined, { maxBytes: MAX_POST_CREATE_BYTES });
|
|
224
353
|
if (read.failure) return { status: "unavailable", reason: "document could not be read safely", findings: [], paths: [] };
|
|
225
354
|
aggregateBytes += read.bytes.length;
|
|
226
355
|
if (aggregateBytes > MAX_POST_CREATE_BYTES) return { status: "unavailable", reason: "document size exceeded the check limit", findings: [], paths: [] };
|
|
@@ -242,36 +371,30 @@ const evaluateDeliverableHedgeGuardInternal = ({ input, pluginRoot, phase = "pre
|
|
|
242
371
|
: cleanResult;
|
|
243
372
|
if (candidates.length > MAX_ARTIFACT_PATHS) return { status: "unavailable", reason: "file count exceeded the check limit", findings: [], paths: [] };
|
|
244
373
|
const byPath = new Map();
|
|
245
|
-
|
|
374
|
+
const roots = new Map();
|
|
246
375
|
for (const candidate of candidates) {
|
|
247
|
-
const
|
|
248
|
-
if (
|
|
249
|
-
|
|
250
|
-
if (
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
if (text === null) return { status: "unavailable", reason: "changed-text diff exceeded the check limit", findings: [], paths: [] };
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
if (!text) continue;
|
|
266
|
-
const bytes = Buffer.byteLength(text, "utf8");
|
|
376
|
+
const located = locate(cwd, candidate.path, projectDir);
|
|
377
|
+
if (located === null) continue;
|
|
378
|
+
const { path, root } = located;
|
|
379
|
+
if (internalPath(root, path) || !readerFacing(path) || DOCUMENT_EXTENSIONS.has(extensionOf(path))) continue;
|
|
380
|
+
byPath.set(path, [...(byPath.get(path) ?? []), candidate]);
|
|
381
|
+
roots.set(path, root);
|
|
382
|
+
}
|
|
383
|
+
const artifacts = [];
|
|
384
|
+
let aggregateBytes = 0;
|
|
385
|
+
for (const [path, group] of byPath) {
|
|
386
|
+
const change = proposedChange(roots.get(path), path, group);
|
|
387
|
+
if (change.failure) return { status: "unavailable", reason: change.failure, findings: [], paths: [] };
|
|
388
|
+
const changed = changedRanges(change.marks);
|
|
389
|
+
if (changed.length === 0 || !change.text) continue;
|
|
390
|
+
const bytes = Buffer.byteLength(change.text, "utf8");
|
|
267
391
|
aggregateBytes += bytes;
|
|
268
392
|
if (bytes > MAX_ARTIFACT_BYTES || aggregateBytes > MAX_AGGREGATE_BYTES) {
|
|
269
393
|
return { status: "unavailable", reason: "changed text exceeded the check limit", findings: [], paths: [] };
|
|
270
394
|
}
|
|
271
|
-
|
|
395
|
+
artifacts.push({ path, text: change.text, changed });
|
|
272
396
|
}
|
|
273
|
-
if (
|
|
274
|
-
const artifacts = [...byPath].map(([path, text]) => ({ path, text }));
|
|
397
|
+
if (artifacts.length === 0) return cleanResult;
|
|
275
398
|
const scanned = runScanner(artifacts, pluginRoot, execute);
|
|
276
399
|
if (scanned.failure) return { status: "unavailable", reason: `detector ${scanned.failure}`, findings: [], paths: [] };
|
|
277
400
|
return resultFor(scanned.findings, artifacts.map(({ path }) => path), scanned.total);
|
|
@@ -293,12 +416,14 @@ const findingSummary = (result) => {
|
|
|
293
416
|
return listed ? `${listed}${omitted}` : "pattern review needed";
|
|
294
417
|
};
|
|
295
418
|
|
|
419
|
+
const negationHint = (result) => result?.findings?.some((finding) => finding.rule === "negation-cluster") ? ` ${NEGATION_CLUSTER_MESSAGE}` : "";
|
|
420
|
+
|
|
296
421
|
export const formatDeliverableHedgeContext = (result) => {
|
|
297
422
|
if (result?.status === "unavailable") return `lit-humanizer check skipped; the write was allowed (${String(result.reason ?? "guard unavailable").slice(0, 120)}).`;
|
|
298
|
-
if (result?.status === "warn") return `lit-humanizer warning: review the changed prose in context; warnings do not block a write (${findingSummary(result)})
|
|
299
|
-
if (result?.phase === "post-create" && result?.status === "block") return `lit-humanizer post-create block finding: the document was created; revise the flagged drafting label or
|
|
423
|
+
if (result?.status === "warn") return `lit-humanizer warning: review the changed prose in context; warnings do not block a write (${findingSummary(result)}).${negationHint(result)}`;
|
|
424
|
+
if (result?.phase === "post-create" && result?.status === "block") return `lit-humanizer post-create block finding: the document was created; revise the flagged drafting label, disclaimer or stacked negation (${findingSummary(result)}).${negationHint(result)}`;
|
|
300
425
|
return "";
|
|
301
426
|
};
|
|
302
427
|
|
|
303
428
|
export const formatHumanizerBlockReason = (result) =>
|
|
304
|
-
`lit-humanizer blocked this write because changed prose matches a high-confidence drafting-residue rule (${findingSummary(result)}). Rewrite the new text or use the requested citation format
|
|
429
|
+
`lit-humanizer blocked this write because changed prose matches a high-confidence drafting-residue rule (${findingSummary(result)}). Rewrite the new text or use the requested citation format.${negationHint(result)}`;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { mkdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { basename, dirname, join } from "node:path";
|
|
3
|
+
|
|
4
|
+
import { ignitionStatePath } from "./hud-ignition.mjs";
|
|
5
|
+
|
|
6
|
+
// Which discipline a session's `lit` prompts already ignited. The prompt hook sends the full
|
|
7
|
+
// activation the first time a discipline starts in a session and a short note when the same
|
|
8
|
+
// discipline is asked for again, so the record is what the hook, not the model, says is active.
|
|
9
|
+
// It sits beside the per-session ignition record in the temp directory: the session id is the
|
|
10
|
+
// host's, nothing is written into the repository, and a missing or unreadable record only means
|
|
11
|
+
// the next `lit` gets the full activation again.
|
|
12
|
+
|
|
13
|
+
const DISCIPLINE_PATTERN = /^[a-z][a-z0-9-]{0,40}$/u;
|
|
14
|
+
const MAX_RECORD_BYTES = 4096;
|
|
15
|
+
|
|
16
|
+
// LITCLAUDE_ACTIVATION_STATE_ROOT moves only this record, so a test run can keep its records apart
|
|
17
|
+
// from the HUD's.
|
|
18
|
+
const recordPath = (sessionId, env) => {
|
|
19
|
+
const ignition = ignitionStatePath(sessionId, env);
|
|
20
|
+
const override = env.LITCLAUDE_ACTIVATION_STATE_ROOT?.trim();
|
|
21
|
+
return (override ? join(override, basename(ignition)) : ignition).replace(/\.json$/u, ".activation.json");
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const hasSession = (sessionId) => typeof sessionId === "string" && sessionId.trim().length > 0;
|
|
25
|
+
|
|
26
|
+
export const readActivation = (sessionId, env = process.env) => {
|
|
27
|
+
if (!hasSession(sessionId)) return null;
|
|
28
|
+
try {
|
|
29
|
+
const path = recordPath(sessionId, env);
|
|
30
|
+
if (statSync(path).size > MAX_RECORD_BYTES) return null;
|
|
31
|
+
const record = JSON.parse(readFileSync(path, "utf8"));
|
|
32
|
+
if (!record || typeof record !== "object" || record.sessionId !== sessionId) return null;
|
|
33
|
+
return typeof record.discipline === "string" && DISCIPLINE_PATTERN.test(record.discipline) ? record.discipline : null;
|
|
34
|
+
} catch {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export const recordActivation = (sessionId, discipline, env = process.env, now = () => new Date()) => {
|
|
40
|
+
if (!hasSession(sessionId) || !DISCIPLINE_PATTERN.test(discipline ?? "")) return false;
|
|
41
|
+
try {
|
|
42
|
+
const path = recordPath(sessionId, env);
|
|
43
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
44
|
+
const staging = `${path}.${process.pid}.tmp`;
|
|
45
|
+
writeFileSync(staging, `${JSON.stringify({ sessionId, discipline, at: now().toISOString() })}\n`);
|
|
46
|
+
renameSync(staging, path);
|
|
47
|
+
return true;
|
|
48
|
+
} catch {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export const clearActivation = (sessionId, env = process.env) => {
|
|
54
|
+
if (!hasSession(sessionId)) return;
|
|
55
|
+
try {
|
|
56
|
+
rmSync(recordPath(sessionId, env), { force: true });
|
|
57
|
+
} catch {
|
|
58
|
+
// A record that cannot be removed only makes the next lit repeat itself.
|
|
59
|
+
}
|
|
60
|
+
};
|
|
@@ -101,7 +101,7 @@ export function lockup(productName, rows = standard) {
|
|
|
101
101
|
if (typeof productName !== "string" || !/^[a-z][a-z0-9 .-]*$/u.test(productName)) {
|
|
102
102
|
throw new TypeError("productName must be a plain product label");
|
|
103
103
|
}
|
|
104
|
-
const labels = [productName, "──────────────", "hermes · codex", "opencode · grok"];
|
|
104
|
+
const labels = [productName, "──────────────", "hermes · codex", "opencode · grok", "muse · gravity"];
|
|
105
105
|
const offset = Math.floor(rows.length / 2);
|
|
106
106
|
const column = Math.max(...rows.map((row) => row.length)) + 6;
|
|
107
107
|
return rows.map((row, index) => row.padEnd(column) + (labels[index - offset] ? ` ${labels[index - offset]}` : ""));
|
|
@@ -238,6 +238,23 @@ const topEdge = (model, sample, { width, glyphs, accent, edge }) => {
|
|
|
238
238
|
const barSpans = (fraction, sample, cells) => barCells(fraction, cells, sample.fillGlow ?? 0)
|
|
239
239
|
.map(({ glyph, color }) => (glyph === "█" ? span(" ", { bg: color }) : span(glyph, { fg: color })));
|
|
240
240
|
|
|
241
|
+
// ●● 2 lanes 1:07: a dot per running lane (amber once stalled), the count and the longest lane's
|
|
242
|
+
// clock. While LitClaude works a light walks across the dots (full motion) or they breathe (subtle),
|
|
243
|
+
// so running lanes move while the main turn waits; a dot changes only by colour, which repaints.
|
|
244
|
+
const laneSegment = (model, sample, glyphs) => {
|
|
245
|
+
const list = model.lanes.list.slice(0, 4);
|
|
246
|
+
const ambient = model.idle ? null : sample.ambient;
|
|
247
|
+
const dots = list.map((lane, index) => {
|
|
248
|
+
const base = lane.status === "stalled" ? PALETTE.amber : PALETTE.green;
|
|
249
|
+
let light = 0;
|
|
250
|
+
if (ambient?.flow !== null && ambient?.flow !== undefined) light = 0.8 * Math.max(0, 1 - Math.abs(ambient.flow * (list.length + 1) - 0.5 - index));
|
|
251
|
+
else if (ambient) light = 0.5 * ambient.breath;
|
|
252
|
+
return span(glyphs.lane, { fg: lerpColor(base, "#ffffff", light) });
|
|
253
|
+
});
|
|
254
|
+
const clock = sample.lanes ? ` ${formatClock(sample.lanes.elapsedMs)}` : "";
|
|
255
|
+
return segment("lanes", 3, [...dots, span(` ${model.lanes.count} ${model.lanes.count === 1 ? "lane" : "lanes"}${clock}`, { fg: PALETTE.dim })]);
|
|
256
|
+
};
|
|
257
|
+
|
|
241
258
|
// The right half of the phase row: a context warning, the lanes, the autoloop budget and the
|
|
242
259
|
// progress of the plan or goal, dropped in that priority order when the row is narrow.
|
|
243
260
|
const progressSegment = (model, sample, glyphs, cells) => {
|
|
@@ -294,8 +311,7 @@ const phaseRow = (model, sample, { inner, glyphs, accent }) => {
|
|
|
294
311
|
: null;
|
|
295
312
|
right.push(segment("ctx", 1, warning));
|
|
296
313
|
if (model.lanes.count > 0) {
|
|
297
|
-
|
|
298
|
-
right.push(segment("lanes", 3, [...dots, span(` ${model.lanes.count} ${model.lanes.count === 1 ? "lane" : "lanes"}`, { fg: PALETTE.dim })]));
|
|
314
|
+
right.push(laneSegment(model, sample, glyphs));
|
|
299
315
|
}
|
|
300
316
|
if (model.autoloop) {
|
|
301
317
|
right.push(segment("loop", 4, [span(`${glyphs.loop} ${model.autoloop.n}/${model.autoloop.max}`, { fg: PALETTE.violet }), span(` · ${formatDuration(model.autoloop.leftMs)}`, { fg: PALETTE.dim })]));
|
|
@@ -389,8 +405,7 @@ const mapRow = (model, sample, { inner, glyphs, accent }) => {
|
|
|
389
405
|
right.push(segment("ctx", 1, [span(`ctx ${model.ctxWarning.percent}% → ${model.ctxWarning.threshold}%`, { fg: lerpColor(PALETTE.dim, PALETTE.amber, sample.warn), bold: sample.warn > 0.5 })]));
|
|
390
406
|
}
|
|
391
407
|
if (model.lanes.count > 0) {
|
|
392
|
-
|
|
393
|
-
right.push(segment("lanes", 3, [...dots, span(` ${model.lanes.count} ${model.lanes.count === 1 ? "lane" : "lanes"}`, { fg: PALETTE.dim })]));
|
|
408
|
+
right.push(laneSegment(model, sample, glyphs));
|
|
394
409
|
}
|
|
395
410
|
if (model.autoloop) {
|
|
396
411
|
right.push(segment("loop", 4, [span(`${glyphs.loop} ${model.autoloop.n}/${model.autoloop.max}`, { fg: PALETTE.violet }), span(` · ${formatDuration(model.autoloop.leftMs)}`, { fg: PALETTE.dim })]));
|
|
@@ -590,12 +605,14 @@ const bottomEdge = (model, sample, { width, glyphs, accent, edge }) => {
|
|
|
590
605
|
return edgeRow("╰─ ", joinSegments(kept, edge), [], "─╯", width, edge, cometOn(sample, "bottom", width));
|
|
591
606
|
};
|
|
592
607
|
|
|
593
|
-
// The border: red or amber under a warning, otherwise the accent
|
|
594
|
-
//
|
|
608
|
+
// The border: red or amber under a warning, otherwise the accent. Idle it is a calm, dim accent;
|
|
609
|
+
// while LitClaude works it sits a step above the accent and breathes brighter toward white with the
|
|
610
|
+
// brand pill.
|
|
595
611
|
const edgeColor = (model, sample, accent) => {
|
|
596
612
|
if (model.warnings.some(({ tone }) => tone === "red")) return PALETTE.red;
|
|
597
613
|
if (model.warnings.length) return PALETTE.amber;
|
|
598
|
-
return lerpColor(PALETTE.faint, accent,
|
|
614
|
+
if (model.idle) return lerpColor(PALETTE.faint, accent, 0.35);
|
|
615
|
+
return lerpColor(accent, "#ffffff", 0.15 + 0.3 * (sample.ambient?.breath ?? 0));
|
|
599
616
|
};
|
|
600
617
|
|
|
601
618
|
/**
|
|
@@ -33,12 +33,13 @@ export const TIMINGS = Object.freeze({
|
|
|
33
33
|
flow: 1400,
|
|
34
34
|
spin: 120,
|
|
35
35
|
ambientFrame: 66,
|
|
36
|
+
clock: 1000,
|
|
36
37
|
});
|
|
37
38
|
|
|
38
39
|
// full: the approved motion, and while LitClaude works the brand breathes, a light sweeps the active
|
|
39
40
|
// phase and a comet runs around the card's rules. subtle: no overshoot, no shimmer or embers, three
|
|
40
41
|
// quarters the time, and only the breathing while working. off: every duration is zero, so the band
|
|
41
|
-
// draws its final frame and
|
|
42
|
+
// draws its final frame and starts no frame timer; a clock on the card still ticks each second.
|
|
42
43
|
export const motionProfile = (mode) => {
|
|
43
44
|
if (mode === "off") {
|
|
44
45
|
return { mode, duration: () => 0, enterEase: EASE.linear, noticeEase: EASE.linear, shimmer: false, embers: false, ambient: null };
|
|
@@ -400,8 +400,8 @@ export const composeSvgCard = (model, { motion = "full", accent = "#5fd7ff" } =
|
|
|
400
400
|
const defs = animate.sweep
|
|
401
401
|
? `<defs><linearGradient id="lit-sweep" x1="0" x2="1" y1="0" y2="0"><stop offset="0" stop-color="#fff" stop-opacity="0"/><stop offset="0.5" stop-color="#fff" stop-opacity="0.55"/><stop offset="1" stop-color="#fff" stop-opacity="0"/><animateTransform attributeName="gradientTransform" type="translate" values="-1.2 0;1.2 0" ${loop(TIMINGS.sweep, 0.5)}/></linearGradient></defs>`
|
|
402
402
|
: "";
|
|
403
|
-
const frame = `<rect x="1" y="1" width="${width - 2}" height="${height - 2}" rx="14" fill="${C.bg}" stroke="${edge}" stroke-width="1.5"${model.idle ? ' stroke-opacity="0.8"' : ""}>`
|
|
404
|
-
+ (animate.breath && !model.warnings.length ? `<animate attributeName="stroke-opacity" values="0.
|
|
403
|
+
const frame = `<rect x="1" y="1" width="${width - 2}" height="${height - 2}" rx="14" fill="${C.bg}" stroke="${edge}" stroke-width="${model.idle ? "1.5" : "2.5"}"${model.idle ? ' stroke-opacity="0.8"' : ""}>`
|
|
404
|
+
+ (animate.breath && !model.warnings.length ? `<animate attributeName="stroke-opacity" values="0.85;1;0.85" ${loop(TIMINGS.breath, BREATH_PHASE)}/>` : "")
|
|
405
405
|
+ "</rect>";
|
|
406
406
|
const comet = animate.comet
|
|
407
407
|
? `<rect x="1" y="1" width="${width - 2}" height="${height - 2}" rx="14" fill="none" stroke="url(#lit-comet)" stroke-width="2.5" stroke-linecap="round" pathLength="${perimeter}" stroke-dasharray="70 ${perimeter - 70}"><animate attributeName="stroke-dashoffset" values="0;-${perimeter}" ${loop(TIMINGS.comet * 2, 0.5)}/></rect>`
|
|
@@ -17,6 +17,12 @@ const fractionOf = (model) => {
|
|
|
17
17
|
// surface counts on between models.
|
|
18
18
|
const stepOf = (model, now) => (model.step ? { name: model.step.name, base: model.step.elapsedMs, at: now } : null);
|
|
19
19
|
|
|
20
|
+
// The lanes' clock, kept the same way: the longest-running lane's time as the model carried it.
|
|
21
|
+
const lanesOf = (model, now) => {
|
|
22
|
+
const times = (model.lanes?.list ?? []).map(({ elapsedMs }) => elapsedMs).filter(Number.isFinite);
|
|
23
|
+
return times.length ? { base: Math.max(...times), at: now } : null;
|
|
24
|
+
};
|
|
25
|
+
|
|
20
26
|
const entryEnd = (profile) => 3 * profile.duration(TIMINGS.stagger) + profile.duration(TIMINGS.entry);
|
|
21
27
|
|
|
22
28
|
// One entry per chip: `at` is the firing the model reported, `arrivedAt` when this timeline saw
|
|
@@ -48,6 +54,7 @@ export const createTimeline = (model, now, profile) => {
|
|
|
48
54
|
done: countOf(model)?.done ?? null,
|
|
49
55
|
flashAt: null,
|
|
50
56
|
step: stepOf(model, now),
|
|
57
|
+
lanes: lanesOf(model, now),
|
|
51
58
|
warn: still(model.ctxWarning ? 1 : 0),
|
|
52
59
|
phases: Object.fromEntries(PHASES.map((id) => [id, { from: model.phases[id], to: model.phases[id], at: now }])),
|
|
53
60
|
notice: model.notice ? { data: model.notice, at: restAt } : null,
|
|
@@ -83,9 +90,13 @@ export const advanceTimeline = (timeline, model, now, profile) => {
|
|
|
83
90
|
next.chips = chipsOf(model, now, timeline.chips);
|
|
84
91
|
next.ambient = ambientOf(model, now, profile, timeline.ambient);
|
|
85
92
|
next.step = stepOf(model, now);
|
|
93
|
+
next.lanes = lanesOf(model, now);
|
|
86
94
|
return next;
|
|
87
95
|
};
|
|
88
96
|
|
|
97
|
+
/** True while the card shows a running clock (the live step or the lanes'); it ticks each second. */
|
|
98
|
+
export const clockShown = (timeline) => timeline.exitAt === null && Boolean(timeline.step || timeline.lanes);
|
|
99
|
+
|
|
89
100
|
/** True while the ambient loop runs; the surface module then keeps a slower frame timer going. */
|
|
90
101
|
export const ambientActive = (timeline, profile) => Boolean(profile.ambient) && timeline.exitAt === null && timeline.ambient.on;
|
|
91
102
|
|
|
@@ -184,6 +195,7 @@ export const sampleTimeline = (timeline, now, profile) => {
|
|
|
184
195
|
chips,
|
|
185
196
|
ambient: ambientSample(timeline, now, profile),
|
|
186
197
|
step: timeline.step ? { name: timeline.step.name, elapsedMs: timeline.step.base + Math.max(0, now - timeline.step.at) } : null,
|
|
198
|
+
lanes: timeline.lanes ? { elapsedMs: timeline.lanes.base + Math.max(0, now - timeline.lanes.at) } : null,
|
|
187
199
|
spin: Math.floor(Math.max(0, now) / TIMINGS.spin) % 4,
|
|
188
200
|
};
|
|
189
201
|
};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// The toasts the mod raises when the LIT state really changes: a discipline starts or switches, the
|
|
2
|
+
// workflow stage moves, a goal is set or met, a lane starts or finishes. Pure: the mod keeps the last
|
|
3
|
+
// status it saw and a gate, and hands each new status in; what comes back is at most one short line
|
|
4
|
+
// to show, never more than one per TOAST_GAP_MS. Gate notices (state.mjs gates, the auto-handoff)
|
|
5
|
+
// pass through the same gate as `{ kind: "notice", text }`.
|
|
6
|
+
|
|
7
|
+
import { DISCIPLINE_ENTRY } from "./workflow.mjs";
|
|
8
|
+
|
|
9
|
+
export const TOAST_GAP_MS = 3000;
|
|
10
|
+
// A burst longer than this many lines ends in `+N more`.
|
|
11
|
+
const SHOWN = 3;
|
|
12
|
+
|
|
13
|
+
const cut = (text, cells) => (text.length > cells ? `${text.slice(0, cells - 1)}…` : text);
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* What a toast compares: the discipline (sticky: a prompt or skill that names none keeps the last),
|
|
17
|
+
* the current stage, the goal and the running lanes by id. `discipline` is the one the session last
|
|
18
|
+
* lit, `model` the band model, `snapshot` the state snapshot.
|
|
19
|
+
*/
|
|
20
|
+
export const statusOf = ({ discipline, model, snapshot }, previous = null) => {
|
|
21
|
+
const flow = model?.workflow;
|
|
22
|
+
const stage = flow && flow.current >= 0 ? flow.stages[flow.current]?.id ?? null : null;
|
|
23
|
+
const goal = snapshot?.goal;
|
|
24
|
+
return {
|
|
25
|
+
discipline: DISCIPLINE_ENTRY[discipline] ? discipline : previous?.discipline ?? null,
|
|
26
|
+
stage: stage && `${flow.family}:${stage}`,
|
|
27
|
+
goal: goal ? { key: goal.createdAt ?? goal.objective, objective: String(goal.objective ?? ""), status: goal.status, passed: goal.criteria.filter(({ status }) => status === "pass").length, total: goal.criteria.length } : null,
|
|
28
|
+
lanes: Object.fromEntries((model?.lanes?.list ?? []).filter(({ id }) => id).map(({ id, name }) => [id, name])),
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const laneEntries = (ids, names, verb) => {
|
|
33
|
+
if (ids.length === 0) return [];
|
|
34
|
+
return [{ kind: `lane-${verb}`, text: ids.length === 1 ? `lane ${verb === "start" ? "started" : "finished"} · ${names[ids[0]]}` : `${ids.length} lanes ${verb === "start" ? "started" : "finished"}` }];
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/** The changes from one status to the next, as toast entries; none for the first status seen. */
|
|
38
|
+
export const statusChanges = (previous, next) => {
|
|
39
|
+
if (!previous) return [];
|
|
40
|
+
const entries = [];
|
|
41
|
+
if (next.discipline && next.discipline !== previous.discipline) entries.push({ kind: "discipline", from: previous.discipline, to: next.discipline });
|
|
42
|
+
else if (next.stage && next.stage !== previous.stage) entries.push({ kind: "stage", text: `stage · ${next.stage.split(":")[1]}` });
|
|
43
|
+
const goal = next.goal;
|
|
44
|
+
const sameGoal = goal && previous.goal?.key === goal.key;
|
|
45
|
+
if (goal && !sameGoal && goal.status !== "complete") entries.push({ kind: "goal", text: `goal set · ${cut(goal.objective, 40)}` });
|
|
46
|
+
if (goal?.status === "complete" && !(sameGoal && previous.goal.status === "complete")) entries.push({ kind: "goal", text: `goal met · ${goal.passed}/${goal.total}` });
|
|
47
|
+
const started = Object.keys(next.lanes).filter((id) => !(id in previous.lanes));
|
|
48
|
+
const finished = Object.keys(previous.lanes).filter((id) => !(id in next.lanes));
|
|
49
|
+
entries.push(...laneEntries(started, next.lanes, "start"), ...laneEntries(finished, previous.lanes, "finish"));
|
|
50
|
+
return entries;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* One line for the entries that waited: a chain of switches shows its two ends (and nothing when it
|
|
55
|
+
* came back where it started), a stage only its newest, repeats once, past SHOWN lines `+N more`.
|
|
56
|
+
* Null when nothing is left to say.
|
|
57
|
+
*/
|
|
58
|
+
export const mergeToasts = (entries) => {
|
|
59
|
+
let switched = null;
|
|
60
|
+
let stage = null;
|
|
61
|
+
const lines = [];
|
|
62
|
+
for (const entry of entries) {
|
|
63
|
+
if (entry.kind === "discipline") {
|
|
64
|
+
switched = switched ? { ...switched, to: entry.to } : { from: entry.from, to: entry.to, at: lines.length };
|
|
65
|
+
} else if (entry.kind === "stage") {
|
|
66
|
+
stage = { text: entry.text, at: lines.length };
|
|
67
|
+
} else if (!lines.includes(entry.text)) {
|
|
68
|
+
lines.push(entry.text);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (stage) lines.splice(stage.at, 0, stage.text);
|
|
72
|
+
if (switched && switched.from !== switched.to) lines.splice(switched.at, 0, switched.from ? `${switched.from} → ${switched.to}` : `${switched.to} started`);
|
|
73
|
+
if (lines.length === 0) return null;
|
|
74
|
+
const shown = lines.length > SHOWN ? [...lines.slice(0, SHOWN), `+${lines.length - SHOWN} more`] : lines;
|
|
75
|
+
return `🔥 ${shown.join(" · ")}`;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* The rate gate: `{ lastAt, pending }`. Entries join what is pending; once TOAST_GAP_MS has passed
|
|
80
|
+
* since the last toast, all of it shows as one line. Otherwise `waitMs` says how long until it may.
|
|
81
|
+
*/
|
|
82
|
+
export const gateToast = (gate, entries, now) => {
|
|
83
|
+
const pending = [...gate.pending, ...entries];
|
|
84
|
+
if (pending.length === 0) return { gate, show: null, waitMs: null };
|
|
85
|
+
const waitMs = gate.lastAt + TOAST_GAP_MS - now;
|
|
86
|
+
if (waitMs > 0) return { gate: { ...gate, pending }, show: null, waitMs };
|
|
87
|
+
const show = mergeToasts(pending);
|
|
88
|
+
return { gate: { lastAt: show ? now : gate.lastAt, pending: [] }, show, waitMs: null };
|
|
89
|
+
};
|