Commit Graph

111 Commits

Author SHA1 Message Date
Levi Neely 0cefd03e9a update kde submodule; session/fs changes 2026-08-05 17:52:26 +02:00
Ollie Agent 09d5462445 fs: remove dead switch cases from writeAgentCtl and writeAgentCfg
Remove no-op cases that did nothing but carry stale comments:
- ctl: backend (selection via cfg instead)
- ctl: skills (handled elsewhere)
- cfg: backend, model
2026-08-04 21:33:18 +02:00
Ollie Agent 5a946a6729 fs: wire up compact/clear ctl commands through HandleCommand
prompts: remove session operational model (9P/DBus prompt blocks)

compact and clear were dead-code comments in writeAgentCtl. Wire them
through agent.HandleCommand so they actually execute. Fix context: use
ctx.Session.Ctx() instead of context.Background() for proper lifecycle
cancellation.

Delete session_9p.md and session_dbus.md — no longer referenced.
2026-08-04 21:32:26 +02:00
Levi Neely 853117758c fs: add trailing newlines to all static read/request handlers
POSIX compliance - text files should end with newlines.

Fixed handlers:
- requestComplete, requestGenerate, requestRoute
- readSessionName, readSessionID
- readAgentCost, readAgentSystemprompt, readAgentName, readAgentID
2026-08-04 17:27:32 +02:00
Levi Neely d200fbad05 refactor: promote remote to session level
- CreateEmpty(name, remote) now spawns remote toolsrv when remote is set
- requestSessionNew parses remote= argument
- Add Session.SetRemote() method
- Update kde submodule
2026-08-04 15:22:18 +02:00
Levi Neely e1b732f09a fix: wire up agent state change events to event bus
SetOnStateChange was defined but never called. Now agents publish
state changes to 'session.{sid}.agent.{aid}.state' which eventwait
can receive.
2026-08-04 14:40:30 +02:00
Levi Neely f21cd99845 fix: eventwait should use BlockOnce, not Stream
eventwait returns a single event then closes, like statewait.
Stream is for continuous data like chat.
2026-08-04 14:39:26 +02:00
Levi Neely f348b968a2 fix: wire up event handler so chat stream receives events
After the fs/session refactor, NewEventHandler was defined but never
called. Agents created via session restore or CreateAgent had nil
output handlers, so emit() was a no-op and the chat stream stayed empty.

- Add Agent.SetOutput() to allow setting the event handler post-creation
- Wire up SetOutput(NewEventHandler(al)) in fs/newroot.go for restored sessions
- Wire up SetOutput(NewEventHandler(al)) in fs/handlers.go for new agents
- Also includes expanded UsageStats fields and TaskState persistence
2026-08-04 14:21:45 +02:00
Levi Neely b1c74d3121 refactor: remove fs/persist.go, inline calls to session package
- Delete fs/persist.go (thin wrappers no longer needed)
- handlers.go: call session.PersistSession() directly
- newroot.go: inline restore logic with AgentLog creation
2026-08-04 14:03:23 +02:00
Levi Neely 4ae1584887 refactor: move persistence to session/, support multi-agent sessions
session/persist.go:
- New multi-agent format: PersistedSession with []PersistedAgent
- PersistSession saves ALL agents, not just first
- RestoreAllSessions returns []RestoredSession with []RestoredAgent
- Backward compatible: restores legacy single-agent format

fs/persist.go:
- Thin wrapper that creates AgentLogs for each restored agent
- Delegates to session.PersistSession/RestoreAllSessions

agent/agent.go:
- Added Messages() to get conversation history
- Added Usage() to get token/cost stats

agent/history.go:
- Added RestoreHistoryFromMessages for multi-agent restore

session/session.go:
- Added Remote() getter
2026-08-04 14:02:15 +02:00
Levi Neely 7fc183c5cb refactor: eliminate Manager type, use package-level session registry
- session/registry.go: package-level vars + functions replace Manager struct
- session.Init() initializes package config
- session.Sessions(), Lookup(), Register(), Kill(), Rename() etc are now top-level
- fs/ calls session.X() directly instead of rs.Manager.X()
- Same thread safety via package-level sync.RWMutex
2026-08-04 13:55:45 +02:00
Levi Neely 2aa7db8445 refactor: split fs/ and session/ packages
session/ now owns all session business logic:
- Manager: session lifecycle (create, kill, rename, lookup)
- CreateAgent: agent creation within sessions
- SetupToolServer, BuildPromptLayers, LoadAutoLoadTools
- PublishEvent for SSE notifications
- NextUname generation

