netlify 27.17.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.
- package/dist/commands/base-command.d.ts +1 -1
- package/dist/commands/base-command.js +33 -4
- package/dist/commands/deploy/deploy.js +9 -0
- package/dist/commands/init/index.js +14 -1
- package/dist/commands/init/init.d.ts +5 -1
- package/dist/commands/init/init.js +49 -7
- package/dist/commands/login/index.js +3 -1
- package/dist/commands/login/login-check.js +1 -1
- package/dist/commands/login/login.js +8 -0
- package/dist/commands/logout/logout.js +1 -1
- package/dist/commands/logs/index.js +2 -7
- package/dist/commands/logs/log-api.d.ts +5 -2
- package/dist/commands/logs/log-api.js +7 -4
- package/dist/commands/logs/logs.d.ts +2 -1
- package/dist/commands/logs/logs.js +39 -7
- package/dist/commands/logs/sources/server.d.ts +3 -1
- package/dist/commands/logs/sources/server.js +6 -2
- package/dist/commands/status/status.js +21 -2
- package/dist/lib/secure-storage.d.ts +8 -0
- package/dist/lib/secure-storage.js +98 -0
- package/dist/utils/agent-detection.js +1 -1
- package/dist/utils/command-helpers.d.ts +1 -1
- package/dist/utils/command-helpers.js +6 -7
- package/dist/utils/deploy/deploy-urls.d.ts +3 -0
- package/dist/utils/deploy/deploy-urls.js +12 -0
- package/dist/utils/init/agent-location.d.ts +6 -0
- package/dist/utils/init/agent-location.js +22 -0
- package/dist/utils/init/agent-mcp-config.d.ts +30 -0
- package/dist/utils/init/agent-mcp-config.js +206 -0
- package/dist/utils/init/agent-mcp.d.ts +57 -0
- package/dist/utils/init/agent-mcp.js +539 -0
- package/dist/utils/init/agent-skills-refresh-worker.d.ts +2 -0
- package/dist/utils/init/agent-skills-refresh-worker.js +17 -0
- package/dist/utils/init/agent-skills-refresh.d.ts +37 -0
- package/dist/utils/init/agent-skills-refresh.js +138 -0
- package/dist/utils/init/agent-skills-state.d.ts +16 -0
- package/dist/utils/init/agent-skills-state.js +42 -0
- package/dist/utils/init/agent-skills.d.ts +41 -2
- package/dist/utils/init/agent-skills.js +104 -21
- package/dist/utils/types.d.ts +5 -1
- package/package.json +5 -4
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import clean from 'clean-deep';
|
|
2
|
+
import { getLegacyConfigFilePath } from '@netlify/dev-utils';
|
|
2
3
|
import prettyjson from 'prettyjson';
|
|
3
4
|
import { chalk, logAndThrowError, exit, getToken, log, logJson, warn, } from '../../utils/command-helpers.js';
|
|
4
5
|
import { isInteractive } from '../../utils/scripted-commands.js';
|
|
@@ -7,10 +8,24 @@ export const STATUS_ERROR_CODES = {
|
|
|
7
8
|
NOT_LOGGED_IN: 'NOT_LOGGED_IN',
|
|
8
9
|
NOT_LINKED: 'NOT_LINKED',
|
|
9
10
|
};
|
|
11
|
+
const formatTokenStorage = (location) => {
|
|
12
|
+
switch (location) {
|
|
13
|
+
case 'keychain':
|
|
14
|
+
return "operating system's keychain";
|
|
15
|
+
case 'config':
|
|
16
|
+
return `plaintext config file (${getLegacyConfigFilePath()})`;
|
|
17
|
+
case 'env':
|
|
18
|
+
return 'NETLIFY_AUTH_TOKEN environment variable';
|
|
19
|
+
case 'flag':
|
|
20
|
+
return '--auth flag';
|
|
21
|
+
default:
|
|
22
|
+
return 'not stored';
|
|
23
|
+
}
|
|
24
|
+
};
|
|
10
25
|
export const status = async (options, command) => {
|
|
11
26
|
const { accounts, api, globalConfig, site, siteInfo } = command.netlify;
|
|
12
27
|
const currentUserId = globalConfig.get('userId');
|
|
13
|
-
const [accessToken] = await getToken();
|
|
28
|
+
const [accessToken, tokenLocation] = await getToken(options.auth);
|
|
14
29
|
if (!accessToken) {
|
|
15
30
|
if (options.json) {
|
|
16
31
|
logJson({
|
|
@@ -76,7 +91,7 @@ export const status = async (options, command) => {
|
|
|
76
91
|
// TODO(serhalp) `deep-clean` type declaration is invalid (this is obscured by `skipLibCheck`). Open a PR or use
|
|
77
92
|
// another lib.
|
|
78
93
|
clean(accountData);
|
|
79
|
-
log(prettyjson.render(cleanAccountData));
|
|
94
|
+
log(prettyjson.render({ ...cleanAccountData, 'Auth token storage': formatTokenStorage(tokenLocation) }));
|
|
80
95
|
if (!siteId) {
|
|
81
96
|
if (options.json) {
|
|
82
97
|
logJson({
|
|
@@ -97,6 +112,10 @@ export const status = async (options, command) => {
|
|
|
97
112
|
if (options.json) {
|
|
98
113
|
logJson({
|
|
99
114
|
account: cleanAccountData,
|
|
115
|
+
authTokenStorage: {
|
|
116
|
+
source: tokenLocation,
|
|
117
|
+
...(tokenLocation === 'config' ? { configPath: getLegacyConfigFilePath() } : {}),
|
|
118
|
+
},
|
|
100
119
|
siteData: {
|
|
101
120
|
'site-name': siteInfo.name,
|
|
102
121
|
'config-path': site.configPath,
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type TokenStorageMode = 'keychain' | 'legacy';
|
|
2
|
+
export declare const skipKeychainMigrationPrompt: () => void;
|
|
3
|
+
export declare const getStoredAPIToken: (env?: NodeJS.ProcessEnv) => Promise<{
|
|
4
|
+
token: string | undefined;
|
|
5
|
+
fromKeychain: boolean;
|
|
6
|
+
}>;
|
|
7
|
+
export declare const writeAuthTokenForStorage: (userId: string, accessToken: string, env?: NodeJS.ProcessEnv) => Promise<TokenStorageMode>;
|
|
8
|
+
//# sourceMappingURL=secure-storage.d.ts.map
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { confirm } from '@inquirer/prompts';
|
|
2
|
+
import { getGlobalConfigStore, getLegacyConfigFilePath, isLegacyAuthStorageForced, LEGACY_STORAGE_ENV_VAR, readStoredAPIToken, storeTokenInKeychain, } from '@netlify/dev-utils';
|
|
3
|
+
import { chalk, isLogSuppressed, log, warn } from '../utils/command-helpers.js';
|
|
4
|
+
import { isInteractive } from '../utils/scripted-commands.js';
|
|
5
|
+
import { reportError, track } from '../utils/telemetry/index.js';
|
|
6
|
+
let skipMigrationThisSession = false;
|
|
7
|
+
let keychainReadFailureWarned = false;
|
|
8
|
+
const skipMigrationKey = (userId) => `users.${userId}.auth.skipKeychainMigration`;
|
|
9
|
+
const trackStored = (mode, migrated, keychainFailed = false) => {
|
|
10
|
+
void track('user_authTokenStored', { mode, migrated, ...(keychainFailed ? { keychainFailed: true } : {}) });
|
|
11
|
+
};
|
|
12
|
+
const warnKeychainReadFailed = (error) => {
|
|
13
|
+
if (keychainReadFailureWarned)
|
|
14
|
+
return;
|
|
15
|
+
keychainReadFailureWarned = true;
|
|
16
|
+
warn(`Could not read your Netlify auth token from your keychain: ${error.message}
|
|
17
|
+
If your keychain is locked or access was denied, unlock it or allow access and try again, or run ${chalk.cyanBright('netlify login --new')}. In scripts, CI or agents, set ${chalk.cyanBright('NETLIFY_AUTH_TOKEN')} instead.`);
|
|
18
|
+
};
|
|
19
|
+
export const skipKeychainMigrationPrompt = () => {
|
|
20
|
+
skipMigrationThisSession = true;
|
|
21
|
+
};
|
|
22
|
+
const canUseKeychainInteractively = (env) => isInteractive() || env.TESTING_PROMPTS === 'true';
|
|
23
|
+
const isPromptExit = (error) => error instanceof Error && error.name === 'ExitPromptError';
|
|
24
|
+
const attemptMigration = async (token, env) => {
|
|
25
|
+
if (isLegacyAuthStorageForced(env) ||
|
|
26
|
+
!canUseKeychainInteractively(env) ||
|
|
27
|
+
skipMigrationThisSession ||
|
|
28
|
+
// --json and --silent hide the prompt's context lines but not the question itself
|
|
29
|
+
isLogSuppressed())
|
|
30
|
+
return false;
|
|
31
|
+
const globalConfig = await getGlobalConfigStore();
|
|
32
|
+
const userId = globalConfig.get('userId');
|
|
33
|
+
if (userId == null || globalConfig.get(skipMigrationKey(userId)) === true)
|
|
34
|
+
return false;
|
|
35
|
+
skipMigrationThisSession = true;
|
|
36
|
+
log();
|
|
37
|
+
log(`Your Netlify auth token is stored in plaintext at ${chalk.cyanBright(getLegacyConfigFilePath())}.`);
|
|
38
|
+
log(`The CLI can move it to your operating system's keychain, which is more secure. You may be asked to allow access.`);
|
|
39
|
+
log();
|
|
40
|
+
let confirmed;
|
|
41
|
+
try {
|
|
42
|
+
confirmed = await confirm({ message: 'Move the token to the keychain now?', default: true });
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
if (isPromptExit(error))
|
|
46
|
+
throw error;
|
|
47
|
+
void reportError(error, { severity: 'error' });
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
if (!confirmed) {
|
|
51
|
+
globalConfig.set(skipMigrationKey(userId), true);
|
|
52
|
+
log(chalk.dim(`The CLI won't ask again. To move it later, run ${chalk.cyanBright('netlify login --new')} in a terminal.`));
|
|
53
|
+
void track('user_authTokenMigrationDeclined', {});
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
const write = await storeTokenInKeychain(userId, token);
|
|
57
|
+
if (write.status === 'error') {
|
|
58
|
+
globalConfig.set(skipMigrationKey(userId), true);
|
|
59
|
+
warn(`Could not save your token to your keychain: ${write.error.message}
|
|
60
|
+
It stays in plaintext and the CLI won't ask again. To retry, unlock your keychain and run ${chalk.cyanBright('netlify login --new')}.`);
|
|
61
|
+
trackStored('legacy', false, true);
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
globalConfig.set(`users.${userId}.auth.token`, undefined);
|
|
65
|
+
log(chalk.green('Auth token moved to your keychain.'));
|
|
66
|
+
trackStored('keychain', true);
|
|
67
|
+
return true;
|
|
68
|
+
};
|
|
69
|
+
export const getStoredAPIToken = async (env = process.env) => {
|
|
70
|
+
const stored = await readStoredAPIToken(env);
|
|
71
|
+
switch (stored.source) {
|
|
72
|
+
case 'keychain':
|
|
73
|
+
return { token: stored.token, fromKeychain: true };
|
|
74
|
+
case 'config':
|
|
75
|
+
return { token: stored.token, fromKeychain: await attemptMigration(stored.token, env) };
|
|
76
|
+
case 'none':
|
|
77
|
+
if (stored.keychainError)
|
|
78
|
+
warnKeychainReadFailed(stored.keychainError);
|
|
79
|
+
return { token: undefined, fromKeychain: false };
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
// Non-interactive logins never touch the keychain, so they can't trigger an OS dialog nobody answers
|
|
83
|
+
export const writeAuthTokenForStorage = async (userId, accessToken, env = process.env) => {
|
|
84
|
+
if (isLegacyAuthStorageForced(env) || !canUseKeychainInteractively(env)) {
|
|
85
|
+
trackStored('legacy', false);
|
|
86
|
+
return 'legacy';
|
|
87
|
+
}
|
|
88
|
+
const write = await storeTokenInKeychain(userId, accessToken);
|
|
89
|
+
if (write.status === 'stored') {
|
|
90
|
+
trackStored('keychain', false);
|
|
91
|
+
return 'keychain';
|
|
92
|
+
}
|
|
93
|
+
warn(`Could not save your auth token to your keychain: ${write.error.message}
|
|
94
|
+
It was saved in plaintext at ${getLegacyConfigFilePath()} instead. To retry, unlock your keychain and run ${chalk.cyanBright('netlify login --new')}. To always use plaintext storage and hide this warning, set ${chalk.cyanBright(`${LEGACY_STORAGE_ENV_VAR}=1`)}.`);
|
|
95
|
+
trackStored('legacy', false, true);
|
|
96
|
+
return 'legacy';
|
|
97
|
+
};
|
|
98
|
+
//# sourceMappingURL=secure-storage.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Only markers an agent product sets on its own count as a signal; never infer from process names, terminals, or the process tree.
|
|
2
|
-
// The result is untrusted attribution from the environment
|
|
2
|
+
// The result is untrusted attribution from the environment. It may label telemetry or pick which agent's config to write, never authorize an action.
|
|
3
3
|
export const CANONICAL_AGENT_NAMES = [
|
|
4
4
|
'claude',
|
|
5
5
|
'codex',
|
|
@@ -43,7 +43,6 @@ export declare const pollForToken: ({ api, ticket, }: {
|
|
|
43
43
|
/**
|
|
44
44
|
* Get a netlify token
|
|
45
45
|
* @param {string} [tokenFromOptions] optional token from the provided --auth options
|
|
46
|
-
* @returns {Promise<[null|string, 'flag' | 'env' |'config' |'not found']>}
|
|
47
46
|
*/
|
|
48
47
|
export type TokenTuple = [string | null, TokenLocation];
|
|
49
48
|
export declare const getToken: (tokenFromOptions?: string) => Promise<TokenTuple>;
|
|
@@ -51,6 +50,7 @@ export declare const getToken: (tokenFromOptions?: string) => Promise<TokenTuple
|
|
|
51
50
|
* logs a json message
|
|
52
51
|
*/
|
|
53
52
|
export declare const logJson: (message?: unknown) => void;
|
|
53
|
+
export declare const isLogSuppressed: () => boolean;
|
|
54
54
|
export declare const log: (message?: string, ...args: string[]) => void;
|
|
55
55
|
export declare const logPadded: (message?: string, ...args: string[]) => void;
|
|
56
56
|
/**
|
|
@@ -2,10 +2,10 @@ import os from 'os';
|
|
|
2
2
|
import fs from 'fs';
|
|
3
3
|
import process from 'process';
|
|
4
4
|
import { format, inspect } from 'util';
|
|
5
|
-
import { getAPIToken } from '@netlify/dev-utils';
|
|
6
5
|
import { Chalk } from 'chalk';
|
|
7
6
|
import WSL from 'is-wsl';
|
|
8
7
|
import terminalLink from 'terminal-link';
|
|
8
|
+
import { getStoredAPIToken } from '../lib/secure-storage.js';
|
|
9
9
|
import { startSpinner } from '../lib/spinner.js';
|
|
10
10
|
import { getDrivingAgent } from './agent-detection.js';
|
|
11
11
|
import getCLIPackageJson from './get-cli-package-json.js';
|
|
@@ -104,10 +104,9 @@ export const getToken = async (tokenFromOptions) => {
|
|
|
104
104
|
if (NETLIFY_AUTH_TOKEN && NETLIFY_AUTH_TOKEN !== 'null') {
|
|
105
105
|
return [NETLIFY_AUTH_TOKEN, 'env'];
|
|
106
106
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
return [tokenFromConfig, 'config'];
|
|
107
|
+
const { token, fromKeychain } = await getStoredAPIToken();
|
|
108
|
+
if (token) {
|
|
109
|
+
return [token, fromKeychain ? 'keychain' : 'config'];
|
|
111
110
|
}
|
|
112
111
|
return [null, 'not found'];
|
|
113
112
|
};
|
|
@@ -122,9 +121,9 @@ export const logJson = (message = '') => {
|
|
|
122
121
|
process.stdout.write(JSON.stringify(message, null, 2));
|
|
123
122
|
}
|
|
124
123
|
};
|
|
124
|
+
export const isLogSuppressed = () => argv.includes('--json') || argv.includes('--silent') || isDefaultJson();
|
|
125
125
|
export const log = (message = '', ...args) => {
|
|
126
|
-
|
|
127
|
-
if (argv.includes('--json') || argv.includes('--silent') || isDefaultJson()) {
|
|
126
|
+
if (isLogSuppressed()) {
|
|
128
127
|
return;
|
|
129
128
|
}
|
|
130
129
|
message = typeof message === 'string' ? message : inspect(message);
|
|
@@ -4,6 +4,7 @@ export interface DeployUrls {
|
|
|
4
4
|
logsUrl: string;
|
|
5
5
|
functionLogsUrl: string;
|
|
6
6
|
edgeFunctionLogsUrl: string;
|
|
7
|
+
serverLogsUrl?: string | undefined;
|
|
7
8
|
}
|
|
8
9
|
interface DeployUrlFields {
|
|
9
10
|
id?: string;
|
|
@@ -12,6 +13,8 @@ interface DeployUrlFields {
|
|
|
12
13
|
deploy_ssl_url?: string;
|
|
13
14
|
deploy_url?: string;
|
|
14
15
|
admin_url?: string;
|
|
16
|
+
branch?: string;
|
|
17
|
+
server?: object | null;
|
|
15
18
|
}
|
|
16
19
|
export declare const getDeployUrls: (deploy: DeployUrlFields, { deployToProduction }: {
|
|
17
20
|
deployToProduction: boolean;
|
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
const getServerLogsUrl = (deploy, deployToProduction) => {
|
|
2
|
+
if (!deploy.server) {
|
|
3
|
+
return undefined;
|
|
4
|
+
}
|
|
5
|
+
const params = new URLSearchParams({ panel: 'logs' });
|
|
6
|
+
// Server logs are kept per branch, not per deploy.
|
|
7
|
+
if (!deployToProduction && deploy.branch) {
|
|
8
|
+
params.set('branch', deploy.branch);
|
|
9
|
+
}
|
|
10
|
+
return `${deploy.admin_url ?? ''}/server?${params.toString()}`;
|
|
11
|
+
};
|
|
1
12
|
export const getDeployUrls = (deploy, { deployToProduction }) => {
|
|
2
13
|
const functionLogsUrl = `${deploy.admin_url ?? ''}/logs/functions`;
|
|
3
14
|
const edgeFunctionLogsUrl = `${deploy.admin_url ?? ''}/logs/edge-functions`;
|
|
@@ -9,6 +20,7 @@ export const getDeployUrls = (deploy, { deployToProduction }) => {
|
|
|
9
20
|
edgeFunctionLogsUrl: deployToProduction
|
|
10
21
|
? edgeFunctionLogsUrl
|
|
11
22
|
: `${edgeFunctionLogsUrl}?scope=deployid:${deploy.id ?? ''}`,
|
|
23
|
+
serverLogsUrl: getServerLogsUrl(deploy, deployToProduction),
|
|
12
24
|
};
|
|
13
25
|
};
|
|
14
26
|
//# sourceMappingURL=deploy-urls.js.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { promises as fs } from 'node:fs';
|
|
2
|
+
import { homedir } from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
const realpathOrSelf = async (target) => {
|
|
5
|
+
try {
|
|
6
|
+
return await fs.realpath(target);
|
|
7
|
+
}
|
|
8
|
+
catch {
|
|
9
|
+
return path.resolve(target);
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
export const findProjectSetupBlocker = async (root, home = homedir()) => {
|
|
13
|
+
const resolvedRoot = await realpathOrSelf(root);
|
|
14
|
+
if (resolvedRoot === (await realpathOrSelf(home))) {
|
|
15
|
+
return { place: 'home', reason: 'this is your home directory, where they would apply to every project' };
|
|
16
|
+
}
|
|
17
|
+
if (resolvedRoot === path.parse(resolvedRoot).root) {
|
|
18
|
+
return { place: 'root', reason: 'this is the root of the file system' };
|
|
19
|
+
}
|
|
20
|
+
return undefined;
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=agent-location.js.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export type ConfigFormat = 'json' | 'toml';
|
|
2
|
+
export interface ProjectConfigFile {
|
|
3
|
+
path: string;
|
|
4
|
+
alternatives?: string[];
|
|
5
|
+
format: ConfigFormat;
|
|
6
|
+
key: string;
|
|
7
|
+
entry: Record<string, string | boolean>;
|
|
8
|
+
note?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface ConfigServer {
|
|
11
|
+
name: string;
|
|
12
|
+
target: string;
|
|
13
|
+
disabled: boolean;
|
|
14
|
+
}
|
|
15
|
+
export type ConfigRead = {
|
|
16
|
+
readable: true;
|
|
17
|
+
path: string;
|
|
18
|
+
content: string;
|
|
19
|
+
servers: ConfigServer[];
|
|
20
|
+
} | {
|
|
21
|
+
readable: false;
|
|
22
|
+
path: string;
|
|
23
|
+
reason: string;
|
|
24
|
+
};
|
|
25
|
+
export declare const readProjectConfig: (workingDir: string, file: ProjectConfigFile) => Promise<ConfigRead>;
|
|
26
|
+
export declare const addToProjectConfig: (workingDir: string, file: ProjectConfigFile, name: string, { path: resolved, content }: {
|
|
27
|
+
path: string;
|
|
28
|
+
content: string;
|
|
29
|
+
}) => Promise<boolean>;
|
|
30
|
+
//# sourceMappingURL=agent-mcp-config.d.ts.map
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { promises as fs } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { findNodeAtLocation, parse, parseTree } from 'jsonc-parser';
|
|
4
|
+
import toml from 'toml';
|
|
5
|
+
import writeFileAtomic from 'write-file-atomic';
|
|
6
|
+
import { fileExistsAsync } from '../../lib/fs.js';
|
|
7
|
+
const SERVER_FIELDS = new Set(['url', 'httpUrl', 'serverUrl', 'command']);
|
|
8
|
+
const isObject = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
9
|
+
const looksLikeServer = (value) => isObject(value) && Object.keys(value).some((field) => SERVER_FIELDS.has(field));
|
|
10
|
+
const stringLeaves = (value) => {
|
|
11
|
+
if (typeof value === 'string') {
|
|
12
|
+
return [value];
|
|
13
|
+
}
|
|
14
|
+
if (Array.isArray(value)) {
|
|
15
|
+
return value.flatMap(stringLeaves);
|
|
16
|
+
}
|
|
17
|
+
if (isObject(value)) {
|
|
18
|
+
return Object.values(value).flatMap(stringLeaves);
|
|
19
|
+
}
|
|
20
|
+
return [];
|
|
21
|
+
};
|
|
22
|
+
const serversIn = (map) => isObject(map)
|
|
23
|
+
? Object.entries(map).map(([name, value]) => ({
|
|
24
|
+
name,
|
|
25
|
+
target: stringLeaves(value).join(' '),
|
|
26
|
+
disabled: isObject(value) && (value.enabled === false || value.disabled === true),
|
|
27
|
+
}))
|
|
28
|
+
: [];
|
|
29
|
+
const readFileOrEmpty = async (file) => {
|
|
30
|
+
try {
|
|
31
|
+
return await fs.readFile(file, 'utf8');
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
if (error.code === 'ENOENT') {
|
|
35
|
+
return '';
|
|
36
|
+
}
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
const detectEol = (content) => (content.includes('\r\n') ? '\r\n' : '\n');
|
|
41
|
+
const detectIndent = (content) => /^([ \t]+)"/m.exec(content)?.[1] ?? ' ';
|
|
42
|
+
const parseJson = (content) => {
|
|
43
|
+
const errors = [];
|
|
44
|
+
const parsed = parse(content, errors, { allowTrailingComma: true });
|
|
45
|
+
return errors.length === 0 && isObject(parsed) ? parsed : undefined;
|
|
46
|
+
};
|
|
47
|
+
const readJson = (file, content, key) => {
|
|
48
|
+
if (content.trim() === '') {
|
|
49
|
+
return { readable: true, path: file, content, servers: [] };
|
|
50
|
+
}
|
|
51
|
+
const parsed = parseJson(content);
|
|
52
|
+
if (parsed === undefined) {
|
|
53
|
+
return { readable: false, path: file, reason: 'it is not valid JSON' };
|
|
54
|
+
}
|
|
55
|
+
const bare = !(key in parsed) && Object.values(parsed).some(looksLikeServer);
|
|
56
|
+
if (bare) {
|
|
57
|
+
return { readable: false, path: file, reason: `its servers are not under ${JSON.stringify(key)}` };
|
|
58
|
+
}
|
|
59
|
+
if (key in parsed && !isObject(parsed[key])) {
|
|
60
|
+
return { readable: false, path: file, reason: `its ${JSON.stringify(key)} is not an object` };
|
|
61
|
+
}
|
|
62
|
+
return { readable: true, path: file, content, servers: serversIn(parsed[key]) };
|
|
63
|
+
};
|
|
64
|
+
const parseToml = (content) => {
|
|
65
|
+
try {
|
|
66
|
+
const parsed = toml.parse(content);
|
|
67
|
+
return isObject(parsed) ? parsed : undefined;
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
return undefined;
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
const readToml = (file, content, key) => {
|
|
74
|
+
const parsed = parseToml(content);
|
|
75
|
+
if (parsed === undefined) {
|
|
76
|
+
return { readable: false, path: file, reason: 'it is not valid TOML' };
|
|
77
|
+
}
|
|
78
|
+
return { readable: true, path: file, content, servers: serversIn(parsed[key]) };
|
|
79
|
+
};
|
|
80
|
+
const existingCandidates = async (workingDir, file) => {
|
|
81
|
+
const present = [];
|
|
82
|
+
for (const candidate of [file.path, ...(file.alternatives ?? [])]) {
|
|
83
|
+
if (await fileExistsAsync(path.join(workingDir, candidate))) {
|
|
84
|
+
present.push(candidate);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return present;
|
|
88
|
+
};
|
|
89
|
+
const realpathOrSelf = async (target) => {
|
|
90
|
+
try {
|
|
91
|
+
return await fs.realpath(target);
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
return target;
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
const realpathThroughMissing = async (target) => {
|
|
98
|
+
const missing = [];
|
|
99
|
+
let existing = target;
|
|
100
|
+
while (!(await fileExistsAsync(existing))) {
|
|
101
|
+
const parent = path.dirname(existing);
|
|
102
|
+
if (parent === existing) {
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
missing.unshift(path.basename(existing));
|
|
106
|
+
existing = parent;
|
|
107
|
+
}
|
|
108
|
+
return path.join(await realpathOrSelf(existing), ...missing);
|
|
109
|
+
};
|
|
110
|
+
const insideProject = async (workingDir, file) => {
|
|
111
|
+
const root = await realpathOrSelf(workingDir);
|
|
112
|
+
const resolved = await realpathThroughMissing(path.join(workingDir, file));
|
|
113
|
+
return resolved.startsWith(`${root}${path.sep}`);
|
|
114
|
+
};
|
|
115
|
+
const readOne = (file, resolved, content) => file.format === 'toml' ? readToml(resolved, content, file.key) : readJson(resolved, content, file.key);
|
|
116
|
+
export const readProjectConfig = async (workingDir, file) => {
|
|
117
|
+
const present = await existingCandidates(workingDir, file);
|
|
118
|
+
const target = present[0] ?? file.path;
|
|
119
|
+
if (!(await insideProject(workingDir, target))) {
|
|
120
|
+
return { readable: false, path: target, reason: 'it points outside this project' };
|
|
121
|
+
}
|
|
122
|
+
const servers = [];
|
|
123
|
+
let first;
|
|
124
|
+
for (const candidate of present.length > 0 ? present : [target]) {
|
|
125
|
+
const content = await readFileOrEmpty(path.join(workingDir, candidate));
|
|
126
|
+
if (content === undefined) {
|
|
127
|
+
return { readable: false, path: candidate, reason: 'it could not be read' };
|
|
128
|
+
}
|
|
129
|
+
const read = readOne(file, candidate, content);
|
|
130
|
+
if (!read.readable) {
|
|
131
|
+
return read;
|
|
132
|
+
}
|
|
133
|
+
servers.push(...read.servers);
|
|
134
|
+
first ??= read.content;
|
|
135
|
+
}
|
|
136
|
+
return { readable: true, path: target, content: first ?? '', servers };
|
|
137
|
+
};
|
|
138
|
+
const tomlValue = (value) => typeof value === 'string' ? JSON.stringify(value) : String(value);
|
|
139
|
+
const objectDepth = (node) => {
|
|
140
|
+
let depth = 0;
|
|
141
|
+
for (let ancestor = node.parent; ancestor; ancestor = ancestor.parent) {
|
|
142
|
+
if (ancestor.type === 'object') {
|
|
143
|
+
depth += 1;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return depth;
|
|
147
|
+
};
|
|
148
|
+
const insertProperty = (content, object, name, value, eol, indent) => {
|
|
149
|
+
const depth = objectDepth(object) + 1;
|
|
150
|
+
const last = object.children?.at(-1);
|
|
151
|
+
const siblingPad = last === undefined ? undefined : /(?:^|\n|\r)([ \t]*)$/.exec(content.slice(0, last.offset))?.[1];
|
|
152
|
+
const pad = siblingPad ?? indent.repeat(depth);
|
|
153
|
+
const closing = object.offset + object.length - 1;
|
|
154
|
+
const property = `${JSON.stringify(name)}: ${JSON.stringify(value, null, indent).split('\n').join(`${eol}${pad}`)}`;
|
|
155
|
+
if (last === undefined) {
|
|
156
|
+
if (content.slice(object.offset + 1, closing).trim() !== '') {
|
|
157
|
+
return undefined;
|
|
158
|
+
}
|
|
159
|
+
return `${content.slice(0, object.offset + 1)}${eol}${pad}${property}${eol}${indent.repeat(depth - 1)}${content.slice(closing)}`;
|
|
160
|
+
}
|
|
161
|
+
const lastEnd = last.offset + last.length;
|
|
162
|
+
const lineEnd = content.indexOf(eol, lastEnd);
|
|
163
|
+
if (lineEnd === -1 || lineEnd > closing) {
|
|
164
|
+
return `${content.slice(0, lastEnd)}, ${JSON.stringify(name)}: ${JSON.stringify(value)}${content.slice(lastEnd)}`;
|
|
165
|
+
}
|
|
166
|
+
const trailingComma = /^\s*,/.test(content.slice(lastEnd, lineEnd));
|
|
167
|
+
const comma = trailingComma ? '' : ',';
|
|
168
|
+
return `${content.slice(0, lastEnd)}${comma}${content.slice(lastEnd, lineEnd)}${eol}${pad}${property}${trailingComma ? ',' : ''}${content.slice(lineEnd)}`;
|
|
169
|
+
};
|
|
170
|
+
const withJsonEntry = (content, { key, entry }, name) => {
|
|
171
|
+
if (content.trim() === '') {
|
|
172
|
+
return `${JSON.stringify({ [key]: { [name]: entry } }, null, 2)}\n`;
|
|
173
|
+
}
|
|
174
|
+
const root = parseTree(content, [], { allowTrailingComma: true });
|
|
175
|
+
if (root?.type !== 'object') {
|
|
176
|
+
return undefined;
|
|
177
|
+
}
|
|
178
|
+
const eol = detectEol(content);
|
|
179
|
+
const indent = detectIndent(content);
|
|
180
|
+
const servers = findNodeAtLocation(root, [key]);
|
|
181
|
+
return servers === undefined
|
|
182
|
+
? insertProperty(content, root, key, { [name]: entry }, eol, indent)
|
|
183
|
+
: insertProperty(content, servers, name, entry, eol, indent);
|
|
184
|
+
};
|
|
185
|
+
const withTomlEntry = (content, { key, entry }, name) => {
|
|
186
|
+
const eol = detectEol(content);
|
|
187
|
+
const lines = Object.entries(entry).map(([field, value]) => `${field} = ${tomlValue(value)}`);
|
|
188
|
+
const table = [`[${key}.${name}]`, ...lines].join(eol);
|
|
189
|
+
const separator = content === '' ? '' : content.endsWith(eol) ? eol : `${eol}${eol}`;
|
|
190
|
+
return `${content}${separator}${table}${eol}`;
|
|
191
|
+
};
|
|
192
|
+
const holdsEntry = (content, { format, key }, name) => {
|
|
193
|
+
const parsed = format === 'toml' ? parseToml(content) : parseJson(content);
|
|
194
|
+
return isObject(parsed?.[key]) && name in parsed[key];
|
|
195
|
+
};
|
|
196
|
+
export const addToProjectConfig = async (workingDir, file, name, { path: resolved, content }) => {
|
|
197
|
+
const updated = file.format === 'toml' ? withTomlEntry(content, file, name) : withJsonEntry(content, file, name);
|
|
198
|
+
if (updated === undefined || !holdsEntry(updated, file, name)) {
|
|
199
|
+
return false;
|
|
200
|
+
}
|
|
201
|
+
const target = path.join(workingDir, resolved);
|
|
202
|
+
await fs.mkdir(path.dirname(target), { recursive: true });
|
|
203
|
+
await writeFileAtomic(target, updated, 'utf8');
|
|
204
|
+
return true;
|
|
205
|
+
};
|
|
206
|
+
//# sourceMappingURL=agent-mcp-config.js.map
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { type CanonicalAgentName } from '../agent-detection.js';
|
|
2
|
+
import { type ProjectConfigFile } from './agent-mcp-config.js';
|
|
3
|
+
export declare const NETLIFY_MCP_URL = "https://mcp.netlify.com/mcp";
|
|
4
|
+
export declare const NETLIFY_MCP_SERVER_NAME = "netlify";
|
|
5
|
+
export declare const MCP_SCOPES: readonly ['project', 'user'];
|
|
6
|
+
export type McpScope = (typeof MCP_SCOPES)[number];
|
|
7
|
+
type LookupKind = 'list' | 'list-json';
|
|
8
|
+
interface NativeCommands {
|
|
9
|
+
add: string[];
|
|
10
|
+
remove?: string[];
|
|
11
|
+
savedIn?: string;
|
|
12
|
+
}
|
|
13
|
+
interface NativeSetup {
|
|
14
|
+
lookup?: LookupKind;
|
|
15
|
+
scopes: Partial<Record<McpScope, NativeCommands>>;
|
|
16
|
+
}
|
|
17
|
+
export interface McpAgent {
|
|
18
|
+
id: string;
|
|
19
|
+
label: string;
|
|
20
|
+
binary?: string;
|
|
21
|
+
drivenBy?: CanonicalAgentName[];
|
|
22
|
+
projectMarkers?: string[];
|
|
23
|
+
projectFile?: ProjectConfigFile;
|
|
24
|
+
inTerminal?: (env: NodeJS.ProcessEnv) => boolean;
|
|
25
|
+
native?: NativeSetup;
|
|
26
|
+
}
|
|
27
|
+
export declare const MCP_AGENTS: McpAgent[];
|
|
28
|
+
export type AgentMcpStatus = 'added' | 'present' | 'kept' | 'printed' | 'unsupported' | 'declined' | 'failed';
|
|
29
|
+
export type AgentSelection = 'driving' | 'prompt' | 'saved' | 'none';
|
|
30
|
+
export interface AgentMcpSetupSummary {
|
|
31
|
+
scope: McpScope;
|
|
32
|
+
selection: AgentSelection;
|
|
33
|
+
agents: Record<string, AgentMcpStatus>;
|
|
34
|
+
failed?: boolean;
|
|
35
|
+
}
|
|
36
|
+
export interface AgentCandidate {
|
|
37
|
+
agent: McpAgent;
|
|
38
|
+
detected: boolean;
|
|
39
|
+
}
|
|
40
|
+
export type ChooseAgents = (candidates: AgentCandidate[]) => Promise<McpAgent[]>;
|
|
41
|
+
export declare const findCandidates: (workingDir: string, env: NodeJS.ProcessEnv, scope?: McpScope) => Promise<AgentCandidate[]>;
|
|
42
|
+
export interface McpChoiceStore {
|
|
43
|
+
get(key: string): unknown;
|
|
44
|
+
set(key: string, value: unknown): void;
|
|
45
|
+
delete(key: string): void;
|
|
46
|
+
}
|
|
47
|
+
export declare const setupAgentMcp: ({ workingDir, store, scope, env, interactive, choose, reset, }: {
|
|
48
|
+
workingDir: string;
|
|
49
|
+
store: McpChoiceStore;
|
|
50
|
+
scope?: McpScope;
|
|
51
|
+
env?: NodeJS.ProcessEnv;
|
|
52
|
+
interactive?: boolean;
|
|
53
|
+
choose?: ChooseAgents;
|
|
54
|
+
reset?: boolean;
|
|
55
|
+
}) => Promise<AgentMcpSetupSummary>;
|
|
56
|
+
export {};
|
|
57
|
+
//# sourceMappingURL=agent-mcp.d.ts.map
|