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
11 changes: 8 additions & 3 deletions .github/workflows/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Docs Agent Workflows

`maintain-docs.yml` is the consumer-facing reusable workflow for scheduled upkeep. Consumer repositories pass product-level inputs such as `audience`, `require_pr`, `base_ref`, `docs_branch`, `writable_paths`, `context_repositories`, `bootstrap_contract`, `source_delta`, `validation_dependencies`, `verification_commands`, `drift_checks`, `prompt`, `run_agent`, `dry_run`, `max_turns`, and `time_budget_ms`.
`maintain-docs.yml` is the consumer-facing reusable workflow for scheduled upkeep. Consumer repositories pass product-level inputs such as `audience`, `require_pr`, `base_ref`, `docs_branch`, `docs_scope`, `writable_paths`, `context_repositories`, `bootstrap_contract`, `source_delta`, `validation_dependencies`, `verification_commands`, `drift_checks`, `prompt`, `run_agent`, `dry_run`, `max_turns`, and `time_budget_ms`.

The consumer workflow supports separate lanes for technical docs, user docs, and live skills maintenance. Use `audience: skills` with skills/package writable paths instead of broad docs paths.

Expand All @@ -16,12 +16,17 @@ The reusable workflow declares the expected typed review artifacts for Docs Agen

The target repository grants `contents: write`, `pull-requests: write`, and `issues: write`. Docs Agent forwards the caller-scoped `${{ github.token }}` to WP Codebox for same-repository publication, so consumers do not configure `ACCESS_TOKEN`. `OPENAI_API_KEY` is an optional workflow secret and is required only for a live OpenAI run; skipped and dry-run calls do not require it. `EXTERNAL_PACKAGE_SOURCE_POLICY` remains a separate required v1 JSON secret. Migrate its value to the exact one-line JSON in the root README: it authorizes the selected Docs Agent package, the pinned Agents API component, the pinned PHP AI Client overlay, and the checksum-pinned OpenAI provider artifact. Both secrets are forwarded to WP Codebox without serialization into the task descriptor.

Docs Agent consumes the reusable WP Codebox workflow and helper implementation at immutable revision `4875fb1550a34e4f07c44cff20bad477b83115de` and passes `wp_codebox_release_ref: v0.33.6` and `wp_codebox_workflow_ref: 4875fb1550a34e4f07c44cff20bad477b83115de`. That revision is the commit the annotated `v0.33.6` tag resolves to, so the reusable workflow, its helper scripts, and the release tag all name the same producer code; the fixed Docs Agent package revision stays separate. WP Codebox checks that the helper checkout matches `wp_codebox_workflow_ref` and that its `package.json` version equals the release tag, then installs its runtime from that checkout. WP Codebox materializes the declared native runtime closure, executes the selected package, applies bounded workspace changes, runs verification, and publishes approved host changes. The v0.33.6 release assets are `wp-codebox-cli-linux-x64.tar.gz`, `wp-codebox-workspace-0.33.6.tgz`, and `wp-codebox.zip`; `tests/wp-codebox-release.fixture.json` records their published SHA-256 digests.
Docs Agent consumes the reusable WP Codebox workflow and helper implementation at immutable revision `9764022156a61ba7d2b4d8a2196b01ccb33b82b5` and passes `wp_codebox_release_ref: v0.33.7` and `wp_codebox_workflow_ref: 9764022156a61ba7d2b4d8a2196b01ccb33b82b5`. That revision is the commit the annotated `v0.33.7` tag resolves to, so the reusable workflow, its helper scripts, and the release tag all name the same producer code; the fixed Docs Agent package revision stays separate. WP Codebox checks that the helper checkout matches `wp_codebox_workflow_ref` and that its `package.json` version equals the release tag, then installs its runtime from that checkout. WP Codebox materializes the declared native runtime closure, executes the selected package, applies bounded workspace changes, runs verification, and publishes approved host changes. The v0.33.7 release assets are `wp-codebox-cli-linux-x64.tar.gz`, `wp-codebox-workspace-0.33.7.tgz`, and `wp-codebox.zip`; `tests/wp-codebox-release.fixture.json` records their published SHA-256 digests.

