Skip to main content

WYN360 CLI - System Architecture

This document provides a detailed overview of the WYN360 CLI system architecture, including all components, layers, and data flows.

Version: 0.5.2 Last Updated: April 2026


Architecture Overview

WYN360 CLI is built on a modular, layered architecture with six main layers. The v0.4.0 and v0.5.0 releases added three new architectural layers (Pipeline, Agentic, State Management) on top of the original three (UI, Agent, Tools).


Layer Descriptions

1. User Interface Layer

The entry point for all user interaction.

ComponentModulePurpose
CLI Interfacecli.pyClick-based CLI with prompt_toolkit input, Rich console output
Slash Commandscli.py25+ commands: /plan, /memory, /dream, /rewind, /cron, /plugins, etc.
Vim Modevim_mode.pyVi-style editing via prompt_toolkit (toggle with /vim)
Voice Inputvoice.pySpeech-to-text via SpeechRecognition (toggle with /voice)
Buddybuddy.pyVirtual companion with deterministic generation and event reactions

Input flow:

User types message (or speaks via /voice)
→ Slash command? → handle_slash_command() → display result
→ Normal message? → pass to Pipeline Layer

2. Pipeline Layer (new in v0.4.0)

Middleware that processes every message before and after the AI sees it. Runs automatically on every turn.

ComponentModuleTriggerPurpose
Pre-Query Hookshooks.pyEvery messageValidate input, transform messages, safety warnings
Post-Response Hookshooks.pyEvery responseFilter output, log, modify responses
Token Budgettoken_budget.pyEvery responseAuto-continue if response was cut off by max_tokens

Built-in hooks (always active):

  • builtin_safety_check — warns on rm -rf, DROP TABLE, etc.
  • builtin_response_tracker — logs oversized responses

3. Agent Layer

The core orchestrator that routes between the LLM and tools.

ComponentModulePurpose
WYN360Agentagent.pyMain agent class using pydantic-ai framework
LLM Provideragent.pyRoutes to Anthropic, AWS Bedrock, Google Gemini, or OpenAI
System Promptagent.pyDynamic prompt including memory context, plan state, skills list
Conversation Historyagent.pyMaintains context across turns with pydantic-ai message objects

Provider selection: CHOOSE_CLIENT env var (1=Anthropic, 2=Bedrock, 3=Gemini, 4=OpenAI) or auto-detect from API keys.

4. Agentic Layer (new in v0.4.0/v0.5.0)

Autonomous subsystems that operate independently or in parallel.

ComponentModuleTriggerPurpose
Plan Modeplanner.pyAI calls enter_plan_mode toolStructured planning before code changes
Sub-Agentssubagent.pyAI spawns workersParallel research, implementation, verification
Dreamdream.pyAuto after 24h + 3 sessionsBackground memory consolidation from session transcripts
Croncron_agent.pyUser creates with /cron addRecurring scheduled tasks (e.g., monitor CI every 5m)

5. Tools Layer

Functions the AI can call to interact with the filesystem, web, and external services.

CategoryToolsModule
File Operationsread_file, write_file, list_files, delete_file, move_file, create_directoryagent.py, utils.py
Git Operationsgit_status, git_diff, git_log, git_branchagent.py
Code Operationsexecute_command, search_files, generate_testsagent.py, utils.py
GitHubgh_commit_changes, gh_create_pr, gh_create_branch, gh_checkout_branch, gh_merge_branchagent.py
Webweb_search (builtin), fetch_website, browse_and_findagent.py, browser_use.py
Browseranalyze_page_dom, execute_dom_action, intelligent_browse, login_to_websiteagent.py, tools/browser/
Documentsread_excel, read_word, read_pdfagent.py, document_readers.py
Plan Modeenter_plan_mode, exit_plan_modeagent.py, planner.py
HuggingFacecreate_hf_space, push_to_hf_space, check_hf_authenticationagent.py

6. State & Storage Layer

Persistent state management across sessions.

ComponentModuleStoragePurpose
Memorymemory.py~/.wyn360/memory/Persistent cross-session knowledge (user, feedback, project, reference)
Skillsskills.py~/.wyn360/skills/ + .wyn360/skills/User-defined slash commands via YAML
Pluginsplugin_system.py~/.wyn360/plugins/Installable extensions with YAML manifests
Rewindrewind.pyIn-memoryConversation state snapshots for undo (up to 50)
Compactioncompaction.pyIn-memoryAuto-drops old messages when history exceeds 50
Configurationconfig.py~/.wyn360/config.yaml + .wyn360.yamlThree-tier config (user < project < env vars)
Sessionssession_manager.py~/.wyn360/sessions/Cookie storage for authenticated browsing
Credentialscredential_manager.py~/.wyn360/credentials/vault.encAES-256-GCM encrypted token storage
Dream Statedream.py~/.wyn360/dream/Tracks last consolidation time, lock file
LSPlsp_client.pyIn-memoryCached diagnostics from pyright/ruff

Data Flow

Complete Request/Response Cycle

User types message

