fix: remove hardcoded /home/jchery paths, use __OPENCODE_DIR__ template token resolved at install time

Command markdown files now use __OPENCODE_DIR__ placeholder instead of
hardcoded user path. Both postinstall.js and install.sh perform template
replacement when copying files to ~/.config/opencode/, making CI portable
across any user/machine/container.
This commit is contained in:
CI
2026-05-29 16:08:46 +00:00
parent 940b85bfae
commit 7a20784c87
13 changed files with 39 additions and 21 deletions
+1 -1
View File
@@ -8,7 +8,7 @@ tools:
---
<execution_context>
@/home/jchery/.config/opencode/ci/workflows/audit.md
@__OPENCODE_DIR__/ci/workflows/audit.md
</execution_context>
<context>
+1 -1
View File
@@ -13,7 +13,7 @@ tools:
---
<execution_context>
@/home/jchery/.config/opencode/ci/workflows/clarify.md
@__OPENCODE_DIR__/ci/workflows/clarify.md
</execution_context>
<context>
+1 -1
View File
@@ -13,7 +13,7 @@ tools:
---
<execution_context>
@/home/jchery/.config/opencode/ci/workflows/debug.md
@__OPENCODE_DIR__/ci/workflows/debug.md
</execution_context>
<context>
+1 -1
View File
@@ -13,7 +13,7 @@ tools:
---
<execution_context>
@/home/jchery/.config/opencode/ci/workflows/init.md
@__OPENCODE_DIR__/ci/workflows/init.md
</execution_context>
<context>
+1 -1
View File
@@ -13,7 +13,7 @@ tools:
---
<execution_context>
@/home/jchery/.config/opencode/ci/workflows/quick.md
@__OPENCODE_DIR__/ci/workflows/quick.md
</execution_context>
<context>
+1 -1
View File
@@ -12,7 +12,7 @@ tools:
---
<execution_context>
@/home/jchery/.config/opencode/ci/workflows/review.md
@__OPENCODE_DIR__/ci/workflows/review.md
</execution_context>
<context>
+1 -1
View File
@@ -13,7 +13,7 @@ tools:
---
<execution_context>
@/home/jchery/.config/opencode/ci/workflows/rollback.md
@__OPENCODE_DIR__/ci/workflows/rollback.md
</execution_context>
<context>
+1 -1
View File
@@ -13,7 +13,7 @@ tools:
---
<execution_context>
@/home/jchery/.config/opencode/ci/workflows/run.md
@__OPENCODE_DIR__/ci/workflows/run.md
</execution_context>
<context>
+1 -1
View File
@@ -12,7 +12,7 @@ tools:
---
<execution_context>
@/home/jchery/.config/opencode/ci/workflows/ship.md
@__OPENCODE_DIR__/ci/workflows/ship.md
</execution_context>
<context>
+1 -1
View File
@@ -8,7 +8,7 @@ tools:
---
<execution_context>
@/home/jchery/.config/opencode/ci/workflows/status.md
@__OPENCODE_DIR__/ci/workflows/status.md
</execution_context>
<context>
+1 -1
View File
@@ -12,7 +12,7 @@ tools:
---
<execution_context>
@/home/jchery/.config/opencode/ci/workflows/verify.md
@__OPENCODE_DIR__/ci/workflows/verify.md
</execution_context>
<context>
+6 -3
View File
@@ -70,7 +70,7 @@ copy_file() {
return
fi
cp "$src" "$dest"
sed "s|__OPENCODE_DIR__|${OPENCODE_DIR}|g" "$src" > "$dest"
COPIED=$((COPIED + 1))
}
@@ -109,14 +109,16 @@ CI_JSON="${CI_DIR}/opencode.json"
if [ -f "$CI_JSON" ]; then
if [ ! -f "$OPENCODE_JSON" ]; then
cp "$CI_JSON" "$OPENCODE_JSON"
sed "s|__OPENCODE_DIR__|${OPENCODE_DIR}|g" "$CI_JSON" > "$OPENCODE_JSON"
echo " Created opencode.json"
else
if command -v node &>/dev/null; then
local_ci_json="$(sed "s|__OPENCODE_DIR__|${OPENCODE_DIR}|g" "$CI_JSON")"
echo "$local_ci_json" > /tmp/ci-json-merge.json
node -e "
const fs = require('fs');
const existing = JSON.parse(fs.readFileSync('${OPENCODE_JSON}', 'utf8'));
const ci = JSON.parse(fs.readFileSync('${CI_JSON}', 'utf8'));
const ci = JSON.parse(fs.readFileSync('/tmp/ci-json-merge.json', 'utf8'));
const merged = { ...existing };
merged.permission = merged.permission || {};
merged.permission.read = merged.permission.read || {};
@@ -130,6 +132,7 @@ if [ -f "$CI_JSON" ]; then
fs.writeFileSync('${OPENCODE_JSON}', JSON.stringify(merged, null, 2));
console.log(' Merged permissions (preserved existing entries)');
"
rm -f /tmp/ci-json-merge.json
else
echo " Warning: node not found. Manually merge opencode.json permissions."
echo " Add to opencode.json:"
+22 -7
View File
@@ -20,7 +20,7 @@ function isGlobalInstall() {
return false;
}
function copyFile(src, dest, force) {
function copyFile(src, dest, force, templateVars) {
if (!fs.existsSync(src)) return { copied: 0, skipped: 0 };
const dir = path.dirname(dest);
@@ -28,17 +28,27 @@ function copyFile(src, dest, force) {
if (fs.existsSync(dest) && !force) {
try {
const srcContent = fs.readFileSync(src, "utf8");
const srcContent = applyTemplate(fs.readFileSync(src, "utf8"), templateVars);
const destContent = fs.readFileSync(dest, "utf8");
if (srcContent === destContent) return { copied: 0, skipped: 1 };
} catch {}
return { copied: 0, skipped: 1 };
}
fs.copyFileSync(src, dest);
const content = applyTemplate(fs.readFileSync(src, "utf8"), templateVars);
fs.writeFileSync(dest, content, "utf8");
return { copied: 1, skipped: 0 };
}
function applyTemplate(content, vars) {
if (!vars) return content;
let result = content;
for (const [key, value] of Object.entries(vars)) {
result = result.replaceAll(key, value);
}
return result;
}
function install() {
const pkgDir = getPackageDir();
if (!pkgDir) {
@@ -58,6 +68,10 @@ function install() {
return;
}
const templateVars = {
__OPENCODE_DIR__: OPENCODE_DIR,
};
let copied = 0;
let skipped = 0;
@@ -68,7 +82,7 @@ function install() {
return f.startsWith(pattern);
});
for (const entry of entries) {
const result = copyFile(path.join(srcDir, entry), path.join(destDir, entry), false);
const result = copyFile(path.join(srcDir, entry), path.join(destDir, entry), false, templateVars);
copied += result.copied;
skipped += result.skipped;
}
@@ -88,7 +102,7 @@ function install() {
const versionFile = path.join(opencodeDir, "ci", "VERSION");
if (fs.existsSync(versionFile)) {
const result = copyFile(versionFile, path.join(OPENCODE_DIR, "ci", "VERSION"), false);
const result = copyFile(versionFile, path.join(OPENCODE_DIR, "ci", "VERSION"), false, templateVars);
copied += result.copied;
skipped += result.skipped;
}
@@ -98,11 +112,12 @@ function install() {
if (fs.existsSync(ciJsonPath)) {
if (!fs.existsSync(targetJsonPath)) {
fs.copyFileSync(ciJsonPath, targetJsonPath);
const content = applyTemplate(fs.readFileSync(ciJsonPath, "utf8"), templateVars);
fs.writeFileSync(targetJsonPath, content, "utf8");
} else {
try {
const existing = JSON.parse(fs.readFileSync(targetJsonPath, "utf8"));
const ciJson = JSON.parse(fs.readFileSync(ciJsonPath, "utf8"));
const ciJson = JSON.parse(applyTemplate(fs.readFileSync(ciJsonPath, "utf8"), templateVars));
existing.permission = existing.permission || {};
existing.permission.read = existing.permission.read || {};
existing.permission.external_directory = existing.permission.external_directory || {};