@warren-dean/code-kit 0.21.0 → 0.22.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 +12 -0
- package/README.md +46 -23
- package/bin/code-kit.mjs +269 -21
- package/hooks/guard-agent.mjs +36 -0
- package/hooks/guard-bash.mjs +23 -11
- package/hooks/guard-paths.mjs +11 -0
- package/hooks/hooks.json +20 -0
- package/hooks/lane-audit.mjs +38 -1
- package/hooks/lib/config.mjs +148 -5
- package/hooks/lib/decisionstore.mjs +89 -0
- package/hooks/lib/harness.mjs +7 -0
- package/hooks/lib/hook.mjs +7 -0
- package/hooks/lib/instructions.mjs +1 -1
- package/hooks/lib/laneclaims.mjs +89 -0
- package/hooks/lib/loop-state.mjs +20 -2
- package/hooks/lib/next.mjs +34 -1
- package/hooks/lib/plan.mjs +3 -1
- package/hooks/lib/questions.mjs +23 -5
- package/hooks/lib/regression.mjs +2 -1
- package/hooks/lib/rules.mjs +18 -12
- package/hooks/lib/schedule.mjs +86 -0
- package/hooks/lib/sessions.mjs +223 -0
- package/hooks/lib/snapshot.mjs +9 -3
- package/hooks/mod/decisions.mjs +1 -28
- package/hooks/mod/loop.mjs +8 -0
- package/hooks/mod/mission.mjs +21 -19
- package/hooks/mod/register.mjs +117 -40
- package/hooks/mod/register.test.ts +244 -73
- package/hooks/mod/view.mjs +98 -47
- package/hooks/post-edit-check.mjs +3 -0
- package/hooks/session.mjs +24 -0
- package/hooks/stop-check.mjs +12 -0
- package/package.json +1 -1
- package/skills/decide/SKILL.md +1 -1
- package/skills/dispatch/SKILL.md +2 -2
- package/skills/init/SKILL.md +1 -1
- package/skills/lead/SKILL.md +28 -0
- package/skills/next/SKILL.md +1 -1
- package/skills/spec-design/SKILL.md +2 -1
- package/templates/claude-md.md +3 -1
- package/templates/plan.md +2 -1
package/bin/code-kit.mjs
CHANGED
|
@@ -34,6 +34,13 @@
|
|
|
34
34
|
// settings [--json] | settings set <key> <value> --reason … [--via pane]
|
|
35
35
|
// the harness settings; set is the person's own change
|
|
36
36
|
// record approvals a person gave in chat (with approvals.lead on, the lead runs it)
|
|
37
|
+
// decisions [--json] [--all] what waits on the person in this session, and a count of each other's
|
|
38
|
+
// who which session this is, whether it leads, and its task (spec 23)
|
|
39
|
+
// sessions [--json] | sessions lead the sessions working the project; make this one the lead
|
|
40
|
+
// task "<what>" --touches globs | task done | task take <session>
|
|
41
|
+
// a working session's ad hoc task and the paths it leases
|
|
42
|
+
// lanes [--json] | lanes release <lane>
|
|
43
|
+
// the lanes running a story now, one each across sessions (spec 23)
|
|
37
44
|
// --config <file> reads a draft (.claude/code-kit.draft.json) instead of .claude/code-kit.json.
|
|
38
45
|
import { execFileSync, spawnSync } from 'node:child_process';
|
|
39
46
|
import {
|
|
@@ -52,10 +59,12 @@ import { BASELINE_FILE, loadBaseline } from '../hooks/lib/baseline.mjs';
|
|
|
52
59
|
import { matchesAny } from '../hooks/lib/glob.mjs';
|
|
53
60
|
import {
|
|
54
61
|
CONFIG_FILE,
|
|
62
|
+
approvalSettings,
|
|
55
63
|
committedConfig,
|
|
56
64
|
effectiveConfig,
|
|
57
65
|
mergeDelegation,
|
|
58
66
|
validate,
|
|
67
|
+
withApprovalSetting,
|
|
59
68
|
} from '../hooks/lib/config.mjs';
|
|
60
69
|
import { diffConfigs, ownershipMoves } from '../hooks/lib/diff.mjs';
|
|
61
70
|
import { CODE, importsOf, layerOf, layerProblems, targetOf } from '../hooks/lib/layers.mjs';
|
|
@@ -133,6 +142,20 @@ import { dependencyRuleProblems, npmFacts, packageOf } from '../hooks/lib/regist
|
|
|
133
142
|
import { heldTo, laneOfBranch, verifyBranch } from '../hooks/lib/verify.mjs';
|
|
134
143
|
import { skippedLine } from '../hooks/lib/checks.mjs';
|
|
135
144
|
import { TESTS_APPROVAL } from '../hooks/lib/regression.mjs';
|
|
145
|
+
import { laneClaim, laneClaims, releaseLane, shortSession } from '../hooks/lib/laneclaims.mjs';
|
|
146
|
+
import { slicesOf } from '../hooks/lib/schedule.mjs';
|
|
147
|
+
import {
|
|
148
|
+
leadSession,
|
|
149
|
+
makeLead,
|
|
150
|
+
memberOf,
|
|
151
|
+
readSession,
|
|
152
|
+
seeSession,
|
|
153
|
+
sessions,
|
|
154
|
+
setTask,
|
|
155
|
+
takeTask,
|
|
156
|
+
} from '../hooks/lib/sessions.mjs';
|
|
157
|
+
import { globsOverlap } from '../hooks/lib/teamfacts.mjs';
|
|
158
|
+
import { decisionsFor, openDecisions } from '../hooks/lib/decisionstore.mjs';
|
|
136
159
|
import {
|
|
137
160
|
appliesTo,
|
|
138
161
|
projectStandards,
|
|
@@ -166,6 +189,8 @@ const laneName = option('--lane');
|
|
|
166
189
|
const intoName = option('--into');
|
|
167
190
|
const via = option('--via');
|
|
168
191
|
const sessionId = option('--session');
|
|
192
|
+
// SESS-1: the session calling, as Claude Code tells every command an agent runs, unless --session says.
|
|
193
|
+
const callerSession = sessionId ?? process.env.CLAUDE_CODE_SESSION_ID ?? null;
|
|
169
194
|
const minutesGiven = option('--minutes');
|
|
170
195
|
const answerGiven = option('--answer');
|
|
171
196
|
const leaseGiven = option('--lease');
|
|
@@ -279,6 +304,23 @@ function check() {
|
|
|
279
304
|
}
|
|
280
305
|
}
|
|
281
306
|
|
|
307
|
+
/** SESS-1: which session the caller is, whether it leads the project, and its task. */
|
|
308
|
+
function whoAmI() {
|
|
309
|
+
load();
|
|
310
|
+
const root = resolve('.');
|
|
311
|
+
const me = callerSession ? readSession(root, callerSession) : null;
|
|
312
|
+
if (!me)
|
|
313
|
+
return out(
|
|
314
|
+
callerSession
|
|
315
|
+
? `Session ${shortSession(callerSession)}, which code-kit hasn't recorded yet.`
|
|
316
|
+
: 'Not run from a Claude Code session, so no member of the team.',
|
|
317
|
+
);
|
|
318
|
+
const lead = leadSession(root);
|
|
319
|
+
out(
|
|
320
|
+
`${memberOf(me)}: ${me.role === 'lead' ? 'the lead session' : `a working session${lead ? ` (${memberOf(lead)} leads)` : ' (no session leads now)'}`}${me.task ? `, working on "${me.task.title}"` : ''}.`,
|
|
321
|
+
);
|
|
322
|
+
}
|
|
323
|
+
|
|
282
324
|
function who(paths) {
|
|
283
325
|
const { config } = load();
|
|
284
326
|
for (const p of paths) {
|
|
@@ -1021,7 +1063,7 @@ function requests() {
|
|
|
1021
1063
|
const open = openRequests(resolve('.')).map((r, i) => ({
|
|
1022
1064
|
...r,
|
|
1023
1065
|
n: i + 1,
|
|
1024
|
-
by: decidedBy(r.names, config),
|
|
1066
|
+
by: decidedBy(r.names, config, r.lane ? { kind: 'lane', lane: r.lane } : { kind: 'lead' }),
|
|
1025
1067
|
}));
|
|
1026
1068
|
const granted = approvalsInForce(resolve('.'));
|
|
1027
1069
|
// CARD-6: every approval given, newest first.
|
|
@@ -1045,6 +1087,159 @@ function requests() {
|
|
|
1045
1087
|
);
|
|
1046
1088
|
}
|
|
1047
1089
|
|
|
1090
|
+
/**
|
|
1091
|
+
* OWN-1: the decisions waiting on the person in this session (the lead's questions, the approvals its
|
|
1092
|
+
* refusals asked for), and a count of those in each other session; `--all` lists every session's.
|
|
1093
|
+
*/
|
|
1094
|
+
function decisionsCommand() {
|
|
1095
|
+
const { config } = load();
|
|
1096
|
+
const root = resolve('.');
|
|
1097
|
+
if (rest.length) die('code-kit decisions [--json] [--all]');
|
|
1098
|
+
const stories =
|
|
1099
|
+
config.docs?.specs && config.docs?.plan
|
|
1100
|
+
? buildStatus('.', config, base(config, false), tracked()).stories
|
|
1101
|
+
: [];
|
|
1102
|
+
if (flag('--all')) {
|
|
1103
|
+
const all = openDecisions(root, { stories });
|
|
1104
|
+
if (flag('--json')) return out(JSON.stringify(all, null, 2));
|
|
1105
|
+
if (!all.length) return out('Nothing waits on the person.');
|
|
1106
|
+
for (const d of all)
|
|
1107
|
+
out(
|
|
1108
|
+
`${pad(d.member ?? 'any session', 30)} ${pad(d.kind, 8)} ${d.what}${d.count > 1 ? ` (asked ${d.count} times)` : ''}`,
|
|
1109
|
+
);
|
|
1110
|
+
return;
|
|
1111
|
+
}
|
|
1112
|
+
const r = decisionsFor(root, callerSession, { stories });
|
|
1113
|
+
if (flag('--json')) return out(JSON.stringify(r, null, 2));
|
|
1114
|
+
if (!r.mine.length) out('Nothing waits on the person in this session.');
|
|
1115
|
+
for (const d of r.mine)
|
|
1116
|
+
out(`${pad(d.kind, 8)} ${d.what}${d.count > 1 ? ` (asked ${d.count} times)` : ''}`);
|
|
1117
|
+
for (const e of r.elsewhere)
|
|
1118
|
+
out(`${e.count} decision${e.count === 1 ? '' : 's'} in session ${e.member}, answered there.`);
|
|
1119
|
+
}
|
|
1120
|
+
|
|
1121
|
+
/**
|
|
1122
|
+
* SESS-1, SESS-2: the sessions working the project, which one leads, and each one's task; `beat` (the mod,
|
|
1123
|
+
* while a session is open) says the session is still there; `lead` makes the caller's session the lead.
|
|
1124
|
+
*/
|
|
1125
|
+
function sessionsCommand() {
|
|
1126
|
+
load();
|
|
1127
|
+
const root = resolve('.');
|
|
1128
|
+
const [sub] = rest;
|
|
1129
|
+
if (sub === 'beat' || sub === 'lead') {
|
|
1130
|
+
if (!callerSession) die(`code-kit sessions ${sub} needs the session: --session <id>.`);
|
|
1131
|
+
if (sub === 'beat') return seeSession(root, callerSession) && out('Seen.');
|
|
1132
|
+
const was = leadSession(root);
|
|
1133
|
+
makeLead(root, callerSession);
|
|
1134
|
+
return out(
|
|
1135
|
+
`This session (${shortSession(callerSession)}) leads the project now${was && was.id !== callerSession ? `; ${shortSession(was.id)} is a working session` : ''}.`,
|
|
1136
|
+
);
|
|
1137
|
+
}
|
|
1138
|
+
if (sub !== undefined) die('code-kit sessions [--json] | sessions lead | sessions beat');
|
|
1139
|
+
const all = sessions(root).filter((s) => s.live || s.task);
|
|
1140
|
+
if (flag('--json'))
|
|
1141
|
+
return out(
|
|
1142
|
+
JSON.stringify(
|
|
1143
|
+
all.map((s) => ({ ...s, member: memberOf(s) })),
|
|
1144
|
+
null,
|
|
1145
|
+
2,
|
|
1146
|
+
),
|
|
1147
|
+
);
|
|
1148
|
+
if (!all.length) return out('No session is working this project.');
|
|
1149
|
+
for (const s of all)
|
|
1150
|
+
out(
|
|
1151
|
+
`${pad(memberOf(s), 30)} ${pad(s.live ? s.role : 'ended', 8)} ${s.task ? `${s.task.title}${s.task.paths?.length ? ` (${s.task.paths.join(', ')})` : ''}${s.live ? '' : ', stale'}` : '-'}${s.id === callerSession ? ' ← this session' : ''}`,
|
|
1152
|
+
);
|
|
1153
|
+
}
|
|
1154
|
+
|
|
1155
|
+
/**
|
|
1156
|
+
* SESS-4: an ad hoc task, for a session working without a story: recorded with the paths it leases, so
|
|
1157
|
+
* the other sessions' agents leave them alone; `done` ends it; `take <session>` moves a stale one here.
|
|
1158
|
+
*/
|
|
1159
|
+
function taskCommand() {
|
|
1160
|
+
load();
|
|
1161
|
+
const root = resolve('.');
|
|
1162
|
+
const [sub] = rest;
|
|
1163
|
+
if (!callerSession)
|
|
1164
|
+
die(
|
|
1165
|
+
'code-kit task needs the session: run it from Claude Code (CLAUDE_CODE_SESSION_ID), or pass --session <id>.',
|
|
1166
|
+
);
|
|
1167
|
+
if (sub === 'done') {
|
|
1168
|
+
const had = readSession(root, callerSession)?.task;
|
|
1169
|
+
if (!had) return out('This session has no task.');
|
|
1170
|
+
setTask(root, callerSession, null);
|
|
1171
|
+
return out(`Done: "${had.title}". Its paths are free for other sessions.`);
|
|
1172
|
+
}
|
|
1173
|
+
if (sub === 'take') {
|
|
1174
|
+
if (rest.length !== 2) die('code-kit task take <session>');
|
|
1175
|
+
const r = takeTask(root, rest[1], callerSession);
|
|
1176
|
+
if (!r.ok) die(r.why);
|
|
1177
|
+
return out(
|
|
1178
|
+
`This session took over "${r.task.title}" from ${memberOf(r.from)}${r.task.paths?.length ? `, leasing ${r.task.paths.join(', ')}` : ''}.`,
|
|
1179
|
+
);
|
|
1180
|
+
}
|
|
1181
|
+
if (sub === undefined) {
|
|
1182
|
+
const s = readSession(root, callerSession);
|
|
1183
|
+
if (flag('--json')) return out(JSON.stringify(s?.task ?? null));
|
|
1184
|
+
return out(
|
|
1185
|
+
s?.task
|
|
1186
|
+
? `"${s.task.title}"${s.task.paths?.length ? `, leasing ${s.task.paths.join(', ')}` : ''}.`
|
|
1187
|
+
: 'This session has no task.',
|
|
1188
|
+
);
|
|
1189
|
+
}
|
|
1190
|
+
if (rest.length !== 1)
|
|
1191
|
+
die(
|
|
1192
|
+
'code-kit task "<what you\'re doing>" --touches "<globs>" | task done | task take <session>',
|
|
1193
|
+
);
|
|
1194
|
+
const paths = (touchesGiven ?? '')
|
|
1195
|
+
.split(',')
|
|
1196
|
+
.map((g) => g.trim())
|
|
1197
|
+
.filter(Boolean);
|
|
1198
|
+
const clash = sessions(root).find(
|
|
1199
|
+
(s) =>
|
|
1200
|
+
s.live &&
|
|
1201
|
+
s.id !== callerSession &&
|
|
1202
|
+
s.task?.paths?.some((p) => paths.some((q) => globsOverlap(p, q))),
|
|
1203
|
+
);
|
|
1204
|
+
if (clash)
|
|
1205
|
+
die(
|
|
1206
|
+
`Another session (${memberOf(clash)}) is working on "${clash.task.title}", leasing ${clash.task.paths.join(', ')}. Pick paths it doesn't lease, or wait until it's done.`,
|
|
1207
|
+
);
|
|
1208
|
+
const branch = currentBranch(root) ?? null;
|
|
1209
|
+
setTask(root, callerSession, { title: sub.trim(), paths, branch });
|
|
1210
|
+
out(
|
|
1211
|
+
`This session is working on "${sub.trim()}"${paths.length ? `, leasing ${paths.join(', ')}` : ''}. \`code-kit task done\` when it's finished.`,
|
|
1212
|
+
);
|
|
1213
|
+
}
|
|
1214
|
+
|
|
1215
|
+
/**
|
|
1216
|
+
* SCHED-1: the lanes claimed now, one story each across every session, or one lane released: for an
|
|
1217
|
+
* agent the lead saw stop without finishing, so its lane can take the next story.
|
|
1218
|
+
*/
|
|
1219
|
+
function lanesCommand() {
|
|
1220
|
+
const { config } = load();
|
|
1221
|
+
const root = resolve('.');
|
|
1222
|
+
if (rest[0] === 'release') {
|
|
1223
|
+
const lane = rest[1];
|
|
1224
|
+
if (!lane || rest.length !== 2) die('code-kit lanes release <lane>');
|
|
1225
|
+
if (!config.lanes[lane])
|
|
1226
|
+
die(`There is no lane "${lane}". Lanes: ${Object.keys(config.lanes).join(', ')}.`);
|
|
1227
|
+
const held = laneClaim(root, lane);
|
|
1228
|
+
if (!releaseLane(root, lane)) return out(`The ${lane} lane isn't claimed.`);
|
|
1229
|
+
return out(
|
|
1230
|
+
`Released the ${lane} lane${held.story ? ` (it was running ${held.story})` : ''}. Its next story can start.`,
|
|
1231
|
+
);
|
|
1232
|
+
}
|
|
1233
|
+
if (rest.length) die('code-kit lanes [--json] | lanes release <lane>');
|
|
1234
|
+
const claims = laneClaims(root);
|
|
1235
|
+
if (flag('--json')) return out(JSON.stringify(claims, null, 2));
|
|
1236
|
+
if (!claims.length) return out('No lane is running a story.');
|
|
1237
|
+
for (const c of claims)
|
|
1238
|
+
out(
|
|
1239
|
+
`${c.lane.padEnd(12)} ${(c.story ?? 'a story').padEnd(8)} session ${shortSession(c.session) ?? '?'}, since ${c.since.slice(0, 16).replace('T', ' ')} UTC${c.stale ? ' (stale: no agent seen to finish in 12 hours)' : ''}`,
|
|
1240
|
+
);
|
|
1241
|
+
}
|
|
1242
|
+
|
|
1048
1243
|
/**
|
|
1049
1244
|
* The harness settings (`harness` in the config): listed, or one changed as the person's own act. The
|
|
1050
1245
|
* change is written to the config and given a kit approval with the person's reason, so the commit that
|
|
@@ -1056,33 +1251,50 @@ function settings() {
|
|
|
1056
1251
|
const [, key, value] = rest;
|
|
1057
1252
|
if (!key || value === undefined)
|
|
1058
1253
|
die('code-kit settings set <key> <value> --reason "<why>" [--via pane]');
|
|
1059
|
-
|
|
1060
|
-
|
|
1254
|
+
const approvalKey = key.startsWith('approvals.');
|
|
1255
|
+
if (!(key in SETTINGS) && !approvalKey)
|
|
1256
|
+
die(
|
|
1257
|
+
`${key} isn't a setting. They are: ${Object.keys(SETTINGS).join(', ')}, and approvals.<name> (see code-kit settings).`,
|
|
1258
|
+
);
|
|
1061
1259
|
if (!reason?.trim()) die('Give a reason with --reason "…": the approval log keeps it.');
|
|
1062
|
-
|
|
1260
|
+
// WHO-3: who decides an approval is the person's setting too, written out in full.
|
|
1261
|
+
const changed = approvalKey
|
|
1262
|
+
? withApprovalSetting(raw, config, key, value)
|
|
1263
|
+
: withSetting(raw, key, parseSetting(key, value));
|
|
1264
|
+
if (!changed)
|
|
1265
|
+
die(
|
|
1266
|
+
`${key} isn't an approval setting, or ${JSON.stringify(value)} isn't one of its values. See code-kit settings.`,
|
|
1267
|
+
);
|
|
1063
1268
|
const problems = validate(changed);
|
|
1064
1269
|
if (problems.length) die(`Nothing changed: ${problems.join('; ')}`);
|
|
1065
1270
|
writeFileSync(resolve(file), `${JSON.stringify(changed, null, 2)}\n`);
|
|
1066
1271
|
const mark =
|
|
1067
1272
|
via === 'pane' ? '(changed in the code-kit pane)' : '(changed with code-kit settings)';
|
|
1068
1273
|
grantApprovals(resolve('.'), ['kit'], null, reason, { kit: mark });
|
|
1274
|
+
const now = approvalKey
|
|
1275
|
+
? approvalSettings(effectiveConfig(changed, resolve('.'))).find((r) => r.key === key)?.value
|
|
1276
|
+
: settingOf(changed.harness, key);
|
|
1069
1277
|
return out(
|
|
1070
|
-
`Set harness.${key} to ${JSON.stringify(
|
|
1278
|
+
`Set ${approvalKey ? key : `harness.${key}`} to ${JSON.stringify(now)}. Commit ${file} to keep it; the approval log will carry your reason.`,
|
|
1071
1279
|
);
|
|
1072
1280
|
}
|
|
1073
1281
|
if (rest.length) die('code-kit settings [--json] | settings set <key> <value> --reason "<why>"');
|
|
1074
|
-
const rows =
|
|
1075
|
-
key,
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1282
|
+
const rows = [
|
|
1283
|
+
...Object.entries(SETTINGS).map(([key, s]) => ({
|
|
1284
|
+
key,
|
|
1285
|
+
value: settingOf(config.harness, key),
|
|
1286
|
+
default: s.default,
|
|
1287
|
+
about: s.about,
|
|
1288
|
+
section: 'Harness',
|
|
1289
|
+
// Chosen in the config, or the default standing in.
|
|
1290
|
+
set: settingOf(raw.harness, key) !== undefined,
|
|
1291
|
+
})),
|
|
1292
|
+
...approvalSettings(config),
|
|
1293
|
+
];
|
|
1082
1294
|
if (flag('--json')) return out(JSON.stringify(rows, null, 2));
|
|
1083
1295
|
for (const r of rows)
|
|
1084
1296
|
out(
|
|
1085
|
-
`${r.key.padEnd(
|
|
1297
|
+
`${r.key.padEnd(44)} ${JSON.stringify(r.value).padEnd(14)} ${r.value === r.default ? '' : `(default ${JSON.stringify(r.default)}) `}${r.about}`,
|
|
1086
1298
|
);
|
|
1087
1299
|
}
|
|
1088
1300
|
|
|
@@ -1264,7 +1476,14 @@ function status() {
|
|
|
1264
1476
|
if (flag('--json')) {
|
|
1265
1477
|
out(
|
|
1266
1478
|
JSON.stringify(
|
|
1267
|
-
{
|
|
1479
|
+
{
|
|
1480
|
+
base: from,
|
|
1481
|
+
stories,
|
|
1482
|
+
slices: slicesOf(stories),
|
|
1483
|
+
requirements: byRequirement,
|
|
1484
|
+
problems,
|
|
1485
|
+
drift,
|
|
1486
|
+
},
|
|
1268
1487
|
null,
|
|
1269
1488
|
2,
|
|
1270
1489
|
),
|
|
@@ -1282,9 +1501,18 @@ function status() {
|
|
|
1282
1501
|
? s.branch
|
|
1283
1502
|
: '';
|
|
1284
1503
|
out(
|
|
1285
|
-
` ${pad(s.id, 7)} ${pad(s.state, 12)} ${pad(s.lane || '-', 10)} ${pad(s.requirements.join(', '), 24)} ${detail}`.trimEnd(),
|
|
1504
|
+
` ${pad(s.id, 7)} ${pad(s.state, 12)} ${pad(s.lane || '-', 10)} ${pad(s.requirements.join(', '), 24)} ${detail}${s.slice ? `${detail ? ' · ' : ''}slice ${s.slice}` : ''}`.trimEnd(),
|
|
1286
1505
|
);
|
|
1287
1506
|
}
|
|
1507
|
+
// SCHED-2: the slices, in plan order, and which are open.
|
|
1508
|
+
const slices = slicesOf(stories);
|
|
1509
|
+
if (slices.length) {
|
|
1510
|
+
out('\nSlices:');
|
|
1511
|
+
for (const sl of slices)
|
|
1512
|
+
out(
|
|
1513
|
+
` ${pad(sl.name, 24)} ${pad(sl.done ? 'done' : sl.open ? 'open' : 'not started', 12)} ${sl.stories.join(', ')}`,
|
|
1514
|
+
);
|
|
1515
|
+
}
|
|
1288
1516
|
out('\nRequirements:');
|
|
1289
1517
|
for (const r of byRequirement) {
|
|
1290
1518
|
const tests = r.tests.length ? `tested (${r.tests.join(', ')})` : 'no test names it';
|
|
@@ -1404,7 +1632,7 @@ async function approve(given) {
|
|
|
1404
1632
|
const rules = config.approvals.delegate;
|
|
1405
1633
|
if (!rules)
|
|
1406
1634
|
die(
|
|
1407
|
-
'This project
|
|
1635
|
+
'This project keeps every approval for the person ("approvals.delegate" is false). Ask the person.',
|
|
1408
1636
|
);
|
|
1409
1637
|
// HELM-3: the lead approves a package for a story it has read, not by default.
|
|
1410
1638
|
const packages = names.filter((n) => n.startsWith(DEPENDENCY_APPROVAL));
|
|
@@ -1421,8 +1649,16 @@ async function approve(given) {
|
|
|
1421
1649
|
: null;
|
|
1422
1650
|
const outside = [];
|
|
1423
1651
|
for (const name of names) {
|
|
1652
|
+
// WHO-2: a weakened test on a lane's branch, after the lead's review; on its own, the person's.
|
|
1424
1653
|
if (name === TESTS_APPROVAL) {
|
|
1425
|
-
outside.push(`${name}:
|
|
1654
|
+
if (!rules.tests) outside.push(`${name}: weakened tests aren't delegated`);
|
|
1655
|
+
else if (!laneName)
|
|
1656
|
+
outside.push(
|
|
1657
|
+
`${name}: on your own branch a weakened test is the person's; you approve one only for a lane, with --lane`,
|
|
1658
|
+
);
|
|
1659
|
+
else if (!storyGiven)
|
|
1660
|
+
outside.push(`${name}: name the story whose branch weakens the test, with --story ST-n`);
|
|
1661
|
+
else marks[name] = delegatedMark(`tests, reviewed by the lead, for ${story.id}`);
|
|
1426
1662
|
continue;
|
|
1427
1663
|
}
|
|
1428
1664
|
if (name.startsWith(DEPENDENCY_APPROVAL)) {
|
|
@@ -1943,6 +2179,7 @@ function askCommand() {
|
|
|
1943
2179
|
if (flag('--blocks') && !storyGiven) die('--blocks holds a story: name it with --story ST-n.');
|
|
1944
2180
|
const r = askQuestion(root, {
|
|
1945
2181
|
by: 'lead',
|
|
2182
|
+
session: callerSession,
|
|
1946
2183
|
question,
|
|
1947
2184
|
why: whyGiven ?? null,
|
|
1948
2185
|
story: storyGiven ?? null,
|
|
@@ -2034,7 +2271,9 @@ function loopCommand() {
|
|
|
2034
2271
|
const r = claimLead(root, sessionId, { take: flag('--take') });
|
|
2035
2272
|
if (!r.ok)
|
|
2036
2273
|
die(
|
|
2037
|
-
|
|
2274
|
+
r.lead
|
|
2275
|
+
? `Another session (${shortSession(r.lead.session)}, seen ${r.lead.at}) leads this project and runs its loop. Leave it there, or lead from here with --take.`
|
|
2276
|
+
: 'No session leads this project now, and this is a working session: the loop runs only in the lead session. Lead from here with --take.',
|
|
2038
2277
|
);
|
|
2039
2278
|
return out('This session runs the lead loop.');
|
|
2040
2279
|
}
|
|
@@ -2043,9 +2282,11 @@ function loopCommand() {
|
|
|
2043
2282
|
'code-kit loop [--json] | loop pause | loop resume | loop lead --session <id> [--take] | loop release --session <id>',
|
|
2044
2283
|
);
|
|
2045
2284
|
const state = readLoop(root);
|
|
2285
|
+
// SESS-2: with --session, whether that session leads the project or works in it.
|
|
2286
|
+
const role = sessionId ? (readSession(root, sessionId)?.role ?? null) : null;
|
|
2046
2287
|
out(
|
|
2047
2288
|
flag('--json')
|
|
2048
|
-
? JSON.stringify(state)
|
|
2289
|
+
? JSON.stringify({ ...state, ...(sessionId ? { role } : {}) })
|
|
2049
2290
|
: `${state.paused ? `The lead loop is paused (since ${state.at}).` : 'The lead loop is running.'}${state.lead ? ` Session ${state.lead.session} runs it.` : ''}`,
|
|
2050
2291
|
);
|
|
2051
2292
|
}
|
|
@@ -2247,6 +2488,10 @@ const commands = {
|
|
|
2247
2488
|
requests,
|
|
2248
2489
|
stops,
|
|
2249
2490
|
settings,
|
|
2491
|
+
lanes: lanesCommand,
|
|
2492
|
+
sessions: sessionsCommand,
|
|
2493
|
+
decisions: decisionsCommand,
|
|
2494
|
+
task: taskCommand,
|
|
2250
2495
|
hold: () => (rest.length === 1 ? hold(rest[0]) : usage()),
|
|
2251
2496
|
queue,
|
|
2252
2497
|
team: teamCommand,
|
|
@@ -2269,7 +2514,7 @@ const commands = {
|
|
|
2269
2514
|
diff,
|
|
2270
2515
|
baseline,
|
|
2271
2516
|
graph,
|
|
2272
|
-
who: () => (rest.length ? who(rest) :
|
|
2517
|
+
who: () => (rest.length ? who(rest) : whoAmI()),
|
|
2273
2518
|
};
|
|
2274
2519
|
function usage() {
|
|
2275
2520
|
die(
|
|
@@ -2288,6 +2533,9 @@ function usage() {
|
|
|
2288
2533
|
' | report [--json] | report send|discard <id>\n' +
|
|
2289
2534
|
' | stops [--session id] [--json] | sent-back <branch> [--reason "…"]\n' +
|
|
2290
2535
|
' | settings [--json] | settings set <key> <value> --reason "…" [--via pane]\n' +
|
|
2536
|
+
' | lanes [--json] | lanes release <lane> | sessions [--json] | sessions lead\n' +
|
|
2537
|
+
' | who | task "<what>" --touches globs | task done | task take <session>\n' +
|
|
2538
|
+
' | decisions [--json] [--all]\n' +
|
|
2291
2539
|
' | hold <id> [--minutes N] | hold <id> --answer approved|refused\n' +
|
|
2292
2540
|
' | queue [--json] | queue add|drop <branch> | queue rules | queue merge --delegated|--person\n' +
|
|
2293
2541
|
' | loop [--json] | loop pause|resume | loop lead|release --session id [--take]\n' +
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// PreToolUse on Agent (docs/specs/23-the-team.md, SCHED-1): a lane runs one story at a time, across every
|
|
3
|
+
// session in the project. Starting a lane's agent claims the lane; a second agent for a claimed lane is
|
|
4
|
+
// refused, naming the story and the session that has it. Any other agent starts as before.
|
|
5
|
+
import { block, start } from './lib/hook.mjs';
|
|
6
|
+
import { CLI } from './lib/rules.mjs';
|
|
7
|
+
import { claimLane, shortSession } from './lib/laneclaims.mjs';
|
|
8
|
+
import { memberOf, readSession } from './lib/sessions.mjs';
|
|
9
|
+
|
|
10
|
+
const { input, project, config, error } = start();
|
|
11
|
+
// A broken config is reported by the other hooks; it doesn't stop agents starting.
|
|
12
|
+
if (error) process.exit(0);
|
|
13
|
+
const call = input.tool_input ?? {};
|
|
14
|
+
const lane = Object.entries(config.lanes).find(([, l]) => l.agent === call.subagent_type)?.[0];
|
|
15
|
+
if (!lane) process.exit(0);
|
|
16
|
+
const story =
|
|
17
|
+
String(call.description ?? '')
|
|
18
|
+
.match(/\bST-\d+\b/i)?.[0]
|
|
19
|
+
?.toUpperCase() ?? null;
|
|
20
|
+
const session = input.session_id ?? null;
|
|
21
|
+
const claimed = claimLane(project, { lane, story, session });
|
|
22
|
+
if (!claimed.ok) {
|
|
23
|
+
const c = claimed.claim;
|
|
24
|
+
// SESS-1: the session by its member and, where it has one, its task.
|
|
25
|
+
const holder = readSession(project, c.session);
|
|
26
|
+
const where =
|
|
27
|
+
c.session && c.session === session
|
|
28
|
+
? 'in this session'
|
|
29
|
+
: c.session
|
|
30
|
+
? `in another session (${holder ? memberOf(holder) : shortSession(c.session)}${holder?.task ? `, working on "${holder.task.title}"` : ''})`
|
|
31
|
+
: 'here';
|
|
32
|
+
block(
|
|
33
|
+
`Blocked: the ${lane} lane is already running ${c.story ?? 'a story'} ${where}, since ${c.since.slice(11, 16)} UTC. A lane runs one story at a time across the project: two agents in one lane build on the same files in their worktrees and conflict at merge.\n` +
|
|
34
|
+
`Start ${story ?? 'this story'} when ${c.story ?? 'that story'} is finished, or dispatch a ready story in another lane meanwhile. If that agent has stopped and the lane is free, release it first:\n node "${CLI}" lanes release ${lane}`,
|
|
35
|
+
);
|
|
36
|
+
}
|
package/hooks/guard-bash.mjs
CHANGED
|
@@ -39,6 +39,7 @@ import {
|
|
|
39
39
|
delegatedMark,
|
|
40
40
|
dependencyChange,
|
|
41
41
|
dependencyGrants,
|
|
42
|
+
leadDecides,
|
|
42
43
|
useApproval,
|
|
43
44
|
owns,
|
|
44
45
|
protectedEntry,
|
|
@@ -217,10 +218,14 @@ if (runs(cmd, new RegExp(String.raw`^${CODE_KIT}\s+loop\s+(pause|resume)\b`)))
|
|
|
217
218
|
block(
|
|
218
219
|
`Blocked: pausing or resuming the lead loop is the person's own act, from the code-kit band or their terminal. Ask them, and stop.\nCommand: ${cmd}`,
|
|
219
220
|
);
|
|
220
|
-
// LOOP-10: which session
|
|
221
|
-
|
|
221
|
+
// LOOP-10, SESS-2: which session leads is recorded by code-kit's hooks and band, and choosing it is
|
|
222
|
+
// the person's own act.
|
|
223
|
+
if (
|
|
224
|
+
runs(cmd, new RegExp(String.raw`^${CODE_KIT}\s+loop\s+(lead|release)\b`)) ||
|
|
225
|
+
runs(cmd, new RegExp(String.raw`^${CODE_KIT}\s+sessions\s+(lead|beat)\b`))
|
|
226
|
+
)
|
|
222
227
|
block(
|
|
223
|
-
`Blocked: which session
|
|
228
|
+
`Blocked: which session leads the project is recorded by code-kit, and choosing it is the person's own act (Lead from here, in the code-kit band, or \`code-kit sessions lead\` in their terminal). Carry on with your work.\nCommand: ${cmd}`,
|
|
224
229
|
);
|
|
225
230
|
// TEAM-9: handing someone's claim to someone else is the tech lead's own decision too.
|
|
226
231
|
if (runs(cmd, new RegExp(String.raw`^${CODE_KIT}\s+team\s+reassign\b`)))
|
|
@@ -282,7 +287,7 @@ if (delegatedMerge && !config.approvals.delegate?.merge)
|
|
|
282
287
|
const delegating = /\s--delegated\b/.test(cmd);
|
|
283
288
|
if (approves && delegating && !config.approvals.delegate)
|
|
284
289
|
block(
|
|
285
|
-
`Blocked: this project
|
|
290
|
+
`Blocked: this project keeps every approval for the person ("approvals.delegate" is false). Ask the person to approve it with the \`!\` command from the refusal.\nCommand: ${cmd}`,
|
|
286
291
|
);
|
|
287
292
|
if (approves && !delegating && !forPerson)
|
|
288
293
|
block(
|
|
@@ -311,7 +316,9 @@ if (packages.length) {
|
|
|
311
316
|
// HELM-2, HELM-3: a lane asks the lead, which judges the package on its merits where it decides.
|
|
312
317
|
const names = unapproved.map(dependencyApproval);
|
|
313
318
|
const whose =
|
|
314
|
-
decidedBy(names, config) === 'lead'
|
|
319
|
+
decidedBy(names, config, actor) === 'lead'
|
|
320
|
+
? "is the lead's decision"
|
|
321
|
+
: "needs a person's approval";
|
|
315
322
|
block(
|
|
316
323
|
`Blocked: a new dependency (${unapproved.join(', ')}) ${whose}. ${askHowTo(names, actor, sessionIn ?? project, config, { allows: 'installing it, and the manifest and lockfile changes that makes,' })}\nCommand: ${cmd}`,
|
|
317
324
|
);
|
|
@@ -520,7 +527,7 @@ function recordApprovals() {
|
|
|
520
527
|
if (entry && !granted && actor.kind !== 'lead' && !byDependency) {
|
|
521
528
|
recordRequest(root, actor, entry.approval, file, entry.why);
|
|
522
529
|
block(
|
|
523
|
-
`Blocked: ${file} is ${entry.why}; committing it needs ${decidedBy(entry.approval, config) === 'lead' ? "the lead's" : "a person's"} approval in force.${noteFor(root, config, { kind: 'protected', name: entry.approval, glob: entry.glob })} ${askHowTo(entry.approval, actor, root, config)}`,
|
|
530
|
+
`Blocked: ${file} is ${entry.why}; committing it needs ${decidedBy(entry.approval, config, actor) === 'lead' ? "the lead's" : "a person's"} approval in force.${noteFor(root, config, { kind: 'protected', name: entry.approval, glob: entry.glob })} ${askHowTo(entry.approval, actor, root, config)}`,
|
|
524
531
|
);
|
|
525
532
|
}
|
|
526
533
|
if (granted)
|
|
@@ -545,8 +552,9 @@ function recordApprovals() {
|
|
|
545
552
|
grantedAt: null,
|
|
546
553
|
});
|
|
547
554
|
}
|
|
548
|
-
// REG-2: a commit that weakens a test waits for
|
|
549
|
-
//
|
|
555
|
+
// REG-2: a commit that weakens a test waits for a `tests` approval: WHO-2, the lead's on a lane's
|
|
556
|
+
// branch where tests are delegated, otherwise the person's (always on the lead's own). It's recorded in
|
|
557
|
+
// the log, so verify accepts the branch, and used up by this commit.
|
|
550
558
|
const weakened = commitWeakenings(
|
|
551
559
|
root,
|
|
552
560
|
files.filter((f) => !arrivesWithMerge(root, f, { staged: true })),
|
|
@@ -558,16 +566,20 @@ function recordApprovals() {
|
|
|
558
566
|
if (!granted) {
|
|
559
567
|
const [w, ...more] = weakened;
|
|
560
568
|
recordRequest(root, actor, TESTS_APPROVAL, w.file, `A weakened test: ${said(w)}.`);
|
|
569
|
+
const leads = leadDecides(TESTS_APPROVAL, config, actor);
|
|
561
570
|
const personOnly = { ...config, approvals: { ...config.approvals, delegate: null } };
|
|
562
571
|
block(
|
|
563
|
-
`Blocked: ${w.file} is a weakened test (${said(w)}); committing it needs a person's approval in force.
|
|
572
|
+
`Blocked: ${w.file} is a weakened test (${said(w)}); committing it needs ${leads ? "the lead's" : "a person's"} approval in force.
|
|
564
573
|
` +
|
|
565
574
|
(more.length
|
|
566
575
|
? `Also weakened: ${more.map((x) => `${x.file} (${said(x)})`).join('; ')}.
|
|
567
576
|
`
|
|
568
577
|
: '') +
|
|
569
|
-
`A weakened test can hide a regression. Fix the code so the test passes as it was.
|
|
570
|
-
|
|
578
|
+
`A weakened test can hide a regression. Fix the code so the test passes as it was. ` +
|
|
579
|
+
(leads
|
|
580
|
+
? `If the test itself is wrong, the lead decides after reviewing it: ${askHowTo(TESTS_APPROVAL, actor, root, config, { allows: 'weakening tests in one commit', need: 'the test, what you weakened and why the test was wrong, and the story' })}`
|
|
581
|
+
: `If the test itself is wrong, ask the person: ${actor.kind === 'lead' ? "on your own branch nobody else reviews it, so you can't approve it." : "the lead can't approve it here."} They run
|
|
582
|
+
${approvalHowTo(TESTS_APPROVAL, actor, root, 'weakening tests in one commit', personOnly)}`),
|
|
571
583
|
);
|
|
572
584
|
}
|
|
573
585
|
for (const w of weakened)
|
package/hooks/guard-paths.mjs
CHANGED
|
@@ -10,6 +10,7 @@ import { brokenLayerRule, layerProblems } from './lib/layers.mjs';
|
|
|
10
10
|
import { noteFor } from './lib/standards.mjs';
|
|
11
11
|
import { block, start } from './lib/hook.mjs';
|
|
12
12
|
import { teamOf, teamProvider, teamRefusal, whoami } from './lib/team.mjs';
|
|
13
|
+
import { sessionWriteProblem } from './lib/sessions.mjs';
|
|
13
14
|
import { spawnSync } from 'node:child_process';
|
|
14
15
|
import {
|
|
15
16
|
actorFor,
|
|
@@ -38,6 +39,16 @@ if (error) {
|
|
|
38
39
|
const problem = writeProblem(actorFor(input, root, config), rel, root, config);
|
|
39
40
|
if (problem) block(`Blocked: ${problem}`);
|
|
40
41
|
|
|
42
|
+
// SESS-4, SESS-5: another session's task leases the path, or a working session writes where it shouldn't.
|
|
43
|
+
const shared = sessionWriteProblem({
|
|
44
|
+
project,
|
|
45
|
+
root,
|
|
46
|
+
rel,
|
|
47
|
+
actor: actorFor(input, root, config),
|
|
48
|
+
session: input.session_id ?? null,
|
|
49
|
+
});
|
|
50
|
+
if (shared) block(`Blocked: ${shared}`);
|
|
51
|
+
|
|
41
52
|
// TEAM-1, TEAM-4: in a team, the tech lead's paths, other people's lanes, claims and leases.
|
|
42
53
|
const team = teamOf(config);
|
|
43
54
|
if (team) {
|
package/hooks/hooks.json
CHANGED
|
@@ -22,6 +22,16 @@
|
|
|
22
22
|
"timeout": 30
|
|
23
23
|
}
|
|
24
24
|
]
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"matcher": "Agent|Task",
|
|
28
|
+
"hooks": [
|
|
29
|
+
{
|
|
30
|
+
"type": "command",
|
|
31
|
+
"command": "node \"${CLAUDE_PLUGIN_ROOT}/hooks/guard-agent.mjs\"",
|
|
32
|
+
"timeout": 10
|
|
33
|
+
}
|
|
34
|
+
]
|
|
25
35
|
}
|
|
26
36
|
],
|
|
27
37
|
"PostToolUse": [
|
|
@@ -53,6 +63,11 @@
|
|
|
53
63
|
"type": "command",
|
|
54
64
|
"command": "node \"${CLAUDE_PLUGIN_ROOT}/hooks/team-session.mjs\" start",
|
|
55
65
|
"timeout": 10
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
"type": "command",
|
|
69
|
+
"command": "node \"${CLAUDE_PLUGIN_ROOT}/hooks/session.mjs\" start",
|
|
70
|
+
"timeout": 10
|
|
56
71
|
}
|
|
57
72
|
]
|
|
58
73
|
}
|
|
@@ -64,6 +79,11 @@
|
|
|
64
79
|
"type": "command",
|
|
65
80
|
"command": "node \"${CLAUDE_PLUGIN_ROOT}/hooks/team-session.mjs\" end",
|
|
66
81
|
"timeout": 10
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
"type": "command",
|
|
85
|
+
"command": "node \"${CLAUDE_PLUGIN_ROOT}/hooks/session.mjs\" end",
|
|
86
|
+
"timeout": 10
|
|
67
87
|
}
|
|
68
88
|
]
|
|
69
89
|
}
|