Commit Graph

141 Commits

Author SHA1 Message Date
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 25924d0909 fs: add /help ctl command — returns command reference 2026-08-09 03:32:21 +02:00
Ollie Agent cbfc08875b fs: unify ctl — all levels use rdwrHandler + rdwrDispatch
Root, session, and agent ctl files all share the same dispatch
mechanism: rdwrHandler map → rdwrDispatch → Request (rdwr).

- ctlHandler/ctlDispatch (write-only) removed
- Root and session ctl upgraded to Request (rdwr), return 'ok'
- systemprompt moved to agent ctl command
- nopRead removed (dead)
2026-08-09 02:58:09 +02:00
Ollie Agent 0025003aa0 fs: refactor agent ctl to map-based dispatch
Replace switch statement with rdwrHandler map. Each command is a
function value in agentCtlHandlers — easy to extend, test individually,
and introspect.
2026-08-09 02:53:17 +02:00
Ollie Agent 993d5a812a fs: move tools to ctl commands, remove tools file
/tools        — lists loaded tools
/tool_load X  — loads a tool by name

System prompt updated to instruct the agent to use ctl for tool
management instead of writing to a tools file.
2026-08-09 02:52:06 +02:00
Ollie Agent 94088ccc94 fs: move cwd to ctl command, remove cwd file
/cwd returns current directory, /cwd X changes it (with stat check).
One fewer file in the agent namespace.
2026-08-09 02:48:50 +02:00
Ollie Agent 2561e01574 fs: move per-agent models to ctl command, remove models file
/models now lists available models for the agent's backend via ctl.
One fewer file in the agent namespace. The root-level models file
(all backends) remains unchanged.
2026-08-09 02:47:26 +02:00
Ollie Agent c05f4d1ef0 fs: agent ctl becomes rdwr (request-response)
The ctl file is now a Request handler: write a command, read the
response. Commands with no args return current state:

  /model        → prints current model
  /agent        → prints current profile
  /cwd          → prints working directory
  /name         → prints agent name
  /model X      → switches model, returns new model
  /compact      → compacts, returns 'ok'

o ctl now uses 'ollie-9p rdwr' to get the response.
This enables /model (no args) to show the current model from
any frontend.
2026-08-09 02:44:21 +02:00
Ollie Agent a4e5f7c9c5 unify commands: / == o ctl, all operations are ctl commands
The slash prefix in prompts now routes directly to the agent's ctl
file. No special-cased commands in the agent — the ctl handler is the
single command surface:

  /stop, /compact, /clear, /model X, /inject X, /agent X, /cwd X

New ctl commands:
  inject <text>  — overwrites any pending inject (replaces /i and /irw)
  agent <name>   — switch agent profile (moved from commands.go)

Agent methods added: Compact(), Clear(), SwitchProfile() — called by
the ctl handler, testable independently.

HandleCommand is now a thin trampoline: strip /, run 'o ctl <rest>'.
commands.go reduced from 155 to 50 lines.

REPL: / → o ctl, !q/!quit → exit TUI.
2026-08-09 02:40:48 +02:00
Ollie Agent c7aea0db59 rename elevate→bypass throughout
The sandbox escape mechanism is a bypass, not privilege elevation.
The old name caused the agent to confuse it with sudo.

- elevate/ → bypass/ (package, types, tests)
- elevate_notify.go → bypass_notify.go
- Namespace: /elevate → /bypass, session/*/elevate → session/*/bypass
- Tool arg: "elevated" → "bypass"
- Env: OLLIE_ELEVATE_SOCKET → OLLIE_BYPASS_SOCKET
- File: elevate-policy.yaml → bypass-policy.yaml
- All docs, prompts, and scripts updated
2026-08-09 02:22:39 +02:00
Ollie Agent 72db6d900d fs: namespace cleanup — merge and remove dead files
- fifo.in + fifo.out → single fifo (write enqueues, read dequeues)
- cost + usage + ctxsz → single stats (key=value lines)
- Remove connection (no consumers, heartbeat handles it)
- Remove dead prevPrompt field and write (prompt.prev gone from spec)
- Clean AGENT_FILES: remove state, context, tail (all already absent
  from spec, were only in the tab-completion list)
2026-08-09 01:57:41 +02:00
Ollie Agent 744f775eb5 fs: split chat into chat (filtered text) and chat.raw (full markup)
chat — strips [[[...]]] markers and source fences at the byte level.
Partial lines pass through immediately for true streaming. Terminals
and text editors use this.

chat.raw — full block-structured stream with markers and fences.
GUIs that parse blocks (KDE, web) use this.

The TUI no longer pipes through grep (which was line-buffering and
killing char-by-char streaming since Aug 4).

