Commit Graph

46 Commits

Author SHA1 Message Date
katie-lpd
a48dd45163 Update agent.md 2026-06-09 15:49:34 +02:00
Adrià Arrufat
2601ba5d9c docs(agent): restore dropped features and fix markdown nits
The agent.md rewrite dropped documentation for several features that still
exist in the code. Restore them and clean up the markdown:

- Re-add /clear and /reset to the meta-commands table
- Re-add waitForState to the browser-tools list and the /save
  state-mutating command list
- Re-add --system-prompt and --verbosity (with the --task stderr-pipe
  escalation) to the providers section
- Strip trailing whitespace on blank lines; add blank lines before
  headings and between lists and following paragraphs
2026-06-09 14:31:05 +02:00
katie-lpd
cd6e875707 Update agent.md
- **New opening.** Direct framing: "lets you drive a headless browser by talking to it."
- **New "How to think about it" section.** Explains the three-layer stack and the one-sentence pitch ("pay for the LLM once, then replay deterministically").
- **New "The REPL is where you build scripts" section.** Positions the REPL as a sandbox with a full sandbox-to-saved-script example.
- **New tips section.** Practical guidance for prompts that produce useful saved scripts (be specific about extracted data, name the page, check the file).
- **Updated Quick start.**
2026-06-09 13:29:32 +02:00
Adrià Arrufat
9d4f284c73 browser: add waitForState and default goto to load
Removes the `waitUntil` option from `goto` and other navigation tools,
making them default to the fast `load` event. Introduces a dedicated
`waitForState` tool to wait for specific load states on demand.
2026-06-05 16:26:19 +02:00
Adrià Arrufat
c355b0bda8 agent: add /clear and /reset REPL commands
- `/clear` forgets conversation history, usage, and node IDs while
  keeping the loaded page and cookies.
- `/reset` does a full reset, starting a fresh browser session.
2026-06-05 14:13:10 +02:00
Adrià Arrufat
2d2914e878 agent: add /usage slash command to REPL
Adds a new `/usage` meta command to print cumulative token usage and
cache hit rate for the current session. Also updates zenai.
2026-06-05 13:35:34 +02:00
Adrià Arrufat
5f2330bb2f agent: add reasoning effort configuration
Adds the `--effort` CLI flag and `/effort` REPL command to control
the reasoning budget, persisting the setting in `.lp-agent.zon`.
2026-06-05 12:40:34 +02:00
Adrià Arrufat
76504604ba docs: update recorder details and add /logout 2026-06-05 12:14:42 +02:00
Adrià Arrufat
157aa30bdc agent: clarify script primitives and save behavior
Updates documentation to clarify that script primitives use CSS
selectors instead of backendNodeIds. Explains how to use `/nodeDetails`
to get selectors. Clarifies the difference in `/save` behavior
between `--no-llm` and LLM modes.
2026-06-05 11:26:24 +02:00
Adrià Arrufat
d18297f204 agent: update docs for recent features and fixes
Updates documentation to reflect the new REPL status bar, JS mode,
corrected `press` syntax, and updated error messages.
2026-06-05 10:43:41 +02:00
Adrià Arrufat
3044f620b9 docs(agent): update docs for recent features and CLI flags
Updates agent-related documentation to reflect recent changes:
- Removes obsolete `follow` option from `extract` schema.
- Documents automatic printing of the script's final expression.
- Adds details on Ollama auto-detection and new CLI flags.
- Documents the `/logout` command and updated tool list.
2026-06-05 10:23:50 +02:00
Adrià Arrufat
05e815225d script: print completion value automatically
Automatically prints the script's final top-level expression (objects
and arrays as JSON, others coerced). Updates docs and prompts to match.
2026-06-04 10:38:02 +02:00
Adrià Arrufat
d06bf747f4 agent: clarify synchronous nature of primitives
Update agent.md and the LLM synthesis prompt to explicitly state
that agent primitives are synchronous and blocking, and should not
use async/await or Promises.
2026-06-03 20:11:55 +02:00
Adrià Arrufat
3514a59236 extract: remove follow option from schema 2026-06-03 19:34:32 +02:00
Adrià Arrufat
5dd37af123 tools: rename eval tool to evaluate 2026-06-03 17:30:25 +02:00
Adrià Arrufat
ac82551e66 agent: replace -i flag with /save and /load commands
Removes the `-i`/`--interactive` CLI flag and live file-based
recording. Instead, the REPL now supports a `/load <path>` command
to run scripts from disk, and `/save` to export the in-memory
session recording.

The `Recorder` is simplified to be purely in-memory, and the script
runtime is moved to `src/script/Runtime.zig`.

BREAKING CHANGE: The `-i`/`--interactive` flag has been removed. Use
the `/save` and `/load` commands within the REPL instead.
2026-06-03 16:21:10 +02:00
Adrià Arrufat
4139252feb mcp: replace recording and healing tools with save
Removes recordStart, recordStop, recordComment, scriptStep, and
scriptHeal MCP tools. Introduces a single 'save' tool that lets
the client synthesize and persist the script directly.
2026-06-03 10:01:38 +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
Francis Bouvier
8824174afa agent: run recorded scripts as JavaScript
Replace recorded agent replay with a standalone JavaScript script runtime.
Install synchronous agent primitives in an isolated V8 context, add console
output, return structured extract values as JS objects/arrays, and route script
execution through the new runtime.

