@litfamily/litmuse 0.1.16 → 0.1.18

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 CHANGED
@@ -1,5 +1,18 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.18 — 2026-11-24
4
+
5
+ - `litmuse install`, `update`, `doctor` and `--help` now print the synthwave LIT mark above their output, and `litmuse status --card` in a truecolor terminal shows a gradient version pill on the stage card. Output to a pipe gets a plain one-line mark instead, and `doctor --json` and `status --card --json` get none.
6
+ - A request that ends with `lit` (`로그인 버튼 고쳐줘 lit`, `… 부탁해 lit`) now gets the lit-loop goal question, with the words before `lit` as the objective. A closing `lit-loop` or `litwork` runs that route the same way it does at the start. `lit`, `lit continue` and `lit resume` alone still ask nothing.
7
+ - A lit-team state lock left by a crashed process no longer blocks the team forever: a lock with no readable owner record, a takeover claim a crashed contender left behind, and a lock held for more than ten minutes (even when its pid now belongs to another process) are reclaimed. A timeout now names the lock path and its holder.
8
+ - The hook code changed, so Muse asks you to approve the LitMuse hooks again after the update.
9
+
10
+ ## 0.1.17 — 2026-11-22
11
+
12
+ - Both READMEs now open with a plain one-line pitch, a short before-and-after story and a "Two ways to use it" section: the easy way is your usual request with `lit` at the start or the end; the full workflow is a six-step table (explore, clarify, plan, build, review, hand off) with the line to type for each step, followed by the one install line.
13
+ - Every goal question now comes with an answer guide under it, so a first-time user sees what to type and what each answer does. The question line itself and the accepted answers are unchanged. `goal-propose.mjs` prints the guide after a blank line, and the prompt hook passes it with the lit-loop question; it is a short Markdown block: a title, the goal, one row per answer (`yes` / `edit` / `no` for a plan with a goal, `yes` / `no` for start only and for a lit-loop) and `Type the word alone.` The model words it in your language and keeps the answer words in English. Muse shows no hook text, so the guide, like the question, depends on the model repeating it.
14
+ - The hook code changed, so Muse asks you to approve the LitMuse hooks again after the update.
15
+
3
16
  ## 0.1.16 — 2026-11-21
4
17
 
5
18
  - A lit-loop or litwork run with no plan can now get a Muse goal too, asked once. When the project has a test command (`npm test`, `pytest`, `cargo test` or `go test ./...`) and the prompt names an objective, the prompt hook records one question at the run's first activation and tells the model to end its first reply with `Set goal for this lit-loop: /goal <check> exits 0 and this is done: <objective>? (yes / no)`. Muse shows no hook text, so that is the model's job and cannot be forced. An exact `yes` arms the goal, and the model sets it with `create_goal` the way a plan's goal is set, but starts no start-work; `no`, `edit` or any other prompt drops the question. With no test command the model asks after its failing check through `goal-propose.mjs --loop --check "<check>" <objective>`, which runs the check once and prints `No goal set: <reason>` when it already passes, cannot run or is not an allowlisted test command. A repeat of `lit`, `lit goal`, a plan, and a session that already holds an open goal or a pending question ask nothing.
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  <h1 align="center">LitMuse</h1>
4
4
  <p align="center"><strong>Keep the work lit.</strong></p>
5
5
 
6
- <p align="center">LitMuse gives Meta's Muse Code the habit of planning before it edits, checking what it built, and leaving a handoff, so the next session starts where this one stopped. One npm command installs it as a Muse plugin.</p>
6
+ <p align="center">LitMuse is an add-on for Muse Code. It makes Muse check its own work before it says "done", and leaves a note so the next session starts where this one stopped.</p>
7
7
 
8
8
  <p align="center">
9
9
  <a href="https://www.npmjs.com/package/@litfamily/litmuse"><img src="https://img.shields.io/npm/v/@litfamily/litmuse?color=FF6337&amp;label=npm" alt="npm version" /></a>
@@ -11,11 +11,44 @@
11
11
  <a href="https://github.com/wjgoarxiv/litmuse/stargazers"><img src="https://img.shields.io/github/stars/wjgoarxiv/litmuse?style=flat" alt="GitHub stars" /></a>
12
12
  </p>
13
13
 
14
+ You ask Muse for a feature. It writes the code and says it is finished, and a day later you find the tests
15
+ never ran. You open a new session and explain the whole project again.
16
+
17
+ With LitMuse you add `lit` to the same request. Muse first writes down what "finished" means for this task,
18
+ adds a test that fails, makes it pass, and ends by telling you what it checked and what it could not. When you
19
+ stop, type `lit handoff`. Muse saves a note, and in the next session `lit adhd` reads it and tells you where to
20
+ pick up.
21
+
14
22
  <p align="center"><a href="#inside-one-lit-turn">How it works</a> &nbsp; <a href="#in-the-muse-app-too">Muse app</a> &nbsp; <a href="#install">Install</a> &nbsp; <a href="#quick-start">Quick start</a> &nbsp; <a href="#the-status-card">Status card</a> &nbsp; <a href="#automatic-handoff">Handoff</a> &nbsp; <a href="#safety">Safety</a> &nbsp; <a href="./README_ko-KR.md">한국어</a></p>
15
23
 
16
- > [!TIP]
17
- > One `npx` line installs LitMuse as a Muse plugin; then open Muse and start a prompt with `lit`, for example
18
- > `lit plan a tiny todo app`. [Quick start](#quick-start) has the lines.
24
+ ## Two ways to use it
25
+
26
+ **The easy way.** Write your request as usual and put `lit` at the start or at the end:
27
+
28
+ ```text
29
+ fix the date parsing bug in src/dates.js lit
30
+ ```
31
+
32
+ Muse sets the goal, writes a failing test, fixes the bug, checks the result and tells you what it checked.
33
+ Most tasks need nothing more.
34
+
35
+ **The full workflow.** For a bigger job, go one step at a time. Each step leaves a file the next step reads,
36
+ and you can skip any step you do not need.
37
+
38
+ | Step | Type | What happens |
39
+ | --- | --- | --- |
40
+ | 1. Explore | `lit brainstorm <question>` | Many options, scored, cut to a short list |
41
+ | 2. Clarify | `lit interview <idea>` | Muse asks questions until the goal is clear |
42
+ | 3. Plan | `lit crucible <approach>` or `lit plan <task>` | Crucible attacks the approach first, then plans; lit-plan writes `plans/<slug>.md` and asks for your yes |
43
+ | 4. Build | `yes` to the plan, or `/start-work` | Muse works through the plan row by row with tests; with no plan, `lit <task>` runs lit-loop |
44
+ | 5. Review | `lit review` | A review in five lanes, findings first |
45
+ | 6. Hand off | `lit handoff` | What was built, how it was checked and what is left, saved to a file |
46
+
47
+ Install with one line, then open Muse in your project ([Quick start](#quick-start) has the full first run):
48
+
49
+ ```bash
50
+ npx @litfamily/litmuse install
51
+ ```
19
52
 
20
53
  ## Pick your path
21
54
 
package/README_ko-KR.md CHANGED
@@ -3,7 +3,7 @@
3
3
  <h1 align="center">LitMuse</h1>
4
4
  <p align="center"><strong>Keep the work lit.</strong></p>
5
5
 
6
- <p align="center">LitMuse는 Meta의 Muse Code에 일하는 습관을 붙여 줍니다. 고치기 전에 계획하고, 만든 것을 확인하고, 끝낼 때 인계 메모를 남깁니다. 그래서 다음 세션이 이번 세션이 멈춘 자리에서 바로 이어집니다. npm 명령 하나로 Muse 플러그인으로 설치됩니다.</p>
6
+ <p align="center">LitMuse는 Muse Code에 붙이는 추가 기능입니다. Muse가 "다 됐어요"라고 말하기 전에 자기 작업을 직접 확인하게 하고, 다음 세션이 이번에 멈춘 자리에서 시작하도록 기록을 남기게 합니다.</p>
7
7
 
8
8
  <p align="center">
9
9
  <a href="https://www.npmjs.com/package/@litfamily/litmuse"><img src="https://img.shields.io/npm/v/@litfamily/litmuse?color=FF6337&amp;label=npm" alt="npm version" /></a>
@@ -11,11 +11,38 @@
11
11
  <a href="https://github.com/wjgoarxiv/litmuse/stargazers"><img src="https://img.shields.io/github/stars/wjgoarxiv/litmuse?style=flat" alt="GitHub stars" /></a>
12
12
  </p>
13
13
 
14
+ Muse에게 기능을 하나 부탁하면 코드를 쓰고 끝났다고 합니다. 그런데 다음 날 보니 테스트는 한 번도 돌지 않았습니다. 새 세션을 열면 프로젝트 설명을 처음부터 다시 해야 합니다.
15
+
16
+ LitMuse를 쓰면 같은 요청에 `lit`만 붙이면 됩니다. Muse는 먼저 이 작업에서 "끝났다"가 무슨 뜻인지 적어 두고, 실패하는 테스트를 추가해 통과시킨 뒤, 무엇을 확인했고 무엇은 확인하지 못했는지 알려 줍니다. 작업을 멈출 때 `lit handoff`라고 치면 Muse가 기록을 남깁니다. 다음 세션에서 `lit adhd`를 치면 그 기록을 읽고 어디서 이어 가면 되는지 알려 줍니다.
17
+
14
18
  <p align="center"><a href="#lit-한-턴의-안쪽">동작 방식</a> &nbsp; <a href="#muse-앱에서도">Muse 앱</a> &nbsp; <a href="#설치">설치</a> &nbsp; <a href="#빠른-시작">빠른 시작</a> &nbsp; <a href="#상태-카드">상태 카드</a> &nbsp; <a href="#자동-핸드오프">핸드오프</a> &nbsp; <a href="#안전">안전</a> &nbsp; <a href="./README.md">English</a></p>
15
19
 
16
- > [!TIP]
17
- > `npx` 한 줄로 LitMuse를 Muse 플러그인으로 설치합니다. 그다음 Muse를 열고 프롬프트를 `lit`으로 시작하세요.
18
- > 예를 들면 `lit plan a tiny todo app`입니다. 실행할 줄은 [빠른 시작](#빠른-시작)에 있습니다.
20
+ ## 두 가지 사용법
21
+
22
+ **간단하게.** 평소처럼 요청을 쓰고, 앞이나 끝에 `lit`을 붙입니다.
23
+
24
+ ```text
25
+ src/dates.js의 날짜 파싱 버그 고쳐줘 lit
26
+ ```
27
+
28
+ Muse가 목표를 정하고, 실패하는 테스트를 쓰고, 버그를 고치고, 결과를 확인한 뒤 무엇을 확인했는지 알려 줍니다. 웬만한 작업은 이것으로 충분합니다.
29
+
30
+ **본격적으로.** 큰 작업은 한 단계씩 밟아 갑니다. 단계마다 남긴 파일을 다음 단계가 읽고, 필요 없는 단계는 건너뛰어도 됩니다.
31
+
32
+ | 단계 | 입력 | 하는 일 |
33
+ | --- | --- | --- |
34
+ | 1. 넓게 보기 | `lit brainstorm <질문>` | 선택지를 많이 낸 뒤 점수를 매겨 몇 개로 추립니다 |
35
+ | 2. 구체화 | `lit interview <아이디어>` | 목표가 분명해질 때까지 Muse가 질문합니다 |
36
+ | 3. 계획 | `lit crucible <접근법>` 또는 `lit plan <작업>` | crucible은 접근법의 약점부터 파고든 뒤 계획으로 넘기고, lit-plan은 `plans/<slug>.md`에 단계를 적고 승인을 묻습니다 |
37
+ | 4. 실행 | 계획에 `yes`, 또는 `/start-work` | 계획을 한 줄씩 테스트와 함께 진행합니다. 계획 없이 바로 하려면 `lit <작업>`이 lit-loop를 돌립니다 |
38
+ | 5. 검토 | `lit review` | 다섯 갈래로 검토하고 발견한 문제부터 알려 줍니다 |
39
+ | 6. 넘겨주기 | `lit handoff` | 만든 것, 확인한 방법, 남은 일을 파일로 남깁니다 |
40
+
41
+ 설치는 한 줄입니다. 그다음 프로젝트에서 Muse를 여세요(처음 써 보는 전체 과정은 [빠른 시작](#빠른-시작)에 있습니다).
42
+
43
+ ```bash
44
+ npx @litfamily/litmuse install
45
+ ```
19
46
 
20
47
  ## 길 고르기
21
48
 
package/bin/litmuse.mjs CHANGED
@@ -15,6 +15,7 @@ import { buildCard, renderCard } from '../lib/stage-card.mjs';
15
15
  import { styleCommand } from '../lib/style.mjs';
16
16
  import { runRewindCli } from '../plugin/lib/rewind/collect.mjs';
17
17
  import { extensionsCommand } from '../lib/extensions.mjs';
18
+ import { colourDepth, litPill, markFor, pillWidth, termColumns } from '../lib/mark.mjs';
18
19
 
19
20
  const HELP = `LitMuse ${packageVersion()}: LitFamily workflows for Meta's Muse Code
20
21
 
@@ -93,6 +94,7 @@ async function main() {
93
94
  }
94
95
  if (command === 'extensions') return extensionsCommand({ args, flags, env, print });
95
96
  if (flags.help || command === 'help') {
97
+ print(markFor({ env }));
96
98
  print(HELP);
97
99
  return 0;
98
100
  }
@@ -103,10 +105,12 @@ async function main() {
103
105
  switch (command) {
104
106
  case 'install':
105
107
  case 'update':
108
+ print(markFor({ env }));
106
109
  return install({ env, flags, interactive, ask, print });
107
110
  case 'uninstall':
108
111
  return uninstall({ env, flags, interactive, print });
109
112
  case 'doctor':
113
+ if (!flags.json) print(markFor({ env }));
110
114
  return doctor({ env, flags, print });
111
115
  case 'models':
112
116
  return models({ env, flags, print });
@@ -122,7 +126,17 @@ async function main() {
122
126
  case 'status': {
123
127
  if (flags.card) {
124
128
  const card = buildCard({ cwd: process.cwd(), env });
125
- print(flags.json ? JSON.stringify(card, null, 2) : renderCard(card));
129
+ if (flags.json) {
130
+ print(JSON.stringify(card, null, 2));
131
+ return 0;
132
+ }
133
+ // /lit-status has the model run this through bash and repeat it, so the mark and pill
134
+ // appear only when a person's terminal is attached.
135
+ const tty = process.stdout.isTTY === true;
136
+ const depth = colourDepth({ env, isTTY: tty });
137
+ const v = packageVersion();
138
+ if (tty) print(markFor({ env }));
139
+ print(renderCard(card, { badge: tty && depth === 'truecolor' ? { text: litPill(v, depth), width: pillWidth(v) } : null, cols: termColumns({ env }) }));
126
140
  return 0;
127
141
  }
128
142
  const st = stageState(paths(env));
package/lib/mark.mjs ADDED
@@ -0,0 +1,130 @@
1
+ // The synthwave LIT mark and the LIT pill, for the person at the terminal only: install, doctor and a
2
+ // TTY `status --card`; piped, install and doctor get the one plain line. Hooks, context files and command text never call it: what they print is
3
+ // model-visible.
4
+ import { MONO_ROWS, PIXEL_ROWS, SHARED_COLOURS } from './synthwave-data.mjs';
5
+
6
+ export const HOST = 'muse code';
7
+ // LitMuse chrome: peach at the top of each letter, plum at the base.
8
+ export const CHROME = Object.freeze(['#fff1e6', '#ffc29e', '#ff7a59', '#ffffff', '#ffd6e7', '#3b0a2a']);
9
+ const TAGLINE = Object.freeze(['#8be9fd', '#ff2d95', '#ffd23f']);
10
+ const EDGE = '#ffffff';
11
+ const PILL_INK = '#0b0e14';
12
+ export const SIZES = Object.freeze([['B-L', 76], ['B-M', 44], ['B-S', 24]]);
13
+ export const FALLBACK = `LIT · ${HOST}`;
14
+
15
+ const ESC = '\u001b';
16
+ const rgb = (hex) => [1, 3, 5].map((i) => Number.parseInt(hex.slice(i, i + 2), 16));
17
+
18
+ // Piecewise-linear sample of a stop list at t in [0, 1].
19
+ export function sample(stops, t) {
20
+ const span = stops.length - 1;
21
+ const i = Math.min(span - 1, Math.floor(t * span));
22
+ const f = t * span - i;
23
+ const a = rgb(stops[i]);
24
+ const b = rgb(stops[i + 1]);
25
+ return `#${a.map((v, k) => Math.round(v + (b[k] - v) * f).toString(16).padStart(2, '0')).join('')}`;
26
+ }
27
+
28
+ const pixel = (sym) => {
29
+ if (sym === ' ') return null;
30
+ if (sym >= 'a' && sym <= 'l') return sample(CHROME, (sym.charCodeAt(0) - 97) / 11);
31
+ if (sym === 'm') return EDGE;
32
+ return SHARED_COLOURS[sym] ?? null;
33
+ };
34
+
35
+ const cube = (hex) => {
36
+ const [r, g, b] = rgb(hex).map((v) => Math.round((v / 255) * 5));
37
+ return 16 + 36 * r + 6 * g + b;
38
+ };
39
+ const sgr = (hex, layer, depth) => (depth === 'truecolor'
40
+ ? `${layer === 'fg' ? 38 : 48};2;${rgb(hex).join(';')}`
41
+ : `${layer === 'fg' ? 38 : 48};5;${cube(hex)}`);
42
+
43
+ // truecolor, 256 or none. NO_COLOR, a pipe or a dumb terminal mean none; a plain 8/16-colour
44
+ // terminal also gets none, since the mark needs at least the 256-colour cube.
45
+ export function colourDepth({ env = process.env, isTTY = process.stdout.isTTY } = {}) {
46
+ if (env.NO_COLOR || !isTTY || env.TERM === 'dumb') return 'none';
47
+ if (/^(truecolor|24bit)$/i.test(env.COLORTERM ?? '')) return 'truecolor';
48
+ if (/256/.test(env.TERM ?? '')) return '256';
49
+ return 'none';
50
+ }
51
+
52
+ // Terminal width in cells; unknown counts as 80.
53
+ export function termColumns({ env = process.env, stream = process.stdout } = {}) {
54
+ const cols = Number(stream?.columns) || Number.parseInt(env.COLUMNS ?? '', 10);
55
+ return Number.isFinite(cols) && cols > 0 ? cols : 80;
56
+ }
57
+
58
+ export function markSize(cols) {
59
+ const width = Number.isFinite(cols) && cols > 0 ? cols : 80;
60
+ return SIZES.find(([, min]) => width >= min)?.[0] ?? null;
61
+ }
62
+
63
+ // One coloured row: cells are [glyph, fg, bg]; an SGR is written only when the colours change.
64
+ const paintRow = (cells, depth) => {
65
+ let out = '';
66
+ let last = '';
67
+ for (const [glyph, fg, bg] of cells) {
68
+ const codes = [fg && sgr(fg, 'fg', depth), bg && sgr(bg, 'bg', depth)].filter(Boolean).join(';');
69
+ if (codes !== last) {
70
+ out += `${ESC}[0m${codes ? `${ESC}[${codes}m` : ''}`;
71
+ last = codes;
72
+ }
73
+ out += glyph;
74
+ }
75
+ return last ? `${out}${ESC}[0m` : out;
76
+ };
77
+
78
+ const artRows = (size, depth) => {
79
+ const rows = PIXEL_ROWS[size];
80
+ const out = [];
81
+ for (let y = 0; y < rows.length; y += 2) {
82
+ const cells = [...rows[y]].map((sym, x) => {
83
+ const top = pixel(sym);
84
+ const bottom = pixel(rows[y + 1][x]);
85
+ if (top === bottom) return [' ', null, top];
86
+ if (top === null) return ['▄', bottom, null];
87
+ return ['▀', top, bottom];
88
+ });
89
+ out.push(paintRow(cells, depth));
90
+ }
91
+ return out;
92
+ };
93
+
94
+ const tagline = (width, depth) => {
95
+ const pad = ' '.repeat(Math.max(0, Math.floor((width - FALLBACK.length) / 2)));
96
+ if (depth === 'none') return `${pad}${FALLBACK}`;
97
+ const glyphs = [...FALLBACK];
98
+ return pad + paintRow(glyphs.map((g, i) => [g, g === ' ' ? null : sample(TAGLINE, i / (glyphs.length - 1)), null]), depth);
99
+ };
100
+
101
+ // The mark as printable rows for `cols` cells at `depth`: the art, then one centred tagline.
102
+ // Below 24 columns it is the single plain line.
103
+ export function markRows({ cols = 80, depth = 'none' } = {}) {
104
+ const size = markSize(cols);
105
+ if (!size) return [FALLBACK];
106
+ const art = depth === 'none' ? [...MONO_ROWS[size]] : artRows(size, depth);
107
+ return [...art, tagline(PIXEL_ROWS[size][0].length, depth)];
108
+ }
109
+
110
+ // The mark for this process's stdout, as one string ending in a blank line. When stdout is not a
111
+ // terminal (a pipe, the model's bash tool, a CI log) it is only the plain line: art is for people.
112
+ export function markFor({ env = process.env, stream = process.stdout } = {}) {
113
+ if (stream?.isTTY !== true) return `${FALLBACK}\n`;
114
+ const rows = markRows({ cols: termColumns({ env, stream }), depth: colourDepth({ env, isTTY: stream?.isTTY }) });
115
+ return `${rows.join('\n')}\n`;
116
+ }
117
+
118
+ // The LIT pill: bold dark ink on a gradient from chrome stop 1 to stop 4. Truecolor only; at any
119
+ // other depth it is null and the caller keeps its plain text.
120
+ export const pillLabel = (version) => ` 🔥LIT v${version} `;
121
+ export function litPill(version, depth) {
122
+ if (depth !== 'truecolor') return null;
123
+ const glyphs = [...pillLabel(version)];
124
+ const ink = rgb(PILL_INK).join(';');
125
+ const body = glyphs.map((g, i) => `${ESC}[48;2;${rgb(sample([CHROME[1], CHROME[4]], glyphs.length > 1 ? i / (glyphs.length - 1) : 0)).join(';')}m${g}`).join('');
126
+ return `${ESC}[1;38;2;${ink}m${body}${ESC}[0m`;
127
+ }
128
+
129
+ // Display width of the pill: the flame is two cells wide.
130
+ export const pillWidth = (version) => [...pillLabel(version)].length + 1;
@@ -260,12 +260,14 @@ const paint = (code, text, color) => (color ? `\u001b[${code}m${text}\u001b[0m`
260
260
  const waitingOf = (card) => (card.threads?.rows ?? []).some((row) => row.status === 'paused')
261
261
  || (card.lanes ?? []).some((lane) => lane.status === 'failed');
262
262
 
263
- const headlineFor = (card, color) => {
264
- if (!card.active) return 'LIT · no active route in this workspace';
263
+ // With a pill (truecolor TTY only) the pill stands in for the leading `LIT · `.
264
+ const headlineFor = (card, color, pill = null) => {
265
+ const lit = (rest, style = (s) => s) => (pill ? `${pill} ${style(rest)}` : style(`LIT · ${rest}`));
266
+ if (!card.active) return lit('no active route in this workspace');
265
267
  const route = card.route ?? 'lit-loop';
266
- if (waitingOf(card)) return paint('33;1', `LIT · ${route} · YOUR TURN`, color);
267
- if (route === 'lit-adhd') return color ? rainbowLine('LIT · lit-adhd · brief on screen') : 'LIT · lit-adhd · brief on screen';
268
- return `LIT · ${route}${card.activeMs !== null ? ` · active ${fmtDuration(card.activeMs)}` : ''}${card.kind && card.kind !== 'ignite' ? ` (${card.kind})` : ''}`;
268
+ if (waitingOf(card)) return lit(`${route} · YOUR TURN`, (s) => paint('33;1', s, color));
269
+ if (route === 'lit-adhd') return lit('lit-adhd · brief on screen', color ? rainbowLine : undefined);
270
+ return lit(`${route}${card.activeMs !== null ? ` · active ${fmtDuration(card.activeMs)}` : ''}${card.kind && card.kind !== 'ignite' ? ` (${card.kind})` : ''}`);
269
271
  };
270
272
 
271
273
  // Canonical review-lane display names, in REVIEW_LANES order; the strip reads the same
@@ -302,10 +304,14 @@ const burstOf = (card, now) => {
302
304
  return null;
303
305
  };
304
306
 
305
- export function renderCard(card) {
307
+ // badge: { text, width } from lib/mark.mjs litPill, or null. It is dropped when the headline
308
+ // would no longer fit `cols`, so the plain headline stays the fallback at every width.
309
+ export function renderCard(card, { badge = null, cols = Infinity } = {}) {
306
310
  const out = [];
307
311
  const color = !card.noColor;
308
- out.push(headlineFor(card, color));
312
+ const plainRest = headlineFor(card, false).length - 'LIT · '.length;
313
+ const pill = badge && color && badge.width + 1 + plainRest <= cols ? badge.text : null;
314
+ out.push(headlineFor(card, color, pill));
309
315
  if (card.restartTo) out.push(`restart to ${card.restartTo}: LitMuse was updated after this session loaded it`);
310
316
  if (!card.active && card.idle) out.push('idle — say `lit adhd` for the cross-session brief');
311
317
  const threads = card.threads?.rows ?? [];
@@ -0,0 +1,185 @@
1
+ // Generated from the LitFamily synthwave spec; do not edit by hand. lib/mark.mjs draws it and
2
+ // test/mark.test.mjs recomputes SPEC_DIGEST over these rows.
3
+ export const SPEC_DIGEST = "f063a0cefb969db40c0fc436742240912d895d43c3013d35782320befc0a2b86";
4
+
5
+ export const SHARED_COLOURS = Object.freeze({
6
+ "0": "#331144",
7
+ "1": "#ff5555",
8
+ "2": "#ff5566",
9
+ "3": "#ff4477",
10
+ "4": "#ff3388",
11
+ "5": "#ffbbee",
12
+ "6": "#ff3399",
13
+ "7": "#110022",
14
+ "8": "#ff4499",
15
+ "9": "#220022",
16
+ "!": "#111122",
17
+ "#": "#88eeff",
18
+ "$": "#111111",
19
+ "%": "#ffffff",
20
+ "&": "#111133",
21
+ "(": "#ffcc44",
22
+ ")": "#221133",
23
+ "*": "#ffbb44",
24
+ "+": "#ffaa33",
25
+ ",": "#ff9933",
26
+ "-": "#ff8833",
27
+ ".": "#ff7733",
28
+ "/": "#ff6633",
29
+ ":": "#ff44aa",
30
+ ";": "#220033",
31
+ "<": "#ff55aa",
32
+ "=": "#ff66bb",
33
+ ">": "#ff6644",
34
+ "?": "#ff4466",
35
+ "@": "#ff77cc",
36
+ "A": "#ffaa44",
37
+ });
38
+
39
+ export const PIXEL_ROWS = Object.freeze({
40
+ "B-L": Object.freeze([
41
+ "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!#!!!!!!",
42
+ "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!",
43
+ "!!!!!!!!!!!!!!!!!!!!!!!!!#!!!!!!!!!!!!!#!!!!!!!!!!!!!!!!!!!!!#!!!!!!!!!!!!!!",
44
+ "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!",
45
+ "!!!!#!!!!!!!!mmmmmm!!!!!!!!!!!!mmmmmmmmmm!!!!mmmmmmmmmmmmmmmmmm!!!!!!!!!!!!!",
46
+ "!!!!!!!!!!!!!mbbbbb$!!!!!!!!%!!mbbbbbbbbb$!!!mbbbbbbbbbbbbbbbbb$!!!!!!!!!!!!",
47
+ "!!!!!!!!!!!!!mbbbbb$!#!!!!!!!!!mbbbbbbbbb$!!!mbbbbbbbbbbbbbbbbb$!!!!!!!%!!!!",
48
+ "!!!!!!!!!!!!!mccccc$!!!!!!!!!!!mccccccccc$!!!mccccccccccccccccc$!!!!!!!!!!!!",
49
+ "&&&&&&&&&&&&&mccccc$&&&&&&&&&&&&$mccccc$$$&&&mccccccccccccccccc$&&&&&&&&&&&&",
50
+ "&&&&&&&&&&&&&mddddd$&&&&&%&&&&&&&mddddd$&&&&&mddddddddddddddddd$&&&&&&&&&&&&",
51
+ "&&&&&&&&&&&&&mddddd$&&&&&&&&&&&&&mddddd$&&&&&&$$$$$mddddd$$$$$$$&%&&&&&&&&&&",
52
+ "&&&&&&&&&&&&&meeeee$&&&&&&%&&&&&&meeeee$&%&&&&&&&&&meeeee$&&&&&&&&&&&&%&&&&&",
53
+ "&&&&&&&&&&&&&meeeee$&&&&&%&&&&&&&meeeee$((((&&&&&&&meeeee$&&&&&&&&&&&&&&&&&&",
54
+ ")))))))))))))mfffff$)))))))))))**mfffff$******)))))mfffff$))))))))))))))))))",
55
+ ")))))))))))))mfffff$)))))))))++++mfffff$++++++++)))mfffff$))))))))))))))))))",
56
+ "#))))))))))))mggggg$)))))))),,,,,mggggg$,,,,,,,,,))mggggg$))))))))))))))))))",
57
+ ")))))))))))))mggggg$)))))))------mggggg$----------)mggggg$))))))))))))))))))",
58
+ ")))))))))))))mhhhhh$))))))-------mhhhhh$-----------mhhhhh$))))))))))))))))))",
59
+ ")))))))))))))mhhhhh$)))))).......mhhhhh$...........mhhhhh$))))))))))))))))))",
60
+ ")))))))))))))miiiii$)))))////////miiiii$///////////miiiii$))))))))))))))))))",
61
+ ")))))))))))))miiiiimmmmmmmm))))))miiiii$)))))))))))miiiii$))))))))))))))))))",
62
+ "0000000000000mjjjjjjjjjjjjj$11111mjjjjj$11111111111mjjjjj$000000000000000000",
63
+ "0000000000000mjjjjjjjjjjjjj$222mmjjjjjjmm2222222222mjjjjj$000000000000000000",
64
+ "0000000000000mkkkkkkkkkkkkk$000mkkkkkkkkk$000000000mkkkkk$000000000000000000",
65
+ "0000000000000mkkkkkkkkkkkkk$333mkkkkkkkkk$333333333mkkkkk$000000000000000000",
66
+ "0000000000000mlllllllllllll$444mlllllllll$444444444mlllll$000000000000000000",
67
+ "00000000000000$$$$$$$$$$$$$$0000$$$$$$$$$$0000000000$$$$$$000000000000000000",
68
+ "5555555555555555555555555555555555555555555555555555555555555555555555555555",
69
+ "6666666666666666666666666666666666666666666666666666666666666666666666666666",
70
+ "7777777777777777677676776767677676776767677676776767677676776777777777777777",
71
+ "8888888888886886886886886886868868868868868868868688688688688688688888888888",
72
+ "7777777767767776776776777677677677767767767776776776777677677677767767777777",
73
+ "9999699969996996999699969996996999699969996999699699969996999699699969996999",
74
+ "6:::6:::6::::6:::6:::6:::6::::6:::6:::6:::6:::6::::6:::6:::6:::6::::6:::6:::",
75
+ "6999969999699969999699996999969996999969999699969999699996999969996999969999",
76
+ ";;6;;;;6;;;;6;;;;6;;;;6;;;;;6;;;;6;;;;6;;;;6;;;;6;;;;;6;;;;6;;;;6;;;;6;;;;6;",
77
+ ";;;;6;;;;;6;;;;6;;;;;6;;;;;6;;;;6;;;;;6;;;;;6;;;;6;;;;;6;;;;;6;;;;6;;;;;6;;;",
78
+ "<6<<<<<<6<<<<<6<<<<<6<<<<<6<<<<<6<<<<<6<<<<<6<<<<<6<<<<<6<<<<<6<<<<<6<<<<<<6",
79
+ ";;;;;6;;;;;;6;;;;;6;;;;;;6;;;;;6;;;;;;6;;;;;;6;;;;;6;;;;;;6;;;;;6;;;;;;6;;;;",
80
+ ";;;6;;;;;;6;;;;;;6;;;;;;6;;;;;;6;;;;;;6;;;;;;6;;;;;;6;;;;;;6;;;;;;6;;;;;;6;;",
81
+ ";6;;;;;;6;;;;;;;6;;;;;;6;;;;;;;6;;;;;;6;;;;;;6;;;;;;;6;;;;;;6;;;;;;;6;;;;;;6",
82
+ ";;;;;;6;;;;;;;6;;;;;;;6;;;;;;;6;;;;;;;6;;;;;;;6;;;;;;;6;;;;;;;6;;;;;;;6;;;;;",
83
+ "====6========6=======6========6=======6=======6========6=======6========6===",
84
+ ";;;6;;;;;;;6;;;;;;;;6;;;;;;;;6;;;;;;;;6;;;;;;;;6;;;;;;;;6;;;;;;;;6;;;;;;;6;;",
85
+ ";6;;;;;;;;6;;;;;;;;6;;;;;;;;;6;;;;;;;;6;;;;;;;;6;;;;;;;;;6;;;;;;;;6;;;;;;;;6",
86
+ ";;;;;;;;;6;;;;;;;;6;;;;;;;;;6;;;;;;;;;6;;;;;;;;;6;;;;;;;;;6;;;;;;;;6;;;;;;;;",
87
+ ]),
88
+ "B-M": Object.freeze([
89
+ "#!!!!!!!!!!!!!!!!!!!!%!!!!%#!!!!!!!!!!%!!!!!",
90
+ "!!!#!!!!!!!!!!%!!!!!!!!!!!!!!!!!%!!!!!!!!!!!",
91
+ "#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!",
92
+ "!!!#!!!!mmm!!!!!#!mmmmm!!!mmmmmmmmm!!!%#!!!!",
93
+ "!!!!!!!!mbb$!!!!!!mbbbb$!!mbbbbbbbb$!!!!!!!!",
94
+ "&&&&&&&&mcc$&&&&&&&mcc$$&&mcccccccc$&&&&&&&&",
95
+ "&&&&&&&&mdd$&&&&&&*mdd$****$$mdd$$$$&&&&&&&&",
96
+ "))))))))mee$)))))++mee$+++++)mee$)))))))))))",
97
+ "))))))))mgg$))))---mgg$------mgg$)))))))))))",
98
+ "))))))))mhh$)))....mhh$......mhh$)))))))))))",
99
+ "))))))))mii$))>>>>>mii$>>>>>>mii$)))))))))))",
100
+ "))))))))mjjmmmm))))mjj$))))))mjj$)))))))))))",
101
+ "00000000mkkkkkk$??mkkkm??????mkk$00000000000",
102
+ "00000000mllllll$44mllll$44444mll$00000000000",
103
+ "000000000$$$$$$$000$$$$$000000$$$00000000000",
104
+ "55555555555555555555555555555555555555555555",
105
+ "66666666666666666666666666666666666666666666",
106
+ "77776767676767676767676767676767676767676777",
107
+ "6::6:6:6::6:6::6:6::6:6:6::6:6::6:6::6:6:6::",
108
+ "99699699696996996996996996996996996969969969",
109
+ ";;6;;6;;;6;;6;;6;;;6;;6;;6;;;6;;6;;6;;;6;;6;",
110
+ "===6===6===6==6===6===6===6===6==6===6===6==",
111
+ ";6;;;6;;;6;;;6;;;;6;;;6;;;6;;;;6;;;6;;;6;;;6",
112
+ ";;;6;;;;6;;;;6;;;6;;;;6;;;;6;;;6;;;;6;;;;6;;",
113
+ ";6;;;;6;;;;;6;;;;6;;;;6;;;;6;;;;6;;;;;6;;;;6",
114
+ "@@@@@6@@@@@6@@@@6@@@@@6@@@@@6@@@@6@@@@@6@@@@",
115
+ ]),
116
+ "B-S": Object.freeze([
117
+ "!!!!!!!%!!!!#!!!!!!!!!!!",
118
+ "!%!!!!!!!!!!!!!!!!!!!!#!",
119
+ "!!!!mm!!!mmmm!mmmmmm!!!!",
120
+ "&&&&mc$&&&mc$$mccccc$&&&",
121
+ "&&&&me$&&Ame$AA$me$$$&&&",
122
+ "))#)mg$)--mg$---mg$)))))",
123
+ "))))mh$)))mh$)))mh$)))%)",
124
+ "))))mjmm11mj$111mj$)))))",
125
+ "0000mlll$mllm333ml$00000",
126
+ "00000$$$$0$$$$000$$00000",
127
+ "555555555555555555555555",
128
+ "6<66<6<6<66<6<66<6<6<66<",
129
+ "6;6;;6;6;;6;6;6;;6;6;;6;",
130
+ "6@@6@@6@@6@@6@@6@@6@@6@@",
131
+ ]),
132
+ });
133
+
134
+ export const MONO_ROWS = Object.freeze({
135
+ "B-L": Object.freeze([
136
+ " ·",
137
+ " · · ·",
138
+ " · ██████ · ██████████ ██████████████████",
139
+ " ██████ · ██████████ ██████████████████ ·",
140
+ " ██████ · ██████ ██████████████████",
141
+ " ██████ · ██████ · ██████ · ·",
142
+ " ██████ · ░░██████░░░░░░░ ██████",
143
+ "· ██████ ░░░░░██████░░░░░░░░░░ ██████",
144
+ " ██████ ░░░░░░░██████░░░░░░░░░░░░██████",
145
+ " ██████ ░░░░░░░░██████░░░░░░░░░░░░██████",
146
+ " ██████████████░░░░░░██████░░░░░░░░░░░░██████",
147
+ " ██████████████░░░░██████████░░░░░░░░░░██████",
148
+ " ██████████████░░░░██████████░░░░░░░░░░██████",
149
+ "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━",
150
+ " ╱ ╱ ╱ ╱ ╱ │╲ ╲ ╲ ╲ ╲",
151
+ "────────────────────────┼──┼──┼─┼──┼──┼─┼──┼─┼──┼──┼────────────────────────",
152
+ " ╱ ╱ ╱ ╱ ╱ │ ╲ ╲ ╲ ╲ ╲",
153
+ "──────────────────┼───┼───┼───┼───┼───┼──┼───┼───┼───┼───┼──────────────────",
154
+ " ╱ ╱ ╱ ╱ ╱ │ ╲ ╲ ╲ ╲ ╲",
155
+ "────────────┼────┼────┼────┼────┼─────┼────┼────┼────┼────┼────┼────────────",
156
+ " ╱ ╱ ╱ ╱ ╱ │ ╲ ╲ ╲ ╲ ╲",
157
+ "──────┼─────┼──────┼─────┼─────┼──────┼─────┼─────┼─────┼──────┼─────┼──────",
158
+ "───┼──────┼──────┼──────┼──────┼──────┼─────┼──────┼──────┼──────┼──────┼───",
159
+ ]),
160
+ "B-M": Object.freeze([
161
+ "· · · · ·· · ·",
162
+ "· · ▄▄▄ · ▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄ ··",
163
+ " ███ ▀███▀ █████████",
164
+ " ███ ░░███░░░░░░░███",
165
+ " ███ ░░░░███░░░░░░░███",
166
+ " ███▄▄▄▄░░░░███░░░░░░░███",
167
+ " ███████░░░█████░░░░░░███",
168
+ "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━",
169
+ " ╱ ╱╱ ╱╱ │╲╲ ╲╲ ╲",
170
+ "───────────┼─┼─┼─┼─┼──┼─┼─┼─┼─┼─┼───────────",
171
+ " ╱ ╱ ╱ ╱ ╱ │ ╲ ╲ ╲ ╲ ╲",
172
+ "─────┼──┼──┼───┼──┼───┼──┼──┼───┼──┼──┼─────",
173
+ "──┼───┼───┼───┼───┼───┼───┼───┼───┼───┼───┼─",
174
+ ]),
175
+ "B-S": Object.freeze([
176
+ " · · · ·",
177
+ " ██ ▀██▀ ██████",
178
+ " · ██░ ░░██░░░░██░",
179
+ " ██▄▄░░██░░░░██░ ·",
180
+ " ▀▀▀▀ ▀▀▀▀░░░▀▀░",
181
+ "━━━━━━━━━━━━━━━━━━━━━━━━",
182
+ " ╱╱ ╱╱╱ │╲╲╲ ╲╲",
183
+ "─┼─┼─┼─┼─┼──┼─┼─┼─┼─┼─┼─",
184
+ ]),
185
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@litfamily/litmuse",
3
- "version": "0.1.16",
3
+ "version": "0.1.18",
4
4
  "description": "Installer for LitMuse: skills, hooks and agents that help Meta's Muse Code plan, build, check and hand off work.",
5
5
  "keywords": [
6
6
  "muse",
@@ -2,7 +2,7 @@
2
2
  "schemaVersion": 1,
3
3
  "name": "litmuse",
4
4
  "displayName": "LitMuse",
5
- "version": "0.1.16",
5
+ "version": "0.1.18",
6
6
  "description": "LitFamily workflows for Muse Code: bare lit activation, planning, evidence-bound execution, review, research, handoff and Korean prose care.",
7
7
  "compat": {
8
8
  "source": "native",
@@ -251,7 +251,7 @@
251
251
  "node",
252
252
  "hooks/session-start.mjs",
253
253
  "--digest",
254
- "a4a3defb933793e6"
254
+ "1dffc2949834e04d"
255
255
  ],
256
256
  "timeoutMs": 5000
257
257
  },
@@ -262,7 +262,7 @@
262
262
  "node",
263
263
  "hooks/user-prompt-submit.mjs",
264
264
  "--digest",
265
- "02f7f133ee18fa8f"
265
+ "a005f619d0221178"
266
266
  ],
267
267
  "timeoutMs": 5000,
268
268
  "statusMessage": "LitMuse route check"
@@ -274,7 +274,7 @@
274
274
  "node",
275
275
  "hooks/pre-tool-use.mjs",
276
276
  "--digest",
277
- "61284066a83e7bf9"
277
+ "86fc0def8a86f4bd"
278
278
  ],
279
279
  "timeoutMs": 5000
280
280
  },
@@ -285,7 +285,7 @@
285
285
  "node",
286
286
  "hooks/post-tool-use.mjs",
287
287
  "--digest",
288
- "c6a96dd6cbac119d"
288
+ "3b81610dc35969d1"
289
289
  ],
290
290
  "timeoutMs": 5000
291
291
  },
@@ -296,7 +296,7 @@
296
296
  "node",
297
297
  "hooks/post-tool-use-failure.mjs",
298
298
  "--digest",
299
- "f4d021c9a022292c"
299
+ "c95b4780ca00948d"
300
300
  ],
301
301
  "timeoutMs": 5000
302
302
  },
@@ -307,7 +307,7 @@
307
307
  "node",
308
308
  "hooks/stop.mjs",
309
309
  "--digest",
310
- "60f1b3268eb85120"
310
+ "0a1a04d48d28875d"
311
311
  ],
312
312
  "timeoutMs": 5000
313
313
  },
@@ -318,7 +318,7 @@
318
318
  "node",
319
319
  "hooks/subagent-start.mjs",
320
320
  "--digest",
321
- "d8b88f8c7d564788"
321
+ "8f675c7f0b5209b3"
322
322
  ],
323
323
  "timeoutMs": 5000
324
324
  },
@@ -329,7 +329,7 @@
329
329
  "node",
330
330
  "hooks/subagent-stop.mjs",
331
331
  "--digest",
332
- "99aa8e23fc29a0a2"
332
+ "05789f8effcb2eff"
333
333
  ],
