Skip to content

Commit 8f62194

Browse files
ualtinokAlfonso
andcommitted
drive-rig: identical-path mounts, plugin runtime dep, XDG connection-file resolution
The container now mounts the snapshot at its host-identical absolute path and starts sessions from a symlinked host-shaped project path, because the host-side mc-module stats the project root on the host filesystem and the plugin embeds absolute paths in config and session state. The snapshot plugin package declares and installs @opencode-ai/plugin, the one bare import the dist bundle externalizes, since OpenCode's file:// plugin loader reports resolution failures only as session errors with no log line. The entrypoint also exposes the mounted subc connection file at the XDG data default the plugin's client resolves. Co-authored-by: Alfonso <alfonso@cortexkit.io>
1 parent 518ff59 commit 8f62194

4 files changed

Lines changed: 61 additions & 14 deletions

File tree

scripts/drive-rig/entrypoint.sh

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,31 @@ if ! kill -0 "$forwarder_pid" 2>/dev/null; then
3434
exit 1
3535
fi
3636

37+
# The cloned session row records its host-side working directory. OpenCode
38+
# resolves the session's project (and Magic Context finds the project config
39+
# carrying transform_mode) from that recorded path, so recreate it as a
40+
# symlink to the snapshot repo instead of rewriting database rows.
41+
: "${DRIVE_SESSION_DIR:=/Users/ufukaltinok/Work/Projects/CortexKit/benchmarks}"
42+
if [[ ! -e "$DRIVE_SESSION_DIR" ]]; then
43+
mkdir -p "$(dirname "$DRIVE_SESSION_DIR")"
44+
ln -s "$DRIVE_REPO" "$DRIVE_SESSION_DIR"
45+
fi
46+
47+
# The plugin's subc client resolves the connection file from the XDG data dir
48+
# default, not only from the config value, so expose the mounted file at that
49+
# default location too.
50+
xdg_conn_dir="${XDG_DATA_HOME:-$HOME/.local/share}/cortexkit/run"
51+
mkdir -p "$xdg_conn_dir"
52+
if [[ ! -e "$xdg_conn_dir/subc-connection.json" ]]; then
53+
ln -s "$SUBC_CONNECTION_FILE" "$xdg_conn_dir/subc-connection.json"
54+
fi
55+
56+
# tmux starts at the host-path symlink, not /snapshot/repo: the working
57+
# directory string travels to the host-side mc-module, which stats the
58+
# project root on the HOST filesystem. The host path exists there (the real
59+
# checkout) and resolves to the snapshot clone inside the container.
3760
if ! tmux has-session -t drive 2>/dev/null; then
38-
tmux new-session -d -s drive -c "$DRIVE_REPO" bash
61+
tmux new-session -d -s drive -c "$DRIVE_SESSION_DIR" bash
3962
fi
4063

4164
exec tail -f /dev/null

scripts/drive-rig/prepare.sh

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ mkdir -p \
4646
"$SNAPSHOT/home/.config/cortexkit" \
4747
"$SNAPSHOT/home/.config/opencode" \
4848
"$SNAPSHOT/home/.cache" \
49-
"$SNAPSHOT/plugin-dist"
49+
"$SNAPSHOT/plugin/dist"
5050

