truemap-cli 0.5.0 → 0.5.2

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/src/ui/sdk.js CHANGED
@@ -50,7 +50,7 @@
50
50
 
51
51
  const drawWires = () => { window.truemapDiagram?.draw(); window.truemapWires?.draw(); markWires(); };
52
52
  let wireTimer = null;
53
- const scheduleWires = () => { clearTimeout(wireTimer); wireTimer = setTimeout(() => { drawWires(); placePins(); }, 40); };
53
+ const scheduleWires = () => { clearTimeout(wireTimer); wireTimer = setTimeout(() => { drawWires(); placePins(); placePlanAct(); }, 40); };
54
54
 
55
55
  // ---------- focus: the agent (or a chat link) points at boxes ----------
56
56
  let focusSet = []; let focusNote = null; let hotBox = null;
@@ -155,6 +155,19 @@
155
155
  for (const w of document.querySelectorAll('.tm-dg-edge, .tm-dg-head, .tm-dg-label')) w.classList.toggle('is-sel', !!el?.id && (w.dataset.from === el.id || w.dataset.to === el.id));
156
156
  if (!el && document.activeElement?.matches?.('.tm-node, .tm-step')) document.activeElement.blur();
157
157
  }
158
+ // Click a box: a small card beside it with what it is and a comment field, so your eyes stay on the map.
159
+ // If the inspector is already open on the right, it follows the box.
160
+ function openBox(box) {
161
+ // a second click on the selected box lets go of it
162
+ if (selected === box) { select(null); post({ type: 'deselect' }); return; }
163
+ select(box);
164
+ post({ type: 'peek-if-open', page: pagePath(), box: boxInfo(box) });
165
+ }
166
+ function cardFor(box) {
167
+ select(box);
168
+ const existing = [...notes.values()].find((n) => n.el === box);
169
+ openCard({ target: box, noteId: existing?.id || null });
170
+ }
158
171
  function peek(el) {
159
172
  select(el);
160
173
  const r = el.getBoundingClientRect();
@@ -261,7 +274,7 @@
261
274
  b.style.top = `${fitsRight ? g.t : above ? g.t - bh - 12 : g.b + 12}px`;
262
275
  } else { b.style.left = `${scrollX + vw - 320}px`; b.style.top = `${scrollY + 16}px`; }
263
276
  }
264
- if (card?.target) ring(card.target, 'active');
277
+ if (card?.target && !card.target.closest('.tm-diagram')) ring(card.target, 'active'); // a map box shows its own selection
265
278
  else if (annotating && hovered) ring(hovered, 'hover');
266
279
  }
