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
13 changes: 11 additions & 2 deletions docs/runtime-sessions.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ upgrade), the history goes with it. The `wp-coding-agents-runtime-sessions.php`
mu-plugin keeps a copy on the site, in the Agents API conversation store, so the
runtime can put it back.

Setup and upgrade install the mu-plugin on colocated sites. Hosts that install
mu-plugins themselves copy `templates/wp-coding-agents-runtime-sessions.php`.
Setup and upgrade install the mu-plugin on colocated sites. An
`--external-wordpress` setup with `--wordpress-mount <path>` copies it into
`<path>/wp-content/mu-plugins`. The copy only happens when the file is missing
or different, and it leaves the mount's ownership and mode alone because the
remote host owns those files. Without a mount, setup skips the mu-plugin. Hosts
that install mu-plugins themselves copy
`templates/wp-coding-agents-runtime-sessions.php`.

## Commands

Expand Down Expand Up @@ -76,3 +81,7 @@ trip with a Pi session fixture (`tests/fixtures/runtime-sessions/pi-session.json
written by Pi's `SessionManager`). It downloads WP-CLI, Agents API and the
SQLite integration unless `WP_CLI_PHAR`, `AGENTS_API_DIR` and
`SQLITE_INTEGRATION_DIR` point at local copies.

`tests/external-wordpress-runtime.sh` checks the external install. It covers a
first install into the mount, a repeat run that leaves the file untouched, and a
run without a mount that still succeeds.
16 changes: 9 additions & 7 deletions lib/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -311,15 +311,17 @@ write_file() {
fi
}

# mu_plugin_template_sync <template-file-name> <label>
# mu_plugin_template_sync <template-file-name> <label> [<wordpress-root>]
#
# Copy templates/<template-file-name> into $SITE_PATH/wp-content/mu-plugins
# when it is missing or differs, then normalize its permissions.
# Copy templates/<template-file-name> into <wordpress-root>/wp-content/mu-plugins
# (default $SITE_PATH) when it is missing or differs, then normalize its
# permissions. External WordPress mounts belong to the remote host, so their
# ownership and mode are left alone.
mu_plugin_template_sync() {
local name="$1" label="$2" template file
[ -n "${SITE_PATH:-}" ] || { warn " $label: SITE_PATH not set — skipping"; return 1; }
local name="$1" label="$2" root="${3:-${SITE_PATH:-}}" template file
[ -n "$root" ] || { warn " $label: SITE_PATH not set — skipping"; return 1; }
template="$SCRIPT_DIR/templates/$name"
file="$SITE_PATH/wp-content/mu-plugins/$name"
file="$root/wp-content/mu-plugins/$name"
[ -f "$template" ] || { warn " $label: missing template $template"; return 1; }
if [ "${DRY_RUN:-false}" = true ]; then
echo -e "${BLUE}[dry-run]${NC} Would sync $label mu-plugin to $file"
Expand All @@ -331,7 +333,7 @@ mu_plugin_template_sync() {
log " Synced $label mu-plugin: $file"
[ -z "${UPDATED_ITEMS+x}" ] || UPDATED_ITEMS+=("$label")
fi
service_file_normalize_perms "$file"
[ "${EXTERNAL_WORDPRESS:-false}" = true ] || service_file_normalize_perms "$file"
}

# service_file_normalize_perms <file>
Expand Down
10 changes: 10 additions & 0 deletions lib/runtime-sessions.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
#!/bin/bash
# Runtime session persistence: `wp coding-agents session push|pull`.

# External WordPress runtimes install into the site only through
# --wordpress-mount; without a mount the host installs the mu-plugin itself.
runtime_sessions_install() {
if [ "${EXTERNAL_WORDPRESS:-false}" = true ]; then
if [ -z "${WORDPRESS_MOUNT:-}" ]; then
log " Runtime sessions: no --wordpress-mount — the host installs the mu-plugin"
return 0
fi
mu_plugin_template_sync wp-coding-agents-runtime-sessions.php "Runtime sessions" "$WORDPRESS_MOUNT"
return
fi
mu_plugin_template_sync wp-coding-agents-runtime-sessions.php "Runtime sessions"
}
2 changes: 1 addition & 1 deletion setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ if convergence_run "$INSTALLATION_OPERATION_SETUP"; then :; else
exit "$CONVERGENCE_EXIT_STATUS"
fi
[ "$RUNTIME_ONLY" != true ] && remove_retired_skills
if [ "$RUNTIME_ONLY" != true ]; then if [ "$EXTERNAL_WORDPRESS" != true ]; then cli_transport_install; inbound_event_bridge_install; runtime_sessions_install; wordpress_chat_apply; else inbound_event_connector_install; fi; fi
if [ "$RUNTIME_ONLY" != true ]; then if [ "$EXTERNAL_WORDPRESS" != true ]; then cli_transport_install; inbound_event_bridge_install; runtime_sessions_install; wordpress_chat_apply; else inbound_event_connector_install; runtime_sessions_install; fi; fi
# Install the reconciler, then run it once so a fresh install converges the same
# way a live change will.
if [ "$RUNTIME_ONLY" != true ] && [ "$EXTERNAL_WORDPRESS" != true ]; then source_reconcile_sync; source_reconcile_run; fi
Expand Down
18 changes: 18 additions & 0 deletions tests/external-wordpress-runtime.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ source "$SCRIPT_DIR/lib/wordpress.sh"
source "$SCRIPT_DIR/lib/external-wordpress.sh"
source "$SCRIPT_DIR/lib/ai-gateway.sh"
source "$SCRIPT_DIR/lib/agents-md-guidance.sh"
source "$SCRIPT_DIR/lib/runtime-sessions.sh"
log() { :; }
warn() { :; }
error() { printf '%s\n' "$*" >&2; exit 1; }
Expand Down Expand Up @@ -119,4 +120,21 @@ if (sleep() { :; }; external_wordpress_project_context) > "$TMP/failure" 2>&1; t
echo 'FAIL: unavailable transport projected context'; exit 1
fi
grep -F 'Could not list injectable Data Machine context through the external control transport' "$TMP/failure"
# Runtime sessions mu-plugin installs into the mount without touching its perms.
service_file_normalize_perms() { echo "$1" >> "$TMP/normalized"; }
mounted="$TMP/mount/wp-content/mu-plugins/wp-coding-agents-runtime-sessions.php"
WORDPRESS_MOUNT="$TMP/mount"
UPDATED_ITEMS=(seed)
runtime_sessions_install
cmp "$SCRIPT_DIR/templates/wp-coding-agents-runtime-sessions.php" "$mounted"
[ "${#UPDATED_ITEMS[@]}" -eq 2 ]
touch -d '2001-01-01 00:00:00' "$mounted"
before="$(stat -c %Y "$mounted")"
runtime_sessions_install
[ "$(stat -c %Y "$mounted")" = "$before" ]
[ "${#UPDATED_ITEMS[@]}" -eq 2 ]
[ ! -e "$TMP/normalized" ]
unset WORDPRESS_MOUNT
runtime_sessions_install
[ ! -e "$RUNTIME_PROJECT_ROOT/wp-content" ]
echo 'PASS: external WordPress Pi-only transport'