netlify 27.18.0 → 27.19.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.
@@ -0,0 +1,138 @@
1
+ import { promises as fs } from 'node:fs';
2
+ import path from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+ import { isCI } from 'ci-info';
5
+ import execa from '../execa.js';
6
+ import { AGENT_DIRECTORIES, LEFTOVER_DETAIL, describeSync, fetchSkillsManifestIfChanged, recordSync, resolveSkillsHost, syncSkills, } from './agent-skills.js';
7
+ import { readAgentSkillsState, updateAgentSkillsState } from './agent-skills-state.js';
8
+ export const AUTO_UPDATE_ENV = 'NETLIFY_SKILLS_AUTO_UPDATE';
9
+ export const REFRESH_INTERVAL_MS = 60 * 60_000;
10
+ const SKILL_PREFIX = 'netlify-';
11
+ const DISABLED_VALUES = new Set(['0', 'false', 'no', 'off']);
12
+ const CHANGED_ACTIONS = new Set(['added', 'updated', 'reset', 'renamed', 'removed']);
13
+ const WORKER_PATH = fileURLToPath(new URL('agent-skills-refresh-worker.js', import.meta.url));
14
+ const hasSkillFile = async (dir) => {
15
+ try {
16
+ return (await fs.stat(path.join(dir, 'SKILL.md'))).isFile();
17
+ }
18
+ catch {
19
+ return false;
20
+ }
21
+ };
22
+ /**
23
+ * Lists the skills directories, relative to `repositoryRoot`, that already hold a Netlify skill.
24
+ * A background refresh only writes to these, so it never adds skills to a project, or to an agent
25
+ * directory, that has none.
26
+ */
27
+ export const installedSkillsDirectories = async (repositoryRoot, knownSkills = []) => {
28
+ const known = new Set(knownSkills);
29
+ const found = [];
30
+ for (const agentDirectory of AGENT_DIRECTORIES) {
31
+ const directory = path.join(agentDirectory, 'skills');
32
+ let names;
33
+ try {
34
+ names = await fs.readdir(path.join(repositoryRoot, directory));
35
+ }
36
+ catch {
37
+ continue;
38
+ }
39
+ for (const name of names) {
40
+ const candidate = known.has(name) || name.startsWith(SKILL_PREFIX);
41
+ if (candidate && (await hasSkillFile(path.join(repositoryRoot, directory, name)))) {
42
+ found.push(directory);
43
+ break;
44
+ }
45
+ }
46
+ }
47
+ return found;
48
+ };
49
+ const isDisabled = (env) => DISABLED_VALUES.has(env[AUTO_UPDATE_ENV]?.trim().toLowerCase() ?? '');
50
+ const isDue = (checkedAt, now) => checkedAt === undefined || now < checkedAt || now - checkedAt >= REFRESH_INTERVAL_MS;
51
+ const spawnRefreshWorker = (repositoryRoot) => {
52
+ const child = execa(process.execPath, [WORKER_PATH, repositoryRoot], { detached: true, stdio: 'ignore' });
53
+ child.catch(() => undefined);
54
+ child.unref();
55
+ };
56
+ /**
57
+ * Starts a background refresh of the project's Netlify skills when one is due, and returns whether
58
+ * it did. Only local files are read here. The manifest request and any downloads happen in a
59
+ * detached process, so the calling command never waits for them.
60
+ */
61
+ export const startAgentSkillsRefresh = async ({ repositoryRoot, env = process.env, now = Date.now(), ci = isCI, spawn = spawnRefreshWorker, }) => {
62
+ if (ci || isDisabled(env)) {
63
+ return false;
64
+ }
65
+ const state = await readAgentSkillsState(repositoryRoot);
66
+ if (!isDue(state.checkedAt, now)) {
67
+ return false;
68
+ }
69
+ if ((await installedSkillsDirectories(repositoryRoot, state.knownSkills)).length === 0) {
70
+ return false;
71
+ }
72
+ // Claiming the slot before spawning keeps commands started at the same time from each spawning one.
73
+ await updateAgentSkillsState(repositoryRoot, (current) => ({ ...current, checkedAt: now }));
74
+ spawn(repositoryRoot);
75
+ return true;
76
+ };
77
+ const isChange = ({ action, detail }) => CHANGED_ACTIONS.has(action) && detail !== LEFTOVER_DETAIL;
78
+ /**
79
+ * Runs in the detached process. When the manifest changed since the last sync, brings every
80
+ * directory that already holds Netlify skills up to date and saves what changed for the next
81
+ * command to show. A skill missing from a directory is added unless the project has had it
82
+ * installed before, so skills someone deleted stay deleted.
83
+ */
84
+ export const refreshAgentSkills = async ({ repositoryRoot, env = process.env, }) => {
85
+ const state = await readAgentSkillsState(repositoryRoot);
86
+ const directories = await installedSkillsDirectories(repositoryRoot, state.knownSkills);
87
+ if (directories.length === 0) {
88
+ return [];
89
+ }
90
+ const host = resolveSkillsHost(env);
91
+ const fetched = await fetchSkillsManifestIfChanged(host, { etag: state.etag, trigger: 'refresh' });
92
+ if (!fetched) {
93
+ return [];
94
+ }
95
+ const { manifest, etag } = fetched;
96
+ const known = new Set(state.knownSkills);
97
+ const isNew = (skill) => ![skill.name, ...(skill.prior_names ?? [])].some((name) => known.has(name));
98
+ const results = [];
99
+ for (const directory of directories) {
100
+ const { actions } = await syncSkills({
101
+ host,
102
+ directory: path.join(repositoryRoot, directory),
103
+ manifest,
104
+ shouldAdd: isNew,
105
+ trigger: 'refresh',
106
+ });
107
+ results.push({ directory, actions });
108
+ }
109
+ const failed = results.some(({ actions }) => actions.some(({ action }) => action === 'failed'));
110
+ const changes = results
111
+ .map(({ directory, actions }) => ({ directory, actions: actions.filter(isChange) }))
112
+ .filter(({ actions }) => actions.length > 0);
113
+ await recordSync(repositoryRoot, {
114
+ manifest,
115
+ directories: directories.map((directory) => path.join(repositoryRoot, directory)),
116
+ etag: failed ? null : etag,
117
+ notice: changes,
118
+ });
119
+ return changes;
120
+ };
121
+ /** Shows what earlier background refreshes changed, once, and returns the lines it wrote. */
122
+ export const showAgentSkillsRefreshNotice = async ({ repositoryRoot, write = (line) => process.stderr.write(`${line}\n`), }) => {
123
+ const { notice } = await readAgentSkillsState(repositoryRoot);
124
+ if (!notice?.length) {
125
+ return [];
126
+ }
127
+ await updateAgentSkillsState(repositoryRoot, (current) => {
128
+ const next = { ...current };
129
+ delete next.notice;
130
+ return next;
131
+ });
132
+ const lines = notice.map((result) => describeSync(result));
133
+ for (const line of lines) {
134
+ write(line);
135
+ }
136
+ return lines;
137
+ };
138
+ //# sourceMappingURL=agent-skills-refresh.js.map
@@ -0,0 +1,16 @@
1
+ import type { SkillsSyncResult } from './agent-skills.js';
2
+ export declare const AGENT_SKILLS_STATE_FILE: string;
3
+ export interface AgentSkillsState {
4
+ /** When a refresh was last started, in milliseconds since the epoch. */
5
+ checkedAt?: number;
6
+ /** ETag of the last manifest that was synced without failures. */
7
+ etag?: string;
8
+ /** Every skill name the project has been offered, so a skill someone deleted is not added back. */
9
+ knownSkills?: string[];
10
+ /** Changes made by a background refresh that have not been shown yet. */
11
+ notice?: SkillsSyncResult[];
12
+ }
13
+ export declare const readAgentSkillsState: (repositoryRoot: string) => Promise<AgentSkillsState>;
14
+ /** Applies `update` to the stored state and writes the result atomically. */
15
+ export declare const updateAgentSkillsState: (repositoryRoot: string, update: (state: AgentSkillsState) => AgentSkillsState) => Promise<void>;
16
+ //# sourceMappingURL=agent-skills-state.d.ts.map
@@ -0,0 +1,42 @@
1
+ import { randomBytes } from 'node:crypto';
2
+ import { promises as fs } from 'node:fs';
3
+ import path from 'node:path';
4
+ export const AGENT_SKILLS_STATE_FILE = path.join('.netlify', 'agent-skills.json');
5
+ const isStringArray = (value) => Array.isArray(value) && value.every((item) => typeof item === 'string');
6
+ const parseState = (raw) => {
7
+ const parsed = JSON.parse(raw);
8
+ if (typeof parsed !== 'object' || parsed === null) {
9
+ return {};
10
+ }
11
+ const { checkedAt, etag, knownSkills, notice } = parsed;
12
+ return {
13
+ ...(typeof checkedAt === 'number' ? { checkedAt } : {}),
14
+ ...(typeof etag === 'string' ? { etag } : {}),
15
+ ...(isStringArray(knownSkills) ? { knownSkills } : {}),
16
+ ...(Array.isArray(notice) ? { notice: notice } : {}),
17
+ };
18
+ };
19
+ export const readAgentSkillsState = async (repositoryRoot) => {
20
+ try {
21
+ return parseState(await fs.readFile(path.join(repositoryRoot, AGENT_SKILLS_STATE_FILE), 'utf8'));
22
+ }
23
+ catch {
24
+ return {};
25
+ }
26
+ };
27
+ /** Applies `update` to the stored state and writes the result atomically. */
28
+ export const updateAgentSkillsState = async (repositoryRoot, update) => {
29
+ const file = path.join(repositoryRoot, AGENT_SKILLS_STATE_FILE);
30
+ const next = update(await readAgentSkillsState(repositoryRoot));
31
+ await fs.mkdir(path.dirname(file), { recursive: true });
32
+ const temporary = `${file}.${process.pid.toString()}-${randomBytes(4).toString('hex')}`;
33
+ await fs.writeFile(temporary, `${JSON.stringify(next, null, 2)}\n`);
34
+ try {
35
+ await fs.rename(temporary, file);
36
+ }
37
+ catch (error) {
38
+ await fs.rm(temporary, { force: true });
39
+ throw error;
40
+ }
41
+ };
42
+ //# sourceMappingURL=agent-skills-state.js.map
@@ -1,6 +1,8 @@
1
1
  export declare const DEFAULT_SKILLS_HOST = "https://netlify-agent-skills.netlify.app";
