Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 4 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ else()
endif()

option(BUILD_SHARED_LIBS "Enable compilation of shared libraries" OFF)
option(WEBFRONT_BUILD_AUTOMATION "Build the optional local developer CLI/MCP launcher" OFF)
option(WEBFRONT_BUILD_EXAMPLES "Build the example applications" ${WEBFRONT_IS_TOP_LEVEL})
option(WEBFRONT_DISTRIBUTION "Require WebKitGTK sandboxing for distribution (development disables it by default)" OFF)
option(WEBFRONT_GZIP_DIFFERENTIAL "Build test-only gzip/zlib differential checks" OFF)
Expand Down Expand Up @@ -148,24 +147,11 @@ webfront_add_embedded_assets()
# Opt-in consumer test registration; inclusion alone downloads nothing and registers no tests.
include(WebFrontJasmine)

if(WEBFRONT_BUILD_AUTOMATION OR (WEBFRONT_ENABLE_TESTING AND
(WEBFRONT_EMBED_CEF OR WEBFRONT_EMBED_WKWEBVIEW OR WEBFRONT_EMBED_WEBVIEW2 OR WEBFRONT_EMBED_WEBKITGTK)))
webfront_default_embedded_frontend(_automation_default FALLBACK CEF)
webfront_select_frontend(WEBFRONT_AUTOMATION_FRONTEND "${_automation_default}"
"Developer automation frontend" EMBEDDED_ONLY REQUIRE_AVAILABLE)
if(NOT ${WEBFRONT_FRONTEND_${WEBFRONT_AUTOMATION_FRONTEND}_OPTION})
message(FATAL_ERROR "Automation needs an explicitly enabled embedded frontend")
endif()
add_executable(webfront-agent js/developer/tools/WebFrontAgent.cpp)
target_link_libraries(webfront-agent PRIVATE WebFront WebFront_options WebFront_warnings)
if(WIN32)
target_link_libraries(webfront-agent PRIVATE ws2_32 bcrypt advapi32)
endif()
target_compile_definitions(webfront-agent PRIVATE WEBFRONT_AUTOMATION_FRONTEND_TYPE=${WEBFRONT_AUTOMATION_FRONTEND_TYPE})
webfront_setup_frontends_for_target(webfront-agent)
# The webfront-agent launcher is gone (ADR-025): an application that enables automation serves MCP itself.
if(DEFINED WEBFRONT_BUILD_AUTOMATION OR DEFINED WEBFRONT_AUTOMATION_FRONTEND)
message(WARNING "WEBFRONT_BUILD_AUTOMATION and WEBFRONT_AUTOMATION_FRONTEND no longer build anything: webfront-agent was removed. "
"An application that calls webfront::automation::enableAutomation serves MCP itself (docs/AUTOMATION.md).")
endif()
# Public helper for a parent project: checks the launcher target and optionally installs it.
include(WebFrontAgent)
# What an agent configuring a project must learn at once: the development model, and how it runs wf itself.
include(WebFrontAgentGuide)
webfront_announce_agent_support()
Expand Down
26 changes: 11 additions & 15 deletions README.fr.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,21 +94,18 @@ Une application WebFront est un programme C++ dont l'interface TypeScript/TSX se

Avec l'environnement épinglé, l'ordre est : `wf create app` (nom du starter, pas du projet), `wf init`, `wf install <paquet>` pour les dépendances navigateur, puis `wf dev ui/main.ts`. Terminez par `wf check`, `wf test` et `wf embed` selon la configuration du projet. `wf create life` fournit le starter React du parcours ci-dessous ; `wf help agents` décrit la marche à suivre.

**L'agent exécute les commandes lui-même**, sans demander à l'utilisateur de les saisir. Configurez avec `-DWEBFRONT_BUILD_AUTOMATION=ON` pour construire `webfront-agent`. L'application partage sa session explicitement avec `webfront::automation::enableAutomation(app, {.grants = {...}, .listen = directory})` ; les autorisations restent choisies par son propriétaire.
**L'agent exécute les commandes lui-même**, par MCP, sans demander à l'utilisateur de les saisir. Dans une build de développement, l'application active l'automatisation avec `webfront::automation::enableAutomation(app, {.grants = {...}})` ; les autorisations restent choisies par son propriétaire. L'application devient alors le serveur MCP : aucun autre programme n'est construit ni lancé. Elle affiche son URL et le chemin d'une configuration cliente privée (`mcp.json`, avec l'URL et un jeton Bearer, hors du projet) :

```sh
webfront-agent --list
webfront-agent --attach DIRECTORY --operation create --starter app
webfront-agent --attach DIRECTORY --operation preview --entry ui/main.ts
webfront-agent --print-mcp-config --attach DIRECTORY > .mcp.json
```text
WebFront MCP (grants: check, build, preview): http://127.0.0.1:PORT/mcp - client configuration: .../sessions/SESSION/mcp.json
```

Après chaque modification, l'agent utilise `preview` à la place de la session interactive `wf dev`. La même interface est disponible en MCP :

```json
{"mcpServers": {"webfront": {"command": "/path/to/webfront-agent", "args": ["--attach", "/path/to/directory", "--mcp"]}}}
{"mcpServers": {"webfront": {"type": "http", "url": "http://127.0.0.1:PORT/mcp", "headers": {"Authorization": "Bearer TOKEN"}}}}
```

Donnez ce fichier au client MCP (`claude --mcp-config PATH/mcp.json`) et ne copiez jamais le jeton dans le projet. L'agent appelle ensuite `webfront.start` avec `create`, `preview` (après chaque modification, à la place de `wf dev`), `check`, `test` ou `embed`, et suit chaque exécution avec `webfront.result`.

Dans un projet consommateur, `webfront_write_agent_guide()` écrit un `AGENTS.md` à la racine ; `wf create` le place à côté des sources du starter. Le [guide des agents](docs/DEVELOPING_WITH_AGENTS.md) détaille ce contrat.

## Du C++ à une interface réactive
Expand Down Expand Up @@ -346,7 +343,7 @@ La recompilation est explicite. L'application fonctionne ensuite hors ligne, san

Un agent peut vérifier les types, construire, prévisualiser, inspecter et cliquer l'interface de **votre application**, dans sa fenêtre et avec ses callbacks C++. Rien n'est activé par défaut.

<img src="docs/images/automation-agent.svg" width="100%" alt="Transcription animée : découverte de session, vérification, compilation, aperçu, clic et appel d'un callback autorisé ; refus d'un callback privé">
<img src="docs/images/automation-agent.svg" width="100%" alt="Transcription animée : connexion à l'URL MCP de l'application, vérification, compilation, aperçu, clic et appel d'un callback autorisé ; refus d'un callback privé">

*Transcription abrégée du test de régression `AutomationConsumerWindow`, exécuté sur une application réelle.*

Expand All @@ -360,17 +357,16 @@ app.bootstrap("developer");
app.cppFunction("bf.render", render);
auto automation = webfront::automation::enableAutomation(
app, {.grants = {"check", "build", "preview", "inspect", "interact", "call"},
.callbacks = {"bf.render"},
.listen = privateEndpointDirectory});
.callbacks = {"bf.render"}});
app.show(automation->launchPage());
automation->close();
app.shutdown();
```

- **Visible.** Le terminal annonce les autorisations et la manière de se connecter.
- **Découvrable.** `webfront-agent --list` liste les sessions partagées sans exposer leur secret de connexion ; `--print-mcp-config --attach <dir>` génère la configuration du client MCP. `--schema` et `--agent-help` décrivent le contrat.
- **Visible.** L'application affiche son URL MCP, et le terminal annonce les autorisations.
- **Découvrable.** Chaque instance en cours publie son URL et le chemin de son `mcp.json` privé dans un enregistrement par utilisateur, jamais le jeton ; `claude --mcp-config PATH/mcp.json` ou tout client MCP s'y connecte.
- **Borné.** Chaque opération demande son autorisation ; seuls les callbacks nommément déclarés sont appelables. Des délais natifs arrêtent un renderer bloqué. Le code du projet conserve les droits de l'utilisateur : ce n'est pas un sandbox.
- **Optionnel.** Sans `enableAutomation`, aucun endpoint n'est enregistré. `webfront_add_agent()` construit et installe le lanceur pour les consommateurs CMake.
- **Optionnel.** Sans `enableAutomation`, rien n'est enregistré et aucun port n'est ouvert ; une build de distribution (`WEBFRONT_DISTRIBUTION`) refuse de le compiler.

