diff --git a/packages/webui/src/public/bus.js b/packages/webui/src/public/bus.js index 409366c8a..35141e097 100644 --- a/packages/webui/src/public/bus.js +++ b/packages/webui/src/public/bus.js @@ -1449,7 +1449,6 @@ if (n === 0 && window.MosaicOrg) return window.MosaicWorkspace.home(); if (a === 'projects' && n === 1 && window.MosaicOrg) return window.MosaicWorkspace.projectsPage(q); if (a === 'organization' && n === 1 && window.MosaicOrg) return window.MosaicWorkspace.dashboard(); - if (a === 'side-by-side' && n === 1 && window.MosaicOrg) return `${head('Side by side', 'Not built yet.')}${empty('Side by side is not built yet.', 'It arrives with a later unified workspace update. Projects and Agents work today.')}`; if (a === 'inbox' && n === 1 && window.MosaicOrg) return window.MosaicWorkspace.inboxPage(q); if (a === 'tasks' && n === 1 && window.MosaicOrg) return window.MosaicTasksBoard.view(); if (a === 'inbox' && n === 1) return inboxView(get); @@ -1542,6 +1541,15 @@ window.MosaicChat?.leave(chatPath); if (path === '/business') { location.replace('#/settings/business'); return; } if (path === '/settings/display') { location.replace('#/settings/appearance'); return; } + // U5: Side by side draws its own two panes (panes.js); every other page stops their polling. + if (path !== '/side-by-side') window.MosaicPanes?.unmount(); + else if (window.MosaicOrg && window.MosaicPanes) { + const fresh = navigated || shown !== path; + shown = path; + if (fresh) { unmountEditor(); await window.MosaicPanes.mount($('bus-view'), query, { navigated }); } + else window.MosaicPanes.refresh(); + return; + } if (chatPath === '/chat' || chatPath.startsWith('/chat/') || /^\/projects\/[0-9a-f-]+\/(?:settings|conversations|tasks|requirements|files)$/i.test(chatPath)) { // Re-read the scoped capability as the Console and bus recover. A failed read // withdraws the control; the chat renderer retains the draft across repaint. diff --git a/packages/webui/src/public/index.html b/packages/webui/src/public/index.html index 586296d90..1687c34d1 100644 --- a/packages/webui/src/public/index.html +++ b/packages/webui/src/public/index.html @@ -6,8 +6,8 @@ - - + +
Skip to content diff --git a/packages/webui/src/public/panes.css b/packages/webui/src/public/panes.css new file mode 100644 index 000000000..29d895cee --- /dev/null +++ b/packages/webui/src/public/panes.css @@ -0,0 +1,66 @@ +/* Side by side (U5, sample 07 "EXT 8"): a bar, then two panes with a divider between them. Each pane + has its own header with the organization's mark and edge, and its own scroll. One pane and a + shown-pane switch on a phone. Loaded after shell.css; every rule is scoped to the side-by-side page. */ +html[data-organizations] .content:has(> #bus-view > .sbs){padding:0} +html[data-organizations] .sbs{margin:0;display:flex;flex-direction:column;min-height:0;height:calc(100vh - var(--bar-h,53px) - var(--foot-h,33px))} +html[data-organizations] .sbs .panebar{display:flex;align-items:center;gap:10px;padding:8px 14px;border-bottom:1px solid var(--line);background:var(--canvas);flex-wrap:wrap} +html[data-organizations] .sbs .panebar h1{font-size:16px;font-weight:700;margin:0;line-height:1.4} +html[data-organizations] .sbs .panebar h1:focus{outline:none} +html[data-organizations] .sbs .panebar .note{font-size:13px;color:var(--muted)} +html[data-organizations] .sbs .panebar [data-pane-add]{margin-left:auto} +html[data-organizations] .sbs .ws-seg.pane-tabs{display:none;margin-left:0} +html[data-organizations] .sbs .pane-tabs>button{gap:5px;max-width:44vw} +html[data-organizations] .sbs .pane-tabs>button>span:last-child{overflow:hidden;text-overflow:ellipsis} + +html[data-organizations] .panes{--sbs-a:1fr;--sbs-b:1fr;display:grid;grid-template-columns:minmax(0,1fr);flex:1;min-height:0} +html[data-organizations] .panes.two{grid-template-columns:minmax(0,var(--sbs-a)) 1px minmax(0,var(--sbs-b))} +html[data-organizations] .pane{display:flex;flex-direction:column;min-width:0;min-height:0} +html[data-organizations] .pane[hidden]{display:none} +html[data-organizations] .pane-h{display:flex;align-items:center;gap:8px;padding:8px 14px;border-bottom:1px solid var(--line);background:var(--surface);box-shadow:inset 0 3px 0 var(--org,var(--line));min-width:0} +html[data-organizations] .pane-h .ttl{font-weight:700;color:var(--strong,var(--text));overflow:hidden;text-overflow:ellipsis;white-space:nowrap;min-width:0;flex:0 1 auto} +html[data-organizations] .pane-h .ttl small{font-weight:500;color:var(--muted);margin-left:6px;font-size:inherit} +html[data-organizations] .pane-h [data-pane-state]:empty{display:none} +html[data-organizations] .pane-pick{flex:0 1 180px;min-width:0;max-width:220px;margin-left:auto;font:500 12px/1.4 var(--font);color:var(--text);background:var(--canvas);border:1px solid var(--line);border-radius:var(--r);padding:3px 6px;min-height:0} +html[data-organizations] .pane-h .tools{display:flex;gap:2px;flex:none} +html[data-organizations] .pane-tool{display:inline-grid;place-items:center;width:26px;height:26px;border-radius:var(--r);color:var(--muted);border:0;background:none;padding:0;min-height:0;cursor:pointer} +html[data-organizations] .pane-tool:hover{background:var(--raised);color:var(--text)} +html[data-organizations] .pane-tool[hidden]{display:none} +html[data-organizations] .pane-tool svg.i{width:15px;height:15px;fill:none;stroke:currentColor;stroke-width:1.8;stroke-linecap:round;stroke-linejoin:round} +html[data-organizations] .pane-line{margin:0;padding:6px 14px;border-bottom:1px solid var(--line);font-size:13px;color:var(--text);background:color-mix(in srgb,var(--warn,#b7791f) 12%,var(--surface))} +html[data-organizations] .pane-line[hidden]{display:none} +html[data-organizations] .pane-body{overflow:auto;padding:14px;min-height:0;flex:1} +html[data-organizations] .pane-body:focus{outline:none} +html[data-organizations] .pane-body:focus-visible{outline:2px solid var(--focus,var(--action));outline-offset:-2px} +/* A page inside a pane is a section of the side-by-side page: smaller headings, no page chrome. */ +html[data-organizations] .pane-body .ws h1,html[data-organizations] .pane-body .project-header h1{font-size:20px} +html[data-organizations] .pane-body .chat-area.pane-project{display:block;height:auto;min-height:0;overflow:visible;padding:0} +/* Project pages size some parts from the window (projects.css); in a pane they size from the pane, + and a pane narrower than a phone gets the phone's stacked header. */ +html[data-organizations] .pane-body{container-type:inline-size} +html[data-organizations] .pane-body .project-header{width:auto;max-width:100%;margin-top:0} +html[data-organizations] .pane-body .project-header-icon{width:44px;height:44px;font-size:22px} +@container (max-width:699px){ + html[data-organizations] .pane-body .project-header:not([data-project-conversation="true"]){display:block} + html[data-organizations] .pane-body .project-actions{margin-top:12px;display:flex;flex-wrap:wrap;gap:8px} +} +/* The side-by-side page has its own bar; the page breadcrumb would name only one pane. */ +body:has(#bus-view > .sbs) #breadcrumbs{display:none} +html[data-organizations] .content:has(> #bus-view > .sbs) > .org-cue{margin:8px 14px} + +html[data-organizations] .pane-div{position:relative;background:var(--line);cursor:col-resize;touch-action:none;outline:none} +html[data-organizations] .pane-div::before{content:"";position:absolute;inset:0 -4px;z-index:1} +html[data-organizations] .pane-div:hover,html[data-organizations] .pane-div.dragging{background:var(--action)} +html[data-organizations] .pane-div:focus-visible{background:var(--action);box-shadow:0 0 0 2px var(--action)} +html[data-organizations] .pane-div[hidden]{display:none} + +@media (max-width:760px){ + html[data-organizations] .content:has(> #bus-view > .sbs){padding:0} + html[data-organizations] .sbs{height:auto} + html[data-organizations] .sbs .ws-seg.pane-tabs{display:inline-flex} + html[data-organizations] .sbs .hide-m{display:none} + html[data-organizations] .panes,html[data-organizations] .panes.two{grid-template-columns:minmax(0,1fr)} + html[data-organizations] .pane.alt,html[data-organizations] .pane-div{display:none} + html[data-organizations] .pane-body{overflow:visible} + html[data-organizations] .pane-h{flex-wrap:wrap} + html[data-organizations] .pane-pick{flex:1 1 100%;max-width:none;order:5;margin-left:0} +} diff --git a/packages/webui/src/public/panes.js b/packages/webui/src/public/panes.js new file mode 100644 index 000000000..52fc2b573 --- /dev/null +++ b/packages/webui/src/public/panes.js @@ -0,0 +1,446 @@ +// Side by side (U5, sample 07): two panes, each showing one page of any organization. A pane holds +// the organization dashboard, the Agents levels or a project page (overview, conversations, tasks, +// requirements, files), drawn by the same modules as the full view (workspace.js, projects.js) into +// the pane instead of #bus-view. Every read names the pane's organization, so the panes never share +// state. Pages that keep one global form, dialog or editor (a conversation, the room, settings, the +// queue, docs, the inbox) are not offered in a pane; their links open the full view. +// +// The panes' routes, the divider and the phone's shown pane live in the URL +// (#/orgs/Nothing is read for an organization that is not on your list.
'; } + else if (org.invalid) { line = `${name}: organization invalid${org.reason ? ` (${org.reason})` : ''}.`; html = 'Nothing is read from an invalid organization. Fix its file under Settings, Organizations.
'; } + else if (!org.busHealthy) line = `${name}: bus unavailable. Reads from this organization may fail; the other pane is not affected.`; + setText(e.line, line); e.line.hidden = !line; + + let title = what?.kind === 'agents' ? 'Agents' : 'Dashboard'; + if (html === null && what?.kind === 'dashboard') html = await ws().dashboard(p.org, { pane: true, idPrefix: `pane-${p.key}-` }).catch(() => 'Dashboard unavailable.
'); + else if (html === null && what?.kind === 'agents') html = await ws().agentGrid('', p.org).catch(() => 'Agents unavailable.
'); + if (!live()) return; + if (html === null && what?.kind === 'project') { + title = await drawProject(p, e, what, fresh); + if (!live()) return; + } else if (html !== null) paintBody(p, html); + p.title = title; + setHtml(e.ttl, `${esc(title)}${esc(name)}`); + p.el.setAttribute('aria-label', `${NAMES[p.key][0].toUpperCase()}${NAMES[p.key].slice(1)} pane: ${title}, ${name}`); + setText(e.fullLabel, `Open ${title}, ${name}, in full view`); + // The picker is rebuilt only while it is closed and unfocused, so a choice in progress stays. + if (document.activeElement !== e.pick) { + const options = await pickerHtml(p, list); + if (!live()) return; + if (document.activeElement !== e.pick) { setHtml(e.pick, options); e.pick.value = paneValue(p); } + } + paintBar(); fit(); + if (focusHead) (e.body.querySelector('h1') || e.body).focus({ preventScroll: true }); + p.timer = setTimeout(() => tick(p), POLL); + } + function tick(p) { + if (!mounted || !p.el.isConnected) return; + if (paused()) { p.timer = setTimeout(() => tick(p), POLL); return; } + void drawPane(p); + } + + // A project page: projects.js's header and content, mounted into the pane with the pane's + // organization, read-only (a pane never sends). + async function drawProject(p, e, what, fresh) { + const [projects, threadsRead] = await Promise.all([projectsOf(p.org, fresh), data.threads(p.org).catch(() => null)]); + const project = projects?.find(r => r.id === what.id); + const sectionName = SECTIONS[what.section]; + if (!project) { + paintBody(p, projects === null ? 'Projects unavailable. The organization did not answer the project read.
' : 'This project is not in the organization\'s project list.
'); + return what.id; + } + const threads = Array.isArray(threadsRead?.rows) ? threadsRead.rows : []; + const head = window.MosaicProjects.header(project, what.section, threads); + const conv = what.section === 'conversations' ? conversations(project, threads, threadsRead) : null; + const key = JSON.stringify([project.id, what.section, head, conv]); + const { body } = e; + if (p.project?.key !== key) { + const kept = capture(p, body); + body.innerHTML = `Conversations unavailable.
'; + const own = threads.filter(t => t && !t.shared && t.project === project.id && typeof t.id === 'string'); + const rows = own.map(t => `${esc(t.name || t.id)}With ${esc(t.instance || 'no agent recorded')}`).join(''); + return `No conversations yet.
'}A conversation opens in its full view.
`; + } + + // ---------- the bar, tabs, divider and layout ---------- + function paintBar() { + if (!mounted) return; + const { root, panes, show } = mounted, two = panes.length === 2; + setText(root.querySelector('[data-sbs-note]'), `${panes.length} ${panes.length === 1 ? 'pane' : 'panes'} · each pane reads its own organization's bus and keeps its own state`); + const tabs = root.querySelector('[data-sbs-tabs]'), focusedTab = tabs.contains(document.activeElement) ? document.activeElement.dataset.paneShow : null; + const list = listCache; + const html = panes.map(p => { + const org = list?.find(o => o?.id === p.org); + return ``; + }).join(''); + if (tabs.innerHTML !== html) { tabs.innerHTML = html; if (focusedTab) tabs.querySelector(`[data-pane-show="${focusedTab}"]`)?.focus({ preventScroll: true }); } + const add = root.querySelector('[data-pane-add]'); + add.disabled = two; add.title = two ? 'Side by side holds two panes. Close one to choose another.' : 'Open a second pane'; + for (const p of panes) { const c = p.el.querySelector('[data-pane-close]'); c.hidden = !two; } + } + function layout() { + if (!mounted) return; + const { root, panes, w, show } = mounted, two = panes.length === 2; + const box = root.querySelector('[data-sbs-panes]'), divider = root.querySelector('[data-sbs-divider]'); + box.classList.toggle('two', two); + box.style.setProperty('--sbs-a', `${w}fr`); box.style.setProperty('--sbs-b', `${100 - w}fr`); + divider.hidden = !two; + divider.setAttribute('aria-valuenow', String(w)); + divider.setAttribute('aria-valuetext', `Left pane ${w} percent, right pane ${100 - w} percent`); + root.querySelector('#pane-b').hidden = !two; + for (const p of panes) p.el.classList.toggle('alt', show !== p.key); + fit(); + } + // Wide screens: the panes fill the window below the bar and each scrolls on its own. + const wide = window.matchMedia('(min-width: 761px)'); + function fit() { + if (!mounted) return; + const { root } = mounted; + if (!wide.matches) { root.style.height = ''; return; } + const foot = document.querySelector('body > .foot, .foot')?.getBoundingClientRect().height || 0; + const top = root.getBoundingClientRect().top; + root.style.height = `${Math.max(360, Math.floor(window.innerHeight - Math.max(top, 0) - foot))}px`; + } + function setWidth(w, persist = true) { + if (!mounted) return; + const next = clampW(w); + if (next === mounted.w) return; + mounted.w = next; layout(); if (persist) writeUrl(); + } + + // ---------- events (bound once to the mount root) ---------- + function bind(root) { + const divider = root.querySelector('[data-sbs-divider]'); + divider.addEventListener('keydown', e => { + const w = mounted?.w; if (w === undefined) return; + const next = { ArrowLeft: w - STEP, ArrowDown: w - STEP, ArrowRight: w + STEP, ArrowUp: w + STEP, PageDown: w - 10, PageUp: w + 10, Home: MIN, End: MAX }[e.key]; + if (next === undefined) return; + e.preventDefault(); setWidth(next); + }); + divider.addEventListener('pointerdown', e => { + if (e.button !== 0) return; + e.preventDefault(); divider.focus({ preventScroll: true }); divider.setPointerCapture(e.pointerId); divider.classList.add('dragging'); + const box = root.querySelector('[data-sbs-panes]').getBoundingClientRect(); + const move = ev => setWidth(((ev.clientX - box.left) / box.width) * 100, false); + const up = () => { divider.removeEventListener('pointermove', move); divider.removeEventListener('pointerup', up); divider.removeEventListener('pointercancel', up); divider.classList.remove('dragging'); writeUrl(); }; + divider.addEventListener('pointermove', move); divider.addEventListener('pointerup', up); divider.addEventListener('pointercancel', up); + }); + root.addEventListener('change', e => { + const pick = e.target.closest?.('[data-pane-pick]'); if (!pick || !mounted) return; + const p = mounted.panes.find(x => x.el.contains(pick)), next = parsePane(pick.value); + if (!p || !next) return; + go(p, next, false); + }); + root.addEventListener('click', e => { + if (!mounted) return; + const show = e.target.closest?.('[data-pane-show]'); + if (show) { mounted.show = show.dataset.paneShow === 'b' && mounted.panes.length === 2 ? 'b' : 'a'; layout(); paintBar(); writeUrl(); return; } + if (e.target.closest?.('[data-pane-add]')) { void addPane(); return; } + const close = e.target.closest?.('[data-pane-close]'); + if (close) { closePane(mounted.panes.find(x => x.el.contains(close))); return; } + // A plain click on a link to a page a pane draws, in the pane's own organization, opens it in + // the pane. Anything else (another organization, a page a pane does not draw, a new tab) is + // an ordinary link to the full view. + const a = e.target.closest?.('a[href^="#/orgs/"]'); + if (!a || a.hasAttribute('data-pane-full') || e.defaultPrevented || e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) return; + const p = mounted.panes.find(x => x.el.contains(a)); if (!p) return; + const m = /^#\/orgs\/([^/?#]+)(\/[^?#]*)$/.exec(a.getAttribute('href')); + let org, route; + try { org = decodeURIComponent(m?.[1] ?? ''); route = decodeURIComponent(m?.[2] ?? ''); } catch { return; } + if (org !== p.org || !page(route)) return; + e.preventDefault(); + go(p, { org, route }, true); + }); + } + function go(p, next, focusHead) { + p.org = next.org; p.route = next.route; p.html = null; p.project = null; p.title = null; + els(p).body.scrollTop = 0; + writeUrl(); + void drawPane(p, { focusHead }); + } + async function addPane() { + if (!mounted || mounted.panes.length !== 1) return; + const [a] = mounted.panes, list = await orgList(); + if (!mounted || mounted.panes.length !== 1) return; + const other = (list || []).find(o => o && !o.invalid && o.id !== a.org && ORG.test(o.id)); + const b = makePane('b', other ? { org: other.id, route: '/organization' } : { org: a.org, route: a.route === '/agents' ? '/organization' : '/agents' }); + mounted.panes.push(b); mounted.show = 'b'; + layout(); writeUrl(); + await drawPane(b); + if (mounted?.panes.includes(b)) els(b).pick.focus({ preventScroll: true }); + } + function closePane(p) { + if (!mounted || !p || mounted.panes.length !== 2) return; + clearTimeout(p.timer); p.turn++; + const keep = mounted.panes.find(x => x !== p); + // The remaining pane becomes the first: its page moves into pane a's element. + const a = mounted.panes[0]; + if (keep !== a) { + const b = mounted.panes[1]; + clearTimeout(b.timer); b.turn++; + a.org = keep.org; a.route = keep.route; a.html = null; a.project = null; a.title = keep.title; + } + setHtml(els(mounted.panes[1]).body, ''); mounted.panes[1].html = null; mounted.panes[1].project = null; + mounted.panes = [a]; mounted.show = 'a'; + layout(); writeUrl(); + void drawPane(a).then(() => { if (mounted?.panes[0] === a) els(a).pick.focus({ preventScroll: true }); }); + if (keep === a) els(a).pick.focus({ preventScroll: true }); + } + function makePane(key, at) { + const el = mounted.root.querySelector(`#pane-${key}`); + const p = { key, el, org: at.org, route: at.route, turn: 0, timer: null, html: null, project: null, title: null }; + // projects.js paints a project's content after its own reads; its links are rewritten as they land. + p.observer?.disconnect(); + p.observer = new MutationObserver(() => rewrite(p, els(p).body)); + p.observer.observe(els(p).body, { childList: true, subtree: true }); + return p; + } + + // ---------- public ---------- + async function mount(container, query, { navigated = false } = {}) { + unmount(); + const gen = ++mountGen; + container.innerHTML = frame(); + const root = container.querySelector('[data-side-by-side]'); + mounted = { root, panes: [], w: 50, show: 'a', gen }; + bind(root); + window.addEventListener('resize', fit); + document.title = 'Side by side · Mosaic Console'; + if (navigated) root.querySelector('h1').focus({ preventScroll: true }); + let wanted = readQuery(query); + if (!wanted.named) { const kept = readQuery(load() || ''); if (kept.a) wanted = { ...kept, named: true }; } + let at = [wanted.a, wanted.b].filter(Boolean); + if (!at.length) at = await defaults(); + if (!mounted || gen !== mountGen) return; + listCache = await orgList(); + if (!mounted || gen !== mountGen) return; + mounted.panes = at.slice(0, 2).map((x, i) => makePane(i ? 'b' : 'a', x)); + mounted.w = Number.isFinite(wanted.w) && wanted.w ? clampW(wanted.w) : 50; + mounted.show = wanted.show === 'b' && mounted.panes.length === 2 ? 'b' : 'a'; + layout(); paintBar(); writeUrl(); + await Promise.all(mounted.panes.map(p => drawPane(p))); + } + function unmount() { + if (!mounted) return; + for (const p of mounted.panes) { clearTimeout(p.timer); p.turn++; p.observer?.disconnect(); } + window.removeEventListener('resize', fit); + mounted = null; mountGen++; + } + // The Console's Refresh: both panes read again now, each keeping its own focus and scroll. + function refresh() { + if (!mounted) return; + projectReads = new Map(); + void orgList(true).then(rows => { if (rows) listCache = rows; }); + for (const p of mounted.panes) void drawPane(p, { fresh: true }); + } + // The list the tabs draw from follows each fresh read of the organization list. + document.addEventListener('mosaic-org-list', e => { if (Array.isArray(e.detail?.rows)) listCache = e.detail.rows; }); + + window.MosaicPanes = Object.freeze({ mount, unmount, refresh, page }); +})(); diff --git a/packages/webui/src/public/projects.js b/packages/webui/src/public/projects.js index 0b4dcf0ec..7e729344b 100644 --- a/packages/webui/src/public/projects.js +++ b/packages/webui/src/public/projects.js @@ -31,12 +31,15 @@ let treeRows=[], treeThreads=[], treeGeneration=0, treeState, treeRead=null, treeReadAt=0; const treeFocus = new WeakMap(); try { treeState=JSON.parse(localStorage.getItem(storageKey) || '{}'); if (!treeState || Array.isArray(treeState) || typeof treeState !== 'object') treeState={}; } catch { treeState={}; } + // A side-by-side pane reads its own organization: its reads name that organization explicitly. + const at=(org,url)=>org && url.startsWith('/api/') ? `/api/orgs/${encodeURIComponent(org)}/${url.slice(5)}` : url; async function read(url) { const response=await fetch(url,{cache:'no-store',redirect:'manual'}); if(response.status===401 || response.type==='opaqueredirect') { document.dispatchEvent(new CustomEvent('mosaic-signed-out',{detail:{signIn:true}})); throw Error('signed-out'); } if(!response.ok) { const body=await response.json().catch(()=>null); const error=Error('unavailable'); error.status=response.status; error.code=body?.error; throw error; } return response.json(); } + const readAt=url=>read(url); function currentProject(route) { const id=route.match(/^\/(?:projects|chat)\/(?:projects\/|rooms\/)?([0-9a-f-]{36})/i)?.[1]; if(id) return id; @@ -104,8 +107,9 @@ const same=(a,b)=>JSON.stringify(canonical(a))===JSON.stringify(canonical(b)); const material=(d,s)=>d && d.candidate && s?.candidate && same(d.candidate,s.candidate) && d.candidate.request===s.request && d.candidate.project===s.project && d.candidate.mode_revision===s.mode_revision && typeof d.prd==='string' && Array.isArray(d.requirements) && Array.isArray(d.candidate.requirements) && d.requirements.length===d.candidate.requirements.length && d.requirements.every((r,i)=>r && r.id===d.candidate.requirements[i]?.id && r.title===d.candidate.requirements[i]?.title && typeof r.text==='string') && d.snapshot && Number.isSafeInteger(d.snapshot.revision) && d.snapshot.revision>=0 && d.snapshot.id===s.snapshot && (d.snapshot.id===null || requestId(d.snapshot.id) && d.snapshot.revision>0); const ownThreads=(project,threads)=>threads.filter(t=>t.project===project.id && !t.shared && UUID.test(t.id)); - async function gather(project,threads) { - const own=ownThreads(project,threads), key=project.id+':'+String(project.repo)+':'+own.map(t=>t.id).join(','); + async function gather(project,threads,org=null) { + const read=url=>readAt(at(org,url)); + const own=ownThreads(project,threads), key=(org?org+'|':'')+project.id+':'+String(project.repo)+':'+own.map(t=>t.id).join(','); const prior=cache.get(key); if(prior && Date.now()-prior.at<10000) return prior.promise; const started=epoch; const promise=(async()=>{ @@ -133,7 +137,7 @@ const [draft,workspace]=await Promise.all([read(base+'/draft').catch(()=>null),read(base+'/workspace').catch(()=>null)]); return {...item,state,draft:material(draft,state)?draft:null,materialFailed:!!state.candidate && !material(draft,state),workspace}; }))).filter(Boolean); - const [tasks,catalog,room]=await Promise.all([read('/api/bus/tasks').catch(()=>null),read('/api/chat/instances').catch(()=>null),readRoomStatus(project)]); + const [tasks,catalog,room]=await Promise.all([read('/api/bus/tasks').catch(()=>null),read('/api/chat/instances').catch(()=>null),readRoomStatus(project,org)]); const members=Array.isArray(catalog?.rows)?catalog.rows.filter(m=>typeof m?.instance==='string' && own.some(t=>t.instance===m.instance && t.name===t.instance)).length:null; let docs=project.repo ? null : {files:[]}, north=null, recordsMissing=false, northMissing=false, northRecordsMissing=false; if(project.repo && /^[A-Za-z0-9][A-Za-z0-9._/-]{0,200}$/.test(project.repo)) { @@ -145,9 +149,9 @@ })(); cache.set(key,{at:Date.now(),promise}); return promise; } - async function readRoomStatus(project) { + async function readRoomStatus(project,org=null) { try { - const response=await fetch(`/api/chat/rooms/${encodeURIComponent(project.id)}/messages?limit=100`,{cache:'no-store',redirect:'manual'}); + const response=await fetch(at(org,'/api/chat/rooms/')+`${encodeURIComponent(project.id)}/messages?limit=100`,{cache:'no-store',redirect:'manual'}); if(response.status===401 || response.type==='opaqueredirect') { document.dispatchEvent(new CustomEvent('mosaic-signed-out',{detail:{signIn:true}})); return 'Unavailable'; } const body=await response.json(); if(response.ok && Array.isArray(body?.rows) && typeof body.hasMore==='boolean') return 'Open'; @@ -241,15 +245,15 @@ const wanted=new Set((restore.disclosures || []).map(String)), closed=new Set((restore.closed || []).map(String)); [...root.querySelectorAll('details')].forEach((el,i)=>{const key=restoreKey(el,i);if(wanted.has(key)) el.open=true;else if(el.dataset.restoreKey && closed.has(key)) el.open=false;}); const f=restore.projectFocus; if(!f) return; - const focus=f.id ? document.getElementById(f.id) : f.details ? [...root.querySelectorAll('details[data-restore-key]')].find(el=>el.dataset.restoreKey===f.details)?.querySelector(':scope > summary') : root.querySelectorAll(FOCUSABLE)[f.index]; + const focus=f.id ? root.querySelector('#'+CSS.escape(f.id)) : f.details ? [...root.querySelectorAll('details[data-restore-key]')].find(el=>el.dataset.restoreKey===f.details)?.querySelector(':scope > summary') : root.querySelectorAll(FOCUSABLE)[f.index]; focus?.focus({preventScroll:true}); } - async function mountContent({container,project,threads,section,canSend,restore,roomReceipt}) { + async function mountContent({container,project,threads,section,canSend,restore,roomReceipt,org=null,pane=false}) { if(!container || !project) return; const generation=epoch, run=(contentRuns.get(container) || 0)+1; contentRuns.set(container,run); if (!contentPaints.has(container)) container.textContent='Reading…'; - const data=await gather(project,threads).catch(()=>null); + const data=await gather(project,threads,org).catch(()=>null); if(!container.isConnected || generation!==epoch || contentRuns.get(container)!==run || document.body.classList.contains('signed-out')) return; if(!data){contentPaints.delete(container);container.textContent='Project data unavailable. Refresh to try again.';return;} const selected=selectedRequests.get(project.id); @@ -260,12 +264,12 @@ // The generated presentation and separately mounted Markdown determine visible content. const signature=JSON.stringify([view, section==='requirements' ? selectedRequest?.draft?.prd : null, ['requirements','overview'].includes(section) ? data.north?.content : null, data.failed && ['files','tasks'].includes(section)]); const header=container.closest('.chat-area')?.querySelector('.project-tabs'); - if(header){const tasks=header.querySelector(`a[href="${path(project.id,'tasks')}"]`), files=header.querySelector(`a[href="${path(project.id,'files')}"]`);const f=filesData(data);if(tasks && !tasks.querySelector('.project-count') && !data.failed)tasks.insertAdjacentHTML('beforeend',` ${taskRefs(data).length}`);if(files && !files.querySelector('.project-count') && !data.failed && f.docs && data.requests.every(r=>r.workspace?.available===true && Array.isArray(r.workspace.entries)))files.insertAdjacentHTML('beforeend',` ${f.reviewed.length+f.drafts.length+f.docs.length}`);} + if(header){const tab=key=>header.querySelector(`a[href$="${path(project.id,key).slice(1)}"]`), tasks=tab('tasks'), files=tab('files');const f=filesData(data);if(tasks && !tasks.querySelector('.project-count') && !data.failed)tasks.insertAdjacentHTML('beforeend',` ${taskRefs(data).length}`);if(files && !files.querySelector('.project-count') && !data.failed && f.docs && data.requests.every(r=>r.workspace?.available===true && Array.isArray(r.workspace.entries)))files.insertAdjacentHTML('beforeend',` ${f.reviewed.length+f.drafts.length+f.docs.length}`);} revealTab(header); // Retained controls (the request selector) draw from the newest accepted read, even when // this read changes nothing visible and the DOM is kept. contentModels.set(container,{data,project,section,canSend,roomReceipt}); - window.MosaicOnboarding?.offer(container,{project,section,north:data.north,docs:data.docs,threads:data.threads,canSend}); // F2: its panel sits before the container, outside draw(). + if(!pane) window.MosaicOnboarding?.offer(container,{project,section,north:data.north,docs:data.docs,threads:data.threads,canSend}); // F2: its panel sits before the container, outside draw(). if (contentPaints.get(container) === signature) return; contentPaints.set(container, signature); // Capture at commit time: the user may have interacted while the read was pending. @@ -285,7 +289,7 @@ if (restore) { restoreView(container,restore); } - const sectionTarget=new URLSearchParams(location.hash.split('?')[1] || '').get('section'); + const sectionTarget=pane ? null : new URLSearchParams(location.hash.split('?')[1] || '').get('section'); if(section==='requirements' && ['prd','north-star'].includes(sectionTarget)) container.querySelector('#project-'+sectionTarget)?.scrollIntoView({block:'start'}); } // Cut at a word boundary, unless that would leave only a markdown marker (a long heading). @@ -334,7 +338,7 @@ } const palette=()=>treeRows.filter(p=>!p.archived && UUID.test(p.id)).flatMap(p=>sections.map(([key,label])=>({href:path(p.id,key),label:key==='overview'?p.name:`${p.name}: ${label}`,group:'project'}))); function breadcrumb(box, view) { - const h=view.querySelector('.project-header'); if(!h)return false; + const h=view.querySelector('.project-header'); if(!h||h.closest('[data-pane]'))return false; const id=h.dataset.projectId, name=h.dataset.projectName, section=h.dataset.projectSection, conversation=h.dataset.projectConversation==='true'; const title=sections.find(([key])=>key===section)?.[1] || (section==='settings'?'Settings':'Overview'); const leaf=conversation?view.querySelector('h1')?.textContent:title; diff --git a/packages/webui/src/public/workspace.js b/packages/webui/src/public/workspace.js index 3c0758f4a..c43959864 100644 --- a/packages/webui/src/public/workspace.js +++ b/packages/webui/src/public/workspace.js @@ -191,8 +191,10 @@ }).join('')}`; } - async function dashboard() { - const id = window.MosaicOrg.id; + // A side-by-side pane passes its own organization and { pane: true, idPrefix }: the pane has no bus + // restart (that stays in the organization's full view) and its ids carry the pane's prefix. + async function dashboard(id = window.MosaicOrg.id, opts = {}) { + const pane = opts.pane === true, why = `${opts.idPrefix || ''}ws-reload-why`; // Only an organization the membership list names is read; anything else reads nothing more. const [listRead] = await Promise.all([data.organizations().catch(() => null), ensureThemes()]); const list = Array.isArray(listRead) ? listRead : null; @@ -210,11 +212,12 @@ // Header: the bus restart is console-restart.js's button where the Console allows it, otherwise // the same control, present and disabled, with the reason. - const restart = window.MosaicConsole?.busButton?.('Restart bus') || ''; - const bus = restart ? `${icon('restart', 'ws-busicon')}${restart}` : ``; - const reload = ``; + const restart = pane ? '' : window.MosaicConsole?.busButton?.('Restart bus') || ''; + const offTitle = pane ? "Restart the bus from this organization's full view" : "Restarting the bus is the owner's trailed action, on a Console started with send and the action trail"; + const bus = restart ? `${icon('restart', 'ws-busicon')}${restart}` : ``; + const reload = ``; const [bcls, bglyph] = state(org); - const meta = ``; + const meta = ``; const projectName = pid => projectRows?.find(p => p.id === pid)?.name || pid; const typechips = '| Agent | Level | Status |
|---|
Agents are defined at three levels: root, organization and project. Root and project agents are read from their files and are not launched yet.${note ? ` ${note}` : ''}
Organizations unavailable.
The selected organization is not on the list.
' : levelsTable(ctx, pick); const rules = `rootYou define root agents in agents.json in your configuration directory. The chief cannot change them.
orgAgents come from the organization file. Add, change or remove them under Settings, Agents.
projectA project in the organization file can add an agent, narrow an inherited agent's limits or exclude one. It never widens them.
overrideThe most specific level wins. A row says which definition it replaces.
An agent's harness, model and thinking are set under Settings, Routing.