Commit Graph

40 Commits

Author SHA1 Message Date
Levi Neely ced1389549 toolsrv: add 9P-based tool server foundation
New files:
- fs9p.go: FS9P struct with /proc-based execution model
  - /proc/new (rdwr): blocking tool execution
  - /proc/new.bg: background/detached execution
  - /proc/<pid>/out, wait, stat, ctl: process management
  - /tools, /ctl, /info: tool registry and host info
  - Payload format: key=value lines, newline delimited

- exec9p.go: Decoupled tool execution
  - ExecuteTool: standalone function for tool execution
  - executeSandboxed: sandbox execution without Server deps
  - executeBypassDirect: bypass broker without Server deps

- fs9p_test.go: Unit tests for FS9P

Design notes:
- Background execution is the internal model
- Foreground (/proc/new rdwr) blocks until completion
- No per-connection state (cwd/env passed per-call or at attach)
- Session ID scoping via registry, not env propagation

This is the foundation - actual 9P serving and integration pending.
2026-08-10 14:53:13 +02:00
Ollie Agent fbe8059cf5 maintainability: docs, contracts, structural cleanup
- doc/boot-sequence.md: init chain from main → fs.NewRoot → session.Init
- Event protocol: comprehensive table on Event struct (all roles, semantics)
- RPC server moved from cmd/ollie-remote into toolsrv/rpcserver.go
  (binary is now a 93-line thin wrapper)
- SetSessionEnv folded into NewAgent (no post-construction wiring needed)
- AgentCfg → AgentParams (distinguish from AgentConfig JSON schema)
- ToolResult/ToolResultContent shared types in toolsrv/rpcwire.go
- toolsrv/shell.go → toolsrv/exec.go (name matches purpose)
- Resume unified: single path, always through Keeper
- AGENTS.md: fix fs/builder.go → fsedsl/builder.go, handlers_*.go
- fsedsl/Tree: document dual-mode (EDSL lazy vs Manual Mount)
- Truncation stack documented at defaultToolResultMaxBytes
- Integration test rewritten to use srv.ServeRPC directly
2026-08-09 21:45:56 +02:00
Ollie Agent 2d74ffb95e prompt audit: trim system prompt, kill dead code, improve maintainability
- System prompt: ~200 → ~80 lines (removed tool-first table, API docs,
  output protocol, dead 9P entries)
- Removed AllowTools entirely (field, RPC, configs)
- Removed PRIME_* env vars, replaced with typed struct fields
- Merged tool listing + docs into single renderTools()
- Killed BuildToolListing, changed OnToolsChanged to func() signal
- Typed Preamble.Section (compile-time safety)
- Added protocol docs on extractToolResult
- Added session/ package godoc
- Moved output protocol to per-agent prompts
- Rewrote data/agents/README.md
- Moved 7 reference docs from doc/resources/ to doc/
- Deleted PromptEnv() dead function
2026-08-09 14:13:52 +02:00
Ollie Agent 2b4d577e39 refactor: architectural cleanup (5 items)
1. Standardize ctl dispatch: hoist rootCtlHandlers and sessionCtlHandlers
   to package-level vars, matching the agent pattern.

2. Fix error wrapping: %v → %w in toolsrv/shell.go (only 2 instances;
   backend/ was already clean).

3. Canonicalize tool server access: LoadTool now only uses
   session.ToolsConn() — removed fallback to agent.ToolServer().

4. Centralize event handler wiring: wireAgentEvents(sessID, ag, al)
   replaces separate SetOutput + wireAgentStateEvents calls. Documents
   the contract.

5. Split toolsrv/shell.go: validation patterns, ValidateCode, and rate
   limiting moved to shell_validate.go (86 lines). shell.go retains
   execution logic (594 lines).
2026-08-09 12:46:36 +02:00
Ollie Agent 9c90cb8954 refactor: reduce redundancy, remove dead code, improve structure
- Fix CodeWhisperer SetModel cache invalidation bug
- Remove dead code: gemini stub, orphaned comments, kiroMetadataEvent
- Extract paths.NewUUID() replacing 3 duplicate UUID implementations
- Export toolsrv.BuildToolListing, deduplicate tool listing render
- Extract baseBackend struct (Name/Model/SetModel) embedded in all backends
- Unify backend factory post-processing (7 if-blocks → 1)
- Split fs/handlers.go (888 lines) into handlers_{root,session,agent}.go
- Strip dead filesystem-backed tree code from fsedsl (WithReadOnly,
  WithIndex, WithResolver, ValidateReadMode, resolve/writePath fallbacks)
