Skip to content
Open
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
14 changes: 6 additions & 8 deletions docs/public-api-contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,9 @@ publish `window.wpCodeboxBrowser.v1`. The `v1` facade is the stable browser SDK
for product consumers running inside the browser. Legacy top-level
`window.wpCodeboxBrowser` methods remain available for existing callers.

Consumer-facing WordPress abilities use the `wp-codebox/*` namespace. When an
ability has multiple registered names, new integrations should prefer the
inspectable `meta.canonical_ability` value. Aliases stay registered for existing
callers, but docs and schemas should describe the canonical Codebox-owned name
first.
Consumer-facing WordPress abilities use the `wp-codebox/*` namespace. Public
docs and schemas describe the canonical Codebox-owned names that integrations
should call directly.

The public runtime contract manifest currently publishes these Codebox-owned
ability identifiers:
Expand All @@ -62,9 +60,9 @@ ability identifiers:
- `wp-codebox/run-agent-task-fanout`
- `wp-codebox/run-runtime-package`

It also includes compatibility aliases for the `run-sandbox-task` family. The
manifest intentionally excludes backend handler bindings such as upstream Agents
API ability names, Playground command handlers, and integration-specific filters.
The manifest intentionally excludes backend handler bindings such as upstream
Agents API ability names, Playground command handlers, legacy aliases, and
integration-specific filters.

WordPress consumers should prefer `WP_Codebox_API` for PHP calls and
`wp-codebox/*` ability ids for ability-oriented calls. Runtime adapters may use
Expand Down
8 changes: 0 additions & 8 deletions packages/runtime-core/src/runtime-contract-manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,12 @@ export const RUNTIME_CONTRACT_MANIFEST_SCHEMA = "wp-codebox/runtime-contract-man
export const CODEBOX_RUN_AGENT_TASK_ABILITY = "wp-codebox/run-agent-task" as const
export const CODEBOX_RUN_AGENT_TASK_BATCH_ABILITY = "wp-codebox/run-agent-task-batch" as const
export const CODEBOX_RUN_AGENT_TASK_FANOUT_ABILITY = "wp-codebox/run-agent-task-fanout" as const
export const CODEBOX_RUN_SANDBOX_TASK_ABILITY = "wp-codebox/run-sandbox-task" as const
export const CODEBOX_RUN_SANDBOX_TASK_BATCH_ABILITY = "wp-codebox/run-sandbox-task-batch" as const
export const CODEBOX_RUN_SANDBOX_TASK_FANOUT_ABILITY = "wp-codebox/run-sandbox-task-fanout" as const

