Skip to content

Commit 359bf39

Browse files
committed
fixes #230
1 parent d725aee commit 359bf39

8 files changed

Lines changed: 77 additions & 143 deletions

File tree

dialoghelper/_modidx.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
'dialoghelper.core._maybe_xml': ('core.html#_maybe_xml', 'dialoghelper/core.py'),
3131
'dialoghelper.core._msg_edit': ('core.html#_msg_edit', 'dialoghelper/core.py'),
3232
'dialoghelper.core._prep_endp': ('core.html#_prep_endp', 'dialoghelper/core.py'),
33-
'dialoghelper.core._python_edit': ('core.html#_python_edit', 'dialoghelper/core.py'),
3433
'dialoghelper.core._umsg': ('core.html#_umsg', 'dialoghelper/core.py'),
3534
'dialoghelper.core.add_html': ('core.html#add_html', 'dialoghelper/core.py'),
3635
'dialoghelper.core.add_html_a': ('core.html#add_html_a', 'dialoghelper/core.py'),
@@ -42,10 +41,10 @@
4241
'dialoghelper.core.call_endp': ('core.html#call_endp', 'dialoghelper/core.py'),
4342
'dialoghelper.core.call_endpa': ('core.html#call_endpa', 'dialoghelper/core.py'),
4443
'dialoghelper.core.connfiles': ('core.html#connfiles', 'dialoghelper/core.py'),
45-
'dialoghelper.core.copy_msg': ('core.html#copy_msg', 'dialoghelper/core.py'),
44+
'dialoghelper.core.copy_msgs': ('core.html#copy_msgs', 'dialoghelper/core.py'),
4645
'dialoghelper.core.create_or_run_dialog': ('core.html#create_or_run_dialog', 'dialoghelper/core.py'),
4746
'dialoghelper.core.curr_dialog': ('core.html#curr_dialog', 'dialoghelper/core.py'),
48-
'dialoghelper.core.del_msg': ('core.html#del_msg', 'dialoghelper/core.py'),
47+
'dialoghelper.core.del_msgs': ('core.html#del_msgs', 'dialoghelper/core.py'),
4948
'dialoghelper.core.dialog_link': ('core.html#dialog_link', 'dialoghelper/core.py'),
5049
'dialoghelper.core.display_response': ('core.html#display_response', 'dialoghelper/core.py'),
5150
'dialoghelper.core.enable_mermaid': ('core.html#enable_mermaid', 'dialoghelper/core.py'),
@@ -69,7 +68,7 @@
6968
'dialoghelper.core.msg_idx': ('core.html#msg_idx', 'dialoghelper/core.py'),
7069
'dialoghelper.core.msg_ref': ('core.html#msg_ref', 'dialoghelper/core.py'),
7170
'dialoghelper.core.names_containing': ('core.html#names_containing', 'dialoghelper/core.py'),
72-
'dialoghelper.core.paste_msg': ('core.html#paste_msg', 'dialoghelper/core.py'),
71+
'dialoghelper.core.paste_msgs': ('core.html#paste_msgs', 'dialoghelper/core.py'),
7372
'dialoghelper.core.pop_data': ('core.html#pop_data', 'dialoghelper/core.py'),
7473
'dialoghelper.core.pop_data_a': ('core.html#pop_data_a', 'dialoghelper/core.py'),
7574
'dialoghelper.core.read_msg': ('core.html#read_msg', 'dialoghelper/core.py'),
@@ -97,8 +96,8 @@
9796
'dialoghelper.core.xgeta': ('core.html#xgeta', 'dialoghelper/core.py'),
9897
'dialoghelper.core.xposta': ('core.html#xposta', 'dialoghelper/core.py')},
9998
'dialoghelper.db_dc': {},
100-
'dialoghelper.exhash': { 'dialoghelper.exhash.exhash_msg': ('exhash.html#exhash_msg', 'dialoghelper/exhash.py'),
101-
'dialoghelper.exhash.lnhashview_msg': ('exhash.html#lnhashview_msg', 'dialoghelper/exhash.py')},
99+
'dialoghelper.exhash': { 'dialoghelper.exhash.lnhashview_msg': ('exhash.html#lnhashview_msg', 'dialoghelper/exhash.py'),
100+
'dialoghelper.exhash.msg_exhash': ('exhash.html#msg_exhash', 'dialoghelper/exhash.py')},
102101
'dialoghelper.solve_auth': { 'dialoghelper.solve_auth.SolveSigninError': ( 'solve_auth.html#solvesigninerror',
103102
'dialoghelper/solve_auth.py'),
104103
'dialoghelper.solve_auth._app_url': ('solve_auth.html#_app_url', 'dialoghelper/solve_auth.py'),

dialoghelper/core.py

Lines changed: 27 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,15 @@
44

55
# %% auto #0
66
__all__ = ['dh_settings', 'Placements', 'mermaid_url', 'msg_insert_line', 'msg_str_replace', 'msg_strs_replace',
7-
'msg_replace_lines', 'msg_del_lines', 'msg_python', 'names_containing', 'find_dname', 'xposta', 'xgeta',
8-
'call_endp', 'call_endpa', 'curr_dialog', 'msg_idx', 'add_html_a', 'add_html', 'add_scr_a', 'add_scr',
9-
'iife_a', 'iife', 'add_mod', 'add_mod_a', 'pop_data_a', 'pop_data', 'fire_event_a', 'fire_event',
10-
'event_get_a', 'event_get', 'trigger_now', 'event_once', 'event_once_a', 'js_run', 'js_run_a', 'js_eval',
11-
'js_eval_a', 'Channel', 'display_response', 'connfiles', 'realpath', 'list_dialogs', 'read_msg', 'find_msgs',
12-
'view_dlg', 'add_msg', 'read_msgid', 'view_msg', 'msg_ref', 'del_msg', 'run_and_prompt', 'update_msg',
13-
'run_msg', 'copy_msg', 'paste_msg', 'enable_mermaid', 'mermaid', 'toggle_header', 'toggle_bookmark',
14-
'toggle_export', 'toggle_comment', 'url2note', 'create_or_run_dialog', 'stop_dialog', 'load_dialog',
15-
'rm_dialog', 'run_code_interactive', 'solveit_docs', 'dialog_link', 'spawn_agent', 'search', 'searches',
16-
'web_answer']
7+
'msg_replace_lines', 'msg_del_lines', 'names_containing', 'find_dname', 'xposta', 'xgeta', 'call_endp',
8+
'call_endpa', 'curr_dialog', 'msg_idx', 'add_html_a', 'add_html', 'add_scr_a', 'add_scr', 'iife_a', 'iife',
9+
'add_mod', 'add_mod_a', 'pop_data_a', 'pop_data', 'fire_event_a', 'fire_event', 'event_get_a', 'event_get',
10+
'trigger_now', 'event_once', 'event_once_a', 'js_run', 'js_run_a', 'js_eval', 'js_eval_a', 'Channel',
11+
'display_response', 'connfiles', 'realpath', 'list_dialogs', 'read_msg', 'find_msgs', 'view_dlg', 'add_msg',
12+
'read_msgid', 'view_msg', 'msg_ref', 'del_msgs', 'run_and_prompt', 'update_msg', 'run_msg', 'copy_msgs',
13+
'paste_msgs', 'enable_mermaid', 'mermaid', 'toggle_header', 'toggle_bookmark', 'toggle_export',
14+
'toggle_comment', 'url2note', 'create_or_run_dialog', 'stop_dialog', 'load_dialog', 'rm_dialog',
15+
'run_code_interactive', 'solveit_docs', 'dialog_link', 'spawn_agent', 'search', 'searches', 'web_answer']
1716