fs/ is now a thin 9P presentation layer:
- SessionNode wraps session.Session, adds AgentLogs and models cache
- RootState caches SessionNodes (GetOrCreateNode pattern)
- Handlers delegate to session.Manager
- persist.go uses session package for restore logic
2026-08-04 13:52:28 +02:00
Levi Neely 757d81a4ba fs: pass sessID and uname to LoadAutoLoadTools for tool server env setup 2026-08-04 13:21:37 +02:00
Levi Neely bf80a63e8a fs: extract session setup, remove dead code and adapter
- Extract SetupToolServer, BuildPromptLayers, LoadAutoLoadTools into setup.go
- Deduplicate session infrastructure setup between CreateAgent and restoreSession
- Delete adapter.go, move HandlerCtx and type aliases into spec.go
- Delete session.go (only contained unused Get/All functions)
- Remove unused: GlobalRootState, PostEvent, LookupByUname, AddSession,
  CreateAgentFromRoot, KillFromRoot, RenameFromRoot, Session.Interrupt,
  Session.SetDisallowTools, Session.RunnableID
- Replace RunnableID() calls with ID()
- Remove comment banners

Net: -131 lines, better DRY compliance
2026-08-04 13:04:31 +02:00
Levi Neely 1f173f1b41 fs: delete redundant tree_test.go (covered by fsedsl) 2026-08-04 12:52:02 +02:00
Levi Neely aaacae40a8 fs: simplify adapter to type aliases only
- Remove wrapper functions from adapter.go (212 → 91 lines)
- Delete redundant adapter_test.go (fsedsl has 94.8% coverage)
- Add local function aliases in spec.go for clean EDSL usage
- Update handlers.go, newroot.go, tree_test.go to use fsedsl directly
- Update fsedsl README with cleaner integration pattern
2026-08-04 12:47:17 +02:00
Levi Neely 19e255c869 fs: remove unnecessary type parameters where inference works
Go can infer [HandlerCtx] from function argument types. Only DirNode
needs explicit type parameter since its args are ...any.
2026-08-04 12:35:50 +02:00
Levi Neely ae6b833d1e fsedsl: remove Adapter, use generic functions directly
The Adapter was pure boilerplate - every method just delegated to the
package-level generic function. Removing it simplifies the API:

- Delete fsedsl/adapter.go
- Update fs/adapter.go to call fsedsl functions directly
- Update README.md to document direct usage
- Remove adapter tests (now redundant)

Coverage remains at 94.8%.
2026-08-04 12:33:03 +02:00
Levi Neely 2c8cbe23ca Rename fs/edsl_test.go -> fs/adapter_test.go 2026-08-04 12:15:43 +02:00
Levi Neely 94d0c18b01 Rename fs/edsl.go -> fs/adapter.go
The file builds an fsedsl adapter - the name should reflect that.
2026-08-04 12:07:40 +02:00
Levi Neely 6c232c7bb7 Add explicit Adapter pattern to fsedsl
- Add Adapter[Ctx] type that provides all EDSL methods specialized for a context type
- NewAdapter[Ctx]() creates an adapter instance
- Update ollie/fs/edsl.go to use the adapter explicitly
- Update README with adapter-based examples

The adapter makes it explicit that we're building a type-specialized
interface to the generic EDSL library.
2026-08-04 12:06:44 +02:00
Levi Neely b1802ca28c Remove dead code: unused BlockFn type and deprecated BindTarget constants 2026-08-04 12:03:56 +02:00
Levi Neely 882fc598d4 Extract EDSL to fsedsl/ library
- Create fsedsl/ as embedded library with generic types:
  - FsNodeDecl[Ctx], Binding[Ctx], NodeOption[Ctx]
  - BuildTree[Ctx], GenerateHelp[Ctx]
  - Tree, File, FileConfig, SyntheticFileInfo

- Update ollie/fs to use fsedsl via type aliases:
  - type FsNodeDecl = fsedsl.FsNodeDecl[HandlerCtx]
  - Wrapper functions for constructors and options

- Migrate binding functions to Applier pattern:
  - Binding.Applier replaces direct field assignment
  - Cleanly separates EDSL mechanics from domain types

- Add replace directive in go.mod for local module

