dsh-agent-team-presets 0.3.2 → 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 (121) hide show
  1. package/NOTICE +58 -3
  2. package/README.md +73 -398
  3. package/README.zh.md +79 -404
  4. package/assets/card-patches/catalog.json +30 -0
  5. package/assets/card-patches/dsh-context-0.85.0.client.js.gz +0 -0
  6. package/assets/card-patches/dsh-context-0.85.1.client.js.gz +0 -0
  7. package/assets/card-patches/dsh-context-0.87.0.client.js.gz +0 -0
  8. package/assets/skills/agent-leader-communication/SKILL.md +100 -0
  9. package/assets/skills/agent-subagent-orchestration/SKILL.md +56 -0
  10. package/assets/skills/agent-subagent-orchestration/references/executor-parallel-execution.md +56 -0
  11. package/assets/skills/agent-subagent-orchestration/references/leader-discovery.md +53 -0
  12. package/assets/skills/agent-subagent-orchestration/references/subagent-communication.md +58 -0
  13. package/assets/skills/backend-architecture-workflow/SKILL.md +55 -0
  14. package/assets/skills/backend-architecture-workflow/references/README.md +9 -0
  15. package/assets/skills/backend-architecture-workflow/references/architecture-audit.md +70 -0
  16. package/assets/skills/backend-architecture-workflow/references/architecture-decay-risks.md +75 -0
  17. package/assets/skills/backend-architecture-workflow/references/architecture-design.md +151 -0
  18. package/assets/skills/backend-architecture-workflow/references/bugfix-regression.md +63 -0
  19. package/assets/skills/backend-architecture-workflow/references/complex-bug-diagnosis.md +104 -0
  20. package/assets/skills/executor-short-task-workflow/SKILL.md +48 -0
  21. package/assets/skills/executor-short-task-workflow/references/agent-communication.md +44 -0
  22. package/assets/skills/executor-short-task-workflow/references/verification-and-reporting.md +45 -0
  23. package/assets/skills/frontend-engineering-workflow/SKILL.md +47 -0
  24. package/assets/skills/frontend-engineering-workflow/references/README.md +7 -0
  25. package/assets/skills/frontend-engineering-workflow/references/frontend-implementation.md +46 -0
  26. package/assets/skills/frontend-engineering-workflow/references/visual-design.md +43 -0
  27. package/assets/skills/frontend-engineering-workflow/references/visual-qa.md +126 -0
  28. package/assets/skills/fullstack-advisor/SKILL.md +50 -0
  29. package/assets/skills/fullstack-advisor/references/brooks-principles.md +51 -0
  30. package/assets/skills/fullstack-advisor/references/consultant-communication.md +51 -0
  31. package/assets/skills/fullstack-advisor/references/consultation-workflow.md +71 -0
  32. package/assets/skills/git-release-hygiene/SKILL.md +33 -21
  33. package/assets/skills/git-release-hygiene/references/git-safety.md +66 -0
  34. package/assets/skills/git-release-hygiene/references/pr-changelog.md +98 -0
  35. package/assets/skills/git-release-hygiene/references/release-standard.md +139 -0
  36. package/assets/skills/git-release-hygiene/references/validation-checklist.md +42 -0
  37. package/assets/skills/github-repository-presentation/SKILL.md +49 -130
  38. package/assets/skills/github-repository-presentation/references/bilingual-writing.md +43 -0
  39. package/assets/skills/github-repository-presentation/references/documentation-architecture.md +156 -0
  40. package/assets/skills/github-repository-presentation/references/readme-standard.md +273 -0
  41. package/assets/skills/github-repository-presentation/references/release-notes.md +70 -0
  42. package/assets/skills/github-repository-presentation/references/validation-checklist.md +47 -0
  43. package/assets/skills/independent-code-review-workflow/SKILL.md +60 -0
  44. package/assets/skills/independent-code-review-workflow/references/README.md +9 -0
  45. package/assets/skills/independent-code-review-workflow/references/decay-risks.md +99 -0
  46. package/assets/skills/independent-code-review-workflow/references/review-checklist.md +53 -0
  47. package/assets/skills/independent-code-review-workflow/references/review-methodology.md +113 -0
  48. package/assets/skills/independent-code-review-workflow/references/review-severity.md +49 -0
  49. package/assets/skills/independent-code-review-workflow/references/test-quality-review.md +71 -0
  50. package/assets/skills/leader-long-task-orchestration/SKILL.md +49 -0
  51. package/assets/skills/leader-long-task-orchestration/references/delivery-plan-template.md +73 -0
  52. package/assets/skills/leader-long-task-orchestration/references/product-alignment.md +46 -0
  53. package/assets/skills/leader-long-task-orchestration/references/rolling-wave-planning.md +32 -0
  54. package/assets/skills/leader-long-task-orchestration/references/technical-decisions-and-escalation.md +34 -0
  55. package/assets/skills/leader-medium-task-workflow/SKILL.md +55 -0
  56. package/assets/skills/leader-medium-task-workflow/references/task-board-and-leader-todo.md +41 -0
  57. package/docs/builtin-team-skills.md +82 -0
  58. package/docs/builtin-team-skills.zh.md +82 -0
  59. package/docs/builtin-teams.md +62 -0
  60. package/docs/builtin-teams.zh.md +62 -0
  61. package/docs/developer/architecture.md +54 -0
  62. package/docs/developer/architecture.zh.md +54 -0
  63. package/docs/guide/install.md +86 -0
  64. package/docs/guide/install.zh.md +86 -0
  65. package/docs/guide/integrations.md +50 -0
  66. package/docs/guide/integrations.zh.md +50 -0
  67. package/docs/guide/team-skills.md +68 -0
  68. package/docs/guide/team-skills.zh.md +68 -0
  69. package/docs/guide/using-teams.md +92 -0
  70. package/docs/guide/using-teams.zh.md +92 -0
  71. package/docs/index.md +53 -0
  72. package/docs/index.zh.md +53 -0
  73. package/docs/reference/tools-and-permissions.md +62 -0
  74. package/docs/reference/tools-and-permissions.zh.md +62 -0
  75. package/docs/reference/troubleshooting.md +59 -0
  76. package/docs/reference/troubleshooting.zh.md +59 -0
  77. package/icon.webp +0 -0
  78. package/lib/client.js +1459 -253
  79. package/lib/index.js +960 -342
  80. package/lib/typert.host.js +402 -29
  81. package/lib/typert.remote-client.d.ts +9 -9
  82. package/lib/typert.remote-client.d.ts.map +1 -1
  83. package/lib/typert.remote-client.js +402 -29
  84. package/lib/types/client/CardPatchView.js +21 -1
  85. package/lib/types/client/ComposerTeamSelect.js +24 -8
  86. package/lib/types/client/TeamAgentView.d.ts +1 -1
  87. package/lib/types/client/TeamAgentView.js +11 -6
  88. package/lib/types/client/TeamImportDialog.d.ts +4 -15
  89. package/lib/types/client/TeamImportDialog.js +29 -25
  90. package/lib/types/client/TeamPresetsSection.js +14 -5
  91. package/lib/types/client/TeamSkillsView.d.ts +5 -4
  92. package/lib/types/client/TeamSkillsView.js +64 -15
  93. package/lib/types/client/locales.d.ts +41 -2
  94. package/lib/types/client/locales.js +185 -8
  95. package/lib/types/client/team-presets-controller.d.ts +15 -2
  96. package/lib/types/client/team-presets-controller.js +86 -30
  97. package/lib/types/client/team-skills-controller.d.ts +14 -5
  98. package/lib/types/client/team-skills-controller.js +71 -37
  99. package/lib/types/index.js +57 -19
  100. package/lib/types/preset-editor.js +3 -4
  101. package/lib/types/preset-transfer.d.ts +1 -1
  102. package/lib/types/presets.d.ts +21 -23
  103. package/lib/types/presets.js +72 -36
  104. package/lib/types/team-catalog.d.ts +50 -3
  105. package/lib/types/team-catalog.js +214 -43
  106. package/lib/types/team-mode.d.ts +48 -0
  107. package/lib/types/team-mode.js +64 -0
  108. package/lib/types/team-skills/import.d.ts +17 -7
  109. package/lib/types/team-skills/import.js +115 -21
  110. package/lib/types/team-skills/index.d.ts +2 -3
  111. package/lib/types/team-skills/index.js +4 -8
  112. package/lib/types/team-skills/manager.d.ts +24 -15
  113. package/lib/types/team-skills/manager.js +98 -105
  114. package/lib/types/team-skills/official-bindings.d.ts +29 -0
  115. package/lib/types/team-skills/official-bindings.js +51 -0
  116. package/lib/types/team-skills/service.d.ts +7 -12
  117. package/lib/types/team-skills/service.js +143 -63
  118. package/lib/types/team-skills/store.d.ts +27 -6
  119. package/lib/types/team-skills/store.js +151 -15
  120. package/lib/types/types.d.ts +18 -4
  121. package/package.json +21 -2
