Skip to content

Commit ed474fb

Browse files
fix(skills-sync): write only to real .agents/skills directories; require a current sync PR head (#212)
* fix(skills-sync): write only to real .agents/skills directories; require a current sync PR head The sync resolved an .agents symlink and wrote managed skills to docs/agents/skills/ in consumers that had one. Every consumer now keeps .agents as a real directory, and ADR-0026 names .agents/skills/<name>/ as the managed path. The sync now refuses a symlink at .agents, .agents/skills or a managed skill directory before it writes a file, and stages the fixed path .agents/skills. The sync pull request procedure gains a step: the head must be current with the consumer's default branch (compare behind_by 0) before the label. A sync branch cut before a consumer's layout move merged green on its old base and put a skill outside .agents/skills/ (frostyard/chairlift#273, fixed by frostyard/chairlift#276). * fix(skills-sync): name the up-to-date case of a sync rerun; pin the behind_by direction in the docs test --------- Co-authored-by: frostyard-machines <[email protected]>
1 parent 9f5cd1c commit ed474fb

8 files changed

Lines changed: 184 additions & 43 deletions

File tree

‎.agents/skills/frostyard-onboard-repo/SKILL.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,9 @@ assigning the repository to an agent's roster (Brian's decision: an ask).
108108

109109
- **The declaration count test.** A declaration PR without the
110110
`repositoryCount` bump fails core's CI.
111-
- **`.agents/skills` as a symlink.** Fine for local tools; the surface
112-
check needs a real tree. The skills sync follows an in-repository symlink
113-
(chairlift and pilothouse point `.agents` at `docs/agents`).
111+
- **`.agents/skills` as a symlink.** The surface check needs a real tree,
112+
and the skills sync refuses a symlinked `.agents` or `.agents/skills`
113+
before it writes a file: make both real directories before enrollment.
114114
- **Missing `merge_group` trigger.** Every queue entry waits for checks that
115115
never run; fix CI before the merge queue.
116116
- **Required checks that no PR produces.** Merges block until the check

‎.memory/corrections.jsonl‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@
2020
{"date": "2026-11-05", "scope": "tests", "correction": "A workflow check must tie each actions/checkout step to persist-credentials: false under its own with: mapping and ignore comments; workflow-wide counts passed a commented-out setting, and a flat step scan passed the key under env:", "evidence": "core#205, cross-review (openai/gpt-6.1-sol) of head 86a187b, finding 1", "promoted_to": "test/repository-baseline.test.mjs"}
2121
{"date": "2026-11-06", "scope": "repository-baseline", "correction": "A check that a workflow runs a command reads only the run: key of a job step (on the step's dash line or at its key indent, never under env:), never comments, step names or shell comments; a folded (>) block is 1 command and a literal (|) block is 1 command per line; a recipe command is compared whole, not as a substring; a Makefile recipe continues past blank lines and comment lines", "evidence": "core#211, cross-review (openai/gpt-6.1-sol) of heads d092fc3 (findings 1 to 3) and 1259baa (findings 1 to 3)", "promoted_to": "test/repository-baseline.test.mjs"}
2222
{"date": "2026-11-06", "scope": "skills", "correction": "A read-only Markdown checker in a skill reads the rendered prose as Markdown renders it: the prose rules (status, documentation and footer lines) ignore fenced code, a heading can have 0 to 3 leading spaces, a link is checked by its destination scheme, host and path (never by a substring), a footer link counts only for a file the tree has, and guard tests never skip when an artifact is missing; whole-file rules and the Develop make line keep the fence behavior the spec gives them", "evidence": "core#206, cross-review (openai/gpt-6.1-sol) of heads b3a1433 (findings 1 to 5) and 4a40d12 (findings 1 and 2)", "promoted_to": "test/readme-check.test.mjs"}
23+
{"date": "2026-11-06", "scope": "skills-sync", "correction": "The skills sync writes only to real directories at .agents/skills/<name>/ and refuses a symlink there, and a sync PR gets the label only when its head is current with the consumer's default branch (behind_by 0); a stale sync PR cut before a layout move merged green and put a skill outside .agents/skills/", "evidence": "frostyard/chairlift#273 and #276 (red main CI after a stale sync PR)", "promoted_to": "test/sync-skills-containment.test.mjs, test/skills-sync-docs.test.mjs, docs/design/shared-skills.md"}

‎docs/design/shared-skills.md‎

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,9 @@ cross-reviewed in core. Brian made a standing exception to the cross-review
217217
rule for it on 2026-11-01: the repository's owner handles it with a tree
218218
check instead.
219219

220-
1. Resolve the consumer's physical skills path first: `.agents/skills/`,
221-
or the in-repository target of an `.agents` symlink (chairlift and
222-
pilothouse use `docs/agents/skills/`).
220+
1. Managed skills live in real directories at `.agents/skills/<name>/`.
221+
`.agents` and `.agents/skills` are real directories too, and the sync
222+
refuses a symlink at any of them before it writes a file.
223223
2. Every file the pull request changes lies under one of that consumer's
224224
managed skill directories (`defaults` plus its extras in
225225
[skills-sync.json](../../.github/skills-sync.json)).
@@ -232,14 +232,30 @@ check instead.
232232
and `sha` for both sides. The `.synced-from-core` marker exists only on
233233
the consumer side; check it separately: its content is the 2 lines
234234
`scripts/lib/skills-sync-containment.sh` writes for that skill.
235-
4. The repository's CI is green at that head.
235+
4. The head is current with the consumer's default branch: `gh api
236+
repos/OWNER/REPO/compare/BRANCH...HEAD_SHA --jq .behind_by` prints `0`,
237+
where `BRANCH` is the default branch. The sync cuts its branch from the
238+
default branch at run time. A later commit on the default branch, for
239+
example a layout move, is not in the head, and green CI at the head does
240+
not test it. When `behind_by` is not `0`, do not add the label: run the
241+
sync again (`gh workflow run sync-skills.yml --repo frostyard/core`). When
242+
the default branch still differs from core in a managed skill, the run
243+
recreates the branch from the current default branch; then check the new
244+
head. The weekly run also does this. When the run log says
245+
`== REPO: up to date`, the default branch already holds core's managed
246+
skills: the run leaves the branch as it was, and the stale pull request
247+
is obsolete. Close it after a check that the default branch's managed
248+
trees equal core's (step 3).
249+
5. The repository's CI is green at that head.
236250

237-
When all 4 hold, the owner adds `ready-for-human`. A new push to the sync
251+
When all 5 hold, the owner adds `ready-for-human`. A new push to the sync
238252
branch (each core skill change force-updates it) means the label comes off
239-
until the check passes again at the new head. A pull request that fails the
240-
check is not edited on the reserved branch: fix core, or dispatch the sync
241-
again. Do not close a needed sync pull request: the next run creates
242-
another one.
253+
until the check passes again at the new head. In a consumer without a merge
254+
queue, a new commit on the default branch before the merge also makes step 4
255+
fail; the label comes off until a new sync run passes the check. A pull
256+
request that fails the check is not edited on the reserved branch: fix core,
257+
or dispatch the sync again. Do not close a needed sync pull request: the next
258+
run creates another one.
243259

244260
## References
245261

‎docs/design/skills-sync-operations.md‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,10 @@ receives the `@go` group in addition to the default skills: that group is
7070
([shared skills](shared-skills.md#vendored-go-skills)).
7171
`snowcat` and `snowcat-cockpit` left the list when Snowcat was retired and
7272
both repositories were archived
73-
([ADR-0064](../adr/0064-retire-snowcat.md)). A regular
74-
`.agents/` directory and a `.agents` symlink are both supported: the script
75-
resolves the physical target before writing or staging files.
73+
([ADR-0064](../adr/0064-retire-snowcat.md)). `.agents`, `.agents/skills` and
74+
each managed skill directory must be real directories: the script refuses a
75+
symlink at any of them before it writes or stages a file, and the run fails
76+
for that repository.
7677

7778
### Merge and ownership contract
7879

@@ -90,8 +91,11 @@ core commits.
9091
If the staged skill tree changed, the script recreates
9192
`chore/sync-core-skills` from the freshly cloned default branch, commits as
9293
`frostyard-core[bot] <[email protected]>`, and force-pushes that reserved
93-
branch. An existing open PR from the branch is thereby updated; otherwise the
94-
script opens one. The automation never pushes to a consumer's default branch,
94+
branch. A run that finds a change rebuilds the branch from the current
95+
default branch, so a dispatch or the weekly run brings a stale sync PR up to
96+
date. A run that finds no change (`== REPO: up to date`) leaves the branch
97+
and any open sync PR as they are; that PR is then obsolete. An existing open
98+
PR from the branch is thereby updated; otherwise the script opens one. The automation never pushes to a consumer's default branch,
9599
and the PR must pass that repository's normal review and merge gate. Human
96100
commits must not be placed on the reserved sync branch because the next run
97101
replaces it.

‎scripts/lib/skills-sync-containment.sh‎

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
# the sync's mkdir / `rsync --delete` / marker write into an escape from
88
# the temporary clone root. Every resolved destination is checked here,
99
# fail-closed, before any of those three operations run.
10+
#
11+
# The sync writes only to real directories at `.agents/skills/<name>/`
12+
# (ADR-0026): it refuses a symlink at `.agents`, at `.agents/skills`, or at
13+
# a managed skill's directory, in the clone or not.
1014
set -euo pipefail
1115

1216
# skills_sync_require_contained <root> <path> <label>
@@ -44,16 +48,31 @@ skills_sync_require_contained() {
4448
esac
4549
}
4650

51+
# skills_sync_require_real_dir <dir> <relative path>
52+
#
53+
# Refuses a symlink at <dir>/<relative path>. The sync stages, copies into
54+
# and marks real directories only (.agents/skills/<name>/), so a symlink at
55+
# any of the three managed levels is an error even when it stays inside the
56+
# clone: it puts the skill outside the path ADR-0026 names. <path> need not
57+
# exist.
58+
skills_sync_require_real_dir() {
59+
local dir="$1" rel="$2"
60+
if [ -L "${dir}/${rel}" ]; then
61+
echo "::error::${rel} is a symlink: managed skills must be real directories at .agents/skills/<name>/ (ADR-0026)" >&2
62+
return 1
63+
fi
64+
return 0
65+
}
66+
4767
# skills_sync_sync_repo <dir> <core_root> <skill...>
4868
#
4969
# Mirrors each named skill from <core_root>/.agents/skills/<skill> into
50-
# <dir>/.agents/skills/<skill> — resolving a supported in-repo `.agents`
51-
# symlink (e.g. `.agents -> docs/agents`) — and writes its
52-
# `.synced-from-core` marker. Callers must have already validated that
53-
# each skill exists under <core_root>. Returns 1 without creating any
54-
# directory, deleting any file, or writing any marker when the resolved
55-
# `.agents/skills` root or a skill's destination is not contained in
56-
# <dir>.
70+
# <dir>/.agents/skills/<skill> and writes its `.synced-from-core` marker.
71+
# Callers must have already validated that each skill exists under
72+
# <core_root>. The destinations must be real directories: the sync refuses
73+
# a symlink at `.agents`, `.agents/skills` or a managed skill's directory
74+
# (ADR-0026). Returns 1 without creating any directory, deleting any file,
75+
# or writing any marker when a destination escapes <dir> or is a symlink.
5776
skills_sync_sync_repo() {
5877
local dir="$1" core_root="$2"
5978
shift 2
@@ -72,6 +91,15 @@ skills_sync_sync_repo() {
7291
skills_sync_require_contained "$dir" "$dst" "managed-skill destination '${skill}'" || return 1
7392
done
7493

94+
# Same no-mutation rule for symbolic links: every managed path is checked
95+
# before the first mkdir, so a symlinked later skill cannot leave an
96+
# earlier skill written behind.
97+
skills_sync_require_real_dir "$dir" ".agents" || return 1
98+
skills_sync_require_real_dir "$dir" ".agents/skills" || return 1
99+
for skill in "$@"; do
100+
skills_sync_require_real_dir "$dir" ".agents/skills/${skill}" || return 1
101+
done
102+
75103
local src
76104
for skill in "$@"; do
77105
src="${core_root}/.agents/skills/${skill}"

‎scripts/lib/skills-sync-repo.sh‎

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,22 +49,14 @@ skills_sync_run_repo() {
4949
fi
5050
done
5151

52-
# Some repos (chairlift, pilothouse) have .agents as a symlink to
53-
# docs/agents — resolve to the physical dir so git pathspecs match the
54-
# files, not the symlink. skills_sync_sync_repo rejects, before any
55-
# mkdir/rsync/marker write, a resolved skills root or skill destination
56-
# that escapes the clone root (e.g. an .agents symlink pointing outside
57-
# $dir, or a pre-existing managed-skill destination symlink that does).
52+
# The sync writes only to `.agents/skills/`, as real directories.
53+
# skills_sync_sync_repo refuses, before any mkdir/rsync/marker write, a
54+
# destination that escapes the clone root or that is a symlink at
55+
# `.agents`, `.agents/skills` or a managed skill's directory (ADR-0026).
5856
if ! skills_sync_sync_repo "$dir" "$core_root" "${skills[@]}"; then
5957
echo "::error::sync failed for frostyard/${repo}" >&2
6058
return 1
6159
fi
62-
local skills_root rel_root
63-
if ! skills_root=$(realpath -m "${dir}/.agents") ||
64-
! rel_root=$(realpath -m --relative-to="$dir" "${skills_root}/skills"); then
65-
echo "::error::sync failed for frostyard/${repo}" >&2
66-
return 1
67-
fi
6860

6961
# Run the per-repo git/PR work in a subshell where every step checks its
7062
# own status. `set -e` cannot be the guard here: sync-skills.sh calls this
@@ -76,7 +68,7 @@ skills_sync_run_repo() {
7668
local rc=0
7769
(
7870
cd "$dir" || exit 1
79-
git add -A "$rel_root" || exit 1
71+
git add -A .agents/skills || exit 1
8072
# 0: nothing staged; 1: a change; anything else is a git error.
8173
diff_rc=0
8274
git diff --cached --quiet || diff_rc=$?

‎test/skills-sync-docs.test.mjs‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import assert from "node:assert/strict";
2+
import { readFile } from "node:fs/promises";
3+
import path from "node:path";
4+
import test from "node:test";
5+
import { fileURLToPath } from "node:url";
6+
7+
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
8+
9+
// Every surface that describes the sync's destination. `.agents/skills/<name>/`
10+
// is the only managed path (ADR-0026), so the retired `docs/agents` layout must
11+
// not come back as an alternative in any of them.
12+
const FILES = [
13+
"docs/design/shared-skills.md",
14+
"docs/design/skills-sync-operations.md",
15+
".agents/skills/frostyard-onboard-repo/SKILL.md",
16+
"scripts/lib/skills-sync-repo.sh",
17+
"scripts/lib/skills-sync-containment.sh",
18+
];
19+
20+
test("no sync surface names the retired docs/agents layout", async () => {
21+
for (const file of FILES) {
22+
const text = await readFile(path.join(root, file), "utf8");
23+
assert.equal(text.includes("docs/agents"), false, `${file} names docs/agents`);
24+
}
25+
});
26+
27+
test("the sync pull request procedure requires a head current with the default branch", async () => {
28+
const text = await readFile(path.join(root, "docs/design/shared-skills.md"), "utf8");
29+
const lines = text.split("\n");
30+
const start = lines.findIndex((line) => line.trim() === "### Handling a sync pull request");
31+
assert.notEqual(start, -1, "missing the '### Handling a sync pull request' heading");
32+
let end = lines.length;
33+
for (let i = start + 1; i < lines.length; i += 1) {
34+
if (/^#{1,6} /.test(lines[i])) {
35+
end = i;
36+
break;
37+
}
38+
}
39+
assert.ok(end > start + 1, "the section is empty");
40+
// Prose wraps: compare with every run of whitespace as 1 space.
41+
const section = lines.slice(start, end).join("\n").replace(/\s+/g, " ");
42+
// The head is compared against the default branch (BRANCH...HEAD_SHA, not
43+
// the reverse), and only behind_by 0 passes.
44+
assert.ok(
45+
section.includes("compare/BRANCH...HEAD_SHA --jq .behind_by` prints `0`"),
46+
"the procedure must require behind_by 0 for compare/BRANCH...HEAD_SHA",
47+
);
48+
assert.ok(
49+
section.includes("When `behind_by` is not `0`, do not add the label"),
50+
"the procedure must withhold the label when the head is behind",
51+
);
52+
assert.ok(section.includes("gh workflow run sync-skills.yml --repo frostyard/core"));
53+
});

