Skip to content

Conversation

@nhorton
Copy link
Contributor

@nhorton nhorton commented Jan 16, 2026

Design docs for next-generation policy system with:

  • File correspondence matching (sets and pairs)
  • Idempotent command execution
  • Queue-based state tracking with detector/evaluator pattern
  • Folder-based policy storage using frontmatter markdown files

Key changes from current system:

  • Policies move from single .deepwork.policy.yml to .deepwork/policies/*.md
  • YAML frontmatter for config, markdown body for instructions
  • New 'set' syntax for bidirectional file relationships
  • New 'pair' syntax for directional file relationships
  • New 'action' field for running commands instead of prompts
  • Queue system prevents duplicate policy triggers across sessions

Design docs for next-generation policy system with:
- File correspondence matching (sets and pairs)
- Idempotent command execution
- Queue-based state tracking with detector/evaluator pattern
- Folder-based policy storage using frontmatter markdown files

Key changes from current system:
- Policies move from single .deepwork.policy.yml to .deepwork/policies/*.md
- YAML frontmatter for config, markdown body for instructions
- New 'set' syntax for bidirectional file relationships
- New 'pair' syntax for directional file relationships
- New 'action' field for running commands instead of prompts
- Queue system prevents duplicate policy triggers across sessions
nhorton and others added 10 commits January 16, 2026 11:26
Key changes:
- Restructure taxonomy: detection modes (trigger/safety, set, pair) + action types (prompt, command)
- Add required `name` field for human-friendly promise tag display (e.g., "✓ Source/Test Pairing")
- Remove priority and defer features (not needed yet)
- Clarify .deepwork/tmp is gitignored, so cleanup is not critical
- Shorten output format - group by policy name, use simple arrow notation for correspondence
- Update all examples to include name field
- Don't enforce idempotency, just document it as expected behavior
- Give lint formatters (black, ruff, prettier) as good examples
- Remove output_mode from config (not referenced elsewhere)
- Remove idempotency verification test scenarios
This implements the redesigned policy system with:

- Detection modes: trigger/safety (default), set (bidirectional), pair (directional)
- Action types: prompt (show instructions), command (run idempotent command)
- Variable pattern matching: {path} for multi-segment, {name} for single-segment
- Queue system in .deepwork/tmp/policy/queue/ for state tracking
- Frontmatter markdown format for policy files in .deepwork/policies/

New core modules:
- pattern_matcher.py: Variable pattern matching with regex
- policy_queue.py: Queue system for policy state persistence
- command_executor.py: Command action execution with substitution

Updates to existing modules:
- policy_parser.py: v2 Policy class with detection modes and action types
- policy_check.py: Uses new v2 system with queue deduplication
- evaluate_policies.py: Updated for v1 backward compatibility
- policy_schema.py: New frontmatter schema for v2 format

Tests updated to work with both v1 and v2 APIs.
- 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
The hook now:
- Checks for v2 policies in .deepwork/policies/ first
- Falls back to v1 policies in .deepwork.policy.yml if no v2 found
- Passes JSON input directly to policy_check.py for v2 (via wrapper)
- Maintains existing behavior for v1 evaluate_policies.py
Remove all legacy v1 policy format (.deepwork.policy.yml) support:

- Remove evaluate_policies.py hook module
- Remove PolicyV1 class and parse_policy_file from policy_parser.py
- Remove v1 schema (POLICY_SCHEMA_V1) from policy_schema.py
- Remove v1 test fixtures and test_evaluate_policies.py
- Update test fixtures to use v2 frontmatter markdown format
- Update documentation to remove v1 references
- Fix policy_stop_hook.sh to handle exit code 2 (block) correctly

Only v2 frontmatter markdown format (.deepwork/policies/*.md) is now supported.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants