@punks/cli 3.2.1 → 3.3.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.
Files changed (117) hide show
  1. package/AGENTS.md +2 -0
  2. package/dist/BASELINE_CHANGELOG.md +76 -0
  3. package/dist/CHANGELOG.md +46 -1
  4. package/dist/baseline/scaffold-baseline/baseline.json +5 -5
  5. package/dist/baseline/scaffold-baseline/data/catalog/lint-assets.json +4 -1
  6. package/dist/baseline/scaffold-baseline/data/catalog/packs.json +7 -3
  7. package/dist/baseline/scaffold-baseline/data/catalog/skills.json +32 -0
  8. package/dist/baseline/scaffold-baseline/skills/agnostic/cli/hi-cli/references/post-command-flow.md +25 -17
  9. package/dist/baseline/scaffold-baseline/skills/agnostic/docs/rule-authoring/SKILL.md +18 -0
  10. package/dist/baseline/scaffold-baseline/skills/agnostic/docs/rule-authoring/references/migration.md +10 -0
  11. package/dist/baseline/scaffold-baseline/skills/agnostic/frontend/animate/LICENSE +21 -0
  12. package/dist/baseline/scaffold-baseline/skills/agnostic/frontend/animate/RECIPES.md +333 -0
  13. package/dist/baseline/scaffold-baseline/skills/agnostic/frontend/animate/SKILL.md +203 -0
  14. package/dist/baseline/scaffold-baseline/skills/agnostic/frontend/animate/UPSTREAM.md +9 -0
  15. package/dist/baseline/scaffold-baseline/skills/agnostic/frontend/review-animations/LICENSE +21 -0
  16. package/dist/baseline/scaffold-baseline/skills/agnostic/frontend/review-animations/SKILL.md +112 -0
  17. package/dist/baseline/scaffold-baseline/skills/agnostic/frontend/review-animations/STANDARDS.md +229 -0
  18. package/dist/baseline/scaffold-baseline/skills/agnostic/frontend/review-animations/UPSTREAM.md +9 -0
  19. package/dist/baseline/scaffold-baseline/skills/agnostic/planning/create-plan/REFERENCE.md +5 -1
  20. package/dist/baseline/scaffold-baseline/skills/agnostic/planning/create-plan/SKILL.md +9 -7
  21. package/dist/baseline/scaffold-baseline/skills/agnostic/planning/create-plan/references/architecture-convergence.md +4 -3
  22. package/dist/baseline/scaffold-baseline/skills/agnostic/planning/create-plan/references/planner-task-graph.md +12 -7
  23. package/dist/baseline/scaffold-baseline/skills/agnostic/quality/tdd/SKILL.md +3 -2
  24. package/dist/baseline/scaffold-baseline/skills/agnostic/quality/tdd/high-signal-tests.md +17 -3
  25. package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/domain-modeling/{CONTEXT-FORMAT.md → GLOSSARY-FORMAT.md} +9 -9
  26. package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/domain-modeling/SKILL.md +12 -12
  27. package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/requirements-grill/SKILL.md +4 -1
  28. package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/requirements-grill/references/artifact-output.md +36 -3
  29. package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/requirements-grill/references/grilling-flow.md +18 -1
  30. package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/write-backlog/EXAMPLES.md +1 -1
  31. package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/write-backlog/REFERENCE.md +4 -3
  32. package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/write-backlog/SKILL.md +2 -2
  33. package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/write-backlog/assets/concepts/backlog-model.md +6 -6
  34. package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/write-backlog/assets/providers/azure-devops-create-payload.md +7 -7
  35. package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/write-backlog/assets/providers/github-projects-create-payload.md +12 -12
  36. package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/write-backlog/assets/providers/linear-create-payload.md +9 -9
  37. package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/write-backlog/assets/providers/monday-create-payload.md +10 -10
  38. package/dist/baseline/scaffold-baseline/skills/frameworks/expo/animate-expo/LICENSE +21 -0
  39. package/dist/baseline/scaffold-baseline/skills/frameworks/expo/animate-expo/RECIPES.md +435 -0
  40. package/dist/baseline/scaffold-baseline/skills/frameworks/expo/animate-expo/SKILL.md +255 -0
  41. package/dist/baseline/scaffold-baseline/skills/frameworks/expo/animate-expo/UPSTREAM.md +9 -0
  42. package/dist/baseline/scaffold-baseline/skills/misc/wait-what/SKILL.md +1 -1
  43. package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/SKILL.md +5 -7
  44. package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/phases/review.md +50 -25
  45. package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/phases/router.md +29 -21
  46. package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/references/phase-handoff.md +28 -10
  47. package/dist/baseline/scaffold-baseline/skills/phases/review-phase/AUTHORING-HANDOFF.md +14 -11
  48. package/dist/baseline/scaffold-baseline/skills/phases/review-phase/phases/prepare-review.md +1 -1
  49. package/dist/baseline/scaffold-baseline/skills/phases/review-phase/phases/retain-report.md +9 -2
  50. package/dist/baseline/scaffold-baseline/skills/phases/review-phase/phases/return-route.md +6 -8
  51. package/dist/baseline/scaffold-baseline/skills/phases/review-phase/phases/run-review.md +8 -5
  52. package/dist/baseline/scaffold-baseline/skills/phases/review-phase/references/durable-report.md +29 -14
  53. package/dist/baseline/scaffold-baseline/skills/phases/review-phase/references/state-graph.md +45 -32
  54. package/dist/baseline/scaffold-baseline/skills/phases/review-phase/references/targets.md +2 -1
  55. package/dist/baseline/scaffold-baseline/skills/phases/review-phase/scripts/review-contract.mjs +86 -12
  56. package/dist/baseline/scaffold-baseline.json +5 -5
  57. package/dist/baseline/scaffold-baseline.tgz +0 -0
  58. package/dist/data/AGENTS.md +2 -0
  59. package/dist/index.js +17 -17
  60. package/dist/skills/agnostic/cli/hi-cli/references/post-command-flow.md +10 -2
  61. package/dist/skills/agnostic/docs/rule-authoring/SKILL.md +18 -0
  62. package/dist/skills/agnostic/docs/rule-authoring/references/migration.md +10 -0
  63. package/dist/skills/agnostic/frontend/animate/LICENSE +21 -0
  64. package/dist/skills/agnostic/frontend/animate/RECIPES.md +324 -0
  65. package/dist/skills/agnostic/frontend/animate/SKILL.md +199 -0
  66. package/dist/skills/agnostic/frontend/animate/UPSTREAM.md +9 -0
  67. package/dist/skills/agnostic/frontend/review-animations/LICENSE +21 -0
  68. package/dist/skills/agnostic/frontend/review-animations/SKILL.md +112 -0
  69. package/dist/skills/agnostic/frontend/review-animations/STANDARDS.md +187 -0
  70. package/dist/skills/agnostic/frontend/review-animations/UPSTREAM.md +9 -0
  71. package/dist/skills/agnostic/planning/create-plan/REFERENCE.md +5 -1
  72. package/dist/skills/agnostic/planning/create-plan/SKILL.md +9 -7
  73. package/dist/skills/agnostic/planning/create-plan/references/architecture-convergence.md +4 -3
  74. package/dist/skills/agnostic/planning/create-plan/references/planner-task-graph.md +12 -7
  75. package/dist/skills/agnostic/quality/tdd/SKILL.md +3 -2
  76. package/dist/skills/agnostic/quality/tdd/high-signal-tests.md +17 -3
  77. package/dist/skills/agnostic/requirements/domain-modeling/{CONTEXT-FORMAT.md → GLOSSARY-FORMAT.md} +9 -9
  78. package/dist/skills/agnostic/requirements/domain-modeling/SKILL.md +12 -12
  79. package/dist/skills/agnostic/requirements/requirements-grill/SKILL.md +4 -1
  80. package/dist/skills/agnostic/requirements/requirements-grill/references/artifact-output.md +33 -3
  81. package/dist/skills/agnostic/requirements/requirements-grill/references/grilling-flow.md +18 -1
  82. package/dist/skills/agnostic/requirements/write-backlog/EXAMPLES.md +1 -1
  83. package/dist/skills/agnostic/requirements/write-backlog/REFERENCE.md +4 -3
  84. package/dist/skills/agnostic/requirements/write-backlog/SKILL.md +2 -2
  85. package/dist/skills/agnostic/requirements/write-backlog/assets/concepts/backlog-model.md +6 -6
  86. package/dist/skills/agnostic/requirements/write-backlog/assets/providers/azure-devops-create-payload.md +7 -7
  87. package/dist/skills/agnostic/requirements/write-backlog/assets/providers/github-projects-create-payload.md +12 -12
  88. package/dist/skills/agnostic/requirements/write-backlog/assets/providers/linear-create-payload.md +9 -9
  89. package/dist/skills/agnostic/requirements/write-backlog/assets/providers/monday-create-payload.md +10 -10
  90. package/dist/skills/frameworks/expo/animate-expo/LICENSE +21 -0
  91. package/dist/skills/frameworks/expo/animate-expo/RECIPES.md +385 -0
  92. package/dist/skills/frameworks/expo/animate-expo/SKILL.md +255 -0
  93. package/dist/skills/frameworks/expo/animate-expo/UPSTREAM.md +9 -0
  94. package/dist/skills/misc/wait-what/SKILL.md +1 -1
  95. package/dist/skills/phases/delivery-phase/SKILL.md +5 -7
  96. package/dist/skills/phases/delivery-phase/phases/review.md +50 -25
  97. package/dist/skills/phases/delivery-phase/phases/router.md +27 -19
  98. package/dist/skills/phases/delivery-phase/references/phase-handoff.md +28 -10
  99. package/dist/skills/phases/review-phase/AUTHORING-HANDOFF.md +14 -11
  100. package/dist/skills/phases/review-phase/phases/prepare-review.md +1 -1
  101. package/dist/skills/phases/review-phase/phases/retain-report.md +9 -2
  102. package/dist/skills/phases/review-phase/phases/return-route.md +6 -8
  103. package/dist/skills/phases/review-phase/phases/run-review.md +8 -5
  104. package/dist/skills/phases/review-phase/references/durable-report.md +29 -14
  105. package/dist/skills/phases/review-phase/references/state-graph.md +19 -6
  106. package/dist/skills/phases/review-phase/references/targets.md +2 -1
  107. package/dist/skills/phases/review-phase/scripts/review-contract.mjs +91 -11
  108. package/package.json +4 -23
  109. package/dist/baseline/scaffold-baseline/data/scripts/harness-projection/adapters/claude.test.ts +0 -130
  110. package/dist/baseline/scaffold-baseline/data/scripts/harness-projection/adapters/codex.test.ts +0 -135
  111. package/dist/baseline/scaffold-baseline/data/scripts/harness-projection/adapters/cursor.test.ts +0 -138
  112. package/dist/baseline/scaffold-baseline/data/scripts/harness-projection/adapters/opencode.test.ts +0 -135
  113. package/dist/baseline/scaffold-baseline/data/scripts/harness-projection/contract.test.ts +0 -875
  114. package/dist/baseline/scaffold-baseline/data/scripts/sync-subagents.lifecycle.test.ts +0 -205
  115. package/dist/baseline/scaffold-baseline/data/scripts/sync-subagents.native.test.ts +0 -2765
  116. package/dist/baseline/scaffold-baseline/data/scripts/sync-subagents.test.ts +0 -2108
  117. package/dist/baseline/scaffold-baseline/data/subagents/manifest.test.ts +0 -116
