MCPcopy Index your code
hub / github.com/garrytan/gstack / loadContext

Function loadContext

bin/gstack-brain-context-load.ts:404–441  ·  view source on GitHub ↗
(args: CliArgs)

Source from the content-addressed store, hash-verified

402// ── Main pipeline ──────────────────────────────────────────────────────────
403
404async function loadContext(args: CliArgs): Promise<{ rendered: string; results: QueryResult[]; mode: "manifest" | "default" }> {
405 const skillFile = resolveSkillFile(args);
406 let manifest: GbrainManifest | null = null;
407 let mode: "manifest" | "default" = "default";
408
409 if (skillFile) {
410 manifest = parseSkillManifest(skillFile);
411 if (manifest && manifest.context_queries.length > 0) {
412 mode = "manifest";
413 }
414 }
415 if (!manifest) {
416 manifest = defaultManifest(args);
417 }
418
419 const results: QueryResult[] = [];
420 for (const q of manifest.context_queries) {
421 const r = await withErrorContext(`context-load:${q.id}`, () => {
422 switch (q.kind) {
423 case "vector": return dispatchVector(q, args);
424 case "list": return dispatchList(q, args);
425 case "filesystem": return dispatchFilesystem(q, args);
426 }
427 }, "gstack-brain-context-load");
428 results.push(r);
429 }
430
431 // Substitute render_as template vars (e.g. "{skill_name}")
432 const rendered = results
433 .filter((r) => r.ok && r.rendered.length > 0)
434 .map((r) => {
435 const { resolved } = substituteTemplateVars(r.rendered, args);
436 return resolved;
437 })
438 .join("\n");
439
440 return { rendered, results, mode };
441}
442
443// ── Entry point ────────────────────────────────────────────────────────────
444

Callers 1

mainFunction · 0.85

Calls 9

parseSkillManifestFunction · 0.90
withErrorContextFunction · 0.90
resolveSkillFileFunction · 0.85
defaultManifestFunction · 0.85
dispatchVectorFunction · 0.85
dispatchListFunction · 0.85
dispatchFilesystemFunction · 0.85
substituteTemplateVarsFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected