Skip to content

Commit 58e712f

Browse files
nhortonclaude
andcommitted
Prevent mixing hook types in job schema validation
Updates the job schema to enforce that each hook event (after_agent, before_tool, before_prompt) can only contain hooks of a single type - either all scripts, all prompts, or all prompt_files. Mixing types like having both a script and a prompt in the same event is now rejected. This prevents confusing configurations where script output would be followed by a prompt evaluation, which doesn't work as expected. Adds tests to verify: - Mixed script/prompt hooks are rejected - Mixed script/prompt_file hooks are rejected - Multiple scripts in same event are allowed - Multiple prompts in same event are allowed Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 12fb39f commit 58e712f

19 files changed

Lines changed: 1077 additions & 114 deletions

File tree

.claude/commands/deepwork_rules.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
---
2+
description: Rules enforcement for AI agent sessions
3+
---
4+
5+
# deepwork_rules
6+
7+
You are executing the **deepwork_rules** job. Rules enforcement for AI agent sessions
8+
9+
Manages rules that automatically trigger when certain files change during an AI agent session.
10+
Rules help ensure that code changes follow team guidelines, documentation is updated,
11+
and architectural decisions are respected.
12+
13+
Rules are stored as individual markdown files with YAML frontmatter in the `.deepwork/rules/`
14+
directory. Each rule file specifies:
15+
- Detection mode: trigger/safety, set (bidirectional), or pair (directional)
16+
- Patterns: Glob patterns for matching files, with optional variable capture
17+
- Instructions: Markdown content describing what the agent should do
18+
19+
Example use cases:
20+
- Update installation docs when configuration files change
21+
- Require security review when authentication code is modified
22+
- Ensure API documentation stays in sync with API code
23+
- Enforce source/test file pairing
24+
25+
26+
## Available Steps
27+
28+
This job has 1 step(s):
29+
30+
### define
31+
**Define Rule**: Create a new rule file in .deepwork/rules/
32+
- Command: `uw.deepwork_rules.define`
33+
34+
## Instructions
35+
36+
This is a **multi-step workflow**. Determine the starting point and run through the steps in sequence.
37+
38+
1. **Analyze user intent** from the text that follows `/deepwork_rules`
39+
40+
2. **Identify the starting step** based on intent:
41+
- define: Create a new rule file in .deepwork/rules/
42+
43+
3. **Run the workflow** starting from the identified step:
44+
- Invoke the starting step using the Skill tool
45+
- When that step completes, **automatically continue** to the next step in the workflow
46+
- Continue until the workflow is complete or the user intervenes
47+
48+
4. **If intent is ambiguous**, ask the user which step to start from:
49+
- Present the available steps as numbered options
50+
- Use AskUserQuestion to let them choose
51+
52+
**Critical**:
53+
- You MUST invoke each step using the Skill tool. Do not copy/paste step instructions.
54+
- After each step completes, check if there's a next step and invoke it automatically.
55+
- The workflow continues until all dependent steps are complete.
56+
57+
## Context Files
58+
59+
- Job definition: `.deepwork/jobs/deepwork_rules/job.yml`

.claude/commands/update.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ description: Update standard jobs in src/ and sync to installed locations
77
You are executing the **update** job. Update standard jobs in src/ and sync to installed locations
88

99
A workflow for maintaining standard jobs bundled with DeepWork. Standard jobs
10-
(like `deepwork_jobs` and `deepwork_policy`) are source-controlled in
10+
(like `deepwork_jobs` and `deepwork_rules`) are source-controlled in
1111
`src/deepwork/standard_jobs/` and must be edited there—never in `.deepwork/jobs/`
1212
or `.claude/commands/` directly.
1313