@@ -1,875 +0,0 @@
1
- import { createHash } from "node:crypto";
2
- import { readFileSync } from "node:fs";
3
- import { access, mkdir, mkdtemp, readFile, readdir, rm, writeFile } from "node:fs/promises";
4
- import os from "node:os";
5
- import path from "node:path";
6
- import { fileURLToPath } from "node:url";
7
-
8
- import * as EffectVitest from "@effect/vitest";
9
- import type { ContextPlan, RepositoryScope } from "@punks/scaffold/context-plan";
10
- import * as ts from "typescript";
11
-
12
- import { applyProjection } from "./apply.mjs";
13
- import { testHarnessProjectionContract } from "./contract";
14
- import type { HarnessProjectionAdapter, ProjectionIntent } from "./contract";
15
- import { project } from "./core.mjs";
16
-
17
- const { describe, expect, it } = EffectVitest;
18
-
19
- const fixture = async <Value>(name: string): Promise<Value> =>
20
- JSON.parse(
21
- await readFile(new URL(`test-fixtures/${name}.json`, import.meta.url), "utf-8"),
22
- ) as Value;
23
-
24
- const declarationFiles = async (directory: URL): Promise<URL[]> => {
25
- const entries = await readdir(directory, { withFileTypes: true });
26
- const nestedFiles = await Promise.all(
27
- entries.map(async (entry) => {
28
- const entryUrl = new URL(entry.name, directory);
29
- if (entry.isDirectory()) {
30
- return await declarationFiles(new URL(`${entryUrl.href}/`));
31
- }
32
- return /\.d\.(?:cts|mts|ts)$/u.test(entry.name) ? [entryUrl] : [];
33
- }),
34
- );
35
- return nestedFiles.flat();
36
- };
37
-
38
- const declarationModuleSpecifiers = (
39
- source: string,
40
- fileName = "declaration.d.ts",
41
- ): readonly string[] => {
42
- const sourceFile = ts.createSourceFile(fileName, source, ts.ScriptTarget.Latest, true);
43
- const moduleSpecifiers: string[] = [];
44
- const visit = (node: ts.Node): void => {
45
- if (
46
- (ts.isImportDeclaration(node) || ts.isExportDeclaration(node)) &&
47
- node.moduleSpecifier !== undefined &&
48
- ts.isStringLiteral(node.moduleSpecifier)
49
- ) {
50
- moduleSpecifiers.push(node.moduleSpecifier.text);
51
- } else if (
52
- ts.isImportTypeNode(node) &&
53
- ts.isLiteralTypeNode(node.argument) &&
54
- ts.isStringLiteral(node.argument.literal)
55
- ) {
56
- moduleSpecifiers.push(node.argument.literal.text);
57
- } else if (
58
- ts.isExternalModuleReference(node) &&
59
- node.expression !== undefined &&
60
- ts.isStringLiteral(node.expression)
61
- ) {
62
- moduleSpecifiers.push(node.expression.text);
63
- }
64
- ts.forEachChild(node, visit);
65
- };
66
- visit(sourceFile);
67
- return moduleSpecifiers;
68
- };
69
-
70
- const projectionDeclarationInventory = [
71
- "adapters/claude.d.mts",
72
- "adapters/codex.d.mts",
73
- "adapters/cursor.d.mts",
74
- "adapters/opencode.d.mts",
75
- "apply.d.mts",
76
- "core.d.mts",
77
- ] as const;
78
-
79
- const normalizeDeclarationPath = (relativePath: string): string =>
80
- relativePath.replaceAll(path.win32.sep, path.posix.sep);
81
-
82
- const isPackageModuleSpecifier = (moduleSpecifier: string, packageName: string): boolean =>
83
- moduleSpecifier === packageName || moduleSpecifier.startsWith(`${packageName}/`);
84
-
85
- const adapterMatrix = Object.fromEntries([
86
- ["matrixVersion", "2026.07.16-test"],
87
- ["adapter", { id: "stub", version: "1.0.0" }],
88
- [
89
- "capabilities",
90
- [
91
- { family: "skill", support: "supported" },
92
- { family: "scoped-prompt", support: "supported" },
93
- { family: "lifecycle-hook", support: "supported" },
94
- Object.fromEntries([
95
- ["family", "tool-configuration"],
96
- ["support", "degraded"],
97
- ["reason", "Limited test support"],
98
- ]),
99
- Object.fromEntries([
100
- ["family", "subagent-template"],
101
- ["support", "unsupported"],
102
- ["reason", "No test subagents"],
103
- ]),
104
- ],
105
- ],
106
- ]) as unknown as HarnessProjectionAdapter["matrix"];
107
-
108
- const adapter = {
109
- matrix: adapterMatrix,
110
- project: ({ contribution }: Parameters<HarnessProjectionAdapter["project"]>[0]) => [
111
- Object.fromEntries([
112
- ["id", `write:${contribution.identity.id}`],
113
- ["content", contribution.identity.id],
114
- ]) as ProjectionIntent,
115
- ],
116
- } satisfies HarnessProjectionAdapter;
117
-
118
- const mixedContextPlan = JSON.parse(
119
- readFileSync(new URL("test-fixtures/mixed-context-plan.json", import.meta.url), "utf-8"),
120
- );
121
-
122
- const lifecycleTrace = (id: string) => ({
123
- adapter: { id: "opencode", version: "1.0.0" },
124
- contextPlanVersion: "1",
125
- contribution: { id, version: "1.0.0" },
126
- matrixVersion: "2026.07.17-v1",
127
- scopeId: "root",
128
- });
129
-
130
- testHarnessProjectionContract({
131
- adapter,
132
- contextPlan: mixedContextPlan,
133
- name: "stub",
134
- });
135
-
136
- describe("portable harness projection contract", () => {
137
- it("normalizes declaration paths and matches only the scaffold package namespace", () => {
138
- expect(normalizeDeclarationPath(String.raw`adapters\cursor.d.mts`)).toBe(
139
- "adapters/cursor.d.mts",
140
- );
141
- expect(isPackageModuleSpecifier("@punks/scaffold", "@punks/scaffold")).toBe(true);
142
- expect(isPackageModuleSpecifier("@punks/scaffold/context-plan", "@punks/scaffold")).toBe(true);
143
- expect(isPackageModuleSpecifier("@punks/scaffolding", "@punks/scaffold")).toBe(false);
144
- expect(isPackageModuleSpecifier("@punks/scaffold-internal", "@punks/scaffold")).toBe(false);
145
- });
146
-
147
- it("extracts every declaration module-specifier syntax", () => {
148
- const source = [
149
- 'import type { ContextPlan } from "@punks/scaffold/context-plan";',
150
- 'export type { HarnessProjectionSummary } from "@punks/scaffold/harness-capability";',
151
- 'type Catalog = import("@punks/scaffold/catalog");',
152
- 'import Baseline = require("@punks/scaffold/baseline");',
153
- ].join("\n");
154
-
155
- expect(declarationModuleSpecifiers(source)).toEqual([
156
- "@punks/scaffold/context-plan",
157
- "@punks/scaffold/harness-capability",
158
- "@punks/scaffold/catalog",
159
- "@punks/scaffold/baseline",
160
- ]);
161
- });
162
-
163
- it("imports scaffold declaration types only through exported module specifiers", async () => {
164
- const declarationRoot = new URL("./", import.meta.url);
165
- const scaffoldPackage = JSON.parse(
166
- await readFile(
167
- new URL("../../../../../../packages/scaffold/package.json", import.meta.url),
168
- "utf-8",
169
- ),
170
- ) as { readonly exports: Readonly<Record<string, unknown>>; readonly name: string };
171
- const unexported: string[] = [];
172
- const files = await declarationFiles(declarationRoot);
173
- const declarationDirectory = fileURLToPath(declarationRoot);
174
- const inventory = files
175
- .map((declaration) =>
176
- normalizeDeclarationPath(path.relative(declarationDirectory, fileURLToPath(declaration))),
177
- )
178
- .toSorted();
179
- expect(inventory.length).toBeGreaterThan(0);
180
- expect(inventory).toEqual(projectionDeclarationInventory);
181
- const declarations = await Promise.all(
182
- files.map(async (declaration) => ({
183
- declaration,
184
- source: await readFile(declaration, "utf-8"),
185
- })),
186
- );
187
-
188
- for (const { declaration, source } of declarations) {
189
- const declarationPath = fileURLToPath(declaration);
190
- for (const moduleSpecifier of declarationModuleSpecifiers(source, declarationPath)) {
191
- if (!isPackageModuleSpecifier(moduleSpecifier, scaffoldPackage.name)) {
192
- continue;
193
- }
194
- const exportKey =
195
- moduleSpecifier === scaffoldPackage.name
196
- ? "."
197
- : `.${moduleSpecifier.slice(scaffoldPackage.name.length)}`;
198
- if (!(exportKey in scaffoldPackage.exports)) {
199
- unexported.push(
200
- `${normalizeDeclarationPath(path.relative(declarationDirectory, declarationPath))}: ${moduleSpecifier}`,
201
- );
202
- }
203
- }
204
- }
205
-
206
- expect(unexported).toEqual([]);
207
- });
208
-
209
- it("keeps the active applicator aligned with the bundled scaffold source", async () => {
210
- const [active, bundled] = await Promise.all([
211
- readFile(
212
- new URL("../../../../../../.agents/scripts/harness-projection/apply.mjs", import.meta.url),
213
- "utf-8",
214
- ),
215
- readFile(new URL("apply.mjs", import.meta.url), "utf-8"),
216
- ]);
217
-
218
- expect(active).toBe(bundled);
219
- });
220
-
221
- it("keeps the active sync entrypoint aligned with its bundled source and fixture identity", async () => {
222
- const [active, bundled, managedAssets] = await Promise.all([
223
- readFile(
224
- new URL("../../../../../../.agents/scripts/sync-subagents.mjs", import.meta.url),
225
- "utf-8",
226
- ),
227
- readFile(new URL("../sync-subagents.mjs", import.meta.url), "utf-8"),
228
- readFile(
229
- new URL("../../../../test-fixtures/public-output/managed-assets.json", import.meta.url),
230
- "utf-8",
231
- ).then(
232
- (value) =>
233
- JSON.parse(value) as {
234
- readonly managedFiles: readonly { readonly path: string; readonly sha256: string }[];
235
- },
236
- ),
237
- ]);
238
- const identity = managedAssets.managedFiles.find(
239
- ({ path: managedPath }) => managedPath === ".agents/scripts/sync-subagents.mjs",
240
- );
241
-
242
- expect(active).toBe(bundled);
243
- for (const modulePath of [
244
- "adapters/claude.mjs",
245
- "adapters/codex.mjs",
246
- "adapters/cursor.mjs",
247
- "adapters/opencode.mjs",
248
- "apply.mjs",
249
- "core.mjs",
250
- ]) {
251
- expect(active).toContain(`from "./harness-projection/${modulePath}"`);
252
- }
253
- expect(createHash("sha256").update(active).digest("hex")).toBe(identity?.sha256);
254
- });
255
-
256
- it("continues supported work and records a typed omission for a known gap", async () => {
257
- const contextPlan = await fixture<ContextPlan>("mixed-context-plan");
258
-
259
- const result = project({ adapter, contextPlan });
260
-
261
- expect(result.actions.map(({ id }) => id)).toEqual(["write:effect", "write:skills-cli"]);
262
- expect(result.summary).toMatchObject({
263
- _tag: "HarnessProjectionPartial",
264
- applied: [
265
- {
266
- _tag: "HarnessProjectionApplied",
267
- support: "supported",
268
- trace: { contribution: { id: "effect", version: "1.0.0" } },
269
- },
270
- {
271
- _tag: "HarnessProjectionApplied",
272
- reason: "Limited test support",
273
- support: "degraded",
274
- trace: { contribution: { id: "skills-cli", version: "1.0.0" } },
275
- },
276
- ],
277
- omissions: [
278
- {
279
- _tag: "HarnessProjectionOmission",
280
- support: "unsupported",
281
- trace: { contribution: { id: "reviewer", version: "1.0.0" } },
282
- warning: {
283
- _tag: "UnsupportedHarnessCapabilityWarning",
284
- family: "subagent-template",
285
- reason: "No test subagents",
286
- },
287
- },
288
- ],
289
- });
290
- });
291
-
292
- it("records a degraded adapter unsupported result as a typed omission", async () => {
293
- const contextPlan = await fixture<ContextPlan>("mixed-context-plan");
294
- const unsupportedAdapter = {
295
- ...adapter,
296
- project: (input: Parameters<typeof adapter.project>[0]) =>
297
- input.contribution.identity.id === "skills-cli"
298
- ? {
299
- _tag: "HarnessProjectionUnsupported" as const,
300
- reason: "No native projection for this degraded contribution",
301
- }
302
- : adapter.project(input),
303
- };
304
-
305
- const result = project({ adapter: unsupportedAdapter, contextPlan });
306
-
307
- expect(result.actions.map(({ id }) => id)).toEqual(["write:effect"]);
308
- expect(result.summary).toMatchObject({
309
- _tag: "HarnessProjectionPartial",
310
- applied: [{ trace: { contribution: { id: "effect" } } }],
311
- omissions: expect.arrayContaining([
312
- expect.objectContaining({
313
- _tag: "HarnessProjectionOmission",
314
- support: "unsupported",
315
- trace: expect.objectContaining({
316
- contribution: expect.objectContaining({ id: "skills-cli" }),
317
- }),
318
- warning: {
319
- _tag: "UnsupportedHarnessCapabilityWarning",
320
- family: "tool-configuration",
321
- reason: "No native projection for this degraded contribution",
322
- },
323
- }),
324
- ]),
325
- });
326
- });
327
-
328
- it("rejects an adapter unsupported result for a supported capability", async () => {
329
- const contextPlan = await fixture<ContextPlan>("mixed-context-plan");
330
- const unsupportedAdapter = {
331
- ...adapter,
332
- project: (input: Parameters<typeof adapter.project>[0]) =>
333
- input.contribution.identity.id === "effect"
334
- ? {
335
- _tag: "HarnessProjectionUnsupported" as const,
336
- reason: "No native projection",
337
- }
338
- : adapter.project(input),
339
- };
340
-
341
- const result = project({ adapter: unsupportedAdapter, contextPlan });
342
-
343
- expect(result.actions.map(({ id }) => id)).toEqual(["write:skills-cli"]);
344
- expect(result.summary).toMatchObject({
345
- _tag: "HarnessProjectionFailure",
346
- completed: [{ trace: { contribution: { id: "skills-cli" } } }],
347
- errors: [
348
- {
349
- _tag: "InvalidHarnessProjectionError",
350
- message: "Adapter declared unsupported for a supported capability",
351
- trace: { contribution: { id: "effect" } },
352
- },
353
- ],
354
- });
355
- });
356
-
357
- it("keeps an invalid adapter result scoped to its contribution", async () => {
358
- const contextPlan = await fixture<ContextPlan>("mixed-context-plan");
359
- const invalidAdapter = {
360
- ...adapter,
361
- project: (input: Parameters<typeof adapter.project>[0]) =>
362
- input.contribution.identity.id === "effect" ? [] : adapter.project(input),
363
- };
364
-
365
- const result = project({ adapter: invalidAdapter, contextPlan });
366
-
367
- expect(result.actions.map(({ id }) => id)).toEqual(["write:skills-cli"]);
368
- expect(result.summary).toMatchObject({
369
- _tag: "HarnessProjectionFailure",
370
- completed: [
371
- {
372
- support: "degraded",
373
- trace: { contribution: { id: "skills-cli" } },
374
- },
375
- ],
376
- errors: [
377
- {
378
- _tag: "InvalidHarnessProjectionError",
379
- message: "Adapter must return at least one identified action",
380
- trace: { contribution: { id: "effect" } },
381
- },
382
- ],
383
- omissions: [{ trace: { contribution: { id: "reviewer" } } }],
384
- });
385
- });
386
-
387
- it("rejects a matrix with a missing capability row before projecting actions", async () => {
388
- const contextPlan =
389
- await fixture<Parameters<typeof project>[0]["contextPlan"]>("mixed-context-plan");
390
- const incompleteAdapter = {
391
- ...adapter,
392
- matrix: {
393
- ...adapter.matrix,
394
- capabilities: adapter.matrix.capabilities.filter(({ family }) => family !== "skill"),
395
- },
396
- };
397
-
398
- const result = project({
399
- adapter: incompleteAdapter as unknown as typeof adapter,
400
- contextPlan,
401
- });
402
-
403
- expect(result.actions).toEqual([]);
404
- expect(result.summary).toMatchObject({
405
- _tag: "HarnessProjectionFailure",
406
- completed: [],
407
- errors: [
408
- {
409
- _tag: "InvalidHarnessProjectionError",
410
- message: "Adapter matrix must contain exactly one capability for skill; found 0",
411
- trace: { contribution: { id: "effect" } },
412
- },
413
- {
414
- _tag: "InvalidHarnessProjectionError",
415
- message: "Adapter matrix must contain exactly one capability for skill; found 0",
416
- trace: { contribution: { id: "skills-cli" } },
417
- },
418
- {
419
- _tag: "InvalidHarnessProjectionError",
420
- message: "Adapter matrix must contain exactly one capability for skill; found 0",
421
- trace: { contribution: { id: "reviewer" } },
422
- },
423
- ],
424
- omissions: [],
425
- });
426
- });
427
-
428
- it("rejects a missing family even when the context plan has no contribution in that family", async () => {
429
- const fixtureContextPlan =
430
- await fixture<Parameters<typeof project>[0]["contextPlan"]>("mixed-context-plan");
431
- const skillsOnlyPlan = {
432
- ...fixtureContextPlan,
433
- scopes: fixtureContextPlan.scopes.map((scope: RepositoryScope) => ({
434
- ...scope,
435
- contributions: scope.contributions.filter(
436
- ({ kind }: RepositoryScope["contributions"][number]) => kind === "skill",
437
- ),
438
- })),
439
- };
440
- const incompleteAdapter = {
441
- ...adapter,
442
- matrix: {
443
- ...adapter.matrix,
444
- capabilities: adapter.matrix.capabilities.filter(
445
- ({ family }) => family !== "scoped-prompt",
446
- ),
447
- },
448
- };
449
-
450
- const result = project({
451
- adapter: incompleteAdapter as unknown as typeof adapter,
452
- contextPlan: skillsOnlyPlan,
453
- });
454
-
455
- expect(result.actions).toEqual([]);
456
- expect(result.summary).toMatchObject({
457
- _tag: "HarnessProjectionFailure",
458
- completed: [],
459
- errors: [
460
- {
461
- _tag: "InvalidHarnessProjectionError",
462
- message: "Adapter matrix must contain exactly one capability for scoped-prompt; found 0",
463
- trace: { contribution: { id: "effect" } },
464
- },
465
- ],
466
- omissions: [],
467
- });
468
- });
469
-
470
- it("rejects duplicate capability rows instead of applying the last row", async () => {
471
- const contextPlan =
472
- await fixture<Parameters<typeof project>[0]["contextPlan"]>("mixed-context-plan");
473
- const duplicateAdapter = {
474
- ...adapter,
475
- matrix: {
476
- ...adapter.matrix,
477
- capabilities: [
478
- ...adapter.matrix.capabilities,
479
- { family: "skill", reason: "Duplicate row", support: "unsupported" },
480
- ],
481
- },
482
- };
483
-
484
- const result = project({
485
- adapter: duplicateAdapter as unknown as typeof adapter,
486
- contextPlan,
487
- });
488
-
489
- expect(result.actions).toEqual([]);
490
- expect(result.summary).toMatchObject({
491
- _tag: "HarnessProjectionFailure",
492
- completed: [],
493
- errors: [
494
- {
495
- _tag: "InvalidHarnessProjectionError",
496
- message: "Adapter matrix must contain exactly one capability for skill; found 2",
497
- trace: { contribution: { id: "effect" } },
498
- },
499
- {
500
- _tag: "InvalidHarnessProjectionError",
501
- message: "Adapter matrix must contain exactly one capability for skill; found 2",
502
- trace: { contribution: { id: "skills-cli" } },
503
- },
504
- {
505
- _tag: "InvalidHarnessProjectionError",
506
- message: "Adapter matrix must contain exactly one capability for skill; found 2",
507
- trace: { contribution: { id: "reviewer" } },
508
- },
509
- ],
510
- omissions: [],
511
- });
512
- });
513
-
514
- it("rejects an unknown capability row before projecting any contribution", async () => {
515
- const contextPlan =
516
- await fixture<Parameters<typeof project>[0]["contextPlan"]>("mixed-context-plan");
517
- const unknownAdapter = {
518
- ...adapter,
519
- matrix: {
520
- ...adapter.matrix,
521
- capabilities: [...adapter.matrix.capabilities, { family: "unknown", support: "supported" }],
522
- },
523
- };
524
-
525
- const result = project({
526
- adapter: unknownAdapter as unknown as typeof adapter,
527
- contextPlan,
528
- });
529
-
530
- expect(result.actions).toEqual([]);
531
- expect(result.summary).toMatchObject({
532
- _tag: "HarnessProjectionFailure",
533
- completed: [],
534
- errors: [
535
- {
536
- _tag: "InvalidHarnessProjectionError",
537
- message: "Adapter matrix contains an unknown or malformed capability row",
538
- trace: { contribution: { id: "effect" } },
539
- },
540
- {
541
- _tag: "InvalidHarnessProjectionError",
542
- message: "Adapter matrix contains an unknown or malformed capability row",
543
- trace: { contribution: { id: "skills-cli" } },
544
- },
545
- {
546
- _tag: "InvalidHarnessProjectionError",
547
- message: "Adapter matrix contains an unknown or malformed capability row",
548
- trace: { contribution: { id: "reviewer" } },
549
- },
550
- ],
551
- omissions: [],
552
- });
553
- });
554
-
555
- it.each([
556
- ["missing matrix version", { matrixVersion: undefined }],
557
- ["matrix version", { matrixVersion: "" }],
558
- ["missing adapter identity", { adapter: undefined }],
559
- ["adapter id", { adapter: { id: "", version: "1.0.0" } }],
560
- ["missing adapter version", { adapter: { id: "stub" } }],
561
- ["adapter version", { adapter: { id: "stub", version: 0 } }],
562
- ])("rejects an invalid %s before projecting actions", async (_label, matrixPatch) => {
563
- const contextPlan =
564
- await fixture<Parameters<typeof project>[0]["contextPlan"]>("mixed-context-plan");
565
- const invalidAdapter = {
566
- ...adapter,
567
- matrix: { ...adapter.matrix, ...matrixPatch },
568
- };
569
-
570
- const result = project({
571
- adapter: invalidAdapter as unknown as typeof adapter,
572
- contextPlan,
573
- });
574
-
575
- expect(result.actions).toEqual([]);
576
- expect(result.summary).toMatchObject({
577
- _tag: "HarnessProjectionFailure",
578
- completed: [],
579
- errors: expect.arrayContaining([
580
- expect.objectContaining({ _tag: "InvalidHarnessProjectionError" }),
581
- ]),
582
- });
583
- });
584
-
585
- it("does not report success for invalid matrix metadata when the plan is empty", async () => {
586
- const contextPlan =
587
- await fixture<Parameters<typeof project>[0]["contextPlan"]>("mixed-context-plan");
588
- const emptyPlan = {
589
- ...contextPlan,
590
- scopes: contextPlan.scopes.map((scope: RepositoryScope) => ({
591
- ...scope,
592
- contributions: [],
593
- })),
594
- };
595
- const invalidAdapter = {
596
- ...adapter,
597
- matrix: { ...adapter.matrix, matrixVersion: "" },
598
- };
599
-
600
- const result = project({
601
- adapter: invalidAdapter as unknown as typeof adapter,
602
- contextPlan: emptyPlan,
603
- });
604
-
605
- expect(result).toMatchObject({
606
- actions: [],
607
- summary: {
608
- _tag: "HarnessProjectionFailure",
609
- completed: [],
610
- errors: [
611
- {
612
- _tag: "InvalidHarnessProjectionError",
613
- trace: {
614
- contribution: { id: "context-plan", version: "unknown" },
615
- matrixVersion: "unknown",
616
- },
617
- },
618
- ],
619
- },
620
- });
621
- });
622
-
623
- it("continues independent filesystem actions and reports only the failed action", async () => {
624
- const contextPlan = await fixture<Parameters<typeof project>[0]["contextPlan"]>(
625
- "application-context-plan",
626
- );
627
- const projection = project({ adapter, contextPlan });
628
- const root = await mkdtemp(path.join(os.tmpdir(), "harness-projection-"));
629
-
630
- try {
631
- const summary = await applyProjection({
632
- filesystem: {
633
- apply: async (action: (typeof projection.actions)[number]) => {
634
- if (action.id === "write:first") {
635
- throw new Error("disk full");
636
- }
637
- if (typeof action.content !== "string") {
638
- throw new TypeError("Expected string projection content.");
639
- }
640
- await mkdir(root, { recursive: true });
641
- await writeFile(path.join(root, `${action.content}.txt`), action.content, "utf-8");
642
- },
643
- },
644
- projection,
645
- });
646
-
647
- expect(await readFile(path.join(root, "second.txt"), "utf-8")).toBe("second");
648
- expect(summary).toMatchObject({
649
- _tag: "HarnessProjectionFailure",
650
- completed: [{ trace: { contribution: { id: "second" } } }],
651
- errors: [
652
- {
653
- _tag: "HarnessApplicationFailureError",
654
- action: "write:first",
655
- message: "disk full",
656
- trace: { contribution: { id: "first" } },
657
- },
658
- ],
659
- omissions: [],
660
- });
661
- expect(JSON.stringify(Object.keys(summary))).toBe(
662
- '["_tag","completed","omissions","errors"]',
663
- );
664
- if (summary._tag === "HarnessProjectionFailure") {
665
- expect(JSON.stringify(Object.keys(summary.errors[0] ?? {}))).toBe(
666
- '["_tag","trace","action","message"]',
667
- );
668
- }
669
- } finally {
670
- await rm(root, { force: true, recursive: true });
671
- }
672
-
673
- await expect(access(root)).rejects.toMatchObject({ code: "ENOENT" });
674
- });
675
-
676
- it("keeps successful contributions distinct when identity is shared across kinds", async () => {
677
- const shared = lifecycleTrace("shared");
678
- const failed = { ...shared, kind: "skill" };
679
- const completed = { ...shared, kind: "tool-configuration" };
680
- const summary = await applyProjection({
681
- filesystem: {
682
- apply: (action) =>
683
- action.id === "failed" ? Promise.reject(new Error("failed")) : Promise.resolve(),
684
- },
685
- projection: {
686
- actions: [
687
- { id: "failed", operation: "native", trace: failed },
688
- { id: "completed", operation: "native", trace: completed },
689
- ],
690
- summary: {
691
- _tag: "HarnessProjectionSuccess",
692
- applied: [
693
- { _tag: "HarnessProjectionApplied", support: "supported", trace: failed },
694
- { _tag: "HarnessProjectionApplied", support: "supported", trace: completed },
695
- ],
696
- },
697
- } as never,
698
- });
699
-
700
- expect(summary).toMatchObject({
701
- _tag: "HarnessProjectionFailure",
702
- completed: [{ trace: { kind: "tool-configuration" } }],
703
- errors: [{ action: "failed", trace: { kind: "skill" } }],
704
- });
705
- });
706
-
707
- it("does not enable a lifecycle hook whose managed mirror failed", async () => {
708
- const failedMirror = {
709
- contributionId: "format-edited-file",
710
- id: "opencode:lifecycle-hook:root:format-edited-file:mirror",
711
- operation: "mirror",
712
- source: ".agents/hooks/format-edited-file.mjs",
713
- target: ".opencode/plugins/format-edited-file.mjs",
714
- trace: lifecycleTrace("format-edited-file"),
715
- };
716
- const failedConfiguration = {
717
- contributionId: "format-edited-file",
718
- id: "opencode:lifecycle-hook:root:format-edited-file:configure",
719
- operation: "merge-json",
720
- target: "opencode.json",
721
- trace: lifecycleTrace("format-edited-file"),
722
- value: { formatter: { harness: { command: ["node", failedMirror.target] } } },
723
- };
724
- const survivingMirror = {
725
- contributionId: "scaffold-update-check",
726
- id: "opencode:lifecycle-hook:root:scaffold-update-check:mirror",
727
- operation: "mirror",
728
- source: ".agents/hooks/scaffold-update-check.mjs",
729
- target: ".opencode/plugins/scaffold-update-check.mjs",
730
- trace: lifecycleTrace("scaffold-update-check"),
731
- };
732
- const survivingConfiguration = {
733
- contributionId: "scaffold-update-check",
734
- id: "opencode:lifecycle-hook:root:scaffold-update-check:configure",
735
- operation: "merge-json",
736
- target: "opencode.json",
737
- trace: lifecycleTrace("scaffold-update-check"),
738
- value: { hooks: { harness: { command: ["node", survivingMirror.target] } } },
739
- };
740
- const configured: string[] = [];
741
- let independentApplied = false;
742
-
743
- const summary = await applyProjection({
744
- filesystem: {
745
- apply: (action) => {
746
- if (action.id === failedMirror.id) {
747
- throw new Error("missing canonical source");
748
- }
749
- if (action.operation === "reconcile-lifecycle-hooks") {
750
- configured.push(
751
- ...(
752
- (action.configurations as readonly { readonly contributionId: string }[]) ?? []
753
- ).map(({ contributionId }) => contributionId),
754
- );
755
- }
756
- if (action.id === "independent") {
757
- independentApplied = true;
758
- }
759
- },
760
- },
761
- projection: {
762
- actions: [
763
- failedMirror,
764
- failedConfiguration,
765
- survivingMirror,
766
- survivingConfiguration,
767
- {
768
- configurations: [failedConfiguration, survivingConfiguration],
769
- hookIds: ["format-edited-file", "scaffold-update-check"],
770
- id: "opencode:reconcile-lifecycle-hooks",
771
- managedHookFiles: [
772
- ".opencode/plugins/format-edited-file.mjs",
773
- ".opencode/plugins/scaffold-update-check.mjs",
774
- ],
775
- operation: "reconcile-lifecycle-hooks",
776
- trace: {
777
- adapter: { id: "opencode", version: "1.0.0" },
778
- contextPlanVersion: "1",
779
- matrixVersion: "2026.07.17-v1",
780
- operation: "lifecycle-hook-reconciliation",
781
- },
782
- },
783
- {
784
- id: "independent",
785
- operation: "native",
786
- trace: lifecycleTrace("independent"),
787
- },
788
- ],
789
- summary: {
790
- _tag: "HarnessProjectionSuccess",
791
- applied: [
792
- {
793
- _tag: "HarnessProjectionApplied",
794
- support: "degraded",
795
- trace: lifecycleTrace("format-edited-file"),
796
- },
797
- {
798
- _tag: "HarnessProjectionApplied",
799
- support: "degraded",
800
- trace: lifecycleTrace("scaffold-update-check"),
801
- },
802
- {
803
- _tag: "HarnessProjectionApplied",
804
- support: "supported",
805
- trace: lifecycleTrace("independent"),
806
- },
807
- ],
808
- },
809
- } as never,
810
- });
811
-
812
- expect(configured).toEqual(["scaffold-update-check"]);
813
- expect(independentApplied).toBe(true);
814
- expect(summary).toMatchObject({
815
- _tag: "HarnessProjectionFailure",
816
- completed: [
817
- { trace: { contribution: { id: "scaffold-update-check" } } },
818
- { trace: { contribution: { id: "independent" } } },
819
- ],
820
- });
821
- });
822
-
823
- it("excludes every affected hook when lifecycle reconciliation itself fails", async () => {
824
- const first = { ...lifecycleTrace("first"), kind: "lifecycle-hook" };
825
- const second = { ...lifecycleTrace("second"), kind: "lifecycle-hook" };
826
- const sameIdSkill = { ...lifecycleTrace("first"), kind: "skill" };
827
- const independent = { ...lifecycleTrace("independent"), kind: "skill" };
828
- const summary = await applyProjection({
829
- filesystem: {
830
- apply: (action) =>
831
- action.operation === "reconcile-lifecycle-hooks"
832
- ? Promise.reject(new Error("config unavailable"))
833
- : Promise.resolve(),
834
- },
835
- projection: {
836
- actions: [
837
- { id: "first", operation: "native", trace: first },
838
- { id: "second", operation: "native", trace: second },
839
- { id: "same-id-skill", operation: "native", trace: sameIdSkill },
840
- {
841
- configurations: [],
842
- hookIds: ["first", "second"],
843
- id: "opencode:reconcile-lifecycle-hooks",
844
- managedHookFiles: [],
845
- operation: "reconcile-lifecycle-hooks",
846
- trace: {
847
- adapter: { id: "opencode", version: "1.0.0" },
848
- contextPlanVersion: "1",
849
- matrixVersion: "2026.07.17-v1",
850
- operation: "lifecycle-hook-reconciliation",
851
- },
852
- },
853
- { id: "independent", operation: "native", trace: independent },
854
- ],
855
- summary: {
856
- _tag: "HarnessProjectionSuccess",
857
- applied: [first, second, sameIdSkill, independent].map((trace) => ({
858
- _tag: "HarnessProjectionApplied",
859
- support: "supported",
860
- trace,
861
- })),
862
- },
863
- } as never,
864
- });
865
-
866
- expect(summary).toMatchObject({
867
- _tag: "HarnessProjectionFailure",
868
- completed: [
869
- { trace: { contribution: { id: "first" }, kind: "skill" } },
870
- { trace: { contribution: { id: "independent" } } },
871
- ],
872
- errors: [{ action: "opencode:reconcile-lifecycle-hooks" }],
873
- });
874
- });
875
- });