1817
# %% ../nbs/00_core.ipynb #4dd4b925
1918
import os,re,inspect,ast,collections,time,asyncio,json,linecache,importlib,uuid,builtins,subprocess,sys
@@ -412,8 +411,8 @@ async def find_msgs(
412411
re_pattern:str='', # Optional regex to search for (re.DOTALL+re.MULTILINE is used)
413412
msg_type:str=None, # optional limit by message type ('code', 'note', or 'prompt')
414413
before:int=0, # Include additional n msgs before matches
415-
after:int=0, # Include additional n msgs before matches
416-
context:int=0, # Include additional n msgs around matches (recommended: set `context=2` when searching to see ipynb context)
414+
after:int=0, # Include additional n msgs after matches
415+
context:int=None, # Include additional n msgs around matches (default 1, or 0 when `headers_only`)
417416
use_case:bool=False, # Use case-sensitive matching?
418417
use_regex:bool=True, # Use regex matching?
419418
only_err:bool=False, # Only return messages that have errors?
@@ -437,6 +436,7 @@ async def find_msgs(
437436
Message ids are identical to those in LLM chat history, so do NOT call this to view a specific message if it's in the chat history--instead use `view_msg`.
438437
Do NOT use find_msgs to view message content in the current dialog above the current prompt -- these are *already* provided in LLM context, so just read the content there directly. (NB: LLM context only includes messages *above* the current prompt, whereas `find_msgs` can access *all* messages.)
439438
To refer to a found message from code, use its `id` field."""
439+
if context is None: context = 0 if headers_only else 1
440440
res = await call_endpa('find_msgs_', dname, json=False, re_pattern=re_pattern, msg_type=msg_type, limit=limit, ids=ids,
441441
use_case=use_case, use_regex=use_regex, only_err=only_err, only_exp=only_exp, only_chg=only_chg,
442442
include_output=include_output, include_meta=include_meta, as_xml=as_xml, nums=nums,
@@ -560,15 +560,18 @@ def msg_ref(id, dname=None):
560560
return f'#{find_dname(dname).strip("/")}/{id}'
561561

562562
# %% ../nbs/00_core.ipynb #f1ee1903
563-
async def del_msg(
564-
id:str=None, # id of message to delete
563+
async def del_msgs(
564+
ids:str=None, # Comma-separated ids of message(s) to delete
565565
dname:str='', # Dialog to get info for; defaults to current dialog
566566
log_changed:bool=False # Add a note showing the deleted content?
567-
) -> dict:
568-
"Delete a message from the dialog. DO NOT USE THIS unless you have been explicitly instructed to delete messages."
569-
if log_changed: msg = await read_msgid(id, dname=dname)
570-
res = await call_endpa('rm_msg_', dname, raiseex=True, msid=id, json=True, audit=True)
571-
if log_changed: await add_msg(f"> Deleted {msg_ref(id, dname)}\n\n```\n{msg.content}\n```")
567+
) -> list:
568+
"Delete messages from the dialog. DO NOT USE THIS unless you have been explicitly instructed to delete messages."
569+
res = []
570+
for i in ([o.strip() for o in ids.split(',')] if isinstance(ids, str) else listify(ids)):
571+
if log_changed: msg = await read_msgid(i, dname=dname)
572+
r = await call_endpa('rm_msg_', dname, raiseex=True, msid=i, json=True, audit=True)
573+
if log_changed: await add_msg(f"> Deleted {msg_ref(i, dname)}\n\n```\n{msg.content}\n```")
574+
res.append(r)
572575
return res
573576

574577
# %% ../nbs/00_core.ipynb #30e90bf9
@@ -626,7 +629,7 @@ async def run_msg(
626629
return await call_endpa('add_runq_', dname, ids=ids, json=True)
627630

628631
# %% ../nbs/00_core.ipynb #73025e57
629-
async def copy_msg(
632+
async def copy_msgs(
630633
ids:str=None, # Comma-separated ids of message(s) to copy
631634
cut:bool=False, # Cut message(s)? (If not, copies)
632635
dname:str='' # Running dialog to copy messages from; defaults to current dialog. (Note dialog *must* be running for this function)
@@ -637,7 +640,7 @@ async def copy_msg(
637640
return _check_res(res, dname)
638641

639642
# %% ../nbs/00_core.ipynb #80def27e
640-
async def paste_msg(
643+
async def paste_msgs(
641644
id:str=None, # Message id to paste next to
642645
after:bool=True, # Paste after id? (If not, pastes before)
643646
dname:str='' # Running dialog to copy messages from; defaults to current dialog. (Note dialog *must* be running for this function)
@@ -773,7 +776,7 @@ async def run_code_interactive(
773776
774777
id: Message id to edit, or list of ids, or 'all' for all messages in dialog
775778
dname: Dialog to get info for; defaults to current dialog
776-
update_output: If True, replace in output instead of content
779+
out: If True, replace in output instead of content
777780
log_changed: Add a note showing the deleted content?
778781
779782
returns:
@@ -782,10 +785,10 @@ async def run_code_interactive(
782785

783786
# %% ../nbs/00_core.ipynb #ee87e70d
784787
def _msg_edit(f, name=None):
785-
async def wrapper(id:str|list[str], *args, update_output:bool=False, dname:str='', log_changed:bool=False, **kw):
788+
async def wrapper(id:str|list[str], *args, out:bool=False, dname:str='', log_changed:bool=False, **kw):
786789
async def _one(mid):
787790
msg = await read_msg(n=0, id=mid, dname=dname)
788-
field = 'output' if update_output else 'content'
791+
field = 'output' if out else 'content'
789792
text = msg.get(field, '')
790793
if not text: return f"error: Message has no {field}"
791794
try: new_text = await maybe_await(f(text, *args, **kw))
@@ -822,17 +825,6 @@ async def _one(mid):
822825
msg_del_lines = _msg_edit (del_lines, 'msg_del_lines')
823826

824827

825-
# %% ../nbs/00_core.ipynb #73cb7c93
826-
async def _python_edit(
827-
text:str,
828-
code:str, # Python code; `text` var has content, last expr is new content
829-
):
830-
"Edit text by running `code` in python. `text` var has content, last expr is new content"
831-
res = await python(f'text = {repr(text)}\n{code}')
832-
return res
833-
834-
msg_python = _msg_edit (_python_edit, 'msg_python')
835-
836828
# %% ../nbs/00_core.ipynb #11ee26d9
837829
async def solveit_docs():
838830
"""Full reference documentation for Solveit - use this to answer questions about how to use Solveit.

dialoghelper/exhash.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/04_exhash.ipynb.
22

33
# %% auto #0
4-
__all__ = ['lnhashview_msg', 'exhash_msg']
4+
__all__ = ['lnhashview_msg', 'msg_exhash']
55

66
# %% ../nbs/04_exhash.ipynb #d6291515
77
from fastcore.utils import *
@@ -22,7 +22,7 @@ async def lnhashview_msg(
2222

2323

2424
# %% ../nbs/04_exhash.ipynb #9bdae034
25-
async def exhash_msg(
25+
async def msg_exhash(
2626
id:str, # id of message to edit
2727
cmds:list, # List of exhash command tuples to apply
2828
dname:str='', # Dialog containing message; defaults to current dialog

dialoghelper/solveitskill.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
- `add_msg` — placement can be `add_after`/`add_before` (relative to current) or `at_start`/`at_end` (absolute)
2424
- **NB** When not passing a message id, it defaults to the *current* message. So if you call it multiple times with no message id, the messages will be added in REVERSE! Instead, get the return value of `add_msg` after each call, and use that for the next call
2525
- `update_msg` — partial updates; only pass fields to change
26-
- `del_msg` — use sparingly, only when explicitly requested
27-
`copy_msg` → `paste_msg` — for moving/duplicating messages within running dialogs.
26+
- `del_msgs` — use sparingly, only when explicitly requested
27+
`copy_msgs` → `paste_msgs` — for moving/duplicating messages within running dialogs.
2828
2929
## Non-decorated Functions Worth Knowing
3030
@@ -49,7 +49,7 @@
4949
0. Find message id in dynamic contenxt, or using `view_dlg` or `find_msgs`
5050
1. lnhashview_msg(id)
5151
2. Identify lines to change
52-
3. exhash_msg(...)
52+
3. msg_exhash(...)
5353
4. If more edits needed: re-read, then repeat from step 2
5454
```
5555
@@ -61,14 +61,14 @@
6161
from pyskills.core import allow
6262

6363
__all__ = [
64-
'curr_dialog', 'msg_idx', 'realpath', 'list_dialogs', 'lnhashview_msg', 'exhash_msg',
64+
'curr_dialog', 'msg_idx', 'realpath', 'list_dialogs', 'lnhashview_msg', 'msg_exhash',
6565
'read_msg', 'find_msgs', 'view_dlg', 'add_msg', 'read_msgid', 'view_msg',
66-
'del_msg', 'update_msg', 'copy_msg', 'paste_msg', 'toggle_header', 'toggle_bookmark', 'toggle_comment',
66+
'del_msgs', 'update_msg', 'copy_msgs', 'paste_msgs', 'toggle_header', 'toggle_bookmark', 'toggle_comment',
6767
'create_or_run_dialog', 'stop_dialog', 'load_dialog', 'run_code_interactive', 'solveit_docs', 'dialog_link', 'spawn_agent',
6868
]
6969

7070
allow(
7171
curr_dialog, msg_idx, realpath, list_dialogs, read_msg, find_msgs, view_dlg, add_msg, read_msgid, view_msg,
72-
del_msg, update_msg, copy_msg, paste_msg, toggle_header, toggle_bookmark, toggle_comment,
73-
create_or_run_dialog, stop_dialog, load_dialog, solveit_docs, dialog_link, spawn_agent, lnhashview_msg, exhash_msg
72+
del_msgs, update_msg, copy_msgs, paste_msgs, toggle_header, toggle_bookmark, toggle_comment,
73+
create_or_run_dialog, stop_dialog, load_dialog, solveit_docs, dialog_link, spawn_agent, lnhashview_msg, msg_exhash
7474
)

dialoghelper/termskill.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@
7676
from dialoghelper.utils import msg_ast_replace
7777

7878
__all__ = ['set_dialog', 'curr_dialog', 'msg_idx', 'read_msg', 'read_msgid', 'view_msg', 'view_dlg', 'find_msgs',
79-
'add_msg', 'update_msg', 'del_msg', 'msg_str_replace', 'msg_strs_replace', 'msg_replace_lines', 'msg_insert_line',
80-
'msg_del_lines', 'msg_ast_replace', 'msg_python', 'create_or_run_dialog', 'stop_dialog', 'realpath', 'list_dialogs']
79+
'add_msg', 'update_msg', 'del_msgs', 'msg_str_replace', 'msg_strs_replace', 'msg_replace_lines', 'msg_insert_line',
80+
'msg_del_lines', 'msg_ast_replace', 'create_or_run_dialog', 'stop_dialog', 'realpath', 'list_dialogs']
8181

8282
def set_dialog(dname:str):
8383
"Set active dialog path for subsequent calls (absolute, no `.ipynb`)"

0 commit comments

Comments
 (0)