mirror of
https://github.com/garrytan/gstack.git
synced 2026-06-26 11:39:58 +02:00
Merge remote-tracking branch 'origin/main' into garrytan/cut-skill-token-bloat
# Conflicts: # scripts/gen-skill-docs.ts # scripts/resolvers/index.ts # ship/SKILL.md # ship/SKILL.md.tmpl # test/fixtures/golden/claude-ship-SKILL.md
This commit is contained in:
@@ -26,6 +26,49 @@ import type { HostConfig } from './host-config';
|
||||
const ROOT = path.resolve(import.meta.dir, '..');
|
||||
const DRY_RUN = process.argv.includes('--dry-run');
|
||||
|
||||
// ─── GBrain Detection Override ──────────────────────────────
|
||||
// When --respect-detection is passed, read ~/.gstack/gbrain-detection.json
|
||||
// and un-suppress GBRAIN_CONTEXT_LOAD + GBRAIN_SAVE_RESULTS for hosts that
|
||||
// statically suppress them (claude, codex, slate, factory, opencode,
|
||||
// openclaw, cursor, kiro). Detection state is produced by
|
||||
// bin/gstack-gbrain-detect and persisted by `gstack-config gbrain-refresh`
|
||||
// or by ./setup.
|
||||
//
|
||||
// Default (no flag): static suppressedResolvers honored as-is. Used by
|
||||
// `bun run gen:skill-docs` (CI + canonical checked-in SKILL.md files) so
|
||||
// the committed output is reproducible regardless of any developer's
|
||||
// local gbrain installation state. Use `bun run gen:skill-docs:user`
|
||||
// (which adds --respect-detection) for user-local installs.
|
||||
const RESPECT_DETECTION = process.argv.includes('--respect-detection');
|
||||
|
||||
function loadGbrainOverride(): { detected: boolean } {
|
||||
if (!RESPECT_DETECTION) return { detected: false };
|
||||
const stateDir = process.env.GSTACK_HOME || path.join(process.env.HOME || '', '.gstack');
|
||||
const detectionPath = path.join(stateDir, 'gbrain-detection.json');
|
||||
try {
|
||||
const json = JSON.parse(fs.readFileSync(detectionPath, 'utf-8')) as { gbrain_local_status?: string };
|
||||
return { detected: json.gbrain_local_status === 'ok' };
|
||||
} catch {
|
||||
return { detected: false };
|
||||
}
|
||||
}
|
||||
|
||||
const GBRAIN_OVERRIDE = loadGbrainOverride();
|
||||
|
||||
/**
|
||||
* Compute effective suppressedResolvers for a host, applying the gbrain
|
||||
* detection override when enabled. When the override fires, GBRAIN_*
|
||||
* resolvers are removed from the suppression set so they render in the
|
||||
* generated SKILL.md.
|
||||
*/
|
||||
function effectiveSuppressedResolvers(hostConfig: HostConfig): Set<string> {
|
||||
let list = hostConfig.suppressedResolvers || [];
|
||||
if (GBRAIN_OVERRIDE.detected) {
|
||||
list = list.filter(r => r !== 'GBRAIN_CONTEXT_LOAD' && r !== 'GBRAIN_SAVE_RESULTS');
|
||||
}
|
||||
return new Set(list);
|
||||
}
|
||||
|
||||
// ─── Host Detection (config-driven) ─────────────────────────
|
||||
|
||||
const HOST_ARG = process.argv.find(a => a.startsWith('--host'));
|
||||
@@ -562,7 +605,10 @@ function resolvePlaceholders(
|
||||
hostConfig: HostConfig,
|
||||
relTmplPath: string,
|
||||
): string {
|
||||
const suppressed = new Set(hostConfig.suppressedResolvers || []);
|
||||
// effectiveSuppressedResolvers() honors --respect-detection: when gbrain is
|
||||
// detected locally, GBRAIN_* resolvers un-suppress. Shared by SKILL.md and
|
||||
// section generation so both paths get the same gbrain-aware behavior.
|
||||
const suppressed = effectiveSuppressedResolvers(hostConfig);
|
||||
const onePass = (input: string): string =>
|
||||
input.replace(/\{\{(\w+(?::[^}]+)?)\}\}/g, (_match, fullKey) => {
|
||||
const parts = fullKey.split(':');
|
||||
|
||||
Reference in New Issue
Block a user