├─ Slash command (/plan, /memory, /dream, etc.)
│ → handle_slash_command() → display result → done

└─ Normal message
→ Pre-Query Hooks fire (safety check, custom hooks)
→ Token Budget starts tracking
→ Agent sends to LLM with conversation history + memory context
→ LLM may call tools:
│ ├─ enter_plan_mode → switch to read-only investigation
│ ├─ read_file, search_files → return results
│ ├─ write_file, execute_command → modify filesystem
│ └─ exit_plan_mode → create plan for user approval
→ LLM returns response
→ Post-Response Hooks fire (tracking, custom hooks)
→ Token Budget checks: cut off? → auto-continue if needed
→ Rewind takes snapshot of conversation state
→ Compaction checks: >50 messages? → drop oldest, keep 10
→ Dream checks: 24h+ and 3+ sessions? → background consolidation
→ Display response to user

Plan Mode Flow

User: "Add authentication to the app"
→ AI decides task is complex
→ AI calls enter_plan_mode("Add authentication")
→ AI investigates: read_file, search_files, list_files (NO writes)
→ AI calls exit_plan_mode("1. Create middleware\n2. Add JWT\n3. Update routes\n4. Write tests")
→ Plan displayed to user

User: /plan approve
→ Plan steps execute sequentially
→ User: /plan status → "2/4 steps completed"
→ User: /plan skip → skip current step

Dream Consolidation Flow

After every AI response (automatic):
→ Check: 24+ hours since last dream? AND 3+ new sessions?
→ Yes → Acquire filesystem lock
→ Background task: read recent session transcripts
→ AI agent extracts useful patterns
→ Save as memory files in ~/.wyn360/memory/
→ Release lock, update dream_state.json
→ No → Skip silently

Module Map

wyn360_cli/
├── cli.py # CLI entry, slash commands, chat loop
├── agent.py # WYN360Agent, tool definitions, LLM routing
├── config.py # Three-tier configuration system
├── utils.py # File ops, command execution, metrics

├── # Agentic Features (v0.4.0)
├── memory.py # Persistent memory with YAML frontmatter
├── subagent.py # Parallel worker agents
├── planner.py # Plan mode state machine
├── token_budget.py # Auto-continue on max_tokens
├── skills.py # User-defined slash commands
├── hooks.py # Pre/post response pipeline

├── # Advanced Features (v0.5.0)
├── dream.py # Background memory consolidation
├── compaction.py # Auto-summarize old messages
├── vim_mode.py # Vi-style editing
├── voice.py # Speech-to-text input
├── buddy.py # Virtual companion
├── cron_agent.py # Scheduled recurring agents
├── plugin_system.py # Plugin management
├── lsp_client.py # Language server diagnostics
├── rewind.py # Conversation state snapshots

├── # Infrastructure
├── browser_use.py # Website fetching with crawl4ai
├── browser_auth.py # Playwright-based login automation
├── browser_controller.py # Browser automation
├── credential_manager.py # AES-256 encrypted credential storage
├── session_manager.py # Cookie/session management
├── vision_engine.py # Claude Vision API
├── document_readers.py # Excel/Word/PDF processing

├── tools/
│ └── browser/ # DOM-first browser automation subsystem
│ ├── automation_orchestrator.py
│ ├── browser_tools.py
│ └── ...

└── tests/
├── test_agent.py # 93 tests
├── test_cli.py # 33 tests
├── test_config.py # 25 tests
├── test_utils.py # 29 tests
├── test_memory.py # 14 tests
├── test_subagent.py # 14 tests
├── test_planner.py # 26 tests
├── test_token_budget.py # 12 tests
├── test_skills.py # 13 tests
├── test_hooks.py # 20 tests
├── test_dream.py # 11 tests
└── test_v050_features.py # 62 tests

Feature Timeline

VersionFeatures Added
v0.1.0-v0.2.xCore CLI, file ops, code generation
v0.3.0-v0.3.20Model switching, config system, streaming, session save/load
v0.3.21-v0.3.25Web search, browser use, website fetching, caching
v0.3.40-v0.3.41Authenticated browsing, credential encryption, session cookies
v0.3.60-v0.3.80DOM browser automation, document readers, multi-provider support
v0.4.0Memory, sub-agents, planner, token budget, skills, hooks
v0.5.0Dream, compaction, vim, voice, buddy, cron, plugins, LSP, rewind
v0.5.1Plan mode AI tools (enter/exit_plan_mode)
v0.5.2Dream auto-trigger wired into chat loop

Design Principles

  1. Safety First — Confirmation prompts, hook-based safety warnings, overwrite protection
  2. Automatic by Default — Hooks, compaction, dream, token budget all fire without user action
  3. User Control — 25+ slash commands for manual override when needed
  4. Transparent — Token tracking, cost visibility, /hooks and /budget status commands
  5. Extensible — Skills (YAML), plugins (Python), hooks (programmatic) for customization
  6. Context Aware — Memory persistence, plan state, conversation history across turns

Maintained by: Yiqiao Yin (yiqiao.yin@wyn-associates.com)