Skip to content

Commit e3f5442

Browse files
authored
feat(flows): publish the generated Software Garden as a pinned artifact (1/2 for #174) (#175)
* feat(flows): publish the generated Software Garden as a pinned artifact The /flows generator is the single source of Software Garden (agentrelay.com#174, option a). Publish its output as web/public/flows/software-garden/v1.flow.ts with a manifest that pins version, sha256, size, path, url and the draft that produced it. The published variant is the catalog's: GitHub issues, Claude Code as builder and reviewer (the entry's default and only allowed agent), Traditional, no extra instructions. Tests prove the file is byte-identical to what /flows hands Cloud for that selection, that it matches the catalog's default agents and trigger, and that a generator change fails until it is published as a new version by scripts/publish-software-garden.mts. Published versions are immutable. public/ is excluded from tsc: the artifact imports @relayflows/surface, which this app does not install. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Session-Id: eae07e25-3482-4ffc-9475-760e93b49aeb * fix(flows): make Software Garden publishing retry-safe and complete - Refuse to publish while a recorded version is missing or edited. - Reuse a version file left by an interrupted publish only when it holds the generated bytes. - Rewrite the manifest when the bytes are unchanged, so a draft change the source does not serialize is still recorded. - Allow a digest to recur: output that returns to earlier bytes is a new version. - Typecheck .mts so the publish script is covered by tsc. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Session-Id: eae07e25-3482-4ffc-9475-760e93b49aeb * fix(flows): write Software Garden manifest and versions atomically Stage each write beside its target and rename it over, so an interrupted publish cannot leave a truncated manifest that blocks retry. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Session-Id: eae07e25-3482-4ffc-9475-760e93b49aeb
1 parent 0a65e8e commit e3f5442

6 files changed

Lines changed: 573 additions & 2 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { factorySource, type FactoryDraft } from './flow-onboarding';
2+
3+
/**
4+
* Software Garden has one source: the /flows generator. Every surface that
5+
* deploys it (the /flows handoff, Cloud's prebuilt-flow wizard, the dashboard's
6+
* recommended flows and ?flow= links) deploys the same bytes, published under
7+
* public/ as a versioned, sha256-pinned file (agentrelay.com#174).
8+
*
9+
* The generator's output depends on the selection, so this is the selection
10+
* the recommended-flow catalog deploys: GitHub issues, Claude Code as builder
11+
* and reviewer (the entry's default and only allowed agent), the Traditional
12+
* workflow, and no extra instructions. Repository and label filters are not
13+
* part of it: Cloud's listener applies them, and they do not change the source.
14+
*/
15+
export const SOFTWARE_GARDEN_DRAFT: FactoryDraft = {
16+
version: 4,
17+
sources: ['github'],
18+
sourceSettings: {},
19+
agents: ['claude'],
20+
otherAgent: '',
21+
task: '',
22+
workflow: 'traditional',
23+
step: 3,
24+
};
25+
26+
export const SOFTWARE_GARDEN_ARTIFACT_DIR = 'public/flows/software-garden';
27+
28+
/** Relative to web/. */
29+
export function softwareGardenArtifactPath(version: number): string {
30+
return `${SOFTWARE_GARDEN_ARTIFACT_DIR}/v${version}.flow.ts`;
31+
}
32+
33+
export function softwareGardenArtifactUrl(version: number): string {
34+
return `https://agentrelay.com/flows/software-garden/v${version}.flow.ts`;
35+
}
36+
37+
export function softwareGardenSource(): string {
38+
return factorySource(SOFTWARE_GARDEN_DRAFT, 'cloud');
39+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import { describe, expect, it } from 'vitest';
2+
import { createHash } from 'node:crypto';
3+
import { existsSync, readFileSync } from 'node:fs';
4+
import path from 'node:path';
5+
import catalog from '../../data/recommended-flow-catalog.v1.json';
6+
import { cloudConnectionsHref, DEFAULT_FACTORY, type FactoryDraft } from '../flow-onboarding';
7+
import {
8+
SOFTWARE_GARDEN_ARTIFACT_DIR,
9+
SOFTWARE_GARDEN_DRAFT,
10+
softwareGardenArtifactPath,
11+
softwareGardenArtifactUrl,
12+
softwareGardenSource,
13+
} from '../software-garden-artifact';
14+
15+
const web = path.resolve(__dirname, '../..');
16+
const manifestPath = path.join(web, SOFTWARE_GARDEN_ARTIFACT_DIR, 'manifest.json');
17+
const sha256 = (bytes: Buffer | string) => createHash('sha256').update(bytes).digest('hex');
18+
const REGENERATE = 'The generator output changed. Publish it as a new version: cd web && npx -y tsx@4 scripts/publish-software-garden.mts';
19+
20+
type Manifest = {
21+
name: string;
22+
catalogId: string;
23+
version: number;
24+
sha256: string;
25+
bytes: number;
26+
path: string;
27+
url: string;
28+
target: 'cloud';
29+
draft: FactoryDraft;
30+
versions: Array<{ version: number; sha256: string }>;
31+
};
32+
33+
const manifest = (): Manifest => JSON.parse(readFileSync(manifestPath, 'utf8'));
34+
const artifact = (version: number) => readFileSync(path.join(web, softwareGardenArtifactPath(version)));
35+
36+
describe('published Software Garden artifact', () => {
37+
it('is byte-identical to what the generator produces today', () => {
38+
const current = manifest();
39+
expect(artifact(current.version).toString('utf8'), REGENERATE).toBe(softwareGardenSource());
40+
});
41+
42+
it('pins the current version by sha256, size, path and url', () => {
43+
const current = manifest();
44+
const bytes = artifact(current.version);
45+
expect(current).toMatchObject({ name: 'Software Garden', catalogId: 'software-factory', target: 'cloud' });
46+
expect(current.sha256, REGENERATE).toBe(sha256(bytes));
47+
expect(current.bytes).toBe(bytes.byteLength);
48+
expect(current.path).toBe(`web/${softwareGardenArtifactPath(current.version)}`);
49+
expect(current.url).toBe(softwareGardenArtifactUrl(current.version));
50+
expect(current.draft).toEqual(SOFTWARE_GARDEN_DRAFT);
51+
expect(current.versions.at(-1)).toEqual({ version: current.version, sha256: current.sha256 });
52+
});
53+
54+
it('never rewrites a published version in place', () => {
55+
const { versions } = manifest();
56+
// Versions only move forward. Output that returns to an earlier version's
57+
// bytes is published as a new version, so a digest may recur.
58+
expect(versions.map(entry => entry.version)).toEqual(versions.map((_, index) => index + 1));
59+
for (const entry of versions) {
60+
expect(existsSync(path.join(web, softwareGardenArtifactPath(entry.version))), `v${entry.version}`).toBe(true);
61+
expect(sha256(artifact(entry.version)), `v${entry.version} was edited after it was published`).toBe(entry.sha256);
62+
}
63+
});
64+
65+
it('is exactly what /flows onboarding hands to Cloud for the same draft', () => {
66+
const current = artifact(manifest().version).toString('utf8');
67+
// A person who picks GitHub, Claude Code and Traditional with no extra
68+
// instructions. Their repository and label filters are applied by Cloud's
69+
// listener, not written into the source, so they do not change the bytes.
70+
const answered: FactoryDraft[] = [
71+
{ ...DEFAULT_FACTORY, sources: ['github'], agents: ['claude'], workflow: 'traditional', step: 2 },
72+
{ ...DEFAULT_FACTORY, sources: ['github'], sourceSettings: { github: { repository: 'acme/app', labels: 'ready' } }, agents: ['claude'], otherAgentSelected: false, workflow: 'traditional', step: 3 },
73+
];
74+
for (const draft of answered) {
75+
const url = new URL(cloudConnectionsHref(draft, '00000000-0000-4000-8000-000000000001'));
76+
const payload = JSON.parse(decodeURIComponent(url.hash.slice(1)));
77+
expect(payload.name).toBe('Software Garden');
78+
expect(payload.source).toBe(current);
79+
}
80+
});
81+
82+
it('is the variant the catalog entry deploys', () => {
83+
// Cloud's prebuilt wizard deploys the catalog source verbatim with the
84+
// entry's default agents and trigger, so the published draft must be that
85+
// same selection: another agent order is a different file.
86+
const entry = catalog.flows.find(flow => flow.id === 'software-factory')!;
87+
expect(SOFTWARE_GARDEN_DRAFT.agents).toEqual(entry.inputs.defaults.agents);
88+
expect(SOFTWARE_GARDEN_DRAFT.agents.every(agent => (entry.inputs.allowedAgents as string[]).includes(agent))).toBe(true);
89+
expect(SOFTWARE_GARDEN_DRAFT.sources).toEqual([entry.defaultTrigger.provider]);
90+
expect(SOFTWARE_GARDEN_DRAFT.sourceSettings).toEqual(entry.defaultTrigger.settings);
91+
expect(SOFTWARE_GARDEN_DRAFT).toMatchObject({ workflow: 'traditional', task: '', otherAgent: '' });
92+
});
93+
});
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"name": "Software Garden",
3+
"catalogId": "software-factory",
4+
"version": 1,
5+
"sha256": "b89a36e2cf9054036a7fc53fba20011a42ef0275ffbaaa907b080738ab46ad27",
6+
"bytes": 64355,
7+
"path": "web/public/flows/software-garden/v1.flow.ts",
8+
"url": "https://agentrelay.com/flows/software-garden/v1.flow.ts",
9+
"target": "cloud",
10+
"draft": {
11+
"version": 4,
12+
"sources": [
13+
"github"
14+
],
15+
"sourceSettings": {},
16+
"agents": [
17+
"claude"
18+
],
19+
"otherAgent": "",
20+
"task": "",
21+
"workflow": "traditional",
22+
"step": 3
23+
},
24+
"versions": [
25+
{
26+
"version": 1,
27+
"sha256": "b89a36e2cf9054036a7fc53fba20011a42ef0275ffbaaa907b080738ab46ad27"
28+
}
29+
]
30+
}

0 commit comments

Comments
 (0)