@gadicc/loom 1.36.0 → 1.38.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 +25 -5
- package/esm/src/cli/localDb.js +2 -2
- package/esm/src/cli/migrationEnv.js +2 -2
- package/esm/src/cli/mod.d.ts +47 -1
- package/esm/src/cli/mod.d.ts.map +1 -1
- package/esm/src/cli/mod.js +805 -56
- package/esm/src/cli/vercelBuildEnv.d.ts.map +1 -1
- package/esm/src/cli/vercelBuildEnv.js +23 -6
- package/esm/src/cli/vercelEnvMask.d.ts +38 -0
- package/esm/src/cli/vercelEnvMask.d.ts.map +1 -0
- package/esm/src/cli/vercelEnvMask.js +136 -0
- package/esm/src/cli/vercelProjectRelease.js +2 -2
- package/esm/src/cli/vercelPulledEnv.d.ts +65 -0
- package/esm/src/cli/vercelPulledEnv.d.ts.map +1 -0
- package/esm/src/cli/vercelPulledEnv.js +132 -0
- package/package.json +2 -2
- package/script/src/cli/localDb.js +2 -2
- package/script/src/cli/migrationEnv.js +2 -2
- package/script/src/cli/mod.d.ts +47 -1
- package/script/src/cli/mod.d.ts.map +1 -1
- package/script/src/cli/mod.js +808 -56
- package/script/src/cli/vercelBuildEnv.d.ts.map +1 -1
- package/script/src/cli/vercelBuildEnv.js +23 -6
- package/script/src/cli/vercelEnvMask.d.ts +38 -0
- package/script/src/cli/vercelEnvMask.d.ts.map +1 -0
- package/script/src/cli/vercelEnvMask.js +142 -0
- package/script/src/cli/vercelProjectRelease.js +2 -2
- package/script/src/cli/vercelPulledEnv.d.ts +65 -0
- package/script/src/cli/vercelPulledEnv.d.ts.map +1 -0
- package/script/src/cli/vercelPulledEnv.js +138 -0
- package/skills/loom/SKILL.md +5 -0
- package/skills/loom/references/dependency-upgrades.md +4 -0
- package/skills/loom/references/release-safety.md +10 -3
- package/skills/loom-auth/references/secrets-and-rotation.md +2 -1
- package/skills/loom-files/references/provider-configuration.md +8 -0
- package/skills/loom-scaffold/references/greenfield-workflow.md +2 -1
- package/skills/loom-secrets/SKILL.md +27 -13
package/esm/src/cli/mod.js
CHANGED
|
@@ -24,6 +24,7 @@ import { decodeSecretKey, DEFAULT_SECRETS_ACTIVE_KEY_ENV, DEFAULT_SECRETS_KEY_EN
|
|
|
24
24
|
import { checkProjectSkills, getProjectSkillStatus, LOOM_EXTERNAL_SKILLS_GITIGNORE_LINE, readProjectSkillsLock, removeLegacyNextSkillLink, setProjectSkillDisabled, syncExternalProjectSkills, syncInstalledPackageSkills, } from "./projectSkills.js";
|
|
25
25
|
import { resolveMigrationEnvironment, resolveMigrationEnvironmentFromEnvFile, verifyMigrationConnection, verifyMigrationConnectionFromEnvFile, } from "./migrationEnv.js";
|
|
26
26
|
import { parseVercelBuildEnvironmentPolicy, prepareVercelBuildEnvironment, verifyVercelBuildArtifact, } from "./vercelBuildEnv.js";
|
|
27
|
+
import { maskVercelPulledEnvironment } from "./vercelEnvMask.js";
|
|
27
28
|
import { parseVercelReleaseTimeout, prepareVercelProjectRelease, promoteVercelProjectRelease, } from "./vercelProjectRelease.js";
|
|
28
29
|
import { denoConfigAsPackageJson, detectProjectTooling, ensureTask, ensureTaskFollowup, ensureTaskPrerequisite, findTaskConflicts, formatTaskInvocation, getTaskCommand, jsonValuesEqual, mutateDenoLinks, mutatePackageJsonOverride, mutateProjectDependencies, parseJsonc, patchJsonText, readDenoLinks, readProjectPackageMetadata, readTaskStore, taskInvokes, taskRunsBeforeCommand, } from "./projectTooling.js";
|
|
29
30
|
import { withLocalDevLock, } from "./localDevLock.js";
|
|
@@ -4551,6 +4552,30 @@ async function checkPnpm11Compatibility(cwd, packageJson, npmrcText) {
|
|
|
4551
4552
|
warnings: major === null || major < 11 ? findings : [],
|
|
4552
4553
|
};
|
|
4553
4554
|
}
|
|
4555
|
+
/**
|
|
4556
|
+
* Without Corepack, Vercel picks the pnpm version from the lockfile rather than
|
|
4557
|
+
* from `packageManager`, and an `engines.pnpm` range can then reject that pnpm
|
|
4558
|
+
* with ERR_PNPM_UNSUPPORTED_ENGINE. `packageManager` already records the
|
|
4559
|
+
* intended version, so removing the range is the advice; this is a warning
|
|
4560
|
+
* only.
|
|
4561
|
+
*/
|
|
4562
|
+
function checkPnpmEnginesWithPackageManager(packageJson) {
|
|
4563
|
+
const engines = packageJson.engines;
|
|
4564
|
+
if (!packageJson.packageManager?.startsWith("pnpm@") ||
|
|
4565
|
+
typeof engines !== "object" || engines === null ||
|
|
4566
|
+
engines.pnpm === undefined) {
|
|
4567
|
+
return { issues: [], suggestions: [], warnings: [] };
|
|
4568
|
+
}
|
|
4569
|
+
return {
|
|
4570
|
+
issues: [],
|
|
4571
|
+
suggestions: [
|
|
4572
|
+
"Remove package.json#engines.pnpm so it cannot reject the pnpm version Vercel selects; keep packageManager as the project's pnpm pin.",
|
|
4573
|
+
],
|
|
4574
|
+
warnings: [
|
|
4575
|
+
"package.json sets engines.pnpm beside a pnpm packageManager pin; Vercel builds without Corepack choose pnpm from the lockfile version, which engines.pnpm can reject with ERR_PNPM_UNSUPPORTED_ENGINE.",
|
|
4576
|
+
],
|
|
4577
|
+
};
|
|
4578
|
+
}
|
|
4554
4579
|
async function getSkillsContext(cwd, packageJson, manifest) {
|
|
4555
4580
|
const tooling = await detectProjectTooling(cwd, manifest?.project?.tooling);
|
|
4556
4581
|
const dependencyConfig = tooling.dependencies.config;
|
|
@@ -5146,6 +5171,124 @@ function workflowStepPreparesVercelProject(block) {
|
|
|
5146
5171
|
/vercel-production-env\.json\b/.test(block) &&
|
|
5147
5172
|
/\.vercel\/project\.json\b/.test(block);
|
|
5148
5173
|
}
|
|
5174
|
+
/**
|
|
5175
|
+
* Ways a workflow runs the Loom CLI: bare `loom`, through a package runner, as
|
|
5176
|
+
* `@gadicc/loom` fetched by `npx`, `pnpm dlx`, `bunx` or Deno, or by path as
|
|
5177
|
+
* `node_modules/.bin/loom`.
|
|
5178
|
+
*/
|
|
5179
|
+
const LOOM_INVOCATION = String
|
|
5180
|
+
.raw `(?:(?:pnpm\s+(?:exec|dlx)|pnpm|npm\s+exec(?:\s+--)?|npx(?:\s+(?:-y|--yes))?|yarn(?:\s+dlx)?|bunx|deno\s+task|deno\s+run\s+-A)\s+)?(?:(?:\.\/)?node_modules\/\.bin\/loom|(?:npm:)?@gadicc\/loom(?:@[^\s]+)?|loom)`;
|
|
5181
|
+
/**
|
|
5182
|
+
* Drops YAML and shell comments so a commented-out step or command is not
|
|
5183
|
+
* mistaken for one that runs. A `#` counts as a comment only at the start of
|
|
5184
|
+
* a line or after whitespace, which leaves URL fragments alone.
|
|
5185
|
+
*/
|
|
5186
|
+
function stripWorkflowComments(text) {
|
|
5187
|
+
return text.split("\n").filter((line) => !line.trim().startsWith("#")).map((line) => line.replace(/\s#.*$/, "")).join("\n");
|
|
5188
|
+
}
|
|
5189
|
+
/** Whether a step's `if:` is literally false, so it never runs. */
|
|
5190
|
+
function workflowStepIsDisabled(block) {
|
|
5191
|
+
return /^\s*(?:-\s+)?if:\s*(?:false|\$\{\{\s*false\s*\}\})\s*$/m.test(block);
|
|
5192
|
+
}
|
|
5193
|
+
/**
|
|
5194
|
+
* File arguments of `loom db release mask-env` commands the step runs. Only a
|
|
5195
|
+
* command in command position counts, so `echo 'loom db release mask-env …'`
|
|
5196
|
+
* does not.
|
|
5197
|
+
*/
|
|
5198
|
+
function loomMaskEnvFileArguments(block) {
|
|
5199
|
+
const joined = block.replace(/\\\r?\n\s*/g, " ");
|
|
5200
|
+
const pattern = new RegExp(String
|
|
5201
|
+
.raw `(?:^\s*(?:-\s+)?(?:run:\s*)?|[;&|]\s*)(?:[A-Za-z_][A-Za-z0-9_]*=\S*\s+)*${LOOM_INVOCATION}\s+db\s+release\s+mask-env\s+("[^"]*"|'[^']*'|[^\s;&|]+)`, "gm");
|
|
5202
|
+
return [...joined.matchAll(pattern)].map((match) => match[1].replace(/^(["'])(.*)\1$/, "$2"));
|
|
5203
|
+
}
|
|
5204
|
+
/**
|
|
5205
|
+
* The env file a `vercel pull` step writes, relative to `.vercel/`, or `null`
|
|
5206
|
+
* when the environment is computed at run time.
|
|
5207
|
+
*/
|
|
5208
|
+
function pulledVercelEnvFileName(block) {
|
|
5209
|
+
const joined = block.replace(/\\\r?\n\s*/g, " ");
|
|
5210
|
+
const environment = joined.match(/\s--environment(?:=|\s+)(["']?)([^\s"']+)\1/)?.[2] ?? (/\s--prod\b/.test(joined) ? "production" : "development");
|
|
5211
|
+
return /[$]/.test(environment) ? null : `.env.${environment}.local`;
|
|
5212
|
+
}
|
|
5213
|
+
/**
|
|
5214
|
+
* Whether masking `file` covers the file a pull wrote. A file named through a
|
|
5215
|
+
* shell variable (such as a copy in `$RUNNER_TEMP`) cannot be checked
|
|
5216
|
+
* statically and is accepted rather than reported.
|
|
5217
|
+
*/
|
|
5218
|
+
function maskedFileCoversPull(file, pulledFile) {
|
|
5219
|
+
if (file.includes("$"))
|
|
5220
|
+
return true;
|
|
5221
|
+
if (pulledFile === null) {
|
|
5222
|
+
return /(?:^|\/)\.vercel\/\.env\.[^/]+\.local$/.test(file);
|
|
5223
|
+
}
|
|
5224
|
+
return file === `.vercel/${pulledFile}` ||
|
|
5225
|
+
file.endsWith(`/.vercel/${pulledFile}`);
|
|
5226
|
+
}
|
|
5227
|
+
/**
|
|
5228
|
+
* `.vercel/.env.*` paths an inline `::add-mask::` step names. Segments such as
|
|
5229
|
+
* `${VERCEL_TARGET_ENV}` are kept, so the path reads as a shell variable.
|
|
5230
|
+
*/
|
|
5231
|
+
function inlineMaskedVercelEnvFiles(block) {
|
|
5232
|
+
if (!block.includes("::add-mask::"))
|
|
5233
|
+
return [];
|
|
5234
|
+
return [
|
|
5235
|
+
...block.matchAll(/[^\s"'`=]*\.vercel\/\.env\.(?:[\w.-]|\$\{[A-Za-z_]\w*\}|\$[A-Za-z_]\w*)+/g),
|
|
5236
|
+
].map((match) => match[0].replace(/[.-]+$/, ""));
|
|
5237
|
+
}
|
|
5238
|
+
/**
|
|
5239
|
+
* Checks that each `vercel pull` step is followed, in the same job, by an
|
|
5240
|
+
* enabled step that masks the file it wrote. Reports pulls that nothing masks,
|
|
5241
|
+
* and an inline `::add-mask::` script that could use `loom db release
|
|
5242
|
+
* mask-env` instead (also when the env file came from another Loom command).
|
|
5243
|
+
*/
|
|
5244
|
+
function checkPulledVercelEnvMasking(workflowText) {
|
|
5245
|
+
let unmaskedPull = false;
|
|
5246
|
+
let inlineMaskBlock;
|
|
5247
|
+
let loomMasksAnyVercelEnv = false;
|
|
5248
|
+
for (const job of getGithubWorkflowJobBlocks(workflowText)) {
|
|
5249
|
+
const steps = job.stepBlocks.map(stripWorkflowComments).filter((block) => !workflowStepIsDisabled(block));
|
|
5250
|
+
for (const block of steps) {
|
|
5251
|
+
if (loomMaskEnvFileArguments(block).some((file) => maskedFileCoversPull(file, null)))
|
|
5252
|
+
loomMasksAnyVercelEnv = true;
|
|
5253
|
+
if (!inlineMaskBlock && !loomMaskEnvFileArguments(block).length &&
|
|
5254
|
+
inlineMaskedVercelEnvFiles(block).length)
|
|
5255
|
+
inlineMaskBlock = block;
|
|
5256
|
+
}
|
|
5257
|
+
steps.forEach((block, index) => {
|
|
5258
|
+
if (!workflowStepUsesVercelCommand(block, "pull"))
|
|
5259
|
+
return;
|
|
5260
|
+
const pulledFile = pulledVercelEnvFileName(block);
|
|
5261
|
+
const later = steps.slice(index + 1);
|
|
5262
|
+
if (later.some((step) => loomMaskEnvFileArguments(step).some((file) => maskedFileCoversPull(file, pulledFile))))
|
|
5263
|
+
return;
|
|
5264
|
+
if (later.some((step) => inlineMaskedVercelEnvFiles(step).some((file) => maskedFileCoversPull(file, pulledFile))))
|
|
5265
|
+
return;
|
|
5266
|
+
unmaskedPull = true;
|
|
5267
|
+
});
|
|
5268
|
+
}
|
|
5269
|
+
return {
|
|
5270
|
+
inlineMaskBlock: loomMasksAnyVercelEnv ? undefined : inlineMaskBlock,
|
|
5271
|
+
unmaskedPull,
|
|
5272
|
+
};
|
|
5273
|
+
}
|
|
5274
|
+
/**
|
|
5275
|
+
* The replacement for an inline masking step, invoking Loom the way the
|
|
5276
|
+
* workflow already does (for example `pnpm exec loom` or `npx @gadicc/loom`)
|
|
5277
|
+
* so the suggestion follows the app's tooling instead of assuming one.
|
|
5278
|
+
*/
|
|
5279
|
+
function loomMaskEnvWorkflowStep(workflowText, inlineMaskBlock) {
|
|
5280
|
+
const envFile = inlineMaskedVercelEnvFiles(inlineMaskBlock)[0] ??
|
|
5281
|
+
".vercel/.env.production.local";
|
|
5282
|
+
const invocation = workflowText.match(new RegExp(String.raw `(?:^|[\s;&|(])(${LOOM_INVOCATION})\s+(?:db|check|init|dev)\b`, "m"))?.[1]?.replace(/\s+/g, " ") ??
|
|
5283
|
+
// No Loom command yet: follow the workflow's pnpm usage when it has one.
|
|
5284
|
+
(/(?:^|[\s;&|(])pnpm\s+(?:install|exec|run|dlx)\b/m.test(workflowText)
|
|
5285
|
+
? "pnpm exec loom"
|
|
5286
|
+
: "loom");
|
|
5287
|
+
return [
|
|
5288
|
+
" - name: Mask pulled Vercel values",
|
|
5289
|
+
` run: ${invocation} db release mask-env ${envFile}`,
|
|
5290
|
+
].join("\n");
|
|
5291
|
+
}
|
|
5149
5292
|
function workflowStepPreparesVercelBuildEnv(block) {
|
|
5150
5293
|
return (/\bvercel-build-env(?:\.mjs)?\b[\s\S]*\bprepare\b/.test(block) ||
|
|
5151
5294
|
/\bloom\b[\s\S]*\bdb\s+release\s+prepare-build-env\b/.test(block));
|
|
@@ -5599,11 +5742,15 @@ async function checkGithubActionsWorkflows(cwd) {
|
|
|
5599
5742
|
warnings.push(`GitHub Actions workflow exposes VERCEL_TOKEN for an entire workflow or job: ${relativePath}`);
|
|
5600
5743
|
suggestions.add("Keep VERCEL_TOKEN in a protected GitHub Environment and bind it only on steps that call Vercel.");
|
|
5601
5744
|
}
|
|
5602
|
-
const
|
|
5603
|
-
|
|
5604
|
-
if (pullsVercelEnv && !masksPulledVercelEnv) {
|
|
5745
|
+
const masking = checkPulledVercelEnvMasking(normalized);
|
|
5746
|
+
if (masking.unmaskedPull) {
|
|
5605
5747
|
warnings.push(`GitHub Actions workflow pulls Vercel secrets without masking the downloaded values: ${relativePath}`);
|
|
5606
|
-
suggestions.add("Immediately after `vercel pull`,
|
|
5748
|
+
suggestions.add("Immediately after `vercel pull`, add a step in the same job that runs `loom db release mask-env .vercel/.env.<target>.local` so GitHub masks every secret-capable pulled value.");
|
|
5749
|
+
}
|
|
5750
|
+
if (masking.inlineMaskBlock) {
|
|
5751
|
+
warnings.push(`GitHub Actions workflow masks pulled Vercel values with its own \`::add-mask::\` script instead of \`loom db release mask-env\`: ${relativePath}`);
|
|
5752
|
+
suggestions.add("Replace the inline Vercel masking step with Loom's shared rule, which reads the file directly, skips only short and public-by-construction values, and masks multi-line values line by line:\n" +
|
|
5753
|
+
loomMaskEnvWorkflowStep(stripWorkflowComments(normalized), masking.inlineMaskBlock));
|
|
5607
5754
|
}
|
|
5608
5755
|
}
|
|
5609
5756
|
return {
|
|
@@ -7982,16 +8129,29 @@ async function listVercelEnvironmentNames(cwd, commandRunner, env, vercelCommand
|
|
|
7982
8129
|
}
|
|
7983
8130
|
return result.stdout;
|
|
7984
8131
|
}
|
|
7985
|
-
|
|
7986
|
-
|
|
8132
|
+
/**
|
|
8133
|
+
* What a failed Vercel CLI call said. In an agent session the CLI reports
|
|
8134
|
+
* errors as JSON on stdout. Vercel does not echo a value it was given, but a
|
|
8135
|
+
* long one is masked anyway, in case a later version does.
|
|
8136
|
+
*/
|
|
8137
|
+
function vercelFailureDetail(result, value) {
|
|
8138
|
+
const detail = result.stderr.trim() || result.stdout.trim() ||
|
|
8139
|
+
`exit code ${result.code}`;
|
|
8140
|
+
return value.length >= 16 ? detail.split(value).join("[redacted]") : detail;
|
|
8141
|
+
}
|
|
8142
|
+
async function addVercelEnvValue(cwd, commandRunner, env, vercelCommand, name, value, environment, extraArgs = []) {
|
|
8143
|
+
// The value goes on stdin, never into the arguments, where the process
|
|
8144
|
+
// list and shell history would show it.
|
|
8145
|
+
const result = await commandRunner(vercelCommand, ["env", "add", name, environment, ...extraArgs], { cwd, env, input: `${value}\n`, stdio: "pipe" });
|
|
7987
8146
|
if (result.code !== 0) {
|
|
7988
|
-
throw new Error(`Could not add ${name} to Vercel ${environment}: ${result
|
|
8147
|
+
throw new Error(`Could not add ${name} to Vercel ${environment}: ${vercelFailureDetail(result, value)}`);
|
|
7989
8148
|
}
|
|
7990
8149
|
}
|
|
7991
8150
|
async function updateVercelEnvValue(cwd, commandRunner, env, vercelCommand, name, value, environment) {
|
|
8151
|
+
// No type flag: `env update` keeps the variable's existing type.
|
|
7992
8152
|
const result = await commandRunner(vercelCommand, ["env", "update", name, environment, "--yes"], { cwd, env, input: `${value}\n`, stdio: "pipe" });
|
|
7993
8153
|
if (result.code !== 0) {
|
|
7994
|
-
throw new Error(`Could not update ${name} in Vercel ${environment}: ${result
|
|
8154
|
+
throw new Error(`Could not update ${name} in Vercel ${environment}: ${vercelFailureDetail(result, value)}`);
|
|
7995
8155
|
}
|
|
7996
8156
|
}
|
|
7997
8157
|
async function promptForVercelSecret(cwd, commandRunner, env, vercelCommand, name, environment) {
|
|
@@ -8029,10 +8189,38 @@ function buildVercelFilesEnvListArgs(environment, project) {
|
|
|
8029
8189
|
}
|
|
8030
8190
|
function withoutInheritedVercelProject(env) {
|
|
8031
8191
|
const result = { ...env };
|
|
8032
|
-
|
|
8033
|
-
|
|
8192
|
+
// The Vercel CLI still honours the older NOW_* names too.
|
|
8193
|
+
for (const name of [
|
|
8194
|
+
"VERCEL_ORG_ID",
|
|
8195
|
+
"VERCEL_PROJECT_ID",
|
|
8196
|
+
"NOW_ORG_ID",
|
|
8197
|
+
"NOW_PROJECT_ID",
|
|
8198
|
+
]) {
|
|
8199
|
+
delete result[name];
|
|
8200
|
+
}
|
|
8034
8201
|
return result;
|
|
8035
8202
|
}
|
|
8203
|
+
/**
|
|
8204
|
+
* Which of `names` Vercel stores as Secrets for `environment`, or null when
|
|
8205
|
+
* the JSON listing is unavailable. A Secret reads back empty, so it looks like
|
|
8206
|
+
* drift, but `vercel env update` keeps a variable's type and cannot fix it.
|
|
8207
|
+
*/
|
|
8208
|
+
async function findVercelFilesValuesStoredAsSecrets(cwd, commandRunner, env, vercelCommand, environment, listArgs, names) {
|
|
8209
|
+
const result = await commandRunner(vercelCommand, [...listArgs, "--format", "json"], { cwd, env, stdio: "pipe" });
|
|
8210
|
+
if (result.code !== 0)
|
|
8211
|
+
return null;
|
|
8212
|
+
const variables = parseVercelEnvListing(result.stdout);
|
|
8213
|
+
if (!variables)
|
|
8214
|
+
return null;
|
|
8215
|
+
return names.filter((name) => variables.some((variable) => variable.key === name && variable.secret &&
|
|
8216
|
+
variable.targets.includes(environment)));
|
|
8217
|
+
}
|
|
8218
|
+
function filesSecretTypeProblem(environment, names) {
|
|
8219
|
+
return `Vercel ${environment} stores ${names.join(", ")} as Secrets, so their values cannot be read back, and \`vercel env update\` keeps a Secret a Secret.`;
|
|
8220
|
+
}
|
|
8221
|
+
function filesSecretTypeFix(environment) {
|
|
8222
|
+
return `Remove them from Vercel ${environment}, then run \`loom files r2 setup\` to add them back as readable values.`;
|
|
8223
|
+
}
|
|
8036
8224
|
async function readVercelFilesNonSecretValues(cwd, commandRunner, env, vercelCommand, environment) {
|
|
8037
8225
|
const link = await readVercelProjectLink(cwd);
|
|
8038
8226
|
if (!link.linked || !link.orgId || !link.projectId)
|
|
@@ -8115,11 +8303,11 @@ async function ensureMinioBucket(cwd, commandRunner, env, endpoint, bucket, acce
|
|
|
8115
8303
|
* is read in raw mode so it is never echoed. Refuses when stdin is not a
|
|
8116
8304
|
* terminal, with the caller's explanation of what to do instead.
|
|
8117
8305
|
*/
|
|
8118
|
-
async function promptForTerminalValue(question, secret, messages) {
|
|
8306
|
+
async function promptForTerminalValue(question, secret, messages, options = {}) {
|
|
8119
8307
|
if (!process.stdin.isTTY) {
|
|
8120
8308
|
throw new Error(messages.notInteractive);
|
|
8121
8309
|
}
|
|
8122
|
-
if (!secret) {
|
|
8310
|
+
if (!secret && !options.rawEcho) {
|
|
8123
8311
|
const input = createInterface({
|
|
8124
8312
|
input: process.stdin,
|
|
8125
8313
|
output: process.stderr,
|
|
@@ -8153,9 +8341,13 @@ async function promptForTerminalValue(question, secret, messages) {
|
|
|
8153
8341
|
return;
|
|
8154
8342
|
}
|
|
8155
8343
|
if (character === "\u007f" || character === "\b") {
|
|
8344
|
+
if (options.rawEcho && value)
|
|
8345
|
+
process.stderr.write("\b \b");
|
|
8156
8346
|
value = value.slice(0, -1);
|
|
8157
8347
|
}
|
|
8158
8348
|
else {
|
|
8349
|
+
if (options.rawEcho)
|
|
8350
|
+
process.stderr.write(character);
|
|
8159
8351
|
value += character;
|
|
8160
8352
|
}
|
|
8161
8353
|
}
|
|
@@ -8833,6 +9025,12 @@ export async function setupCloudflareR2(cwd, options = {}) {
|
|
|
8833
9025
|
throw new Error(`Could not inspect existing non-secret Files values in Vercel ${environment}.`);
|
|
8834
9026
|
}
|
|
8835
9027
|
const drift = existingNonSecretNames.filter((name) => actualValues[name] !== nonSecretValues[name]);
|
|
9028
|
+
const storedAsSecrets = drift.length
|
|
9029
|
+
? await findVercelFilesValuesStoredAsSecrets(cwd, commandRunner, providerEnv, vercelCli.command, environment, ["env", "ls", environment], drift)
|
|
9030
|
+
: null;
|
|
9031
|
+
if (storedAsSecrets?.length) {
|
|
9032
|
+
throw new Error(`${filesSecretTypeProblem(environment, storedAsSecrets)} ${filesSecretTypeFix(environment)}`);
|
|
9033
|
+
}
|
|
8836
9034
|
if (drift.length && !options.repair) {
|
|
8837
9035
|
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
9036
|
}
|
|
@@ -8842,7 +9040,11 @@ export async function setupCloudflareR2(cwd, options = {}) {
|
|
|
8842
9040
|
}
|
|
8843
9041
|
for (const [name, value] of Object.entries(nonSecretValues)) {
|
|
8844
9042
|
if (!hasExactEnvName(listing, name)) {
|
|
8845
|
-
await addVercelEnvValue(cwd, commandRunner, providerEnv, vercelCli.command, name, value, environment
|
|
9043
|
+
await addVercelEnvValue(cwd, commandRunner, providerEnv, vercelCli.command, name, value, environment,
|
|
9044
|
+
// Vercel CLI stores a Production or Preview value read from
|
|
9045
|
+
// stdin as a Secret unless told otherwise, and the env-run probe
|
|
9046
|
+
// and release env policies must be able to read these back.
|
|
9047
|
+
["--no-sensitive", "--yes"]);
|
|
8846
9048
|
listing += `\n${name}`;
|
|
8847
9049
|
}
|
|
8848
9050
|
}
|
|
@@ -8950,6 +9152,9 @@ async function readVercelProjectLink(cwd) {
|
|
|
8950
9152
|
linked: true,
|
|
8951
9153
|
orgId,
|
|
8952
9154
|
projectId,
|
|
9155
|
+
projectName: typeof project.projectName === "string"
|
|
9156
|
+
? project.projectName
|
|
9157
|
+
: null,
|
|
8953
9158
|
relativePath,
|
|
8954
9159
|
};
|
|
8955
9160
|
}
|
|
@@ -9872,6 +10077,23 @@ function checkFilesNetworkFeature(context) {
|
|
|
9872
10077
|
FILES_S3_FORCE_PATH_STYLE: String(provider.forcePathStyle ?? false),
|
|
9873
10078
|
};
|
|
9874
10079
|
const drift = Object.entries(expectedValues).filter(([name, value]) => actualValues[name] !== value).map(([name]) => name);
|
|
10080
|
+
const storedAsSecrets = drift.length
|
|
10081
|
+
? await findVercelFilesValuesStoredAsSecrets(context.cwd, context.commandRunner, withoutInheritedVercelProject(context.env), state.vercelCommand, environment, buildVercelFilesEnvListArgs(environment, state.vercelProject), drift)
|
|
10082
|
+
: null;
|
|
10083
|
+
if (storedAsSecrets?.length) {
|
|
10084
|
+
const otherDrift = drift.filter((name) => !storedAsSecrets.includes(name));
|
|
10085
|
+
return networkCheckResult("issue", `Vercel ${environment} stores non-secret Files values as Secrets: ${storedAsSecrets.join(", ")}.`, {
|
|
10086
|
+
issues: [
|
|
10087
|
+
filesSecretTypeProblem(environment, storedAsSecrets),
|
|
10088
|
+
...(otherDrift.length
|
|
10089
|
+
? [
|
|
10090
|
+
`Vercel ${environment} has incompatible non-secret Files R2 values: ${otherDrift.join(", ")}.`,
|
|
10091
|
+
]
|
|
10092
|
+
: []),
|
|
10093
|
+
],
|
|
10094
|
+
suggestions: [filesSecretTypeFix(environment)],
|
|
10095
|
+
});
|
|
10096
|
+
}
|
|
9875
10097
|
return drift.length
|
|
9876
10098
|
? networkCheckResult("issue", `Vercel ${environment} Files values drift from loom.json: ${drift.join(", ")}.`, {
|
|
9877
10099
|
issues: [
|
|
@@ -10857,7 +11079,7 @@ async function applySecretsFeature(cwd, framework, manifest, activate, options =
|
|
|
10857
11079
|
changedFiles.push(...localKey.changedFiles);
|
|
10858
11080
|
notes.push(...localKey.notes);
|
|
10859
11081
|
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.");
|
|
11082
|
+
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
11083
|
}
|
|
10862
11084
|
}
|
|
10863
11085
|
feature.config = mergeSecretsConfig(currentFeature?.config, config);
|
|
@@ -13712,7 +13934,7 @@ async function checkSecretsFeature(cwd, framework, manifest, options) {
|
|
|
13712
13934
|
}
|
|
13713
13935
|
if (Array.isArray(config.keys.production) && config.keys.production.length === 0) {
|
|
13714
13936
|
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.");
|
|
13937
|
+
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
13938
|
}
|
|
13717
13939
|
const policyText = await readTextIfExists(join(cwd, VERCEL_PRODUCTION_ENV_POLICY_PATH));
|
|
13718
13940
|
if (policyText !== null) {
|
|
@@ -13947,15 +14169,18 @@ function recordedSecretKeys(config, environment) {
|
|
|
13947
14169
|
return recorded;
|
|
13948
14170
|
}
|
|
13949
14171
|
/** 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
|
-
}
|
|
14172
|
+
function validateSecretKeys(environment, keys) {
|
|
14173
|
+
if (!keys.length)
|
|
14174
|
+
return;
|
|
14175
|
+
try {
|
|
14176
|
+
parseExpectedSecretKeys(keys);
|
|
13958
14177
|
}
|
|
14178
|
+
catch (error) {
|
|
14179
|
+
throw new Error(`The ${environment} key list in loom.json would be invalid: ${error.message}`);
|
|
14180
|
+
}
|
|
14181
|
+
}
|
|
14182
|
+
async function writeSecretKeys(cwd, loaded, environment, keys) {
|
|
14183
|
+
validateSecretKeys(environment, keys);
|
|
13959
14184
|
// Replaces this one list and nothing else: any other property a user keeps
|
|
13960
14185
|
// under `config` or `config.keys` is theirs, and stays.
|
|
13961
14186
|
const existing = isJsonObject(loaded.feature.config)
|
|
@@ -13973,6 +14198,49 @@ async function writeSecretKeys(cwd, loaded, environment, keys) {
|
|
|
13973
14198
|
? ["loom.json"]
|
|
13974
14199
|
: [];
|
|
13975
14200
|
}
|
|
14201
|
+
function nextSecretsKey(config, environment) {
|
|
14202
|
+
const current = recordedSecretKeys(config, environment);
|
|
14203
|
+
const id = current.reduce((highest, key) => isSecretKeyId(key?.id) ? Math.max(highest, key.id) : highest, 0) + 1;
|
|
14204
|
+
const state = current.some((key) => key?.state === "active")
|
|
14205
|
+
? "decrypt-only"
|
|
14206
|
+
: "active";
|
|
14207
|
+
return { current, id, state };
|
|
14208
|
+
}
|
|
14209
|
+
/**
|
|
14210
|
+
* The version, state and variable names `generateSecretsKey` would use next,
|
|
14211
|
+
* without generating or recording anything.
|
|
14212
|
+
*/
|
|
14213
|
+
export async function planSecretsKey(cwd, environment = "production") {
|
|
14214
|
+
const loaded = await readActiveSecretsFeature(cwd);
|
|
14215
|
+
const { id, state } = nextSecretsKey(loaded.config, environment);
|
|
14216
|
+
return {
|
|
14217
|
+
activeKeyName: loaded.config.env.activeKeyName,
|
|
14218
|
+
id,
|
|
14219
|
+
state,
|
|
14220
|
+
variableName: `${loaded.config.env.keyPrefix}${id}`,
|
|
14221
|
+
};
|
|
14222
|
+
}
|
|
14223
|
+
/**
|
|
14224
|
+
* A recorded key that is not retired, with its variable names, for putting it
|
|
14225
|
+
* on a deployment platform. Refuses a version that is not listed or retired.
|
|
14226
|
+
*/
|
|
14227
|
+
export async function recordedSecretsKey(cwd, id, environment = "production") {
|
|
14228
|
+
const loaded = await readActiveSecretsFeature(cwd);
|
|
14229
|
+
const key = recordedSecretKeys(loaded.config, environment).find((entry) => entry?.id === id);
|
|
14230
|
+
if (!key) {
|
|
14231
|
+
throw new Error(`Key version ${id} is not listed for ${environment} in loom.json.`);
|
|
14232
|
+
}
|
|
14233
|
+
if (key.state === "retired") {
|
|
14234
|
+
throw new Error(`Key version ${id} is retired for ${environment}.`);
|
|
14235
|
+
}
|
|
14236
|
+
return {
|
|
14237
|
+
activeKeyName: loaded.config.env.activeKeyName,
|
|
14238
|
+
fingerprint: key.fingerprint,
|
|
14239
|
+
id,
|
|
14240
|
+
state: key.state,
|
|
14241
|
+
variableName: `${loaded.config.env.keyPrefix}${id}`,
|
|
14242
|
+
};
|
|
14243
|
+
}
|
|
13976
14244
|
/**
|
|
13977
14245
|
* Generates a key for a deployed environment and records its fingerprint in
|
|
13978
14246
|
* loom.json: `active` when the environment has no active key, otherwise
|
|
@@ -13986,11 +14254,7 @@ async function writeSecretKeys(cwd, loaded, environment, keys) {
|
|
|
13986
14254
|
export async function generateSecretsKey(cwd, options = {}) {
|
|
13987
14255
|
const environment = options.environment ?? "production";
|
|
13988
14256
|
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";
|
|
14257
|
+
const { current, id, state } = nextSecretsKey(loaded.config, environment);
|
|
13994
14258
|
const key = globalThis.crypto.getRandomValues(new Uint8Array(SECRETS_KEY_BYTES));
|
|
13995
14259
|
const fingerprint = await secretKeyFingerprint(key);
|
|
13996
14260
|
const changedFiles = await writeSecretKeys(cwd, loaded, environment, [
|
|
@@ -14020,8 +14284,12 @@ export async function fingerprintSecretsKey(value) {
|
|
|
14020
14284
|
/**
|
|
14021
14285
|
* Marks a recorded key `active` in loom.json and the previously active key
|
|
14022
14286
|
* `decrypt-only`. Refuses a version that is not listed or is retired.
|
|
14287
|
+
*
|
|
14288
|
+
* `beforeWrite` runs once those checks pass and before loom.json changes, so
|
|
14289
|
+
* the platform's pointer can be moved first; if it throws, loom.json is left
|
|
14290
|
+
* as it was.
|
|
14023
14291
|
*/
|
|
14024
|
-
export async function activateSecretsKey(cwd, id, environment = "production") {
|
|
14292
|
+
export async function activateSecretsKey(cwd, id, environment = "production", options = {}) {
|
|
14025
14293
|
const loaded = await readActiveSecretsFeature(cwd);
|
|
14026
14294
|
const current = recordedSecretKeys(loaded.config, environment);
|
|
14027
14295
|
const target = current.find((key) => key?.id === id);
|
|
@@ -14031,11 +14299,36 @@ export async function activateSecretsKey(cwd, id, environment = "production") {
|
|
|
14031
14299
|
if (target.state === "retired") {
|
|
14032
14300
|
throw new Error(`Key version ${id} is retired and cannot be activated. Generate a new key with \`loom secrets keygen\`.`);
|
|
14033
14301
|
}
|
|
14034
|
-
const
|
|
14302
|
+
const next = current.map((key) => key?.id === id
|
|
14035
14303
|
? { ...key, state: "active" }
|
|
14036
14304
|
: key?.state === "active"
|
|
14037
14305
|
? { ...key, state: "decrypt-only" }
|
|
14038
|
-
: key)
|
|
14306
|
+
: key);
|
|
14307
|
+
// Checked before the hook, which may change a deployment platform: that
|
|
14308
|
+
// must not happen for a list that could not then be written.
|
|
14309
|
+
validateSecretKeys(environment, next);
|
|
14310
|
+
if (!options.beforeWrite) {
|
|
14311
|
+
return {
|
|
14312
|
+
activeKeyName: loaded.config.env.activeKeyName,
|
|
14313
|
+
changedFiles: await writeSecretKeys(cwd, loaded, environment, next),
|
|
14314
|
+
environment,
|
|
14315
|
+
id,
|
|
14316
|
+
};
|
|
14317
|
+
}
|
|
14318
|
+
const changedOutside = await options.beforeWrite({
|
|
14319
|
+
activeKeyName: loaded.config.env.activeKeyName,
|
|
14320
|
+
id,
|
|
14321
|
+
variableName: `${loaded.config.env.keyPrefix}${id}`,
|
|
14322
|
+
});
|
|
14323
|
+
let changedFiles;
|
|
14324
|
+
try {
|
|
14325
|
+
changedFiles = await writeSecretKeys(cwd, loaded, environment, next);
|
|
14326
|
+
}
|
|
14327
|
+
catch (error) {
|
|
14328
|
+
if (!changedOutside)
|
|
14329
|
+
throw error;
|
|
14330
|
+
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.`);
|
|
14331
|
+
}
|
|
14039
14332
|
return {
|
|
14040
14333
|
activeKeyName: loaded.config.env.activeKeyName,
|
|
14041
14334
|
changedFiles,
|
|
@@ -14211,6 +14504,11 @@ export async function checkProject(cwd, env = process.env, options = {}) {
|
|
|
14211
14504
|
for (const suggestion of pnpmCompatibilityCheck.suggestions) {
|
|
14212
14505
|
suggestions.add(suggestion);
|
|
14213
14506
|
}
|
|
14507
|
+
const pnpmEnginesCheck = checkPnpmEnginesWithPackageManager(packageJson);
|
|
14508
|
+
warnings.push(...pnpmEnginesCheck.warnings);
|
|
14509
|
+
for (const suggestion of pnpmEnginesCheck.suggestions) {
|
|
14510
|
+
suggestions.add(suggestion);
|
|
14511
|
+
}
|
|
14214
14512
|
const framework = await detectFramework(cwd, packageJson);
|
|
14215
14513
|
const dependency = packageJson.dependencies?.[LOOM_DEPENDENCY];
|
|
14216
14514
|
if (!dependency) {
|
|
@@ -14869,9 +15167,10 @@ function printHelp({ out }) {
|
|
|
14869
15167
|
out(" files r2 check Verify R2 buckets/account/privacy, Vercel env scoping, local storage, and Files adapter wiring.");
|
|
14870
15168
|
out(" api-keys integrate jobs Record an explicit API-key jobs integration after the route has session/admin authorization.");
|
|
14871
15169
|
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.");
|
|
15170
|
+
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.");
|
|
15171
|
+
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
15172
|
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.");
|
|
15173
|
+
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
15174
|
out(" secrets retire <id> Record a secrets key that nothing needs any more as retired.");
|
|
14876
15175
|
out(" status Show the Loom package, manifest, active features, local-dev state, and project skill state.");
|
|
14877
15176
|
out(" check Validate project bootstrap, managed guidance, features, skill locks, caches, and links.");
|
|
@@ -14891,6 +15190,7 @@ function printHelp({ out }) {
|
|
|
14891
15190
|
out(" db release trust-apply <plan> <approval-sha256> Apply a reviewed Trusted Sources plan.");
|
|
14892
15191
|
out(" db release trust-check <plan> Verify the reviewed Trusted Sources plan is active.");
|
|
14893
15192
|
out(" db release prepare-build-env <env> <metadata> <policy> <manifest> Prepare metadata-backed placeholders for an external Vercel build.");
|
|
15193
|
+
out(" db release mask-env <env> Print GitHub Actions ::add-mask:: commands for secret-capable pulled Vercel values.");
|
|
14894
15194
|
out(" db release prepare-vercel-project production <env> <metadata> <project> Materialize project-scoped Production release inputs.");
|
|
14895
15195
|
out(" db release promote-vercel <deployment-id> Promote an exact READY Production deployment with project-scoped auth.");
|
|
14896
15196
|
out(" db release verify-build-env <output> <manifest> [deployment-root] Reject build-only placeholders in a deployable Vercel artifact.");
|
|
@@ -14904,6 +15204,7 @@ function printHelp({ out }) {
|
|
|
14904
15204
|
out(" --network Run registered network checks after the local project checks.");
|
|
14905
15205
|
out(" --production Treat local Loom dev overrides and local lockfile resolutions as release-blocking check failures.");
|
|
14906
15206
|
out(" --no-progress Disable the interactive network progress renderer.");
|
|
15207
|
+
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
15208
|
out(" --local-db-host <host> Local PostgreSQL host (default: db.localtest.me).");
|
|
14908
15209
|
out(" --local-db-port <port> Local PostgreSQL port (default: 5432).");
|
|
14909
15210
|
out(" --replace-local-target Replace an existing development URL during local DB setup.");
|
|
@@ -14976,6 +15277,29 @@ async function runApiKeys(cwd, command, target, options, io) {
|
|
|
14976
15277
|
io.out(`Note: ${note}`);
|
|
14977
15278
|
return 0;
|
|
14978
15279
|
}
|
|
15280
|
+
/**
|
|
15281
|
+
* Whether what follows `loom secrets push` is only a version number and
|
|
15282
|
+
* options Loom knows. Anything else may be a key typed in the wrong place,
|
|
15283
|
+
* which the argument parser would quote back in its error.
|
|
15284
|
+
*/
|
|
15285
|
+
function secretsPushArgumentsAreSafe(rest) {
|
|
15286
|
+
const flags = ["--vercel", "--no-vercel", "--no-color", "--help", "-h"];
|
|
15287
|
+
const withValue = ["--cwd", "--environment"];
|
|
15288
|
+
for (let index = 0; index < rest.length; index += 1) {
|
|
15289
|
+
const arg = rest[index];
|
|
15290
|
+
if (/^[1-9][0-9]{0,8}$/.test(arg) || flags.includes(arg))
|
|
15291
|
+
continue;
|
|
15292
|
+
if (withValue.some((name) => arg.startsWith(`${name}=`)))
|
|
15293
|
+
continue;
|
|
15294
|
+
if (withValue.includes(arg) && index + 1 < rest.length) {
|
|
15295
|
+
index += 1;
|
|
15296
|
+
continue;
|
|
15297
|
+
}
|
|
15298
|
+
return false;
|
|
15299
|
+
}
|
|
15300
|
+
return true;
|
|
15301
|
+
}
|
|
15302
|
+
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
15303
|
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
15304
|
/**
|
|
14981
15305
|
* Variables that an automated or agent session sets. A key must not be shown
|
|
@@ -14991,13 +15315,239 @@ const AUTOMATED_SESSION_ENV_NAMES = [
|
|
|
14991
15315
|
"CURSOR_AGENT",
|
|
14992
15316
|
"GEMINI_CLI",
|
|
14993
15317
|
];
|
|
14994
|
-
|
|
14995
|
-
|
|
15318
|
+
/**
|
|
15319
|
+
* Whether a command may change something outside the repository, such as a
|
|
15320
|
+
* deployment platform's settings. An explicit flag decides. Without one, only
|
|
15321
|
+
* a person at a terminal is asked, and the default answer is no; anywhere
|
|
15322
|
+
* else nothing outside changes and the command says how to do it instead.
|
|
15323
|
+
* See "CLI prompts and outside changes" in AGENTS.md.
|
|
15324
|
+
*/
|
|
15325
|
+
export function resolveOutsideChange(flags, interactive) {
|
|
15326
|
+
if (flags.yes)
|
|
15327
|
+
return "yes";
|
|
15328
|
+
if (flags.no)
|
|
15329
|
+
return "no";
|
|
15330
|
+
return interactive ? "ask" : "no";
|
|
15331
|
+
}
|
|
15332
|
+
const isYesAnswer = (answer) => /^y(es)?$/i.test(answer.trim());
|
|
15333
|
+
/**
|
|
15334
|
+
* Parses `vercel env ls --format json` output, or returns null when it is not
|
|
15335
|
+
* that listing. Vercel CLI 54 and newer print it.
|
|
15336
|
+
*/
|
|
15337
|
+
function parseVercelEnvListing(text) {
|
|
15338
|
+
let parsed;
|
|
15339
|
+
try {
|
|
15340
|
+
parsed = JSON.parse(text.slice(text.indexOf("{"), text.lastIndexOf("}") + 1));
|
|
15341
|
+
}
|
|
15342
|
+
catch {
|
|
15343
|
+
return null;
|
|
15344
|
+
}
|
|
15345
|
+
const envs = isJsonObject(parsed) ? parsed.envs : undefined;
|
|
15346
|
+
if (!Array.isArray(envs))
|
|
15347
|
+
return null;
|
|
15348
|
+
return envs.flatMap((entry) => {
|
|
15349
|
+
if (!isJsonObject(entry) || typeof entry.key !== "string")
|
|
15350
|
+
return [];
|
|
15351
|
+
const targets = (Array.isArray(entry.target) ? entry.target : [entry.target])
|
|
15352
|
+
.filter((target) => typeof target === "string");
|
|
15353
|
+
return [{
|
|
15354
|
+
custom: Array.isArray(entry.customEnvironmentIds) &&
|
|
15355
|
+
entry.customEnvironmentIds.length > 0,
|
|
15356
|
+
key: entry.key,
|
|
15357
|
+
secret: entry.type === "sensitive" || entry.visibility === "secret",
|
|
15358
|
+
targets,
|
|
15359
|
+
type: typeof entry.type === "string" ? entry.type : "",
|
|
15360
|
+
}];
|
|
15361
|
+
});
|
|
15362
|
+
}
|
|
15363
|
+
async function listVercelProductionVariables(cwd, commandRunner, command, env) {
|
|
15364
|
+
// JSON, not the table: the table cannot tell a variable that applies to
|
|
15365
|
+
// Production alone from one shared with Preview, and a name could appear
|
|
15366
|
+
// inside another variable's displayed value.
|
|
15367
|
+
const result = await commandRunner(command, ["env", "ls", "production", "--format", "json"], { cwd, env, stdio: "pipe" });
|
|
15368
|
+
if (result.code !== 0) {
|
|
15369
|
+
throw new Error(`Could not list Vercel Production variables: ${vercelFailureDetail(result, "")}`);
|
|
15370
|
+
}
|
|
15371
|
+
const variables = parseVercelEnvListing(result.stdout);
|
|
15372
|
+
if (!variables) {
|
|
15373
|
+
throw new Error("Vercel did not list Production variables as JSON.");
|
|
15374
|
+
}
|
|
15375
|
+
return variables.filter((variable) => variable.targets.includes("production"));
|
|
15376
|
+
}
|
|
15377
|
+
const vercelVariables = (target, key) => target.variables.filter((variable) => variable.key === key);
|
|
15378
|
+
/**
|
|
15379
|
+
* Why the pointer cannot simply be updated for Production, or null when it
|
|
15380
|
+
* can. A variable shared with Preview would move its pointer too, and Preview
|
|
15381
|
+
* has a key list of its own. Sharing with a custom environment is not in
|
|
15382
|
+
* Vercel's listing, so it cannot be seen here.
|
|
15383
|
+
*/
|
|
15384
|
+
function vercelPointerProblem(target, name) {
|
|
15385
|
+
const found = vercelVariables(target, name);
|
|
15386
|
+
if (found.length === 0)
|
|
15387
|
+
return null;
|
|
15388
|
+
const shared = found.find((variable) => variable.custom || variable.targets.some((each) => each !== "production"));
|
|
15389
|
+
return found.length > 1 || shared
|
|
15390
|
+
? `${name} on Vercel is shared with ${shared
|
|
15391
|
+
? shared.targets.filter((each) => each !== "production").join(", ") ||
|
|
15392
|
+
"a custom environment"
|
|
15393
|
+
: "another entry"}. Give Production its own ${name} by hand, so the other environments keep theirs.`
|
|
15394
|
+
: null;
|
|
15395
|
+
}
|
|
15396
|
+
async function findSecretsVercelTarget(cwd, commandRunner) {
|
|
15397
|
+
const link = await readVercelProjectLink(cwd);
|
|
15398
|
+
if (!link.linked || !link.projectId) {
|
|
15399
|
+
return {
|
|
15400
|
+
linked: false,
|
|
15401
|
+
reason: `This project is not linked to Vercel: ${link.detail} Run \`vercel link\` first.`,
|
|
15402
|
+
};
|
|
15403
|
+
}
|
|
15404
|
+
// The link names the project; inherited ids would silently point the
|
|
15405
|
+
// writes somewhere else.
|
|
15406
|
+
const env = withoutInheritedVercelProject(process.env);
|
|
15407
|
+
const cli = await detectVercelCliCommand(cwd, commandRunner, env);
|
|
15408
|
+
if (!cli.command) {
|
|
15409
|
+
return {
|
|
15410
|
+
linked: true,
|
|
15411
|
+
reason: "The Vercel CLI (`vercel` or `vc`) was not found.",
|
|
15412
|
+
};
|
|
15413
|
+
}
|
|
15414
|
+
try {
|
|
15415
|
+
return {
|
|
15416
|
+
target: {
|
|
15417
|
+
command: cli.command,
|
|
15418
|
+
env,
|
|
15419
|
+
project: link.projectName ?? link.projectId,
|
|
15420
|
+
variables: await listVercelProductionVariables(cwd, commandRunner, cli.command, env),
|
|
15421
|
+
},
|
|
15422
|
+
};
|
|
15423
|
+
}
|
|
15424
|
+
catch (error) {
|
|
15425
|
+
return { linked: true, reason: error.message };
|
|
15426
|
+
}
|
|
15427
|
+
}
|
|
15428
|
+
function warnIfPointerSecret(target, name, io) {
|
|
15429
|
+
if (vercelVariables(target, name).some((variable) => variable.secret)) {
|
|
15430
|
+
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.`);
|
|
15431
|
+
}
|
|
15432
|
+
}
|
|
15433
|
+
/** Sets the pointer for Production only, as a readable variable. */
|
|
15434
|
+
async function setVercelPointer(cwd, commandRunner, target, name, id) {
|
|
15435
|
+
if (vercelVariables(target, name).length) {
|
|
15436
|
+
await updateVercelEnvValue(cwd, commandRunner, target.env, target.command, name, String(id), "production");
|
|
15437
|
+
}
|
|
15438
|
+
else {
|
|
15439
|
+
// Without --no-sensitive, a value given on stdin is stored as a Secret,
|
|
15440
|
+
// which `vercel pull` cannot read back for the release build.
|
|
15441
|
+
await addVercelEnvValue(cwd, commandRunner, target.env, target.command, name, String(id), "production", ["--no-sensitive", "--yes"]);
|
|
15442
|
+
}
|
|
15443
|
+
}
|
|
15444
|
+
/**
|
|
15445
|
+
* Puts a secrets key on Vercel Production as a Secret, and the pointer when
|
|
15446
|
+
* the key is the active one, from a copy the operator pastes back from their
|
|
15447
|
+
* password manager. That copy is checked against the fingerprint in loom.json
|
|
15448
|
+
* before Vercel gets it: a key that reached Vercel but not the password
|
|
15449
|
+
* manager could never be recovered, since Vercel never shows a Secret again.
|
|
15450
|
+
* Afterwards Vercel is listed again to confirm how it stored them.
|
|
15451
|
+
*/
|
|
15452
|
+
async function pushSecretsKeyToVercel(cwd, commandRunner, target, key, terminal, io, options) {
|
|
15453
|
+
if (vercelVariables(target, key.variableName).length) {
|
|
15454
|
+
io.err(`${key.variableName} already exists in Vercel Production. Loom never replaces a key there; find out why Vercel and loom.json differ first.`);
|
|
15455
|
+
return false;
|
|
15456
|
+
}
|
|
15457
|
+
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.`);
|
|
15458
|
+
let value = null;
|
|
15459
|
+
for (let attempt = 1; attempt <= 3 && value === null; attempt += 1) {
|
|
15460
|
+
let pasted = (await terminal.prompt(`${key.variableName} from your password manager (input is hidden): `)).trim();
|
|
15461
|
+
if (!pasted) {
|
|
15462
|
+
io.err("Nothing was entered, so nothing was sent to Vercel.");
|
|
15463
|
+
return false;
|
|
15464
|
+
}
|
|
15465
|
+
// The whole printed line is a likely thing to have saved.
|
|
15466
|
+
if (pasted.startsWith(`${key.variableName}=`)) {
|
|
15467
|
+
pasted = pasted.slice(key.variableName.length + 1).trim();
|
|
15468
|
+
}
|
|
15469
|
+
let fingerprint = null;
|
|
15470
|
+
try {
|
|
15471
|
+
fingerprint = await fingerprintSecretsKey(pasted);
|
|
15472
|
+
}
|
|
15473
|
+
catch {
|
|
15474
|
+
io.err("That is not a secrets key: it does not decode to 32 bytes. Check the saved copy.");
|
|
15475
|
+
continue;
|
|
15476
|
+
}
|
|
15477
|
+
if (fingerprint === key.fingerprint) {
|
|
15478
|
+
value = pasted;
|
|
15479
|
+
}
|
|
15480
|
+
else {
|
|
15481
|
+
io.err(`That is a different key from version ${key.id}: its fingerprint does not match loom.json. Check the saved copy.`);
|
|
15482
|
+
}
|
|
15483
|
+
}
|
|
15484
|
+
if (value === null) {
|
|
15485
|
+
io.err(`Nothing was sent to Vercel. Fix the saved copy, then run \`loom secrets push ${key.id}\`.`);
|
|
15486
|
+
return false;
|
|
15487
|
+
}
|
|
15488
|
+
let setPointer = key.state === "active";
|
|
15489
|
+
const pointerProblem = setPointer
|
|
15490
|
+
? vercelPointerProblem(target, key.activeKeyName)
|
|
15491
|
+
: null;
|
|
15492
|
+
if (pointerProblem)
|
|
15493
|
+
setPointer = false;
|
|
15494
|
+
else if (setPointer && vercelVariables(target, key.activeKeyName).length) {
|
|
15495
|
+
setPointer = options.replacePointer === "ask" &&
|
|
15496
|
+
isYesAnswer(await terminal.ask(`${key.activeKeyName} already exists in Vercel Production. Set it to ${key.id}? [y/N] `));
|
|
15497
|
+
}
|
|
15498
|
+
try {
|
|
15499
|
+
await addVercelEnvValue(cwd, commandRunner, target.env, target.command, key.variableName, value, "production", ["--sensitive", "--yes"]);
|
|
15500
|
+
}
|
|
15501
|
+
catch (error) {
|
|
15502
|
+
io.err(`${error.message} Nothing else was changed.`);
|
|
15503
|
+
return false;
|
|
15504
|
+
}
|
|
15505
|
+
if (setPointer) {
|
|
15506
|
+
try {
|
|
15507
|
+
await setVercelPointer(cwd, commandRunner, target, key.activeKeyName, key.id);
|
|
15508
|
+
}
|
|
15509
|
+
catch (error) {
|
|
15510
|
+
io.err(`${key.variableName} was added, but ${key.activeKeyName} was not: ${error.message} Set ${key.activeKeyName}=${key.id} in Vercel Production yourself.`);
|
|
15511
|
+
return false;
|
|
15512
|
+
}
|
|
15513
|
+
}
|
|
15514
|
+
// Confirm what Vercel stored, rather than trusting how it was asked.
|
|
15515
|
+
let stored;
|
|
15516
|
+
try {
|
|
15517
|
+
stored = await listVercelProductionVariables(cwd, commandRunner, target.command, target.env);
|
|
15518
|
+
}
|
|
15519
|
+
catch (error) {
|
|
15520
|
+
io.err(`Added ${key.variableName}, but could not confirm how Vercel stored it: ${error.message} Check it is a Secret for Production only.`);
|
|
15521
|
+
return false;
|
|
15522
|
+
}
|
|
15523
|
+
const confirmed = { ...target, variables: stored };
|
|
15524
|
+
const keyEntry = vercelVariables(confirmed, key.variableName);
|
|
15525
|
+
if (keyEntry.length !== 1 || !keyEntry[0].secret ||
|
|
15526
|
+
keyEntry[0].custom || keyEntry[0].targets.join() !== "production") {
|
|
15527
|
+
io.err(`Vercel did not store ${key.variableName} as a Secret for Production only. Fix it in Vercel before deploying.`);
|
|
15528
|
+
return false;
|
|
15529
|
+
}
|
|
15530
|
+
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.`);
|
|
15531
|
+
if (setPointer)
|
|
15532
|
+
warnIfPointerSecret(confirmed, key.activeKeyName, io);
|
|
15533
|
+
if (pointerProblem)
|
|
15534
|
+
io.err(pointerProblem);
|
|
15535
|
+
else if (key.state === "active" && !setPointer) {
|
|
15536
|
+
io.out(`Set ${key.activeKeyName}=${key.id} in Vercel Production before deploying.`);
|
|
15537
|
+
}
|
|
15538
|
+
return true;
|
|
15539
|
+
}
|
|
15540
|
+
async function runSecrets(cwd, command, target, options, io, terminal = {}, commandRunner = defaultCommandRunner) {
|
|
15541
|
+
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
15542
|
const environmentOption = options.environment ?? "production";
|
|
14997
15543
|
if (environmentOption !== "production" && environmentOption !== "preview") {
|
|
14998
15544
|
io.err("--environment must be production or preview.");
|
|
14999
15545
|
return 1;
|
|
15000
15546
|
}
|
|
15547
|
+
if (options.vercel && options.noVercel) {
|
|
15548
|
+
io.err("--vercel and --no-vercel cannot be used together.");
|
|
15549
|
+
return 1;
|
|
15550
|
+
}
|
|
15001
15551
|
const environment = environmentOption;
|
|
15002
15552
|
const platformTarget = environment === "production"
|
|
15003
15553
|
? "Production"
|
|
@@ -15006,6 +15556,27 @@ async function runSecrets(cwd, command, target, options, io, terminal = {}) {
|
|
|
15006
15556
|
const stdoutIsTty = terminal.stdoutIsTty ?? Boolean(process.stdout.isTTY);
|
|
15007
15557
|
const sessionEnv = terminal.env ?? process.env;
|
|
15008
15558
|
const automatedMarker = AUTOMATED_SESSION_ENV_NAMES.find((name) => Boolean(sessionEnv[name]));
|
|
15559
|
+
const vercelChoice = resolveOutsideChange({ no: options.noVercel, yes: options.vercel }, stdinIsTty && stdoutIsTty && !automatedMarker);
|
|
15560
|
+
if (options.vercel && environment !== "production") {
|
|
15561
|
+
io.err("--vercel sets Vercel Production only. Set Preview variables yourself.");
|
|
15562
|
+
return 1;
|
|
15563
|
+
}
|
|
15564
|
+
// Raw mode rather than readline: under Deno a readline question never
|
|
15565
|
+
// settles on Ctrl-C, and the command would end without a word.
|
|
15566
|
+
const ask = terminal.ask ??
|
|
15567
|
+
((question) => promptForTerminalValue(question, false, {
|
|
15568
|
+
cancelled: "Cancelled.",
|
|
15569
|
+
notInteractive: "This question needs a terminal.",
|
|
15570
|
+
}, { rawEcho: true }));
|
|
15571
|
+
const prompt = (cancelled, notInteractive) => terminal.prompt ??
|
|
15572
|
+
((question) => promptForTerminalValue(question, true, { cancelled, notInteractive }));
|
|
15573
|
+
// Reading a key is only for a person at a terminal: never a pipe, a file
|
|
15574
|
+
// or an agent's session, whose transcript would then hold the key.
|
|
15575
|
+
const keyReadRefusal = (name) => automatedMarker
|
|
15576
|
+
? `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.`
|
|
15577
|
+
: !stdinIsTty
|
|
15578
|
+
? `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.`
|
|
15579
|
+
: null;
|
|
15009
15580
|
try {
|
|
15010
15581
|
switch (command) {
|
|
15011
15582
|
case "keygen": {
|
|
@@ -15024,6 +15595,29 @@ async function runSecrets(cwd, command, target, options, io, terminal = {}) {
|
|
|
15024
15595
|
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
15596
|
return 1;
|
|
15026
15597
|
}
|
|
15598
|
+
// Asked for explicitly, Vercel must be reachable before a key exists:
|
|
15599
|
+
// finding out afterwards would leave a recorded key with nowhere to go.
|
|
15600
|
+
let vercel = null;
|
|
15601
|
+
let vercelNote = null;
|
|
15602
|
+
if (vercelChoice !== "no" && environment === "production") {
|
|
15603
|
+
const found = await findSecretsVercelTarget(cwd, commandRunner);
|
|
15604
|
+
const planned = await planSecretsKey(cwd, environment);
|
|
15605
|
+
if ("target" in found &&
|
|
15606
|
+
vercelVariables(found.target, planned.variableName).length) {
|
|
15607
|
+
// Drift between Vercel and loom.json, whether or not Vercel was
|
|
15608
|
+
// asked for; a key generated now would have nowhere to go.
|
|
15609
|
+
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.`);
|
|
15610
|
+
return 1;
|
|
15611
|
+
}
|
|
15612
|
+
if (!("target" in found) && vercelChoice === "yes") {
|
|
15613
|
+
io.err(`${found.reason} No key was generated.`);
|
|
15614
|
+
return 1;
|
|
15615
|
+
}
|
|
15616
|
+
if ("target" in found)
|
|
15617
|
+
vercel = found.target;
|
|
15618
|
+
else if (found.linked)
|
|
15619
|
+
vercelNote = found.reason;
|
|
15620
|
+
}
|
|
15027
15621
|
const result = await generateSecretsKey(cwd, { environment });
|
|
15028
15622
|
io.out(`Generated secrets key version ${result.id} for ${environment}. It is shown once and Loom keeps no copy.`);
|
|
15029
15623
|
io.out("");
|
|
@@ -15031,16 +15625,92 @@ async function runSecrets(cwd, command, target, options, io, terminal = {}) {
|
|
|
15031
15625
|
io.out(`Fingerprint: ${result.fingerprint}`);
|
|
15032
15626
|
io.out("");
|
|
15033
15627
|
io.out(`Recorded the fingerprint in loom.json as ${result.state}. Commit loom.json; it holds no key.`);
|
|
15628
|
+
let pushed = false;
|
|
15629
|
+
let go = false;
|
|
15630
|
+
if (vercel) {
|
|
15631
|
+
io.out("Save the key and its fingerprint in your password manager now, before anything else.");
|
|
15632
|
+
try {
|
|
15633
|
+
go = vercelChoice === "yes" || isYesAnswer(await ask(`Add ${result.variableName} (Secret, Production only)${result.state === "active"
|
|
15634
|
+
? ` and ${result.activeKeyName}=${result.id}`
|
|
15635
|
+
: ""} to Vercel project ${vercel.project}? [y/N] `));
|
|
15636
|
+
}
|
|
15637
|
+
catch {
|
|
15638
|
+
// An interrupted question is a no; the next steps still print.
|
|
15639
|
+
}
|
|
15640
|
+
if (go) {
|
|
15641
|
+
pushed = await pushSecretsKeyToVercel(cwd, commandRunner, vercel, result, {
|
|
15642
|
+
ask,
|
|
15643
|
+
prompt: prompt("Nothing was sent to Vercel.", "This needs a terminal."),
|
|
15644
|
+
}, io,
|
|
15645
|
+
// An explicit --vercel asks nothing more, so it leaves an
|
|
15646
|
+
// existing pointer alone and says so.
|
|
15647
|
+
{ replacePointer: vercelChoice === "yes" ? "no" : "ask" }).catch((error) => {
|
|
15648
|
+
io.err(`${error.message} Nothing was sent to Vercel.`);
|
|
15649
|
+
return false;
|
|
15650
|
+
});
|
|
15651
|
+
}
|
|
15652
|
+
}
|
|
15653
|
+
else if (vercelNote) {
|
|
15654
|
+
io.out(`Note: Vercel was not offered: ${vercelNote}`);
|
|
15655
|
+
}
|
|
15034
15656
|
io.out("Next steps:");
|
|
15035
|
-
|
|
15036
|
-
|
|
15037
|
-
|
|
15038
|
-
|
|
15039
|
-
|
|
15040
|
-
|
|
15657
|
+
const steps = [];
|
|
15658
|
+
if (!vercel) {
|
|
15659
|
+
steps.push("Save the key and its fingerprint in your password manager now, before anything else.");
|
|
15660
|
+
}
|
|
15661
|
+
if (!pushed) {
|
|
15662
|
+
steps.push(`Add ${result.variableName} to the deployment platform from the password-manager copy, ${platformTarget} only, as a write-only secret${result.state === "active"
|
|
15663
|
+
? `, and set ${result.activeKeyName}=${result.id} there`
|
|
15664
|
+
: ""}.${environment === "production"
|
|
15665
|
+
? ` On Vercel, \`loom secrets push ${result.id}\` checks the saved copy and does this for you.`
|
|
15666
|
+
: ""}`);
|
|
15667
|
+
}
|
|
15668
|
+
steps.push("Deploy.");
|
|
15669
|
+
steps.push(`Confirm \`secrets.assertReady()\` passes in the deployment: that proves the deployed key is the one you saved.${result.state === "active"
|
|
15041
15670
|
? ""
|
|
15042
15671
|
: ` Then switch to it with \`loom secrets activate ${result.id}\`.`}`);
|
|
15043
|
-
|
|
15672
|
+
steps.forEach((step, index) => io.out(` ${index + 1}. ${step}`));
|
|
15673
|
+
// The key exists either way; a push that was asked for and did not
|
|
15674
|
+
// happen is still a failure for whoever runs this.
|
|
15675
|
+
return go && !pushed ? 1 : 0;
|
|
15676
|
+
}
|
|
15677
|
+
case "push": {
|
|
15678
|
+
const id = target === undefined ? null : parseSecretKeyId(target);
|
|
15679
|
+
if (id === null) {
|
|
15680
|
+
io.err(usage);
|
|
15681
|
+
return 1;
|
|
15682
|
+
}
|
|
15683
|
+
if (options.vercel || options.noVercel) {
|
|
15684
|
+
io.err("loom secrets push always asks first; it takes no --vercel or --no-vercel.");
|
|
15685
|
+
return 1;
|
|
15686
|
+
}
|
|
15687
|
+
const refusal = keyReadRefusal("push");
|
|
15688
|
+
if (refusal) {
|
|
15689
|
+
io.err(refusal);
|
|
15690
|
+
return 1;
|
|
15691
|
+
}
|
|
15692
|
+
if (environment !== "production") {
|
|
15693
|
+
io.err("loom secrets push sets Vercel Production only. Set Preview variables yourself.");
|
|
15694
|
+
return 1;
|
|
15695
|
+
}
|
|
15696
|
+
const key = await recordedSecretsKey(cwd, id, environment);
|
|
15697
|
+
const found = await findSecretsVercelTarget(cwd, commandRunner);
|
|
15698
|
+
if (!("target" in found)) {
|
|
15699
|
+
io.err(found.reason);
|
|
15700
|
+
return 1;
|
|
15701
|
+
}
|
|
15702
|
+
if (!isYesAnswer(await ask(`Add ${key.variableName} (Secret, Production only)${key.state === "active"
|
|
15703
|
+
? ` and ${key.activeKeyName}=${key.id}`
|
|
15704
|
+
: ""} to Vercel project ${found.target.project}? [y/N] `))) {
|
|
15705
|
+
io.out("Nothing was changed.");
|
|
15706
|
+
return 0;
|
|
15707
|
+
}
|
|
15708
|
+
return await pushSecretsKeyToVercel(cwd, commandRunner, found.target, key, {
|
|
15709
|
+
ask,
|
|
15710
|
+
prompt: prompt("Nothing was sent to Vercel.", keyReadRefusal("push") ?? "This needs a terminal."),
|
|
15711
|
+
}, io, { replacePointer: "ask" })
|
|
15712
|
+
? 0
|
|
15713
|
+
: 1;
|
|
15044
15714
|
}
|
|
15045
15715
|
case "fingerprint": {
|
|
15046
15716
|
// Checked before anything else, and never echoed: whatever followed
|
|
@@ -15049,21 +15719,17 @@ async function runSecrets(cwd, command, target, options, io, terminal = {}) {
|
|
|
15049
15719
|
io.err(SECRETS_FINGERPRINT_ARGUMENT_REFUSAL);
|
|
15050
15720
|
return 1;
|
|
15051
15721
|
}
|
|
15052
|
-
if (
|
|
15053
|
-
io.err(
|
|
15722
|
+
if (options.vercel || options.noVercel) {
|
|
15723
|
+
io.err("loom secrets fingerprint changes nothing on Vercel.");
|
|
15054
15724
|
return 1;
|
|
15055
15725
|
}
|
|
15056
|
-
const
|
|
15057
|
-
if (
|
|
15058
|
-
io.err(
|
|
15726
|
+
const refusal = keyReadRefusal("fingerprint");
|
|
15727
|
+
if (refusal) {
|
|
15728
|
+
io.err(refusal);
|
|
15059
15729
|
return 1;
|
|
15060
15730
|
}
|
|
15061
|
-
const
|
|
15062
|
-
|
|
15063
|
-
cancelled: "Fingerprinting was cancelled.",
|
|
15064
|
-
notInteractive,
|
|
15065
|
-
}));
|
|
15066
|
-
io.out(await fingerprintSecretsKey(await prompt("Secrets key (input is hidden): ")));
|
|
15731
|
+
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.");
|
|
15732
|
+
io.out(await fingerprintSecretsKey(await readKey("Secrets key (input is hidden): ")));
|
|
15067
15733
|
return 0;
|
|
15068
15734
|
}
|
|
15069
15735
|
case "activate":
|
|
@@ -15074,13 +15740,78 @@ async function runSecrets(cwd, command, target, options, io, terminal = {}) {
|
|
|
15074
15740
|
return 1;
|
|
15075
15741
|
}
|
|
15076
15742
|
if (command === "activate") {
|
|
15077
|
-
|
|
15743
|
+
if (environment !== "production" && options.vercel) {
|
|
15744
|
+
io.err("--vercel sets Vercel Production only. Set Preview variables yourself.");
|
|
15745
|
+
return 1;
|
|
15746
|
+
}
|
|
15747
|
+
let pointerSet = false;
|
|
15748
|
+
let vercelNote = null;
|
|
15749
|
+
const result = await activateSecretsKey(cwd, id, environment, {
|
|
15750
|
+
// The platform's pointer moves first: a deployment carrying the
|
|
15751
|
+
// new list with the old pointer would fail every seal. A build
|
|
15752
|
+
// between the two, with the new pointer and the old list, fails
|
|
15753
|
+
// too, so loom.json should follow at once.
|
|
15754
|
+
beforeWrite: async (key) => {
|
|
15755
|
+
if (vercelChoice === "no" || environment !== "production") {
|
|
15756
|
+
return false;
|
|
15757
|
+
}
|
|
15758
|
+
const found = await findSecretsVercelTarget(cwd, commandRunner);
|
|
15759
|
+
const refusal = !("target" in found)
|
|
15760
|
+
? found.reason
|
|
15761
|
+
: !vercelVariables(found.target, key.variableName).length
|
|
15762
|
+
? `${key.variableName} is not in Vercel Production. Add it (\`loom secrets push ${id}\`) and deploy before activating it.`
|
|
15763
|
+
: vercelPointerProblem(found.target, key.activeKeyName);
|
|
15764
|
+
if (refusal) {
|
|
15765
|
+
if (vercelChoice === "yes") {
|
|
15766
|
+
throw new Error(`${refusal} loom.json was not changed.`);
|
|
15767
|
+
}
|
|
15768
|
+
if ("target" in found || found.linked)
|
|
15769
|
+
vercelNote = refusal;
|
|
15770
|
+
return false;
|
|
15771
|
+
}
|
|
15772
|
+
const vercel = found.target;
|
|
15773
|
+
if (vercelChoice === "ask" &&
|
|
15774
|
+
!isYesAnswer(await ask(`Set ${key.activeKeyName}=${id} in Vercel project ${vercel.project}, Production, before loom.json changes? [y/N] `).catch(() => ""))) {
|
|
15775
|
+
return false;
|
|
15776
|
+
}
|
|
15777
|
+
try {
|
|
15778
|
+
await setVercelPointer(cwd, commandRunner, vercel, key.activeKeyName, id);
|
|
15779
|
+
}
|
|
15780
|
+
catch (error) {
|
|
15781
|
+
throw new Error(`${error.message} loom.json was not changed.`);
|
|
15782
|
+
}
|
|
15783
|
+
pointerSet = true;
|
|
15784
|
+
io.out(`Set ${key.activeKeyName}=${id} in Vercel project ${vercel.project}, Production.`);
|
|
15785
|
+
// Team policy, or an existing Secret kept by `env update`, can
|
|
15786
|
+
// leave the pointer unreadable to the release build.
|
|
15787
|
+
try {
|
|
15788
|
+
warnIfPointerSecret({
|
|
15789
|
+
...vercel,
|
|
15790
|
+
variables: await listVercelProductionVariables(cwd, commandRunner, vercel.command, vercel.env),
|
|
15791
|
+
}, key.activeKeyName, io);
|
|
15792
|
+
}
|
|
15793
|
+
catch {
|
|
15794
|
+
// The pointer is set; how it is stored is a warning only.
|
|
15795
|
+
}
|
|
15796
|
+
return true;
|
|
15797
|
+
},
|
|
15798
|
+
});
|
|
15078
15799
|
io.out(result.changedFiles.length
|
|
15079
15800
|
? `Updated ${result.changedFiles.join(", ")}: key version ${id} is now the active ${environment} key.`
|
|
15080
15801
|
: `Key version ${id} is already the active ${environment} key in loom.json.`);
|
|
15081
|
-
|
|
15802
|
+
if (vercelNote)
|
|
15803
|
+
io.out(`Note: Vercel was not changed: ${vercelNote}`);
|
|
15804
|
+
io.out(pointerSet
|
|
15805
|
+
? "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."
|
|
15806
|
+
: `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"
|
|
15807
|
+
? " On Vercel, `--vercel` does this first."
|
|
15808
|
+
: ""}`);
|
|
15082
15809
|
return 0;
|
|
15083
15810
|
}
|
|
15811
|
+
if (options.vercel || options.noVercel) {
|
|
15812
|
+
io.err("loom secrets retire changes nothing on Vercel; remove the variable there yourself, after deploying the retired list.");
|
|
15813
|
+
return 1;
|
|
15814
|
+
}
|
|
15084
15815
|
const result = await retireSecretsKey(cwd, id, environment);
|
|
15085
15816
|
io.out(result.changedFiles.length
|
|
15086
15817
|
? `Updated ${result.changedFiles.join(", ")}: key version ${id} is now retired for ${environment}.`
|
|
@@ -15719,6 +16450,13 @@ async function runDbRelease(cwd, command, args, io, options) {
|
|
|
15719
16450
|
}, io);
|
|
15720
16451
|
return 0;
|
|
15721
16452
|
}
|
|
16453
|
+
case "mask-env": {
|
|
16454
|
+
if (args.length !== 1) {
|
|
16455
|
+
io.err("Usage: loom db release mask-env <env-file>");
|
|
16456
|
+
return 1;
|
|
16457
|
+
}
|
|
16458
|
+
return maskVercelPulledEnvironment({ env: process.env, envFile: resolve(cwd, args[0]) }, io);
|
|
16459
|
+
}
|
|
15722
16460
|
case "verify-build-env": {
|
|
15723
16461
|
if (args.length < 2 || args.length > 3) {
|
|
15724
16462
|
io.err("Usage: loom db release verify-build-env <output-directory> <manifest-file> [deployment-root]");
|
|
@@ -16003,6 +16741,11 @@ export async function runCli(args = process.argv.slice(2), io = {
|
|
|
16003
16741
|
io.err(SECRETS_FINGERPRINT_ARGUMENT_REFUSAL);
|
|
16004
16742
|
return 1;
|
|
16005
16743
|
}
|
|
16744
|
+
if (secretsIndex >= 0 && args[secretsIndex + 1] === "push" &&
|
|
16745
|
+
!secretsPushArgumentsAreSafe(args.slice(secretsIndex + 2))) {
|
|
16746
|
+
io.err(SECRETS_PUSH_ARGUMENT_REFUSAL);
|
|
16747
|
+
return 1;
|
|
16748
|
+
}
|
|
16006
16749
|
const parsed = parseArgs({
|
|
16007
16750
|
allowPositionals: true,
|
|
16008
16751
|
args,
|
|
@@ -16032,6 +16775,8 @@ export async function runCli(args = process.argv.slice(2), io = {
|
|
|
16032
16775
|
"max-requests-per-key": { type: "string" },
|
|
16033
16776
|
"no-color": { type: "boolean" },
|
|
16034
16777
|
"no-progress": { type: "boolean" },
|
|
16778
|
+
"no-vercel": { type: "boolean" },
|
|
16779
|
+
vercel: { type: "boolean" },
|
|
16035
16780
|
"no-sync": { type: "boolean" },
|
|
16036
16781
|
network: { type: "boolean" },
|
|
16037
16782
|
"neon-auth": { type: "boolean" },
|
|
@@ -16138,7 +16883,11 @@ export async function runCli(args = process.argv.slice(2), io = {
|
|
|
16138
16883
|
resource: parsed.values.resource,
|
|
16139
16884
|
}, io);
|
|
16140
16885
|
case "secrets":
|
|
16141
|
-
return await runSecrets(cwd, arg1, arg2, {
|
|
16886
|
+
return await runSecrets(cwd, arg1, arg2, {
|
|
16887
|
+
environment: parsed.values.environment,
|
|
16888
|
+
noVercel: parsed.values["no-vercel"],
|
|
16889
|
+
vercel: parsed.values.vercel,
|
|
16890
|
+
}, io, options.secretsTerminal, options.commandRunner);
|
|
16142
16891
|
case "skills":
|
|
16143
16892
|
return await runSkills(cwd, arg1, [arg2, ...rest].filter(Boolean), io, {
|
|
16144
16893
|
acceptUnknownLicense: parsed.values["accept-unknown-license"],
|