ommlds 0.0.0.dev449__py3-none-any.whl → 0.0.0.dev450__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 (42) hide show
  1. ommlds/.omlish-manifests.json +1 -1
  2. ommlds/backends/google/protocol/__init__.py +3 -0
  3. ommlds/backends/google/protocol/_marshal.py +16 -0
  4. ommlds/backends/google/protocol/types.py +303 -76
  5. ommlds/backends/mlx/generation.py +1 -1
  6. ommlds/cli/main.py +27 -6
  7. ommlds/cli/sessions/chat/code.py +114 -0
  8. ommlds/cli/sessions/chat/interactive.py +2 -5
  9. ommlds/cli/sessions/chat/printing.py +1 -4
  10. ommlds/cli/sessions/chat/prompt.py +2 -2
  11. ommlds/cli/sessions/chat/state.py +1 -0
  12. ommlds/cli/sessions/chat/tools.py +3 -4
  13. ommlds/cli/tools/config.py +1 -0
  14. ommlds/cli/tools/inject.py +9 -2
  15. ommlds/minichain/backends/impls/google/chat.py +66 -11
  16. ommlds/minichain/backends/impls/google/tools.py +149 -0
  17. ommlds/minichain/lib/code/prompts.py +6 -0
  18. ommlds/minichain/lib/fs/context.py +4 -4
  19. ommlds/minichain/lib/fs/{catalog → tools}/ls.py +2 -2
  20. ommlds/minichain/lib/fs/{catalog → tools}/read.py +5 -5
  21. ommlds/minichain/lib/fs/tools/recursivels/__init__.py +0 -0
  22. ommlds/minichain/lib/todo/__init__.py +0 -0
  23. ommlds/minichain/lib/todo/context.py +27 -0
  24. ommlds/minichain/lib/todo/tools/__init__.py +0 -0
  25. ommlds/minichain/lib/todo/tools/read.py +39 -0
  26. ommlds/minichain/lib/todo/tools/write.py +275 -0
  27. ommlds/minichain/lib/todo/types.py +55 -0
  28. ommlds/minichain/tools/jsonschema.py +11 -1
  29. ommlds/minichain/tools/reflect.py +7 -0
  30. ommlds/minichain/tools/types.py +9 -0
  31. ommlds/minichain/utils.py +27 -0
  32. {ommlds-0.0.0.dev449.dist-info → ommlds-0.0.0.dev450.dist-info}/METADATA +3 -3
  33. {ommlds-0.0.0.dev449.dist-info → ommlds-0.0.0.dev450.dist-info}/RECORD +42 -30
  34. /ommlds/minichain/lib/{fs/catalog → code}/__init__.py +0 -0
  35. /ommlds/minichain/lib/fs/{catalog/recursivels → tools}/__init__.py +0 -0
  36. /ommlds/minichain/lib/fs/{catalog → tools}/recursivels/execution.py +0 -0
  37. /ommlds/minichain/lib/fs/{catalog → tools}/recursivels/rendering.py +0 -0
  38. /ommlds/minichain/lib/fs/{catalog → tools}/recursivels/running.py +0 -0
  39. {ommlds-0.0.0.dev449.dist-info → ommlds-0.0.0.dev450.dist-info}/WHEEL +0 -0
  40. {ommlds-0.0.0.dev449.dist-info → ommlds-0.0.0.dev450.dist-info}/entry_points.txt +0 -0
  41. {ommlds-0.0.0.dev449.dist-info → ommlds-0.0.0.dev450.dist-info}/licenses/LICENSE +0 -0
  42. {ommlds-0.0.0.dev449.dist-info → ommlds-0.0.0.dev450.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,27 @@
1
+ import typing as ta
2
+
3
+ from ...tools.execution.context import tool_context
4
+ from .types import TodoItem
5
+
6
+
7
+ ##
8
+
9
+
10
+ class TodoContext:
11
+ def __init__(
12
+ self,
13
+ items: ta.Sequence[TodoItem] | None = None,
14
+ ) -> None:
15
+ super().__init__()
16
+
17
+ self._items = items
18
+
19
+ def get_items(self) -> ta.Sequence[TodoItem] | None:
20
+ return self._items
21
+
22
+ def set_items(self, items: ta.Sequence[TodoItem] | None) -> None:
23
+ self._items = list(items) if items is not None else None
24
+
25
+
26
+ def todo_tool_context() -> TodoContext:
27
+ return tool_context()[TodoContext]
File without changes
@@ -0,0 +1,39 @@
1
+ from omlish import lang
2
+ from omlish.formats import json
3
+
4
+ from ....tools.execution.catalog import ToolCatalogEntry
5
+ from ....tools.execution.reflect import reflect_tool_catalog_entry
6
+ from ....tools.reflect import tool_spec_override
7
+ from ..context import todo_tool_context
8
+
9
+
10
+ ##
11
+
12
+
13
+ @tool_spec_override(
14
+ desc="""
15
+ Use this tool to read the current todo list for your current session. This tool should be used proactively and
16
+ frequently to ensure that you are aware of the status of the current subtask list.
17
+
18
+ You should make use of this tool often, especially in the following situations:
19
+ - At the beginning of conversations to see what's pending.
20
+ - Before starting new tasks to prioritize work.
21
+ - When the user asks about previous tasks or plans.
22
+ - Whenever you're uncertain about what to do next.
23
+ - After completing tasks to update your understanding of remaining work.
24
+ - After every few messages to ensure you're on track.
25
+
26
+ Usage:
27
+ - Returns a list of todo items in json format with their id, status, priority, and content.
28
+ - Use this information to track progress and plan next steps.
29
+ """,
30
+ )
31
+ def execute_todo_read_tool() -> str:
32
+ ctx = todo_tool_context()
33
+
34
+ return json.dumps_compact(ctx.get_items() or [])
35
+
36
+
37
+ @lang.cached_function
38
+ def todo_read_tool() -> ToolCatalogEntry:
39
+ return reflect_tool_catalog_entry(execute_todo_read_tool)
@@ -0,0 +1,275 @@
1
+ """
2
+ TODO:
3
+ - ContentNamespace
4
+ """
5
+ import typing as ta
6
+
7
+ from omlish import lang
8
+
9
+ from ....tools.execution.catalog import ToolCatalogEntry
10
+ from ....tools.execution.reflect import reflect_tool_catalog_entry
11
+ from ....tools.reflect import tool_spec_override
12
+ from ..context import todo_tool_context
13
+ from ..types import TODO_ITEM_FIELD_DESCS
14
+ from ..types import TodoItem
15
+
16
+
17
+ ##
18
+
19
+
20
+ @tool_spec_override(
21
+ desc=f"""
22
+ Use this tool to create and manage a structured list of todo items corresponding to subtasks for your current
23
+ session. This helps you track progress, organize complex tasks, and demonstrate thoroughness to the user. It
24
+ also helps the user understand the progress of the overall task and progress of their requests.
25
+
26
+ A todo item is comprised of the following fields:
27
+ - id: {TODO_ITEM_FIELD_DESCS['id']}
28
+ - content: {TODO_ITEM_FIELD_DESCS['content']}
29
+ - priority: {TODO_ITEM_FIELD_DESCS['priority']}
30
+ - status: {TODO_ITEM_FIELD_DESCS['status']}
31
+
32
+ Todo item priorities are as follows:
33
+ - pending: Task not yet started.
34
+ - in_progress: Currently working on (limit to ONE task at a time).
35
+ - completed: Task finished successfully.
36
+ - cancelled: Task no longer needed.
37
+
38
+ Manage todo items in the following manner:
39
+ - Update todo item status in real-time as you work.
40
+ - Mark todo items complete IMMEDIATELY after finishing (don't batch completions).
41
+ - Only have ONE todo item task in_progress at any time.
42
+ - Complete current todo item tasks before starting new ones.
43
+ - Cancel todo items that become irrelevant.
44
+
45
+ Breakdown tasks in the following manner:
46
+ - Create specific, actionable items.
47
+ - Break complex tasks into smaller, manageable steps.
48
+ - Use clear, descriptive task names.
49
+
50
+ Use this tool proactively in these scenarios:
51
+ - Complex multi-step tasks - When a task requires 3 or more distinct steps or actions.
52
+ - Non-trivial and complex tasks - Tasks that require careful planning or multiple operations.
53
+ - User explicitly requests todo list - When the user directly asks you to use the todo list.
54
+ - User provides multiple tasks - When users provide a list of things to be done (numbered or comma-separated).
55
+ - After receiving new instructions - Immediately capture user requirements as todos. Feel free to edit the todo
56
+ list based on new information.
57
+ - After completing a task - Mark it complete and add any new follow-up tasks
58
+ - When you start working on a new task, mark the todo item as in_progress. Ideally you should only have one todo
59
+ item as in_progress at a time. Complete existing tasks before starting new ones.
60
+
61
+ Skip using this tool when:
62
+ - There is only a single, straightforward task.
63
+ - The task is trivial and tracking it provides no organizational benefit.
64
+ - The task can be completed in less than 3 trivial steps.
65
+ - The task is purely conversational or informational.
66
+
67
+ You should not use this tool if there is only one trivial task to do. In this case you are better off just doing
68
+ the task directly.
69
+
70
+ ## Examples of WHEN to use the todo list
71
+
72
+ <example>
73
+ <user>
74
+ I want to add a dark mode toggle to the application settings. Make sure you run the tests and build when
75
+ you're done!
76
+ </user>
77
+ <assistant>
78
+ I'll help add a dark mode toggle to your application settings. Let me create a todo list to track this
79
+ implementation.
80
+ </assistant>
81
+ <action>
82
+ * Creates todo list with the following items *
83
+ 1. Create dark mode toggle component in Settings page
84
+ 2. Add dark mode state management (context/store)
85
+ 3. Implement CSS-in-JS styles for dark theme
86
+ 4. Update existing components to support theme switching
87
+ 5. Run tests and build process, addressing any failures or errors that occur
88
+
89
+ * Begins working on the first task *
90
+ </action>
91
+ <reasoning>
92
+ The assistant used the todo list because:
93
+ - Adding dark mode is a multi-step feature requiring UI, state management, and styling changes.
94
+ - The user explicitly requested tests and build be run afterward.
95
+ - The assistant inferred that tests and build need to pass by adding "Ensure tests and build succeed" as
96
+ the final task.
97
+ </reasoning>
98
+ </example>
99
+
100
+ <example>
101
+ <user>
102
+ Help me rename the function getCwd to getCurrentWorkingDirectory across my project
103
+ </user>
104
+ <assistant>
105
+ Let me first search through your codebase to find all occurrences of 'getCwd'.
106
+ </assistant>
107
+ <action>
108
+ * Uses grep or search tools to locate all instances of getCwd in the codebase *
109
+ </action>
110
+ <assistant>
111
+ I've found 15 instances of 'getCwd' across 8 different files. Let me create a todo list to track these
112
+ changes.
113
+ </assistant>
114
+ <action>
115
+ * Creates todo list with specific items for each file that needs updating *
116
+ </action>
117
+ <reasoning>
118
+ The assistant used the todo list because:
119
+ - First, the assistant searched to understand the scope of the task.
120
+ - Upon finding multiple occurrences across different files, it determined this was a complex task with
121
+ multiple steps.
122
+ - The todo list helps ensure every instance is tracked and updated systematically.
123
+ - This approach prevents missing any occurrences and maintains code consistency.
124
+ </reasoning>
125
+ </example>
126
+
127
+ <example>
128
+ <user>
129
+ I need to implement these features for my e-commerce site: user registration, product catalog, shopping
130
+ cart, and checkout flow.
131
+ </user>
132
+ <assistant>
133
+ I'll help implement these features. First, let's add all the features to the todo list.
134
+ </assistant>
135
+ <action>
136
+ * Creates a todo list breaking down each feature into specific tasks based on the project architecture *
137
+ </action>
138
+ <assistant>
139
+ Let's start with user registration. This will involve creating database models, API endpoints, and
140
+ frontend forms that integrate with your existing authentication system.
141
+ </assistant>
142
+ <reasoning>
143
+ The assistant used the todo list because:
144
+ - The user provided multiple complex features to implement in a comma separated list.
145
+ - The todo list helps organize these large features into manageable tasks.
146
+ - This approach allows for tracking progress across the entire implementation.
147
+ </reasoning>
148
+ </example>
149
+
150
+ <example>
151
+ <user>
152
+ Can you help optimize my React application? It's rendering slowly and has performance issues.
153
+ </user>
154
+ <assistant>
155
+ I'll help optimize your React application. First, let me examine your codebase to identify potential
156
+ performance bottlenecks.
157
+ </assistant>
158
+ <action>
159
+ * Reviews component structure, render patterns, state management, and data fetching *
160
+ </action>
161
+ <assistant>
162
+ After analyzing your codebase, I've identified several performance issues. Let me create a todo list to
163
+ track our optimization efforts.
164
+ </assistant>
165
+ <action>
166
+ * Creates todo list with the following items *
167
+ 1. Implement memoization for expensive calculations in ProductList
168
+ 2. Add virtualization for long lists in Dashboard
169
+ 3. Optimize image loading in Gallery component
170
+ 4. Fix state update loops in ShoppingCart
171
+ 5. Review bundle size and implement code splitting
172
+ </action>
173
+ <assistant>
174
+ Let's start by implementing memoization for the expensive calculations in your ProductList component.
175
+ </assistant>
176
+ <reasoning>
177
+ The assistant used the todo list because:
178
+ - First, the assistant examined the codebase to identify specific performance issues.
179
+ - Based on this analysis, it identified multiple optimization opportunities.
180
+ - Performance optimization is a non-trivial task requiring multiple steps.
181
+ - The todo list helps methodically track improvements across different components.
182
+ - This systematic approach ensures all performance bottlenecks are addressed.
183
+ </reasoning>
184
+ </example>
185
+
186
+ ## Examples of when NOT to use the todo list
187
+
188
+ <example>
189
+ <user>
190
+ How do I print 'Hello World' in Python?
191
+ </user>
192
+ <assistant>
193
+ In Python, you can print "Hello World" with this simple code:
194
+
195
+ print("Hello World")
196
+
197
+ This will output the text "Hello World" to the console when executed.
198
+ </assistant>
199
+ <reasoning>
200
+ The assistant did not use the todo list because this is a single, trivial task that can be completed in
201
+ one step. There's no need to track multiple tasks or steps for such a straightforward request.
202
+ </reasoning>
203
+ </counter>
204
+
205
+ <example>
206
+ <user>
207
+ What does the git status command do?
208
+ </user>
209
+ <assistant>
210
+ The git status command shows the current state of your working directory and staging area. It displays
211
+ which changes have been staged, which haven't, and which files aren't being tracked by Git. This is a
212
+ fundamental command for understanding the current state of your repository before making commits.
213
+ </assistant>
214
+ <reasoning>
215
+ The assistant did not use the todo list because this is an informational request with no actual coding
216
+ task to complete. The user is simply asking for an explanation, not for the assistant to perform
217
+ multiple steps or tasks.
218
+ </reasoning>
219
+ </example>
220
+
221
+ <example>
222
+ <user>
223
+ Can you add a comment to the calculateTotal function to explain what it does?
224
+ </user>
225
+ <assistant>
226
+ Sure, let me add a comment to the calculateTotal function to explain what it does.
227
+ </assistant>
228
+ <action>
229
+ * Uses the Edit tool to add a comment to the calculateTotal function *
230
+ </action>
231
+ <reasoning>
232
+ The assistant did not use the todo list because this is a single, straightforward task confined to one
233
+ location in the code. Adding a comment doesn't require tracking multiple steps or systematic
234
+ organization.
235
+ </reasoning>
236
+ </example>
237
+
238
+ <example>
239
+ <user>
240
+ Run npm install for me and tell me what happens.
241
+ </user>
242
+ <assistant>
243
+ I'll run the npm install command for you.
244
+ </assistant>
245
+ <action>
246
+ * Executes: npm install *
247
+ </action>
248
+ <assistant>
249
+ The command completed successfully. Here's the output:
250
+
251
+ [Output of npm install command]
252
+
253
+ All dependencies have been installed according to your package.json file.
254
+ </assistant>
255
+ <reasoning>
256
+ The assistant did not use the todo list because this is a single command execution with immediate
257
+ results. There are no multiple steps to track or organize, making the todo list unnecessary for this
258
+ straightforward task.
259
+ </reasoning>
260
+ </example>
261
+
262
+ When in doubt, use this tool. Being proactive with task management demonstrates attentiveness and ensures you
263
+ complete all requirements successfully.
264
+ """,
265
+ )
266
+ def execute_todo_write_tool(todo_items: ta.Sequence[TodoItem]) -> str:
267
+ ctx = todo_tool_context()
268
+ ctx.set_items(todo_items)
269
+
270
+ return 'Todo list updated.'
271
+
272
+
273
+ @lang.cached_function
274
+ def todo_write_tool() -> ToolCatalogEntry:
275
+ return reflect_tool_catalog_entry(execute_todo_write_tool)
@@ -0,0 +1,55 @@
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 = dc.field(metadata=tool_param_metadata(desc='A unique identifier for this todo item.'))
42
+ content: str = dc.field(metadata=tool_param_metadata(desc='A brief description of the task.'))
43
+ priority: ToolPriority = dc.field(metadata=tool_param_metadata(
44
+ desc=f'Priority of the task: {join_human_readable_str_list(map(repr, TOOL_PRIORITIES))}.',
45
+ ))
46
+
47
+ status: TodoStatus = dc.field(metadata=tool_param_metadata(
48
+ desc=f'Current status of the task: {join_human_readable_str_list(map(repr, TOOL_STATUSES))}.',
49
+ ))
50
+
51
+
52
+ TODO_ITEM_FIELD_DESCS: ta.Mapping[str, str] = {
53
+ f.name: f.metadata[ToolParam].desc
54
+ for f in dc.fields(TodoItem) # noqa
55
+ }
@@ -9,6 +9,7 @@ from ..content.prepare import default_content_str_preparer
9
9
  from .types import EnumToolDtype
10
10
  from .types import MappingToolDtype
11
11
  from .types import NullableToolDtype
12
+ from .types import ObjectToolDtype
12
13
  from .types import PrimitiveToolDtype
13
14
  from .types import SequenceToolDtype
14
15
  from .types import ToolDtype
@@ -72,6 +73,15 @@ class ToolJsonschemaRenderer:
72
73
  'enum': list(t.values),
73
74
  }