‎test/sync-skills-containment.test.mjs‎

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,20 +94,67 @@ test("syncs a skill into a normal .agents directory", async () => {
9494
assert.equal(synced, "# Example\n");
9595
});
9696

97-
test("syncs a skill through an in-repository .agents -> docs/agents symlink", async () => {
97+
test("rejects an in-repository .agents -> docs/agents symlink", async () => {
9898
const { dir, coreRoot } = await createFixture();
9999
await mkdir(path.join(dir, "docs/agents"), { recursive: true });
100100
await symlink("docs/agents", path.join(dir, ".agents"), "dir");
101101

102-
await runSyncRepo(dir, coreRoot, ["example"]);
102+
await assert.rejects(
103+
runSyncRepo(dir, coreRoot, ["example"]),
104+
(error) => assertSymlinkRefusal(error, ".agents"),
105+
);
106+
assert.deepEqual(await readdir(path.join(dir, "docs/agents")), []);
107+
});
103108

104-
const marker = await readFile(
105-
path.join(dir, "docs/agents/skills/example/.synced-from-core"),
106-
"utf8",
109+
test("rejects an in-repository .agents/skills -> ../docs/skills symlink", async () => {
110+
const { dir, coreRoot } = await createFixture();
111+
await mkdir(path.join(dir, ".agents"), { recursive: true });
112+
await mkdir(path.join(dir, "docs/skills"), { recursive: true });
113+
await symlink("../docs/skills", path.join(dir, ".agents/skills"), "dir");
114+
115+
await assert.rejects(
116+
runSyncRepo(dir, coreRoot, ["example"]),
117+
(error) => assertSymlinkRefusal(error, ".agents/skills"),
107118
);
108-
assert.match(marker, /Managed by frostyard\/core/);
119+
assert.deepEqual(await readdir(path.join(dir, "docs/skills")), []);
120+
});
121+
122+
test("rejects an in-repository managed-skill symlink", async () => {
123+
const { dir, coreRoot } = await createFixture();
124+
await mkdir(path.join(dir, ".agents/skills"), { recursive: true });
125+
await mkdir(path.join(dir, "docs/example"), { recursive: true });
126+
await symlink("../../docs/example", path.join(dir, ".agents/skills/example"), "dir");
127+
128+
await assert.rejects(
129+
runSyncRepo(dir, coreRoot, ["example"]),
130+
(error) => assertSymlinkRefusal(error, ".agents/skills/example"),
131+
);
132+
assert.deepEqual(await readdir(path.join(dir, "docs/example")), []);
109133
});
110134

135+
test("rejects a later symlinked destination without creating an earlier valid one", async () => {
136+
const { dir, coreRoot } = await createFixture();
137+
await mkdir(path.join(coreRoot, ".agents/skills/second"), { recursive: true });
138+
await writeFile(path.join(coreRoot, ".agents/skills/second/SKILL.md"), "# Second\n");
139+
await mkdir(path.join(dir, ".agents/skills"), { recursive: true });
140+
await mkdir(path.join(dir, "docs/second"), { recursive: true });
141+
await symlink("../../docs/second", path.join(dir, ".agents/skills/second"), "dir");
142+
143+
await assert.rejects(
144+
runSyncRepo(dir, coreRoot, ["example", "second"]),
145+
(error) => assertSymlinkRefusal(error, ".agents/skills/second"),
146+
);
147+
assert.deepEqual(await readdir(path.join(dir, "docs/second")), []);
148+
await assert.rejects(readdir(path.join(dir, ".agents/skills/example")));
149+
});
150+
151+
function assertSymlinkRefusal(error, relPath) {
152+
assert.equal(error.code, 1);
153+
assert.match(error.stderr, /is a symlink: managed skills must be real directories/);
154+
assert.ok(error.stderr.includes(`${relPath} is a symlink`), error.stderr);
155+
return true;
156+
}
157+
111158
async function createFixture() {
112159
const base = await mkdtemp(path.join(os.tmpdir(), "sync-skills-containment-"));
113160
const dir = path.join(base, "clone");

0 commit comments

Comments
 (0)