diffwiki 0.9.0 → 0.10.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.
Files changed (2) hide show
  1. package/dist/bin.js +354 -229
  2. package/package.json +2 -2
package/dist/bin.js CHANGED
@@ -57,6 +57,9 @@ function withErrors(fn) {
57
57
  }
58
58
  var collect = (value, previous) => previous.concat([value]);
59
59
  var splitTags = (raw) => raw.flatMap((t) => t.split(",")).map((t) => t.trim()).filter((t) => t.length > 0);
60
+ var deprecated = (oldForm, newForm) => {
61
+ console.error(`\u26A0 "diffwiki ${oldForm}" is deprecated; use "diffwiki ${newForm}".`);
62
+ };
60
63
 
61
64
  // src/ui-server.ts
62
65
  import { spawn } from "child_process";
@@ -292,283 +295,405 @@ async function runPreview(opts) {
292
295
 
293
296
  // src/cli.ts
294
297
  var icon = (level) => level === "ok" ? "\u2713" : level === "warn" ? "!" : "\u2716";
298
+ async function listCollectionsAction() {
299
+ const collections = await listCollections2();
300
+ if (collections.length === 0) {
301
+ console.log("No collections yet. Create one with: diffwiki collection create <name>");
302
+ return;
303
+ }
304
+ for (const c of collections) {
305
+ const status = await collectionGitStatus(c);
306
+ const branch = status?.branch ? ` (${status.branch})` : "";
307
+ console.log(`${c.name} [${c.type}] ${c.path}${branch}`);
308
+ }
309
+ }
310
+ async function addExternalAction(opts) {
311
+ const entry = await addExternalCollection({ cwd: process.cwd(), docsDir: opts.docs });
312
+ const status = await collectionGitStatus(entry);
313
+ const branch = status?.branch ? ` (${status.branch})` : "";
314
+ console.log(`Added "${entry.name}"${branch} \u2192 ${entry.path}`);
315
+ console.log("Registered globally \u2014 discoverable via: diffwiki collection list");
316
+ }
317
+ async function createCollectionAction(name) {
318
+ const entry = await createCollection(name);
319
+ console.log(`Created collection "${entry.name}" at ${entry.path}`);
320
+ }
321
+ async function createArticleAction(target, body, tags) {
322
+ const article = await createArticle({
323
+ target,
324
+ tags: splitTags(tags),
325
+ body
326
+ });
327
+ console.log(article.path);
328
+ }
329
+ async function updateArticleAction(target, body) {
330
+ const article = await updateArticleBody(target, body);
331
+ console.log(`Updated ${article.path}`);
332
+ }
333
+ async function removeArticleAction(target) {
334
+ const removed = await removeArticle(target);
335
+ console.log(`Removed ${removed}`);
336
+ }
337
+ async function tagsAction(fn, target, tags) {
338
+ const article = await fn(target, splitTags([tags]));
339
+ console.log(`${article.path} \u2192 tags: ${article.tags.join(", ") || "(none)"}`);
340
+ }
341
+ async function indexAction(opts) {
342
+ const provider = await loadSearchProvider();
343
+ if (!provider) {
344
+ const installable = (await listSearchModes()).filter((m) => m.plugin !== "native");
345
+ console.log(
346
+ installable.length > 0 ? `No index-backed plugin active. Available modes: ${installable.map((m) => `${m.plugin}\xB7${m.type}`).join(", ")}` : "No search plugin installed \u2014 using native search (nothing to index). Install one with: diffwiki plugin install <spec>"
347
+ );
348
+ return;
349
+ }
350
+ const indexed = await provider.reindex(await listCollections2(), { embed: !!opts.embed });
351
+ console.log(`Indexed ${indexed} document(s).`);
352
+ }
353
+ async function queryAction(term, opts) {
354
+ const queryOpts = { engine: opts.engine, collection: opts.collection, type: opts.type };
355
+ const outcome = await search(term, queryOpts);
356
+ const hits = outcome.hits;
357
+ console.log(`${hits.length} result(s)`);
358
+ for (const hit of hits) {
359
+ const score = typeof hit.score === "number" ? hit.score.toFixed(3) : "-";
360
+ const line = `${score} ${hit.collection} ${hit.title} ${hit.path}`;
361
+ console.log(hit.snippet ? `${line} ${hit.snippet}` : line);
362
+ }
363
+ if (outcome.error) {
364
+ console.error(`\u26A0 engine "${outcome.engine}" failed: ${outcome.error} \u2014 used native (${hits.length} results)`);
365
+ }
366
+ }
367
+ async function pluginInstallAction(spec, opts) {
368
+ const { record, setup, defaulted } = await installPlugin(spec, {
369
+ setup: opts.setup,
370
+ setDefault: opts.default,
371
+ prefetchModels: opts.prefetchModels
372
+ });
373
+ console.log(`Installed "${record.name}"${record.version ? ` v${record.version}` : ""}`);
374
+ if (!opts.setup) {
375
+ console.log("Skipped setup (--no-setup) \u2014 run: diffwiki search index");
376
+ } else if (setup && !setup.ready) {
377
+ const reason = setup.steps.find((s) => !s.ok)?.message ?? "setup did not complete";
378
+ console.log(`\u26A0 Not ready: ${reason}`);
379
+ console.log(" \u2192 run: diffwiki doctor");
380
+ }
381
+ if (defaulted) {
382
+ console.log(
383
+ `Set "${record.name}" as the default search engine (change: diffwiki config set defaultSearch <engine[:type]>)`
384
+ );
385
+ }
386
+ }
387
+ async function pluginRegisterAction(name, opts) {
388
+ const record = await registerPlugin(name, opts.command);
389
+ console.log(`Registered "${record.name}" \u2192 ${record.command.join(" ")}`);
390
+ }
391
+ async function pluginListAction() {
392
+ const installed = await listPlugins();
393
+ const installedNames = new Set(installed.map((p) => p.name));
394
+ console.log("Installed:");
395
+ if (installed.length === 0) {
396
+ console.log(" (none)");
397
+ } else {
398
+ for (const p of installed) {
399
+ console.log(
400
+ ` ${p.name} ${p.kind} ${p.version ?? "-"} enabled=${p.enabled} managed=${!!p.managed} spawnable=${p.spawnable}`
401
+ );
402
+ }
403
+ }
404
+ const available = listAvailablePlugins().filter((k) => !installedNames.has(k.name));
405
+ if (available.length > 0) {
406
+ console.log("\nAvailable (install with: diffwiki plugin install <name>):");
407
+ for (const k of available) {
408
+ console.log(` ${k.name} [${k.kind}] ${k.description}`);
409
+ console.log(` requires ${k.requires ?? "nothing"}`);
410
+ }
411
+ }
412
+ }
413
+ async function pluginRemoveAction(name) {
414
+ await removePlugin(name);
415
+ console.log(`Removed "${name}"`);
416
+ }
417
+ async function initAction(opts) {
418
+ const entry = await initRepoWiki({
419
+ cwd: process.cwd(),
420
+ collection: opts.collection,
421
+ wikiPath: opts.path
422
+ });
423
+ console.log(`Initialized repo wiki "${entry.name}" at ${entry.path}`);
424
+ console.log("Registered globally \u2014 discoverable via: diffwiki collection list");
425
+ }
426
+ async function exportAction(opts) {
427
+ await runExport({
428
+ out: opts.out,
429
+ base: opts.base,
430
+ filter: opts.filter,
431
+ exclude: opts.exclude,
432
+ project: opts.project
433
+ });
434
+ }
435
+ async function configSetAction(key, value) {
436
+ await setConfigValue(key, value);
437
+ console.log(`Set ${key} = ${value}`);
438
+ }
439
+ async function configGetAction(key) {
440
+ const value = await getConfigValue(key);
441
+ console.log(value ?? "(unset)");
442
+ }
443
+ async function doctorAction() {
444
+ const diagnostics = await doctor();
445
+ for (const d of diagnostics) {
446
+ console.log(`${icon(d.level)} ${d.message}`);
447
+ }
448
+ if (diagnostics.some((d) => d.level === "error")) {
449
+ process.exitCode = 1;
450
+ }
451
+ }
452
+ async function upAction(opts) {
453
+ const existing = await readState();
454
+ if (existing && isAlive(existing.pid)) {
455
+ console.log(`UI already running at ${existing.url} (pid ${existing.pid})`);
456
+ return;
457
+ }
458
+ const state = await startUi(Number(opts.port));
459
+ const ok = await waitForServer(state.url);
460
+ console.log(
461
+ ok ? `UI started at ${state.url} (pid ${state.pid})` : `Launched (pid ${state.pid}) but ${state.url} did not respond yet \u2014 check \`diffwiki ui status\``
462
+ );
463
+ }
464
+ async function downAction() {
465
+ const stopped = await stopUi();
466
+ console.log(stopped ? `Stopped UI (pid ${stopped.pid})` : "UI is not running.");
467
+ }
468
+ async function statusAction() {
469
+ const state = await readState();
470
+ if (state && isAlive(state.pid)) {
471
+ console.log(`running \xB7 ${state.url} \xB7 pid ${state.pid} \xB7 since ${state.startedAt}`);
472
+ } else {
473
+ console.log("stopped");
474
+ }
475
+ }
476
+ async function openAction(opts) {
477
+ let state = await readState();
478
+ if (!state || !isAlive(state.pid)) {
479
+ state = await startUi(Number(opts.port));
480
+ await waitForServer(state.url);
481
+ }
482
+ const coll = await resolveCwdCollection(process.cwd());
483
+ const target = coll ? `${state.url}/${encodeURIComponent(coll.name)}` : state.url;
484
+ openBrowser(target);
485
+ console.log(`Opening ${target}`);
486
+ }
487
+ async function editAction(target, editorFlag) {
488
+ const argv = await resolveEditorCommand(editorFlag);
489
+ if (!argv) {
490
+ console.error(
491
+ 'No editor set. Configure one: diffwiki config set editor "<cmd>" \u2014 or set $EDITOR, or pass --editor.'
492
+ );
493
+ process.exitCode = 1;
494
+ return;
495
+ }
496
+ const { path: dest, kind } = await resolveEditTarget(target, process.cwd());
497
+ const [cmd, ...args] = argv;
498
+ console.log(`Opening ${kind} ${dest} with ${argv.join(" ")}`);
499
+ const code = await new Promise((resolve) => {
500
+ const child = spawn4(cmd, [...args, dest], { stdio: "inherit" });
501
+ child.on("error", (err) => {
502
+ console.error(`Could not launch editor "${cmd}": ${err.message}`);
503
+ resolve(127);
504
+ });
505
+ child.on("exit", (c) => resolve(c ?? 0));
506
+ });
507
+ if (code !== 0) process.exitCode = code;
508
+ }
509
+ async function previewAction(opts) {
510
+ await runPreview({ cwd: process.cwd(), port: Number(opts.port) });
511
+ }
295
512
  function createProgram() {
296
513
  const program = new Command();
297
514
  program.name("diffwiki").description("A git-based knowledge base").version(version).showHelpAfterError().option("-v, --verbose", "verbose logging (sets the log level to debug)").option("--log <level>", "log level: trace|debug|info|warning|error|fatal");
298
515
  program.action(() => {
299
516
  program.outputHelp();
300
517
  });
301
- program.command("list").description("List all collections").action(
302
- withErrors(async () => {
303
- const collections = await listCollections2();
304
- if (collections.length === 0) {
305
- console.log("No collections yet. Create one with: diffwiki create <name>");
306
- return;
307
- }
308
- for (const c of collections) {
309
- const status = await collectionGitStatus(c);
310
- const branch = status?.branch ? ` (${status.branch})` : "";
311
- console.log(`${c.name} [${c.type}] ${c.path}${branch}`);
312
- }
313
- })
518
+ const collection = program.command("collection").description("Manage collections (containers)");
519
+ collection.command("list").description("List all collections").action(withErrors(listCollectionsAction));
520
+ collection.command("create").description("Create a new global collection").argument("<name>", "collection name").action(withErrors((name) => createCollectionAction(name)));
521
+ collection.command("add").description("Add the current git repo as an external collection (docs dir, no diffwiki.yaml)").option("-d, --docs <dir>", "content dir relative to repo root", "docs").action(withErrors((opts) => addExternalAction(opts)));
522
+ collection.command("init").description("Initialize an in-repo wiki and register it globally").option("-c, --collection <name>", "collection name (default: repo name)").option("-p, --path <path>", "wiki path within the repo (default: wiki)").action(withErrors((opts) => initAction(opts)));
523
+ collection.command("edit").description("Open a collection in your editor \u2014 GUI not required").argument("[name]", "collection (default: the current repo collection)").option("--editor <cmd>", "editor command (overrides config `editor`, $VISUAL, $EDITOR)").action(withErrors((name, opts) => editAction(name, opts.editor)));
524
+ const article = program.command("article").description("Manage articles (documents)");
525
+ article.command("create").description("Add an article to a collection").argument("<target>", '"[collection:]title"').argument("[body]", "markdown body").option("-t, --tag <tag>", "tag (repeatable, comma-separated)", collect, []).action(
526
+ withErrors(
527
+ (target, body, opts) => createArticleAction(target, body, opts.tag)
528
+ )
314
529
  );
315
- program.command("add").description("Add the current git repo as an external collection (docs dir, no diffwiki.yaml)").option("-d, --docs <dir>", "content dir relative to repo root", "docs").action(
316
- withErrors(async (opts) => {
317
- const entry = await addExternalCollection({ cwd: process.cwd(), docsDir: opts.docs });
318
- const status = await collectionGitStatus(entry);
319
- const branch = status?.branch ? ` (${status.branch})` : "";
320
- console.log(`Added "${entry.name}"${branch} \u2192 ${entry.path}`);
321
- console.log("Registered globally \u2014 discoverable via: diffwiki list");
322
- })
530
+ article.command("update").description("Replace an article's body").argument("<target>", '"collection:slug"').argument("<body>", "new markdown body").action(withErrors((target, body) => updateArticleAction(target, body)));
531
+ article.command("remove").description("Delete an article").argument("<target>", '"collection:slug"').action(withErrors((target) => removeArticleAction(target)));
532
+ article.command("edit").description("Open an article in your editor \u2014 GUI not required").argument("<target>", '"collection:slug"').option("--editor <cmd>", "editor command (overrides config `editor`, $VISUAL, $EDITOR)").action(withErrors((target, opts) => editAction(target, opts.editor)));
533
+ const tags = program.command("tags").description("Manage an article's tags");
534
+ const registerTagsSub = (name, description, fn) => {
535
+ tags.command(name).description(description).argument("<target>", '"collection:slug"').argument("<tags>", "comma-separated tags").action(withErrors((target, tagList) => tagsAction(fn, target, tagList)));
536
+ };
537
+ registerTagsSub("add", "Add to an article's tags", addTags);
538
+ registerTagsSub("remove", "Remove from an article's tags", removeTags);
539
+ registerTagsSub("set", "Replace an article's tags", setTags);
540
+ const searchCmd = program.command("search").description("Search articles and manage the index");
541
+ searchCmd.command("query").alias("q").description("Search articles via the resolved search engine (native fallback if none)").option("--engine <name>", "search engine/plugin (default: config defaultSearch, else native)").option("-c, --collection <name>", "limit to a collection").option("-t, --type <type>", "search type (engine-defined, e.g. keyword|semantic|hybrid)").argument("[term]", "search term", "").action(
542
+ withErrors(
543
+ (term, opts) => queryAction(term, opts)
544
+ )
323
545
  );
324
- program.command("create").description("Create a new global collection").argument("<name>", "collection name").action(
325
- withErrors(async (name) => {
326
- const entry = await createCollection(name);
327
- console.log(`Created collection "${entry.name}" at ${entry.path}`);
328
- })
546
+ searchCmd.command("index").description("Rebuild the search index via the active plugin").option("--embed", "also build vector embeddings (may download models on first run)").action(withErrors((opts) => indexAction(opts)));
547
+ const plugin = program.command("plugin").description("Manage search plugins");
548
+ plugin.command("install").description("Install a search plugin from an npm spec and provision it (setup)").argument("<spec>", "npm package spec (name, name@version, or path)").option("--no-setup", "skip the end-to-end setup after install").option("--no-default", "do not make this the default search engine").option("--prefetch-models", "pre-download models during setup (heavy)").action(
549
+ withErrors(
550
+ (spec, opts) => pluginInstallAction(spec, opts)
551
+ )
329
552
  );
330
- program.command("add-article").description("Add an article to a collection").requiredOption("-p, --path <target>", '"[collection:]title"').option("-t, --tag <tag>", "tag (repeatable, comma-separated)", collect, []).argument("[body]", "markdown body").action(
331
- withErrors(async (body, opts) => {
332
- const article = await createArticle({
333
- target: opts.path,
334
- tags: splitTags(opts.tag),
335
- body
336
- });
337
- console.log(article.path);
338
- })
553
+ plugin.command("register").description("Register an existing executable as a search plugin").argument("<name>", "plugin name").requiredOption("--command <cmd...>", "command argv to spawn the plugin (e.g. node /abs/adapter.js)").action(withErrors((name, opts) => pluginRegisterAction(name, opts)));
554
+ plugin.command("list").description("List installed and available search plugins").action(withErrors(pluginListAction));
555
+ plugin.command("remove").description("Remove a search plugin").argument("<name>", "plugin name").action(withErrors((name) => pluginRemoveAction(name)));
556
+ const site = program.command("site").description("Build and preview the published site");
557
+ site.command("export").description("Generate a static site (deployable to GitHub Pages)").requiredOption("-o, --out <dir>", "output directory").option("-b, --base <path>", "base URL path (e.g. /my-repo/ for GitHub Pages)", "/").option("-f, --filter <globs>", "only export collections matching these globs (comma-separated)").option("-e, --exclude <globs>", "exclude collections matching these globs (comma-separated)").option("--project [dir]", "build only the repo project from its diffwiki.yaml (default: cwd)").action(
558
+ withErrors(
559
+ (opts) => exportAction(opts)
560
+ )
339
561
  );
340
- program.command("update-article").description("Replace an article's body").requiredOption("-p, --path <target>", '"collection:path"').argument("<body>", "new markdown body").action(
341
- withErrors(async (body, opts) => {
342
- const article = await updateArticleBody(opts.path, body);
343
- console.log(`Updated ${article.path}`);
562
+ site.command("preview").description("Preview the site from the repo diffwiki.yaml (ignores global collections)").option("-p, --port <port>", "port to serve on", "4321").action(withErrors((opts) => previewAction(opts)));
563
+ const ui = program.command("ui").description("Run the local diffwiki app server");
564
+ ui.command("up").description("Start the diffwiki UI (latest published diffwiki-app)").option("-p, --port <port>", "port to serve on", "4321").action(withErrors((opts) => upAction(opts)));
565
+ ui.command("down").description("Stop the running diffwiki UI").action(withErrors(downAction));
566
+ ui.command("status").description("Show whether the diffwiki UI is running").action(withErrors(statusAction));
567
+ ui.command("open").description("Open the diffwiki UI in the browser (starting it if needed)").option("-p, --port <port>", "port to serve on", "4321").action(withErrors((opts) => openAction(opts)));
568
+ const config = program.command("config").description("Read and write diffwiki config");
569
+ config.command("set").description("Set a config value (e.g. defaultCollection, or defaultSearch <engine[:type]>)").argument("<key>", "config key").argument("<value>", "config value").action(withErrors((key, value) => configSetAction(key, value)));
570
+ config.command("get").description("Read a config value").argument("<key>", "config key").action(withErrors((key) => configGetAction(key)));
571
+ program.command("doctor").description("Diagnose configuration issues").action(withErrors(doctorAction));
572
+ registerDeprecatedAliases(program);
573
+ return program;
574
+ }
575
+ function registerDeprecatedAliases(program) {
576
+ program.command("list", { hidden: true }).action(
577
+ withErrors(() => {
578
+ deprecated("list", "collection list");
579
+ return listCollectionsAction();
344
580
  })
345
581
  );
346
- program.command("remove-article").description("Delete an article").requiredOption("-p, --path <target>", '"collection:path"').action(
347
- withErrors(async (opts) => {
348
- const removed = await removeArticle(opts.path);
349
- console.log(`Removed ${removed}`);
582
+ program.command("add", { hidden: true }).option("-d, --docs <dir>", "content dir relative to repo root", "docs").action(
583
+ withErrors((opts) => {
584
+ deprecated("add", "collection add");
585
+ return addExternalAction(opts);
350
586
  })
351
587
  );
352
- const registerTagCommand = (name, fn) => {
353
- program.command(name).requiredOption("-p, --path <target>", '"collection:path"').argument("<tags>", "comma-separated tags").action(
354
- withErrors(async (tags, opts) => {
355
- const article = await fn(opts.path, splitTags([tags]));
356
- console.log(`${article.path} \u2192 tags: ${article.tags.join(", ") || "(none)"}`);
357
- })
358
- );
359
- };
360
- registerTagCommand("add-tags", addTags);
361
- registerTagCommand("remove-tags", removeTags);
362
- registerTagCommand("update-tags", setTags);
363
- program.command("index").description("Rebuild the search index via the active plugin").option("--embed", "also build vector embeddings (may download models on first run)").action(
364
- withErrors(async (opts) => {
365
- const provider = await loadSearchProvider();
366
- if (!provider) {
367
- const installable = (await listSearchModes()).filter((m) => m.plugin !== "native");
368
- console.log(
369
- installable.length > 0 ? `No index-backed plugin active. Available modes: ${installable.map((m) => `${m.plugin}\xB7${m.type}`).join(", ")}` : "No search plugin installed \u2014 using native search (nothing to index). Install one with: diffwiki plugin install <spec>"
370
- );
371
- return;
372
- }
373
- const indexed = await provider.reindex(await listCollections2(), { embed: !!opts.embed });
374
- console.log(`Indexed ${indexed} document(s).`);
588
+ program.command("create", { hidden: true }).argument("<name>", "collection name").action(
589
+ withErrors((name) => {
590
+ deprecated("create", "collection create");
591
+ return createCollectionAction(name);
375
592
  })
376
593
  );
377
- program.command("query").description("Search articles via the resolved search engine (native fallback if none)").option("--engine <name>", "search engine/plugin (default: config defaultSearch, else native)").option("-c, --collection <name>", "limit to a collection").option("-t, --type <type>", "search type (engine-defined, e.g. keyword|semantic|hybrid)").argument("[term]", "search term", "").action(
378
- withErrors(async (term, opts) => {
379
- const queryOpts = { engine: opts.engine, collection: opts.collection, type: opts.type };
380
- const outcome = await search(term, queryOpts);
381
- const hits = outcome.hits;
382
- console.log(`${hits.length} result(s)`);
383
- for (const hit of hits) {
384
- const score = typeof hit.score === "number" ? hit.score.toFixed(3) : "-";
385
- const line = `${score} ${hit.collection} ${hit.title} ${hit.path}`;
386
- console.log(hit.snippet ? `${line} ${hit.snippet}` : line);
387
- }
388
- if (outcome.error) {
389
- console.error(`\u26A0 engine "${outcome.engine}" failed: ${outcome.error} \u2014 used native (${hits.length} results)`);
390
- }
594
+ program.command("add-article", { hidden: true }).requiredOption("-p, --path <target>", '"[collection:]title"').option("-t, --tag <tag>", "tag (repeatable, comma-separated)", collect, []).argument("[body]", "markdown body").action(
595
+ withErrors((body, opts) => {
596
+ deprecated("add-article", "article create");
597
+ return createArticleAction(opts.path, body, opts.tag);
391
598
  })
392
599
  );
393
- const plugin = program.command("plugin").description("Manage search plugins");
394
- plugin.command("install").description("Install a search plugin from an npm spec and provision it (setup)").argument("<spec>", "npm package spec (name, name@version, or path)").option("--no-setup", "skip the end-to-end setup after install").option("--no-default", "do not make this the default search engine").option("--prefetch-models", "pre-download models during setup (heavy)").action(
395
- withErrors(async (spec, opts) => {
396
- const { record, setup, defaulted } = await installPlugin(spec, {
397
- setup: opts.setup,
398
- setDefault: opts.default,
399
- prefetchModels: opts.prefetchModels
400
- });
401
- console.log(`Installed "${record.name}"${record.version ? ` v${record.version}` : ""}`);
402
- if (!opts.setup) {
403
- console.log("Skipped setup (--no-setup) \u2014 run: diffwiki index");
404
- } else if (setup && !setup.ready) {
405
- const reason = setup.steps.find((s) => !s.ok)?.message ?? "setup did not complete";
406
- console.log(`\u26A0 Not ready: ${reason}`);
407
- console.log(" \u2192 run: diffwiki doctor");
408
- }
409
- if (defaulted) {
410
- console.log(
411
- `Set "${record.name}" as the default search engine (change: diffwiki config-set defaultSearch <engine[:type]>)`
412
- );
413
- }
600
+ program.command("update-article", { hidden: true }).requiredOption("-p, --path <target>", '"collection:path"').argument("<body>", "new markdown body").action(
601
+ withErrors((body, opts) => {
602
+ deprecated("update-article", "article update");
603
+ return updateArticleAction(opts.path, body);
414
604
  })
415
605
  );
416
- plugin.command("register").description("Register an existing executable as a search plugin").argument("<name>", "plugin name").requiredOption("--command <cmd...>", "command argv to spawn the plugin (e.g. node /abs/adapter.js)").action(
417
- withErrors(async (name, opts) => {
418
- const record = await registerPlugin(name, opts.command);
419
- console.log(`Registered "${record.name}" \u2192 ${record.command.join(" ")}`);
606
+ program.command("remove-article", { hidden: true }).requiredOption("-p, --path <target>", '"collection:path"').action(
607
+ withErrors((opts) => {
608
+ deprecated("remove-article", "article remove");
609
+ return removeArticleAction(opts.path);
420
610
  })
421
611
  );
422
- plugin.command("list").description("List installed and available search plugins").action(
423
- withErrors(async () => {
424
- const installed = await listPlugins();
425
- const installedNames = new Set(installed.map((p) => p.name));
426
- console.log("Installed:");
427
- if (installed.length === 0) {
428
- console.log(" (none)");
429
- } else {
430
- for (const p of installed) {
431
- console.log(
432
- ` ${p.name} ${p.kind} ${p.version ?? "-"} enabled=${p.enabled} managed=${!!p.managed} spawnable=${p.spawnable}`
433
- );
434
- }
435
- }
436
- const available = listAvailablePlugins().filter((k) => !installedNames.has(k.name));
437
- if (available.length > 0) {
438
- console.log("\nAvailable (install with: diffwiki plugin install <name>):");
439
- for (const k of available) {
440
- console.log(` ${k.name} [${k.kind}] ${k.description}`);
441
- console.log(` requires ${k.requires ?? "nothing"}`);
442
- }
443
- }
612
+ const registerDeprecatedTag = (name, newForm, fn) => {
613
+ program.command(name, { hidden: true }).requiredOption("-p, --path <target>", '"collection:path"').argument("<tags>", "comma-separated tags").action(
614
+ withErrors((tagList, opts) => {
615
+ deprecated(name, newForm);
616
+ return tagsAction(fn, opts.path, tagList);
617
+ })
618
+ );
619
+ };
620
+ registerDeprecatedTag("add-tags", "tags add", addTags);
621
+ registerDeprecatedTag("remove-tags", "tags remove", removeTags);
622
+ registerDeprecatedTag("update-tags", "tags set", setTags);
623
+ program.command("index", { hidden: true }).option("--embed", "also build vector embeddings (may download models on first run)").action(
624
+ withErrors((opts) => {
625
+ deprecated("index", "search index");
626
+ return indexAction(opts);
444
627
  })
445
628
  );
446
- plugin.command("remove").description("Remove a search plugin").argument("<name>", "plugin name").action(
447
- withErrors(async (name) => {
448
- await removePlugin(name);
449
- console.log(`Removed "${name}"`);
629
+ program.command("query", { hidden: true }).option("--engine <name>", "search engine/plugin (default: config defaultSearch, else native)").option("-c, --collection <name>", "limit to a collection").option("-t, --type <type>", "search type (engine-defined, e.g. keyword|semantic|hybrid)").argument("[term]", "search term", "").action(
630
+ withErrors((term, opts) => {
631
+ deprecated("query", "search query");
632
+ return queryAction(term, opts);
450
633
  })
451
634
  );
452
- program.command("init").description("Initialize an in-repo wiki and register it globally").option("-c, --collection <name>", "collection name (default: repo name)").option("-p, --path <path>", "wiki path within the repo (default: wiki)").action(
453
- withErrors(async (opts) => {
454
- const entry = await initRepoWiki({
455
- cwd: process.cwd(),
456
- collection: opts.collection,
457
- wikiPath: opts.path
458
- });
459
- console.log(`Initialized repo wiki "${entry.name}" at ${entry.path}`);
460
- console.log("Registered globally \u2014 discoverable via: diffwiki list");
635
+ program.command("init", { hidden: true }).option("-c, --collection <name>", "collection name (default: repo name)").option("-p, --path <path>", "wiki path within the repo (default: wiki)").action(
636
+ withErrors((opts) => {
637
+ deprecated("init", "collection init");
638
+ return initAction(opts);
461
639
  })
462
640
  );
463
- program.command("export").description("Generate a static site (deployable to GitHub Pages)").requiredOption("-o, --out <dir>", "output directory").option("-b, --base <path>", "base URL path (e.g. /my-repo/ for GitHub Pages)", "/").option("-f, --filter <globs>", "only export collections matching these globs (comma-separated)").option("-e, --exclude <globs>", "exclude collections matching these globs (comma-separated)").option("--project [dir]", "build only the repo project from its diffwiki.yaml (default: cwd)").action(
641
+ program.command("export", { hidden: true }).requiredOption("-o, --out <dir>", "output directory").option("-b, --base <path>", "base URL path (e.g. /my-repo/ for GitHub Pages)", "/").option("-f, --filter <globs>", "only export collections matching these globs (comma-separated)").option("-e, --exclude <globs>", "exclude collections matching these globs (comma-separated)").option("--project [dir]", "build only the repo project from its diffwiki.yaml (default: cwd)").action(
464
642
  withErrors(
465
- async (opts) => {
466
- await runExport({
467
- out: opts.out,
468
- base: opts.base,
469
- filter: opts.filter,
470
- exclude: opts.exclude,
471
- project: opts.project
472
- });
643
+ (opts) => {
644
+ deprecated("export", "site export");
645
+ return exportAction(opts);
473
646
  }
474
647
  )
475
648
  );
476
- program.command("config-set").description("Set a config value (e.g. defaultCollection, or defaultSearch <engine[:type]>)").argument("<key>", "config key").argument("<value>", "config value").action(
477
- withErrors(async (key, value) => {
478
- await setConfigValue(key, value);
479
- console.log(`Set ${key} = ${value}`);
649
+ program.command("config-set", { hidden: true }).argument("<key>", "config key").argument("<value>", "config value").action(
650
+ withErrors((key, value) => {
651
+ deprecated("config-set", "config set");
652
+ return configSetAction(key, value);
480
653
  })
481
654
  );
482
- program.command("config-get").description("Read a config value").argument("<key>", "config key").action(
483
- withErrors(async (key) => {
484
- const value = await getConfigValue(key);
485
- console.log(value ?? "(unset)");
655
+ program.command("config-get", { hidden: true }).argument("<key>", "config key").action(
656
+ withErrors((key) => {
657
+ deprecated("config-get", "config get");
658
+ return configGetAction(key);
486
659
  })
487
660
  );
488
- program.command("doctor").description("Diagnose configuration issues").action(
489
- withErrors(async () => {
490
- const diagnostics = await doctor();
491
- for (const d of diagnostics) {
492
- console.log(`${icon(d.level)} ${d.message}`);
493
- }
494
- if (diagnostics.some((d) => d.level === "error")) {
495
- process.exitCode = 1;
496
- }
661
+ program.command("up", { hidden: true }).option("-p, --port <port>", "port to serve on", "4321").action(
662
+ withErrors((opts) => {
663
+ deprecated("up", "ui up");
664
+ return upAction(opts);
497
665
  })
498
666
  );
499
- program.command("up").description("Start the diffwiki UI (latest published diffwiki-app)").option("-p, --port <port>", "port to serve on", "4321").action(
500
- withErrors(async (opts) => {
501
- const existing = await readState();
502
- if (existing && isAlive(existing.pid)) {
503
- console.log(`UI already running at ${existing.url} (pid ${existing.pid})`);
504
- return;
505
- }
506
- const state = await startUi(Number(opts.port));
507
- const ok = await waitForServer(state.url);
508
- console.log(
509
- ok ? `UI started at ${state.url} (pid ${state.pid})` : `Launched (pid ${state.pid}) but ${state.url} did not respond yet \u2014 check \`diffwiki status\``
510
- );
667
+ program.command("down", { hidden: true }).action(
668
+ withErrors(() => {
669
+ deprecated("down", "ui down");
670
+ return downAction();
511
671
  })
512
672
  );
513
- program.command("down").description("Stop the running diffwiki UI").action(
514
- withErrors(async () => {
515
- const stopped = await stopUi();
516
- console.log(stopped ? `Stopped UI (pid ${stopped.pid})` : "UI is not running.");
673
+ program.command("status", { hidden: true }).action(
674
+ withErrors(() => {
675
+ deprecated("status", "ui status");
676
+ return statusAction();
517
677
  })
518
678
  );
519
- program.command("status").description("Show whether the diffwiki UI is running").action(
520
- withErrors(async () => {
521
- const state = await readState();
522
- if (state && isAlive(state.pid)) {
523
- console.log(`running \xB7 ${state.url} \xB7 pid ${state.pid} \xB7 since ${state.startedAt}`);
524
- } else {
525
- console.log("stopped");
526
- }
679
+ program.command("open", { hidden: true }).option("-p, --port <port>", "port to serve on", "4321").action(
680
+ withErrors((opts) => {
681
+ deprecated("open", "ui open");
682
+ return openAction(opts);
527
683
  })
528
684
  );
529
- program.command("open").description("Open the diffwiki UI in the browser (starting it if needed)").option("-p, --port <port>", "port to serve on", "4321").action(
530
- withErrors(async (opts) => {
531
- let state = await readState();
532
- if (!state || !isAlive(state.pid)) {
533
- state = await startUi(Number(opts.port));
534
- await waitForServer(state.url);
535
- }
536
- const coll = await resolveCwdCollection(process.cwd());
537
- const target = coll ? `${state.url}/${encodeURIComponent(coll.name)}` : state.url;
538
- openBrowser(target);
539
- console.log(`Opening ${target}`);
685
+ program.command("edit", { hidden: true }).argument("[target]", 'collection or "collection:slug" (default: the current repo collection)').option("--editor <cmd>", "editor command (overrides config `editor`, $VISUAL, $EDITOR)").action(
686
+ withErrors((target, opts) => {
687
+ deprecated("edit", "collection edit / article edit");
688
+ return editAction(target, opts.editor);
540
689
  })
541
690
  );
542
- program.command("edit").description("Open a collection (or article) in your editor \u2014 GUI not required").argument("[target]", 'collection or "collection:slug" (default: the current repo collection)').option("--editor <cmd>", "editor command (overrides config `editor`, $VISUAL, $EDITOR)").action(
543
- withErrors(async (target, opts) => {
544
- const argv = await resolveEditorCommand(opts.editor);
545
- if (!argv) {
546
- console.error(
547
- 'No editor set. Configure one: diffwiki config-set editor "<cmd>" \u2014 or set $EDITOR, or pass --editor.'
548
- );
549
- process.exitCode = 1;
550
- return;
551
- }
552
- const { path: dest, kind } = await resolveEditTarget(target, process.cwd());
553
- const [cmd, ...args] = argv;
554
- console.log(`Opening ${kind} ${dest} with ${argv.join(" ")}`);
555
- const code = await new Promise((resolve) => {
556
- const child = spawn4(cmd, [...args, dest], { stdio: "inherit" });
557
- child.on("error", (err) => {
558
- console.error(`Could not launch editor "${cmd}": ${err.message}`);
559
- resolve(127);
560
- });
561
- child.on("exit", (c) => resolve(c ?? 0));
562
- });
563
- if (code !== 0) process.exitCode = code;
691
+ program.command("preview", { hidden: true }).option("-p, --port <port>", "port to serve on", "4321").action(
692
+ withErrors((opts) => {
693
+ deprecated("preview", "site preview");
694
+ return previewAction(opts);
564
695
  })
565
696
  );
566
- program.command("preview").description("Preview the site from the repo diffwiki.yaml (ignores global collections)").option("-p, --port <port>", "port to serve on", "4321").action(
567
- withErrors(async (opts) => {
568
- await runPreview({ cwd: process.cwd(), port: Number(opts.port) });
569
- })
570
- );
571
- return program;
572
697
  }
573
698
 
574
699
  // src/logging.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "diffwiki",
3
- "version": "0.9.0",
3
+ "version": "0.10.0",
4
4
  "description": "diffwiki command-line interface",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -17,7 +17,7 @@
17
17
  "@logtape/logtape": "^2.2.4",
18
18
  "@logtape/file": "^2.2.4",
19
19
  "commander": "^13.0.0",
20
- "diffwiki-core": "0.9.0"
20
+ "diffwiki-core": "0.10.0"
21
21
  },
22
22
  "devDependencies": {
23
23
  "@types/node": "^22.0.0"