@popcorn245/cornfield 0.31.0 → 0.32.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/README.md CHANGED
@@ -41,9 +41,9 @@ ssh -L 3350:127.0.0.1:3350 you@the-machine
41
41
  - **The map.** WebGL2 (Canvas 2D fallback), 5,000 nodes and 15,000 edges at frame rate. Orbit, data-flow and House views, layers, search, focus, freeform drag. `/?fixture=5k&bench=1` measures it. All of it works by keyboard, and a screen reader is told where you are: [docs/accessibility.md](docs/accessibility.md).
42
42
  - **Derived, not drawn by hand.** `cornfield sync` runs the derivers named in your config and merges what they find into `topology.json`; hand-written parts (descriptions, flows, anything of a type no deriver owns) are kept. `cornfield validate` fails on drift, so CI keeps the map honest.
43
43
  - **Proposals.** `docs/specs/proposals/NNNN-slug.json` says what a change would add, change and remove, with scenarios. cornfield lists them from your checkout, from every git worktree in the configured worktrees folder and, with sign-in, from your open spec PRs, and shows Before / Diff / After, the scenario player, what-if edits, and Approve / Send back. Writing, reviewing and landing one in your repo: [docs/proposals.md](docs/proposals.md). The format and its validator: [core/proposal.js](core/proposal.js).
44
- - **Issues and pull requests.** With a forge in the config and sign-in, a panel of its pull requests and issues (GitHub; Forgejo behind the same interface), with filters. Select a pull request and the nodes its files are light up on the map, and a failing check lights the tests it names. A Deploys list reads the forge's workflow runs and lights what a selected deploy restarted, from a mapping in the config ([docs/deploys.md](docs/deploys.md)). A maintainer can land a green pull request, re-run a failed check, start a spec on an issue and open the build issue of an approved spec, each one button with a confirm step. A bottom sheet on a phone. A **Release notes** tab drafts the notes from the pull requests merged since the last tag, grouped by what they changed on the map, to copy or to post as a draft release (never published); `cornfield notes` prints the same Markdown. [docs/issues-and-prs.md](docs/issues-and-prs.md).
44
+ - **Issues and pull requests.** With a forge in the config and sign-in, a panel of its pull requests and issues (GitHub; Forgejo behind the same interface), with filters. Select a pull request and the nodes its files are light up on the map, and a failing check lights the tests it names. A Deploys list reads the forge's workflow runs and lights what a selected deploy restarted, from a mapping in the config ([docs/deploys.md](docs/deploys.md)). A maintainer can land a green pull request, re-run a failed check, start a spec on an issue and open the build issue of an approved spec, each one button with a confirm step. A bottom sheet on a phone. A **Release notes …** action on the PRs list drafts the notes from the pull requests merged since the last tag, grouped by what they changed on the map, to copy or to post as a draft release (never published); `cornfield notes` prints the same Markdown. [docs/issues-and-prs.md](docs/issues-and-prs.md).
45
45
  - **Threads.** The panel's Threads tab shows ideas (issues labelled `idea`) and spec PRs' conversations from the forge, read-only, and lights the nodes they mention with `[[node-id]]` or `[[repo/path]]`; a node's panel lists the threads that mention it. "New idea" opens an issue as you. Hooks tell outside code when a thread opens, gets a comment or is linked to the map. Nothing is kept in cornfield. [docs/threads.md](docs/threads.md).
46
- - **Agents, tracked.** The panel's Agents tab groups branches, spec PRs and PRs by the issue and the proposal they belong to, and marks the work agents made (by author, bot account, label or branch prefix, set in the config). Nothing is launched. [docs/agents.md](docs/agents.md).
46
+ - **Agents, tracked.** The panel's Runs tab groups branches, spec PRs and PRs by the issue and the proposal they belong to, and marks the work agents made (by author, bot account, label or branch prefix, set in the config). Nothing is launched. [docs/agents.md](docs/agents.md).
47
47
  - **Personas, not people.** `topology.personas.json` holds archetypes (Admin, Member, Guest); scenarios act as them, never as a real person.
48
48
  - **The cloud you do not control.** `topology.cloud.json` describes the outside services; the cloud deriver's detectors (hosts in code, Dockerfiles, container images, CI workflows, a Caddyfile) keep it complete in both directions. "Cloudflare is down" plays as an outage: what breaks now, at the next deploy, at the next certificate renewal. [docs/cloud.md](docs/cloud.md).
49
49
  - **The house, optional.** A House view of floors, rooms, devices, machines and people (as counts), read from a source: a JSON file in your repo, your own API, later Home Assistant. cornfield only displays it. [docs/house.md](docs/house.md).
