Skip to content

src/dashboard — the dashboard host

The dashboard's extension-host side: the state builder and intent router behind the zer0Cms.dashboard tab, whose UI lives in src/webview/dashboard/.

One file: dashboardPanel.ts, the extension-host side of the zer0Cms.dashboard editor tab. The UI it drives lives in src/webview/dashboard/; this directory contains no DOM code and the webview contains no vscode import. That split is the whole architecture, and it is enforced by eslint and by the build.

src/dashboard/dashboardPanel.ts     ← you are here: state builder + intent router
        │  postMessage({type:'state', state})
        ▼
dist/dashboard.js  ←  src/webview/dashboard/{main,header,contents,structure}.ts
                                            {governance,catering,fleet,settings,welcome}.ts
        │  postMessage({type:'command', id, args})
        ▼
src/commands/**  ← the same functions the command palette calls

What the host owns

# Job Where
1 Building one full DashboardState snapshot per post buildState() and the build* projections
2 The closed intent whitelist (Record<CommandId, Handler>) dispatch()
3 Routing the two governed intents into the injected GovernanceActions, and the two fleet intents into the injected FleetActions runGovernance(), runFleet()
4 Round-tripping the durable UI preferences through workspaceState UI_STATE_KEYS, writeUiState()
5 Three request ops: searchContent, guardText, previewDraft handleRequest()
6 The CSP'd page shell with a per-render nonce dashboardHtml()

Everything else — which tab is open, which sort order, which rows are ticked — is view-local state that lives in the webview and is not authoritative anywhere.

Decision D5, concretely

draft.approve and draft.publish do not go through vscode.commands.executeCommand. They call the GovernanceActions injected by extension.ts, which are the very doApprove/doPublish closures src/commands/governance.ts registers for the palette. Those re-read the draft from disk, re-run the brand guard, re-evaluate evaluatePublishGates() and ask modally before writing a byte.

The webview supplies a draft path and nothing else. The blockers rendered under a disabled Publish button come from buildReview() and are advisory: the ones that decide are computed again, later, in a different process boundary.

fleet.toggleSwitch and fleet.dispatchLane are the same shape. They call the FleetActions injected by extension.ts — doToggleSwitch/doDispatchLane from src/commands/fleet.ts — which re-read fleet.manifest.yml, re-run evaluateFleetGates(), obtain the GitHub session lazily and ask modally. The webview supplies a lane id and nothing else; the toggle's new value is derived host-side from the variable as fetched inside the action. buildFleet() re-reads the manifest on every snapshot (one small file) but never touches the network: the switch and run columns come from the last live read, which only a person's act refreshes — fleet.refresh (interactive; may prompt to sign in) or a Route write of fleet (passive; never prompts). Without a read the columns say unknown, and the note above the table says why.

Deleting and renaming are not governed actions — nothing is written to the ledger and no gate applies — so they are implemented here directly, against workspace.fs, with useTrash: true. Both still re-derive their target host-side through contentTargetPath(): the path a message names has to be a file the page index holds, so a forged {"paths":["/home/me/.ssh/id_rsa"]} resolves to nothing. And both ask host-side before acting. The webview's own alert() is a dialog the code that wants the deletion also controls, which makes it a courtesy rather than a gate; the rule that the webview is never the gate has no exception for the one privileged filesystem action on this surface.

The intent whitelist

if (!isCommandId(id) || !Object.hasOwn(this.handlers, id)) { log.warn(…); return; }

Both checks matter. isCommandId rejects anything outside the closed CommandId union in protocol.ts. Object.hasOwn rejects an id that would resolve through Object.prototype — without it a forged {"id":"toString"} looks like a handler and is callable. A forged intent provably runs nothing.

The same doctrine applies twice more: UI_STATE_KEYS is the only set of workspace-state keys the webview can write, and SETTING_KEYS (plus the two dashboard.cardFields.* members) is the only set of settings it can change. zer0Cms.governance.publishAllow is deliberately not in that table — the publish switch is not something a webview may flip.

Durable UI state

Four preferences must survive the webview being disposed. They are stored under the keys PLAN §4.5 names, inconsistent prefixes and all, because those are the keys an existing workspace already holds:

webview key workspace-state key
Contents:Sorting zer0Cms:Dashboard:Contents:Sorting
Contents:Grouping zer0Cms:Dashboard:Contents:Grouping
Contents:Tab zer0Cms:Dashboard:Contents:Tab
PagesView zer0Cms:PagesView
SelectedFolder zer0Cms:SelectedFolder
Route zer0Cms:Dashboard:Route
Drafts:Selected zer0Cms:Dashboard:Drafts:Selected

Two of them feed back into the snapshot: Contents:Sorting becomes contents.defaultSorting and PagesView becomes contents.defaultView, so a reopened dashboard is sorted the way you left it. Route becomes the boot route templated into the shell as data-route. Drafts:Selected is the one key whose write triggers a re-post, because the review pane it selects is built here rather than in the webview.

The review pane is expensive, so it is built once

buildDrafts() summarises the whole queue but builds a ReviewState for exactly one draft — the selected one, defaulting to the first pending entry. That single build reads the draft, runs guardWithWorkspace and calls buildPreview, which resolves the source page and composes the exact artifact that would be published. A preview failure is not swallowed: it becomes the previewFailed blocker, because "we could not build it" is itself a reason not to publish.

Deliberate simplifications

  • No image previews on content cards. The webview's localResourceRoots are media/ and dist/ and nothing else (PLAN §4.4), so a workspace image has no loadable URI. Widening the roots to the whole repository to put a thumbnail on a card is not a trade worth making; contents.ts renders <img> only for https:/data: references and the markdown glyph otherwise.
  • The lane empty-state sentences are imported, not copied. LANE_EMPTY_STATES comes from core/catering/worklist.ts, the module that also writes those sentences into .cms/distribution/worklists/<date>.md; buildCatering picks between lane B's two variants with the real hasEvidence(plan). This host is Node, so it can reach that module — the screen and the generated file are two renderings of one definition and cannot disagree. The dashboard bundle keeps a fallback copy (EMPTY_STATES in src/webview/dashboard/catering.ts) because a browser cannot import node:fs; that one is a mirror and is commented as such.
  • customSorting and grouping are read from zer0.json directly (customDashboardConfig()), not from Zer0Config. They are a dashboard nicety rather than part of the content model, so resolveConfig has no field for them. Entries are coerced defensively and a customSorting id follows Front Matter's <field>-<asc|desc> convention, which is how the webview applies a sort it has never seen without a second schema.
  • open(route) routes a new panel only. The route is validated against the closed route set and templated into data-route; an already-open panel is revealed. The manifest's zer0Cms.dashboard command takes no argument, so nothing in the shipped surface hits the other case.

Changing this file

  • A new intent needs three things: a literal in CommandId (src/webview/shared/protocol.ts), an entry in this.handlers, and a caller in the webview. Adding the literal alone grants nothing.
  • A new piece of state belongs in DashboardState in protocol.ts first, then in buildState(). Do not smuggle data through data-* attributes on the shell — the one there now is a validated enum literal, and that is the whole budget.
  • Nothing that renders belongs here. If you are writing el( in this directory, it is in the wrong file.