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
@@ -0,0 +1,12 @@
1
+ # Vendor marks
2
+
3
+ Third-party brand marks shown in the top-level README as works-with
4
+ attribution. Each is the exact artwork published by its owner; none are
5
+ redrawn. All trademarks belong to their respective owners.
6
+
7
+ - `claude-mark.svg`: the Claude sunburst, from Anthropic's published asset.
8
+ - `openai-mark.svg`: the OpenAI symbol (2025 mark), from OpenAI's published
9
+ asset; `openai-mark-dark.svg` is the same geometry with the white fill the
10
+ brand uses on dark backgrounds.
11
+ - `gemini-mark.svg`: the Gemini spark with its published gradient, from
12
+ Google's hosted asset.
@@ -0,0 +1,3 @@
1
+ <svg width="248" height="248" viewBox="0 0 248 248" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <path d="M52.4285 162.873L98.7844 136.879L99.5485 134.602L98.7844 133.334H96.4921L88.7237 132.862L62.2346 132.153L39.3113 131.207L17.0249 130.026L11.4214 128.844L6.2 121.873L6.7094 118.447L11.4214 115.257L18.171 115.847L33.0711 116.911L55.485 118.447L71.6586 119.392L95.728 121.873H99.5485L100.058 120.337L98.7844 119.392L97.7656 118.447L74.5877 102.732L49.4995 86.1905L36.3823 76.62L29.3779 71.7757L25.8121 67.2858L24.2839 57.3608L30.6515 50.2716L39.3113 50.8623L41.4763 51.4531L50.2636 58.1879L68.9842 72.7209L93.4357 90.6804L97.0015 93.6343L98.4374 92.6652L98.6571 91.9801L97.0015 89.2625L83.757 65.2772L69.621 40.8192L63.2534 30.6579L61.5978 24.632C60.9565 22.1032 60.579 20.0111 60.579 17.4246L67.8381 7.49965L71.9133 6.19995L81.7193 7.49965L85.7946 11.0443L91.9074 24.9865L101.714 46.8451L116.996 76.62L121.453 85.4816L123.873 93.6343L124.764 96.1155H126.292V94.6976L127.566 77.9197L129.858 57.3608L132.15 30.8942L132.915 23.4505L136.608 14.4708L143.994 9.62643L149.725 12.344L154.437 19.0788L153.8 23.4505L150.998 41.6463L145.522 70.1215L141.957 89.2625H143.994L146.414 86.7813L156.093 74.0206L172.266 53.698L179.398 45.6635L187.803 36.802L193.152 32.5484H203.34L210.726 43.6549L207.415 55.1159L196.972 68.3492L188.312 79.5739L175.896 96.2095L168.191 109.585L168.882 110.689L170.738 110.53L198.755 104.504L213.91 101.787L231.994 98.7149L240.144 102.496L241.036 106.395L237.852 114.311L218.495 119.037L195.826 123.645L162.07 131.592L161.696 131.893L162.137 132.547L177.36 133.925L183.855 134.279H199.774L229.447 136.524L237.215 141.605L241.8 147.867L241.036 152.711L229.065 158.737L213.019 154.956L175.45 145.977L162.587 142.787H160.805V143.85L171.502 154.366L191.242 172.089L215.82 195.011L217.094 200.682L213.91 205.172L210.599 204.699L188.949 188.394L180.544 181.069L161.696 165.118H160.422V166.772L164.752 173.152L187.803 207.771L188.949 218.405L187.294 221.832L181.308 223.959L174.813 222.777L161.187 203.754L147.305 182.486L136.098 163.345L134.745 164.2L128.075 235.42L125.019 239.082L117.887 241.8L111.902 237.31L108.718 229.984L111.902 215.452L115.722 196.547L118.779 181.541L121.58 162.873L123.291 156.636L123.14 156.219L121.773 156.449L107.699 175.752L86.304 204.699L69.3663 222.777L65.291 224.431L58.2867 220.768L58.9235 214.27L62.8713 208.48L86.304 178.705L100.44 160.155L109.551 149.507L109.462 147.967L108.959 147.924L46.6977 188.512L35.6182 189.93L30.7788 185.44L31.4156 178.115L33.7079 175.752L52.4285 162.873Z" fill="#D97757"/>
3
+ </svg>
@@ -0,0 +1,10 @@
1
+ <svg width="28" height="28" viewBox="0 0 28 28" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <path d="M14 28C14 26.0633 13.6267 24.2433 12.88 22.54C12.1567 20.8367 11.165 19.355 9.905 18.095C8.645 16.835 7.16333 15.8433 5.46 15.12C3.75667 14.3733 1.93667 14 0 14C1.93667 14 3.75667 13.6383 5.46 12.915C7.16333 12.1683 8.645 11.165 9.905 9.905C11.165 8.645 12.1567 7.16333 12.88 5.46C13.6267 3.75667 14 1.93667 14 0C14 1.93667 14.3617 3.75667 15.085 5.46C15.8317 7.16333 16.835 8.645 18.095 9.905C19.355 11.165 20.8367 12.1683 22.54 12.915C24.2433 13.6383 26.0633 14 28 14C26.0633 14 24.2433 14.3733 22.54 15.12C20.8367 15.8433 19.355 16.835 18.095 18.095C16.835 19.355 15.8317 20.8367 15.085 22.54C14.3617 24.2433 14 26.0633 14 28Z" fill="url(#paint0_radial_16771_53212)"/>
3
+ <defs>
4
+ <radialGradient id="paint0_radial_16771_53212" cx="0" cy="0" r="1" gradientUnits="userSpaceOnUse" gradientTransform="translate(2.77876 11.3795) rotate(18.6832) scale(29.8025 238.737)">
5
+ <stop offset="0.0671246" stop-color="#9168C0"/>
6
+ <stop offset="0.342551" stop-color="#5684D1"/>
7
+ <stop offset="0.672076" stop-color="#1BA1E3"/>
8
+ </radialGradient>
9
+ </defs>
10
+ </svg>
@@ -0,0 +1 @@
1
+ <svg fill="#ffffff" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20"><path d="M11.248 18.25q-.825 0-1.568-.314a4.3 4.3 0 0 1-1.32-.874 4 4 0 0 1-1.304.214 4 4 0 0 1-2.046-.544 4.27 4.27 0 0 1-1.518-1.485 4 4 0 0 1-.56-2.095q0-.48.131-1.04A4.4 4.4 0 0 1 2.04 10.71a4.07 4.07 0 0 1 .017-3.4 4.2 4.2 0 0 1 1.056-1.418 3.8 3.8 0 0 1 1.6-.842 3.9 3.9 0 0 1 .76-1.683q.593-.759 1.451-1.188a4.04 4.04 0 0 1 1.832-.429q.825 0 1.567.313.742.314 1.32.875a4 4 0 0 1 1.304-.215q1.106 0 2.046.545a4.14 4.14 0 0 1 1.501 1.485q.578.941.578 2.095 0 .48-.132 1.04.66.61 1.023 1.419.363.792.363 1.666 0 .892-.38 1.717a4.3 4.3 0 0 1-1.072 1.435 3.8 3.8 0 0 1-1.584.825 3.8 3.8 0 0 1-.775 1.683 4.06 4.06 0 0 1-1.436 1.188 4.04 4.04 0 0 1-1.832.429m-4.076-2.062q.825 0 1.435-.347l3.103-1.782a.36.36 0 0 0 .164-.313v-1.42L7.881 14.62a.67.67 0 0 1-.726 0l-3.118-1.798a.5.5 0 0 1-.017.115v.198q0 .841.396 1.551.413.693 1.139 1.089a3.2 3.2 0 0 0 1.617.412m.165-2.69a.4.4 0 0 0 .181.05q.083 0 .165-.05l1.238-.71-3.977-2.31a.7.7 0 0 1-.363-.643v-3.58q-.825.362-1.32 1.122a2.9 2.9 0 0 0-.495 1.65q0 .809.413 1.55.412.743 1.072 1.123zm3.91 3.663q.875 0 1.585-.396a2.96 2.96 0 0 0 1.534-2.64v-3.564a.32.32 0 0 0-.165-.297l-1.254-.726v4.604a.7.7 0 0 1-.363.643l-3.119 1.799a3 3 0 0 0 1.783.577m.627-6.039V8.878L10.01 7.822 8.129 8.878v2.244l1.881 1.056zM7.057 5.859a.7.7 0 0 1 .363-.644l3.119-1.798a3 3 0 0 0-1.782-.578q-.874 0-1.584.396A2.96 2.96 0 0 0 6.05 4.324a3.07 3.07 0 0 0-.396 1.551v3.547q0 .199.165.314l1.237.726zm8.383 7.887q.825-.364 1.303-1.123.495-.758.495-1.65a3.15 3.15 0 0 0-.412-1.55q-.413-.743-1.073-1.123l-3.086-1.782q-.099-.065-.181-.049a.3.3 0 0 0-.165.05l-1.238.692 3.993 2.327a.6.6 0 0 1 .264.264.64.64 0 0 1 .1.363zm-3.317-8.382a.63.63 0 0 1 .726 0l3.135 1.831v-.297q0-.792-.396-1.501a2.86 2.86 0 0 0-1.105-1.155q-.71-.43-1.65-.43-.825 0-1.436.347L8.294 5.941a.36.36 0 0 0-.165.314v1.418z"/></svg>
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20"><path d="M11.248 18.25q-.825 0-1.568-.314a4.3 4.3 0 0 1-1.32-.874 4 4 0 0 1-1.304.214 4 4 0 0 1-2.046-.544 4.27 4.27 0 0 1-1.518-1.485 4 4 0 0 1-.56-2.095q0-.48.131-1.04A4.4 4.4 0 0 1 2.04 10.71a4.07 4.07 0 0 1 .017-3.4 4.2 4.2 0 0 1 1.056-1.418 3.8 3.8 0 0 1 1.6-.842 3.9 3.9 0 0 1 .76-1.683q.593-.759 1.451-1.188a4.04 4.04 0 0 1 1.832-.429q.825 0 1.567.313.742.314 1.32.875a4 4 0 0 1 1.304-.215q1.106 0 2.046.545a4.14 4.14 0 0 1 1.501 1.485q.578.941.578 2.095 0 .48-.132 1.04.66.61 1.023 1.419.363.792.363 1.666 0 .892-.38 1.717a4.3 4.3 0 0 1-1.072 1.435 3.8 3.8 0 0 1-1.584.825 3.8 3.8 0 0 1-.775 1.683 4.06 4.06 0 0 1-1.436 1.188 4.04 4.04 0 0 1-1.832.429m-4.076-2.062q.825 0 1.435-.347l3.103-1.782a.36.36 0 0 0 .164-.313v-1.42L7.881 14.62a.67.67 0 0 1-.726 0l-3.118-1.798a.5.5 0 0 1-.017.115v.198q0 .841.396 1.551.413.693 1.139 1.089a3.2 3.2 0 0 0 1.617.412m.165-2.69a.4.4 0 0 0 .181.05q.083 0 .165-.05l1.238-.71-3.977-2.31a.7.7 0 0 1-.363-.643v-3.58q-.825.362-1.32 1.122a2.9 2.9 0 0 0-.495 1.65q0 .809.413 1.55.412.743 1.072 1.123zm3.91 3.663q.875 0 1.585-.396a2.96 2.96 0 0 0 1.534-2.64v-3.564a.32.32 0 0 0-.165-.297l-1.254-.726v4.604a.7.7 0 0 1-.363.643l-3.119 1.799a3 3 0 0 0 1.783.577m.627-6.039V8.878L10.01 7.822 8.129 8.878v2.244l1.881 1.056zM7.057 5.859a.7.7 0 0 1 .363-.644l3.119-1.798a3 3 0 0 0-1.782-.578q-.874 0-1.584.396A2.96 2.96 0 0 0 6.05 4.324a3.07 3.07 0 0 0-.396 1.551v3.547q0 .199.165.314l1.237.726zm8.383 7.887q.825-.364 1.303-1.123.495-.758.495-1.65a3.15 3.15 0 0 0-.412-1.55q-.413-.743-1.073-1.123l-3.086-1.782q-.099-.065-.181-.049a.3.3 0 0 0-.165.05l-1.238.692 3.993 2.327a.6.6 0 0 1 .264.264.64.64 0 0 1 .1.363zm-3.317-8.382a.63.63 0 0 1 .726 0l3.135 1.831v-.297q0-.792-.396-1.501a2.86 2.86 0 0 0-1.105-1.155q-.71-.43-1.65-.43-.825 0-1.436.347L8.294 5.941a.36.36 0 0 0-.165.314v1.418z"/></svg>
data/docs/README.md CHANGED
@@ -19,8 +19,9 @@ agent becomes part of a real application.
19
19
 