package/core/strings.js CHANGED
@@ -31,13 +31,13 @@ export const STRINGS = Object.freeze({
31
31
  sendBackWithNote: 'Send back with this note',
32
32
  reviewNoteLabel: 'Note for the drafting agent',
33
33
  reviewNotePlaceholder: 'What should change?',
34
- // The issues and pull requests panel
35
- tabPulls: 'Pull requests',
34
+ // The Work panel: its tabs run in the order of the loop
35
+ tabSpecs: 'Specs',
36
+ tabPulls: 'PRs',
36
37
  tabIssues: 'Issues',
37
38
  tabThreads: 'Threads',
39
+ tabRuns: 'Runs',
38
40
  tabDeploys: 'Deploys',
39
- tabAgents: 'Agents',
40
- tabNotes: 'Release notes',
41
41
  newIdea: 'New idea',
42
42
  landIt: 'Land it',
43
43
  // Agent runs
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * Links from chat that land in the right place (issue #103, docs/agents.md "Deep links"):
5
5
  *
6
- * ?run=<runId> the Agents tab, that run lit and in view
6
+ * ?run=<runId> the Runs tab, that run lit and in view
7
7
  * ?issue=<n> the Issues tab, that issue's Start an agent button focused
8
8
  * ?proposal=<slug>&start=1 the proposal opened (proposal.js) and the Start dialog on it
9
9
  *
@@ -748,14 +748,14 @@ button.hx-proposal-item:focus-visible { outline: var(--corn-focus-width) solid v
748
748
  .hx-forge { position: absolute; top: 0; left: 0; bottom: 0; width: var(--hx-forge-w); border-left: 0; transform: translateX(-100%); box-shadow: var(--corn-shadow-lg); }
749
749
  .hx-forge.forge-open { transform: translateX(0); }
750
750
  /* The proposal bar and the player make room for it: 12px past its edge, and the node panel's 480px (+24) when that is open too */
751
- .hx-stage:has(.forge-open) .hx-proposal-bar { left: calc(var(--hx-forge-w) + 12px); width: min(720px, calc(100% - var(--hx-forge-w) - 36px)); }
752
- .hx-stage:has(.forge-open):has(.drawer-open) .hx-proposal-bar { width: min(720px, calc(100% - var(--hx-forge-w) - 540px)); }
751
+ .hx-stage:has(.forge-open) .hx-proposal-bar { left: calc(var(--hx-forge-w) + 12px); width: min(960px, calc(100% - var(--hx-forge-w) - 36px)); }
752
+ .hx-stage:has(.forge-open):has(.drawer-open) .hx-proposal-bar { width: min(960px, calc(100% - var(--hx-forge-w) - 540px)); }
753
753
  }
754
754
  @media (max-width: 767px) {
755
755
  .hx-forge:not(.forge-open) { display: none; }
756
756
  .hx-forge { max-height: 60dvh; }
757
757
  .hx-forge[data-sheet-state="peek"] .hx-forge-body { flex: none; padding: 0 var(--corn-space-5) var(--corn-space-3); gap: var(--corn-space-1); overflow: hidden; }
758
- .hx-forge[data-sheet-state="peek"] .hx-forge-body > :not(.hx-forge-head):not(#forge-status) { display: none; }
758
+ .hx-forge[data-sheet-state="peek"] .hx-forge-body > :not(.hx-forge-head):not(#forge-bar), .hx-forge[data-sheet-state="peek"] #forge-filter-chip { display: none; }
759
759
  .hx-forge[data-sheet-state="peek"] .hx-forge-head { padding-bottom: 0; border-bottom: 0; }
760
760
  .hx-forge[data-sheet-state="peek"] .hx-forge-head .hx-btn { display: none; }
761
761
  }
@@ -764,11 +764,25 @@ button.hx-proposal-item:focus-visible { outline: var(--corn-focus-width) solid v
764
764
  .hx-forge-head { display: flex; align-items: center; gap: var(--corn-space-3); padding-bottom: var(--corn-space-3); border-bottom: var(--corn-border) solid var(--corn-surface-2); }
765
765
  .hx-forge-head .hx-drawer-title { flex: 1; min-width: 0; }
766
766
  .hx-forge-status, .hx-forge-rate { font-size: var(--corn-text-xs); line-height: 1.5; }
767
- .hx-forge-controls { display: flex; flex-direction: column; gap: var(--corn-space-3); }
768
- .hx-forge-tabs { display: inline-flex; align-self: flex-start; padding: calc(var(--corn-space-1) / 2); border-radius: var(--corn-radius-sm); border: var(--corn-border) solid var(--corn-line); background: color-mix(in srgb, var(--corn-ground) 55%, transparent); }
769
- .hx-forge-tab { padding: var(--corn-space-1) var(--corn-space-4); border: 0; border-radius: var(--corn-radius-sm); background: none; color: var(--corn-text-3); font-size: var(--corn-text-sm); font-weight: 500; }
767
+ .hx-forge-controls { display: flex; flex-direction: column; gap: var(--corn-space-3); padding: var(--corn-space-3); border: var(--corn-border) solid var(--corn-line); border-radius: var(--corn-radius); background: var(--corn-surface-2); } /* the Filter chip's box */
768
+ /* The tabs, in the order of the loop: underlined here, pills that scroll sideways on a phone (below) */
769
+ .hx-forge-tabs { display: flex; gap: calc(var(--corn-space-1) / 2); margin: 0 calc(var(--corn-space-4) * -1); padding: 0 var(--corn-space-4); border-bottom: var(--corn-border) solid var(--corn-line); overflow-x: auto; scrollbar-width: none; }
770
+ .hx-forge-tabs::-webkit-scrollbar { display: none; }
771
+ .hx-forge-tab { flex: none; display: inline-flex; align-items: baseline; gap: var(--corn-space-1); padding: var(--corn-space-2) var(--corn-space-3) var(--corn-space-3); border: 0; border-bottom: var(--corn-border-strong) solid transparent; background: none; white-space: nowrap; color: var(--corn-text-2); font-size: var(--corn-text-sm); font-weight: 500; }
770
772
  .hx-forge-tab:hover { color: var(--corn-text); }
771
- .hx-forge-tab[aria-pressed="true"] { background: var(--corn-accent); color: var(--corn-text-on-accent); box-shadow: var(--corn-shadow-sm); }
773
+ .hx-forge-tab[aria-pressed="true"] { border-bottom-color: var(--corn-accent); color: var(--corn-text); font-weight: 600; }
774
+ .hx-forge-tab:focus-visible, .hx-forge-chip:focus-visible, .hx-forge-back:focus-visible { outline: var(--corn-focus-width) solid var(--corn-focus); outline-offset: -2px; }
775
+ .hx-forge-count { color: var(--corn-text-3); font-size: var(--corn-text-xs); font-weight: 500; }
776
+ .hx-forge-count[hidden] { display: none; }
777
+ /* The status line and the Filter chip; the focus is put on the title (a heading, tabindex -1) when the panel opens, so it shows no ring */
778
+ .hx-forge-body > * { flex-shrink: 0; } /* a tall detail scrolls the body; it must not squash the tabs */
779
+ .hx-forge .hx-drawer-title:focus-visible, .hx-forge-notes-title:focus-visible { outline: none; }
780
+ .hx-forge-bar { display: flex; align-items: center; gap: var(--corn-space-3); min-height: 28px; }
781
+ .hx-forge-bar .hx-forge-status { flex: 1; min-width: 0; }
782
+ .hx-forge-chip { flex: none; display: inline-flex; align-items: center; gap: var(--corn-space-1); min-height: 24px; padding: 0 var(--corn-space-3); border: var(--corn-border) solid var(--corn-line); border-radius: var(--corn-radius-pill); background: none; color: var(--corn-text-2); font-size: var(--corn-text-xs); }
783
+ .hx-forge-chip:hover { background: var(--corn-surface-3); color: var(--corn-text); }
784
+ .hx-forge-chip[aria-expanded="true"], .hx-forge-chip.is-on { border-color: var(--corn-accent); color: var(--corn-text); }
785
+ .hx-forge-bar[hidden], .hx-forge-chip[hidden], .hx-forge-controls[hidden], .hx-forge-foot[hidden], .hx-forge-detail[hidden], .hx-forge-notes[hidden] { display: none; }
772
786
  .hx-forge-filters { display: grid; grid-template-columns: 1fr 1fr; gap: var(--corn-space-2) var(--corn-space-3); }
773
787
  .hx-forge-field { display: flex; flex-direction: column; gap: calc(var(--corn-space-1) / 2); min-width: 0; font-size: var(--corn-text-2xs); font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--corn-text-3); }
774
788
  .hx-forge-field--text { grid-column: 1 / -1; }
@@ -801,10 +815,11 @@ a.hx-forge-row:hover, button.hx-forge-row:hover { background: var(--corn-surface
801
815
  .hx-forge-state--draft, .hx-forge-state--running, .hx-forge-state--queued { color: var(--corn-warn); }
802
816
  .hx-forge-state--neutral, .hx-forge-state--skipped, .hx-forge-state--cancelled { color: var(--corn-text-3); }
803
817
 
804
- .hx-forge-detail { display: flex; flex-direction: column; gap: var(--corn-space-2); padding: var(--corn-space-3); border: var(--corn-border) solid var(--corn-line); border-left: calc(var(--corn-border-strong) * 2) solid var(--corn-accent-text); border-radius: var(--corn-radius); background: color-mix(in srgb, var(--corn-ground) 55%, transparent); }
805
- .hx-forge-detail-head { display: flex; align-items: center; justify-content: space-between; gap: var(--corn-space-3); }
806
- .hx-forge-detail-title { min-width: 0; font-size: var(--corn-text-md); font-weight: 700; color: var(--corn-text); overflow-wrap: anywhere; }
807
- .hx-forge-sub, .hx-forge-subact, .hx-forge-runs-title, .hx-forge-confirm-title { margin: var(--corn-space-1) 0 0; font-size: var(--corn-text-xs); font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--corn-text-2); }
818
+ .hx-forge-detail { display: flex; flex-direction: column; gap: var(--corn-space-3); }
819
+ .hx-forge-detail-title, .hx-forge-notes-title { margin: 0; min-width: 0; font-size: var(--corn-text-lg); font-weight: 700; letter-spacing: -0.01em; color: var(--corn-text); overflow-wrap: anywhere; }
820
+ /* A section's label, in sentence case */
821
+ .hx-forge-sub, .hx-forge-subact, .hx-forge-runs-title { margin: var(--corn-space-1) 0 0; font-size: var(--corn-text-sm); font-weight: 600; color: var(--corn-text-3); }
822
+ .hx-forge-confirm-title { margin: var(--corn-space-1) 0 0; font-size: var(--corn-text-xs); font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--corn-text-2); }
808
823
  .hx-forge-check { display: flex; flex-wrap: wrap; align-items: center; gap: calc(var(--corn-space-1) / 2) var(--corn-space-2); }
809
824
  .hx-forge-check .hx-link { display: inline-flex; align-items: center; min-height: 24px; }
810
825
  .hx-forge-lights { flex-basis: 100%; font-size: var(--corn-text-xs); line-height: 1.5; }
@@ -813,7 +828,6 @@ a.hx-forge-row:hover, button.hx-forge-row:hover { background: var(--corn-surface
813
828
  .hx-forge-fstatus { flex: none; min-width: var(--hx-forge-status-w); color: var(--corn-text-3); font-size: var(--corn-text-xs); }
814
829
  .hx-forge-del { color: var(--corn-bad); }
815
830
  .hx-forge-act { align-self: flex-start; min-height: 24px; padding: calc(var(--corn-space-1) / 2) var(--corn-space-3); }
816
- .hx-forge-detail > .hx-forge-act { padding: var(--corn-space-2) var(--corn-space-4); }
817
831
  .hx-forge-why { margin: 0; font-size: var(--corn-text-xs); line-height: 1.5; }
818
832
  .hx-forge-step { display: flex; flex-direction: column; gap: var(--corn-space-1); }
819
833
  .hx-forge-startspec { flex: none; align-self: center; }
@@ -864,6 +878,35 @@ a.hx-forge-row:hover, button.hx-forge-row:hover { background: var(--corn-surface
864
878
  .hx-forge-confirm { padding: var(--corn-space-3); border: var(--corn-border) solid var(--corn-line); border-left: calc(var(--corn-border-strong) * 2) solid var(--corn-added-text); border-radius: var(--corn-radius); background: color-mix(in srgb, var(--corn-ground) 55%, transparent); line-height: 1.5; }
865
879
  .hx-forge-runs { display: flex; flex-direction: column; gap: var(--corn-space-2); margin: var(--corn-space-1) 0 var(--corn-space-3); }
866
880
  .hx-forge-runs[hidden] { display: none; }
881
+ /* A Specs row: title and state on one line, a line of what it is, the facts */
882
+ .hx-forge-line { display: flex; align-items: center; gap: var(--corn-space-3); }
883
+ .hx-forge-line .hx-forge-title { flex: 1; min-width: 0; }
884
+ .hx-forge-sum { color: var(--corn-text-2); line-height: 1.4; overflow-wrap: anywhere; }
885
+ .hx-forge-facts { display: flex; flex-wrap: wrap; gap: 0 var(--corn-space-3); }
886
+ .hx-forge-add { color: var(--corn-added-text); }
887
+ .hx-forge-chg { color: var(--corn-warn); }
888
+ /* A selection replaces the list, with a back control named by the list; Land it is the one primary action */
889
+ .hx-forge-back { align-self: flex-start; display: inline-flex; align-items: center; gap: var(--corn-space-2); min-height: 28px; margin-left: calc(var(--corn-space-2) * -1); padding: 0 var(--corn-space-3) 0 var(--corn-space-2); border: 0; border-radius: var(--corn-radius-sm); background: none; color: var(--corn-text-2); font-size: var(--corn-text-xs); }
890
+ .hx-forge-back:hover { background: var(--corn-surface-3); color: var(--corn-text); }
891
+ .hx-forge-dmeta { display: flex; flex-wrap: wrap; align-items: center; gap: var(--corn-space-1) var(--corn-space-3); }
892
+ .hx-forge-cta { display: flex; flex-wrap: wrap; gap: var(--corn-space-3); }
893
+ .hx-forge-cta .hx-btn { min-height: 32px; justify-content: center; }
894
+ .hx-forge-cta .hx-btn--approve { flex: 1; }
895
+ .hx-forge-cta .hx-btn[disabled] { background: var(--corn-surface-3); border-color: var(--corn-line); color: var(--corn-text-3); box-shadow: none; cursor: default; }
896
+ .hx-forge-open { text-decoration: none; color: var(--corn-text-2); }
897
+ .hx-forge-runline { display: flex; flex-wrap: wrap; align-items: center; gap: var(--corn-space-2); padding: var(--corn-space-2) var(--corn-space-3); border: var(--corn-border) solid var(--corn-line); border-radius: var(--corn-radius-sm); background: var(--corn-surface-2); }
898
+ /* The foot of a list: Release notes … on PRs, New idea on Specs and Threads */
899
+ .hx-forge-foot { display: flex; flex-direction: column; gap: var(--corn-space-3); margin-top: auto; padding-top: var(--corn-space-3); border-top: var(--corn-border) solid var(--corn-line); }
900
+ .hx-forge-foot > .hx-btn { align-self: flex-start; }
901
+ /* A phone: the tabs are pills, and everything a thumb has to hit is 44px */
902
+ @media (max-width: 767px) {
903
+ .hx-forge-tabs { gap: var(--corn-space-2); padding-bottom: var(--corn-space-3); border-bottom: 0; }
904
+ .hx-forge-tab { align-items: center; min-height: 44px; padding: 0 var(--corn-space-4); border: var(--corn-border) solid var(--corn-line); border-radius: var(--corn-radius-pill); }
905
+ .hx-forge-tab[aria-pressed="true"] { background: var(--corn-accent); border-color: var(--corn-accent); color: var(--corn-text-on-accent); }
906
+ .hx-forge-tab[aria-pressed="true"] .hx-forge-count { color: inherit; }
907
+ .hx-forge .hx-btn, .hx-forge .hx-close, .hx-forge-chip, .hx-forge-back, .hx-forge-node, .hx-forge-toggle, .hx-forge-select, .hx-forge-input, .hx-forge-check .hx-link, .hx-forge-out { min-height: 44px; min-width: 44px; }
908
+ .hx-forge .hx-close { display: inline-flex; align-items: center; justify-content: center; }
909
+ }
867
910
 
868
911
  /* Threads (forge-panel.js, docs/threads.md): messages as written, read-only; a node's "Threads" opens one */
869
912
  .hx-thread-msgs { display: flex; flex-direction: column; gap: var(--corn-space-3); margin: 0; padding: 0; list-style: none; }
@@ -406,7 +406,7 @@ export function mergeBlock(detail) {
406
406
  if (!checks.length) return 'It has no checks, so nothing says it works.';
407
407
  const words = { queued: 'is waiting to run', running: 'is still running', failure: 'failed', cancelled: 'was cancelled' };
408
408
  const not = checks.filter((c) => !GREEN.includes(c.state));
409
- if (not.length) return `Not every check is green: ${not.map((c) => `${c.name} ${words[c.state] || c.state}`).join('; ')}.`;
409
+ if (not.length) return `Can't land yet: ${not.map((c) => `${c.name} ${words[c.state] || c.state}`).join(', ')}.`;
410
410
  if (detail.stale) return 'This is an older answer from the forge: refresh before landing it.';
411
411
  return null;
412
412
  }
@@ -1,7 +1,13 @@
1
1
  /**
2
2
  * @module explorer/forge-panel
3
3
  *
4
- * The issues and PRs panel (CF-07, spec 0001 section 4): the repo's pull requests and issues, from whichever forge
4
+ * The Work panel (CF-07, CF-42, spec 0001 section 4; it began as the issues and PRs panel): Specs, PRs, Issues, Threads, Runs and Deploys, in
5
+ * the order of the loop. Specs lists the proposals the header's Proposals menu lists (proposal.js `proposalListing`), a row opens one. A selection
6
+ * (a PR, a thread, a deploy) REPLACES the list, with a back control named by the list; the State, Label and Author selects sit behind one Filter
7
+ * chip; Release notes is an action at the foot of the PRs list; `openForge({ tab })` opens it on a tab, and any `data-action="toggle-forge"` toggles it.
8
+ * The text below describes each view as it was built.
9
+ *
10
+ * The repo's pull requests and issues, from whichever forge
5
11
  * the config names, read through the server (`/api/forge/…`, server/forge-routes.js; the signed-in maintainer's own
6
12
  * token never leaves it). A header button opens it: a slide-over from the left from 768px, a bottom sheet on a phone
7
13
  * (sheets.js). With no forge in the config, or no sign-in (Stage 1: there is nobody to ask the forge as, and the
@@ -69,7 +75,7 @@ import { relativeTime } from './review-model.js';
69
75
  import { LAYER_DEFS, toggleLayer } from './layers.js';
70
76
  import { WORK_URL, groupWork, filterGroups, groupWords, workStatus, markWords } from './agents-model.js';
71
77
  import {
72
- RUNS_URL, runsUrl, stopUrl, runOnThread, threadRunWords, canRetry, retryRefs, retryWords, limitsFromFields, defaultLimits, LIMIT_KEYS, briefUrl, runTone, answerUrl, answerBody, answerWordsFor, KINDS, aboutWords, statusWords, statusWhy, runMeta, canStop, runsStatus, runnerState, runnerWords, triggerNotice, totalsLines, handLines, startBody, startWords, stopWords, confirmStartWords, litOfRun, changeWords,
78
+ RUNS_URL, runsUrl, stopUrl, runOnThread, threadRunWords, runOnPull, pullRunWords, canRetry, retryRefs, retryWords, limitsFromFields, defaultLimits, LIMIT_KEYS, briefUrl, runTone, answerUrl, answerBody, answerWordsFor, KINDS, aboutWords, statusWords, statusWhy, runMeta, canStop, runsStatus, runnerState, runnerWords, triggerNotice, totalsLines, handLines, startBody, startWords, stopWords, confirmStartWords, litOfRun, changeWords,
73
79
  } from './runs-model.js';
74
80
  import { runsHtml, totalsHtml } from './runs-view.js';
75
81
  import { setRunsOnMap, clearRunsOnMap } from './runs-map.js';
@@ -82,6 +88,8 @@ import {
82
88
  threadsUrl, threadUrl, issueUrl, IDEAS_URL, threadKindWords, threadMeta, litForThread, mentionsIndex, ideaRequest, ideaWords,
83
89
  } from './forge-panel-model.js';
84
90
  import { cornStateAttr } from './corn-state.js';
91
+ import { proposalListing, onProposalListing, loadProposalList } from './proposal.js';
92
+ import { specRowHtml } from './proposal-model.js';
85
93
  import { t } from './strings.js';
86
94
 
87
95
  const $ = (id) => document.getElementById(id);
@@ -92,7 +100,8 @@ const SEARCH_ANNOUNCE_MS = 500;
92
100
  const ui = {
93
101
  config: null,
94
102
  open: false,
95
- kind: 'pulls',
103
+ kind: 'specs', // the tab: specs | pulls | issues | threads | work (Runs) | deploys; 'notes' is the Release notes view, reached from the PRs list
104
+ filtersOpen: false, // the Filter chip's box
96
105
  filters: defaultFilters(),
97
106
  lists: {}, // `${kind}|${server state}` -> { items, at, rate, stale }
98
107
  work: null, // { grouped, problem, at, rate, stale } of the Agents tab
@@ -100,6 +109,7 @@ const ui = {
100
109
  loading: false,
101
110
  error: '',
102
111
  selected: null, // the pull request's number
112
+ selectedOn: '', // the tab it was selected on ('pulls' or 'work')
103
113
  detail: null, // { pull, files, checks, at, rate, stale } of the selected one
104
114
  landing: null, // what waits to land on its approval for the selected pull request ({ slug, by, since }), or null
105
115
  detailError: '',
@@ -152,14 +162,20 @@ let pullToken = 0;
152
162
  let notesToken = 0;
153
163
  let searchTimer = null;
154
164
  let offScene = null;
165
+ let offListing = null;
155
166
  let now = () => Date.now();
156
167
 
157
168
  const forgeName = () => FORGE_NAMES[ui.config && ui.config.forge && ui.config.forge.type] || 'the forge';
158
169
  const listKey = () => listKeyOf(ui.kind, ui.filters.state);
159
- const current = () => (ui.kind === 'work' ? ui.work : ui.lists[listKey()]) || null;
170
+ const current = () => (ui.kind === 'work' ? ui.work : ui.kind === 'specs' ? specsList() : ui.lists[listKey()]) || null;
171
+ /** The proposals the Proposals menu lists (proposal.js reads them), as a list of the panel's own shape; null before the first answer */
172
+ function specsList() {
173
+ const { entries, problem, forgeProblem, at } = proposalListing();
174
+ return entries ? { items: entries, at: at ? new Date(at).toISOString() : '', rate: '', stale: '', problem: problem || forgeProblem || '' } : null;
175
+ }
160
176
  const groupsShown = () => (ui.work ? filterGroups(ui.work.grouped.groups, ui.workFilters) : []);
161
177
  const plural = (n, word, more = `${word}s`) => `${n} ${n === 1 ? word : more}`;
162
- const kindWords = () => ({ pulls: 'pull request', issues: 'issue', threads: 'thread', deploys: 'deploy' })[ui.kind] || 'piece of work';
178
+ const kindWords = () => ({ specs: 'spec', pulls: 'pull request', issues: 'issue', threads: 'thread', deploys: 'deploy' })[ui.kind] || 'piece of work';
163
179
  /** A link only if it is the forge's web address: a forge's JSON is data, not trusted markup */
164
180
  const safeUrl = (u) => (typeof u === 'string' && /^https?:\/\//i.test(u) ? u : null);
165
181
 
@@ -251,6 +267,7 @@ function onPageShow() { pageAway = false; syncRunsPoll(); }
251
267
  async function loadList(refresh = false, quiet = false) {
252
268
  const token = ++listToken;
253
269
  if (ui.kind === 'work') return loadWork(refresh, token);
270
+ if (ui.kind === 'specs') return loadSpecs(token, quiet);
254
271
  const key = listKey();
255
272
  ui.loading = true;
256
273
  ui.error = '';
@@ -274,6 +291,36 @@ async function loadList(refresh = false, quiet = false) {
274
291
  paint();
275
292
  }
276
293
 
294
+ /** Loads the Specs tab: the proposals the server finds (the list the header's Proposals menu shows, proposal.js); always asked again, worktrees come and go */
295
+ async function loadSpecs(token, quiet) {
296
+ ui.loading = true;
297
+ ui.error = '';
298
+ paint();
299
+ await loadProposalList();
300
+ if (token !== listToken) return;
301
+ ui.loading = false;
302
+ const { entries, problem } = proposalListing();
303
+ if (!entries) ui.error = `The proposals could not be listed: ${problem || 'no answer'}`;
304
+ if (!quiet) announce(ui.error || `${plural(entries.length, 'spec')} shown`);
305
+ paint();
306
+ }
307
+
308
+ /** The counts on the tabs, read quietly the first time the panel opens: the open pull requests and issues (the Threads and Runs counts come from what those tabs read anyway) */
309
+ function primeCounts() {
310
+ for (const kind of ['pulls', 'issues']) {
311
+ const key = listKeyOf(kind, 'open');
312
+ if (ui.lists[key] || primed.has(kind) || kind === ui.kind) continue;
313
+ primed.add(kind);
314
+ request(listUrl(kind, 'open'), false).then((res) => {
315
+ if (res.ok && !ui.lists[key]) ui.lists[key] = { items: res.body.items || [], at: res.body.at, rate: res.body.rate || '', stale: res.body.stale || '', problem: res.body.problem || '' };
316
+ if (ui.open) paint();
317
+ });
318
+ }
319
+ if (!primed.has('threads')) { primed.add('threads'); ensureThreadsList(); }
320
+ if (ui.kind !== 'specs' && !proposalListing().entries) loadProposalList();
321
+ }
322
+ const primed = new Set();
323
+
277
324
  /** Selects a pull request: asks for its files and checks, then lights what they are on the map */
278
325
  async function selectPull(n) {
279
326
  const token = ++pullToken;
@@ -282,6 +329,7 @@ async function selectPull(n) {
282
329
  ui.deployItem = null;
283
330
  ui.litDeploy = null;
284
331
  ui.selected = n;
332
+ ui.selectedOn = ui.kind; // the PRs list or the Runs tab's groups: its detail replaces that list only
285
333
  ui.detail = null;
286
334
  ui.landing = null;
287
335
  ui.detailError = '';
@@ -301,6 +349,8 @@ async function selectPull(n) {
301
349
  }
302
350
  ui.detail = { pull: res.body.pull, files: res.body.files || [], checks: res.body.checks || [], specs: res.body.specs || [], at: res.body.at, rate: res.body.rate || '', stale: res.body.stale || '' };
303
351
  relight();
352
+ // The run that made it is on the detail: the runs are read once, if the config has any
353
+ if (!ui.runs && ui.config.agents && ui.config.agents.runs) loadRuns(false, { say: false }).then(() => { if (ui.selected === n) paint(); }, () => {});
304
354
  await loadLanding(n, token);
305
355
  $('forge-panel').querySelector('.hx-forge-body').scrollTop = 0; // the pull request's files are what was asked for, not the row that was tapped
306
356
  announce(selectionWords());
@@ -611,9 +661,13 @@ async function afterIdea(res) {
611
661
  const n = res.body && res.body.number;
612
662
  let trouble = '';
613
663
  try {
664
+ // The new thread is shown where threads are: an idea opened from Specs goes on to the Threads tab
665
+ if (ui.kind !== 'threads') { ui.kind = 'threads'; ui.actNote = null; ui.filters = defaultFilters('threads'); paintFilters(); }
614
666
  ui.lists = {};
667
+ primed.clear(); // the tabs' counts are read again
615
668
  indexCache = null;
616
669
  await loadList(true, true);
670
+ if (ui.open) primeCounts();
617
671
  ensureThreadsList();
618
672
  // The new thread is selected in the list, so what it mentions lights on the map once its messages are in
619
673
  if (Number.isInteger(n)) await selectThread(n);
@@ -634,7 +688,8 @@ async function afterIdea(res) {
634
688
  function paintIdea() {
635
689
  const bar = $('forge-idea');
636
690
  if (!bar) return;
637
- bar.hidden = ui.kind !== 'threads';
691
+ // An idea is a thread: with threads off (`threads: false`) there is no New idea, on Specs either
692
+ bar.hidden = (ui.kind !== 'threads' && ui.kind !== 'specs') || !!detailKey() || !ui.config || ui.config.threads === false;
638
693
  $('idea-open').setAttribute('aria-expanded', String(ui.idea.open));
639
694
  $('idea-form').hidden = !ui.idea.open;
640
695
  $('idea-send').textContent = ui.idea.busy ? 'Opening …' : 'Open the idea';
@@ -817,13 +872,40 @@ function paintNotes() {
817
872
 
818
873
  const option = (value, label, on) => `<option value="${escHtml(value)}"${on ? ' selected' : ''}>${escHtml(label)}</option>`;
819
874
 
875
+ /** Whether the Filter chip applies to the view: the proposals and the release notes have nothing to filter */
876
+ const filterable = () => ui.kind !== 'specs' && ui.kind !== 'notes';
877
+
878
+ /** How many filters are on: a state other than the default, a label, an author, a search; on Runs, its two checkboxes */
879
+ function activeFilters() {
880
+ if (ui.kind === 'work') return Number(ui.workFilters.agentsOnly) + Number(ui.workFilters.finished);
881
+ if (!filterable()) return 0;
882
+ const f = ui.filters;
883
+ return Number(f.state !== defaultFilters(ui.kind).state) + Number(!!f.label) + Number(!!f.author) + Number(!!f.text);
884
+ }
885
+
886
+ /** The Filter chip, its count, and the box behind it */
887
+ function paintChip() {
888
+ const chip = $('forge-filter-chip');
889
+ const box = $('forge-filter-box');
890
+ const on = filterable() && !detailKey();
891
+ const n = activeFilters();
892
+ chip.hidden = !on;
893
+ chip.setAttribute('aria-expanded', String(on && ui.filtersOpen));
894
+ chip.setAttribute('aria-label', n ? `Filter, ${plural(n, 'filter')} on` : 'Filter');
895
+ const count = chip.querySelector('.hx-forge-count');
896
+ count.hidden = !n;
897
+ count.textContent = String(n);
898
+ chip.classList.toggle('is-on', n > 0);
899
+ box.hidden = !(on && ui.filtersOpen);
900
+ }
901
+
820
902
  /** The filters' choices: the states of the kind, the labels and authors of what is loaded */
821
903
  function paintFilters() {
822
- $('forge-filters').hidden = ui.kind === 'work' || ui.kind === 'notes';
904
+ $('forge-filters').hidden = ui.kind === 'work' || !filterable();
823
905
  $('forge-work-filters').hidden = ui.kind !== 'work';
824
906
  $('forge-work-agents').checked = ui.workFilters.agentsOnly;
825
907
  $('forge-work-finished').checked = ui.workFilters.finished;
826
- if (ui.kind === 'work' || ui.kind === 'notes') return;
908
+ if (ui.kind === 'work' || !filterable()) return;
827
909
  const items = current() && ui.kind !== 'deploys' ? current().items : [];
828
910
  const { labels, authors } = facetsOf(items);
829
911
  if (ui.filters.label && !labels.includes(ui.filters.label)) ui.filters.label = '';
@@ -912,13 +994,23 @@ function groupsHtml(groups) {
912
994
  }).join('');
913
995
  }
914
996
 
915
- /** The selected pull request: its checks, its files and the nodes they are */
997
+ /** Which selection replaces the list now, as a key ('pr:12', 'thread:3', 'deploy:9004'), or '' while the list shows. A selection stays lit on the map but shows only on the tab it belongs to. */
998
+ function detailKey() {
999
+ if (ui.kind === 'threads' && ui.thread !== null) return `thread:${ui.thread}`;
1000
+ if (ui.kind === 'deploys' && ui.deployItem) return `deploy:${ui.deploy}`;
1001
+ if (ui.selected !== null && ui.kind === ui.selectedOn) return `pr:${ui.selected}`;
1002
+ return '';
1003
+ }
1004
+
1005
+ /** The back control of a detail: an arrow and the name of the list it returns to ("All pull requests") */
1006
+ const backHtml = (action, words) => `<button type="button" class="hx-forge-back" data-action="${action}"><svg width="14" height="14" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.6" aria-hidden="true"><path d="M10 3L5 8l5 5"/></svg><span class="hx-forge-back-text">${escHtml(words)}</span></button>`;
1007
+
916
1008
  /** The selected deploy: what it was, and the nodes it restarted (each a button that selects it on the map) */
917
1009
  function deployDetailHtml() {
918
1010
  const d = ui.deployItem;
919
1011
  const lit = ui.litDeploy;
920
1012
  const url = safeUrl(d.url);
921
- const head = `<div class="hx-forge-detail-head"><h3 class="hx-forge-detail-title">${escHtml(d.name)}</h3><button type="button" class="hx-btn hx-btn--quiet" data-action="clear-forge-deploy" data-corn-kind="quiet">Clear</button></div>
1013
+ const head = `${backHtml('clear-forge-deploy', 'All deploys')}<h3 class="hx-forge-detail-title">${escHtml(d.name)}</h3>
922
1014
  <p class="hx-forge-meta"><span class="hx-forge-state hx-forge-state--${escHtml(d.state)}" data-corn="state-pill"${cornStateAttr(d.state)}>${escHtml(deployWords(d))}</span> ${escHtml(deployMeta(d, now()))}${url ? ` · <a class="hx-link" href="${escHtml(url)}" target="_blank" rel="noreferrer">Open on ${escHtml(forgeName())} ↗</a>` : ''}</p>`;
923
1015
  const stale = ui.lists.deploys && ui.lists.deploys.stale;
924
1016
  let body;
@@ -938,7 +1030,7 @@ const nodeButton = (n) => `<button type="button" class="hx-forge-node" data-forg
938
1030
 
939
1031
  /** The selected thread: read-only, its messages as written, a way to reply on the forge, and the nodes its text lights */
940
1032
  function threadDetailHtml() {
941
- const head = (title) => `<div class="hx-forge-detail-head"><h3 class="hx-forge-detail-title">${title}</h3><button type="button" class="hx-btn hx-btn--quiet" data-action="clear-forge-thread" data-corn-kind="quiet">Clear</button></div>`;
1033
+ const head = (title) => `${backHtml('clear-forge-thread', 'All threads')}<h3 class="hx-forge-detail-title">${title}</h3>`;
942
1034
  if (ui.threadError) return `${head(`Thread ${ui.thread}`)}<p class="hx-forge-notice" data-corn="notice">${escHtml(ui.threadError)}</p>`;
943
1035
  if (!ui.threadDetail) return `${head(`Thread ${ui.thread}`)}<p class="hx-faint">Loading its messages …</p>`;
944
1036
  const { thread: t, stale } = ui.threadDetail;
@@ -974,10 +1066,11 @@ function threadDetailHtml() {
974
1066
  }
975
1067
 
976
1068
  function detailHtml() {
977
- if (ui.thread !== null) return threadDetailHtml();
978
- if (ui.deployItem) return deployDetailHtml();
979
- if (ui.selected === null) return '';
980
- const head = (title, link) => `<div class="hx-forge-detail-head"><h3 class="hx-forge-detail-title">${title}</h3><button type="button" class="hx-btn hx-btn--quiet" data-action="clear-forge-pr" data-corn-kind="quiet">Clear</button></div>${link || ''}`;
1069
+ const shown = detailKey();
1070
+ if (shown.startsWith('thread:')) return threadDetailHtml();
1071
+ if (shown.startsWith('deploy:')) return deployDetailHtml();
1072
+ if (!shown) return '';
1073
+ const head = (title, meta) => `${backHtml('clear-forge-pr', ui.kind === 'work' ? 'All work' : 'All pull requests')}${meta || ''}<h3 class="hx-forge-detail-title">${title}</h3>`;
981
1074
  if (ui.detailError) return `${head(`Pull request ${ui.selected}`)}<p class="hx-forge-notice" data-corn="notice">${escHtml(ui.detailError)}</p>`;
982
1075
  if (!ui.detail) return `${head(`Pull request ${ui.selected}`)}<p class="hx-faint">Loading its files and checks …</p>`;
983
1076
  const { pull, checks, stale } = ui.detail;
@@ -1010,10 +1103,12 @@ function detailHtml() {
1010
1103
  return `<li class="hx-forge-file"><span class="hx-forge-fstatus">${escHtml(f.status)}</span> <code class="hx-code">${escHtml(f.path)}</code>${renamed} <span class="hx-good">+${f.additions}</span> <span class="hx-forge-del">−${f.deletions}</span><span class="hx-forge-nodes">${nodes}</span></li>`;
1011
1104
  }).join('');
1012
1105
 
1106
+ // Land it is the one primary action, with Open on the forge beside it; a pull request that cannot land says why in one line
1013
1107
  const block = mergeBlock(ui.detail);
1014
- const act = block
1015
- ? `<p class="hx-forge-why hx-faint">${pull.state === 'merged' ? '' : 'Cannot be landed from here. '}${escHtml(block)}</p>`
1016
- : `<button type="button" class="hx-btn hx-btn--approve hx-forge-act" data-forge-merge="${pull.number}"${ui.busy ? ' disabled' : ''} data-corn-kind="approve">${escHtml(t('landIt'))} …</button><p class="hx-forge-why hx-faint">Opens a confirm step that shows what will land. Never forced, never deployed.</p>`;
1108
+ const land = block
1109
+ ? `<button type="button" class="hx-btn hx-btn--approve" disabled data-corn-kind="approve">${escHtml(t('landIt'))}</button>`
1110
+ : `<button type="button" class="hx-btn hx-btn--approve hx-forge-act" data-forge-merge="${escHtml(String(pull.number))}"${ui.busy ? ' disabled' : ''} data-corn-kind="approve">${escHtml(t('landIt'))} …</button>`;
1111
+ const act = `<div class="hx-forge-cta">${land}${url ? `<a class="hx-btn hx-forge-open" href="${escHtml(url)}" target="_blank" rel="noreferrer">Open on ${escHtml(forgeName())} ↗</a>` : ''}</div>${block ? `<p class="hx-forge-why hx-faint">${escHtml(block)}</p>` : ''}`;
1017
1112
  // A spec approved with `proposals.approveLands` waits for its checks: said here, with a way to stop it
1018
1113
  const waiting = ui.landing && pull.state === 'open'
1019
1114
  ? `<div class="hx-forge-step"><p class="hx-forge-notice hx-forge-notice--ok" role="status" data-corn="notice" data-corn-state="success">${escHtml(landingWords(ui.landing, now()))}</p><button type="button" class="hx-btn hx-forge-act" data-forge-landing-cancel="${pull.number}"${ui.busy ? ' disabled' : ''}>Cancel</button></div>`
@@ -1030,23 +1125,31 @@ function detailHtml() {
1030
1125
  const key = lit.changed.size || lit.failing.size
1031
1126
  ? `<p class="hx-forge-key hx-faint"><span class="hx-mark-dot hx-mark-dot--changed" aria-hidden="true"></span>a file this pull request changes <span class="hx-mark-dot hx-mark-dot--removed" aria-hidden="true"></span>a test a failing check names</p>`
1032
1127
  : '';
1033
- return `${head(`#${pull.number} ${escHtml(pull.title)}`, `<p class="hx-forge-meta"><span class="hx-forge-state hx-forge-state--${escHtml(pull.draft ? 'draft' : pull.state)}" data-corn="state-pill"${cornStateAttr(pull.draft ? 'draft' : pull.state)}>${escHtml(stateWords(pull))}</span> ${escHtml(pull.head.ref)} → ${escHtml(pull.base.ref)}${url ? ` · <a class="hx-link" href="${escHtml(url)}" target="_blank" rel="noreferrer">Open on ${escHtml(forgeName())} ↗</a>` : ''}</p>`)}
1128
+ // Its run: who is running it, their state, the time and the cost (the runs are read for the Runs tab, and once for the first PR selected)
1129
+ const runs = ui.runs && ui.runs.data ? ui.runs.data.runs : null;
1130
+ const made = runOnPull(runs, pull.number);
1131
+ const runSection = made
1132
+ ? `<h4 class="hx-forge-sub">Run</h4><p class="hx-forge-runline"${cornStateAttr(made.status)} data-corn="run">${escHtml(pullRunWords(made, now()))}</p>`
1133
+ : '';
1134
+ const meta = `<p class="hx-forge-meta hx-forge-dmeta"><span class="hx-forge-state hx-forge-state--${escHtml(pull.draft ? 'draft' : pull.state)}" data-corn="state-pill"${cornStateAttr(pull.draft ? 'draft' : pull.state)}>${escHtml(stateWords(pull))}</span> <span>#${escHtml(String(pull.number))}</span> <span>${escHtml(pull.head.ref)} → ${escHtml(pull.base.ref)}</span> <span>${escHtml(pull.author ? pull.author.login : 'someone')}</span> <span>${escHtml(relativeTime(pull.createdAt || pull.updatedAt, now()))}</span></p>`;
1135
+ return `${head(escHtml(pull.title), meta)}
1136
+ ${act}
1034
1137
  ${stale ? `<p class="hx-forge-notice" data-corn="notice">${escHtml(`This is an older answer. ${stale}`)}</p>` : ''}
1035
- <h4 class="hx-forge-sub">Checks: ${escHtml(checksWords(checks))}</h4>
1036
- ${checks.length ? `<ul class="hx-forge-checks">${checkRows}</ul>` : ''}
1037
- ${build}
1038
- <h4 class="hx-forge-subact">${escHtml(t('landIt'))}</h4>
1039
1138
  ${note}
1040
1139
  ${waiting}
1041
- ${act}
1140
+ ${build}
1141
+ <h4 class="hx-forge-sub">Checks: ${escHtml(checksWords(checks))}</h4>
1142
+ ${checks.length ? `<ul class="hx-forge-checks">${checkRows}</ul>` : ''}
1042
1143
  <h4 class="hx-forge-sub">${escHtml(plural(lit.files.length, 'file'))} changed, ${mapped} on the map</h4>
1043
1144
  ${key}
1044
- <ul class="hx-forge-files">${fileRows}</ul>`;
1145
+ <ul class="hx-forge-files">${fileRows}</ul>
1146
+ ${runSection}`;
1045
1147
  }
1046
1148
 
1047
1149
  /** How to find an element of the panel again after it is drawn anew, or null */
1048
1150
  function findAgain(el) {
1049
1151
  if (!el || !el.dataset) return null;
1152
+ if (el.classList.contains('hx-forge-back') && el.closest('#forge-detail')) return '#forge-detail .hx-forge-back'; // the detail is drawn anew as its answer comes in
1050
1153
  if (el.dataset.forgePr) return `[data-forge-pr="${el.dataset.forgePr}"]`;
1051
1154
  if (el.dataset.forgeDeploy) return `[data-forge-deploy="${el.dataset.forgeDeploy}"]`;
1052
1155
  if (el.dataset.forgeThread) return `[data-forge-thread="${el.dataset.forgeThread}"]`;
@@ -1065,23 +1168,66 @@ function findAgain(el) {
1065
1168
  return null;
1066
1169
  }
1067
1170
 
1171
+ /** What the focus does when a selection replaces the list, and when it goes back: the key of the selection shown at the last paint, and the tab it was on */
1172
+ let shownKey = '';
1173
+ let shownKind = '';
1174
+ let returnTo = null; // the selector of the row that opened the selection
1175
+
1068
1176
  /** Everything the panel shows, from `ui` (a row or node button that had the focus has it again) */
1069
1177
  function paint() {
1070
1178
  const panel = $('forge-panel');
1071
1179
  if (!panel) return;
1072
- const again = panel.contains(document.activeElement) ? findAgain(document.activeElement) : null;
1180
+ const had = panel.contains(document.activeElement) ? document.activeElement : null;
1181
+ const again = had ? findAgain(had) : null;
1073
1182
  draw(panel);
1074
1183
  const back = again && panel.querySelector(again);
1075
- if (back && back !== document.activeElement) back.focus();
1184
+ if (back && back !== document.activeElement && !back.closest('[hidden]')) back.focus();
1185
+ // A selection replaces the list: the focus goes to its back control, and returns to the row when it is let go of
1186
+ // (a tab changed leaves the focus on the tab)
1187
+ const key = detailKey();
1188
+ if (key !== shownKey && shownKind === ui.kind) {
1189
+ if (key) {
1190
+ const target = panel.querySelector('#forge-detail .hx-forge-back');
1191
+ if (target && (had || !shownKey)) target.focus();
1192
+ } else {
1193
+ const row = returnTo && panel.querySelector(returnTo);
1194
+ if (row && !row.closest('[hidden]')) row.focus(); else $('forge-title').focus();
1195
+ returnTo = null;
1196
+ }
1197
+ }
1198
+ shownKey = key;
1199
+ shownKind = ui.kind;
1200
+ }
1201
+
1202
+ /** The tabs' counts, where there is one: the proposals, the open pull requests and issues and threads, the runs still open */
1203
+ function paintCounts() {
1204
+ const open = (key) => (ui.lists[key] ? ui.lists[key].items.length : null);
1205
+ const specs = proposalListing().entries;
1206
+ const runs = ui.runs && ui.runs.data ? ui.runs.data.open : null;
1207
+ const counts = { specs: specs ? specs.length : null, pulls: open('pulls|open'), issues: open('issues|open'), threads: ui.config && ui.config.threads === false ? null : open('threads|open'), work: runs };
1208
+ for (const btn of document.querySelectorAll('#forge-panel [data-forge-kind]')) {
1209
+ const n = counts[btn.dataset.forgeKind];
1210
+ const el = btn.querySelector('.hx-forge-count');
1211
+ if (!el) continue;
1212
+ el.hidden = !n;
1213
+ el.textContent = n ? String(n) : '';
1214
+ }
1076
1215
  }
1077
1216
 
1078
1217
  function draw(panel) {
1079
- for (const btn of panel.querySelectorAll('[data-forge-kind]')) btn.setAttribute('aria-pressed', String(btn.dataset.forgeKind === ui.kind));
1218
+ for (const btn of panel.querySelectorAll('[data-forge-kind]')) btn.setAttribute('aria-pressed', String(btn.dataset.forgeKind === (ui.kind === 'notes' ? 'pulls' : ui.kind)));
1219
+ paintCounts();
1080
1220
  const notes = ui.kind === 'notes';
1081
- $('forge-filters').hidden = notes || ui.kind === 'work';
1221
+ const specs = ui.kind === 'specs';
1222
+ const showing = detailKey();
1223
+ $('forge-filters').hidden = notes || ui.kind === 'work' || specs;
1082
1224
  $('forge-work-filters').hidden = ui.kind !== 'work';
1083
- $('forge-list').hidden = notes;
1225
+ $('forge-bar').hidden = !!showing;
1226
+ paintChip();
1227
+ $('forge-list').hidden = notes || !!showing;
1084
1228
  $('forge-notes').hidden = !notes;
1229
+ $('notes-open').hidden = ui.kind !== 'pulls' || !!showing;
1230
+ $('forge-foot').hidden = notes || !!showing;
1085
1231
  if (notes) {
1086
1232
  drawNotes();
1087
1233
  return;
@@ -1090,15 +1236,16 @@ function draw(panel) {
1090
1236
  const list = current();
1091
1237
  const work = ui.kind === 'work';
1092
1238
  const groups = work ? groupsShown() : [];
1093
- const shown = list && !work ? filterItems(list.items, ui.kind, ui.filters) : [];
1239
+ const shown = list && !work && !specs ? filterItems(list.items, ui.kind, ui.filters) : [];
1094
1240
  const status = $('forge-status');
1095
- if (ui.loading && !list) status.textContent = work ? `Loading the work from ${forgeName()} …` : `Loading ${kindWords()}s from ${forgeName()} …`;
1241
+ if (ui.loading && !list) status.textContent = work ? `Loading the work from ${forgeName()} …` : specs ? 'Looking for proposals …' : `Loading ${kindWords()}s from ${forgeName()} …`;
1096
1242
  else if (!list) status.textContent = '';
1097
1243
  else if (work) status.textContent = workStatus(groups, list.at, now());
1244
+ else if (specs) status.textContent = `${plural(list.items.length, 'open spec')}${list.at ? `, as of ${relativeTime(list.at, now())}` : ''}`;
1098
1245
  else status.textContent = `${shown.length} of ${plural(list.items.length, kindWords())}${list.at ? `, as of ${relativeTime(list.at, now())}` : ''}`;
1099
1246
 
1100
1247
  const notice = $('forge-notice');
1101
- const words = ui.error || (list && list.stale ? `Showing an older answer. ${list.stale}` : '') || (work && list && list.problem ? `Spec pull requests could not all be read: ${list.problem}` : '') || (ui.kind === 'threads' && list && list.problem ? `Some threads could not all be read: ${list.problem}` : '');
1248
+ const words = ui.error || (list && list.stale ? `Showing an older answer. ${list.stale}` : '') || (specs && list && list.problem ? `The spec PRs could not be listed: ${list.problem}` : '') || (work && list && list.problem ? `Spec pull requests could not all be read: ${list.problem}` : '') || (ui.kind === 'threads' && list && list.problem ? `Some threads could not all be read: ${list.problem}` : '');
1102
1249
  notice.hidden = !words;
1103
1250
  notice.textContent = words;
1104
1251
 
@@ -1113,16 +1260,21 @@ function draw(panel) {
1113
1260
 
1114
1261
  const rows = $('forge-list');
1115
1262
  if (!list) rows.innerHTML = '';
1263
+ else if (specs) {
1264
+ const open = state.proposal ? { slug: state.proposalSlug, source: state.proposalSource } : null;
1265
+ rows.innerHTML = list.items.length ? list.items.map((e) => specRowHtml(e, { current: open })).join('') : '<li class="hx-forge-empty hx-faint">No proposals</li>';
1266
+ }
1116
1267
  else if (work) rows.innerHTML = groups.length ? groupsHtml(groups) : `<li class="hx-forge-empty hx-faint">${ui.work.grouped.groups.length ? 'No work matches these filters.' : 'No work here yet.'}</li>`;
1117
1268
  else rows.innerHTML = shown.length ? shown.map((i) => itemHtml(i)).join('') : `<li class="hx-forge-empty hx-faint">${list.items.length ? `No ${kindWords()} matches these filters.` : `No ${kindWords()}s here.`}</li>`;
1118
1269
 
1119
1270
  const detail = $('forge-detail');
1120
- detail.hidden = ui.selected === null && !ui.deployItem && ui.thread === null;
1121
- detail.setAttribute('aria-label', ui.thread !== null ? 'Selected thread' : ui.deployItem ? 'Selected deploy' : 'Selected pull request');
1271
+ detail.hidden = !showing;
1272
+ detail.setAttribute('aria-label', showing.startsWith('thread:') ? 'Selected thread' : showing.startsWith('deploy:') ? 'Selected deploy' : 'Selected pull request');
1122
1273
  detail.innerHTML = detailHtml();
1123
1274
 
1124
1275
  paintIdea();
1125
- const rate = (ui.threadDetail && ui.threadDetail.rate) || (ui.detail && ui.detail.rate) || (list && list.rate) || '';
1276
+ $('forge-foot').hidden = $('notes-open').hidden && $('forge-idea').hidden;
1277
+ const rate = (showing && ((ui.threadDetail && ui.threadDetail.rate) || (ui.detail && ui.detail.rate))) || (list && list.rate) || '';
1126
1278
  $('forge-rate').textContent = rate;
1127
1279
  paintRuns();
1128
1280
  paintButton();
@@ -1132,7 +1284,7 @@ function draw(panel) {
1132
1284
  function paintRuns() {
1133
1285
  const box = $('forge-runs');
1134
1286
  if (!box) return;
1135
- box.hidden = ui.kind !== 'work';
1287
+ box.hidden = ui.kind !== 'work' || !!detailKey();
1136
1288
  if (box.hidden) return;
1137
1289
  const data = ui.runs && ui.runs.data;
1138
1290
  $('forge-runs-status').textContent = data ? runsStatus(data) : ui.loading ? 'Loading the runs …' : '';
@@ -1234,16 +1386,18 @@ function drawNotes() {
1234
1386
  paintButton();
1235
1387
  }
1236
1388
 
1237
- /** The header button says which pull request is lit */
1389
+ /** The toggles that open the panel (`data-action="toggle-forge"`: the header's, whatever it calls it) say whether it is open, and the old button which selection is lit */
1238
1390
  function paintButton() {
1391
+ for (const toggle of document.querySelectorAll('[data-action="toggle-forge"]')) toggle.setAttribute('aria-expanded', String(ui.open));
1239
1392
  const btn = $('forge-btn');
1240
1393
  if (!btn) return;
1241
1394
  const lit = ui.selected !== null || !!ui.deployItem || ui.thread !== null || !!ui.runSel;
1242
1395
  const tag = $('forge-btn-lit');
1243
- tag.hidden = !lit;
1244
- tag.textContent = ui.runSel ? 'run' : ui.thread !== null ? `thread #${ui.thread}` : ui.deployItem ? 'deploy' : lit ? `#${ui.selected}` : '';
1396
+ if (tag) {
1397
+ tag.hidden = !lit;
1398
+ tag.textContent = ui.runSel ? 'run' : ui.thread !== null ? `thread #${ui.thread}` : ui.deployItem ? 'deploy' : lit ? `#${ui.selected}` : '';
1399
+ }
1245
1400
  btn.setAttribute('aria-label', `${t('issuesAndPrs')}${ui.runSel ? ', a run lit on the map' : ui.thread !== null ? `, thread ${ui.thread} selected` : ui.deployItem ? ', a deploy selected' : lit ? `, pull request ${ui.selected} selected` : ''}`);
1246
- btn.setAttribute('aria-expanded', String(ui.open));
1247
1401
  }
1248
1402
 
1249
1403
  // ---------------------------------------------------------------------------
@@ -1695,10 +1849,21 @@ async function answerRun(runId, action) {
1695
1849
 
1696
1850
  export const isForgeOpen = () => ui.open;
1697
1851
 
1698
- /** Opens the panel with the focus on its title; the first time, loads the pull requests */
1699
- export function openForge({ load = true } = {}) {
1852
+ /** What opened the panel (a toggle in the header), so Escape and Close give the focus back to it */
1853
+ let openerEl = null;
1854
+
1855
+ /**
1856
+ * Opens the panel with the focus on its title; the first time, loads what its tab shows (the proposals, to start with).
1857
+ * `tab` opens it on that tab ('specs', 'pulls', 'issues', 'threads', 'work' for Runs, 'deploys'), whichever was shown last otherwise.
1858
+ */
1859
+ export function openForge({ load = true, tab } = {}) {
1700
1860
  const panel = $('forge-panel');
1701
1861
  if (!panel || panel.hidden) return;
1862
+ if (tab && tab !== (ui.kind === 'notes' ? 'pulls' : ui.kind) && TABS.includes(tab)) { // the Release notes are one level down on PRs
1863
+ ui.kind = tab;
1864
+ ui.filters = defaultFilters(tab);
1865
+ ui.actNote = null;
1866
+ }
1702
1867
  ui.open = true;
1703
1868
  panel.inert = false;
1704
1869
  panel.classList.add('forge-open');
@@ -1706,12 +1871,16 @@ export function openForge({ load = true } = {}) {
1706
1871
  paintButton();
1707
1872
  const title = $('forge-title');
1708
1873
  title.focus();
1709
- announce('Issues and pull requests');
1874
+ announce('Work');
1710
1875
  if (!load) return; // a deep link loads the list it wants itself (openTab)
1876
+ if (!tab) primeCounts(); // opened by a toggle, not for a tab: the other tabs' counts are read quietly
1711
1877
  if (ui.kind === 'notes') { if (!ui.notes.data && !ui.notes.loading) loadNotes(); else paint(); return; }
1712
- if (!current()) { paintFilters(); loadList(); } else paint();
1878
+ if (ui.kind === 'specs' || !current()) { paintFilters(); loadList(); } else paint();
1713
1879
  }
1714
1880
 
1881
+ /** The tabs, in the order of the loop */
1882
+ const TABS = ['specs', 'pulls', 'issues', 'threads', 'work', 'deploys'];
1883
+
1715
1884
  // ---------------------------------------------------------------------------
1716
1885
  // Deep links (explorer/deep-link.js): a run, an issue, a proposal's Start dialog
1717
1886
  // ---------------------------------------------------------------------------
@@ -1807,8 +1976,9 @@ export function closeForge({ restoreFocus = true } = {}) {
1807
1976
  panel.inert = true;
1808
1977
  collapseSheet('forge');
1809
1978
  paintButton();
1810
- if (restoreFocus && hadFocus) $('forge-btn').focus();
1811
- announce('Issues and pull requests closed');
1979
+ const back = openerEl && openerEl.isConnected ? openerEl : $('forge-btn');
1980
+ if (restoreFocus && hadFocus && back) back.focus();
1981
+ announce('Work closed');
1812
1982
  }
1813
1983
 
1814
1984
  export const toggleForge = () => (ui.open ? closeForge() : openForge());
@@ -1863,32 +2033,31 @@ function onClick(e) {
1863
2033
  const kind = t.closest('[data-forge-kind]');
1864
2034
  if (kind) {
1865
2035
  if (kind.dataset.forgeKind === ui.kind) return;
1866
- if (kind.dataset.forgeKind === 'notes') {
1867
- ui.kind = 'notes';
1868
- if (ui.notes.data || ui.notes.loading) { paint(); announce(`Release notes. ${ui.notes.data ? notesSummary(ui.notes.data) : ''}`); } else loadNotes();
1869
- return;
1870
- }
1871
2036
  ui.kind = kind.dataset.forgeKind;
1872
2037
  ui.actNote = null;
1873
2038
  ui.filters = defaultFilters(ui.kind);
1874
2039
  paintFilters();
1875
- if (current()) filtersChanged(); else { paint(); loadList(); }
2040
+ // The proposals are asked for again each time (worktrees come and go); the other lists keep what they have
2041
+ if (ui.kind === 'specs') { paint(); loadList(false, true); announce(current() ? `${plural(current().items.length, 'spec')} shown` : 'Looking for proposals'); } else if (current()) filtersChanged(); else { paint(); loadList(); }
1876
2042
  return;
1877
2043
  }
1878
2044
  const pr = t.closest('[data-forge-pr]');
1879
2045
  if (pr) {
1880
2046
  const n = Number(pr.dataset.forgePr);
2047
+ returnTo = findAgain(pr); // the row to give the focus back to when the selection is let go of
1881
2048
  if (ui.selected === n) clearPull(); else selectPull(n);
1882
2049
  return;
1883
2050
  }
1884
2051
  const thr = t.closest('[data-forge-thread]');
1885
2052
  if (thr) {
1886
2053
  const n = Number(thr.dataset.forgeThread);
2054
+ returnTo = findAgain(thr);
1887
2055
  if (ui.thread === n) clearThread(); else selectThread(n);
1888
2056
  return;
1889
2057
  }
1890
2058
  const dep = t.closest('[data-forge-deploy]');
1891
2059
  if (dep) {
2060
+ returnTo = findAgain(dep);
1892
2061
  if (ui.deploy === dep.dataset.forgeDeploy) clearDeploy(); else selectDeploy(dep.dataset.forgeDeploy);
1893
2062
  return;
1894
2063
  }
@@ -1934,9 +2103,13 @@ function onClick(e) {
1934
2103
  else if (action.dataset.action === 'post-notes') { if (ui.notes.confirm) closeNotesConfirm(); else openNotesConfirm(); }
1935
2104
  else if (action.dataset.action === 'confirm-notes') postDraft();
1936
2105
  else if (action.dataset.action === 'cancel-notes') { closeNotesConfirm(); announce('Cancelled. Nothing was posted.'); }
1937
- else if (action.dataset.action === 'clear-forge-pr') { clearPull(); $('forge-title').focus(); }
1938
- else if (action.dataset.action === 'clear-forge-deploy') { clearDeploy(); $('forge-title').focus(); }
1939
- else if (action.dataset.action === 'clear-forge-thread') { clearThread(); $('forge-title').focus(); }
2106
+ else if (action.dataset.action === 'clear-forge-pr') clearPull();
2107
+ else if (action.dataset.action === 'clear-forge-deploy') clearDeploy();
2108
+ else if (action.dataset.action === 'clear-forge-thread') clearThread();
2109
+ else if (action.dataset.action === 'toggle-filters') { ui.filtersOpen = !ui.filtersOpen; paintChip(); }
2110
+ else if (action.dataset.action === 'open-notes') openNotes();
2111
+ else if (action.dataset.action === 'close-notes') closeNotes();
2112
+ else if (action.dataset.action === 'open-proposal' && isPhone()) collapseSheet('forge'); // the proposal's own bar and the map are what is wanted now
1940
2113
  else if (action.dataset.action === 'idea-open') toggleIdea(!ui.idea.open);
1941
2114
  else if (action.dataset.action === 'idea-send') {
1942
2115
  // Nothing of it may escape as an unhandled rejection: what went wrong is said, and the form is usable again
@@ -1951,6 +2124,22 @@ function onClick(e) {
1951
2124
  else if (action.dataset.action === 'idea-cancel') { toggleIdea(false); announce('Cancelled. Nothing was opened.'); }
1952
2125
  }
1953
2126
 
2127
+ /** The Release notes view, from the PRs list: its own page with a way back */
2128
+ function openNotes() {
2129
+ ui.kind = 'notes';
2130
+ ui.actNote = null;
2131
+ if (ui.notes.data || ui.notes.loading) { paint(); announce(`Release notes. ${ui.notes.data ? notesSummary(ui.notes.data) : ''}`); } else loadNotes();
2132
+ $('notes-title').focus();
2133
+ }
2134
+
2135
+ /** Back from the Release notes to the PRs list, the focus on the button that opened them */
2136
+ function closeNotes() {
2137
+ ui.kind = 'pulls';
2138
+ paint();
2139
+ $('notes-open').focus();
2140
+ announce('All pull requests');
2141
+ }
2142
+
1954
2143
  function onChange(e) {
1955
2144
  const id = e.target.id;
1956
2145
  if (id === 'notes-since') {
@@ -2000,6 +2189,19 @@ function onKey(e) {
2000
2189
  closeForge();
2001
2190
  }
2002
2191
 
2192
+ /** Any `data-action="toggle-forge"` opens and closes the panel; one listener on the page, however many times the panel is wired */
2193
+ let onToggle = null;
2194
+ function wireToggles() {
2195
+ if (onToggle) document.removeEventListener('click', onToggle);
2196
+ onToggle = (e) => {
2197
+ const el = e.target.closest && e.target.closest('[data-action="toggle-forge"]');
2198
+ if (!el) return;
2199
+ openerEl = el;
2200
+ toggleForge();
2201
+ };
2202
+ document.addEventListener('click', onToggle);
2203
+ }
2204
+
2003
2205
  /**
2004
2206
  * Wires the panel (main.js calls this once the config is read). With no forge in the config, or nobody signed in,
2005
2207
  * the button and the panel stay hidden, and this returns false.
@@ -2008,13 +2210,15 @@ function onKey(e) {
2008
2210
  * @returns {boolean} whether the panel is on
2009
2211
  */
2010
2212
  export function initForgePanel(config, opts = {}) {
2011
- const btn = $('forge-btn');
2012
2213
  const panel = $('forge-panel');
2013
- if (!config || !config.forge || !config.signIn || !btn || !panel) return false;
2214
+ if (!config || !config.forge || !config.signIn || !panel) return false;
2014
2215
  ui.config = config;
2015
2216
  if (opts.clock) now = opts.clock;
2016
- btn.hidden = false;
2217
+ for (const toggle of document.querySelectorAll('[data-action="toggle-forge"]')) toggle.hidden = false;
2017
2218
  panel.hidden = false;
2219
+ // The Specs tab lists the proposals: the account menu's Proposals entry is only for a cornfield without the panel (no forge, or no sign-in)
2220
+ const proposalsEntry = $('proposal-wrap');
2221
+ if (proposalsEntry) proposalsEntry.hidden = true;
2018
2222
  // `threads: false` in the config turns the tab off; a server that does not say has threads
2019
2223
  const threadsOn = config.threads !== false;
2020
2224
  const tab = panel.querySelector('[data-forge-kind="threads"]');
@@ -2029,7 +2233,7 @@ export function initForgePanel(config, opts = {}) {
2029
2233
  }
2030
2234
  if (!wired) {
2031
2235
  wired = true;
2032
- btn.addEventListener('click', toggleForge);
2236
+ wireToggles();
2033
2237
  panel.addEventListener('click', onClick);
2034
2238
  panel.addEventListener('change', onChange);
2035
2239
  panel.addEventListener('input', onInput);
@@ -2051,6 +2255,8 @@ export function initForgePanel(config, opts = {}) {
2051
2255
  confirm.addEventListener('keydown', onConfirmKey);
2052
2256
  }
2053
2257
  offScene = onSceneTouch(onNodesChange);
2258
+ // The header's Proposals menu reads the same list: when it is read again the Specs tab and its count follow
2259
+ offListing = onProposalListing(() => { if (ui.open) paint(); });
2054
2260
  // A node's panel lists the threads that mention it; a click there shows one in this panel
2055
2261
  const drawer = $('spec-drawer');
2056
2262
  if (drawer) drawer.addEventListener('click', (e) => {
@@ -2067,8 +2273,17 @@ export function initForgePanel(config, opts = {}) {
2067
2273
  export function resetForgePanelForTests(clock = () => Date.now()) {
2068
2274
  if (ui.confirm) closeConfirm({ restoreFocus: false });
2069
2275
  if (ui.agent) closeAgent({ restoreFocus: false });
2276
+ if (onToggle) document.removeEventListener('click', onToggle);
2277
+ onToggle = null;
2278
+ openerEl = null;
2279
+ primed.clear();
2280
+ shownKey = '';
2281
+ shownKind = '';
2282
+ returnTo = null;
2070
2283
  if (offScene) offScene();
2071
2284
  offScene = null;
2285
+ if (offListing) offListing();
2286
+ offListing = null;
2072
2287
  clearTimeout(searchTimer);
2073
2288
  wired = false;
2074
2289
  now = clock;
@@ -2085,5 +2300,5 @@ export function resetForgePanelForTests(clock = () => Date.now()) {
2085
2300
  runsTimer = 0;
2086
2301
  pageAway = false;
2087
2302
  clearRunsOnMap();
2088
- Object.assign(ui, { runSel: null, runTimelines: new Set(), runReplies: new Map(), thread: null, threadDetail: null, threadError: '', litThread: null, idea: freshIdea(), config: null, open: false, kind: 'pulls', filters: defaultFilters(), lists: {}, work: null, workFilters: { agentsOnly: false, finished: false }, loading: false, error: '', selected: null, detail: null, landing: null, detailError: '', lit: null, deploy: null, deployItem: null, litDeploy: null, nodesSeen: null, busy: '', note: null, confirm: null, actNote: null, notes: freshNotes(), runs: null, runnerSaid: null, runNote: null, agent: null, retrying: false });
2303
+ Object.assign(ui, { runSel: null, runTimelines: new Set(), runReplies: new Map(), thread: null, threadDetail: null, threadError: '', litThread: null, idea: freshIdea(), config: null, open: false, kind: 'specs', filtersOpen: false, filters: defaultFilters(), lists: {}, work: null, workFilters: { agentsOnly: false, finished: false }, loading: false, error: '', selected: null, selectedOn: '', detail: null, landing: null, detailError: '', lit: null, deploy: null, deployItem: null, litDeploy: null, nodesSeen: null, busy: '', note: null, confirm: null, actNote: null, notes: freshNotes(), runs: null, runnerSaid: null, runNote: null, agent: null, retrying: false });
2089
2304
  }
@@ -155,7 +155,7 @@
155
155
  <!-- Review tokens (explorer/review-tokens.js): shown only when somebody is signed in to a forge -->
156
156
  <button type="button" id="tokens-btn" class="hx-account-item" aria-haspopup="dialog" aria-expanded="false" aria-controls="tokens-dialog" title="Review tokens: let a script or a chat bot approve or send back a proposal as you" hidden data-corn="tokens-button">Review tokens</button>
157
157
 
158
- <!-- Proposals: what a change would add, change and remove, drawn on the map (proposal.js). Until they are the Work panel's Specs tab, the list opens here -->
158
+ <!-- Proposals: what a change would add, change and remove, drawn on the map (proposal.js). Only without the Work panel (no forge, or no sign-in): with it, its Specs tab lists them and forge-panel.js hides this -->
159
159
  <div id="proposal-wrap">
160
160
  <button type="button" id="proposal-btn" class="hx-account-item" data-action="toggle-proposals-menu" aria-haspopup="true" aria-expanded="false" title="Open a proposal: what a change would add, change and remove" data-corn="proposals-button"><span data-corn-string="proposals">Proposals</span><span class="hx-faint" aria-hidden="true">▾</span></button>
161
161
  <div id="proposal-menu" class="hx-menu hx-menu--proposals" hidden data-corn="proposals-menu"></div>
@@ -230,24 +230,27 @@
230
230
  </div>
231
231
  </section>
232
232
 
233
- <!-- Issues and pull requests (forge-panel.js): a slide-over from the left on desktop, a bottom sheet on a phone; hidden and inert until the config names a forge -->
234
- <aside id="forge-panel" class="hx-forge glass" aria-label="Issues and pull requests" inert hidden data-corn="forge-panel">
235
- <div class="hx-forge-body">
233
+ <!-- The Work panel (forge-panel.js): Specs, PRs, Issues, Threads, Runs and Deploys, in the order of the loop. A slide-over from the left on desktop, a bottom sheet on a phone; hidden and inert until the config names a forge. `forge-panel` on the inner box is the old name of the hook, kept for one release (docs/theming.md) -->
234
+ <aside id="forge-panel" class="hx-forge glass" aria-label="Work" inert hidden data-corn="work-panel">
235
+ <div class="hx-forge-body" data-corn="forge-panel">
236
236
  <div class="hx-forge-head">
237
- <h2 id="forge-title" class="hx-drawer-title" tabindex="-1">Issues and pull requests</h2>
237
+ <h2 id="forge-title" class="hx-drawer-title" tabindex="-1">Work</h2>
238
238
  <button type="button" class="hx-btn hx-btn--quiet" data-action="refresh-forge" title="Ask the forge again" data-corn-kind="quiet">Refresh</button>
239
239
  <button type="button" class="hx-close" data-action="close-forge" aria-label="Close" data-corn-kind="icon">✕</button>
240
240
  </div>
241
- <p id="forge-status" class="hx-forge-status hx-faint"></p>
242
- <div class="hx-forge-controls">
243
- <div class="hx-forge-tabs" role="group" aria-label="Show" data-corn="tabs">
244
- <button type="button" class="hx-forge-tab" data-forge-kind="pulls" aria-pressed="true" data-corn="tab" data-corn-string="tabPulls">Pull requests</button>
245
- <button type="button" class="hx-forge-tab" data-forge-kind="issues" aria-pressed="false" data-corn="tab" data-corn-string="tabIssues">Issues</button>
246
- <button type="button" class="hx-forge-tab" data-forge-kind="threads" aria-pressed="false" title="Ideas and spec conversations, with the nodes they mention" data-corn="tab" data-corn-string="tabThreads">Threads</button>
247
- <button type="button" class="hx-forge-tab" data-forge-kind="deploys" aria-pressed="false" data-corn="tab" data-corn-string="tabDeploys">Deploys</button>
248
- <button type="button" class="hx-forge-tab" data-forge-kind="work" aria-pressed="false" title="Work grouped by issue and proposal, agent-made work marked" data-corn="tab" data-corn-string="tabAgents">Agents</button>
249
- <button type="button" class="hx-forge-tab" data-forge-kind="notes" aria-pressed="false" data-corn="tab" data-corn-string="tabNotes">Release notes</button>
250
- </div>
241
+ <div class="hx-forge-tabs" role="group" aria-label="Show" data-corn="tabs">
242
+ <button type="button" class="hx-forge-tab" data-forge-kind="specs" aria-pressed="true" title="The proposals: what a change would add, change and remove" data-corn="tab"><span data-corn-string="tabSpecs">Specs</span><span class="hx-forge-count" hidden></span></button>
243
+ <button type="button" class="hx-forge-tab" data-forge-kind="pulls" aria-pressed="false" title="Pull requests" data-corn="tab"><span data-corn-string="tabPulls">PRs</span><span class="hx-forge-count" hidden></span></button>
244
+ <button type="button" class="hx-forge-tab" data-forge-kind="issues" aria-pressed="false" data-corn="tab"><span data-corn-string="tabIssues">Issues</span><span class="hx-forge-count" hidden></span></button>
245
+ <button type="button" class="hx-forge-tab" data-forge-kind="threads" aria-pressed="false" title="Ideas and spec conversations, with the nodes they mention" data-corn="tab"><span data-corn-string="tabThreads">Threads</span><span class="hx-forge-count" hidden></span></button>
246
+ <button type="button" class="hx-forge-tab" data-forge-kind="work" aria-pressed="false" title="Agent runs, and the work grouped by issue and proposal with agent-made work marked" data-corn="tab"><span data-corn-string="tabRuns">Runs</span><span class="hx-forge-count" hidden></span></button>
247
+ <button type="button" class="hx-forge-tab" data-forge-kind="deploys" aria-pressed="false" data-corn="tab"><span data-corn-string="tabDeploys">Deploys</span><span class="hx-forge-count" hidden></span></button>
248
+ </div>
249
+ <div id="forge-bar" class="hx-forge-bar">
250
+ <p id="forge-status" class="hx-forge-status hx-faint"></p>
251
+ <button type="button" id="forge-filter-chip" class="hx-forge-chip" data-action="toggle-filters" aria-expanded="false" aria-controls="forge-filter-box" hidden>Filter<span class="hx-forge-count" hidden></span></button>
252
+ </div>
253
+ <div id="forge-filter-box" class="hx-forge-controls" hidden>
251
254
  <div id="forge-work-filters" class="hx-forge-work-filters" hidden>
252
255
  <label class="hx-forge-toggle"><input type="checkbox" id="forge-work-agents" /> Agent-made only</label>
253
256
  <label class="hx-forge-toggle"><input type="checkbox" id="forge-work-finished" /> Include merged and closed</label>
@@ -261,25 +264,10 @@
261
264
  </div>
262
265
  <p id="forge-notice" class="hx-forge-notice" hidden data-corn="notice"></p>
263
266
  <p id="forge-act-note" class="hx-forge-notice" hidden data-corn="notice"></p>
264
- <!-- New idea (forge-panel.js): opens an issue with the threads label as you, on the forge; the thread itself lives there -->
265
- <section id="forge-idea" class="hx-forge-notes" aria-label="New idea" data-corn-string-aria-label="newIdea" hidden>
266
- <div class="hx-forge-actions">
267
- <button type="button" id="idea-open" class="hx-btn hx-btn--approve" data-action="idea-open" aria-expanded="false" aria-controls="idea-form" data-corn-kind="approve"><span data-corn-string="newIdea">New idea</span> …</button>
268
- </div>
269
- <p id="idea-message" class="hx-forge-msg" role="status" hidden data-corn="message"></p>
270
- <div id="idea-form" class="hx-forge-confirm" role="group" aria-labelledby="idea-form-title" hidden>
271
- <h3 id="idea-form-title" class="hx-forge-confirm-title" data-corn-string="newIdea">New idea</h3>
272
- <p id="idea-words"></p>
273
- <label class="hx-forge-field" data-corn="field">Title<input type="text" id="idea-title" class="hx-forge-input" maxlength="256" autocomplete="off" /></label>
274
- <label class="hx-forge-field" data-corn="field">What is the idea?<textarea id="idea-body" class="hx-forge-preview hx-thread-compose" rows="6" maxlength="20000" spellcheck="true"></textarea></label>
275
- <div class="hx-forge-actions">
276
- <button type="button" id="idea-send" class="hx-btn hx-btn--approve" data-action="idea-send" data-corn-kind="approve">Open the idea</button>
277
- <button type="button" class="hx-btn hx-btn--quiet" data-action="idea-cancel" data-corn-kind="quiet">Cancel</button>
278
- </div>
279
- </div>
280
- </section>
281
- <!-- Release notes (forge-panel.js): the pull requests merged since a tag, grouped by the map; copy them, or have the forge keep them as a draft release -->
267
+ <!-- Release notes (forge-panel.js), reached from the PRs list: the pull requests merged since a tag, grouped by the map; copy them, or have the forge keep them as a draft release -->
282
268
  <section id="forge-notes" class="hx-forge-notes" aria-label="Release notes" hidden>
269
+ <button type="button" class="hx-forge-back" data-action="close-notes"><svg width="14" height="14" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.6" aria-hidden="true"><path d="M10 3L5 8l5 5"/></svg><span class="hx-forge-back-text">All pull requests</span></button>
270
+ <h3 id="notes-title" class="hx-forge-notes-title" tabindex="-1">Release notes</h3>
283
271
  <label class="hx-forge-field" data-corn="field">Since tag<select id="notes-since" class="hx-forge-select"></select></label>
284
272
  <label class="hx-forge-field" data-corn="field">Draft, in Markdown<textarea id="notes-preview" class="hx-forge-preview" rows="14" readonly spellcheck="false"></textarea></label>
285
273
  <div class="hx-forge-actions">
@@ -297,7 +285,7 @@
297
285
  </div>
298
286
  </div>
299
287
  </section>
300
- <!-- Agent runs (forge-panel.js, runs-model.js): shown on the Agents tab; each run's state, what it is about, links, and Stop -->
288
+ <!-- Agent runs (forge-panel.js, runs-model.js): shown on the Runs tab; each run's state, what it is about, links, and Stop -->
301
289
  <section id="forge-runs" class="hx-forge-runs" aria-labelledby="forge-runs-title" hidden>
302
290
  <h3 id="forge-runs-title" class="hx-forge-runs-title">Agent runs</h3>
303
291
  <p id="forge-runs-status" class="hx-forge-meta hx-faint"></p>
@@ -310,6 +298,27 @@
310
298
  </section>
311
299
  <section id="forge-detail" class="hx-forge-detail" aria-label="Selected pull request" hidden></section>
312
300
  <ul id="forge-list" class="hx-forge-list" aria-label="Results"></ul>
301
+ <!-- The foot of the list: Release notes… on the PRs list, New idea on Specs (and Threads) -->
302
+ <div id="forge-foot" class="hx-forge-foot">
303
+ <button type="button" id="notes-open" class="hx-btn" data-action="open-notes" hidden>Release notes …</button>
304
+ <!-- New idea (forge-panel.js): opens an issue with the threads label as you, on the forge; the thread itself lives there -->
305
+ <section id="forge-idea" class="hx-forge-notes" aria-label="New idea" data-corn-string-aria-label="newIdea" hidden>
306
+ <div class="hx-forge-actions">
307
+ <button type="button" id="idea-open" class="hx-btn hx-btn--approve" data-action="idea-open" aria-expanded="false" aria-controls="idea-form" data-corn-kind="approve"><span data-corn-string="newIdea">New idea</span> …</button>
308
+ </div>
309
+ <p id="idea-message" class="hx-forge-msg" role="status" hidden data-corn="message"></p>
310
+ <div id="idea-form" class="hx-forge-confirm" role="group" aria-labelledby="idea-form-title" hidden>
311
+ <h3 id="idea-form-title" class="hx-forge-confirm-title" data-corn-string="newIdea">New idea</h3>
312
+ <p id="idea-words"></p>
313
+ <label class="hx-forge-field" data-corn="field">Title<input type="text" id="idea-title" class="hx-forge-input" maxlength="256" autocomplete="off" /></label>
314
+ <label class="hx-forge-field" data-corn="field">What is the idea?<textarea id="idea-body" class="hx-forge-preview hx-thread-compose" rows="6" maxlength="20000" spellcheck="true"></textarea></label>
315
+ <div class="hx-forge-actions">
316
+ <button type="button" id="idea-send" class="hx-btn hx-btn--approve" data-action="idea-send" data-corn-kind="approve">Open the idea</button>
317
+ <button type="button" class="hx-btn hx-btn--quiet" data-action="idea-cancel" data-corn-kind="quiet">Cancel</button>
318
+ </div>
319
+ </div>
320
+ </section>
321
+ </div>
313
322
  <p id="forge-rate" class="hx-forge-rate hx-faint"></p>
314
323
  </div>
315
324
  </aside>
@@ -192,6 +192,48 @@ export function proposalPanelHtml(item) {
192
192
  </div>`;
193
193
  }
194
194
 
195
+ // ---------------------------------------------------------------------------
196
+ // A proposal as a row of the Work panel's Specs tab
197
+ // ---------------------------------------------------------------------------
198
+
199
+ /** What a listing entry's state pill says: its spec PR's state, or "Local" for a proposal that is only in a checkout or a worktree */
200
+ export const specState = (entry) => (entry.pull ? (entry.pull.draft ? 'Draft' : 'Open') : 'Local');
201
+
202
+ /** Where a listing entry is, as a line of meta: "PR #11", or the checkout or worktree it is in */
203
+ export function specWhere(entry) {
204
+ if (entry.pull) return `PR #${entry.pull.number}`;
205
+ return entry.source === 'checkout' ? 'in the checkout' : `in worktree ${entry.source}`;
206
+ }
207
+
208
+ /**
209
+ * One row: title, a state pill, a line of what it is for, and the meta (spec number, where it is, +added ~changed −removed, scenarios).
210
+ * A proposal that could not be read is a row that says why and opens nothing. Same `open-proposal` action as the Proposals menu's row.
211
+ * @param {{ slug: string, source: string, title?: string, summary?: string, spec?: string, pull?: {number: number, draft?: boolean}, counts?: {added?: number, changed?: number, removed?: number, scenarios?: number}, errors?: number, error?: string }} entry
212
+ * @param {{ current?: {slug: string, source: string} | null }} [opts] the proposal that is open now
213
+ */
214
+ export function specRowHtml(entry, { current = null } = {}) {
215
+ const head = `<span class="hx-forge-title">${escHtml(entry.title || entry.slug)}</span>`;
216
+ if (entry.error) {
217
+ return `<li class="hx-forge-item"><div class="hx-forge-row hx-forge-spec" data-corn="row">${head}<span class="hx-forge-sum hx-error-text">${escHtml(entry.error)}</span><span class="hx-forge-meta">${escHtml(specWhere(entry))}</span></div></li>`;
218
+ }
219
+ const state = specState(entry);
220
+ const tone = state === 'Local' ? '' : ` data-corn-state="${state === 'Draft' ? 'draft' : 'open'}"`;
221
+ const c = entry.counts || {};
222
+ const meta = [
223
+ entry.spec ? `<span>spec ${escHtml(entry.spec)}</span>` : '',
224
+ `<span>${escHtml(specWhere(entry))}</span>`,
225
+ c.added ? `<span class="hx-forge-add" title="${c.added} added">+${c.added}</span>` : '',
226
+ c.changed ? `<span class="hx-forge-chg" title="${c.changed} changed">~${c.changed}</span>` : '',
227
+ c.removed ? `<span class="hx-forge-del" title="${c.removed} removed">\u2212${c.removed}</span>` : '',
228
+ c.scenarios ? `<span>${c.scenarios} ${c.scenarios === 1 ? 'scenario' : 'scenarios'}</span>` : '',
229
+ entry.errors ? `<span class="hx-warn">${entry.errors} ${entry.errors === 1 ? 'problem' : 'problems'}</span>` : '',
230
+ ].filter(Boolean).join('');
231
+ const mine = !!current && current.slug === entry.slug && current.source === entry.source;
232
+ return `<li class="hx-forge-item"><button type="button" class="hx-forge-row hx-forge-spec" data-action="open-proposal" data-slug="${escHtml(entry.slug)}" data-source="${escHtml(entry.source)}" aria-pressed="${mine}" data-corn="row">`
233
+ + `<span class="hx-forge-line">${head}<span class="hx-forge-state hx-forge-state--${state === 'Draft' ? 'draft' : state === 'Open' ? 'open' : 'neutral'}" data-corn="state-pill"${tone}>${state}</span></span>`
234
+ + `${entry.summary ? `<span class="hx-forge-sum">${escHtml(entry.summary)}</span>` : ''}<span class="hx-forge-meta hx-forge-facts">${meta}</span></button></li>`;
235
+ }
236
+
195
237
  // ---------------------------------------------------------------------------
196
238
  // Where an added node sits
197
239
  // ---------------------------------------------------------------------------
@@ -53,6 +53,17 @@ let listing = null;
53
53
  let listingProblem = null;
54
54
  /** Why the server left the open spec PRs out of the last listing (the forge could not be asked), or null */
55
55
  let forgeProblem = null;
56
+ /** When the listing was last read (ms), and who wants to hear of a new one (the Work panel's Specs tab, forge-panel.js) */
57
+ let listingAt = 0;
58
+ const listingWatchers = new Set();
59
+
60
+ /** What the server listed last, for the Work panel's Specs tab: the entries (null before the first answer), why the list could not be read, why the spec PRs are missing, and when */
61
+ export const proposalListing = () => ({ entries: listing, problem: listingProblem, forgeProblem, at: listingAt });
62
+ /** Calls `fn` each time the list is read again; returns the way to stop */
63
+ export function onProposalListing(fn) {
64
+ listingWatchers.add(fn);
65
+ return () => listingWatchers.delete(fn);
66
+ }
56
67
 
57
68
  // ---------------------------------------------------------------------------
58
69
  // Loading and closing
@@ -63,7 +74,9 @@ export async function loadProposalList() {
63
74
  try {
64
75
  const res = await fetch('/proposals', { cache: 'no-store' });
65
76
  if (!res.ok) throw new Error(`GET /proposals answered ${res.status}`);
66
- listing = await res.json();
77
+ const body = await res.json();
78
+ if (!Array.isArray(body)) throw new Error('GET /proposals did not answer with a list');
79
+ listing = body;
67
80
  listingProblem = null;
68
81
  const said = res.headers.get('X-Proposals-Forge-Error');
69
82
  forgeProblem = said ? decodeURIComponent(said) : null;
@@ -72,7 +85,9 @@ export async function loadProposalList() {
72
85
  forgeProblem = null;
73
86
  listingProblem = err.message || String(err);
74
87
  }
88
+ listingAt = Date.now();
75
89
  renderMenu();
90
+ for (const fn of listingWatchers) fn();
76
91
  return listing;
77
92
  }
78
93
 
@@ -59,6 +59,21 @@ export function runOnThread(runs, number) {
59
59
  return [...mine.filter((r) => r.open === true).sort(newest), ...mine.filter((r) => r.open !== true).sort(newest)][0];
60
60
  }
61
61
 
62
+ /** The run that made a pull request (the one whose pull request it is), an open one before a finished one, then the newest; null when none did */
63
+ export function runOnPull(runs, number) {
64
+ if (!Array.isArray(runs)) return null;
65
+ const mine = runs.filter((r) => r.pull && r.pull.number === number);
66
+ const newest = (a, b) => Date.parse(b.requestedAt || 0) - Date.parse(a.requestedAt || 0);
67
+ return [...mine.filter((r) => r.open === true).sort(newest), ...mine.filter((r) => r.open !== true).sort(newest)][0] || null;
68
+ }
69
+
70
+ /** A pull request's run in one line: who is running it, its state, how long ago it was asked for, and the cost the runner reported ("bucket-bot · Working · asked 12 min ago · cost 0.84") */
71
+ export function pullRunWords(run, nowMs) {
72
+ const who = (run.report && run.report.by) || (run.pull && run.pull.by) || run.requestedBy;
73
+ const when = relativeTime(run.requestedAt, nowMs);
74
+ return [who, statusWords(run), when && `asked ${when}`, run.report && run.report.cost != null && `cost ${run.report.cost}`].filter(Boolean).join(' · ');
75
+ }
76
+
62
77
  /** What a thread's row says of its run, in a few words: "Run: Working" (more than one run on it: "Run: Working (+1)") */
63
78
  export function threadRunWords(runs, number) {
64
79
  const run = runOnThread(runs, number);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@popcorn245/cornfield",
3
- "version": "0.31.0",
3
+ "version": "0.32.0",
4
4
  "description": "A self-hostable dev dashboard with the topology map at its centre: proposals on the map, scenarios, outages and what-if edits, for any repo.",
5
5
  "license": "MIT",
6
6
  "author": "popcorn245 (https://github.com/popcorn245)",