loopwright 0.1.11 → 0.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -6
- package/content/agents/implementer.md +1 -1
- package/content/agents/reviewer.md +1 -1
- package/content/hooks/default-config.json +1 -0
- package/content/hooks/guard-locked-tests.mjs +1 -1
- package/content/hooks/lib.mjs +101 -29
- package/content/hooks/lw.mjs +469 -67
- package/content/hooks/plain-questions.mjs +6 -10
- package/content/hooks/reinject-context.mjs +10 -3
- package/content/hooks/stop-gate.mjs +1 -2
- package/content/hooks/task-file.mjs +243 -0
- package/content/prompts/blocked-branch.md +9 -0
- package/content/prompts/commit-and-pr.md +55 -0
- package/content/prompts/glossary.md +37 -0
- package/content/prompts/standards.md +1 -0
- package/content/prompts/user-messages.md +6 -25
- package/content/skills/loopwright-build/SKILL.md +7 -7
- package/content/skills/loopwright-done/SKILL.md +25 -16
- package/content/skills/loopwright-explore/SKILL.md +1 -1
- package/content/skills/loopwright-fix/SKILL.md +2 -2
- package/content/skills/loopwright-flow/SKILL.md +10 -8
- package/content/skills/loopwright-park/SKILL.md +10 -2
- package/content/skills/loopwright-plan/SKILL.md +73 -48
- package/content/skills/loopwright-review/SKILL.md +29 -22
- package/content/skills/loopwright-test/SKILL.md +9 -9
- package/dist/cli.js +1 -0
- package/package.json +2 -2
package/content/hooks/lw.mjs
CHANGED
|
@@ -3,11 +3,13 @@
|
|
|
3
3
|
import { copyFileSync, existsSync, readFileSync, readdirSync, mkdirSync, unlinkSync, writeFileSync } from 'node:fs';
|
|
4
4
|
import { homedir } from 'node:os';
|
|
5
5
|
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
6
|
-
import { execFileSync } from 'node:child_process';
|
|
6
|
+
import { execFileSync, spawnSync } from 'node:child_process';
|
|
7
7
|
import { isatty } from 'node:tty';
|
|
8
8
|
import { fileURLToPath } from 'node:url';
|
|
9
9
|
import {
|
|
10
|
+
ICON_PREFIX,
|
|
10
11
|
PROFILES,
|
|
12
|
+
TASK_FILE_ICONS,
|
|
11
13
|
fingerprint,
|
|
12
14
|
gitTopLevel,
|
|
13
15
|
loopwrightDir,
|
|
@@ -17,12 +19,28 @@ import {
|
|
|
17
19
|
readState,
|
|
18
20
|
realpathLoose,
|
|
19
21
|
repoRelative,
|
|
22
|
+
settingValue,
|
|
20
23
|
sha256File,
|
|
21
24
|
statePath,
|
|
22
25
|
workingTree,
|
|
23
26
|
worktreeId,
|
|
27
|
+
writeFileAtomic,
|
|
24
28
|
writeState,
|
|
25
29
|
} from './lib.mjs';
|
|
30
|
+
import {
|
|
31
|
+
ENTRY_NAMES,
|
|
32
|
+
SECTION_NAMES,
|
|
33
|
+
SETTING_KEYS,
|
|
34
|
+
addEntry,
|
|
35
|
+
editEntry,
|
|
36
|
+
fenced,
|
|
37
|
+
fillTask,
|
|
38
|
+
header,
|
|
39
|
+
markEntry,
|
|
40
|
+
setSetting,
|
|
41
|
+
skeleton,
|
|
42
|
+
writeSection,
|
|
43
|
+
} from './task-file.mjs';
|
|
26
44
|
|
|
27
45
|
const STAGES = ['plan', 'test', 'build', 'review', 'done'];
|
|
28
46
|
const cwd = process.cwd();
|
|
@@ -31,8 +49,8 @@ function fail(msg) {
|
|
|
31
49
|
process.stderr.write(msg + '\n');
|
|
32
50
|
process.exit(1);
|
|
33
51
|
}
|
|
34
|
-
const note = (state, event, detail) => {
|
|
35
|
-
(state.history ??= []).push({ event, detail, at: new Date().toISOString() });
|
|
52
|
+
const note = (state, event, detail, extra) => {
|
|
53
|
+
(state.history ??= []).push({ event, detail, ...extra, at: new Date().toISOString() });
|
|
36
54
|
};
|
|
37
55
|
const out = (v) => process.stdout.write(JSON.stringify(v, null, 2) + '\n');
|
|
38
56
|
|
|
@@ -61,6 +79,32 @@ function scaffold(dir, withConfig) {
|
|
|
61
79
|
if (withConfig && !existsSync(cfg)) copyFileSync(seedConfig(), cfg);
|
|
62
80
|
}
|
|
63
81
|
|
|
82
|
+
/** Stdin as LF text; empty when there is none. isatty, not process.stdin.isTTY: touching process.stdin makes a piped fd 0 non-blocking, so a slow writer fails readFileSync with EAGAIN. */
|
|
83
|
+
const readInput = () => (isatty(0) ? '' : readFileSync(0, 'utf8')).replace(/\r\n/g, '\n');
|
|
84
|
+
const inputLines = () =>
|
|
85
|
+
readInput()
|
|
86
|
+
.split('\n')
|
|
87
|
+
.map((l) => l.trimEnd())
|
|
88
|
+
.filter(Boolean);
|
|
89
|
+
|
|
90
|
+
/** The task file a writer command edits: the `--file <path under .loopwright>` (a stub, another task), else the active task. */
|
|
91
|
+
function writerTarget(cmd, args) {
|
|
92
|
+
const named = flag(args, '--file');
|
|
93
|
+
const dir = loopwrightPath(cwd);
|
|
94
|
+
const task = named ?? (dir && readState(dir, worktreeId(cwd))?.task);
|
|
95
|
+
if (!task) fail(`loopwright: ${cmd} needs an active task or --file`);
|
|
96
|
+
const file = resolve(dir, task);
|
|
97
|
+
if (!existsSync(file)) fail(`loopwright: ${cmd}: ${task} not found`);
|
|
98
|
+
return file;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Replace a task file with `change(text)`: read and written with its own line endings, in one rename. */
|
|
102
|
+
function rewriteTask(file, change) {
|
|
103
|
+
const raw = readFileSync(file, 'utf8');
|
|
104
|
+
const next = change(raw.replace(/\r\n/g, '\n'));
|
|
105
|
+
writeFileAtomic(file, raw.includes('\r\n') ? next.replace(/\n/g, '\r\n') : next);
|
|
106
|
+
}
|
|
107
|
+
|
|
64
108
|
const isMainCheckout = () => gitTopLevel(cwd) === mainWorktreeRoot(cwd);
|
|
65
109
|
|
|
66
110
|
function ctx(create = false) {
|
|
@@ -92,7 +136,7 @@ function effortFor(role, badProfile = fail, flagged) {
|
|
|
92
136
|
const dir = !name && loopwrightDir(cwd);
|
|
93
137
|
const state = dir && readState(dir, worktreeId(cwd));
|
|
94
138
|
if (state?.task && existsSync(join(dir, state.task))) {
|
|
95
|
-
name =
|
|
139
|
+
name = settingValue(readFileSync(join(dir, state.task), 'utf8').split(/^## /m)[0], 'profile');
|
|
96
140
|
if (name === 'pending') name = undefined;
|
|
97
141
|
}
|
|
98
142
|
} catch {
|
|
@@ -122,16 +166,14 @@ function effortFor(role, badProfile = fail, flagged) {
|
|
|
122
166
|
*/
|
|
123
167
|
function setHeader(taskPath, key, value) {
|
|
124
168
|
try {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
const head = text.slice(0, split);
|
|
130
|
-
if (!line.test(head)) return `no "${key}:" line`;
|
|
131
|
-
writeFileSync(taskPath, head.replace(line, () => `${key}: ${value}`) + text.slice(split));
|
|
169
|
+
rewriteTask(taskPath, (t) => {
|
|
170
|
+
if (!new RegExp(`^${ICON_PREFIX}${key}:`, 'm').test(header(t))) throw new Error(`no "${key}:" line`);
|
|
171
|
+
return setSetting(t, key, value);
|
|
172
|
+
});
|
|
132
173
|
return null;
|
|
133
174
|
} catch (err) {
|
|
134
|
-
|
|
175
|
+
if (!err.code) return err.message;
|
|
176
|
+
return err.code === 'ENOENT' ? 'task file missing' : `cannot write "${key}:" (${err.code})`;
|
|
135
177
|
}
|
|
136
178
|
}
|
|
137
179
|
|
|
@@ -142,6 +184,174 @@ function headerResult(misses) {
|
|
|
142
184
|
return missed.length === 0;
|
|
143
185
|
}
|
|
144
186
|
|
|
187
|
+
const PROGRESS_OPEN = '<!-- loopwright progress: written by the state tool, edits are overwritten -->';
|
|
188
|
+
const PROGRESS_CLOSE = '<!-- /loopwright progress -->';
|
|
189
|
+
// Markers only count at a line start, so a decision that quotes them in running text is never taken for the block.
|
|
190
|
+
const PROGRESS_BLOCK = /^<!-- loopwright progress[^\r\n]*-->[\s\S]*?^<!-- \/loopwright progress -->/m;
|
|
191
|
+
|
|
192
|
+
const SLICE_ENTRY = new RegExp(`^- (S\\d+) ${ICON_PREFIX}\\[(todo|tested|passed)\\][ \\t]*(.*)$`, 'gm');
|
|
193
|
+
const WHOLE_BRANCH = 'whole branch';
|
|
194
|
+
|
|
195
|
+
/** The slice a stage works on, picked like the stage skills do: Test the first todo, Build and Review the first tested, none left open → the whole branch. */
|
|
196
|
+
function currentSlice(text, stage) {
|
|
197
|
+
const slices = [...text.matchAll(SLICE_ENTRY)];
|
|
198
|
+
if (!['test', 'build', 'review'].includes(stage) || !slices.length) return undefined;
|
|
199
|
+
const open =
|
|
200
|
+
slices.find((m) => m[2] === (stage === 'test' ? 'todo' : 'tested')) ?? slices.find((m) => m[2] !== 'passed');
|
|
201
|
+
return open ? open[1] : WHOLE_BRANCH;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/** The slice to record on a stage or verdict event; none when the task has no Slices list. */
|
|
205
|
+
const sliceFor = (dir, state, stage) =>
|
|
206
|
+
existsSync(join(dir, state.task)) ? currentSlice(readFileSync(join(dir, state.task), 'utf8'), stage) : undefined;
|
|
207
|
+
|
|
208
|
+
const sliceName = (label) => (/^S\d+$/.test(label) ? `slice ${label.slice(1)}` : label);
|
|
209
|
+
const capital = (s) => s[0].toUpperCase() + s.slice(1);
|
|
210
|
+
|
|
211
|
+
/** Trail steps from the history since the task started. The last one stands for the current stage. */
|
|
212
|
+
function trailSteps(history, state, finished) {
|
|
213
|
+
const steps = [];
|
|
214
|
+
for (const e of history) {
|
|
215
|
+
const last = steps.at(-1);
|
|
216
|
+
if (e.event === 'reopen') steps.push({ stage: e.detail, back: true });
|
|
217
|
+
else if (e.event === 'verdict' && last?.stage === 'review') last.pass = e.detail.startsWith('pass');
|
|
218
|
+
else if (e.event === 'stage' && e.detail !== 'plan') {
|
|
219
|
+
const same = last?.stage === e.detail && last.pass === undefined && (last.back || last.slice === e.slice);
|
|
220
|
+
if (!same) steps.push({ stage: e.detail, slice: e.slice });
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
const want = finished ? 'done' : state.stage;
|
|
224
|
+
if (want !== 'plan' && steps.at(-1)?.stage !== want) steps.push({ stage: want });
|
|
225
|
+
return steps;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/** The progress block lines: a Now line, then the step trail. Facts come from what the tool recorded in the history. */
|
|
229
|
+
function progressLines(state, text) {
|
|
230
|
+
const { finished: done, failed, running, paused, back } = TASK_FILE_ICONS.progress;
|
|
231
|
+
const head = text.split(/^## /m)[0];
|
|
232
|
+
const all = state.history ?? [];
|
|
233
|
+
// A forced restart of the same task keeps the trail; only a start of another task begins an empty one.
|
|
234
|
+
const starts = all.flatMap((e, i) => (e.event === 'start' ? [{ i, task: e.task ?? e.detail }] : []));
|
|
235
|
+
let first = starts.length - 1;
|
|
236
|
+
while (first > 0 && starts[first].task === starts[first - 1].task) first--;
|
|
237
|
+
const history = all.slice(first < 0 ? 0 : starts[first].i + 1);
|
|
238
|
+
const finished = history.at(-1)?.event === 'done';
|
|
239
|
+
const steps = trailSteps(history, state, finished);
|
|
240
|
+
const mark = (s, isLast) => {
|
|
241
|
+
if (s.pass === false) return failed;
|
|
242
|
+
if (!isLast || finished) return done;
|
|
243
|
+
return s.pass ? done : state.awaitingUser ? paused : running;
|
|
244
|
+
};
|
|
245
|
+
const shown = steps.map(
|
|
246
|
+
(s, i) => `${s.back ? `${back} ` : ''}${capital(s.stage)} ${mark(s, i === steps.length - 1)}`,
|
|
247
|
+
);
|
|
248
|
+
const trail = [];
|
|
249
|
+
let label;
|
|
250
|
+
steps.forEach((s, i) => {
|
|
251
|
+
label = s.slice ?? label;
|
|
252
|
+
let line = trail.find((t) => t.label === label);
|
|
253
|
+
if (!line) trail.push((line = { label, steps: [] }));
|
|
254
|
+
line.steps.push(shown[i]);
|
|
255
|
+
});
|
|
256
|
+
const planMark = steps.length ? done : state.awaitingUser ? paused : running;
|
|
257
|
+
const sliced = trail.some((t) => t.label);
|
|
258
|
+
const lines = sliced
|
|
259
|
+
? [
|
|
260
|
+
`Plan ${planMark}`,
|
|
261
|
+
...trail.map(
|
|
262
|
+
(t) =>
|
|
263
|
+
`${t.label ? `${TASK_FILE_ICONS.headings.Slices} **${sliceName(t.label)}:** ` : ''}${t.steps.join(' → ')}`,
|
|
264
|
+
),
|
|
265
|
+
]
|
|
266
|
+
: [[`Plan ${planMark}`, ...shown].join(' → ')];
|
|
267
|
+
|
|
268
|
+
const slices = [...text.matchAll(SLICE_ENTRY)];
|
|
269
|
+
const tail = steps.at(-1);
|
|
270
|
+
// After a passing review the Now line keeps naming that slice until the next Test starts.
|
|
271
|
+
const current = finished ? undefined : currentSlice(text, state.stage);
|
|
272
|
+
const passed =
|
|
273
|
+
current !== WHOLE_BRANCH && tail?.stage === 'review' && tail.pass && state.stage === 'review'
|
|
274
|
+
? tail.slice
|
|
275
|
+
: undefined;
|
|
276
|
+
const live = finished ? undefined : (passed ?? current);
|
|
277
|
+
const at = slices.findIndex((m) => m[1] === live);
|
|
278
|
+
const title = at === -1 ? '' : slices[at][3].replace(/ — [^—]*$/, '');
|
|
279
|
+
const where =
|
|
280
|
+
live === WHOLE_BRANCH ? `, ${WHOLE_BRANCH}` : at === -1 ? '' : `, slice ${at + 1} of ${slices.length} (${title})`;
|
|
281
|
+
const verdicts = history.filter((e) => e.event === 'verdict');
|
|
282
|
+
const own = verdicts.filter((e) => e.slice === live);
|
|
283
|
+
const cap = Number(settingValue(head, 'fix-round cap')) || 0;
|
|
284
|
+
const prev = verdicts.findLast((e) => e.slice && e.slice !== live && e.detail.startsWith('pass'));
|
|
285
|
+
const prevRounds = prev ? verdicts.filter((e) => e.slice === prev.slice && e.detail.startsWith('fail')).length : 0;
|
|
286
|
+
const facts = [
|
|
287
|
+
state.stage === 'build' && own.at(-1)?.detail.startsWith('fail')
|
|
288
|
+
? `fix round ${own.filter((e) => e.detail.startsWith('fail')).length}${cap ? ` of ${cap}` : ''}`
|
|
289
|
+
: null,
|
|
290
|
+
state.awaitingUser ? `waiting for you (${state.awaitingUser})` : null,
|
|
291
|
+
prev
|
|
292
|
+
? `${sliceName(prev.slice)} passed ${prevRounds ? `after ${prevRounds} fix round${prevRounds === 1 ? '' : 's'}` : 'with no fix rounds'}`
|
|
293
|
+
: null,
|
|
294
|
+
].filter(Boolean);
|
|
295
|
+
const now = finished
|
|
296
|
+
? `**All stages finished** ${done}`
|
|
297
|
+
: `**Now: ${capital(state.stage)}${where}**${facts.map((f) => ` · ${f}`).join('')} ${state.awaitingUser ? paused : running}`;
|
|
298
|
+
return [now, '', ...lines.map((l) => `${l} `)];
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/** Settings lines, known headings and tagged lines with a missing or wrong icon get the one from TASK_FILE_ICONS. Text is never reflowed. */
|
|
302
|
+
function repairIcons(text) {
|
|
303
|
+
const { settings, headings, tags } = TASK_FILE_ICONS;
|
|
304
|
+
const at = text.search(/^## /m);
|
|
305
|
+
const split = at === -1 ? text.length : at;
|
|
306
|
+
return (
|
|
307
|
+
text
|
|
308
|
+
.slice(0, split)
|
|
309
|
+
.replace(new RegExp(`^${ICON_PREFIX}([a-z][a-z -]*):`, 'gm'), (all, key) =>
|
|
310
|
+
Object.hasOwn(settings, key) ? `${settings[key]} ${key}:` : all,
|
|
311
|
+
) +
|
|
312
|
+
text
|
|
313
|
+
.slice(split)
|
|
314
|
+
.replace(new RegExp(`^## ${ICON_PREFIX}(.+?)(?=[ \\t]*$)`, 'gm'), (all, name) =>
|
|
315
|
+
Object.hasOwn(headings, name) ? `## ${headings[name]} ${name}` : all,
|
|
316
|
+
)
|
|
317
|
+
.replace(new RegExp(`^(- [ADS]\\d+) ${ICON_PREFIX}\\[([a-z-]+)\\]`, 'gm'), (all, id, tag) =>
|
|
318
|
+
Object.hasOwn(tags, tag) ? `${id} ${tags[tag]} [${tag}]` : all,
|
|
319
|
+
)
|
|
320
|
+
);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/** The task text with its progress block rewritten (inserted under the title when missing), and icons repaired in a file with the fenced settings block. */
|
|
324
|
+
function withProgress(text, state) {
|
|
325
|
+
const eol = text.includes('\r\n') ? '\r\n' : '\n';
|
|
326
|
+
const block = [PROGRESS_OPEN, ...progressLines(state, text), PROGRESS_CLOSE].join(eol);
|
|
327
|
+
const afterTitle = /^# [^\r\n]*(?:\r?\n)+/.exec(text)?.[0].length ?? 0;
|
|
328
|
+
const next = PROGRESS_BLOCK.test(text)
|
|
329
|
+
? text.replace(PROGRESS_BLOCK, () => block)
|
|
330
|
+
: `${text.slice(0, afterTitle)}${block}${eol}${eol}${text.slice(afterTitle)}`;
|
|
331
|
+
return fenced(next) ? repairIcons(next) : next;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/** Write the progress block into the task file. A failure is a warning only: state is already saved. */
|
|
335
|
+
function refreshTaskFile(taskPath, state) {
|
|
336
|
+
try {
|
|
337
|
+
const text = readFileSync(taskPath, 'utf8');
|
|
338
|
+
const next = withProgress(text, state);
|
|
339
|
+
if (next !== text) writeFileAtomic(taskPath, next);
|
|
340
|
+
} catch (err) {
|
|
341
|
+
// A missing file is already reported by the header write.
|
|
342
|
+
if (err.code !== 'ENOENT')
|
|
343
|
+
process.stderr.write(`loopwright: task file progress list not updated (${err.code ?? err.message})\n`);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
/** A writer command's edit; the active task's progress block is rewritten in the same write, any other file keeps its block. */
|
|
348
|
+
function editTask(file, change) {
|
|
349
|
+
const dir = loopwrightPath(cwd);
|
|
350
|
+
const state = dir && readState(dir, worktreeId(cwd));
|
|
351
|
+
const active = state?.task && resolve(dir, state.task) === file;
|
|
352
|
+
rewriteTask(file, (t) => (active ? withProgress(change(t), state) : change(t)));
|
|
353
|
+
}
|
|
354
|
+
|
|
145
355
|
/** The main checkout's config.json, else the seed config. */
|
|
146
356
|
const readConfig = () => {
|
|
147
357
|
const main = mainLoopwrightPath(cwd);
|
|
@@ -153,20 +363,23 @@ const gitOut = (args) => execFileSync('git', args, { cwd, encoding: 'utf8', stdi
|
|
|
153
363
|
|
|
154
364
|
/** The worktree a task header names: `worktree: <path> (branch <name>)`. */
|
|
155
365
|
function namedWorktree(header) {
|
|
156
|
-
const m =
|
|
366
|
+
const m = new RegExp(`^${ICON_PREFIX}worktree:[ \\t]*(.+?)(?:[ \\t]+\\(branch[ \\t]+(.*?)\\))?[ \\t]*$`, 'm').exec(
|
|
367
|
+
header,
|
|
368
|
+
);
|
|
157
369
|
return m ? { path: resolve(m[1]), branch: m[2] ?? null } : null;
|
|
158
370
|
}
|
|
159
371
|
|
|
160
372
|
/** Task file fields: status/stage from the header (before the first `## `), title from `# `, goal from `## Goal`. */
|
|
161
373
|
function readTask(root, rel) {
|
|
162
374
|
const [head, ...sections] = readFileSync(join(root, rel), 'utf8').split(/^## /m);
|
|
163
|
-
const
|
|
375
|
+
const goalHeading = new RegExp(`^${ICON_PREFIX}Goal[ \\t]*\\r?\\n`);
|
|
376
|
+
const goal = sections.find((s) => goalHeading.test(s));
|
|
164
377
|
return {
|
|
165
378
|
title: /^# (.*)$/m.exec(head)?.[1].trim() ?? null,
|
|
166
|
-
status:
|
|
167
|
-
stage:
|
|
379
|
+
status: settingValue(head, 'status') ?? null,
|
|
380
|
+
stage: settingValue(head, 'stage') ?? null,
|
|
168
381
|
named: namedWorktree(head),
|
|
169
|
-
goal: goal ? goal.replace(
|
|
382
|
+
goal: goal ? goal.replace(goalHeading, '').trim() : '',
|
|
170
383
|
};
|
|
171
384
|
}
|
|
172
385
|
|
|
@@ -182,17 +395,25 @@ const listWorktrees = () =>
|
|
|
182
395
|
|
|
183
396
|
/** A move copies; the source stays, marked so no listing offers it again. */
|
|
184
397
|
function markMoved(file, to) {
|
|
185
|
-
|
|
398
|
+
const status = new RegExp(`^(${ICON_PREFIX})status:.*$`, 'm');
|
|
399
|
+
writeFileAtomic(
|
|
400
|
+
file,
|
|
401
|
+
readFileSync(file, 'utf8').replace(status, (_, icon) => `${icon}status: moved\nmoved to: ${to}`),
|
|
402
|
+
);
|
|
186
403
|
}
|
|
187
404
|
|
|
405
|
+
const p2 = (n) => String(n).padStart(2, '0');
|
|
406
|
+
|
|
188
407
|
const today = () => {
|
|
189
408
|
const d = new Date();
|
|
190
|
-
const p2 = (n) => String(n).padStart(2, '0');
|
|
191
409
|
return `${d.getFullYear()}-${p2(d.getMonth() + 1)}-${p2(d.getDate())}`;
|
|
192
410
|
};
|
|
193
411
|
|
|
194
|
-
/** File name (no extension) for a stub: date
|
|
195
|
-
const stubBase = (title) =>
|
|
412
|
+
/** File name (no extension) for a new task file or stub: local date and time, then the title with spaces and path characters dashed. */
|
|
413
|
+
const stubBase = (title) => {
|
|
414
|
+
const d = new Date();
|
|
415
|
+
return `${today()}-${p2(d.getHours())}-${p2(d.getMinutes())}-${title.replace(/\s+/g, '-').replace(/[\\/:*?"<>|]/g, '-')}`;
|
|
416
|
+
};
|
|
196
417
|
|
|
197
418
|
/** Write `tasks/<base>.md`, adding `-2`, `-3`... on a name collision; returns the path relative to `dir`. */
|
|
198
419
|
function writeUnique(dir, base, text) {
|
|
@@ -207,8 +428,21 @@ function writeUnique(dir, base, text) {
|
|
|
207
428
|
}
|
|
208
429
|
}
|
|
209
430
|
|
|
210
|
-
/** A proposed stub in park's format; `goal` is empty for a stub parked mid-task. */
|
|
211
|
-
|
|
431
|
+
/** A proposed stub in park's format, settings in a yaml fence with their icons; `goal` is empty for a stub parked mid-task. */
|
|
432
|
+
function stubText(title, kind, goal = '', links = {}) {
|
|
433
|
+
const { settings, headings } = TASK_FILE_ICONS;
|
|
434
|
+
const lines = Object.entries({ kind, status: 'proposed', stage: 'plan', plan: 'draft', ...links }).map(
|
|
435
|
+
([key, value]) => `${settings[key]} ${key}: ${value}`,
|
|
436
|
+
);
|
|
437
|
+
return `# ${title}\n\n\`\`\`yaml\n${lines.join('\n')}\n\`\`\`\n\n## ${headings.Goal} Goal\n\n${goal ? `${goal}\n\n` : ''}## ${headings.Evidence} Evidence\n`;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
/** The branch name a title suggests: lower-case words joined by dashes. */
|
|
441
|
+
const titleSlug = (title) =>
|
|
442
|
+
title
|
|
443
|
+
.toLowerCase()
|
|
444
|
+
.replace(/[^\p{L}\p{N}]+/gu, '-')
|
|
445
|
+
.replace(/^-+|-+$/g, '') || 'task';
|
|
212
446
|
|
|
213
447
|
const refExists = (ref) => {
|
|
214
448
|
try {
|
|
@@ -219,6 +453,71 @@ const refExists = (ref) => {
|
|
|
219
453
|
}
|
|
220
454
|
};
|
|
221
455
|
|
|
456
|
+
/** Run gh with a time limit; null when it is missing, fails or times out, so GitHub never blocks a commit. */
|
|
457
|
+
function ghJson(path) {
|
|
458
|
+
const r = spawnSync('gh', ['api', path], { cwd, encoding: 'utf8', timeout: 10_000 });
|
|
459
|
+
if (r.status !== 0) return null;
|
|
460
|
+
try {
|
|
461
|
+
return JSON.parse(r.stdout);
|
|
462
|
+
} catch {
|
|
463
|
+
return null;
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
// https://docs.github.com/en/rest/repos/rules#get-rules-for-a-branch: rule types that stop direct changes to a branch.
|
|
468
|
+
const PUSH_RESTRICTING_RULES = [
|
|
469
|
+
'pull_request',
|
|
470
|
+
'update',
|
|
471
|
+
'required_status_checks',
|
|
472
|
+
'required_deployments',
|
|
473
|
+
'merge_queue',
|
|
474
|
+
];
|
|
475
|
+
|
|
476
|
+
/** Why committing on the current branch is refused, or null when it is a working branch. */
|
|
477
|
+
function blockedBranchReason(branch) {
|
|
478
|
+
if (branch === 'HEAD') return 'a detached HEAD is not a working branch';
|
|
479
|
+
if (branch === 'main' || branch === 'master') return `loopwright never commits on ${branch}`;
|
|
480
|
+
let remoteDefault = null;
|
|
481
|
+
try {
|
|
482
|
+
remoteDefault = gitOut(['symbolic-ref', '--short', 'refs/remotes/origin/HEAD']).replace(/^origin\//, '');
|
|
483
|
+
} catch {
|
|
484
|
+
// No remote or no origin/HEAD: only the built-in names and the config list apply.
|
|
485
|
+
}
|
|
486
|
+
if (branch === remoteDefault) return `${branch} is the default branch`;
|
|
487
|
+
if ((readConfig().protectedBranches ?? []).includes(branch))
|
|
488
|
+
return `${branch} is in protectedBranches in config.json`;
|
|
489
|
+
let url = '';
|
|
490
|
+
try {
|
|
491
|
+
url = gitOut(['remote', 'get-url', 'origin']);
|
|
492
|
+
} catch {
|
|
493
|
+
return null;
|
|
494
|
+
}
|
|
495
|
+
const repo = /github\.com[:/]([^/]+\/[^/]+?)(?:\.git)?\/?$/.exec(url)?.[1];
|
|
496
|
+
if (!repo) return null;
|
|
497
|
+
const ref = encodeURIComponent(branch);
|
|
498
|
+
// `protected` is also true for a ruleset of any rule type; `protection.enabled` is false when only rulesets protect it.
|
|
499
|
+
const info = ghJson(`repos/${repo}/branches/${ref}`);
|
|
500
|
+
if (
|
|
501
|
+
(info?.protected === true && info.protection?.enabled !== false) ||
|
|
502
|
+
ghJson(`repos/${repo}/rules/branches/${ref}`)?.some((rule) => PUSH_RESTRICTING_RULES.includes(rule.type))
|
|
503
|
+
)
|
|
504
|
+
return `${branch} is protected on GitHub`;
|
|
505
|
+
return null;
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
/** Fails with the reason when the current branch is blocked for commits; call before anything touches git's index. */
|
|
509
|
+
function requireWorkingBranch() {
|
|
510
|
+
const branch = gitOut(['rev-parse', '--abbrev-ref', 'HEAD']);
|
|
511
|
+
const reason = blockedBranchReason(branch);
|
|
512
|
+
if (!reason) return;
|
|
513
|
+
const dir = loopwrightDir(cwd);
|
|
514
|
+
const state = dir && readState(dir, worktreeId(cwd));
|
|
515
|
+
const title = state?.task ? readTask(dir, state.task).title : null;
|
|
516
|
+
fail(
|
|
517
|
+
`loopwright: commit refused: ${reason}. Create a working branch with lw.mjs branch (suggested name: ${titleSlug(title ?? '')}), or skip the commit.`,
|
|
518
|
+
);
|
|
519
|
+
}
|
|
520
|
+
|
|
222
521
|
/**
|
|
223
522
|
* Re-locks and restarts that the history flags for the user's attention, and the ones an `accept-locks` took out.
|
|
224
523
|
* Re-locking an existing lock after a build could launder an implementer's edit; first-time locks in later slices are legitimate.
|
|
@@ -401,11 +700,19 @@ try {
|
|
|
401
700
|
const base = flag(rest, '--base') ?? 'HEAD';
|
|
402
701
|
const force = rest.includes('--force');
|
|
403
702
|
if (force) rest.splice(rest.indexOf('--force'), 1);
|
|
404
|
-
const
|
|
405
|
-
|
|
703
|
+
const kind = flag(rest, '--kind') ?? 'feature';
|
|
704
|
+
const profile = flag(rest, '--profile');
|
|
705
|
+
let task = rest[0];
|
|
706
|
+
// Without a path the title comes on stdin and the state tool names the file.
|
|
707
|
+
const titled = task ? '' : readInput().split('\n')[0].trim();
|
|
708
|
+
if (!task && !titled) fail('loopwright: start: give a task path, or a title on stdin');
|
|
709
|
+
if (kind !== 'feature' && kind !== 'fix') fail(`loopwright: start: kind must be feature or fix, not '${kind}'`);
|
|
710
|
+
if (profile !== undefined && !Object.hasOwn(PROFILES, profile))
|
|
711
|
+
fail(`loopwright: unknown profile '${profile}' (allowed: ${Object.keys(PROFILES).join(', ')})`);
|
|
406
712
|
// A task file belongs to the worktree its header names; starting it elsewhere would split its state.
|
|
407
713
|
const own = loopwrightPath(cwd);
|
|
408
|
-
const header =
|
|
714
|
+
const header =
|
|
715
|
+
own && task && existsSync(join(own, task)) ? readFileSync(join(own, task), 'utf8').split(/^## /m)[0] : '';
|
|
409
716
|
const named = namedWorktree(header)?.path;
|
|
410
717
|
if (named && realpathLoose(named) !== realpathLoose(gitTopLevel(cwd)))
|
|
411
718
|
fail(`loopwright: ${task} belongs to the worktree ${named}; start it there`);
|
|
@@ -413,6 +720,10 @@ try {
|
|
|
413
720
|
const prior = readState(dir, id);
|
|
414
721
|
if (!force && prior) fail('loopwright: task already active (run lw.mjs done first, or start --force)');
|
|
415
722
|
const baseCommit = gitOut(['rev-parse', base]);
|
|
723
|
+
const worktree = gitTopLevel(cwd);
|
|
724
|
+
const branch = gitOut(['rev-parse', '--abbrev-ref', 'HEAD']);
|
|
725
|
+
const fill = { profile, worktree: `${worktree} (branch ${branch})`, base: baseCommit };
|
|
726
|
+
if (!task) task = writeUnique(dir, stubBase(titled), fillTask(skeleton(titled, kind), fill));
|
|
416
727
|
const baseMoved = prior?.baseCommit !== baseCommit;
|
|
417
728
|
// Locked tests out of step with their lock now that the base moves, that the commits it moves over touched:
|
|
418
729
|
// the pull's files, fixed here so a later edit of a test that matched its lock is never taken for a pull.
|
|
@@ -429,8 +740,8 @@ try {
|
|
|
429
740
|
pulledSnapshot: pulledSnapshot?.length ? pulledSnapshot : undefined,
|
|
430
741
|
baseMovedAt: baseMoved ? (prior?.history?.length ?? 0) : prior.baseMovedAt,
|
|
431
742
|
answeredHead: prior?.answeredHead,
|
|
432
|
-
worktree
|
|
433
|
-
branch
|
|
743
|
+
worktree,
|
|
744
|
+
branch,
|
|
434
745
|
// A forced restart keeps the audit trail and the lock records, so a locked test edited
|
|
435
746
|
// during Build cannot be re-baselined unnoticed.
|
|
436
747
|
lockedTests: Array.isArray(prior?.lockedTests) ? prior.lockedTests : [],
|
|
@@ -438,12 +749,78 @@ try {
|
|
|
438
749
|
stopBlocks: 0,
|
|
439
750
|
history: Array.isArray(prior?.history) ? prior.history : [],
|
|
440
751
|
};
|
|
441
|
-
|
|
442
|
-
|
|
752
|
+
note(state, 'start', force ? '--force' : task, { task });
|
|
753
|
+
// A file that is missing (the title comes on stdin) or a proposed stub becomes a task file at Plan; any other
|
|
754
|
+
// file is left alone except for the base commit line of a forced restart.
|
|
755
|
+
const file = join(dir, task);
|
|
756
|
+
const title = existsSync(file) ? '' : readInput().split('\n')[0].trim();
|
|
757
|
+
const proposed = settingValue(header, 'status') === 'proposed';
|
|
758
|
+
if (title) writeFileAtomic(file, fillTask(skeleton(title, kind), fill));
|
|
759
|
+
else if (proposed) rewriteTask(file, (t) => fillTask(t, fill));
|
|
760
|
+
else if (force) setHeader(file, 'base commit', baseCommit);
|
|
443
761
|
writeState(dir, id, state);
|
|
762
|
+
if (title || proposed || titled) refreshTaskFile(file, state);
|
|
444
763
|
out(state);
|
|
445
764
|
break;
|
|
446
765
|
}
|
|
766
|
+
case 'set': {
|
|
767
|
+
const file = writerTarget('set', rest);
|
|
768
|
+
const unset = rest.includes('--unset');
|
|
769
|
+
if (unset) rest.splice(rest.indexOf('--unset'), 1);
|
|
770
|
+
const [key, value, ...more] = rest;
|
|
771
|
+
if (!SETTING_KEYS.includes(key))
|
|
772
|
+
fail(`loopwright: set: unknown setting '${key ?? ''}' (one of ${SETTING_KEYS.join(', ')})`);
|
|
773
|
+
if (unset !== (value === undefined) || more.length)
|
|
774
|
+
fail('loopwright: usage: set <key> <value> | set <key> --unset [--file <path>]');
|
|
775
|
+
editTask(file, (t) => setSetting(t, key, unset ? null : value));
|
|
776
|
+
break;
|
|
777
|
+
}
|
|
778
|
+
case 'add': {
|
|
779
|
+
const file = writerTarget('add', rest);
|
|
780
|
+
const opts = Object.fromEntries(
|
|
781
|
+
['tag', 'interface', 'test', 'scope', 'resolves'].map((name) => [name, flag(rest, `--${name}`)]),
|
|
782
|
+
);
|
|
783
|
+
for (const name of Object.keys(opts)) if (opts[name] === undefined) delete opts[name];
|
|
784
|
+
const [type, ...more] = rest;
|
|
785
|
+
if (!ENTRY_NAMES.includes(type) || more.length)
|
|
786
|
+
fail(`loopwright: add: unknown entry type '${rest.join(' ')}' (one of ${ENTRY_NAMES.join(', ')})`);
|
|
787
|
+
let id;
|
|
788
|
+
const input = inputLines();
|
|
789
|
+
editTask(file, (t) => {
|
|
790
|
+
const added = addEntry(t, type, opts, input);
|
|
791
|
+
id = added.id;
|
|
792
|
+
return added.text;
|
|
793
|
+
});
|
|
794
|
+
out({ id });
|
|
795
|
+
break;
|
|
796
|
+
}
|
|
797
|
+
case 'mark': {
|
|
798
|
+
const file = writerTarget('mark', rest);
|
|
799
|
+
editTask(file, (t) => markEntry(t, rest[0], rest[1]));
|
|
800
|
+
break;
|
|
801
|
+
}
|
|
802
|
+
case 'edit': {
|
|
803
|
+
const file = writerTarget('edit', rest);
|
|
804
|
+
const opts = { interface: flag(rest, '--interface'), test: flag(rest, '--test') };
|
|
805
|
+
if (opts.interface === undefined && opts.test === undefined) {
|
|
806
|
+
opts.text = inputLines()[0];
|
|
807
|
+
if (opts.text === undefined) fail('loopwright: edit needs the new text on stdin, or --interface or --test');
|
|
808
|
+
}
|
|
809
|
+
editTask(file, (t) => editEntry(t, rest[0], opts));
|
|
810
|
+
break;
|
|
811
|
+
}
|
|
812
|
+
case 'section': {
|
|
813
|
+
const file = writerTarget('section', rest);
|
|
814
|
+
const set = rest.includes('--set');
|
|
815
|
+
const append = rest.includes('--append');
|
|
816
|
+
const [name] = rest.filter((a) => a !== '--set' && a !== '--append');
|
|
817
|
+
if (!SECTION_NAMES.includes(name))
|
|
818
|
+
fail(`loopwright: section: unknown section '${name ?? ''}' (one of ${SECTION_NAMES.join(', ')})`);
|
|
819
|
+
if (set === append) fail('loopwright: section needs one of --set or --append');
|
|
820
|
+
const body = readInput().replace(/^\n+/, '').trimEnd();
|
|
821
|
+
editTask(file, (t) => writeSection(t, name, body, append));
|
|
822
|
+
break;
|
|
823
|
+
}
|
|
447
824
|
case 'stage': {
|
|
448
825
|
const name = rest[0];
|
|
449
826
|
if (!STAGES.includes(name)) fail(`loopwright: invalid stage '${name ?? ''}' (one of ${STAGES.join(', ')})`);
|
|
@@ -451,9 +828,11 @@ try {
|
|
|
451
828
|
state.stage = name;
|
|
452
829
|
state.stopBlocks = 0;
|
|
453
830
|
delete state.awaitingUser;
|
|
454
|
-
note(state, 'stage', name);
|
|
831
|
+
note(state, 'stage', name, { slice: sliceFor(dir, state, name) });
|
|
455
832
|
writeState(dir, id, state);
|
|
456
|
-
|
|
833
|
+
const header = headerResult([setHeader(join(dir, state.task), 'stage', name)]);
|
|
834
|
+
refreshTaskFile(join(dir, state.task), state);
|
|
835
|
+
out({ stage: name, header });
|
|
457
836
|
break;
|
|
458
837
|
}
|
|
459
838
|
case 'reopen': {
|
|
@@ -475,7 +854,9 @@ try {
|
|
|
475
854
|
// Both lines are attempted even if the first misses, so a partial header is still fixed.
|
|
476
855
|
const set = [setHeader(file, 'stage', target)];
|
|
477
856
|
if (target === 'plan') set.push(setHeader(file, 'plan', 'draft'));
|
|
478
|
-
|
|
857
|
+
const header = headerResult(set);
|
|
858
|
+
refreshTaskFile(file, state);
|
|
859
|
+
out({ stage: target, reopened: true, header });
|
|
479
860
|
break;
|
|
480
861
|
}
|
|
481
862
|
case 'lock': {
|
|
@@ -559,6 +940,42 @@ try {
|
|
|
559
940
|
out({ fingerprint: fingerprint(cwd, state.baseCommit) });
|
|
560
941
|
break;
|
|
561
942
|
}
|
|
943
|
+
case 'commit': {
|
|
944
|
+
requireWorkingBranch();
|
|
945
|
+
const names = (...args) => gitOut(['-c', 'core.quotePath=false', 'diff', '--name-only', ...args]);
|
|
946
|
+
if (rest.includes('--prepare')) {
|
|
947
|
+
gitOut(['add', '-A']);
|
|
948
|
+
process.stdout.write(names('--cached') + '\n');
|
|
949
|
+
break;
|
|
950
|
+
}
|
|
951
|
+
const message = readInput().trim();
|
|
952
|
+
if (!message) fail('loopwright: commit requires the message on stdin');
|
|
953
|
+
if (!names('--cached')) fail('loopwright: commit has nothing in the index to commit; run commit --prepare first');
|
|
954
|
+
const { dir, id, state } = requireState();
|
|
955
|
+
const before = workingTree(cwd);
|
|
956
|
+
const r = spawnSync('git', ['commit', '-F', '-'], { cwd, encoding: 'utf8', input: message });
|
|
957
|
+
if (r.status !== 0) fail(`loopwright: git commit failed\n${r.stdout}${r.stderr}`.trimEnd());
|
|
958
|
+
// A hook that rewrote a file changed content after the review, so the files it touched are named.
|
|
959
|
+
const rewritten = names(before, workingTree(cwd));
|
|
960
|
+
const commit = gitOut(['rev-parse', 'HEAD']).slice(0, 7);
|
|
961
|
+
note(state, 'commit', commit);
|
|
962
|
+
writeState(dir, id, state);
|
|
963
|
+
process.stdout.write(`committed ${commit}\n`);
|
|
964
|
+
if (rewritten) process.stdout.write(`hooks rewrote files after the review:\n${rewritten}\n`);
|
|
965
|
+
break;
|
|
966
|
+
}
|
|
967
|
+
case 'branch': {
|
|
968
|
+
const { dir, id, state } = requireState();
|
|
969
|
+
const name = rest[0] ?? titleSlug(readTask(dir, state.task).title ?? '');
|
|
970
|
+
if (refExists(`refs/heads/${name}`)) fail(`loopwright: branch: ${name} already exists; give another name`);
|
|
971
|
+
gitOut(['switch', '-c', name]);
|
|
972
|
+
state.branch = name;
|
|
973
|
+
note(state, 'branch', name);
|
|
974
|
+
writeState(dir, id, state);
|
|
975
|
+
headerResult([setHeader(join(dir, state.task), 'worktree', `${gitTopLevel(cwd)} (branch ${name})`)]);
|
|
976
|
+
process.stdout.write(`switched to ${name}\n`);
|
|
977
|
+
break;
|
|
978
|
+
}
|
|
562
979
|
case 'verdict': {
|
|
563
980
|
const result = rest.shift();
|
|
564
981
|
if (result !== 'pass' && result !== 'fail') fail('loopwright: usage: verdict <pass|fail> --round <n>');
|
|
@@ -578,8 +995,9 @@ try {
|
|
|
578
995
|
);
|
|
579
996
|
}
|
|
580
997
|
delete state.awaitingUser;
|
|
581
|
-
note(state, 'verdict', `${result} round ${round}
|
|
998
|
+
note(state, 'verdict', `${result} round ${round}`, { slice: sliceFor(dir, state, 'review') });
|
|
582
999
|
writeState(dir, id, state);
|
|
1000
|
+
refreshTaskFile(join(dir, state.task), state);
|
|
583
1001
|
out(state.verdict);
|
|
584
1002
|
break;
|
|
585
1003
|
}
|
|
@@ -621,6 +1039,7 @@ try {
|
|
|
621
1039
|
state.awaitingUser = reason;
|
|
622
1040
|
note(state, 'await-user', reason);
|
|
623
1041
|
writeState(dir, id, state);
|
|
1042
|
+
refreshTaskFile(join(dir, state.task), state);
|
|
624
1043
|
out(state);
|
|
625
1044
|
break;
|
|
626
1045
|
}
|
|
@@ -629,6 +1048,7 @@ try {
|
|
|
629
1048
|
note(state, 'resume', state.awaitingUser ?? '');
|
|
630
1049
|
delete state.awaitingUser;
|
|
631
1050
|
writeState(dir, id, state);
|
|
1051
|
+
refreshTaskFile(join(dir, state.task), state);
|
|
632
1052
|
out(state);
|
|
633
1053
|
break;
|
|
634
1054
|
}
|
|
@@ -755,8 +1175,7 @@ try {
|
|
|
755
1175
|
fail(`loopwright: worktree: ${stubFlag} is not a proposed stub`);
|
|
756
1176
|
}
|
|
757
1177
|
let goal = '';
|
|
758
|
-
|
|
759
|
-
if (!source && !isatty(0)) goal = readFileSync(0, 'utf8').trim();
|
|
1178
|
+
if (!source) goal = readInput().trim();
|
|
760
1179
|
let base = baseFlag;
|
|
761
1180
|
if (base !== undefined) {
|
|
762
1181
|
if (base.startsWith('-') || !refExists(base)) fail(`loopwright: worktree: unknown base '${base}'`);
|
|
@@ -765,11 +1184,7 @@ try {
|
|
|
765
1184
|
base = ['origin/HEAD', 'main', 'master'].find(refExists) ?? 'HEAD';
|
|
766
1185
|
}
|
|
767
1186
|
const main = mainWorktreeRoot(cwd);
|
|
768
|
-
const slug =
|
|
769
|
-
title
|
|
770
|
-
.toLowerCase()
|
|
771
|
-
.replace(/[^\p{L}\p{N}]+/gu, '-')
|
|
772
|
-
.replace(/^-+|-+$/g, '') || 'task';
|
|
1187
|
+
const slug = titleSlug(title);
|
|
773
1188
|
let name;
|
|
774
1189
|
let folder;
|
|
775
1190
|
for (let n = 1; ; n++) {
|
|
@@ -786,11 +1201,7 @@ try {
|
|
|
786
1201
|
copyFileSync(source, join(dir, stub));
|
|
787
1202
|
markMoved(source, join(dir, stub));
|
|
788
1203
|
} else {
|
|
789
|
-
stub = writeUnique(
|
|
790
|
-
dir,
|
|
791
|
-
stubBase(title),
|
|
792
|
-
stubText([`# ${title}`, '', `kind: ${kind}`, 'status: proposed', 'stage: plan', 'plan: draft'], goal),
|
|
793
|
-
);
|
|
1204
|
+
stub = writeUnique(dir, stubBase(title), stubText(title, kind, goal));
|
|
794
1205
|
}
|
|
795
1206
|
const hook = join('.agents', 'loopwright', 'hooks', 'lw.mjs');
|
|
796
1207
|
out({
|
|
@@ -923,26 +1334,16 @@ try {
|
|
|
923
1334
|
const foundWhile = active && existsSync(join(dir, active)) ? active : null;
|
|
924
1335
|
if (active && !foundWhile)
|
|
925
1336
|
process.stderr.write(`loopwright: warning: active task file ${active} is missing; follow-up not linked\n`);
|
|
926
|
-
const
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
if (!m) next = body.replace(/\n*$/, '\n') + `\n## Follow-ups\n${line}\n`;
|
|
937
|
-
else {
|
|
938
|
-
const start = m.index + m[0].length;
|
|
939
|
-
const end = body.slice(start).search(/^## /m);
|
|
940
|
-
const stop = end === -1 ? body.length : start + end;
|
|
941
|
-
const section = body.slice(start, stop).replace(/\s*$/, '');
|
|
942
|
-
next = body.slice(0, start) + section + `\n${line}\n` + (end === -1 ? '' : '\n') + body.slice(stop);
|
|
943
|
-
}
|
|
944
|
-
writeFileSync(file, next);
|
|
945
|
-
}
|
|
1337
|
+
const links = {
|
|
1338
|
+
...(foundWhile && { 'found while': foundWhile }),
|
|
1339
|
+
...(blocks && foundWhile && { blocks: foundWhile }),
|
|
1340
|
+
};
|
|
1341
|
+
const stub = writeUnique(dir, stubBase(title), stubText(title, kind, '', links));
|
|
1342
|
+
if (foundWhile)
|
|
1343
|
+
rewriteTask(
|
|
1344
|
+
join(dir, foundWhile),
|
|
1345
|
+
(t) => addEntry(t, 'followup', {}, [`${title} — ${stub}${blocks ? ' [blocking]' : ''}`]).text,
|
|
1346
|
+
);
|
|
946
1347
|
out({ stub, foundWhile, blocks: Boolean(blocks && foundWhile) });
|
|
947
1348
|
break;
|
|
948
1349
|
}
|
|
@@ -1047,13 +1448,14 @@ try {
|
|
|
1047
1448
|
state.stage = 'done';
|
|
1048
1449
|
note(state, 'done', state.task);
|
|
1049
1450
|
writeState(dir, id, state);
|
|
1451
|
+
refreshTaskFile(join(dir, state.task), state);
|
|
1050
1452
|
unlinkSync(statePath(dir, id));
|
|
1051
1453
|
out(state);
|
|
1052
1454
|
break;
|
|
1053
1455
|
}
|
|
1054
1456
|
default:
|
|
1055
1457
|
fail(
|
|
1056
|
-
'loopwright: usage: lw.mjs <dir|start|stage|reopen|lock|check-locks|accept-locks|keep-base|fingerprint|verdict|review-diff|await-user|resume|park|explore|status|config|brief|tasks|adopt|worktree|carry|effort|done>',
|
|
1458
|
+
'loopwright: usage: lw.mjs <dir|start|set|add|mark|edit|section|stage|reopen|lock|check-locks|accept-locks|keep-base|fingerprint|commit|branch|verdict|review-diff|await-user|resume|park|explore|status|config|brief|tasks|adopt|worktree|carry|effort|done>',
|
|
1057
1459
|
);
|
|
1058
1460
|
}
|
|
1059
1461
|
} catch (err) {
|