.claude/commands/uw.add_platform.verify.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ hooks:
1313
2. Does running `deepwork install --platform <platform>` complete without errors?
1414
3. Are expected command files created in the platform's command directory?
1515
4. Does command file content match the templates and job definitions?
16-
5. Are established DeepWork jobs (deepwork_jobs, deepwork_policy) installed correctly?
16+
5. Are established DeepWork jobs (deepwork_jobs, deepwork_rules) installed correctly?
1717
6. Can the platform be used alongside existing platforms without conflicts?
1818
1919
## Instructions
@@ -117,7 +117,7 @@ Ensure the implementation step is complete:
117117
- `deepwork_jobs.define.md` exists (or equivalent for the platform)
118118
- `deepwork_jobs.implement.md` exists
119119
- `deepwork_jobs.refine.md` exists
120-
- `deepwork_policy.define.md` exists
120+
- `deepwork_rules.define.md` exists
121121
- All expected step commands exist
122122

123123
4. **Validate command file content**
@@ -147,7 +147,7 @@ Ensure the implementation step is complete:
147147
- `deepwork install --platform <platform_name>` completes without errors
148148
- All expected command files are created:
149149
- deepwork_jobs.define, implement, refine
150-
- deepwork_policy.define
150+
- deepwork_rules.define
151151
- Any other standard job commands
152152
- Command file content is correct:
153153
- Matches platform's expected format
@@ -214,7 +214,7 @@ This step uses an iterative quality validation loop. After completing your work,
214214
2. Does running `deepwork install --platform <platform>` complete without errors?
215215
3. Are expected command files created in the platform's command directory?
216216
4. Does command file content match the templates and job definitions?
217-
5. Are established DeepWork jobs (deepwork_jobs, deepwork_policy) installed correctly?
217+
5. Are established DeepWork jobs (deepwork_jobs, deepwork_rules) installed correctly?
218218
6. Can the platform be used alongside existing platforms without conflicts?
219219

220220

.claude/commands/uw.commit.format.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,6 @@ hooks:
55
- hooks:
66
- type: command
77
command: ".deepwork/jobs/commit/hooks/run_ruff.sh"
8-
- type: prompt
9-
prompt: |
10-
Evaluate the ruff format and lint check output above.
11-
12-
**If ruff reported issues (exit code non-zero)**: Start your response with "**AGENT: TAKE ACTION** -" followed by what needs to be fixed.
13-
14-
**If ruff reported no issues (exit code 0)**: Confirm the agent included `<promise>✓ Quality Criteria Met</promise>`. Allow completion.
15-
168
---
179

1810
# commit.format
@@ -128,11 +120,20 @@ No file output is required. Success is determined by ruff passing all checks.
128120
- `uv run ruff check src/ tests/` passes (exit code 0)
129121
- Any fixes made don't break functionality (tests should still pass)
130122
- If issues couldn't be fixed in 5 attempts, clear explanation provided
131-
- When all checks pass, include `<promise>✓ Quality Criteria Met</promise>` in your response
123+
124+
## Hook Behavior
125+
126+
After you complete this step, a hook will automatically run ruff format and lint checks and show you the results.
127+
128+
**Interpreting the hook output:**
129+
- **Both checks passed (exit code 0)**: The step is complete. Proceed to the next step.
130+
- **Checks failed (exit code non-zero)**: You must fix the issues. Use `uv run ruff format src/ tests/` for formatting and `uv run ruff check --fix src/ tests/` for auto-fixable lint issues. For remaining issues, fix manually. The hook will re-run after each attempt.
131+
132+
**Important**: The hook runs automatically - you don't need to run the checks yourself after fixing. Just focus on making fixes, and the hook will verify them.
132133

133134
## Context
134135

135-
This is the second step in the commit workflow, after tests pass. Code must be properly formatted and lint-free before committing. The format step uses a script hook that automatically runs ruff checks, so focus on analyzing results and making fixes efficiently.
136+
This is the second step in the commit workflow, after tests pass. Code must be properly formatted and lint-free before committing.
136137

137138

138139

.claude/commands/uw.commit.test.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,6 @@ hooks:
55
- hooks:
66
- type: command
77
command: ".deepwork/jobs/commit/hooks/run_tests.sh"
8-
- type: prompt
9-
prompt: |
10-
Evaluate the pytest output above.
11-
12-
**If any tests failed**: Start your response with "**AGENT: TAKE ACTION** -" followed by which tests failed and why.
13-
14-
**If ALL tests passed**: Confirm the agent included `<promise>✓ Quality Criteria Met</promise>`. Allow completion.
15-
168
---
179

