Commit Graph

80 Commits

Author SHA1 Message Date
Levi Neely b65fc0fdf7 execute: add jq, expect, bc support
jq: filter as positional arg, file args appended, pipeline-safe.
expect: pipes script via printf '%s' $'...' | expect -.
bc: pipes via printf '%s' $'...' | bc -ql (quiet + math library).
All three use ANSI-C quoting consistently.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-14 13:25:43 +02:00
Levi Neely 9ec58b0ae8 execute: add sed and ed support; refactor detectLanguage to use shebang basename
sed: sed -e $'...' inline, file args appended, pipeline-safe.
ed: pipes script via printf '%s' $'...' | ed -s [file].
detectLanguage now parses shebang command basename rather than
using strings.Contains, fixing potential false matches.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-14 13:18:08 +02:00
Levi Neely 2ecdcc26c8 execute: add awk support via gawk -e; file args passed after --
Uses gawk -e $'...' (ANSI-C quoting) consistently across Execute() and
pipelines. injectArgs for awk produces a bash snippet with file args
after --. No BEGIN block hacks needed.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-14 13:15:27 +02:00
Levi Neely 3f0a77619b execute: add perl support (shebang detection, @ARGV injection, pipe support)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-14 13:07:03 +02:00
Levi Neely e5e94e57fe agent: inject shell tool descriptions into system prompt at build time
toolsSummary() scans OLLIE_TOOLS_PATH for # description: and # Args:
headers and injects the result as {{.Tools}} in the system prompt —
same effect as MCP schema injection but for shell/python tools.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-14 13:00:03 +02:00
Levi Neely ac77e11afa remove built-in memory and task tool servers
Delegate memory and task to MCP servers (denote-mcp, 9beads-mcp or
equivalents). When no MCP server provides these tools, the model
degrades gracefully — files in ollie/m and ollie/pl remain accessible
via file_* and execute_code. reasoning_think and file_* stay built-in.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-14 08:37:26 +02:00
Levi Neely ae3fc3be78 refactor: split memory and task out of reasoning into own packages
- pkg/tools/memory: memory_remember + memory_recall with FlatDirBackend
  baked in (no more injectable MemoryBackend abstraction)
- pkg/tools/task: task_plan + task_complete with file-based plan
  persistence baked in (no more injectable PlanBackend abstraction)
- pkg/tools/reasoning: stripped to reasoning_think only
- pkg/tools/tools: remove PlanStep/PlanBackend/MemoryBackend interfaces
- pkg/agent: remove dispatchMemoryBackend, dispatchPlanBackend,
  WithFallbackPlanBackend; BuildAgentEnv takes no options

Fixes infinite recursion crash: previously dispatchMemoryBackend routed
memory_recall back to the reasoning server that owned it, causing
unbounded mutual recursion and a goroutine stack overflow.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-14 08:14:41 +02:00
Levi Neely 2d122c70dd gate file tools with sandbox path checks
file_read, file_write, file_edit, file_grep, and file_glob now check
paths against the sandbox config before operating. Same policy that
landrun enforces on execute_code, applied at the application level.

- Add sandbox.LoadMerged: loads base config + named layer, graceful
  fallback if layer missing. Replaces duplicated logic in execute.
- Add sandbox.CheckPath: resolves symlinks, expands templates, checks
  path against allowed entries (RO/ROX for read, RW/RWX for write).
- file.Server.checkAccess wires the check into every file dispatch.
2026-04-13 18:37:17 +02:00
Levi Neely 809ad3472d rename workdir to cwd
Go API: WorkDir→CWD, SetWorkDir→SetCWD, WorkDirSetter→CWDSetter.
Unexported: workdir→cwd in fields, params, locals.
Docs: README.md updated.
2026-04-13 18:03:20 +02:00
Levi Neely a035913514 fix: only use json wire field for JSON objects in tool results
Bare JSON scalars (0, true, null, "string") and arrays pass
json.Valid() but the Kiro API rejects them in the json field with
ValidationException. Once such a tool result is in session history,
every subsequent request fails, making the session unrecoverable.

