Skip to content

Commit bf5541c

Browse files
suryaiyer95claude
andauthored
feat: ship builtin skills to customers via postinstall (#279)
* feat: ship builtin skills to ~/.altimate/builtin/ via postinstall ## What All skills (dbt, SQL, training, compliance) are now available to customers with zero setup. On every `npm install`/upgrade: - `postinstall.mjs` copies skills from the package to `~/.altimate/builtin/` - The directory is fully wiped and replaced — each release owns it entirely - Skill discovery adds a dedicated scan of `~/.altimate/builtin/` in `skill.ts` ## Skills shipped (22 total) **dbt:** dbt-develop, dbt-test, dbt-docs, dbt-troubleshoot, dbt-analyze, generate-tests, model-scaffold, yaml-config, incremental-logic, medallion-patterns, impact-analysis **SQL:** sql-review, sql-translate, query-optimize, lineage-diff, schema-migration, pii-audit, cost-report **Training:** teach, train, training-status **Viz:** data-viz ## Design - `~/.altimate/builtin/` — release-managed, never user-edited - `~/.altimate/skills/` — user-owned, never touched by installs - `.opencode/skills/` (project) — highest priority, overrides everything - Reference files (layer-patterns.md, etc.) ship alongside SKILL.md and are read on-demand by the agent — same as user-installed skills Co-Authored-By: Claude Sonnet 4.6 <[email protected]> * refactor: use .opencode/skills/ as source instead of src/skill/builtin/ Skills already live in .opencode/skills/ — no need to duplicate them into src/. publish.ts now copies from ../../.opencode/skills (repo root) into the dist package. src/skill/builtin/ removed entirely. Add 6 new skills to .opencode/skills/ that were missing: generate-tests, model-scaffold, yaml-config, medallion-patterns, incremental-logic, impact-analysis Co-Authored-By: Claude Sonnet 4.6 <[email protected]> * chore: remove unused new skills (generate-tests, model-scaffold, yaml-config, medallion-patterns, incremental-logic, impact-analysis) * revert: restore tool/skill.ts to match main (cosmetic comment was unintended) * test: verify ~/.altimate/builtin/ skill discovery and project override * chore: protect postinstall.mjs and .opencode/skills/ from upstream overwrites --------- Co-authored-by: Claude Sonnet 4.6 <[email protected]>
1 parent eed2dc0 commit bf5541c

5 files changed

Lines changed: 141 additions & 0 deletions

File tree

‎packages/opencode/script/postinstall.mjs‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,39 @@ function printWelcome(version) {
115115
out(bot)
116116
}
117117

118+
function copyDirRecursive(src, dst) {
119+
fs.mkdirSync(dst, { recursive: true })
120+
for (const entry of fs.readdirSync(src, { withFileTypes: true })) {
121+
const srcPath = path.join(src, entry.name)
122+
const dstPath = path.join(dst, entry.name)
123+
if (entry.isDirectory()) {
124+
copyDirRecursive(srcPath, dstPath)
125+
} else {
126+
fs.copyFileSync(srcPath, dstPath)
127+
}
128+
}
129+
}
130+
131+
/**
132+
* Copy bundled skills to ~/.altimate/builtin/ on every install/upgrade.
133+
* The entire directory is wiped and replaced so each release is the single
134+
* source of truth. Intentionally separate from ~/.altimate/skills/ which users own.
135+
*/
136+
function copySkillsToAltimate() {
137+
try {
138+
const skillsSrc = path.join(__dirname, "skills")
139+
if (!fs.existsSync(skillsSrc)) return // skills not in package (shouldn't happen)
140+
141+
const builtinDst = path.join(os.homedir(), ".altimate", "builtin")
142+
143+
// Full wipe-and-replace — each release owns this directory entirely
144+
if (fs.existsSync(builtinDst)) fs.rmSync(builtinDst, { recursive: true, force: true })
145+
copyDirRecursive(skillsSrc, builtinDst)
146+
} catch {
147+
// Non-fatal — skills can be installed manually
148+
}
149+
}
150+
118151
/**
119152
* Write a marker file so the CLI can show a welcome/upgrade banner on first run.
120153
* npm v7+ silences postinstall stdout, so the CLI reads this marker at startup instead.
@@ -144,6 +177,7 @@ async function main() {
144177
// On Windows, the .exe is already included in the package and bin field points to it
145178
// No postinstall setup needed
146179
if (version) writeUpgradeMarker(version)
180+
copySkillsToAltimate()
147181
return
148182
}
149183

@@ -161,6 +195,7 @@ async function main() {
161195
// Write marker only — npm v7+ suppresses all postinstall output.
162196
// The CLI picks up the marker and shows the welcome box on first run.
163197
if (version) writeUpgradeMarker(version)
198+
copySkillsToAltimate()
164199
} catch (error) {
165200
console.error("Failed to setup altimate-code binary:", error.message)
166201
process.exit(1)

‎packages/opencode/script/publish.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const version = Object.values(binaries)[0]
2929

3030
await $`mkdir -p ./dist/${pkg.name}`
3131
await $`cp -r ./bin ./dist/${pkg.name}/bin`
32+
await $`cp -r ../../.opencode/skills ./dist/${pkg.name}/skills`
3233
await $`cp ./script/postinstall.mjs ./dist/${pkg.name}/postinstall.mjs`
3334
await Bun.file(`./dist/${pkg.name}/LICENSE`).write(await Bun.file("../../LICENSE").text())
3435
await Bun.file(`./dist/${pkg.name}/CHANGELOG.md`).write(await Bun.file("../../CHANGELOG.md").text())
@@ -70,6 +71,7 @@ const unscopedDir = `./dist/${unscopedName}`
7071
try {
7172
await $`mkdir -p ${unscopedDir}`
7273
await $`cp -r ./bin ${unscopedDir}/bin`
74+
await $`cp -r ../../.opencode/skills ${unscopedDir}/skills`
7375
await $`cp ./script/postinstall.mjs ${unscopedDir}/postinstall.mjs`
7476
await Bun.file(`${unscopedDir}/LICENSE`).write(await Bun.file("../../LICENSE").text())
7577
await Bun.file(`${unscopedDir}/CHANGELOG.md`).write(await Bun.file("../../CHANGELOG.md").text())

‎packages/opencode/src/skill/skill.ts‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,23 @@ export namespace Skill {
104104
})
105105
}
106106

107+
// altimate_change start - scan ~/.altimate/builtin/ for release-managed builtin skills
108+
// This path is fully owned by postinstall (wipe-and-replace on every release).
109+
// Kept separate from user-editable skill dirs so users never accidentally modify builtins.
110+
if (!Flag.OPENCODE_DISABLE_EXTERNAL_SKILLS) {
111+
const builtinDir = path.join(Global.Path.home, ".altimate", "builtin")
112+
if (await Filesystem.isDir(builtinDir)) {
113+
const matches = await Glob.scan(SKILL_PATTERN, {
114+
cwd: builtinDir,
115+
absolute: true,
116+
include: "file",
117+
symlink: true,
118+
})
119+
await Promise.all(matches.map(addSkill))
120+
}
121+
}
122+
// altimate_change end
123+
107124
// Scan external skill directories (.claude/skills/, .agents/skills/, etc.)
108125
// Load global (home) first, then project-level (so project-level overwrites)
109126
if (!Flag.OPENCODE_DISABLE_EXTERNAL_SKILLS) {

‎packages/opencode/test/skill/skill.test.ts‎

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,89 @@ description: A skill in the .agents/skills directory.
327327
})
328328
})
329329

330+
test("discovers builtin skills from ~/.altimate/builtin/", async () => {
331+
await using tmp = await tmpdir({ git: true })
332+
333+
const originalHome = process.env.OPENCODE_TEST_HOME
334+
process.env.OPENCODE_TEST_HOME = tmp.path
335+
336+
try {
337+
const builtinDir = path.join(tmp.path, ".altimate", "builtin", "builtin-skill")
338+
await fs.mkdir(builtinDir, { recursive: true })
339+
await Bun.write(
340+
path.join(builtinDir, "SKILL.md"),
341+
`---
342+
name: builtin-skill
343+
description: A builtin skill shipped with the package.
344+
---
345+
346+
# Builtin Skill
347+
`,
348+
)
349+
350+
await Instance.provide({
351+
directory: tmp.path,
352+
fn: async () => {
353+
const skills = await Skill.all()
354+
expect(skills.length).toBe(1)
355+
expect(skills[0].name).toBe("builtin-skill")
356+
expect(skills[0].location).toContain(path.join(".altimate", "builtin", "builtin-skill", "SKILL.md"))
357+
},
358+
})
359+
} finally {
360+
process.env.OPENCODE_TEST_HOME = originalHome
361+
}
362+
})
363+
364+
test("project skill overrides builtin skill with same name", async () => {
365+
await using tmp = await tmpdir({
366+
git: true,
367+
init: async (dir) => {
368+
const projectSkillDir = path.join(dir, ".claude", "skills", "shared-skill")
369+
await Bun.write(
370+
path.join(projectSkillDir, "SKILL.md"),
371+
`---
372+
name: shared-skill
373+
description: Project-level version.
374+
---
375+
376+
# Project Skill
377+
`,
378+
)
379+
},
380+
})
381+
382+
const originalHome = process.env.OPENCODE_TEST_HOME
383+
process.env.OPENCODE_TEST_HOME = tmp.path
384+
385+
try {
386+
const builtinDir = path.join(tmp.path, ".altimate", "builtin", "shared-skill")
387+
await fs.mkdir(builtinDir, { recursive: true })
388+
await Bun.write(
389+
path.join(builtinDir, "SKILL.md"),
390+
`---
391+
name: shared-skill
392+
description: Builtin version.
393+
---
394+
395+
# Builtin Skill
396+
`,
397+
)
398+
399+
await Instance.provide({
400+
directory: tmp.path,
401+
fn: async () => {
402+
const skills = await Skill.all()
403+
const skill = skills.find((s) => s.name === "shared-skill")
404+
expect(skill).toBeDefined()
405+
expect(skill!.description).toBe("Project-level version.")
406+
},
407+
})
408+
} finally {
409+
process.env.OPENCODE_TEST_HOME = originalHome
410+
}
411+
})
412+
330413
test("properly resolves directories that skills live in", async () => {
331414
await using tmp = await tmpdir({
332415
git: true,

‎script/upstream/utils/config.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,10 @@ export const defaultConfig: MergeConfig = {
268268
"packages/opencode/script/build.ts",
269269
"packages/opencode/script/publish.ts",
270270
"packages/opencode/script/bump-version.ts",
271+
// postinstall copies builtin skills to ~/.altimate/builtin/ — our addition
272+
"packages/opencode/script/postinstall.mjs",
273+
// Builtin skills shipped to customers — fully owned by Altimate
274+
".opencode/skills/**",
271275
// Bin wrappers are Altimate-branded
272276
"packages/opencode/bin/**",
273277
"experiments/**",

0 commit comments

Comments
 (0)