2026-08-09 11:23:25 +02:00
Ollie Agent b2700b6e50 session: remove dead New() constructor and per-session sessionsDir
session.New() had zero callers — all sessions are created via
NewEmpty() + buildAgent(). Remove it along with the Config struct
(20 fields) and the per-session sessionsDir field (always identical
to pkgSessionsDir).

-92 net lines
2026-08-09 01:12:10 +02:00
Ollie Agent 7070e56346 session: remove dead env map (was stored but never read back) 2026-08-09 01:09:46 +02:00
Ollie Agent 5c81eefe0a remove dead code: TaskState subsystem, Verbosity, dead session fields
Remove entire TaskState machinery:
- TaskState struct, render(), taskState()/updateTaskState() on History
- inferTaskStateUpdate() — heuristic plan tracking
- Replan gate (replanGate const, roundsWithoutPlan counter)
- Stall detection (stallThreshold, stallRounds, lastAction)
- Plan reinject (planReinjectInterval, periodic re-injection)
- ReadPlanStep plumbing (AgentCfg → Agent → TurnCtx → loop)

None of this worked in practice — the model ignores the nudges,
ReadPlanStep was never wired to a non-nil value, and TaskState
fields were only populated by inferTaskStateUpdate (which depends
on ReadPlanStep being set).

Compaction now uses plain summary text in the cold zone instead
of serialized TaskState JSON.

Also remove:
- Verbosity field (declared, threaded, never read by any backend)
- DisallowTools (config field never wired to session)
- Session.listHandlers, plan, prevPrompt (never read)
- Config.Output, Config.ListHandlers, Config.ReadPlanStep (never set)

-246 net lines
2026-08-09 01:03:19 +02:00
Ollie Agent 12894027dd session: export immutable fields, extract buildAgent helper
- Export ID, Uname, Ctx, Cancel, Proc, Keeper, Remote as struct fields
  (set-once at creation, not raced during agent loop)
- Keep mutex-protected accessors only for Name, ToolsConn, IsPaused
  which are read/written concurrently
- Extract buildAgent() shared helper used by both CreateAgent and
  restoreMultiAgentSession — eliminates ~100 lines of duplicated
  orchestration (tool server setup, prompt layers, runtime, backend)
- Paused sessions skip tool server entirely during restore (minimal
  agent with just history)
- Update fs/session_node.go delegators for exported fields
- 1638 → 1523 lines (-115)
2026-08-09 00:45:39 +02:00
Ollie Agent 010ad83944 simplify preamble: section-based model, no string surgery
Replace the monolithic preamble string with Preamble struct — an
ordered list of named sections joined on demand. Updates are simple
Set() calls; no marker-based string splicing.

Changes:
- Delete prompts/tool_discovery.md (content already in system_prompt.md)
- Reduce prompts/ package to just the embed + ResolveSystemPrompt
- Replace buildPreamble() with direct section construction
- Replace refreshToolListing() 90-line string surgery with one Set()
- Replace SetCWD string.ReplaceAll with env section rebuild
- Remove RenamePreamble (was a no-op; session ID is a template var)
- Export EnvironmentBlock() for session setup
- All callers use PreambleString() instead of raw string field
2026-08-09 00:32:49 +02:00
Ollie Agent 455434608a all: merge toolsrv files, fix context hierarchy, remove dead params
toolsrv:
- Merge rpc.go into conn.go (wire types already there)
- Merge tools.go + discover.go into registry.go
- Merge accessors.go into server.go
- 4 files eliminated

fs:
- HandlerCtx.Context now carries the session context (set via
  sessionBindings Applier). Previously it was the daemon context
  which never cancels — handlers checking ctx.Done() now properly
  detect session kill/pause.
- Session-scoped blocking handlers (streamAgentChat, blockAgentStateWait)
  merge session context with per-read timeout via mergeCtx(). A session
  kill now immediately unblocks readers without waiting for the 5s timeout.
- Remove redundant manual AfterFunc in blockAgentStateWait.

