from fastcore.utils import *

The quick brown fox jumps over the lazy dog. Jackdaws love my big sphinx of quartz. Pack my box with five dozen liquor jugs. How vexingly quick daft zebras jump! The five boxing wizards jump quickly. Sphinx of black quartz, judge my vow. Two driven jocks help fax my big quiz. Bright vixens jump; dozy fowl quack.

msg = await read_msg()
id_ = msg.id
cts = msg.content

source

msg_lnhashview


async def msg_lnhashview(
    id:str
):

Show lnhash-addressed lines of a message


source

msg_exhash


async def msg_exhash(
    id:str, cmds:list
):

Verified line-addressed editor. Apply commands to msg id contents, return lnhashview(result). NB: all exhash commands must start with an address. The only allowed addresses are a single lnhash, or a pair separated by ,. (I.e no %, ., etc.) NB: hashes are checked before each command is run. So be sure to have commands go last->first order to avoid changing earlier lines.

Commands are like ex, but use lnhash addresses instead of bare line numbers: lineno|hash|cmd where hash is a 4-char hex content hash. Use msg_lnhashview(text) to get addresses before first use.

Addressing: Single: 12|a3f2|cmd Range: 12|a3f2|,15|b1c3|cmd Special: 0|0000| targets before line 1 (only with a or i)

Commands: s/pat/rep/[flags] Substitute (regex). Flags: g=all, i=case-insensitive d Delete line(s) a Append text after line i Insert text before line c Change/replace line(s) j Join with next line; with range, joins all m dest Move line(s) after dest address t dest Copy line(s) after dest address >[n] Indent n levels (default 1, 4 spaces each) <[n] Dedent n levels (default 1) sort Sort lines alphabetically p Print (include in output without changing) g/pat/cmd Global: run cmd on matching lines g!/pat/cmd Inverted global (also v/pat/cmd)

cmds is a required list of command strings. For a/i/c, include the text block in the same command string after a newline.


source

file_lnhashview


def file_lnhashview(
    path:str
):

Show lnhash-addressed lines of a file


source

file_exhash


def file_exhash(
    path:str, cmds:list
):

Verified line-addressed editor for files. Apply commands to file at path, return lnhashview(result). See doc(msg_lnhashview) for details

tp = Path('tmp.txt')
tp.write_text(cts)
313

Try indenting the first 3 lines of this file with &[file_lnhashview,file_exhash].

🤖Reply🤖
file_lnhashview(path=‘tmp.txt’)
{
  "id": "toolu_01T723e8w3tcYjgdEwNopV18",
  "call": {
    "function": "file_lnhashview",
    "arguments": {
      "path": "tmp.txt"
    }
  },
  "result": "1|da2a|  The quick brown fox jumps over the lazy dog.\n2|32e4|  Jackdaws love my big sphinx of quartz.\n3|04e4|  Pack my box with five dozen liquor jugs.\n4|025f|  How vexingly quick daft zebras jump!\n5|c720|  The five boxing wizards jump quickly.\n6|0666|  Sphinx of black quartz, judge my vow.\n7|d61c|  Two driven jocks help fax my big quiz.\n8|bc1b|  Bright vixens jump; dozy fowl quack."
}
file_exhash(path=‘tmp.txt’, cmds=[‘1|da2a|,3|04e4|>’])
{
  "id": "toolu_01QdybzYCodQBHB5WKMo7Z92",
  "call": {
    "function": "file_exhash",
    "arguments": {
      "path": "tmp.txt",
      "cmds": "['1|da2a|,3|04e4|>']"
    }
  },
  "result": "1|dfab|      The quick brown fox jumps over the lazy dog.\n2|e110|      Jackdaws love my big sphinx of quartz.\n3|a4ce|      Pack my box with five dozen liquor jugs.\n4|025f|  How vexingly quick daft zebras jump!\n5|c720|  The five boxing wizards jump quickly.\n6|0666|  Sphinx of black quartz, judge my vow.\n7|d61c|  Two driven jocks help fax my big quiz.\n8|bc1b|  Bright vixens jump; dozy fowl quack."
}

Done — first 3 lines are now indented. You can see the hashes changed for those lines (da2adfab, etc.) since the content now includes leading spaces.

print(tp.read_text())
    The quick brown fox jumps over the lazy dog.
    Jackdaws love my big sphinx of quartz.
    Pack my box with five dozen liquor jugs.
How vexingly quick daft zebras jump!
The five boxing wizards jump quickly.
Sphinx of black quartz, judge my vow.
Two driven jocks help fax my big quiz.
Bright vixens jump; dozy fowl quack.
tp.unlink()