Update recording to emit .js function calls, default /save filenames to .js,
drop script-level extract save support, and refresh agent docs/tutorials for
the new format.

Self-healing is disabled for now.
2026-06-01 15:43:37 +02:00
Adrià Arrufat
cf65a00a8f extract: add declarative follow option
Allows fetching sub-pages per row and resolving nested fields against
them. Supports string templates with sibling placeholders (e.g., `{id}`)
and element-specs. Updates the JS walker to be async.
2026-05-31 17:07:42 +02:00
Adrià Arrufat
fc15027100 eval: clarify automatic JSON serialization
Update agent docs and tool descriptions to note that objects and
arrays are automatically serialized to JSON, making manual
`JSON.stringify` calls unnecessary.
2026-05-31 16:27:28 +02:00
Adrià Arrufat
27c2fe00c7 eval: support top-level await and return
Falls back to compiling the script inside an async IIFE if the initial
block-scoped compilation fails. This enables top-level await and return
statements directly in the eval tool.
2026-05-31 16:10:42 +02:00
Adrià Arrufat
1f85de3d3d agent: use ZON format for remembered config
Migrates the `.lp-agent` file to `.lp-agent.zon` and uses `std.zon`
for serialization and parsing.
2026-05-30 19:10:40 +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
bd861f5ac0 mcp: rename tools to camelCase 2026-05-24 11:13:56 +02:00
Adrià Arrufat
fec1909aa1 script: strip backendNodeId and fix error line reporting
- Allow recording commands with backendNodeId if they also have a
  selector, stripping backendNodeId during formatting.
- Point UnterminatedQuote errors to the opening line instead of EOF.
- Fix buildHints allocation when fields is empty but required is not.
- Update docs to clarify positional argument rules.
2026-05-22 09:18:32 +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
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
303c5eefce agent: document schema-based EXTRACT command 2026-05-13 09:30:32 +02:00
Adrià Arrufat
0bbb77f292 agent.tutorial: document structured EXTRACT schema
Updates the agent tutorial to explain the JSON schema grammar for the
EXTRACT command, including selectors, attributes, and nested fields.
Adds examples for multi-line input and clarifies recording behavior.
2026-05-13 09:20:27 +02:00
Adrià Arrufat
cd830a7152 agent: add end-to-end tutorial 2026-05-12 10:20:50 +02:00
Adrià Arrufat
1a84f56160 refactor: relocate PandaScript and improve agent reliability
Moves script logic to `browser/script/` for shared use. Implements
message rollback on API failure, caches environment variables, and
fixes a potential panic in the spinner.

- Relocate Command, Recorder, and Verifier to `src/browser/script/`
- Implement message rollback on API and synthesis failures in Agent
- Cache `LP_*` environment variables process-wide with mutex protection
- Fix potential panic in Spinner during backward clock jumps
- Improve Recorder to handle write failures and multi-line comments
- Update documentation regarding attachments and path safety
2026-05-11 19:49:15 +02:00
Adrià Arrufat
b5777ce35c agent: support listing LP_* variables in getEnv 2026-05-11 12:34:36 +02:00
Adrià Arrufat
ecfb404af4 agent: require ALL CAPS for commands 2026-05-11 11:41:04 +02:00
Adrià Arrufat
16b83f5093 agent: add provider auto-detection and --no-llm flag 2026-05-09 19:52:42 +02:00
Adrià Arrufat
c6ccd83ac4 mcp: add pandascript recording and self-healing tools
Adds tools to record sessions and heal scripts over MCP. Refactors
shared logic to `script.zig` and adds a TTY spinner for the agent.
2026-05-07 20:11:40 +02:00
Adrià Arrufat
7bf69a9a34 agent: remove integrated mcp server
Removes the `--mcp` flag and the internal `task` tool from the agent.
Users should use `lightpanda mcp` for external agent integrations.
2026-05-07 17:12:46 +02:00
Adrià Arrufat
a9b3b66802 agent.mcp: prevent path traversal in task attachments 2026-05-04 10:33:46 +02:00
Adrià Arrufat
2ca7550947 agent: restrict getEnv tool to LP_ namespace
Limits the getEnv tool to variables starting with LP_ to prevent the
model from probing sensitive system environment variables or API keys.
2026-05-04 09:54:13 +02:00
Adrià Arrufat
8ce0624f0d agent: clarify that WAIT waits for DOM presence 2026-05-04 07:23:06 +02:00
Adrià Arrufat
eb14783af7 agent: rename Pandascript to PandaScript and .panda to .lp 2026-04-30 17:29:36 +02:00
Adrià Arrufat
300fdfb34c agent: add MCP server mode with task tool 2026-04-30 17:11:48 +02:00
Adrià Arrufat
85f2a08128 agent: update docs 2026-04-30 16:29:52 +02:00
Adrià Arrufat
7aef08f28b agent: replace QUIT command with /quit slash command 2026-04-30 16:22:19 +02:00
Adrià Arrufat
5b66a4f227 agent: add agent mode and pandascript documentation 2026-04-30 16:06:47 +02:00