Commit graph

17 commits

Author SHA1 Message Date
Armin Ronacher
18b142f2fe fix(codemode,durable,coding-agent): start() runs in one remote session; review fixes
- RemoteCodemodeSandbox ran start() step by step, saving the whole heap after
  every step (and failing on a WeakRef). Sandboxes now open a run with its
  lifetime (session or saved), and a start() run is one session on the remote,
  as on main.
- start()'s tests run on the worker, inline, and remote sandboxes again, with
  main's cases for globals numbered with tools and rejections carrying their
  properties; a test checks a remote start() takes no steps.
- start()'s fingerprint names the run's actual CPU budget (none, a number, or
  remote), not "default" for every sandbox.
- start()'s call records carry the module; the dropped calls are computed once.
- Durable skips a namespace named like a built-in global or a global's
  namespace (models) as a module, instead of failing every script; pi-codemode
  exports CODEMODE_RESERVED_NAMES from /declarations for it.
- Docs: CodemodeHostCall.id, durable's call keys and schema, the CHANGELOGs
  (start()'s jsName, the un-awaited calls rule, /remote, strict mode and UTC in
  the coding agent), the README on dropped calls and remote start() runs, and
  the coding agent's Bun caveat, which no longer holds (checked on Bun 1.4.4:
  a long sort or split stops at the deadline).
2026-11-30 19:15:05 +01:00
Armin Ronacher
5b74b2b7bc feat(codemode): local time is UTC in every run; store() errors without the host stack
- djs's local zone is one fixed offset (the host's current one, no DST), so
  dates across a DST change were an hour off. Every run now passes
  timeZoneOffset 0: getTimezoneOffset() is 0 and local time is UTC, as it
  already was in deterministic runs.
- A store() value JSON cannot hold no longer puts the host's
  JSON.stringify stack (absolute host paths) into the script's error; the
  reason is name and message only.
2026-11-30 19:15:05 +01:00
Armin Ronacher
8ce71fa54f feat(coding-agent): codemode on djs, a worker per script
Scripts run on djs in a worker of their own, as before with QuickJS: worker admission
and PI_CODEMODE_MAX_WORKERS stay, the bundle and the Bun binary embed djs.wasm and the
codemode worker. A script has a CPU budget of about a minute; TypeScript works.
2026-11-30 19:08:13 +01:00
Vegard Stikbakke
c863bdf19c feat(ai,coding-agent): add image generation options
- Add aspectRatio and size to ImagesOptions
- Forward aspectRatio and size to OpenRouter's image_config in
  openrouter-images
- Validate and forward optional { aspectRatio, size } as the third
  argument to codemode models.generateImages(); unknown option keys
  such as apiKey or aspect_ratio throw
- Document the options in the ai README and the codemode and models
  docs, and add tests
2026-11-26 15:25:51 +01:00
Vegard Stikbakke
6906528da0 docs(ai,coding-agent): use decision models in prose and changelogs
Pi-Session: 01a2119a-06d9-7426-b332-0e6e6770881c
2026-11-25 08:43:24 +01:00
Vegard Stikbakke
fe1c08109d docs(coding-agent): document classifier responseId in codemode 2026-11-24 14:59:33 +01:00
Petr Houška
943a99e3c2
fix(coding-agent,tui): stop temp file write failures from crashing pi (#12452)
Fixes #10585.

## Problem

Bash output past the truncation limit is copied to a temp file in
`$TMPDIR`. The `WriteStream` had no `error` listener, so any open or
write failure became an uncaught exception and killed pi, including the
in-flight turn, subagents and background jobs. Triggers seen in
practice: a full tmpfs `/tmp` (ENOSPC), per-user tmpfs quotas that
systemd sets on `/tmp` (EDQUOT, errno 122), an unwritable `TMPDIR`
(EACCES). Both paths were affected: the agent `bash` tool
(`OutputAccumulator`) and `!` commands (`executeBashWithOperations`).

Only adding a listener is not enough: `end()` on a stream that already
errored never emits `finish` or `error`, so `closeTempFile()` would hang
instead.

## Change

- `createOutputFileStream` returns an `OutputFileStream` wrapper: error
handling from the start, writes ignored after a failure, a partially
written file removed (never a file that was already at the path), and
`close()` that never rejects or hangs and returns `{ kind: "saved", path
} | { kind: "failed", error }`.
- Bash tool: the temp file is closed before the final result is built.
On failure the result keeps the in-memory tail and ends with `[Showing
lines X-Y of N. Could not save the full output: ENOSPC ...]`, without
`fullOutputPath` / `full_output_path`. `readFullOutput()` (structured
output for codemode) falls back to the tail. This matches what codemode
already does for its own output files.
- `!` commands: the executor waits for the file to flush before
returning its path. On failure it returns the tail without a path.
- Other crashes from temp dir failures: opening the external editor
(Ctrl+G) and `/share` now report the error instead of throwing from
key/submit handlers. The TUI width crash keeps its error and restores
the terminal when its debug log cannot be written.

Durable's bash spill handling (kills the command when the spill file
fails) is unchanged; aligning it is left for a separate PR.

