@ngockhoale/ckit 0.1.1 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -1
- package/dist/src/gui/server.js +72 -6
- package/dist/src/team/cli-args.d.ts +12 -0
- package/dist/src/team/cli-args.js +69 -0
- package/dist/src/team/config.js +205 -8
- 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 +90 -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 +31 -0
- package/gui/app.js +333 -65
- package/gui/index.html +2 -2
- package/gui/network.js +34 -9
- package/package.json +1 -1
package/gui/app.js
CHANGED
|
@@ -7,10 +7,8 @@
|
|
|
7
7
|
var SHOT = Q.get('shot') || '', CLIS = [], CHECK = {};
|
|
8
8
|
var TC = {director: '#A36BFF', ba: '#21D6E8', implement: '#F3A544', qc: '#4AD69A'};
|
|
9
9
|
var TL = {director: 'DIRECTOR', ba: 'TEAM BA', implement: 'TEAM IMPLEMENT', qc: 'TEAM QC'};
|
|
10
|
-
var
|
|
11
|
-
var
|
|
12
|
-
var PHASE = {'director-intake': 'Director intake', 'ba-discussion': 'BA internal discussion', 'implement': 'Implement team at work', 'qc': 'QC inspection', 'ba-review': 'BA review', 'delivery': 'Delivery'};
|
|
13
|
-
var STAGE_TEAM = {'director-intake': 'director', 'ba-discussion': 'ba', 'implement': 'implement', 'qc': 'qc', 'ba-review': 'ba', 'delivery': 'director'};
|
|
10
|
+
var PHASE = {'director-intake': 'Director intake', 'ba-discussion': 'BA internal discussion', 'implement': 'Implement team at work', 'qc': 'QC inspection', 'review': 'Director review', 'delivery': 'Delivery'};
|
|
11
|
+
var STAGE_TEAM = {'director-intake': 'director', 'ba-discussion': 'ba', 'implement': 'implement', 'qc': 'qc', 'review': 'director', 'delivery': 'director'};
|
|
14
12
|
var $ = function (id) { return document.getElementById(id); };
|
|
15
13
|
function h(tag, attrs, kids) {
|
|
16
14
|
var e = document.createElement(tag);
|
|
@@ -32,45 +30,76 @@
|
|
|
32
30
|
function clock(iso) { var d = new Date(iso); return isNaN(d) ? '' : d.toTimeString().slice(0, 8); }
|
|
33
31
|
|
|
34
32
|
var S = {config: null, view: 'live', comic: false, run: null, agents: {}, order: [], events: [], msgs: 0, tokens: 0, stageIdx: -1, loop: 1, stageTimes: {}, selected: null,
|
|
35
|
-
started: 0, ended: 0, outcome: null, replay: false, history: true, buckets: [], tokBuckets: [], handoffs: [], verdicts: [], lastStageAt: 0, dirty: true, bubbles: {}, narr: '', lastPanelSub: {}, lastAt: 0};
|
|
33
|
+
started: 0, ended: 0, outcome: null, replay: false, history: true, buckets: [], tokBuckets: [], handoffs: [], flowBacks: [], verdicts: [], lastStageAt: 0, dirty: true, bubbles: {}, narr: '', lastPanelSub: {}, lastAt: 0};
|
|
36
34
|
var net = window.CKNet.create($('net'));
|
|
37
35
|
window.__ck = {S: S, net: net};
|
|
38
36
|
|
|
39
|
-
|
|
37
|
+
var XPAL = ['#FF6B8A', '#8BE04E', '#4F9DFF', '#FF8A4C', '#E0C341', '#B58CFF'], BUILTIN = {director: 1, ba: 1, implement: 1, qc: 1};
|
|
38
|
+
var DEFAULT_MISSION = {ba: 'Turn the goal into one clear handoff: scope, testable acceptance criteria, out of scope, risks. Afterwards check the finished work against it.', implement: 'Build what the handoff asks for in the project: change the code, run the checks, report what changed and how to verify.', qc: 'Independently review and test the deliverable against the acceptance criteria and give a PASS or FAIL verdict with reasons.'};
|
|
39
|
+
function extrasOf(cfg) { return (cfg && cfg.extraTeams) || []; }
|
|
40
|
+
function cfgAgents(cfg) { var x = []; extrasOf(cfg).forEach(function (t) { x = x.concat(t.agents); }); return [cfg.director].concat(cfg.teams.ba || [], cfg.teams.implement || [], cfg.teams.qc || [], x); }
|
|
41
|
+
/* extra teams get a colour from the palette (index = position in extraTeams) and a label; shared with the canvas through the CKNet colour table */
|
|
42
|
+
function registerTeams(cfg) {
|
|
43
|
+
Object.keys(TC).forEach(function (k) { if (!BUILTIN[k]) { delete TC[k]; delete TL[k]; delete window.CKNet.TEAM_COLOR[k]; delete window.CKNet.TEAM_LABEL[k]; } });
|
|
44
|
+
extrasOf(cfg).forEach(function (t, i) { TC[t.id] = XPAL[i % XPAL.length]; TL[t.id] = 'TEAM ' + String(t.name).toUpperCase(); window.CKNet.TEAM_COLOR[t.id] = TC[t.id]; window.CKNet.TEAM_LABEL[t.id] = TL[t.id]; });
|
|
45
|
+
}
|
|
46
|
+
/* flow order: cfg.order wins, else ba, implement, qc with extra teams after the stage named by their legacy runAfter (mirrors effectiveOrder in src/team/types.ts) */
|
|
47
|
+
function orderOf(cfg) {
|
|
48
|
+
var has = function (id) { return BUILTIN[id] ? id !== 'director' && (cfg.teams[id] || []).length > 0 : extrasOf(cfg).some(function (t) { return t.id === id && t.agents.length > 0; }); };
|
|
49
|
+
var ids = (cfg.order || null);
|
|
50
|
+
if (ids) { var seen = {}, out = ids.filter(function (id) { if (seen[id] || !has(id)) return false; seen[id] = 1; return true; }); ['ba', 'implement', 'qc'].concat(extrasOf(cfg).map(function (t) { return t.id; })).forEach(function (id) { if (has(id) && !seen[id]) out.push(id); }); return out; }
|
|
51
|
+
var xs = function (after) { return extrasOf(cfg).filter(function (t) { return (t.runAfter || 'implement') === after; }).map(function (t) { return t.id; }); };
|
|
52
|
+
return ['ba'].concat(xs('ba'), ['implement'], xs('implement'), ['qc'], xs('qc')).filter(has);
|
|
53
|
+
}
|
|
54
|
+
/* strip stages in flow order; only teams that have agents (built-ins) appear, extra teams sit after the stage they run after */
|
|
55
|
+
function stageList(cfg) {
|
|
56
|
+
var out = [{key: 'director-intake', label: 'Director', team: 'director'}];
|
|
57
|
+
var chip = {ba: {key: 'ba-discussion', label: 'BA', team: 'ba'}, implement: {key: 'implement', label: 'Implement', team: 'implement'}, qc: {key: 'qc', label: 'QC', team: 'qc'}};
|
|
58
|
+
var lanes = (cfg && cfg.lanes) || [], ids = S.lane ? S.lane.order : lanes.length ? null : cfg ? orderOf(cfg) : ['ba', 'implement', 'qc'];
|
|
59
|
+
if (ids === null) out.push({key: 'lane?', label: '…', team: 'director'}); /* lanes exist and the Director has not chosen yet */
|
|
60
|
+
else ids.forEach(function (id) { if (chip[id]) out.push(chip[id]); else { var t = extrasOf(cfg).filter(function (x) { return x.id === id; })[0]; if (t) out.push({key: 'x:' + t.id, label: t.name, team: t.id}); } });
|
|
61
|
+
if (!cfg || cfg.directorReview !== false) out.push({key: 'review', label: 'Review', team: 'director'});
|
|
62
|
+
out.push({key: 'delivery', label: 'Delivery', team: 'director'});
|
|
63
|
+
return out;
|
|
64
|
+
}
|
|
40
65
|
function setupAgents(cfg) {
|
|
66
|
+
registerTeams(cfg); window.CKNet.TEAM_ORDER = orderOf(cfg);
|
|
41
67
|
S.agents = {}; S.order = [];
|
|
42
68
|
cfgAgents(cfg).forEach(function (a) { S.order.push(a.id); S.agents[a.id] = {cfg: a, state: 'idle', task: '', activity: '', step: 0, total: null, label: '', tokens: 0, t0: 0, spark: [], outputs: [], subs: {}, msgs: 0}; });
|
|
43
69
|
net.setAgents(cfgAgents(cfg));
|
|
44
70
|
}
|
|
45
71
|
function resetRun() {
|
|
46
|
-
S.events = []; S.atts = []; S.fails = []; S.msgs = 0; S.tokens = 0; S.stageIdx = -1; S.loop = 1; S.stageTimes = {}; S.started = 0; S.ended = 0; S.outcome = null; S.handoffs = []; S.verdicts = []; S.buckets = []; S.tokBuckets = []; S.lastStageAt = 0; S.narr = '';
|
|
72
|
+
S.events = []; S.atts = []; S.fails = []; S.msgs = 0; S.tokens = 0; S.stageIdx = -1; S.stageKey = ''; S.loop = 1; S.stageTimes = {}; S.started = 0; S.ended = 0; S.outcome = null; S.handoffs = []; S.flowBacks = []; S.verdicts = []; S.buckets = []; S.tokBuckets = []; S.lastStageAt = 0; S.narr = '';
|
|
47
73
|
$('feed').innerHTML = ''; $('comicpanels').innerHTML = ''; $('bubbles').innerHTML = ''; S.bubbles = {}; S.lastPanelSub = {};
|
|
48
74
|
$('overlay').hidden = true; $('hobanner').classList.remove('on');
|
|
75
|
+
S.lane = null; S.laneBy = ''; S.waiting = null; net.setActiveTeams(null);
|
|
49
76
|
if (S.config) setupAgents(S.config);
|
|
50
77
|
net.reset(); setNarr('Waiting for a mission…'); S.dirty = true;
|
|
51
78
|
}
|
|
52
79
|
function A(id) { return S.agents[id]; }
|
|
53
80
|
function nm(id) { return A(id) ? A(id).cfg.name : id === 'all' ? 'everyone' : TL[id] || id; }
|
|
54
|
-
function tcol(id) { return A(id) ? TC[A(id).cfg.team] : TC[id] || '#8A9AAF'; }
|
|
81
|
+
function tcol(id) { return A(id) ? TC[A(id).cfg.team] || '#8A9AAF' : TC[id] || '#8A9AAF'; }
|
|
55
82
|
function ini(id) { return A(id) ? net.initials(A(id).cfg) : '?'; }
|
|
56
|
-
function setNarr(t) { S.narr = t; $('nowtext').textContent = t; }
|
|
83
|
+
function setNarr(t) { S.narr = t; $('nowtext').textContent = t; $('now').classList.toggle('ask', !!S.waiting); }
|
|
57
84
|
|
|
58
85
|
function activeSubs() { var n = 0; S.order.forEach(function (id) { Object.keys(A(id).subs).forEach(function (k) { if (A(id).subs[k].state === 'run') n++; }); }); return n; }
|
|
59
86
|
function caption() {
|
|
60
|
-
var st =
|
|
61
|
-
if (S.outcome) c = S.outcome === 'delivered' ? '<b>Mission delivered</b> — báo cáo đã sẵn sàng' : '<b>Run ' + S.outcome + '</b>';
|
|
87
|
+
var st = S.stageKey && S.stageKey.slice(0, 2) === 'x:' ? 'x' : S.stageKey, n = activeSubs(), c;
|
|
88
|
+
if (S.outcome) c = S.outcome === 'delivered' ? '<b>Mission delivered</b> — báo cáo đã sẵn sàng' : S.outcome === 'declined' ? '<b>Director could not take this request</b> — no team started' : '<b>Run ' + S.outcome + '</b>';
|
|
89
|
+
else if (S.waiting) c = '<b>Director</b> is waiting for your answer — nothing is running';
|
|
62
90
|
else if (!st) c = 'Chờ nhiệm vụ…';
|
|
63
91
|
else if (st === 'director-intake') c = '<b>Director</b> đang tiếp nhận và phân tích yêu cầu';
|
|
64
92
|
else if (st === 'ba-discussion') c = '<b>Team BA</b> đang thảo luận yêu cầu (các BA tranh luận → HANDOFF)';
|
|
65
93
|
else if (st === 'implement') c = '<b>Implement</b> đang viết code' + (n ? ' — <b>' + n + ' subagent</b> đang hỗ trợ' : '') + (S.loop > 1 ? ' (sửa lỗi vòng ' + S.loop + ')' : '');
|
|
94
|
+
else if (S.stageKey && S.stageKey.slice(0, 2) === 'x:') c = '<b>' + (extrasOf(S.config).filter(function (t) { return 'x:' + t.id === S.stageKey; })[0] || {name: 'Team'}).name + '</b> đang làm việc';
|
|
66
95
|
else if (st === 'qc') c = '<b>QC</b> đang kiểm thử' + (n ? ' — ' + n + ' subagent hỗ trợ' : '') + (S.loop > 1 ? ' (QC loop ' + S.loop + ')' : '');
|
|
67
|
-
else if (st === '
|
|
96
|
+
else if (st === 'review') c = '<b>Director</b> đối chiếu kết quả với yêu cầu gốc';
|
|
68
97
|
else c = '<b>Director</b> đang tổng hợp báo cáo giao khách';
|
|
69
98
|
$('caption').innerHTML = c;
|
|
70
99
|
}
|
|
71
100
|
function narrate(st) {
|
|
72
101
|
var m = {'director-intake': 'Director nhận yêu cầu từ chủ dự án và giao cho Team BA.', 'ba-discussion': 'Team BA: hai analyst tranh luận để chốt yêu cầu, rồi tạo HANDOFF.', 'implement': 'Team Implement nhận HANDOFF và bắt đầu viết code' + (S.loop > 1 ? ' — sửa lỗi QC vừa tìm ra (vòng ' + S.loop + ').' : '.'),
|
|
73
|
-
'qc': 'Team QC kiểm tra sản phẩm' + (S.loop > 1 ? ' lần ' + S.loop + '.' : '.'), '
|
|
102
|
+
'extra-team': 'Một team bổ sung đang làm phần việc của mình.', 'qc': 'Team QC kiểm tra sản phẩm' + (S.loop > 1 ? ' lần ' + S.loop + '.' : '.'), 'review': 'Director đối chiếu kết quả với yêu cầu gốc.', 'delivery': 'Director tổng hợp báo cáo và giao hàng.'};
|
|
74
103
|
setNarr(m[st] || '');
|
|
75
104
|
}
|
|
76
105
|
|
|
@@ -148,19 +177,22 @@
|
|
|
148
177
|
S.events.push(e); S.dirty = true;
|
|
149
178
|
var now = performance.now(), a = e.agentId ? A(e.agentId) : null;
|
|
150
179
|
if (e.type === 'run.started') {
|
|
151
|
-
S.started = Date.parse(e.at); S.config = e.config; S.simulated = e.simulated; S.run = S.run || {}; S.run.runId = e.runId; S.run.goal = e.goal; S.run.running = true; setupAgents(e.config);
|
|
180
|
+
S.started = Date.parse(e.at); S.config = e.config; S.simulated = e.simulated; S.run = S.run || {}; S.run.runId = e.runId; S.run.goal = e.goal; S.run.running = true; S.lane = null; S.laneBy = ''; net.setActiveTeams(null); setupAgents(e.config);
|
|
152
181
|
$('goal').textContent = e.goal; $('goal').title = e.goal; $('runid').textContent = e.runId.replace('team-', '');
|
|
153
182
|
setNarr('Mission: ' + e.goal.slice(0, 120)); feedBanner('dir', '◆ MISSION STARTED — ' + e.goal); feedAtts(e.attachments);
|
|
154
183
|
comicCaption('Episode 1: ' + e.goal.slice(0, 90), 'director');
|
|
155
184
|
}
|
|
156
185
|
S.lastAt = Date.parse(e.at);
|
|
186
|
+
if (S.waiting && (e.type === 'agent.started' || e.type === 'user.message' || e.type === 'run.completed' || e.type === 'stage.changed')) { S.waiting = null; if (e.type !== 'run.completed') setNarr('Director is working on your answer…'); }
|
|
157
187
|
switch (e.type) {
|
|
158
188
|
case 'stage.changed': {
|
|
159
|
-
var
|
|
160
|
-
if (
|
|
161
|
-
S.
|
|
162
|
-
|
|
163
|
-
|
|
189
|
+
var xt = e.stage === 'extra-team' ? extrasOf(S.config).filter(function (t) { return t.id === e.team; })[0] : null;
|
|
190
|
+
if (e.stage === 'ba-review') break; /* journals written before the review stage was removed: shown as no stage of its own */
|
|
191
|
+
var prevKey = S.stageKey, key = xt ? 'x:' + xt.id : e.stage, sl = stageList(S.config), idx = Math.max(0, sl.map(function (z) { return z.key; }).indexOf(key));
|
|
192
|
+
if (prevKey && S.lastStageAt) S.stageTimes[prevKey + (e.loop > 1 && (prevKey === 'implement' || prevKey === 'qc') ? '#' + e.loop : '')] = Date.parse(e.at) - S.lastStageAt;
|
|
193
|
+
S.stageKey = key; S.lastStageAt = Date.parse(e.at); S.loop = e.loop; S.stageIdx = idx; net.setStage(idx, e.loop, sl.length); narrate(xt ? 'extra-team' : e.stage);
|
|
194
|
+
feedPhase(xt ? xt.name + ' team at work' + (e.loop > 1 ? ' · loop ' + e.loop : '') : PHASE[e.stage] + (e.loop > 1 ? ' · loop ' + e.loop : ''), xt ? xt.id : STAGE_TEAM[e.stage]);
|
|
195
|
+
comicCaption(e.stage === 'review' ? 'The Director checks the result against your request…' : xt ? 'Meanwhile, at Team ' + xt.name + '…' : ['Meanwhile, at the Director’s desk…', 'Team BA huddles to debate the requirements…', 'Meanwhile, at Team IMPLEMENT…' + (e.loop > 1 ? ' (round ' + e.loop + ')' : ''), 'Meanwhile, at Team QC…', 'The Director prepares the final report…'][e.stage === 'director-intake' ? 0 : e.stage === 'ba-discussion' ? 1 : e.stage === 'implement' ? 2 : e.stage === 'qc' ? 3 : 4], xt ? xt.id : STAGE_TEAM[e.stage]);
|
|
164
196
|
break;
|
|
165
197
|
}
|
|
166
198
|
case 'agent.started':
|
|
@@ -177,15 +209,33 @@
|
|
|
177
209
|
case 'agent.failed': if (a) { a.state = 'failed'; a.activity = e.reason; net.setState(e.agentId, 'failed'); } S.fails.push(e); feedBanner('fail', '✕ ' + nm(e.agentId) + ' failed: ' + plain(e.reason).slice(0, 220) + ' (click for details)', function () { showFailure(); }); break;
|
|
178
210
|
case 'handoff.created':
|
|
179
211
|
S.handoffs.push(e); if (!S.history) { net.handoff(e.from, e.to, e.title); showHoBanner('📦 HANDOFF ' + TL[e.from] + ' → ' + TL[e.to]); }
|
|
180
|
-
feedBanner('ho', '📦
|
|
212
|
+
feedBanner('ho', '📦 ' + teamLbl(e.from) + ' → ' + teamLbl(e.to) + ' · ' + e.title, e.text ? function () { showMessage({from: e.from, to: e.to, at: e.at, text: e.text}); } : null); comicHandoff(e);
|
|
181
213
|
S.order.forEach(function (id) { if (A(id).cfg.team === e.from) { A(id).state = 'idle'; net.setState(id, 'idle'); } });
|
|
182
214
|
break;
|
|
215
|
+
case 'flow.back': {
|
|
216
|
+
var fb = e.kind === 'ask' ? '? ' + teamLbl(e.from) + ' asked ' + teamLbl(e.to) + ': ' + e.reason : '↩ ' + teamLbl(e.from) + ' returned to ' + teamLbl(e.to) + ': ' + e.reason;
|
|
217
|
+
S.flowBacks.push(e); feedBanner(e.kind === 'ask' ? 'ask' : 'ret', fb);
|
|
218
|
+
comicSimple(e.kind === 'ask' ? 'director' : 'you', (e.kind === 'ask' ? 'ASK-BACK · ' : 'RETURN · ') + teamLbl(e.from) + ' → ' + teamLbl(e.to), e.reason);
|
|
219
|
+
break;
|
|
220
|
+
}
|
|
183
221
|
case 'qc.verdict': S.verdicts.push(e); if (!S.history) net.verdict(e.verdict);
|
|
184
222
|
feedBanner(e.verdict === 'PASS' ? 'pass' : 'fail', (e.verdict === 'PASS' ? '✔ QC PASS' : '✕ QC FAIL') + ' · loop ' + e.loop + ' — ' + e.summary);
|
|
185
223
|
comicVerdict(e); setNarr(e.verdict === 'FAIL' ? 'QC phát hiện lỗi → trả về Implement để sửa.' : 'QC PASS — sản phẩm đạt yêu cầu!');
|
|
186
224
|
break;
|
|
187
225
|
case 'user.message': feedBanner('you', '▸ OWNER: ' + e.text); feedAtts(e.attachments); comicSimple('you', 'OWNER', e.text + (e.attachments && e.attachments.length ? ' 📎 ' + e.attachments.length + ' file(s)' : '')); break;
|
|
188
226
|
case 'director.decision': feedBanner('dir', '◆ DIRECTOR ' + e.decision.toUpperCase() + ' — ' + e.note); comicSimple('director', 'DIRECTOR · ' + e.decision.toUpperCase(), e.note); break;
|
|
227
|
+
case 'lane.chosen': {
|
|
228
|
+
var ln = ((S.config && S.config.lanes) || []).filter(function (l) { return l.id === e.laneId; })[0];
|
|
229
|
+
S.lane = ln ? {id: ln.id, name: ln.name, order: ln.order.slice()} : {id: e.laneId, name: e.name, order: []}; S.laneBy = e.by; net.setActiveTeams(S.lane.order);
|
|
230
|
+
feedBanner('dir', e.by === 'owner' ? '◆ Owner fixed lane ' + e.name : e.by === 'fallback' ? '◆ Lane chosen by fallback: ' + e.name + (e.reason ? ' · ' + e.reason : '') : '◆ Director chose lane ' + e.name + ': ' + e.reason);
|
|
231
|
+
comicSimple('director', 'LANE · ' + e.name, e.reason || e.by);
|
|
232
|
+
break;
|
|
233
|
+
}
|
|
234
|
+
case 'review.verdict': S.verdicts.push(e); if (!S.history) net.verdict(e.verdict);
|
|
235
|
+
feedBanner(e.verdict === 'PASS' ? 'pass' : 'fail', 'Director review · ' + e.verdict + ' — ' + e.summary);
|
|
236
|
+
comicSimple('director', 'DIRECTOR REVIEW · ' + e.verdict, e.summary);
|
|
237
|
+
break;
|
|
238
|
+
case 'run.waiting': S.waiting = {round: e.round, questions: e.questions, assumptions: e.assumptions}; feedQuestions(e); setNarr('Director needs your answer'); break;
|
|
189
239
|
case 'subagent.started':
|
|
190
240
|
if (a) { a.subs[e.childId] = {kind: e.kind || 'sub', text: e.task, state: 'run'}; net.spawnSub(e.agentId, e.childId, e.kind); feedSub(e.agentId, '◆ spawned ' + (e.kind || 'subagent') + ': ' + e.task); comicSub(e); }
|
|
191
241
|
break;
|
|
@@ -193,10 +243,11 @@
|
|
|
193
243
|
case 'subagent.finished': if (a && a.subs[e.childId]) { a.subs[e.childId].state = e.ok ? 'done' : 'failed'; net.finishSub(e.childId, e.ok); feedSub(e.agentId, (e.ok ? '✓ ' : '✕ ') + a.subs[e.childId].kind + ': ' + e.summary); } break;
|
|
194
244
|
case 'run.completed':
|
|
195
245
|
S.ended = Date.parse(e.at); S.outcome = e.outcome; S.reportText = e.report; if (S.run) S.run.running = false;
|
|
196
|
-
if (S.
|
|
197
|
-
if (e.outcome === 'delivered') { S.stageIdx =
|
|
246
|
+
if (S.stageKey) S.stageTimes[S.stageKey] = Date.parse(e.at) - S.lastStageAt;
|
|
247
|
+
if (e.outcome === 'delivered') { var sl2 = stageList(S.config); S.stageIdx = sl2.length; S.stageKey = 'done'; net.setStage(sl2.length, S.loop, sl2.length); }
|
|
198
248
|
S.order.forEach(function (id) { if (A(id).state === 'thinking') { A(id).state = 'idle'; net.setState(id, 'idle'); } });
|
|
199
|
-
|
|
249
|
+
if (e.outcome === 'declined') feedBanner('fail', '◆ Director could not take this request');
|
|
250
|
+
setNarr(e.outcome === 'delivered' ? 'MISSION DELIVERED ✔' : e.outcome === 'declined' ? 'Director could not take this request' : 'Run ended: ' + e.outcome + (e.outcome === 'failed' ? ' · click to see why' : '')); $('now').classList.toggle('click', e.outcome === 'failed'); comicCaption(e.outcome === 'delivered' ? 'THE END — mission delivered!' : 'The run ended: ' + e.outcome, 'director');
|
|
200
251
|
showOverlay(e);
|
|
201
252
|
break;
|
|
202
253
|
}
|
|
@@ -206,6 +257,7 @@
|
|
|
206
257
|
|
|
207
258
|
/* feed */
|
|
208
259
|
function feedScroll() { var f = $('feed'); f.scrollTop = f.scrollHeight; }
|
|
260
|
+
function teamLbl(id) { if (id === 'director') return 'Director'; var t = extrasOf(S.config).filter(function (x) { return x.id === id; })[0]; return t ? t.name : ({ba: 'BA', implement: 'Implement', qc: 'QC'})[id] || id; }
|
|
209
261
|
function feedPhase(t, team) { $('feed').appendChild(h('div', {class: 'fphase', style: 'color:' + TC[team], text: '▍' + t})); feedScroll(); }
|
|
210
262
|
function feedBanner(kind, t, onclick) { $('feed').appendChild(h('div', {class: 'fban ' + kind + (onclick ? ' click' : ''), text: t, onclick: onclick})); feedScroll(); count(); }
|
|
211
263
|
function fmtSize(n) { return n >= 1048576 ? (n / 1048576).toFixed(1) + ' MB' : n >= 1024 ? Math.round(n / 1024) + ' KB' : n + ' B'; }
|
|
@@ -220,6 +272,13 @@
|
|
|
220
272
|
S.atts = (S.atts || []).concat(list);
|
|
221
273
|
$('feed').appendChild(h('div', {class: 'fatts'}, list.map(attChip))); feedScroll();
|
|
222
274
|
}
|
|
275
|
+
function feedQuestions(e) {
|
|
276
|
+
var qs = String(e.questions || '').split('\n').map(function (l) { return l.replace(/^\s*\d+[.)]\s*/, '').trim(); }).filter(Boolean);
|
|
277
|
+
var as = e.assumptions ? String(e.assumptions).split('\n').map(function (l) { return l.replace(/^\s*[-*\d.)]+\s*/, '').trim(); }).filter(Boolean) : [];
|
|
278
|
+
$('feed').appendChild(h('div', {class: 'qcard'}, [h('b', {text: 'Director needs your answer · round ' + e.round + ' of 3'}), h('ol', {}, qs.map(function (q) { return h('li', {text: q}); })),
|
|
279
|
+
as.length ? h('div', {class: 'ml', text: 'IF YOU DO NOT ANSWER, THE DIRECTOR WILL ASSUME'}) : null, as.length ? h('ul', {}, as.map(function (q) { return h('li', {text: q}); })) : null,
|
|
280
|
+
h('div', {class: 'qhint', text: as.length ? 'Type your answer below, or choose Proceed with assumptions.' : 'Type your answer below. No team starts until you answer.'})])); feedScroll(); count();
|
|
281
|
+
}
|
|
223
282
|
function feedSub(parent, t) { $('feed').appendChild(h('div', {class: 'fsub', text: '↳ ' + nm(parent) + ' ' + t})); feedScroll(); }
|
|
224
283
|
function count() { $('feedcount').textContent = S.events.filter(function (e) { return e.type === 'agent.message'; }).length + ' MESSAGES'; }
|
|
225
284
|
function typeInto(el, text) {
|
|
@@ -231,7 +290,7 @@
|
|
|
231
290
|
var txt = h('div', {class: 'ft'});
|
|
232
291
|
var row = h('div', {class: 'fm', style: '--tc:' + col + ';--tg:' + hexA(col, .3) + ';--tg2:' + hexA(col, .1), onclick: function () { showMessage({from: e.agentId, to: e.to, at: e.at, tokens: e.tokens, text: e.text}); }}, [
|
|
233
292
|
h('div', {class: 'fav', text: ini(e.agentId)}),
|
|
234
|
-
h('div', {class: 'fb'}, [h('div', {class: 'fh'}, [h('b', {text: nm(e.agentId)}), h('span', {class: 'to', text: '→ ' + nm(e.to)}), h('span', {class: 'tm', text: clock(e.at) + (e.tokens ? ' · ' + e.tokens + ' tok' : '')})]), txt])]);
|
|
293
|
+
h('div', {class: 'fb'}, [h('div', {class: 'fh'}, [h('b', {text: nm(e.agentId)}), h('span', {class: 'to', text: '→ ' + nm(e.to)}), e.round ? h('span', {class: 'rnd', text: 'round ' + e.round}) : null, h('span', {class: 'tm', text: clock(e.at) + (e.tokens ? ' · ' + e.tokens + ' tok' : '')})]), txt])]);
|
|
235
294
|
$('feed').appendChild(row); typeInto(txt, short); feedScroll(); count();
|
|
236
295
|
}
|
|
237
296
|
|
|
@@ -270,11 +329,39 @@
|
|
|
270
329
|
p.querySelector('.dron').appendChild(h('span', {text: '◆ ' + (e.kind || 'sub') + ' · ' + e.task.slice(0, 50)}));
|
|
271
330
|
}
|
|
272
331
|
|
|
332
|
+
/* small text dialog (replaces window.prompt); sits above the Config modal. Resolves the trimmed text, or null when cancelled. */
|
|
333
|
+
function askText(o) {
|
|
334
|
+
return new Promise(function (done) {
|
|
335
|
+
var input = h('input', {value: o.value || '', placeholder: o.placeholder || '', spellcheck: false, autocomplete: 'off'}), err = h('div', {class: 'askerr'});
|
|
336
|
+
var close = function (v) { layer.remove(); done(v); };
|
|
337
|
+
var ok = function () { var v = input.value.trim(), bad = !v ? 'Type a name, or press Cancel.' : o.check ? o.check(v) : ''; if (bad) { err.textContent = bad; input.focus(); return; } close(v); };
|
|
338
|
+
var chips = (o.suggestions || []).length ? h('div', {class: 'askchips'}, [h('span', {text: 'Found on this machine'})].concat(o.suggestions.map(function (s) { return h('button', {type: 'button', text: s, onclick: function () { input.value = s; err.textContent = ''; input.focus(); }}); }))) : null;
|
|
339
|
+
var card = h('div', {class: 'askcard'}, [
|
|
340
|
+
h('header', {}, [h('b', {text: o.title}), h('button', {class: 'askx', type: 'button', text: '✕', title: 'Cancel', onclick: function () { close(null); }})]),
|
|
341
|
+
h('div', {class: 'askbody'}, [h('label', {class: 'ml', text: o.label}), input, err, chips, o.hint ? h('p', {text: o.hint}) : null]),
|
|
342
|
+
h('footer', {}, [h('span', {class: 'askkeys', text: 'Enter to confirm · Esc to cancel'}), h('button', {type: 'button', text: 'Cancel', onclick: function () { close(null); }}), h('button', {type: 'button', class: 'primary', text: o.okText || 'OK', onclick: ok})])]);
|
|
343
|
+
card.setAttribute('role', 'dialog'); card.setAttribute('aria-modal', 'true'); card.setAttribute('aria-label', o.title);
|
|
344
|
+
var layer = h('div', {class: 'ask'}, [card]);
|
|
345
|
+
layer.addEventListener('mousedown', function (e) { if (e.target === layer) close(null); });
|
|
346
|
+
layer.addEventListener('keydown', function (e) { if (e.key === 'Escape') { e.stopPropagation(); close(null); } else if (e.key === 'Enter' && e.target === input) { e.preventDefault(); ok(); } });
|
|
347
|
+
input.addEventListener('input', function () { err.textContent = ''; });
|
|
348
|
+
document.body.appendChild(layer); input.focus(); input.select();
|
|
349
|
+
});
|
|
350
|
+
}
|
|
273
351
|
/* overlay */
|
|
274
352
|
function showHoBanner(t) { var b = $('hobanner'); b.textContent = t; b.classList.add('on'); clearTimeout(b._t); b._t = setTimeout(function () { b.classList.remove('on'); }, 3200); }
|
|
353
|
+
function showDeclined(e, ov) {
|
|
354
|
+
var rep = String(e.report || ''), m1 = /REASON:\s*([\s\S]*?)(?:\n\s*WHAT WOULD WORK:|$)/.exec(rep), m2 = /WHAT WOULD WORK:\s*([\s\S]*)$/.exec(rep);
|
|
355
|
+
ov.innerHTML = '';
|
|
356
|
+
ov.appendChild(h('div', {class: 'mission declined'}, [h('div', {class: 'ml', text: 'NO TEAM STARTED'}), h('h1', {text: 'Director could not take this request'}), h('div', {text: (S.run && S.run.goal) || ''}),
|
|
357
|
+
h('div', {class: 'dcard'}, [h('div', {class: 'ml', text: 'REASON'}), h('div', {class: 'dtxt', text: (m1 ? m1[1] : rep).trim()}), m2 && m2[1].trim() ? h('div', {class: 'ml', style: 'margin-top:10px', text: 'WHAT WOULD WORK'}) : null, m2 && m2[1].trim() ? h('div', {class: 'dtxt', text: m2[1].trim()}) : null]),
|
|
358
|
+
h('div', {style: 'display:flex;gap:10px;justify-content:center'}, [h('button', {class: 'primary', text: 'Start a new request', onclick: function () { ov.hidden = true; $('msg').focus(); }}), h('button', {text: 'View transcript', onclick: function () { ov.hidden = true; showArtifact('Transcript', 'transcript.md'); }}), h('button', {text: 'Close', onclick: function () { ov.hidden = true; }})])]));
|
|
359
|
+
ov.hidden = !(!S.history || SHOT === 'delivery');
|
|
360
|
+
}
|
|
275
361
|
function showOverlay(e) {
|
|
276
362
|
var ok = e.outcome === 'delivered', ov = $('overlay');
|
|
277
|
-
|
|
363
|
+
if (e.outcome === 'declined') { showDeclined(e, ov); return; }
|
|
364
|
+
var fails = S.verdicts.filter(function (v) { return v.verdict === 'FAIL' && v.type === 'qc.verdict'; }).length;
|
|
278
365
|
ov.innerHTML = '';
|
|
279
366
|
ov.appendChild(h('div', {class: 'mission' + (ok ? '' : ' fail')}, [
|
|
280
367
|
h('div', {class: 'ml', text: ok ? 'ALL STAGES COMPLETE' : 'RUN ENDED'}), h('h1', {text: ok ? 'MISSION DELIVERED' : e.outcome.toUpperCase()}),
|
|
@@ -289,7 +376,7 @@
|
|
|
289
376
|
if (/not found on PATH/.test(r)) return 'The ' + cli + ' program is not installed (or not on PATH) on this machine. Install it, or open Config and switch this agent to an engine you have.';
|
|
290
377
|
if ((m = /Missing environment variable: `?([A-Z0-9_]+)/.exec(r))) return cli + ' needs the environment variable ' + m[1] + ' and did not get it.' + (/env boundary withheld/.test(r) ? ' CKit withheld it because it holds the same key as the CKit advisor; worker agents never receive the advisor key. Fix: give this agent its own key or let ' + cli + ' use its own login, or open Config and switch this agent to another engine (for example claude-code).' : ' Fix: set it in the terminal before running ckit gui, or switch this agent to another engine in Config.');
|
|
291
378
|
if (/401|403|unauthori[sz]ed|invalid api key|authentication/i.test(r)) return 'The provider rejected the credentials. Check the API key or login for ' + cli + ', then use Test connection in Config.';
|
|
292
|
-
if (/model.*(not found|does not exist|may not exist|unknown)|unknown model|unrecognized_model/i.test(r)) return 'The model "' + (cfg && cfg.model || '') + '" is not available to ' + cli + '. Open Config and set this agent\'s Model to a name that ' + cli + ' accepts when you run it yourself in the terminal' + (cli === 'claude-code' ? ' (for example haiku, sonnet or opus)' : '') + ', or leave it blank to use the CLI default.';
|
|
379
|
+
if (/model.*(not found|does not exist|may not exist|unknown)|unknown model|unrecognized_model/i.test(r)) return 'The model "' + (cfg && cfg.model || '') + '" is not available to ' + cli + '. Open Config and set this agent\'s Model to a name that ' + cli + ' accepts when you run it yourself in the terminal' + (cli === 'claude-code' ? ' (for example haiku, sonnet or opus)' : '') + ', or leave it blank to use the CLI default. If this model comes from another settings or profile file, put that file in “Extra CLI arguments” (for example --settings ~/.claude/profile/name.json) and check again.';
|
|
293
380
|
if (/timed out/.test(r)) return 'The agent did not answer in time. Check the network or provider, or raise the timeout in Config.';
|
|
294
381
|
if (/429|rate limit|quota/i.test(r)) return 'The provider is rate-limiting or the quota is used up. Wait and retry, or switch this agent to another model.';
|
|
295
382
|
if (/ECONNREFUSED|ENOTFOUND|network|fetch failed/i.test(r)) return 'The provider could not be reached. Check the network and the endpoint URL of this agent in Config.';
|
|
@@ -318,11 +405,12 @@
|
|
|
318
405
|
}
|
|
319
406
|
function renderRoster() {
|
|
320
407
|
var r = $('roster'), keep = r.scrollTop; r.innerHTML = '';
|
|
321
|
-
|
|
408
|
+
var dimmed = function (t) { return !!S.lane && t !== 'director' && S.lane.order.indexOf(t) < 0; };
|
|
409
|
+
['director'].concat(orderOf(S.config)).forEach(function (team) {
|
|
322
410
|
var ids = S.order.filter(function (i) { return A(i).cfg.team === team; }); if (!ids.length) return;
|
|
323
|
-
r.appendChild(h('div', {class: 'rteam', style: 'color:' + TC[team]}, [h('i', {style: 'background:' + TC[team]}), TL[team]]));
|
|
411
|
+
r.appendChild(h('div', {class: 'rteam' + (dimmed(team) ? ' dim' : ''), style: 'color:' + TC[team]}, [h('i', {style: 'background:' + TC[team]}), TL[team]]));
|
|
324
412
|
ids.forEach(function (id) {
|
|
325
|
-
var a = A(id), c = TC[team], el = h('div', {class: 'tile ' + a.state + (S.selected === id ? ' sel' : ''), style: '--tc:' + c + ';--tg:' + hexA(c, .4), onclick: function () { S.selected = id; net.select(id); S.dirty = true; }});
|
|
413
|
+
var a = A(id), c = TC[team], el = h('div', {class: 'tile ' + a.state + (S.selected === id ? ' sel' : '') + (dimmed(team) ? ' dim' : ''), style: '--tc:' + c + ';--tg:' + hexA(c, .4), onclick: function () { S.selected = id; net.select(id); S.dirty = true; }});
|
|
326
414
|
var work = a.state === 'thinking';
|
|
327
415
|
el.appendChild(h('div', {class: 'trow'}, [h('div', {class: 'av w' + net.initials(a.cfg).length, text: net.initials(a.cfg)}), h('div', {style: 'min-width:0;flex:1'}, [h('div', {class: 'tname', text: a.cfg.name}), h('div', {class: 'tsub'}, [h('span', {class: 'pill', text: a.cfg.cli}), a.cfg.model ? h('span', {class: 'pill', title: a.cfg.model, text: a.cfg.model}) : null])]),
|
|
328
416
|
h('div', {class: 'tright'}, [h('span', {class: 'sp ' + a.state}, [h('i'), a.state]), h('span', {class: 'tok', text: (work ? fmtT(performance.now() - a.t0) + ' · ' : '') + fmtN(a.tokens) + ' tok'})])]));
|
|
@@ -367,42 +455,61 @@
|
|
|
367
455
|
r.appendChild(h('button', {text: '× deselect', style: 'margin-top:6px', onclick: function () { S.selected = null; net.select(null); S.dirty = true; }}));
|
|
368
456
|
} else {
|
|
369
457
|
r.appendChild(h('h3', {text: 'Handoffs & verdicts'}));
|
|
370
|
-
S.handoffs.slice(-3).forEach(function (e) {
|
|
371
|
-
|
|
458
|
+
S.handoffs.slice(-3).forEach(function (e) {
|
|
459
|
+
var secs = []; String(e.text || '').split(/^#### /m).slice(1).forEach(function (blk) { var nl = blk.indexOf('\n'); secs.push([blk.slice(0, nl < 0 ? blk.length : nl).trim(), plain(nl < 0 ? '' : blk.slice(nl))]); });
|
|
460
|
+
r.appendChild(h('div', {class: 'card ho' + (e.text ? ' click' : ''), title: e.text ? 'Click to read the full handoff' : '', onclick: e.text ? function () { showMessage({from: e.from, to: e.to, at: e.at, text: e.text}); } : null}, [h('div', {class: 'ml', text: '📦 ' + teamLbl(e.from) + ' → ' + teamLbl(e.to)}), h('div', {text: e.title})].concat(secs.map(function (x) { return h('div', {class: 'hos'}, [h('b', {text: x[0]}), h('span', {text: x[1].length > 110 ? x[1].slice(0, 109) + '…' : x[1]})]); }))));
|
|
461
|
+
});
|
|
462
|
+
S.verdicts.slice(-3).forEach(function (e) { r.appendChild(h('div', {class: 'card ' + (e.verdict === 'PASS' ? 'pass' : 'fail')}, [h('b', {class: e.verdict === 'PASS' ? 'ok' : 'bad', text: e.type === 'review.verdict' ? 'Director review · ' + e.verdict : e.verdict + ' · loop ' + e.loop}), h('div', {style: 'font-size:12px', text: e.summary})])); });
|
|
372
463
|
if (!S.handoffs.length && !S.verdicts.length) r.appendChild(h('div', {class: 'tact', text: 'Click an agent to inspect it.'}));
|
|
373
464
|
if (S.atts && S.atts.length) { r.appendChild(h('h3', {style: 'margin-top:12px', text: 'Attachments · ' + S.atts.length})); r.appendChild(h('div', {class: 'tact', text: 'Every team gets these with the request.'})); r.appendChild(h('div', {class: 'fatts', style: 'margin-top:6px'}, S.atts.map(attChip))); }
|
|
374
465
|
}
|
|
375
466
|
r.appendChild(h('h3', {style: 'margin-top:12px', text: 'Telemetry'}));
|
|
376
|
-
var tele = h('div', {class: 'tele'}), pct = S.stageIdx < 0 ? 0 : Math.max(0, Math.min(1, (S.stageIdx + (S.outcome ? 0 : .5)) /
|
|
467
|
+
var tele = h('div', {class: 'tele'}), pct = S.stageIdx < 0 ? 0 : Math.max(0, Math.min(1, (S.stageIdx + (S.outcome ? 0 : .5)) / Math.max(1, stageList(S.config).length)));
|
|
377
468
|
var gauge = h('div', {class: 'card gauge'}), circ = 2 * Math.PI * 28;
|
|
378
469
|
gauge.innerHTML = '<svg width="74" height="74" viewBox="0 0 74 74"><circle cx="37" cy="37" r="28" fill="none" stroke="#1a2538" stroke-width="6"/><circle cx="37" cy="37" r="28" fill="none" stroke="#21D6E8" stroke-width="6" stroke-linecap="round" stroke-dasharray="' + (circ * pct).toFixed(1) + ' ' + circ.toFixed(1) + '" transform="rotate(-90 37 37)"/><text x="37" y="42" text-anchor="middle" fill="#fff" font-family="monospace" font-size="15">' + Math.round(pct * 100) + '%</text></svg><span class="ml">PROGRESS</span>';
|
|
379
470
|
var tk = h('div', {class: 'card'}); tk.innerHTML = '<span class="ml">TOKENS / TIME</span>' + lineSvg(S.tokBuckets.map(function (x) { return x[1]; }), '#4F8CFF');
|
|
380
471
|
var mb = h('div', {class: 'card'}); mb.innerHTML = '<span class="ml">MSGS / 10s</span>' + barSvg();
|
|
381
|
-
var sd = h('div', {class: 'card'}); sd.innerHTML = '<span class="ml">STAGE DURATIONS</span>' + Object.keys(S.stageTimes).slice(-4).map(function (k) { return '<div class="kv mono" style="font-size:10px"><span>' + k.replace('director-intake', 'intake').replace('ba-discussion', 'ba')
|
|
472
|
+
var sd = h('div', {class: 'card'}); sd.innerHTML = '<span class="ml">STAGE DURATIONS</span>' + Object.keys(S.stageTimes).slice(-4).map(function (k) { return '<div class="kv mono" style="font-size:10px"><span>' + k.replace('director-intake', 'intake').replace('ba-discussion', 'ba') + '</span><span>' + fmtT(S.stageTimes[k]) + '</span></div>'; }).join('');
|
|
382
473
|
[gauge, tk, mb, sd].forEach(function (x) { tele.appendChild(x); }); r.appendChild(tele); r.scrollTop = keep;
|
|
383
474
|
}
|
|
384
475
|
function renderStrip() {
|
|
385
476
|
var st = $('stages'); st.innerHTML = '';
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
477
|
+
var list = stageList(S.config), cur = S.stageKey === 'done' ? list.length : list.map(function (x) { return x.key; }).indexOf(S.stageKey);
|
|
478
|
+
$('lanename').textContent = S.lane ? 'Lane: ' + S.lane.name : ''; $('lanename').hidden = !S.lane;
|
|
479
|
+
list.forEach(function (x, i) {
|
|
480
|
+
var cls = cur > i ? 'done' : cur === i ? 'cur' : '', dur = S.stageTimes[x.key], xs = x.key.slice(0, 2) === 'x:';
|
|
481
|
+
st.appendChild(h('div', {class: 'st ' + cls + (x.key === 'review' ? ' rv' : ''), style: xs ? 'border-color:' + hexA(TC[x.team] || '#8A9AAF', .6) : ''}, [x.label, cls === 'done' && dur ? h('small', {text: fmtT(dur)}) : null, x.key === 'qc' && S.loop > 1 ? h('small', {text: 'loop ' + S.loop}) : null]));
|
|
389
482
|
});
|
|
390
483
|
}
|
|
391
484
|
function renderTop() {
|
|
392
485
|
var live = S.run && S.run.running && !S.outcome, b = $('badge');
|
|
393
|
-
b.className = 'badge ' + (S.outcome ? 'done' : live ? (S.replay ? 'replay' : 'live') : '');
|
|
394
|
-
b.querySelector('span').textContent = S.outcome ? (S.replay ? 'REPLAY DONE' : S.outcome === 'delivered' ? 'COMPLETE' : String(S.outcome).toUpperCase()) : live ? (S.replay ? 'REPLAY' : 'LIVE') : 'IDLE';
|
|
486
|
+
b.className = 'badge ' + (S.outcome === 'declined' ? 'replay' : S.outcome ? 'done' : live ? (S.replay ? 'replay' : 'live') : '');
|
|
487
|
+
b.querySelector('span').textContent = S.outcome ? (S.replay ? 'REPLAY DONE' : S.outcome === 'delivered' ? 'COMPLETE' : String(S.outcome).toUpperCase()) : live ? (S.replay ? 'REPLAY' : S.waiting ? 'WAITING' : 'LIVE') : 'IDLE';
|
|
395
488
|
var end = S.outcome || S.replay ? (S.lastAt || S.started) : Date.now();
|
|
396
489
|
$('elapsed').textContent = S.started ? fmtT(end - S.started) : '00:00'; $('tokens').textContent = fmtN(S.tokens); $('msgs').textContent = S.msgs;
|
|
397
490
|
$('active').textContent = S.order.filter(function (i) { return A(i).state === 'thinking'; }).length + activeSubs();
|
|
398
491
|
$('idleHint').style.display = S.run ? 'none' : ''; $('now').style.display = S.run ? '' : 'none';
|
|
399
492
|
/* composer: talks to the Director during a run, starts a mission when nothing is running */
|
|
400
|
-
var sim = simDefault(), mode = live ? 'live' : sim ? 'sim' : 'real';
|
|
493
|
+
var sim = simDefault(), wt = !!(live && S.waiting), mode = wt ? 'wait' + (S.waiting.assumptions ? 'A' : '') : live ? 'live' : sim ? 'sim' : 'real';
|
|
401
494
|
if (S.cmode !== mode) {
|
|
402
|
-
S.cmode = mode; $('clabel').textContent = live ? 'OWNER → DIRECTOR' : 'NEW MISSION → DIRECTOR'; $('send').textContent = live ? 'Send ▸' : 'Start ▸'; $('chips').style.display = live ? '' : 'none';
|
|
403
|
-
$('msg').placeholder = live ? 'Message the Director… (Enter to send)' : 'Describe the mission and press Enter to start the team…';
|
|
404
|
-
$('cnote').textContent = live ? '' : sim ? 'Demo mode: no real agent is configured, so this starts a simulated run.' : 'Starts real agents in ' + shortPath(S.projectRoot); $('cnote').title = S.projectRoot || '';
|
|
495
|
+
S.cmode = mode; $('clabel').textContent = wt ? 'ANSWER → DIRECTOR' : live ? 'OWNER → DIRECTOR' : 'NEW MISSION → DIRECTOR'; $('send').textContent = wt ? 'Send answer ▸' : live ? 'Send ▸' : 'Start ▸'; $('chips').style.display = live && !wt ? '' : 'none';
|
|
496
|
+
$('msg').placeholder = wt ? 'Answer the Director…' : live ? 'Message the Director… (Enter to send)' : 'Describe the mission and press Enter to start the team…';
|
|
497
|
+
$('cnote').textContent = wt ? 'The Director is waiting for you: no team has started and nothing is running.' : live ? '' : sim ? 'Demo mode: no real agent is configured, so this starts a simulated run.' : 'Starts real agents in ' + shortPath(S.projectRoot); $('cnote').title = S.projectRoot || '';
|
|
498
|
+
waitButtons(wt); if (wt) setTimeout(function () { $('msg').focus(); }, 30);
|
|
405
499
|
}
|
|
500
|
+
var lanes = (S.config && S.config.lanes) || [], sig = live ? '' : lanes.map(function (l) { return l.id + ':' + l.name; }).join('|');
|
|
501
|
+
if (S.laneSig !== sig) { S.laneSig = sig; var old = $('lane').value, ns = laneSelect(); $('lane').innerHTML = ns ? ns.innerHTML : ''; if (old && ns && Array.prototype.some.call($('lane').options, function (o) { return o.value === old; })) $('lane').value = old; }
|
|
502
|
+
$('lanewrap').hidden = !sig;
|
|
503
|
+
}
|
|
504
|
+
function laneSelect() {
|
|
505
|
+
var lanes = (S.config && S.config.lanes) || []; if (!lanes.length) return null;
|
|
506
|
+
var sel = h('select', {class: 'laneSel', title: 'Lane for this request. Auto: the Director decides which lane fits.'}); sel.appendChild(h('option', {value: '', text: 'Lane: Auto (Director decides)'}));
|
|
507
|
+
lanes.forEach(function (l) { sel.appendChild(h('option', {value: l.id, text: 'Lane: ' + l.name})); }); return sel;
|
|
508
|
+
}
|
|
509
|
+
function waitButtons(wt) {
|
|
510
|
+
var b = $('wbtns'); b.innerHTML = ''; b.hidden = !wt; if (!wt) return;
|
|
511
|
+
if (S.waiting && S.waiting.assumptions) b.appendChild(h('button', {class: 'chip', text: 'Proceed with assumptions', onclick: function () { api('POST', '/api/runs/current/proceed').then(function (r) { if (r.status !== 200) toast(r.body.error || 'could not proceed'); }); }}));
|
|
512
|
+
b.appendChild(h('button', {class: 'chip', text: 'Stop', onclick: function () { api('POST', '/api/runs/current/stop').then(function (r) { if (r.status !== 200) toast(r.body.error || 'No active run'); }); }}));
|
|
406
513
|
}
|
|
407
514
|
var lastRender = 0;
|
|
408
515
|
function loop(now) {
|
|
@@ -428,13 +535,15 @@
|
|
|
428
535
|
function renderRuns() {
|
|
429
536
|
var box = $('runs'); box.innerHTML = '<div class="ml" style="margin:6px 0 10px">PAST RUNS — open to replay</div>';
|
|
430
537
|
api('GET', '/api/runs').then(function (r) {
|
|
431
|
-
var rows = r.body.runs || [], t = h('table', {class: 'runs'}); t.innerHTML = '<tr><th>Date</th><th>Goal</th><th>Outcome</th><th>Duration</th><th>Replay</th></tr>';
|
|
538
|
+
var rows = r.body.runs || [], t = h('table', {class: 'runs'}); t.innerHTML = '<tr><th>Date</th><th>Goal</th><th>Lane</th><th>Outcome</th><th>Duration</th><th>Replay</th></tr>';
|
|
432
539
|
rows.forEach(function (x) {
|
|
433
540
|
var tr = h('tr'); tr.appendChild(h('td', {class: 'mono', text: x.startedAt ? new Date(x.startedAt).toLocaleString() : x.runId})); tr.appendChild(h('td', {text: (x.simulated ? '[demo] ' : '') + x.goal}));
|
|
434
|
-
|
|
541
|
+
var lbl = x.outcome === 'declined' ? 'declined: the Director could not take this request' : x.outcome === 'incomplete' ? (x.waiting ? 'interrupted while waiting for your answer' : 'interrupted before it finished') : x.outcome;
|
|
542
|
+
tr.appendChild(h('td', {text: x.lane || ''}));
|
|
543
|
+
tr.appendChild(h('td', {class: x.outcome === 'delivered' ? 'ok' : x.outcome === 'failed' ? 'bad' : x.outcome === 'declined' || x.outcome === 'incomplete' ? 'warn' : '', title: x.outcome === 'incomplete' ? 'A run lives only in the CKit process that started it and is not resumed after CKit stops or restarts. Start the request again as a new run.' : '', text: lbl})); tr.appendChild(h('td', {class: 'mono', text: fmtT(x.durationMs)}));
|
|
435
544
|
var td = h('td'); [1, 2, 4].forEach(function (sp) { td.appendChild(h('button', {text: sp + '×', style: 'margin-right:4px', onclick: function () { replay(x.runId, sp); }})); }); tr.appendChild(td); t.appendChild(tr);
|
|
436
545
|
});
|
|
437
|
-
if (!rows.length) t.appendChild(h('tr', {}, [h('td', {colSpan:
|
|
546
|
+
if (!rows.length) t.appendChild(h('tr', {}, [h('td', {colSpan: 6, text: 'No runs yet.'})]));
|
|
438
547
|
box.appendChild(t);
|
|
439
548
|
});
|
|
440
549
|
}
|
|
@@ -442,10 +551,11 @@
|
|
|
442
551
|
function replay(id, speed) { api('POST', '/api/runs/' + id + '/replay', {speed: speed}).then(function (r) { if (r.status !== 200) { toast(r.body.error || 'replay failed'); return; } S.replay = true; setComic(false); setView('live'); }); }
|
|
443
552
|
function newRunDialog() {
|
|
444
553
|
var goal = h('textarea', {rows: 4, placeholder: 'Describe the mission… e.g. "Add a dark-mode toggle to the settings page"'}), sim = h('input', {type: 'checkbox', style: 'width:auto'});
|
|
445
|
-
sim.checked = simDefault();
|
|
554
|
+
sim.checked = simDefault(); var laneSel = laneSelect();
|
|
446
555
|
openModal(h('div', {class: 'dlg'}, [h('header', {}, [h('b', {text: 'NEW RUN'}), h('button', {text: '✕', onclick: closeModal})]),
|
|
447
556
|
h('div', {class: 'body'}, [h('div', {class: 'ml', text: 'GOAL'}), goal, h('div', {class: 'ml', style: 'margin-top:12px', text: 'WORKSPACE (agents run in this folder)'}), h('div', {class: 'mono', style: 'font-size:12px;word-break:break-all;color:var(--cy)', text: S.projectRoot || ''}), h('div', {class: 'ml', style: 'margin-top:12px', text: 'ATTACHMENTS (any file type; the Director and every team read them)'}), h('div', {style: 'margin:6px 0'}, [h('button', {text: '📎 Attach files', onclick: function () { $('file').click(); }})]), h('div', {class: 'attlist'}), h('label', {style: 'display:flex;gap:8px;align-items:center;margin-top:12px'}, [sim, 'Demo mode (simulated agents, no API cost)'])]),
|
|
448
|
-
h('footer', {}, [h('button', {text: 'Cancel', onclick: closeModal}), h('button', {class: 'primary', text: 'Start ▸', onclick: function () { startRun(goal.value, sim.checked); }})])]));
|
|
557
|
+
h('footer', {}, [h('button', {text: 'Cancel', onclick: closeModal}), h('button', {class: 'primary', text: 'Start ▸', onclick: function () { startRun(goal.value, sim.checked, laneSel ? laneSel.value : ''); }})])]));
|
|
558
|
+
if (laneSel) $('modal').querySelector('.body').appendChild(h('div', {style: 'margin-top:12px'}, [h('div', {class: 'ml', text: 'LANE'}), laneSel]));
|
|
449
559
|
renderPending(); setTimeout(function () { goal.focus(); }, 30);
|
|
450
560
|
}
|
|
451
561
|
/* attachments waiting to be sent: uploaded as soon as they are picked, claimed by id when the message / mission is sent */
|
|
@@ -487,14 +597,14 @@
|
|
|
487
597
|
document.addEventListener('dragleave', function (ev) { if (!ev.relatedTarget) $('composer').classList.remove('drop'); });
|
|
488
598
|
document.addEventListener('drop', function (ev) { if (hasFiles(ev)) { ev.preventDefault(); $('composer').classList.remove('drop'); addFiles(ev.dataTransfer.files); } });
|
|
489
599
|
|
|
490
|
-
function startRun(goal, sim) {
|
|
600
|
+
function startRun(goal, sim, lane) {
|
|
491
601
|
var ids = pendingIds(); if (!ids) return Promise.resolve(false);
|
|
492
602
|
if (!goal.trim() && !ids.length) return Promise.resolve(false);
|
|
493
|
-
return api('POST', '/api/runs', {goal: goal, simulated: sim, attachments: ids}).then(function (r) { if (r.status !== 200) { toast(r.body.error || 'could not start the run'); return false; } clearPending(); closeModal(); S.replay = false; setView('live'); return true; });
|
|
603
|
+
return api('POST', '/api/runs', Object.assign({goal: goal, simulated: sim, attachments: ids}, lane ? {lane: lane} : {})).then(function (r) { if (r.status !== 200) { toast(r.body.error || 'could not start the run'); return false; } clearPending(); closeModal(); S.replay = false; setView('live'); return true; });
|
|
494
604
|
}
|
|
495
605
|
function send(text) {
|
|
496
606
|
var chip = !!text; text = (text || $('msg').value).trim(); if (!text && !PEND.length) return;
|
|
497
|
-
if (!(S.run && S.run.running && !S.outcome)) { startRun(text, simDefault()).then(function (ok) { if (ok) $('msg').value = ''; }); return; }
|
|
607
|
+
if (!(S.run && S.run.running && !S.outcome)) { startRun(text, simDefault(), $('lanewrap').hidden ? '' : $('lane').value).then(function (ok) { if (ok) $('msg').value = ''; }); return; }
|
|
498
608
|
var ids = chip ? [] : pendingIds(); if (!ids) return;
|
|
499
609
|
api('POST', '/api/runs/current/message', {text: text, attachments: ids}).then(function (r) { if (r.status !== 200) toast(r.body.error || 'No active run'); else { if (!chip) { $('msg').value = ''; clearPending(); } } });
|
|
500
610
|
}
|
|
@@ -537,13 +647,48 @@
|
|
|
537
647
|
/* config editor (settings view + popup) */
|
|
538
648
|
function strip(cfg) {
|
|
539
649
|
var c = JSON.parse(JSON.stringify(cfg));
|
|
540
|
-
|
|
650
|
+
cfgAgents(c).forEach(function (a) { delete a.hasKey; delete a._auto; if (a.baseUrl === '') delete a.baseUrl; if (!a.persona) delete a.persona; if (!a.short) delete a.short; if (typeof a.cliArgs !== 'string' || !a.cliArgs.trim()) delete a.cliArgs; else a.cliArgs = a.cliArgs.trim(); });
|
|
651
|
+
['ba', 'implement', 'qc'].forEach(function (k) { if (!c.teams[k]) c.teams[k] = []; });
|
|
652
|
+
if (c.missions) { Object.keys(c.missions).forEach(function (k) { if (!String(c.missions[k] || '').trim()) delete c.missions[k]; }); if (!Object.keys(c.missions).length) delete c.missions; }
|
|
653
|
+
if (c.extraTeams && !c.extraTeams.length) delete c.extraTeams;
|
|
654
|
+
c.order = orderOf(c);
|
|
655
|
+
if (typeof c.systemPrompt === 'string' && c.systemPrompt.trim()) c.systemPrompt = c.systemPrompt.trim(); else delete c.systemPrompt;
|
|
656
|
+
if (c.directorReview !== false) delete c.directorReview;
|
|
657
|
+
if (!c.lanes || !c.lanes.length) delete c.lanes;
|
|
658
|
+
(c.extraTeams || []).forEach(function (t) { delete t.runAfter; });
|
|
541
659
|
return c;
|
|
542
660
|
}
|
|
661
|
+
var ENH = {}, ENH_BUSY = ''; /* Enhance state per field; one request at a time; a proposal is never applied until the owner says so */
|
|
543
662
|
function mountEditor(box, modal) {
|
|
544
663
|
var draft = JSON.parse(JSON.stringify(S.config)), sel = 'director', tab = Q.get('tab') || 'form', dirty = false, errors = [], note = '', jsonText = '';
|
|
545
664
|
var serverCfg = JSON.stringify(strip(draft));
|
|
546
|
-
|
|
665
|
+
var selTeam = null; /* team whose header fields are shown instead of an agent */
|
|
666
|
+
function laneMode() { return !!(draft.lanes && draft.lanes.length); }
|
|
667
|
+
function enhance(kind, ids, ta, apply) {
|
|
668
|
+
var key = kind + '|' + (ids.team || '') + '|' + (ids.agent || '') + '|' + (ids.lane || ''), st = ENH[key], box2 = h('div');
|
|
669
|
+
var btn = h('button', {class: 'enhbtn', text: st && st.state === 'run' ? '' : '\u2726 Enhance', title: 'Rewrite this text so it is clear and specific. You decide whether to use the result.'});
|
|
670
|
+
var sync = function () { var empty = !ta.value.trim(), busy = !!ENH_BUSY; btn.disabled = empty || busy; btn.title = empty ? 'Type a few words first' : busy ? 'Another Enhance is running' : 'Rewrite this text so it is clear and specific. You decide whether to use the result.'; };
|
|
671
|
+
if (st && st.state === 'run') { btn.appendChild(h('span', {class: 'spin'})); btn.appendChild(document.createTextNode(' Enhancing\u2026')); }
|
|
672
|
+
ta.addEventListener('input', sync); sync();
|
|
673
|
+
btn.addEventListener('click', function () {
|
|
674
|
+
if (ENH_BUSY || !ta.value.trim()) return;
|
|
675
|
+
ENH_BUSY = key; ENH[key] = {state: 'run', orig: ta.value}; render();
|
|
676
|
+
api('POST', '/api/enhance-prompt', {kind: kind, text: ENH[key].orig, ids: ids}).then(function (res) {
|
|
677
|
+
ENH_BUSY = '';
|
|
678
|
+
if (res.status === 200 && res.body.ok) ENH[key] = {state: 'prop', orig: ENH[key].orig, proposal: res.body.proposal};
|
|
679
|
+
else ENH[key] = {state: 'bad', orig: ENH[key].orig, reason: res.body.reason || res.body.error || 'enhance failed'};
|
|
680
|
+
render();
|
|
681
|
+
});
|
|
682
|
+
});
|
|
683
|
+
box2.appendChild(h('div', {class: 'enh'}, [btn]));
|
|
684
|
+
if (st && st.state === 'prop') box2.appendChild(h('div', {class: 'prop'}, [h('div', {class: 'ml', text: 'YOUR TEXT'}), h('div', {class: 'pt orig', text: st.orig}), h('div', {class: 'ml', text: 'PROPOSAL'}), h('div', {class: 'pt', text: st.proposal}),
|
|
685
|
+
h('div', {class: 'pb'}, [h('button', {class: 'primary', text: 'Use this', onclick: function () { delete ENH[key]; apply(st.proposal); mark(); render(); }}), h('button', {text: 'Discard', onclick: function () { delete ENH[key]; render(); }})])]));
|
|
686
|
+
if (st && st.state === 'bad') { box2.appendChild(h('pre', {class: 'chkerr', text: st.reason})); box2.appendChild(h('div', {class: 'fix'}, [h('b', {text: 'How to fix '}), 'Enhance uses the Director\'s CLI. Open the Director agent, press "Check this CLI + model", and fix what it reports; your text was not changed. You can also edit it by hand.'])); box2.appendChild(h('button', {text: 'Dismiss', onclick: function () { delete ENH[key]; render(); }})); }
|
|
687
|
+
return box2;
|
|
688
|
+
}
|
|
689
|
+
function laneTags(id) { return (draft.lanes || []).filter(function (l) { return l.order.indexOf(id) >= 0; }); }
|
|
690
|
+
function dropFromLanes(id) { (draft.lanes || []).forEach(function (l) { l.order = l.order.filter(function (x) { return x !== id; }); }); }
|
|
691
|
+
function allA() { return cfgAgents(draft); }
|
|
547
692
|
function find(id) { return allA().filter(function (a) { return a.id === id; })[0]; }
|
|
548
693
|
function mark() { dirty = JSON.stringify(strip(draft)) !== serverCfg; }
|
|
549
694
|
function render() {
|
|
@@ -567,15 +712,89 @@
|
|
|
567
712
|
});
|
|
568
713
|
}
|
|
569
714
|
function jsonTab() { var t = h('textarea', {class: 'json', spellcheck: false}); t.value = jsonText || JSON.stringify(strip(draft), null, 2); t.addEventListener('input', function () { jsonText = t.value; dirty = true; }); return h('div', {style: 'height:' + (modal ? '56vh' : '66vh')}, [t]); }
|
|
715
|
+
function teamDefs() {
|
|
716
|
+
var d = [{id: 'director', label: 'DIRECTOR', list: [draft.director]}];
|
|
717
|
+
var ord = orderOf(draft); if (selTeam && BUILTIN[selTeam] && ord.indexOf(selTeam) < 0) ord.push(selTeam);
|
|
718
|
+
ord.forEach(function (id, i) {
|
|
719
|
+
var x = (draft.extraTeams || []).filter(function (t) { return t.id === id; })[0];
|
|
720
|
+
d.push(x ? {id: id, label: 'TEAM ' + String(x.name).toUpperCase(), list: x.agents, extra: x, n: i + 1, of: ord.length} : {id: id, label: TL[id], list: draft.teams[id] || [], n: i + 1, of: ord.length});
|
|
721
|
+
});
|
|
722
|
+
return d;
|
|
723
|
+
}
|
|
724
|
+
function newAgent(team, access) {
|
|
725
|
+
var n = 1, id; do { id = team + '-' + n; n++; } while (find(id));
|
|
726
|
+
var src = (draft.teams.implement || [])[0] || {};
|
|
727
|
+
return {id: id, name: (TL[team] || team).replace('TEAM ', '') + ' ' + (n - 1), team: team, cli: src.cli || (CLIS.filter(function (c) { return c.installed; })[0] || {cli: 'claude-code'}).cli, model: src.model || null, access: access};
|
|
728
|
+
}
|
|
729
|
+
function listOf(team) { var x = (draft.extraTeams || []).filter(function (t) { return t.id === team; })[0]; return x ? x.agents : (draft.teams[team] = draft.teams[team] || []); }
|
|
730
|
+
function addTeam(kind) {
|
|
731
|
+
if (kind === 'custom') {
|
|
732
|
+
var n = 1, id; do { id = 'team-' + n; n++; } while ((draft.extraTeams || []).some(function (t) { return t.id === id; }) || find(id));
|
|
733
|
+
var ag = newAgent(id, 'read'); ag.name = 'New agent'; ag.id = id + '-1'; var k = 1; while (find(ag.id)) { k++; ag.id = id + '-' + k; }
|
|
734
|
+
var ord0 = orderOf(draft);
|
|
735
|
+
draft.extraTeams = (draft.extraTeams || []).concat([{id: id, name: 'New team', mission: 'Describe what this team does for the goal', agents: [ag]}]);
|
|
736
|
+
draft.order = ord0.concat([id]);
|
|
737
|
+
selTeam = id; sel = ag.id;
|
|
738
|
+
} else { var ord1 = orderOf(draft); draft.teams[kind] = [newAgent(kind, kind === 'implement' ? 'write' : 'read')]; draft.order = ord1.concat([kind]); selTeam = null; sel = draft.teams[kind][0].id; }
|
|
739
|
+
mark(); render();
|
|
740
|
+
}
|
|
741
|
+
function addMenu() {
|
|
742
|
+
var wrap = h('div', {style: 'position:relative;margin-top:8px'}), missing = ['ba', 'implement', 'qc'].filter(function (t) { return !(draft.teams[t] || []).length; });
|
|
743
|
+
var s2 = h('select', {style: 'width:100%'}); s2.appendChild(h('option', {value: '', text: '+ Add team…'}));
|
|
744
|
+
missing.forEach(function (t) { s2.appendChild(h('option', {value: t, text: TL[t].replace('TEAM ', 'Team ')})); });
|
|
745
|
+
s2.appendChild(h('option', {value: 'custom', text: 'Custom team'}));
|
|
746
|
+
s2.addEventListener('change', function () { if (s2.value) addTeam(s2.value); });
|
|
747
|
+
wrap.appendChild(s2); return wrap;
|
|
748
|
+
}
|
|
749
|
+
function move(id, d) {
|
|
750
|
+
var o = orderOf(draft), i = o.indexOf(id), j = i + d;
|
|
751
|
+
if (i < 0 || j < 0 || j >= o.length) return;
|
|
752
|
+
o.splice(i, 1); o.splice(j, 0, id); draft.order = o; mark(); render();
|
|
753
|
+
}
|
|
754
|
+
function posControls(t) {
|
|
755
|
+
var o = orderOf(draft), i = o.indexOf(t.id);
|
|
756
|
+
return h('div', {class: 'poscl'}, [h('b', {text: 'Step ' + (i + 1) + ' of ' + o.length}),
|
|
757
|
+
h('button', {text: '▲ Up', title: 'Run earlier', disabled: i <= 0, onclick: function () { move(t.id, -1); }}),
|
|
758
|
+
h('button', {text: '▼ Down', title: 'Run later', disabled: i < 0 || i >= o.length - 1, onclick: function () { move(t.id, 1); }})]);
|
|
759
|
+
}
|
|
760
|
+
function posOrLanes(t) {
|
|
761
|
+
if (!laneMode()) return posControls(t);
|
|
762
|
+
var ls = laneTags(t.id);
|
|
763
|
+
return h('div', {class: 'clinote', style: 'margin:0', text: ls.length ? 'Order is set inside each lane. In: ' + ls.map(function (l) { return l.name; }).join(', ') : 'Not in any lane yet. Add it to a lane under Lanes (below), otherwise it never runs.'});
|
|
764
|
+
}
|
|
765
|
+
function teamHeader(t) {
|
|
766
|
+
var f = h('div'), isX = !!t.extra, o = isX ? t.extra : draft;
|
|
767
|
+
f.appendChild(h('div', {class: 'sec', text: 'TEAM'}));
|
|
768
|
+
var mission = isX ? t.extra.mission : ((draft.missions || {})[t.id] || DEFAULT_MISSION[t.id]);
|
|
769
|
+
var ta = h('textarea', {rows: 3, value: mission, placeholder: 'What does this team do for the goal?'});
|
|
770
|
+
ta.addEventListener('input', function () { if (isX) t.extra.mission = ta.value; else { draft.missions = draft.missions || {}; draft.missions[t.id] = ta.value; } var was = dirty; mark(); if (dirty !== was) render(); });
|
|
771
|
+
var row = [];
|
|
772
|
+
if (isX) {
|
|
773
|
+
row.push(fld('Team name', bind(h('input', {value: t.extra.name}), t.extra, 'name')));
|
|
774
|
+
row.push(fld('Position in the flow', posOrLanes(t), 'Work goes Director, then team 1, 2, 3 ... Use the arrows to change the order.'));
|
|
775
|
+
f.appendChild(h('div', {class: 'row2'}, row));
|
|
776
|
+
} else f.appendChild(h('div', {class: 'row2'}, [fld('Position in the flow', posOrLanes(t), 'Work goes Director, then team 1, 2, 3 ... Use the arrows to change the order.'), h('div', {class: 'clinote', text: 'Built-in team "' + t.id + '"' + (t.id === 'ba' ? '; also reviews the finished work at the end.' : '.')})]));
|
|
777
|
+
f.appendChild(fld('Mission', ta, 'The Director reads this when it splits the work; every agent of the team gets it in its prompt.'));
|
|
778
|
+
f.appendChild(enhance('mission', {team: t.id}, ta, function (v) { if (isX) t.extra.mission = v; else { draft.missions = draft.missions || {}; draft.missions[t.id] = v; } }));
|
|
779
|
+
f.appendChild(h('div', {style: 'margin:10px 0'}, [h('button', {class: 'danger', text: 'Remove team', onclick: function () {
|
|
780
|
+
draft.order = orderOf(draft).filter(function (x) { return x !== t.id; }); dropFromLanes(t.id);
|
|
781
|
+
if (isX) draft.extraTeams = draft.extraTeams.filter(function (x) { return x.id !== t.id; }); else { draft.teams[t.id] = []; if (draft.missions) delete draft.missions[t.id]; }
|
|
782
|
+
selTeam = null; sel = 'director'; mark(); render(); }})]));
|
|
783
|
+
return f;
|
|
784
|
+
}
|
|
570
785
|
function form() {
|
|
571
786
|
var wrap = h('div', {class: 'cfg', style: modal ? 'height:58vh' : ''}), left = h('div'), right = h('div');
|
|
572
|
-
|
|
573
|
-
var team =
|
|
574
|
-
left.appendChild(h('div', {class: 'rteam', style: 'color:' +
|
|
575
|
-
list.forEach(function (a) { left.appendChild(h('div', {class: 'al' + (sel === a.id ? ' sel' : ''), style: '--tc:' +
|
|
576
|
-
if (
|
|
787
|
+
teamDefs().forEach(function (t) {
|
|
788
|
+
var team = t.id, color = TC[team] || '#8A9AAF', isDir = team === 'director';
|
|
789
|
+
left.appendChild(h('div', {class: 'rteam' + (selTeam === team ? ' sel' : ''), style: 'color:' + color + (isDir ? '' : ';cursor:pointer'), title: isDir ? '' : 'Click to edit this team (name, mission, when it runs)', onclick: isDir ? null : function () { selTeam = team; render(); }}, [isDir ? h('i', {style: 'background:' + color}) : h('span', {class: 'nbadge', style: 'background:' + color, text: String(t.n)}), h('span', {style: 'flex:1', text: t.label + (isDir ? '' : ' ✎')}), isDir ? null : h('span', {}, laneTags(team).map(function (l) { return h('span', {class: 'ltag', title: 'In lane ' + l.name, text: l.name}); })), isDir || laneMode() ? null : h('button', {class: 'mv', text: '▲', title: 'Move up (run earlier)', disabled: t.n <= 1, onclick: function (ev) { ev.stopPropagation(); move(team, -1); }}), isDir || laneMode() ? null : h('button', {class: 'mv', text: '▼', title: 'Move down (run later)', disabled: t.n >= t.of, onclick: function (ev) { ev.stopPropagation(); move(team, 1); }})]));
|
|
790
|
+
t.list.forEach(function (a) { left.appendChild(h('div', {class: 'al' + (sel === a.id && !selTeam ? ' sel' : ''), style: '--tc:' + color + ';--tg:' + hexA(color, .3), onclick: function () { sel = a.id; selTeam = null; render(); }}, [h('b', {text: a.name}), h('small', {text: a.cli + (a.model ? ' · ' + a.model : '') + (a.cliArgs ? ' · +args' : '')})])); });
|
|
791
|
+
if (!isDir) left.appendChild(h('button', {text: '+ Add agent', style: 'width:100%;margin-bottom:6px', onclick: function () { var ag = newAgent(team, team === 'implement' ? 'write' : 'read'); listOf(team).push(ag); sel = ag.id; selTeam = null; mark(); render(); }}));
|
|
577
792
|
});
|
|
578
|
-
|
|
793
|
+
left.appendChild(addMenu());
|
|
794
|
+
var cur = selTeam ? teamDefs().filter(function (x) { return x.id === selTeam; })[0] : null;
|
|
795
|
+
if (selTeam && !cur) selTeam = null;
|
|
796
|
+
if (cur && cur.id !== 'director') right.appendChild(teamHeader(cur)); else right.appendChild(editAgent(find(sel) || draft.director));
|
|
797
|
+
right.appendChild(projectBox()); right.appendChild(lanesBox()); right.appendChild(limits()); wrap.appendChild(left); wrap.appendChild(right); return wrap;
|
|
579
798
|
}
|
|
580
799
|
function fld(label, input, hint) { return h('div', {class: 'fld'}, [h('label', {class: 'ml', text: label}), input, hint ? h('div', {class: 'ml', style: 'margin-top:3px;text-transform:none', text: hint}) : null]); }
|
|
581
800
|
function bind(el, obj, key, num) {
|
|
@@ -589,7 +808,11 @@
|
|
|
589
808
|
ci.models.forEach(function (m) { s.appendChild(h('option', {value: m, text: m, selected: a.model === m})); });
|
|
590
809
|
if (a.model && !known) s.appendChild(h('option', {value: a.model, text: a.model + ' (typed by you, not in the CLI list)', selected: true}));
|
|
591
810
|
s.appendChild(h('option', {value: '\u0000', text: 'Other…'}));
|
|
592
|
-
s.addEventListener('change', function () { var v = s.value;
|
|
811
|
+
s.addEventListener('change', function () { var v = s.value; var set = function (x) { a.model = x || null; a._auto = true; mark(); render(); };
|
|
812
|
+
if (v !== '\u0000') return set(v);
|
|
813
|
+
askText({title: 'Custom model', label: 'Model name, exactly as ' + a.cli + ' accepts it', value: known ? '' : a.model || '', placeholder: 'model-name', okText: 'Use this model', suggestions: ci.models,
|
|
814
|
+
hint: 'CKit passes this name to ' + a.cli + ' unchanged. If the model comes from another settings or profile file, name that file in “Extra CLI arguments” below.',
|
|
815
|
+
check: function (x) { return /^[A-Za-z0-9._:\/@\[\]-]{1,120}$/.test(x) ? '' : 'Use letters, digits and . _ : / @ [ ] - only (max 120), no spaces.'; }}).then(function (x) { if (x === null) render(); else set(x); }); });
|
|
593
816
|
return s;
|
|
594
817
|
}
|
|
595
818
|
function editAgent(a) {
|
|
@@ -598,7 +821,9 @@
|
|
|
598
821
|
var sn = h('input', {value: a.short || '', maxLength: 4, placeholder: net.initials({name: a.name || '?', team: a.team}), style: 'text-transform:uppercase;font-family:var(--mono);font-weight:700;letter-spacing:.08em', title: 'Shown inside the agent circle. 1-4 letters or digits. Empty = ' + net.initials({name: a.name || '?', team: a.team}) + ' (from the name).'});
|
|
599
822
|
sn.addEventListener('input', function () { var v = sn.value.replace(/[^\p{L}\p{N}]/gu, '').toUpperCase().slice(0, 4); if (v !== sn.value) sn.value = v; });
|
|
600
823
|
f.appendChild(h('div', {class: 'row2', style: 'grid-template-columns:150px 1fr 1fr'}, [fld('Short name (max 4)', bind(sn, a, 'short')), fld('Name', bind(h('input', {value: a.name}), a, 'name')), fld('Team', h('input', {value: a.team, disabled: true}))]));
|
|
601
|
-
|
|
824
|
+
var pta = bind(h('textarea', {rows: 2, value: a.persona || ''}), a, 'persona');
|
|
825
|
+
f.appendChild(fld('Persona / extra guidance (optional)', pta));
|
|
826
|
+
f.appendChild(enhance('persona', {team: a.team, agent: a.id}, pta, function (v) { a.persona = v; }));
|
|
602
827
|
f.appendChild(h('div', {class: 'sec', text: 'ENGINE'}));
|
|
603
828
|
/* an agent is: which CLI of this machine, and which of that CLI's own models. `api` stays selectable only where it is already in use. */
|
|
604
829
|
var info = function (n) { return CLIS.filter(function (c) { return c.cli === n; })[0]; }, ci = info(a.cli);
|
|
@@ -606,14 +831,15 @@
|
|
|
606
831
|
cli.addEventListener('change', function () { a.cli = cli.value; a.model = null; a._auto = true; mark(); render(); });
|
|
607
832
|
var acc = h('select'); ['read', 'write'].forEach(function (o) { var op = h('option', {text: o === 'write' ? 'Read + write (can change code)' : 'Read only (changes nothing)', value: o}); if (o === a.access) op.selected = true; acc.appendChild(op); }); acc.addEventListener('change', function () { a.access = acc.value; mark(); render(); });
|
|
608
833
|
f.appendChild(h('div', {class: 'row3'}, [fld('CLI', cli), fld('Model', modelPick(a, ci)), fld('Access', acc)]));
|
|
834
|
+
if (a.cli === 'claude-code' || a.cli === 'codex' || a.cli === 'omp') f.appendChild(fld('Extra CLI arguments (optional)', bind(h('input', {value: a.cliArgs || '', maxLength: 500, placeholder: '--settings ~/.claude/profile/other.json', spellcheck: false, style: 'font-family:var(--mono)', onchange: function () { a._auto = true; render(); }}), a, 'cliArgs'), 'Added to this agent\'s start command as typed. Leave empty to use the CLI\'s defaults. ~ and $HOME mean your home folder; quote values with spaces. The check below runs with these arguments.'));
|
|
609
835
|
f.appendChild(h('div', {class: 'clinote', text: a.access === 'write' ? 'Access: this agent reads the whole project and may change files in it.' : 'Access: this agent reads the whole project (code, docs, attachments) but changes nothing. Pick “Read + write” for agents that must edit code.'}));
|
|
610
836
|
if (ci && ci.installed) {
|
|
611
837
|
/* verify the pair with one real tiny turn; result is cached per CLI + model */
|
|
612
|
-
var ck = a.cli + '|' + (a.model || ''), st = CHECK[ck];
|
|
613
|
-
var run = function () { CHECK[ck] = {state: 'run'}; render(); api('POST', '/api/check-agent', {cli: a.cli, model: a.model || null}).then(function (r) { CHECK[ck] = r.status === 200 && r.body.ok ? {state: 'ok'} : {state: 'bad', reason: r.body.reason || r.body.error || 'check failed'}; render(); }); };
|
|
838
|
+
var xa = (a.cliArgs || '').trim(), ck = a.cli + '|' + (a.model || '') + '|' + xa, st = CHECK[ck];
|
|
839
|
+
var run = function () { CHECK[ck] = {state: 'run'}; render(); api('POST', '/api/check-agent', {cli: a.cli, model: a.model || null, cliArgs: xa}).then(function (r) { CHECK[ck] = r.status === 200 && r.body.ok ? {state: 'ok'} : {state: 'bad', reason: r.body.reason || r.body.error || 'check failed'}; render(); }); };
|
|
614
840
|
var line = h('div', {class: 'chk ' + (st ? st.state : '')}, [
|
|
615
841
|
h('button', {text: st && st.state === 'run' ? 'Checking…' : st ? 'Check again' : 'Check this CLI + model', disabled: !!(st && st.state === 'run'), onclick: run}),
|
|
616
|
-
h('span', {text: !st ? 'Runs one tiny real turn to confirm ' + a.cli + ' accepts this model.' : st.state === 'run' ? 'asking ' + a.cli + ' for a one-word reply (up to 90 s)…' : st.state === 'ok' ? '✓ works: ' + a.cli + ' answered with ' + (a.model || 'its default model') : '✕ ' + a.cli + ' rejected this setup'})]);
|
|
842
|
+
h('span', {text: !st ? 'Runs one tiny real turn to confirm ' + a.cli + ' accepts this model' + (xa ? ' with the extra arguments.' : '.') : st.state === 'run' ? 'asking ' + a.cli + ' for a one-word reply (up to 90 s)…' : st.state === 'ok' ? '✓ works: ' + a.cli + ' answered with ' + (a.model || 'its default model') + (xa ? ' and the extra arguments' : '') : '✕ ' + a.cli + ' rejected this setup'})]);
|
|
617
843
|
f.appendChild(line);
|
|
618
844
|
if (st && st.state === 'bad') { f.appendChild(h('pre', {class: 'chkerr', text: st.reason})); f.appendChild(h('div', {class: 'fix'}, [h('b', {text: 'How to fix '}), fixHint(st.reason, a)])); }
|
|
619
845
|
if (a._auto) { a._auto = false; if (!st) setTimeout(run, 0); }
|
|
@@ -629,12 +855,54 @@
|
|
|
629
855
|
a.hasKey ? h('span', {class: 'ok mono', text: 'key stored ✓'}) : null]), 'Stored in your user config dir as agent-' + a.id + '; never shown again.'));
|
|
630
856
|
f.appendChild(h('div', {style: 'display:flex;align-items:center'}, [h('button', {text: 'Test connection', onclick: function () { res.className = 'mono'; if (dirty) { res.textContent = 'save first'; return; } res.textContent = 'testing…'; api('POST', '/api/test-connection', {agentId: a.id}).then(function (r) { var s = r.body.status || r.body.error; res.textContent = '● ' + s + (r.body.http ? ' (HTTP ' + r.body.http + ')' : ''); res.className = 'mono ' + (s === 'ok' ? 'ok' : 'bad'); }); }}), res]));
|
|
631
857
|
}
|
|
632
|
-
if (!isDir) f.appendChild(h('div', {style: 'margin-top:14px'}, [h('button', {class: 'danger', text: 'Remove agent', onclick: function () {
|
|
858
|
+
if (!isDir) f.appendChild(h('div', {style: 'margin-top:14px'}, [h('button', {class: 'danger', text: 'Remove agent', onclick: function () { var L = listOf(a.team), at = L.indexOf(a); if (at >= 0) L.splice(at, 1); sel = 'director'; mark(); render(); }})]));
|
|
859
|
+
return f;
|
|
860
|
+
}
|
|
861
|
+
function projectBox() {
|
|
862
|
+
var f = h('div'); f.appendChild(h('div', {class: 'sec', text: 'PROJECT-WIDE'}));
|
|
863
|
+
var sp = h('textarea', {rows: 4, value: draft.systemPrompt || '', maxLength: 8000, placeholder: 'Optional'});
|
|
864
|
+
sp.addEventListener('input', function () { draft.systemPrompt = sp.value; var was = dirty; mark(); if (dirty !== was) render(); });
|
|
865
|
+
f.appendChild(fld('System prompt (optional)', sp, 'Sent to every agent in this project. Leave empty if your project already has its own agent instructions.'));
|
|
866
|
+
f.appendChild(enhance('system', {}, sp, function (v) { draft.systemPrompt = v; }));
|
|
867
|
+
var cb = h('input', {type: 'checkbox', checked: draft.directorReview !== false});
|
|
868
|
+
cb.addEventListener('change', function () { if (cb.checked) delete draft.directorReview; else draft.directorReview = false; mark(); render(); });
|
|
869
|
+
f.appendChild(h('div', {class: 'chkrow'}, [cb, h('div', {}, [h('div', {text: 'Director reviews the result against your request before delivery'}), h('div', {class: 'ml', style: 'text-transform:none;margin-top:2px', text: 'Adds one Director turn; may send the work back to the last team.'})])]));
|
|
870
|
+
return f;
|
|
871
|
+
}
|
|
872
|
+
function slug(name) { var b = String(name || 'lane').toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '').slice(0, 24) || 'lane', id = b, n = 2; while ((draft.lanes || []).some(function (l) { return l.id === id; })) { id = b + '-' + n; n++; } return id; }
|
|
873
|
+
function lanesBox() {
|
|
874
|
+
var f = h('div'); f.appendChild(h('div', {class: 'sec', text: 'LANES'}));
|
|
875
|
+
var lanes = draft.lanes || [], tn = function (id) { var t = teamDefs().filter(function (x) { return x.id === id; })[0]; return t ? t.label.replace(/^TEAM /, '') : id; };
|
|
876
|
+
if (!lanes.length) {
|
|
877
|
+
f.appendChild(h('div', {class: 'row2', style: 'grid-template-columns:1fr auto;align-items:center'}, [h('div', {class: 'clinote', style: 'margin:0', text: 'One flow for every request'}), h('button', {text: '+ Add lane', title: 'Different kinds of request can use different teams. The Director picks the lane.', onclick: function () { var o = orderOf(draft); draft.lanes = [{id: 'default', name: 'Default', when: 'General requests', order: o}]; mark(); render(); }})]));
|
|
878
|
+
return f;
|
|
879
|
+
}
|
|
880
|
+
f.appendChild(h('div', {class: 'clinote', text: 'The Director reads each lane\'s "When to use" and picks one lane per request; only that lane\'s teams run, in the order shown.'}));
|
|
881
|
+
lanes.forEach(function (l, li) {
|
|
882
|
+
var nm2 = h('input', {value: l.name, placeholder: 'Lane name'}); nm2.addEventListener('input', function () { l.name = nm2.value; var was = dirty; mark(); if (dirty !== was) render(); });
|
|
883
|
+
var when = h('textarea', {rows: 2, value: l.when || '', placeholder: 'Which requests belong in this lane? e.g. "Code changes: features, bug fixes, refactors"'}); when.addEventListener('input', function () { l.when = when.value; var was = dirty; mark(); if (dirty !== was) render(); });
|
|
884
|
+
var box3 = h('div', {class: 'lane'}, [h('div', {class: 'lh'}, [nm2, h('button', {class: 'danger', text: 'Remove lane', onclick: function () {
|
|
885
|
+
var gone = draft.lanes.splice(li, 1)[0];
|
|
886
|
+
if (!draft.lanes.length) { delete draft.lanes; draft.order = gone.order.slice(); }
|
|
887
|
+
mark(); render(); }})]), fld('When to use', when, 'Written for the Director.'), enhance('lane', {lane: l.id}, when, function (v) { l.when = v; })]);
|
|
888
|
+
box3.appendChild(h('div', {class: 'ml', text: 'TEAMS IN THIS LANE, IN ORDER'}));
|
|
889
|
+
if (!l.order.length) box3.appendChild(h('div', {class: 'clinote bad', text: 'No teams yet. A lane needs at least one team, or remove it; saving is refused otherwise.'}));
|
|
890
|
+
l.order.forEach(function (id, i) {
|
|
891
|
+
var mv = function (d) { var j = i + d; if (j < 0 || j >= l.order.length) return; l.order.splice(i, 1); l.order.splice(j, 0, id); mark(); render(); };
|
|
892
|
+
box3.appendChild(h('div', {class: 'lteam'}, [h('span', {class: 'nbadge', style: 'background:' + (TC[id] || '#8A9AAF'), text: String(i + 1)}), h('span', {class: 'nm', text: tn(id)}),
|
|
893
|
+
h('button', {text: '▲', title: 'Run earlier', disabled: i === 0, onclick: function () { mv(-1); }}), h('button', {text: '▼', title: 'Run later', disabled: i === l.order.length - 1, onclick: function () { mv(1); }}),
|
|
894
|
+
h('button', {text: 'Remove from lane', onclick: function () { l.order.splice(i, 1); mark(); render(); }})]));
|
|
895
|
+
});
|
|
896
|
+
var avail = orderOf(draft).filter(function (id) { return l.order.indexOf(id) < 0; });
|
|
897
|
+
if (avail.length) { var sel2 = h('select', {style: 'margin-top:6px'}); sel2.appendChild(h('option', {value: '', text: '+ Add team to lane…'})); avail.forEach(function (id) { sel2.appendChild(h('option', {value: id, text: tn(id)})); }); sel2.addEventListener('change', function () { if (sel2.value) { l.order.push(sel2.value); mark(); render(); } }); box3.appendChild(sel2); }
|
|
898
|
+
f.appendChild(box3);
|
|
899
|
+
});
|
|
900
|
+
f.appendChild(h('button', {text: '+ Add lane', onclick: function () { draft.lanes.push({id: slug('lane-' + (draft.lanes.length + 1)), name: 'Lane ' + (draft.lanes.length + 1), when: '', order: []}); mark(); render(); }}));
|
|
633
901
|
return f;
|
|
634
902
|
}
|
|
635
903
|
function limits() {
|
|
636
904
|
var f = h('div'); f.appendChild(h('div', {class: 'sec', text: 'LIMITS'}));
|
|
637
|
-
f.appendChild(h('div', {class: 'row3'}, [fld('
|
|
905
|
+
f.appendChild(h('div', {class: 'row3'}, [fld('Discussion rounds per team', bind(h('input', {type: 'number', value: draft.limits.baRounds, min: 1}), draft.limits, 'baRounds', true)), fld('Max send-backs per team', bind(h('input', {type: 'number', value: draft.limits.qcLoops, min: 0}), draft.limits, 'qcLoops', true)), fld('Agent timeout (ms)', bind(h('input', {type: 'number', value: draft.limits.agentTimeoutMs}), draft.limits, 'agentTimeoutMs', true))]));
|
|
638
906
|
return f;
|
|
639
907
|
}
|
|
640
908
|
render();
|