The library can be extracted to a separate repo later by
changing the module path and removing the replace directive.
2026-08-04 12:02:32 +02:00
Levi Neely 3a1c16878f fs: generate /help dynamically from Doc() strings
Add self-documenting filesystem:
- Doc() option on FsNodeDecl for human-readable descriptions
- /help now generated from spec at runtime, not loaded from file
- Every file/directory in spec.go has documentation

Also fix file-template Each nodes:
- Each without children but with Read/Write creates files, not dirs
- Update validator, listDir, statDir to recognize file templates
- Fix elevate/{reqid} and proc/{pid} to use file-template pattern
2026-08-04 11:43:14 +02:00
Levi Neely 0fa9dd5694 fs: remove comment banners
The code structure is self-evident. Banners add noise without value.
2026-08-04 11:32:09 +02:00
Levi Neely 6ea5b54940 fs: add comprehensive documentation to all file nodes
Add Doc() EDSL option and Desc field to FsNodeDecl for self-documenting
filesystem specification. Every file and directory now has a human-readable
description explaining its purpose, format, and usage.

Documentation covers:
- Root-level files (backends, models, agents, tools, ctl, etc.)
- Elevate broker (policy, pending requests)
- Session management (new, idx, per-session files)
- Agent management (prompt, chat, state, config, tools, proc)

This makes spec.go the single source of truth for both structure and
documentation. The Desc field can be used to generate help text or
API documentation programmatically.
2026-08-04 11:30:19 +02:00
Levi Neely b47792d8be fs: restructure package into logical files
Split fs/ package for better organization:
- edsl.go: EDSL types and constructors (HandlerCtx, FsNodeDecl, Binding, etc.)
- cache.go: ModelCache for backend model list caching
- file.go: File/FileTree interfaces (renamed from fs.go)
- handlers.go: all handler functions (extracted from spec.go)
- spec.go: filesystem declaration only

Renames:
- fsnode.go -> edsl.go (consolidated EDSL types)
- fs.go -> file.go (clearer name)
- each_test.go -> edsl_test.go
- fs_test.go -> tree_test.go, renamed TestFlatDir* -> TestTree*

Exports for potential future use:
- RootState (was rootState)
- GlobalRootState() getter
- BuildIndex() (was buildIndex)
2026-08-04 11:27:28 +02:00
Levi Neely ad286834f4 fix template names: {sname} and {aname}
The primary directory name comes from Instance.Name (session/agent name),
not the ID. The ID is just an alias for lookup.
2026-08-04 10:48:46 +02:00
Levi Neely 013d894ad8 rename Dynamic → Each
Each says exactly what it does: for each item in a collection,
create this directory structure.

DirNode, FileNode, Each - the EDSL is now clear and declarative.
2026-08-04 10:47:58 +02:00
Levi Neely 7c6dff4a01 rename EDSL constructors for clarity
- Leaf → FileNode (file node)
- Dir → DirNode (directory node)
- Blueprint → Dynamic (state-dependent directory)

The names now clearly indicate what they create:
- FileNode: a file
- DirNode: a directory
- Dynamic: a directory whose children depend on runtime state
2026-08-04 10:45:28 +02:00
Levi Neely 99e88ef407 add Blueprint pattern unit tests
Test coverage for:
- Basic Blueprint: structure declaration, instance resolution, aliases
- Nested Blueprints: session/{id}/agent/{aid} pattern
- Context propagation: handlers called with bound context
- UID/GID inheritance: custom vs inherited ownership
- Rename callback: instance rename via Rename func
- Empty instances: graceful handling of no instances
- Mixed static/dynamic: Blueprint alongside static children
- File modes: correct permissions on blueprint files

Also fix validation to accept template nodes with Instances (not just List).
2026-08-04 10:38:56 +02:00
Levi Neely 3a920998bd implement Blueprint pattern for EDSL
New EDSL construct: Blueprint(name, instancesFn, ...children)
- Declares static structure in treeSpec
- InstanceFn returns identity info (name, aliases, UID/GID, data binding)
- Handlers access instance data via ctx.Session/Agent/AgentLog
- No more closure captures for session/agent data

Changes:
- Add Instance type and InstanceFn to fsnode.go
- Add Blueprint() constructor
- Update builder.go to handle blueprint node expansion
- Convert session/{id} to Blueprint with sessionInstances
- Convert agent/{aid} to Blueprint with agentInstances
- Convert all handlers to use ctx fields instead of closures

