Imported from yuji-hatakeyama/opencode-gpt-imagegen (
AGENTS.md). Install upstream withnpx skills add yuji-hatakeyama/opencode-gpt-imagegen. Copyright stays with the author.
AGENTS.md
Project Shape
- Bun is the package manager/runtime; use
bun install --frozen-lockfilewith the committedbun.lock. - The plugin entry is
src/index.ts(plugin wiring + tool schema); helpers live in role-based modules —src/types.ts(shared types),src/auth.ts(auth resolution),src/input-image.ts(reference image reading),src/output-image.ts(non-overwriting save + message),src/codex.ts(Codex backend call + SSE parsing). bun run buildbundlessrcinto a single self-containeddist/index.jsviabun build --target node --format esm --packages external(dependencies, including the@opencode-ai/pluginpeer dep, stay external). Bundling avoids the extensionless relative importstscwould emit, which native Node ESM cannot resolve. No.d.tsis published — the plugin is loaded by OpenCode at runtime, not imported as a typed library.dist/is ignored locally but is the publish artifact (justindex.js). Runbun run buildbefore inspecting package output.bunfig.tomlenforcesinstall.minimumReleaseAge = 604800(1 week): newly published versions are filtered out bybun install/bun add/bun outdated.
Commands
- Tests are split by kind:
tests/unit/(helper-module unit tests) andtests/e2e/(one file per auth path, e.g.subscription.test.ts). bun run typecheckrunstsc --noEmitoversrcandtests.bunx biome ci .is the CI formatter/linter check.bun run checkrunsbiome check --write .; it may modify files.bun run testrunsbun test tests/unit— unit tests only, and is what CI uses. (A barebun testwould also discover the e2e files undertests/e2e/and try to run them for real, so prefer the script.)bun run test:e2e_subscriptionsetsOPENCODE_MODEL=openai/gpt-5.5and runstests/e2e/subscription.test.ts(ChatGPT subscription / OAuth path). It can take minutes because it callsopencode runand generates real images. The future API-key path gets its owntest:e2e_apikeyscript +tests/e2e/apikey.test.ts.- Each e2e path is its own script (its own
bun testprocess), which also avoids the unit-testprocess.envleak into the single-process e2eopencodespawn. - CI runs
bun run typecheck,bunx biome ci ., andbun run test. The e2e suites are not run in CI's default checks (they need real auth + generations); they are invoked separately via theirtest:e2e_*scripts.
E2E Requirements
tests/e2e.test.tsshells out to theopencodeCLI with--dangerously-skip-permissionsin a temporary workdir.- E2E requires OpenCode to be authenticated with ChatGPT OAuth; the plugin reads
OPENCODE_AUTH_CONTENTfirst, then$XDG_DATA_HOME/opencode/auth.json. - The e2e tests assert that produced files are valid PNGs and cover the plugin's output auto-versioning behavior.
Implementation Notes
- The exposed tool is
gpt_imagegen; it calls the ChatGPT Codex responses endpoint with the hostedimage_generationtool. - Output paths are resolved relative to the OpenCode context directory unless absolute, and existing files are never overwritten; suffixes
-v2through-v999are tried. - Reference images are read from paths relative to the OpenCode context directory and are embedded as data URLs after MIME detection.
Publishing
package.jsonfilesintentionally publishes onlydist,README.md, andLICENSE.prepublishOnlyrunsbun run build, sonpm publishalways rebuildsdist/first.- Release flow: run
bun run release:patch(or:minor/:major) on a cleanmain. The npm script chainsscripts/prepare-release.sh <level>(preflight, diff review, version bump) withgit push --follow-tags. The shell script checks the working tree is clean and in sync withorigin/main, prints the commits since the previous tag along with a GitHub compare URL for diff review, asks for confirmation, and runsnpm version <level>to create thechore: release X.Y.Zcommit andvX.Y.Ztag locally; the push happens only on success. - The tag push triggers
.github/workflows/release.yml, which runsnpm publish --provenance --access publicvia npm OIDC trusted publisher (noNPM_TOKENsecret) and creates a GitHub release with auto-generated notes. The npm package must have GitHub Actions registered as a trusted publisher on npmjs.com for OIDC to work.