Commit Graph

236 Commits

Author SHA1 Message Date
Adrià Arrufat
349b4ea798 agent: clean up dead code and optimize schema parsing
- Remove unused `callEval` and `extract` from `ToolExecutor`.
- Optimize `parseValue` in `schema.zig` to allocate directly instead of
  using `std.ArrayList` when filling missing defaults.
- Simplify redundant checks and clean up comments.
2026-05-21 21:41:28 +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
0ce0d264a4 agent: prevent use-after-free in self-heal path 2026-05-21 20:45:03 +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
88ac71a474 agent: remove no_llm field 2026-05-21 19:05:55 +02:00
Adrià Arrufat
19c361c2e8 agent: use zenai credentials detection 2026-05-21 19:03:48 +02:00
Adrià Arrufat
2bd24ba30e agent: use zenai envVarName helper 2026-05-21 18:55:50 +02:00
Adrià Arrufat
758d2c48fb agent: require --no-llm for basic REPL 2026-05-21 18:37:16 +02:00
Adrià Arrufat
ceb5f368f0 script: rename raw_line to opener_line 2026-05-21 18:01:46 +02:00
Adrià Arrufat
31e20ae261 Recorder: pass directory to init and reuse arena
Update `Recorder.init` to accept a `std.fs.Dir` and relative path,
decoupling it from the current working directory.

Also add a persistent arena allocator to `Recorder` to reuse
allocations when scrubbing environment variables on each write.
2026-05-21 17:45:54 +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
55a50746fa script: move helper functions into Command union
Renames `Command.zig` to `command.zig` and moves associated functions
like `parse`, `toToolCall`, and `canHeal` directly into the `Command`
union. This simplifies usage from `Command.Command` to just `Command`.
2026-05-21 17:13:19 +02:00
Adrià Arrufat
651504efb5 agent: consolidate LLM provider and key resolution
Introduce an `Llm` struct to bundle the provider and API key together.
Add `UserError` to identify errors that have already printed human-
readable messages, preventing duplicate logging on exit.
2026-05-21 15:01:44 +02:00
Adrià Arrufat
85276df004 deps: update zenai and use thinking_level 2026-05-20 00:16:03 +02:00
Adrià Arrufat
98baccf1db agent: update default Gemini model 2026-05-19 23:56:41 +02:00
Adrià Arrufat
19e3e7b74e agent: simplify spinner and remove tool failure state 2026-05-19 13:16:51 +02:00
Adrià Arrufat
e0af9c4168 refactor: unify tool results and rename CommandExecutor
Unifies tool outcomes into a `ToolResult` struct, replacing `EvalResult`.
Renames `CommandExecutor` to `CommandRunner` and simplifies error handling.
2026-05-19 13:01:39 +02:00
Adrià Arrufat
9eed73434c agent: make isHealAllowed exhaustive 2026-05-19 12:09:41 +02:00
Adrià Arrufat
74ba2fb6bd agent: reuse ToolExecutor.buildTools in SlashCommand tests 2026-05-19 12:03:50 +02:00
Adrià Arrufat
2ca26c8bbf agent: simplify slash command test helpers 2026-05-19 11:51:33 +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
7122dd5e52 agent: document Ctrl-C behavior in pickModel
Explains that Ctrl-C is ignored during the synchronous model listing
call because it occurs before SigBridge.attach.
2026-05-19 10:55:11 +02:00
Adrià Arrufat
66e7b1aafd script: improve verifier and recorder robustness
- Make `VerifyResult.failed` reason non-optional with an OOM fallback.
- Use `ElementProperty` enum for safer JS property injection.
- Ensure `Recorder` disables on all errors to prevent silent data loss.
- Add `CHECK` command round-trip test.
2026-05-19 10:51:13 +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
d0a8da453b agent: implement graceful Ctrl-C interruption 2026-05-15 18:45:56 +02:00
Adrià Arrufat
52340f4d62 agent: defer message pruning to avoid dangling pointers 2026-05-15 11:27:03 +02:00
Adrià Arrufat
373920841c agent: add /verbosity slash command 2026-05-15 10:51:21 +02:00
Adrià Arrufat
882ed74e89 agent: update zenai and default models 2026-05-14 19:35:38 +02:00
Adrià Arrufat
e8ac1bada7 agent: make verbosity default context-aware 2026-05-14 17:49:05 +02:00
Adrià Arrufat
cbe81e150b agent: condense prompts and tool descriptions 2026-05-14 14:59:58 +02:00
Adrià Arrufat
61b6003818 refactor: simplify tool execution and recording logic 2026-05-14 13:45:35 +02:00
Adrià Arrufat
2862feb7c4 agent: improve recording quality and tool guidance
- Filter redundant `extract` calls in recordings to reduce noise.
- Scrub literal `LP_*` secrets from recorded commands for portability.
- Throw a descriptive error in `extract` when no selectors match.
- Update tool descriptions and guidance to favor a `tree` ->
  `nodeDetails` -> `extract` workflow for more robust selectors.
