Skip to content

Commit 19a8310

Browse files
committed
Update documentation and version for policy system v2
- Update README.md with v2 policy examples and directory structure - Update doc/architecture.md with v2 detection modes, action types, and queue system - Bump version to 0.4.0 in pyproject.toml - Add changelog entry for v2 policy system features
1 parent 549cfa5 commit 19a8310

4 files changed

Lines changed: 183 additions & 53 deletions

File tree

CHANGELOG.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,24 @@ All notable changes to DeepWork will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.4.0] - 2026-01-16
9+
10+
### Added
11+
- Policy system v2 with frontmatter markdown format in `.deepwork/policies/`
12+
- Detection modes: trigger/safety (default), set (bidirectional), pair (directional)
13+
- Action types: prompt (show instructions), command (run idempotent commands)
14+
- Variable pattern matching with `{path}` (multi-segment) and `{name}` (single-segment)
15+
- Queue system in `.deepwork/tmp/policy/queue/` for state tracking and deduplication
16+
- New core modules:
17+
- `pattern_matcher.py`: Variable pattern matching with regex-based capture
18+
- `policy_queue.py`: Queue system for policy state persistence
19+
- `command_executor.py`: Command action execution with variable substitution
20+
- Updated `policy_check.py` hook to use v2 system with queue-based deduplication
21+
22+
### Changed
23+
- Policy parser now supports both v1 (`.deepwork.policy.yml`) and v2 (`.deepwork/policies/*.md`) formats
24+
- Documentation updated with v2 policy examples and configuration
25+
826
## [0.3.0] - 2026-01-16
927

1028
### Added
@@ -64,6 +82,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6482

6583
Initial version.
6684

85+
[0.4.0]: https://github.com/anthropics/deepwork/releases/tag/0.4.0
6786
[0.3.0]: https://github.com/anthropics/deepwork/releases/tag/0.3.0
6887
[0.1.1]: https://github.com/anthropics/deepwork/releases/tag/0.1.1
6988
[0.1.0]: https://github.com/anthropics/deepwork/releases/tag/0.1.0

README.md

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,10 @@ DeepWork follows a **Git-native, installation-only** design:
178178
your-project/
179179
├── .deepwork/
180180
│ ├── config.yml # Platform configuration
181+
│ ├── policies/ # Policy definitions (v2 format)
182+
│ │ └── policy-name.md # Individual policy files
183+
│ ├── tmp/ # Temporary state (gitignored)
184+
│ │ └── policy/queue/ # Policy evaluation queue
181185
│ └── jobs/ # Job definitions
182186
│ └── job_name/
183187
│ ├── job.yml # Job metadata
@@ -208,11 +212,16 @@ deepwork/
208212
│ ├── core/ # Core functionality
209213
│ │ ├── parser.py # Job definition parsing
210214
│ │ ├── detector.py # Platform detection
211-
│ │ └── generator.py # Skill file generation
215+
│ │ ├── generator.py # Skill file generation
216+
│ │ ├── policy_parser.py # Policy parsing (v1 and v2)
217+
│ │ ├── pattern_matcher.py # Variable pattern matching
218+
│ │ ├── policy_queue.py # Policy state queue
219+
│ │ └── command_executor.py # Command action execution
212220
│ ├── hooks/ # Cross-platform hook wrappers
213221
│ │ ├── wrapper.py # Input/output normalization
214-
│ │ ├── claude_hook.sh # Claude Code adapter
215-
│ │ └── gemini_hook.sh # Gemini CLI adapter
222+
│ │ ├── policy_check.py # Policy evaluation hook (v2)
223+
│ │ ├── claude_hook.sh # Claude Code adapter
224+
│ │ └── gemini_hook.sh # Gemini CLI adapter
216225
│ ├── templates/ # Jinja2 templates
217226
│ │ ├── claude/ # Claude Code templates
218227
│ │ └── gemini/ # Gemini CLI templates
@@ -243,15 +252,31 @@ Maintain a clean repository with automatic branch management and isolation.
243252
### 🛡️ Automated Policies
244253
Enforce project standards and best practices without manual oversight. Policies monitor file changes and automatically prompt your AI assistant to follow specific guidelines when relevant code is modified.
245254
- **Automatic Triggers**: Detect when specific files or directories are changed to fire relevant policies.
255+
- **File Correspondence**: Define bidirectional (set) or directional (pair) relationships between files.
256+
- **Command Actions**: Run idempotent commands (formatters, linters) automatically when files change.
246257
- **Contextual Guidance**: Instructions are injected directly into the AI's workflow at the right moment.
247-
- **Common Use Cases**: Keep documentation in sync, enforce security reviews, or automate changelog updates.
248258

249-
**Example Policy**:
250-
```yaml
251-
# Enforce documentation updates when config changes
252-
- name: "Update docs on config changes"
253-
trigger: "app/config/**/*"
254-
instructions: "Configuration files changed. Please update docs/install_guide.md."
259+
**Example Policy** (`.deepwork/policies/source-test-pairing.md`):
260+
```markdown
261+
---
262+
name: Source/Test Pairing
263+
set:
264+
- src/{path}.py
265+
- tests/{path}_test.py
266+
---
267+
When source files change, corresponding test files should also change.
268+
Please create or update tests for the modified source files.
269+
```
270+
271+
**Example Command Policy** (`.deepwork/policies/format-python.md`):
272+
```markdown
273+
---
274+
name: Format Python
275+
trigger: "**/*.py"
276+
action:
277+
command: "ruff format {file}"
278+
run_for: each_match
279+
---
255280
```
256281

257282
### 🚀 Multi-Platform Support

doc/architecture.md

Lines changed: 128 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,11 @@ deepwork/ # DeepWork tool repository
4646
│ │ ├── detector.py # AI platform detection
4747
│ │ ├── generator.py # Command file generation
4848
│ │ ├── parser.py # Job definition parsing
49-
│ │ ├── policy_parser.py # Policy definition parsing
50-
│ │ └── hooks_syncer.py # Hook syncing to platforms
49+
│ │ ├── policy_parser.py # Policy definition parsing (v1 and v2)
50+
│ │ ├── pattern_matcher.py # Variable pattern matching for policies
51+
│ │ ├── policy_queue.py # Policy state queue system
52+
│ │ ├── command_executor.py # Command action execution
53+
│ │ └── hooks_syncer.py # Hook syncing to platforms
5154
│ ├── hooks/ # Hook system and cross-platform wrappers
5255
│ │ ├── __init__.py
5356
│ │ ├── wrapper.py # Cross-platform input/output normalization
@@ -286,7 +289,13 @@ my-project/ # User's project (target)
286289
│ └── ...
287290
├── .deepwork/ # DeepWork configuration
288291
│ ├── config.yml # Platform config
289-
│ ├── .gitignore # Ignores .last_work_tree
292+
│ ├── .gitignore # Ignores tmp/ directory
293+
│ ├── policies/ # Policy definitions (v2 format)
294+
│ │ ├── source-test-pairing.md
295+
│ │ ├── format-python.md
296+
│ │ └── api-docs.md
297+
│ ├── tmp/ # Temporary state (gitignored)
298+
│ │ └── policy/queue/ # Policy evaluation queue
290299
│ └── jobs/ # Job definitions
291300
│ ├── deepwork_jobs/ # Core job for managing jobs
292301
│ │ ├── job.yml
@@ -305,7 +314,7 @@ my-project/ # User's project (target)
305314
│ │ └── steps/
306315
│ └── ad_campaign/
307316
│ └── ...
308-
├── .deepwork.policy.yml # Policy definitions (project root)
317+
├── .deepwork.policy.yml # Legacy policy definitions (v1 format)
309318
├── (rest of user's project files)
310319
└── README.md
311320
```
@@ -1000,74 +1009,151 @@ Policies are automated enforcement rules that trigger based on file changes duri
10001009
- Documentation stays in sync with code changes
10011010
- Security reviews happen when sensitive code is modified
10021011
- Team guidelines are followed automatically
1012+
- File correspondences are maintained (e.g., source/test pairing)
10031013