session:
- Remove unused _ string parameter from WaitEvent
2026-08-08 16:13:55 +02:00
Ollie Agent 5b64d62d2e agent: remove auditLog (was always derived from log)
The audit logger was never a separate destination — it was always
log.Sub("audit"), writing to the same sink with a prefix. The
fallback in NewAgent even warned 'deriving from Log' every time.

Replace ag.auditLog.Debug() calls with ag.log.Debug() directly.
Remove the field, AgentCfg.AuditLog, and all session plumbing.
2026-08-08 15:59:00 +02:00
Ollie Agent 8152dec075 all: delete dead code, tighten API surface
toolsrv:
- Delete WithOnClose, WithOnEnvSet, SetOnExit (dead Options)
- Delete ListDetached, ListDetachedInfo (only ListDetachedRaw used)
- Delete Execute (dead wrapper)
- Delete CWD, ToolRegistry, SessionID, InjectContent (dead accessors)
- Delete ExecuteInSandbox, ExecuteElevated (zero external callers)
- Delete Summaries, RefreshLoaded from Registry (dead)
- Delete DialSSH (alias for RemoteDial)
- Simplify Dial: takes socket string directly, kill Addr/LocalAddr/SSHAddr
- Rename Server receiver e → s
- Unexport context import (no longer needed in tools.go)

session:
- Delete SaveFuncs, AgentAt, AgentCount, NextUncheckedStep
- Delete SetDisallowTools, SaveAllSessions

env:
- Delete Set, Get, All, Format, managed (dead exports)
- Unexport LoadFile → loadFile

fs:
- Delete HandlerCtx.ToolReg, Skills, SaveFn (never read by handlers)
- Delete Config.MkdirAll, Config.SkillsRegistry (dead plumbing)
- Delete AgentLog: Plan, SetPlan, PrevPrompt, Mu, LogInfo, Remote methods
- Delete unused type aliases (NodeOption, FileTree, FileConfig, etc.)

backend:
- Delete ClosePool, PoolStats (dead), New() (dead)
- Delete kiroTokenExpiringSoon standalone func (dead)
- Unexport SharedTransport/SharedClient → sharedTransport/sharedClient

skills:
- Delete entire package (zero importers; feature works via tool scripts)

agent:
- Delete BroadcastChange (dead duplicate of notifyChange)
- Delete HasHistory, ToolCallCount, CompactionModel, SetCompactionModel
- Unexport SetReply, BuildPreamble, DefaultPromptsDir
2026-08-08 15:51:13 +02:00
Ollie Agent 06a996e967 all: replace toolsrv.Runner interface with *toolsrv.Conn
The agent always talks to a *Conn (never a *Server directly).
Replace the Runner interface with the concrete type throughout:

- Runtime.ToolServer is now *toolsrv.Conn
- BuildRuntime takes *toolsrv.Conn
- session.Config, SessionInfra, InfraConfig use *toolsrv.Conn
- All inline type assertions in agent.go deleted — methods called
  directly on *Conn (SetEnv, SetCWD, Close, Detach, ListDetachedRaw,
  SignalDetached, GetDetachedOutput, DismissDetached, SetAllowTools,
  SetOnToolsChanged, Ping, ToolRegistryRevision)
