@ngockhoale/ckit 0.1.0 → 0.2.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/.env.example +12 -33
- package/README.md +15 -57
- package/dist/src/cli/ckit.js +6 -94
- package/dist/src/cli/lifecycle.d.ts +19 -0
- package/dist/src/cli/lifecycle.js +90 -0
- package/dist/src/cli/setup.js +1 -1
- package/dist/src/gui/server.js +60 -6
- package/dist/src/team/cli-args.d.ts +10 -0
- package/dist/src/team/cli-args.js +58 -0
- package/dist/src/team/config.js +208 -9
- package/dist/src/team/engine.d.ts +19 -1
- package/dist/src/team/engine.js +503 -109
- package/dist/src/team/runners.d.ts +6 -0
- package/dist/src/team/runners.js +47 -13
- package/dist/src/team/types.d.ts +92 -10
- package/dist/src/team/types.js +17 -1
- package/dist/src/tui/team/app.js +12 -12
- package/dist/src/tui/team/model.d.ts +23 -12
- package/dist/src/tui/team/model.js +25 -9
- package/gui/app.css +21 -1
- package/gui/app.js +310 -63
- package/gui/index.html +2 -2
- package/gui/network.js +38 -13
- package/package.json +2 -3
package/dist/src/team/config.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Team config: defaults, strict validation, load/write of <root>/.ckit/team.json.
|
|
2
2
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
3
3
|
import { dirname, join } from 'node:path';
|
|
4
|
+
import { splitCliArgs } from './cli-args.js';
|
|
4
5
|
const agent = (id, name, team, cli, access) => ({ id, name, team, cli, model: null, access });
|
|
5
6
|
export function defaultTeamConfig() {
|
|
6
7
|
return {
|
|
@@ -29,11 +30,12 @@ export function parseTeamConfig(json) {
|
|
|
29
30
|
return null;
|
|
30
31
|
}
|
|
31
32
|
const n = errors.length;
|
|
32
|
-
const
|
|
33
|
+
const cliArgsRaw = raw['cliArgs'];
|
|
34
|
+
const id = raw['id'], name = raw['name'], cli = raw['cli'], model = raw['model'] ?? null, access = raw['access'] ?? 'read', persona = raw['persona'], short = raw['short'];
|
|
33
35
|
if (typeof id !== 'string' || !ID_RE.test(id))
|
|
34
36
|
errors.push(`${path}.id must match ${ID_RE}`);
|
|
35
37
|
else if (seen.has(id))
|
|
36
|
-
errors.push(`${path}.id "${id}" is
|
|
38
|
+
errors.push(`${path}.id "${id}" is already used by another agent; every agent id must be unique across all teams (change this id, e.g. "${id}-2")`);
|
|
37
39
|
else
|
|
38
40
|
seen.add(id);
|
|
39
41
|
if (typeof name !== 'string' || !name.trim())
|
|
@@ -43,13 +45,31 @@ export function parseTeamConfig(json) {
|
|
|
43
45
|
else if (cli === 'auto' && team !== 'director')
|
|
44
46
|
errors.push(`${path}.cli "auto" is only valid for the director`);
|
|
45
47
|
if (raw['team'] !== undefined && raw['team'] !== team)
|
|
46
|
-
errors.push(`${path}.team
|
|
48
|
+
errors.push(`${path}.team is "${String(raw['team'])}" but this agent sits in team "${team}"; set team to "${team}" or leave it out`);
|
|
47
49
|
if (model !== null && (typeof model !== 'string' || !model.trim()))
|
|
48
50
|
errors.push(`${path}.model must be a string or null`);
|
|
49
51
|
if (access !== 'read' && access !== 'write')
|
|
50
52
|
errors.push(`${path}.access must be read|write`);
|
|
51
53
|
if (persona !== undefined && typeof persona !== 'string')
|
|
52
54
|
errors.push(`${path}.persona must be a string`);
|
|
55
|
+
if (short !== undefined && (typeof short !== 'string' || !/^[\p{L}\p{N}]{1,4}$/u.test(short)))
|
|
56
|
+
errors.push(`${path}.short must be 1-4 letters or digits`);
|
|
57
|
+
let cliArgs;
|
|
58
|
+
if (cliArgsRaw !== undefined && cliArgsRaw !== null) {
|
|
59
|
+
if (typeof cliArgsRaw !== 'string')
|
|
60
|
+
errors.push(`${path}.cliArgs must be a string`);
|
|
61
|
+
else if (cliArgsRaw.length > 500)
|
|
62
|
+
errors.push(`${path}.cliArgs is ${cliArgsRaw.length} characters; the limit is 500`);
|
|
63
|
+
else if (/[\n\r\0]/.test(cliArgsRaw))
|
|
64
|
+
errors.push(`${path}.cliArgs must be a single line (no line breaks or NUL characters)`);
|
|
65
|
+
else if (cliArgsRaw.trim()) {
|
|
66
|
+
const sp = splitCliArgs(cliArgsRaw);
|
|
67
|
+
if (!sp.ok)
|
|
68
|
+
errors.push(`${path}.cliArgs ${sp.error}; close the quote or remove it`);
|
|
69
|
+
else
|
|
70
|
+
cliArgs = cliArgsRaw.trim();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
53
73
|
const baseUrl = raw['baseUrl'], apiKeyRef = raw['apiKeyRef'];
|
|
54
74
|
if (baseUrl !== undefined && (typeof baseUrl !== 'string' || !/^https?:\/\/[^\s/]+/i.test(baseUrl)))
|
|
55
75
|
errors.push(`${path}.baseUrl must be an http(s) URL`);
|
|
@@ -57,19 +77,180 @@ export function parseTeamConfig(json) {
|
|
|
57
77
|
errors.push(`${path}.apiKeyRef must match /^[A-Za-z0-9_-]{1,64}$/`);
|
|
58
78
|
if (errors.length > n)
|
|
59
79
|
return null;
|
|
60
|
-
return { id: id, name: name, team, cli: cli, model: model, access: access, ...(typeof persona === 'string' ? { persona } : {}), ...(typeof baseUrl === 'string' ? { baseUrl: baseUrl.replace(/\/+$/, '') } : {}), ...(typeof apiKeyRef === 'string' ? { apiKeyRef } : {}) };
|
|
80
|
+
return { id: id, name: name, team, cli: cli, model: model, access: access, ...(typeof persona === 'string' ? { persona } : {}), ...(typeof short === 'string' ? { short: short.toUpperCase() } : {}), ...(cliArgs ? { cliArgs } : {}), ...(typeof baseUrl === 'string' ? { baseUrl: baseUrl.replace(/\/+$/, '') } : {}), ...(typeof apiKeyRef === 'string' ? { apiKeyRef } : {}) };
|
|
61
81
|
};
|
|
62
82
|
const director = parseAgent(json['director'], 'director', 'director');
|
|
63
|
-
const teams = isObj(json['teams']) ? json['teams'] : (errors.push('teams must be an object'), {});
|
|
83
|
+
const teams = json['teams'] === undefined ? {} : isObj(json['teams']) ? json['teams'] : (errors.push('teams must be an object'), {});
|
|
84
|
+
for (const k of Object.keys(teams))
|
|
85
|
+
if (k !== 'ba' && k !== 'implement' && k !== 'qc')
|
|
86
|
+
errors.push(`teams.${k} is not a built-in team: "teams" only holds ba, implement and qc. To add your own team use the "+ Add team" button in Config, or put it under "extraTeams" ({"id": "${k}", "name": "...", "mission": "...", "runAfter": "implement", "agents": [...]}) and give its agents new unique ids`);
|
|
64
87
|
const list = (team) => {
|
|
65
|
-
const raw = teams[team];
|
|
66
|
-
if (!Array.isArray(raw)
|
|
67
|
-
errors.push(`teams.${team}
|
|
88
|
+
const raw = teams[team] ?? [];
|
|
89
|
+
if (!Array.isArray(raw)) {
|
|
90
|
+
errors.push(`teams.${team} must be an array of agents (empty or absent = no ${team} team)`);
|
|
68
91
|
return [];
|
|
69
92
|
}
|
|
70
93
|
return raw.map((r, i) => parseAgent(r, team, `teams.${team}[${i}]`)).filter((a) => a !== null);
|
|
71
94
|
};
|
|
72
95
|
const ba = list('ba'), implement = list('implement'), qc = list('qc');
|
|
96
|
+
const missions = {};
|
|
97
|
+
if (json['missions'] !== undefined) {
|
|
98
|
+
if (!isObj(json['missions']))
|
|
99
|
+
errors.push('missions must be an object like {"qc": "..."}');
|
|
100
|
+
else
|
|
101
|
+
for (const k of Object.keys(json['missions'])) {
|
|
102
|
+
const v = json['missions'][k];
|
|
103
|
+
if (k !== 'ba' && k !== 'implement' && k !== 'qc')
|
|
104
|
+
errors.push(`missions.${k} is not a built-in team (use ba, implement or qc; extra teams carry their own mission)`);
|
|
105
|
+
else if (typeof v !== 'string' || !v.trim())
|
|
106
|
+
errors.push(`missions.${k} must be a non-empty string`);
|
|
107
|
+
else
|
|
108
|
+
missions[k] = v.trim();
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
const extraTeams = [];
|
|
112
|
+
const rawExtra = json['extraTeams'];
|
|
113
|
+
if (rawExtra !== undefined) {
|
|
114
|
+
if (!Array.isArray(rawExtra))
|
|
115
|
+
errors.push('extraTeams must be an array');
|
|
116
|
+
else {
|
|
117
|
+
const teamIds = new Set(['director', 'ba', 'implement', 'qc']);
|
|
118
|
+
rawExtra.forEach((t, i) => {
|
|
119
|
+
const path = `extraTeams[${i}]`;
|
|
120
|
+
if (!isObj(t)) {
|
|
121
|
+
errors.push(`${path} must be an object`);
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
const id = t['id'], name = t['name'], mission = t['mission'], runAfter = t['runAfter'];
|
|
125
|
+
let idOk = false;
|
|
126
|
+
if (typeof id !== 'string' || !ID_RE.test(id))
|
|
127
|
+
errors.push(`${path}.id must match ${ID_RE}`);
|
|
128
|
+
else if (teamIds.has(id))
|
|
129
|
+
errors.push(`${path}.id "${id}" is already a team id (director, ba, implement, qc and other extra teams are taken)`);
|
|
130
|
+
else {
|
|
131
|
+
teamIds.add(id);
|
|
132
|
+
idOk = true;
|
|
133
|
+
}
|
|
134
|
+
if (typeof name !== 'string' || !name.trim())
|
|
135
|
+
errors.push(`${path}.name must be a non-empty string`);
|
|
136
|
+
if (typeof mission !== 'string' || !mission.trim())
|
|
137
|
+
errors.push(`${path}.mission must say what this team does`);
|
|
138
|
+
const raOk = runAfter === undefined || runAfter === 'ba' || runAfter === 'implement' || runAfter === 'qc';
|
|
139
|
+
if (!raOk)
|
|
140
|
+
errors.push(`${path}.runAfter must be ba|implement|qc (old files only; use the top-level "order" list instead)`);
|
|
141
|
+
const rawAgents = t['agents'];
|
|
142
|
+
if (!Array.isArray(rawAgents) || rawAgents.length < 1) {
|
|
143
|
+
errors.push(`${path}.agents needs at least one agent`);
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
const agents = rawAgents.map((r, k) => parseAgent(r, idOk ? id : 'extra', `${path}.agents[${k}]`)).filter((a) => a !== null);
|
|
147
|
+
if (idOk && typeof name === 'string' && name.trim() && typeof mission === 'string' && mission.trim() && raOk && agents.length === rawAgents.length)
|
|
148
|
+
extraTeams.push({ id: id, name: name.trim(), mission: mission.trim(), ...(runAfter ? { runAfter: runAfter } : {}), agents });
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
let order;
|
|
153
|
+
if (json['order'] !== undefined) {
|
|
154
|
+
const raw = json['order'];
|
|
155
|
+
if (!Array.isArray(raw))
|
|
156
|
+
errors.push('order must be a list of team ids, e.g. ["ba", "implement", "test", "qc"]');
|
|
157
|
+
else {
|
|
158
|
+
const withAgents = new Set([...(ba.length ? ['ba'] : []), ...(implement.length ? ['implement'] : []), ...(qc.length ? ['qc'] : []), ...extraTeams.map(t => t.id)]);
|
|
159
|
+
const known = new Set([...withAgents, 'ba', 'implement', 'qc', ...extraTeams.map(t => t.id)]);
|
|
160
|
+
const got = new Set(), list = [];
|
|
161
|
+
raw.forEach((v, i) => {
|
|
162
|
+
if (typeof v !== 'string') {
|
|
163
|
+
errors.push(`order[${i}] must be a team id (string)`);
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
if (v === 'director')
|
|
167
|
+
errors.push(`order[${i}] is "director": the Director always comes first and is not part of the list`);
|
|
168
|
+
else if (!known.has(v))
|
|
169
|
+
errors.push(`order[${i}] "${v}" is not a team of this company (known teams: ${[...withAgents].join(', ') || 'none'})`);
|
|
170
|
+
else if (!withAgents.has(v))
|
|
171
|
+
errors.push(`order[${i}] "${v}" has no agents; leave empty teams out of the order`);
|
|
172
|
+
else if (got.has(v))
|
|
173
|
+
errors.push(`order[${i}] "${v}" appears twice; each team must be listed exactly once`);
|
|
174
|
+
else {
|
|
175
|
+
got.add(v);
|
|
176
|
+
list.push(v);
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
const missing = [...withAgents].filter(id => !got.has(id));
|
|
180
|
+
if (missing.length)
|
|
181
|
+
errors.push(`order is missing team(s) that have agents: ${missing.join(', ')}; every team with agents must be in the order`);
|
|
182
|
+
order = list;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
let lanes;
|
|
186
|
+
if (json['lanes'] !== undefined && json['lanes'] !== null) {
|
|
187
|
+
const raw = json['lanes'];
|
|
188
|
+
if (!Array.isArray(raw))
|
|
189
|
+
errors.push('lanes must be a list of {id, name, when, order}');
|
|
190
|
+
else if (raw.length) {
|
|
191
|
+
const withAgents = new Set([...(ba.length ? ['ba'] : []), ...(implement.length ? ['implement'] : []), ...(qc.length ? ['qc'] : []), ...extraTeams.map(t => t.id)]);
|
|
192
|
+
const seen = new Set(), list = [];
|
|
193
|
+
raw.forEach((l, i) => {
|
|
194
|
+
const p = `lanes[${i}]`;
|
|
195
|
+
if (!isObj(l)) {
|
|
196
|
+
errors.push(`${p} must be an object`);
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
const id = l['id'], name = l['name'], when = l['when'], ord = l['order'];
|
|
200
|
+
let ok = true;
|
|
201
|
+
if (typeof id !== 'string' || !ID_RE.test(id) || id === 'director') {
|
|
202
|
+
errors.push(`${p}.id must be lowercase letters, digits or dashes`);
|
|
203
|
+
ok = false;
|
|
204
|
+
}
|
|
205
|
+
else if (seen.has(id)) {
|
|
206
|
+
errors.push(`${p}.id "${id}" is used by another lane; lane ids must be unique`);
|
|
207
|
+
ok = false;
|
|
208
|
+
}
|
|
209
|
+
else
|
|
210
|
+
seen.add(id);
|
|
211
|
+
if (typeof name !== 'string' || !name.trim()) {
|
|
212
|
+
errors.push(`${p}.name must not be empty`);
|
|
213
|
+
ok = false;
|
|
214
|
+
}
|
|
215
|
+
if (typeof when !== 'string' || !when.trim()) {
|
|
216
|
+
errors.push(`${p}.when must say what kind of request belongs in this lane`);
|
|
217
|
+
ok = false;
|
|
218
|
+
}
|
|
219
|
+
const got = new Set(), seq = [];
|
|
220
|
+
if (!Array.isArray(ord) || ord.length === 0) {
|
|
221
|
+
errors.push(`${p}${typeof name === 'string' && name.trim() ? ` ("${name.trim()}")` : ''} has no teams; add at least one team or remove the lane`);
|
|
222
|
+
ok = false;
|
|
223
|
+
}
|
|
224
|
+
else
|
|
225
|
+
ord.forEach((v, k) => {
|
|
226
|
+
if (typeof v !== 'string') {
|
|
227
|
+
errors.push(`${p}.order[${k}] must be a team id (string)`);
|
|
228
|
+
ok = false;
|
|
229
|
+
}
|
|
230
|
+
else if (v === 'director') {
|
|
231
|
+
errors.push(`${p}.order[${k}] is "director": the Director is not part of a lane`);
|
|
232
|
+
ok = false;
|
|
233
|
+
}
|
|
234
|
+
else if (!withAgents.has(v)) {
|
|
235
|
+
errors.push(`${p}.order[${k}] "${v}" is not a team with agents (teams: ${[...withAgents].join(', ') || 'none'})`);
|
|
236
|
+
ok = false;
|
|
237
|
+
}
|
|
238
|
+
else if (got.has(v)) {
|
|
239
|
+
errors.push(`${p}.order[${k}] "${v}" appears twice in this lane`);
|
|
240
|
+
ok = false;
|
|
241
|
+
}
|
|
242
|
+
else {
|
|
243
|
+
got.add(v);
|
|
244
|
+
seq.push(v);
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
if (ok)
|
|
248
|
+
list.push({ id: id, name: name.trim(), when: when.trim(), order: seq });
|
|
249
|
+
});
|
|
250
|
+
if (list.length === raw.length)
|
|
251
|
+
lanes = list;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
73
254
|
const lim = isObj(json['limits']) ? json['limits'] : (errors.push('limits must be an object'), {});
|
|
74
255
|
const int = (key, lo, hi) => {
|
|
75
256
|
const v = lim[key];
|
|
@@ -79,10 +260,28 @@ export function parseTeamConfig(json) {
|
|
|
79
260
|
}
|
|
80
261
|
return v;
|
|
81
262
|
};
|
|
263
|
+
let directorReview, systemPrompt;
|
|
264
|
+
if (json['directorReview'] !== undefined && json['directorReview'] !== null) {
|
|
265
|
+
if (typeof json['directorReview'] !== 'boolean')
|
|
266
|
+
errors.push('directorReview must be true or false');
|
|
267
|
+
else if (!json['directorReview'])
|
|
268
|
+
directorReview = false; // true is the default: keep the file small
|
|
269
|
+
}
|
|
270
|
+
const sp = json['systemPrompt'];
|
|
271
|
+
if (sp !== undefined && sp !== null) {
|
|
272
|
+
if (typeof sp !== 'string')
|
|
273
|
+
errors.push('systemPrompt must be a string');
|
|
274
|
+
else if (sp.length > 8000)
|
|
275
|
+
errors.push(`systemPrompt is ${sp.length} characters; the limit is 8000`);
|
|
276
|
+
else if (sp.includes('\0'))
|
|
277
|
+
errors.push('systemPrompt must not contain NUL characters');
|
|
278
|
+
else if (sp.trim())
|
|
279
|
+
systemPrompt = sp.trim();
|
|
280
|
+
}
|
|
82
281
|
const limits = { baRounds: int('baRounds', 1, 10), qcLoops: int('qcLoops', 0, 10), agentTimeoutMs: int('agentTimeoutMs', 1000, 7200000) };
|
|
83
282
|
if (errors.length || !director)
|
|
84
283
|
return { ok: false, errors };
|
|
85
|
-
return { ok: true, config: { version: 1, director, teams: { ba, implement, qc }, limits } };
|
|
284
|
+
return { ok: true, config: { version: 1, director, teams: { ba, implement, qc }, ...(Object.keys(missions).length ? { missions } : {}), ...(extraTeams.length ? { extraTeams } : {}), ...(order ? { order } : {}), ...(lanes ? { lanes } : {}), ...(directorReview === false ? { directorReview } : {}), ...(systemPrompt ? { systemPrompt } : {}), limits } };
|
|
86
285
|
}
|
|
87
286
|
export const teamConfigPath = (root) => join(root, '.ckit', 'team.json');
|
|
88
287
|
/** Missing file -> default. Present but invalid/unreadable -> ok:false with errors (never silently default). */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type AttachmentInput } from './attachments.js';
|
|
2
2
|
import { type AgentRunner } from './runners.js';
|
|
3
|
-
import type
|
|
3
|
+
import { type TeamConfig, type TeamRunHandle } from './types.js';
|
|
4
4
|
export interface StartTeamRunOptions {
|
|
5
5
|
readonly projectRoot: string;
|
|
6
6
|
readonly goal: string;
|
|
@@ -13,6 +13,8 @@ export interface StartTeamRunOptions {
|
|
|
13
13
|
readonly simSpeed?: number;
|
|
14
14
|
/** Files the owner attached to the request (any type). Copied into the run folder; every agent turn is told where they are. */
|
|
15
15
|
readonly attachments?: readonly AttachmentInput[];
|
|
16
|
+
/** Lane id fixed by the owner (only when the config has lanes); absent = the Director decides. */
|
|
17
|
+
readonly lane?: string;
|
|
16
18
|
}
|
|
17
19
|
/** Pure rule-based owner-chat decision (director cli 'auto', and the fallback for model directors). */
|
|
18
20
|
export declare function ruleDecision(text: string): {
|
|
@@ -21,6 +23,22 @@ export declare function ruleDecision(text: string): {
|
|
|
21
23
|
};
|
|
22
24
|
/** Last `VERDICT: PASS|FAIL` wins; no verdict at all counts as FAIL (conservative). */
|
|
23
25
|
export declare function parseVerdict(text: string): 'PASS' | 'FAIL';
|
|
26
|
+
export interface DirectorDecision {
|
|
27
|
+
readonly kind: 'proceed' | 'need' | 'cannot';
|
|
28
|
+
readonly body: string;
|
|
29
|
+
readonly questions: string;
|
|
30
|
+
readonly assumptions: string;
|
|
31
|
+
readonly reason: string;
|
|
32
|
+
readonly alternatives: string;
|
|
33
|
+
}
|
|
34
|
+
/** The Director's first-turn decision line (lenient: case, bullets, bold, dashes). No decision line = PROCEED. Never throws. */
|
|
35
|
+
export declare function parseDirectorDecision(text: string): DirectorDecision;
|
|
36
|
+
export type HandoffSection = 'DONE' | 'DECISIONS' | 'OPEN' | 'FOR YOU';
|
|
37
|
+
export declare const HANDOFF_SECTIONS: readonly HandoffSection[];
|
|
38
|
+
/** Reads the four handoff sections out of a team lead's message. null when any is missing (callers fall back to the raw message). Never throws. */
|
|
39
|
+
export declare function parseHandoff(text: string): Record<HandoffSection, string> | null;
|
|
40
|
+
/** Last `REVIEW: PASS|FAIL` wins; null when no verdict line exists. */
|
|
41
|
+
export declare function parseReview(text: string): 'PASS' | 'FAIL' | null;
|
|
24
42
|
export declare function startTeamRun(opts: StartTeamRunOptions): TeamRunHandle;
|
|
25
43
|
/** Re-emits a journal with original relative timing / speed (gaps capped at 1.5s/speed). */
|
|
26
44
|
export declare function replayTeamRun(runDir: string, opts?: {
|