@shdwsdk/cli 0.0.0-stage → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin.d.ts +3 -0
- package/dist/bin.d.ts.map +1 -0
- package/dist/bin.js +11 -0
- package/dist/bin.js.map +1 -0
- package/dist/codegen.d.ts +21 -0
- package/dist/codegen.d.ts.map +1 -0
- package/dist/codegen.js +136 -0
- package/dist/codegen.js.map +1 -0
- package/dist/connectivity.d.ts +17 -0
- package/dist/connectivity.d.ts.map +1 -0
- package/dist/connectivity.js +103 -0
- package/dist/connectivity.js.map +1 -0
- package/dist/env.d.ts +36 -0
- package/dist/env.d.ts.map +1 -0
- package/dist/env.js +105 -0
- package/dist/env.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/wizard.d.ts +25 -0
- package/dist/wizard.d.ts.map +1 -0
- package/dist/wizard.js +193 -0
- package/dist/wizard.js.map +1 -0
- package/package.json +45 -4
- package/src/bin.ts +12 -0
- package/src/codegen.ts +167 -0
- package/src/connectivity.ts +131 -0
- package/src/env.ts +144 -0
- package/src/index.ts +31 -0
- package/src/wizard.ts +267 -0
- package/README.md +0 -3
package/src/env.ts
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
// ============================================================================
|
|
2
|
+
// @shdwsdk/cli — Safe Environment File Injection (.env / .env.local)
|
|
3
|
+
// Updates or appends SHDW_API_KEY and SHDW_GRID_REGION without overwriting
|
|
4
|
+
// unrelated environment variables or existing comments.
|
|
5
|
+
// ============================================================================
|
|
6
|
+
|
|
7
|
+
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
8
|
+
import { resolve } from "node:path";
|
|
9
|
+
|
|
10
|
+
export interface EnvInjectionResult {
|
|
11
|
+
filePath: string;
|
|
12
|
+
fileName: string;
|
|
13
|
+
createdNew: boolean;
|
|
14
|
+
updatedKeys: string[];
|
|
15
|
+
appendedKeys: string[];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Resolves the target environment file in `cwd`.
|
|
20
|
+
* Prefers an existing `.env.local` or `.env`; if neither exists and a Next.js
|
|
21
|
+
* config is detected, defaults to `.env.local`, otherwise `.env`.
|
|
22
|
+
*/
|
|
23
|
+
export function resolveTargetEnvFile(cwd: string): {
|
|
24
|
+
filePath: string;
|
|
25
|
+
fileName: string;
|
|
26
|
+
exists: boolean;
|
|
27
|
+
} {
|
|
28
|
+
const envLocalPath = resolve(cwd, ".env.local");
|
|
29
|
+
if (existsSync(envLocalPath)) {
|
|
30
|
+
return { filePath: envLocalPath, fileName: ".env.local", exists: true };
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const envPath = resolve(cwd, ".env");
|
|
34
|
+
if (existsSync(envPath)) {
|
|
35
|
+
return { filePath: envPath, fileName: ".env", exists: true };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const isNextProject =
|
|
39
|
+
existsSync(resolve(cwd, "next.config.ts")) ||
|
|
40
|
+
existsSync(resolve(cwd, "next.config.mjs")) ||
|
|
41
|
+
existsSync(resolve(cwd, "next.config.js"));
|
|
42
|
+
|
|
43
|
+
const fileName = isNextProject ? ".env.local" : ".env";
|
|
44
|
+
return {
|
|
45
|
+
filePath: resolve(cwd, fileName),
|
|
46
|
+
fileName,
|
|
47
|
+
exists: false,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function formatEnvValue(val: string): string {
|
|
52
|
+
// Quote only if value contains spaces, hashes, or quotes
|
|
53
|
+
if (/[\s#"']/.test(val)) {
|
|
54
|
+
return `"${val.replace(/"/g, '\\"')}"`;
|
|
55
|
+
}
|
|
56
|
+
return val;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Upserts a set of key-value pairs into an `.env`-formatted string while
|
|
61
|
+
* preserving all unrelated variables, comments, and blank lines.
|
|
62
|
+
*/
|
|
63
|
+
export function upsertEnvContent(
|
|
64
|
+
existingContent: string,
|
|
65
|
+
entries: Readonly<Record<string, string>>
|
|
66
|
+
): {
|
|
67
|
+
content: string;
|
|
68
|
+
updatedKeys: string[];
|
|
69
|
+
appendedKeys: string[];
|
|
70
|
+
} {
|
|
71
|
+
const eol = existingContent.includes("\r\n") ? "\r\n" : "\n";
|
|
72
|
+
const lines = existingContent.length > 0 ? existingContent.split(/\r?\n/) : [];
|
|
73
|
+
const remaining = new Map<string, string>(Object.entries(entries));
|
|
74
|
+
const updatedKeys: string[] = [];
|
|
75
|
+
const appendedKeys: string[] = [];
|
|
76
|
+
|
|
77
|
+
const nextLines = lines.map((line) => {
|
|
78
|
+
const match = line.match(/^\s*(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*=/);
|
|
79
|
+
if (!match) {
|
|
80
|
+
return line;
|
|
81
|
+
}
|
|
82
|
+
const key = match[1];
|
|
83
|
+
if (!key || !remaining.has(key)) {
|
|
84
|
+
return line;
|
|
85
|
+
}
|
|
86
|
+
const nextValue = remaining.get(key) ?? "";
|
|
87
|
+
remaining.delete(key);
|
|
88
|
+
updatedKeys.push(key);
|
|
89
|
+
const hasExportPrefix = /^\s*export\s+/.test(line);
|
|
90
|
+
return `${hasExportPrefix ? "export " : ""}${key}=${formatEnvValue(nextValue)}`;
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
if (remaining.size > 0) {
|
|
94
|
+
// Trim trailing empty lines before appending a clean SHDWsdk block
|
|
95
|
+
while (
|
|
96
|
+
nextLines.length > 0 &&
|
|
97
|
+
nextLines[nextLines.length - 1]?.trim() === ""
|
|
98
|
+
) {
|
|
99
|
+
nextLines.pop();
|
|
100
|
+
}
|
|
101
|
+
if (nextLines.length > 0) {
|
|
102
|
+
nextLines.push("");
|
|
103
|
+
}
|
|
104
|
+
nextLines.push("# SHDWsdk Scope 3 AI Carbon & AI-BOM Telemetry");
|
|
105
|
+
for (const [key, val] of remaining.entries()) {
|
|
106
|
+
nextLines.push(`${key}=${formatEnvValue(val)}`);
|
|
107
|
+
appendedKeys.push(key);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return {
|
|
112
|
+
content: nextLines.join(eol) + eol,
|
|
113
|
+
updatedKeys,
|
|
114
|
+
appendedKeys,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Injects `SHDW_API_KEY` and `SHDW_GRID_REGION` into `.env` or `.env.local`
|
|
120
|
+
* in the target directory without disturbing unrelated variables.
|
|
121
|
+
*/
|
|
122
|
+
export function injectShdwEnvVariables(params: {
|
|
123
|
+
cwd: string;
|
|
124
|
+
apiKey: string;
|
|
125
|
+
gridRegion: string;
|
|
126
|
+
}): EnvInjectionResult {
|
|
127
|
+
const target = resolveTargetEnvFile(params.cwd);
|
|
128
|
+
const existing = target.exists ? readFileSync(target.filePath, "utf8") : "";
|
|
129
|
+
|
|
130
|
+
const { content, updatedKeys, appendedKeys } = upsertEnvContent(existing, {
|
|
131
|
+
SHDW_API_KEY: params.apiKey,
|
|
132
|
+
SHDW_GRID_REGION: params.gridRegion,
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
writeFileSync(target.filePath, content, "utf8");
|
|
136
|
+
|
|
137
|
+
return {
|
|
138
|
+
filePath: target.filePath,
|
|
139
|
+
fileName: target.fileName,
|
|
140
|
+
createdNew: !target.exists,
|
|
141
|
+
updatedKeys,
|
|
142
|
+
appendedKeys,
|
|
143
|
+
};
|
|
144
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// ============================================================================
|
|
2
|
+
// @shdwsdk/cli — Public Library Entrypoint
|
|
3
|
+
// ============================================================================
|
|
4
|
+
|
|
5
|
+
export {
|
|
6
|
+
buildBoilerplateSource,
|
|
7
|
+
generateShdwBoilerplateFile,
|
|
8
|
+
type GenerateBoilerplateParams,
|
|
9
|
+
type GeneratedBoilerplateResult,
|
|
10
|
+
} from "./codegen.js";
|
|
11
|
+
|
|
12
|
+
export {
|
|
13
|
+
DEFAULT_SHDW_INGEST_ENDPOINT,
|
|
14
|
+
testShdwConnectivity,
|
|
15
|
+
type ConnectivityTestResult,
|
|
16
|
+
} from "./connectivity.js";
|
|
17
|
+
|
|
18
|
+
export {
|
|
19
|
+
injectShdwEnvVariables,
|
|
20
|
+
resolveTargetEnvFile,
|
|
21
|
+
upsertEnvContent,
|
|
22
|
+
type EnvInjectionResult,
|
|
23
|
+
} from "./env.js";
|
|
24
|
+
|
|
25
|
+
export {
|
|
26
|
+
parseCliArgs,
|
|
27
|
+
runCliFromArgv,
|
|
28
|
+
runInitWizard,
|
|
29
|
+
type CliWizardOptions,
|
|
30
|
+
type CliWizardResult,
|
|
31
|
+
} from "./wizard.js";
|
package/src/wizard.ts
ADDED
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
// ============================================================================
|
|
2
|
+
// @shdwsdk/cli — Interactive Setup Wizard (npx @shdwsdk/sdk init / npx shdw-init)
|
|
3
|
+
// ============================================================================
|
|
4
|
+
|
|
5
|
+
import { stdin as defaultInput, stdout as defaultOutput } from "node:process";
|
|
6
|
+
import { createInterface } from "node:readline/promises";
|
|
7
|
+
import {
|
|
8
|
+
GRID_REGION_FACTORS,
|
|
9
|
+
MODEL_ENERGY_COEFFICIENTS,
|
|
10
|
+
resolveGridRegionFactor,
|
|
11
|
+
resolveModelCoefficient,
|
|
12
|
+
} from "@shdwsdk/sdk";
|
|
13
|
+
import { generateShdwBoilerplateFile } from "./codegen.js";
|
|
14
|
+
import {
|
|
15
|
+
DEFAULT_SHDW_INGEST_ENDPOINT,
|
|
16
|
+
testShdwConnectivity,
|
|
17
|
+
type ConnectivityTestResult,
|
|
18
|
+
} from "./connectivity.js";
|
|
19
|
+
import { injectShdwEnvVariables } from "./env.js";
|
|
20
|
+
|
|
21
|
+
export interface CliWizardOptions {
|
|
22
|
+
cwd?: string;
|
|
23
|
+
apiKey?: string;
|
|
24
|
+
region?: string;
|
|
25
|
+
model?: string;
|
|
26
|
+
outputPath?: string;
|
|
27
|
+
endpoint?: string;
|
|
28
|
+
skipPing?: boolean;
|
|
29
|
+
customFetch?: typeof fetch;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface CliWizardResult {
|
|
33
|
+
apiKeyPrefix: string;
|
|
34
|
+
gridRegion: string;
|
|
35
|
+
modelPattern: string;
|
|
36
|
+
envFilePath: string;
|
|
37
|
+
boilerplateFilePath: string;
|
|
38
|
+
connectivity: ConnectivityTestResult | null;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function parseCliArgs(argv: readonly string[]): CliWizardOptions & {
|
|
42
|
+
help?: boolean;
|
|
43
|
+
} {
|
|
44
|
+
const opts: CliWizardOptions & { help?: boolean } = {};
|
|
45
|
+
for (let i = 0; i < argv.length; i++) {
|
|
46
|
+
const arg = argv[i];
|
|
47
|
+
if (arg === "--help" || arg === "-h") {
|
|
48
|
+
opts.help = true;
|
|
49
|
+
} else if (arg === "--skip-ping") {
|
|
50
|
+
opts.skipPing = true;
|
|
51
|
+
} else if (arg === "--api-key" && argv[i + 1]) {
|
|
52
|
+
opts.apiKey = argv[++i];
|
|
53
|
+
} else if (arg === "--region" && argv[i + 1]) {
|
|
54
|
+
opts.region = argv[++i];
|
|
55
|
+
} else if (arg === "--model" && argv[i + 1]) {
|
|
56
|
+
opts.model = argv[++i];
|
|
57
|
+
} else if ((arg === "--out" || arg === "--output") && argv[i + 1]) {
|
|
58
|
+
opts.outputPath = argv[++i];
|
|
59
|
+
} else if (arg === "--endpoint" && argv[i + 1]) {
|
|
60
|
+
opts.endpoint = argv[++i];
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return opts;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function printHelp(): void {
|
|
67
|
+
defaultOutput.write(`
|
|
68
|
+
SHDWsdk (@shdwsdk/sdk) Interactive Setup Wizard
|
|
69
|
+
|
|
70
|
+
Usage:
|
|
71
|
+
npx @shdwsdk/sdk init
|
|
72
|
+
npx shdw-init
|
|
73
|
+
|
|
74
|
+
Options:
|
|
75
|
+
--api-key <key> SHDW API key (shdw_live_*)
|
|
76
|
+
--region <region> Primary cloud datacenter region (e.g., us-west-2, eu-north-1)
|
|
77
|
+
--model <pattern> Primary AI model pattern (e.g., claude-3-7-sonnet, gpt-4o, gemini-2.5-pro)
|
|
78
|
+
--out <path> Boilerplate output path (default: src/lib/shdw.ts)
|
|
79
|
+
--endpoint <url> Custom telemetry ingest URL (default: ${DEFAULT_SHDW_INGEST_ENDPOINT})
|
|
80
|
+
--skip-ping Skip the live connectivity validation ping
|
|
81
|
+
-h, --help Show this help message
|
|
82
|
+
`);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export async function runInitWizard(
|
|
86
|
+
options: CliWizardOptions = {}
|
|
87
|
+
): Promise<CliWizardResult> {
|
|
88
|
+
const cwd = options.cwd ?? process.cwd();
|
|
89
|
+
const regions = Object.values(GRID_REGION_FACTORS);
|
|
90
|
+
const models = [...MODEL_ENERGY_COEFFICIENTS];
|
|
91
|
+
|
|
92
|
+
const needsInteractive =
|
|
93
|
+
!options.apiKey || !options.region || !options.model || !options.outputPath;
|
|
94
|
+
|
|
95
|
+
const rl = needsInteractive
|
|
96
|
+
? createInterface({ input: defaultInput, output: defaultOutput })
|
|
97
|
+
: null;
|
|
98
|
+
|
|
99
|
+
try {
|
|
100
|
+
if (needsInteractive) {
|
|
101
|
+
defaultOutput.write(
|
|
102
|
+
"\n=== SHDWsdk (@shdwsdk/sdk) Setup Wizard — Scope 3 Carbon & AI-BOM ===\n\n"
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// 1. Prompt for SHDW API Key (shdw_live_*)
|
|
107
|
+
let apiKey = options.apiKey?.trim() ?? "";
|
|
108
|
+
while (!apiKey && rl) {
|
|
109
|
+
const answer = await rl.question(
|
|
110
|
+
"1. Enter your SHDW API key (shdw_live_*): "
|
|
111
|
+
);
|
|
112
|
+
const trimmed = answer.trim();
|
|
113
|
+
if (trimmed.length < 12) {
|
|
114
|
+
defaultOutput.write(
|
|
115
|
+
" Invalid API key. Please enter a valid key (at least 12 characters, e.g., shdw_live_...).\n"
|
|
116
|
+
);
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
if (!trimmed.startsWith("shdw_live_") && !trimmed.startsWith("shdw_test_")) {
|
|
120
|
+
defaultOutput.write(
|
|
121
|
+
" Note: Production keys typically start with 'shdw_live_'. Proceeding with provided key.\n"
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
apiKey = trimmed;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// 2. Select Primary Cloud Data Center Region
|
|
128
|
+
let selectedRegion = options.region?.trim() ?? "";
|
|
129
|
+
if (!selectedRegion && rl) {
|
|
130
|
+
defaultOutput.write(
|
|
131
|
+
"\n2. Select your primary cloud data center region:\n"
|
|
132
|
+
);
|
|
133
|
+
regions.forEach((r, idx) => {
|
|
134
|
+
defaultOutput.write(
|
|
135
|
+
` [${idx + 1}] ${r.region.padEnd(16)} — ${r.displayName} (${r.intensityGco2PerKwh} gCO2e/kWh)\n`
|
|
136
|
+
);
|
|
137
|
+
});
|
|
138
|
+
const defaultIdx = regions.findIndex((r) => r.region === "us-west-2") + 1;
|
|
139
|
+
const answer = await rl.question(
|
|
140
|
+
` Choose region number or code [default: ${defaultIdx} (us-west-2)]: `
|
|
141
|
+
);
|
|
142
|
+
const trimmed = answer.trim();
|
|
143
|
+
if (!trimmed) {
|
|
144
|
+
selectedRegion = "us-west-2";
|
|
145
|
+
} else {
|
|
146
|
+
const num = Number(trimmed);
|
|
147
|
+
if (Number.isInteger(num) && num >= 1 && num <= regions.length) {
|
|
148
|
+
selectedRegion = regions[num - 1]?.region ?? "us-west-2";
|
|
149
|
+
} else {
|
|
150
|
+
selectedRegion = resolveGridRegionFactor(trimmed).region;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
const resolvedRegion = resolveGridRegionFactor(
|
|
155
|
+
selectedRegion || "us-west-2"
|
|
156
|
+
);
|
|
157
|
+
|
|
158
|
+
// 3. Select Primary AI Model Pattern
|
|
159
|
+
let selectedModel = options.model?.trim() ?? "";
|
|
160
|
+
if (!selectedModel && rl) {
|
|
161
|
+
defaultOutput.write("\n3. Select your primary AI model in production:\n");
|
|
162
|
+
models.forEach((m, idx) => {
|
|
163
|
+
defaultOutput.write(
|
|
164
|
+
` [${idx + 1}] ${m.modelPattern.padEnd(22)} — ${m.displayName}\n`
|
|
165
|
+
);
|
|
166
|
+
});
|
|
167
|
+
const answer = await rl.question(
|
|
168
|
+
" Choose model number or pattern [default: 1 (claude-3-7-sonnet)]: "
|
|
169
|
+
);
|
|
170
|
+
const trimmed = answer.trim();
|
|
171
|
+
if (!trimmed) {
|
|
172
|
+
selectedModel = "claude-3-7-sonnet";
|
|
173
|
+
} else {
|
|
174
|
+
const num = Number(trimmed);
|
|
175
|
+
if (Number.isInteger(num) && num >= 1 && num <= models.length) {
|
|
176
|
+
selectedModel = models[num - 1]?.modelPattern ?? "claude-3-7-sonnet";
|
|
177
|
+
} else {
|
|
178
|
+
selectedModel = trimmed;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
const resolvedModel = resolveModelCoefficient(
|
|
183
|
+
selectedModel || "claude-3-7-sonnet"
|
|
184
|
+
);
|
|
185
|
+
const effectiveModelPattern =
|
|
186
|
+
resolvedModel.modelPattern === "default-frontier" && selectedModel
|
|
187
|
+
? selectedModel
|
|
188
|
+
: resolvedModel.modelPattern;
|
|
189
|
+
|
|
190
|
+
// 4. Output Path for Boilerplate File
|
|
191
|
+
let outputPath = options.outputPath?.trim() ?? "";
|
|
192
|
+
if (!outputPath && rl) {
|
|
193
|
+
const answer = await rl.question(
|
|
194
|
+
"\n4. Boilerplate integration file path [default: src/lib/shdw.ts]: "
|
|
195
|
+
);
|
|
196
|
+
outputPath = answer.trim() || "src/lib/shdw.ts";
|
|
197
|
+
}
|
|
198
|
+
if (!outputPath) {
|
|
199
|
+
outputPath = "src/lib/shdw.ts";
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// 5. Environment File Injection (.env / .env.local)
|
|
203
|
+
const envResult = injectShdwEnvVariables({
|
|
204
|
+
cwd,
|
|
205
|
+
apiKey,
|
|
206
|
+
gridRegion: resolvedRegion.region,
|
|
207
|
+
});
|
|
208
|
+
defaultOutput.write(
|
|
209
|
+
`\n[1/3] ${envResult.createdNew ? "Created" : "Updated"} ${envResult.fileName} (${envResult.filePath})\n`
|
|
210
|
+
);
|
|
211
|
+
|
|
212
|
+
// 6. Boilerplate Code Generation
|
|
213
|
+
const codeResult = generateShdwBoilerplateFile({
|
|
214
|
+
cwd,
|
|
215
|
+
outputPath,
|
|
216
|
+
modelPattern: effectiveModelPattern,
|
|
217
|
+
gridRegion: resolvedRegion.region,
|
|
218
|
+
});
|
|
219
|
+
defaultOutput.write(
|
|
220
|
+
`[2/3] Generated ${codeResult.providerLabel} integration at ${codeResult.relativePath}\n`
|
|
221
|
+
);
|
|
222
|
+
|
|
223
|
+
// 7. Live Connectivity Test (<= 1500ms AbortController timeout)
|
|
224
|
+
let connectivity: ConnectivityTestResult | null = null;
|
|
225
|
+
if (!options.skipPing) {
|
|
226
|
+
defaultOutput.write(
|
|
227
|
+
"[3/3] Testing live connectivity (1500ms timeout guard)...\n"
|
|
228
|
+
);
|
|
229
|
+
connectivity = await testShdwConnectivity({
|
|
230
|
+
apiKey,
|
|
231
|
+
modelPattern: effectiveModelPattern,
|
|
232
|
+
gridRegion: resolvedRegion.region,
|
|
233
|
+
endpoint: options.endpoint,
|
|
234
|
+
timeoutMs: 1500,
|
|
235
|
+
customFetch: options.customFetch,
|
|
236
|
+
});
|
|
237
|
+
defaultOutput.write(
|
|
238
|
+
` ${connectivity.ok ? "OK:" : "WARN:"} ${connectivity.message}\n`
|
|
239
|
+
);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
defaultOutput.write(
|
|
243
|
+
`\nSetup complete. Import your wrapped AI client from "./${codeResult.relativePath.replace(/\.ts$/, "")}" to begin tracking Scope 3 carbon & AI-BOM lineage.\n\n`
|
|
244
|
+
);
|
|
245
|
+
|
|
246
|
+
return {
|
|
247
|
+
apiKeyPrefix: apiKey.slice(0, 14),
|
|
248
|
+
gridRegion: resolvedRegion.region,
|
|
249
|
+
modelPattern: effectiveModelPattern,
|
|
250
|
+
envFilePath: envResult.filePath,
|
|
251
|
+
boilerplateFilePath: codeResult.filePath,
|
|
252
|
+
connectivity,
|
|
253
|
+
};
|
|
254
|
+
} finally {
|
|
255
|
+
rl?.close();
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
export async function runCliFromArgv(argv: readonly string[]): Promise<void> {
|
|
260
|
+
const cleaned = argv[0] === "init" ? argv.slice(1) : argv;
|
|
261
|
+
const parsed = parseCliArgs(cleaned);
|
|
262
|
+
if (parsed.help) {
|
|
263
|
+
printHelp();
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
await runInitWizard(parsed);
|
|
267
|
+
}
|
package/README.md
DELETED