1810
# commit.test
@@ -100,11 +92,20 @@ No file output is required. Success is determined by all tests passing.
10092
- All tests pass (`uv run pytest tests/ -v` exits with code 0)
10193
- Any fixes made are minimal and don't break other functionality
10294
- If tests couldn't be fixed in 5 attempts, clear explanation provided
103-
- When all tests pass, include `<promise>✓ Quality Criteria Met</promise>` in your response
95+
96+
## Hook Behavior
97+
98+
After you complete this step, a hook will automatically run `uv run pytest tests/ -v` and show you the results.
99+
100+
**Interpreting the hook output:**
101+
- **All tests passed (exit code 0)**: The step is complete. Proceed to the next step.
102+
- **Tests failed (exit code non-zero)**: You must fix the failing tests. Analyze the output, make fixes, and try again. The hook will re-run after each attempt.
103+
104+
**Important**: The hook runs automatically - you don't need to run pytest yourself after the initial run. Just focus on making fixes when tests fail, and the hook will verify your fixes.
104105

105106
## Context
106107

107-
This is the first step in the commit workflow. Tests must pass before code formatting is checked, ensuring that any changes being committed are functionally correct. The test step uses a script hook that automatically runs pytest, so focus on analyzing results and making fixes.
108+
This is the first step in the commit workflow. Tests must pass before code formatting is checked, ensuring that any changes being committed are functionally correct.
108109

109110

110111

.claude/commands/uw.deepwork_jobs.implement.md

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ hooks:
1717
6. **Ask Structured Questions**: Do step instructions that gather user input explicitly use the phrase "ask structured questions"?
1818
7. **Sync Complete**: Has `deepwork sync` been run successfully?
1919
8. **Commands Available**: Are the slash-commands generated in `.claude/commands/`?
20-
9. **Policies Considered**: Has the agent thought about whether policies would benefit this job? If relevant policies were identified, did they explain them and offer to run `/deepwork_policy.define`? Not every job needs policies - only suggest when genuinely helpful.
20+
9. **Rules Considered**: Has the agent thought about whether rules would benefit this job? If relevant rules were identified, did they explain them and offer to run `/deepwork_rules.define`? Not every job needs rules - only suggest when genuinely helpful.
2121
2222
## Instructions
2323
@@ -192,48 +192,48 @@ This will:
192192

193193
After running `deepwork sync`, look at the "To use the new commands" section in the output. **Relay these exact reload instructions to the user** so they know how to pick up the new commands. Don't just reference the sync output - tell them directly what they need to do (e.g., "Type 'exit' then run 'claude --resume'" for Claude Code, or "Run '/memory refresh'" for Gemini CLI).
194194

195-
### Step 7: Consider Policies for the New Job
195+
### Step 7: Consider Rules for the New Job
196196

197-
After implementing the job, consider whether there are **policies** that would help enforce quality or consistency when working with this job's domain.
197+
After implementing the job, consider whether there are **rules** that would help enforce quality or consistency when working with this job's domain.
198198

199-
**What are policies?**
199+
**What are rules?**
200200

201-
Policies are automated guardrails defined in `.deepwork.policy.yml` that trigger when certain files change during an AI session. They help ensure:
201+
Rules are automated guardrails stored as markdown files in `.deepwork/rules/` that trigger when certain files change during an AI session. They help ensure:
202202
- Documentation stays in sync with code
203203
- Team guidelines are followed
204204
- Architectural decisions are respected
205205
- Quality standards are maintained
206206

207-
**When to suggest policies:**
207+
**When to suggest rules:**
208208

209209
Think about the job you just implemented and ask:
210210
- Does this job produce outputs that other files depend on?
211211
- Are there documentation files that should be updated when this job's outputs change?
212212
- Are there quality checks or reviews that should happen when certain files in this domain change?
213213
- Could changes to the job's output files impact other parts of the project?
214214

215-
**Examples of policies that might make sense:**
215+
**Examples of rules that might make sense:**
216216

