Skip to content

feat(v3r2): Wave 1+2 Bundle — Constitution + Runtime Foundation#739

Open
GoosLab wants to merge 1 commit intomainfrom
feat/SPEC-V3R2-wave-1-2-runtime-foundation
Open

feat(v3r2): Wave 1+2 Bundle — Constitution + Runtime Foundation#739
GoosLab wants to merge 1 commit intomainfrom
feat/SPEC-V3R2-wave-1-2-runtime-foundation

Conversation

@GoosLab
Copy link
Copy Markdown
Collaborator

@GoosLab GoosLab commented Apr 28, 2026

Summary

  • Wave 1 — Constitution Foundation: CON-002 (5-layer amendment safety gate), CON-003 (rule tree consolidation, 4 files merged/relocated), SPC-001 (EARS hierarchical acceptance criteria parser)
  • Wave 2 — Runtime Core: RT-005 (multi-layer settings resolution with 8-source provenance), RT-001 (hook JSON-OR-ExitCode dual protocol), RT-004 (typed session state with phase checkpoints)
  • 78 files changed: 8,477 insertions, 784 deletions across Go code, rules, skills, and templates

SPEC Coverage

SPEC Wave Type Description
CON-002 1 Go code Amendment protocol with frozen guard, canary check, contradiction detector, rate limiter, human oversight
CON-003 1 Rules-only Rule consolidation (delete 4 files, relocate content, frontmatter migration)
SPC-001 1 Go code EARS parser + hierarchical acceptance criteria + moai spec lint subcommand
RT-005 2 Go code Multi-layer settings resolution with provenance tags (policy > user > project > local > plugin > skill > session > builtin)
RT-001 2 Go code Hook JSON-OR-ExitCode dual protocol (HookResponse schema for 27 events)
RT-004 2 Go code Typed session state (blocker reports, phase checkpoints, task ledger, resumable store)

Test plan

  • go build ./... — clean build
  • go vet ./... — no warnings
  • go test ./internal/constitution/... ./internal/spec/... ./internal/config/... ./internal/hook/... ./internal/session/... ./internal/cli/... — all pass
  • CI green (Lint + Test ubuntu/macos/windows + Build)

Next Steps (Wave 3)

  • RT-002: Permission stack + bubble mode
  • SPC-002: @mx TAG v2 (sidecar index + hook integration)
  • RT-006: Hook handler 27-event coverage (after RT-002)

🤖 MoAI email@mo.ai.kr

Summary by CodeRabbit

  • New Features

    • Added moai constitution amend CLI command to propose rule amendments with dry-run support and multi-layer safety gates.
    • Added moai doctor config commands to inspect, dump, and compare configuration values across tiers.
    • Added moai state commands to view workflow phase checkpoints and blocker reports.
    • Added moai spec view command to display spec acceptance criteria in hierarchical format.
    • Introduced EARS-based acceptance criteria parser with validation and requirement mapping detection.
  • Documentation

    • Reorganized workflow methodology documentation into consolidated spec-workflow reference.
    • Refactored team coordination protocol into worktree-integration documentation.

Wave 1 — Constitution Foundation (CON-002, CON-003, SPC-001):
- CON-002: 5-layer amendment safety gate (frozen guard, canary check,
  contradiction detector, rate limiter, human oversight)
- CON-003: Rule tree consolidation (merge 4 deleted files, relocate
  content, frontmatter migration)
- SPC-001: EARS hierarchical acceptance criteria parser with spec
  linter subcommand

Wave 2 — Runtime Core (RT-005, RT-001, RT-004):
- RT-005: Multi-layer settings resolution with provenance tags
  (8-source priority stack: policy > user > project > local >
  plugin > skill > session > builtin)
- RT-001: Hook JSON-OR-ExitCode dual protocol (HookResponse schema,
  structured output for all 27 hook events)
- RT-004: Typed session state with phase checkpoints and
  resumable permission context

Supporting changes:
- Template mirrors for all rules/skills changes
- LSP client decision document
- Master wave plan document
- CLI subcommands: constitution, spec lint/view, state, doctor config

🤖 MoAI <email@mo.ai.kr>
@GoosLab GoosLab added critical Critical priority feature A new capability or enhancement request config hooks labels Apr 28, 2026
@github-actions github-actions Bot added docs Documentation improvements go tests templates labels Apr 28, 2026
@GoosLab
Copy link
Copy Markdown
Collaborator Author

GoosLab commented Apr 28, 2026

@claude CI 빌드가 실패했습니다. 오류를 분석하고 수정해주세요.

실패한 워크플로우: Release Drafter
브랜치: feat/SPEC-V3R2-wave-1-2-runtime-foundation
실패 로그: https://github.com/modu-ai/moai-adk/actions/runs/25040415873

실패 로그를 확인하고 근본 원인을 파악한 뒤 수정해주세요.

Latte AI CI Monitor • latte@mo.ai.kr

@GoosLab
Copy link
Copy Markdown
Collaborator Author

GoosLab commented Apr 28, 2026

@claude CI 빌드가 실패했습니다. 오류를 분석하고 수정해주세요.

