You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(ambient): ensure skill tool invocations happen before text output (#158)
## Summary
- Ambient mode skills were not loading despite correct
GUIDED/ORCHESTRATED classification
- Root cause: model prints "Loading: X, Y" text then skips actual
`Skill()` tool calls — generating prose overrides the tool-call
requirement
- Fix: reverse instruction order in ambient-router SKILL.md and hook
preamble so Skill tool invocations must happen **before** any text
output
## Changes
- `shared/skills/ambient-router/SKILL.md` — IMPORTANT block and Step 4
now require tool calls first, classification text after
- `scripts/hooks/ambient-prompt` — preamble reinforces "FIRST tool calls
MUST be Skill tool invocations"
- `tests/integration/helpers.ts` — sync preamble string
- `tests/ambient.test.ts` — sync drift detection expected value
- `CHANGELOG.md` — add fix to [Unreleased]
## Test plan
- [x] Build passes (`npm run build`)
- [x] All 362 tests pass (`npm test`)
- [x] Preamble drift detection test passes (verifies hook ↔ helpers
sync)
Co-authored-by: Dean Sharon <deanshrn@gmain.com>
Copy file name to clipboardExpand all lines: scripts/hooks/ambient-prompt
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -40,7 +40,7 @@ fi
40
40
41
41
# Inject classification preamble
42
42
# SYNC: must match tests/integration/helpers.ts AMBIENT_PREAMBLE
43
-
PREAMBLE="AMBIENT MODE ACTIVE: Before responding, silently classify this prompt using the ambient-router skill already in your session context. If QUICK, respond normally without stating classification. If GUIDED or ORCHESTRATED, you MUST load the selected skills using the Skill tool before proceeding."
43
+
PREAMBLE="AMBIENT MODE ACTIVE: Before responding, silently classify this prompt using the ambient-router skill already in your session context. If QUICK, respond normally without stating classification. If GUIDED or ORCHESTRATED, your FIRST tool calls MUST be Skill tool invocations for each selected skill — before writing ANY text about the task."
Copy file name to clipboardExpand all lines: shared/skills/ambient-router/SKILL.md
+5-3Lines changed: 5 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -87,16 +87,18 @@ See `references/skill-catalog.md` for the full skill-to-intent mapping with file
87
87
<IMPORTANT>
88
88
When classification is GUIDED or ORCHESTRATED, skill loading is NON-NEGOTIABLE.
89
89
Do not rationalize skipping skills. Do not respond without loading them first.
90
-
BLOCKING REQUIREMENT: Invoke each selected skill using the Skill tool before proceeding.
90
+
BLOCKING REQUIREMENT: Your FIRST tool calls MUST be Skill tool invocations — before
91
+
writing ANY text about the task. Invoke all selected skills, THEN state classification,
92
+
THEN proceed with work. Do NOT write implementation text before all Skill tools return.
91
93
For IMPLEMENT intent, enforce TDD: write the failing test before ANY production code.
92
94
NOTE: Skills loaded in the main session via ambient mode are reference patterns only —
93
95
their allowed-tools metadata does NOT restrict your tool access. You retain full access
94
96
to all tools (Edit, Write, Bash, Agent, etc.) for implementation work.
95
97
</IMPORTANT>
96
98
97
99
-**QUICK:** Respond directly. No preamble, no classification statement.
98
-
-**GUIDED:**State classification briefly: `Ambient: IMPLEMENT/GUIDED. Loading: implementation-patterns, search-first.` Then invoke each skill using the Skill tool and work directly in main session. After code changes, spawn Simplifier on changed files.
99
-
-**ORCHESTRATED:**State classification briefly: `Ambient: IMPLEMENT/ORCHESTRATED. Loading: implementation-orchestration, implementation-patterns.` Then invoke each skill using the Skill tool and follow Step 5 for agent orchestration.
100
+
-**GUIDED:**First, invoke each selected skill using the Skill tool. After all Skill tools return, state classification briefly: `Ambient: IMPLEMENT/GUIDED. Loading: implementation-patterns, search-first.` Then work directly in main session. After code changes, spawn Simplifier on changed files.
101
+
-**ORCHESTRATED:**First, invoke each selected skill using the Skill tool. After all Skill tools return, state classification briefly: `Ambient: IMPLEMENT/ORCHESTRATED. Loading: implementation-orchestration, implementation-patterns.` Then follow Step 5 for agent orchestration.
// The helpers.ts AMBIENT_PREAMBLE is used by extractIntent/extractDepth etc.
261
261
// We verify it indirectly by checking the shell script value matches expected.
262
262
constexpectedPreamble=
263
-
'AMBIENT MODE ACTIVE: Before responding, silently classify this prompt using the ambient-router skill already in your session context. If QUICK, respond normally without stating classification. If GUIDED or ORCHESTRATED, you MUST load the selected skills using the Skill tool before proceeding.';
263
+
'AMBIENT MODE ACTIVE: Before responding, silently classify this prompt using the ambient-router skill already in your session context. If QUICK, respond normally without stating classification. If GUIDED or ORCHESTRATED, your FIRST tool calls MUST be Skill tool invocations for each selected skill — before writing ANY text about the task.';
Copy file name to clipboardExpand all lines: tests/integration/helpers.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -17,7 +17,7 @@ export function isClaudeAvailable(): boolean {
17
17
18
18
// SYNC: must match scripts/hooks/ambient-prompt line 43
19
19
constAMBIENT_PREAMBLE=
20
-
'AMBIENT MODE ACTIVE: Before responding, silently classify this prompt using the ambient-router skill already in your session context. If QUICK, respond normally without stating classification. If GUIDED or ORCHESTRATED, you MUST load the selected skills using the Skill tool before proceeding.';
20
+
'AMBIENT MODE ACTIVE: Before responding, silently classify this prompt using the ambient-router skill already in your session context. If QUICK, respond normally without stating classification. If GUIDED or ORCHESTRATED, your FIRST tool calls MUST be Skill tool invocations for each selected skill — before writing ANY text about the task.';
21
21
22
22
/**
23
23
* Run a prompt through claude CLI in non-interactive mode.
0 commit comments