@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/esm/src/cli/mod.js
CHANGED
|
@@ -7982,16 +7982,29 @@ async function listVercelEnvironmentNames(cwd, commandRunner, env, vercelCommand
|
|
|
7982
7982
|
}
|
|
7983
7983
|
return result.stdout;
|
|
7984
7984
|
}
|
|
7985
|
-
|
|
7986
|
-
|
|
7985
|
+
/**
|
|
7986
|
+
* What a failed Vercel CLI call said. In an agent session the CLI reports
|
|
7987
|
+
* errors as JSON on stdout. Vercel does not echo a value it was given, but a
|
|
7988
|
+
* long one is masked anyway, in case a later version does.
|
|
7989
|
+
*/
|
|
7990
|
+
function vercelFailureDetail(result, value) {
|
|
7991
|
+
const detail = result.stderr.trim() || result.stdout.trim() ||
|
|
7992
|
+
`exit code ${result.code}`;
|
|
7993
|
+
return value.length >= 16 ? detail.split(value).join("[redacted]") : detail;
|
|
7994
|
+
}
|
|
7995
|
+
async function addVercelEnvValue(cwd, commandRunner, env, vercelCommand, name, value, environment, extraArgs = []) {
|
|
7996
|
+
// The value goes on stdin, never into the arguments, where the process
|
|
7997
|
+
// list and shell history would show it.
|
|
7998
|
+
const result = await commandRunner(vercelCommand, ["env", "add", name, environment, ...extraArgs], { cwd, env, input: `${value}\n`, stdio: "pipe" });
|
|
7987
7999
|
if (result.code !== 0) {
|
|
7988
|
-
throw new Error(`Could not add ${name} to Vercel ${environment}: ${result
|
|
8000
|
+
throw new Error(`Could not add ${name} to Vercel ${environment}: ${vercelFailureDetail(result, value)}`);
|
|
7989
8001
|
}
|
|
7990
8002
|
}
|
|
7991
8003
|
async function updateVercelEnvValue(cwd, commandRunner, env, vercelCommand, name, value, environment) {
|
|
8004
|
+
// No type flag: `env update` keeps the variable's existing type.
|
|
7992
8005
|
const result = await commandRunner(vercelCommand, ["env", "update", name, environment, "--yes"], { cwd, env, input: `${value}\n`, stdio: "pipe" });
|
|
7993
8006
|
if (result.code !== 0) {
|
|
7994
|
-
throw new Error(`Could not update ${name} in Vercel ${environment}: ${result
|
|
8007
|
+
throw new Error(`Could not update ${name} in Vercel ${environment}: ${vercelFailureDetail(result, value)}`);
|
|
7995
8008
|
}
|
|
7996
8009
|
}
|
|
7997
8010
|
async function promptForVercelSecret(cwd, commandRunner, env, vercelCommand, name, environment) {
|
|
@@ -8029,10 +8042,38 @@ function buildVercelFilesEnvListArgs(environment, project) {
|
|
|
8029
8042
|
}
|
|
8030
8043
|
function withoutInheritedVercelProject(env) {
|
|
8031
8044
|
const result = { ...env };
|
|
8032
|
-
|
|
8033
|
-
|
|
8045
|
+
// The Vercel CLI still honours the older NOW_* names too.
|
|
8046
|
+
for (const name of [
|
|
8047
|
+
"VERCEL_ORG_ID",
|
|
8048
|
+
"VERCEL_PROJECT_ID",
|
|
8049
|
+
"NOW_ORG_ID",
|
|
8050
|
+
"NOW_PROJECT_ID",
|
|
8051
|
+
]) {
|
|
8052
|
+
delete result[name];
|
|
8053
|
+
}
|
|
8034
8054
|
return result;
|
|
8035
8055
|
}
|
|
8056
|
+
/**
|
|
8057
|
+
* Which of `names` Vercel stores as Secrets for `environment`, or null when
|
|
8058
|
+
* the JSON listing is unavailable. A Secret reads back empty, so it looks like
|
|
8059
|
+
* drift, but `vercel env update` keeps a variable's type and cannot fix it.
|
|
8060
|
+
*/
|
|
8061
|
+
async function findVercelFilesValuesStoredAsSecrets(cwd, commandRunner, env, vercelCommand, environment, listArgs, names) {
|
|
8062
|
+
const result = await commandRunner(vercelCommand, [...listArgs, "--format", "json"], { cwd, env, stdio: "pipe" });
|
|
8063
|
+
if (result.code !== 0)
|
|
8064
|
+
return null;
|
|
8065
|
+
const variables = parseVercelEnvListing(result.stdout);
|
|
8066
|
+
if (!variables)
|
|
8067
|
+
return null;
|
|
8068
|
+
return names.filter((name) => variables.some((variable) => variable.key === name && variable.secret &&
|
|
8069
|
+
variable.targets.includes(environment)));
|
|
8070
|
+
}
|
|
8071
|
+
function filesSecretTypeProblem(environment, names) {
|
|
8072
|
+
return `Vercel ${environment} stores ${names.join(", ")} as Secrets, so their values cannot be read back, and \`vercel env update\` keeps a Secret a Secret.`;
|
|
8073
|
+
}
|
|
8074
|
+
function filesSecretTypeFix(environment) {
|
|
8075
|
+
return `Remove them from Vercel ${environment}, then run \`loom files r2 setup\` to add them back as readable values.`;
|
|
8076
|
+
}
|
|
8036
8077
|
async function readVercelFilesNonSecretValues(cwd, commandRunner, env, vercelCommand, environment) {
|
|
8037
8078
|
const link = await readVercelProjectLink(cwd);
|
|
8038
8079
|
if (!link.linked || !link.orgId || !link.projectId)
|
|
@@ -8115,11 +8156,11 @@ async function ensureMinioBucket(cwd, commandRunner, env, endpoint, bucket, acce
|
|
|
8115
8156
|
* is read in raw mode so it is never echoed. Refuses when stdin is not a
|
|
8116
8157
|
* terminal, with the caller's explanation of what to do instead.
|
|
8117
8158
|
*/
|
|
8118
|
-
async function promptForTerminalValue(question, secret, messages) {
|
|
8159
|
+
async function promptForTerminalValue(question, secret, messages, options = {}) {
|
|
8119
8160
|
if (!process.stdin.isTTY) {
|
|
8120
8161
|
throw new Error(messages.notInteractive);
|
|
8121
8162
|
}
|
|
8122
|
-
if (!secret) {
|
|
8163
|
+
if (!secret && !options.rawEcho) {
|
|
8123
8164
|
const input = createInterface({
|
|
8124
8165
|
input: process.stdin,
|
|
8125
8166
|
output: process.stderr,
|
|
@@ -8153,9 +8194,13 @@ async function promptForTerminalValue(question, secret, messages) {
|
|
|
8153
8194
|
return;
|
|
8154
8195
|
}
|
|
8155
8196
|
if (character === "\u007f" || character === "\b") {
|
|
8197
|
+
if (options.rawEcho && value)
|
|
8198
|
+
process.stderr.write("\b \b");
|
|
8156
8199
|
value = value.slice(0, -1);
|
|
8157
8200
|
}
|
|
8158
8201
|
else {
|
|
8202
|
+
if (options.rawEcho)
|
|
8203
|
+
process.stderr.write(character);
|
|
8159
8204
|
value += character;
|
|
8160
8205
|
}
|
|
8161
8206
|
}
|
|
@@ -8833,6 +8878,12 @@ export async function setupCloudflareR2(cwd, options = {}) {
|
|
|
8833
8878
|
throw new Error(`Could not inspect existing non-secret Files values in Vercel ${environment}.`);
|
|
8834
8879
|
}
|
|
8835
8880
|
const drift = existingNonSecretNames.filter((name) => actualValues[name] !== nonSecretValues[name]);
|
|
8881
|
+
const storedAsSecrets = drift.length
|
|
8882
|
+
? await findVercelFilesValuesStoredAsSecrets(cwd, commandRunner, providerEnv, vercelCli.command, environment, ["env", "ls", environment], drift)
|
|
8883
|
+
: null;
|
|
8884
|
+
if (storedAsSecrets?.length) {
|
|
8885
|
+
throw new Error(`${filesSecretTypeProblem(environment, storedAsSecrets)} ${filesSecretTypeFix(environment)}`);
|
|
8886
|
+
}
|
|
8836
8887
|
if (drift.length && !options.repair) {
|
|
8837
8888
|
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.`);
|
|
8838
8889
|
}
|
|
@@ -8842,7 +8893,11 @@ export async function setupCloudflareR2(cwd, options = {}) {
|
|
|
8842
8893
|
}
|
|
8843
8894
|
for (const [name, value] of Object.entries(nonSecretValues)) {
|
|
8844
8895
|
if (!hasExactEnvName(listing, name)) {
|
|
8845
|
-
await addVercelEnvValue(cwd, commandRunner, providerEnv, vercelCli.command, name, value, environment
|
|
8896
|
+
await addVercelEnvValue(cwd, commandRunner, providerEnv, vercelCli.command, name, value, environment,
|
|
8897
|
+
// Vercel CLI stores a Production or Preview value read from
|
|
8898
|
+
// stdin as a Secret unless told otherwise, and the env-run probe
|
|
8899
|
+
// and release env policies must be able to read these back.
|
|
8900
|
+
["--no-sensitive", "--yes"]);
|
|
8846
8901
|
listing += `\n${name}`;
|
|
8847
8902
|
}
|
|
8848
8903
|
}
|
|
@@ -8950,6 +9005,9 @@ async function readVercelProjectLink(cwd) {
|
|
|
8950
9005
|
linked: true,
|
|
8951
9006
|
orgId,
|
|
8952
9007
|
projectId,
|
|
9008
|
+
projectName: typeof project.projectName === "string"
|
|
9009
|
+
? project.projectName
|
|
9010
|
+
: null,
|
|
8953
9011
|
relativePath,
|
|
8954
9012
|
};
|
|
8955
9013
|
}
|
|
@@ -9872,6 +9930,23 @@ function checkFilesNetworkFeature(context) {
|
|
|
9872
9930
|
FILES_S3_FORCE_PATH_STYLE: String(provider.forcePathStyle ?? false),
|
|
9873
9931
|
};
|
|
9874
9932
|
const drift = Object.entries(expectedValues).filter(([name, value]) => actualValues[name] !== value).map(([name]) => name);
|
|
9933
|
+
const storedAsSecrets = drift.length
|
|
9934
|
+
? await findVercelFilesValuesStoredAsSecrets(context.cwd, context.commandRunner, withoutInheritedVercelProject(context.env), state.vercelCommand, environment, buildVercelFilesEnvListArgs(environment, state.vercelProject), drift)
|
|
9935
|
+
: null;
|
|
9936
|
+
if (storedAsSecrets?.length) {
|
|
9937
|
+
const otherDrift = drift.filter((name) => !storedAsSecrets.includes(name));
|
|
9938
|
+
return networkCheckResult("issue", `Vercel ${environment} stores non-secret Files values as Secrets: ${storedAsSecrets.join(", ")}.`, {
|
|
9939
|
+
issues: [
|
|
9940
|
+
filesSecretTypeProblem(environment, storedAsSecrets),
|
|
9941
|
+
...(otherDrift.length
|
|
9942
|
+
? [
|
|
9943
|
+
`Vercel ${environment} has incompatible non-secret Files R2 values: ${otherDrift.join(", ")}.`,
|
|
9944
|
+
]
|
|
9945
|
+
: []),
|
|
9946
|
+
],
|
|
9947
|
+
suggestions: [filesSecretTypeFix(environment)],
|
|
9948
|
+
});
|
|
9949
|
+
}
|
|
9875
9950
|
return drift.length
|
|
9876
9951
|
? networkCheckResult("issue", `Vercel ${environment} Files values drift from loom.json: ${drift.join(", ")}.`, {
|
|
9877
9952
|
issues: [
|
|
@@ -10857,7 +10932,7 @@ async function applySecretsFeature(cwd, framework, manifest, activate, options =
|
|
|
10857
10932
|
changedFiles.push(...localKey.changedFiles);
|
|
10858
10933
|
notes.push(...localKey.notes);
|
|
10859
10934
|
if (!Array.isArray(config.keys.production) || !config.keys.production.length) {
|
|
10860
|
-
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.");
|
|
10935
|
+
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.");
|
|
10861
10936
|
}
|
|
10862
10937
|
}
|
|
10863
10938
|
feature.config = mergeSecretsConfig(currentFeature?.config, config);
|
|
@@ -13712,7 +13787,7 @@ async function checkSecretsFeature(cwd, framework, manifest, options) {
|
|
|
13712
13787
|
}
|
|
13713
13788
|
if (Array.isArray(config.keys.production) && config.keys.production.length === 0) {
|
|
13714
13789
|
releaseBlocking("No production secrets key is recorded in loom.json, so production would run with unverified keys.");
|
|
13715
|
-
suggestions.add("Have an operator run `loom secrets keygen` in their own terminal, then commit the recorded fingerprint.");
|
|
13790
|
+
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.");
|
|
13716
13791
|
}
|
|
13717
13792
|
const policyText = await readTextIfExists(join(cwd, VERCEL_PRODUCTION_ENV_POLICY_PATH));
|
|
13718
13793
|
if (policyText !== null) {
|
|
@@ -13947,15 +14022,18 @@ function recordedSecretKeys(config, environment) {
|
|
|
13947
14022
|
return recorded;
|
|
13948
14023
|
}
|
|
13949
14024
|
/** Validates a changed key list, then records it in loom.json. */
|
|
13950
|
-
|
|
13951
|
-
if (keys.length)
|
|
13952
|
-
|
|
13953
|
-
|
|
13954
|
-
|
|
13955
|
-
catch (error) {
|
|
13956
|
-
throw new Error(`The ${environment} key list in loom.json would be invalid: ${error.message}`);
|
|
13957
|
-
}
|
|
14025
|
+
function validateSecretKeys(environment, keys) {
|
|
14026
|
+
if (!keys.length)
|
|
14027
|
+
return;
|
|
14028
|
+
try {
|
|
14029
|
+
parseExpectedSecretKeys(keys);
|
|
13958
14030
|
}
|
|
14031
|
+
catch (error) {
|
|
14032
|
+
throw new Error(`The ${environment} key list in loom.json would be invalid: ${error.message}`);
|
|
14033
|
+
}
|
|
14034
|
+
}
|
|
14035
|
+
async function writeSecretKeys(cwd, loaded, environment, keys) {
|
|
14036
|
+
validateSecretKeys(environment, keys);
|
|
13959
14037
|
// Replaces this one list and nothing else: any other property a user keeps
|
|
13960
14038
|
// under `config` or `config.keys` is theirs, and stays.
|
|
13961
14039
|
const existing = isJsonObject(loaded.feature.config)
|
|
@@ -13973,6 +14051,49 @@ async function writeSecretKeys(cwd, loaded, environment, keys) {
|
|
|
13973
14051
|
? ["loom.json"]
|
|
13974
14052
|
: [];
|
|
13975
14053
|
}
|
|
14054
|
+
function nextSecretsKey(config, environment) {
|
|
14055
|
+
const current = recordedSecretKeys(config, environment);
|
|
14056
|
+
const id = current.reduce((highest, key) => isSecretKeyId(key?.id) ? Math.max(highest, key.id) : highest, 0) + 1;
|
|
14057
|
+
const state = current.some((key) => key?.state === "active")
|
|
14058
|
+
? "decrypt-only"
|
|
14059
|
+
: "active";
|
|
14060
|
+
return { current, id, state };
|
|
14061
|
+
}
|
|
14062
|
+
/**
|
|
14063
|
+
* The version, state and variable names `generateSecretsKey` would use next,
|
|
14064
|
+
* without generating or recording anything.
|
|
14065
|
+
*/
|
|
14066
|
+
export async function planSecretsKey(cwd, environment = "production") {
|
|
14067
|
+
const loaded = await readActiveSecretsFeature(cwd);
|
|
14068
|
+
const { id, state } = nextSecretsKey(loaded.config, environment);
|
|
14069
|
+
return {
|
|
14070
|
+
activeKeyName: loaded.config.env.activeKeyName,
|
|
14071
|
+
id,
|
|
14072
|
+
state,
|
|
14073
|
+
variableName: `${loaded.config.env.keyPrefix}${id}`,
|
|
14074
|
+
};
|
|
14075
|
+
}
|
|
14076
|
+
/**
|
|
14077
|
+
* A recorded key that is not retired, with its variable names, for putting it
|
|
14078
|
+
* on a deployment platform. Refuses a version that is not listed or retired.
|
|
14079
|
+
*/
|
|
14080
|
+
export async function recordedSecretsKey(cwd, id, environment = "production") {
|
|
14081
|
+
const loaded = await readActiveSecretsFeature(cwd);
|
|
14082
|
+
const key = recordedSecretKeys(loaded.config, environment).find((entry) => entry?.id === id);
|
|
14083
|
+
if (!key) {
|
|
14084
|
+
throw new Error(`Key version ${id} is not listed for ${environment} in loom.json.`);
|
|
14085
|
+
}
|
|
14086
|
+
if (key.state === "retired") {
|
|
14087
|
+
throw new Error(`Key version ${id} is retired for ${environment}.`);
|
|
14088
|
+
}
|
|
14089
|
+
return {
|
|
14090
|
+
activeKeyName: loaded.config.env.activeKeyName,
|
|
14091
|
+
fingerprint: key.fingerprint,
|
|
14092
|
+
id,
|
|
14093
|
+
state: key.state,
|
|
14094
|
+
variableName: `${loaded.config.env.keyPrefix}${id}`,
|
|
14095
|
+
};
|
|
14096
|
+
}
|
|
13976
14097
|
/**
|
|
13977
14098
|
* Generates a key for a deployed environment and records its fingerprint in
|
|
13978
14099
|
* loom.json: `active` when the environment has no active key, otherwise
|
|
@@ -13986,11 +14107,7 @@ async function writeSecretKeys(cwd, loaded, environment, keys) {
|
|
|
13986
14107
|
export async function generateSecretsKey(cwd, options = {}) {
|
|
13987
14108
|
const environment = options.environment ?? "production";
|
|
13988
14109
|
const loaded = await readActiveSecretsFeature(cwd);
|
|
13989
|
-
const current =
|
|
13990
|
-
const id = current.reduce((highest, key) => isSecretKeyId(key?.id) ? Math.max(highest, key.id) : highest, 0) + 1;
|
|
13991
|
-
const state = current.some((key) => key?.state === "active")
|
|
13992
|
-
? "decrypt-only"
|
|
13993
|
-
: "active";
|
|
14110
|
+
const { current, id, state } = nextSecretsKey(loaded.config, environment);
|
|
13994
14111
|
const key = globalThis.crypto.getRandomValues(new Uint8Array(SECRETS_KEY_BYTES));
|
|
13995
14112
|
const fingerprint = await secretKeyFingerprint(key);
|
|
13996
14113
|
const changedFiles = await writeSecretKeys(cwd, loaded, environment, [
|
|
@@ -14020,8 +14137,12 @@ export async function fingerprintSecretsKey(value) {
|
|
|
14020
14137
|
/**
|
|
14021
14138
|
* Marks a recorded key `active` in loom.json and the previously active key
|
|
14022
14139
|
* `decrypt-only`. Refuses a version that is not listed or is retired.
|
|
14140
|
+
*
|
|
14141
|
+
* `beforeWrite` runs once those checks pass and before loom.json changes, so
|
|
14142
|
+
* the platform's pointer can be moved first; if it throws, loom.json is left
|
|
14143
|
+
* as it was.
|
|
14023
14144
|
*/
|
|
14024
|
-
export async function activateSecretsKey(cwd, id, environment = "production") {
|
|
14145
|
+
export async function activateSecretsKey(cwd, id, environment = "production", options = {}) {
|
|
14025
14146
|
const loaded = await readActiveSecretsFeature(cwd);
|
|
14026
14147
|
const current = recordedSecretKeys(loaded.config, environment);
|
|
14027
14148
|
const target = current.find((key) => key?.id === id);
|
|
@@ -14031,11 +14152,36 @@ export async function activateSecretsKey(cwd, id, environment = "production") {
|
|
|
14031
14152
|
if (target.state === "retired") {
|
|
14032
14153
|
throw new Error(`Key version ${id} is retired and cannot be activated. Generate a new key with \`loom secrets keygen\`.`);
|
|
14033
14154
|
}
|
|
14034
|
-
const
|
|
14155
|
+
const next = current.map((key) => key?.id === id
|
|
14035
14156
|
? { ...key, state: "active" }
|
|
14036
14157
|
: key?.state === "active"
|
|
14037
14158
|
? { ...key, state: "decrypt-only" }
|
|
14038
|
-
: key)
|
|
14159
|
+
: key);
|
|
14160
|
+
// Checked before the hook, which may change a deployment platform: that
|
|
14161
|
+
// must not happen for a list that could not then be written.
|
|
14162
|
+
validateSecretKeys(environment, next);
|
|
14163
|
+
if (!options.beforeWrite) {
|
|
14164
|
+
return {
|
|
14165
|
+
activeKeyName: loaded.config.env.activeKeyName,
|
|
14166
|
+
changedFiles: await writeSecretKeys(cwd, loaded, environment, next),
|
|
14167
|
+
environment,
|
|
14168
|
+
id,
|
|
14169
|
+
};
|
|
14170
|
+
}
|
|
14171
|
+
const changedOutside = await options.beforeWrite({
|
|
14172
|
+
activeKeyName: loaded.config.env.activeKeyName,
|
|
14173
|
+
id,
|
|
14174
|
+
variableName: `${loaded.config.env.keyPrefix}${id}`,
|
|
14175
|
+
});
|
|
14176
|
+
let changedFiles;
|
|
14177
|
+
try {
|
|
14178
|
+
changedFiles = await writeSecretKeys(cwd, loaded, environment, next);
|
|
14179
|
+
}
|
|
14180
|
+
catch (error) {
|
|
14181
|
+
if (!changedOutside)
|
|
14182
|
+
throw error;
|
|
14183
|
+
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.`);
|
|
14184
|
+
}
|
|
14039
14185
|
return {
|
|
14040
14186
|
activeKeyName: loaded.config.env.activeKeyName,
|
|
14041
14187
|
changedFiles,
|
|
@@ -14869,9 +15015,10 @@ function printHelp({ out }) {
|
|
|
14869
15015
|
out(" files r2 check Verify R2 buckets/account/privacy, Vercel env scoping, local storage, and Files adapter wiring.");
|
|
14870
15016
|
out(" api-keys integrate jobs Record an explicit API-key jobs integration after the route has session/admin authorization.");
|
|
14871
15017
|
out(" api-keys retention enable|disable Record API-key audit cleanup policy; scheduling remains app-owned.");
|
|
14872
|
-
out(" secrets keygen Generate a production secrets key, print it once to a terminal, and record its fingerprint in loom.json.");
|
|
15018
|
+
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.");
|
|
15019
|
+
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.");
|
|
14873
15020
|
out(" secrets fingerprint Read a secrets key from a hidden terminal prompt and print only its fingerprint.");
|
|
14874
|
-
out(" secrets activate <id> Record a listed secrets key as the active one; the previous active key becomes decrypt-only.");
|
|
15021
|
+
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.");
|
|
14875
15022
|
out(" secrets retire <id> Record a secrets key that nothing needs any more as retired.");
|
|
14876
15023
|
out(" status Show the Loom package, manifest, active features, local-dev state, and project skill state.");
|
|
14877
15024
|
out(" check Validate project bootstrap, managed guidance, features, skill locks, caches, and links.");
|
|
@@ -14904,6 +15051,7 @@ function printHelp({ out }) {
|
|
|
14904
15051
|
out(" --network Run registered network checks after the local project checks.");
|
|
14905
15052
|
out(" --production Treat local Loom dev overrides and local lockfile resolutions as release-blocking check failures.");
|
|
14906
15053
|
out(" --no-progress Disable the interactive network progress renderer.");
|
|
15054
|
+
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.");
|
|
14907
15055
|
out(" --local-db-host <host> Local PostgreSQL host (default: db.localtest.me).");
|
|
14908
15056
|
out(" --local-db-port <port> Local PostgreSQL port (default: 5432).");
|
|
14909
15057
|
out(" --replace-local-target Replace an existing development URL during local DB setup.");
|
|
@@ -14976,6 +15124,29 @@ async function runApiKeys(cwd, command, target, options, io) {
|
|
|
14976
15124
|
io.out(`Note: ${note}`);
|
|
14977
15125
|
return 0;
|
|
14978
15126
|
}
|
|
15127
|
+
/**
|
|
15128
|
+
* Whether what follows `loom secrets push` is only a version number and
|
|
15129
|
+
* options Loom knows. Anything else may be a key typed in the wrong place,
|
|
15130
|
+
* which the argument parser would quote back in its error.
|
|
15131
|
+
*/
|
|
15132
|
+
function secretsPushArgumentsAreSafe(rest) {
|
|
15133
|
+
const flags = ["--vercel", "--no-vercel", "--no-color", "--help", "-h"];
|
|
15134
|
+
const withValue = ["--cwd", "--environment"];
|
|
15135
|
+
for (let index = 0; index < rest.length; index += 1) {
|
|
15136
|
+
const arg = rest[index];
|
|
15137
|
+
if (/^[1-9][0-9]{0,8}$/.test(arg) || flags.includes(arg))
|
|
15138
|
+
continue;
|
|
15139
|
+
if (withValue.some((name) => arg.startsWith(`${name}=`)))
|
|
15140
|
+
continue;
|
|
15141
|
+
if (withValue.includes(arg) && index + 1 < rest.length) {
|
|
15142
|
+
index += 1;
|
|
15143
|
+
continue;
|
|
15144
|
+
}
|
|
15145
|
+
return false;
|
|
15146
|
+
}
|
|
15147
|
+
return true;
|
|
15148
|
+
}
|
|
15149
|
+
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.";
|
|
14979
15150
|
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.";
|
|
14980
15151
|
/**
|
|
14981
15152
|
* Variables that an automated or agent session sets. A key must not be shown
|
|
@@ -14991,13 +15162,239 @@ const AUTOMATED_SESSION_ENV_NAMES = [
|
|
|
14991
15162
|
"CURSOR_AGENT",
|
|
14992
15163
|
"GEMINI_CLI",
|
|
14993
15164
|
];
|
|
14994
|
-
|
|
14995
|
-
|
|
15165
|
+
/**
|
|
15166
|
+
* Whether a command may change something outside the repository, such as a
|
|
15167
|
+
* deployment platform's settings. An explicit flag decides. Without one, only
|
|
15168
|
+
* a person at a terminal is asked, and the default answer is no; anywhere
|
|
15169
|
+
* else nothing outside changes and the command says how to do it instead.
|
|
15170
|
+
* See "CLI prompts and outside changes" in AGENTS.md.
|
|
15171
|
+
*/
|
|
15172
|
+
export function resolveOutsideChange(flags, interactive) {
|
|
15173
|
+
if (flags.yes)
|
|
15174
|
+
return "yes";
|
|
15175
|
+
if (flags.no)
|
|
15176
|
+
return "no";
|
|
15177
|
+
return interactive ? "ask" : "no";
|
|
15178
|
+
}
|
|
15179
|
+
const isYesAnswer = (answer) => /^y(es)?$/i.test(answer.trim());
|
|
15180
|
+
/**
|
|
15181
|
+
* Parses `vercel env ls --format json` output, or returns null when it is not
|
|
15182
|
+
* that listing. Vercel CLI 54 and newer print it.
|
|
15183
|
+
*/
|
|
15184
|
+
function parseVercelEnvListing(text) {
|
|
15185
|
+
let parsed;
|
|
15186
|
+
try {
|
|
15187
|
+
parsed = JSON.parse(text.slice(text.indexOf("{"), text.lastIndexOf("}") + 1));
|
|
15188
|
+
}
|
|
15189
|
+
catch {
|
|
15190
|
+
return null;
|
|
15191
|
+
}
|
|
15192
|
+
const envs = isJsonObject(parsed) ? parsed.envs : undefined;
|
|
15193
|
+
if (!Array.isArray(envs))
|
|
15194
|
+
return null;
|
|
15195
|
+
return envs.flatMap((entry) => {
|
|
15196
|
+
if (!isJsonObject(entry) || typeof entry.key !== "string")
|
|
15197
|
+
return [];
|
|
15198
|
+
const targets = (Array.isArray(entry.target) ? entry.target : [entry.target])
|
|
15199
|
+
.filter((target) => typeof target === "string");
|
|
15200
|
+
return [{
|
|
15201
|
+
custom: Array.isArray(entry.customEnvironmentIds) &&
|
|
15202
|
+
entry.customEnvironmentIds.length > 0,
|
|
15203
|
+
key: entry.key,
|
|
15204
|
+
secret: entry.type === "sensitive" || entry.visibility === "secret",
|
|
15205
|
+
targets,
|
|
15206
|
+
type: typeof entry.type === "string" ? entry.type : "",
|
|
15207
|
+
}];
|
|
15208
|
+
});
|
|
15209
|
+
}
|
|
15210
|
+
async function listVercelProductionVariables(cwd, commandRunner, command, env) {
|
|
15211
|
+
// JSON, not the table: the table cannot tell a variable that applies to
|
|
15212
|
+
// Production alone from one shared with Preview, and a name could appear
|
|
15213
|
+
// inside another variable's displayed value.
|
|
15214
|
+
const result = await commandRunner(command, ["env", "ls", "production", "--format", "json"], { cwd, env, stdio: "pipe" });
|
|
15215
|
+
if (result.code !== 0) {
|
|
15216
|
+
throw new Error(`Could not list Vercel Production variables: ${vercelFailureDetail(result, "")}`);
|
|
15217
|
+
}
|
|
15218
|
+
const variables = parseVercelEnvListing(result.stdout);
|
|
15219
|
+
if (!variables) {
|
|
15220
|
+
throw new Error("Vercel did not list Production variables as JSON.");
|
|
15221
|
+
}
|
|
15222
|
+
return variables.filter((variable) => variable.targets.includes("production"));
|
|
15223
|
+
}
|
|
15224
|
+
const vercelVariables = (target, key) => target.variables.filter((variable) => variable.key === key);
|
|
15225
|
+
/**
|
|
15226
|
+
* Why the pointer cannot simply be updated for Production, or null when it
|
|
15227
|
+
* can. A variable shared with Preview would move its pointer too, and Preview
|
|
15228
|
+
* has a key list of its own. Sharing with a custom environment is not in
|
|
15229
|
+
* Vercel's listing, so it cannot be seen here.
|
|
15230
|
+
*/
|
|
15231
|
+
function vercelPointerProblem(target, name) {
|
|
15232
|
+
const found = vercelVariables(target, name);
|
|
15233
|
+
if (found.length === 0)
|
|
15234
|
+
return null;
|
|
15235
|
+
const shared = found.find((variable) => variable.custom || variable.targets.some((each) => each !== "production"));
|
|
15236
|
+
return found.length > 1 || shared
|
|
15237
|
+
? `${name} on Vercel is shared with ${shared
|
|
15238
|
+
? shared.targets.filter((each) => each !== "production").join(", ") ||
|
|
15239
|
+
"a custom environment"
|
|
15240
|
+
: "another entry"}. Give Production its own ${name} by hand, so the other environments keep theirs.`
|
|
15241
|
+
: null;
|
|
15242
|
+
}
|
|
15243
|
+
async function findSecretsVercelTarget(cwd, commandRunner) {
|
|
15244
|
+
const link = await readVercelProjectLink(cwd);
|
|
15245
|
+
if (!link.linked || !link.projectId) {
|
|
15246
|
+
return {
|
|
15247
|
+
linked: false,
|
|
15248
|
+
reason: `This project is not linked to Vercel: ${link.detail} Run \`vercel link\` first.`,
|
|
15249
|
+
};
|
|
15250
|
+
}
|
|
15251
|
+
// The link names the project; inherited ids would silently point the
|
|
15252
|
+
// writes somewhere else.
|
|
15253
|
+
const env = withoutInheritedVercelProject(process.env);
|
|
15254
|
+
const cli = await detectVercelCliCommand(cwd, commandRunner, env);
|
|
15255
|
+
if (!cli.command) {
|
|
15256
|
+
return {
|
|
15257
|
+
linked: true,
|
|
15258
|
+
reason: "The Vercel CLI (`vercel` or `vc`) was not found.",
|
|
15259
|
+
};
|
|
15260
|
+
}
|
|
15261
|
+
try {
|
|
15262
|
+
return {
|
|
15263
|
+
target: {
|
|
15264
|
+
command: cli.command,
|
|
15265
|
+
env,
|
|
15266
|
+
project: link.projectName ?? link.projectId,
|
|
15267
|
+
variables: await listVercelProductionVariables(cwd, commandRunner, cli.command, env),
|
|
15268
|
+
},
|
|
15269
|
+
};
|
|
15270
|
+
}
|
|
15271
|
+
catch (error) {
|
|
15272
|
+
return { linked: true, reason: error.message };
|
|
15273
|
+
}
|
|
15274
|
+
}
|
|
15275
|
+
function warnIfPointerSecret(target, name, io) {
|
|
15276
|
+
if (vercelVariables(target, name).some((variable) => variable.secret)) {
|
|
15277
|
+
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.`);
|
|
15278
|
+
}
|
|
15279
|
+
}
|
|
15280
|
+
/** Sets the pointer for Production only, as a readable variable. */
|
|
15281
|
+
async function setVercelPointer(cwd, commandRunner, target, name, id) {
|
|
15282
|
+
if (vercelVariables(target, name).length) {
|
|
15283
|
+
await updateVercelEnvValue(cwd, commandRunner, target.env, target.command, name, String(id), "production");
|
|
15284
|
+
}
|
|
15285
|
+
else {
|
|
15286
|
+
// Without --no-sensitive, a value given on stdin is stored as a Secret,
|
|
15287
|
+
// which `vercel pull` cannot read back for the release build.
|
|
15288
|
+
await addVercelEnvValue(cwd, commandRunner, target.env, target.command, name, String(id), "production", ["--no-sensitive", "--yes"]);
|
|
15289
|
+
}
|
|
15290
|
+
}
|
|
15291
|
+
/**
|
|
15292
|
+
* Puts a secrets key on Vercel Production as a Secret, and the pointer when
|
|
15293
|
+
* the key is the active one, from a copy the operator pastes back from their
|
|
15294
|
+
* password manager. That copy is checked against the fingerprint in loom.json
|
|
15295
|
+
* before Vercel gets it: a key that reached Vercel but not the password
|
|
15296
|
+
* manager could never be recovered, since Vercel never shows a Secret again.
|
|
15297
|
+
* Afterwards Vercel is listed again to confirm how it stored them.
|
|
15298
|
+
*/
|
|
15299
|
+
async function pushSecretsKeyToVercel(cwd, commandRunner, target, key, terminal, io, options) {
|
|
15300
|
+
if (vercelVariables(target, key.variableName).length) {
|
|
15301
|
+
io.err(`${key.variableName} already exists in Vercel Production. Loom never replaces a key there; find out why Vercel and loom.json differ first.`);
|
|
15302
|
+
return false;
|
|
15303
|
+
}
|
|
15304
|
+
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.`);
|
|
15305
|
+
let value = null;
|
|
15306
|
+
for (let attempt = 1; attempt <= 3 && value === null; attempt += 1) {
|
|
15307
|
+
let pasted = (await terminal.prompt(`${key.variableName} from your password manager (input is hidden): `)).trim();
|
|
15308
|
+
if (!pasted) {
|
|
15309
|
+
io.err("Nothing was entered, so nothing was sent to Vercel.");
|
|
15310
|
+
return false;
|
|
15311
|
+
}
|
|
15312
|
+
// The whole printed line is a likely thing to have saved.
|
|
15313
|
+
if (pasted.startsWith(`${key.variableName}=`)) {
|
|
15314
|
+
pasted = pasted.slice(key.variableName.length + 1).trim();
|
|
15315
|
+
}
|
|
15316
|
+
let fingerprint = null;
|
|
15317
|
+
try {
|
|
15318
|
+
fingerprint = await fingerprintSecretsKey(pasted);
|
|
15319
|
+
}
|
|
15320
|
+
catch {
|
|
15321
|
+
io.err("That is not a secrets key: it does not decode to 32 bytes. Check the saved copy.");
|
|
15322
|
+
continue;
|
|
15323
|
+
}
|
|
15324
|
+
if (fingerprint === key.fingerprint) {
|
|
15325
|
+
value = pasted;
|
|
15326
|
+
}
|
|
15327
|
+
else {
|
|
15328
|
+
io.err(`That is a different key from version ${key.id}: its fingerprint does not match loom.json. Check the saved copy.`);
|
|
15329
|
+
}
|
|
15330
|
+
}
|
|
15331
|
+
if (value === null) {
|
|
15332
|
+
io.err(`Nothing was sent to Vercel. Fix the saved copy, then run \`loom secrets push ${key.id}\`.`);
|
|
15333
|
+
return false;
|
|
15334
|
+
}
|
|
15335
|
+
let setPointer = key.state === "active";
|
|
15336
|
+
const pointerProblem = setPointer
|
|
15337
|
+
? vercelPointerProblem(target, key.activeKeyName)
|
|
15338
|
+
: null;
|
|
15339
|
+
if (pointerProblem)
|
|
15340
|
+
setPointer = false;
|
|
15341
|
+
else if (setPointer && vercelVariables(target, key.activeKeyName).length) {
|
|
15342
|
+
setPointer = options.replacePointer === "ask" &&
|
|
15343
|
+
isYesAnswer(await terminal.ask(`${key.activeKeyName} already exists in Vercel Production. Set it to ${key.id}? [y/N] `));
|
|
15344
|
+
}
|
|
15345
|
+
try {
|
|
15346
|
+
await addVercelEnvValue(cwd, commandRunner, target.env, target.command, key.variableName, value, "production", ["--sensitive", "--yes"]);
|
|
15347
|
+
}
|
|
15348
|
+
catch (error) {
|
|
15349
|
+
io.err(`${error.message} Nothing else was changed.`);
|
|
15350
|
+
return false;
|
|
15351
|
+
}
|
|
15352
|
+
if (setPointer) {
|
|
15353
|
+
try {
|
|
15354
|
+
await setVercelPointer(cwd, commandRunner, target, key.activeKeyName, key.id);
|
|
15355
|
+
}
|
|
15356
|
+
catch (error) {
|
|
15357
|
+
io.err(`${key.variableName} was added, but ${key.activeKeyName} was not: ${error.message} Set ${key.activeKeyName}=${key.id} in Vercel Production yourself.`);
|
|
15358
|
+
return false;
|
|
15359
|
+
}
|
|
15360
|
+
}
|
|
15361
|
+
// Confirm what Vercel stored, rather than trusting how it was asked.
|
|
15362
|
+
let stored;
|
|
15363
|
+
try {
|
|
15364
|
+
stored = await listVercelProductionVariables(cwd, commandRunner, target.command, target.env);
|
|
15365
|
+
}
|
|
15366
|
+
catch (error) {
|
|
15367
|
+
io.err(`Added ${key.variableName}, but could not confirm how Vercel stored it: ${error.message} Check it is a Secret for Production only.`);
|
|
15368
|
+
return false;
|
|
15369
|
+
}
|
|
15370
|
+
const confirmed = { ...target, variables: stored };
|
|
15371
|
+
const keyEntry = vercelVariables(confirmed, key.variableName);
|
|
15372
|
+
if (keyEntry.length !== 1 || !keyEntry[0].secret ||
|
|
15373
|
+
keyEntry[0].custom || keyEntry[0].targets.join() !== "production") {
|
|
15374
|
+
io.err(`Vercel did not store ${key.variableName} as a Secret for Production only. Fix it in Vercel before deploying.`);
|
|
15375
|
+
return false;
|
|
15376
|
+
}
|
|
15377
|
+
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.`);
|
|
15378
|
+
if (setPointer)
|
|
15379
|
+
warnIfPointerSecret(confirmed, key.activeKeyName, io);
|
|
15380
|
+
if (pointerProblem)
|
|
15381
|
+
io.err(pointerProblem);
|
|
15382
|
+
else if (key.state === "active" && !setPointer) {
|
|
15383
|
+
io.out(`Set ${key.activeKeyName}=${key.id} in Vercel Production before deploying.`);
|
|
15384
|
+
}
|
|
15385
|
+
return true;
|
|
15386
|
+
}
|
|
15387
|
+
async function runSecrets(cwd, command, target, options, io, terminal = {}, commandRunner = defaultCommandRunner) {
|
|
15388
|
+
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]";
|
|
14996
15389
|
const environmentOption = options.environment ?? "production";
|
|
14997
15390
|
if (environmentOption !== "production" && environmentOption !== "preview") {
|
|
14998
15391
|
io.err("--environment must be production or preview.");
|
|
14999
15392
|
return 1;
|
|
15000
15393
|
}
|
|
15394
|
+
if (options.vercel && options.noVercel) {
|
|
15395
|
+
io.err("--vercel and --no-vercel cannot be used together.");
|
|
15396
|
+
return 1;
|
|
15397
|
+
}
|
|
15001
15398
|
const environment = environmentOption;
|
|
15002
15399
|
const platformTarget = environment === "production"
|
|
15003
15400
|
? "Production"
|
|
@@ -15006,6 +15403,27 @@ async function runSecrets(cwd, command, target, options, io, terminal = {}) {
|
|
|
15006
15403
|
const stdoutIsTty = terminal.stdoutIsTty ?? Boolean(process.stdout.isTTY);
|
|
15007
15404
|
const sessionEnv = terminal.env ?? process.env;
|
|
15008
15405
|
const automatedMarker = AUTOMATED_SESSION_ENV_NAMES.find((name) => Boolean(sessionEnv[name]));
|
|
15406
|
+
const vercelChoice = resolveOutsideChange({ no: options.noVercel, yes: options.vercel }, stdinIsTty && stdoutIsTty && !automatedMarker);
|
|
15407
|
+
if (options.vercel && environment !== "production") {
|
|
15408
|
+
io.err("--vercel sets Vercel Production only. Set Preview variables yourself.");
|
|
15409
|
+
return 1;
|
|
15410
|
+
}
|
|
15411
|
+
// Raw mode rather than readline: under Deno a readline question never
|
|
15412
|
+
// settles on Ctrl-C, and the command would end without a word.
|
|
15413
|
+
const ask = terminal.ask ??
|
|
15414
|
+
((question) => promptForTerminalValue(question, false, {
|
|
15415
|
+
cancelled: "Cancelled.",
|
|
15416
|
+
notInteractive: "This question needs a terminal.",
|
|
15417
|
+
}, { rawEcho: true }));
|
|
15418
|
+
const prompt = (cancelled, notInteractive) => terminal.prompt ??
|
|
15419
|
+
((question) => promptForTerminalValue(question, true, { cancelled, notInteractive }));
|
|
15420
|
+
// Reading a key is only for a person at a terminal: never a pipe, a file
|
|
15421
|
+
// or an agent's session, whose transcript would then hold the key.
|
|
15422
|
+
const keyReadRefusal = (name) => automatedMarker
|
|
15423
|
+
? `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.`
|
|
15424
|
+
: !stdinIsTty
|
|
15425
|
+
? `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.`
|
|
15426
|
+
: null;
|
|
15009
15427
|
try {
|
|
15010
15428
|
switch (command) {
|
|
15011
15429
|
case "keygen": {
|
|
@@ -15024,6 +15442,29 @@ async function runSecrets(cwd, command, target, options, io, terminal = {}) {
|
|
|
15024
15442
|
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.`);
|
|
15025
15443
|
return 1;
|
|
15026
15444
|
}
|
|
15445
|
+
// Asked for explicitly, Vercel must be reachable before a key exists:
|
|
15446
|
+
// finding out afterwards would leave a recorded key with nowhere to go.
|
|
15447
|
+
let vercel = null;
|
|
15448
|
+
let vercelNote = null;
|
|
15449
|
+
if (vercelChoice !== "no" && environment === "production") {
|
|
15450
|
+
const found = await findSecretsVercelTarget(cwd, commandRunner);
|
|
15451
|
+
const planned = await planSecretsKey(cwd, environment);
|
|
15452
|
+
if ("target" in found &&
|
|
15453
|
+
vercelVariables(found.target, planned.variableName).length) {
|
|
15454
|
+
// Drift between Vercel and loom.json, whether or not Vercel was
|
|
15455
|
+
// asked for; a key generated now would have nowhere to go.
|
|
15456
|
+
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.`);
|
|
15457
|
+
return 1;
|
|
15458
|
+
}
|
|
15459
|
+
if (!("target" in found) && vercelChoice === "yes") {
|
|
15460
|
+
io.err(`${found.reason} No key was generated.`);
|
|
15461
|
+
return 1;
|
|
15462
|
+
}
|
|
15463
|
+
if ("target" in found)
|
|
15464
|
+
vercel = found.target;
|
|
15465
|
+
else if (found.linked)
|
|
15466
|
+
vercelNote = found.reason;
|
|
15467
|
+
}
|
|
15027
15468
|
const result = await generateSecretsKey(cwd, { environment });
|
|
15028
15469
|
io.out(`Generated secrets key version ${result.id} for ${environment}. It is shown once and Loom keeps no copy.`);
|
|
15029
15470
|
io.out("");
|
|
@@ -15031,16 +15472,92 @@ async function runSecrets(cwd, command, target, options, io, terminal = {}) {
|
|
|
15031
15472
|
io.out(`Fingerprint: ${result.fingerprint}`);
|
|
15032
15473
|
io.out("");
|
|
15033
15474
|
io.out(`Recorded the fingerprint in loom.json as ${result.state}. Commit loom.json; it holds no key.`);
|
|
15475
|
+
let pushed = false;
|
|
15476
|
+
let go = false;
|
|
15477
|
+
if (vercel) {
|
|
15478
|
+
io.out("Save the key and its fingerprint in your password manager now, before anything else.");
|
|
15479
|
+
try {
|
|
15480
|
+
go = vercelChoice === "yes" || isYesAnswer(await ask(`Add ${result.variableName} (Secret, Production only)${result.state === "active"
|
|
15481
|
+
? ` and ${result.activeKeyName}=${result.id}`
|
|
15482
|
+
: ""} to Vercel project ${vercel.project}? [y/N] `));
|
|
15483
|
+
}
|
|
15484
|
+
catch {
|
|
15485
|
+
// An interrupted question is a no; the next steps still print.
|
|
15486
|
+
}
|
|
15487
|
+
if (go) {
|
|
15488
|
+
pushed = await pushSecretsKeyToVercel(cwd, commandRunner, vercel, result, {
|
|
15489
|
+
ask,
|
|
15490
|
+
prompt: prompt("Nothing was sent to Vercel.", "This needs a terminal."),
|
|
15491
|
+
}, io,
|
|
15492
|
+
// An explicit --vercel asks nothing more, so it leaves an
|
|
15493
|
+
// existing pointer alone and says so.
|
|
15494
|
+
{ replacePointer: vercelChoice === "yes" ? "no" : "ask" }).catch((error) => {
|
|
15495
|
+
io.err(`${error.message} Nothing was sent to Vercel.`);
|
|
15496
|
+
return false;
|
|
15497
|
+
});
|
|
15498
|
+
}
|
|
15499
|
+
}
|
|
15500
|
+
else if (vercelNote) {
|
|
15501
|
+
io.out(`Note: Vercel was not offered: ${vercelNote}`);
|
|
15502
|
+
}
|
|
15034
15503
|
io.out("Next steps:");
|
|
15035
|
-
|
|
15036
|
-
|
|
15037
|
-
|
|
15038
|
-
|
|
15039
|
-
|
|
15040
|
-
|
|
15504
|
+
const steps = [];
|
|
15505
|
+
if (!vercel) {
|
|
15506
|
+
steps.push("Save the key and its fingerprint in your password manager now, before anything else.");
|
|
15507
|
+
}
|
|
15508
|
+
if (!pushed) {
|
|
15509
|
+
steps.push(`Add ${result.variableName} to the deployment platform from the password-manager copy, ${platformTarget} only, as a write-only secret${result.state === "active"
|
|
15510
|
+
? `, and set ${result.activeKeyName}=${result.id} there`
|
|
15511
|
+
: ""}.${environment === "production"
|
|
15512
|
+
? ` On Vercel, \`loom secrets push ${result.id}\` checks the saved copy and does this for you.`
|
|
15513
|
+
: ""}`);
|
|
15514
|
+
}
|
|
15515
|
+
steps.push("Deploy.");
|
|
15516
|
+
steps.push(`Confirm \`secrets.assertReady()\` passes in the deployment: that proves the deployed key is the one you saved.${result.state === "active"
|
|
15041
15517
|
? ""
|
|
15042
15518
|
: ` Then switch to it with \`loom secrets activate ${result.id}\`.`}`);
|
|
15043
|
-
|
|
15519
|
+
steps.forEach((step, index) => io.out(` ${index + 1}. ${step}`));
|
|
15520
|
+
// The key exists either way; a push that was asked for and did not
|
|
15521
|
+
// happen is still a failure for whoever runs this.
|
|
15522
|
+
return go && !pushed ? 1 : 0;
|
|
15523
|
+
}
|
|
15524
|
+
case "push": {
|
|
15525
|
+
const id = target === undefined ? null : parseSecretKeyId(target);
|
|
15526
|
+
if (id === null) {
|
|
15527
|
+
io.err(usage);
|
|
15528
|
+
return 1;
|
|
15529
|
+
}
|
|
15530
|
+
if (options.vercel || options.noVercel) {
|
|
15531
|
+
io.err("loom secrets push always asks first; it takes no --vercel or --no-vercel.");
|
|
15532
|
+
return 1;
|
|
15533
|
+
}
|
|
15534
|
+
const refusal = keyReadRefusal("push");
|
|
15535
|
+
if (refusal) {
|
|
15536
|
+
io.err(refusal);
|
|
15537
|
+
return 1;
|
|
15538
|
+
}
|
|
15539
|
+
if (environment !== "production") {
|
|
15540
|
+
io.err("loom secrets push sets Vercel Production only. Set Preview variables yourself.");
|
|
15541
|
+
return 1;
|
|
15542
|
+
}
|
|
15543
|
+
const key = await recordedSecretsKey(cwd, id, environment);
|
|
15544
|
+
const found = await findSecretsVercelTarget(cwd, commandRunner);
|
|
15545
|
+
if (!("target" in found)) {
|
|
15546
|
+
io.err(found.reason);
|
|
15547
|
+
return 1;
|
|
15548
|
+
}
|
|
15549
|
+
if (!isYesAnswer(await ask(`Add ${key.variableName} (Secret, Production only)${key.state === "active"
|
|
15550
|
+
? ` and ${key.activeKeyName}=${key.id}`
|
|
15551
|
+
: ""} to Vercel project ${found.target.project}? [y/N] `))) {
|
|
15552
|
+
io.out("Nothing was changed.");
|
|
15553
|
+
return 0;
|
|
15554
|
+
}
|
|
15555
|
+
return await pushSecretsKeyToVercel(cwd, commandRunner, found.target, key, {
|
|
15556
|
+
ask,
|
|
15557
|
+
prompt: prompt("Nothing was sent to Vercel.", keyReadRefusal("push") ?? "This needs a terminal."),
|
|
15558
|
+
}, io, { replacePointer: "ask" })
|
|
15559
|
+
? 0
|
|
15560
|
+
: 1;
|
|
15044
15561
|
}
|
|
15045
15562
|
case "fingerprint": {
|
|
15046
15563
|
// Checked before anything else, and never echoed: whatever followed
|
|
@@ -15049,21 +15566,17 @@ async function runSecrets(cwd, command, target, options, io, terminal = {}) {
|
|
|
15049
15566
|
io.err(SECRETS_FINGERPRINT_ARGUMENT_REFUSAL);
|
|
15050
15567
|
return 1;
|
|
15051
15568
|
}
|
|
15052
|
-
if (
|
|
15053
|
-
io.err(
|
|
15569
|
+
if (options.vercel || options.noVercel) {
|
|
15570
|
+
io.err("loom secrets fingerprint changes nothing on Vercel.");
|
|
15054
15571
|
return 1;
|
|
15055
15572
|
}
|
|
15056
|
-
const
|
|
15057
|
-
if (
|
|
15058
|
-
io.err(
|
|
15573
|
+
const refusal = keyReadRefusal("fingerprint");
|
|
15574
|
+
if (refusal) {
|
|
15575
|
+
io.err(refusal);
|
|
15059
15576
|
return 1;
|
|
15060
15577
|
}
|
|
15061
|
-
const
|
|
15062
|
-
|
|
15063
|
-
cancelled: "Fingerprinting was cancelled.",
|
|
15064
|
-
notInteractive,
|
|
15065
|
-
}));
|
|
15066
|
-
io.out(await fingerprintSecretsKey(await prompt("Secrets key (input is hidden): ")));
|
|
15578
|
+
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.");
|
|
15579
|
+
io.out(await fingerprintSecretsKey(await readKey("Secrets key (input is hidden): ")));
|
|
15067
15580
|
return 0;
|
|
15068
15581
|
}
|
|
15069
15582
|
case "activate":
|
|
@@ -15074,13 +15587,78 @@ async function runSecrets(cwd, command, target, options, io, terminal = {}) {
|
|
|
15074
15587
|
return 1;
|
|
15075
15588
|
}
|
|
15076
15589
|
if (command === "activate") {
|
|
15077
|
-
|
|
15590
|
+
if (environment !== "production" && options.vercel) {
|
|
15591
|
+
io.err("--vercel sets Vercel Production only. Set Preview variables yourself.");
|
|
15592
|
+
return 1;
|
|
15593
|
+
}
|
|
15594
|
+
let pointerSet = false;
|
|
15595
|
+
let vercelNote = null;
|
|
15596
|
+
const result = await activateSecretsKey(cwd, id, environment, {
|
|
15597
|
+
// The platform's pointer moves first: a deployment carrying the
|
|
15598
|
+
// new list with the old pointer would fail every seal. A build
|
|
15599
|
+
// between the two, with the new pointer and the old list, fails
|
|
15600
|
+
// too, so loom.json should follow at once.
|
|
15601
|
+
beforeWrite: async (key) => {
|
|
15602
|
+
if (vercelChoice === "no" || environment !== "production") {
|
|
15603
|
+
return false;
|
|
15604
|
+
}
|
|
15605
|
+
const found = await findSecretsVercelTarget(cwd, commandRunner);
|
|
15606
|
+
const refusal = !("target" in found)
|
|
15607
|
+
? found.reason
|
|
15608
|
+
: !vercelVariables(found.target, key.variableName).length
|
|
15609
|
+
? `${key.variableName} is not in Vercel Production. Add it (\`loom secrets push ${id}\`) and deploy before activating it.`
|
|
15610
|
+
: vercelPointerProblem(found.target, key.activeKeyName);
|
|
15611
|
+
if (refusal) {
|
|
15612
|
+
if (vercelChoice === "yes") {
|
|
15613
|
+
throw new Error(`${refusal} loom.json was not changed.`);
|
|
15614
|
+
}
|
|
15615
|
+
if ("target" in found || found.linked)
|
|
15616
|
+
vercelNote = refusal;
|
|
15617
|
+
return false;
|
|
15618
|
+
}
|
|
15619
|
+
const vercel = found.target;
|
|
15620
|
+
if (vercelChoice === "ask" &&
|
|
15621
|
+
!isYesAnswer(await ask(`Set ${key.activeKeyName}=${id} in Vercel project ${vercel.project}, Production, before loom.json changes? [y/N] `).catch(() => ""))) {
|
|
15622
|
+
return false;
|
|
15623
|
+
}
|
|
15624
|
+
try {
|
|
15625
|
+
await setVercelPointer(cwd, commandRunner, vercel, key.activeKeyName, id);
|
|
15626
|
+
}
|
|
15627
|
+
catch (error) {
|
|
15628
|
+
throw new Error(`${error.message} loom.json was not changed.`);
|
|
15629
|
+
}
|
|
15630
|
+
pointerSet = true;
|
|
15631
|
+
io.out(`Set ${key.activeKeyName}=${id} in Vercel project ${vercel.project}, Production.`);
|
|
15632
|
+
// Team policy, or an existing Secret kept by `env update`, can
|
|
15633
|
+
// leave the pointer unreadable to the release build.
|
|
15634
|
+
try {
|
|
15635
|
+
warnIfPointerSecret({
|
|
15636
|
+
...vercel,
|
|
15637
|
+
variables: await listVercelProductionVariables(cwd, commandRunner, vercel.command, vercel.env),
|
|
15638
|
+
}, key.activeKeyName, io);
|
|
15639
|
+
}
|
|
15640
|
+
catch {
|
|
15641
|
+
// The pointer is set; how it is stored is a warning only.
|
|
15642
|
+
}
|
|
15643
|
+
return true;
|
|
15644
|
+
},
|
|
15645
|
+
});
|
|
15078
15646
|
io.out(result.changedFiles.length
|
|
15079
15647
|
? `Updated ${result.changedFiles.join(", ")}: key version ${id} is now the active ${environment} key.`
|
|
15080
15648
|
: `Key version ${id} is already the active ${environment} key in loom.json.`);
|
|
15081
|
-
|
|
15649
|
+
if (vercelNote)
|
|
15650
|
+
io.out(`Note: Vercel was not changed: ${vercelNote}`);
|
|
15651
|
+
io.out(pointerSet
|
|
15652
|
+
? "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."
|
|
15653
|
+
: `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"
|
|
15654
|
+
? " On Vercel, `--vercel` does this first."
|
|
15655
|
+
: ""}`);
|
|
15082
15656
|
return 0;
|
|
15083
15657
|
}
|
|
15658
|
+
if (options.vercel || options.noVercel) {
|
|
15659
|
+
io.err("loom secrets retire changes nothing on Vercel; remove the variable there yourself, after deploying the retired list.");
|
|
15660
|
+
return 1;
|
|
15661
|
+
}
|
|
15084
15662
|
const result = await retireSecretsKey(cwd, id, environment);
|
|
15085
15663
|
io.out(result.changedFiles.length
|
|
15086
15664
|
? `Updated ${result.changedFiles.join(", ")}: key version ${id} is now retired for ${environment}.`
|
|
@@ -16003,6 +16581,11 @@ export async function runCli(args = process.argv.slice(2), io = {
|
|
|
16003
16581
|
io.err(SECRETS_FINGERPRINT_ARGUMENT_REFUSAL);
|
|
16004
16582
|
return 1;
|
|
16005
16583
|
}
|
|
16584
|
+
if (secretsIndex >= 0 && args[secretsIndex + 1] === "push" &&
|
|
16585
|
+
!secretsPushArgumentsAreSafe(args.slice(secretsIndex + 2))) {
|
|
16586
|
+
io.err(SECRETS_PUSH_ARGUMENT_REFUSAL);
|
|
16587
|
+
return 1;
|
|
16588
|
+
}
|
|
16006
16589
|
const parsed = parseArgs({
|
|
16007
16590
|
allowPositionals: true,
|
|
16008
16591
|
args,
|
|
@@ -16032,6 +16615,8 @@ export async function runCli(args = process.argv.slice(2), io = {
|
|
|
16032
16615
|
"max-requests-per-key": { type: "string" },
|
|
16033
16616
|
"no-color": { type: "boolean" },
|
|
16034
16617
|
"no-progress": { type: "boolean" },
|
|
16618
|
+
"no-vercel": { type: "boolean" },
|
|
16619
|
+
vercel: { type: "boolean" },
|
|
16035
16620
|
"no-sync": { type: "boolean" },
|
|
16036
16621
|
network: { type: "boolean" },
|
|
16037
16622
|
"neon-auth": { type: "boolean" },
|
|
@@ -16138,7 +16723,11 @@ export async function runCli(args = process.argv.slice(2), io = {
|
|
|
16138
16723
|
resource: parsed.values.resource,
|
|
16139
16724
|
}, io);
|
|
16140
16725
|
case "secrets":
|
|
16141
|
-
return await runSecrets(cwd, arg1, arg2, {
|
|
16726
|
+
return await runSecrets(cwd, arg1, arg2, {
|
|
16727
|
+
environment: parsed.values.environment,
|
|
16728
|
+
noVercel: parsed.values["no-vercel"],
|
|
16729
|
+
vercel: parsed.values.vercel,
|
|
16730
|
+
}, io, options.secretsTerminal, options.commandRunner);
|
|
16142
16731
|
case "skills":
|
|
16143
16732
|
return await runSkills(cwd, arg1, [arg2, ...rest].filter(Boolean), io, {
|
|
16144
16733
|
acceptUnknownLicense: parsed.values["accept-unknown-license"],
|