How hkuds/openspace works
Purpose and Entry Points
OpenSpace is a local-first skill-management and execution layer for AI agents: it runs tasks, retrieves local/cloud skills, records outcomes, and conditionally evolves skills. Python is the primary runtime; public processes include CLI, MCP server, dashboard API, gateway, and embedded Python API.
• openspace/application.py
• openspace/entrypoints/cli/main.py
• openspace/entrypoints/mcp/server.py
• openspace/entrypoints/dashboard/server.py
Shared Execution Runtime
All invocation surfaces converge on a shared runtime that owns requests, sessions/workspaces, event publication, scheduling, turn execution, and finalization. This is the main control boundary: UI/host adapters submit execution requests rather than implementing agent logic themselves.
• openspace/runtime/app.py
• openspace/runtime/execution_scheduler.py
• openspace/runtime/turn_runner.py
• openspace/runtime/session_runtime.py
Agent and Turn Loop
The agent layer builds context, injects/retrieves skills, calls the configured LLM, interprets tool turns, and applies stop/compaction/session policies. Coordinator and multi-agent modules support delegated/background work. Conversation history, tool results, and task state feed subsequent turns and recoverable sessions.
• openspace/agents/grounding_agent.py
• openspace/agents/turns/loop.py
• openspace/agents/turns/model_call_controller.py
• openspace/agents/coordinator.py
Tool Grounding, Security, and Permissions
A unified grounding client abstracts local and remote tools. Providers cover shell, MCP, GUI/computer use, and web; tool execution is gated by permission engines, shell/path validation, and optional platform sandboxing. This is the safety boundary between model-directed actions and host resources.
• openspace/grounding/core/grounding_client.py
• openspace/grounding/core/tool_executor.py
• openspace/grounding/core/permissions/engine.py
• openspace/services/sandbox/manager.py
Skill Registry, Retrieval, and Persistent Evidence
Skills are discovered from configured directories and represented with stable IDs, safety checks, local metadata, lineage, and quality records. Hybrid ranking selects relevant skills; runtime/tool/session evidence is assembled into packets used for quality decisions and later evolution. Local persistence is SQLite-oriented; project state conventionally lives under .openspace.
• openspace/skill_engine/registry.py
• openspace/skill_engine/skill_ranker.py
• openspace/skill_engine/store.py
• openspace/skill_engine/evidence/packet_builder.py
Controlled Skill Evolution
Post-run analysis detects signals and proposes FIX, DERIVED, or CAPTURED changes. Admission, authoring, validation, behavioral evaluation, and auditing constrain writes; candidates may remain audit-only, and trust/enablement are separate lifecycle controls. Successful evolved skills re-enter the registry and retrieval flow.
• openspace/skill_engine/evolution/engine.py
• openspace/skill_engine/evolution/admission.py
• openspace/skill_engine/evolution/validator.py
• openspace/skill_engine/evolver.py
External Boundaries and Clients
LLM access is centralized behind a LiteLLM-oriented client. Cloud services provide authenticated skill upload/download/search, embeddings, quality/trace telemetry, and redaction; cloud discovery is distinct from local execution/import. MCP supports stdio and network transports; communication gateway adapters connect Feishu and WhatsApp, with the latter including a Node bridge.
• openspace/llm/client.py
• openspace/cloud/client.py
• openspace/grounding/backends/mcp/client.py
• openspace/communication/gateway_runtime.py
User Interfaces
The TypeScript Ink TUI communicates with Python through an NDJSON bridge/protocol and renders streamed runtime events, permissions, transcripts, and background tasks. The separate React/Vite dashboard consumes the dashboard API to browse skill classes, lineage, workflow records, and evolution details.
• apps/tui/src/index.tsx
• apps/tui/src/bridge/protocol.ts
• apps/dashboard/src/main.tsx
• apps/dashboard/src/api/client.ts
Main entry points: app.py Runtime App · loop.py Grounding Agent Loop · turn_runner.py Turn Runner · grounding_client.py Grounding Client
Components 19
Invocation & UI
- Embedded Python API
openspace/application.py - CLI, MCP & Dashboard API · Host-facing adapters submit requests to the shared runtime.
openspace/entrypoints/cli/main.py - Ink TUI Bridge · Streams runtime events and permission interactions to the TypeScript TUI.
apps/tui/src/bridge/protocol.ts - React Dashboard
apps/dashboard/src/main.tsx
Execution Runtime
- Runtime App · Shared request, workspace, event, and finalization boundary.
openspace/runtime/app.py - Execution Scheduler
openspace/runtime/execution_scheduler.py - Turn Runner
openspace/runtime/turn_runner.py - Session Runtime · Maintains recoverable conversations, task state, and tool results.
openspace/runtime/session_runtime.py - Grounding Agent Loop · Builds context, retrieves skills, calls models, and interprets tool turns.
openspace/agents/turns/loop.py - Agent Coordinator · Supports delegated and background agent work.
openspace/agents/coordinator.py - Grounding Client · Unifies local and remote shell, MCP, GUI, and web tools.
openspace/grounding/core/grounding_client.py - Permissions & Sandbox · Gates model-directed host actions with validation and sandboxing.
openspace/grounding/core/permissions/engine.py
Skill Lifecycle
- Skill Registry & Store · Persists discovered skills, IDs, metadata, lineage, and quality records under local project state.
openspace/skill_engine/registry.py - Hybrid Skill Ranker
openspace/skill_engine/skill_ranker.py - Evidence Packets · Assembles runtime, tool, and session evidence for quality decisions.
openspace/skill_engine/evidence/packet_builder.py - Controlled Evolution · Admits, authors, validates, evaluates, and audits proposed skill changes.
openspace/skill_engine/evolution/engine.py
External Boundaries
- LLM Client · Central LiteLLM-oriented model access.
openspace/llm/client.py - Cloud Services · Authenticated skill discovery, embeddings, telemetry, and redaction boundary.
openspace/cloud/client.py - Communication Gateway · Connects Feishu and WhatsApp, including the WhatsApp Node bridge.
openspace/communication/gateway_runtime.py
Connections 23
- Embedded Python API → Runtime App: submits requests
- CLI, MCP & Dashboard API → Runtime App: submits requests
- Ink TUI Bridge → CLI, MCP & Dashboard API: NDJSON requests/events
- React Dashboard → CLI, MCP & Dashboard API: dashboard API
- Communication Gateway → Runtime App: channel tasks
- Runtime App → Execution Scheduler: schedules
- Runtime App → Session Runtime: owns sessions
- Execution Scheduler → Turn Runner: dispatches turns
- Turn Runner → Grounding Agent Loop: runs
- Turn Runner → Session Runtime: reads and records state
- Grounding Agent Loop → Hybrid Skill Ranker: retrieves skills
- Hybrid Skill Ranker → Skill Registry & Store: ranks local skills
- Grounding Agent Loop → LLM Client: model calls
- Grounding Agent Loop → Grounding Client: tool turns
- Grounding Agent Loop → Agent Coordinator: delegates work
- Grounding Client → Permissions & Sandbox: authorizes actions
- Grounding Client → Evidence Packets: tool outcomes
- Session Runtime → Evidence Packets: run context
- Evidence Packets → Controlled Evolution: quality signals
- Controlled Evolution → Skill Registry & Store: validated skills
- Skill Registry & Store → Cloud Services: upload, download & search
- Cloud Services → Hybrid Skill Ranker: cloud discovery
- Runtime App → Ink TUI Bridge: streamed events