Commit Graph

101 Commits

Author SHA1 Message Date
Adrià Arrufat
04ee47c268 Merge branch 'agent' into agent_repl_pimp 2026-06-02 11:23:39 +02:00
Francis Bouvier
f54359aef6 agent: improve banner 2026-06-02 10:45:19 +02:00
Adrià Arrufat
8e063f8e83 repl: add JS evaluation mode 2026-06-02 10:19:37 +02:00
Adrià Arrufat
12b2375969 terminal: support kitty keyboard protocol
Updates the isocline dependency and enables the kitty keyboard
protocol "disambiguate" mode to support Ctrl+Enter detection.
2026-06-02 09:11:56 +02:00
Adrià Arrufat
044b34d228 refactor: remove legacy PandaScript self-healing and execution
Removes the `--self-heal` CLI option, the `scriptStep` and `scriptHeal`
MCP tools, and associated verification/iterator machinery. Replaces
"PandaScript" terminology with "slash commands" and moves shared
helpers to `tools.zig`.

BREAKING CHANGE: The `--self-heal` CLI flag and the `scriptStep` and
`scriptHeal` MCP tools have been removed.
2026-06-01 17:29:24 +02:00
Adrià Arrufat
2104de8e6d agent: move slash command helpers to Terminal
Moves `printHelpSection` and `printSlashParseError` from `Agent` to
`Terminal` to consolidate terminal rendering logic.
2026-06-01 15:10:09 +02:00
Adrià Arrufat
1a7e70fff7 agent: clean up terminal and slash command logic
- Move `atLeast` helper to `AgentVerbosity` enum.
- Simplify `ghostFirstMatch` signature by removing `anytype`.
- Replace pointer-mutating `skipWs` with `skipWhitespace`.
- Convert several comments to doc comments.
2026-06-01 12:19:03 +02:00
Adrià Arrufat
63f2706202 terminal: remove bare command validation
Stop highlighting bare tokens matching tool names as errors. Also
updates the zenai dependency.
2026-05-31 15:29:53 +02:00
Adrià Arrufat
7204de5a1b agent: prompt for provider selection when multiple found
Allows interactive selection of an LLM provider when multiple keys are
detected in the environment. Saves the choice to `.lp-agent.zon`.
2026-05-31 14:33:57 +02:00
Adrià Arrufat
de0eff05f6 terminal: simplify interactive choice selection
Remove number typing input and only support arrow keys and Enter.
2026-05-31 13:21:44 +02:00
Francis Bouvier
99ef54a557 agent: add arrow-key navigation to provider picker
Make the numbered agent choice prompt interactive on TTYs: Up/Down
moves the selected row, Enter confirms it, and numeric input still works as before.

