fix: use ${GITEA_TOKEN:-} to handle unset token #193

Merged
shoko merged 4 commits from fix/issue-cmd-destroy-unbound-var into main 2026-04-07 02:41:18 +02:00
Owner

Bug

With set -u enabled, expanding $GITEA_TOKEN fails if the variable is not set:

nohup sh -c "GITEA_TOKEN='$GITEA_TOKEN' opencode run ..."
# Error: GITEA_TOKEN: unbound variable

This caused cmd_start to appear to succeed (worktree created, session created) but the agent never actually ran because the fork command failed.

Fix

Changed all 4 GITEA_TOKEN usages to use ${GITEA_TOKEN:-} pattern:

nohup sh -c "GITEA_TOKEN='${GITEA_TOKEN:-}' opencode run ..."

This provides an empty string default if GITEA_TOKEN is not set, allowing the command to proceed.

Files Changed

  • kugetsu-session.sh: lines 198, 317, 372, 374
## Bug With `set -u` enabled, expanding `$GITEA_TOKEN` fails if the variable is not set: ```bash nohup sh -c "GITEA_TOKEN='$GITEA_TOKEN' opencode run ..." # Error: GITEA_TOKEN: unbound variable ``` This caused `cmd_start` to appear to succeed (worktree created, session created) but the agent never actually ran because the fork command failed. ## Fix Changed all 4 GITEA_TOKEN usages to use `${GITEA_TOKEN:-}` pattern: ```bash nohup sh -c "GITEA_TOKEN='${GITEA_TOKEN:-}' opencode run ..." ``` This provides an empty string default if GITEA_TOKEN is not set, allowing the command to proceed. ## Files Changed - `kugetsu-session.sh`: lines 198, 317, 372, 374
shoko added 1 commit 2026-04-06 11:43:00 +02:00
With set -u, expanding $GITEA_TOKEN fails if not set.
Changed to ${GITEA_TOKEN:-} to provide empty default.
This fixes the issue where cmd_start appears to succeed but agent never runs.
shoko force-pushed fix/issue-cmd-destroy-unbound-var from 1a8c64c0a8 to 860bf9295f 2026-04-06 11:45:22 +02:00 Compare
shoko added 1 commit 2026-04-07 02:13:12 +02:00
- Add create_session() function that forks from base session using JSON session detection
- cmd_delegate: fork new session from base instead of using pm_agent
- cmd_start: use create_session() instead of broken before/after detection
- cmd_continue: use --session instead of --continue (no need to continue existing session)
- Remove pm_agent check from cmd_start (no longer needed)
shoko added 1 commit 2026-04-07 02:24:10 +02:00
Tests run sequentially to avoid memory exhaustion with too many opencode sessions:
- JSON session list parsing
- Session ID format validation
- create_session returns valid session ID
- create_session creates NEW session (different from base)
- create_session creates different sessions on multiple calls
- create_session accepts optional base session parameter
- Created session visible in opencode session list
shoko added 1 commit 2026-04-07 02:35:47 +02:00
The index.json was getting corrupted (ending with 'issues: }' instead of 'issues: {}').
Added validation that checks if the JSON is valid before moving the temp file.
If invalid, the write is aborted with an error message showing the problematic values.
shoko force-pushed fix/issue-cmd-destroy-unbound-var from 8ba7242861 to 998f7a4f44 2026-04-07 02:39:54 +02:00 Compare
shoko merged commit 8729321922 into main 2026-04-07 02:41:18 +02:00
Sign in to join this conversation.