Run setup to create a temporary Python project and notes. Follow the sections in order. Inspect existing files, search the source, read an outline, then make checked edits using paths, section addresses, and digests returned in this run. Every write stays in the temporary directory. Its files disappear when this kernel exits.
Tool catalog: saved files and source
Run setup to create a temporary Python project and notes. Follow the sections in order. Inspect existing files, search the source, read an outline, then make checked edits using paths, section addresses, and digests returned in this run. Every write stays in the temporary directory. Its files disappear when this kernel exits.
from pathlib import Path
from tempfile import TemporaryDirectory
import hashlib
from nbinlineai.tools import tool_catalog
from nbinlineai.tools import (
path_info, list_files, view_file, create_file, file_str_replace, file_insert_line, file_replace_lines, search_files, source_doc, document_outline, read_document_section, file_strs_replace, view_file_hashes, file_replace_checked
)
catalog_temp = TemporaryDirectory(prefix="nbinlineai-catalog-")
catalog_root = Path(catalog_temp.name)
catalog_source = catalog_root /"sample.py"
catalog_source.write_text('"""Disposable source."""\n\ndef double(value: int) -> int:\n"""Double one value."""\n return value * 2\n', encoding="utf-8")
catalog_notes = catalog_root /"notes.md"
catalog_notes.write_text("# Field notes\nOne observation.\n## Counts\nvisits = 2\n", encoding="utf-8")
catalog_edit = catalog_root /"edit.txt"
catalog_edit.write_text("alpha\nbeta\ngamma\n", encoding="utf-8")
print("Disposable folder:", catalog_root)
# Independent paths keep the AI edits separate from the direct-call examples.
catalog_ai_create_path =str(catalog_root /"ai-created.txt")
catalog_ai_replace_path =str(catalog_root /"ai-replace.txt")
catalog_ai_insert_path =str(catalog_root /"ai-insert.txt")
catalog_ai_lines_path =str(catalog_root /"ai-lines.txt")
catalog_ai_multi_path =str(catalog_root /"ai-multi.txt")
catalog_ai_checked_path =str(catalog_root /"ai-checked.txt")
for path in (catalog_ai_replace_path, catalog_ai_insert_path,
catalog_ai_lines_path, catalog_ai_multi_path, catalog_ai_checked_path):
Path(path).write_text("alpha\nbeta\ngamma\n", encoding="utf-8")
print("Five separate disposable files are ready for AI edits.")
Disposable folder: [temporary local path]
Five separate disposable files are ready for AI edits.
Outline: [temporary local path]
s:9ebb77061ede41e957aa6e3152e0473351bddf4e5733c0f12020db058adcca64:0 Entire document (lines 1-4)
s:9ebb77061ede41e957aa6e3152e0473351bddf4e5733c0f12020db058adcca64:1 Field notes (lines 1-4)
s:9ebb77061ede41e957aa6e3152e0473351bddf4e5733c0f12020db058adcca64:2 Counts (lines 3-4)
read_document_section
catalog_counts_address =next(line.split()[0] for line in catalog_outline.splitlines() if"Counts (lines"in line)
print(read_document_section(str(catalog_notes), section=catalog_counts_address))
[temporary local path] s:9ebb77061ede41e957aa6e3152e0473351bddf4e5733c0f12020db058adcca64:2
## Counts
visits = 2
Run these questions after the direct code examples. They use separate temporary files, so every edit has a fresh, checkable starting state. Each question explicitly names its tools and reports the returned evidence.
On the disposable folder $catalog_root, use &path_info for the folder, &list_files for its *.py files, and &view_file for $catalog_source lines 1–5. Name the file and quote its function signature from the returned text.
The folder is a directory containing sample.py. Its function signature is def double(value: int) -> int:.
Observed live tool calls for the answer above (actual subscription events; private fields shortened).
‘File: [local path] “”“Disposable source.”“”\n2: \n3: def double(value: int) -> int:\n4: “”“Double one value.”“”\n5: return value * 2’
Use &search_files for double under $catalog_root with *.py, then &source_doc for symbol double in $catalog_source. Give its source location and one sentence on what it does.
double is defined in sample.py at line 3. It doubles an integer value.
Observed live tool calls for the answer above (actual subscription events; private fields shortened).
‘[local path] double\ndef double(value: int) -> int:\nDouble one value.’
Use &document_outline on $catalog_notes and copy the fresh address of its Counts section. Pass that address to &read_document_section, then report the visit count from the returned section.
Counts address: s:9ebb77061ede41e957aa6e3152e0473351bddf4e5733c0f12020db058adcca64:2. The section reports visits = 2.
Observed live tool calls for the answer above (actual subscription events; private fields shortened).
Use &create_file at the new path $catalog_ai_create_path with content AI note: three visits.\n. Then use &view_file on that exact path and quote the line it returned.
1: AI note: three visits.
Observed live tool calls for the answer above (actual subscription events; private fields shortened).
Make three independent, checked changes: use &file_str_replace on $catalog_ai_replace_path to replace the one alpha with first (expected_matches=1); use &file_insert_line on $catalog_ai_insert_path before line 1 to add heading; use &file_replace_lines on $catalog_ai_lines_path to replace line 2 with second. Report each returned result briefly.
All three edits succeeded: ai-replace.txt changed alpha to first; ai-insert.txt gained heading before line 1; and ai-lines.txt changed line 2 from beta to second.
Observed live tool calls for the answer above (actual subscription events; private fields shortened).
On $catalog_ai_multi_path, use &file_strs_replace to change alpha→first and gamma→third. Separately, use &view_file_hashes on $catalog_ai_checked_path for lines 1–3, copy its actual digest, then &file_replace_checked there to change gamma to third with that digest. Report the two edits and digest source.
Both edits succeeded: ai-multi.txt changed alpha → first and gamma → third; ai-checked.txt changed gamma → third. The checked edit used digest 4fdbc441ea7b546100e086ac1e4fc5ae6749b7314311c99db05be450eca12996 returned by view_file_hashes for ai-checked.txt.
Observed live tool calls for the answer above (actual subscription events; private fields shortened).
for label, path in [("created", catalog_ai_create_path), ("replace", catalog_ai_replace_path),
("insert", catalog_ai_insert_path), ("lines", catalog_ai_lines_path),
("multi", catalog_ai_multi_path), ("checked", catalog_ai_checked_path)]:
item = Path(path)
if item.exists():
print(label, item.read_text(encoding="utf-8").strip().replace("\n", " | "))
else:
print(label, "pending AI create_file result")
created AI note: three visits.
replace first | beta | gamma
insert heading | alpha | beta | gamma
lines alpha | second | gamma
multi first | beta | third
checked alpha | beta | third