267
280
  function setAnnotate(on) {
@@ -279,50 +292,98 @@
279
292
  shadow.innerHTML = `<style>
280
293
  :host { all: initial; }
281
294
  * { box-sizing: border-box; }
282
- .card { position: absolute; width: 340px; background: #fff; color: #141413; border: 1px solid #d2d2cb; border-radius: 10px;
283
- box-shadow: 0 12px 32px -12px rgba(20,20,19,.28); font: 14px/1.45 "Instrument Sans", system-ui, -apple-system, "Segoe UI", sans-serif; padding: 12px; }
284
- .what { display: flex; align-items: baseline; gap: 8px; min-width: 0; margin: 0 2px 8px; }
295
+ .card { position: absolute; z-index: 10; width: 360px; background: var(--tm-sheet, #fff); color: var(--tm-ink, #141413); border: 1px solid var(--tm-rule-strong, #d2d2cb); border-radius: 10px;
296
+ box-shadow: 0 12px 32px -12px rgba(20,20,19,.28); font: 14px/1.45 var(--tm-font, system-ui, sans-serif); padding: 12px; }
297
+ .what { display: flex; align-items: baseline; gap: 8px; min-width: 0; margin: 0 2px 6px; }
298
+ .card.viewing { width: 320px; }
299
+ .card.viewing textarea, .card.viewing .suggest, .card.viewing [data-act="add"], .card.viewing [data-act="cancel"], .card.viewing .hint { display: none; }
300
+ .card:not(.viewing) [data-act="comment"] { display: none; }
301
+ .card.viewing .foot { justify-content: flex-start; margin-top: 4px; }
302
+ .card.viewing .sum { margin-bottom: 6px; }
303
+ .sum { margin: 0 2px 10px; font-size: 13px; line-height: 1.45; color: var(--tm-graphite, #6c6c65); }
304
+ .sum .flag { margin-top: 4px; font-size: 12px; color: var(--tm-changed, #a35f00); }
285
305
  .what b { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
286
- .what code { font: 11.5px "Commit Mono", ui-monospace, Consolas, monospace; color: #9a9a92; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; flex: 1; }
287
- textarea { width: 100%; min-height: 72px; max-height: 220px; resize: none; font: inherit; color: inherit; background: #fafaf9; border: 1px solid #e6e6e1; border-radius: 7px; padding: 9px 10px; outline: none; }
288
- textarea:focus { border-color: #141413; background: #fff; }
306
+ .what code { font: 11.5px var(--tm-code, ui-monospace, Consolas, monospace); color: var(--tm-pencil, #9a9a92); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; flex: 1; }
307
+ textarea { width: 100%; min-height: 72px; max-height: 220px; resize: none; font: inherit; color: inherit; background: color-mix(in oklab, var(--tm-wash, #f2f2ef) 45%, var(--tm-sheet, #fff)); border: 1px solid var(--tm-rule, #e6e6e1); border-radius: 7px; padding: 9px 10px; outline: none; }
308
+ textarea:focus { border-color: var(--tm-ink, #141413); background: var(--tm-sheet, #fff); }
289
309
  .suggest { display: flex; flex-wrap: wrap; gap: 4px 14px; margin: 8px 2px 0; }
290
- .suggest button { all: unset; cursor: pointer; font-size: 12.5px; color: #141413; }
310
+ .suggest button { all: unset; cursor: pointer; font-size: 12.5px; color: var(--tm-ink, #141413); }
291
311
  .suggest button:hover { text-decoration: underline; text-underline-offset: 3px; }
292
312
  .foot { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
293
- .hint { flex: 1; font-size: 11.5px; color: #9a9a92; line-height: 1.3; }
294
- .btn { all: unset; cursor: pointer; font: 500 13px/1 "Instrument Sans", system-ui, sans-serif; padding: 8px 11px; border-radius: 6px; color: #6c6c65; }
295
- .btn:hover { background: #f2f2ef; color: #141413; }
296
- .btn.primary { background: #141413; color: #fff; }
297
- .btn.primary:hover { background: #3a3a36; }
298
- .btn.danger { color: #c0392b; }
299
- .btn:focus-visible { outline: 2px solid #141413; outline-offset: 2px; }
300
- .ring { position: absolute; border: 1.5px solid #141413; border-radius: 8px; pointer-events: none; }
313
+ .foot .btn { white-space: nowrap; }
314
+ .foot [data-act="details"] { padding-left: 2px; text-decoration: underline; text-underline-offset: 3px; }
315
+ .hint { flex: 1; font-size: 11.5px; color: var(--tm-pencil, #9a9a92); line-height: 1.3; }
316
+ .btn { all: unset; cursor: pointer; font: 500 13px/1 var(--tm-font, system-ui, sans-serif); padding: 8px 11px; border-radius: 6px; color: var(--tm-graphite, #6c6c65); }
317
+ .btn:hover { background: var(--tm-wash, #f2f2ef); color: var(--tm-ink, #141413); }
318
+ .btn.primary { background: var(--tm-accent, #141413); color: var(--tm-accent-text, #fff); }
319
+ .btn.primary:hover { background: color-mix(in oklab, var(--tm-accent, #141413) 84%, var(--tm-sheet, #fff)); }
320
+ .btn.danger { color: var(--tm-broken, #c0392b); }
321
+ .btn:focus-visible { outline: 2px solid var(--tm-ink, #141413); outline-offset: 2px; }
322
+ .ring { position: absolute; border: 1.5px solid var(--tm-ink, #141413); border-radius: 8px; pointer-events: none; }
301
323
  .ring.active { border-width: 2px; }
302
- .ring.agent { border: 2px solid #141413; border-radius: 9px; }
303
- .bubble { position: absolute; width: 300px; background: #141413; color: #fafaf9; border-radius: 10px; padding: 10px 30px 11px 12px; box-shadow: 0 14px 34px -14px rgba(20,20,19,.5); font: 13.5px/1.5 "Instrument Sans", system-ui, -apple-system, "Segoe UI", sans-serif; pointer-events: auto; }
304
- .bubble-who { font-size: 11.5px; font-weight: 600; color: #ffe27a; margin-bottom: 3px; }
324
+ .ring.agent { border: 2px solid var(--tm-ink, #141413); border-radius: 9px; }
325
+ .bubble { position: absolute; width: 300px; background: var(--tm-ink, #141413); color: var(--tm-paper, #fff); border-radius: 10px; padding: 10px 30px 11px 12px; box-shadow: 0 14px 34px -14px rgba(20,20,19,.5); font: 13.5px/1.5 var(--tm-font, system-ui, sans-serif); pointer-events: auto; }
326
+ .bubble-who { font-size: 11.5px; font-weight: 600; color: color-mix(in oklab, var(--tm-paper, #fff) 70%, var(--tm-mark, #ffe27a)); margin-bottom: 3px; }
305
327
  .bubble-text { white-space: pre-wrap; }
306
- .bubble-x { all: unset; position: absolute; top: 6px; right: 8px; cursor: pointer; color: #a0a098; font-size: 16px; line-height: 1; padding: 2px 4px; border-radius: 4px; }
307
- .bubble-x:hover { color: #fff; background: rgba(255,255,255,.1); }
308
- .ring.noted { border-color: rgba(20, 20, 19, .35); }
309
- @media (prefers-color-scheme: dark) { .ring { border-color: #f2f2ee; } .ring.noted { border-color: rgba(242, 242, 238, .45); } }
310
- .pin { position: absolute; width: 20px; height: 20px; border-radius: 50%; background: #ffe27a; color: #141413;
311
- font: 600 11px/20px "Commit Mono", ui-monospace, Consolas, monospace; text-align: center; cursor: pointer; border: 2px solid #fff; box-shadow: 0 1px 3px rgba(20,20,19,.25); }
312
- .select-btn { position: absolute; all: unset; position: absolute; cursor: pointer; background: #141413; color: #fff; font: 500 12.5px/1 "Instrument Sans", system-ui, sans-serif; padding: 7px 10px; border-radius: 6px; box-shadow: 0 6px 18px -8px rgba(20,20,19,.5); }
313
- .select-btn:hover { background: #141413; }
314
- @media (prefers-color-scheme: dark) {
315
- .card { background: #1b1b1a; color: #f2f2ee; border-color: #44443f; box-shadow: 0 12px 32px -12px rgba(0,0,0,.6); }
316
- textarea { background: #161615; border-color: #2f2f2c; }
317
- textarea:focus { background: #161615; border-color: #f2f2ee; }
318
- .suggest button { color: #f2f2ee; }
319
- .btn { color: #a0a098; } .btn:hover { background: #252523; color: #f2f2ee; }
320
- .btn.primary { background: #f2f2ee; color: #141413; }
321
- .pin { border-color: #161615; }
322
- }
323
- </style><div id="rings"></div><div id="pins"></div><div id="slot"></div>`;
328
+ .bubble-x { all: unset; position: absolute; top: 6px; right: 8px; cursor: pointer; color: color-mix(in oklab, var(--tm-paper, #fff) 60%, var(--tm-ink, #141413)); font-size: 16px; line-height: 1; padding: 2px 4px; border-radius: 4px; }
329
+ .bubble-x:hover { color: var(--tm-paper, #fff); background: color-mix(in oklab, var(--tm-paper, #fff) 12%, transparent); }
330
+ .ring.noted { border-color: color-mix(in oklab, var(--tm-ink, #141413) 40%, transparent); }
331
+ .pin { position: absolute; width: 20px; height: 20px; border-radius: 50%; background: var(--tm-mark, #ffe27a); color: var(--tm-ink, #141413);
332
+ font: 600 11px/20px var(--tm-code, ui-monospace, Consolas, monospace); text-align: center; cursor: pointer; border: 2px solid var(--tm-sheet, #fff); box-shadow: 0 1px 3px rgba(20,20,19,.25); }
333
+ .select-btn { position: absolute; all: unset; position: absolute; cursor: pointer; background: var(--tm-accent, #141413); color: var(--tm-accent-text, #fff); font: 500 12.5px/1 var(--tm-font, system-ui, sans-serif); padding: 7px 10px; border-radius: 6px; box-shadow: 0 6px 18px -8px rgba(20,20,19,.5); }
334
+ .select-btn:hover { background: var(--tm-accent, #141413); }
335
+ .planact { position: absolute; display: flex; gap: 4px; padding: 4px; background: var(--tm-sheet, #fff); border: 1px solid var(--tm-rule-strong, #d2d2cb); border-radius: 999px; box-shadow: 0 8px 22px -10px rgba(20,20,19,.4); pointer-events: auto; z-index: 3; animation: pa-in .22s cubic-bezier(.2,.8,.3,1.2) both; }
336
+ @keyframes pa-in { from { opacity: 0; transform: translateY(4px) scale(.92); } to { opacity: 1; transform: none; } }
337
+ .planact button { all: unset; display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; cursor: pointer; color: var(--tm-ink, #141413); transition: transform .12s ease, background-color .12s ease; }
338
+ .planact button:hover { background: var(--tm-wash, #f2f2ef); transform: scale(1.1); }
339
+ .planact button.ok { background: var(--tm-accent, #141413); color: var(--tm-accent-text, #fff); }
340
+ .planact button.ok:hover { background: color-mix(in oklab, var(--tm-accent, #141413) 84%, var(--tm-sheet, #fff)); }
341
+ .planact button:focus-visible { outline: 2px solid var(--tm-ink, #141413); outline-offset: 2px; }
342
+ .planact svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
343
+ .planact .wait { display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; color: var(--tm-fine, #2f7a4f); }
344
+ .planact .wait.revise { color: var(--tm-graphite, #6c6c65); animation: pa-pulse 1.4s ease-in-out infinite; }
345
+ @keyframes pa-pulse { 50% { opacity: .35; } }
346
+ @media (prefers-reduced-motion: reduce) { .planact, .planact .wait.revise { animation: none; } .planact button { transition: none; } }
347
+ </style><div id="rings"></div><div id="pins"></div><div id="slot"></div><div id="planact"></div>`;
348
+ const applyTheme = (t) => {
349
+ if (t === 'light' || t === 'dark') document.documentElement.setAttribute('data-theme', t); else document.documentElement.removeAttribute('data-theme');
350
+ };
351
+ applyTheme(document.documentElement.getAttribute('data-theme'));
324
352
  const pinsEl = shadow.getElementById('pins');
325
353
  const slot = shadow.getElementById('slot');
354
+ const planActEl = shadow.getElementById('planact');
355
+ let planNow = null;
356
+ const ICON = {
357
+ ok: '<svg viewBox="0 0 16 16"><path d="M3 8.5 6.5 12 13 4.5"/></svg>',
358
+ no: '<svg viewBox="0 0 16 16"><path d="M4 4l8 8M12 4l-8 8"/></svg>',
359
+ ask: '<svg viewBox="0 0 16 16"><path d="M3 3.5h10v7H7.5L4.5 13v-2.5H3z"/></svg>',
360
+ };
361
+ // The plan's actions sit next to the boxes it adds or changes, where your eyes already are.
362
+ function placePlanAct() {
363
+ planActEl.innerHTML = '';
364
+ const p = planNow;
365
+ if (!p || !['review', 'revise', 'approved'].includes(p.status)) return;
366
+ const els = [...document.querySelectorAll('[data-plan]')].filter((el) => el.isConnected && el.getBoundingClientRect().width);
367
+ if (!els.length) return;
368
+ mount();
369
+ const rs = els.map((el) => el.getBoundingClientRect());
370
+ const u = { l: Math.min(...rs.map((r) => r.left)) + scrollX, t: Math.min(...rs.map((r) => r.top)) + scrollY, r: Math.max(...rs.map((r) => r.right)) + scrollX, b: Math.max(...rs.map((r) => r.bottom)) + scrollY };
371
+ const box = document.createElement('div'); box.className = 'planact'; box.setAttribute('role', 'group'); box.setAttribute('aria-label', 'Plan');
372
+ if (p.status === 'review') box.innerHTML = `<button class="ok" data-pa="approve" title="Approve the plan" aria-label="Approve the plan">${ICON.ok}</button><button data-pa="reject" title="Reject the plan" aria-label="Reject the plan">${ICON.no}</button><button data-pa="ask" title="Ask or comment on the plan" aria-label="Ask or comment on the plan">${ICON.ask}</button>`;
373
+ else box.innerHTML = p.status === 'revise' ? `<span class="wait revise" title="Waiting for the revised plan">${ICON.ask}</span>` : `<span class="wait" title="Approved">${ICON.ok}</span>`;
374
+ box.title = p.title;
375
+ planActEl.appendChild(box);
376
+ const vw = document.documentElement.clientWidth; const w = box.offsetWidth; const h = box.offsetHeight;
377
+ let left = u.r + 10; let top = u.t - h / 2;
378
+ if (left + w > scrollX + vw - 8) { left = Math.max(scrollX + 8, u.r - w); top = u.t - h - 14; }
379
+ if (top < scrollY + 4) top = u.b + 10;
380
+ box.style.left = `${left}px`; box.style.top = `${top}px`;
381
+ box.onclick = (e) => {
382
+ const act = e.target.closest('[data-pa]')?.dataset.pa; if (!act) return;
383
+ if (act === 'ask') { const r = box.getBoundingClientRect(); openCard({ text: p.title, rect: docRect(r), planComment: true }); return; }
384
+ post({ type: 'plan-act', act });
385
+ };
386
+ }
326
387
  rings = shadow.getElementById('rings');
327
388
  const mount = () => { if (!host.isConnected) document.body.appendChild(host); };
328
389
 
@@ -342,24 +403,40 @@
342
403
  }
343
404
  function docRect(r) { return { left: r.left + scrollX, top: r.top + scrollY, right: r.right + scrollX, bottom: r.bottom + scrollY, width: r.width, height: r.height }; }
344
405
 
345
- function openCard({ target = null, text = null, rect, noteId = null }) {
406
+ function openCard({ target = null, text = null, rect, noteId = null, planComment = false, view = false }) {
346
407
  closeCard(); hideSelectBtn(); mount(); setHover(null);
347
408
  const existing = noteId ? notes.get(noteId) : null;
348
409
  const sel = getSelection();
349
410
  const range = existing ? existing.range || null : (text && sel?.rangeCount ? sel.getRangeAt(0).cloneRange() : null);
350
- const label = existing?.label || (target ? labelOf(target) : clean(text, 60));
411
+ const label = existing?.label || (target ? clean(target.getAttribute('data-name'), 60) || labelOf(target) : clean(text, 60));
351
412
  const src = existing?.src ?? (target ? target.closest('[data-src]')?.getAttribute('data-src') || '' : (text && rangeSrc()) || '');
352
413
  const el = document.createElement('div');
353
- el.className = 'card'; el.setAttribute('role', 'dialog'); el.setAttribute('aria-label', 'Comment');
354
- el.innerHTML = `<div class="what"><b></b><code></code></div><textarea rows="3"></textarea>
414
+ el.className = view ? 'card viewing' : 'card'; el.setAttribute('role', 'dialog'); el.setAttribute('aria-label', view ? 'About this box' : 'Comment');
415
+ el.innerHTML = `<div class="what"><b></b><code></code></div><div class="sum"></div><textarea rows="3"></textarea>
355
416
  <div class="suggest"></div>
356
- <div class="foot"><span class="hint"></span>${existing ? `<button class="btn danger" data-act="remove" type="button">${T.remove}</button>` : `<button class="btn" data-act="cancel" type="button">${T.cancel}</button>`}<button class="btn primary" data-act="add" type="button">${existing ? T.save : T.add}</button></div>`;
417
+ <div class="foot">${view ? '<button class="btn primary" data-act="comment" type="button" title="Or double-click the box">Comment</button>' : ''}${target ? '<button class="btn" data-act="details" type="button">Details</button>' : ''}<span class="hint"></span>${existing ? `<button class="btn danger" data-act="remove" type="button">${T.remove}</button>` : `<button class="btn" data-act="cancel" type="button">${T.cancel}</button>`}<button class="btn primary" data-act="add" type="button">${planComment ? 'Send' : existing ? T.save : T.add}</button></div>`;
357
418
  el.querySelector('b').textContent = text ? `“${label}”` : label;
358
- el.querySelector('code').textContent = src;
359
- el.querySelector('.hint').textContent = T.hint;
419
+ el.querySelector('code').textContent = target?.getAttribute('data-tag') || src;
420
+ // what it is, in a line or two; what a plan or a change says about it
421
+ if (target) {
422
+ const det = target.querySelector(':scope > .tm-detail');
423
+ const first = clean(det?.querySelector('p')?.textContent || target.querySelector('.tm-node-desc')?.textContent || '', 220);
424
+ const extra = [
425
+ target.getAttribute('data-plan-note') && `Plan: ${clean(target.getAttribute('data-plan-note'), 160)}`,
426
+ target.getAttribute('data-plan') === 'new' && 'New in this plan',
427
+ target.getAttribute('data-tm-delta') && `Changed: ${target.getAttribute('data-tm-delta')} lines`,
428
+ target.getAttribute('data-tm-mark') && (target.getAttribute('data-tm-mark') === 'broken' ? 'No longer matches the code' : 'The code changed since this box was checked'),
429
+ ].filter(Boolean);
430
+ const sumEl = el.querySelector('.sum');
431
+ sumEl.textContent = first;
432
+ for (const x of extra) { const d = document.createElement('div'); d.className = 'flag'; d.textContent = x; sumEl.appendChild(d); }
433
+ if (!first && !extra.length) sumEl.remove();
434
+ } else el.querySelector('.sum').remove();
435
+ el.querySelector('.hint').textContent = ''; el.querySelector('[data-act="add"]').title = T.hint;
360
436
  const ta = el.querySelector('textarea'); ta.placeholder = T.placeholder; ta.value = existing?.text || '';
361
437
  const sug = el.querySelector('.suggest');
362
- if (!existing) for (const [lbl, prompt] of T.suggest) {
438
+ if (planComment) { el.querySelector('b').textContent = `Plan: ${label}`; ta.placeholder = 'Ask a question or say what should change'; }
439
+ if (!existing && !planComment) for (const [lbl, prompt] of T.suggest) {
363
440
  const b = document.createElement('button'); b.type = 'button'; b.textContent = lbl;
364
441
  b.onclick = () => { ta.value = prompt; ta.focus(); };
365
442
  sug.appendChild(b);
@@ -367,7 +444,7 @@
367
444
  slot.appendChild(el);
368
445
  // position: below the target, kept inside the viewport
369
446
  const r = rect || docRect(target.getBoundingClientRect());
370
- const w = 340; const vw = document.documentElement.clientWidth;
447
+ const w = 360; const vw = document.documentElement.clientWidth;
371
448
  let left = Math.min(Math.max(8 + scrollX, r.left), scrollX + vw - w - 12);
372
449
  let top = r.bottom + 10;
373
450
  const h = el.offsetHeight || 220;
@@ -392,7 +469,9 @@
392
469
  };
393
470
  el.addEventListener('click', (e) => {
394
471
  const act = e.target.closest('[data-act]')?.dataset.act;
395
- if (act === 'add') finish(false);
472
+ if (act === 'add') finish(planComment);
473
+ else if (act === 'details') { closeCard(); peek(target); }
474
+ else if (act === 'comment') { el.classList.remove('viewing'); el.setAttribute('aria-label', 'Comment'); ta.focus({ preventScroll: true }); }
396
475
  else if (act === 'cancel') closeCard();
397
476
  else if (act === 'remove') { removeNote(noteId, true); closeCard(); }
398
477
  });
@@ -400,7 +479,8 @@
400
479
  if (e.key === 'Escape') { e.preventDefault(); e.stopPropagation(); closeCard(); }
401
480
  else if (e.key === 'Enter' && !e.shiftKey && !e.isComposing && e.keyCode !== 229) { e.preventDefault(); finish(e.ctrlKey || e.metaKey); }
402
481
  });
403
- setTimeout(() => ta.focus({ preventScroll: true }), 0);
482
+ if (!view) setTimeout(() => ta.focus({ preventScroll: true }), 0);
483
+ else el.addEventListener('keydown', (e) => { if (e.key === 'Escape') { e.preventDefault(); closeCard(); } });
404
484
  }
405
485
 
406
486
  function rangeSrc() {
@@ -503,7 +583,7 @@
503
583
  }
504
584
  if (inner && inner !== box && box.contains(inner)) return;
505
585
  e.preventDefault(); e.stopPropagation();
506
- peek(box);
586
+ openBox(box);
507
587
  return;
508
588
  }
509
589
  if (String(getSelection?.() || '').trim().length > 1) return;
@@ -514,6 +594,17 @@
514
594
  openCard({ target: el, noteId: existing?.id || null });
515
595
  }, true);
516
596
 
597
+ // A double click on a box goes straight to writing a comment (a single click only looks).
598
+ document.addEventListener('dblclick', (e) => {
599
+ if (!e.isTrusted || e.composedPath().includes(host)) return;
600
+ const t = e.target instanceof Element ? e.target : null;
601
+ const box = t?.closest(boxSel);
602
+ if (!box || t.closest('a[href],button,input,select,textarea,label,summary,.tm-ask,[role=tab]')) return;
603
+ e.preventDefault();
604
+ getSelection()?.removeAllRanges();
605
+ cardFor(box);
606
+ }, true);
607
+
517
608
  document.addEventListener('mouseup', (e) => {
518
609
  if (!e.isTrusted || e.composedPath().includes(host)) return;
519
610
  setTimeout(() => {
@@ -534,7 +625,7 @@
534
625
  const typing = e.target instanceof Element && e.target.closest('input,textarea,select,[contenteditable]');
535
626
  if (e.key === 'Escape' && card) { closeCard(); return; }
536
627
  if (e.key === 'Escape' && (focusSet.length || focusNote)) { clearFocus(); post({ type: 'focus-cleared' }); return; }
537
- if ((e.key === 'Enter' || e.key === ' ') && !annotating && e.target instanceof Element && e.target.matches?.('.tm-node, .tm-step') && !typing) { e.preventDefault(); peek(e.target); return; }
628
+ if ((e.key === 'Enter' || e.key === ' ') && !annotating && e.target instanceof Element && e.target.matches?.('.tm-node, .tm-step') && !typing) { e.preventDefault(); cardFor(e.target); return; }
538
629
  });
539
630
 
540
631
  // ---------- decisions: <form class="tm-ask" data-tm-ask="question"> ----------
@@ -565,6 +656,7 @@
565
656
  window.addEventListener('message', (e) => {
566
657
  if (e.source !== parentWin || e.origin !== PARENT || !e.data || !e.data.__truemap) return;
567
658
  const d = e.data;
659
+ if (d.type === 'theme') { applyTheme(d.theme); return; }
568
660
  if (d.type === 'marks') {
569
661
  document.querySelectorAll('[data-tm-mark]').forEach((el) => el.removeAttribute('data-tm-mark'));
570
662
  for (const m of d.items || []) {
@@ -599,6 +691,7 @@
599
691
  } else if (d.type === 'select') {
600
692
  select(d.id ? document.getElementById(d.id) : null);
601
693
  } else if (d.type === 'plan') {
694
+ planNow = d.plan || null;
602
695
  // A plan drawn on the map: what it touches, adds (dashed, in its group) and removes.
603
696
  for (const el of document.querySelectorAll('[data-plan-overlay], [data-plan-revised]')) { el.removeAttribute('data-plan'); el.removeAttribute('data-plan-note'); el.removeAttribute('data-plan-overlay'); el.removeAttribute('data-plan-revised'); }
604
697
  clearFocus();
@@ -614,26 +707,28 @@
614
707
  };
615
708
  if (p) { for (const t of p.touch || []) markPlan(t.box, 'change', t.what); for (const r of p.remove || []) markPlan(r.box, 'remove', r.why); }
616
709
  for (const id of p?.revised || []) findItems([id])[0]?.setAttribute('data-plan-revised', '');
710
+ setTimeout(placePlanAct, 60);
617
711
  for (const b of document.querySelectorAll('.tm-node, .tm-step')) { if (!b.hasAttribute('tabindex') && !b.matches('a[href]')) b.setAttribute('tabindex', '0'); }
618
712
  markWires();
619
713
  } else if (d.type === 'changes') {
620
714
  // Review mode: changed boxes carry their +/- lines; the rest of the map goes quiet.
621
715
  document.documentElement.toggleAttribute('data-tm-changes', !!d.on);
622
- for (const el of document.querySelectorAll('[data-tm-change], [data-tm-unbuilt]')) { el.removeAttribute('data-tm-change'); el.removeAttribute('data-tm-delta'); el.removeAttribute('data-tm-unbuilt'); }
716
+ for (const el of document.querySelectorAll('[data-tm-change], [data-tm-unbuilt]')) { el.removeAttribute('data-tm-change'); el.removeAttribute('data-tm-delta'); el.removeAttribute('data-tm-unbuilt'); el.removeAttribute('data-tm-new'); }
623
717
  for (const u of d.unbuilt || []) { const el = findItems([u.src || u.box, u.box])[0]; if (el) el.setAttribute('data-tm-unbuilt', ''); }
624
718
  const names = [];
625
719
  for (const it of d.items || []) {
626
720
  for (const el of document.querySelectorAll('[data-src]')) {
627
721
  if (el.getAttribute('data-src') !== it.src) continue;
628
722
  el.setAttribute('data-tm-change', '');
629
- el.setAttribute('data-tm-delta', it.add == null ? 'binary' : [it.add ? '+' + it.add : '', it.del ? '−' + it.del : ''].filter(Boolean).join(' ') || '±0');
723
+ el.setAttribute('data-tm-delta', (it.isNew ? 'New ' : '') + (it.add == null ? 'binary' : [it.add ? '+' + it.add : '', it.del ? '−' + it.del : ''].filter(Boolean).join(' ') || '±0'));
724
+ el.toggleAttribute('data-tm-new', !!it.isNew);
630
725
  names.push({ src: it.src, name: clean(el.getAttribute('data-name'), 60) || labelOf(el) });
631
726
  }
632
727
  }
633
728
  if (names.length) post({ type: 'changes-names', items: names });
634
729
  } else if (d.type === 'open-box') {
635
730
  const el = d.id ? document.getElementById(d.id) : [...document.querySelectorAll('[data-src]')].find((x) => x.getAttribute('data-src') === d.src);
636
- if (el) { reveal([el], 'nearest'); peek(el); }
731
+ if (el) { reveal([el], 'nearest'); select(el); peek(el); }
637
732
  } else if (d.type === 'clear-focus') {
638
733
  clearFocus();
639
734
  } else if (d.type === 'highlight') {
@@ -654,6 +749,9 @@
654
749
  window.truemapDiagram?.interact();
655
750
  const ready = () => {
656
751
  drawWires();
752
+ // index.html#runs: arriving from a draft's box link lights that box on the map
753
+ const hashId = decodeURIComponent((location.hash || '').slice(1));
754
+ if (hashId && /^[\w-]+$/.test(hashId) && document.getElementById(hashId)) setTimeout(() => applyFocus([hashId], '', '', 'center'), 250);
657
755
  // Boxes are reachable from the keyboard too.
658
756
  for (const b of document.querySelectorAll('.tm-node, .tm-step')) { if (!b.hasAttribute('tabindex') && !b.matches('a[href]')) b.setAttribute('tabindex', '0'); }
659
757
  if ('ResizeObserver' in window) new ResizeObserver(scheduleWires).observe(document.body);
@@ -1,39 +1,24 @@
1
- @font-face { font-family: "Instrument Sans"; font-weight: 400; font-display: swap; src: url("/__truemap/fonts/instrument-sans-latin-400-normal.woff2") format("woff2"); }
2
- @font-face { font-family: "Instrument Sans"; font-weight: 500; font-display: swap; src: url("/__truemap/fonts/instrument-sans-latin-500-normal.woff2") format("woff2"); }
3
- @font-face { font-family: "Instrument Sans"; font-weight: 600; font-display: swap; src: url("/__truemap/fonts/instrument-sans-latin-600-normal.woff2") format("woff2"); }
4
- @font-face { font-family: "Commit Mono"; font-weight: 400; font-display: swap; src: url("/__truemap/fonts/commit-mono-latin-400-normal.woff2") format("woff2"); }
5
-
6
- /* One fixed system: neutrals and ink carry structure and selection. The accent (ink by default, the
7
- project's own colour when truemap finds one) marks the primary action. A highlighter marks what the
8
- agent points at. Status colours mean status and nothing else. */
1
+ /* Colours and fonts come from /__truemap/tokens.css (truemap's tokens, then the project's theme.css),
2
+ so the workspace and the pages always share one look. These names are the workspace's shorthand. */
9
3
  :root {
10
- --bg: #ffffff;
11
- --chrome: #fafaf9;
12
- --surface: #f2f2ef;
13
- --line: #e6e6e1;
14
- --line-strong: #d2d2cb;
15
- --ink: #141413;
16
- --text: #2b2b28;
17
- --muted: #6c6c65;
18
- --faint: #9a9a92;
19
- --accent: #141413;
20
- --accent-text: #ffffff;
21
- --mark: #ffe27a;
22
- --changed: #a35f00;
23
- --broken: #c0392b;
24
- --fine: #2f7a4f;
25
- --font: "Instrument Sans", system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
26
- --code: "Commit Mono", ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
4
+ --bg: var(--tm-paper);
5
+ --chrome: var(--tm-chrome);
6
+ --surface: var(--tm-wash);
7
+ --line: var(--tm-rule);
8
+ --line-strong: var(--tm-rule-strong);
9
+ --ink: var(--tm-ink);
10
+ --text: var(--tm-text);
11
+ --muted: var(--tm-graphite);
12
+ --faint: var(--tm-pencil);
13
+ --accent: var(--tm-accent);
14
+ --accent-text: var(--tm-accent-text);
15
+ --mark: var(--tm-mark);
16
+ --changed: var(--tm-changed);
17
+ --broken: var(--tm-broken);
18
+ --fine: var(--tm-fine);
19
+ --font: var(--tm-font);
20
+ --code: var(--tm-code);
27
21
  --panel-w: 420px;
28
- color-scheme: light dark;
29
- }
30
- @media (prefers-color-scheme: dark) {
31
- :root {
32
- --bg: #161615; --chrome: #1b1b1a; --surface: #252523; --line: #2f2f2c; --line-strong: #44443f;
33
- --ink: #f2f2ee; --text: #dadad4; --muted: #a0a098; --faint: #75756e;
34
- --accent: #f2f2ee; --accent-text: #141413; --mark: #6b5a12;
35
- --changed: #e0a548; --broken: #ef8574; --fine: #7cc49c;
36
- }
37
22
  }
38
23
 
39
24
  * { box-sizing: border-box; }
@@ -402,3 +387,42 @@ code { font-family: var(--code); font-size: 0.9em; }
402
387
  .send.quiet { background: var(--bg); color: var(--ink); border: 1px solid var(--line-strong); }
403
388
  .code-box pre span em { display: inline-block; width: 1.4em; font-style: normal; color: var(--faint); user-select: none; }
404
389
  .code-box pre span.add em { color: var(--fine); } .code-box pre span.del em { color: var(--broken); }
390
+ .ch-why { margin: -6px 4px 14px; font-size: 12px; color: var(--muted); line-height: 1.45; }
391
+ /* the map, one click away; drafts as a numbered record */
392
+ .map-btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line-strong); background: var(--bg); padding: 4px 10px 4px 8px; border-radius: 8px; cursor: pointer; font-size: 13px; font-weight: 500; color: var(--muted); }
393
+ .map-btn svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.4; }
394
+ .map-btn:hover { color: var(--ink); background: var(--surface); }
395
+ .map-btn.on { color: var(--ink); border-color: var(--ink); }
396
+ .menu-label { padding: 8px 8px 4px; font-size: 12px; color: var(--faint); }
397
+ .pi-num { flex: none; min-width: 22px; height: 20px; padding: 0 5px; border-radius: 6px; background: var(--surface); color: var(--ink); font: 600 11px/20px var(--font); text-align: center; }
398
+ /* what changed in a turn, as a card in the conversation */
399
+ .cc { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: var(--bg); }
400
+ .cc-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
401
+ .cc-head b { font-weight: 600; color: var(--ink); }
402
+ .cc-rows { display: grid; gap: 2px; margin-top: 8px; }
403
+ .cc-row { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; width: 100%; border: 0; background: none; text-align: left; padding: 5px 6px; margin: 0 -6px; border-radius: 6px; cursor: pointer; font-size: 13px; color: var(--text); }
404
+ .cc-row:hover { background: var(--surface); }
405
+ .cc-row b { font-weight: 500; color: var(--ink); }
406
+ .cc-warn { margin: 8px 0 0; font-size: 12.5px; color: var(--changed); }
407
+ .cc-loose { margin-top: 8px; font-size: 12.5px; color: var(--muted); }
408
+ .cc-loose summary { cursor: pointer; }
409
+ .cc-loose div { display: flex; justify-content: space-between; gap: 8px; margin: 3px 0; }
410
+ .cc-loose code { font-size: 12px; color: var(--text); background: none !important; padding: 0 !important; }
411
+ .cc-loose .text-btn { margin-top: 6px; }
412
+ .cc-hint { margin: 8px 0 0 !important; font-size: 12px; color: var(--faint); }
413
+ .panel-head { justify-content: flex-end; }
414
+ .nav-btns { display: inline-flex; gap: 0; margin-right: 4px; }
415
+ .icon-btn.nav { width: 26px; height: 26px; }
416
+ .icon-btn.nav svg { width: 15px; height: 15px; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
417
+ .icon-btn.nav:disabled { opacity: .35; cursor: default; background: none; }
418
+ .cc-new { margin-left: 6px; font-size: 11px; font-weight: 500; padding: 0 6px; border-radius: 6px; background: color-mix(in oklab, var(--fine) 16%, transparent); color: var(--fine); }
419
+ .more-theme { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 6px 8px; font-size: 13px; font-weight: 500; color: var(--ink); }
420
+ .seg { display: inline-flex; gap: 2px; padding: 2px; border-radius: 8px; background: var(--surface); }
421
+ .seg button { border: 0; background: none; padding: 4px 9px; border-radius: 6px; font-size: 12px; color: var(--muted); cursor: pointer; }
422
+ .seg button:hover { color: var(--ink); }
423
+ .seg button[aria-pressed="true"] { background: var(--bg); color: var(--ink); box-shadow: 0 1px 2px rgba(20, 20, 19, .14); }
424
+ .msg a.pic { display: block; width: fit-content; max-width: 100%; margin: 6px 0; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); line-height: 0; }
425
+ .msg a.pic img { display: block; max-width: 100%; max-height: 280px; object-fit: contain; background: var(--surface); }
426
+ .msg a.pic.broken { line-height: 1.4; padding: 8px 10px; font-size: 12.5px; color: var(--faint); }
427
+ .msg a.pic.broken::before { content: "Image not found"; }
428
+ .msg a.pic.broken img { display: none; }
@@ -6,6 +6,7 @@
6
6
  <meta name="referrer" content="no-referrer">
7
7
  <title>truemap</title>
8
8
  <link rel="icon" href="data:image/svg+xml,%3Csvg xmlns=%27http://www.w3.org/2000/svg%27 viewBox=%270 0 20 20%27%3E%3Cpath d=%27M10 2.2 15.6 17.6 10 14.4 4.4 17.6z%27 fill=%27%23fff%27 stroke=%27%2317202b%27 stroke-width=%271.5%27 stroke-linejoin=%27round%27/%3E%3Cpath d=%27M10 2.2V14.4L4.4 17.6z%27 fill=%27%23141413%27/%3E%3C/svg%3E">
9
+ <link rel="stylesheet" href="/__truemap/tokens.css" id="tokensCss">
9
10
  <link rel="stylesheet" href="/__truemap/workspace.css">
10
11
  <script>window.TRUEMAP_TOKEN = "__TRUEMAP_TOKEN__"; window.TRUEMAP_CONTENT = "__TRUEMAP_CONTENT__";</script>
11
12
  </head>
@@ -23,8 +24,9 @@
23
24
  <div class="menu proj-menu" id="projMenu" role="menu" hidden></div>
24
25
  </div>
25
26
  <span class="slash" aria-hidden="true">/</span>
26
- <button class="crumb-home" id="crumbHome" type="button" hidden></button>
27
- <span class="crumb-sep" id="crumbSep" aria-hidden="true" hidden>›</span>
27
+ <span class="nav-btns"><button class="icon-btn nav" id="navBack" type="button" title="Back (Alt+Left)" aria-label="Back" disabled><svg viewBox="0 0 16 16" aria-hidden="true"><path d="M10 3.5 5.5 8l4.5 4.5"/></svg></button><button class="icon-btn nav" id="navFwd" type="button" title="Forward (Alt+Right)" aria-label="Forward" disabled><svg viewBox="0 0 16 16" aria-hidden="true"><path d="M6 3.5 10.5 8 6 12.5"/></svg></button></span>
28
+ <button class="map-btn" id="crumbHome" type="button" title="The map of the whole system"><svg viewBox="0 0 16 16" aria-hidden="true"><rect x="2" y="2.5" width="12" height="3.5" rx="1"/><rect x="2" y="7.5" width="5" height="6" rx="1"/><rect x="9" y="7.5" width="5" height="6" rx="1"/></svg>Map</button>
29
+ <span class="crumb-sep" id="crumbSep" aria-hidden="true" hidden></span>
28
30
  <div class="switcher">
29
31
  <button class="page-btn" id="pageBtn" type="button" aria-haspopup="menu" aria-expanded="false" title="Pages (Ctrl+K)">
30
32
  <span class="page-name" id="pageTitle">No pages yet</span>
@@ -49,6 +51,7 @@
49
51
  <div class="menu more-menu" id="moreMenu" role="menu" hidden>
50
52
  <div class="more-file"><span class="more-label">This page</span><div class="more-path"><code id="moreFile">No page open</code><button class="text-btn" id="copyPath" type="button">Copy path</button></div></div>
51
53
  <button class="more-item" id="exportPage" type="button" role="menuitem"><svg viewBox="0 0 20 20" aria-hidden="true"><path d="M10 3.5v9M6 9l4 4 4-4M4 16.5h12"/></svg><span>Export as one HTML file<small>To share it; opens without truemap</small></span></button>
54
+ <div class="more-theme"><span>Appearance</span><span class="seg" id="themeSeg" role="group" aria-label="Appearance"><button type="button" data-theme-pick="">System</button><button type="button" data-theme-pick="light">Light</button><button type="button" data-theme-pick="dark">Dark</button></span></div>
52
55
  <div class="menu-gap"></div>
53
56
  <button class="more-item" id="endConv" type="button" role="menuitem"><svg viewBox="0 0 20 20" aria-hidden="true"><path d="M8 4.5H5a1 1 0 0 0-1 1v9a1 1 0 0 0 1 1h3M12.5 6.5 16 10l-3.5 3.5M16 10H8"/></svg><span>End conversation<small id="endHint">Lets the agent go back to the terminal</small></span></button>
54
57
  </div>
@@ -74,14 +77,14 @@
74
77
  </section>
75
78
  <div class="convo">
76
79
  <div class="panel-head">
77
- <div class="ptabs" role="tablist">
78
- <button class="ptab" id="tabConvo" type="button" role="tab" aria-selected="true">Conversation</button>
79
- <button class="ptab" id="tabChanges" type="button" role="tab" aria-selected="false">Changes<span class="ptab-n" id="changesCount" hidden></span></button>
80
+ <div class="ptabs" role="tablist" hidden>
81
+ <button class="ptab" id="tabConvo" type="button" role="tab" aria-selected="true" title="Talk with the agent working in your terminal">Conversation</button>
82
+ <button class="ptab" id="tabChanges" type="button" role="tab" aria-selected="false" title="What changed in the code, shown on the map box by box">Changes<span class="ptab-n" id="changesCount" hidden></span></button>
80
83
  </div>
81
84
  <span class="agent-state" id="agent" data-state="offline"><i aria-hidden="true"></i><span id="agentLabel">Not listening</span><span class="elapsed" id="elapsed" hidden></span></span>
82
85
  </div>
83
86
  <div class="msgs" id="msgs" aria-live="polite"></div>
84
- <div class="changes" id="changes"></div>
87
+ <div class="changes" id="changes" hidden></div>
85
88
  <div class="notice" id="notice" hidden></div>
86
89
  <form class="composer" id="composer" autocomplete="off">
87
90
  <ol class="notes" id="notes" hidden></ol>