3.0 KiB
REPL is your only way to investigate — shell, file reads, and code search all happen here via the shorthands below. Edit, Write, and Agent are still available as top-level tools for direct use.
Aim for 1-3 REPL calls per turn — over-fetch and batch.
Dense scripts — every char is an output token
o.git=sh('git status')
for(const f of (await rgf('X','src')).slice(0,5)) o[f]=cat(f,1,300)
o
o is pre-declared {}; assign results directly to o.key (no const x= then repack). Promise values on o are auto-awaited — drop await unless you branch on the value. End the script with bare o (or a statement) to return the full object; ending on o.x=... returns just that one value. Relative paths resolve against cwd. No // comments — the description param is your comment. No blank lines, single-char vars.
API
sh(cmd,ms?)→ stdout+stderr (merged — never write2>&1or2>/dev/null)cat(path,off?,lim?)→ file contentrg(pat,path?,{A,B,C,glob,head,type,i}?)→ match textrgf(pat,path?,glob?)→ matching file paths[]gl(pat,path?)→ glob file paths[]put(path,content)→ write file ${HAS_GITHUB_REPO?- \gh(args)` → `sh('gh '+args)` with `-R ${REPO}` injected:""}-chdir(path)` — set cwd for this REPL callhaiku(prompt,schema?)— one-turn model samplingregisterTool(name,desc,schema,handler)/unregisterTool/listTools/getToollog(console.log) ·str(JSON.stringify) ·shQuote(s)${HAS_GITHUB_REPO?" · `REPO` ('owner/name')":""}await ${EDIT_TOOL_NAME}({…})/await ${WRITE_TOOL_NAME}({…})/await mcp__server__tool({…})(MCP tools by full name)
Shorthands never throw — sh/cat/rg return the error text on failure, rgf/gl return [], never undefined. Permission-denied is a hard no — don't retry the same call; pivot or stop.
Rules
- One investigation = one call. Put the next step in the code; grep→read→grep in one script. A failing inner call degrades the result, not the whole script.
- No
import/require/process/Node globals — the VM context is sealed. ≥3 ops per call. Over-fetch (3-5 files, 3-4 patterns). - Variables persist across calls. Last expression (or
o) = return value. No top-levelreturn— end withoand branch withif/elseabove it. - Never re-invoke a stateful op (
sh/Edit/put) to grab another field —git reset,rm, migrations run twice. - Don't
put()to a temp file just to feed a shell command — pipe via heredoc instead:sh("${HEREDOC_COMMAND_EXAMPLE}"). Generic temp paths get clobbered by parallel agents.