@ngockhoale/ckit 0.2.10 → 0.3.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.
@@ -0,0 +1,21 @@
1
+ export interface LeaseHolder {
2
+ readonly runId: string;
3
+ readonly agentId: string;
4
+ readonly since: number;
5
+ }
6
+ export interface WriteSession {
7
+ readonly runId: string;
8
+ readonly agentId: string;
9
+ readonly at: number;
10
+ }
11
+ export interface WorkspaceLease {
12
+ /** Resolves with a release function once this run owns the workspace (FIFO). Rejects with an AbortError when `signal` aborts while waiting. */
13
+ acquire(runId: string, agentId: string, signal?: AbortSignal, onWait?: (holder: LeaseHolder) => void): Promise<() => void>;
14
+ holder(): LeaseHolder | null;
15
+ /** Run ids (other than `runId`) with a finished or running write session since `since` (epoch ms). */
16
+ othersSince(runId: string, since: number): string[];
17
+ }
18
+ export declare function createWorkspaceLease(): WorkspaceLease;
19
+ /** One lease per project root (by realpath), shared by every run in this process. */
20
+ export declare function workspaceLeaseFor(projectRoot: string): WorkspaceLease;
21
+ export declare const otherRunsNote: (runs: readonly string[]) => string;
@@ -0,0 +1,72 @@
1
+ import { realpathSync } from 'node:fs';
2
+ import { resolve } from 'node:path';
3
+ const LOG_MAX = 50;
4
+ export function createWorkspaceLease() {
5
+ let current = null;
6
+ const queue = [];
7
+ const log = [];
8
+ const grantNext = () => { const n = queue.shift(); if (n)
9
+ n.grant(); };
10
+ return {
11
+ acquire(runId, agentId, signal, onWait) {
12
+ return new Promise((resolveP, reject) => {
13
+ if (signal?.aborted) {
14
+ reject(abortError());
15
+ return;
16
+ }
17
+ const take = () => {
18
+ current = { runId, agentId, since: Date.now() };
19
+ let released = false;
20
+ resolveP(() => {
21
+ if (released)
22
+ return;
23
+ released = true;
24
+ log.push({ runId, agentId, at: Date.now() });
25
+ if (log.length > LOG_MAX)
26
+ log.shift();
27
+ current = null;
28
+ grantNext();
29
+ });
30
+ };
31
+ if (!current && !queue.length) {
32
+ take();
33
+ return;
34
+ }
35
+ const entry = { runId, agentId, grant: () => { signal?.removeEventListener('abort', onAbort); take(); } };
36
+ const onAbort = () => { const i = queue.indexOf(entry); if (i >= 0)
37
+ queue.splice(i, 1); reject(abortError()); };
38
+ signal?.addEventListener('abort', onAbort, { once: true });
39
+ queue.push(entry);
40
+ if (current && onWait)
41
+ onWait(current);
42
+ });
43
+ },
44
+ holder: () => current,
45
+ othersSince(runId, since) {
46
+ const ids = new Set(log.filter(s => s.runId !== runId && s.at >= since).map(s => s.runId));
47
+ if (current && current.runId !== runId)
48
+ ids.add(current.runId);
49
+ return [...ids];
50
+ },
51
+ };
52
+ }
53
+ function abortError() { const e = new Error('cancelled'); e.name = 'AbortError'; return e; }
54
+ const leases = new Map();
55
+ /** One lease per project root (by realpath), shared by every run in this process. */
56
+ export function workspaceLeaseFor(projectRoot) {
57
+ let key;
58
+ try {
59
+ key = realpathSync(projectRoot);
60
+ }
61
+ catch {
62
+ key = resolve(projectRoot);
63
+ }
64
+ let l = leases.get(key);
65
+ if (!l) {
66
+ l = createWorkspaceLease();
67
+ leases.set(key, l);
68
+ }
69
+ return l;
70
+ }
71
+ export const otherRunsNote = (runs) => `NOTE: Other CKit runs in this project changed files while this run was active (runs: ${runs.join(', ')}). Judge only the changes for THIS run's goal; do not revert or report other runs' changes as defects.`;
72
+ //# sourceMappingURL=workspace-lease.js.map
@@ -73,6 +73,7 @@ export function reduceTeam(state, event) {
73
73
  return s0;
74
74
  return { ...s0, agents: patch(s0, event.agentId, x => ({ ...x, state: 'thinking', turnStartedAt: at, lastActivity: oneLine(event.task) })) };
75
75
  }
76
+ case 'agent.delta': return s0; // live partial text: the TUI waits for the finished message
76
77
  case 'agent.activity': {
77
78
  const text = oneLine(event.text);
78
79
  const a = agentOf(s0, event.agentId);
package/gui/app.css CHANGED
@@ -433,3 +433,15 @@ body.noroster #live{grid-template-columns:0 minmax(0,1fr) var(--iw)}body.noroste
433
433
  .out:last-of-type{margin-bottom:12px}
434
434
  #ctabs .ctab.add{min-width:28px;justify-content:center;font-weight:700;color:var(--mu)}#ctabs .ctab.add:hover{color:#fff}
435
435
  #inspector .out + .ish{margin-top:12px}
436
+
437
+ /* run switcher */
438
+ #runtabs{position:absolute;left:12px;right:12px;top:52px;z-index:4;display:flex;gap:6px;overflow-x:auto;pointer-events:auto}
439
+ #runtabs[hidden]{display:none}
440
+ .rtab{flex:none;display:flex;align-items:center;gap:6px;padding:3px 10px;border-radius:12px;border:1px solid var(--b2);background:rgba(6,12,24,.88);color:var(--mu);font-size:12px;cursor:pointer}
441
+ .rtab.on{border-color:rgba(33,214,232,.6);color:#dbe6f5}
442
+ .rtab .rel{font:600 10px var(--mono);opacity:.7}
443
+ .rdot{width:8px;height:8px;border-radius:50%;background:var(--gr)}
444
+ .rdot.waiting{background:var(--am)}.rdot.done{background:var(--cy)}.rdot.failed{background:var(--rd)}.rdot.stopped{background:var(--mu)}
445
+ .rdot.running{animation:rpulse 1.2s infinite}@keyframes rpulse{50%{opacity:.35}}
446
+ .rbadge{background:var(--am);color:#111;border-radius:8px;padding:0 5px;font-size:10px}
447
+ .aglive{margin-top:6px;font-size:11px;line-height:1.4;color:#9fb0c6;max-height:120px;overflow:auto;white-space:pre-wrap;word-break:break-word;border-left:2px solid #3b4a63;padding-left:6px;font-style:italic}
package/gui/app.js CHANGED
@@ -244,8 +244,16 @@
244
244
  }
245
245
 
246
246
  /* reducer */
247
+ /* Run-scoped API prefix for the run on screen ('current' = server focus run as fallback). */
248
+ function runBase() { return '/api/runs/' + encodeURIComponent((S.run && S.run.runId) || 'current'); }
247
249
  function onEvent(e) {
250
+ if (S.run && S.run.runId && e.runId && e.runId !== S.run.runId) return; /* another run's event: not for this view */
248
251
  if (e.type === 'run.started') comicCtx(e.config);
252
+ if (e.type === 'agent.delta') { /* live typing preview: per-agent buffer only, never stored in the event list */
253
+ var da = e.agentId ? A(e.agentId) : null;
254
+ if (da && typeof e.text === 'string') { da.live = ((da.live || '') + e.text).slice(-2000); S.dirty = true; }
255
+ return;
256
+ }
249
257
  comicCall('push', e);
250
258
  S.events.push(e); S.dirty = true;
251
259
  if (e.type !== 'agent.message') termLine(e.at, e.type + (e.agentId ? ' ' + e.agentId : '') + (e.stage ? ' ' + e.stage : '') + (e.from ? ' ' + e.from + '→' + e.to : '') + (e.verdict ? ' ' + e.verdict : '') + (e.label ? ' · ' + e.label : e.text && e.type !== 'user.message' ? ' · ' + plain(String(e.text)).slice(0, 120) : ''));
@@ -268,18 +276,19 @@
268
276
  break;
269
277
  }
270
278
  case 'agent.started':
271
- if (a) { a.state = 'thinking'; a.task = e.task; a.t0 = now; a.step = 0; a.label = ''; a.total = null; a.activity = ''; net.setState(e.agentId, 'thinking'); net.setStep(e.agentId, null); if (S.config && e.agentId !== S.config.director.id && !S.history) net.pulse(S.config.director.id, e.agentId, undefined, e.task ? plain(String(e.task)).slice(0, 26) : undefined); }
279
+ if (a) { a.live = ''; a.state = 'thinking'; a.task = e.task; a.t0 = now; a.step = 0; a.label = ''; a.total = null; a.activity = ''; net.setState(e.agentId, 'thinking'); net.setStep(e.agentId, null); if (S.config && e.agentId !== S.config.director.id && !S.history) net.pulse(S.config.director.id, e.agentId, undefined, e.task ? plain(String(e.task)).slice(0, 26) : undefined); }
272
280
  break;
273
281
  case 'agent.activity': if (a) { a.activity = e.text; bump(a); } break;
274
282
  case 'agent.step': if (a) { a.step = e.step; a.total = e.total; a.label = e.label; a.activity = e.label; net.setStep(e.agentId, {step: e.step, total: e.total, label: e.label}); bump(a); } break;
275
283
  case 'agent.message':
284
+ if (a) a.live = '';
276
285
  S.msgs++; S.tokens += e.tokens || 0; if (a) { a.state = 'done'; a.tokens += e.tokens || 0; a.msgs++; a.label = ''; a.outputs.unshift({text: e.text, to: e.to, at: e.at, tokens: e.tokens}); a.outputs.length = Math.min(a.outputs.length, 5); net.setState(e.agentId, 'done'); a.activity = 'finished turn'; }
277
286
  S.tokBuckets.push([Date.parse(e.at), S.tokens]); S.buckets.push(Date.parse(e.at));
278
287
  if (!S.history) { net.pulse(e.agentId, e.to === 'all' || e.to === 'director' ? S.config.director.id : e.to, undefined, e.round ? 'Round ' + e.round : plain(e.text).slice(0, 20)); bubbleFor(e.agentId, e.text, e, e.to); }
279
288
  termLine(e.at, nm(e.agentId) + ' → ' + nm(e.to) + (e.tokens ? ' (' + e.tokens + ' tok)' : '') + ': ' + plain(e.text).slice(0, 160));
280
289
  feedMsg(e);
281
290
  break;
282
- 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;
291
+ case 'agent.failed': if (a) { a.live = ''; 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;
283
292
  case 'handoff.created':
284
293
  S.handoffs.push(e); if (!S.history) { net.handoff(e.from, e.to, e.title); showHoBanner('HANDOFF ' + TL[e.from] + ' → ' + TL[e.to]); }
285
294
  feedBanner('ho', '⇢ HANDOFF ' + 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);
@@ -594,7 +603,7 @@
594
603
  frag.appendChild(h('div', {class: 'icard agent', style: '--tc:' + c}, [h('div', {class: 'aghead'}, [avatarEl(a.cfg, 64, {slot: 'i', state: a.state}), h('div', {class: 'agid'}, [h('b', {text: a.cfg.name}), h('div', {class: 'ml', style: 'color:' + c, text: TL[a.cfg.team]}), h('button', {class: 'chip', type: 'button', text: 'Change avatar', title: 'Pick a portrait. The agent keeps running; only the picture changes.', onclick: function () { avatarPicker(a.cfg, function (v) { saveAvatar(a.cfg.id, v); }); }})])]),
595
604
  kv('Engine', eng(a.cfg.cli).label + ' (' + a.cfg.cli + ')'), kv('Model', a.cfg.model || 'default'), kv('Access', a.cfg.access === 'write' ? 'read + write' : 'read only'), a.cfg.baseUrl ? kv('Endpoint', a.cfg.baseUrl.replace(/^https?:\/\//, '').slice(0, 26)) : null, kv('State', stateWord(a)), kv('Messages', a.msgs), kv('Tokens', fmtN(a.tokens)),
596
605
  a.total ? kv('Step', a.step + ' / ' + a.total) : null,
597
- h('div', {class: 'ml', style: 'margin-top:6px', text: 'Current task'}), h('div', {class: 'agtask', text: a.task || '—'})]));
606
+ h('div', {class: 'ml', style: 'margin-top:6px', text: 'Current task'}), h('div', {class: 'agtask', text: a.task || '—'}), a.live ? h('div', {class: 'aglive', title: 'Live text (preview)', text: a.live}) : null]));
598
607
  var af = (S.fails || []).filter(function (f) { return f.agentId === a.cfg.id; }).pop();
599
608
  if (af) frag.appendChild(h('div', {class: 'card fail failcard'}, [h('b', {class: 'bad', text: 'WHY IT FAILED'}), h('pre', {text: af.reason}), h('div', {class: 'fix'}, [h('b', {text: 'How to fix '}), fixHint(af.reason, a.cfg)]), h('div', {style: 'display:flex;gap:6px;margin-top:8px'}, [h('button', {text: 'Full details', onclick: showFailure}), h('button', {class: 'primary', text: 'Open Config', onclick: function () { setView('settings'); }})])]));
600
609
  frag.appendChild(secHead('RECENT OUTPUTS', a.outputs.length > 2 ? h('span', {class: 'ml', text: '2 / ' + a.outputs.length}) : null));
@@ -674,8 +683,8 @@
674
683
  }
675
684
  function waitButtons(wt) {
676
685
  var b = $('wbtns'); b.innerHTML = ''; b.hidden = !wt; if (!wt) return;
677
- 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'); }); }}));
678
- 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'); }); }}));
686
+ if (S.waiting && S.waiting.assumptions) b.appendChild(h('button', {class: 'chip', text: 'Proceed with assumptions', onclick: function () { api('POST', runBase() + '/proceed').then(function (r) { if (r.status !== 200) toast(r.body.error || 'could not proceed'); }); }}));
687
+ b.appendChild(h('button', {class: 'chip', text: 'Stop', onclick: function () { api('POST', runBase() + '/stop').then(function (r) { if (r.status !== 200) toast(r.body.error || 'No active run'); }); }}));
679
688
  }
680
689
  var lastRender = 0;
681
690
  function loop(now) {
@@ -734,8 +743,8 @@
734
743
  });
735
744
  }