Le [guide d'automation](docs/AUTOMATION.md#automating-your-own-application) décrit permissions, découverte, délais et profil MCP.

Expand Down
24 changes: 11 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,18 @@ If you are a coding agent, or work with one, read this before anything else. The

- **The model.** A WebFront application is a C++ program whose interface is TypeScript/TSX. The interface lives in **`ui/`** of the project directory (`ui/main.ts` or `ui/main.tsx`) and is developed with **`wf dev`**, in the terminal that `app.bootstrap("developer")` opens in the application's window. Pages of hand-written HTML and classic JavaScript served through `documentRoot` are not the development path: none of the tools apply to them.
- **The sequence.** With the pinned developer environment: `wf create app` (the starter name, not your project's name), `wf init`, `wf install <package>` for browser dependencies, then `wf dev ui/main.ts`. Finish with `wf check`, `wf test` and `wf embed` using the project's configuration. Use `wf create life` for the React walkthrough. `wf help agents` prints the workflow.
- **An agent runs `wf` itself, in JSON or MCP.** Do not ask a person to type the commands. Configure with `-DWEBFRONT_BUILD_AUTOMATION=ON` to build `webfront-agent`; the application opts in with `webfront::automation::enableAutomation(app, {.grants = {...}, .listen = directory})`, whose grants stay the owner's; then:
- **An agent runs `wf` itself, through MCP.** Do not ask a person to type the commands. In a development build, the application opts in with `webfront::automation::enableAutomation(app, {.grants = {...}})`, whose grants stay the owner's, and becomes the MCP server: no other program is built or launched. It prints its URL and the path of a private client configuration (`mcp.json`, URL and Bearer token, outside the project):

```sh
webfront-agent --list # the sessions shared with agents
webfront-agent --attach DIRECTORY --operation create --starter app
webfront-agent --attach DIRECTORY --operation preview --entry ui/main.ts # after each edit, in place of wf dev
webfront-agent --print-mcp-config --attach DIRECTORY > .mcp.json # the same operations as an MCP server
```text
WebFront MCP (grants: check, build, preview): http://127.0.0.1:PORT/mcp - client configuration: .../sessions/SESSION/mcp.json
```

```json
{"mcpServers": {"webfront": {"command": "/path/to/webfront-agent", "args": ["--attach", "/path/to/directory", "--mcp"]}}}
{"mcpServers": {"webfront": {"type": "http", "url": "http://127.0.0.1:PORT/mcp", "headers": {"Authorization": "Bearer TOKEN"}}}}
```

Pass that file to the MCP client (`claude --mcp-config PATH/mcp.json`) and never copy the token into the project. The agent then calls `webfront.start` with `create`, `preview` (after each edit, in place of `wf dev`), `check`, `test` or `embed`, and reads each run with `webfront.result`.

In a project that embeds WebFront, `webfront_write_agent_guide()` writes these rules as `AGENTS.md` at its root, and `wf create` writes them beside the starter's sources.

## From C++ to a reactive UI
Expand Down Expand Up @@ -386,7 +385,7 @@ Your own application can select `webfront::NativeApp` or `webfront::NativeAppWit
Your coding agent can type-check, build, preview, inspect and click the interface of **your own application**, in its own
window and with its own C++ callbacks, while you keep the window and decide what the agent may do. Nothing is on by default.

<img src="docs/images/automation-agent.svg" width="100%" alt="Animated transcript. On the left, an agent lists the shared session, checks, builds and previews the interface, clicks a button, calls the allow-listed C++ callback bf.render and is refused bf.secret. On the right, the application window shows the interface updating, and the C++ process logs only the callbacks that ran.">
<img src="docs/images/automation-agent.svg" width="100%" alt="Animated transcript. On the left, an agent connects to the application's MCP URL, checks, builds and previews the interface, clicks a button, calls the allow-listed C++ callback bf.render and is refused bf.secret. On the right, the application window shows the interface updating, and the C++ process logs only the callbacks that ran.">

*Abridged transcript of the `AutomationConsumerWindow` regression test, which runs these steps against a real application.*

Expand All @@ -400,17 +399,16 @@ app.bootstrap("developer");
app.cppFunction("bf.render", render); // your callbacks stay yours
auto automation = webfront::automation::enableAutomation(
app, {.grants = {"check", "build", "preview", "inspect", "interact", "call"},
.callbacks = {"bf.render"}, // the only callback an agent may call
.listen = privateEndpointDirectory});
.callbacks = {"bf.render"}}); // the only callback an agent may call
app.show(automation->launchPage());
automation->close();
app.shutdown();
```

- **Visible to you.** The window's terminal prints the grants and how to attach, `wf help` says so, and the window title can carry a marker.
- **Found without being told.** `webfront-agent --list` shows the sessions their owners shared (never the capability), and `webfront-agent --print-mcp-config --attach <dir>` writes the `.mcp.json` for Claude Code or any MCP client. `wf create` adds an `AGENTS.md` that tells the agent how to attach.
- **Visible to you.** The application prints its MCP URL, the window's terminal prints the grants, `wf help` says so, and the window title can carry a marker.
- **Found without being told.** Each running instance writes its URL and the path of its private `mcp.json` (URL and token) to a per-user record, never the token itself; `claude --mcp-config PATH/mcp.json` or any MCP client connects to it. `wf create` adds an `AGENTS.md` that tells the agent how to connect.
- **Bounded.** Each operation is a separate grant; a callback is reachable only by an exact name you listed; a stuck renderer is stopped by native deadlines; project code still runs with your rights (this is not a sandbox).
- **Optional.** It lives in a separate launcher and one header; applications that do not call `enableAutomation` register nothing. `webfront_add_agent()` builds and installs the launcher for `add_subdirectory` and `FetchContent` consumers.
- **Optional.** It lives in one header; applications that do not call `enableAutomation` register nothing and open no listener, and a distribution build (`WEBFRONT_DISTRIBUTION`) refuses to compile it.

The [automation guide](docs/AUTOMATION.md#automating-your-own-application) covers grants, callbacks, discovery, deadlines and the MCP profile.

Expand Down
36 changes: 0 additions & 36 deletions cmake/WebFrontAgent.cmake

This file was deleted.

16 changes: 5 additions & 11 deletions cmake/WebFrontAgentGuide.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ include_guard(GLOBAL)
#
# Writes the agent guide of a WebFront application (the same text `wf create` puts beside a starter's sources) as
# AGENTS.md at the root of the calling project: the model (C++ with a TypeScript/TSX interface in ui/, developed with
# `wf dev`) and how an agent runs wf itself in JSON or MCP. Coding agents read that file before anything else.
# `wf dev`) and how an agent runs wf itself through the MCP URL of the application. Coding agents read that file first.
#
# add_subdirectory(WebFront) # or FetchContent / CPM
# webfront_write_agent_guide() # <project>/AGENTS.md, once
Expand Down Expand Up @@ -47,8 +47,8 @@ function(webfront_write_agent_guide)
message(STATUS "WebFront: wrote the agent guide ${destination}")
endfunction()

# One notice per configuration, for whoever reads the configure output first: the development model, the guide, and
# either how to attach to the launcher that is built or the option that builds it.
# One notice per configuration, for whoever reads the configure output first: the development model, the guide, and how an
# application serves MCP to an agent.
function(webfront_announce_agent_support)
get_property(announced GLOBAL PROPERTY WEBFRONT_AGENT_SUPPORT_ANNOUNCED)
if(announced)
Expand All @@ -57,14 +57,8 @@ function(webfront_announce_agent_support)
set_property(GLOBAL PROPERTY WEBFRONT_AGENT_SUPPORT_ANNOUNCED ON)
set(guide "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/../docs/DEVELOPING_WITH_AGENTS.md")
cmake_path(NORMAL_PATH guide)
if(TARGET webfront-agent)
set(launcher "the webfront-agent target runs wf for an agent in JSON or MCP (webfront-agent --agent-help)")
else()
set(launcher "webfront-agent, which runs wf for an agent in JSON or MCP, is not built: "
"configure with -DWEBFRONT_BUILD_AUTOMATION=ON")
string(JOIN "" launcher ${launcher})
endif()
message(STATUS "WebFront for agents: an application is C++ with a TypeScript/TSX interface in ui/, developed with `wf dev` "
"(not pages served from documentRoot); ${launcher}. Guide: ${guide}"
"(not pages served from documentRoot); an application that calls webfront::automation::enableAutomation serves MCP "
"itself and prints its URL. Guide: ${guide}"
"; webfront_write_agent_guide() writes it as AGENTS.md in your project.")
endfunction()
Loading
Loading