/stack-utils

Stack Mode L2+ Production low usage

/stack-utils

Overview

/stack-utils is a production command in the Stack Mode category of the Prismatic Platform. It provides advanced utility operations for the stack-based conversation system, including stack maintenance, debugging, analytics, export, and health monitoring. While the core stack commands (/stack, /frame, /pop, /fork) handle basic conversation state management, /stack-utils addresses operational concerns: diagnosing stack corruption, analyzing conversation patterns, exporting stack histories, and maintaining the underlying ETS-backed storage layer.

This command operates under the L2+ authority level and is executed by the stack-conversation-manager agent. It is part of the platform's 216-command slash command registry, built on the AIAD (Autonomous Intelligence Agent Design) standard. The stack-conversation-manager agent is implemented as an OTP-compliant GenServer (PrismaticClaude.StackConversation) with 1,128 lines of production code, providing the programmatic infrastructure for all stack operations.

The stack-based conversation mode is a P0 absolute enforcement requirement for all Claude interactions on the Prismatic Platform. Every response creates an immutable frame, every branch is tracked, and every checkpoint is persisted. /stack-utils ensures this critical infrastructure remains healthy, provides diagnostic tools when issues arise, and enables operators to extract value from conversation history through analytics and export.

Architecture

The stack-utils system operates as an administrative layer above the core StackConversation GenServer.

Stack Utils Architecture

             /stack-utils
                   |
           Utils Orchestrator
                   |
          +--------+--------+--------+
          |        |        |        |
       Health    Analytics  Export   Maintenance
       Monitor   Engine     System   Toolkit
          |        |        |        |
    +-----+--+ +--+--+ +--+--+ +---+---+
    |    |   | |  |  | |  |  | |   |   |
   ETS  Frame Branch Conv Frame Compact
   Check Valid  Trace  Stats Export Repair
    |    |   | |  |  | |  |  | |   |   |
    +----+---+-+--+--+-+--+--+-+---+---+
                   |
          Stack Status Report

Component Overview

ComponentPurposeKey Operations
Health MonitorStack infrastructure healthETS table status, GenServer liveness, disk persistence
Analytics EngineConversation pattern analysisFrame statistics, branch frequency, decision tracking
Export SystemStack data extractionJSON export, markdown summary, conversation replay
Maintenance ToolkitStorage maintenanceCompaction, orphan cleanup, integrity repair

Storage Layer

LayerTechnologyPurposePersistence
PrimaryETS (Erlang Term Storage)Fast frame read/writeIn-memory
PersistenceDisk filesSession survival.claude/stack-conversation/
CheckpointsNamed snapshotsState restorationPersisted to disk
BranchesFork recordsConversation treeETS + disk

Usage

# Show stack health status
/stack-utils health

# Display stack analytics summary
/stack-utils analytics

# Export current stack to JSON
/stack-utils export --format json --output ./stack-export.json

# Export conversation as readable markdown
/stack-utils export --format markdown --output ./conversation.md

# Run integrity check on stack storage
/stack-utils check --integrity

# Compact stack storage (remove orphaned data)
/stack-utils compact

# Show branch tree visualization
/stack-utils branches --tree

# List all checkpoints with metadata
/stack-utils checkpoints --verbose

# Repair corrupted stack frames
/stack-utils repair --dry-run

# Show frame creation timeline
/stack-utils timeline

Practical Examples

# Full diagnostic report for debugging stack issues
/stack-utils health --verbose --include-ets-stats

# Analyze conversation patterns over the last 24 hours
/stack-utils analytics --since 24h --format json

# Export specific branch for review
/stack-utils export --branch main --format markdown --output ./branch-review.md

# Find and clean orphaned frames from interrupted sessions
/stack-utils compact --orphans --dry-run

# Validate all frame checksums
/stack-utils check --integrity --checksums

# Replay conversation from checkpoint
/stack-utils replay --from-checkpoint "pre-refactor"

Options

OptionTypeDefaultDescription
healthsubcommand--Stack infrastructure health check
analyticssubcommand--Conversation pattern analytics
exportsubcommand--Export stack data
checksubcommand--Integrity and validation checks
compactsubcommand--Storage compaction and cleanup
branchessubcommand--Branch tree operations
checkpointssubcommand--Checkpoint management
repairsubcommand--Stack frame repair
timelinesubcommand--Frame creation timeline
replaysubcommand--Conversation replay
--formatenumtextOutput format: text, json, markdown
--outputpathnoneExport output file path
--verboseflagfalseDetailed output with internal state
--sincedurationallTime filter for analytics and export
--branchstringcurrentTarget branch for operations
--dry-runflagfalseShow planned action without executing
--include-ets-statsflagfalseInclude ETS table statistics
--checksumsflagfalseValidate frame data checksums
--orphansflagfalseTarget orphaned frames specifically