실패한 워크플로우: Claude Code Review
브랜치: feat/SPEC-V3R2-wave-1-2-runtime-foundation
실패 로그: https://github.com/modu-ai/moai-adk/actions/runs/25040415760

실패 로그를 확인하고 근본 원인을 파악한 뒤 수정해주세요.

Latte AI CI Monitor • latte@mo.ai.kr

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 28, 2026

Caution

Review failed

Failed to post review comments

Walkthrough

This PR introduces comprehensive infrastructure for constitutional amendments, configuration resolution tiers, session state persistence, EARS-based acceptance criteria parsing, updated hook response typing, and new CLI commands (spec view, state management, doctor config, constitution amend). It also refactors documentation by consolidating development methodology details into spec-workflow.md and consolidating team protocol into worktree-integration.md.

Changes

Cohort / File(s) Summary
Documentation & Template Refactoring
.claude/rules/moai/workflow/workflow-modes.md, .claude/rules/moai/workflow/team-protocol.md, internal/template/templates/.claude/rules/moai/workflow/workflow-modes.md, internal/template/templates/.claude/rules/moai/workflow/team-protocol.md
Deleted two legacy documentation files (workflow-modes, team-protocol) that are being superseded by expanded spec-workflow.md and worktree-integration.md.
Documentation Cross-References
.claude/rules/moai/workflow/context-window-management.md, .claude/rules/moai/workflow/spec-workflow.md, .claude/rules/moai/workflow/team-pattern-cookbook.md, .claude/rules/moai/workflow/worktree-integration.md, .claude/skills/moai/SKILL.md, .claude/skills/moai/references/reference.md, .claude/skills/moai/workflows/moai.md, .claude/skills/moai/workflows/run.md, CLAUDE.md, internal/template/templates/.claude/rules/moai/.../*
Updated all documentation links to redirect from deleted workflow-modes.md to spec-workflow.md; consolidated AskUserQuestion/agent-interaction rules in CLAUDE.md by removing inlined protocol details and linking to external protocol docs; updated frontmatter paths/globs configuration.
Configuration System
internal/config/source.go, internal/config/source_test.go, internal/config/provenance.go, internal/config/provenance_test.go, internal/config/merge.go, internal/config/merge_test.go, internal/config/resolver.go, internal/config/resolver_test.go, internal/config/resolver_errors.go, internal/config/audit_test.go
New 8-tier configuration priority system with provenance tracking, multi-tier merging/diffing, and resolution layer supporting policy/user/project/local/plugin/skill/session/builtin sources. Includes comprehensive error types for schema mismatches, ambiguity, and read failures.
Constitutional Amendment Pipeline
internal/constitution/amendment.go, internal/constitution/amendment_test.go, internal/constitution/canary.go, internal/constitution/contradiction.go, internal/constitution/evolution_log.go, internal/constitution/evolution_log_test.go, internal/constitution/frozen_guard.go, internal/constitution/human_oversight.go, internal/constitution/pipeline.go, internal/constitution/rate_limiter.go
Complete 5-gate safety system for constitutional amendments: frozen-zone protection, canary evaluation (against completed SPECs), contradiction detection, rate limiting, and human oversight. Includes evolution log persistence via YAML frontmatter and dry-run support.
Session State & Checkpointing
internal/session/phase.go, internal/session/phase_test.go, internal/session/checkpoint.go, internal/session/checkpoint_test.go, internal/session/state.go, internal/session/state_test.go, internal/session/blocker.go, internal/session/blocker_test.go, internal/session/store.go, internal/session/store_test.go, internal/session/task_ledger.go
New workflow phase enumeration, phase-specific checkpoints (Plan/Run/Sync), persistent session state with custom JSON marshaling to reconstruct polymorphic checkpoint types, blocker reporting, and FileSessionStore with TTL-based staleness detection.
Spec & Acceptance Criteria
internal/spec/ears.go, internal/spec/ears_test.go, internal/spec/errors.go, internal/spec/parser.go, internal/spec/parser_test.go
EARS-based acceptance criteria parser with hierarchical tree building, requirement-mapping extraction, depth/leaf validation, auto-wrapping of flat ACs, dangling reference detection. Includes custom error types for ID conflicts, depth violations, and missing mappings.
Hook Response Typing
internal/hook/response.go, internal/hook/response_test.go, internal/hook/dual_parse.go, internal/hook/dual_parse_test.go
Typed hook response system with 20+ event-specific output structs, dual-parse support for legacy exit-code and JSON protocols, permission decision enum, context truncation validation, and bridging helpers.
CLI Commands
internal/cli/root.go, internal/cli/constitution.go, internal/cli/doctor_config.go, internal/cli/spec.go, internal/cli/spec_view.go, internal/cli/state.go
New moai constitution amend, moai doctor config dump/diff, moai spec view, and moai state dump/show-blocker commands with validation, registry loading, dry-run support, and hierarchical acceptance-criteria rendering.
Scaffolding & Design
internal/cli/design_folder.go
Added strict reserved-filename collision check during design directory scaffolding before template deployment.
Planning & Tracking
.moai/plans/V3R2-V3R3-MASTER-WAVE-PLAN.md, .moai/decisions/lsp-client-choice.md, internal/template/templates/.moai/decisions/lsp-client-choice.md
New comprehensive master execution plan for V3R2+V3R3 waves with dependency DAG, per-wave SPEC tables, and progress tracking. Updated decision document versioning and relocation metadata.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CLI as moai<br/>constitution amend
    participant FrozenGuard
    participant Canary as Canary<br/>Evaluator
    participant ContradictionDetector
    participant RateLimiter
    participant HumanOversight
    participant EvolutionLog
    participant RuleFile

    User->>CLI: moai constitution amend --rule ... --before ... --after ...
    CLI->>CLI: Load zone registry & validate inputs
    CLI->>FrozenGuard: Check(proposal)
    FrozenGuard-->>CLI: allowed or ErrFrozenAmendment
    CLI->>Canary: Evaluate(proposal, projectDir)
    Canary->>Canary: Scan completed SPECs, compute score impact
    Canary-->>CLI: CanaryResult or ErrCanaryUnavailable
    CLI->>ContradictionDetector: Scan(proposal, registry)
    ContradictionDetector->>ContradictionDetector: Check zone & clause conflicts
    ContradictionDetector-->>CLI: conflicts or empty result
    CLI->>RateLimiter: Admit(proposal, evolutionLogPath)
    RateLimiter->>EvolutionLog: Load prior amendments
    EvolutionLog-->>RateLimiter: amendment history
    RateLimiter->>RateLimiter: Check rollback cooldown, weekly cap, 24h cooldown
    RateLimiter-->>CLI: allowed or ErrRateLimitExceeded
    CLI->>HumanOversight: Approve(proposal)
    HumanOversight->>User: Display proposal + metrics, prompt Y/N
    User-->>HumanOversight: Y/N response
    HumanOversight-->>CLI: approval boolean
    alt not dry-run
        CLI->>RuleFile: Update rule clause
        CLI->>CLI: Update zone registry
        CLI->>EvolutionLog: Append AmendmentLog
    end
    CLI-->>User: Success with log ID or dry-run diagnostics
Loading
sequenceDiagram
    participant CLI as moai spec view
    participant Filesystem
    participant Parser as EARS Parser
    participant Validator

    CLI->>Filesystem: Read /.moai/specs/{SPEC-ID}/spec.md
    alt spec.md missing
        CLI-->>CLI: Error & exit
    end
    CLI->>Parser: ParseAcceptanceCriteria(markdown)
    Parser->>Parser: Locate AC section, extract lines by depth
    Parser->>Parser: Build hierarchical tree, inherit Given
    Parser->>Validator: ValidateDepth() per node
    Parser->>Validator: ValidateRequirementMappings()
    Validator-->>Parser: errors (DuplicateID, MaxDepthExceeded, Missing mappings)
    alt parse errors present
        CLI->>CLI: Print warnings (DanglingRef, MissingMapping)
        alt hard errors
            CLI-->>CLI: Error & exit
        end
    end
    CLI->>CLI: Render tree hierarchically (with --shape-trace metadata)
    CLI-->>Filesystem: Print formatted AC tree
Loading

Estimated code review effort

🎯 5 (Critical) | ⏱️ ~105 minutes

Reasoning: This PR spans 5+ heterogeneous subsystems (config resolution, constitution amendments, session state, spec parsing, hook typing, CLI) with ~5000+ lines of new logic and tests. Each domain requires independent reasoning: config merging/provenance logic, multi-gate amendment pipeline with canary scoring and contradiction scanning, polymorphic JSON marshaling for checkpoint types, complex EARS parser with hierarchical tree building and validation, dual-parse hook protocol, and multiple CLI integrations. The test coverage is comprehensive but dense logic (especially parser, pipeline, and resolver) demands careful validation of edge cases, error handling, and correctness.

Possibly related PRs

Suggested labels

docs, go, tests, config, cli, session

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 57.06% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat(v3r2): Wave 1+2 Bundle — Constitution + Runtime Foundation' is specific and clearly describes the main changes: a large feature bundle implementing constitutional amendment safety gates, rule consolidation, EARS parser, multi-layer settings resolution, hook protocols, and session state management.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/SPEC-V3R2-wave-1-2-runtime-foundation

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov-commenter
Copy link
Copy Markdown

@GoosLab
Copy link
Copy Markdown
Collaborator Author

GoosLab commented Apr 28, 2026

@claude CI 빌드가 실패했습니다. 오류를 분석하고 수정해주세요.

실패한 워크플로우: CI
브랜치: feat/SPEC-V3R2-wave-1-2-runtime-foundation
실패 로그: https://github.com/modu-ai/moai-adk/actions/runs/25040415927

실패 로그를 확인하고 근본 원인을 파악한 뒤 수정해주세요.

Latte AI CI Monitor • latte@mo.ai.kr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

config critical Critical priority docs Documentation improvements feature A new capability or enhancement request go hooks templates tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants