truemap-cli 0.5.1 → 0.5.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/README.md +1 -0
- package/kit/tokens.css +67 -0
- package/kit/truemap.css +23 -73
- package/package.json +1 -1
- package/skills/truemap/SKILL.md +2 -2
- package/src/changes.js +10 -8
- package/src/check.js +66 -8
- package/src/cli.js +41 -10
- package/src/contrast.js +93 -0
- package/src/export.js +12 -7
- package/src/guide.md +34 -9
- package/src/outline.js +7 -3
- package/src/server.js +81 -23
- package/src/theme.js +11 -10
- package/src/ui/diagram.js +139 -27
- package/src/ui/sdk.js +52 -55
- package/src/ui/workspace.css +19 -34
- package/src/ui/workspace.html +1 -0
- package/src/ui/workspace.js +61 -14
package/src/ui/workspace.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
const S = {
|
|
7
7
|
placeholder: 'Ask about this page', placeholderNotes: 'Add a message (optional)',
|
|
8
8
|
drawPrompt: 'Read this project and draw its blueprint as .truemap/index.html, then open it for me.',
|
|
9
|
-
ok: 'Matches the code', changed: (n) =>
|
|
9
|
+
ok: 'Matches the code', changed: (n, what = 'Map') => `${what} may be out of date (${n})`, broken: (n, what = 'Map') => `${what} out of date (${n})`,
|
|
10
10
|
fixPrompt: (p, c, b) => `Check ${p} against the code and update it: ${[b && `${b} anchor(s) no longer match`, c && `${c} anchor(s) whose code changed after the page was written`].filter(Boolean).join(', ')}.`,
|
|
11
11
|
chose: 'Chose', fromPage: 'Sent by the page’s own script', waiting: 'Waiting for the agent', you: 'You',
|
|
12
12
|
state: { listening: 'Listening', working: 'Working', idle: 'Stopped listening', stale: 'No reply yet', offline: 'Not listening', closed: 'Closed' },
|
|
@@ -151,6 +151,20 @@
|
|
|
151
151
|
});
|
|
152
152
|
$('recheck').onclick = () => { api('/api/check'); closeMenu(); };
|
|
153
153
|
|
|
154
|
+
// ---------- browser translation ----------
|
|
155
|
+
// Chrome's page translation translates text it sees appear. A menu written in the HTML and shown later only
|
|
156
|
+
// changes its hidden attribute, so it would stay untranslated: give its text to the translator again.
|
|
157
|
+
const translating = () => /\btranslated-(ltr|rtl)\b/.test(document.documentElement.className);
|
|
158
|
+
new MutationObserver((ms) => {
|
|
159
|
+
if (!translating()) return;
|
|
160
|
+
for (const m of ms) {
|
|
161
|
+
if (m.target.hidden) continue;
|
|
162
|
+
const walk = document.createTreeWalker(m.target, NodeFilter.SHOW_TEXT); const nodes = [];
|
|
163
|
+
while (walk.nextNode()) if (walk.currentNode.nodeValue.trim() && !walk.currentNode.parentElement.closest('code, [translate="no"]')) nodes.push(walk.currentNode);
|
|
164
|
+
for (const n of nodes) n.replaceWith(document.createTextNode(n.nodeValue));
|
|
165
|
+
}
|
|
166
|
+
}).observe(document.body, { subtree: true, attributes: true, attributeFilter: ['hidden'] });
|
|
167
|
+
|
|
154
168
|
// ---------- more menu: the page file, export, end the conversation ----------
|
|
155
169
|
const more = $('moreMenu');
|
|
156
170
|
const filePath = () => {
|
|
@@ -215,7 +229,9 @@
|
|
|
215
229
|
chip.hidden = !st;
|
|
216
230
|
const { changed, broken } = r.counts;
|
|
217
231
|
chip.dataset.state = st || 'ok';
|
|
218
|
-
|
|
232
|
+
// name what is stale: the map, a draft or another page
|
|
233
|
+
const what = state.page === 'index.html' ? 'Map' : state.page.startsWith('drafts/') ? 'Draft' : 'Page';
|
|
234
|
+
$('checkText').textContent = broken ? S.broken(broken, what) + (changed ? `, ${S.changed(changed, what).toLowerCase()}` : '') : changed ? S.changed(changed, what) : S.ok;
|
|
219
235
|
chip.title = st ? 'Ask the agent to update this page' : `${S.ok}: ${r.counts.ok} boxes checked`;
|
|
220
236
|
if (!st) $('checkText').textContent = '';
|
|
221
237
|
chip.setAttribute('aria-label', st ? $('checkText').textContent : S.ok);
|
|
@@ -284,7 +300,7 @@
|
|
|
284
300
|
function renderAll() {
|
|
285
301
|
msgsEl.innerHTML = ''; lastRole = null;
|
|
286
302
|
if (!state.history.length) {
|
|
287
|
-
msgsEl.innerHTML = `<div class="intro"><p>Ask about anything on the page. <b>Click a box</b> to
|
|
303
|
+
msgsEl.innerHTML = `<div class="intro"><p>Ask about anything on the page. <b>Click a box</b> to light up what it connects to; <b>double-click</b> it to see what it is and comment right there. Comments go out together, each with the code it points to.</p></div>`;
|
|
288
304
|
}
|
|
289
305
|
for (const e of state.history) appendEntry(e, false);
|
|
290
306
|
renderWorking();
|
|
@@ -296,18 +312,30 @@
|
|
|
296
312
|
const rows = c.boxes.map((b) => `<button type="button" class="cc-row" data-src="${esc(b.src)}" data-page="${esc(b.pages?.includes(state.page) ? state.page : (b.pages?.[0] || state.page))}"><b>${esc(b.name || b.src.split('#')[1] || b.src)}${b.isNew ? '<span class="cc-new">New</span>' : ''}</b>${d(b.add, b.del)}</button>`).join('');
|
|
297
313
|
const loose = c.unmapped?.length ? `<details class="cc-loose"><summary>${c.unmapped.length} file${c.unmapped.length > 1 ? 's' : ''} not on the map</summary>${c.unmapped.map((x) => `<div><code>${esc(x.path)}</code>${d(x.add, x.del)}</div>`).join('')}<button type="button" class="text-btn" data-act="map-these">Ask the agent to map these</button></details>` : '';
|
|
298
314
|
const notDone = c.notDone?.length ? `<p class="cc-warn">Planned, no changes: ${esc(c.notDone.join(', '))}</p>` : '';
|
|
299
|
-
return `<div class="cc"><div class="cc-head"><b>Changed ${c.files} file${c.files > 1 ? 's' : ''}</b>${d(c.add, c.del)}</div>${rows ? `<div class="cc-rows">${rows}</div>` : ''}${notDone}${loose}<p class="cc-hint">Click a box to see its diff.</p></div>`;
|
|
315
|
+
return `<div class="cc"><div class="cc-head"><b>Changed ${c.files} file${c.files > 1 ? 's' : ''}</b>${d(c.add, c.del)}</div>${rows ? `<div class="cc-rows">${rows}</div>` : ''}${notDone}${loose}<p class="cc-hint">Click a box name above to see its diff.</p></div>`;
|
|
300
316
|
}
|
|
301
317
|
let latestChanges = null;
|
|
302
318
|
function showChangeBadges() {
|
|
303
319
|
toFrame({ type: 'changes', on: false, items: latestChanges ? latestChanges.boxes.filter((b) => !b.pages || b.pages.includes(state.page)).map((b) => ({ src: b.src, add: b.add, del: b.del, isNew: !!b.isNew })) : [] });
|
|
304
320
|
}
|
|
321
|
+
// The server keeps one changes card per turn and updates it in place as the turn goes on.
|
|
322
|
+
function updateEntry(e) {
|
|
323
|
+
const i = state.history.findIndex((h) => h.id === e.id);
|
|
324
|
+
if (i === -1) { state.history.push(e); appendEntry(e, true, true); return; }
|
|
325
|
+
state.history[i] = e;
|
|
326
|
+
const el = msgsEl.querySelector(`.msg[data-id="${CSS.escape(e.id)}"]`);
|
|
327
|
+
if (!el || e.kind !== 'changes' || !e.changes) { renderAll(); return; }
|
|
328
|
+
el.innerHTML = changesCard(e.changes);
|
|
329
|
+
// the map's badges follow the newest card
|
|
330
|
+
const last = [...state.history].reverse().find((h) => h.kind === 'changes' && h.changes);
|
|
331
|
+
if (last === e) { latestChanges = e.changes; if (showingChanges()) loadChanges(); else showChangeBadges(); }
|
|
332
|
+
}
|
|
305
333
|
function appendEntry(e, scroll = true, live = false) {
|
|
306
334
|
msgsEl.querySelector('.intro')?.remove();
|
|
307
335
|
if (e.role !== lastRole) { msgsEl.appendChild(whoLine(e.role, e.at, e.agent)); lastRole = e.role; }
|
|
308
336
|
const el = document.createElement('div');
|
|
309
337
|
if (e.kind === 'changes' && e.changes) {
|
|
310
|
-
el.className = 'msg agent';
|
|
338
|
+
el.className = 'msg agent'; if (e.id) el.dataset.id = e.id;
|
|
311
339
|
el.innerHTML = changesCard(e.changes);
|
|
312
340
|
latestChanges = e.changes; showChangeBadges();
|
|
313
341
|
msgsEl.appendChild(el); renderWorking(); if (scroll) scrollChat();
|
|
@@ -349,17 +377,26 @@
|
|
|
349
377
|
}
|
|
350
378
|
const scrollChat = () => { msgsEl.scrollTop = msgsEl.scrollHeight; };
|
|
351
379
|
let hoverLit = null;
|
|
380
|
+
let pinnedFocus = null;
|
|
381
|
+
const endPreview = () => {
|
|
382
|
+
msgsEl.querySelector('li.lit')?.classList.remove('lit');
|
|
383
|
+
const keep = pinnedFocus && pinnedFocus.page === state.page ? pinnedFocus.msg : null;
|
|
384
|
+
hoverLit = keep ? '__pinned' : null;
|
|
385
|
+
toFrame(keep ? { ...keep, scroll: false } : { type: 'clear-focus' });
|
|
386
|
+
};
|
|
387
|
+
const unpin = () => { pinnedFocus = null; if (hoverLit === '__pinned') hoverLit = null; };
|
|
352
388
|
msgsEl.addEventListener('mouseover', (e) => {
|
|
353
389
|
const host = e.target.closest('li.has-ref, a.ref');
|
|
354
390
|
const ids = host ? [...new Set([...(host.matches('a.ref') ? [host] : host.querySelectorAll('a.ref'))].flatMap((r) => r.dataset.focus.split(',')).filter(Boolean))] : null;
|
|
355
391
|
const key = ids ? ids.join(',') : null;
|
|
356
392
|
if (key === hoverLit || (!key && (hoverLit === '__pinned' || !hoverLit))) return;
|
|
393
|
+
if (!ids) return endPreview();
|
|
357
394
|
msgsEl.querySelector('li.lit')?.classList.remove('lit');
|
|
358
395
|
hoverLit = key;
|
|
359
|
-
if (
|
|
360
|
-
|
|
396
|
+
if (host.matches('li')) host.classList.add('lit');
|
|
397
|
+
toFrame({ type: 'focus', items: ids, note: '', who: '', scroll: false, transient: true });
|
|
361
398
|
});
|
|
362
|
-
msgsEl.addEventListener('mouseleave', () => { if (hoverLit && hoverLit !== '__pinned')
|
|
399
|
+
msgsEl.addEventListener('mouseleave', () => { if (hoverLit && hoverLit !== '__pinned') endPreview(); });
|
|
363
400
|
msgsEl.addEventListener('click', (e) => {
|
|
364
401
|
const cc = e.target.closest('.cc-row');
|
|
365
402
|
if (cc) { if (cc.dataset.page !== state.page) { state.pendingOpen = cc.dataset.src; go(cc.dataset.page); } else toFrame({ type: 'open-box', src: cc.dataset.src }); return; }
|
|
@@ -385,6 +422,7 @@
|
|
|
385
422
|
function pointAt(items, note, who, page) {
|
|
386
423
|
const target = page && state.pages.some((p) => p.page === page) ? page : state.page;
|
|
387
424
|
const msg = { type: 'focus', items, note: note || '', who: who || agentName() };
|
|
425
|
+
pinnedFocus = { page: target, msg }; hoverLit = '__pinned';
|
|
388
426
|
if (target && target !== state.page) { state.pendingFocus = msg; go(target); } else toFrame(msg);
|
|
389
427
|
}
|
|
390
428
|
|
|
@@ -503,10 +541,15 @@
|
|
|
503
541
|
else if (act === 'links') pointAt([box.id, ...box.to.map((c) => c.id), ...box.from.map((c) => c.id)], '', '');
|
|
504
542
|
};
|
|
505
543
|
}
|
|
544
|
+
// Escape lets go of a highlight (the chip's, a clicked link's), wherever the cursor is.
|
|
545
|
+
document.addEventListener('keydown', (e) => {
|
|
546
|
+
if (e.key !== 'Escape' || inspecting() || !menu.hidden || !$('moreMenu').hidden || (!pinnedFocus && $('litPill').hidden)) return;
|
|
547
|
+
unpin(); toFrame({ type: 'clear-focus' }); $('litPill').hidden = true;
|
|
548
|
+
});
|
|
506
549
|
document.addEventListener('keydown', (e) => {
|
|
507
550
|
if (e.key !== 'Escape' || !inspecting() || !menu.hidden || !$('moreMenu').hidden) return;
|
|
508
551
|
if (e.target.closest?.('.insp-comment') && e.target.value) return;
|
|
509
|
-
closeInspector(); toFrame({ type: 'clear-focus' }); e.stopPropagation();
|
|
552
|
+
closeInspector(); unpin(); toFrame({ type: 'clear-focus' }); e.stopPropagation();
|
|
510
553
|
}, true);
|
|
511
554
|
|
|
512
555
|
// "Ask about this": the box goes along with the next message.
|
|
@@ -859,7 +902,7 @@
|
|
|
859
902
|
pointAt(stale.map((a) => a.src), broken ? 'These boxes no longer match the code.' : 'The code under these boxes changed after this page was written.', 'truemap');
|
|
860
903
|
setPanel(true); setTab('convo');
|
|
861
904
|
if (!input.value.trim()) { input.value = `The code under ${stale.map((a) => a.src.split('#')[1] || a.path).join(', ')} changed. Check whether the map still says the right thing about ${stale.length > 1 ? 'them' : 'it'}: fix what is wrong, confirm the rest.`; autosize(); }
|
|
862
|
-
input.focus();
|
|
905
|
+
input.focus(); requestAnimationFrame(scrollChat);
|
|
863
906
|
};
|
|
864
907
|
|
|
865
908
|
// A decision only counts as the user's if the user actually moved focus into the page.
|
|
@@ -903,7 +946,7 @@
|
|
|
903
946
|
$('litPill').hidden = !n || !!d.transient;
|
|
904
947
|
$('litText').textContent = n === 1 ? '1 box lit' : `${n} boxes lit`;
|
|
905
948
|
} else if (d.type === 'focus-cleared') {
|
|
906
|
-
$('litPill').hidden = true;
|
|
949
|
+
$('litPill').hidden = true; unpin();
|
|
907
950
|
} else if (d.type === 'plan-act') {
|
|
908
951
|
if (d.act === 'approve') {
|
|
909
952
|
if (state.notes.length || input.value.trim()) { const t = input.value; input.value = ''; autosize(); await send(t, { approving: true }); }
|
|
@@ -928,7 +971,7 @@
|
|
|
928
971
|
}
|
|
929
972
|
});
|
|
930
973
|
|
|
931
|
-
$('litClear').onclick = () => { toFrame({ type: 'clear-focus' }); $('litPill').hidden = true; };
|
|
974
|
+
$('litClear').onclick = () => { unpin(); toFrame({ type: 'clear-focus' }); $('litPill').hidden = true; };
|
|
932
975
|
|
|
933
976
|
// ---------- live events from the server ----------
|
|
934
977
|
let closedTimer = null;
|
|
@@ -973,6 +1016,9 @@
|
|
|
973
1016
|
} else if (d.type === 'chat') {
|
|
974
1017
|
state.history.push(d.entry); appendEntry(d.entry, true, true);
|
|
975
1018
|
if (d.entry.role === 'agent') state.lastAgentEvent = Date.now();
|
|
1019
|
+
} else if (d.type === 'chat-update') {
|
|
1020
|
+
updateEntry(d.entry);
|
|
1021
|
+
if (d.entry.role === 'agent') state.lastAgentEvent = Date.now();
|
|
976
1022
|
} else if (d.type === 'agent') {
|
|
977
1023
|
setAgent(d.agent);
|
|
978
1024
|
} else if (d.type === 'delivered') {
|
|
@@ -985,6 +1031,7 @@
|
|
|
985
1031
|
else if (state.page && !state.pages.some((p) => p.page === state.page)) state.pages[0] ? go(state.pages[0].page) : showEmpty();
|
|
986
1032
|
} else if (d.type === 'changed') {
|
|
987
1033
|
const files = d.files || [];
|
|
1034
|
+
if (files.some((f) => !f || f.startsWith('assets/'))) $('tokensCss').href = `/__truemap/tokens.css?v=${Date.now()}`;
|
|
988
1035
|
if (state.page && files.some((f) => !f || f === state.page || f.startsWith('assets/'))) reloadFrame();
|
|
989
1036
|
} else if (d.type === 'check') {
|
|
990
1037
|
state.check = d.check || { results: [] }; renderHeader(); sendMarks(); if (!menu.hidden) renderMenu();
|
|
@@ -993,10 +1040,10 @@
|
|
|
993
1040
|
if (d.page && state.pages.some((p) => p.page === d.page)) go(d.page, { force: true });
|
|
994
1041
|
renderHeader();
|
|
995
1042
|
} else if (d.type === 'show') {
|
|
996
|
-
if (d.clear) toFrame({ type: 'clear-focus' });
|
|
1043
|
+
if (d.clear) { unpin(); toFrame({ type: 'clear-focus' }); }
|
|
997
1044
|
else pointAt(d.focus || [], d.note || '', AGENTS[d.agent] || agentName(), d.page);
|
|
998
1045
|
} else if (d.type === 'plan') {
|
|
999
|
-
|
|
1046
|
+
msgsEl.querySelector('li.lit')?.classList.remove('lit'); unpin();
|
|
1000
1047
|
$('litPill').hidden = true; toFrame({ type: 'clear-focus' });
|
|
1001
1048
|
state.plan = d.plan || null; renderPlan(); sendPlan(); renderNotes();
|
|
1002
1049
|
} else if (d.type === 'changes-base') {
|