Skip to content

feat: doctrine stack, agent profiles, and mission template repository (specs 046-058)#348

Draft
stijn-dejongh wants to merge 22 commits intoPriivacy-ai:mainfrom
stijn-dejongh:feature/agent-profile-implementation-rebased
Draft

feat: doctrine stack, agent profiles, and mission template repository (specs 046-058)#348
stijn-dejongh wants to merge 22 commits intoPriivacy-ai:mainfrom
stijn-dejongh:feature/agent-profile-implementation-rebased

Conversation

@stijn-dejongh
Copy link
Copy Markdown
Collaborator

Summary

Supersedes #305 — rebased, exception-hardened, extended with mission 057+058.

  • Doctrine stack (src/doctrine/): 8 artifact types with consistent repository pattern, DoctrineService facade, Pydantic v2 frozen models, ArtifactKind StrEnum
  • Agent profiles (spec 048): DDR-011 weighted context matching, hierarchy traversal, cycle detection, CLI surfaces
  • Constitution bootstrap (spec 054): ConstitutionInterview, compile_constitution(), MissionStepContract domain model
  • Kernel package (spec 057): shared utilities, glossary type shims, init-time doctrine integration
  • MissionTemplateRepository (spec 058): sole authority for mission asset access via value objects (TemplateResult, ConfigResult), 5-tier resolver integration, ProjectPaths centralization
  • Feature→mission terminology rename (spec 058 WP08): cord-cut backward-compat shims and --feature flags
  • Architectural boundary tests: pytestarch-enforced kernel→doctrine→specify_cli layering

