create-pmos 0.396.0 → 0.398.0
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/package.json +25 -25
- package/payload/KIT-VERSION +2 -2
- package/payload/planning/evals/eval-calibration.md +1 -1
- package/payload/planning/okrs/health-budgets.md +1 -1
- package/payload/scripts/nine-stages.js +49 -20
- package/payload/state/discoveries.md +1 -1
- package/payload/state/log.md +1 -1
- package/workspace/briefing-premium-adddoc-test.js +103 -74
- package/workspace/briefing-premium-board-test.js +316 -154
- package/workspace/briefing-premium-calendar-2-test.js +135 -195
- package/workspace/briefing-premium-calendar-3-test.js +143 -413
- package/workspace/briefing-premium-calendar-test.js +86 -185
- package/workspace/briefing-premium-doc-edit-test.js +95 -83
- package/workspace/briefing-premium-initiative-test.js +166 -294
- package/workspace/briefing-premium-insights-test.js +351 -214
- package/workspace/briefing-premium-metrics-test.js +53 -118
- package/workspace/briefing-premium-products-test.js +40 -27
- package/workspace/briefing-premium-sources-test.js +91 -52
- package/workspace/briefing-premium-test.js +150 -633
- package/workspace/briefing-premium-work-test.js +88 -269
- package/workspace/changelog.json +24 -0
- package/workspace/fixtures/board-premium-facts.js +2 -1
- package/workspace/fixtures/board-premium-jira.js +28 -0
- package/workspace/fixtures/board-premium-trail.js +32 -0
- package/workspace/fixtures/initiative-premium-facts.js +2 -1
- package/workspace/fixtures/initiatives-api/list.json +30 -42
- package/workspace/fixtures/initiatives-api/roadmap.json +40 -56
- package/workspace/fixtures/initiatives-api/sheet.json +10 -14
- package/workspace/fixtures/insights-premium-facts.js +11 -2
- package/workspace/fixtures/premium-viewer-fixtures.js +182 -0
- package/workspace/guide/briefing-premium.md +3 -1
- package/workspace/guide/home.md +47 -0
- package/workspace/guide/index.md +2 -0
- package/workspace/guide/lifecycle.md +51 -0
- package/workspace/home-shot.js +38 -0
- package/workspace/lib/agent-roles.js +71 -0
- package/workspace/lib/board-premium.js +160 -3
- package/workspace/lib/board-trail.js +223 -0
- package/workspace/lib/engine/boards.js +15 -14
- package/workspace/lib/engine/nine-stages.js +49 -20
- package/workspace/lib/engine/signals/detectors.js +13 -11
- package/workspace/lib/home-work-item.js +58 -0
- package/workspace/lib/insights-goals.js +196 -0
- package/workspace/lib/insights-premium.js +126 -1
- package/workspace/lib/insights-records.js +101 -0
- package/workspace/lib/jira-tickets.js +1 -1
- package/workspace/lib/route-modules.js +4 -0
- package/workspace/lib/routes-board-premium.js +3 -2
- package/workspace/lib/routes-board-trail.js +33 -0
- package/workspace/lib/routes-home-desk.js +176 -0
- package/workspace/lib/routes-initiatives.js +1 -1
- package/workspace/lib/routes-insights-premium.js +19 -3
- package/workspace/lib/routes-insights-records.js +129 -0
- package/workspace/lib/routes-notes.js +1 -0
- package/workspace/lib/routes-viewer.js +108 -0
- package/workspace/lib/transcript-steps.js +123 -0
- package/workspace/lib/vendor/scripts/nine-stages.js +49 -20
- package/workspace/lib/viewer-meeting.js +205 -0
- package/workspace/lib/viewer-report.js +89 -0
- package/workspace/package-lock.json +2 -2
- package/workspace/package.json +1 -1
- package/workspace/premium-agreed-viewer-shots.js +76 -0
- package/workspace/premium-board-actions-test.js +85 -73
- package/workspace/premium-briefing-depth-test.js +66 -53
- package/workspace/premium-chat-attach-test.js +54 -63
- package/workspace/premium-chat-chart-tab-test.js +35 -36
- package/workspace/premium-chat-context-test.js +22 -19
- package/workspace/premium-chat-goal-view-test.js +28 -26
- package/workspace/premium-chat-notes-test.js +29 -33
- package/workspace/premium-chat-report-tab-test.js +35 -25
- package/workspace/premium-chat-term-test.js +16 -14
- package/workspace/premium-chat-viewer-test.js +60 -53
- package/workspace/premium-core-doc-issue-test.js +50 -41
- package/workspace/premium-html-viewer-test.js +17 -18
- package/workspace/premium-phone-card-test.js +8 -2
- package/workspace/premium-phone-room-test.js +42 -31
- package/workspace/premium-report-read-test.js +115 -197
- package/workspace/premium-viewer-download-test.js +19 -22
- package/workspace/premium-viewer-flicker-test.js +11 -16
- package/workspace/premium-viewer-share-test.js +6 -9
- package/workspace/premium-viewer-test.js +41 -60
- package/workspace/premium-vw-backlog-test.js +53 -31
- package/workspace/premium-vw-cal-test.js +82 -123
- package/workspace/premium-vw-copy-test.js +17 -33
- package/workspace/premium-vw-doc-test.js +12 -11
- package/workspace/premium-vw-item-test.js +50 -48
- package/workspace/premium-vw-jira-test.js +55 -26
- package/workspace/premium-vw-meet-test.js +118 -187
- package/workspace/premium-vw-notes-test.js +85 -107
- package/workspace/premium-vw-rec-test.js +72 -193
- package/workspace/premium-vw-slides-test.js +46 -50
- package/workspace/premium-welcome-test.js +3 -2
- package/workspace/premium-work-depth-test.js +63 -51
- package/workspace/public/pm/bd-acts.js +305 -0
- package/workspace/public/pm/bd-span.js +224 -0
- package/workspace/public/pm/bd-stages.js +47 -0
- package/workspace/public/pm/c3-doc-sheet.js +1 -1
- package/workspace/public/pm/c3-md.js +3 -395
- package/workspace/public/pm/c3-phone-detail.js +1 -1
- package/workspace/public/pm/c3-phone-model.js +3 -68
- package/workspace/public/pm/chat-term.js +3 -3
- package/workspace/public/pm/cozy-board.css +640 -0
- package/workspace/public/pm/cozy-home.css +580 -0
- package/workspace/public/pm/cozy-home.js +172 -0
- package/workspace/public/pm/cozy-initiative.css +138 -0
- package/workspace/public/pm/cozy-insights.css +421 -0
- package/workspace/public/pm/cozy-md.js +396 -0
- package/workspace/public/pm/cozy-nav.js +65 -0
- package/workspace/public/pm/cozy-placeholder.js +26 -0
- package/workspace/public/pm/cozy-viewer.css +143 -0
- package/workspace/public/pm/cozy-viewer.js +144 -0
- package/workspace/public/pm/cozy-vw.css +485 -0
- package/workspace/public/pm/cozy.css +254 -0
- package/workspace/public/pm/home-adddoc.js +48 -0
- package/workspace/public/pm/home-app.js +905 -0
- package/workspace/public/pm/home-around.js +515 -0
- package/workspace/public/pm/home-chat.js +459 -0
- package/workspace/public/pm/home-data.js +312 -0
- package/workspace/public/pm/home-draft.js +68 -0
- package/workspace/public/pm/home-more.js +249 -0
- package/workspace/public/pm/home-phone-card.js +109 -0
- package/workspace/public/pm/home-work.js +519 -0
- package/workspace/public/pm/lifecycle-lens-model.js +45 -27
- package/workspace/public/pm/lifecycle-lens.js +22 -11
- package/workspace/public/pm/phone-moment.js +69 -0
- package/workspace/public/pm/pm-work-view.js +1 -1
- package/workspace/public/pm/premium-attach.js +4 -0
- package/workspace/public/pm/premium-board.js +544 -253
- package/workspace/public/pm/premium-brief.js +1 -1
- package/workspace/public/pm/premium-chart-tab.js +110 -62
- package/workspace/public/pm/premium-chat.js +17 -10
- package/workspace/public/pm/premium-deck.js +3 -3
- package/workspace/public/pm/premium-first.js +25 -21
- package/workspace/public/pm/premium-initiative-head.js +138 -0
- package/workspace/public/pm/premium-initiative.js +28 -4
- package/workspace/public/pm/premium-insights.js +950 -440
- package/workspace/public/pm/premium-meeting.js +61 -549
- package/workspace/public/pm/premium-notes.js +1 -1
- package/workspace/public/pm/premium-report-frame.css +20 -0
- package/workspace/public/pm/premium-report-read.js +509 -480
- package/workspace/public/pm/premium-report-tab.js +87 -63
- package/workspace/public/pm/premium-shell.js +107 -124
- package/workspace/public/pm/premium-viewer.js +27 -1
- package/workspace/public/pm/premium-vw-cal.js +187 -48
- package/workspace/public/pm/premium-vw-doc.css +6 -0
- package/workspace/public/pm/premium-vw-doc.js +40 -2
- package/workspace/public/pm/premium-vw-file.js +2 -2
- package/workspace/public/pm/premium-vw-jira-model.js +22 -5
- package/workspace/public/pm/premium-vw-jira.css +11 -0
- package/workspace/public/pm/premium-vw-jira.js +11 -4
- package/workspace/public/pm/premium-vw-meet.js +6 -83
- package/workspace/public/pm/premium-vw-mtg.js +731 -0
- package/workspace/public/pm/premium-vw-notes.js +56 -69
- package/workspace/public/pm/premium-vw-open.js +35 -0
- package/workspace/public/pm/premium-vw-page.js +16 -0
- package/workspace/public/pm/premium-vw-rec.js +11 -215
- package/workspace/public/pm/premium-vw-slides.css +5 -0
- package/workspace/public/pm/premium-vw-slides.js +44 -8
- package/workspace/public/pm/term-view.js +22 -0
- package/workspace/public/premium-board.html +57 -64
- package/workspace/public/premium-chat.html +7 -33
- package/workspace/public/premium-initiative.html +8 -41
- package/workspace/public/premium-insights.html +63 -62
- package/workspace/public/premium-viewer.html +20 -0
- package/workspace/public/premium-work.html +6 -72
- package/workspace/public/premium.html +21 -66
- package/workspace/public/vendor/nunito-var.woff2 +0 -0
- package/workspace/server.js +25 -3
- package/workspace/test-files.json +1 -0
- package/workspace/test-lists/home-libs.json +9 -0
- package/workspace/test-lists/premium-agreed-viewer.json +9 -0
- package/workspace/test-lists/premium-report-read.json +1 -1
- package/workspace/test-lists/premium-vw-agreed.json +9 -0
- package/workspace/test-lists/premium-vw-notes.json +1 -1
- package/workspace/third-party/README.md +1 -0
- package/workspace/public/pm/premium-work.js +0 -719
- package/workspace/public/pm/premium.js +0 -1133
|
@@ -0,0 +1,459 @@
|
|
|
1
|
+
/* pm/home-chat.js — Home's chat column (initiative premium-agreed-design, Home; mockup Main.dc.html section "Conversation", AgChat*).
|
|
2
|
+
*
|
|
3
|
+
* No header on the docked desk. The stream: the role's avatar and name over each agent message with Copy, Retry and Make a work-item; the
|
|
4
|
+
* PM's bubbles with "You · HH:MM"; "Worked …" folds (under the message that asks, while it asks); a Today divider; "New since you left"; "N earlier messages · show"; the agent's step
|
|
5
|
+
* checklist while it works (from its own TodoWrite list); a permission card with the change before → after, Allow and Deny. Over the box: the
|
|
6
|
+
* run strip with Stop, and "Also waiting on you". Two boxes: the basic one on Home (In: chip above, → send, the hint under it) and the rich
|
|
7
|
+
* one in an initiative (+, /, @, the In:/To: chip, the key hint, ↑ send). The + menu holds Attach a file, and the Notes and the terminal of
|
|
8
|
+
* the conversation (not in the design yet: marked Waiting for design).
|
|
9
|
+
*
|
|
10
|
+
* The words are Claude Code's own transcript. A conversation is either a chat key (GET /api/briefing-premium/thread?key=, the session it
|
|
11
|
+
* started, POST /ask and /press) or a session with no chat key (GET /api/sessions/conversation?id=, POST /api/session/say and /keys).
|
|
12
|
+
* Every write is the PM's press. mountChat(el, host) returns { open(target), refresh(), focus(), send(text) }.
|
|
13
|
+
* target: { key?, sid?, title, scope: { text, icon, loose }, role: { name, initial }, intro?: { role, text, at, pills: [{ label, primary, go }] },
|
|
14
|
+
* ini?, rich, also?: { text, go } }
|
|
15
|
+
* host: { esc, toast, pmGet, pmPost, roles(), seen(key), markSeen(key), onScope(btn), onLink(btn), onTo(btn), workItem(text, target),
|
|
16
|
+
* viewerClosed(), reopenViewer() } */
|
|
17
|
+
import { mdHtml, userHtml, toolLine, webKind } from './chat-md.js';
|
|
18
|
+
import { streamOf, runOf, roleOf, tintOf, hm } from './home-data.js';
|
|
19
|
+
import { splitGoal, shownUser, goalBlockHtml, goalProgressHtml, goalChipHtml, goalViewHtml, goalNow, slashMatches } from './goal-chat.js';
|
|
20
|
+
import { splitReport, reportChipHtml, blockSig } from './report-chat.js';
|
|
21
|
+
import { turnsOf } from './chat-context.js';
|
|
22
|
+
import { askCardHtml, answerText } from './chat-ask.js';
|
|
23
|
+
import { splitFiles, filesHtml, sizeText, MAX_BYTES, MAX_FILES, setAttachSink } from './premium-attach.js';
|
|
24
|
+
import * as VWC from './cozy-viewer.js';
|
|
25
|
+
/* The views a chat opens go in the Viewer: on a page with no dialog the old viewer's views draw in the cozy card (premium-viewer.js). */
|
|
26
|
+
const views = {
|
|
27
|
+
ctx: () => import('./premium-vw-ctx.js'), file: () => import('./premium-vw-file.js'), attach: () => import('./premium-attach.js'),
|
|
28
|
+
block: (b) => (b.kind === 'report' ? import('./premium-report-tab.js').then((M) => M.openReportTab(b)) : import('./premium-chart-tab.js').then((M) => M.openChartTab(b))),
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const SVG = (d, w = 16, sw = 2) => `<svg aria-hidden="true" width="${w}" height="${w}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="${sw}" stroke-linecap="round" stroke-linejoin="round"><path d="${d}"/></svg>`;
|
|
32
|
+
const CHEV = 'M9 6l6 6-6 6', ARROW = 'M5 12h14M13 6l6 6-6 6', UP = 'M12 19V5M6 11l6-6 6 6', PLUS = 'M12 5v14M5 12h14', DOWN = 'M6 9l6 6 6-6';
|
|
33
|
+
const PANE = '<svg aria-hidden="true" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"><rect x="3" y="4" width="18" height="16" rx="3"></rect><path d="M14 4v16"></path></svg>';
|
|
34
|
+
const DOTS = '<svg aria-hidden="true" width="16" height="16" viewBox="0 0 24 24" fill="currentColor"><circle cx="5" cy="12" r="1.8"/><circle cx="12" cy="12" r="1.8"/><circle cx="19" cy="12" r="1.8"/></svg>';
|
|
35
|
+
const INTERRUPT = /^\[Request interrupted by user/;
|
|
36
|
+
const POLL = 2000, IDLE_POLL = 9000;
|
|
37
|
+
|
|
38
|
+
export function avHtml(role, size = 28, cls = '') {
|
|
39
|
+
const k = (role && role.initial) || 'C';
|
|
40
|
+
return `<span class="hm-av t-${tintOf(k)} s${size}${k.length > 1 ? ' two' : ''}${cls ? ' ' + cls : ''}" aria-hidden="true">${k}</span>`;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function mountChat(el, host) {
|
|
44
|
+
const esc = host.esc;
|
|
45
|
+
const C = { t: null, th: null, conv: null, timer: null, show: 12, open: new Set(), seq: 0, sending: false, files: [], seenAt: null, lastKey: null, picked: {}, auto: { key: null, ctx: new Set(), rep: null, goal: null }, slashAt: 0 };
|
|
46
|
+
el.innerHTML = `<button type="button" class="hm-reopen" id="hmReopen" aria-label="Open the Viewer" title="Open the Viewer" hidden>${PANE}</button>`
|
|
47
|
+
+ '<div class="hm-log" id="hmLog" role="log" aria-live="polite"></div><div class="hm-foot" id="hmFoot"></div>';
|
|
48
|
+
const log = el.querySelector('#hmLog'), foot = el.querySelector('#hmFoot'), reopen = el.querySelector('#hmReopen');
|
|
49
|
+
reopen.onclick = () => host.reopenViewer();
|
|
50
|
+
// the foot's height, for the place menu's button on a phone: it sits just above the box and its bars (cozy-home.css --hm-foot-h)
|
|
51
|
+
if (typeof ResizeObserver === 'function') new ResizeObserver(() => document.body.style.setProperty('--bd-hmfoot', Math.round(foot.getBoundingClientRect().height) + 'px')).observe(foot);
|
|
52
|
+
|
|
53
|
+
const role = () => (C.t && C.t.role) || roleOf(C.sess || null, host.roles(), firstUser());
|
|
54
|
+
const firstUser = () => { const m = ((C.conv && C.conv.messages) || []).find((x) => x.role === 'user'); return m ? m.text : ''; };
|
|
55
|
+
const running = () => !!C.conv && (C.conv.turn === 'agent' || C.conv.turn === 'tool') && C.conv.state !== 'ended';
|
|
56
|
+
|
|
57
|
+
/* ── reading ── */
|
|
58
|
+
async function read() {
|
|
59
|
+
const t = C.t; if (!t) return;
|
|
60
|
+
const my = ++C.seq;
|
|
61
|
+
let th = null, conv = null;
|
|
62
|
+
if (t.key) {
|
|
63
|
+
th = await host.pmGet('/api/briefing-premium/thread?key=' + encodeURIComponent(t.key) + (t.ws ? '&ws=' + encodeURIComponent(t.ws) : '')).catch(() => null);
|
|
64
|
+
if (th && th.ok && th.session) conv = await host.pmGet('/api/sessions/conversation?id=' + encodeURIComponent(th.session)).catch(() => null);
|
|
65
|
+
else if (th && th.ok && th.history && (th.history.messages || []).length) conv = { ok: true, state: 'ended', messages: th.history.messages };
|
|
66
|
+
} else if (t.sid) conv = await host.pmGet('/api/sessions/conversation?id=' + encodeURIComponent(t.sid)).catch(() => null);
|
|
67
|
+
if (my !== C.seq || C.t !== t) return;
|
|
68
|
+
C.th = th && th.ok ? th : null; C.conv = conv && conv.ok ? conv : null;
|
|
69
|
+
C.sess = host.session ? host.session(t.sid || (C.th && C.th.session)) : null;
|
|
70
|
+
draw();
|
|
71
|
+
clearTimeout(C.timer);
|
|
72
|
+
const live = (C.th && (C.th.session || C.th.working)) || (t.sid && C.conv && C.conv.state !== 'ended');
|
|
73
|
+
C.timer = setTimeout(() => { if (!document.hidden) read(); else C.timer = setTimeout(read, IDLE_POLL); }, live ? POLL : IDLE_POLL);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/* ── drawing ── */
|
|
77
|
+
const put = (node, html) => { if (node.__h === html) return; node.__h = html; node.innerHTML = html; };
|
|
78
|
+
function msgHtml(it, i, R) {
|
|
79
|
+
if (it.t === 'fold') return `<button type="button" class="hm-fold" data-hm-fold>${esc(it.text)}</button>`;
|
|
80
|
+
if (it.t === 'day') return `<div class="hm-day" role="separator"><span></span>${esc(it.text)}<span></span></div>`;
|
|
81
|
+
if (it.t === 'since') return `<div class="hm-since" role="separator"><span></span>${esc(it.text)}<span></span></div>`;
|
|
82
|
+
if (it.t === 'user') {
|
|
83
|
+
if (INTERRUPT.test(it.text)) return '<p class="hm-stopped">Stopped</p>';
|
|
84
|
+
const a = splitFiles(shownUser(it.text));
|
|
85
|
+
return `<div class="hm-u"><div class="hm-bub">${filesHtml(a.files)}${a.text ? userHtml(a.text) : ''}</div>${it.at ? `<span class="hm-you">You · ${esc(hm(it.at))}</span>` : ''}</div>`;
|
|
86
|
+
}
|
|
87
|
+
if (it.t === 'worked') {
|
|
88
|
+
const id = 'w' + i, on = C.open.has(id);
|
|
89
|
+
const what = toolLine(it.tools).replace(/^Used /, '');
|
|
90
|
+
return `<div class="hm-worked"><button type="button" class="hm-wk" data-hm-wk="${id}" aria-expanded="${on}">${SVG(CHEV, 12, 2.4)}<span>Worked${it.took ? ' ' + esc(it.took) : ''}${what ? ' · ' + esc(what) : ''}</span></button>`
|
|
91
|
+
+ (on ? `<ol class="hm-calls">${it.calls.slice(0, 40).map((c) => `<li><b>${esc(c.tool.split(/__|\//).pop())}</b><code>${esc(c.target || '')}</code></li>`).join('')}</ol>` : '') + '</div>'
|
|
92
|
+
+ (it.ask ? askHtmlOf(it, R) : '');
|
|
93
|
+
}
|
|
94
|
+
const last = i === R.lastAgent;
|
|
95
|
+
const asking = last && R.asking; // the message that asks before a change: no tools while the ask is open, and the name on its own line (AgChatAsk)
|
|
96
|
+
const g = splitGoal(it.text), rp = splitReport(g.text);
|
|
97
|
+
const goal = C.th && C.th.goal, gl = it.mi === R.lastMsg && R.waiting && !!goal && goal.state === 'grilling';
|
|
98
|
+
return `<div class="hm-a${asking ? ' ask' : ''}">${avHtml(R.role)}<div class="hm-ab"><p class="hm-who">${esc(R.role.name)} <span>${esc(hm(it.at))}</span></p>${rp.text ? mdHtml(rp.text) : ''}${goalBlockHtml(g.block, { live: gl, state: goal && goal.state })}${reportChipHtml(rp.block, it.mi)}${R.chips(it.mi)}`
|
|
99
|
+
+ (asking ? '' : `<div class="hm-tools" role="group" aria-label="Message actions"><button type="button" data-hm-copy="${i}">Copy</button>${last && !running() ? `<button type="button" data-hm-retry>Retry</button>` : ''}<button type="button" data-hm-wi="${i}">Make a work-item</button></div>`) + '</div></div>';
|
|
100
|
+
}
|
|
101
|
+
function introHtml(o) {
|
|
102
|
+
if (!o) return '';
|
|
103
|
+
const r = o.role || { name: 'Claude', initial: 'C' };
|
|
104
|
+
return `<div class="hm-a">${avHtml(r)}<div class="hm-ab"><p class="hm-who"><b>${esc(r.name)}</b> <span class="hm-say">${esc(o.text)}</span></p></div></div>`
|
|
105
|
+
+ (o.pills && o.pills.length ? `<div class="hm-pills">${o.pills.map((p, i) => `<button type="button" class="${p.primary ? 'pri' : ''}" data-hm-pill="${i}"${p.disabled ? ' disabled' : ''}>${esc(p.label)}</button>`).join('')}</div>` : '');
|
|
106
|
+
}
|
|
107
|
+
/** Claude's question card (AskUserQuestion), answerable until the PM writes again. */
|
|
108
|
+
function askHtmlOf(it, R) {
|
|
109
|
+
const msgs = (C.conv && C.conv.messages) || [];
|
|
110
|
+
const live = !!C.t.key && C.conv && C.conv.state !== 'ended' && !msgs.slice(it.mi + 1).some((x) => x.role === 'user');
|
|
111
|
+
const at = askId(it.askMsg);
|
|
112
|
+
return `<div class="hm-a hm-askc">${avHtml(R.role)}<div class="hm-ab"><div class="tc">${askCardHtml(it.ask, { live, picked: live ? (C.picked[at] || {}) : {}, at })}</div></div></div>`;
|
|
113
|
+
}
|
|
114
|
+
function liveHtml(R) {
|
|
115
|
+
const run = runOf(C.conv, R.role);
|
|
116
|
+
if (!run || !run.steps) return '';
|
|
117
|
+
return `<div class="hm-live">${avHtml(R.role, 28, 'run')}<div class="hm-lb"><p class="hm-who">${esc(R.role.name)} <span>working${run.clock ? ' for ' + esc(run.clock) : ''} · ${esc(run.title)}</span></p>`
|
|
118
|
+
+ `<ol class="hm-steps">${run.steps.map((s) => { const call = s.call || (s.state === 'now' ? lastCall() : ''); return `<li class="${s.state}"><i aria-hidden="true"></i><span>${esc(s.text)}${s.sub ? `<small>${esc(s.sub)}</small>` : ''}${call ? `<code>${esc(call)}</code>` : ''}</span></li>`; }).join('')}</ol>`
|
|
119
|
+
+ `<button type="button" class="hm-watch" data-hm-term>Watch its terminal</button></div></div>`;
|
|
120
|
+
}
|
|
121
|
+
/** The newest tool call of the turn that runs now ("Read · planning/sprint.md"), for the step that is current when the session's step has none. */
|
|
122
|
+
function lastCall() {
|
|
123
|
+
const ms = (C.conv && C.conv.messages) || [];
|
|
124
|
+
for (let i = ms.length - 1; i >= 0; i--) {
|
|
125
|
+
if (ms[i].role === 'user') return '';
|
|
126
|
+
const c = ms[i].role === 'tool' && (ms[i].calls || []).slice(-1)[0];
|
|
127
|
+
if (c) return String(c.tool || '').split(/__|\//).pop() + (c.target ? ' ' + c.target : '');
|
|
128
|
+
}
|
|
129
|
+
return '';
|
|
130
|
+
}
|
|
131
|
+
function askHtml(R) {
|
|
132
|
+
const c = C.conv; if (!c || c.state === 'ended' || !c.ask) return '';
|
|
133
|
+
const opts = c.ask.options || [];
|
|
134
|
+
const deny = opts.find((o) => /^no\b/i.test(o.label)) || opts[opts.length - 1];
|
|
135
|
+
const allow = opts[0];
|
|
136
|
+
const more = opts.filter((o) => o !== allow && o !== deny);
|
|
137
|
+
const ch = c.change;
|
|
138
|
+
const body = ch ? `<span class="hm-chg"><span class="k">Change in ${esc(ch.system)}</span><b>${esc(ch.what)}</b>${ch.from || ch.to ? `<span class="ft">${ch.from ? `<s>${esc(ch.from)}</s>${SVG('M5 12h14M13 6l6 6-6 6', 14)}` : ''}<b>${esc(ch.to)}</b></span>` : ''}</span>`
|
|
139
|
+
: `<span class="hm-chg"><span class="k">Asks before it goes on</span><b>${esc(c.ask.question)}</b></span>`;
|
|
140
|
+
// part of the agent's last message: no avatar of its own, in line with the message text (AgChatAsk)
|
|
141
|
+
return `<div class="hm-askw" role="group" aria-label="${esc(R.role.name)} asks before it goes on"><div class="hm-ab"><div class="hm-perm">${body}`
|
|
142
|
+
+ `<span class="hm-pa"><button type="button" class="pri" data-hm-press="${esc(allow.n)}">Allow</button><button type="button" data-hm-press="${esc(deny.n)}">Deny</button><span class="sp"></span>`
|
|
143
|
+
+ (more.length ? `<span class="hm-mw"><button type="button" class="hm-dots" data-hm-pmore aria-haspopup="menu" aria-label="More choices: ${esc(more.map((o) => o.label).join(', '))}" title="${esc(more.map((o) => o.label).join(' · '))}">${DOTS}</button><span class="hm-pmenu" role="menu" hidden>${more.map((o) => `<button type="button" role="menuitem" data-hm-press="${esc(o.n)}">${esc(o.label)}</button>`).join('')}</span></span>` : '')
|
|
144
|
+
+ '</span></div></div></div>';
|
|
145
|
+
}
|
|
146
|
+
function queuedHtml() {
|
|
147
|
+
const q = host.queued ? host.queued(sid()) : [];
|
|
148
|
+
const said = new Set(((C.conv && C.conv.messages) || []).filter((m) => m.role === 'user').map((m) => String(m.text || '').trim()));
|
|
149
|
+
return q.filter((x) => !said.has(String(x.text).trim())).map((x) => `<div class="hm-q"><div class="hm-qb">${userHtml(x.text)}</div><span class="hm-qn">Queued · ${esc(role().name)} reads it after this step<button type="button" data-hm-qdel="${esc(x.at)}">Delete</button></span></div>`).join('');
|
|
150
|
+
}
|
|
151
|
+
const sid = () => (C.t && C.t.sid) || (C.th && C.th.session) || null;
|
|
152
|
+
function draw() {
|
|
153
|
+
const t = C.t; if (!t) return;
|
|
154
|
+
const R = { role: role() };
|
|
155
|
+
const msgs = (C.conv && C.conv.messages) || [];
|
|
156
|
+
const items = streamOf(msgs, { seen: C.seenAt, show: C.show });
|
|
157
|
+
R.lastAgent = -1; items.forEach((it, i) => { if (it.t === 'agent') R.lastAgent = i; });
|
|
158
|
+
R.asking = !!(C.conv && C.conv.state !== 'ended' && C.conv.ask);
|
|
159
|
+
// while it asks, the "Worked …" line of its turn sits under the message that asks, over the permission card (AgChatAsk)
|
|
160
|
+
const la = R.lastAgent;
|
|
161
|
+
if (R.asking && la > 0 && items[la - 1].t === 'worked' && !items[la - 1].ask) { const w = items[la - 1]; items[la - 1] = items[la]; items[la] = w; R.lastAgent = la - 1; }
|
|
162
|
+
R.lastMsg = msgs.length - 1;
|
|
163
|
+
R.waiting = !!C.conv && !C.conv.ask && C.conv.turn !== 'agent' && C.conv.turn !== 'tool';
|
|
164
|
+
const ctx = new Map(turnsOf(msgs, R.waiting || (C.conv && C.conv.state === 'ended')).filter((x) => x.done).map((x) => [x.at, x.items]));
|
|
165
|
+
R.chips = (mi) => (ctx.get(mi) ? chipsOf(ctx.get(mi)) : '');
|
|
166
|
+
const atEnd = log.scrollHeight - log.scrollTop - log.clientHeight < 80;
|
|
167
|
+
const goal = C.th && C.th.goal;
|
|
168
|
+
let html = (t.intro && !(t.intro.onlyEmpty && items.length) ? introHtml(t.intro) : '') + items.map((it, i) => msgHtml(it, i, R)).join('') + (goalProgressHtml(goal) ? goalChipHtml(goal) : '') + liveHtml(R) + askHtml(R) + queuedHtml();
|
|
169
|
+
if (C.th && C.th.working) html += `<p class="hm-note" role="status">The agent is answering. You can write again when it has.</p>`;
|
|
170
|
+
if (C.conv && C.conv.state === 'ended') html += '<p class="hm-note">This session has ended. Your conversation is kept here, and your next message picks it up.</p>';
|
|
171
|
+
if (!html) html = `<p class="hm-empty">${esc(t.empty || 'Ask anything. It works in a real Claude Code session.')}</p>`;
|
|
172
|
+
put(log, html);
|
|
173
|
+
C.items = items;
|
|
174
|
+
if (atEnd || C.jump) { log.scrollTop = log.scrollHeight; C.jump = false; }
|
|
175
|
+
drawFoot(R);
|
|
176
|
+
reopen.hidden = !host.viewerClosed();
|
|
177
|
+
// the PM has seen what is here now
|
|
178
|
+
const lastAt = msgs.length ? msgs[msgs.length - 1].at : null;
|
|
179
|
+
if (t.key && lastAt && (!C.marked || C.marked < lastAt)) { C.marked = lastAt; host.markSeen(t.key); }
|
|
180
|
+
autoOpen(R);
|
|
181
|
+
const gp = document.querySelector('.obody.vw[data-vw="goal"]'); // an open Goal view follows every change
|
|
182
|
+
if (gp) { const h = goalViewHtml(C.th && C.th.goal, readyDraft(C.conv), { live: goalLive() }); if (h && gp.__h !== h) { gp.__h = h; gp.innerHTML = h; } }
|
|
183
|
+
}
|
|
184
|
+
/* What an answer worked with opens by itself, once, when the answer finishes while the chat is open: on a desktop in the Viewer, on a phone
|
|
185
|
+
* as a bar over the box. What was already there when the chat opened opens nothing. Reports, charts and dashboards and a /goal do the same. */
|
|
186
|
+
function autoOpen(R) {
|
|
187
|
+
const conv = C.conv, key = C.t.key || C.t.sid; if (!conv || !Array.isArray(conv.messages)) return;
|
|
188
|
+
const first = C.auto.key !== key;
|
|
189
|
+
const done = turnsOf(conv.messages, R.waiting || conv.state === 'ended').filter((x) => x.done);
|
|
190
|
+
const rep = R.waiting || conv.state === 'ended' ? newestReport(conv) : undefined;
|
|
191
|
+
const now = goalNow(C.th && C.th.goal, readyDraft(conv));
|
|
192
|
+
if (first) { C.auto = { key, ctx: new Set(done.map((x) => x.id)), rep: rep === undefined ? null : blockSig(rep), goal: now ? now.sig : null }; peek(null); return; }
|
|
193
|
+
for (const d of done) {
|
|
194
|
+
if (C.auto.ctx.has(d.id)) continue;
|
|
195
|
+
C.auto.ctx.add(d.id);
|
|
196
|
+
if (d.items.length && d === done[done.length - 1]) show({ kind: 'ctx', item: d.items[0], title: d.items[0].title, sub: d.items[0].sub });
|
|
197
|
+
}
|
|
198
|
+
if (rep !== undefined) { const sig = blockSig(rep); if (rep && sig !== C.auto.rep) { const P = rep.proposal; show({ kind: 'report', block: rep, title: P ? (rep.kind === 'chart' ? P.title || P.measure : P.name) : rep.id, sub: rep.kind === 'report' ? 'Report' : rep.kind === 'chart' ? 'Chart' : 'Dashboard' }); } C.auto.rep = sig; }
|
|
199
|
+
const gs = now ? now.sig : null; if (now && gs !== C.auto.goal) show({ kind: 'goal', title: now.title, sub: now.sub }); C.auto.goal = gs;
|
|
200
|
+
}
|
|
201
|
+
function show(it) { if (host.desk()) openIt(it); else peek(it); }
|
|
202
|
+
function openIt(it) {
|
|
203
|
+
if (it.kind === 'goal') return openGoal();
|
|
204
|
+
if (it.kind === 'report') return views.block(it.block);
|
|
205
|
+
return views.ctx().then((M) => M.openCtx(it.item, where()));
|
|
206
|
+
}
|
|
207
|
+
function peek(it) {
|
|
208
|
+
clearTimeout(C.peekT);
|
|
209
|
+
let b = el.querySelector('#hmPeek');
|
|
210
|
+
if (!it) { if (b) b.hidden = true; return; }
|
|
211
|
+
if (!b) { foot.insertAdjacentHTML('beforebegin', '<button type="button" class="hm-peek" id="hmPeek" hidden></button>'); b = el.querySelector('#hmPeek'); }
|
|
212
|
+
b.innerHTML = `<span>${esc(it.sub || '')} · <b>${esc(it.title || '')}</b></span><em>View</em>`; b.hidden = false;
|
|
213
|
+
b.onclick = () => { peek(null); openIt(it); };
|
|
214
|
+
C.peekT = setTimeout(() => peek(null), 15000);
|
|
215
|
+
}
|
|
216
|
+
const where = () => ({ session: sid(), ws: C.t.ws || new URLSearchParams(location.search).get('ws') });
|
|
217
|
+
function newestReport(conv) {
|
|
218
|
+
const ms = (conv && conv.messages) || [];
|
|
219
|
+
for (let i = ms.length - 1; i >= 0; i--) { if (ms[i].role !== 'assistant') continue; const b = splitReport(splitGoal(ms[i].text).text).block; if (b) return b; }
|
|
220
|
+
return null;
|
|
221
|
+
}
|
|
222
|
+
function readyDraft(conv) {
|
|
223
|
+
const ms = (conv && conv.messages) || [];
|
|
224
|
+
for (let i = ms.length - 1; i >= 0; i--) { if (ms[i].role !== 'assistant') continue; const b = splitGoal(ms[i].text).block; if (b && b.step === 'ready') return b.draft || null; }
|
|
225
|
+
return null;
|
|
226
|
+
}
|
|
227
|
+
const goalLive = () => !!(C.th && C.th.goal) && C.th.goal.state === 'grilling' && !!C.conv && !C.conv.ask && C.conv.turn !== 'agent' && C.conv.turn !== 'tool';
|
|
228
|
+
function openGoal() {
|
|
229
|
+
const html = goalViewHtml(C.th && C.th.goal, readyDraft(C.conv), { live: goalLive() }); if (!html) return null;
|
|
230
|
+
return import('./premium-viewer.js').then((V) => { V.vwStyle('doc'); return V.vwOpen({ id: 'goal', title: 'Goal', icon: 'goal', render: (p) => { p.innerHTML = p.__h = goalViewHtml(C.th && C.th.goal, readyDraft(C.conv), { live: goalLive() }); p.onclick = (e) => { const g = e.target.closest('[data-goal]'); if (g) goalPress(g); }; } }); });
|
|
231
|
+
}
|
|
232
|
+
async function goalPress(gb) {
|
|
233
|
+
const act = gb.dataset.goal;
|
|
234
|
+
if (act === 'change') { const ta = foot.querySelector('textarea'); ta.placeholder = 'Tell Claude what to change'; ta.focus(); return; }
|
|
235
|
+
const goal = C.th && C.th.goal; if (!goal || !C.t.key) return;
|
|
236
|
+
gb.disabled = true;
|
|
237
|
+
const r = await host.pmPost('/api/briefing-premium/goal' + (C.t.ws ? '?ws=' + encodeURIComponent(C.t.ws) : ''), { key: C.t.key, id: goal.id, act, draft: readyDraft(C.conv) }).catch(() => null);
|
|
238
|
+
host.toast(r && r.ok ? ({ start: 'Claude is starting on the goal.', cancel: 'The goal is cancelled.', stop: 'The goal is stopped.' }[act]) : (r && r.error) || 'The press did not reach the session.');
|
|
239
|
+
read();
|
|
240
|
+
}
|
|
241
|
+
const askId = (m) => String((m && m.at) || '') + ':' + ((m && m.ask) || []).map((q) => q.question).join('|').slice(0, 80);
|
|
242
|
+
function askOf(id) { const m = ((C.conv && C.conv.messages) || []).find((x) => x.role === 'tool' && x.ask && askId(x) === id); return m ? m.ask : null; }
|
|
243
|
+
/* the context chips under an answer (the files, tickets, pages and links it worked with), drawn as premium-vw-ctx draws them */
|
|
244
|
+
let chipsHtmlFn = null;
|
|
245
|
+
views.ctx().then((M) => { chipsHtmlFn = M.chipsHtml; if (C.t) draw(); }).catch(() => {});
|
|
246
|
+
const chipsOf = (items) => (chipsHtmlFn ? chipsHtmlFn(items) : '');
|
|
247
|
+
function drawFoot(R) {
|
|
248
|
+
const t = C.t, run = runOf(C.conv, R.role), busy = running();
|
|
249
|
+
const strip = run ? `<div class="hm-run" role="status">${avHtml(R.role, 28, 'run')}<span class="hm-rt"><b>${esc(run.title)}</b><span>${esc(run.sub)}</span></span><progress class="hm-bar" aria-hidden="true" max="100" value="${Math.round(run.frac * 100)}"></progress><button type="button" class="hm-stop" data-hm-press="esc" title="Stop (Esc)"><i aria-hidden="true"></i>Stop</button></div>` : '';
|
|
250
|
+
const also = t.also && !(C.conv && C.conv.ask) ? `<button type="button" class="hm-also" data-hm-also><i aria-hidden="true"></i><span><b>Also waiting on you:</b> ${esc(t.also.text)}</span><em>Answer</em></button>` : '';
|
|
251
|
+
const ph = busy ? 'Steer ' + R.role.name + '…' : C.conv && C.conv.ask ? 'Or tell ' + R.role.name + ' what to do instead' : t.placeholder || 'Message Claude';
|
|
252
|
+
const sc = t.scope || { text: 'All work', icon: 'M5 21V4M5 4h12l-2 4 2 4H5' };
|
|
253
|
+
const keep = foot.querySelector('textarea'); const val = keep ? keep.value : '';
|
|
254
|
+
// the session's terminal: watch it read only while the session runs; copy the line that resumes an ended chat
|
|
255
|
+
const live = sid() && C.conv && C.conv.state !== 'ended';
|
|
256
|
+
// the + is the box's one quiet entry: Attach a file (the Agreed design's +), then the conversation's Notes and its terminal, which the
|
|
257
|
+
// design does not draw yet (each marked Waiting for design). The toolbar stays "+ / @ chip" as the mockup has it.
|
|
258
|
+
const W = '<em>Waiting for design</em>';
|
|
259
|
+
const term = live ? `<button type="button" role="menuitem" id="hmTerm" data-hm-term aria-label="Watch its terminal"><b>Watch its terminal</b>${W}</button>`
|
|
260
|
+
: C.th && C.th.resume ? `<button type="button" role="menuitem" id="hmTerm" data-hm-copyterm aria-label="Copy the terminal command"><b>Copy the terminal command</b>${W}</button>` : '';
|
|
261
|
+
const notesBtn = t.key ? `<button type="button" role="menuitem" id="hmNotes" data-hm-notes aria-label="Notes for this conversation"><b>Notes</b>${W}</button>` : '';
|
|
262
|
+
const attach = t.key ? '<button type="button" role="menuitem" data-hm-file><b>Attach a file</b><em>Or paste or drop it on the conversation</em></button>' : '';
|
|
263
|
+
const addOpen = !!C.addOpen && !!(attach || notesBtn || term);
|
|
264
|
+
const add = attach || notesBtn || term ? `<span class="hm-mw hm-addw"><button type="button" class="hm-tool" id="hmAdd" data-hm-add aria-haspopup="menu" aria-expanded="${addOpen}" aria-label="${t.key ? 'Attach a file, notes and more' : 'More'}" title="${t.key ? 'Attach a file' : 'More'}">${SVG(PLUS)}</button>`
|
|
265
|
+
+ `<span class="hm-pmenu hm-addm" role="menu" aria-label="Add"${addOpen ? ' data-esc-layer' : ' hidden'}>${attach}${notesBtn}${term}</span>${t.key ? '<input type="file" id="hmFile" multiple hidden>' : ''}</span>` : '';
|
|
266
|
+
let html;
|
|
267
|
+
if (t.rich) {
|
|
268
|
+
const wait = C.conv && C.conv.ask && t.also ? `<button type="button" class="hm-chip" data-hm-also><i class="dot" aria-hidden="true"></i><span>1 more needs you</span></button>` : '';
|
|
269
|
+
const to = t.to && !wait ? `<button type="button" class="hm-chip to" data-hm-to aria-label="Who reads this: ${esc(t.to.name)}. Change">${avHtml(t.to, 20)}<span>To: ${esc(t.to.name)}</span></button>` : '';
|
|
270
|
+
const scope = !to && !wait ? `<button type="button" class="hm-chip" data-hm-scope aria-label="Where this goes: ${esc(sc.text)}. Change" title="Where this goes: ${esc(sc.text)}">${SVG(sc.icon, 14)}<span>In: ${esc(sc.text)}</span></button>` : '';
|
|
271
|
+
html = `${also}${strip}<form class="hm-box" id="hmForm"><textarea id="hmIn" rows="1" aria-label="A message for ${esc(R.role.name)}" placeholder="${esc(ph)}"></textarea>`
|
|
272
|
+
+ `<div class="hm-tb">${add}`
|
|
273
|
+
+ `<button type="button" class="hm-tool" data-hm-slash aria-label="Commands" title="Commands"><b>/</b></button><button type="button" class="hm-tool" data-hm-at aria-label="Bring in an agent" title="Bring in an agent"><b>@</b></button>`
|
|
274
|
+
+ to + wait + scope + `<span class="sp"></span>${host.viewerClosed() ? '<span class="hm-key">Enter sends · Shift+Enter for a new line</span>' : ''}`
|
|
275
|
+
+ `<button type="submit" class="hm-send" aria-label="Send" title="Send">${SVG(UP, 18)}</button></div>`
|
|
276
|
+
+ filesRow()
|
|
277
|
+
+ '</form>';
|
|
278
|
+
} else {
|
|
279
|
+
html = `${also}${strip}<div class="hm-scope"><button type="button" class="hm-chip${sc.loose ? ' loose' : ''}" data-hm-scope aria-label="Where this goes: ${esc(sc.text)}. Change" title="Where this goes: ${esc(sc.text)}">${SVG(sc.icon, 14)}<span>In: ${esc(sc.text)}</span>${SVG(DOWN, 12)}</button>`
|
|
280
|
+
+ (sc.loose && t.sid ? '<button type="button" class="hm-link" data-hm-link>Link to an initiative</button>' : '') + `<span class="sp"></span>${add}</div>`
|
|
281
|
+
+ filesRow() + `<form class="hm-basic" id="hmForm"><textarea id="hmIn" rows="1" aria-label="A message for Claude" placeholder="${esc(ph)}"></textarea><button type="submit" class="hm-go" aria-label="Send to Claude" title="Send">${SVG(ARROW, 18)}</button></form>`
|
|
282
|
+
+ '<p class="hm-hint">It works in a real Claude Code session: it can read, change files, run commands and take slash commands.</p>';
|
|
283
|
+
}
|
|
284
|
+
if (foot.__h !== html) {
|
|
285
|
+
const focused = document.activeElement && document.activeElement.id === 'hmIn';
|
|
286
|
+
foot.__h = html; foot.innerHTML = html;
|
|
287
|
+
const ta = foot.querySelector('textarea'); ta.value = val; grow(ta);
|
|
288
|
+
if (focused) { ta.focus(); ta.setSelectionRange(ta.value.length, ta.value.length); }
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
/* the files on the next message: a photo shows its picture, a saved file its size; × takes it off and deletes the copy nothing will name */
|
|
292
|
+
const filesRow = () => (C.files.length ? `<div class="hm-files" id="hmFiles">${C.files.map((f, i) => `<span class="hm-att${f.state === 'saving' ? ' saving' : ''}">`
|
|
293
|
+
+ (f.url ? `<img class="hm-ath" src="${esc(f.url)}" alt="">` : '') + `<b>${esc(f.name)}</b><em>${f.state === 'saving' ? 'Saving…' : f.note ? 'Note' : esc(sizeText(f.size || 0))}</em>`
|
|
294
|
+
+ `<button type="button" data-hm-unfile="${i}" aria-label="Remove ${esc(f.name)}">×</button></span>`).join('')}</div>` : '');
|
|
295
|
+
const grow = (ta) => { ta.rows = 1; while (ta.rows < 9 && ta.scrollHeight > ta.clientHeight + 1) ta.rows += 1; }; // the box grows with its text, up to 9 lines (rows, not geometry)
|
|
296
|
+
|
|
297
|
+
/* ── writing ── */
|
|
298
|
+
async function send(text) {
|
|
299
|
+
const t = C.t; text = String(text || '').trim();
|
|
300
|
+
if (!t || (!text && !C.files.length) || C.sending) return false;
|
|
301
|
+
C.sending = true;
|
|
302
|
+
let r;
|
|
303
|
+
const was = running();
|
|
304
|
+
if (t.key) {
|
|
305
|
+
if (C.files.some((f) => f.state === 'saving')) { C.sending = false; host.toast('A file is still being saved. Send again in a moment.'); return false; }
|
|
306
|
+
const files = C.files.map((f) => f.saved);
|
|
307
|
+
r = await host.pmPost('/api/briefing-premium/ask' + (t.ws ? '?ws=' + encodeURIComponent(t.ws) : ''), files.length ? { key: t.key, text, files, ...(t.context ? { context: t.context } : {}) } : { key: t.key, text, ...(t.context ? { context: t.context } : {}) }).catch(() => null);
|
|
308
|
+
} else r = await host.pmPost('/api/session/say', { id: t.sid, text }).catch(() => null);
|
|
309
|
+
C.sending = false;
|
|
310
|
+
if (!r || r.ok !== true) { host.toast((r && r.error) || 'The message was not sent.'); return false; }
|
|
311
|
+
const s = sid() || r.session;
|
|
312
|
+
if (was && s && host.queue) host.queue(s, text);
|
|
313
|
+
C.files.forEach((f) => { if (f.url) URL.revokeObjectURL(f.url); }); C.files = []; C.jump = true;
|
|
314
|
+
if (t.onSent) t.onSent(r);
|
|
315
|
+
read();
|
|
316
|
+
return true;
|
|
317
|
+
}
|
|
318
|
+
async function press(k) {
|
|
319
|
+
const t = C.t; if (!t) return;
|
|
320
|
+
const r = t.key && !t.sid ? await host.pmPost('/api/briefing-premium/press' + (t.ws ? '?ws=' + encodeURIComponent(t.ws) : ''), { key: t.key, press: k }).catch(() => null)
|
|
321
|
+
: await host.pmPost('/api/session/keys', { id: sid(), press: k }).catch(() => null);
|
|
322
|
+
if (!r || !r.ok) host.toast((r && r.error) || 'The key did not reach the session.');
|
|
323
|
+
setTimeout(read, 500);
|
|
324
|
+
}
|
|
325
|
+
async function upload(files) {
|
|
326
|
+
const t = C.t; if (!t || !t.key) { host.toast('Attach a file in a chat, not in a terminal session.'); return; }
|
|
327
|
+
for (const file of files) {
|
|
328
|
+
if (C.files.length >= MAX_FILES) { host.toast('A message takes ' + MAX_FILES + ' files at most.'); break; }
|
|
329
|
+
if (file.size > MAX_BYTES) { host.toast(file.name + ' is larger than 20 MB. Attach a smaller copy, or paste a link.'); continue; }
|
|
330
|
+
const name = file.name || (file.type === 'image/png' ? 'pasted-image.png' : 'pasted-file');
|
|
331
|
+
const f = { name, size: file.size, state: 'saving', url: /\.(png|jpe?g|gif|webp)$/i.test(name) ? URL.createObjectURL(file) : null };
|
|
332
|
+
C.files.push(f); drawFoot({ role: role() });
|
|
333
|
+
const res = await fetch('/api/chat-file?key=' + encodeURIComponent(t.key) + '&name=' + encodeURIComponent(name), { method: 'POST', credentials: 'same-origin', headers: { ...host.pressHeaders(), 'Content-Type': 'application/octet-stream' }, body: file }).then((x) => x.json()).catch(() => null);
|
|
334
|
+
if (!C.files.includes(f)) { if (res && res.ok) host.pmPost('/api/chat-file/remove', { key: t.key, name: res.name }).catch(() => {}); continue; } // removed while it saved
|
|
335
|
+
if (res && res.ok) Object.assign(f, { state: 'saved', saved: res.name, path: res.path });
|
|
336
|
+
else { C.files = C.files.filter((x) => x !== f); host.toast(name + ' was not attached: ' + ((res && res.error) || 'the workspace server did not answer.')); }
|
|
337
|
+
drawFoot({ role: role() });
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
/* ── presses ── */
|
|
342
|
+
el.onclick = async (e) => { // delegated: buttons, file links and chips
|
|
343
|
+
const a = e.target.closest('a[href]');
|
|
344
|
+
if (a && a.closest('.hm-ab .md') && !e.metaKey && !e.ctrlKey && !e.shiftKey && !e.button) { // a Claude artifact, Google Doc or Confluence link opens in the Viewer
|
|
345
|
+
const k = webKind(a.getAttribute('href'));
|
|
346
|
+
if (k) { e.preventDefault(); views.file().then((M) => M.openWebLink(a.getAttribute('href'), k, a.textContent.trim(), where())); }
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
const b = e.target.closest('button, [data-file], [data-att], [data-ctx]'); if (!b || !el.contains(b)) return;
|
|
350
|
+
const d = b.dataset;
|
|
351
|
+
if ('hmAdd' in d) { C.addOpen = !C.addOpen; drawFoot({ role: role() }); const f = C.addOpen && foot.querySelector('.hm-addm [role=menuitem]'); if (f) f.focus(); return; }
|
|
352
|
+
if (C.addOpen && b.closest('.hm-addm')) { C.addOpen = false; drawFoot({ role: role() }); } // a press in the + menu closes it, then does its part
|
|
353
|
+
if ('hmFile' in d) { const i = foot.querySelector('#hmFile'); if (i) i.click(); return; }
|
|
354
|
+
if (d.reportOpen != null && d.reportOpen !== '') { e.preventDefault(); const m = ((C.conv && C.conv.messages) || [])[+d.reportOpen]; const bl = m ? splitReport(splitGoal(m.text).text).block : null; if (bl) views.block(bl); return; }
|
|
355
|
+
if (d.ctx != null) { e.preventDefault(); views.ctx().then((M) => M.openCtx(M.itemOf(b), where())); return; }
|
|
356
|
+
if (d.file) { e.preventDefault(); views.file().then((M) => M.openChatFile(d.file, where())); return; }
|
|
357
|
+
if (d.att) { e.preventDefault(); if (/\/notes\/n[0-9a-z]{6,16}\.md$/.test(d.att)) openNotesHere(d.att.split('/').pop().replace(/\.md$/, '')); else views.attach().then((M) => M.openAttachment(d.att)); return; }
|
|
358
|
+
if ('goalOpen' in d) { e.preventDefault(); openGoal(); return; }
|
|
359
|
+
if (d.goal) { goalPress(b); return; }
|
|
360
|
+
if (d.chatSay) { b.disabled = true; send(d.chatSay); return; }
|
|
361
|
+
if (d.slash) { pickSlash(d.slash); return; }
|
|
362
|
+
if (d.askPick) {
|
|
363
|
+
const card = b.closest('.tc'), btn = card && card.querySelector('[data-ask-send]'), at = btn ? btn.dataset.askSend : null, ask = at != null && askOf(at); if (!ask) return;
|
|
364
|
+
const [q, k] = d.askPick.split(':').map(Number);
|
|
365
|
+
const cur = (C.picked[at] = C.picked[at] || {}), had = cur[q] || [];
|
|
366
|
+
cur[q] = had.includes(k) ? had.filter((x) => x !== k) : ask[q].multi ? had.concat(k) : [k];
|
|
367
|
+
card.innerHTML = askCardHtml(ask, { live: true, picked: cur, at });
|
|
368
|
+
return;
|
|
369
|
+
}
|
|
370
|
+
if (d.askSend != null && d.askSend !== '') { const ask = askOf(d.askSend), text = ask && answerText(ask, C.picked[d.askSend]); if (!text) return; b.disabled = true; if (await send(text)) delete C.picked[d.askSend]; return; }
|
|
371
|
+
if ('hmFold' in d) { C.show = Infinity; draw(); return; }
|
|
372
|
+
if (d.hmWk) { if (C.open.has(d.hmWk)) C.open.delete(d.hmWk); else C.open.add(d.hmWk); draw(); return; }
|
|
373
|
+
if (d.hmCopy) { const it = C.items[+d.hmCopy]; try { await navigator.clipboard.writeText(it.text); host.toast('Copied.'); } catch { host.toast('The copy did not work in this browser.'); } return; }
|
|
374
|
+
if ('hmRetry' in d) { const u = ((C.conv && C.conv.messages) || []).filter((m) => m.role === 'user').pop(); if (u) send(u.text); return; }
|
|
375
|
+
if (d.hmWi) { const it = C.items[+d.hmWi]; if (it) host.workItem(it.text, C.t); return; }
|
|
376
|
+
if (d.hmPill) { const p = C.t.intro.pills[+d.hmPill]; if (p && p.go) { b.disabled = true; await p.go(b); b.disabled = false; } return; }
|
|
377
|
+
if (d.hmPress) { b.disabled = true; press(d.hmPress); return; }
|
|
378
|
+
if ('hmPmore' in d) { const m = b.nextElementSibling; m.hidden = !m.hidden; return; }
|
|
379
|
+
if ('hmTerm' in d) { host.openTerminal(sid()); return; }
|
|
380
|
+
if ('hmCopyterm' in d) { const cmd = C.th && C.th.resume; try { await navigator.clipboard.writeText(cmd); host.toast('Copied. Paste it in Terminal on the computer PMOS runs on.'); } catch { host.toast('Copy did not work here. The command: ' + cmd); } return; }
|
|
381
|
+
if (d.hmQdel) { host.unqueue(sid(), d.hmQdel); draw(); return; }
|
|
382
|
+
if ('hmAlso' in d) { if (C.t.also && C.t.also.go) C.t.also.go(); return; }
|
|
383
|
+
if ('hmNotes' in d) { openNotesHere(); return; }
|
|
384
|
+
if ('hmScope' in d) { host.onScope(b); return; }
|
|
385
|
+
if ('hmLink' in d) { host.onLink(b, C.t); return; }
|
|
386
|
+
if ('hmTo' in d || 'hmAt' in d) { host.onTo(b, C.t); return; }
|
|
387
|
+
if ('hmSlash' in d) { const ta = foot.querySelector('textarea'); if (!ta.value.startsWith('/')) ta.value = '/' + ta.value; ta.focus(); drawSlash(); return; }
|
|
388
|
+
if (d.hmUnfile) {
|
|
389
|
+
const f = C.files[+d.hmUnfile]; if (!f) return;
|
|
390
|
+
C.files = C.files.filter((x) => x !== f); if (f.url) URL.revokeObjectURL(f.url);
|
|
391
|
+
if (f.saved && !f.note && C.t && C.t.key) host.pmPost('/api/chat-file/remove', { key: C.t.key, name: f.saved }).catch(() => { /* left in the folder; nothing names it */ });
|
|
392
|
+
drawFoot({ role: role() });
|
|
393
|
+
}
|
|
394
|
+
};
|
|
395
|
+
el.addEventListener('submit', (e) => { e.preventDefault(); const ta = foot.querySelector('textarea'); const v = ta.value; send(v).then((ok) => { if (ok) { ta.value = ''; grow(ta); } }); });
|
|
396
|
+
const shutAdd = (focus) => { if (!C.addOpen) return; C.addOpen = false; drawFoot({ role: role() }); if (focus) { const a = foot.querySelector('#hmAdd'); if (a) a.focus(); } };
|
|
397
|
+
document.addEventListener('click', (e) => { if (C.addOpen && e.target.isConnected && !e.target.closest('.hm-addw')) shutAdd(false); }, true);
|
|
398
|
+
el.addEventListener('keydown', (e) => {
|
|
399
|
+
if (e.key === 'Escape' && C.addOpen) { e.preventDefault(); e.stopPropagation(); shutAdd(true); return; }
|
|
400
|
+
if (e.target.id !== 'hmIn') { if (e.key === 'Escape' && running() && !document.querySelector('[data-esc-layer]') && !(window.czViewer && window.czViewer.isOpen())) press('esc'); return; }
|
|
401
|
+
if (e.isComposing || e.keyCode === 229) return;
|
|
402
|
+
const list = slashMatches(e.target.value), sm = el.querySelector('#hmSlash'), menu = list.length && sm && !sm.hidden;
|
|
403
|
+
if (menu && (e.key === 'ArrowDown' || e.key === 'ArrowUp')) { e.preventDefault(); C.slashAt = (C.slashAt + (e.key === 'ArrowDown' ? 1 : list.length - 1)) % list.length; drawSlash(); return; }
|
|
404
|
+
if (menu && (e.key === 'Tab' || (e.key === 'Enter' && !e.shiftKey && e.target.value !== list[C.slashAt].cmd))) { e.preventDefault(); pickSlash(list[C.slashAt].cmd); return; }
|
|
405
|
+
if (menu && e.key === 'Escape') { e.preventDefault(); e.stopPropagation(); e.target.value = ''; drawSlash(); grow(e.target); return; }
|
|
406
|
+
if (e.key === 'Enter' && !e.shiftKey && !e.altKey && !e.ctrlKey && !e.metaKey) { e.preventDefault(); el.querySelector('#hmForm').requestSubmit(); }
|
|
407
|
+
});
|
|
408
|
+
el.addEventListener('input', (e) => { if (e.target.id === 'hmIn') { grow(e.target); C.slashAt = 0; drawSlash(); } });
|
|
409
|
+
/* the / menu: opens on a leading /, arrows move, Enter or Tab picks, Esc shuts it */
|
|
410
|
+
function drawSlash() {
|
|
411
|
+
const ta = foot.querySelector('textarea'); if (!ta) return;
|
|
412
|
+
let m = el.querySelector('#hmSlash');
|
|
413
|
+
const list = slashMatches(ta.value);
|
|
414
|
+
if (!list.length) { if (m) { m.hidden = true; m.removeAttribute('data-esc-layer'); } return; }
|
|
415
|
+
if (!m) { foot.insertAdjacentHTML('afterbegin', '<div class="hm-slash" id="hmSlash" role="listbox" aria-label="Commands"></div>'); m = el.querySelector('#hmSlash'); }
|
|
416
|
+
C.slashAt = Math.min(C.slashAt, list.length - 1);
|
|
417
|
+
m.innerHTML = list.map((x, i) => `<button type="button" role="option" aria-selected="${i === C.slashAt}" data-slash="${esc(x.cmd)}"><code>${esc(x.cmd)}</code><b>${esc(x.name)}</b><em>${esc(x.say)}</em></button>`).join('');
|
|
418
|
+
m.hidden = false; m.setAttribute('data-esc-layer', '');
|
|
419
|
+
}
|
|
420
|
+
function pickSlash(cmd) { const ta = foot.querySelector('textarea'); ta.value = cmd + ' '; C.slashAt = 0; drawSlash(); grow(ta); ta.focus(); }
|
|
421
|
+
/* Notes: the notepad opens in the Viewer for the conversation's key; Add selection writes into this box, Share with Claude puts the note
|
|
422
|
+
* on the next message as a chip (premium-attach's sink), and on a phone both return to the chat. */
|
|
423
|
+
let notesM = null;
|
|
424
|
+
const notesLib = () => notesM || (notesM = import('./premium-notes.js').then((M) => {
|
|
425
|
+
M.mountNotes({ getKey: () => (C.t && C.t.key) || null, ws: (C.t && C.t.ws) || new URLSearchParams(location.search).get('ws') || undefined,
|
|
426
|
+
get input() { return foot.querySelector('textarea'); }, note: { set textContent(v) { if (v) host.toast(v); } },
|
|
427
|
+
show: () => { const b = VWC.body(); if (b && !b.querySelector(':scope > .hx-wait')) b.insertAdjacentHTML('afterbegin', host.wait || ''); },
|
|
428
|
+
toChat: () => { if (!host.desk()) VWC.close(); } });
|
|
429
|
+
return M;
|
|
430
|
+
}));
|
|
431
|
+
setAttachSink((f) => {
|
|
432
|
+
if (!C.t || !C.t.key || C.files.some((x) => x.saved === f.saved)) return;
|
|
433
|
+
if (C.files.length >= MAX_FILES) { host.toast('A message takes ' + MAX_FILES + ' files at most.'); return; }
|
|
434
|
+
C.files.push({ name: f.name, size: f.size, state: 'saved', saved: f.saved, path: f.path, note: !!f.note }); drawFoot({ role: role() });
|
|
435
|
+
});
|
|
436
|
+
function openNotesHere(id) { notesLib().then((M) => M.openNotes(id)); }
|
|
437
|
+
el.addEventListener('change', (e) => { if (e.target.id === 'hmFile') { upload([...e.target.files]); e.target.value = ''; } });
|
|
438
|
+
// a pasted file, or one dropped on the conversation, is attached like a picked one
|
|
439
|
+
el.addEventListener('paste', (e) => { if (e.target.id !== 'hmIn' || !C.t || !C.t.key) return; const fs = e.clipboardData ? [...e.clipboardData.files] : []; if (!fs.length) return; e.preventDefault(); upload(fs); });
|
|
440
|
+
el.addEventListener('dragover', (e) => { if (!C.t || !C.t.key || !e.dataTransfer || ![...(e.dataTransfer.types || [])].includes('Files')) return; e.preventDefault(); el.classList.add('hm-drop'); });
|
|
441
|
+
el.addEventListener('dragleave', (e) => { if (e.target === el || !el.contains(e.relatedTarget)) el.classList.remove('hm-drop'); });
|
|
442
|
+
el.addEventListener('drop', (e) => { el.classList.remove('hm-drop'); const fs = e.dataTransfer ? [...e.dataTransfer.files] : []; if (!fs.length || !C.t || !C.t.key) return; e.preventDefault(); upload(fs); });
|
|
443
|
+
|
|
444
|
+
return {
|
|
445
|
+
open(t) {
|
|
446
|
+
if (notesM) notesM.then((M) => setTimeout(() => M.syncNotes(), 0)); // the Notes open in the Viewer belonged to the conversation before
|
|
447
|
+
const same = C.t && t && C.t.key === t.key && C.t.sid === t.sid;
|
|
448
|
+
C.t = t;
|
|
449
|
+
if (!same) { C.addOpen = false; C.th = null; C.conv = null; C.show = 12; C.open = new Set(); C.files = []; C.marked = null; C.picked = {}; C.seenAt = t.key ? host.seen(t.key) : null; put(log, introHtml(t.intro)); C.jump = true; peek(null); }
|
|
450
|
+
draw(); read();
|
|
451
|
+
},
|
|
452
|
+
refresh() { if (C.t) draw(); },
|
|
453
|
+
reread() { read(); },
|
|
454
|
+
focus() { const ta = foot.querySelector('textarea'); if (ta) ta.focus(); },
|
|
455
|
+
send,
|
|
456
|
+
current: () => C.t,
|
|
457
|
+
running,
|
|
458
|
+
};
|
|
459
|
+
}
|