dsh-agent-team-presets 0.3.3 → 0.3.4

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.
Files changed (50) hide show
  1. package/NOTICE +4 -3
  2. package/README.md +2 -2
  3. package/README.zh.md +2 -2
  4. package/assets/card-patches/catalog.json +10 -0
  5. package/assets/card-patches/dsh-context-0.87.0.client.js.gz +0 -0
  6. package/docs/builtin-team-skills.md +4 -4
  7. package/docs/builtin-team-skills.zh.md +4 -4
  8. package/docs/guide/install.md +1 -1
  9. package/docs/guide/install.zh.md +1 -1
  10. package/docs/guide/integrations.md +1 -1
  11. package/docs/guide/integrations.zh.md +1 -1
  12. package/docs/guide/team-skills.md +21 -9
  13. package/docs/guide/team-skills.zh.md +21 -9
  14. package/icon.webp +0 -0
  15. package/lib/client.js +952 -176
  16. package/lib/index.js +560 -297
  17. package/lib/typert.host.js +402 -29
  18. package/lib/typert.remote-client.d.ts +9 -9
  19. package/lib/typert.remote-client.d.ts.map +1 -1
  20. package/lib/typert.remote-client.js +402 -29
  21. package/lib/types/client/TeamImportDialog.d.ts +4 -15
  22. package/lib/types/client/TeamImportDialog.js +29 -25
  23. package/lib/types/client/TeamPresetsSection.js +14 -5
  24. package/lib/types/client/TeamSkillsView.d.ts +3 -3
  25. package/lib/types/client/TeamSkillsView.js +56 -12
  26. package/lib/types/client/locales.d.ts +1 -1
  27. package/lib/types/client/locales.js +60 -8
  28. package/lib/types/client/team-presets-controller.d.ts +15 -2
  29. package/lib/types/client/team-presets-controller.js +86 -30
  30. package/lib/types/client/team-skills-controller.d.ts +14 -5
  31. package/lib/types/client/team-skills-controller.js +71 -37
  32. package/lib/types/index.js +5 -7
  33. package/lib/types/preset-editor.js +3 -4
  34. package/lib/types/preset-transfer.d.ts +1 -1
  35. package/lib/types/presets.d.ts +21 -23
  36. package/lib/types/presets.js +72 -36
  37. package/lib/types/team-skills/import.d.ts +17 -7
  38. package/lib/types/team-skills/import.js +115 -21
  39. package/lib/types/team-skills/index.d.ts +1 -12
  40. package/lib/types/team-skills/index.js +3 -26
  41. package/lib/types/team-skills/manager.d.ts +3 -3
  42. package/lib/types/team-skills/manager.js +39 -81
  43. package/lib/types/team-skills/official-bindings.d.ts +29 -0
  44. package/lib/types/team-skills/official-bindings.js +51 -0
  45. package/lib/types/team-skills/service.d.ts +7 -12
  46. package/lib/types/team-skills/service.js +125 -56
  47. package/lib/types/team-skills/store.d.ts +16 -6
  48. package/lib/types/team-skills/store.js +119 -14
  49. package/lib/types/types.d.ts +18 -4
  50. package/package.json +4 -1
package/lib/index.js CHANGED
@@ -54,64 +54,87 @@ const IMPLICIT_TOOLS = [SKILL_TOOL_NAME];
54
54
  function toolMode(agent) {
55
55
  return agent.toolMode ?? (agent.tools.length === 0 ? "all" : "custom");
56
56
  }
57
- /** The member name grammar the Agent Teams service accepts. */
57
+ /** The grammar and length of a configured member's summon target. */
58
58
  const MEMBER_TARGET = /^[a-z0-9]+(?:-[a-z0-9]+)*$/u;
59
+ const MEMBER_TARGET_LIMIT = 64;
60
+ /** Return the member's normalized name when it can be used as a target. */
61
+ function preferredMemberTarget(member) {
62
+ const target = member.name.trim().toLowerCase();
63
+ return target !== "lead" && target.length <= MEMBER_TARGET_LIMIT && MEMBER_TARGET.test(target) ? target : void 0;
64
+ }
59
65
  /**
60
- * Derive a teammate target from one member's display name.
61
- *
62
- * Teammate names are permanent, lower-kebab-case, and never reused, so a
63
- * display name that already satisfies the grammar is kept and any other name
64
- * is transliterated to `member-<index>`. The display name still reaches the
65
- * captain through the roster.
66
+ * Claim a target for one member after the Team's preferred targets are reserved.
66
67
  * @param member - the configured member.
67
68
  * @param index - zero-based position in the Team's member list.
68
69
  * @param used - targets already taken in this Team; the returned target is added.
69
70
  * @returns the teammate target this member is summoned under.
70
71
  */
71
72
  function memberTarget(member, index, used) {
72
- const candidate = member.name.trim().toLowerCase();
73
- const base = MEMBER_TARGET.test(candidate) && candidate !== "lead" && candidate.length <= 64 ? candidate : `member-${index + 1}`;
74
- let target = base;
75
- let suffix = 2;
76
- while (used.has(target)) {
77
- target = `${base}-${suffix}`;
78
- suffix += 1;
73
+ const preferred = preferredMemberTarget(member);
74
+ let target;
75
+ if (preferred === void 0) {
76
+ let number = index + 1;
77
+ while (used.has(`member-${number}`)) number += 1;
78
+ target = `member-${number}`;
79
+ } else {
80
+ target = preferred;
81
+ let suffix = 2;
82
+ while (used.has(target)) {
83
+ const tail = `-${suffix}`;
84
+ target = `${preferred.slice(0, MEMBER_TARGET_LIMIT - tail.length).replace(/-+$/u, "")}${tail}`;
85
+ suffix += 1;
86
+ }
79
87
  }
80
88
  used.add(target);
81
89
  return target;
82
90
  }
83
91
  /**
84
- * Resolve one member by its display name or its teammate target.
85
- *
86
- * The resolved target travels with the member, so a caller never re-derives it
87
- * and cannot disagree with the roster about the name it summons.
88
- * @param team - the Team preset to search.
89
- * @param key - the model-authored member name.
90
- * @returns the matching member with its target, or undefined when the name is unknown.
91
- */
92
- function findMember(team, key) {
93
- const wanted = key.trim();
94
- const used = /* @__PURE__ */ new Set();
95
- for (const [index, member] of team.members.entries()) {
96
- const target = memberTarget(member, index, used);
97
- if (target === wanted.toLowerCase() || member.name.trim() === wanted) return {
98
- member,
99
- target
100
- };
101
- }
102
- }
103
- /**
104
92
  * List every addressable teammate target of one Team.
105
93
  * @param team - the Team preset.
106
94
  * @returns one entry per member, in declared order.
107
95
  */
108
96
  function memberTargets(team) {
109
97
  const used = /* @__PURE__ */ new Set();
98
+ const preferred = team.members.map(preferredMemberTarget);
99
+ const targets = preferred.map((target) => {
100
+ if (target === void 0 || used.has(target)) return void 0;
101
+ used.add(target);
102
+ return target;
103
+ });
104
+ for (const [index, target] of preferred.entries()) {
105
+ if (target !== void 0) continue;
106
+ const fallback = `member-${index + 1}`;
107
+ if (used.has(fallback)) continue;
108
+ used.add(fallback);
109
+ targets[index] = fallback;
110
+ }
110
111
  return team.members.map((member, index) => ({
111
112
  member,
112
- target: memberTarget(member, index, used)
113
+ target: targets[index] ?? memberTarget(member, index, used)
113
114
  }));
114
115
  }
116
+ /** Resolve an exact target, then an exact display name, then a case-insensitive target. */
117
+ function findMemberInRoster(roster, key) {
118
+ const wanted = key.trim();
119
+ const normalized = wanted.toLowerCase();
120
+ return roster.find((row) => row.target === wanted) ?? roster.find((row) => row.member.name.trim() === wanted) ?? roster.find((row) => row.target === normalized);
121
+ }
122
+ /** Resolve one member by display name or the same target shown in the roster. */
123
+ function findMember(team, key) {
124
+ return findMemberInRoster(memberTargets(team), key);
125
+ }
126
+ /**
127
+ * Recover the role of a durable instance created before role ids were recorded.
128
+ * Its instance name can overlap a different role's current summon target.
129
+ */
130
+ function recordedMemberRole(team, record) {
131
+ if (record.roleId !== void 0) return record.roleId;
132
+ if (team === void 0) return record.memberName;
133
+ const matches = team.members.filter((member) => member.name.trim() === record.displayName);
134
+ if (matches.length !== 1) return void 0;
135
+ const member = matches[0];
136
+ return member.id ?? member.name;
137
+ }
115
138
  /**
116
139
  * Select the fields of one slot that a Team task owns.
117
140
  *
@@ -9269,9 +9292,7 @@ function editTeamPreset(team, edit) {
9269
9292
  members
9270
9293
  });
9271
9294
  for (const entry of edit.members ?? []) {
9272
- const wanted = entry.member.trim();
9273
- const at = roster.findIndex((row) => row.target === wanted.toLowerCase() || row.member.name.trim() === wanted);
9274
- const row = roster[at];
9295
+ const row = findMemberInRoster(roster, entry.member);
9275
9296
  if (row === void 0) {
9276
9297
  const targets = roster.map((candidate) => candidate.target).join(", ");
9277
9298
  return {
@@ -9279,6 +9300,7 @@ function editTeamPreset(team, edit) {
9279
9300
  message: `unknown Team member "${entry.member}"; available members: ${targets === "" ? "(none)" : targets}`
9280
9301
  };
9281
9302
  }
9303
+ const at = roster.indexOf(row);
9282
9304
  const current = members[at] ?? row.member;
9283
9305
  const updated = { ...current };
9284
9306
  if (entry.description !== void 0) {
@@ -16724,35 +16746,45 @@ var import_dist = (/* @__PURE__ */ __commonJSMin(((exports) => {
16724
16746
  })))();
