create-nimbo 0.0.0-stage → 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/CHANGELOG.md +28 -0
- package/LICENSE +21 -0
- package/README.md +32 -2
- package/install.js +6 -0
- package/package.json +33 -4
- package/tools/nimbo/install.js +576 -0
- package/tools/nimbo/template/.claude/skills/blueprint/SKILL.md +161 -0
- package/tools/nimbo/template/.claude/skills/discover/SKILL.md +71 -0
- package/tools/nimbo/template/.claude/skills/explain/SKILL.md +66 -0
- package/tools/nimbo/template/.claude/skills/feature/SKILL.md +124 -0
- package/tools/nimbo/template/.claude/skills/intake/SKILL.md +131 -0
- package/tools/nimbo/template/.claude/skills/integrate/SKILL.md +75 -0
- package/tools/nimbo/template/.claude/skills/reflect/SKILL.md +58 -0
- package/tools/nimbo/template/.claude/skills/release/SKILL.md +80 -0
- package/tools/nimbo/template/.claude/skills/roadmap/SKILL.md +166 -0
- package/tools/nimbo/template/.claude/skills/stack/SKILL.md +116 -0
- package/tools/nimbo/template/.workflow/dashboard/build.mjs +301 -0
- package/tools/nimbo/template/.workflow/dashboard/template.html +964 -0
- package/tools/nimbo/template/AGENTS.md.template +21 -0
- package/tools/nimbo/template/CLAUDE.md.template +143 -0
|
@@ -0,0 +1,576 @@
|
|
|
1
|
+
// Place Nimbo's user template in a project without overwriting existing work.
|
|
2
|
+
|
|
3
|
+
import { createHash } from "node:crypto";
|
|
4
|
+
import fs from "node:fs";
|
|
5
|
+
import os from "node:os";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import readline from "node:readline";
|
|
8
|
+
import { fileURLToPath } from "node:url";
|
|
9
|
+
import { parseArgs } from "node:util";
|
|
10
|
+
|
|
11
|
+
const HERE = path.dirname(fs.realpathSync(fileURLToPath(import.meta.url)));
|
|
12
|
+
export const SOURCE_ROOT = path.resolve(HERE, "../..");
|
|
13
|
+
export const TEMPLATE = path.join(HERE, "template");
|
|
14
|
+
const SKILLS = ["intake", "discover", "blueprint", "stack", "roadmap", "feature", "integrate", "release", "explain", "reflect"];
|
|
15
|
+
const MANIFEST = ".workflow/nimbo-install.json";
|
|
16
|
+
|
|
17
|
+
/** An installation cannot proceed without risking existing work. */
|
|
18
|
+
export class InstallError extends Error {}
|
|
19
|
+
|
|
20
|
+
// Payload keys are POSIX-style paths relative to the project root.
|
|
21
|
+
const onDisk = (root, relative) => path.join(root, ...relative.split("/"));
|
|
22
|
+
|
|
23
|
+
function fileState(file) {
|
|
24
|
+
try {
|
|
25
|
+
return fs.lstatSync(file);
|
|
26
|
+
} catch (error) {
|
|
27
|
+
if (error.code === "ENOENT") return null;
|
|
28
|
+
throw error;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function ancestors(file) {
|
|
33
|
+
const chain = [file];
|
|
34
|
+
while (path.dirname(chain[0]) !== chain[0]) chain.unshift(path.dirname(chain[0]));
|
|
35
|
+
return chain;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Inspect a path and its ancestors without resolving or following symbolic links. */
|
|
39
|
+
function directoryProblem(directory) {
|
|
40
|
+
for (const candidate of ancestors(directory)) {
|
|
41
|
+
const info = fileState(candidate);
|
|
42
|
+
if (info === null) continue;
|
|
43
|
+
if (info.isSymbolicLink()) return `symbolic link in path: ${candidate}`;
|
|
44
|
+
if (!info.isDirectory()) return `not a directory: ${candidate}`;
|
|
45
|
+
}
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function isWithin(child, parent) {
|
|
50
|
+
const relative = path.relative(parent, child);
|
|
51
|
+
return relative === "" || (relative !== ".." && !relative.startsWith(`..${path.sep}`) && !path.isAbsolute(relative));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function listEntries(root, prefix = "") {
|
|
55
|
+
const found = [];
|
|
56
|
+
for (const entry of fs.readdirSync(path.join(root, prefix), { withFileTypes: true })) {
|
|
57
|
+
const relative = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
58
|
+
if (entry.isDirectory()) found.push(...listEntries(root, relative));
|
|
59
|
+
else found.push(relative);
|
|
60
|
+
}
|
|
61
|
+
return found;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function templateFiles() {
|
|
65
|
+
const mapping = new Map([
|
|
66
|
+
["AGENTS.md", "AGENTS.md.template"],
|
|
67
|
+
["CLAUDE.md", "CLAUDE.md.template"],
|
|
68
|
+
// The dashboard script and its page; they write their output to .workflow/out/ (outside Git).
|
|
69
|
+
[".workflow/dashboard/build.mjs", ".workflow/dashboard/build.mjs"],
|
|
70
|
+
[".workflow/dashboard/template.html", ".workflow/dashboard/template.html"],
|
|
71
|
+
]);
|
|
72
|
+
// Claude Code reads .claude/skills (/name); Codex reads .agents/skills ($name).
|
|
73
|
+
for (const root of [".claude/skills", ".agents/skills"]) {
|
|
74
|
+
for (const skill of SKILLS) mapping.set(`${root}/${skill}/SKILL.md`, `.claude/skills/${skill}/SKILL.md`);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// An explicit payload prevents accidental inclusion of project data or secrets.
|
|
78
|
+
const problem = directoryProblem(TEMPLATE);
|
|
79
|
+
if (problem) throw new InstallError(`Invalid source folder: ${problem}`);
|
|
80
|
+
if (!fileState(TEMPLATE)?.isDirectory()) throw new InstallError(`Template missing: ${TEMPLATE}`);
|
|
81
|
+
for (const source of mapping.values()) {
|
|
82
|
+
const file = onDisk(TEMPLATE, source);
|
|
83
|
+
const info = fileState(file);
|
|
84
|
+
if (directoryProblem(path.dirname(file)) || info === null || !info.isFile()) {
|
|
85
|
+
throw new InstallError(`Template file missing or not a regular file: ${source}`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
const expected = new Set(mapping.values());
|
|
89
|
+
const unexpected = listEntries(TEMPLATE).filter((relative) => !expected.has(relative)).sort();
|
|
90
|
+
if (unexpected.length) {
|
|
91
|
+
throw new InstallError(`Unexpected template files; change the template set deliberately: ${unexpected.join(", ")}`);
|
|
92
|
+
}
|
|
93
|
+
const payload = new Map();
|
|
94
|
+
for (const [target, source] of mapping) payload.set(target, fs.readFileSync(onDisk(TEMPLATE, source)));
|
|
95
|
+
return payload;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const sha256 = (data) => createHash("sha256").update(data).digest("hex");
|
|
99
|
+
|
|
100
|
+
function sortedObject(entries) {
|
|
101
|
+
return Object.fromEntries([...entries].sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)));
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function nimboVersion() {
|
|
105
|
+
try {
|
|
106
|
+
return JSON.parse(fs.readFileSync(path.join(SOURCE_ROOT, "package.json"), "utf8")).version || "unknown";
|
|
107
|
+
} catch {
|
|
108
|
+
return "unknown";
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export function installationFiles() {
|
|
113
|
+
const payload = templateFiles();
|
|
114
|
+
const license = path.join(SOURCE_ROOT, "LICENSE");
|
|
115
|
+
if (!fileState(license)?.isFile()) {
|
|
116
|
+
throw new InstallError("The Nimbo license is missing from the source or is not a regular file.");
|
|
117
|
+
}
|
|
118
|
+
payload.set(".workflow/LICENSE.nimbo", fs.readFileSync(license));
|
|
119
|
+
const hashes = sortedObject([...payload].map(([relative, data]) => [relative, sha256(data)]));
|
|
120
|
+
const manifest = sortedObject(Object.entries({
|
|
121
|
+
tool: "nimbo",
|
|
122
|
+
version: nimboVersion(),
|
|
123
|
+
manifest_version: 1,
|
|
124
|
+
template_sha256: sha256(JSON.stringify(hashes)),
|
|
125
|
+
files: hashes,
|
|
126
|
+
}));
|
|
127
|
+
payload.set(MANIFEST, Buffer.from(`${JSON.stringify(manifest, null, 2)}\n`, "utf8"));
|
|
128
|
+
return payload;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** The manifest of an earlier Nimbo installation, or null if there is none (or it is not Nimbo's). */
|
|
132
|
+
export function readManifest(target) {
|
|
133
|
+
const file = onDisk(target, MANIFEST);
|
|
134
|
+
if (directoryProblem(path.dirname(file)) || !fileState(file)?.isFile()) return null;
|
|
135
|
+
try {
|
|
136
|
+
const manifest = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
137
|
+
const files = manifest?.files;
|
|
138
|
+
if (manifest?.tool !== "nimbo" || !files || typeof files !== "object" || Array.isArray(files)) return null;
|
|
139
|
+
if (!Object.values(files).every((digest) => typeof digest === "string")) return null;
|
|
140
|
+
return manifest;
|
|
141
|
+
} catch {
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** Only these locations may ever be removed on the strength of an old manifest. */
|
|
147
|
+
function isNimboPath(relative) {
|
|
148
|
+
const parts = relative.split("/");
|
|
149
|
+
if (parts.some((part) => part === "" || part === "." || part === "..") || relative.includes("\\")) return false;
|
|
150
|
+
if (["AGENTS.md", "CLAUDE.md"].includes(relative)) return true;
|
|
151
|
+
if ([".claude", ".agents"].includes(parts[0]) && parts[1] === "skills" && parts.length === 4 && parts[3] === "SKILL.md") return true;
|
|
152
|
+
return parts[0] === ".workflow" && relative !== ".workflow/config.md" && parts[1] !== "out";
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export const sidecar = (relative) => `${relative}.nimbo-new`;
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Compare the payload with the target.
|
|
159
|
+
* Without a Nimbo manifest this is a fresh install: any differing file is a conflict.
|
|
160
|
+
* With one it is an update: files the user did not change are replaced, changed files are
|
|
161
|
+
* kept (the new version is placed next to them as .nimbo-new) and retired files are removed.
|
|
162
|
+
*/
|
|
163
|
+
export function makePlan(target, payload) {
|
|
164
|
+
if (isWithin(target, SOURCE_ROOT) || isWithin(SOURCE_ROOT, target)) {
|
|
165
|
+
throw new InstallError("Choose a separate user project, outside the Nimbo source folder.");
|
|
166
|
+
}
|
|
167
|
+
const problem = directoryProblem(target);
|
|
168
|
+
if (problem) throw new InstallError(problem);
|
|
169
|
+
const manifest = readManifest(target);
|
|
170
|
+
const plan = { update: Boolean(manifest), additions: [], updates: [], unchanged: [], kept: [], removals: [], left: [], conflicts: [] };
|
|
171
|
+
const inspect = (relative) => {
|
|
172
|
+
const destination = onDisk(target, relative);
|
|
173
|
+
const parentProblem = directoryProblem(path.dirname(destination));
|
|
174
|
+
if (parentProblem) return { problem: parentProblem };
|
|
175
|
+
const info = fileState(destination);
|
|
176
|
+
if (info === null) return { missing: true };
|
|
177
|
+
if (!info.isFile()) return { problem: "not a regular file (or a symbolic link)" };
|
|
178
|
+
return { data: fs.readFileSync(destination) };
|
|
179
|
+
};
|
|
180
|
+
for (const [relative, data] of payload) {
|
|
181
|
+
const found = inspect(relative);
|
|
182
|
+
if (found.problem) plan.conflicts.push([relative, found.problem]);
|
|
183
|
+
else if (found.missing) plan.additions.push(relative);
|
|
184
|
+
else if (found.data.equals(data)) plan.unchanged.push(relative);
|
|
185
|
+
else if (!manifest) plan.conflicts.push([relative, "exists with different content"]);
|
|
186
|
+
else if (relative === MANIFEST || manifest.files[relative] === sha256(found.data)) plan.updates.push(relative);
|
|
187
|
+
// The user changed it, but this Nimbo version did not: their version simply stays.
|
|
188
|
+
else if (manifest.files[relative] === sha256(data)) plan.unchanged.push(relative);
|
|
189
|
+
else {
|
|
190
|
+
const side = inspect(sidecar(relative));
|
|
191
|
+
if (side.problem) plan.conflicts.push([sidecar(relative), side.problem]);
|
|
192
|
+
else plan.kept.push([relative, Boolean(side.data?.equals(data))]);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
if (manifest) {
|
|
196
|
+
for (const [relative, digest] of Object.entries(manifest.files).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))) {
|
|
197
|
+
if (payload.has(relative) || !isNimboPath(relative)) continue;
|
|
198
|
+
const found = inspect(relative);
|
|
199
|
+
if (found.problem) plan.conflicts.push([relative, found.problem]);
|
|
200
|
+
else if (found.missing) continue;
|
|
201
|
+
else if (sha256(found.data) === digest) plan.removals.push(relative);
|
|
202
|
+
else plan.left.push(relative);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return plan;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export function writeNewFile(file, data, createdFiles) {
|
|
209
|
+
// Exclusive creation never replaces an entry created after the preflight.
|
|
210
|
+
const descriptor = fs.openSync(file, "wx");
|
|
211
|
+
try {
|
|
212
|
+
const info = fs.fstatSync(descriptor);
|
|
213
|
+
createdFiles.push({ file, dev: info.dev, ino: info.ino });
|
|
214
|
+
fs.writeFileSync(descriptor, data);
|
|
215
|
+
} finally {
|
|
216
|
+
fs.closeSync(descriptor);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** Replace a regular file in one step: write next to it, then rename over it. */
|
|
221
|
+
export function replaceFile(file, data) {
|
|
222
|
+
const temporary = `${file}.nimbo-tmp`;
|
|
223
|
+
if (fileState(temporary)?.isFile()) fs.unlinkSync(temporary);
|
|
224
|
+
fs.writeFileSync(temporary, data, { flag: "wx" });
|
|
225
|
+
fs.renameSync(temporary, file);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// The manifest goes last, so an interrupted run is still recognised as the old installation.
|
|
229
|
+
const manifestLast = (list) => [...list.filter((relative) => relative !== MANIFEST), ...list.filter((relative) => relative === MANIFEST)];
|
|
230
|
+
|
|
231
|
+
export function applyPlan(target, payload, plan, { write = writeNewFile, replace = replaceFile } = {}) {
|
|
232
|
+
const createdFiles = [];
|
|
233
|
+
const createdDirectories = [];
|
|
234
|
+
const restore = []; // [file, original content or null when the file did not exist]
|
|
235
|
+
try {
|
|
236
|
+
// Recheck the full plan before making even a directory.
|
|
237
|
+
const current = makePlan(target, payload);
|
|
238
|
+
if (JSON.stringify(current) !== JSON.stringify({ ...plan, conflicts: [] })) {
|
|
239
|
+
throw new InstallError("The target changed since the check; run the installation again.");
|
|
240
|
+
}
|
|
241
|
+
const ensureParents = (destination) => {
|
|
242
|
+
let problem = directoryProblem(path.dirname(destination));
|
|
243
|
+
if (problem) throw new InstallError(problem);
|
|
244
|
+
const missing = [];
|
|
245
|
+
let parent = path.dirname(destination);
|
|
246
|
+
while (fileState(parent) === null) {
|
|
247
|
+
missing.push(parent);
|
|
248
|
+
parent = path.dirname(parent);
|
|
249
|
+
}
|
|
250
|
+
for (const directory of missing.reverse()) {
|
|
251
|
+
fs.mkdirSync(directory);
|
|
252
|
+
createdDirectories.push(directory);
|
|
253
|
+
}
|
|
254
|
+
problem = directoryProblem(path.dirname(destination));
|
|
255
|
+
if (problem) throw new InstallError(problem);
|
|
256
|
+
};
|
|
257
|
+
const replaceTracked = (destination, data) => {
|
|
258
|
+
const original = fileState(destination) ? fs.readFileSync(destination) : null;
|
|
259
|
+
restore.push([destination, original]);
|
|
260
|
+
replace(destination, data);
|
|
261
|
+
};
|
|
262
|
+
for (const relative of manifestLast(plan.additions)) {
|
|
263
|
+
const destination = onDisk(target, relative);
|
|
264
|
+
ensureParents(destination);
|
|
265
|
+
write(destination, payload.get(relative), createdFiles);
|
|
266
|
+
}
|
|
267
|
+
for (const [relative, current] of plan.kept) {
|
|
268
|
+
if (current) continue;
|
|
269
|
+
const destination = onDisk(target, sidecar(relative));
|
|
270
|
+
replaceTracked(destination, payload.get(relative));
|
|
271
|
+
}
|
|
272
|
+
for (const relative of plan.removals) {
|
|
273
|
+
const destination = onDisk(target, relative);
|
|
274
|
+
restore.push([destination, fs.readFileSync(destination)]);
|
|
275
|
+
fs.unlinkSync(destination);
|
|
276
|
+
}
|
|
277
|
+
for (const relative of manifestLast(plan.updates)) replaceTracked(onDisk(target, relative), payload.get(relative));
|
|
278
|
+
} catch (error) {
|
|
279
|
+
const cleanupErrors = [];
|
|
280
|
+
for (const [file, original] of restore.reverse()) {
|
|
281
|
+
try {
|
|
282
|
+
if (original === null) fs.rmSync(file, { force: true });
|
|
283
|
+
else fs.writeFileSync(file, original);
|
|
284
|
+
} catch (cleanupError) {
|
|
285
|
+
cleanupErrors.push(cleanupError.message);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
for (const { file, dev, ino } of createdFiles.reverse()) {
|
|
289
|
+
try {
|
|
290
|
+
const info = fileState(file);
|
|
291
|
+
if (info?.isFile() && info.dev === dev && info.ino === ino) fs.unlinkSync(file);
|
|
292
|
+
} catch (cleanupError) {
|
|
293
|
+
cleanupErrors.push(cleanupError.message);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
for (const directory of createdDirectories.reverse()) {
|
|
297
|
+
try {
|
|
298
|
+
fs.rmdirSync(directory); // Only empty directories created by this run.
|
|
299
|
+
} catch (cleanupError) {
|
|
300
|
+
cleanupErrors.push(cleanupError.message);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
const detail = cleanupErrors.length
|
|
304
|
+
? ` Check for leftover new files/folders: ${cleanupErrors.join("; ")}`
|
|
305
|
+
: "";
|
|
306
|
+
throw new InstallError(`Installation aborted: ${error.message}.${detail}`, { cause: error });
|
|
307
|
+
}
|
|
308
|
+
// A retired skill leaves an empty folder; tidy it up (best effort, nothing else is touched).
|
|
309
|
+
for (const relative of plan.removals) {
|
|
310
|
+
try {
|
|
311
|
+
fs.rmdirSync(path.dirname(onDisk(target, relative)));
|
|
312
|
+
} catch {
|
|
313
|
+
// Not empty or already gone: leave it.
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
const USAGE = "usage: nimbo [-h] [--dry-run] [--verbose] [--yes] [project]";
|
|
319
|
+
const HELP = `${USAGE}
|
|
320
|
+
|
|
321
|
+
Install Nimbo into a new or existing project without overwriting files.
|
|
322
|
+
Run it again in a project that has Nimbo to update it: files you did not change are
|
|
323
|
+
replaced, files you changed are kept and the new version is placed next to them as
|
|
324
|
+
<file>.nimbo-new. Your project documents, configuration and code are never touched.
|
|
325
|
+
|
|
326
|
+
arguments:
|
|
327
|
+
project target folder; defaults to the current terminal folder
|
|
328
|
+
|
|
329
|
+
options:
|
|
330
|
+
-h, --help show this help
|
|
331
|
+
--dry-run show the plan file by file without creating anything
|
|
332
|
+
-v, --verbose list every file
|
|
333
|
+
-y, --yes install without confirmation; requires a target folder
|
|
334
|
+
|
|
335
|
+
Requires Node.js 20+. Sets up no Git, product plan or intake configuration; Nimbo's intake does that.
|
|
336
|
+
Colors are off when the output is not a terminal or NO_COLOR is set.`;
|
|
337
|
+
|
|
338
|
+
class UsageError extends Error {}
|
|
339
|
+
|
|
340
|
+
function parseArguments(argv) {
|
|
341
|
+
let parsed;
|
|
342
|
+
try {
|
|
343
|
+
parsed = parseArgs({
|
|
344
|
+
args: argv,
|
|
345
|
+
allowPositionals: true,
|
|
346
|
+
options: {
|
|
347
|
+
help: { type: "boolean", short: "h" },
|
|
348
|
+
"dry-run": { type: "boolean" },
|
|
349
|
+
verbose: { type: "boolean", short: "v" },
|
|
350
|
+
yes: { type: "boolean", short: "y" },
|
|
351
|
+
},
|
|
352
|
+
});
|
|
353
|
+
} catch (error) {
|
|
354
|
+
throw new UsageError(error.message);
|
|
355
|
+
}
|
|
356
|
+
const { values, positionals } = parsed;
|
|
357
|
+
if (positionals.length > 1) throw new UsageError(`unexpected arguments: ${positionals.slice(1).join(" ")}`);
|
|
358
|
+
const options = {
|
|
359
|
+
help: Boolean(values.help),
|
|
360
|
+
dryRun: Boolean(values["dry-run"]),
|
|
361
|
+
verbose: Boolean(values.verbose || values["dry-run"]),
|
|
362
|
+
yes: Boolean(values.yes),
|
|
363
|
+
project: positionals[0],
|
|
364
|
+
};
|
|
365
|
+
if (options.yes && options.project === undefined && !options.help) {
|
|
366
|
+
throw new UsageError("--yes requires a target folder.");
|
|
367
|
+
}
|
|
368
|
+
return options;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/** Ask one question; resolves to null on end of input or interruption. */
|
|
372
|
+
function ask(question) {
|
|
373
|
+
return new Promise((resolve) => {
|
|
374
|
+
const prompt = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
375
|
+
let answered = false;
|
|
376
|
+
prompt.on("SIGINT", () => prompt.close());
|
|
377
|
+
prompt.on("close", () => {
|
|
378
|
+
if (!answered) resolve(null);
|
|
379
|
+
});
|
|
380
|
+
prompt.question(question, (answer) => {
|
|
381
|
+
answered = true;
|
|
382
|
+
prompt.close();
|
|
383
|
+
resolve(answer);
|
|
384
|
+
});
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
function expandHome(project) {
|
|
389
|
+
if (project === "~") return os.homedir();
|
|
390
|
+
if (project.startsWith("~/")) return path.join(os.homedir(), project.slice(2));
|
|
391
|
+
return project;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
const shortHome = (target) => {
|
|
395
|
+
const home = os.homedir();
|
|
396
|
+
return isWithin(target, home) && target !== home ? `~${target.slice(home.length)}` : target;
|
|
397
|
+
};
|
|
398
|
+
|
|
399
|
+
// The dashboard palette (dark theme), with a 256-color fallback for terminals without truecolor.
|
|
400
|
+
const PALETTE = {
|
|
401
|
+
text: [[233, 231, 227], 255],
|
|
402
|
+
muted: [[141, 138, 133], 245],
|
|
403
|
+
faint: [[90, 88, 84], 240],
|
|
404
|
+
you: [[217, 162, 115], 179],
|
|
405
|
+
nimbo: [[143, 169, 220], 110],
|
|
406
|
+
red: [[217, 115, 111], 167],
|
|
407
|
+
};
|
|
408
|
+
|
|
409
|
+
/** Color helpers for one output stream; plain text when it is not a terminal or NO_COLOR is set. */
|
|
410
|
+
export function painter(stream, env = process.env) {
|
|
411
|
+
const on = Boolean(stream.isTTY) && !env.NO_COLOR;
|
|
412
|
+
const truecolor = /truecolor|24bit/i.test(env.COLORTERM || "");
|
|
413
|
+
const paint = (name, bold = false) => (text) => {
|
|
414
|
+
if (!on) return text;
|
|
415
|
+
const [rgb, fallback] = PALETTE[name];
|
|
416
|
+
const color = truecolor ? `38;2;${rgb.join(";")}` : `38;5;${fallback}`;
|
|
417
|
+
return `\x1b[${bold ? "1;" : ""}${color}m${text}\x1b[0m`;
|
|
418
|
+
};
|
|
419
|
+
return {
|
|
420
|
+
text: paint("text"), bold: paint("text", true), muted: paint("muted"), faint: paint("faint"),
|
|
421
|
+
you: paint("you"), nimbo: paint("nimbo"), red: paint("red"),
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
function logo(c) {
|
|
426
|
+
// The dashboard logo: an open ring with a sphere in the middle.
|
|
427
|
+
return [
|
|
428
|
+
"",
|
|
429
|
+
` ${c.muted(" ──╮")}`,
|
|
430
|
+
` ${c.muted("│ ")}${c.bold("●")}${c.muted(" │")} ${c.bold("N I M B O")} ${c.faint(nimboVersion())}`,
|
|
431
|
+
` ${c.muted("╰─────╯")} ${c.faint("learn while doing")}`,
|
|
432
|
+
"",
|
|
433
|
+
].join("\n");
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
const plural = (n, one, many) => (n === 1 ? one : many);
|
|
437
|
+
const skillName = (relative) => relative.match(/^\.(?:claude|agents)\/skills\/([^/]+)\/SKILL\.md$/)?.[1];
|
|
438
|
+
|
|
439
|
+
/** Summarize files the way a user thinks about them: agent files, skills, dashboard, the rest. */
|
|
440
|
+
function summarize(files, c) {
|
|
441
|
+
const lines = [];
|
|
442
|
+
const agents = files.filter((relative) => relative === "AGENTS.md" || relative === "CLAUDE.md");
|
|
443
|
+
if (agents.length) lines.push(agents.join(", "));
|
|
444
|
+
const skills = [...new Set(files.map(skillName).filter(Boolean))];
|
|
445
|
+
if (skills.length === SKILLS.length && skills.every((name) => SKILLS.includes(name))) {
|
|
446
|
+
lines.push(`${skills.length} skills ${c.muted("for Claude Code and Codex")}`);
|
|
447
|
+
} else if (skills.length) {
|
|
448
|
+
lines.push(`${skills.length} ${plural(skills.length, "skill", "skills")}: ${skills.join(", ")}`);
|
|
449
|
+
}
|
|
450
|
+
if (files.some((relative) => relative.startsWith(".workflow/dashboard/"))) lines.push("dashboard");
|
|
451
|
+
const quiet = new Set([MANIFEST, ".workflow/LICENSE.nimbo"]);
|
|
452
|
+
for (const relative of files) {
|
|
453
|
+
if (agents.includes(relative) || skillName(relative) || relative.startsWith(".workflow/dashboard/") || quiet.has(relative)) continue;
|
|
454
|
+
lines.push(relative);
|
|
455
|
+
}
|
|
456
|
+
return lines;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
export async function main(argv = process.argv.slice(2)) {
|
|
460
|
+
let options;
|
|
461
|
+
try {
|
|
462
|
+
options = parseArguments(argv);
|
|
463
|
+
} catch (error) {
|
|
464
|
+
if (!(error instanceof UsageError)) throw error;
|
|
465
|
+
console.error(`${USAGE}\nnimbo: error: ${error.message}`);
|
|
466
|
+
return 2;
|
|
467
|
+
}
|
|
468
|
+
if (options.help) {
|
|
469
|
+
console.log(HELP);
|
|
470
|
+
return 0;
|
|
471
|
+
}
|
|
472
|
+
const c = painter(process.stdout);
|
|
473
|
+
const e = painter(process.stderr);
|
|
474
|
+
const say = (line = "") => console.log(line);
|
|
475
|
+
const item = (mark, text) => say(` ${mark} ${text}`);
|
|
476
|
+
const detail = (text) => say(` ${c.faint(text)}`);
|
|
477
|
+
try {
|
|
478
|
+
const target = path.resolve(options.project === undefined ? process.cwd() : expandHome(options.project));
|
|
479
|
+
say(logo(c));
|
|
480
|
+
const payload = installationFiles();
|
|
481
|
+
const plan = makePlan(target, payload);
|
|
482
|
+
const version = nimboVersion();
|
|
483
|
+
const updates = plan.updates.filter((relative) => relative !== MANIFEST);
|
|
484
|
+
const changes = plan.additions.length + updates.length
|
|
485
|
+
+ plan.removals.length + plan.kept.filter(([, current]) => !current).length;
|
|
486
|
+
|
|
487
|
+
say(` ${c.muted("Folder")} ${c.text(shortHome(target))}`);
|
|
488
|
+
if (plan.update && changes) {
|
|
489
|
+
const installed = readManifest(target).version ?? "unknown";
|
|
490
|
+
say(` ${c.muted("Update")} ${c.muted(installed)} ${c.muted("→")} ${c.text(version)}`);
|
|
491
|
+
}
|
|
492
|
+
say();
|
|
493
|
+
|
|
494
|
+
if (plan.conflicts.length) {
|
|
495
|
+
item(c.red("✖"), c.bold(`${plan.conflicts.length} ${plural(plan.conflicts.length, "file is", "files are")} in the way:`));
|
|
496
|
+
for (const [relative, reason] of plan.conflicts) {
|
|
497
|
+
detail(`${relative}${reason === "exists with different content" ? "" : `: ${reason}`}`);
|
|
498
|
+
}
|
|
499
|
+
item(c.muted("→"), `Rename or remove ${plural(plan.conflicts.length, "it", "them")}, then run the command again. Nothing was changed.`);
|
|
500
|
+
say();
|
|
501
|
+
return 1;
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
if (plan.update) {
|
|
505
|
+
if (updates.length) item(c.nimbo("↻"), `${updates.length} ${plural(updates.length, "file", "files")} updated`);
|
|
506
|
+
for (const line of summarize(plan.additions, c)) item(c.nimbo("+"), line);
|
|
507
|
+
if (plan.kept.length) {
|
|
508
|
+
const n = plan.kept.length;
|
|
509
|
+
item(c.you("!"), `${n} ${plural(n, "file you changed is kept; the new version is next to it:", "files you changed are kept; the new versions are next to them:")}`);
|
|
510
|
+
for (const [relative] of plan.kept) say(` ${c.faint(relative)}${c.you(".nimbo-new")}`);
|
|
511
|
+
}
|
|
512
|
+
if (plan.removals.length) {
|
|
513
|
+
item(c.nimbo("−"), `${plan.removals.length} ${plural(plan.removals.length, "file is", "files are")} no longer part of Nimbo and will be removed:`);
|
|
514
|
+
for (const relative of plan.removals) detail(relative);
|
|
515
|
+
}
|
|
516
|
+
if (plan.left.length) {
|
|
517
|
+
item(c.you("!"), `${plan.left.length} ${plural(plan.left.length, "file is", "files are")} no longer part of Nimbo, but you changed ${plural(plan.left.length, "it", "them")}; left in place:`);
|
|
518
|
+
for (const relative of plan.left) detail(relative);
|
|
519
|
+
}
|
|
520
|
+
} else {
|
|
521
|
+
for (const line of summarize(plan.additions, c)) item(c.nimbo("+"), line);
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
if (options.verbose) {
|
|
525
|
+
say();
|
|
526
|
+
for (const relative of plan.additions) detail(`NEW ${relative}`);
|
|
527
|
+
for (const relative of updates) detail(`UPDATE ${relative}`);
|
|
528
|
+
for (const [relative] of plan.kept) detail(`KEEP ${relative}`);
|
|
529
|
+
for (const relative of plan.removals) detail(`REMOVE ${relative}`);
|
|
530
|
+
for (const relative of plan.left) detail(`LEAVE ${relative}`);
|
|
531
|
+
if (!plan.update) for (const relative of plan.unchanged) detail(`SAME ${relative}`);
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
if (plan.update && !changes) {
|
|
535
|
+
// Only Nimbo's own bookkeeping may differ (such as the version number): refresh it quietly.
|
|
536
|
+
if (!options.dryRun && plan.updates.length) applyPlan(target, payload, plan);
|
|
537
|
+
item(c.nimbo("✔"), c.bold(`Nimbo ${version} is up to date.`));
|
|
538
|
+
say();
|
|
539
|
+
return 0;
|
|
540
|
+
}
|
|
541
|
+
if (options.dryRun) {
|
|
542
|
+
say();
|
|
543
|
+
say(` ${c.muted("Dry run: nothing written.")}`);
|
|
544
|
+
say();
|
|
545
|
+
return 0;
|
|
546
|
+
}
|
|
547
|
+
say();
|
|
548
|
+
if (changes && !options.yes) {
|
|
549
|
+
const verb = plan.update ? "Update" : "Install";
|
|
550
|
+
const where = options.project === undefined ? "here" : `in '${target}'`;
|
|
551
|
+
const answer = await ask(` ${verb} Nimbo ${where}? ${c.muted("[y/N]")} `);
|
|
552
|
+
if (answer === null || !["j", "ja", "y", "yes"].includes(answer.trim().toLowerCase())) {
|
|
553
|
+
say(`${answer === null ? "\n" : ""} ${c.muted("Cancelled: nothing written.")}`);
|
|
554
|
+
say();
|
|
555
|
+
return 0;
|
|
556
|
+
}
|
|
557
|
+
say();
|
|
558
|
+
}
|
|
559
|
+
applyPlan(target, payload, plan);
|
|
560
|
+
if (plan.update) {
|
|
561
|
+
item(c.nimbo("✔"), `${c.bold(`Nimbo updated to ${version}.`)} ${c.muted("Your project files are untouched.")}`);
|
|
562
|
+
if (plan.kept.length) item(c.you("!"), "Compare each .nimbo-new with your version and keep what you want.");
|
|
563
|
+
item(c.muted("→"), "Start a new Codex or Claude session to use it.");
|
|
564
|
+
} else {
|
|
565
|
+
item(c.nimbo("✔"), c.bold("Nimbo installed."));
|
|
566
|
+
item(c.muted("→"), "Open this folder in Claude Code or Codex and send any message.");
|
|
567
|
+
}
|
|
568
|
+
say();
|
|
569
|
+
return 0;
|
|
570
|
+
} catch (error) {
|
|
571
|
+
if (!(error instanceof InstallError) && typeof error?.code !== "string") throw error;
|
|
572
|
+
console.error(` ${e.red("✖")} ${error.message}`);
|
|
573
|
+
console.error();
|
|
574
|
+
return 1;
|
|
575
|
+
}
|
|
576
|
+
}
|