feat: add completions API and scanning logic

Implement a new completions system that scans markdown files for
dice notation and headings. The server now exposes a
`/__COMPLETIONS.json`
endpoint and automatically recomputes the completion index when
files are added, updated, or deleted.
This commit is contained in:
2026-07-06 16:50:45 +08:00
parent 307a3c8320
commit 8284f5caee
5 changed files with 195 additions and 0 deletions
+32
View File
@@ -0,0 +1,32 @@
/**
* Completion index — orchestrates all registered completion sources.
*/
import { diceSource } from "./sources/dice.js";
import { linksSource } from "./sources/links.js";
import type { CompletionSource, CompletionsPayload } from "./types.js";
export type {
CompletionsPayload,
DiceCompletion,
LinkCompletion,
} from "./types.js";
/** Registered sources — open for extension */
const sources: CompletionSource[] = [diceSource, linksSource];
/**
* Scan the full content index and return structured completion data.
* Called at server startup and on any file change.
*/
export function scanCompletions(
index: Record<string, string>,
): CompletionsPayload {
const payload: Record<string, unknown[]> = {};
for (const source of sources) {
payload[source.key] = source.scan(index);
}
return payload as unknown as CompletionsPayload;
}