mistri 0.6.1 → 0.8.0

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 (113) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +355 -2
  3. data/CONTRIBUTING.md +17 -3
  4. data/NOTICE +11 -0
  5. data/README.md +145 -226
  6. data/UPGRADING.md +810 -0
  7. data/assets/vendors/README.md +12 -0
  8. data/assets/vendors/claude-mark.svg +3 -0
  9. data/assets/vendors/gemini-mark.svg +10 -0
  10. data/assets/vendors/openai-mark-dark.svg +1 -0
  11. data/assets/vendors/openai-mark.svg +1 -0
  12. data/docs/README.md +2 -1
  13. data/docs/context-and-workspaces.md +84 -13
  14. data/docs/logging.md +90 -0
  15. data/docs/mcp.md +762 -21
  16. data/docs/reliability.md +210 -24
  17. data/docs/sessions.md +415 -36
  18. data/docs/sub-agents.md +85 -7
  19. data/docs/tool-contracts.md +528 -13
  20. data/examples/approval.rb +7 -7
  21. data/examples/browser.rb +1 -1
  22. data/examples/page_editor.rb +2 -2
  23. data/examples/quickstart.rb +1 -1
  24. data/lib/generators/mistri/install/templates/migration.rb.tt +4 -2
  25. data/lib/generators/mistri/mcp/mcp_generator.rb +2 -2
  26. data/lib/generators/mistri/mcp/templates/model.rb.tt +21 -8
  27. data/lib/mistri/agent.rb +839 -141
  28. data/lib/mistri/call_order.rb +137 -0
  29. data/lib/mistri/child.rb +69 -13
  30. data/lib/mistri/compaction.rb +200 -35
  31. data/lib/mistri/compactor/text.rb +91 -0
  32. data/lib/mistri/compactor.rb +474 -117
  33. data/lib/mistri/console.rb +44 -11
  34. data/lib/mistri/content.rb +70 -3
  35. data/lib/mistri/definition.rb +2 -2
  36. data/lib/mistri/edit.rb +13 -7
  37. data/lib/mistri/errors.rb +37 -0
  38. data/lib/mistri/event.rb +20 -9
  39. data/lib/mistri/locks/rails_cache.rb +16 -2
  40. data/lib/mistri/locks.rb +12 -3
  41. data/lib/mistri/mcp/client.rb +247 -61
  42. data/lib/mistri/mcp/conversation.rb +161 -0
  43. data/lib/mistri/mcp/egress.rb +5 -4
  44. data/lib/mistri/mcp/mirror.rb +90 -0
  45. data/lib/mistri/mcp/negotiation.rb +222 -0
  46. data/lib/mistri/mcp/oauth/client_identity.rb +53 -0
  47. data/lib/mistri/mcp/oauth/tolerance.rb +61 -0
  48. data/lib/mistri/mcp/oauth.rb +303 -82
  49. data/lib/mistri/mcp/results.rb +97 -0
  50. data/lib/mistri/mcp/sdk_client.rb +47 -0
  51. data/lib/mistri/mcp/wires.rb +325 -52
  52. data/lib/mistri/mcp.rb +304 -55
  53. data/lib/mistri/memory.rb +1 -1
  54. data/lib/mistri/message.rb +45 -8
  55. data/lib/mistri/models.rb +146 -24
  56. data/lib/mistri/partial_json.rb +5 -5
  57. data/lib/mistri/providers/anthropic/assembler.rb +40 -3
  58. data/lib/mistri/providers/anthropic/serializer.rb +154 -22
  59. data/lib/mistri/providers/anthropic.rb +77 -12
  60. data/lib/mistri/providers/fake.rb +4 -1
  61. data/lib/mistri/providers/gemini/assembler.rb +63 -3
  62. data/lib/mistri/providers/gemini/serializer.rb +27 -16
  63. data/lib/mistri/providers/gemini.rb +56 -11
  64. data/lib/mistri/providers/openai/assembler.rb +36 -5
  65. data/lib/mistri/providers/openai/serializer.rb +76 -22
  66. data/lib/mistri/providers/openai.rb +91 -14
  67. data/lib/mistri/reminder.rb +35 -3
  68. data/lib/mistri/result.rb +6 -4
  69. data/lib/mistri/result_limit.rb +164 -0
  70. data/lib/mistri/sandbox/quickjs.rb +345 -0
  71. data/lib/mistri/sandbox.rb +18 -0
  72. data/lib/mistri/schema.rb +26 -2
  73. data/lib/mistri/scratchpad.rb +107 -0
  74. data/lib/mistri/session/log.rb +137 -0
  75. data/lib/mistri/session.rb +405 -75
  76. data/lib/mistri/sinks/logger.rb +407 -0
  77. data/lib/mistri/skills.rb +10 -4
  78. data/lib/mistri/spawner.rb +43 -12
  79. data/lib/mistri/sse.rb +3 -2
  80. data/lib/mistri/stores/active_record.rb +30 -6
  81. data/lib/mistri/stores/jsonl.rb +26 -7
  82. data/lib/mistri/stores/memory.rb +6 -2
  83. data/lib/mistri/sub_agent/execution.rb +11 -3
  84. data/lib/mistri/sub_agent/runtime.rb +11 -1
  85. data/lib/mistri/sub_agent.rb +13 -4
  86. data/lib/mistri/tool.rb +71 -7
  87. data/lib/mistri/tool_arguments.rb +10 -11
  88. data/lib/mistri/tool_context.rb +15 -3
  89. data/lib/mistri/tool_executor.rb +49 -26
  90. data/lib/mistri/tool_result.rb +8 -2
  91. data/lib/mistri/tool_search/index.rb +193 -0
  92. data/lib/mistri/tool_search.rb +200 -0
  93. data/lib/mistri/tools/delete_file.rb +22 -0
  94. data/lib/mistri/tools/edit_file.rb +24 -14
  95. data/lib/mistri/tools/find_in_file.rb +1 -0
  96. data/lib/mistri/tools/grep.rb +212 -0
  97. data/lib/mistri/tools/list_files.rb +38 -5
  98. data/lib/mistri/tools/read_file.rb +83 -21
  99. data/lib/mistri/tools/read_memory.rb +2 -1
  100. data/lib/mistri/tools/run_code.rb +167 -0
  101. data/lib/mistri/tools/write_file.rb +66 -9
  102. data/lib/mistri/tools.rb +72 -1
  103. data/lib/mistri/transport/streamable_http.rb +140 -0
  104. data/lib/mistri/transport.rb +53 -63
  105. data/lib/mistri/usage.rb +33 -4
  106. data/lib/mistri/version.rb +1 -1
  107. data/lib/mistri/workspace/active_record.rb +22 -10
  108. data/lib/mistri/workspace/directory.rb +5 -1
  109. data/lib/mistri/workspace/memory.rb +4 -0
  110. data/lib/mistri/workspace/path_space.rb +56 -0
  111. data/lib/mistri/workspace/single.rb +6 -1
  112. data/lib/mistri.rb +28 -4
  113. metadata +30 -2
