Skip to content

fix(preamble): quoted tilde made Artifacts Sync and telemetry-finalize blocks dead code#2333

Open
jawadakram20 wants to merge 1 commit into
garrytan:mainfrom
jawadakram20:fix/quoted-tilde-dead-code
Open

fix(preamble): quoted tilde made Artifacts Sync and telemetry-finalize blocks dead code#2333
jawadakram20 wants to merge 1 commit into
garrytan:mainfrom
jawadakram20:fix/quoted-tilde-dead-code

Conversation

@jawadakram20

Copy link
Copy Markdown

The bug

Bash performs tilde expansion only when ~ is unquoted. Inside double quotes it is a literal character, so "~/.claude/skills/gstack/bin/x" is a relative path that never resolves.

Two preamble generators interpolated a tilde-based ctx.paths.binDir inside double quotes:

  • scripts/resolvers/preamble/generate-brain-sync-block.ts — 4 sites
  • scripts/resolvers/preamble/generate-preamble-bash.ts — 1 site

Those 5 source sites expanded into roughly 250 broken lines across 49 generated SKILL.md files.

Impact

Artifacts Sync (skill start) was entirely inert. _BRAIN_SYNC_BIN and _BRAIN_CONFIG_BIN never resolved, so artifacts_sync_mode always read as "off" regardless of the user's actual config, and the --discover-new / --once sync calls always failed.

Pending telemetry was discarded unlogged. The finalize guard was always false:

if [ "$_TEL" != "off" ] && [ -x "~/.../gstack-telemetry-log" ]; then   # never true
  ...log...
fi
rm -f "$_PF" 2>/dev/null || true                                       # still deletes

The guard never fired, but the next line still removed the pending marker — so events were dropped rather than flushed.

Nothing errored, because every call site was guarded by || true or an if that simply never fired. The features looked wired up and did nothing.

Demonstration:

$ [ -x "~/.claude/skills/gstack/bin/gstack-telemetry-log" ] && echo yes || echo no
no
$ [ -x "$HOME/.claude/skills/gstack/bin/gstack-telemetry-log" ] && echo yes || echo no
yes

Fix

Add quoteSafePath() to scripts/resolvers/types.ts, rewriting a leading ~/ to $HOME/, and apply it at exactly the five quoted sites.

  • Env-var hosts ($GSTACK_BIN) already expand correctly when quoted and pass through untouched.
  • Unquoted interpolations are deliberately left alone — they expand fine, and generated docs keep the more readable ~.

Only 3 source files change; the 49 SKILL.md files in the diff are regenerated output from bun run gen:skill-docs, not hand edits.

Verification

  • 0 broken quoted-tilde sites remain in generated docs (was ~250)
  • Golden fixtures regenerate cleanly
bun test test/gen-skill-docs.test.ts test/skill-validation.test.ts \
         test/skill-size-budget.test.ts test/brain-sync.test.ts \
         test/brain-sync-windows-paths.test.ts
 770 pass
 0 fail

bun test test/skill-e2e.test.ts test/skill-e2e-autoplan-chain.test.ts \
         test/one-way-doors.test.ts test/hook-scripts.test.ts \
         test/question-preference-hook.test.ts
 64 pass
 0 fail

…e blocks dead code

Bash performs tilde expansion only when `~` is UNQUOTED. Inside double quotes
it is a literal character, so `"~/.claude/skills/gstack/bin/x"` is a relative
path that never resolves. Two preamble generators interpolated a tilde-based
`ctx.paths.binDir` inside double quotes:

  scripts/resolvers/preamble/generate-brain-sync-block.ts   (4 sites)
  scripts/resolvers/preamble/generate-preamble-bash.ts      (1 site)

Those five sites expanded into ~250 broken lines across 49 generated
SKILL.md files. Concretely:

- `_BRAIN_SYNC_BIN` / `_BRAIN_CONFIG_BIN` never resolved, so the whole
  "Artifacts Sync (skill start)" block was inert. `artifacts_sync_mode`
  always read as "off" regardless of the user's real config, and the
  `--discover-new` / `--once` sync calls always failed (silently, behind
  `|| true`).
- The pending-telemetry finalize guard
  `[ -x "~/.../gstack-telemetry-log" ]` was ALWAYS false, so the event was
  never logged — but the very next line still ran `rm -f "$_PF"`, deleting
  the pending marker. Pending telemetry was discarded unlogged rather than
  being flushed.

Nothing errored, because every call site was guarded by `|| true` or an
`if` that simply never fired. The features looked wired up and did nothing.

Fix: add `quoteSafePath()` in scripts/resolvers/types.ts, which rewrites a
leading `~/` to `$HOME/`, and apply it at exactly the five quoted sites.
Env-var hosts (`$GSTACK_BIN`) already expand correctly when quoted and pass
through untouched. Unquoted interpolations are deliberately left alone —
they expand fine and keep the more readable `~` in generated docs.

The 49 SKILL.md changes in this commit are regenerated output
(`bun run gen:skill-docs`), not hand edits.

Verified:
- `[ -x "~/..." ]` → false, `[ -x "$HOME/..." ]` → true on this machine.
- 0 broken quoted-tilde sites remain in generated docs (was ~250).
- 770 pass / 0 fail across gen-skill-docs (incl. golden fixtures),
  skill-validation, skill-size-budget, brain-sync, brain-sync-windows-paths.
- 64 pass / 0 fail across skill-e2e, autoplan-chain, one-way-doors,
  hook-scripts, question-preference-hook.
@trunk-io

trunk-io Bot commented Jul 23, 2026

Copy link
Copy Markdown

Merging to main in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant