openclaw-opencode-bridge 2.0.6 → 2.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/onboard.js CHANGED
@@ -47,24 +47,20 @@ const BRIDGE_COMMANDS = [
47
47
  // Variable names used in each script (for patching existing scripts)
48
48
  const SCRIPT_VARS = {
49
49
  "opencode-session.sh": {
50
- TMUX: "TMUX_BIN",
51
50
  OPENCODE: "OPENCODE_BIN",
52
51
  WORKSPACE: "WORKSPACE",
53
- SESSION: "SESSION_NAME",
54
52
  },
55
53
  "opencode-send.sh": {
56
- TMUX: "TMUX_BIN",
54
+ OPENCODE: "OPENCODE_BIN",
57
55
  CHANNEL: "CHANNEL",
58
56
  TARGET: "TARGET_ID",
59
- SESSION: "SESSION_NAME",
57
+ WORKSPACE: "WORKSPACE",
60
58
  },
61
59
  "opencode-new-session.sh": {
62
- TMUX: "TMUX_BIN",
63
60
  OPENCODE: "OPENCODE_BIN",
64
- WORKSPACE: "WORKSPACE",
65
61
  CHANNEL: "CHANNEL",
66
62
  TARGET: "TARGET_ID",
67
- SESSION: "SESSION_NAME",
63
+ WORKSPACE: "WORKSPACE",
68
64
  },
69
65
  "opencode-stats.sh": {
70
66
  TMUX: "TMUX_BIN",
@@ -80,7 +76,6 @@ const SCRIPT_VARS = {
80
76
  TARGET: "TARGET_ID",
81
77
  },
82
78
  "opencode-setmodel.sh": {
83
- TMUX: "TMUX_BIN",
84
79
  OPENCODE: "OPENCODE_BIN",
85
80
  CHANNEL: "CHANNEL",
86
81
  TARGET: "TARGET_ID",
package/package.json CHANGED
@@ -1,13 +1,12 @@
1
1
  {
2
2
  "name": "openclaw-opencode-bridge",
3
- "version": "2.0.6",
3
+ "version": "2.0.7",
4
4
  "description": "Bridge OpenClaw messaging channels to OpenCode via tmux persistent sessions",
5
5
  "main": "./lib/onboard.js",
6
6
  "bin": {
7
7
  "openclaw-opencode-bridge": "./lib/cli.js"
8
8
  },
9
- "scripts": {
10
- },
9
+ "scripts": {},
11
10
  "preferGlobal": true,
12
11
  "dependencies": {
13
12
  "commander": "^12.0.0",
@@ -17,7 +16,9 @@
17
16
  "node": ">=18.0.0"
18
17
  },
19
18
  "openclaw": {
20
- "extensions": ["./plugin/index.ts"]
19
+ "extensions": [
20
+ "./plugin/index.ts"
21
+ ]
21
22
  },
22
23
  "keywords": [
23
24
  "openclaw",
@@ -1,46 +1,20 @@
1
1
  #!/bin/bash
2
- # bridge-version: 1
3
- # Kill existing session -> create new session -> send instruction
2
+ # bridge-version: 2
3
+ # Start fresh session and send instruction
4
4
  MSG="$1"
5
- TMUX="{{TMUX_BIN}}"
6
5
  OPENCODE="{{OPENCODE_BIN}}"
7
- WORKSPACE="{{WORKSPACE}}"
8
6
  CHANNEL="{{CHANNEL}}"
9
7
  TARGET="{{TARGET_ID}}"
10
- SESSION="{{SESSION_NAME}}"
8
+ WORKSPACE="{{WORKSPACE}}"
11
9
 
12
10
  if [ -z "$MSG" ]; then
13
11
  echo "ERROR: No message provided"
14
12
  exit 1
15
13
  fi
16
14
 
17
- # Kill existing session
18
- if "$TMUX" has-session -t "$SESSION" 2>/dev/null; then
19
- "$TMUX" kill-session -t "$SESSION" 2>/dev/null
20
- sleep 1
21
- fi
22
-
23
- # Create new session
24
- "$TMUX" new-session -d -s "$SESSION"
25
- "$TMUX" set-option -t "$SESSION" history-limit 10000
26
- "$TMUX" send-keys -t "$SESSION" "cd $WORKSPACE && $OPENCODE" Enter
27
-
28
- # Wait for OpenCode prompt
29
- WAIT=0
30
- while [ $WAIT -lt 60 ]; do
31
- PANE=$("$TMUX" capture-pane -t "$SESSION" -p)
32
- if echo "$PANE" | grep -qE "❯|>|opencode"; then
33
- break
34
- fi
35
- sleep 2
36
- WAIT=$((WAIT + 2))
37
- done
15
+ cd "$WORKSPACE"
16
+ FULL_MSG="[${CHANNEL}:${TARGET}] $MSG"
38
17
 
39
- # Send instruction
40
- sleep 1
41
- printf '%s' "[${CHANNEL}:${TARGET}] $MSG" | "$TMUX" load-buffer -
42
- "$TMUX" paste-buffer -t "$SESSION" -d -p
43
- sleep 0.3
44
- "$TMUX" send-keys -t "$SESSION" Enter
18
+ "$OPENCODE" run --fork "$FULL_MSG" 2>&1 &
45
19
 
46
20
  echo "✅ New session started. Reply will arrive shortly."
@@ -1,31 +1,20 @@
1
1
  #!/bin/bash
2
- # bridge-version: 1
3
- # Send instruction to existing opencode-daemon tmux session
2
+ # bridge-version: 2
3
+ # Send instruction to OpenCode (non-interactive mode)
4
4
  MSG="$1"
5
- TMUX="{{TMUX_BIN}}"
5
+ OPENCODE="{{OPENCODE_BIN}}"
6
6
  CHANNEL="{{CHANNEL}}"
7
7
  TARGET="{{TARGET_ID}}"
8
- SESSION="{{SESSION_NAME}}"
8
+ WORKSPACE="{{WORKSPACE}}"
9
9
 
10
10
  if [ -z "$MSG" ]; then
11
11
  echo "ERROR: No message provided"
12
12
  exit 1
13
13
  fi
14
14
 
15
- # Check session exists
16
- if ! "$TMUX" has-session -t "$SESSION" 2>/dev/null; then
17
- echo "ERROR: $SESSION session not found. It will be auto-created within 30 seconds."
18
- exit 1
19
- fi
15
+ cd "$WORKSPACE"
16
+ FULL_MSG="[${CHANNEL}:${TARGET}] $MSG"
20
17
 
21
- # Clear input line, then send message with channel prefix
22
- "$TMUX" send-keys -t "$SESSION" C-c
23
- sleep 0.5
24
- "$TMUX" send-keys -t "$SESSION" C-u
25
- sleep 0.3
26
- printf '%s' "[${CHANNEL}:${TARGET}] $MSG" | "$TMUX" load-buffer -
27
- "$TMUX" paste-buffer -t "$SESSION" -d -p
28
- sleep 0.3
29
- "$TMUX" send-keys -t "$SESSION" Enter
18
+ "$OPENCODE" run --continue "$FULL_MSG" 2>&1 &
30
19
 
31
20
  echo "✅ Delivered to OpenCode. Reply will arrive shortly."
@@ -1,12 +1,10 @@
1
1
  #!/bin/bash
2
- # bridge-version: 3
3
- # Keep opencode-daemon tmux session alive (daemon runs every 30s)
4
- # Safe: idempotent, flock-protected (with fallback), short timeout
2
+ # bridge-version: 4
3
+ # Keep OpenCode server alive (runs every 30s via daemon)
4
+ # Safe: idempotent, flock-protected (with fallback)
5
5
 
6
- TMUX="{{TMUX_BIN}}"
7
6
  OPENCODE="{{OPENCODE_BIN}}"
8
7
  WORKSPACE="{{WORKSPACE}}"
9
- SESSION="{{SESSION_NAME}}"
10
8
  LOCK_FILE="/tmp/opencode-session.lock"
11
9
  TIMEOUT=10
12
10
 
@@ -15,7 +13,7 @@ if command -v flock &> /dev/null; then
15
13
  exec 200>"$LOCK_FILE"
16
14
  flock -w "$TIMEOUT" 200 || exit 0
17
15
  else
18
- # Fallback: simple PID lock (less robust but works without flock)
16
+ # Fallback: simple PID lock
19
17
  if [ -f "$LOCK_FILE" ]; then
20
18
  OLD_PID=$(cat "$LOCK_FILE" 2>/dev/null)
21
19
  if [ -n "$OLD_PID" ] && kill -0 "$OLD_PID" 2>/dev/null; then
@@ -25,13 +23,12 @@ else
25
23
  echo $$ > "$LOCK_FILE"
26
24
  fi
27
25
 
28
- # Idempotent: exit if session already exists
29
- if "$TMUX" has-session -t "$SESSION" 2>/dev/null; then
30
- exit 0
26
+ cd "$WORKSPACE"
27
+
28
+ # Start OpenCode in server mode if not running
29
+ if ! pgrep -f "opencode serve" > /dev/null 2>&1; then
30
+ "$OPENCODE" serve &
31
+ sleep 2
31
32
  fi
32
33
 
33
- # Create new session + start OpenCode
34
- "$TMUX" new-session -d -s "$SESSION"
35
- "$TMUX" set-option -t "$SESSION" history-limit 10000
36
- "$TMUX" send-keys -t "$SESSION" \
37
- "cd $WORKSPACE && $OPENCODE --continue" Enter
34
+ exit 0
@@ -1,6 +1,6 @@
1
1
  # OPENCODE.md
2
2
 
3
- ## Bot Mode (Top Priority Rule)
3
+ ## Bot Mode
4
4
 
5
5
  When a message starts with `[{CHANNEL}:{ID}]` prefix, you **MUST** follow this procedure.
6
6
 
@@ -8,13 +8,12 @@ When a message starts with `[{CHANNEL}:{ID}]` prefix, you **MUST** follow this p
8
8
 
9
9
  1. Extract `{CHANNEL}` and `{ID}` from the prefix
10
10
  2. Perform the task described after the prefix
11
- 3. **After completion, you MUST** send the response via:
11
+ 3. **After completion, send the response via:**
12
12
  ```bash
13
13
  openclaw message send --channel {CHANNEL} --target {ID} -m '🔗 response'
14
14
  ```
15
- 4. **Every message MUST start with 🔗** — this identifies you as OpenCode (not the gateway LLM)
16
- 5. Split into multiple messages if over 4000 characters (each part starts with 🔗)
17
- 6. Print `Sent` after transmission
15
+ 4. **Every message MUST start with 🔗** — this identifies you as OpenCode
16
+ 5. Split messages over 4000 characters into multiple sends (each starts with 🔗)
18
17
 
19
18
  ### Response transmission is mandatory (never skip)
20
19
 
@@ -22,20 +21,4 @@ openclaw message send --channel {CHANNEL} --target {ID} -m '🔗 response'
22
21
  - Regardless of success, failure, or error, you must always send the result.
23
22
  - Ending a turn without sending is **strictly forbidden**.
24
23
  - If the task failed, send the failure reason. If it succeeded, send the result.
25
- - If you did not run `openclaw message send`, the task is NOT complete.
26
-
27
- ### Self-check
28
-
29
- When completing a task, verify:
30
- - Did I run `openclaw message send`? -> If not, run it immediately now
31
- - Did I print `Sent`? -> If not, the transmission was missed
32
-
33
- ## Bridge Commands (Do NOT respond)
34
-
35
- Messages starting with `@cc`, `@ccn`, `@ccu`, `/cc`, `/ccn`, `/ccu` are handled by the opencode-bridge plugin.
36
- These are routed to a separate OpenCode session via tmux.
37
-
38
- **When you see a message starting with these prefixes, you MUST:**
39
- - Do NOT interpret, process, or respond to the message content
40
- - Output ONLY this exact text: 🔗 Delivered to OpenCode. Reply will arrive shortly.
41
- - Do NOT explain, translate, or add any other text
24
+ - If you did not run `openclaw message send`, the task is **NOT** complete.