@cairnvibe/indexer 0.2.0 → 0.2.1
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/concurrency.js +10 -12
- package/dist/l3-describe.js +3 -3
- package/dist/prompt.js +23 -0
- package/dist/setup.js +145 -48
- package/dist/ui.js +79 -0
- package/package.json +1 -1
package/dist/concurrency.js
CHANGED
|
@@ -25,17 +25,6 @@ async function mapWithConcurrency(items, limit, fn) {
|
|
|
25
25
|
await Promise.all(Array.from({ length: workerCount }, () => worker()));
|
|
26
26
|
return results;
|
|
27
27
|
}
|
|
28
|
-
/**
|
|
29
|
-
* Retries a rate-limited (429) or transient-server-error (5xx) call with
|
|
30
|
-
* backoff — found live and necessary, not theoretical: raising describeAll's
|
|
31
|
-
* concurrency (see DEFAULT_DESCRIBE_CONCURRENCY) surfaced a real 429 from
|
|
32
|
-
* Groq on a 40-page build within seconds ("Rate limit reached... tokens per
|
|
33
|
-
* minute"), which without this would have thrown straight out of
|
|
34
|
-
* mapWithConcurrency's Promise.all and aborted the *entire* build,
|
|
35
|
-
* discarding every other page's already-completed work too. Honors the
|
|
36
|
-
* provider's Retry-After header when present (both the Anthropic and Groq
|
|
37
|
-
* SDKs expose one on a 429), falls back to exponential backoff otherwise.
|
|
38
|
-
*/
|
|
39
28
|
async function withRetry(fn, opts) {
|
|
40
29
|
const maxAttempts = opts?.maxAttempts ?? 4;
|
|
41
30
|
const baseDelayMs = opts?.baseDelayMs ?? 1000;
|
|
@@ -49,7 +38,16 @@ async function withRetry(fn, opts) {
|
|
|
49
38
|
if (!isRetryable(err) || attempt === maxAttempts)
|
|
50
39
|
throw err;
|
|
51
40
|
const delayMs = retryAfterMs(err) ?? baseDelayMs * 2 ** (attempt - 1);
|
|
52
|
-
|
|
41
|
+
const message = errorMessage(err);
|
|
42
|
+
// Default behavior (plain `cairn build`, unchanged): log every attempt directly.
|
|
43
|
+
// A caller that wants something quieter/nicer (`cairn setup`'s spinner) passes
|
|
44
|
+
// its own onRetry instead of getting this raw per-attempt line.
|
|
45
|
+
if (opts?.onRetry) {
|
|
46
|
+
opts.onRetry({ attempt, maxAttempts, delayMs: Math.round(delayMs), message });
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
console.error(`[cairn] retryable error (attempt ${attempt}/${maxAttempts}), waiting ${Math.round(delayMs)}ms:`, message);
|
|
50
|
+
}
|
|
53
51
|
await new Promise((resolve) => setTimeout(resolve, delayMs));
|
|
54
52
|
}
|
|
55
53
|
}
|
package/dist/l3-describe.js
CHANGED
|
@@ -18,7 +18,7 @@ const GLOBAL_ROUTE_LABEL = "(present on every page — layout/framework elements
|
|
|
18
18
|
// rather than maximal: still bounded by whatever the provider's real rate
|
|
19
19
|
// limit is, this just stops leaving 3 of 4 rotated keys idle.
|
|
20
20
|
const DEFAULT_DESCRIBE_CONCURRENCY = 6;
|
|
21
|
-
async function describeAll(rootDir, facts, client, concurrency = DEFAULT_DESCRIBE_CONCURRENCY) {
|
|
21
|
+
async function describeAll(rootDir, facts, client, concurrency = DEFAULT_DESCRIBE_CONCURRENCY, onRetry) {
|
|
22
22
|
const absRoot = node_path_1.default.resolve(rootDir);
|
|
23
23
|
const cacheDir = node_path_1.default.join(absRoot, CACHE_DIR);
|
|
24
24
|
node_fs_1.default.mkdirSync(cacheDir, { recursive: true });
|
|
@@ -51,7 +51,7 @@ async function describeAll(rootDir, facts, client, concurrency = DEFAULT_DESCRIB
|
|
|
51
51
|
file: page.file,
|
|
52
52
|
source,
|
|
53
53
|
elements: page.elements.map(toDescribeElementInput),
|
|
54
|
-
}));
|
|
54
|
+
}), { onRetry });
|
|
55
55
|
}
|
|
56
56
|
catch (err) {
|
|
57
57
|
// One page permanently failing (retries exhausted, or a
|
|
@@ -94,7 +94,7 @@ async function describeAll(rootDir, facts, client, concurrency = DEFAULT_DESCRIB
|
|
|
94
94
|
file: files.join(", "),
|
|
95
95
|
source,
|
|
96
96
|
elements: facts.frameworkElements.map(toDescribeElementInput),
|
|
97
|
-
}));
|
|
97
|
+
}), { onRetry });
|
|
98
98
|
}
|
|
99
99
|
catch (err) {
|
|
100
100
|
console.error(`[cairn] describing framework elements failed after retries — degrading:`, err);
|
package/dist/prompt.js
CHANGED
|
@@ -12,6 +12,7 @@ exports.closePrompts = closePrompts;
|
|
|
12
12
|
exports.ask = ask;
|
|
13
13
|
exports.askYesNo = askYesNo;
|
|
14
14
|
exports.askOptional = askOptional;
|
|
15
|
+
exports.selectFromList = selectFromList;
|
|
15
16
|
const node_readline_1 = __importDefault(require("node:readline"));
|
|
16
17
|
let sharedInterface = null;
|
|
17
18
|
function rl() {
|
|
@@ -40,3 +41,25 @@ async function askOptional(question) {
|
|
|
40
41
|
const answer = await ask(question);
|
|
41
42
|
return answer.length > 0 ? answer : null;
|
|
42
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* A numbered menu instead of free text — the actual fix for "I had to
|
|
46
|
+
* type the exact provider name." Prints the choices, accepts a number,
|
|
47
|
+
* and (for anyone who prefers typing) also accepts the label/value text
|
|
48
|
+
* itself, case-insensitively. Empty answer takes `defaultIndex`.
|
|
49
|
+
*/
|
|
50
|
+
async function selectFromList(question, options, defaultIndex = 0) {
|
|
51
|
+
console.log(question);
|
|
52
|
+
options.forEach((o, i) => {
|
|
53
|
+
const marker = i === defaultIndex ? " (default)" : "";
|
|
54
|
+
console.log(` ${i + 1}. ${o.label}${marker}`);
|
|
55
|
+
});
|
|
56
|
+
const answer = await ask(`Choose [1-${options.length}]: `);
|
|
57
|
+
if (!answer)
|
|
58
|
+
return options[defaultIndex].value;
|
|
59
|
+
const asNumber = Number(answer);
|
|
60
|
+
if (Number.isInteger(asNumber) && asNumber >= 1 && asNumber <= options.length) {
|
|
61
|
+
return options[asNumber - 1].value;
|
|
62
|
+
}
|
|
63
|
+
const byText = options.find((o) => o.value.toLowerCase() === answer.toLowerCase() || o.label.toLowerCase().includes(answer.toLowerCase()));
|
|
64
|
+
return byText ? byText.value : options[defaultIndex].value;
|
|
65
|
+
}
|
package/dist/setup.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// `cairn setup` — the one-command onboarding path: install what's
|
|
3
|
-
// needed, ask only for what's actually optional (skippable
|
|
4
|
-
//
|
|
3
|
+
// needed, ask only for what's actually optional (skippable, and picked
|
|
4
|
+
// from a real numbered menu rather than typed free text), scaffold the
|
|
5
|
+
// backend, wire the widget into the real layout file, build the
|
|
5
6
|
// manifest once now, and leave a `prebuild` hook so it rebuilds itself
|
|
6
7
|
// on every future `npm run build` without another manual step.
|
|
7
8
|
//
|
|
@@ -9,8 +10,8 @@
|
|
|
9
10
|
// `init` stays the safe, deterministic, non-interactive primitive
|
|
10
11
|
// (never touches an existing file, never installs anything, never
|
|
11
12
|
// prompts); `setup` is the opinionated wizard built from those same
|
|
12
|
-
// primitives plus the
|
|
13
|
-
//
|
|
13
|
+
// primitives plus the things `init` intentionally doesn't do: install
|
|
14
|
+
// dependencies, edit an existing layout file, and actually build.
|
|
14
15
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
15
16
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
16
17
|
};
|
|
@@ -28,7 +29,14 @@ const l3_describe_1 = require("./l3-describe");
|
|
|
28
29
|
const llm_1 = require("./llm");
|
|
29
30
|
const manifest_1 = require("./manifest");
|
|
30
31
|
const core_1 = require("@cairnvibe/core");
|
|
32
|
+
const ui_1 = require("./ui");
|
|
31
33
|
const PACKAGES = ["@cairnvibe/core", "@cairnvibe/sdk", "@cairnvibe/indexer"];
|
|
34
|
+
// Lower than cairn build's own default (6) — a first-time setup is exactly
|
|
35
|
+
// the scenario most likely to be running on a free-tier key with a tight
|
|
36
|
+
// per-minute token budget; found live, not theoretical (a real `cairn
|
|
37
|
+
// setup` run against Groq's on-demand tier hit a 429-retry cascade at the
|
|
38
|
+
// default concurrency on a small handful of pages).
|
|
39
|
+
const SETUP_BUILD_CONCURRENCY = 3;
|
|
32
40
|
function readPackageJson(absDir) {
|
|
33
41
|
const p = node_path_1.default.join(absDir, "package.json");
|
|
34
42
|
if (!node_fs_1.default.existsSync(p))
|
|
@@ -46,13 +54,98 @@ function alreadyInstalled(pkg) {
|
|
|
46
54
|
const deps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
47
55
|
return PACKAGES.every((p) => !!deps[p]);
|
|
48
56
|
}
|
|
57
|
+
/** One build attempt — spinner-driven, quiet on individual retries (they
|
|
58
|
+
* update the same line instead of scrolling the terminal), and honest
|
|
59
|
+
* about failure instead of throwing a raw stack trace at the user. */
|
|
60
|
+
async function attemptBuild(dir, provider, key) {
|
|
61
|
+
if (provider === "anthropic")
|
|
62
|
+
process.env.ANTHROPIC_API_KEY = key;
|
|
63
|
+
if (provider === "groq")
|
|
64
|
+
process.env.GROQ_API_KEYS = key;
|
|
65
|
+
const spinner = new ui_1.Spinner(`Building the manifest (${provider}) ...`);
|
|
66
|
+
spinner.start();
|
|
67
|
+
try {
|
|
68
|
+
const client = provider === "anthropic" ? new llm_1.AnthropicDescribeClient() : new llm_1.GroqDescribeClient();
|
|
69
|
+
const facts = (0, l1_scan_1.scanL1)(dir);
|
|
70
|
+
const l2 = (0, l2_reachability_1.computeL2)(dir, facts);
|
|
71
|
+
const l3 = await (0, l3_describe_1.describeAll)(dir, facts, client, SETUP_BUILD_CONCURRENCY, (info) => {
|
|
72
|
+
spinner.update(`Building the manifest (${provider}) ... rate-limited, retrying in ${Math.round(info.delayMs / 1000)}s (attempt ${info.attempt}/${info.maxAttempts})`);
|
|
73
|
+
});
|
|
74
|
+
const manifest = core_1.ManifestSchema.parse((0, manifest_1.assembleManifest)(dir, facts, l2, l3));
|
|
75
|
+
node_fs_1.default.writeFileSync(node_path_1.default.join(node_path_1.default.resolve(dir), "ui-manifest.json"), JSON.stringify(manifest, null, 2) + "\n");
|
|
76
|
+
spinner.stop((0, ui_1.green)(`✓ wrote ui-manifest.json (${manifest.pages.length} page(s))`));
|
|
77
|
+
return { ok: true, pageCount: manifest.pages.length };
|
|
78
|
+
}
|
|
79
|
+
catch (err) {
|
|
80
|
+
spinner.stop((0, ui_1.red)("✗ build failed"));
|
|
81
|
+
return { ok: false, error: err };
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/** Runs after a failed build: explains what actually went wrong in plain
|
|
85
|
+
* English, then offers real next actions instead of just dying. Loops
|
|
86
|
+
* until the user picks something that resolves (a successful retry) or
|
|
87
|
+
* explicitly chooses to skip. */
|
|
88
|
+
async function recoverFromBuildFailure(dir, provider, key, err) {
|
|
89
|
+
const classified = (0, ui_1.classifyError)(err);
|
|
90
|
+
console.log("");
|
|
91
|
+
console.log((0, ui_1.yellow)(`Here's what happened: ${classified.summary}`));
|
|
92
|
+
const options = classified.kind === "rate_limit"
|
|
93
|
+
? [
|
|
94
|
+
{ label: "Try again in a bit (same provider)", value: "retry" },
|
|
95
|
+
{ label: "Switch to the other provider and try that instead", value: "switch" },
|
|
96
|
+
{ label: "Skip for now — I'll run `npx cairn build .` later", value: "skip" },
|
|
97
|
+
]
|
|
98
|
+
: classified.kind === "auth"
|
|
99
|
+
? [
|
|
100
|
+
{ label: "Paste the key again (I probably mistyped it)", value: "rekey" },
|
|
101
|
+
{ label: "Switch to the other provider instead", value: "switch" },
|
|
102
|
+
{ label: "Skip for now — I'll run `npx cairn build .` later", value: "skip" },
|
|
103
|
+
]
|
|
104
|
+
: [
|
|
105
|
+
{ label: "Try again", value: "retry" },
|
|
106
|
+
{ label: "Switch to the other provider instead", value: "switch" },
|
|
107
|
+
{ label: "Skip for now — I'll run `npx cairn build .` later", value: "skip" },
|
|
108
|
+
];
|
|
109
|
+
for (;;) {
|
|
110
|
+
const choice = await (0, prompt_1.selectFromList)("What do you want to do?", options, 0);
|
|
111
|
+
if (choice === "skip")
|
|
112
|
+
return null;
|
|
113
|
+
let nextProvider = provider;
|
|
114
|
+
let nextKey = key;
|
|
115
|
+
if (choice === "switch") {
|
|
116
|
+
nextProvider = provider === "anthropic" ? "groq" : "anthropic";
|
|
117
|
+
const pasted = await (0, prompt_1.askOptional)(nextProvider === "anthropic" ? "Paste your ANTHROPIC_API_KEY: " : "Paste your GROQ_API_KEYS: ");
|
|
118
|
+
if (!pasted) {
|
|
119
|
+
console.log((0, ui_1.dim)("No key given — back to the menu."));
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
nextKey = pasted;
|
|
123
|
+
}
|
|
124
|
+
else if (choice === "rekey") {
|
|
125
|
+
const pasted = await (0, prompt_1.askOptional)(provider === "anthropic" ? "Paste your ANTHROPIC_API_KEY: " : "Paste your GROQ_API_KEYS: ");
|
|
126
|
+
if (!pasted) {
|
|
127
|
+
console.log((0, ui_1.dim)("No key given — back to the menu."));
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
nextKey = pasted;
|
|
131
|
+
}
|
|
132
|
+
// choice === "retry" falls through with the same provider/key.
|
|
133
|
+
const result = await attemptBuild(dir, nextProvider, nextKey);
|
|
134
|
+
if (result.ok)
|
|
135
|
+
return { provider: nextProvider, key: nextKey };
|
|
136
|
+
console.log("");
|
|
137
|
+
console.log((0, ui_1.yellow)(`Still failing: ${(0, ui_1.classifyError)(result.error).summary}`));
|
|
138
|
+
// loop back to the menu rather than recursing — keeps this one flat retry
|
|
139
|
+
// loop instead of a call stack that grows with every attempt
|
|
140
|
+
}
|
|
141
|
+
}
|
|
49
142
|
async function runSetup(dir) {
|
|
50
143
|
const absDir = node_path_1.default.resolve(dir);
|
|
51
|
-
console.log(
|
|
144
|
+
console.log(`${(0, ui_1.bold)("cairn setup")} — looking at ${absDir}\n`);
|
|
52
145
|
// 1. Scaffold what init already safely can — framework detection, the
|
|
53
146
|
// backend route, .env.example. Never overwrites anything that exists.
|
|
54
147
|
const init = (0, init_1.runInit)(dir);
|
|
55
|
-
console.log(`Detected: ${init.framework}`);
|
|
148
|
+
console.log(`Detected: ${(0, ui_1.bold)(init.framework)}`);
|
|
56
149
|
for (const f of init.filesWritten)
|
|
57
150
|
console.log(` wrote ${node_path_1.default.relative(absDir, f) || f}`);
|
|
58
151
|
for (const f of init.filesSkipped)
|
|
@@ -71,31 +164,43 @@ async function runSetup(dir) {
|
|
|
71
164
|
// cleanly if already present (e.g. re-running setup after a partial run).
|
|
72
165
|
const pkg = readPackageJson(absDir);
|
|
73
166
|
if (!alreadyInstalled(pkg)) {
|
|
74
|
-
|
|
167
|
+
const spinner = new ui_1.Spinner(`Installing ${PACKAGES.join(", ")} ...`);
|
|
168
|
+
spinner.start();
|
|
75
169
|
try {
|
|
76
|
-
(0, node_child_process_1.execSync)(`npm install ${PACKAGES.join(" ")}`, { cwd: absDir, stdio: "
|
|
170
|
+
(0, node_child_process_1.execSync)(`npm install ${PACKAGES.join(" ")}`, { cwd: absDir, stdio: "pipe" });
|
|
171
|
+
spinner.stop((0, ui_1.green)(`✓ installed ${PACKAGES.join(", ")}`));
|
|
77
172
|
}
|
|
78
173
|
catch {
|
|
79
|
-
|
|
80
|
-
console.error(` npm install ${PACKAGES.join(" ")}`);
|
|
174
|
+
spinner.stop((0, ui_1.red)("✗ npm install failed"));
|
|
175
|
+
console.error(`Install these yourself and re-run \`cairn setup\`:\n npm install ${PACKAGES.join(" ")}`);
|
|
81
176
|
return;
|
|
82
177
|
}
|
|
83
178
|
}
|
|
84
179
|
else {
|
|
85
|
-
console.log("Dependencies already installed — skipping
|
|
180
|
+
console.log((0, ui_1.dim)("Dependencies already installed — skipping."));
|
|
86
181
|
}
|
|
87
|
-
// 3. Ask only what's actually needed, everything skippable
|
|
88
|
-
|
|
182
|
+
// 3. Ask only what's actually needed, everything skippable, picked from a
|
|
183
|
+
// real menu rather than typed free text.
|
|
184
|
+
console.log(`\n${(0, ui_1.bold)("A couple of quick questions")} — press enter to skip anything you'll add later.\n`);
|
|
89
185
|
let provider = null;
|
|
90
186
|
let providerKey = null;
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
187
|
+
const llmChoice = await (0, prompt_1.selectFromList)("Set up an LLM provider now? (needed for the agent to actually answer anything)", [
|
|
188
|
+
{ label: "Anthropic (Claude)", value: "anthropic" },
|
|
189
|
+
{ label: "Groq", value: "groq" },
|
|
190
|
+
{ label: "Skip — I'll add one to .env later", value: "skip" },
|
|
191
|
+
], 0);
|
|
192
|
+
if (llmChoice !== "skip") {
|
|
193
|
+
provider = llmChoice;
|
|
95
194
|
providerKey = await (0, prompt_1.askOptional)(provider === "anthropic" ? "Paste your ANTHROPIC_API_KEY: " : "Paste your GROQ_API_KEYS: ");
|
|
96
195
|
}
|
|
97
|
-
|
|
98
|
-
|
|
196
|
+
// Honest about what's actually implemented here — Deepgram is the only
|
|
197
|
+
// voice provider this SDK wires up today, so this is "on or off," not a
|
|
198
|
+
// real multi-provider menu dressed up as one.
|
|
199
|
+
const voiceChoice = await (0, prompt_1.selectFromList)("Set up voice now?", [
|
|
200
|
+
{ label: "Deepgram (speech in + out)", value: "deepgram" },
|
|
201
|
+
{ label: "Skip — no voice for now", value: "skip" },
|
|
202
|
+
], 1);
|
|
203
|
+
const deepgramKey = voiceChoice === "deepgram" ? await (0, prompt_1.askOptional)("Paste your DEEPGRAM_API_KEY: ") : null;
|
|
99
204
|
(0, prompt_1.closePrompts)();
|
|
100
205
|
// 4. Write a real .env (not just .env.example) with whatever was actually given.
|
|
101
206
|
const envLines = [];
|
|
@@ -120,37 +225,29 @@ async function runSetup(dir) {
|
|
|
120
225
|
const framework = init.framework;
|
|
121
226
|
const inject = (0, inject_widget_1.injectWidget)(dir, framework);
|
|
122
227
|
if (inject.injected) {
|
|
123
|
-
console.log(
|
|
228
|
+
console.log((0, ui_1.green)(`✓ wired <Copilot/> into ${node_path_1.default.relative(absDir, inject.filePath)}`));
|
|
124
229
|
}
|
|
125
230
|
else {
|
|
126
231
|
console.log(`\n<Copilot/> not auto-wired (${inject.reason}). Add it yourself:`);
|
|
127
232
|
console.log(' import { Copilot } from "@cairnvibe/sdk";');
|
|
128
233
|
console.log(" <Copilot registeredActions={[]} onDo={(action, target) => { /* run it */ }} />");
|
|
129
234
|
}
|
|
130
|
-
// 6. Build the manifest once now, if we actually have a usable key —
|
|
131
|
-
//
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
const l2 = (0, l2_reachability_1.computeL2)(dir, facts);
|
|
147
|
-
const l3 = await (0, l3_describe_1.describeAll)(dir, facts, client);
|
|
148
|
-
const manifest = core_1.ManifestSchema.parse((0, manifest_1.assembleManifest)(dir, facts, l2, l3));
|
|
149
|
-
node_fs_1.default.writeFileSync(node_path_1.default.join(absDir, "ui-manifest.json"), JSON.stringify(manifest, null, 2) + "\n");
|
|
150
|
-
console.log(`wrote ui-manifest.json (${manifest.pages.length} page(s))`);
|
|
151
|
-
}
|
|
152
|
-
catch (err) {
|
|
153
|
-
console.error(`manifest build failed (${err.message}) — run \`npx cairn build .\` yourself once your key is confirmed working.`);
|
|
235
|
+
// 6. Build the manifest once now, if we actually have a usable key — no
|
|
236
|
+
// point trying (and failing loudly) with nothing to call. On failure,
|
|
237
|
+
// don't just print a stack trace and give up: classify what went wrong
|
|
238
|
+
// and offer real next steps (retry / switch provider / skip).
|
|
239
|
+
if (provider && providerKey) {
|
|
240
|
+
console.log("");
|
|
241
|
+
let result = await attemptBuild(dir, provider, providerKey);
|
|
242
|
+
if (!result.ok) {
|
|
243
|
+
const recovered = await recoverFromBuildFailure(dir, provider, providerKey, result.error);
|
|
244
|
+
if (recovered) {
|
|
245
|
+
provider = recovered.provider;
|
|
246
|
+
providerKey = recovered.key;
|
|
247
|
+
}
|
|
248
|
+
// else: user chose to skip — fall through with the original provider/key
|
|
249
|
+
// still recorded for the prebuild script below; ui-manifest.json is
|
|
250
|
+
// simply not written yet.
|
|
154
251
|
}
|
|
155
252
|
}
|
|
156
253
|
else {
|
|
@@ -167,9 +264,9 @@ async function runSetup(dir) {
|
|
|
167
264
|
? `${fresh.scripts.prebuild} && cairn build . --provider ${providerFlag} --if-configured`
|
|
168
265
|
: `cairn build . --provider ${providerFlag} --if-configured`;
|
|
169
266
|
node_fs_1.default.writeFileSync(pkgPath, JSON.stringify(fresh, null, 2) + "\n");
|
|
170
|
-
console.log('
|
|
171
|
-
console.log("(--if-configured means a build with no key set yet skips this step instead of failing the whole build —");
|
|
172
|
-
console.log(" set the same key as an environment variable on whatever platform you deploy to.)");
|
|
267
|
+
console.log('\nadded a "prebuild" script — the manifest regenerates automatically on every `npm run build`.');
|
|
268
|
+
console.log((0, ui_1.dim)("(--if-configured means a build with no key set yet skips this step instead of failing the whole build —"));
|
|
269
|
+
console.log((0, ui_1.dim)(" set the same key as an environment variable on whatever platform you deploy to.)"));
|
|
173
270
|
}
|
|
174
|
-
console.log("
|
|
271
|
+
console.log(`\n${(0, ui_1.bold)("Done.")} \`npm run dev\` and ask it something.`);
|
|
175
272
|
}
|
package/dist/ui.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// A small terminal UI toolkit for `cairn setup` — zero new dependencies,
|
|
3
|
+
// plain ANSI codes (this is a handful of escape sequences, not a reason
|
|
4
|
+
// to pull in a whole chalk/ora dependency tree). Every piece degrades
|
|
5
|
+
// gracefully when stdout isn't a real TTY (CI logs, piped output): the
|
|
6
|
+
// spinner just prints its text once instead of animating, and colors
|
|
7
|
+
// still work fine (most CI systems render ANSI color codes correctly
|
|
8
|
+
// even without an interactive terminal).
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.Spinner = exports.cyan = exports.red = exports.yellow = exports.green = exports.bold = exports.dim = void 0;
|
|
11
|
+
exports.classifyError = classifyError;
|
|
12
|
+
const ESC = "\x1b[";
|
|
13
|
+
const color = (code, s) => `${ESC}${code}m${s}${ESC}0m`;
|
|
14
|
+
const dim = (s) => color("2", s);
|
|
15
|
+
exports.dim = dim;
|
|
16
|
+
const bold = (s) => color("1", s);
|
|
17
|
+
exports.bold = bold;
|
|
18
|
+
const green = (s) => color("32", s);
|
|
19
|
+
exports.green = green;
|
|
20
|
+
const yellow = (s) => color("33", s);
|
|
21
|
+
exports.yellow = yellow;
|
|
22
|
+
const red = (s) => color("31", s);
|
|
23
|
+
exports.red = red;
|
|
24
|
+
const cyan = (s) => color("36", s);
|
|
25
|
+
exports.cyan = cyan;
|
|
26
|
+
const FRAMES = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
|
|
27
|
+
class Spinner {
|
|
28
|
+
text;
|
|
29
|
+
frame = 0;
|
|
30
|
+
timer = null;
|
|
31
|
+
animated;
|
|
32
|
+
constructor(text) {
|
|
33
|
+
this.text = text;
|
|
34
|
+
this.animated = !!process.stdout.isTTY;
|
|
35
|
+
}
|
|
36
|
+
start() {
|
|
37
|
+
if (!this.animated) {
|
|
38
|
+
console.log((0, exports.dim)(this.text));
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
this.timer = setInterval(() => {
|
|
42
|
+
process.stdout.write(`\r${ESC}K${(0, exports.cyan)(FRAMES[(this.frame = (this.frame + 1) % FRAMES.length)])} ${this.text}`);
|
|
43
|
+
}, 80);
|
|
44
|
+
}
|
|
45
|
+
/** Update the line in place without starting a new one. */
|
|
46
|
+
update(text) {
|
|
47
|
+
this.text = text;
|
|
48
|
+
if (!this.animated)
|
|
49
|
+
console.log((0, exports.dim)(text));
|
|
50
|
+
}
|
|
51
|
+
/** Stop animating and print a final, non-spinning result line. */
|
|
52
|
+
stop(finalLine) {
|
|
53
|
+
if (this.timer) {
|
|
54
|
+
clearInterval(this.timer);
|
|
55
|
+
this.timer = null;
|
|
56
|
+
}
|
|
57
|
+
if (this.animated)
|
|
58
|
+
process.stdout.write(`\r${ESC}K`);
|
|
59
|
+
console.log(finalLine);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.Spinner = Spinner;
|
|
63
|
+
/** Turns a raw thrown error into a plain-English category + summary —
|
|
64
|
+
* the thing `cairn setup` actually reasons about when deciding what to
|
|
65
|
+
* offer next (switch provider vs. just retry vs. nothing to fix). */
|
|
66
|
+
function classifyError(err) {
|
|
67
|
+
const status = err?.status;
|
|
68
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
69
|
+
if (status === 429 || /rate.?limit/i.test(message)) {
|
|
70
|
+
return { kind: "rate_limit", summary: "the provider is rate-limiting requests — this key has hit its per-minute quota" };
|
|
71
|
+
}
|
|
72
|
+
if (status === 401 || status === 403 || /invalid.*key|unauthorized|authentication/i.test(message)) {
|
|
73
|
+
return { kind: "auth", summary: "that API key was rejected — check it's correct and active" };
|
|
74
|
+
}
|
|
75
|
+
if ((typeof status === "number" && status >= 500) || /ECONNRESET|ETIMEDOUT|network/i.test(message)) {
|
|
76
|
+
return { kind: "network", summary: "the provider's servers had a problem — often transient" };
|
|
77
|
+
}
|
|
78
|
+
return { kind: "unknown", summary: message };
|
|
79
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cairnvibe/indexer",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Cairn's analyzer and installer (the `cairn` CLI) — scans Next.js source or crawls any running app, and scaffolds the backend either way.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": { "access": "public" },
|