@netlify/agent-runner-cli 2.17.0-PAW-612.0 → 2.18.0

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.
@@ -1,4 +1,5 @@
1
- import { appendFile, cp, mkdir, readdir, readFile, rm } from 'node:fs/promises'
1
+ import { existsSync } from 'node:fs'
2
+ import { cp, mkdir, readdir, readFile, rm, writeFile } from 'node:fs/promises'
2
3
  import { createRequire } from 'node:module'
3
4
  import path from 'node:path'
4
5
  import process from 'node:process'
@@ -8,34 +9,55 @@ const localSkillsDir = new URL('../src/skills/', import.meta.url)
8
9
  const sharedPackagePath = createRequire(import.meta.url).resolve('@netlify/skills/package.json')
9
10
  const sharedSkillsDir = path.join(path.dirname(sharedPackagePath), 'skills')
10
11
  export const bundledSkillsDir = fileURLToPath(new URL('../dist/skills/', import.meta.url))
11
- const selectedSharedSkills = [
12
- { name: 'netlify-access-control' },
13
- {
14
- name: 'netlify-forms',
15
- instructions: new URL('../src/skill-instructions/netlify-forms.md', import.meta.url),
16
- assets: new URL('../src/skill-assets/netlify-forms/', import.meta.url),
17
- },
18
- {
19
- name: 'netlify-image-cdn',
20
- instructions: new URL('../src/skill-instructions/netlify-image-cdn.md', import.meta.url),
21
- },
22
- ]
12
+ const skillOverridesDir = fileURLToPath(new URL('../src/skill-overrides/', import.meta.url))
13
+ export const selectedSharedSkills = ['netlify-access-control', 'netlify-forms', 'netlify-image-cdn', 'netlify-identity']
14
+
15
+ const readOptionalFile = async (filePath) => {
16
+ try {
17
+ return await readFile(filePath, 'utf8')
18
+ } catch (error) {
19
+ if (error.code === 'ENOENT') return undefined
20
+ throw error
21
+ }
22
+ }
23
+
24
+ export const applySkillReplacements = (content, replacements) => {
25
+ let result = content
26
+ for (const { from, to } of replacements) {
27
+ if (!from || result.split(from).length !== 2) {
28
+ throw new Error(`Expected exactly one occurrence of shared skill text: ${JSON.stringify(from)}`)
29
+ }
30
+ result = result.replace(from, () => to)
31
+ }
32
+ return result
33
+ }
23
34
 
24
35
  export const buildSkills = async (targetDir = bundledSkillsDir) => {
25
36
  await rm(targetDir, { recursive: true, force: true })
26
37
  await cp(localSkillsDir, targetDir, { recursive: true })
27
38
 
28
- for (const { name, instructions, assets } of selectedSharedSkills) {
39
+ for (const name of selectedSharedSkills) {
29
40
  await cp(path.join(sharedSkillsDir, name), path.join(targetDir, name), {
30
41
  recursive: true,
31
42
  force: false,
32
43
  errorOnExist: true,
33
44
  })
34
- if (instructions) {
35
- await appendFile(path.join(targetDir, name, 'SKILL.md'), `\n\n${await readFile(instructions, 'utf8')}`)
45
+ const overrideDir = path.join(skillOverridesDir, name)
46
+ const replacements = await readOptionalFile(path.join(overrideDir, 'replacements.json'))
47
+ const instructions = await readOptionalFile(path.join(overrideDir, 'instructions.md'))
48
+ if (instructions !== undefined || replacements !== undefined) {
49
+ const skillPath = path.join(targetDir, name, 'SKILL.md')
50
+ let content = await readFile(skillPath, 'utf8')
51
+ if (replacements !== undefined) {
52
+ content = applySkillReplacements(content, JSON.parse(replacements))
53
+ }
54
+ if (instructions !== undefined) {
55
+ content += `\n\n${instructions}`
56
+ }
57
+ await writeFile(skillPath, content)
36
58
  }
37
- if (assets) {
38
- const assetsDir = fileURLToPath(assets)
59
+ const assetsDir = path.join(overrideDir, 'assets')
60
+ if (existsSync(assetsDir)) {
39
61
  for (const entry of await readdir(assetsDir, { recursive: true, withFileTypes: true })) {
40
62
  if (!entry.isFile()) continue
41
63
  const source = path.join(entry.parentPath, entry.name)