74
75
 
76
+ if isinstance(t, ObjectToolDtype):
77
+ return {
78
+ 'type': 'object',
79
+ 'properties': {
80
+ k: self.render_type(v)
81
+ for k, v in t.fields.items()
82
+ },
83
+ }
84
+
75
85
  raise TypeError(t)
76
86
 
77
87
  def render_tool_params(self, ts: ToolSpec) -> dict:
@@ -98,7 +108,7 @@ class ToolJsonschemaRenderer:
98
108
  }
99
109
 
100
110
  def render_tool(self, ts: ToolSpec) -> dict:
101
- pa_dct = self.render_tool_params(ts)
111
+ pa_dct = self.render_tool_params(ts) if ts.params else None
102
112
 
103
113
  ret_dct = {
104
114
  **({'description': self._content_str_preparer.prepare_str(ts.returns_desc)} if ts.returns_desc is not None else {}), # noqa
@@ -27,6 +27,7 @@ from ..content.materialize import CanContent
27
27
  from .types import EnumToolDtype
28
28
  from .types import MappingToolDtype
29
29
  from .types import NullableToolDtype
30
+ from .types import ObjectToolDtype
30
31
  from .types import PrimitiveToolDtype
31
32
  from .types import SequenceToolDtype
32
33
  from .types import ToolDtype
@@ -109,6 +110,12 @@ class ToolReflector:
109
110
  ])
