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

Function buildContext

scripts/gen-skill-docs.ts:716–736  ·  view source on GitHub ↗

* Build the TemplateContext from a template's frontmatter. Shared by SKILL.md * and section generation so sections inherit the SAME context the parent skill * resolves with (skillName, tier, benefitsFrom, interactive) — enforced by * test/template-context-parity.test.ts. skillNameOverride lets se

(
  tmplContent: string,
  tmplPath: string,
  host: Host,
  skillNameOverride?: string,
)

Source from the content-addressed store, hash-verified

714 * generation pin the parent skill's name instead of deriving "sections".
715 */
716function buildContext(
717 tmplContent: string,
718 tmplPath: string,
719 host: Host,
720 skillNameOverride?: string,
721): TemplateContext {
722 const { name: extractedName } = extractNameAndDescription(tmplContent);
723 const skillName = skillNameOverride || extractedName || path.basename(path.dirname(tmplPath));
724 const benefitsMatch = tmplContent.match(/^benefits-from:\s*\[([^\]]*)\]/m);
725 const benefitsFrom = benefitsMatch
726 ? benefitsMatch[1].split(',').map(s => s.trim()).filter(Boolean)
727 : undefined;
728 const tierMatch = tmplContent.match(/^preamble-tier:\s*(\d+)$/m);
729 const preambleTier = tierMatch ? parseInt(tierMatch[1], 10) : undefined;
730 const interactiveMatch = tmplContent.match(/^interactive:\s*(true|false)\s*$/m);
731 const interactive = interactiveMatch ? interactiveMatch[1] === 'true' : undefined;
732 return {
733 skillName, tmplPath, benefitsFrom, host, paths: HOST_PATHS[host],
734 preambleTier, model: MODEL_ARG_VAL, interactive, explainLevel: EXPLAIN_LEVEL,
735 };
736}
737
738/**
739 * Process external host output: routing, frontmatter, path rewrites, metadata.

Callers 2

processTemplateFunction · 0.85
processSectionTemplateFunction · 0.85

Calls 1

Tested by

no test coverage detected