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/README.md +4 -3
- package/kit/tokens.css +65 -0
- package/kit/truemap.css +9 -64
- package/package.json +1 -1
- package/skills/truemap/SKILL.md +3 -2
- package/src/changes.js +10 -1
- package/src/check.js +4 -1
- package/src/cli.js +90 -9
- package/src/common.js +12 -1
- package/src/contrast.js +93 -0
- package/src/export.js +12 -7
- package/src/guide.md +55 -8
- package/src/plan.js +1 -1
- package/src/server.js +124 -25
- package/src/theme.js +47 -0
- package/src/ui/sdk.js +152 -54
- package/src/ui/workspace.css +58 -34
- package/src/ui/workspace.html +9 -6
- package/src/ui/workspace.js +148 -48
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) => `Map may be out of date (${n})`, broken: (n) => `Map 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' },
|
|
@@ -47,12 +47,18 @@
|
|
|
47
47
|
.replace(/`([^`]+)`/g, '<code>$1</code>')
|
|
48
48
|
.replace(/\*\*([^*]+)\*\*/g, '<strong>$1</strong>')
|
|
49
49
|
.replace(/(^|[^*\w])\*([^*\s][^*]*?)\*(?![*\w])/g, '$1<em>$2</em>')
|
|
50
|
-
.replace(
|
|
50
|
+
.replace(/!\[([^\]]*)\]\(([^)\s]+)\)/g, (all, alt, href) => {
|
|
51
|
+
const src = /^https:\/\/[^\s"'<>]+$/i.test(href) ? href
|
|
52
|
+
: /^[^\s"'<>:]+\.(png|jpe?g|gif|webp)$/i.test(href) || /^[a-z]:[\\/][^\s"'<>]+\.(png|jpe?g|gif|webp)$/i.test(href) ? `/api/image?path=${encodeURIComponent(href.replace(/&/g, '&'))}&t=${encodeURIComponent(TOKEN)}` : '';
|
|
53
|
+
if (!src) return all;
|
|
54
|
+
return `<a class="pic" href="${src}" target="_blank" rel="noopener noreferrer"><img src="${src}" alt="${alt}" loading="lazy" onerror="this.parentNode.classList.add('broken')"></a>`;
|
|
55
|
+
})
|
|
56
|
+
.replace(/(^|[^!])\[([^\]]+)\]\(([^)\s]+)\)/g, (all, pre, t, href) => pre + ((() => {
|
|
51
57
|
if (/^[\w./-]+\.html?(#[\w-]*)?$/i.test(href)) return `<a href="#" data-page="${href}">${t}</a>`;
|
|
52
58
|
if (/^#[\w-]+$/.test(href)) return `<a href="#" class="ref" data-focus="${href.slice(1)}">${t}</a>`;
|
|
53
59
|
if (/^https:\/\/[^\s"'<>]+$/i.test(href)) return `<a href="${href}" target="_blank" rel="noopener noreferrer">${t}</a>`;
|
|
54
60
|
return t;
|
|
55
|
-
});
|
|
61
|
+
})()));
|
|
56
62
|
}
|
|
57
63
|
function md(text) {
|
|
58
64
|
const lines = esc(text).split('\n');
|
|
@@ -104,22 +110,27 @@
|
|
|
104
110
|
const stateOf = (r) => (r?.counts?.broken ? 'broken' : r?.counts?.changed ? 'changed' : '');
|
|
105
111
|
const titleOf = (p) => (p.page === 'index.html' && (!p.title || p.title === 'index') ? 'Blueprint' : p.title || p.page);
|
|
106
112
|
|
|
113
|
+
// Drafts are the record of what the agent explained, newest first; other pages after them.
|
|
114
|
+
const isDraft = (p) => /^drafts\//.test(p.page);
|
|
115
|
+
const draftNo = (p) => { const n = parseInt(p.page.slice(7), 10); return Number.isFinite(n) ? n : null; };
|
|
107
116
|
function renderMenu() {
|
|
108
117
|
const list = $('pages'); list.innerHTML = '';
|
|
109
118
|
const q = $('filter').value.trim().toLowerCase();
|
|
110
119
|
$('filter').hidden = state.pages.length <= 7;
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
if (
|
|
120
|
+
const match = (p) => !q || `${p.title} ${p.page}`.toLowerCase().includes(q);
|
|
121
|
+
const drafts = state.pages.filter((p) => isDraft(p) && match(p)).sort((a, b) => (draftNo(b) ?? 0) - (draftNo(a) ?? 0) || b.at - a.at);
|
|
122
|
+
const pages = state.pages.filter((p) => !isDraft(p) && p.page !== 'index.html' && match(p));
|
|
123
|
+
const item = (p, num) => {
|
|
124
|
+
const st = stateOf(resultFor(p.page));
|
|
125
|
+
const b = document.createElement('button');
|
|
126
|
+
b.type = 'button'; b.className = 'page-item' + (p.page === state.page ? ' active' : ''); b.setAttribute('role', 'menuitem');
|
|
127
|
+
b.innerHTML = `${num != null ? `<span class="pi-num">${num}</span>` : ''}<span class="pi-text"><span class="pi-title">${esc(titleOf(p))}</span><span class="pi-file">${p.at ? esc(timeOf(new Date(p.at).toISOString())) : esc(p.page)}</span></span>${st ? `<span class="tri ${st}" title="${st === 'broken' ? 'Out of date' : 'Code changed'}"></span>` : ''}`;
|
|
128
|
+
b.onclick = () => { closeMenu(); go(p.page); };
|
|
129
|
+
list.appendChild(b);
|
|
130
|
+
};
|
|
131
|
+
if (drafts.length) { list.insertAdjacentHTML('beforeend', '<div class="menu-label">Drafts</div>'); drafts.forEach((p) => item(p, draftNo(p))); }
|
|
132
|
+
if (pages.length) { list.insertAdjacentHTML('beforeend', '<div class="menu-label">Pages</div>'); pages.forEach((p) => item(p, null)); }
|
|
133
|
+
if (!drafts.length && !pages.length) list.innerHTML = `<div class="menu-head">${state.pages.length ? 'No drafts yet. Ask the agent to explain something and it draws one here.' : 'No pages in .truemap/ yet'}</div>`;
|
|
123
134
|
}
|
|
124
135
|
function openMenu() { renderMenu(); menu.hidden = false; $('pageBtn').setAttribute('aria-expanded', 'true'); ($('filter').hidden ? menu.querySelector('.page-item.active, .page-item') : $('filter'))?.focus(); }
|
|
125
136
|
function closeMenu() { menu.hidden = true; $('pageBtn').setAttribute('aria-expanded', 'false'); }
|
|
@@ -140,6 +151,20 @@
|
|
|
140
151
|
});
|
|
141
152
|
$('recheck').onclick = () => { api('/api/check'); closeMenu(); };
|
|
142
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
|
+
|
|
143
168
|
// ---------- more menu: the page file, export, end the conversation ----------
|
|
144
169
|
const more = $('moreMenu');
|
|
145
170
|
const filePath = () => {
|
|
@@ -157,6 +182,20 @@
|
|
|
157
182
|
$('endHint').textContent = talking ? `Lets ${agentName()} go back to the terminal` : 'No conversation is running';
|
|
158
183
|
}
|
|
159
184
|
const closeMore = () => { more.hidden = true; $('moreBtn').setAttribute('aria-expanded', 'false'); };
|
|
185
|
+
const renderTheme = () => {
|
|
186
|
+
const t = document.documentElement.getAttribute('data-theme') || '';
|
|
187
|
+
for (const b of document.querySelectorAll('[data-theme-pick]')) b.setAttribute('aria-pressed', String(b.dataset.themePick === t));
|
|
188
|
+
};
|
|
189
|
+
renderTheme();
|
|
190
|
+
for (const b of document.querySelectorAll('[data-theme-pick]')) {
|
|
191
|
+
b.onclick = () => {
|
|
192
|
+
const t = b.dataset.themePick;
|
|
193
|
+
if (t) document.documentElement.setAttribute('data-theme', t); else document.documentElement.removeAttribute('data-theme');
|
|
194
|
+
renderTheme();
|
|
195
|
+
toFrame({ type: 'theme', theme: t });
|
|
196
|
+
api('/api/prefs', { theme: t || 'system' });
|
|
197
|
+
};
|
|
198
|
+
}
|
|
160
199
|
$('moreBtn').onclick = (e) => {
|
|
161
200
|
e.stopPropagation();
|
|
162
201
|
if (!more.hidden) return closeMore();
|
|
@@ -177,12 +216,12 @@
|
|
|
177
216
|
|
|
178
217
|
function renderHeader() {
|
|
179
218
|
const p = state.pages.find((x) => x.page === state.page);
|
|
180
|
-
|
|
181
|
-
// The blueprint is always one click away.
|
|
219
|
+
// The map is always one click away; the switcher names the draft or page you are on, or offers the drafts.
|
|
182
220
|
const home = state.pages.find((x) => x.page === 'index.html');
|
|
183
|
-
const
|
|
184
|
-
$('crumbHome').hidden = !
|
|
185
|
-
|
|
221
|
+
const onMap = !state.page || state.page === 'index.html';
|
|
222
|
+
$('crumbHome').hidden = !home; $('crumbHome').classList.toggle('on', onMap);
|
|
223
|
+
const nDrafts = state.pages.filter(isDraft).length;
|
|
224
|
+
$('pageTitle').textContent = !onMap && p ? `${isDraft(p) && draftNo(p) != null ? `#${draftNo(p)} ` : ''}${titleOf(p)}` : nDrafts ? `Drafts (${nDrafts})` : state.pages.length > 1 ? 'Pages' : 'No drafts yet';
|
|
186
225
|
renderProjects();
|
|
187
226
|
const r = resultFor(state.page); const st = stateOf(r);
|
|
188
227
|
const chip = $('checkChip');
|
|
@@ -216,7 +255,7 @@
|
|
|
216
255
|
state.page = page;
|
|
217
256
|
history.replaceState(null, '', `${location.pathname}${location.search}#page=${encodeURIComponent(page)}`);
|
|
218
257
|
api('/api/viewing', { page });
|
|
219
|
-
renderHeader(); renderNotice(); renderNotes();
|
|
258
|
+
renderHeader(); renderNotice(); renderNotes(); renderNav();
|
|
220
259
|
}
|
|
221
260
|
function showEmpty() {
|
|
222
261
|
state.page = null; frame.hidden = true; frame.removeAttribute('src'); $('empty').hidden = false; renderHeader(); renderNotice();
|
|
@@ -259,16 +298,36 @@
|
|
|
259
298
|
function renderAll() {
|
|
260
299
|
msgsEl.innerHTML = ''; lastRole = null;
|
|
261
300
|
if (!state.history.length) {
|
|
262
|
-
msgsEl.innerHTML = `<div class="intro"><p>Ask about anything on the page. <b>Click a box</b> to see what it is and comment
|
|
301
|
+
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>`;
|
|
263
302
|
}
|
|
264
303
|
for (const e of state.history) appendEntry(e, false);
|
|
265
304
|
renderWorking();
|
|
266
305
|
scrollChat(); requestAnimationFrame(scrollChat); setTimeout(scrollChat, 300);
|
|
267
306
|
}
|
|
307
|
+
// What changed in a turn: one card in the conversation, badges on the map, the diff from the box.
|
|
308
|
+
function changesCard(c) {
|
|
309
|
+
const d = (a, x) => `<span class="delta">${[a ? `<span class="a">+${a}</span>` : '', x ? `<span class="d">−${x}</span>` : ''].filter(Boolean).join(' ') || '±0'}</span>`;
|
|
310
|
+
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('');
|
|
311
|
+
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>` : '';
|
|
312
|
+
const notDone = c.notDone?.length ? `<p class="cc-warn">Planned, no changes: ${esc(c.notDone.join(', '))}</p>` : '';
|
|
313
|
+
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>`;
|
|
314
|
+
}
|
|
315
|
+
let latestChanges = null;
|
|
316
|
+
function showChangeBadges() {
|
|
317
|
+
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 })) : [] });
|
|
318
|
+
}
|
|
268
319
|
function appendEntry(e, scroll = true, live = false) {
|
|
269
320
|
msgsEl.querySelector('.intro')?.remove();
|
|
270
321
|
if (e.role !== lastRole) { msgsEl.appendChild(whoLine(e.role, e.at, e.agent)); lastRole = e.role; }
|
|
271
322
|
const el = document.createElement('div');
|
|
323
|
+
if (e.kind === 'changes' && e.changes) {
|
|
324
|
+
el.className = 'msg agent';
|
|
325
|
+
el.innerHTML = changesCard(e.changes);
|
|
326
|
+
latestChanges = e.changes; showChangeBadges();
|
|
327
|
+
msgsEl.appendChild(el); renderWorking(); if (scroll) scrollChat();
|
|
328
|
+
if (live && !panelOpen()) { state.unread = true; renderBadge(); }
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
272
331
|
if (e.role === 'agent') {
|
|
273
332
|
el.className = 'msg agent';
|
|
274
333
|
el.innerHTML = e.ask && e.text.trim() === e.ask.question.trim() ? '' : md(e.text);
|
|
@@ -304,18 +363,34 @@
|
|
|
304
363
|
}
|
|
305
364
|
const scrollChat = () => { msgsEl.scrollTop = msgsEl.scrollHeight; };
|
|
306
365
|
let hoverLit = null;
|
|
366
|
+
let pinnedFocus = null;
|
|
367
|
+
const endPreview = () => {
|
|
368
|
+
msgsEl.querySelector('li.lit')?.classList.remove('lit');
|
|
369
|
+
const keep = pinnedFocus && pinnedFocus.page === state.page ? pinnedFocus.msg : null;
|
|
370
|
+
hoverLit = keep ? '__pinned' : null;
|
|
371
|
+
toFrame(keep ? { ...keep, scroll: false } : { type: 'clear-focus' });
|
|
372
|
+
};
|
|
373
|
+
const unpin = () => { pinnedFocus = null; if (hoverLit === '__pinned') hoverLit = null; };
|
|
307
374
|
msgsEl.addEventListener('mouseover', (e) => {
|
|
308
375
|
const host = e.target.closest('li.has-ref, a.ref');
|
|
309
376
|
const ids = host ? [...new Set([...(host.matches('a.ref') ? [host] : host.querySelectorAll('a.ref'))].flatMap((r) => r.dataset.focus.split(',')).filter(Boolean))] : null;
|
|
310
377
|
const key = ids ? ids.join(',') : null;
|
|
311
378
|
if (key === hoverLit || (!key && (hoverLit === '__pinned' || !hoverLit))) return;
|
|
379
|
+
if (!ids) return endPreview();
|
|
312
380
|
msgsEl.querySelector('li.lit')?.classList.remove('lit');
|
|
313
381
|
hoverLit = key;
|
|
314
|
-
if (
|
|
315
|
-
|
|
382
|
+
if (host.matches('li')) host.classList.add('lit');
|
|
383
|
+
toFrame({ type: 'focus', items: ids, note: '', who: '', scroll: false, transient: true });
|
|
316
384
|
});
|
|
317
|
-
msgsEl.addEventListener('mouseleave', () => { if (hoverLit && hoverLit !== '__pinned')
|
|
385
|
+
msgsEl.addEventListener('mouseleave', () => { if (hoverLit && hoverLit !== '__pinned') endPreview(); });
|
|
318
386
|
msgsEl.addEventListener('click', (e) => {
|
|
387
|
+
const cc = e.target.closest('.cc-row');
|
|
388
|
+
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; }
|
|
389
|
+
if (e.target.closest('[data-act="map-these"]')) {
|
|
390
|
+
const files = [...e.target.closest('.cc').querySelectorAll('.cc-loose code')].map((c) => c.textContent);
|
|
391
|
+
send(`These changed files are not on the map yet. Add boxes for the ones that matter (or say why they don't need one): ${files.join(', ')}`, { context: [], noNotes: true });
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
319
394
|
const ref = e.target.closest('[data-focus]');
|
|
320
395
|
if (ref) { e.preventDefault(); hoverLit = '__pinned'; pointAt(ref.dataset.focus.split(',').filter(Boolean), '', ''); return; }
|
|
321
396
|
const step = e.target.closest('li.has-ref');
|
|
@@ -333,6 +408,7 @@
|
|
|
333
408
|
function pointAt(items, note, who, page) {
|
|
334
409
|
const target = page && state.pages.some((p) => p.page === page) ? page : state.page;
|
|
335
410
|
const msg = { type: 'focus', items, note: note || '', who: who || agentName() };
|
|
411
|
+
pinnedFocus = { page: target, msg }; hoverLit = '__pinned';
|
|
336
412
|
if (target && target !== state.page) { state.pendingFocus = msg; go(target); } else toFrame(msg);
|
|
337
413
|
}
|
|
338
414
|
|
|
@@ -410,8 +486,8 @@
|
|
|
410
486
|
inspBody.innerHTML = `
|
|
411
487
|
<div class="insp-name"><h2>${esc(box.label)}</h2>${box.tag ? `<code>${esc(box.tag)}</code>` : ''}</div>
|
|
412
488
|
${PLAN[box.plan] ? `<span class="insp-plan">${PLAN[box.plan]}</span>${box.planNote ? `<p class="insp-why">${esc(box.planNote)}</p>` : ''}` : ''}
|
|
413
|
-
${box.mark ? `<div class="insp-state ${box.mark === 'broken' ? 'broken' : ''}">${box.mark === 'broken' ? 'This box no longer matches the code.' : 'The code changed since this box was last checked.'}</div>` : ''}
|
|
414
|
-
${box.mark === 'changed' && box.src ? '<details class="insp-drift" open><summary>What changed in its code</summary><div class="code-box"><div class="code-note">Reading the diff…</div></div></details>' : ''}
|
|
489
|
+
${box.mark && !(box.mark === 'changed' && latestChanges?.boxes?.some((x) => x.src === box.src)) ? `<div class="insp-state ${box.mark === 'broken' ? 'broken' : ''}">${box.mark === 'broken' ? 'This box no longer matches the code.' : 'The code changed since this box was last checked.'}</div>` : ''}
|
|
490
|
+
${box.mark === 'changed' && box.src && !latestChanges?.boxes?.some((x) => x.src === box.src) ? '<details class="insp-drift" open><summary>What changed in its code</summary><div class="code-box"><div class="code-note">Reading the diff…</div></div></details>' : ''}
|
|
415
491
|
${unbuiltNote(box)}${changeSection(box)}
|
|
416
492
|
${detail ? `<div class="insp-detail">${detail}</div>` : ''}
|
|
417
493
|
${box.why ? `<div class="insp-why">${esc(box.why)}</div>` : ''}
|
|
@@ -451,10 +527,15 @@
|
|
|
451
527
|
else if (act === 'links') pointAt([box.id, ...box.to.map((c) => c.id), ...box.from.map((c) => c.id)], '', '');
|
|
452
528
|
};
|
|
453
529
|
}
|
|
530
|
+
// Escape lets go of a highlight (the chip's, a clicked link's), wherever the cursor is.
|
|
531
|
+
document.addEventListener('keydown', (e) => {
|
|
532
|
+
if (e.key !== 'Escape' || inspecting() || !menu.hidden || !$('moreMenu').hidden || (!pinnedFocus && $('litPill').hidden)) return;
|
|
533
|
+
unpin(); toFrame({ type: 'clear-focus' }); $('litPill').hidden = true;
|
|
534
|
+
});
|
|
454
535
|
document.addEventListener('keydown', (e) => {
|
|
455
536
|
if (e.key !== 'Escape' || !inspecting() || !menu.hidden || !$('moreMenu').hidden) return;
|
|
456
537
|
if (e.target.closest?.('.insp-comment') && e.target.value) return;
|
|
457
|
-
closeInspector(); toFrame({ type: 'clear-focus' }); e.stopPropagation();
|
|
538
|
+
closeInspector(); unpin(); toFrame({ type: 'clear-focus' }); e.stopPropagation();
|
|
458
539
|
}, true);
|
|
459
540
|
|
|
460
541
|
// "Ask about this": the box goes along with the next message.
|
|
@@ -515,7 +596,8 @@
|
|
|
515
596
|
if (!r) { el.innerHTML = '<p class="ch-empty">Reading the working tree…</p>'; return; }
|
|
516
597
|
if (r.error) { el.innerHTML = `<p class="ch-empty">Changes need a git repository with at least one commit (${esc(r.error)}).</p>`; return; }
|
|
517
598
|
const opts = r.bases.map((k) => `<option value="${k}"${k === r.base.kind ? ' selected' : ''}>${esc(k === r.base.kind ? r.base.label : BASES[k])}</option>`).join('');
|
|
518
|
-
|
|
599
|
+
const WHY = { turn: 'What the agent changed since it picked up your last message.', plan: r.base.label.startsWith('What was done') ? 'What was changed between your approval and the end of the plan.' : 'What changed since you approved the plan.', head: 'Everything not committed yet, yours and the agent’s.', main: 'Everything on this branch that main doesn’t have, like a pull request.' };
|
|
600
|
+
let html = `<div class="ch-base"><select id="chBase" aria-label="Compare with">${opts}</select><span class="ch-sum">${r.files ? `${plural(r.files, 'file')} ${delta(r.add, r.del)}` : 'Nothing changed'}</span></div><p class="ch-why">${esc(WHY[r.base.kind] || '')} Click a changed box to see its diff.</p>`;
|
|
519
601
|
if (r.plan) {
|
|
520
602
|
const done = r.plan.planned.filter((p) => p.changed).length; const missing = r.plan.planned.filter((p) => !p.changed);
|
|
521
603
|
html += `<div class="ch-plan"><div class="ch-h">Plan: ${esc(r.plan.title)}</div><p class="ch-sum">${done} of ${r.plan.planned.length} planned boxes have changes${r.plan.unplanned.length ? `, ${plural(r.plan.unplanned.length, 'box')} outside the plan` : ''}. Open a box to check its diff against what was planned.</p>`;
|
|
@@ -608,10 +690,10 @@
|
|
|
608
690
|
}
|
|
609
691
|
// The inspector shows what changed in a box while you review changes.
|
|
610
692
|
function changeSection(box) {
|
|
611
|
-
|
|
612
|
-
const b = ch.data.boxes.find((x) => x.src === box.src);
|
|
693
|
+
const b = latestChanges?.boxes?.find((x) => x.src === box.src);
|
|
613
694
|
if (!b) return '';
|
|
614
|
-
|
|
695
|
+
ch.data = { base: { kind: latestChanges.base, label: latestChanges.label } };
|
|
696
|
+
return `<div class="insp-change"><div><span>Changed in the last turn</span>${delta(b.add, b.del)}</div>${b.files.map((p, i) => `<details${i === 0 ? ' open' : ''} data-path="${esc(p)}"><summary><span>${esc(p)}</span></summary><div class="code-box"></div></details>`).join('')}</div>`;
|
|
615
697
|
}
|
|
616
698
|
function wireChangeSection() {
|
|
617
699
|
for (const d of inspBody.querySelectorAll('.insp-change details')) {
|
|
@@ -619,7 +701,7 @@
|
|
|
619
701
|
d.addEventListener('toggle', load); load();
|
|
620
702
|
}
|
|
621
703
|
}
|
|
622
|
-
|
|
704
|
+
|
|
623
705
|
|
|
624
706
|
// ---------- plan review: the agent's plan on the map, approve or ask for changes ----------
|
|
625
707
|
// Requesting changes is a mode of the composer: a heading says so, Send sends the request (comments included).
|
|
@@ -645,11 +727,13 @@
|
|
|
645
727
|
const counts = [p.add.length && `${p.add.length} new`, p.touch.length && `${p.touch.length} changing`, p.remove.length && `${p.remove.length} removed`].filter(Boolean).join(', ');
|
|
646
728
|
const here = p.page === state.page;
|
|
647
729
|
const old = here && state.planUnsupported;
|
|
730
|
+
// on its own map the plan's buttons sit beside its boxes; the bar is only a way there (or for old pages)
|
|
731
|
+
if (here && !old) { planBar.hidden = true; planBar.innerHTML = ''; renderNotes(); return; }
|
|
648
732
|
let html = `<div class="pb-text"><b>Plan</b><span class="pb-title">${esc(p.title)}</span><span class="pb-meta">${old ? 'not drawn: this page uses the old map format' : `${esc(counts)}${p.revision > 1 && p.status === 'review' ? ', revised' : ''}`}</span></div>`;
|
|
649
733
|
if (p.status === 'review' && old) {
|
|
650
734
|
html += `<div class="pb-acts"><span class="pb-wait">Read it in the conversation; the agent converts the map first.</span><button type="button" class="pb-btn" data-pb="request">Request changes</button><button type="button" class="pb-btn primary" data-pb="approve">Approve as text</button></div>`;
|
|
651
735
|
} else if (p.status === 'review') {
|
|
652
|
-
html +=
|
|
736
|
+
html += '<div class="pb-acts"><button type="button" class="pb-btn" data-pb="open" title="Review it where it is drawn">Show on the map</button></div>';
|
|
653
737
|
} else if (p.status === 'revise') {
|
|
654
738
|
html += `<div class="pb-acts"><span class="pb-wait">Waiting for the revised plan</span></div>`;
|
|
655
739
|
} else if (p.status === 'approved') {
|
|
@@ -664,7 +748,7 @@
|
|
|
664
748
|
const p = state.plan; if (!act || !p) return;
|
|
665
749
|
if (act === 'open') go(p.page);
|
|
666
750
|
else if (act === 'hide') { state.planHidden = `${p.slug}:${p.status}`; renderPlan(); }
|
|
667
|
-
else if (act === 'changes') {
|
|
751
|
+
else if (act === 'changes') { setPanel(true); scrollChat(); }
|
|
668
752
|
else if (act === 'request') { setPanel(true); setTab('convo'); setRequest(true); }
|
|
669
753
|
else if (act === 'approve') {
|
|
670
754
|
// comments written before approving still go to the agent, first
|
|
@@ -803,8 +887,8 @@
|
|
|
803
887
|
const broken = stale.filter((a) => a.state === 'broken').length;
|
|
804
888
|
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');
|
|
805
889
|
setPanel(true); setTab('convo');
|
|
806
|
-
if (!input.value.trim()) { input.value = `
|
|
807
|
-
input.focus();
|
|
890
|
+
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(); }
|
|
891
|
+
input.focus(); requestAnimationFrame(scrollChat);
|
|
808
892
|
};
|
|
809
893
|
|
|
810
894
|
// A decision only counts as the user's if the user actually moved focus into the page.
|
|
@@ -812,7 +896,7 @@
|
|
|
812
896
|
const userIsInFrame = () => document.activeElement === frame && state.frameFocusAt > 0;
|
|
813
897
|
|
|
814
898
|
// ---------- messages from the page frame ----------
|
|
815
|
-
window.addEventListener('message', (e) => {
|
|
899
|
+
window.addEventListener('message', async (e) => {
|
|
816
900
|
if (e.source !== frame.contentWindow || e.origin !== CONTENT || !e.data || !e.data.__truemap) return;
|
|
817
901
|
const d = e.data;
|
|
818
902
|
if (d.type === 'press' || d.type === 'deselect') {
|
|
@@ -821,11 +905,13 @@
|
|
|
821
905
|
navigate(d.dir);
|
|
822
906
|
} else if (d.type === 'peek') {
|
|
823
907
|
if (d.box) openInspector(d.box);
|
|
908
|
+
} else if (d.type === 'peek-if-open') {
|
|
909
|
+
if (d.box && panelEl.classList.contains('inspecting')) openInspector(d.box);
|
|
824
910
|
} else if (d.type === 'loaded') {
|
|
825
911
|
if (d.page && d.page !== state.page) setCurrent(d.page);
|
|
826
912
|
closeInspector();
|
|
827
913
|
if (state.pendingFocus) { const pf = state.pendingFocus; state.pendingFocus = null; setTimeout(() => toFrame({ type: 'focus', note: '', who: agentName(), ...pf }), 60); }
|
|
828
|
-
renderHeader(); sendMarks();
|
|
914
|
+
renderHeader(); sendMarks(); showChangeBadges(); sendPlan(); renderPlan();
|
|
829
915
|
if (state.pendingOpen) { const src = state.pendingOpen; state.pendingOpen = null; setTimeout(() => toFrame({ type: 'open-box', src }), 80); }
|
|
830
916
|
syncFrameNotes();
|
|
831
917
|
const y = state.scroll[d.page]; if (y) toFrame({ type: 'scroll', y });
|
|
@@ -846,7 +932,14 @@
|
|
|
846
932
|
$('litPill').hidden = !n || !!d.transient;
|
|
847
933
|
$('litText').textContent = n === 1 ? '1 box lit' : `${n} boxes lit`;
|
|
848
934
|
} else if (d.type === 'focus-cleared') {
|
|
849
|
-
$('litPill').hidden = true;
|
|
935
|
+
$('litPill').hidden = true; unpin();
|
|
936
|
+
} else if (d.type === 'plan-act') {
|
|
937
|
+
if (d.act === 'approve') {
|
|
938
|
+
if (state.notes.length || input.value.trim()) { const t = input.value; input.value = ''; autosize(); await send(t, { approving: true }); }
|
|
939
|
+
await api('/api/plan', { action: 'approve' });
|
|
940
|
+
} else if (d.act === 'reject') {
|
|
941
|
+
await api('/api/plan', { action: 'reject' });
|
|
942
|
+
}
|
|
850
943
|
} else if (d.type === 'changes-names') {
|
|
851
944
|
for (const it of d.items || []) if (it && it.src) ch.names.set(String(it.src), String(it.name || '').slice(0, 80));
|
|
852
945
|
if (showingChanges()) renderChanges();
|
|
@@ -864,10 +957,11 @@
|
|
|
864
957
|
}
|
|
865
958
|
});
|
|
866
959
|
|
|
867
|
-
$('litClear').onclick = () => { toFrame({ type: 'clear-focus' }); $('litPill').hidden = true; };
|
|
960
|
+
$('litClear').onclick = () => { unpin(); toFrame({ type: 'clear-focus' }); $('litPill').hidden = true; };
|
|
868
961
|
|
|
869
962
|
// ---------- live events from the server ----------
|
|
870
963
|
let closedTimer = null;
|
|
964
|
+
let loadedBuild = null;
|
|
871
965
|
function setConn(c) {
|
|
872
966
|
if (state.conn === c) return;
|
|
873
967
|
state.conn = c; app.dataset.conn = c;
|
|
@@ -887,6 +981,8 @@
|
|
|
887
981
|
let d; try { d = JSON.parse(ev.data); } catch { return; }
|
|
888
982
|
if (d.type === 'hello') {
|
|
889
983
|
greeted = true; clearTimeout(guard); clearTimeout(closedTimer); closedTimer = null;
|
|
984
|
+
if (d.build && loadedBuild && d.build !== loadedBuild) { es.close(); location.reload(); return; }
|
|
985
|
+
loadedBuild = d.build || loadedBuild;
|
|
890
986
|
setConn('live');
|
|
891
987
|
state.pages = d.pages || []; state.check = d.check || { results: [] }; state.history = d.history || [];
|
|
892
988
|
state.pending = new Set(d.pending || []);
|
|
@@ -897,7 +993,7 @@
|
|
|
897
993
|
$('project').textContent = String(d.root || '').split(/[\\/]/).filter(Boolean).pop() || '';
|
|
898
994
|
state.agent = { state: d.agent?.state || 'offline', name: d.agent?.name || '', since: d.agent?.since || 0 };
|
|
899
995
|
state.plan = d.plan || null;
|
|
900
|
-
renderAll(); renderAgent(); renderNotes();
|
|
996
|
+
renderAll(); renderAgent(); renderNotes(); renderPlan();
|
|
901
997
|
const last = [...state.history].reverse().find((h) => h.role === 'agent');
|
|
902
998
|
if (!panelOpen() && !narrow() && (state.plan?.status === 'review' || (last?.ask && !state.history.some((h) => h.kind === 'answer' && h.at > last.at)))) setPanel(true, false);
|
|
903
999
|
const fromHash = decodeURIComponent((location.hash.match(/page=([^&]+)/) || [])[1] || '');
|
|
@@ -918,6 +1014,7 @@
|
|
|
918
1014
|
else if (state.page && !state.pages.some((p) => p.page === state.page)) state.pages[0] ? go(state.pages[0].page) : showEmpty();
|
|
919
1015
|
} else if (d.type === 'changed') {
|
|
920
1016
|
const files = d.files || [];
|
|
1017
|
+
if (files.some((f) => !f || f.startsWith('assets/'))) $('tokensCss').href = `/__truemap/tokens.css?v=${Date.now()}`;
|
|
921
1018
|
if (state.page && files.some((f) => !f || f === state.page || f.startsWith('assets/'))) reloadFrame();
|
|
922
1019
|
} else if (d.type === 'check') {
|
|
923
1020
|
state.check = d.check || { results: [] }; renderHeader(); sendMarks(); if (!menu.hidden) renderMenu();
|
|
@@ -926,18 +1023,18 @@
|
|
|
926
1023
|
if (d.page && state.pages.some((p) => p.page === d.page)) go(d.page, { force: true });
|
|
927
1024
|
renderHeader();
|
|
928
1025
|
} else if (d.type === 'show') {
|
|
929
|
-
if (d.clear) toFrame({ type: 'clear-focus' });
|
|
1026
|
+
if (d.clear) { unpin(); toFrame({ type: 'clear-focus' }); }
|
|
930
1027
|
else pointAt(d.focus || [], d.note || '', AGENTS[d.agent] || agentName(), d.page);
|
|
931
1028
|
} else if (d.type === 'plan') {
|
|
932
|
-
|
|
1029
|
+
msgsEl.querySelector('li.lit')?.classList.remove('lit'); unpin();
|
|
933
1030
|
$('litPill').hidden = true; toFrame({ type: 'clear-focus' });
|
|
934
1031
|
state.plan = d.plan || null; renderPlan(); sendPlan(); renderNotes();
|
|
935
1032
|
} else if (d.type === 'changes-base') {
|
|
936
|
-
loadChanges();
|
|
937
1033
|
} else if (d.type === 'view') {
|
|
938
|
-
if (d.view === 'changes') {
|
|
1034
|
+
if (d.view === 'changes') { setPanel(true); scrollChat(); }
|
|
939
1035
|
} else if (d.type === 'closing') {
|
|
940
|
-
es.close();
|
|
1036
|
+
es.close();
|
|
1037
|
+
if (d.restart) setTimeout(connect, 700); else setConn('closed');
|
|
941
1038
|
}
|
|
942
1039
|
};
|
|
943
1040
|
}
|
|
@@ -948,7 +1045,10 @@
|
|
|
948
1045
|
if (state.pages.some((p) => p.page === page)) { if (state.page) to.push(state.page); nav.moving = true; go(page); return; }
|
|
949
1046
|
}
|
|
950
1047
|
}
|
|
951
|
-
$('crumbHome').onclick = () => go('index.html');
|
|
1048
|
+
$('crumbHome').onclick = () => { if (state.page !== 'index.html') go('index.html'); };
|
|
1049
|
+
$('navBack').onclick = () => navigate('back');
|
|
1050
|
+
$('navFwd').onclick = () => navigate('forward');
|
|
1051
|
+
function renderNav() { $('navBack').disabled = !nav.back.length; $('navFwd').disabled = !nav.fwd.length; }
|
|
952
1052
|
document.addEventListener('keydown', (e) => {
|
|
953
1053
|
if (e.altKey && (e.key === 'ArrowLeft' || e.key === 'ArrowRight')) { e.preventDefault(); navigate(e.key === 'ArrowLeft' ? 'back' : 'forward'); }
|
|
954
1054
|
});
|