736
745
  function simDefault() { return !S.config || !!S.simulatedDefault || !cfgAgents(S.config).some(function (a) { return a.cli !== 'auto' && a.cli !== 'simulated'; }); }
737
- 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; S.replaySpeed = speed; setComic(false); setView('live'); }); }
738
- function stopReplay() { api('POST', '/api/runs/current/stop').then(function (r) { if (r.status !== 200) toast(r.body.error || 'No replay is playing'); else toast('Replay stopped'); replayStopped(); }); }
746
+ function replay(id, speed) { S.starting = true; api('POST', '/api/runs/' + id + '/replay', {speed: speed}).then(function (r) { S.starting = false; if (r.status !== 200) { toast(r.body.error || 'replay failed'); return; } S.replay = true; S.replaySpeed = speed; setComic(false); setView('live'); }); }
747
+ function stopReplay() { api('POST', runBase() + '/stop').then(function (r) { if (r.status !== 200) toast(r.body.error || 'No replay is playing'); else toast('Replay stopped'); replayStopped(); }); }
739
748
  /* A stopped playback sends no run.completed, so the page is told separately (also for other open tabs). */
740
749
  function replayStopped() { if (S.run) S.run.running = false; S.dirty = true; if (S.view === 'runs') renderRuns(); }
741
750
  function newRunDialog() {
@@ -789,13 +798,19 @@
789
798
  function startRun(goal, sim, lane) {
790
799
  var ids = pendingIds(); if (!ids) return Promise.resolve(false);
791
800
  if (!goal.trim() && !ids.length) return Promise.resolve(false);
792
- 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; });
793
- }
801
+ S.starting = true;
802
+ return api('POST', '/api/runs', Object.assign({goal: goal, simulated: sim, attachments: ids}, lane ? {lane: lane} : {})).then(function (r) { S.starting = false; if (r.status !== 200) { toast(r.body.error || 'could not start the run'); return false; } clearPending(); closeModal(); S.replay = false; setView('live'); return true; });
803
+ }
804
+ /* Start another run even while one is live (plain Send still messages the run on screen). */
805
+ $('sendNew').onclick = function () {
806
+ var t = $('msg').value.trim(); if (!t) return newRunDialog();
807
+ startRun(t, simDefault(), $('lanewrap').hidden ? '' : $('lane').value).then(function (ok) { if (ok) { $('msg').value = ''; REQ.applied = null; syncEnh(); } });
808
+ };
794
809
  function send(text) {
795
810
  var chip = !!text; text = (text || $('msg').value).trim(); if (!text && !PEND.length) return;
796
811
  if (!(S.run && S.run.running && !S.outcome)) { startRun(text, simDefault(), $('lanewrap').hidden ? '' : $('lane').value).then(function (ok) { if (ok) { $('msg').value = ''; REQ.applied = null; syncEnh(); } }); return; }
797
812
  var ids = chip ? [] : pendingIds(); if (!ids) return;
798
- 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(); } } });
813
+ api('POST', runBase() + '/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(); } } });
799
814
  }
