@aiwg/cockpit 2026.10.1 → 2026.10.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.
@@ -152,7 +152,8 @@
152
152
 
153
153
  const meta = document.getElementById('meta');
154
154
  const fmt = (id) => (id && id.length > 12) ? id.slice(0, 8) + '…' : id;
155
- const esc = (s) => String(s).replace(/[&<>]/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;' }[c]));
155
+ // Shared by text and quoted attribute contexts; escape both quote types.
156
+ const esc = (s) => String(s).replace(/[&<>"']/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c]));
156
157
  // Exchange a one-time URL-fragment nonce for an HttpOnly session. The
157
158
  // fragment is removed before any control-surface request is made.
158
159
  let CSRF = '';
@@ -220,10 +221,10 @@
220
221
  let costLine = '';
221
222
  try {
222
223
  const c = await (await api('/api/cost')).json();
223
- costLine = `<p class="hint">Spend across stacks: <strong>$${c.total.usd.toFixed(2)}</strong> · ${(c.total.input_tokens + c.total.output_tokens).toLocaleString()} tokens</p>`;
224
+ costLine = `<p class="hint">Spend across stacks: <strong>$${esc(c.total.usd.toFixed(2))}</strong> · ${esc((c.total.input_tokens + c.total.output_tokens).toLocaleString())} tokens</p>`;
224
225
  } catch { /* cost optional */ }
225
226
  if (!r.running.length) { view.innerHTML = costLine + '<p class="empty">Nothing running.</p>'; return; }
226
- view.innerHTML = costLine + `<table><caption>Running across all stacks — ${r.count} task(s)</caption>
227
+ view.innerHTML = costLine + `<table><caption>Running across all stacks — ${esc(r.count)} task(s)</caption>
227
228
  <thead><tr><th scope="col">Instance</th><th scope="col">Task</th><th scope="col">State</th><th scope="col">Tenant</th><th scope="col">Control</th></tr></thead>
228
229
  <tbody>${r.running.map((t) => `<tr>
229
230
  <td><code title="${esc(t.instance_id)}">${esc(fmt(t.instance_id))}</code></td>
@@ -252,8 +253,15 @@
252
253
  const decode = (b64) => { try { return atob(b64); } catch { return b64; } };
253
254
  function write(text) { terminal.textContent += text; terminal.scrollTop = terminal.scrollHeight; }
254
255
  function setRole(r) {
256
+ r = ['controller', 'observer'].includes(r) ? r : null;
255
257
  role = r;
256
- roleBadge.innerHTML = r ? `<span class="badge ${r}">${r}</span>` : '';
258
+ roleBadge.replaceChildren();
259
+ if (r) {
260
+ const badge = document.createElement('span');
261
+ badge.setAttribute('class', r === 'controller' ? 'badge controller' : 'badge observer');
262
+ badge.textContent = r;
263
+ roleBadge.append(badge);
264
+ }
257
265
  const driving = r === 'controller';
258
266
  cmd.disabled = !driving; btn.send.disabled = !driving;
259
267
  cmd.placeholder = driving ? 'Type to drive the session…' : 'Observing — input is read-only';
@@ -275,13 +283,33 @@
275
283
  try {
276
284
  const r = await (await api('/api/sessions?instance=' + encodeURIComponent(inst))).json();
277
285
  if (!r.sessions.length) { selSession.innerHTML = '<option value="">— no sessions —</option>'; return; }
278
- selSession.innerHTML = r.sessions.map((s) => `<option value="${esc(s.attach_url)}">${esc(s.id)} · seq ${s.seq} · ${s.members} viewer(s)</option>`).join('');
279
- } catch (e) { selSession.innerHTML = `<option value="">${esc(e.message)}</option>`; }
286
+ selSession.replaceChildren(...r.sessions.map((s) => {
287
+ const option = document.createElement('option');
288
+ option.value = validatedAttachUrl(s.attach_url);
289
+ option.textContent = `${s.id} · seq ${s.seq} · ${s.members} viewer(s)`;
290
+ return option;
291
+ }));
292
+ } catch (e) {
293
+ const option = document.createElement('option');
294
+ option.value = ''; option.textContent = e.message;
295
+ selSession.replaceChildren(option);
296
+ }
280
297
  }
281
298
  selInstance.addEventListener('change', loadSessions);
282
299
 
300
+ function validatedAttachUrl(value) {
301
+ const url = new URL(value);
302
+ const protocol = location.protocol === 'https:' ? 'wss:' : 'ws:';
303
+ if (url.protocol !== protocol || url.host !== location.host || url.username || url.password || url.search || url.hash ||
304
+ !/^\/api\/pty\/agents\/[^/]+\/sessions\/[^/]+\/attach\/[^/]+$/.test(url.pathname)) {
305
+ throw new Error('Invalid session attach URL.');
306
+ }
307
+ return url.href;
308
+ }
309
+
283
310
  function attach(replay) {
284
- attachUrl = selSession.value;
311
+ try { attachUrl = selSession.value ? validatedAttachUrl(selSession.value) : ''; }
312
+ catch (e) { write(`\n[${e.message}]\n`); return; }
285
313
  if (!attachUrl) return;
286
314
  const url = replay ? attachUrl + '?replay_from=' + lastSeq : attachUrl;
287
315
  if (replay) terminal.textContent = '';
@@ -334,7 +362,7 @@
334
362
  if (!rs.length) { exResults.innerHTML = '<p class="empty">No matches.</p>'; return; }
335
363
  exResults.innerHTML = `<table><caption>${rs.length} capabilit${rs.length === 1 ? 'y' : 'ies'}</caption><tbody>${rs.map((r, i) => `
336
364
  <tr><td>
337
- <button type="button" class="ex-pick" data-i="${i}" style="width:100%;text-align:left">
365
+ <button type="button" class="ex-pick" data-i="${esc(i)}" style="width:100%;text-align:left">
338
366
  <span class="badge">${esc(r.type)}</span> <strong>${esc(r.name)}</strong>
339
367
  <span style="color:var(--muted);font-size:12px"> · ${(r.score ?? 0).toFixed(2)}</span><br>
340
368
  <span style="color:var(--muted);font-size:13px">${esc((r.capability || r.title || '').slice(0, 90))}</span>
@@ -364,7 +392,7 @@
364
392
  <thead><tr><th scope="col">Request</th><th scope="col">Risk</th><th scope="col">Instance</th><th scope="col">Decision</th></tr></thead>
365
393
  <tbody>${a.approvals.map((p) => `<tr>
366
394
  <td>${esc(p.prompt)}</td>
367
- <td><span class="badge ${p.risk === 'high' ? 'observer' : ''}">${esc(p.risk)}</span></td>
395
+ <td><span class="badge ${esc(p.risk === 'high' ? 'observer' : '')}">${esc(p.risk)}</span></td>
368
396
  <td><code title="${esc(p.instance_id)}">${esc(fmt(p.instance_id))}</code></td>
369
397
  <td style="white-space:nowrap">
370
398
  <button class="apr" data-id="${esc(p.id)}" data-d="approve">Approve</button>