20
20
  | Guide | Use it when |
21
21
  | --- | --- |
22
- | [Tool contracts](tool-contracts.md) | Defining schemas, validating arguments, gating tools, returning UI data, or handing off a turn |
22
+ | [Tool contracts](tool-contracts.md) | Defining schemas, validating arguments, gating tools, returning UI data, loading tools on demand, or handing off a turn |
23
23
  | [Sessions and control](sessions.md) | Choosing a store, resuming, steering, approving, compacting, or rendering transcripts |
24
+ | [Logging](logging.md) | Turning on the run log, tuning its options, and its operational guarantees |
24
25
  | [Context and workspaces](context-and-workspaces.md) | Loading Skills and Definitions, transforming context, storing host-owned memory, or exposing editable documents |
25
26
  | [Sub-agents](sub-agents.md) | Delegating into child sessions, dispatching background workers, or exposing worker controls |
26
27
  | [MCP](mcp.md) | Connecting Streamable HTTP or stdio servers, OAuth, private networks, or large results |
@@ -34,7 +34,7 @@ files:
34
34
  skills = Mistri::Skills.load("app/agent_skills")
35
35
 
36
36
  agent = Mistri.agent(
37
- "claude-opus-4-8",
37
+ "claude-opus-5-5",
38
38
  skills: skills,
39
39
  tools: application_tools,
40
40
  )
@@ -62,6 +62,11 @@ Skill bodies are instructions, not a security boundary. Load only host-reviewed
62
62
  files, keep descriptions specific enough for correct selection, and let tool
63
63
  authorization enforce what the model may actually do.
64
64
 
65
+ The model receives a Skill body as the result of `read_skill`. Gemini treats
66
+ instructions inside a tool result as untrusted, so Mistri also puts a loaded
67
+ Skill in Gemini's system instruction. An unknown Skill name is a failed tool
68
+ result.
69
+
65
70
  ## Definitions
66
71
 
67
72
  A Definition keeps an Agent's editable prompt and host vocabulary in one
@@ -70,7 +75,7 @@ Markdown file:
70
75
  ```markdown
71
76
  ---
72
77
  role: Trip planner
73
- model: claude-opus-4-8
78
+ model: claude-opus-5-5
74
79
  tools:
75
80
  - search_flights
76
81
  - book_hotel
@@ -106,7 +111,7 @@ Pass acting identity and request-scoped services through `context:`:
106
111
 
107
112
  ```ruby
108
113
  agent = Mistri.agent(
109
- "claude-opus-4-8",
114
+ "claude-opus-5-5",
110
115
  tools: tools,
111
116
  context: { actor: current_user, tenant: current_tenant },
112
117
  before_tool: lambda { |call, tool_context|
@@ -139,6 +144,15 @@ This seam supports host redaction, retrieval, and deliberate windowing, but it
139
144
  is low-level. Preserve message order and every tool-call/result pair. A
140
145
  provider will reject a history whose correlation facts were removed.
141
146
 
147
+ After a provider's own compaction, the first message holds that provider's
148
+ block or item. Keep it first. Anthropic refuses a request with a message
149
+ before its block.
150
+
151
+ Current Claude models sign thinking against the preceding prefix. A transform
152
+ that changes between turns, including the periodic reminder below, makes the
153
+ API drop earlier thinking. The run continues and the model reasons again. See
154
+ [Thinking is signed against the prefix](reliability.md#thinking-is-signed-against-the-prefix).
155
+
142
156
  For periodic instruction reinforcement, use the built-in Reminder:
143
157
 
144
158
  ```ruby
@@ -148,7 +162,7 @@ reminder = Mistri::Reminder.every(
148
162
  )
149
163
 
150
164
  agent = Mistri.agent(
151
- "claude-opus-4-8",
165
+ "claude-opus-5-5",
152
166
  tools: tools,
153
167
  transform_context: reminder,
154
168
  )
@@ -169,6 +183,10 @@ delete(path)
169
183
  list(prefix = nil) # sorted path Strings
170
184
  ```
171
185
 
186
+ A backend may also answer `sizes(prefix = nil)`, a Hash of path to bytes in path
187
+ order. `list_files` then shows each document's size without reading it. The
188
+ built-in workspaces answer it, the Active Record one in a single query.
189
+
172
190
  A backend may additionally claim atomic conditional writes:
173
191
 
174
192
  ```ruby
@@ -196,19 +214,71 @@ committed and must read the document again. Custom four-method workspaces keep
196
214
  their existing behavior unless they explicitly return true from
197
215
  `atomic_writes?` and implement both methods.
198
216
 
199
- The conditional protocol is used by `edit_file`. `write_file` remains an
200
- intentional blind whole-document replacement, and deletion has no conditional
201
- form. When concurrent writers must preserve unrelated changes, use an anchored
202
- edit or provide a host tool with a stronger domain contract.
217
+ The conditional protocol is used by `edit_file` and `write_file`. Deletion has
218
+ no conditional form. When concurrent writers must preserve unrelated changes,
219
+ use an anchored edit or provide a host tool with a stronger domain contract.
220
+
221
+ `write_file` creates a document freely and replaces one only at the version the
222
+ model read. `read_file`, `write_file` and `edit_file` each state the document's
223
+ version, twelve characters that are the same for the same bytes in any process.
224
+ A write to an existing document without `if_version`, or with a version the
225
+ document is no longer at, is refused, and the result holds the document as it
226
+ is now with its version. On a workspace without conditional writes the check
227
+ and the write are two steps, so another process can still write between them.
228
+ The same holds where a workspace cannot take one step, as the Active Record
229
+ workspace inside a transaction the host opened, which is how a Rails test
230
+ usually runs.
231
+
232
+ For a single replacement, `edit_file` tries an exact match first, then tolerates
233
+ indentation and trailing space differences across whole lines. In that fallback,
234
+ the final line separator is replaced only when `old_string` includes it;
235
+ otherwise it stays untouched. Trailing blank lines are part of the anchor.
236
+ Replacement indentation is not adjusted automatically.
237
+
238
+ The document tools:
239
+
240
+ | Tool | What the model gets |
241
+ | --- | --- |
242
+ | `read_file` | Numbered lines with the total and the version, 20,000 bytes a call, or less where the result limit is lower. A line over 2,000 characters is shown cut, with the offset that `unit: "characters"` reads on from |
243
+ | `write_file` | Creates a document, or replaces one at `if_version` |
244
+ | `edit_file` | Replaces an exact snippet, as described above |
245
+ | `grep` | A regular expression over one document or every document under a folder, with context lines or a count. A match on a long line comes with the 150 characters on each side and its character offset in the document |
246
+ | `list_files` | Paths under a prefix with their sizes, 200 at most |
247
+ | `delete_file` | Deletes one document |
248
+
249
+ A pattern is 500 characters at most and runs with a one second timeout for
250
+ each match. One `grep` call takes five seconds at most, and starts no further
251
+ document once it has read 5 MB. It says so when it stops at either.
252
+
253
+ A document that is not valid UTF-8 is not text. `read_file` and `edit_file`
254
+ say so in place of showing it, and `grep` leaves it out and counts it.
255
+
256
+ A path from the model is checked before any workspace is asked: relative,
257
+ parts joined by `/`, no part that is empty, `.` or `..`, no backslash or
258
+ control character, 512 bytes at most. Any other path is refused with a line
259
+ that says why, on every backend alike.
260
+
261
+ Pass the workspace as `files:` and the agent binds the tools itself:
262
+
263
+ ```ruby
264
+ agent = Mistri.agent("claude-opus-5-5", files: workspace, scratchpad: scratch)
265
+ ```
266
+
267
+ With `files:` and a [scratchpad](tool-contracts.md#saving-the-whole-result) the
268
+ model sees one path space. A path under `scratchpad/` belongs to the
269
+ scratchpad's workspace, and every other path to the host's. Paths are stored
270
+ as they are, so both may be the same workspace: one table and one scope then
271
+ hold the host's documents beside the agent's. Conditional writes hold where
272
+ both workspaces make them.
203
273
 
204
- Bind one to the built-in read, write, edit, find, and list tools:
274
+ Or bind a workspace to the tools yourself and pass them in `tools:`:
205
275
 
206
276
  ```ruby
207
277
  workspace = Mistri::Workspace::Memory.new
208
278
  workspace.write("brief.md", "# Launch brief\n")
209
279
 
210
280
  agent = Mistri.agent(
211
- "claude-opus-4-8",
281
+ "claude-opus-5-5",
212
282
  tools: Mistri::Tools.files(workspace),
213
283
  system: "Read before editing. Keep the brief concise.",
214
284
  )
@@ -250,7 +320,7 @@ workspace = Mistri::Workspace::Single.new(
250
320
  read: -> { page.reload.draft_html },
251
321
  write: ->(html) { page.update!(draft_html: html) },
252
322
  synchronize: lambda do |&operation|
253
- if page.class.connection.transaction_open?
323
+ if page.class.connection_pool.with_connection(&:transaction_open?)
254
324
  raise Mistri::ConfigurationError, "page editor must run outside a transaction"
255
325
  end
256
326
 
@@ -302,7 +372,8 @@ well as other adapters, retain the legacy four-method behavior rather than
302
372
  advertise an unproved lock. Create-only conditional writes rely on the verified
303
373
  unique scope/path index. The adapter copies and freezes the scope Hash plus
304
374
  nested Hash, Array, Range, and String values at construction; atomic mode's
305
- narrower scalar contract keeps its tenant identity stable.
375
+ narrower scalar contract keeps its tenant identity stable. It measures sizes in
376
+ the database with `OCTET_LENGTH`, which SQLite has from version 3.43.
306
377
 
307
378
  Storage and schema capability are inspected on the first capability check and
308
379
  cached thereafter, off the edit path. Bind the workspace before concurrent use,
@@ -333,7 +404,7 @@ memory = Mistri::Memory.new(
333
404
  )
334
405
 
335
406
  agent = Mistri.agent(
336
- "claude-opus-4-8",
407
+ "claude-opus-5-5",
337
408
  tools: Mistri::Tools.memory(memory),
338
409
  )
339
410
  ```
data/docs/logging.md ADDED
@@ -0,0 +1,90 @@
1
+ # Logging
2
+
3
+ Assigning `Mistri.logger` makes every run log its story as one line per
4
+ meaningful beat: the input, each tool call with its arguments and duration,
5
+ each turn's token usage, retries, approvals, compaction, worker reports, and
6
+ a closing line with the outcome, elapsed time, and dollar cost whenever
7
+ pricing is known.
8
+
9
+ ```ruby
10
+ Mistri.logger = Rails.logger # or any object responding to info/warn/error
11
+ ```
12
+
13
+ ```text
14
+ [mistri 0a1b2c3d] run "What is 2 plus 3?" (gpt-6.1-sol, 3 tools)
15
+ [mistri 0a1b2c3d] turn 1 done tool_use (312 in / 48 out)
16
+ [mistri 0a1b2c3d] tool add#7f3a {"a":2,"b":3}
17
+ [mistri 0a1b2c3d] tool add#7f3a ok 12ms "5"
18
+ [mistri 0a1b2c3d] text "The sum is 5."
19
+ [mistri 0a1b2c3d] turn 2 done stop (410 in / 22 out)
20
+ [mistri 0a1b2c3d] done completed in 1.2s, 2 turns, 722 in / 70 out, $0.0042
21
+ ```
22
+
23
+ ## Reading the lines
24
+
25
+ - Every line carries the session tag, so concurrent runs stay separable and
26
+ one run is one grep. Sub-agents log under their own worker label
27
+ (`[mistri researcher#89bb20de]`) exactly once, whichever process runs them.
28
+ - A turn line lands when the model finishes speaking, so it precedes the
29
+ tool executions that turn requested.
30
+ - The short `#id` on tool lines pairs concurrent same-name calls. An
31
+ `approval needed` line carries the full call id, which is what
32
+ `session.approve` takes.
33
+ - Failed tools and retries log at warn and provider errors at error, while
34
+ expected stops (a cancel, a budget ceiling) log calmly at info and warn.
35
+ - Cached prompt tokens count toward the tokens in and are called out
36
+ (`900 in (890 cached)`). Dollar cost appears whenever pricing is known,
37
+ including a known $0.0000, which is distinct from unpriced usage.
38
+ - A `task` logs one frame around all its fix passes, reporting the validated
39
+ outcome.
40
+ - Hidden bytes in any value (control characters, Unicode line separators,
41
+ bidirectional overrides) render as visible escapes, so untrusted output
42
+ cannot forge lines or steer a terminal.
43
+
44
+ ## Options
45
+
46
+ Assign a preconfigured sink for options; a wrong assignment or option raises
47
+ at configuration time rather than leaving the log silently empty.
48
+
49
+ ```ruby
50
+ Mistri.logger = Mistri::Sinks::Logger.new(logger, content: false, level: :debug)
51
+ ```
52
+
53
+ - `content: false` keeps the whole story as metadata: names, ids, durations,
54
+ sizes, tokens, cost, and statuses. Payloads never appear, and error,
55
+ crash, and retry text reduces to its byte size while classes and reasons
56
+ stay.
57
+ - `level:` floors the ordinary lines (pass `:debug` to keep the story out of
58
+ a production logger sitting at `:info`); warnings and errors keep their
59
+ own levels. Formatting is skipped entirely when the floor level is
60
+ disabled on the host logger.
61
+ - `truncate:` bounds every rendered value (default 200 characters; `nil`
62
+ for full payloads). Truncated values carry the original payload size.
63
+ - `color:` adds ANSI color for terminal viewing; off by default.
64
+
65
+ By default the lines carry payloads: inputs, thinking, arguments, results.
66
+ That is the point in development, and it is a valid production posture too
67
+ when your log pipeline is where you want the story; use `content: false`
68
+ when payloads must stay out of a log.
69
+
70
+ ## Composing per run
71
+
72
+ `agent.run(input, &Mistri::Sinks::Logger.new(logger))` delivers the event
73
+ lines only, under a bare `[mistri]` tag, with no framing: the run and done
74
+ lines come from the Agent, so the composed form has neither. A composed sink
75
+ renders forwarded child events with their origin, since no child sink exists
76
+ to log them.
77
+
78
+ ## Operational guarantees
79
+
80
+ - Logging never breaks a run. Sink construction and every write are
81
+ contained; a failing logger warns once per run and that run's sink goes
82
+ quiet. A host exception is never replaced by a logging failure, invalid
83
+ byte sequences included.
84
+ - Logger calls are synchronous on the run's own threads, so a slow logger
85
+ slows the run. Keep the destination local (stdout, a file) and let your
86
+ log shipper make the network hop, or buffer at the logger layer.
87
+ - With no logger assigned the cost is one nil check per run. With one
88
+ assigned, streaming delta events short-circuit without allocating, and
89
+ per-line string work, tool arguments included, is bounded by the
90
+ truncation limit rather than the payload size.