From 645fce138bbc4a7f40984a47bedf59a0283f0ddd Mon Sep 17 00:00:00 2001 From: Ambroise Leclerc <6860842+ambroise-leclerc@users.noreply.github.com> Date: Sun, 1 Nov 2026 17:13:01 +0100 Subject: [PATCH 1/4] Add init, create, install, restore and embed to the automation contract (#466) --- docs/AUTOMATION.md | 19 +++++--- docs/CHANGELOG.md | 4 ++ ...9-developpement-automatisable-et-agents.md | 5 ++- include/webfront/automation/Contract.hpp | 17 +++++-- include/webfront/automation/Instructions.hpp | 1 + include/webfront/automation/Session.hpp | 12 +++++ js/developer/environment/automation.mjs | 12 +++-- test/developer/specs/automation-specs.mjs | 16 +++++++ test/unit/AutomationTests.cpp | 44 +++++++++++++++++++ 9 files changed, 118 insertions(+), 12 deletions(-) diff --git a/docs/AUTOMATION.md b/docs/AUTOMATION.md index 06ffcc90..08ba0dba 100644 --- a/docs/AUTOMATION.md +++ b/docs/AUTOMATION.md @@ -41,8 +41,7 @@ build-agent/test/web/webfront-wf --project "$PWD" --manifest-dir js/developer -- ``` `build-distribution/provision.json` gives the resulting integrity. Project packages must also be -installed/restored beforehand through wf. Package installation and network restoration are not -agent tools. Tests use configure-provisioned packages and a local registry, with no public network +installed/restored beforehand through wf, or by an agent granted `install`/`restore`. Tests use configure-provisioned packages and a local registry, with no public network after provisioning. This source build does not publish a release or change the pinned bootstrap. ## Invocation and authority @@ -62,11 +61,14 @@ webfront-agent --project /absolute/project \ ``` All executable operations are denied unless granted by the process owner using `--allow`. -Valid grants are `check`, `build`, `test`, `preview`, `inspect` and `interact` (click/fill). +Valid grants are `check`, `build`, `test`, `preview`, `inspect`, `interact` (click/fill) and the project setup +grants `init`, `create`, `install`, `restore` and `embed`. The setup grants write the manifest, the lock, the cache, a new +starter directory or the generated provider header; grant them only for a project whose registry you trust. The project, environment, manifest directory and grants cannot be changed by MCP or the manifest. Omit grants to expose session discovery only. In particular, there is no agent tool for shell, -JavaScript evaluation, arbitrary callback calls, `wf run`, `exec`, install, restore or arbitrary -native file reads/writes. An agent edits project files through its separately authorized workspace +JavaScript evaluation, arbitrary callback calls, `wf run`, `exec` or arbitrary +native file reads/writes. `install` and `restore` use the registry already configured by the owner, the manifest or the +default; the operation cannot choose another one. An agent edits project files through its separately authorized workspace tools, then asks WebFront to verify them. `--manifest-dir` selects a project-relative manifest directory. `--registry-dir` serves an @@ -183,9 +185,16 @@ Operations and their arguments: | `build`, `preview` | `{entry?}` | Operation's own grant | | `test` | `{pattern?}` | `test` | | `inspect` | `{}` | `inspect` | +| `init` | `{name?}` | `init` | +| `create` | `{starter, directory?}` | `create` | +| `install` | `{package?}` (one `name[@range]`; none installs the locked graph) | `install` | +| `restore` | `{}` | `restore` | +| `embed` | `{provider}` or `{entry, output}` | `embed` | | `click` | `{pageId, elementId}` | `interact` | | `fill` | `{pageId, elementId, value}` | `interact` | +`name`, `starter`, `package` and `provider` refuse a leading `-`, a backslash and spaces; `directory` and `output` must be +new project-relative paths. `embed` needs a provider, or an entry together with an output, never both. Unknown arguments, wrong sessions, unsupported commands and option-like entry/pattern strings are refused natively. Entries accept manifest labels (including `app:debug` and `app..debug`); entry paths must be project-relative. A queued/running operation blocks diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index bae7bb40..388631d8 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +- Automation can set a project up end to end (#466): `init`, `create`, `install`, `restore` and `embed` join the contract of + `webfront-agent`, each behind its own `--allow` grant and with plain-name or project-relative arguments (no options, no + traversal). `install` takes one package from the configured registry or installs the locked graph; `embed` takes a manifest + provider, or an entry with an output header. See `docs/AUTOMATION.md`. - Declare the embedded engine without consumer-side macros (#467): `webfront::embeddedFrontendAvailable` (`constexpr bool`, true when a native web view or CEF is compiled in) and `webfront::EmbeddedWebFront` (the application type with the native web view, or with CEF when only CEF is built) exist in every configuration; constructing `EmbeddedWebFront` throws diff --git a/docs/adr/ADR-019-developpement-automatisable-et-agents.md b/docs/adr/ADR-019-developpement-automatisable-et-agents.md index cd743c3f..43fcaf59 100644 --- a/docs/adr/ADR-019-developpement-automatisable-et-agents.md +++ b/docs/adr/ADR-019-developpement-automatisable-et-agents.md @@ -78,7 +78,10 @@ longue rend un runId consultable ; le chemin `connectAutomation` borne les sorti les coupures par `truncated`, alors que `runNonInteractive` conserve par défaut sa sortie complète. L'annulation est coopérative, ne revient pas sur une publication commise et ne garantit pas d'arrêter le JavaScript déjà lancé. Un résultat perdu après une mutation est signalé comme incertain, jamais rejoué automatiquement. -Installation/restauration réseau, wf run/exec et callbacks C++ arbitraires ne sont pas des outils MCP. +wf run/exec et callbacks C++ arbitraires ne sont pas des outils MCP. Amendement (#466) : `init`, `create`, `install`, +`restore` et `embed` sont des opérations du contrat, chacune sous sa propre permission explicite du propriétaire ; +`install`/`restore` n'utilisent que le registre déjà configuré (jamais choisi par l'agent) et les arguments restent +des noms simples ou des chemins relatifs au projet. ### CLI et MCP local stdio diff --git a/include/webfront/automation/Contract.hpp b/include/webfront/automation/Contract.hpp index f97cfe06..d1f1cc1f 100644 --- a/include/webfront/automation/Contract.hpp +++ b/include/webfront/automation/Contract.hpp @@ -10,13 +10,19 @@ inline constexpr std::string_view contractSource = R"JSON({ "type":"object","additionalProperties":false,"required":["session","operation"], "properties":{ "session":{"type":"string","minLength":1}, - "operation":{"type":"string","enum":["check","build","test","preview","inspect","click","fill"]}, + "operation":{"type":"string","enum":["check","build","test","preview","inspect","click","fill","init","create","install","restore","embed"]}, "arguments":{"type":"object","additionalProperties":false,"properties":{ "entry":{"type":"string","maxLength":4096,"description":"Project-relative path or manifest entry; no leading option or path traversal."}, "pattern":{"type":"string","maxLength":4096,"description":"Spec name substring, never a command option."}, "pageId":{"type":"string","minLength":1,"maxLength":4096}, "elementId":{"type":"string","minLength":1,"maxLength":4096}, - "value":{"type":"string","maxLength":4096} + "value":{"type":"string","maxLength":4096}, + "name":{"type":"string","maxLength":4096,"description":"Project name written by init; never a command option."}, + "starter":{"type":"string","maxLength":4096,"description":"Starter name for create, never a command option."}, + "directory":{"type":"string","maxLength":4096,"description":"New project-relative directory for create."}, + "package":{"type":"string","maxLength":4096,"description":"One package name with optional range for install, from the configured registry; omit to install the locked graph."}, + "provider":{"type":"string","maxLength":4096,"description":"Manifest provider label for embed."}, + "output":{"type":"string","maxLength":4096,"description":"Project-relative provider header for embed with an entry."} }} }, "$defs":{ @@ -37,7 +43,12 @@ inline constexpr std::string_view contractSource = R"JSON({ "preview":{"permission":"preview","arguments":["entry"],"required":[]}, "inspect":{"permission":"inspect","arguments":[],"required":[]}, "click":{"permission":"interact","arguments":["pageId","elementId"],"required":["pageId","elementId"]}, - "fill":{"permission":"interact","arguments":["pageId","elementId","value"],"required":["pageId","elementId","value"]} + "fill":{"permission":"interact","arguments":["pageId","elementId","value"],"required":["pageId","elementId","value"]}, + "init":{"permission":"init","arguments":["name"],"required":[]}, + "create":{"permission":"create","arguments":["starter","directory"],"required":["starter"]}, + "install":{"permission":"install","arguments":["package"],"required":[]}, + "restore":{"permission":"restore","arguments":[],"required":[]}, + "embed":{"permission":"embed","arguments":["provider","entry","output"],"required":[]} } })JSON"; diff --git a/include/webfront/automation/Instructions.hpp b/include/webfront/automation/Instructions.hpp index 41205219..d70aaad4 100644 --- a/include/webfront/automation/Instructions.hpp +++ b/include/webfront/automation/Instructions.hpp @@ -7,6 +7,7 @@ inline constexpr std::string_view agentInstructions = R"(WebFront developer auto 2. Ask the owner to launch a developer window with --serve --listen DIRECTORY and explicit --allow grants. Attach only to the exact directory supplied by the owner; never discover or read unrelated endpoints. 3. Run `webfront-agent --attach DIRECTORY --operation check` or build/test/preview as authorized. + Setup operations init, create, install, restore and embed need their own grants and plain arguments. Add --entry or --pattern only for the operation that accepts it. No shell string is interpreted. Attached responses have a 30-second budget; --request-timeout SECONDS changes it (1..3600). 4. Read JSON state and result.exitCode. A failed operation is not a successful verification. diff --git a/include/webfront/automation/Session.hpp b/include/webfront/automation/Session.hpp index 2b1d6045..785fda4e 100644 --- a/include/webfront/automation/Session.hpp +++ b/include/webfront/automation/Session.hpp @@ -262,6 +262,18 @@ class Session { fs::safeRelativePath(value); if (key == "pattern" && value.starts_with('-')) throw std::invalid_argument("Pattern must not be an option"); + if ((key == "name" || key == "starter" || key == "package" || key == "provider") + && (value.starts_with('-') || value.contains('\\') || value.contains(' '))) + throw std::invalid_argument("Argument must be a plain name, not an option or a path"); + if ((key == "directory" || key == "output") && (value.empty() || value.starts_with('-') || value.contains('\\') || value.starts_with('/'))) + throw std::invalid_argument("Argument must be a project-relative path"); + if (key == "directory" || key == "output") + fs::safeRelativePath(value); + } + if (operation == "embed") { + const bool provider = args.has("provider"), entry = args.has("entry"), output = args.has("output"); + if (provider == entry || entry != output) + throw std::invalid_argument("embed needs either provider, or entry together with output"); } } Run& find(std::string_view id) { diff --git a/js/developer/environment/automation.mjs b/js/developer/environment/automation.mjs index 5bcc1c49..a031d98a 100644 --- a/js/developer/environment/automation.mjs +++ b/js/developer/environment/automation.mjs @@ -175,10 +175,16 @@ export function createAutomationRunner({run, exclusive, context, inspector, onSt result = await exclusive(context, async () => ({exitCode:0, output:'', report:null, data:request.operation === 'inspect' ? inspector.inspect() : inspector.action(request.operation,args)})); } else { - if (!['check','build','test','preview'].includes(request.operation)) throw new Error('Unknown automation operation'); + if (!['check','build','test','preview','init','create','install','restore','embed'].includes(request.operation)) throw new Error('Unknown automation operation'); const argv = [request.operation]; - if (args.entry) argv.push(args.entry); - if (args.pattern) argv.push(args.pattern); + if (request.operation === 'embed') { + if (args.provider) argv.push(args.provider); + else if (args.entry && args.output) argv.push(args.entry, '--output', args.output); + else throw new Error('embed needs either provider, or entry together with output'); + } else { + for (const key of ['name','starter','directory','package','entry','pattern']) + if (args[key]) argv.push(args[key]); + } result = await run(argv, {...context, signal:controller.signal, onExit:() => {}, outputLimit:16000, write:text => { output = clip(output + text); }, reporter:undefined}); // A command that stopped because of the cancellation reports it, whatever code it chose. diff --git a/test/developer/specs/automation-specs.mjs b/test/developer/specs/automation-specs.mjs index 108b329e..1ba770a8 100644 --- a/test/developer/specs/automation-specs.mjs +++ b/test/developer/specs/automation-specs.mjs @@ -39,6 +39,22 @@ describe('Developer automation', () => { expect(completed[1].result.exitCode).toBe(1); }); + it('maps project setup operations to wf argument lists and refuses an incomplete embed', async () => { + const argvs=[], completed=[]; + const runner=createAutomationRunner({context:{},exclusive,inspector:{}, + run:async argv => {argvs.push(argv); return {exitCode:0,output:'',report:null};}, + complete:async (_id,result) => {completed.push(result);}}); + await runner.start({runId:'a',operation:'create',arguments:{starter:'life',directory:'ui'}}); + await runner.start({runId:'b',operation:'install',arguments:{package:'react@19.3.1'}}); + await runner.start({runId:'c',operation:'restore',arguments:{}}); + await runner.start({runId:'d',operation:'embed',arguments:{provider:'LifeUI'}}); + await runner.start({runId:'e',operation:'embed',arguments:{entry:'ui/main.tsx',output:'generated/LifeUI.hpp'}}); + await runner.start({runId:'f',operation:'embed',arguments:{entry:'ui/main.tsx'}}); + expect(argvs).toEqual([['create','life','ui'],['install','react@19.3.1'],['restore'],['embed','LifeUI'], + ['embed','ui/main.tsx','--output','generated/LifeUI.hpp']]); + expect(completed[5].exitCode).toBe(1); + }); + it('does not turn a script exit 130 into a cancellation', async () => { let completed; const runner=createAutomationRunner({context:{},exclusive,inspector:{}, diff --git a/test/unit/AutomationTests.cpp b/test/unit/AutomationTests.cpp index 53557ede..3fa9fa0b 100644 --- a/test/unit/AutomationTests.cpp +++ b/test/unit/AutomationTests.cpp @@ -231,6 +231,50 @@ SCENARIO("Automation entries accept manifest labels while refusing unsafe paths" } } +SCENARIO("Project setup operations need their own grants and plain arguments") { + webfront::test::TemporaryDirectory directory; + Session denied{ + {directory.path(), {"build"}} + }; + Session session{ + {directory.path(), {"init", "create", "install", "restore", "embed"}} + }; + denied.poll(); + session.poll(); + const auto accepted = [&](const char* operation, const char* arguments) { + const auto id = Object(session.start(command(session, operation, arguments))).string("runId"); + session.poll(); + session.complete(id, R"({"exitCode":0,"output":"","report":null})"); + }; + GIVEN("a session without those grants") { + for (const auto operation : {"init", "create", "install", "restore", "embed"}) + REQUIRE_THROWS(denied.start(command(denied, operation, operation == std::string_view("create") ? R"({"starter":"life"})" : "{}"))); + } + GIVEN("granted operations with valid arguments") { + accepted("init", R"({"name":"demo"})"); + accepted("create", R"({"starter":"life","directory":"ui"})"); + accepted("install", "{}"); + accepted("install", R"({"package":"react@19.3.1"})"); + accepted("restore", "{}"); + accepted("embed", R"({"provider":"LifeUI"})"); + accepted("embed", R"({"entry":"ui/main.tsx","output":"generated/LifeUI.hpp"})"); + } + GIVEN("options, escapes and incomplete requests") { + REQUIRE_THROWS(session.start(command(session, "create", "{}"))); + REQUIRE_THROWS(session.start(command(session, "create", R"({"starter":"--help"})"))); + REQUIRE_THROWS(session.start(command(session, "create", R"({"starter":"life","directory":"../escape"})"))); + REQUIRE_THROWS(session.start(command(session, "create", R"({"starter":"life","directory":"/absolute"})"))); + REQUIRE_THROWS(session.start(command(session, "install", R"({"package":"--update"})"))); + REQUIRE_THROWS(session.start(command(session, "install", R"({"package":"a b"})"))); + REQUIRE_THROWS(session.start(command(session, "init", R"({"name":"-x"})"))); + REQUIRE_THROWS(session.start(command(session, "restore", R"({"offline":"true"})"))); + REQUIRE_THROWS(session.start(command(session, "embed", "{}"))); + REQUIRE_THROWS(session.start(command(session, "embed", R"({"entry":"ui/main.tsx"})"))); + REQUIRE_THROWS(session.start(command(session, "embed", R"({"provider":"LifeUI","output":"a.hpp"})"))); + REQUIRE_THROWS(session.start(command(session, "embed", R"({"entry":"ui/main.tsx","output":"../a.hpp"})"))); + } +} + SCENARIO("Authorization precedes operation and argument validation") { webfront::test::TemporaryDirectory directory; Session session{ From 840a5517d65bdf3359ac266f5b29a7b15aaf9585 Mon Sep 17 00:00:00 2001 From: Ambroise Leclerc <6860842+ambroise-leclerc@users.noreply.github.com> Date: Sun, 1 Nov 2026 17:18:31 +0100 Subject: [PATCH 2/4] Advance the developer environment sources to 0.6.4 and refresh the bundle checksums (#466) The runner change alters the environment archive and 0.6.3 is published. The release pin stays on 0.6.3. --- docs/CHANGELOG.md | 3 ++- docs/DEVELOPER_ENVIRONMENT.md | 3 ++- js/developer/environment/bundles.json | 4 ++-- js/developer/tools/distribution.json | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 388631d8..1007daad 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -5,7 +5,8 @@ - Automation can set a project up end to end (#466): `init`, `create`, `install`, `restore` and `embed` join the contract of `webfront-agent`, each behind its own `--allow` grant and with plain-name or project-relative arguments (no options, no traversal). `install` takes one package from the configured registry or installs the locked graph; `embed` takes a manifest - provider, or an entry with an output header. See `docs/AUTOMATION.md`. + provider, or an entry with an output header. See `docs/AUTOMATION.md`. The environment sources advance to 0.6.4 (unpublished, + the pin stays on 0.6.3). - Declare the embedded engine without consumer-side macros (#467): `webfront::embeddedFrontendAvailable` (`constexpr bool`, true when a native web view or CEF is compiled in) and `webfront::EmbeddedWebFront` (the application type with the native web view, or with CEF when only CEF is built) exist in every configuration; constructing `EmbeddedWebFront` throws diff --git a/docs/DEVELOPER_ENVIRONMENT.md b/docs/DEVELOPER_ENVIRONMENT.md index 11529247..472be154 100644 --- a/docs/DEVELOPER_ENVIRONMENT.md +++ b/docs/DEVELOPER_ENVIRONMENT.md @@ -34,7 +34,8 @@ installed or required (see [Type checking](#type-checking-wf-check)). The generated `DeveloperReleaseData.hpp` selects the default environment and its integrity. Published versions stay immutable. Environment **0.6.3** adds automation API v1 and the shared human/agent execution -lease; version 0.6.2 predates that API. Publication and pin changes follow +lease; version 0.6.2 predates that API. The sources advance to 0.6.4 (project setup operations in the automation +runner), which is not published yet; the release pin stays on the published 0.6.3. Publication and pin changes follow [PUBLISHING](../js/developer/tools/PUBLISHING.md), with deployment verified before merging a new pin. ## Minimal C++ application diff --git a/js/developer/environment/bundles.json b/js/developer/environment/bundles.json index 146b2d35..81ead40b 100644 --- a/js/developer/environment/bundles.json +++ b/js/developer/environment/bundles.json @@ -18,7 +18,7 @@ "js/developer/environment/starter.mjs": "89ccab43be4455ed9598c54355b4bbe5adea1afd7a0ae5d755a14317e3ca39df", "js/developer/environment/paths.mjs": "3b6114df78eb193161c5c84499dda084cb7ff91c56a4496371c30295d00880e3", "js/developer/environment/runtime.mjs": "0acfdf8da60496403203cba5a3a019f2334eed774bb75e216424440ec65e8ee7", - "js/developer/environment/automation.mjs": "937bf263902f51bd24854b8758fea92454f1c19bb839dfac172dce877fe1aa8e", + "js/developer/environment/automation.mjs": "25d37fc9715445f3f96a6b2aaff72a36efee0c8b10dea6dcf326719c22f1a576", "js/developer/environment/development.mjs": "1125043016727111031a452fbebec358b9e78231f82fe91df7dea0fe8b22f015", "js/developer/environment/testing.mjs": "326e003f114bdbad68fedbceaded30717b3fc15315e6d87fa747972b681e2dce", "js/developer/environment/terminal.mjs": "7ffcf7ac6ef63c35cdf5ef70284b384525b13ba18422af069289e53b6c4f6be1", @@ -39,7 +39,7 @@ "js/developer/environment/embed.mjs": "3e6bc10200939fa30d5f60a96f01eb33ddf3da87661390ad433a18366bf52547", "examples/life/ui/main.tsx": "7b1ff285d2a6b8f897ef12df872886e61ef4b24e2358a9423b76b38ab75c85d3", "examples/life/ui/style.css": "9bb55eb0f0a3287e5b7dc78af9d69608b87ff42c4d9c8a653bc83a52fe293c44", - "js/developer/tools/distribution.json": "7029cf3e2e64e5ea44b595fddcc0151fca4cc210d2ef1258cee7bb8d75e7cd2f", + "js/developer/tools/distribution.json": "35b7806b2d47841f7e01715b9338fb0a55c164fec77260d2267c7d433073354b", "js/developer/tools/archive.mjs": "da63bb9d796ddfd24ed945b15c53f66a0400eb177886fd4f1c8fd10cafb5a91b", "js/developer/tools/distribution.mjs": "1108b61bc659dd945ba1417aa84337bca03039842d342c95815b5463d87a136e", "js/developer/scripts/build.mjs": "7aa0358dbd8555ab83bf0380f67892e96b7e9806d4968de18e1a8eaf6e91c080", diff --git a/js/developer/tools/distribution.json b/js/developer/tools/distribution.json index 48ac84ab..e19c7bee 100644 --- a/js/developer/tools/distribution.json +++ b/js/developer/tools/distribution.json @@ -1,4 +1,4 @@ { - "version": "0.6.3", + "version": "0.6.4", "baseUrl": "https://ambroise-leclerc.github.io/WebFront/" } From 7a631c02aa6505e7245d0d4beb70824e5d52ee75 Mon Sep 17 00:00:00 2001 From: Ambroise Leclerc <6860842+ambroise-leclerc@users.noreply.github.com> Date: Sun, 1 Nov 2026 17:23:01 +0100 Subject: [PATCH 3/4] Refuse setup grants on environments older than 0.6.4 and document embed replacement (#466) --- docs/AUTOMATION.md | 7 +++++-- docs/CHANGELOG.md | 3 ++- include/webfront/automation/Binding.hpp | 12 ++++++++++-- include/webfront/automation/Contract.hpp | 17 +++++++++-------- include/webfront/automation/Session.hpp | 9 +++++++++ js/developer/environment/bundles.json | 2 +- js/developer/environment/runtime.mjs | 2 ++ test/unit/AutomationTests.cpp | 8 ++++++++ 8 files changed, 46 insertions(+), 14 deletions(-) diff --git a/docs/AUTOMATION.md b/docs/AUTOMATION.md index 08ba0dba..f455d3c6 100644 --- a/docs/AUTOMATION.md +++ b/docs/AUTOMATION.md @@ -30,7 +30,9 @@ test configurations also build the launcher for their regression tests. Without embedded engine, requesting the launcher fails configure instead of opening a system browser. The implementation is native C++23; no Node.js, npm or Python is required to run the launcher. -Provision an environment containing automation API v1 (0.6.3 or later). Environment 0.6.2 +Provision an environment containing automation API v1 (0.6.3 or later). The setup operations (`init`, `create`, `install`, +`restore`, `embed`) need environment **0.6.4 or later**: the launcher checks this at startup, and granting one of them to an +older environment fails with a bootstrap error (status 70) naming the operation, instead of failing each run. Environment 0.6.2 predates that API; passing an older environment produces a bootstrap error with status 70. The launcher takes an explicit archive and its independently trusted SHA-512 SRI. Use a verified published distribution or build one in this repository: @@ -194,7 +196,8 @@ Operations and their arguments: | `fill` | `{pageId, elementId, value}` | `interact` | `name`, `starter`, `package` and `provider` refuse a leading `-`, a backslash and spaces; `directory` and `output` must be -new project-relative paths. `embed` needs a provider, or an entry together with an output, never both. +project-relative paths: `create` never replaces an existing directory (`wf` refuses it), while `embed` **replaces** its output header, as +regeneration requires. `embed` needs a provider, or an entry together with an output, never both. Unknown arguments, wrong sessions, unsupported commands and option-like entry/pattern strings are refused natively. Entries accept manifest labels (including `app:debug` and `app..debug`); entry paths must be project-relative. A queued/running operation blocks diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 1007daad..b05e21d8 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -6,7 +6,8 @@ `webfront-agent`, each behind its own `--allow` grant and with plain-name or project-relative arguments (no options, no traversal). `install` takes one package from the configured registry or installs the locked graph; `embed` takes a manifest provider, or an entry with an output header. See `docs/AUTOMATION.md`. The environment sources advance to 0.6.4 (unpublished, - the pin stays on 0.6.3). + the pin stays on 0.6.3). Granting one of these operations to an older environment now fails at startup with a bootstrap error naming + the operation, and `embed` is documented as replacing its output header. - Declare the embedded engine without consumer-side macros (#467): `webfront::embeddedFrontendAvailable` (`constexpr bool`, true when a native web view or CEF is compiled in) and `webfront::EmbeddedWebFront` (the application type with the native web view, or with CEF when only CEF is built) exist in every configuration; constructing `EmbeddedWebFront` throws diff --git a/include/webfront/automation/Binding.hpp b/include/webfront/automation/Binding.hpp index ec643735..862385c8 100644 --- a/include/webfront/automation/Binding.hpp +++ b/include/webfront/automation/Binding.hpp @@ -64,6 +64,9 @@ void (async () => { const environment = await response.json(); const runtime = await import('/webfront/developer/environment/'+environment.entry); if (typeof runtime.connectAutomation !== 'function') throw new Error('This environment has no automation API v1; provision an updated environment'); + const supported = Array.isArray(runtime.automationOperations) ? runtime.automationOperations : []; + for (const [operation, since] of __VERSIONED__) + if (!supported.includes(operation)) throw new Error('This environment cannot run granted operation '+operation+'; provision environment '+since+' or later'); runtime.connectAutomation({bridge:webFront,call,config,preview:document.getElementById('preview')}); } catch (error) { await call('failed',failureText(error?.message ?? error)).catch(() => {}); @@ -72,8 +75,13 @@ void (async () => { })(); )JS"; -inline std::string connectionScript(std::string_view capability) { +inline std::string connectionScript(std::string_view capability, const std::vector>& versioned = {}) { std::string script{connectionScriptTemplate}; + std::string list = "["; + for (const auto& [operation, since] : versioned) + list += (list.size() > 1 ? "," : "") + std::string("[") + json::quote(operation) + "," + json::quote(since) + "]"; + list += "]"; + script.replace(script.find("__VERSIONED__"), std::string_view("__VERSIONED__").size(), list); script.replace(script.find("__CAPABILITY__"), std::string_view("__CAPABILITY__").size(), capability); return script; } @@ -114,7 +122,7 @@ class Binding { throw std::runtime_error("Automation window claim rejected"); owned->browser = ui; owned->launchToken.clear(); // one successful claim; later connections cannot replace the selected browser - ui.addScript(owned->closing ? std::string{"window.close()"} : connectionScript(owned->pageAuthentication.secret())); + ui.addScript(owned->closing ? std::string{"window.close()"} : connectionScript(owned->pageAuthentication.secret(), owned->session->versionedOperations())); return std::string{"null"}; }); app.cppFunction("webfront.automation.poll", [owned](AppUI ui, std::string sequence, std::string mac, std::string output) { diff --git a/include/webfront/automation/Contract.hpp b/include/webfront/automation/Contract.hpp index d1f1cc1f..ddce760a 100644 --- a/include/webfront/automation/Contract.hpp +++ b/include/webfront/automation/Contract.hpp @@ -19,10 +19,10 @@ inline constexpr std::string_view contractSource = R"JSON({ "value":{"type":"string","maxLength":4096}, "name":{"type":"string","maxLength":4096,"description":"Project name written by init; never a command option."}, "starter":{"type":"string","maxLength":4096,"description":"Starter name for create, never a command option."}, - "directory":{"type":"string","maxLength":4096,"description":"New project-relative directory for create."}, + "directory":{"type":"string","maxLength":4096,"description":"Project-relative directory for create; wf refuses an existing one."}, "package":{"type":"string","maxLength":4096,"description":"One package name with optional range for install, from the configured registry; omit to install the locked graph."}, "provider":{"type":"string","maxLength":4096,"description":"Manifest provider label for embed."}, - "output":{"type":"string","maxLength":4096,"description":"Project-relative provider header for embed with an entry."} + "output":{"type":"string","maxLength":4096,"description":"Project-relative provider header for embed with an entry; an existing file is replaced."} }} }, "$defs":{ @@ -44,11 +44,11 @@ inline constexpr std::string_view contractSource = R"JSON({ "inspect":{"permission":"inspect","arguments":[],"required":[]}, "click":{"permission":"interact","arguments":["pageId","elementId"],"required":["pageId","elementId"]}, "fill":{"permission":"interact","arguments":["pageId","elementId","value"],"required":["pageId","elementId","value"]}, - "init":{"permission":"init","arguments":["name"],"required":[]}, - "create":{"permission":"create","arguments":["starter","directory"],"required":["starter"]}, - "install":{"permission":"install","arguments":["package"],"required":[]}, - "restore":{"permission":"restore","arguments":[],"required":[]}, - "embed":{"permission":"embed","arguments":["provider","entry","output"],"required":[]} + "init":{"permission":"init","since":"0.6.4","arguments":["name"],"required":[]}, + "create":{"permission":"create","since":"0.6.4","arguments":["starter","directory"],"required":["starter"]}, + "install":{"permission":"install","since":"0.6.4","arguments":["package"],"required":[]}, + "restore":{"permission":"restore","since":"0.6.4","arguments":[],"required":[]}, + "embed":{"permission":"embed","since":"0.6.4","arguments":["provider","entry","output"],"required":[]} } })JSON"; @@ -83,6 +83,7 @@ struct OperationDefinition { Object schema; std::string permission; std::vector arguments, required; + std::string since; ///< First environment version that runs the operation; empty when every automation environment does. }; inline const auto& operationDefinitions() { static const auto definitions = [] { @@ -92,7 +93,7 @@ inline const auto& operationDefinitions() { const Object schema{raw}; values.emplace( name, - OperationDefinition{schema, schema.string("permission"), contractStrings(schema.raw("arguments")), contractStrings(schema.raw("required"))}); + OperationDefinition{schema, schema.string("permission"), contractStrings(schema.raw("arguments")), contractStrings(schema.raw("required")), schema.string("since")}); } return values; }(); diff --git a/include/webfront/automation/Session.hpp b/include/webfront/automation/Session.hpp index 785fda4e..5fc9e5ca 100644 --- a/include/webfront/automation/Session.hpp +++ b/include/webfront/automation/Session.hpp @@ -36,6 +36,15 @@ class Session { identity = channel::nonce(); } + /// Granted operations that only newer environments implement, with the first version that does. + std::vector> versionedOperations() const { + std::vector> result; + for (const auto& [name, definition] : operationDefinitions()) + if (!definition.since.empty() && std::ranges::find(options.allow, definition.permission) != options.allow.end()) + result.emplace_back(name, definition.since); + return result; + } + std::string describe() const { std::scoped_lock lock{mutex}; return "{\"version\":1,\"session\":" + json::quote(identity) + ",\"project\":" + json::quote(options.project.generic_string()) + ",\"state\":" diff --git a/js/developer/environment/bundles.json b/js/developer/environment/bundles.json index 81ead40b..a05619b0 100644 --- a/js/developer/environment/bundles.json +++ b/js/developer/environment/bundles.json @@ -17,7 +17,7 @@ "js/developer/environment/packages.mjs": "37fe2a410e211264cfeaedbff3df50f7e62b02f8088130127d94f92081e2a5ad", "js/developer/environment/starter.mjs": "89ccab43be4455ed9598c54355b4bbe5adea1afd7a0ae5d755a14317e3ca39df", "js/developer/environment/paths.mjs": "3b6114df78eb193161c5c84499dda084cb7ff91c56a4496371c30295d00880e3", - "js/developer/environment/runtime.mjs": "0acfdf8da60496403203cba5a3a019f2334eed774bb75e216424440ec65e8ee7", + "js/developer/environment/runtime.mjs": "e996b0e55798080f17eaf21cab482b1cd72d2fff1b52f4117388bca21111750b", "js/developer/environment/automation.mjs": "25d37fc9715445f3f96a6b2aaff72a36efee0c8b10dea6dcf326719c22f1a576", "js/developer/environment/development.mjs": "1125043016727111031a452fbebec358b9e78231f82fe91df7dea0fe8b22f015", "js/developer/environment/testing.mjs": "326e003f114bdbad68fedbceaded30717b3fc15315e6d87fa747972b681e2dce", diff --git a/js/developer/environment/runtime.mjs b/js/developer/environment/runtime.mjs index d3faf4f3..7be427c5 100644 --- a/js/developer/environment/runtime.mjs +++ b/js/developer/environment/runtime.mjs @@ -313,6 +313,8 @@ export async function execute(args, context) { return exclusive(context, async owned => commands[command](rest, owned),{settlesOnAbort:command==='test'}); } +/** Automation operations this environment runs beyond the 0.6.3 set; the native owner refuses a grant it does not list. */ +export const automationOperations = ['init', 'create', 'install', 'restore', 'embed']; export const connectAutomation = context => connectAgent({...context,run:runNonInteractive,exclusive}); /** diff --git a/test/unit/AutomationTests.cpp b/test/unit/AutomationTests.cpp index 3fa9fa0b..ad4cf95b 100644 --- a/test/unit/AutomationTests.cpp +++ b/test/unit/AutomationTests.cpp @@ -246,6 +246,14 @@ SCENARIO("Project setup operations need their own grants and plain arguments") { session.poll(); session.complete(id, R"({"exitCode":0,"output":"","report":null})"); }; + GIVEN("grants that older environments cannot run") { + REQUIRE(denied.versionedOperations().empty()); + const auto versioned = session.versionedOperations(); + REQUIRE(versioned.size() == 5); + for (const auto& [operation, since] : versioned) + REQUIRE(since == "0.6.4"); + REQUIRE(webfront::automation::connectionScript("secret", versioned).find("[\"embed\",\"0.6.4\"]") != std::string::npos); + } GIVEN("a session without those grants") { for (const auto operation : {"init", "create", "install", "restore", "embed"}) REQUIRE_THROWS(denied.start(command(denied, operation, operation == std::string_view("create") ? R"({"starter":"life"})" : "{}"))); From 4c33e17c876ad01f8a7c9caa46d0aea12c80fc72 Mon Sep 17 00:00:00 2001 From: Ambroise Leclerc <6860842+ambroise-leclerc@users.noreply.github.com> Date: Sun, 1 Nov 2026 17:42:28 +0100 Subject: [PATCH 4/4] Let the automation create operation load the pinned starter and test the setup flow end to end (#466) --- docs/AUTOMATION.md | 5 ++++- docs/CHANGELOG.md | 4 +++- include/webfront/automation/Binding.hpp | 2 +- js/developer/environment/bootstrap.mjs | 2 +- js/developer/environment/bundles.json | 4 ++-- js/developer/environment/runtime.mjs | 5 ++++- js/developer/tools/WebFrontAgent.cpp | 11 ++++++++++ test/tools/AutomationClient.py | 28 +++++++++++++++++++++++++ 8 files changed, 54 insertions(+), 7 deletions(-) diff --git a/docs/AUTOMATION.md b/docs/AUTOMATION.md index f455d3c6..468ab3f3 100644 --- a/docs/AUTOMATION.md +++ b/docs/AUTOMATION.md @@ -32,7 +32,10 @@ The implementation is native C++23; no Node.js, npm or Python is required to run Provision an environment containing automation API v1 (0.6.3 or later). The setup operations (`init`, `create`, `install`, `restore`, `embed`) need environment **0.6.4 or later**: the launcher checks this at startup, and granting one of them to an -older environment fails with a bootstrap error (status 70) naming the operation, instead of failing each run. Environment 0.6.2 +older environment fails with a bootstrap error (status 70) naming the operation, instead of failing each run. +`create` needs the starter archives (`-starter.tgz`, such as `life-starter.tgz` of a distribution build) in the same +directory as the `--environment` archive: the launcher serves only files of that name from there, and the environment's +manifest pins their SHA-512, so the directory is not trusted for content. Environment 0.6.2 predates that API; passing an older environment produces a bootstrap error with status 70. The launcher takes an explicit archive and its independently trusted SHA-512 SRI. Use a verified published distribution or build one in this repository: diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index b05e21d8..e56ba834 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -7,7 +7,9 @@ traversal). `install` takes one package from the configured registry or installs the locked graph; `embed` takes a manifest provider, or an entry with an output header. See `docs/AUTOMATION.md`. The environment sources advance to 0.6.4 (unpublished, the pin stays on 0.6.3). Granting one of these operations to an older environment now fails at startup with a bootstrap error naming - the operation, and `embed` is documented as replacing its output header. + the operation, and `embed` is documented as replacing its output header. `create` now finds the pinned starters (the connection reads them from the + environment manifest) and the launcher serves `-starter.tgz` from beside the environment archive; an end-to-end case + creates, initializes, installs and embeds a project. - Declare the embedded engine without consumer-side macros (#467): `webfront::embeddedFrontendAvailable` (`constexpr bool`, true when a native web view or CEF is compiled in) and `webfront::EmbeddedWebFront` (the application type with the native web view, or with CEF when only CEF is built) exist in every configuration; constructing `EmbeddedWebFront` throws diff --git a/include/webfront/automation/Binding.hpp b/include/webfront/automation/Binding.hpp index 862385c8..3b075ca8 100644 --- a/include/webfront/automation/Binding.hpp +++ b/include/webfront/automation/Binding.hpp @@ -67,7 +67,7 @@ void (async () => { const supported = Array.isArray(runtime.automationOperations) ? runtime.automationOperations : []; for (const [operation, since] of __VERSIONED__) if (!supported.includes(operation)) throw new Error('This environment cannot run granted operation '+operation+'; provision environment '+since+' or later'); - runtime.connectAutomation({bridge:webFront,call,config,preview:document.getElementById('preview')}); + runtime.connectAutomation({bridge:webFront,call,config,environment,preview:document.getElementById('preview')}); } catch (error) { await call('failed',failureText(error?.message ?? error)).catch(() => {}); window.close(); diff --git a/js/developer/environment/bootstrap.mjs b/js/developer/environment/bootstrap.mjs index 3b1f8ee4..8e889cba 100644 --- a/js/developer/environment/bootstrap.mjs +++ b/js/developer/environment/bootstrap.mjs @@ -73,7 +73,7 @@ function validStarter(starter) { return String(starter.integrity).startsWith('sha512-'); } -function pinnedStarters(manifest, environmentUrl) { +export function pinnedStarters(manifest, environmentUrl) { return Object.fromEntries(Object.entries(manifest.starters ?? {}).map(([name, starter]) => { if (!validStarter(starter)) throw new Error('Invalid pinned starter metadata'); return [name, {url: new URL(starter.archive, environmentUrl).href, integrity: starter.integrity}]; diff --git a/js/developer/environment/bundles.json b/js/developer/environment/bundles.json index a05619b0..fb7501ae 100644 --- a/js/developer/environment/bundles.json +++ b/js/developer/environment/bundles.json @@ -12,12 +12,12 @@ "js/developer/environment/typecheck-snapshot.mjs": "e8c3a3c6913f7873396a1ce216d9a203c9745855c33efd93efd5826e183cccce", "js/developer/environment/typecheck-worker.mjs": "9f89315a8f7dcb2a19141c321a79aa47eabefdf60d05c60d39016663f1bafecd", "js/developer/environment/packages-entry.mjs": "e0b4acd4330b8b51eb0e695384c8df2b103a4be4f598ac83277838022f747e30", - "js/developer/environment/bootstrap.mjs": "5fa50cc9264809a6a9eb03564a60fbe3171a3ffcc781d26352ae59e2866a7090", + "js/developer/environment/bootstrap.mjs": "c39265627ba42bf17d810a46e0104f35cb63fda1477a92fe3e83507d638f7343", "js/developer/environment/bootstrap-entry.mjs": "ff8084f23f5acc721f97eb1ed0a454e7bfee1894de17d54f0100fa11f7ef8b77", "js/developer/environment/packages.mjs": "37fe2a410e211264cfeaedbff3df50f7e62b02f8088130127d94f92081e2a5ad", "js/developer/environment/starter.mjs": "89ccab43be4455ed9598c54355b4bbe5adea1afd7a0ae5d755a14317e3ca39df", "js/developer/environment/paths.mjs": "3b6114df78eb193161c5c84499dda084cb7ff91c56a4496371c30295d00880e3", - "js/developer/environment/runtime.mjs": "e996b0e55798080f17eaf21cab482b1cd72d2fff1b52f4117388bca21111750b", + "js/developer/environment/runtime.mjs": "1d381cb9a4344de01bbea1601c0b68fa7b25bd4c59f7e0358f680e39bce2dc9e", "js/developer/environment/automation.mjs": "25d37fc9715445f3f96a6b2aaff72a36efee0c8b10dea6dcf326719c22f1a576", "js/developer/environment/development.mjs": "1125043016727111031a452fbebec358b9e78231f82fe91df7dea0fe8b22f015", "js/developer/environment/testing.mjs": "326e003f114bdbad68fedbceaded30717b3fc15315e6d87fa747972b681e2dce", diff --git a/js/developer/environment/runtime.mjs b/js/developer/environment/runtime.mjs index 7be427c5..449f46e5 100644 --- a/js/developer/environment/runtime.mjs +++ b/js/developer/environment/runtime.mjs @@ -16,6 +16,7 @@ import {build, dev, showPreview} from './development.mjs'; import {parseTestOptions, specFiles, jasmineCore, runnerFiles, runInFrame, reportResult, fitResult, stoppedRun, abortable, testDirectory} from './testing.mjs'; import {generateProvider, applicationPage} from './embed.mjs'; import {typescriptPackage, parseCheckOptions, checkHost} from './typecheck.mjs'; +import {pinnedStarters} from './bootstrap.mjs'; import {connectAutomation as connectAgent, clipText} from './automation.mjs'; const encoder = new TextEncoder(); @@ -315,7 +316,9 @@ export async function execute(args, context) { /** Automation operations this environment runs beyond the 0.6.3 set; the native owner refuses a grant it does not list. */ export const automationOperations = ['init', 'create', 'install', 'restore', 'embed']; -export const connectAutomation = context => connectAgent({...context,run:runNonInteractive,exclusive}); +// The launcher's native configuration has no starters: they come from the environment's own manifest, as in the terminal. +export const connectAutomation = ({environment, ...context}) => connectAgent({...context, run:runNonInteractive, exclusive, + config:{...context.config, starters:pinnedStarters(environment, new URL(context.config.environment, location.href))}}); /** * Runs one wf command without a terminal, for a page that the application drives: the command's output goes to diff --git a/js/developer/tools/WebFrontAgent.cpp b/js/developer/tools/WebFrontAgent.cpp index f8bdd98b..dc6486d9 100644 --- a/js/developer/tools/WebFrontAgent.cpp +++ b/js/developer/tools/WebFrontAgent.cpp @@ -48,6 +48,15 @@ struct Sources { }; Sources sources; +/// `-starter.tgz`: a plain file name, never a path. +bool isStarterArchive(std::string_view name) { + constexpr std::string_view suffix{"-starter.tgz"}; + return name.size() > suffix.size() && name.ends_with(suffix) + && std::ranges::all_of(name.substr(0, name.size() - suffix.size()), [](char c) { + return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '-' || c == '_'; + }); +} + struct Files { explicit Files(const std::filesystem::path&) { } std::optional open(std::filesystem::path path) const { @@ -55,6 +64,8 @@ struct Files { std::filesystem::path file; if (name == "automation/environment.tgz") file = sources.archive; + else if (name.starts_with("automation/") && isStarterArchive(name.substr(11))) + file = sources.archive.parent_path() / name.substr(11); // beside the environment; its manifest pins the integrity else if (!sources.registry.empty() && name.starts_with("automation/registry/")) { try { file = developer::projectPath(sources.registry, std::string_view(name).substr(20)); diff --git a/test/tools/AutomationClient.py b/test/tools/AutomationClient.py index d2fde97c..c1503706 100644 --- a/test/tools/AutomationClient.py +++ b/test/tools/AutomationClient.py @@ -466,6 +466,34 @@ def main(): client.close() assert client.child.returncode == 0, (client.child.returncode, pathlib.Path(log.name).read_text()) + # An agent builds a project from nothing: the starter comes from the environment's manifest and is served by the launcher. + setup = pathlib.Path(temporary) / "setup-project" + setup.mkdir() + setup_command = ["--project", str(setup), "--environment", args.environment, "--integrity", integrity, + "--registry-dir", args.registry] + with (pathlib.Path(temporary) / "setup.log").open("w") as log: + client = Client([args.agent, *setup_command, "--mcp", "--timeout", "60", "--startup-timeout", "60", + *sum((["--allow", op] for op in ("init", "create", "install", "restore", "embed")), [])], log) + try: + client.initialize() + missing = client.run("create", {"starter": "nonexistent"}, state="failed") + assert "Unknown pinned starter" in missing["output"], missing + client.run("create", {"starter": "life", "directory": "ui"}) + assert (setup / "ui/main.tsx").is_file() and (setup / "ui/style.css").is_file() + again = client.run("create", {"starter": "life", "directory": "ui"}, state="failed") + assert (setup / "ui/main.tsx").is_file(), again + client.run("init") + assert (setup / "webfront.project.json").is_file() + client.run("install", {"package": "react@19.3.1"}) + client.run("install", {"package": "react-dom@19.3.1"}) + client.run("restore") + client.run("embed", {"entry": "ui/main.tsx", "output": "generated/LifeUI.hpp"}) + header = setup / "generated/LifeUI.hpp" + assert header.is_file() and b"class LifeUI" in header.read_bytes(), "embed did not write the provider" + finally: + client.close() + assert client.child.returncode == 0, (client.child.returncode, pathlib.Path(log.name).read_text()) + # A human-owned window is already running before either agent attaches. Native grants remain the owner's. endpoint = pathlib.Path(temporary) / "shared-window" # Keep Chromium's temporary Unix socket paths below sockaddr_un's limit, independently