@spunto/design-system 0.52.0 → 0.53.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
@@ -362,6 +362,15 @@ Same rules as `/workers`: nothing fetches, types are structural and lax
362
362
  secrets") instead of showing a bare chevron, and the form opens it by itself
363
363
  when any of those sections already has a value — so editing a project never
364
364
  hides a setting you made earlier.
365
+ - **Or a sidebar of pages** (`layout="sidebar"`, 0.52.0) — what the dashboard's
366
+ creation screen uses. A left rail of pages (`groups`, default `DEFAULT_GROUPS`:
367
+ General = identity + image + repos, then Tooling, Lifecycle, Runtime,
368
+ Secrets), one page shown at a time. Every entry says whether it holds
369
+ something required, **names what's missing**, and recaps what it already
370
+ holds; each section header carries a Required / Optional badge. The rail is
371
+ the recap, so `manifest` and `advancedSections` don't apply. Submitting with a
372
+ required section empty (`REQUIRED_SECTIONS`, or `required: true` on a custom
373
+ section) is refused and jumps to the page of the first one.
365
374
  - **Git hosting is a list of providers, not GitHub** (0.21.0). `gitProviders`
366
375
  (id, name, `connected`, `accounts`, `installUrl`, `operations`, `icon`) and
367
376
  `gitRepos` (each tagged with its `provider`) replace `githubRepos` / `github` /
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spunto/design-system",
3
- "version": "0.52.0",
3
+ "version": "0.53.0",
4
4
  "description": "Spunto's shared design system — green tokens (conservatory + sprout), color constants, and UI primitives.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -52,6 +52,9 @@ export const STACK_MARK_PATHS = {
52
52
  "M13.88 12.685c-.4 0 .08.2.601.28.14-.1.27-.22.39-.33a3.001 3.001 0 01-.99.05m2.14-.53c.23-.33.4-.69.47-1.06-.06.27-.2.5-.33.73-.75.47-.07-.27 0-.56-.8 1.01-.11.6-.14.89m.781-2.05c.05-.721-.14-.501-.2-.221.07.04.13.5.2.22M12.38.31c.2.04.45.07.42.12.23-.05.28-.1-.43-.12m.43.12l-.15.03.14-.01V.43m6.633 9.944c.02.64-.2.95-.38 1.5l-.35.181c-.28.54.03.35-.17.78-.44.39-1.34 1.22-1.62 1.301-.201 0 .14-.25.19-.34-.591.4-.481.6-1.371.85l-.03-.06c-2.221 1.04-5.303-1.02-5.253-3.842-.03.17-.07.13-.12.2a3.551 3.552 0 012.001-3.501 3.361 3.362 0 013.732.48 3.341 3.342 0 00-2.721-1.3c-1.18.01-2.281.76-2.651 1.57-.6.38-.67 1.47-.93 1.661-.361 2.601.66 3.722 2.38 5.042.27.19.08.21.12.35a4.702 4.702 0 01-1.53-1.16c.23.33.47.66.8.91-.55-.18-1.27-1.3-1.48-1.35.93 1.66 3.78 2.921 5.261 2.3a6.203 6.203 0 01-2.33-.28c-.33-.16-.77-.51-.7-.57a5.802 5.803 0 005.902-.84c.44-.35.93-.94 1.07-.95-.2.32.04.16-.12.44.44-.72-.2-.3.46-1.24l.24.33c-.09-.6.74-1.321.66-2.262.19-.3.2.3 0 .97.29-.74.08-.85.15-1.46.08.2.18.42.23.63-.18-.7.2-1.2.28-1.6-.09-.05-.28.3-.32-.53 0-.37.1-.2.14-.28-.08-.05-.26-.32-.38-.861.08-.13.22.33.34.34-.08-.42-.2-.75-.2-1.08-.34-.68-.12.1-.4-.3-.34-1.091.3-.25.34-.74.54.77.84 1.96.981 2.46-.1-.6-.28-1.2-.49-1.76.16.07-.26-1.241.21-.37A7.823 7.824 0 0017.702 1.6c.18.17.42.39.33.42-.75-.45-.62-.48-.73-.67-.61-.25-.65.02-1.06 0C15.082.73 14.862.8 13.8.4l.05.23c-.77-.25-.9.1-1.73 0-.05-.04.27-.14.53-.18-.741.1-.701-.14-1.431.03.17-.13.36-.21.55-.32-.6.04-1.44.35-1.18.07C9.6.68 7.847 1.3 6.867 2.22L6.838 2c-.45.54-1.96 1.611-2.08 2.311l-.131.03c-.23.4-.38.85-.57 1.261-.3.52-.45.2-.4.28-.6 1.22-.9 2.251-1.16 3.102.18.27 0 1.65.07 2.76-.3 5.463 3.84 10.776 8.363 12.006.67.23 1.65.23 2.49.25-.99-.28-1.12-.15-2.08-.49-.7-.32-.85-.7-1.34-1.13l.2.35c-.971-.34-.57-.42-1.361-.67l.21-.27c-.31-.03-.83-.53-.97-.81l-.34.01c-.41-.501-.63-.871-.61-1.161l-.111.2c-.13-.21-1.52-1.901-.8-1.511-.13-.12-.31-.2-.5-.55l.14-.17c-.35-.44-.64-1.02-.62-1.2.2.24.32.3.45.33-.88-2.172-.93-.12-1.601-2.202l.15-.02c-.1-.16-.18-.34-.26-.51l.06-.6c-.63-.74-.18-3.102-.09-4.402.07-.54.53-1.1.88-1.981l-.21-.04c.4-.71 2.341-2.872 3.241-2.761.43-.55-.09 0-.18-.14.96-.991 1.26-.7 1.901-.88.7-.401-.6.16-.27-.151 1.2-.3.85-.7 2.421-.85.16.1-.39.14-.52.26 1-.49 3.151-.37 4.562.27 1.63.77 3.461 3.011 3.531 5.132l.08.02c-.04.85.13 1.821-.17 2.711l.2-.42M9.54 13.236l-.05.28c.26.35.47.73.8 1.01-.24-.47-.42-.66-.75-1.3m.62-.02c-.14-.15-.22-.34-.31-.52.08.32.26.6.43.88l-.12-.36m10.945-2.382l-.07.15c-.1.76-.34 1.511-.69 2.212.4-.73.65-1.541.75-2.362M12.45.12c.27-.1.66-.05.95-.12-.37.03-.74.05-1.1.1l.15.02M3.006 5.142c.07.57-.43.8.11.42.3-.66-.11-.18-.1-.42m-.64 2.661c.12-.39.15-.62.2-.84-.35.44-.17.53-.2.83",
53
53
  bash:
54
54
  "M21.038,4.9l-7.577-4.498C13.009,0.134,12.505,0,12,0c-0.505,0-1.009,0.134-1.462,0.403L2.961,4.9 C2.057,5.437,1.5,6.429,1.5,7.503v8.995c0,1.073,0.557,2.066,1.462,2.603l7.577,4.497C10.991,23.866,11.495,24,12,24 c0.505,0,1.009-0.134,1.461-0.402l7.577-4.497c0.904-0.537,1.462-1.529,1.462-2.603V7.503C22.5,6.429,21.943,5.437,21.038,4.9z M15.17,18.946l0.013,0.646c0.001,0.078-0.05,0.167-0.111,0.198l-0.383,0.22c-0.061,0.031-0.111-0.007-0.112-0.085L14.57,19.29 c-0.328,0.136-0.66,0.169-0.872,0.084c-0.04-0.016-0.057-0.075-0.041-0.142l0.139-0.584c0.011-0.046,0.036-0.092,0.069-0.121 c0.012-0.011,0.024-0.02,0.036-0.026c0.022-0.011,0.043-0.014,0.062-0.006c0.229,0.077,0.521,0.041,0.802-0.101 c0.357-0.181,0.596-0.545,0.592-0.907c-0.003-0.328-0.181-0.465-0.613-0.468c-0.55,0.001-1.064-0.107-1.072-0.917 c-0.007-0.667,0.34-1.361,0.889-1.8l-0.007-0.652c-0.001-0.08,0.048-0.168,0.111-0.2l0.37-0.236 c0.061-0.031,0.111,0.007,0.112,0.087l0.006,0.653c0.273-0.109,0.511-0.138,0.726-0.088c0.047,0.012,0.067,0.076,0.048,0.151 l-0.144,0.578c-0.011,0.044-0.036,0.088-0.065,0.116c-0.012,0.012-0.025,0.021-0.038,0.028c-0.019,0.01-0.038,0.013-0.057,0.009 c-0.098-0.022-0.332-0.073-0.699,0.113c-0.385,0.195-0.52,0.53-0.517,0.778c0.003,0.297,0.155,0.387,0.681,0.396 c0.7,0.012,1.003,0.318,1.01,1.023C16.105,17.747,15.736,18.491,15.17,18.946z M19.143,17.859c0,0.06-0.008,0.116-0.058,0.145 l-1.916,1.164c-0.05,0.029-0.09,0.004-0.09-0.056v-0.494c0-0.06,0.037-0.093,0.087-0.122l1.887-1.129 c0.05-0.029,0.09-0.004,0.09,0.056V17.859z M20.459,6.797l-7.168,4.427c-0.894,0.523-1.553,1.109-1.553,2.187v8.833 c0,0.645,0.26,1.063,0.66,1.184c-0.131,0.023-0.264,0.039-0.398,0.039c-0.42,0-0.833-0.114-1.197-0.33L3.226,18.64 c-0.741-0.44-1.201-1.261-1.201-2.142V7.503c0-0.881,0.46-1.702,1.201-2.142l7.577-4.498c0.363-0.216,0.777-0.33,1.197-0.33 c0.419,0,0.833,0.114,1.197,0.33l7.577,4.498c0.624,0.371,1.046,1.013,1.164,1.732C21.686,6.557,21.12,6.411,20.459,6.797z",
55
+ // simple-icons `openai` — the mark of the Codex agent app (RFC 0048).
56
+ openai:
57
+ "M22.2819 9.8211a5.9847 5.9847 0 0 0-.5157-4.9108 6.0462 6.0462 0 0 0-6.5098-2.9A6.0651 6.0651 0 0 0 4.9807 4.1818a5.9847 5.9847 0 0 0-3.9977 2.9 6.0462 6.0462 0 0 0 .7427 7.0966 5.98 5.98 0 0 0 .511 4.9107 6.051 6.051 0 0 0 6.5146 2.9001A5.9847 5.9847 0 0 0 13.2599 24a6.0557 6.0557 0 0 0 5.7718-4.2058 5.9894 5.9894 0 0 0 3.9977-2.9001 6.0557 6.0557 0 0 0-.7475-7.0729zm-9.022 12.6081a4.4755 4.4755 0 0 1-2.8764-1.0408l.1419-.0804 4.7783-2.7582a.7948.7948 0 0 0 .3927-.6813v-6.7369l2.02 1.1686a.071.071 0 0 1 .038.052v5.5826a4.504 4.504 0 0 1-4.4945 4.4944zm-9.6607-4.1254a4.4708 4.4708 0 0 1-.5346-3.0137l.142.0852 4.783 2.7582a.7712.7712 0 0 0 .7806 0l5.8428-3.3685v2.3324a.0804.0804 0 0 1-.0332.0615L9.74 19.9502a4.4992 4.4992 0 0 1-6.1408-1.6464zM2.3408 7.8956a4.485 4.485 0 0 1 2.3655-1.9728V11.6a.7664.7664 0 0 0 .3879.6765l5.8144 3.3543-2.0201 1.1685a.0757.0757 0 0 1-.071 0l-4.8303-2.7865A4.504 4.504 0 0 1 2.3408 7.872zm16.5963 3.8558L13.1038 8.364 15.1192 7.2a.0757.0757 0 0 1 .071 0l4.8303 2.7913a4.4944 4.4944 0 0 1-.6765 8.1042v-5.6772a.79.79 0 0 0-.407-.667zm2.0107-3.0231l-.142-.0852-4.7735-2.7818a.7759.7759 0 0 0-.7854 0L9.409 9.2297V6.8974a.0662.0662 0 0 1 .0284-.0615l4.8303-2.7866a4.4992 4.4992 0 0 1 6.6802 4.66zM8.3065 12.863l-2.02-1.1638a.0804.0804 0 0 1-.038-.0567V6.0742a4.4992 4.4992 0 0 1 7.3757-3.4537l-.142.0805L8.704 5.459a.7948.7948 0 0 0-.3927.6813zm1.0976-2.3654l2.602-1.4998 2.6069 1.4998v2.9994l-2.5974 1.4997-2.6067-1.4997Z",
55
58
  claude:
56
59
  "m4.7144 15.9555 4.7174-2.6471.079-.2307-.079-.1275h-.2307l-.7893-.0486-2.6956-.0729-2.3375-.0971-2.2646-.1214-.5707-.1215-.5343-.7042.0546-.3522.4797-.3218.686.0608 1.5179.1032 2.2767.1578 1.6514.0972 2.4468.255h.3886l.0546-.1579-.1336-.0971-.1032-.0972L6.973 9.8356l-2.55-1.6879-1.3356-.9714-.7225-.4918-.3643-.4614-.1578-1.0078.6557-.7225.8803.0607.2246.0607.8925.686 1.9064 1.4754 2.4893 1.8336.3643.3035.1457-.1032.0182-.0728-.164-.2733-1.3539-2.4467-1.445-2.4893-.6435-1.032-.17-.6194c-.0607-.255-.1032-.4674-.1032-.7285L6.287.1335 6.6997 0l.9957.1336.419.3642.6192 1.4147 1.0018 2.2282 1.5543 3.0296.4553.8985.2429.8318.091.255h.1579v-.1457l.1275-1.706.2368-2.0947.2307-2.6957.0789-.7589.3764-.9107.7468-.4918.5828.2793.4797.686-.0668.4433-.2853 1.8517-.5586 2.9021-.3643 1.9429h.2125l.2429-.2429.9835-1.3053 1.6514-2.0643.7286-.8196.85-.9046.5464-.4311h1.0321l.759 1.1293-.34 1.1657-1.0625 1.3478-.8804 1.1414-1.2628 1.7-.7893 1.36.0729.1093.1882-.0183 2.8535-.607 1.5421-.2794 1.8396-.3157.8318.3886.091.3946-.3278.8075-1.967.4857-2.3072.4614-3.4364.8136-.0425.0304.0486.0607 1.5482.1457.6618.0364h1.621l3.0175.2247.7892.522.4736.6376-.079.4857-1.2142.6193-1.6393-.3886-3.825-.9107-1.3113-.3279h-.1822v.1093l1.0929 1.0686 2.0035 1.8092 2.5075 2.3314.1275.5768-.3218.4554-.34-.0486-2.2039-1.6575-.85-.7468-1.9246-1.621h-.1275v.17l.4432.6496 2.3436 3.5214.1214 1.0807-.17.3521-.6071.2125-.6679-.1214-1.3721-1.9246L14.38 17.959l-1.1414-1.9428-.1397.079-.674 7.2552-.3156.3703-.7286.2793-.6071-.4614-.3218-.7468.3218-1.4753.3886-1.9246.3157-1.53.2853-1.9004.17-.6314-.0121-.0425-.1397.0182-1.4328 1.9672-2.1796 2.9446-1.7243 1.8456-.4128.164-.7164-.3704.0667-.6618.4008-.5889 2.386-3.0357 1.4389-1.882.929-1.0868-.0062-.1579h-.0546l-6.3385 4.1164-1.1293.1457-.4857-.4554.0608-.7467.2307-.2429 1.9064-1.3114Z",
57
60
  } as const satisfies Record<string, string>