Restrict the json path to content starting with '{' so only actual
JSON objects are sent that way; everything else uses the text field.
2026-04-13 16:21:45 +02:00
Levi Neely bebe3014fc rename workdir to cwd
Rename the user-facing 9P file and session key from "workdir" to
"cwd" for consistency with the /cwd command.
2026-04-13 15:51:48 +02:00
Levi Neely 2273f0e867 agent: drop empty input in Submit 2026-04-13 15:46:25 +02:00
Levi Neely aa32d17e81 backend: add Backends() listing supported backend names 2026-04-13 14:45:14 +02:00
Levi Neely 269c3eacd5 agent: add SetSessionID for session rename support
- Add SetSessionID to Core interface and agentCore implementation
- Renames persisted .json and .compaction.jsonl files on disk
- Propagates OLLIE_SESSION_ID env var to execute server
- Add /kill and /rn to /help output
2026-04-13 14:25:47 +02:00
Levi Neely dace96ce5b core: guard /model writes while agent is running 2026-04-13 13:34:13 +02:00
Levi Neely adb4b3c46f core: guard state-mutating commands while agent is running
/backend, /agent, /compact, and /clear now return an error if
the agent loop is active. These commands replace pointers or
mutate session state that the running loop holds by copy or
reference, leading to silent failures or races.
2026-04-13 13:29:46 +02:00
Levi Neely 46cd8e9a66 reasoning_plan: make tool description backend-agnostic
Strip flatfs-specific lifecycle instructions (filenames, sed, mv)
from the reasoning_plan tool description. The abstract tool now
describes only generic state transitions; concrete backends supply
their own instructions via CreatePlan response messages.
2026-04-13 13:05:04 +02:00
Levi Neely d705eb520e plan prompt: document __todo/__wip/__done lifecycle and listing patterns 2026-04-13 12:01:36 +02:00
Levi Neely 47133b1ccd flat planning repo built-in 2026-04-13 11:41:01 +02:00
Levi Neely e5a3c8cfc9 usage: drop TotalResponses, accumulate requests only 2026-04-13 11:06:29 +02:00
Levi Neely cf604bd38f usage: track responses, estimate tokens when backend doesn't report 2026-04-13 11:03:39 +02:00
Levi Neely 0429c590af usage/ctxsz: separate billed tokens from context size
- Rename Core.Usage() to Core.CtxSz() (estimated context size)
- New Core.Usage() returns billed token counts (in, out, requests)
- 9P: add ctxsz file, usage file now returns billed tokens
- /context command now shows context size summary
- Emacs mode-line reads ctxsz instead of usage
2026-04-13 10:45:45 +02:00
Levi Neely a1acf0d936 core: update default tools path to ~/.config/ollie/tools
- OLLIE_TOOLS_PATH now takes first entry if colon-separated
- Default changed from ~/.local/share/ollie/tools to ~/.config/ollie/tools
- Update README accordingly
2026-04-13 10:25:18 +02:00
Levi Neely 6b8cd7afee add /skills and /tools slash commands 2026-04-13 09:53:27 +02:00
Levi Neely 7ebd809817 improve /backend and command handling: show current backend with no args, emit blank info events before command output 2026-04-13 09:50:32 +02:00
Levi Neely 4786866e66 fix: strip inline comments in env file parser, fix backtick syntax errors
loadEnvFile now strips " # ..." suffixes from values so inline comments
in ~/.config/ollie/env don't leak into environment variables.  Also add
kiro to the supported-backends error message and fix two raw-string
backtick escaping errors in tool descriptions.
2026-04-13 09:32:56 +02:00
Levi Neely f9918525d5 refactor: improve tool prompts for consistency and clarity
- Standardize all tool description format
- Add usage guidelines and examples
- Clarify tool-specific behaviors and limitations
- Include cross-references between related tools
- Add security warnings for execute_code
- Provide concrete examples for complex tools
- Ensure prompts match actual implementations