334
334
  "timeoutMs": 5000
335
335
  },
@@ -340,7 +340,7 @@
340
340
  "node",
341
341
  "hooks/session-end.mjs",
342
342
  "--digest",
343
- "0a3ad8b835c39886"
343
+ "4fbfe88045109e11"
344
344
  ],
345
345
  "timeoutMs": 5000
346
346
  },
@@ -351,7 +351,7 @@
351
351
  "node",
352
352
  "hooks/pre-compact.mjs",
353
353
  "--digest",
354
- "1b0c8c166a3ae681"
354
+ "6e445d503992e185"
355
355
  ],
356
356
  "timeoutMs": 5000
357
357
  }
@@ -27,14 +27,36 @@ export const CONSENT_TTL_MS = 30 * 60 * 1000;
27
27
  export const FALSIFY_TIMEOUT_MS = 120_000;
28
28
  export const LIT_TAG = /\[lit:([0-9a-f]{8})\]\s*$/u;
29
29
 
30
+ // The answers each goal question accepts, with what each one does. The question's `(yes / …)` suffix and the answer
31
+ // guide under it are both built from this one list, so they cannot drift apart.
32
+ export const GOAL_ANSWERS = Object.freeze({
33
+ plan: { title: 'approve plan · start work · set goal', answers: [['yes', 'Starts the work now and sets this goal'], ['edit', "Change the plan or the goal's check first, then you are asked again"], ['no', 'Nothing starts and no goal is set']] },
34
+ start: { title: 'approve plan · start work', answers: [['yes', 'Starts the work now, with no goal'], ['no', 'Nothing starts']] },
35
+ loop: { title: 'set goal for this lit-loop', answers: [['yes', 'Sets this goal; the loop goes on'], ['no', 'The loop goes on without a goal']] },
36
+ });
37
+ const choices = (kind) => `(${GOAL_ANSWERS[kind].answers.map(([word]) => word).join(' / ')})`;
38
+
39
+ /**
40
+ * The answer guide the model renders under a goal question, as a Markdown block quote: Muse shows no hook text, so every
41
+ * goal question reaches the user inside a model-written reply. The model words the descriptions in the user's language;
42
+ * the answer words stay English because the prompt hook matches them exactly. A condition holding a backtick is fenced
43
+ * with double backticks.
44
+ */
45
+ export function answerGuide(kind, cond) {
46
+ const { title, answers } = GOAL_ANSWERS[kind];
47
+ const goal = cond === undefined ? [] : [`> Goal: \`\`/goal ${cond}\`\``, '>'];
48
+ return [`> **▶ Answer: ${title}**`, '>', ...goal, '> | Type | What happens |', '> |---|---|',
49
+ ...answers.map(([word, effect]) => `> | **\`${word}\`** | ${effect} |`), '>', '> Type the word alone.'].join('\n');
50
+ }
51
+
30
52
  // Fixed status lines, one per outcome. Hooks and the propose script print these and nothing else.
