Skip to content

feat: Navigation-based workflow engine for deterministic traversal#35

Closed
m2ux wants to merge 7 commits intomainfrom
feat/34-navigation-workflow-engine
Closed

feat: Navigation-based workflow engine for deterministic traversal#35
m2ux wants to merge 7 commits intomainfrom
feat/34-navigation-workflow-engine

Conversation

@m2ux
Copy link
Copy Markdown
Owner

@m2ux m2ux commented Jan 29, 2026

Summary

Implements a navigation-based workflow engine that provides server-side authority over workflow state and transitions. This addresses the issue of AI agents bypassing workflow fidelity by making the engine the sole interpreter of state.

Key Changes

  • State Codec Module: Encode/decode workflow state as opaque gzip+base64 tokens
  • Navigation Computation: Compute available actions (affordances) from workflow + state
  • State Transitions: Pure functions producing new state from actions (XState pattern)
  • Navigation Tools: 4 MCP tools (nav_start, nav_situation, nav_action, nav_checkpoint)
  • Comprehensive Tests: 165 tests including unit, integration, and E2E coverage
  • API Documentation: Updated docs with navigation tools reference

Architecture

Agent                    Engine
  |                        |
  |-- nav_start ---------> |  (Start workflow)
  |<-- position + actions -|
  |                        |
  |-- nav_action --------> |  (Execute action)
  |<-- new position -------|  (+ opaque state token)
  |                        |
  |-- nav_checkpoint ----> |  (If checkpoint blocking)
  |<-- checkpoint options -|

Key Design Principles

  1. Opaque State: Agents cannot read/interpret state, only pass it through
  2. Checkpoint Blocking: Steps cannot complete while checkpoint active
  3. Transition Validation: Engine validates all activity transitions
  4. Immutable Transitions: State functions return new state, never mutate

Test Plan

  • Unit tests for state codec (encoding, decoding, compression)
  • Unit tests for navigation computation (position, actions, checkpoints)
  • Unit tests for state transitions (steps, checkpoints, activities, loops)
  • Integration tests for navigation tools
  • E2E tests for complete workflow traversal
  • Regression: All 165 tests passing

Closes #34

m2ux added 7 commits January 29, 2026 15:57
Implement opaque state token encoding/decoding using gzip compression
and base64 encoding. The token format (v1.gzB64.{payload}) is designed
to be non-human-readable to prevent agents from interpreting state.

- Add encodeState/decodeState with gzip+base64
- Add validation helpers (isValidTokenFormat, getTokenVersion)
- Add compression ratio diagnostic
- Add StateCodecError for structured error handling
- Add navigation types for API responses
- Add comprehensive test coverage (20 tests)

Part of #34
Implement core affordance computation logic that determines available
actions from workflow definition and current state.

- computePosition: Get current position (activity, step, loop)
- computeAvailableActions: Core affordance computation
- getActiveCheckpoint: Detect blocking checkpoints
- isCheckpointBlocking: Check if progress is blocked
- isActivityComplete: Check if activity can transition
- generateSituationMessage: Human-readable status

Checkpoints block step completion until responded, ensuring agents
cannot skip required user decisions.

Part of #34
Implement pure functions that produce new state from workflow actions,
following XState pattern of Machine.transition(state, event) → newState.

- completeStep: Mark step complete, advance to next
- respondToCheckpoint: Record checkpoint response
- transitionToActivity: Move to new activity (validates completion)
- advanceLoop: Start/advance/complete loop iterations
- tryDefaultTransition: Convenience for default transitions

All functions return TransitionResult with success/error, ensuring
agents receive clear feedback on invalid actions. State immutability
verified in tests.

Part of #34
Implement the 4 core navigation tools that provide the "navigation
landscape" for agents:

- nav_start: Initialize workflow, return initial situation
- nav_situation: Get current situation from state token
- nav_action: Execute action (complete_step, respond_to_checkpoint,
  transition, advance_loop) with validation
- nav_checkpoint: Get active checkpoint details

Each response includes position, available actions, active checkpoint
(if any), and opaque state token. Agents cannot interpret state,
only pass it through, ensuring engine authority over transitions.

History events added automatically for all state changes.

Part of #34
Enable navigation tools in MCP server startup. Tools now available:
- nav_start, nav_situation, nav_action, nav_checkpoint

Part of #34
Comprehensive E2E tests covering:
- Simple workflow completion without checkpoints
- Checkpoint blocking until response
- Full activity traversal with transition
- State resumption from saved token
- Multi-activity workflow traversal
- Error handling for invalid inputs

Tests validate the complete navigation flow from start through
multiple activities, ensuring agents cannot skip checkpoints or
complete steps out of order.

Part of #34
Document the new navigation API including:
- Tool descriptions and parameters
- Response format with position, actions, checkpoint
- State token opacity and purpose
- Action types and required parameters
- Checkpoint blocking behavior

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement navigation-based workflow engine with server-side enforcement

1 participant