ommlds 0.0.0.dev436__py3-none-any.whl → 0.0.0.dev480__py3-none-any.whl

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 (271) hide show
  1. ommlds/.omlish-manifests.json +332 -35
  2. ommlds/__about__.py +15 -9
  3. ommlds/_hacks/__init__.py +4 -0
  4. ommlds/_hacks/funcs.py +110 -0
  5. ommlds/_hacks/names.py +158 -0
  6. ommlds/_hacks/params.py +73 -0
  7. ommlds/_hacks/patches.py +0 -3
  8. ommlds/backends/anthropic/protocol/_marshal.py +2 -2
  9. ommlds/backends/anthropic/protocol/sse/_marshal.py +1 -1
  10. ommlds/backends/anthropic/protocol/sse/assemble.py +23 -7
  11. ommlds/backends/anthropic/protocol/sse/events.py +13 -0
  12. ommlds/backends/anthropic/protocol/types.py +30 -9
  13. ommlds/backends/google/protocol/__init__.py +3 -0
  14. ommlds/backends/google/protocol/_marshal.py +16 -0
  15. ommlds/backends/google/protocol/types.py +626 -0
  16. ommlds/backends/groq/_marshal.py +23 -0
  17. ommlds/backends/groq/protocol.py +249 -0
  18. ommlds/backends/mlx/generation.py +1 -1
  19. ommlds/backends/mlx/loading.py +58 -1
  20. ommlds/backends/ollama/__init__.py +0 -0
  21. ommlds/backends/ollama/protocol.py +170 -0
  22. ommlds/backends/openai/protocol/__init__.py +9 -28
  23. ommlds/backends/openai/protocol/_common.py +18 -0
  24. ommlds/backends/openai/protocol/_marshal.py +27 -0
  25. ommlds/backends/openai/protocol/chatcompletion/chunk.py +58 -31
  26. ommlds/backends/openai/protocol/chatcompletion/contentpart.py +49 -44
  27. ommlds/backends/openai/protocol/chatcompletion/message.py +55 -43
  28. ommlds/backends/openai/protocol/chatcompletion/request.py +114 -66
  29. ommlds/backends/openai/protocol/chatcompletion/response.py +71 -45
  30. ommlds/backends/openai/protocol/chatcompletion/responseformat.py +27 -20
  31. ommlds/backends/openai/protocol/chatcompletion/tokenlogprob.py +16 -7
  32. ommlds/backends/openai/protocol/completionusage.py +24 -15
  33. ommlds/backends/tavily/__init__.py +0 -0
  34. ommlds/backends/tavily/protocol.py +301 -0
  35. ommlds/backends/tinygrad/models/llama3/__init__.py +22 -14
  36. ommlds/backends/transformers/__init__.py +0 -0
  37. ommlds/backends/transformers/filecache.py +109 -0
  38. ommlds/backends/transformers/streamers.py +73 -0
  39. ommlds/cli/asyncs.py +30 -0
  40. ommlds/cli/backends/catalog.py +93 -0
  41. ommlds/cli/backends/configs.py +9 -0
  42. ommlds/cli/backends/inject.py +31 -36
  43. ommlds/cli/backends/injection.py +16 -0
  44. ommlds/cli/backends/types.py +46 -0
  45. ommlds/cli/content/__init__.py +0 -0
  46. ommlds/cli/content/messages.py +34 -0
  47. ommlds/cli/content/strings.py +42 -0
  48. ommlds/cli/inject.py +15 -32
  49. ommlds/cli/inputs/__init__.py +0 -0
  50. ommlds/cli/inputs/asyncs.py +32 -0
  51. ommlds/cli/inputs/sync.py +75 -0
  52. ommlds/cli/main.py +270 -110
  53. ommlds/cli/rendering/__init__.py +0 -0
  54. ommlds/cli/rendering/configs.py +9 -0
  55. ommlds/cli/rendering/inject.py +31 -0
  56. ommlds/cli/rendering/markdown.py +52 -0
  57. ommlds/cli/rendering/raw.py +73 -0
  58. ommlds/cli/rendering/types.py +21 -0
  59. ommlds/cli/secrets.py +21 -0
  60. ommlds/cli/sessions/base.py +1 -1
  61. ommlds/cli/sessions/chat/chat/__init__.py +0 -0
  62. ommlds/cli/sessions/chat/chat/ai/__init__.py +0 -0
  63. ommlds/cli/sessions/chat/chat/ai/configs.py +11 -0
  64. ommlds/cli/sessions/chat/chat/ai/inject.py +74 -0
  65. ommlds/cli/sessions/chat/chat/ai/injection.py +14 -0
  66. ommlds/cli/sessions/chat/chat/ai/rendering.py +70 -0
  67. ommlds/cli/sessions/chat/chat/ai/services.py +79 -0
  68. ommlds/cli/sessions/chat/chat/ai/tools.py +44 -0
  69. ommlds/cli/sessions/chat/chat/ai/types.py +28 -0
  70. ommlds/cli/sessions/chat/chat/state/__init__.py +0 -0
  71. ommlds/cli/sessions/chat/chat/state/configs.py +11 -0
  72. ommlds/cli/sessions/chat/chat/state/inject.py +36 -0
  73. ommlds/cli/sessions/chat/chat/state/inmemory.py +33 -0
  74. ommlds/cli/sessions/chat/chat/state/storage.py +52 -0
  75. ommlds/cli/sessions/chat/chat/state/types.py +38 -0
  76. ommlds/cli/sessions/chat/chat/user/__init__.py +0 -0
  77. ommlds/cli/sessions/chat/chat/user/configs.py +17 -0
  78. ommlds/cli/sessions/chat/chat/user/inject.py +62 -0
  79. ommlds/cli/sessions/chat/chat/user/interactive.py +31 -0
  80. ommlds/cli/sessions/chat/chat/user/oneshot.py +25 -0
  81. ommlds/cli/sessions/chat/chat/user/types.py +15 -0
  82. ommlds/cli/sessions/chat/configs.py +27 -0
  83. ommlds/cli/sessions/chat/driver.py +43 -0
  84. ommlds/cli/sessions/chat/inject.py +33 -65
  85. ommlds/cli/sessions/chat/phases/__init__.py +0 -0
  86. ommlds/cli/sessions/chat/phases/inject.py +27 -0
  87. ommlds/cli/sessions/chat/phases/injection.py +14 -0
  88. ommlds/cli/sessions/chat/phases/manager.py +29 -0
  89. ommlds/cli/sessions/chat/phases/types.py +29 -0
  90. ommlds/cli/sessions/chat/session.py +27 -0
  91. ommlds/cli/sessions/chat/tools/__init__.py +0 -0
  92. ommlds/cli/sessions/chat/tools/configs.py +22 -0
  93. ommlds/cli/sessions/chat/tools/confirmation.py +46 -0
  94. ommlds/cli/sessions/chat/tools/execution.py +66 -0
  95. ommlds/cli/sessions/chat/tools/fs/__init__.py +0 -0
  96. ommlds/cli/sessions/chat/tools/fs/configs.py +12 -0
  97. ommlds/cli/sessions/chat/tools/fs/inject.py +35 -0
  98. ommlds/cli/sessions/chat/tools/inject.py +88 -0
  99. ommlds/cli/sessions/chat/tools/injection.py +44 -0
  100. ommlds/cli/sessions/chat/tools/rendering.py +58 -0
  101. ommlds/cli/sessions/chat/tools/todo/__init__.py +0 -0
  102. ommlds/cli/sessions/chat/tools/todo/configs.py +12 -0
  103. ommlds/cli/sessions/chat/tools/todo/inject.py +31 -0
  104. ommlds/cli/sessions/chat/tools/weather/__init__.py +0 -0
  105. ommlds/cli/sessions/chat/tools/weather/configs.py +12 -0
  106. ommlds/cli/sessions/chat/tools/weather/inject.py +22 -0
  107. ommlds/cli/{tools/weather.py → sessions/chat/tools/weather/tools.py} +1 -1
  108. ommlds/cli/sessions/completion/configs.py +21 -0
  109. ommlds/cli/sessions/completion/inject.py +42 -0
  110. ommlds/cli/sessions/completion/session.py +35 -0
  111. ommlds/cli/sessions/embedding/configs.py +21 -0
  112. ommlds/cli/sessions/embedding/inject.py +42 -0
  113. ommlds/cli/sessions/embedding/session.py +33 -0
  114. ommlds/cli/sessions/inject.py +28 -11
  115. ommlds/cli/state/__init__.py +0 -0
  116. ommlds/cli/state/inject.py +28 -0
  117. ommlds/cli/{state.py → state/storage.py} +41 -24
  118. ommlds/minichain/__init__.py +84 -24
  119. ommlds/minichain/_marshal.py +49 -9
  120. ommlds/minichain/_typedvalues.py +2 -4
  121. ommlds/minichain/backends/catalogs/base.py +20 -1
  122. ommlds/minichain/backends/catalogs/simple.py +2 -2
  123. ommlds/minichain/backends/catalogs/strings.py +10 -8
  124. ommlds/minichain/backends/impls/anthropic/chat.py +65 -27
  125. ommlds/minichain/backends/impls/anthropic/names.py +10 -8
  126. ommlds/minichain/backends/impls/anthropic/protocol.py +109 -0
  127. ommlds/minichain/backends/impls/anthropic/stream.py +111 -43
  128. ommlds/minichain/backends/impls/duckduckgo/search.py +1 -1
  129. ommlds/minichain/backends/impls/dummy/__init__.py +0 -0
  130. ommlds/minichain/backends/impls/dummy/chat.py +69 -0
  131. ommlds/minichain/backends/impls/google/chat.py +114 -22
  132. ommlds/minichain/backends/impls/google/search.py +7 -2
  133. ommlds/minichain/backends/impls/google/stream.py +219 -0
  134. ommlds/minichain/backends/impls/google/tools.py +149 -0
  135. ommlds/minichain/backends/impls/groq/__init__.py +0 -0
  136. ommlds/minichain/backends/impls/groq/chat.py +75 -0
  137. ommlds/minichain/backends/impls/groq/names.py +48 -0
  138. ommlds/minichain/backends/impls/groq/protocol.py +143 -0
  139. ommlds/minichain/backends/impls/groq/stream.py +125 -0
  140. ommlds/minichain/backends/impls/llamacpp/chat.py +33 -18
  141. ommlds/minichain/backends/impls/llamacpp/completion.py +1 -1
  142. ommlds/minichain/backends/impls/llamacpp/format.py +4 -2
  143. ommlds/minichain/backends/impls/llamacpp/stream.py +37 -20
  144. ommlds/minichain/backends/impls/mistral.py +20 -5
  145. ommlds/minichain/backends/impls/mlx/chat.py +96 -22
  146. ommlds/minichain/backends/impls/ollama/__init__.py +0 -0
  147. ommlds/minichain/backends/impls/ollama/chat.py +199 -0
  148. ommlds/minichain/backends/impls/openai/chat.py +18 -8
  149. ommlds/minichain/backends/impls/openai/completion.py +10 -3
  150. ommlds/minichain/backends/impls/openai/embedding.py +10 -3
  151. ommlds/minichain/backends/impls/openai/format.py +131 -106
  152. ommlds/minichain/backends/impls/openai/names.py +31 -5
  153. ommlds/minichain/backends/impls/openai/stream.py +43 -25
  154. ommlds/minichain/backends/impls/tavily.py +66 -0
  155. ommlds/minichain/backends/impls/tinygrad/chat.py +23 -16
  156. ommlds/minichain/backends/impls/transformers/sentence.py +1 -1
  157. ommlds/minichain/backends/impls/transformers/tokens.py +1 -1
  158. ommlds/minichain/backends/impls/transformers/transformers.py +155 -34
  159. ommlds/minichain/backends/strings/parsing.py +1 -1
  160. ommlds/minichain/backends/strings/resolving.py +4 -1
  161. ommlds/minichain/chat/_marshal.py +16 -9
  162. ommlds/minichain/chat/choices/adapters.py +4 -4
  163. ommlds/minichain/chat/choices/services.py +1 -1
  164. ommlds/minichain/chat/choices/stream/__init__.py +0 -0
  165. ommlds/minichain/chat/choices/stream/adapters.py +35 -0
  166. ommlds/minichain/chat/choices/stream/joining.py +31 -0
  167. ommlds/minichain/chat/choices/stream/services.py +45 -0
  168. ommlds/minichain/chat/choices/stream/types.py +43 -0
  169. ommlds/minichain/chat/choices/types.py +2 -2
  170. ommlds/minichain/chat/history.py +3 -3
  171. ommlds/minichain/chat/messages.py +55 -19
  172. ommlds/minichain/chat/services.py +3 -3
  173. ommlds/minichain/chat/stream/_marshal.py +16 -0
  174. ommlds/minichain/chat/stream/joining.py +85 -0
  175. ommlds/minichain/chat/stream/services.py +15 -21
  176. ommlds/minichain/chat/stream/types.py +32 -19
  177. ommlds/minichain/chat/tools/execution.py +8 -7
  178. ommlds/minichain/chat/tools/ids.py +9 -15
  179. ommlds/minichain/chat/tools/parsing.py +17 -26
  180. ommlds/minichain/chat/transforms/base.py +29 -38
  181. ommlds/minichain/chat/transforms/metadata.py +30 -4
  182. ommlds/minichain/chat/transforms/services.py +9 -11
  183. ommlds/minichain/content/_marshal.py +44 -20
  184. ommlds/minichain/content/json.py +13 -0
  185. ommlds/minichain/content/materialize.py +14 -21
  186. ommlds/minichain/content/prepare.py +4 -0
  187. ommlds/minichain/content/transforms/interleave.py +1 -1
  188. ommlds/minichain/content/transforms/squeeze.py +1 -1
  189. ommlds/minichain/content/transforms/stringify.py +1 -1
  190. ommlds/minichain/json.py +20 -0
  191. ommlds/minichain/lib/code/__init__.py +0 -0
  192. ommlds/minichain/lib/code/prompts.py +6 -0
  193. ommlds/minichain/lib/fs/binfiles.py +108 -0
  194. ommlds/minichain/lib/fs/context.py +126 -0
  195. ommlds/minichain/lib/fs/errors.py +101 -0
  196. ommlds/minichain/lib/fs/suggestions.py +36 -0
  197. ommlds/minichain/lib/fs/tools/__init__.py +0 -0
  198. ommlds/minichain/lib/fs/tools/edit.py +104 -0
  199. ommlds/minichain/lib/fs/tools/ls.py +38 -0
  200. ommlds/minichain/lib/fs/tools/read.py +115 -0
  201. ommlds/minichain/lib/fs/tools/recursivels/__init__.py +0 -0
  202. ommlds/minichain/lib/fs/tools/recursivels/execution.py +40 -0
  203. ommlds/minichain/lib/todo/__init__.py +0 -0
  204. ommlds/minichain/lib/todo/context.py +54 -0
  205. ommlds/minichain/lib/todo/tools/__init__.py +0 -0
  206. ommlds/minichain/lib/todo/tools/read.py +44 -0
  207. ommlds/minichain/lib/todo/tools/write.py +335 -0
  208. ommlds/minichain/lib/todo/types.py +60 -0
  209. ommlds/minichain/llms/_marshal.py +25 -17
  210. ommlds/minichain/llms/types.py +4 -0
  211. ommlds/minichain/registries/globals.py +18 -4
  212. ommlds/minichain/resources.py +66 -43
  213. ommlds/minichain/search.py +1 -1
  214. ommlds/minichain/services/_marshal.py +46 -39
  215. ommlds/minichain/services/facades.py +3 -3
  216. ommlds/minichain/services/services.py +1 -1
  217. ommlds/minichain/standard.py +8 -0
  218. ommlds/minichain/stream/services.py +152 -38
  219. ommlds/minichain/stream/wrap.py +22 -24
  220. ommlds/minichain/tools/_marshal.py +1 -1
  221. ommlds/minichain/tools/execution/catalog.py +2 -1
  222. ommlds/minichain/tools/execution/context.py +34 -14
  223. ommlds/minichain/tools/execution/errors.py +15 -0
  224. ommlds/minichain/tools/execution/executors.py +8 -3
  225. ommlds/minichain/tools/execution/reflect.py +40 -5
  226. ommlds/minichain/tools/fns.py +46 -9
  227. ommlds/minichain/tools/jsonschema.py +14 -5
  228. ommlds/minichain/tools/reflect.py +54 -18
  229. ommlds/minichain/tools/types.py +33 -1
  230. ommlds/minichain/utils.py +27 -0
  231. ommlds/minichain/vectors/_marshal.py +11 -10
  232. ommlds/nanochat/LICENSE +21 -0
  233. ommlds/nanochat/__init__.py +0 -0
  234. ommlds/nanochat/rustbpe/LICENSE +21 -0
  235. ommlds/nanochat/tokenizers.py +406 -0
  236. ommlds/server/server.py +3 -3
  237. ommlds/specs/__init__.py +0 -0
  238. ommlds/specs/mcp/__init__.py +0 -0
  239. ommlds/specs/mcp/_marshal.py +23 -0
  240. ommlds/specs/mcp/protocol.py +266 -0
  241. ommlds/tools/git.py +27 -10
  242. ommlds/tools/ocr.py +8 -9
  243. ommlds/wiki/analyze.py +2 -2
  244. ommlds/wiki/text/mfh.py +1 -5
  245. ommlds/wiki/text/wtp.py +1 -3
  246. ommlds/wiki/utils/xml.py +5 -5
  247. {ommlds-0.0.0.dev436.dist-info → ommlds-0.0.0.dev480.dist-info}/METADATA +24 -21
  248. ommlds-0.0.0.dev480.dist-info/RECORD +427 -0
  249. ommlds/cli/backends/standard.py +0 -20
  250. ommlds/cli/sessions/chat/base.py +0 -42
  251. ommlds/cli/sessions/chat/interactive.py +0 -73
  252. ommlds/cli/sessions/chat/printing.py +0 -96
  253. ommlds/cli/sessions/chat/prompt.py +0 -143
  254. ommlds/cli/sessions/chat/state.py +0 -109
  255. ommlds/cli/sessions/chat/tools.py +0 -91
  256. ommlds/cli/sessions/completion/completion.py +0 -44
  257. ommlds/cli/sessions/embedding/embedding.py +0 -42
  258. ommlds/cli/tools/config.py +0 -13
  259. ommlds/cli/tools/inject.py +0 -64
  260. ommlds/minichain/chat/stream/adapters.py +0 -69
  261. ommlds/minichain/lib/fs/ls/execution.py +0 -32
  262. ommlds-0.0.0.dev436.dist-info/RECORD +0 -303
  263. /ommlds/{cli/tools → backends/google}/__init__.py +0 -0
  264. /ommlds/{minichain/lib/fs/ls → backends/groq}/__init__.py +0 -0
  265. /ommlds/{huggingface.py → backends/huggingface.py} +0 -0
  266. /ommlds/minichain/lib/fs/{ls → tools/recursivels}/rendering.py +0 -0
  267. /ommlds/minichain/lib/fs/{ls → tools/recursivels}/running.py +0 -0
  268. {ommlds-0.0.0.dev436.dist-info → ommlds-0.0.0.dev480.dist-info}/WHEEL +0 -0
  269. {ommlds-0.0.0.dev436.dist-info → ommlds-0.0.0.dev480.dist-info}/entry_points.txt +0 -0
  270. {ommlds-0.0.0.dev436.dist-info → ommlds-0.0.0.dev480.dist-info}/licenses/LICENSE +0 -0
  271. {ommlds-0.0.0.dev436.dist-info → ommlds-0.0.0.dev480.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,54 @@
1
+ import typing as ta
2
+
3
+ from omlish import dataclasses as dc
4
+
5
+ from ...tools.execution.context import tool_context
6
+ from .types import TodoItem
7
+
8
+
9
+ ##
10
+
11
+
12
+ def _try_int(s: str | None) -> int | None:
13
+ if s is None:
14
+ return None
15
+ try:
16
+ return int(s)
17
+ except ValueError:
18
+ return None
19
+
20
+
21
+ class TodoContext:
22
+ def __init__(
23
+ self,
24
+ items: ta.Sequence[TodoItem] | None = None,
25
+ ) -> None:
26
+ super().__init__()
27
+
28
+ self._items = items
29
+ self._next_id: int = 1
30
+
31
+ def get_items(self) -> ta.Sequence[TodoItem] | None:
32
+ return self._items
33
+
34
+ def set_items(self, items: ta.Sequence[TodoItem] | None) -> ta.Sequence[TodoItem] | None:
35
+ if items and any(item.id is None for item in items):
36
+ max_id = max([
37
+ *[ii for item in items if (ii := _try_int(item.id)) is not None],
38
+ self._next_id - 1,
39
+ ])
40
+ new_items: list[TodoItem] = []
41
+ for item in items:
42
+ if item.id is None:
43
+ item = dc.replace(item, id=str(max_id + 1))
44
+ max_id += 1
45
+ new_items.append(item)
46
+ items = new_items
47
+ self._next_id = max_id + 1
48
+
49
+ self._items = list(items) if items is not None else None
50
+ return items
51
+
52
+
53
+ def tool_todo_context() -> TodoContext:
54
+ return tool_context()[TodoContext]
File without changes
@@ -0,0 +1,44 @@
1
+ import typing as ta
2
+
3
+ from omlish import lang
4
+
5
+ from ....tools.execution.catalog import ToolCatalogEntry
6
+ from ....tools.execution.reflect import reflect_tool_catalog_entry
7
+ from ....tools.reflect import tool_spec_override
8
+ from ..context import tool_todo_context
9
+ from ..types import TodoItem
10
+
11
+
12
+ ##
13
+
14
+
15
+ @tool_spec_override(
16
+ desc="""
17
+ Use this tool to read the current todo list for your current session. This tool should be used proactively and
18
+ frequently to ensure that you are aware of the status of the current subtask list.
19
+
20
+ You should make use of this tool often, especially in the following situations:
21
+ - At the beginning of conversations to see what's pending.
22
+ - Before starting new tasks to prioritize work.
23
+ - When the user asks about previous tasks or plans.
24
+ - Whenever you're uncertain about what to do next.
25
+ - After completing tasks to update your understanding of remaining work.
26
+ - After every few messages to ensure you're on track.
27
+
28
+ Usage:
29
+ - Returns a list of todo items in json format with their id, status, priority, and content.
30
+ - Use this information to track progress and plan next steps.
31
+ """,
32
+ )
33
+ def execute_todo_read_tool() -> ta.Sequence[TodoItem]:
34
+ ctx = tool_todo_context()
35
+
36
+ return ctx.get_items() or []
37
+
38
+
39
+ @lang.cached_function
40
+ def todo_read_tool() -> ToolCatalogEntry:
41
+ return reflect_tool_catalog_entry(
42
+ execute_todo_read_tool,
43
+ marshal_output=True,
44
+ )
@@ -0,0 +1,335 @@
1
+ """
2
+ TODO:
3
+ - ContentNamespace Example materializable class
4
+ """
5
+ import typing as ta
6
+
7
+ from omlish import lang
8
+ from omlish import marshal as msh
9
+
10
+ from ....content.namespaces import ContentNamespace
11
+ from ....tools.execution.catalog import ToolCatalogEntry
12
+ from ....tools.execution.reflect import reflect_tool_catalog_entry
13
+ from ....tools.reflect import tool_spec_override
14
+ from ..context import tool_todo_context
15
+ from ..types import TODO_ITEM_FIELD_DESCS
16
+ from ..types import TodoItem
17
+
18
+
19
+ ##
20
+
21
+
22
+ class TodoWriteDescriptionChunks(ContentNamespace):
23
+ INTRO: ta.ClassVar[str] = """
24
+ Use this tool to create and manage a structured list of todo items corresponding to subtasks for your current
25
+ session. This helps you track progress, organize complex tasks, and demonstrate thoroughness to the user. It
26
+ also helps the user understand the progress of the overall task and progress of their requests.
27
+ """
28
+
29
+ FIELD_DESCRIPTIONS: ta.ClassVar[str] = f"""
30
+ A todo item is comprised of the following fields:
31
+ - id: {TODO_ITEM_FIELD_DESCS['id']}
32
+ - content: {TODO_ITEM_FIELD_DESCS['content']}
33
+ - priority: {TODO_ITEM_FIELD_DESCS['priority']}
34
+ - status: {TODO_ITEM_FIELD_DESCS['status']}
35
+ """
36
+
37
+ WHEN_USING_THIS_TOOL: ta.ClassVar[str] = """
38
+ When using the todo write tool:
39
+ - All items must be present on each use of the tool.
40
+ - All fields except the id field must be present on all items. If not given, the id field will be automatically
41
+ set to a valid integer.
42
+ - The new todo list, including any generated ids, will be returned from the tool.
43
+ """
44
+
45
+ STATUS_DESCRIPTIONS: ta.ClassVar[str] = """
46
+ Todo item statuses are as follows:
47
+ - pending: Task not yet started.
48
+ - in_progress: Currently working on (limit to ONE task at a time).
49
+ - completed: Task finished successfully.
50
+ - cancelled: Task no longer needed.
51
+ """
52
+
53
+ MANAGING_ITEMS: ta.ClassVar[str] = """
54
+ Manage todo items in the following manner:
55
+ - Update todo item status in real-time as you work.
56
+ - Mark todo items complete IMMEDIATELY after finishing (don't batch completions).
57
+ - Only have ONE todo item task in_progress at any time.
58
+ - Complete current todo item tasks before starting new ones.
59
+ - Cancel todo items that become irrelevant.
60
+ """
61
+
62
+ BREAKING_DOWN: ta.ClassVar[str] = """
63
+ Breakdown tasks in the following manner:
64
+ - Create specific, actionable items.
65
+ - Break complex tasks into smaller, manageable steps.
66
+ - Use clear, descriptive task names.
67
+ """
68
+
69
+ USE_PROACTIVELY: ta.ClassVar[str] = """
70
+ Use this tool proactively in these scenarios:
71
+ - Complex multi-step tasks - When a task requires 3 or more distinct steps or actions.
72
+ - Non-trivial and complex tasks - Tasks that require careful planning or multiple operations.
73
+ - User explicitly requests todo list - When the user directly asks you to use the todo list.
74
+ - User provides multiple tasks - When users provide a list of things to be done (numbered or comma-separated).
75
+ - After receiving new instructions - Immediately capture user requirements as todos. Feel free to edit the todo
76
+ list based on new information.
77
+ - After completing a task - Mark it complete and add any new follow-up tasks
78
+ - When you start working on a new task, mark the todo item as in_progress. Ideally you should only have one todo
79
+ item as in_progress at a time. Complete existing tasks before starting new ones.
80
+ """
81
+
82
+ SKIP_USE_WHEN: ta.ClassVar[str] = """
83
+ Skip using this tool when:
84
+ - There is only a single, straightforward task.
85
+ - The task is trivial and tracking it provides no organizational benefit.
86
+ - The task can be completed in less than 3 trivial steps.
87
+ - The task is purely conversational or informational.
88
+ """
89
+
90
+ SKIP_WHEN_TRIVIAL: ta.ClassVar[str] = """
91
+ You should not use this tool if there is only one trivial task to do. In this case you are better off just doing
92
+ the task directly.
93
+ """
94
+
95
+ EXAMPLES_WHEN_HEADER: ta.ClassVar[str] = """
96
+ ## Examples of WHEN to use the todo list
97
+ """
98
+
99
+ EXAMPLE_WHEN_1: ta.ClassVar[str] = """
100
+ <example>
101
+ <user>
102
+ I want to add a dark mode toggle to the application settings. Make sure you run the tests and build when
103
+ you're done!
104
+ </user>
105
+ <assistant>
106
+ I'll help add a dark mode toggle to your application settings. Let me create a todo list to track this
107
+ implementation.
108
+ </assistant>
109
+ <action>
110
+ * Creates todo list with the following items *
111
+ 1. Create dark mode toggle component in Settings page
112
+ 2. Add dark mode state management (context/store)
113
+ 3. Implement CSS-in-JS styles for dark theme
114
+ 4. Update existing components to support theme switching
115
+ 5. Run tests and build process, addressing any failures or errors that occur
116
+
117
+ * Begins working on the first task *
118
+ </action>
119
+ <reasoning>
120
+ The assistant used the todo list because:
121
+ - Adding dark mode is a multi-step feature requiring UI, state management, and styling changes.
122
+ - The user explicitly requested tests and build be run afterward.
123
+ - The assistant inferred that tests and build need to pass by adding "Ensure tests and build succeed" as
124
+ the final task.
125
+ </reasoning>
126
+ </example>
127
+ """
128
+
129
+ EXAMPLE_WHEN_2: ta.ClassVar[str] = """
130
+ <example>
131
+ <user>
132
+ Help me rename the function getCwd to getCurrentWorkingDirectory across my project
133
+ </user>
134
+ <assistant>
135
+ Let me first search through your codebase to find all occurrences of 'getCwd'.
136
+ </assistant>
137
+ <action>
138
+ * Uses grep or search tools to locate all instances of getCwd in the codebase *
139
+ </action>
140
+ <assistant>
141
+ I've found 15 instances of 'getCwd' across 8 different files. Let me create a todo list to track these
142
+ changes.
143
+ </assistant>
144
+ <action>
145
+ * Creates todo list with specific items for each file that needs updating *
146
+ </action>
147
+ <reasoning>
148
+ The assistant used the todo list because:
149
+ - First, the assistant searched to understand the scope of the task.
150
+ - Upon finding multiple occurrences across different files, it determined this was a complex task with
151
+ multiple steps.
152
+ - The todo list helps ensure every instance is tracked and updated systematically.
153
+ - This approach prevents missing any occurrences and maintains code consistency.
154
+ </reasoning>
155
+ </example>
156
+ """
157
+
158
+ EXAMPLE_WHEN_3: ta.ClassVar[str] = """
159
+ <example>
160
+ <user>
161
+ I need to implement these features for my e-commerce site: user registration, product catalog, shopping
162
+ cart, and checkout flow.
163
+ </user>
164
+ <assistant>
165
+ I'll help implement these features. First, let's add all the features to the todo list.
166
+ </assistant>
167
+ <action>
168
+ * Creates a todo list breaking down each feature into specific tasks based on the project architecture *
169
+ </action>
170
+ <assistant>
171
+ Let's start with user registration. This will involve creating database models, API endpoints, and
172
+ frontend forms that integrate with your existing authentication system.
173
+ </assistant>
174
+ <reasoning>
175
+ The assistant used the todo list because:
176
+ - The user provided multiple complex features to implement in a comma separated list.
177
+ - The todo list helps organize these large features into manageable tasks.
178
+ - This approach allows for tracking progress across the entire implementation.
179
+ </reasoning>
180
+ </example>
181
+ """
182
+
183
+ EXAMPLE_WHEN_4: ta.ClassVar[str] = """
184
+ <example>
185
+ <user>
186
+ Can you help optimize my React application? It's rendering slowly and has performance issues.
187
+ </user>
188
+ <assistant>
189
+ I'll help optimize your React application. First, let me examine your codebase to identify potential
190
+ performance bottlenecks.
191
+ </assistant>
192
+ <action>
193
+ * Reviews component structure, render patterns, state management, and data fetching *
194
+ </action>
195
+ <assistant>
196
+ After analyzing your codebase, I've identified several performance issues. Let me create a todo list to
197
+ track our optimization efforts.
198
+ </assistant>
199
+ <action>
200
+ * Creates todo list with the following items *
201
+ 1. Implement memoization for expensive calculations in ProductList
202
+ 2. Add virtualization for long lists in Dashboard
203
+ 3. Optimize image loading in Gallery component
204
+ 4. Fix state update loops in ShoppingCart
205
+ 5. Review bundle size and implement code splitting
206
+ </action>
207
+ <assistant>
208
+ Let's start by implementing memoization for the expensive calculations in your ProductList component.
209
+ </assistant>
210
+ <reasoning>
211
+ The assistant used the todo list because:
212
+ - First, the assistant examined the codebase to identify specific performance issues.
213
+ - Based on this analysis, it identified multiple optimization opportunities.
214
+ - Performance optimization is a non-trivial task requiring multiple steps.
215
+ - The todo list helps methodically track improvements across different components.
216
+ - This systematic approach ensures all performance bottlenecks are addressed.
217
+ </reasoning>
218
+ </example>
219
+ """
220
+
221
+ EXAMPLES_WHEN_NOT_HEADER: ta.ClassVar[str] = """
222
+ ## Examples of when NOT to use the todo list
223
+ """
224
+
225
+ EXAMPLE_WHEN_NOT_1: ta.ClassVar[str] = """
226
+ <example>
227
+ <user>
228
+ How do I print 'Hello World' in Python?
229
+ </user>
230
+ <assistant>
231
+ In Python, you can print "Hello World" with this simple code:
232
+
233
+ print("Hello World")
234
+
235
+ This will output the text "Hello World" to the console when executed.
236
+ </assistant>
237
+ <reasoning>
238
+ The assistant did not use the todo list because this is a single, trivial task that can be completed in
239
+ one step. There's no need to track multiple tasks or steps for such a straightforward request.
240
+ </reasoning>
241
+ </example>
242
+ """
243
+
244
+ EXAMPLE_WHEN_NOT_2: ta.ClassVar[str] = """
245
+ <example>
246
+ <user>
247
+ What does the git status command do?
248
+ </user>
249
+ <assistant>
250
+ The git status command shows the current state of your working directory and staging area. It displays
251
+ which changes have been staged, which haven't, and which files aren't being tracked by Git. This is a
252
+ fundamental command for understanding the current state of your repository before making commits.
253
+ </assistant>
254
+ <reasoning>
255
+ The assistant did not use the todo list because this is an informational request with no actual coding
256
+ task to complete. The user is simply asking for an explanation, not for the assistant to perform
257
+ multiple steps or tasks.
258
+ </reasoning>
259
+ </example>
260
+ """
261
+
262
+ EXAMPLE_WHEN_NOT_3: ta.ClassVar[str] = """
263
+ <example>
264
+ <user>
265
+ Can you add a comment to the calculateTotal function to explain what it does?
266
+ </user>
267
+ <assistant>
268
+ Sure, let me add a comment to the calculateTotal function to explain what it does.
269
+ </assistant>
270
+ <action>
271
+ * Uses the Edit tool to add a comment to the calculateTotal function *
272
+ </action>
273
+ <reasoning>
274
+ The assistant did not use the todo list because this is a single, straightforward task confined to one
275
+ location in the code. Adding a comment doesn't require tracking multiple steps or systematic
276
+ organization.
277
+ </reasoning>
278
+ </example>
279
+ """
280
+
281
+ EXAMPLE_WHEN_NOT_4: ta.ClassVar[str] = """
282
+ <example>
283
+ <user>
284
+ Run npm install for me and tell me what happens.
285
+ </user>
286
+ <assistant>
287
+ I'll run the npm install command for you.
288
+ </assistant>
289
+ <action>
290
+ * Executes: npm install *
291
+ </action>
292
+ <assistant>
293
+ The command completed successfully. Here's the output:
294
+
295
+ [Output of npm install command]
296
+
297
+ All dependencies have been installed according to your package.json file.
298
+ </assistant>
299
+ <reasoning>
300
+ The assistant did not use the todo list because this is a single command execution with immediate
301
+ results. There are no multiple steps to track or organize, making the todo list unnecessary for this
302
+ straightforward task.
303
+ </reasoning>
304
+ </example>
305
+ """
306
+
307
+ OUTRO: ta.ClassVar[str] = """
308
+ When in doubt, use this tool. Being proactive with task management demonstrates attentiveness and ensures you
309
+ complete all requirements successfully.
310
+ """
311
+
312
+
313
+ @tool_spec_override(
314
+ desc=TodoWriteDescriptionChunks,
315
+ )
316
+ def execute_todo_write_tool(todo_items: ta.Sequence[TodoItem]) -> ta.Sequence[TodoItem]:
317
+ if todo_items:
318
+ todo_items = [
319
+ msh.unmarshal(o, TodoItem) if not isinstance(o, TodoItem) else o # noqa
320
+ for o in todo_items
321
+ ]
322
+
323
+ ctx = tool_todo_context()
324
+ out_items = ctx.set_items(todo_items)
325
+
326
+ return out_items or []
327
+
328
+
329
+ @lang.cached_function
330
+ def todo_write_tool() -> ToolCatalogEntry:
331
+ return reflect_tool_catalog_entry(
332
+ execute_todo_write_tool,
333
+ marshal_input=True,
334
+ marshal_output=True,
335
+ )
@@ -0,0 +1,60 @@
1
+ """
2
+ TODO:
3
+ - enums lol
4
+ - * with ToolParam-like desc metadata somehow *
5
+ """
6
+ import dataclasses as dc
7
+ import typing as ta
8
+
9
+ from omlish import lang
10
+
11
+ from ...tools.reflect import tool_param_metadata
12
+ from ...tools.types import ToolParam
13
+ from ...utils import join_human_readable_str_list
14
+ from ...utils import str_literal_values
15
+
16
+
17
+ ##
18
+
19
+
20
+ TodoStatus: ta.TypeAlias = ta.Literal[
21
+ 'pending',
22
+ 'in_progress',
23
+ 'completed',
24
+ 'cancelled',
25
+ ]
26
+
27
+ TOOL_STATUSES: ta.Sequence[str] = str_literal_values(TodoStatus)
28
+
29
+
30
+ ToolPriority: ta.TypeAlias = ta.Literal[
31
+ 'high',
32
+ 'medium',
33
+ 'low',
34
+ ]
35
+
36
+ TOOL_PRIORITIES: ta.Sequence[str] = str_literal_values(ToolPriority)
37
+
38
+
39
+ @dc.dataclass(frozen=True, kw_only=True)
40
+ class TodoItem(lang.Final):
41
+ id: str | None = dc.field(default=None, metadata=tool_param_metadata(
42
+ desc=(
43
+ 'A unique identifier for this todo item within the current session. '
44
+ 'If this is not provided it will be automatically set to an integer.'
45
+ ),
46
+ ))
47
+ content: str = dc.field(metadata=tool_param_metadata(desc='A brief description of the task.'))
48
+ priority: ToolPriority = dc.field(metadata=tool_param_metadata(
49
+ desc=f'Priority of the task: {join_human_readable_str_list(map(repr, TOOL_PRIORITIES))}.',
50
+ ))
51
+
52
+ status: TodoStatus = dc.field(metadata=tool_param_metadata(
53
+ desc=f'Current status of the task: {join_human_readable_str_list(map(repr, TOOL_STATUSES))}.',
54
+ ))
55
+
56
+
57
+ TODO_ITEM_FIELD_DESCS: ta.Mapping[str, str] = {
58
+ f.name: f.metadata[ToolParam].desc
59
+ for f in dc.fields(TodoItem) # noqa
60
+ }
@@ -2,6 +2,8 @@
2
2
  TODO:
3
3
  - can this for reuse
4
4
  """
5
+ import typing as ta
6
+
5
7
  from omlish import check
6
8
  from omlish import dataclasses as dc
7
9
  from omlish import lang
@@ -14,35 +16,41 @@ from .tokens import Tokens
14
16
  ##
15
17
 
16
18
 
17
- class TokensMarshalerFactory(msh.SimpleMarshalerFactory):
18
- def guard(self, ctx: msh.MarshalContext, rty: rfl.Type) -> bool:
19
- return rty is Tokens
19
+ class TokensMarshalerFactory(msh.MarshalerFactory):
20
+ def make_marshaler(self, ctx: msh.MarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], msh.Marshaler] | None:
21
+ if rty is not Tokens:
22
+ return None
20
23
 
21
- def fn(self, ctx: msh.MarshalContext, rty: rfl.Type) -> msh.Marshaler:
22
- rty = check.isinstance(check.is_(rty, Tokens), type)
23
- dc_rfl = dc.reflect(rty)
24
+ dc_rfl = dc.reflect(Tokens)
24
25
  dc_f = check.single(dc_rfl.fields.values())
25
26
  v_rty = rfl.type_(dc_f.type)
26
- v_m = ctx.make(v_rty)
27
+ v_m = ctx.make_marshaler(v_rty)
27
28
  f_n = dc_f.name
28
- return msh.WrappedMarshaler(lambda _, o: getattr(o, f_n), v_m)
29
+
30
+ def inner() -> msh.Marshaler:
31
+ return msh.WrappedMarshaler(lambda _, o: getattr(o, f_n), v_m)
32
+
33
+ return inner
29
34
 
30
35
 
31
- class TokensUnmarshalerFactory(msh.SimpleUnmarshalerFactory):
32
- def guard(self, ctx: msh.UnmarshalContext, rty: rfl.Type) -> bool:
33
- return rty is Tokens
36
+ class TokensUnmarshalerFactory(msh.UnmarshalerFactory):
37
+ def make_unmarshaler(self, ctx: msh.UnmarshalFactoryContext, rty: rfl.Type) -> ta.Callable[[], msh.Unmarshaler] | None: # noqa
38
+ if rty is not Tokens:
39
+ return None
34
40
 
35
- def fn(self, ctx: msh.UnmarshalContext, rty: rfl.Type) -> msh.Unmarshaler:
36
- rty = check.isinstance(check.is_(rty, Tokens), type)
37
- dc_rfl = dc.reflect(rty)
41
+ dc_rfl = dc.reflect(Tokens)
38
42
  dc_f = check.single(dc_rfl.fields.values())
39
43
  v_rty = rfl.type_(dc_f.type)
40
- v_u = ctx.make(v_rty)
41
- return msh.WrappedUnmarshaler(lambda _, v: rty(v), v_u)
44
+ v_u = ctx.make_unmarshaler(v_rty)
45
+
46
+ def inner() -> msh.Unmarshaler:
47
+ return msh.WrappedUnmarshaler(lambda _, v: Tokens(v), v_u)
48
+
49
+ return inner
42
50
 
43
51
 
44
52
  @lang.static_init
45
- def _install_standard_marshalling() -> None:
53
+ def _install_standard_marshaling() -> None:
46
54
  msh.install_standard_factories(
47
55
  TokensMarshalerFactory(),
48
56
  TokensUnmarshalerFactory(),
@@ -31,6 +31,10 @@ class MaxTokens(LlmOption, tv.UniqueScalarTypedValue[int]):
31
31
  pass
32
32
 
33
33
 
34
+ class MaxCompletionTokens(LlmOption, tv.UniqueScalarTypedValue[int]):
35
+ pass
36
+
37
+
34
38
  ##
35
39
 
36
40
 
@@ -98,20 +98,34 @@ def register_type(
98
98
 
99
99
 
100
100
  @ta.overload
101
- def registry_new(cls: type[T], name: str, *args: ta.Any, **kwargs: ta.Any) -> T:
101
+ def get_registry_cls(cls: type[T], name: str) -> type[T]:
102
102
  ...
103
103
 
104
104
 
105
105
  @ta.overload
106
- def registry_new(cls: ta.Any, name: str, *args: ta.Any, **kwargs: ta.Any) -> ta.Any:
106
+ def get_registry_cls(cls: ta.Any, name: str) -> ta.Any:
107
107
  ...
108
108
 
109
109
 
110
- def registry_new(cls, name, *args, **kwargs):
110
+ def get_registry_cls(cls, name, *args, **kwargs):
111
111
  be_cls = _GlobalRegistry.instance().get_registry_cls(cls, name)
112
112
  if isinstance(cls, type):
113
113
  be_cls = check.issubclass(be_cls, cls) # noqa
114
- return be_cls(*args, **kwargs)
114
+ return be_cls
115
+
116
+
117
+ @ta.overload
118
+ def registry_new(cls: type[T], name: str, *args: ta.Any, **kwargs: ta.Any) -> T:
119
+ ...
120
+
121
+
122
+ @ta.overload
123
+ def registry_new(cls: ta.Any, name: str, *args: ta.Any, **kwargs: ta.Any) -> ta.Any:
124
+ ...
125
+
126
+
127
+ def registry_new(cls, name, *args, **kwargs):
128
+ return get_registry_cls(cls, name)(*args, **kwargs)
115
129
 
116
130
 
117
131
  #