deepwork 0.1.0__py3-none-any.whl → 0.1.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/sync.py +9 -0
- deepwork/core/adapters.py +17 -0
- deepwork/core/policy_parser.py +10 -0
- deepwork/hooks/evaluate_policies.py +237 -20
- deepwork/schemas/policy_schema.py +10 -0
- deepwork/standard_jobs/deepwork_jobs/job.yml +24 -19
- deepwork/standard_jobs/deepwork_jobs/steps/define.md +6 -0
- deepwork/standard_jobs/deepwork_jobs/steps/implement.md +10 -6
- deepwork/standard_jobs/deepwork_jobs/steps/learn.md +346 -0
- deepwork/standard_jobs/deepwork_jobs/steps/supplemental_file_references.md +40 -0
- deepwork/standard_jobs/deepwork_policy/hooks/{capture_work_tree.sh → capture_prompt_work_tree.sh} +3 -2
- deepwork/standard_jobs/deepwork_policy/hooks/policy_stop_hook.sh +3 -19
- deepwork/standard_jobs/deepwork_policy/hooks/user_prompt_submit.sh +5 -6
- deepwork/standard_jobs/deepwork_policy/steps/define.md +22 -1
- {deepwork-0.1.0.dist-info → deepwork-0.1.1.dist-info}/METADATA +51 -128
- {deepwork-0.1.0.dist-info → deepwork-0.1.1.dist-info}/RECORD +19 -19
- deepwork/standard_jobs/deepwork_jobs/steps/refine.md +0 -447
- deepwork/standard_jobs/deepwork_policy/hooks/get_changed_files.sh +0 -30
- {deepwork-0.1.0.dist-info → deepwork-0.1.1.dist-info}/WHEEL +0 -0
- {deepwork-0.1.0.dist-info → deepwork-0.1.1.dist-info}/entry_points.txt +0 -0
- {deepwork-0.1.0.dist-info → deepwork-0.1.1.dist-info}/licenses/LICENSE.md +0 -0
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
# Learn from Job Execution
|
|
2
|
+
|
|
3
|
+
## Objective
|
|
4
|
+
|
|
5
|
+
Think deeply about this task. Reflect on the current conversation to identify learnings from DeepWork job executions, improve job instructions with generalizable insights, and capture bespoke (run-specific) learnings in AGENTS.md files in the appropriate working folder.
|
|
6
|
+
|
|
7
|
+
## Task
|
|
8
|
+
|
|
9
|
+
Analyze the conversation history to extract learnings and improvements, then apply them appropriately:
|
|
10
|
+
- **Generalizable learnings** → Update job instruction files
|
|
11
|
+
- **Bespoke learnings** (specific to this run) → Add to AGENTS.md in working folder
|
|
12
|
+
|
|
13
|
+
### Step 1: Analyze Conversation for Job Executions
|
|
14
|
+
|
|
15
|
+
1. **Scan the conversation** for DeepWork slash commands that were run
|
|
16
|
+
- Look for patterns like `/job_name.step_id`
|
|
17
|
+
- Identify which jobs and steps were executed
|
|
18
|
+
- Note the order of execution
|
|
19
|
+
|
|
20
|
+
2. **Identify the working folder**
|
|
21
|
+
- Should be clear from conversation history where work was done
|
|
22
|
+
- If unclear, run `git diff` to see where changes were made on the branch
|
|
23
|
+
|
|
24
|
+
3. **If no job was specified**, ask the user:
|
|
25
|
+
- "Which DeepWork job would you like me to learn from?"
|
|
26
|
+
- List available jobs from `.deepwork/jobs/`
|
|
27
|
+
|
|
28
|
+
### Step 2: Identify Points of Confusion and Inefficiency
|
|
29
|
+
|
|
30
|
+
Review the conversation for:
|
|
31
|
+
|
|
32
|
+
1. **Confusion signals**
|
|
33
|
+
- Questions the agent asked that shouldn't have been necessary
|
|
34
|
+
- Misunderstandings about what a step required
|
|
35
|
+
- Incorrect outputs that needed correction
|
|
36
|
+
- Ambiguous instructions that led to wrong interpretations
|
|
37
|
+
|
|
38
|
+
2. **Inefficiency signals**
|
|
39
|
+
- Extra steps or iterations that were needed
|
|
40
|
+
- Information that had to be repeated
|
|
41
|
+
- Context that was missing from instructions
|
|
42
|
+
- Dependencies that weren't clear
|
|
43
|
+
|
|
44
|
+
3. **Error patterns**
|
|
45
|
+
- Failed validations and why they failed
|
|
46
|
+
- Quality criteria that were misunderstood
|
|
47
|
+
- Edge cases that weren't handled
|
|
48
|
+
|
|
49
|
+
4. **Success patterns**
|
|
50
|
+
- What worked particularly well
|
|
51
|
+
- Efficient approaches worth preserving
|
|
52
|
+
- Good examples that could be added to instructions
|
|
53
|
+
|
|
54
|
+
### Step 3: Classify Learnings
|
|
55
|
+
|
|
56
|
+
For each learning identified, determine if it is:
|
|
57
|
+
|
|
58
|
+
**Generalizable** (should improve instructions):
|
|
59
|
+
- Would help ANY future run of this job
|
|
60
|
+
- Addresses unclear or missing guidance
|
|
61
|
+
- Fixes incorrect assumptions in instructions
|
|
62
|
+
- Adds helpful examples or context
|
|
63
|
+
- Examples:
|
|
64
|
+
- "Step instructions should mention that X format is required"
|
|
65
|
+
- "Quality criteria should include checking for Y"
|
|
66
|
+
- "Add example of correct output format"
|
|
67
|
+
|
|
68
|
+
**Bespoke** (should go in AGENTS.md):
|
|
69
|
+
- Specific to THIS project/codebase/run
|
|
70
|
+
- Depends on local conventions or structure
|
|
71
|
+
- References specific files or paths
|
|
72
|
+
- Would not apply to other uses of this job
|
|
73
|
+
- Examples:
|
|
74
|
+
- "In this codebase, API endpoints are in `src/api/`"
|
|
75
|
+
- "This project uses camelCase for function names"
|
|
76
|
+
- "The main config file is at `config/settings.yml`"
|
|
77
|
+
|
|
78
|
+
### Step 4: Update Job Instructions (Generalizable Learnings)
|
|
79
|
+
|
|
80
|
+
For each generalizable learning:
|
|
81
|
+
|
|
82
|
+
1. **Locate the instruction file**
|
|
83
|
+
- Path: `.deepwork/jobs/[job_name]/steps/[step_id].md`
|
|
84
|
+
|
|
85
|
+
2. **Make targeted improvements**
|
|
86
|
+
- Add missing context or clarification
|
|
87
|
+
- Include helpful examples
|
|
88
|
+
- Clarify ambiguous instructions
|
|
89
|
+
- Update quality criteria if needed
|
|
90
|
+
|
|
91
|
+
3. **Keep instructions concise**
|
|
92
|
+
- Avoid redundancy - don't repeat the same guidance in multiple places
|
|
93
|
+
- Be direct - remove verbose explanations that don't add value
|
|
94
|
+
- Prefer bullet points over paragraphs where appropriate
|
|
95
|
+
|
|
96
|
+
4. **Preserve instruction structure**
|
|
97
|
+
- Keep existing sections (Objective, Task, Process, Output Format, Quality Criteria)
|
|
98
|
+
- Add to appropriate sections rather than restructuring
|
|
99
|
+
- Maintain consistency with other steps
|
|
100
|
+
|
|
101
|
+
5. **Track changes for changelog**
|
|
102
|
+
- Note what was changed and why
|
|
103
|
+
- Prepare changelog entry for job.yml
|
|
104
|
+
|
|
105
|
+
### Step 4b: Extract Shared Content into Referenced Files
|
|
106
|
+
|
|
107
|
+
Review all instruction files for the job and identify content that:
|
|
108
|
+
- Appears in multiple step instructions (duplicated)
|
|
109
|
+
- Is lengthy and could be extracted for clarity
|
|
110
|
+
- Would benefit from being maintained in one place
|
|
111
|
+
|
|
112
|
+
**Extract to shared files:**
|
|
113
|
+
|
|
114
|
+
1. **Create shared files** in `.deepwork/jobs/[job_name]/steps/shared/`
|
|
115
|
+
- `conventions.md` - Coding/formatting conventions used across steps
|
|
116
|
+
- `examples.md` - Common examples referenced by multiple steps
|
|
117
|
+
- `schemas.md` - Data structures or formats used throughout
|
|
118
|
+
|
|
119
|
+
2. **Reference from instructions** using markdown includes or explicit references:
|
|
120
|
+
```markdown
|
|
121
|
+
## Conventions
|
|
122
|
+
|
|
123
|
+
Follow the conventions defined in `shared/conventions.md`.
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
3. **Benefits of extraction:**
|
|
127
|
+
- Single source of truth - update once, applies everywhere
|
|
128
|
+
- Shorter instruction files - easier to read and maintain
|
|
129
|
+
- Consistent guidance across steps
|
|
130
|
+
|
|
131
|
+
### Step 5: Create/Update AGENTS.md (Bespoke Learnings)
|
|
132
|
+
|
|
133
|
+
The AGENTS.md file captures project-specific knowledge that helps future agent runs.
|
|
134
|
+
|
|
135
|
+
1. **Determine the correct location**
|
|
136
|
+
- Place AGENTS.md in the working folder where job outputs live
|
|
137
|
+
- This ensures the knowledge is available when working in that context
|
|
138
|
+
- If uncertain, place at the project root
|
|
139
|
+
|
|
140
|
+
2. **Use file references where possible**
|
|
141
|
+
- Instead of duplicating information, reference source files
|
|
142
|
+
- This keeps AGENTS.md in sync as the codebase evolves
|
|
143
|
+
- Pattern: "See `path/to/file.ext` for [description]"
|
|
144
|
+
|
|
145
|
+
3. **AGENTS.md structure**:
|
|
146
|
+
|
|
147
|
+
```markdown
|
|
148
|
+
# Project Context for [Job Name]
|
|
149
|
+
|
|
150
|
+
## Codebase Structure
|
|
151
|
+
|
|
152
|
+
<!-- Reference files rather than duplicating content -->
|
|
153
|
+
- Project structure: See `README.md` for overview
|
|
154
|
+
- API documentation: See `docs/api.md`
|
|
155
|
+
- Configuration: See `config/README.md`
|
|
156
|
+
|
|
157
|
+
## Conventions
|
|
158
|
+
|
|
159
|
+
### Naming Conventions
|
|
160
|
+
- [Convention]: See example in `path/to/example.ext:LINE`
|
|
161
|
+
|
|
162
|
+
### File Organization
|
|
163
|
+
- [Pattern]: Reference `path/to/pattern/`
|
|
164
|
+
|
|
165
|
+
## Job-Specific Context
|
|
166
|
+
|
|
167
|
+
### [Job Name]
|
|
168
|
+
|
|
169
|
+
#### [Step Name]
|
|
170
|
+
- [Learning]: Reference `relevant/file.ext`
|
|
171
|
+
- [Context]: [Brief explanation with file reference]
|
|
172
|
+
|
|
173
|
+
## Known Issues and Workarounds
|
|
174
|
+
|
|
175
|
+
- [Issue]: [Workaround with file reference if applicable]
|
|
176
|
+
|
|
177
|
+
## Last Updated
|
|
178
|
+
- Date: [YYYY-MM-DD]
|
|
179
|
+
- From conversation about: [Brief description]
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
4. **Writing entries**
|
|
183
|
+
- Be concise but specific
|
|
184
|
+
- Always prefer file references over inline content
|
|
185
|
+
- Use line numbers when referencing specific code: `file.ext:42`
|
|
186
|
+
- Group related learnings together
|
|
187
|
+
|
|
188
|
+
### Step 6: Update Job Version and Changelog
|
|
189
|
+
|
|
190
|
+
If instruction files were modified:
|
|
191
|
+
|
|
192
|
+
1. **Bump version in job.yml**
|
|
193
|
+
- Patch version (0.0.x) for instruction improvements
|
|
194
|
+
- Minor version (0.x.0) if quality criteria changed
|
|
195
|
+
|
|
196
|
+
2. **Add changelog entry**
|
|
197
|
+
```yaml
|
|
198
|
+
- version: "[new_version]"
|
|
199
|
+
changes: "Improved [step] instructions based on execution learnings: [brief description]"
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
### Step 7: Sync and Summarize
|
|
203
|
+
|
|
204
|
+
1. **Run deepwork sync** (if instructions were modified)
|
|
205
|
+
```bash
|
|
206
|
+
deepwork sync
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
2. **Create learning_summary.md** in the working folder:
|
|
210
|
+
```markdown
|
|
211
|
+
# Learning Summary
|
|
212
|
+
|
|
213
|
+
## Job Analyzed
|
|
214
|
+
- Job: [job_name]
|
|
215
|
+
- Steps executed: [list of steps]
|
|
216
|
+
|
|
217
|
+
## Generalizable Improvements Made
|
|
218
|
+
- [Step]: [What was improved]
|
|
219
|
+
|
|
220
|
+
## Bespoke Learnings Captured
|
|
221
|
+
- Location: [path to AGENTS.md]
|
|
222
|
+
- Entries added: [list of entries]
|
|
223
|
+
|
|
224
|
+
## Files Modified
|
|
225
|
+
- [List of files changed]
|
|
226
|
+
|
|
227
|
+
## Recommendations
|
|
228
|
+
- [Any additional suggestions]
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
3. **If commands were regenerated**, look at the "To use the new commands" 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)
|
|
232
|
+
|
|
233
|
+
## File Reference Patterns
|
|
234
|
+
|
|
235
|
+
When adding entries to AGENTS.md, prefer these patterns:
|
|
236
|
+
|
|
237
|
+
**Good (references)**:
|
|
238
|
+
```markdown
|
|
239
|
+
- API endpoints follow REST conventions. See `src/api/routes.ts` for examples.
|
|
240
|
+
- Error handling pattern: See `src/utils/errors.ts:15-30`
|
|
241
|
+
- Configuration schema: Defined in `config/schema.json`
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
**Avoid (duplicating)**:
|
|
245
|
+
```markdown
|
|
246
|
+
- API endpoints should return JSON with this format: { status: ..., data: ... }
|
|
247
|
+
- Error handling should use try/catch with custom error classes
|
|
248
|
+
- Configuration requires these fields: name, version, ...
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
## Quality Criteria
|
|
252
|
+
|
|
253
|
+
- Conversation has been analyzed for job executions
|
|
254
|
+
- Points of confusion and inefficiency are identified
|
|
255
|
+
- Learnings are correctly classified (generalizable vs bespoke)
|
|
256
|
+
- Job instructions updated for generalizable improvements
|
|
257
|
+
- Instructions are concise - no redundancy or unnecessary verbosity
|
|
258
|
+
- Shared/lengthy content extracted into referenced files where appropriate
|
|
259
|
+
- AGENTS.md created/updated with bespoke learnings
|
|
260
|
+
- File references used instead of duplicating content
|
|
261
|
+
- AGENTS.md is in the correct working folder
|
|
262
|
+
- learning_summary.md documents all changes
|
|
263
|
+
- When all criteria are met, include `<promise>✓ Quality Criteria Met</promise>`
|
|
264
|
+
|
|
265
|
+
## Example Dialog
|
|
266
|
+
|
|
267
|
+
```
|
|
268
|
+
User: /deepwork_jobs.learn
|
|
269
|
+
|
|
270
|
+
Claude: I'll analyze this conversation for learnings from DeepWork job executions.
|
|
271
|
+
|
|
272
|
+
**Conversation Analysis**
|
|
273
|
+
|
|
274
|
+
I found the following job executions:
|
|
275
|
+
1. `/competitive_research.identify_competitors` - Completed
|
|
276
|
+
2. `/competitive_research.research_competitors` - Completed with 2 iterations
|
|
277
|
+
3. `/competitive_research.comparative_analysis` - Completed
|
|
278
|
+
|
|
279
|
+
**Identified Issues**
|
|
280
|
+
|
|
281
|
+
1. **Confusion in step 2**: The instructions didn't specify that competitor research should include pricing information. This caused an extra iteration.
|
|
282
|
+
|
|
283
|
+
2. **Missing context**: The agent had to ask about the industry focus, which should have been carried forward from step 1.
|
|
284
|
+
|
|
285
|
+
**Classification**
|
|
286
|
+
|
|
287
|
+
- Generalizable: Add pricing to research requirements in instructions
|
|
288
|
+
- Bespoke: This project focuses on B2B SaaS in the HR tech space
|
|
289
|
+
|
|
290
|
+
**Actions Taken**
|
|
291
|
+
|
|
292
|
+
1. Updated `.deepwork/jobs/competitive_research/steps/research_competitors.md`:
|
|
293
|
+
- Added "Include pricing information (tiers, models, approximate ranges)" to research requirements
|
|
294
|
+
- Added note about carrying forward industry context from previous step
|
|
295
|
+
|
|
296
|
+
2. Created `./competitive_research_output/AGENTS.md`:
|
|
297
|
+
```markdown
|
|
298
|
+
# Project Context for Competitive Research
|
|
299
|
+
|
|
300
|
+
## Job-Specific Context
|
|
301
|
+
|
|
302
|
+
### competitive_research
|
|
303
|
+
|
|
304
|
+
#### Industry Focus
|
|
305
|
+
- Domain: B2B SaaS, HR Technology sector
|
|
306
|
+
- See `identify_competitors_output.md` for market definition
|
|
307
|
+
|
|
308
|
+
#### Competitors Identified
|
|
309
|
+
- Reference: `competitor_list.md` for full details
|
|
310
|
+
|
|
311
|
+
## Last Updated
|
|
312
|
+
- Date: 2024-01-15
|
|
313
|
+
- From conversation about: Initial competitive analysis run
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
3. Updated job.yml version to 1.0.1 with changelog entry
|
|
317
|
+
|
|
318
|
+
4. Ran `deepwork sync`
|
|
319
|
+
|
|
320
|
+
**Summary**
|
|
321
|
+
|
|
322
|
+
Created `learning_summary.md` documenting all changes. To get the updated commands, type 'exit' then run 'claude --resume'.
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
## Handling Edge Cases
|
|
326
|
+
|
|
327
|
+
**No job executions found**:
|
|
328
|
+
- Ask user which job they'd like to analyze
|
|
329
|
+
- Or offer to review available jobs
|
|
330
|
+
|
|
331
|
+
**Multiple jobs executed**:
|
|
332
|
+
- Analyze each job separately
|
|
333
|
+
- Create separate AGENTS.md entries or files as appropriate
|
|
334
|
+
|
|
335
|
+
**AGENTS.md already exists**:
|
|
336
|
+
- Read existing content
|
|
337
|
+
- Append new learnings to appropriate sections
|
|
338
|
+
- Update "Last Updated" section
|
|
339
|
+
|
|
340
|
+
**No issues found**:
|
|
341
|
+
- Document what worked well
|
|
342
|
+
- Consider if any successful patterns should be added to instructions as examples
|
|
343
|
+
|
|
344
|
+
**Sensitive information**:
|
|
345
|
+
- Never include secrets, credentials, or PII in AGENTS.md
|
|
346
|
+
- Reference config files instead of including values
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# Supplementary Reference Files
|
|
2
|
+
|
|
3
|
+
Step instructions can include additional `.md` files in the `steps/` directory. These supplementary files are useful for:
|
|
4
|
+
|
|
5
|
+
- Providing detailed examples or templates that would clutter the main instruction file
|
|
6
|
+
- Sharing common reference material across multiple steps
|
|
7
|
+
- Including technical specifications, API documentation, or style guides
|
|
8
|
+
|
|
9
|
+
## How to Use
|
|
10
|
+
|
|
11
|
+
1. Place additional `.md` files in the `steps/` directory alongside the main step instruction files
|
|
12
|
+
2. Reference them in your step instructions using the **full path from the project root**
|
|
13
|
+
|
|
14
|
+
## Example
|
|
15
|
+
|
|
16
|
+
If you have a job called `my_job` and want to include an API specification template:
|
|
17
|
+
|
|
18
|
+
1. Create the file at `.deepwork/jobs/my_job/steps/api_spec.md`
|
|
19
|
+
2. Reference it in your step instructions like this:
|
|
20
|
+
|
|
21
|
+
```markdown
|
|
22
|
+
Use the template in `.deepwork/jobs/my_job/steps/api_spec.md` to structure your API endpoints.
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Path Format
|
|
26
|
+
|
|
27
|
+
Always use the full relative path from the project root:
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
.deepwork/jobs/[job_name]/steps/[filename].md
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
For example:
|
|
34
|
+
- `.deepwork/jobs/competitive_research/steps/competitor_template.md`
|
|
35
|
+
- `.deepwork/jobs/api_design/steps/endpoint_schema.md`
|
|
36
|
+
- `.deepwork/jobs/onboarding/steps/checklist_template.md`
|
|
37
|
+
|
|
38
|
+
## Benefits
|
|
39
|
+
|
|
40
|
+
Using supplementary files keeps your main step instructions focused and readable while allowing you to provide detailed reference material when needed. The AI agent can read these files during execution to get additional context.
|
deepwork/standard_jobs/deepwork_policy/hooks/{capture_work_tree.sh → capture_prompt_work_tree.sh}
RENAMED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
#!/bin/bash
|
|
2
|
-
#
|
|
2
|
+
# capture_prompt_work_tree.sh - Captures the git work tree state at prompt submission
|
|
3
3
|
#
|
|
4
4
|
# This script creates a snapshot of the current git state by recording
|
|
5
5
|
# all files that have been modified, added, or deleted. This baseline
|
|
6
|
-
# is used
|
|
6
|
+
# is used for policies with compare_to: prompt to detect what changed
|
|
7
|
+
# during an agent response (between user prompts).
|
|
7
8
|
|
|
8
9
|
set -e
|
|
9
10
|
|
|
@@ -2,16 +2,13 @@
|
|
|
2
2
|
# policy_stop_hook.sh - Evaluates policies when the agent stops
|
|
3
3
|
#
|
|
4
4
|
# This script is called as a Claude Code Stop hook. It:
|
|
5
|
-
# 1.
|
|
6
|
-
# 2.
|
|
5
|
+
# 1. Evaluates policies from .deepwork.policy.yml
|
|
6
|
+
# 2. Computes changed files based on each policy's compare_to setting
|
|
7
7
|
# 3. Checks for <promise> tags in the conversation transcript
|
|
8
8
|
# 4. Returns JSON to block stop if policies need attention
|
|
9
|
-
# 5. Resets the work tree baseline for the next iteration
|
|
10
9
|
|
|
11
10
|
set -e
|
|
12
11
|
|
|
13
|
-
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
14
|
-
|
|
15
12
|
# Check if policy file exists
|
|
16
13
|
if [ ! -f .deepwork.policy.yml ]; then
|
|
17
14
|
# No policies defined, nothing to do
|
|
@@ -31,16 +28,6 @@ if [ -n "${HOOK_INPUT}" ]; then
|
|
|
31
28
|
TRANSCRIPT_PATH=$(echo "${HOOK_INPUT}" | jq -r '.transcript_path // empty' 2>/dev/null || echo "")
|
|
32
29
|
fi
|
|
33
30
|
|
|
34
|
-
# Get changed files
|
|
35
|
-
changed_files=$("${SCRIPT_DIR}/get_changed_files.sh" 2>/dev/null || echo "")
|
|
36
|
-
|
|
37
|
-
# If no files changed, nothing to evaluate
|
|
38
|
-
if [ -z "${changed_files}" ]; then
|
|
39
|
-
# Reset baseline for next iteration
|
|
40
|
-
"${SCRIPT_DIR}/capture_work_tree.sh" 2>/dev/null || true
|
|
41
|
-
exit 0
|
|
42
|
-
fi
|
|
43
|
-
|
|
44
31
|
# Extract conversation text from the JSONL transcript
|
|
45
32
|
# The transcript is JSONL format - each line is a JSON object
|
|
46
33
|
# We need to extract the text content from assistant messages
|
|
@@ -57,16 +44,13 @@ fi
|
|
|
57
44
|
# Call the Python evaluator
|
|
58
45
|
# The Python module handles:
|
|
59
46
|
# - Parsing the policy file
|
|
47
|
+
# - Computing changed files based on each policy's compare_to setting
|
|
60
48
|
# - Matching changed files against triggers/safety patterns
|
|
61
49
|
# - Checking for promise tags in the conversation context
|
|
62
50
|
# - Generating appropriate JSON output
|
|
63
51
|
result=$(echo "${conversation_context}" | python -m deepwork.hooks.evaluate_policies \
|
|
64
52
|
--policy-file .deepwork.policy.yml \
|
|
65
|
-
--changed-files "${changed_files}" \
|
|
66
53
|
2>/dev/null || echo '{}')
|
|
67
54
|
|
|
68
|
-
# Reset the work tree baseline for the next iteration
|
|
69
|
-
"${SCRIPT_DIR}/capture_work_tree.sh" 2>/dev/null || true
|
|
70
|
-
|
|
71
55
|
# Output the result (JSON for Claude Code hooks)
|
|
72
56
|
echo "${result}"
|
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
#!/bin/bash
|
|
2
2
|
# user_prompt_submit.sh - Runs on every user prompt submission
|
|
3
3
|
#
|
|
4
|
-
# This script captures the work tree
|
|
5
|
-
# This
|
|
4
|
+
# This script captures the work tree state at each prompt submission.
|
|
5
|
+
# This baseline is used for policies with compare_to: prompt to detect
|
|
6
|
+
# what changed during an agent response.
|
|
6
7
|
|
|
7
8
|
set -e
|
|
8
9
|
|
|
9
10
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
10
11
|
|
|
11
|
-
#
|
|
12
|
-
|
|
13
|
-
"${SCRIPT_DIR}/capture_work_tree.sh"
|
|
14
|
-
fi
|
|
12
|
+
# Capture work tree state at each prompt for compare_to: prompt policies
|
|
13
|
+
"${SCRIPT_DIR}/capture_prompt_work_tree.sh"
|
|
15
14
|
|
|
16
15
|
# Exit successfully - don't block the prompt
|
|
17
16
|
exit 0
|
|
@@ -56,6 +56,22 @@ If there are files that, when also changed, mean the policy shouldn't fire:
|
|
|
56
56
|
- Trigger: `src/auth/**/*`
|
|
57
57
|
- Safety: `SECURITY.md`, `docs/security_review.md`
|
|
58
58
|
|
|
59
|
+
### Step 3b: Choose the Comparison Mode (Optional)
|
|
60
|
+
|
|
61
|
+
The `compare_to` field controls what baseline is used when detecting "changed files":
|
|
62
|
+
|
|
63
|
+
**Options:**
|
|
64
|
+
- `base` (default) - Compares to the base of the current branch (merge-base with main/master). This is the most common choice for feature branches, as it shows all changes made on the branch.
|
|
65
|
+
- `default_tip` - Compares to the current tip of the default branch (main/master). Useful when you want to see the difference from what's currently in production.
|
|
66
|
+
- `prompt` - Compares to the state at the start of each prompt. Useful for policies that should only fire based on changes made during a single agent response.
|
|
67
|
+
|
|
68
|
+
**When to use each:**
|
|
69
|
+
- **base**: Best for most policies. "Did this branch change config files?" → trigger docs review
|
|
70
|
+
- **default_tip**: For policies about what's different from production/main
|
|
71
|
+
- **prompt**: For policies that should only consider very recent changes within the current session
|
|
72
|
+
|
|
73
|
+
Most policies should use the default (`base`) and don't need to specify `compare_to`.
|
|
74
|
+
|
|
59
75
|
### Step 4: Write the Instructions
|
|
60
76
|
|
|
61
77
|
Create clear, actionable instructions for what the agent should do when the policy fires.
|
|
@@ -86,6 +102,7 @@ Create or update `.deepwork.policy.yml` in the project root.
|
|
|
86
102
|
- name: "[Friendly name for the policy]"
|
|
87
103
|
trigger: "[glob pattern]" # or array: ["pattern1", "pattern2"]
|
|
88
104
|
safety: "[glob pattern]" # optional, or array
|
|
105
|
+
compare_to: "base" # optional: "base" (default), "default_tip", or "prompt"
|
|
89
106
|
instructions: |
|
|
90
107
|
[Multi-line instructions for the agent...]
|
|
91
108
|
```
|
|
@@ -95,6 +112,7 @@ Create or update `.deepwork.policy.yml` in the project root.
|
|
|
95
112
|
- name: "[Friendly name for the policy]"
|
|
96
113
|
trigger: "[glob pattern]"
|
|
97
114
|
safety: "[glob pattern]"
|
|
115
|
+
compare_to: "base" # optional
|
|
98
116
|
instructions_file: "path/to/instructions.md"
|
|
99
117
|
```
|
|
100
118
|
|
|
@@ -166,7 +184,10 @@ Create or update this file at the project root with the new policy entry.
|
|
|
166
184
|
## Context
|
|
167
185
|
|
|
168
186
|
Policies are evaluated automatically when you finish working on a task. The system:
|
|
169
|
-
1.
|
|
187
|
+
1. Determines which files have changed based on each policy's `compare_to` setting:
|
|
188
|
+
- `base` (default): Files changed since the branch diverged from main/master
|
|
189
|
+
- `default_tip`: Files different from the current main/master branch
|
|
190
|
+
- `prompt`: Files changed since the last prompt submission
|
|
170
191
|
2. Checks if any changes match policy trigger patterns
|
|
171
192
|
3. Skips policies where safety patterns also matched
|
|
172
193
|
4. Prompts you with instructions for any triggered policies
|