Changes since #305

  • All 21 bare except Exception handlers in src/doctrine/ narrowed to specific exception tuples (M1 from feat: doctrine artifact domain models, agent profiles, and constitution bootstrap (specs 046, 048, 054) #305 review)
  • C1 resolved: doctrine no longer imports specify_cli (glossary imports moved to kernel.*)
  • C2 resolved: CI coverage now includes --cov=src/doctrine across all test suites
  • M2-M4 resolved: module-level constants, resolution path logging, documented graceful degradation
  • All 5 architecture discrepancies from March 26 review addressed in architecture docs
  • Mission 057 (kernel + doctrine stack + profile infrastructure) fully integrated
  • Mission 058 (MissionTemplateRepository encapsulation + terminology rename) fully integrated

Test plan

  • pytest tests/doctrine/ --timeout=30 — 1110 passed
  • ruff check src/doctrine/ src/constitution/ — clean
  • grep -r "except Exception" src/doctrine/ --include="*.py" — zero results
  • pytest -m fast --timeout=30 — full fast suite passes

🤖 Generated with Claude Code

@stijn-dejongh
Copy link
Copy Markdown
Collaborator Author

PR #348 is the continuation of #305 after rebasing onto the newer main
architecture, so the right comparison is not "did we replay #305 verbatim?"
but "which #305 review concerns survive after aligning with main, and which
ones are now explicitly addressed?"

What from #305 is applied in #348

1. Architectural boundary correction

The most important actionable review item on #305 was the doctrine boundary:
doctrine should not depend on specify_cli.

That is now materially addressed in this branch:

  • src/kernel/ exists as the shared dependency floor for path, atomic-write,
    and glossary-boundary primitives.
  • doctrine-side shared/glossary primitives were lifted out of specify_cli and
    anchored in kernel.
  • specify_cli.runtime.home is now a compatibility shim over kernel.paths.
  • package boundary expectations are no longer just prose; they are codified in
    ADRs and enforced by architectural tests (tests/architectural/).

This is the main architectural improvement over #305: the doctrine work is no
longer landing into the old package arrangement, but into an explicitly layered
kernel <- doctrine <- constitution <- specify_cli model.

2. Constitution as pass-through / local router

The branch also moves closer to the intended constitution role as the
project-local router for governance concerns:

  • project-local mission path construction now flows through
    ProjectMissionPaths
  • doctrine-backed mission/template reads flow through
    MissionTemplateRepository
  • constitution-facing code composes those layers instead of having each
    consumer hand-build paths ad hoc

That is the important alignment point: constitution is becoming the local
indirection point for governance and doctrine-aware project state, not just a
document compiler.

3. Doctrine asset expansion and repository encapsulation

The PR still carries forward the core #305 and mission 058 asset work:

  • doctrine remains the home of the expanded artifact model
  • mission/template access is formalized through
    MissionTemplateRepository
  • the rebased branch keeps the doctrine asset migration while fitting it into
    main's newer runtime and shim architecture

This also preserves the March 26-27 review direction: doctrine owns the shipped
assets, while consumers stop reaching into package paths directly.

4. CI and verification improvements

The #305 concern that doctrine work was not properly exercised in CI is also
addressed materially here:

  • doctrine is included in coverage paths
  • kernel has its own CI test/coverage gate
  • architectural dependency checks run as a first-class CI surface
  • release/readiness flows were updated for the newer package layout

This is a meaningful improvement over #305 because the new package boundaries
are now tested rather than only argued for.

5. Mission type vs mission run split

The rename work is also more explicit in #348, and this is the practical
response to issue #241:

  • issue Rename --feature flag to --mission (with backward compatibility) #241 started as a proposed --feature--mission rename
  • that collided with the existing use of --mission for the workflow kind
  • the branch resolves that collision by splitting the concepts instead of
    forcing one overloaded flag
  • mission type now means the abstract workflow category and is selected via
    --mission-type
  • mission run now means the concrete execution instance and is selected via
    --mission-run

This is a useful clarification over older feature/mission overloading. It
keeps the taxonomy separate from a specific run instance, which matters in the
runtime, CLI, and documentation surfaces.

What from #305 is still relevant

Two architectural comments from #305 remain valid follow-on guidance rather
than "done in this PR":

  1. The compiler-backed mission-bundle follow-up is still relevant. The doctrine
    foundation is in place, but the longer-term goal of compiling structured
    mission sources into stable runtime bundles remains a separate step.
  2. The separation between shipped product-operation skills and mission-authoring
    doctrine still matters. Skills should help agents operate Spec Kitty
    correctly; they should not become a second authored source of mission
    behavior.

There is also still constitution-routing work left beyond the current mission
path centralization. Using constitution as the local governance router is the
right direction, but this PR does not claim that every constitution, global
runtime, or governance path is fully centralized yet.

Issue #241 is also not "fully done everywhere" yet. The conceptual split is the
right answer and large parts of the runtime/CLI now use it, but a number of
older compatibility surfaces and docs still retain --feature language during
the deprecation period.

Open tasks this PR does not pretend to close

  • expand constitution-led path centralization beyond ProjectMissionPaths
  • continue burning down residual exception-swallowing / graceful-degradation
    debt in constitution and adjacent surfaces
  • carry the compiler-backed mission composition follow-on
  • keep reducing remaining runtime/test debt that predates this rebase

Net assessment

#348 should be read as:

So the important #305 review comments were not ignored. The concrete ones were
applied in the rebased branch, and the longer-horizon ones remain explicitly
relevant follow-on architecture rather than hidden debt.

@stijn-dejongh stijn-dejongh force-pushed the feature/agent-profile-implementation-rebased branch 2 times, most recently from 6375aa8 to 9951989 Compare March 31, 2026 14:16
stijn-dejongh and others added 18 commits March 31, 2026 16:26
Add the kernel peer package — zero-dependency shared utilities used by
constitution, doctrine, and specify_cli.

Modules:
- kernel.paths: package asset root resolution and kittify home discovery
- kernel.atomic: atomic file write helper
- kernel.glossary_types: canonical glossary data types and enums
- kernel.glossary_runner: protocol for glossary-aware primitive runners

Part of mission 057 (doctrine stack and agent profile infrastructure).

Co-authored-by: Copilot <[email protected]>
Add the doctrine and constitution peer packages with full governance
infrastructure for agent-driven workflows.

Doctrine additions:
- agent_profiles/: agent profile definitions, repository, validation, and
  weighted matching (DDR-011)
- mission_step_contracts/: structured step contracts for mission workflows
- curation/: doctrine artifact curation pipeline
- Shipped YAML artifacts: directives, tactics, paradigms, styleguides,
  toolguides, procedures (~50 files)
- Schema definitions for all artifact types
- Updated skill references for git-workflow, mission-system, orchestrator-api,
  runtime-next, runtime-review, setup-doctor

Constitution package (new peer package):
- Compiler, extractor, generator for constitution documents
- Interview system for guided constitution creation
- Reference resolver with transitive doctrine resolution
- Schema validation (Pydantic models)
- Sync system for detecting stale governance artifacts
- Template resolver bridging to MissionTemplateRepository

Both packages depend on kernel (commit 1). Constitution additionally
depends on doctrine for artifact resolution and reference traversal.

Part of mission 057 (doctrine stack and agent profile infrastructure).

Co-authored-by: Copilot <[email protected]>
Add doctrine initialization during project setup and agent profile
suggestion infrastructure for work packages.

Init-time doctrine:
- _run_doctrine_stack_init(): interactive or default constitution setup
- _apply_doctrine_defaults(): generate constitution from shipped defaults
- _run_inline_interview(): guided interactive constitution creation
- _maybe_generate_structure_templates(): REPO_MAP.md and SURFACES.md

Profile infrastructure:
- task_profile.py: suggest agent profiles based on WP task types
  (ROLE_TO_PROFILE mapping, display helpers)
- m_2_2_0_profile_context_deployment.py: migration for profile context

Tests:
- test_init_doctrine.py: init-time doctrine integration tests
- test_profile_context_migration.py: migration tests
- test_task_profile_suggestion.py: profile suggestion tests

Part of mission 057 (WP07-WP09).

Co-authored-by: Copilot <[email protected]>
Resolves the namespace collision identified in Priivacy-ai#241: the "mission"
subcommand (which lists available mission types like software-dev,
research) is renamed to "mission-type", freeing the "mission" namespace
for the upcoming feature→mission-run terminology rename.

Changes:
- Rename cli/commands/mission.py → cli/commands/mission_type.py
- Update subcommand registration: name="mission" → name="mission-type"
- Update help text: "per-feature" → "per mission run"

Co-authored-by: Copilot <[email protected]>
Complete the terminology unification across the codebase per issue Priivacy-ai#241:
- "mission type" = abstract workflow methodology (software-dev, research)
- "mission run" = concrete work item (was "feature")

CLI-facing changes:
- --feature flag → --mission-run across all commands
- "agent feature" subcommand → "agent mission-run"
- Help text updated to use "mission run" terminology

Internal code changes (266 files):
- feature_slug → mission_slug, feature_dir → mission_dir
- feature_metadata.py → mission_metadata.py
- upgrade/feature_meta.py → upgrade/mission_meta.py
- dashboard/handlers/features.py → dashboard/handlers/missions.py
- cli/commands/agent/feature.py → cli/commands/agent/mission_run.py
- core/feature_detection.py → core/mission_detection.py (restored)

New modules added from feature branch:
- identity.py (structured 4-part agent identity)
- cli/commands/_flag_utils.py (mission-type flag resolver)
- cli/commands/agent/profile.py (agent profile management)
- core/tool_config.py (renamed from agent_config)

Co-authored-by: Copilot <[email protected]>
Replace the full implementation in specify_cli/runtime/home.py with a
thin re-export shim that delegates to kernel.paths. This makes the
5-tier template resolver PACKAGE tier automatically point to
doctrine/missions/ instead of specify_cli/missions/.

The resolver chain is now:
  resolver.py → home.get_package_asset_root() → kernel.paths → doctrine/missions/

No call sites need to change — the shim preserves all existing imports.

Co-authored-by: Copilot <[email protected]>
Wire remaining integration points from the feature branch:

CI workflows:
- ci-quality.yml: add kernel-tests job (90% coverage floor), expand
  coverage to constitution/doctrine/kernel packages, add contextive
  checks for constitution sources, mypy scans doctrine+constitution
- release-readiness.yml: Python 3.11 → 3.12
- release.yml: Python 3.11 → 3.12

pyproject.toml:
- Add python-ulid, chardet, pytestarch dependencies
- Add kernel + constitution to wheel packages
- Switch to explicit artifact file-type globs (md/yaml/json/csv)
- Fix stale mypy overrides (feature→mission_run, legacy_bridge removed)
- Add kernel/constitution to mutmut also_copy
- spec-kitty-runtime via git URL

New source modules:
- __main__.py: python -m specify_cli entry point
- doctrine.py: CLI adapter for doctrine curation workflow
- m_2_0_1: tool config key rename migration
- m_2_0_2: constitution context bootstrap migration

Test suite additions (24 files):
- Profile CLI, init, interview tests
- Doctrine reconstruction e2e
- Feature detection, tool config tests
- Mission flag rename, bare feature flag tests
- Identity parsing, frontmatter agent tests
- Workflow profile injection, constitution context
- Dual-write integration, structured identity e2e

Skipped 5 test files that test deleted modules (legacy_bridge,
forecast, status_resolver) — consistent with prior decision.

Co-authored-by: Copilot <[email protected]>
…ent docs

Add mission planning artifacts from the feature branch:

Mission specs:
- 045-agent-profile-system (spec, plan, tasks, 11 WPs)
- 046-doctrine-artifact-domain-models (spec, plan, tasks, 11 WPs)
- 048-structured-agent-identity-and-constitution-profile-integration
  (spec, plan, tasks, contracts, 8 WPs)
- 054-constitution-interview-compiler-and-bootstrap
  (spec, plan, tasks, contracts, 12 WPs)
- 057-doctrine-stack-init-and-profile-integration
  (spec, plan, tasks, 9 WPs)
- 058-mission-template-repository-refactor
  (spec, plan, tasks, contracts, 11 WPs)

Architecture:
- ADR: glossary type ownership (2026-03-25-1)
- ADR: pytestarch architectural dependency testing (2026-03-27-1)
- Initiative: doctrine execution integration
- Initiative: 054 postmortem

Development docs:
- Code review, constitution path resolution, doctrine migration
- Model-first schema generation, PR305 review plans
- Ad-hoc specialist session how-to

Supporting files:
- generate_schemas.py script
- .kittify memory and curation state

Co-authored-by: Copilot <[email protected]>
Replace 21 bare `except Exception` handlers across src/doctrine/ with
specific exception tuples matching actual failure modes:
- YAML loading loops: (YAMLError, ValidationError, OSError)
- importlib.resources fallback: (ModuleNotFoundError, TypeError)
- Config file loading: (OSError, UnicodeDecodeError, YAMLError)

Addresses PR Priivacy-ai#305 review finding M1.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
workflow.py and tasks.py use Optional[str] in Typer-annotated function
parameters but only imported Annotated from typing. With
`from __future__ import annotations`, Typer eval()s annotation strings
at app construction time, causing NameError on `spec-kitty --help`.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
The {SCRIPT} placeholder required a scripts: frontmatter key that no
template provided, causing render failures during upgrade for analyze
and checklist (prompt-driven commands). Replace all 6 occurrences with
the actual spec-kitty agent mission-run commands, matching how main
branch hardcodes spec-kitty agent feature check-prerequisites.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@stijn-dejongh stijn-dejongh force-pushed the feature/agent-profile-implementation-rebased branch from b668f0e to 80c7a23 Compare March 31, 2026 15:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2-enhancement Approved features, next version

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant