@ngockhoale/ckit 0.2.1 → 0.2.3

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/gui/app.css CHANGED
@@ -181,7 +181,7 @@ a.att:hover{border-color:var(--cy)}
181
181
  #lanename{font:700 10px var(--mono);letter-spacing:.08em;color:var(--vi);border:1px solid #4a3a7a;border-radius:3px;padding:4px 8px;white-space:nowrap;text-transform:uppercase}#lanename[hidden]{display:none}
182
182
  #now.ask{background:#ffd9a0;border-color:#5a2d00}#now.ask .nowtag{background:#5a2d00;color:#ffd9a0}
183
183
  .qcard{border:1px solid var(--am);background:rgba(243,165,68,.07);border-radius:6px;padding:10px 14px;font-size:13px;line-height:1.5}.qcard b{color:var(--am)}.qcard ol,.qcard ul{margin:6px 0 6px 20px;padding:0}.qcard li{margin:3px 0}.qcard .qhint{font:11px var(--mono);color:var(--mu);margin-top:6px}
184
- #wbtns{margin:4px 0}#wbtns[hidden],#lanewrap[hidden]{display:none}#lanewrap{display:block;margin:0 0 6px}#lanewrap select,.laneSel{font:11px var(--mono);width:100%}
184
+ #composer.wait{border-color:var(--am);box-shadow:0 0 0 1px var(--am),0 0 26px rgba(243,165,68,.35);animation:waitpulse 1.6s ease-in-out infinite}#composer.wait #clabel{color:var(--am)}@keyframes waitpulse{50%{box-shadow:0 0 0 1px var(--am),0 0 10px rgba(243,165,68,.15)}}@media (prefers-reduced-motion:reduce){#composer.wait{animation:none}}.qcard .qgo{margin-top:8px}#wbtns{margin:4px 0}#wbtns[hidden],#lanewrap[hidden]{display:none}#lanewrap{display:block;margin:0 0 6px}#lanewrap select,.laneSel{font:11px var(--mono);width:100%}
185
185
  .rnd{font:700 9px var(--mono);letter-spacing:.08em;color:var(--mu);border:1px solid var(--b1);border-radius:8px;padding:1px 6px;margin-left:6px;text-transform:uppercase}
186
186
  .rteam.dim,.tile.dim{opacity:.35}
