mindroot 9.24.0__py3-none-any.whl → 10.0.0__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.
Potentially problematic release.
This version of mindroot might be problematic. Click here for more details.
- mindroot/coreplugins/chat/static/js/chat.js +13 -2
- mindroot/coreplugins/chat/static/js/chatform.js +1 -1
- mindroot/coreplugins/check_list/helpers.py +221 -0
- mindroot/coreplugins/check_list/mod.py +383 -126
- mindroot/coreplugins/check_list/mod.py.backup +378 -0
- mindroot/coreplugins/check_list/mod.py.backup2 +506 -0
- mindroot/coreplugins/check_list/mod.py.backup3 +506 -0
- mindroot/coreplugins/check_list/plugin_info.json +14 -0
- mindroot/lib/buchatlog3.py +592 -0
- mindroot/lib/chatlog.py +155 -5
- {mindroot-9.24.0.dist-info → mindroot-10.0.0.dist-info}/METADATA +1 -1
- {mindroot-9.24.0.dist-info → mindroot-10.0.0.dist-info}/RECORD +16 -10
- {mindroot-9.24.0.dist-info → mindroot-10.0.0.dist-info}/WHEEL +0 -0
- {mindroot-9.24.0.dist-info → mindroot-10.0.0.dist-info}/entry_points.txt +0 -0
- {mindroot-9.24.0.dist-info → mindroot-10.0.0.dist-info}/licenses/LICENSE +0 -0
- {mindroot-9.24.0.dist-info → mindroot-10.0.0.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
"""
|
|
2
|
+
checklist helper for an LLM‑agent system
|
|
3
|
+
—————————————————————————————————————————————————————————————————————————————
|
|
4
|
+
Purpose
|
|
5
|
+
-------
|
|
6
|
+
• Parse a Markdown "##\tChecklist" section where each subtask is
|
|
7
|
+
written as a task‑list line:
|
|
8
|
+
|
|
9
|
+
- [ ] label of subtask
|
|
10
|
+
arbitrary markdown body… (until next task or heading)
|
|
11
|
+
|
|
12
|
+
• Store parsed tasks + cursor in `context.data['checklist']`.
|
|
13
|
+
|
|
14
|
+
• Runtime helpers:
|
|
15
|
+
load_checklist(md, ctx) → parse markdown + reset state
|
|
16
|
+
complete_subtask(subtask_id, context) → mark subtask done, advance cursor
|
|
17
|
+
goto_subtask(subtask_id, context) → move to a specific subtask
|
|
18
|
+
clear_subtask(subtask_id, context) → mark a subtask as incomplete
|
|
19
|
+
get_checklist_status(context) → show the full checklist status
|
|
20
|
+
|
|
21
|
+
`complete_subtask` and other commands live at module level so the agent can call them
|
|
22
|
+
as tools. No third‑party deps—only Python's `re` module.
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
import re
|
|
26
|
+
from lib.providers.commands import command, command_manager
|
|
27
|
+
from lib.providers.services import service
|
|
28
|
+
import traceback
|
|
29
|
+
|
|
30
|
+
# ---------- parsing ------------------------------------------------------
|
|
31
|
+
|
|
32
|
+
# Only match top-level checklist items (no indentation at start of line)
|
|
33
|
+
TASK_RE = re.compile(r'^-\s*\[(?P<done>[ xX])\]\s*(?P<label>.*?)\s*$')
|
|
34
|
+
HEADER_RE = re.compile(r'^#{1,6}\s') # any Markdown heading
|
|
35
|
+
CHECKLIST_HEADER_RE = re.compile(r'^#{1,6}\s+Checklist\b', re.IGNORECASE) # Checklist heading
|
|
36
|
+
|
|
37
|
+
def _parse(md: str):
|
|
38
|
+
"""Extract tasks as a list of dicts: {label, body, done}."""
|
|
39
|
+
lines, tasks, i = md.splitlines(), [], 0
|
|
40
|
+
while i < len(lines):
|
|
41
|
+
# Skip lines that start with whitespace (nested items)
|
|
42
|
+
if lines[i].startswith(' ') or lines[i].startswith('\t'):
|
|
43
|
+
i += 1
|
|
44
|
+
continue
|
|
45
|
+
m = TASK_RE.match(lines[i])
|
|
46
|
+
if not m: # not a task‑list line
|
|
47
|
+
i += 1
|
|
48
|
+
continue
|
|
49
|
+
|
|
50
|
+
done = m.group("done").strip().lower() in ("x", "✓")
|
|
51
|
+
label = m.group("label").strip()
|
|
52
|
+
|
|
53
|
+
# collect everything until next task or heading
|
|
54
|
+
body_lines = []
|
|
55
|
+
i += 1
|
|
56
|
+
while i < len(lines) and not (
|
|
57
|
+
# Stop at next top-level task or heading
|
|
58
|
+
(TASK_RE.match(lines[i]) and not (lines[i].startswith(' ') or lines[i].startswith('\t'))) or
|
|
59
|
+
HEADER_RE.match(lines[i])
|
|
60
|
+
):
|
|
61
|
+
body_lines.append(lines[i])
|
|
62
|
+
i += 1
|
|
63
|
+
|
|
64
|
+
tasks.append({
|
|
65
|
+
"label": label,
|
|
66
|
+
"body": "\n".join(body_lines).strip(),
|
|
67
|
+
"done": done,
|
|
68
|
+
})
|
|
69
|
+
return tasks
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def extract_checklist_section(md: str):
|
|
73
|
+
"""Extract checklist items from the entire markdown text.
|
|
74
|
+
|
|
75
|
+
No longer requires a specific 'Checklist' heading - processes the entire text
|
|
76
|
+
and extracts only top-level checklist items, leaving nested ones intact.
|
|
77
|
+
"""
|
|
78
|
+
return md # Return the entire text for processing
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
# ---------- state helpers ------------------------------------------------
|
|
82
|
+
|
|
83
|
+
def _state(ctx):
|
|
84
|
+
"""Return the mutable checklist state in ctx.data."""
|
|
85
|
+
return ctx.data.setdefault("checklist", {"tasks": [], "cursor": 0})
|
|
86
|
+
|
|
87
|
+
def load_checklist(md: str, ctx):
|
|
88
|
+
"""Parse markdown and reset cursor to first unchecked subtask."""
|
|
89
|
+
st = _state(ctx)
|
|
90
|
+
st["tasks"] = _parse(md)
|
|
91
|
+
st["cursor"] = next(
|
|
92
|
+
(i for i, t in enumerate(st["tasks"]) if not t["done"]),
|
|
93
|
+
len(st["tasks"]),
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
@service()
|
|
98
|
+
async def load_checklist_from_instructions(md: str, context=None):
|
|
99
|
+
"""Load checklist from instructions.
|
|
100
|
+
|
|
101
|
+
Processes the entire text and extracts top-level checklist items.
|
|
102
|
+
|
|
103
|
+
Example:
|
|
104
|
+
{ "load_checklist_from_instructions": { "md": "Full instructions with embedded checklist" } }
|
|
105
|
+
"""
|
|
106
|
+
checklist_section = extract_checklist_section(md)
|
|
107
|
+
load_checklist(checklist_section, context)
|
|
108
|
+
return f"Loaded checklist from instructions.\n\n{_format_checklist_status(context)}"
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
# ---------- helper functions ---------------------------------------------
|
|
112
|
+
|
|
113
|
+
def _resolve_subtask_id(subtask_id, context):
|
|
114
|
+
"""Resolve a subtask_id to an index (0-based).
|
|
115
|
+
|
|
116
|
+
subtask_id can be:
|
|
117
|
+
- A number (1-based index, converted to 0-based)
|
|
118
|
+
- A string matching a subtask label
|
|
119
|
+
- None/default (-1) to use the current cursor position
|
|
120
|
+
"""
|
|
121
|
+
st = _state(context)
|
|
122
|
+
|
|
123
|
+
# Default to current cursor position
|
|
124
|
+
if subtask_id is None or subtask_id == -1:
|
|
125
|
+
return st["cursor"]
|
|
126
|
+
|
|
127
|
+
# If it's a number, convert from 1-based to 0-based
|
|
128
|
+
if isinstance(subtask_id, int):
|
|
129
|
+
idx = subtask_id - 1
|
|
130
|
+
else:
|
|
131
|
+
# It's a string, try to find a matching label
|
|
132
|
+
for i, task in enumerate(st["tasks"]):
|
|
133
|
+
if task["label"] == subtask_id:
|
|
134
|
+
return i
|
|
135
|
+
# No match found
|
|
136
|
+
return -1
|
|
137
|
+
|
|
138
|
+
return idx
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def _format_checklist_status(context):
|
|
142
|
+
"""Format the full checklist status as a markdown string."""
|
|
143
|
+
st = _state(context)
|
|
144
|
+
if not st["tasks"]:
|
|
145
|
+
return "_No checklist found. Make sure to include a checklist in your instructions._"
|
|
146
|
+
|
|
147
|
+
lines = ["### Checklist Status\n"]
|
|
148
|
+
|
|
149
|
+
for i, task in enumerate(st["tasks"]):
|
|
150
|
+
# Determine status indicator
|
|
151
|
+
if i == st["cursor"]:
|
|
152
|
+
status = "➡️ " # Current task
|
|
153
|
+
elif task["done"]:
|
|
154
|
+
status = "✅ " # Completed
|
|
155
|
+
else:
|
|
156
|
+
status = "❌ " # Not completed
|
|
157
|
+
|
|
158
|
+
# Add task line
|
|
159
|
+
lines.append(f"{status}**Subtask**: {task['label']}")
|
|
160
|
+
|
|
161
|
+
return "\n".join(lines)
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
# ---------- module‑level tool commands ----------------------------------
|
|
165
|
+
|
|
166
|
+
@command()
|
|
167
|
+
async def complete_subtask(subtask_id=None, context=None):
|
|
168
|
+
"""
|
|
169
|
+
Mark a subtask complete and return a Markdown status message.
|
|
170
|
+
|
|
171
|
+
Parameters:
|
|
172
|
+
- subtask_id: Optional. The subtask to complete, specified by:
|
|
173
|
+
- The exact subtask label text
|
|
174
|
+
- Omit to complete the current subtask
|
|
175
|
+
|
|
176
|
+
Example:
|
|
177
|
+
{ "complete_subtask": {} } # Complete current subtask
|
|
178
|
+
{ "complete_subtask": { "subtask_id": "Review documents" } } # Complete by label
|
|
179
|
+
"""
|
|
180
|
+
if context is None:
|
|
181
|
+
return "_Context is required._"
|
|
182
|
+
|
|
183
|
+
st = _state(context)
|
|
184
|
+
if not st["tasks"]:
|
|
185
|
+
try:
|
|
186
|
+
print("Loading checklist from instructions...")
|
|
187
|
+
print("Agent is")
|
|
188
|
+
print(context.agent)
|
|
189
|
+
instructions = context.agent["instructions"]
|
|
190
|
+
await load_checklist_from_instructions(instructions, context)
|
|
191
|
+
except Exception as e:
|
|
192
|
+
print(f"Error loading checklist: {e}")
|
|
193
|
+
trace = traceback.format_exc()
|
|
194
|
+
print(trace)
|
|
195
|
+
return "_No checklist found. Make sure to include a checklist in your instructions._"
|
|
196
|
+
|
|
197
|
+
idx = _resolve_subtask_id(subtask_id, context)
|
|
198
|
+
if idx < 0 or idx >= len(st["tasks"]):
|
|
199
|
+
return "_Invalid subtask identifier._"
|
|
200
|
+
|
|
201
|
+
# mark as done
|
|
202
|
+
done_task = st["tasks"][idx]
|
|
203
|
+
done_task["done"] = True
|
|
204
|
+
|
|
205
|
+
# advance cursor to next open subtask
|
|
206
|
+
st["cursor"] = next(
|
|
207
|
+
(i for i, t in enumerate(st["tasks"][idx + 1:], idx + 1) if not t["done"]),
|
|
208
|
+
len(st["tasks"]),
|
|
209
|
+
)
|
|
210
|
+
|
|
211
|
+
# build markdown response
|
|
212
|
+
completed = f"Completed Subtask {idx+1}: - [x] {done_task['label']}"
|
|
213
|
+
if st["cursor"] >= len(st["tasks"]):
|
|
214
|
+
return f"{completed}\n\nAll subtasks complete ✅\n\n{_format_checklist_status(context)}"
|
|
215
|
+
|
|
216
|
+
next_task = st["tasks"][st['cursor']]
|
|
217
|
+
return f"""
|
|
218
|
+
{completed}
|
|
219
|
+
|
|
220
|
+
Next subtask (Subtask {st['cursor']+1})
|
|
221
|
+
- [ ] {next_task['label']}
|
|
222
|
+
{next_task['body']}
|
|
223
|
+
|
|
224
|
+
{_format_checklist_status(context)}
|
|
225
|
+
"""
|
|
226
|
+
|
|
227
|
+
@command()
|
|
228
|
+
async def goto_subtask(subtask_id, context=None):
|
|
229
|
+
"""
|
|
230
|
+
Move to a specific subtask without changing its completion status.
|
|
231
|
+
|
|
232
|
+
Parameters:
|
|
233
|
+
- subtask_id: Required. The subtask to navigate to, specified by:
|
|
234
|
+
- The exact subtask label text
|
|
235
|
+
|
|
236
|
+
Example:
|
|
237
|
+
{ "goto_subtask": { "subtask_id": "Data analysis" } } # Go to by label
|
|
238
|
+
"""
|
|
239
|
+
if context is None:
|
|
240
|
+
return "_Context is required._"
|
|
241
|
+
|
|
242
|
+
st = _state(context)
|
|
243
|
+
if not st["tasks"]:
|
|
244
|
+
return "_No checklist found. Make sure to include a checklist in your instructions._"
|
|
245
|
+
|
|
246
|
+
idx = _resolve_subtask_id(subtask_id, context)
|
|
247
|
+
if idx < 0 or idx >= len(st["tasks"]):
|
|
248
|
+
return "_Invalid subtask identifier._"
|
|
249
|
+
|
|
250
|
+
# Update cursor position
|
|
251
|
+
st["cursor"] = idx
|
|
252
|
+
|
|
253
|
+
# Get the current task
|
|
254
|
+
current_task = st["tasks"][idx]
|
|
255
|
+
|
|
256
|
+
# Build response
|
|
257
|
+
status = "✅" if current_task["done"] else "❌"
|
|
258
|
+
return (
|
|
259
|
+
f"Moved to Subtask {idx+1}: {status} {current_task['label']}\n"
|
|
260
|
+
f"{current_task['body']}\n\n"
|
|
261
|
+
f"{_format_checklist_status(context)}"
|
|
262
|
+
)
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
@command()
|
|
266
|
+
async def clear_subtask(subtask_id=None, context=None):
|
|
267
|
+
"""
|
|
268
|
+
Mark a subtask as incomplete (not done).
|
|
269
|
+
|
|
270
|
+
Parameters:
|
|
271
|
+
- subtask_id: Optional. The subtask to clear, specified by:
|
|
272
|
+
- The exact subtask label text
|
|
273
|
+
- Omit to clear the current subtask
|
|
274
|
+
|
|
275
|
+
Example:
|
|
276
|
+
{ "clear_subtask": {} } # Clear current subtask
|
|
277
|
+
{ "clear_subtask": { "subtask_id": "Review documents" } } # Clear by label
|
|
278
|
+
"""
|
|
279
|
+
if context is None:
|
|
280
|
+
return "_Context is required._"
|
|
281
|
+
|
|
282
|
+
st = _state(context)
|
|
283
|
+
if not st["tasks"]:
|
|
284
|
+
return "_No checklist found. Make sure to include a checklist in your instructions._"
|
|
285
|
+
|
|
286
|
+
idx = _resolve_subtask_id(subtask_id, context)
|
|
287
|
+
if idx < 0 or idx >= len(st["tasks"]):
|
|
288
|
+
return "_Invalid subtask identifier._"
|
|
289
|
+
|
|
290
|
+
# Mark as not done
|
|
291
|
+
task = st["tasks"][idx]
|
|
292
|
+
was_done = task["done"]
|
|
293
|
+
task["done"] = False
|
|
294
|
+
|
|
295
|
+
# If we cleared the current or earlier task, update cursor
|
|
296
|
+
if idx <= st["cursor"]:
|
|
297
|
+
st["cursor"] = idx
|
|
298
|
+
|
|
299
|
+
# Build response
|
|
300
|
+
action = "Cleared" if was_done else "Already clear"
|
|
301
|
+
return (
|
|
302
|
+
f"{action} Subtask {idx+1}: - [ ] {task['label']}\n"
|
|
303
|
+
f"Current subtask is now Subtask {st['cursor']+1}\n\n"
|
|
304
|
+
f"{_format_checklist_status(context)}"
|
|
305
|
+
)
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
@command()
|
|
309
|
+
async def get_checklist_status(context=None):
|
|
310
|
+
"""
|
|
311
|
+
Show the full status of the checklist.
|
|
312
|
+
|
|
313
|
+
Example:
|
|
314
|
+
{ "get_checklist_status": {} }
|
|
315
|
+
"""
|
|
316
|
+
if context is None:
|
|
317
|
+
return "_Context is required._"
|
|
318
|
+
|
|
319
|
+
return _format_checklist_status(context)
|
|
320
|
+
|
|
321
|
+
|
|
322
|
+
@command()
|
|
323
|
+
async def delegate_subtask(subtask_id, details:str, agent=None, context=None):
|
|
324
|
+
"""
|
|
325
|
+
Delegate a subtask to an agent, automatically passing the subtask body as
|
|
326
|
+
instructions, along with any details you add.
|
|
327
|
+
|
|
328
|
+
If agent is not specified, the current agent name will be used for the subtask.
|
|
329
|
+
|
|
330
|
+
Example:
|
|
331
|
+
|
|
332
|
+
Given a checklist with subtasks like:
|
|
333
|
+
|
|
334
|
+
- Research
|
|
335
|
+
...
|
|
336
|
+
|
|
337
|
+
- Draft
|
|
338
|
+
...
|
|
339
|
+
|
|
340
|
+
- Complete
|
|
341
|
+
..
|
|
342
|
+
|
|
343
|
+
Suppose you had already created /data/sess_1234.
|
|
344
|
+
You might initiate work on the first subtask with this command:
|
|
345
|
+
|
|
346
|
+
{ "delegate_subtask": { "subtask_id": "Research",
|
|
347
|
+
"details": "Session data in /data/sess_1234/" }}
|
|
348
|
+
|
|
349
|
+
Note that you do not need to repeat the text of the subtask item from the checklist
|
|
350
|
+
in your details.
|
|
351
|
+
"""
|
|
352
|
+
st = _state(context)
|
|
353
|
+
if not st["tasks"]:
|
|
354
|
+
try:
|
|
355
|
+
print("Loading checklist from instructions...")
|
|
356
|
+
print("Agent is")
|
|
357
|
+
print(context.agent)
|
|
358
|
+
instructions = context.agent["instructions"]
|
|
359
|
+
await load_checklist_from_instructions(instructions, context)
|
|
360
|
+
except Exception as e:
|
|
361
|
+
print(f"Error loading checklist: {e}")
|
|
362
|
+
trace = traceback.format_exc()
|
|
363
|
+
print(trace)
|
|
364
|
+
return "_No checklist found. Make sure to include a checklist in your instructions._"
|
|
365
|
+
idx = _resolve_subtask_id(subtask_id, context)
|
|
366
|
+
if idx < 0 or idx >= len(st["tasks"]):
|
|
367
|
+
return "_Invalid subtask identifier._"
|
|
368
|
+
current_task = st["tasks"][idx]
|
|
369
|
+
subtask = current_task["body"]
|
|
370
|
+
reminder = """Important: you may see instructions for the full process. However, you are to ONLY
|
|
371
|
+
do the specified part of the process and then return a task result."""
|
|
372
|
+
instructions = f"You are working as part of a multi-step process. Please complete the following subtask:\n\n{subtask}\n\n{details}\n\n{reminder}\n"
|
|
373
|
+
if agent is None:
|
|
374
|
+
agent_name = context.agent["name"]
|
|
375
|
+
else:
|
|
376
|
+
agent_name = agent
|
|
377
|
+
return await command_manager.delegate_task(instructions, agent_name, context=context)
|
|
378
|
+
|