diff --git a/apps/web/__tests__/DecisionsView.images.test.tsx b/apps/web/__tests__/DecisionsView.images.test.tsx new file mode 100644 index 0000000000..1385d5962f --- /dev/null +++ b/apps/web/__tests__/DecisionsView.images.test.tsx @@ -0,0 +1,275 @@ +/** + * #1938: images in decision items. A workspace path is fetched with the key and shown as an object + * URL, revoked on cleanup; an http(s) URL is left to the browser; anything else, and any refusal, + * shows a note in place of the image. The browser itself never requests a workspace path. + */ +import { describe, it, expect, vi, afterEach, beforeEach } from 'vitest'; +import { render, screen, cleanup, waitFor, fireEvent } from '@testing-library/react'; +import { TOWER_KEY_HEADER } from '@cluesmith/codev-types'; +import type { DecisionItem, DecisionsDocument } from '@cluesmith/codev-types'; +import type { DecisionsState } from '../src/hooks/useDecisions.js'; + +const mockUseDecisions = vi.fn<(isActive: boolean) => { state: DecisionsState; applyDocument: () => void }>(); +vi.mock('../src/hooks/useDecisions.js', () => ({ + useDecisions: (isActive: boolean) => mockUseDecisions(isActive), +})); + +import { DecisionsView } from '../src/components/DecisionsView.js'; + +const PNG = new Uint8Array([0x89, 0x50, 0x4e, 0x47]); + +function makeDocument(item: Partial, ruledMarkdown = ''): DecisionsDocument { + return { + path: 'codev/state/pending-decisions.md', + version: 'v1', + items: [{ + id: 'web-4', + stamp: null, + question: 'Compact or stacked?', + bodyMarkdown: '', + options: [], + currentRuling: '', + qa: [], + fingerprint: 'fp-web-4', + problems: [], + writable: true, + ...item, + }], + ruledMarkdown, + problems: [], + }; +} + +function show(item: Partial, ruledMarkdown = '') { + mockUseDecisions.mockReturnValue({ state: { status: 'ready', document: makeDocument(item, ruledMarkdown) }, applyDocument: () => {} }); + return render(); +} + +function imageResponse(): Response { + return new Response(PNG, { status: 200, headers: { 'Content-Type': 'image/png' } }); +} + +function refusalResponse(status: number, code: string, message: string): Response { + return new Response(JSON.stringify({ ok: false, code, message }), { status, headers: { 'Content-Type': 'application/json' } }); +} + +/** The `path` each image request asked for, in order. */ +function requestedPaths(): string[] { + return fetchMock.mock.calls.map(([url]) => new URL(String(url), 'http://dashboard.test/').searchParams.get('path') ?? ''); +} + +let fetchMock: ReturnType>; +let createObjectURL: ReturnType string>>; +let revokeObjectURL: ReturnType void>>; +let nextUrl: number; + +type KeyedWindow = Window & { __CODEV_TOWER_KEY__?: string }; + +beforeEach(() => { + // The key as Tower injects it into the dashboard shell. + (window as KeyedWindow).__CODEV_TOWER_KEY__ = 'the-key'; + fetchMock = vi.fn(async () => imageResponse()); + vi.stubGlobal('fetch', fetchMock); + nextUrl = 0; + createObjectURL = vi.fn(() => `blob:http://dashboard.test/${++nextUrl}`); + revokeObjectURL = vi.fn(); + // jsdom has no object URLs. + Object.assign(URL, { createObjectURL, revokeObjectURL }); +}); + +afterEach(() => { + cleanup(); + mockUseDecisions.mockReset(); + vi.unstubAllGlobals(); + vi.restoreAllMocks(); + delete (window as KeyedWindow).__CODEV_TOWER_KEY__; +}); + +describe('DecisionsView images (#1938)', () => { + it('fetches a workspace image with the key and shows it from an object URL', async () => { + let respond!: (res: Response) => void; + fetchMock.mockReturnValueOnce(new Promise(resolve => { respond = resolve; })); + show({ bodyMarkdown: '![Compact layout](decision-assets/web-4-compact.png)' }); + + // Until it loads, the browser has no source to request against the dashboard URL. + const image = screen.getByRole('img', { name: 'Compact layout' }); + expect(image).not.toHaveAttribute('src'); + expect(requestedPaths()).toEqual(['decision-assets/web-4-compact.png']); + const [url, init] = fetchMock.mock.calls[0]; + expect(String(url)).toMatch(/api\/decisions\/image\?path=decision-assets%2Fweb-4-compact\.png$/); + expect(init?.headers).toEqual({ [TOWER_KEY_HEADER]: 'the-key' }); + + respond(imageResponse()); + await waitFor(() => expect(image).toHaveAttribute('src', 'blob:http://dashboard.test/1')); + expect(createObjectURL).toHaveBeenCalledOnce(); + }); + + it('sends a `/`-rooted path as written, and a percent-encoded name decoded', async () => { + show({ bodyMarkdown: '![one](/docs/stacked.svg) ![two]()' }); + await waitFor(() => expect(createObjectURL).toHaveBeenCalledTimes(2)); + expect(requestedPaths()).toEqual(['/docs/stacked.svg', 'decision-assets/my shot.png']); + }); + + it('fetches the file a source names, without its ?query or #fragment', async () => { + show({ bodyMarkdown: '![cached](shot.png?v=2) ![anchored](diagram.svg#part)' }); + await waitFor(() => expect(createObjectURL).toHaveBeenCalledTimes(2)); + expect(requestedPaths()).toEqual(['shot.png', 'diagram.svg']); + }); + + it('drops srcset, which would make the browser load a candidate itself', async () => { + const { container } = show({ + bodyMarkdown: 'raw web', + }); + expect(container.querySelectorAll('img[srcset]')).toHaveLength(0); + expect(screen.getByRole('img', { name: 'web' })).toHaveAttribute('src', 'https://example.com/x.png'); + await waitFor(() => expect(screen.getByRole('img', { name: 'raw' })).toHaveAttribute('src', 'blob:http://dashboard.test/1')); + expect(requestedPaths()).toEqual(['a.png']); + }); + + it('loads images in the body, the question-and-answer thread and the ruled section', async () => { + show( + { + bodyMarkdown: '![body](a.png)', + qa: [{ kind: 'answer', name: 'Web', time: '7:00 am', markdown: 'Like this: ![answer](b.png)' }], + }, + '- **web-3** · ruled `keep` ![ruled](c.png)', + ); + await waitFor(() => expect(requestedPaths()).toEqual(['a.png', 'b.png', 'c.png'])); + }); + + it('shows a refused image as not loaded: its alt text and its path, with the reason', async () => { + const reason = 'The image ../../outside.png is outside the workspace, so it was not read.'; + fetchMock.mockResolvedValueOnce(refusalResponse(400, 'outside-workspace', reason)); + const { container } = show({ bodyMarkdown: '![Escape](../../outside.png)' }); + + const note = await screen.findByText('Image not loaded'); + expect(note.parentElement).toHaveTextContent('Image not loaded Escape ../../outside.png'); + expect(note.parentElement).toHaveAttribute('title', reason); + expect(container.querySelector('img')).toBeNull(); + expect(createObjectURL).not.toHaveBeenCalled(); + }); + + it.each([ + ['a network failure', () => Promise.reject(new TypeError('Failed to fetch')), 'Could not reach Tower: Failed to fetch'], + ['a response that is not an image', () => Promise.resolve(new Response('', { status: 200, headers: { 'Content-Type': 'text/html' } })), 'Unexpected response from Tower (HTTP 200)'], + ])('shows %s as not loaded', async (_what, respond, reason) => { + fetchMock.mockImplementationOnce(respond); + show({ bodyMarkdown: '![Shot](shot.png)' }); + const note = await screen.findByText('Image not loaded'); + expect(note.parentElement).toHaveAttribute('title', reason); + }); + + it('shows a file the browser cannot decode as not loaded, not as a broken image', async () => { + show({ bodyMarkdown: '![Corrupt](corrupt.png)' }); + const image = screen.getByRole('img', { name: 'Corrupt' }); + await waitFor(() => expect(image).toHaveAttribute('src')); + fireEvent.error(image); + expect(screen.getByText('Image not loaded').parentElement).toHaveTextContent('Corrupt corrupt.png'); + expect(screen.queryByRole('img', { name: 'Corrupt' })).toBeNull(); + }); + + it('never loads a data: URL, another scheme or a protocol-relative URL', () => { + const { container } = show({ + bodyMarkdown: '![inline](data:image/png;base64,iVBORw0KGgo=) ![ftp](ftp://example.com/x.png) ![relative](//example.com/x.png)', + }); + expect(fetchMock).not.toHaveBeenCalled(); + expect(container.querySelector('img')).toBeNull(); + const notes = screen.getAllByText('Image not loaded').map(label => label.parentElement?.textContent); + expect(notes).toEqual([ + 'Image not loaded inline data:image/png;base64,iVBORw0KGgo=', + 'Image not loaded ftp ftp://example.com/x.png', + 'Image not loaded relative //example.com/x.png', + ]); + }); + + it('leaves an http(s) image to the browser, as before', () => { + show({ bodyMarkdown: '![remote](https://example.com/shot.png)' }); + expect(screen.getByRole('img', { name: 'remote' })).toHaveAttribute('src', 'https://example.com/shot.png'); + expect(fetchMock).not.toHaveBeenCalled(); + }); + + it('revokes the object URL when the markdown changes and when the card goes', async () => { + const { rerender, unmount } = show({ bodyMarkdown: '![first](first.png)' }); + await waitFor(() => expect(screen.getByRole('img', { name: 'first' })).toHaveAttribute('src', 'blob:http://dashboard.test/1')); + + mockUseDecisions.mockReturnValue({ state: { status: 'ready', document: makeDocument({ bodyMarkdown: '![second](second.png)' }) }, applyDocument: () => {} }); + rerender(); + expect(revokeObjectURL).toHaveBeenCalledExactlyOnceWith('blob:http://dashboard.test/1'); + await waitFor(() => expect(screen.getByRole('img', { name: 'second' })).toHaveAttribute('src', 'blob:http://dashboard.test/2')); + + unmount(); + expect(revokeObjectURL).toHaveBeenLastCalledWith('blob:http://dashboard.test/2'); + expect(revokeObjectURL).toHaveBeenCalledTimes(2); + }); + + it('keeps the loaded image, and the link rule, through a re-render with the same markdown', async () => { + const bodyMarkdown = '![same](same.png) [guide](codev/guide.md)'; + const { rerender } = show({ bodyMarkdown }); + const image = screen.getByRole('img', { name: 'same' }); + await waitFor(() => expect(image).toHaveAttribute('src', 'blob:http://dashboard.test/1')); + + // A fresh document with the same item, as each poll or a draft keystroke re-renders the card. + mockUseDecisions.mockReturnValue({ state: { status: 'ready', document: makeDocument({ bodyMarkdown }) }, applyDocument: () => {} }); + rerender(); + expect(screen.getByRole('img', { name: 'same' })).toHaveAttribute('src', 'blob:http://dashboard.test/1'); + expect(screen.getByText('guide').closest('a')).not.toHaveAttribute('href'); + expect(fetchMock).toHaveBeenCalledOnce(); + expect(revokeObjectURL).not.toHaveBeenCalled(); + }); + + it('abandons a load still in flight when the card goes', async () => { + let respond!: (res: Response) => void; + fetchMock.mockReturnValueOnce(new Promise(resolve => { respond = resolve; })); + const { unmount } = show({ bodyMarkdown: '![slow](slow.png)' }); + const signal = fetchMock.mock.calls[0][1]?.signal; + unmount(); + expect(signal?.aborted).toBe(true); + respond(imageResponse()); + await new Promise(resolve => setTimeout(resolve, 0)); + expect(createObjectURL).not.toHaveBeenCalled(); + }); + + describe('clicking an image', () => { + it('opens a loaded workspace image full size on a page that shows it through ', async () => { + const open = vi.spyOn(window, 'open').mockReturnValue(null); + show({ bodyMarkdown: '![Stacked](stacked.svg)' }); + const image = screen.getByRole('img', { name: 'Stacked' }); + await waitFor(() => expect(image).toHaveAttribute('src', 'blob:http://dashboard.test/1')); + + fireEvent.click(image); + expect(open).toHaveBeenCalledExactlyOnceWith('blob:http://dashboard.test/2', '_blank', 'noopener'); + const page = createObjectURL.mock.calls[1][0]; + expect(page.type).toBe('text/html'); + // jsdom's Blob has no text(). + const html = await new Promise(resolve => { + const reader = new FileReader(); + reader.onload = () => resolve(String(reader.result)); + reader.readAsText(page); + }); + expect(html).toMatch(/^/); + expect(html).toContain('Stacked'); + }); + + it('opens an http(s) image itself', () => { + const open = vi.spyOn(window, 'open').mockReturnValue(null); + show({ bodyMarkdown: '![remote](https://example.com/shot.png)' }); + fireEvent.click(screen.getByRole('img', { name: 'remote' })); + expect(open).toHaveBeenCalledExactlyOnceWith('https://example.com/shot.png', '_blank', 'noopener'); + }); + + it('follows the link around an image instead', () => { + const open = vi.spyOn(window, 'open').mockReturnValue(null); + show({ bodyMarkdown: '[![remote](https://example.com/shot.png)](https://example.com/page)' }); + fireEvent.click(screen.getByRole('img', { name: 'remote' })); + expect(open).toHaveBeenCalledExactlyOnceWith('https://example.com/page', '_blank', 'noopener'); + }); + + it('does nothing for an image still loading', () => { + fetchMock.mockReturnValueOnce(new Promise(() => {})); + const open = vi.spyOn(window, 'open').mockReturnValue(null); + show({ bodyMarkdown: '![pending](pending.png)' }); + fireEvent.click(screen.getByRole('img', { name: 'pending' })); + expect(open).not.toHaveBeenCalled(); + }); + }); +}); diff --git a/apps/web/src/components/DecisionsView.tsx b/apps/web/src/components/DecisionsView.tsx index aa6b5d528c..877611c34a 100644 --- a/apps/web/src/components/DecisionsView.tsx +++ b/apps/web/src/components/DecisionsView.tsx @@ -1,8 +1,8 @@ -import { useCallback, useId, useLayoutEffect, useRef, useState } from 'react'; +import { useCallback, useId, useLayoutEffect, useMemo, useRef, useState } from 'react'; import type { FormEvent, MouseEvent, ReactNode } from 'react'; -import { MarkdownView } from '@cluesmith/codev-artifact-canvas'; +import { renderMarkdown } from '@cluesmith/codev-artifact-canvas'; import { useDecisions } from '../hooks/useDecisions.js'; -import { postDecisionRuling } from '../lib/api.js'; +import { fetchDecisionImage, postDecisionRuling } from '../lib/api.js'; import type { DecisionRulingResult, DecisionItem, @@ -103,28 +103,114 @@ export const STAMP_TIME_FORMAT: Intl.DateTimeFormatOptions = { const EXTERNAL_LINK_RE = /^https?:\/\//i; +/** How long a full-size image page stays openable after the click that made it. */ +const FULL_SIZE_PAGE_MS = 60_000; + +/** + * Open an image full size in a new tab. A workspace image is a blob of the dashboard's origin, + * so it is shown on a page holding only an `` of it: an SVG opened as a document itself + * would run its scripts as the dashboard. + */ +function openFullSize(image: HTMLImageElement) { + const src = image.getAttribute('src') ?? ''; + if (EXTERNAL_LINK_RE.test(src)) { + window.open(src, '_blank', 'noopener'); + return; + } + if (!src.startsWith('blob:')) return; + const page = document.implementation.createHTMLDocument(image.alt || 'Image'); + const full = page.createElement('img'); + full.alt = image.alt; + full.src = src; + page.body.append(full); + const pageUrl = URL.createObjectURL(new Blob([`${page.documentElement.outerHTML}`], { type: 'text/html' })); + window.open(pageUrl, '_blank', 'noopener'); + setTimeout(() => URL.revokeObjectURL(pageUrl), FULL_SIZE_PAGE_MS); +} + /** - * One handler for every link in the view, since item bodies are injected HTML: http(s) links - * open in a new browser tab, any other link is inert, and the dashboard never navigates away. + * One handler for every link and image in the view, since item bodies are injected HTML: http(s) + * links open in a new browser tab, any other link is inert, an image (outside a link) opens full + * size, and the dashboard never navigates away. */ function handleLinkClick(event: MouseEvent) { if (!(event.target instanceof Element)) return; const anchor = event.target.closest('a'); - if (!anchor) return; + if (!anchor) { + if (event.target instanceof HTMLImageElement) openFullSize(event.target); + return; + } event.preventDefault(); const href = anchor.getAttribute('href')?.trim() ?? ''; if (EXTERNAL_LINK_RE.test(href)) window.open(href, '_blank', 'noopener'); } +/** Where an image the browser must not load itself keeps its source until the tab loads it. */ +const PARKED_SRC = 'data-decisions-src'; +const URL_SCHEME_RE = /^[a-z][a-z0-9+.-]*:/i; +/** The longest source a not-loaded note shows; a `data:` URL can run to megabytes. */ +const MAX_SHOWN_SOURCE = 200; + +/** + * The item markdown as HTML, with every image source that is not an http(s) URL parked in + * {@link PARKED_SRC}: the browser would resolve a workspace path against the dashboard URL, + * where Tower's key-gated routes cannot answer it, and must not show a `data:` image at all. + * Parsed in an inert document, so nothing loads before the source is parked. + */ +function decisionsHtml(source: string): string { + const page = new DOMParser().parseFromString(renderMarkdown(source), 'text/html'); + for (const image of page.querySelectorAll('img')) { + image.removeAttribute('srcset'); + const src = image.getAttribute('src')?.trim() ?? ''; + if (EXTERNAL_LINK_RE.test(src)) continue; + image.removeAttribute('src'); + image.setAttribute(PARKED_SRC, src); + } + return page.body.innerHTML; +} + +/** The workspace path an image source names, or null for a URL of any other kind. */ +function workspaceImagePath(src: string): string | null { + if (src === '' || src.startsWith('//') || URL_SCHEME_RE.test(src)) return null; + try { + // The source is a URL reference: a `?query` or `#fragment` is not part of the file name, and the + // renderer percent-encodes the rest (`my shot.png` → `my%20shot.png`), so the file is the decoded path. + return decodeURIComponent(src.replace(/[?#].*$/s, '')); + } catch { + return null; + } +} + +/** Put a note in place of an image that was not loaded: its alt text and its source as written. */ +function showNotLoaded(image: HTMLImageElement, source: string, reason: string) { + const note = document.createElement('span'); + note.className = 'decisions-image-missing'; + note.title = reason; + const label = document.createElement('span'); + label.className = 'decisions-image-missing-label'; + label.textContent = 'Image not loaded'; + const path = document.createElement('code'); + path.textContent = source.length > MAX_SHOWN_SOURCE ? `${source.slice(0, MAX_SHOWN_SOURCE)}…` : source; + note.append(label, image.alt ? ` ${image.alt} ` : ' ', path); + image.replaceWith(note); +} + /** - * `MarkdownView` with the same rule applied to the rendered anchors themselves, so it also holds - * for a middle-click, the context menu or the keyboard: an http(s) link opens in a new tab, and - * any other link loses its `href`, leaving nothing to open. The shared renderer is unchanged. + * The shared markdown renderer, with the view's rules applied to what it renders. An http(s) link + * opens in a new tab and any other link loses its `href`, so the rule also holds for a + * middle-click, the context menu or the keyboard. An http(s) image loads as the browser would; any + * other image source is a workspace path the tab fetches with the key and shows as an object URL, + * revoked when the markdown changes or leaves, or it is a note saying the image was not loaded. */ function DecisionsMarkdown({ source }: { source: string }) { const ref = useRef(null); + // One object per source: React 19 compares this prop by identity and re-sets the HTML whenever + // it changes, which would wipe what the effect below did while the effect does not run again. + const markup = useMemo(() => ({ __html: decisionsHtml(source) }), [source]); useLayoutEffect(() => { - for (const anchor of ref.current?.querySelectorAll('a') ?? []) { + const root = ref.current; + if (!root) return; + for (const anchor of root.querySelectorAll('a')) { const href = anchor.getAttribute('href')?.trim() ?? ''; if (EXTERNAL_LINK_RE.test(href)) { anchor.target = '_blank'; @@ -133,8 +219,37 @@ function DecisionsMarkdown({ source }: { source: string }) { anchor.removeAttribute('href'); } } - }, [source]); - return
; + const controller = new AbortController(); + const objectUrls: string[] = []; + for (const image of root.querySelectorAll(`img[${PARKED_SRC}]`)) { + const written = image.getAttribute(PARKED_SRC) ?? ''; + const path = workspaceImagePath(written); + if (path === null) { + showNotLoaded(image, written, 'Only an http(s) URL or a path in the workspace is shown.'); + continue; + } + void fetchDecisionImage(path, controller.signal).then(result => { + if (controller.signal.aborted) return; + if (result.kind === 'not-loaded') { + showNotLoaded(image, path, result.message); + return; + } + const url = URL.createObjectURL(result.blob); + objectUrls.push(url); + image.addEventListener('error', () => showNotLoaded(image, path, 'The browser could not show this file as an image.'), { once: true }); + image.src = url; + }); + } + return () => { + controller.abort(); + for (const url of objectUrls) URL.revokeObjectURL(url); + }; + }, [markup]); + return ( +
+
+
+ ); } /** What a submit writes under the item, and what a held draft shows: the word, a blank line, the comment. */ diff --git a/apps/web/src/index.css b/apps/web/src/index.css index 483b9e004f..8f1dd98317 100644 --- a/apps/web/src/index.css +++ b/apps/web/src/index.css @@ -2542,6 +2542,36 @@ a.attention-row { overflow-wrap: anywhere; } +/* An image in an item (#1938) never widens the card and keeps its aspect ratio; a click opens it + full size in a new tab. */ +.decisions-view .codev-artifact-canvas-rendered img { + max-width: 100%; + max-height: 480px; + object-fit: contain; + vertical-align: top; + cursor: zoom-in; +} + +.decisions-view .codev-artifact-canvas-rendered a img { + cursor: pointer; +} + +/* In place of an image that was not loaded: its alt text and its path, never a broken icon. */ +.decisions-image-missing { + display: inline-block; + max-width: 100%; + padding: 4px 8px; + border: 1px dashed var(--status-waiting); + border-radius: 4px; + font-size: 12px; + color: var(--text-secondary); +} + +.decisions-image-missing-label { + font-weight: 600; + color: var(--status-waiting); +} + .decisions-cards { display: flex; flex-direction: column; diff --git a/apps/web/src/lib/api.ts b/apps/web/src/lib/api.ts index 75fec9769b..631d84fed6 100644 --- a/apps/web/src/lib/api.ts +++ b/apps/web/src/lib/api.ts @@ -191,6 +191,31 @@ export async function fetchDecisions(): Promise { : { kind: 'error', message: result.message }; } +/** #1938: an image an item references, or why it was not loaded. Never thrown. */ +export type DecisionImageResult = + | { kind: 'image'; blob: Blob } + | { kind: 'not-loaded'; message: string }; + +/** + * #1938: fetch an image from the workspace with the key, which an `` request cannot carry. + * `path` is as written in the item: relative to the decisions file, or `/`-rooted at the workspace. + */ +export async function fetchDecisionImage(path: string, signal: AbortSignal): Promise { + try { + const res = await fetch(apiUrl(`api/decisions/image?path=${encodeURIComponent(path)}`), { headers: getAuthHeaders(), signal }); + if (res.ok && res.headers.get('Content-Type')?.startsWith('image/')) { + return { kind: 'image', blob: await res.blob() }; + } + const body: unknown = await res.json().catch(() => null); + if (isRecord(body) && body.ok === false && typeof body.message === 'string') { + return { kind: 'not-loaded', message: body.message }; + } + return { kind: 'not-loaded', message: `Unexpected response from Tower (HTTP ${res.status})` }; + } catch (err) { + return { kind: 'not-loaded', message: `Could not reach Tower: ${err instanceof Error ? err.message : String(err)}` }; + } +} + /** Spec 1819: write the owner's ruling into the decisions file; success carries the re-parsed document. */ export async function postDecisionRuling(request: DecisionsRuleRequest): Promise { return requestDecisions('api/decisions/rule', { diff --git a/codev-skeleton/resources/commands/agent-farm.md b/codev-skeleton/resources/commands/agent-farm.md index a535a5346a..92018ae51b 100644 --- a/codev-skeleton/resources/commands/agent-farm.md +++ b/codev-skeleton/resources/commands/agent-farm.md @@ -1010,7 +1010,7 @@ Both are Tower-global (they apply to the whole Tower, not per-project) and optio Turn the tab on with `afx decisions init`. It creates the decisions file from its template, prints where it went, and gives the one sentence to tell the main architect: "Route every ask for my word through the decisions file." It refuses a file that already exists, because that file holds the owner's rulings, and a path outside the workspace. `--path ` creates another file, relative to the workspace root; the tab shows it once `dashboard.decisionsFile` names it. -When a workspace has a pending-decisions file, the dashboard shows a **Decisions** tab (Spec 1819). The tab is a view of that file. Each item under `## Open` becomes a card with a click box per option (the first option, the recommended one, is marked) and a comment box. Submitting writes the chosen word, then the comment, on the lines right after the item's `**Your word:**` line, exactly as the owner would type them, and changes nothing else. `## Ruled` is shown below as a collapsed, read-only list. The file is the only state. While the tab is open it re-reads the file every 2 seconds, so edits made elsewhere appear without a reload, and an unsent draft survives them. +When a workspace has a pending-decisions file, the dashboard shows a **Decisions** tab (Spec 1819). The tab is a view of that file. Each item under `## Open` becomes a card with a click box per option (the first option, the recommended one, is marked) and a comment box. Submitting writes the chosen word, then the comment, on the lines right after the item's `**Your word:**` line, exactly as the owner would type them, and changes nothing else. `## Ruled` is shown below as a collapsed, read-only list. An image in an item's markdown shows inline: a relative path is read from the decisions file's directory (keep the files in `decision-assets/` beside it), a `/`-rooted one from the workspace root, and only PNG, JPEG, GIF, WebP and SVG files up to 10 MB inside the workspace are shown; any other image appears as its alt text and path, marked not loaded. The file is the only state. While the tab is open it re-reads the file every 2 seconds, so edits made elsewhere appear without a reload, and an unsent draft survives them. The file's format and the process around it are in [`decision-protocol.md`](../decision-protocol.md): one hub architect, `main`, is the only agent that edits the file, other architects send it their items, and the hub relays each ruling. The tab reads exactly the item format that document describes. diff --git a/codev-skeleton/resources/decision-protocol.md b/codev-skeleton/resources/decision-protocol.md index 85db58a8b0..d5a0865d94 100644 --- a/codev-skeleton/resources/decision-protocol.md +++ b/codev-skeleton/resources/decision-protocol.md @@ -90,6 +90,14 @@ per option and a comment box. - **Questions and answers** are body lines above the word line, `- **You asked (