@warren-dean/code-kit 0.26.1 → 0.27.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 +24 -0
- package/README.md +5 -3
- package/bin/code-kit.mjs +269 -52
- package/hooks/act.mjs +14 -5
- package/hooks/guard-bash.mjs +76 -17
- package/hooks/lib/checkout.mjs +105 -0
- package/hooks/lib/checks.mjs +34 -8
- package/hooks/lib/config.mjs +5 -2
- package/hooks/lib/dependencies.mjs +4 -0
- package/hooks/lib/designs.mjs +137 -0
- package/hooks/lib/events.mjs +9 -4
- package/hooks/lib/hook.mjs +41 -1
- package/hooks/lib/next.mjs +33 -5
- package/hooks/lib/plan.mjs +103 -15
- package/hooks/lib/queue.mjs +86 -1
- package/hooks/lib/regression.mjs +54 -44
- package/hooks/lib/rules.mjs +63 -20
- package/hooks/lib/team.mjs +27 -1
- package/hooks/lib/timeline.mjs +3 -20
- package/hooks/lib/verify.mjs +37 -4
- package/hooks/lib/worktrees.mjs +18 -1
- package/hooks/mod/board.mjs +54 -59
- package/hooks/mod/characters.mjs +96 -174
- package/hooks/mod/loop.mjs +44 -1
- package/hooks/mod/register.mjs +96 -8
- package/hooks/mod/surface/character.mjs +1 -1
- package/hooks/mod/view.mjs +8 -0
- package/hooks/stop-check.mjs +6 -1
- package/package.json +1 -1
- package/skills/design/SKILL.md +36 -7
- package/skills/dispatch/SKILL.md +1 -0
- package/skills/review/SKILL.md +2 -1
- package/skills/spec-design/SKILL.md +1 -1
- package/skills/status/SKILL.md +1 -1
- package/templates/agent.md +2 -1
package/hooks/mod/characters.mjs
CHANGED
|
@@ -1,76 +1,24 @@
|
|
|
1
|
-
// The lane agents' characters, redrawn (docs/specs/27-the-mod-redesigned.md, UI-11):
|
|
1
|
+
// The lane agents' characters, redrawn (docs/specs/27-the-mod-redesigned.md, UI-11): 8 by 8
|
|
2
2
|
// pixels, each lane its own shape as well as its tint so lanes read apart without colour, the lead's
|
|
3
3
|
// crowned. A pose is the agent's state or the kind of work it's doing; a move is a one-off at an
|
|
4
4
|
// event. Every frame is composed from layers (a head by shape, a face, a body, a prop), so each
|
|
5
5
|
// shape gets every pose. Pure: the mod draws the grids as half-block cells or SVG.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
/** Pixels a side: four terminal rows of half-blocks, eight columns. */
|
|
8
|
+
export const SIZE = 8;
|
|
8
9
|
|
|
9
|
-
/**
|
|
10
|
+
/**
|
|
11
|
+
* Each head, rows 0 to 3, the face in columns 1 to 5 (row 0 what's on top of it): H the tint, D its
|
|
12
|
+
* shade, K gold.
|
|
13
|
+
*/
|
|
10
14
|
const HEADS = {
|
|
11
|
-
crown: [
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
'....HHHH....',
|
|
19
|
-
],
|
|
20
|
-
antenna: [
|
|
21
|
-
'......K.....',
|
|
22
|
-
'......D.....',
|
|
23
|
-
'...HHHHHH...',
|
|
24
|
-
'...HHHHHH...',
|
|
25
|
-
'...HHHHHH...',
|
|
26
|
-
'...HHHHHH...',
|
|
27
|
-
'...HHHHHH...',
|
|
28
|
-
],
|
|
29
|
-
cat: [
|
|
30
|
-
'............',
|
|
31
|
-
'...D....D...',
|
|
32
|
-
'...HD..DH...',
|
|
33
|
-
'...HHHHHH...',
|
|
34
|
-
'...HHHHHH...',
|
|
35
|
-
'...HHHHHH...',
|
|
36
|
-
'....HHHH....',
|
|
37
|
-
],
|
|
38
|
-
cap: [
|
|
39
|
-
'............',
|
|
40
|
-
'...DDDDDD...',
|
|
41
|
-
'...DDDDDDDD.',
|
|
42
|
-
'...HHHHHH...',
|
|
43
|
-
'...HHHHHH...',
|
|
44
|
-
'...HHHHHH...',
|
|
45
|
-
'....HHHH....',
|
|
46
|
-
],
|
|
47
|
-
bunny: [
|
|
48
|
-
'....D..D....',
|
|
49
|
-
'....D..D....',
|
|
50
|
-
'....HHHH....',
|
|
51
|
-
'...HHHHHH...',
|
|
52
|
-
'...HHHHHH...',
|
|
53
|
-
'...HHHHHH...',
|
|
54
|
-
'....HHHH....',
|
|
55
|
-
],
|
|
56
|
-
bolts: [
|
|
57
|
-
'............',
|
|
58
|
-
'............',
|
|
59
|
-
'...HHHHHH...',
|
|
60
|
-
'..DHHHHHHD..',
|
|
61
|
-
'..DHHHHHHD..',
|
|
62
|
-
'...HHHHHH...',
|
|
63
|
-
'...DDDDDD...',
|
|
64
|
-
],
|
|
65
|
-
wizard: [
|
|
66
|
-
'.....DD.....',
|
|
67
|
-
'....DDDD....',
|
|
68
|
-
'..DDDDDDDD..',
|
|
69
|
-
'...HHHHHH...',
|
|
70
|
-
'...HHHHHH...',
|
|
71
|
-
'...HHHHHH...',
|
|
72
|
-
'....HHHH....',
|
|
73
|
-
],
|
|
15
|
+
crown: ['.K.K.K..', '.KKKKK..', '.HHHHH..', '.HHHHH..'],
|
|
16
|
+
antenna: ['...K....', '.HHHHH..', '.HHHHH..', '.HHHHH..'],
|
|
17
|
+
cat: ['.D...D..', '.DHHHD..', '.HHHHH..', '.HHHHH..'],
|
|
18
|
+
cap: ['.DDDD...', '.DDDDDD.', '.HHHHH..', '.HHHHH..'],
|
|
19
|
+
bunny: ['..D.D...', '..D.D...', '.HHHHH..', '.HHHHH..'],
|
|
20
|
+
bolts: ['........', '.HHHHH..', 'DHHHHHD.', '.DDDDD..'],
|
|
21
|
+
wizard: ['...D....', 'DDDDDDD.', '.HHHHH..', '.HHHHH..'],
|
|
74
22
|
};
|
|
75
23
|
/** The lanes' shapes, tints and marks: six shapes first, then a mark on each, so lanes differ without colour. */
|
|
76
24
|
const SHAPES = ['antenna', 'cat', 'cap', 'bunny', 'bolts', 'wizard'];
|
|
@@ -129,8 +77,9 @@ export function characterOf(lane, lanes) {
|
|
|
129
77
|
return charactersOf(lanes.includes(lane) ? lanes : [...lanes, lane])[lane];
|
|
130
78
|
}
|
|
131
79
|
|
|
132
|
-
/** The body, rows
|
|
133
|
-
const BODY = ['
|
|
80
|
+
/** The body, rows 4 to 7: a neck, arms out in columns 1 and 5, legs. */
|
|
81
|
+
const BODY = ['..DDD...', '.HHHHH..', '..HHH...', '..H.H...'];
|
|
82
|
+
const BODY_TOP = 4;
|
|
134
83
|
|
|
135
84
|
/** Each pose and move: its frames, how long each shows, and whether it loops. */
|
|
136
85
|
export const POSES = {
|
|
@@ -174,118 +123,95 @@ const put = (grid, points, ch) => {
|
|
|
174
123
|
};
|
|
175
124
|
const clear = (grid, points) => put(grid, points, '.');
|
|
176
125
|
|
|
177
|
-
/** The eyes and mouth: where the eyes look, and the face's mood. */
|
|
126
|
+
/** The eyes and mouth: where the eyes look, and the face's mood. Eyes sit in columns 2 and 4. */
|
|
178
127
|
function face(grid, kind, dx = 0, dy = 0) {
|
|
179
128
|
const at = (points) => points.map(([y, x]) => [y + dy, x + dx]);
|
|
180
129
|
const eyes = {
|
|
181
130
|
open: [
|
|
182
|
-
[
|
|
183
|
-
[
|
|
131
|
+
[2, 2],
|
|
132
|
+
[2, 4],
|
|
184
133
|
],
|
|
185
134
|
down: [
|
|
186
|
-
[
|
|
187
|
-
[
|
|
135
|
+
[3, 2],
|
|
136
|
+
[3, 4],
|
|
188
137
|
],
|
|
189
138
|
up: [
|
|
190
|
-
[
|
|
191
|
-
[
|
|
139
|
+
[2, 1],
|
|
140
|
+
[2, 3],
|
|
192
141
|
],
|
|
193
142
|
scan: [
|
|
194
|
-
[
|
|
195
|
-
[
|
|
143
|
+
[3, 3],
|
|
144
|
+
[3, 5],
|
|
196
145
|
],
|
|
197
146
|
};
|
|
198
|
-
if (kind === 'closed') return put(grid, at(eyes.
|
|
147
|
+
if (kind === 'closed') return put(grid, at(eyes.down), 'L');
|
|
199
148
|
if (kind === 'crossed') return put(grid, at(eyes.open), 'X');
|
|
200
149
|
put(grid, at(eyes[kind] ?? eyes.open), 'E');
|
|
201
|
-
if (kind === 'happy')
|
|
202
|
-
put(
|
|
203
|
-
grid,
|
|
204
|
-
at([
|
|
205
|
-
[5, 5],
|
|
206
|
-
[5, 6],
|
|
207
|
-
]),
|
|
208
|
-
'E',
|
|
209
|
-
);
|
|
150
|
+
if (kind === 'happy') put(grid, at([[3, 3]]), 'E');
|
|
210
151
|
if (kind === 'oops') {
|
|
211
|
-
put(grid, at([[
|
|
212
|
-
put(grid, at([[
|
|
152
|
+
put(grid, at([[3, 3]]), 'E');
|
|
153
|
+
put(grid, at([[1, 6]]), 'B');
|
|
213
154
|
}
|
|
214
155
|
}
|
|
215
156
|
|
|
216
157
|
/** A lane's mark, worn in every pose: glasses round the eyes, a scarf at the neck, a belt. */
|
|
217
158
|
function wear(grid, mark, mood, dx = 0, dy = 0) {
|
|
218
159
|
const at = (points) => points.map(([y, x]) => [y + dy, x + dx]);
|
|
219
|
-
const eyes = mood === 'down' || mood === 'scan'
|
|
220
|
-
if (mark === 'glasses')
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
at([
|
|
224
|
-
[eyes, 3],
|
|
225
|
-
[eyes, 5],
|
|
226
|
-
[eyes, 6],
|
|
227
|
-
[eyes, 8],
|
|
228
|
-
]),
|
|
229
|
-
'P',
|
|
230
|
-
);
|
|
231
|
-
if (mark === 'scarf') put(grid, at([3, 4, 5, 6, 7, 8].map((x) => [7, x])), 'S');
|
|
232
|
-
if (mark === 'belt') put(grid, at([4, 5, 6, 7].map((x) => [9, x])), 'P');
|
|
160
|
+
const eyes = mood === 'down' || mood === 'scan' || mood === 'closed' ? 3 : 2;
|
|
161
|
+
if (mark === 'glasses') put(grid, at([1, 3, 5].map((x) => [eyes, x])), 'P');
|
|
162
|
+
if (mark === 'scarf') put(grid, at([1, 2, 3, 4, 5].map((x) => [4, x])), 'S');
|
|
163
|
+
if (mark === 'belt') put(grid, at([2, 3, 4].map((x) => [6, x])), 'P');
|
|
233
164
|
}
|
|
234
165
|
|
|
235
|
-
/** A frame as a grid of letters, before colour. */
|
|
166
|
+
/** A frame as a grid of letters, before colour. Props sit in columns 6 and 7. */
|
|
236
167
|
function compose({ shape, mark = null }, pose, frame) {
|
|
237
168
|
const g = blank();
|
|
238
169
|
const head = HEADS[shape] ?? HEADS.antenna;
|
|
239
170
|
const whole = (dx, dy, mood, body = BODY) => {
|
|
240
171
|
paint(g, head, { dx, dy });
|
|
241
|
-
paint(g, body, { top:
|
|
172
|
+
paint(g, body, { top: BODY_TOP, dx, dy });
|
|
242
173
|
face(g, mood, dx, dy);
|
|
243
174
|
wear(g, mark, mood, dx, dy);
|
|
244
175
|
};
|
|
245
176
|
const f = frame % (POSES[pose]?.frames ?? 1);
|
|
246
177
|
switch (pose) {
|
|
247
178
|
case 'writing': {
|
|
248
|
-
// At a sheet of paper on the right, the pencil moving and
|
|
179
|
+
// At a sheet of paper on the right, the pencil moving and a line filling.
|
|
249
180
|
whole(0, 0, 'down');
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
const tip = [9, 10, 11, 10][f];
|
|
253
|
-
put(g, [[9, tip]], 'K');
|
|
254
|
-
put(g, [[8, Math.min(11, tip + 1)]], 'P');
|
|
181
|
+
paint(g, ['WW', 'WW'], { top: 6, dx: 6 });
|
|
182
|
+
put(g, [[5, [6, 7, 7, 6][f]]], 'K');
|
|
255
183
|
put(
|
|
256
184
|
g,
|
|
257
185
|
[
|
|
258
|
-
[
|
|
259
|
-
[
|
|
260
|
-
|
|
261
|
-
].slice(0, f),
|
|
186
|
+
[6, 6],
|
|
187
|
+
[6, 7],
|
|
188
|
+
].slice(0, [0, 0, 1, 2][f]),
|
|
262
189
|
'E',
|
|
263
190
|
);
|
|
264
191
|
break;
|
|
265
192
|
}
|
|
266
193
|
case 'running': {
|
|
267
|
-
// Turning a crank on the
|
|
268
|
-
|
|
269
|
-
whole(0, bob, 'open');
|
|
194
|
+
// Turning a crank on the right, its bar spinning a quarter a frame, bobbing as it works.
|
|
195
|
+
whole(0, f % 2, 'open');
|
|
270
196
|
const spin = [
|
|
271
197
|
['.P.', '.K.', '.P.'],
|
|
272
198
|
['..P', '.K.', 'P..'],
|
|
273
199
|
['...', 'PKP', '...'],
|
|
274
200
|
['P..', '.K.', '..P'],
|
|
275
201
|
];
|
|
276
|
-
paint(g, spin[f], { top:
|
|
202
|
+
paint(g, spin[f], { top: 4, dx: 5 });
|
|
277
203
|
break;
|
|
278
204
|
}
|
|
279
205
|
case 'reading': {
|
|
280
206
|
// A book held open, eyes down, a page turning.
|
|
281
207
|
whole(0, 0, f === 1 ? 'scan' : 'down');
|
|
282
|
-
paint(g, ['
|
|
208
|
+
paint(g, ['WWDWW', 'WWDWW'], { top: 5, dx: 1 });
|
|
283
209
|
if (f === 2)
|
|
284
210
|
put(
|
|
285
211
|
g,
|
|
286
212
|
[
|
|
287
|
-
[
|
|
288
|
-
[
|
|
213
|
+
[4, 4],
|
|
214
|
+
[4, 5],
|
|
289
215
|
],
|
|
290
216
|
'W',
|
|
291
217
|
);
|
|
@@ -293,8 +219,8 @@ function compose({ shape, mark = null }, pose, frame) {
|
|
|
293
219
|
put(
|
|
294
220
|
g,
|
|
295
221
|
[
|
|
296
|
-
[
|
|
297
|
-
[
|
|
222
|
+
[4, 1],
|
|
223
|
+
[4, 2],
|
|
298
224
|
],
|
|
299
225
|
'W',
|
|
300
226
|
);
|
|
@@ -303,47 +229,39 @@ function compose({ shape, mark = null }, pose, frame) {
|
|
|
303
229
|
case 'thinking': {
|
|
304
230
|
// A hand to the chin, eyes up, a thought rising.
|
|
305
231
|
whole(0, 0, 'up');
|
|
306
|
-
|
|
307
|
-
put(
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
[
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
if (f >= 3) paint(g, ['SSS', 'SSS'], { top: 0, dx: 9 });
|
|
232
|
+
put(g, [[4, 5]], 'H');
|
|
233
|
+
if (f >= 1) put(g, [[2, 6]], 'S');
|
|
234
|
+
if (f >= 2) put(g, [[1, 7]], 'S');
|
|
235
|
+
if (f >= 3)
|
|
236
|
+
put(
|
|
237
|
+
g,
|
|
238
|
+
[
|
|
239
|
+
[0, 6],
|
|
240
|
+
[0, 7],
|
|
241
|
+
],
|
|
242
|
+
'S',
|
|
243
|
+
);
|
|
319
244
|
break;
|
|
320
245
|
}
|
|
321
246
|
case 'waiting': {
|
|
322
|
-
// A raised
|
|
247
|
+
// A hand raised.
|
|
323
248
|
whole(0, 0, 'open');
|
|
324
|
-
clear(g, [[
|
|
249
|
+
clear(g, [[5, 5]]);
|
|
325
250
|
put(
|
|
326
251
|
g,
|
|
327
|
-
[
|
|
328
|
-
[8, 9],
|
|
329
|
-
[7, 9],
|
|
330
|
-
[6, 9],
|
|
331
|
-
[5, 9],
|
|
332
|
-
[4, 9],
|
|
333
|
-
],
|
|
252
|
+
[1, 2, 3, 4].map((y) => [y, 6]),
|
|
334
253
|
'H',
|
|
335
254
|
);
|
|
336
255
|
break;
|
|
337
256
|
}
|
|
338
257
|
case 'quiet': {
|
|
339
|
-
// Still, looking on, a trailing
|
|
258
|
+
// Still, looking on, a trailing pair of dots.
|
|
340
259
|
whole(0, 0, 'open');
|
|
341
260
|
put(
|
|
342
261
|
g,
|
|
343
262
|
[
|
|
344
|
-
[1,
|
|
345
|
-
[1,
|
|
346
|
-
[1, 11],
|
|
263
|
+
[1, 6],
|
|
264
|
+
[1, 7],
|
|
347
265
|
],
|
|
348
266
|
'S',
|
|
349
267
|
);
|
|
@@ -351,27 +269,34 @@ function compose({ shape, mark = null }, pose, frame) {
|
|
|
351
269
|
}
|
|
352
270
|
case 'stalled': {
|
|
353
271
|
// Slumped: the head dropped and tilted, eyes crossed.
|
|
354
|
-
paint(g, BODY, { top:
|
|
272
|
+
paint(g, BODY, { top: BODY_TOP });
|
|
355
273
|
paint(g, head, { dx: 1, dy: 1 });
|
|
356
274
|
face(g, 'crossed', 1, 1);
|
|
357
275
|
wear(g, mark, 'open', 1, 1);
|
|
358
276
|
break;
|
|
359
277
|
}
|
|
360
278
|
case 'resting': {
|
|
361
|
-
//
|
|
279
|
+
// Asleep: eyes shut, and a z rising.
|
|
362
280
|
whole(0, 0, 'closed');
|
|
363
|
-
|
|
281
|
+
put(
|
|
282
|
+
g,
|
|
283
|
+
[
|
|
284
|
+
[2, 6],
|
|
285
|
+
[0, 7],
|
|
286
|
+
],
|
|
287
|
+
'S',
|
|
288
|
+
);
|
|
364
289
|
break;
|
|
365
290
|
}
|
|
366
291
|
case 'arriving': {
|
|
367
292
|
// Dropping into the lane.
|
|
368
|
-
whole(0, [-
|
|
293
|
+
whole(0, [-6, -3, -1, 0][f], 'open');
|
|
369
294
|
if (f < 2)
|
|
370
295
|
put(
|
|
371
296
|
g,
|
|
372
297
|
[
|
|
373
|
-
[0,
|
|
374
|
-
[0,
|
|
298
|
+
[0, 0],
|
|
299
|
+
[0, 6],
|
|
375
300
|
],
|
|
376
301
|
'S',
|
|
377
302
|
);
|
|
@@ -382,17 +307,16 @@ function compose({ shape, mark = null }, pose, frame) {
|
|
|
382
307
|
whole(0, 0, f === 3 ? 'happy' : 'open');
|
|
383
308
|
const paper = [
|
|
384
309
|
[
|
|
385
|
-
[
|
|
386
|
-
[
|
|
310
|
+
[5, 6],
|
|
311
|
+
[5, 7],
|
|
387
312
|
],
|
|
388
313
|
[
|
|
389
|
-
[
|
|
390
|
-
[
|
|
314
|
+
[3, 6],
|
|
315
|
+
[3, 7],
|
|
391
316
|
],
|
|
392
|
-
[[
|
|
317
|
+
[[1, 7]],
|
|
393
318
|
[],
|
|
394
319
|
][f];
|
|
395
|
-
if (f < 2) put(g, [[8, 9]], 'H');
|
|
396
320
|
put(g, paper, 'W');
|
|
397
321
|
break;
|
|
398
322
|
}
|
|
@@ -403,18 +327,16 @@ function compose({ shape, mark = null }, pose, frame) {
|
|
|
403
327
|
}
|
|
404
328
|
case 'merged': {
|
|
405
329
|
// A cheer: arms up, a jump, sparkles.
|
|
406
|
-
const up = [0, -
|
|
407
|
-
const body = BODY.map((r, i) => (i === 1
|
|
330
|
+
const up = [0, -1, -1, 0][f];
|
|
331
|
+
const body = BODY.map((r, i) => (i === 1 ? '..HHH...' : r));
|
|
408
332
|
whole(0, up, 'happy', body);
|
|
409
333
|
put(
|
|
410
334
|
g,
|
|
411
335
|
[
|
|
412
|
-
[
|
|
413
|
-
[
|
|
414
|
-
[
|
|
415
|
-
[
|
|
416
|
-
[6 + up, 9],
|
|
417
|
-
[5 + up, 9],
|
|
336
|
+
[4 + up, 0],
|
|
337
|
+
[3 + up, 0],
|
|
338
|
+
[4 + up, 6],
|
|
339
|
+
[3 + up, 6],
|
|
418
340
|
],
|
|
419
341
|
'H',
|
|
420
342
|
);
|
|
@@ -422,12 +344,12 @@ function compose({ shape, mark = null }, pose, frame) {
|
|
|
422
344
|
g,
|
|
423
345
|
f % 2
|
|
424
346
|
? [
|
|
425
|
-
[0,
|
|
426
|
-
[
|
|
347
|
+
[0, 0],
|
|
348
|
+
[1, 7],
|
|
427
349
|
]
|
|
428
350
|
: [
|
|
429
351
|
[1, 0],
|
|
430
|
-
[0,
|
|
352
|
+
[0, 7],
|
|
431
353
|
],
|
|
432
354
|
'K',
|
|
433
355
|
);
|
|
@@ -445,7 +367,7 @@ const shade = (rgb, by) =>
|
|
|
445
367
|
Math.round((rgb & 0xff) * by);
|
|
446
368
|
|
|
447
369
|
/**
|
|
448
|
-
* A pose's frame as a grid of colours (null for none),
|
|
370
|
+
* A pose's frame as a grid of colours (null for none), SIZE by SIZE. Resting is drawn dimmed. With
|
|
449
371
|
* motion off, a loop shows its first frame and a move its last.
|
|
450
372
|
*/
|
|
451
373
|
export function characterFrame(pose, frame, character, { motion = 'while-active' } = {}) {
|
package/hooks/mod/loop.mjs
CHANGED
|
@@ -382,9 +382,52 @@ export const requestContext = (usage) =>
|
|
|
382
382
|
(usage?.cache_read_input_tokens ?? 0) +
|
|
383
383
|
(usage?.cache_creation_input_tokens ?? 0);
|
|
384
384
|
|
|
385
|
+
/** LOOP-14: the first wait after a failed turn with no used-up window, and the longest. */
|
|
386
|
+
export const RETRY_MS = 5 * 60 * 1000;
|
|
387
|
+
export const RETRY_MAX_MS = 60 * 60 * 1000;
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* LOOP-14: how long the loop holds after a lead turn ended on an API error: until the latest reset of
|
|
391
|
+
* the rate-limit windows that are used up, or, with none (an overloaded or failing API), 5 minutes
|
|
392
|
+
* doubling with each failure in a row (`failures`, from 1), at most an hour.
|
|
393
|
+
* { until, why: 'limit' | 'error' }.
|
|
394
|
+
*/
|
|
395
|
+
export function limitHold({ rateLimits = [], now, failures = 1 }) {
|
|
396
|
+
const resets = rateLimits
|
|
397
|
+
.filter((w) => w.percentUsed >= 100 && w.resetsAt)
|
|
398
|
+
.map((w) => Date.parse(w.resetsAt))
|
|
399
|
+
.filter((at) => Number.isFinite(at) && at > now);
|
|
400
|
+
if (resets.length) return { until: Math.max(...resets), why: 'limit' };
|
|
401
|
+
const wait = Math.min(RETRY_MS * 2 ** Math.max(0, failures - 1), RETRY_MAX_MS);
|
|
402
|
+
return { until: now + wait, why: 'error' };
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
/** LOOP-14: the band's words for the hold: "Claude's usage limit is reached: the loop waits until …". */
|
|
406
|
+
export function limitText(hold) {
|
|
407
|
+
const when = new Date(hold.until).toLocaleString(undefined, {
|
|
408
|
+
weekday: 'short',
|
|
409
|
+
hour: 'numeric',
|
|
410
|
+
minute: '2-digit',
|
|
411
|
+
});
|
|
412
|
+
return hold.why === 'limit'
|
|
413
|
+
? `Claude's usage limit is reached: the loop waits until ${when}`
|
|
414
|
+
: `Claude's API failed the lead's turn: the loop tries again at ${when}`;
|
|
415
|
+
}
|
|
416
|
+
|
|
385
417
|
/** LEAN-5: what a lane agent past its context limit is told. */
|
|
386
418
|
export const wrapUpText = (limit) =>
|
|
387
|
-
`Your context is past ${Math.round(limit / 1000)}k tokens, and every step from here rereads all of it. Finish the step you're on, commit your work, write your report, and hand back now.
|
|
419
|
+
`Your context is past ${Math.round(limit / 1000)}k tokens, and every step from here rereads all of it. Finish the step you're on, commit your work, write your report, and hand back now. If the story isn't done, start your hand-back with "${UNFINISHED}" and what's left: the lead carries it on with a fresh agent that reads your report. If it is done, hand back as usual.`;
|
|
420
|
+
|
|
421
|
+
/** LEAN-5: how a lane agent past its limit says its story isn't done. */
|
|
422
|
+
export const UNFINISHED = 'Not finished:';
|
|
423
|
+
|
|
424
|
+
/** LEAN-5: whether a hand-back says the story isn't done, so a fresh agent carries it on. */
|
|
425
|
+
export const unfinished = (answer) =>
|
|
426
|
+
String(answer ?? '')
|
|
427
|
+
.trimStart()
|
|
428
|
+
.replace(/^[*_#>\s]+/, '')
|
|
429
|
+
.toLowerCase()
|
|
430
|
+
.startsWith(UNFINISHED.toLowerCase());
|
|
388
431
|
|
|
389
432
|
/** LEAN-5, LEAN-6: the lead's prompt to carry a story on with a fresh agent once its agent handed back at the limit. */
|
|
390
433
|
export function continuePrompt({ type, story, branch, cli = 'code-kit' }) {
|