mirror of
https://github.com/garrytan/gstack.git
synced 2026-06-17 15:20:11 +02:00
da5f26872f
A.2 jargon dedup: generate-writing-style.ts replaces the inlined 80-term jargon list with a one-line pointer to scripts/jargon-list.json. The list was duplicated into every tier-2+ skill (48 of 51 skills); inlining cost was ~1.5 KB × 48 = ~70 KB across the corpus. Pointer cost is ~30 bytes per skill. Agents Read the JSON once per session on first jargon term encountered; thereafter the terms array is the canonical reference. A.3 terse build flag: --explain-level=terse compresses preamble prose at gen time. When the flag is set, writing-style collapses to a one-line terse directive and completeness-section + confusion-protocol + context-health are dropped entirely. The default build keeps the runtime-conditional behavior intact (sections still render; the model skips them when EXPLAIN_LEVEL: terse appears in the preamble echo). Terse build is opt-in for users who want shipped skills to match their runtime preference and avoid the per-session terse-mode dead prose. TemplateContext gains an optional `explainLevel: 'default' | 'terse'` field. Default builds set it to 'default'; --explain-level=terse sets 'terse'. Resolvers gate their output via `ctx?.explainLevel === 'terse'`. Measured impact (default build, post-T3): - Total corpus: 2,847 KB → 2,812 KB (saved 35 KB) - ship.md: 160 → 159 KB - plan-ceo-review.md: 128 → 127 KB - Top 10 heaviest: all slightly smaller from jargon pointer Larger compression lands in T4 (catalog trim) and T7 (atomic regen across the full Phase A pipeline). The terse build path further compresses to ~711K tokens vs default ~725K (saved ~14K tokens corpus-wide). Test plan: - bun test test/gen-skill-docs.test.ts: 389 pass (no regression) - bun test test/resolver-entry.test.ts: 6 pass - bun test test/helpers/capture-parity-baseline.test.ts: 4 pass - bun run gen:skill-docs --explain-level=terse: ship.md drops completeness + confusion-protocol + context-health sections; writing-style collapses to one-line terse directive 48 SKILL.md files updated (every tier-2+ skill picks up the jargon pointer). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
118 lines
4.3 KiB
TypeScript
118 lines
4.3 KiB
TypeScript
import { ALL_HOST_CONFIGS } from '../../hosts/index';
|
|
|
|
/**
|
|
* Host type — derived from host configs in hosts/*.ts.
|
|
* Adding a new host: create hosts/myhost.ts + add to hosts/index.ts.
|
|
* Do NOT hardcode host names here.
|
|
*/
|
|
export type Host = (typeof ALL_HOST_CONFIGS)[number]['name'];
|
|
|
|
export interface HostPaths {
|
|
skillRoot: string;
|
|
localSkillRoot: string;
|
|
binDir: string;
|
|
browseDir: string;
|
|
designDir: string;
|
|
makePdfDir: string;
|
|
}
|
|
|
|
/**
|
|
* HOST_PATHS — derived from host configs.
|
|
* Each config's globalRoot/localSkillRoot determines the path structure.
|
|
* Non-Claude hosts use $GSTACK_ROOT env vars (set by preamble).
|
|
*/
|
|
function buildHostPaths(): Record<string, HostPaths> {
|
|
const paths: Record<string, HostPaths> = {};
|
|
for (const config of ALL_HOST_CONFIGS) {
|
|
if (config.usesEnvVars) {
|
|
paths[config.name] = {
|
|
skillRoot: '$GSTACK_ROOT',
|
|
localSkillRoot: config.localSkillRoot,
|
|
binDir: '$GSTACK_BIN',
|
|
browseDir: '$GSTACK_BROWSE',
|
|
designDir: '$GSTACK_DESIGN',
|
|
makePdfDir: '$GSTACK_MAKE_PDF',
|
|
};
|
|
} else {
|
|
const root = `~/${config.globalRoot}`;
|
|
paths[config.name] = {
|
|
skillRoot: root,
|
|
localSkillRoot: config.localSkillRoot,
|
|
binDir: `${root}/bin`,
|
|
browseDir: `${root}/browse/dist`,
|
|
designDir: `${root}/design/dist`,
|
|
makePdfDir: `${root}/make-pdf/dist`,
|
|
};
|
|
}
|
|
}
|
|
return paths;
|
|
}
|
|
|
|
export const HOST_PATHS: Record<string, HostPaths> = buildHostPaths();
|
|
|
|
import type { Model } from '../models';
|
|
export type { Model } from '../models';
|
|
|
|
export interface TemplateContext {
|
|
skillName: string;
|
|
tmplPath: string;
|
|
benefitsFrom?: string[];
|
|
host: Host;
|
|
paths: HostPaths;
|
|
preambleTier?: number; // 1-4, controls which preamble sections are included
|
|
model?: Model; // model family for behavioral overlay. Omitted/undefined → no overlay.
|
|
interactive?: boolean; // true → emit plan-mode handshake in preamble. Generator-only, not written to SKILL.md.
|
|
/**
|
|
* Build-time compression mode. Defaults to 'default'.
|
|
*
|
|
* - 'default': full preamble prose ships as today (writing style, completeness,
|
|
* confusion protocol, context health are all present).
|
|
* - 'terse': writing-style + completeness + confusion-protocol + context-health
|
|
* sections are compressed to a one-line pointer at gen time. Saves ~3-5 KB
|
|
* per tier-2+ skill. Opt-in via `--explain-level=terse` build flag for
|
|
* users who want shipped skills to match their runtime preference and
|
|
* avoid the per-session terse-mode prose.
|
|
*
|
|
* Default builds keep the runtime-conditional behavior intact (Writing Style
|
|
* section says "skip entirely if EXPLAIN_LEVEL: terse appears in preamble echo").
|
|
* Terse builds make the compression structural — bytes never ship in the first place.
|
|
*/
|
|
explainLevel?: 'default' | 'terse';
|
|
}
|
|
|
|
/** Resolver function signature. args is populated for parameterized placeholders like {{INVOKE_SKILL:name}}. */
|
|
export type ResolverFn = (ctx: TemplateContext, args?: string[]) => string;
|
|
|
|
/**
|
|
* Optional gated resolver. When the gate returns false, the resolver is
|
|
* skipped (substituted with empty string) — same effect as the placeholder
|
|
* not being referenced. Use when a resolver's output is only meaningful for
|
|
* a known subset of skills, so future template authors get a structural
|
|
* guardrail instead of relying on social knowledge.
|
|
*
|
|
* Most resolvers don't need this — the {{NAME}} placeholder system is
|
|
* already conditional at the template level. Use only when a resolver
|
|
* lives inside another resolver (e.g. via preamble composition) AND must
|
|
* be conditionalized, or when a top-level resolver has a small, well-defined
|
|
* audience.
|
|
*/
|
|
export interface ResolverEntry {
|
|
resolve: ResolverFn;
|
|
appliesTo?: (ctx: TemplateContext) => boolean;
|
|
}
|
|
|
|
/** Anything the RESOLVERS map accepts — either a bare function or a gated entry. */
|
|
export type ResolverValue = ResolverFn | ResolverEntry;
|
|
|
|
/**
|
|
* Type-narrowing helper for the gen-skill-docs lookup.
|
|
* Returns (resolverFn, gate) so callers can do gate?.(ctx) before invoking.
|
|
*/
|
|
export function unwrapResolver(entry: ResolverValue): {
|
|
resolve: ResolverFn;
|
|
appliesTo?: (ctx: TemplateContext) => boolean;
|
|
} {
|
|
if (typeof entry === 'function') return { resolve: entry };
|
|
return { resolve: entry.resolve, appliesTo: entry.appliesTo };
|
|
}
|