The DeepSchema system provides rich, file-level schemas with automatic validation on writes and synthetic review rule generation.
- The system MUST support two schema types: named and anonymous.
- Named schemas MUST be directories containing a
deepschema.ymlmanifest, located under a schema folder. - Anonymous schemas MUST be single files named
.deepschema.<filename>.yml, placed alongside the target file.
- The
deepschema.ymlmanifest MUST support the following fields:summary,instructions,matchers,requirements,parent_deep_schemas,json_schema_path,verification_bash_command,examples,references. - All fields MUST be optional — an empty schema is valid.
- The manifest MUST be validated against the DeepSchema JSON Schema (
deepschema_schema.json). - The
requirementsfield MUST be a mapping of requirement names to RFC 2119 requirement descriptions. - The
matchersfield MUST be an array of glob patterns. - The
json_schema_pathfield MUST be a relative path from the schema directory to a JSON Schema file. - The
verification_bash_commandfield MUST be an array of shell command strings. - The
parent_deep_schemasfield MUST be an array of named schema names to inherit from.
- Named schemas MUST be discovered from multiple directories in priority order: project-local (
.deepwork/schemas/), standard (standard_schemas/), andDEEPWORK_ADDITIONAL_SCHEMAS_FOLDERSenv var (colon-delimited). - If the same schema name appears in multiple sources, the first source MUST win.
- Each source directory MUST be scanned for subdirectories containing
deepschema.yml.
- Anonymous schemas MUST be found by walking the project tree for files matching
.deepschema.<filename>.yml. - Standard skip directories (
.git,node_modules,__pycache__,.venv, etc.) MUST be excluded from the walk.
- When a schema lists
parent_deep_schemas, the resolver MUST merge parent requirements into the child. - Child requirements MUST override parent requirements with the same key.
- If a child has no
json_schema_path, it MUST inherit the parent's. verification_bash_commandentries from parents MUST be appended to the child's list.- Circular references in
parent_deep_schemasMUST be detected and reported as errors.
- A file MUST match a named schema if any of the schema's
matchersglob patterns match the file's project-relative path. - A file MUST match an anonymous schema if a
.deepschema.<filename>.ymlfile exists alongside it. - The
get_schemas_for_file_fast()function MUST avoid full tree walks by only scanning named schema folders and checking for the anonymous schema file at O(1).
- The write hook MUST fire on PostToolUse events for Write and Edit tools.
- For each applicable schema, the hook MUST inject a conformance note: "Note: this file must conform to the DeepSchema at
<path>". - If
json_schema_pathis set, the hook MUST validate the written file against the JSON Schema. The file content MUST be parsed as YAML (which is a superset of JSON), so both YAML and JSON formats are accepted regardless of file extension. - If
verification_bash_commandis set, the hook MUST execute each command with the file path as$1, with a 30-second timeout. - Validation failures MUST be reported via
hookSpecificOutput.additionalContextso the agent can act on them. - The hook MUST NOT use
systemMessagefor validation output — that route is user-visible only.
- Each discovered schema with requirements MUST generate a synthetic
ReviewRule. - Review rule names MUST follow the pattern
"<name> DeepSchema Compliance". - Named schema reviews MUST include the schema's summary, instructions, and requirements in the review prompt.
- Anonymous schema reviews MUST include only the requirements.
- All generated reviews MUST use the
"individual"strategy (one file at a time). - Generated reviews MUST be included in both
/reviewruns and workflow quality gate checks. - Review instructions MUST specify RFC 2119 severity logic: fail any violation of a MUST requirement, fail any SHOULD requirement that could easily be followed but is not, give feedback without failing on other applicable items, and ignore requirements that are not applicable.
- The
get_named_schemasMCP tool MUST return all discovered named schemas. - Each entry MUST include
name,summary, andmatchersfields. - Schemas that fail to parse MUST still appear in the results with an error summary instead of a real summary.
- Each requirement in the
requirementsfield MUST be verifiable by examining files on the filesystem. - Requirements about processes, user behavior, or context not present in files SHOULD be placed in the
instructionssection instead. - Requirements MUST NOT restate constraints that are already enforced by the schema's
json_schema_pathorverification_bash_command, including syntactic validity (e.g., "must be valid JSON"), field types, allowed enum values, required fields, and structural shape. - Requirements SHOULD focus on semantic rules, behavioral gotchas, and cross-field concerns that JSON Schema cannot express.
- The DeepSchema review bridge MUST populate the generated
ReviewRule.reference_fileswith the schema'sreferencesentries and thejson_schema_pathfile (when set), so reviewers receive their contents inlined in the review instructions. - Each referenced path MUST be resolved relative to the schema file's directory.
- The schema's
examplesentries MUST NOT be inlined as reference files. Instead, the bridge MUST list them in the rule's review instruction text with theirpathanddescriptionso reviewers know the example material exists and can fetch it on demand. - The order of inlined reference files MUST be deterministic across runs for a given schema.
- When a referenced file cannot be located on disk, the bridge MUST skip it and surface an error through the
errorsreturn ofgenerate_review_rules. A missing reference file MUST NOT prevent the rule from being generated. - Reference entries whose
pathbegins withhttp://orhttps://MUST be skipped without producing an error, since they are informational pointers rather than local files.