File tools:
- file_read: clarify limits (8MB, 2000 lines/chars), diff format
- file_write: simplify, emphasize read-before-write
- file_edit: explain uniqueness and diff format handling
- file_grep: add ripgrep syntax guidance and examples
- file_glob: add pattern examples, clarify sorting

Execute tools:
- execute_code: add security warnings, examples
- execute_tool: clarify tool discovery and usage
- execute_pipe: explain structure with examples

Reasoning tools:
- reasoning_plan: restructure for clarity, add when-to-plan
- reasoning_think: expand usage scenarios
- memory_remember: structure requirements with examples
- memory_recall: clarify search scope (titles/tags only)
2026-04-12 21:20:38 +02:00
Levi Neely 496087a874 tools/file: output diff format (context=bare, new=+, changes=unified diff)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-12 20:39:42 +02:00
Levi Neely 5efcafa9a6 tools/file: rename tools to file_read/write/edit/grep/glob
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-12 20:22:49 +02:00
Levi Neely c47c1ea84c agent: /model with no args shows current model
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-12 20:20:43 +02:00
Levi Neely c1e5fceda6 tools/file: port Read, Write, Edit, Grep, Glob from goq
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-12 20:18:59 +02:00
Levi Neely 345ec744d0 remove dead code 2026-04-12 20:05:52 +02:00
Levi Neely 1b44244f81 cleanup tools 2026-04-12 16:26:50 +02:00
Levi Neely 41fa92f544 agent: add pluggable memory backend with flat-dir fallback
Introduces memory_remember and memory_recall built-in tools on the
reasoning server. A MemoryBackend interface allows swapping backends:
dispatchMemoryBackend routes through a registered MCP server (e.g.
denote-mcp) when available; FlatDirBackend writes dated markdown files
to ~/.local/share/ollie/memory/ as a zero-config fallback.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-11 23:26:26 +02:00
Levi Neely ae82e0eff0 agent: inject mid-turn prompts at tool boundaries instead of queueing
- Submit routes to Inject when a turn is already running, keeping the
  routing decision in core rather than the frontend or 9p layer
- Inject no longer cancels the current action; the pending prompt is
  stored and consumed at the next tool result boundary (success or
  failure), matching goq interrupt semantics
- If an inject is already pending, fall back to the FIFO so nothing is
  lost; /irw (interrupt-rewrite) explicitly overwrites the pending inject
- PopInject is now called after every tool result, not just the last one
- Injected prompts are echoed to the chat via the running turn's output

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-11 22:25:37 +02:00
Levi Neely b194968851 agent: fix reply never being set — commit on run completion not newline event
The newline event is emitted via handler() directly, not through
loopcfg.Output, so the Output-based newline case never fired.
Commit replyBuf to s.reply alongside the state="idle" transition.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-11 18:06:08 +02:00
Levi Neely edad6472c8 agent: initialize state to "idle" in NewAgentCore
Zero value was "" causing IsIdle() to return false on fresh sessions.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-11 18:05:21 +02:00
Levi Neely 9990ceb444 agent: expose State, Reply, AgentName, BackendName, ModelName on Core
Frontends no longer need to shadow these in their own structs; they can
read authoritative values directly through the Core interface.

State and reply tracking moves into agentCore: state transitions on
call/tool events, reply resets and accumulates per-turn in Submit's
Output func. This also fixes a bug where reply accumulated across all
queue-drained turns instead of reflecting only the most recent one.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-11 17:55:25 +02:00
Levi Neely 93e49e9f6f emit user event from Submit; strengthen no-echo-tool rule
- Submit now emits Event{Role:"user"} before each turn so queued prompts
  appear in the chat log via the normal event path, not just direct
  appendChat calls from the 9p prompt handler
- Strengthen system prompt rule against using execute_code/echo as a
  communication mechanism

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-11 17:37:10 +02:00
Levi Neely 8142f5096e agent: yield after queue-based planning; extend PlanBackend interface
PlanBackend.CreatePlan now returns an optional message alongside IDs.
When non-empty, the reasoning server uses it as the tool response
instead of the default plan summary — allowing queue backends to
instruct the agent to stop after planning rather than execute directly.