1004-
### Policy Configuration File
1014+
### Policy System v2 (Frontmatter Markdown)
10051015

1006-
Policies are defined in `.deepwork.policy.yml` at the project root:
1016+
Policies are defined as individual markdown files in `.deepwork/policies/`:
10071017

1018+
```
1019+
.deepwork/policies/
1020+
├── source-test-pairing.md
1021+
├── format-python.md
1022+
└── api-docs.md
1023+
```
1024+
1025+
Each policy file uses YAML frontmatter with a markdown body for instructions:
1026+
1027+
```markdown
1028+
---
1029+
name: Source/Test Pairing
1030+
set:
1031+
- src/{path}.py
1032+
- tests/{path}_test.py
1033+
---
1034+
When source files change, corresponding test files should also change.
1035+
Please create or update tests for the modified source files.
1036+
```
1037+
1038+
### Detection Modes
1039+
1040+
Policies support three detection modes:
1041+
1042+
**1. Trigger/Safety (default)** - Fire when trigger matches but safety doesn't:
10081043
```yaml
1009-
- name: "Update install guide on config changes"
1010-
trigger: "app/config/**/*"
1011-
safety: "docs/install_guide.md"
1012-
instructions: |
1013-
Configuration files have been modified. Please review docs/install_guide.md
1014-
and update it if any installation instructions need to change.
1015-
1016-
- name: "Security review for auth changes"
1017-
trigger:
1018-
- "src/auth/**/*"
1019-
- "src/security/**/*"
1020-
safety:
1021-
- "SECURITY.md"
1022-
- "docs/security_audit.md"
1023-
instructions: |
1024-
Authentication or security code has been changed. Please:
1025-
1. Check for hardcoded credentials
1026-
2. Verify input validation
1027-
3. Review access control logic
1044+
---
1045+
name: Update install guide
1046+
trigger: "app/config/**/*"
1047+
safety: "docs/install_guide.md"
1048+
---
1049+
```
1050+
1051+
**2. Set (bidirectional)** - Enforce file correspondence in both directions:
1052+
```yaml
1053+
---
1054+
name: Source/Test Pairing
1055+
set:
1056+
- src/{path}.py
1057+
- tests/{path}_test.py
1058+
---
1059+
```
1060+
Uses variable patterns like `{path}` (multi-segment) and `{name}` (single-segment) for matching.
1061+
1062+
**3. Pair (directional)** - Trigger requires corresponding files, but not vice versa:
1063+
```yaml
1064+
---
1065+
name: API Documentation
1066+
pair:
1067+
trigger: src/api/{name}.py
1068+
expects: docs/api/{name}.md
1069+
---
1070+
```
1071+
1072+
### Action Types
1073+
1074+
**1. Prompt (default)** - Show instructions to the agent:
1075+
```yaml
1076+
---
1077+
name: Security Review
1078+
trigger: "src/auth/**/*"
1079+
---
1080+
Please check for hardcoded credentials and validate input.
1081+
```
1082+
1083+
**2. Command** - Run an idempotent command:
1084+
```yaml
1085+
---
1086+
name: Format Python
1087+
trigger: "**/*.py"
1088+
action:
1089+
command: "ruff format {file}"
1090+
run_for: each_match # or "all_matches"
1091+
---
10281092
```
10291093

10301094
### Policy Evaluation Flow
10311095

10321096
1. **Session Start**: When a Claude Code session begins, the baseline git state is captured
10331097
2. **Agent Works**: The AI agent performs tasks, potentially modifying files
1034-
3. **Session Stop**: When the agent finishes:
1035-
- Changed files are detected by comparing against the baseline
1036-
- Each policy is evaluated:
1037-
- If any changed file matches a `trigger` pattern AND
1038-
- No changed file matches a `safety` pattern AND
1039-
- The agent hasn't marked it with a `<promise>` tag
1040-
- → The policy fires
1041-
- If policies fire, Claude is prompted to address them
1098+
3. **Session Stop**: When the agent finishes (after_agent event):
1099+
- Changed files are detected based on `compare_to` setting (base, default_tip, or prompt)
1100+
- Each policy is evaluated based on its detection mode
1101+
- Queue entries are created in `.deepwork/tmp/policy/queue/` for deduplication
1102+
- For command actions: commands are executed, results tracked
1103+
- For prompt actions: if policy fires and not already promised, agent is prompted
10421104
4. **Promise Tags**: Agents can mark policies as addressed by including `<promise>✓ Policy Name</promise>` in their response
10431105

1106+
### Queue System
1107+
1108+
Policy state is tracked in `.deepwork/tmp/policy/queue/` with files named `{hash}.{status}.json`:
1109+
- `queued` - Detected, awaiting evaluation
1110+
- `passed` - Policy satisfied (promise found or command succeeded)
1111+
- `failed` - Policy not satisfied
1112+
- `skipped` - Safety pattern matched
1113+
1114+
This prevents re-prompting for the same policy violation within a session.
1115+
10441116
### Hook Integration
10451117

1046-
Policies are implemented using Claude Code's hooks system. The `deepwork_policy` standard job includes:
1118+
The v2 policy system uses the cross-platform hook wrapper:
10471119

10481120
```
1049-
.deepwork/jobs/deepwork_policy/hooks/
1050-
├── global_hooks.yml # Maps lifecycle events to scripts
1051-
├── user_prompt_submit.sh # Captures baseline at each prompt
1052-
├── capture_prompt_work_tree.sh # Creates git state snapshot for compare_to: prompt
1053-
└── policy_stop_hook.sh # Evaluates policies on stop (calls Python evaluator)
1121+
src/deepwork/hooks/
1122+
├── wrapper.py # Cross-platform input/output normalization
1123+
├── policy_check.py # Policy evaluation hook (v2)
1124+
├── claude_hook.sh # Claude Code shell wrapper
1125+
└── gemini_hook.sh # Gemini CLI shell wrapper
1126+
```
1127+
1128+
Hooks are called via the shell wrappers:
1129+
```bash
1130+
claude_hook.sh deepwork.hooks.policy_check
10541131
```
10551132

10561133
The hooks are installed to `.claude/settings.json` during `deepwork sync`:
10571134

10581135
```json
10591136
{
10601137
"hooks": {
1061-
"UserPromptSubmit": [
1062-
{"matcher": "", "hooks": [{"type": "command", "command": ".deepwork/jobs/deepwork_policy/hooks/user_prompt_submit.sh"}]}
1063-
],
10641138
"Stop": [
10651139
{"matcher": "", "hooks": [{"type": "command", "command": ".deepwork/jobs/deepwork_policy/hooks/policy_stop_hook.sh"}]}
10661140
]
10671141
}
10681142
}
10691143
```
10701144

1145+
### Legacy v1 Format
1146+
1147+
The v1 format (`.deepwork.policy.yml`) is still supported for backward compatibility:
1148+
1149+
```yaml
1150+
- name: "Update install guide"
1151+
trigger: "app/config/**/*"
1152+
safety: "docs/install_guide.md"
1153+
instructions: |
1154+
Configuration files have been modified. Please review docs/install_guide.md.
1155+
```
1156+
10711157
### Cross-Platform Hook Wrapper System
10721158
10731159
The `hooks/` module provides a wrapper system that allows writing hooks once in Python and running them on multiple platforms. This normalizes the differences between Claude Code and Gemini CLI hook systems.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "deepwork"
3-
version = "0.3.0"
3+
version = "0.4.0"
44
description = "Framework for enabling AI agents to perform complex, multi-step work tasks"
55
readme = "README.md"
66
requires-python = ">=3.11"

0 commit comments

Comments
 (0)