deepwork 0.2.0__py3-none-any.whl → 0.3.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- deepwork/cli/install.py +116 -71
- deepwork/cli/sync.py +20 -20
- deepwork/core/adapters.py +88 -51
- deepwork/core/command_executor.py +173 -0
- deepwork/core/generator.py +148 -31
- deepwork/core/hooks_syncer.py +51 -25
- deepwork/core/parser.py +8 -0
- deepwork/core/pattern_matcher.py +271 -0
- deepwork/core/rules_parser.py +559 -0
- deepwork/core/rules_queue.py +321 -0
- deepwork/hooks/README.md +181 -0
- deepwork/hooks/__init__.py +77 -1
- deepwork/hooks/claude_hook.sh +55 -0
- deepwork/hooks/gemini_hook.sh +55 -0
- deepwork/hooks/rules_check.py +700 -0
- deepwork/hooks/wrapper.py +363 -0
- deepwork/schemas/job_schema.py +14 -1
- deepwork/schemas/rules_schema.py +135 -0
- deepwork/standard_jobs/deepwork_jobs/job.yml +35 -53
- deepwork/standard_jobs/deepwork_jobs/steps/define.md +9 -6
- deepwork/standard_jobs/deepwork_jobs/steps/implement.md +28 -26
- deepwork/standard_jobs/deepwork_jobs/steps/learn.md +2 -2
- deepwork/standard_jobs/deepwork_rules/hooks/capture_prompt_work_tree.sh +30 -0
- deepwork/standard_jobs/deepwork_rules/hooks/global_hooks.yml +8 -0
- deepwork/standard_jobs/deepwork_rules/job.yml +47 -0
- deepwork/standard_jobs/deepwork_rules/rules/.gitkeep +13 -0
- deepwork/standard_jobs/deepwork_rules/rules/api-documentation-sync.md.example +10 -0
- deepwork/standard_jobs/deepwork_rules/rules/readme-documentation.md.example +10 -0
- deepwork/standard_jobs/deepwork_rules/rules/security-review.md.example +11 -0
- deepwork/standard_jobs/deepwork_rules/rules/skill-md-validation.md +46 -0
- deepwork/standard_jobs/deepwork_rules/rules/source-test-pairing.md.example +13 -0
- deepwork/standard_jobs/deepwork_rules/steps/define.md +249 -0
- deepwork/templates/claude/skill-job-meta.md.jinja +70 -0
- deepwork/templates/claude/skill-job-step.md.jinja +198 -0
- deepwork/templates/gemini/skill-job-meta.toml.jinja +76 -0
- deepwork/templates/gemini/skill-job-step.toml.jinja +147 -0
- {deepwork-0.2.0.dist-info → deepwork-0.3.1.dist-info}/METADATA +56 -25
- deepwork-0.3.1.dist-info/RECORD +62 -0
- deepwork/core/policy_parser.py +0 -295
- deepwork/hooks/evaluate_policies.py +0 -376
- deepwork/schemas/policy_schema.py +0 -78
- deepwork/standard_jobs/deepwork_policy/hooks/capture_prompt_work_tree.sh +0 -27
- deepwork/standard_jobs/deepwork_policy/hooks/global_hooks.yml +0 -8
- deepwork/standard_jobs/deepwork_policy/hooks/policy_stop_hook.sh +0 -56
- deepwork/standard_jobs/deepwork_policy/job.yml +0 -35
- deepwork/standard_jobs/deepwork_policy/steps/define.md +0 -195
- deepwork/templates/claude/command-job-step.md.jinja +0 -210
- deepwork/templates/default_policy.yml +0 -53
- deepwork/templates/gemini/command-job-step.toml.jinja +0 -169
- deepwork-0.2.0.dist-info/RECORD +0 -49
- /deepwork/standard_jobs/{deepwork_policy → deepwork_rules}/hooks/user_prompt_submit.sh +0 -0
- {deepwork-0.2.0.dist-info → deepwork-0.3.1.dist-info}/WHEEL +0 -0
- {deepwork-0.2.0.dist-info → deepwork-0.3.1.dist-info}/entry_points.txt +0 -0
- {deepwork-0.2.0.dist-info → deepwork-0.3.1.dist-info}/licenses/LICENSE.md +0 -0
|
@@ -6,13 +6,15 @@ Create a `job.yml` specification file that defines the structure of a new DeepWo
|
|
|
6
6
|
|
|
7
7
|
## Task
|
|
8
8
|
|
|
9
|
-
Guide the user through defining a job specification by asking
|
|
9
|
+
Guide the user through defining a job specification by asking structured questions. **Do not attempt to create the specification without first fully understanding the user's needs.**
|
|
10
|
+
|
|
11
|
+
**Important**: Use the AskUserQuestion tool to ask structured questions when gathering information from the user. This provides a better user experience with clear options and guided choices.
|
|
10
12
|
|
|
11
13
|
The output of this step is **only** the `job.yml` file - a complete specification of the workflow. The actual step instruction files will be created in the next step (`implement`).
|
|
12
14
|
|
|
13
15
|
### Step 1: Understand the Job Purpose
|
|
14
16
|
|
|
15
|
-
Start by asking questions to understand what the user wants to accomplish:
|
|
17
|
+
Start by asking structured questions to understand what the user wants to accomplish:
|
|
16
18
|
|
|
17
19
|
1. **What is the overall goal of this workflow?**
|
|
18
20
|
- What complex task are they trying to accomplish?
|
|
@@ -31,7 +33,7 @@ Start by asking questions to understand what the user wants to accomplish:
|
|
|
31
33
|
|
|
32
34
|
### Step 2: Define Each Step
|
|
33
35
|
|
|
34
|
-
For each major phase they mentioned, ask
|
|
36
|
+
For each major phase they mentioned, ask structured questions to gather details:
|
|
35
37
|
|
|
36
38
|
1. **Step Purpose**
|
|
37
39
|
- What exactly does this step accomplish?
|
|
@@ -92,7 +94,7 @@ After gathering information about all steps:
|
|
|
92
94
|
|
|
93
95
|
For each step, consider whether it would benefit from **quality validation loops**. Stop hooks allow the AI agent to iteratively refine its work until quality criteria are met.
|
|
94
96
|
|
|
95
|
-
**Ask
|
|
97
|
+
**Ask structured questions about quality validation:**
|
|
96
98
|
- "Are there specific quality criteria that must be met for this step?"
|
|
97
99
|
- "Would you like the agent to validate its work before completing?"
|
|
98
100
|
- "What would make you send the work back for revision?"
|
|
@@ -281,11 +283,11 @@ Run `/deepwork_jobs.implement` to generate the instruction files for each step b
|
|
|
281
283
|
## Important Guidelines
|
|
282
284
|
|
|
283
285
|
1. **Focus on specification only** - Don't create instruction files yet
|
|
284
|
-
2. **Ask
|
|
286
|
+
2. **Ask structured questions** - Never skip the discovery phase; use the AskUserQuestion tool
|
|
285
287
|
3. **Rich context in description** - This helps with future refinement
|
|
286
288
|
4. **Validate understanding** - Summarize and confirm before creating
|
|
287
289
|
5. **Use examples** - Help users understand what good specifications look like
|
|
288
|
-
6. **Understand file organization** - Always ask where outputs should be saved and if subdirectories are needed
|
|
290
|
+
6. **Understand file organization** - Always ask structured questions about where outputs should be saved and if subdirectories are needed
|
|
289
291
|
|
|
290
292
|
## Validation Rules
|
|
291
293
|
|
|
@@ -319,6 +321,7 @@ After creating the file:
|
|
|
319
321
|
|
|
320
322
|
## Quality Criteria
|
|
321
323
|
|
|
324
|
+
- Asked structured questions to fully understand user requirements
|
|
322
325
|
- User fully understands what job they're creating
|
|
323
326
|
- All steps have clear inputs and outputs
|
|
324
327
|
- Dependencies make logical sense
|
|
@@ -69,6 +69,7 @@ For each step in the job.yml, create a comprehensive instruction file at `.deepw
|
|
|
69
69
|
4. **Explain the "why"** - Help the user understand the step's role in the workflow
|
|
70
70
|
5. **Quality over quantity** - Detailed, actionable instructions are better than vague ones
|
|
71
71
|
6. **Align with stop hooks** - If the step has `stop_hooks` defined, ensure the quality criteria in the instruction file match the validation criteria in the hooks
|
|
72
|
+
7. **Ask structured questions** - When a step has user inputs, the instructions MUST explicitly tell the agent to "ask structured questions" using the AskUserQuestion tool to gather that information. Never use generic phrasing like "ask the user" - always use "ask structured questions"
|
|
72
73
|
|
|
73
74
|
### Handling Stop Hooks
|
|
74
75
|
|
|
@@ -112,9 +113,9 @@ See `.deepwork/jobs/deepwork_jobs/steps/supplemental_file_references.md` for det
|
|
|
112
113
|
|
|
113
114
|
Verify that `job.yml` is in the correct location at `.deepwork/jobs/[job_name]/job.yml`. The define step should have created it there. If for some reason it's not there, you may need to create or move it.
|
|
114
115
|
|
|
115
|
-
### Step 5: Sync
|
|
116
|
+
### Step 5: Sync Skills
|
|
116
117
|
|
|
117
|
-
Run `deepwork sync` to generate the
|
|
118
|
+
Run `deepwork sync` to generate the skills for this job:
|
|
118
119
|
|
|
119
120
|
```bash
|
|
120
121
|
deepwork sync
|
|
@@ -122,26 +123,26 @@ deepwork sync
|
|
|
122
123
|
|
|
123
124
|
This will:
|
|
124
125
|
- Parse the job definition
|
|
125
|
-
- Generate
|
|
126
|
-
- Make the
|
|
126
|
+
- Generate skills for each step
|
|
127
|
+
- Make the skills available in `.claude/skills/` (or appropriate platform directory)
|
|
127
128
|
|
|
128
129
|
### Step 6: Relay Reload Instructions
|
|
129
130
|
|
|
130
|
-
After running `deepwork sync`, look at the "To use the new
|
|
131
|
+
After running `deepwork sync`, look at the "To use the new skills" section in the output. **Relay these exact reload instructions to the user** so they know how to pick up the new skills. 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).
|
|
131
132
|
|
|
132
|
-
### Step 7: Consider
|
|
133
|
+
### Step 7: Consider Rules for the New Job
|
|
133
134
|
|
|
134
|
-
After implementing the job, consider whether there are **
|
|
135
|
+
After implementing the job, consider whether there are **rules** that would help enforce quality or consistency when working with this job's domain.
|
|
135
136
|
|
|
136
|
-
**What are
|
|
137
|
+
**What are rules?**
|
|
137
138
|
|
|
138
|
-
|
|
139
|
+
Rules are automated guardrails stored as markdown files in `.deepwork/rules/` that trigger when certain files change during an AI session. They help ensure:
|
|
139
140
|
- Documentation stays in sync with code
|
|
140
141
|
- Team guidelines are followed
|
|
141
142
|
- Architectural decisions are respected
|
|
142
143
|
- Quality standards are maintained
|
|
143
144
|
|
|
144
|
-
**When to suggest
|
|
145
|
+
**When to suggest rules:**
|
|
145
146
|
|
|
146
147
|
Think about the job you just implemented and ask:
|
|
147
148
|
- Does this job produce outputs that other files depend on?
|
|
@@ -149,28 +150,28 @@ Think about the job you just implemented and ask:
|
|
|
149
150
|
- Are there quality checks or reviews that should happen when certain files in this domain change?
|
|
150
151
|
- Could changes to the job's output files impact other parts of the project?
|
|
151
152
|
|
|
152
|
-
**Examples of
|
|
153
|
+
**Examples of rules that might make sense:**
|
|
153
154
|
|
|
154
|
-
| Job Type | Potential
|
|
155
|
-
|
|
155
|
+
| Job Type | Potential Rule |
|
|
156
|
+
|----------|----------------|
|
|
156
157
|
| API Design | "Update API docs when endpoint definitions change" |
|
|
157
158
|
| Database Schema | "Review migrations when schema files change" |
|
|
158
159
|
| Competitive Research | "Update strategy docs when competitor analysis changes" |
|
|
159
160
|
| Feature Development | "Update changelog when feature files change" |
|
|
160
161
|
| Configuration Management | "Update install guide when config files change" |
|
|
161
162
|
|
|
162
|
-
**How to offer
|
|
163
|
+
**How to offer rule creation:**
|
|
163
164
|
|
|
164
|
-
If you identify one or more
|
|
165
|
-
1. **What the
|
|
165
|
+
If you identify one or more rules that would benefit the user, explain:
|
|
166
|
+
1. **What the rule would do** - What triggers it and what action it prompts
|
|
166
167
|
2. **Why it would help** - How it prevents common mistakes or keeps things in sync
|
|
167
168
|
3. **What files it would watch** - The trigger patterns
|
|
168
169
|
|
|
169
170
|
Then ask the user:
|
|
170
171
|
|
|
171
|
-
> "Would you like me to create this
|
|
172
|
+
> "Would you like me to create this rule for you? I can run `/deepwork_rules.define` to set it up."
|
|
172
173
|
|
|
173
|
-
If the user agrees, invoke the `/
|
|
174
|
+
If the user agrees, invoke the `/deepwork_rules.define` command to guide them through creating the rule.
|
|
174
175
|
|
|
175
176
|
**Example dialogue:**
|
|
176
177
|
|
|
@@ -179,15 +180,15 @@ Based on the competitive_research job you just created, I noticed that when
|
|
|
179
180
|
competitor analysis files change, it would be helpful to remind you to update
|
|
180
181
|
your strategy documentation.
|
|
181
182
|
|
|
182
|
-
I'd suggest a
|
|
183
|
+
I'd suggest a rule like:
|
|
183
184
|
- **Name**: "Update strategy when competitor analysis changes"
|
|
184
185
|
- **Trigger**: `**/positioning_report.md`
|
|
185
186
|
- **Action**: Prompt to review and update `docs/strategy.md`
|
|
186
187
|
|
|
187
|
-
Would you like me to create this
|
|
188
|
+
Would you like me to create this rule? I can run `/deepwork_rules.define` to set it up.
|
|
188
189
|
```
|
|
189
190
|
|
|
190
|
-
**Note:** Not every job needs
|
|
191
|
+
**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.
|
|
191
192
|
|
|
192
193
|
## Example Implementation
|
|
193
194
|
|
|
@@ -219,10 +220,10 @@ Before marking this step complete, ensure:
|
|
|
219
220
|
- [ ] All step instruction files created
|
|
220
221
|
- [ ] Each instruction file is complete and actionable
|
|
221
222
|
- [ ] `deepwork sync` executed successfully
|
|
222
|
-
- [ ]
|
|
223
|
+
- [ ] Skills generated in platform directory
|
|
223
224
|
- [ ] User informed to follow reload instructions from `deepwork sync`
|
|
224
|
-
- [ ] Considered whether
|
|
225
|
-
- [ ] If
|
|
225
|
+
- [ ] Considered whether rules would benefit this job (Step 7)
|
|
226
|
+
- [ ] If rules suggested, offered to run `/deepwork_rules.define`
|
|
226
227
|
|
|
227
228
|
## Quality Criteria
|
|
228
229
|
|
|
@@ -231,6 +232,7 @@ Before marking this step complete, ensure:
|
|
|
231
232
|
- Instructions are specific and actionable
|
|
232
233
|
- Output examples are provided in each instruction file
|
|
233
234
|
- Quality criteria defined for each step
|
|
235
|
+
- Steps with user inputs explicitly use "ask structured questions" phrasing
|
|
234
236
|
- Sync completed successfully
|
|
235
|
-
-
|
|
236
|
-
- Thoughtfully considered relevant
|
|
237
|
+
- Skills available for use
|
|
238
|
+
- Thoughtfully considered relevant rules for the job domain
|
|
@@ -171,7 +171,7 @@ If instruction files were modified:
|
|
|
171
171
|
deepwork sync
|
|
172
172
|
```
|
|
173
173
|
|
|
174
|
-
2. **If
|
|
174
|
+
2. **If skills were regenerated**, look at the "To use the new skills" section in the `deepwork sync` output and **relay these exact reload instructions to the user** (e.g., "Type 'exit' then run 'claude --resume'" for Claude Code)
|
|
175
175
|
|
|
176
176
|
## File Reference Patterns
|
|
177
177
|
|
|
@@ -261,7 +261,7 @@ I found the following job executions:
|
|
|
261
261
|
|
|
262
262
|
**Summary**
|
|
263
263
|
|
|
264
|
-
Updated job instructions and created AGENTS.md with bespoke learnings. To get the updated
|
|
264
|
+
Updated job instructions and created AGENTS.md with bespoke learnings. To get the updated skills, type 'exit' then run 'claude --resume'.
|
|
265
265
|
```
|
|
266
266
|
|
|
267
267
|
## Handling Edge Cases
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# capture_prompt_work_tree.sh - Captures the git work tree state at prompt submission
|
|
3
|
+
#
|
|
4
|
+
# This script creates a snapshot of ALL tracked files at the time the prompt
|
|
5
|
+
# is submitted. This baseline is used for rules with compare_to: prompt and
|
|
6
|
+
# created: mode to detect truly NEW files (not modifications to existing ones).
|
|
7
|
+
#
|
|
8
|
+
# The baseline contains ALL tracked files (not just changed files) so that
|
|
9
|
+
# the rules_check hook can determine which files are genuinely new vs which
|
|
10
|
+
# files existed before and were just modified.
|
|
11
|
+
|
|
12
|
+
set -e
|
|
13
|
+
|
|
14
|
+
# Ensure .deepwork directory exists
|
|
15
|
+
mkdir -p .deepwork
|
|
16
|
+
|
|
17
|
+
# Save ALL tracked files (not just changed files)
|
|
18
|
+
# This is critical for created: mode rules to distinguish between:
|
|
19
|
+
# - Newly created files (not in baseline) -> should trigger created: rules
|
|
20
|
+
# - Modified existing files (in baseline) -> should NOT trigger created: rules
|
|
21
|
+
git ls-files > .deepwork/.last_work_tree 2>/dev/null || true
|
|
22
|
+
|
|
23
|
+
# Also include untracked files that exist at prompt time
|
|
24
|
+
# These are files the user may have created before submitting the prompt
|
|
25
|
+
git ls-files --others --exclude-standard >> .deepwork/.last_work_tree 2>/dev/null || true
|
|
26
|
+
|
|
27
|
+
# Sort and deduplicate
|
|
28
|
+
if [ -f .deepwork/.last_work_tree ]; then
|
|
29
|
+
sort -u .deepwork/.last_work_tree -o .deepwork/.last_work_tree
|
|
30
|
+
fi
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
name: deepwork_rules
|
|
2
|
+
version: "0.3.0"
|
|
3
|
+
summary: "Rules enforcement for AI agent sessions"
|
|
4
|
+
description: |
|
|
5
|
+
Manages rules that automatically trigger when certain files change during an AI agent session.
|
|
6
|
+
Rules help ensure that code changes follow team guidelines, documentation is updated,
|
|
7
|
+
and architectural decisions are respected.
|
|
8
|
+
|
|
9
|
+
IMPORTANT: Rules are evaluated at the "Stop" hook, which fires when an agent finishes its turn.
|
|
10
|
+
This includes when sub-agents complete their work. Rules are NOT evaluated immediately after
|
|
11
|
+
each file edit - they batch up and run once at the end of the agent's response cycle.
|
|
12
|
+
- Command action rules: Execute their command (e.g., `uv sync`) when the agent stops
|
|
13
|
+
- Prompt action rules: Display instructions to the agent, blocking until addressed
|
|
14
|
+
|
|
15
|
+
Rules are stored as individual markdown files with YAML frontmatter in the `.deepwork/rules/`
|
|
16
|
+
directory. Each rule file specifies:
|
|
17
|
+
- Detection mode: trigger/safety, set (bidirectional), or pair (directional)
|
|
18
|
+
- Patterns: Glob patterns for matching files, with optional variable capture
|
|
19
|
+
- Action type: prompt (default) to show instructions, or command to run a shell command
|
|
20
|
+
- Instructions: Markdown content describing what the agent should do
|
|
21
|
+
|
|
22
|
+
Example use cases:
|
|
23
|
+
- Update installation docs when configuration files change
|
|
24
|
+
- Require security review when authentication code is modified
|
|
25
|
+
- Ensure API documentation stays in sync with API code
|
|
26
|
+
- Enforce source/test file pairing
|
|
27
|
+
- Auto-run `uv sync` when pyproject.toml changes (command action)
|
|
28
|
+
|
|
29
|
+
changelog:
|
|
30
|
+
- version: "0.1.0"
|
|
31
|
+
changes: "Initial version"
|
|
32
|
+
- version: "0.2.0"
|
|
33
|
+
changes: "Standardized on 'ask structured questions' phrasing for user input"
|
|
34
|
+
- version: "0.3.0"
|
|
35
|
+
changes: "Migrated to v2 format - individual markdown files in .deepwork/rules/"
|
|
36
|
+
|
|
37
|
+
steps:
|
|
38
|
+
- id: define
|
|
39
|
+
name: "Define Rule"
|
|
40
|
+
description: "Create a new rule file in .deepwork/rules/"
|
|
41
|
+
instructions_file: steps/define.md
|
|
42
|
+
inputs:
|
|
43
|
+
- name: rule_purpose
|
|
44
|
+
description: "What guideline or constraint should this rule enforce?"
|
|
45
|
+
outputs:
|
|
46
|
+
- .deepwork/rules/{rule-name}.md
|
|
47
|
+
dependencies: []
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# This directory contains example rule templates.
|
|
2
|
+
# Copy and customize these files to create your own rules.
|
|
3
|
+
#
|
|
4
|
+
# Rule files use YAML frontmatter in markdown format:
|
|
5
|
+
#
|
|
6
|
+
# ---
|
|
7
|
+
# name: Rule Name
|
|
8
|
+
# trigger: "pattern/**/*"
|
|
9
|
+
# safety: "optional/pattern"
|
|
10
|
+
# ---
|
|
11
|
+
# Instructions in markdown here.
|
|
12
|
+
#
|
|
13
|
+
# See doc/rules_syntax.md for full documentation.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: API Documentation Sync
|
|
3
|
+
trigger: src/api/**/*
|
|
4
|
+
safety: docs/api/**/*.md
|
|
5
|
+
---
|
|
6
|
+
API code has changed. Please verify that API documentation is up to date:
|
|
7
|
+
|
|
8
|
+
- New or changed endpoints
|
|
9
|
+
- Modified request/response schemas
|
|
10
|
+
- Updated authentication requirements
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: README Documentation
|
|
3
|
+
trigger: src/**/*
|
|
4
|
+
safety: README.md
|
|
5
|
+
---
|
|
6
|
+
Source code has been modified. Please review README.md for accuracy:
|
|
7
|
+
|
|
8
|
+
1. Verify the project overview reflects current functionality
|
|
9
|
+
2. Check that usage examples are still correct
|
|
10
|
+
3. Ensure installation/setup instructions remain valid
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Security Review for Auth Changes
|
|
3
|
+
trigger:
|
|
4
|
+
- src/auth/**/*
|
|
5
|
+
- src/security/**/*
|
|
6
|
+
---
|
|
7
|
+
Authentication or security code has been changed. Please:
|
|
8
|
+
|
|
9
|
+
1. Review for hardcoded credentials or secrets
|
|
10
|
+
2. Check input validation on user inputs
|
|
11
|
+
3. Verify access control logic is correct
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: SKILL.md Validation
|
|
3
|
+
trigger: "**/SKILL.md"
|
|
4
|
+
compare_to: base
|
|
5
|
+
---
|
|
6
|
+
A SKILL.md file has been created or modified. Please validate that it follows the required format:
|
|
7
|
+
|
|
8
|
+
## Required Structure
|
|
9
|
+
|
|
10
|
+
The file MUST have valid YAML frontmatter at the start, enclosed between `---` markers:
|
|
11
|
+
|
|
12
|
+
```markdown
|
|
13
|
+
---
|
|
14
|
+
name: my-skill-name
|
|
15
|
+
description: A description of what this skill does
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
# Rest of the skill documentation...
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Validation Checklist
|
|
22
|
+
|
|
23
|
+
1. **YAML Frontmatter**: Verify the file starts with `---` followed by valid YAML and ends with `---`
|
|
24
|
+
|
|
25
|
+
2. **`name` field** (required):
|
|
26
|
+
- Must be present in the frontmatter
|
|
27
|
+
- Must contain only lowercase letters, numbers, and hyphens (`a-z`, `0-9`, `-`)
|
|
28
|
+
- Must be 64 characters or fewer
|
|
29
|
+
- Example valid names: `my-skill`, `code-review-2`, `lint`
|
|
30
|
+
- Example invalid names: `My Skill` (uppercase/spaces), `skill_name` (underscores), `SKILL` (uppercase)
|
|
31
|
+
|
|
32
|
+
3. **`description` field** (required):
|
|
33
|
+
- Must be present in the frontmatter
|
|
34
|
+
- Must be 1024 characters or fewer
|
|
35
|
+
- Should clearly describe what the skill does
|
|
36
|
+
|
|
37
|
+
## What to Check
|
|
38
|
+
|
|
39
|
+
For the modified file: {trigger_files}
|
|
40
|
+
|
|
41
|
+
1. Parse the YAML frontmatter and verify it is valid YAML
|
|
42
|
+
2. Check that `name` exists and matches the pattern `^[a-z0-9-]+$` with max length 64
|
|
43
|
+
3. Check that `description` exists and is at most 1024 characters
|
|
44
|
+
4. Report any validation errors to the user
|
|
45
|
+
|
|
46
|
+
If the file does not pass validation, help the user fix the issues.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Source/Test Pairing
|
|
3
|
+
set:
|
|
4
|
+
- src/{path}.py
|
|
5
|
+
- tests/{path}_test.py
|
|
6
|
+
---
|
|
7
|
+
Source and test files should change together.
|
|
8
|
+
|
|
9
|
+
When modifying source code, ensure corresponding tests are updated.
|
|
10
|
+
When adding tests, ensure they test actual source code.
|
|
11
|
+
|
|
12
|
+
Modified source: {trigger_files}
|
|
13
|
+
Expected tests: {expected_files}
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
# Define Rule
|
|
2
|
+
|
|
3
|
+
## Objective
|
|
4
|
+
|
|
5
|
+
Create a new rule file in the `.deepwork/rules/` directory to enforce team guidelines, documentation requirements, or other constraints when specific files change.
|
|
6
|
+
|
|
7
|
+
## Task
|
|
8
|
+
|
|
9
|
+
Guide the user through defining a new rule by asking structured questions. **Do not create the rule without first understanding what they want to enforce.**
|
|
10
|
+
|
|
11
|
+
**Important**: Use the AskUserQuestion tool to ask structured questions when gathering information from the user. This provides a better user experience with clear options and guided choices.
|
|
12
|
+
|
|
13
|
+
### Step 1: Understand the Rule Purpose
|
|
14
|
+
|
|
15
|
+
Start by asking structured questions to understand what the user wants to enforce:
|
|
16
|
+
|
|
17
|
+
1. **What guideline or constraint should this rule enforce?**
|
|
18
|
+
- What situation triggers the need for action?
|
|
19
|
+
- What files or directories, when changed, should trigger this rule?
|
|
20
|
+
- Examples: "When config files change", "When API code changes", "When database schema changes"
|
|
21
|
+
|
|
22
|
+
2. **What action should be taken?**
|
|
23
|
+
- What should the agent do when the rule triggers?
|
|
24
|
+
- Update documentation? Perform a security review? Update tests?
|
|
25
|
+
- Is there a specific file or process that needs attention?
|
|
26
|
+
|
|
27
|
+
3. **Are there any "safety" conditions?**
|
|
28
|
+
- Are there files that, if also changed, mean the rule doesn't need to fire?
|
|
29
|
+
- For example: If config changes AND install_guide.md changes, assume docs are already updated
|
|
30
|
+
- This prevents redundant prompts when the user has already done the right thing
|
|
31
|
+
|
|
32
|
+
### Step 2: Choose the Detection Mode
|
|
33
|
+
|
|
34
|
+
Help the user select the appropriate detection mode:
|
|
35
|
+
|
|
36
|
+
**Trigger/Safety Mode** (most common):
|
|
37
|
+
- Fires when trigger patterns match AND no safety patterns match
|
|
38
|
+
- Use for: "When X changes, check Y" rules
|
|
39
|
+
- Example: When config changes, verify install docs
|
|
40
|
+
|
|
41
|
+
**Set Mode** (bidirectional correspondence):
|
|
42
|
+
- Fires when files that should change together don't all change
|
|
43
|
+
- Use for: Source/test pairing, model/migration sync
|
|
44
|
+
- Example: `src/foo.py` and `tests/foo_test.py` should change together
|
|
45
|
+
|
|
46
|
+
**Pair Mode** (directional correspondence):
|
|
47
|
+
- Fires when a trigger file changes but expected files don't
|
|
48
|
+
- Changes to expected files alone do NOT trigger
|
|
49
|
+
- Use for: API code requires documentation updates (but docs can update independently)
|
|
50
|
+
|
|
51
|
+
### Step 3: Define the Patterns
|
|
52
|
+
|
|
53
|
+
Help the user define glob patterns for files.
|
|
54
|
+
|
|
55
|
+
**Common patterns:**
|
|
56
|
+
- `src/**/*.py` - All Python files in src directory (recursive)
|
|
57
|
+
- `app/config/**/*` - All files in app/config directory
|
|
58
|
+
- `*.md` - All markdown files in root
|
|
59
|
+
- `src/api/**/*` - All files in the API directory
|
|
60
|
+
- `migrations/**/*.sql` - All SQL migrations
|
|
61
|
+
|
|
62
|
+
**Variable patterns (for set/pair modes):**
|
|
63
|
+
- `src/{path}.py` - Captures path variable (e.g., `foo/bar` from `src/foo/bar.py`)
|
|
64
|
+
- `tests/{path}_test.py` - Uses same path variable in corresponding file
|
|
65
|
+
- `{name}` matches single segment, `{path}` matches multiple segments
|
|
66
|
+
|
|
67
|
+
**Pattern syntax:**
|
|
68
|
+
- `*` - Matches any characters within a single path segment
|
|
69
|
+
- `**` - Matches any characters across multiple path segments (recursive)
|
|
70
|
+
- `?` - Matches a single character
|
|
71
|
+
|
|
72
|
+
### Step 4: Choose the Comparison Mode (Optional)
|
|
73
|
+
|
|
74
|
+
The `compare_to` field controls what baseline is used when detecting "changed files":
|
|
75
|
+
|
|
76
|
+
**Options:**
|
|
77
|
+
- `base` (default) - Compares to the base of the current branch (merge-base with main/master). Best for feature branches.
|
|
78
|
+
- `default_tip` - Compares to the current tip of the default branch. Useful for seeing difference from production.
|
|
79
|
+
- `prompt` - Compares to the state at the start of each prompt. For rules about very recent changes.
|
|
80
|
+
|
|
81
|
+
Most rules should use the default (`base`) and don't need to specify `compare_to`.
|
|
82
|
+
|
|
83
|
+
### Step 5: Write the Instructions
|
|
84
|
+
|
|
85
|
+
Create clear, actionable instructions for what the agent should do when the rule fires.
|
|
86
|
+
|
|
87
|
+
**Good instructions include:**
|
|
88
|
+
- What to check or review
|
|
89
|
+
- What files might need updating
|
|
90
|
+
- Specific actions to take
|
|
91
|
+
- Quality criteria for completion
|
|
92
|
+
|
|
93
|
+
**Template variables available in instructions:**
|
|
94
|
+
- `{trigger_files}` - Files that triggered the rule
|
|
95
|
+
- `{expected_files}` - Expected corresponding files (for set/pair modes)
|
|
96
|
+
|
|
97
|
+
### Step 6: Create the Rule File
|
|
98
|
+
|
|
99
|
+
Create a new file in `.deepwork/rules/` with a kebab-case filename:
|
|
100
|
+
|
|
101
|
+
**File Location**: `.deepwork/rules/{rule-name}.md`
|
|
102
|
+
|
|
103
|
+
**Format for Trigger/Safety Mode:**
|
|
104
|
+
```markdown
|
|
105
|
+
---
|
|
106
|
+
name: Friendly Name for the Rule
|
|
107
|
+
trigger: "glob/pattern/**/*" # or array: ["pattern1", "pattern2"]
|
|
108
|
+
safety: "optional/pattern" # optional, or array
|
|
109
|
+
compare_to: base # optional: "base" (default), "default_tip", or "prompt"
|
|
110
|
+
---
|
|
111
|
+
Instructions for the agent when this rule fires.
|
|
112
|
+
|
|
113
|
+
Multi-line markdown content is supported.
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
**Format for Set Mode (bidirectional):**
|
|
117
|
+
```markdown
|
|
118
|
+
---
|
|
119
|
+
name: Source/Test Pairing
|
|
120
|
+
set:
|
|
121
|
+
- src/{path}.py
|
|
122
|
+
- tests/{path}_test.py
|
|
123
|
+
---
|
|
124
|
+
Source and test files should change together.
|
|
125
|
+
|
|
126
|
+
Modified: {trigger_files}
|
|
127
|
+
Expected: {expected_files}
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
**Format for Pair Mode (directional):**
|
|
131
|
+
```markdown
|
|
132
|
+
---
|
|
133
|
+
name: API Documentation
|
|
134
|
+
pair:
|
|
135
|
+
trigger: api/{path}.py
|
|
136
|
+
expects: docs/api/{path}.md
|
|
137
|
+
---
|
|
138
|
+
API code requires documentation updates.
|
|
139
|
+
|
|
140
|
+
Changed API: {trigger_files}
|
|
141
|
+
Update docs: {expected_files}
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### Step 7: Verify the Rule
|
|
145
|
+
|
|
146
|
+
After creating the rule:
|
|
147
|
+
|
|
148
|
+
1. **Check the YAML frontmatter** - Ensure valid YAML formatting
|
|
149
|
+
2. **Test trigger patterns** - Verify patterns match intended files
|
|
150
|
+
3. **Review instructions** - Ensure they're clear and actionable
|
|
151
|
+
4. **Check for conflicts** - Ensure the rule doesn't conflict with existing ones
|
|
152
|
+
|
|
153
|
+
## Example Rules
|
|
154
|
+
|
|
155
|
+
### Update Documentation on Config Changes
|
|
156
|
+
`.deepwork/rules/config-docs.md`:
|
|
157
|
+
```markdown
|
|
158
|
+
---
|
|
159
|
+
name: Update Install Guide on Config Changes
|
|
160
|
+
trigger: app/config/**/*
|
|
161
|
+
safety: docs/install_guide.md
|
|
162
|
+
---
|
|
163
|
+
Configuration files have been modified. Please review docs/install_guide.md
|
|
164
|
+
and update it if any installation instructions need to change based on the
|
|
165
|
+
new configuration.
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### Security Review for Auth Code
|
|
169
|
+
`.deepwork/rules/security-review.md`:
|
|
170
|
+
```markdown
|
|
171
|
+
---
|
|
172
|
+
name: Security Review for Authentication Changes
|
|
173
|
+
trigger:
|
|
174
|
+
- src/auth/**/*
|
|
175
|
+
- src/security/**/*
|
|
176
|
+
safety:
|
|
177
|
+
- SECURITY.md
|
|
178
|
+
- docs/security_audit.md
|
|
179
|
+
---
|
|
180
|
+
Authentication or security code has been changed. Please:
|
|
181
|
+
|
|
182
|
+
1. Review for hardcoded credentials or secrets
|
|
183
|
+
2. Check input validation on user inputs
|
|
184
|
+
3. Verify access control logic is correct
|
|
185
|
+
4. Update security documentation if needed
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
### Source/Test Pairing
|
|
189
|
+
`.deepwork/rules/source-test-pairing.md`:
|
|
190
|
+
```markdown
|
|
191
|
+
---
|
|
192
|
+
name: Source/Test Pairing
|
|
193
|
+
set:
|
|
194
|
+
- src/{path}.py
|
|
195
|
+
- tests/{path}_test.py
|
|
196
|
+
---
|
|
197
|
+
Source and test files should change together.
|
|
198
|
+
|
|
199
|
+
When modifying source code, ensure corresponding tests are updated.
|
|
200
|
+
When adding tests, ensure they test actual source code.
|
|
201
|
+
|
|
202
|
+
Modified: {trigger_files}
|
|
203
|
+
Expected: {expected_files}
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
### API Documentation Sync
|
|
207
|
+
`.deepwork/rules/api-docs.md`:
|
|
208
|
+
```markdown
|
|
209
|
+
---
|
|
210
|
+
name: API Documentation Update
|
|
211
|
+
pair:
|
|
212
|
+
trigger: src/api/{path}.py
|
|
213
|
+
expects: docs/api/{path}.md
|
|
214
|
+
---
|
|
215
|
+
API code has changed. Please verify that API documentation in docs/api/
|
|
216
|
+
is up to date with the code changes. Pay special attention to:
|
|
217
|
+
|
|
218
|
+
- New or changed endpoints
|
|
219
|
+
- Modified request/response schemas
|
|
220
|
+
- Updated authentication requirements
|
|
221
|
+
|
|
222
|
+
Changed API: {trigger_files}
|
|
223
|
+
Update: {expected_files}
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
## Output Format
|
|
227
|
+
|
|
228
|
+
### .deepwork/rules/{rule-name}.md
|
|
229
|
+
Create a new file with the rule definition using YAML frontmatter and markdown body.
|
|
230
|
+
|
|
231
|
+
## Quality Criteria
|
|
232
|
+
|
|
233
|
+
- Asked structured questions to understand user requirements
|
|
234
|
+
- Rule name is clear and descriptive (used in promise tags)
|
|
235
|
+
- Correct detection mode selected for the use case
|
|
236
|
+
- Patterns accurately match the intended files
|
|
237
|
+
- Safety patterns prevent unnecessary triggering (if applicable)
|
|
238
|
+
- Instructions are actionable and specific
|
|
239
|
+
- YAML frontmatter is valid
|
|
240
|
+
|
|
241
|
+
## Context
|
|
242
|
+
|
|
243
|
+
Rules are evaluated automatically when the agent finishes a task. The system:
|
|
244
|
+
1. Determines which files have changed based on each rule's `compare_to` setting
|
|
245
|
+
2. Evaluates rules based on their detection mode (trigger/safety, set, or pair)
|
|
246
|
+
3. Skips rules where the correspondence is satisfied (for set/pair) or safety matched
|
|
247
|
+
4. Prompts you with instructions for any triggered rules
|
|
248
|
+
|
|
249
|
+
You can mark a rule as addressed by including `<promise>Rule Name</promise>` in your response (replace Rule Name with the actual rule name from the `name` field). This tells the system you've already handled that rule's requirements.
|