Skip to content

Commit 137e9ef

Browse files
authored
Merge pull request #368 from Extra-Chill/fix/367-wp-cli-global-flags
Fix external WordPress WP-CLI global flag ordering
2 parents aa22c3a + 1700d4f commit 137e9ef

5 files changed

Lines changed: 27 additions & 11 deletions

File tree

bridges/kimaki/plugins/kimaki-session-attribution.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ type SessionAwareHooks = Awaited<ReturnType<Plugin>> & {
1212
};
1313

1414
const DISCORD_THREAD_URL = /^https:\/\/discord\.com\/channels\/\d{17,20}\/(\d{17,20})\/?$/;
15-
const LOOKUP_TIMEOUT_MS = 2_000;
15+
const LOOKUP_TIMEOUT_MS = 5_000;
1616
const OUTPUT_LIMIT = 1_024;
1717

1818
const sessionAttribution = (async (_input: PluginInput): Promise<SessionAwareHooks> => {

lib/external-wordpress.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ value = json.loads(sys.argv[1])
2424
if not isinstance(value, list) or not value or any(not isinstance(item, str) or not item or "\0" in item for item in value):
2525
raise SystemExit(1)
2626
PY
27-
mapfile -d '' -t WP_CONTROL_TRANSPORT < <(python3 - "$WP_CONTROL_TRANSPORT_JSON" <<'PY'
27+
WP_CONTROL_TRANSPORT=()
28+
while IFS= read -r -d '' transport_argument; do
29+
WP_CONTROL_TRANSPORT+=("$transport_argument")
30+
done < <(python3 - "$WP_CONTROL_TRANSPORT_JSON" <<'PY'
2831
import json, sys
2932
for item in json.loads(sys.argv[1]):
3033
sys.stdout.buffer.write(item.encode() + b"\0")

lib/wordpress.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ wp_cmd() {
66
if [ "${EXTERNAL_WORDPRESS:-false}" = true ]; then
77
local user_args=()
88
[ -z "${WORDPRESS_USER:-}" ] || user_args=("--user=$WORDPRESS_USER")
9-
run_cmd "${WP_CONTROL_TRANSPORT[@]}" "$@" "${user_args[@]}" "--path=$WORDPRESS_PATH"
9+
run_cmd "${WP_CONTROL_TRANSPORT[@]}" "${user_args[@]}" "--path=$WORDPRESS_PATH" "$@"
1010
return
1111
fi
1212
if [ "$IS_STUDIO" = true ]; then

scripts/wp-control-transport.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ def fail(message: str) -> None:
3030
if not wordpress_path:
3131
fail("WORDPRESS_PATH is required")
3232

33-
command = [*transport, *sys.argv[1:]]
3433
wordpress_user = os.environ.get("WORDPRESS_USER", "") or profile.get("wordpress_user", "")
34+
global_args = []
3535
if wordpress_user:
36-
command.append(f"--user={wordpress_user}")
37-
command.append(f"--path={wordpress_path}")
36+
global_args.append(f"--user={wordpress_user}")
37+
global_args.append(f"--path={wordpress_path}")
38+
command = [*transport, *global_args, *sys.argv[1:]]
3839
os.execvpe(command[0], command, os.environ)

tests/external-wordpress-runtime.sh

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,16 @@ PY
3636
cat > "$TRANSPORT" <<'SH'
3737
#!/bin/bash
3838
printf '%s\n' "$@" >> "$WP_TEST_ARGS"
39-
case "$3:$4" in
40-
core:is-installed) exit 0 ;;
39+
case "$#:$1:$2:$3:$4:$5:$6" in
40+
"6:--identity:secret value with spaces:--user=$WORDPRESS_USER:--path=$WORDPRESS_PATH:core:is-installed") exit 0 ;;
41+
"5:--identity:secret value with spaces:--path=$WORDPRESS_PATH:core:is-installed:") exit 0 ;;
42+
esac
43+
case "$5:$6" in
4144
datamachine:memory)
42-
case "$5" in
45+
case "$7" in
4346
injectable-files) printf '%s\n' '[{"filename":"SITE.md","layer":"shared","priority":10,"path":"/remote/wp-content/uploads/datamachine-files/shared/SITE.md"},{"filename":"SOUL.md","layer":"agent","priority":20,"path":"/remote/wp-content/uploads/datamachine-files/agents/remote/SOUL.md"}]' ;;
4447
read)
45-
case "$6" in
48+
case "$8" in
4649
SITE.md) printf '%s\n' 'site context' ;;
4750
SOUL.md) printf '%s\n' 'agent context' ;;
4851
*) exit 7 ;;
@@ -51,10 +54,11 @@ case "$3:$4" in
5154
esac
5255
;;
5356
eval:*)
54-
[ "$#" -eq 6 ] && [ "$5" = "--user=$WORDPRESS_USER" ] && [ "$6" = "--path=$WORDPRESS_PATH" ] || {
57+
[ "$#" -eq 6 ] && [ "$3" = "--user=$WORDPRESS_USER" ] && [ "$4" = "--path=$WORDPRESS_PATH" ] || {
5558
echo "wp eval received unsupported positional arguments" >&2
5659
exit 9
5760
}
61+
set -- "$1" "$2" "$3" "$6"
5862
case "$4" in
5963
*"require base64_decode"*) echo "decoded PHP source was treated as a filename" >&2; exit 9 ;;
6064
esac
@@ -111,6 +115,7 @@ error() { printf '%s\n' "$*" >&2; return 1; }
111115

112116
external_wordpress_prepare_transport
113117
external_wordpress_validate
118+
"$RUNTIME_PROJECT_ROOT/.wp-coding-agents/bin/wp-control" core is-installed >/dev/null
114119
external_wordpress_project_context
115120
runtime_generate_config
116121
WITH_AI_GATEWAY=true
@@ -193,6 +198,13 @@ after_wrapper_calls="$(wc -l < "$ARGS" | tr -d ' ')"
193198
[ "$(sed -n '3p' "$KIMAKI_ENV")" = "agent user" ] || { echo "FAIL: Kimaki launcher lost WordPress user"; exit 1; }
194199
export WORDPRESS_PATH="/remote/site root" WORDPRESS_USER="agent user"
195200

201+
# Userless profiles retain the transport prefix and emit only the path global.
202+
printf '%s\n' '{"wordpress_path":"/remote/site root","wordpress_user":""}' > "$RUNTIME_PROJECT_ROOT/.wp-coding-agents/wordpress.json"
203+
unset WORDPRESS_USER
204+
"$RUNTIME_PROJECT_ROOT/.wp-coding-agents/bin/wp-control" core is-installed >/dev/null
205+
external_wordpress_validate
206+
export WORDPRESS_USER="agent user"
207+
196208
if grep -R -F -- "secret value with spaces" "$RUNTIME_PROJECT_ROOT" >/dev/null 2>&1; then
197209
echo "FAIL: transport credential persisted below runtime root"
198210
exit 1

0 commit comments

Comments
 (0)