5.3 KiB
Phase 3: The AI-Native Git Layer (Full Traceability)
Status: ✅ COMPLETE - All 10 tests passing
Overview
Phase 3 implements semantic mutation tracking and comprehensive traceability through a deterministic hashing and classification system. Every file mutation is now logged with intent metadata, SHA-256 content hashing, and classification (AST_REFACTOR vs INTENT_EVOLUTION).
Core Components
1. TraceLogger (src/core/intent/TraceLogger.ts)
Purpose: Semantic tracking and trace serialization for all mutations
Key Methods:
hashContent(content: string): string- Generates SHA-256 hash of file contentclassifyMutation(content, originalContent?, isNewFile?): MutationClass- Classifies mutations:- INTENT_EVOLUTION: New files or >20% size changes
- AST_REFACTOR: Syntax-only changes within existing scope
logTrace(intentId, filePath, content, mutationClass, reqId?)- Appends trace entry to.orchestration/agent_trace.jsonlreadTraces()- Reads all entries from trace filegetTracesByIntent(intentId)- Queries traces filtered by intent_id
Trace Entry Schema:
{
"intent_id": "string | null",
"mutation_class": "AST_REFACTOR" | "INTENT_EVOLUTION",
"path": "string",
"content_hash": "sha256_hex_string",
"timestamp": "ISO8601_string",
"req_id": "optional_request_id"
}
2. Tool Schema Updates (src/core/prompts/tools/native-tools/write_to_file.ts)
Changes: Added two required parameters to the write_to_file tool:
intent_id: {
type: "string",
description: "The active intent ID that authorizes this write operation"
}
mutation_class: {
type: "string",
enum: ["AST_REFACTOR", "INTENT_EVOLUTION"],
description: "Classification of the change"
}
Impact: All write_file operations must now provide intent context and mutation classification.
Integration Points
Gatekeeper (Phase 2)
Located in src/core/assistant-message/presentAssistantMessage.ts:
- Blocks restricted tools (write_file, apply_diff, execute_command) without active intent
- Returns XML context block with current intent
Post-Hook (Phase 3 Ready)
TraceLogger is now ready to be integrated as a post-hook after successful tool execution. When integrated, write_file operations will automatically:
- Extract intent_id and mutation_class from tool parameters
- Generate content_hash via SHA-256
- Append trace entry to agent_trace.jsonl with timestamp and optional req_id
Test Coverage
Phase 1 Tests (1 test, 1 passing):
- Intent handshake enforcement and gatekeeper validation
Phase 3 Tests (10 tests, all passing):
- ✅ SHA-256 hash generation and consistency
- ✅ AST_REFACTOR classification for syntax-only changes
- ✅ INTENT_EVOLUTION classification for new files
- ✅ INTENT_EVOLUTION classification for >20% size changes
- ✅ Trace entry logging with intent_id and content_hash
- ✅ Trace entry logging with req_id support
- ✅ Multiple trace entries appended correctly
- ✅ Query traces by intent_id
- ✅ Handle missing intent_id (null) in traces
- ✅ JSONL serialization format validation
Total: 11/11 tests passing
Mutation Classification Heuristic
if (isNewFile) → INTENT_EVOLUTION
else if (!originalContent) → INTENT_EVOLUTION
else if ((newLen - originalLen) / originalLen > 0.2) → INTENT_EVOLUTION
else → AST_REFACTOR
20% Threshold Rationale:
- Captures multi-line additions/refactoring as INTENT_EVOLUTION
- Preserves minor formatting/style changes as AST_REFACTOR
- MVP approach; future enhancement: AST-based semantic analysis
Trace Persistence
Location: .orchestration/agent_trace.jsonl
- Append-only log format (JSONL)
- One entry per mutation
- Automatically created if missing
- Human-readable JSON per line for CLI tooling
Architecture Benefits
- Auditability: Every mutation traced to an intent with SHA-256 verification
- Semantic Classification: Distinguish refactoring from feature evolution
- Deterministic: Hash consistency enables re-validation and conflict detection
- Immutable: JSONL format prevents accidental modifications
- Queryable: Intent-based filtering for trace analysis
Next Steps (Post-Phase-3)
- Integration: Wire TraceLogger into tool dispatcher's post-hook
- Dashboard: Build trace visualization UI in Roo-Code UI
- Verification: Implement trace validation CLI for hash verification
- Enhancement: Replace heuristic with AST-based semantic analysis
- Rollup: Create intent summary reports from trace entries
Files Modified
- ✅
src/core/intent/TraceLogger.ts- NEW (120 lines) - ✅
src/core/prompts/tools/native-tools/write_to_file.ts- MODIFIED (schema updated) - ✅
tests/phase3-trace-logging.test.ts- NEW (10 comprehensive tests)
Compliance
| Phase | Component | Status |
|---|---|---|
| 1 | System Prompt Enforcement | ✅ Complete |
| 1 | select_active_intent Tool | ✅ Complete |
| 1 | Intent Validation | ✅ Complete |
| 2 | IntentHookEngine | ✅ Complete |
| 2 | Tool Gatekeeper | ✅ Complete |
| 3 | Semantic Hashing | ✅ Complete |
| 3 | Mutation Classification | ✅ Complete |
| 3 | Trace Serialization | ✅ Complete |
All Phase 3 deliverables implemented and tested.