Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<PackageVersion Include="Microsoft.Extensions.Configuration.Json" Version="10.0.2" />
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="10.0.2" />
<PackageVersion Include="OllamaSharp" Version="5.4.16" />
<PackageVersion Include="Termina" Version="0.5.1" />
</ItemGroup>
<!-- Serialization -->
<ItemGroup>
Expand Down
42 changes: 27 additions & 15 deletions IMPLEMENTATION_PLAN.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,9 @@ Full task breakdowns:

> **Gateway note:** Netclaw.App was temporarily changed from `Microsoft.NET.Sdk.Web`
> to `Microsoft.NET.Sdk` (plain console host) for the proof-of-concept console
> adapter. The web gateway (health endpoints, future API surface) must be
> restored before Slack adapter or any multi-client scenario. Track as part of
> Task 1.11 (CLI scaffold) or earlier if needed.
> adapter. Task 1.11 restores `Microsoft.NET.Sdk.Web` for daemon modes per
> SPEC-011. Single-process architecture validated by research in
> `docs/research/agent-gateway-architecture.md`.

### Task 1.1: Framework protocol and persistence-safe message envelopes (DONE)

Expand Down Expand Up @@ -364,43 +364,52 @@ Done when:
- [ ] CI tests pass without live provider credentials.
- [ ] Tests for provider switching, fallback activation, tool calling round-trip.

### Task 1.11: CLI scaffold with Cocona
### Task 1.11: Daemon architecture scaffold with mode routing

**PRD:** `docs/prd/PRD-004-cli-onboarding-and-config.md` (CLI-010, CLI-012)
**Spec:** `docs/spec/SPEC-011-daemon-architecture.md`
**OpenSpec:** `openspec/specs/netclaw-cli/spec.md`
**OpenSpec Changes:** `openspec/changes/add-tui-adapter-and-config-hot-reload/` (Section 1)
**Surface area:** CLI framework
**Surface area:** CLI framework + gateway
**Verification:** L1
**Previously:** Task 1.13

Replaces the bare console loop with a proper CLI framework. Restore web gateway
hosting (`Microsoft.NET.Sdk.Web`) if needed for daemon mode.
Replaces the bare console loop with mode-selected startup per SPEC-011.
Daemon modes use `WebApplication.CreateBuilder()` (ASP.NET host for SignalR
and health endpoints). Lightweight modes use `Host.CreateApplicationBuilder()`.
Cocona is archived (Dec 2025) — replaced with simple arg routing.

Done when:
- [ ] Cocona and Termina package references added to `Directory.Packages.props` and `Netclaw.App.csproj`.
- [ ] `Program.cs` rewritten as Cocona entry point with DI registration.
- [ ] `RunCommand.cs` created for daemon mode (`netclaw run`).
- [ ] Termina wired as hosted service for TUI commands.
- [ ] Termina and System.Reactive package references added to `Directory.Packages.props`.
- [ ] `Netclaw.App.csproj` SDK changed to `Microsoft.NET.Sdk.Web`, Termina added, Hosting removed.
- [ ] `Program.cs` rewritten with mode routing: `run`/`chat`/headless use `WebApplication`, `init`/`doctor` use `Host`.
- [ ] Shared config services extracted to `ConfigureConfigServices()` method.
- [ ] Daemon-only services extracted to `ConfigureDaemonServices()` method.
- [ ] SignalR hub mapped at `/hub/session` (stub — Phase 1 placeholder).
- [ ] Health probe mapped at `/api/health/ready`.
- [ ] `ConsoleChannel.cs` deleted (replaced by Termina TUI).
- [ ] `dotnet build` passes with new dependencies.

### Task 1.12: TUI chat adapter (`netclaw chat`)

**PRD:** `docs/prd/PRD-004-cli-onboarding-and-config.md` (CLI-011), `docs/prd/PRD-009-input-adapters-and-unified-input.md` (INPUT-005)
**Spec:** `docs/spec/SPEC-011-daemon-architecture.md`
**OpenSpec:** `openspec/specs/netclaw-input-adapters/spec.md`, `openspec/specs/netclaw-cli/spec.md`
**OpenSpec Changes:** `openspec/changes/add-tui-adapter-and-config-hot-reload/` (Section 2)
**Surface area:** TUI + adapter
**Verification:** L3
**Wireframe:** `docs/ui/TUI-001-command-wireframes.md` (netclaw chat)
**Previously:** Task 1.14

The TUI uses `SessionPipeline` directly — no SignalR indirection. Same
in-process pattern as the current ConsoleChannel/HeadlessChannel.

Done when:
- [ ] `TuiInputAdapter` implementing adapter contract (`SendUserMessage` with entity key `tui/{sessionId}`).
- [ ] `ChatCommand.cs` hosts actor system in-process and launches TUI.
- [ ] `ChatPage.cs` with `StreamingTextNode` (scrollable history) and `TextInputNode` (multi-line input).
- [ ] `ChatViewModel.cs` with session lifecycle and broadcast subscription.
- [ ] `ChatViewModel.cs` uses `SessionPipeline` directly via DI — calls `CreateAsync()`, pushes `ChannelInput`, subscribes to `SessionOutput`.
- [ ] Inline tool activity panel (completed with duration, in-progress with spinner).
- [ ] MCP status indicator in status bar (green/yellow/red).
- [ ] E2E: user types → `SendUserMessage` → session actor → LLM → streaming response in TUI.
- [ ] E2E: user types → `ChannelInput` → `SessionPipeline` → session actor → LLM → streaming response in TUI.

---

Expand Down Expand Up @@ -703,3 +712,6 @@ the linked research documents.
- `docs/research/actor-llm-optimization-patterns.md` — Prompt caching,
safety circuit breakers, parallel execution, streaming, retry, and
sub-agent isolation patterns for actor-based LLM systems
- `docs/research/agent-gateway-architecture.md` — Single-process vs
multi-process architecture analysis (OpenClaw, IronClaw, ZeroClaw).
Validates single-process model for homelab/personal agent use.
32 changes: 31 additions & 1 deletion docs/prd/PRD-001-netclaw-mvp.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,37 @@ irrelevant — the differentiator is the instructions attached to the context.
10. Agent can modify its own configuration through conversation.
11. MCP integration provides external memory (Memorizer) and tool capabilities.

## Daemon Architecture

Netclaw runs as a single OS process. All components — Akka actor system,
persistence, gateway endpoints, TUI, and tool execution — share one process
boundary. This is validated by architecture research across comparable projects
(see `docs/research/agent-gateway-architecture.md`).

The executable supports multiple modes selected by command-line arguments:

| Mode | Command | Description |
|------|---------|-------------|
| Daemon | `netclaw run` | Full service stack. Slack, schedules, SignalR hub, health endpoint. |
| Chat | `netclaw chat` | Full service stack + Termina TUI. Interactive chat via `SessionPipeline`. |
| Headless | `netclaw -p "..."` | Full service stack + headless client. Single turn, exits on completion. |
| Init | `netclaw init` | Lightweight. Config services only, no Akka/persistence. Reentrant TUI wizard. |
| Doctor | `netclaw doctor` | Lightweight. Config services only. Health checks and diagnostics. |

In-process channels (TUI, headless) use `SessionPipeline` directly — no network
hop. The SignalR hub exists for future remote clients (Blazor ops console) and
uses the same `SessionPipeline` internally.

Tools execute on the host process. This is the only model that works for Slack
(no client to delegate to), scheduled tasks (autonomous), and Docker deployment
(tools need access to the host's Docker socket).

See `SPEC-011-daemon-architecture.md` for full specification.

## Non-Goals (MVP)

- Multi-process gateway/agent split
- Multi-process gateway/agent split (validated by architecture research —
single-process is the correct model for homelab/personal agent use)
- Ambient channel monitoring with per-channel instructions
- Webhook ingress (Tailscale Serve / Cloudflare Tunnel)
- Sub-agent model routing (cheaper models for high-token tasks)
Expand Down Expand Up @@ -269,3 +297,5 @@ schedule changes → timer reconfiguration).
- Agent Personality and Memory: PRD-007
- Scheduling: PRD-008
- Input Adapters: PRD-009 (post-MVP)
- Daemon Architecture: SPEC-011
- Architecture Research: `docs/research/agent-gateway-architecture.md`
27 changes: 22 additions & 5 deletions docs/prd/PRD-004-cli-onboarding-and-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,34 @@ diagnostics using CLI commands and guided output.