800
815
  /* "@" mentions: typing @ in a request box lists files and folders of the workspace; the chosen path goes into the text as @path */
801
816
  var MENT = null;
@@ -1217,12 +1232,59 @@
1217
1232
  if (SHOT === 'comic') setComic(true);
1218
1233
  if (SHOT === 'newrun') newRunDialog();
1219
1234
  }
1235
+ /* Run switcher: the view renders ONE run through its own per-run stream; the global stream only tracks every run's status (tabs + badges). */
1236
+ var RS = {}, runES = null, GREADY = false;
1237
+ function rsOf(id) { return RS[id] || (RS[id] = {runId: id, goal: '', running: true, waiting: false, outcome: null, startedAt: 0, badge: false}); }
1238
+ function rsLoad(list) { (list || []).forEach(function (r) { if (r.replay) return; var o = rsOf(r.runId); o.goal = r.goal || o.goal; o.running = r.running; o.outcome = r.outcome; o.startedAt = Date.parse(r.startedAt) || o.startedAt; }); renderTabs(); }
1239
+ function rsTrack(e) {
1240
+ if (!e.runId || (S.run && S.run.goal === '(replay)' && S.replay)) return;
1241
+ var o = rsOf(e.runId), cur = S.run && S.run.runId === e.runId, was = o.waiting || !!o.outcome;
1242
+ if (e.type === 'run.started') { o.goal = e.goal || o.goal; o.startedAt = Date.parse(e.at) || o.startedAt; o.running = true; o.outcome = null; }
1243
+ else if (e.type === 'run.waiting') o.waiting = true;
1244
+ else if (e.type === 'agent.started' || e.type === 'user.message' || e.type === 'stage.changed') o.waiting = false;
1245
+ else if (e.type === 'run.completed') { o.endedAt = Date.parse(e.at) || Date.now(); o.running = false; o.waiting = false; o.outcome = e.outcome || 'done'; }
1246
+ else return;
1247
+ if (cur) o.badge = false; else if (GREADY && !was && (o.waiting || o.outcome)) o.badge = true;
1248
+ renderTabs();
1249
+ }
1250
+ function tabState(o) { return o.outcome ? (o.outcome === 'delivered' ? 'done' : o.outcome === 'stopped' ? 'stopped' : 'failed') : o.waiting ? 'waiting' : 'running'; }
1251
+ function renderTabs() {
1252
+ var box = $('runtabs'), ids = Object.keys(RS).sort(function (a, b) { return RS[a].startedAt - RS[b].startedAt; });
1253
+ var fin = ids.filter(function (i) { return RS[i].outcome; }).slice(-3), keep = ids.filter(function (i) { return !RS[i].outcome || fin.indexOf(i) >= 0 || (S.run && S.run.runId === i); });
1254
+ box.hidden = keep.length < 2; box.innerHTML = '';
1255
+ keep.forEach(function (i) {
1256
+ var o = RS[i], st = tabState(o), on = S.run && S.run.runId === i;
1257
+ var b = h('button', {class: 'rtab' + (on ? ' on' : ''), type: 'button', title: (o.goal || i) + ' · ' + st, onclick: function () { if (!on) openRun(i); }}, [
1258
+ h('i', {class: 'rdot ' + st}), h('span', {class: 'rgoal', text: (o.goal || i).replace(/\s+/g, ' ').slice(0, 28)}), h('span', {class: 'rel', 'data-i': i, text: o.startedAt ? fmtT((o.outcome ? o.endedAt || Date.now() : Date.now()) - o.startedAt) : ''}), o.badge && !on ? h('b', {class: 'rbadge', text: st === 'waiting' ? '?' : '●'}) : null]);
1259
+ box.appendChild(b);
1260
+ });
1261
+ }
1262
+ setInterval(function () { var n = document.querySelectorAll('#runtabs .rel'); for (var k = 0; k < n.length; k++) { var o = RS[n[k].getAttribute('data-i')]; if (o && o.startedAt && !o.outcome) n[k].textContent = fmtT(Date.now() - o.startedAt); } }, 1000);
1263
+ /* Switch the view to one run: fresh state, close the previous per-run stream, replay that run's history then follow it live. */
1264
+ function openRun(id, goal) {
1265
+ if (runES) { runES.close(); runES = null; }
1266
+ resetRun(); var o = rsOf(id); o.badge = false; if (goal) o.goal = goal;
1267
+ S.run = {runId: id, running: !o.outcome, goal: o.goal}; S.replay = false; S.history = true; comicCall('setHistory', true); renderTabs();
1268
+ var es = runES = new EventSource('/api/runs/' + encodeURIComponent(id) + '/events?t=' + encodeURIComponent(TOKEN)), opens = 0;
1269
+ es.onopen = function () { if (es !== runES) return; if (opens++ > 0) { resetRun(); S.run = S.run || {runId: id}; S.history = true; comicCall('setHistory', true); } }; /* auto-reconnect replays history */
1270
+ es.onmessage = function (m) { if (es !== runES) return; try { onEvent(JSON.parse(m.data)); } catch (err) { console.error(err); } };
1271
+ es.addEventListener('ready', function () { if (es !== runES) return; S.history = false; comicCall('setHistory', false); S.dirty = true; shots(); });
1272
+ }
1220
1273
  function connect() {
1221
1274
  var es = new EventSource('/api/events?t=' + encodeURIComponent(TOKEN));
1222
- es.onmessage = function (m) { try { onEvent(JSON.parse(m.data)); } catch (err) { console.error(err); } };
1223
- es.addEventListener('reset', function () { resetRun(); S.history = true; comicCall('setHistory', true); });
1224
- es.addEventListener('ready', function () { S.history = false; comicCall('setHistory', false); S.dirty = true; shots(); });
1275
+ var first = true;
1276
+ es.addEventListener('ready', function () { GREADY = true; });
1277
+ es.addEventListener('error', function () { GREADY = false; });
1225
1278
  es.addEventListener('replaystop', replayStopped);
1279
+ es.onopen = function () { if (!first) api('GET', '/api/state').then(function (r) { if (r.status === 200) rsLoad(r.body.runs); }); first = false; };
1280
+ es.onmessage = function (m) { try { rsTrack(JSON.parse(m.data)); } catch (err) { console.error(err); } };
1281
+ /* A run started from this page takes over the view; runs started elsewhere do not disturb a live one. */
1282
+ es.addEventListener('runstarted', function (m) {
1283
+ var d; try { d = JSON.parse(m.data); } catch (err) { return; }
1284
+ rsOf(d.runId).startedAt = rsOf(d.runId).startedAt || Date.now();
1285
+ if (!S.starting && S.run && S.run.running && !S.outcome) { renderTabs(); return; }
1286
+ S.starting = false; openRun(d.runId);
1287
+ });
1226
1288
  }