16725
16747
  /** The instruction file every Team Skill must carry. */
16726
16748
  const SKILL_FILE = "SKILL.md";
16749
+ const DEPENDENCY_FRONTMATTER_FIELDS = [
16750
+ "executables",
16751
+ "mcpServers",
16752
+ "otherSkills"
16753
+ ];
16727
16754
  /** The kebab-case grammar the official skill registry enforces. */
16728
16755
  const SKILL_NAME = /^[a-z0-9]+(?:-[a-z0-9]+)*$/u;
16729
- /**
16730
- * Parse the YAML frontmatter of one `SKILL.md`.
16731
- *
16732
- * Only `name` and `description` are interpreted, and both are required by the
16733
- * Agent Skills specification. Everything else — `license`, `compatibility`,
16734
- * `metadata`, `allowed-tools`, an unknown vendor key — stays in the file
16735
- * untouched, because the document is portable and this reader is one consumer.
16736
- * @param text - the whole document.
16737
- * @returns the two required fields, or undefined when the fence is absent.
16738
- */
16739
- function parseSkillFrontmatter(text) {
16740
- const match = /^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/u.exec(text);
16741
- if (match?.[1] === void 0) return void 0;
16756
+ /** Read the frontmatter and retain the location of the YAML source. */
16757
+ function readSkillFrontmatter(text, keepSourceTokens = false) {
16758
+ const match = /^\uFEFF?---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/du.exec(text);
16759
+ const range = match?.indices?.[1];
16760
+ if (match?.[1] === void 0 || range === void 0) return void 0;
16742
16761
  try {
16743
- const document = (0, import_dist.parseDocument)(match[1], { uniqueKeys: true });
16762
+ const document = (0, import_dist.parseDocument)(match[1], {
16763
+ uniqueKeys: true,
16764
+ keepSourceTokens
16765
+ });
16744
16766
  if (document.errors.length > 0) return void 0;
16745
- const fields = document.toJS({ maxAliasCount: 100 });
16746
- if (fields === null || typeof fields !== "object" || Array.isArray(fields)) return void 0;
16747
- const { name, description } = fields;
16767
+ const value = document.toJS({ maxAliasCount: 100 });
16768
+ if (value === null || typeof value !== "object" || Array.isArray(value)) return void 0;
16769
+ const fields = value;
16748
16770
  return {
16749
- name: typeof name === "string" ? name : "",
16750
- description: typeof description === "string" ? description : ""
16771
+ document,
16772
+ yamlStart: range[0],
16773
+ name: typeof fields["name"] === "string" ? fields["name"] : "",
16774
+ description: typeof fields["description"] === "string" ? fields["description"] : ""
16751
16775
  };
16752
16776
  } catch {
16753
16777
  return;
16754
16778
  }
16755
16779
  }
16780
+ /** Find an explicitly written top-level field without following YAML merges. */
16781
+ function explicitField(document, field) {
16782
+ if (!(0, import_dist.isMap)(document.contents)) return void 0;
16783
+ return document.contents.items.findLast(({ key }) => {
16784
+ const resolved = (0, import_dist.isAlias)(key) ? key.resolve(document) : key;
16785
+ return (0, import_dist.isScalar)(resolved) && resolved.value === field;
16786
+ });
16787
+ }
16756
16788
  /**
16757
16789
  * Validate one decoded folder as a Team Skill.
16758
16790
  *
@@ -16791,7 +16823,10 @@ function buildSkillPackage(input) {
16791
16823
  };
16792
16824
  let text;
16793
16825
  try {
16794
- text = new TextDecoder("utf-8", { fatal: true }).decode(instruction.bytes);
16826
+ text = new TextDecoder("utf-8", {
16827
+ fatal: true,
16828
+ ignoreBOM: true
16829
+ }).decode(instruction.bytes);
16795
16830
  } catch {
16796
16831
  return {
16797
16832
  ok: false,
@@ -16799,7 +16834,7 @@ function buildSkillPackage(input) {
16799
16834
  path: SKILL_FILE
16800
16835
  };
16801
16836
  }
16802
- const frontmatter = parseSkillFrontmatter(text);
16837
+ const frontmatter = readSkillFrontmatter(text);
16803
16838
  if (frontmatter === void 0) return {
16804
16839
  ok: false,
16805
16840
  reason: "invalid-frontmatter",
@@ -16815,6 +16850,10 @@ function buildSkillPackage(input) {
16815
16850
  reason: "missing-description",
16816
16851
  path: SKILL_FILE
16817
16852
  };
16853
+ const dependencyWarnings = DEPENDENCY_FRONTMATTER_FIELDS.filter((field) => explicitField(frontmatter.document, field) !== void 0).map((field) => ({
16854
+ code: "unsupported-dependency-frontmatter",
16855
+ field
16856
+ }));
16818
16857
  const totalBytes = ordered.reduce((sum, file) => sum + file.bytes.byteLength, 0);
16819
16858
  const warnings = [];
16820
16859
  const scripts = ordered.filter((file) => /\.(?:py|sh|ps1|bat|cmd)$/u.test(file.path));
@@ -16827,10 +16866,66 @@ function buildSkillPackage(input) {
16827
16866
  files: ordered,
16828
16867
  totalBytes
16829
16868
  },
16830
- warnings
16869
+ warnings,
16870
+ dependencyWarnings
16831
16871
  };
16832
16872
  }
16833
16873
  /**
16874
+ * Rename an already validated Team Skill package for a new copy.
16875
+ * @param package_ - the source package, whose files are left intact.
16876
+ * @param name - the new kebab-case name.
16877
+ * @returns the renamed package, with only the instruction file changed.
16878
+ */
16879
+ function renameSkillPackage(package_, name) {
16880
+ if (!SKILL_NAME.test(name)) throw new Error(`invalid Team Skill name: ${name}`);
16881
+ const instruction = package_.files.find((file) => file.path === SKILL_FILE);
16882
+ if (instruction === void 0) throw new Error(`missing ${SKILL_FILE}`);
16883
+ const text = new TextDecoder("utf-8", {
16884
+ fatal: true,
16885
+ ignoreBOM: true
16886
+ }).decode(instruction.bytes);
16887
+ const frontmatter = readSkillFrontmatter(text, true);
16888
+ if (frontmatter === void 0 || !SKILL_NAME.test(frontmatter.name)) throw new Error(`invalid skill name in ${SKILL_FILE}`);
16889
+ if (frontmatter.name === name && package_.name === name) return package_;
16890
+ const { document, yamlStart } = frontmatter;
16891
+ const node = explicitField(document, "name")?.value;
16892
+ let replacement = (0, import_dist.stringify)(name, { version: document.directives.yaml.version }).trimEnd();
16893
+ let start;
16894
+ let end;
16895
+ if (((0, import_dist.isScalar)(node) || (0, import_dist.isAlias)(node)) && node.range !== void 0) [start, end] = node.range;
16896
+ else if ((0, import_dist.isMap)(document.contents) && document.contents.range !== void 0) {
16897
+ start = document.contents.range[0];
16898
+ if (document.contents.flow) {
16899
+ start += 1;
16900
+ replacement = `name: ${replacement}, `;
16901
+ } else {
16902
+ const keyStart = yamlStart + start;
16903
+ const lineStart = text.lastIndexOf("\n", keyStart - 1) + 1;
16904
+ const indent = text.slice(lineStart, keyStart);
16905
+ const newline = text[lineStart - 2] === "\r" ? "\r\n" : "\n";
16906
+ replacement = `name: ${replacement}${newline}${indent}`;
16907
+ }
16908
+ end = start;
16909
+ } else throw new Error(`cannot locate name in ${SKILL_FILE}`);
16910
+ if ((0, import_dist.isScalar)(node) && node.srcToken?.type === "block-scalar") {
16911
+ const { source } = node.srcToken;
16912
+ const offset = source.indexOf(frontmatter.name);
16913
+ if (offset < 0) throw new Error(`cannot locate name in ${SKILL_FILE}`);
16914
+ start = end - source.length + offset;
16915
+ end = start + frontmatter.name.length;
16916
+ replacement = name;
16917
+ } else if ((0, import_dist.isScalar)(node) && node.type === "QUOTE_SINGLE") replacement = `'${name}'`;
16918
+ else if ((0, import_dist.isScalar)(node) && node.type === "QUOTE_DOUBLE") replacement = JSON.stringify(name);
16919
+ const renamed = text.slice(0, yamlStart + start) + replacement + text.slice(yamlStart + end);
16920
+ const result = buildSkillPackage(package_.files.map((file) => file === instruction ? {
16921
+ path: file.path,
16922
+ bytes: new TextEncoder().encode(renamed)
16923
+ } : file));
16924
+ if (!result.ok) throw new Error(`invalid renamed Team Skill: ${result.reason}`);
16925
+ if (result.skill.name !== name) throw new Error(`could not rename ${SKILL_FILE} to ${name}`);
16926
+ return result.skill;
16927
+ }
16928
+ /**
16834
16929
  * Decode the browser's base64 file payloads into bytes.
16835
16930
  *
16836
16931
  * A folder picker cannot hand over a `File` object across the Remote boundary,
@@ -16847,6 +16942,7 @@ function decodeImportFiles(files) {
16847
16942
 
16848
16943
 
16849
16944
  /** Immutable package versions and an atomically persisted private registry. */
16945
+ const SKILL_IMPORT_FOLDER = "inbox";
16850
16946
  const REGISTRY_VERSION = 1;
16851
16947
  const NO_DEPENDENCIES = {
16852
16948
  mcpServers: [],
@@ -16887,6 +16983,10 @@ function diskComponent(value) {
16887
16983
  function strings(value) {
16888
16984
  return Array.isArray(value) && value.every((item) => typeof item === "string");
16889
16985
  }
16986
+ function importFolderName(value) {
16987
+ if (normalizeSkillPath(value) !== value || value.includes("/") || value.startsWith(".")) throw new Error("invalid Team Skill source folder");
16988
+ return value;
16989
+ }
16890
16990
  function validateAsset(value) {
16891
16991
  if (value === null || typeof value !== "object") throw new Error("invalid Team Skill asset");
16892
16992
  const a = value;
@@ -16898,6 +16998,10 @@ function validateAsset(value) {
16898
16998
  "custom",
16899
16999
  "override"
16900
17000
  ].includes(a.origin) || typeof a.description !== "string" || !/^[a-f0-9]{64}$/u.test(a.digest) || !Number.isSafeInteger(a.updatedAt) || a.updatedAt < 0 || !Array.isArray(a.files) || a.officialSkillId !== void 0 && (typeof a.officialSkillId !== "string" || assetDirectoryName(a.officialSkillId) !== a.officialSkillId) || a.baseVersion !== void 0 && component(a.baseVersion) !== a.baseVersion || a.updateAvailable !== void 0 && typeof a.updateAvailable !== "boolean") throw new Error("invalid Team Skill asset shape");
17001
+ if (a.sourceFolder !== void 0) {
17002
+ if (a.origin !== "custom" || typeof a.sourceFolder !== "string") throw new Error("invalid Team Skill source folder");
17003
+ importFolderName(a.sourceFolder);
17004
+ }
16901
17005
  for (const file of a.files) if (file === null || typeof file !== "object" || typeof file.path !== "string" || normalizeSkillPath(file.path) !== file.path || typeof file.text !== "boolean" || typeof file.sha256 !== "string" || !/^[a-f0-9]{64}$/u.test(file.sha256)) throw new Error("invalid Team Skill file shape");
16902
17006
  checkFolder(a.files.map((file) => ({
16903
17007
  path: file.path,
@@ -16999,7 +17103,11 @@ var TeamSkillStore = class {
16999
17103
  return join(this.root, "transaction.json");
17000
17104
  }
17001
17105
  journalTarget(path) {
17002
- if (!/^(?:(?:assets|manifests)\/(?:[A-Za-z0-9][A-Za-z0-9:._-]*|~(?:[a-f0-9]+|h[a-f0-9]{64}))(?:\/(?:[A-Za-z0-9][A-Za-z0-9:._-]*|~(?:[a-f0-9]+|h[a-f0-9]{64}))(?:\.json)?)?|\.(?:stage|removed)-[a-f0-9-]+)$/u.test(path) || path.split("/").some((part) => part === "." || part === "..")) throw new Error("invalid Team Skill transaction path");
17106
+ const parts = path.split("/");
17107
+ if (parts[0] === "inbox" && parts.length >= 3) {
17108
+ importFolderName(parts[1]);
17109
+ normalizeSkillPath(parts.slice(2).join("/"));
17110
+ } else if (!/^(?:(?:assets|manifests)\/(?:[A-Za-z0-9][A-Za-z0-9:._-]*|~(?:[a-f0-9]+|h[a-f0-9]{64}))(?:\/(?:[A-Za-z0-9][A-Za-z0-9:._-]*|~(?:[a-f0-9]+|h[a-f0-9]{64}))(?:\.json)?)?|\.(?:stage|removed)-[a-f0-9-]+)$/u.test(path) || path.split("/").some((part) => part === "." || part === "..")) throw new Error("invalid Team Skill transaction path");
17003
17111
  if (process.platform === "win32" && path.includes(":")) throw new Error("invalid Team Skill transaction path");
17004
17112
  return resolveInside(this.root, path);
17005
17113
  }
@@ -17231,6 +17339,7 @@ var TeamSkillStore = class {
17231
17339
  version: options.version,
17232
17340
  ...options.officialSkillId === void 0 ? {} : { officialSkillId: options.officialSkillId },
17233
17341
  ...options.baseVersion === void 0 ? {} : { baseVersion: options.baseVersion },
17342
+ ...options.sourceFolder === void 0 ? {} : { sourceFolder: options.sourceFolder },
17234
17343
  digest: folderDigest(files),
17235
17344
  files,
17236
17345
  dependencies: options.dependencies ?? NO_DEPENDENCIES,
@@ -17287,10 +17396,41 @@ var TeamSkillStore = class {
17287
17396
  return asset;
17288
17397
  });
17289
17398
  }
17290
- async writeFile(assetId, path, content) {
17399
+ sourcePath(folder) {
17400
+ return resolveInside(join(this.root, SKILL_IMPORT_FOLDER), importFolderName(folder));
17401
+ }
17402
+ /** Publish a scanned package under its existing identity, or register it for the first time. */
17403
+ async publishSource(folder, package_) {
17404
+ importFolderName(folder);
17405
+ return this.transaction(async () => {
17406
+ const current = this.bySkillId(package_.name);
17407
+ if (current !== void 0 && current.origin !== "custom") throw new Error(`the skill name "${package_.name}" already belongs to ${current.id}`);
17408
+ if (current !== void 0 && current.digest === folderDigest(fileTable(package_.files))) {
17409
+ if (current.sourceFolder !== folder) {
17410
+ const tx = this.transactions.getStore();
17411
+ tx.assets.set(current.id, immutable({
17412
+ ...current,
17413
+ sourceFolder: folder
17414
+ }));
17415
+ tx.dirty = true;
17416
+ }
17417
+ return "existing";
17418
+ }
17419
+ await this.install(package_, {
17420
+ id: current?.id ?? `custom:${package_.name}`,
17421
+ origin: "custom",
17422
+ sourceFolder: folder,
17423
+ version: current === void 0 ? "1" : nextVersion(),
17424
+ ...current === void 0 ? {} : { dependencies: current.dependencies }
17425
+ });
17426
+ return current === void 0 ? "imported" : "updated";
17427
+ });
17428
+ }
17429
+ async writeFile(assetId, path, content, expectedVersion) {
17291
17430
  return this.transaction(async () => {
17292
17431
  const asset = requireAsset(this.table, assetId);
17293
17432
  if (asset.origin === "builtin") throw new Error("a shipped Team Skill is read-only; create an editable copy instead");
17433
+ if (expectedVersion !== void 0 && asset.version !== expectedVersion) throw new Error("This Team Skill has a newer published version. Reopen its file before saving.");
17294
17434
  const relative = normalizeSkillPath(path);
17295
17435
  const files = /* @__PURE__ */ new Map();
17296
17436
  for (const file of asset.files) files.set(file.path, await this.readBytes(assetId, file.path, asset.version));
@@ -17301,12 +17441,48 @@ var TeamSkillStore = class {
17301
17441
  })));
17302
17442
  if (!checked.ok) throw new Error(`invalid skill package: ${checked.reason}`);
17303
17443
  if (checked.skill.name !== asset.skillId) throw new Error("editing cannot change the skill name");
17444
+ if (asset.sourceFolder !== void 0) await this.writeSourceFile(asset, asset.sourceFolder, relative, files.get(relative));
17304
17445
  return this.install(checked.skill, {
17305
17446
  ...asset,
17306
17447
  version: nextVersion()
17307
17448
  });
17308
17449
  });
17309
17450
  }
17451
+ async writeSourceFile(asset, folder, path, bytes) {
17452
+ const current = await inspectSkillDirectory(this.sourcePath(folder));
17453
+ const sourceChanged = "The Team Skill source changed on disk. Scan the import folder before saving.";
17454
+ if (!current.ok || folderDigest(fileTable(current.skill.files)) !== asset.digest) throw new Error(sourceChanged);
17455
+ const previous = asset.files.find((file) => file.path === path);
17456
+ if (previous === void 0 || !previous.text) throw new Error("Only existing text files can be edited in a scanned Team Skill.");
17457
+ const sourcePath = `${SKILL_IMPORT_FOLDER}/${folder}/${path}`;
17458
+ const stagePath = `.stage-${randomUUID()}`;
17459
+ const backupPath = `.removed-${randomUUID()}`;
17460
+ const target = this.journalTarget(sourcePath);
17461
+ const stage = this.journalTarget(stagePath);
17462
+ const backup = this.journalTarget(backupPath);
17463
+ await assertNoSymlinks(target);
17464
+ await this.record({
17465
+ kind: "create",
17466
+ path: stagePath
17467
+ });
17468
+ await writeFile(stage, bytes, {
17469
+ flag: "wx",
17470
+ mode: (await lstat(target)).mode & 511
17471
+ });
17472
+ await this.record({
17473
+ kind: "move",
17474
+ path: sourcePath,
17475
+ backup: backupPath
17476
+ });
17477
+ await rename(target, backup);
17478
+ if (digestBytes(await readFile(backup)) !== previous.sha256) throw new Error(sourceChanged);
17479
+ await this.record({
17480
+ kind: "relocate",
17481
+ path: stagePath,
17482
+ destination: sourcePath
17483
+ });
17484
+ await rename(stage, target);
17485
+ }
17310
17486
  /** Change dependency metadata by publishing a new immutable asset version. */
17311
17487
  async updateDependencies(assetId, dependencies) {
17312
17488
  return this.transaction(async () => {
@@ -17443,25 +17619,57 @@ var TeamSkillStore = class {
17443
17619
  if (parsed.id !== assetId || parsed.version !== version) throw new Error("Team Skill manifest does not match its version");
17444
17620
  return immutable(parsed);
17445
17621
  }
17446
- async createOverride(skillId, id) {
17622
+ freeCopyName(skillId, reserved) {
17623
+ const taken = new Set([...reserved, ...this.list().map((asset) => asset.skillId)]);
17624
+ let suffix = 1;
17625
+ while (taken.has(`${skillId}-${suffix}`)) suffix += 1;
17626
+ return `${skillId}-${suffix}`;
17627
+ }
17628
+ /** Keep old binding identities when a previously same-named copy needs its own name. */
17629
+ async renameLegacyCopies(reserved) {
17630
+ await this.transaction(async () => {
17631
+ const seen = new Set([...reserved, ...this.list().filter((asset) => asset.origin !== "override").map((asset) => asset.skillId)]);
17632
+ for (const asset of this.list()) {
17633
+ if (asset.origin !== "override") continue;
17634
+ if (seen.has(asset.skillId) || asset.skillId === asset.officialSkillId) {
17635
+ const name = this.freeCopyName(asset.officialSkillId ?? asset.skillId, reserved);
17636
+ const package_ = renameSkillPackage(await this.readPackage(asset), name);
17637
+ await this.install(package_, {
17638
+ ...asset,
17639
+ version: nextVersion()
17640
+ });
17641
+ seen.add(name);
17642
+ } else seen.add(asset.skillId);
17643
+ }
17644
+ });
17645
+ }
17646
+ async readPackage(asset) {
17647
+ const files = [];
17648
+ for (const file of asset.files) files.push({
17649
+ path: file.path,
17650
+ bytes: await this.readBytes(asset.id, file.path, asset.version)
17651
+ });
17652
+ const checked = buildSkillPackage(files);
17653
+ if (!checked.ok) throw new Error(`invalid skill package: ${checked.reason}`);
17654
+ return checked.skill;
17655
+ }
17656
+ async createOverride(skillId, id, reserved = []) {
17447
17657
  return this.transaction(async () => {
17448
- const existing = this.table.get(id);
17658
+ const existing = id === void 0 ? void 0 : this.table.get(id);
17449
17659
  if (existing) {
17450
17660
  if (existing.origin === "override" && existing.officialSkillId === skillId) return existing;
17451
17661
  throw new Error("asset identity already belongs to another skill");
17452
17662
  }
17453
17663
  const official = requireAsset(this.table, `builtin:${skillId}`);
17454
- const files = [];
17455
- for (const file of official.files) files.push({
17456
- path: file.path,
17457
- bytes: await this.readBytes(official.id, file.path, official.version)
17458
- });
17459
- return this.installFiles(skillId, files, {
17460
- id,
17664
+ const name = this.freeCopyName(skillId, reserved);
17665
+ const package_ = renameSkillPackage(await this.readPackage(official), name);
17666
+ return this.install(package_, {
17667
+ id: id ?? `override:${randomUUID()}`,
17461
17668
  origin: "override",
17462
17669
  version: nextVersion(),
17463
17670
  officialSkillId: skillId,
17464
- baseVersion: official.version
17671
+ baseVersion: official.version,
17672
+ dependencies: official.dependencies
17465
17673
  });
17466
17674
  });
17467
17675
  }
@@ -17470,16 +17678,10 @@ var TeamSkillStore = class {
17470
17678
  const asset = requireAsset(this.table, assetId);
17471
17679
  if (asset.origin !== "override" || asset.officialSkillId === void 0) throw new Error("only an override of a shipped Team Skill can be reset");
17472
17680
  const official = requireAsset(this.table, `builtin:${asset.officialSkillId}`);
17473
- const files = [];
17474
- for (const file of official.files) files.push({
17475
- path: file.path,
17476
- bytes: await this.readBytes(official.id, file.path, official.version)
17477
- });
17478
- return this.installFiles(official.skillId, files, {
17479
- id: assetId,
17480
- origin: "override",
17681
+ const package_ = renameSkillPackage(await this.readPackage(official), asset.skillId);
17682
+ return this.install(package_, {
17683
+ ...asset,
17481
17684
  version: nextVersion(),
17482
- officialSkillId: official.skillId,
17483
17685
  baseVersion: official.version
17484
17686
  });
17485
17687
  });
@@ -17547,10 +17749,7 @@ async function readDirectory(source) {
17547
17749
  async function inspectSkillDirectory(source) {
17548
17750
  try {
17549
17751
  const checked = buildSkillPackage(await readDirectory(source));
17550
- if (checked.ok) return {
17551
- ok: true,
17552
- skill: checked.skill
17553
- };
17752
+ if (checked.ok) return checked;
17554
17753
  return {
17555
17754
  ok: false,
17556
17755
  reason: checked.reason,
@@ -17570,6 +17769,65 @@ async function inspectSkillDirectory(source) {
17570
17769
  }
17571
17770
 
17572
17771
 
17772
+ /** Skills shipped under `assets/skills`, including assets missing from this installation. */
17773
+ const OFFICIAL_SKILL_IDS = [
17774
+ "agent-leader-communication",
17775
+ "leader-medium-task-workflow",
17776
+ "leader-long-task-orchestration",
17777
+ "agent-subagent-orchestration",
17778
+ "fullstack-advisor",
17779
+ "executor-short-task-workflow",
17780
+ "github-repository-presentation",
17781
+ "git-release-hygiene",
17782
+ "frontend-engineering-workflow",
17783
+ "backend-architecture-workflow",
17784
+ "independent-code-review-workflow",
17785
+ "grilling",
17786
+ "research"
17787
+ ];
17788
+ const officialIds = new Set(OFFICIAL_SKILL_IDS);
17789
+ /** The binding slot reserved for a captain. */
17790
+ const CAPTAIN_ROLE = "captain";
17791
+ /** Shipped identities always use the catalog, including records from earlier releases. */
17792
+ function officialSkillDefaults(team) {
17793
+ const entry = builtinEntry(team.id);
17794
+ return entry === void 0 ? {
17795
+ source: "preset",
17796
+ declarations: team.officialSkills ?? []
17797
+ } : {
17798
+ source: "catalog",
17799
+ declarations: entry.officialSkillBindings
17800
+ };
17801
+ }
17802
+ /** A declaration can address only an unambiguous name and an unambiguous binding slot. */
17803
+ function officialSkillTarget(team, declaration) {
17804
+ if (!officialIds.has(declaration.skillId)) return { status: "unknown-skill" };
17805
+ const roles = [{
17806
+ name: team.captain.name,
17807
+ id: CAPTAIN_ROLE
17808
+ }, ...team.members.map((member) => ({
17809
+ name: member.name,
17810
+ id: member.id ?? member.name
17811
+ }))];
17812
+ const [role, otherMatch] = roles.filter((candidate) => candidate.name === declaration.roleName);
17813
+ if (role === void 0) return { status: "missing-role" };
17814
+ if (otherMatch !== void 0 || roles.filter((candidate) => candidate.id === role.id).length !== 1) return { status: "ambiguous-role" };
17815
+ return {
17816
+ status: "valid",
17817
+ roleId: role.id,
17818
+ assetId: `builtin:${declaration.skillId}`
17819
+ };
17820
+ }
17821
+ /** A default can seed only the shipped asset with the declared identity. */
17822
+ function isOfficialSkillAsset(asset, assetId) {
17823
+ return asset.origin === "builtin" && asset.id === assetId;
17824
+ }
17825
+ /** A role that already holds a derived override keeps its explicit assignment. */
17826
+ function isOfficialSkillOverride(asset, skillId) {
17827
+ return asset.origin === "override" && asset.officialSkillId === skillId;
17828
+ }
17829
+
17830
+
17573
17831
  /**
17574
17832
  * Who receives which Team Skill, and what may not be deleted.
17575
17833
  *
@@ -17591,8 +17849,6 @@ async function inspectSkillDirectory(source) {
17591
17849
  */
17592
17850
  /** Bindings document revision this build understands. */
17593
17851
  const BINDINGS_VERSION = 1;
17594
- /** The role slot the captain is stored under. */
17595
- const CAPTAIN_ROLE = "captain";
17596
17852
  /** Windows executable extensions assumed when PATHEXT is unset. */
17597
17853
  const DEFAULT_PATHEXT = ".COM;.EXE;.BAT;.CMD";
17598
17854
  /**
@@ -17754,39 +18010,12 @@ var TeamSkillManager = class {
17754
18010
  };
17755
18011
  }));
17756
18012
  }
17757
- /** Replace existing shipped bindings after an editable copy is created. */
18013
+ /** Replace only existing bindings to the shipped skill after an explicit switch. */
17758
18014
  async replaceBuiltinBindings(skillId, overrideId) {
17759
18015
  return this.mutate(() => this.store.withLock(async () => {
17760
18016
  const replacement = this.store.get(overrideId);
17761
18017
  if (replacement?.origin !== "override" || replacement.officialSkillId !== skillId) throw new Error("replacement must be an override of the shipped skill");
17762
- const builtinId = `builtin:${skillId}`;
17763
- let replaced = 0;
17764
- const seen = /* @__PURE__ */ new Set();
17765
- const next = [];
17766
- for (const binding of this.bindings) {
17767
- const hasOtherOverride = binding.assetId === builtinId && this.bindings.some((other) => {
17768
- if (other.teamId !== binding.teamId || other.roleId !== binding.roleId || other.assetId === overrideId) return false;
17769
- const asset = this.store.get(other.assetId);
17770
- return asset?.origin === "override" && asset.officialSkillId === skillId;
17771
- });
17772
- const convert = binding.assetId === builtinId && !hasOtherOverride;
17773
- const row = convert ? {
17774
- ...binding,
17775
- assetId: overrideId
17776
- } : binding;
17777
- if (convert) replaced += 1;
17778
- const key = JSON.stringify([
17779
- row.teamId,
17780
- row.roleId,
17781
- row.assetId
17782
- ]);
17783
- if (row.assetId !== overrideId || !seen.has(key)) next.push(row);
17784
- if (row.assetId === overrideId) seen.add(key);
17785
- }
17786
- if (replaced === 0) return 0;
17787
- this.bindings = next;
17788
- await this.flush();
17789
- return replaced;
18018
+ return this.replaceAssetBindingsNow(`builtin:${skillId}`, overrideId);
17790
18019
  }));
17791
18020
  }
17792
18021
  /**
@@ -17933,34 +18162,33 @@ var TeamSkillManager = class {
17933
18162
  const owner = seedOwner(key);
17934
18163
  return owner !== void 0 && this.hasRole(owner[0], owner[1]);
17935
18164
  }));
17936
- for (const team of teams) {
17937
- const declarations = BUILTIN_TEAM_CATALOG.find((entry) => entry.id === team.id)?.officialSkillBindings ?? team.officialSkills ?? [];
17938
- for (const declaration of declarations) {
17939
- const isCaptain = team.captain.name === declaration.roleName;
17940
- const member = isCaptain ? void 0 : team.members.find((member) => member.name === declaration.roleName);
17941
- const memberRole = member === void 0 ? void 0 : member.id ?? member.name;
17942
- const roleId = isCaptain ? CAPTAIN_ROLE : memberRole === "captain" ? void 0 : memberRole;
17943
- if (roleId === void 0) continue;
17944
- const assetId = `builtin:${declaration.skillId}`;
17945
- if (this.store.get(assetId) === void 0) continue;
17946
- const key = JSON.stringify([
17947
- team.id,
17948
- roleId,
17949
- assetId
17950
- ]);
17951
- if (this.bindings.some((row) => {
17952
- if (row.teamId !== team.id || row.roleId !== roleId) return false;
17953
- return this.store.get(row.assetId)?.skillId === declaration.skillId;
17954
- })) continue;
17955
- if (this.seeded.has(key)) continue;
18165
+ for (const team of teams) for (const declaration of officialSkillDefaults(team).declarations) {
18166
+ const target = officialSkillTarget(team, declaration);
18167
+ if (target.status !== "valid") continue;
18168
+ const { roleId, assetId } = target;
18169
+ const key = JSON.stringify([
18170
+ team.id,
18171
+ roleId,
18172
+ assetId
18173
+ ]);
18174
+ if (this.bindings.some((row) => {
18175
+ if (row.teamId !== team.id || row.roleId !== roleId) return false;
18176
+ const asset = this.store.get(row.assetId);
18177
+ return asset !== void 0 && (isOfficialSkillAsset(asset, assetId) || isOfficialSkillOverride(asset, declaration.skillId));
18178
+ })) {
17956
18179
  this.seeded.add(key);
17957
- this.bindings.push({
17958
- teamId: team.id,
17959
- roleId,
17960
- assetId,
17961
- ...roleId === "captain" ? { captain: true } : {}
17962
- });
18180
+ continue;
17963
18181
  }
18182
+ const shipped = this.store.get(assetId);
18183
+ if (shipped === void 0 || !isOfficialSkillAsset(shipped, assetId)) continue;
18184
+ if (this.seeded.has(key)) continue;
18185
+ this.seeded.add(key);
18186
+ this.bindings.push({
18187
+ teamId: team.id,
18188
+ roleId,
18189
+ assetId,
18190
+ ...roleId === "captain" ? { captain: true } : {}
18191
+ });
17964
18192
  }
17965
18193
  if (JSON.stringify([this.bindings, [...this.seeded]]) !== before) await this.flush();
17966
18194
  }
@@ -17975,20 +18203,26 @@ var TeamSkillManager = class {
17975
18203
  * @returns the number of bindings moved.
17976
18204
  */
17977
18205
  async replaceAssetBindings(fromAssetId, toAssetId) {
17978
- return this.mutate(async () => {
17979
- if (this.store.get(toAssetId) === void 0) return 0;
17980
- let moved = 0;
17981
- this.bindings = this.bindings.map((row) => {
17982
- if (row.assetId !== fromAssetId) return row;
17983
- moved += 1;
17984
- return {
17985
- ...row,
17986
- assetId: toAssetId
17987
- };
17988
- });
17989
- if (moved > 0) await this.flush();
17990
- return moved;
18206
+ return this.mutate(() => this.replaceAssetBindingsNow(fromAssetId, toAssetId));
18207
+ }
18208
+ async replaceAssetBindingsNow(fromAssetId, toAssetId) {
18209
+ if (fromAssetId === toAssetId || this.store.get(toAssetId) === void 0) return 0;
18210
+ const moved = this.bindings.filter((row) => row.assetId === fromAssetId).length;
18211
+ if (moved === 0) return 0;
18212
+ const seen = /* @__PURE__ */ new Set();
18213
+ this.bindings = this.bindings.flatMap((binding) => {
18214
+ const row = binding.assetId === fromAssetId ? {
18215
+ ...binding,
18216
+ assetId: toAssetId
18217
+ } : binding;
18218
+ if (row.assetId !== toAssetId) return [row];
18219
+ const key = JSON.stringify([row.teamId, row.roleId]);
18220
+ if (seen.has(key)) return [];
18221
+ seen.add(key);
18222
+ return [row];
17991
18223
  });
18224
+ await this.flush();
18225
+ return moved;
17992
18226
  }
17993
18227
  mutate(operation) {
17994
18228
  const result = this.pending.then(async () => {
@@ -18518,50 +18752,6 @@ var TeamSkillRuntime = class {
18518
18752
  this.injectFiber.dispose();
18519
18753
  }
18520
18754
  };
18521
-
18522
-
18523
- /**
18524
- * The Team Skill subsystem as one object the plugin lifecycle drives.
18525
- *
18526
- * This module is the seam between the plugin and the store/manager/provider
18527
- * trio: it resolves the private root, loads the shipped skills, and answers the
18528
- * two lifecycle questions the runtime asks — "what does this role get?" and
18529
- * "this Agent is gone, release it".
18530
- *
18531
- * The private root is resolved from the Harness home the deployment itself uses
18532
- * (`$DSH_HOME`, else `~/.dsh`) under a plugin-owned directory. v0.2.1-rc.2
18533
- * publishes no per-plugin data-directory API, so this is a documented
18534
- * derivation rather than a guess about a global skill directory: it is never a
18535
- * user or project skill folder, it is never scanned by the host's own skill
18536
- * providers, and an explicit `skillRoot` config value always wins.
18537
- * @module dsh-agent-team-presets/team-skills
18538
- */
18539
- /**
18540
- * The skills the package ships under `assets/skills`.
18541
- *
18542
- * The engineering workflow skills are bound to a role by `team-catalog.ts`; the
18543
- * three professional-role workflows (`frontend-engineering-workflow`,
18544
- * `backend-architecture-workflow`, `independent-code-review-workflow`) are the
18545
- * progressive-loading entry points of the UI frontend engineer, the backend
18546
- * architect, and the independent reviewer, whose detailed methods live in each
18547
- * skill's `references/` folder; `grilling` and `research` are method skills the
18548
- * work-mode Teams bind instead.
18549
- */
18550
- const OFFICIAL_SKILL_IDS = [
18551
- "agent-leader-communication",
18552
- "leader-medium-task-workflow",
18553
- "leader-long-task-orchestration",
18554
- "agent-subagent-orchestration",
18555
- "fullstack-advisor",
18556
- "executor-short-task-workflow",
18557
- "github-repository-presentation",
18558
- "git-release-hygiene",
18559
- "frontend-engineering-workflow",
18560
- "backend-architecture-workflow",
18561
- "independent-code-review-workflow",
18562
- "grilling",
18563
- "research"
18564
- ];
18565
18755
  /**
18566
18756
  * Resolve the private Team Skill root.
18567
18757
  * @param configured - an explicit `skillRoot` from the plugin config, when set.
@@ -18578,21 +18768,6 @@ function resolveSkillRoot(configured) {
18578
18768
  function officialSkillDirectory() {
18579
18769
  return join(dirname(dirname(fileURLToPath(import.meta.url))), "assets", "skills");
18580
18770
  }
18581
- /**
18582
- * Resolve the role identity one live member belongs to.
18583
- *
18584
- * The member's own durable snapshot names the role, and the roster gives the
18585
- * teammate target; a role without a stored identity falls back to its display
18586
- * name, which is how shipped presets identify their members.
18587
- * @param team - the Team the member belongs to.
18588
- * @param memberTarget - the target the captain summoned it under.
18589
- * @returns the role identity, or undefined when the target matches no member.
18590
- */
18591
- function roleOfMember(team, memberTarget) {
18592
- const row = memberTargets(team).find((candidate) => candidate.target === memberTarget);
18593
- if (row === void 0) return void 0;
18594
- return row.member.id ?? row.member.name;
18595
- }
18596
18771
  /** The Team Skill subsystem, ready for the runtime to drive. */
18597
18772
  var TeamSkills = class {
18598
18773
  root;
@@ -18659,6 +18834,7 @@ var TeamSkills = class {
18659
18834
  }
18660
18835
  this.official = entries.map((entry) => entry.skillId);
18661
18836
  const warnings = [];
18837
+ await this.store.renameLegacyCopies(OFFICIAL_SKILL_IDS);
18662
18838
  const changed = await this.store.ensureOfficial(entries, warnings);
18663
18839
  for (const warning of warnings) log(warning);
18664
18840
  if (changed.length > 0) log(`Team Skill store updated: ${changed.join(", ")}`);
@@ -18827,9 +19003,6 @@ var __esDecorate$1 = function(ctor, descriptorIn, decorators, contextIn, initial
18827
19003
  if (target) Object.defineProperty(target, contextIn.name, descriptor);
18828
19004
  done = true;
18829
19005
  };
18830
- /** Text the page shows when this deployment could not open its store. */
18831
- /** Folder under the private root that a scan reads. */
18832
- const IMPORT_FOLDER = "inbox";
18833
19006
  const UNAVAILABLE = "the Team Skill store could not be opened in this deployment";
18834
19007
  /** Blank instruction text a freshly created skill starts from. */
18835
19008
  const TEMPLATE = "---\nname: SKILL-ID\ndescription: Describe when this method applies.\n---\n\n# Method\n\nDescribe the steps to follow.\n";
@@ -19118,7 +19291,7 @@ let TeamSkillService = (() => {
19118
19291
  * List the library, the roster, and the shipped skill ids.
19119
19292
  * @returns one page load.
19120
19293
  */
19121
- async library() {
19294
+ async library(checkInbox) {
19122
19295
  const issue = await this.settle();
19123
19296
  if (issue !== void 0) return {
19124
19297
  root: this.config.store.root,
@@ -19127,6 +19300,7 @@ let TeamSkillService = (() => {
19127
19300
  official: [],
19128
19301
  issue
19129
19302
  };
19303
+ const check = checkInbox === true ? await this.checkInbox() : void 0;
19130
19304
  return {
19131
19305
  root: this.config.store.root,
19132
19306
  assets: this.config.store.list().flatMap((asset) => {
@@ -19134,7 +19308,12 @@ let TeamSkillService = (() => {
19134
19308
  return row === void 0 ? [] : [row];
19135
19309
  }),
19136
19310
  teams: this.roster(),
19137
- official: [...this.config.official()]
19311
+ official: [...this.config.official()],
19312
+ ...check === void 0 ? {} : { inboxChanges: Array.isArray(check) ? check.filter((entry) => entry.status !== "existing").map(({ digest: _digest, ...entry }) => entry) : [{
19313
+ folder: SKILL_IMPORT_FOLDER,
19314
+ status: "invalid",
19315
+ reason: "unreadable"
19316
+ }] }
19138
19317
  };
19139
19318
  }
19140
19319
  /**
@@ -19175,7 +19354,7 @@ let TeamSkillService = (() => {
19175
19354
  text: file.text
19176
19355
  })),
19177
19356
  body,
19178
- directory: this.config.store.assetPath(asset.id, asset.version),
19357
+ directory: asset.sourceFolder === void 0 ? this.config.store.assetPath(asset.id, asset.version) : this.config.store.sourcePath(asset.sourceFolder),
19179
19358
  dependencies: report
19180
19359
  };
19181
19360
  }
@@ -19211,9 +19390,10 @@ let TeamSkillService = (() => {
19211
19390
  * @param assetId - asset identity.
19212
19391
  * @param path - relative path.
19213
19392
  * @param text - new content.
19393
+ * @param expectedVersion - the version the editor has open.
19214
19394
  * @returns the refreshed detail, or a refusal.
19215
19395
  */
19216
- async writeFile(assetId, path, text) {
19396
+ async writeFile(assetId, path, text, expectedVersion) {
19217
19397
  const issue = await this.settle();
19218
19398
  if (issue !== void 0) return {
19219
19399
  ok: false,
@@ -19221,7 +19401,7 @@ let TeamSkillService = (() => {
19221
19401
  detail: issue
19222
19402
  };
19223
19403
  try {
19224
- await this.config.store.writeFile(assetId, path, text);
19404
+ await this.config.store.writeFile(assetId, path, text, expectedVersion);
19225
19405
  } catch (error) {
19226
19406
  return {
19227
19407
  ok: false,
@@ -19232,6 +19412,9 @@ let TeamSkillService = (() => {
19232
19412
  this.config.resync();
19233
19413
  return this.detail(assetId);
19234
19414
  }
19415
+ reservedSkillName(name) {
19416
+ return OFFICIAL_SKILL_IDS.some((skillId) => skillId === name) || this.config.official().includes(name) || this.config.store.get(`builtin:${name}`) !== void 0;
19417
+ }
19235
19418
  /**
19236
19419
  * Create one editable skill from the blank template.
19237
19420
  * @param skillId - kebab-case name the new skill takes.
@@ -19256,6 +19439,11 @@ let TeamSkillService = (() => {
19256
19439
  detail: `"${skillId}" is not a legal skill id.`
19257
19440
  };
19258
19441
  const id = `custom:${skillId}`;
19442
+ if (this.reservedSkillName(result.skill.name)) return {
19443
+ ok: false,
19444
+ reason: "builtin-name-conflict",
19445
+ detail: `"${result.skill.name}" is reserved for a read-only built-in Team Skill.`
19446
+ };
19259
19447
  if (this.config.store.list().some((asset) => asset.skillId === result.skill.name)) return {
19260
19448
  ok: false,
19261
19449
  reason: "duplicate",
@@ -19308,6 +19496,11 @@ let TeamSkillService = (() => {
19308
19496
  detail: `${result.reason}${result.path === void 0 ? "" : ` at ${result.path}`}`
19309
19497
  };
19310
19498
  const id = `custom:${result.skill.name}`;
19499
+ if (this.reservedSkillName(result.skill.name)) return {
19500
+ ok: false,
19501
+ reason: "builtin-name-conflict",
19502
+ detail: `"${result.skill.name}" is reserved for a read-only built-in Team Skill.`
19503
+ };
19311
19504
  if (this.config.store.list().some((asset) => asset.skillId === result.skill.name)) return {
19312
19505
  ok: false,
19313
19506
  reason: "duplicate",
@@ -19326,7 +19519,11 @@ let TeamSkillService = (() => {
19326
19519
  detail: String(error)
19327
19520
  };
19328
19521
  }
19329
- return this.detail(id);
19522
+ const detail = await this.detail(id);
19523
+ return "asset" in detail && result.dependencyWarnings.length > 0 ? {
19524
+ ...detail,
19525
+ ignoredDependencyFields: result.dependencyWarnings.map((warning) => warning.field)
19526
+ } : detail;
19330
19527
  }
19331
19528
  /**
19332
19529
  * Create the private import directory when it is missing.
@@ -19343,7 +19540,7 @@ let TeamSkillService = (() => {
19343
19540
  reason: "unavailable",
19344
19541
  detail: issue
19345
19542
  };
19346
- const path = join(this.config.store.root, IMPORT_FOLDER);
19543
+ const path = join(this.config.store.root, SKILL_IMPORT_FOLDER);
19347
19544
  try {
19348
19545
  await assertNoSymlinks(path);
19349
19546
  await mkdir(path, { recursive: true });
@@ -19361,128 +19558,184 @@ let TeamSkillService = (() => {
19361
19558
  path
19362
19559
  };
19363
19560
  }
19364
- /**
19365
- * Scan the private import directory and publish every legal new skill.
19366
- *
19367
- * The directory is the only supported way to hand the plugin a skill without
19368
- * the browser picker. Each folder is judged by the same importer rules as a
19369
- * picked folder, and the answer names the exact refusal for the ones that
19370
- * fail, so the page can list them instead of reporting a single count.
19371
- * @returns one row per folder, or a refusal when the store is unavailable.
19372
- */
19373
- async scanImportFolder() {
19374
- const issue = await this.settle();
19375
- if (issue !== void 0) return {
19376
- ok: false,
19377
- reason: "unavailable",
19378
- detail: issue
19379
- };
19380
- const root = join(this.config.store.root, IMPORT_FOLDER);
19561
+ async checkInbox() {
19562
+ const root = join(this.config.store.root, SKILL_IMPORT_FOLDER);
19381
19563
  let dirents;
19382
19564
  try {
19383
19565
  await assertNoSymlinks(root);
19384
19566
  dirents = await readdir(root, { withFileTypes: true });
19385
19567
  } catch (error) {
19386
- if (error.code === "ENOENT") return {
19387
- ok: true,
19388
- root,
19389
- scanned: 0,
19390
- imported: 0,
19391
- existing: 0,
19392
- invalid: 0,
19393
- entries: []
19394
- };
19395
- return {
19568
+ if (error.code !== "ENOENT") return {
19396
19569
  ok: false,
19397
19570
  reason: "scan-refused",
19398
19571
  detail: String(error)
19399
19572
  };
19573
+ dirents = [];
19574
+ }
19575
+ const entries = [];
19576
+ const names = /* @__PURE__ */ new Map();
19577
+ for (const dirent of dirents.sort((left, right) => left.name.localeCompare(right.name))) {
19578
+ const folder = dirent.name;
19579
+ if (folder.startsWith(".")) continue;
19580
+ if (!dirent.isDirectory()) {
19581
+ entries.push({
19582
+ folder,
19583
+ status: "invalid",
19584
+ reason: dirent.isSymbolicLink() ? "symlink-escape" : "not-directory"
19585
+ });
19586
+ continue;
19587
+ }
19588
+ const inspected = await inspectSkillDirectory(join(root, folder));
19589
+ if (!inspected.ok) {
19590
+ entries.push({
19591
+ folder,
19592
+ status: "invalid",
19593
+ reason: inspected.reason,
19594
+ ...inspected.path === void 0 ? {} : { detail: inspected.path }
19595
+ });
19596
+ continue;
19597
+ }
19598
+ const skillId = inspected.skill.name;
19599
+ const ignoredDependencyFields = inspected.dependencyWarnings.map((warning) => warning.field);
19600
+ const info = {
19601
+ folder,
19602
+ skillId,
19603
+ ...ignoredDependencyFields.length === 0 ? {} : { ignoredDependencyFields }
19604
+ };
19605
+ if (this.reservedSkillName(skillId)) {
19606
+ entries.push({
19607
+ ...info,
19608
+ status: "invalid",
19609
+ reason: "builtin-name-conflict"
19610
+ });
19611
+ continue;
19612
+ }
19613
+ const current = this.config.store.bySkillId(skillId);
19614
+ if (current !== void 0 && current.origin !== "custom") {
19615
+ entries.push({
19616
+ ...info,
19617
+ status: "invalid",
19618
+ reason: "copy-name-conflict",
19619
+ assetId: current.id
19620
+ });
19621
+ continue;
19622
+ }
19623
+ const digest = folderDigest(fileTable(inspected.skill.files));
19624
+ const duplicate = names.get(skillId);
19625
+ if (duplicate !== void 0) {
19626
+ entries[duplicate] = {
19627
+ ...entries[duplicate],
19628
+ status: "invalid",
19629
+ reason: "duplicate-source-name"
19630
+ };
19631
+ entries.push({
19632
+ ...info,
19633
+ status: "invalid",
19634
+ reason: "duplicate-source-name"
19635
+ });
19636
+ continue;
19637
+ }
19638
+ names.set(skillId, entries.length);
19639
+ if (current === void 0) entries.push({
19640
+ ...info,
19641
+ status: "imported",
19642
+ digest
19643
+ });
19644
+ else entries.push({
19645
+ ...info,
19646
+ assetId: current.id,
19647
+ digest,
19648
+ status: current.digest !== digest || current.sourceFolder !== void 0 && current.sourceFolder !== folder ? "updated" : "existing"
19649
+ });
19400
19650
  }
19401
- return this.config.store.withLock(async () => {
19651
+ for (const asset of this.config.store.list()) {
19652
+ if (asset.sourceFolder === void 0 || names.has(asset.skillId)) continue;
19653
+ if (entries.some((entry) => entry.folder === asset.sourceFolder && entry.status === "invalid")) continue;
19654
+ entries.push({
19655
+ folder: asset.sourceFolder,
19656
+ status: "missing",
19657
+ skillId: asset.skillId,
19658
+ assetId: asset.id,
19659
+ reason: "source-missing"
19660
+ });
19661
+ }
19662
+ return entries;
19663
+ }
19664
+ /** Validate sources, publishing changed packages as new versions only on this explicit request. */
19665
+ async scanImportFolder() {
19666
+ const issue = await this.settle();
19667
+ if (issue !== void 0) return {
19668
+ ok: false,
19669
+ reason: "unavailable",
19670
+ detail: issue
19671
+ };
19672
+ const root = join(this.config.store.root, SKILL_IMPORT_FOLDER);
19673
+ const result = await this.config.store.withLock(async () => {
19674
+ const planned = await this.checkInbox();
19675
+ if (!Array.isArray(planned)) return planned;
19402
19676
  const entries = [];
19403
- for (const dirent of dirents.sort((left, right) => left.name.localeCompare(right.name))) {
19404
- if (dirent.name.startsWith(".")) continue;
19405
- if (!dirent.isDirectory()) {
19406
- entries.push({
19407
- folder: dirent.name,
19408
- status: "invalid",
19409
- reason: dirent.isSymbolicLink() ? "symlink-escape" : "not-directory"
19410
- });
19677
+ for (const { digest, ...entry } of planned) {
19678
+ if (entry.status === "invalid" || entry.status === "missing") {
19679
+ entries.push(entry);
19411
19680
  continue;
19412
19681
  }
19413
- const inspected = await inspectSkillDirectory(join(root, dirent.name));
19414
- if (!inspected.ok) {
19682
+ const inspected = await inspectSkillDirectory(join(root, entry.folder));
19683
+ if (!inspected.ok || inspected.skill.name !== entry.skillId || folderDigest(fileTable(inspected.skill.files)) !== digest) {
19415
19684
  entries.push({
19416
- folder: dirent.name,
19685
+ ...entry,
19417
19686
  status: "invalid",
19418
- reason: inspected.reason,
19419
- ...inspected.path === void 0 ? {} : { detail: inspected.path }
19420
- });
19421
- continue;
19422
- }
19423
- const skillId = inspected.skill.name;
19424
- const clash = this.config.store.list().find((asset) => asset.skillId === skillId);
19425
- if (clash !== void 0) {
19426
- entries.push({
19427
- folder: dirent.name,
19428
- status: "existing",
19429
- skillId,
19430
- assetId: clash.id,
19431
- reason: "duplicate"
19687
+ reason: "source-changed"
19432
19688
  });
19433
19689
  continue;
19434
19690
  }
19435
19691
  try {
19436
- const asset = await this.config.store.install(inspected.skill, {
19437
- id: `custom:${skillId}`,
19438
- origin: "custom",
19439
- version: "1"
19440
- });
19692
+ const status = await this.config.store.publishSource(entry.folder, inspected.skill);
19441
19693
  entries.push({
19442
- folder: dirent.name,
19443
- status: "imported",
19444
- skillId,
19445
- assetId: asset.id
19694
+ ...entry,
19695
+ status,
19696
+ assetId: this.config.store.bySkillId(inspected.skill.name).id
19446
19697
  });
19447
19698
  } catch (error) {
19448
19699
  entries.push({
19449
- folder: dirent.name,
19700
+ ...entry,
19450
19701
  status: "invalid",
19451
- skillId,
19452
19702
  reason: "install-refused",
19453
19703
  detail: String(error)
19454
19704
  });
19455
19705
  }
19456
19706
  }
19457
19707
  const count = (status) => entries.filter((entry) => entry.status === status).length;
19708
+ const missing = count("missing");
19458
19709
  return {
19459
19710
  ok: true,
19460
19711
  root,
19461
- scanned: entries.length,
19712
+ scanned: entries.length - missing,
19462
19713
  imported: count("imported"),
19714
+ updated: count("updated"),
19463
19715
  existing: count("existing"),
19464
19716
  invalid: count("invalid"),
19717
+ missing,
19465
19718
  entries
19466
19719
  };
19467
19720
  });
19721
+ if (result.ok && (result.updated > 0 || result.imported > 0)) this.config.resync();
19722
+ return result;
19468
19723
  }
19469
19724
  /**
19470
19725
  * Copy one shipped skill into an editable override.
19471
19726
  * @param skillId - shipped skill id.
19472
19727
  * @returns the new detail, or a refusal.
19473
19728
  */
19474
- async overrideSkill(skillId) {
19729
+ async overrideSkill(skillId, switchBindings) {
19475
19730
  const issue = await this.settle();
19476
19731
  if (issue !== void 0) return {
19477
19732
  ok: false,
19478
19733
  reason: "unavailable",
19479
19734
  detail: issue
19480
19735
  };
19481
- const id = `override:${skillId}`;
19736
+ let id;
19482
19737
  try {
19483
- await this.config.store.createOverride(skillId, id);
19484
- await this.config.manager.replaceBuiltinBindings(skillId, id);
19485
- this.config.resync();
19738
+ id = (await this.config.store.createOverride(skillId, void 0, [...OFFICIAL_SKILL_IDS, ...this.config.official()])).id;
19486
19739
  } catch (error) {
19487
19740
  return {
19488
19741
  ok: false,
@@ -19490,7 +19743,18 @@ let TeamSkillService = (() => {
19490
19743
  detail: String(error)
19491
19744
  };
19492
19745
  }
19493
- return this.detail(id);
19746
+ let bindingSwitchIssue;
19747
+ if (switchBindings === true) try {
19748
+ await this.config.manager.replaceBuiltinBindings(skillId, id);
19749
+ this.config.resync();
19750
+ } catch (error) {
19751
+ bindingSwitchIssue = String(error);
19752
+ }
19753
+ const detail = await this.detail(id);
19754
+ return "asset" in detail && bindingSwitchIssue !== void 0 ? {
19755
+ ...detail,
19756
+ bindingSwitchIssue
19757
+ } : detail;
19494
19758
  }
19495
19759
  async updateDependencies(assetId, dependencies) {
19496
19760
  const issue = await this.settle();
@@ -21189,8 +21453,7 @@ function apply(ctx, config) {
21189
21453
  quarantines.get(agent)?.dispose();
21190
21454
  quarantines.delete(agent);
21191
21455
  managedMembers.add(agent);
21192
- const claimedTeam = findTeam(config.teams.get(), claim.record.teamId);
21193
- const role = claim.record.roleId ?? (claimedTeam === void 0 ? claim.record.memberName : roleOfMember(claimedTeam, claim.record.memberName));
21456
+ const role = recordedMemberRole(findTeam(config.teams.get(), claim.record.teamId), claim.record);
21194
21457
  let installation;
21195
21458
  if (role !== void 0) {
21196
21459
  const assignment = {