Benefits:
- Full namespace structure visible in treeSpec at top of spec.go
- Handlers are stateless functions (easier to test/reason about)
- Less memory (no closure allocations per instance)
- Cleaner separation: structure vs data binding vs handlers
2026-08-04 10:35:18 +02:00
Levi Neely b6e2f9048b consolidate fs handlers into spec.go
Single source of truth for the 9P namespace:
- Move rootfiles.go handlers into spec.go
- Move sessionfiles.go (listSessions) into spec.go
- Move agentfiles.go (listAgents) into spec.go
- Move procfiles.go (listProcesses) into spec.go
- Move elevatefiles.go handlers into spec.go

The full namespace structure is now visible in one file with
structure comments documenting the layout of dynamic subtrees.

No functional changes - just reorganization.
2026-08-04 10:24:26 +02:00
Levi Neely 66850e822f cleanup: remove dead code from olliesrv
- Remove unused GroupTable.Remove() method, rename Add to Populate
- Remove unused toolPrompt field from Server struct and Config
- Remove unused ModelCache type alias
- Remove unused toolsrv import
- Flatten if true {} blocks (debugging remnants)
- Convert fcallTypeName switch to map lookup
- Remove unused Tree.Unmount() method

-44 lines
2026-08-04 10:19:12 +02:00
Levi Neely 73de0b3cc0 hierarchical event topics and TCP support
Event topics now follow session hierarchy:
  session.{sid}.new/kill/pause/resume/rename
  session.{sid}.agent.{aid}.new/kill/state

Wildcard routing publishes to all ancestors:
  session.{sid}.agent.{aid}.state publishes to:
    session.{sid}.agent.{aid}.*
    session.{sid}.agent.*
    session.{sid}.*
    session.*
    *

GUI can subscribe to session.{sid}.* to get all events
for one session including its agents.

Also:
- ollie-9p -a flag now supports TCP (host:port or tcp!host:port)
- Add Session.ID() accessor method
2026-08-03 19:10:31 +02:00
Levi Neely 4e817f5de9 replace event ring buffer with pubsub
- Use github.com/simonfxr/pubsub for topic-based event routing
- Topic format: session.{id}.{action}, agent.{id}.{action}
- Wildcard subscriptions: *, session.*, agent.*
- PublishEvent routes to exact topic + wildcards
- WaitEvent maintains backwards compatibility for eventwait
- Add agent.SetOnStateChange callback for state change events
- Extend session/idx format with paused, connected, agent list

Events now published:
- session.{id}.new/kill/pause/resume/rename
- agent.{id}.new/kill/state

