@anhlp/alp-core 0.0.0-beta.2 → 0.0.1-beta.10

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 (158) hide show
  1. package/dist/backup.js +106 -4
  2. package/dist/bridges.d.ts +26 -0
  3. package/dist/bridges.js +96 -0
  4. package/dist/gate-ledger.d.ts +30 -0
  5. package/dist/gate-ledger.js +99 -0
  6. package/dist/index.d.ts +1 -0
  7. package/dist/index.js +2 -0
  8. package/dist/library-edit.d.ts +57 -5
  9. package/dist/library-edit.js +216 -11
  10. package/dist/library.d.ts +14 -1
  11. package/dist/library.js +73 -5
  12. package/dist/migrations.js +1 -1
  13. package/dist/models.d.ts +74 -0
  14. package/dist/models.js +67 -1
  15. package/dist/packaged.d.ts +122 -0
  16. package/dist/packaged.js +125 -0
  17. package/dist/packs.d.ts +57 -0
  18. package/dist/packs.js +247 -0
  19. package/dist/permissions.d.ts +3 -2
  20. package/dist/permissions.js +6 -3
  21. package/dist/profiles.js +6 -6
  22. package/dist/providers.d.ts +4 -5
  23. package/dist/providers.js +26 -5
  24. package/dist/skill-validate.d.ts +85 -0
  25. package/dist/skill-validate.js +298 -0
  26. package/dist/task-rows.d.ts +5 -0
  27. package/dist/task-rows.js +1 -1
  28. package/dist/tasks.d.ts +23 -4
  29. package/dist/tasks.js +103 -9
  30. package/dist/types.d.ts +3 -0
  31. package/dist/upgrade.d.ts +10 -0
  32. package/dist/upgrade.js +112 -6
  33. package/dist/user-settings.d.ts +2 -0
  34. package/dist/user-settings.js +40 -1
  35. package/dist/user-worktree.d.ts +29 -0
  36. package/dist/user-worktree.js +242 -0
  37. package/dist/validation.d.ts +1 -0
  38. package/dist/validation.js +35 -13
  39. package/package.json +34 -2
  40. package/src/backup.js +106 -5
  41. package/src/bridges.js +113 -0
  42. package/src/gate-ledger.js +125 -0
  43. package/src/index.js +1 -0
  44. package/src/library-edit.js +227 -12
  45. package/src/library.js +96 -6
  46. package/src/migrations.js +1 -1
  47. package/src/models.js +87 -1
  48. package/src/packaged.js +207 -0
  49. package/src/packs.js +246 -0
  50. package/src/permissions.d.ts +3 -2
  51. package/src/permissions.js +13 -3
  52. package/src/profiles.js +7 -7
  53. package/src/providers.js +23 -7
  54. package/src/resolver.js +1 -1
  55. package/src/skill-validate.js +287 -0
  56. package/src/task-rows.js +1 -1
  57. package/src/tasks.d.ts +23 -4
  58. package/src/tasks.js +137 -10
  59. package/src/types.d.ts +3 -0
  60. package/src/upgrade.js +54 -6
  61. package/src/user-settings.d.ts +2 -0
  62. package/src/user-settings.js +51 -1
  63. package/src/user-worktree.js +259 -0
  64. package/src/validation.d.ts +1 -0
  65. package/src/validation.js +43 -14
  66. package/templates/ALP.md +52 -52
  67. package/templates/agents/lead/AGENT.md +77 -74
  68. package/templates/agents/main/AGENT.md +153 -141
  69. package/templates/agents/oracle/AGENT.md +38 -37
  70. package/templates/agents/peer/AGENT.md +56 -52
  71. package/templates/agents/reviewer/AGENT.md +63 -65
  72. package/templates/agents/supervisor/AGENT.md +63 -63
  73. package/templates/packs/architecture/agents/architect/AGENT.md +41 -0
  74. package/templates/packs/architecture/agents/architect/agent.json +5 -0
  75. package/templates/packs/architecture/agents/docs-maintainer/AGENT.md +33 -0
  76. package/templates/packs/architecture/agents/docs-maintainer/agent.json +4 -0
  77. package/templates/packs/architecture/pack.json +7 -0
  78. package/templates/packs/architecture/teams/blueprint/HOUSE_RULES.md +12 -0
  79. package/templates/packs/architecture/teams/blueprint/team.json +19 -0
  80. package/templates/packs/backend/pack.json +6 -0
  81. package/templates/packs/backend/skills/backend-development/SKILL.md +102 -0
  82. package/templates/packs/backend/skills/backend-development/references/api-design.md +96 -0
  83. package/templates/packs/backend/skills/backend-development/references/authentication.md +78 -0
  84. package/templates/packs/backend/skills/backend-development/references/error-handling.md +86 -0
  85. package/templates/packs/backend/skills/backend-development/references/testing.md +81 -0
  86. package/templates/packs/backend/skills/databases/SKILL.md +103 -0
  87. package/templates/packs/backend/skills/databases/references/query-performance.md +87 -0
  88. package/templates/packs/backend/skills/databases/references/schema-and-migrations.md +87 -0
  89. package/templates/packs/design/pack.json +6 -0
  90. package/templates/packs/design/skills/ui-design/SKILL.md +86 -0
  91. package/templates/packs/design/skills/ui-design/references/design-tokens.md +67 -0
  92. package/templates/packs/design/skills/ui-design/references/interaction-states.md +73 -0
  93. package/templates/packs/design/skills/ui-design/references/layout-and-typography.md +71 -0
  94. package/templates/packs/design/skills/ui-design/references/ui-review.md +83 -0
  95. package/templates/packs/frontend/pack.json +6 -0
  96. package/templates/packs/frontend/skills/frontend-development/SKILL.md +105 -0
  97. package/templates/packs/frontend/skills/frontend-development/references/accessibility.md +86 -0
  98. package/templates/packs/frontend/skills/frontend-development/references/components-and-state.md +79 -0
  99. package/templates/packs/frontend/skills/frontend-development/references/data-fetching.md +86 -0
  100. package/templates/packs/frontend/skills/frontend-development/references/frameworks.md +77 -0
  101. package/templates/packs/frontend/skills/frontend-development/references/performance.md +78 -0
  102. package/templates/packs/integration/pack.json +6 -0
  103. package/templates/packs/integration/skills/mcp-integration/SKILL.md +100 -0
  104. package/templates/packs/integration/skills/mcp-integration/references/server-implementation.md +95 -0
  105. package/templates/packs/integration/skills/mcp-integration/references/testing.md +78 -0
  106. package/templates/packs/integration/skills/mcp-integration/references/tool-design.md +97 -0
  107. package/templates/packs/operations/pack.json +6 -0
  108. package/templates/packs/operations/skills/devops/SKILL.md +85 -0
  109. package/templates/packs/operations/skills/devops/references/ci-cd.md +84 -0
  110. package/templates/packs/operations/skills/devops/references/containers.md +85 -0
  111. package/templates/packs/operations/skills/devops/references/deployment-and-rollback.md +85 -0
  112. package/templates/packs/operations/skills/devops/references/observability.md +86 -0
  113. package/templates/packs/quality/pack.json +6 -0
  114. package/templates/packs/quality/skills/web-testing/SKILL.md +102 -0
  115. package/templates/packs/quality/skills/web-testing/references/e2e.md +85 -0
  116. package/templates/packs/quality/skills/web-testing/references/performance-testing.md +85 -0
  117. package/templates/packs/quality/skills/web-testing/references/security-testing.md +78 -0
  118. package/templates/packs/quality/skills/web-testing/references/unit-and-component.md +78 -0
  119. package/templates/role-skills.json +4 -4
  120. package/templates/skills/architecture-docs/SKILL.md +81 -0
  121. package/templates/skills/architecture-docs/references/adr.md +62 -0
  122. package/templates/skills/architecture-docs/references/diagrams.md +60 -0
  123. package/templates/skills/architecture-docs/references/evidence-rules.md +49 -0
  124. package/templates/skills/bug-loop/SKILL.md +41 -40
  125. package/templates/skills/bug-loop/references/test-proof.md +21 -19
  126. package/templates/skills/compact/SKILL.md +34 -0
  127. package/templates/skills/curate/SKILL.md +36 -0
  128. package/templates/skills/feature-architecture/SKILL.md +90 -0
  129. package/templates/skills/feature-architecture/references/architecture-contract.md +95 -0
  130. package/templates/skills/feature-architecture/references/feature-design.md +69 -0
  131. package/templates/skills/feature-architecture/scripts/check-boundaries.mjs +270 -0
  132. package/templates/skills/goal-griller/SKILL.md +27 -27
  133. package/templates/skills/prompt-leverage/SKILL.md +29 -27
  134. package/templates/skills/prompt-leverage/references/brief-template.md +9 -9
  135. package/templates/skills/release-readiness/SKILL.md +83 -0
  136. package/templates/skills/release-readiness/references/checklist.md +40 -0
  137. package/templates/skills/release-readiness/references/verdict-template.md +53 -0
  138. package/templates/skills/safe-refactor/SKILL.md +84 -0
  139. package/templates/skills/safe-refactor/references/characterization-tests.md +57 -0
  140. package/templates/skills/safe-refactor/references/compatibility-checklist.md +56 -0
  141. package/templates/skills/security-review/SKILL.md +87 -0
  142. package/templates/skills/security-review/references/checklist.md +74 -0
  143. package/templates/skills/security-review/references/severity.md +61 -0
  144. package/templates/skills/sequence-execution-plan/SKILL.md +41 -38
  145. package/templates/skills/sequence-execution-plan/references/plan-template.md +5 -5
  146. package/templates/skills/skill-authoring/SKILL.md +84 -0
  147. package/templates/skills/skill-authoring/references/evaluation.md +45 -0
  148. package/templates/skills/skill-authoring/references/skill-anatomy.md +74 -0
  149. package/templates/skills/skill-authoring/references/trigger-design.md +52 -0
  150. package/templates/skills/smart-commits/SKILL.md +37 -36
  151. package/templates/skills/test-strategy/SKILL.md +83 -0
  152. package/templates/skills/test-strategy/references/contract-tests.md +46 -0
  153. package/templates/skills/test-strategy/references/risk-matrix.md +53 -0
  154. package/templates/skills/xia/SKILL.md +40 -38
  155. package/templates/teams/cafe/HOUSE_RULES.md +1 -1
  156. package/templates/teams/cafe/team.json +1 -1
  157. package/templates/teams/pho/HOUSE_RULES.md +1 -1
  158. package/templates/teams/pho/team.json +1 -1