2026-05-14 13:36:36 +02:00
Adrià Arrufat
9ac2c03a7e tools: unify eval and extract tool dispatching
- Add `callEvalLike` to consolidate tools returning `EvalResult`.
- Update `Agent` and `MCP` to use the new helper.
- Route failed data commands to stderr in `CommandExecutor`.
- Update CSS selector guidance in `script.zig`.
2026-05-14 11:14:11 +02:00
Adrià Arrufat
688924e7a1 agent: add eval_js support to CommandExecutor
Implements execution for the .eval_js command and adds a helper to
correctly map JavaScript execution errors to the failed state.
2026-05-14 10:37:51 +02:00
Adrià Arrufat
3d8621561a tools: add extract tool for structured data
Adds the `extract` tool for lifting structured data via JSON schemas.
Updates the command system to support recording and replaying
extraction steps in PandaScript.
2026-05-14 10:32:59 +02:00
Adrià Arrufat
819d2f9884 verifier: change VerifyResult to a tagged union
Replaces the struct-based result with a tagged union to represent
verification outcomes more idiomatically. Updates callers in Agent
and MCP tools to handle the new union type.
2026-05-14 09:39:12 +02:00
Adrià Arrufat
eb863e0b16 script: unify tool call conversion to use json values 2026-05-14 09:23:54 +02:00
Adrià Arrufat
001fbb97d0 Recorder: make init fallible and Agent.recorder optional 2026-05-14 08:59:47 +02:00
Adrià Arrufat
f35a80682b refactor: simplify CommandExecutor and switch MCP to extractSchema
- Remove `extractText` from browser tools and `ToolExecutor`
- Update MCP `extract` step to use `extractSchema` instead of a selector
- Remove `allocator` and `execute` method from `CommandExecutor`
2026-05-14 08:41:09 +02:00
Adrià Arrufat
c009b291cb agent: correctly report JS errors in eval tool
Routes the eval tool through callEval instead of callValue. This
ensures JavaScript execution errors are flagged with is_error=true,
allowing the model to self-correct.
2026-05-13 14:33:11 +02:00
Adrià Arrufat
6538a34f56 browser: separate operational and JS errors in eval
Changes `EvalResult` to a union and uses Zig errors for operational
failures, distinguishing them from JavaScript execution errors.
Also removes redundant `stringifyJson` in favor of standard library.
2026-05-13 14:27:28 +02:00
Adrià Arrufat
fb06e282c2 agent: simplify promptNumberedChoice API\ 2026-05-13 13:29:26 +02:00
Adrià Arrufat
b2454a9190 chore: add license headers to source files 2026-05-13 13:20:36 +02:00
Adrià Arrufat
b4b533d2be agent: derive Action enum from tool_defs and clean up Verifier
- Derives the `Action` enum in `src/browser/tools.zig` from `tool_defs` to prevent manual maintenance and potential drift.
- Refactors `verifyElementValue` in `src/script/Verifier.zig` to use a `Check` struct for its parameters.
- Reorganizes and cleans up imports in `src/agent/Agent.zig`.
2026-05-13 13:18:30 +02:00
Adrià Arrufat
f35c4219c9 refactor: improve error handling and rename Self to Agent
- Replace `unreachable` with explicit error returns in Agent and Executor.
- Add `EvalResult.err` helper in `tools.zig` to simplify error paths.
- Improve error propagation in `SlashCommand` and `Recorder`.
- Rename `Self` to `Agent` for better clarity in function signatures.
2026-05-13 13:15:44 +02:00
Adrià Arrufat
6478853e93 agent: simplify zig syntax and arena usage 2026-05-13 13:01:30 +02:00
Adrià Arrufat
cc59dd64b9 script: make ScriptIterator.next fallible 2026-05-13 12:40:07 +02:00
Adrià Arrufat
18890ea695 spinner: reset state on thread spawn failure 2026-05-13 12:25:32 +02:00