shadok-ai 0.19.24 → 0.19.26

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/dist/server.js CHANGED
@@ -66,7 +66,7 @@ import { resolveSpawnIsolation, osUserFor, homeForUser, tierStateDir, tierStateD
66
66
  import { mayActOnSession, cronCheckAllowed, mayReachGroup, osUserForChannelGroup, cronCheckEnv, cronCheckCommand, statAsUserArgv, parseStatOutput, readAsUserArgv, sameOfferedFile, } from "./group-exec.js";
67
67
  import { mediaDirForGroup, mediaFileMode, parseMediaRequest, groupForMediaKey, passwdGid, mediaDirSpec, mediaDirTrusted, mediaServable, } from "./media-scope.js";
68
68
  import { runPrivileged, TREE_OP_TIMEOUT_MS } from "./privileged.js";
69
- import { HOME_SKILLS_BASE, rewriteSkillsBase } from "./skill-paths.js";
69
+ import { HOME_SKILLS_BASE, missingHomeSkillLinks, rewriteSkillsBase } from "./skill-paths.js";
70
70
  import { instanceKey } from "./paths.js";
71
71
  import { peerFileFor, loadPeers, savePeers, peerFromToken, signPeerToken, newPeer, withSalts, redeemVerdict, redeemPeer, normPeerName, removePeer, ownedByPeer, peersOutFileFor, tierPeersOutSeed, agentInvitePrompt, peerScope, } from "./peers.js";
72
72
  import { loadCrons, saveCrons, upsertCron, removeCron, resolveCronId, nextRunFor, nextRunAfterFailure, isTransient, CRON_MAX_RETRIES, markCronPrompt, isCronPrompt, normalizeSchedule, parseDays, onceAt, stateAfterFire, scheduleLabel, cronTimeZone, defaultTimeZone, systemTimeZone, isValidTimeZone, } from "./crons.js";
@@ -3752,12 +3752,62 @@ function seedSystemSkills() {
3752
3752
  }
3753
3753
  }
3754
3754
  /**
3755
- * Seed a group user's HOME at PROVISION time. Skills are no longer copied here —
3755
+ * Make the conventional `~/.claude/skills/<skill>` path resolve in a group's
3756
+ * HOME, by linking each machine-wide skill into it.
3757
+ *
3758
+ * The skills themselves stay in ONE place (`seedSystemSkills`) — these are
3759
+ * symlinks, not copies, so an updated skill needs no per-HOME refresh. What
3760
+ * this buys is the path: `rewriteSkillsBase` fixes what an agent reads, and
3761
+ * cannot fix what an agent KNOWS. A dropped agent writing a command from habit
3762
+ * reaches for `~/.claude/skills/...`, which exists for the server user and for
3763
+ * every mono-tenant install and, until now, nowhere in a group home — the
3764
+ * answer being a bare `MODULE_NOT_FOUND` that names no better path
3765
+ * (`missingHomeSkillLinks`).
3766
+ *
3767
+ * A directory, never a symlink to the tier: `~/.claude/skills` is also where an
3768
+ * agent keeps the skills it AUTHORS (`healCommonsStrandedScripts`), and that
3769
+ * directory has to stay writable by its owner. For the same reason an existing
3770
+ * name is never touched — `ln -s` without `-f`, so the agent's own copy wins.
3771
+ *
3772
+ * Everything runs AS the group user, like `ensureTierStateDir`: root must not
3773
+ * write through a 0700 HOME it does not own, where an agent could have planted
3774
+ * a symlink.
3775
+ */
3776
+ function linkSystemSkills(user, home) {
3777
+ if (DEPLOYMENT_MODE !== "multi-tenant")
3778
+ return;
3779
+ const dir = path.join(home, ".claude", "skills");
3780
+ try {
3781
+ const system = fs
3782
+ .readdirSync(SYSTEM_SKILLS_DIR, { withFileTypes: true })
3783
+ .filter((d) => d.isDirectory())
3784
+ .map((d) => d.name);
3785
+ if (!system.length)
3786
+ return; // nothing seeded (SHADOK_SEED_SKILLS=0, or a failed seed)
3787
+ if (!spawnAsUserSync(user, "mkdir", ["-p", dir]).ok) {
3788
+ console.log(`skills: could not create ${dir} as ${user} — left alone`);
3789
+ return;
3790
+ }
3791
+ const have = spawnAsUserSync(user, "ls", ["-1", dir]).stdout.split("\n");
3792
+ const missing = missingHomeSkillLinks(system, have);
3793
+ for (const name of missing) {
3794
+ spawnAsUserSync(user, "ln", ["-s", path.join(SYSTEM_SKILLS_DIR, name), path.join(dir, name)]);
3795
+ }
3796
+ if (missing.length)
3797
+ console.log(`skills: linked ${missing.length} machine-wide skills into ${dir}`);
3798
+ }
3799
+ catch (e) {
3800
+ console.log(`skills: could not link the machine-wide skills into ${dir} — ${e instanceof Error ? e.message : String(e)}`);
3801
+ }
3802
+ }
3803
+ /**
3804
+ * Seed a group user's HOME at PROVISION time. The skills are not COPIED here —
3756
3805
  * they live in the machine-wide Enterprise tier (`seedSystemSkills`), read by
3757
- * every user. Kept as the hook for any future per-HOME provisioning step.
3806
+ * every user — but they are LINKED, so the conventional `~/.claude/skills` path
3807
+ * an agent reaches for from habit resolves (`linkSystemSkills`).
3758
3808
  */
3759
- async function seedGroupHome(_home, _user) {
3760
- /* skills are machine-wide now; nothing per-HOME to seed */
3809
+ async function seedGroupHome(home, user) {
3810
+ linkSystemSkills(user, home);
3761
3811
  }
3762
3812
  /** Does an OS user already exist? Used to make provisioning idempotent. */
3763
3813
  async function osUserExists(u) {
@@ -8161,6 +8211,11 @@ function preseedGroupHomes() {
8161
8211
  // merely RESUMED never runs the spawn path, so it stayed without an identity
8162
8212
  // until someone reloaded it. Idempotent: skipped the moment the key is there.
8163
8213
  ensureAgentSshKey(user, home);
8214
+ // And the skills' conventional path, at BOOT and not only at provisioning:
8215
+ // every HOME that predates this, and every one a docker recreate wiped,
8216
+ // would otherwise keep answering MODULE_NOT_FOUND. Idempotent — an existing
8217
+ // name is left exactly as it is.
8218
+ linkSystemSkills(user, home);
8164
8219
  }
8165
8220
  seedCommonsPeersOut();
8166
8221
  }