@@ -1,5 +1,5 @@
1
1
  // packages/core/src/library-edit.js
2
- import { mkdir, rename, rm, stat, writeFile } from "node:fs/promises";
2
+ import { cp, lstat, mkdir, readdir, rename, rm, stat, writeFile } from "node:fs/promises";
3
3
  import { createHash, randomUUID } from "node:crypto";
4
4
  import path from "node:path";
5
5
  import { moveFile } from "./atomic.js";
@@ -9,6 +9,19 @@ import { agentSources, builtinText, jsonObject, libraryEntries, optionalText } f
9
9
  import { teamSources, validateTeam } from "./teams.js";
10
10
  import { normalizeMcp, validateAgentConfig, validateHook } from "./validation.js";
11
11
  import { validateProvider } from "./providers.js";
12
+ import { checkFrontmatter, skillReferences, specName, splitSkill } from "./skill-validate.js";
13
+ function withSkillName(body, name) {
14
+ const match = /^(\uFEFF?---(\r?\n))([\s\S]*?)(\r?\n---[ \t]*(?:\r?\n|$))/.exec(body);
15
+ if (!match) return body;
16
+ const lines = match[3].split(/\r?\n/);
17
+ const at = lines.findIndex((line) => /^name[ \t]*:/.test(line));
18
+ if (at >= 0) lines[at] = `name: ${name}`;
19
+ else lines.unshift(`name: ${name}`);
20
+ return match[1] + lines.join(match[2]) + match[4] + body.slice(match[0].length);
21
+ }
22
+ function skillTarget(body, name) {
23
+ if (splitSkill(body).frontmatter !== void 0 && !specName(name)) fail("INVALID_NAME", `'${name}' is not a skill name: use 1-64 lowercase letters, digits and single hyphens`);
24
+ }
12
25
  var EDIT_KINDS = ["agents", "skills", "mcp", "hooks", "teams", "providers"];
13
26
  var validName = (name) => typeof name === "string" && /^[\w.-]+$/.test(name) && name !== "." && name !== "..";
14
27
  var object = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
@@ -39,6 +52,42 @@ function base(scope, { root, library }, kind) {
39
52
  return fail("INVALID_SCOPE", `Scope must be library or project, not '${scope}'`);
40
53
  }
41
54
  var revisionOf = (content) => content === void 0 ? null : createHash("sha256").update(JSON.stringify(content)).digest("hex").slice(0, 16);