1227
1289
  api('GET', '/api/clis').then(function (r) { if (r.status === 200) { CLIS = r.body.clis || []; S.configFile = r.body.configFile; if (S.view === 'settings') setView('settings'); } });
1228
1290
  api('GET', '/api/state').then(function (r) {
@@ -1239,6 +1301,7 @@
1239
1301
  setupAgents(S.config); comicCtx(S.config);
1240
1302
  // First run (no .ckit/team.json, nothing running): land on Config so setup starts in the GUI.
1241
1303
  var v = location.hash.slice(1); setView(['live', 'settings', 'runs'].indexOf(v) >= 0 ? v : (!S.configExists && !r.body.run && !SHOT && Q.get('demo') !== '1') ? 'settings' : 'live');
1304
+ rsLoad(r.body.runs); if (r.body.run) { var fr = r.body.run; openRun(fr.runId, fr.goal); S.replay = !!(fr.goal === '(replay)'); S.replaySpeed = fr.replay ? fr.replay.speed : 0; }
1242
1305
  connect(); requestAnimationFrame(loop);
1243
1306
  if (Q.get('demo') === '1' && !r.body.run) startRun('Add a dark-mode toggle to the settings page', true);
1244
1307
  });
package/gui/index.html CHANGED
@@ -34,6 +34,7 @@
34
34
  <main id="live">
