drawbore 0.1.0 → 0.1.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/bin/drawbore.js CHANGED
@@ -1,267 +1,335 @@
1
- #!/usr/bin/env node
2
-
3
- import path from "node:path";
4
- import {
5
- addInstruction,
6
- checkNotebook,
7
- createNotebook,
8
- findProjectRoot,
9
- fixMechanical,
10
- inspectProject,
11
- installMarkerFile,
12
- installSkills,
13
- loadPackageData,
14
- notebookDirectory,
15
- SkillConflictError,
16
- summarize,
17
- supportedLocations,
18
- writeInstallMarker,
19
- } from "../lib/index.js";
20
-
21
- const CHECK_FLAGS = new Set(["--json", "--strict", "--fix"]);
22
- const SUPPORTED_INSTRUCTIONS = new Set(["AGENTS.md", "CLAUDE.md"]);
23
-
24
- const args = process.argv.slice(2);
25
- const packageData = await loadPackageData();
26
- const command = args[0];
27
-
28
- if (args.includes("--help") || args.includes("-h")) {
29
- if (command === "check") printCheckHelp(packageData.version);
30
- else printHelp(packageData.version);
31
- process.exit(0);
32
- }
33
-
34
- if (args.includes("--version") || args.includes("-v")) {
35
- console.log(packageData.version);
36
- process.exit(0);
37
- }
38
-
39
- if (command === "check") {
40
- await runCheck(args.slice(1));
41
- } else if (command !== "init") {
42
- console.error("Usage: drawbore init | drawbore check");
43
- process.exit(2);
44
- } else {
45
- let plan;
46
- try {
47
- plan = parseExplicitOptions(args.slice(1), packageData);
48
- } catch (error) {
49
- console.error(error.message);
50
- printHelp(packageData.version);
51
- process.exit(2);
52
- }
53
-
54
- const root = await findProjectRoot();
55
- await inspectProject(root);
56
- const selectedLocations = plan?.locations ?? [".agents"];
57
- const createNotebookDirectory = plan?.notebook ?? true;
58
- const instructionTargets = plan?.instructions ?? [{ instructionFile: "AGENTS.md" }];
59
-
60
- try {
61
- console.log(`Drawbore ${packageData.version}`);
62
- console.log(`Project: ${root}`);
63
-
64
- const selection = plan?.skills ? { ...packageData, skills: plan.skills } : packageData;
65
- const preservedSkillFiles = [];
66
- const replacedSkillFiles = [];
67
- const skillHashes = {};
68
-
69
- for (const location of selectedLocations) {
70
- const result = await installSkills(root, location, selection, {
71
- replaceExisting: plan?.replaceSkills === true,
72
- force: plan?.force === true,
73
- });
74
- preservedSkillFiles.push(...result.preserved);
75
- replacedSkillFiles.push(...result.replaced);
76
- skillHashes[location] = result.hashes;
77
- }
78
-
79
- let notebookCreated = false;
80
- if (createNotebookDirectory) {
81
- await createNotebook(root);
82
- notebookCreated = true;
83
- }
84
-
85
- const instructionFiles = [];
86
- for (const target of instructionTargets) {
87
- await addInstruction(root, target.instructionFile, packageData);
88
- instructionFiles.push(target.instructionFile);
89
- }
90
-
91
- await writeInstallMarker(root, selection, selectedLocations, notebookCreated, [...new Set(instructionFiles)], skillHashes);
92
- console.log(formatInstallResult(selectedLocations, notebookCreated, instructionFiles, preservedSkillFiles, replacedSkillFiles));
93
- } catch (error) {
94
- if (error instanceof SkillConflictError) {
95
- console.error(error.message);
96
- process.exit(1);
97
- }
98
- throw error;
99
- }
100
- }
101
-
102
- function parseExplicitOptions(options, packageData) {
103
- if (options.length === 0) {
104
- return {
105
- locations: [".agents"],
106
- notebook: true,
107
- instructions: [{ instructionFile: "AGENTS.md" }],
108
- replaceSkills: false,
109
- force: false,
110
- skills: null,
111
- };
112
- }
113
-
114
- const locations = [];
115
- const instructions = [];
116
- let notebook = null;
117
- let replaceSkills = false;
118
- let force = false;
119
- let skills = null;
120
-
121
- for (let index = 0; index < options.length; index += 1) {
122
- const option = options[index];
123
- if (option === "--location") {
124
- const value = options[++index];
125
- if (value === undefined) throw new Error("Missing value for --location");
126
- for (const location of splitList(value)) {
127
- if (!supportedLocations[location]) throw new Error(`Unsupported location: ${location}`);
128
- locations.push(location);
129
- }
130
- } else if (option === "--notebook") {
131
- notebook = true;
132
- } else if (option === "--instruction") {
133
- const value = options[++index];
134
- if (value === undefined) throw new Error("Missing value for --instruction");
135
- for (const instructionFile of splitList(value)) {
136
- if (!SUPPORTED_INSTRUCTIONS.has(instructionFile)) throw new Error(`Unsupported instruction file: ${instructionFile}`);
137
- instructions.push({ instructionFile });
138
- }
139
- } else if (option === "--skills") {
140
- const value = options[++index];
141
- if (value === undefined) throw new Error("Missing value for --skills");
142
- const requested = splitList(value);
143
- const unknown = requested.filter((skill) => !packageData.skills.includes(skill));
144
- if (unknown.length > 0) throw new Error(`Unknown skill(s): ${unknown.join(", ")}`);
145
- skills = [...new Set(requested)];
146
- } else if (option === "--replace-skills") {
147
- replaceSkills = true;
148
- } else if (option === "--force") {
149
- force = true;
150
- } else if (option === "--yes") {
151
- // accepted for compatibility
152
- } else {
153
- throw new Error(`Unknown option: ${option}`);
154
- }
155
- }
156
-
157
- if (locations.length === 0) locations.push(".agents");
158
- if (notebook === null) notebook = true;
159
- if (instructions.length === 0) {
160
- for (const instructionFile of new Set(locations.map((location) => supportedLocations[location]))) {
161
- instructions.push({ instructionFile });
162
- }
163
- }
164
-
165
- return {
166
- locations: [...new Set(locations)],
167
- notebook,
168
- replaceSkills,
169
- force,
170
- skills,
171
- instructions: [...new Map(instructions.map((target) => [target.instructionFile, target])).values()],
172
- };
173
- }
174
-
175
- function splitList(value) {
176
- return value.split(",").map((item) => item.trim()).filter(Boolean);
177
- }
178
-
179
- async function runCheck(options) {
180
- for (const option of options) {
181
- if (!CHECK_FLAGS.has(option)) {
182
- console.error(`Unknown option for check: ${option}`);
183
- process.exit(2);
184
- }
185
- }
186
-
187
- const json = options.includes("--json");
188
- const strict = options.includes("--strict");
189
- const fix = options.includes("--fix");
190
- const root = await findProjectRoot();
191
- const notebookDir = path.join(root, notebookDirectory);
192
-
193
- if (fix) {
194
- const { fixed } = await fixMechanical(notebookDir);
195
- if (json) {
196
- console.log(JSON.stringify({ fixed, changed: fixed.length > 0 }, null, 2));
197
- } else if (fixed.length === 0) {
198
- console.log("Nothing to fix.");
199
- } else {
200
- for (const item of fixed) {
201
- console.log(`fixed ${item.code} ${item.file}: ${item.message}`);
202
- }
203
- }
204
- }
205
-
206
- const findings = await checkNotebook(notebookDir);
207
- const summary = summarize(findings);
208
-
209
- if (json) {
210
- console.log(JSON.stringify({
211
- ok: summary.ok,
212
- errors: summary.errors,
213
- warnings: summary.warnings,
214
- stale: summary.stale,
215
- }, null, 2));
216
- } else if (findings.length === 0) {
217
- console.log("No structural issues found.");
218
- } else {
219
- for (const finding of findings) {
220
- const where = finding.file ? ` (${finding.file})` : "";
221
- const tag = finding.code.startsWith("S") ? "review" : finding.code.startsWith("W") ? "warn" : "error";
222
- console.log(`${finding.code} [${tag}]${where}: ${finding.message}`);
223
- }
224
- }
225
-
226
- const failed = !summary.ok || (strict && summary.warnings.length > 0);
227
- process.exit(failed ? 1 : 0);
228
- }
229
-
230
- function formatInstallResult(locations, notebookCreated, instructionFiles, preservedSkillFiles, replacedSkillFiles) {
231
- const lines = ["", "Installed:"];
232
- for (const location of locations) lines.push(`- skills: ${location}/skills/`);
233
- if (notebookCreated) lines.push(`- record: ${notebookDirectory}/`);
234
- for (const file of instructionFiles) lines.push(`- instruction: ${file}`);
235
- lines.push(`- marker: ${installMarkerFile}`);
236
- if (preservedSkillFiles.length > 0) lines.push("", `Preserved ${preservedSkillFiles.length} file(s).`);
237
- if (replacedSkillFiles.length > 0) lines.push(`Replaced ${replacedSkillFiles.length} file(s).`);
238
- lines.push("", "Run the discover skill in your agent to propose the first durable records.");
239
- return lines.join("\n");
240
- }
241
-
242
- function printCheckHelp(version) {
243
- console.log(`Drawbore ${version}\n\nUsage:\n drawbore check [--json] [--strict] [--fix]`);
244
- }
245
-
246
- function printHelp(version) {
247
- console.log(`Drawbore ${version}
248
-
249
- Usage:
250
- drawbore init [options]
251
- drawbore check [--json] [--strict] [--fix]
252
- drawbore --version
253
- drawbore --help
254
-
255
- init options:
256
- --location <dir> Harness location to install into (repeatable).
257
- One of: .agents, .claude, .codex, .cursor, .omp, .opencode.
258
- --notebook Create or refresh the .drawbore templates.
259
- --instruction <file> Add the Drawbore block to an instruction file (repeatable).
260
- One of: AGENTS.md, CLAUDE.md.
261
- --skills <list> Comma-separated subset of skills to install.
262
- --replace-skills Replace installed skill files that differ.
263
- --force Replace skills owned by another package.
264
- --yes Accept defaults without prompting.
265
-
266
- Drawbore is provider-neutral: it does not assume a forge, registry, or CI provider.`);
1
+ #!/usr/bin/env node
2
+
3
+ import path from "node:path";
4
+ import {
5
+ addInstruction,
6
+ buildInstructionChoices,
7
+ buildLocationChoices,
8
+ checkNotebook,
9
+ createNotebook,
10
+ createUi,
11
+ findProjectRoot,
12
+ fixMechanical,
13
+ inspectProject,
14
+ installMarkerFile,
15
+ installSkills,
16
+ loadPackageData,
17
+ notebookDirectory,
18
+ SkillConflictError,
19
+ summarize,
20
+ supportedLocations,
21
+ writeInstallMarker,
22
+ } from "../lib/index.js";
23
+
24
+ const CHECK_FLAGS = new Set(["--json", "--strict", "--fix"]);
25
+ const SUPPORTED_INSTRUCTIONS = new Set(["AGENTS.md", "CLAUDE.md"]);
26
+
27
+ const args = process.argv.slice(2);
28
+ const packageData = await loadPackageData();
29
+ const command = args[0];
30
+
31
+ if (args.includes("--help") || args.includes("-h")) {
32
+ if (command === "check") printCheckHelp(packageData.version);
33
+ else printHelp(packageData.version);
34
+ process.exit(0);
35
+ }
36
+
37
+ if (args.includes("--version") || args.includes("-v")) {
38
+ console.log(packageData.version);
39
+ process.exit(0);
40
+ }
41
+
42
+ if (command === "check") {
43
+ await runCheck(args.slice(1));
44
+ } else if (command !== "init") {
45
+ console.error("Usage: drawbore init | drawbore check");
46
+ process.exit(2);
47
+ } else {
48
+ let plan;
49
+ try {
50
+ plan = parseExplicitOptions(args.slice(1), packageData);
51
+ } catch (error) {
52
+ console.error(error.message);
53
+ printHelp(packageData.version);
54
+ process.exit(2);
55
+ }
56
+ const root = await findProjectRoot();
57
+ const inspection = await inspectProject(root);
58
+ const ui = createUi();
59
+
60
+ // No flags + non-interactive (pipe, CI, test): use the defaults rather than
61
+ // prompting on a stream nobody is reading. The prompts layer itself falls
62
+ // back to readline, which would block forever on a closed stdin.
63
+ if (!plan && !ui.isInteractive) {
64
+ plan = {
65
+ locations: [".agents"],
66
+ notebook: true,
67
+ instructions: [{ instructionFile: "AGENTS.md" }],
68
+ replaceSkills: false,
69
+ force: false,
70
+ skills: null,
71
+ };
72
+ }
73
+
74
+
75
+ try {
76
+ console.log(`Drawbore ${packageData.version}`);
77
+ console.log(`Project: ${root}`);
78
+
79
+ if (!plan) ui.renderProjectState(inspection);
80
+
81
+ const selectedLocations = plan?.locations ?? await pickLocations(inspection, ui);
82
+ if (selectedLocations.length === 0) {
83
+ console.log("No harness locations selected. Nothing was installed.");
84
+ process.exit(0);
85
+ }
86
+
87
+ const createNotebookDirectory = plan?.notebook ?? await pickNotebook(ui, inspection);
88
+ const instructionTargets = plan?.instructions ?? await pickInstructions(selectedLocations, inspection, ui);
89
+
90
+ if (!plan && !(await ui.confirm({ message: "Install Drawbore with these choices?", defaultValue: true }))) {
91
+ console.log("Installation cancelled. Nothing was installed.");
92
+ process.exit(0);
93
+ }
94
+
95
+ const selection = plan?.skills ? { ...packageData, skills: plan.skills } : packageData;
96
+ const preservedSkillFiles = [];
97
+ const replacedSkillFiles = [];
98
+ const skillHashes = {};
99
+
100
+ for (const location of selectedLocations) {
101
+ const result = await installSkills(root, location, selection, {
102
+ replaceExisting: plan?.replaceSkills === true,
103
+ force: plan?.force === true,
104
+ });
105
+ preservedSkillFiles.push(...result.preserved);
106
+ replacedSkillFiles.push(...result.replaced);
107
+ skillHashes[location] = result.hashes;
108
+ }
109
+
110
+ let notebookCreated = false;
111
+ if (createNotebookDirectory) {
112
+ await createNotebook(root);
113
+ notebookCreated = true;
114
+ }
115
+
116
+ const instructionFiles = [];
117
+ for (const target of instructionTargets) {
118
+ await addInstruction(root, target.instructionFile, packageData);
119
+ instructionFiles.push(target.instructionFile);
120
+ }
121
+
122
+ await writeInstallMarker(root, selection, selectedLocations, notebookCreated, [...new Set(instructionFiles)], skillHashes);
123
+ console.log(formatInstallResult(selectedLocations, notebookCreated, instructionFiles, preservedSkillFiles, replacedSkillFiles));
124
+ } catch (error) {
125
+ if (error instanceof SkillConflictError) {
126
+ console.error(error.message);
127
+ process.exit(1);
128
+ }
129
+ throw error;
130
+ } finally {
131
+ ui.close();
132
+ }
133
+ }
134
+
135
+ function parseExplicitOptions(options, packageData) {
136
+ if (options.length === 0) {
137
+ return undefined;
138
+ }
139
+
140
+ const locations = [];
141
+ const instructions = [];
142
+ let notebook = null;
143
+ let replaceSkills = false;
144
+ let force = false;
145
+ let skills = null;
146
+
147
+ for (let index = 0; index < options.length; index += 1) {
148
+ const option = options[index];
149
+ if (option === "--location") {
150
+ const value = options[++index];
151
+ if (value === undefined) throw new Error("Missing value for --location");
152
+ for (const location of splitList(value)) {
153
+ if (!supportedLocations[location]) throw new Error(`Unsupported location: ${location}`);
154
+ locations.push(location);
155
+ }
156
+ } else if (option === "--notebook") {
157
+ notebook = true;
158
+ } else if (option === "--instruction") {
159
+ const value = options[++index];
160
+ if (value === undefined) throw new Error("Missing value for --instruction");
161
+ for (const instructionFile of splitList(value)) {
162
+ if (!SUPPORTED_INSTRUCTIONS.has(instructionFile)) throw new Error(`Unsupported instruction file: ${instructionFile}`);
163
+ instructions.push({ instructionFile });
164
+ }
165
+ } else if (option === "--skills") {
166
+ const value = options[++index];
167
+ if (value === undefined) throw new Error("Missing value for --skills");
168
+ const requested = splitList(value);
169
+ const unknown = requested.filter((skill) => !packageData.skills.includes(skill));
170
+ if (unknown.length > 0) throw new Error(`Unknown skill(s): ${unknown.join(", ")}`);
171
+ skills = [...new Set(requested)];
172
+ } else if (option === "--replace-skills") {
173
+ replaceSkills = true;
174
+ } else if (option === "--force") {
175
+ force = true;
176
+ } else if (option === "--yes") {
177
+ // accepted for compatibility
178
+ } else {
179
+ throw new Error(`Unknown option: ${option}`);
180
+ }
181
+ }
182
+
183
+ if (locations.length === 0) locations.push(".agents");
184
+ if (notebook === null) notebook = true;
185
+ if (instructions.length === 0) {
186
+ for (const instructionFile of new Set(locations.map((location) => supportedLocations[location]))) {
187
+ instructions.push({ instructionFile });
188
+ }
189
+ }
190
+
191
+ return {
192
+ locations: [...new Set(locations)],
193
+ notebook,
194
+ replaceSkills,
195
+ force,
196
+ skills,
197
+ instructions: [...new Map(instructions.map((target) => [target.instructionFile, target])).values()],
198
+ };
199
+ }
200
+
201
+ async function pickLocations(inspection, ui) {
202
+ const choices = buildLocationChoices(inspection);
203
+ const selected = await ui.selectLocations(choices);
204
+ return validateSelectedLocations(selected);
205
+ }
206
+
207
+ async function pickNotebook(ui, inspection) {
208
+ const message = inspection.notebookExists
209
+ ? `Create or refresh the ${notebookDirectory} templates? Existing files will be preserved.`
210
+ : `Create ${notebookDirectory} with starter records?`;
211
+ return ui.confirm({ message, defaultValue: true });
212
+ }
213
+
214
+ async function pickInstructions(selectedLocations, inspection, ui) {
215
+ const targets = [...new Set(selectedLocations.map((location) => supportedLocations[location]))].map(
216
+ (instructionFile) => ({
217
+ instructionFile,
218
+ exists: inspection.locations.some((entry) => entry.instructionName === instructionFile && entry.instructionExists),
219
+ }),
220
+ );
221
+ const choices = buildInstructionChoices(targets);
222
+ const picked = await ui.selectInstructions(choices);
223
+
224
+ const invalid = picked.filter((value) => !targets.some((target) => target.instructionFile === value));
225
+ if (invalid.length > 0) {
226
+ throw new Error(`Unsupported instruction file(s): ${invalid.join(", ")}`);
227
+ }
228
+
229
+ return picked.map((instructionFile) => ({ instructionFile }));
230
+ }
231
+
232
+ function validateSelectedLocations(selected) {
233
+ if (!selected || selected.length === 0) {
234
+ return [];
235
+ }
236
+ const invalid = selected.filter((location) => !(location in supportedLocations));
237
+ if (invalid.length > 0) {
238
+ throw new Error(`Unsupported location(s): ${invalid.join(", ")}`);
239
+ }
240
+ return [...new Set(selected)];
241
+ }
242
+
243
+ function splitList(value) {
244
+ return value.split(",").map((item) => item.trim()).filter(Boolean);
245
+ }
246
+
247
+ async function runCheck(options) {
248
+ for (const option of options) {
249
+ if (!CHECK_FLAGS.has(option)) {
250
+ console.error(`Unknown option for check: ${option}`);
251
+ process.exit(2);
252
+ }
253
+ }
254
+
255
+ const json = options.includes("--json");
256
+ const strict = options.includes("--strict");
257
+ const fix = options.includes("--fix");
258
+ const root = await findProjectRoot();
259
+ const notebookDir = path.join(root, notebookDirectory);
260
+
261
+ if (fix) {
262
+ const { fixed } = await fixMechanical(notebookDir);
263
+ if (json) {
264
+ console.log(JSON.stringify({ fixed, changed: fixed.length > 0 }, null, 2));
265
+ } else if (fixed.length === 0) {
266
+ console.log("Nothing to fix.");
267
+ } else {
268
+ for (const item of fixed) {
269
+ console.log(`fixed ${item.code} ${item.file}: ${item.message}`);
270
+ }
271
+ }
272
+ }
273
+
274
+ const findings = await checkNotebook(notebookDir);
275
+ const summary = summarize(findings);
276
+
277
+ if (json) {
278
+ console.log(JSON.stringify({
279
+ ok: summary.ok,
280
+ errors: summary.errors,
281
+ warnings: summary.warnings,
282
+ stale: summary.stale,
283
+ }, null, 2));
284
+ } else if (findings.length === 0) {
285
+ console.log("No structural issues found.");
286
+ } else {
287
+ for (const finding of findings) {
288
+ const where = finding.file ? ` (${finding.file})` : "";
289
+ const tag = finding.code.startsWith("S") ? "review" : finding.code.startsWith("W") ? "warn" : "error";
290
+ console.log(`${finding.code} [${tag}]${where}: ${finding.message}`);
291
+ }
292
+ }
293
+
294
+ const failed = !summary.ok || (strict && summary.warnings.length > 0);
295
+ process.exit(failed ? 1 : 0);
296
+ }
297
+
298
+ function formatInstallResult(locations, notebookCreated, instructionFiles, preservedSkillFiles, replacedSkillFiles) {
299
+ const lines = ["", "Installed:"];
300
+ for (const location of locations) lines.push(`- skills: ${location}/skills/`);
301
+ if (notebookCreated) lines.push(`- record: ${notebookDirectory}/`);
302
+ for (const file of instructionFiles) lines.push(`- instruction: ${file}`);
303
+ lines.push(`- marker: ${installMarkerFile}`);
304
+ if (preservedSkillFiles.length > 0) lines.push("", `Preserved ${preservedSkillFiles.length} file(s).`);
305
+ if (replacedSkillFiles.length > 0) lines.push(`Replaced ${replacedSkillFiles.length} file(s).`);
306
+ lines.push("", "Run the discover skill in your agent to propose the first durable records.");
307
+ return lines.join("\n");
308
+ }
309
+
310
+ function printCheckHelp(version) {
311
+ console.log(`Drawbore ${version}\n\nUsage:\n drawbore check [--json] [--strict] [--fix]`);
312
+ }
313
+
314
+ function printHelp(version) {
315
+ console.log(`Drawbore ${version}
316
+
317
+ Usage:
318
+ drawbore init [options]
319
+ drawbore check [--json] [--strict] [--fix]
320
+ drawbore --version
321
+ drawbore --help
322
+
323
+ init options:
324
+ --location <dir> Harness location to install into (repeatable).
325
+ One of: .agents, .claude, .codex, .cursor, .omp, .opencode.
326
+ --notebook Create or refresh the .drawbore templates.
327
+ --instruction <file> Add the Drawbore block to an instruction file (repeatable).
328
+ One of: AGENTS.md, CLAUDE.md.
329
+ --skills <list> Comma-separated subset of skills to install.
330
+ --replace-skills Replace installed skill files that differ.
331
+ --force Replace skills owned by another package.
332
+ --yes Accept defaults without prompting.
333
+
334
+ Drawbore is provider-neutral: it does not assume a forge, registry, or CI provider.`);
267
335
  }