Skip to content

Beautiful, AI-native markdown IDE and LLM wiki

fix(ok): seed built-in skills on first run only, not every launch (#3582)

tim-inkeep4634ffb82878
diff --git a/.changeset/builtin-skill-placement.md b/.changeset/builtin-skill-placement.md
new file mode 100644
index 000000000..ab416d5b1
--- /dev/null
+++ b/.changeset/builtin-skill-placement.md
@@ -0,0 +1,19 @@
+---
+'@inkeep/open-knowledge': patch
+---
+
+Stop re-seeding the built-in skills into agents you removed them from
+
+Seeding `open-knowledge-discovery` and `open-knowledge-write-skill` ran on every
+launch and topped the bundles back up into every agent folder on the machine, so
+uninstalling one from a single agent was undone the next time OpenKnowledge
+started. Agents that read the shared `~/.agents/skills` hub also ended up with a
+second copy under their own path and reported a name collision.
+
+Seeding is now a first-run act: once a bundle exists anywhere the user can reach
+it, its host set is theirs to choose and the sweep leaves it alone. A machine
+where the bundle is absent everywhere still gets the full set, so a fresh install
+is unchanged.
+
+Uninstalling a built-in from one agent also works now — the reserved-name gate
+that guards authoring was rejecting the lifecycle verbs too.
diff --git a/packages/cli/src/commands/repair-skills.placement.test.ts b/packages/cli/src/commands/repair-skills.placement.test.ts
new file mode 100644
index 000000000..e92fb6770
--- /dev/null
+++ b/packages/cli/src/commands/repair-skills.placement.test.ts
@@ -0,0 +1,110 @@
+/**
+ * CLI parity for the desktop reclaim's first-run-only seeding: once the bundle
+ * exists anywhere the user can reach it, the sweep leaves the host set alone.
+ */
+import { existsSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { join } from 'node:path';
+import { afterEach, describe, expect, test } from 'vitest';
+import { repairSkills } from './repair-skills.ts';
+
+const NAME = 'open-knowledge-discovery';
+
+/** hostDir (existence gate) -> skillsRoot (write target), per `USER_SKILL_HOSTS`. */
+const HOSTS: Array<[string, string]> = [
+ ['.claude', '.claude/skills'],
+ ['.cursor', '.cursor/skills'],
+ ['.codex', '.codex/skills'],
+ ['.copilot', '.copilot/skills'],
+ ['.opencode', '.opencode/skills'],
+ ['.pi', '.pi/agent/skills'],
+ ['.gemini', '.gemini/skills'],
+];
+
+const cleanup: string[] = [];
+afterEach(() => {
+ for (const p of cleanup.splice(0)) {
+ try {
+ rmSync(p, { recursive: true, force: true });
+ } catch {
+ /* best effort */
+ }
+ }
+});
+
+function scratch(): { home: string; project: string; bundle: string } {
+ const root = mkdtempSync(join(tmpdir(), 'ok-cli-placement-'));
+ cleanup.push(root);
+ const home = join(root, 'home');
+ const project = join(root, 'project');
+ const bundle = join(root, 'bundle');
+ for (const [hostDir] of HOSTS) mkdirSync(join(home, hostDir), { recursive: true });
+ mkdirSync(join(home, '.agents'), { recursive: true });
+ mkdirSync(join(project, '.ok'), { recursive: true });
+ mkdirSync(bundle, { recursive: true });
+ writeFileSync(join(bundle, 'SKILL.md'), `---\nname: ${NAME}\n---\n# body\n`);
+ return { home, project, bundle };
+}
+
+function deps(bundle: string) {
+ return {
+ resolveProjectBundledSkillDir: () => bundle,
+ resolveUserBundledSkillDir: () => bundle,
+ readBundledVersion: async () => '9.9.9',
+ readRecordedVersion: async () => null,
+ writeRecordedVersion: async () => {},
+ recordEvent: async () => {},
+ readBundleDecision: async () => true,
+ writeBundleDecision: async () => {},
+ removeBundleFromDisk: () => {},
+ };
+}
+
+const dest = (home: string, root: string) => join(home, root, NAME);
+
+function installAt(home: string, root: string): void {
+ const dir = dest(home, root);
+ mkdirSync(dir, { recursive: true });
+ writeFileSync(join(dir, 'SKILL.md'), `---\nname: ${NAME}\n---\n# body\n`);
+}
+
+const sweep = (s: { home: string; project: string; bundle: string }) =>
+ repairSkills({
+ projectDir: s.project,
+ home: s.home,
+ logger: () => {},
+ deps: deps(s.bundle),
+ });
+
+describe('repairSkills user sweep placement', () => {
+ test('seeds the default host set when the bundle is nowhere', async () => {
+ const s = scratch();
+
+ await sweep(s);
+
+ for (const [, root] of HOSTS) expect(existsSync(dest(s.home, root))).toBe(true);
+ expect(existsSync(dest(s.home, '.agents/skills'))).toBe(true);
+ });
+
+ test('hub-only stays hub-only', async () => {
+ const s = scratch();
+ installAt(s.home, '.agents/skills');
+
+ await sweep(s);
+
+ expect(existsSync(dest(s.home, '.agents/skills'))).toBe(true);
+ for (const [, root] of HOSTS) expect(existsSync(dest(s.home, root))).toBe(false);
+ });
+
+ test('an uninstalled agent is not re-seeded', async () => {
+ const s = scratch();
+ installAt(s.home, '.agents/skills');
+ for (const [, root] of HOSTS) installAt(s.home, root);
+ rmSync(dest(s.home, '.codex/skills'), { recursive: true, force: true });
+
+ await sweep(s);
+
+ expect(existsSync(dest(s.home, '.codex/skills'))).toBe(false);
+ expect(existsSync(dest(s.home, '.claude/skills'))).toBe(true);
+ });
+});
diff --git a/packages/cli/src/commands/repair-skills.ts b/packages/cli/src/commands/repair-skills.ts
index 382feda73..c9d669544 100644
--- a/packages/cli/src/commands/repair-skills.ts
+++ b/packages/cli/src/commands/repair-skills.ts
@@ -312,6 +312,44 @@ function installUserBundleToHostDirs(
): { entries: UserSkillEntry[]; anyWritten: boolean; anyDestinationSucceeded: boolean } {
const entries: UserSkillEntry[] = [];
const centralDest = join(home, '.agents', 'skills', bundleDirName);
+ // Already installed somewhere ⇒ the user's current host set is the answer.
+ // Seeding is a FIRST-RUN act, not a per-run top-up: without this an uninstall
+ // from one agent is undone by the next sweep, and a host that merely reads the
+ // shared hub gets a duplicate under its own path. `userBundleExists` is the
+ // same "anywhere?" question the version fast-path already asks. Sibling of the
+ // desktop reclaim's identical gate — keep the two aligned.
+ if (userBundleExists(home, bundleDirName, fs)) {
+ // Report the destinations that actually hold a copy. A host the user removed
+ // it from is absent from the list rather than reported as a skip — it is not
+ // a destination any more.
+ if (fs.existsSync(centralDest)) {
+ entries.push({ kind: 'central', path: centralDest, outcome: 'skipped-present' });
+ }
+ for (const host of USER_SKILL_HOSTS) {
+ const hostDest = join(home, host.skillsRoot, bundleDirName);
+ if (hostDest === centralDest) continue;
+ if (!fs.existsSync(join(home, host.hostDir))) {
+ entries.push({
+ kind: 'host',
+ editorId: host.editorId,
+ hostDir: host.hostDir,
+ path: hostDest,
+ outcome: 'skipped-host-absent',
+ });
+ continue;
+ }
+ if (fs.existsSync(hostDest)) {
+ entries.push({
+ kind: 'host',
+ editorId: host.editorId,
+ hostDir: host.hostDir,
+ path: hostDest,
+ outcome: 'skipped-present',
+ });
+ }
+ }
+ return { entries, anyWritten: false, anyDestinationSucceeded: true };
+ }
// SEED-IF-ABSENT: guarantee the built-in is PRESENT
// but never OVERWRITE an existing copy — that copy may be a user-applied
// skills.sh update. Updates flow through the manual "update available" path,
diff --git a/packages/desktop/src/main/skill-reclaim.placement.test.ts b/packages/desktop/src/main/skill-reclaim.placement.test.ts
new file mode 100644
index 000000000..61ebbf19e
--- /dev/null
+++ b/packages/desktop/src/main/skill-reclaim.placement.test.ts
@@ -0,0 +1,147 @@
+/**
+ * Seeding a user-global built-in is a FIRST-RUN act, not a per-launch top-up.
+ *
+ * Once the bundle exists anywhere the user can reach it, its host set is the
+ * user's to choose: unchecking an agent in the install menu has to survive the
+ * next launch, and an agent that only reads the shared `~/.agents/skills` hub
+ * must not also get a copy under its own path.
+ */
+import { existsSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { dirname, join } from 'node:path';
+import { afterEach, describe, expect, test } from 'vitest';
+import { reclaimUserSkillsOnLaunch } from './skill-reclaim.ts';
+
+const EXE = '/Applications/OpenKnowledge.app/Contents/MacOS/OpenKnowledge';
+const BUNDLES = [{ id: 'discovery', name: 'open-knowledge-discovery' }] as const;
+const NAME = 'open-knowledge-discovery';
+
+/** hostDir (existence gate) -> skillsRoot (write target), per `USER_SKILL_HOSTS`. */
+const HOSTS: Array<[string, string]> = [
+ ['.claude', '.claude/skills'],
+ ['.cursor', '.cursor/skills'],
+ ['.codex', '.codex/skills'],
+ ['.copilot', '.copilot/skills'],
+ ['.opencode', '.opencode/skills'],
+ ['.pi', '.pi/agent/skills'],
+ ['.gemini', '.gemini/skills'],
+];
+
+const cleanup: string[] = [];
+afterEach(() => {
+ for (const p of cleanup.splice(0)) {
+ try {
+ rmSync(p, { recursive: true, force: true });
+ } catch {
+ /* best effort */
+ }
+ }
+});
+
+function bundleDir(): string {
+ const d = mkdtempSync(join(tmpdir(), 'ok-placement-bundle-'));
+ cleanup.push(d);
+ writeFileSync(join(d, 'SKILL.md'), `---\nname: ${NAME}\n---\n# body\n`);
+ return d;
+}
+
+/** A `$HOME` with every host home present, so only placement decides the writes. */
+function homeWithAllHosts(): string {
+ const h = mkdtempSync(join(tmpdir(), 'ok-placement-home-'));
+ cleanup.push(h);
+ for (const [hostDir] of HOSTS) mkdirSync(join(h, hostDir), { recursive: true });
+ mkdirSync(join(h, '.agents'), { recursive: true });
+ return h;
+}
+
+const dest = (home: string, root: string) => join(home, root, NAME);
+
+/** Put a copy of the bundle at one location, as a prior install would have. */
+function installAt(home: string, root: string): void {
+ const dir = dest(home, root);
+ mkdirSync(dir, { recursive: true });
+ writeFileSync(join(dir, 'SKILL.md'), `---\nname: ${NAME}\n---\n# body\n`);
+}
+
+function run(home: string, bundle: string) {
+ return reclaimUserSkillsOnLaunch({
+ home,
+ isPackaged: true,
+ platform: 'darwin',
+ executablePath: EXE,
+ deps: {
+ userGlobalBundles: BUNDLES,
+ resolveBundledSkillDir: () => bundle,
+ readServerPackageVersion: async () => '9.9.9',
+ writeTargetVersion: async () => {},
+ recordSkillInstallEvent: async () => {},
+ readBundleDecision: async () => true,
+ writeBundleDecision: async () => {},
+ removeBundleFromDisk: () => {},
+ },
+ logger: { event: () => {}, warn: () => {} },
+ });
+}
+
+describe('reclaimUserSkillsOnLaunch placement', () => {
+ test('seeds the default host set when the bundle is nowhere (first run)', async () => {
+ const home = homeWithAllHosts();
+
+ await run(home, bundleDir());
+
+ for (const [, root] of HOSTS) expect(existsSync(dest(home, root))).toBe(true);
+ expect(existsSync(dest(home, '.agents/skills'))).toBe(true);
+ });
+
+ test('hub-only stays hub-only — no host copies are topped up', async () => {
+ const home = homeWithAllHosts();
+ installAt(home, '.agents/skills');
+
+ await run(home, bundleDir());
+
+ expect(existsSync(dest(home, '.agents/skills'))).toBe(true);
+ for (const [, root] of HOSTS) expect(existsSync(dest(home, root))).toBe(false);
+ });
+
+ test('an uninstall from one agent survives the next launch', async () => {
+ const home = homeWithAllHosts();
+ // Installed everywhere, then the user unchecks Codex.
+ installAt(home, '.agents/skills');
+ for (const [, root] of HOSTS) installAt(home, root);
+ rmSync(dest(home, '.codex/skills'), { recursive: true, force: true });
+
+ await run(home, bundleDir());
+
+ expect(existsSync(dest(home, '.codex/skills'))).toBe(false);
+ expect(existsSync(dest(home, '.claude/skills'))).toBe(true);
+ });
+
+ test('removing every copy re-seeds — the presence guarantee still holds', async () => {
+ const home = homeWithAllHosts();
+ const bundle = bundleDir();
+ await run(home, bundle);
+
+ rmSync(dest(home, '.agents/skills'), { recursive: true, force: true });
+ for (const [, root] of HOSTS) rmSync(dest(home, root), { recursive: true, force: true });
+
+ await run(home, bundle);
+
+ expect(existsSync(dest(home, '.agents/skills'))).toBe(true);
+ expect(existsSync(dest(home, '.claude/skills'))).toBe(true);
+ });
+
+ test('a host installed later is not auto-seeded', async () => {
+ const home = homeWithAllHosts();
+ const bundle = bundleDir();
+ // Existing install that predates the new agent.
+ installAt(home, '.agents/skills');
+ installAt(home, '.claude/skills');
+ // The user installs a new agent; its home appears with no OK skill in it.
+ const newHost = join(home, '.opencode');
+ mkdirSync(dirname(newHost), { recursive: true });
+
+ await run(home, bundle);
+
+ expect(existsSync(dest(home, '.opencode/skills'))).toBe(false);
+ });
+});
diff --git a/packages/desktop/src/main/skill-reclaim.ts b/packages/desktop/src/main/skill-reclaim.ts
index 997be55a5..0f29c3420 100644
--- a/packages/desktop/src/main/skill-reclaim.ts
+++ b/packages/desktop/src/main/skill-reclaim.ts
@@ -312,6 +312,21 @@ interface ReclaimUserSkillsOpts {
* `installUserBundleToHostDirs` in `packages/cli/src/commands/repair-skills.ts`
* — keep the shape aligned.
*/
+/**
+ * True when this bundle already exists at ANY user-global location — the hub or
+ * any host root.
+ *
+ * Placement is the user's, and for an in-place skill the on-disk reality is the
+ * host-set truth (there is no marker to consult — the install verb deliberately
+ * records none for in-place skills). So "installed somewhere" is the only honest
+ * signal that a choice has been made, and the sweep must not second-guess it by
+ * topping the bundle back up into hosts the user removed it from.
+ */
+function bundleInstalledAnywhere(home: string, bundleDirName: string, fs: SkillFsOps): boolean {
+ if (fs.existsSync(join(home, '.agents', 'skills', bundleDirName))) return true;
+ return USER_SKILL_HOSTS.some((host) => fs.existsSync(join(home, host.skillsRoot, bundleDirName)));
+}
+
function installUserBundleToHostDirs(
home: string,
bundleDirName: string,
@@ -322,6 +337,43 @@ function installUserBundleToHostDirs(
): { entries: UserSkillReclaimEntry[]; anyWritten: boolean; anyDestinationSucceeded: boolean } {
const entries: UserSkillReclaimEntry[] = [];
const centralDest = join(home, '.agents', 'skills', bundleDirName);
+ // Already installed somewhere ⇒ the user's current host set is the answer.
+ // Seeding is a FIRST-RUN act, not a per-launch top-up: without this an
+ // uninstall from one agent is undone on the next launch, and a host that
+ // merely reads the shared hub gets a duplicate under its own path.
+ if (bundleInstalledAnywhere(home, bundleDirName, fs)) {
+ // Report the destinations that actually hold a copy, so the event log still
+ // shows where the bundle lives. A host the user removed it from is simply
+ // absent from the list rather than reported as a skip — it is not a
+ // destination any more.
+ if (fs.existsSync(centralDest)) {
+ entries.push({ kind: 'central', path: centralDest, status: 'skipped-present' });
+ }
+ for (const host of USER_SKILL_HOSTS) {
+ const hostDest = join(home, host.skillsRoot, bundleDirName);
+ if (hostDest === centralDest) continue;
+ if (!fs.existsSync(join(home, host.hostDir))) {
+ entries.push({
+ kind: 'host',
+ hostDir: host.hostDir,
+ editorId: host.editorId,
+ path: hostDest,
+ status: 'skipped-host-absent',
+ });
+ continue;
+ }
+ if (fs.existsSync(hostDest)) {
+ entries.push({
+ kind: 'host',
+ hostDir: host.hostDir,
+ editorId: host.editorId,
+ path: hostDest,
+ status: 'skipped-present',
+ });
+ }
+ }
+ return { entries, anyWritten: false, anyDestinationSucceeded: true };
+ }
// SEED-IF-ABSENT: the reclaim guarantees the
// built-in is PRESENT (offline-safe), but never OVERWRITES an existing copy —
// that copy may be a user-applied skills.sh update, and force-refreshing it
diff --git a/packages/server/src/api-extension.ts b/packages/server/src/api-extension.ts
index 7ac08e83f..f180913d9 100644
--- a/packages/server/src/api-extension.ts
+++ b/packages/server/src/api-extension.ts
@@ -17917,7 +17917,13 @@ export function createApiExtension(
: skillLiveDocName(body.scope, body.name);
await flushDiskAndDetectOutcome(liveSkillDoc);
- const validity = validateSkillForInstall(skillDir, body.name);
+ // Lifecycle verbs are ordinary for OK's own bundles: the reserved-name
+ // gate exists to stop a user AUTHORING over them, not to stop them being
+ // installed or uninstalled. Without this an uninstall of a built-in is
+ // refused as INVALID_SKILL_SOURCE and its placement can never be edited.
+ const validity = validateSkillForInstall(skillDir, body.name, {
+ allowReservedName: isInternalBundleSkillName(body.name),
+ });
if (!validity.ok) {
errorResponse(
res,