skill: cache preamble bash output within session to reduce duplication
- Dominant language
- TypeScript
- Stars
- 133k
- Forks
- 19.9k
- Avg merge
- 18h 46m
- Merged PRs (30d)
- 26
Description
## Problem
When executing a long plan that invokes 5–8 gstack-flavored skills sequentially (`/investigate` → `/plan-eng-review` → `/codex` → `/review` → `/ship` etc.), the SKILL.md "Preamble (run first)" bash block is re-injected and re-executed on every invocation. Each preamble is ~200 lines of bash producing 30+ echoed lines (PROACTIVE / PROACTIVE_PROMPTED / BRANCH / SKILL_PREFIX / REPO_MODE / LAKE_INTRO / TELEMETRY / TEL_PROMPTED / EXPLAIN_LEVEL / QUESTION_TUNING / LEARNINGS / HAS_ROUTING / ROUTING_DECLINED / VENDORED_GSTACK / MODEL_OVERLAY / CHECKPOINT_MODE / CHECKPOINT_PUSH / ARTIFACTS_SYNC / etc.).
Within a single session these values do not change. The repeated `gstack-config get`, `find ~/.gstack/sessions`, `gstack-learnings-search`, `gstack-timeline-log` calls add noise to the agent's context and slow the skill startup.
## Measured impact
In a recent 10-task implementation plan (PR #309-like, schema migration + 5 route refactor + double review), the same preamble executed 8 times, ~1600+ lines of duplicated state echo consumed in agent context across the run.
## Proposal
Session-scoped cache for preamble outputs:
1. On first invoke per session: full preamble runs, output written to `~/.gstack/sessions//preamble.env` (or similar)
2. Subsequent invokes within the same session: skill checks the cache file age (mtime < 2 hours, same PPID), if valid → emit cached values, skip the bash block entirely
3. One-shot invalidations (`gstack-config set ...`, telemetry toggle, etc.) write a marker to invalidate cache
Alternative lighter-weight: extract preamble into a single shared `gstack-session-init` helper that all skills source, which itself checks cache.
## Repro
```bash
# In a Claude Code session, invoke several gstack skills in sequence:
/investigate
/plan-eng-review
/codex review
/review
# Each skill emits the full preamble block — values are identical across invocations.
```
## Why now
PR-level plans now routinely chain 5+ skills (investigate → write-plans → execute → codex → kimi review → finishing-a-branch). Preamble overhead is no longer a one-time cost.
Contributor guide
Research direction
Start by locating the SKILL.md preamble and the session data under ~/.gstack/sessions, then inspect how gstack-config and the other listed preamble commands are invoked. Define the cache validity and invalidation behavior, and verify that chained skills reuse values within a session while one-shot configuration changes invalidate them.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- bash
- Domain
- developer-experience, tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100