@nodetool-ai/cli 0.8.18 → 0.8.19
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 +9 -0
- package/dist/.nodetool-build-stamp +1 -1
- package/dist/lean/envCatalogue.d.ts +36 -0
- package/dist/lean/envCatalogue.d.ts.map +1 -0
- package/dist/lean/envCatalogue.js +102 -0
- package/dist/lean/envCatalogue.js.map +1 -0
- package/dist/lean/envCommands.d.ts +50 -0
- package/dist/lean/envCommands.d.ts.map +1 -0
- package/dist/lean/envCommands.js +171 -0
- package/dist/lean/envCommands.js.map +1 -0
- package/dist/lean/envFiles.d.ts +58 -0
- package/dist/lean/envFiles.d.ts.map +1 -0
- package/dist/lean/envFiles.js +138 -0
- package/dist/lean/envFiles.js.map +1 -0
- package/dist/lean/program.d.ts +19 -1
- package/dist/lean/program.d.ts.map +1 -1
- package/dist/lean/program.js +177 -15
- package/dist/lean/program.js.map +1 -1
- package/dist/lean/providerStatus.d.ts +9 -1
- package/dist/lean/providerStatus.d.ts.map +1 -1
- package/dist/lean/providerStatus.js +30 -4
- package/dist/lean/providerStatus.js.map +1 -1
- package/package.json +9 -9
package/README.md
CHANGED
|
@@ -32,6 +32,12 @@ nodetool run flow.json --params '{"topic":"rivers"}'
|
|
|
32
32
|
store when `SECRETS_MASTER_KEY` is set and the key is stored, and from the
|
|
33
33
|
environment otherwise.
|
|
34
34
|
|
|
35
|
+
At startup the CLI loads `./.env.local`, `./.env`, `~/.nodetool/.env` and
|
|
36
|
+
`~/.env`, after any file named by `--env-file` or `NODETOOL_ENV_FILE`. Real
|
|
37
|
+
environment variables win. `nodetool env check --json` lists every variable
|
|
38
|
+
with its status and source, never its value. See
|
|
39
|
+
[Environment and Env Files](../../docs/cli.md#environment-and-env-files).
|
|
40
|
+
|
|
35
41
|
No single provider is required. `nodetool info` shows the credential state of
|
|
36
42
|
each provider (names only, never values), and `nodetool providers list` lists
|
|
37
43
|
the providers usable now: a key is set, an installed pack registers it, or, for
|
|
@@ -85,6 +91,9 @@ nodetool models list --provider openai
|
|
|
85
91
|
nodetool text 'Hello' --model <model-id>
|
|
86
92
|
```
|
|
87
93
|
|
|
94
|
+
`assets download` keeps an existing destination file unless you pass `--force`.
|
|
95
|
+
`workflows list --limit` accepts a whole number from 1 to 500.
|
|
96
|
+
|
|
88
97
|
Secret values are read from stdin and encrypted for the authenticated user.
|
|
89
98
|
Without a token, `secrets list` and `secrets set` use the local store instead. `OPENAI_BASE_URL` selects a public HTTPS OpenAI-compatible endpoint.
|
|
90
99
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
2026-11-
|
|
1
|
+
2026-11-28T10:16:58.696Z
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export type EnvGroup = "secrets" | "local" | "server" | "provider";
|
|
2
|
+
export interface EnvVariable {
|
|
3
|
+
readonly name: string;
|
|
4
|
+
readonly group: EnvGroup;
|
|
5
|
+
readonly description: string;
|
|
6
|
+
/** Commands or providers that read the variable. */
|
|
7
|
+
readonly usedBy: readonly string[];
|
|
8
|
+
/** A credential: its value is never printed, and `env import` moves it into the secret store. */
|
|
9
|
+
readonly secret: boolean;
|
|
10
|
+
}
|
|
11
|
+
/** Every variable the lean CLI and its keyed providers read. */
|
|
12
|
+
export declare const ENV_CATALOGUE: readonly EnvVariable[];
|
|
13
|
+
/** Credentials that belong in the encrypted secret store rather than a file. */
|
|
14
|
+
export declare function isStorableCredential(name: string): boolean;
|
|
15
|
+
/** What the local secret store holds for the current user, by name only. */
|
|
16
|
+
export interface SecretStoreState {
|
|
17
|
+
readonly path: string;
|
|
18
|
+
readonly exists: boolean;
|
|
19
|
+
/** Every stored name. */
|
|
20
|
+
readonly names: ReadonlySet<string>;
|
|
21
|
+
/** Stored names that decrypt with the current SECRETS_MASTER_KEY. Empty without one. */
|
|
22
|
+
readonly readable: ReadonlySet<string>;
|
|
23
|
+
readonly masterKey: "set" | "missing" | "too short";
|
|
24
|
+
}
|
|
25
|
+
export type CredentialStatus = "set" | "locked" | "unreadable" | "unset";
|
|
26
|
+
/** `locked`: stored, but no master key to decrypt it. `unreadable`: stored under another master key. */
|
|
27
|
+
export declare function storedCredentialStatus(name: string, store: SecretStoreState): CredentialStatus;
|
|
28
|
+
/**
|
|
29
|
+
* A missing-credential error that names the variable, where it may live, and
|
|
30
|
+
* the command that sets it. It tells a store with no master key apart from a
|
|
31
|
+
* value stored under another key and from a value that is nowhere.
|
|
32
|
+
*/
|
|
33
|
+
export declare function missingCredentialMessage(name: string, store: SecretStoreState): string;
|
|
34
|
+
/** The commented template `nodetool env init` writes. Every value is left empty. */
|
|
35
|
+
export declare function envTemplate(): string;
|
|
36
|
+
//# sourceMappingURL=envCatalogue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"envCatalogue.d.ts","sourceRoot":"","sources":["../../src/lean/envCatalogue.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,QAAQ,GAAG,SAAS,GAAG,OAAO,GAAG,QAAQ,GAAG,UAAU,CAAC;AAEnE,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC;IACzB,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,oDAAoD;IACpD,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;IACnC,iGAAiG;IACjG,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;CAC1B;AAyCD,gEAAgE;AAChE,eAAO,MAAM,aAAa,EAAE,SAAS,WAAW,EAAgD,CAAC;AAEjG,gFAAgF;AAChF,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAG1D;AAED,4EAA4E;AAC5E,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,yBAAyB;IACzB,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IACpC,wFAAwF;IACxF,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IACvC,QAAQ,CAAC,SAAS,EAAE,KAAK,GAAG,SAAS,GAAG,WAAW,CAAC;CACrD;AAED,MAAM,MAAM,gBAAgB,GAAG,KAAK,GAAG,QAAQ,GAAG,YAAY,GAAG,OAAO,CAAC;AAEzE,wGAAwG;AACxG,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,gBAAgB,GAAG,gBAAgB,CAI9F;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,gBAAgB,GAAG,MAAM,CAUtF;AAED,oFAAoF;AACpF,wBAAgB,WAAW,IAAI,MAAM,CA2BpC"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { KEYED_PROVIDERS } from "./providerStatus.js";
|
|
2
|
+
/** Variables the lean CLI itself reads. Provider credentials follow from the provider table. */
|
|
3
|
+
const CORE_VARIABLES = [
|
|
4
|
+
{ name: "SECRETS_MASTER_KEY", group: "secrets", secret: true, usedBy: ["secrets set", "env import", "serve", "every run that reads a stored secret"],
|
|
5
|
+
description: "Encrypts the local secret store, at least 32 characters (`openssl rand -base64 32`). Without it, command features read the key from the system keychain, which a headless machine lacks. Keep it: secrets stored with one key cannot be read with another." },
|
|
6
|
+
{ name: "NODETOOL_ENV_FILE", group: "local", secret: false, usedBy: ["every command"], description: "An extra env file, loaded before ./.env.local, ./.env, ~/.nodetool/.env and ~/.env." },
|
|
7
|
+
{ name: "NODETOOL_USER_ID", group: "local", secret: false, usedBy: ["secrets", "run", "serve"], description: "Local user whose secrets are read and written. Default \"1\", shared with the desktop app." },
|
|
8
|
+
{ name: "DB_PATH", group: "local", secret: false, usedBy: ["secrets", "run", "info"], description: "SQLite database that holds the local secret store. Default nodetool.sqlite3 in the NodeTool data directory." },
|
|
9
|
+
{ name: "DATABASE_URL", group: "local", secret: true, usedBy: ["secrets", "run"], description: "Database connection string, used instead of DB_PATH when set." },
|
|
10
|
+
{ name: "NODETOOL_TEXT_MODEL", group: "local", secret: false, usedBy: ["text", "nodes --example"], description: "Default model for `nodetool text`." },
|
|
11
|
+
{ name: "OPENAI_BASE_URL", group: "local", secret: false, usedBy: ["text", "run", "serve"], description: "An OpenAI-compatible endpoint on a public HTTPS host for `nodetool text` and the built-in OpenAI nodes. Loopback, private and .local hosts are refused." },
|
|
12
|
+
{ name: "NODETOOL_LOG_LEVEL", group: "local", secret: false, usedBy: ["every command"], description: "Set to debug to log which env files were loaded (names only, never values)." },
|
|
13
|
+
{ name: "NODETOOL_API_URL", group: "server", secret: false, usedBy: ["workflows", "jobs", "assets", "secrets (with a token)"], description: "Server URL for server commands. Default http://127.0.0.1:7777." },
|
|
14
|
+
{ name: "NODETOOL_API_TOKEN", group: "server", secret: true, usedBy: ["workflows", "jobs", "assets", "secrets (with a token)", "serve"], description: "Bearer token for server commands, and the token `nodetool serve` accepts." },
|
|
15
|
+
{ name: "NODETOOL_TOKENS", group: "server", secret: true, usedBy: ["serve"], description: "JSON object mapping bearer tokens to user IDs, for a server with several users." },
|
|
16
|
+
{ name: "NODETOOL_DATA_DIR", group: "server", secret: false, usedBy: ["serve"], description: "Data directory of `nodetool serve`. Default ./nodetool-data." },
|
|
17
|
+
{ name: "NODETOOL_FEATURES", group: "server", secret: false, usedBy: ["serve"], description: "Pack features `nodetool serve` loads, as feature-id=package,..." },
|
|
18
|
+
{ name: "HOST", group: "server", secret: false, usedBy: ["serve"], description: "Listen address of `nodetool serve`. Default 127.0.0.1." },
|
|
19
|
+
{ name: "PORT", group: "server", secret: false, usedBy: ["serve"], description: "Listen port of `nodetool serve`. Default 7777." }
|
|
20
|
+
];
|
|
21
|
+
/** Credential names that hold an address or project id rather than a secret. */
|
|
22
|
+
const NON_SECRET_CREDENTIALS = new Set(["AZURE_OPENAI_ENDPOINT", "GOOGLE_CLOUD_PROJECT", "LLAMA_CPP_URL", "VLLM_BASE_URL"]);
|
|
23
|
+
function providerVariables() {
|
|
24
|
+
const byName = new Map();
|
|
25
|
+
for (const provider of KEYED_PROVIDERS) {
|
|
26
|
+
for (const credential of provider.credentials) {
|
|
27
|
+
const entry = byName.get(credential) ?? { providers: [], names: [] };
|
|
28
|
+
entry.providers.push(`provider ${provider.id}`);
|
|
29
|
+
entry.names.push(provider.name);
|
|
30
|
+
byName.set(credential, entry);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return [...byName].map(([name, entry]) => ({
|
|
34
|
+
name, group: "provider", secret: !NON_SECRET_CREDENTIALS.has(name), usedBy: entry.providers,
|
|
35
|
+
description: `${entry.names.join(", ")} credential.`
|
|
36
|
+
}));
|
|
37
|
+
}
|
|
38
|
+
/** Every variable the lean CLI and its keyed providers read. */
|
|
39
|
+
export const ENV_CATALOGUE = [...CORE_VARIABLES, ...providerVariables()];
|
|
40
|
+
/** Credentials that belong in the encrypted secret store rather than a file. */
|
|
41
|
+
export function isStorableCredential(name) {
|
|
42
|
+
const variable = ENV_CATALOGUE.find(entry => entry.name === name);
|
|
43
|
+
return variable?.group === "provider" && variable.secret;
|
|
44
|
+
}
|
|
45
|
+
/** `locked`: stored, but no master key to decrypt it. `unreadable`: stored under another master key. */
|
|
46
|
+
export function storedCredentialStatus(name, store) {
|
|
47
|
+
if (store.readable.has(name)) {
|
|
48
|
+
return "set";
|
|
49
|
+
}
|
|
50
|
+
if (!store.names.has(name)) {
|
|
51
|
+
return "unset";
|
|
52
|
+
}
|
|
53
|
+
return store.masterKey === "set" ? "unreadable" : "locked";
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* A missing-credential error that names the variable, where it may live, and
|
|
57
|
+
* the command that sets it. It tells a store with no master key apart from a
|
|
58
|
+
* value stored under another key and from a value that is nowhere.
|
|
59
|
+
*/
|
|
60
|
+
export function missingCredentialMessage(name, store) {
|
|
61
|
+
const status = storedCredentialStatus(name, store);
|
|
62
|
+
const check = "Run `nodetool env check` to see every variable and where it comes from.";
|
|
63
|
+
if (status === "locked") {
|
|
64
|
+
return `${name} is in the local secret store (${store.path}), but SECRETS_MASTER_KEY is ${store.masterKey === "too short" ? "shorter than 32 characters" : "not set"}, so it cannot be decrypted. Set SECRETS_MASTER_KEY in the environment or in ~/.nodetool/.env (the key it was stored with). ${check}`;
|
|
65
|
+
}
|
|
66
|
+
if (status === "unreadable") {
|
|
67
|
+
return `${name} is in the local secret store (${store.path}), but it does not decrypt with the current SECRETS_MASTER_KEY: it was stored under another key. Restore that key, or store the value again with \`printf %s "$VALUE" | nodetool secrets set ${name}\`. ${check}`;
|
|
68
|
+
}
|
|
69
|
+
return `${name} is not set: it is not in the environment, not in a loaded env file (./.env.local, ./.env, ~/.nodetool/.env, ~/.env), and not in the local secret store. Store it with \`printf %s "$VALUE" | nodetool secrets set ${name}\` (needs SECRETS_MASTER_KEY), or add ${name}=... to ./.env or ~/.nodetool/.env. ${check}`;
|
|
70
|
+
}
|
|
71
|
+
/** The commented template `nodetool env init` writes. Every value is left empty. */
|
|
72
|
+
export function envTemplate() {
|
|
73
|
+
const lines = [
|
|
74
|
+
"# NodeTool CLI environment.",
|
|
75
|
+
"# Copy this file to .env (project) or ~/.nodetool/.env (every project) and fill in",
|
|
76
|
+
"# only what you use. Keep the copy private: chmod 600, and never commit it.",
|
|
77
|
+
"#",
|
|
78
|
+
"# Load order, highest first: real environment variables, --env-file,",
|
|
79
|
+
"# NODETOOL_ENV_FILE, ./.env.local, ./.env, ~/.nodetool/.env, ~/.env.",
|
|
80
|
+
"# `nodetool env check` shows each variable's source. `nodetool env import .env`",
|
|
81
|
+
"# moves provider keys into the encrypted secret store.",
|
|
82
|
+
""
|
|
83
|
+
];
|
|
84
|
+
const headings = {
|
|
85
|
+
secrets: "Secret store",
|
|
86
|
+
local: "Local commands",
|
|
87
|
+
server: "Server commands and `nodetool serve`",
|
|
88
|
+
provider: "Provider credentials (only what you use)"
|
|
89
|
+
};
|
|
90
|
+
for (const group of ["secrets", "local", "server", "provider"]) {
|
|
91
|
+
lines.push(`# ── ${headings[group]} ──`);
|
|
92
|
+
for (const variable of ENV_CATALOGUE.filter(entry => entry.group === group)) {
|
|
93
|
+
if (group !== "provider") {
|
|
94
|
+
lines.push(`# ${variable.description}`);
|
|
95
|
+
}
|
|
96
|
+
lines.push(`# ${variable.name}=${group === "provider" ? ` # ${variable.description.replace(/\.$/, "")}` : ""}`);
|
|
97
|
+
}
|
|
98
|
+
lines.push("");
|
|
99
|
+
}
|
|
100
|
+
return lines.join("\n");
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=envCatalogue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"envCatalogue.js","sourceRoot":"","sources":["../../src/lean/envCatalogue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AActD,gGAAgG;AAChG,MAAM,cAAc,GAA2B;IAC7C,EAAE,IAAI,EAAE,oBAAoB,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,aAAa,EAAE,YAAY,EAAE,OAAO,EAAE,sCAAsC,CAAC;QAClJ,WAAW,EAAE,4PAA4P,EAAE;IAC7Q,EAAE,IAAI,EAAE,mBAAmB,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,eAAe,CAAC,EAAE,WAAW,EAAE,qFAAqF,EAAE;IAC3L,EAAE,IAAI,EAAE,kBAAkB,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,SAAS,EAAE,KAAK,EAAE,OAAO,CAAC,EAAE,WAAW,EAAE,4FAA4F,EAAE;IAC3M,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,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,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,KAAK,KAAK,CAAC,EAAE,CAAC;YAC5E,IAAI,KAAK,KAAK,UAAU,EAAE,CAAC;gBAAC,KAAK,CAAC,IAAI,CAAC,KAAK,QAAQ,CAAC,WAAW,EAAE,CAAC,CAAC;YAAC,CAAC;YACtE,KAAK,CAAC,IAAI,CAAC,KAAK,QAAQ,CAAC,IAAI,IAAI,KAAK,KAAK,UAAU,CAAC,CAAC,CAAC,SAAS,QAAQ,CAAC,WAAW,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QACrH,CAAC;QACD,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACjB,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { Command } from "commander";
|
|
2
|
+
import { type CredentialStatus, type EnvGroup, type SecretStoreState } from "./envCatalogue.js";
|
|
3
|
+
import { type EnvLoadResult } from "./envFiles.js";
|
|
4
|
+
export interface EnvCommandDeps {
|
|
5
|
+
readonly env: NodeJS.ProcessEnv;
|
|
6
|
+
/** Files applied at startup. Without it every set variable counts as coming from the process environment. */
|
|
7
|
+
envLoad?: EnvLoadResult;
|
|
8
|
+
readonly cwd: string;
|
|
9
|
+
readonly print: (value: unknown) => void;
|
|
10
|
+
readonly output: (value: string) => void;
|
|
11
|
+
readonly secretStoreState: () => Promise<SecretStoreState>;
|
|
12
|
+
/** Encrypt and store each pair in the local secret store. Throws without SECRETS_MASTER_KEY. */
|
|
13
|
+
readonly storeSecrets: (pairs: readonly (readonly [string, string])[]) => Promise<void>;
|
|
14
|
+
}
|
|
15
|
+
export type VariableSource = "env" | "file" | "secret store" | null;
|
|
16
|
+
export interface VariableReport {
|
|
17
|
+
readonly name: string;
|
|
18
|
+
readonly group: EnvGroup;
|
|
19
|
+
readonly secret: boolean;
|
|
20
|
+
readonly status: CredentialStatus;
|
|
21
|
+
readonly source: VariableSource;
|
|
22
|
+
/** The env file that set it, when `source` is "file". */
|
|
23
|
+
readonly file?: string;
|
|
24
|
+
readonly used_by: readonly string[];
|
|
25
|
+
}
|
|
26
|
+
export interface EnvCheckReport {
|
|
27
|
+
readonly files: readonly {
|
|
28
|
+
readonly path: string;
|
|
29
|
+
readonly scope: string;
|
|
30
|
+
readonly exists: boolean;
|
|
31
|
+
readonly applied: readonly string[];
|
|
32
|
+
readonly shadowed: readonly string[];
|
|
33
|
+
readonly git_tracked: boolean;
|
|
34
|
+
readonly warnings: readonly string[];
|
|
35
|
+
}[];
|
|
36
|
+
readonly secret_store: {
|
|
37
|
+
readonly path: string;
|
|
38
|
+
readonly exists: boolean;
|
|
39
|
+
readonly master_key: SecretStoreState["masterKey"];
|
|
40
|
+
readonly master_key_source: VariableSource;
|
|
41
|
+
readonly stored: readonly string[];
|
|
42
|
+
};
|
|
43
|
+
readonly variables: readonly VariableReport[];
|
|
44
|
+
readonly warnings: readonly string[];
|
|
45
|
+
}
|
|
46
|
+
/** Build the `env check` report. Reads names, paths and file modes, never values. */
|
|
47
|
+
export declare function envCheckReport(deps: Pick<EnvCommandDeps, "env" | "envLoad" | "secretStoreState">): Promise<EnvCheckReport>;
|
|
48
|
+
/** Register `nodetool env check|list|init|import`. */
|
|
49
|
+
export declare function registerEnvCommands(program: Command, deps: EnvCommandDeps): void;
|
|
50
|
+
//# sourceMappingURL=envCommands.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"envCommands.d.ts","sourceRoot":"","sources":["../../src/lean/envCommands.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,EAA4E,KAAK,gBAAgB,EAAE,KAAK,QAAQ,EAAE,KAAK,gBAAgB,EAAE,MAAM,mBAAmB,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Q,CAAC,MAAM,EAAE,OAAO,CAAC;QACxE,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;QAAC,QAAQ,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;QAC1E,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC;QAAC,QAAQ,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;KACrE,EAAE,CAAC;IACJ,QAAQ,CAAC,YAAY,EAAE;QAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;QAAC,QAAQ,CAAC,UAAU,EAAE,gBAAgB,CAAC,WAAW,CAAC,CAAC;QAAC,QAAQ,CAAC,iBAAiB,EAAE,cAAc,CAAC;QAAC,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAA;KAAE,CAAC;IAC/M,QAAQ,CAAC,SAAS,EAAE,SAAS,cAAc,EAAE,CAAC;IAC9C,QAAQ,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;CACtC;AAED,qFAAqF;AACrF,wBAAsB,cAAc,CAAC,IAAI,EAAE,IAAI,CAAC,cAAc,EAAE,KAAK,GAAG,SAAS,GAAG,kBAAkB,CAAC,GAAG,OAAO,CAAC,cAAc,CAAC,CAuChI;AAQD,sDAAsD;AACtD,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,cAAc,GAAG,IAAI,CA2EhF"}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { chmod, readFile, stat, writeFile } from "node:fs/promises";
|
|
3
|
+
import { join, resolve } from "node:path";
|
|
4
|
+
import { parseEnvFile } from "@nodetool-ai/config";
|
|
5
|
+
import { ENV_CATALOGUE, envTemplate, isStorableCredential, storedCredentialStatus } from "./envCatalogue.js";
|
|
6
|
+
import { envFilePermissionWarnings, isGitTracked } from "./envFiles.js";
|
|
7
|
+
import { CREDENTIAL_ALIASES } from "./providerStatus.js";
|
|
8
|
+
/** Build the `env check` report. Reads names, paths and file modes, never values. */
|
|
9
|
+
export async function envCheckReport(deps) {
|
|
10
|
+
const { env, envLoad } = deps;
|
|
11
|
+
const store = await deps.secretStoreState();
|
|
12
|
+
const sources = envLoad?.sources ?? {};
|
|
13
|
+
const environmentSource = (name) => {
|
|
14
|
+
const present = [name, ...CREDENTIAL_ALIASES[name] ?? []].find(candidate => env[candidate]);
|
|
15
|
+
if (!present) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
const file = sources[present];
|
|
19
|
+
return file ? { source: "file", file } : { source: "env" };
|
|
20
|
+
};
|
|
21
|
+
const variables = ENV_CATALOGUE.map((variable) => {
|
|
22
|
+
const base = { name: variable.name, group: variable.group, secret: variable.secret, used_by: variable.usedBy };
|
|
23
|
+
const fromEnvironment = environmentSource(variable.name);
|
|
24
|
+
if (fromEnvironment) {
|
|
25
|
+
return { ...base, status: "set", ...fromEnvironment };
|
|
26
|
+
}
|
|
27
|
+
if (variable.group === "provider") {
|
|
28
|
+
const status = storedCredentialStatus(variable.name, store);
|
|
29
|
+
return { ...base, status, source: status === "unset" ? null : "secret store" };
|
|
30
|
+
}
|
|
31
|
+
return { ...base, status: "unset", source: null };
|
|
32
|
+
});
|
|
33
|
+
const files = (envLoad?.files ?? []).map(file => {
|
|
34
|
+
const gitTracked = file.exists && isGitTracked(file.path);
|
|
35
|
+
const warnings = [...file.warnings];
|
|
36
|
+
if (gitTracked) {
|
|
37
|
+
warnings.push(`${file.path} is tracked by git. Remove it with \`git rm --cached ${file.path}\` and add it to .gitignore.`);
|
|
38
|
+
}
|
|
39
|
+
return { path: file.path, scope: file.scope, exists: file.exists, applied: file.applied, shadowed: file.shadowed, git_tracked: gitTracked, warnings };
|
|
40
|
+
});
|
|
41
|
+
const warnings = files.flatMap(file => file.warnings);
|
|
42
|
+
if (store.masterKey !== "set" && [...store.names].length > 0) {
|
|
43
|
+
warnings.push(`The secret store holds ${store.names.size} secret(s), but SECRETS_MASTER_KEY is ${store.masterKey === "missing" ? "not set" : "shorter than 32 characters"}. Command features then need the system keychain to read them. On a headless machine, set SECRETS_MASTER_KEY in ~/.nodetool/.env.`);
|
|
44
|
+
}
|
|
45
|
+
const unreadable = variables.filter(variable => variable.status === "unreadable").map(variable => variable.name);
|
|
46
|
+
if (unreadable.length) {
|
|
47
|
+
warnings.push(`Stored under another SECRETS_MASTER_KEY, so no run can read them: ${unreadable.join(", ")}.`);
|
|
48
|
+
}
|
|
49
|
+
const masterKey = variables.find(variable => variable.name === "SECRETS_MASTER_KEY");
|
|
50
|
+
return {
|
|
51
|
+
files,
|
|
52
|
+
secret_store: { path: store.path, exists: store.exists, master_key: store.masterKey, master_key_source: masterKey?.source ?? null, stored: [...store.names].sort() },
|
|
53
|
+
variables,
|
|
54
|
+
warnings
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function gitignoreCoversEnv(directory) {
|
|
58
|
+
const file = join(directory, ".gitignore");
|
|
59
|
+
if (!existsSync(file)) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
return readFileSync(file, "utf8").split(/\r?\n/).map(line => line.trim()).some(line => [".env", ".env*", "*.env", ".env.*", "/.env"].includes(line));
|
|
63
|
+
}
|
|
64
|
+
/** Register `nodetool env check|list|init|import`. */
|
|
65
|
+
export function registerEnvCommands(program, deps) {
|
|
66
|
+
const envCommand = program.command("env").description("Discover, check and set up the environment variables the CLI reads, and the env files it loads");
|
|
67
|
+
envCommand.command("check").description("List every known variable with its status and source (environment, env file or secret store). Never prints values.")
|
|
68
|
+
.option("--json", "Output JSON, for agents")
|
|
69
|
+
.option("--all", "Include provider credentials that are not set (text output; JSON always includes them)")
|
|
70
|
+
.action(async (flags) => {
|
|
71
|
+
const report = await envCheckReport(deps);
|
|
72
|
+
if (flags.json) {
|
|
73
|
+
deps.print(report);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const out = deps.output;
|
|
77
|
+
out("Env files (highest precedence first):\n");
|
|
78
|
+
for (const file of report.files) {
|
|
79
|
+
out(` ${file.exists ? "loaded " : "absent "} ${file.path}${file.exists ? ` (${file.applied.length} set${file.shadowed.length ? `, ${file.shadowed.length} already set elsewhere` : ""})` : ""}\n`);
|
|
80
|
+
}
|
|
81
|
+
out(`\nSecret store: ${report.secret_store.path}${report.secret_store.exists ? "" : " (not created yet)"}\n`);
|
|
82
|
+
out(` SECRETS_MASTER_KEY: ${report.secret_store.master_key}${report.secret_store.master_key_source ? ` (${report.secret_store.master_key_source})` : ""}\n`);
|
|
83
|
+
out("\nVariables:\n");
|
|
84
|
+
const shown = report.variables.filter(variable => flags.all || variable.group !== "provider" || variable.status !== "unset");
|
|
85
|
+
const width = Math.max(...shown.map(variable => variable.name.length));
|
|
86
|
+
for (const variable of shown) {
|
|
87
|
+
const where = variable.source === "file" ? `file ${variable.file ?? ""}` : variable.source ?? "";
|
|
88
|
+
out(` ${variable.name.padEnd(width)} ${variable.status.padEnd(10)} ${where}\n`);
|
|
89
|
+
}
|
|
90
|
+
const hidden = report.variables.length - shown.length;
|
|
91
|
+
if (hidden > 0) {
|
|
92
|
+
out(` (${hidden} provider credentials not set: \`nodetool env check --all\` lists them)\n`);
|
|
93
|
+
}
|
|
94
|
+
if (report.warnings.length) {
|
|
95
|
+
out("\nWarnings:\n");
|
|
96
|
+
for (const warning of report.warnings) {
|
|
97
|
+
out(` ${warning}\n`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
envCommand.command("list").description("List every variable the CLI reads, which commands read it, and whether it is a credential")
|
|
102
|
+
.option("--json", "Output JSON")
|
|
103
|
+
.action((flags) => {
|
|
104
|
+
const entries = ENV_CATALOGUE.map(variable => ({ name: variable.name, group: variable.group, secret: variable.secret, used_by: variable.usedBy, description: variable.description }));
|
|
105
|
+
if (flags.json) {
|
|
106
|
+
deps.print(entries);
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
for (const entry of entries) {
|
|
110
|
+
deps.output(`${entry.name} [${entry.group}${entry.secret ? ", secret" : ""}]\n ${entry.description}\n Used by: ${entry.used_by.join(", ")}\n`);
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
envCommand.command("init [file]").description("Write a commented template of every variable (default ./.env.example), with mode 600 and every value empty")
|
|
114
|
+
.option("--force", "Overwrite an existing file")
|
|
115
|
+
.action(async (file, flags) => {
|
|
116
|
+
const path = resolve(deps.cwd, file ?? ".env.example");
|
|
117
|
+
try {
|
|
118
|
+
await writeFile(path, envTemplate(), { mode: 0o600, flag: flags.force ? "w" : "wx" });
|
|
119
|
+
}
|
|
120
|
+
catch (error) {
|
|
121
|
+
if (error instanceof Error && "code" in error && error.code === "EEXIST") {
|
|
122
|
+
throw new Error(`${path} already exists. Pass --force to overwrite it.`);
|
|
123
|
+
}
|
|
124
|
+
throw error;
|
|
125
|
+
}
|
|
126
|
+
if (process.platform !== "win32") {
|
|
127
|
+
await chmod(path, 0o600);
|
|
128
|
+
}
|
|
129
|
+
deps.output(`Wrote ${path}.\nCopy it to .env or ~/.nodetool/.env and fill in only what you use. \`nodetool env check\` confirms what loaded.\n`);
|
|
130
|
+
if (!gitignoreCoversEnv(deps.cwd)) {
|
|
131
|
+
deps.output(`Add .env and .env.local to ${join(deps.cwd, ".gitignore")} so the filled-in copy is never committed.\n`);
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
envCommand.command("import [file]").description("Move provider credentials from an env file (default ./.env) into the encrypted local secret store. Needs SECRETS_MASTER_KEY.")
|
|
135
|
+
.option("--remove", "Delete the imported lines from the file afterwards")
|
|
136
|
+
.option("--json", "Output JSON")
|
|
137
|
+
.action(async (file, flags) => {
|
|
138
|
+
const path = resolve(deps.cwd, file ?? ".env");
|
|
139
|
+
if (!existsSync(path)) {
|
|
140
|
+
throw new Error(`Env file ${path} does not exist. Name another with \`nodetool env import <file>\`.`);
|
|
141
|
+
}
|
|
142
|
+
const pairs = Object.entries(parseEnvFile(await readFile(path, "utf8")));
|
|
143
|
+
const importable = pairs.filter(([name, value]) => value !== "" && isStorableCredential(name));
|
|
144
|
+
const skipped = pairs.filter(([name, value]) => !(value !== "" && isStorableCredential(name))).map(([name, value]) => ({
|
|
145
|
+
name, reason: value === "" ? "empty" : name === "SECRETS_MASTER_KEY" ? "the master key stays outside the store it encrypts" : "not a provider credential"
|
|
146
|
+
}));
|
|
147
|
+
if (importable.length) {
|
|
148
|
+
await deps.storeSecrets(importable);
|
|
149
|
+
}
|
|
150
|
+
const imported = importable.map(([name]) => name);
|
|
151
|
+
if (flags.remove && imported.length) {
|
|
152
|
+
const mode = (await stat(path)).mode & 0o777;
|
|
153
|
+
const kept = (await readFile(path, "utf8")).split(/(?<=\n)/).filter(line => !Object.keys(parseEnvFile(line)).some(name => imported.includes(name)));
|
|
154
|
+
await writeFile(path, kept.join(""), { mode });
|
|
155
|
+
}
|
|
156
|
+
const store = await deps.secretStoreState();
|
|
157
|
+
const result = { file: path, imported, skipped, secret_store: store.path, removed_from_file: Boolean(flags.remove && imported.length), warnings: envFilePermissionWarnings(path) };
|
|
158
|
+
if (flags.json) {
|
|
159
|
+
deps.print(result);
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
deps.output(`Imported ${imported.length} credential(s) into ${store.path}${imported.length ? `: ${imported.join(", ")}` : ""}.\n`);
|
|
163
|
+
if (imported.length && !flags.remove) {
|
|
164
|
+
deps.output(`They are still in ${path}. Delete those lines, or run again with --remove.\n`);
|
|
165
|
+
}
|
|
166
|
+
for (const warning of result.warnings) {
|
|
167
|
+
deps.output(`${warning}\n`);
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
//# sourceMappingURL=envCommands.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"envCommands.js","sourceRoot":"","sources":["../../src/lean/envCommands.ts"],"names":[],"mappings":"AAAA,OAA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EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;QACjD,CAAC;QACD,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,gBAAgB,EAAE,CAAC;QAC5C,MAAM,MAAM,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,YAAY,EAAE,KAAK,CAAC,IAAI,EAAE,iBAAiB,EAAE,OAAO,CAAC,KAAK,CAAC,MAAM,IAAI,QAAQ,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,yBAAyB,CAAC,IAAI,CAAC,EAAE,CAAC;QACnL,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC;YAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;YAAC,OAAO;QAAC,CAAC;QAC/C,IAAI,CAAC,MAAM,CAAC,YAAY,QAAQ,CAAC,MAAM,uBAAuB,KAAK,CAAC,IAAI,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;QACnI,IAAI,QAAQ,CAAC,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;YAAC,IAAI,CAAC,MAAM,CAAC,qBAAqB,IAAI,qDAAqD,CAAC,CAAC;QAAC,CAAC;QACtI,KAAK,MAAM,OAAO,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC;YAAC,IAAI,CAAC,MAAM,CAAC,GAAG,OAAO,IAAI,CAAC,CAAC;QAAC,CAAC;IACzE,CAAC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/** Where an env file sits in the search order. */
|
|
2
|
+
export type EnvFileScope = "flag" | "NODETOOL_ENV_FILE" | "project" | "home";
|
|
3
|
+
export interface EnvFileCandidate {
|
|
4
|
+
readonly path: string;
|
|
5
|
+
readonly scope: EnvFileScope;
|
|
6
|
+
}
|
|
7
|
+
export interface EnvFileReport extends EnvFileCandidate {
|
|
8
|
+
readonly exists: boolean;
|
|
9
|
+
/** Names this file set: absent from the environment and from every earlier file. */
|
|
10
|
+
readonly applied: readonly string[];
|
|
11
|
+
/** Names in the file that an earlier source already set. */
|
|
12
|
+
readonly shadowed: readonly string[];
|
|
13
|
+
readonly warnings: readonly string[];
|
|
14
|
+
}
|
|
15
|
+
export interface EnvLoadResult {
|
|
16
|
+
readonly files: readonly EnvFileReport[];
|
|
17
|
+
/** Variable name to the env file that supplied it. Names missing here came from the process environment. */
|
|
18
|
+
readonly sources: Readonly<Record<string, string>>;
|
|
19
|
+
}
|
|
20
|
+
export interface EnvLoadOptions {
|
|
21
|
+
/** Mutated in place: values from env files are added to it. */
|
|
22
|
+
readonly env: NodeJS.ProcessEnv;
|
|
23
|
+
readonly cwd?: string;
|
|
24
|
+
readonly home?: string;
|
|
25
|
+
/** Value of `--env-file`. */
|
|
26
|
+
readonly envFile?: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Env files in precedence order, highest first: `--env-file`, then
|
|
30
|
+
* NODETOOL_ENV_FILE, then `./.env.local` and `./.env` in the working
|
|
31
|
+
* directory, then `~/.nodetool/.env` and `~/.env`. A path reached twice (the
|
|
32
|
+
* working directory is the home directory) is listed once.
|
|
33
|
+
*/
|
|
34
|
+
export declare function envFileCandidates(options: Omit<EnvLoadOptions, "env"> & {
|
|
35
|
+
readonly env: NodeJS.ProcessEnv;
|
|
36
|
+
}): EnvFileCandidate[];
|
|
37
|
+
/** Permission warnings for one env file. Windows has no POSIX mode bits to check. */
|
|
38
|
+
export declare function envFilePermissionWarnings(path: string): string[];
|
|
39
|
+
/** True when git tracks the file. False when git is missing or the file is outside a repository. */
|
|
40
|
+
export declare function isGitTracked(path: string): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Apply env files to `options.env`. A variable already set in the environment
|
|
43
|
+
* always wins, and among files the first in the search order wins. Values are
|
|
44
|
+
* never logged or returned: only names and paths. A file named by
|
|
45
|
+
* `--env-file` or NODETOOL_ENV_FILE must exist.
|
|
46
|
+
*/
|
|
47
|
+
export declare function loadCliEnvironment(options: EnvLoadOptions): EnvLoadResult;
|
|
48
|
+
/**
|
|
49
|
+
* Remove `--env-file <path>` and `--env-file=<path>` from argv, before any
|
|
50
|
+
* `--`, so command features never see the flag.
|
|
51
|
+
*/
|
|
52
|
+
export declare function extractEnvFileFlag(argv: readonly string[]): {
|
|
53
|
+
argv: string[];
|
|
54
|
+
envFile?: string;
|
|
55
|
+
};
|
|
56
|
+
/** One line per loaded file, names only. */
|
|
57
|
+
export declare function describeEnvLoad(result: EnvLoadResult): string[];
|
|
58
|
+
//# sourceMappingURL=envFiles.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"envFiles.d.ts","sourceRoot":"","sources":["../../src/lean/envFiles.ts"],"names":[],"mappings":"AAMA,kDAAkD;AAClD,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,mBAAmB,GAAG,SAAS,GAAG,MAAM,CAAC;AAE7E,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAC;CAC9B;AAED,MAAM,WAAW,aAAc,SAAQ,gBAAgB;IACrD,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,oFAAoF;IACpF,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC,4DAA4D;IAC5D,QAAQ,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;IACrC,QAAQ,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;CACtC;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,KAAK,EAAE,SAAS,aAAa,EAAE,CAAC;IACzC,4GAA4G;IAC5G,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CACpD;AAED,MAAM,WAAW,cAAc;IAC7B,+DAA+D;IAC/D,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC,UAAU,CAAC;IAChC,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,6BAA6B;IAC7B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;CAC3B;AAID;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,IAAI,CAAC,cAAc,EAAE,KAAK,CAAC,GAAG;IAAE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC,UAAU,CAAA;CAAE,GAAG,gBAAgB,EAAE,CAmBhI;AAED,qFAAqF;AACrF,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAUhE;AAED,oGAAoG;AACpG,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAQlD;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,cAAc,GAAG,aAAa,CAyBzE;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,GAAG;IAAE,IAAI,EAAE,MAAM,EAAE,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,CAmBhG;AAED,4CAA4C;AAC5C,wBAAgB,eAAe,CAAC,MAAM,EAAE,aAAa,GAAG,MAAM,EAAE,CAE/D"}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { execFileSync } from "node:child_process";
|
|
2
|
+
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
import { basename, dirname, join, resolve } from "node:path";
|
|
5
|
+
import { parseEnvFile } from "@nodetool-ai/config";
|
|
6
|
+
const isSet = (value) => value !== undefined && value !== "";
|
|
7
|
+
/**
|
|
8
|
+
* Env files in precedence order, highest first: `--env-file`, then
|
|
9
|
+
* NODETOOL_ENV_FILE, then `./.env.local` and `./.env` in the working
|
|
10
|
+
* directory, then `~/.nodetool/.env` and `~/.env`. A path reached twice (the
|
|
11
|
+
* working directory is the home directory) is listed once.
|
|
12
|
+
*/
|
|
13
|
+
export function envFileCandidates(options) {
|
|
14
|
+
const cwd = options.cwd ?? process.cwd();
|
|
15
|
+
const home = options.home ?? (options.env.HOME || options.env.USERPROFILE || homedir());
|
|
16
|
+
const candidates = [];
|
|
17
|
+
if (isSet(options.envFile)) {
|
|
18
|
+
candidates.push({ path: resolve(cwd, options.envFile), scope: "flag" });
|
|
19
|
+
}
|
|
20
|
+
if (isSet(options.env.NODETOOL_ENV_FILE)) {
|
|
21
|
+
candidates.push({ path: resolve(cwd, options.env.NODETOOL_ENV_FILE), scope: "NODETOOL_ENV_FILE" });
|
|
22
|
+
}
|
|
23
|
+
candidates.push({ path: join(cwd, ".env.local"), scope: "project" }, { path: join(cwd, ".env"), scope: "project" }, { path: join(home, ".nodetool", ".env"), scope: "home" }, { path: join(home, ".env"), scope: "home" });
|
|
24
|
+
const seen = new Set();
|
|
25
|
+
return candidates.filter(candidate => {
|
|
26
|
+
const path = resolve(candidate.path);
|
|
27
|
+
if (seen.has(path)) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
seen.add(path);
|
|
31
|
+
return true;
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
/** Permission warnings for one env file. Windows has no POSIX mode bits to check. */
|
|
35
|
+
export function envFilePermissionWarnings(path) {
|
|
36
|
+
if (process.platform === "win32") {
|
|
37
|
+
return [];
|
|
38
|
+
}
|
|
39
|
+
try {
|
|
40
|
+
const mode = statSync(path).mode;
|
|
41
|
+
if (mode & 0o004) {
|
|
42
|
+
return [`${path} is readable by every user on this machine. Restrict it with \`chmod 600 ${path}\`.`];
|
|
43
|
+
}
|
|
44
|
+
if (mode & 0o040) {
|
|
45
|
+
return [`${path} is readable by its group. Restrict it with \`chmod 600 ${path}\`.`];
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
// The file vanished after it was read: nothing to warn about.
|
|
50
|
+
}
|
|
51
|
+
return [];
|
|
52
|
+
}
|
|
53
|
+
/** True when git tracks the file. False when git is missing or the file is outside a repository. */
|
|
54
|
+
export function isGitTracked(path) {
|
|
55
|
+
try {
|
|
56
|
+
execFileSync("git", ["ls-files", "--error-unmatch", "--", basename(path)], { cwd: dirname(path), stdio: "ignore", timeout: 5000 });
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
// Untracked, outside a repository, or no git executable.
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Apply env files to `options.env`. A variable already set in the environment
|
|
66
|
+
* always wins, and among files the first in the search order wins. Values are
|
|
67
|
+
* never logged or returned: only names and paths. A file named by
|
|
68
|
+
* `--env-file` or NODETOOL_ENV_FILE must exist.
|
|
69
|
+
*/
|
|
70
|
+
export function loadCliEnvironment(options) {
|
|
71
|
+
const { env } = options;
|
|
72
|
+
const files = [];
|
|
73
|
+
const sources = {};
|
|
74
|
+
for (const candidate of envFileCandidates(options)) {
|
|
75
|
+
if (!existsSync(candidate.path)) {
|
|
76
|
+
if (candidate.scope === "flag" || candidate.scope === "NODETOOL_ENV_FILE") {
|
|
77
|
+
throw new Error(`Env file ${candidate.path} does not exist. It was named by ${candidate.scope === "flag" ? "--env-file" : "NODETOOL_ENV_FILE"}.`);
|
|
78
|
+
}
|
|
79
|
+
files.push({ ...candidate, exists: false, applied: [], shadowed: [], warnings: [] });
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
const applied = [];
|
|
83
|
+
const shadowed = [];
|
|
84
|
+
for (const [name, value] of Object.entries(parseEnvFile(readFileSync(candidate.path, "utf8")))) {
|
|
85
|
+
// An empty assignment (`KEY=`) is a placeholder, not a value: it must not hide a lower file.
|
|
86
|
+
if (value === "") {
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
if (isSet(env[name])) {
|
|
90
|
+
shadowed.push(name);
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
env[name] = value;
|
|
94
|
+
sources[name] = candidate.path;
|
|
95
|
+
applied.push(name);
|
|
96
|
+
}
|
|
97
|
+
files.push({ ...candidate, exists: true, applied, shadowed, warnings: envFilePermissionWarnings(candidate.path) });
|
|
98
|
+
}
|
|
99
|
+
return { files, sources };
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Remove `--env-file <path>` and `--env-file=<path>` from argv, before any
|
|
103
|
+
* `--`, so command features never see the flag.
|
|
104
|
+
*/
|
|
105
|
+
export function extractEnvFileFlag(argv) {
|
|
106
|
+
const rest = [];
|
|
107
|
+
let envFile;
|
|
108
|
+
for (let index = 0; index < argv.length; index++) {
|
|
109
|
+
const argument = argv[index] ?? "";
|
|
110
|
+
if (argument === "--") {
|
|
111
|
+
rest.push(...argv.slice(index));
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
if (argument === "--env-file") {
|
|
115
|
+
const value = argv[index + 1];
|
|
116
|
+
if (value === undefined || value.startsWith("-")) {
|
|
117
|
+
throw new Error("--env-file needs a path, e.g. --env-file ./staging.env");
|
|
118
|
+
}
|
|
119
|
+
envFile = value;
|
|
120
|
+
index++;
|
|
121
|
+
}
|
|
122
|
+
else if (argument.startsWith("--env-file=")) {
|
|
123
|
+
envFile = argument.slice("--env-file=".length);
|
|
124
|
+
if (!envFile) {
|
|
125
|
+
throw new Error("--env-file needs a path, e.g. --env-file=./staging.env");
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
rest.push(argument);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return envFile === undefined ? { argv: rest } : { argv: rest, envFile };
|
|
133
|
+
}
|
|
134
|
+
/** One line per loaded file, names only. */
|
|
135
|
+
export function describeEnvLoad(result) {
|
|
136
|
+
return result.files.filter(file => file.exists).map(file => `Loaded ${file.applied.length} variable(s) from ${file.path}${file.applied.length ? `: ${file.applied.join(", ")}` : ""}`);
|
|
137
|
+
}
|
|
138
|
+
//# sourceMappingURL=envFiles.js.map
|