@punks/cli 3.2.2 → 3.3.1
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/AGENTS.md +4 -2
- package/README.md +1 -1
- package/dist/BASELINE_CHANGELOG.md +56 -0
- package/dist/CHANGELOG.md +32 -0
- package/dist/baseline/scaffold-baseline/baseline.json +5 -5
- package/dist/baseline/scaffold-baseline/data/catalog/lint-assets.json +4 -1
- package/dist/baseline/scaffold-baseline/data/catalog/packs.json +6 -2
- package/dist/baseline/scaffold-baseline/data/catalog/skills.json +32 -0
- package/dist/baseline/scaffold-baseline/data/subagents/manifest.mjs +1 -0
- package/dist/baseline/scaffold-baseline/skills/agnostic/cli/hi-cli/references/post-command-flow.md +6 -1
- package/dist/baseline/scaffold-baseline/skills/agnostic/frontend/animate/LICENSE +21 -0
- package/dist/baseline/scaffold-baseline/skills/agnostic/frontend/animate/RECIPES.md +333 -0
- package/dist/baseline/scaffold-baseline/skills/agnostic/frontend/animate/SKILL.md +203 -0
- package/dist/baseline/scaffold-baseline/skills/agnostic/frontend/animate/UPSTREAM.md +9 -0
- package/dist/baseline/scaffold-baseline/skills/agnostic/frontend/improve-mobile-frontend/SKILL.md +109 -0
- package/dist/baseline/scaffold-baseline/skills/agnostic/frontend/improve-mobile-frontend/UPSTREAM.md +5 -0
- package/dist/baseline/scaffold-baseline/skills/agnostic/frontend/review-animations/LICENSE +21 -0
- package/dist/baseline/scaffold-baseline/skills/agnostic/frontend/review-animations/SKILL.md +112 -0
- package/dist/baseline/scaffold-baseline/skills/agnostic/frontend/review-animations/STANDARDS.md +229 -0
- package/dist/baseline/scaffold-baseline/skills/agnostic/frontend/review-animations/UPSTREAM.md +9 -0
- package/dist/baseline/scaffold-baseline/skills/agnostic/planning/create-plan/REFERENCE.md +5 -1
- package/dist/baseline/scaffold-baseline/skills/agnostic/planning/create-plan/SKILL.md +8 -6
- package/dist/baseline/scaffold-baseline/skills/agnostic/planning/create-plan/references/planner-task-graph.md +12 -7
- package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/requirements-grill/SKILL.md +6 -4
- package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/requirements-grill/references/artifact-output.md +36 -3
- package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/requirements-grill/references/grilling-flow.md +18 -1
- package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/write-backlog/EXAMPLES.md +1 -1
- package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/write-backlog/REFERENCE.md +4 -3
- package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/write-backlog/SKILL.md +2 -2
- package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/write-backlog/assets/concepts/backlog-model.md +6 -6
- package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/write-backlog/assets/providers/azure-devops-create-payload.md +7 -7
- package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/write-backlog/assets/providers/github-projects-create-payload.md +12 -12
- package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/write-backlog/assets/providers/linear-create-payload.md +9 -9
- package/dist/baseline/scaffold-baseline/skills/agnostic/requirements/write-backlog/assets/providers/monday-create-payload.md +10 -10
- package/dist/baseline/scaffold-baseline/skills/frameworks/expo/animate-expo/LICENSE +21 -0
- package/dist/baseline/scaffold-baseline/skills/frameworks/expo/animate-expo/RECIPES.md +435 -0
- package/dist/baseline/scaffold-baseline/skills/frameworks/expo/animate-expo/SKILL.md +255 -0
- package/dist/baseline/scaffold-baseline/skills/frameworks/expo/animate-expo/UPSTREAM.md +9 -0
- package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/phases/review.md +34 -9
- package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/phases/router.md +18 -11
- package/dist/baseline/scaffold-baseline/skills/phases/delivery-phase/references/phase-handoff.md +19 -1
- package/dist/baseline/scaffold-baseline/skills/phases/review-phase/AUTHORING-HANDOFF.md +14 -11
- package/dist/baseline/scaffold-baseline/skills/phases/review-phase/phases/retain-report.md +9 -2
- package/dist/baseline/scaffold-baseline/skills/phases/review-phase/phases/return-route.md +6 -8
- package/dist/baseline/scaffold-baseline/skills/phases/review-phase/phases/run-review.md +8 -5
- package/dist/baseline/scaffold-baseline/skills/phases/review-phase/references/durable-report.md +29 -14
- package/dist/baseline/scaffold-baseline/skills/phases/review-phase/references/state-graph.md +45 -32
- package/dist/baseline/scaffold-baseline/skills/phases/review-phase/references/targets.md +2 -1
- package/dist/baseline/scaffold-baseline/skills/phases/review-phase/scripts/review-contract.mjs +86 -12
- package/dist/baseline/scaffold-baseline.json +5 -5
- package/dist/baseline/scaffold-baseline.tgz +0 -0
- package/dist/data/AGENTS.md +1 -1
- package/dist/data/subagents/manifest.mjs +1 -0
- package/dist/index.js +27 -27
- package/dist/skills/agnostic/cli/hi-cli/references/post-command-flow.md +6 -1
- package/dist/skills/agnostic/frontend/animate/LICENSE +21 -0
- package/dist/skills/agnostic/frontend/animate/RECIPES.md +324 -0
- package/dist/skills/agnostic/frontend/animate/SKILL.md +199 -0
- package/dist/skills/agnostic/frontend/animate/UPSTREAM.md +9 -0
- package/dist/skills/agnostic/frontend/improve-mobile-frontend/SKILL.md +109 -0
- package/dist/skills/agnostic/frontend/improve-mobile-frontend/UPSTREAM.md +5 -0
- package/dist/skills/agnostic/frontend/review-animations/LICENSE +21 -0
- package/dist/skills/agnostic/frontend/review-animations/SKILL.md +112 -0
- package/dist/skills/agnostic/frontend/review-animations/STANDARDS.md +187 -0
- package/dist/skills/agnostic/frontend/review-animations/UPSTREAM.md +9 -0
- package/dist/skills/agnostic/planning/create-plan/REFERENCE.md +5 -1
- package/dist/skills/agnostic/planning/create-plan/SKILL.md +8 -6
- package/dist/skills/agnostic/planning/create-plan/references/planner-task-graph.md +12 -7
- package/dist/skills/agnostic/requirements/requirements-grill/SKILL.md +6 -4
- package/dist/skills/agnostic/requirements/requirements-grill/references/artifact-output.md +33 -3
- package/dist/skills/agnostic/requirements/requirements-grill/references/grilling-flow.md +18 -1
- package/dist/skills/agnostic/requirements/write-backlog/EXAMPLES.md +1 -1
- package/dist/skills/agnostic/requirements/write-backlog/REFERENCE.md +4 -3
- package/dist/skills/agnostic/requirements/write-backlog/SKILL.md +2 -2
- package/dist/skills/agnostic/requirements/write-backlog/assets/concepts/backlog-model.md +6 -6
- package/dist/skills/agnostic/requirements/write-backlog/assets/providers/azure-devops-create-payload.md +7 -7
- package/dist/skills/agnostic/requirements/write-backlog/assets/providers/github-projects-create-payload.md +12 -12
- package/dist/skills/agnostic/requirements/write-backlog/assets/providers/linear-create-payload.md +9 -9
- package/dist/skills/agnostic/requirements/write-backlog/assets/providers/monday-create-payload.md +10 -10
- package/dist/skills/frameworks/expo/animate-expo/LICENSE +21 -0
- package/dist/skills/frameworks/expo/animate-expo/RECIPES.md +385 -0
- package/dist/skills/frameworks/expo/animate-expo/SKILL.md +255 -0
- package/dist/skills/frameworks/expo/animate-expo/UPSTREAM.md +9 -0
- package/dist/skills/phases/delivery-phase/phases/review.md +34 -9
- package/dist/skills/phases/delivery-phase/phases/router.md +16 -9
- package/dist/skills/phases/delivery-phase/references/phase-handoff.md +19 -1
- package/dist/skills/phases/review-phase/AUTHORING-HANDOFF.md +14 -11
- package/dist/skills/phases/review-phase/phases/retain-report.md +9 -2
- package/dist/skills/phases/review-phase/phases/return-route.md +6 -8
- package/dist/skills/phases/review-phase/phases/run-review.md +8 -5
- package/dist/skills/phases/review-phase/references/durable-report.md +29 -14
- package/dist/skills/phases/review-phase/references/state-graph.md +18 -5
- package/dist/skills/phases/review-phase/references/targets.md +2 -1
- package/dist/skills/phases/review-phase/scripts/review-contract.mjs +91 -11
- package/package.json +52 -9
- package/dist/baseline/scaffold-baseline/data/scripts/harness-projection/adapters/claude.test.ts +0 -130
- package/dist/baseline/scaffold-baseline/data/scripts/harness-projection/adapters/codex.test.ts +0 -135
- package/dist/baseline/scaffold-baseline/data/scripts/harness-projection/adapters/cursor.test.ts +0 -138
- package/dist/baseline/scaffold-baseline/data/scripts/harness-projection/adapters/opencode.test.ts +0 -135
- package/dist/baseline/scaffold-baseline/data/scripts/harness-projection/contract.test.ts +0 -875
- package/dist/baseline/scaffold-baseline/data/scripts/sync-subagents.lifecycle.test.ts +0 -205
- package/dist/baseline/scaffold-baseline/data/scripts/sync-subagents.native.test.ts +0 -2765
- package/dist/baseline/scaffold-baseline/data/scripts/sync-subagents.test.ts +0 -2108
- package/dist/baseline/scaffold-baseline/data/subagents/manifest.test.ts +0 -116
- package/dist/skills/frameworks/nestjs/nestjs-best-practices/.gitignore +0 -29
|
@@ -1,2108 +0,0 @@
|
|
|
1
|
-
import { execFile } from "node:child_process";
|
|
2
|
-
import {
|
|
3
|
-
cp,
|
|
4
|
-
lstat,
|
|
5
|
-
mkdir,
|
|
6
|
-
mkdtemp,
|
|
7
|
-
readFile,
|
|
8
|
-
readlink,
|
|
9
|
-
rm,
|
|
10
|
-
symlink,
|
|
11
|
-
writeFile,
|
|
12
|
-
} from "node:fs/promises";
|
|
13
|
-
import os from "node:os";
|
|
14
|
-
import path from "node:path";
|
|
15
|
-
import { pathToFileURL } from "node:url";
|
|
16
|
-
import { promisify } from "node:util";
|
|
17
|
-
|
|
18
|
-
import * as EffectVitest from "@effect/vitest";
|
|
19
|
-
|
|
20
|
-
import { hashManagedFileContent } from "../../scaffold/json";
|
|
21
|
-
|
|
22
|
-
import { normalizeHarnessProjection } from "../../features/scaffold-state/compile";
|
|
23
|
-
import { claudeAdapter } from "./harness-projection/adapters/claude.mjs";
|
|
24
|
-
import { codexAdapter } from "./harness-projection/adapters/codex.mjs";
|
|
25
|
-
import { cursorAdapter } from "./harness-projection/adapters/cursor.mjs";
|
|
26
|
-
import { openCodeAdapter } from "./harness-projection/adapters/opencode.mjs";
|
|
27
|
-
import { project } from "./harness-projection/core.mjs";
|
|
28
|
-
|
|
29
|
-
const execFileAsync = promisify(execFile);
|
|
30
|
-
const { describe: suite, expect: assertThat, it: test } = EffectVitest;
|
|
31
|
-
|
|
32
|
-
const requireDefined = <Value>(value: Value | undefined): Value => {
|
|
33
|
-
if (value === undefined) {
|
|
34
|
-
throw new Error("Expected value to be defined");
|
|
35
|
-
}
|
|
36
|
-
return value;
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
const scriptSourcePath = path.resolve(import.meta.dirname, "sync-subagents.mjs");
|
|
40
|
-
const projectionSourcePath = path.resolve(import.meta.dirname, "harness-projection");
|
|
41
|
-
const receiptRelativePath = ".devpunks/harness-projection-receipt.json";
|
|
42
|
-
const projectGeneratedOwnership = {
|
|
43
|
-
_tag: "ProjectGenerated",
|
|
44
|
-
evidence: {
|
|
45
|
-
authority: { _tag: "RepositoryMirror", sourcePath: ".agents/hooks/existing.mjs" },
|
|
46
|
-
outputFingerprint: { _tag: "File", mode: 0o644, sha256: "a".repeat(64) },
|
|
47
|
-
producer: "sync-test",
|
|
48
|
-
revision: "1",
|
|
49
|
-
},
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
const scaffoldManifest = (
|
|
53
|
-
receiptEntries: readonly Record<string, unknown>[] = [
|
|
54
|
-
{ kind: "projection-receipt", path: receiptRelativePath, sha256: "b".repeat(64) },
|
|
55
|
-
],
|
|
56
|
-
) => ({
|
|
57
|
-
finalPacks: ["quality", "subagents"],
|
|
58
|
-
managedFiles: [
|
|
59
|
-
{ kind: "hook", path: ".agents/hooks/existing.mjs", sha256: "a".repeat(64) },
|
|
60
|
-
...receiptEntries,
|
|
61
|
-
],
|
|
62
|
-
projectionReceiptFile: receiptRelativePath,
|
|
63
|
-
projectionStatus: "partial",
|
|
64
|
-
unrelated: { retained: true },
|
|
65
|
-
version: "3.1.5",
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
const writeScaffoldManifest = async (root: string, manifest: unknown): Promise<string> => {
|
|
69
|
-
const manifestPath = path.join(root, ".devpunks/scaffold-manifest.json");
|
|
70
|
-
await writeFile(manifestPath, `${JSON.stringify(manifest, null, 4)}\n`, "utf-8");
|
|
71
|
-
return manifestPath;
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
const writeHarnessHooks = async (root: string): Promise<void> => {
|
|
75
|
-
await mkdir(path.join(root, ".agents/hooks"), { recursive: true });
|
|
76
|
-
await writeFile(path.join(root, ".agents/hooks/format-edited-file.mjs"), "", "utf-8");
|
|
77
|
-
await writeFile(path.join(root, ".agents/hooks/scaffold-update-check.mjs"), "", "utf-8");
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
const providerAgentSurfaces = [
|
|
81
|
-
{ adapter: "claude", directory: ".claude/agents", extension: "md" },
|
|
82
|
-
{ adapter: "codex", directory: ".codex/agents", extension: "toml" },
|
|
83
|
-
{ adapter: "cursor", directory: ".cursor/agents", extension: "md" },
|
|
84
|
-
{ adapter: "opencode", directory: ".opencode/agents", extension: "md" },
|
|
85
|
-
] as const;
|
|
86
|
-
|
|
87
|
-
const fixturePathExists = async (targetPath: string): Promise<boolean> => {
|
|
88
|
-
try {
|
|
89
|
-
await lstat(targetPath);
|
|
90
|
-
return true;
|
|
91
|
-
} catch (error) {
|
|
92
|
-
if (error && typeof error === "object" && "code" in error && error.code === "ENOENT") {
|
|
93
|
-
return false;
|
|
94
|
-
}
|
|
95
|
-
throw error;
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
const emittedRenderPayloadHash = async (
|
|
100
|
-
root: string,
|
|
101
|
-
agentNames: readonly string[],
|
|
102
|
-
): Promise<string> => {
|
|
103
|
-
const rendered = Object.fromEntries(
|
|
104
|
-
await Promise.all(
|
|
105
|
-
providerAgentSurfaces.map(async ({ adapter, directory, extension }) => [
|
|
106
|
-
adapter,
|
|
107
|
-
Object.fromEntries(
|
|
108
|
-
await Promise.all(
|
|
109
|
-
agentNames.map(async (agentName) => [
|
|
110
|
-
agentName,
|
|
111
|
-
await readFile(path.join(root, directory, `${agentName}.${extension}`), "utf-8"),
|
|
112
|
-
]),
|
|
113
|
-
),
|
|
114
|
-
),
|
|
115
|
-
]),
|
|
116
|
-
),
|
|
117
|
-
);
|
|
118
|
-
const [hasFormatHook, hasUpdateCheckHook] = await Promise.all(
|
|
119
|
-
["format-edited-file.mjs", "scaffold-update-check.mjs"].map((hookName) =>
|
|
120
|
-
fixturePathExists(path.join(root, ".agents/hooks", hookName)),
|
|
121
|
-
),
|
|
122
|
-
);
|
|
123
|
-
|
|
124
|
-
return hashManagedFileContent(
|
|
125
|
-
receiptRelativePath,
|
|
126
|
-
JSON.stringify({
|
|
127
|
-
availableHooks: { hasFormatHook, hasUpdateCheckHook },
|
|
128
|
-
rendered,
|
|
129
|
-
}),
|
|
130
|
-
);
|
|
131
|
-
};
|
|
132
|
-
|
|
133
|
-
const canonicalContextPlan = {
|
|
134
|
-
scopes: [
|
|
135
|
-
{
|
|
136
|
-
contributions: [
|
|
137
|
-
{
|
|
138
|
-
compatibility: [],
|
|
139
|
-
identity: { id: ".agents:shared-agents", version: "2026.07.17" },
|
|
140
|
-
kind: "scoped-prompt",
|
|
141
|
-
order: 0,
|
|
142
|
-
provenance: { revision: "2026.07.17", source: "bundled" },
|
|
143
|
-
references: [],
|
|
144
|
-
},
|
|
145
|
-
],
|
|
146
|
-
id: ".agents",
|
|
147
|
-
packs: [{ id: "subagents", order: 0 }],
|
|
148
|
-
},
|
|
149
|
-
{
|
|
150
|
-
contributions: [
|
|
151
|
-
{
|
|
152
|
-
compatibility: [],
|
|
153
|
-
identity: { id: "simplify", version: "2026.07.17" },
|
|
154
|
-
kind: "skill",
|
|
155
|
-
order: 0,
|
|
156
|
-
provenance: { revision: "2026.07.17", source: "bundled" },
|
|
157
|
-
references: [],
|
|
158
|
-
},
|
|
159
|
-
{
|
|
160
|
-
compatibility: [],
|
|
161
|
-
identity: { id: "format-edited-file", version: "2026.07.17" },
|
|
162
|
-
kind: "lifecycle-hook",
|
|
163
|
-
order: 1,
|
|
164
|
-
provenance: { revision: "2026.07.17", source: "bundled" },
|
|
165
|
-
references: [],
|
|
166
|
-
},
|
|
167
|
-
{
|
|
168
|
-
compatibility: [],
|
|
169
|
-
identity: { id: "scaffold-update-check", version: "2026.07.17" },
|
|
170
|
-
kind: "lifecycle-hook",
|
|
171
|
-
order: 2,
|
|
172
|
-
provenance: { revision: "2026.07.17", source: "bundled" },
|
|
173
|
-
references: [],
|
|
174
|
-
},
|
|
175
|
-
{
|
|
176
|
-
compatibility: [],
|
|
177
|
-
identity: { id: "opensrc", version: "2026.07.17" },
|
|
178
|
-
kind: "tool-configuration",
|
|
179
|
-
order: 3,
|
|
180
|
-
provenance: { revision: "2026.07.17", source: "bundled" },
|
|
181
|
-
references: [],
|
|
182
|
-
},
|
|
183
|
-
{
|
|
184
|
-
compatibility: [],
|
|
185
|
-
identity: { id: "frontend-worker", version: "2026.07.17" },
|
|
186
|
-
kind: "subagent-template",
|
|
187
|
-
order: 4,
|
|
188
|
-
provenance: { revision: "2026.07.17", source: "bundled" },
|
|
189
|
-
references: ["simplify"],
|
|
190
|
-
},
|
|
191
|
-
],
|
|
192
|
-
id: "root",
|
|
193
|
-
packs: [
|
|
194
|
-
{ id: "quality", order: 0 },
|
|
195
|
-
{ id: "subagents", order: 1 },
|
|
196
|
-
],
|
|
197
|
-
},
|
|
198
|
-
],
|
|
199
|
-
version: "1",
|
|
200
|
-
};
|
|
201
|
-
|
|
202
|
-
const canonicalProjectionPlan = (contextPlan = canonicalContextPlan) => ({
|
|
203
|
-
contextPlanVersion: contextPlan.version,
|
|
204
|
-
projections: [claudeAdapter, codexAdapter, cursorAdapter, openCodeAdapter].map((adapter) =>
|
|
205
|
-
normalizeHarnessProjection({
|
|
206
|
-
matrix: adapter.matrix,
|
|
207
|
-
result: project({
|
|
208
|
-
adapter,
|
|
209
|
-
contextPlan: contextPlan as Parameters<typeof project>[0]["contextPlan"],
|
|
210
|
-
}),
|
|
211
|
-
}),
|
|
212
|
-
),
|
|
213
|
-
version: "1",
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
const harnessStrings = [
|
|
217
|
-
"backend logic stays out of apps/web",
|
|
218
|
-
"transport stays out of packages/api",
|
|
219
|
-
"auth-sensitive work stays in packages/auth",
|
|
220
|
-
"update docs/README.md",
|
|
221
|
-
];
|
|
222
|
-
|
|
223
|
-
const writeFixture = async ({
|
|
224
|
-
guidanceFile,
|
|
225
|
-
projectionTransforms = {},
|
|
226
|
-
scriptSource,
|
|
227
|
-
writeContextPlan = true,
|
|
228
|
-
writeGuidance = true,
|
|
229
|
-
}: {
|
|
230
|
-
readonly guidanceFile: string;
|
|
231
|
-
readonly projectionTransforms?: Readonly<Record<string, (source: string) => string>>;
|
|
232
|
-
readonly scriptSource?: string;
|
|
233
|
-
readonly writeContextPlan?: boolean;
|
|
234
|
-
readonly writeGuidance?: boolean;
|
|
235
|
-
}): Promise<string> => {
|
|
236
|
-
const root = await mkdtemp(path.join(os.tmpdir(), "sync-subagents-"));
|
|
237
|
-
await mkdir(path.join(root, "app/backend"), { recursive: true });
|
|
238
|
-
await mkdir(path.join(root, "app/frontend"), { recursive: true });
|
|
239
|
-
await mkdir(path.join(root, "app/lambda"), { recursive: true });
|
|
240
|
-
await mkdir(path.join(root, "app/wiki"), { recursive: true });
|
|
241
|
-
await mkdir(path.join(root, "infra"), { recursive: true });
|
|
242
|
-
await mkdir(path.join(root, ".agents/scripts"), { recursive: true });
|
|
243
|
-
await mkdir(path.join(root, ".agents/skills/simplify"), { recursive: true });
|
|
244
|
-
await mkdir(path.join(root, ".agents/subagents"), { recursive: true });
|
|
245
|
-
await mkdir(path.join(root, ".devpunks"), { recursive: true });
|
|
246
|
-
if (writeGuidance) {
|
|
247
|
-
await mkdir(path.dirname(path.join(root, guidanceFile)), { recursive: true });
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
await writeFile(
|
|
251
|
-
path.join(root, ".agents/scripts/sync-subagents.mjs"),
|
|
252
|
-
scriptSource ?? (await readFile(scriptSourcePath, "utf-8")),
|
|
253
|
-
"utf-8",
|
|
254
|
-
);
|
|
255
|
-
await writeFile(path.join(root, ".agents/skills/simplify/SKILL.md"), "# Simplify\n", "utf-8");
|
|
256
|
-
await writeFile(path.join(root, ".agents/AGENTS.md"), "Shared neutral guidance\n", "utf-8");
|
|
257
|
-
if (writeContextPlan) {
|
|
258
|
-
await writeFile(
|
|
259
|
-
path.join(root, ".devpunks/context-plan.json"),
|
|
260
|
-
`${JSON.stringify(canonicalContextPlan, null, 2)}\n`,
|
|
261
|
-
"utf-8",
|
|
262
|
-
);
|
|
263
|
-
}
|
|
264
|
-
await cp(projectionSourcePath, path.join(root, ".agents/scripts/harness-projection"), {
|
|
265
|
-
recursive: true,
|
|
266
|
-
});
|
|
267
|
-
await Promise.all(
|
|
268
|
-
Object.entries(projectionTransforms).map(async ([relativePath, transform]) => {
|
|
269
|
-
const targetPath = path.join(root, ".agents/scripts/harness-projection", relativePath);
|
|
270
|
-
const source = await readFile(targetPath, "utf-8");
|
|
271
|
-
await writeFile(targetPath, transform(source), "utf-8");
|
|
272
|
-
}),
|
|
273
|
-
);
|
|
274
|
-
await writeFile(
|
|
275
|
-
path.join(root, ".agents/subagents/manifest.mjs"),
|
|
276
|
-
[
|
|
277
|
-
"const capabilityPacks = {",
|
|
278
|
-
' quality: { description: "Quality guidance pack.", skills: ["simplify"] },',
|
|
279
|
-
"};",
|
|
280
|
-
"const agents = [",
|
|
281
|
-
" {",
|
|
282
|
-
' name: "frontend-worker",',
|
|
283
|
-
' description: "Own frontend changes.",',
|
|
284
|
-
' ownedPaths: ["app/frontend", "app/frontend/**"],',
|
|
285
|
-
` guidanceFiles: [${JSON.stringify(guidanceFile)}],`,
|
|
286
|
-
' activationInstructions: ["Read scoped guidance before editing."],',
|
|
287
|
-
' packs: ["quality"],',
|
|
288
|
-
' skills: ["simplify"],',
|
|
289
|
-
' boundaries: ["Stay inside src unless parent expands scope."],',
|
|
290
|
-
" },",
|
|
291
|
-
"];",
|
|
292
|
-
"export { agents, capabilityPacks };",
|
|
293
|
-
"",
|
|
294
|
-
].join("\n"),
|
|
295
|
-
"utf-8",
|
|
296
|
-
);
|
|
297
|
-
if (writeGuidance) {
|
|
298
|
-
await writeFile(
|
|
299
|
-
path.join(root, guidanceFile),
|
|
300
|
-
[
|
|
301
|
-
"## Consumer App Guidance",
|
|
302
|
-
"",
|
|
303
|
-
"Primary skills here: `simplify`.",
|
|
304
|
-
"",
|
|
305
|
-
"Only this consumer-authored guidance should name local product boundaries.",
|
|
306
|
-
"",
|
|
307
|
-
].join("\n"),
|
|
308
|
-
"utf-8",
|
|
309
|
-
);
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
return root;
|
|
313
|
-
};
|
|
314
|
-
|
|
315
|
-
suite("sync-subagents script", () => {
|
|
316
|
-
test("keeps the CLI source Effect capability aligned across generated providers", async () => {
|
|
317
|
-
const repositoryRoot = path.resolve(import.meta.dirname, "../../../../..");
|
|
318
|
-
const manifest = (await import(
|
|
319
|
-
pathToFileURL(path.join(repositoryRoot, ".agents/subagents/manifest.mjs")).toString()
|
|
320
|
-
)) as {
|
|
321
|
-
readonly agents: readonly {
|
|
322
|
-
readonly name: string;
|
|
323
|
-
readonly skills?: readonly string[];
|
|
324
|
-
}[];
|
|
325
|
-
};
|
|
326
|
-
const cliSourceAgent = manifest.agents.find(({ name }) => name === "apps-cli-src");
|
|
327
|
-
const contextPlan = JSON.parse(
|
|
328
|
-
await readFile(path.join(repositoryRoot, ".devpunks/context-plan.json"), "utf-8"),
|
|
329
|
-
) as {
|
|
330
|
-
readonly scopes: readonly {
|
|
331
|
-
readonly contributions: readonly {
|
|
332
|
-
readonly kind: string;
|
|
333
|
-
readonly identity: { readonly id: string };
|
|
334
|
-
readonly references: readonly string[];
|
|
335
|
-
}[];
|
|
336
|
-
}[];
|
|
337
|
-
};
|
|
338
|
-
const cliSourceContribution = contextPlan.scopes
|
|
339
|
-
.flatMap(({ contributions }) => contributions)
|
|
340
|
-
.find(({ identity, kind }) => kind === "subagent-template" && identity.id === "apps-cli-src");
|
|
341
|
-
|
|
342
|
-
assertThat(cliSourceAgent?.skills).toContain("effect");
|
|
343
|
-
assertThat(cliSourceContribution?.references).toContain("effect");
|
|
344
|
-
await Promise.all(
|
|
345
|
-
[
|
|
346
|
-
".claude/agents/apps-cli-src.md",
|
|
347
|
-
".codex/agents/apps-cli-src.toml",
|
|
348
|
-
".cursor/agents/apps-cli-src.md",
|
|
349
|
-
".opencode/agents/apps-cli-src.md",
|
|
350
|
-
].map(async (relativePath) => {
|
|
351
|
-
const generatedAgent = await readFile(path.join(repositoryRoot, relativePath), "utf-8");
|
|
352
|
-
assertThat(generatedAgent).toContain("Primary skills here:");
|
|
353
|
-
assertThat(generatedAgent).toContain("`effect`");
|
|
354
|
-
}),
|
|
355
|
-
);
|
|
356
|
-
assertThat(
|
|
357
|
-
await readFile(path.join(repositoryRoot, ".claude/agents/apps-cli-src.md"), "utf-8"),
|
|
358
|
-
).toContain(" - effect\n");
|
|
359
|
-
assertThat(
|
|
360
|
-
await readFile(path.join(repositoryRoot, ".codex/agents/apps-cli-src.toml"), "utf-8"),
|
|
361
|
-
).toContain('path = "../../.agents/skills/effect"');
|
|
362
|
-
});
|
|
363
|
-
|
|
364
|
-
test("refreshes only the committed projection receipt manifest entry", async () => {
|
|
365
|
-
const root = await writeFixture({ guidanceFile: "app/frontend/AGENTS.md" });
|
|
366
|
-
await writeHarnessHooks(root);
|
|
367
|
-
const manifest = scaffoldManifest();
|
|
368
|
-
const manifestPath = await writeScaffoldManifest(root, manifest);
|
|
369
|
-
|
|
370
|
-
await execFileAsync("node", [path.join(root, ".agents/scripts/sync-subagents.mjs")], {
|
|
371
|
-
cwd: root,
|
|
372
|
-
});
|
|
373
|
-
|
|
374
|
-
const receiptBytes = await readFile(path.join(root, receiptRelativePath));
|
|
375
|
-
const receipt = JSON.parse(receiptBytes.toString("utf-8")) as { readonly status: string };
|
|
376
|
-
const persisted = JSON.parse(await readFile(manifestPath, "utf-8")) as typeof manifest;
|
|
377
|
-
assertThat(persisted).toStrictEqual({
|
|
378
|
-
...manifest,
|
|
379
|
-
managedFiles: [
|
|
380
|
-
manifest.managedFiles[0],
|
|
381
|
-
{
|
|
382
|
-
...manifest.managedFiles[1],
|
|
383
|
-
sha256: hashManagedFileContent(receiptRelativePath, receiptBytes),
|
|
384
|
-
},
|
|
385
|
-
],
|
|
386
|
-
projectionStatus: receipt.status,
|
|
387
|
-
});
|
|
388
|
-
});
|
|
389
|
-
|
|
390
|
-
test("receipts an effective project-authored subagent output change", async () => {
|
|
391
|
-
const root = await writeFixture({ guidanceFile: "app/frontend/AGENTS.md" });
|
|
392
|
-
await writeHarnessHooks(root);
|
|
393
|
-
const manifestPath = await writeScaffoldManifest(root, scaffoldManifest());
|
|
394
|
-
const scriptPath = path.join(root, ".agents/scripts/sync-subagents.mjs");
|
|
395
|
-
const contextPlanPath = path.join(root, ".devpunks/context-plan.json");
|
|
396
|
-
const subagentManifestPath = path.join(root, ".agents/subagents/manifest.mjs");
|
|
397
|
-
const fixtureManifest = (await import(pathToFileURL(subagentManifestPath).toString())) as {
|
|
398
|
-
readonly agents: readonly { readonly name: string }[];
|
|
399
|
-
};
|
|
400
|
-
const agentNames = fixtureManifest.agents.map(({ name }) => name);
|
|
401
|
-
const agentPaths = providerAgentSurfaces.flatMap(({ directory, extension }) =>
|
|
402
|
-
agentNames.map((agentName) => `${directory}/${agentName}.${extension}`),
|
|
403
|
-
);
|
|
404
|
-
|
|
405
|
-
await execFileAsync("node", [scriptPath], { cwd: root });
|
|
406
|
-
const firstReceiptBytes = await readFile(path.join(root, receiptRelativePath), "utf-8");
|
|
407
|
-
const firstReceipt = JSON.parse(firstReceiptBytes) as {
|
|
408
|
-
readonly renderedOutputSha256?: string;
|
|
409
|
-
};
|
|
410
|
-
assertThat(firstReceipt.renderedOutputSha256).toBe(
|
|
411
|
-
await emittedRenderPayloadHash(root, agentNames),
|
|
412
|
-
);
|
|
413
|
-
await execFileAsync("node", [scriptPath], { cwd: root });
|
|
414
|
-
assertThat(await readFile(path.join(root, receiptRelativePath), "utf-8")).toBe(
|
|
415
|
-
firstReceiptBytes,
|
|
416
|
-
);
|
|
417
|
-
const firstManifest = JSON.parse(await readFile(manifestPath, "utf-8")) as {
|
|
418
|
-
readonly managedFiles: readonly { readonly kind: string; readonly sha256: string }[];
|
|
419
|
-
readonly projectionStatus: string;
|
|
420
|
-
readonly [key: string]: unknown;
|
|
421
|
-
};
|
|
422
|
-
const firstGenerated = await Promise.all(
|
|
423
|
-
agentPaths.map((relativePath) => readFile(path.join(root, relativePath), "utf-8")),
|
|
424
|
-
);
|
|
425
|
-
|
|
426
|
-
const subagentManifest = await readFile(subagentManifestPath, "utf-8");
|
|
427
|
-
await writeFile(
|
|
428
|
-
subagentManifestPath,
|
|
429
|
-
subagentManifest.replace(
|
|
430
|
-
'description: "Own frontend changes.",',
|
|
431
|
-
'description: "Own focused frontend changes.",',
|
|
432
|
-
),
|
|
433
|
-
"utf-8",
|
|
434
|
-
);
|
|
435
|
-
|
|
436
|
-
await execFileAsync("node", [scriptPath], { cwd: root });
|
|
437
|
-
const secondReceiptBytes = await readFile(path.join(root, receiptRelativePath), "utf-8");
|
|
438
|
-
const secondReceipt = JSON.parse(secondReceiptBytes) as {
|
|
439
|
-
readonly renderedOutputSha256?: string;
|
|
440
|
-
};
|
|
441
|
-
const secondManifest = JSON.parse(
|
|
442
|
-
await readFile(manifestPath, "utf-8"),
|
|
443
|
-
) as typeof firstManifest;
|
|
444
|
-
const secondGenerated = await Promise.all(
|
|
445
|
-
agentPaths.map((relativePath) => readFile(path.join(root, relativePath), "utf-8")),
|
|
446
|
-
);
|
|
447
|
-
|
|
448
|
-
assertThat(secondGenerated).not.toStrictEqual(firstGenerated);
|
|
449
|
-
assertThat(secondReceipt.renderedOutputSha256).toBe(
|
|
450
|
-
await emittedRenderPayloadHash(root, agentNames),
|
|
451
|
-
);
|
|
452
|
-
assertThat(secondReceipt.renderedOutputSha256).not.toBe(firstReceipt.renderedOutputSha256);
|
|
453
|
-
assertThat(
|
|
454
|
-
secondManifest.managedFiles.find(({ kind }) => kind === "projection-receipt")?.sha256,
|
|
455
|
-
).not.toBe(
|
|
456
|
-
firstManifest.managedFiles.find(({ kind }) => kind === "projection-receipt")?.sha256,
|
|
457
|
-
);
|
|
458
|
-
assertThat({
|
|
459
|
-
...secondManifest,
|
|
460
|
-
managedFiles: secondManifest.managedFiles.filter(({ kind }) => kind !== "projection-receipt"),
|
|
461
|
-
}).toStrictEqual({
|
|
462
|
-
...firstManifest,
|
|
463
|
-
managedFiles: firstManifest.managedFiles.filter(({ kind }) => kind !== "projection-receipt"),
|
|
464
|
-
});
|
|
465
|
-
|
|
466
|
-
const contextPlan = JSON.parse(await readFile(contextPlanPath, "utf-8"));
|
|
467
|
-
await writeFile(contextPlanPath, `${JSON.stringify(contextPlan, null, 4)}\n`, "utf-8");
|
|
468
|
-
await execFileAsync("node", [scriptPath], { cwd: root });
|
|
469
|
-
assertThat(await readFile(path.join(root, receiptRelativePath), "utf-8")).toBe(
|
|
470
|
-
secondReceiptBytes,
|
|
471
|
-
);
|
|
472
|
-
});
|
|
473
|
-
|
|
474
|
-
test("receipts intentional projection failure before returning the failure", async () => {
|
|
475
|
-
const baseSource = await readFile(scriptSourcePath, "utf-8");
|
|
476
|
-
const scriptSource = baseSource.replace(
|
|
477
|
-
"filesystem: { apply: (action) => applyHarnessAction(action, application) },",
|
|
478
|
-
[
|
|
479
|
-
"filesystem: {",
|
|
480
|
-
" apply: async (action) => {",
|
|
481
|
-
' if (action.id.includes("claude:subagent-template")) throw new Error("write denied");',
|
|
482
|
-
" return applyHarnessAction(action, application);",
|
|
483
|
-
" },",
|
|
484
|
-
"},",
|
|
485
|
-
].join("\n"),
|
|
486
|
-
);
|
|
487
|
-
const root = await writeFixture({
|
|
488
|
-
guidanceFile: "app/frontend/AGENTS.md",
|
|
489
|
-
scriptSource,
|
|
490
|
-
});
|
|
491
|
-
const manifestPath = await writeScaffoldManifest(root, scaffoldManifest());
|
|
492
|
-
|
|
493
|
-
await assertThat(
|
|
494
|
-
execFileAsync("node", [path.join(root, ".agents/scripts/sync-subagents.mjs")], { cwd: root }),
|
|
495
|
-
).rejects.toThrow();
|
|
496
|
-
|
|
497
|
-
const receiptBytes = await readFile(path.join(root, receiptRelativePath));
|
|
498
|
-
const receipt = JSON.parse(receiptBytes.toString("utf-8")) as {
|
|
499
|
-
readonly renderedOutputSha256: string;
|
|
500
|
-
readonly status: string;
|
|
501
|
-
readonly projections: readonly { readonly failures: readonly unknown[] }[];
|
|
502
|
-
};
|
|
503
|
-
const manifest = JSON.parse(await readFile(manifestPath, "utf-8")) as {
|
|
504
|
-
readonly managedFiles: readonly { readonly kind: string; readonly sha256: string }[];
|
|
505
|
-
readonly projectionStatus: string;
|
|
506
|
-
};
|
|
507
|
-
// Render evidence describes the desired payload; application failure remains separate evidence.
|
|
508
|
-
assertThat(receipt.renderedOutputSha256).toMatch(/^[0-9a-f]{64}$/u);
|
|
509
|
-
assertThat(receipt.status).toBe("failure");
|
|
510
|
-
assertThat(receipt.projections.some(({ failures }) => failures.length > 0)).toBe(true);
|
|
511
|
-
assertThat(manifest.projectionStatus).toBe("failure");
|
|
512
|
-
assertThat(
|
|
513
|
-
manifest.managedFiles.find(({ kind }) => kind === "projection-receipt")?.sha256,
|
|
514
|
-
).toBe(hashManagedFileContent(receiptRelativePath, receiptBytes));
|
|
515
|
-
});
|
|
516
|
-
|
|
517
|
-
test.each([
|
|
518
|
-
["malformed", "{not-json"],
|
|
519
|
-
["missing", scaffoldManifest([])],
|
|
520
|
-
[
|
|
521
|
-
"duplicate",
|
|
522
|
-
scaffoldManifest([
|
|
523
|
-
{ kind: "projection-receipt", path: receiptRelativePath, sha256: "b".repeat(64) },
|
|
524
|
-
{ kind: "projection-receipt", path: receiptRelativePath, sha256: "c".repeat(64) },
|
|
525
|
-
]),
|
|
526
|
-
],
|
|
527
|
-
[
|
|
528
|
-
"wrong-path",
|
|
529
|
-
scaffoldManifest([
|
|
530
|
-
{ kind: "projection-receipt", path: ".devpunks/other.json", sha256: "b".repeat(64) },
|
|
531
|
-
]),
|
|
532
|
-
],
|
|
533
|
-
[
|
|
534
|
-
"ambiguous-path",
|
|
535
|
-
scaffoldManifest([
|
|
536
|
-
{ kind: "projection-receipt", path: receiptRelativePath, sha256: "b".repeat(64) },
|
|
537
|
-
{ kind: "hook", path: receiptRelativePath, sha256: "c".repeat(64) },
|
|
538
|
-
]),
|
|
539
|
-
],
|
|
540
|
-
])("rejects %s receipt manifest evidence before projection effects", async (_case, value) => {
|
|
541
|
-
const root = await writeFixture({ guidanceFile: "app/frontend/AGENTS.md" });
|
|
542
|
-
const manifestPath = path.join(root, ".devpunks/scaffold-manifest.json");
|
|
543
|
-
await writeFile(
|
|
544
|
-
manifestPath,
|
|
545
|
-
typeof value === "string" ? value : `${JSON.stringify(value, null, 4)}\n`,
|
|
546
|
-
"utf-8",
|
|
547
|
-
);
|
|
548
|
-
|
|
549
|
-
await assertThat(
|
|
550
|
-
execFileAsync("node", [path.join(root, ".agents/scripts/sync-subagents.mjs")], { cwd: root }),
|
|
551
|
-
).rejects.toThrow();
|
|
552
|
-
await assertThat(readFile(path.join(root, receiptRelativePath))).rejects.toMatchObject({
|
|
553
|
-
code: "ENOENT",
|
|
554
|
-
});
|
|
555
|
-
await assertThat(
|
|
556
|
-
readFile(path.join(root, ".codex/agents/frontend-worker.toml")),
|
|
557
|
-
).rejects.toMatchObject({ code: "ENOENT" });
|
|
558
|
-
});
|
|
559
|
-
|
|
560
|
-
test("rejects unknown ownership on every manifest entry before projection effects", async () => {
|
|
561
|
-
const root = await writeFixture({ guidanceFile: "app/frontend/AGENTS.md" });
|
|
562
|
-
const manifest = scaffoldManifest();
|
|
563
|
-
manifest.managedFiles[0] = {
|
|
564
|
-
...manifest.managedFiles[0],
|
|
565
|
-
ownership: { _tag: "UnknownOwnership" },
|
|
566
|
-
};
|
|
567
|
-
await writeScaffoldManifest(root, manifest);
|
|
568
|
-
|
|
569
|
-
await assertThat(
|
|
570
|
-
execFileAsync("node", [path.join(root, ".agents/scripts/sync-subagents.mjs")], { cwd: root }),
|
|
571
|
-
).rejects.toThrow();
|
|
572
|
-
await assertThat(readFile(path.join(root, receiptRelativePath))).rejects.toMatchObject({
|
|
573
|
-
code: "ENOENT",
|
|
574
|
-
});
|
|
575
|
-
await assertThat(
|
|
576
|
-
readFile(path.join(root, ".codex/agents/frontend-worker.toml")),
|
|
577
|
-
).rejects.toMatchObject({ code: "ENOENT" });
|
|
578
|
-
});
|
|
579
|
-
|
|
580
|
-
test.each([
|
|
581
|
-
["malformed unrelated", { _tag: "ProjectGenerated" }, 0],
|
|
582
|
-
["unknown receipt", { _tag: "UnknownOwnership" }, 1],
|
|
583
|
-
["project-generated receipt", projectGeneratedOwnership, 1],
|
|
584
|
-
])("rejects %s ownership before projection effects", async (_case, ownership, entryIndex) => {
|
|
585
|
-
const root = await writeFixture({ guidanceFile: "app/frontend/AGENTS.md" });
|
|
586
|
-
const manifest = scaffoldManifest();
|
|
587
|
-
manifest.managedFiles[entryIndex] = {
|
|
588
|
-
...manifest.managedFiles[entryIndex],
|
|
589
|
-
ownership,
|
|
590
|
-
};
|
|
591
|
-
await writeScaffoldManifest(root, manifest);
|
|
592
|
-
|
|
593
|
-
await assertThat(
|
|
594
|
-
execFileAsync("node", [path.join(root, ".agents/scripts/sync-subagents.mjs")], { cwd: root }),
|
|
595
|
-
).rejects.toThrow();
|
|
596
|
-
await assertThat(readFile(path.join(root, receiptRelativePath))).rejects.toMatchObject({
|
|
597
|
-
code: "ENOENT",
|
|
598
|
-
});
|
|
599
|
-
});
|
|
600
|
-
|
|
601
|
-
test("accepts valid unrelated ownership and exact scaffold-managed receipt ownership", async () => {
|
|
602
|
-
const root = await writeFixture({ guidanceFile: "app/frontend/AGENTS.md" });
|
|
603
|
-
await writeHarnessHooks(root);
|
|
604
|
-
const manifest = scaffoldManifest();
|
|
605
|
-
manifest.managedFiles[0] = {
|
|
606
|
-
...manifest.managedFiles[0],
|
|
607
|
-
ownership: projectGeneratedOwnership,
|
|
608
|
-
};
|
|
609
|
-
manifest.managedFiles[1] = {
|
|
610
|
-
...manifest.managedFiles[1],
|
|
611
|
-
ownership: { _tag: "ScaffoldManaged" },
|
|
612
|
-
};
|
|
613
|
-
const manifestPath = await writeScaffoldManifest(root, manifest);
|
|
614
|
-
|
|
615
|
-
await execFileAsync("node", [path.join(root, ".agents/scripts/sync-subagents.mjs")], {
|
|
616
|
-
cwd: root,
|
|
617
|
-
});
|
|
618
|
-
|
|
619
|
-
const persisted = JSON.parse(await readFile(manifestPath, "utf-8")) as typeof manifest;
|
|
620
|
-
assertThat(persisted.managedFiles[0]?.ownership).toStrictEqual(projectGeneratedOwnership);
|
|
621
|
-
assertThat(persisted.managedFiles[1]?.ownership).toStrictEqual({ _tag: "ScaffoldManaged" });
|
|
622
|
-
});
|
|
623
|
-
|
|
624
|
-
test("hashes reread committed receipt bytes with CLI semantic JSON parity", async () => {
|
|
625
|
-
const baseSource = await readFile(scriptSourcePath, "utf-8");
|
|
626
|
-
const scriptSource = baseSource.replace(
|
|
627
|
-
"await writeConfinedTextFile(projectionReceiptPath, encodeJson(receipt));",
|
|
628
|
-
"await writeConfinedTextFile(projectionReceiptPath, JSON.stringify({ projections: receipt.projections, status: receipt.status, copyFallbacks: receipt.copyFallbacks, contextPlanVersion: receipt.contextPlanVersion, renderedOutputSha256: receipt.renderedOutputSha256, version: receipt.version }));",
|
|
629
|
-
);
|
|
630
|
-
const root = await writeFixture({ guidanceFile: "app/frontend/AGENTS.md", scriptSource });
|
|
631
|
-
await writeHarnessHooks(root);
|
|
632
|
-
const manifestPath = await writeScaffoldManifest(root, scaffoldManifest());
|
|
633
|
-
|
|
634
|
-
await execFileAsync("node", [path.join(root, ".agents/scripts/sync-subagents.mjs")], {
|
|
635
|
-
cwd: root,
|
|
636
|
-
});
|
|
637
|
-
|
|
638
|
-
const receiptBytes = await readFile(path.join(root, receiptRelativePath));
|
|
639
|
-
const manifest = JSON.parse(await readFile(manifestPath, "utf-8")) as {
|
|
640
|
-
readonly managedFiles: readonly { readonly kind: string; readonly sha256: string }[];
|
|
641
|
-
};
|
|
642
|
-
assertThat(
|
|
643
|
-
manifest.managedFiles.find(({ kind }) => kind === "projection-receipt")?.sha256,
|
|
644
|
-
).toBe(hashManagedFileContent(receiptRelativePath, receiptBytes));
|
|
645
|
-
});
|
|
646
|
-
|
|
647
|
-
test("uses legacy sync only when the canonical context plan is absent", async () => {
|
|
648
|
-
const root = await writeFixture({
|
|
649
|
-
guidanceFile: "app/frontend/AGENTS.md",
|
|
650
|
-
writeContextPlan: false,
|
|
651
|
-
});
|
|
652
|
-
|
|
653
|
-
await execFileAsync("node", [path.join(root, ".agents/scripts/sync-subagents.mjs")], {
|
|
654
|
-
cwd: root,
|
|
655
|
-
});
|
|
656
|
-
|
|
657
|
-
await assertThat(
|
|
658
|
-
readFile(path.join(root, ".devpunks/harness-projection-receipt.json"), "utf-8"),
|
|
659
|
-
).rejects.toMatchObject({ code: "ENOENT" });
|
|
660
|
-
assertThat(
|
|
661
|
-
await readFile(path.join(root, ".codex/agents/frontend-worker.toml"), "utf-8"),
|
|
662
|
-
).toContain("Only this consumer-authored guidance");
|
|
663
|
-
});
|
|
664
|
-
|
|
665
|
-
test("materializes legacy output without creating a missing .devpunks parent", async () => {
|
|
666
|
-
const root = await writeFixture({
|
|
667
|
-
guidanceFile: "app/frontend/AGENTS.md",
|
|
668
|
-
writeContextPlan: false,
|
|
669
|
-
});
|
|
670
|
-
await rm(path.join(root, ".devpunks"), { recursive: true });
|
|
671
|
-
|
|
672
|
-
await execFileAsync("node", [path.join(root, ".agents/scripts/sync-subagents.mjs")], {
|
|
673
|
-
cwd: root,
|
|
674
|
-
});
|
|
675
|
-
|
|
676
|
-
await assertThat(lstat(path.join(root, ".devpunks"))).rejects.toMatchObject({ code: "ENOENT" });
|
|
677
|
-
assertThat(
|
|
678
|
-
await readFile(path.join(root, ".codex/agents/frontend-worker.toml"), "utf-8"),
|
|
679
|
-
).toContain("Only this consumer-authored guidance");
|
|
680
|
-
});
|
|
681
|
-
|
|
682
|
-
test("removes stale legacy hook mirrors when the canonical hook source disappears", async () => {
|
|
683
|
-
const root = await writeFixture({
|
|
684
|
-
guidanceFile: "app/frontend/AGENTS.md",
|
|
685
|
-
writeContextPlan: false,
|
|
686
|
-
});
|
|
687
|
-
const scriptPath = path.join(root, ".agents/scripts/sync-subagents.mjs");
|
|
688
|
-
const sourcePath = path.join(root, ".agents/hooks/format-edited-file.mjs");
|
|
689
|
-
const mirrorPaths = [
|
|
690
|
-
".claude/hooks/format-edited-file.mjs",
|
|
691
|
-
".codex/hooks/format-edited-file.mjs",
|
|
692
|
-
".cursor/hooks/format-edited-file.mjs",
|
|
693
|
-
".opencode/plugins/format-edited-file.mjs",
|
|
694
|
-
].map((relativePath) => path.join(root, relativePath));
|
|
695
|
-
await mkdir(path.dirname(sourcePath), { recursive: true });
|
|
696
|
-
await writeFile(sourcePath, "", "utf-8");
|
|
697
|
-
|
|
698
|
-
await execFileAsync("node", [scriptPath], { cwd: root });
|
|
699
|
-
await Promise.all(
|
|
700
|
-
mirrorPaths.map((mirrorPath) => assertThat(lstat(mirrorPath)).resolves.toBeDefined()),
|
|
701
|
-
);
|
|
702
|
-
|
|
703
|
-
await rm(sourcePath);
|
|
704
|
-
await execFileAsync("node", [scriptPath], { cwd: root });
|
|
705
|
-
|
|
706
|
-
await Promise.all(
|
|
707
|
-
mirrorPaths.map((mirrorPath) =>
|
|
708
|
-
assertThat(lstat(mirrorPath)).rejects.toMatchObject({ code: "ENOENT" }),
|
|
709
|
-
),
|
|
710
|
-
);
|
|
711
|
-
});
|
|
712
|
-
|
|
713
|
-
test("projects from canonical context without an explicit plan and persists deterministic neutral evidence", async () => {
|
|
714
|
-
const root = await writeFixture({ guidanceFile: "app/frontend/AGENTS.md" });
|
|
715
|
-
const staleAgent = path.join(root, ".claude/agents/stale.md");
|
|
716
|
-
await mkdir(path.join(root, ".agents/hooks"), { recursive: true });
|
|
717
|
-
await writeFile(path.join(root, ".agents/hooks/format-edited-file.mjs"), "", "utf-8");
|
|
718
|
-
await writeFile(path.join(root, ".agents/hooks/scaffold-update-check.mjs"), "", "utf-8");
|
|
719
|
-
await writeFile(
|
|
720
|
-
path.join(root, "opencode.json"),
|
|
721
|
-
JSON.stringify({
|
|
722
|
-
formatter: {
|
|
723
|
-
"harness-format-edited-file": {
|
|
724
|
-
command: ["node", ".agents/hooks/format-edited-file.mjs", "files", "$FILE"],
|
|
725
|
-
},
|
|
726
|
-
user: { command: ["echo", "$FILE"] },
|
|
727
|
-
},
|
|
728
|
-
}),
|
|
729
|
-
"utf-8",
|
|
730
|
-
);
|
|
731
|
-
await mkdir(path.dirname(staleAgent), { recursive: true });
|
|
732
|
-
await writeFile(
|
|
733
|
-
staleAgent,
|
|
734
|
-
"<!-- Generated by scripts/sync-subagents.mjs. Edit .agents/subagents/manifest.mjs instead. -->\n",
|
|
735
|
-
"utf-8",
|
|
736
|
-
);
|
|
737
|
-
|
|
738
|
-
await execFileAsync("node", [path.join(root, ".agents/scripts/sync-subagents.mjs")], {
|
|
739
|
-
cwd: root,
|
|
740
|
-
});
|
|
741
|
-
const firstReceipt = await readFile(
|
|
742
|
-
path.join(root, ".devpunks/harness-projection-receipt.json"),
|
|
743
|
-
"utf-8",
|
|
744
|
-
);
|
|
745
|
-
const firstGenerated = await Promise.all(
|
|
746
|
-
[
|
|
747
|
-
".claude/agents/frontend-worker.md",
|
|
748
|
-
".codex/agents/frontend-worker.toml",
|
|
749
|
-
".cursor/agents/frontend-worker.md",
|
|
750
|
-
".opencode/agents/frontend-worker.md",
|
|
751
|
-
].map((relativePath) => readFile(path.join(root, relativePath), "utf-8")),
|
|
752
|
-
);
|
|
753
|
-
|
|
754
|
-
await execFileAsync("node", [path.join(root, ".agents/scripts/sync-subagents.mjs")], {
|
|
755
|
-
cwd: root,
|
|
756
|
-
});
|
|
757
|
-
const secondReceipt = await readFile(
|
|
758
|
-
path.join(root, ".devpunks/harness-projection-receipt.json"),
|
|
759
|
-
"utf-8",
|
|
760
|
-
);
|
|
761
|
-
const secondGenerated = await Promise.all(
|
|
762
|
-
[
|
|
763
|
-
".claude/agents/frontend-worker.md",
|
|
764
|
-
".codex/agents/frontend-worker.toml",
|
|
765
|
-
".cursor/agents/frontend-worker.md",
|
|
766
|
-
".opencode/agents/frontend-worker.md",
|
|
767
|
-
].map((relativePath) => readFile(path.join(root, relativePath), "utf-8")),
|
|
768
|
-
);
|
|
769
|
-
const receipt = JSON.parse(secondReceipt) as {
|
|
770
|
-
readonly status: string;
|
|
771
|
-
readonly projections: readonly {
|
|
772
|
-
readonly adapter: { readonly id: string };
|
|
773
|
-
readonly matrixVersion: string;
|
|
774
|
-
readonly actions: readonly {
|
|
775
|
-
readonly operation: string;
|
|
776
|
-
readonly trace: { readonly contribution?: unknown; readonly operation?: string };
|
|
777
|
-
}[];
|
|
778
|
-
readonly warnings: readonly unknown[];
|
|
779
|
-
readonly limitations: readonly {
|
|
780
|
-
readonly _tag: string;
|
|
781
|
-
readonly trace: { readonly contribution: { readonly id: string } };
|
|
782
|
-
}[];
|
|
783
|
-
readonly omissions: readonly {
|
|
784
|
-
readonly _tag: string;
|
|
785
|
-
readonly support: string;
|
|
786
|
-
readonly trace: { readonly contribution: { readonly id: string } };
|
|
787
|
-
readonly family: string;
|
|
788
|
-
readonly reason: string;
|
|
789
|
-
}[];
|
|
790
|
-
readonly failures: readonly unknown[];
|
|
791
|
-
}[];
|
|
792
|
-
};
|
|
793
|
-
|
|
794
|
-
assertThat(secondReceipt).toBe(firstReceipt);
|
|
795
|
-
assertThat(secondGenerated).toStrictEqual(firstGenerated);
|
|
796
|
-
assertThat(receipt.status).toBe("success");
|
|
797
|
-
assertThat(receipt.projections.map(({ adapter }) => adapter.id)).toEqual([
|
|
798
|
-
"claude",
|
|
799
|
-
"codex",
|
|
800
|
-
"cursor",
|
|
801
|
-
"opencode",
|
|
802
|
-
]);
|
|
803
|
-
assertThat(receipt.projections.every(({ matrixVersion }) => matrixVersion.length > 0)).toBe(
|
|
804
|
-
true,
|
|
805
|
-
);
|
|
806
|
-
assertThat(receipt.projections.every(({ actions }) => actions.length > 0)).toBe(true);
|
|
807
|
-
assertThat(
|
|
808
|
-
receipt.projections.every(({ actions }) =>
|
|
809
|
-
actions.some(({ operation }) => operation === "cleanup-managed-agents"),
|
|
810
|
-
),
|
|
811
|
-
).toBe(true);
|
|
812
|
-
assertThat(
|
|
813
|
-
receipt.projections.every(({ actions }) =>
|
|
814
|
-
actions.every(
|
|
815
|
-
({ trace }) =>
|
|
816
|
-
trace.contribution !== undefined ||
|
|
817
|
-
trace.operation === "managed-agent-cleanup" ||
|
|
818
|
-
trace.operation === "lifecycle-hook-reconciliation",
|
|
819
|
-
),
|
|
820
|
-
),
|
|
821
|
-
).toBe(true);
|
|
822
|
-
assertThat(receipt.projections.every(({ warnings }) => warnings.length === 0)).toBe(true);
|
|
823
|
-
assertThat(receipt.projections.every(({ limitations }) => limitations.length > 0)).toBe(true);
|
|
824
|
-
assertThat(
|
|
825
|
-
receipt.projections.every(({ limitations }) =>
|
|
826
|
-
limitations.every(({ _tag }) => _tag === "HarnessCapabilityLimitation"),
|
|
827
|
-
),
|
|
828
|
-
).toBe(true);
|
|
829
|
-
assertThat(
|
|
830
|
-
receipt.projections
|
|
831
|
-
.filter(({ adapter }) => adapter.id !== "opencode")
|
|
832
|
-
.every(({ omissions }) => omissions.length === 1),
|
|
833
|
-
).toBe(true);
|
|
834
|
-
assertThat(
|
|
835
|
-
receipt.projections.find(({ adapter }) => adapter.id === "opencode")?.omissions,
|
|
836
|
-
).toContainEqual(
|
|
837
|
-
assertThat.objectContaining({
|
|
838
|
-
_tag: "HarnessProjectionOmission",
|
|
839
|
-
family: "lifecycle-hook",
|
|
840
|
-
support: "unsupported",
|
|
841
|
-
trace: assertThat.objectContaining({
|
|
842
|
-
contribution: assertThat.objectContaining({ id: "scaffold-update-check" }),
|
|
843
|
-
}),
|
|
844
|
-
}),
|
|
845
|
-
);
|
|
846
|
-
assertThat(
|
|
847
|
-
receipt.projections.find(({ adapter }) => adapter.id === "opencode")?.omissions,
|
|
848
|
-
).toHaveLength(2);
|
|
849
|
-
assertThat(receipt.projections.every(({ failures }) => failures.length === 0)).toBe(true);
|
|
850
|
-
assertThat(JSON.stringify(receipt)).not.toContain("Warning");
|
|
851
|
-
assertThat(
|
|
852
|
-
await readFile(path.join(root, ".claude/agents/frontend-worker.md"), "utf-8"),
|
|
853
|
-
).toContain("Only this consumer-authored guidance");
|
|
854
|
-
assertThat(
|
|
855
|
-
await readFile(path.join(root, ".codex/agents/frontend-worker.toml"), "utf-8"),
|
|
856
|
-
).toContain("Only this consumer-authored guidance");
|
|
857
|
-
assertThat(
|
|
858
|
-
await readFile(path.join(root, ".cursor/agents/frontend-worker.md"), "utf-8"),
|
|
859
|
-
).toContain("Only this consumer-authored guidance");
|
|
860
|
-
assertThat(
|
|
861
|
-
await readFile(path.join(root, ".opencode/agents/frontend-worker.md"), "utf-8"),
|
|
862
|
-
).toContain("Only this consumer-authored guidance");
|
|
863
|
-
const codexConfig = await readFile(path.join(root, ".codex/config.toml"), "utf-8");
|
|
864
|
-
assertThat(codexConfig).toContain("hooks = true");
|
|
865
|
-
assertThat(codexConfig).not.toContain("codex_hooks");
|
|
866
|
-
assertThat(await readFile(path.join(root, "opencode.json"), "utf-8")).not.toContain(
|
|
867
|
-
"harness-format-edited-file",
|
|
868
|
-
);
|
|
869
|
-
assertThat(await readFile(path.join(root, "opencode.json"), "utf-8")).toContain('"user"');
|
|
870
|
-
await assertThat(readFile(staleAgent, "utf-8")).rejects.toMatchObject({ code: "ENOENT" });
|
|
871
|
-
});
|
|
872
|
-
|
|
873
|
-
test("hard-fails an invalid explicit projection plan without falling back to context", async () => {
|
|
874
|
-
const root = await writeFixture({ guidanceFile: "app/frontend/AGENTS.md" });
|
|
875
|
-
const projectionPlan = path.join(root, "invalid-projection-plan.json");
|
|
876
|
-
await writeFile(
|
|
877
|
-
projectionPlan,
|
|
878
|
-
`${JSON.stringify({
|
|
879
|
-
contextPlanVersion: "1",
|
|
880
|
-
projections: [],
|
|
881
|
-
version: "1",
|
|
882
|
-
})}\n`,
|
|
883
|
-
"utf-8",
|
|
884
|
-
);
|
|
885
|
-
|
|
886
|
-
await assertThat(
|
|
887
|
-
execFileAsync("node", [path.join(root, ".agents/scripts/sync-subagents.mjs")], {
|
|
888
|
-
cwd: root,
|
|
889
|
-
env: { ...process.env, DP_HARNESS_PROJECTION_PLAN: projectionPlan },
|
|
890
|
-
}),
|
|
891
|
-
).rejects.toThrow();
|
|
892
|
-
await assertThat(
|
|
893
|
-
readFile(path.join(root, ".devpunks/harness-projection-receipt.json"), "utf-8"),
|
|
894
|
-
).rejects.toMatchObject({ code: "ENOENT" });
|
|
895
|
-
await assertThat(readFile(path.join(root, ".codex/AGENTS.md"), "utf-8")).rejects.toMatchObject({
|
|
896
|
-
code: "ENOENT",
|
|
897
|
-
});
|
|
898
|
-
});
|
|
899
|
-
|
|
900
|
-
test("hard-fails an explicit projection plan when canonical context is malformed", async () => {
|
|
901
|
-
const root = await writeFixture({ guidanceFile: "app/frontend/AGENTS.md" });
|
|
902
|
-
await writeFile(
|
|
903
|
-
path.join(root, ".devpunks/context-plan.json"),
|
|
904
|
-
`${JSON.stringify({ scopes: null })}\n`,
|
|
905
|
-
"utf-8",
|
|
906
|
-
);
|
|
907
|
-
const projectionPlan = path.join(root, "projection-plan-without-context.json");
|
|
908
|
-
await writeFile(
|
|
909
|
-
projectionPlan,
|
|
910
|
-
`${JSON.stringify(
|
|
911
|
-
{
|
|
912
|
-
contextPlanVersion: "unknown",
|
|
913
|
-
projections: [claudeAdapter, codexAdapter, cursorAdapter, openCodeAdapter].map(
|
|
914
|
-
({ matrix }) => ({
|
|
915
|
-
actions: [],
|
|
916
|
-
matrix,
|
|
917
|
-
summary: { _tag: "HarnessProjectionSuccess", applied: [] },
|
|
918
|
-
}),
|
|
919
|
-
),
|
|
920
|
-
version: "1",
|
|
921
|
-
},
|
|
922
|
-
null,
|
|
923
|
-
2,
|
|
924
|
-
)}\n`,
|
|
925
|
-
"utf-8",
|
|
926
|
-
);
|
|
927
|
-
|
|
928
|
-
await assertThat(
|
|
929
|
-
execFileAsync("node", [path.join(root, ".agents/scripts/sync-subagents.mjs")], {
|
|
930
|
-
cwd: root,
|
|
931
|
-
env: { ...process.env, DP_HARNESS_PROJECTION_PLAN: projectionPlan },
|
|
932
|
-
}),
|
|
933
|
-
).rejects.toThrow();
|
|
934
|
-
await assertThat(
|
|
935
|
-
readFile(path.join(root, ".devpunks/harness-projection-receipt.json"), "utf-8"),
|
|
936
|
-
).rejects.toMatchObject({ code: "ENOENT" });
|
|
937
|
-
await assertThat(readFile(path.join(root, ".codex/AGENTS.md"), "utf-8")).rejects.toMatchObject({
|
|
938
|
-
code: "ENOENT",
|
|
939
|
-
});
|
|
940
|
-
});
|
|
941
|
-
|
|
942
|
-
test("hard-fails an explicit projection plan containing an unknown operation", async () => {
|
|
943
|
-
const root = await writeFixture({ guidanceFile: "app/frontend/AGENTS.md" });
|
|
944
|
-
const projectionPlan = path.join(root, "invalid-operation-plan.json");
|
|
945
|
-
const plan = canonicalProjectionPlan();
|
|
946
|
-
const invalidPlan = {
|
|
947
|
-
...plan,
|
|
948
|
-
projections: plan.projections.map((projection, index) => ({
|
|
949
|
-
...projection,
|
|
950
|
-
actions: projection.actions.map((action, actionIndex) =>
|
|
951
|
-
index === 0 && actionIndex === 0 ? { ...action, operation: "delete-repository" } : action,
|
|
952
|
-
),
|
|
953
|
-
})),
|
|
954
|
-
};
|
|
955
|
-
await writeFile(projectionPlan, `${JSON.stringify(invalidPlan, null, 2)}\n`, "utf-8");
|
|
956
|
-
|
|
957
|
-
await assertThat(
|
|
958
|
-
execFileAsync("node", [path.join(root, ".agents/scripts/sync-subagents.mjs")], {
|
|
959
|
-
cwd: root,
|
|
960
|
-
env: { ...process.env, DP_HARNESS_PROJECTION_PLAN: projectionPlan },
|
|
961
|
-
}),
|
|
962
|
-
).rejects.toThrow();
|
|
963
|
-
await assertThat(
|
|
964
|
-
readFile(path.join(root, ".devpunks/harness-projection-receipt.json"), "utf-8"),
|
|
965
|
-
).rejects.toMatchObject({ code: "ENOENT" });
|
|
966
|
-
});
|
|
967
|
-
|
|
968
|
-
test("hard-fails an explicit projection plan containing an escaping path", async () => {
|
|
969
|
-
const root = await writeFixture({ guidanceFile: "app/frontend/AGENTS.md" });
|
|
970
|
-
const projectionPlan = path.join(root, "invalid-path-plan.json");
|
|
971
|
-
const plan = canonicalProjectionPlan();
|
|
972
|
-
const mirror = requireDefined(plan.projections[0]).actions.find(
|
|
973
|
-
(action) => action.operation === "mirror",
|
|
974
|
-
);
|
|
975
|
-
if (mirror === undefined) {
|
|
976
|
-
throw new Error("Missing canonical mirror action");
|
|
977
|
-
}
|
|
978
|
-
const invalidPlan = {
|
|
979
|
-
...plan,
|
|
980
|
-
projections: plan.projections.map((projection, index) => ({
|
|
981
|
-
...projection,
|
|
982
|
-
actions: projection.actions.map((action) =>
|
|
983
|
-
index === 0 && action === mirror ? { ...action, source: "../outside/AGENTS.md" } : action,
|
|
984
|
-
),
|
|
985
|
-
})),
|
|
986
|
-
};
|
|
987
|
-
await writeFile(projectionPlan, `${JSON.stringify(invalidPlan, null, 2)}\n`, "utf-8");
|
|
988
|
-
|
|
989
|
-
await assertThat(
|
|
990
|
-
execFileAsync("node", [path.join(root, ".agents/scripts/sync-subagents.mjs")], {
|
|
991
|
-
cwd: root,
|
|
992
|
-
env: { ...process.env, DP_HARNESS_PROJECTION_PLAN: projectionPlan },
|
|
993
|
-
}),
|
|
994
|
-
).rejects.toThrow();
|
|
995
|
-
await assertThat(
|
|
996
|
-
readFile(path.join(root, ".devpunks/harness-projection-receipt.json"), "utf-8"),
|
|
997
|
-
).rejects.toMatchObject({ code: "ENOENT" });
|
|
998
|
-
});
|
|
999
|
-
|
|
1000
|
-
test("hard-fails an explicit projection plan retargeted to the repository root", async () => {
|
|
1001
|
-
const root = await writeFixture({ guidanceFile: "app/frontend/AGENTS.md" });
|
|
1002
|
-
const projectionPlan = path.join(root, "root-target-plan.json");
|
|
1003
|
-
const plan = canonicalProjectionPlan();
|
|
1004
|
-
const mirror = requireDefined(
|
|
1005
|
-
plan.projections
|
|
1006
|
-
.flatMap(({ actions }) => actions)
|
|
1007
|
-
.find((action) => action.operation === "mirror"),
|
|
1008
|
-
);
|
|
1009
|
-
const invalidPlan = {
|
|
1010
|
-
...plan,
|
|
1011
|
-
projections: plan.projections.map((projection) => ({
|
|
1012
|
-
...projection,
|
|
1013
|
-
actions: projection.actions.map((action) =>
|
|
1014
|
-
action === mirror ? { ...action, target: ".codex/agents/retargeted.toml" } : action,
|
|
1015
|
-
),
|
|
1016
|
-
})),
|
|
1017
|
-
};
|
|
1018
|
-
await writeFile(projectionPlan, `${JSON.stringify(invalidPlan, null, 2)}\n`, "utf-8");
|
|
1019
|
-
|
|
1020
|
-
await assertThat(
|
|
1021
|
-
execFileAsync("node", [path.join(root, ".agents/scripts/sync-subagents.mjs")], {
|
|
1022
|
-
cwd: root,
|
|
1023
|
-
env: { ...process.env, DP_HARNESS_PROJECTION_PLAN: projectionPlan },
|
|
1024
|
-
}),
|
|
1025
|
-
).rejects.toThrow();
|
|
1026
|
-
await assertThat(
|
|
1027
|
-
readFile(path.join(root, ".devpunks/harness-projection-receipt.json"), "utf-8"),
|
|
1028
|
-
).rejects.toMatchObject({ code: "ENOENT" });
|
|
1029
|
-
});
|
|
1030
|
-
|
|
1031
|
-
test("hard-fails an explicit projection plan with a noncanonical summary", async () => {
|
|
1032
|
-
const root = await writeFixture({ guidanceFile: "app/frontend/AGENTS.md" });
|
|
1033
|
-
const projectionPlan = path.join(root, "noncanonical-summary-plan.json");
|
|
1034
|
-
const plan = canonicalProjectionPlan();
|
|
1035
|
-
const invalidPlan = {
|
|
1036
|
-
...plan,
|
|
1037
|
-
projections: plan.projections.map((projection, index) =>
|
|
1038
|
-
index === 0 && projection.summary._tag !== "HarnessProjectionFailure"
|
|
1039
|
-
? {
|
|
1040
|
-
...projection,
|
|
1041
|
-
summary: {
|
|
1042
|
-
...projection.summary,
|
|
1043
|
-
applied: projection.summary.applied.map((outcome, outcomeIndex) =>
|
|
1044
|
-
outcomeIndex === 0
|
|
1045
|
-
? { ...outcome, reason: "forged", support: "degraded" }
|
|
1046
|
-
: outcome,
|
|
1047
|
-
),
|
|
1048
|
-
},
|
|
1049
|
-
}
|
|
1050
|
-
: projection,
|
|
1051
|
-
),
|
|
1052
|
-
};
|
|
1053
|
-
await writeFile(projectionPlan, `${JSON.stringify(invalidPlan, null, 2)}\n`, "utf-8");
|
|
1054
|
-
|
|
1055
|
-
await assertThat(
|
|
1056
|
-
execFileAsync("node", [path.join(root, ".agents/scripts/sync-subagents.mjs")], {
|
|
1057
|
-
cwd: root,
|
|
1058
|
-
env: { ...process.env, DP_HARNESS_PROJECTION_PLAN: projectionPlan },
|
|
1059
|
-
}),
|
|
1060
|
-
).rejects.toThrow();
|
|
1061
|
-
await assertThat(
|
|
1062
|
-
readFile(path.join(root, ".devpunks/harness-projection-receipt.json"), "utf-8"),
|
|
1063
|
-
).rejects.toMatchObject({ code: "ENOENT" });
|
|
1064
|
-
});
|
|
1065
|
-
|
|
1066
|
-
test("hard-fails an explicit projection plan containing a mismatched action trace", async () => {
|
|
1067
|
-
const root = await writeFixture({ guidanceFile: "app/frontend/AGENTS.md" });
|
|
1068
|
-
const projectionPlan = path.join(root, "invalid-trace-plan.json");
|
|
1069
|
-
const plan = canonicalProjectionPlan();
|
|
1070
|
-
const invalidPlan = {
|
|
1071
|
-
...plan,
|
|
1072
|
-
projections: plan.projections.map((projection, index) => ({
|
|
1073
|
-
...projection,
|
|
1074
|
-
actions: projection.actions.map((action, actionIndex) =>
|
|
1075
|
-
index === 0 && actionIndex === 0
|
|
1076
|
-
? {
|
|
1077
|
-
...action,
|
|
1078
|
-
trace: {
|
|
1079
|
-
...action.trace,
|
|
1080
|
-
adapter: { ...action.trace.adapter, version: "999.0.0" },
|
|
1081
|
-
},
|
|
1082
|
-
}
|
|
1083
|
-
: action,
|
|
1084
|
-
),
|
|
1085
|
-
})),
|
|
1086
|
-
};
|
|
1087
|
-
await writeFile(projectionPlan, `${JSON.stringify(invalidPlan, null, 2)}\n`, "utf-8");
|
|
1088
|
-
|
|
1089
|
-
await assertThat(
|
|
1090
|
-
execFileAsync("node", [path.join(root, ".agents/scripts/sync-subagents.mjs")], {
|
|
1091
|
-
cwd: root,
|
|
1092
|
-
env: { ...process.env, DP_HARNESS_PROJECTION_PLAN: projectionPlan },
|
|
1093
|
-
}),
|
|
1094
|
-
).rejects.toThrow();
|
|
1095
|
-
await assertThat(
|
|
1096
|
-
readFile(path.join(root, ".devpunks/harness-projection-receipt.json"), "utf-8"),
|
|
1097
|
-
).rejects.toMatchObject({ code: "ENOENT" });
|
|
1098
|
-
});
|
|
1099
|
-
|
|
1100
|
-
test("hard-fails an explicit projection plan containing an inconsistent summary trace", async () => {
|
|
1101
|
-
const root = await writeFixture({ guidanceFile: "app/frontend/AGENTS.md" });
|
|
1102
|
-
const projectionPlan = path.join(root, "invalid-summary-plan.json");
|
|
1103
|
-
const plan = canonicalProjectionPlan();
|
|
1104
|
-
const projection = requireDefined(plan.projections[0]);
|
|
1105
|
-
const { summary } = projection;
|
|
1106
|
-
const applied =
|
|
1107
|
-
summary._tag === "HarnessProjectionFailure" ? summary.completed : summary.applied;
|
|
1108
|
-
const invalidApplied = applied.map((outcome, index) =>
|
|
1109
|
-
index === 0
|
|
1110
|
-
? {
|
|
1111
|
-
...outcome,
|
|
1112
|
-
trace: {
|
|
1113
|
-
...outcome.trace,
|
|
1114
|
-
adapter: { ...outcome.trace.adapter, version: "999.0.0" },
|
|
1115
|
-
},
|
|
1116
|
-
}
|
|
1117
|
-
: outcome,
|
|
1118
|
-
);
|
|
1119
|
-
const invalidPlan = {
|
|
1120
|
-
...plan,
|
|
1121
|
-
projections: plan.projections.map((entry, index) =>
|
|
1122
|
-
index === 0
|
|
1123
|
-
? {
|
|
1124
|
-
...entry,
|
|
1125
|
-
summary:
|
|
1126
|
-
summary._tag === "HarnessProjectionFailure"
|
|
1127
|
-
? { ...summary, completed: invalidApplied }
|
|
1128
|
-
: { ...summary, applied: invalidApplied },
|
|
1129
|
-
}
|
|
1130
|
-
: entry,
|
|
1131
|
-
),
|
|
1132
|
-
};
|
|
1133
|
-
await writeFile(projectionPlan, `${JSON.stringify(invalidPlan, null, 2)}\n`, "utf-8");
|
|
1134
|
-
|
|
1135
|
-
await assertThat(
|
|
1136
|
-
execFileAsync("node", [path.join(root, ".agents/scripts/sync-subagents.mjs")], {
|
|
1137
|
-
cwd: root,
|
|
1138
|
-
env: { ...process.env, DP_HARNESS_PROJECTION_PLAN: projectionPlan },
|
|
1139
|
-
}),
|
|
1140
|
-
).rejects.toThrow();
|
|
1141
|
-
await assertThat(
|
|
1142
|
-
readFile(path.join(root, ".devpunks/harness-projection-receipt.json"), "utf-8"),
|
|
1143
|
-
).rejects.toMatchObject({ code: "ENOENT" });
|
|
1144
|
-
});
|
|
1145
|
-
|
|
1146
|
-
test("hard-fails an explicit projection plan containing an invalid summary outcome tag", async () => {
|
|
1147
|
-
const root = await writeFixture({ guidanceFile: "app/frontend/AGENTS.md" });
|
|
1148
|
-
const projectionPlan = path.join(root, "invalid-summary-tag-plan.json");
|
|
1149
|
-
const plan = canonicalProjectionPlan();
|
|
1150
|
-
const { summary } = requireDefined(plan.projections[0]);
|
|
1151
|
-
const applied =
|
|
1152
|
-
summary._tag === "HarnessProjectionFailure" ? summary.completed : summary.applied;
|
|
1153
|
-
const invalidApplied = applied.map((outcome, index) =>
|
|
1154
|
-
index === 0 ? { ...outcome, _tag: "TrustedProjectionApplied" } : outcome,
|
|
1155
|
-
);
|
|
1156
|
-
const invalidPlan = {
|
|
1157
|
-
...plan,
|
|
1158
|
-
projections: plan.projections.map((entry, index) =>
|
|
1159
|
-
index === 0
|
|
1160
|
-
? {
|
|
1161
|
-
...entry,
|
|
1162
|
-
summary:
|
|
1163
|
-
summary._tag === "HarnessProjectionFailure"
|
|
1164
|
-
? { ...summary, completed: invalidApplied }
|
|
1165
|
-
: { ...summary, applied: invalidApplied },
|
|
1166
|
-
}
|
|
1167
|
-
: entry,
|
|
1168
|
-
),
|
|
1169
|
-
};
|
|
1170
|
-
await writeFile(projectionPlan, `${JSON.stringify(invalidPlan, null, 2)}\n`, "utf-8");
|
|
1171
|
-
|
|
1172
|
-
await assertThat(
|
|
1173
|
-
execFileAsync("node", [path.join(root, ".agents/scripts/sync-subagents.mjs")], {
|
|
1174
|
-
cwd: root,
|
|
1175
|
-
env: { ...process.env, DP_HARNESS_PROJECTION_PLAN: projectionPlan },
|
|
1176
|
-
}),
|
|
1177
|
-
).rejects.toThrow();
|
|
1178
|
-
await assertThat(
|
|
1179
|
-
readFile(path.join(root, ".devpunks/harness-projection-receipt.json"), "utf-8"),
|
|
1180
|
-
).rejects.toMatchObject({ code: "ENOENT" });
|
|
1181
|
-
});
|
|
1182
|
-
|
|
1183
|
-
test("hard-fails when explicit plan actions and applied summary traces diverge", async () => {
|
|
1184
|
-
const root = await writeFixture({ guidanceFile: "app/frontend/AGENTS.md" });
|
|
1185
|
-
const projectionPlan = path.join(root, "inconsistent-actions-summary-plan.json");
|
|
1186
|
-
const plan = canonicalProjectionPlan();
|
|
1187
|
-
const projection = requireDefined(plan.projections[0]);
|
|
1188
|
-
const { summary } = projection;
|
|
1189
|
-
const applied =
|
|
1190
|
-
summary._tag === "HarnessProjectionFailure" ? summary.completed : summary.applied;
|
|
1191
|
-
const removedTrace = requireDefined(applied[0]).trace;
|
|
1192
|
-
const remainingActions = projection.actions.filter(
|
|
1193
|
-
({ trace }) =>
|
|
1194
|
-
trace.scopeId !== removedTrace.scopeId ||
|
|
1195
|
-
trace.contribution.id !== removedTrace.contribution.id ||
|
|
1196
|
-
trace.contribution.version !== removedTrace.contribution.version,
|
|
1197
|
-
);
|
|
1198
|
-
const invalidPlan = {
|
|
1199
|
-
...plan,
|
|
1200
|
-
projections: plan.projections.map((entry, index) =>
|
|
1201
|
-
index === 0 ? { ...entry, actions: remainingActions } : entry,
|
|
1202
|
-
),
|
|
1203
|
-
};
|
|
1204
|
-
await writeFile(projectionPlan, `${JSON.stringify(invalidPlan, null, 2)}\n`, "utf-8");
|
|
1205
|
-
|
|
1206
|
-
await assertThat(
|
|
1207
|
-
execFileAsync("node", [path.join(root, ".agents/scripts/sync-subagents.mjs")], {
|
|
1208
|
-
cwd: root,
|
|
1209
|
-
env: { ...process.env, DP_HARNESS_PROJECTION_PLAN: projectionPlan },
|
|
1210
|
-
}),
|
|
1211
|
-
).rejects.toThrow();
|
|
1212
|
-
await assertThat(
|
|
1213
|
-
readFile(path.join(root, ".devpunks/harness-projection-receipt.json"), "utf-8"),
|
|
1214
|
-
).rejects.toMatchObject({ code: "ENOENT" });
|
|
1215
|
-
});
|
|
1216
|
-
|
|
1217
|
-
test("accepts real projection summaries sharing a trace identity across contribution kinds", async () => {
|
|
1218
|
-
const root = await writeFixture({ guidanceFile: "app/frontend/AGENTS.md" });
|
|
1219
|
-
const projectionPlan = path.join(root, "duplicate-kind-trace-plan.json");
|
|
1220
|
-
const contextPlan = {
|
|
1221
|
-
...canonicalContextPlan,
|
|
1222
|
-
scopes: canonicalContextPlan.scopes.map((scope) => ({
|
|
1223
|
-
...scope,
|
|
1224
|
-
contributions: scope.contributions.map((contribution) =>
|
|
1225
|
-
contribution.kind === "tool-configuration"
|
|
1226
|
-
? {
|
|
1227
|
-
...contribution,
|
|
1228
|
-
identity: { id: "simplify", version: "2026.07.17" },
|
|
1229
|
-
}
|
|
1230
|
-
: contribution,
|
|
1231
|
-
),
|
|
1232
|
-
})),
|
|
1233
|
-
};
|
|
1234
|
-
await writeFile(
|
|
1235
|
-
path.join(root, ".devpunks/context-plan.json"),
|
|
1236
|
-
`${JSON.stringify(contextPlan, null, 2)}\n`,
|
|
1237
|
-
"utf-8",
|
|
1238
|
-
);
|
|
1239
|
-
await mkdir(path.join(root, ".agents/hooks"), { recursive: true });
|
|
1240
|
-
await writeFile(path.join(root, ".agents/hooks/format-edited-file.mjs"), "", "utf-8");
|
|
1241
|
-
await writeFile(path.join(root, ".agents/hooks/scaffold-update-check.mjs"), "", "utf-8");
|
|
1242
|
-
await writeFile(
|
|
1243
|
-
projectionPlan,
|
|
1244
|
-
`${JSON.stringify(canonicalProjectionPlan(contextPlan), null, 2)}\n`,
|
|
1245
|
-
"utf-8",
|
|
1246
|
-
);
|
|
1247
|
-
|
|
1248
|
-
await execFileAsync("node", [path.join(root, ".agents/scripts/sync-subagents.mjs")], {
|
|
1249
|
-
cwd: root,
|
|
1250
|
-
env: { ...process.env, DP_HARNESS_PROJECTION_PLAN: projectionPlan },
|
|
1251
|
-
});
|
|
1252
|
-
const receipt = JSON.parse(
|
|
1253
|
-
await readFile(path.join(root, ".devpunks/harness-projection-receipt.json"), "utf-8"),
|
|
1254
|
-
) as { readonly status: string };
|
|
1255
|
-
assertThat(receipt.status).toBe("success");
|
|
1256
|
-
});
|
|
1257
|
-
|
|
1258
|
-
test("rejects subagent manifest drift before applying a persisted context plan", async () => {
|
|
1259
|
-
const root = await writeFixture({ guidanceFile: "app/frontend/AGENTS.md" });
|
|
1260
|
-
const manifestPath = path.join(root, ".agents/subagents/manifest.mjs");
|
|
1261
|
-
const manifestSource = await readFile(manifestPath, "utf-8");
|
|
1262
|
-
await writeFile(
|
|
1263
|
-
manifestPath,
|
|
1264
|
-
manifestSource.replace('skills: ["simplify"],', 'skills: ["simplify", "docs-onboarding"],'),
|
|
1265
|
-
"utf-8",
|
|
1266
|
-
);
|
|
1267
|
-
const existingAgent = path.join(root, ".codex/agents/frontend-worker.toml");
|
|
1268
|
-
await mkdir(path.dirname(existingAgent), { recursive: true });
|
|
1269
|
-
await writeFile(existingAgent, "consumer sentinel\n", "utf-8");
|
|
1270
|
-
|
|
1271
|
-
await assertThat(
|
|
1272
|
-
execFileAsync("node", [path.join(root, ".agents/scripts/sync-subagents.mjs")], { cwd: root }),
|
|
1273
|
-
).rejects.toThrow();
|
|
1274
|
-
const receipt = JSON.parse(
|
|
1275
|
-
await readFile(path.join(root, ".devpunks/harness-projection-receipt.json"), "utf-8"),
|
|
1276
|
-
) as {
|
|
1277
|
-
readonly status: string;
|
|
1278
|
-
readonly projections: readonly {
|
|
1279
|
-
readonly actions: readonly unknown[];
|
|
1280
|
-
readonly failures: readonly { readonly _tag: string; readonly message: string }[];
|
|
1281
|
-
}[];
|
|
1282
|
-
};
|
|
1283
|
-
|
|
1284
|
-
assertThat(receipt.status).toBe("failure");
|
|
1285
|
-
assertThat(receipt.projections.every(({ actions }) => actions.length === 0)).toBe(true);
|
|
1286
|
-
assertThat(
|
|
1287
|
-
receipt.projections.every(({ failures }) =>
|
|
1288
|
-
failures.some(
|
|
1289
|
-
({ _tag, message }) =>
|
|
1290
|
-
_tag === "InvalidHarnessProjectionError" &&
|
|
1291
|
-
message.includes("Subagent manifest diverges from canonical context plan"),
|
|
1292
|
-
),
|
|
1293
|
-
),
|
|
1294
|
-
).toBe(true);
|
|
1295
|
-
assertThat(await readFile(existingAgent, "utf-8")).toBe("consumer sentinel\n");
|
|
1296
|
-
});
|
|
1297
|
-
|
|
1298
|
-
test("removes lifecycle hook mirrors and managed configuration absent from the plan", async () => {
|
|
1299
|
-
const root = await writeFixture({ guidanceFile: "app/frontend/AGENTS.md" });
|
|
1300
|
-
await mkdir(path.join(root, ".agents/hooks"), { recursive: true });
|
|
1301
|
-
await writeFile(path.join(root, ".agents/hooks/format-edited-file.mjs"), "", "utf-8");
|
|
1302
|
-
await writeFile(path.join(root, ".agents/hooks/scaffold-update-check.mjs"), "", "utf-8");
|
|
1303
|
-
const scriptPath = path.join(root, ".agents/scripts/sync-subagents.mjs");
|
|
1304
|
-
|
|
1305
|
-
await execFileAsync("node", [scriptPath], { cwd: root });
|
|
1306
|
-
const withoutFormatter = structuredClone(canonicalContextPlan);
|
|
1307
|
-
const hookScope = requireDefined(withoutFormatter.scopes[1]);
|
|
1308
|
-
hookScope.contributions = hookScope.contributions.filter(
|
|
1309
|
-
({ identity }) => identity.id !== "format-edited-file",
|
|
1310
|
-
);
|
|
1311
|
-
await writeFile(
|
|
1312
|
-
path.join(root, ".devpunks/context-plan.json"),
|
|
1313
|
-
`${JSON.stringify(withoutFormatter, null, 2)}\n`,
|
|
1314
|
-
"utf-8",
|
|
1315
|
-
);
|
|
1316
|
-
|
|
1317
|
-
await execFileAsync("node", [scriptPath], { cwd: root });
|
|
1318
|
-
|
|
1319
|
-
await Promise.all(
|
|
1320
|
-
[
|
|
1321
|
-
".claude/hooks/format-edited-file.mjs",
|
|
1322
|
-
".codex/hooks/format-edited-file.mjs",
|
|
1323
|
-
".cursor/hooks/format-edited-file.mjs",
|
|
1324
|
-
".opencode/plugins/format-edited-file.mjs",
|
|
1325
|
-
".opencode/plugins/scaffold-update-check.mjs",
|
|
1326
|
-
].map((relativePath) =>
|
|
1327
|
-
assertThat(readFile(path.join(root, relativePath), "utf-8")).rejects.toMatchObject({
|
|
1328
|
-
code: "ENOENT",
|
|
1329
|
-
}),
|
|
1330
|
-
),
|
|
1331
|
-
);
|
|
1332
|
-
await Promise.all(
|
|
1333
|
-
[
|
|
1334
|
-
".claude/hooks/scaffold-update-check.mjs",
|
|
1335
|
-
".codex/hooks/scaffold-update-check.mjs",
|
|
1336
|
-
".cursor/hooks/scaffold-update-check.mjs",
|
|
1337
|
-
].map((relativePath) =>
|
|
1338
|
-
assertThat(readFile(path.join(root, relativePath), "utf-8")).resolves.toBe(""),
|
|
1339
|
-
),
|
|
1340
|
-
);
|
|
1341
|
-
assertThat(await readFile(path.join(root, ".codex/config.toml"), "utf-8")).toContain(
|
|
1342
|
-
"scaffold-update-check.mjs",
|
|
1343
|
-
);
|
|
1344
|
-
assertThat(await readFile(path.join(root, ".codex/config.toml"), "utf-8")).not.toContain(
|
|
1345
|
-
"format-edited-file.mjs",
|
|
1346
|
-
);
|
|
1347
|
-
assertThat(await readFile(path.join(root, ".claude/settings.json"), "utf-8")).toContain(
|
|
1348
|
-
"scaffold-update-check.mjs",
|
|
1349
|
-
);
|
|
1350
|
-
assertThat(await readFile(path.join(root, ".claude/settings.json"), "utf-8")).not.toContain(
|
|
1351
|
-
"format-edited-file.mjs",
|
|
1352
|
-
);
|
|
1353
|
-
assertThat(await readFile(path.join(root, ".cursor/hooks.json"), "utf-8")).toContain(
|
|
1354
|
-
"scaffold-update-check.mjs",
|
|
1355
|
-
);
|
|
1356
|
-
assertThat(await readFile(path.join(root, ".cursor/hooks.json"), "utf-8")).not.toContain(
|
|
1357
|
-
"format-edited-file.mjs",
|
|
1358
|
-
);
|
|
1359
|
-
await assertThat(readFile(path.join(root, "opencode.json"), "utf-8")).rejects.toMatchObject({
|
|
1360
|
-
code: "ENOENT",
|
|
1361
|
-
});
|
|
1362
|
-
const receipt = JSON.parse(
|
|
1363
|
-
await readFile(path.join(root, ".devpunks/harness-projection-receipt.json"), "utf-8"),
|
|
1364
|
-
) as {
|
|
1365
|
-
readonly projections: readonly {
|
|
1366
|
-
readonly actions: readonly { readonly operation: string }[];
|
|
1367
|
-
}[];
|
|
1368
|
-
};
|
|
1369
|
-
assertThat(
|
|
1370
|
-
receipt.projections.every(({ actions }) =>
|
|
1371
|
-
actions.some(({ operation }) => operation === "reconcile-lifecycle-hooks"),
|
|
1372
|
-
),
|
|
1373
|
-
).toBe(true);
|
|
1374
|
-
});
|
|
1375
|
-
|
|
1376
|
-
test("cleans managed surfaces for a valid zero-template plan with a plan-scoped trace", async () => {
|
|
1377
|
-
const root = await writeFixture({ guidanceFile: "app/frontend/AGENTS.md" });
|
|
1378
|
-
const staleAgent = path.join(root, ".claude/agents/stale.md");
|
|
1379
|
-
await mkdir(path.dirname(staleAgent), { recursive: true });
|
|
1380
|
-
await writeFile(
|
|
1381
|
-
staleAgent,
|
|
1382
|
-
"<!-- Generated by scripts/sync-subagents.mjs. Edit .agents/subagents/manifest.mjs instead. -->\n",
|
|
1383
|
-
"utf-8",
|
|
1384
|
-
);
|
|
1385
|
-
await writeFile(
|
|
1386
|
-
path.join(root, ".devpunks/context-plan.json"),
|
|
1387
|
-
'{"version":"1","scopes":[]}\n',
|
|
1388
|
-
"utf-8",
|
|
1389
|
-
);
|
|
1390
|
-
|
|
1391
|
-
await execFileAsync("node", [path.join(root, ".agents/scripts/sync-subagents.mjs")], {
|
|
1392
|
-
cwd: root,
|
|
1393
|
-
});
|
|
1394
|
-
const receipt = JSON.parse(
|
|
1395
|
-
await readFile(path.join(root, ".devpunks/harness-projection-receipt.json"), "utf-8"),
|
|
1396
|
-
) as {
|
|
1397
|
-
readonly status: string;
|
|
1398
|
-
readonly projections: readonly {
|
|
1399
|
-
readonly adapter: { readonly id: string; readonly version: string };
|
|
1400
|
-
readonly matrixVersion: string;
|
|
1401
|
-
readonly actions: readonly {
|
|
1402
|
-
readonly operation: string;
|
|
1403
|
-
readonly trace: Record<string, unknown>;
|
|
1404
|
-
}[];
|
|
1405
|
-
}[];
|
|
1406
|
-
};
|
|
1407
|
-
|
|
1408
|
-
assertThat(receipt.status).toBe("success");
|
|
1409
|
-
assertThat(receipt.projections).toHaveLength(4);
|
|
1410
|
-
for (const projection of receipt.projections) {
|
|
1411
|
-
assertThat(projection.actions).toEqual([
|
|
1412
|
-
assertThat.objectContaining({
|
|
1413
|
-
operation: "cleanup-managed-agents",
|
|
1414
|
-
trace: {
|
|
1415
|
-
adapter: projection.adapter,
|
|
1416
|
-
contextPlanVersion: "1",
|
|
1417
|
-
matrixVersion: projection.matrixVersion,
|
|
1418
|
-
operation: "managed-agent-cleanup",
|
|
1419
|
-
},
|
|
1420
|
-
}),
|
|
1421
|
-
assertThat.objectContaining({
|
|
1422
|
-
operation: "reconcile-lifecycle-hooks",
|
|
1423
|
-
trace: {
|
|
1424
|
-
adapter: projection.adapter,
|
|
1425
|
-
contextPlanVersion: "1",
|
|
1426
|
-
matrixVersion: projection.matrixVersion,
|
|
1427
|
-
operation: "lifecycle-hook-reconciliation",
|
|
1428
|
-
},
|
|
1429
|
-
}),
|
|
1430
|
-
]);
|
|
1431
|
-
for (const action of projection.actions) {
|
|
1432
|
-
assertThat(action.trace).not.toHaveProperty("contribution");
|
|
1433
|
-
assertThat(action.trace).not.toHaveProperty("scopeId");
|
|
1434
|
-
}
|
|
1435
|
-
}
|
|
1436
|
-
await assertThat(readFile(staleAgent, "utf-8")).rejects.toMatchObject({ code: "ENOENT" });
|
|
1437
|
-
});
|
|
1438
|
-
|
|
1439
|
-
test("persists typed adapter defects while retaining independent harness output", async () => {
|
|
1440
|
-
const root = await writeFixture({
|
|
1441
|
-
guidanceFile: "app/frontend/AGENTS.md",
|
|
1442
|
-
projectionTransforms: {
|
|
1443
|
-
"adapters/cursor.mjs": (source) =>
|
|
1444
|
-
source.replace(
|
|
1445
|
-
"project: cursorProject,",
|
|
1446
|
-
[
|
|
1447
|
-
"project: (input) => {",
|
|
1448
|
-
' if (input.contribution.identity.id === "simplify") throw new Error("cursor defect");',
|
|
1449
|
-
" return cursorProject(input);",
|
|
1450
|
-
"},",
|
|
1451
|
-
].join("\n"),
|
|
1452
|
-
),
|
|
1453
|
-
},
|
|
1454
|
-
});
|
|
1455
|
-
|
|
1456
|
-
await assertThat(
|
|
1457
|
-
execFileAsync("node", [path.join(root, ".agents/scripts/sync-subagents.mjs")], { cwd: root }),
|
|
1458
|
-
).rejects.toThrow();
|
|
1459
|
-
const receipt = JSON.parse(
|
|
1460
|
-
await readFile(path.join(root, ".devpunks/harness-projection-receipt.json"), "utf-8"),
|
|
1461
|
-
) as {
|
|
1462
|
-
readonly status: string;
|
|
1463
|
-
readonly projections: readonly {
|
|
1464
|
-
readonly adapter: { readonly id: string };
|
|
1465
|
-
readonly failures: readonly { readonly _tag: string }[];
|
|
1466
|
-
}[];
|
|
1467
|
-
};
|
|
1468
|
-
|
|
1469
|
-
assertThat(receipt.status).toBe("failure");
|
|
1470
|
-
assertThat(
|
|
1471
|
-
receipt.projections.find(({ adapter }) => adapter.id === "cursor")?.failures,
|
|
1472
|
-
).toContainEqual(assertThat.objectContaining({ _tag: "HarnessAdapterDefectError" }));
|
|
1473
|
-
assertThat(
|
|
1474
|
-
await readFile(path.join(root, ".claude/agents/frontend-worker.md"), "utf-8"),
|
|
1475
|
-
).toContain("Only this consumer-authored guidance");
|
|
1476
|
-
assertThat(
|
|
1477
|
-
await readFile(path.join(root, ".opencode/agents/frontend-worker.md"), "utf-8"),
|
|
1478
|
-
).toContain("Only this consumer-authored guidance");
|
|
1479
|
-
});
|
|
1480
|
-
|
|
1481
|
-
test("persists invalid matrix failures instead of degrading them", async () => {
|
|
1482
|
-
const root = await writeFixture({
|
|
1483
|
-
guidanceFile: "app/frontend/AGENTS.md",
|
|
1484
|
-
projectionTransforms: {
|
|
1485
|
-
"adapters/claude.mjs": (source) =>
|
|
1486
|
-
source.replace(
|
|
1487
|
-
'{ family: "scoped-prompt", support: "supported" },',
|
|
1488
|
-
'{ family: "skill", support: "supported" },',
|
|
1489
|
-
),
|
|
1490
|
-
},
|
|
1491
|
-
});
|
|
1492
|
-
|
|
1493
|
-
await assertThat(
|
|
1494
|
-
execFileAsync("node", [path.join(root, ".agents/scripts/sync-subagents.mjs")], { cwd: root }),
|
|
1495
|
-
).rejects.toThrow();
|
|
1496
|
-
const receipt = JSON.parse(
|
|
1497
|
-
await readFile(path.join(root, ".devpunks/harness-projection-receipt.json"), "utf-8"),
|
|
1498
|
-
) as {
|
|
1499
|
-
readonly status: string;
|
|
1500
|
-
readonly projections: readonly {
|
|
1501
|
-
readonly adapter: { readonly id: string };
|
|
1502
|
-
readonly failures: readonly { readonly _tag: string }[];
|
|
1503
|
-
}[];
|
|
1504
|
-
};
|
|
1505
|
-
|
|
1506
|
-
assertThat(receipt.status).toBe("failure");
|
|
1507
|
-
assertThat(
|
|
1508
|
-
receipt.projections.find(({ adapter }) => adapter.id === "claude")?.failures,
|
|
1509
|
-
).toContainEqual(assertThat.objectContaining({ _tag: "InvalidHarnessProjectionError" }));
|
|
1510
|
-
});
|
|
1511
|
-
|
|
1512
|
-
test("persists malformed canonical input as invalid projection evidence", async () => {
|
|
1513
|
-
const root = await writeFixture({ guidanceFile: "app/frontend/AGENTS.md" });
|
|
1514
|
-
const staleAgent = path.join(root, ".claude/agents/stale.md");
|
|
1515
|
-
await mkdir(path.dirname(staleAgent), { recursive: true });
|
|
1516
|
-
await writeFile(
|
|
1517
|
-
staleAgent,
|
|
1518
|
-
"<!-- Generated by scripts/sync-subagents.mjs. Edit .agents/subagents/manifest.mjs instead. -->\n",
|
|
1519
|
-
"utf-8",
|
|
1520
|
-
);
|
|
1521
|
-
await writeFile(
|
|
1522
|
-
path.join(root, ".devpunks/context-plan.json"),
|
|
1523
|
-
'{"version":"1","scopes":[{"id":"root"}]}\n',
|
|
1524
|
-
"utf-8",
|
|
1525
|
-
);
|
|
1526
|
-
|
|
1527
|
-
await assertThat(
|
|
1528
|
-
execFileAsync("node", [path.join(root, ".agents/scripts/sync-subagents.mjs")], { cwd: root }),
|
|
1529
|
-
).rejects.toThrow();
|
|
1530
|
-
const receipt = JSON.parse(
|
|
1531
|
-
await readFile(path.join(root, ".devpunks/harness-projection-receipt.json"), "utf-8"),
|
|
1532
|
-
) as {
|
|
1533
|
-
readonly status: string;
|
|
1534
|
-
readonly projections: readonly {
|
|
1535
|
-
readonly failures: readonly { readonly _tag: string }[];
|
|
1536
|
-
}[];
|
|
1537
|
-
};
|
|
1538
|
-
|
|
1539
|
-
assertThat(receipt.status).toBe("failure");
|
|
1540
|
-
assertThat(receipt.projections).toHaveLength(4);
|
|
1541
|
-
assertThat(
|
|
1542
|
-
receipt.projections.every(
|
|
1543
|
-
({ failures }) => failures[0]?._tag === "InvalidHarnessProjectionError",
|
|
1544
|
-
),
|
|
1545
|
-
).toBe(true);
|
|
1546
|
-
assertThat(await readFile(staleAgent, "utf-8")).toContain(
|
|
1547
|
-
"Generated by scripts/sync-subagents.mjs",
|
|
1548
|
-
);
|
|
1549
|
-
});
|
|
1550
|
-
|
|
1551
|
-
test("persists managed-agent cleanup failures as typed adapter evidence", async () => {
|
|
1552
|
-
const root = await writeFixture({ guidanceFile: "app/frontend/AGENTS.md" });
|
|
1553
|
-
await mkdir(path.join(root, ".agents/hooks"), { recursive: true });
|
|
1554
|
-
await writeFile(path.join(root, ".agents/hooks/format-edited-file.mjs"), "", "utf-8");
|
|
1555
|
-
await writeFile(path.join(root, ".agents/hooks/scaffold-update-check.mjs"), "", "utf-8");
|
|
1556
|
-
await mkdir(path.join(root, ".claude/agents/stale.md"), { recursive: true });
|
|
1557
|
-
|
|
1558
|
-
await assertThat(
|
|
1559
|
-
execFileAsync("node", [path.join(root, ".agents/scripts/sync-subagents.mjs")], { cwd: root }),
|
|
1560
|
-
).rejects.toThrow();
|
|
1561
|
-
const receipt = JSON.parse(
|
|
1562
|
-
await readFile(path.join(root, ".devpunks/harness-projection-receipt.json"), "utf-8"),
|
|
1563
|
-
) as {
|
|
1564
|
-
readonly status: string;
|
|
1565
|
-
readonly projections: readonly {
|
|
1566
|
-
readonly adapter: { readonly id: string };
|
|
1567
|
-
readonly actions: readonly { readonly operation: string }[];
|
|
1568
|
-
readonly failures: readonly { readonly _tag: string; readonly action: string }[];
|
|
1569
|
-
}[];
|
|
1570
|
-
};
|
|
1571
|
-
|
|
1572
|
-
assertThat(receipt.status).toBe("failure");
|
|
1573
|
-
const claude = receipt.projections.find(({ adapter }) => adapter.id === "claude");
|
|
1574
|
-
assertThat(claude?.actions).toContainEqual(
|
|
1575
|
-
assertThat.objectContaining({ operation: "cleanup-managed-agents" }),
|
|
1576
|
-
);
|
|
1577
|
-
assertThat(claude?.failures).toContainEqual(
|
|
1578
|
-
assertThat.objectContaining({
|
|
1579
|
-
_tag: "HarnessApplicationFailureError",
|
|
1580
|
-
action: assertThat.stringContaining("cleanup-managed-agents"),
|
|
1581
|
-
}),
|
|
1582
|
-
);
|
|
1583
|
-
assertThat(
|
|
1584
|
-
await readFile(path.join(root, ".codex/agents/frontend-worker.toml"), "utf-8"),
|
|
1585
|
-
).toContain("Only this consumer-authored guidance");
|
|
1586
|
-
});
|
|
1587
|
-
|
|
1588
|
-
test("persists a present null scope list as invalid projection evidence", async () => {
|
|
1589
|
-
const root = await writeFixture({ guidanceFile: "app/frontend/AGENTS.md" });
|
|
1590
|
-
await writeFile(
|
|
1591
|
-
path.join(root, ".devpunks/context-plan.json"),
|
|
1592
|
-
'{"version":"1","scopes":null}\n',
|
|
1593
|
-
"utf-8",
|
|
1594
|
-
);
|
|
1595
|
-
|
|
1596
|
-
await assertThat(
|
|
1597
|
-
execFileAsync("node", [path.join(root, ".agents/scripts/sync-subagents.mjs")], { cwd: root }),
|
|
1598
|
-
).rejects.toThrow();
|
|
1599
|
-
const receipt = JSON.parse(
|
|
1600
|
-
await readFile(path.join(root, ".devpunks/harness-projection-receipt.json"), "utf-8"),
|
|
1601
|
-
) as {
|
|
1602
|
-
readonly status: string;
|
|
1603
|
-
readonly projections: readonly {
|
|
1604
|
-
readonly failures: readonly { readonly _tag: string }[];
|
|
1605
|
-
}[];
|
|
1606
|
-
};
|
|
1607
|
-
|
|
1608
|
-
assertThat(receipt.status).toBe("failure");
|
|
1609
|
-
assertThat(
|
|
1610
|
-
receipt.projections.every(
|
|
1611
|
-
({ failures }) => failures[0]?._tag === "InvalidHarnessProjectionError",
|
|
1612
|
-
),
|
|
1613
|
-
).toBe(true);
|
|
1614
|
-
});
|
|
1615
|
-
|
|
1616
|
-
test("persists a null canonical plan as invalid projection evidence", async () => {
|
|
1617
|
-
const root = await writeFixture({ guidanceFile: "app/frontend/AGENTS.md" });
|
|
1618
|
-
await writeFile(path.join(root, ".devpunks/context-plan.json"), "null\n", "utf-8");
|
|
1619
|
-
|
|
1620
|
-
await assertThat(
|
|
1621
|
-
execFileAsync("node", [path.join(root, ".agents/scripts/sync-subagents.mjs")], { cwd: root }),
|
|
1622
|
-
).rejects.toThrow();
|
|
1623
|
-
const receipt = JSON.parse(
|
|
1624
|
-
await readFile(path.join(root, ".devpunks/harness-projection-receipt.json"), "utf-8"),
|
|
1625
|
-
) as {
|
|
1626
|
-
readonly contextPlanVersion: string;
|
|
1627
|
-
readonly status: string;
|
|
1628
|
-
readonly projections: readonly {
|
|
1629
|
-
readonly failures: readonly { readonly _tag: string }[];
|
|
1630
|
-
}[];
|
|
1631
|
-
};
|
|
1632
|
-
|
|
1633
|
-
assertThat(receipt).toMatchObject({ contextPlanVersion: "unknown", status: "failure" });
|
|
1634
|
-
assertThat(
|
|
1635
|
-
receipt.projections.every(
|
|
1636
|
-
({ failures }) => failures[0]?._tag === "InvalidHarnessProjectionError",
|
|
1637
|
-
),
|
|
1638
|
-
).toBe(true);
|
|
1639
|
-
});
|
|
1640
|
-
|
|
1641
|
-
test.each([
|
|
1642
|
-
[
|
|
1643
|
-
"an excess materialization field",
|
|
1644
|
-
(plan: typeof canonicalContextPlan) => {
|
|
1645
|
-
const input = structuredClone(plan) as typeof canonicalContextPlan & {
|
|
1646
|
-
scopes: (typeof canonicalContextPlan.scopes)[number][];
|
|
1647
|
-
};
|
|
1648
|
-
const scope = requireDefined(input.scopes[0]);
|
|
1649
|
-
Object.assign(requireDefined(scope.contributions[0]), { targetPath: "CLAUDE.md" });
|
|
1650
|
-
return input;
|
|
1651
|
-
},
|
|
1652
|
-
],
|
|
1653
|
-
[
|
|
1654
|
-
"a missing contribution identity version",
|
|
1655
|
-
(plan: typeof canonicalContextPlan) => {
|
|
1656
|
-
const input = structuredClone(plan) as typeof canonicalContextPlan;
|
|
1657
|
-
const scope = requireDefined(input.scopes[0]);
|
|
1658
|
-
delete (requireDefined(scope.contributions[0]).identity as { version?: string }).version;
|
|
1659
|
-
return input;
|
|
1660
|
-
},
|
|
1661
|
-
],
|
|
1662
|
-
])("rejects canonical input with %s before every adapter action", async (_label, mutate) => {
|
|
1663
|
-
const root = await writeFixture({ guidanceFile: "app/frontend/AGENTS.md" });
|
|
1664
|
-
await writeFile(
|
|
1665
|
-
path.join(root, ".devpunks/context-plan.json"),
|
|
1666
|
-
`${JSON.stringify(mutate(canonicalContextPlan), null, 2)}\n`,
|
|
1667
|
-
"utf-8",
|
|
1668
|
-
);
|
|
1669
|
-
|
|
1670
|
-
await assertThat(
|
|
1671
|
-
execFileAsync("node", [path.join(root, ".agents/scripts/sync-subagents.mjs")], { cwd: root }),
|
|
1672
|
-
).rejects.toThrow();
|
|
1673
|
-
const receipt = JSON.parse(
|
|
1674
|
-
await readFile(path.join(root, ".devpunks/harness-projection-receipt.json"), "utf-8"),
|
|
1675
|
-
) as {
|
|
1676
|
-
readonly status: string;
|
|
1677
|
-
readonly projections: readonly {
|
|
1678
|
-
readonly actions: readonly unknown[];
|
|
1679
|
-
readonly failures: readonly { readonly _tag: string }[];
|
|
1680
|
-
}[];
|
|
1681
|
-
};
|
|
1682
|
-
|
|
1683
|
-
assertThat(receipt.status).toBe("failure");
|
|
1684
|
-
assertThat(receipt.projections.every(({ actions }) => actions.length === 0)).toBe(true);
|
|
1685
|
-
assertThat(
|
|
1686
|
-
receipt.projections.every(
|
|
1687
|
-
({ failures }) => failures[0]?._tag === "InvalidHarnessProjectionError",
|
|
1688
|
-
),
|
|
1689
|
-
).toBe(true);
|
|
1690
|
-
});
|
|
1691
|
-
|
|
1692
|
-
test("persists malformed JSON as invalid projection evidence", async () => {
|
|
1693
|
-
const root = await writeFixture({ guidanceFile: "app/frontend/AGENTS.md" });
|
|
1694
|
-
await writeFile(path.join(root, ".devpunks/context-plan.json"), '{"version":', "utf-8");
|
|
1695
|
-
|
|
1696
|
-
await assertThat(
|
|
1697
|
-
execFileAsync("node", [path.join(root, ".agents/scripts/sync-subagents.mjs")], { cwd: root }),
|
|
1698
|
-
).rejects.toThrow();
|
|
1699
|
-
const receipt = JSON.parse(
|
|
1700
|
-
await readFile(path.join(root, ".devpunks/harness-projection-receipt.json"), "utf-8"),
|
|
1701
|
-
) as {
|
|
1702
|
-
readonly projections: readonly {
|
|
1703
|
-
readonly failures: readonly { readonly _tag: string }[];
|
|
1704
|
-
}[];
|
|
1705
|
-
};
|
|
1706
|
-
|
|
1707
|
-
assertThat(
|
|
1708
|
-
receipt.projections.every(
|
|
1709
|
-
({ failures }) => failures[0]?._tag === "InvalidHarnessProjectionError",
|
|
1710
|
-
),
|
|
1711
|
-
).toBe(true);
|
|
1712
|
-
});
|
|
1713
|
-
|
|
1714
|
-
test("records missing hook sources as affected-action failures while preserving valid writes", async () => {
|
|
1715
|
-
const root = await writeFixture({ guidanceFile: "app/frontend/AGENTS.md" });
|
|
1716
|
-
|
|
1717
|
-
await assertThat(
|
|
1718
|
-
execFileAsync("node", [path.join(root, ".agents/scripts/sync-subagents.mjs")], { cwd: root }),
|
|
1719
|
-
).rejects.toThrow();
|
|
1720
|
-
const receipt = JSON.parse(
|
|
1721
|
-
await readFile(path.join(root, ".devpunks/harness-projection-receipt.json"), "utf-8"),
|
|
1722
|
-
) as {
|
|
1723
|
-
readonly status: string;
|
|
1724
|
-
readonly projections: readonly {
|
|
1725
|
-
readonly adapter: { readonly id: string };
|
|
1726
|
-
readonly failures: readonly {
|
|
1727
|
-
readonly _tag: string;
|
|
1728
|
-
readonly action: string;
|
|
1729
|
-
}[];
|
|
1730
|
-
}[];
|
|
1731
|
-
};
|
|
1732
|
-
|
|
1733
|
-
assertThat(receipt.status).toBe("failure");
|
|
1734
|
-
assertThat(
|
|
1735
|
-
receipt.projections.every(({ failures }) =>
|
|
1736
|
-
failures.some(({ _tag }) => _tag === "HarnessApplicationFailureError"),
|
|
1737
|
-
),
|
|
1738
|
-
).toBe(true);
|
|
1739
|
-
assertThat(
|
|
1740
|
-
await readFile(path.join(root, ".codex/agents/frontend-worker.toml"), "utf-8"),
|
|
1741
|
-
).toContain("Only this consumer-authored guidance");
|
|
1742
|
-
assertThat(
|
|
1743
|
-
await readFile(path.join(root, ".opencode/agents/frontend-worker.md"), "utf-8"),
|
|
1744
|
-
).toContain("Only this consumer-authored guidance");
|
|
1745
|
-
});
|
|
1746
|
-
|
|
1747
|
-
test("records a missing canonical managed prompt source as an exact application failure", async () => {
|
|
1748
|
-
const root = await writeFixture({ guidanceFile: "app/frontend/AGENTS.md" });
|
|
1749
|
-
await writeHarnessHooks(root);
|
|
1750
|
-
await rm(path.join(root, ".agents/AGENTS.md"));
|
|
1751
|
-
|
|
1752
|
-
await assertThat(
|
|
1753
|
-
execFileAsync("node", [path.join(root, ".agents/scripts/sync-subagents.mjs")], { cwd: root }),
|
|
1754
|
-
).rejects.toThrow();
|
|
1755
|
-
const receipt = JSON.parse(
|
|
1756
|
-
await readFile(path.join(root, ".devpunks/harness-projection-receipt.json"), "utf-8"),
|
|
1757
|
-
) as {
|
|
1758
|
-
readonly status: string;
|
|
1759
|
-
readonly projections: readonly {
|
|
1760
|
-
readonly failures: readonly {
|
|
1761
|
-
readonly _tag: string;
|
|
1762
|
-
readonly action: string;
|
|
1763
|
-
readonly message: string;
|
|
1764
|
-
}[];
|
|
1765
|
-
readonly omissions: readonly { readonly _tag: string }[];
|
|
1766
|
-
}[];
|
|
1767
|
-
};
|
|
1768
|
-
|
|
1769
|
-
assertThat(receipt.status).toBe("failure");
|
|
1770
|
-
assertThat(
|
|
1771
|
-
receipt.projections.every(({ failures }) =>
|
|
1772
|
-
failures.some(
|
|
1773
|
-
({ _tag, action, message }) =>
|
|
1774
|
-
_tag === "HarnessApplicationFailureError" &&
|
|
1775
|
-
action.includes(":scoped-prompt:") &&
|
|
1776
|
-
message === "Missing canonical source: .agents/AGENTS.md",
|
|
1777
|
-
),
|
|
1778
|
-
),
|
|
1779
|
-
).toBe(true);
|
|
1780
|
-
assertThat(
|
|
1781
|
-
receipt.projections.every(({ omissions }) =>
|
|
1782
|
-
omissions.every(({ _tag }) => _tag !== "MissingCanonicalPromptWarning"),
|
|
1783
|
-
),
|
|
1784
|
-
).toBe(true);
|
|
1785
|
-
});
|
|
1786
|
-
|
|
1787
|
-
test("preserves consumer prompt files as silent neutral omissions instead of applied actions", async () => {
|
|
1788
|
-
const root = await writeFixture({ guidanceFile: "app/frontend/AGENTS.md" });
|
|
1789
|
-
await mkdir(path.join(root, ".agents/hooks"), { recursive: true });
|
|
1790
|
-
await writeFile(path.join(root, ".agents/hooks/format-edited-file.mjs"), "", "utf-8");
|
|
1791
|
-
await writeFile(path.join(root, ".agents/hooks/scaffold-update-check.mjs"), "", "utf-8");
|
|
1792
|
-
await mkdir(path.join(root, ".claude"), { recursive: true });
|
|
1793
|
-
await mkdir(path.join(root, ".codex"), { recursive: true });
|
|
1794
|
-
await mkdir(path.join(root, ".opencode"), { recursive: true });
|
|
1795
|
-
await writeFile(path.join(root, ".claude/CLAUDE.md"), "consumer claude\n", "utf-8");
|
|
1796
|
-
await writeFile(path.join(root, ".codex/AGENTS.md"), "consumer codex\n", "utf-8");
|
|
1797
|
-
await writeFile(path.join(root, ".opencode/AGENTS.md"), "consumer opencode\n", "utf-8");
|
|
1798
|
-
|
|
1799
|
-
await execFileAsync("node", [path.join(root, ".agents/scripts/sync-subagents.mjs")], {
|
|
1800
|
-
cwd: root,
|
|
1801
|
-
});
|
|
1802
|
-
const receipt = JSON.parse(
|
|
1803
|
-
await readFile(path.join(root, ".devpunks/harness-projection-receipt.json"), "utf-8"),
|
|
1804
|
-
) as {
|
|
1805
|
-
readonly status: string;
|
|
1806
|
-
readonly projections: readonly {
|
|
1807
|
-
readonly adapter: { readonly id: string };
|
|
1808
|
-
readonly actions: readonly { readonly id: string }[];
|
|
1809
|
-
readonly warnings: readonly unknown[];
|
|
1810
|
-
readonly omissions: readonly {
|
|
1811
|
-
readonly _tag: string;
|
|
1812
|
-
readonly support: string;
|
|
1813
|
-
readonly family: string;
|
|
1814
|
-
readonly reason: string;
|
|
1815
|
-
}[];
|
|
1816
|
-
readonly failures: readonly unknown[];
|
|
1817
|
-
}[];
|
|
1818
|
-
};
|
|
1819
|
-
|
|
1820
|
-
assertThat(receipt.status).toBe("success");
|
|
1821
|
-
assertThat(receipt.projections.every(({ warnings }) => warnings.length === 0)).toBe(true);
|
|
1822
|
-
assertThat(receipt.projections.every(({ failures }) => failures.length === 0)).toBe(true);
|
|
1823
|
-
for (const adapterId of ["claude", "codex", "opencode"]) {
|
|
1824
|
-
const projection = receipt.projections.find(({ adapter }) => adapter.id === adapterId);
|
|
1825
|
-
assertThat(projection?.actions.some(({ id }) => id.includes(":scoped-prompt:"))).toBe(false);
|
|
1826
|
-
assertThat(projection?.omissions).toContainEqual(
|
|
1827
|
-
assertThat.objectContaining({
|
|
1828
|
-
_tag: "HarnessApplicationOmission",
|
|
1829
|
-
family: "scoped-prompt",
|
|
1830
|
-
support: "preserved",
|
|
1831
|
-
}),
|
|
1832
|
-
);
|
|
1833
|
-
}
|
|
1834
|
-
assertThat(await readFile(path.join(root, ".claude/CLAUDE.md"), "utf-8")).toBe(
|
|
1835
|
-
"consumer claude\n",
|
|
1836
|
-
);
|
|
1837
|
-
assertThat(await readFile(path.join(root, ".codex/AGENTS.md"), "utf-8")).toBe(
|
|
1838
|
-
"consumer codex\n",
|
|
1839
|
-
);
|
|
1840
|
-
assertThat(await readFile(path.join(root, ".opencode/AGENTS.md"), "utf-8")).toBe(
|
|
1841
|
-
"consumer opencode\n",
|
|
1842
|
-
);
|
|
1843
|
-
});
|
|
1844
|
-
|
|
1845
|
-
test("preserves consumer prompt symlinks that do not point at the managed source", async () => {
|
|
1846
|
-
const root = await writeFixture({ guidanceFile: "app/frontend/AGENTS.md" });
|
|
1847
|
-
await mkdir(path.join(root, ".agents/hooks"), { recursive: true });
|
|
1848
|
-
await writeFile(path.join(root, ".agents/hooks/format-edited-file.mjs"), "", "utf-8");
|
|
1849
|
-
await writeFile(path.join(root, ".agents/hooks/scaffold-update-check.mjs"), "", "utf-8");
|
|
1850
|
-
await mkdir(path.join(root, ".claude"), { recursive: true });
|
|
1851
|
-
await writeFile(path.join(root, "custom-claude.md"), "consumer claude\n", "utf-8");
|
|
1852
|
-
await symlink("../custom-claude.md", path.join(root, ".claude/CLAUDE.md"));
|
|
1853
|
-
|
|
1854
|
-
await execFileAsync("node", [path.join(root, ".agents/scripts/sync-subagents.mjs")], {
|
|
1855
|
-
cwd: root,
|
|
1856
|
-
});
|
|
1857
|
-
|
|
1858
|
-
assertThat(await readlink(path.join(root, ".claude/CLAUDE.md"))).toBe("../custom-claude.md");
|
|
1859
|
-
assertThat(await readFile(path.join(root, ".claude/CLAUDE.md"), "utf-8")).toBe(
|
|
1860
|
-
"consumer claude\n",
|
|
1861
|
-
);
|
|
1862
|
-
});
|
|
1863
|
-
|
|
1864
|
-
test("records an affected-action application failure without converting it to degradation", async () => {
|
|
1865
|
-
const baseSource = await readFile(scriptSourcePath, "utf-8");
|
|
1866
|
-
const scriptSource = baseSource.replace(
|
|
1867
|
-
"filesystem: { apply: (action) => applyHarnessAction(action, application) },",
|
|
1868
|
-
[
|
|
1869
|
-
"filesystem: {",
|
|
1870
|
-
" apply: async (action) => {",
|
|
1871
|
-
' if (action.id.includes("claude:subagent-template")) throw new Error("write denied");',
|
|
1872
|
-
" return applyHarnessAction(action, application);",
|
|
1873
|
-
" },",
|
|
1874
|
-
"},",
|
|
1875
|
-
].join("\n"),
|
|
1876
|
-
);
|
|
1877
|
-
const root = await writeFixture({ guidanceFile: "app/frontend/AGENTS.md", scriptSource });
|
|
1878
|
-
|
|
1879
|
-
await assertThat(
|
|
1880
|
-
execFileAsync("node", [path.join(root, ".agents/scripts/sync-subagents.mjs")], { cwd: root }),
|
|
1881
|
-
).rejects.toThrow();
|
|
1882
|
-
const receipt = JSON.parse(
|
|
1883
|
-
await readFile(path.join(root, ".devpunks/harness-projection-receipt.json"), "utf-8"),
|
|
1884
|
-
) as {
|
|
1885
|
-
readonly status: string;
|
|
1886
|
-
readonly projections: readonly {
|
|
1887
|
-
readonly adapter: { readonly id: string };
|
|
1888
|
-
readonly failures: readonly {
|
|
1889
|
-
readonly _tag: string;
|
|
1890
|
-
readonly action: string;
|
|
1891
|
-
}[];
|
|
1892
|
-
}[];
|
|
1893
|
-
};
|
|
1894
|
-
const claude = receipt.projections.find(({ adapter }) => adapter.id === "claude");
|
|
1895
|
-
|
|
1896
|
-
assertThat(receipt.status).toBe("failure");
|
|
1897
|
-
assertThat(claude?.failures).toContainEqual(
|
|
1898
|
-
assertThat.objectContaining({
|
|
1899
|
-
_tag: "HarnessApplicationFailureError",
|
|
1900
|
-
action: assertThat.stringContaining("claude:subagent-template"),
|
|
1901
|
-
}),
|
|
1902
|
-
);
|
|
1903
|
-
assertThat(
|
|
1904
|
-
await readFile(path.join(root, ".codex/agents/frontend-worker.toml"), "utf-8"),
|
|
1905
|
-
).toContain("Only this consumer-authored guidance");
|
|
1906
|
-
});
|
|
1907
|
-
|
|
1908
|
-
test("generates prompts from authored guidance without Harness-specific defaults", async () => {
|
|
1909
|
-
const root = await writeFixture({
|
|
1910
|
-
guidanceFile: "app/frontend/AGENTS.md",
|
|
1911
|
-
writeContextPlan: false,
|
|
1912
|
-
});
|
|
1913
|
-
|
|
1914
|
-
await execFileAsync("node", [path.join(root, ".agents/scripts/sync-subagents.mjs")], {
|
|
1915
|
-
cwd: root,
|
|
1916
|
-
});
|
|
1917
|
-
|
|
1918
|
-
const generatedFiles = await Promise.all(
|
|
1919
|
-
[
|
|
1920
|
-
".codex/agents/frontend-worker.toml",
|
|
1921
|
-
".claude/agents/frontend-worker.md",
|
|
1922
|
-
".cursor/agents/frontend-worker.md",
|
|
1923
|
-
".opencode/agents/frontend-worker.md",
|
|
1924
|
-
].map((generatedFile) => readFile(path.join(root, generatedFile), "utf-8")),
|
|
1925
|
-
);
|
|
1926
|
-
|
|
1927
|
-
for (const generated of generatedFiles) {
|
|
1928
|
-
assertThat(generated).toContain("### app/frontend/AGENTS.md");
|
|
1929
|
-
assertThat(generated).toContain("Only this consumer-authored guidance");
|
|
1930
|
-
assertThat(generated).toContain(
|
|
1931
|
-
"Keep repo boundaries intact unless the parent explicitly assigns cross-surface coordination.",
|
|
1932
|
-
);
|
|
1933
|
-
for (const harnessString of harnessStrings) {
|
|
1934
|
-
assertThat(generated).not.toContain(harnessString);
|
|
1935
|
-
}
|
|
1936
|
-
}
|
|
1937
|
-
});
|
|
1938
|
-
|
|
1939
|
-
test("keeps the missing-guidance fallback in generated prompts", async () => {
|
|
1940
|
-
const root = await writeFixture({
|
|
1941
|
-
guidanceFile: "missing/AGENTS.md",
|
|
1942
|
-
writeContextPlan: false,
|
|
1943
|
-
writeGuidance: false,
|
|
1944
|
-
});
|
|
1945
|
-
|
|
1946
|
-
await execFileAsync("node", [path.join(root, ".agents/scripts/sync-subagents.mjs")], {
|
|
1947
|
-
cwd: root,
|
|
1948
|
-
});
|
|
1949
|
-
|
|
1950
|
-
const generated = await readFile(
|
|
1951
|
-
path.join(root, ".codex/agents/frontend-worker.toml"),
|
|
1952
|
-
"utf-8",
|
|
1953
|
-
);
|
|
1954
|
-
|
|
1955
|
-
assertThat(generated).toContain("Missing neutral guidance source: missing/AGENTS.md.");
|
|
1956
|
-
assertThat(generated).toContain("Author the scoped AGENTS.md file");
|
|
1957
|
-
});
|
|
1958
|
-
|
|
1959
|
-
test("preserves existing Claude settings when adding Harness hooks", async () => {
|
|
1960
|
-
const root = await writeFixture({
|
|
1961
|
-
guidanceFile: "app/frontend/AGENTS.md",
|
|
1962
|
-
writeContextPlan: false,
|
|
1963
|
-
});
|
|
1964
|
-
await mkdir(path.join(root, ".agents/hooks"), { recursive: true });
|
|
1965
|
-
await mkdir(path.join(root, ".claude"), { recursive: true });
|
|
1966
|
-
await writeFile(path.join(root, ".agents/hooks/format-edited-file.mjs"), "", "utf-8");
|
|
1967
|
-
await writeFile(path.join(root, ".agents/hooks/scaffold-update-check.mjs"), "", "utf-8");
|
|
1968
|
-
await writeFile(
|
|
1969
|
-
path.join(root, ".claude/settings.json"),
|
|
1970
|
-
JSON.stringify(
|
|
1971
|
-
{
|
|
1972
|
-
env: { KEEP_ME: "yes" },
|
|
1973
|
-
hooks: {
|
|
1974
|
-
PreToolUse: [{ hooks: [{ command: "echo keep", type: "command" }], matcher: "Bash" }],
|
|
1975
|
-
},
|
|
1976
|
-
permissions: { allow: ["Bash(bun test:*)"] },
|
|
1977
|
-
},
|
|
1978
|
-
null,
|
|
1979
|
-
2,
|
|
1980
|
-
),
|
|
1981
|
-
"utf-8",
|
|
1982
|
-
);
|
|
1983
|
-
|
|
1984
|
-
await execFileAsync("node", [path.join(root, ".agents/scripts/sync-subagents.mjs")], {
|
|
1985
|
-
cwd: root,
|
|
1986
|
-
});
|
|
1987
|
-
await execFileAsync("node", [path.join(root, ".agents/scripts/sync-subagents.mjs")], {
|
|
1988
|
-
cwd: root,
|
|
1989
|
-
});
|
|
1990
|
-
|
|
1991
|
-
const settings = JSON.parse(await readFile(path.join(root, ".claude/settings.json"), "utf-8"));
|
|
1992
|
-
|
|
1993
|
-
assertThat(settings.permissions).toEqual({ allow: ["Bash(bun test:*)"] });
|
|
1994
|
-
assertThat(settings.env).toEqual({ KEEP_ME: "yes" });
|
|
1995
|
-
assertThat(settings.hooks.PreToolUse).toEqual([
|
|
1996
|
-
{ hooks: [{ command: "echo keep", type: "command" }], matcher: "Bash" },
|
|
1997
|
-
]);
|
|
1998
|
-
assertThat(settings.hooks.SessionStart).toHaveLength(1);
|
|
1999
|
-
assertThat(settings.hooks.PostToolUse).toHaveLength(1);
|
|
2000
|
-
assertThat(settings.hooks.SessionStart[0].hooks[0].command).toContain(
|
|
2001
|
-
"scaffold-update-check.mjs claude",
|
|
2002
|
-
);
|
|
2003
|
-
assertThat(settings.hooks.PostToolUse[0].hooks[0].command).toContain(
|
|
2004
|
-
"format-edited-file.mjs claude",
|
|
2005
|
-
);
|
|
2006
|
-
});
|
|
2007
|
-
|
|
2008
|
-
test("preserves user Claude hooks colocated with Harness hooks", async () => {
|
|
2009
|
-
const root = await writeFixture({
|
|
2010
|
-
guidanceFile: "app/frontend/AGENTS.md",
|
|
2011
|
-
writeContextPlan: false,
|
|
2012
|
-
});
|
|
2013
|
-
await mkdir(path.join(root, ".agents/hooks"), { recursive: true });
|
|
2014
|
-
await mkdir(path.join(root, ".claude"), { recursive: true });
|
|
2015
|
-
await writeFile(path.join(root, ".agents/hooks/scaffold-update-check.mjs"), "", "utf-8");
|
|
2016
|
-
await writeFile(
|
|
2017
|
-
path.join(root, ".claude/settings.json"),
|
|
2018
|
-
JSON.stringify(
|
|
2019
|
-
{
|
|
2020
|
-
hooks: {
|
|
2021
|
-
PostToolUse: [
|
|
2022
|
-
{
|
|
2023
|
-
hooks: [
|
|
2024
|
-
{
|
|
2025
|
-
command:
|
|
2026
|
-
'node "$CLAUDE_PROJECT_DIR"/.claude/hooks/format-edited-file.mjs claude',
|
|
2027
|
-
type: "command",
|
|
2028
|
-
},
|
|
2029
|
-
{ command: "echo keep-post", type: "command" },
|
|
2030
|
-
],
|
|
2031
|
-
matcher: "Edit",
|
|
2032
|
-
},
|
|
2033
|
-
],
|
|
2034
|
-
SessionStart: [
|
|
2035
|
-
{
|
|
2036
|
-
hooks: [
|
|
2037
|
-
{
|
|
2038
|
-
command:
|
|
2039
|
-
'node "$CLAUDE_PROJECT_DIR"/.claude/hooks/scaffold-update-check.mjs claude',
|
|
2040
|
-
type: "command",
|
|
2041
|
-
},
|
|
2042
|
-
{ command: "echo keep-session", type: "command" },
|
|
2043
|
-
],
|
|
2044
|
-
},
|
|
2045
|
-
],
|
|
2046
|
-
},
|
|
2047
|
-
},
|
|
2048
|
-
null,
|
|
2049
|
-
2,
|
|
2050
|
-
),
|
|
2051
|
-
"utf-8",
|
|
2052
|
-
);
|
|
2053
|
-
|
|
2054
|
-
await execFileAsync("node", [path.join(root, ".agents/scripts/sync-subagents.mjs")], {
|
|
2055
|
-
cwd: root,
|
|
2056
|
-
});
|
|
2057
|
-
|
|
2058
|
-
const settings = JSON.parse(await readFile(path.join(root, ".claude/settings.json"), "utf-8"));
|
|
2059
|
-
const sessionCommands = settings.hooks.SessionStart.flatMap((entry: { hooks: unknown[] }) =>
|
|
2060
|
-
entry.hooks.map((hook) => (hook as { command?: string }).command),
|
|
2061
|
-
);
|
|
2062
|
-
const postCommands = settings.hooks.PostToolUse.flatMap((entry: { hooks: unknown[] }) =>
|
|
2063
|
-
entry.hooks.map((hook) => (hook as { command?: string }).command),
|
|
2064
|
-
);
|
|
2065
|
-
|
|
2066
|
-
assertThat(sessionCommands).toContain("echo keep-session");
|
|
2067
|
-
assertThat(
|
|
2068
|
-
sessionCommands.filter((command: string) => command?.includes("scaffold-update-check.mjs")),
|
|
2069
|
-
).toHaveLength(1);
|
|
2070
|
-
assertThat(postCommands).toEqual(["echo keep-post"]);
|
|
2071
|
-
});
|
|
2072
|
-
|
|
2073
|
-
test("copies prompt mirrors when symlink creation is not permitted", async () => {
|
|
2074
|
-
const baseSource = await readFile(scriptSourcePath, "utf-8");
|
|
2075
|
-
const scriptSource = baseSource.replace(
|
|
2076
|
-
" symlinkSync(request.linkTarget, request.target, request.type);",
|
|
2077
|
-
[
|
|
2078
|
-
' if (["AGENTS.md", "CLAUDE.md", "skills"].includes(request.target)) {',
|
|
2079
|
-
' const error = new Error("operation not permitted");',
|
|
2080
|
-
' error.code = "EPERM";',
|
|
2081
|
-
" throw error;",
|
|
2082
|
-
" }",
|
|
2083
|
-
" symlinkSync(request.linkTarget, request.target, request.type);",
|
|
2084
|
-
].join("\n"),
|
|
2085
|
-
);
|
|
2086
|
-
const root = await writeFixture({
|
|
2087
|
-
guidanceFile: "app/frontend/AGENTS.md",
|
|
2088
|
-
scriptSource,
|
|
2089
|
-
writeContextPlan: false,
|
|
2090
|
-
});
|
|
2091
|
-
|
|
2092
|
-
await execFileAsync("node", [path.join(root, ".agents/scripts/sync-subagents.mjs")], {
|
|
2093
|
-
cwd: root,
|
|
2094
|
-
});
|
|
2095
|
-
|
|
2096
|
-
const codexMirror = path.join(root, ".codex/AGENTS.md");
|
|
2097
|
-
const claudeSkillsMirror = path.join(root, ".claude/skills");
|
|
2098
|
-
|
|
2099
|
-
const codexMirrorStat = await lstat(codexMirror);
|
|
2100
|
-
assertThat(codexMirrorStat.isSymbolicLink()).toBe(false);
|
|
2101
|
-
assertThat(await readFile(codexMirror, "utf-8")).toContain("Shared neutral guidance");
|
|
2102
|
-
const claudeSkillsMirrorStat = await lstat(claudeSkillsMirror);
|
|
2103
|
-
assertThat(claudeSkillsMirrorStat.isDirectory()).toBe(true);
|
|
2104
|
-
assertThat(await readFile(path.join(claudeSkillsMirror, "simplify/SKILL.md"), "utf-8")).toBe(
|
|
2105
|
-
"# Simplify\n",
|
|
2106
|
-
);
|
|
2107
|
-
});
|
|
2108
|
-
});
|