data/docs/sub-agents.md CHANGED
@@ -21,13 +21,13 @@ transcripts are supported.
21
21
  researcher = Mistri::SubAgent.new(
22
22
  name: "researcher",
23
23
  description: "Reads approved sources and answers factual questions.",
24
- provider: Mistri.provider("claude-haiku-4-5"),
24
+ provider: Mistri.provider("claude-haiku-5-5"),
25
25
  system: "Research the question. Return findings and source URLs.",
26
26
  tools: [fetch_page],
27
27
  )
28
28
 
29
29
  agent = Mistri.agent(
30
- "claude-opus-4-8",
30
+ "claude-opus-5-5",
31
31
  tools: [researcher.tool],
32
32
  )
33
33
  ```
@@ -50,11 +50,11 @@ The open spawner lets the parent compose a worker from a pool the host controls:
50
50
  spawn = Mistri::SubAgent.spawner(
51
51
  provider: child_provider,
52
52
  tools: [fetch_page, search_catalog],
53
- models: ["claude-haiku-4-5", "gpt-5-nano"],
53
+ models: ["claude-haiku-5-5", "gpt-5-nano"],
54
54
  max_children: 4,
55
55
  )
56
56
 
57
- agent = Mistri.agent("claude-opus-4-8", tools: [spawn])
57
+ agent = Mistri.agent("claude-opus-5-5", tools: [spawn])
58
58
  ```
