Skip to content

Commit a6c81bf

Browse files
committed
fix(lib): refactor opencode entrypoint template
1 parent 54ed9ac commit a6c81bf

1 file changed

Lines changed: 18 additions & 14 deletions

File tree

packages/lib/src/core/templates-entrypoint/opencode.ts

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,13 @@
11
import type { TemplateConfig } from "../domain.js"
22

3-
// CHANGE: bootstrap OpenCode config (permissions + plugins) and share OpenCode auth.json across projects
4-
// WHY: make OpenCode usable out-of-the-box inside disposable docker-git containers
5-
// QUOTE(ТЗ): "Preinstall OpenCode and oh-my-opencode with full authorization of existing tools"
6-
// REF: issue-34
7-
// SOURCE: n/a
8-
// FORMAT THEOREM: forall s: start(s) -> config_exists(s)
9-
// PURITY: CORE
10-
// INVARIANT: never overwrites an existing opencode.json/opencode.jsonc
11-
// COMPLEXITY: O(1)
12-
export const renderEntrypointOpenCodeConfig = (config: TemplateConfig): string =>
13-
`# OpenCode: share auth.json across projects (so /connect is one-time)
3+
const entrypointOpenCodeTemplate = `# OpenCode: share auth.json across projects (so /connect is one-time)
144
OPENCODE_SHARE_AUTH="\${OPENCODE_SHARE_AUTH:-1}"
155
if [[ "$OPENCODE_SHARE_AUTH" == "1" ]]; then
16-
OPENCODE_DATA_DIR="/home/${config.sshUser}/.local/share/opencode"
6+
OPENCODE_DATA_DIR="/home/__SSH_USER__/.local/share/opencode"
177
OPENCODE_AUTH_FILE="$OPENCODE_DATA_DIR/auth.json"
188
199
# Store in the shared auth volume to persist across projects/containers.
20-
OPENCODE_SHARED_HOME="${config.codexHome}-shared/opencode"
10+
OPENCODE_SHARED_HOME="__CODEX_HOME__-shared/opencode"
2111
OPENCODE_SHARED_AUTH_FILE="$OPENCODE_SHARED_HOME/auth.json"
2212
2313
mkdir -p "$OPENCODE_DATA_DIR" "$OPENCODE_SHARED_HOME"
@@ -59,7 +49,7 @@ NODE
5949
fi
6050
6151
# OpenCode: ensure global config exists (plugins + permissions)
62-
OPENCODE_CONFIG_DIR="/home/${config.sshUser}/.config/opencode"
52+
OPENCODE_CONFIG_DIR="/home/__SSH_USER__/.config/opencode"
6353
OPENCODE_CONFIG_JSON="$OPENCODE_CONFIG_DIR/opencode.json"
6454
OPENCODE_CONFIG_JSONC="$OPENCODE_CONFIG_DIR/opencode.jsonc"
6555
@@ -85,3 +75,17 @@ if [[ ! -f "$OPENCODE_CONFIG_JSON" && ! -f "$OPENCODE_CONFIG_JSONC" ]]; then
8575
EOF
8676
chown 1000:1000 "$OPENCODE_CONFIG_JSON" || true
8777
fi`
78+
79+
// CHANGE: bootstrap OpenCode config (permissions + plugins) and share OpenCode auth.json across projects
80+
// WHY: make OpenCode usable out-of-the-box inside disposable docker-git containers
81+
// QUOTE(ТЗ): "Preinstall OpenCode and oh-my-opencode with full authorization of existing tools"
82+
// REF: issue-34
83+
// SOURCE: n/a
84+
// FORMAT THEOREM: forall s: start(s) -> config_exists(s)
85+
// PURITY: CORE
86+
// INVARIANT: never overwrites an existing opencode.json/opencode.jsonc
87+
// COMPLEXITY: O(1)
88+
export const renderEntrypointOpenCodeConfig = (config: TemplateConfig): string =>
89+
entrypointOpenCodeTemplate
90+
.replaceAll("__SSH_USER__", config.sshUser)
91+
.replaceAll("__CODEX_HOME__", config.codexHome)

0 commit comments

Comments
 (0)