| name | deft-directive-sync |
| description | Session-start framework sync skill. Pulls latest deft submodule, validates xBRIEF lifecycle structure, checks folder/status consistency, detects stale origins (RFC D12), and summarizes changes. |
| triggers | ["good morning","update deft","update xbrief","sync frameworks"] |
Deft Directive Sync
Session-start framework sync -- pull latest deft submodule updates, validate xBRIEF lifecycle structure, and detect stale origins.
Canonical bootstrap / update path (#761 npm cutover): Install and upgrade via npm: npm i -g @deftai/directive (install) or npm i -g @deftai/directive@latest (upgrade); Node >= 20 is required. For machines without Node, the frozen legacy Go installer (deft-install / platform-specific install-* from GitHub Releases) is a no-Node bootstrap bridge (#1912) -- migrate to npm once Node is available. After a session start the canonical scripts/doctor.py --session --json (deft doctor / task doctor) reports install + payload state and, when the manifest sha shows the payload is stale, recommends npm i -g @deftai/directive@latest. Legacy run upgrade / task upgrade are metadata-only acknowledgment (they do NOT replace the payload), and git-submodule / task framework:doctor paths are back-compat only -- the submodule sync in Phases 1-2 below is the legacy update flow, de-emphasized in UPGRADING.md / README. See UPGRADING.md and #761 / #1912.
Legend (from RFC2119): !=MUST, ~=SHOULD, ≉=SHOULD NOT, ⊗=MUST NOT, ?=MAY.
Platform Requirements
! This skill requires GitHub as the SCM platform and the GitHub CLI (gh) to be installed and authenticated. Origin freshness checks (Phase 5) fetch issue data via gh issue view.
When to Use
- User says "good morning", "update deft", "update xbrief", or "sync frameworks"
- Beginning of a new session where framework updates may be available
- After a known upstream deft release
Session orientation — unmanaged header (#2065)
! The region of AGENTS.md above the <!-- deft:managed-section ... --> marker is project-owned, preserved verbatim on refresh, and not freshness-checked by deft doctor.
- ! Do NOT treat that unmanaged header as the work queue — consult
deft triage:queue, xbrief/ lifecycle, GitHub issues, and PROJECT-DEFINITION.xbrief.json instead (#1149, #2065 Option A).
- ⊗ Do NOT add or revive
Status, Next:, or Known Issues blocks in AGENTS.md — they duplicate authoritative sources and rot silently while the managed section stays current.
Framework Events Emitted Here
! When this skill responds to a context-window shift or an explicit "are you using Deft?" probe (per AGENTS.md Deft Alignment Confirmation), emit the paired session:interrupted -> session:resumed framework events via scripts/_events.py so observability of agent-runtime state transitions is structural, not prose-only:
- ! Before re-confirming alignment:
python -m scripts._events emit session:interrupted --session-id <id> --reason context-window-shift
- ! Immediately after the alignment confirmation line:
python -m scripts._events emit session:resumed --session-id <id> --interrupted-id <id-from-prior-emit>
- ⊗ Emit a
session:resumed whose interrupted_id does not reference a prior session:interrupted -- such records are orphan and rejected by scripts._events.validate_pairing (#635 events behavioral wiring)
Pre-Cutover Detection Guard
! Before proceeding with sync, detect whether the project uses the pre-v0.20 document model and report model state.
Detection Criteria
A project is pre-cutover if ANY of the following are true. This prose mirrors the executable helper in scripts/_precutover.py; when in doubt, the helper is canonical.
SPECIFICATION.md exists and is neither a deprecation redirect nor a current generated spec export. A current generated spec export contains <!-- Purpose: rendered specification --> and <!-- Source of truth: xbrief/specification.xbrief.json -->, and xbrief/specification.xbrief.json plus all five lifecycle folders exist.
PROJECT.md exists and contains neither the legacy <!-- deft:deprecated-redirect --> sentinel NOR the current Purpose: deprecation redirect canonical-banner marker (real content, not a deprecation redirect)
xbrief/specification.xbrief.json exists but the lifecycle folders (xbrief/proposed/, xbrief/pending/, xbrief/active/, xbrief/completed/, xbrief/cancelled/) do NOT exist
Action on Detection
! If pre-cutover state is detected, display the actionable migration message, then skip Phases 1-6 and proceed directly to Phase 7 with the Document Model line set to "pre-v0.20 (legacy)":
"This project uses the pre-v0.20 document model. Current npm releases no longer ship in-product task migrate:vbrief (#2068). Follow UPGRADING.md § Frozen pre-v0.20 document-model migration: pin framework v0.59.0, install Python 3.11+ and uv, run task migrate:vbrief once from that payload, then upgrade to current npm."
! Include specific details about what was detected:
- Missing lifecycle folders: "Create lifecycle folders via the frozen v0.59.0 migrator (#2068), or manually add
xbrief/{proposed,pending,active,completed,cancelled}/ after migrating narratives"
SPECIFICATION.md with real content: "SPECIFICATION.md contains non-redirect content -- this file is deprecated; use scope xBRIEFs in xbrief/ instead"
PROJECT.md with real content: "PROJECT.md contains non-redirect content -- this file is deprecated; use PROJECT-DEFINITION.xbrief.json instead"
- Missing
PROJECT-DEFINITION.xbrief.json: "Run task project:render to generate the project definition"
- Scope xBRIEF in wrong folder: "Status is '{status}' but file is in {folder}/ -- run
task scope:activate <file> to fix"
Model State in Sync Output
! Include a Document Model line in the Phase 7 summary:
- Pre-cutover detected: "Document Model: pre-v0.20 (legacy) -- follow UPGRADING.md § Frozen pre-v0.20 document-model migration (#2068)"
- Post-cutover (lifecycle folders present, no stale artifacts): "Document Model: v0.20+ (xBRIEF-centric) -- OK"
- Post-cutover with tampered placeholders: "Document Model: v0.20+ with warnings -- SPECIFICATION.md or PROJECT.md contains non-redirect content"
⊗ Skip model state detection during sync -- always report the document model state.
⊗ Silently ignore pre-cutover artifacts -- the user must be informed with an actionable command to fix the state.
Phase 1 -- Pre-flight
! Check that the deft/ submodule working tree is clean before attempting any update.
- ! Run
git -C deft status --porcelain
- ! If output is non-empty (dirty working tree): stop and ask user whether to stash (
git -C deft stash) or abort the sync entirely. Do NOT proceed with a dirty submodule.
- ! Record the current DEFT commit for later comparison:
git -C deft log --oneline -1
- ! Present the current state to the user:
- Current DEFT commit (hash + subject)
- Clean/dirty status
- Confirmation that pre-flight passed (or the blocker if dirty)
Phase 2 -- Update DEFT Submodule
- ! Run the submodule update:
git submodule update --remote --merge deft
- ! Show what changed by comparing before/after:
git -C deft log --oneline <old-hash>..HEAD
- ~ If no new commits, report "deft submodule already up to date" and proceed to Phase 3.
Phase 3 -- Structure Validation
! Validate the xBRIEF lifecycle folder structure and project files.
3a: Lifecycle Folder Structure
! Verify all required lifecycle folders exist:
- ! Check that the following directories exist under
./xbrief/:
proposed/
pending/
active/
completed/
cancelled/
- ! Report any missing folders with a clear warning:
- "WARNING: xbrief/{folder}/ does not exist -- lifecycle structure is incomplete"
- ~ If folders are missing, suggest
task migrate:preflight and the frozen v0.59.0 migrator path (#2068), or creating them manually after migration
3b: PROJECT-DEFINITION.xbrief.json Validation
! Validate the project identity gestalt file:
- ! Check that
./xbrief/PROJECT-DEFINITION.xbrief.json exists
- If missing: "WARNING: PROJECT-DEFINITION.xbrief.json not found -- run
task project:render to create"
- ! If the file exists, validate it is well-formed:
- Valid JSON (
python3 -m json.tool or equivalent)
- Top-level
xBRIEFInfo envelope with version field equal to "0.6"
plan object with title, status, and items fields present
plan.narratives values are plain strings (not objects or arrays)
- ! Freshness check: Compare
xBRIEFInfo.updated (or xBRIEFInfo.created if no updated) against recent scope completions:
- Scan
xbrief/completed/ for xBRIEFs with xBRIEFInfo.updated timestamps newer than the PROJECT-DEFINITION timestamp
- If stale: "WARNING: PROJECT-DEFINITION.xbrief.json may be stale -- {N} scopes completed since last update. Run
task project:render to refresh."
3c: Validate Root-Level xBRIEF Files
! Validate all ./xbrief/*.xbrief.json files at the xbrief root:
- ! Check each file is valid JSON
- ! Verify structural conformance:
- Top-level
xBRIEFInfo envelope with version field present
plan object with title, status, and items fields present
plan.status values from valid enum: draft, proposed, approved, pending, running, completed, blocked, cancelled
- ~ Use
task xbrief:validate if available for deeper validation
- ! Report any validation failures with file name and specific violation
⊗ Overwrite or modify project-level ./xbrief/*.xbrief.json files -- those are project data, not framework files. Report issues and let the user decide how to fix them.
Phase 4 -- Lifecycle Consistency Check
! Verify that each scope xBRIEF's plan.status matches its folder location.
- ! Scan all scope xBRIEFs in lifecycle folders (
proposed/, pending/, active/, completed/, cancelled/)
- ! For each xBRIEF, check
plan.status against the expected statuses for its folder:
proposed/: status should be draft or proposed
pending/: status should be approved or pending
active/: status should be running or blocked
completed/: status should be completed
cancelled/: status should be cancelled
- ! Report any mismatches:
- "MISMATCH: {filename} in {folder}/ has status '{status}' -- expected one of [{expected_statuses}]"
- ~ Per
vbrief/vbrief.md convention, trust the status field and suggest correcting the folder location:
- "Suggested fix: move {filename} to {correct_folder}/ (status '{status}' is authoritative)"
⊗ Auto-move xBRIEFs to fix folder/status mismatches -- report only; user decides during refinement or ad-hoc
Phase 5 -- Origin Freshness (RFC D12)
! For xBRIEFs with external origin references, detect staleness and externally-closed origins.
Step 1: Scan Origins
- ! For each xBRIEF in
proposed/ and pending/ with a github-issue reference in plan.references or top-level references:
- Extract the issue number from the reference URL or
id field
- Fetch the issue:
gh issue view {N} --repo {owner/repo} --json updatedAt,state
- ! Compare the issue's
updatedAt against the xBRIEF's xBRIEFInfo.updated (or xBRIEFInfo.created if no updated field)
Step 2: Categorize and Report
- ! Stale origins -- issue
updatedAt is newer than xBRIEF updated timestamp:
- "{N} xBRIEFs have origins updated since last sync"
- List each: "{filename}: Issue #{N} updated {time_delta} ago"
- ! Externally closed origins -- issue state is
CLOSED:
- "{N} xBRIEFs have origins that were closed externally"
- List each: "{filename}: Issue #{N} is closed ({close_reason})"
- ~ Current origins -- no changes detected (report count only)
Step 3: Recommendation
- ! Report only -- never auto-update xBRIEFs based on origin changes
- ~ If stale or externally-closed xBRIEFs are found, suggest: "Run a refinement session (
skills/deft-directive-refinement/SKILL.md) to reconcile stale origins with user approval."
⊗ Auto-update xBRIEFs based on origin freshness checks -- report only; user decides during refinement
Phase 6 -- Framework Sync
After structure validation, sync framework-level assets.
6a: Check AGENTS.md freshness
~ Compare the project's AGENTS.md against the deft template (if a template exists in the updated deft/ submodule):
- ~ Diff the structure (section headings, key rules) rather than expecting byte-identical content
- ~ Report any new sections or rules added upstream that are missing locally
- ~ Do NOT auto-overwrite -- present differences and let the user decide
- ~ If the unmanaged header still carries
Status, Next:, or Known Issues, recommend replacing them with the Session orientation pointer at xbrief/ + triage + issues (#2065 Option A) -- do NOT treat that header prose as the work queue
6b: Check codebase MAP freshness
~ If ./.planning/codebase/MAP.md exists, or PROJECT-DEFINITION.xbrief.json declares a projectionManifest[] entry with kind: "codebase-map", run task verify:codebase-map-fresh when the command resolves. If it reports drift, recommend task codebase:map and note that the generated MAP is advisory unless the operator asked to refresh projections.
- ! Keep
plan.architecture.codeStructure and configured provider artifacts authoritative; the MAP is a generated projection.
- ⊗ Auto-edit canonical xBRIEF metadata to make the MAP fresh during sync -- report drift and let the operator choose a follow-up.
6c: List new skills
! Compare the skills/ directory before and after the update:
- ! List any new skill directories added in the update
- ~ For each new skill, read its frontmatter
description field and present a one-liner
- ~ Mention if any existing skills were updated (changed files)
Phase 6d -- Legacy Artifact Review (post-migration, one-time)
! If xbrief/migration/LEGACY-REPORT.md exists (and has NOT been renamed to LEGACY-REPORT.reviewed.md), walk the operator through each captured legacy section and record their disposition inline in the same file. This phase surfaces the non-canonical content that task migrate:xbrief preserved via the LegacyArtifacts narrative mechanism (#505).
Detection
- ! Check for
xbrief/migration/LEGACY-REPORT.md in the project root.
- ! If the file is absent or
LEGACY-REPORT.reviewed.md exists (reviewed form), skip Phase 6d silently and proceed to Phase 7.
- ! If
LEGACY-REPORT.md is present and has NOT been renamed, begin the review loop below.
Review loop
- ! Present the report summary (sources + per-bucket section counts) to the user.
- ! For each captured section listed under
## specification.xbrief.json -> LegacyArtifacts, ## PROJECT-DEFINITION.xbrief.json -> LegacyArtifacts, and ## PRD.md content (flagged: hand-edited):
- Restate the section title, source file + line range, and size.
- Offer exactly three disposition options: Keep (leave inside
LegacyArtifacts), Fold into {suggested narrative} (move into a canonical narrative key), or Drop (remove from LegacyArtifacts, with explicit user confirmation).
- ~ If a sidecar pointer is present (
xbrief/legacy/{stem}-{slug}.md), open the sidecar for the user before offering options so the full content is visible.
- ! Record each disposition inline in the same
LEGACY-REPORT.md file under a new ## Reviewed section with one entry per legacy item: original section, user's decision, target location (if folded) or confirmation note (if kept/dropped), and the reviewer's timestamp.
- ! For a Fold decision, the agent updates the target xBRIEF's narrative key AND deletes only the corresponding section from the
LegacyArtifacts narrative -- never the file.
- ! For a Drop decision, the agent removes only the corresponding section from the
LegacyArtifacts narrative.
- ! Once all sections carry a recorded disposition, rename the file to
LEGACY-REPORT.reviewed.md. The file is kept so the audit trail remains -- ⊗ MUST NOT delete either form.
Anti-patterns
- ⊗ Delete
LEGACY-REPORT.md or LEGACY-REPORT.reviewed.md -- these are the migration audit trail and MUST persist.
- ⊗ Auto-dispose of legacy artifacts without user input -- every section requires an explicit decision.
- ⊗ Rename to
.reviewed.md before every captured section has a recorded disposition in the ## Reviewed section.
- ⊗ Drop a legacy section without explicit user confirmation (even if the section looks obviously stale).
- ⊗ Silently delete sidecar files under
xbrief/legacy/ -- they are referenced from LegacyArtifacts and are part of the audit trail.
Phase 6e -- Doc-sprawl awareness (advisory, #647)
Doc sprawl is a project-health concern, not just a human-experience one: a lean, well-written AGENTS.md sitting on top of a large reachable doc corpus does not stop agents from discovering and loading those docs (Augment Code study, content/docs/good-agents-md.md). It degrades agent quality silently until measured. This step surfaces the risk; it is ADVISORY and MUST NOT block or fail the sync.
- ~ Scan the project's reachable documentation footprint: the top-level
docs/ / _docs/ directories, nested README.md files, and any architecture / design docs.
- ~ Flag, as a non-blocking nudge, when any of these appear:
- A large
docs/ (or _docs/) directory that is not referenced from the AGENTS.md reference chain (orphan docs are discovered <10% of the time yet still cost context when found -- the reference-chain contract, #644).
- Deeply nested READMEs that duplicate guidance the reference chain already carries.
- Architecture / design docs that restate what the codebase already shows (a measured overexploration trigger).
- ~ Point the operator at
content/docs/agent-docs.md (the empirically-grounded structure pattern) and the REFERENCES.md reference-chain contract for remediation. For directive's own always-loaded file, the verify:agents-md-budget ratchet (#645) and the consumer advisory (agentsMdAdvisory, #2155) are the size guards.
- ⊗ Do NOT convert this into a hard gate or auto-delete any doc -- the value is the nudge at the right moment; thresholds are a judgment call the operator owns.
Phase 7 -- Summary
! Present a consolidated summary to the user covering:
- DEFT version change: old commit -> new commit (or "already up to date")
- Structure validation: lifecycle folders status (all present / missing folders listed)
- PROJECT-DEFINITION status: valid / missing / stale (with freshness details)
- xBRIEF validation results: pass/fail per file, with details on any failures
- Lifecycle consistency: all consistent / N mismatches found (with details)
- Origin freshness: N stale / N externally-closed / N current (with details)
- Document Model: pre-v0.20 (legacy) / v0.20+ (xBRIEF-centric) OK / v0.20+ with warnings (see Pre-Cutover Detection Guard)
- AGENTS.md status: current / has upstream changes / needs review
- Codebase MAP status: current / stale / absent / not configured (advisory)
- New skills: list any newly added skills with descriptions
! Ask the user: "Shall I commit the submodule update?" -- do NOT auto-commit.
? If the user confirms, commit with message:
chore(deft): update deft submodule to <short-hash>
Anti-Patterns
- ⊗ Auto-commit submodule changes without user approval
- ⊗ Overwrite project-level
./xbrief/*.xbrief.json files -- those are project data
- ⊗ Skip the pre-flight dirty check -- a dirty submodule can cause merge conflicts or data loss
- ⊗ Include a separate fetch of the xBRIEF schema from upstream deftai/xBRIEF -- that is a CI concern (see #128), not a user sync task
- ⊗ Auto-move xBRIEFs to fix folder/status mismatches -- report only; never auto-fix
- ⊗ Auto-update xBRIEFs based on origin freshness -- report only; user decides during refinement