Execution Flow

Phase 1: GenServer Connection

The utils orchestrator connects to the running StackConversation GenServer process. If the GenServer is not running (application not started), utilities that only need disk-persisted data can still operate in offline mode by reading directly from .claude/stack-conversation/.

Phase 2: State Inspection

The current stack state is inspected: total frame count, active branch, checkpoint count, ETS table size, and disk persistence status. This baseline informs all subsequent operations.

Phase 3: Operation Dispatch

Based on the selected subcommand, the appropriate operation module is invoked. Health checks run non-destructively. Analytics compute derived metrics from frame data. Export serializes stack data. Maintenance operations (compact, repair) require explicit confirmation for destructive actions.

Phase 4: Integrity Validation

For check and repair operations, each frame is validated against its expected structure: frame ID uniqueness, parent-child relationship consistency, checkpoint reference validity, and optional checksum verification. Violations are categorized by severity.

Phase 5: Report Generation

Results are formatted according to the requested output format. Health reports include status indicators (green/yellow/red). Analytics include computed metrics with trend indicators. Export produces self-contained documents suitable for external review.

Integration Points

ComponentIntegration TypeDescription
/stackCoreDisplay operations use the same GenServer
/frameCoreFrame inspection shares state infrastructure
/popCorePop operations tracked by utils analytics
/forkCoreFork operations create branch records
StackConversation GenServerRuntimeDirect GenServer interaction
TelemetryMonitoring[:prismatic_claude, :stack_conversation, *] events
Quality DNAStateConversation patterns inform quality DNA
Session ContextPersistenceStack data persists across sessions

Best Practices

Regular Health Checks

Run /stack-utils health at the beginning of each session, especially after unexpected session terminations. Stack corruption from interrupted persistence operations can cause subtle issues that compound over time.

Periodic Compaction

Execute /stack-utils compact weekly to clean up orphaned frames from popped branches, interrupted forks, and abandoned checkpoints. Without compaction, the ETS table grows monotonically and may impact performance in long-running sessions.

Export Before Destructive Operations

Before using /pop or /fork (both marked DESTRUCTIVE), export the current stack state with /stack-utils export. This provides a recovery point if the destructive operation produces unexpected results.

Analytics for Conversation Optimization

Use /stack-utils analytics to identify conversation patterns: excessive branching (indicates unclear requirements), deep stacks without checkpoints (risk of context loss), and frequent pops (indicates exploration without commitment). These patterns guide conversation strategy improvements.

Error Handling

Error CodeDescriptionResolution
GENSERVER_DOWNStackConversation GenServer not runningStart application or use offline mode
ETS_TABLE_MISSINGETS table not foundGenServer restart required
FRAME_CORRUPTEDFrame data fails integrity checkRun /stack-utils repair
CHECKPOINT_ORPHANEDCheckpoint references non-existent frameRun /stack-utils compact --orphans
BRANCH_INCONSISTENTBranch tree has inconsistent parent-child linksRun /stack-utils repair --branch-tree
DISK_PERSISTENCE_STALEDisk state older than ETS stateForce persistence with /stack-utils sync
EXPORT_WRITE_FAILURECannot write export fileCheck filesystem permissions

Advanced Usage

Conversation Replay

Replay a conversation from a specific checkpoint for review:

/stack-utils replay --from-checkpoint "feature-start" --to-checkpoint "feature-complete" --format markdown

Branch Comparison

Compare two branches to understand divergence:

/stack-utils branches --compare main feature-exploration --format json

Automated Maintenance Schedule

Set up periodic maintenance hooks:

# Add to session lifecycle hooks
/stack-utils maintenance --schedule session-end --operations "compact,check"

Doctrine Compliance

All commands operate under the NO MERCY, NO DOUBTS doctrine:

  • NO MERCY: Zero tolerance for incomplete execution or quality violations. Stack integrity is maintained absolutely; corrupted frames are never silently ignored.
  • NO DOUBTS: Full investigation before action, evidence-based results. Every repair operation provides evidence of corruption before and verification of repair after.
  • /stack - Display complete conversation stack with all frames
  • /frame - Inspect specific conversation frame by ID
  • /pop - Remove last N frames from conversation stack (DESTRUCTIVE)
  • /fork - Branch conversation from specific frame (DESTRUCTIVE)
  • /checkpoint - Mark current frame as named checkpoint
  • /goto - Restore conversation to named checkpoint
  • /agents - List and manage agent ecosystem with status monitoring

Connect & Contribute

Created by Tomáš Korcak (korczis) | Open Source under GHL