diffwiki 0.9.0-rc.202607291540.2b773e4 → 0.9.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/bin.js +229 -354
- package/package.json +2 -2
package/dist/bin.js
CHANGED
|
@@ -57,9 +57,6 @@ 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
|
-
};
|
|
63
60
|
|
|
64
61
|
// src/ui-server.ts
|
|
65
62
|
import { spawn } from "child_process";
|
|
@@ -295,405 +292,283 @@ async function runPreview(opts) {
|
|
|
295
292
|
|
|
296
293
|
// src/cli.ts
|
|
297
294
|
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
|
-
}
|
|
512
295
|
function createProgram() {
|
|
513
296
|
const program = new Command();
|
|
514
297
|
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");
|
|
515
298
|
program.action(() => {
|
|
516
299
|
program.outputHelp();
|
|
517
300
|
});
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
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
|
+
})
|
|
529
314
|
);
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
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
|
-
)
|
|
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
|
+
})
|
|
545
323
|
);
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
)
|
|
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
|
+
})
|
|
552
329
|
);
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
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
|
+
})
|
|
561
339
|
);
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
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();
|
|
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}`);
|
|
580
344
|
})
|
|
581
345
|
);
|
|
582
|
-
program.command("
|
|
583
|
-
withErrors((opts) => {
|
|
584
|
-
|
|
585
|
-
|
|
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}`);
|
|
586
350
|
})
|
|
587
351
|
);
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
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).`);
|
|
592
375
|
})
|
|
593
376
|
);
|
|
594
|
-
program.command("
|
|
595
|
-
withErrors((
|
|
596
|
-
|
|
597
|
-
|
|
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
|
+
}
|
|
598
391
|
})
|
|
599
392
|
);
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
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
|
+
}
|
|
604
414
|
})
|
|
605
415
|
);
|
|
606
|
-
|
|
607
|
-
withErrors((opts) => {
|
|
608
|
-
|
|
609
|
-
|
|
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(" ")}`);
|
|
610
420
|
})
|
|
611
421
|
);
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
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
|
+
}
|
|
627
444
|
})
|
|
628
445
|
);
|
|
629
|
-
|
|
630
|
-
withErrors((
|
|
631
|
-
|
|
632
|
-
|
|
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}"`);
|
|
633
450
|
})
|
|
634
451
|
);
|
|
635
|
-
program.command("init"
|
|
636
|
-
withErrors((opts) => {
|
|
637
|
-
|
|
638
|
-
|
|
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");
|
|
639
461
|
})
|
|
640
462
|
);
|
|
641
|
-
program.command("export"
|
|
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(
|
|
642
464
|
withErrors(
|
|
643
|
-
(opts) => {
|
|
644
|
-
|
|
645
|
-
|
|
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
|
+
});
|
|
646
473
|
}
|
|
647
474
|
)
|
|
648
475
|
);
|
|
649
|
-
program.command("config-set",
|
|
650
|
-
withErrors((key, value) => {
|
|
651
|
-
|
|
652
|
-
|
|
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}`);
|
|
653
480
|
})
|
|
654
481
|
);
|
|
655
|
-
program.command("config-get"
|
|
656
|
-
withErrors((key) => {
|
|
657
|
-
|
|
658
|
-
|
|
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)");
|
|
659
486
|
})
|
|
660
487
|
);
|
|
661
|
-
program.command("
|
|
662
|
-
withErrors((
|
|
663
|
-
|
|
664
|
-
|
|
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
|
+
}
|
|
665
497
|
})
|
|
666
498
|
);
|
|
667
|
-
program.command("
|
|
668
|
-
withErrors(() => {
|
|
669
|
-
|
|
670
|
-
|
|
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
|
+
);
|
|
671
511
|
})
|
|
672
512
|
);
|
|
673
|
-
program.command("
|
|
674
|
-
withErrors(() => {
|
|
675
|
-
|
|
676
|
-
|
|
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.");
|
|
677
517
|
})
|
|
678
518
|
);
|
|
679
|
-
program.command("
|
|
680
|
-
withErrors((
|
|
681
|
-
|
|
682
|
-
|
|
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
|
+
}
|
|
683
527
|
})
|
|
684
528
|
);
|
|
685
|
-
program.command("
|
|
686
|
-
withErrors((
|
|
687
|
-
|
|
688
|
-
|
|
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}`);
|
|
689
540
|
})
|
|
690
541
|
);
|
|
691
|
-
program.command("
|
|
692
|
-
withErrors((opts) => {
|
|
693
|
-
|
|
694
|
-
|
|
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;
|
|
695
564
|
})
|
|
696
565
|
);
|
|
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;
|
|
697
572
|
}
|
|
698
573
|
|
|
699
574
|
// 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.9.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.9.0"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@types/node": "^22.0.0"
|