--- name: endeavor-notebooks description: >- Use for any work in a live notebook through Endeavor's notebook tools (`new_notebook`, `open_notebook`, `read_cell`, `edit_cell`, `submit_changes`, ...): creating or opening a notebook; adding, editing, deleting, folding or running cells; reading results and checking plots; widgets and data analysis in a Julia (Pluto), R (Ember) or Python (marimo) notebook; working in a notebook another agent has open; or a notebook tool refusing a call. For a `.jl`, `.R` or `.py` file the user asks to open, show or look at, call `open_notebook` before reading the file, even when you can't tell it is a notebook (a `.py` file may be a marimo notebook; a plain script fails at once with `not_a_notebook`). Read it before the first notebook tool call of a session. Not for Jupyter `.ipynb` files. --- # Working in a live notebook These tools act on a notebook that is running in Endeavor's runtime. The user watches the same notebook and can edit it while you work. It is not a file to patch: the runtime owns the notebook's file and rewrites it, so create notebooks with `new_notebook` and change them only through the tools. You can read any notebook's file to reuse its code. The notebook is reactive. Running a cell also runs every cell that depends on it, and cells run in dependency order, not page order. `read_notebook_code` shows the order they run in. ## Before the first cell - **Engine.** The file's ending names the language: `.jl` is a Julia notebook (Pluto), `.R` an R notebook (Ember), `.py` a Python notebook (marimo). Each engine limits what one cell may hold, and code that would be fine in a script fails. Read the engine's reference before you write a cell. Julia: [reference/pluto.md](reference/pluto.md). R: [reference/ember.md](reference/ember.md). Python: [reference/marimo.md](reference/marimo.md). - **Host.** You are in the Endeavor app unless the server's instructions say the notebooks run without it. In the app, read [reference/app.md](reference/app.md): prompts name the notebook, the user approves runs, and your replies link the cells they talk about. Without the app, skip it. Either way, when `new_notebook` or `open_notebook` returns `browser_url`, give it to the user so they can watch. If the result has `opened_in_browser` true, the notebook should already be open in their browser: say so, and give the address in case it isn't. If it has `shown_beside_chat` true, the notebook shows in the chat instead: say that it should open beside the chat or full screen, by itself or with one click on its card, and don't give the address. If the user then says they don't see it, call `open_notebook` again with `in_browser` true. If it has `browser_note`, no browser opened for the user: give them the address and follow the note. - **Paths.** If a tool says the server was not told the project folder, give absolute paths: your working folder plus the file name. - **On a server.** When the notebook runs on a server, its files are there. Use `list_folder`, `read_file` and `run_shell` for them; your own file tools see the user's computer, and may find a copy of the project there and show no error. ## One notebook per session A session works in one notebook: the first it creates or opens. `list_notebooks` marks it `this_session`. - No notebook yet and the user wants notebook work: call `new_notebook` with a short descriptive file name, ending in `.jl` for Julia, `.R` for R or `.py` for Python. Make an R notebook when the user asks for R or their project is in R, and a Python notebook when they ask for Python or their project is in Python; otherwise Julia. R notebooks don't run on Windows yet: there, tell the user and offer Julia or Python. Don't ask the user to make one. Its empty first cell is in `cell_ids` and counts as read, so edit that cell first. - The user names an existing notebook: `open_notebook`. If it is unclear which file they mean, ask; don't search for one to open. If the notebook is already open, the session joins it as it is and nothing runs (`already_open`). That is also how a second agent shares your notebook: give it the path. - After that, any call that opens, creates, changes or runs another notebook fails with `one_notebook`. A new step of the analysis is a new section in this notebook. If the user wants to work in another notebook, they start a new session. ## Read, stage, run, check 1. **Read.** An edit is accepted only for a cell you have read as it is now. `read_required` and `stale_read` mean read it and try again; `stale_read` means someone changed it since, so see what they did before you overwrite it. `read_notebook_code` reads every cell it returns, but leaves prose cells out unless `include_markdown=true`. `add_cell` needs a read of the cell it goes after. A cell you just added or edited counts as read. Subagents of one conversation count as one reader, so neither is warned about the other's edits: don't give two subagents that run at the same time work in the same notebook. 2. **Stage.** `edit_cell`, `edit_cells` and `add_cell` change code without running it. Staged cells are listed in `pending_run`, and `read_cell` shows them `stale`: the output is from the old code. Each `add_cell` puts its cell directly after `after_cell_id`, so two cells added after the same cell end up in reverse order. To add several in order, add them one at a time, each after the `cell_id` the previous call returned. 3. **Run once.** `submit_changes` runs everything staged, with dependents. An R notebook can be in Ember's lazy mode instead (`on_cell_change` is `lazy` in `list_notebooks` and `open_notebook`): there a run marks the cells that depend on it stale and doesn't run them, and its result warns `lazy_mode` and lists the notebook's stale cells in `stale_cells`. Running a stale cell runs its stale ancestors first, so run the ones the user needs current. Run once per batch of edits, not per edit, so expensive cells downstream run once. Don't end a turn with cells staged unless the user asked for that, declined the run, or the notebook is in safe preview. If cells stay staged, tell the user which ones haven't run, since the notebook shows output that doesn't match their code. 4. **Check.** - Pass `wait_for_completion=true` when you will read the result next. Without it the run returns at once: do other work, then read the cells until `running` and `queued` are false. - A waited run waits at most 45 seconds from the start of the call. If the run is still going then, the call returns normally with the cells still running in `execution.still_running` and a `message` (`execution.status` is `running`, or `errored` if a cell already failed). The run continues and its cells are no longer in `pending_run`: read them later with `read_cell`, which waits up to 45 seconds for a cell your run is still running (if the cell is still running then, its `message` says how long the read waited), and do not run them again. `submit_changes` with nothing staged and `wait_for_completion=true` waits the same way for the rest of your run, and its `affected_cells` and `execution.status` are those of the cells that ran meanwhile (`errored` if one failed). - An edit with `run_after=true` isn't waited for. While its cell is still `running` or `queued`, the result gives the cell's output and error from before the edit as `previous_output`, `previous_errored` and `previous_error`, not `output`, `errored` and `error`, and `outputs.changed` leaves it out. Read the cell for the new output. A run not waited for names the dependents that will rerun after it in `execution.will_run`; read them too once they finish. - An edit that only stages its cell doesn't run it, so its result gives the old run's output and error the same way, as `previous_output`, `previous_errored` and `previous_error`: they are not the new code's. - A waited run that ended lists, in `affected_cells` and `outputs.changed`, the cells you ran, the upstream cells it ran first, and the dependents that reran with them. `outputs.changed` leaves out cells with no output. `execution.status` is `errored` if any of these failed, a dependent included. A dependent still running when the wait ended is in `execution.still_running` instead. - The first time a notebook uses a package (`using DataFrames` in Julia, `library(dplyr)` in R, `import pandas` in Python), it is installed before the cells that need it run, and they stay `queued`. That can take several minutes. Tell the user it is installing, then call `read_cell` on a queued cell to wait. Don't run the cells again meanwhile. Results have `packages` and a `message` saying so, and while packages install each `read_cell` waits up to 45 seconds. In Julia every cell waits; in R, the cells that may need the packages wait and the others run. If the message says it is taking longer than usual, tell the user and follow the message: keep waiting only while the last line of the package log changes. - Look at `errored`, `error`, the output and the run's `warnings` before you report. A `logged_warning` or `logged_error` is a warning or error the cell logged, which the user sees under the cell: say what it says when you report, since the result may not be what it looks like. 5. **Stop.** `interrupt_notebook` stops the notebook's run, as the notebook's Stop button does: the running cells end interrupted and the queued ones don't run. Call it when the user asks you to stop a run, or when a run you started is taking too long or is wrong. When the user interrupts you, the notebook's run goes on; stop it only if they ask. Don't call it for a run the user or another session started unless the user asked. The result lists the cells that `stopped`, which now show the interrupt as their error, and the queued cells `dropped`, which keep their old output. Run them again once you've fixed what was wrong. A cell in `still_running` is in code that ignores the interrupt. Tell the user; only a restart ends it. 6. **Restart.** `restart_notebook` starts the notebook's process again, as the Restart on its page does, and every value is gone. Call it when the user asks for a fresh start ("start R fresh", "restart the kernel"), or for a cell in `still_running` once the user agrees. A Julia notebook then runs every cell, including one that was stuck: the result names those in `running_again`. To end a stuck Julia cell, interrupt, edit the cell so it finishes (or tell the user it needs changing), then restart. An R notebook's cells are all `not_run`; run what you need, or `run_all_cells`. 7. **Close.** `close_notebook` ends the notebook's process, for the user's browser and every session too; the file keeps the saved code. Call it only when the user asks to close or stop the notebook. Open it again with `open_notebook` to go on. `delete_cell`, `move_cell` and `fold_cell` are not staged. Deleting reruns the cell's dependents and can't be undone. ## Outputs - For tables and other rich values, `output` only names the type and `output_text` has the value as text. Read that; don't edit the cell to print it. In a run's result, `output` is named `output_summary`, and `output_text` is cut at 2000 bytes for the cells you ran and at 200 for cells that only ran along with them (the cells that depend on them, or stale cells they needed), other than ones you edited; `read_cell` gives up to 16 KB. - For a plot, call `view_cell_output` and look at it before you say it is right. Code that runs can still draw the wrong thing. - An interactive plot or a widget is HTML. Outside the Endeavor app, or for an R or Python notebook, `view_cell_output` fails with `no_image` for most HTML: then you haven't seen it. - Keep the plot as the user asked for it. Don't switch plotting packages or go to a static plot, and don't redraw it another way or install anything to get a picture. If the chosen package fails to load, tell the user and stop. - In your answer, say that you couldn't see the plot, and ask the user to check that it shows and that its hover, zoom or other controls work. Don't describe how it looks or behaves beyond what the code sets. A picture, when there is one, shows how the plot looks, not that its controls work. - Fold cells that hold only prose (`add_cell`, `edit_cell` or `edit_cells` with `folded=true`, or `fold_cell`), so the reader sees the rendered text and not its source. ## Shape the notebook The notebook is what the user keeps and shows others after this chat is gone. Write it for a reader who wasn't here. The engine runs cells by what they use, not where they are, so put each cell where a reader needs it. - Start with a prose cell: a title, the question and the data. Once there are results, add a short summary of them there, with numbers computed in the prose (see the engine reference), and keep it true as results change. - Then packages and data loading, then one section per step. Open each section with a short prose cell saying what it does and why. - Show a result as the cell's value: a table, a plot, a number in prose. Not as printed text (`println`, `cat`, banners). - When the user changes a choice, such as a threshold or a window, edit the cell that holds it and let its dependents rerun. Don't copy those steps into new cells. If the user wants old and new compared, call the same step for both values in one cell. - Give a choice the user may want to vary its own cell at the top of its section. - New work goes where it belongs in the story: `add_cell` after the cell it follows, `move_cell` to put a cell in place. - After a long stretch of work, or when the user asks to tidy up, read it as the reader sees it (`read_notebook_code` with `order="visual"` and `include_markdown=true`) and offer to fix what would trip a reader: an old summary, dead ends, steps out of order. Say what you would change, and wait for the user's yes before you delete or move any cell: "tidy it up" asks for your proposal, not for a new order in a notebook they wrote. ## Safe preview A notebook opened from a file runs nothing until the user allows it, because its code may not be theirs (`execution_allowed` is false). Edits and `submit_changes` still stage, and the result warns `execution_blocked`: nothing ran. The warning names `allow_execution`, but call that only when the user asked you to run the notebook. Otherwise say the outputs are not current, and that they can run it from the notebook or ask you to. ## Other sessions in the notebook Several agents can work in one notebook. When a write is refused with `stale_read`, or a run with `run_conflict`, those cells changed since this session read them. The user changed them, or another session did, or this conversation did before it was resumed. Read them again, tell the user what changed, then retry. A notebook with `this_session` false is another session's: read it, but don't change it. If the user asks you to work in it and this session has no notebook yet, `open_notebook` with its path joins it; if this session already has one, that fails with `one_notebook`, so tell the user it needs a new session. ## When the user quotes the notebook A message can quote the notebook, each part as a `` whose `uri` names its cell (`notebook://…/cell/{cell_id}`; a `box` quote lists every cell under the box, separated by spaces). Since you last read them, the user may have edited or rerun those cells, or the cells they read. A quote holds text only for lines the user picked or text they selected; otherwise it only names what was picked. See a `figure` with `view_cell_output`. A `box` quote's picture follows it, or its `crop` names it: pass that `crop` to `view_cell_output` with one of the box's cells. A box with neither is over text, so read its cells. Before you answer, `read_cell` each quoted cell and the cells it reads (`get_cell_dependencies`), and answer from what they hold now, not from the quote's text or what you remember. For any other error code or warning, see [reference/errors.md](reference/errors.md). ## Feedback If the user wants to report a problem with Endeavor or say what got in their way, give them this link, with your own agent's name at the end (`claude`, `codex` or `antigravity`): https://jowch.github.io/Endeavor/feedback/?source=plugin&agent=claude. It offers a short form that needs no account, or a GitHub issue. Don't fill in or send either yourself.