110
111
 
111
112
  def reflect_type(self, rty: rfl.Type) -> ToolDtype:
113
+ if isinstance(rty, type) and dc.is_dataclass(rty):
114
+ return ObjectToolDtype({
115
+ f.name: self.reflect_type(rfl.type_(f.type))
116
+ for f in dc.fields(rty)
117
+ })
118
+
112
119
  if isinstance(rty, (type, rfl.Any)):
113
120
  return PrimitiveToolDtype.of(rty)
114
121
 
@@ -127,6 +127,15 @@ class EnumToolDtype(ToolDtype):
127
127
  values: ta.Sequence[ta.Any]
128
128
 
129
129
 
130
+ #
131
+
132
+
133
+ @dc.dataclass(frozen=True)
134
+ @dc.extra_class_params(terse_repr=True)
135
+ class ObjectToolDtype(ToolDtype):
136
+ fields: ta.Mapping[str, ToolDtype]
137
+
138
+
130
139
  ##
131
140
 
132
141
 
@@ -0,0 +1,27 @@
1
+ import typing as ta
2
+
3
+ from omlish import check
4
+ from omlish import reflect as rfl
5
+
6
+
7
+ ##
8
+
9
+
10
+ def join_human_readable_str_list(
11
+ strs: ta.Iterable[str],
12
+ *,
13
+ sep: str = ', ',
14
+ disj: str = 'or ',
15
+ ) -> str:
16
+ seq = list(strs)
17
+ return sep.join(
18
+ (disj if i == len(seq) - 1 else '') + s
19
+ for i, s in enumerate(seq)
20
+ )
21
+
22
+
23
+ ##
24
+
25
+
26
+ def str_literal_values(lit: ta.Any) -> ta.Sequence[str]:
27
+ return tuple(check.isinstance(rfl.type_(lit), rfl.Literal).args)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ommlds
3
- Version: 0.0.0.dev449
3
+ Version: 0.0.0.dev450
4
4
  Summary: ommlds
5
5
  Author: wrmsr
6
6
  License-Expression: BSD-3-Clause
@@ -14,8 +14,8 @@ Classifier: Programming Language :: Python :: 3.13
14
14
  Requires-Python: >=3.13
15
15
  Description-Content-Type: text/markdown
16
16
  License-File: LICENSE
17
- Requires-Dist: omdev==0.0.0.dev449
18
- Requires-Dist: omlish==0.0.0.dev449
17
+ Requires-Dist: omdev==0.0.0.dev450
18
+ Requires-Dist: omlish==0.0.0.dev450
19
19
  Provides-Extra: all
20
20
  Requires-Dist: llama-cpp-python~=0.3; extra == "all"
21
21
  Requires-Dist: mlx~=0.29; extra == "all"