Files
zalbot/scripts/loreShared.ts
Kaysser Kayyali b884a13d98
Some checks failed
tests / Unit tests (Node 22) (push) Failing after 28s
fix wizard for new stories
2026-06-20 06:52:19 +00:00

33 lines
1.4 KiB
TypeScript

// Shared fetch + format for the per-section lore-options tools. Importable,
// not a direct CLI. Each scripts/lore-<section>.ts builds a section-flavored
// query from the user's vibe seed and calls printOptions().
//
// GraphMCP's semantic_search returns scored lore text chunks (not clean entity
// lists), so the wizard reads these chunks and names the top ~3-4 as
// AskUserQuestion options. This helper just fetches and prints them cleanly.
//
// Host override required: GRAPHMCP_URL=http://localhost:9000 (see SKILL.md).
import { semanticSearch } from '../src/graphmcp/client.js';
/**
* Run a section-flavored semantic_search query and print ranked chunks.
* Exit 0 with results (or "No lore matched this section."); exit 1 on fetch
* failure. The caller wraps this in try/catch for the exit-1 path.
*/
export async function printOptions(query: string, limit = 8): Promise<void> {
const r = await semanticSearch(query, limit);
if (r.chunks.length === 0) {
console.log('No lore matched this section.');
return;
}
r.chunks.forEach((c, i) => {
const snippet = c.content.length > 240 ? c.content.slice(0, 237) + '…' : c.content;
console.log(`${i + 1}. [${c.score.toFixed(3)}] ${c.source ?? 'lore'}: ${snippet}`);
});
}
/** Build a query that prepends a section scope to the user's vibe seed. */
export function sectionQuery(scope: string, vibe: string): string {
return `${scope}${vibe}`;
}