35
35
  <aside id="roster" aria-label="Agents"></aside>
36
36
  <section id="center">
37
+ <div id="runtabs" hidden></div>
37
38
  <canvas id="net" aria-label="Agent topology"></canvas>
38
39
  <div id="bubbles"></div>
39
40
  <div id="mission"><span class="mtag" id="mtag">READY</span><span id="mgoal">No active run — type a mission below.</span><button class="primary" id="bHint" type="button">+ New run</button></div>
@@ -52,7 +53,7 @@
52
53
  <div class="dh"><span class="ml" id="clabel">OWNER → DIRECTOR</span><span class="ctools"><button class="chip" id="enh" title="Rewrite your request so the Director cannot misread it. You decide whether to use the result.">✦ Enhance</button></span><input type="file" id="file" multiple hidden><span id="cnote"></span></div>
53
54
  <div class="chips" id="chips"></div><div class="chips" id="wbtns" hidden></div><span id="lanewrap" hidden><select id="lane" title="Lane for this request. Auto: the Director decides which lane fits."></select></span>
54
55
  <div class="attlist" id="atts"></div>
55
- <div class="cbox"><button class="cattach" id="attach" type="button" title="Attach any files: images, PDF, Word, Excel, drawio, XML… You can also drop or paste them here." aria-label="Attach files"><svg viewBox="0 0 24 24"><path d="M20 11.5l-8 8a5 5 0 01-7-7l8.5-8.5a3.3 3.3 0 014.7 4.7L9.6 17.3a1.7 1.7 0 01-2.4-2.4L15 7" fill="none"/></svg></button><textarea id="msg" rows="1" placeholder="Gửi tin nhắn cho Director… (Enter to send, @ for a file)" aria-label="Message"></textarea><span class="kbd" aria-hidden="true">Enter ↵</span><button class="primary" id="send" aria-label="Send">Send ▸</button></div>
56
+ <div class="cbox"><button class="cattach" id="attach" type="button" title="Attach any files: images, PDF, Word, Excel, drawio, XML… You can also drop or paste them here." aria-label="Attach files"><svg viewBox="0 0 24 24"><path d="M20 11.5l-8 8a5 5 0 01-7-7l8.5-8.5a3.3 3.3 0 014.7 4.7L9.6 17.3a1.7 1.7 0 01-2.4-2.4L15 7" fill="none"/></svg></button><textarea id="msg" rows="1" placeholder="Gửi tin nhắn cho Director… (Enter to send, @ for a file)" aria-label="Message"></textarea><span class="kbd" aria-hidden="true">Enter ↵</span><button id="sendNew" type="button" title="Start a separate new run with this text (the current run keeps going)">+ New run</button><button class="primary" id="send" aria-label="Send">Send ▸</button></div>
56
57
  </div>