187
187
  .card.ho.click{cursor:pointer}.card.ho .hos{font-size:11px;line-height:1.4;margin-top:3px;color:#c4d0e4}.card.ho .hos b{display:block;font:700 9px var(--mono);letter-spacing:.1em;color:var(--cy)}
@@ -197,7 +197,7 @@ table.runs td.warn{color:var(--am)}
197
197
  .chkrow{display:flex;gap:8px;align-items:flex-start;margin:6px 0}.chkrow input{width:auto;margin-top:3px}
198
198
 
199
199
  /* text dialog (askText) */
200
- .ask{position:fixed;inset:0;z-index:80;display:grid;place-items:center;background:rgba(3,5,10,.72);backdrop-filter:blur(6px);animation:askfade .14s ease-out}
200
+ .asklayer{position:fixed;inset:0;z-index:80;display:grid;place-items:center;background:rgba(3,5,10,.72);backdrop-filter:blur(6px);animation:askfade .14s ease-out}
201
201
  .askcard{width:min(520px,92vw);background:linear-gradient(180deg,rgba(33,214,232,.07),transparent 90px),var(--p1);border:1px solid var(--b2);border-top:2px solid var(--cy);border-radius:6px;box-shadow:0 24px 80px rgba(0,0,0,.6),0 0 60px rgba(33,214,232,.14);animation:askpop .18s cubic-bezier(.2,1.2,.4,1)}
202
202
  .askcard header{display:flex;justify-content:space-between;align-items:center;padding:14px 18px 4px}.askcard header b{font:700 13px var(--mono);letter-spacing:.14em;text-transform:uppercase;color:#fff}
203
203
  .askx{border:0;background:none;color:var(--mu);padding:2px 6px;font-size:13px}.askx:hover{color:#fff;box-shadow:none}
@@ -206,3 +206,62 @@ table.runs td.warn{color:var(--am)}
206
206
  .askchips{display:flex;flex-wrap:wrap;gap:6px;align-items:center;margin-top:4px}.askchips span{font:11px var(--mono);color:var(--mu);margin-right:2px}.askchips button{font:12px var(--mono);padding:3px 9px;border-radius:999px}
207
207
  .askcard footer{display:flex;gap:8px;align-items:center;justify-content:flex-end;padding:12px 18px 16px}.askkeys{margin-right:auto;font:11px var(--mono);color:var(--mu)}
208
208
  @keyframes askfade{from{opacity:0}to{opacity:1}}@keyframes askpop{from{opacity:0;transform:translateY(8px) scale(.98)}to{opacity:1;transform:none}}
209
+ /* composer Enhance + comic empty state */
210
+ .ctools{display:flex;gap:6px;align-items:flex-start}#enh{color:#c9b4ff;border-color:#4a3a86;background:rgba(163,107,255,.08)}#enh:hover:not([disabled]){border-color:var(--vi);box-shadow:0 0 12px rgba(163,107,255,.35)}#enh[disabled]{opacity:.45;cursor:not-allowed}#enh.busy{opacity:1;animation:enhpulse 1.1s ease-in-out infinite}
211
+ @keyframes enhpulse{50%{box-shadow:0 0 16px rgba(163,107,255,.55);border-color:var(--vi)}}
212
+ .dlg.enhdlg{width:min(1040px,95vw);border-top:2px solid var(--vi)}.enhcols{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1.5fr);gap:14px}.enhcols .ml{margin-bottom:6px}
213
+ .enhorig{white-space:pre-wrap;word-break:break-word;font-size:13px;line-height:1.55;color:var(--mu);max-height:52vh;overflow:auto;padding:10px 12px;border:1px dashed var(--b2);border-radius:4px}
214
+ .enhta{width:100%;height:52vh;resize:vertical;font-size:13.5px;line-height:1.55;border-color:#4a3a86}.enhnote{margin:10px 0 0;font-size:12px;color:var(--mu)}
215
+ @media (max-width:820px){.enhcols{grid-template-columns:1fr}.enhta{height:34vh}.enhorig{max-height:18vh}}
216
+ #comicpanels:empty::before{content:'Comic view retells a run as comic panels: who said what, each handoff, each verdict.\A Nothing to show yet: start a mission in the box below, or open Runs and replay an old one.';white-space:pre-line;display:block;margin:12vh auto 0;max-width:560px;text-align:center;font:13px/1.7 var(--mono);color:var(--mu)}
217
+ /* "@" file mentions */
218
+ .ment{position:fixed;z-index:90;display:flex;flex-direction:column;overflow:auto;background:var(--p1);border:1px solid var(--b2);border-top:2px solid var(--cy);border-radius:6px;box-shadow:0 18px 60px rgba(0,0,0,.65),0 0 40px rgba(33,214,232,.12);padding:4px}
219
+ .menth{display:flex;justify-content:space-between;gap:12px;padding:6px 8px 7px;font:600 10px var(--mono);letter-spacing:.08em;color:var(--mu);position:sticky;top:-4px;background:var(--p1);white-space:nowrap}.menth span:first-child{overflow:hidden;text-overflow:ellipsis}.menth span:last-child{letter-spacing:0;font-weight:400}
220
+ .mentrow{display:flex;align-items:baseline;gap:8px;padding:6px 8px;border-radius:4px;cursor:pointer;font:13px var(--mono);white-space:nowrap}.mentrow b{font-weight:600;color:#e6eefb}.mentrow small{color:var(--mu);font-size:11px;overflow:hidden;text-overflow:ellipsis;min-width:0}
221
+ .menti{width:10px;color:var(--cy);flex:none}.mentrow:hover{background:rgba(255,255,255,.04)}.mentrow.on{background:rgba(33,214,232,.13);box-shadow:inset 2px 0 0 var(--cy)}.mentnone{padding:10px 8px;font-size:12px;color:var(--mu)}
222
+ /* workspace explorer */
223
+ #ws{cursor:pointer;border-radius:4px;transition:.15s}#ws:hover{background:rgba(33,214,232,.08)}#ws:focus-visible{outline:1px solid var(--cy)}
224
+ .dlg.exdlg{width:min(1240px,96vw);height:min(84vh,860px);max-height:none}
225
+ .exdlg header{gap:12px}.exdlg header b{font:700 13px var(--mono);letter-spacing:.14em;color:#fff;white-space:nowrap}
226
+ .exroot{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:var(--mu);font-size:11px;direction:rtl;text-align:left}
227
+ .excopy{font-size:11px;padding:3px 9px}.exlive{display:flex;align-items:center;gap:5px;font:600 10px var(--mono);letter-spacing:.1em;text-transform:uppercase;color:var(--gr)}
228
+ .exlive i{width:7px;height:7px;border-radius:50%;background:var(--gr);box-shadow:0 0 8px var(--gr);animation:blink 2s infinite}.exlive.off{color:var(--rd)}.exlive.off i{background:var(--rd);box-shadow:none;animation:none}
229
+ .extool{display:flex;align-items:center;gap:8px;padding:10px 16px;border-bottom:1px solid var(--b1);flex:none}
230
+ .extool button{white-space:nowrap}.exup{width:32px;padding:6px 0;font-weight:700}
231
+ .exbc{flex:1;min-width:0;display:flex;align-items:center;gap:2px;overflow:hidden;white-space:nowrap}
232
+ .excrumb{background:none;border:1px solid transparent;padding:4px 8px;color:var(--mu);max-width:200px;overflow:hidden;text-overflow:ellipsis;flex:0 1 auto;min-width:0}
233
+ .excrumb:hover{color:#fff;border-color:var(--b2);box-shadow:none}.excrumb.cur{color:var(--cy);font-weight:600}.excrumb.dropto{border-color:var(--cy);background:rgba(33,214,232,.16);color:#fff}.exsep{color:var(--b2)}
234
+ .exfilter{width:190px;flex:none;padding:6px 9px}.exref{border-color:var(--vi);color:#d8c2ff;background:rgba(163,107,255,.1)}
235
+ .exmain{flex:1;min-height:0;display:grid;grid-template-columns:minmax(0,1fr) 0}.exdlg.hasprev .exmain{grid-template-columns:minmax(0,1fr) minmax(300px,38%)}
236
+ .exlist{position:relative;display:flex;flex-direction:column;min-width:0;min-height:0}.exprev{min-width:0;overflow:hidden;display:flex;flex-direction:column;border-left:1px solid var(--b1);background:#080d17}
237
+ .exdlg:not(.hasprev) .exprev{display:none}
238
+ .exrow{display:grid;grid-template-columns:34px minmax(0,1fr) 84px 108px 118px;align-items:center;gap:6px;padding:0 16px;height:36px;flex:none}
239
+ .exhead{height:30px;border-bottom:1px solid var(--b1);background:#09101c}.exhead>span:first-child{display:block}
240
+ .exsort{background:none;border:0;padding:0;text-align:left;font:600 10px var(--mono);letter-spacing:.1em;text-transform:uppercase;color:var(--mu);height:100%}.exsort:hover{color:#fff;box-shadow:none}.exsort.on{color:var(--cy)}.exsort.on::after{content:' ' attr(data-arrow);font-size:8px}
241
+ .exrows{flex:1;min-height:0;overflow:auto;outline:none;scrollbar-gutter:stable}
242
+ .exitem{border-bottom:1px solid rgba(37,51,71,.45);cursor:default;user-select:none;position:relative;border-left:2px solid transparent;padding-left:14px}
243
+ .exitem:hover{background:rgba(33,214,232,.05)}.exitem.sel{background:rgba(33,214,232,.14);border-left-color:var(--cy)}.exrows:focus-within .exitem.sel{background:rgba(33,214,232,.2)}
244
+ .exitem.dropto{background:rgba(163,107,255,.25);outline:1px dashed var(--vi);outline-offset:-2px}
245
+ .exitem.pulse{animation:expulse 2.4s ease-out}@keyframes expulse{0%{background:rgba(74,214,154,.4)}100%{background:transparent}}
246
+ .exic{font:700 11px var(--mono);text-align:center;width:26px;height:22px;line-height:22px;border-radius:4px;background:#121b2b;color:var(--mu)}
247
+ .exic.dir{color:var(--am);background:rgba(243,165,68,.12);font-size:13px}.exic.img{color:var(--mg);background:rgba(240,79,155,.12)}.exic.doc{color:var(--bl);background:rgba(79,140,255,.12)}.exic.code{color:var(--cy);background:rgba(33,214,232,.1);font-size:9px}
248
+ .exname{display:flex;align-items:center;gap:8px;min-width:0}.exn{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;min-width:0}
249
+ .exbadge{flex:none;font:700 9px var(--mono);letter-spacing:.08em;padding:1px 6px;border-radius:9px;border:1px solid}
250
+ .exbadge.new{color:var(--gr);border-color:#1f5b44;background:rgba(74,214,154,.12)}.exbadge.chg{color:var(--am);border-color:#6b4a1c;background:rgba(243,165,68,.1)}.exbadge.run{color:var(--vi);border-color:#4b3380;background:rgba(163,107,255,.1)}
251
+ .exsize,.exmod{color:var(--mu);font-size:12px;white-space:nowrap;font-variant-numeric:tabular-nums}
252
+ .exacts{display:flex;gap:2px;justify-content:flex-end;opacity:0;transition:opacity .12s}.exitem:hover .exacts,.exitem.sel .exacts{opacity:1}
253
+ .exact{padding:2px 6px;font-size:12px;line-height:18px;border-color:transparent;background:none;color:var(--mu)}.exact:hover{color:#fff;border-color:var(--b2);box-shadow:none}
254
+ .exempty,.exnoprev{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:8px;text-align:center;color:var(--mu);padding:30px;flex:1}
255
+ .exebig{font:700 34px var(--mono);color:var(--b2)}.exetitle{font-size:14px;color:var(--tx);font-weight:600}.exetitle.err{color:var(--rd)}.exesub{font-size:12px;max-width:380px;line-height:1.5}
256
+ .exdrop{display:none;position:absolute;inset:0;z-index:3;place-items:center;font:700 15px var(--mono);color:#fff;background:rgba(33,214,232,.12);border:2px dashed var(--cy);pointer-events:none}.exlist.over .exdrop{display:grid}
257
+ .exph{display:flex;align-items:center;justify-content:space-between;gap:8px;padding:12px 14px 2px}.exphn{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:13px;color:#fff}
258
+ .exmeta{display:flex;gap:12px;padding:0 14px;color:var(--mu);font-size:11px}.exbtns{display:flex;gap:8px;padding:10px 14px;flex-wrap:wrap}
259
+ .exbtns .btn,.exnoprev .btn{display:inline-block;font:inherit;color:var(--tx);background:var(--p2);border:1px solid var(--b2);border-radius:4px;padding:6px 12px;text-decoration:none}.exbtns .btn:hover,.exnoprev .btn:hover{border-color:var(--cy)}.exnoprev .btn.primary{background:linear-gradient(135deg,#1b6dd8,#7a3fd0);border-color:#6f8cff}
260
+ .exbody{flex:1;min-height:0;overflow:auto;border-top:1px solid var(--b1);display:flex;flex-direction:column}.extext{margin:0;padding:12px 14px;font:12px/1.55 var(--mono);color:#cfe0f3;white-space:pre-wrap;word-break:break-word;tab-size:2}
261
+ .eximg{max-width:100%;margin:12px auto;display:block;background:repeating-conic-gradient(#111a2a 0 25%,#0b1220 0 50%) 0 0/16px 16px;border:1px solid var(--b1);object-fit:contain}.exload{padding:20px;color:var(--mu)}
262
+ .exups{max-height:116px;overflow:auto;border-top:1px solid var(--b1);padding:6px 16px;flex:none}
263
+ .exu{display:grid;grid-template-columns:minmax(0,1fr) 130px minmax(0,1.2fr) 22px;gap:10px;align-items:center;font-size:12px;height:24px}.exun{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
264
+ .exubar{height:5px;border-radius:3px;background:#121b2b;overflow:hidden}.exubar i{display:block;height:100%;background:linear-gradient(90deg,var(--cy),var(--vi));transition:width .15s}
265
+ .exu.ok .exubar i{background:var(--gr)}.exu.bad .exubar i{background:var(--rd)}.exust{color:var(--mu);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.exu.bad .exust{color:var(--rd)}.exu.ok .exust{color:var(--gr)}
266
+ .exfoot{justify-content:space-between!important;align-items:center;font-size:11px;color:var(--mu)}.exstat.err{color:var(--rd)}.exhint{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;min-width:0}
267
+ @media (max-width:1000px){.exdlg.hasprev .exmain{grid-template-columns:minmax(0,1fr);grid-template-rows:minmax(0,1fr) 40%}.exdlg.hasprev .exprev{border-left:0;border-top:1px solid var(--b1)}.exfilter{width:130px}}
package/gui/app.js CHANGED
@@ -33,6 +33,7 @@
33
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};
34
34
  var net = window.CKNet.create($('net'));
35
35
  window.__ck = {S: S, net: net};
36
+ window.__ck.api = {h: h, token: TOKEN, S: S, openModal: function (n) { openModal(n); }, closeModal: function () { closeModal(); }, toast: function (t) { toast(t); }, askText: function (o) { return askText(o); }};
36
37
 
37
38
  var XPAL = ['#FF6B8A', '#8BE04E', '#4F9DFF', '#FF8A4C', '#E0C341', '#B58CFF'], BUILTIN = {director: 1, ba: 1, implement: 1, qc: 1};
38
39
  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.'};
@@ -86,7 +87,7 @@
86
87
  function caption() {
87
88
  var st = S.stageKey && S.stageKey.slice(0, 2) === 'x:' ? 'x' : S.stageKey, n = activeSubs(), c;
88
89
  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';
90
+ else if (S.waiting) c = '<b>Director</b> is waiting for your answer — ' + (S.waiting.team ? 'the run is paused' : 'nothing is running');
90
91
  else if (!st) c = 'Chờ nhiệm vụ…';
91
92
  else if (st === 'director-intake') c = '<b>Director</b> đang tiếp nhận và phân tích yêu cầu';
92
93
  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)';
@@ -235,7 +236,7 @@
235
236
  feedBanner(e.verdict === 'PASS' ? 'pass' : 'fail', 'Director review · ' + e.verdict + ' — ' + e.summary);
236
237
  comicSimple('director', 'DIRECTOR REVIEW · ' + e.verdict, e.summary);
237
238
  break;
238
- case 'run.waiting': S.waiting = {round: e.round, questions: e.questions, assumptions: e.assumptions}; feedQuestions(e); setNarr('Director needs your answer'); break;
239
+ case 'run.waiting': S.waiting = {round: e.round, questions: e.questions, assumptions: e.assumptions, team: e.team || ''}; feedQuestions(e); setNarr('Director needs your answer'); break;
239
240
  case 'subagent.started':
240
241
  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); }
241
242
  break;
@@ -275,9 +276,10 @@
275
276
  function feedQuestions(e) {
276
277
  var qs = String(e.questions || '').split('\n').map(function (l) { return l.replace(/^\s*\d+[.)]\s*/, '').trim(); }).filter(Boolean);
277
278
  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
+ $('feed').appendChild(h('div', {class: 'qcard'}, [h('b', {text: e.team ? 'Director needs your decision · asked by ' + teamLbl(e.team) : 'Director needs your answer · round ' + e.round + ' of 3'}), h('ol', {}, qs.map(function (q) { return h('li', {text: q}); })),
279
280
  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
+ h('div', {class: 'qhint', text: as.length ? 'Type your answer in the ANSWER box (you can attach files and use @), or choose Proceed with assumptions.' : e.team ? 'Type your answer in the ANSWER box (you can attach files and use @). The run is paused until you answer.' : 'Type your answer in the ANSWER box (you can attach files and use @). No team starts until you answer.'}),
282
+ h('button', {class: 'primary qgo', type: 'button', text: 'Answer now ▸', onclick: function () { $('msg').focus(); }})])); feedScroll(); count();
281
283
  }
282
284
  function feedSub(parent, t) { $('feed').appendChild(h('div', {class: 'fsub', text: '↳ ' + nm(parent) + ' ' + t})); feedScroll(); }
283
285
  function count() { $('feedcount').textContent = S.events.filter(function (e) { return e.type === 'agent.message'; }).length + ' MESSAGES'; }
@@ -341,7 +343,7 @@
341
343
  h('div', {class: 'askbody'}, [h('label', {class: 'ml', text: o.label}), input, err, chips, o.hint ? h('p', {text: o.hint}) : null]),
342
344
  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
345
  card.setAttribute('role', 'dialog'); card.setAttribute('aria-modal', 'true'); card.setAttribute('aria-label', o.title);
344
- var layer = h('div', {class: 'ask'}, [card]);
346
+ var layer = h('div', {class: 'asklayer'}, [card]);
345
347
  layer.addEventListener('mousedown', function (e) { if (e.target === layer) close(null); });
346
348
  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
349
  input.addEventListener('input', function () { err.textContent = ''; });
@@ -490,16 +492,16 @@
490
492
  $('active').textContent = S.order.filter(function (i) { return A(i).state === 'thinking'; }).length + activeSubs();
491
493
  $('idleHint').style.display = S.run ? 'none' : ''; $('now').style.display = S.run ? '' : 'none';
492
494
  /* composer: talks to the Director during a run, starts a mission when nothing is running */
493
- var sim = simDefault(), wt = !!(live && S.waiting), mode = wt ? 'wait' + (S.waiting.assumptions ? 'A' : '') : live ? 'live' : sim ? 'sim' : 'real';
495
+ var sim = simDefault(), wt = !!(live && S.waiting), mode = wt ? 'wait' + (S.waiting.assumptions ? 'A' : '') + S.waiting.round + (S.waiting.team || '') : live ? 'live' : sim ? 'sim' : 'real';
494
496
  if (S.cmode !== mode) {
495
497
  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
+ $('composer').classList.toggle('wait', wt); $('msg').placeholder = wt ? 'Type your answer and press Enter… (@ for a file, 📎 to attach)' : live ? 'Message the Director… (Enter to send, @ for a file)' : 'Describe the mission and press Enter to start the team… Type @ to point at a file or folder.';
499
+ $('cnote').textContent = wt ? (S.waiting.team ? 'The run is paused: the Director is waiting for your decision.' : '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
500
  waitButtons(wt); if (wt) setTimeout(function () { $('msg').focus(); }, 30);
499
501
  }
500
502
  var lanes = (S.config && S.config.lanes) || [], sig = live ? '' : lanes.map(function (l) { return l.id + ':' + l.name; }).join('|');
501
503
  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;
504
+ $('lanewrap').hidden = !sig; syncEnh();
503
505
  }
504
506
  function laneSelect() {
505
507
  var lanes = (S.config && S.config.lanes) || []; if (!lanes.length) return null;
@@ -556,7 +558,7 @@
556
558
  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)'])]),
557
559
  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
560
  if (laneSel) $('modal').querySelector('.body').appendChild(h('div', {style: 'margin-top:12px'}, [h('div', {class: 'ml', text: 'LANE'}), laneSel]));
559
- renderPending(); setTimeout(function () { goal.focus(); }, 30);
561
+ mentionable(goal); renderPending(); setTimeout(function () { goal.focus(); }, 30);
560
562
  }
561
563
  /* attachments waiting to be sent: uploaded as soon as they are picked, claimed by id when the message / mission is sent */
562
564
  var PEND = [];
@@ -604,10 +606,87 @@
604
606
  }
605
607
  function send(text) {
606
608
  var chip = !!text; text = (text || $('msg').value).trim(); if (!text && !PEND.length) 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; }
609
+ 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; }
608
610
  var ids = chip ? [] : pendingIds(); if (!ids) return;
609
611
  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(); } } });
610
612
  }
613
+ /* "@" mentions: typing @ in a request box lists files and folders of the workspace; the chosen path goes into the text as @path */
614
+ var MENT = null;
615
+ function mentionClose() { if (MENT) { MENT.box.remove(); MENT = null; } }
616
+ function mentionToken(ta) {
617
+ var before = ta.value.slice(0, ta.selectionStart), m = /(^|\s)@(?:"([^"\n]*)|([^\s"]*))$/.exec(before); if (!m) return null;
618
+ var q = m[2] !== undefined ? m[2] : m[3]; return {q: q, start: before.length - q.length - (m[2] !== undefined ? 2 : 1)};
619
+ }
620
+ function mentionPick(ta, f, stay) {
621
+ var t = mentionToken(ta); if (!t) return mentionClose();
622
+ var path = f.path + (f.dir ? '/' : ''), txt = '@' + (/\s/.test(path) ? '"' + path + (stay ? '' : '"') : path) + (stay ? '' : ' ');
623
+ ta.value = ta.value.slice(0, t.start) + txt + ta.value.slice(ta.selectionStart); var pos = t.start + txt.length; ta.setSelectionRange(pos, pos);
624
+ ta.dispatchEvent(new Event('input')); if (!stay) mentionClose();
625
+ }
626
+ function mentionDraw(ta) {
627
+ var M = MENT, r = ta.getBoundingClientRect(); M.box.innerHTML = '';
628
+ M.box.appendChild(h('div', {class: 'menth'}, [h('span', {text: M.q ? 'FILES MATCHING “' + M.q + '”' : 'FILES IN ' + (S.projectRoot ? shortPath(S.projectRoot) : 'THIS FOLDER')}), h('span', {text: '↑↓ move · Enter pick · Tab open folder · Esc close'})]));
629
+ if (!M.items.length) M.box.appendChild(h('div', {class: 'mentnone', text: M.loading ? 'Searching…' : M.error || 'No file or folder matches. Keep typing, or press Esc.'}));
630
+ M.items.forEach(function (f, i) {
631
+ var cut = f.path.lastIndexOf('/'), row = h('div', {class: 'mentrow' + (i === M.idx ? ' on' : '')}, [h('span', {class: 'menti', text: f.dir ? '▸' : '·'}), h('b', {text: f.path.slice(cut + 1) + (f.dir ? '/' : '')}), h('small', {text: cut >= 0 ? f.path.slice(0, cut) : ''})]);
632
+ row.addEventListener('mousedown', function (ev) { ev.preventDefault(); mentionPick(ta, f, false); });
633
+ M.box.appendChild(row); if (i === M.idx) setTimeout(function () { row.scrollIntoView({block: 'nearest'}); }, 0);
634
+ });
635
+ var w = Math.max(360, Math.min(560, window.innerWidth - 24)); M.box.style.width = w + 'px';
636
+ M.box.style.left = Math.max(12, Math.min(r.left, window.innerWidth - w - 12)) + 'px'; M.box.style.bottom = (window.innerHeight - r.top + 6) + 'px'; M.box.style.maxHeight = Math.max(140, Math.min(340, r.top - 18)) + 'px';
637
+ }
638
+ function mentionSync(ta) {
639
+ var t = mentionToken(ta); if (!t) return mentionClose();
640
+ if (!MENT || MENT.ta !== ta) { mentionClose(); MENT = {ta: ta, box: h('div', {class: 'ment'}), items: [], idx: 0, q: '', seq: 0, loading: true, error: ''}; document.body.appendChild(MENT.box); }
641
+ var M = MENT, seq = ++M.seq; M.q = t.q; M.loading = true; mentionDraw(ta);
642
+ clearTimeout(M.timer); M.timer = setTimeout(function () {
643
+ api('GET', '/api/files?q=' + encodeURIComponent(t.q)).then(function (r) { if (MENT !== M || M.seq !== seq) return; M.loading = false; M.error = r.status === 200 ? '' : (r.body.error || 'Could not list files.'); M.items = r.status === 200 ? r.body.files : []; M.idx = 0; mentionDraw(ta); });
644
+ }, 70);
645
+ }
646
+ function mentionable(ta) {
647
+ ta.addEventListener('input', function () { mentionSync(ta); });
648
+ ta.addEventListener('click', function () { if (MENT) mentionSync(ta); });
649
+ ta.addEventListener('blur', function () { setTimeout(function () { if (MENT && MENT.ta === ta) mentionClose(); }, 120); });
650
+ ta.addEventListener('keydown', function (ev) {
651
+ if (!MENT || MENT.ta !== ta) return; var M = MENT, n = M.items.length, eat = true;
652
+ if (ev.key === 'Escape') mentionClose();
653
+ else if (ev.key === 'ArrowDown' && n) { M.idx = (M.idx + 1) % n; mentionDraw(ta); }
654
+ else if (ev.key === 'ArrowUp' && n) { M.idx = (M.idx + n - 1) % n; mentionDraw(ta); }
655
+ else if (ev.key === 'Enter' && !ev.shiftKey && n) mentionPick(ta, M.items[M.idx], false);
656
+ else if (ev.key === 'Tab' && n) mentionPick(ta, M.items[M.idx], M.items[M.idx].dir);
657
+ else if (ev.key === 'Enter' && !ev.shiftKey) mentionClose();
658
+ else eat = false;
659
+ if (eat) { ev.preventDefault(); ev.stopImmediatePropagation(); }
660
+ }, true);
661
+ }
662
+ mentionable($('msg'));
663
+ /* Enhance for the first request: one turn of the Director's CLI proposes a clearer brief; nothing is replaced or started until the owner says so */
664
+ var REQ = {busy: false, applied: null, before: ''};
665
+ function syncEnh() {
666
+ var b = $('enh'), live = !!(S.run && S.run.running && !S.outcome), undo = REQ.applied !== null && $('msg').value === REQ.applied, empty = !$('msg').value.trim();
667
+ b.hidden = live; b.classList.toggle('busy', REQ.busy);
668
+ b.textContent = REQ.busy ? '✦ Enhancing…' : undo ? '↶ Undo enhance' : '✦ Enhance';
669
+ b.disabled = REQ.busy || (!undo && (empty || !!ENH_BUSY));
670
+ b.title = REQ.busy ? 'The Director\'s CLI is rewriting your request (up to 2 minutes)…' : undo ? 'Put back the text you typed' : empty ? 'Type your request first' : 'Rewrite your request so the Director cannot misread it. You decide whether to use the result.';
671
+ }
672
+ function enhanceDialog(orig, r) {
673
+ var ok = r.status === 200 && r.body.ok, ta = h('textarea', {class: 'enhta', rows: 12, spellcheck: false}); if (ok) ta.value = r.body.proposal;
674
+ var use = function () { var v = ta.value.trim(); if (!v) return; REQ.before = orig; REQ.applied = v; $('msg').value = v; closeModal(); syncEnh(); $('msg').focus(); };
675
+ var body = ok ? [h('div', {class: 'enhcols'}, [h('div', {}, [h('div', {class: 'ml', text: 'YOUR TEXT'}), h('div', {class: 'enhorig', text: orig})]), h('div', {}, [h('div', {class: 'ml', text: 'PROPOSAL · you can edit it here'}), ta])]),
676
+ h('p', {class: 'enhnote', text: 'Check the “Open points”: answer them in the text if you can. Nothing starts until you press Start.'})]
677
+ : [h('pre', {class: 'chkerr', text: r.body.reason || r.body.error || 'enhance failed'}), h('div', {class: 'fix'}, [h('b', {text: 'How to fix '}), 'Enhance uses the Director\'s CLI. Open Config, select the Director agent, press "Check this CLI + model" and fix what it reports. Your text was not changed.'])];
678
+ openModal(h('div', {class: 'dlg' + (ok ? ' enhdlg' : '')}, [h('header', {}, [h('b', {text: ok ? '✦ ENHANCED REQUEST' : 'ENHANCE FAILED'}), h('button', {text: '✕', onclick: closeModal})]), h('div', {class: 'body'}, body),
679
+ h('footer', {}, ok ? [h('button', {text: 'Keep my text', onclick: closeModal}), h('button', {text: 'Try again', onclick: function () { closeModal(); runEnhance(); }}), h('button', {class: 'primary', text: 'Use this', onclick: use})] : [h('button', {text: 'Close', onclick: closeModal})])]));
680
+ if (ok) ta.focus();
681
+ }
682
+ function runEnhance() {
683
+ var orig = $('msg').value; if (REQ.busy || !orig.trim()) return;
684
+ if (orig.length > 8000) { toast('This request is longer than 8,000 characters; shorten it before using Enhance.'); return; }
685
+ REQ.busy = true; syncEnh();
686
+ api('POST', '/api/enhance-prompt', {kind: 'request', text: orig, ids: {files: PEND.map(function (p) { return p.name || (p.file && p.file.name) || ''; }).filter(Boolean)}}).then(function (r) { REQ.busy = false; syncEnh(); enhanceDialog(orig, r); }, function () { REQ.busy = false; syncEnh(); toast('Enhance could not reach CKit; is ckit still running?'); });
687
+ }
688
+ $('enh').onclick = function () { if (REQ.applied !== null && $('msg').value === REQ.applied) { $('msg').value = REQ.before; REQ.applied = null; syncEnh(); $('msg').focus(); return; } runEnhance(); };
689
+ $('msg').addEventListener('input', syncEnh);
611
690
  /* resizable panes: sizes are CSS variables on #live, remembered per browser; double-click a handle to go back to the default */
612
691
  (function () {
613
692
  var live = $('live'), saved = {};
@@ -932,7 +1011,7 @@
932
1011
  return;
933
1012
  }
934
1013
  if (r.status !== 200) { document.body.innerHTML = '<p style="padding:40px;color:#F05668;font-family:monospace">Missing or invalid session token. Open the URL printed by `ckit gui`.</p>'; return; }
935
- S.config = r.body.config; S.configExists = r.body.configExists !== false; S.projectRoot = r.body.projectRoot || ''; (function (root) { var name = root.split(/[\\/]/).filter(Boolean).pop() || root, ws = $('cwd').parentNode; $('cwdn').textContent = name; $('cwd').textContent = '\u200e' + root; document.title = name + ' · CKit'; ws.title = 'Agents read and write files in this folder (click to copy):\n' + root; ws.onclick = function () { if (navigator.clipboard) navigator.clipboard.writeText(root).then(function () { $('cwdn').textContent = 'copied ✓'; setTimeout(function () { $('cwdn').textContent = name; }, 1200); }, function () {}); }; })(S.projectRoot); S.simulatedDefault = r.body.simulatedDefault; S.run = r.body.run ? {runId: r.body.run.runId, running: r.body.run.running, goal: r.body.run.goal} : null;
1014
+ S.config = r.body.config; S.configExists = r.body.configExists !== false; S.projectRoot = r.body.projectRoot || ''; (function (root) { var name = root.split(/[\\/]/).filter(Boolean).pop() || root, ws = $('cwd').parentNode; $('cwdn').textContent = name; $('cwd').textContent = '\u200e' + root; document.title = name + ' · CKit'; ws.title = 'Open workspace files\n' + root; ws.style.cursor = 'pointer'; ws.setAttribute('role', 'button'); ws.tabIndex = 0; ws.onclick = function () { if (window.__ckExplorer) window.__ckExplorer.open(''); }; ws.onkeydown = function (e) { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); ws.onclick(); } }; })(S.projectRoot); S.simulatedDefault = r.body.simulatedDefault; S.run = r.body.run ? {runId: r.body.run.runId, running: r.body.run.running, goal: r.body.run.goal} : null;
936
1015
  S.replay = !!(r.body.run && r.body.run.goal === '(replay)');
937
1016
  setupAgents(S.config);
938
1017
  // First run (no .ckit/team.json, nothing running): land on Config so setup starts in the GUI.