Provider artifacts retain only allowlisted review artifacts, controlled workflow envelopes, and canonical runtime-source and seed provenance. WP Codebox uploads a reviewer-safe workflow-result projection: public control, verification, workspace-apply, publication, output-projection, access, failure, artifact-declaration, and canonical transcript-provenance fields remain, while raw `runtime_result`, `outputs.engine_data`, model/provider/tool payloads, source content, private paths, and secrets are excluded. Before persistence or upload, it sanitizes private runtime paths from nested values, object keys, diagnostics, and command arguments. WP Codebox captures one trusted canonical `codebox-transcript` through a pre-sanitization reviewer-evidence descriptor, validates its artifact-root containment, schema, digest, and size, then emits the compact reviewer transcript as a `wp-codebox/reviewer-agent-transcript/v1` projection. Before apply-back, it compares the seed identity with the host workspace identity; rejected patches preserve the expected and actual identities plus patch and changed-file evidence for upload. Its pre-redaction trusted apply input preserves machine-applicable patch bytes in a private channel that is removed before durable artifact sanitization, as fixed in [WP Codebox #1842](https://github.com/Automattic/wp-codebox/pull/1842). Lifecycle and downstream failures retain runtime evidence in their internal normalized failed result even when artifact preparation cannot complete. Diagnostic messages that name runtime classes remain reviewable, while PHP-shaped runtime source remains blocked. See [WP Codebox #1767](https://github.com/Automattic/wp-codebox/issues/1767), [WP Codebox #1814](https://github.com/Automattic/wp-codebox/issues/1814), [WP Codebox #1815](https://github.com/Automattic/wp-codebox/pull/1815), and [WP Codebox #1823](https://github.com/Automattic/wp-codebox/pull/1823). Successful canonical reviewer-evidence reference: [run `29350690551`](https://github.com/Automattic/build-with-wordpress/actions/runs/29350690551). The [hosted failure `29468956857`](https://github.com/Automattic/agents-api/actions/runs/29468956857) executed WP Codebox v0.12.20, published [Agents API #430](https://github.com/Automattic/agents-api/pull/430), then failed during upload preparation; it motivated #1814/#1815.

Publication integrity snapshots exclude Git-ignored verification artifacts, such as pnpm's symlinked `node_modules` tree, and mutable `.codebox` runtime control files, while tracked or otherwise publishable symlinks stay rejected. Integrity failures report bounded added, modified, and deleted paths, and non-Git workspaces keep a bounded filesystem snapshot fallback. Canonical GitHub repository identity is compared case-insensitively, while pull-request URL, pull number, target binding, and API resolution checks stay strict. Successful pull-request verification returns `{ valid: true }` without a failure-only `error`. These came from [WP Codebox #1845](https://github.com/Automattic/wp-codebox/pull/1845), [#1848](https://github.com/Automattic/wp-codebox/pull/1848), [#1852](https://github.com/Automattic/wp-codebox/pull/1852), [#1875](https://github.com/Automattic/wp-codebox/pull/1875), and [#1885](https://github.com/Automattic/wp-codebox/pull/1885).

WP Codebox v0.33.7 fixes two producer defects found in Extra Chill shop runs ([WP Codebox #2592](https://github.com/Automattic/wp-codebox/pull/2592), [#2591](https://github.com/Automattic/wp-codebox/issues/2591)):

- `workspace_git_status` and `workspace_git_diff` work in the git-less sandbox. They used to fail on every call (`tool_call_failed`) because no filesystem baseline was supplied. They now compare against the seeded content recorded before each path's first mutation. The diff is a real unified diff that replays through `workspace_apply_patch`.
- An explicit `runner_workspace.branch` is used as the publication branch exactly as given. Docs Agent now passes `docs_branch` only as `branch`, so the doubled `<docs_branch><workload-id>` names are gone. It passes `title`, `commit_message`, and `body` as well: the PR is titled `docs(<docs_scope>): <lane> docs <run_kind>` instead of the generic workload label, and WP Codebox appends the changed-files list to the body.

WP Codebox v0.33.6 reports why a failed agent runtime failed: every non-zero exit or unreadable native result now produces `failure` with `stage: agent`, a `code` and a `message`, and the canonical transcript plus `tool_observability` are uploaded on failure too ([WP Codebox #2590](https://github.com/Automattic/wp-codebox/pull/2590)). It also raises the native result bound from 1 MiB to 32 MiB and the tool-observability bound from 64 to 512 calls, because 40-turn runs exceeded both and lost all of their evidence.

WP Codebox v0.33.5 honors the caller's `max_turns` over an imported package's `default_max_turns` ([WP Codebox #2589](https://github.com/Automattic/wp-codebox/pull/2589)), so this workflow's `max_turns` input actually reaches the agent loop. A run that exhausts its turn budget while still calling tools now fails at `stage: agent` with `max_turns_exceeded` (`terminal_status: max_turns`, `agent_turn_limit` in the result) instead of finishing as a green no-op; partial work is not applied.
Expand All @@ -32,7 +37,7 @@ WP Codebox v0.33.4 made the runner-workspace apply step observable; see [WP Code
- If the sandbox accepted `workspace_write`, `workspace_edit`, or `workspace_apply_patch` calls but the canonical patch declared no changes, the run fails at `stage: apply` with `writes-not-applied` and lists the lost paths. Verification, drift checks, and the Docs Agent completion check do not run in that case. A run with no write calls still reaches them.
- The sandbox and the host use the same writable-path glob matcher: `**` spans directories, and `*`, `?`, and `[...]` stay within one path segment. Patterns such as `docs/**/*.md` or `plugins/*/docs/user/**` are no longer accepted in the sandbox and then rejected on the host.
- The uploader decodes the JSON-encoded `wordpress.run-php` output, so the compact reviewer transcript includes tool observability and the write ledger (tool names and workspace paths, never file contents).
- Publication reuses the branch derived from `docs_branch` only while it has an exact open pull request that descends from the current base. If the branch exists without an open pull request, WP Codebox publishes to a fresh `<branch>-<base-sha-12>` branch instead of appending to the stale one. If the open pull request's branch does not descend from the current base, publication fails and asks for a rebase.
- Publication reuses `docs_branch` only while it has an exact open pull request that descends from the current base. If the branch exists without an open pull request, WP Codebox publishes to a fresh `<branch>-<base-sha-12>` branch instead of appending to the stale one. If the open pull request's branch does not descend from the current base, publication fails and asks for a rebase.

## Docs Agent Runner Recipe

Expand Down
51 changes: 42 additions & 9 deletions .github/workflows/maintain-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Maintain Docs

env:
# Advance this revision and all package digests together when package bytes change.
DOCS_AGENT_PACKAGE_REVISION: 667a3d7e43b938cae157235131da4462b09eebb5
DOCS_AGENT_PACKAGE_REVISION: 2f83a20d5abb24f46fea9630259c8886d7134823
# Advance independently when the post-command completion validator changes.
DOCS_AGENT_COMPLETION_CONTRACT_REVISION: b136f9bc84e6f0ad9d5d0d5cdbb3df9c62e382e2

Expand All @@ -26,9 +26,13 @@ env:
type: string
default: main
docs_branch:
description: Stable branch reused for the canonical Docs Agent pull request.
description: Stable branch reused for the canonical Docs Agent pull request. Used exactly as given; WP Codebox appends -<base-sha-12> only when the branch exists without an open pull request.
type: string
default: docs-agent/docs-upkeep
docs_scope:
description: 'Conventional-commit scope for the docs pull request title, such as the component name, giving `docs(<scope>): <lane> docs <run_kind>`. Defaults to the repository name.'
type: string
default: ""
writable_paths:
description: Comma-separated paths Docs Agent may edit.
type: string
Expand Down Expand Up @@ -157,6 +161,7 @@ jobs:
DRY_RUN: ${{ inputs.dry_run }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
INPUT_DOCS_BRANCH: ${{ inputs.docs_branch }}
INPUT_DOCS_SCOPE: ${{ inputs.docs_scope }}
INPUT_BASE_REF: ${{ inputs.base_ref }}
GITHUB_REPOSITORY_NAME: ${{ github.repository }}
GITHUB_SERVER_URL: ${{ github.server_url }}
Expand All @@ -175,21 +180,21 @@ jobs:
technical:maintenance)
package_path="bundles/technical-docs-agent/native/technical-docs-maintenance-agent.agent.json"
agent_slug="technical-docs-maintenance-agent"
package_digest="sha256-bytes-v1:975c7b0a0a7aff52897c52be5ac903a7fb110ea3c33e16227f8694c74c932519"
package_digest="sha256-bytes-v1:4c0b545c7490ba62c243e085f6a145907787b19e76d72e3d83911657f6b187ab"
lane_requires_pr=false
default_prompt="Maintain source-grounded developer documentation that helps developers understand, use, and extend the code in the repository."
;;
user:bootstrap)
package_path="bundles/user-docs-agent/native/user-docs-bootstrap-agent.agent.json"
agent_slug="user-docs-bootstrap-agent"
package_digest="sha256-bytes-v1:d22cf858b4413e150226989ff8cf253e2cfa7ef88b041d8ce14360f22df9d3a4"
package_digest="sha256-bytes-v1:b2e61a5052e35be709b00210b36cea5dc2d5d4f42d1f183bc7af597270f552e1"
lane_requires_pr=true
default_prompt="Bootstrap source-grounded product documentation for onboarding, setup, common tasks, expected outcomes, permissions, compatibility, troubleshooting, and FAQs."
;;
user:maintenance)
package_path="bundles/user-docs-agent/native/user-docs-maintenance-agent.agent.json"
agent_slug="user-docs-maintenance-agent"
package_digest="sha256-bytes-v1:c93ce43cd7e057759779d36499fd26de45f8c7d3395bbf08583bbc83121e80e6"
package_digest="sha256-bytes-v1:dfdc3281afae497e311bd515a4bda8db40a9653b82ac5e621798cace53e1487c"
lane_requires_pr=false
default_prompt="Maintain source-grounded product documentation for onboarding, setup, common tasks, expected outcomes, permissions, compatibility, troubleshooting, and FAQs."
;;
Expand Down Expand Up @@ -310,11 +315,39 @@ jobs:
external_package_source="$(jq -cn --arg repository "Automattic/docs-agent" --arg revision "$DOCS_AGENT_PACKAGE_REVISION" --arg path "$package_path" --arg digest "$package_digest" '{repository:$repository,revision:$revision,path:$path,digest:$digest}')"
runtime_sources='[{"version":1,"role":"component","repository":"Automattic/agents-api","revision":"78e2dd409010f98fa4d26cdd72572117384ab18d","path":".","metadata":{"slug":"agents-api","loadAs":"mu-plugin","pluginFile":"agents-api.php"}},{"version":1,"role":"provider_plugin","source":{"type":"https_zip","url":"https://downloads.wordpress.org/plugin/ai-provider-for-openai.1.0.3.zip","sha256":"48f3c0c714b3164cda79d320829830d5a0ea1116e0b19653da8af898a22d3bb6","archive_root":"ai-provider-for-openai"},"metadata":{"slug":"ai-provider-for-openai","pluginFile":"plugin.php","activate":true,"providers":["openai"]}},{"version":1,"role":"bundled_library","repository":"WordPress/php-ai-client","revision":"631704201d15ffeff7091ad3bc7156db74054956","path":".","metadata":{"library":"php-ai-client","strategy":"wordpress-scoped-bundle"}}]'

# Pull request title and body. The title says what the run did instead of
# the generic workload label; WP Codebox appends the changed-files list.
docs_scope="${INPUT_DOCS_SCOPE:-${GITHUB_REPOSITORY_NAME##*/}}"
if ! printf '%s' "$docs_scope" | grep -Eq '^[A-Za-z0-9._/-]+$'; then
printf 'docs_scope must contain only letters, digits, dot, underscore, slash, and hyphen.\n' >&2
exit 1
fi
case "$AUDIENCE" in
skills) lane_title="skills" ;;
*) lane_title="$AUDIENCE docs" ;;
esac
pr_title="docs($docs_scope): $lane_title $RUN_KIND"
pr_body="$(jq -nr \
--arg scope "$docs_scope" \
--arg lane "$lane_title" \
--arg runKind "$RUN_KIND" \
--arg runUrl "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY_NAME/actions/runs/$GITHUB_RUN_ID_VALUE" \
--arg writablePaths "$INPUT_WRITABLE_PATHS" \
--argjson delta "$source_delta" '
"Automated " + $lane + " " + $runKind + " for `" + $scope + "` by [Docs Agent](https://github.com/Automattic/docs-agent).\n\n" +
"- Workflow run: " + $runUrl + "\n" +
"- Writable paths: `" + $writablePaths + "`\n" +
(if ($delta | length) > 0 then "- Source delta: " + ($delta | map("`" + .id + "`") | join(", ")) + "\n" else "" end) +
"\nGenerated documentation needs human review before merge. Check that every removed or rewritten line is contradicted by the source, and that accurate sections and concrete values were kept."
')"

runner_workspace="$(jq -cn \
--arg repo "$GITHUB_REPOSITORY_NAME" \
--arg branch "$INPUT_DOCS_BRANCH" \
--arg baseRef "$INPUT_BASE_REF" \
'{enabled:true,repo:$repo,clone_url:("https://github.com/" + $repo + ".git"),branch:$branch,branch_prefix:$branch,base:$baseRef,from:("origin/" + $baseRef)}')"
--arg title "$pr_title" \
--arg body "$pr_body" \
'{enabled:true,repo:$repo,clone_url:("https://github.com/" + $repo + ".git"),branch:$branch,base:$baseRef,from:("origin/" + $baseRef),title:$title,commit_message:$title,body:$body}')"
expected_artifacts="$(printf '%s' "$artifact_declarations" | jq -c 'map(.name)')"
output_projections="$(jq -cn --arg path 'metadata.runner_workspace_publication.pull_request.url' --argjson required "$success_requires_pr" '{docs_agent_publication:{path:$path,required:$required}}')"
if ! printf '%s' "$DOCS_AGENT_COMPLETION_CONTRACT_REVISION" | grep -Eq '^[0-9a-fA-F]{40}$'; then
Expand Down Expand Up @@ -356,10 +389,10 @@ jobs:
contents: write
pull-requests: write
issues: write
uses: Automattic/wp-codebox/.github/workflows/run-agent-task.yml@4875fb1550a34e4f07c44cff20bad477b83115de
uses: Automattic/wp-codebox/.github/workflows/run-agent-task.yml@9764022156a61ba7d2b4d8a2196b01ccb33b82b5
with:
wp_codebox_release_ref: v0.33.6
wp_codebox_workflow_ref: 4875fb1550a34e4f07c44cff20bad477b83115de
wp_codebox_release_ref: v0.33.7
wp_codebox_workflow_ref: 9764022156a61ba7d2b4d8a2196b01ccb33b82b5
external_package_source: ${{ needs.prepare.outputs.external_package_source }}
runtime_sources: ${{ needs.prepare.outputs.runtime_sources }}
workload_id: docs-agent-${{ inputs.audience }}-${{ inputs.run_kind }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
uses: actions/checkout@v4
with:
repository: Automattic/wp-codebox
ref: 4875fb1550a34e4f07c44cff20bad477b83115de
ref: 9764022156a61ba7d2b4d8a2196b01ccb33b82b5
path: .wp-codebox
- name: Validate Docs Agent
env:
Expand Down
Loading
Loading