@warren-dean/code-kit 0.33.0 → 0.34.0
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/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/CHANGELOG.md +15 -0
- package/README.md +36 -34
- package/bin/code-kit.mjs +2 -0
- package/hooks/guard-bash.mjs +52 -6
- package/hooks/lib/checkout.mjs +38 -3
- package/hooks/lib/harness.mjs +15 -0
- package/hooks/lib/instructions.mjs +4 -2
- package/hooks/lib/next.mjs +6 -0
- package/hooks/lib/plan.mjs +8 -2
- package/hooks/lib/shell.mjs +13 -4
- package/hooks/mod/board.mjs +2 -0
- package/hooks/mod/loop.mjs +66 -3
- package/hooks/mod/register.mjs +202 -4
- package/hooks/mod/view.mjs +17 -1
- package/package.json +1 -1
package/hooks/lib/checkout.mjs
CHANGED
|
@@ -7,7 +7,9 @@
|
|
|
7
7
|
// project's installs in and deleting them again on every merge is millions of files each time, which
|
|
8
8
|
// keeps the machine's file-change tracking and search indexing busy. Each run checks out the tree it
|
|
9
9
|
// needs, and installs again only where its manifests and lockfiles differ from the ones the kept
|
|
10
|
-
// installs were made for. The folder's name ends in .noindex, which Spotlight leaves alone.
|
|
10
|
+
// installs were made for. The folder's name ends in .noindex, which Spotlight leaves alone. The OS
|
|
11
|
+
// empties old files out of its temporary folder and leaves the folders and links, so a run counts the
|
|
12
|
+
// kept installs' files, and copies them again when any have gone.
|
|
11
13
|
import { createHash } from 'node:crypto';
|
|
12
14
|
import { execFileSync, spawnSync } from 'node:child_process';
|
|
13
15
|
import {
|
|
@@ -16,6 +18,7 @@ import {
|
|
|
16
18
|
mkdirSync,
|
|
17
19
|
mkdtempSync,
|
|
18
20
|
openSync,
|
|
21
|
+
readdirSync,
|
|
19
22
|
readFileSync,
|
|
20
23
|
realpathSync,
|
|
21
24
|
rmSync,
|
|
@@ -106,6 +109,26 @@ function dependencyHashes(dir) {
|
|
|
106
109
|
return hashes;
|
|
107
110
|
}
|
|
108
111
|
|
|
112
|
+
// The files in a kept checkout's installs, and how many there were when they were made. Tools' caches
|
|
113
|
+
// come and go on their own, so they don't count. A folder that can't be read counts as empty.
|
|
114
|
+
const countOf = (dir) => `${dir}.installs.count`;
|
|
115
|
+
function installedFiles(dir) {
|
|
116
|
+
let files = 0;
|
|
117
|
+
for (const rel of installsOf(dir)) {
|
|
118
|
+
try {
|
|
119
|
+
for (const e of readdirSync(join(dir, rel), { recursive: true, withFileTypes: true }))
|
|
120
|
+
if (e.isFile() && !/[\\/]\.cache(?:[\\/]|$)/.test(e.parentPath)) files++;
|
|
121
|
+
} catch {
|
|
122
|
+
// gone while being read: fewer files, so it's copied again
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return files;
|
|
126
|
+
}
|
|
127
|
+
const recordInstalled = (dir) => writeFileSync(countOf(dir), String(installedFiles(dir)));
|
|
128
|
+
/** Whether a kept checkout's installs have lost files, or lost the records of what they were made for. */
|
|
129
|
+
const hollow = (dir) =>
|
|
130
|
+
!existsSync(stampOf(dir)) || !(installedFiles(dir) >= Number(readFileSafe(countOf(dir)) || NaN));
|
|
131
|
+
|
|
109
132
|
/** Takes the kept checkout's lock for this process, or false while another live process holds it. */
|
|
110
133
|
function lock(slot) {
|
|
111
134
|
const file = `${slot}.lock`;
|
|
@@ -243,10 +266,19 @@ export function freshCheckout(
|
|
|
243
266
|
throw Object.assign(new Error(why || 'the merge conflicts'), { conflict: true });
|
|
244
267
|
}
|
|
245
268
|
}
|
|
269
|
+
// MQ-9: the OS took files out of the kept installs: they can't be trusted, so they're copied again.
|
|
270
|
+
// What they're copied from may be behind the base by now, so the stamp names nothing, and the
|
|
271
|
+
// project's install runs over the copy for this tree.
|
|
272
|
+
const emptied = installsFrom && dir === slot && installsOf(dir).length > 0 && hollow(dir);
|
|
273
|
+
if (emptied)
|
|
274
|
+
for (const rel of installsOf(dir)) rmSync(join(dir, rel), { recursive: true, force: true });
|
|
246
275
|
if (installsFrom && !installsOf(dir).length) {
|
|
247
276
|
copyInstalls(installsFrom, dir);
|
|
248
277
|
// The copied installs were made for installsFrom's manifests and lockfiles.
|
|
249
|
-
if (dir === slot)
|
|
278
|
+
if (dir === slot) {
|
|
279
|
+
writeFileSync(stampOf(dir), JSON.stringify(emptied ? {} : dependencyHashes(installsFrom)));
|
|
280
|
+
recordInstalled(dir);
|
|
281
|
+
}
|
|
250
282
|
}
|
|
251
283
|
return { dir, remove };
|
|
252
284
|
}
|
|
@@ -351,7 +383,10 @@ export function matchInstalls(dir, from, { prepare = null, timeout = 900000 } =
|
|
|
351
383
|
const stamp = stampOf(dir);
|
|
352
384
|
if (res.status === 0) {
|
|
353
385
|
// A kept checkout's installs now match this tree.
|
|
354
|
-
if (existsSync(stamp))
|
|
386
|
+
if (existsSync(stamp)) {
|
|
387
|
+
writeFileSync(stamp, JSON.stringify(dependencyHashes(dir)));
|
|
388
|
+
recordInstalled(dir);
|
|
389
|
+
}
|
|
355
390
|
return { ...facts, command, failed: null };
|
|
356
391
|
}
|
|
357
392
|
// What a failed install left can't be trusted: the next run copies the installs afresh.
|
package/hooks/lib/harness.mjs
CHANGED
|
@@ -28,6 +28,21 @@ export const SETTINGS = {
|
|
|
28
28
|
about:
|
|
29
29
|
"How the lead loop acts: on its own, by proposing each step, or not at all; vibe is on its own with every decision the lead's, and you only asked for accounts, keys and payments",
|
|
30
30
|
},
|
|
31
|
+
'loop.quietMinutes': {
|
|
32
|
+
default: 10,
|
|
33
|
+
problem: (v) =>
|
|
34
|
+
Number.isFinite(v) && v >= 0 && v <= 120
|
|
35
|
+
? null
|
|
36
|
+
: 'must be a number of minutes from 0 (off) to 120',
|
|
37
|
+
about:
|
|
38
|
+
"How long the loop waits after you last spoke, while you're talking with the lead about something other than the build; 0 for not at all",
|
|
39
|
+
},
|
|
40
|
+
'loop.check': {
|
|
41
|
+
default: true,
|
|
42
|
+
problem: (v) => (typeof v === 'boolean' ? null : 'must be true or false'),
|
|
43
|
+
about:
|
|
44
|
+
"Check each step against the project as it is now (git, the queue, the agents at work, the lead's last replies) before the lead is prompted with it",
|
|
45
|
+
},
|
|
31
46
|
'hold.minutes': {
|
|
32
47
|
default: 2,
|
|
33
48
|
problem: (v) =>
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
import { registerFile } from './costs.mjs';
|
|
16
16
|
|
|
17
17
|
/** The version of code-kit's instructions: raised whenever the templates' rules change. */
|
|
18
|
-
export const INSTRUCTIONS_VERSION =
|
|
18
|
+
export const INSTRUCTIONS_VERSION = 13;
|
|
19
19
|
|
|
20
20
|
const TEMPLATES = fileURLToPath(new URL('../../templates/', import.meta.url));
|
|
21
21
|
const BEGIN = (v) => `<!-- code-kit:begin v${v} -->`;
|
|
@@ -111,12 +111,14 @@ const AGENT_LEGACY = /^Always:\s*$/;
|
|
|
111
111
|
|
|
112
112
|
/**
|
|
113
113
|
* Where a file's code-kit part stands: `current`; `stale` (marked, from an older code-kit or an older
|
|
114
|
-
* config); `
|
|
114
|
+
* config); `ahead` (marked by a newer code-kit than this one, as when a teammate has updated: never
|
|
115
|
+
* written back to this one's older rules); `legacy` (written before the markers, often tailored by hand, so merged once by the lead, not
|
|
115
116
|
* overwritten); or `missing` (none yet).
|
|
116
117
|
*/
|
|
117
118
|
function stateOf(text, block, legacy) {
|
|
118
119
|
const m = MARKED.exec(text);
|
|
119
120
|
// A formatter that rewraps the project's markdown doesn't make code-kit's part out of date.
|
|
121
|
+
if (m && Number(m[1]) > INSTRUCTIONS_VERSION) return { state: 'ahead', version: Number(m[1]) };
|
|
120
122
|
if (m) return { state: same(m[0], block) ? 'current' : 'stale', version: Number(m[1]) };
|
|
121
123
|
if (text.split('\n').some((l) => legacy.test(l))) return { state: 'legacy', version: 0 };
|
|
122
124
|
return { state: 'missing', version: null };
|
package/hooks/lib/next.mjs
CHANGED
|
@@ -437,6 +437,12 @@ export function nextStep(root, base) {
|
|
|
437
437
|
attention.push(
|
|
438
438
|
`${none.map((f) => f.file).join(', ')} ${none.length === 1 ? 'has' : 'have'} none of code-kit's instructions; \`code-kit instructions --write\` adds them.`,
|
|
439
439
|
);
|
|
440
|
+
// Newer than this code-kit: a teammate updated first. The session's own code-kit is what's behind.
|
|
441
|
+
const ahead = instructions.filter((f) => f.state === 'ahead');
|
|
442
|
+
if (ahead.length)
|
|
443
|
+
attention.push(
|
|
444
|
+
`code-kit's instructions in ${ahead.map((f) => f.file).join(', ')} come from a newer code-kit than this session's: don't write them back. Run /plugin marketplace update code-kit and restart Claude Code.`,
|
|
445
|
+
);
|
|
440
446
|
if (behind.length) {
|
|
441
447
|
const legacy = behind.filter((f) => f.state === 'legacy');
|
|
442
448
|
return result(
|
package/hooks/lib/plan.mjs
CHANGED
|
@@ -9,6 +9,7 @@ import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';
|
|
|
9
9
|
import { isAbsolute, join } from 'node:path';
|
|
10
10
|
import { readEvents } from './events.mjs';
|
|
11
11
|
import { laneClaims } from './laneclaims.mjs';
|
|
12
|
+
import { readQueue, waiting } from './queue.mjs';
|
|
12
13
|
import { waitingStories } from './questions.mjs';
|
|
13
14
|
import { sentBack } from './reviews.mjs';
|
|
14
15
|
import { isTestFile } from './testfiles.mjs';
|
|
@@ -405,7 +406,7 @@ function worktrees(root) {
|
|
|
405
406
|
/**
|
|
406
407
|
* Where each story is. The plan's `done` stands (the lead marks it after merging, and merged
|
|
407
408
|
* branches are often deleted or squashed). Otherwise git decides: a branch with commits not in
|
|
408
|
-
* `base` is in review. A branch still at the commit a review sent back is `sent back`, waiting for
|
|
409
|
+
* `base` is in review. A branch with commits ahead, still at the commit a review sent back, is `sent back`, waiting for
|
|
409
410
|
* its lane's fix. Without a branch, the plan's status stands. A story is `blocked` while a story it
|
|
410
411
|
* depends on isn't done, whatever its branch holds; a todo story whose dependencies are done is `ready`.
|
|
411
412
|
* A story with an open question for the person that holds it (`code-kit ask --blocks`) is `waiting on
|
|
@@ -426,6 +427,10 @@ function worktrees(root) {
|
|
|
426
427
|
export function storyStates(root, stories, base, { designing = null } = {}) {
|
|
427
428
|
const trees = worktrees(root);
|
|
428
429
|
const backs = sentBack(root);
|
|
430
|
+
// Queued again since its send-back, at that same commit: a review passed it, and it waits to merge.
|
|
431
|
+
const queued = waiting(readQueue(root));
|
|
432
|
+
const requeued = (branch, back) =>
|
|
433
|
+
queued.some((e) => e.branch === branch && e.commit === back.sha && e.passed > back.at);
|
|
429
434
|
const refs = branchRefs(root, base);
|
|
430
435
|
const claims = laneClaims(root).filter((c) => !c.stale);
|
|
431
436
|
const live = new Set(claims.map((c) => `${c.lane}|${c.story ?? ''}`));
|
|
@@ -464,7 +469,8 @@ export function storyStates(root, stories, base, { designing = null } = {}) {
|
|
|
464
469
|
let stopped = false;
|
|
465
470
|
if (ref && !['done', DROPPED].includes(story.status)) {
|
|
466
471
|
const head = backs[branch] ? refs[ref].sha : null;
|
|
467
|
-
if (head && head === backs[branch].sha
|
|
472
|
+
if (ahead > 0 && head && head === backs[branch].sha && !requeued(branch, backs[branch]))
|
|
473
|
+
state = 'sent back';
|
|
468
474
|
else if (ahead > 0)
|
|
469
475
|
state =
|
|
470
476
|
building(story) || (story.lane === DESIGN && designing?.(story, ref))
|
package/hooks/lib/shell.mjs
CHANGED
|
@@ -275,10 +275,18 @@ export function readsOnly(cmd) {
|
|
|
275
275
|
);
|
|
276
276
|
}
|
|
277
277
|
|
|
278
|
-
// What could change what a later command in the line runs: a function or alias defined, a
|
|
279
|
-
//
|
|
278
|
+
// What could change what a later command in the line runs: a function or alias defined, a file sourced,
|
|
279
|
+
// a shell option, a variable exported, or one the shell or a command reads (PATH among them).
|
|
280
280
|
const REDEFINES =
|
|
281
|
-
/(?:^|[;&|\n(]\s*)(?:[\w.-]+\s*\(\s*\)|function\s|alias\s|unalias\s|source\s|\.\s|hash\s|enable\s|builtin\s|set\s|setopt\s|shopt\s|unset\s|export\s|typeset\s|declare\s|local\s|readonly\s
|
|
281
|
+
/(?:^|[;&|\n(]\s*)(?:[\w.-]+\s*\(\s*\)|function\s|alias\s|unalias\s|source\s|\.\s|hash\s|enable\s|builtin\s|set\s|setopt\s|shopt\s|unset\s|export\s|typeset\s|declare\s|local\s|readonly\s)/;
|
|
282
|
+
const SHELL_READS =
|
|
283
|
+
/^(?:PATH|path|FPATH|fpath|CDPATH|cdpath|IFS|ENV|BASH_ENV|ZDOTDIR|HOME|LD_\w*|DYLD_\w*|GIT_\w*|XDG_\w*)$/;
|
|
284
|
+
// Any other variable set in the line (`CK=…/code-kit.mjs`) stays in the shell: no command it runs sees
|
|
285
|
+
// it, unless it was exported already, and what names it is judged on its own.
|
|
286
|
+
const setsWhatRuns = (code) =>
|
|
287
|
+
[...code.matchAll(/(?:^|[;&|\n(]\s*)([A-Za-z_]\w*)(?:\[[^\]]*\])?\+?=/g)].some(
|
|
288
|
+
([, name]) => SHELL_READS.test(name) || name in process.env,
|
|
289
|
+
);
|
|
282
290
|
|
|
283
291
|
/**
|
|
284
292
|
* The parts of `cmd` that name `pattern`, each a pipeline (`a | b`) of its own, that don't only read
|
|
@@ -289,7 +297,8 @@ export function unreadNames(cmd, pattern) {
|
|
|
289
297
|
const read = withoutHarmlessRedirects(cmd);
|
|
290
298
|
const code = codeOf(read);
|
|
291
299
|
if (!pattern.test(cmd)) return [];
|
|
292
|
-
if (/<</.test(cmd) || REDEFINES.test(code)
|
|
300
|
+
if (/<</.test(cmd) || REDEFINES.test(code) || setsWhatRuns(code))
|
|
301
|
+
return readsOnly(cmd) ? [] : [cmd];
|
|
293
302
|
const text = withoutHeredocs(read);
|
|
294
303
|
const parts = [];
|
|
295
304
|
let start = 0;
|
package/hooks/mod/board.mjs
CHANGED
package/hooks/mod/loop.mjs
CHANGED
|
@@ -113,6 +113,13 @@ export function storiesSignature(ids, stories = [], heads = new Map(), inFlight
|
|
|
113
113
|
.join('|');
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
+
/**
|
|
117
|
+
* LOOP-15: what the lead is told about stories it was asked about before, that waited the park's half
|
|
118
|
+
* hour with nothing they watch moving.
|
|
119
|
+
*/
|
|
120
|
+
export const holdHint = (ids, { cli = 'code-kit' } = {}) =>
|
|
121
|
+
`${ids.join(', ')} ${ids.length === 1 ? 'was' : 'were'} left half an hour ago with nothing ${ids.length === 1 ? 'it waits' : 'they wait'} on moving since. If ${ids.length === 1 ? 'it waits' : 'they wait'} on a date or on something outside the build, hold ${ids.length === 1 ? 'it' : 'each'} instead, so the loop stops asking: node "${cli}" defer ${ids[0]} --reason "<what it waits on>" [--until <date>].`;
|
|
122
|
+
|
|
116
123
|
/** The story ids a step names, upper-cased: `review ST-158 ST-172` gives ST-158 and ST-172. */
|
|
117
124
|
export const stepStories = (step) =>
|
|
118
125
|
STORY_STEPS.has(step?.stepKind ?? step?.kind ?? step?.step)
|
|
@@ -260,25 +267,37 @@ const ANSWER_SHOWN = 4000;
|
|
|
260
267
|
* lead's own conversation (so it knows the whole exchange), with the reply itself for a call that
|
|
261
268
|
* can't fork. `prompt` is the loop's own prompt for that turn, or null when the person started it.
|
|
262
269
|
*/
|
|
263
|
-
export function outcomePrompt({ prompt = null, answer = '' }) {
|
|
270
|
+
export function outcomePrompt({ prompt = null, answer = '', said = null }) {
|
|
264
271
|
const reply = String(answer ?? '').trim();
|
|
265
272
|
const shown =
|
|
266
273
|
reply.length > ANSWER_SHOWN ? `${reply.slice(0, ANSWER_SHOWN)}\n[… cut short]` : reply;
|
|
274
|
+
const person = !prompt && String(said ?? '').trim() ? clip(String(said).trim()) : null;
|
|
267
275
|
return [
|
|
268
276
|
prompt
|
|
269
277
|
? `code-kit's lead loop prompted you: "${prompt}"`
|
|
270
|
-
:
|
|
278
|
+
: person
|
|
279
|
+
? `The person prompted you:\n"""\n${person}\n"""\ncode-kit's lead loop is about to prompt you with the build's next step.`
|
|
280
|
+
: "The person prompted you, and code-kit's lead loop is about to prompt you with the build's next step.",
|
|
271
281
|
`Your reply ended your turn. It read:\n"""\n${shown}\n"""`,
|
|
272
282
|
'Say where that reply left things, so the loop knows whether to prompt you again. Answer with one JSON object and nothing else:',
|
|
273
|
-
|
|
283
|
+
`{"outcome": "done" | "started" | "needs-person" | "blocked" | "waiting", "question": "…", "options": [{"label": "…", "effect": "…"}], "reason": "…", "waits": [{"story": "ST-n", "on": ["ST-n"], "why": "…"}]${person ? ', "talk": "build" | "conversation"' : ''}}`,
|
|
274
284
|
'- done: you finished what was asked, or there was nothing to do.',
|
|
275
285
|
'- started: you started work that carries on without you, such as lane agents.',
|
|
276
286
|
"- needs-person: you asked the person something, or wait on their answer, approval or feedback before you go on. question: what you wait on, as one question; options: 2 to 4 answers they could give (a label of at most five words, and what it does), or [] when it's theirs to put in words.",
|
|
277
287
|
"- waiting: the step isn't due yet for some or all of its stories: they wait on other work still going (a lane building a story they merge with, a rebuild, a check running). waits: one entry per story that waits, with the stories it waits on (their ST ids, [] when it's other work) and why, in a few words. Use this, not done, when you said a story can't be taken yet.",
|
|
278
288
|
"- blocked: you didn't take the step, for a reason no answer from the person settles now and no work in flight will change. reason: why, in a sentence.",
|
|
289
|
+
...(person
|
|
290
|
+
? [
|
|
291
|
+
"- talk (LOOP-16): build when the person asked you to carry on with the build or to do its work; conversation when they're talking with you about something else (a question, a discussion, another task) or said not to build now, so a prompt from the loop would cut in.",
|
|
292
|
+
]
|
|
293
|
+
: []),
|
|
279
294
|
].join('\n');
|
|
280
295
|
}
|
|
281
296
|
|
|
297
|
+
/** A text cut to what a side call is shown. */
|
|
298
|
+
const clip = (text) =>
|
|
299
|
+
text.length > ANSWER_SHOWN ? `${text.slice(0, ANSWER_SHOWN)}\n[… cut short]` : text;
|
|
300
|
+
|
|
282
301
|
/**
|
|
283
302
|
* LOOP-11: the side call's answer: { outcome, question, options: [{ label, effect }], reason }, or
|
|
284
303
|
* null when it isn't one (the loop then goes on as before).
|
|
@@ -314,9 +333,53 @@ export function readOutcome(text) {
|
|
|
314
333
|
options: options.length >= 2 ? options : [],
|
|
315
334
|
reason: words(parsed.reason, 300),
|
|
316
335
|
waits,
|
|
336
|
+
talk: ['build', 'conversation'].includes(parsed.talk) ? parsed.talk : null,
|
|
317
337
|
};
|
|
318
338
|
}
|
|
319
339
|
|
|
340
|
+
/** LOOP-16: the band's words while the person talks with the lead. */
|
|
341
|
+
export const talkingText = (minutes) =>
|
|
342
|
+
`You're talking with the lead: the loop waits until you've been quiet for ${minutes} minute${minutes === 1 ? '' : 's'}`;
|
|
343
|
+
|
|
344
|
+
/** LOOP-17: the steps checked against the project before the lead is prompted (a design is the person's). */
|
|
345
|
+
export const CHECKED_STEPS = new Set([...LEAD_STEPS].filter((s) => s !== 'design'));
|
|
346
|
+
|
|
347
|
+
/** LOOP-17: how long a step judged not due waits before it's checked again, with the project moving. */
|
|
348
|
+
export const RECHECK_MS = 5 * 60_000;
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* LOOP-17: the side call that checks a step against the project as it is now, before the lead is
|
|
352
|
+
* prompted with it. `facts` is what the mod read itself: the step's stories and branches, the merge
|
|
353
|
+
* queue, the agents at work, the base's and this checkout's latest commits, and the lead's last replies.
|
|
354
|
+
*/
|
|
355
|
+
export function checkPrompt({ prompt, facts }) {
|
|
356
|
+
return [
|
|
357
|
+
`code-kit's lead loop is about to prompt the lead: "${prompt}"`,
|
|
358
|
+
"The loop's step comes from code-kit's records, which can lag the work: a story already merged or committed, work already under way in an agent or a background run, or a step the lead already said why it won't take. Judge from the project as it is now, below, whether prompting the lead is still useful.",
|
|
359
|
+
`The project now:\n"""\n${clip(String(facts ?? '').trim())}\n"""`,
|
|
360
|
+
'Answer with one JSON object and nothing else: {"due": true | false, "why": "…"}',
|
|
361
|
+
'- due false: the step is done already (its branch merged, its change on the base or this checkout), its work is under way (an agent at work on it, or the lead said a run is going and nothing since shows it finished), or the lead said why it is not taking the step and nothing it named has changed since. why: what shows it, in one sentence.',
|
|
362
|
+
'- due true: none of that shows; when unsure, due. why: what makes it due, in a few words.',
|
|
363
|
+
].join('\n');
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/** LOOP-17: the check's answer: { due, why }, or null when it isn't one (the step is then prompted). */
|
|
367
|
+
export function readCheck(text) {
|
|
368
|
+
const raw = String(text ?? '');
|
|
369
|
+
let parsed;
|
|
370
|
+
try {
|
|
371
|
+
parsed = JSON.parse(raw.slice(raw.indexOf('{'), raw.lastIndexOf('}') + 1));
|
|
372
|
+
} catch {
|
|
373
|
+
return null;
|
|
374
|
+
}
|
|
375
|
+
if (typeof parsed?.due !== 'boolean') return null;
|
|
376
|
+
const why =
|
|
377
|
+
typeof parsed.why === 'string' && parsed.why.trim()
|
|
378
|
+
? parsed.why.replace(/\s+/g, ' ').trim().slice(0, 300)
|
|
379
|
+
: null;
|
|
380
|
+
return { due: parsed.due, why };
|
|
381
|
+
}
|
|
382
|
+
|
|
320
383
|
/**
|
|
321
384
|
* LOOP-12: a design is made with the person, so the loop hands a design story to the lead once; while
|
|
322
385
|
* the stories `next` names have all been handed over, it leaves them to the person and the lead.
|