## Tests

`test/output-file-failures.test.ts` covers failed open (missing
`TMPDIR`), failed writes (ENOSPC, injected), and `EEXIST` for the
stream, the bash tool and the `!` executor. New cases in
`external-editor.test.ts`, `session-share.test.ts` and
`tui-render.test.ts`.
2026-11-24 00:09:07 +01:00
Mario Zechner
885a564b3b fix(coding-agent): queue codemode scripts at the worker limit
Some checks are pending
CI / build-check-test (push) Waiting to run
CI / mcp-conformance (push) Waiting to run
Scripts wait in arrival order for a free worker instead of failing
immediately. The wait counts toward timeout_ms, honours abort, and is
capped at 60 seconds. PI_CODEMODE_MAX_WORKERS raises the process-wide
limit of two workers for hosts running many sessions in one process.

closes #11184
2026-10-20 20:50:27 +02:00
Armin Ronacher
3daa20280f fix(coding-agent): keep codemode cancellation prompt and bounded
Some checks are pending
CI / mcp-conformance (push) Waiting to run
CI / build-check-test (push) Waiting to run
Refs #10748
2026-10-13 18:17:31 +02:00
Armin Ronacher
b6d505cd1f fix(codemode): reject // @options: lines that are not the first line
A misplaced options line was ignored, so its timeout_ms never applied and
the script ran without a deadline. parseCodemodeSource now throws
CodemodeSourceError before the script runs.

fixes #10631
2026-10-12 17:55:33 +02:00
Armin Ronacher
ce8972a0e9 feat(ai,coding-agent): add OpenAI Decisions classifier and classifier images
Adds the openai-decisions classifier API with gpt-6-luna on the openai provider. bool questions map to predicates with the criteria in the instructions, refusals fail the result, and gateway timeouts (504) are not retried. The model needs an API key and is hidden from availability while openai uses Sign in with ChatGPT.

Adds optional images to ClassifierContext. Models without image input and APIs that cannot send images return an error result. Codemode's models.classify() accepts images.

Moves the shared classifier HTTP code out of system-one-shared.ts into classifier-shared.ts.
2026-10-07 08:27:56 +02:00
Armin Ronacher
eb326d265a fix(codemode,coding-agent): separate codemode output items
Some checks are pending
CI / build-check-test (push) Waiting to run
CI / mcp-conformance (push) Waiting to run
Text items get ==> text N/M <== headers when there are several, and
console output is grouped into one <console_output> block. Console text
items are marked with console: true.
2026-10-06 23:51:09 +02:00
Armin Ronacher
c30840c2eb fix(coding-agent): keep hidden tools out of prompt rules and skills hint
Rules and the tool list follow the declared tools (active minus
hiddenDeclarations). The skills hint names no tool when the reader is
hidden. Codemode shows each tool's prompt guidelines with its
declaration, via the new ToolLoadout.getPromptGuidelines().

closes #10343
2026-10-05 18:50:17 +02:00
Armin Ronacher
021eae60a7 fix(coding-agent): resolve codemode read calls on images to image blocks
read declares an output schema: text for text files, and an image block
with its note for images, which codemode's image() shows.

closes #10251
2026-10-05 16:58:05 +02:00
Armin Ronacher
d677d0ee71 feat(coding-agent): save codemode image() output to temp files
image() output is also written to a temp file and the result names the
path before each image, so later turns can reference generated images.
Output files are now created through one helper (still tmpdir()) and
are readable only by the user.

closes #10310
2026-10-04 23:32:43 +02:00
Armin Ronacher
319fecb89b fix(codemode): cap script output so print loops cannot exhaust host memory
text(), image(), and console.* fail the script with a RangeError past
MAX_OUTPUT_CHARS (16 Mi) characters or MAX_OUTPUT_ITEMS (100000) items.

closes #10283
2026-10-02 17:54:35 +02:00
Armin Ronacher
6f1072cc08 feat(coding-agent): shrink codemode prompt and guide scripts back from errors
Move the codemode script reference, including the models API, into
docs/codemode.md and keep only one line per global in the tool
description. Declared tools get a one-line note on how scripts call them,
and the codemode system prompt guidance and MCP server section are shorter.
With the default tools a GPT-5.6 request drops from about 5,300 to 3,300
tokens.

Errors now point the way back: unknown tools and models members name close
matches, models.classify() and models.generateImages() validate their
arguments, unknown or mistyped models point to getAvailableOfType(),
store() overflow explains the store, and unshown generated images get a note.
2026-10-01 18:27:23 +02:00