## CLI Framework

- **Cocona** for command routing (lightweight, convention-based, DI integration)
- **Simple arg routing** in `Program.cs` for mode selection (Cocona is archived
as of Dec 2025 — replaced with direct `args[0]` routing)
- **Termina 0.5.1** for interactive TUI commands (`netclaw init`, `netclaw chat`)
- All other commands use plain console output via Cocona
- All other commands use plain console output
- `netclaw run` is the explicit daemon entry point (Slack + timers + health
endpoints, no TUI)
- All CLI modes are in-process — no REST client in Phase 1
- Configuration is privileged local file I/O, never exposed over the wire
(contains API keys/secrets)

## Two-Phase Onboarding

### Phase 1: CLI Wizard (`netclaw init`)

Technical setup, no LLM required:
Technical setup, no LLM required. `netclaw init` runs as a **lightweight mode**
— no Akka actor system, no persistence, no SignalR. Only config services are
booted. Provider testing uses direct DI service calls (`ChatClientFactory`),
not REST endpoints.

1. LLM provider configuration (OpenRouter API key, model selection)
The wizard is **reentrant** — re-running `netclaw init` detects existing config
and shows a section dashboard with status per section. Each section is
independently enterable for modification. First-run guides linearly through
all steps.

Steps:

1. LLM provider configuration (endpoint URL, API key, model selection,
connectivity test via direct HTTP to provider)
2. Slack app setup (bot token, app token for Socket Mode)
3. PostgreSQL connection string
4. ACL bootstrap (owner identity, initial channel rules)
Expand Down Expand Up @@ -175,7 +190,7 @@ Results are persisted to the environment inventory file.

`netclaw init` and `netclaw chat` SHALL use Termina 0.5.1 for interactive TUI
rendering. All other commands SHALL use plain console output. TUI commands SHALL
launch Termina as a hosted service within the Cocona command handler.
launch Termina as a hosted service within the mode-selected host builder.

### CLI-011 Local Chat Adapter

Expand Down Expand Up @@ -219,3 +234,5 @@ rendering. This is the primary production entry point.
- MCP setup: PRD-006
- Memory and personality: PRD-007
- Scheduling: PRD-008
- Daemon architecture: SPEC-011
- TUI wireframes: TUI-001
16 changes: 11 additions & 5 deletions docs/prd/PRD-009-input-adapters-and-unified-input.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ child session actor.
### MVP Input Adapters

**Local TUI Adapter** (Phase 1):
- Hosted in-process by `netclaw chat` command
- Hosted in-process by `netclaw chat` command (daemon mode — full service stack)
- Uses `SessionPipeline` directly — no SignalR indirection for in-process channels
- Receives keyboard input via Termina TextInputNode
- Produces `SendUserMessage` commands with entity key `tui/{sessionId}`
- Subscribes to session broadcasts for reply delivery
- Pushes `ChannelInput` to `SessionPipeline` input sink
- Subscribes to `SessionOutput` source for rendering
- Renders responses as streaming text via StreamingTextNode
- Displays tool invocation status inline (name, duration, spinner)
- Shows MCP server connectivity in status bar
Expand Down Expand Up @@ -75,9 +76,12 @@ child session actor.
- Each webhook hit creates a new session with source-specific instructions

**Web UI Adapter** (Phase 5):
- WebSocket connection from Blazor Server ops console
- Connects via SignalR hub (`/hub/session`) — the gateway surface documented in
SPEC-011
- Provides interactive session control and real-time updates
- Same pub/sub broadcast pattern as Slack adapter
- Same `SessionPipeline` abstraction as all other channels
- SignalR hub is mapped from Phase 1 (for future remote clients) but not used
by TUI or headless modes

## Adapter Contract

Expand Down Expand Up @@ -174,3 +178,5 @@ SHALL display tool invocation status inline between user message and response.
- Security (ACL per source): PRD-002
- Scheduling (timer source): PRD-008
- Ops console (web UI source): PRD-003
- Daemon architecture and gateway surface: SPEC-011
- SessionPipeline and channel abstraction: `src/Netclaw.Actors/Channels/ChannelPipeline.cs`
Loading