Skip to content
Merged
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ The setup command detects OpenCode and Pi, registers the plugin, and offers a co

Then start OpenCode and run `/openai`.

On OpenCode 2, sign in once more: run `opencode auth login openai` and choose **ChatGPT (openai-auth pool, browser)** or **(headless)**, or use **Vault → Connect** in `/openai` on a host that uses only the vault. Do this after an upgrade from OpenCode 1 too, because OpenCode 2.3 and later import OpenCode 1's sign-in, which the plugin can't use. See [Signing in](docs/opencode-2.md#signing-in).

## Shared limit policy

In `/openai`, **Routing → Longest wait on the same account** offers **Don't wait**, **15 minutes** (the default), and **Until the cache expires**. A wait needs a confirmed reset and usable cache evidence; an unknown reset does not justify holding the account. The killswitch and credential checks still apply, and the killswitch can prevent a same-account wait.
Expand Down
8 changes: 4 additions & 4 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ On OpenCode, `log_level` accepts `"error"`, `"warn"`, `"info"`, `"debug"`, `"tra
| Environment variable | Purpose |
| --- | --- |
| `OPENCODE_OPENAI_AUTH_FILE` | Full path of the config file, which also holds the account store. |
| `OPENCODE_OPENAI_AUTH_STATE_FILE` | Full path of the account state file. The vault folder `openai-auth-vault/` sits next to it. By default the state file is `openai-auth-state.json` in the plugin's state folder (see [Where the files live](#where-the-files-live)). When `OPENCODE_OPENAI_AUTH_FILE` names a custom config file, the default is `<config file>.state.json` next to it, or `openai-auth-state.json` when the custom file is named `openai-auth.json`. The plugin never moves a state file you name here. It must not be the config file itself. |
| `OPENCODE_OPENAI_AUTH_STATE_FILE` | Full path of the account state file. The vault folder `openai-auth-vault/` sits next to it. By default the state file is `openai-auth-state.json` in the plugin's state folder (see [Where the files live](#where-the-files-live)). When `OPENCODE_OPENAI_AUTH_FILE` names a custom config file, the default is `<config file>.state.json` next to it, or `openai-auth-state.json` when the custom file is named `openai-auth.json`. The plugin never moves a state file you name here. It must not be the config file itself. After the runtime-file move, the old default path in OpenCode's config folder can point to a vault with only leftover enrollment state and no token; remove the override or point it at the state file in the runtime folder. |
| `OPENCODE_CONFIG_DIR`, `XDG_CONFIG_HOME` | Where the config directory is, as for OpenCode itself. |
| `XDG_STATE_HOME` | Base of the plugin's state folder; `~/.local/state` when unset. |
| `OPENCODE_OPENAI_AUTH_LOG_LEVEL`, `OPENCODE_OPENAI_AUTH_LOG_FILE` | Log level and log file; see [Troubleshooting](troubleshooting.md#logging). |
Expand Down Expand Up @@ -167,7 +167,7 @@ The plugin's state folder is `cortexkit/openai-auth` under `XDG_STATE_HOME`, or

Each runtime folder holds `config-dir.json`, which names the config folder it belongs to. If it names a different one, the plugin refuses to start and leaves the folder alone. The plugin creates these folders and files owner-only: mode `0700` for folders and `0600` for files on Linux and macOS, and an access list that grants only your user on Windows.

`OPENCODE_OPENAI_AUTH_STATE_FILE`, and a custom config file named by `OPENCODE_OPENAI_AUTH_FILE`, keep the state file and its vault folder where they say (see the table above), and the plugin never moves or deletes them.
`OPENCODE_OPENAI_AUTH_STATE_FILE`, and a custom config file named by `OPENCODE_OPENAI_AUTH_FILE`, keep the state file and its vault folder where they say (see the table above), and the plugin never moves or deletes them. After the move, an explicit state-file override to the old default in OpenCode's config folder still selects the old vault folder. If that folder contains only the enrollment state the move left behind and the enrolled vault is in the runtime folder, startup refuses with both paths. Remove `OPENCODE_OPENAI_AUTH_STATE_FILE` or set it to `openai-auth-state.json` in the runtime folder.

### The move from OpenCode's config folder

Expand All @@ -177,7 +177,7 @@ Only an OpenCode started without `OPENCODE_OPENAI_AUTH_STATE_FILE` and without a

The move waits while any other OpenCode process could still write the old files, because a sign-in token written to the old folder after the move would be lost. Such a process is one running an older version of the plugin, or one that started while such a process was running. While the move waits, the plugin keeps using the old files and logs once: "openai-auth keeps its files in OpenCode's config folder until every running OpenCode using it has restarted on this version." A process that starts while the move must wait also keeps the old files for its whole life, so restarting OpenCode processes one at a time can keep the move waiting. **To let it happen, close every OpenCode on the machine, then start OpenCode again.** Only OpenCode moves these files; Pi keeps its own files where they are.

If the move fails before writing `layout.json`, for example because the disk is full, the plugin keeps using the old files, logs the error once, and tries again at the next start. If it cannot record that it uses the old files, or cannot use or read its state folder at all, it refuses to start and names the folder and the error, rather than run where other OpenCode processes cannot see it. A malformed `layout.json` also refuses the start: the copies cannot be trusted. The refusal names the marker path and asks you to delete `layout.json` and restart OpenCode. Before doing so, check that the old runtime files are still in OpenCode's config folder. A marker damaged after completed cleanup does not prove the old files remain; keep the runtime folder intact if no old copies exist.
If the move fails before writing `layout.json`, for example because the disk is full, the plugin keeps using the old files, logs the error once, and tries again at the next start. If it cannot record that it uses the old files, or cannot use or read its state folder at all, it refuses to start and names the folder and the error, rather than run where other OpenCode processes cannot see it. A damaged or unrecognised `layout.json` also refuses the start. If the runtime folder holds runtime files, keep them in place and restore a backup of `layout.json` for that OpenCode config folder before restarting. Do not delete the marker: the next start could use the old folder instead. The plugin tells you to delete the marker and restart only if it finds no runtime files in the runtime folder.

After the marker is written, an old state file or any vault file whose bytes differ from its new copy is a credential conflict, both during the move's cleanup and when a later start retries cleanup. An old credential file that matches its copy but cannot be removed yet (on Windows, another program may still have it open) is logged once, and the next start tries the removal again. An old state or vault file that reappears after a finished move is also a conflict, even if its bytes match. The one exception is the vault enrollment state file of an approved enrollment: the move removes the old token but leaves that file in the old vault folder, byte for byte as it moved. Later starts accept that file there as long as it still says this OpenCode's enrollment is approved, or blocked only because its token is missing, and no token file is in the old vault folder. An older version that runs after the move rewrites the file that way, and the file holds no secret. Anything else there, such as an enrollment request in progress, a file that cannot be read as an enrollment state, another enrollment's name, or a token file next to it, is a conflict. Disconnect removes the file. The plugin refuses to start and names both paths: keep the newer one, delete the other, and restart OpenCode. It never merges the copies or chooses by timestamp: the old copy may hold the only live successor to a single-use OAuth refresh token. A file named by this process's override remains its own and is not a conflict. Differing or reappeared session files are left alone with a warning; reappeared sessions are also shown once in the Diagnostics section of `/openai`.

Expand All @@ -192,7 +192,7 @@ A version from before the move looks only in OpenCode's config folder, so after
- move `openai-auth-state.json`, `openai-auth-vault/` and the sessions files from the runtime folder back into OpenCode's config folder, and delete `layout.json` from the runtime folder so a later upgrade moves them again;
- or set `OPENCODE_OPENAI_AUTH_STATE_FILE` to the state file in the runtime folder, for example `~/.local/state/cortexkit/openai-auth/opencode/openai-auth-state.json`. The older version then reads the state file and the vault folder from there.

Close every OpenCode process before switching versions or moving credentials. Do not run an older version against the old copies while a newer version uses the runtime folder: refreshing either copy can spend the token held by the other. If the old version recreates the state file or vault files in the config folder, a later upgrade refuses to start until you resolve the two-path conflict above. Delete `layout.json` only for the explicit move-back procedure or the malformed-marker recovery, not to bypass a credential conflict.
Close every OpenCode process before switching versions or moving credentials. Do not run an older version against the old copies while a newer version uses the runtime folder: refreshing either copy can spend the token held by the other. If the old version recreates the state file or vault files in the config folder, a later upgrade refuses to start until you resolve the two-path conflict above. Delete `layout.json` only for the explicit move-back procedure or when the damaged-marker message says there are no runtime files in the runtime folder, not to bypass a credential conflict.

## Pi

Expand Down
Loading
Loading