Keep the line-based numbered prompt as the non-interactive fallback, restore
terminal settings after the raw-mode picker exits, and render raw-mode output
with CRLF so menu rows stay aligned. Dim the picker hint text to match existing
terminal command hints.
2026-05-31 13:21:44 +02:00
Adrià Arrufat
88fdeeade8 refactor: extract JSON formatting and timeout helpers 2026-05-30 23:48:50 +02:00
Adrià Arrufat
53ba47cbec agent: suggest closest slash command on typo
Implements Levenshtein distance-based suggestions for unknown slash
commands. If a typo is within two edits of a valid command, the
terminal suggests it with "Did you mean ...?".
2026-05-30 23:40:34 +02:00
Adrià Arrufat
e42862e544 terminal: add ghost hints for slash commands 2026-05-30 23:26:40 +02:00
Adrià Arrufat
c92dad165f command: add /logout and refactor LLM commands 2026-05-30 22:03:46 +02:00
Adrià Arrufat
17aeef886c terminal: show ghost text hints for /help arguments 2026-05-30 20:11:03 +02:00
Francis Bouvier
8052f0ad81 Agent model provider picker (#2581)
* agent: add a /model command to chnage current model

And remove the pick-model CLI option

* agent: add /provider to change the current provider

* agent: extract requireLlmNoArg helper

* agent: simplify provider detection

* repl: add tab completion for /model and /provider

Changes `/model` and `/provider` to accept an optional name argument
instead of prompting with a numbered list. Bare commands now print the
current selection, while Tab dynamically completes candidates. Model
lists are fetched and cached to prevent redundant network requests.

* agent: remember last selected provider and model

Persists the last selected AI provider and model in a local
`.lp-agent` file and resumes it on startup. Removes the
interactive provider picker in favor of deterministic auto-detection.

* agent: simplify requireLlm and model resolution

Changes `requireLlm` to return a boolean instead of credentials, and
cleans up the model initialization logic to use `resolved` directly.
Also removes unused user errors.

---------

Co-authored-by: Adrià Arrufat <adria.arrufat@gmail.com>
2026-05-30 19:02:44 +02:00
Adrià Arrufat
9689aa0412 Improve extraction (#2577)
* tools: add session-scoped bridge store

Exposes `globalThis.lp` to `/eval` calls, allowing state to persist
across evaluations and page navigations. Adds a `save` parameter to
both `/eval` and `/extract` to store results in the bridge.

* browser: await promises in eval and support inline args

- Await JS Promises in `eval` tool with a 30s timeout
- Support inline arguments in multi-line slash commands
- Silence output on successful `save=`
- Add `limit` option to extract schema walker

* eval: return empty text for undefined async IIFE

* extract: support limit on simple string arrays

Treats `["<sel>"]` as sugar for `[{"selector": "<sel>"}]` in the schema
walker. This enables the `"limit"` option on simple string arrays.
Also updates agent documentation to cover cross-call state with `lp.*`.

* refactor: optimize bridge store and schema lookup

- Introduce `bridgeStorePut` to skip redundant JSON validation for
  trusted stringified values in `bridgeSync`.
- Store the schema pointer in `BlockOpener` to avoid re-parsing and
  looking up the schema in `Iterator.next`.
- Clean up error handling and optional unwrapping in `execEval`.
2026-05-29 17:15:21 +02:00
Adrià Arrufat
6e7a4420e3 terminal: deduplicate error and warning printing
Extracts the common printing logic from `printError` and `printWarning`
into a new `printSeverity` helper function.
2026-05-25 18:18:20 +02:00
Adrià Arrufat
8721bfb69e Spinner: prevent line wrapping and multi-line breaks
Strips control characters from tool arguments to avoid breaking the
carriage-return redraw. Queries the terminal width and truncates
arguments to fit on a single row, appending an ellipsis if needed.
2026-05-23 17:22:47 +02:00
Adrià Arrufat
4c06fe482f agent: record slash commands as tool calls
Mirrors user-typed slash commands into the message history as synthetic
tool calls. This ensures the LLM conversation remains in sync and the
next prompt can see the action's result.
2026-05-23 11:54:48 +02:00
Adrià Arrufat
f917a7adfc terminal: simplify print API and add printDimmed
Unifies printInfo/printInfoFmt and printError/printErrorFmt into
single functions accepting format arguments. Adds printDimmed for
dimmed output and supports highlighting quoted slash arguments.
2026-05-22 21:49:41 +02:00
Adrià Arrufat
5454f2b2c2 terminal: disable completions inside triple quotes 2026-05-22 21:15:14 +02:00
Adrià Arrufat
4d283ae21c terminal: improve colors and help formatting
- Remove automatic dimming from `printInfoFmt`
- Add explicit ANSI formatting to slash command help
- Adjust syntax highlighting colors for terminal output
2026-05-22 20:56:35 +02:00
Adrià Arrufat
c30ccae5fb terminal: improve log routing and navigation error reporting
- Route logs through a terminal sink to avoid trampling the spinner.
- Track and format the last navigation error in browser tools.
2026-05-22 19:58:02 +02:00
Adrià Arrufat
0219ee66b7 tools: add argument diagnostics
Validate tool arguments like `waitUntil` before parsing to provide
clearer error messages with expected enum values.
2026-05-22 19:33:53 +02:00
Adrià Arrufat
f7a4d1f6e2 terminal: unify tool and action result printing
Replaces `printActionResult` and `printToolResult` with a single
`printToolOutcome` function. This unifies the output path and adds
red/green color coding for tool failures and successes.
2026-05-22 19:05:46 +02:00
Adrià Arrufat
1309407e01 script: unify heal formatting and move TTY helpers
- Merge `formatHealReplacement` and `formatHealReplacementLines` using
  a new `HealBody` union.
- Move `interactiveTty` and `promptNumberedChoice` to `Terminal.zig`.
- Relocate and consolidate tests for `canHeal` and `isRecorded`.
- Make internal `Schema` functions private.
2026-05-22 16:19:46 +02:00
Adrià Arrufat
486d0d53a9 agent: inline CommandRunner and simplify Command union 2026-05-22 15:50:36 +02:00
Adrià Arrufat
3a792c7c1c command: centralize slash command parsing and retry logic 2026-05-22 15:17:59 +02:00
Adrià Arrufat
8fb3c7baed tools: restructure browser tools and script schemas
- Replace `Action` enum with `Tool` enum using exhaustive switches
- Extract `ScriptIterator` to `Iterator.zig`
- Refactor `schema.zig` into `Schema.zig`
- Move string substitution logic into `tools.zig`
- Clean up `SlashCommand.zig` to only handle REPL meta-commands
2026-05-22 13:41:04 +02:00
Adrià Arrufat
a3eeec0b26 agent: use global tools and simplify meta commands
- Initialize tools once globally instead of allocating per-agent.
- Refactor meta commands to use an enum for cleaner dispatch.
- Remove unused `findSchemaCanonical` and simplify command parsing.
2026-05-21 23:24:21 +02:00
Adrià Arrufat
8cf431b771 agent: remove ToolExecutor abstraction
Inlines the browser, session, and node registry management directly
into Agent. Updates CommandRunner to use Session and Registry directly,
and calls browser_tools.call without the ToolExecutor wrapper.
2026-05-21 22:02:27 +02:00
Adrià Arrufat
d16f8a032e script: support triple-quoted strings and optimize lookups
- Add support for triple-quoted strings (''' and """) in the tokenizer
  and quote stripper.
- Avoid allocations in `stripQuotes` by returning slices.
- Optimize schema lookups using O(1) enum-based canonical resolution.
- Skip env var substitution if "$LP_" is not present in the string.
2026-05-21 21:33:05 +02:00
Adrià Arrufat
7f60d73338 use global schemas and enum-based tool matching
- Use `SlashCommand.globalSchemas()` instead of passing schemas around.
- Use `browser_tools.Action` enums for tool matching in Agent and Verifier.
- Optimize string substitution and quote stripping with early exits.
2026-05-21 21:08:02 +02:00
Adrià Arrufat
459893f414 script: unify PandaScript to slash commands
Unifies PandaScript syntax by replacing uppercase keywords with slash
commands (e.g., `/goto`, `/click`, `/fill`). Refactors the `Command`
representation to use a generic tool call structure backed by schemas.

BREAKING CHANGE: Uppercase PandaScript keywords (GOTO, CLICK, TYPE, etc.)
are no longer supported. All scripts must use slash commands.
2026-05-21 20:38:21 +02:00
Adrià Arrufat
3e0a59c96a browser: avoid dangling pointers in lpEnvNames
Walk std.c.environ dynamically and duplicate names into a provided
allocator instead of caching pointers to std.os.environ, which can
be invalidated by setenv.
2026-05-21 17:28:49 +02:00
Adrià Arrufat
19e3e7b74e agent: simplify spinner and remove tool failure state 2026-05-19 13:16:51 +02:00
Adrià Arrufat
92733763d8 refactor: use explicit type names and encapsulate spinner state
- Replace `Self` with `Recorder` and `Verifier` for improved clarity.
- Add `Spinner.isEnabled()` to encapsulate atomic state access.
- Shorten and refine various comments across the codebase.
2026-05-19 11:13:15 +02:00
Adrià Arrufat
8d250ac7b0 agent: rename --task-attachment to --attach
Adds the `-a` short flag, improves CLI validation for one-shot mode,
and ensures `--model` takes precedence over `--pick-model`.

BREAKING CHANGE: `--task-attachment` has been renamed to `--attach`.
2026-05-19 11:02:46 +02:00
Adrià Arrufat
0efbcc1289 spinner: make enabled flag atomic
Updates the `enabled` field in `Spinner` to use `std.atomic.Value(bool)`.
This prevents potential race conditions between the agent thread and
the spinner worker thread when checking or updating the state.
2026-05-19 10:23:24 +02:00
Adrià Arrufat
373920841c agent: add /verbosity slash command 2026-05-15 10:51:21 +02:00
Adrià Arrufat
b2454a9190 chore: add license headers to source files 2026-05-13 13:20:36 +02:00
Adrià Arrufat
96fce3c56f refactor: unify tool UI and browser action finalization
- Add `beginTool` and `endTool` to `Terminal` to encapsulate spinner logic.
- Consolidate navigation awaiting and context tagging in browser tools
  via a new `finalizeAction` helper.
2026-05-13 12:10:07 +02:00
Adrià Arrufat
ecd27791e4 terminal: skip isocline setup in script mode
Prevents unwanted terminal probes (ESC[6n) when not in REPL mode by
wrapping Isocline initialization in a conditional.
2026-05-12 15:10:06 +02:00
Adrià Arrufat
bfe9f98fb7 agent: unify REPL result and error formatting 2026-05-12 12:22:17 +02:00
Adrià Arrufat
11fb6a3f6e agent: improve slash command parsing and spinner logic
- Use `SlashCommand.splitNameRest` for cleaner command handling.
- Centralize `max_hint_slots` constant and add assertions.
- Refactor `Spinner` thread management and rendering code.
2026-05-12 11:58:24 +02:00
Adrià Arrufat
ef1dde49a6 terminal: improve command highlighting with prefix checking 2026-05-12 11:29:34 +02:00
Adrià Arrufat
19c33499cb terminal: delay error highlighting until token is closed 2026-05-12 11:25:04 +02:00
Adrià Arrufat
60a880a88c terminal: simplify command completion logic
Removes hardcoded starters and uses trailing spaces to trigger hints for
commands with parameters. Updates isocline dependency.
2026-05-12 11:19:48 +02:00