@gadicc/loom 1.36.0 → 1.37.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/README.md +15 -5
- package/esm/src/cli/mod.d.ts +46 -1
- package/esm/src/cli/mod.d.ts.map +1 -1
- package/esm/src/cli/mod.js +641 -52
- package/package.json +2 -2
- package/script/src/cli/mod.d.ts +46 -1
- package/script/src/cli/mod.d.ts.map +1 -1
- package/script/src/cli/mod.js +644 -52
- package/skills/loom/SKILL.md +5 -0
- package/skills/loom-files/references/provider-configuration.md +8 -0
- package/skills/loom-secrets/SKILL.md +27 -13
package/script/src/cli/mod.js
CHANGED
|
@@ -63,6 +63,8 @@ exports.setupGithubMigrationCredential = setupGithubMigrationCredential;
|
|
|
63
63
|
exports.setupGithubVercelRelease = setupGithubVercelRelease;
|
|
64
64
|
exports.initProject = initProject;
|
|
65
65
|
exports.addFeature = addFeature;
|
|
66
|
+
exports.planSecretsKey = planSecretsKey;
|
|
67
|
+
exports.recordedSecretsKey = recordedSecretsKey;
|
|
66
68
|
exports.generateSecretsKey = generateSecretsKey;
|
|
67
69
|
exports.fingerprintSecretsKey = fingerprintSecretsKey;
|
|
68
70
|
exports.activateSecretsKey = activateSecretsKey;
|
|
@@ -73,6 +75,7 @@ exports.addSkills = addSkills;
|
|
|
73
75
|
exports.checkProject = checkProject;
|
|
74
76
|
exports.checkProjectNetwork = checkProjectNetwork;
|
|
75
77
|
exports.formatPlainNetworkCheckLines = formatPlainNetworkCheckLines;
|
|
78
|
+
exports.resolveOutsideChange = resolveOutsideChange;
|
|
76
79
|
exports.runEnvCommand = runEnvCommand;
|
|
77
80
|
exports.runCli = runCli;
|
|
78
81
|
const node_child_process_1 = require("node:child_process");
|
|
@@ -8059,16 +8062,29 @@ async function listVercelEnvironmentNames(cwd, commandRunner, env, vercelCommand
|
|
|
8059
8062
|
}
|
|
8060
8063
|
return result.stdout;
|
|
8061
8064
|
}
|
|
8062
|
-
|
|
8063
|
-
|
|
8065
|
+
/**
|
|
8066
|
+
* What a failed Vercel CLI call said. In an agent session the CLI reports
|
|
8067
|
+
* errors as JSON on stdout. Vercel does not echo a value it was given, but a
|
|
8068
|
+
* long one is masked anyway, in case a later version does.
|
|
8069
|
+
*/
|
|
8070
|
+
function vercelFailureDetail(result, value) {
|
|
8071
|
+
const detail = result.stderr.trim() || result.stdout.trim() ||
|
|
8072
|
+
`exit code ${result.code}`;
|
|
8073
|
+
return value.length >= 16 ? detail.split(value).join("[redacted]") : detail;
|
|
8074
|
+
}
|
|
8075
|
+
async function addVercelEnvValue(cwd, commandRunner, env, vercelCommand, name, value, environment, extraArgs = []) {
|
|
8076
|
+
// The value goes on stdin, never into the arguments, where the process
|
|
8077
|
+
// list and shell history would show it.
|
|
8078
|
+
const result = await commandRunner(vercelCommand, ["env", "add", name, environment, ...extraArgs], { cwd, env, input: `${value}\n`, stdio: "pipe" });
|
|
8064
8079
|
if (result.code !== 0) {
|
|
8065
|
-
throw new Error(`Could not add ${name} to Vercel ${environment}: ${result
|
|
8080
|
+
throw new Error(`Could not add ${name} to Vercel ${environment}: ${vercelFailureDetail(result, value)}`);
|
|
8066
8081
|
}
|
|
8067
8082
|
}
|
|
8068
8083
|
async function updateVercelEnvValue(cwd, commandRunner, env, vercelCommand, name, value, environment) {
|
|
8084
|
+
// No type flag: `env update` keeps the variable's existing type.
|
|
8069
8085
|
const result = await commandRunner(vercelCommand, ["env", "update", name, environment, "--yes"], { cwd, env, input: `${value}\n`, stdio: "pipe" });
|
|
8070
8086
|
if (result.code !== 0) {
|
|
8071
|
-
throw new Error(`Could not update ${name} in Vercel ${environment}: ${result
|
|
8087
|
+
throw new Error(`Could not update ${name} in Vercel ${environment}: ${vercelFailureDetail(result, value)}`);
|
|
8072
8088
|
}
|
|
8073
8089
|
}
|
|
8074
8090
|
async function promptForVercelSecret(cwd, commandRunner, env, vercelCommand, name, environment) {
|
|
@@ -8106,10 +8122,38 @@ function buildVercelFilesEnvListArgs(environment, project) {
|
|
|
8106
8122
|
}
|
|
8107
8123
|
function withoutInheritedVercelProject(env) {
|
|
8108
8124
|
const result = { ...env };
|
|
8109
|
-
|
|
8110
|
-
|
|
8125
|
+
// The Vercel CLI still honours the older NOW_* names too.
|
|
8126
|
+
for (const name of [
|
|
8127
|
+
"VERCEL_ORG_ID",
|
|
8128
|
+
"VERCEL_PROJECT_ID",
|
|
8129
|
+
"NOW_ORG_ID",
|
|
8130
|
+
"NOW_PROJECT_ID",
|
|
8131
|
+
]) {
|
|
8132
|
+
delete result[name];
|
|
8133
|
+
}
|
|
8111
8134
|
return result;
|
|
8112
8135
|
}
|
|
8136
|
+
/**
|
|
8137
|
+
* Which of `names` Vercel stores as Secrets for `environment`, or null when
|
|
8138
|
+
* the JSON listing is unavailable. A Secret reads back empty, so it looks like
|
|
8139
|
+
* drift, but `vercel env update` keeps a variable's type and cannot fix it.
|
|
8140
|
+
*/
|
|
8141
|
+
async function findVercelFilesValuesStoredAsSecrets(cwd, commandRunner, env, vercelCommand, environment, listArgs, names) {
|
|
8142
|
+
const result = await commandRunner(vercelCommand, [...listArgs, "--format", "json"], { cwd, env, stdio: "pipe" });
|
|
8143
|
+
if (result.code !== 0)
|
|
8144
|
+
return null;
|
|
8145
|
+
const variables = parseVercelEnvListing(result.stdout);
|
|
8146
|
+
if (!variables)
|
|
8147
|
+
return null;
|
|
8148
|
+
return names.filter((name) => variables.some((variable) => variable.key === name && variable.secret &&
|
|
8149
|
+
variable.targets.includes(environment)));
|
|
8150
|
+
}
|
|
8151
|
+
function filesSecretTypeProblem(environment, names) {
|
|
8152
|
+
return `Vercel ${environment} stores ${names.join(", ")} as Secrets, so their values cannot be read back, and \`vercel env update\` keeps a Secret a Secret.`;
|
|
8153
|
+
}
|
|
8154
|
+
function filesSecretTypeFix(environment) {
|
|
8155
|
+
return `Remove them from Vercel ${environment}, then run \`loom files r2 setup\` to add them back as readable values.`;
|
|
8156
|
+
}
|
|
8113
8157
|
async function readVercelFilesNonSecretValues(cwd, commandRunner, env, vercelCommand, environment) {
|
|
8114
8158
|
const link = await readVercelProjectLink(cwd);
|
|
8115
8159
|
if (!link.linked || !link.orgId || !link.projectId)
|
|
@@ -8192,11 +8236,11 @@ async function ensureMinioBucket(cwd, commandRunner, env, endpoint, bucket, acce
|
|
|
8192
8236
|
* is read in raw mode so it is never echoed. Refuses when stdin is not a
|
|
8193
8237
|
* terminal, with the caller's explanation of what to do instead.
|
|
8194
8238
|
*/
|
|
8195
|
-
async function promptForTerminalValue(question, secret, messages) {
|
|
8239
|
+
async function promptForTerminalValue(question, secret, messages, options = {}) {
|
|
8196
8240
|
if (!node_process_1.default.stdin.isTTY) {
|
|
8197
8241
|
throw new Error(messages.notInteractive);
|
|
8198
8242
|
}
|
|
8199
|
-
if (!secret) {
|
|
8243
|
+
if (!secret && !options.rawEcho) {
|
|
8200
8244
|
const input = (0, promises_2.createInterface)({
|
|
8201
8245
|
input: node_process_1.default.stdin,
|
|
8202
8246
|
output: node_process_1.default.stderr,
|
|
@@ -8230,9 +8274,13 @@ async function promptForTerminalValue(question, secret, messages) {
|
|
|
8230
8274
|
return;
|
|
8231
8275
|
}
|
|
8232
8276
|
if (character === "\u007f" || character === "\b") {
|
|
8277
|
+
if (options.rawEcho && value)
|
|
8278
|
+
node_process_1.default.stderr.write("\b \b");
|
|
8233
8279
|
value = value.slice(0, -1);
|
|
8234
8280
|
}
|
|
8235
8281
|
else {
|
|
8282
|
+
if (options.rawEcho)
|
|
8283
|
+
node_process_1.default.stderr.write(character);
|
|
8236
8284
|
value += character;
|
|
8237
8285
|
}
|
|
8238
8286
|
}
|
|
@@ -8910,6 +8958,12 @@ async function setupCloudflareR2(cwd, options = {}) {
|
|
|
8910
8958
|
throw new Error(`Could not inspect existing non-secret Files values in Vercel ${environment}.`);
|
|
8911
8959
|
}
|
|
8912
8960
|
const drift = existingNonSecretNames.filter((name) => actualValues[name] !== nonSecretValues[name]);
|
|
8961
|
+
const storedAsSecrets = drift.length
|
|
8962
|
+
? await findVercelFilesValuesStoredAsSecrets(cwd, commandRunner, providerEnv, vercelCli.command, environment, ["env", "ls", environment], drift)
|
|
8963
|
+
: null;
|
|
8964
|
+
if (storedAsSecrets?.length) {
|
|
8965
|
+
throw new Error(`${filesSecretTypeProblem(environment, storedAsSecrets)} ${filesSecretTypeFix(environment)}`);
|
|
8966
|
+
}
|
|
8913
8967
|
if (drift.length && !options.repair) {
|
|
8914
8968
|
throw new Error(`Vercel ${environment} non-secret Files values differ from the declared R2 policy: ${drift.join(", ")}. Review the drift and rerun with --repair; credentials will not be changed.`);
|
|
8915
8969
|
}
|
|
@@ -8919,7 +8973,11 @@ async function setupCloudflareR2(cwd, options = {}) {
|
|
|
8919
8973
|
}
|
|
8920
8974
|
for (const [name, value] of Object.entries(nonSecretValues)) {
|
|
8921
8975
|
if (!hasExactEnvName(listing, name)) {
|
|
8922
|
-
await addVercelEnvValue(cwd, commandRunner, providerEnv, vercelCli.command, name, value, environment
|
|
8976
|
+
await addVercelEnvValue(cwd, commandRunner, providerEnv, vercelCli.command, name, value, environment,
|
|
8977
|
+
// Vercel CLI stores a Production or Preview value read from
|
|
8978
|
+
// stdin as a Secret unless told otherwise, and the env-run probe
|
|
8979
|
+
// and release env policies must be able to read these back.
|
|
8980
|
+
["--no-sensitive", "--yes"]);
|
|
8923
8981
|
listing += `\n${name}`;
|
|
8924
8982
|
}
|
|
8925
8983
|
}
|
|
@@ -9027,6 +9085,9 @@ async function readVercelProjectLink(cwd) {
|
|
|
9027
9085
|
linked: true,
|
|
9028
9086
|
orgId,
|
|
9029
9087
|
projectId,
|
|
9088
|
+
projectName: typeof project.projectName === "string"
|
|
9089
|
+
? project.projectName
|
|
9090
|
+
: null,
|
|
9030
9091
|
relativePath,
|
|
9031
9092
|
};
|
|
9032
9093
|
}
|
|
@@ -9949,6 +10010,23 @@ function checkFilesNetworkFeature(context) {
|
|
|
9949
10010
|
FILES_S3_FORCE_PATH_STYLE: String(provider.forcePathStyle ?? false),
|
|
9950
10011
|
};
|
|
9951
10012
|
const drift = Object.entries(expectedValues).filter(([name, value]) => actualValues[name] !== value).map(([name]) => name);
|
|
10013
|
+
const storedAsSecrets = drift.length
|
|
10014
|
+
? await findVercelFilesValuesStoredAsSecrets(context.cwd, context.commandRunner, withoutInheritedVercelProject(context.env), state.vercelCommand, environment, buildVercelFilesEnvListArgs(environment, state.vercelProject), drift)
|
|
10015
|
+
: null;
|
|
10016
|
+
if (storedAsSecrets?.length) {
|
|
10017
|
+
const otherDrift = drift.filter((name) => !storedAsSecrets.includes(name));
|
|
10018
|
+
return networkCheckResult("issue", `Vercel ${environment} stores non-secret Files values as Secrets: ${storedAsSecrets.join(", ")}.`, {
|
|
10019
|
+
issues: [
|
|
10020
|
+
filesSecretTypeProblem(environment, storedAsSecrets),
|
|
10021
|
+
...(otherDrift.length
|
|
10022
|
+
? [
|
|
10023
|
+
`Vercel ${environment} has incompatible non-secret Files R2 values: ${otherDrift.join(", ")}.`,
|
|
10024
|
+
]
|
|
10025
|
+
: []),
|
|
10026
|
+
],
|
|
10027
|
+
suggestions: [filesSecretTypeFix(environment)],
|
|
10028
|
+
});
|
|
10029
|
+
}
|
|
9952
10030
|
return drift.length
|
|
9953
10031
|
? networkCheckResult("issue", `Vercel ${environment} Files values drift from loom.json: ${drift.join(", ")}.`, {
|
|
9954
10032
|
issues: [
|
|
@@ -10934,7 +11012,7 @@ async function applySecretsFeature(cwd, framework, manifest, activate, options =
|
|
|
10934
11012
|
changedFiles.push(...localKey.changedFiles);
|
|
10935
11013
|
notes.push(...localKey.notes);
|
|
10936
11014
|
if (!Array.isArray(config.keys.production) || !config.keys.production.length) {
|
|
10937
|
-
notes.push("No production key is recorded yet. Before the first production deploy, an operator runs `loom secrets keygen` in their own terminal; an agent must not run it.");
|
|
11015
|
+
notes.push("No production key is recorded yet. Before the first production deploy, an operator runs `loom secrets keygen` in their own terminal; an agent must not run it. On a linked Vercel project it offers to add the key and pointer there.");
|
|
10938
11016
|
}
|
|
10939
11017
|
}
|
|
10940
11018
|
feature.config = mergeSecretsConfig(currentFeature?.config, config);
|
|
@@ -13789,7 +13867,7 @@ async function checkSecretsFeature(cwd, framework, manifest, options) {
|
|
|
13789
13867
|
}
|
|
13790
13868
|
if (Array.isArray(config.keys.production) && config.keys.production.length === 0) {
|
|
13791
13869
|
releaseBlocking("No production secrets key is recorded in loom.json, so production would run with unverified keys.");
|
|
13792
|
-
suggestions.add("Have an operator run `loom secrets keygen` in their own terminal, then commit the recorded fingerprint.");
|
|
13870
|
+
suggestions.add("Have an operator run `loom secrets keygen` in their own terminal, then commit the recorded fingerprint. On a linked Vercel project it offers to add the key there too.");
|
|
13793
13871
|
}
|
|
13794
13872
|
const policyText = await readTextIfExists((0, node_path_1.join)(cwd, VERCEL_PRODUCTION_ENV_POLICY_PATH));
|
|
13795
13873
|
if (policyText !== null) {
|
|
@@ -14024,15 +14102,18 @@ function recordedSecretKeys(config, environment) {
|
|
|
14024
14102
|
return recorded;
|
|
14025
14103
|
}
|
|
14026
14104
|
/** Validates a changed key list, then records it in loom.json. */
|
|
14027
|
-
|
|
14028
|
-
if (keys.length)
|
|
14029
|
-
|
|
14030
|
-
|
|
14031
|
-
|
|
14032
|
-
catch (error) {
|
|
14033
|
-
throw new Error(`The ${environment} key list in loom.json would be invalid: ${error.message}`);
|
|
14034
|
-
}
|
|
14105
|
+
function validateSecretKeys(environment, keys) {
|
|
14106
|
+
if (!keys.length)
|
|
14107
|
+
return;
|
|
14108
|
+
try {
|
|
14109
|
+
(0, fingerprint_js_1.parseExpectedSecretKeys)(keys);
|
|
14035
14110
|
}
|
|
14111
|
+
catch (error) {
|
|
14112
|
+
throw new Error(`The ${environment} key list in loom.json would be invalid: ${error.message}`);
|
|
14113
|
+
}
|
|
14114
|
+
}
|
|
14115
|
+
async function writeSecretKeys(cwd, loaded, environment, keys) {
|
|
14116
|
+
validateSecretKeys(environment, keys);
|
|
14036
14117
|
// Replaces this one list and nothing else: any other property a user keeps
|
|
14037
14118
|
// under `config` or `config.keys` is theirs, and stays.
|
|
14038
14119
|
const existing = isJsonObject(loaded.feature.config)
|
|
@@ -14050,6 +14131,49 @@ async function writeSecretKeys(cwd, loaded, environment, keys) {
|
|
|
14050
14131
|
? ["loom.json"]
|
|
14051
14132
|
: [];
|
|
14052
14133
|
}
|
|
14134
|
+
function nextSecretsKey(config, environment) {
|
|
14135
|
+
const current = recordedSecretKeys(config, environment);
|
|
14136
|
+
const id = current.reduce((highest, key) => (0, keyring_js_1.isSecretKeyId)(key?.id) ? Math.max(highest, key.id) : highest, 0) + 1;
|
|
14137
|
+
const state = current.some((key) => key?.state === "active")
|
|
14138
|
+
? "decrypt-only"
|
|
14139
|
+
: "active";
|
|
14140
|
+
return { current, id, state };
|
|
14141
|
+
}
|
|
14142
|
+
/**
|
|
14143
|
+
* The version, state and variable names `generateSecretsKey` would use next,
|
|
14144
|
+
* without generating or recording anything.
|
|
14145
|
+
*/
|
|
14146
|
+
async function planSecretsKey(cwd, environment = "production") {
|
|
14147
|
+
const loaded = await readActiveSecretsFeature(cwd);
|
|
14148
|
+
const { id, state } = nextSecretsKey(loaded.config, environment);
|
|
14149
|
+
return {
|
|
14150
|
+
activeKeyName: loaded.config.env.activeKeyName,
|
|
14151
|
+
id,
|
|
14152
|
+
state,
|
|
14153
|
+
variableName: `${loaded.config.env.keyPrefix}${id}`,
|
|
14154
|
+
};
|
|
14155
|
+
}
|
|
14156
|
+
/**
|
|
14157
|
+
* A recorded key that is not retired, with its variable names, for putting it
|
|
14158
|
+
* on a deployment platform. Refuses a version that is not listed or retired.
|
|
14159
|
+
*/
|
|
14160
|
+
async function recordedSecretsKey(cwd, id, environment = "production") {
|
|
14161
|
+
const loaded = await readActiveSecretsFeature(cwd);
|
|
14162
|
+
const key = recordedSecretKeys(loaded.config, environment).find((entry) => entry?.id === id);
|
|
14163
|
+
if (!key) {
|
|
14164
|
+
throw new Error(`Key version ${id} is not listed for ${environment} in loom.json.`);
|
|
14165
|
+
}
|
|
14166
|
+
if (key.state === "retired") {
|
|
14167
|
+
throw new Error(`Key version ${id} is retired for ${environment}.`);
|
|
14168
|
+
}
|
|
14169
|
+
return {
|
|
14170
|
+
activeKeyName: loaded.config.env.activeKeyName,
|
|
14171
|
+
fingerprint: key.fingerprint,
|
|
14172
|
+
id,
|
|
14173
|
+
state: key.state,
|
|
14174
|
+
variableName: `${loaded.config.env.keyPrefix}${id}`,
|
|
14175
|
+
};
|
|
14176
|
+
}
|
|
14053
14177
|
/**
|
|
14054
14178
|
* Generates a key for a deployed environment and records its fingerprint in
|
|
14055
14179
|
* loom.json: `active` when the environment has no active key, otherwise
|
|
@@ -14063,11 +14187,7 @@ async function writeSecretKeys(cwd, loaded, environment, keys) {
|
|
|
14063
14187
|
async function generateSecretsKey(cwd, options = {}) {
|
|
14064
14188
|
const environment = options.environment ?? "production";
|
|
14065
14189
|
const loaded = await readActiveSecretsFeature(cwd);
|
|
14066
|
-
const current =
|
|
14067
|
-
const id = current.reduce((highest, key) => (0, keyring_js_1.isSecretKeyId)(key?.id) ? Math.max(highest, key.id) : highest, 0) + 1;
|
|
14068
|
-
const state = current.some((key) => key?.state === "active")
|
|
14069
|
-
? "decrypt-only"
|
|
14070
|
-
: "active";
|
|
14190
|
+
const { current, id, state } = nextSecretsKey(loaded.config, environment);
|
|
14071
14191
|
const key = globalThis.crypto.getRandomValues(new Uint8Array(keyring_js_1.SECRETS_KEY_BYTES));
|
|
14072
14192
|
const fingerprint = await (0, fingerprint_js_1.secretKeyFingerprint)(key);
|
|
14073
14193
|
const changedFiles = await writeSecretKeys(cwd, loaded, environment, [
|
|
@@ -14097,8 +14217,12 @@ async function fingerprintSecretsKey(value) {
|
|
|
14097
14217
|
/**
|
|
14098
14218
|
* Marks a recorded key `active` in loom.json and the previously active key
|
|
14099
14219
|
* `decrypt-only`. Refuses a version that is not listed or is retired.
|
|
14220
|
+
*
|
|
14221
|
+
* `beforeWrite` runs once those checks pass and before loom.json changes, so
|
|
14222
|
+
* the platform's pointer can be moved first; if it throws, loom.json is left
|
|
14223
|
+
* as it was.
|
|
14100
14224
|
*/
|
|
14101
|
-
async function activateSecretsKey(cwd, id, environment = "production") {
|
|
14225
|
+
async function activateSecretsKey(cwd, id, environment = "production", options = {}) {
|
|
14102
14226
|
const loaded = await readActiveSecretsFeature(cwd);
|
|
14103
14227
|
const current = recordedSecretKeys(loaded.config, environment);
|
|
14104
14228
|
const target = current.find((key) => key?.id === id);
|
|
@@ -14108,11 +14232,36 @@ async function activateSecretsKey(cwd, id, environment = "production") {
|
|
|
14108
14232
|
if (target.state === "retired") {
|
|
14109
14233
|
throw new Error(`Key version ${id} is retired and cannot be activated. Generate a new key with \`loom secrets keygen\`.`);
|
|
14110
14234
|
}
|
|
14111
|
-
const
|
|
14235
|
+
const next = current.map((key) => key?.id === id
|
|
14112
14236
|
? { ...key, state: "active" }
|
|
14113
14237
|
: key?.state === "active"
|
|
14114
14238
|
? { ...key, state: "decrypt-only" }
|
|
14115
|
-
: key)
|
|
14239
|
+
: key);
|
|
14240
|
+
// Checked before the hook, which may change a deployment platform: that
|
|
14241
|
+
// must not happen for a list that could not then be written.
|
|
14242
|
+
validateSecretKeys(environment, next);
|
|
14243
|
+
if (!options.beforeWrite) {
|
|
14244
|
+
return {
|
|
14245
|
+
activeKeyName: loaded.config.env.activeKeyName,
|
|
14246
|
+
changedFiles: await writeSecretKeys(cwd, loaded, environment, next),
|
|
14247
|
+
environment,
|
|
14248
|
+
id,
|
|
14249
|
+
};
|
|
14250
|
+
}
|
|
14251
|
+
const changedOutside = await options.beforeWrite({
|
|
14252
|
+
activeKeyName: loaded.config.env.activeKeyName,
|
|
14253
|
+
id,
|
|
14254
|
+
variableName: `${loaded.config.env.keyPrefix}${id}`,
|
|
14255
|
+
});
|
|
14256
|
+
let changedFiles;
|
|
14257
|
+
try {
|
|
14258
|
+
changedFiles = await writeSecretKeys(cwd, loaded, environment, next);
|
|
14259
|
+
}
|
|
14260
|
+
catch (error) {
|
|
14261
|
+
if (!changedOutside)
|
|
14262
|
+
throw error;
|
|
14263
|
+
throw new Error(`${error.message} The platform was already changed for key version ${id}; fix loom.json and run this again, or put the platform back.`);
|
|
14264
|
+
}
|
|
14116
14265
|
return {
|
|
14117
14266
|
activeKeyName: loaded.config.env.activeKeyName,
|
|
14118
14267
|
changedFiles,
|
|
@@ -14946,9 +15095,10 @@ function printHelp({ out }) {
|
|
|
14946
15095
|
out(" files r2 check Verify R2 buckets/account/privacy, Vercel env scoping, local storage, and Files adapter wiring.");
|
|
14947
15096
|
out(" api-keys integrate jobs Record an explicit API-key jobs integration after the route has session/admin authorization.");
|
|
14948
15097
|
out(" api-keys retention enable|disable Record API-key audit cleanup policy; scheduling remains app-owned.");
|
|
14949
|
-
out(" secrets keygen Generate a production secrets key, print it once to a terminal, and record its fingerprint in loom.json.");
|
|
15098
|
+
out(" secrets keygen Generate a production secrets key, print it once to a terminal, and record its fingerprint in loom.json. On a linked Vercel project it offers to add the key there.");
|
|
15099
|
+
out(" secrets push <id> Add a recorded secrets key to Vercel Production as a Secret, from a copy pasted back and checked against loom.json.");
|
|
14950
15100
|
out(" secrets fingerprint Read a secrets key from a hidden terminal prompt and print only its fingerprint.");
|
|
14951
|
-
out(" secrets activate <id> Record a listed secrets key as the active one; the previous active key becomes decrypt-only.");
|
|
15101
|
+
out(" secrets activate <id> Record a listed secrets key as the active one; the previous active key becomes decrypt-only. On a linked Vercel project it offers to move the pointer there first.");
|
|
14952
15102
|
out(" secrets retire <id> Record a secrets key that nothing needs any more as retired.");
|
|
14953
15103
|
out(" status Show the Loom package, manifest, active features, local-dev state, and project skill state.");
|
|
14954
15104
|
out(" check Validate project bootstrap, managed guidance, features, skill locks, caches, and links.");
|
|
@@ -14981,6 +15131,7 @@ function printHelp({ out }) {
|
|
|
14981
15131
|
out(" --network Run registered network checks after the local project checks.");
|
|
14982
15132
|
out(" --production Treat local Loom dev overrides and local lockfile resolutions as release-blocking check failures.");
|
|
14983
15133
|
out(" --no-progress Disable the interactive network progress renderer.");
|
|
15134
|
+
out(" --vercel, --no-vercel For secrets keygen and activate: change the linked Vercel project without asking, or never. Without either, only a person at a terminal is asked.");
|
|
14984
15135
|
out(" --local-db-host <host> Local PostgreSQL host (default: db.localtest.me).");
|
|
14985
15136
|
out(" --local-db-port <port> Local PostgreSQL port (default: 5432).");
|
|
14986
15137
|
out(" --replace-local-target Replace an existing development URL during local DB setup.");
|
|
@@ -15053,6 +15204,29 @@ async function runApiKeys(cwd, command, target, options, io) {
|
|
|
15053
15204
|
io.out(`Note: ${note}`);
|
|
15054
15205
|
return 0;
|
|
15055
15206
|
}
|
|
15207
|
+
/**
|
|
15208
|
+
* Whether what follows `loom secrets push` is only a version number and
|
|
15209
|
+
* options Loom knows. Anything else may be a key typed in the wrong place,
|
|
15210
|
+
* which the argument parser would quote back in its error.
|
|
15211
|
+
*/
|
|
15212
|
+
function secretsPushArgumentsAreSafe(rest) {
|
|
15213
|
+
const flags = ["--vercel", "--no-vercel", "--no-color", "--help", "-h"];
|
|
15214
|
+
const withValue = ["--cwd", "--environment"];
|
|
15215
|
+
for (let index = 0; index < rest.length; index += 1) {
|
|
15216
|
+
const arg = rest[index];
|
|
15217
|
+
if (/^[1-9][0-9]{0,8}$/.test(arg) || flags.includes(arg))
|
|
15218
|
+
continue;
|
|
15219
|
+
if (withValue.some((name) => arg.startsWith(`${name}=`)))
|
|
15220
|
+
continue;
|
|
15221
|
+
if (withValue.includes(arg) && index + 1 < rest.length) {
|
|
15222
|
+
index += 1;
|
|
15223
|
+
continue;
|
|
15224
|
+
}
|
|
15225
|
+
return false;
|
|
15226
|
+
}
|
|
15227
|
+
return true;
|
|
15228
|
+
}
|
|
15229
|
+
const SECRETS_PUSH_ARGUMENT_REFUSAL = "loom secrets push takes only a key version number, such as `loom secrets push 1`. A key must never be passed as an argument: if a key was typed there, treat it as exposed, because it is now in the shell history and was visible in the process list. The key is read from a hidden terminal prompt instead.";
|
|
15056
15230
|
const SECRETS_FINGERPRINT_ARGUMENT_REFUSAL = "loom secrets fingerprint takes no arguments. A key must never be passed as an argument: if a key was typed there, treat it as exposed, because it is now in the shell history and was visible in the process list. The key is read from a hidden terminal prompt instead.";
|
|
15057
15231
|
/**
|
|
15058
15232
|
* Variables that an automated or agent session sets. A key must not be shown
|
|
@@ -15068,13 +15242,239 @@ const AUTOMATED_SESSION_ENV_NAMES = [
|
|
|
15068
15242
|
"CURSOR_AGENT",
|
|
15069
15243
|
"GEMINI_CLI",
|
|
15070
15244
|
];
|
|
15071
|
-
|
|
15072
|
-
|
|
15245
|
+
/**
|
|
15246
|
+
* Whether a command may change something outside the repository, such as a
|
|
15247
|
+
* deployment platform's settings. An explicit flag decides. Without one, only
|
|
15248
|
+
* a person at a terminal is asked, and the default answer is no; anywhere
|
|
15249
|
+
* else nothing outside changes and the command says how to do it instead.
|
|
15250
|
+
* See "CLI prompts and outside changes" in AGENTS.md.
|
|
15251
|
+
*/
|
|
15252
|
+
function resolveOutsideChange(flags, interactive) {
|
|
15253
|
+
if (flags.yes)
|
|
15254
|
+
return "yes";
|
|
15255
|
+
if (flags.no)
|
|
15256
|
+
return "no";
|
|
15257
|
+
return interactive ? "ask" : "no";
|
|
15258
|
+
}
|
|
15259
|
+
const isYesAnswer = (answer) => /^y(es)?$/i.test(answer.trim());
|
|
15260
|
+
/**
|
|
15261
|
+
* Parses `vercel env ls --format json` output, or returns null when it is not
|
|
15262
|
+
* that listing. Vercel CLI 54 and newer print it.
|
|
15263
|
+
*/
|
|
15264
|
+
function parseVercelEnvListing(text) {
|
|
15265
|
+
let parsed;
|
|
15266
|
+
try {
|
|
15267
|
+
parsed = JSON.parse(text.slice(text.indexOf("{"), text.lastIndexOf("}") + 1));
|
|
15268
|
+
}
|
|
15269
|
+
catch {
|
|
15270
|
+
return null;
|
|
15271
|
+
}
|
|
15272
|
+
const envs = isJsonObject(parsed) ? parsed.envs : undefined;
|
|
15273
|
+
if (!Array.isArray(envs))
|
|
15274
|
+
return null;
|
|
15275
|
+
return envs.flatMap((entry) => {
|
|
15276
|
+
if (!isJsonObject(entry) || typeof entry.key !== "string")
|
|
15277
|
+
return [];
|
|
15278
|
+
const targets = (Array.isArray(entry.target) ? entry.target : [entry.target])
|
|
15279
|
+
.filter((target) => typeof target === "string");
|
|
15280
|
+
return [{
|
|
15281
|
+
custom: Array.isArray(entry.customEnvironmentIds) &&
|
|
15282
|
+
entry.customEnvironmentIds.length > 0,
|
|
15283
|
+
key: entry.key,
|
|
15284
|
+
secret: entry.type === "sensitive" || entry.visibility === "secret",
|
|
15285
|
+
targets,
|
|
15286
|
+
type: typeof entry.type === "string" ? entry.type : "",
|
|
15287
|
+
}];
|
|
15288
|
+
});
|
|
15289
|
+
}
|
|
15290
|
+
async function listVercelProductionVariables(cwd, commandRunner, command, env) {
|
|
15291
|
+
// JSON, not the table: the table cannot tell a variable that applies to
|
|
15292
|
+
// Production alone from one shared with Preview, and a name could appear
|
|
15293
|
+
// inside another variable's displayed value.
|
|
15294
|
+
const result = await commandRunner(command, ["env", "ls", "production", "--format", "json"], { cwd, env, stdio: "pipe" });
|
|
15295
|
+
if (result.code !== 0) {
|
|
15296
|
+
throw new Error(`Could not list Vercel Production variables: ${vercelFailureDetail(result, "")}`);
|
|
15297
|
+
}
|
|
15298
|
+
const variables = parseVercelEnvListing(result.stdout);
|
|
15299
|
+
if (!variables) {
|
|
15300
|
+
throw new Error("Vercel did not list Production variables as JSON.");
|
|
15301
|
+
}
|
|
15302
|
+
return variables.filter((variable) => variable.targets.includes("production"));
|
|
15303
|
+
}
|
|
15304
|
+
const vercelVariables = (target, key) => target.variables.filter((variable) => variable.key === key);
|
|
15305
|
+
/**
|
|
15306
|
+
* Why the pointer cannot simply be updated for Production, or null when it
|
|
15307
|
+
* can. A variable shared with Preview would move its pointer too, and Preview
|
|
15308
|
+
* has a key list of its own. Sharing with a custom environment is not in
|
|
15309
|
+
* Vercel's listing, so it cannot be seen here.
|
|
15310
|
+
*/
|
|
15311
|
+
function vercelPointerProblem(target, name) {
|
|
15312
|
+
const found = vercelVariables(target, name);
|
|
15313
|
+
if (found.length === 0)
|
|
15314
|
+
return null;
|
|
15315
|
+
const shared = found.find((variable) => variable.custom || variable.targets.some((each) => each !== "production"));
|
|
15316
|
+
return found.length > 1 || shared
|
|
15317
|
+
? `${name} on Vercel is shared with ${shared
|
|
15318
|
+
? shared.targets.filter((each) => each !== "production").join(", ") ||
|
|
15319
|
+
"a custom environment"
|
|
15320
|
+
: "another entry"}. Give Production its own ${name} by hand, so the other environments keep theirs.`
|
|
15321
|
+
: null;
|
|
15322
|
+
}
|
|
15323
|
+
async function findSecretsVercelTarget(cwd, commandRunner) {
|
|
15324
|
+
const link = await readVercelProjectLink(cwd);
|
|
15325
|
+
if (!link.linked || !link.projectId) {
|
|
15326
|
+
return {
|
|
15327
|
+
linked: false,
|
|
15328
|
+
reason: `This project is not linked to Vercel: ${link.detail} Run \`vercel link\` first.`,
|
|
15329
|
+
};
|
|
15330
|
+
}
|
|
15331
|
+
// The link names the project; inherited ids would silently point the
|
|
15332
|
+
// writes somewhere else.
|
|
15333
|
+
const env = withoutInheritedVercelProject(node_process_1.default.env);
|
|
15334
|
+
const cli = await detectVercelCliCommand(cwd, commandRunner, env);
|
|
15335
|
+
if (!cli.command) {
|
|
15336
|
+
return {
|
|
15337
|
+
linked: true,
|
|
15338
|
+
reason: "The Vercel CLI (`vercel` or `vc`) was not found.",
|
|
15339
|
+
};
|
|
15340
|
+
}
|
|
15341
|
+
try {
|
|
15342
|
+
return {
|
|
15343
|
+
target: {
|
|
15344
|
+
command: cli.command,
|
|
15345
|
+
env,
|
|
15346
|
+
project: link.projectName ?? link.projectId,
|
|
15347
|
+
variables: await listVercelProductionVariables(cwd, commandRunner, cli.command, env),
|
|
15348
|
+
},
|
|
15349
|
+
};
|
|
15350
|
+
}
|
|
15351
|
+
catch (error) {
|
|
15352
|
+
return { linked: true, reason: error.message };
|
|
15353
|
+
}
|
|
15354
|
+
}
|
|
15355
|
+
function warnIfPointerSecret(target, name, io) {
|
|
15356
|
+
if (vercelVariables(target, name).some((variable) => variable.secret)) {
|
|
15357
|
+
io.err(`Vercel holds ${name} as a Secret, perhaps by team policy. It is not secret, and the release build cannot read a Secret back: give its release-policy requirement a placeholder, or store it readable.`);
|
|
15358
|
+
}
|
|
15359
|
+
}
|
|
15360
|
+
/** Sets the pointer for Production only, as a readable variable. */
|
|
15361
|
+
async function setVercelPointer(cwd, commandRunner, target, name, id) {
|
|
15362
|
+
if (vercelVariables(target, name).length) {
|
|
15363
|
+
await updateVercelEnvValue(cwd, commandRunner, target.env, target.command, name, String(id), "production");
|
|
15364
|
+
}
|
|
15365
|
+
else {
|
|
15366
|
+
// Without --no-sensitive, a value given on stdin is stored as a Secret,
|
|
15367
|
+
// which `vercel pull` cannot read back for the release build.
|
|
15368
|
+
await addVercelEnvValue(cwd, commandRunner, target.env, target.command, name, String(id), "production", ["--no-sensitive", "--yes"]);
|
|
15369
|
+
}
|
|
15370
|
+
}
|
|
15371
|
+
/**
|
|
15372
|
+
* Puts a secrets key on Vercel Production as a Secret, and the pointer when
|
|
15373
|
+
* the key is the active one, from a copy the operator pastes back from their
|
|
15374
|
+
* password manager. That copy is checked against the fingerprint in loom.json
|
|
15375
|
+
* before Vercel gets it: a key that reached Vercel but not the password
|
|
15376
|
+
* manager could never be recovered, since Vercel never shows a Secret again.
|
|
15377
|
+
* Afterwards Vercel is listed again to confirm how it stored them.
|
|
15378
|
+
*/
|
|
15379
|
+
async function pushSecretsKeyToVercel(cwd, commandRunner, target, key, terminal, io, options) {
|
|
15380
|
+
if (vercelVariables(target, key.variableName).length) {
|
|
15381
|
+
io.err(`${key.variableName} already exists in Vercel Production. Loom never replaces a key there; find out why Vercel and loom.json differ first.`);
|
|
15382
|
+
return false;
|
|
15383
|
+
}
|
|
15384
|
+
io.out(`Paste the key back from your password manager: the value after \`${key.variableName}=\`. Loom checks the saved copy against the fingerprint in loom.json before Vercel gets it.`);
|
|
15385
|
+
let value = null;
|
|
15386
|
+
for (let attempt = 1; attempt <= 3 && value === null; attempt += 1) {
|
|
15387
|
+
let pasted = (await terminal.prompt(`${key.variableName} from your password manager (input is hidden): `)).trim();
|
|
15388
|
+
if (!pasted) {
|
|
15389
|
+
io.err("Nothing was entered, so nothing was sent to Vercel.");
|
|
15390
|
+
return false;
|
|
15391
|
+
}
|
|
15392
|
+
// The whole printed line is a likely thing to have saved.
|
|
15393
|
+
if (pasted.startsWith(`${key.variableName}=`)) {
|
|
15394
|
+
pasted = pasted.slice(key.variableName.length + 1).trim();
|
|
15395
|
+
}
|
|
15396
|
+
let fingerprint = null;
|
|
15397
|
+
try {
|
|
15398
|
+
fingerprint = await fingerprintSecretsKey(pasted);
|
|
15399
|
+
}
|
|
15400
|
+
catch {
|
|
15401
|
+
io.err("That is not a secrets key: it does not decode to 32 bytes. Check the saved copy.");
|
|
15402
|
+
continue;
|
|
15403
|
+
}
|
|
15404
|
+
if (fingerprint === key.fingerprint) {
|
|
15405
|
+
value = pasted;
|
|
15406
|
+
}
|
|
15407
|
+
else {
|
|
15408
|
+
io.err(`That is a different key from version ${key.id}: its fingerprint does not match loom.json. Check the saved copy.`);
|
|
15409
|
+
}
|
|
15410
|
+
}
|
|
15411
|
+
if (value === null) {
|
|
15412
|
+
io.err(`Nothing was sent to Vercel. Fix the saved copy, then run \`loom secrets push ${key.id}\`.`);
|
|
15413
|
+
return false;
|
|
15414
|
+
}
|
|
15415
|
+
let setPointer = key.state === "active";
|
|
15416
|
+
const pointerProblem = setPointer
|
|
15417
|
+
? vercelPointerProblem(target, key.activeKeyName)
|
|
15418
|
+
: null;
|
|
15419
|
+
if (pointerProblem)
|
|
15420
|
+
setPointer = false;
|
|
15421
|
+
else if (setPointer && vercelVariables(target, key.activeKeyName).length) {
|
|
15422
|
+
setPointer = options.replacePointer === "ask" &&
|
|
15423
|
+
isYesAnswer(await terminal.ask(`${key.activeKeyName} already exists in Vercel Production. Set it to ${key.id}? [y/N] `));
|
|
15424
|
+
}
|
|
15425
|
+
try {
|
|
15426
|
+
await addVercelEnvValue(cwd, commandRunner, target.env, target.command, key.variableName, value, "production", ["--sensitive", "--yes"]);
|
|
15427
|
+
}
|
|
15428
|
+
catch (error) {
|
|
15429
|
+
io.err(`${error.message} Nothing else was changed.`);
|
|
15430
|
+
return false;
|
|
15431
|
+
}
|
|
15432
|
+
if (setPointer) {
|
|
15433
|
+
try {
|
|
15434
|
+
await setVercelPointer(cwd, commandRunner, target, key.activeKeyName, key.id);
|
|
15435
|
+
}
|
|
15436
|
+
catch (error) {
|
|
15437
|
+
io.err(`${key.variableName} was added, but ${key.activeKeyName} was not: ${error.message} Set ${key.activeKeyName}=${key.id} in Vercel Production yourself.`);
|
|
15438
|
+
return false;
|
|
15439
|
+
}
|
|
15440
|
+
}
|
|
15441
|
+
// Confirm what Vercel stored, rather than trusting how it was asked.
|
|
15442
|
+
let stored;
|
|
15443
|
+
try {
|
|
15444
|
+
stored = await listVercelProductionVariables(cwd, commandRunner, target.command, target.env);
|
|
15445
|
+
}
|
|
15446
|
+
catch (error) {
|
|
15447
|
+
io.err(`Added ${key.variableName}, but could not confirm how Vercel stored it: ${error.message} Check it is a Secret for Production only.`);
|
|
15448
|
+
return false;
|
|
15449
|
+
}
|
|
15450
|
+
const confirmed = { ...target, variables: stored };
|
|
15451
|
+
const keyEntry = vercelVariables(confirmed, key.variableName);
|
|
15452
|
+
if (keyEntry.length !== 1 || !keyEntry[0].secret ||
|
|
15453
|
+
keyEntry[0].custom || keyEntry[0].targets.join() !== "production") {
|
|
15454
|
+
io.err(`Vercel did not store ${key.variableName} as a Secret for Production only. Fix it in Vercel before deploying.`);
|
|
15455
|
+
return false;
|
|
15456
|
+
}
|
|
15457
|
+
io.out(`Added ${key.variableName} to Vercel project ${target.project}, Production only, as a Secret${setPointer ? `, and set ${key.activeKeyName}=${key.id}` : ""}. Deployments built before this keep their old environment.`);
|
|
15458
|
+
if (setPointer)
|
|
15459
|
+
warnIfPointerSecret(confirmed, key.activeKeyName, io);
|
|
15460
|
+
if (pointerProblem)
|
|
15461
|
+
io.err(pointerProblem);
|
|
15462
|
+
else if (key.state === "active" && !setPointer) {
|
|
15463
|
+
io.out(`Set ${key.activeKeyName}=${key.id} in Vercel Production before deploying.`);
|
|
15464
|
+
}
|
|
15465
|
+
return true;
|
|
15466
|
+
}
|
|
15467
|
+
async function runSecrets(cwd, command, target, options, io, terminal = {}, commandRunner = defaultCommandRunner) {
|
|
15468
|
+
const usage = "Usage: loom secrets keygen [--environment production|preview] [--vercel|--no-vercel]\n or: loom secrets fingerprint\n or: loom secrets push <id>\n or: loom secrets activate <id> [--environment production|preview] [--vercel|--no-vercel]\n or: loom secrets retire <id> [--environment production|preview]";
|
|
15073
15469
|
const environmentOption = options.environment ?? "production";
|
|
15074
15470
|
if (environmentOption !== "production" && environmentOption !== "preview") {
|
|
15075
15471
|
io.err("--environment must be production or preview.");
|
|
15076
15472
|
return 1;
|
|
15077
15473
|
}
|
|
15474
|
+
if (options.vercel && options.noVercel) {
|
|
15475
|
+
io.err("--vercel and --no-vercel cannot be used together.");
|
|
15476
|
+
return 1;
|
|
15477
|
+
}
|
|
15078
15478
|
const environment = environmentOption;
|
|
15079
15479
|
const platformTarget = environment === "production"
|
|
15080
15480
|
? "Production"
|
|
@@ -15083,6 +15483,27 @@ async function runSecrets(cwd, command, target, options, io, terminal = {}) {
|
|
|
15083
15483
|
const stdoutIsTty = terminal.stdoutIsTty ?? Boolean(node_process_1.default.stdout.isTTY);
|
|
15084
15484
|
const sessionEnv = terminal.env ?? node_process_1.default.env;
|
|
15085
15485
|
const automatedMarker = AUTOMATED_SESSION_ENV_NAMES.find((name) => Boolean(sessionEnv[name]));
|
|
15486
|
+
const vercelChoice = resolveOutsideChange({ no: options.noVercel, yes: options.vercel }, stdinIsTty && stdoutIsTty && !automatedMarker);
|
|
15487
|
+
if (options.vercel && environment !== "production") {
|
|
15488
|
+
io.err("--vercel sets Vercel Production only. Set Preview variables yourself.");
|
|
15489
|
+
return 1;
|
|
15490
|
+
}
|
|
15491
|
+
// Raw mode rather than readline: under Deno a readline question never
|
|
15492
|
+
// settles on Ctrl-C, and the command would end without a word.
|
|
15493
|
+
const ask = terminal.ask ??
|
|
15494
|
+
((question) => promptForTerminalValue(question, false, {
|
|
15495
|
+
cancelled: "Cancelled.",
|
|
15496
|
+
notInteractive: "This question needs a terminal.",
|
|
15497
|
+
}, { rawEcho: true }));
|
|
15498
|
+
const prompt = (cancelled, notInteractive) => terminal.prompt ??
|
|
15499
|
+
((question) => promptForTerminalValue(question, true, { cancelled, notInteractive }));
|
|
15500
|
+
// Reading a key is only for a person at a terminal: never a pipe, a file
|
|
15501
|
+
// or an agent's session, whose transcript would then hold the key.
|
|
15502
|
+
const keyReadRefusal = (name) => automatedMarker
|
|
15503
|
+
? `loom secrets ${name} reads a key, so it only runs for a person at a terminal, and this is an automated or agent session. A key must not be typed into, or read by, such a session. An operator runs it personally, in their own terminal.`
|
|
15504
|
+
: !stdinIsTty
|
|
15505
|
+
? `loom secrets ${name} reads the key from a hidden terminal prompt, so its input must be a terminal. Never pass a key as an argument, through a pipe, or from a file. Run it yourself, in your own terminal.`
|
|
15506
|
+
: null;
|
|
15086
15507
|
try {
|
|
15087
15508
|
switch (command) {
|
|
15088
15509
|
case "keygen": {
|
|
@@ -15101,6 +15522,29 @@ async function runSecrets(cwd, command, target, options, io, terminal = {}) {
|
|
|
15101
15522
|
io.err(`loom secrets keygen prints a production key, so it only runs for a person at a terminal, and ${refusal}. A production key must not be written to a pipe, a file, a log or an AI agent transcript. An operator runs it personally, in their own terminal.`);
|
|
15102
15523
|
return 1;
|
|
15103
15524
|
}
|
|
15525
|
+
// Asked for explicitly, Vercel must be reachable before a key exists:
|
|
15526
|
+
// finding out afterwards would leave a recorded key with nowhere to go.
|
|
15527
|
+
let vercel = null;
|
|
15528
|
+
let vercelNote = null;
|
|
15529
|
+
if (vercelChoice !== "no" && environment === "production") {
|
|
15530
|
+
const found = await findSecretsVercelTarget(cwd, commandRunner);
|
|
15531
|
+
const planned = await planSecretsKey(cwd, environment);
|
|
15532
|
+
if ("target" in found &&
|
|
15533
|
+
vercelVariables(found.target, planned.variableName).length) {
|
|
15534
|
+
// Drift between Vercel and loom.json, whether or not Vercel was
|
|
15535
|
+
// asked for; a key generated now would have nowhere to go.
|
|
15536
|
+
io.err(`${planned.variableName} already exists in Vercel Production, but loom.json has no such key. Find out why they differ before generating one. No key was generated.`);
|
|
15537
|
+
return 1;
|
|
15538
|
+
}
|
|
15539
|
+
if (!("target" in found) && vercelChoice === "yes") {
|
|
15540
|
+
io.err(`${found.reason} No key was generated.`);
|
|
15541
|
+
return 1;
|
|
15542
|
+
}
|
|
15543
|
+
if ("target" in found)
|
|
15544
|
+
vercel = found.target;
|
|
15545
|
+
else if (found.linked)
|
|
15546
|
+
vercelNote = found.reason;
|
|
15547
|
+
}
|
|
15104
15548
|
const result = await generateSecretsKey(cwd, { environment });
|
|
15105
15549
|
io.out(`Generated secrets key version ${result.id} for ${environment}. It is shown once and Loom keeps no copy.`);
|
|
15106
15550
|
io.out("");
|
|
@@ -15108,16 +15552,92 @@ async function runSecrets(cwd, command, target, options, io, terminal = {}) {
|
|
|
15108
15552
|
io.out(`Fingerprint: ${result.fingerprint}`);
|
|
15109
15553
|
io.out("");
|
|
15110
15554
|
io.out(`Recorded the fingerprint in loom.json as ${result.state}. Commit loom.json; it holds no key.`);
|
|
15555
|
+
let pushed = false;
|
|
15556
|
+
let go = false;
|
|
15557
|
+
if (vercel) {
|
|
15558
|
+
io.out("Save the key and its fingerprint in your password manager now, before anything else.");
|
|
15559
|
+
try {
|
|
15560
|
+
go = vercelChoice === "yes" || isYesAnswer(await ask(`Add ${result.variableName} (Secret, Production only)${result.state === "active"
|
|
15561
|
+
? ` and ${result.activeKeyName}=${result.id}`
|
|
15562
|
+
: ""} to Vercel project ${vercel.project}? [y/N] `));
|
|
15563
|
+
}
|
|
15564
|
+
catch {
|
|
15565
|
+
// An interrupted question is a no; the next steps still print.
|
|
15566
|
+
}
|
|
15567
|
+
if (go) {
|
|
15568
|
+
pushed = await pushSecretsKeyToVercel(cwd, commandRunner, vercel, result, {
|
|
15569
|
+
ask,
|
|
15570
|
+
prompt: prompt("Nothing was sent to Vercel.", "This needs a terminal."),
|
|
15571
|
+
}, io,
|
|
15572
|
+
// An explicit --vercel asks nothing more, so it leaves an
|
|
15573
|
+
// existing pointer alone and says so.
|
|
15574
|
+
{ replacePointer: vercelChoice === "yes" ? "no" : "ask" }).catch((error) => {
|
|
15575
|
+
io.err(`${error.message} Nothing was sent to Vercel.`);
|
|
15576
|
+
return false;
|
|
15577
|
+
});
|
|
15578
|
+
}
|
|
15579
|
+
}
|
|
15580
|
+
else if (vercelNote) {
|
|
15581
|
+
io.out(`Note: Vercel was not offered: ${vercelNote}`);
|
|
15582
|
+
}
|
|
15111
15583
|
io.out("Next steps:");
|
|
15112
|
-
|
|
15113
|
-
|
|
15114
|
-
|
|
15115
|
-
|
|
15116
|
-
|
|
15117
|
-
|
|
15584
|
+
const steps = [];
|
|
15585
|
+
if (!vercel) {
|
|
15586
|
+
steps.push("Save the key and its fingerprint in your password manager now, before anything else.");
|
|
15587
|
+
}
|
|
15588
|
+
if (!pushed) {
|
|
15589
|
+
steps.push(`Add ${result.variableName} to the deployment platform from the password-manager copy, ${platformTarget} only, as a write-only secret${result.state === "active"
|
|
15590
|
+
? `, and set ${result.activeKeyName}=${result.id} there`
|
|
15591
|
+
: ""}.${environment === "production"
|
|
15592
|
+
? ` On Vercel, \`loom secrets push ${result.id}\` checks the saved copy and does this for you.`
|
|
15593
|
+
: ""}`);
|
|
15594
|
+
}
|
|
15595
|
+
steps.push("Deploy.");
|
|
15596
|
+
steps.push(`Confirm \`secrets.assertReady()\` passes in the deployment: that proves the deployed key is the one you saved.${result.state === "active"
|
|
15118
15597
|
? ""
|
|
15119
15598
|
: ` Then switch to it with \`loom secrets activate ${result.id}\`.`}`);
|
|
15120
|
-
|
|
15599
|
+
steps.forEach((step, index) => io.out(` ${index + 1}. ${step}`));
|
|
15600
|
+
// The key exists either way; a push that was asked for and did not
|
|
15601
|
+
// happen is still a failure for whoever runs this.
|
|
15602
|
+
return go && !pushed ? 1 : 0;
|
|
15603
|
+
}
|
|
15604
|
+
case "push": {
|
|
15605
|
+
const id = target === undefined ? null : (0, keyring_js_1.parseSecretKeyId)(target);
|
|
15606
|
+
if (id === null) {
|
|
15607
|
+
io.err(usage);
|
|
15608
|
+
return 1;
|
|
15609
|
+
}
|
|
15610
|
+
if (options.vercel || options.noVercel) {
|
|
15611
|
+
io.err("loom secrets push always asks first; it takes no --vercel or --no-vercel.");
|
|
15612
|
+
return 1;
|
|
15613
|
+
}
|
|
15614
|
+
const refusal = keyReadRefusal("push");
|
|
15615
|
+
if (refusal) {
|
|
15616
|
+
io.err(refusal);
|
|
15617
|
+
return 1;
|
|
15618
|
+
}
|
|
15619
|
+
if (environment !== "production") {
|
|
15620
|
+
io.err("loom secrets push sets Vercel Production only. Set Preview variables yourself.");
|
|
15621
|
+
return 1;
|
|
15622
|
+
}
|
|
15623
|
+
const key = await recordedSecretsKey(cwd, id, environment);
|
|
15624
|
+
const found = await findSecretsVercelTarget(cwd, commandRunner);
|
|
15625
|
+
if (!("target" in found)) {
|
|
15626
|
+
io.err(found.reason);
|
|
15627
|
+
return 1;
|
|
15628
|
+
}
|
|
15629
|
+
if (!isYesAnswer(await ask(`Add ${key.variableName} (Secret, Production only)${key.state === "active"
|
|
15630
|
+
? ` and ${key.activeKeyName}=${key.id}`
|
|
15631
|
+
: ""} to Vercel project ${found.target.project}? [y/N] `))) {
|
|
15632
|
+
io.out("Nothing was changed.");
|
|
15633
|
+
return 0;
|
|
15634
|
+
}
|
|
15635
|
+
return await pushSecretsKeyToVercel(cwd, commandRunner, found.target, key, {
|
|
15636
|
+
ask,
|
|
15637
|
+
prompt: prompt("Nothing was sent to Vercel.", keyReadRefusal("push") ?? "This needs a terminal."),
|
|
15638
|
+
}, io, { replacePointer: "ask" })
|
|
15639
|
+
? 0
|
|
15640
|
+
: 1;
|
|
15121
15641
|
}
|
|
15122
15642
|
case "fingerprint": {
|
|
15123
15643
|
// Checked before anything else, and never echoed: whatever followed
|
|
@@ -15126,21 +15646,17 @@ async function runSecrets(cwd, command, target, options, io, terminal = {}) {
|
|
|
15126
15646
|
io.err(SECRETS_FINGERPRINT_ARGUMENT_REFUSAL);
|
|
15127
15647
|
return 1;
|
|
15128
15648
|
}
|
|
15129
|
-
if (
|
|
15130
|
-
io.err(
|
|
15649
|
+
if (options.vercel || options.noVercel) {
|
|
15650
|
+
io.err("loom secrets fingerprint changes nothing on Vercel.");
|
|
15131
15651
|
return 1;
|
|
15132
15652
|
}
|
|
15133
|
-
const
|
|
15134
|
-
if (
|
|
15135
|
-
io.err(
|
|
15653
|
+
const refusal = keyReadRefusal("fingerprint");
|
|
15654
|
+
if (refusal) {
|
|
15655
|
+
io.err(refusal);
|
|
15136
15656
|
return 1;
|
|
15137
15657
|
}
|
|
15138
|
-
const
|
|
15139
|
-
|
|
15140
|
-
cancelled: "Fingerprinting was cancelled.",
|
|
15141
|
-
notInteractive,
|
|
15142
|
-
}));
|
|
15143
|
-
io.out(await fingerprintSecretsKey(await prompt("Secrets key (input is hidden): ")));
|
|
15658
|
+
const readKey = prompt("Fingerprinting was cancelled.", "loom secrets fingerprint reads the key from a hidden terminal prompt, so its input must be a terminal. Never pass a key as an argument, through a pipe, or from a file. Run it yourself, in your own terminal.");
|
|
15659
|
+
io.out(await fingerprintSecretsKey(await readKey("Secrets key (input is hidden): ")));
|
|
15144
15660
|
return 0;
|
|
15145
15661
|
}
|
|
15146
15662
|
case "activate":
|
|
@@ -15151,13 +15667,78 @@ async function runSecrets(cwd, command, target, options, io, terminal = {}) {
|
|
|
15151
15667
|
return 1;
|
|
15152
15668
|
}
|
|
15153
15669
|
if (command === "activate") {
|
|
15154
|
-
|
|
15670
|
+
if (environment !== "production" && options.vercel) {
|
|
15671
|
+
io.err("--vercel sets Vercel Production only. Set Preview variables yourself.");
|
|
15672
|
+
return 1;
|
|
15673
|
+
}
|
|
15674
|
+
let pointerSet = false;
|
|
15675
|
+
let vercelNote = null;
|
|
15676
|
+
const result = await activateSecretsKey(cwd, id, environment, {
|
|
15677
|
+
// The platform's pointer moves first: a deployment carrying the
|
|
15678
|
+
// new list with the old pointer would fail every seal. A build
|
|
15679
|
+
// between the two, with the new pointer and the old list, fails
|
|
15680
|
+
// too, so loom.json should follow at once.
|
|
15681
|
+
beforeWrite: async (key) => {
|
|
15682
|
+
if (vercelChoice === "no" || environment !== "production") {
|
|
15683
|
+
return false;
|
|
15684
|
+
}
|
|
15685
|
+
const found = await findSecretsVercelTarget(cwd, commandRunner);
|
|
15686
|
+
const refusal = !("target" in found)
|
|
15687
|
+
? found.reason
|
|
15688
|
+
: !vercelVariables(found.target, key.variableName).length
|
|
15689
|
+
? `${key.variableName} is not in Vercel Production. Add it (\`loom secrets push ${id}\`) and deploy before activating it.`
|
|
15690
|
+
: vercelPointerProblem(found.target, key.activeKeyName);
|
|
15691
|
+
if (refusal) {
|
|
15692
|
+
if (vercelChoice === "yes") {
|
|
15693
|
+
throw new Error(`${refusal} loom.json was not changed.`);
|
|
15694
|
+
}
|
|
15695
|
+
if ("target" in found || found.linked)
|
|
15696
|
+
vercelNote = refusal;
|
|
15697
|
+
return false;
|
|
15698
|
+
}
|
|
15699
|
+
const vercel = found.target;
|
|
15700
|
+
if (vercelChoice === "ask" &&
|
|
15701
|
+
!isYesAnswer(await ask(`Set ${key.activeKeyName}=${id} in Vercel project ${vercel.project}, Production, before loom.json changes? [y/N] `).catch(() => ""))) {
|
|
15702
|
+
return false;
|
|
15703
|
+
}
|
|
15704
|
+
try {
|
|
15705
|
+
await setVercelPointer(cwd, commandRunner, vercel, key.activeKeyName, id);
|
|
15706
|
+
}
|
|
15707
|
+
catch (error) {
|
|
15708
|
+
throw new Error(`${error.message} loom.json was not changed.`);
|
|
15709
|
+
}
|
|
15710
|
+
pointerSet = true;
|
|
15711
|
+
io.out(`Set ${key.activeKeyName}=${id} in Vercel project ${vercel.project}, Production.`);
|
|
15712
|
+
// Team policy, or an existing Secret kept by `env update`, can
|
|
15713
|
+
// leave the pointer unreadable to the release build.
|
|
15714
|
+
try {
|
|
15715
|
+
warnIfPointerSecret({
|
|
15716
|
+
...vercel,
|
|
15717
|
+
variables: await listVercelProductionVariables(cwd, commandRunner, vercel.command, vercel.env),
|
|
15718
|
+
}, key.activeKeyName, io);
|
|
15719
|
+
}
|
|
15720
|
+
catch {
|
|
15721
|
+
// The pointer is set; how it is stored is a warning only.
|
|
15722
|
+
}
|
|
15723
|
+
return true;
|
|
15724
|
+
},
|
|
15725
|
+
});
|
|
15155
15726
|
io.out(result.changedFiles.length
|
|
15156
15727
|
? `Updated ${result.changedFiles.join(", ")}: key version ${id} is now the active ${environment} key.`
|
|
15157
15728
|
: `Key version ${id} is already the active ${environment} key in loom.json.`);
|
|
15158
|
-
|
|
15729
|
+
if (vercelNote)
|
|
15730
|
+
io.out(`Note: Vercel was not changed: ${vercelNote}`);
|
|
15731
|
+
io.out(pointerSet
|
|
15732
|
+
? "Next: run `loom check --production` and push this loom.json now. A production build made before it lands has the new pointer and the old list, and fails every seal."
|
|
15733
|
+
: `Note: Set ${result.activeKeyName}=${id} for ${platformTarget} on the deployment platform, before deploying this loom.json. Until both match, every seal fails (opens still work).${environment === "production"
|
|
15734
|
+
? " On Vercel, `--vercel` does this first."
|
|
15735
|
+
: ""}`);
|
|
15159
15736
|
return 0;
|
|
15160
15737
|
}
|
|
15738
|
+
if (options.vercel || options.noVercel) {
|
|
15739
|
+
io.err("loom secrets retire changes nothing on Vercel; remove the variable there yourself, after deploying the retired list.");
|
|
15740
|
+
return 1;
|
|
15741
|
+
}
|
|
15161
15742
|
const result = await retireSecretsKey(cwd, id, environment);
|
|
15162
15743
|
io.out(result.changedFiles.length
|
|
15163
15744
|
? `Updated ${result.changedFiles.join(", ")}: key version ${id} is now retired for ${environment}.`
|
|
@@ -16080,6 +16661,11 @@ async function runCli(args = node_process_1.default.argv.slice(2), io = {
|
|
|
16080
16661
|
io.err(SECRETS_FINGERPRINT_ARGUMENT_REFUSAL);
|
|
16081
16662
|
return 1;
|
|
16082
16663
|
}
|
|
16664
|
+
if (secretsIndex >= 0 && args[secretsIndex + 1] === "push" &&
|
|
16665
|
+
!secretsPushArgumentsAreSafe(args.slice(secretsIndex + 2))) {
|
|
16666
|
+
io.err(SECRETS_PUSH_ARGUMENT_REFUSAL);
|
|
16667
|
+
return 1;
|
|
16668
|
+
}
|
|
16083
16669
|
const parsed = (0, node_util_1.parseArgs)({
|
|
16084
16670
|
allowPositionals: true,
|
|
16085
16671
|
args,
|
|
@@ -16109,6 +16695,8 @@ async function runCli(args = node_process_1.default.argv.slice(2), io = {
|
|
|
16109
16695
|
"max-requests-per-key": { type: "string" },
|
|
16110
16696
|
"no-color": { type: "boolean" },
|
|
16111
16697
|
"no-progress": { type: "boolean" },
|
|
16698
|
+
"no-vercel": { type: "boolean" },
|
|
16699
|
+
vercel: { type: "boolean" },
|
|
16112
16700
|
"no-sync": { type: "boolean" },
|
|
16113
16701
|
network: { type: "boolean" },
|
|
16114
16702
|
"neon-auth": { type: "boolean" },
|
|
@@ -16215,7 +16803,11 @@ async function runCli(args = node_process_1.default.argv.slice(2), io = {
|
|
|
16215
16803
|
resource: parsed.values.resource,
|
|
16216
16804
|
}, io);
|
|
16217
16805
|
case "secrets":
|
|
16218
|
-
return await runSecrets(cwd, arg1, arg2, {
|
|
16806
|
+
return await runSecrets(cwd, arg1, arg2, {
|
|
16807
|
+
environment: parsed.values.environment,
|
|
16808
|
+
noVercel: parsed.values["no-vercel"],
|
|
16809
|
+
vercel: parsed.values.vercel,
|
|
16810
|
+
}, io, options.secretsTerminal, options.commandRunner);
|
|
16219
16811
|
case "skills":
|
|
16220
16812
|
return await runSkills(cwd, arg1, [arg2, ...rest].filter(Boolean), io, {
|
|
16221
16813
|
acceptUnknownLicense: parsed.values["accept-unknown-license"],
|