- tools.PlanBackend: CreatePlan returns ([]string, string, error)
- dispatchPlanBackend: returns "" (agent continues as before)
- reasoning/server: uses backend message when non-empty

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-11 17:24:12 +02:00
Levi Neely 1ac68c2ac1 agent: queue-based reasoning_plan fallback; add default-nobeads agent
- BuildAgentEnv accepts WithFallbackPlanBackend option; wired when
  task_create is absent (task backend takes priority when present)
- reasoning_plan description updated to reflect queue fallback
- agents/default-nobeads.json: copy of default without 9beads MCP

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-11 16:58:34 +02:00
Levi Neely 3d02de4a71 tools: add Python support; document tools in system prompt
- Detect language from shebang (bash default, python3 if shebang contains "python")
- Inject args language-appropriately: set -- for bash, sys.argv for Python
- Add python3 to executor language switch
- Handle Python steps in execute_pipe using bash $'...' embedding
- Update execute_tool description to mention supported languages
- Add Tools section to SYSTEM_PROMPT.md pointing to $OLLIE_9MOUNT/t/

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-11 16:33:57 +02:00
Levi Neely 7d6692183e tools: remove stale discover_skill.sh example from execute_tool schema
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-11 16:25:51 +02:00
Levi Neely 4b9b03053f tools: remove file_read and file_write in favor of shell tools
The line-range patching interface was fragile (models drift on line
numbers), and both tools were redundant with execute_code + standard
shell utilities (cat, grep, sed, ed, ssam). Drop the file server
entirely; update agent configs, system prompt, and documentation.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-11 16:11:50 +02:00
Levi Neely e2d973fe3f Remove agent stalled feature
Remove MaxSteps limit and associated stalled event emission.
The agent will now run indefinitely until completion or interruption,
eliminating the annoying 'agent stalled' messages.
2026-04-11 15:51:39 +02:00
Levi Neely 5e08beb9bf agent: add dynamic workdir support via /cwd command and SetWorkDir API
- Add WorkDirSetter interface to pkg/tools so servers can receive workdir updates
- Add SetWorkDir on execute.Server with RWMutex-guarded workdir field
- Add WorkDir()/SetWorkDir() to the Core interface and agentCore
- Store agentPrompt in AgentEnv/agentCore so system prompt can be rebuilt on workdir change
- Add /cwd [path] slash command (no args shows current dir, arg changes it)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-11 14:21:34 +02:00
Levi Neely c871ecabfe mcp: fix hang on notifications/initialized
Call() blocks on sc.Scan() waiting for a response that spec-compliant
servers must not send. Add Notify() for fire-and-forget messages and
use it for notifications/initialized.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-11 12:00:27 +02:00
Levi Neely 7fa952c59f agent: add reasoning_plan, task backend integration, and /mcp command
- Add reasoning_plan built-in tool: decomposes goals into ordered steps
  with dependency edges; persists to task backend when available, falls
  back to in-context plan otherwise.
- Add PlanBackend/PlanBackendSetter interfaces and PlanStep type to
  pkg/tools; add GetServer to Dispatcher.
- Add dispatchPlanBackend in pkg/agent: routes task_create calls through
  the dispatcher to any registered task MCP server.
- BuildAgentEnv auto-wires the task backend to the reasoning server after
  connecting MCP servers; re-wires on every /agent switch.
- Add ListServers() to Core interface: groups all registered tools by
  server, returns formatted text.
- Add /mcp command to handleCommand(); update /help.
- Add doc/PLANNING.md and update ARCHITECTURE.md.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-11 11:31:41 +02:00
Levi Neely b77aefbe1e agent: add PromptFIFO unit tests
Tests cover FIFO ordering, empty-pop behaviour, and concurrent push safety.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-11 10:03:47 +02:00
Levi Neely 7b90a459d1 agent: add /usage command, Usage() and ListModels() on Core 2026-04-10 20:37:21 +02:00