59
59
 
60
60
  The generated `spawn_agent` tool asks for a complete task and system
@@ -63,6 +63,13 @@ instructions. The model may select only tools in the pool and only model IDs in
63
63
  provider object. A background child records that provider's model identity and
64
64
  the Runtime factory reconstructs its provider inside the worker.
65
65
 
66
+ A pool may hold [deferred tools](tool-contracts.md#tools-on-demand). The
67
+ spawner's definition then names only the tools that are not deferred, so the
68
+ deferred ones add nothing to the parent's requests. A child that is granted
69
+ the whole pool gets its own `tool_search` and loads them itself. A parent
70
+ that holds the same deferred tools can grant one by its name. Otherwise it
71
+ omits `tools`, and the child loads what it needs.
72
+
66
73
  Do not place `spawn_agent` inside its own tool pool. Mistri rejects that host
67
74
  configuration.
68
75
 
@@ -81,7 +88,7 @@ spawn = Mistri::SubAgent.spawner(
81
88
  provider: child_provider,
82
89
  tools: [fetch_page, search_catalog, inspect_record],
83
90
  types: types,
84
- models: ["claude-haiku-4-5"],
91
+ models: ["claude-haiku-5-5"],
85
92
  )
86
93
  ```
87
94
 
@@ -133,7 +140,12 @@ request. The factory constructs what one background child may actually use.
133
140
  `Mistri::SubAgent::Runtime` holds the provider, system prompt, exact tools, an
134
141
  optional `cleanup:` callable, and safe Agent options for one execution:
135
142
  `budget`, `max_concurrency`, `transform_context`, `compaction`, `retries`,
136
- `before_tool`, `after_tool`, and application `context`. `skills:` is refused in
143
+ `result_limit`, `files`, `scratchpad`, `sandbox`, `before_tool`, `after_tool`,
144
+ and application `context`. A background Runtime with `files:` or `scratchpad:`
145
+ must be granted the document tools by name, for the same reason: the agent
146
+ would otherwise add them outside the durable grant. `sandbox:` adds
147
+ `run_code` to any child. Code reaches only the tools and the documents the
148
+ child was granted, so it widens nothing. `skills:` is refused in
137
149
  a background Runtime because Agent would add a `read_skill` tool outside the
138
150
  durable grant. Lifecycle keywords such as `session`, `task`, `signal`, and
139
151
  `emit` are never Agent options; the child boundary owns them. The same option
@@ -237,6 +249,46 @@ specialists continue to use the provider and Tool objects supplied by the host;
237
249
  parallel inline calls may therefore share whatever those objects close over.
238
250
  That is deliberate host policy, not an isolation guarantee.
239
251
 
252
+ ## Workers that write what they find
253
+
254
+ Give a worker the scratchpad of the agent that starts it, and its findings
255
+ land in documents the parent reads when it needs them, in place of one long
256
+ report:
257
+
258
+ ```ruby
259
+ spawn = Mistri::SubAgent.spawner(
260
+ provider: provider,
261
+ tools: [*research_tools, *Mistri::Tools.files(workspace)],
262
+ types: { "researcher" => researcher },
263
+ dispatcher: dispatcher,
264
+ runtime_factory: lambda do |spec|
265
+ Mistri::SubAgent::Runtime.new(provider: provider_for(spec), tools: tools_for(spec),
266
+ scratchpad: workspace)
267
+ end,
268
+ scratchpad: workspace,
269
+ )
270
+ agent = Mistri.agent("claude-opus-5-5", tools: [spawn], scratchpad: workspace)
271
+ ```
272
+
273
+ - The worker's large tool results are saved under `scratchpad/tool-results/`
274
+ like the parent's, so raw pages stay out of its context too.
275
+ - Its note names a folder of its own, `scratchpad/agents/<name>-<id>/`, and
276
+ asks it to write there as it goes and to name the documents in its report.
277
+ What it wrote is still there when the worker is stopped or runs out of
278
+ budget.
279
+ - A worker reaches the scratchpad through the document tools it was granted,
280
+ so keep them in the pool. A worker that was not granted `read_file` runs
281
+ without the scratchpad and without `files:`: its large results are cut, and
282
+ no document tool is added to it. A background runtime refuses that shape.
283
+ - Nothing enforces who writes where. The folder of saved results is read-only
284
+ to every model, a write over an existing document needs the version that
285
+ was read, and `edit_file` changes one place.
286
+ - Say in the worker's own prompt what to write and how to report. The gem
287
+ tells it where.
288
+ - Pass `sandbox:` as well and the worker takes what it needs out of a large
289
+ saved result with [code](tool-contracts.md#code-the-model-writes), in place
290
+ of reading it back in parts.
291
+
240
292
  ## Reports and control
241
293
 
242
294
  A background spawn returns a truthful receipt based on the child's stored
@@ -267,10 +319,27 @@ child.status # :queued, :running, :interrupted, :done, :stoppe
267
319
  child.report # terminal report when done
268
320
  child.error # terminal error when failed
269
321
  child.transcript(tail: 20) # presentation-oriented recent entries
322
+ child.transcript(from: 40, to: 60) # entries 40 to 59
323
+ child.size # how many entries the log holds
270
324
  child.say("Check pricing too") # queues a steer
271
325
  child.stop # durable if inactive, cooperative if running
272
326
  ```
273
327
 
328
+ On a store that answers `size`, a finished child is not loaded to be asked
329
+ about. The first `status`, `report` or `error` reads the last entry of its
330
+ log, and the first `transcript(tail:)` reads only the entries it returns. A
331
+ child that has not finished is read whole, and so is one that was sent
332
+ something after it ended. A `Child` that has read its log keeps it and reads
333
+ on from there, so a wait loads the log once and then only what is new.
334
+
335
+ `read_agent` shows the model a page of a worker's log, one line an entry, each
336
+ under its number. It shows the twenty most recent entries by default. `offset`
337
+ reads from another entry and `limit` sets how many, two hundred at most, and
338
+ each page gives the offset and limit that read on in either direction, so the
339
+ model can walk a long log back to its start. On a store that answers `size`
340
+ the entries of a page are read on their own. The status in its first line
341
+ costs what `status` costs, as above.
342
+
274
343
  `read_agent` with `wait: true` waits for a terminal, including across an
275
344
  interrupted worker's later queue retry or cancellation. Abort and timeout still
276
345
  end the wait in band.
@@ -346,7 +415,14 @@ Mistri.locks = Mistri::Locks::RailsCache.new(cache: Rails.cache)
346
415
  ```
347
416
 
348
417
  The cache must implement atomic `unless_exist` writes and be shared by every
349
- worker process. A local memory cache is not a cross-process adapter.
418
+ worker process. A local memory cache is not a cross-process adapter. A null
419
+ cache store, the Rails default in development and test, grants every lock:
420
+ Mistri prints a warning when it is given one, and two runs can then write one
421
+ session at once.
422
+
423
+ A configured adapter also guards every top-level `run`, `resume`, `task`, and
424
+ `compact` with the same lease a child's runner holds; see
425
+ [Concurrency and crashes](sessions.md#concurrency-and-crashes).
350
426
 
351
427
  A custom adapter implements:
352
428
 
@@ -360,6 +436,8 @@ flag?(key) -> boolean
360
436
  clear_flag(key)
361
437
  ```
362
438
 
439
+ `acquire` returns false only when the key is held; a backend failure raises.
440
+
363
441
  The current lease is a best-effort duplicate-suppression and liveness signal,
364
442
  not an ownership token or exactly-once fence. It stores no holder identity. A
365
443
  process stalled beyond the TTL can resume after another process acquires the