@plainconceptsplatform/workflows 0.2.1 → 0.3.2

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.
@@ -0,0 +1,121 @@
1
+ import { routeNames, workflowRoutes } from "./workflow-catalog.js";
2
+ const routeCrons = {
3
+ audit: "17 1 * * 1",
4
+ propose: "29 7 * * *",
5
+ };
6
+ export function stripRouteFromRouter(yaml, route) {
7
+ let result = yaml;
8
+ const cron = routeCrons[route];
9
+ if (cron !== undefined) {
10
+ result = result.replace(new RegExp(`^ - cron: "${escapeRegex(cron)}"\\n`, "gm"), "");
11
+ }
12
+ result = removeJobBlock(result, `call-${route}`);
13
+ result = result.replace(new RegExp(`^ - ${escapeRegex(route)}\\n`, "gm"), "");
14
+ return result;
15
+ }
16
+ export function stripRouteFromClassifier(shell, route) {
17
+ const constName = route.replace(/-/g, "_").toUpperCase() + "_CRON";
18
+ let result = shell;
19
+ result = result.replace(new RegExp(`^readonly ${constName}="[^"]*"\\n`, "gm"), "");
20
+ const cron = routeCrons[route];
21
+ if (cron !== undefined) {
22
+ result = result.replace(new RegExp(`\\s*"\\$${constName}"\\) route="${escapeRegex(route)}" ;;\\n`, "g"), "");
23
+ }
24
+ result = result.replace(new RegExp(` \\| ${escapeRegex(route)}\\)`, "g"), ")");
25
+ result = result.replace(new RegExp(`^(\\s+)${escapeRegex(route)} \\| `, "gm"), "$1");
26
+ if (!result.includes(`| ${route}`) && !result.includes(`${route} |`)) {
27
+ result = removeAloneDispatchCase(result, route);
28
+ }
29
+ return result;
30
+ }
31
+ function removeAloneDispatchCase(shell, route) {
32
+ const lines = shell.split("\n");
33
+ const pattern = new RegExp(`^(\\s+)${escapeRegex(route)}\\)\\s*$`);
34
+ const result = [];
35
+ let i = 0;
36
+ while (i < lines.length) {
37
+ const match = lines[i].match(pattern);
38
+ if (match) {
39
+ const indent = match[1];
40
+ i++;
41
+ while (i < lines.length) {
42
+ if (new RegExp(`^${escapeRegex(indent)};;\\s*$`).test(lines[i])) {
43
+ i++;
44
+ break;
45
+ }
46
+ i++;
47
+ }
48
+ }
49
+ else {
50
+ result.push(lines[i]);
51
+ i++;
52
+ }
53
+ }
54
+ return result.join("\n");
55
+ }
56
+ export function addRouteExclusion(matrix, route) {
57
+ if (matrix.includes(`excluded route '${route}'`))
58
+ return matrix;
59
+ let result = matrix;
60
+ result = result.replace(new RegExp(` ${escapeRegex(route)} `, "g"), " ");
61
+ const exclusionBlock = `\necho "── Excluded routes ──────────────────────────────────────────────────────"\nif ! grep -q "route == '${route}'" "$ROUTER_YML"; then\n PASS=$((PASS + 1))\n echo " ${route} correctly excluded from work-router.yml"\nelse\n FAIL=$((FAIL + 1))\n echo "FAIL: excluded route '${route}' is still in work-router.yml" >&2\nfi\n`;
62
+ result = result.replace(/(\necho\nif \[ "\$FAIL" -eq 0 \])/, `${exclusionBlock}$1`);
63
+ return result;
64
+ }
65
+ export function processRoutes(files, selectedRoutes) {
66
+ const excludedRoutes = routeNames.filter((r) => !selectedRoutes.includes(r));
67
+ if (excludedRoutes.length === 0)
68
+ return files;
69
+ const result = new Map(files);
70
+ for (const route of excludedRoutes) {
71
+ const routerKey = findFileKey(result, "work-router.yml");
72
+ if (routerKey !== undefined) {
73
+ result.set(routerKey, stripRouteFromRouter(result.get(routerKey), route));
74
+ }
75
+ const classifierKey = findFileKey(result, "classify-route.sh");
76
+ if (classifierKey !== undefined) {
77
+ result.set(classifierKey, stripRouteFromClassifier(result.get(classifierKey), route));
78
+ }
79
+ const matrixKey = findFileKey(result, "verify-route-matrix.sh");
80
+ if (matrixKey !== undefined) {
81
+ result.set(matrixKey, addRouteExclusion(result.get(matrixKey), route));
82
+ }
83
+ }
84
+ return result;
85
+ }
86
+ export function excludedWorkerFiles(selectedRoutes) {
87
+ return new Set(workflowRoutes
88
+ .filter((route) => !selectedRoutes.includes(route.name))
89
+ .map((route) => route.worker));
90
+ }
91
+ function removeJobBlock(yaml, jobName) {
92
+ const lines = yaml.split("\n");
93
+ const startPattern = new RegExp(`^ ${escapeRegex(jobName)}:`);
94
+ const result = [];
95
+ let skipping = false;
96
+ for (const line of lines) {
97
+ if (skipping) {
98
+ if (/^ \S/.test(line) || /^[^\s]/.test(line)) {
99
+ skipping = false;
100
+ result.push(line);
101
+ }
102
+ }
103
+ else if (startPattern.test(line)) {
104
+ skipping = true;
105
+ }
106
+ else {
107
+ result.push(line);
108
+ }
109
+ }
110
+ return result.join("\n");
111
+ }
112
+ function findFileKey(files, endsWith) {
113
+ for (const key of files.keys()) {
114
+ if (key.endsWith(endsWith))
115
+ return key;
116
+ }
117
+ return undefined;
118
+ }
119
+ function escapeRegex(str) {
120
+ return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
121
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,340 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { addRouteExclusion, excludedWorkerFiles, processRoutes, stripRouteFromClassifier, stripRouteFromRouter, } from "./route-processing.js";
3
+ import { routeNames } from "./workflow-catalog.js";
4
+ const ROUTER_YAML = `# header
5
+ name: "All Work Router"
6
+
7
+ on:
8
+ schedule:
9
+ - cron: "17 1 * * 1"
10
+ - cron: "43 3 * * *"
11
+ - cron: "0 6 * * *"
12
+ - cron: "0 */2 * * *"
13
+ - cron: "29 7 * * *"
14
+
15
+ workflow_dispatch:
16
+ inputs:
17
+ operation:
18
+ description: "Operation to run"
19
+ required: true
20
+ type: choice
21
+ options:
22
+ - refine
23
+ - implement
24
+ - direct
25
+ - apply-review
26
+ - merge-gate
27
+ - audit
28
+ - propose
29
+ - audit-close
30
+ - cleanup-artifacts
31
+ - stale-recovery
32
+ - validate
33
+
34
+ jobs:
35
+ call-refine:
36
+ needs: [classify, authorize]
37
+ if: needs.classify.outputs.route == 'refine' && needs.authorize.outputs.trusted == 'true'
38
+ uses: ./.github/workflows/agent-refine.lock.yml
39
+ secrets:
40
+ OPENAI_API_KEY: \${{ secrets.OPENAI_API_KEY }}
41
+
42
+ call-implement:
43
+ needs: [classify, authorize]
44
+ if: needs.classify.outputs.route == 'implement' && needs.authorize.outputs.trusted == 'true'
45
+ uses: ./.github/workflows/agent-implement.lock.yml
46
+ secrets:
47
+ OPENAI_API_KEY: \${{ secrets.OPENAI_API_KEY }}
48
+
49
+ call-audit:
50
+ needs: classify
51
+ if: needs.classify.outputs.route == 'audit'
52
+ uses: ./.github/workflows/agent-audit.lock.yml
53
+ secrets:
54
+ OPENAI_API_KEY: \${{ secrets.OPENAI_API_KEY }}
55
+
56
+ call-propose:
57
+ needs: classify
58
+ if: needs.classify.outputs.route == 'propose'
59
+ uses: ./.github/workflows/agent-propose.lock.yml
60
+ secrets:
61
+ OPENAI_API_KEY: \${{ secrets.OPENAI_API_KEY }}
62
+
63
+ audit-close:
64
+ needs: classify
65
+ if: needs.classify.outputs.route == 'audit-close'
66
+ runs-on: ubuntu-latest
67
+ `;
68
+ const CLASSIFIER_SH = `#!/usr/bin/env bash
69
+ set -euo pipefail
70
+
71
+ readonly AUDIT_CRON="17 1 * * 1"
72
+ readonly AUDIT_CLOSE_CRON="43 3 * * *"
73
+ readonly CLEANUP_ARTIFACTS_CRON="0 6 * * *"
74
+ readonly STALE_RECOVERY_CRON="0 */2 * * *"
75
+ readonly PROPOSE_CRON="29 7 * * *"
76
+
77
+ classify_route() {
78
+ local route="none" error=""
79
+
80
+ case "\${EVENT:-}" in
81
+ schedule)
82
+ trigger_kind="scheduled"
83
+ case "\${SCHEDULE:-}" in
84
+ "\$AUDIT_CRON") route="audit" ;;
85
+ "\$AUDIT_CLOSE_CRON") route="audit-close" ;;
86
+ "\$CLEANUP_ARTIFACTS_CRON") route="cleanup-artifacts" ;;
87
+ "\$STALE_RECOVERY_CRON") route="stale-recovery" ;;
88
+ "\$PROPOSE_CRON") route="propose" ;;
89
+ *) error="no route for cron '\${SCHEDULE:-}'" ;;
90
+ esac
91
+ ;;
92
+
93
+ workflow_dispatch)
94
+ trigger_kind="manual"
95
+ case "\${OPERATION:-}" in
96
+ refine | implement | direct)
97
+ route="\${OPERATION}"
98
+ ;;
99
+ apply-review)
100
+ route="apply-review"
101
+ ;;
102
+ merge-gate)
103
+ route="merge-gate"
104
+ ;;
105
+ audit | propose)
106
+ route="\${OPERATION}"
107
+ trigger_kind="\${INPUT_TRIGGER_KIND:-manual}"
108
+ ;;
109
+ audit-close | cleanup-artifacts | stale-recovery | validate)
110
+ route="\${OPERATION}"
111
+ ;;
112
+ *)
113
+ error="unknown operation '\${OPERATION:-}'"
114
+ ;;
115
+ esac
116
+ ;;
117
+ esac
118
+
119
+ cat <<EOF
120
+ route=\${route}
121
+ error=\${error}
122
+ EOF
123
+ }
124
+
125
+ if [ "\${BASH_SOURCE[0]}" = "\$0" ]; then
126
+ classify_route
127
+ fi
128
+ `;
129
+ const MATRIX_SH = `#!/usr/bin/env bash
130
+ set -euo pipefail
131
+
132
+ echo "── Router wiring ─────────────────────────────────────────────────────────"
133
+ for route in refine implement direct apply-review merge-gate audit propose bot-approve \\
134
+ audit-close cleanup-artifacts stale-recovery validate; do
135
+ if grep -q "route == '\${route}'" "\$ROUTER_YML"; then
136
+ PASS=\$((PASS + 1))
137
+ else
138
+ FAIL=\$((FAIL + 1))
139
+ echo "FAIL: work-router.yml has no job for route '\${route}'" >&2
140
+ fi
141
+ done
142
+
143
+ while read -r operation; do
144
+ if grep -q "route == '\${operation}'" "\$ROUTER_YML"; then
145
+ PASS=\$((PASS + 1))
146
+ else
147
+ FAIL=\$((FAIL + 1))
148
+ echo "FAIL: dispatch operation '\${operation}' has no job in work-router.yml" >&2
149
+ fi
150
+ done < <(sed -n '/^ operation:/,/^ issue-number:/p' "\$ROUTER_YML" | sed -n 's/^ - //p')
151
+
152
+ echo
153
+ if [ "\$FAIL" -eq 0 ]; then
154
+ echo "Route matrix: \${PASS} passed"
155
+ else
156
+ echo "Route matrix: \${PASS} passed, \${FAIL} FAILED" >&2
157
+ fi
158
+
159
+ exit \$((FAIL > 0))
160
+ `;
161
+ describe("stripRouteFromRouter", () => {
162
+ it("removes the propose cron entry", () => {
163
+ const result = stripRouteFromRouter(ROUTER_YAML, "propose");
164
+ expect(result).not.toContain('cron: "29 7 * * *"');
165
+ expect(result).toContain('cron: "17 1 * * 1"');
166
+ });
167
+ it("removes the call-propose job block", () => {
168
+ const result = stripRouteFromRouter(ROUTER_YAML, "propose");
169
+ expect(result).not.toContain("call-propose");
170
+ expect(result).toContain("call-refine");
171
+ expect(result).toContain("call-audit");
172
+ });
173
+ it("removes propose from the dispatch options", () => {
174
+ const result = stripRouteFromRouter(ROUTER_YAML, "propose");
175
+ expect(result).not.toMatch(/^\s+- propose$/m);
176
+ expect(result).toMatch(/^\s+- refine$/m);
177
+ expect(result).toMatch(/^\s+- audit$/m);
178
+ });
179
+ it("removes the audit cron entry", () => {
180
+ const result = stripRouteFromRouter(ROUTER_YAML, "audit");
181
+ expect(result).not.toContain('cron: "17 1 * * 1"');
182
+ expect(result).toContain('cron: "29 7 * * *"');
183
+ });
184
+ it("removes the call-audit job block", () => {
185
+ const result = stripRouteFromRouter(ROUTER_YAML, "audit");
186
+ expect(result).not.toContain("call-audit");
187
+ expect(result).toContain("call-refine");
188
+ });
189
+ it("preserves the audit-close job when removing audit", () => {
190
+ const result = stripRouteFromRouter(ROUTER_YAML, "audit");
191
+ expect(result).toContain("audit-close");
192
+ });
193
+ it("does not modify the yaml when stripping a route that has no cron", () => {
194
+ const yamlWithoutCron = ROUTER_YAML.replace(/ - cron: "17 1 \* \* 1"\n/, "");
195
+ const result = stripRouteFromRouter(yamlWithoutCron, "audit");
196
+ expect(result).not.toContain("call-audit");
197
+ });
198
+ });
199
+ describe("stripRouteFromClassifier", () => {
200
+ it("removes the PROPOSE_CRON constant", () => {
201
+ const result = stripRouteFromClassifier(CLASSIFIER_SH, "propose");
202
+ expect(result).not.toContain('readonly PROPOSE_CRON');
203
+ expect(result).toContain('readonly AUDIT_CRON');
204
+ });
205
+ it("removes the propose schedule case", () => {
206
+ const result = stripRouteFromClassifier(CLASSIFIER_SH, "propose");
207
+ expect(result).not.toContain('"$PROPOSE_CRON") route="propose"');
208
+ expect(result).toContain('"$AUDIT_CRON") route="audit"');
209
+ });
210
+ it("removes the AUDIT_CRON constant", () => {
211
+ const result = stripRouteFromClassifier(CLASSIFIER_SH, "audit");
212
+ expect(result).not.toContain('readonly AUDIT_CRON');
213
+ expect(result).toContain('readonly PROPOSE_CRON');
214
+ });
215
+ it("removes the audit schedule case", () => {
216
+ const result = stripRouteFromClassifier(CLASSIFIER_SH, "audit");
217
+ expect(result).not.toContain('"$AUDIT_CRON") route="audit"');
218
+ expect(result).toContain('"$PROPOSE_CRON") route="propose"');
219
+ });
220
+ it("removes propose from the dispatch case union", () => {
221
+ const result = stripRouteFromClassifier(CLASSIFIER_SH, "propose");
222
+ expect(result).not.toContain("audit | propose)");
223
+ expect(result).toContain("audit)");
224
+ });
225
+ });
226
+ describe("addRouteExclusion", () => {
227
+ it("adds an exclusion assertion for the route", () => {
228
+ const result = addRouteExclusion(MATRIX_SH, "propose");
229
+ expect(result).toContain("excluded route 'propose'");
230
+ expect(result).toContain("propose correctly excluded from work-router.yml");
231
+ });
232
+ it("does not add the exclusion twice", () => {
233
+ const once = addRouteExclusion(MATRIX_SH, "propose");
234
+ const twice = addRouteExclusion(once, "propose");
235
+ const matchCount = (twice.match(/excluded route 'propose'/g) ?? []).length;
236
+ expect(matchCount).toBe(1);
237
+ });
238
+ });
239
+ describe("processRoutes", () => {
240
+ it("returns the same map when all routes are selected", () => {
241
+ const files = new Map([
242
+ ["work-router.yml", ROUTER_YAML],
243
+ ["classify-route.sh", CLASSIFIER_SH],
244
+ ["verify-route-matrix.sh", MATRIX_SH],
245
+ ]);
246
+ const result = processRoutes(files, [...routeNames]);
247
+ expect(result).toBe(files);
248
+ });
249
+ it("strips every worker route when no routes are selected", () => {
250
+ const files = new Map([
251
+ [".github/workflows/work-router.yml", ROUTER_YAML],
252
+ [".github/actions/classify-route/classify-route.sh", CLASSIFIER_SH],
253
+ [".github/actions/verify-route-matrix/verify-route-matrix.sh", MATRIX_SH],
254
+ ]);
255
+ const result = processRoutes(files, []);
256
+ const router = result.get(".github/workflows/work-router.yml");
257
+ expect(router).not.toContain("call-propose");
258
+ expect(router).not.toContain("call-audit");
259
+ expect(router).not.toContain("- propose");
260
+ expect(router).not.toContain("- refine");
261
+ const classifier = result.get(".github/actions/classify-route/classify-route.sh");
262
+ expect(classifier).not.toContain("readonly PROPOSE_CRON");
263
+ expect(classifier).not.toContain("readonly AUDIT_CRON");
264
+ const matrix = result.get(".github/actions/verify-route-matrix/verify-route-matrix.sh");
265
+ expect(matrix).toContain("excluded route 'propose'");
266
+ expect(matrix).toContain("excluded route 'refine'");
267
+ });
268
+ it("strips propose from all three files when unselected", () => {
269
+ const files = new Map([
270
+ [".github/workflows/work-router.yml", ROUTER_YAML],
271
+ [".github/actions/classify-route/classify-route.sh", CLASSIFIER_SH],
272
+ [".github/actions/verify-route-matrix/verify-route-matrix.sh", MATRIX_SH],
273
+ ]);
274
+ const selectedRoutes = routeNames.filter((r) => r !== "propose");
275
+ const result = processRoutes(files, selectedRoutes);
276
+ const router = result.get(".github/workflows/work-router.yml");
277
+ expect(router).not.toContain("call-propose");
278
+ expect(router).not.toContain('cron: "29 7 * * *"');
279
+ expect(router).not.toMatch(/^\s+- propose$/m);
280
+ const classifier = result.get(".github/actions/classify-route/classify-route.sh");
281
+ expect(classifier).not.toContain("readonly PROPOSE_CRON");
282
+ expect(classifier).not.toContain('"$PROPOSE_CRON")');
283
+ const matrix = result.get(".github/actions/verify-route-matrix/verify-route-matrix.sh");
284
+ expect(matrix).toContain("excluded route 'propose'");
285
+ });
286
+ it("strips audit from all three files when unselected", () => {
287
+ const files = new Map([
288
+ ["work-router.yml", ROUTER_YAML],
289
+ ["classify-route.sh", CLASSIFIER_SH],
290
+ ["verify-route-matrix.sh", MATRIX_SH],
291
+ ]);
292
+ const selectedRoutes = routeNames.filter((r) => r !== "audit");
293
+ const result = processRoutes(files, selectedRoutes);
294
+ const router = result.get("work-router.yml");
295
+ expect(router).not.toContain("call-audit");
296
+ expect(router).not.toContain('cron: "17 1 * * 1"');
297
+ const classifier = result.get("classify-route.sh");
298
+ expect(classifier).not.toContain("readonly AUDIT_CRON");
299
+ expect(classifier).not.toContain('"$AUDIT_CRON")');
300
+ });
301
+ it("processes multiple excluded routes at once", () => {
302
+ const files = new Map([
303
+ ["work-router.yml", ROUTER_YAML],
304
+ ["classify-route.sh", CLASSIFIER_SH],
305
+ ["verify-route-matrix.sh", MATRIX_SH],
306
+ ]);
307
+ const selectedRoutes = ["refine", "implement"];
308
+ const result = processRoutes(files, selectedRoutes);
309
+ const router = result.get("work-router.yml");
310
+ expect(router).toContain("call-refine");
311
+ expect(router).toContain("call-implement");
312
+ expect(router).not.toContain("call-audit");
313
+ expect(router).not.toContain("call-propose");
314
+ });
315
+ });
316
+ describe("excludedWorkerFiles", () => {
317
+ it("returns worker files for unselected routes", () => {
318
+ const selectedRoutes = ["refine", "implement"];
319
+ const excluded = excludedWorkerFiles(selectedRoutes);
320
+ expect(excluded.has("agent-refine.md")).toBe(false);
321
+ expect(excluded.has("agent-implement.md")).toBe(false);
322
+ expect(excluded.has("agent-audit.md")).toBe(true);
323
+ expect(excluded.has("agent-propose.md")).toBe(true);
324
+ });
325
+ it("returns an empty set when all routes are selected", () => {
326
+ const excluded = excludedWorkerFiles([...routeNames]);
327
+ expect(excluded.size).toBe(0);
328
+ });
329
+ it("returns all worker files when no routes are selected", () => {
330
+ const excluded = excludedWorkerFiles([]);
331
+ expect(excluded.size).toBe(7);
332
+ expect(excluded.has("agent-refine.md")).toBe(true);
333
+ expect(excluded.has("agent-implement.md")).toBe(true);
334
+ expect(excluded.has("agent-direct.md")).toBe(true);
335
+ expect(excluded.has("agent-apply-review.md")).toBe(true);
336
+ expect(excluded.has("agent-merge-gate.md")).toBe(true);
337
+ expect(excluded.has("agent-audit.md")).toBe(true);
338
+ expect(excluded.has("agent-propose.md")).toBe(true);
339
+ });
340
+ });
@@ -0,0 +1,11 @@
1
+ import type { RepositoryInspection } from "./repository-inspection.js";
2
+ export interface StackDefaults {
3
+ readonly verifyCommands: string;
4
+ readonly repoRulesBase: string;
5
+ readonly hasDotnet: boolean;
6
+ readonly hasNodeOnly: boolean;
7
+ }
8
+ export declare function generateStackDefaults(inspection: RepositoryInspection): StackDefaults;
9
+ export declare function injectStackEnv(content: string, defaults: StackDefaults): string;
10
+ export declare function generateOpencodeCi(baseContent: string, inspection: RepositoryInspection): string;
11
+ export declare function generateOpencodeConfig(baseContent: string, inspection: RepositoryInspection): string;
@@ -0,0 +1,105 @@
1
+ export function generateStackDefaults(inspection) {
2
+ const hasDotnet = inspection.stackHints.solutionFiles.length > 0;
3
+ const hasNode = inspection.stackHints.pnpmLockfile;
4
+ const hasNodeOnly = hasNode && !hasDotnet;
5
+ let verifyCommands;
6
+ let repoRulesBase;
7
+ if (hasDotnet && hasNode) {
8
+ verifyCommands = ".NET: dotnet restore && dotnet build -c Release && dotnet test | Web: pnpm lint && pnpm test && pnpm build";
9
+ repoRulesBase = "Full-stack .NET + React/Next.js repository. Follow Clean Architecture layering: API → Application → Domain. Infrastructure implements Application ports. Do not reference EF Core or ASP.NET from Application. Frontend communicates exclusively via HTTP endpoints. Run both .NET and frontend verification.";
10
+ }
11
+ else if (hasDotnet) {
12
+ verifyCommands = "dotnet restore && dotnet build -c Release --no-restore && dotnet test";
13
+ repoRulesBase = ".NET repository using Clean Architecture. Follow layering: API → Application → Domain. Infrastructure implements Application ports. Do not reference EF Core or ASP.NET from Application.";
14
+ }
15
+ else {
16
+ verifyCommands = "pnpm verify";
17
+ repoRulesBase = "Node.js repository. Follow existing project conventions and import boundaries.";
18
+ }
19
+ return { verifyCommands, repoRulesBase, hasDotnet, hasNodeOnly };
20
+ }
21
+ export function injectStackEnv(content, defaults) {
22
+ let result = content;
23
+ if (defaults.verifyCommands === "pnpm verify")
24
+ return result;
25
+ if (result.includes("VERIFY_COMMANDS:")) {
26
+ result = result.replace(/ VERIFY_COMMANDS: ".*"/, ` VERIFY_COMMANDS: "${defaults.verifyCommands}"`);
27
+ }
28
+ else if (/^env:\n/m.test(result)) {
29
+ result = result.replace(/^env:\n/m, `env:\n VERIFY_COMMANDS: "${defaults.verifyCommands}"\n`);
30
+ }
31
+ return result;
32
+ }
33
+ export function generateOpencodeCi(baseContent, inspection) {
34
+ let result = baseContent;
35
+ if (inspection.stackHints.solutionFiles.length > 0) {
36
+ const nugetSteps = ` - name: Cache NuGet packages
37
+ uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
38
+ with:
39
+ path: ~/.nuget/packages
40
+ key: nuget-\${{ runner.os }}-\${{ hashFiles('**/*.slnx', '**/Directory.Packages.props') }}
41
+ restore-keys: nuget-\${{ runner.os }}-
42
+
43
+ - name: Restore .NET dependencies
44
+ run: dotnet restore
45
+ `;
46
+ result = insertBeforeMarker(result, nugetSteps, " - name: Install workspace dependencies");
47
+ }
48
+ if (inspection.stackHints.openSpec) {
49
+ const openspecStep = ` - name: Install OpenSpec CLI
50
+ run: |
51
+ set -euo pipefail
52
+ npm install -g @openspec/cli@latest
53
+ openspec --version
54
+ `;
55
+ result = insertBeforeMarker(result, openspecStep, " - name: Install workspace dependencies");
56
+ }
57
+ if (inspection.stackHints.packageJson && !result.includes("--legacy-peer-deps")) {
58
+ result = result.replace(` if ! npm install --prefix .opencode; then\n echo "No plugin deps, skipping."\n exit 0\n fi`, ` if ! npm install --prefix .opencode; then\n echo "::warning::Strict npm install failed on a peer conflict. Retrying with --legacy-peer-deps; check .opencode/package.json."\n npm install --prefix .opencode --legacy-peer-deps\n fi`);
59
+ }
60
+ return result;
61
+ }
62
+ function insertBeforeMarker(content, steps, marker) {
63
+ if (content.includes(marker)) {
64
+ return content.replace(marker, steps + marker);
65
+ }
66
+ return content + "\n" + steps;
67
+ }
68
+ export function generateOpencodeConfig(baseContent, inspection) {
69
+ try {
70
+ const config = JSON.parse(baseContent);
71
+ const hasDotnet = inspection.stackHints.solutionFiles.length > 0;
72
+ if (!hasDotnet && config.lsp !== undefined) {
73
+ delete config.lsp;
74
+ }
75
+ else if (hasDotnet && config.lsp === undefined) {
76
+ config.lsp = {
77
+ csharp: { disabled: true },
78
+ fsharp: { disabled: true },
79
+ razor: { disabled: true },
80
+ };
81
+ }
82
+ const agent = config.agent;
83
+ if (agent !== undefined) {
84
+ const agentEntry = agent["ci-workflow-agent"];
85
+ if (agentEntry !== undefined) {
86
+ let prompt = agentEntry.prompt ?? "";
87
+ if (hasDotnet) {
88
+ if (!prompt.includes(".NET guardrails")) {
89
+ prompt += "\n\n# .NET guardrails\nFollow Clean Architecture layering: API → Application → Domain. Infrastructure implements Application ports. Application must not reference EF Core or ASP.NET. Use Central Package Management (Directory.Packages.props). Build in Release mode for CI.";
90
+ }
91
+ }
92
+ else {
93
+ if (!prompt.includes("Node/React rules")) {
94
+ prompt += "\n\n# Node/React rules\nFollow Feature-Sliced Design import boundaries. Use pnpm, never npm or yarn. All user-facing text must be i18n messages. TypeScript strict mode.";
95
+ }
96
+ }
97
+ agentEntry.prompt = prompt;
98
+ }
99
+ }
100
+ return JSON.stringify(config, null, 2) + "\n";
101
+ }
102
+ catch {
103
+ return baseContent;
104
+ }
105
+ }
@@ -0,0 +1 @@
1
+ export {};