55
+ function assertProjectDataContent(kind, content) {
56
+ const deny = () => fail("UNSAFE_LIBRARY_WRITE", "Project-data writes allow only instruction entries and non-executable agent configuration");
57
+ if (!object(content) || !["agents", "skills"].includes(kind)) deny();
58
+ const keys = kind === "skills" ? ["body"] : ["instructions", "config"];
59
+ if (Object.keys(content).some((key) => !keys.includes(key))) deny();
60
+ const text = kind === "skills" ? content.body : content.instructions;
61
+ if (typeof text !== "string" || !text.trim()) deny();
62
+ if (content.config !== void 0) {
63
+ const config = content.config;
64
+ if (!object(config)) deny();
65
+ const allowed = ["description", "model", "thinking", "context", "autocompact"];
66
+ if (Object.keys(config).some((key) => !allowed.includes(key))) deny();
67
+ for (const key of ["description", "thinking"]) if (config[key] !== void 0 && typeof config[key] !== "string") deny();
68
+ if (config.model !== void 0 && (typeof config.model !== "string" || !/^(codex|claude):[^\s/\\:]{1,240}$/.test(config.model))) deny();
69
+ for (const key of ["context", "autocompact"]) if (config[key] !== void 0 && !(typeof config[key] === "string" || typeof config[key] === "number" && Number.isFinite(config[key]))) deny();
70
+ }
71
+ }
72
+ async function projectDataEntry(kind, name, { scope, root, library, templates }) {
73
+ if (scope !== "project" || !root || !["agents", "skills"].includes(kind)) fail("UNSAFE_LIBRARY_WRITE", "Project-data writes require project scope and agents or skills");
74
+ nameOf(name);
75
+ const directory = base(scope, { root, library }, kind);
76
+ await safeEntryPaths(directory, kind, name);
77
+ const found = await layers(kind, name, { root, library, templates });
78
+ if (found.library !== void 0 || found.builtin !== void 0) fail("UNSAFE_LIBRARY_WRITE", "Project-data writes cannot shadow or reveal a library or built-in entry");
79
+ if (found.project !== void 0) assertProjectDataContent(kind, found.project);
80
+ const owned = path.join(directory, kind, name);
81
+ const files = await readdir(owned).catch((error) => {
82
+ if (error.code === "ENOENT") return [];
83
+ throw error;
84
+ });
85
+ const allowed = new Set(FILES[kind](name).map(([file]) => path.basename(file)));
86
+ for (const file of files) {
87
+ const info = await lstat(path.join(owned, file));
88
+ if (!allowed.has(file) || !info.isFile() || info.isSymbolicLink() || info.nlink !== 1) fail("UNSAFE_LIBRARY_WRITE", "Project-data entries cannot contain sidecars, links or executable assets");
89
+ }
90
+ }
42
91
  async function safeEntryPaths(directory, kind, name) {
43
92
  for (const [file] of FILES[kind](name)) {
44
93
  await assertNoSymlinks(directory, path.join(kind, file));
@@ -116,7 +165,7 @@ async function getEntry(kind, name, { root, library, templates, scope } = {}) {
116
165
  async function readGiven(library) {
117
166
  const file = path.join(library, "role-skills.json");
118
167
  const text = await optionalText(file);
119
- if (text === void 0) return { file, roles: {} };
168
+ if (text === void 0) return { file, roles: /* @__PURE__ */ Object.create(null) };
120
169
  let roles;
121
170
  try {
122
171
  roles = JSON.parse(text);
@@ -124,7 +173,7 @@ async function readGiven(library) {
124
173
  throw new AlpError("INVALID_LIBRARY", `${file}: ${cause.message}`, { cause });
125
174
  }
126
175
  if (!object(roles)) fail("INVALID_LIBRARY", `${file}: expected an object of agent names to skill lists`);
127
- return { file, roles };
176
+ return { file, roles: Object.assign(/* @__PURE__ */ Object.create(null), roles) };
128
177
  }
129
178
  async function givenSkills(library, agent) {
130
179
  const { roles } = await readGiven(library);
@@ -142,6 +191,99 @@ async function setGivenSkills(agent, skills, { library } = {}) {
142
191
  await writeAtomic(file, JSON.stringify(roles, null, 2) + "\n");
143
192
  return { skills: unique };
144
193
  }
194
+ var RETIRED_SKILLS = "retired-skills";
195
+ var RETIRED_METADATA = "retired.json";
196
+ var RETIRED_FOLDER = /^(.+)-(\d{4}-\d\d-\d\dT\d\d-\d\d-\d\d-\d{3}Z)$/;
197
+ async function retiredMetadata(directory) {
198
+ const text = await optionalText(path.join(directory, RETIRED_METADATA));
199
+ if (text === void 0) return void 0;
200
+ let data;
201
+ try {
202
+ data = JSON.parse(text);
203
+ } catch (cause) {
204
+ throw new AlpError("INVALID_LIBRARY", `${path.join(directory, RETIRED_METADATA)}: ${cause.message}`, { cause });
205
+ }
206
+ if (!object(data) || !Array.isArray(data.roles) || !data.roles.every(validName)) fail("INVALID_LIBRARY", `${path.join(directory, RETIRED_METADATA)}: expected { name, roles: [...] }`);
207
+ return data;
208
+ }
209
+ async function listRetiredSkills({ library } = {}) {
210
+ if (!library) fail("INVALID_SCOPE", "No library: ALP_HOME is not set");
211
+ const root = path.join(library, RETIRED_SKILLS);
212
+ const entries = await readdir(root, { withFileTypes: true }).catch((error) => {
213
+ if (error.code === "ENOENT") return [];
214
+ throw error;
215
+ });
216
+ const rows = [];
217
+ for (const entry of entries) {
218
+ const match = entry.isDirectory() && RETIRED_FOLDER.exec(entry.name);
219
+ if (!match) continue;
220
+ const directory = path.join(root, entry.name);
221
+ let meta, invalid;
222
+ try {
223
+ meta = await retiredMetadata(directory);
224
+ } catch (error) {
225
+ invalid = error.message;
226
+ }
227
+ const stamp = match[2].replace(/T(\d\d)-(\d\d)-(\d\d)-(\d{3})Z$/, "T$1:$2:$3.$4Z");
228
+ rows.push({ name: match[1], directory, retiredAt: typeof meta?.retiredAt === "string" ? meta.retiredAt : stamp, roles: meta ? meta.roles : null, agent: typeof meta?.agent === "string" ? meta.agent : null, ...invalid ? { invalid } : {} });
229
+ }
230
+ return rows.sort((a, b) => b.retiredAt.localeCompare(a.retiredAt) || b.directory.localeCompare(a.directory));
231
+ }
232
+ async function restoreSkill(name, { library, from, roles } = {}) {
233
+ nameOf(name);
234
+ if (!library) fail("INVALID_SCOPE", "No library: ALP_HOME is not set");
235
+ if (roles !== void 0 && (!Array.isArray(roles) || !roles.every(validName))) fail("INVALID_ENTRY", "Roles must be a list of agent names");
236
+ let source;
237
+ if (from !== void 0) {
238
+ source = path.resolve(from);
239
+ const info = await lstat(source).catch(() => void 0);
240
+ if (info?.isSymbolicLink()) fail("INVALID_ENTRY", `${source} is a symbolic link; pass the directory itself`);
241
+ if (!info?.isDirectory()) fail("NOT_FOUND", `${source} is not a directory`);
242
+ } else {
243
+ const found = (await listRetiredSkills({ library })).find((row) => row.name === name);
244
+ if (!found) fail("NOT_FOUND", `No retired skill '${name}' in ${path.join(library, RETIRED_SKILLS)}`);
245
+ source = found.directory;
246
+ }
247
+ if (!await exists(path.join(source, "SKILL.md"))) fail("NOT_FOUND", `${source} has no SKILL.md`);
248
+ const target = path.join(library, "skills", name);
249
+ if (await lstat(target).then(() => true, () => false)) fail("ALREADY_EXISTS", `The library already has a skill '${name}' (${target}); nothing was restored`);
250
+ const metaFile = path.join(source, RETIRED_METADATA);
251
+ const metaText = await optionalText(metaFile);
252
+ let meta;
253
+ try {
254
+ meta = await retiredMetadata(source);
255
+ } catch (error) {
256
+ if (error?.code !== "INVALID_LIBRARY" || roles === void 0) throw error;
257
+ }
258
+ if (meta && meta.name !== void 0 && meta.name !== name) fail("INVALID_ENTRY", `${metaFile} is for the skill '${meta.name}', not '${name}'`);
259
+ const given = roles ?? meta?.roles;
260
+ if (!given) fail("ROLES_REQUIRED", `${source} does not record the roles that had '${name}'; pass --roles a,b or --no-roles`);
261
+ const unique = [...new Set(given)];
262
+ const { file: rolesFile, roles: current } = await readGiven(library);
263
+ const before = await optionalText(rolesFile);
264
+ await mkdir(path.dirname(target), { recursive: true });
265
+ await moveFile(source, target);
266
+ try {
267
+ if (metaText !== void 0) await rm(path.join(target, RETIRED_METADATA), { force: true });
268
+ if (unique.length) {
269
+ for (const role of unique) {
270
+ const list = Array.isArray(current[role]) ? current[role] : [];
271
+ if (!list.includes(name)) list.push(name);
272
+ current[role] = list;
273
+ }
274
+ await writeAtomic(rolesFile, JSON.stringify(current, null, 2) + "\n");
275
+ }
276
+ } catch (error) {
277
+ if (before !== void 0) await writeAtomic(rolesFile, before).catch(() => {
278
+ });
279
+ if (metaText !== void 0) await writeFile(path.join(target, RETIRED_METADATA), metaText).catch(() => {
280
+ });
281
+ await moveFile(target, source).catch(() => {
282
+ });
283
+ throw error;
284
+ }
285
+ return { name, restored: target, from: source, roles: unique };
286
+ }
145
287
  async function listEntries(kind, { root, library, templates } = {}) {
146
288
  kindOf(kind);
147
289
  if (kind !== "teams") return libraryEntries(kind, root, { library, templates });
@@ -236,9 +378,20 @@ async function writeAtomic(file, text) {
236
378
  await moveFile(temporary, file);
237
379
  }
238
380
  var exists = (target) => stat(target).then(() => true, () => false);
239
- async function saveEntry(kind, name, content, { scope, root, library, templates, revision } = {}) {
381
+ async function saveEntry(kind, name, content, { scope, root, library, templates, revision, policy, strict = false } = {}) {
240
382
  kindOf(kind);
241
383
  nameOf(name);
384
+ const warnings = [];
385
+ if (strict && kind === "skills" && revision === null && typeof content?.body === "string") {
386
+ const errors = checkFrontmatter(splitSkill(content.body).frontmatter, name, { strict: true }).findings.filter((finding) => finding.level === "error");
387
+ if (errors.length) fail("INVALID_ENTRY", `skills '${name}' does not meet the skill format: ${errors.map((finding) => finding.message).join("; ")}`);
388
+ const links = skillReferences(splitSkill(content.body).body);
389
+ if (links.length) warnings.push(`SKILL.md points to ${links.join(", ")}: add ${links.length > 1 ? "those files" : "that file"} beside it, in the skill's directory`);
390
+ }
391
+ if (policy === "project-data") {
392
+ assertProjectDataContent(kind, content);
393
+ await projectDataEntry(kind, name, { scope, root, library, templates });
394
+ }
242
395
  const directory = base(scope, { root, library }, kind);
243
396
  await safeEntryPaths(directory, kind, name);
244
397
  await check(kind, name, content, { scope, root, library, templates });
@@ -258,11 +411,12 @@ async function saveEntry(kind, name, content, { scope, root, library, templates,
258
411
  await writeAtomic(target, type === "json" ? JSON.stringify(value, null, 2) + "\n" : value.endsWith("\n") ? value : `${value}
259
412
  `);
260
413
  }
261
- return { revision: revisionOf(await readLayer(kind, name, directory)) };
414
+ return { revision: revisionOf(await readLayer(kind, name, directory)), ...warnings.length ? { warnings } : {} };
262
415
  }
263
- async function deleteEntry(kind, name, { scope, root, library, templates, revision } = {}) {
416
+ async function deleteEntry(kind, name, { scope, root, library, templates, revision, policy } = {}) {
264
417
  kindOf(kind);
265
418
  nameOf(name);
419
+ if (policy === "project-data") await projectDataEntry(kind, name, { scope, root, library, templates });
266
420
  const directory = base(scope, { root, library }, kind);
267
421
  const current = await readLayer(kind, name, directory);
268
422
  if (current === void 0) fail("NOT_FOUND", `No ${kind} entry '${name}' in the ${scope}`);
@@ -278,14 +432,57 @@ async function deleteEntry(kind, name, { scope, root, library, templates, revisi
278
432
  const now = scope === "project" && found.library !== void 0 ? "library" : "builtin";
279
433
  return { removed: true, ...fallback !== void 0 ? { now } : {} };
280
434
  }
281
- async function duplicateEntry(kind, from, to, { scope, root, library, templates } = {}) {
282
- const { content } = await getEntry(kind, from, { root, library, templates });
283
- return saveEntry(kind, to, structuredClone(content), { scope, root, library, templates, revision: null });
435
+ async function duplicateEntry(kind, from, to, { scope, root, library, templates, policy } = {}) {
436
+ kindOf(kind);
437
+ nameOf(from);
438
+ nameOf(to);
439
+ if (policy === "project-data") {
440
+ await projectDataEntry(kind, from, { scope, root, library, templates });
441
+ await projectDataEntry(kind, to, { scope, root, library, templates });
442
+ }
443
+ const entry = await getEntry(kind, from, { root, library, templates });
444
+ if (kind === "skills") {
445
+ skillTarget(entry.content.body, to);
446
+ entry.content.body = withSkillName(entry.content.body, to);
447
+ }
448
+ const resources = kind === "skills" && policy !== "project-data" ? await skillResources(entry.source === "project" ? path.join(path.resolve(root), ".alp", "skills", from) : path.join(library, "skills", from)) : [];
449
+ const saved = await saveEntry(kind, to, structuredClone(entry.content), { scope, root, library, templates, revision: null, policy });
450
+ if (resources.length) {
451
+ const target = path.join(base(scope, { root, library }, kind), kind, to);
452
+ try {
453
+ for (const [source, relative] of resources) await cp(source, path.join(target, relative), { recursive: true, errorOnExist: true, force: false });
454
+ } catch (error) {
455
+ await rm(target, { recursive: true, force: true });
456
+ throw error;
457
+ }
458
+ }
459
+ return saved;
460
+ }
461
+ async function skillResources(directory) {
462
+ const found = [];
463
+ const walk = async (relative) => {
464
+ for (const item of await readdir(path.join(directory, relative), { withFileTypes: true }).catch((error) => {
465
+ if (error.code === "ENOENT") return [];
466
+ throw error;
467
+ })) {
468
+ const rel = path.join(relative, item.name);
469
+ if (item.name === ".git" || item.name === "node_modules") continue;
470
+ if (item.isSymbolicLink()) fail("UNSAFE_LIBRARY_WRITE", `${path.join(directory, rel)} is a symbolic link; copy the skill by hand`);
471
+ if (item.isDirectory()) await walk(rel);
472
+ else if (item.isFile() && rel !== "SKILL.md") found.push([path.join(directory, rel), rel]);
473
+ }
474
+ };
475
+ await walk("");
476
+ return found;
284
477
  }
285
- async function renameEntry(kind, from, to, { scope, root, library, templates } = {}) {
478
+ async function renameEntry(kind, from, to, { scope, root, library, templates, policy } = {}) {
286
479
  kindOf(kind);
287
480
  nameOf(from);
288
481
  nameOf(to);
482
+ if (policy === "project-data") {
483
+ await projectDataEntry(kind, from, { scope, root, library, templates });
484
+ await projectDataEntry(kind, to, { scope, root, library, templates });
485
+ }
289
486
  const directory = base(scope, { root, library }, kind);
290
487
  const content = await readLayer(kind, from, directory);
291
488
  if (content === void 0) fail("NOT_FOUND", `No ${kind} entry '${from}' in the ${scope}`);
@@ -293,9 +490,11 @@ async function renameEntry(kind, from, to, { scope, root, library, templates } =
293
490
  const users = await usersOf(kind, from, { root, library, templates });
294
491
  if (users.length) fail("IN_USE", `${kind} '${from}' is used by ${users.join(", ")}; change them first`);
295
492
  await check(kind, to, content, { scope, root, library, templates });
493
+ if (kind === "skills") skillTarget(content.body, to);
296
494
  if (ownDirectory(kind)) {
297
495
  if (await exists(path.join(directory, kind, to))) fail("REVISION_CONFLICT", `${path.join(directory, kind, to)} already exists`);
298
496
  await rename(path.join(directory, kind, from), path.join(directory, kind, to));
497
+ if (kind === "skills" && withSkillName(content.body, to) !== content.body) await writeAtomic(path.join(directory, kind, to, "SKILL.md"), withSkillName(content.body, to));
299
498
  } else {
300
499
  await rename(path.join(directory, kind, `${from}.json`), path.join(directory, kind, `${to}.json`));
301
500
  }
@@ -303,13 +502,19 @@ async function renameEntry(kind, from, to, { scope, root, library, templates } =
303
502
  }
304
503
  export {
305
504
  EDIT_KINDS,
505
+ RETIRED_METADATA,
506
+ RETIRED_SKILLS,
507
+ assertProjectDataContent,
306
508
  deleteEntry,
307
509
  duplicateEntry,
308
510
  getEntry,
309
511
  givenSkills,
310
512
  listEntries,
513
+ listRetiredSkills,
311
514
  renameEntry,
515
+ restoreSkill,
312
516
  saveEntry,
313
517
  setGivenSkills,
314
- usersOf
518
+ usersOf,
519
+ withSkillName
315
520
  };
package/dist/library.d.ts CHANGED
@@ -9,15 +9,20 @@ export function alpHome(env?: NodeJS.ProcessEnv): string;
9
9
  /**
10
10
  * Seeds or updates the library in `home`. A file is written when ALP never
11
11
  * shipped it before, and replaced only while it still holds what ALP last wrote.
12
+ * With `offerRoleSkills` (alp upgrade, alp update-template), an edited role-skills.json
13
+ * is also offered the built-in role skills it never was (offerRoleSkills above).
12
14
  * @param {string} home
13
- * @param {{ templateRoot?: URL, templates?: Record<string, string> }} [options]
15
+ * @param {{ templateRoot?: URL, templates?: Record<string, string>, offerRoleSkills?: boolean }} [options]
16
+ * @returns {Promise<{ created: string[], updated: string[], offered?: string[] }>} offered only with offerRoleSkills
14
17
  */
15
18
  export function seedLibrary(home: string, options?: {
16
19
  templateRoot?: URL;
17
20
  templates?: Record<string, string>;
21
+ offerRoleSkills?: boolean;
18
22
  }): Promise<{
19
23
  created: string[];
20
24
  updated: string[];
25
+ offered?: string[];
21
26
  }>;
22
27
  /** Seeds a library once per process; sessions call it on every open. */
23
28
  export function ensureLibrary(home: any, options?: {}): any;
@@ -26,3 +31,11 @@ export function librarySkills(home: any, agent: any): Promise<{
26
31
  name: any;
27
32
  path: string;
28
33
  }[]>;
34
+ /**
35
+ * Every role-skills.json ALP shipped, by sha (CRLF-normalized), with what it gave each role. A
36
+ * library's manifest names the one ALP last wrote, so the built-in skills its user has already been
37
+ * offered are known for a library from before `roleSkillsOffered` was recorded (t-de1a). Add each
38
+ * new shipped version here (packages/core/tests/role-skills-offer.test.js checks the current one is).
39
+ * @type {Readonly<Record<string, Record<string, string[]>>>}
40
+ */
41
+ export const SHIPPED_ROLE_SKILLS: Readonly<Record<string, Record<string, string[]>>>;
package/dist/library.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // packages/core/src/library.js
2
2
  import { shippedTemplateRoot } from "./template-path.js";
3
- import { mkdir, readFile, readdir, writeFile } from "node:fs/promises";
3
+ import { chmod, mkdir, readFile, readdir, writeFile } from "node:fs/promises";
4
4
  import { moveFile } from "./atomic.js";
5
5
  import { createHash, randomUUID } from "node:crypto";
6
6
  import os from "node:os";
@@ -33,6 +33,64 @@ async function shippedFiles({ templateRoot, templates }) {
33
33
  await walk("providers");
34
34
  return files;
35
35
  }
36
+ var SHIPPED_ROLE_SKILLS = Object.freeze({
37
+ // 0086846 (2026-10-07)
38
+ "7132b9ef1f10db55caea23dbe705a0ab06c83c86f51f074e663d12043a79327a": { main: ["goal-griller", "xia", "sequence-execution-plan", "prompt-leverage", "bug-loop", "smart-commits"], lead: ["xia", "sequence-execution-plan", "prompt-leverage", "bug-loop", "smart-commits"], peer: ["xia", "bug-loop", "smart-commits"] },
39
+ // 9ccd54c (2026-10-08): oracle and reviewer, with none
40
+ "c03f7bcecd61e26e70ef05b268aa7881a75f9e9c45ae5486ae9659cefd6bb449": { main: ["goal-griller", "xia", "sequence-execution-plan", "prompt-leverage", "bug-loop", "smart-commits"], lead: ["xia", "sequence-execution-plan", "prompt-leverage", "bug-loop", "smart-commits"], peer: ["xia", "bug-loop", "smart-commits"] },
41
+ // 61181b5 (2026-10-09): supervisor, with none
42
+ "8c5664042d4a4ecd3ded61240d8febbffa6e8965a88af0e9ba0420ad2f2ce8fe": { main: ["goal-griller", "xia", "sequence-execution-plan", "prompt-leverage", "bug-loop", "smart-commits"], lead: ["xia", "sequence-execution-plan", "prompt-leverage", "bug-loop", "smart-commits"], peer: ["xia", "bug-loop", "smart-commits"] },
43
+ // 9180aa1 (2026-10-29): compact for main
44
+ "b12b52102c358119cf834e5f3be54e6a69aa4c9f388fe889dffbb529755292dc": { main: ["goal-griller", "xia", "sequence-execution-plan", "prompt-leverage", "bug-loop", "smart-commits", "compact"], lead: ["xia", "sequence-execution-plan", "prompt-leverage", "bug-loop", "smart-commits"], peer: ["xia", "bug-loop", "smart-commits"] },
45
+ // f4d7986 (2026-10-29): curate for main
46
+ "a84b035d0058cbfcda7e32dc1706b9e83e67764eed24e2e121bdfcd60f924e46": { main: ["goal-griller", "xia", "sequence-execution-plan", "prompt-leverage", "bug-loop", "smart-commits", "compact", "curate"], lead: ["xia", "sequence-execution-plan", "prompt-leverage", "bug-loop", "smart-commits"], peer: ["xia", "bug-loop", "smart-commits"] },
47
+ // Skill system v2 (2026-11-05): engineering core skills; reviewer gets its first two
48
+ "e60be7eec8d9b5180866c9b5a2c14cf0d95a9f1331ed771e93791f7b524af9b1": { main: ["goal-griller", "xia", "sequence-execution-plan", "prompt-leverage", "bug-loop", "smart-commits", "compact", "curate", "skill-authoring", "architecture-docs", "feature-architecture", "test-strategy", "safe-refactor", "security-review", "release-readiness"], lead: ["xia", "sequence-execution-plan", "prompt-leverage", "bug-loop", "smart-commits", "architecture-docs", "feature-architecture", "test-strategy", "safe-refactor", "security-review", "release-readiness"], peer: ["xia", "bug-loop", "smart-commits", "feature-architecture", "test-strategy", "safe-refactor"], reviewer: ["security-review", "release-readiness"] }
49
+ });
50
+ var rolePairs = (roles) => roles && typeof roles === "object" && !Array.isArray(roles) ? Object.entries(roles).flatMap(([role, names]) => Array.isArray(names) ? names.filter(skillName).map((name) => `${role}/${name}`) : []) : [];
51
+ async function offerRoleSkills(home, manifest, shippedText, seeded) {
52
+ const name = "role-skills.json";
53
+ const shipped = rolePairs(JSON.parse(shippedText));
54
+ const baseline = Array.isArray(manifest.roleSkillsOffered) ? manifest.roleSkillsOffered : seeded !== void 0 && Object.hasOwn(SHIPPED_ROLE_SKILLS, seeded) ? rolePairs(SHIPPED_ROLE_SKILLS[seeded]) : shipped;
55
+ const offered = new Set(baseline.filter((pair) => typeof pair === "string"));
56
+ const fresh = shipped.filter((pair) => !offered.has(pair));
57
+ const record = () => {
58
+ manifest.roleSkillsOffered = [.../* @__PURE__ */ new Set([...offered, ...shipped])].sort();
59
+ };
60
+ if (!fresh.length) {
61
+ const before = JSON.stringify(manifest.roleSkillsOffered);
62
+ record();
63
+ return { added: [], changed: before !== JSON.stringify(manifest.roleSkillsOffered) };
64
+ }
65
+ const target = path.join(home, name);
66
+ const text = await optional(target);
67
+ if (text === void 0) {
68
+ record();
69
+ return { added: [], changed: true };
70
+ }
71
+ let roles;
72
+ try {
73
+ roles = JSON.parse(text);
74
+ } catch {
75
+ return { added: [], changed: false };
76
+ }
77
+ if (!roles || typeof roles !== "object" || Array.isArray(roles)) return { added: [], changed: false };
78
+ const added = [];
79
+ for (const pair of fresh) {
80
+ const [role, skill] = pair.split("/");
81
+ if (!Array.isArray(roles[role]) || roles[role].includes(skill)) continue;
82
+ roles[role].push(skill);
83
+ added.push(pair);
84
+ }
85
+ if (added.length) {
86
+ const next = JSON.stringify(roles, null, 2) + "\n";
87
+ const temporary = `${target}.${randomUUID().slice(0, 8)}.tmp`;
88
+ await writeFile(temporary, next);
89
+ await moveFile(temporary, target);
90
+ }
91
+ record();
92
+ return { added, changed: true };
93
+ }
36
94
  async function seedLibrary(home, options = {}) {
37
95
  const shipped = await shippedFiles(options);
38
96
  await mkdir(home, { recursive: true, mode: 448 });
@@ -41,6 +99,7 @@ async function seedLibrary(home, options = {}) {
41
99
  const manifest = manifestText ? JSON.parse(manifestText) : { files: {} };
42
100
  const created = [];
43
101
  const updated = [];
102
+ const seededRoles = manifest.files["role-skills.json"];
44
103
  for (const [name, content] of Object.entries(shipped).sort(([a], [b]) => a.localeCompare(b))) {
45
104
  const target = path.join(home, ...name.split("/"));
46
105
  const current = await optional(target);
@@ -48,24 +107,32 @@ async function seedLibrary(home, options = {}) {
48
107
  if (seeded === void 0) {
49
108
  if (current !== void 0) continue;
50
109
  await mkdir(path.dirname(target), { recursive: true });
51
- await writeFile(target, content, { flag: "wx" }).catch((error) => {
110
+ const wrote = await writeFile(target, content, { flag: "wx" }).then(() => true, (error) => {
52
111
  if (error.code !== "EEXIST") throw error;
112
+ return false;
53
113
  });
114
+ if (wrote) await keepExecutable(name, target, content);
54
115
  manifest.files[name] = sha(content);
55
116
  created.push(name);
56
117
  } else if (current !== void 0 && sha(current) === seeded && seeded !== sha(content)) {
57
118
  await writeFile(target, content);
119
+ await keepExecutable(name, target, content);
58
120
  manifest.files[name] = sha(content);
59
121
  updated.push(name);
60
122
  }
61
123
  }
62
- if (created.length || updated.length || manifestText === void 0) {
124
+ const offer = options.offerRoleSkills && shipped["role-skills.json"] !== void 0 ? await offerRoleSkills(home, manifest, shipped["role-skills.json"], seededRoles) : void 0;
125
+ if (created.length || updated.length || offer?.changed || manifestText === void 0) {
63
126
  await mkdir(home, { recursive: true });
64
127
  const temporary = `${manifestPath}.${randomUUID().slice(0, 8)}.tmp`;
65
128
  await writeFile(temporary, JSON.stringify(manifest, null, 2) + "\n");
66
129
  await moveFile(temporary, manifestPath);
67
130
  }
68
- return { created, updated };
131
+ return { created, updated, ...options.offerRoleSkills ? { offered: offer?.added ?? [] } : {} };
132
+ }
133
+ async function keepExecutable(name, target, content) {
134
+ if (process.platform === "win32" || !/^skills\/[^/]+\/scripts\//.test(name) || !content.startsWith("#!")) return;
135
+ await chmod(target, 493);
69
136
  }
70
137
  var seeding = /* @__PURE__ */ new Map();
71
138
  function ensureLibrary(home, options = {}) {
@@ -90,7 +157,7 @@ async function librarySkills(home, agent) {
90
157
  } catch (cause) {
91
158
  throw new AlpError("INVALID_LIBRARY", `${file}: ${cause.message}`, { cause });
92
159
  }
93
- if (!roles || typeof roles !== "object" || Array.isArray(roles)) throw new AlpError("INVALID_LIBRARY", `${file}: expected an object of role names to skill lists`);
160
+ if (!roles || typeof roles !== "object" || Array.isArray(roles)) throw new AlpError("INVALID_LIBRARY", `${file}: expected an object of agent names to skill lists`);
94
161
  const names = roles[agent] ?? [];
95
162
  if (!Array.isArray(names) || !names.every(skillName)) throw new AlpError("INVALID_LIBRARY", `${file}: ${agent} must list skill directory names`);
96
163
  const skills = [];
@@ -101,6 +168,7 @@ async function librarySkills(home, agent) {
101
168
  return skills;
102
169
  }
103
170
  export {
171
+ SHIPPED_ROLE_SKILLS,
104
172
  alpHome,
105
173
  ensureLibrary,
106
174
  librarySkills,
@@ -78,7 +78,7 @@ async function migrateState(home, { by = "alp", migrations = MIGRATIONS, target
78
78
  throw new AlpError("STATE_MIGRATION_ROLLBACK_FAILED", `state migration ${step.name} failed (${error?.message ?? error}) and putting the state back from ${backup} failed too (${rollback?.message ?? rollback}); the next start tries the migration again. See docs/alp/data-recovery.md`, { cause: error });
79
79
  }
80
80
  await rm(migrationFile(home), { force: true });
81
- throw new AlpError("STATE_MIGRATION_FAILED", `state migration ${step.name} (schema ${step.from} \u2192 ${step.to}) failed: ${error?.message ?? error}; the state was put back from ${backup} and is unchanged. See docs/alp/data-recovery.md`, { cause: error });
81
+ throw new AlpError("STATE_MIGRATION_FAILED", `state migration ${step.name} (schema ${step.from} \u2192 ${step.to}) failed: ${error?.message ?? error}; data was restored from ${backup} with workspace authority checks. See docs/alp/data-recovery.md`, { cause: error });
82
82
  }
83
83
  await writeStateSchema(home, step.to, by);
84
84
  await rm(migrationFile(home), { force: true });
package/dist/models.d.ts CHANGED
@@ -1,3 +1,59 @@
1
+ /**
2
+ * Live over static (t-e5ee): a runtime with a live list shows its live models first, in the provider's
3
+ * order, with the provider's label and description; a live model ALP knows keeps ALP's efforts (plus any
4
+ * new ones the provider adds) and ALP's default effort, a new one takes the provider's. Static rows the
5
+ * provider did not report stay as `fallback` (aliases, 1M variants). A runtime without a live list keeps
6
+ * its static rows. MODEL_POLICY applies last.
7
+ * @param {typeof MODELS} base
8
+ * @param {Partial<Record<string, Array<{ id: string, label?: string, description?: string, efforts?: string[], effort?: string }> | undefined>>} live
9
+ * @returns {Array<(typeof MODELS)[number] & { source?: 'live' | 'fallback' | 'static' }>}
10
+ */
11
+ export function mergeCatalog(base: typeof MODELS, live: Partial<Record<string, Array<{
12
+ id: string;
13
+ label?: string;
14
+ description?: string;
15
+ efforts?: string[];
16
+ effort?: string;
17
+ }> | undefined>>): Array<(typeof MODELS)[number] & {
18
+ source?: "live" | "fallback" | "static";
19
+ }>;
20
+ /**
21
+ * The rows effort checks consult in this process (t-086c): alpd's runtime installs its live catalog
22
+ * here as it changes, and alp setup the cached one it read. Nothing here reads the network; without
23
+ * rows, MODELS serve. @param {typeof MODELS | undefined} rows
24
+ */
25
+ export function useLiveModels(rows: typeof MODELS | undefined): void;
26
+ /**
27
+ * The row for a runtime-prefixed model id, its efforts kept to EFFORTS; undefined for a model no
28
+ * catalog lists (any effort in EFFORTS stays accepted for it). @param {string} id
29
+ */
30
+ export function knownModel(id: string): {
31
+ effort: string;
32
+ efforts: string[];
33
+ runtime: "codex" | "claude" | "antigravity";
34
+ id: string;
35
+ label: string;
36
+ description: string;
37
+ } | {
38
+ effort: undefined;
39
+ efforts: string[];
40
+ runtime: "codex" | "claude" | "antigravity";
41
+ id: string;
42
+ label: string;
43
+ description: string;
44
+ } | undefined;
45
+ /**
46
+ * The catalog as alpd last saw it, for readers outside alpd (alp setup, the Paseo plugin): static rows
47
+ * when there is no cache or it is unreadable. @param {string | undefined} home
48
+ */
49
+ export function catalogModels(home: string | undefined): {
50
+ runtime: "codex" | "claude" | "antigravity";
51
+ id: string;
52
+ label: string;
53
+ description: string;
54
+ efforts: string[];
55
+ effort?: string;
56
+ }[];
1
57
  /**
2
58
  * @type {Array<{ runtime: 'codex' | 'claude' | 'antigravity', id: string, label: string, description: string, efforts: string[], effort?: string }>}
3
59
  */
@@ -9,3 +65,21 @@ export const MODELS: Array<{
9
65
  efforts: string[];
10
66
  effort?: string;
11
67
  }>;
68
+ /** ALP policy applied over whatever a provider reports. */
69
+ export const MODEL_POLICY: {
70
+ 'codex:gpt-6-astra': {
71
+ efforts: string[];
72
+ effort: string;
73
+ };
74
+ };
75
+ /** Every effort ALP knows; no catalog widens a model beyond these. */
76
+ export const EFFORTS: string[];
77
+ export function knownModels(): {
78
+ runtime: "codex" | "claude" | "antigravity";
79
+ id: string;
80
+ label: string;
81
+ description: string;
82
+ efforts: string[];
83
+ effort?: string;
84
+ }[];
85
+ export function catalogCacheFile(home: string): string;
package/dist/models.js CHANGED
@@ -1,4 +1,6 @@
1
1
  // packages/core/src/models.js
2
+ import { readFileSync } from "node:fs";
3
+ import path from "node:path";
2
4
  var codexFull = ["low", "medium", "high", "xhigh", "max", "ultra"];
3
5
  var codexStandard = ["low", "medium", "high", "xhigh", "max"];
4
6
  var claudeFull = ["low", "medium", "high", "xhigh", "max", "ultracode"];
@@ -39,6 +41,70 @@ var MODELS = [
39
41
  ["antigravity", "claude-opus-4-6-thinking", "Claude Opus 4.6 Thinking", "Opus 4.6 with thinking via Antigravity.", [], void 0],
40
42
  ["antigravity", "gpt-oss-120b-medium", "GPT-OSS 120B (Medium)", "Open weights model via Antigravity.", [], void 0]
41
43
  ].map(([runtime, id, label, description, efforts, effort]) => ({ runtime, id, label, description, efforts, ...effort ? { effort } : {} }));
44
+ var MODEL_POLICY = {
45
+ // ALP runs GPT-6 Astra at low effort only.
46
+ "codex:gpt-6-astra": { efforts: ["low"], effort: "low" }
47
+ };
48
+ var CATALOG_RUNTIMES = ["codex", "claude", "antigravity"];
49
+ function mergeCatalog(base, live) {
50
+ const out = [];
51
+ for (const runtime of CATALOG_RUNTIMES) {
52
+ const known = base.filter((entry) => entry.runtime === runtime);
53
+ const listed = live?.[runtime];
54
+ const reported = (Array.isArray(listed) ? listed : []).filter((model) => typeof model?.id === "string" && model.id.trim());
55
+ if (!reported.length) {
56
+ out.push(...known);
57
+ continue;
58
+ }
59
+ const seen = /* @__PURE__ */ new Set();
60
+ for (const model of reported) {
61
+ if (seen.has(model.id)) continue;
62
+ seen.add(model.id);
63
+ const prior = known.find((entry) => entry.id === model.id);
64
+ const priorEfforts = prior?.efforts ?? [];
65
+ const efforts = [...priorEfforts, ...(Array.isArray(model.efforts) ? model.efforts : []).filter((effort2) => typeof effort2 === "string" && !priorEfforts.includes(effort2))];
66
+ const effort = prior?.effort ?? (typeof model.effort === "string" && efforts.includes(model.effort) ? model.effort : void 0);
67
+ const text = (value) => typeof value === "string" && value ? value : void 0;
68
+ out.push({ runtime, id: model.id, label: text(model.label) ?? prior?.label ?? model.id, description: text(model.description) ?? prior?.description ?? "", efforts, ...effort ? { effort } : {}, source: "live" });
69
+ }
70
+ for (const entry of known) if (!seen.has(entry.id)) out.push({ ...entry, source: "fallback" });
71
+ }
72
+ return out.map((entry) => {
73
+ const policy = MODEL_POLICY[`${entry.runtime}:${entry.id}`];
74
+ return policy ? { ...entry, ...policy } : entry;
75
+ });
76
+ }
77
+ var EFFORTS = ["none", "off", "low", "medium", "high", "xhigh", "max", "ultra", "ultracode"];
78
+ var liveRows;
79
+ function useLiveModels(rows) {
80
+ liveRows = Array.isArray(rows) && rows.length ? rows : void 0;
81
+ }
82
+ var knownModels = () => liveRows ?? MODELS;
83
+ function knownModel(id) {
84
+ const row = knownModels().find((model) => `${model.runtime}:${model.id}` === id);
85
+ if (!row) return void 0;
86
+ const efforts = (row.efforts ?? []).filter((effort) => EFFORTS.includes(effort));
87
+ return { ...row, efforts, ...row.effort && efforts.includes(row.effort) ? { effort: row.effort } : { effort: void 0 } };
88
+ }
89
+ var catalogCacheFile = (home) => path.join(home, "cache", "models.json");
90
+ function catalogModels(home) {
91
+ if (!home) return MODELS;
92
+ try {
93
+ const cached = JSON.parse(readFileSync(catalogCacheFile(home), "utf8"));
94
+ const providers = cached?.providers && typeof cached.providers === "object" ? cached.providers : {};
95
+ return mergeCatalog(MODELS, Object.fromEntries(Object.entries(providers).map(([runtime, state]) => [runtime, Array.isArray(state?.models) ? state.models : void 0])));
96
+ } catch {
97
+ return MODELS;
98
+ }
99
+ }
42
100
  export {
43
- MODELS
101
+ EFFORTS,
102
+ MODELS,
103
+ MODEL_POLICY,
104
+ catalogCacheFile,
105
+ catalogModels,
106
+ knownModel,
107
+ knownModels,
108
+ mergeCatalog,
109
+ useLiveModels
44
110
  };