@anhlp/alp-core 0.0.1-beta.7 → 0.0.1-beta.9

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 (135) hide show
  1. package/dist/bridges.js +2 -2
  2. package/dist/library-edit.d.ts +51 -2
  3. package/dist/library-edit.js +160 -8
  4. package/dist/library.d.ts +14 -1
  5. package/dist/library.js +73 -5
  6. package/dist/models.d.ts +35 -0
  7. package/dist/models.js +17 -1
  8. package/dist/packaged.d.ts +45 -12
  9. package/dist/packaged.js +46 -5
  10. package/dist/packs.d.ts +57 -0
  11. package/dist/packs.js +247 -0
  12. package/dist/permissions.d.ts +3 -2
  13. package/dist/permissions.js +6 -3
  14. package/dist/profiles.js +3 -3
  15. package/dist/providers.d.ts +2 -4
  16. package/dist/providers.js +20 -4
  17. package/dist/skill-validate.d.ts +85 -0
  18. package/dist/skill-validate.js +298 -0
  19. package/dist/upgrade.d.ts +10 -0
  20. package/dist/upgrade.js +112 -6
  21. package/dist/user-settings.d.ts +2 -0
  22. package/dist/user-settings.js +40 -1
  23. package/dist/validation.d.ts +1 -0
  24. package/dist/validation.js +16 -10
  25. package/package.json +18 -2
  26. package/src/bridges.js +3 -2
  27. package/src/library-edit.js +170 -8
  28. package/src/library.js +96 -6
  29. package/src/models.js +24 -0
  30. package/src/packaged.js +77 -8
  31. package/src/packs.js +246 -0
  32. package/src/permissions.d.ts +3 -2
  33. package/src/permissions.js +13 -3
  34. package/src/profiles.js +4 -4
  35. package/src/providers.js +20 -5
  36. package/src/resolver.js +1 -1
  37. package/src/skill-validate.js +287 -0
  38. package/src/upgrade.js +54 -6
  39. package/src/user-settings.d.ts +2 -0
  40. package/src/user-settings.js +51 -1
  41. package/src/validation.d.ts +1 -0
  42. package/src/validation.js +21 -12
  43. package/templates/ALP.md +52 -52
  44. package/templates/agents/lead/AGENT.md +77 -74
  45. package/templates/agents/main/AGENT.md +153 -145
  46. package/templates/agents/oracle/AGENT.md +38 -37
  47. package/templates/agents/peer/AGENT.md +56 -52
  48. package/templates/agents/reviewer/AGENT.md +63 -65
  49. package/templates/agents/supervisor/AGENT.md +63 -63
  50. package/templates/packs/architecture/agents/architect/AGENT.md +41 -0
  51. package/templates/packs/architecture/agents/architect/agent.json +5 -0
  52. package/templates/packs/architecture/agents/docs-maintainer/AGENT.md +33 -0
  53. package/templates/packs/architecture/agents/docs-maintainer/agent.json +4 -0
  54. package/templates/packs/architecture/pack.json +7 -0
  55. package/templates/packs/architecture/teams/blueprint/HOUSE_RULES.md +12 -0
  56. package/templates/packs/architecture/teams/blueprint/team.json +19 -0
  57. package/templates/packs/backend/pack.json +6 -0
  58. package/templates/packs/backend/skills/backend-development/SKILL.md +102 -0
  59. package/templates/packs/backend/skills/backend-development/references/api-design.md +96 -0
  60. package/templates/packs/backend/skills/backend-development/references/authentication.md +78 -0
  61. package/templates/packs/backend/skills/backend-development/references/error-handling.md +86 -0
  62. package/templates/packs/backend/skills/backend-development/references/testing.md +81 -0
  63. package/templates/packs/backend/skills/databases/SKILL.md +103 -0
  64. package/templates/packs/backend/skills/databases/references/query-performance.md +87 -0
  65. package/templates/packs/backend/skills/databases/references/schema-and-migrations.md +87 -0
  66. package/templates/packs/design/pack.json +6 -0
  67. package/templates/packs/design/skills/ui-design/SKILL.md +86 -0
  68. package/templates/packs/design/skills/ui-design/references/design-tokens.md +67 -0
  69. package/templates/packs/design/skills/ui-design/references/interaction-states.md +73 -0
  70. package/templates/packs/design/skills/ui-design/references/layout-and-typography.md +71 -0
  71. package/templates/packs/design/skills/ui-design/references/ui-review.md +83 -0
  72. package/templates/packs/frontend/pack.json +6 -0
  73. package/templates/packs/frontend/skills/frontend-development/SKILL.md +105 -0
  74. package/templates/packs/frontend/skills/frontend-development/references/accessibility.md +86 -0
  75. package/templates/packs/frontend/skills/frontend-development/references/components-and-state.md +79 -0
  76. package/templates/packs/frontend/skills/frontend-development/references/data-fetching.md +86 -0
  77. package/templates/packs/frontend/skills/frontend-development/references/frameworks.md +77 -0
  78. package/templates/packs/frontend/skills/frontend-development/references/performance.md +78 -0
  79. package/templates/packs/integration/pack.json +6 -0
  80. package/templates/packs/integration/skills/mcp-integration/SKILL.md +100 -0
  81. package/templates/packs/integration/skills/mcp-integration/references/server-implementation.md +95 -0
  82. package/templates/packs/integration/skills/mcp-integration/references/testing.md +78 -0
  83. package/templates/packs/integration/skills/mcp-integration/references/tool-design.md +97 -0
  84. package/templates/packs/operations/pack.json +6 -0
  85. package/templates/packs/operations/skills/devops/SKILL.md +85 -0
  86. package/templates/packs/operations/skills/devops/references/ci-cd.md +84 -0
  87. package/templates/packs/operations/skills/devops/references/containers.md +85 -0
  88. package/templates/packs/operations/skills/devops/references/deployment-and-rollback.md +85 -0
  89. package/templates/packs/operations/skills/devops/references/observability.md +86 -0
  90. package/templates/packs/quality/pack.json +6 -0
  91. package/templates/packs/quality/skills/web-testing/SKILL.md +102 -0
  92. package/templates/packs/quality/skills/web-testing/references/e2e.md +85 -0
  93. package/templates/packs/quality/skills/web-testing/references/performance-testing.md +85 -0
  94. package/templates/packs/quality/skills/web-testing/references/security-testing.md +78 -0
  95. package/templates/packs/quality/skills/web-testing/references/unit-and-component.md +78 -0
  96. package/templates/role-skills.json +4 -4
  97. package/templates/skills/architecture-docs/SKILL.md +81 -0
  98. package/templates/skills/architecture-docs/references/adr.md +62 -0
  99. package/templates/skills/architecture-docs/references/diagrams.md +60 -0
  100. package/templates/skills/architecture-docs/references/evidence-rules.md +49 -0
  101. package/templates/skills/bug-loop/SKILL.md +41 -40
  102. package/templates/skills/bug-loop/references/test-proof.md +21 -19
  103. package/templates/skills/compact/SKILL.md +2 -2
  104. package/templates/skills/curate/SKILL.md +6 -5
  105. package/templates/skills/feature-architecture/SKILL.md +90 -0
  106. package/templates/skills/feature-architecture/references/architecture-contract.md +95 -0
  107. package/templates/skills/feature-architecture/references/feature-design.md +69 -0
  108. package/templates/skills/feature-architecture/scripts/check-boundaries.mjs +270 -0
  109. package/templates/skills/goal-griller/SKILL.md +27 -27
  110. package/templates/skills/prompt-leverage/SKILL.md +29 -27
  111. package/templates/skills/prompt-leverage/references/brief-template.md +9 -9
  112. package/templates/skills/release-readiness/SKILL.md +83 -0
  113. package/templates/skills/release-readiness/references/checklist.md +40 -0
  114. package/templates/skills/release-readiness/references/verdict-template.md +53 -0
  115. package/templates/skills/safe-refactor/SKILL.md +84 -0
  116. package/templates/skills/safe-refactor/references/characterization-tests.md +57 -0
  117. package/templates/skills/safe-refactor/references/compatibility-checklist.md +56 -0
  118. package/templates/skills/security-review/SKILL.md +87 -0
  119. package/templates/skills/security-review/references/checklist.md +74 -0
  120. package/templates/skills/security-review/references/severity.md +61 -0
  121. package/templates/skills/sequence-execution-plan/SKILL.md +41 -38
  122. package/templates/skills/sequence-execution-plan/references/plan-template.md +5 -5
  123. package/templates/skills/skill-authoring/SKILL.md +84 -0
  124. package/templates/skills/skill-authoring/references/evaluation.md +45 -0
  125. package/templates/skills/skill-authoring/references/skill-anatomy.md +74 -0
  126. package/templates/skills/skill-authoring/references/trigger-design.md +52 -0
  127. package/templates/skills/smart-commits/SKILL.md +37 -36
  128. package/templates/skills/test-strategy/SKILL.md +83 -0
  129. package/templates/skills/test-strategy/references/contract-tests.md +46 -0
  130. package/templates/skills/test-strategy/references/risk-matrix.md +53 -0
  131. package/templates/skills/xia/SKILL.md +40 -38
  132. package/templates/teams/cafe/HOUSE_RULES.md +1 -1
  133. package/templates/teams/cafe/team.json +1 -1
  134. package/templates/teams/pho/HOUSE_RULES.md +1 -1
  135. package/templates/teams/pho/team.json +1 -1