The stripMarkers state machine processes each chunk from the server:
- Complete lines starting with [[[ and ending with ]]] → dropped
- Fence lines (```...) → dropped (open toggles in-fence state)
- Partial lines (no trailing \n) → always emitted immediately
- Everything else → passed through
2026-08-09 01:43:39 +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 68b844bbfa fs: fix cfg display — dereference pointer fields, omit when nil
temperature, topP, topK are *float64/*int pointers. Previously
printed as hex addresses or <nil>. Now shows actual values when
set, omitted when nil.
2026-08-08 16:58:48 +02:00
Ollie Agent f4caf29a35 fs: fix nil panic in sessionBindings — RootState captured at build time
The previous commit (3b83b9d) replaced globalRootState with
ctx.Root.Data.(*RootState), but ctx.Root is nil inside closures
captured by BuildTree (Root is set *after* the tree is built).

Fix: add RootState field to HandlerCtx and create it before BuildTree
so all closures capture the live pointer directly.
2026-08-08 16:17:42 +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 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 3b83b9d373 all: delete dead interfaces, kill globalRootState
- agent: delete 'state' interface (one implementation: *History). run()
  now takes *History directly.
- agent: delete 'backendNamer' interface. resolveCompactionModel takes
  backend.Backend directly.
- fs: delete Shutdown/InterruptAll/Lookup wrappers that took *Tree they
  never used. Callers (olliesrv) now call session.* directly.
- fs: delete globalRootState. sessionBindings uses ctx.Root.Data.(*RootState)
  via the HandlerCtx that was always available.
2026-08-08 14:58:47 +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
Levi Neely 4dd32ce162 fs: split types.go into session_node.go and agent_log.go
- session_node.go: SessionNode wrapper with agent log management and model cache
- agent_log.go: AgentLog with event handler and replay logic
2026-08-07 10:18:24 +02:00
Levi Neely d936ec29a8 format: remove agent dependency from FormatEvent
FormatEvent now takes primitive string arguments instead of agent.Event.
This fixes the dependency direction - format/ should be a leaf package
that agent/, session/, and fs/ depend on, not the other way around.
2026-08-07 10:16:28 +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
Levi Neely 3d9eca97b2 fix: close streaming fence before ending block on call/default events
The event handler was emitting [[[end]]] to close an assistant block
without first closing an open streaming fence (code block). This left
the log in a state where a [[[call:...]]] block appeared nested inside
an unclosed assistant block, triggering a log structure violation.

Now the call and default cases close streamingFence (like the tool case
already did) before writing the [[[end]]] marker.
2026-08-07 09:05:39 +02:00
Ollie Agent c7f1bec71c refactor: extract format package, ctl dispatcher, and log structure validator
- Extract all [[[block]]] formatting constants/helpers into format/format.go
  (EndTag, RoleDelim, ToolDelim, CallDelim, BlockHeader, ParseBlockHeader, IsEndMarker)
- Replace switch/case ctl dispatchers in fs/handlers.go with generic
  ctlDispatch() from new fs/ctl.go
- Add LogValidator state machine to AgentLog enforcing:
  - Every [[[block]]] MUST have an [[[end]]] marker
  - Blocks SHALL NOT be nested
  - Streaming line buffering across partial writes
  - Fatal failure on first violation with line-number reporting
  - UnclosedAtTeardown() for session/agent teardown checks
- Fix kde/kate ollie_ghost compile: stripPrefixEcho signature mismatch
2026-08-07 08:59:07 +02:00
Ollie Agent 7c99d101b1 namespace audit: remove prompt.prev, state, offset, context, tail
- Removed from fs/spec.go: prompt.prev, state, offset, context, tail
- Removed handlers: readAgentPromptPrev, readAgentState, readAgentOffset, readAgentContext, readAgentTail
- statewait still exists but now has an inline read handler
- 5 files out of the namespace; 18 agent-level files remaining
- Reduces each agent dir by 5 entries
2026-08-07 08:19:54 +02:00
Ollie Agent 5ec208c5ea fsedsl: HandlerCtx composes context.Context — no more context.Background() in handlers
- HandlerCtx now embeds context.Context for per-operation cancellation/deadline
- Reverted fsedsl signatures back to simple (ctx Ctx) since context is embedded
- requestGenerate handler uses ctx instead of context.Background()
- cmdInject propagates its context parameter instead of using Background
2026-08-07 07:42:41 +02:00
Ollie Agent 7e29d28848 remove agent/complete.go — completions now go through /generate
- Delete agent/complete.go (110 lines) and its requestComplete handler
- Remove /complete 9P file from fs/spec.go
- Update KDE kate plugin to build the completion prompt inline and call
  ollie-9p rdwr generate instead of ollie-9p rdwr complete
- StripCompletionNoise and stripPrefixEcho moved into C++ helpers
2026-08-07 07:36:58 +02:00
Ollie Agent 97c8bcbb62 fs/spec.go: move GID("agent") to root node, let children inherit
- Removed 19 redundant GID("agent") calls from leaf nodes and subdirectories
- Root DirNode now sets GID once; all descendants inherit via fsedsl resolver
2026-08-07 07:19:24 +02:00
Ollie Agent fc0c368e91 Good idea fairy cleanup: ~960 lines removed
Phase 1:
- agent/hooks.go (entire hooks engine, 237 lines)
- backend/noop.go (unused test backend)
- backend/oneshot.go: Route/RouteRequest/RouteResult + /route 9P file
- cmd/ollie-9p/mount/ (FUSE mount, 336 lines)
- toolsrv/schema.go (ParseToolInfo, zero callers)
- toolsrv/discover.go: ToolPrompt/ReadTool (zero callers)
- agent/commands.go: CompactionSnapshot + history.go: PreCompactionSnapshot
- data/tools/route.meta + justfile route install

Phase 2:
- detach/process.go: stripped Signal(), Cmd field, unused imports
- SignalDetached reimplemented with syscall.Kill directly

24 files changed, 19 insertions, ~980 deletions
2026-08-05 21:51:55 +02:00
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