57
58
  </section>
58
59
  <div class="rz col" id="rzL" title="Drag to resize · double-click to reset"></div><div class="rz col" id="rzR" title="Drag to resize · double-click to reset"></div><div class="rz row" id="rzD" title="Drag to resize · double-click to reset"></div><div class="rz col" id="rzC" title="Drag to resize · double-click to reset"></div>
package/gui/network.js CHANGED
@@ -56,12 +56,16 @@
56
56
  M = mk(s, true); if (M.fit || s <= .4) break;
57
57
  s = Math.max(.4, s * .94);
58
58
  }
59
+ var minCw = 108;
60
+ if (M.total > W - 24) { /* still too wide at the smallest scale: squeeze the horizontal spacing so no team or agent is clipped */
61
+ var k = (W - 24) / M.total; M.sp *= k; M.tg *= k; minCw *= k; M.total = W - 24;
62
+ }
59
63
  S = M.s; hub = {x: W / 2, y: M.dirY, r: M.hr};
60
64
  geo = {hubB: M.hubB, bus1: M.bus1, bus2: M.bus2, teamB: M.teamB, baseY: H - 12, plH: M.plH};
61
65
  zones = {}; nodes = {};
62
66
  var x = (W - M.total) / 2, gi = 0;
63
67
  tids.forEach(function (t) {
64
- var L = lists[t], n = L.length, cw = Math.max(n * M.sp, 108), cx = x + cw / 2, col = TEAM_COLOR[t] || '#8A9AAF';
68
+ var L = lists[t], n = L.length, cw = Math.max(n * M.sp, minCw), cx = x + cw / 2, col = TEAM_COLOR[t] || '#8A9AAF';
65
69
  zones[t] = {id: t, x: cx, y: M.teamY, r: M.tr, n: n, color: col};
66
70
  L.forEach(function (a, i) {
67
71
  var o = old[a.id], ay = M.agentY + (M.zig && gi % 2 ? M.zdy : 0); gi++;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ngockhoale/ckit",
3
- "version": "0.2.10",
3
+ "version": "0.3.0",
4
4
  "description": "CKit — local Agent Company: a Director plus BA / Implement / QC teams running your own codex, claude and omp CLIs, with a web Mission Control (ckit gui).",
5
5
  "type": "module",
6
6
  "bin": {