31
53
  export const GOAL_STATUS = Object.freeze({
32
- asked: (cond) => `Approve plan, start work and set goal: /goal ${cond}? (yes / edit / no)`,
33
- askedStart: 'Approve plan and start work? (yes / no)',
54
+ asked: (cond) => `Approve plan, start work and set goal: /goal ${cond}? ${choices('plan')}`,
55
+ askedStart: `Approve plan and start work? ${choices('start')}`,
34
56
  declined: 'Nothing started and no goal set: you said no',
35
57
  notStarted: (why) => `Work not started and no goal set: ${why}`,
36
58
  notRecorded: (plan) => `Approval not recorded for this session. Run: lit start ${plan}`,
37
- loopAsked: (cond) => `Set goal for this lit-loop: /goal ${cond}? (yes / no)`,
59
+ loopAsked: (cond) => `Set goal for this lit-loop: /goal ${cond}? ${choices('loop')}`,
38
60
  skipped: (reason) => `No goal set: ${reason}`,
39
61
  set: (id) => `LitMuse goal set [lit:${id}]`,
40
62
  yours: 'Your own goal is active; LitMuse left it alone.',
@@ -150,7 +172,7 @@ export function buildLoopConsent({ cwd, check, objective, now = Date.now(), time
150
172
  const dry = falsifyNow ? falsifyLoop({ cwd, check: command, ...(timeoutMs ? { timeoutMs } : {}), ...(run ? { run } : {}) }) : { ok: true };
151
173
  if (!dry.ok) return { line: GOAL_STATUS.skipped(dry.reason) };
152
174
  const consent = { version: 1, kind: 'loop', goal: true, condition: built.condition, hash: conditionHash(built.condition), id: built.id, plan: null, check: command, objective: goal, sessionId, askedAt: new Date(now).toISOString() };
153
- return { line: GOAL_STATUS.loopAsked(built.condition), consent };
175
+ return { line: GOAL_STATUS.loopAsked(built.condition), guide: answerGuide('loop', built.condition), consent };
154
176
  }
155
177
 
156
178
  const openRows = (planText) => String(planText ?? '').split('\n').filter((line) => /^- \[ \] (?:\d+|F\d+)\. /u.test(line)).length;
@@ -167,16 +167,20 @@ export function detectRoute(prompt) {
167
167
  }
168
168
 
169
169
  // A standalone `lit` or `LIT` as the last word of the prompt ("Hello! lit") activates lit-loop with the earlier text as
170
- // the task, as it does in the sibling products. Only a word of its own counts: a `lit` inside a word (literal, split),
171
- // after a path or URL character (lit-plan.md, /x/lit/y), in quotes, in a code span or fence, or followed by more text
172
- // does not.
173
- const TRAILING_LIT = /(?:^|\s)(?:lit|LIT)\s*$/;
170
+ // the task, as it does in the sibling products. A closing run word (`lit-loop`, `litwork`) runs that route the same way,
171
+ // as it would at the start. Only a word of its own counts: a `lit` inside a word (literal, split), after a path or URL
172
+ // character (lit-plan.md, /x/lit/y), in quotes, in a code span or fence, or followed by more text does not.
173
+ const TRAILING_LIT = /(?:^|\s)(lit|LIT|lit-loop|LIT-LOOP|litwork|LITWORK)\s*$/;
174
174
  function detectTrailing(prompt) {
175
175
  const withoutFences = prompt.replace(/```[\s\S]*?```/g, ' ');
176
176
  if (withoutFences.includes('```')) return null;
177
177
  const text = withoutFences.replace(/`[^`\n]*`/g, ' ');
178
- if (!TRAILING_LIT.test(text)) return null;
179
- return { route: 'lit-loop', keyword: null, bare: false, resume: false, restart: false, trailing: true, task: prompt.replace(/(?:lit|LIT)\s*$/u, '') };
178
+ const word = TRAILING_LIT.exec(text)?.[1];
179
+ if (!word) return null;
180
+ const lower = word.toLowerCase();
181
+ const task = prompt.replace(/\S+\s*$/u, '');
182
+ if (lower === 'lit') return { route: 'lit-loop', keyword: null, bare: false, resume: false, restart: false, trailing: true, task };
183
+ return { route: lower, keyword: lower, bare: false, resume: false, restart: false, trailing: true, task };
180
184
  }
181
185
 
182
186
  function detectLeading(prompt) {
@@ -40,7 +40,7 @@ function goalQuestionMissing(cwd, saved) {
40
40
  if (text === null || !/^##\s+Done when\s*$/imu.test(text) || /^goal:\s*never\s*$/mu.test(text)) return null;
41
41
  const consent = readGoalRecord(resolveProjectStateRoot(cwd), 'consent');
42
42
  if (consent && consent.plan === saved && Date.parse(consent.askedAt) >= statSync(join(cwd, saved)).mtimeMs - 1000) return null;
43
- return `LitMuse lit-plan gate: ${saved} has a \`## Done when\` block but no goal question yet. Run \`node ${join(PLUGIN_ROOT, 'skills', 'lit-plan', 'scripts', 'goal-propose.mjs')} ${saved}\` once and put the one line it prints into the approval question, then end the turn.`;
43
+ return `LitMuse lit-plan gate: ${saved} has a \`## Done when\` block but no goal question yet. Run \`node ${join(PLUGIN_ROOT, 'skills', 'lit-plan', 'scripts', 'goal-propose.mjs')} ${saved}\` once and end the reply with what it prints (the approval question, then its answer guide), then end the turn.`;
44
44
  }
45
45
 
46
46
  // At turn end the goal LitMuse owns is checked the only way a 5 s hook can: when every row of its plan is ticked, the
@@ -67,7 +67,7 @@ function stackCount(frame) {
67
67
  }
68
68
 
69
69
  function activation(hit, payload) {
70
- const task = hit.trailing ? 'The task is the rest of the prompt before the closing `lit`.' : `The task is the rest of the prompt after the keyword${hit.keyword ? ` "${hit.keyword}"` : ''}.`;
70
+ const task = hit.trailing ? `The task is the rest of the prompt before the closing \`${hit.keyword ?? 'lit'}\`.` : `The task is the rest of the prompt after the keyword${hit.keyword ? ` "${hit.keyword}"` : ''}.`;
71
71
  const moved = movedActivation(hit.route);
72
72
  const lines = [
73
73
  ...banner('LIT IGNITED', hit.route),
@@ -98,7 +98,7 @@ function activation(hit, payload) {
98
98
  lines.push('Only when the user asks for detail (`lit adhd 자세히`, `lit adhd detail`) add `--detail`: it prints the KPI board (bars, milestones, done, left, reminders) with the per-session list under it. The collector draws every bar and count; never redraw, round or add to them. `' + rewind + ' --json` holds the same records, the board and the verdict.');
99
99
  }
100
100
  if (hit.trailing) {
101
- lines.push('Soft-confirm: `lit` came last in the prompt. If the request reads like ordinary prose, say in one line that you are starting a lit-loop and carry on; a stray English `lit` is recoverable.');
101
+ lines.push(`Soft-confirm: \`${hit.keyword ?? 'lit'}\` came last in the prompt. If the request reads like ordinary prose, say in one line that you are starting a ${hit.route} and carry on; a stray English \`lit\` is recoverable.`);
102
102
  }
103
103
  if (hit.bare && !hit.restart) {
104
104
  lines.push('The prompt has no task text after the keyword. After loading the skill, ask the user in one line what to run (a task for lit-loop, or a route such as plan or review) and wait for the answer before any other tool.');
@@ -310,14 +310,14 @@ function loopGoalAnswer(payload, root, consent, answer) {
310
310
  return true;
311
311
  }
312
312
 
313
- // A run route's first activation asks one goal question when the prompt names an objective, and no goal of this session is
314
- // open and no question is pending. With a test command the hook records the question itself (no test run here) and tells the
313
+ // A run route's first activation asks one goal question when the prompt names an objective (the words before a closing
314
+ // activation word count as one), and no goal of this session is open and no question is pending. With a test command the hook records the question itself (no test run here) and tells the
315
315
  // model to end its first reply with it: Muse shows no hook text, so this is advisory. Without one, the model asks it after
316
316
  // its RED check through goal-propose --loop, which dry-runs and refuses a check that already passes.
317
317
  const RUN_GOAL_ROUTES = new Set(['lit-loop', 'litwork']);
318
318
  function loopGoalNote(hit, payload) {
319
319
  try {
320
- if (!RUN_GOAL_ROUTES.has(hit.route) || hit.bare || hit.resume || hit.trailing || !safeId(payload.session_id)) return null;
320
+ if (!RUN_GOAL_ROUTES.has(hit.route) || hit.bare || hit.resume || !safeId(payload.session_id)) return null;
321
321
  const task = typeof hit.task === 'string' ? hit.task : String(payload.prompt ?? '').replace(/^\s*\/?(?:litmuse:)?(?:lit-loop|litwork)\b[\s:,.!?]*/iu, '');
322
322
  const objective = normalizeLoopObjective(task);
323
323
  if (!objective) return null;
@@ -333,7 +333,7 @@ function loopGoalNote(hit, payload) {
333
333
  const offer = buildLoopConsent({ cwd, check, objective, falsifyNow: false, sessionId: payload.session_id });
334
334
  if (!offer.consent) return null;
335
335
  writeGoalRecord(root, 'consent', offer.consent);
336
- return `Native goal: LitMuse recorded one goal question for this run. End your first reply with exactly this line, as its last line and asked once: ${offer.line} Never type or send /goal yourself. Do not call create_goal for this run before the user's exact \`yes\` on a later prompt; the hook then gives you the objective. Until then keep the ledger authoritative.`;
336
+ return `Native goal: LitMuse recorded one goal question for this run. End your first reply with exactly this line, asked once, and under it this answer guide as Markdown, its descriptions in the user's language and the answer words in English:\n${offer.line}\n\n${offer.guide}\nNever type or send /goal yourself. Do not call create_goal for this run before the user's exact \`yes\` on a later prompt; the hook then gives you the objective. Until then keep the ledger authoritative.`;
337
337
  } catch {
338
338
  return null;
339
339
  }
@@ -439,7 +439,7 @@ run((payload) => {
439
439
  const turnId = payload.turn_id ?? null;
440
440
  const active = hit.restart ? null : liveRoute(previous);
441
441
  // start-work is always sent in full: its prompt carries the write grant and names the plan to run.
442
- const continues = active && (hit.bare || hit.resume || hit.trailing || (hit.route === active && active !== 'start-work'));
442
+ const continues = active && (hit.bare || hit.resume || (hit.trailing && !hit.keyword) || (hit.route === active && active !== 'start-work'));
443
443
  if (continues) {
444
444
  // `lit continue` with a side frame on top closes the side and resumes the paused spine.
445
445
  const frame = hit.resume ? stackContinue(payload) : null;
@@ -95,8 +95,8 @@ Durable path: create or reuse the record per `litgoal` (`read_skill` id `plugin:
95
95
 
96
96
  Native goal for a loop with no plan: LitMuse asks one question per run and the user's exact `yes` arms it, the way a plan's approval does but without starting `start-work`.
97
97
 
98
- - When the project has a test command (`npm test`, `pytest`, `cargo test`, `go test ./...`) and the prompt names an objective, the prompt hook records the question at the loop's first activation and its context hands you the line. Muse shows no hook text, so end your first reply with exactly `Set goal for this lit-loop: /goal <condition>? (yes / no)`, once, with the condition the hook gave (`` `<check>` exits 0 and this is done: <objective> [lit:<id>] ``). Do not ask it again later.
99
- - Without a test command, run `node <skill-dir-of-lit-plan>/scripts/goal-propose.mjs --loop --check "<check>" <objective>` once a failing check proves the objective (after the RED step) and end that reply with the line it prints. The script runs the check once: a check that already passes, cannot run or is not an allowlisted test command prints `No goal set: <reason>` and records nothing, and you go on without a goal.
98
+ - When the project has a test command (`npm test`, `pytest`, `cargo test`, `go test ./...`) and the prompt names an objective, the prompt hook records the question at the loop's first activation and its context hands you the line. Muse shows no hook text, so end your first reply with exactly `Set goal for this lit-loop: /goal <condition>? (yes / no)`, once, with the condition the hook gave (`` `<check>` exits 0 and this is done: <objective> [lit:<id>] ``), and under it the answer guide the hook gives: a Markdown block quote with a `yes` row and a `no` row saying what each does, closed by `Type the word alone.` Word its title and descriptions in the user's language and keep the answer words in English, because the prompt hook matches only the exact English word. Do not ask it again later.
99
+ - Without a test command, run `node <skill-dir-of-lit-plan>/scripts/goal-propose.mjs --loop --check "<check>" <objective>` once a failing check proves the objective (after the RED step) and end that reply with what it prints: the question line unchanged, then the answer guide under it, rendered the same way. The script runs the check once: a check that already passes, cannot run or is not an allowlisted test command prints `No goal set: <reason>` and records nothing, and you go on without a goal.
100
100
  - Only the user's exact `yes` (any case) on the next prompt arms it: the hook then tells you to call `get_goal` and, with no unfinished goal, `create_goal` with that exact objective (PreToolUse refuses any other `[lit:…]` objective), and to call `update_goal` with `complete` once the check exits 0 and the objective is done. `no` or any other prompt, including `edit`, drops the question. Never type `/goal` yourself and never call `create_goal` for this run before that `yes`; a goal the user set by hand stays untouched.
101
101
 
102
102
  For a goal with several units, write a dependency map before delegating:
@@ -115,7 +115,7 @@ If the question cannot be asked in this turn but a human is present, write the p
115
115
 
116
116
  The plan carries a `Goal` block (one outcome sentence and two to six criteria, each naming the command or surface that proves it) and a machine-readable `## Done when` block with exactly one line `- check: \`<command>\``: the one allowlisted test command whose exit 0, together with every row ticked, means the plan is done (`npm test`, `npm run <script>`, `node --test …`, `pytest …`, `cargo test`, `go test …`, `make test|check|verify`, or `bash scripts/<name>.sh` for a long plan that needs a check script). Judgment words ("works", "looks good", "잘 동작") and outward actions (push, publish, release) are not checks. A plan that should never become a goal says `goal: never` on its own line instead.
117
117
 
118
- After the plan file exists, run `node <skill-dir>/scripts/goal-propose.mjs plans/<slug>.md` once (the planning guard allows exactly this command). It compiles the block into one Muse goal objective, `Every row in plans/<slug>.md is ticked and \`<check>\` exits 0 [lit:<id>]` (at most 500 characters), lints it, runs the check once to prove the objective is false right now, and prints the closing approval question: `Approve plan, start work and set goal: /goal <objective>? (yes / edit / no)`. When no goal is possible (no Done when block, `goal: never`, a refused check, an objective that is already true), it prints `Approve plan and start work? (yes / no)` and under it the one `No goal set: <reason>` line. End the reply with what it printed, unchanged.
118
+ After the plan file exists, run `node <skill-dir>/scripts/goal-propose.mjs plans/<slug>.md` once (the planning guard allows exactly this command). It compiles the block into one Muse goal objective, `Every row in plans/<slug>.md is ticked and \`<check>\` exits 0 [lit:<id>]` (at most 500 characters), lints it, runs the check once to prove the objective is false right now, and prints the closing approval question: `Approve plan, start work and set goal: /goal <objective>? (yes / edit / no)`. When no goal is possible (no Done when block, `goal: never`, a refused check, an objective that is already true), it prints `Approve plan and start work? (yes / no)` and under it the one `No goal set: <reason>` line. After a blank line it prints the answer guide, a Markdown block quote with one row per accepted answer (`yes`, `edit`, `no`, or `yes`, `no` for start only) saying what each one does, closed by `Type the word alone.` End the reply with what it printed: the question line exactly as printed, then the answer guide under it, its title and descriptions in the user's language and the answer words in English, because the prompt hook matches only the exact English word. Do not drop the guide: it is how a first-time user learns what to type.
119
119
 
120
120
  The planning turn itself sets nothing: `create_goal` and `update_goal` are refused here. Only the session that was asked can answer: PostToolUse stamps this session on the question when goal-propose runs, and a `yes` typed in any other session, or on a question no session was stamped on, starts nothing and shows `Approval not recorded for this session. Run: lit start plans/<slug>.md`. In `muse exec` or another one-shot run nobody can answer in that session, so the question is printed and the user starts the plan later with `lit start plans/<slug>.md`, or types `yes` after resuming that same session (`muse resume`). The user's exact `yes` on the next prompt of this session does it all in one step: the LitMuse prompt hook approves the plan, starts `start-work` on it (the same start as a typed `lit start plans/<slug>.md`, with the same grants) and arms the goal, telling the model to call `create_goal` with that exact objective (PreToolUse admits a `[lit:…]` objective only then). When the start is refused (another live session already runs start-work on the plan, or the plan has no open row), nothing starts, no goal is armed, and the hook shows `Work not started and no goal set: <reason>`. `edit` re-opens the plan and asks again, `no` starts nothing and sets no goal, and anything else leaves the question open for 30 minutes. `get_goal` is allowed here: call it once, and when another goal is active, say so in the plan's Bootstrap section, because a session holds one goal and LitMuse never replaces the user's own.
121
121
 
@@ -352,7 +352,7 @@ Refused on this route: `create_goal`, `update_goal`, `write_todos`, `add_memory`
352
352
 
353
353
  Stop when the plan file is written and passes the checklist, or when a missing answer blocks every useful task (then the plan carries the question as row 1 and the reply says `BLOCKED: <question>`). After two failed attempts at one section, surface what you tried and ask.
354
354
 
355
- Reply in reader form: the plan path, the TL;DR, the number of tasks, any assumption the user should confirm, and the next action. End the reply with what goal-propose printed (`yes` then approves the plan, starts the work and, when the question names one, sets the goal). Only when goal-propose could not run, end with this line instead, plan name filled in: "Type `go` within 30 minutes to start `plans/<slug>.md` with start-work, or run `/start-work` later." The Stop hook records the saved plan for this session only, so `go` from another session, or after 30 minutes, starts nothing. Approval covers plan generation; implementation, commit, push, versioning and publishing each need their own go-ahead. Keep logs, lane verdicts and command lists in the draft and ledger unless the user asks for them.
355
+ Reply in reader form: the plan path, the TL;DR, the number of tasks, any assumption the user should confirm, and the next action. End the reply with what goal-propose printed, the question and its answer guide (`yes` then approves the plan, starts the work and, when the question names one, sets the goal). Only when goal-propose could not run, end with this line instead, plan name filled in: "Type `go` within 30 minutes to start `plans/<slug>.md` with start-work, or run `/start-work` later." The Stop hook records the saved plan for this session only, so `go` from another session, or after 30 minutes, starts nothing. Approval covers plan generation; implementation, commit, push, versioning and publishing each need their own go-ahead. Keep logs, lane verdicts and command lists in the draft and ledger unless the user asks for them.
356
356
 
357
357
  ## Pitfalls
358
358
 
@@ -3,8 +3,8 @@
3
3
  // puts what it prints into the approval question. It compiles the plan's `## Done when` block into one Muse goal
4
4
  // objective, lints it, runs the check once to prove the objective is false now, and records the question in
5
5
  // `.litmuse/goal/consent.json` under the project's state root. It prints the question that starts the work and sets the
6
- // goal, or, when no goal is possible, the start-only question and the one `No goal set: <reason>` line. An unreadable
7
- // plan prints that reason alone. It never starts work or sets a goal; only the user's exact `yes` does both. The lit-plan write guard allows
6
+ // goal, or, when no goal is possible, the start-only question and the one `No goal set: <reason>` line; a blank line and
7
+ // the answer guide follow any question, for the model to render under it. An unreadable plan prints that reason alone. It never starts work or sets a goal; only the user's exact `yes` does both. The lit-plan write guard allows
8
8
  // this one command during a planning turn.
9
9
  // `node <skill-dir>/scripts/goal-propose.mjs --loop --check "<check>" <objective...>` is the lit-loop form: a run with no
10
10
  // plan asks one goal question once its failing check exists (the check must fail now; a check that already passes, cannot
@@ -13,7 +13,7 @@
13
13
  import { readFileSync } from 'node:fs';
14
14
  import { isAbsolute, relative, resolve } from 'node:path';
15
15
  import { pathToFileURL } from 'node:url';
16
- import { GOAL_STATUS, buildLoopConsent, compileCondition, conditionHash, consentKey, falsify, lintCondition, parseDoneWhen, writeGoalRecord } from '../../../hooks/lib/goal.mjs';
16
+ import { GOAL_STATUS, answerGuide, buildLoopConsent, compileCondition, conditionHash, consentKey, falsify, lintCondition, parseDoneWhen, writeGoalRecord } from '../../../hooks/lib/goal.mjs';
17
17
  import { resolveProjectStateRoot } from '../../../hooks/lib/workflow-stack.mjs';
18
18
 
19
19
  export function proposeGoal({ cwd, planArg, now = Date.now(), timeoutMs, run, sessionId = null } = {}) {
@@ -32,7 +32,7 @@ export function proposeGoal({ cwd, planArg, now = Date.now(), timeoutMs, run, se
32
32
  const consent = { version: 1, goal: false, plan, reason, sessionId, askedAt };
33
33
  consent.hash = conditionHash(consentKey(consent));
34
34
  writeGoalRecord(resolveProjectStateRoot(cwd), 'consent', consent);
35
- return { line: `${GOAL_STATUS.askedStart}\n${GOAL_STATUS.skipped(reason)}`, consent };
35
+ return { line: `${GOAL_STATUS.askedStart}\n${GOAL_STATUS.skipped(reason)}`, guide: answerGuide('start'), consent };
36
36
  };
37
37
  if (/^goal:\s*never\s*$/mu.test(planText)) return startOnly('this plan is marked goal: never');
38
38
  const done = parseDoneWhen(planText);
@@ -45,7 +45,7 @@ export function proposeGoal({ cwd, planArg, now = Date.now(), timeoutMs, run, se
45
45
  if (!dry.ok) return startOnly(dry.reason);
46
46
  const consent = { version: 1, goal: true, condition: built.condition, hash: conditionHash(built.condition), id: built.id, plan, check: done.check, sessionId, askedAt };
47
47
  writeGoalRecord(resolveProjectStateRoot(cwd), 'consent', consent);
48
- return { line: GOAL_STATUS.asked(built.condition), consent };
48
+ return { line: GOAL_STATUS.asked(built.condition), guide: answerGuide('plan', built.condition), consent };
49
49
  }
50
50
 
51
51
  export function proposeLoopGoal({ cwd, check, objective, now = Date.now(), timeoutMs, run, sessionId = null } = {}) {
@@ -56,8 +56,8 @@ export function proposeLoopGoal({ cwd, check, objective, now = Date.now(), timeo
56
56
 
57
57
  if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
58
58
  const [first, ...rest] = process.argv.slice(2);
59
- const { line } = first === '--loop' && rest[0] === '--check'
59
+ const { line, guide } = first === '--loop' && rest[0] === '--check'
60
60
  ? proposeLoopGoal({ cwd: process.cwd(), check: rest[1], objective: rest.slice(2).join(' ') })
61
61
  : proposeGoal({ cwd: process.cwd(), planArg: first });
62
- process.stdout.write(`${line}\n`);
62
+ process.stdout.write(guide ? `${line}\n\n${guide}\n` : `${line}\n`);
63
63
  }
@@ -22,6 +22,9 @@ import {
22
22
  } from "./secure-path.mjs";
23
23
 
24
24
  const MAX_OWNER_BYTES = 4096;
25
+ // No team update holds the lock for more than a moment, so an owner older than this crashed even when its recorded pid
26
+ // now belongs to another live process (pids are reused, often on WSL).
27
+ const MAX_HOLD_MS = 10 * 60 * 1000;
25
28
  const sleepSync = (milliseconds) => Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, milliseconds);
26
29
  const monotonicNowMs = () => Number(process.hrtime.bigint()) / 1_000_000;
27
30
 
@@ -204,11 +207,24 @@ const takeoverWinner = (lockDir, incumbent, ownClaim, staleAfter, expectedLockDi
204
207
  for (const name of names) {
205
208
  assertLockDirectory(lockDir, expectedLockDirectory);
206
209
  const claimRecord = readTakeoverClaim(lockDir, name, incumbent.nonce);
207
- if (claimRecord === null) return null;
210
+ if (claimRecord === null) {
211
+ // A contender that died while writing its claim left a file nobody can read; once old it is removed.
212
+ const claimPath = join(lockDir, name);
213
+ const stats = lstatSync(claimPath, { throwIfNoEntry: false });
214
+ if (!stats?.isFile() || stats.isSymbolicLink() || Date.now() - stats.mtimeMs < staleAfter) return null;
215
+ const identity = pathIdentity(stats);
216
+ try {
217
+ if (!removeVerifiedPath(claimPath, identity, expectedLockDirectory)) return null;
218
+ } catch (error) {
219
+ if (error?.code !== "ENOENT") return null;
220
+ }
221
+ continue;
222
+ }
208
223
  const { claim, identity, text } = claimRecord;
209
224
  const alive = processIsAlive(claim.pid);
210
225
  const oldEnough = Date.now() - claim.acquired_at_ms >= staleAfter;
211
- if (!alive && oldEnough) {
226
+ // A contender waits far less than the stale window, so an old claim is left over even when its pid looks alive.
227
+ if (oldEnough && claim.claimant_nonce !== ownClaim.claimant_nonce) {
212
228
  try {
213
229
  assertLockDirectory(lockDir, expectedLockDirectory);
214
230
  const claimPath = join(lockDir, name);
@@ -266,9 +282,20 @@ export const acquireOwnerLock = (lockDir, { timeoutMs = 500, staleMs = 30_000 }
266
282
 
267
283
  lockDirectory = assertLockDirectory(lockDir);
268
284
  const incumbent = readOwnerLock(lockDir);
285
+ if (!incumbent && lockDirectory) {
286
+ // A holder that died between creating the folder and writing its owner record left a lock nobody can judge;
287
+ // once it is older than the stale window it is moved aside and the acquisition retried.
288
+ const folder = lstatSync(lockDir, { throwIfNoEntry: false });
289
+ if (folder && Date.now() - folder.mtimeMs >= staleAfter) {
290
+ try {
291
+ if (removeVerifiedPath(lockDir, lockDirectory, undefined, `${lockDir}.stale.ownerless.${randomUUID()}`,
292
+ (quarantine) => !readOwnerLock(quarantine))) continue;
293
+ } catch { /* A lock that changed under us is judged again on the next pass. */ }
294
+ }
295
+ }
296
+ const heldFor = incumbent ? Date.now() - incumbent.acquired_at_ms : 0;
269
297
  const stale = incumbent
270
- && Date.now() - incumbent.acquired_at_ms >= staleAfter
271
- && !processIsAlive(incumbent.pid);
298
+ && (heldFor >= MAX_HOLD_MS || (heldFor >= staleAfter && !processIsAlive(incumbent.pid)));
272
299
  if (stale) {
273
300
  if (takeoverClaim?.owner_nonce !== incumbent.nonce) {
274
301
  takeoverClaim = {
@@ -310,7 +337,10 @@ export const acquireOwnerLock = (lockDir, { timeoutMs = 500, staleMs = 30_000 }
310
337
  }
311
338
  }
312
339
 
313
- if (monotonicNowMs() - startedAt >= timeout) throw new OwnerLockError("state lock timed out");
340
+ if (monotonicNowMs() - startedAt >= timeout) {
341
+ const holder = incumbent ? `held by pid ${incumbent.pid} for ${Math.round(heldFor / 1000)} s` : "with no owner record";
342
+ throw new OwnerLockError(`state lock timed out (${holder}; lock ${lockDir})`);
343
+ }
314
344
  sleepSync(Math.min(20, Math.max(1, timeout)));
315
345
  }
316
346
  }