@spunto/design-system 0.77.0 → 0.79.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/package.json +1 -1
- package/src/components/projects/lifecycle-commands.tsx +7 -4
- package/src/components/projects/panel-types.ts +1 -0
- package/src/components/projects/project-form-lifecycle.test.tsx +40 -0
- package/src/components/projects/project-form.tsx +14 -2
- package/src/components/projects/project-panel.tsx +2 -1
- package/src/components/projects/section-status.ts +1 -1
- package/src/components/projects/types.ts +5 -0
- package/src/components/tasks/task-details.tsx +12 -3
- package/src/components/tasks/tasks.test.tsx +20 -0
- package/src/components/tasks/types.ts +2 -0
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// devcontainer lifecycle commands — `postCreate` / `postStart`.
|
|
1
|
+
// devcontainer lifecycle commands — `postCreate` / `postStart` — and Spunto's `postSnapshot`.
|
|
2
2
|
//
|
|
3
3
|
// Generalised from Lite's local `LifecycleRow`; the dashboard wrote the same
|
|
4
4
|
// block out twice by hand.
|
|
@@ -34,17 +34,20 @@ export function LifecycleCommand({ label, command, className }: LifecycleCommand
|
|
|
34
34
|
export interface LifecycleCommandsProps {
|
|
35
35
|
postCreateCommand?: string | null
|
|
36
36
|
postStartCommand?: string | null
|
|
37
|
+
/** Run once in a sandbox started from a snapshot. */
|
|
38
|
+
postSnapshotCommand?: string | null
|
|
37
39
|
className?: string
|
|
38
40
|
}
|
|
39
41
|
|
|
40
|
-
/**
|
|
41
|
-
export function LifecycleCommands({ postCreateCommand, postStartCommand, className }: LifecycleCommandsProps) {
|
|
42
|
-
if (!postCreateCommand && !postStartCommand) return null
|
|
42
|
+
/** The lifecycle blocks, each rendered only when the project defines it. */
|
|
43
|
+
export function LifecycleCommands({ postCreateCommand, postStartCommand, postSnapshotCommand, className }: LifecycleCommandsProps) {
|
|
44
|
+
if (!postCreateCommand && !postStartCommand && !postSnapshotCommand) return null
|
|
43
45
|
|
|
44
46
|
return (
|
|
45
47
|
<div data-slot="lifecycle-commands" className={cn("space-y-1.5", className)}>
|
|
46
48
|
{postCreateCommand && <LifecycleCommand label="postCreate" command={postCreateCommand} />}
|
|
47
49
|
{postStartCommand && <LifecycleCommand label="postStart" command={postStartCommand} />}
|
|
50
|
+
{postSnapshotCommand && <LifecycleCommand label="postSnapshot" command={postSnapshotCommand} />}
|
|
48
51
|
</div>
|
|
49
52
|
)
|
|
50
53
|
}
|
|
@@ -47,6 +47,7 @@ export interface ProjectPanelProject {
|
|
|
47
47
|
forwardPorts?: (number | string)[]
|
|
48
48
|
postCreateCommand?: string | null
|
|
49
49
|
postStartCommand?: string | null
|
|
50
|
+
postSnapshotCommand?: string | null
|
|
50
51
|
/** Public half of the project's SSH deploy key (RFC 0013). */
|
|
51
52
|
deployPublicKey?: string | null
|
|
52
53
|
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The lifecycle section's third command, `postSnapshotCommand`, is Spunto's own: offered only to an
|
|
3
|
+
* app whose value holds it (`""` included), so a form without it (Lite) does not show a field it
|
|
4
|
+
* has nowhere to save.
|
|
5
|
+
*/
|
|
6
|
+
import { describe, it, expect } from "vitest"
|
|
7
|
+
import { useState } from "react"
|
|
8
|
+
import { render, screen, fireEvent } from "@testing-library/react"
|
|
9
|
+
import { ProjectForm } from "./project-form"
|
|
10
|
+
import { emptyProjectFormValue, type ProjectFormValue } from "./types"
|
|
11
|
+
|
|
12
|
+
function Harness({ initial, onValue }: { initial: ProjectFormValue; onValue?: (v: ProjectFormValue) => void }) {
|
|
13
|
+
const [value, setValue] = useState(initial)
|
|
14
|
+
return (
|
|
15
|
+
<ProjectForm
|
|
16
|
+
value={value}
|
|
17
|
+
onChange={(v) => {
|
|
18
|
+
setValue(v)
|
|
19
|
+
onValue?.(v)
|
|
20
|
+
}}
|
|
21
|
+
sections={["lifecycle"]}
|
|
22
|
+
defaultAdvancedOpen
|
|
23
|
+
/>
|
|
24
|
+
)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
describe("ProjectForm — lifecycle commands", () => {
|
|
28
|
+
it("offers no post-snapshot command to a value without one", () => {
|
|
29
|
+
render(<Harness initial={emptyProjectFormValue()} />)
|
|
30
|
+
expect(screen.getByLabelText(/Post-start command/)).toBeTruthy()
|
|
31
|
+
expect(screen.queryByLabelText(/Post-snapshot command/)).toBeNull()
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
it("offers it, and edits it, when the value holds one", () => {
|
|
35
|
+
let last: ProjectFormValue | null = null
|
|
36
|
+
render(<Harness initial={{ ...emptyProjectFormValue(), postSnapshotCommand: "" }} onValue={(v) => (last = v)} />)
|
|
37
|
+
fireEvent.change(screen.getByLabelText(/Post-snapshot command/), { target: { value: "./catch-up.sh" } })
|
|
38
|
+
expect(last!.postSnapshotCommand).toBe("./catch-up.sh")
|
|
39
|
+
})
|
|
40
|
+
})
|
|
@@ -656,6 +656,18 @@ export function ProjectForm<TValue extends ProjectFormValue = ProjectFormValue>(
|
|
|
656
656
|
onChange={(e) => patch({ postStartCommand: e.target.value })}
|
|
657
657
|
/>
|
|
658
658
|
</Field>
|
|
659
|
+
{value.postSnapshotCommand !== undefined && (
|
|
660
|
+
<Field label="Post-snapshot command" htmlFor="post-snapshot" hint="Runs once in a sandbox started from a snapshot, after it fetched">
|
|
661
|
+
<Input
|
|
662
|
+
id="post-snapshot"
|
|
663
|
+
name="postSnapshotCommand"
|
|
664
|
+
placeholder="./catch-up.sh"
|
|
665
|
+
className="font-mono text-xs"
|
|
666
|
+
value={value.postSnapshotCommand}
|
|
667
|
+
onChange={(e) => patch({ postSnapshotCommand: e.target.value })}
|
|
668
|
+
/>
|
|
669
|
+
</Field>
|
|
670
|
+
)}
|
|
659
671
|
</div>
|
|
660
672
|
)
|
|
661
673
|
|
|
@@ -781,9 +793,9 @@ export function manifestRows<TValue extends ProjectFormValue>(
|
|
|
781
793
|
rows.push({
|
|
782
794
|
label: "lifecycle",
|
|
783
795
|
value:
|
|
784
|
-
[value.postCreateCommand && "create", value.postStartCommand && "start"].filter(Boolean).join(" + ") ||
|
|
796
|
+
[value.postCreateCommand && "create", value.postStartCommand && "start", value.postSnapshotCommand && "snapshot"].filter(Boolean).join(" + ") ||
|
|
785
797
|
"default",
|
|
786
|
-
done: !!(value.postCreateCommand || value.postStartCommand),
|
|
798
|
+
done: !!(value.postCreateCommand || value.postStartCommand || value.postSnapshotCommand),
|
|
787
799
|
})
|
|
788
800
|
if (shown.has("ports"))
|
|
789
801
|
rows.push({ label: "ports", value: value.forwardPorts.join(", ") || "—", done: value.forwardPorts.length > 0 })
|
|
@@ -264,11 +264,12 @@ export function ProjectPanel({
|
|
|
264
264
|
</PanelSection>
|
|
265
265
|
)}
|
|
266
266
|
|
|
267
|
-
{(project.postCreateCommand || project.postStartCommand) && (
|
|
267
|
+
{(project.postCreateCommand || project.postStartCommand || project.postSnapshotCommand) && (
|
|
268
268
|
<PanelSection title="Lifecycle">
|
|
269
269
|
<LifecycleCommands
|
|
270
270
|
postCreateCommand={project.postCreateCommand}
|
|
271
271
|
postStartCommand={project.postStartCommand}
|
|
272
|
+
postSnapshotCommand={project.postSnapshotCommand}
|
|
272
273
|
/>
|
|
273
274
|
</PanelSection>
|
|
274
275
|
)}
|
|
@@ -42,7 +42,7 @@ export function sectionSummary<TValue extends ProjectFormValue>(
|
|
|
42
42
|
case "extensions":
|
|
43
43
|
return value.vscodeExtensions.length ? plural(value.vscodeExtensions.length, "extension") : null
|
|
44
44
|
case "lifecycle":
|
|
45
|
-
return value.postCreateCommand || value.postStartCommand ? "lifecycle" : null
|
|
45
|
+
return value.postCreateCommand || value.postStartCommand || value.postSnapshotCommand ? "lifecycle" : null
|
|
46
46
|
case "ports":
|
|
47
47
|
return value.forwardPorts.length ? `ports ${value.forwardPorts.join(", ")}` : null
|
|
48
48
|
case "prewarm":
|
|
@@ -94,6 +94,11 @@ export interface ProjectFormValue {
|
|
|
94
94
|
vscodeExtensions: string[]
|
|
95
95
|
postCreateCommand: string
|
|
96
96
|
postStartCommand: string
|
|
97
|
+
/**
|
|
98
|
+
* Run once in a sandbox started from a snapshot (Spunto's own, not devcontainer's). The field is
|
|
99
|
+
* offered only to an app that has it: present in its value — `""` included — not `undefined`.
|
|
100
|
+
*/
|
|
101
|
+
postSnapshotCommand?: string
|
|
97
102
|
/** Secrets typed in this session. */
|
|
98
103
|
secrets: ProjectSecretDraft[]
|
|
99
104
|
/** Ids of already-saved secrets the user asked to remove. */
|
|
@@ -228,6 +228,11 @@ function CustomizeLink({ tile, href }: { tile: TaskAppTile; href?: (tile: TaskAp
|
|
|
228
228
|
)
|
|
229
229
|
}
|
|
230
230
|
|
|
231
|
+
/** Anything to draw in a block — a tile with only `links` has none: its links go to the header. */
|
|
232
|
+
function hasBody(tile: TaskAppTile): boolean {
|
|
233
|
+
return !!(tile.meters?.length || tile.facts?.length || tile.items?.length || tile.lists?.length)
|
|
234
|
+
}
|
|
235
|
+
|
|
231
236
|
export function TaskDetails({
|
|
232
237
|
task,
|
|
233
238
|
variant = "sidebar",
|
|
@@ -248,7 +253,11 @@ export function TaskDetails({
|
|
|
248
253
|
}: TaskDetailsProps) {
|
|
249
254
|
const sheet = useContext(TaskDetailsSheetContext)
|
|
250
255
|
const meta = task.meta && Object.keys(task.meta).length > 0 ? task.meta : null
|
|
251
|
-
|
|
256
|
+
// The task's own links, then those its org's apps add (Spunto IDE: « Open IDE »), once each.
|
|
257
|
+
const allLinks = [...(task.links ?? []), ...(appTiles ?? []).flatMap((tile) => tile.links ?? [])].filter(
|
|
258
|
+
(link, i, list) => list.findIndex((l) => l.url === link.url) === i,
|
|
259
|
+
)
|
|
260
|
+
const links = allLinks.length > 0 ? allLinks : null
|
|
252
261
|
const metadata = task.metadata && Object.keys(task.metadata).length > 0 ? Object.entries(task.metadata) : null
|
|
253
262
|
const ran = task.completedAt ? taskSpan(task.startedAt ?? task.createdAt, task.completedAt) : null
|
|
254
263
|
// `baseBranch: null` is the project's default — saying so ("project default") on every task of a
|
|
@@ -360,7 +369,7 @@ export function TaskDetails({
|
|
|
360
369
|
|
|
361
370
|
{/* What only the harness knows about its session (its quota, its MCP servers, its skills…),
|
|
362
371
|
from the task's agent app — Session's numbers stay ours, the same for every harness. */}
|
|
363
|
-
{appTiles?.filter((tile) => tile.session).map((tile) => (
|
|
372
|
+
{appTiles?.filter((tile) => tile.session && hasBody(tile)).map((tile) => (
|
|
364
373
|
<Block key={tile.appId} id={`app:${tile.appId}`} variant={variant} title={tile.title} hint={tile.appName === tile.title ? undefined : tile.appName}>
|
|
365
374
|
<TaskAppTileContent tile={tile} onAction={onAppTileAction && ((item, action) => onAppTileAction(tile, item, action))} />
|
|
366
375
|
<CustomizeLink tile={tile} href={appTileSettingsHref} />
|
|
@@ -369,7 +378,7 @@ export function TaskDetails({
|
|
|
369
378
|
|
|
370
379
|
{/* What the org's apps make of the links the conversation shared — GitHub: the pull requests
|
|
371
380
|
it talked about, with where each one stands. */}
|
|
372
|
-
{appTiles?.filter((tile) => !tile.session).map((tile) => (
|
|
381
|
+
{appTiles?.filter((tile) => !tile.session && hasBody(tile)).map((tile) => (
|
|
373
382
|
<Block key={tile.appId} id={`app:${tile.appId}`} variant={variant} title={tile.title} hint={tile.appName === tile.title ? undefined : tile.appName}>
|
|
374
383
|
<TaskAppTileContent tile={tile} onAction={onAppTileAction && ((item, action) => onAppTileAction(tile, item, action))} />
|
|
375
384
|
<CustomizeLink tile={tile} href={appTileSettingsHref} />
|
|
@@ -548,6 +548,26 @@ describe("TaskDetails", () => {
|
|
|
548
548
|
expect(screen.queryByText("Fix the login")).toBeNull()
|
|
549
549
|
})
|
|
550
550
|
|
|
551
|
+
it("adds the links an app gives to the task's own, and draws no block for an app with nothing else", () => {
|
|
552
|
+
window.localStorage.clear()
|
|
553
|
+
const { container } = render(
|
|
554
|
+
<TaskDetails
|
|
555
|
+
task={task({ links: [{ label: "BAC-78", url: "https://cms.test/BAC-78" }] })}
|
|
556
|
+
appTiles={[
|
|
557
|
+
{ appId: "github", appName: "GitHub", title: "Pull requests", items: [{ title: "github row" }] },
|
|
558
|
+
{ appId: "ide", appName: "Spunto IDE", title: "IDE", links: [{ url: "https://sbx-a-code.test/", label: "Open IDE" }] },
|
|
559
|
+
]}
|
|
560
|
+
commands={[]}
|
|
561
|
+
/>,
|
|
562
|
+
)
|
|
563
|
+
expect(screen.getByText("Links")).toBeTruthy()
|
|
564
|
+
expect(screen.getByText("BAC-78").closest("a")?.getAttribute("href")).toBe("https://cms.test/BAC-78")
|
|
565
|
+
expect(screen.getByText("Open IDE").closest("a")?.getAttribute("href")).toBe("https://sbx-a-code.test/")
|
|
566
|
+
const blocks = [...container.querySelectorAll("[data-block]")].map((el) => el.getAttribute("data-block"))
|
|
567
|
+
expect(blocks).not.toContain("app:ide")
|
|
568
|
+
expect(blocks).toContain("app:github")
|
|
569
|
+
})
|
|
570
|
+
|
|
551
571
|
it("remembers a block the reader opened, in every conversation", () => {
|
|
552
572
|
window.localStorage.clear()
|
|
553
573
|
const first = render(<TaskDetails task={task({ id: "t1", prompt: "First prompt" })} commands={[]} />)
|
|
@@ -309,6 +309,8 @@ export interface TaskAppTile {
|
|
|
309
309
|
facts?: TaskAppTileFact[]
|
|
310
310
|
items?: TaskAppTileItem[]
|
|
311
311
|
lists?: TaskAppTileList[]
|
|
312
|
+
/** Links the app adds to the task's own « Links », in the header — not drawn in its block (Spunto IDE: « Open IDE »). */
|
|
313
|
+
links?: TaskLink[]
|
|
312
314
|
}
|
|
313
315
|
|
|
314
316
|
// ── Machine ──────────────────────────────────────────────────────────────────────────────────
|