@se-studio/skills 1.10.25 → 1.13.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/CHANGELOG.md +37 -0
- package/agent-guard/README.md +23 -0
- package/agent-guard/bin.mjs +2 -0
- package/agent-guard/doctor.mjs +367 -0
- package/agent-guard/rules.mjs +1 -1
- package/agent-guard/skill-links.mjs +130 -0
- package/package.json +1 -1
- package/references/agent-session/customer-guardrails/README.md +1 -1
- package/references/agent-session/fleet-audit.mjs +106 -22
- package/references/deployment-smoke-feature-branch-skip/README.md +2 -21
- package/references/lockfile-sync/README.md +1 -1
- package/skills/coding-discipline/SKILL.md +18 -18
- package/skills/contentful-cms-generate-cms-guidelines/SKILL.md +1 -1
- package/skills/contentful-cms-regenerate-editor-pack/SKILL.md +11 -21
- package/skills/contentful-cms-schema-audit/SKILL.md +2 -2
- package/skills/contentful-cms-update-cms-guidelines/SKILL.md +1 -1
- package/skills/screaming-frog-audit/SKILL.md +31 -2
- package/skills/screaming-frog-audit/references/profiles.md +2 -2
- package/skills/se-marketing-sites-customer-simplicity/SKILL.md +1 -0
- package/skills/se-marketing-sites-markdown-accuracy-review/SKILL.md +2 -2
- package/skills/se-marketing-sites-redirects/SKILL.md +67 -7
- package/skills/se-marketing-sites-smoke-test-setup/SKILL.md +1 -1
- package/skills/site-workflows-agent-session/SKILL.md +1 -1
- package/skills/site-workflows-deps-update/SKILL.md +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,42 @@
|
|
|
1
1
|
# @se-studio/skills
|
|
2
2
|
|
|
3
|
+
## 1.13.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- cd4c17c: Redirects skill: `skeleton:check` now enforces the live redirect path (the redirects-sync route and sitemap routes that call `getRedirectMap`), and the rollout checks can be skipped only with an expiry date and owner. PHILOSOPHY R6.9 to R6.11 (live redirects, the fail-closed sync route, project-scoped credentials) are approved.
|
|
8
|
+
|
|
9
|
+
## 1.13.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- 24262f4: `fleet-audit` flags a site that still carries a local `scripts/check-cms-driven.mjs`, a `cms-driven.baseline.json` with more than 25 violations ("needs work"), and a baseline that has not changed in 90 days with debt still in it.
|
|
14
|
+
- 4163446: `fleet-audit` lists sites in remake mode with their deadline and flags a remake window that has passed but is still in `cms-driven.config.json`. The customer-simplicity skill points at the new `check-cms-driven` R3/R4 enforcement.
|
|
15
|
+
|
|
16
|
+
## 1.12.0
|
|
17
|
+
|
|
18
|
+
### Minor Changes
|
|
19
|
+
|
|
20
|
+
- dfa21ee: New `se-agent-guard doctor`: checks that a checkout is actually protected. It runs the guard-health checks from `fleet-audit` on the working tree and adds local-only ones: missing `node_modules`, installed version differs from the exact pin (or not installed), git not running the shipped hooks (or a hook not executable), the guard bin missing, dangling skill links in `.agents/skills` and the per-agent directories, stale copied skills left by `skills add`, and broken relative links in installed or repo-owned skills (resolved from the skill's real location). Exit 0 healthy, 1 problems, 2 could not run. It reads only small regular files whose real path stays under the repo or its `node_modules`, so a hostile repo can neither hang it with a device or FIFO symlink nor make it read files outside the repo. It reads `CI` the same way the guard does. `fleet-audit`'s file selection is now the exported `wantedPaths`, shared with the doctor.
|
|
21
|
+
|
|
22
|
+
## 1.11.0
|
|
23
|
+
|
|
24
|
+
### Minor Changes
|
|
25
|
+
|
|
26
|
+
- 3b685dd: `pnpm skills:validate` now fails on broken relative links in every markdown file of a skill (`SKILL.md` and nested references). A link must point at a file with exactly matching case, and a link in a published skill must point at something the package actually ships (its `files` list: `skills`, `references`, `agent-guard`, root `*.md`), so a core-repo path or a `core-only` skill can never be linked. The checker (`agent-guard/skill-links.mjs`) skips URLs, anchors, templates and code, and reports a malformed `%` escape as a broken link instead of crashing. Fixes two wrong paths and turns core-repo paths in `coding-discipline` and five other skills (plus one directory link) into plain code text.
|
|
27
|
+
|
|
28
|
+
## 1.10.27
|
|
29
|
+
|
|
30
|
+
### Patch Changes
|
|
31
|
+
|
|
32
|
+
- f8adb5d: Add Screaming Frog 25 JSON profiles for a quick production check, a thorough metadata and social check, and a production-versus-develop compare. The weekly fleet crawl uses the thorough profile and no longer depends on the old binary config files.
|
|
33
|
+
|
|
34
|
+
## 1.10.26
|
|
35
|
+
|
|
36
|
+
### Patch Changes
|
|
37
|
+
|
|
38
|
+
- db5d98b: Document that customer cms-edit MCP runs on the shared cms-edit-host. Editor-pack regen no longer scaffolds or deploys a per-site host.
|
|
39
|
+
|
|
3
40
|
## 1.10.25
|
|
4
41
|
|
|
5
42
|
### Patch Changes
|
package/agent-guard/README.md
CHANGED
|
@@ -30,6 +30,29 @@ Grok and Cursor rely on the git hooks and the CI audit. Add thin adapters that c
|
|
|
30
30
|
- For `gh pr merge`, checks **every** merge in the command against the merge gate. Any failure denies. If `gh` cannot be reached it asks. When all pass it allows without asking: the approval comment is the confirmation.
|
|
31
31
|
- A malformed hook payload exits 0 (never breaks the session).
|
|
32
32
|
|
|
33
|
+
## Doctor: is this checkout protected?
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
pnpm exec se-agent-guard doctor
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Run it in a repo or worktree whose **root** `package.json` has `@se-studio/skills` as a dependency (the hooks run `pnpm exec se-agent-guard` from the repo root; without it you get a single `skills-dependency-missing` finding). It exits 0 when healthy, 1 with one line per problem, and 2 when it could not run (not a git repo, git missing, or an unexpected failure). `fleet-audit` finds the same class of problem from remote refs; the doctor finds it on the machine where it bites, including uncommitted state.
|
|
40
|
+
|
|
41
|
+
It reuses the guard-health checks from `fleet-audit` on the working tree (a hook that does not call the guard, a missing Claude hook or merge audit, a pin that is not exact, skills linked by the old sync, tracked skill symlinks) and adds checks only a local run can do:
|
|
42
|
+
|
|
43
|
+
| Finding | Meaning |
|
|
44
|
+
|---|---|
|
|
45
|
+
| `node-modules-missing` | no install: the git hooks fail closed, the Claude hook fails open |
|
|
46
|
+
| `pin-not-installed` | `node_modules` holds a different version than the exact pin in `package.json` |
|
|
47
|
+
| `guard-bin-missing` | `node_modules/.bin/se-agent-guard` is absent, so the hooks cannot run |
|
|
48
|
+
| `hooks-not-installed`, `hook-not-active` | the repo ships a hook but git is not running it (`core.hooksPath` unset, or no wrapper for it) |
|
|
49
|
+
| `hook-not-executable` | the active hook file lacks the execute bit |
|
|
50
|
+
| `skills-not-linked`, `skills-link-dangling` | `.agents/skills` is empty or has links to nothing, in it or in `.claude/skills`, `.cursor/skills`, `.grok/skills` (run `skills-npm --yes`) |
|
|
51
|
+
| `skills-stale-copy` | a package skill in `.agents/skills` or an agent skills directory is a real copy (left by `skills add`), not a link into the pinned package |
|
|
52
|
+
| `skill-link-broken`, `own-skill-link-broken`, `skill-unreadable` | a relative link in an installed skill, or in a skill the repo owns (including per-entry skills under `.claude/skills`), points at a missing file, or a `SKILL.md` cannot be read. Links are resolved from the skill's real location, the way an agent reads them |
|
|
53
|
+
|
|
54
|
+
The skills checks are skipped when `CI` is set (anything but `false`, the same rule the guard uses) or `VERCEL` is set, because `skills-npm` does not run there. Every file the doctor reads must be a regular file under 1 MB whose real path stays under the repo or its `node_modules` (which a worktree may symlink to a shared install), so a hook or `SKILL.md` that is a symlink to a device, a FIFO or a file outside the repo is not read. Review-doc copies, wording and deploy-script findings stay in `fleet-audit`: they are hygiene, not guard health.
|
|
55
|
+
|
|
33
56
|
## Merge gate
|
|
34
57
|
|
|
35
58
|
`merge-gate.mjs <pr>`: the PR needs a `## Merge approval` comment that names the current head SHA and cites a review. **Anyone** may post it (Nick's decision, 30 Oct 2026: what matters is that the PR was reviewed, not who clicks approve), so the author is not checked. The review is: a link into this PR to a review comment (agent or human; its first heading says "review", it names the head SHA, it gives a verdict such as PASS/BLOCKERS/NITs/LGTM, and it was posted strictly before the approval), or a line that is exactly `none, Nick override`. The head SHA match is the full SHA or a prefix of at least 12 hex characters. A later lint, typecheck, test, or format push may keep that review only when the review names the current head that way; a different hex string shared with the approval does not. A production promote (`dev` → `main`, or `develop` → `main` / `production`, and `isCrossRepository` false) may instead use a whole line `CI covers the changes since` and does not need a review comment on that PR (Nick, 4 Nov 2026: no second AI review; CI covers the commits since the feature review). `dev` → `production` and a fork head do not. Words after that line do not count. Links to PR reviews (`#pullrequestreview-N`) are not accepted because `gh` returns no numeric review id to match them to; post the review as a comment. A bare "reviewed", an external link, a link to a comment that does not exist, a review of an older SHA, a `#pullrequestreview-` link, a minimized comment, or the approval citing itself all fail. Also: not a draft, not "do not merge". `--audit` labels `pushed-through` after a breach and comments that no post-merge AI review will run.
|
package/agent-guard/bin.mjs
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
* se-agent-guard merge-gate <pr> [--audit]
|
|
9
9
|
* se-agent-guard core-request --from <key> --feature <slug> --why "..." file a tracked Core request
|
|
10
10
|
* se-agent-guard worktrees-clean [--apply] [--remote] remove merged worktrees and branches
|
|
11
|
+
* se-agent-guard doctor is this checkout protected? hooks, installs, pins, skills links
|
|
11
12
|
*/
|
|
12
13
|
import { spawnSync } from 'node:child_process';
|
|
13
14
|
import path from 'node:path';
|
|
@@ -20,6 +21,7 @@ const SUBCOMMANDS = {
|
|
|
20
21
|
'merge-gate': ['merge-gate.mjs', []],
|
|
21
22
|
'core-request': ['core-request.mjs', []],
|
|
22
23
|
'worktrees-clean': ['worktrees-clean.mjs', []],
|
|
24
|
+
doctor: ['doctor.mjs', []],
|
|
23
25
|
};
|
|
24
26
|
|
|
25
27
|
const [sub, ...rest] = process.argv.slice(2);
|
|
@@ -0,0 +1,367 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* `se-agent-guard doctor`: is this checkout actually protected? Run it in a repo (or worktree)
|
|
4
|
+
* that depends on @se-studio/skills. `fleet-audit` finds these problems from remote refs; this
|
|
5
|
+
* finds them on the machine where they bite: a hook git is not running, a missing node_modules,
|
|
6
|
+
* a skills link that points at nothing.
|
|
7
|
+
*
|
|
8
|
+
* The policy checks are `auditFiles` from fleet-audit, fed the working tree instead of a remote
|
|
9
|
+
* ref, so there is one definition of "a correct customer repo". The rest are local-only.
|
|
10
|
+
* Everything it reads is repo-controlled, so every read goes through `isReadable`: the file must
|
|
11
|
+
* be regular (not a device or FIFO, which would hang a read), small, and its real path must stay
|
|
12
|
+
* under the repo or its node_modules. Content from outside is never read, so it cannot be printed.
|
|
13
|
+
*
|
|
14
|
+
* se-agent-guard doctor exit 0 healthy, 1 problems found, 2 could not run
|
|
15
|
+
*/
|
|
16
|
+
import { execFileSync } from 'node:child_process';
|
|
17
|
+
import fs from 'node:fs';
|
|
18
|
+
import os from 'node:os';
|
|
19
|
+
import path from 'node:path';
|
|
20
|
+
import { fileURLToPath } from 'node:url';
|
|
21
|
+
import { auditFiles, wantedPaths } from '../references/agent-session/fleet-audit.mjs';
|
|
22
|
+
import { inCi } from './rules.mjs';
|
|
23
|
+
import { findBrokenLinks } from './skill-links.mjs';
|
|
24
|
+
|
|
25
|
+
const SKILLS = '@se-studio/skills';
|
|
26
|
+
const HOOKS = ['pre-commit', 'pre-push'];
|
|
27
|
+
const AGENT_SKILL_DIRS = ['.claude/skills', '.cursor/skills', '.grok/skills'];
|
|
28
|
+
const MAX_FILE_BYTES = 1024 * 1024;
|
|
29
|
+
const MAX_GIT_OUTPUT = 64 * 1024 * 1024;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The fleet checks that say whether the guard and the pinned skills work. The rest of
|
|
33
|
+
* `auditFiles` (review-doc copies, wording, deploy scripts) is fleet hygiene: `fleet-audit`
|
|
34
|
+
* reports it, and burying a broken hook under it would hide the one thing doctor is for.
|
|
35
|
+
*/
|
|
36
|
+
export const GUARD_HEALTH_FINDINGS = new Set([
|
|
37
|
+
'hook-commit-missing',
|
|
38
|
+
'hook-push-missing',
|
|
39
|
+
'claude-hook-missing',
|
|
40
|
+
'merge-audit-missing',
|
|
41
|
+
'pin-not-exact',
|
|
42
|
+
'skills-too-old',
|
|
43
|
+
'skills-npm-missing',
|
|
44
|
+
'skills-sync-legacy',
|
|
45
|
+
'skills-links-tracked',
|
|
46
|
+
'skills-update-script',
|
|
47
|
+
]);
|
|
48
|
+
|
|
49
|
+
const safeJson = (text) => {
|
|
50
|
+
try {
|
|
51
|
+
return JSON.parse(text);
|
|
52
|
+
} catch {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
function git(root, args) {
|
|
58
|
+
return execFileSync('git', args, {
|
|
59
|
+
cwd: root,
|
|
60
|
+
encoding: 'utf8',
|
|
61
|
+
maxBuffer: MAX_GIT_OUTPUT,
|
|
62
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Does the path exist once symlinks are followed? A dangling link is false. */
|
|
67
|
+
const resolves = (p) => fs.existsSync(p);
|
|
68
|
+
|
|
69
|
+
const within = (real, base) => real === base || real.startsWith(base + path.sep);
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Is it safe to read? A regular file (a device or FIFO would hang the read), not huge, and whose
|
|
73
|
+
* real path is under one of `bases`.
|
|
74
|
+
* @param {string} file
|
|
75
|
+
* @param {string[]} bases real paths
|
|
76
|
+
*/
|
|
77
|
+
function isReadable(file, bases) {
|
|
78
|
+
try {
|
|
79
|
+
const stat = fs.statSync(file);
|
|
80
|
+
if (!stat.isFile() || stat.size > MAX_FILE_BYTES) return false;
|
|
81
|
+
const real = fs.realpathSync(file);
|
|
82
|
+
return bases.some((base) => within(real, base));
|
|
83
|
+
} catch {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const readRegular = (file, bases) =>
|
|
89
|
+
isReadable(file, bases) ? fs.readFileSync(file, 'utf8') : null;
|
|
90
|
+
|
|
91
|
+
const readJson = (file, bases) => safeJson(readRegular(file, bases) ?? '');
|
|
92
|
+
|
|
93
|
+
const realOrNull = (p) => {
|
|
94
|
+
try {
|
|
95
|
+
return fs.realpathSync(p);
|
|
96
|
+
} catch {
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
function listDir(dir) {
|
|
102
|
+
try {
|
|
103
|
+
return fs.readdirSync(dir).filter((name) => !name.startsWith('.'));
|
|
104
|
+
} catch {
|
|
105
|
+
return []; // missing, or not a directory
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* The skills the agents can see: entries of .agents/skills and of the per-agent directories,
|
|
111
|
+
* each once (the agent directories usually link to .agents/skills).
|
|
112
|
+
* @returns {{ dangling: string[], skills: { name: string, rel: string, real: string, isLink: boolean }[] }}
|
|
113
|
+
*/
|
|
114
|
+
function visibleSkills(root) {
|
|
115
|
+
const dangling = [];
|
|
116
|
+
const skills = [];
|
|
117
|
+
const seen = new Set();
|
|
118
|
+
for (const dirRel of ['.agents/skills', ...AGENT_SKILL_DIRS]) {
|
|
119
|
+
const dir = path.join(root, dirRel);
|
|
120
|
+
try {
|
|
121
|
+
fs.lstatSync(dir);
|
|
122
|
+
} catch {
|
|
123
|
+
continue; // the directory is optional
|
|
124
|
+
}
|
|
125
|
+
if (!resolves(dir)) {
|
|
126
|
+
dangling.push(dirRel);
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
for (const name of listDir(dir)) {
|
|
130
|
+
const entry = path.join(dir, name);
|
|
131
|
+
const rel = `${dirRel}/${name}`;
|
|
132
|
+
if (!resolves(entry)) {
|
|
133
|
+
dangling.push(rel);
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
const real = fs.realpathSync(entry);
|
|
137
|
+
if (seen.has(real)) continue;
|
|
138
|
+
seen.add(real);
|
|
139
|
+
skills.push({ name, rel, real, isLink: fs.lstatSync(entry).isSymbolicLink() });
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return { dangling, skills };
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* @param {{ root: string, env?: Record<string, string | undefined> }} input root: the repo top level
|
|
147
|
+
* @returns {{ findings: { id: string, text: string }[] }}
|
|
148
|
+
*/
|
|
149
|
+
export function diagnose({ root, env = process.env }) {
|
|
150
|
+
const findings = [];
|
|
151
|
+
const add = (id, text) => findings.push({ id, text });
|
|
152
|
+
|
|
153
|
+
// Paths come NUL-separated: without -z git quotes non-ASCII names and they would never match.
|
|
154
|
+
const tree = git(root, ['ls-files', '-s', '-z'])
|
|
155
|
+
.split('\0')
|
|
156
|
+
.filter(Boolean)
|
|
157
|
+
.map((entry) => ({
|
|
158
|
+
mode: entry.slice(0, entry.indexOf(' ')),
|
|
159
|
+
path: entry.slice(entry.indexOf('\t') + 1),
|
|
160
|
+
}));
|
|
161
|
+
const untracked = git(root, ['ls-files', '-o', '--exclude-standard', '-z'])
|
|
162
|
+
.split('\0')
|
|
163
|
+
.filter(Boolean);
|
|
164
|
+
const rootReal = fs.realpathSync(root);
|
|
165
|
+
const modules = path.join(root, 'node_modules');
|
|
166
|
+
const modulesReal = realOrNull(modules); // a worktree may symlink this to a shared install
|
|
167
|
+
const bases = modulesReal ? [rootReal, modulesReal] : [rootReal];
|
|
168
|
+
const files = {};
|
|
169
|
+
for (const rel of wantedPaths([...tree.map((t) => t.path), ...untracked])) {
|
|
170
|
+
const body = readRegular(path.join(root, rel), [rootReal]);
|
|
171
|
+
if (body !== null) files[rel] = body;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const pkg = files['package.json'] ? safeJson(files['package.json']) : null;
|
|
175
|
+
const deps = { ...pkg?.dependencies, ...pkg?.devDependencies };
|
|
176
|
+
if (!(SKILLS in deps)) {
|
|
177
|
+
// Everything below assumes the pinned guard is installed from the root package.json.
|
|
178
|
+
const source = readJson(path.join(root, 'packages/skills/package.json'), [rootReal]);
|
|
179
|
+
add(
|
|
180
|
+
'skills-dependency-missing',
|
|
181
|
+
!pkg
|
|
182
|
+
? 'package.json is missing or not valid JSON, so there is no pinned guard to check'
|
|
183
|
+
: source?.name === SKILLS
|
|
184
|
+
? `this is the source repo of ${SKILLS}: doctor is for repos that depend on it`
|
|
185
|
+
: `${SKILLS} is not a dependency in the root package.json. The hooks run \`pnpm exec se-agent-guard\` from the repo root, so it must be a root devDependency at an exact version`,
|
|
186
|
+
);
|
|
187
|
+
return { findings };
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// 1. The shared policy checks, on the working tree (uncommitted state included).
|
|
191
|
+
// No remote to compare with: skip "behind core" and "block stale".
|
|
192
|
+
for (const f of auditFiles({ files, tree, coreBlockVersion: 0, coreVersions: {} }).findings) {
|
|
193
|
+
if (GUARD_HEALTH_FINDINGS.has(f.id)) add(f.id, f.text);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// 2. Dependencies are installed, and at the pinned version.
|
|
197
|
+
if (!fs.existsSync(modules)) {
|
|
198
|
+
add(
|
|
199
|
+
'node-modules-missing',
|
|
200
|
+
'node_modules is missing: run `pnpm install`. The git hooks fail closed without it (commits are refused); the Claude hook fails open.',
|
|
201
|
+
);
|
|
202
|
+
} else {
|
|
203
|
+
for (const [name, spec] of Object.entries(deps)) {
|
|
204
|
+
if (!name.startsWith('@se-studio/') || String(spec).startsWith('workspace:')) continue;
|
|
205
|
+
if (!/^\d+\.\d+\.\d+/.test(String(spec))) continue; // a range is reported by pin-not-exact
|
|
206
|
+
const installed = readJson(path.join(modules, name, 'package.json'), bases)?.version;
|
|
207
|
+
if (installed === undefined) {
|
|
208
|
+
add(
|
|
209
|
+
'pin-not-installed',
|
|
210
|
+
`${name} is pinned ${spec} but is not installed: run \`pnpm install\``,
|
|
211
|
+
);
|
|
212
|
+
} else if (installed !== spec) {
|
|
213
|
+
add(
|
|
214
|
+
'pin-not-installed',
|
|
215
|
+
`${name} is pinned ${spec} but ${installed} is installed: run \`pnpm install\``,
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
if (!resolves(path.join(modules, '.bin', 'se-agent-guard'))) {
|
|
220
|
+
add(
|
|
221
|
+
'guard-bin-missing',
|
|
222
|
+
'node_modules/.bin/se-agent-guard is missing: the hooks call it and will fail. Run `pnpm install`',
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// 3. Git is actually running the hooks the repo ships.
|
|
228
|
+
const present = HOOKS.filter((name) => `.husky/${name}` in files || `.githooks/${name}` in files);
|
|
229
|
+
if (present.length > 0) {
|
|
230
|
+
let hooksPath = '';
|
|
231
|
+
try {
|
|
232
|
+
hooksPath = git(root, ['config', 'core.hooksPath']).trim();
|
|
233
|
+
} catch {
|
|
234
|
+
// unset
|
|
235
|
+
}
|
|
236
|
+
// Plain `git config` (--type=path needs git 2.18): expand a leading ~ the way git would.
|
|
237
|
+
if (hooksPath === '~' || hooksPath.startsWith('~/')) {
|
|
238
|
+
hooksPath = path.join(os.homedir(), hooksPath.slice(1));
|
|
239
|
+
}
|
|
240
|
+
if (!hooksPath) {
|
|
241
|
+
add(
|
|
242
|
+
'hooks-not-installed',
|
|
243
|
+
'git core.hooksPath is not set, so the pre-commit and pre-push guards do not run: run `pnpm install` (the `prepare` script sets it)',
|
|
244
|
+
);
|
|
245
|
+
} else {
|
|
246
|
+
const active = path.resolve(root, hooksPath);
|
|
247
|
+
for (const name of present) {
|
|
248
|
+
const hook = path.join(active, name);
|
|
249
|
+
if (!resolves(hook)) {
|
|
250
|
+
add(
|
|
251
|
+
'hook-not-active',
|
|
252
|
+
`the repo has a ${name} hook but core.hooksPath (${hooksPath}) has none, so git does not run it: run \`pnpm install\``,
|
|
253
|
+
);
|
|
254
|
+
} else if (!(fs.statSync(hook).mode & 0o111)) {
|
|
255
|
+
add(
|
|
256
|
+
'hook-not-executable',
|
|
257
|
+
`${hooksPath}/${name} is not executable: run \`chmod +x ${hooksPath}/${name}\``,
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// 4. Skills are linked from the installed package. skills-npm does not run on Vercel or CI.
|
|
265
|
+
if (!inCi(env) && !env.VERCEL && fs.existsSync(path.join(modules, SKILLS))) {
|
|
266
|
+
if (listDir(path.join(root, '.agents/skills')).length === 0) {
|
|
267
|
+
add(
|
|
268
|
+
'skills-not-linked',
|
|
269
|
+
'.agents/skills is missing or empty: run `pnpm exec skills-npm --yes`',
|
|
270
|
+
);
|
|
271
|
+
}
|
|
272
|
+
const { dangling, skills } = visibleSkills(root);
|
|
273
|
+
if (dangling.length > 0) {
|
|
274
|
+
add(
|
|
275
|
+
'skills-link-dangling',
|
|
276
|
+
`${dangling.length} skill link(s) point at nothing (${dangling.slice(0, 3).join(', ')}): run \`pnpm install\`, then \`pnpm exec skills-npm --yes\``,
|
|
277
|
+
);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// A real directory in .agents/skills that shares a name with a package skill is a copy left
|
|
281
|
+
// by `skills add`, not a link: its relative links no longer resolve, and it never updates.
|
|
282
|
+
const packaged = new Set(listDir(path.join(modules, SKILLS, 'skills')));
|
|
283
|
+
const copies = skills.filter((s) => !s.isLink && packaged.has(s.name));
|
|
284
|
+
if (copies.length > 0) {
|
|
285
|
+
add(
|
|
286
|
+
'skills-stale-copy',
|
|
287
|
+
`${copies.length} skill(s) are copies, not links into the pinned package (${copies
|
|
288
|
+
.slice(0, 3)
|
|
289
|
+
.map((s) => s.name)
|
|
290
|
+
.join(', ')}): delete them and run \`pnpm exec skills-npm --yes\``,
|
|
291
|
+
);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// Links inside a skill resolve from the skill's real location: .agents/skills/<name> is a
|
|
295
|
+
// symlink into node_modules, and `../../references/x.md` means the package's references/.
|
|
296
|
+
const fromPackage = [];
|
|
297
|
+
const fromRepo = [];
|
|
298
|
+
const unreadable = [];
|
|
299
|
+
for (const skill of skills.filter((s) => !copies.includes(s))) {
|
|
300
|
+
const file = path.join(skill.real, 'SKILL.md');
|
|
301
|
+
if (!resolves(file)) continue;
|
|
302
|
+
// The link checker reads the file itself, so apply the same guard first.
|
|
303
|
+
if (!isReadable(file, bases)) {
|
|
304
|
+
unreadable.push(skill.rel);
|
|
305
|
+
continue;
|
|
306
|
+
}
|
|
307
|
+
const bucket = modulesReal && within(skill.real, modulesReal) ? fromPackage : fromRepo;
|
|
308
|
+
try {
|
|
309
|
+
for (const { link } of findBrokenLinks(file)) bucket.push(`${skill.name}: ${link}`);
|
|
310
|
+
} catch {
|
|
311
|
+
unreadable.push(skill.rel);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
if (fromPackage.length > 0) {
|
|
315
|
+
add(
|
|
316
|
+
'skill-link-broken',
|
|
317
|
+
`${fromPackage.length} broken link(s) in installed skills (${fromPackage.slice(0, 3).join('; ')}): the pinned ${SKILLS} ships a bad link, update it`,
|
|
318
|
+
);
|
|
319
|
+
}
|
|
320
|
+
if (fromRepo.length > 0) {
|
|
321
|
+
add(
|
|
322
|
+
'own-skill-link-broken',
|
|
323
|
+
`${fromRepo.length} broken link(s) in this repo's own skills (${fromRepo.slice(0, 3).join('; ')}): they do not resolve from where the agent reads them`,
|
|
324
|
+
);
|
|
325
|
+
}
|
|
326
|
+
if (unreadable.length > 0) {
|
|
327
|
+
add(
|
|
328
|
+
'skill-unreadable',
|
|
329
|
+
`${unreadable.length} skill(s) have a SKILL.md that cannot be read (${unreadable.slice(0, 3).join(', ')})`,
|
|
330
|
+
);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
return { findings };
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
function main() {
|
|
338
|
+
let root;
|
|
339
|
+
try {
|
|
340
|
+
root = git(process.cwd(), ['rev-parse', '--show-toplevel']).trim();
|
|
341
|
+
} catch (error) {
|
|
342
|
+
console.error(
|
|
343
|
+
error?.code === 'ENOENT'
|
|
344
|
+
? 'se-agent-guard doctor: git is not installed'
|
|
345
|
+
: 'se-agent-guard doctor: could not read a git repository here (not a repo, or a broken worktree)',
|
|
346
|
+
);
|
|
347
|
+
process.exit(2);
|
|
348
|
+
}
|
|
349
|
+
let findings;
|
|
350
|
+
try {
|
|
351
|
+
({ findings } = diagnose({ root }));
|
|
352
|
+
} catch (error) {
|
|
353
|
+
console.error(
|
|
354
|
+
`se-agent-guard doctor: could not finish: ${error instanceof Error ? error.message : error}`,
|
|
355
|
+
);
|
|
356
|
+
process.exit(2);
|
|
357
|
+
}
|
|
358
|
+
if (findings.length === 0) {
|
|
359
|
+
console.log('se-agent-guard doctor: ok');
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
console.error(`se-agent-guard doctor: ${findings.length} problem(s)\n`);
|
|
363
|
+
for (const f of findings) console.error(` ${f.id}: ${f.text}`);
|
|
364
|
+
process.exit(1);
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) main();
|
package/agent-guard/rules.mjs
CHANGED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check that relative markdown links in a skill file point at files that exist.
|
|
3
|
+
* Links resolve against the file's own directory. Code spans, fenced code, URLs,
|
|
4
|
+
* absolute paths, in-page anchors and URL templates (`<x>`, `{x}`, `?query`) are skipped.
|
|
5
|
+
*
|
|
6
|
+
* A target must be a file (not a directory) and must match case exactly, so a link that only
|
|
7
|
+
* works on a case-insensitive filesystem is reported before it 404s on Linux. With a
|
|
8
|
+
* `packageRoot` and the package's `files` list, a link to something that does not ship is
|
|
9
|
+
* reported too: a customer never gets it. `packageRoot` and `filePath` must be in the same
|
|
10
|
+
* path space (both realpaths, or both not).
|
|
11
|
+
*
|
|
12
|
+
* Not checked (known gaps): reference-style links, HTML `<a href>` / `<img src>`, `?query`
|
|
13
|
+
* links, `#fragment` targets, and link text containing brackets.
|
|
14
|
+
*/
|
|
15
|
+
import fs from 'node:fs';
|
|
16
|
+
import path from 'node:path';
|
|
17
|
+
|
|
18
|
+
// One level of balanced parentheses in the path; a double- or single-quoted title is allowed.
|
|
19
|
+
const LINK = /\[[^\]]*\]\(((?:[^()\s]|\([^()\s]*\))+)(?:\s+(?:"[^"]*"|'[^']*'))?\)/g;
|
|
20
|
+
// A backtick fence's info string may not contain a backtick (CommonMark: that is inline code).
|
|
21
|
+
const FENCE_OPEN = /^\s*(`{3,}(?=[^`]*$)|~{3,})/;
|
|
22
|
+
|
|
23
|
+
/** Blank out fenced blocks (matched by character and length) and inline code. */
|
|
24
|
+
function stripCode(markdown) {
|
|
25
|
+
const lines = markdown.split('\n');
|
|
26
|
+
const out = [];
|
|
27
|
+
let fence = null; // { char, length, from } while inside a block
|
|
28
|
+
for (let i = 0; i < lines.length; i++) {
|
|
29
|
+
const line = lines[i];
|
|
30
|
+
if (fence === null) {
|
|
31
|
+
const open = line.match(FENCE_OPEN);
|
|
32
|
+
if (open) {
|
|
33
|
+
fence = { char: open[1][0], length: open[1].length, from: out.length };
|
|
34
|
+
out.push('');
|
|
35
|
+
} else {
|
|
36
|
+
out.push(line);
|
|
37
|
+
}
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
const close = line.match(/^\s*(`{3,}|~{3,})\s*$/);
|
|
41
|
+
out.push('');
|
|
42
|
+
if (close && close[1][0] === fence.char && close[1].length >= fence.length) fence = null;
|
|
43
|
+
}
|
|
44
|
+
// An unterminated fence hides nothing: a typo must not switch checking off for the rest of the file.
|
|
45
|
+
if (fence !== null) {
|
|
46
|
+
for (let i = fence.from; i < lines.length; i++) out[i] = lines[i];
|
|
47
|
+
}
|
|
48
|
+
return out.join('\n').replace(/(`+)[^\n]*?\1/g, '');
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** @returns {string | null} the path to check, or null when the link is not a file link */
|
|
52
|
+
function localTarget(raw) {
|
|
53
|
+
if (/^([a-z][a-z0-9+.-]*:|\/|#)/i.test(raw)) return null;
|
|
54
|
+
if (/[<>{}?]/.test(raw)) return null;
|
|
55
|
+
const target = raw.split('#')[0];
|
|
56
|
+
if (target === '') return null;
|
|
57
|
+
try {
|
|
58
|
+
return decodeURIComponent(target);
|
|
59
|
+
} catch {
|
|
60
|
+
return target; // malformed escape: check it as written, which reports it as missing
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* A regular file whose every path segment, below `stopAt`, matches the directory listing exactly.
|
|
66
|
+
* @param {string} resolved
|
|
67
|
+
* @param {string} stopAt the link file's own directory: it and everything above it exist
|
|
68
|
+
*/
|
|
69
|
+
function isFileExact(resolved, stopAt) {
|
|
70
|
+
try {
|
|
71
|
+
if (!fs.statSync(resolved).isFile()) return false;
|
|
72
|
+
} catch {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
let current = resolved;
|
|
76
|
+
while (stopAt !== current && !stopAt.startsWith(current + path.sep)) {
|
|
77
|
+
const parent = path.dirname(current);
|
|
78
|
+
if (parent === current) return true;
|
|
79
|
+
try {
|
|
80
|
+
if (!fs.readdirSync(parent).includes(path.basename(current))) return false;
|
|
81
|
+
} catch {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
current = parent;
|
|
85
|
+
}
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** npm always publishes these, whatever `files` says. */
|
|
90
|
+
const ALWAYS_PUBLISHED = /^(package\.json|README(\..*)?|LICENSE(\..*)?|CHANGELOG(\..*)?)$/i;
|
|
91
|
+
|
|
92
|
+
/** Does a package.json `files` list publish this path (relative to the package root, posix)? */
|
|
93
|
+
function isPublished(rel, files) {
|
|
94
|
+
if (ALWAYS_PUBLISHED.test(rel)) return true;
|
|
95
|
+
return files.some((entry) => {
|
|
96
|
+
if (entry.includes('*')) {
|
|
97
|
+
const glob = entry.replace(/[.+?^${}()|[\]\\]/g, '\\$&').replace(/\*/g, '[^/]*');
|
|
98
|
+
return new RegExp(`^${glob}$`).test(rel);
|
|
99
|
+
}
|
|
100
|
+
return rel === entry || rel.startsWith(`${entry}/`);
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const inside = (root, target, files) => {
|
|
105
|
+
const rel = path.relative(root, target);
|
|
106
|
+
if (rel === '' || rel.startsWith('..') || path.isAbsolute(rel)) return false;
|
|
107
|
+
return files ? isPublished(rel.split(path.sep).join('/'), files) : true;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* @param {string} filePath absolute path of the markdown file
|
|
112
|
+
* @param {{ packageRoot?: string, files?: string[] }} [options] files: the package.json `files` list
|
|
113
|
+
* @returns {{ link: string, resolved: string, reason: 'missing' | 'outside-package' }[]}
|
|
114
|
+
*/
|
|
115
|
+
export function findBrokenLinks(filePath, { packageRoot, files } = {}) {
|
|
116
|
+
const text = stripCode(fs.readFileSync(filePath, 'utf8'));
|
|
117
|
+
const dir = path.dirname(filePath);
|
|
118
|
+
const broken = [];
|
|
119
|
+
for (const match of text.matchAll(LINK)) {
|
|
120
|
+
const target = localTarget(match[1]);
|
|
121
|
+
if (target === null) continue;
|
|
122
|
+
const resolved = path.resolve(dir, target);
|
|
123
|
+
if (packageRoot && !inside(packageRoot, resolved, files)) {
|
|
124
|
+
broken.push({ link: match[1], resolved, reason: 'outside-package' });
|
|
125
|
+
} else if (!isFileExact(resolved, dir)) {
|
|
126
|
+
broken.push({ link: match[1], resolved, reason: 'missing' });
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return broken;
|
|
130
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Customer guardrail files (v1)
|
|
2
2
|
|
|
3
|
-
Thin files a customer repo copies once. The hook, Claude settings, and merge-gate audit call the pinned `se-agent-guard` bin from `@se-studio/skills`, so that behaviour is versioned by the lockfile and cannot drift. `site-ci.yml` calls the shared workflow in se-core-product.
|
|
3
|
+
Thin files a customer repo copies once. The hook, Claude settings, and merge-gate audit call the pinned `se-agent-guard` bin from `@se-studio/skills`, so that behaviour is versioned by the lockfile and cannot drift. `site-ci.yml` calls the shared workflow in se-core-product. `pnpm exec se-agent-guard doctor` checks that this checkout still has them and that they work (see the agent-guard README); `fleet-audit` does the same from remote refs across the fleet.
|
|
4
4
|
|
|
5
5
|
| Copy | To | Purpose |
|
|
6
6
|
|------|----|---------|
|