ollama_agent 0.3.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (241) hide show
  1. checksums.yaml +4 -4
  2. data/.claude/scheduled_tasks.lock +1 -0
  3. data/.env.example +21 -1
  4. data/CHANGELOG.md +47 -0
  5. data/CONTRIBUTING.md +23 -0
  6. data/README.md +308 -9
  7. data/Rakefile +2 -0
  8. data/config/ollama_agent/owners.yml +53 -0
  9. data/containers/ollama_agent-verification-sandbox.Dockerfile +16 -0
  10. data/db/ollama_agent/migrations/0001_initial.sql +102 -0
  11. data/db/ollama_agent/migrations/0002_cost_ledger.sql +12 -0
  12. data/db/ollama_agent/schema.sql +1 -0
  13. data/docs/CAPABILITIES.md +91 -0
  14. data/docs/CLI.md +212 -0
  15. data/docs/FEATURES.md +1298 -0
  16. data/docs/OPERATIONS.md +179 -0
  17. data/docs/TOOLS.md +104 -1
  18. data/docs/TRADING_AGENT_PLAN.md +88 -0
  19. data/docs/USAGE.md +246 -0
  20. data/docs/agile/docker_spec_activation.md +55 -0
  21. data/docs/agile/release_rollout_runbook.md +125 -0
  22. data/docs/agile/runtime_kernel_backlog.md +173 -0
  23. data/docs/agile/runtime_kernel_risk_register.md +27 -0
  24. data/docs/agile/separate_server_strategy.md +25 -0
  25. data/docs/agile/sprint_0_setup.md +52 -0
  26. data/docs/agile/sprint_execution_map.md +24 -0
  27. data/docs/new_features copy.md +14446 -0
  28. data/docs/new_features.md +11771 -0
  29. data/docs/new_features_plan.md +246 -0
  30. data/docs/new_features_plan_v2.md +223 -0
  31. data/docs/superpowers/plans/2026-05-28-interactive-completion-system.md +697 -0
  32. data/docs/superpowers/plans/2026-05-29-session-runtime-integration.md +966 -0
  33. data/docs/superpowers/specs/2026-05-29-session-runtime-integration-design.md +318 -0
  34. data/docs/trading_agent.md +3180 -0
  35. data/examples/agentic_tool_calling.rb +104 -0
  36. data/lib/ollama_agent/agent/agent_config.rb +23 -2
  37. data/lib/ollama_agent/agent/chat_coordinator.rb +88 -0
  38. data/lib/ollama_agent/agent/client_wiring.rb +3 -8
  39. data/lib/ollama_agent/agent/prompt_wiring.rb +1 -1
  40. data/lib/ollama_agent/agent/session_wiring.rb +36 -6
  41. data/lib/ollama_agent/agent/turn_loop.rb +89 -0
  42. data/lib/ollama_agent/agent.rb +153 -85
  43. data/lib/ollama_agent/agent_root_resolver.rb +23 -0
  44. data/lib/ollama_agent/cli/health_command.rb +45 -0
  45. data/lib/ollama_agent/cli/repl.rb +159 -0
  46. data/lib/ollama_agent/cli/repl_shared.rb +336 -0
  47. data/lib/ollama_agent/cli/skill_command.rb +71 -0
  48. data/lib/ollama_agent/cli/tui_repl.rb +202 -0
  49. data/lib/ollama_agent/cli.rb +149 -53
  50. data/lib/ollama_agent/console.rb +2 -2
  51. data/lib/ollama_agent/context/token_counter.rb +5 -0
  52. data/lib/ollama_agent/core/action_envelope.rb +82 -0
  53. data/lib/ollama_agent/core/budget.rb +90 -0
  54. data/lib/ollama_agent/core/loop_detector.rb +67 -0
  55. data/lib/ollama_agent/core/schema_validator.rb +135 -0
  56. data/lib/ollama_agent/core/trace_logger.rb +140 -0
  57. data/lib/ollama_agent/errors.rb +61 -0
  58. data/lib/ollama_agent/external_agents/default_agents.yml +11 -2
  59. data/lib/ollama_agent/external_agents/path_validator.rb +1 -3
  60. data/lib/ollama_agent/external_agents/probe.rb +56 -8
  61. data/lib/ollama_agent/external_agents/runner.rb +22 -43
  62. data/lib/ollama_agent/external_agents.rb +4 -0
  63. data/lib/ollama_agent/gemma_thought_content_parser.rb +211 -0
  64. data/lib/ollama_agent/indexing/context_packer.rb +140 -0
  65. data/lib/ollama_agent/indexing/diff_summarizer.rb +125 -0
  66. data/lib/ollama_agent/indexing/file_indexer.rb +129 -0
  67. data/lib/ollama_agent/indexing/repo_scanner.rb +158 -0
  68. data/lib/ollama_agent/llm/anthropic_client.rb +263 -0
  69. data/lib/ollama_agent/llm/cloud_fallback_router.rb +111 -0
  70. data/lib/ollama_agent/llm/context_builder.rb +57 -0
  71. data/lib/ollama_agent/llm/first_json_object.rb +41 -0
  72. data/lib/ollama_agent/llm/planner.rb +140 -0
  73. data/lib/ollama_agent/llm/planner_schema.rb +90 -0
  74. data/lib/ollama_agent/llm/think_block_stripper.rb +16 -0
  75. data/lib/ollama_agent/memory/long_term.rb +113 -0
  76. data/lib/ollama_agent/memory/manager.rb +120 -0
  77. data/lib/ollama_agent/memory/session_memory.rb +93 -0
  78. data/lib/ollama_agent/memory/short_term.rb +66 -0
  79. data/lib/ollama_agent/ollama_chat_thinking_stream.rb +25 -0
  80. data/lib/ollama_agent/ollama_cloud_catalog.rb +85 -0
  81. data/lib/ollama_agent/ollama_connection.rb +39 -0
  82. data/lib/ollama_agent/plugins/loader.rb +95 -0
  83. data/lib/ollama_agent/plugins/registry.rb +107 -0
  84. data/lib/ollama_agent/providers/anthropic.rb +261 -0
  85. data/lib/ollama_agent/providers/base.rb +85 -0
  86. data/lib/ollama_agent/providers/credential.rb +156 -0
  87. data/lib/ollama_agent/providers/credential_pool.rb +96 -0
  88. data/lib/ollama_agent/providers/credential_router.rb +130 -0
  89. data/lib/ollama_agent/providers/error_classifier.rb +107 -0
  90. data/lib/ollama_agent/providers/health_monitor.rb +133 -0
  91. data/lib/ollama_agent/providers/model_descriptor.rb +45 -0
  92. data/lib/ollama_agent/providers/model_registry.rb +207 -0
  93. data/lib/ollama_agent/providers/ollama.rb +184 -0
  94. data/lib/ollama_agent/providers/openai.rb +232 -0
  95. data/lib/ollama_agent/providers/quota_tracker.rb +144 -0
  96. data/lib/ollama_agent/providers/rate_window.rb +57 -0
  97. data/lib/ollama_agent/providers/registry.rb +162 -0
  98. data/lib/ollama_agent/providers/router.rb +91 -0
  99. data/lib/ollama_agent/repo_list.rb +22 -10
  100. data/lib/ollama_agent/resilience/retry_middleware.rb +7 -0
  101. data/lib/ollama_agent/ruby_index_tool_support.rb +11 -1
  102. data/lib/ollama_agent/runner.rb +97 -10
  103. data/lib/ollama_agent/runtime/approval_gate.rb +74 -0
  104. data/lib/ollama_agent/runtime/atomic_mutator.rb +366 -0
  105. data/lib/ollama_agent/runtime/blob_store.rb +98 -0
  106. data/lib/ollama_agent/runtime/cas_guard.rb +52 -0
  107. data/lib/ollama_agent/runtime/compactor.rb +250 -0
  108. data/lib/ollama_agent/runtime/compactor_runner.rb +25 -0
  109. data/lib/ollama_agent/runtime/compensation_engine.rb +85 -0
  110. data/lib/ollama_agent/runtime/compensation_manifest.rb +66 -0
  111. data/lib/ollama_agent/runtime/cost_ledger.rb +53 -0
  112. data/lib/ollama_agent/runtime/criticality_policy.rb +51 -0
  113. data/lib/ollama_agent/runtime/database_registry.rb +74 -0
  114. data/lib/ollama_agent/runtime/event_store.rb +80 -0
  115. data/lib/ollama_agent/runtime/execution_context.rb +21 -0
  116. data/lib/ollama_agent/runtime/execution_manifest.rb +41 -0
  117. data/lib/ollama_agent/runtime/execution_mode.rb +22 -0
  118. data/lib/ollama_agent/runtime/fencing_allocator.rb +30 -0
  119. data/lib/ollama_agent/runtime/file_atomic_swap.rb +76 -0
  120. data/lib/ollama_agent/runtime/integration_queue.rb +61 -0
  121. data/lib/ollama_agent/runtime/intent_reservation.rb +115 -0
  122. data/lib/ollama_agent/runtime/intent_translator.rb +193 -0
  123. data/lib/ollama_agent/runtime/isolated_validator.rb +217 -0
  124. data/lib/ollama_agent/runtime/kernel_bridge.rb +280 -0
  125. data/lib/ollama_agent/runtime/kernel_event_logger.rb +53 -0
  126. data/lib/ollama_agent/runtime/kernel_feature.rb +19 -0
  127. data/lib/ollama_agent/runtime/kernel_health.rb +96 -0
  128. data/lib/ollama_agent/runtime/kernel_pipeline.rb +691 -0
  129. data/lib/ollama_agent/runtime/kernel_pipeline_assembly.rb +119 -0
  130. data/lib/ollama_agent/runtime/kernel_tool_seed.rb +235 -0
  131. data/lib/ollama_agent/runtime/lock_manager.rb +153 -0
  132. data/lib/ollama_agent/runtime/logical_clock.rb +22 -0
  133. data/lib/ollama_agent/runtime/mutation_classifier.rb +24 -0
  134. data/lib/ollama_agent/runtime/permission_bridge.rb +89 -0
  135. data/lib/ollama_agent/runtime/permissions.rb +103 -0
  136. data/lib/ollama_agent/runtime/policies.rb +96 -0
  137. data/lib/ollama_agent/runtime/post_condition_verifier.rb +52 -0
  138. data/lib/ollama_agent/runtime/rollback_signals.rb +87 -0
  139. data/lib/ollama_agent/runtime/saga_coordinator.rb +224 -0
  140. data/lib/ollama_agent/runtime/saga_recovery_daemon.rb +91 -0
  141. data/lib/ollama_agent/runtime/saga_state.rb +44 -0
  142. data/lib/ollama_agent/runtime/sandbox.rb +130 -0
  143. data/lib/ollama_agent/runtime/schema_migrator.rb +138 -0
  144. data/lib/ollama_agent/runtime/unified_diff_apply.rb +102 -0
  145. data/lib/ollama_agent/runtime/wal.rb +54 -0
  146. data/lib/ollama_agent/runtime/workspace_wal_replay.rb +72 -0
  147. data/lib/ollama_agent/runtime_command_system/ast.rb +96 -0
  148. data/lib/ollama_agent/runtime_command_system/command_palette.rb +53 -0
  149. data/lib/ollama_agent/runtime_command_system/command_registry.rb +48 -0
  150. data/lib/ollama_agent/runtime_command_system/completers.rb +83 -0
  151. data/lib/ollama_agent/runtime_command_system/dispatch/dispatcher.rb +36 -0
  152. data/lib/ollama_agent/runtime_command_system/dispatch/handlers/model_handler.rb +20 -0
  153. data/lib/ollama_agent/runtime_command_system/dispatch/handlers/provider_handler.rb +19 -0
  154. data/lib/ollama_agent/runtime_command_system/ghost_text.rb +34 -0
  155. data/lib/ollama_agent/runtime_command_system/input_buffer.rb +43 -0
  156. data/lib/ollama_agent/runtime_command_system/interactive_menu.rb +48 -0
  157. data/lib/ollama_agent/runtime_command_system/session/events.rb +32 -0
  158. data/lib/ollama_agent/runtime_command_system/session/runtime.rb +40 -0
  159. data/lib/ollama_agent/runtime_command_system/suggestion.rb +30 -0
  160. data/lib/ollama_agent/runtime_command_system/suggestion_engine.rb +41 -0
  161. data/lib/ollama_agent/runtime_command_system.rb +11 -0
  162. data/lib/ollama_agent/sandboxed_tools/search_text.rb +27 -4
  163. data/lib/ollama_agent/sandboxed_tools.rb +20 -7
  164. data/lib/ollama_agent/security/ownership_compile_validators.rb +77 -0
  165. data/lib/ollama_agent/security/ownership_compiler.rb +89 -0
  166. data/lib/ollama_agent/security/ownership_index.rb +63 -0
  167. data/lib/ollama_agent/security/ownership_rule_tree_flattener.rb +122 -0
  168. data/lib/ollama_agent/security/resource_guard.rb +55 -0
  169. data/lib/ollama_agent/skills/architecture_refactorer.rb +52 -0
  170. data/lib/ollama_agent/skills/base.rb +57 -0
  171. data/lib/ollama_agent/skills/debug_engineer.rb +53 -0
  172. data/lib/ollama_agent/skills/feature_builder.rb +59 -0
  173. data/lib/ollama_agent/skills/json_extractor.rb +81 -0
  174. data/lib/ollama_agent/skills/llm_client.rb +42 -0
  175. data/lib/ollama_agent/skills/performance_optimizer.rb +48 -0
  176. data/lib/ollama_agent/skills/registry.rb +39 -0
  177. data/lib/ollama_agent/skills/runner.rb +35 -0
  178. data/lib/ollama_agent/state/ast_summarizer.rb +167 -0
  179. data/lib/ollama_agent/state/git_changed_paths.rb +22 -0
  180. data/lib/ollama_agent/state/reconciler.rb +29 -0
  181. data/lib/ollama_agent/state/reentry_packet.rb +53 -0
  182. data/lib/ollama_agent/state/tree_digest.rb +20 -0
  183. data/lib/ollama_agent/state/workspace_fingerprint.rb +48 -0
  184. data/lib/ollama_agent/streaming/hooks.rb +3 -1
  185. data/lib/ollama_agent/synthesis/event_schema_registry.rb +98 -0
  186. data/lib/ollama_agent/synthesis/integration_extractor/concerns.rb +174 -0
  187. data/lib/ollama_agent/synthesis/integration_extractor.rb +106 -0
  188. data/lib/ollama_agent/synthesis/integration_scan.rb +8 -0
  189. data/lib/ollama_agent/synthesis/route_synthesizer.rb +58 -0
  190. data/lib/ollama_agent/synthesis/sidekiq_synthesizer.rb +24 -0
  191. data/lib/ollama_agent/think_param.rb +23 -1
  192. data/lib/ollama_agent/tool_arguments.rb +9 -0
  193. data/lib/ollama_agent/tool_runtime/supervisor.rb +111 -0
  194. data/lib/ollama_agent/tool_runtime/tool_registry.rb +52 -0
  195. data/lib/ollama_agent/tool_runtime.rb +4 -0
  196. data/lib/ollama_agent/tools/base.rb +106 -0
  197. data/lib/ollama_agent/tools/built_in_schemas.rb +234 -0
  198. data/lib/ollama_agent/tools/filesystem_explorer.rb +77 -0
  199. data/lib/ollama_agent/tools/git_tools.rb +176 -0
  200. data/lib/ollama_agent/tools/http_tools.rb +207 -0
  201. data/lib/ollama_agent/tools/memory_tools.rb +116 -0
  202. data/lib/ollama_agent/tools/safe_calculator.rb +203 -0
  203. data/lib/ollama_agent/tools/shell_tools.rb +257 -0
  204. data/lib/ollama_agent/tools_schema.rb +15 -144
  205. data/lib/ollama_agent/topology/class_node_merger.rb +54 -0
  206. data/lib/ollama_agent/topology/extractors/ruby_semantic_extractor/concern_body.rb +45 -0
  207. data/lib/ollama_agent/topology/extractors/ruby_semantic_extractor/ir_nodes_emitter.rb +65 -0
  208. data/lib/ollama_agent/topology/extractors/ruby_semantic_extractor/mixin_dispatch.rb +101 -0
  209. data/lib/ollama_agent/topology/extractors/ruby_semantic_extractor/navigation.rb +124 -0
  210. data/lib/ollama_agent/topology/extractors/ruby_semantic_extractor/parameter_list.rb +71 -0
  211. data/lib/ollama_agent/topology/extractors/ruby_semantic_extractor/semantic_context.rb +40 -0
  212. data/lib/ollama_agent/topology/extractors/ruby_semantic_extractor.rb +67 -0
  213. data/lib/ollama_agent/topology/ir/callback_node.rb +38 -0
  214. data/lib/ollama_agent/topology/ir/class_node.rb +41 -0
  215. data/lib/ollama_agent/topology/ir/concern_node.rb +41 -0
  216. data/lib/ollama_agent/topology/ir/event_publisher_node.rb +38 -0
  217. data/lib/ollama_agent/topology/ir/module_node.rb +40 -0
  218. data/lib/ollama_agent/topology/ir/node.rb +30 -0
  219. data/lib/ollama_agent/topology/ir/route_node.rb +41 -0
  220. data/lib/ollama_agent/topology/ir/worker_node.rb +38 -0
  221. data/lib/ollama_agent/topology/linker/aggregate.rb +93 -0
  222. data/lib/ollama_agent/topology/linker/discovery.rb +33 -0
  223. data/lib/ollama_agent/topology/linker/extract.rb +35 -0
  224. data/lib/ollama_agent/topology/linker/link.rb +56 -0
  225. data/lib/ollama_agent/topology/linker/resolve.rb +42 -0
  226. data/lib/ollama_agent/topology/linker/validate.rb +97 -0
  227. data/lib/ollama_agent/topology/linker.rb +90 -0
  228. data/lib/ollama_agent/topology/signature_normalizer.rb +74 -0
  229. data/lib/ollama_agent/topology/staged_graph/symbol_ids.rb +111 -0
  230. data/lib/ollama_agent/topology/staged_graph.rb +115 -0
  231. data/lib/ollama_agent/topology/symbol_graph.rb +50 -0
  232. data/lib/ollama_agent/topology/symbol_identity.rb +42 -0
  233. data/lib/ollama_agent/topology/zeitwerk_inflector.rb +71 -0
  234. data/lib/ollama_agent/tui.rb +316 -0
  235. data/lib/ollama_agent/tui_slash_reader.rb +255 -0
  236. data/lib/ollama_agent/tui_user_prompt.rb +45 -0
  237. data/lib/ollama_agent/version.rb +1 -1
  238. data/lib/ollama_agent.rb +148 -3
  239. data/lib/tasks/docker_validator.rake +16 -0
  240. metadata +324 -6
  241. data/reproduce_429.rb +0 -40
