deepwork 0.1.0__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.
Files changed (41) hide show
  1. deepwork/__init__.py +25 -0
  2. deepwork/cli/__init__.py +1 -0
  3. deepwork/cli/install.py +290 -0
  4. deepwork/cli/main.py +25 -0
  5. deepwork/cli/sync.py +176 -0
  6. deepwork/core/__init__.py +1 -0
  7. deepwork/core/adapters.py +373 -0
  8. deepwork/core/detector.py +93 -0
  9. deepwork/core/generator.py +290 -0
  10. deepwork/core/hooks_syncer.py +206 -0
  11. deepwork/core/parser.py +310 -0
  12. deepwork/core/policy_parser.py +285 -0
  13. deepwork/hooks/__init__.py +1 -0
  14. deepwork/hooks/evaluate_policies.py +159 -0
  15. deepwork/schemas/__init__.py +1 -0
  16. deepwork/schemas/job_schema.py +212 -0
  17. deepwork/schemas/policy_schema.py +68 -0
  18. deepwork/standard_jobs/deepwork_jobs/job.yml +102 -0
  19. deepwork/standard_jobs/deepwork_jobs/steps/define.md +359 -0
  20. deepwork/standard_jobs/deepwork_jobs/steps/implement.md +435 -0
  21. deepwork/standard_jobs/deepwork_jobs/steps/refine.md +447 -0
  22. deepwork/standard_jobs/deepwork_policy/hooks/capture_work_tree.sh +26 -0
  23. deepwork/standard_jobs/deepwork_policy/hooks/get_changed_files.sh +30 -0
  24. deepwork/standard_jobs/deepwork_policy/hooks/global_hooks.yml +8 -0
  25. deepwork/standard_jobs/deepwork_policy/hooks/policy_stop_hook.sh +72 -0
  26. deepwork/standard_jobs/deepwork_policy/hooks/user_prompt_submit.sh +17 -0
  27. deepwork/standard_jobs/deepwork_policy/job.yml +35 -0
  28. deepwork/standard_jobs/deepwork_policy/steps/define.md +174 -0
  29. deepwork/templates/__init__.py +1 -0
  30. deepwork/templates/claude/command-job-step.md.jinja +210 -0
  31. deepwork/templates/gemini/command-job-step.toml.jinja +169 -0
  32. deepwork/utils/__init__.py +1 -0
  33. deepwork/utils/fs.py +128 -0
  34. deepwork/utils/git.py +164 -0
  35. deepwork/utils/validation.py +31 -0
  36. deepwork/utils/yaml_utils.py +89 -0
  37. deepwork-0.1.0.dist-info/METADATA +389 -0
  38. deepwork-0.1.0.dist-info/RECORD +41 -0
  39. deepwork-0.1.0.dist-info/WHEEL +4 -0
  40. deepwork-0.1.0.dist-info/entry_points.txt +2 -0
  41. deepwork-0.1.0.dist-info/licenses/LICENSE.md +60 -0
