@nusoft/nuos-build-catalogue 0.10.1 → 0.11.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/cli.js CHANGED
@@ -12,20 +12,22 @@
12
12
  */
13
13
  import path from 'node:path';
14
14
  import { fileURLToPath } from 'node:url';
15
- import { selectEmbedderFromEnv } from './embedder/select.js';
16
- import { openStore } from './store/open.js';
17
- import { runIndex } from './indexer/upsert.js';
18
- import { runSearch } from './search/query.js';
19
- import { formatHumanReadable, formatJson } from './search/format.js';
15
+ // Static imports these don't pull in NuVector / NuFlow transitively.
16
+ // init / migrate / regenerate / summary / list / show / install-protocols all
17
+ // work without those native deps being installed.
20
18
  import { runMigrate } from './migrate/run.js';
21
19
  import { openWorkflowStore } from './migrate/store.js';
22
20
  import { listRegister, showRecord, commandToRegister, listAcrossRegisters, } from './commands/handlers.js';
23
21
  import { runRegenerate } from './regenerate/check.js';
24
- import { createBuildCatalogueRuntime } from './runtime/runtime.js';
25
- import { cmdWuAdvance, cmdWuTick, cmdDecisionSupersede, cmdQuestionResolve, } from './commands/write.js';
26
- import { cmdWuCreate, cmdDecisionCreate, cmdQuestionCreate, cmdPersonaCreate, } from './commands/create.js';
27
22
  import { openPrompt } from './commands/prompt.js';
28
23
  import { cmdInit, cmdInstallProtocols } from './commands/init.js';
24
+ // Dynamic imports below — index / search / write commands / create commands
25
+ // load NuVector or NuFlow transitively. Loading them at module-parse time
26
+ // would crash on platforms where the NuVector native binary isn't resolved
27
+ // (e.g. fresh npx installs before @nusoft/nuvector ships its platform-specific
28
+ // binaries as optionalDependencies). Lazy-load so the lightweight commands
29
+ // (init, migrate, etc.) work universally; the heavyweight commands degrade
30
+ // gracefully when their deps are missing.
29
31
  const __filename = fileURLToPath(import.meta.url);
30
32
  const PACKAGE_ROOT = path.resolve(path.dirname(__filename), '..');
31
33
  // Defaults resolve in this order: env var > flag-supplied > package-relative
@@ -65,6 +67,9 @@ async function cmdIndex(flags) {
65
67
  const catalogueRoot = String(flags['catalogue'] ?? DEFAULT_CATALOGUE_ROOT);
66
68
  const indexPath = String(flags['index'] ?? DEFAULT_INDEX_PATH);
67
69
  const hashPath = String(flags['hash-file'] ?? DEFAULT_HASH_PATH);
70
+ const { selectEmbedderFromEnv } = await import('./embedder/select.js');
71
+ const { openStore } = await import('./store/open.js');
72
+ const { runIndex } = await import('./indexer/upsert.js');
68
73
  const embedder = await selectEmbedderFromEnv();
69
74
  const store = await openStore({ storagePath: indexPath, dimensions: embedder.dimensions });
70
75
  console.log(`indexing ${catalogueRoot}`);
@@ -95,6 +100,10 @@ async function cmdSearch(positional, flags) {
95
100
  process.exit(2);
96
101
  }
97
102
  const indexPath = String(flags['index'] ?? DEFAULT_INDEX_PATH);
103
+ const { selectEmbedderFromEnv } = await import('./embedder/select.js');
104
+ const { openStore } = await import('./store/open.js');
105
+ const { runSearch } = await import('./search/query.js');
106
+ const { formatHumanReadable, formatJson } = await import('./search/format.js');
98
107
  const embedder = await selectEmbedderFromEnv();
99
108
  const store = await openStore({ storagePath: indexPath, dimensions: embedder.dimensions });
100
109
  const limit = flags['limit'] ? Number(flags['limit']) : 10;
@@ -190,6 +199,8 @@ async function cmdRegisterDispatch(command, positional, flags) {
190
199
  console.error(`'advance' is a wu subcommand only`);
191
200
  process.exit(2);
192
201
  }
202
+ const { createBuildCatalogueRuntime } = await import('./runtime/runtime.js');
203
+ const { cmdWuAdvance } = await import('./commands/write.js');
193
204
  const runtime = createBuildCatalogueRuntime({ store, catalogueRoot: buildRoot });
194
205
  const result = await cmdWuAdvance(store, runtime, {
195
206
  handle: positional[1],
@@ -205,6 +216,8 @@ async function cmdRegisterDispatch(command, positional, flags) {
205
216
  console.error(`'tick' is a wu subcommand only`);
206
217
  process.exit(2);
207
218
  }
219
+ const { createBuildCatalogueRuntime } = await import('./runtime/runtime.js');
220
+ const { cmdWuTick } = await import('./commands/write.js');
208
221
  const runtime = createBuildCatalogueRuntime({ store, catalogueRoot: buildRoot });
209
222
  const result = await cmdWuTick(store, runtime, {
210
223
  handle: positional[1],
@@ -220,6 +233,8 @@ async function cmdRegisterDispatch(command, positional, flags) {
220
233
  console.error(`'supersede' is a decision subcommand only`);
221
234
  process.exit(2);
222
235
  }
236
+ const { createBuildCatalogueRuntime } = await import('./runtime/runtime.js');
237
+ const { cmdDecisionSupersede } = await import('./commands/write.js');
223
238
  const runtime = createBuildCatalogueRuntime({ store, catalogueRoot: buildRoot });
224
239
  const result = await cmdDecisionSupersede(store, runtime, {
225
240
  target: positional[1],
@@ -235,6 +250,8 @@ async function cmdRegisterDispatch(command, positional, flags) {
235
250
  console.error(`'resolve' is a question subcommand only`);
236
251
  process.exit(2);
237
252
  }
253
+ const { createBuildCatalogueRuntime } = await import('./runtime/runtime.js');
254
+ const { cmdQuestionResolve } = await import('./commands/write.js');
238
255
  const runtime = createBuildCatalogueRuntime({ store, catalogueRoot: buildRoot });
239
256
  const result = await cmdQuestionResolve(store, runtime, {
240
257
  qHandle: positional[1],
@@ -246,6 +263,8 @@ async function cmdRegisterDispatch(command, positional, flags) {
246
263
  break;
247
264
  }
248
265
  case 'create': {
266
+ const { createBuildCatalogueRuntime } = await import('./runtime/runtime.js');
267
+ const { cmdWuCreate, cmdDecisionCreate, cmdQuestionCreate, cmdPersonaCreate, } = await import('./commands/create.js');
249
268
  const runtime = createBuildCatalogueRuntime({ store, catalogueRoot: buildRoot });
250
269
  const prompt = openPrompt();
251
270
  try {
@@ -5,8 +5,15 @@
5
5
  * 1. mkdir docs/build/ + copy starter-kit content
6
6
  * 2. Substitute {{PROJECT_NAME}} / {{PROJECT_TAGLINE}} / {{TODAY}} in
7
7
  * STATE.md and methodfile.json
8
- * 3. Copy the four protocols into .claude/commands/ (preserving
9
- * existing files)
8
+ * 3. Fan the four protocols out to ALL THREE supported AI coding tools:
9
+ * Claude Code (.claude/commands/<n>.md), OpenCode
10
+ * (.opencode/commands/<n>.md), and Codex CLI
11
+ * (.agents/skills/<n>/SKILL.md). Each tool reads commands from a
12
+ * different path with slightly different frontmatter; the body is
13
+ * identical across all three. We write to all three by default — the
14
+ * files are tiny and harmless if a tool is unused. A consumer of
15
+ * this catalogue on any of the three tools gets working slash
16
+ * commands without extra configuration.
10
17
  * 4. Append a "Build catalogue (NuOS Build Method)" section to
11
18
  * CLAUDE.md (creating it if missing; preserving existing content)
12
19
  * 5. Update .gitignore: !docs/build/ override (if `build/` is present
@@ -16,7 +23,8 @@
16
23
  * 6. Run a first migrate to verify
17
24
  *
18
25
  * Companion command: `install-protocols` refreshes just step 3 from the
19
- * canonical bodies bundled in this CLI package.
26
+ * canonical bodies bundled in this CLI package, also fanning out to all
27
+ * three tool paths.
20
28
  */
21
29
  import type { Prompt } from './prompt.js';
22
30
  export interface InitOptions {
@@ -5,8 +5,15 @@
5
5
  * 1. mkdir docs/build/ + copy starter-kit content
6
6
  * 2. Substitute {{PROJECT_NAME}} / {{PROJECT_TAGLINE}} / {{TODAY}} in
7
7
  * STATE.md and methodfile.json
8
- * 3. Copy the four protocols into .claude/commands/ (preserving
9
- * existing files)
8
+ * 3. Fan the four protocols out to ALL THREE supported AI coding tools:
9
+ * Claude Code (.claude/commands/<n>.md), OpenCode
10
+ * (.opencode/commands/<n>.md), and Codex CLI
11
+ * (.agents/skills/<n>/SKILL.md). Each tool reads commands from a
12
+ * different path with slightly different frontmatter; the body is
13
+ * identical across all three. We write to all three by default — the
14
+ * files are tiny and harmless if a tool is unused. A consumer of
15
+ * this catalogue on any of the three tools gets working slash
16
+ * commands without extra configuration.
10
17
  * 4. Append a "Build catalogue (NuOS Build Method)" section to
11
18
  * CLAUDE.md (creating it if missing; preserving existing content)
12
19
  * 5. Update .gitignore: !docs/build/ override (if `build/` is present
@@ -16,9 +23,10 @@
16
23
  * 6. Run a first migrate to verify
17
24
  *
18
25
  * Companion command: `install-protocols` refreshes just step 3 from the
19
- * canonical bodies bundled in this CLI package.
26
+ * canonical bodies bundled in this CLI package, also fanning out to all
27
+ * three tool paths.
20
28
  */
21
- import { mkdir, readFile, writeFile, copyFile, readdir, access } from 'node:fs/promises';
29
+ import { mkdir, readFile, writeFile, readdir, access } from 'node:fs/promises';
22
30
  import { existsSync, constants } from 'node:fs';
23
31
  import path from 'node:path';
24
32
  import { fileURLToPath } from 'node:url';
@@ -32,6 +40,41 @@ const PROTOCOL_FILES = [
32
40
  'wu-new.md',
33
41
  'persona-new.md',
34
42
  ];
43
+ /**
44
+ * One-line descriptions used in the frontmatter of installed protocol
45
+ * files. Tools surface this text in their command list, so it should
46
+ * read as an imperative summary.
47
+ */
48
+ const PROTOCOL_DESCRIPTIONS = {
49
+ 'start-of-session': 'Read STATE, last session log, active WU; surface next action',
50
+ 'end-of-session': 'Write session log, update STATE + indices, move ✅ WUs to done/, commit',
51
+ 'wu-new': 'Create a new work unit with the six-field outcome shape (per D046)',
52
+ 'persona-new': 'Create a new P-NNN persona with the seven dimensions and acid-test (per D046)',
53
+ };
54
+ const TOOLS = {
55
+ claude: {
56
+ label: 'Claude Code',
57
+ destPath: (slug) => path.join('.claude', 'commands', `${slug}.md`),
58
+ render: (slug, body) => withFrontmatter({ description: PROTOCOL_DESCRIPTIONS[slug] ?? '' }, body),
59
+ },
60
+ opencode: {
61
+ label: 'OpenCode',
62
+ destPath: (slug) => path.join('.opencode', 'commands', `${slug}.md`),
63
+ render: (slug, body) => withFrontmatter({ description: PROTOCOL_DESCRIPTIONS[slug] ?? '' }, body),
64
+ },
65
+ codex: {
66
+ label: 'Codex CLI',
67
+ destPath: (slug) => path.join('.agents', 'skills', slug, 'SKILL.md'),
68
+ render: (slug, body) => withFrontmatter({ name: slug, description: PROTOCOL_DESCRIPTIONS[slug] ?? '' }, body),
69
+ },
70
+ };
71
+ function withFrontmatter(fields, body) {
72
+ const lines = ['---'];
73
+ for (const [k, v] of Object.entries(fields))
74
+ lines.push(`${k}: ${v}`);
75
+ lines.push('---', '', '');
76
+ return lines.join('\n') + body;
77
+ }
35
78
  export async function cmdInit(prompt, options = {}) {
36
79
  const cwd = options.cwd ?? process.cwd();
37
80
  const today = new Date().toISOString().slice(0, 10);
@@ -107,14 +150,20 @@ export async function cmdInit(prompt, options = {}) {
107
150
  log_line(' · writing methodfile.json at repo root');
108
151
  const methodfileSrc = await readFile(path.join(TEMPLATES_ROOT, 'starter-kit', 'methodfile.json'), 'utf8');
109
152
  await writeFile(path.join(cwd, 'methodfile.json'), substitute(methodfileSrc, subs), 'utf8');
110
- // Step 3: copy protocols into .claude/commands/
111
- const claudeCommandsDir = path.join(cwd, '.claude', 'commands');
112
- await mkdir(claudeCommandsDir, { recursive: true });
113
- for (const protocol of PROTOCOL_FILES) {
114
- const dest = path.join(claudeCommandsDir, protocol);
115
- const existed = existsSync(dest);
116
- await copyFile(path.join(TEMPLATES_ROOT, 'protocols', protocol), dest);
117
- log_line(` · ${existed ? 'overwrote' : 'installed'} .claude/commands/${protocol}`);
153
+ // Step 3: fan protocols out to all three supported AI coding tools.
154
+ // Each tool reads project-level commands from its own path; we install
155
+ // to all three by default so users on any of Claude Code / OpenCode /
156
+ // Codex CLI get working slash commands without extra configuration.
157
+ for (const protocolFile of PROTOCOL_FILES) {
158
+ const slug = path.basename(protocolFile, '.md');
159
+ const body = await readFile(path.join(TEMPLATES_ROOT, 'protocols', protocolFile), 'utf8');
160
+ for (const tool of Object.values(TOOLS)) {
161
+ const dest = path.join(cwd, tool.destPath(slug));
162
+ const existed = existsSync(dest);
163
+ await mkdir(path.dirname(dest), { recursive: true });
164
+ await writeFile(dest, tool.render(slug, body), 'utf8');
165
+ log_line(` · ${existed ? 'overwrote' : 'installed'} ${tool.destPath(slug)} (${tool.label})`);
166
+ }
118
167
  }
119
168
  // Step 4: CLAUDE.md
120
169
  const claudeMdPath = path.join(cwd, 'CLAUDE.md');
@@ -159,26 +208,26 @@ export async function cmdInstallProtocols(prompt, options = {}) {
159
208
  exitCode: 1,
160
209
  };
161
210
  }
162
- const claudeCommandsDir = path.join(cwd, '.claude', 'commands');
163
- await mkdir(claudeCommandsDir, { recursive: true });
164
211
  const lines = [];
165
- for (const protocol of PROTOCOL_FILES) {
166
- const src = path.join(TEMPLATES_ROOT, 'protocols', protocol);
167
- const dest = path.join(claudeCommandsDir, protocol);
168
- let action = 'created';
169
- if (existsSync(dest)) {
170
- const [srcContent, destContent] = await Promise.all([
171
- readFile(src, 'utf8'),
172
- readFile(dest, 'utf8'),
173
- ]);
174
- action = srcContent === destContent ? 'unchanged' : 'updated';
175
- }
176
- if (action !== 'unchanged') {
177
- await copyFile(src, dest);
212
+ for (const protocolFile of PROTOCOL_FILES) {
213
+ const slug = path.basename(protocolFile, '.md');
214
+ const body = await readFile(path.join(TEMPLATES_ROOT, 'protocols', protocolFile), 'utf8');
215
+ for (const tool of Object.values(TOOLS)) {
216
+ const dest = path.join(cwd, tool.destPath(slug));
217
+ const rendered = tool.render(slug, body);
218
+ let action = 'created';
219
+ if (existsSync(dest)) {
220
+ const destContent = await readFile(dest, 'utf8');
221
+ action = destContent === rendered ? 'unchanged' : 'updated';
222
+ }
223
+ if (action !== 'unchanged') {
224
+ await mkdir(path.dirname(dest), { recursive: true });
225
+ await writeFile(dest, rendered, 'utf8');
226
+ }
227
+ lines.push(` ${action.padEnd(10)} ${tool.destPath(slug)}`);
178
228
  }
179
- lines.push(` ${action.padEnd(10)} .claude/commands/${protocol}`);
180
229
  }
181
- prompt.print(`Refreshing protocols at ${claudeCommandsDir}:`);
230
+ prompt.print(`Refreshing protocols (Claude Code / OpenCode / Codex CLI):`);
182
231
  for (const l of lines)
183
232
  prompt.print(l);
184
233
  return { output: '', exitCode: 0 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nusoft/nuos-build-catalogue",
3
- "version": "0.10.1",
3
+ "version": "0.11.0",
4
4
  "description": "NuOS build-catalogue tooling: semantic search (WU 110) + migration runner that lifts markdown artefacts into JSON-backed workflow records (WU 111, Phase G).",
5
5
  "type": "module",
6
6
  "bin": {