@@ -0,0 +1,287 @@
1
+ import { lstat, readFile, readdir, realpath, stat } from 'node:fs/promises';
2
+ import path from 'node:path';
3
+
4
+ /**
5
+ * Skill validation (Agent Skills format, https://agentskills.io/specification): a skill is a
6
+ * directory holding SKILL.md, whose YAML frontmatter names it and says what it is for, and the
7
+ * references, scripts and assets SKILL.md points to.
8
+ *
9
+ * Two modes. `strict` is for skills ALP ships, packs and new skills: format problems are errors.
10
+ * `legacy` (the default) is for skills already in a user's library or project: format problems
11
+ * are warnings with a migration hint, since ALP never rewrites them and the runtime keeps loading
12
+ * them. A symlink leaving the skill, a broken symlink or an unreadable file is an error in both
13
+ * modes; a plain path leaving the skill is an error in strict mode and a warning in legacy mode. Validation only reads; it never runs a script or follows a link outside the skill.
14
+ */
15
+
16
+ /** Frontmatter keys of the Agent Skills specification. */
17
+ export const SPEC_KEYS = ['name', 'description', 'license', 'compatibility', 'metadata', 'allowed-tools'];
18
+ /** Keys other runtimes add (Claude Code); kept, reported as runtime-specific in strict mode. */
19
+ const RUNTIME_KEYS = ['argument-hint', 'disable-model-invocation', 'user-invocable', 'model', 'version', 'when_to_use', 'mode'];
20
+ export const NAME_MAX = 64;
21
+ export const DESCRIPTION_MAX = 1024;
22
+ /** How much of a description ALP's skill index shows (resolve.ts SKILL_DESCRIPTION_CHARS). */
23
+ export const INDEX_DESCRIPTION_CHARS = 400;
24
+ const COMPATIBILITY_MAX = 500;
25
+ const BODY_LINES_RECOMMENDED = 500;
26
+ const MAX_FILES = 2000;
27
+
28
+
29
+ const NAME_RE = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
30
+ /** A trigger cue: the description says when to use the skill. */
31
+ const TRIGGER_RE = /\b(use|when|before|after|whenever|for)\b|dùng|khi/i;
32
+
33
+ /** Whether `name` follows the specification's name rules. */
34
+ export const specName = name => typeof name === 'string' && name.length >= 1 && name.length <= NAME_MAX && NAME_RE.test(name);
35
+
36
+ /** A YAML double-quoted scalar's escapes (the JSON subset plus \/ and \e not needed here). */
37
+ function doubleQuoted(raw) {
38
+ try { return JSON.parse(`"${raw.replace(/\\'/g, "'")}"`); } catch { return undefined; }
39
+ }
40
+
41
+ /**
42
+ * Parses the YAML subset skills use: `key: scalar`, quoted scalars, block scalars (`|`, `>`),
43
+ * multi-line plain scalars, comments, and one level of `key:` + indented `sub: value` (metadata).
44
+ * Anything else (sequences, flow collections, anchors, tags) is reported as unsupported.
45
+ * @returns {{ data: Record<string, unknown>, problems: string[] }}
46
+ */
47
+ export function parseFrontmatter(text) {
48
+ const lines = text.split(/\r?\n/);
49
+ const data = {};
50
+ const problems = [];
51
+ const indent = line => /^ */.exec(line)[0].length;
52
+ let i = 0;
53
+ const scalar = (raw, key, baseIndent) => {
54
+ const value = raw.trim();
55
+ if (!value) {
56
+ // A nested mapping, or an empty value.
57
+ const nested = {};
58
+ let found = false;
59
+ while (i < lines.length && (lines[i].trim() === '' || lines[i].trimStart().startsWith('#') || indent(lines[i]) > baseIndent)) {
60
+ const line = lines[i++];
61
+ if (!line.trim() || line.trimStart().startsWith('#')) continue;
62
+ const match = /^\s+([^:#\s][^:]*?):(?:\s+(.*)|\s*)$/.exec(line);
63
+ if (!match) { problems.push(`${key}: unsupported YAML in '${line.trim()}' (use "key: value" lines)`); continue; }
64
+ found = true;
65
+ nested[match[1].trim()] = scalar(match[2] ?? '', `${key}.${match[1].trim()}`, indent(line));
66
+ }
67
+ return found ? nested : '';
68
+ }
69
+ if (value.startsWith('"')) {
70
+ const end = /^"((?:[^"\\]|\\.)*)"\s*(?:#.*)?$/.exec(value);
71
+ if (!end) { problems.push(`${key}: unterminated or multi-line double-quoted value`); return undefined; }
72
+ const parsed = doubleQuoted(end[1]);
73
+ if (parsed === undefined) problems.push(`${key}: invalid escape in double-quoted value`);
74
+ return parsed;
75
+ }
76
+ if (value.startsWith("'")) {
77
+ const end = /^'((?:[^']|'')*)'\s*(?:#.*)?$/.exec(value);
78
+ if (!end) { problems.push(`${key}: unterminated or multi-line single-quoted value`); return undefined; }
79
+ return end[1].replaceAll("''", "'");
80
+ }
81
+ const block = /^([|>])([+-]?)([1-9]?)([+-]?)\s*(?:#.*)?$/.exec(value);
82
+ if (block?.[3]) problems.push(`${key}: block scalar indentation indicators are not supported; indent the text instead`);
83
+ if (block) {
84
+ const body = [];
85
+ while (i < lines.length && (lines[i].trim() === '' || indent(lines[i]) > baseIndent)) body.push(lines[i++]);
86
+ while (body.length && !body[body.length - 1].trim()) body.pop();
87
+ const width = Math.min(...body.filter(line => line.trim()).map(indent));
88
+ const content = body.map(line => line.slice(Number.isFinite(width) ? width : 0));
89
+ const joined = block[1] === '|' ? content.join('\n') : content.join('\n').replace(/([^\n])\n(?=[^\n])/g, '$1 ');
90
+ return (block[2] || block[4]) === '-' ? joined : `${joined}\n`;
91
+ }
92
+ if (/^[[{&*!%@`]/.test(value) || value.startsWith('- ')) {
93
+ problems.push(`${key}: unsupported YAML value '${value.slice(0, 40)}' (use a plain or quoted string)`);
94
+ return undefined;
95
+ }
96
+ let plain = value.replace(/\s+#.*$/, '');
97
+ // A plain scalar may continue on more-indented lines.
98
+ while (i < lines.length && lines[i].trim() && indent(lines[i]) > baseIndent && !lines[i].trimStart().startsWith('#')) plain += ` ${lines[i++].trim()}`;
99
+ if (/:\s/.test(plain) || plain.endsWith(':')) problems.push(`${key}: plain value contains ": " which YAML rejects; quote the value`);
100
+ return plain;
101
+ };
102
+ while (i < lines.length) {
103
+ const line = lines[i++];
104
+ if (!line.trim() || line.trimStart().startsWith('#')) continue;
105
+ if (indent(line) > 0) { problems.push(`unexpected indentation: '${line.trim().slice(0, 40)}'`); continue; }
106
+ const match = /^([^:#\s][^:]*?):(?:\s+(.*)|\s*)$/.exec(line);
107
+ if (!match) { problems.push(`not a "key: value" line: '${line.trim().slice(0, 40)}'`); continue; }
108
+ const key = match[1].trim();
109
+ if (Object.hasOwn(data, key)) problems.push(`${key}: duplicate key`);
110
+ data[key] = scalar(match[2] ?? '', key, 0);
111
+ }
112
+ return { data, problems };
113
+ }
114
+
115
+ /** The frontmatter block and body of a SKILL.md, or undefined frontmatter when it has none. */
116
+ export function splitSkill(text) {
117
+ const match = /^?---\r?\n([\s\S]*?)\r?\n---[ \t]*(?:\r?\n|$)/.exec(text);
118
+ return match ? { frontmatter: match[1], body: text.slice(match[0].length) } : { frontmatter: undefined, body: text };
119
+ }
120
+
121
+ /**
122
+ * The relative files a Markdown text points to: link targets and code spans naming a resource
123
+ * directory (`references/x.md`). URLs, anchors and template placeholders are skipped.
124
+ */
125
+ export function skillReferences(markdown) {
126
+ const found = new Set();
127
+ const withoutFences = markdown.replace(/^(```|~~~)[\s\S]*?^\1/gm, '');
128
+ for (const match of withoutFences.matchAll(/\]\(\s*<?([^)\s>]+)>?(?:\s+"[^"]*")?\s*\)/g)) found.add(match[1]);
129
+ // A code span is a reference only under references/: `scripts/x` or `templates/` in prose often
130
+ // names a directory of the project the skill works on, so those need a link to be checked.
131
+ for (const match of withoutFences.matchAll(/`([^`\s]+)`/g)) {
132
+ if (/^(?:\.\/)?references\/[^*<>{}$]+\.[a-z0-9]+$/i.test(match[1])) found.add(match[1]);
133
+ }
134
+ return [...found].filter(target => !/^[a-z][\w+.-]*:/i.test(target) && !target.startsWith('#') && !target.startsWith('//'))
135
+ .map(target => { const plain = target.split('#')[0]; try { return decodeURI(plain); } catch { return plain; } }).filter(Boolean);
136
+ }
137
+
138
+ const inside = (root, target) => { const relative = path.relative(root, target); return relative === '' || (!relative.startsWith('..') && !path.isAbsolute(relative)); };
139
+
140
+ /**
141
+ * Checks frontmatter text against the specification. `directory` is the skill directory's name.
142
+ * @returns {{ data: Record<string, unknown>, findings: Array<{ level: 'error' | 'warning', code: string, message: string }> }}
143
+ */
144
+ export function checkFrontmatter(frontmatter, directory, { strict = false } = {}) {
145
+ const findings = [];
146
+ const format = (code, message) => findings.push({ level: strict ? 'error' : 'warning', code, message });
147
+ const error = (code, message) => findings.push({ level: 'error', code, message });
148
+ const warn = (code, message) => findings.push({ level: 'warning', code, message });
149
+ if (frontmatter === undefined) {
150
+ format('NO_FRONTMATTER', 'SKILL.md has no YAML frontmatter; add "---\\nname: ...\\ndescription: ...\\n---" so agents see what the skill is for');
151
+ return { data: {}, findings };
152
+ }
153
+ const { data, problems } = parseFrontmatter(frontmatter);
154
+ for (const problem of problems) format('YAML', `frontmatter: ${problem}`);
155
+ const { name, description } = data;
156
+ if (name === undefined) format('NAME_MISSING', 'frontmatter has no name');
157
+ else if (typeof name !== 'string' || !specName(name)) format('NAME_FORMAT', `name '${name}' must be 1-${NAME_MAX} lowercase letters, digits and single hyphens, not starting or ending with one`);
158
+ if (typeof name === 'string' && directory !== undefined && name !== directory) format('NAME_DIRECTORY', `name '${name}' differs from its directory '${directory}'; agents find it by the directory name`);
159
+ if (directory !== undefined && !specName(directory)) format('DIRECTORY_NAME', `directory '${directory}' is not a valid skill name; rename it to lowercase letters, digits and hyphens`);
160
+ if (description === undefined || (typeof description === 'string' && !description.trim())) format('DESCRIPTION_MISSING', 'frontmatter has no description: it is all an agent sees before opening the skill');
161
+ else if (typeof description !== 'string') format('DESCRIPTION_FORMAT', 'description must be text');
162
+ else {
163
+ const flat = description.replace(/\s+/g, ' ').trim();
164
+ if (flat.length > DESCRIPTION_MAX) format('DESCRIPTION_LENGTH', `description has ${flat.length} characters; the limit is ${DESCRIPTION_MAX}`);
165
+ else if (flat.length > INDEX_DESCRIPTION_CHARS) warn('DESCRIPTION_CLIPPED', `description has ${flat.length} characters; ALP's skill index shows the first ${INDEX_DESCRIPTION_CHARS}`);
166
+ if (flat.length < 40) warn('DESCRIPTION_SHORT', 'description is under 40 characters; say what the skill does and when to use it');
167
+ if (!TRIGGER_RE.test(flat)) warn('DESCRIPTION_TRIGGER', 'description does not say when to use the skill (for example "Use when ...")');
168
+ if (/[<>]/.test(flat)) format('DESCRIPTION_ANGLE', 'description contains < or >, which some runtimes reject');
169
+ }
170
+ if (data.compatibility !== undefined && (typeof data.compatibility !== 'string' || data.compatibility.length > COMPATIBILITY_MAX)) format('COMPATIBILITY', `compatibility must be text of at most ${COMPATIBILITY_MAX} characters`);
171
+ if (data.license !== undefined && typeof data.license !== 'string') format('LICENSE', 'license must be text');
172
+ if (data['allowed-tools'] !== undefined && typeof data['allowed-tools'] !== 'string') format('ALLOWED_TOOLS', 'allowed-tools must be a space-separated string');
173
+ if (data['allowed-tools'] !== undefined) warn('ALLOWED_TOOLS_ADVISORY', 'allowed-tools is advisory: ALP permissions come from the session mode and permission profiles, never from a skill');
174
+ if (data.metadata !== undefined && (typeof data.metadata !== 'object' || data.metadata === null || Object.values(data.metadata).some(value => typeof value !== 'string'))) format('METADATA', 'metadata must map names to text values');
175
+ for (const key of Object.keys(data)) {
176
+ if (SPEC_KEYS.includes(key)) continue;
177
+ if (RUNTIME_KEYS.includes(key)) format('RUNTIME_KEY', `'${key}' is specific to one runtime; other runtimes ignore it`);
178
+ else format('UNKNOWN_KEY', `unknown frontmatter key '${key}'; the specification allows ${SPEC_KEYS.join(', ')}`);
179
+ }
180
+ return { data, findings };
181
+ }
182
+
183
+ /** Whether a buffer is UTF-8 text without NUL bytes. */
184
+ const isText = buffer => !buffer.includes(0) && Buffer.from(buffer.toString('utf8'), 'utf8').equals(buffer);
185
+
186
+ /**
187
+ * Validates one skill directory.
188
+ * @param {string} directory absolute or relative path of the skill directory
189
+ * @param {{ mode?: 'strict' | 'legacy', shipped?: boolean }} [options] `shipped`: the skill ships in
190
+ * ALP's templates, which bundles carry as UTF-8 text, so every file must be text
191
+ * @returns {Promise<{ name: string, directory: string, mode: 'strict' | 'legacy', ok: boolean, errors: Finding[], warnings: Finding[], files: number }>}
192
+ * @typedef {{ code: string, message: string, file?: string }} Finding
193
+ */
194
+ export async function validateSkill(directory, { mode = 'legacy', shipped = false } = {}) {
195
+ const root = path.resolve(directory);
196
+ const strict = mode === 'strict';
197
+ /** @type {Array<Finding & { level: 'error' | 'warning' }>} */
198
+ const findings = [];
199
+ const add = (level, code, message, file) => findings.push({ level, code, message, ...(file ? { file } : {}) });
200
+ const format = (code, message, file) => add(strict ? 'error' : 'warning', code, message, file);
201
+ const result = () => {
202
+ const errors = findings.filter(f => f.level === 'error').map(({ level, ...f }) => f);
203
+ const warnings = findings.filter(f => f.level === 'warning').map(({ level, ...f }) => f);
204
+ return { name: path.basename(root), directory: root, mode, ok: errors.length === 0, errors, warnings, files };
205
+ };
206
+ let files = 0;
207
+ const info = await lstat(root).catch(() => undefined);
208
+ if (!info) { add('error', 'NOT_FOUND', `no skill directory at ${root}`); return result(); }
209
+ if (info.isSymbolicLink()) add('warning', 'DIRECTORY_LINK', 'the skill directory is a symbolic link; its contents are checked where it points');
210
+ const real = await realpath(root).catch(() => root);
211
+ if (!(await stat(real).then(s => s.isDirectory(), () => false))) { add('error', 'NOT_DIRECTORY', `${root} is not a directory`); return result(); }
212
+
213
+ // Every file under the skill: symlinks must stay inside it; shipped skills must be text.
214
+ const markdown = [];
215
+ let stopped = false;
216
+ const walk = async relative => {
217
+ let entries;
218
+ try { entries = await readdir(path.join(real, relative), { withFileTypes: true }); }
219
+ catch (error) { add('error', 'UNREADABLE', `${relative || '.'} cannot be read: ${error.code ?? error.message}`, relative || undefined); return; }
220
+ for (const entry of entries.sort((a, b) => a.name.localeCompare(b.name))) {
221
+ if (stopped) return;
222
+ const rel = path.join(relative, entry.name);
223
+ const full = path.join(real, rel);
224
+ if (++files > MAX_FILES) { stopped = true; add('error', 'TOO_MANY_FILES', `more than ${MAX_FILES} files; a skill should hold instructions and small resources`); return; }
225
+ if (entry.name === 'node_modules' || entry.name === '.git') { add('warning', 'BUNDLED_DEPENDENCIES', `${rel} is bundled; skills must not carry installed dependencies or repositories`, rel); continue; }
226
+ if (entry.isSymbolicLink()) {
227
+ const target = await realpath(full).catch(() => undefined);
228
+ if (target === undefined) add('error', 'BROKEN_SYMLINK', `${rel} is a symbolic link to nothing`, rel);
229
+ else if (!inside(real, target)) add('error', 'UNSAFE_SYMLINK', `${rel} links outside the skill (${target})`, rel);
230
+ else if (shipped) add('error', 'SHIPPED_SYMLINK', `${rel} is a symbolic link; shipped skills hold plain files`, rel);
231
+ continue;
232
+ }
233
+ if (entry.isDirectory()) { await walk(rel); continue; }
234
+ if (!entry.isFile()) { add('error', 'SPECIAL_FILE', `${rel} is not a regular file`, rel); continue; }
235
+ const posix = rel.split(path.sep).join('/');
236
+ if (shipped || posix.endsWith('.md') || posix.startsWith('scripts/')) {
237
+ let buffer;
238
+ try { buffer = await readFile(full); }
239
+ catch (error) { add('error', 'UNREADABLE', `${rel} cannot be read: ${error.code ?? error.message}`, rel); continue; }
240
+ if (shipped && !isText(buffer)) add('error', 'SHIPPED_BINARY', `${rel} is not UTF-8 text; ALP bundles carry shipped skills as text`, rel);
241
+ if (posix.endsWith('.md')) markdown.push([posix, buffer.toString('utf8')]);
242
+ if (posix.startsWith('scripts/') && !shipped && process.platform !== 'win32' && buffer.subarray(0, 2).toString() === '#!' && !((await stat(full)).mode & 0o111)) {
243
+ add('warning', 'SCRIPT_NOT_EXECUTABLE', `${rel} has a #! line but is not executable; run it with its interpreter or chmod +x it`, rel);
244
+ }
245
+ }
246
+ }
247
+ };
248
+ await walk('');
249
+
250
+ const skillFile = markdown.find(([file]) => file === 'SKILL.md');
251
+ if (!skillFile) {
252
+ const other = await readdir(real).then(list => list.find(name => name.toLowerCase() === 'skill.md'), () => undefined);
253
+ add('error', 'SKILL_MD_MISSING', other ? `found ${other}; the file must be named SKILL.md` : 'no SKILL.md');
254
+ return result();
255
+ }
256
+ const { frontmatter, body } = splitSkill(skillFile[1]);
257
+ for (const finding of checkFrontmatter(frontmatter, path.basename(root), { strict }).findings) add(finding.level, finding.code, finding.message, 'SKILL.md');
258
+ if (!body.trim()) format('BODY_EMPTY', 'SKILL.md has no instructions after its frontmatter', 'SKILL.md');
259
+ const lines = body.split('\n').length;
260
+ if (lines > BODY_LINES_RECOMMENDED) add('warning', 'BODY_LONG', `SKILL.md body has ${lines} lines; move detail into references/ (recommended under ${BODY_LINES_RECOMMENDED})`, 'SKILL.md');
261
+
262
+ // References from every Markdown file in the skill, resolved against that file.
263
+ for (const [file, text] of markdown) {
264
+ const content = file === 'SKILL.md' ? body : text;
265
+ for (const target of skillReferences(content)) {
266
+ // A path leaving the skill does not travel with it: an error for new skills, a warning for existing
267
+ // ones (a link to a sibling skill still works where it is). A symlink leaving it is always an error.
268
+ if (path.isAbsolute(target) || /^[a-z]:[\\/]/i.test(target) || target.startsWith('~')) { format('ABSOLUTE_REFERENCE', `${file} names the absolute path ${target}; use a path relative to the skill`, file); continue; }
269
+ const resolved = path.resolve(real, path.dirname(file), target);
270
+ if (!inside(real, resolved)) { format('REFERENCE_OUTSIDE', `${file} points outside the skill: ${target}`, file); continue; }
271
+ const linked = await lstat(resolved).catch(() => undefined);
272
+ if (!linked) { format('BROKEN_REFERENCE', `${file} points to ${target}, which does not exist`, file); continue; }
273
+ if (linked.isSymbolicLink()) {
274
+ const target2 = await realpath(resolved).catch(() => undefined);
275
+ if (!target2 || !inside(real, target2)) add('error', 'REFERENCE_OUTSIDE', `${file} points through a link outside the skill: ${target}`, file);
276
+ }
277
+ }
278
+ }
279
+ return result();
280
+ }
281
+
282
+ /** One line per finding, for a terminal. */
283
+ export function formatValidation(report) {
284
+ const head = `${report.ok ? 'ok ' : 'FAIL'} ${report.name} (${report.mode}) ${report.directory}`;
285
+ const rows = [...report.errors.map(f => ` error ${f.code}: ${f.message}`), ...report.warnings.map(f => ` warning ${f.code}: ${f.message}`)];
286
+ return [head, ...rows].join('\n');
287
+ }
package/src/upgrade.js CHANGED
@@ -14,14 +14,62 @@ const legacy = {
14
14
  };
15
15
  // SHA-256 of shipped role definitions after CRLF normalization. Custom
16
16
  // definitions do not match and remain untouched. Keep historical IDs immutable.
17
+ //
18
+ // A project only receives a new role definition when the copy it holds is listed here, so a version
19
+ // ALP once shipped and never listed is stranded as customInstructions for ever (t-1293). The second
20
+ // block of each list is every distinct content `templates/<file>` ever had in this repository, in
21
+ // commit order, with the commit it first appeared in; the first block is what earlier releases (and
22
+ // the pre-fork Paseo team-v1 lineage) listed by hand. Append only, never edit or remove a line.
23
+ // To extend after changing a template, take the hash of the content being replaced:
24
+ // git show <commit>:templates/agents/supervisor/AGENT.md |
25
+ // node -e 'let d="";process.stdin.setEncoding("utf8").on("data",c=>d+=c).on("end",()=>console.log(require("crypto").createHash("sha256").update(d.replaceAll("\r\n","\n")).digest("hex")))'
17
26
  const teamV1 = {
18
- 'ALP.md': ['c2785aac6538d10e79bd6fb59b11066ccdec77287edf950fad59aa57bf3417f1', '0875293195d35d965effb70bb150d1edbc789f66f72c545f7760dea4346b1a9a'],
19
- '.alp/agents/main/AGENT.md': ['15d217cbc5ede782790d1086124598d9a2b5ff13bcf971a37231962fcef1b47c', 'e7201a1ed7800d7500b5c8091bd8a435aa9d5138f247c2b02b8bf76299387c90', '5001b807bbb686aa1a3b7ecadf9501428909e052e8231281454fd41cbe0ebf27', '90f9903fcc97ddf6336e1a28b81103dddc60a6038dcf74d326be8998862cb022', '9085ab906e2744a4151ae5c63dd66a545115cd4c876be1fd80f0a0ed4e623da8', 'fb55cfb0852d07592090de2c49e6c5c2b57936cbffc823dd24767c2db5e5f7fb'],
20
- '.alp/agents/lead/AGENT.md': ['c259b085a3c102445f97e5c7d402ca68347bcc1a9b02d6ab96e02be6d8b6f9af', '2eef2a4474f757cd89b35b50638a1b23fe49a54c26bf0dedb24a96d7117ddd92', '6c71393c9b3aa655c4731bda96396ea3ec0d4da62cddb3ad50d1a24113416b77', 'a382f0faa724e23a0ba9c212205978aa3fef87c3aecdf8823fba136e04568487', '547e3f8fc354b22c7beb3432182d68f4de1f24938375c8bfb167ae8afbf97de2'],
21
- '.alp/agents/peer/AGENT.md': ['f3dcf16c8c899a5378a468e922ca3956fd72cbb3e3798ed1109f11e01aa8f476', '39ccf3317eba3003faad77ebad4489fae3eb3c4d89258a03f619d1d3d65af0b7', 'c59e45e8f22eb0daca9b8b5e1b19e90666156807f160e75a21eca48b5fee1102', '9623dbf76eda598f6267629e993663c149acb0efd253f3900a4ee1eda8f2f9e7'],
22
- '.alp/agents/oracle/AGENT.md': ['cdce1babcd587a190dc94a32a951ed70ce2c75f99c205a4049df940851ac7059'],
23
- '.alp/agents/reviewer/AGENT.md': ['6eab9f918c79335a0665bf4e3a3a26b66258684d6725c4c95637e70e8d355123'],
27
+ 'ALP.md': ['c2785aac6538d10e79bd6fb59b11066ccdec77287edf950fad59aa57bf3417f1', '0875293195d35d965effb70bb150d1edbc789f66f72c545f7760dea4346b1a9a', 'fe0d5e6f64ef5a5030ee99feaf083f062a8e5136ac52d451e2ca7cdacb21d14f',
28
+ 'e04fe558a26d6e3c9b08211c426a83c368e4f0d15b0929e55df8ab4e5c4bb932', // 61181b5
29
+ 'ff1a7da448b735a9b4f88e3d9b6006d048114d3becee96a331d225b63e453c56', // ca2a971
30
+ '263135a3139eb40501f6e502271e946ec3db4692b63e39c2dd349ac0aaae6d62', // 818ab2e
31
+ 'e855f56ca0af0691c731ac5f2eb93d2528e339f2dbfd6f2376594f878d2c11e1', // 1f827c6
32
+ '48c6a0f80b41958457f8dbaaad7a4b3118efeaf5feb6ae626501c2f7896b077d'], // PR #330 (replaces 83388aa's hash, which never reached main)
33
+ '.alp/agents/main/AGENT.md': ['15d217cbc5ede782790d1086124598d9a2b5ff13bcf971a37231962fcef1b47c', 'e7201a1ed7800d7500b5c8091bd8a435aa9d5138f247c2b02b8bf76299387c90', '5001b807bbb686aa1a3b7ecadf9501428909e052e8231281454fd41cbe0ebf27', '90f9903fcc97ddf6336e1a28b81103dddc60a6038dcf74d326be8998862cb022', '9085ab906e2744a4151ae5c63dd66a545115cd4c876be1fd80f0a0ed4e623da8', 'fb55cfb0852d07592090de2c49e6c5c2b57936cbffc823dd24767c2db5e5f7fb', '91b71f5750e75f707488b70618e1d65a63aabf7518762f97ea0fde999d36fead',
34
+ '60d92fa634e178244a38e99c074e169af1847d7512e268262148ec15ebf08bed', // 61181b5
35
+ 'b501142ebff430e2ac6d0c3ecb2673cbf0fe0e1fa123b73b113ba9b4aa5f3a39', // ca2a971
36
+ 'ddbd75ebacf5f13615fa3da4941a389b14b534742032c3046e0e6c214a46c989', // ec26e6c
37
+ '5d610e7639bc8eaa29ad4119a5c090cbd286bd217f2f4a7d3abdd59725a985c1', // a1acd92
38
+ '28037d678457a392a42510d57919b14a643ea729c2a358fa7aeee4b7a33e6727', // 8d0e12a
39
+ 'b4435cf5ef8cfab2238eee86298f21cfa508e3fdeb6b3e697fde94160c341fe7', // 105f68f
40
+ '973539ce5dd998440cb59938f37260760f96f66a67b66369fcb28421acd49903', // 40ce2de
41
+ 'ab85e561f62a46e8838cc955984b66583a7325e69c1e7f2fd049479241553751', // cc9215e
42
+ '8b8d0bff45d245543f543ecd15043be38fd03edd364c6750aac58b87785c1afa', // 818ab2e
43
+ '2e82f110b108032c3c4444c306e73409bb6b481e5dc9ab080fe1ee2eb583fb78', // b8d2fbc
44
+ 'cde93f41883b26c2ef7636735d88be8fb202b143c479821647799c83b7d673dc', // 9180aa1
45
+ '29f181001edfee5521d8f4965b33f501f8ef869f6af3abf74a05e5f1623809ac', // f4d7986
46
+ 'd6f8002a81e3e0b7bb5868a6834d7be37731cc307877d7a03513067be10cad2f', // 1f827c6
47
+ 'b9bdd073e22903e3813f13caf87c9341215476ed692b3f04bc0971b66fd93ac5'], // 83388aa
48
+ '.alp/agents/lead/AGENT.md': ['c259b085a3c102445f97e5c7d402ca68347bcc1a9b02d6ab96e02be6d8b6f9af', '2eef2a4474f757cd89b35b50638a1b23fe49a54c26bf0dedb24a96d7117ddd92', '6c71393c9b3aa655c4731bda96396ea3ec0d4da62cddb3ad50d1a24113416b77', 'a382f0faa724e23a0ba9c212205978aa3fef87c3aecdf8823fba136e04568487', '547e3f8fc354b22c7beb3432182d68f4de1f24938375c8bfb167ae8afbf97de2', 'f3609df1486c0911459d8ee7d823b344369df0538654b0de6e9bc23170186b22',
49
+ '1674d7b96450824111ce885c828af51aa8924c38888bdeb583f4f31684c2bf60', // 61181b5
50
+ '7cd01a44200fda79ae0979a4975c483494a35e2e8c144b4e56f0b61046fc1a67', // ca2a971
51
+ 'c622392fcb94aeec18efcb12fe9ed574117304af02c303d0f575a2181991b454', // 8d0e12a
52
+ '6e9166b3b72333b76b4b2ef5a7778e142d6fd3c1023efd8a792bec1b12516415', // 40ce2de
53
+ '8aef2591deb1ca12f3cbc843445688140aeb03f7c42bff8e15ef74bdd03be940', // 1f827c6
54
+ 'e241608ee9579ed894024cba8f9b7b60e75283179d68ebbd4cb28a526c78965d'], // 83388aa
55
+ '.alp/agents/peer/AGENT.md': ['f3dcf16c8c899a5378a468e922ca3956fd72cbb3e3798ed1109f11e01aa8f476', '39ccf3317eba3003faad77ebad4489fae3eb3c4d89258a03f619d1d3d65af0b7', 'c59e45e8f22eb0daca9b8b5e1b19e90666156807f160e75a21eca48b5fee1102', '9623dbf76eda598f6267629e993663c149acb0efd253f3900a4ee1eda8f2f9e7', '20b0d2b6be74597ea1f39cf6d2d56c0ef2bffe39cb3bfe1ae41761748ef9bfae',
56
+ 'da389b7fa194fcf4cb8683664d30e06197999d804ec4ee94c1889bb397f540a9', // 61181b5
57
+ 'c7c8f4c5468484bab165f8f32b141398a259d4e6e9966e304528d82858e6807e', // ca2a971
58
+ 'd7cbdac679c82086ce2601d0a2c82480f6b2300ea011a9e07862f1b900d6ac75'], // 1f827c6
59
+ '.alp/agents/oracle/AGENT.md': ['cdce1babcd587a190dc94a32a951ed70ce2c75f99c205a4049df940851ac7059', '0907091b17aa8e54215b65171433f222b8491e9490a16a66b6a2b8cffc3f9023',
60
+ 'ae6219e0141d290705ed45992f0cc78688d17c78757f7f1f72f1639432e110cc'], // 1f827c6
61
+ '.alp/agents/reviewer/AGENT.md': ['6eab9f918c79335a0665bf4e3a3a26b66258684d6725c4c95637e70e8d355123', '1809de0be6473d5f9ceeae2d35128d52a0c0cde3968b45a7569ceae7a8a74416',
62
+ '56bebc192fda9d67bc2ceaf14d4f0cf274eaa40bf3e652caaf85c239eba1a253'], // 1f827c6
63
+ '.alp/agents/supervisor/AGENT.md': ['81ac93f4fbf2337224f838d39a9c4ef13fdba12d5fc7de681a00628bf9e69a27',
64
+ 'a2be7e682b030d2ff122ba4e836b1c89858493a05937fa11ad1fa808e0df9c8d', // 61181b5
65
+ 'd26d642128bedb6c90d4a84b227877ae4ea8be0838de75f40d786c0ba55183ae', // ec26e6c
66
+ 'f920b505cda38c90f7014827352225846b6b1e35a40675e2f5d01b03cee250ce', // cdbc297
67
+ '10e22e451264a901a7ad62e04189a91fae70940a62f4646f22c1135244986d03', // cc9215e
68
+ '6c306170ee5218313c93dc8bc1049e1dd9daf401073fda4c476ff4b5630765ab'], // 1f827c6
24
69
  };
70
+ /** The hashes above, by project-relative path, so a test can hold the list to the templates. */
71
+ export const shippedRoleHashes = teamV1;
72
+
25
73
  /** Profiles' names before 0.4. */
26
74
  const renamedProfiles = { smart: 'pho', supervised: 'cafe' };
27
75
 
@@ -4,3 +4,5 @@ export function userLanguage(home?: string): Promise<string>;
4
4
  export function languageSetting(home: string): Promise<{ language: string | null; applies: string; default: string }>;
5
5
  export function setLanguage(home: string | undefined, language: string | null): Promise<{ language: string | null; applies: string; default: string }>;
6
6
  export function setWebRelay(home: string, patch: { enabled?: boolean; endpoint?: string; useTls?: boolean }): Promise<{ enabled?: boolean; endpoint?: string; useTls?: boolean }>;
7
+ export function dashboardSettings(settings: unknown): { enabled?: boolean; port?: number; permissions?: string[] };
8
+ export function migrateDashboardSettings(home: string): Promise<{ moved: string[]; conflicts: string[] }>;
@@ -3,7 +3,7 @@ import { moveFile } from './atomic.js';
3
3
  import { randomUUID } from 'node:crypto';
4
4
  import path from 'node:path';
5
5
  import { AlpError } from './errors.js';
6
- import { validateUserSettings } from './validation.js';
6
+ import { DASHBOARD_SETTINGS, validateUserSettings } from './validation.js';
7
7
 
8
8
  /**
9
9
  * The user's own settings in $ALP_HOME/settings.json that ALP and its screens edit
@@ -74,3 +74,53 @@ export async function setWebRelay(home, patch) {
74
74
  await moveFile(temporary, file);
75
75
  return next.web.relay;
76
76
  }
77
+
78
+ /**
79
+ * alp dashboard's settings (enabled, port, permissions): `dashboard.*` first, then the `web.*` they
80
+ * had before the rename (t-81b0.5), so a file not yet migrated is still obeyed rather than ignored.
81
+ * @param {any} settings
82
+ * @returns {{ enabled?: boolean, port?: number, permissions?: string[] }}
83
+ */
84
+ export function dashboardSettings(settings) {
85
+ const now = settings?.dashboard ?? {};
86
+ const before = settings?.web ?? {};
87
+ /** @type {any} */
88
+ const result = {};
89
+ for (const key of DASHBOARD_SETTINGS) {
90
+ const value = now[key] !== undefined ? now[key] : before[key];
91
+ if (value !== undefined) result[key] = value;
92
+ }
93
+ return result;
94
+ }
95
+
96
+ /**
97
+ * Moves alp dashboard's settings from `web` (before the rename, t-81b0.5) to `dashboard` in
98
+ * settings.json, keeping everything else, `web.relay` (Paseo's) included. A key `dashboard` already
99
+ * sets wins: the `web` one is left in place and reported, never merged over it. Idempotent: a file
100
+ * with nothing to move is not written. Returns what it moved and what it left.
101
+ * @param {string} home
102
+ * @returns {Promise<{ moved: string[], conflicts: string[] }>}
103
+ */
104
+ export async function migrateDashboardSettings(home) {
105
+ const { file, settings } = await readSettings(home);
106
+ const web = settings.web;
107
+ if (!web || typeof web !== 'object') return { moved: [], conflicts: [] };
108
+ const moved = [], conflicts = [];
109
+ const dashboard = { ...settings.dashboard };
110
+ const rest = { ...web };
111
+ for (const key of DASHBOARD_SETTINGS) {
112
+ if (web[key] === undefined) continue;
113
+ if (dashboard[key] !== undefined) { conflicts.push(key); continue; }
114
+ dashboard[key] = web[key];
115
+ delete rest[key];
116
+ moved.push(key);
117
+ }
118
+ if (!moved.length) return { moved, conflicts };
119
+ const next = { ...settings, dashboard };
120
+ if (Object.keys(rest).length) next.web = rest; else delete next.web;
121
+ validateUserSettings(next, file);
122
+ const temporary = `${file}.${randomUUID().slice(0, 8)}.tmp`;
123
+ await writeFile(temporary, JSON.stringify(next, null, 2) + '\n', { mode: 0o600 });
124
+ await moveFile(temporary, file);
125
+ return { moved, conflicts };
126
+ }
@@ -1,5 +1,6 @@
1
1
  export const PROJECT_SETTINGS: string[];
2
2
  export const USER_SETTINGS: string[];
3
+ export const DASHBOARD_SETTINGS: readonly string[];
3
4
  export const RETIRED_SETTINGS: { project: Record<string, string>; user: Record<string, string> };
4
5
  export function settingsKeys(settings: unknown, known: string[], retired?: Record<string, string>): { unknown: Array<{ key: string; suggestion?: string }>; retired: Array<{ key: string; instead: string }> };
5
6
  export function settingsWarnings(settings: unknown, scope: 'project' | 'user'): string[];
package/src/validation.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import path from 'node:path';
2
2
  import { AlpError } from './errors.js';
3
- import { MODELS } from './models.js';
3
+ import { EFFORTS, knownModel } from './models.js';
4
4
  import { validatePermissions } from './permissions.js';
5
5
  import { validateVerify } from './verify.js';
6
6
 
@@ -11,12 +11,12 @@ function requireValue(condition, code, source, message) {
11
11
  if (!condition) throw new AlpError(code, `${source}: ${message}`);
12
12
  }
13
13
 
14
- /** Efforts a profile may name; a model ALP knows takes only its own (src/core/models.js). */
15
- const EFFORTS = ['none', 'off', 'low', 'medium', 'high', 'xhigh', 'max', 'ultra', 'ultracode'];
16
14
  /** Top-level keys of a project's .alp/settings.json. */
17
15
  export const PROJECT_SETTINGS = ['$schema', 'defaultAgent', 'workflow', 'runtime', 'permissions', 'verify', 'delegation', 'team', 'profile', 'templateDefaults', 'compact', 'curate'];
18
16
  /** Top-level keys of the user's $ALP_HOME/settings.json. */
19
- export const USER_SETTINGS = ['$schema', 'language', 'permissions', 'limits', 'recovery', 'web', 'curate'];
17
+ export const USER_SETTINGS = ['$schema', 'language', 'permissions', 'limits', 'recovery', 'dashboard', 'web', 'curate'];
18
+ /** The settings of `alp dashboard`; before the rename (t-81b0.5) they lived under `web`, which still holds Paseo's relay. */
19
+ export const DASHBOARD_SETTINGS = Object.freeze(['enabled', 'port', 'permissions']);
20
20
  /**
21
21
  * Top-level keys ALP no longer reads, with what to use instead. They warn rather than
22
22
  * fail, so settings written for an older ALP keep working.
@@ -131,7 +131,8 @@ export function validateSettings(settings, source) {
131
131
  const [provider, model, effort] = entry.split(':');
132
132
  check(model !== '*' || (agent !== 'oracle' && agent !== 'main'), `${at}: ${agent} runs on a named model, not any model`);
133
133
  if (effort !== undefined) {
134
- const known = MODELS.find(candidate => candidate.runtime === provider && candidate.id === model);
134
+ // The live catalog when this process has one (knownModels), else MODELS; never beyond EFFORTS.
135
+ const known = knownModel(`${provider}:${model}`);
135
136
  check(EFFORTS.includes(effort), `${at}: effort ${effort} is unsupported`);
136
137
  check(!known?.efforts.length || known.efforts.includes(effort), `${at}: ${provider}:${model} takes effort ${known?.efforts.join(', ')}`);
137
138
  }
@@ -183,12 +184,22 @@ export function validateUserSettings(settings, source) {
183
184
  check(!extra, `unsupported ${key} field '${extra}'; use autoResume`);
184
185
  if (settings[key].autoResume !== undefined) check(typeof settings[key].autoResume === 'boolean', `${key}.autoResume must be true or false`);
185
186
  }
187
+ // `dashboard` holds alp dashboard's settings. `web` keeps Paseo's relay, and still accepts the
188
+ // dashboard settings written before the rename (alp dashboard moves them, then reads them from
189
+ // `dashboard` first and `web` second), so a file written for an older release stays valid.
190
+ for (const key of ['dashboard', 'web']) {
191
+ const section = settings[key];
192
+ if (section === undefined) continue;
193
+ check(object(section), `${key} must be an object`);
194
+ const allowed = key === 'web' ? [...DASHBOARD_SETTINGS, 'relay'] : DASHBOARD_SETTINGS;
195
+ const extra = Object.keys(section).find(field => !allowed.includes(field));
196
+ check(!extra, `unsupported ${key} field '${extra}'; use ${allowed.slice(0, -1).join(', ')} or ${allowed.at(-1)}`);
197
+ // Gateway permissions `alp dashboard` adds to its default grant; the service checks each name against the gateway's list.
198
+ if (section.permissions !== undefined) check(Array.isArray(section.permissions) && section.permissions.every(entry => typeof entry === 'string' && /^[a-z][a-z.]*$/.test(entry)), `${key}.permissions must be a list of permission names, such as files.read`);
199
+ if (section.enabled !== undefined) check(typeof section.enabled === 'boolean', `${key}.enabled must be true or false`);
200
+ if (section.port !== undefined) check(Number.isInteger(section.port) && section.port >= 1024 && section.port <= 65535, `${key}.port must be a port from 1024 to 65535`);
201
+ }
186
202
  if (settings.web !== undefined) {
187
- check(object(settings.web), 'web must be an object');
188
- const extra = Object.keys(settings.web).find(field => !['enabled', 'port', 'relay', 'permissions'].includes(field));
189
- check(!extra, `unsupported web field '${extra}'; use enabled, port, relay or permissions`);
190
- // Gateway permissions `alp web` adds to its default grant; alp-web checks each name against the gateway's list.
191
- if (settings.web.permissions !== undefined) check(Array.isArray(settings.web.permissions) && settings.web.permissions.every(entry => typeof entry === 'string' && /^[a-z][a-z.]*$/.test(entry)), 'web.permissions must be a list of permission names, such as files.read');
192
203
  // The relay that lets Paseo's app reach alpd from another device (ALPD §64).
193
204
  const relay = settings.web.relay;
194
205
  if (relay !== undefined) {
@@ -199,8 +210,6 @@ export function validateUserSettings(settings, source) {
199
210
  if (relay.endpoint !== undefined) check(typeof relay.endpoint === 'string' && /^[a-z0-9.-]+:\d{1,5}$/i.test(relay.endpoint), 'web.relay.endpoint must be host:port, such as relay.paseo.sh:443');
200
211
  if (relay.useTls !== undefined) check(typeof relay.useTls === 'boolean', 'web.relay.useTls must be true or false');
201
212
  }
202
- if (settings.web.enabled !== undefined) check(typeof settings.web.enabled === 'boolean', 'web.enabled must be true or false');
203
- if (settings.web.port !== undefined) check(Number.isInteger(settings.web.port) && settings.web.port >= 1024 && settings.web.port <= 65535, 'web.port must be a port from 1024 to 65535');
204
213
  }
205
214
  if (settings.language !== undefined) check(nonempty(settings.language) && settings.language.trim().length <= 40, 'language must be a language name of at most 40 characters, such as Vietnamese or English');
206
215
  validatePermissions(settings.permissions, source);