217-
| Job Type | Potential Policy |
218-
|----------|------------------|
217+
| Job Type | Potential Rule |
218+
|----------|----------------|
219219
| API Design | "Update API docs when endpoint definitions change" |
220220
| Database Schema | "Review migrations when schema files change" |
221221
| Competitive Research | "Update strategy docs when competitor analysis changes" |
222222
| Feature Development | "Update changelog when feature files change" |
223223
| Configuration Management | "Update install guide when config files change" |
224224

225-
**How to offer policy creation:**
225+
**How to offer rule creation:**
226226

227-
If you identify one or more policies that would benefit the user, explain:
228-
1. **What the policy would do** - What triggers it and what action it prompts
227+
If you identify one or more rules that would benefit the user, explain:
228+
1. **What the rule would do** - What triggers it and what action it prompts
229229
2. **Why it would help** - How it prevents common mistakes or keeps things in sync
230230
3. **What files it would watch** - The trigger patterns
231231

232232
Then ask the user:
233233

234-
> "Would you like me to create this policy for you? I can run `/deepwork_policy.define` to set it up."
234+
> "Would you like me to create this rule for you? I can run `/deepwork_rules.define` to set it up."
235235

236-
If the user agrees, invoke the `/deepwork_policy.define` command to guide them through creating the policy.
236+
If the user agrees, invoke the `/deepwork_rules.define` command to guide them through creating the rule.
237237

238238
**Example dialogue:**
239239

@@ -242,15 +242,15 @@ Based on the competitive_research job you just created, I noticed that when
242242
competitor analysis files change, it would be helpful to remind you to update
243243
your strategy documentation.
244244

245-
I'd suggest a policy like:
245+
I'd suggest a rule like:
246246
- **Name**: "Update strategy when competitor analysis changes"
247247
- **Trigger**: `**/positioning_report.md`
248248
- **Action**: Prompt to review and update `docs/strategy.md`
249249

250-
Would you like me to create this policy? I can run `/deepwork_policy.define` to set it up.
250+
Would you like me to create this rule? I can run `/deepwork_rules.define` to set it up.
251251
```
252252
253-
**Note:** Not every job needs policies. Only suggest them when they would genuinely help maintain consistency or quality. Don't force policies where they don't make sense.
253+
**Note:** Not every job needs rules. Only suggest them when they would genuinely help maintain consistency or quality. Don't force rules where they don't make sense.
254254
255255
## Example Implementation
256256
@@ -284,8 +284,8 @@ Before marking this step complete, ensure:
284284
- [ ] `deepwork sync` executed successfully
285285
- [ ] Commands generated in platform directory
286286
- [ ] User informed to follow reload instructions from `deepwork sync`
287-
- [ ] Considered whether policies would benefit this job (Step 7)
288-
- [ ] If policies suggested, offered to run `/deepwork_policy.define`
287+
- [ ] Considered whether rules would benefit this job (Step 7)
288+
- [ ] If rules suggested, offered to run `/deepwork_rules.define`
289289
290290
## Quality Criteria
291291
@@ -297,7 +297,7 @@ Before marking this step complete, ensure:
297297
- Steps with user inputs explicitly use "ask structured questions" phrasing
298298
- Sync completed successfully
299299
- Commands available for use
300-
- Thoughtfully considered relevant policies for the job domain
300+
- Thoughtfully considered relevant rules for the job domain
301301
302302
303303
## Inputs
@@ -346,7 +346,7 @@ This step uses an iterative quality validation loop. After completing your work,
346346
6. **Ask Structured Questions**: Do step instructions that gather user input explicitly use the phrase "ask structured questions"?
347347
7. **Sync Complete**: Has `deepwork sync` been run successfully?
348348
8. **Commands Available**: Are the slash-commands generated in `.claude/commands/`?
349-
9. **Policies Considered**: Has the agent thought about whether policies would benefit this job? If relevant policies were identified, did they explain them and offer to run `/deepwork_policy.define`? Not every job needs policies - only suggest when genuinely helpful.
349+
9. **Rules Considered**: Has the agent thought about whether rules would benefit this job? If relevant rules were identified, did they explain them and offer to run `/deepwork_rules.define`? Not every job needs rules - only suggest when genuinely helpful.
350350

351351

352352
### Completion Promise

0 commit comments

Comments
 (0)