@notchlet/cli 0.0.0-stage → 0.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/auth.js +380 -0
- package/dist/cli-format.js +46 -0
- package/dist/cli-prompt.js +73 -0
- package/dist/cli.js +1040 -0
- package/dist/guidance-install.js +111 -0
- package/dist/integration.js +806 -0
- package/dist/setup.js +92 -0
- package/guidance/aliases.json +27 -0
- package/guidance/generated/claude-code/notchlet-deliver/SKILL.md +94 -0
- package/guidance/generated/claude-code/notchlet-implement/SKILL.md +94 -0
- package/guidance/generated/claude-code/notchlet-init/SKILL.md +30 -0
- package/guidance/generated/claude-code/notchlet-mcp/SKILL.md +60 -0
- package/guidance/generated/claude-code/notchlet-plan/SKILL.md +100 -0
- package/guidance/generated/claude-code/notchlet-platform/SKILL.md +85 -0
- package/guidance/generated/claude-code/notchlet-review/SKILL.md +68 -0
- package/guidance/generated/claude-code/notchlet-super/SKILL.md +47 -0
- package/guidance/generated/compatibility.json +94 -0
- package/guidance/generated/manifest.json +140 -0
- package/guidance/generated/opencode/notchlet-deliver/SKILL.md +94 -0
- package/guidance/generated/opencode/notchlet-implement/SKILL.md +94 -0
- package/guidance/generated/opencode/notchlet-init/SKILL.md +30 -0
- package/guidance/generated/opencode/notchlet-mcp/SKILL.md +60 -0
- package/guidance/generated/opencode/notchlet-plan/SKILL.md +100 -0
- package/guidance/generated/opencode/notchlet-platform/SKILL.md +85 -0
- package/guidance/generated/opencode/notchlet-review/SKILL.md +68 -0
- package/guidance/generated/opencode/notchlet-super/SKILL.md +47 -0
- package/package.json +1 -6
- package/scripts/generate-guidance.mjs +115 -0
- package/README.md +0 -3
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
+
import { lstat, mkdir, readFile, rename, rm, writeFile, readdir } from 'node:fs/promises';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
const hash = (value) => createHash('sha256').update(value).digest('hex');
|
|
6
|
+
const packageRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
7
|
+
const generatedDir = (client) => path.join(packageRoot, 'guidance', 'generated', client === 'claude' ? 'claude-code' : 'opencode');
|
|
8
|
+
const targetFor = (client, skill) => client === 'opencode'
|
|
9
|
+
? `.opencode/skills/${skill}/SKILL.md`
|
|
10
|
+
: `.claude/skills/${skill}/SKILL.md`;
|
|
11
|
+
async function lstatOrNull(file) {
|
|
12
|
+
try {
|
|
13
|
+
return await lstat(file);
|
|
14
|
+
}
|
|
15
|
+
catch (error) {
|
|
16
|
+
if (error.code === 'ENOENT')
|
|
17
|
+
return null;
|
|
18
|
+
throw error;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
async function assertSafeParents(root, relative) {
|
|
22
|
+
let current = root;
|
|
23
|
+
for (const segment of path.dirname(relative).split(path.sep).filter(Boolean)) {
|
|
24
|
+
current = path.join(current, segment);
|
|
25
|
+
const stat = await lstatOrNull(current);
|
|
26
|
+
if (stat?.isSymbolicLink() || (stat && !stat.isDirectory()))
|
|
27
|
+
throw new Error(`Guidance target traverses a non-directory or symlink: ${relative}`);
|
|
28
|
+
}
|
|
29
|
+
const target = await lstatOrNull(path.join(root, relative));
|
|
30
|
+
if (target?.isSymbolicLink() || (target && !target.isFile()))
|
|
31
|
+
throw new Error(`Guidance target is not a regular file: ${relative}`);
|
|
32
|
+
return target;
|
|
33
|
+
}
|
|
34
|
+
async function readManifest(file) {
|
|
35
|
+
const stat = await lstatOrNull(file);
|
|
36
|
+
if (!stat)
|
|
37
|
+
return { manifestVersion: 1, clients: {}, skills: {} };
|
|
38
|
+
if (stat.isSymbolicLink() || !stat.isFile())
|
|
39
|
+
throw new Error('Client guidance manifest is not a regular file.');
|
|
40
|
+
const parsed = JSON.parse(await readFile(file, 'utf8'));
|
|
41
|
+
if (parsed?.manifestVersion !== 1)
|
|
42
|
+
throw new Error('Client guidance manifest is invalid; preserve it and reconcile manually.');
|
|
43
|
+
return parsed;
|
|
44
|
+
}
|
|
45
|
+
async function atomicWrite(file, contents) {
|
|
46
|
+
await mkdir(path.dirname(file), { recursive: true });
|
|
47
|
+
const temporary = `${file}.${randomUUID()}.tmp`;
|
|
48
|
+
await writeFile(temporary, contents, { flag: 'wx' });
|
|
49
|
+
await rename(temporary, file).catch(async (error) => { await rm(temporary, { force: true }); throw error; });
|
|
50
|
+
}
|
|
51
|
+
export async function installClientGuidance(rootInput, client, options = {}) {
|
|
52
|
+
if (!['opencode', 'claude'].includes(client))
|
|
53
|
+
throw new Error('Client must be opencode or claude.');
|
|
54
|
+
const root = path.resolve(rootInput);
|
|
55
|
+
const genDir = generatedDir(client);
|
|
56
|
+
const genStat = await lstatOrNull(genDir);
|
|
57
|
+
if (!genStat?.isDirectory())
|
|
58
|
+
throw new Error(`Generated guidance not found for ${client}; run \`npm run guidance:generate\` first.`);
|
|
59
|
+
const skillNames = await readdir(genDir);
|
|
60
|
+
const manifestRelative = path.join('.notchlet', '.local', 'client-guidance.json');
|
|
61
|
+
await assertSafeParents(root, manifestRelative);
|
|
62
|
+
const manifestPath = path.join(root, manifestRelative);
|
|
63
|
+
const manifest = await readManifest(manifestPath);
|
|
64
|
+
const skillsInstalled = manifest.clients[client] ?? {};
|
|
65
|
+
const results = [];
|
|
66
|
+
for (const skill of skillNames) {
|
|
67
|
+
const sourceFile = path.join(genDir, skill, 'SKILL.md');
|
|
68
|
+
const sourceStat = await lstatOrNull(sourceFile);
|
|
69
|
+
if (!sourceStat?.isFile())
|
|
70
|
+
continue;
|
|
71
|
+
const source = await readFile(sourceFile, 'utf8');
|
|
72
|
+
const sourceHash = hash(source);
|
|
73
|
+
const target = targetFor(client, skill);
|
|
74
|
+
const previous = skillsInstalled[skill];
|
|
75
|
+
const currentStat = await assertSafeParents(root, target);
|
|
76
|
+
const current = currentStat ? await readFile(path.join(root, target), 'utf8') : null;
|
|
77
|
+
const currentHash = current === null ? null : hash(current);
|
|
78
|
+
let action;
|
|
79
|
+
let reason;
|
|
80
|
+
if (current === null)
|
|
81
|
+
action = 'install';
|
|
82
|
+
else if (!previous || previous.target !== target) {
|
|
83
|
+
action = 'conflict';
|
|
84
|
+
reason = 'An unmanaged file already exists at the target path.';
|
|
85
|
+
}
|
|
86
|
+
else if (currentHash !== previous.installedHash) {
|
|
87
|
+
action = 'conflict';
|
|
88
|
+
reason = 'The managed guidance file was modified locally; local content is preserved.';
|
|
89
|
+
}
|
|
90
|
+
else if (currentHash === sourceHash)
|
|
91
|
+
action = 'unchanged';
|
|
92
|
+
else
|
|
93
|
+
action = 'update';
|
|
94
|
+
const result = { skill, target, action, sourceHash, ...(reason ? { reason } : {}), applied: false };
|
|
95
|
+
if (!options.apply || action === 'conflict' || action === 'unchanged') {
|
|
96
|
+
results.push(result);
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
await atomicWrite(path.join(root, target), source);
|
|
100
|
+
skillsInstalled[skill] = { target, sourceHash, installedHash: sourceHash, sourceVersion: JSON.parse(await readFile(path.join(packageRoot, 'package.json'), 'utf8')).version };
|
|
101
|
+
results.push({ ...result, applied: true });
|
|
102
|
+
}
|
|
103
|
+
manifest.clients[client] = skillsInstalled;
|
|
104
|
+
await atomicWrite(manifestPath, `${JSON.stringify(manifest, null, 2)}\n`);
|
|
105
|
+
const anyApplied = results.some(r => r.applied);
|
|
106
|
+
const hasConflict = results.some(r => r.action === 'conflict');
|
|
107
|
+
const hasUpdate = results.some(r => r.action === 'update');
|
|
108
|
+
const hasUnchanged = results.every(r => r.action === 'unchanged');
|
|
109
|
+
const aggregateAction = hasConflict ? 'conflict' : hasUpdate ? 'update' : hasUnchanged ? 'unchanged' : 'install';
|
|
110
|
+
return { client, action: aggregateAction, applied: anyApplied, results };
|
|
111
|
+
}
|