This enables efficient selective subscriptions - GUI can subscribe
to specific sessions/agents instead of receiving all events.
2026-08-03 18:48:30 +02:00
Levi Neely 5634123c6d feat: add session connected file for RPC health check
Adds session/{id}/connected file that pings the RPC connection to
determine if the tool server is responsive. Used by GUI to show:
- Green: connected and not paused
- Gray: paused (intentional)
- Red: disconnected/crashed (not paused but connection broken)
- Yellow: zombie (paused but still connected - shouldn't happen)
2026-08-03 18:13:53 +02:00
Levi Neely 8cebf08cbd feat: session pause/resume to reduce resource usage
Adds pause and resume commands to session/ctl:
- pause: stops the tool server process, closes connections
- resume: respawns the process and re-establishes connection

When paused, tool calls return 'connection closed' errors which
propagate to the chat log. Useful for reducing resource usage when
many sessions exist but aren't actively being used.

Also adds session/{id}/paused file to check pause status.
2026-08-03 18:08:09 +02:00
Levi Neely a6ab61cfed fix: session/idx includes sessions with zero agents
buildIndex was skipping sessions where Core != nil but Agents() was empty.
Now empty sessions appear in idx so the GUI can display them as tree nodes.
2026-08-03 17:48:47 +02:00
Levi Neely fa7abc9a99 fix: set Backend on Runtime when creating second agent in session
CreateAgent() was missing rt.Backend = be for the second agent path,
causing nil pointer dereference when /agent command accessed runtime.Backend.
2026-08-03 17:46:11 +02:00
Levi Neely aae307046a fs: ensure tool server on agent creation, retry via keeper
ToolServer is vital infrastructure — it must never be nil. If the
initial dial fails, retry via ProcessKeeper (which respawns
ollie-remote). If still unavailable, fail agent creation with a
clear error asking the user to try again.

Reverted the nil-check band-aid in turn.go — ToolServer is now
guaranteed non-nil for any running agent.
2026-08-03 15:51:23 +02:00
Levi Neely 81e47c8513 fs: add error logging to Kill when session not found in map
Helps trace zombie sessions — if Kill is called with a key that
doesn't match the sessions map, we'll see it in the log.
2026-08-03 12:34:42 +02:00
Levi Neely fe2348c0cc toolsrv: add ProcessKeeper for resilient ollie-remote lifecycle
ProcessKeeper maintains a running ollie-remote process and respawns
it on failure. Multiple agents Dial() the same keeper to get
independent connections. If the process dies, the next Dial()
triggers a respawn (up to 3 attempts with backoff).

All session creation and restore paths now use ProcessKeeper.
Kill/Shutdown close the keeper (which closes the current process).
This fixes 'connection closed' errors persisting indefinitely
after ollie-remote crashes — the next tool call respawns it.
2026-08-03 12:21:54 +02:00
Levi Neely 45f76c3e01 fs: fix elevate broker session lookup by immutable ID
Lookup() was keyed only by display name, but the elevate broker
passes OLLIE_SESSION_ID (the immutable UUID). Added fallback to
search by sess.id when the name-based lookup misses.

This fixes 'elevate-broker: denied (session not found)' for all
elevated commands.
2026-08-03 11:01:01 +02:00
Levi Neely d71e3eb8e4 fs: set agent dir UID to agent ID, GID to 'agent'
Agent directories now have proper ownership: UID is the agent's
immutable 12-char hex identity, GID is 'agent'. Consistent with
session directories which use UID(s.Uname()).
2026-08-03 10:56:20 +02:00
Levi Neely 04e1bfa228 agent: persist uname separately, fix OLLIE_UNAME != OLLIE_SESSION_ID
The agent's 12-char hex uname was not persisted. On restore,
fs/persist.go incorrectly used ps.ID (session UUID) as the uname,
making OLLIE_UNAME identical to OLLIE_SESSION_ID.

Fix: add Uname field to PersistedAgent, persist ag.id in SaveFull,
restore from ps.Uname (falls back to nextUname for old files).
2026-08-03 10:55:50 +02:00
Levi Neely 911733bd8a fs: add agent-level kill, remove activeAgentID from session
Add 'kill' command to agent ctl (removes agent from session).
Add Session.RemoveAgent() method.
Remove activeAgentID field, Agent(), SetActiveAgent, and dead
WaitChange — 'active agent' is a GUI concept, not a server one.
All callers updated to iterate Agents() or use FindAgent(id).
2026-08-03 10:37:29 +02:00
Levi Neely 44f173214d fs: add Aliases to FsNodeDecl for immutable ID path resolution
Nodes in the 9P namespace can now declare alternate names (Aliases)
that resolve during Twalk but are invisible in directory listings.
Session dirs alias their immutable RunnableID(), agent dirs alias
their ID(). Clients can use session/{uuid}/agent/{uuid}/... paths
that remain valid across renames.

Changes:
- fs/fsnode.go: Add Aliases []string field, Alias() NodeOption
- fs/builder.go: findChild checks aliases via matchAlias helper
- fs/sessionfiles.go: Session dirs get Alias(s.RunnableID())
- fs/agentfiles.go: Agent dirs get Alias(a.ID())
- fs/spec.go: Add /aliases file (read-only alias→path table)
- fs/rootfiles.go: readAliases handler
- fs/lifecycle.go: buildIndex includes immutable ID in session/idx
- doc/edsl.md: Document Aliases field and behavior
- prompts: Update session/idx format documentation

The KDE GUI submodule now uses immutable IDs in all 9P paths,
fixing disconnected indicators after session rename.
2026-08-03 09:41:26 +02:00
Ollie Agent bc4c27b602 demote plan from session level to agent level
plan now lives at session/{id}/agent/{aid}/plan instead of
session/{id}/plan. Moved the Leaf declaration from fs/sessionfiles.go
to fs/agentfiles.go. Updated both prompt docs to match.
2026-08-03 01:06:16 +02:00
Ollie Agent 6509bdb5ae streaming tool blocks: always close source fence and emit [[[end]]]
When a streaming tool completes, emit a final empty-Content event so the
log handler always closes the markdown source fence. In the handler,
emit [[[end]]] directly instead of a blank line, so the GUI block parser
transitions back to BlockStart regardless of what follows.
2026-08-03 00:21:48 +02:00