- Added Conn.ToolRegistryRevision() that returns 0 (remote connections
  don't support revision tracking; use push-based OnToolsChanged instead)
- Deleted the Runner interface and its test
- Renamed LoadToolOnRunner → LoadToolOnConn
2026-08-08 15:10:01 +02:00
Ollie Agent 63c4cd6173 all: kill dead code, remove classifier system, clean up names
Dead code removed:
- agent: firstSentence, Checkpoint, WaitForChange, InitCond, cfgDir,
  execServer, SaveTo, SaveFull, saveTo, saveToFull, sanitizeMessages,
  LoadPersistedAgent, RestoreHistory, Restore, PersistedAgent type
- toolsrv: entire tier.go (MemoryTier, MemoryTierArgs, OutputFormat,
  CanParallelize on Server), same methods on Conn
- cmd/ollie-remote: can_parallelize, memory_tier, memory_tier_args RPC
  handlers
- toolsrv/rpc_integration_test: all classifier tests
- fs/lifecycle: state(root) dead helper

Renames:
- session.Session receiver: 'a' → 's' throughout
- SaveSession(path) → Save() (dead parameter removed)
- execServer() eliminated — callers use ag.runtime.ToolServer directly

The agent-package save/restore chain was entirely dead: PersistSession
in session/persist.go reads agent accessors directly and never called
SaveTo/SaveFull.
2026-08-08 14:52:10 +02:00
Ollie Agent 32ff54f708 agent: simplify configuration/instantiation layers
- Kill agentConfig struct. run() takes (*Runtime, TurnCtx, state) directly.
  TurnCtx holds only 7 per-turn closures; stable config reads come from Runtime.

- Lazy tool refresh: toolsNeedRefresh() checks ToolRegistryRevision() on the
  tool server. Skips ListTools IPC when registry hasn't changed. Remote Conn
  falls back to always-refetch (same as before).

- AgentConfig.GenParams() method replaces the 16-line manual field copy in
  BuildRuntime.

- Remove CfgBackend/CfgModel from Runtime. Callers read cfg.Backend/cfg.Model
  directly since they already have the AgentConfig in scope.
2026-08-08 14:19:46 +02:00
Ollie Agent ba740701e2 simplify prompt loading, some renames 2026-08-08 13:29:01 +02:00
Levi Neely 21e46b9895 refactor: consolidate event formatting, remove log validator
- Move FormatEvent to format/ package for reuse by both live handler
  and replay
- Move LoadConfig to agent/ package where it belongs
- Remove log validator (was noisy, not essential)
- Update replay to use FormatEvent for consistent output format
- Update kde submodule with GUI streaming fix
2026-08-07 10:11:48 +02:00
Ollie Agent 2bd6d6f66a Remove OLLIE_*_PATH env vars: paths follow ~/.config/ollie/ convention
- Stripped OLLIE_TOOLS_PATH, OLLIE_AGENTS_PATH, OLLIE_SKILLS_PATH,
  OLLIE_PROMPTS_PATH, OLLIE_MEMORY_PATH, OLLIE_TMP_PATH from managed
  list and defaults in env.go
- ToolsPath(), SkillsPath(), PromptsDirs(), AgentsDirs(), ollieTmpDir()
  now derive from paths.CfgDir()/paths.DataDir() directly
- Removed shell-exec fallback from resolveExecPrompt() — only file
  resolution remains
- Cleaned up env_test.go to match reduced managed set
- Updated stale comments referencing /home/lkn/.config/ollie/tools
2026-08-05 19:37:13 +02:00
Levi Neely 0cefd03e9a update kde submodule; session/fs changes 2026-08-05 17:52:26 +02:00
Levi Neely cfb30de060 session: remove persisted session on kill
Kill is unconditional — a killed session must not be restored
on daemon restart. Call RemovePersistedSession() to delete the
session file from ~/.config/ollie/sessions/active/.
2026-08-05 09:06:29 +02:00
Levi Neely cee5e9fefe remove D-Bus session management, 9P is the only control plane
- Remove OperationalModel function and OpModel prompt layer (dead code)
- Update session-9p.md: remove D-Bus preference mention
- Update desktop file: remove X-DBUS-* entries
- Update systemd service: remove dbus.service dependency
- Rewrite route, process_output, process_signal tools to use 9P

D-Bus is still used for:
- Desktop notifications (org.freedesktop.Notifications) for elevation prompts
- KDE tools (gui_windows, etc.) talking to KWin - not ollie's D-Bus
2026-08-05 08:20:04 +02:00
Levi Neely fbb2a767f6 session: pause/resume persistence, restore paused sessions without spawning processes
- Skip SetupToolServer for paused sessions during restore
- Pause() and Resume() now persist state to disk
- Resume() sets up tool server from scratch for sessions restored paused
- IsConnected() returns false when paused
- Add SetPaused(), SetToolServer() methods
- ProcessKeeper.SetContext() for resume after pause
- Session index sorts active-first, paused-last
- CreateAgent accepts name= parameter
- Remove duplicate SetCwd method
2026-08-04 16:05:22 +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 86f7c54805 refactor: rename saveSession/flushSave to save/flush, remove legacy restore
- Rename AgentCfg.SaveSession/FlushSave to Save/Flush for brevity
- Remove restoreLegacySession — all sessions now use multi-agent format
- Pass Save/Flush callbacks to agents in CreateAgent and restore paths
- Add AuditLog fallback warning in NewAgent
2026-08-04 14:38:09 +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 3cfbd14203 fix: unify session persistence to preserve name on restart
- flushSave and SaveSession now use PersistSession instead of
  agent.SaveFull, ensuring the multi-agent format with Name field
  is consistently written
- Rename now calls PersistSession immediately so renamed sessions
  survive server restart

The previous approach had two save formats (legacy single-agent via
agent.SaveFull, and new multi-agent via PersistSession) writing to
the same file. Since flushSave ran on every turn, it would overwrite
the Name field with the legacy format that didn't preserve it.
2026-08-04 14:11:14 +02:00
Levi Neely 5a9d605840 fix: persist session name correctly
flushSave and SaveSession were passing empty string instead of
a.Name() as the sessionName argument to agent.SaveFull, causing
the session name to be lost on restart.
2026-08-04 14:08:02 +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 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
Ollie Agent 8fc47622c8 Persist renamed sessions and profiles 2026-08-02 22:34:35 +02:00
Ollie Agent 119e673299 fix naming problems 2026-08-02 22:10:00 +02:00
Ollie Agent 9ef397045c session: add multi-agent support by name, not index
- Session.Agent() now looks up activeAgentName in the agents slice
  instead of returning agents[0]. Falls back to first agent if unset.
- Added SetActiveAgent(), FindAgent(), SaveFuncs() methods.
- New() and AddAgent() set activeAgentName automatically.
- CreateAgent: refactored to ADD to existing core session instead
  of overwriting it. If sess.Core exists, builds the new agent via
  agent.NewAgent() and adds it via Core.AddAgent().
- agent/new now lists all agents in the session directory.
- 9P path handlers (rootReaddir/Stat/Open) use FindAgent() and
  AgentLogFor() to resolve agents by name/ID instead of using
  the first agent exclusively.
- Added AgentLogFor(id) to fs Session for per-agent log lookup.
2026-08-01 20:44:47 +02:00
Ollie Agent b1cbb9ca7c session/fs: handle empty sessions during persistence
persistSession: check sess.Core.Agent() != nil before saving.
silently skip sessions with no agent instead of logging
'no active session' error on shutdown.

SaveSession: return nil (no-op) when there are no agents,
rather than returning an error that gets logged.
2026-08-01 20:35:02 +02:00
Ollie Agent 951fdc8133 session: support multiple agents in data structures
- session.Session: r *agent.Agent → agents []*agent.Agent
  - Agent() returns agents[0] for backward compat
  - Added Agents(), AgentAt(), AgentCount(), AddAgent()
  - Close/SetEnv/SetSessionID iterate all agents
  - Other methods use Agent() (primary agent)
- fs/session: AgentLog *AgentLog → AgentLogs map[string]*AgentLog
  - Added AgentLog() (returns first) and SetAgentLog(id, al) methods
  - Updated create.go, persist.go, root.go, olliesrv/server.go
2026-08-01 20:29:23 +02:00
Ollie Agent 7403e1f5bb session: replace timestamp-prefix IDs with UUIDv4; show first segment in acme GUI 2026-08-01 17:26:34 +02:00
Ollie Agent 937e6aef3b update: agent loop, session persistence, 9P filesystem, server, and remote sandbox 2026-08-01 15:06:49 +02:00
Ollie Agent 9b6ddb7df1 flatten: absorb submodules into single Go module
- Remove submodules: core, 9p, acme, httpgw, remote, el
- Keep submodules: kde, webui (separate build systems)
- Collapse core/ packages into root: agent/, backend/, detach/, elevate/,
  env/, log/, paths/, sandbox/, session/, skills/, tools/, toolsrv/
- Collapse 9p/ packages: fs/session/, mount/, dbus/, cmd/olliesrv/
- Move binaries: acme/ → cmd/Ollie/, httpgw/ → cmd/ollie-httpgw/,
  remote/ → cmd/ollie-remote/, 9p/cmd/ollie-9p/ → cmd/ollie-9p/
- Move data: agents/, prompts/, tools/, scripts/, skills/ → contrib/
- Move services/ → contrib/services/, experiments/ → doc/experiments/
- Delete .beads/, .claude/, .kiro
- Single go.mod at root (module ollie)
- Fix all import paths, merge fs/ + session/ packages
- Extract dbus/ and elevate/notify.go from 9p server package
- Update justfile for new paths and single-module build
2026-07-30 18:57:51 +02:00