truemap-cli 0.5.0 → 0.5.1
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 +3 -3
- package/kit/truemap.css +4 -0
- 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 +59 -8
- package/src/common.js +12 -1
- package/src/guide.md +28 -6
- package/src/plan.js +1 -1
- package/src/server.js +103 -25
- package/src/theme.js +46 -0
- package/src/ui/sdk.js +137 -20
- package/src/ui/workspace.css +39 -0
- package/src/ui/workspace.html +8 -6
- package/src/ui/workspace.js +109 -39
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'); }
|
|
@@ -157,6 +168,20 @@
|
|
|
157
168
|
$('endHint').textContent = talking ? `Lets ${agentName()} go back to the terminal` : 'No conversation is running';
|
|
158
169
|
}
|
|
159
170
|
const closeMore = () => { more.hidden = true; $('moreBtn').setAttribute('aria-expanded', 'false'); };
|
|
171
|
+
const renderTheme = () => {
|
|
172
|
+
const t = document.documentElement.getAttribute('data-theme') || '';
|
|
173
|
+
for (const b of document.querySelectorAll('[data-theme-pick]')) b.setAttribute('aria-pressed', String(b.dataset.themePick === t));
|
|
174
|
+
};
|
|
175
|
+
renderTheme();
|
|
176
|
+
for (const b of document.querySelectorAll('[data-theme-pick]')) {
|
|
177
|
+
b.onclick = () => {
|
|
178
|
+
const t = b.dataset.themePick;
|
|
179
|
+
if (t) document.documentElement.setAttribute('data-theme', t); else document.documentElement.removeAttribute('data-theme');
|
|
180
|
+
renderTheme();
|
|
181
|
+
toFrame({ type: 'theme', theme: t });
|
|
182
|
+
api('/api/prefs', { theme: t || 'system' });
|
|
183
|
+
};
|
|
184
|
+
}
|
|
160
185
|
$('moreBtn').onclick = (e) => {
|
|
161
186
|
e.stopPropagation();
|
|
162
187
|
if (!more.hidden) return closeMore();
|
|
@@ -177,12 +202,12 @@
|
|
|
177
202
|
|
|
178
203
|
function renderHeader() {
|
|
179
204
|
const p = state.pages.find((x) => x.page === state.page);
|
|
180
|
-
|
|
181
|
-
// The blueprint is always one click away.
|
|
205
|
+
// The map is always one click away; the switcher names the draft or page you are on, or offers the drafts.
|
|
182
206
|
const home = state.pages.find((x) => x.page === 'index.html');
|
|
183
|
-
const
|
|
184
|
-
$('crumbHome').hidden = !
|
|
185
|
-
|
|
207
|
+
const onMap = !state.page || state.page === 'index.html';
|
|
208
|
+
$('crumbHome').hidden = !home; $('crumbHome').classList.toggle('on', onMap);
|
|
209
|
+
const nDrafts = state.pages.filter(isDraft).length;
|
|
210
|
+
$('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
211
|
renderProjects();
|
|
187
212
|
const r = resultFor(state.page); const st = stateOf(r);
|
|
188
213
|
const chip = $('checkChip');
|
|
@@ -216,7 +241,7 @@
|
|
|
216
241
|
state.page = page;
|
|
217
242
|
history.replaceState(null, '', `${location.pathname}${location.search}#page=${encodeURIComponent(page)}`);
|
|
218
243
|
api('/api/viewing', { page });
|
|
219
|
-
renderHeader(); renderNotice(); renderNotes();
|
|
244
|
+
renderHeader(); renderNotice(); renderNotes(); renderNav();
|
|
220
245
|
}
|
|
221
246
|
function showEmpty() {
|
|
222
247
|
state.page = null; frame.hidden = true; frame.removeAttribute('src'); $('empty').hidden = false; renderHeader(); renderNotice();
|
|
@@ -259,16 +284,36 @@
|
|
|
259
284
|
function renderAll() {
|
|
260
285
|
msgsEl.innerHTML = ''; lastRole = null;
|
|
261
286
|
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
|
|
287
|
+
msgsEl.innerHTML = `<div class="intro"><p>Ask about anything on the page. <b>Click a box</b> to see what it is; <b>double-click</b> it to write a comment right there. Comments go out together, each with the code it points to.</p></div>`;
|
|
263
288
|
}
|
|
264
289
|
for (const e of state.history) appendEntry(e, false);
|
|
265
290
|
renderWorking();
|
|
266
291
|
scrollChat(); requestAnimationFrame(scrollChat); setTimeout(scrollChat, 300);
|
|
267
292
|
}
|
|
293
|
+
// What changed in a turn: one card in the conversation, badges on the map, the diff from the box.
|
|
294
|
+
function changesCard(c) {
|
|
295
|
+
const d = (a, x) => `<span class="delta">${[a ? `<span class="a">+${a}</span>` : '', x ? `<span class="d">−${x}</span>` : ''].filter(Boolean).join(' ') || '±0'}</span>`;
|
|
296
|
+
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
|
+
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
|
+
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>`;
|
|
300
|
+
}
|
|
301
|
+
let latestChanges = null;
|
|
302
|
+
function showChangeBadges() {
|
|
303
|
+
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
|
+
}
|
|
268
305
|
function appendEntry(e, scroll = true, live = false) {
|
|
269
306
|
msgsEl.querySelector('.intro')?.remove();
|
|
270
307
|
if (e.role !== lastRole) { msgsEl.appendChild(whoLine(e.role, e.at, e.agent)); lastRole = e.role; }
|
|
271
308
|
const el = document.createElement('div');
|
|
309
|
+
if (e.kind === 'changes' && e.changes) {
|
|
310
|
+
el.className = 'msg agent';
|
|
311
|
+
el.innerHTML = changesCard(e.changes);
|
|
312
|
+
latestChanges = e.changes; showChangeBadges();
|
|
313
|
+
msgsEl.appendChild(el); renderWorking(); if (scroll) scrollChat();
|
|
314
|
+
if (live && !panelOpen()) { state.unread = true; renderBadge(); }
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
272
317
|
if (e.role === 'agent') {
|
|
273
318
|
el.className = 'msg agent';
|
|
274
319
|
el.innerHTML = e.ask && e.text.trim() === e.ask.question.trim() ? '' : md(e.text);
|
|
@@ -316,6 +361,13 @@
|
|
|
316
361
|
});
|
|
317
362
|
msgsEl.addEventListener('mouseleave', () => { if (hoverLit && hoverLit !== '__pinned') { hoverLit = null; msgsEl.querySelector('li.lit')?.classList.remove('lit'); toFrame({ type: 'clear-focus' }); } });
|
|
318
363
|
msgsEl.addEventListener('click', (e) => {
|
|
364
|
+
const cc = e.target.closest('.cc-row');
|
|
365
|
+
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; }
|
|
366
|
+
if (e.target.closest('[data-act="map-these"]')) {
|
|
367
|
+
const files = [...e.target.closest('.cc').querySelectorAll('.cc-loose code')].map((c) => c.textContent);
|
|
368
|
+
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 });
|
|
369
|
+
return;
|
|
370
|
+
}
|
|
319
371
|
const ref = e.target.closest('[data-focus]');
|
|
320
372
|
if (ref) { e.preventDefault(); hoverLit = '__pinned'; pointAt(ref.dataset.focus.split(',').filter(Boolean), '', ''); return; }
|
|
321
373
|
const step = e.target.closest('li.has-ref');
|
|
@@ -410,8 +462,8 @@
|
|
|
410
462
|
inspBody.innerHTML = `
|
|
411
463
|
<div class="insp-name"><h2>${esc(box.label)}</h2>${box.tag ? `<code>${esc(box.tag)}</code>` : ''}</div>
|
|
412
464
|
${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>' : ''}
|
|
465
|
+
${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>` : ''}
|
|
466
|
+
${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
467
|
${unbuiltNote(box)}${changeSection(box)}
|
|
416
468
|
${detail ? `<div class="insp-detail">${detail}</div>` : ''}
|
|
417
469
|
${box.why ? `<div class="insp-why">${esc(box.why)}</div>` : ''}
|
|
@@ -515,7 +567,8 @@
|
|
|
515
567
|
if (!r) { el.innerHTML = '<p class="ch-empty">Reading the working tree…</p>'; return; }
|
|
516
568
|
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
569
|
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
|
-
|
|
570
|
+
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.' };
|
|
571
|
+
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
572
|
if (r.plan) {
|
|
520
573
|
const done = r.plan.planned.filter((p) => p.changed).length; const missing = r.plan.planned.filter((p) => !p.changed);
|
|
521
574
|
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 +661,10 @@
|
|
|
608
661
|
}
|
|
609
662
|
// The inspector shows what changed in a box while you review changes.
|
|
610
663
|
function changeSection(box) {
|
|
611
|
-
|
|
612
|
-
const b = ch.data.boxes.find((x) => x.src === box.src);
|
|
664
|
+
const b = latestChanges?.boxes?.find((x) => x.src === box.src);
|
|
613
665
|
if (!b) return '';
|
|
614
|
-
|
|
666
|
+
ch.data = { base: { kind: latestChanges.base, label: latestChanges.label } };
|
|
667
|
+
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
668
|
}
|
|
616
669
|
function wireChangeSection() {
|
|
617
670
|
for (const d of inspBody.querySelectorAll('.insp-change details')) {
|
|
@@ -619,7 +672,7 @@
|
|
|
619
672
|
d.addEventListener('toggle', load); load();
|
|
620
673
|
}
|
|
621
674
|
}
|
|
622
|
-
|
|
675
|
+
|
|
623
676
|
|
|
624
677
|
// ---------- plan review: the agent's plan on the map, approve or ask for changes ----------
|
|
625
678
|
// Requesting changes is a mode of the composer: a heading says so, Send sends the request (comments included).
|
|
@@ -645,11 +698,13 @@
|
|
|
645
698
|
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
699
|
const here = p.page === state.page;
|
|
647
700
|
const old = here && state.planUnsupported;
|
|
701
|
+
// on its own map the plan's buttons sit beside its boxes; the bar is only a way there (or for old pages)
|
|
702
|
+
if (here && !old) { planBar.hidden = true; planBar.innerHTML = ''; renderNotes(); return; }
|
|
648
703
|
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
704
|
if (p.status === 'review' && old) {
|
|
650
705
|
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
706
|
} else if (p.status === 'review') {
|
|
652
|
-
html +=
|
|
707
|
+
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
708
|
} else if (p.status === 'revise') {
|
|
654
709
|
html += `<div class="pb-acts"><span class="pb-wait">Waiting for the revised plan</span></div>`;
|
|
655
710
|
} else if (p.status === 'approved') {
|
|
@@ -664,7 +719,7 @@
|
|
|
664
719
|
const p = state.plan; if (!act || !p) return;
|
|
665
720
|
if (act === 'open') go(p.page);
|
|
666
721
|
else if (act === 'hide') { state.planHidden = `${p.slug}:${p.status}`; renderPlan(); }
|
|
667
|
-
else if (act === 'changes') {
|
|
722
|
+
else if (act === 'changes') { setPanel(true); scrollChat(); }
|
|
668
723
|
else if (act === 'request') { setPanel(true); setTab('convo'); setRequest(true); }
|
|
669
724
|
else if (act === 'approve') {
|
|
670
725
|
// comments written before approving still go to the agent, first
|
|
@@ -803,7 +858,7 @@
|
|
|
803
858
|
const broken = stale.filter((a) => a.state === 'broken').length;
|
|
804
859
|
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
860
|
setPanel(true); setTab('convo');
|
|
806
|
-
if (!input.value.trim()) { input.value = `
|
|
861
|
+
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(); }
|
|
807
862
|
input.focus();
|
|
808
863
|
};
|
|
809
864
|
|
|
@@ -812,7 +867,7 @@
|
|
|
812
867
|
const userIsInFrame = () => document.activeElement === frame && state.frameFocusAt > 0;
|
|
813
868
|
|
|
814
869
|
// ---------- messages from the page frame ----------
|
|
815
|
-
window.addEventListener('message', (e) => {
|
|
870
|
+
window.addEventListener('message', async (e) => {
|
|
816
871
|
if (e.source !== frame.contentWindow || e.origin !== CONTENT || !e.data || !e.data.__truemap) return;
|
|
817
872
|
const d = e.data;
|
|
818
873
|
if (d.type === 'press' || d.type === 'deselect') {
|
|
@@ -821,11 +876,13 @@
|
|
|
821
876
|
navigate(d.dir);
|
|
822
877
|
} else if (d.type === 'peek') {
|
|
823
878
|
if (d.box) openInspector(d.box);
|
|
879
|
+
} else if (d.type === 'peek-if-open') {
|
|
880
|
+
if (d.box && panelEl.classList.contains('inspecting')) openInspector(d.box);
|
|
824
881
|
} else if (d.type === 'loaded') {
|
|
825
882
|
if (d.page && d.page !== state.page) setCurrent(d.page);
|
|
826
883
|
closeInspector();
|
|
827
884
|
if (state.pendingFocus) { const pf = state.pendingFocus; state.pendingFocus = null; setTimeout(() => toFrame({ type: 'focus', note: '', who: agentName(), ...pf }), 60); }
|
|
828
|
-
renderHeader(); sendMarks();
|
|
885
|
+
renderHeader(); sendMarks(); showChangeBadges(); sendPlan(); renderPlan();
|
|
829
886
|
if (state.pendingOpen) { const src = state.pendingOpen; state.pendingOpen = null; setTimeout(() => toFrame({ type: 'open-box', src }), 80); }
|
|
830
887
|
syncFrameNotes();
|
|
831
888
|
const y = state.scroll[d.page]; if (y) toFrame({ type: 'scroll', y });
|
|
@@ -847,6 +904,13 @@
|
|
|
847
904
|
$('litText').textContent = n === 1 ? '1 box lit' : `${n} boxes lit`;
|
|
848
905
|
} else if (d.type === 'focus-cleared') {
|
|
849
906
|
$('litPill').hidden = true;
|
|
907
|
+
} else if (d.type === 'plan-act') {
|
|
908
|
+
if (d.act === 'approve') {
|
|
909
|
+
if (state.notes.length || input.value.trim()) { const t = input.value; input.value = ''; autosize(); await send(t, { approving: true }); }
|
|
910
|
+
await api('/api/plan', { action: 'approve' });
|
|
911
|
+
} else if (d.act === 'reject') {
|
|
912
|
+
await api('/api/plan', { action: 'reject' });
|
|
913
|
+
}
|
|
850
914
|
} else if (d.type === 'changes-names') {
|
|
851
915
|
for (const it of d.items || []) if (it && it.src) ch.names.set(String(it.src), String(it.name || '').slice(0, 80));
|
|
852
916
|
if (showingChanges()) renderChanges();
|
|
@@ -868,6 +932,7 @@
|
|
|
868
932
|
|
|
869
933
|
// ---------- live events from the server ----------
|
|
870
934
|
let closedTimer = null;
|
|
935
|
+
let loadedBuild = null;
|
|
871
936
|
function setConn(c) {
|
|
872
937
|
if (state.conn === c) return;
|
|
873
938
|
state.conn = c; app.dataset.conn = c;
|
|
@@ -887,6 +952,8 @@
|
|
|
887
952
|
let d; try { d = JSON.parse(ev.data); } catch { return; }
|
|
888
953
|
if (d.type === 'hello') {
|
|
889
954
|
greeted = true; clearTimeout(guard); clearTimeout(closedTimer); closedTimer = null;
|
|
955
|
+
if (d.build && loadedBuild && d.build !== loadedBuild) { es.close(); location.reload(); return; }
|
|
956
|
+
loadedBuild = d.build || loadedBuild;
|
|
890
957
|
setConn('live');
|
|
891
958
|
state.pages = d.pages || []; state.check = d.check || { results: [] }; state.history = d.history || [];
|
|
892
959
|
state.pending = new Set(d.pending || []);
|
|
@@ -897,7 +964,7 @@
|
|
|
897
964
|
$('project').textContent = String(d.root || '').split(/[\\/]/).filter(Boolean).pop() || '';
|
|
898
965
|
state.agent = { state: d.agent?.state || 'offline', name: d.agent?.name || '', since: d.agent?.since || 0 };
|
|
899
966
|
state.plan = d.plan || null;
|
|
900
|
-
renderAll(); renderAgent(); renderNotes();
|
|
967
|
+
renderAll(); renderAgent(); renderNotes(); renderPlan();
|
|
901
968
|
const last = [...state.history].reverse().find((h) => h.role === 'agent');
|
|
902
969
|
if (!panelOpen() && !narrow() && (state.plan?.status === 'review' || (last?.ask && !state.history.some((h) => h.kind === 'answer' && h.at > last.at)))) setPanel(true, false);
|
|
903
970
|
const fromHash = decodeURIComponent((location.hash.match(/page=([^&]+)/) || [])[1] || '');
|
|
@@ -933,11 +1000,11 @@
|
|
|
933
1000
|
$('litPill').hidden = true; toFrame({ type: 'clear-focus' });
|
|
934
1001
|
state.plan = d.plan || null; renderPlan(); sendPlan(); renderNotes();
|
|
935
1002
|
} else if (d.type === 'changes-base') {
|
|
936
|
-
loadChanges();
|
|
937
1003
|
} else if (d.type === 'view') {
|
|
938
|
-
if (d.view === 'changes') {
|
|
1004
|
+
if (d.view === 'changes') { setPanel(true); scrollChat(); }
|
|
939
1005
|
} else if (d.type === 'closing') {
|
|
940
|
-
es.close();
|
|
1006
|
+
es.close();
|
|
1007
|
+
if (d.restart) setTimeout(connect, 700); else setConn('closed');
|
|
941
1008
|
}
|
|
942
1009
|
};
|
|
943
1010
|
}
|
|
@@ -948,7 +1015,10 @@
|
|
|
948
1015
|
if (state.pages.some((p) => p.page === page)) { if (state.page) to.push(state.page); nav.moving = true; go(page); return; }
|
|
949
1016
|
}
|
|
950
1017
|
}
|
|
951
|
-
$('crumbHome').onclick = () => go('index.html');
|
|
1018
|
+
$('crumbHome').onclick = () => { if (state.page !== 'index.html') go('index.html'); };
|
|
1019
|
+
$('navBack').onclick = () => navigate('back');
|
|
1020
|
+
$('navFwd').onclick = () => navigate('forward');
|
|
1021
|
+
function renderNav() { $('navBack').disabled = !nav.back.length; $('navFwd').disabled = !nav.fwd.length; }
|
|
952
1022
|
document.addEventListener('keydown', (e) => {
|
|
953
1023
|
if (e.altKey && (e.key === 'ArrowLeft' || e.key === 'ArrowRight')) { e.preventDefault(); navigate(e.key === 'ArrowLeft' ? 'back' : 'forward'); }
|
|
954
1024
|
});
|