@@ -0,0 +1,51 @@
1
+ import { builtinEntry } from "../team-catalog.js";
2
+ /** Skills shipped under `assets/skills`, including assets missing from this installation. */
3
+ export const OFFICIAL_SKILL_IDS = [
4
+ 'agent-leader-communication',
5
+ 'leader-medium-task-workflow',
6
+ 'leader-long-task-orchestration',
7
+ 'agent-subagent-orchestration',
8
+ 'fullstack-advisor',
9
+ 'executor-short-task-workflow',
10
+ 'github-repository-presentation',
11
+ 'git-release-hygiene',
12
+ 'frontend-engineering-workflow',
13
+ 'backend-architecture-workflow',
14
+ 'independent-code-review-workflow',
15
+ 'grilling',
16
+ 'research',
17
+ ];
18
+ const officialIds = new Set(OFFICIAL_SKILL_IDS);
19
+ /** The binding slot reserved for a captain. */
20
+ export const CAPTAIN_ROLE = 'captain';
21
+ /** Shipped identities always use the catalog, including records from earlier releases. */
22
+ export function officialSkillDefaults(team) {
23
+ const entry = builtinEntry(team.id);
24
+ return entry === undefined
25
+ ? { source: 'preset', declarations: team.officialSkills ?? [] }
26
+ : { source: 'catalog', declarations: entry.officialSkillBindings };
27
+ }
28
+ /** A declaration can address only an unambiguous name and an unambiguous binding slot. */
29
+ export function officialSkillTarget(team, declaration) {
30
+ if (!officialIds.has(declaration.skillId))
31
+ return { status: 'unknown-skill' };
32
+ const roles = [
33
+ { name: team.captain.name, id: CAPTAIN_ROLE },
34
+ ...team.members.map(member => ({ name: member.name, id: member.id ?? member.name })),
35
+ ];
36
+ const [role, otherMatch] = roles.filter(candidate => candidate.name === declaration.roleName);
37
+ if (role === undefined)
38
+ return { status: 'missing-role' };
39
+ if (otherMatch !== undefined || roles.filter(candidate => candidate.id === role.id).length !== 1) {
40
+ return { status: 'ambiguous-role' };
41
+ }
42
+ return { status: 'valid', roleId: role.id, assetId: `builtin:${declaration.skillId}` };
43
+ }
44
+ /** A default can seed only the shipped asset with the declared identity. */
45
+ export function isOfficialSkillAsset(asset, assetId) {
46
+ return asset.origin === 'builtin' && asset.id === assetId;
47
+ }
48
+ /** A role that already holds a derived override keeps its explicit assignment. */
49
+ export function isOfficialSkillOverride(asset, skillId) {
50
+ return asset.origin === 'override' && asset.officialSkillId === skillId;
51
+ }
@@ -66,7 +66,7 @@ export declare class TeamSkillService extends TypertRemoteService {
66
66
  * List the library, the roster, and the shipped skill ids.
67
67
  * @returns one page load.
68
68
  */
69
- library(): Promise<TeamSkillLibraryView>;
69
+ library(checkInbox?: boolean): Promise<TeamSkillLibraryView>;
70
70
  /**
71
71
  * Read one asset with its files and body.
72
72
  * @param assetId - asset identity.
@@ -89,9 +89,11 @@ export declare class TeamSkillService extends TypertRemoteService {
89
89
  * @param assetId - asset identity.
90
90
  * @param path - relative path.
91
91
  * @param text - new content.
92
+ * @param expectedVersion - the version the editor has open.
92
93
  * @returns the refreshed detail, or a refusal.
93
94
  */
94
- writeFile(assetId: string, path: string, text: string): Promise<TeamSkillDetailView | TeamSkillRefusalView>;
95
+ writeFile(assetId: string, path: string, text: string, expectedVersion?: string): Promise<TeamSkillDetailView | TeamSkillRefusalView>;
96
+ private reservedSkillName;
95
97
  /**
96
98
  * Create one editable skill from the blank template.
97
99
  * @param skillId - kebab-case name the new skill takes.
@@ -114,22 +116,15 @@ export declare class TeamSkillService extends TypertRemoteService {
114
116
  * @returns the absolute folder, or a refusal when it cannot be created safely.
115
117
  */
116
118
  prepareImportFolder(): Promise<TeamSkillImportFolderView | TeamSkillRefusalView>;
117
- /**
118
- * Scan the private import directory and publish every legal new skill.
119
- *
120
- * The directory is the only supported way to hand the plugin a skill without
121
- * the browser picker. Each folder is judged by the same importer rules as a
122
- * picked folder, and the answer names the exact refusal for the ones that
123
- * fail, so the page can list them instead of reporting a single count.
124
- * @returns one row per folder, or a refusal when the store is unavailable.
125
- */
119
+ private checkInbox;
120
+ /** Validate sources, publishing changed packages as new versions only on this explicit request. */
126
121
  scanImportFolder(): Promise<TeamSkillScanView | TeamSkillRefusalView>;
127
122
  /**
128
123
  * Copy one shipped skill into an editable override.
129
124
  * @param skillId - shipped skill id.
130
125
  * @returns the new detail, or a refusal.
131
126
  */
132
- overrideSkill(skillId: string): Promise<TeamSkillDetailView | TeamSkillRefusalView>;
127
+ overrideSkill(skillId: string, switchBindings?: boolean): Promise<TeamSkillDetailView | TeamSkillRefusalView>;
133
128
  updateDependencies(assetId: string, dependencies: TeamSkillDependencies): Promise<TeamSkillDetailView | TeamSkillRefusalView>;
134
129
  /**
135
130
  * Reset one override back to the shipped copy.
@@ -46,12 +46,10 @@ import { mkdir, readdir } from 'node:fs/promises';
46
46
  import { join } from 'node:path';
47
47
  import { Remote, TypertRemoteService } from '@deepseek-ai/dsh-typert-protocol';
48
48
  import { buildSkillPackage, decodeImportFiles } from "./import.js";
49
- import { CAPTAIN_ROLE } from "./manager.js";
49
+ import { CAPTAIN_ROLE, sanctionedCopy } from "./manager.js";
50
+ import { OFFICIAL_SKILL_IDS } from "./official-bindings.js";
50
51
  import { assertNoSymlinks } from "./paths.js";
51
- import { inspectSkillDirectory } from "./store.js";
52
- /** Text the page shows when this deployment could not open its store. */
53
- /** Folder under the private root that a scan reads. */
54
- const IMPORT_FOLDER = 'inbox';
52
+ import { fileTable, folderDigest, inspectSkillDirectory, SKILL_IMPORT_FOLDER } from "./store.js";
55
53
  const UNAVAILABLE = 'the Team Skill store could not be opened in this deployment';
56
54
  /** Blank instruction text a freshly created skill starts from. */
57
55
  const TEMPLATE = '---\nname: SKILL-ID\ndescription: Describe when this method applies.\n---\n\n# Method\n\nDescribe the steps to follow.\n';
@@ -163,12 +161,13 @@ let TeamSkillService = (() => {
163
161
  fileCount: asset.files.length,
164
162
  totalBytes: asset.files.reduce((sum, file) => sum + file.size, 0),
165
163
  mcpServers: asset.dependencies.mcpServers.map(server => server.serverName),
166
- // A name can legitimately exist under several origins (the official copy, a
167
- // local override of it, and a user skill that happens to share the name).
168
- // They never overwrite each other, so the page states the coexistence
169
- // instead of pretending one won.
164
+ // A name can legitimately exist under several origins, but two of them are
165
+ // the SAME skill: the shipped copy and an override derived from it. That
166
+ // pair is a sanctioned copy, not a clash, and reporting it made a healthy
167
+ // library look broken. Anything else sharing the name is a real clash the
168
+ // page has to state, because nothing overwrites anything.
170
169
  clashesWith: this.config.store.list()
171
- .filter(other => other.id !== asset.id && other.skillId === asset.skillId)
170
+ .filter(other => other.id !== asset.id && other.skillId === asset.skillId && !sanctionedCopy(asset, other))
172
171
  .map(other => other.id),
173
172
  bindings: this.config.manager.bindingSummaries(assetId),
174
173
  };
@@ -193,11 +192,12 @@ let TeamSkillService = (() => {
193
192
  * List the library, the roster, and the shipped skill ids.
194
193
  * @returns one page load.
195
194
  */
196
- async library() {
195
+ async library(checkInbox) {
197
196
  const issue = await this.settle();
198
197
  if (issue !== undefined) {
199
198
  return { root: this.config.store.root, assets: [], teams: [], official: [], issue };
200
199
  }
200
+ const check = checkInbox === true ? await this.checkInbox() : undefined;
201
201
  return {
202
202
  root: this.config.store.root,
203
203
  assets: this.config.store.list().flatMap((asset) => {
@@ -206,6 +206,11 @@ let TeamSkillService = (() => {
206
206
  }),
207
207
  teams: this.roster(),
208
208
  official: [...this.config.official()],
209
+ ...(check === undefined ? {} : {
210
+ inboxChanges: Array.isArray(check)
211
+ ? check.filter(entry => entry.status !== 'existing').map(({ digest: _digest, ...entry }) => entry)
212
+ : [{ folder: SKILL_IMPORT_FOLDER, status: 'invalid', reason: 'unreadable' }],
213
+ }),
209
214
  };
210
215
  }
211
216
  /**
@@ -234,7 +239,9 @@ let TeamSkillService = (() => {
234
239
  asset: row,
235
240
  files: asset.files.map(file => ({ path: file.path, size: file.size, text: file.text })),
236
241
  body,
237
- directory: this.config.store.assetPath(asset.id, asset.version),
242
+ directory: asset.sourceFolder === undefined
243
+ ? this.config.store.assetPath(asset.id, asset.version)
244
+ : this.config.store.sourcePath(asset.sourceFolder),
238
245
  dependencies: report,
239
246
  };
240
247
  }
@@ -260,14 +267,15 @@ let TeamSkillService = (() => {
260
267
  * @param assetId - asset identity.
261
268
  * @param path - relative path.
262
269
  * @param text - new content.
270
+ * @param expectedVersion - the version the editor has open.
263
271
  * @returns the refreshed detail, or a refusal.
264
272
  */
265
- async writeFile(assetId, path, text) {
273
+ async writeFile(assetId, path, text, expectedVersion) {
266
274
  const issue = await this.settle();
267
275
  if (issue !== undefined)
268
276
  return { ok: false, reason: 'unavailable', detail: issue };
269
277
  try {
270
- await this.config.store.writeFile(assetId, path, text);
278
+ await this.config.store.writeFile(assetId, path, text, expectedVersion);
271
279
  }
272
280
  catch (error) {
273
281
  return { ok: false, reason: 'write-refused', detail: String(error) };
@@ -275,6 +283,10 @@ let TeamSkillService = (() => {
275
283
  this.config.resync();
276
284
  return this.detail(assetId);
277
285
  }
286
+ reservedSkillName(name) {
287
+ return OFFICIAL_SKILL_IDS.some(skillId => skillId === name) || this.config.official().includes(name)
288
+ || this.config.store.get(`builtin:${name}`) !== undefined;
289
+ }
278
290
  /**
279
291
  * Create one editable skill from the blank template.
280
292
  * @param skillId - kebab-case name the new skill takes.
@@ -290,6 +302,8 @@ let TeamSkillService = (() => {
290
302
  if (!result.ok)
291
303
  return { ok: false, reason: result.reason, detail: `"${skillId}" is not a legal skill id.` };
292
304
  const id = `custom:${skillId}`;
305
+ if (this.reservedSkillName(result.skill.name))
306
+ return { ok: false, reason: 'builtin-name-conflict', detail: `"${result.skill.name}" is reserved for a read-only built-in Team Skill.` };
293
307
  if (this.config.store.list().some(asset => asset.skillId === result.skill.name))
294
308
  return { ok: false, reason: 'duplicate', detail: `a skill named "${result.skill.name}" already exists` };
295
309
  try {
@@ -321,6 +335,8 @@ let TeamSkillService = (() => {
321
335
  return { ok: false, reason: result.reason, detail: `${result.reason}${result.path === undefined ? '' : ` at ${result.path}`}` };
322
336
  }
323
337
  const id = `custom:${result.skill.name}`;
338
+ if (this.reservedSkillName(result.skill.name))
339
+ return { ok: false, reason: 'builtin-name-conflict', detail: `"${result.skill.name}" is reserved for a read-only built-in Team Skill.` };
324
340
  if (this.config.store.list().some(asset => asset.skillId === result.skill.name)) {
325
341
  return { ok: false, reason: 'duplicate', detail: `a skill named "${result.skill.name}" already exists` };
326
342
  }
@@ -330,7 +346,10 @@ let TeamSkillService = (() => {
330
346
  catch (error) {
331
347
  return { ok: false, reason: 'install-refused', detail: String(error) };
332
348
  }
333
- return this.detail(id);
349
+ const detail = await this.detail(id);
350
+ return 'asset' in detail && result.dependencyWarnings.length > 0
351
+ ? { ...detail, ignoredDependencyFields: result.dependencyWarnings.map(warning => warning.field) }
352
+ : detail;
334
353
  }
335
354
  /**
336
355
  * Create the private import directory when it is missing.
@@ -344,7 +363,7 @@ let TeamSkillService = (() => {
344
363
  const issue = await this.settle();
345
364
  if (issue !== undefined)
346
365
  return { ok: false, reason: 'unavailable', detail: issue };
347
- const path = join(this.config.store.root, IMPORT_FOLDER);
366
+ const path = join(this.config.store.root, SKILL_IMPORT_FOLDER);
348
367
  try {
349
368
  await assertNoSymlinks(path);
350
369
  await mkdir(path, { recursive: true });
@@ -355,85 +374,136 @@ let TeamSkillService = (() => {
355
374
  }
356
375
  return { ok: true, root: this.config.store.root, path };
357
376
  }
358
- /**
359
- * Scan the private import directory and publish every legal new skill.
360
- *
361
- * The directory is the only supported way to hand the plugin a skill without
362
- * the browser picker. Each folder is judged by the same importer rules as a
363
- * picked folder, and the answer names the exact refusal for the ones that
364
- * fail, so the page can list them instead of reporting a single count.
365
- * @returns one row per folder, or a refusal when the store is unavailable.
366
- */
367
- async scanImportFolder() {
368
- const issue = await this.settle();
369
- if (issue !== undefined)
370
- return { ok: false, reason: 'unavailable', detail: issue };
371
- const root = join(this.config.store.root, IMPORT_FOLDER);
377
+ async checkInbox() {
378
+ const root = join(this.config.store.root, SKILL_IMPORT_FOLDER);
372
379
  let dirents;
373
380
  try {
374
381
  await assertNoSymlinks(root);
375
382
  dirents = await readdir(root, { withFileTypes: true });
376
383
  }
377
384
  catch (error) {
378
- if (error.code === 'ENOENT') {
379
- return { ok: true, root, scanned: 0, imported: 0, existing: 0, invalid: 0, entries: [] };
385
+ if (error.code !== 'ENOENT')
386
+ return { ok: false, reason: 'scan-refused', detail: String(error) };
387
+ dirents = [];
388
+ }
389
+ const entries = [];
390
+ const names = new Map();
391
+ for (const dirent of dirents.sort((left, right) => left.name.localeCompare(right.name))) {
392
+ const folder = dirent.name;
393
+ if (folder.startsWith('.'))
394
+ continue;
395
+ if (!dirent.isDirectory()) {
396
+ entries.push({ folder, status: 'invalid', reason: dirent.isSymbolicLink() ? 'symlink-escape' : 'not-directory' });
397
+ continue;
380
398
  }
381
- return { ok: false, reason: 'scan-refused', detail: String(error) };
382
- }
383
- // One scan is a check-and-publish across many folders; holding the store
384
- // lock keeps a concurrent assignment or edit from interleaving a version
385
- // publish between the duplicate check and the install.
386
- return this.config.store.withLock(async () => {
399
+ const inspected = await inspectSkillDirectory(join(root, folder));
400
+ if (!inspected.ok) {
401
+ entries.push({ folder, status: 'invalid', reason: inspected.reason, ...(inspected.path === undefined ? {} : { detail: inspected.path }) });
402
+ continue;
403
+ }
404
+ const skillId = inspected.skill.name;
405
+ const ignoredDependencyFields = inspected.dependencyWarnings.map(warning => warning.field);
406
+ const info = { folder, skillId, ...(ignoredDependencyFields.length === 0 ? {} : { ignoredDependencyFields }) };
407
+ if (this.reservedSkillName(skillId)) {
408
+ entries.push({ ...info, status: 'invalid', reason: 'builtin-name-conflict' });
409
+ continue;
410
+ }
411
+ const current = this.config.store.bySkillId(skillId);
412
+ if (current !== undefined && current.origin !== 'custom') {
413
+ entries.push({ ...info, status: 'invalid', reason: 'copy-name-conflict', assetId: current.id });
414
+ continue;
415
+ }
416
+ const digest = folderDigest(fileTable(inspected.skill.files));
417
+ const duplicate = names.get(skillId);
418
+ if (duplicate !== undefined) {
419
+ const previous = entries[duplicate];
420
+ entries[duplicate] = { ...previous, status: 'invalid', reason: 'duplicate-source-name' };
421
+ entries.push({ ...info, status: 'invalid', reason: 'duplicate-source-name' });
422
+ continue;
423
+ }
424
+ names.set(skillId, entries.length);
425
+ if (current === undefined)
426
+ entries.push({ ...info, status: 'imported', digest });
427
+ else
428
+ entries.push({ ...info, assetId: current.id, digest,
429
+ status: current.digest !== digest || (current.sourceFolder !== undefined && current.sourceFolder !== folder) ? 'updated' : 'existing' });
430
+ }
431
+ for (const asset of this.config.store.list()) {
432
+ if (asset.sourceFolder === undefined || names.has(asset.skillId))
433
+ continue;
434
+ if (entries.some(entry => entry.folder === asset.sourceFolder && entry.status === 'invalid'))
435
+ continue;
436
+ entries.push({ folder: asset.sourceFolder, status: 'missing', skillId: asset.skillId, assetId: asset.id, reason: 'source-missing' });
437
+ }
438
+ return entries;
439
+ }
440
+ /** Validate sources, publishing changed packages as new versions only on this explicit request. */
441
+ async scanImportFolder() {
442
+ const issue = await this.settle();
443
+ if (issue !== undefined)
444
+ return { ok: false, reason: 'unavailable', detail: issue };
445
+ const root = join(this.config.store.root, SKILL_IMPORT_FOLDER);
446
+ const result = await this.config.store.withLock(async () => {
447
+ const planned = await this.checkInbox();
448
+ if (!Array.isArray(planned))
449
+ return planned;
387
450
  const entries = [];
388
- for (const dirent of dirents.sort((left, right) => left.name.localeCompare(right.name))) {
389
- if (dirent.name.startsWith('.'))
390
- continue;
391
- if (!dirent.isDirectory()) {
392
- entries.push({ folder: dirent.name, status: 'invalid', reason: dirent.isSymbolicLink() ? 'symlink-escape' : 'not-directory' });
393
- continue;
394
- }
395
- const inspected = await inspectSkillDirectory(join(root, dirent.name));
396
- if (!inspected.ok) {
397
- entries.push({ folder: dirent.name, status: 'invalid', reason: inspected.reason, ...inspected.path === undefined ? {} : { detail: inspected.path } });
451
+ for (const { digest, ...entry } of planned) {
452
+ if (entry.status === 'invalid' || entry.status === 'missing') {
453
+ entries.push(entry);
398
454
  continue;
399
455
  }
400
- const skillId = inspected.skill.name;
401
- const clash = this.config.store.list().find(asset => asset.skillId === skillId);
402
- if (clash !== undefined) {
403
- entries.push({ folder: dirent.name, status: 'existing', skillId, assetId: clash.id, reason: 'duplicate' });
456
+ const inspected = await inspectSkillDirectory(join(root, entry.folder));
457
+ if (!inspected.ok || inspected.skill.name !== entry.skillId || folderDigest(fileTable(inspected.skill.files)) !== digest) {
458
+ entries.push({ ...entry, status: 'invalid', reason: 'source-changed' });
404
459
  continue;
405
460
  }
406
461
  try {
407
- const asset = await this.config.store.install(inspected.skill, { id: `custom:${skillId}`, origin: 'custom', version: '1' });
408
- entries.push({ folder: dirent.name, status: 'imported', skillId, assetId: asset.id });
462
+ const status = await this.config.store.publishSource(entry.folder, inspected.skill);
463
+ entries.push({ ...entry, status, assetId: this.config.store.bySkillId(inspected.skill.name).id });
409
464
  }
410
465
  catch (error) {
411
- entries.push({ folder: dirent.name, status: 'invalid', skillId, reason: 'install-refused', detail: String(error) });
466
+ entries.push({ ...entry, status: 'invalid', reason: 'install-refused', detail: String(error) });
412
467
  }
413
468
  }
414
469
  const count = (status) => entries.filter(entry => entry.status === status).length;
415
- return { ok: true, root, scanned: entries.length, imported: count('imported'), existing: count('existing'), invalid: count('invalid'), entries };
470
+ const missing = count('missing');
471
+ return { ok: true, root, scanned: entries.length - missing, imported: count('imported'), updated: count('updated'),
472
+ existing: count('existing'), invalid: count('invalid'), missing, entries };
416
473
  });
474
+ if (result.ok && (result.updated > 0 || result.imported > 0))
475
+ this.config.resync();
476
+ return result;
417
477
  }
418
478
  /**
419
479
  * Copy one shipped skill into an editable override.
420
480
  * @param skillId - shipped skill id.
421
481
  * @returns the new detail, or a refusal.
422
482
  */
423
- async overrideSkill(skillId) {
483
+ async overrideSkill(skillId, switchBindings) {
424
484
  const issue = await this.settle();
425
485
  if (issue !== undefined)
426
486
  return { ok: false, reason: 'unavailable', detail: issue };
427
- const id = `override:${skillId}`;
487
+ let id;
428
488
  try {
429
- await this.config.store.createOverride(skillId, id);
430
- await this.config.manager.replaceBuiltinBindings(skillId, id);
431
- this.config.resync();
489
+ const asset = await this.config.store.createOverride(skillId, undefined, [...OFFICIAL_SKILL_IDS, ...this.config.official()]);
490
+ id = asset.id;
432
491
  }
433
492
  catch (error) {
434
493
  return { ok: false, reason: 'override-refused', detail: String(error) };
435
494
  }
436
- return this.detail(id);
495
+ let bindingSwitchIssue;
496
+ if (switchBindings === true) {
497
+ try {
498
+ await this.config.manager.replaceBuiltinBindings(skillId, id);
499
+ this.config.resync();
500
+ }
501
+ catch (error) {
502
+ bindingSwitchIssue = String(error);
503
+ }
504
+ }
505
+ const detail = await this.detail(id);
506
+ return 'asset' in detail && bindingSwitchIssue !== undefined ? { ...detail, bindingSwitchIssue } : detail;
437
507
  }
438
508
  async updateDependencies(assetId, dependencies) {
439
509
  const issue = await this.settle();
@@ -458,7 +528,13 @@ let TeamSkillService = (() => {
458
528
  if (issue !== undefined)
459
529
  return { ok: false, reason: 'unavailable', detail: issue };
460
530
  try {
461
- await this.config.store.resetOverride(assetId);
531
+ const reset = await this.config.store.resetOverride(assetId);
532
+ // "Restore to the built-in version" has to put the roles back on the
533
+ // shipped copy: leaving them on a copy whose content merely equals the
534
+ // shipped one would keep the default bound to the user's own asset.
535
+ if (reset.officialSkillId !== undefined) {
536
+ await this.config.manager.replaceAssetBindings(assetId, `builtin:${reset.officialSkillId}`);
537
+ }
462
538
  }
463
539
  catch (error) {
464
540
  return { ok: false, reason: 'reset-refused', detail: String(error) };
@@ -556,6 +632,10 @@ let TeamSkillService = (() => {
556
632
  await this.config.manager.restoreBuiltinBindings(teamIds);
557
633
  }
558
634
  catch (error) {
635
+ // A swallowed error here reads on the page as "nothing happened", which is
636
+ // indistinguishable from "there was nothing to restore". Log it, and keep
637
+ // returning the issue so the page can name the failure too.
638
+ this.ctx.logger.warn('agent-team-presets: restoring built-in Team Skill bindings failed: %s', String(error));
559
639
  return { ...await this.library(), issue: String(error) };
560
640
  }
561
641
  this.config.resync();
@@ -1,5 +1,7 @@
1
+ import { buildSkillPackage } from './import.ts';
1
2
  import type { ImportedFile, SkillPackage } from './import.ts';
2
3
  import type { TeamSkillAsset, TeamSkillDependencies, TeamSkillFile, TeamSkillOrigin } from '../types.ts';
4
+ export declare const SKILL_IMPORT_FOLDER = "inbox";
3
5
  export interface OfficialSkillEntry {
4
6
  readonly skillId: string;
5
7
  readonly directory: string;
@@ -43,6 +45,17 @@ export declare class TeamSkillStore {
43
45
  private migrateLayout;
44
46
  list(): readonly TeamSkillAsset[];
45
47
  get(assetId: string): TeamSkillAsset | undefined;
48
+ /**
49
+ * Resolve one skill by its name rather than by asset identity.
50
+ *
51
+ * Several assets may legitimately share a name: the shipped copy, a local
52
+ * override of it, and a skill the user imported under the same name. The
53
+ * shipped copy wins, because a name denotes the skill the plugin ships — a
54
+ * user's own copy must never shadow it for a caller that only said the name.
55
+ * Callers that know which copy they mean pass the asset id instead.
56
+ * @param skillId - kebab-case skill name.
57
+ * @returns the shipped copy when it exists, else the best local one.
58
+ */
46
59
  bySkillId(skillId: string): TeamSkillAsset | undefined;
47
60
  /** Commit all nested store mutations once; failures restore memory and version folders. */
48
61
  transaction<T>(operation: () => Promise<T>): Promise<T>;
@@ -53,8 +66,13 @@ export declare class TeamSkillStore {
53
66
  readonly officialSkillId?: string;
54
67
  readonly baseVersion?: string;
55
68
  readonly dependencies?: TeamSkillDependencies;
69
+ readonly sourceFolder?: string;
56
70
  }): Promise<TeamSkillAsset>;
57
- writeFile(assetId: string, path: string, content: string): Promise<TeamSkillAsset>;
71
+ sourcePath(folder: string): string;
72
+ /** Publish a scanned package under its existing identity, or register it for the first time. */
73
+ publishSource(folder: string, package_: SkillPackage): Promise<'imported' | 'updated' | 'existing'>;
74
+ writeFile(assetId: string, path: string, content: string, expectedVersion?: string): Promise<TeamSkillAsset>;
75
+ private writeSourceFile;
58
76
  /** Change dependency metadata by publishing a new immutable asset version. */
59
77
  updateDependencies(assetId: string, dependencies: TeamSkillDependencies): Promise<TeamSkillAsset>;
60
78
  readBytes(assetId: string, path: string, version?: string): Promise<Uint8Array>;
@@ -63,7 +81,11 @@ export declare class TeamSkillStore {
63
81
  ensureOfficial(entries: readonly OfficialSkillEntry[], warnings?: string[]): Promise<readonly string[]>;
64
82
  private installFiles;
65
83
  private manifest;
66
- createOverride(skillId: string, id: string): Promise<TeamSkillAsset>;
84
+ private freeCopyName;
85
+ /** Keep old binding identities when a previously same-named copy needs its own name. */
86
+ renameLegacyCopies(reserved: readonly string[]): Promise<void>;
87
+ private readPackage;
88
+ createOverride(skillId: string, id?: string, reserved?: readonly string[]): Promise<TeamSkillAsset>;
67
89
  resetOverride(assetId: string): Promise<TeamSkillAsset>;
68
90
  verify(assetId: string): Promise<boolean>;
69
91
  }
@@ -74,10 +96,9 @@ export declare function installFromDirectory(store: TeamSkillStore, source: stri
74
96
  readonly version: string;
75
97
  }): Promise<TeamSkillAsset>;
76
98
  /** What reading one untrusted folder produced: a legal package or the exact rule that refused it. */
77
- export type SkillFolderInspection = {
78
- readonly ok: true;
79
- readonly skill: SkillPackage;
80
- } | {
99
+ export type SkillFolderInspection = Extract<ReturnType<typeof buildSkillPackage>, {
100
+ ok: true;
101
+ }> | {
81
102
  readonly ok: false;
82
103
  readonly reason: string;
83
104
  readonly path?: string;