opencode-multi-account-core 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +57 -0
  2. package/dist/index.js +1798 -0
  3. package/package.json +56 -0
package/README.md ADDED
@@ -0,0 +1,57 @@
1
+ # multi-account-core
2
+
3
+ Shared core logic for multi-account OpenCode plugins. This package contains ~70% of the logic used by both [`anthropic-multi-account`](../anthropic-multi-account) and [`codex-multi-account`](../codex-multi-account).
4
+
5
+ ## What's inside
6
+
7
+ | Module | What it does |
8
+ |:-------|:-------------|
9
+ | AccountStore | Single write path. Serializes all disk mutations through file locking. |
10
+ | AccountManager | In-memory account cache and selection strategies (sticky, round-robin, hybrid). Created via `createAccountManagerForProvider`. |
11
+ | Executor | Retry loop with account rotation on auth and rate-limit failures. Created via `createExecutorForProvider`. |
12
+ | Claims | Cross-process coordination via claim files with zombie detection. |
13
+ | Storage | Atomic file read/write with `proper-lockfile`. |
14
+ | RateLimit | Per-account rate-limit tracking with configurable backoff. Created via `createRateLimitTrackerForProvider`. |
15
+ | ProactiveRefreshQueue | Background token refresh before expiry. Created via `createProactiveRefreshForProvider`. |
16
+ | Config | Plugin configuration loading and validation with valibot. Created via `createConfigLoaderForProvider`. |
17
+ | AuthMigration | One-time import of existing single-account OAuth creds from OpenCode's `auth.json`. |
18
+ | UI | Terminal UI primitives (ANSI formatting, confirm dialogs, select menus). |
19
+ | Utils | Config directory resolution, formatting helpers. |
20
+
21
+ ## Usage
22
+
23
+ This package is not intended to be used directly. It is a dependency of the provider-specific plugin packages. Each module exposes a factory function that accepts provider-specific config (endpoints, client IDs, plan labels) and returns a ready-to-use instance.
24
+
25
+ ```ts
26
+ import { createAccountManagerForProvider } from "opencode-multi-account-core";
27
+
28
+ export const AccountManager = createAccountManagerForProvider({
29
+ refreshTokenFn: myRefreshToken,
30
+ isTokenExpiredFn: myIsTokenExpired,
31
+ });
32
+ ```
33
+
34
+ ## Architecture
35
+
36
+ ```
37
+ ┌─────────────────────────────────────────────────┐
38
+ │ anthropic-multi-account / codex-multi-account │
39
+ │ (provider-specific: auth, usage, transforms) │
40
+ ├─────────────────────────────────────────────────┤
41
+ │ multi-account-core ← you are here │
42
+ │ AccountStore . AccountManager . Executor │
43
+ │ Claims . Storage . RateLimit . ProactiveRefresh │
44
+ │ AuthMigration . Config . Utils . UI │
45
+ ├─────────────────────────────────────────────────┤
46
+ │ oauth-adapters │
47
+ │ (endpoints, client IDs, plan labels) │
48
+ └─────────────────────────────────────────────────┘
49
+ ```
50
+
51
+ ## Safety guarantees
52
+
53
+ - All disk mutations go through AccountStore with file locking
54
+ - Atomic writes via temp-file-then-rename
55
+ - Concurrent token refresh requests for the same account are deduplicated
56
+ - Circuit breaker: an account is only auto-disabled when at least one other remains usable
57
+ - Dead process claims are automatically released