@@ -0,0 +1,16 @@
1
+ # Minimal sandbox for post-condition / isolated validation (array-exec only at the Docker CLI).
2
+ # Build: docker build -f containers/ollama_agent-verification-sandbox.Dockerfile -t ollama-agent-validator:local .
3
+ #
4
+ # ruby:3.3-slim is smaller than the default non-slim image while keeping glibc compatibility.
5
+ FROM ruby:3.3-slim-bookworm
6
+
7
+ RUN groupadd --system --gid 65532 sandbox \
8
+ && useradd --system --uid 65532 --gid sandbox --home-dir /workspace --shell /usr/sbin/nologin sandbox
9
+
10
+ WORKDIR /workspace
11
+
12
+ # Replace with a concrete argv at `docker run ... image <cmd...>`; this is only a smoke default.
13
+ ENTRYPOINT []
14
+ CMD ["ruby", "-rjson", "-e", "puts JSON.dump({ok: true})"]
15
+
16
+ USER sandbox
@@ -0,0 +1,102 @@
1
+ -- ### event_store.db
2
+ -- WAL / synchronous PRAGMAs are applied by DatabaseRegistry on each connection.
3
+
4
+ CREATE TABLE IF NOT EXISTS events (
5
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
6
+ manifest_id TEXT NOT NULL,
7
+ logical_stamp TEXT NOT NULL,
8
+ kind TEXT NOT NULL,
9
+ payload BLOB NOT NULL,
10
+ intent_hash TEXT,
11
+ created_at TEXT NOT NULL
12
+ );
13
+
14
+ CREATE INDEX IF NOT EXISTS idx_events_manifest_id_id ON events (manifest_id, id);
15
+
16
+ CREATE UNIQUE INDEX IF NOT EXISTS idx_events_intent_hash_unique ON events (intent_hash) WHERE intent_hash IS NOT NULL;
17
+
18
+ -- ### runtime.db
19
+
20
+ CREATE TABLE IF NOT EXISTS workspace_fingerprints (
21
+ manifest_id TEXT PRIMARY KEY,
22
+ fingerprint TEXT NOT NULL,
23
+ parent_manifest_id TEXT,
24
+ created_at TEXT NOT NULL
25
+ );
26
+
27
+ CREATE TABLE IF NOT EXISTS fencing_tokens (
28
+ scope TEXT PRIMARY KEY,
29
+ last_token INTEGER NOT NULL
30
+ );
31
+
32
+ CREATE TABLE IF NOT EXISTS integration_queue (
33
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
34
+ manifest_id TEXT NOT NULL,
35
+ payload BLOB NOT NULL,
36
+ status TEXT NOT NULL,
37
+ created_at TEXT NOT NULL
38
+ );
39
+
40
+ CREATE TABLE IF NOT EXISTS locks (
41
+ scope TEXT PRIMARY KEY,
42
+ lease_token INTEGER NOT NULL,
43
+ holder TEXT NOT NULL,
44
+ acquired_at TEXT NOT NULL,
45
+ expires_at_epoch INTEGER NOT NULL,
46
+ fencing_token INTEGER NOT NULL
47
+ );
48
+
49
+ CREATE INDEX IF NOT EXISTS idx_locks_expires ON locks (expires_at_epoch);
50
+
51
+ CREATE TABLE IF NOT EXISTS intent_reservations (
52
+ intent_hash TEXT PRIMARY KEY,
53
+ manifest_id TEXT NOT NULL,
54
+ scopes TEXT NOT NULL,
55
+ created_at_epoch INTEGER NOT NULL
56
+ );
57
+
58
+ CREATE TABLE IF NOT EXISTS sagas (
59
+ manifest_id TEXT PRIMARY KEY,
60
+ state TEXT NOT NULL,
61
+ intent_hash TEXT,
62
+ planned_scopes TEXT NOT NULL,
63
+ supervisor_lease TEXT,
64
+ last_transition_at_epoch INTEGER NOT NULL,
65
+ terminal INTEGER NOT NULL DEFAULT 0,
66
+ metadata TEXT
67
+ );
68
+
69
+ CREATE INDEX IF NOT EXISTS idx_sagas_state ON sagas (state) WHERE terminal = 0;
70
+
71
+ CREATE TABLE IF NOT EXISTS saga_transitions (
72
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
73
+ manifest_id TEXT NOT NULL,
74
+ from_state TEXT NOT NULL,
75
+ to_state TEXT NOT NULL,
76
+ reason TEXT,
77
+ logical_stamp TEXT NOT NULL,
78
+ created_at_epoch INTEGER NOT NULL
79
+ );
80
+
81
+ CREATE INDEX IF NOT EXISTS idx_saga_transitions_manifest ON saga_transitions (manifest_id, id);
82
+
83
+ CREATE TABLE IF NOT EXISTS compensations (
84
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
85
+ manifest_id TEXT NOT NULL,
86
+ path TEXT NOT NULL,
87
+ op TEXT NOT NULL,
88
+ pre_blob_sha TEXT,
89
+ pre_existed INTEGER NOT NULL,
90
+ fencing_token INTEGER NOT NULL,
91
+ logical_stamp TEXT NOT NULL,
92
+ applied INTEGER NOT NULL DEFAULT 0
93
+ );
94
+
95
+ CREATE INDEX IF NOT EXISTS idx_compensations_manifest_unapplied ON compensations (manifest_id) WHERE applied = 0;
96
+
97
+ CREATE TABLE IF NOT EXISTS recovery_leases (
98
+ manifest_id TEXT PRIMARY KEY,
99
+ holder TEXT NOT NULL,
100
+ acquired_at_epoch INTEGER NOT NULL,
101
+ expires_at_epoch INTEGER NOT NULL
102
+ );
@@ -0,0 +1,12 @@
1
+ -- ### runtime.db
2
+ CREATE TABLE IF NOT EXISTS cost_ledger (
3
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
4
+ manifest_id TEXT,
5
+ model TEXT NOT NULL,
6
+ input_tokens INTEGER NOT NULL,
7
+ output_tokens INTEGER NOT NULL,
8
+ cost_usd REAL NOT NULL,
9
+ created_at_epoch INTEGER NOT NULL
10
+ );
11
+
12
+ CREATE INDEX IF NOT EXISTS idx_cost_ledger_manifest ON cost_ledger (manifest_id);
@@ -0,0 +1 @@
1
+ -- Runtime schema is applied from versioned files in db/ollama_agent/migrations/ (see OllamaAgent::Runtime::SchemaMigrator).
@@ -0,0 +1,91 @@
1
+ # ollama_agent capabilities (post-kernel)
2
+
3
+ ## Overview
4
+
5
+ `ollama_agent` is a Ruby gem and CLI that drives a **tool-calling agent** against a chat model (default: local **Ollama**; optional OpenAI / Anthropic providers). The model proposes **function calls**; the runtime validates arguments and executes tools under a **workspace root** (file IO, search, patches, optional shell and delegation). An optional **kernel runtime** (`OLLAMA_AGENT_KERNEL`) adds SQLite-backed sagas, a mutation WAL, ownership gates, replayable mutations, and operator-facing health and cost persistence—without changing the high-level “ask the model, run tools” loop.
6
+
7
+ ---
8
+
9
+ ## Core agent capabilities
10
+
11
+ | Capability | Status | Primary code | Related docs |
12
+ |------------|--------|--------------|--------------|
13
+ | Multi-turn chat with tool loop | stable | `lib/ollama_agent/agent.rb`, `lib/ollama_agent/agent/turn_loop.rb`, `lib/ollama_agent/agent/chat_coordinator.rb` | `docs/USAGE.md`, `README.md` |
14
+ | Ollama `/api/chat` (blocking + streaming hooks) | stable | `lib/ollama_agent/ollama_connection.rb`, `lib/ollama_agent/providers/ollama.rb` | `README.md` |
15
+ | OpenAI / Anthropic providers + router | stable / opt-in keys | `lib/ollama_agent/providers/*.rb` | `README.md`, `docs/USAGE.md` |
16
+ | Built-in tools: `read_file`, `search_code`, `list_files`, `edit_file`, `write_file`, optional `run_shell` | stable | `lib/ollama_agent/tools/built_in_schemas.rb`, `lib/ollama_agent/sandboxed_tools.rb` | `README.md` |
17
+ | **Prism Ruby index** (`search_code` modes: class, module, constant, method) | stable | `lib/ollama_agent/ruby_index*.rb`, `lib/ollama_agent/ruby_index_tool_support.rb` | `lib/ollama_agent/tools/built_in_schemas.rb` (schema text) |
18
+ | Prompt **skills** (bundled + extra paths) | stable | `lib/ollama_agent/prompt_skills.rb`, `lib/ollama_agent/agent_prompt.rb` | `README.md`, `docs/USAGE.md` |
19
+ | Deterministic **JSON skills** CLI (`skill list|run|pipeline`) | stable | `lib/ollama_agent/cli/skill_command.rb`, `lib/ollama_agent/skills/` | `README.md`, `docs/CLI.md` |
20
+ | **Sessions** (save / resume transcript) | stable | `lib/ollama_agent/session/store.rb`, `lib/ollama_agent/cli.rb` (`sessions`) | `README.md` |
21
+ | **TUI** + line REPL | stable | `lib/ollama_agent/cli/tui_repl.rb`, `lib/ollama_agent/cli/repl.rb` | `README.md`, `docs/CLI.md` |
22
+ | Orchestrator tools + `orchestrate` | opt-in | `lib/ollama_agent/external_agents.rb`, `lib/ollama_agent/cli.rb` | `README.md` |
23
+ | Permissions / policies / approval gate | stable | `lib/ollama_agent/runtime/permissions.rb`, `lib/ollama_agent/runtime/policies.rb`, `lib/ollama_agent/runtime/approval_gate.rb` | `README.md`, `docs/USAGE.md` |
24
+ | Loop detection, budget, context trim | stable | `lib/ollama_agent/core/loop_detector.rb`, `lib/ollama_agent/context/manager.rb` | `README.md` |
25
+ | Self-review / improve (sandbox modes) | stable | `lib/ollama_agent/self_improvement/`, `lib/ollama_agent/cli.rb` | `README.md`, `docs/CLI.md` |
26
+ | Plugins | experimental | `lib/ollama_agent/plugins/loader.rb` | `README.md` |
27
+
28
+ ---
29
+
30
+ ## Kernel runtime capabilities
31
+
32
+ Enabled when `OLLAMA_AGENT_KERNEL` is `true` or `shadow` (`lib/ollama_agent/runtime/kernel_feature.rb`). Tool subset routed through the pipeline is configurable via `OLLAMA_AGENT_KERNEL_PIPELINE_TOOLS` (see `lib/ollama_agent/runtime/kernel_bridge.rb`).
33
+
34
+ | Capability | Status | Primary code | Related docs |
35
+ |------------|--------|--------------|--------------|
36
+ | Saga FSM (reserved → locked → mutations_applied → verified → integration_queued → committed / compensated) | stable (flagged) | `lib/ollama_agent/runtime/saga_state.rb`, `lib/ollama_agent/runtime/saga_coordinator.rb`, `lib/ollama_agent/runtime/kernel_pipeline.rb` | `docs/agile/release_rollout_runbook.md`, `docs/OPERATIONS.md` |
37
+ | **Shadow** execution (WAL + saga without real byte swap for configured ops) | opt-in | `lib/ollama_agent/runtime/execution_mode.rb`, `lib/ollama_agent/runtime/kernel_pipeline.rb` | `docs/agile/release_rollout_runbook.md` |
38
+ | Atomic mutations (CAS, blobs, compensation rows) | stable (flagged) | `lib/ollama_agent/runtime/atomic_mutator.rb`, `lib/ollama_agent/runtime/blob_store.rb`, `lib/ollama_agent/runtime/compensation_engine.rb` | `docs/OPERATIONS.md` |
39
+ | Ownership index + compiler (`owners.yml`) | opt-in file | `lib/ollama_agent/security/ownership_compiler.rb`, `lib/ollama_agent/security/ownership_index.rb`, `config/ollama_agent/owners.yml` | `docs/USAGE.md`, `docs/OPERATIONS.md` |
40
+ | Permission bridge (legacy vs kernel) | stable (flagged) | `lib/ollama_agent/runtime/permission_bridge.rb` | `README.md` |
41
+ | Recovery / leases / fencing | stable (flagged) | `lib/ollama_agent/runtime/saga_recovery_daemon.rb`, `lib/ollama_agent/runtime/lock_manager.rb`, `lib/ollama_agent/runtime/fencing_allocator.rb` | `docs/OPERATIONS.md` |
42
+ | Post-mutation validation (isolated validator optional Docker) | experimental / CI-gated | `lib/ollama_agent/runtime/isolated_validator.rb` | `docs/agile/docker_spec_activation.md` |
43
+ | Mutation WAL + global replay | stable (flagged) | `lib/ollama_agent/runtime/wal.rb`, `lib/ollama_agent/runtime/event_store.rb`, `lib/ollama_agent/runtime/workspace_wal_replay.rb` | `docs/USAGE.md`, `docs/OPERATIONS.md` |
44
+ | **LLM boundary** (no wall-clock on saga path; cloud router uses separate clock for breakers only) | stable | `lib/ollama_agent/llm/cloud_fallback_router.rb`, `lib/ollama_agent/llm/anthropic_client.rb` | `docs/USAGE.md` |
45
+ | Topology (IR, symbol graph, linker) | stable library | `lib/ollama_agent/topology/` | `docs/new_features_plan_v2.md` |
46
+ | Integration synthesis | stable library | `lib/ollama_agent/synthesis/` | `docs/new_features_plan_v2.md` |
47
+ | Kernel event JSON logging | stable | `lib/ollama_agent/runtime/kernel_event_logger.rb` | `docs/OPERATIONS.md` |
48
+
49
+ ---
50
+
51
+ ## Operational tooling
52
+
53
+ | Capability | Status | Primary code | Related docs |
54
+ |------------|--------|--------------|--------------|
55
+ | Feature flag `OLLAMA_AGENT_KERNEL` (`false` / `shadow` / `true`) | stable | `lib/ollama_agent/runtime/kernel_feature.rb` | `docs/agile/release_rollout_runbook.md`, `docs/OPERATIONS.md` |
56
+ | **Kernel health** CLI (`ollama_agent kernel health`) | stable | `lib/ollama_agent/cli/health_command.rb`, `lib/ollama_agent/runtime/kernel_health.rb` | `docs/CLI.md`, `docs/OPERATIONS.md` |
57
+ | **Schema migrations** (versioned SQL under `db/ollama_agent/migrations/`) | stable | `lib/ollama_agent/runtime/schema_migrator.rb`, `lib/ollama_agent/runtime/database_registry.rb` | `docs/OPERATIONS.md` |
58
+ | **Cost ledger** (runtime SQLite `cost_ledger` + `CloudFallbackRouter`) | stable | `lib/ollama_agent/runtime/cost_ledger.rb`, `lib/ollama_agent/llm/cloud_fallback_router.rb` | `docs/USAGE.md` |
59
+ | **RollbackSignals** (in-memory thresholds for operators) | stable | `lib/ollama_agent/runtime/rollback_signals.rb` | `docs/OPERATIONS.md` |
60
+ | Compaction + archive DB | opt-in operator job | `lib/ollama_agent/runtime/compactor.rb`, `lib/ollama_agent/runtime/compactor_runner.rb` | `docs/agile/release_rollout_runbook.md`, `docs/OPERATIONS.md` |
61
+ | Audit / trace hooks | opt-in env | `lib/ollama_agent/resilience/audit_logger.rb`, `lib/ollama_agent/core/trace_logger.rb` | `README.md` |
62
+
63
+ ---
64
+
65
+ ## Test coverage summary (684 examples)
66
+
67
+ The suite is **RSpec** under `spec/`. Approximate layers:
68
+
69
+ | Layer | Paths | What is exercised |
70
+ |-------|--------|---------------------|
71
+ | Agent + tools | `spec/ollama_agent/agent_spec.rb`, `spec/ollama_agent/sandboxed_tools_spec.rb`, tool schema specs | Chat loop, tool execution, path sandbox, read-only mode |
72
+ | Providers / LLM | `spec/ollama_agent/providers/`, `spec/ollama_agent/llm/` | Ollama/OpenAI/Anthropic adapters, retry + streaming client, cloud router + cost ledger |
73
+ | Kernel runtime | `spec/ollama_agent/runtime/` | Database registry + migrations, saga, WAL, bridge, pipeline, health, blob store, compactor, permissions |
74
+ | Integration | `spec/integration/` | Legacy path without kernel; optional real-Ollama smoke (`OLLAMA_HOST`) |
75
+ | Self-improvement / CLI | `spec/ollama_agent/self_improvement/`, CLI-related specs where present | Modes, harness behavior |
76
+
77
+ Counts are from `bundle exec rspec` (includes pending examples for Docker and opt-in real LLM).
78
+
79
+ ---
80
+
81
+ ## Related documentation
82
+
83
+ | Document | Role |
84
+ |----------|------|
85
+ | `README.md` | Install, quick usage, kernel summary |
86
+ | `docs/CLI.md` | Subcommand and flag reference |
87
+ | `docs/USAGE.md` | End-user workflows |
88
+ | `docs/OPERATIONS.md` | Rollout, incidents, SQL, compaction, health |
89
+ | `docs/agile/release_rollout_runbook.md` | Kernel rollout stages (cross-ref operations) |
90
+ | `docs/new_features_plan_v2.md` | Design backlog and architecture notes |
91
+ | `docs/agile/docker_spec_activation.md` | Isolated validator / Docker |
data/docs/CLI.md ADDED
@@ -0,0 +1,212 @@
1
+ # ollama_agent CLI reference
2
+
3
+ Entry point: `exe/ollama_agent` → `OllamaAgent::CLI` (`lib/ollama_agent/cli.rb`). **Thor** is used; `CLI.exit_on_failure?` is **true**, so uncaught errors typically yield **exit code 1**.
4
+
5
+ **Default task:** `ask`. Invoking `ollama_agent` with no subcommand runs `ask` (same as `ollama_agent ask`).
6
+
7
+ **Global behavior:** many commands call `load_plugins!` (see `Plugins::Loader`) when applicable.
8
+
9
+ **Root resolution:** most commands use `OLLAMA_AGENT_ROOT` or `--root`, else current working directory (see `resolved_root_for_self_review` in `lib/ollama_agent/cli.rb`).
10
+
11
+ ---
12
+
13
+ ## `ask [QUERY]` (default)
14
+
15
+ **Syntax:** `ollama_agent [options] [QUERY]` or `ollama_agent ask [options] [QUERY]`
16
+
17
+ **Description:** Run one task with a query string, or enter **interactive** mode when `QUERY` is empty (TUI vs line REPL depends on `--interactive` / `--tui`; see `apply_session_interactive_tui_flags!`).
18
+
19
+ **Common options** (from `lib/ollama_agent/cli.rb`):
20
+
21
+ | Option | Alias | Meaning |
22
+ |--------|-------|---------|
23
+ | `--model` | | Model id (default from `OLLAMA_AGENT_MODEL` / client) |
24
+ | `--interactive` | `-i` | Interactive session |
25
+ | `--tui` | | TTY UI when interactive |
26
+ | `--tui-god` | | Auto-pick first TUI choice (dangerous) |
27
+ | `--read-only` | `-R` | No write/patch/delegation tools |
28
+ | `--yes` | `-y` | Skip patch confirmation |
29
+ | `--root` | | Project root |
30
+ | `--timeout` | `-t` | HTTP timeout seconds (default 120) |
31
+ | `--think` | | Thinking / reasoning level (model-specific) |
32
+ | `--no-skills` | | Disable bundled skills (`OLLAMA_AGENT_SKILLS=0` equivalent) |
33
+ | `--skill-paths` | | Colon-separated extra skill paths |
34
+ | `--stream` | | Stream tokens (`OLLAMA_AGENT_STREAM=1` equivalent) |
35
+ | `--audit` | | Audit log under `.ollama_agent/logs/` |
36
+ | `--max-retries` | | HTTP retries (0 disables) |
37
+ | `--session` | | Named session id |
38
+ | `--resume` | | Resume session |
39
+ | `--max-tokens` | | Context budget |
40
+ | `--context-summarize` | | Summarize dropped context |
41
+ | `--provider` | | `ollama` (default) \| `openai` \| `anthropic` \| `auto` |
42
+ | `--permissions` | | `read_only` \| `standard` \| `developer` \| `full` |
43
+ | `--trace` | | Structured trace (`OLLAMA_AGENT_TRACE=1`) |
44
+
45
+ **Examples:**
46
+
47
+ ```bash
48
+ bundle exec ollama_agent ask "Summarize lib/ for a newcomer"
49
+ bundle exec ollama_agent ask --read-only -R "List risks only"
50
+ bundle exec ollama_agent ask -y --root /path/to/repo "Apply the patch plan"
51
+ bundle exec ollama_agent ask --session myfeat --resume "Continue where we left off"
52
+ ```
53
+
54
+ **Exit codes:** `0` on success; `1` on agent/CLI errors (`run_single_shot_agent!` rescues and `exit 1`).
55
+
56
+ ---
57
+
58
+ ## `orchestrate [QUERY]`
59
+
60
+ **Syntax:** `ollama_agent orchestrate [options] [QUERY]`
61
+
62
+ Same interactive / TUI flags as `ask` where declared. Builds an agent with **orchestrator** enabled (`build_orchestrator_agent`). Adds delegation tools (`list_external_agents`, `delegate_to_agent`) per `README.md`.
63
+
64
+ **Examples:**
65
+
66
+ ```bash
67
+ bundle exec ollama_agent orchestrate "Delegate a subtask to claude if stuck"
68
+ ```
69
+
70
+ **Exit codes:** same pattern as `ask`.
71
+
72
+ ---
73
+
74
+ ## `sessions`
75
+
76
+ **Syntax:** `ollama_agent sessions [--root PATH]`
77
+
78
+ Lists saved session ids for the resolved root (`Session::Store.list`).
79
+
80
+ **Exit codes:** `0`.
81
+
82
+ ---
83
+
84
+ ## `agents` and `doctor`
85
+
86
+ **Syntax:** `ollama_agent agents` — `ollama_agent doctor` is an **alias** for `agents`.
87
+
88
+ Prints external CLI agent registry probe table (`ExternalAgents::Registry`, `ExternalAgents::Probe`).
89
+
90
+ **Exit codes:** `0`.
91
+
92
+ ---
93
+
94
+ ## `self_review`
95
+
96
+ **Syntax:** `ollama_agent self_review [options]`
97
+
98
+ **Modes** (`--mode`, normalized in `SelfImprovement::Modes`):
99
+
100
+ - `analysis` (default, aliases `1`, `readonly`) — read-only tools, report.
101
+ - `interactive` (`2`, `fix`, `confirm`) — full tools, confirm patches (`--yes` / `--semi`).
102
+ - `automated` (`3`, `sandbox`, `full`) — sandbox copy, agent, `bundle exec rspec`, optional `--apply`.
103
+
104
+ **Notable options:** `--root`, `--timeout`, `--think`, `--yes`, `--semi`, `--apply` (automated), `--verify` (automated), `--no-skills`, `--skill-paths`, `--stream`, `--max-tokens`, `--context-summarize`, `--no-ruby-mastery`.
105
+
106
+ **Examples:**
107
+
108
+ ```bash
109
+ bundle exec ollama_agent self_review --mode analysis
110
+ bundle exec ollama_agent self_review --mode interactive --root .
111
+ bundle exec ollama_agent self_review --mode automated --apply --yes
112
+ ```
113
+
114
+ **Exit codes:** `1` if improve/verify fails (see `report_improve_result`); `0` on success paths.
115
+
116
+ ---
117
+
118
+ ## `improve`
119
+
120
+ **Syntax:** `ollama_agent improve [options]`
121
+
122
+ Shortcut for **`self_review --mode automated`**. Rejects non-automated modes (`ensure_improve_mode_only_automated!`).
123
+
124
+ **Exit codes:** same as automated self_review.
125
+
126
+ ---
127
+
128
+ ## `skill` (subcommand)
129
+
130
+ Defined in `lib/ollama_agent/cli/skill_command.rb`, mounted as `CLI.subcommand "skill", CLI::SkillCommand`.
131
+
132
+ ### `skill list`
133
+
134
+ **Syntax:** `ollama_agent skill list`
135
+
136
+ Prints registered skill names (`Skills.registry.names`).
137
+
138
+ **Exit codes:** `0`.
139
+
140
+ ### `skill run NAME`
141
+
142
+ **Syntax:** `ollama_agent skill run NAME [--code-file PATH] [--requirements TEXT] [--error TEXT] [--model MODEL]`
143
+
144
+ Runs one skill; prints **JSON** (`JSON.pretty_generate`).
145
+
146
+ **Exit codes:** `0` on success; Thor raises on missing file / errors (→ process exit `1` with `exit_on_failure?`).
147
+
148
+ **Example:**
149
+
150
+ ```bash
151
+ ollama_agent skill run architecture_refactor --code-file lib/foo.rb
152
+ ```
153
+
154
+ ### `skill pipeline NAME [NAME ...]`
155
+
156
+ **Syntax:** `ollama_agent skill pipeline SKILL [SKILL ...] [same options as run]`
157
+
158
+ Runs a deterministic pipeline of skills.
159
+
160
+ **Example:**
161
+
162
+ ```bash
163
+ ollama_agent skill pipeline architecture_refactor performance_optimizer --code-file lib/foo.rb
164
+ ```
165
+
166
+ ---
167
+
168
+ ## `kernel` (subcommand)
169
+
170
+ Defined in `lib/ollama_agent/cli/health_command.rb` as `CLI::KernelHealthCommand`, mounted `CLI.subcommand "kernel", ...`.
171
+
172
+ ### `kernel health`
173
+
174
+ **Syntax:** `ollama_agent kernel health [--root PATH]`
175
+
176
+ Opens kernel SQLite under `<root>/.ollama_agent/kernel/`, runs `KernelHealth#check`, prints **one JSON object** to stdout.
177
+
178
+ **Exit codes:**
179
+
180
+ - `0` if top-level `"status"` is `"ok"`.
181
+ - `1` if `"degraded"` or `"unhealthy"` (or any non-ok status).
182
+
183
+ **Example:**
184
+
185
+ ```bash
186
+ bundle exec ollama_agent kernel health --root /path/to/repo
187
+ ```
188
+
189
+ Interpretation of `checks` keys: see `docs/OPERATIONS.md`.
190
+
191
+ ---
192
+
193
+ ## Thor / invocation notes
194
+
195
+ - **Subcommand spelling:** use spaces (`ollama_agent kernel health`), not a colon.
196
+ - **Default executable:** after `gem install`, `ollama_agent` on `PATH`; from source often `bundle exec ruby exe/ollama_agent …`.
197
+ - **Help:** `ollama_agent help`, `ollama_agent help ask`, `ollama_agent help skill`, `ollama_agent help kernel`.
198
+
199
+ ---
200
+
201
+ ## Quick reference table
202
+
203
+ | Command | Purpose |
204
+ |---------|---------|
205
+ | `ask` / (no subcommand) | Main agent |
206
+ | `orchestrate` | Agent + external CLI delegation |
207
+ | `sessions` | List sessions |
208
+ | `agents`, `doctor` | External agent probe |
209
+ | `self_review` | Analysis / interactive / automated improvement |
210
+ | `improve` | Automated self_review only |
211
+ | `skill list\|run\|pipeline` | Deterministic JSON skills |
212
+ | `kernel health` | Kernel DB + blob + schema readiness JSON |