5151
vacuum_into() {
5252
local source=$1
@@ -106,8 +106,8 @@ rewrite_opencode_plugin_path() {
106106
local contents
107107
local host_plugin_url="file://$REPO_ROOT/packages/plugin"
108108
contents=$(<"$config_path")
109-
contents=${contents//"$host_plugin_url"/"file:///snapshot/plugin-dist/index.js"}
110-
contents=${contents//"$REPO_ROOT/packages/plugin"/"/snapshot/plugin-dist/index.js"}
109+
contents=${contents//"$host_plugin_url"/"file://$SNAPSHOT/plugin"}
110+
contents=${contents//"$REPO_ROOT/packages/plugin"/"$SNAPSHOT/plugin"}
111111
printf '%s\n' "$contents" > "$config_path"
112112
}
113113
prune_dead_file_plugins() {
@@ -116,7 +116,7 @@ prune_dead_file_plugins() {
116116
awk '
117117
BEGIN { in_plugins = 0 }
118118
/^[[:space:]]*"plugin"[[:space:]]*:[[:space:]]*\[/ { in_plugins = 1 }
119-
in_plugins && /file:\/\// && $0 !~ /file:\/\/\/snapshot\/plugin-dist\/index\.js/ { next }
119+
in_plugins && /file:\/\// && $0 !~ /file:\/\/\/snapshot\/plugin/ { next }
120120
in_plugins && /^[[:space:]]*\]/ { in_plugins = 0 }
121121
{ print }
122122
' "$config_path" > "$config_tmp"
@@ -143,7 +143,31 @@ if [[ -d "$BENCHMARKS_SOURCE/.cortexkit" ]]; then
143143
cp -R "$BENCHMARKS_SOURCE/.cortexkit" "$SNAPSHOT/repo/.cortexkit"
144144
fi
145145

146-
cp -R "$PLUGIN_DIST/." "$SNAPSHOT/plugin-dist/"
146+
# OpenCode loads directory plugins through their package.json entry. The dist
147+
# bundle inlines almost everything but externalizes @opencode-ai/plugin (the
148+
# host resolves it through the workspace node_modules), so the snapshot
149+
# package declares exactly that one dependency and installs it here on the
150+
# host. The subtree is pure JS, so a host-side install is portable to the
151+
# linux container. The full plugin package.json is deliberately NOT copied:
152+
# its dependency list includes macOS-native onnx binaries that cannot load
153+
# inside the container.
154+
cp -R "$PLUGIN_DIST/." "$SNAPSHOT/plugin/dist/"
155+
plugin_version=$(jq -r '.version' "$REPO_ROOT/packages/plugin/package.json")
156+
plugin_api_version=$(jq -r '.version' \
157+
"$REPO_ROOT/packages/plugin/node_modules/@opencode-ai/plugin/package.json")
158+
jq -n --arg version "$plugin_version" --arg api "$plugin_api_version" '{
159+
name: "@cortexkit/opencode-magic-context",
160+
version: $version,
161+
type: "module",
162+
main: "dist/index.js",
163+
dependencies: { "@opencode-ai/plugin": $api }
164+
}' > "$SNAPSHOT/plugin/package.json"
165+
printf 'installing plugin runtime dependency\n'
166+
(cd "$SNAPSHOT/plugin" && bun install --production >/dev/null 2>&1)
167+
if [[ ! -d "$SNAPSHOT/plugin/node_modules/@opencode-ai/plugin" ]]; then
168+
printf 'plugin dependency install failed in %s\n' "$SNAPSHOT/plugin" >&2
169+
exit 1
170+
fi
147171

148172
printf 'snapshot ready: %s\n' "$SNAPSHOT"
149173
printf 'session preserved: %s\n' "$SESSION_ID"

scripts/drive-rig/run.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@ docker run -d \
5454
--cpus=4 \
5555
--memory=8g \
5656
--add-host=host.docker.internal:host-gateway \
57-
-v "$SNAPSHOT:/snapshot:rw" \
57+
-v "$SNAPSHOT:$SNAPSHOT:rw" \
5858
-v "$CONNECTION_FILE:$CONNECTION_FILE:ro" \
59-
-e HOME=/snapshot/home \
60-
-e XDG_DATA_HOME=/snapshot/home/.local/share \
61-
-e XDG_CONFIG_HOME=/snapshot/home/.config \
62-
-e XDG_CACHE_HOME=/snapshot/home/.cache \
63-
-e MAGIC_CONTEXT_LOG_PATH=/snapshot/magic-context.log \
59+
-e HOME="$SNAPSHOT/home" \
60+
-e XDG_DATA_HOME="$SNAPSHOT/home/.local/share" \
61+
-e XDG_CONFIG_HOME="$SNAPSHOT/home/.config" \
62+
-e XDG_CACHE_HOME="$SNAPSHOT/home/.cache" \
63+
-e MAGIC_CONTEXT_LOG_PATH="$SNAPSHOT/magic-context.log" \
6464
-e SUBC_CONNECTION_FILE="$CONNECTION_FILE" \
65-
-e DRIVE_REPO=/snapshot/repo \
65+
-e DRIVE_REPO="$SNAPSHOT/repo" \
6666
"$IMAGE"
6767

6868
printf 'container started: %s\n' "$CONTAINER"

scripts/drive-rig/verify.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ CONTAINER=${DRIVE_RIG_CONTAINER:-mc-drive}
55
SNAPSHOT=${DRIVE_RIG_SNAPSHOT:-"$HOME/.cache/mc-drive-rig/snapshot"}
66
CONNECTION_FILE=${DRIVE_RIG_CONNECTION_FILE:-"$HOME/.local/share/cortexkit/run/subc-connection.json"}
77
SESSION_ID=${DRIVE_RIG_SESSION_ID:-ses_OqknfoW2O3LTOcjLvOMQoREVPtz1}
8-
LOG_PATH=${DRIVE_RIG_LOG_PATH:-/snapshot/magic-context.log}
8+
LOG_PATH=${DRIVE_RIG_LOG_PATH:-$SNAPSHOT/magic-context.log}
99
WAIT_SECONDS=${DRIVE_RIG_WAIT_SECONDS:-180}
1010

1111
if ! command -v docker >/dev/null 2>&1; then

0 commit comments

Comments
 (0)