diff --git a/AGENTS.md b/AGENTS.md index 66ef53a..c887564 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -18,7 +18,7 @@ This repository manages personal CLI configuration. Preserve these project-local - Durable architecture/workflow decisions belong in `docs/adr/`; supporting external research belongs in `docs/research/`. - Before presenting a change as ready, run `./script/test`, `./script/test-workflow`, `./script/check-secrets`, and relevant `./script/check` / `./script/secrets-doctor` validation. -Project-wide delivery, authority, evidence, and review rules follow the current `rebuildup/project-init` operating profile. +Project-wide delivery, authority, evidence, and review rules follow the current `rebuildup/aude-skills` (formerly `rebuildup/project-init`; migration tracking: `rebuildup/aude-skills#212`) operating profile. ## Constitution / operating profile @@ -30,9 +30,9 @@ Project-wide delivery, authority, evidence, and review rules follow the current ## Agent Skills lifecycle -project-init 由来の Agent Skills は **project-local** に管理し、global install を canonical にしない。 +aude-skills(旧称 project-init)由来の Agent Skills は **project-local** に管理し、global install を canonical にしない。 -- 初回導入 / 全体 reconcile: `bunx skills@1.7.0 add rebuildup/project-init --skill '*' --agent claude-code opencode codex devin -y` +- 初回導入 / 全体 reconcile: `bunx skills@1.7.0 add rebuildup/aude-skills --skill '*' --agent claude-code opencode codex devin -y` - fresh clone から lock を復元: `bunx skills@1.7.0 experimental_install` - 継続更新: `bunx skills@1.7.0 update -p -y` - `skills-lock.json` は `skills` CLI が生成・更新する source/freshness metadata として commit する。手で hash / source entry を捏造しない。 diff --git a/docs/agent-launcher.md b/docs/agent-launcher.md index c300ed4..ff515b9 100644 --- a/docs/agent-launcher.md +++ b/docs/agent-launcher.md @@ -34,7 +34,7 @@ agent task reconcile # resolve journal UNKNOWNs vs evidence | `script/agent/limits.ts` | Failure classification & retry policy (issue #92) | | `script/agent/telemetry.ts` | Usage/task efficiency ledger (issue #93) | | `script/agent/recommend.ts` | Task-aware route recommendation (issue #94) | -| `script/agent/policy.ts` | project-init policy resolver (issue #95) | +| `script/agent/policy.ts` | aude-skills (formerly project-init) policy resolver (issue #95) | | `script/agent/preflight.ts` | Execution admission & task classification (issue #96) | | `script/agent/machines.ts` | Machine inventory & placement (issue #97) | | `script/agent/workspace.ts` | Workspace/runtime leases (issue #98) | diff --git a/mise.toml b/mise.toml index cd718b6..9dbe331 100644 --- a/mise.toml +++ b/mise.toml @@ -5,12 +5,12 @@ bun = "1.4.2" [tasks.skills-list] -description = "List Agent Skills available from rebuildup/project-init" -run = "bunx skills@1.7.0 add rebuildup/project-init --list" +description = "List Agent Skills available from rebuildup/aude-skills (formerly rebuildup/project-init)" +run = "bunx skills@1.7.0 add rebuildup/aude-skills --list" [tasks.skills-bootstrap] -description = "Install project-init Skills for Claude Code and universal .agents/skills consumers" -run = "bunx skills@1.7.0 add rebuildup/project-init --skill '*' --agent claude-code --agent codex -y" +description = "Install aude-skills (formerly project-init) Skills for Claude Code and universal .agents/skills consumers" +run = "bunx skills@1.7.0 add rebuildup/aude-skills --skill '*' --agent claude-code --agent codex -y" [tasks.skills-update] description = "Update tracked project-local Agent Skills non-interactively" diff --git a/organization/profiles/release-driven-solo.md b/organization/profiles/release-driven-solo.md index f153172..a4931fa 100644 --- a/organization/profiles/release-driven-solo.md +++ b/organization/profiles/release-driven-solo.md @@ -8,7 +8,7 @@ dotfiles の current release-driven development で使用する Operating Model を定義します。 -このprofileはproject-initの唯一の正しいorganization topologyではありません。別profileまたはproject-specific modelがConstitutionを満たす場合は置換できます。 +このprofileはaude-skills(旧称 project-init)の唯一の正しいorganization topologyではありません。別profileまたはproject-specific modelがConstitutionを満たす場合は置換できます。 ## Current topology @@ -145,9 +145,9 @@ explicit user/project decisionとして固定されたrelease scope/version/publ - Project-local Agent Skills の導入・更新は **`bunx skills` を canonical mechanism** とする。手動 copy / 個別 agent directory の内容を upstream freshness の SoT にしない。 - Bun は Skills CLI 用の development prerequisite とする。Bun が application runtime / package manager でない repository でも、既存の project-local `mise` または established bootstrap から利用可能にし、application の native toolchain ownership は変更しない。 -- project-init Skills は floating source `rebuildup/project-init` を追跡する。上記の `release-0-3-0` は Constitution / Operating Model の reconciliation baseline であり、Skills の freeze/pin ではない。freeze が必要なら ADR で明示する。 +- aude-skills(旧称 project-init)由来 Skills は canonical source `rebuildup/aude-skills` を追跡する(既存 lock の旧 `rebuildup/project-init` 参照は移行期間中リダイレクト互換、次回再導入時に新名へ移行。移行正本: `rebuildup/aude-skills#212`)。上記の `release-0-3-0` は Constitution / Operating Model の reconciliation baseline であり、Skills の freeze/pin ではない。freeze が必要なら ADR で明示する。 - canonical install layout は `.agents/skills/` と `.claude/skills/`。Codex / OpenCode / Cursor は universal `.agents/skills/` を共有し、Claude Code は `.claude/skills/` を使用する。 -- 初回導入 / scope変更は `bunx skills@1.7.0 add rebuildup/project-init --list` で候補を確認し、標準bootstrapは `bunx skills@1.7.0 add rebuildup/project-init --skill '*' --agent claude-code --agent codex -y` とする。repositoryに `mise.toml` taskがある場合は `mise run skills-bootstrap` を同じ入口とする。 +- 初回導入 / scope変更は `bunx skills@1.7.0 add rebuildup/aude-skills --list` で候補を確認し、標準bootstrapは `bunx skills@1.7.0 add rebuildup/aude-skills --skill '*' --agent claude-code --agent codex -y` とする。repositoryに `mise.toml` taskがある場合は `mise run skills-bootstrap` を同じ入口とする。 - project-local `skills-lock.json` は source / skill path / content hash の durable metadata として commit する。通常の追従更新は `bunx skills@1.7.0 update -p -y`(または `mise run skills-update`)を使う。 - current Skills CLI では lock からの復元は `skills experimental_install` を使う(`skills install` は `add` の alias で、lock からの復元には使わない)。ただし fresh clone bootstrap の入口は `mise run skills-bootstrap` とし、lock 復元だけで Claude Code 側の配置を保証しない。 - `--global` は通常運用で使用しない。user-global Skills を repository policy / freshness evidence にしない。 diff --git a/script/agent.policy.test.ts b/script/agent.policy.test.ts index 67c9363..c14d6e7 100755 --- a/script/agent.policy.test.ts +++ b/script/agent.policy.test.ts @@ -25,6 +25,12 @@ const BASELINE_SHA = "57fb4a2e5abe6f52e4fd9cb2cb88234496e47d4b"; * from the documented algorithm, independent of the resolver implementation. */ const FRESH_SKILL_FOLDER_HASH = "0ac5560b3a1b6da13cebb57ca706b8bdb1e2b52ed7a34b21304c09b188d803a6"; +/** skills >= 1.9 (lock version 2) folder hash of a skill directory holding + * SKILL.md ("exact locked body\n", CRLF-normalized) and references/note.md + * ("note text"), excluding metadata.json. Precomputed independently. */ +const FRESH_SKILL_V2_FOLDER_HASH = + "7c805ed1df6b64777404fb6b7a8238a619b375cade4529d42d3c92cd45eab373"; +const AUDE_SKILLS_V0141_SHA = "2ac7951c01cdce3a59dade7eb6434e9b13382cb8"; function factKinds(resolution: PolicyResolution): Set { return new Set(resolution.facts.map((fact) => fact.kind)); @@ -40,8 +46,11 @@ function writeFixture( writeFileSync(path, content); } -function lockJson(entries: Record>): string { - return JSON.stringify({ version: 1, skills: entries }, null, 2); +function lockJson( + entries: Record>, + version = 1, +): string { + return JSON.stringify({ version, skills: entries }, null, 2); } describe("policy resolver: real repository (no mocks)", () => { @@ -393,4 +402,92 @@ describe("policy resolver: fixture repositories (mocks)", () => { rmSync(root, { recursive: true, force: true }); } }); + + test("resolves renamed rebuildup/aude-skills baselines alongside legacy project-init baselines", () => { + const root = mkdtempSync(join(tmpdir(), "policy-aude-baseline-")); + try { + writeFixture( + root, + "organization/profiles/release-driven-solo.md", + `## Upstream source\n\n\`rebuildup/aude-skills@v0.14.1\` (\`${AUDE_SKILLS_V0141_SHA}\`) を基準にする。\n`, + ); + writeFixture( + root, + "skills-lock.json", + lockJson( + { + "fresh-skill": { + source: "rebuildup/aude-skills", + sourceType: "github", + ref: "v0.14.1", + commit: AUDE_SKILLS_V0141_SHA, + skillPath: "skills/fresh-skill/SKILL.md", + computedHash: FRESH_SKILL_V2_FOLDER_HASH, + }, + }, + 2, + ), + ); + writeFixture( + root, + ".agents/skills/fresh-skill/SKILL.md", + "exact locked body\r\n", + ); + writeFixture( + root, + ".agents/skills/fresh-skill/references/note.md", + "note text", + ); + writeFixture( + root, + ".agents/skills/fresh-skill/metadata.json", + '{"ignored":true}', + ); + const resolution = resolvePolicy(root); + expect(resolution.baseline).toEqual({ + ref: "v0.14.1", + sha: AUDE_SKILLS_V0141_SHA, + }); + expect(resolution.lockUnpinned).toBe(false); + expect(resolution.skills[0]?.source).toBe("rebuildup/aude-skills"); + expect(resolution.skills[0]?.status).toBe("ok"); + expect(factKinds(resolution)).toContain("baseline-pinned"); + expect(factKinds(resolution)).not.toContain("baseline-divergence-risk"); + expect(factKinds(resolution)).not.toContain("skill-hash-mismatch"); + } finally { + rmSync(root, { recursive: true, force: true }); + } + }); + + test("detects hash mismatch under skills-lock.json version 2 for aude-skills", () => { + const root = mkdtempSync(join(tmpdir(), "policy-aude-v2-mismatch-")); + try { + writeFixture( + root, + "skills-lock.json", + lockJson( + { + "tampered-skill": { + source: "rebuildup/aude-skills", + sourceType: "github", + ref: "v0.14.1", + skillPath: "skills/tampered-skill/SKILL.md", + computedHash: FRESH_SKILL_V2_FOLDER_HASH, + }, + }, + 2, + ), + ); + writeFixture( + root, + ".agents/skills/tampered-skill/SKILL.md", + "tampered body\n", + ); + const resolution = resolvePolicy(root); + expect(resolution.skills[0]?.status).toBe("hash-mismatch"); + expect(factKinds(resolution)).toContain("skill-hash-mismatch"); + } finally { + rmSync(root, { recursive: true, force: true }); + } + }); }); diff --git a/script/agent/policy.ts b/script/agent/policy.ts index a314f97..22a7176 100755 --- a/script/agent/policy.ts +++ b/script/agent/policy.ts @@ -23,7 +23,13 @@ */ import { createHash } from "node:crypto"; -import { existsSync, readdirSync, readFileSync } from "node:fs"; +import { + existsSync, + readdirSync, + readFileSync, + realpathSync, + statSync, +} from "node:fs"; import { join, relative, sep } from "node:path"; import { errorMessage, isPlainObject } from "./contract"; @@ -114,7 +120,7 @@ const QUALITY_PROFILE_PATHS = [ ]; const BASELINE_RE = - /rebuildup\/project-init@([A-Za-z0-9._-]+)`?\s*\(`?([0-9a-f]{40})`?\)/; + /rebuildup\/(?:aude-skills|project-init)@([A-Za-z0-9._-]+)`?\s*\(`?([0-9a-f]{40})`?\)/; const LANDING_RE = /PR landing method:\s*([^\n`]+)/; const MERGE_SETTING_RE = /allow_(merge_commit|squash_merge|rebase_merge)=(true|false)/g; @@ -202,7 +208,7 @@ function collectSkillFiles( } } -function computeSkillFolderHash(skillDir: string): string { +function computeSkillFolderHashV1(skillDir: string): string { const files: Array<{ relativePath: string; content: Buffer }> = []; collectSkillFiles(skillDir, skillDir, files); files.sort((a, b) => a.relativePath.localeCompare(b.relativePath)); @@ -214,9 +220,101 @@ function computeSkillFolderHash(skillDir: string): string { return hash.digest("hex"); } +// skills-lock.json version 2 (skills CLI >= 1.9): mirrors hashSkillFiles — +// excludes metadata.json and cache dirs, resolves symlinks only inside the +// skill root, normalizes CRLF on non-binary files, sorts paths byte-wise, +// and frames each entry as `path\0length\0content`. +const V2_EXCLUDE_FILES = new Set(["metadata.json"]); +const V2_EXCLUDE_DIRS = new Set([".git", "__pycache__", "__pypackages__"]); + +function isV2Excluded(name: string, isDirectory: boolean): boolean { + return ( + V2_EXCLUDE_FILES.has(name) || (isDirectory && V2_EXCLUDE_DIRS.has(name)) + ); +} + +function normalizeV2Content(content: Buffer): Buffer { + if (content.includes(0) || !content.includes("\r\n")) return content; + return Buffer.from( + content.toString("latin1").replaceAll("\r\n", "\n"), + "latin1", + ); +} + +function collectSkillFilesV2( + dir: string, + prefix: string, + rootRealPath: string, + results: Array<{ relativePath: string; content: Buffer }>, +): void { + const current = prefix ? join(dir, prefix) : dir; + for (const entry of readdirSync(current, { withFileTypes: true })) { + if (isV2Excluded(entry.name, entry.isDirectory())) continue; + const rel = prefix ? `${prefix}/${entry.name}` : entry.name; + const full = join(current, entry.name); + if (entry.isDirectory()) { + collectSkillFilesV2(dir, rel, rootRealPath, results); + } else if (entry.isSymbolicLink()) { + try { + const target = realpathSync(full); + if ( + target !== rootRealPath && + !target.startsWith(`${rootRealPath}${sep}`) + ) { + continue; + } + const st = statSync(target); + if (st.isDirectory()) { + if (isV2Excluded(entry.name, true)) continue; + collectSkillFilesV2(dir, rel, rootRealPath, results); + } else if (st.isFile()) { + results.push({ + relativePath: rel, + content: normalizeV2Content(readFileSync(target)), + }); + } + } catch { + // Dangling symlink: skipped, matching Skills CLI behavior. + } + } else if (entry.isFile()) { + results.push({ + relativePath: rel, + content: normalizeV2Content(readFileSync(full)), + }); + } + } +} + +function computeSkillFolderHashV2(skillDir: string): string { + const rootRealPath = realpathSync(skillDir); + const files: Array<{ relativePath: string; content: Buffer }> = []; + collectSkillFilesV2(skillDir, "", rootRealPath, files); + files.sort((a, b) => + Buffer.compare( + Buffer.from(a.relativePath, "utf8"), + Buffer.from(b.relativePath, "utf8"), + ), + ); + const hash = createHash("sha256"); + for (const file of files) { + hash.update(Buffer.from(file.relativePath, "utf8")); + hash.update("\0"); + hash.update(String(file.content.length)); + hash.update("\0"); + hash.update(file.content); + } + return hash.digest("hex"); +} + +function computeSkillFolderHash(skillDir: string, lockVersion: number): string { + return lockVersion >= 2 + ? computeSkillFolderHashV2(skillDir) + : computeSkillFolderHashV1(skillDir); +} + function resolveSkills( repoRoot: string, - lock: { skills: Record } | null, + lock: { version: number; skills: Record } | null, ): SkillState[] { if (!lock) return []; return Object.keys(lock.skills) @@ -235,7 +333,7 @@ function resolveSkills( hashMatchesLock: null, }; } - const hash = computeSkillFolderHash(path); + const hash = computeSkillFolderHash(path, lock.version); return { layout, path: relative(repoRoot, path).split(sep).join("/"), @@ -307,11 +405,18 @@ function landingFacts(profile: string): PolicyFact[] { function resolveLock( repoRoot: string, -): { lock: { skills: Record } | null; facts: PolicyFact[] } { +): { + lock: { version: number; skills: Record } | null; + facts: PolicyFact[]; +} { const read = readIfPresent(repoRoot, LOCK_PATH); if (!read.present) return { lock: null, facts: [] }; try { const parsed: unknown = JSON.parse(read.content); + const lockVersion = + isPlainObject(parsed) && typeof parsed["version"] === "number" + ? parsed["version"] + : 1; const skillsRaw = isPlainObject(parsed) ? parsed["skills"] : undefined; if ( skillsRaw === null || @@ -349,7 +454,7 @@ function resolveLock( detail: `${LOCK_PATH}: dropped non-object skill entr${dropped.length === 1 ? "y" : "ies"}: ${dropped.join(", ")}`, }); } - return { lock: { skills }, facts }; + return { lock: { version: lockVersion, skills }, facts }; } catch (error) { return { lock: null, @@ -517,7 +622,7 @@ export function resolvePolicy(repoRoot: string): PolicyResolution { const knownLimitations = [ "network-free: upstream freshness of floating-source skills and GitHub Issue/PR state are not resolved; only committed local state is read", - "skill hash comparison validates installed skill directories against the lock's computedHash using the skills@1.7.0 folder-hash algorithm (locale-sorted relative paths + contents); locale-dependent collation could theoretically differ across environments", + "skill hash comparison validates installed skill directories against the lock's computedHash using both v1 (skills@1.7.0 locale-sorted relative paths + contents) and v2 (skills >= 1.9 byte-sorted length-framed hashSkillFiles) folder-hash algorithms; v1 locale-dependent collation could theoretically differ across environments", "the landing-policy check is an internal consistency check of the operating model text, not a semantic policy evaluation", "this resolver reports facts only; it does not authorize, apply or overwrite policy", ];