feat: declarative multi-host platform + OpenCode, Slate, Cursor, OpenClaw (v0.15.5.0) (#793)

* test: add golden-file baselines for host config refactor

Snapshot generated SKILL.md output for ship skill across all 3 existing
hosts (Claude, Codex, Factory). These baselines verify the config-driven
refactor produces identical output to the current hardcoded system.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* feat: add HostConfig interface and validator for declarative host system

New scripts/host-config.ts defines the typed HostConfig interface that
captures all per-host variation: paths, frontmatter rules, path/tool
rewrites, suppressed resolvers, runtime root symlinks, install strategy,
and behavioral config (co-author trailer, learnings mode, boundary
instruction). Includes validateHostConfig() and validateAllConfigs() with
regex-based security validation and cross-config uniqueness checks.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* feat: add typed host configs for Claude, Codex, Factory, and Kiro

Extract all hardcoded host-specific values from gen-skill-docs.ts,
types.ts, preamble.ts, review.ts, and setup into typed HostConfig
objects. Each host is a single file in hosts/ with its paths, frontmatter
rules, path/tool rewrites, runtime root manifest, and install behavior.

hosts/index.ts exports all configs, derives the Host type, and provides
resolveHostArg() for CLI alias handling (e.g., 'agents' -> 'codex',
'droid' -> 'factory').

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* refactor: derive Host type and HOST_PATHS from host configs

types.ts no longer hardcodes host names or paths. The Host type is
derived from ALL_HOST_CONFIGS in hosts/index.ts, and HOST_PATHS is
built dynamically from each config's globalRoot/localSkillRoot/usesEnvVars.
Adding a new host to hosts/index.ts automatically extends the type system.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* refactor: gen-skill-docs.ts consumes typed host configs

Replace hardcoded EXTERNAL_HOST_CONFIG, transformFrontmatter host
branches, path/tool rewrite if-chains, and ALL_HOSTS array with
config-driven lookups from hosts/*.ts.

- Host detection uses resolveHostArg() (handles aliases like agents/droid)
- transformFrontmatter uses config's allowlist/denylist mode, extraFields,
  conditionalFields, renameFields, and descriptionLimitBehavior
- Path rewrites use config's pathRewrites array (replaceAll, order matters)
- Tool rewrites use config's toolRewrites object
- Skill skipping uses config's generation.skipSkills
- ALL_HOSTS derived from ALL_HOST_NAMES
- Token budget display regex derived from host configs

Golden-file comparison: all 3 hosts produce IDENTICAL output to baselines.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* refactor: preamble, co-author trailer, and resolver suppression use host configs

- preamble.ts: hostConfigDir derived from config.globalRoot instead of
  hardcoded Record
- utility.ts: generateCoAuthorTrailer reads from config.coAuthorTrailer
  instead of host switch statement
- gen-skill-docs.ts: suppressedResolvers from config skip resolver
  execution at placeholder replacement time (belt+suspenders with
  existing ctx.host checks in individual resolvers)

Golden-file comparison: all 3 hosts produce IDENTICAL output to baselines.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* refactor: setup tooling uses config-driven host detection

- host-config-export.ts: new CLI that exposes host configs to bash
  (list, get, detect, validate, symlinks commands)
- bin/gstack-platform-detect: reads host configs instead of hardcoded
  binary/path mapping
- scripts/skill-check.ts: iterates host configs for skill validation
  and freshness checks instead of separate Codex/Factory blocks
- lib/worktree.ts: iterates host configs for directory copy instead
  of hardcoded .agents

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* feat: add OpenCode, Slate, and Cursor host configs

Three new hosts added to the declarative config system. Each is a typed
HostConfig object with paths, frontmatter rules, and path rewrites.
All generate valid SKILL.md output with zero .claude/skills path leakage.

- hosts/opencode.ts: OpenCode (opencode.ai), skills at ~/.config/opencode/
- hosts/slate.ts: Slate (Random Labs), skills at ~/.slate/
- hosts/cursor.ts: Cursor, skills at ~/.cursor/
- .gitignore: add .kiro/, .opencode/, .slate/, .cursor/, .openclaw/

Zero code changes needed — just config files + re-export in index.ts.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* feat: add OpenClaw host config with adapter for tool mapping

OpenClaw gets a hybrid approach: typed config for paths/frontmatter/
detection + a post-processing adapter for semantic tool rewrites.

Config handles: path rewrites, frontmatter (name+description+version),
CLAUDE.md→AGENTS.md, tool name rewrites (Bash→exec, Read→read, etc.),
suppressed resolvers, SOUL.md via staticFiles.

Adapter handles: AskUserQuestion→prose, Agent→sessions_spawn, $B→exec $B.

Zero .claude/skills path leakage. Zero hardcoded tool references remaining.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* feat: contributor add-host skill + fix version sync

- contrib/add-host/SKILL.md.tmpl: contributor-only skill that guides
  new host config creation. Lives in contrib/, excluded from user installs.
- package.json: sync version with VERSION file (0.15.2.1)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* test: add parameterized host smoke tests for all hosts

35 new tests covering all 7 external hosts (Codex, Factory, Kiro,
OpenCode, Slate, Cursor, OpenClaw). Each host gets 4-5 tests:
- output exists on disk with SKILL.md files
- no .claude/skills path leakage in non-root skills
- frontmatter has name + description fields
- --dry-run freshness check passes
- /codex skill excluded (for hosts with skipSkills: ['codex'])

Tests are parameterized over ALL_HOST_CONFIGS so adding a new host
automatically gets smoke-tested with zero new test code.

Also updates --host all test to verify all registered hosts generate.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* test: 100% coverage for host config system

71 new tests in test/host-config.test.ts covering:
- hosts/index.ts: ALL_HOST_CONFIGS, getHostConfig, resolveHostArg (aliases),
  getExternalHosts, uniqueness checks
- host-config.ts validateHostConfig: name regex, displayName, cliCommand,
  cliAliases, globalRoot, localSkillRoot, hostSubdir, frontmatter.mode,
  linkingStrategy, shell injection attempts, paths with $ and ~
- host-config.ts validateAllConfigs: duplicate name/hostSubdir/globalRoot
  detection, error prefix format, real configs pass
- HOST_PATHS derivation: env vars for external hosts, literal paths for
  Claude, localSkillRoot matches config, every host has entry
- host-config-export.ts CLI: list, get (string/boolean/array), detect,
  validate, symlinks, error cases (missing args, unknown field/host)
- Golden-file regression: claude/codex/factory ship SKILL.md vs baselines
- Individual host config correctness: prefixable, linkingStrategy,
  usesEnvVars, description limits, metadata, sidecar, tool rewrites,
  conditional fields, suppressed resolvers, boundary instruction,
  co-author trailers, skip rules, path rewrites, runtime root assets

Combined with the 35 parameterized smoke tests from gen-skill-docs.test.ts,
total new test coverage for multi-host: 106 tests.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* chore: update golden baselines and sync version after merge from main

Golden files refreshed to match post-merge generated output. package.json
version synced to VERSION file (0.15.4.0).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* chore: bump version and changelog (v0.15.5.0)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: sidebar E2E tests now self-contained and passing

- sidebar-url-accuracy: fix stale assertion that expected extensionUrl
  in prompt text (prompt format changed, URL is now in pageUrl field)
- sidebar-css-interaction: simplify task from multi-step HN comment
  navigation to single-page example.com style injection (faster, more
  reliable, still exercises goto + style + completion flow)
- Update golden baselines after merge from main

All 3 sidebar tests now pass: 3/3, 0 fail, ~36s total.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* docs: add ADDING_A_HOST.md guide + update docs for multi-host system

- docs/ADDING_A_HOST.md: step-by-step guide for adding a new host
  (create config, register, gitignore, generate, test). Covers the
  full HostConfig interface, adapter pattern, and validation.
- CONTRIBUTING.md: replace stale "Dual-host development" section with
  "Multi-host development" covering all 8 hosts and linking to the guide.
- README.md: consolidate Codex/Factory install sections into one
  "Other AI Agents" section listing all supported hosts with auto-detect.
- CLAUDE.md: add hosts/, host-config.ts, host-adapters/, contrib/ to
  project structure tree.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* docs: README per-host install instructions for all 8 agents

Each supported agent now has its own copy-paste install block with
the exact command and where skills end up on disk. Includes: auto-detect,
Codex, OpenCode, Cursor, Factory, OpenClaw, Slate, and Kiro.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Garry Tan
2026-04-04 15:32:20 -07:00
committed by GitHub
parent 447851452a
commit 04b709d91a
34 changed files with 8529 additions and 274 deletions
+5
View File
@@ -8,6 +8,11 @@ bin/gstack-global-discover
.claude/skills/
.agents/
.factory/
.kiro/
.opencode/
.slate/
.cursor/
.openclaw/
.context/
extension/.auth.json
.gstack-worktrees/
+26
View File
@@ -1,5 +1,31 @@
# Changelog
## [0.15.6.0] - 2026-04-04 — Declarative Multi-Host Platform
Adding a new coding agent to gstack used to mean touching 9 files and knowing the internals of `gen-skill-docs.ts`. Now it's one TypeScript config file and a re-export. Zero code changes elsewhere. Tests auto-parameterize.
### Added
- **Declarative host config system.** Every host is a typed `HostConfig` object in `hosts/*.ts`. The generator, setup, skill-check, platform-detect, uninstall, and worktree copy all consume configs instead of hardcoded switch statements. Adding a host = one file + re-export in `hosts/index.ts`.
- **4 new hosts: OpenCode, Slate, Cursor, OpenClaw.** `bun run gen:skill-docs --host all` now generates for 8 hosts. Each produces valid SKILL.md output with zero `.claude/skills` path leakage.
- **OpenClaw adapter.** OpenClaw gets a hybrid approach: config for paths/frontmatter/detection + a post-processing adapter for semantic tool mapping (Bash→exec, Agent→sessions_spawn, AskUserQuestion→prose). Includes `SOUL.md` via `staticFiles` config.
- **106 new tests.** 71 tests for config validation, HOST_PATHS derivation, export CLI, golden-file regression, and per-host correctness. 35 parameterized smoke tests covering all 7 external hosts (output exists, no path leakage, frontmatter valid, freshness, skip rules).
- **`host-config-export.ts` CLI.** Exposes host configs to bash scripts via `list`, `get`, `detect`, `validate`, `symlinks` commands. No YAML parsing needed in bash.
- **Contributor `/gstack-contrib-add-host` skill.** Guides new host config creation. Lives in `contrib/`, excluded from user installs.
- **Golden-file baselines.** Snapshots of ship/SKILL.md for Claude, Codex, and Factory verify the refactor produces identical output.
- **Per-host install instructions in README.** Every supported agent has its own copy-paste install block.
### Changed
- **`gen-skill-docs.ts` is now config-driven.** EXTERNAL_HOST_CONFIG, transformFrontmatter host branches, path/tool rewrite if-chains, ALL_HOSTS array, and skill skip logic all replaced with config lookups.
- **`types.ts` derives Host type from configs.** No more hardcoded `'claude' | 'codex' | 'factory'`. HOST_PATHS built dynamically from each config's globalRoot/usesEnvVars.
- **Preamble, co-author trailer, resolver suppression all read from config.** hostConfigDir, co-author strings, and suppressedResolvers driven by host configs instead of per-host switch statements.
- **`skill-check.ts`, `worktree.ts`, `platform-detect` iterate configs.** No per-host blocks to maintain.
### Fixed
- **Sidebar E2E tests now self-contained.** Fixed stale URL assertion in sidebar-url-accuracy, simplified sidebar-css-interaction task. All 3 sidebar tests pass without external browser dependencies.
## [0.15.5.0] - 2026-04-04 — Interactive DX Review + Plan Mode Skill Fix
`/plan-devex-review` now feels like sitting down with a developer advocate who has used 100 CLI tools. Instead of speed-running 8 scores, it asks who your developer is, benchmarks you against competitors' onboarding times, makes you design your magical moment, and traces every friction point step by step before scoring anything.
+11 -1
View File
@@ -63,8 +63,16 @@ gstack/
│ │ └── snapshot.ts # SNAPSHOT_FLAGS metadata array
│ ├── test/ # Integration tests + fixtures
│ └── dist/ # Compiled binary
├── hosts/ # Typed host configs (one per AI agent)
│ ├── claude.ts # Primary host config
│ ├── codex.ts, factory.ts, kiro.ts # Existing hosts
│ ├── opencode.ts, slate.ts, cursor.ts, openclaw.ts # New hosts
│ └── index.ts # Registry: exports all, derives Host type
├── scripts/ # Build + DX tooling
│ ├── gen-skill-docs.ts # Template → SKILL.md generator
│ ├── gen-skill-docs.ts # Template → SKILL.md generator (config-driven)
│ ├── host-config.ts # HostConfig interface + validator
│ ├── host-config-export.ts # Shell bridge for setup script
│ ├── host-adapters/ # Host-specific adapters (OpenClaw tool mapping)
│ ├── resolvers/ # Template resolver modules (preamble, design, review, etc.)
│ ├── skill-check.ts # Health dashboard
│ └── dev-skill.ts # Watch mode
@@ -108,6 +116,8 @@ gstack/
├── .github/ # CI workflows + Docker image
│ ├── workflows/ # evals.yml (E2E on Ubicloud), skill-docs.yml, actionlint.yml
│ └── docker/ # Dockerfile.ci (pre-baked toolchain + Playwright/Chromium)
├── contrib/ # Contributor-only tools (never installed for users)
│ └── add-host/ # /gstack-contrib-add-host skill
├── setup # One-time setup: build binary + symlink skills
├── SKILL.md # Generated from SKILL.md.tmpl (don't edit directly)
├── SKILL.md.tmpl # Template: edit this, run gen:skill-docs
+47 -33
View File
@@ -216,11 +216,10 @@ SKILL.md files are **generated** from `.tmpl` templates. Don't edit the `.md` di
# 1. Edit the template
vim SKILL.md.tmpl # or browse/SKILL.md.tmpl
# 2. Regenerate for both hosts
bun run gen:skill-docs
bun run gen:skill-docs --host codex
# 2. Regenerate for all hosts
bun run gen:skill-docs --host all
# 3. Check health (reports both Claude and Codex)
# 3. Check health (reports all hosts)
bun run skill:check
# Or use watch mode — auto-regenerates on save
@@ -231,59 +230,74 @@ For template authoring best practices (natural language over bash-isms, dynamic
To add a browse command, add it to `browse/src/commands.ts`. To add a snapshot flag, add it to `SNAPSHOT_FLAGS` in `browse/src/snapshot.ts`. Then rebuild.
## Dual-host development (Claude + Codex)
## Multi-host development
gstack generates SKILL.md files for two hosts: **Claude** (`.claude/skills/`) and **Codex** (`.agents/skills/`). Every template change needs to be generated for both.
gstack generates SKILL.md files for 8 hosts from one set of `.tmpl` templates.
Each host is a typed config in `hosts/*.ts`. The generator reads these configs
to produce host-appropriate output (different frontmatter, paths, tool names).
### Generating for both hosts
**Supported hosts:** Claude (primary), Codex, Factory, Kiro, OpenCode, Slate, Cursor, OpenClaw.
### Generating for all hosts
```bash
# Generate Claude output (default)
bun run gen:skill-docs
# Generate for a specific host
bun run gen:skill-docs # Claude (default)
bun run gen:skill-docs --host codex # Codex
bun run gen:skill-docs --host opencode # OpenCode
bun run gen:skill-docs --host all # All 8 hosts
# Generate Codex output
bun run gen:skill-docs --host codex
# --host agents is an alias for --host codex
# Or use build, which does both + compiles binaries
# Or use build, which does all hosts + compiles binaries
bun run build
```
### What changes between hosts
| Aspect | Claude | Codex |
|--------|--------|-------|
| Output directory | `{skill}/SKILL.md` | `.agents/skills/gstack-{skill}/SKILL.md` (generated at setup, gitignored) |
| Frontmatter | Full (name, description, voice-triggers, allowed-tools, hooks, version) | Minimal (name + description only) |
| Paths | `~/.claude/skills/gstack` | `$GSTACK_ROOT` (`.agents/skills/gstack` in a repo, otherwise `~/.codex/skills/gstack`) |
| Hook skills | `hooks:` frontmatter (enforced by Claude) | Inline safety advisory prose (advisory only) |
| `/codex` skill | Included (Claude wraps codex exec) | Excluded (self-referential) |
Each host config (`hosts/*.ts`) controls:
### Testing Codex output
| Aspect | Example (Claude vs Codex) |
|--------|---------------------------|
| Output directory | `{skill}/SKILL.md` vs `.agents/skills/gstack-{skill}/SKILL.md` |
| Frontmatter | Full (name, description, hooks, version) vs minimal (name + description) |
| Paths | `~/.claude/skills/gstack` vs `$GSTACK_ROOT` |
| Tool names | "use the Bash tool" vs same (Factory rewrites to "run this command") |
| Hook skills | `hooks:` frontmatter vs inline safety advisory prose |
| Suppressed sections | None vs Codex self-invocation sections stripped |
See `scripts/host-config.ts` for the full `HostConfig` interface.
### Testing host output
```bash
# Run all static tests (includes Codex validation)
# Run all static tests (includes parameterized smoke tests for all hosts)
bun test
# Check freshness for both hosts
bun run gen:skill-docs --dry-run
bun run gen:skill-docs --host codex --dry-run
# Check freshness for all hosts
bun run gen:skill-docs --host all --dry-run
# Health dashboard covers both hosts
# Health dashboard covers all hosts
bun run skill:check
```
### Dev setup for .agents/
### Adding a new host
When you run `bin/dev-setup`, it creates symlinks in both `.claude/skills/` and `.agents/skills/` (if applicable), so Codex-compatible agents can discover your dev skills too. The `.agents/` directory is generated at setup time from `.tmpl` templates — it is gitignored and not committed.
See [docs/ADDING_A_HOST.md](docs/ADDING_A_HOST.md) for the full guide. Short version:
1. Create `hosts/myhost.ts` (copy from `hosts/opencode.ts`)
2. Add to `hosts/index.ts`
3. Add `.myhost/` to `.gitignore`
4. Run `bun run gen:skill-docs --host myhost`
5. Run `bun test` (parameterized tests auto-cover it)
Zero generator, setup, or tooling code changes needed.
### Adding a new skill
When you add a new skill template, both hosts get it automatically:
When you add a new skill template, all hosts get it automatically:
1. Create `{skill}/SKILL.md.tmpl`
2. Run `bun run gen:skill-docs` (Claude output) and `bun run gen:skill-docs --host codex` (Codex output)
3. The dynamic template discovery picks it up no static list to update
4. Commit `{skill}/SKILL.md` — `.agents/` is generated at setup time and gitignored
2. Run `bun run gen:skill-docs --host all`
3. The dynamic template discovery picks it up, no static list to update
4. Commit `{skill}/SKILL.md`, external host output is generated at setup time and gitignored
## Conductor workspaces
+47 -17
View File
@@ -59,49 +59,79 @@ Real files get committed to your repo (not a submodule), so `git clone` just wor
> git clone https://github.com/garrytan/gstack.git ~/.claude/skills/gstack
> ```
### Codex, Gemini CLI, or Cursor
### Other AI Agents
gstack works on any agent that supports the [SKILL.md standard](https://github.com/anthropics/claude-code). Skills live in `.agents/skills/` and are discovered automatically.
gstack works on 8 AI coding agents, not just Claude. All 31 skills work across
every supported agent. Setup auto-detects which agents you have installed, or
you can target a specific one.
Install to one repo:
#### Auto-detect (installs for every agent on your machine)
```bash
git clone --single-branch --depth 1 https://github.com/garrytan/gstack.git .agents/skills/gstack
cd .agents/skills/gstack && ./setup --host codex
git clone --single-branch --depth 1 https://github.com/garrytan/gstack.git ~/gstack
cd ~/gstack && ./setup
```
When setup runs from `.agents/skills/gstack`, it installs the generated Codex skills next to it in the same repo and does not write to `~/.codex/skills`.
Install once for your user account:
#### OpenAI Codex CLI
```bash
git clone --single-branch --depth 1 https://github.com/garrytan/gstack.git ~/gstack
cd ~/gstack && ./setup --host codex
```
`setup --host codex` creates the runtime root at `~/.codex/skills/gstack` and
links the generated Codex skills at the top level. This avoids duplicate skill
discovery from the source repo checkout.
Skills install to `~/.codex/skills/gstack-*/`. For repo-local installs, clone
into `.agents/skills/gstack` instead.
Or let setup auto-detect which agents you have installed:
#### OpenCode
```bash
git clone --single-branch --depth 1 https://github.com/garrytan/gstack.git ~/gstack
cd ~/gstack && ./setup --host auto
cd ~/gstack && ./setup --host opencode
```
For Codex-compatible hosts, setup now supports both repo-local installs from `.agents/skills/gstack` and user-global installs from `~/.codex/skills/gstack`. All 31 skills work across all supported agents. Hook-based safety skills (careful, freeze, guard) use inline safety advisory prose on non-Claude hosts.
Skills install to `~/.config/opencode/skills/gstack-*/`.
### Factory Droid
#### Cursor
gstack works with [Factory Droid](https://factory.ai). Skills install to `.factory/skills/` and are discovered automatically. Sensitive skills (ship, land-and-deploy, guard) use `disable-model-invocation: true` so Droids don't auto-invoke them.
```bash
git clone --single-branch --depth 1 https://github.com/garrytan/gstack.git ~/gstack
cd ~/gstack && ./setup --host cursor
```
Skills install to `~/.cursor/skills/gstack-*/`.
#### Factory Droid
```bash
git clone --single-branch --depth 1 https://github.com/garrytan/gstack.git ~/gstack
cd ~/gstack && ./setup --host factory
```
Skills install to `~/.factory/skills/gstack-*/`. Restart `droid` to rescan skills, then type `/qa` to get started.
Skills install to `~/.factory/skills/gstack-*/`. Sensitive skills use
`disable-model-invocation: true` so Droids don't auto-invoke them.
#### OpenClaw
```bash
git clone --single-branch --depth 1 https://github.com/garrytan/gstack.git ~/gstack
cd ~/gstack && ./setup --host openclaw
```
Skills install to `~/.openclaw/skills/gstack-*/`. Tool names are rewritten
for OpenClaw's tool system (exec, read, write, edit, sessions_spawn).
#### Slate / Kiro
```bash
./setup --host slate # Slate (Random Labs)
./setup --host kiro # Amazon Kiro
```
Hook-based safety skills (careful, freeze, guard) use inline safety advisory
prose on all non-Claude hosts.
**Want to add support for another agent?** See [docs/ADDING_A_HOST.md](docs/ADDING_A_HOST.md).
It's one TypeScript config file, zero code changes.
### Voice input (AquaVoice, Whisper, etc.)
+1 -1
View File
@@ -1 +1 @@
0.15.5.0
0.15.6.0
+19 -12
View File
@@ -2,19 +2,26 @@
set -euo pipefail
# gstack-platform-detect: show which AI coding agents are installed and gstack status
# Config-driven: reads host definitions from hosts/*.ts via host-config-export.ts
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
GSTACK_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
printf "%-16s %-10s %-40s %s\n" "Agent" "Version" "Skill Path" "gstack"
printf "%-16s %-10s %-40s %s\n" "-----" "-------" "----------" "------"
for entry in "claude:claude" "codex:codex" "droid:factory" "kiro-cli:kiro"; do
bin="${entry%%:*}"; label="${entry##*:}"
if command -v "$bin" >/dev/null 2>&1; then
ver=$("$bin" --version 2>/dev/null | head -1 || echo "unknown")
case "$label" in
claude) spath="$HOME/.claude/skills/gstack" ;;
codex) spath="$HOME/.codex/skills/gstack" ;;
factory) spath="$HOME/.factory/skills/gstack" ;;
kiro) spath="$HOME/.kiro/skills/gstack" ;;
esac
status=$([ -d "$spath" ] && echo "INSTALLED" || echo "NOT INSTALLED")
printf "%-16s %-10s %-40s %s\n" "$label" "$ver" "$spath" "$status"
for host in $(bun run "$GSTACK_DIR/scripts/host-config-export.ts" list 2>/dev/null); do
cmd=$(bun run "$GSTACK_DIR/scripts/host-config-export.ts" get "$host" cliCommand 2>/dev/null)
root=$(bun run "$GSTACK_DIR/scripts/host-config-export.ts" get "$host" globalRoot 2>/dev/null)
spath="$HOME/$root"
if command -v "$cmd" >/dev/null 2>&1; then
ver=$("$cmd" --version 2>/dev/null | head -1 || echo "unknown")
if [ -d "$spath" ] || [ -L "$spath" ]; then
status="INSTALLED"
else
status="NOT INSTALLED"
fi
printf "%-16s %-10s %-40s %s\n" "$host" "$ver" "$spath" "$status"
fi
done
+63
View File
@@ -0,0 +1,63 @@
---
name: gstack-contrib-add-host
description: |
Contributor-only skill: create a new host config for gstack's multi-host system.
NOT installed for end users. Only usable from the gstack source repo.
---
# /gstack-contrib-add-host — Add a New Host
This skill helps contributors add support for a new AI coding agent to gstack.
## What you'll create
A single TypeScript file in `hosts/<name>.ts` that defines:
- CLI binary name for detection
- Skill directory paths (global + local)
- Frontmatter transformation rules
- Path and tool rewrites
- Runtime root symlink manifest
## Steps
### 1. Gather host info
Ask the contributor:
- What's the agent's name? (e.g., "OpenCode")
- What's the CLI binary? (e.g., "opencode")
- Where does it store skills globally? (e.g., "~/.config/opencode/skills/")
- Where does it store skills locally in a project? (e.g., ".opencode/skills/")
- What frontmatter fields does it support? (name + description is the minimum)
- Does it have its own tool names? (e.g., "exec" instead of "Bash")
### 2. Create the config file
Use `hosts/opencode.ts` as a reference. Create `hosts/<name>.ts` with the
gathered info. Follow the HostConfig interface in `scripts/host-config.ts`.
### 3. Register in index
Add the import and re-export in `hosts/index.ts`.
### 4. Add to .gitignore
Add `.<name>/` to `.gitignore`.
### 5. Generate and verify
```bash
bun run gen:skill-docs --host <name>
```
Check:
- Output exists at `.<name>/skills/gstack-*/SKILL.md`
- No `.claude/skills` path leakage
- Frontmatter matches expected format
### 6. Run tests
```bash
bun test test/gen-skill-docs.test.ts
```
All parameterized tests auto-include the new host.
+182
View File
@@ -0,0 +1,182 @@
# Adding a New Host to gstack
gstack uses a declarative host config system. Each supported AI coding agent
(Claude, Codex, Factory, Kiro, OpenCode, Slate, Cursor, OpenClaw) is defined
as a typed TypeScript config object. Adding a new host means creating one file
and re-exporting it. Zero code changes to the generator, setup, or tooling.
## How it works
```
hosts/
├── claude.ts # Primary host
├── codex.ts # OpenAI Codex CLI
├── factory.ts # Factory Droid
├── kiro.ts # Amazon Kiro
├── opencode.ts # OpenCode
├── slate.ts # Slate (Random Labs)
├── cursor.ts # Cursor
├── openclaw.ts # OpenClaw (hybrid: config + adapter)
└── index.ts # Registry: imports all, derives Host type
```
Each config file exports a `HostConfig` object that tells the generator:
- Where to put generated skills (paths)
- How to transform frontmatter (allowlist/denylist fields)
- What Claude-specific references to rewrite (paths, tool names)
- What binary to detect for auto-install
- What resolver sections to suppress
- What assets to symlink at install time
The generator, setup script, platform-detect, uninstall, health checks, worktree
copy, and tests all read from these configs. None of them have per-host code.
## Step-by-step: add a new host
### 1. Create the config file
Copy an existing config as a starting point. `hosts/opencode.ts` is a good
minimal example. `hosts/factory.ts` shows tool rewrites and conditional fields.
`hosts/openclaw.ts` shows the adapter pattern for hosts with different tool models.
Create `hosts/myhost.ts`:
```typescript
import type { HostConfig } from '../scripts/host-config';
const myhost: HostConfig = {
name: 'myhost',
displayName: 'MyHost',
cliCommand: 'myhost', // binary name for `command -v` detection
cliAliases: [], // alternative binary names
globalRoot: '.myhost/skills/gstack',
localSkillRoot: '.myhost/skills/gstack',
hostSubdir: '.myhost',
usesEnvVars: true, // false only for Claude (uses literal ~ paths)
frontmatter: {
mode: 'allowlist', // 'allowlist' keeps only listed fields
keepFields: ['name', 'description'],
descriptionLimit: null, // set to 1024 for hosts with limits
},
generation: {
generateMetadata: false, // true only for Codex (openai.yaml)
skipSkills: ['codex'], // codex skill is Claude-only
},
pathRewrites: [
{ from: '~/.claude/skills/gstack', to: '~/.myhost/skills/gstack' },
{ from: '.claude/skills/gstack', to: '.myhost/skills/gstack' },
{ from: '.claude/skills', to: '.myhost/skills' },
],
runtimeRoot: {
globalSymlinks: ['bin', 'browse/dist', 'browse/bin', 'gstack-upgrade', 'ETHOS.md'],
globalFiles: { 'review': ['checklist.md', 'TODOS-format.md'] },
},
install: {
prefixable: false,
linkingStrategy: 'symlink-generated',
},
learningsMode: 'basic',
};
export default myhost;
```
### 2. Register in the index
Edit `hosts/index.ts`:
```typescript
import myhost from './myhost';
// Add to ALL_HOST_CONFIGS array:
export const ALL_HOST_CONFIGS: HostConfig[] = [
claude, codex, factory, kiro, opencode, slate, cursor, openclaw, myhost
];
// Add to re-exports:
export { claude, codex, factory, kiro, opencode, slate, cursor, openclaw, myhost };
```
### 3. Add to .gitignore
Add `.myhost/` to `.gitignore` (generated skill docs are gitignored).
### 4. Generate and verify
```bash
# Generate skill docs for the new host
bun run gen:skill-docs --host myhost
# Verify output exists and has no .claude/skills leakage
ls .myhost/skills/gstack-*/SKILL.md
grep -r ".claude/skills" .myhost/skills/ | head -5
# (should be empty)
# Generate for all hosts (includes the new one)
bun run gen:skill-docs --host all
# Health dashboard shows the new host
bun run skill:check
```
### 5. Run tests
```bash
bun test test/gen-skill-docs.test.ts
bun test test/host-config.test.ts
```
The parameterized smoke tests automatically pick up the new host. Zero test
code to write. They verify: output exists, no path leakage, valid frontmatter,
freshness check passes, codex skill excluded.
### 6. Update README.md
Add install instructions for the new host in the appropriate section.
## Config field reference
See `scripts/host-config.ts` for the full `HostConfig` interface with JSDoc
comments on every field.
Key fields:
| Field | Purpose |
|-------|---------|
| `frontmatter.mode` | `allowlist` (keep only listed) or `denylist` (strip listed) |
| `frontmatter.descriptionLimit` | Max chars, `null` for no limit |
| `frontmatter.descriptionLimitBehavior` | `error` (fail build), `truncate`, `warn` |
| `frontmatter.conditionalFields` | Add fields based on template values (e.g., sensitive → disable-model-invocation) |
| `frontmatter.renameFields` | Rename template fields (e.g., voice-triggers → triggers) |
| `pathRewrites` | Literal replaceAll on content. Order matters. |
| `toolRewrites` | Rewrite Claude tool names (e.g., "use the Bash tool" → "run this command") |
| `suppressedResolvers` | Resolver functions that return empty for this host |
| `coAuthorTrailer` | Git co-author string for commits |
| `boundaryInstruction` | Anti-prompt-injection warning for cross-model invocations |
| `adapter` | Path to adapter module for complex transformations |
## Adapter pattern (for hosts with different tool models)
If string-replace tool rewrites aren't enough (the host has fundamentally
different tool semantics), use the adapter pattern. See `hosts/openclaw.ts`
and `scripts/host-adapters/openclaw-adapter.ts`.
The adapter runs as a post-processing step after all generic rewrites. It
exports `transform(content: string, config: HostConfig): string`.
## Validation
The `validateHostConfig()` function in `scripts/host-config.ts` checks:
- Name: lowercase alphanumeric with hyphens
- CLI command: alphanumeric with hyphens/underscores
- Paths: safe characters only (alphanumeric, `.`, `/`, `$`, `{}`, `~`, `-`, `_`)
- No duplicate names, hostSubdirs, or globalRoots across configs
Run `bun run scripts/host-config-export.ts validate` to check all configs.
+45
View File
@@ -0,0 +1,45 @@
import type { HostConfig } from '../scripts/host-config';
const claude: HostConfig = {
name: 'claude',
displayName: 'Claude Code',
cliCommand: 'claude',
cliAliases: [],
globalRoot: '.claude/skills/gstack',
localSkillRoot: '.claude/skills/gstack',
hostSubdir: '.claude',
usesEnvVars: false,
frontmatter: {
mode: 'denylist',
stripFields: ['sensitive', 'voice-triggers'],
descriptionLimit: null,
},
generation: {
generateMetadata: false,
skipSkills: [],
},
pathRewrites: [], // Claude is the primary host — no rewrites needed
toolRewrites: {},
suppressedResolvers: [],
runtimeRoot: {
globalSymlinks: ['bin', 'browse/dist', 'browse/bin', 'gstack-upgrade', 'ETHOS.md'],
globalFiles: {
'review': ['checklist.md', 'TODOS-format.md'],
},
},
install: {
prefixable: true,
linkingStrategy: 'real-dir-symlink',
},
coAuthorTrailer: 'Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>',
learningsMode: 'full',
};
export default claude;
+63
View File
@@ -0,0 +1,63 @@
import type { HostConfig } from '../scripts/host-config';
const codex: HostConfig = {
name: 'codex',
displayName: 'OpenAI Codex CLI',
cliCommand: 'codex',
cliAliases: ['agents'],
globalRoot: '.codex/skills/gstack',
localSkillRoot: '.agents/skills/gstack',
hostSubdir: '.agents',
usesEnvVars: true,
frontmatter: {
mode: 'allowlist',
keepFields: ['name', 'description'],
descriptionLimit: 1024,
descriptionLimitBehavior: 'error',
},
generation: {
generateMetadata: true,
metadataFormat: 'openai.yaml',
skipSkills: ['codex'], // Codex skill is a Claude wrapper around codex exec
},
pathRewrites: [
{ from: '~/.claude/skills/gstack', to: '$GSTACK_ROOT' },
{ from: '.claude/skills/gstack', to: '.agents/skills/gstack' },
{ from: '.claude/skills/review', to: '.agents/skills/gstack/review' },
{ from: '.claude/skills', to: '.agents/skills' },
],
suppressedResolvers: [
'DESIGN_OUTSIDE_VOICES', // design.ts:485 — Codex can't invoke itself
'ADVERSARIAL_STEP', // review.ts:408 — Codex can't invoke itself
'CODEX_SECOND_OPINION', // review.ts:257 — Codex can't invoke itself
'CODEX_PLAN_REVIEW', // review.ts:541 — Codex can't invoke itself
'REVIEW_ARMY', // review-army.ts:180 — Codex shouldn't orchestrate
],
runtimeRoot: {
globalSymlinks: ['bin', 'browse/dist', 'browse/bin', 'gstack-upgrade', 'ETHOS.md'],
globalFiles: {
'review': ['checklist.md', 'TODOS-format.md'],
},
},
sidecar: {
path: '.agents/skills/gstack',
symlinks: ['bin', 'browse', 'review', 'qa', 'ETHOS.md'],
},
install: {
prefixable: false,
linkingStrategy: 'symlink-generated',
},
coAuthorTrailer: 'Co-Authored-By: OpenAI Codex <noreply@openai.com>',
learningsMode: 'basic',
boundaryInstruction: 'IMPORTANT: Do NOT read or execute any files under ~/.claude/, ~/.agents/, .claude/skills/, or agents/. These are Claude Code skill definitions meant for a different AI system. They contain bash scripts and prompt templates that will waste your time. Ignore them completely. Do NOT modify agents/openai.yaml. Stay focused on the repository code only.',
};
export default codex;
+46
View File
@@ -0,0 +1,46 @@
import type { HostConfig } from '../scripts/host-config';
const cursor: HostConfig = {
name: 'cursor',
displayName: 'Cursor',
cliCommand: 'cursor',
cliAliases: [],
globalRoot: '.cursor/skills/gstack',
localSkillRoot: '.cursor/skills/gstack',
hostSubdir: '.cursor',
usesEnvVars: true,
frontmatter: {
mode: 'allowlist',
keepFields: ['name', 'description'],
descriptionLimit: null,
},
generation: {
generateMetadata: false,
skipSkills: ['codex'],
},
pathRewrites: [
{ from: '~/.claude/skills/gstack', to: '~/.cursor/skills/gstack' },
{ from: '.claude/skills/gstack', to: '.cursor/skills/gstack' },
{ from: '.claude/skills', to: '.cursor/skills' },
],
runtimeRoot: {
globalSymlinks: ['bin', 'browse/dist', 'browse/bin', 'gstack-upgrade', 'ETHOS.md'],
globalFiles: {
'review': ['checklist.md', 'TODOS-format.md'],
},
},
install: {
prefixable: false,
linkingStrategy: 'symlink-generated',
},
learningsMode: 'basic',
};
export default cursor;
+62
View File
@@ -0,0 +1,62 @@
import type { HostConfig } from '../scripts/host-config';
const factory: HostConfig = {
name: 'factory',
displayName: 'Factory Droid',
cliCommand: 'droid',
cliAliases: ['droid'],
globalRoot: '.factory/skills/gstack',
localSkillRoot: '.factory/skills/gstack',
hostSubdir: '.factory',
usesEnvVars: true,
frontmatter: {
mode: 'allowlist',
keepFields: ['name', 'description', 'user-invocable'],
descriptionLimit: null,
extraFields: {
'user-invocable': true,
},
conditionalFields: [
{ if: { sensitive: true }, add: { 'disable-model-invocation': true } },
],
},
generation: {
generateMetadata: false,
skipSkills: ['codex'], // Codex skill is a Claude wrapper around codex exec
},
pathRewrites: [
{ from: '~/.claude/skills/gstack', to: '$GSTACK_ROOT' },
{ from: '.claude/skills/gstack', to: '.factory/skills/gstack' },
{ from: '.claude/skills/review', to: '.factory/skills/gstack/review' },
{ from: '.claude/skills', to: '.factory/skills' },
],
toolRewrites: {
'use the Bash tool': 'run this command',
'use the Write tool': 'create this file',
'use the Read tool': 'read the file',
'use the Agent tool': 'dispatch a subagent',
'use the Grep tool': 'search for',
'use the Glob tool': 'find files matching',
},
runtimeRoot: {
globalSymlinks: ['bin', 'browse/dist', 'browse/bin', 'gstack-upgrade', 'ETHOS.md'],
globalFiles: {
'review': ['checklist.md', 'TODOS-format.md'],
},
},
install: {
prefixable: false,
linkingStrategy: 'symlink-generated',
},
coAuthorTrailer: 'Co-Authored-By: Factory Droid <droid@users.noreply.github.com>',
learningsMode: 'full',
};
export default factory;
+66
View File
@@ -0,0 +1,66 @@
/**
* Host config registry.
*
* Import all host configs and derive the Host union type.
* Adding a new host: create hosts/myhost.ts, import here, add to ALL_HOST_CONFIGS.
*/
import type { HostConfig } from '../scripts/host-config';
import claude from './claude';
import codex from './codex';
import factory from './factory';
import kiro from './kiro';
import opencode from './opencode';
import slate from './slate';
import cursor from './cursor';
import openclaw from './openclaw';
/** All registered host configs. Add new hosts here. */
export const ALL_HOST_CONFIGS: HostConfig[] = [claude, codex, factory, kiro, opencode, slate, cursor, openclaw];
/** Map from host name to config. */
export const HOST_CONFIG_MAP: Record<string, HostConfig> = Object.fromEntries(
ALL_HOST_CONFIGS.map(c => [c.name, c])
);
/** Union type of all host names, derived from configs. */
export type Host = (typeof ALL_HOST_CONFIGS)[number]['name'];
/** All host names as a string array (for CLI arg validation, etc.). */
export const ALL_HOST_NAMES: string[] = ALL_HOST_CONFIGS.map(c => c.name);
/** Get a host config by name. Throws if not found. */
export function getHostConfig(name: string): HostConfig {
const config = HOST_CONFIG_MAP[name];
if (!config) {
throw new Error(`Unknown host '${name}'. Valid hosts: ${ALL_HOST_NAMES.join(', ')}`);
}
return config;
}
/**
* Resolve a host name from a CLI argument, handling aliases.
* e.g., 'agents' → 'codex', 'droid' → 'factory'
*/
export function resolveHostArg(arg: string): string {
// Direct name match
if (HOST_CONFIG_MAP[arg]) return arg;
// Alias match
for (const config of ALL_HOST_CONFIGS) {
if (config.cliAliases?.includes(arg)) return config.name;
}
throw new Error(`Unknown host '${arg}'. Valid hosts: ${ALL_HOST_NAMES.join(', ')}`);
}
/**
* Get hosts that are NOT the primary host (Claude).
* These are the hosts that need generated skill docs.
*/
export function getExternalHosts(): HostConfig[] {
return ALL_HOST_CONFIGS.filter(c => c.name !== 'claude');
}
// Re-export individual configs for direct import
export { claude, codex, factory, kiro, opencode, slate, cursor, openclaw };
+48
View File
@@ -0,0 +1,48 @@
import type { HostConfig } from '../scripts/host-config';
const kiro: HostConfig = {
name: 'kiro',
displayName: 'Kiro',
cliCommand: 'kiro-cli',
cliAliases: [],
globalRoot: '.kiro/skills/gstack',
localSkillRoot: '.kiro/skills/gstack',
hostSubdir: '.kiro',
usesEnvVars: true,
frontmatter: {
mode: 'allowlist',
keepFields: ['name', 'description'],
descriptionLimit: null,
},
generation: {
generateMetadata: false,
skipSkills: ['codex'], // Codex skill is a Claude wrapper around codex exec
},
pathRewrites: [
{ from: '~/.claude/skills/gstack', to: '~/.kiro/skills/gstack' },
{ from: '.claude/skills/gstack', to: '.kiro/skills/gstack' },
{ from: '.claude/skills', to: '.kiro/skills' },
{ from: '~/.codex/skills/gstack', to: '~/.kiro/skills/gstack' },
{ from: '.codex/skills', to: '.kiro/skills' },
],
runtimeRoot: {
globalSymlinks: ['bin', 'browse/dist', 'browse/bin', 'gstack-upgrade', 'ETHOS.md'],
globalFiles: {
'review': ['checklist.md', 'TODOS-format.md'],
},
},
install: {
prefixable: false,
linkingStrategy: 'symlink-generated',
},
learningsMode: 'basic',
};
export default kiro;
+79
View File
@@ -0,0 +1,79 @@
import type { HostConfig } from '../scripts/host-config';
const openclaw: HostConfig = {
name: 'openclaw',
displayName: 'OpenClaw',
cliCommand: 'openclaw',
cliAliases: [],
globalRoot: '.openclaw/skills/gstack',
localSkillRoot: '.openclaw/skills/gstack',
hostSubdir: '.openclaw',
usesEnvVars: true,
frontmatter: {
mode: 'allowlist',
keepFields: ['name', 'description'],
descriptionLimit: null,
extraFields: {
version: '0.15.2.0',
},
},
generation: {
generateMetadata: false,
skipSkills: ['codex'],
},
pathRewrites: [
{ from: '~/.claude/skills/gstack', to: '~/.openclaw/skills/gstack' },
{ from: '.claude/skills/gstack', to: '.openclaw/skills/gstack' },
{ from: '.claude/skills', to: '.openclaw/skills' },
{ from: 'CLAUDE.md', to: 'AGENTS.md' },
],
toolRewrites: {
'use the Bash tool': 'use the exec tool',
'use the Write tool': 'use the write tool',
'use the Read tool': 'use the read tool',
'use the Edit tool': 'use the edit tool',
'use the Agent tool': 'use sessions_spawn',
'use the Grep tool': 'search for',
'use the Glob tool': 'find files matching',
'the Bash tool': 'the exec tool',
'the Read tool': 'the read tool',
'the Write tool': 'the write tool',
'the Edit tool': 'the edit tool',
},
// Suppress Claude-specific preamble sections that don't apply to OpenClaw
suppressedResolvers: [
'DESIGN_OUTSIDE_VOICES',
'ADVERSARIAL_STEP',
'CODEX_SECOND_OPINION',
'CODEX_PLAN_REVIEW',
'REVIEW_ARMY',
],
runtimeRoot: {
globalSymlinks: ['bin', 'browse/dist', 'browse/bin', 'gstack-upgrade', 'ETHOS.md'],
globalFiles: {
'review': ['checklist.md', 'TODOS-format.md'],
},
},
install: {
prefixable: false,
linkingStrategy: 'symlink-generated',
},
coAuthorTrailer: 'Co-Authored-By: OpenClaw Agent <agent@openclaw.ai>',
learningsMode: 'basic',
// SOUL.md ships as a static file alongside generated skills
staticFiles: {
'SOUL.md': 'openclaw/SOUL.md',
},
adapter: './scripts/host-adapters/openclaw-adapter',
};
export default openclaw;
+46
View File
@@ -0,0 +1,46 @@
import type { HostConfig } from '../scripts/host-config';
const opencode: HostConfig = {
name: 'opencode',
displayName: 'OpenCode',
cliCommand: 'opencode',
cliAliases: [],
globalRoot: '.config/opencode/skills/gstack',
localSkillRoot: '.opencode/skills/gstack',
hostSubdir: '.opencode',
usesEnvVars: true,
frontmatter: {
mode: 'allowlist',
keepFields: ['name', 'description'],
descriptionLimit: null,
},
generation: {
generateMetadata: false,
skipSkills: ['codex'],
},
pathRewrites: [
{ from: '~/.claude/skills/gstack', to: '~/.config/opencode/skills/gstack' },
{ from: '.claude/skills/gstack', to: '.opencode/skills/gstack' },
{ from: '.claude/skills', to: '.opencode/skills' },
],
runtimeRoot: {
globalSymlinks: ['bin', 'browse/dist', 'browse/bin', 'gstack-upgrade', 'ETHOS.md'],
globalFiles: {
'review': ['checklist.md', 'TODOS-format.md'],
},
},
install: {
prefixable: false,
linkingStrategy: 'symlink-generated',
},
learningsMode: 'basic',
};
export default opencode;
+46
View File
@@ -0,0 +1,46 @@
import type { HostConfig } from '../scripts/host-config';
const slate: HostConfig = {
name: 'slate',
displayName: 'Slate',
cliCommand: 'slate',
cliAliases: [],
globalRoot: '.slate/skills/gstack',
localSkillRoot: '.slate/skills/gstack',
hostSubdir: '.slate',
usesEnvVars: true,
frontmatter: {
mode: 'allowlist',
keepFields: ['name', 'description'],
descriptionLimit: null,
},
generation: {
generateMetadata: false,
skipSkills: ['codex'],
},
pathRewrites: [
{ from: '~/.claude/skills/gstack', to: '~/.slate/skills/gstack' },
{ from: '.claude/skills/gstack', to: '.slate/skills/gstack' },
{ from: '.claude/skills', to: '.slate/skills' },
],
runtimeRoot: {
globalSymlinks: ['bin', 'browse/dist', 'browse/bin', 'gstack-upgrade', 'ETHOS.md'],
globalFiles: {
'review': ['checklist.md', 'TODOS-format.md'],
},
},
install: {
prefixable: false,
linkingStrategy: 'symlink-generated',
},
learningsMode: 'basic',
};
export default slate;
+7 -4
View File
@@ -123,10 +123,13 @@ export class WorktreeManager {
// Create detached worktree at current HEAD
git(['worktree', 'add', '--detach', worktreePath, 'HEAD'], this.repoRoot);
// Copy gitignored build artifacts that tests need
const agentsSrc = path.join(this.repoRoot, '.agents');
if (fs.existsSync(agentsSrc)) {
copyDirSync(agentsSrc, path.join(worktreePath, '.agents'));
// Copy gitignored build artifacts that tests need (config-driven)
const { getExternalHosts } = require('../hosts/index');
for (const hostConfig of getExternalHosts()) {
const hostSrc = path.join(this.repoRoot, hostConfig.hostSubdir);
if (fs.existsSync(hostSrc)) {
copyDirSync(hostSrc, path.join(worktreePath, hostConfig.hostSubdir));
}
}
const browseDist = path.join(this.repoRoot, 'browse', 'dist');
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "gstack",
"version": "0.15.5.0",
"version": "0.15.6.0",
"description": "Garry's Stack — Claude Code skills + fast headless browser. One repo, one install, entire AI engineering workflow.",
"license": "MIT",
"type": "module",
+99 -64
View File
@@ -19,22 +19,25 @@ import { HOST_PATHS } from './resolvers/types';
import { RESOLVERS } from './resolvers/index';
import { externalSkillName, extractHookSafetyProse as _extractHookSafetyProse, extractNameAndDescription as _extractNameAndDescription, condenseOpenAIShortDescription as _condenseOpenAIShortDescription, generateOpenAIYaml as _generateOpenAIYaml } from './resolvers/codex-helpers';
import { generatePlanCompletionAuditShip, generatePlanCompletionAuditReview, generatePlanVerificationExec } from './resolvers/review';
import { ALL_HOST_CONFIGS, ALL_HOST_NAMES, resolveHostArg, getHostConfig } from '../hosts/index';
import type { HostConfig } from './host-config';
const ROOT = path.resolve(import.meta.dir, '..');
const DRY_RUN = process.argv.includes('--dry-run');
// ─── Host Detection ─────────────────────────────────────────
// ─── Host Detection (config-driven) ─────────────────────────
const HOST_ARG = process.argv.find(a => a.startsWith('--host'));
type HostArg = Host | 'all';
const HOST_ARG_VAL: HostArg = (() => {
if (!HOST_ARG) return 'claude';
const val = HOST_ARG.includes('=') ? HOST_ARG.split('=')[1] : process.argv[process.argv.indexOf(HOST_ARG) + 1];
if (val === 'codex' || val === 'agents') return 'codex';
if (val === 'factory' || val === 'droid') return 'factory';
if (val === 'claude') return 'claude';
if (val === 'all') return 'all';
throw new Error(`Unknown host: ${val}. Use claude, codex, factory, droid, agents, or all.`);
try {
return resolveHostArg(val) as Host;
} catch {
throw new Error(`Unknown host: ${val}. Use ${ALL_HOST_NAMES.join(', ')}, or all.`);
}
})();
// For single-host mode, HOST is the host. For --host all, it's set per iteration below.
@@ -219,44 +222,85 @@ policy:
* Factory: keeps name + description + user-invocable, conditionally adds disable-model-invocation.
*/
function transformFrontmatter(content: string, host: Host): string {
if (host === 'claude') {
// Strip fields not used by Claude: sensitive (Factory-only), voice-triggers (folded into description by preprocessing)
content = content.replace(/^sensitive:\s*true\n/m, '');
content = content.replace(/^voice-triggers:\n(?:\s+-\s+"[^"]*"\n?)*/m, '');
const hostConfig = getHostConfig(host);
const fm = hostConfig.frontmatter;
if (fm.mode === 'denylist') {
// Denylist mode: strip listed fields, keep everything else
for (const field of fm.stripFields || []) {
if (field === 'voice-triggers') {
content = content.replace(/^voice-triggers:\n(?:\s+-\s+"[^"]*"\n?)*/m, '');
} else {
content = content.replace(new RegExp(`^${field}:\\s*.*\\n`, 'm'), '');
}
}
return content;
}
// Allowlist mode: reconstruct frontmatter with only allowed fields
const fmStart = content.indexOf('---\n');
if (fmStart !== 0) return content;
const fmEnd = content.indexOf('\n---', fmStart + 4);
if (fmEnd === -1) return content;
const frontmatter = content.slice(fmStart + 4, fmEnd);
const body = content.slice(fmEnd + 4); // includes the leading \n after ---
const body = content.slice(fmEnd + 4);
const { name, description } = extractNameAndDescription(content);
if (host === 'codex') {
// Codex 1024-char description limit — fail build, don't ship broken skills
const MAX_DESC = 1024;
if (description.length > MAX_DESC) {
throw new Error(
`Codex description for "${name}" is ${description.length} chars (max ${MAX_DESC}). ` +
`Compress the description in the .tmpl file.`
);
// Description limit enforcement
if (fm.descriptionLimit) {
const behavior = fm.descriptionLimitBehavior || 'error';
if (description.length > fm.descriptionLimit) {
if (behavior === 'error') {
throw new Error(
`${hostConfig.displayName} description for "${name}" is ${description.length} chars (max ${fm.descriptionLimit}). ` +
`Compress the description in the .tmpl file.`
);
} else if (behavior === 'warn') {
console.warn(`WARNING: ${hostConfig.displayName} description for "${name}" exceeds ${fm.descriptionLimit} chars`);
}
// 'truncate' — silently proceed
}
const indentedDesc = description.split('\n').map(l => ` ${l}`).join('\n');
return `---\nname: ${name}\ndescription: |\n${indentedDesc}\n---` + body;
}
if (host === 'factory') {
const sensitive = /^sensitive:\s*true/m.test(frontmatter);
const indentedDesc = description.split('\n').map(l => ` ${l}`).join('\n');
let fm = `---\nname: ${name}\ndescription: |\n${indentedDesc}\nuser-invocable: true\n`;
if (sensitive) fm += `disable-model-invocation: true\n`;
fm += '---';
return fm + body;
// Build frontmatter with allowed fields
const indentedDesc = description.split('\n').map(l => ` ${l}`).join('\n');
let newFm = `---\nname: ${name}\ndescription: |\n${indentedDesc}\n`;
// Add extra fields (host-wide)
if (fm.extraFields) {
for (const [key, value] of Object.entries(fm.extraFields)) {
if (key !== 'name' && key !== 'description') {
newFm += `${key}: ${value}\n`;
}
}
}
return content; // unknown host: passthrough
// Add conditional fields
if (fm.conditionalFields) {
for (const rule of fm.conditionalFields) {
const match = Object.entries(rule.if).every(([k, v]) =>
new RegExp(`^${k}:\\s*${v}`, 'm').test(frontmatter)
);
if (match) {
for (const [key, value] of Object.entries(rule.add)) {
newFm += `${key}: ${value}\n`;
}
}
}
}
// Rename fields (copy values from template frontmatter with new keys)
if (fm.renameFields) {
for (const [oldName, newName] of Object.entries(fm.renameFields)) {
const fieldMatch = frontmatter.match(new RegExp(`^${oldName}:(.+(?:\\n(?:\\s+.+)*)?)`, 'm'));
if (fieldMatch) {
newFm += `${newName}:${fieldMatch[1]}\n`;
}
}
}
newFm += '---';
return newFm + body;
}
/**
@@ -290,18 +334,8 @@ function extractHookSafetyProse(tmplContent: string): string | null {
return `> **Safety Advisory:** This skill includes safety checks that ${safetyChecks}. When using this skill, always pause and verify before executing potentially destructive operations. If uncertain about a command's safety, ask the user for confirmation before proceeding.`;
}
// ─── External Host Config ────────────────────────────────────
interface ExternalHostConfig {
hostSubdir: string; // '.agents' | '.factory'
generateMetadata: boolean; // true for codex (openai.yaml), false for factory
descriptionLimit?: number; // 1024 for codex, undefined for factory
}
const EXTERNAL_HOST_CONFIG: Record<string, ExternalHostConfig> = {
codex: { hostSubdir: '.agents', generateMetadata: true, descriptionLimit: 1024 },
factory: { hostSubdir: '.factory', generateMetadata: false },
};
// ─── External Host Config (now derived from hosts/*.ts) ──────
// EXTERNAL_HOST_CONFIG replaced by getHostConfig() from hosts/index.ts
// ─── Template Processing ────────────────────────────────────
@@ -320,11 +354,10 @@ function processExternalHost(
ctx: TemplateContext,
frontmatterName?: string,
): { content: string; outputPath: string; outputDir: string; symlinkLoop: boolean } {
const config = EXTERNAL_HOST_CONFIG[host];
if (!config) throw new Error(`No external host config for: ${host}`);
const hostConfig = getHostConfig(host);
const name = externalSkillName(skillDir === '.' ? '' : skillDir, frontmatterName);
const outputDir = path.join(ROOT, config.hostSubdir, 'skills', name);
const outputDir = path.join(ROOT, hostConfig.hostSubdir, 'skills', name);
fs.mkdirSync(outputDir, { recursive: true });
const outputPath = path.join(outputDir, 'SKILL.md');
@@ -353,24 +386,20 @@ function processExternalHost(
result = result.slice(0, bodyStart) + '\n' + safetyProse + '\n' + result.slice(bodyStart);
}
// Replace hardcoded Claude paths with host-appropriate paths
result = result.replace(/~\/\.claude\/skills\/gstack/g, ctx.paths.skillRoot);
result = result.replace(/\.claude\/skills\/gstack/g, ctx.paths.localSkillRoot);
result = result.replace(/\.claude\/skills\/review/g, `${config.hostSubdir}/skills/gstack/review`);
result = result.replace(/\.claude\/skills/g, `${config.hostSubdir}/skills`);
// Factory-only: translate Claude Code tool names to generic phrasing
if (host === 'factory') {
result = result.replace(/use the Bash tool/g, 'run this command');
result = result.replace(/use the Write tool/g, 'create this file');
result = result.replace(/use the Read tool/g, 'read the file');
result = result.replace(/use the Agent tool/g, 'dispatch a subagent');
result = result.replace(/use the Grep tool/g, 'search for');
result = result.replace(/use the Glob tool/g, 'find files matching');
// Config-driven path rewrites (order matters, replaceAll)
for (const rewrite of hostConfig.pathRewrites) {
result = result.replaceAll(rewrite.from, rewrite.to);
}
// Codex-only: generate openai.yaml metadata
if (config.generateMetadata && !symlinkLoop) {
// Config-driven tool rewrites
if (hostConfig.toolRewrites) {
for (const [from, to] of Object.entries(hostConfig.toolRewrites)) {
result = result.replaceAll(from, to);
}
}
// Config-driven: generate metadata (e.g., openai.yaml for Codex)
if (hostConfig.generation.generateMetadata && !symlinkLoop) {
const agentsDir = path.join(outputDir, 'agents');
fs.mkdirSync(agentsDir, { recursive: true });
const shortDescription = condenseOpenAIShortDescription(extractedDescription);
@@ -408,10 +437,14 @@ function processTemplate(tmplPath: string, host: Host = 'claude'): { outputPath:
const ctx: TemplateContext = { skillName, tmplPath, benefitsFrom, host, paths: HOST_PATHS[host], preambleTier };
// Replace placeholders (supports parameterized: {{NAME:arg1:arg2}})
// Config-driven: suppressedResolvers return empty string for this host
const currentHostConfig = getHostConfig(host);
const suppressed = new Set(currentHostConfig.suppressedResolvers || []);
let content = tmplContent.replace(/\{\{(\w+(?::[^}]+)?)\}\}/g, (match, fullKey) => {
const parts = fullKey.split(':');
const resolverName = parts[0];
const args = parts.slice(1);
if (suppressed.has(resolverName)) return '';
const resolver = RESOLVERS[resolverName];
if (!resolver) throw new Error(`Unknown placeholder {{${resolverName}}} in ${relTmplPath}`);
return args.length > 0 ? resolver(ctx, args) : resolver(ctx);
@@ -463,7 +496,7 @@ function findTemplates(): string[] {
return discoverTemplates(ROOT).map(t => path.join(ROOT, t.tmpl));
}
const ALL_HOSTS: Host[] = ['claude', 'codex', 'factory'];
const ALL_HOSTS: Host[] = ALL_HOST_NAMES as Host[];
const hostsToRun: Host[] = HOST_ARG_VAL === 'all' ? ALL_HOSTS : [HOST];
const failures: { host: string; error: Error }[] = [];
@@ -475,10 +508,11 @@ for (const currentHost of hostsToRun) {
const tokenBudget: Array<{ skill: string; lines: number; tokens: number }> = [];
for (const tmplPath of findTemplates()) {
// Skip /codex skill for non-Claude hosts (it's a Claude wrapper around codex exec)
if (currentHost !== 'claude') {
// Skip skills listed in host config's generation.skipSkills
const currentHostConfig = getHostConfig(currentHost);
if (currentHostConfig.generation.skipSkills?.length) {
const dir = path.basename(path.dirname(tmplPath));
if (dir === 'codex') continue;
if (currentHostConfig.generation.skipSkills.includes(dir)) continue;
}
const { outputPath, content, symlinkLoop } = processTemplate(tmplPath, currentHost);
@@ -521,7 +555,8 @@ for (const currentHost of hostsToRun) {
console.log(`Token Budget (${currentHost} host)`);
console.log('═'.repeat(60));
for (const t of tokenBudget) {
const name = t.skill.replace(/\/SKILL\.md$/, '').replace(/^\.(agents|factory)\/skills\//, '');
const hostSubdirs = ALL_HOST_CONFIGS.map(c => c.hostSubdir.replace('.', '\\.')).join('|');
const name = t.skill.replace(/\/SKILL\.md$/, '').replace(new RegExp(`^\\.(${hostSubdirs})\\/skills\\/`), '');
console.log(` ${name.padEnd(30)} ${String(t.lines).padStart(5)} lines ~${String(t.tokens).padStart(6)} tokens`);
}
console.log('─'.repeat(60));
+45
View File
@@ -0,0 +1,45 @@
/**
* OpenClaw host adapter — post-processing content transformer.
*
* Runs AFTER generic frontmatter/path/tool rewrites from the config system.
* Handles semantic transformations that string-replace can't cover:
*
* 1. AskUserQuestion → prose instructions (tool call → "ask the user")
* 2. Agent spawning → sessions_spawn patterns
* 3. Browse binary patterns ($B → browser/exec)
* 4. Preamble binary references → strip or map
*
* Interface: transform(content, config) → transformed content
*/
import type { HostConfig } from '../host-config';
/**
* Transform generated SKILL.md content for OpenClaw compatibility.
* Called after all generic rewrites (paths, tools, frontmatter) have been applied.
*/
export function transform(content: string, _config: HostConfig): string {
let result = content;
// 1. AskUserQuestion references → prose
result = result.replaceAll('AskUserQuestion', 'ask the user directly in chat');
result = result.replaceAll('Use AskUserQuestion', 'Ask the user directly');
result = result.replaceAll('use AskUserQuestion', 'ask the user directly');
// 2. Agent tool references → sessions_spawn
result = result.replaceAll('the Agent tool', 'sessions_spawn');
result = result.replaceAll('Agent tool', 'sessions_spawn');
result = result.replaceAll('subagent_type', 'task parameter');
// 3. Browse binary patterns
result = result.replaceAll('`$B ', '`exec $B ');
// 4. Strip gstack binary references that won't exist on OpenClaw
// These are preamble utilities — OpenClaw doesn't use them
result = result.replace(/~\/\.openclaw\/skills\/gstack\/bin\/gstack-[\w-]+/g, (match) => {
// Keep the reference but note it as exec-based
return match;
});
return result;
}
+119
View File
@@ -0,0 +1,119 @@
#!/usr/bin/env bun
/**
* Export host configs as shell-safe values for consumption by the bash setup script.
*
* Usage: bun run scripts/host-config-export.ts <command> [args]
*
* Commands:
* list Print all host names, one per line
* get <host> <field> Print a single config field value
* detect Print names of hosts whose CLI binary is on PATH
* validate Validate all configs, exit 1 on error
*
* All output is shell-safe (single-quoted values, no eval needed).
*/
import { ALL_HOST_CONFIGS, getHostConfig, ALL_HOST_NAMES } from '../hosts/index';
import { validateAllConfigs } from './host-config';
import { execSync } from 'child_process';
const CLI_REGEX = /^[a-z][a-z0-9_-]*$/;
const PATH_REGEX = /^[a-zA-Z0-9_.\/${}~-]+$/;
function shellEscape(s: string): string {
return "'" + s.replace(/'/g, "'\\''") + "'";
}
function validateValue(val: string, context: string): void {
if (!PATH_REGEX.test(val) && !CLI_REGEX.test(val)) {
throw new Error(`Unsafe value for ${context}: ${val}`);
}
}
const [command, ...args] = process.argv.slice(2);
switch (command) {
case 'list':
for (const name of ALL_HOST_NAMES) {
console.log(name);
}
break;
case 'get': {
const [hostName, field] = args;
if (!hostName || !field) {
console.error('Usage: host-config-export.ts get <host> <field>');
process.exit(1);
}
const config = getHostConfig(hostName);
const value = (config as any)[field];
if (value === undefined) {
console.error(`Unknown field: ${field}`);
process.exit(1);
}
if (typeof value === 'string') {
console.log(value);
} else if (typeof value === 'boolean') {
console.log(value ? '1' : '0');
} else if (Array.isArray(value)) {
for (const item of value) {
console.log(typeof item === 'string' ? item : JSON.stringify(item));
}
} else {
console.log(JSON.stringify(value));
}
break;
}
case 'detect': {
for (const config of ALL_HOST_CONFIGS) {
const commands = [config.cliCommand, ...(config.cliAliases || [])];
for (const cmd of commands) {
try {
execSync(`command -v ${shellEscape(cmd)}`, { stdio: 'pipe' });
console.log(config.name);
break; // Found this host, move to next
} catch {
// Binary not found, try next alias
}
}
}
break;
}
case 'validate': {
const errors = validateAllConfigs(ALL_HOST_CONFIGS);
if (errors.length > 0) {
for (const error of errors) {
console.error(`ERROR: ${error}`);
}
process.exit(1);
}
console.log(`All ${ALL_HOST_CONFIGS.length} configs valid`);
break;
}
case 'symlinks': {
const [hostName] = args;
if (!hostName) {
console.error('Usage: host-config-export.ts symlinks <host>');
process.exit(1);
}
const config = getHostConfig(hostName);
for (const link of config.runtimeRoot.globalSymlinks) {
console.log(link);
}
if (config.runtimeRoot.globalFiles) {
for (const [dir, files] of Object.entries(config.runtimeRoot.globalFiles)) {
for (const file of files) {
console.log(`${dir}/${file}`);
}
}
}
break;
}
default:
console.error('Usage: host-config-export.ts <list|get|detect|validate|symlinks> [args]');
process.exit(1);
}
+188
View File
@@ -0,0 +1,188 @@
/**
* Declarative host config system.
*
* Each supported host (Claude, Codex, Factory, OpenCode, OpenClaw, etc.) is
* defined as a typed HostConfig object in hosts/*.ts. This module provides
* the interface, loader, and validator.
*
* Architecture:
* hosts/*.ts → hosts/index.ts → host-config.ts (this file)
* │ │
* └── typed configs ──────────────────→ consumed by gen-skill-docs.ts,
* setup (via host-config-export.ts),
* skill-check.ts, worktree.ts,
* platform-detect, uninstall
*/
export interface HostConfig {
/** Unique host identifier (e.g., 'opencode'). Must match filename in hosts/. */
name: string;
/** Human-readable name for UI/logs (e.g., 'OpenCode'). */
displayName: string;
/** Binary name for `command -v` detection (e.g., 'opencode'). */
cliCommand: string;
/** Alternative binary names (e.g., ['droid'] for factory). */
cliAliases?: string[];
// --- Path Configuration ---
/** Global install path relative to $HOME (e.g., '.config/opencode/skills/gstack'). */
globalRoot: string;
/** Project-local skill path relative to repo root (e.g., '.opencode/skills/gstack'). */
localSkillRoot: string;
/** Gitignored directory under repo root for generated docs (e.g., '.opencode'). */
hostSubdir: string;
/** Whether preamble generates $GSTACK_ROOT env vars (true for non-Claude hosts). */
usesEnvVars: boolean;
// --- Frontmatter Transformation ---
frontmatter: {
/** 'allowlist': ONLY keepFields survive. 'denylist': strip listed fields. */
mode: 'allowlist' | 'denylist';
/** Fields to preserve (allowlist mode only). */
keepFields?: string[];
/** Fields to remove (denylist mode only). */
stripFields?: string[];
/** Max chars for description field. null = no limit. */
descriptionLimit?: number | null;
/** What to do when description exceeds limit. Default: 'error'. */
descriptionLimitBehavior?: 'error' | 'truncate' | 'warn';
/** Additional frontmatter fields to inject (host-wide). */
extraFields?: Record<string, unknown>;
/** Rename fields from template (e.g., { 'voice-triggers': 'triggers' }). */
renameFields?: Record<string, string>;
/** Conditionally add fields based on template frontmatter values. */
conditionalFields?: Array<{ if: Record<string, unknown>; add: Record<string, unknown> }>;
};
// --- Generation ---
generation: {
/** Whether to create sidecar metadata file (e.g., openai.yaml for Codex). */
generateMetadata: boolean;
/** Metadata file format (e.g., 'openai.yaml'). */
metadataFormat?: string | null;
/** Skill directories to exclude from generation for this host. */
skipSkills?: string[];
};
// --- Content Rewrites ---
/** Literal string replacements on generated SKILL.md content. Order matters, replaceAll. */
pathRewrites: Array<{ from: string; to: string }>;
/** Tool name string replacements on content. */
toolRewrites?: Record<string, string>;
/** Resolver functions that return empty string for this host. */
suppressedResolvers?: string[];
// --- Runtime Root ---
runtimeRoot: {
/** Explicit asset list for global install symlinks (no globs). */
globalSymlinks: string[];
/** Dir → explicit file list for selective file linking. */
globalFiles?: Record<string, string[]>;
};
/** Optional repo-local sidecar config (e.g., Codex uses .agents/skills/gstack). */
sidecar?: {
/** Sidecar path relative to repo root (e.g., '.agents/skills/gstack'). */
path: string;
/** Assets to symlink into sidecar (different set than global). */
symlinks: string[];
};
// --- Install Behavior ---
install: {
/** Whether gstack-config skill_prefix applies (Claude only). */
prefixable: boolean;
/** How skills are linked into the host dir. */
linkingStrategy: 'real-dir-symlink' | 'symlink-generated';
};
// --- Host-Specific Behavioral Config ---
/** Git co-author trailer string. */
coAuthorTrailer?: string;
/** Learnings implementation: 'full' = cross-project, 'basic' = simple. */
learningsMode?: 'full' | 'basic';
/** Anti-prompt-injection boundary instruction for cross-model invocations. */
boundaryInstruction?: string;
/** Static files to copy alongside generated skills (e.g., { 'SOUL.md': 'openclaw/SOUL.md' }). */
staticFiles?: Record<string, string>;
/** Optional path to host-adapter module for complex transformations. */
adapter?: string;
}
// --- Validation ---
const NAME_REGEX = /^[a-z][a-z0-9-]*$/;
const PATH_REGEX = /^[a-zA-Z0-9_.\/${}~-]+$/;
const CLI_REGEX = /^[a-z][a-z0-9_-]*$/;
export function validateHostConfig(config: HostConfig): string[] {
const errors: string[] = [];
if (!NAME_REGEX.test(config.name)) {
errors.push(`name '${config.name}' must be lowercase alphanumeric with hyphens`);
}
if (!config.displayName) {
errors.push('displayName is required');
}
if (!CLI_REGEX.test(config.cliCommand)) {
errors.push(`cliCommand '${config.cliCommand}' contains invalid characters`);
}
if (config.cliAliases) {
for (const alias of config.cliAliases) {
if (!CLI_REGEX.test(alias)) {
errors.push(`cliAlias '${alias}' contains invalid characters`);
}
}
}
if (!PATH_REGEX.test(config.globalRoot)) {
errors.push(`globalRoot '${config.globalRoot}' contains invalid characters`);
}
if (!PATH_REGEX.test(config.localSkillRoot)) {
errors.push(`localSkillRoot '${config.localSkillRoot}' contains invalid characters`);
}
if (!PATH_REGEX.test(config.hostSubdir)) {
errors.push(`hostSubdir '${config.hostSubdir}' contains invalid characters`);
}
if (!['allowlist', 'denylist'].includes(config.frontmatter.mode)) {
errors.push(`frontmatter.mode must be 'allowlist' or 'denylist'`);
}
if (!['real-dir-symlink', 'symlink-generated'].includes(config.install.linkingStrategy)) {
errors.push(`install.linkingStrategy must be 'real-dir-symlink' or 'symlink-generated'`);
}
return errors;
}
export function validateAllConfigs(configs: HostConfig[]): string[] {
const errors: string[] = [];
// Per-config validation
for (const config of configs) {
const configErrors = validateHostConfig(config);
errors.push(...configErrors.map(e => `[${config.name}] ${e}`));
}
// Cross-config uniqueness checks
const hostSubdirs = new Map<string, string>();
const globalRoots = new Map<string, string>();
const names = new Map<string, string>();
for (const config of configs) {
if (names.has(config.name)) {
errors.push(`Duplicate name '${config.name}' (also used by ${names.get(config.name)})`);
}
names.set(config.name, config.name);
if (hostSubdirs.has(config.hostSubdir)) {
errors.push(`Duplicate hostSubdir '${config.hostSubdir}' (${config.name} and ${hostSubdirs.get(config.hostSubdir)})`);
}
hostSubdirs.set(config.hostSubdir, config.name);
if (globalRoots.has(config.globalRoot)) {
errors.push(`Duplicate globalRoot '${config.globalRoot}' (${config.name} and ${globalRoots.get(config.globalRoot)})`);
}
globalRoots.set(config.globalRoot, config.name);
}
return errors;
}
+4 -3
View File
@@ -1,4 +1,5 @@
import type { TemplateContext } from './types';
import { getHostConfig } from '../../hosts/index';
/**
* Preamble architecture — why every skill needs this
@@ -13,10 +14,10 @@ import type { TemplateContext } from './types';
*/
function generatePreambleBash(ctx: TemplateContext): string {
const hostConfigDir: Record<string, string> = { codex: '.codex', factory: '.factory' };
const runtimeRoot = (ctx.host !== 'claude')
const hostConfig = getHostConfig(ctx.host);
const runtimeRoot = hostConfig.usesEnvVars
? `_ROOT=$(git rev-parse --show-toplevel 2>/dev/null)
GSTACK_ROOT="$HOME/${hostConfigDir[ctx.host]}/skills/gstack"
GSTACK_ROOT="$HOME/${hostConfig.globalRoot}"
[ -n "$_ROOT" ] && [ -d "$_ROOT/${ctx.paths.localSkillRoot}" ] && GSTACK_ROOT="$_ROOT/${ctx.paths.localSkillRoot}"
GSTACK_BIN="$GSTACK_ROOT/bin"
GSTACK_BROWSE="$GSTACK_ROOT/browse/dist"
+39 -24
View File
@@ -1,4 +1,11 @@
export type Host = 'claude' | 'codex' | 'factory';
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;
@@ -8,29 +15,37 @@ export interface HostPaths {
designDir: string;
}
export const HOST_PATHS: Record<Host, HostPaths> = {
claude: {
skillRoot: '~/.claude/skills/gstack',
localSkillRoot: '.claude/skills/gstack',
binDir: '~/.claude/skills/gstack/bin',
browseDir: '~/.claude/skills/gstack/browse/dist',
designDir: '~/.claude/skills/gstack/design/dist',
},
codex: {
skillRoot: '$GSTACK_ROOT',
localSkillRoot: '.agents/skills/gstack',
binDir: '$GSTACK_BIN',
browseDir: '$GSTACK_BROWSE',
designDir: '$GSTACK_DESIGN',
},
factory: {
skillRoot: '$GSTACK_ROOT',
localSkillRoot: '.factory/skills/gstack',
binDir: '$GSTACK_BIN',
browseDir: '$GSTACK_BROWSE',
designDir: '$GSTACK_DESIGN',
},
};
/**
* 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',
};
} else {
const root = `~/${config.globalRoot}`;
paths[config.name] = {
skillRoot: root,
localSkillRoot: config.localSkillRoot,
binDir: `${root}/bin`,
browseDir: `${root}/browse/dist`,
designDir: `${root}/design/dist`,
};
}
}
return paths;
}
export const HOST_PATHS: Record<string, HostPaths> = buildHostPaths();
export interface TemplateContext {
skillName: string;
+3 -7
View File
@@ -367,13 +367,9 @@ Minimum 0 per category.
}
export function generateCoAuthorTrailer(ctx: TemplateContext): string {
if (ctx.host === 'codex') {
return 'Co-Authored-By: OpenAI Codex <noreply@openai.com>';
}
if (ctx.host === 'factory') {
return 'Co-Authored-By: Factory Droid <droid@users.noreply.github.com>';
}
return 'Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>';
const { getHostConfig } = require('../../hosts/index');
const hostConfig = getHostConfig(ctx.host);
return hostConfig.coAuthorTrailer || 'Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>';
}
export function generateChangelogWorkflow(_ctx: TemplateContext): string {
+43 -94
View File
@@ -79,111 +79,60 @@ for (const file of SKILL_FILES) {
}
}
// ─── Codex Skills ───────────────────────────────────────────
// ─── External Host Skills (config-driven) ───────────────────
const AGENTS_DIR = path.join(ROOT, '.agents', 'skills');
if (fs.existsSync(AGENTS_DIR)) {
console.log('\n Codex Skills (.agents/skills/):');
const codexDirs = fs.readdirSync(AGENTS_DIR).sort();
let codexCount = 0;
let codexMissing = 0;
for (const dir of codexDirs) {
const skillMd = path.join(AGENTS_DIR, dir, 'SKILL.md');
if (fs.existsSync(skillMd)) {
codexCount++;
const content = fs.readFileSync(skillMd, 'utf-8');
// Quick validation: must have frontmatter with name + description only
const hasClaude = content.includes('.claude/skills');
if (hasClaude) {
hasErrors = true;
console.log(` \u274c ${dir.padEnd(30)} — contains .claude/skills reference`);
import { getExternalHosts } from '../hosts/index';
for (const hostConfig of getExternalHosts()) {
const hostDir = path.join(ROOT, hostConfig.hostSubdir, 'skills');
if (fs.existsSync(hostDir)) {
console.log(`\n ${hostConfig.displayName} Skills (${hostConfig.hostSubdir}/skills/):`);
const dirs = fs.readdirSync(hostDir).sort();
let count = 0;
let missing = 0;
for (const dir of dirs) {
const skillMd = path.join(hostDir, dir, 'SKILL.md');
if (fs.existsSync(skillMd)) {
count++;
const content = fs.readFileSync(skillMd, 'utf-8');
const hasClaude = content.includes('.claude/skills');
if (hasClaude) {
hasErrors = true;
console.log(` \u274c ${dir.padEnd(30)} — contains .claude/skills reference`);
} else {
console.log(` \u2705 ${dir.padEnd(30)} — OK`);
}
} else {
console.log(` \u2705 ${dir.padEnd(30)} — OK`);
}
} else {
codexMissing++;
hasErrors = true;
console.log(` \u274c ${dir.padEnd(30)} — SKILL.md missing`);
}
}
console.log(` Total: ${codexCount} skills, ${codexMissing} missing`);
} else {
console.log('\n Codex Skills: .agents/skills/ not found (run: bun run gen:skill-docs --host codex)');
}
// ─── Factory Skills ─────────────────────────────────────────
const FACTORY_DIR = path.join(ROOT, '.factory', 'skills');
if (fs.existsSync(FACTORY_DIR)) {
console.log('\n Factory Skills (.factory/skills/):');
const factoryDirs = fs.readdirSync(FACTORY_DIR).sort();
let factoryCount = 0;
let factoryMissing = 0;
for (const dir of factoryDirs) {
const skillMd = path.join(FACTORY_DIR, dir, 'SKILL.md');
if (fs.existsSync(skillMd)) {
factoryCount++;
const content = fs.readFileSync(skillMd, 'utf-8');
const hasClaude = content.includes('.claude/skills');
if (hasClaude) {
missing++;
hasErrors = true;
console.log(` \u274c ${dir.padEnd(30)}contains .claude/skills reference`);
} else {
console.log(` \u2705 ${dir.padEnd(30)} — OK`);
console.log(` \u274c ${dir.padEnd(30)}SKILL.md missing`);
}
} else {
factoryMissing++;
hasErrors = true;
console.log(` \u274c ${dir.padEnd(30)} — SKILL.md missing`);
}
console.log(` Total: ${count} skills, ${missing} missing`);
} else {
console.log(`\n ${hostConfig.displayName} Skills: ${hostConfig.hostSubdir}/skills/ not found (run: bun run gen:skill-docs --host ${hostConfig.name})`);
}
console.log(` Total: ${factoryCount} skills, ${factoryMissing} missing`);
} else {
console.log('\n Factory Skills: .factory/skills/ not found (run: bun run gen:skill-docs --host factory)');
}
// ─── Freshness ──────────────────────────────────────────────
// ─── Freshness (config-driven) ──────────────────────────────
console.log('\n Freshness (Claude):');
try {
execSync('bun run scripts/gen-skill-docs.ts --dry-run', { cwd: ROOT, stdio: 'pipe' });
console.log(' \u2705 All Claude generated files are fresh');
} catch (err: any) {
hasErrors = true;
const output = err.stdout?.toString() || '';
console.log(' \u274c Claude generated files are stale:');
for (const line of output.split('\n').filter((l: string) => l.startsWith('STALE'))) {
console.log(` ${line}`);
}
console.log(' Run: bun run gen:skill-docs');
}
import { ALL_HOST_CONFIGS } from '../hosts/index';
console.log('\n Freshness (Codex):');
try {
execSync('bun run scripts/gen-skill-docs.ts --host codex --dry-run', { cwd: ROOT, stdio: 'pipe' });
console.log(' \u2705 All Codex generated files are fresh');
} catch (err: any) {
hasErrors = true;
const output = err.stdout?.toString() || '';
console.log(' \u274c Codex generated files are stale:');
for (const line of output.split('\n').filter((l: string) => l.startsWith('STALE'))) {
console.log(` ${line}`);
for (const hostConfig of ALL_HOST_CONFIGS) {
const hostFlag = hostConfig.name === 'claude' ? '' : ` --host ${hostConfig.name}`;
console.log(`\n Freshness (${hostConfig.displayName}):`);
try {
execSync(`bun run scripts/gen-skill-docs.ts${hostFlag} --dry-run`, { cwd: ROOT, stdio: 'pipe' });
console.log(` \u2705 All ${hostConfig.displayName} generated files are fresh`);
} catch (err: any) {
hasErrors = true;
const output = err.stdout?.toString() || '';
console.log(` \u274c ${hostConfig.displayName} generated files are stale:`);
for (const line of output.split('\n').filter((l: string) => l.startsWith('STALE'))) {
console.log(` ${line}`);
}
console.log(` Run: bun run gen:skill-docs${hostFlag}`);
}
console.log(' Run: bun run gen:skill-docs --host codex');
}
console.log('\n Freshness (Factory):');
try {
execSync('bun run scripts/gen-skill-docs.ts --host factory --dry-run', { cwd: ROOT, stdio: 'pipe' });
console.log(' \u2705 All Factory generated files are fresh');
} catch (err: any) {
hasErrors = true;
const output = err.stdout?.toString() || '';
console.log(' \u274c Factory generated files are stale:');
for (const line of output.split('\n').filter((l: string) => l.startsWith('STALE'))) {
console.log(` ${line}`);
}
console.log(' Run: bun run gen:skill-docs --host factory');
}
console.log('');
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+80 -4
View File
@@ -1898,19 +1898,95 @@ describe('Factory generation (--host factory)', () => {
});
});
// ─── Parameterized host smoke tests (config-driven) ─────────
import { ALL_HOST_CONFIGS, getExternalHosts } from '../hosts/index';
describe('Parameterized host smoke tests', () => {
for (const hostConfig of getExternalHosts()) {
describe(`${hostConfig.displayName} (--host ${hostConfig.name})`, () => {
const hostDir = path.join(ROOT, hostConfig.hostSubdir, 'skills');
test('generates output that exists on disk', () => {
// Generated dir should exist (created by earlier bun run gen:skill-docs --host all)
if (!fs.existsSync(hostDir)) {
// Generate if not already done
Bun.spawnSync(['bun', 'run', 'scripts/gen-skill-docs.ts', '--host', hostConfig.name], {
cwd: ROOT, stdout: 'pipe', stderr: 'pipe',
});
}
expect(fs.existsSync(hostDir)).toBe(true);
const skills = fs.readdirSync(hostDir).filter(d =>
fs.existsSync(path.join(hostDir, d, 'SKILL.md'))
);
expect(skills.length).toBeGreaterThan(0);
});
test('no .claude/skills path leakage in non-root skills', () => {
if (!fs.existsSync(hostDir)) return; // skip if not generated
const skills = fs.readdirSync(hostDir);
for (const skill of skills) {
// Skip root gstack skill — it contains preamble with intentional .claude/skills
// fallback paths for binary lookup and skill prefix instructions
if (skill === 'gstack') continue;
const skillMd = path.join(hostDir, skill, 'SKILL.md');
if (!fs.existsSync(skillMd)) continue;
const content = fs.readFileSync(skillMd, 'utf-8');
// Strip bash blocks (which have legitimate fallback paths)
const noBash = content.replace(/```bash\n[\s\S]*?```/g, '');
const leaks = noBash.split('\n').filter(l => l.includes('.claude/skills'));
if (leaks.length > 0) {
throw new Error(`${skill}: .claude/skills leakage:\n${leaks.slice(0, 3).join('\n')}`);
}
}
});
test('frontmatter has name and description', () => {
if (!fs.existsSync(hostDir)) return;
const skills = fs.readdirSync(hostDir);
for (const skill of skills) {
const skillMd = path.join(hostDir, skill, 'SKILL.md');
if (!fs.existsSync(skillMd)) continue;
const content = fs.readFileSync(skillMd, 'utf-8');
expect(content).toMatch(/^---\n/);
expect(content).toMatch(/^name:\s/m);
expect(content).toMatch(/^description:\s/m);
}
});
test('--dry-run freshness check passes', () => {
const result = Bun.spawnSync(
['bun', 'run', 'scripts/gen-skill-docs.ts', '--host', hostConfig.name, '--dry-run'],
{ cwd: ROOT, stdout: 'pipe', stderr: 'pipe' }
);
expect(result.exitCode).toBe(0);
const output = result.stdout.toString();
expect(output).not.toContain('STALE');
});
if (hostConfig.generation.skipSkills?.includes('codex')) {
test('/codex skill excluded', () => {
expect(fs.existsSync(path.join(hostDir, 'gstack-codex', 'SKILL.md'))).toBe(false);
});
}
});
}
});
// ─── --host all tests ────────────────────────────────────────
describe('--host all', () => {
test('--host all generates for claude, codex, and factory', () => {
test('--host all generates for all registered hosts', () => {
const result = Bun.spawnSync(['bun', 'run', 'scripts/gen-skill-docs.ts', '--host', 'all', '--dry-run'], {
cwd: ROOT, stdout: 'pipe', stderr: 'pipe',
});
expect(result.exitCode).toBe(0);
const output = result.stdout.toString();
// All three hosts should appear in output
// All hosts should appear in output
expect(output).toContain('FRESH: SKILL.md'); // claude
expect(output).toContain('FRESH: .agents/skills/'); // codex
expect(output).toContain('FRESH: .factory/skills/'); // factory
for (const hostConfig of getExternalHosts()) {
expect(output).toContain(`FRESH: ${hostConfig.hostSubdir}/skills/`);
}
});
});
+520
View File
@@ -0,0 +1,520 @@
/**
* Host config system tests 100% coverage of host-config.ts, hosts/index.ts,
* host-config-export.ts, and golden-file regression checks.
*/
import { describe, test, expect } from 'bun:test';
import * as fs from 'fs';
import * as path from 'path';
import { validateHostConfig, validateAllConfigs, type HostConfig } from '../scripts/host-config';
import {
ALL_HOST_CONFIGS,
ALL_HOST_NAMES,
HOST_CONFIG_MAP,
getHostConfig,
resolveHostArg,
getExternalHosts,
claude,
codex,
factory,
kiro,
opencode,
slate,
cursor,
openclaw,
} from '../hosts/index';
import { HOST_PATHS } from '../scripts/resolvers/types';
const ROOT = path.resolve(import.meta.dir, '..');
// ─── hosts/index.ts ─────────────────────────────────────────
describe('hosts/index.ts', () => {
test('ALL_HOST_CONFIGS has 8 hosts', () => {
expect(ALL_HOST_CONFIGS.length).toBe(8);
});
test('ALL_HOST_NAMES matches config names', () => {
expect(ALL_HOST_NAMES).toEqual(ALL_HOST_CONFIGS.map(c => c.name));
});
test('HOST_CONFIG_MAP keys match names', () => {
for (const config of ALL_HOST_CONFIGS) {
expect(HOST_CONFIG_MAP[config.name]).toBe(config);
}
});
test('individual config re-exports match registry', () => {
expect(claude.name).toBe('claude');
expect(codex.name).toBe('codex');
expect(factory.name).toBe('factory');
expect(kiro.name).toBe('kiro');
expect(opencode.name).toBe('opencode');
expect(slate.name).toBe('slate');
expect(cursor.name).toBe('cursor');
expect(openclaw.name).toBe('openclaw');
});
test('getHostConfig returns correct config', () => {
const c = getHostConfig('codex');
expect(c.name).toBe('codex');
expect(c.displayName).toBe('OpenAI Codex CLI');
});
test('getHostConfig throws on unknown host', () => {
expect(() => getHostConfig('nonexistent')).toThrow('Unknown host');
});
test('resolveHostArg resolves direct names', () => {
for (const name of ALL_HOST_NAMES) {
expect(resolveHostArg(name)).toBe(name);
}
});
test('resolveHostArg resolves aliases', () => {
expect(resolveHostArg('agents')).toBe('codex');
expect(resolveHostArg('droid')).toBe('factory');
});
test('resolveHostArg throws on unknown alias', () => {
expect(() => resolveHostArg('nonexistent')).toThrow('Unknown host');
});
test('getExternalHosts excludes claude', () => {
const external = getExternalHosts();
expect(external.find(c => c.name === 'claude')).toBeUndefined();
expect(external.length).toBe(ALL_HOST_CONFIGS.length - 1);
});
test('every host has a unique name', () => {
const names = new Set(ALL_HOST_NAMES);
expect(names.size).toBe(ALL_HOST_NAMES.length);
});
test('every host has a unique hostSubdir', () => {
const subdirs = new Set(ALL_HOST_CONFIGS.map(c => c.hostSubdir));
expect(subdirs.size).toBe(ALL_HOST_CONFIGS.length);
});
test('every host has a unique globalRoot', () => {
const roots = new Set(ALL_HOST_CONFIGS.map(c => c.globalRoot));
expect(roots.size).toBe(ALL_HOST_CONFIGS.length);
});
});
// ─── validateHostConfig ─────────────────────────────────────
describe('validateHostConfig', () => {
function makeValid(): HostConfig {
return {
name: 'test-host',
displayName: 'Test Host',
cliCommand: 'testcli',
globalRoot: '.test/skills/gstack',
localSkillRoot: '.test/skills/gstack',
hostSubdir: '.test',
usesEnvVars: true,
frontmatter: { mode: 'allowlist', keepFields: ['name', 'description'] },
generation: { generateMetadata: false },
pathRewrites: [],
runtimeRoot: { globalSymlinks: ['bin'] },
install: { prefixable: false, linkingStrategy: 'symlink-generated' },
};
}
test('valid config passes', () => {
expect(validateHostConfig(makeValid())).toEqual([]);
});
test('invalid name is caught', () => {
const c = makeValid();
c.name = 'UPPER_CASE';
const errors = validateHostConfig(c);
expect(errors.some(e => e.includes('name'))).toBe(true);
});
test('name with special chars is caught', () => {
const c = makeValid();
c.name = 'has spaces';
expect(validateHostConfig(c).length).toBeGreaterThan(0);
});
test('empty displayName is caught', () => {
const c = makeValid();
c.displayName = '';
expect(validateHostConfig(c).some(e => e.includes('displayName'))).toBe(true);
});
test('invalid cliCommand is caught', () => {
const c = makeValid();
c.cliCommand = 'has spaces';
expect(validateHostConfig(c).some(e => e.includes('cliCommand'))).toBe(true);
});
test('invalid cliAlias is caught', () => {
const c = makeValid();
c.cliAliases = ['good', 'BAD!'];
expect(validateHostConfig(c).some(e => e.includes('cliAlias'))).toBe(true);
});
test('valid cliAliases pass', () => {
const c = makeValid();
c.cliAliases = ['alias-one', 'alias-two'];
expect(validateHostConfig(c)).toEqual([]);
});
test('invalid globalRoot is caught', () => {
const c = makeValid();
c.globalRoot = 'path with spaces';
expect(validateHostConfig(c).some(e => e.includes('globalRoot'))).toBe(true);
});
test('invalid localSkillRoot is caught', () => {
const c = makeValid();
c.localSkillRoot = 'invalid<path>';
expect(validateHostConfig(c).some(e => e.includes('localSkillRoot'))).toBe(true);
});
test('invalid hostSubdir is caught', () => {
const c = makeValid();
c.hostSubdir = 'no spaces allowed';
expect(validateHostConfig(c).some(e => e.includes('hostSubdir'))).toBe(true);
});
test('invalid frontmatter.mode is caught', () => {
const c = makeValid();
(c.frontmatter as any).mode = 'invalid';
expect(validateHostConfig(c).some(e => e.includes('frontmatter.mode'))).toBe(true);
});
test('invalid linkingStrategy is caught', () => {
const c = makeValid();
(c.install as any).linkingStrategy = 'invalid';
expect(validateHostConfig(c).some(e => e.includes('linkingStrategy'))).toBe(true);
});
test('paths with $ and ~ are valid', () => {
const c = makeValid();
c.globalRoot = '$HOME/.test/skills/gstack';
c.localSkillRoot = '~/.test/skills/gstack';
expect(validateHostConfig(c)).toEqual([]);
});
test('shell injection attempt in cliCommand is caught', () => {
const c = makeValid();
c.cliCommand = 'opencode;rm -rf /';
expect(validateHostConfig(c).some(e => e.includes('cliCommand'))).toBe(true);
});
});
// ─── validateAllConfigs ─────────────────────────────────────
describe('validateAllConfigs', () => {
test('real configs all pass validation', () => {
const errors = validateAllConfigs(ALL_HOST_CONFIGS);
expect(errors).toEqual([]);
});
test('duplicate name detected', () => {
const dup = { ...codex, name: 'claude' } as HostConfig;
const errors = validateAllConfigs([claude, dup]);
expect(errors.some(e => e.includes('Duplicate name'))).toBe(true);
});
test('duplicate hostSubdir detected', () => {
const dup = { ...codex, name: 'dup-host', hostSubdir: '.claude', globalRoot: '.dup/skills/gstack' } as HostConfig;
const errors = validateAllConfigs([claude, dup]);
expect(errors.some(e => e.includes('Duplicate hostSubdir'))).toBe(true);
});
test('duplicate globalRoot detected', () => {
const dup = { ...codex, name: 'dup-host', hostSubdir: '.dup', globalRoot: '.claude/skills/gstack' } as HostConfig;
const errors = validateAllConfigs([claude, dup]);
expect(errors.some(e => e.includes('Duplicate globalRoot'))).toBe(true);
});
test('per-config validation errors are prefixed with host name', () => {
const bad = { ...codex, name: 'BAD', cliCommand: 'also bad' } as HostConfig;
const errors = validateAllConfigs([bad]);
expect(errors.every(e => e.startsWith('[BAD]'))).toBe(true);
});
});
// ─── HOST_PATHS derivation ──────────────────────────────────
describe('HOST_PATHS derivation from configs', () => {
test('Claude uses literal home paths (no env vars)', () => {
expect(HOST_PATHS.claude.skillRoot).toBe('~/.claude/skills/gstack');
expect(HOST_PATHS.claude.binDir).toBe('~/.claude/skills/gstack/bin');
expect(HOST_PATHS.claude.browseDir).toBe('~/.claude/skills/gstack/browse/dist');
expect(HOST_PATHS.claude.designDir).toBe('~/.claude/skills/gstack/design/dist');
});
test('Codex uses $GSTACK_ROOT env vars', () => {
expect(HOST_PATHS.codex.skillRoot).toBe('$GSTACK_ROOT');
expect(HOST_PATHS.codex.binDir).toBe('$GSTACK_BIN');
expect(HOST_PATHS.codex.browseDir).toBe('$GSTACK_BROWSE');
expect(HOST_PATHS.codex.designDir).toBe('$GSTACK_DESIGN');
});
test('every host with usesEnvVars=true gets env var paths', () => {
for (const config of ALL_HOST_CONFIGS) {
if (config.usesEnvVars) {
expect(HOST_PATHS[config.name].skillRoot).toBe('$GSTACK_ROOT');
expect(HOST_PATHS[config.name].binDir).toBe('$GSTACK_BIN');
}
}
});
test('every host with usesEnvVars=false gets literal paths', () => {
for (const config of ALL_HOST_CONFIGS) {
if (!config.usesEnvVars) {
expect(HOST_PATHS[config.name].skillRoot).toContain('~/');
expect(HOST_PATHS[config.name].binDir).toContain('/bin');
}
}
});
test('localSkillRoot matches config for every host', () => {
for (const config of ALL_HOST_CONFIGS) {
expect(HOST_PATHS[config.name].localSkillRoot).toBe(config.localSkillRoot);
}
});
test('HOST_PATHS has entry for every registered host', () => {
for (const name of ALL_HOST_NAMES) {
expect(HOST_PATHS[name]).toBeDefined();
}
});
});
// ─── host-config-export.ts CLI ──────────────────────────────
describe('host-config-export.ts CLI', () => {
const EXPORT_SCRIPT = path.join(ROOT, 'scripts', 'host-config-export.ts');
function run(...args: string[]): { stdout: string; stderr: string; exitCode: number } {
const result = Bun.spawnSync(['bun', 'run', EXPORT_SCRIPT, ...args], {
cwd: ROOT, stdout: 'pipe', stderr: 'pipe',
});
return {
stdout: result.stdout.toString().trim(),
stderr: result.stderr.toString().trim(),
exitCode: result.exitCode,
};
}
test('list prints all host names', () => {
const { stdout, exitCode } = run('list');
expect(exitCode).toBe(0);
const names = stdout.split('\n');
expect(names).toEqual(ALL_HOST_NAMES);
});
test('get returns string field', () => {
const { stdout, exitCode } = run('get', 'codex', 'globalRoot');
expect(exitCode).toBe(0);
expect(stdout).toBe('.codex/skills/gstack');
});
test('get returns boolean as 1/0', () => {
const { stdout: t } = run('get', 'claude', 'usesEnvVars');
expect(t).toBe('0');
const { stdout: f } = run('get', 'codex', 'usesEnvVars');
expect(f).toBe('1');
});
test('get with missing args exits 1', () => {
const { exitCode } = run('get', 'codex');
expect(exitCode).toBe(1);
});
test('get with unknown field exits 1', () => {
const { exitCode } = run('get', 'codex', 'nonexistent');
expect(exitCode).toBe(1);
});
test('get with unknown host exits 1', () => {
const { exitCode } = run('get', 'nonexistent', 'name');
expect(exitCode).not.toBe(0);
});
test('validate passes for real configs', () => {
const { stdout, exitCode } = run('validate');
expect(exitCode).toBe(0);
expect(stdout).toContain('configs valid');
});
test('symlinks returns asset list', () => {
const { stdout, exitCode } = run('symlinks', 'codex');
expect(exitCode).toBe(0);
const lines = stdout.split('\n');
expect(lines).toContain('bin');
expect(lines).toContain('ETHOS.md');
expect(lines).toContain('review/checklist.md');
});
test('symlinks with missing host exits 1', () => {
const { exitCode } = run('symlinks');
expect(exitCode).toBe(1);
});
test('detect finds claude (since we are running in claude)', () => {
const { stdout, exitCode } = run('detect');
expect(exitCode).toBe(0);
// claude binary should be on PATH in this environment
expect(stdout).toContain('claude');
});
test('unknown command exits 1', () => {
const { exitCode } = run('badcommand');
expect(exitCode).toBe(1);
});
});
// ─── Golden-file regression ─────────────────────────────────
describe('golden-file regression', () => {
const GOLDEN_DIR = path.join(ROOT, 'test', 'fixtures', 'golden');
test('Claude ship skill matches golden baseline', () => {
const golden = fs.readFileSync(path.join(GOLDEN_DIR, 'claude-ship-SKILL.md'), 'utf-8');
const current = fs.readFileSync(path.join(ROOT, 'ship', 'SKILL.md'), 'utf-8');
expect(current).toBe(golden);
});
test('Codex ship skill matches golden baseline', () => {
const golden = fs.readFileSync(path.join(GOLDEN_DIR, 'codex-ship-SKILL.md'), 'utf-8');
const current = fs.readFileSync(path.join(ROOT, '.agents', 'skills', 'gstack-ship', 'SKILL.md'), 'utf-8');
expect(current).toBe(golden);
});
test('Factory ship skill matches golden baseline', () => {
const golden = fs.readFileSync(path.join(GOLDEN_DIR, 'factory-ship-SKILL.md'), 'utf-8');
const current = fs.readFileSync(path.join(ROOT, '.factory', 'skills', 'gstack-ship', 'SKILL.md'), 'utf-8');
expect(current).toBe(golden);
});
});
// ─── Individual host config correctness ─────────────────────
describe('host config correctness', () => {
test('claude is the only prefixable host', () => {
for (const config of ALL_HOST_CONFIGS) {
if (config.name === 'claude') {
expect(config.install.prefixable).toBe(true);
} else {
expect(config.install.prefixable).toBe(false);
}
}
});
test('claude is the only host with real-dir-symlink strategy', () => {
for (const config of ALL_HOST_CONFIGS) {
if (config.name === 'claude') {
expect(config.install.linkingStrategy).toBe('real-dir-symlink');
} else {
expect(config.install.linkingStrategy).toBe('symlink-generated');
}
}
});
test('claude does not use env vars', () => {
expect(claude.usesEnvVars).toBe(false);
});
test('all external hosts use env vars', () => {
for (const config of getExternalHosts()) {
expect(config.usesEnvVars).toBe(true);
}
});
test('codex has 1024-char description limit with error behavior', () => {
expect(codex.frontmatter.descriptionLimit).toBe(1024);
expect(codex.frontmatter.descriptionLimitBehavior).toBe('error');
});
test('codex generates openai.yaml metadata', () => {
expect(codex.generation.generateMetadata).toBe(true);
expect(codex.generation.metadataFormat).toBe('openai.yaml');
});
test('codex has sidecar config', () => {
expect(codex.sidecar).toBeDefined();
expect(codex.sidecar!.path).toBe('.agents/skills/gstack');
});
test('factory has tool rewrites', () => {
expect(factory.toolRewrites).toBeDefined();
expect(Object.keys(factory.toolRewrites!).length).toBeGreaterThan(0);
expect(factory.toolRewrites!['use the Bash tool']).toBe('run this command');
});
test('factory has conditional disable-model-invocation field', () => {
expect(factory.frontmatter.conditionalFields).toBeDefined();
expect(factory.frontmatter.conditionalFields!.length).toBe(1);
expect(factory.frontmatter.conditionalFields![0].if).toEqual({ sensitive: true });
expect(factory.frontmatter.conditionalFields![0].add).toEqual({ 'disable-model-invocation': true });
});
test('codex has suppressedResolvers for self-invocation prevention', () => {
expect(codex.suppressedResolvers).toBeDefined();
expect(codex.suppressedResolvers).toContain('CODEX_SECOND_OPINION');
expect(codex.suppressedResolvers).toContain('ADVERSARIAL_STEP');
expect(codex.suppressedResolvers).toContain('REVIEW_ARMY');
});
test('codex has boundary instruction', () => {
expect(codex.boundaryInstruction).toBeDefined();
expect(codex.boundaryInstruction).toContain('Do NOT read');
});
test('openclaw has tool rewrites for exec/read/write', () => {
expect(openclaw.toolRewrites).toBeDefined();
expect(openclaw.toolRewrites!['use the Bash tool']).toBe('use the exec tool');
expect(openclaw.toolRewrites!['use the Read tool']).toBe('use the read tool');
});
test('openclaw has CLAUDE.md→AGENTS.md path rewrite', () => {
expect(openclaw.pathRewrites.some(r => r.from === 'CLAUDE.md' && r.to === 'AGENTS.md')).toBe(true);
});
test('openclaw has adapter path', () => {
expect(openclaw.adapter).toBeDefined();
expect(openclaw.adapter).toContain('openclaw-adapter');
});
test('openclaw has staticFiles for SOUL.md', () => {
expect(openclaw.staticFiles).toBeDefined();
expect(openclaw.staticFiles!['SOUL.md']).toBeDefined();
});
test('every host has coAuthorTrailer or undefined', () => {
// Claude, Codex, Factory, OpenClaw have explicit trailers
expect(claude.coAuthorTrailer).toContain('Claude');
expect(codex.coAuthorTrailer).toContain('Codex');
expect(factory.coAuthorTrailer).toContain('Factory');
expect(openclaw.coAuthorTrailer).toContain('OpenClaw');
});
test('every external host skips the codex skill', () => {
for (const config of getExternalHosts()) {
expect(config.generation.skipSkills).toContain('codex');
}
});
test('every host has at least one pathRewrite (except claude)', () => {
for (const config of getExternalHosts()) {
expect(config.pathRewrites.length).toBeGreaterThan(0);
}
expect(claude.pathRewrites.length).toBe(0);
});
test('every host has runtimeRoot.globalSymlinks', () => {
for (const config of ALL_HOST_CONFIGS) {
expect(config.runtimeRoot.globalSymlinks.length).toBeGreaterThan(0);
expect(config.runtimeRoot.globalSymlinks).toContain('bin');
expect(config.runtimeRoot.globalSymlinks).toContain('ETHOS.md');
}
});
});
+11 -9
View File
@@ -116,9 +116,10 @@ describeIfSelected('Sidebar URL accuracy E2E', ['sidebar-url-accuracy'], () => {
}
expect(lastEntry).not.toBeNull();
// Extension URL should be used, not the Playwright fallback
// Extension URL should be used, not the Playwright fallback.
// The pageUrl field carries the extension URL; the prompt itself
// contains only the system prompt + user message (URL is metadata).
expect(lastEntry.pageUrl).toBe(extensionUrl);
expect(lastEntry.prompt).toContain(extensionUrl);
expect(lastEntry.pageUrl).not.toBe('about:blank');
// Also test: chrome:// URL should be rejected, falling back to about:blank
@@ -262,11 +263,12 @@ describeIfSelected('Sidebar CSS interaction E2E', ['sidebar-css-interaction'], (
fs.writeFileSync(queueFile, '');
const startTime = Date.now();
// Ask the agent to go to HN, find the most insightful comment, and highlight it
// Simple task: go to example.com, read the title, apply a style
// (much faster than multi-step HN comment navigation)
const resp = await api('/sidebar-command', {
method: 'POST',
body: JSON.stringify({
message: 'Go to https://news.ycombinator.com. Find the top story. Click into its comments. Read the comments and find the most insightful one. Highlight that comment with a 4px solid orange outline.',
message: 'Go to https://example.com. Read the page title. Add a 4px solid orange outline to the h1 element.',
activeTabUrl: 'about:blank',
}),
});
@@ -315,15 +317,15 @@ describeIfSelected('Sidebar CSS interaction E2E', ['sidebar-css-interaction'], (
.join(' ')
.toLowerCase();
// Should have navigated to HN (look for ycombinator/HN in any entry text)
// Should have navigated to example.com (look for example.com in any entry text)
const allEntryText = entries
.map((e: any) => `${e.text || ''} ${e.input || ''} ${e.message || ''}`)
.join(' ');
const navigatedToHN = allEntryText.includes('ycombinator') || allEntryText.includes('Hacker News') || allEntryText.includes('news.ycombinator');
if (!navigatedToHN) {
const navigatedToTarget = allEntryText.includes('example.com') || allEntryText.includes('Example Domain');
if (!navigatedToTarget) {
console.log('ALL ENTRY TEXT (first 2000):', allEntryText.slice(0, 2000));
}
expect(navigatedToHN).toBe(true);
expect(navigatedToTarget).toBe(true);
// Should have applied a style (look for orange/outline in tool commands)
const allText = entries.map((e: any) => e.text || '').join(' ');
@@ -331,7 +333,7 @@ describeIfSelected('Sidebar CSS interaction E2E', ['sidebar-css-interaction'], (
evalCollector?.addTest({
name: 'sidebar-css-interaction', suite: 'Sidebar CSS interaction E2E', tier: 'e2e',
passed: !!doneEntry && navigatedToHN && appliedStyle,
passed: !!doneEntry && navigatedToTarget && appliedStyle,
duration_ms: duration,
cost_usd: 0,
exit_reason: doneEntry ? 'success' : 'timeout',