@@ -0,0 +1,16 @@
1
+ import { describe, expect, it } from "vitest"
2
+ import { STACK_MARK_PATHS, resolveStackMark } from "./stack-mark"
3
+
4
+ describe("resolveStackMark", () => {
5
+ it("gives each agent app its brand (RFC 0048)", () => {
6
+ expect(resolveStackMark("claude")).toBe("claude")
7
+ expect(resolveStackMark("codex")).toBe("openai")
8
+ expect(resolveStackMark("spunto-agent-codex")).toBe("openai")
9
+ expect(STACK_MARK_PATHS.openai.startsWith("M")).toBe(true)
10
+ })
11
+
12
+ it("keeps the more specific patterns first", () => {
13
+ expect(resolveStackMark("typescript-node-26")).toBe("typescript")
14
+ expect(resolveStackMark("unknown-thing")).toBeUndefined()
15
+ })
16
+ })
@@ -27,6 +27,7 @@ const PATTERNS: [RegExp, StackMarkName][] = [
27
27
  [/google-?cloud|gcloud|(^|[^a-z])gcp([^a-z]|$)/, "googlecloud"],
28
28
  [/github|(^|[^a-z])gh([^a-z]|$)/, "github"],
29
29
  [/claude|anthropic/, "claude"],
30
+ [/openai|codex/, "openai"],
30
31
  [/jekyll/, "jekyll"],
31
32
  [/ruby|rails/, "ruby"],
32
33
  [/rust|cargo/, "rust"],
@@ -5,12 +5,12 @@ import { ChevronDownIcon, Settings2Icon } from "lucide-react"
5
5
 
6
6
  import { cn } from "../../utils"
7
7
  import {
8
- isInternalSectionId,
9
8
  type ProjectFormCustomSection,
10
9
  type ProjectFormSectionId,
11
10
  type ProjectFormValue,
12
11
  type ProjectSecretRef,
13
12
  } from "./types"
13
+ import { sectionSummary } from "./section-status"
14
14
 
15
15
  export interface AdvancedDisclosureProps {
16
16
  open: boolean
@@ -124,44 +124,12 @@ export function advancedSummary<TValue extends ProjectFormValue>(
124
124
  */
125
125
  customSections: ProjectFormCustomSection<TValue>[] = []
126
126
  ): string[] {
127
- const custom = new Map(customSections.filter((s) => !isInternalSectionId(s.id)).map((s) => [s.id, s]))
128
- const out: string[] = []
129
- for (const id of sections) {
130
- const own = custom.get(id)
131
- if (own) {
132
- const label = own.summary?.(value)
133
- if (label) out.push(label)
134
- continue
135
- }
136
- switch (id) {
137
- case "features":
138
- if (value.features.length) out.push(`${value.features.length} feature${value.features.length > 1 ? "s" : ""}`)
139
- break
140
- case "extensions":
141
- if (value.vscodeExtensions.length)
142
- out.push(`${value.vscodeExtensions.length} extension${value.vscodeExtensions.length > 1 ? "s" : ""}`)
143
- break
144
- case "lifecycle":
145
- if (value.postCreateCommand || value.postStartCommand) out.push("lifecycle")
146
- break
147
- case "ports":
148
- if (value.forwardPorts.length) out.push(`ports ${value.forwardPorts.join(", ")}`)
149
- break
150
- case "prewarm":
151
- if (value.prewarmImages.length) out.push(`${value.prewarmImages.length} prewarm`)
152
- break
153
- case "docker":
154
- if (value.dockerInDocker) out.push("docker-in-docker")
155
- break
156
- case "secrets": {
157
- const n = value.secrets.length + savedSecrets.filter((x) => !value.removedSecretIds.includes(x.id)).length
158
- if (n) out.push(`${n} secret${n > 1 ? "s" : ""}`)
159
- break
160
- }
161
- // Identity, image and repositories are never advanced — they're the form.
162
- default:
163
- break
164
- }
165
- }
166
- return out
127
+ return sections.flatMap((id) => {
128
+ // The three sections that *are* the form keep out of the fold's sentence
129
+ // even if a caller folds them: "my-project" isn't a setting you'd look for
130
+ // behind "Advanced options".
131
+ if (id === "identity" || id === "image" || id === "repositories") return []
132
+ const label = sectionSummary(value, id, savedSecrets, customSections)
133
+ return label ? [label] : []
134
+ })
167
135
  }
@@ -0,0 +1,225 @@
1
+ "use client"
2
+
3
+ import type { ComponentType, ReactNode } from "react"
4
+ import { AsteriskIcon, CheckIcon } from "lucide-react"
5
+
6
+ import { cn } from "../../utils"
7
+
8
+ /** One page of a sectioned form, as its nav entry sees it — counts, not values. */
9
+ export interface FormNavItem {
10
+ id: string
11
+ title: string
12
+ icon?: ComponentType<{ className?: string }>
13
+ /** Required sections on this page. */
14
+ required: number
15
+ /** Titles of the required sections still empty — named in the nav, not just counted. */
16
+ missing: string[]
17
+ /** One label per section that holds something (`my-project`, `2 features`). */
18
+ summary: string[]
19
+ }
20
+
21
+ export interface FormNavProps {
22
+ items: FormNavItem[]
23
+ active: string
24
+ onSelect: (id: string) => void
25
+ /** Turns "missing" from a reminder into an error — set once a submit was refused. */
26
+ showErrors?: boolean
27
+ /** Under the list: the submit block, typically. */
28
+ footer?: ReactNode
29
+ className?: string
30
+ }
31
+
32
+ /** Where a page stands: something required is missing, something is set, or nothing yet. */
33
+ function itemState(item: FormNavItem): "missing" | "done" | "empty" {
34
+ if (item.missing.length) return "missing"
35
+ return item.summary.length || item.required ? "done" : "empty"
36
+ }
37
+
38
+ /**
39
+ * The left rail of the `sidebar` layout: one entry per page of the form, each
40
+ * saying **whether it's required, what's missing, and what it already holds** —
41
+ * so the state of the whole form reads at a glance, without visiting a page.
42
+ *
43
+ * Three states, three marks, and a legend under the list that names them: a
44
+ * mark you have to guess the meaning of isn't an indicator.
45
+ *
46
+ * Below the container's `48rem`, the rail turns into a strip of pills over the
47
+ * content; the counts collapse into the mark alone.
48
+ */
49
+ export function FormNav({ items, active, onSelect, showErrors = false, footer, className }: FormNavProps) {
50
+ const required = items.reduce((n, i) => n + i.required, 0)
51
+ const missing = items.reduce((n, i) => n + i.missing.length, 0)
52
+ const done = required - missing
53
+
54
+ return (
55
+ <nav data-slot="form-nav" aria-label="Form sections" className={cn("space-y-4", className)}>
56
+ {required > 0 && (
57
+ <div className="hidden space-y-2 @min-[48rem]/form:block">
58
+ <div className="flex items-baseline justify-between text-xs">
59
+ <span className="font-medium">Required</span>
60
+ <span className={cn("font-mono", missing ? "text-muted-foreground" : "text-success")}>
61
+ {done}/{required}
62
+ </span>
63
+ </div>
64
+ <div className="flex gap-1" aria-hidden>
65
+ {Array.from({ length: required }, (_, i) => (
66
+ <span
67
+ key={i}
68
+ className={cn("h-1 flex-1 rounded-full transition-colors", i < done ? "bg-success" : "bg-muted")}
69
+ />
70
+ ))}
71
+ </div>
72
+ </div>
73
+ )}
74
+
75
+ <ol
76
+ className={cn(
77
+ // A strip of pills on a narrow form, a list beside it once there's room.
78
+ "-mx-1 flex gap-1.5 overflow-x-auto px-1 pb-1",
79
+ "@min-[48rem]/form:mx-0 @min-[48rem]/form:flex-col @min-[48rem]/form:gap-1 @min-[48rem]/form:overflow-visible @min-[48rem]/form:px-0 @min-[48rem]/form:pb-0"
80
+ )}
81
+ >
82
+ {items.map((item) => {
83
+ const state = itemState(item)
84
+ const current = item.id === active
85
+ const Icon = item.icon
86
+ return (
87
+ <li key={item.id} className="shrink-0">
88
+ <button
89
+ type="button"
90
+ onClick={() => onSelect(item.id)}
91
+ aria-current={current ? "step" : undefined}
92
+ data-state={state}
93
+ className={cn(
94
+ "group relative flex w-full cursor-pointer items-center gap-2.5 rounded-lg border px-3 py-2 text-left transition-colors",
95
+ "@min-[48rem]/form:items-start @min-[48rem]/form:py-2.5",
96
+ current
97
+ ? "border-border bg-card shadow-sm"
98
+ : "border-transparent hover:bg-muted/60"
99
+ )}
100
+ >
101
+ {current && (
102
+ <span
103
+ aria-hidden
104
+ className="absolute inset-y-2 left-0 hidden w-0.5 rounded-full bg-primary @min-[48rem]/form:block"
105
+ />
106
+ )}
107
+ {Icon && (
108
+ <Icon
109
+ className={cn(
110
+ "h-4 w-4 shrink-0 @min-[48rem]/form:mt-0.5",
111
+ current ? "text-primary" : "text-muted-foreground"
112
+ )}
113
+ />
114
+ )}
115
+ <span className="min-w-0 flex-1">
116
+ <span className="flex items-center gap-1.5 text-sm font-medium whitespace-nowrap">
117
+ {item.title}
118
+ {item.required > 0 && (
119
+ <span className="hidden font-mono text-[10px] font-normal text-muted-foreground @min-[48rem]/form:inline">
120
+ required
121
+ </span>
122
+ )}
123
+ </span>
124
+ <span
125
+ className={cn(
126
+ "mt-0.5 hidden truncate text-xs @min-[48rem]/form:block",
127
+ state === "missing"
128
+ ? showErrors
129
+ ? "text-destructive"
130
+ : "text-warning"
131
+ : "text-muted-foreground"
132
+ )}
133
+ >
134
+ {state === "missing"
135
+ ? `Missing: ${item.missing.join(", ").toLowerCase()}`
136
+ : item.summary.length
137
+ ? item.summary.join(" · ")
138
+ : "Optional · nothing set"}
139
+ </span>
140
+ </span>
141
+ <StateMark state={state} error={showErrors} />
142
+ </button>
143
+ </li>
144
+ )
145
+ })}
146
+ </ol>
147
+
148
+ <ul className="hidden space-y-1 border-t pt-3 text-[11px] text-muted-foreground @min-[48rem]/form:block">
149
+ <li className="flex items-center gap-2">
150
+ <StateMark state="missing" /> Required, still to fill
151
+ </li>
152
+ <li className="flex items-center gap-2">
153
+ <StateMark state="done" /> Filled in
154
+ </li>
155
+ <li className="flex items-center gap-2">
156
+ <StateMark state="empty" /> Optional, nothing set
157
+ </li>
158
+ </ul>
159
+
160
+ {footer}
161
+ </nav>
162
+ )
163
+ }
164
+
165
+ /** The little round mark at the end of a nav entry (and in the legend). */
166
+ function StateMark({ state, error = false }: { state: "missing" | "done" | "empty"; error?: boolean }) {
167
+ return (
168
+ <span
169
+ aria-hidden
170
+ className={cn(
171
+ "flex h-4 w-4 shrink-0 items-center justify-center rounded-full border transition-colors @min-[48rem]/form:mt-0.5",
172
+ state === "done" && "border-success bg-success text-background",
173
+ state === "missing" &&
174
+ (error ? "border-destructive bg-destructive/10 text-destructive" : "border-warning bg-warning/10 text-warning"),
175
+ state === "empty" && "border-dashed border-muted-foreground/40"
176
+ )}
177
+ >
178
+ {state === "done" && <CheckIcon className="h-2.5 w-2.5" strokeWidth={3} />}
179
+ {state === "missing" && <AsteriskIcon className="h-2.5 w-2.5" strokeWidth={3} />}
180
+ </span>
181
+ )
182
+ }
183
+
184
+ /**
185
+ * The badge in a section's header: Required / Optional, and whether it's set.
186
+ * Same words as the nav, so the two never disagree about a section.
187
+ */
188
+ export function SectionStatusBadge({
189
+ required,
190
+ filled,
191
+ error = false,
192
+ }: {
193
+ required: boolean
194
+ filled: boolean
195
+ /** A submit was refused: an empty required section turns red instead of amber. */
196
+ error?: boolean
197
+ }) {
198
+ const base = "inline-flex items-center gap-1 rounded-full border px-2 py-0.5 text-[11px] leading-none font-medium"
199
+ if (filled)
200
+ return (
201
+ <span data-slot="section-status" data-state="done" className={cn(base, "border-success/30 bg-success/10 text-success")}>
202
+ <CheckIcon className="h-3 w-3" strokeWidth={3} />
203
+ {required ? "Required · done" : "Set"}
204
+ </span>
205
+ )
206
+ if (required)
207
+ return (
208
+ <span
209
+ data-slot="section-status"
210
+ data-state="missing"
211
+ className={cn(
212
+ base,
213
+ error ? "border-destructive/40 bg-destructive/10 text-destructive" : "border-warning/40 bg-warning/10 text-warning"
214
+ )}
215
+ >
216
+ <AsteriskIcon className="h-3 w-3" strokeWidth={3} />
217
+ Required
218
+ </span>
219
+ )
220
+ return (
221
+ <span data-slot="section-status" data-state="empty" className={cn(base, "border-dashed text-muted-foreground")}>
222
+ Optional
223
+ </span>
224
+ )
225
+ }
@@ -13,6 +13,8 @@ export interface FormSectionProps {
13
13
  accent?: SectionAccent
14
14
  title: string
15
15
  hint?: string
16
+ /** Right side of the header — a "Required" / "Optional" badge, typically. */
17
+ status?: ReactNode
16
18
  children: ReactNode
17
19
  /** Mostly for the entrance `animationDelay` a stack of sections staggers with. */
18
20
  style?: React.CSSProperties
@@ -31,7 +33,7 @@ export interface FormSectionProps {
31
33
  * for one fade-in, and `motion-reduce:animate-none` covers the accessibility
32
34
  * side that `useReducedMotion` covered before.
33
35
  */
34
- export function FormSection({ n, icon: Icon, accent = "build", title, hint, children, style, className }: FormSectionProps) {
36
+ export function FormSection({ n, icon: Icon, accent = "build", title, hint, status, children, style, className }: FormSectionProps) {
35
37
  return (
36
38
  <section
37
39
  data-slot="form-section"
@@ -54,13 +56,14 @@ export function FormSection({ n, icon: Icon, accent = "build", title, hint, chil
54
56
  {n}
55
57
  </span>
56
58
  )}
57
- <div className="min-w-0">
59
+ <div className="min-w-0 flex-1">
58
60
  <h3 className="flex items-center gap-2 font-display text-base font-bold tracking-tight">
59
61
  {Icon && <Icon className="h-4 w-4 shrink-0 text-[var(--a)]" />}
60
62
  {title}
61
63
  </h3>
62
64
  {hint && <p className="text-xs text-muted-foreground">{hint}</p>}
63
65
  </div>
66
+ {status && <div className="shrink-0 self-start">{status}</div>}
64
67
  </div>
65
68
  {children}
66
69
  </section>
@@ -26,12 +26,17 @@
26
26
  // Every brick is exported on its own, because a screen that needs only the repo
27
27
  // rows or only the manifest shouldn't have to take the form with it.
28
28
 
29
- export { ProjectForm, manifestRows } from "./project-form"
29
+ export { ProjectForm, manifestRows, DEFAULT_GROUPS } from "./project-form"
30
30
  export type { ProjectFormProps } from "./project-form"
31
31
 
32
32
  export { FormSection, Field } from "./form-section"
33
33
  export type { FormSectionProps, SectionAccent } from "./form-section"
34
34
 
35
+ export { FormNav, SectionStatusBadge } from "./form-nav"
36
+ export type { FormNavItem, FormNavProps } from "./form-nav"
37
+
38
+ export { sectionSummary, isSectionRequired } from "./section-status"
39
+
35
40
  export { AdvancedDisclosure, advancedSummary } from "./advanced-sections"
36
41
  export type { AdvancedDisclosureProps } from "./advanced-sections"
37
42
 
@@ -57,6 +62,7 @@ export {
57
62
  CREATE_SECTIONS,
58
63
  EDIT_SECTIONS,
59
64
  INTERNAL_SECTION_IDS,
65
+ REQUIRED_SECTIONS,
60
66
  emptyProjectFormValue,
61
67
  isInternalSectionId,
62
68
  toProjectFormValue,
@@ -65,6 +71,7 @@ export type {
65
71
  InternalSectionId,
66
72
  ProjectFeatureSelection,
67
73
  ProjectFormCustomSection,
74
+ ProjectFormGroup,
68
75
  ProjectFormSectionId,
69
76
  ProjectFormValue,
70
77
  ProjectRepo,
@@ -0,0 +1,47 @@
1
+ /**
2
+ * The `sidebar` layout's promise: the rail says what's required and what's missing, and a submit
3
+ * with a required section empty never reaches the app — it lands the user on the page to fix.
4
+ */
5
+ import { describe, it, expect, vi } from "vitest"
6
+ import { useState } from "react"
7
+ import { render, screen, fireEvent, within } from "@testing-library/react"
8
+ import { ProjectForm } from "./project-form"
9
+ import { emptyProjectFormValue, type ProjectFormValue } from "./types"
10
+
11
+ const IMAGES = [{ id: "node", label: "Node.js 24", image: "mcr.microsoft.com/devcontainers/typescript-node:24" }]
12
+
13
+ function Harness({ onSubmit }: { onSubmit: (v: ProjectFormValue) => void }) {
14
+ const [value, setValue] = useState<ProjectFormValue>(emptyProjectFormValue)
15
+ return <ProjectForm layout="sidebar" value={value} onChange={setValue} onSubmit={onSubmit} images={IMAGES} submitLabel="Create" />
16
+ }
17
+
18
+ const nav = () => within(document.querySelector('[data-slot="form-nav"]') as HTMLElement)
19
+ const navEntry = (title: string) => nav().getByRole("button", { name: new RegExp(`^${title}`) })
20
+
21
+ describe("ProjectForm layout=sidebar", () => {
22
+ it("names what's missing, refuses the submit, and jumps to the page holding it", () => {
23
+ const onSubmit = vi.fn()
24
+ render(<Harness onSubmit={onSubmit} />)
25
+
26
+ expect(navEntry("General").textContent).toContain("Missing: name, base image")
27
+ expect(navEntry("Tooling").textContent).toContain("Optional · nothing set")
28
+
29
+ fireEvent.click(navEntry("Secrets"))
30
+ expect(navEntry("Secrets").getAttribute("aria-current")).toBe("step")
31
+
32
+ fireEvent.click(screen.getAllByRole("button", { name: "Create" })[0])
33
+ expect(onSubmit).not.toHaveBeenCalled()
34
+ expect(navEntry("General").getAttribute("aria-current")).toBe("step")
35
+ expect(screen.getByText("Give the project a name.")).toBeTruthy()
36
+
37
+ fireEvent.change(screen.getByLabelText(/^Name/), { target: { value: "api" } })
38
+ fireEvent.click(screen.getByRole("button", { name: /Node\.js 24/ }))
39
+ expect(navEntry("General").textContent).not.toContain("Missing")
40
+ expect(navEntry("General").textContent).toContain("api")
41
+
42
+ fireEvent.click(screen.getAllByRole("button", { name: "Create" })[0])
43
+ expect(onSubmit).toHaveBeenCalledWith(
44
+ expect.objectContaining({ name: "api", image: "mcr.microsoft.com/devcontainers/typescript-node:24" })
45
+ )
46
+ })
47
+ })
@@ -1,7 +1,9 @@
1
1
  "use client"
2
2
 
3
- import { useState, type ComponentType, type ReactNode } from "react"
3
+ import { useRef, useState, type ComponentType, type ReactNode } from "react"
4
4
  import {
5
+ ArrowLeftIcon,
6
+ ArrowRightIcon,
5
7
  BlocksIcon,
6
8
  BoxIcon,
7
9
  GitBranchIcon,
@@ -14,6 +16,7 @@ import {
14
16
  } from "lucide-react"
15
17
 
16
18
  import { cn } from "../../utils"
19
+ import { Button } from "../button"
17
20
  import { Input } from "../input"
18
21
  import { Switch } from "../switch"
19
22
  import { Textarea } from "../textarea"
@@ -23,6 +26,8 @@ import { ImagePicker, type ImagePickerProps } from "./image-picker"
23
26
  import { AdvancedDisclosure, advancedSummary } from "./advanced-sections"
24
27
  import { BuildManifest, type ManifestRow } from "./build-manifest"
25
28
  import { Field, FormSection, type SectionAccent } from "./form-section"
29
+ import { FormNav, SectionStatusBadge, type FormNavItem } from "./form-nav"
30
+ import { isSectionRequired, sectionSummary } from "./section-status"
26
31
  import { RepoList, type GitProvider, type GitRepoOption, type RepoFieldRender } from "./repo-list"
27
32
  import { SecretList } from "./secret-list"
28
33
  import {
@@ -30,6 +35,7 @@ import {
30
35
  isInternalSectionId,
31
36
  type InternalSectionId,
32
37
  type ProjectFormCustomSection,
38
+ type ProjectFormGroup,
33
39
  type ProjectFormSectionId,
34
40
  type ProjectFormValue,
35
41
  type ProjectSecretRef,
@@ -69,6 +75,53 @@ const DEFAULT_ADVANCED: InternalSectionId[] = [
69
75
  "secrets",
70
76
  ]
71
77
 
78
+ /** What a missing required section is called in the nav — the field, not the card. */
79
+ const REQUIRED_LABEL: Partial<Record<ProjectFormSectionId, string>> = { identity: "Name", image: "Base image" }
80
+
81
+ /**
82
+ * The `sidebar` layout's pages. "General" is the three sections that decide what
83
+ * a worker *is* — the ones the stacked layout keeps out of its fold — and the
84
+ * rest is sorted by what it tunes. A group none of whose sections is shown is
85
+ * dropped, so the same list serves creation and editing.
86
+ */
87
+ export const DEFAULT_GROUPS: ProjectFormGroup[] = [
88
+ {
89
+ id: "general",
90
+ title: "General",
91
+ hint: "What the project is: its name, the image its workers boot, and the code they clone.",
92
+ icon: SquarePenIcon,
93
+ sections: ["identity", "image", "repositories"],
94
+ },
95
+ {
96
+ id: "tooling",
97
+ title: "Tooling",
98
+ hint: "What gets installed on top of the base image — devcontainer features and IDE extensions.",
99
+ icon: PuzzleIcon,
100
+ sections: ["features", "extensions"],
101
+ },
102
+ {
103
+ id: "lifecycle",
104
+ title: "Lifecycle",
105
+ hint: "Commands run when a worker is created, and every time it starts.",
106
+ icon: TerminalIcon,
107
+ sections: ["lifecycle"],
108
+ },
109
+ {
110
+ id: "runtime",
111
+ title: "Runtime",
112
+ hint: "How a running worker behaves: forwarded ports, preloaded images, Docker inside.",
113
+ icon: NetworkIcon,
114
+ sections: ["ports", "prewarm", "docker"],
115
+ },
116
+ {
117
+ id: "secrets",
118
+ title: "Secrets",
119
+ hint: "Environment variables injected into every workspace of the project.",
120
+ icon: KeyRoundIcon,
121
+ sections: ["secrets"],
122
+ },
123
+ ]
124
+
72
125
  export interface ProjectFormProps<TValue extends ProjectFormValue = ProjectFormValue> {
73
126
  /**
74
127
  * The complete value. Generic: an app whose project has a field the package
@@ -101,6 +154,22 @@ export interface ProjectFormProps<TValue extends ProjectFormValue = ProjectFormV
101
154
  /** Forces the initial state. Omitted → open iff an advanced section has a value. */
102
155
  defaultAdvancedOpen?: boolean
103
156
 
157
+ /**
158
+ * `stack` (default) — every section in one column, the tuning ones folded
159
+ * behind "Advanced options", the build manifest on the right.
160
+ *
161
+ * `sidebar` — a left rail of pages (`groups`), one page shown at a time, each
162
+ * entry marked required / filled / optional; the submit sits under the rail.
163
+ * The rail *is* the recap there, so `manifest` and `advancedSections` don't
164
+ * apply. Nothing is folded: a page you haven't opened still says what it holds.
165
+ */
166
+ layout?: "stack" | "sidebar"
167
+ /**
168
+ * Pages of the `sidebar` layout. Defaults to `DEFAULT_GROUPS`. A shown section
169
+ * that no group lists — a custom one, typically — gets a page of its own, after.
170
+ */
171
+ groups?: ProjectFormGroup[]
172
+
104
173
  /** Catalogs, already fetched by the app — the form never calls an API. */
105
174
  images?: DevcontainerImageEntry[]
106
175
  features?: DevcontainerFeatureEntry[]
@@ -190,6 +259,8 @@ export function ProjectForm<TValue extends ProjectFormValue = ProjectFormValue>(
190
259
  advancedLabel,
191
260
  advancedHint,
192
261
  defaultAdvancedOpen,
262
+ layout = "stack",
263
+ groups = DEFAULT_GROUPS,
193
264
  images = [],
194
265
  features = [],
195
266
  imagePicker,
@@ -240,6 +311,144 @@ export function ProjectForm<TValue extends ProjectFormValue = ProjectFormValue>(
240
311
  // user's cursor.
241
312
  const [advancedOpen, setAdvancedOpen] = useState(() => defaultAdvancedOpen ?? summary.length > 0)
242
313
 
314
+ // ── Sidebar layout state. Declared unconditionally (hooks), unused in `stack`.
315
+ const pages = sidebarPages(shown, groups, custom)
316
+ const [activePage, setActivePage] = useState(() => pages[0]?.id ?? "")
317
+ // Flips once a submit was refused, and stays: from then on an empty required
318
+ // field is an error, not a reminder.
319
+ const [showErrors, setShowErrors] = useState(false)
320
+ const contentRef = useRef<HTMLDivElement>(null)
321
+
322
+ if (layout === "sidebar") {
323
+ const customList = customSections ?? []
324
+ const filledOf = (id: ProjectFormSectionId) => sectionSummary(value, id, savedSecrets, customList)
325
+ const navItems: FormNavItem[] = pages.map((page) => {
326
+ const required = page.sections.filter((id) => isSectionRequired(id, customList))
327
+ return {
328
+ id: page.id,
329
+ title: page.title,
330
+ icon: page.icon,
331
+ required: required.length,
332
+ missing: required.filter((id) => !filledOf(id)).map((id) => REQUIRED_LABEL[id] ?? metaOf(id).title),
333
+ summary: page.sections.map(filledOf).filter((x): x is string => !!x),
334
+ }
335
+ })
336
+ const firstMissing = navItems.find((item) => item.missing.length)
337
+ const index = Math.max(0, pages.findIndex((p) => p.id === activePage))
338
+ const page = pages[index]
339
+ const prev = pages[index - 1]
340
+ const next = pages[index + 1]
341
+
342
+ const go = (id: string) => {
343
+ setActivePage(id)
344
+ // Only scroll when the page's top went out of view: switching from the
345
+ // rail mustn't jolt a form you're already looking at the top of.
346
+ const el = contentRef.current
347
+ if (el && el.getBoundingClientRect().top < 0) el.scrollIntoView({ behavior: "smooth", block: "start" })
348
+ }
349
+
350
+ const submitBlock = (
351
+ <div className="space-y-3 border-t pt-4">
352
+ {firstMissing && showErrors && (
353
+ <p className="text-xs text-destructive">
354
+ Fill in the required fields first — {navItems.flatMap((i) => i.missing).join(", ").toLowerCase()}.
355
+ </p>
356
+ )}
357
+ {error && (
358
+ <p className="rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-sm text-destructive">
359
+ {error}
360
+ </p>
361
+ )}
362
+ <Button type="submit" size="lg" disabled={submitting} className="group w-full">
363
+ {submitting ? (
364
+ <span className="flex items-center gap-2">
365
+ <span className="h-4 w-4 animate-spin rounded-full border-2 border-background/40 border-t-background" />
366
+ {submittingLabel}
367
+ </span>
368
+ ) : (
369
+ submitLabel
370
+ )}
371
+ </Button>
372
+ {manifestCaption && <p className="text-center text-[11px] text-muted-foreground">{manifestCaption}</p>}
373
+ {manifestFooter}
374
+ </div>
375
+ )
376
+
377
+ return (
378
+ <div className={cn("@container/form", className)}>
379
+ <form
380
+ data-slot="project-form"
381
+ data-layout="sidebar"
382
+ // Validation is ours: the browser's would stop at a required input on
383
+ // a page that isn't shown, and point at nothing.
384
+ noValidate
385
+ onSubmit={(e) => {
386
+ e.preventDefault()
387
+ if (firstMissing) {
388
+ setShowErrors(true)
389
+ go(firstMissing.id)
390
+ return
391
+ }
392
+ onSubmit?.(value)
393
+ }}
394
+ className="grid grid-cols-[minmax(0,1fr)] gap-6 @min-[48rem]/form:grid-cols-[15rem_minmax(0,1fr)] @min-[48rem]/form:items-start"
395
+ >
396
+ <aside className="min-w-0 @min-[48rem]/form:sticky @min-[48rem]/form:top-6">
397
+ <FormNav
398
+ items={navItems}
399
+ active={page?.id ?? ""}
400
+ onSelect={go}
401
+ showErrors={showErrors}
402
+ footer={<div className="hidden @min-[48rem]/form:block">{submitBlock}</div>}
403
+ />
404
+ </aside>
405
+
406
+ <div ref={contentRef} className="min-w-0 scroll-mt-6 space-y-4">
407
+ {pages.map((p) => (
408
+ // Every page stays mounted, the others `hidden`: pickers keep their
409
+ // own UI state (a search, a "custom image" toggle) across pages,
410
+ // and `display:none` takes their inputs out of the tab order.
411
+ <div key={p.id} hidden={p.id !== page?.id} className="space-y-4">
412
+ <header className="space-y-1">
413
+ <p className="font-mono text-[11px] tracking-wide text-muted-foreground uppercase">
414
+ Step {pages.indexOf(p) + 1} of {pages.length}
415
+ </p>
416
+ <h2 className="font-display text-2xl font-bold tracking-tight">{p.title}</h2>
417
+ {p.hint && <p className="text-sm text-muted-foreground">{p.hint}</p>}
418
+ </header>
419
+ {p.sections.map((id) => {
420
+ const required = isSectionRequired(id, customList)
421
+ return section(id, undefined, (
422
+ <SectionStatusBadge required={required} filled={!!filledOf(id)} error={showErrors} />
423
+ ))
424
+ })}
425
+ </div>
426
+ ))}
427
+
428
+ <div className="flex items-center justify-between gap-3 pt-2">
429
+ {prev ? (
430
+ <Button type="button" variant="ghost" onClick={() => go(prev.id)} className="gap-1.5">
431
+ <ArrowLeftIcon className="h-4 w-4" />
432
+ {prev.title}
433
+ </Button>
434
+ ) : (
435
+ <span />
436
+ )}
437
+ {next && (
438
+ <Button type="button" variant="outline" onClick={() => go(next.id)} className="gap-1.5">
439
+ Next: {next.title}
440
+ <ArrowRightIcon className="h-4 w-4" />
441
+ </Button>
442
+ )}
443
+ </div>
444
+
445
+ <div className="@min-[48rem]/form:hidden">{submitBlock}</div>
446
+ </div>
447
+ </form>
448
+ </div>
449
+ )
450
+ }
451
+
243
452
  return (
244
453
  // The container is this wrapper, not the form: a container query styles a
245
454
  // container's DESCENDANTS, never the element that declares it — put both on
@@ -297,18 +506,29 @@ export function ProjectForm<TValue extends ProjectFormValue = ProjectFormValue>(
297
506
  </div>
298
507
  )
299
508
 
300
- /** One section, numbered by its position in the whole form (folded or not). */
301
- function section(id: ProjectFormSectionId, index: number) {
509
+ /** Chrome of a section, built-in or the app's own. */
510
+ function metaOf(id: ProjectFormSectionId) {
302
511
  const own = custom.get(id)
303
512
  // A custom card is chrome-identical to a built-in one: same `FormSection`,
304
513
  // same badge, same accent — only its body comes from the app.
305
- const meta = own
514
+ return own
306
515
  ? { icon: own.icon, accent: own.accent, title: own.title, hint: own.hint }
307
516
  : SECTION_META[id as InternalSectionId]
517
+ }
518
+
519
+ /**
520
+ * One section, numbered by its position in the whole form (folded or not) —
521
+ * or unnumbered in the sidebar layout, where the page is the step and the
522
+ * badge says required / optional instead.
523
+ */
524
+ function section(id: ProjectFormSectionId, index: number | undefined, status?: ReactNode) {
525
+ const own = custom.get(id)
526
+ const meta = metaOf(id)
308
527
  return (
309
528
  <FormSection
310
529
  key={id}
311
- n={index + 1}
530
+ n={index == null ? undefined : index + 1}
531
+ status={status}
312
532
  icon={meta.icon}
313
533
  accent={meta.accent}
314
534
  title={meta.title}
@@ -316,7 +536,7 @@ export function ProjectForm<TValue extends ProjectFormValue = ProjectFormValue>(
316
536
  // The stagger is an inline delay rather than ten Tailwind variants;
317
537
  // capped, or a long form's last section would arrive noticeably after
318
538
  // you've already scrolled to it.
319
- style={{ animationDelay: `${Math.min(index, 8) * 40}ms` }}
539
+ style={{ animationDelay: `${Math.min(index ?? 0, 8) * 40}ms` }}
320
540
  >
321
541
  {own ? own.render(value, patchCustom) : renderSection(id as InternalSectionId)}
322
542
  {extras?.[id]}
@@ -329,12 +549,24 @@ export function ProjectForm<TValue extends ProjectFormValue = ProjectFormValue>(
329
549
  case "identity":
330
550
  return (
331
551
  <div className="space-y-4">
332
- <Field label="Name" htmlFor="project-name">
552
+ <Field
553
+ label={
554
+ <>
555
+ Name
556
+ <span aria-hidden className="text-destructive">
557
+ *
558
+ </span>
559
+ </>
560
+ }
561
+ htmlFor="project-name"
562
+ error={showErrors && !value.name.trim() ? "Give the project a name." : undefined}
563
+ >
333
564
  <Input
334
565
  id="project-name"
335
566
  name="name"
336
567
  placeholder="my-project"
337
568
  required
569
+ aria-invalid={showErrors && !value.name.trim() ? true : undefined}
338
570
  value={value.name}
339
571
  onChange={(e) => patch({ name: e.target.value })}
340
572
  />
@@ -354,13 +586,18 @@ export function ProjectForm<TValue extends ProjectFormValue = ProjectFormValue>(
354
586
 
355
587
  case "image":
356
588
  return (
357
- <ImagePicker
358
- images={images}
359
- value={value.image}
360
- onChange={(image) => patch({ image })}
361
- layout={imagePicker?.layout}
362
- detail={imagePicker?.detail}
363
- />
589
+ <>
590
+ <ImagePicker
591
+ images={images}
592
+ value={value.image}
593
+ onChange={(image) => patch({ image })}
594
+ layout={imagePicker?.layout}
595
+ detail={imagePicker?.detail}
596
+ />
597
+ {showErrors && !value.image && (
598
+ <p className="mt-3 text-xs text-destructive">Pick a base image, or type the reference of your own.</p>
599
+ )}
600
+ </>
364
601
  )
365
602
 
366
603
  case "repositories":
@@ -488,6 +725,32 @@ export function ProjectForm<TValue extends ProjectFormValue = ProjectFormValue>(
488
725
  }
489
726
  }
490
727
 
728
+ /**
729
+ * The sidebar's pages: the declared groups, narrowed to the sections actually
730
+ * shown (an empty group is dropped), then one page per shown section no group
731
+ * listed — so a custom section can't silently vanish for want of a group.
732
+ */
733
+ function sidebarPages<TValue extends ProjectFormValue>(
734
+ shown: ProjectFormSectionId[],
735
+ groups: ProjectFormGroup[],
736
+ custom: Map<string, ProjectFormCustomSection<TValue>>
737
+ ): ProjectFormGroup[] {
738
+ const placed = new Set<ProjectFormSectionId>()
739
+ const pages: ProjectFormGroup[] = []
740
+ for (const group of groups) {
741
+ const sections = group.sections.filter((id) => shown.includes(id) && !placed.has(id))
742
+ sections.forEach((id) => placed.add(id))
743
+ if (sections.length) pages.push({ ...group, sections })
744
+ }
745
+ for (const id of shown) {
746
+ if (placed.has(id)) continue
747
+ const own = custom.get(id)
748
+ const meta = own ?? SECTION_META[id as InternalSectionId]
749
+ pages.push({ id, title: meta.title, hint: meta.hint, icon: meta.icon, sections: [id] })
750
+ }
751
+ return pages
752
+ }
753
+
491
754
  /** `"3000, 8080, "` → `[3000, 8080]`. Anything that isn't a number is dropped. */
492
755
  function parsePorts(raw: string): number[] {
493
756
  return raw
@@ -0,0 +1,67 @@
1
+ // What a section holds, read off the value — never stored.
2
+ //
3
+ // One place for the question "is this section filled in, and how would you say
4
+ // it in three words?", because three surfaces ask it: the closed fold's summary
5
+ // (`advancedSummary`), and the `sidebar` layout's nav and section badges. They
6
+ // used to be one `switch` inside the fold; the sidebar needed the same answer
7
+ // for the sections the fold never held (a name, an image, repos).
8
+
9
+ import {
10
+ REQUIRED_SECTIONS,
11
+ isInternalSectionId,
12
+ type ProjectFormCustomSection,
13
+ type ProjectFormSectionId,
14
+ type ProjectFormValue,
15
+ type ProjectSecretRef,
16
+ } from "./types"
17
+
18
+ const plural = (n: number, word: string) => `${n} ${word}${n === 1 ? "" : "s"}`
19
+
20
+ /**
21
+ * A short label — `my-project`, `2 features`, `lifecycle` — when the section
22
+ * holds something, `null` when it's empty. A custom section answers through its
23
+ * own `summary`; one without it reads as always empty.
24
+ */
25
+ export function sectionSummary<TValue extends ProjectFormValue>(
26
+ value: TValue,
27
+ id: ProjectFormSectionId,
28
+ /** Saved secrets count like drafts — an existing secret is still a secret. */
29
+ savedSecrets: ProjectSecretRef[] = [],
30
+ customSections: ProjectFormCustomSection<TValue>[] = []
31
+ ): string | null {
32
+ if (!isInternalSectionId(id)) return customSections.find((s) => s.id === id)?.summary?.(value) ?? null
33
+ switch (id) {
34
+ case "identity":
35
+ return value.name.trim() || null
36
+ case "image":
37
+ return value.image ? (value.image.split("/").pop() ?? value.image) : null
38
+ case "repositories":
39
+ return value.repositories.length ? plural(value.repositories.length, "repo") : null
40
+ case "features":
41
+ return value.features.length ? plural(value.features.length, "feature") : null
42
+ case "extensions":
43
+ return value.vscodeExtensions.length ? plural(value.vscodeExtensions.length, "extension") : null
44
+ case "lifecycle":
45
+ return value.postCreateCommand || value.postStartCommand ? "lifecycle" : null
46
+ case "ports":
47
+ return value.forwardPorts.length ? `ports ${value.forwardPorts.join(", ")}` : null
48
+ case "prewarm":
49
+ return value.prewarmImages.length ? `${value.prewarmImages.length} prewarm` : null
50
+ case "docker":
51
+ return value.dockerInDocker ? "docker-in-docker" : null
52
+ case "secrets": {
53
+ const n = value.secrets.length + savedSecrets.filter((x) => !value.removedSecretIds.includes(x.id)).length
54
+ return n ? plural(n, "secret") : null
55
+ }
56
+ }
57
+ }
58
+
59
+ /** Required = in `REQUIRED_SECTIONS`, or a custom section that says so. */
60
+ export function isSectionRequired<TValue extends ProjectFormValue>(
61
+ id: ProjectFormSectionId,
62
+ customSections: ProjectFormCustomSection<TValue>[] = []
63
+ ): boolean {
64
+ return isInternalSectionId(id)
65
+ ? REQUIRED_SECTIONS.includes(id)
66
+ : !!customSections.find((s) => s.id === id)?.required
67
+ }
@@ -161,6 +161,26 @@ export interface ProjectFormCustomSection<TValue extends ProjectFormValue = Proj
161
161
  summary?: (value: TValue) => string | null
162
162
  /** A line in the build manifest, or `null`. Appended after the built-in rows. */
163
163
  manifestRow?: (value: TValue) => ManifestRow | null
164
+ /**
165
+ * Marks the section as required in the `sidebar` layout: flagged in the nav,
166
+ * counted in the progress, and blocking submit while `summary` returns `null`
167
+ * — "filled" for a custom section *is* having a summary, so a required one
168
+ * without `summary` can never be satisfied.
169
+ */
170
+ required?: boolean
171
+ }
172
+
173
+ /**
174
+ * One entry of the `sidebar` layout's navigation: a page of the form holding one
175
+ * or more sections. Sections not placed in any group get a page of their own,
176
+ * after the declared ones — a custom section is never lost for want of a group.
177
+ */
178
+ export interface ProjectFormGroup {
179
+ id: string
180
+ title: string
181
+ hint?: string
182
+ icon?: ComponentType<{ className?: string }>
183
+ sections: ProjectFormSectionId[]
164
184
  }
165
185
 
166
186
  /** Internal ids, as a runtime set — what tells a custom id from a built-in one. */
@@ -207,6 +227,12 @@ export const EDIT_SECTIONS: ProjectFormSectionId[] = [
207
227
  "secrets",
208
228
  ]
209
229
 
230
+ /**
231
+ * What the API refuses to create a project without: a name and a base image.
232
+ * Everything else has a working default — no repo is a valid (empty) workspace.
233
+ */
234
+ export const REQUIRED_SECTIONS: InternalSectionId[] = ["identity", "image"]
235
+
210
236
  /** An empty, complete value — the starting point of a creation form. */
211
237
  export function emptyProjectFormValue(): ProjectFormValue {
212
238
  return {
@@ -53,12 +53,15 @@ export interface NewTaskComposerProps {
53
53
  /** The project's default model — what the chip says when nobody picked one. */
54
54
  defaultModel?: string | null
55
55
  /**
56
- * The app's own fields, drawn as chips after the package's: `render` should draw a compact
57
- * control (`newTaskChipClassName`); `label` and `hint` become its tooltip.
56
+ * The app's own fields, drawn as chips after the package's — or before them, with
57
+ * `placement: "lead"`: `render` should draw a compact control (`newTaskChipClassName`); `label`
58
+ * and `hint` become its tooltip.
58
59
  */
59
60
  fields?: NewTaskCustomField[]
60
61
  /** Every pick of an app field, as it happens — for fields whose options depend on another one. */
61
62
  onFieldChange?: (id: string, value: unknown) => void
63
+ /** The model as it is typed or picked ("" = none) — for fields whose options depend on it. */
64
+ onModelChange?: (model: string) => void
62
65
  /**
63
66
  * What this member delegated with last time in this project: the branch and model chips start
64
67
  * on it, over the defaults. Applied again — and the app fields' picks dropped, so their
@@ -227,6 +230,7 @@ export function NewTaskComposer({
227
230
  defaultModel = null,
228
231
  fields = [],
229
232
  onFieldChange,
233
+ onModelChange,
230
234
  remembered,
231
235
  draftKey,
232
236
  onSubmit,
@@ -372,6 +376,22 @@ export function NewTaskComposer({
372
376
  />
373
377
  )}
374
378
 
379
+ {/* Fields the package's chips depend on — the harness, before the model it lists. */}
380
+ {fields.filter((f) => f.placement === "lead").map((f) => (
381
+ <span
382
+ key={f.id}
383
+ className="inline-flex"
384
+ data-slot="new-task-field"
385
+ data-field={f.id}
386
+ title={[f.label, typeof f.hint === "string" ? f.hint : null].filter(Boolean).join(" — ")}
387
+ >
388
+ {f.render(fieldValue(f), (v) => {
389
+ setPicked((prev) => ({ ...prev, [f.id]: v }))
390
+ onFieldChange?.(f.id, v)
391
+ })}
392
+ </span>
393
+ ))}
394
+
375
395
  <FreeTextChip
376
396
  label="Base branch"
377
397
  icon={<GitBranchIcon />}
@@ -386,14 +406,17 @@ export function NewTaskComposer({
386
406
  label="Model"
387
407
  icon={<PackageIcon />}
388
408
  value={model}
389
- onChange={setModel}
409
+ onChange={(next) => {
410
+ setModel(next)
411
+ onModelChange?.(next)
412
+ }}
390
413
  placeholder={defaultModel ?? "harness default"}
391
414
  groups={modelGroups.map((g) => ({ id: g.id, heading: g.label, items: g.models.map((m) => ({ value: m.value, label: m.label, meta: m.label })) }))}
392
415
  searchPlaceholder="Any model id your harness understands"
393
416
  mono
394
417
  />
395
418
 
396
- {fields.map((f) => (
419
+ {fields.filter((f) => f.placement !== "lead").map((f) => (
397
420
  <span
398
421
  key={f.id}
399
422
  className="inline-flex"
@@ -70,6 +70,12 @@ export interface NewTaskCustomField {
70
70
  defaultValue?: unknown
71
71
  /** Delegate stays disabled while it has no value (`undefined`, `null` or `""`). */
72
72
  required?: boolean
73
+ /**
74
+ * Where the composer draws it: `lead` before the package's own chips (base branch, model) — for
75
+ * a field they depend on, like the harness whose models the model chip lists — `trail` (the
76
+ * default) after them. The dialog ignores it: its fields come after the package's.
77
+ */
78
+ placement?: "lead" | "trail"
73
79
  render: (value: unknown, onChange: (value: unknown) => void) => ReactNode
74
80
  }
75
81
 
@@ -539,6 +539,20 @@ describe("NewTaskComposer — delegating where the conversation will be", () =>
539
539
  expect(onSubmit.mock.calls[0]![0]).toEqual({ prompt: "Fix the login on Safari", files: [] })
540
540
  })
541
541
 
542
+ it("draws a lead field before the package's chips — the harness before the model it lists", () => {
543
+ const onSubmit = vi.fn()
544
+ const harness = machine({ id: "harness", label: "Harness", defaultValue: "claude", placement: "lead" })
545
+ render(<NewTaskComposer defaultModel="claude-opus-5" fields={[machine(), harness]} onSubmit={onSubmit} />)
546
+ const order = [...document.querySelectorAll("[data-field], [aria-label='Model'], [aria-label='Base branch']")].map(
547
+ (el) => el.getAttribute("data-field") ?? el.getAttribute("aria-label"),
548
+ )
549
+ expect(order.indexOf("harness")).toBeLessThan(order.indexOf("Base branch") === -1 ? order.length : order.indexOf("Base branch"))
550
+ expect(order.indexOf("harness")).toBeLessThan(order.indexOf("machine"))
551
+ fireEvent.change(prompt(), { target: { value: "Fix it" } })
552
+ fireEvent.keyDown(prompt(), { key: "Enter" })
553
+ expect(onSubmit.mock.calls[0]![0].fields).toEqual({ machine: "worker", harness: "claude" })
554
+ })
555
+
542
556
  it("org-wide, Delegate waits for a project and says so", () => {
543
557
  const onSubmit = vi.fn()
544
558
  render(<NewTaskComposer projects={[{ id: "p1", name: "spunto" }]} onSubmit={onSubmit} />)