2
2
  export declare const SKILLS_HOST_ENV = "NETLIFY_SKILLS_HOST";
3
3
  export declare const DEFAULT_SKILLS_DIRECTORY: string;
4
+ export declare const AGENT_DIRECTORIES: readonly ['.claude', '.agents', '.grok'];
5
+ export declare const LEFTOVER_DETAIL = "leftover from an interrupted install";
4
6
  export interface SkillHistoryEntry {
5
7
  version: string | null;
6
8
  name?: string;
@@ -68,19 +70,56 @@ export interface SkillsSyncResult {
68
70
  actions: SkillActionRecord[];
69
71
  }
70
72
  export declare const resolveSkillsHost: (env?: NodeJS.ProcessEnv) => string;
73
+ /**
74
+ * What started a sync. It is sent in the user agent, so the skills host can tell syncs people ran
75
+ * from automatic ones.
76
+ */
77
+ export type SkillsTrigger = 'init' | 'refresh';
78
+ export interface FetchedManifest {
79
+ manifest: SkillsManifest;
80
+ etag: string | null;
81
+ }
82
+ /**
83
+ * Fetches the manifest, sending `etag` as `If-None-Match` when given. Returns null when the
84
+ * host answers 304, meaning the manifest is unchanged since the response that carried `etag`.
85
+ */
86
+ export declare const fetchSkillsManifestIfChanged: (host: string, { etag, trigger }?: {
87
+ etag?: string;
88
+ trigger?: SkillsTrigger;
89
+ }) => Promise<FetchedManifest | null>;
71
90
  export declare const fetchSkillsManifest: (host: string) => Promise<SkillsManifest>;
72
91
  export declare const hashSkillTree: (dir: string, declaredExecutable?: Set<string>) => Promise<string>;
73
92
  export declare const classifySkillsDirectory: (root: string, manifest: SkillsManifest) => Promise<SkillsClassification>;
74
- export declare const installSkill: (host: string, dest: string, skill: ManifestSkill, { force }?: {
93
+ export declare const installSkill: (host: string, dest: string, skill: ManifestSkill, { force, trigger }?: {
75
94
  force?: boolean;
95
+ trigger?: SkillsTrigger;
76
96
  }) => Promise<number>;
77
- export declare const syncSkills: ({ host, directory, manifest, reset, }: {
97
+ /**
98
+ * Brings `directory` in line with `manifest`. `shouldAdd` decides which active skills absent from
99
+ * the directory get installed; by default all of them are.
100
+ */
101
+ export declare const syncSkills: ({ host, directory, manifest, reset, shouldAdd, trigger, }: {
78
102
  host: string;
79
103
  directory: string;
80
104
  manifest: SkillsManifest;
81
105
  reset?: boolean;
106
+ shouldAdd?: (skill: ManifestSkill) => boolean;
107
+ trigger?: SkillsTrigger;
82
108
  }) => Promise<SkillsSyncResult>;
83
109
  export declare const resolveSkillsDirectories: (workingDir: string, env?: NodeJS.ProcessEnv) => Promise<string[]>;
110
+ export declare const describeSync: ({ directory, actions }: SkillsSyncResult) => string;
111
+ /**
112
+ * Records a finished sync in the project's skills state, so a background refresh compares against
113
+ * it. A skill joins the known skills only once it is installed in every one of `directories`, so a
114
+ * later refresh still adds one that is missing anywhere. A null `etag` makes the next refresh
115
+ * download the manifest again. Never throws.
116
+ */
117
+ export declare const recordSync: (repositoryRoot: string, { manifest, directories, etag, notice, }: {
118
+ manifest: SkillsManifest;
119
+ directories: string[];
120
+ etag: string | null;
121
+ notice?: SkillsSyncResult[];
122
+ }) => Promise<void>;
84
123
  export interface AgentSkillsSetupSummary {
85
124
  installed: boolean;
86
125
  directories: string[];
@@ -3,10 +3,11 @@ import { promises as fs } from 'node:fs';
3
3
  import path from 'node:path';
4
4
  import { getDrivingAgent } from '../agent-detection.js';
5
5
  import { chalk, log, netlifyCommand, version, warn } from '../command-helpers.js';
6
+ import { updateAgentSkillsState } from './agent-skills-state.js';
6
7
  export const DEFAULT_SKILLS_HOST = 'https://netlify-agent-skills.netlify.app';
7
8
  export const SKILLS_HOST_ENV = 'NETLIFY_SKILLS_HOST';
8
9
  export const DEFAULT_SKILLS_DIRECTORY = path.join('.agents', 'skills');
9
- const AGENT_DIRECTORIES = ['.claude', '.agents', '.grok'];
10
+ export const AGENT_DIRECTORIES = ['.claude', '.agents', '.grok'];
10
11
  const AGENT_DIRECTORY_BY_DRIVING_AGENT = {
11
12
  claude: '.claude',
12
13
  };
@@ -18,6 +19,7 @@ const RETIRED_LEFTOVER = /^(.+)\.old-\d+-[0-9a-f]{12}$/;
18
19
  const FETCH_TIMEOUT_MS = 10_000;
19
20
  const LEFTOVER_MIN_AGE_MS = 10 * 60_000;
20
21
  const LOOPBACK_HOSTS = new Set(['localhost', '127.0.0.1', '[::1]']);
22
+ export const LEFTOVER_DETAIL = 'leftover from an interrupted install';
21
23
  class SkillsError extends Error {
22
24
  }
23
25
  class SkillConflictError extends SkillsError {
@@ -45,12 +47,13 @@ export const resolveSkillsHost = (env = process.env) => {
45
47
  return url.toString().replace(/\/$/, '');
46
48
  };
47
49
  const urlFor = (host, ...parts) => `${host}/${parts.map((part) => encodeURIComponent(part)).join('/')}`;
48
- const fetchBytes = async (url) => {
49
- const response = await fetch(url, {
50
- headers: { 'user-agent': `NetlifyCLI ${version}` },
51
- signal: AbortSignal.timeout(FETCH_TIMEOUT_MS),
52
- redirect: 'error',
53
- });
50
+ const request = (url, { trigger, headers = {} } = {}) => fetch(url, {
51
+ headers: { 'user-agent': trigger ? `NetlifyCLI ${version} (${trigger})` : `NetlifyCLI ${version}`, ...headers },
52
+ signal: AbortSignal.timeout(FETCH_TIMEOUT_MS),
53
+ redirect: 'error',
54
+ });
55
+ const fetchBytes = async (url, trigger) => {
56
+ const response = await request(url, { trigger });
54
57
  if (!response.ok) {
55
58
  throw new SkillsError(`${url}: HTTP ${response.status.toString()}`);
56
59
  }
@@ -96,12 +99,22 @@ const indexManifest = (manifest) => {
96
99
  return { exact, prior };
97
100
  };
98
101
  const skillUnderName = ({ exact, prior }, name) => exact.get(name) ?? prior.get(name);
99
- export const fetchSkillsManifest = async (host) => {
102
+ /**
103
+ * Fetches the manifest, sending `etag` as `If-None-Match` when given. Returns null when the
104
+ * host answers 304, meaning the manifest is unchanged since the response that carried `etag`.
105
+ */
106
+ export const fetchSkillsManifestIfChanged = async (host, { etag, trigger } = {}) => {
100
107
  const url = urlFor(host, 'manifest.json');
101
- const bytes = await fetchBytes(url);
108
+ const response = await request(url, { trigger, headers: etag ? { 'if-none-match': etag } : {} });
109
+ if (response.status === 304 && etag) {
110
+ return null;
111
+ }
112
+ if (!response.ok) {
113
+ throw new SkillsError(`${url}: HTTP ${response.status.toString()}`);
114
+ }
102
115
  let manifest;
103
116
  try {
104
- manifest = JSON.parse(Buffer.from(bytes).toString('utf8'));
117
+ manifest = JSON.parse(await response.text());
105
118
  }
106
119
  catch {
107
120
  throw new SkillsError(`${url}: invalid JSON`);
@@ -110,8 +123,16 @@ export const fetchSkillsManifest = async (host) => {
110
123
  throw new SkillsError(`${url}: manifest schema ${String(manifest.schema_version)} is not supported by this CLI version; update the Netlify CLI`);
111
124
  }
112
125
  indexManifest(manifest);
113
- return manifest;
126
+ return { manifest, etag: response.headers.get('etag') };
127
+ };
128
+ const fetchLatestManifest = async (host, trigger) => {
129
+ const fetched = await fetchSkillsManifestIfChanged(host, { trigger });
130
+ if (!fetched) {
131
+ throw new SkillsError(`${urlFor(host, 'manifest.json')}: no manifest in the response`);
132
+ }
133
+ return fetched;
114
134
  };
135
+ export const fetchSkillsManifest = async (host) => (await fetchLatestManifest(host)).manifest;
115
136
  const historyOf = (skill) => {
116
137
  if (Array.isArray(skill.history) && skill.history.length > 0) {
117
138
  return skill.history;
@@ -315,7 +336,7 @@ const isReplaceableCopy = async (target, skill) => {
315
336
  }
316
337
  return isUneditedRelease(target, skill);
317
338
  };
318
- const downloadSkill = async (host, skill) => {
339
+ const downloadSkill = async (host, skill, trigger) => {
319
340
  const downloaded = [];
320
341
  for (const file of Object.keys(skill.files ?? {}).sort()) {
321
342
  if (!isSafeFilePath(file)) {
@@ -323,7 +344,7 @@ const downloadSkill = async (host, skill) => {
323
344
  }
324
345
  let bytes;
325
346
  try {
326
- bytes = await fetchBytes(urlFor(host, 'skills', skill.name, ...file.split('/')));
347
+ bytes = await fetchBytes(urlFor(host, 'skills', skill.name, ...file.split('/')), trigger);
327
348
  }
328
349
  catch (error) {
329
350
  throw new SkillsError(`${skill.name}/${file}: ${errorMessage(error)}`);
@@ -335,8 +356,8 @@ const downloadSkill = async (host, skill) => {
335
356
  }
336
357
  return downloaded;
337
358
  };
338
- export const installSkill = async (host, dest, skill, { force = false } = {}) => {
339
- const downloaded = await downloadSkill(host, skill);
359
+ export const installSkill = async (host, dest, skill, { force = false, trigger } = {}) => {
360
+ const downloaded = await downloadSkill(host, skill, trigger);
340
361
  const target = path.join(dest, skill.name);
341
362
  if (!force && !(await isReplaceableCopy(target, skill))) {
342
363
  throw new SkillConflictError(`${target} already exists and is not an unedited Netlify skill; left in place`);
@@ -398,7 +419,11 @@ const removeInstallLeftovers = async (root, index) => {
398
419
  }
399
420
  return removed;
400
421
  };
401
- export const syncSkills = async ({ host, directory, manifest, reset = false, }) => {
422
+ /**
423
+ * Brings `directory` in line with `manifest`. `shouldAdd` decides which active skills absent from
424
+ * the directory get installed; by default all of them are.
425
+ */
426
+ export const syncSkills = async ({ host, directory, manifest, reset = false, shouldAdd = () => true, trigger, }) => {
402
427
  const index = indexManifest(manifest);
403
428
  const actions = [];
404
429
  const act = (name, action, detail) => {
@@ -429,7 +454,7 @@ export const syncSkills = async ({ host, directory, manifest, reset = false, })
429
454
  return undefined;
430
455
  };
431
456
  for (const leftover of await removeInstallLeftovers(directory, index)) {
432
- act(leftover, 'removed', 'leftover from an interrupted install');
457
+ act(leftover, 'removed', LEFTOVER_DETAIL);
433
458
  }
434
459
  const before = await classifySkillsDirectory(directory, manifest);
435
460
  const installed = new Set();
@@ -444,7 +469,7 @@ export const syncSkills = async ({ host, directory, manifest, reset = false, })
444
469
  return false;
445
470
  }
446
471
  try {
447
- await installSkill(host, directory, skill, options);
472
+ await installSkill(host, directory, skill, { ...options, trigger });
448
473
  installed.add(skill.name);
449
474
  return true;
450
475
  }
@@ -553,6 +578,8 @@ export const syncSkills = async ({ host, directory, manifest, reset = false, })
553
578
  if (installed.has(name))
554
579
  continue;
555
580
  const skill = skillByName(name);
581
+ if (!shouldAdd(skill))
582
+ continue;
556
583
  if (await install(skill)) {
557
584
  act(name, 'added', skill.version ?? undefined);
558
585
  }
@@ -590,7 +617,7 @@ const summarize = (actions) => {
590
617
  }
591
618
  return summary;
592
619
  };
593
- const describeSync = ({ directory, actions }) => {
620
+ export const describeSync = ({ directory, actions }) => {
594
621
  const summary = summarize(actions);
595
622
  const location = chalk.underline(directory);
596
623
  const changed = summary.added + summary.updated + summary.reset + summary.renamed + summary.removed;
@@ -624,19 +651,75 @@ const logSync = (directory, result, reset) => {
624
651
  log(` Run ${chalk.cyanBright.bold(`${netlifyCommand()} init --reset-context`)} to replace edited Netlify skills with the latest release.`);
625
652
  }
626
653
  };
654
+ const skillsInEveryDirectory = async (directories, manifest) => {
655
+ if (directories.length === 0) {
656
+ return [];
657
+ }
658
+ const missing = new Set();
659
+ for (const directory of directories) {
660
+ for (const name of (await classifySkillsDirectory(directory, manifest)).missing) {
661
+ missing.add(name);
662
+ }
663
+ }
664
+ return manifest.skills
665
+ .filter((skill) => skill.status === 'active' && !missing.has(skill.name))
666
+ .flatMap((skill) => [skill.name, ...(skill.prior_names ?? [])]);
667
+ };
668
+ /**
669
+ * Records a finished sync in the project's skills state, so a background refresh compares against
670
+ * it. A skill joins the known skills only once it is installed in every one of `directories`, so a
671
+ * later refresh still adds one that is missing anywhere. A null `etag` makes the next refresh
672
+ * download the manifest again. Never throws.
673
+ */
674
+ export const recordSync = async (repositoryRoot, { manifest, directories, etag, notice = [], }) => {
675
+ try {
676
+ const installed = await skillsInEveryDirectory(directories, manifest);
677
+ await updateAgentSkillsState(repositoryRoot, (state) => {
678
+ const next = {
679
+ ...state,
680
+ checkedAt: Date.now(),
681
+ knownSkills: [...new Set([...(state.knownSkills ?? []), ...installed])].sort(),
682
+ };
683
+ if (etag) {
684
+ next.etag = etag;
685
+ }
686
+ else {
687
+ delete next.etag;
688
+ }
689
+ if (notice.length > 0) {
690
+ next.notice = [...(state.notice ?? []), ...notice];
691
+ }
692
+ return next;
693
+ });
694
+ }
695
+ catch {
696
+ // A missing record only means the next refresh downloads the manifest again.
697
+ }
698
+ };
627
699
  export const setupAgentSkills = async ({ workingDir, env = process.env, reset = false, }) => {
628
700
  let directories = [];
629
701
  try {
630
702
  directories = await resolveSkillsDirectories(workingDir, env);
631
703
  const host = resolveSkillsHost(env);
632
- const manifest = await fetchSkillsManifest(host);
704
+ const { manifest, etag } = await fetchLatestManifest(host, 'init');
633
705
  const actions = [];
634
706
  for (const directory of directories) {
635
- const result = await syncSkills({ host, directory: path.resolve(workingDir, directory), manifest, reset });
707
+ const result = await syncSkills({
708
+ host,
709
+ directory: path.resolve(workingDir, directory),
710
+ manifest,
711
+ reset,
712
+ trigger: 'init',
713
+ });
636
714
  actions.push(...result.actions);
637
715
  logSync(directory, result, reset);
638
716
  }
639
717
  const summary = summarize(actions);
718
+ await recordSync(workingDir, {
719
+ manifest,
720
+ directories: directories.map((directory) => path.resolve(workingDir, directory)),
721
+ etag: summary.failed === 0 ? etag : null,
722
+ });
640
723
  return {
641
724
  installed: summary.current + summary.added + summary.updated + summary.reset + summary.renamed + summary.kept > 0,
642
725
  directories,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "netlify",
3
- "version": "27.18.0",
3
+ "version": "27.19.0",
4
4
  "description": "Netlify command line tool",
5
5
  "keywords": [
6
6
  "api",
@@ -111,6 +111,7 @@
111
111
  "is-stream": "^4.0.1",
112
112
  "is-wsl": "^3.1.0",
113
113
  "isexe": "^4.0.0",
114
+ "jsonc-parser": "^3.3.1",
114
115
  "jsonwebtoken": "^9.0.3",
115
116
  "jwt-decode": "^4.0.0",
116
117
  "lambda-local": "^2.2.0",