export const CODEBOX_PUBLIC_RUNTIME_ABILITIES = {
agentTask: {
run: CODEBOX_RUN_AGENT_TASK_ABILITY,
batch: CODEBOX_RUN_AGENT_TASK_BATCH_ABILITY,
fanout: CODEBOX_RUN_AGENT_TASK_FANOUT_ABILITY,
aliases: {
runSandboxTask: CODEBOX_RUN_SANDBOX_TASK_ABILITY,
runSandboxTaskBatch: CODEBOX_RUN_SANDBOX_TASK_BATCH_ABILITY,
runSandboxTaskFanout: CODEBOX_RUN_SANDBOX_TASK_FANOUT_ABILITY,
},
},
runtimePackage: {
run: CODEBOX_RUN_RUNTIME_PACKAGE_ABILITY,
Expand Down
18 changes: 0 additions & 18 deletions packages/wordpress-plugin/src/class-wp-codebox-abilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,12 +305,6 @@ private function register(): void {

wp_register_ability( 'wp-codebox/run-agent-task', $run_agent_task_ability );

$run_sandbox_task_ability = $run_agent_task_ability;
$run_sandbox_task_ability['label'] = 'Run Sandbox Task';
$run_sandbox_task_ability['description'] = 'Run a bounded task inside an isolated WP Codebox WordPress sandbox and return artifacts.';
$run_sandbox_task_ability['meta'] = array( 'show_in_rest' => true, 'canonical_ability' => 'wp-codebox/run-agent-task', 'alias_of' => 'wp-codebox/run-agent-task' );
wp_register_ability( 'wp-codebox/run-sandbox-task', $run_sandbox_task_ability );

wp_register_ability(
'wp-codebox/run-runtime-task',
array(
Expand Down Expand Up @@ -416,12 +410,6 @@ private function register(): void {

wp_register_ability( 'wp-codebox/run-agent-task-batch', $run_agent_task_batch_ability );

$run_sandbox_task_batch_ability = $run_agent_task_batch_ability;
$run_sandbox_task_batch_ability['label'] = 'Run Sandbox Task Batch';
$run_sandbox_task_batch_ability['description'] = 'Run multiple tasks in isolated WP Codebox WordPress sandboxes and return artifacts for each run.';
$run_sandbox_task_batch_ability['meta'] = array( 'show_in_rest' => true, 'canonical_ability' => 'wp-codebox/run-agent-task-batch', 'alias_of' => 'wp-codebox/run-agent-task-batch' );
wp_register_ability( 'wp-codebox/run-sandbox-task-batch', $run_sandbox_task_batch_ability );

$run_agent_task_fanout_ability = array(
'label' => 'Run Agent Sandbox Task Fanout',
'description' => 'Run multiple agent sandbox workers with bounded host-side concurrency and parent/child artifact envelopes.',
Expand Down Expand Up @@ -490,12 +478,6 @@ private function register(): void {

wp_register_ability( 'wp-codebox/run-agent-task-fanout', $run_agent_task_fanout_ability );

$run_sandbox_task_fanout_ability = $run_agent_task_fanout_ability;
$run_sandbox_task_fanout_ability['label'] = 'Run Sandbox Task Fanout';
$run_sandbox_task_fanout_ability['description'] = 'Run multiple sandbox workers with bounded host-side concurrency and parent/child artifact envelopes.';
$run_sandbox_task_fanout_ability['meta'] = array( 'show_in_rest' => true, 'canonical_ability' => 'wp-codebox/run-agent-task-fanout', 'alias_of' => 'wp-codebox/run-agent-task-fanout' );
wp_register_ability( 'wp-codebox/run-sandbox-task-fanout', $run_sandbox_task_fanout_ability );

wp_register_ability(
'wp-codebox/run-runtime-package',
array(
Expand Down
2 changes: 0 additions & 2 deletions packages/wordpress-plugin/src/class-wp-codebox-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@ final class WP_Codebox_API {
'wp-codebox/run-agent-task-batch' => 'run_agent_task_batch',
'wp-codebox/run-agent-task-fanout' => 'run_agent_task_fanout',
'wp-codebox/create-browser-playground-session' => 'create_browser_session',
'wp-codebox/create-sandbox-session' => 'create_browser_session',
'wp-codebox/create-browser-contained-site-session' => 'create_browser_contained_site_session',
'wp-codebox/get-browser-contained-site-status' => 'get_browser_session_status',
'wp-codebox/preview-reuse-decision' => 'preview_reuse_decision',
'wp-codebox/open-browser-contained-site' => 'open_browser_session',
'wp-codebox/open-or-create-browser-contained-site' => 'open_or_create_browser_session',
'wp-codebox/open-contained-runtime' => 'open_or_create_browser_session',
'wp-codebox/list-artifacts' => 'list_artifacts',
'wp-codebox/get-artifact' => 'get_artifact',
'wp-codebox/apply-artifact-preflight' => 'preflight_artifact_apply',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -696,42 +696,6 @@ public static function descriptors( array $context ): array {
),
);

$aliases = array(
'wp-codebox/create-sandbox-session' => array(
'canonical' => 'wp-codebox/create-browser-playground-session',
'label' => 'Create Sandbox Session',
'description' => 'Prepare a WP Codebox browser sandbox session and return the current browser session descriptor.',
),
'wp-codebox/create-task-contract' => array(
'canonical' => 'wp-codebox/create-browser-task-contract',
'label' => 'Create Task Contract',
'description' => 'Prepare a product-facing multi-phase WP Codebox task contract with a primary sandbox session and optional materializer phases.',
),
'wp-codebox/open-contained-runtime' => array(
'canonical' => 'wp-codebox/open-or-create-browser-contained-site',
'label' => 'Open Contained Runtime',
'description' => 'Open a reusable contained WP Codebox runtime when possible, otherwise create a fresh sandbox session from the same task input.',
),
);

foreach ( $aliases as $ability_id => $alias ) {
$canonical = $alias['canonical'];
if ( ! isset( $descriptors[ $canonical ] ) ) {
continue;
}

$descriptors[ $ability_id ] = $descriptors[ $canonical ];
$descriptors[ $ability_id ]['label'] = $alias['label'];
$descriptors[ $ability_id ]['description'] = $alias['description'];
$descriptors[ $ability_id ]['meta'] = array_merge(
is_array( $descriptors[ $ability_id ]['meta'] ?? null ) ? $descriptors[ $ability_id ]['meta'] : array(),
array(
'canonical_ability' => $canonical,
'alias_of' => $canonical,
)
);
}

return $descriptors;
}
}
40 changes: 19 additions & 21 deletions tests/public-ability-aliases.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,41 @@ import { readFile } from "node:fs/promises"
const abilitiesPhp = await readFile("packages/wordpress-plugin/src/class-wp-codebox-abilities.php", "utf8")
const descriptorsPhp = await readFile("packages/wordpress-plugin/src/class-wp-codebox-browser-ability-descriptors.php", "utf8")
const schemasPhp = await readFile("packages/wordpress-plugin/src/trait-wp-codebox-abilities-schemas.php", "utf8")
const apiPhp = await readFile("packages/wordpress-plugin/src/class-wp-codebox-api.php", "utf8")

const taskAliases = new Map([
["wp-codebox/run-sandbox-task", { canonical: "wp-codebox/run-agent-task", canonicalVar: "run_agent_task_ability", aliasVar: "run_sandbox_task_ability", callback: "run_agent_task" }],
["wp-codebox/run-sandbox-task-batch", { canonical: "wp-codebox/run-agent-task-batch", canonicalVar: "run_agent_task_batch_ability", aliasVar: "run_sandbox_task_batch_ability", callback: "run_agent_task_batch" }],
["wp-codebox/run-sandbox-task-fanout", { canonical: "wp-codebox/run-agent-task-fanout", canonicalVar: "run_agent_task_fanout_ability", aliasVar: "run_sandbox_task_fanout_ability", callback: "run_agent_task_fanout" }],
const taskAbilities = new Map([
["wp-codebox/run-agent-task", { variable: "run_agent_task_ability", callback: "run_agent_task" }],
["wp-codebox/run-agent-task-batch", { variable: "run_agent_task_batch_ability", callback: "run_agent_task_batch" }],
["wp-codebox/run-agent-task-fanout", { variable: "run_agent_task_fanout_ability", callback: "run_agent_task_fanout" }],
])

for (const [alias, expectation] of taskAliases) {
assert.match(abilitiesPhp, new RegExp(`wp_register_ability\\(\\s*'${alias}',\\s*\\$${expectation.aliasVar}\\s*\\)`))
assert.match(abilitiesPhp, new RegExp(`\\$${expectation.aliasVar}\\s*=\\s*\\$${expectation.canonicalVar};`))
assert.match(abilitiesPhp, new RegExp(`\\$${expectation.aliasVar}\\['meta'\\]\\s*=\\s*array\\([\\s\\S]*'canonical_ability'\\s*=>\\s*'${expectation.canonical}'[\\s\\S]*'alias_of'\\s*=>\\s*'${expectation.canonical}'[\\s\\S]*\\);`))
assert.match(abilitiesPhp, new RegExp(`\\$${expectation.canonicalVar}\\s*=\\s*array\\([\\s\\S]*'execute_callback'\\s*=>\\s*array\\(\\s*self::class,\\s*'${expectation.callback}'\\s*\\)`))
for (const [ability, expectation] of taskAbilities) {
assert.match(abilitiesPhp, new RegExp(`wp_register_ability\\(\\s*'${ability}',\\s*\\$${expectation.variable}\\s*\\)`))
assert.match(abilitiesPhp, new RegExp(`\\$${expectation.variable}\\s*=\\s*array\\([\\s\\S]*'execute_callback'\\s*=>\\s*array\\(\\s*self::class,\\s*'${expectation.callback}'\\s*\\)`))
}

for (const removedAlias of ["wp-codebox/run-sandbox-task", "wp-codebox/run-sandbox-task-batch", "wp-codebox/run-sandbox-task-fanout"]) {
assert.doesNotMatch(abilitiesPhp, new RegExp(`wp_register_ability\\(\\s*'${removedAlias}'`))
}

assert.match(abilitiesPhp, /wp_register_ability\(\s*'wp-codebox\/run-runtime-task'/)
assert.match(abilitiesPhp, /'execute_callback'\s*=>\s*array\(\s*self::class,\s*'run_runtime_task'\s*\)/)
assert.match(schemasPhp, /'schema'\s*=>\s*array\(\s*'type'\s*=>\s*'string',\s*'const'\s*=>\s*'wp-codebox\/runtime-task-request\/v1'\s*\)/)
assert.match(schemasPhp, /'schema'\s*=>\s*array\(\s*'type'\s*=>\s*'string',\s*'const'\s*=>\s*'wp-codebox\/runtime-task-result\/v1'\s*\)/)

const browserAliases = new Map([
["wp-codebox/create-sandbox-session", "wp-codebox/create-browser-playground-session"],
["wp-codebox/create-task-contract", "wp-codebox/create-browser-task-contract"],
["wp-codebox/open-contained-runtime", "wp-codebox/open-or-create-browser-contained-site"],
])
for (const canonical of ["wp-codebox/create-browser-playground-session", "wp-codebox/create-browser-task-contract", "wp-codebox/open-or-create-browser-contained-site"]) {
assert.match(descriptorsPhp, new RegExp(`'${canonical}'\\s*=>\\s*array\\(`))
}

for (const [alias, canonical] of browserAliases) {
assert.match(descriptorsPhp, new RegExp(`'${alias}'\\s*=>\\s*array\\(`))
assert.match(descriptorsPhp, new RegExp(`'canonical'\\s*=>\\s*'${canonical}'`))
for (const removedAlias of ["wp-codebox/create-sandbox-session", "wp-codebox/create-task-contract", "wp-codebox/open-contained-runtime"]) {
assert.doesNotMatch(descriptorsPhp, new RegExp(`'${removedAlias}'\\s*=>`))
assert.doesNotMatch(apiPhp, new RegExp(`'${removedAlias}'\\s*=>`))
}

assert.match(descriptorsPhp, /\$descriptors\[\s*\$ability_id\s*\]\s*=\s*\$descriptors\[\s*\$canonical\s*\]/)
assert.match(descriptorsPhp, /'canonical_ability'\s*=>\s*\$canonical/)
assert.match(descriptorsPhp, /'alias_of'\s*=>\s*\$canonical/)
assert.match(abilitiesPhp, /wp_register_ability\(\s*'wp-codebox\/run-runtime-package'/)
assert.match(abilitiesPhp, /'execute_callback'\s*=>\s*array\(\s*self::class,\s*'run_runtime_package'\s*\)/)
assert.match(abilitiesPhp, /'canonical_ability'\s*=>\s*'wp-codebox\/run-runtime-package'/)
assert.doesNotMatch(abilitiesPhp, /wp_register_ability\(\s*'agents\/run-runtime-package'/)
assert.doesNotMatch(abilitiesPhp + descriptorsPhp + schemasPhp, /datamachine|data machine/i)

console.log("public ability aliases ok")
console.log("public canonical abilities ok")
7 changes: 1 addition & 6 deletions tests/runtime-contract-manifest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ import {
CODEBOX_RUN_AGENT_TASK_BATCH_ABILITY,
CODEBOX_RUN_AGENT_TASK_FANOUT_ABILITY,
CODEBOX_RUN_RUNTIME_PACKAGE_ABILITY,
CODEBOX_RUN_SANDBOX_TASK_ABILITY,
CODEBOX_RUN_SANDBOX_TASK_BATCH_ABILITY,
CODEBOX_RUN_SANDBOX_TASK_FANOUT_ABILITY,
FANOUT_AGGREGATION_INPUT_SCHEMA,
FANOUT_AGGREGATION_OUTPUT_SCHEMA,
HOST_DELEGATION_EVENT_SCHEMA,
Expand Down Expand Up @@ -104,9 +101,7 @@ assert.equal(manifest.schemas.wordpressRuntimeDiscovery.restMatrixResult, WORDPR
assert.equal(manifest.abilities.agentTask.run, CODEBOX_RUN_AGENT_TASK_ABILITY)
assert.equal(manifest.abilities.agentTask.batch, CODEBOX_RUN_AGENT_TASK_BATCH_ABILITY)
assert.equal(manifest.abilities.agentTask.fanout, CODEBOX_RUN_AGENT_TASK_FANOUT_ABILITY)
assert.equal(manifest.abilities.agentTask.aliases.runSandboxTask, CODEBOX_RUN_SANDBOX_TASK_ABILITY)
assert.equal(manifest.abilities.agentTask.aliases.runSandboxTaskBatch, CODEBOX_RUN_SANDBOX_TASK_BATCH_ABILITY)
assert.equal(manifest.abilities.agentTask.aliases.runSandboxTaskFanout, CODEBOX_RUN_SANDBOX_TASK_FANOUT_ABILITY)
assert.equal("aliases" in manifest.abilities.agentTask, false)
assert.equal(manifest.abilities.runtimePackage.run, CODEBOX_RUN_RUNTIME_PACKAGE_ABILITY)

const values = runtimeContractSchemaValues()
Expand Down