@@ -0,0 +1,447 @@
1
+ # Refine Existing DeepWork Job
2
+
3
+ ## Objective
4
+
5
+ Help the user modify an existing DeepWork job definition by understanding what they want to change and ensuring the modifications maintain consistency and validity.
6
+
7
+ ## Task
8
+
9
+ Guide the user through refining a job by first understanding their existing job, then what they want to change, and finally implementing those changes safely.
10
+
11
+ ### Step 1: Select and Load Job
12
+
13
+ 1. **List available jobs**
14
+ - Scan `.deepwork/jobs/` directory for installed jobs
15
+ - Display installed jobs with versions and descriptions
16
+ - Ask which job to refine
17
+
18
+ 2. **Load job definition**
19
+ - Read `.deepwork/jobs/[job_name]/job.yml`
20
+ - Parse and understand the current structure
21
+
22
+ 3. **Show current structure**
23
+ - Display all steps with their names and descriptions
24
+ - Show the dependency flow
25
+ - Highlight key inputs and outputs
26
+
27
+ ### Step 2: Understand Desired Changes
28
+
29
+ Ask the user what they want to change:
30
+
31
+ **Change Options:**
32
+ 1. Add a new step to the workflow
33
+ 2. Modify step instructions
34
+ 3. Change step inputs/outputs
35
+ 4. Update dependencies between steps
36
+ 5. Update job metadata (description, version)
37
+ 6. Remove a step
38
+ 7. Add or modify stop hooks (quality validation)
39
+
40
+ **For each change, ask clarifying questions:**
41
+ - Why do they want to make this change?
42
+ - How will it improve the workflow?
43
+ - Are there dependencies or side effects to consider?
44
+
45
+ ### Step 3: Make Changes Safely
46
+
47
+ Based on the user's selection:
48
+
49
+ #### Adding a Step
50
+
51
+ 1. **Gather step details** (same as define command)
52
+ - What does this step accomplish?
53
+ - What are the inputs? User parameters or file inputs?
54
+ - What outputs does it produce?
55
+ - What are the dependencies?
56
+
57
+ 2. **Determine placement**
58
+ - Where should it go in the workflow?
59
+ - Before which existing step?
60
+ - Or at the end?
61
+
62
+ 3. **Validate placement**
63
+ - Can't depend on later steps if inserted early
64
+ - File inputs must come from dependencies
65
+ - Check for circular dependencies
66
+
67
+ 4. **Update files**
68
+ - Update `job.yml` with new step
69
+ - Create step instructions file in `steps/[step_id].md`
70
+ - Prepare changelog entry describing the addition
71
+
72
+ #### Modifying Step Instructions
73
+
74
+ 1. **Select step to modify**
75
+ - Show list of steps
76
+ - Ask which one to modify
77
+
78
+ 2. **Understand the change**
79
+ - What's not working with current instructions?
80
+ - What should be different?
81
+ - Show current instructions
82
+
83
+ 3. **Update instructions**
84
+ - Modify `.deepwork/jobs/[job_name]/steps/[step_id].md`
85
+ - Keep the same structure (Objective, Task, Process, Output Format, Quality Criteria)
86
+ - Prepare changelog entry describing the modification
87
+
88
+ #### Changing Inputs/Outputs
89
+
90
+ 1. **Select step to modify**
91
+ 2. **Show current inputs and outputs**
92
+ 3. **Understand the change**
93
+ - Adding or removing?
94
+ - Why is this needed?
95
+
96
+ 4. **Validate impact**
97
+ - If removing output: check if other steps depend on it (BREAKING CHANGE)
98
+ - If adding file input: ensure from_step is in dependencies
99
+ - If removing input: ensure it's not critical
100
+
101
+ 5. **Update job.yml**
102
+ - Prepare changelog entry describing the input/output changes
103
+
104
+ #### Updating Dependencies
105
+
106
+ 1. **Select step to modify**
107
+ 2. **Show current dependency graph**
108
+ 3. **Understand the change**
109
+ - Adding or removing dependency?
110
+ - Why?
111
+
112
+ 4. **Validate**
113
+ - Check for circular dependencies
114
+ - Ensure all file inputs have matching dependencies
115
+ - Ensure dependency chain makes logical sense
116
+
117
+ 5. **Update job.yml**
118
+ - Prepare changelog entry describing the dependency changes
119
+
120
+ #### Updating Metadata
121
+
122
+ 1. **Ask what to change**
123
+ - Description?
124
+ - Version?
125
+
126
+ 2. **If version change, explain semantic versioning**
127
+ - Major (x.0.0): Breaking changes (removing steps, removing outputs)
128
+ - Minor (0.x.0): New features, backwards compatible (adding steps)
129
+ - Patch (0.0.x): Bug fixes, improvements
130
+
131
+ 3. **Update job.yml**
132
+ - Prepare changelog entry describing the metadata changes
133
+
134
+ #### Removing a Step
135
+
136
+ 1. **Select step to remove**
137
+
138
+ 2. **CRITICAL: Validate safety**
139
+ - Check if other steps depend on this step
140
+ - Check if other steps use outputs from this step
141
+ - If dependencies exist: **WARN** and suggest updating dependents first
142
+ - This is a BREAKING CHANGE - requires major version bump
143
+
144
+ 3. **If safe to remove**
145
+ - Remove from `job.yml`
146
+ - Delete step instructions file
147
+ - Suggest version bump
148
+ - Prepare changelog entry describing the removal
149
+
150
+ #### Adding or Modifying Stop Hooks
151
+
152
+ Stop hooks provide quality validation loops that ensure step outputs meet criteria before completing.
153
+
154
+ 1. **Select step to modify**
155
+ - Show list of steps
156
+ - Ask which one to add/modify hooks for
157
+
158
+ 2. **Understand the need**
159
+ - What quality criteria should be validated?
160
+ - Is the output subjective (use prompt hook) or objective (use script hook)?
161
+ - Should validation happen automatically or only on specific conditions?
162
+
163
+ 3. **Choose hook type**
164
+
165
+ **Prompt hooks** (recommended for most cases):
166
+ - Best for subjective quality criteria
167
+ - AI evaluates the output against criteria
168
+ - Example: "Verify the report is comprehensive and well-organized"
169
+ ```yaml
170
+ stop_hooks:
171
+ - prompt: |
172
+ Verify the output meets criteria:
173
+ 1. Contains all required sections
174
+ 2. Analysis is thorough
175
+ 3. Recommendations are actionable
176
+ ```
177
+
178
+ **Prompt file hooks**:
179
+ - For reusable or complex validation criteria
180
+ - Stores criteria in a separate markdown file
181
+ ```yaml
182
+ stop_hooks:
183
+ - prompt_file: hooks/quality_check.md
184
+ ```
185
+
186
+ **Script hooks**:
187
+ - For objective, programmatic validation
188
+ - Best for tests, linting, format checking
189
+ ```yaml
190
+ stop_hooks:
191
+ - script: hooks/run_tests.sh
192
+ ```
193
+
194
+ 4. **Multiple hooks can be combined**
195
+ ```yaml
196
+ stop_hooks:
197
+ - script: hooks/lint.sh # First: objective checks
198
+ - prompt: "Verify content quality" # Then: subjective review
199
+ ```
200
+
201
+ 5. **Update files**
202
+ - Add/modify `stop_hooks` array in job.yml
203
+ - Create hook files if using prompt_file or script types
204
+ - Update step instructions to match quality criteria
205
+ - Prepare changelog entry
206
+
207
+ 6. **Encourage prompt-based hooks**
208
+ - They leverage the AI's ability to understand context
209
+ - More flexible than rigid script checks
210
+ - Can evaluate nuanced quality criteria
211
+
212
+ ### Step 4: Update Changelog
213
+
214
+ After making changes to the job.yml:
215
+
216
+ 1. **Add a changelog entry**
217
+ - Add a new entry to the `changelog` array in the job.yml
218
+ - Use the new version number
219
+ - List all changes made in this refinement
220
+
221
+ 2. **Changelog entry format**:
222
+ ```yaml
223
+ - version: "[new_version]"
224
+ changes: "[Description of all changes in this version]"
225
+ ```
226
+
227
+ 3. **Example changelog entries**:
228
+ - "Added step: validate_positioning"
229
+ - "Modified step instructions for research_competitors to improve clarity and add quality criteria"
230
+ - "Removed step: duplicate_analysis (consolidated into comparative_analysis)"
231
+ - "Updated dependencies: positioning_recommendations now depends on validate_positioning"
232
+ - "Changed output filename: comparison_matrix.md → comparison_table.md"
233
+ - "Added step: validate_positioning; Updated dependencies for positioning_recommendations"
234
+
235
+ ### Step 5: Validate Changes
236
+
237
+ After updating the changelog:
238
+
239
+ 1. **Review the updated structure**
240
+ - Show the complete updated workflow
241
+ - Highlight what changed
242
+ - Check for consistency
243
+
244
+ 2. **Validate job definition**
245
+ - No circular dependencies
246
+ - All file inputs match dependencies
247
+ - All step IDs unique
248
+ - All outputs defined
249
+
250
+ 3. **Confirm version update**
251
+ - Ensure version was bumped appropriately
252
+ - Breaking changes? Major version
253
+ - New features? Minor version
254
+ - Improvements? Patch version
255
+
256
+ ### Step 6: Sync and Reload
257
+
258
+ 1. **Run sync**
259
+ ```bash
260
+ deepwork sync
261
+ ```
262
+
263
+ 2. **Reload commands**
264
+ - Instruct user to run `/reload` or restart session
265
+
266
+ 3. **Provide summary**
267
+ - Show what changed
268
+ - List updated files
269
+ - Display the changelog entry
270
+ - Explain next steps
271
+
272
+ ## Safe Modification Patterns
273
+
274
+ Guide users toward safe changes:
275
+
276
+ ### Safe Changes (Always OK)
277
+ - Adding steps at the end with new outputs
278
+ - Updating step instructions (content only)
279
+ - Changing job description
280
+ - Adding user inputs to a step
281
+ - Adding outputs (not removing)
282
+ - Patch version bumps
283
+
284
+ ### Potentially Breaking Changes (Warn User)
285
+ - Removing steps
286
+ - Removing outputs
287
+ - Removing inputs
288
+ - Changing dependencies
289
+ - Renaming outputs (other steps may reference them)
290
+ - Requires major or minor version bump
291
+
292
+ ### Always Validate
293
+ - Circular dependencies after any dependency change
294
+ - File inputs match dependencies after any change
295
+ - Step IDs remain unique
296
+ - At least one output per step
297
+
298
+ ## Example Dialog
299
+
300
+ ```
301
+ Claude: I'll help you refine an existing job. Here are your installed jobs:
302
+
303
+ 1. competitive_research v1.0.0 - Systematic competitive analysis workflow
304
+ 2. blog_post v1.0.0 - Blog post creation workflow
305
+
306
+ Which job would you like to refine?
307
+
308
+ User: 1
309
+
310
+ Claude: Loading competitive_research v1.0.0...
311
+
312
+ Current structure:
313
+ - Step 1: identify_competitors - Identify 5-7 competitors in target market
314
+ - Step 2: research_competitors - Deep research on each competitor
315
+ - Step 3: comparative_analysis - Side-by-side comparison matrix
316
+ - Step 4: positioning_recommendations - Strategic positioning report
317
+
318
+ What would you like to change?
319
+ 1. Add a new step
320
+ 2. Modify step instructions
321
+ 3. Change inputs/outputs
322
+ 4. Update dependencies
323
+ 5. Update job metadata
324
+ 6. Remove a step
325
+
326
+ User: 1
327
+
328
+ Claude: Great! Let's add a new step. First, help me understand:
329
+
330
+ 1. What should this new step accomplish?
331
+ 2. Where should it fit in the workflow?
332
+ - Should it go between existing steps or at the end?
333
+
334
+ User: I want to add a step that validates our product positioning before the final recommendations. It should go between step 3 and step 4.
335
+
336
+ Claude: Excellent idea. So this would be:
337
+ - Step 4: validate_positioning
338
+ - Step 5: positioning_recommendations (renumbered)
339
+
340
+ For this validation step:
341
+ 1. What inputs does it need? I assume it needs the comparison_matrix.md from step 3?
342
+ 2. What should it output?
343
+ 3. What exactly should this validation check for?
344
+
345
+ User: Yes, it needs the comparison matrix. It should output a validation_report.md that identifies gaps in our positioning.
346
+
347
+ Claude: Perfect. Let me confirm the details:
348
+
349
+ **New Step: validate_positioning**
350
+ - Name: "Validate Product Positioning"
351
+ - Description: "Identify gaps and opportunities in current positioning"
352
+ - Inputs: comparison_matrix.md (from comparative_analysis step)
353
+ - Outputs: validation_report.md
354
+ - Dependencies: comparative_analysis
355
+ - Position: Between step 3 and 4
356
+
357
+ Should the positioning_recommendations step also use the validation_report.md as input?
358
+
359
+ User: Yes, definitely
360
+
361
+ Claude: Great! So I'll also update the positioning_recommendations step to include validation_report.md as an input and add validate_positioning as a dependency.
362
+
363
+ This is a new feature, so I'll bump the version to 1.1.0 (minor version).
364
+
365
+ Creating the new step... ✓
366
+
367
+ Updated files:
368
+ - .deepwork/jobs/competitive_research/job.yml (added step, updated dependencies, version → 1.1.0, updated changelog)
369
+ - .deepwork/jobs/competitive_research/steps/validate_positioning.md (created)
370
+
371
+ Changelog entry added:
372
+ ```yaml
373
+ - version: "1.1.0"
374
+ changes: "Added step: validate_positioning between comparative_analysis and positioning_recommendations; Updated dependencies for positioning_recommendations"
375
+ ```
376
+
377
+ Now run:
378
+ ```bash
379
+ deepwork sync
380
+ ```
381
+
382
+ Then reload your session and you'll have:
383
+ - /competitive_research.validate_positioning (new!)
384
+ - All other commands updated
385
+ ```
386
+
387
+ ## Validation Rules
388
+
389
+ Enforce the same rules as job definition:
390
+ - Job name: lowercase, underscores
391
+ - Version: semantic versioning
392
+ - Step IDs: unique within job
393
+ - Dependencies: must reference existing step IDs
394
+ - File inputs: `from_step` must be in dependencies
395
+ - At least one output per step
396
+ - No circular dependencies
397
+
398
+ ## Error Handling
399
+
400
+ If issues arise, provide clear guidance:
401
+ - **Dependency conflict**: "Step X depends on step Y which you're trying to remove. You must update step X first, or remove both steps."
402
+ - **Circular dependency**: "Adding this dependency would create a cycle: A → B → C → A. Please choose a different dependency structure."
403
+ - **Missing file input**: "Step X requires file.md from step Y, but Y is not in its dependencies. I'll add Y to the dependencies."
404
+ - **Breaking change**: "Removing this output is a breaking change. Other steps depend on it. I recommend against this change unless you update the dependent steps first."
405
+
406
+ ## Changelog Entry Format
407
+
408
+ Instead of creating a separate refinement_summary.md file, add the changes directly to the job.yml changelog section. This creates a permanent version history within the job definition itself.
409
+
410
+ **Location**: `.deepwork/jobs/[job_name]/job.yml`
411
+
412
+ **Add to the `changelog` array**:
413
+
414
+ ```yaml
415
+ changelog:
416
+ - version: "1.0.0"
417
+ changes: "Initial job creation"
418
+ - version: "[new_version]"
419
+ changes: "[Concise description of all changes in this version]"
420
+ ```
421
+
422
+ **Guidelines for changelog entries**:
423
+ - Be concise but descriptive
424
+ - Use action verbs (Added, Modified, Removed, Updated, Changed, Fixed)
425
+ - Reference specific step names when relevant
426
+ - For breaking changes, prefix with "BREAKING:"
427
+ - If multiple changes, separate with semicolons or use clear phrasing
428
+
429
+ **Examples**:
430
+ - "Added step: validate_positioning between comparative_analysis and positioning_recommendations"
431
+ - "Modified step instructions for research_competitors to improve clarity and add quality criteria"
432
+ - "Removed step: duplicate_analysis (consolidated into comparative_analysis)"
433
+ - "Updated dependencies: positioning_recommendations now depends on validate_positioning"
434
+ - "Changed output filename: comparison_matrix.md → comparison_table.md"
435
+ - "BREAKING: Removed output file shared_data.json from identify_competitors step"
436
+ - "Fixed circular dependency between steps A and B"
437
+ - "Updated job description to reflect new validation phase"
438
+ - "Added validate_positioning step; Updated dependencies for positioning_recommendations"
439
+
440
+ ## Quality Criteria
441
+
442
+ - Changes maintain job consistency
443
+ - Dependencies are logically valid
444
+ - Version bump follows semantic versioning
445
+ - No circular dependencies introduced
446
+ - User understands impact of changes
447
+ - Breaking changes are clearly communicated
@@ -0,0 +1,26 @@
1
+ #!/bin/bash
2
+ # capture_work_tree.sh - Captures the current git work tree state
3
+ #
4
+ # This script creates a snapshot of the current git state by recording
5
+ # all files that have been modified, added, or deleted. This baseline
6
+ # is used later to detect what changed during an agent session.
7
+
8
+ set -e
9
+
10
+ # Ensure .deepwork directory exists
11
+ mkdir -p .deepwork
12
+
13
+ # Stage all changes so we can diff against HEAD
14
+ git add -A 2>/dev/null || true
15
+
16
+ # Save the current state of changed files
17
+ # Using git diff --name-only HEAD to get the list of all changed files
18
+ git diff --name-only HEAD > .deepwork/.last_work_tree 2>/dev/null || true
19
+
20
+ # Also include untracked files not yet in the index
21
+ git ls-files --others --exclude-standard >> .deepwork/.last_work_tree 2>/dev/null || true
22
+
23
+ # Sort and deduplicate
24
+ if [ -f .deepwork/.last_work_tree ]; then
25
+ sort -u .deepwork/.last_work_tree -o .deepwork/.last_work_tree
26
+ fi
@@ -0,0 +1,30 @@
1
+ #!/bin/bash
2
+ # get_changed_files.sh - Gets files that changed since the last work tree capture
3
+ #
4
+ # This script compares the current git state against the baseline captured
5
+ # at the start of the session to determine what files were modified.
6
+
7
+ set -e
8
+
9
+ # Stage all current changes
10
+ git add -A 2>/dev/null || true
11
+
12
+ # Get current state
13
+ current_files=$(git diff --name-only HEAD 2>/dev/null || echo "")
14
+ untracked=$(git ls-files --others --exclude-standard 2>/dev/null || echo "")
15
+
16
+ # Combine and deduplicate current files
17
+ all_current=$(echo -e "${current_files}\n${untracked}" | sort -u | grep -v '^$' || true)
18
+
19
+ if [ -f .deepwork/.last_work_tree ]; then
20
+ # Compare with baseline - files that are new or different
21
+ # Get files in current that weren't in baseline
22
+ last_files=$(cat .deepwork/.last_work_tree 2>/dev/null || echo "")
23
+
24
+ # Output files that are in current state
25
+ # This includes both newly changed files and files that were already changed
26
+ echo "${all_current}"
27
+ else
28
+ # No baseline exists - return all currently changed files
29
+ echo "${all_current}"
30
+ fi
@@ -0,0 +1,8 @@
1
+ # DeepWork Policy Hooks Configuration
2
+ # Maps Claude Code lifecycle events to hook scripts
3
+
4
+ UserPromptSubmit:
5
+ - user_prompt_submit.sh
6
+
7
+ Stop:
8
+ - policy_stop_hook.sh
@@ -0,0 +1,72 @@
1
+ #!/bin/bash
2
+ # policy_stop_hook.sh - Evaluates policies when the agent stops
3
+ #
4
+ # This script is called as a Claude Code Stop hook. It:
5
+ # 1. Gets the list of files changed during the session
6
+ # 2. Evaluates policies from .deepwork.policy.yml
7
+ # 3. Checks for <promise> tags in the conversation transcript
8
+ # 4. Returns JSON to block stop if policies need attention
9
+ # 5. Resets the work tree baseline for the next iteration
10
+
11
+ set -e
12
+
13
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
14
+
15
+ # Check if policy file exists
16
+ if [ ! -f .deepwork.policy.yml ]; then
17
+ # No policies defined, nothing to do
18
+ exit 0
19
+ fi
20
+
21
+ # Read the hook input JSON from stdin
22
+ HOOK_INPUT=""
23
+ if [ ! -t 0 ]; then
24
+ HOOK_INPUT=$(cat)
25
+ fi
26
+
27
+ # Extract transcript_path from the hook input JSON using jq
28
+ # Claude Code passes: {"session_id": "...", "transcript_path": "...", ...}
29
+ TRANSCRIPT_PATH=""
30
+ if [ -n "${HOOK_INPUT}" ]; then
31
+ TRANSCRIPT_PATH=$(echo "${HOOK_INPUT}" | jq -r '.transcript_path // empty' 2>/dev/null || echo "")
32
+ fi
33
+
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
+ # Extract conversation text from the JSONL transcript
45
+ # The transcript is JSONL format - each line is a JSON object
46
+ # We need to extract the text content from assistant messages
47
+ conversation_context=""
48
+ if [ -n "${TRANSCRIPT_PATH}" ] && [ -f "${TRANSCRIPT_PATH}" ]; then
49
+ # Extract text content from all assistant messages in the transcript
50
+ # Each line is a JSON object; we extract .message.content[].text for assistant messages
51
+ conversation_context=$(cat "${TRANSCRIPT_PATH}" | \
52
+ grep -E '"role"\s*:\s*"assistant"' | \
53
+ jq -r '.message.content // [] | map(select(.type == "text")) | map(.text) | join("\n")' 2>/dev/null | \
54
+ tr -d '\0' || echo "")
55
+ fi
56
+
57
+ # Call the Python evaluator
58
+ # The Python module handles:
59
+ # - Parsing the policy file
60
+ # - Matching changed files against triggers/safety patterns
61
+ # - Checking for promise tags in the conversation context
62
+ # - Generating appropriate JSON output
63
+ result=$(echo "${conversation_context}" | python -m deepwork.hooks.evaluate_policies \
64
+ --policy-file .deepwork.policy.yml \
65
+ --changed-files "${changed_files}" \
66
+ 2>/dev/null || echo '{}')
67
+
68
+ # Reset the work tree baseline for the next iteration
69
+ "${SCRIPT_DIR}/capture_work_tree.sh" 2>/dev/null || true
70
+
71
+ # Output the result (JSON for Claude Code hooks)
72
+ echo "${result}"
@@ -0,0 +1,17 @@
1
+ #!/bin/bash
2
+ # user_prompt_submit.sh - Runs on every user prompt submission
3
+ #
4
+ # This script captures the work tree baseline if it doesn't exist yet.
5
+ # This ensures we have a baseline to compare against when evaluating policies.
6
+
7
+ set -e
8
+
9
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
10
+
11
+ # Only capture if no baseline exists yet (first prompt of session)
12
+ if [ ! -f .deepwork/.last_work_tree ]; then
13
+ "${SCRIPT_DIR}/capture_work_tree.sh"
14
+ fi
15
+
16
+ # Exit successfully - don't block the prompt
17
+ exit 0
@@ -0,0 +1,35 @@
1
+ name: deepwork_policy
2
+ version: "0.1.0"
3
+ summary: "Policy enforcement for AI agent sessions"
4
+ description: |
5
+ Manages policies that automatically trigger when certain files change during an AI agent session.
6
+ Policies help ensure that code changes follow team guidelines, documentation is updated,
7
+ and architectural decisions are respected.
8
+
9
+ Policies are defined in a `.deepwork.policy.yml` file at the root of your project. Each policy
10
+ specifies:
11
+ - Trigger patterns: Glob patterns for files that, when changed, should trigger the policy
12
+ - Safety patterns: Glob patterns for files that, if also changed, mean the policy doesn't need to fire
13
+ - Instructions: What the agent should do when the policy triggers
14
+
15
+ Example use cases:
16
+ - Update installation docs when configuration files change
17
+ - Require security review when authentication code is modified
18
+ - Ensure API documentation stays in sync with API code
19
+ - Remind developers to update changelogs
20
+
21
+ changelog:
22
+ - version: "0.1.0"
23
+ changes: "Initial version"
24
+
25
+ steps:
26
+ - id: define
27
+ name: "Define Policy"
28
+ description: "Create or update policy entries in .deepwork.policy.yml"
29
+ instructions_file: steps/define.md
30
+ inputs:
31
+ - name: policy_purpose
32
+ description: "What guideline or constraint should this policy enforce?"
33
+ outputs:
34
+ - .deepwork.policy.yml
35
+ dependencies: []