oc-codex-multi-auth 6.0.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.
- package/LICENSE +21 -0
- package/README.md +162 -0
- package/assets/opencode-logo-ornate-dark.svg +18 -0
- package/assets/readme-hero.svg +31 -0
- package/config/README.md +96 -0
- package/config/minimal-opencode.json +13 -0
- package/config/opencode-legacy.json +871 -0
- package/config/opencode-modern.json +358 -0
- package/dist/index.d.ts +45 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5008 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/accounts/rate-limits.d.ts +22 -0
- package/dist/lib/accounts/rate-limits.d.ts.map +1 -0
- package/dist/lib/accounts/rate-limits.js +63 -0
- package/dist/lib/accounts/rate-limits.js.map +1 -0
- package/dist/lib/accounts.d.ts +134 -0
- package/dist/lib/accounts.d.ts.map +1 -0
- package/dist/lib/accounts.js +795 -0
- package/dist/lib/accounts.js.map +1 -0
- package/dist/lib/audit.d.ts +45 -0
- package/dist/lib/audit.d.ts.map +1 -0
- package/dist/lib/audit.js +154 -0
- package/dist/lib/audit.js.map +1 -0
- package/dist/lib/auth/auth.d.ts +51 -0
- package/dist/lib/auth/auth.d.ts.map +1 -0
- package/dist/lib/auth/auth.js +191 -0
- package/dist/lib/auth/auth.js.map +1 -0
- package/dist/lib/auth/browser.d.ts +17 -0
- package/dist/lib/auth/browser.d.ts.map +1 -0
- package/dist/lib/auth/browser.js +90 -0
- package/dist/lib/auth/browser.js.map +1 -0
- package/dist/lib/auth/device-code.d.ts +28 -0
- package/dist/lib/auth/device-code.d.ts.map +1 -0
- package/dist/lib/auth/device-code.js +215 -0
- package/dist/lib/auth/device-code.js.map +1 -0
- package/dist/lib/auth/login-runner.d.ts +55 -0
- package/dist/lib/auth/login-runner.d.ts.map +1 -0
- package/dist/lib/auth/login-runner.js +631 -0
- package/dist/lib/auth/login-runner.js.map +1 -0
- package/dist/lib/auth/server.d.ts +10 -0
- package/dist/lib/auth/server.d.ts.map +1 -0
- package/dist/lib/auth/server.js +98 -0
- package/dist/lib/auth/server.js.map +1 -0
- package/dist/lib/auth/token-utils.d.ts +60 -0
- package/dist/lib/auth/token-utils.d.ts.map +1 -0
- package/dist/lib/auth/token-utils.js +416 -0
- package/dist/lib/auth/token-utils.js.map +1 -0
- package/dist/lib/auth-rate-limit.d.ts +20 -0
- package/dist/lib/auth-rate-limit.d.ts.map +1 -0
- package/dist/lib/auth-rate-limit.js +91 -0
- package/dist/lib/auth-rate-limit.js.map +1 -0
- package/dist/lib/auto-update-checker.d.ts +10 -0
- package/dist/lib/auto-update-checker.d.ts.map +1 -0
- package/dist/lib/auto-update-checker.js +129 -0
- package/dist/lib/auto-update-checker.js.map +1 -0
- package/dist/lib/circuit-breaker.d.ts +34 -0
- package/dist/lib/circuit-breaker.d.ts.map +1 -0
- package/dist/lib/circuit-breaker.js +124 -0
- package/dist/lib/circuit-breaker.js.map +1 -0
- package/dist/lib/cli.d.ts +46 -0
- package/dist/lib/cli.d.ts.map +1 -0
- package/dist/lib/cli.js +192 -0
- package/dist/lib/cli.js.map +1 -0
- package/dist/lib/config.d.ts +42 -0
- package/dist/lib/config.d.ts.map +1 -0
- package/dist/lib/config.js +314 -0
- package/dist/lib/config.js.map +1 -0
- package/dist/lib/constants.d.ts +90 -0
- package/dist/lib/constants.d.ts.map +1 -0
- package/dist/lib/constants.js +90 -0
- package/dist/lib/constants.js.map +1 -0
- package/dist/lib/context-overflow.d.ts +27 -0
- package/dist/lib/context-overflow.d.ts.map +1 -0
- package/dist/lib/context-overflow.js +124 -0
- package/dist/lib/context-overflow.js.map +1 -0
- package/dist/lib/errors.d.ts +113 -0
- package/dist/lib/errors.d.ts.map +1 -0
- package/dist/lib/errors.js +103 -0
- package/dist/lib/errors.js.map +1 -0
- package/dist/lib/health.d.ts +33 -0
- package/dist/lib/health.d.ts.map +1 -0
- package/dist/lib/health.js +70 -0
- package/dist/lib/health.js.map +1 -0
- package/dist/lib/index.d.ts +20 -0
- package/dist/lib/index.d.ts.map +1 -0
- package/dist/lib/index.js +20 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/lib/logger.d.ts +40 -0
- package/dist/lib/logger.d.ts.map +1 -0
- package/dist/lib/logger.js +337 -0
- package/dist/lib/logger.js.map +1 -0
- package/dist/lib/oauth-success.html +712 -0
- package/dist/lib/parallel-probe.d.ts +28 -0
- package/dist/lib/parallel-probe.d.ts.map +1 -0
- package/dist/lib/parallel-probe.js +97 -0
- package/dist/lib/parallel-probe.js.map +1 -0
- package/dist/lib/proactive-refresh.d.ts +67 -0
- package/dist/lib/proactive-refresh.d.ts.map +1 -0
- package/dist/lib/proactive-refresh.js +161 -0
- package/dist/lib/proactive-refresh.js.map +1 -0
- package/dist/lib/prompts/codex-opencode-bridge.d.ts +20 -0
- package/dist/lib/prompts/codex-opencode-bridge.d.ts.map +1 -0
- package/dist/lib/prompts/codex-opencode-bridge.js +126 -0
- package/dist/lib/prompts/codex-opencode-bridge.js.map +1 -0
- package/dist/lib/prompts/codex.d.ts +41 -0
- package/dist/lib/prompts/codex.d.ts.map +1 -0
- package/dist/lib/prompts/codex.js +400 -0
- package/dist/lib/prompts/codex.js.map +1 -0
- package/dist/lib/prompts/opencode-codex.d.ts +25 -0
- package/dist/lib/prompts/opencode-codex.d.ts.map +1 -0
- package/dist/lib/prompts/opencode-codex.js +223 -0
- package/dist/lib/prompts/opencode-codex.js.map +1 -0
- package/dist/lib/recovery/constants.d.ts +12 -0
- package/dist/lib/recovery/constants.d.ts.map +1 -0
- package/dist/lib/recovery/constants.js +25 -0
- package/dist/lib/recovery/constants.js.map +1 -0
- package/dist/lib/recovery/index.d.ts +12 -0
- package/dist/lib/recovery/index.d.ts.map +1 -0
- package/dist/lib/recovery/index.js +12 -0
- package/dist/lib/recovery/index.js.map +1 -0
- package/dist/lib/recovery/storage.d.ts +24 -0
- package/dist/lib/recovery/storage.d.ts.map +1 -0
- package/dist/lib/recovery/storage.js +362 -0
- package/dist/lib/recovery/storage.js.map +1 -0
- package/dist/lib/recovery/types.d.ts +116 -0
- package/dist/lib/recovery/types.d.ts.map +1 -0
- package/dist/lib/recovery/types.js +7 -0
- package/dist/lib/recovery/types.js.map +1 -0
- package/dist/lib/recovery.d.ts +31 -0
- package/dist/lib/recovery.d.ts.map +1 -0
- package/dist/lib/recovery.js +313 -0
- package/dist/lib/recovery.js.map +1 -0
- package/dist/lib/refresh-queue.d.ts +131 -0
- package/dist/lib/refresh-queue.d.ts.map +1 -0
- package/dist/lib/refresh-queue.js +297 -0
- package/dist/lib/refresh-queue.js.map +1 -0
- package/dist/lib/request/fetch-helpers.d.ts +142 -0
- package/dist/lib/request/fetch-helpers.d.ts.map +1 -0
- package/dist/lib/request/fetch-helpers.js +749 -0
- package/dist/lib/request/fetch-helpers.js.map +1 -0
- package/dist/lib/request/helpers/input-utils.d.ts +7 -0
- package/dist/lib/request/helpers/input-utils.d.ts.map +1 -0
- package/dist/lib/request/helpers/input-utils.js +214 -0
- package/dist/lib/request/helpers/input-utils.js.map +1 -0
- package/dist/lib/request/helpers/model-map.d.ts +22 -0
- package/dist/lib/request/helpers/model-map.d.ts.map +1 -0
- package/dist/lib/request/helpers/model-map.js +183 -0
- package/dist/lib/request/helpers/model-map.js.map +1 -0
- package/dist/lib/request/helpers/tool-utils.d.ts +29 -0
- package/dist/lib/request/helpers/tool-utils.d.ts.map +1 -0
- package/dist/lib/request/helpers/tool-utils.js +117 -0
- package/dist/lib/request/helpers/tool-utils.js.map +1 -0
- package/dist/lib/request/rate-limit-backoff.d.ts +17 -0
- package/dist/lib/request/rate-limit-backoff.d.ts.map +1 -0
- package/dist/lib/request/rate-limit-backoff.js +83 -0
- package/dist/lib/request/rate-limit-backoff.js.map +1 -0
- package/dist/lib/request/request-transformer.d.ts +107 -0
- package/dist/lib/request/request-transformer.d.ts.map +1 -0
- package/dist/lib/request/request-transformer.js +930 -0
- package/dist/lib/request/request-transformer.js.map +1 -0
- package/dist/lib/request/response-handler.d.ts +23 -0
- package/dist/lib/request/response-handler.d.ts.map +1 -0
- package/dist/lib/request/response-handler.js +245 -0
- package/dist/lib/request/response-handler.js.map +1 -0
- package/dist/lib/request/retry-budget.d.ts +19 -0
- package/dist/lib/request/retry-budget.d.ts.map +1 -0
- package/dist/lib/request/retry-budget.js +99 -0
- package/dist/lib/request/retry-budget.js.map +1 -0
- package/dist/lib/rotation.d.ts +130 -0
- package/dist/lib/rotation.d.ts.map +1 -0
- package/dist/lib/rotation.js +301 -0
- package/dist/lib/rotation.js.map +1 -0
- package/dist/lib/runtime-contracts.d.ts +16 -0
- package/dist/lib/runtime-contracts.d.ts.map +1 -0
- package/dist/lib/runtime-contracts.js +24 -0
- package/dist/lib/runtime-contracts.js.map +1 -0
- package/dist/lib/schemas.d.ts +457 -0
- package/dist/lib/schemas.d.ts.map +1 -0
- package/dist/lib/schemas.js +283 -0
- package/dist/lib/schemas.js.map +1 -0
- package/dist/lib/shutdown.d.ts +7 -0
- package/dist/lib/shutdown.d.ts.map +1 -0
- package/dist/lib/shutdown.js +43 -0
- package/dist/lib/shutdown.js.map +1 -0
- package/dist/lib/storage/migrations.d.ts +65 -0
- package/dist/lib/storage/migrations.d.ts.map +1 -0
- package/dist/lib/storage/migrations.js +44 -0
- package/dist/lib/storage/migrations.js.map +1 -0
- package/dist/lib/storage/paths.d.ts +16 -0
- package/dist/lib/storage/paths.d.ts.map +1 -0
- package/dist/lib/storage/paths.js +92 -0
- package/dist/lib/storage/paths.js.map +1 -0
- package/dist/lib/storage.d.ts +157 -0
- package/dist/lib/storage.d.ts.map +1 -0
- package/dist/lib/storage.js +1169 -0
- package/dist/lib/storage.js.map +1 -0
- package/dist/lib/table-formatter.d.ts +32 -0
- package/dist/lib/table-formatter.d.ts.map +1 -0
- package/dist/lib/table-formatter.js +44 -0
- package/dist/lib/table-formatter.js.map +1 -0
- package/dist/lib/types.d.ts +131 -0
- package/dist/lib/types.d.ts.map +1 -0
- package/dist/lib/types.js +2 -0
- package/dist/lib/types.js.map +1 -0
- package/dist/lib/ui/ansi.d.ts +22 -0
- package/dist/lib/ui/ansi.d.ts.map +1 -0
- package/dist/lib/ui/ansi.js +38 -0
- package/dist/lib/ui/ansi.js.map +1 -0
- package/dist/lib/ui/auth-menu.d.ts +39 -0
- package/dist/lib/ui/auth-menu.d.ts.map +1 -0
- package/dist/lib/ui/auth-menu.js +186 -0
- package/dist/lib/ui/auth-menu.js.map +1 -0
- package/dist/lib/ui/beginner.d.ts +62 -0
- package/dist/lib/ui/beginner.d.ts.map +1 -0
- package/dist/lib/ui/beginner.js +259 -0
- package/dist/lib/ui/beginner.js.map +1 -0
- package/dist/lib/ui/confirm.d.ts +2 -0
- package/dist/lib/ui/confirm.d.ts.map +1 -0
- package/dist/lib/ui/confirm.js +21 -0
- package/dist/lib/ui/confirm.js.map +1 -0
- package/dist/lib/ui/format.d.ts +9 -0
- package/dist/lib/ui/format.d.ts.map +1 -0
- package/dist/lib/ui/format.js +49 -0
- package/dist/lib/ui/format.js.map +1 -0
- package/dist/lib/ui/runtime.d.ts +11 -0
- package/dist/lib/ui/runtime.d.ts.map +1 -0
- package/dist/lib/ui/runtime.js +31 -0
- package/dist/lib/ui/runtime.js.map +1 -0
- package/dist/lib/ui/select.d.ts +20 -0
- package/dist/lib/ui/select.d.ts.map +1 -0
- package/dist/lib/ui/select.js +343 -0
- package/dist/lib/ui/select.js.map +1 -0
- package/dist/lib/ui/theme.d.ts +34 -0
- package/dist/lib/ui/theme.d.ts.map +1 -0
- package/dist/lib/ui/theme.js +84 -0
- package/dist/lib/ui/theme.js.map +1 -0
- package/dist/lib/utils.d.ts +29 -0
- package/dist/lib/utils.d.ts.map +1 -0
- package/dist/lib/utils.js +54 -0
- package/dist/lib/utils.js.map +1 -0
- package/package.json +113 -0
- package/scripts/audit-dev-allowlist.js +114 -0
- package/scripts/copy-oauth-success.js +37 -0
- package/scripts/install-oc-codex-multi-auth-core.js +381 -0
- package/scripts/install-oc-codex-multi-auth.js +15 -0
- package/scripts/test-all-models.sh +260 -0
- package/scripts/validate-model-map.sh +97 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { ManagedAccount, AccountManager } from "./accounts.js";
|
|
2
|
+
import type { ModelFamily } from "./prompts/codex.js";
|
|
3
|
+
export interface ProbeCandidate {
|
|
4
|
+
account: ManagedAccount;
|
|
5
|
+
controller: AbortController;
|
|
6
|
+
}
|
|
7
|
+
export interface ProbeResult<T> {
|
|
8
|
+
type: "success" | "failure";
|
|
9
|
+
account: ManagedAccount;
|
|
10
|
+
response?: T;
|
|
11
|
+
error?: Error;
|
|
12
|
+
}
|
|
13
|
+
export interface ParallelProbeOptions {
|
|
14
|
+
maxConcurrency: number;
|
|
15
|
+
timeoutMs: number;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Get top N candidates ranked by hybrid score WITHOUT mutating AccountManager state.
|
|
19
|
+
* Uses getAccountsSnapshot() and ranks by health + tokens + freshness.
|
|
20
|
+
*/
|
|
21
|
+
export declare function getTopCandidates(accountManager: AccountManager, modelFamily: ModelFamily, model: string | null, maxCandidates: number): ManagedAccount[];
|
|
22
|
+
/**
|
|
23
|
+
* Probe accounts in parallel with first-success-wins racing.
|
|
24
|
+
* Immediately aborts losing candidates when a winner is found.
|
|
25
|
+
*/
|
|
26
|
+
export declare function probeAccountsInParallel<T>(candidates: ProbeCandidate[], probeFn: (account: ManagedAccount, signal: AbortSignal) => Promise<T>, _options?: Partial<ParallelProbeOptions>): Promise<ProbeResult<T> | null>;
|
|
27
|
+
export declare function createProbeCandidates(accounts: ManagedAccount[]): ProbeCandidate[];
|
|
28
|
+
//# sourceMappingURL=parallel-probe.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parallel-probe.d.ts","sourceRoot":"","sources":["../../lib/parallel-probe.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACpE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAWtD,MAAM,WAAW,cAAc;IAC9B,OAAO,EAAE,cAAc,CAAC;IACxB,UAAU,EAAE,eAAe,CAAC;CAC5B;AAED,MAAM,WAAW,WAAW,CAAC,CAAC;IAC7B,IAAI,EAAE,SAAS,GAAG,SAAS,CAAC;IAC5B,OAAO,EAAE,cAAc,CAAC;IACxB,QAAQ,CAAC,EAAE,CAAC,CAAC;IACb,KAAK,CAAC,EAAE,KAAK,CAAC;CACd;AAED,MAAM,WAAW,oBAAoB;IACpC,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;CAClB;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAC/B,cAAc,EAAE,cAAc,EAC9B,WAAW,EAAE,WAAW,EACxB,KAAK,EAAE,MAAM,GAAG,IAAI,EACpB,aAAa,EAAE,MAAM,GACnB,cAAc,EAAE,CAuClB;AAED;;;GAGG;AACH,wBAAsB,uBAAuB,CAAC,CAAC,EAC9C,UAAU,EAAE,cAAc,EAAE,EAC5B,OAAO,EAAE,CAAC,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,WAAW,KAAK,OAAO,CAAC,CAAC,CAAC,EACrE,QAAQ,GAAE,OAAO,CAAC,oBAAoB,CAAM,GAC1C,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CA8ChC;AAED,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,cAAc,EAAE,GAAG,cAAc,EAAE,CAKlF"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { createLogger } from "./logger.js";
|
|
2
|
+
import { getHealthTracker, getTokenTracker, } from "./rotation.js";
|
|
3
|
+
import { clearExpiredRateLimits, isRateLimitedForFamily } from "./accounts/rate-limits.js";
|
|
4
|
+
const log = createLogger("parallel-probe");
|
|
5
|
+
/**
|
|
6
|
+
* Get top N candidates ranked by hybrid score WITHOUT mutating AccountManager state.
|
|
7
|
+
* Uses getAccountsSnapshot() and ranks by health + tokens + freshness.
|
|
8
|
+
*/
|
|
9
|
+
export function getTopCandidates(accountManager, modelFamily, model, maxCandidates) {
|
|
10
|
+
const accounts = accountManager.getAccountsSnapshot();
|
|
11
|
+
if (accounts.length === 0)
|
|
12
|
+
return [];
|
|
13
|
+
const quotaKey = model ? `${modelFamily}:${model}` : modelFamily;
|
|
14
|
+
const healthTracker = getHealthTracker();
|
|
15
|
+
const tokenTracker = getTokenTracker();
|
|
16
|
+
const accountsWithMetrics = [];
|
|
17
|
+
for (const account of accounts) {
|
|
18
|
+
clearExpiredRateLimits(account);
|
|
19
|
+
const isRateLimited = isRateLimitedForFamily(account, modelFamily, model);
|
|
20
|
+
const isCoolingDown = account.coolingDownUntil !== undefined && account.coolingDownUntil > Date.now();
|
|
21
|
+
const isAvailable = !isRateLimited && !isCoolingDown;
|
|
22
|
+
accountsWithMetrics.push({
|
|
23
|
+
index: account.index,
|
|
24
|
+
isAvailable,
|
|
25
|
+
lastUsed: account.lastUsed,
|
|
26
|
+
account,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
const available = accountsWithMetrics.filter((a) => a.isAvailable);
|
|
30
|
+
if (available.length === 0)
|
|
31
|
+
return [];
|
|
32
|
+
const now = Date.now();
|
|
33
|
+
const scored = available.map((a) => {
|
|
34
|
+
const health = healthTracker.getScore(a.index, quotaKey);
|
|
35
|
+
const tokens = tokenTracker.getTokens(a.index, quotaKey);
|
|
36
|
+
const hoursSinceUsed = (now - a.lastUsed) / (1000 * 60 * 60);
|
|
37
|
+
const score = health * 2 + tokens * 5 + hoursSinceUsed * 2.0;
|
|
38
|
+
return { ...a, score };
|
|
39
|
+
});
|
|
40
|
+
scored.sort((a, b) => b.score - a.score);
|
|
41
|
+
return scored.slice(0, maxCandidates).map((s) => s.account);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Probe accounts in parallel with first-success-wins racing.
|
|
45
|
+
* Immediately aborts losing candidates when a winner is found.
|
|
46
|
+
*/
|
|
47
|
+
export async function probeAccountsInParallel(candidates, probeFn, _options = {}) {
|
|
48
|
+
if (candidates.length === 0) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
if (candidates.length === 1) {
|
|
52
|
+
const candidate = candidates[0];
|
|
53
|
+
if (!candidate)
|
|
54
|
+
return null;
|
|
55
|
+
const { account, controller } = candidate;
|
|
56
|
+
try {
|
|
57
|
+
const response = await probeFn(account, controller.signal);
|
|
58
|
+
return { type: "success", account, response };
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
return { type: "failure", account, error: error };
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
log.debug(`Probing ${candidates.length} accounts in parallel`);
|
|
65
|
+
let winner = null;
|
|
66
|
+
let resolvedCount = 0;
|
|
67
|
+
return new Promise((resolve) => {
|
|
68
|
+
for (const { account, controller } of candidates) {
|
|
69
|
+
probeFn(account, controller.signal)
|
|
70
|
+
.then((response) => {
|
|
71
|
+
if (!winner) {
|
|
72
|
+
winner = { type: "success", account, response };
|
|
73
|
+
log.debug(`Parallel probe succeeded with account ${account.index + 1}`);
|
|
74
|
+
for (const c of candidates) {
|
|
75
|
+
if (c.account.index !== account.index) {
|
|
76
|
+
c.controller.abort();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
resolve(winner);
|
|
80
|
+
}
|
|
81
|
+
})
|
|
82
|
+
.catch((_error) => {
|
|
83
|
+
resolvedCount++;
|
|
84
|
+
if (resolvedCount === candidates.length && !winner) {
|
|
85
|
+
resolve(null);
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
export function createProbeCandidates(accounts) {
|
|
92
|
+
return accounts.map((account) => ({
|
|
93
|
+
account,
|
|
94
|
+
controller: new AbortController(),
|
|
95
|
+
}));
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=parallel-probe.js.map
|
|
@@ -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K,MAAM,CAAC,IAAI,UAAU,EAAE,CAAC;wBAC5B,IAAI,CAAC,CAAC,OAAO,CAAC,KAAK,KAAK,OAAO,CAAC,KAAK,EAAE,CAAC;4BACvC,CAAC,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;wBACtB,CAAC;oBACF,CAAC;oBACD,OAAO,CAAC,MAAM,CAAC,CAAC;gBACjB,CAAC;YACF,CAAC,CAAC;iBACD,KAAK,CAAC,CAAC,MAAM,EAAE,EAAE;gBACjB,aAAa,EAAE,CAAC;gBAChB,IAAI,aAAa,KAAK,UAAU,CAAC,MAAM,IAAI,CAAC,MAAM,EAAE,CAAC;oBACpD,OAAO,CAAC,IAAI,CAAC,CAAC;gBACf,CAAC;YACF,CAAC,CAAC,CAAC;QACL,CAAC;IACF,CAAC,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,QAA0B;IAC/D,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;QACjC,OAAO;QACP,UAAU,EAAE,IAAI,eAAe,EAAE;KACjC,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Proactive Token Refresh Module
|
|
3
|
+
*
|
|
4
|
+
* Refreshes OAuth tokens before they expire to prevent auth failures mid-request.
|
|
5
|
+
* Default buffer: 5 minutes before expiry (configurable via tokenRefreshSkewMs).
|
|
6
|
+
*
|
|
7
|
+
* This is a production hardening feature that:
|
|
8
|
+
* - Reduces mid-request auth failures
|
|
9
|
+
* - Improves user experience with seamless token rotation
|
|
10
|
+
* - Works alongside the existing reactive refresh in fetch-helpers
|
|
11
|
+
*/
|
|
12
|
+
import type { ManagedAccount } from "./accounts.js";
|
|
13
|
+
import type { TokenResult } from "./types.js";
|
|
14
|
+
/** Default buffer before expiry to trigger proactive refresh (5 minutes) */
|
|
15
|
+
export declare const DEFAULT_PROACTIVE_BUFFER_MS: number;
|
|
16
|
+
/** Minimum buffer to prevent unnecessary refreshes (30 seconds) */
|
|
17
|
+
export declare const MIN_PROACTIVE_BUFFER_MS: number;
|
|
18
|
+
/**
|
|
19
|
+
* Result of a proactive refresh operation.
|
|
20
|
+
*/
|
|
21
|
+
export interface ProactiveRefreshResult {
|
|
22
|
+
refreshed: boolean;
|
|
23
|
+
tokenResult?: TokenResult;
|
|
24
|
+
reason: "not_needed" | "no_refresh_token" | "success" | "failed" | "exception";
|
|
25
|
+
errorMessage?: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Determines if an account's token should be proactively refreshed.
|
|
29
|
+
*
|
|
30
|
+
* @param account - The managed account to check
|
|
31
|
+
* @param bufferMs - Time buffer before expiry to trigger refresh (default: 5 minutes)
|
|
32
|
+
* @returns True if token is approaching expiry and should be refreshed
|
|
33
|
+
*/
|
|
34
|
+
export declare function shouldRefreshProactively(account: ManagedAccount, bufferMs?: number): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Calculates milliseconds until an account's token expires.
|
|
37
|
+
*
|
|
38
|
+
* @param account - The managed account to check
|
|
39
|
+
* @returns Milliseconds until expiry, or Infinity if no expiry set
|
|
40
|
+
*/
|
|
41
|
+
export declare function getTimeUntilExpiry(account: ManagedAccount): number;
|
|
42
|
+
/**
|
|
43
|
+
* Proactively refreshes an account's token if it's approaching expiry.
|
|
44
|
+
*
|
|
45
|
+
* @param account - The managed account to refresh
|
|
46
|
+
* @param bufferMs - Time buffer before expiry to trigger refresh
|
|
47
|
+
* @returns Result indicating whether refresh was performed and outcome
|
|
48
|
+
*/
|
|
49
|
+
export declare function proactiveRefreshAccount(account: ManagedAccount, bufferMs?: number): Promise<ProactiveRefreshResult>;
|
|
50
|
+
/**
|
|
51
|
+
* Refreshes all accounts that are approaching token expiry.
|
|
52
|
+
*
|
|
53
|
+
* @param accounts - Array of managed accounts to check
|
|
54
|
+
* @param bufferMs - Time buffer before expiry to trigger refresh
|
|
55
|
+
* @returns Map of account index to refresh result
|
|
56
|
+
*/
|
|
57
|
+
export declare function refreshExpiringAccounts(accounts: ManagedAccount[], bufferMs?: number): Promise<Map<number, ProactiveRefreshResult>>;
|
|
58
|
+
/**
|
|
59
|
+
* Updates a ManagedAccount with fresh token data from a successful refresh.
|
|
60
|
+
*
|
|
61
|
+
* @param account - The account to update
|
|
62
|
+
* @param result - Successful token refresh result
|
|
63
|
+
*/
|
|
64
|
+
export declare function applyRefreshResult(account: ManagedAccount, result: Extract<TokenResult, {
|
|
65
|
+
type: "success";
|
|
66
|
+
}>): void;
|
|
67
|
+
//# sourceMappingURL=proactive-refresh.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proactive-refresh.d.ts","sourceRoot":"","sources":["../../lib/proactive-refresh.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAI9C,4EAA4E;AAC5E,eAAO,MAAM,2BAA2B,QAAgB,CAAC;AAEzD,mEAAmE;AACnE,eAAO,MAAM,uBAAuB,QAAY,CAAC;AAEjD;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACtC,SAAS,EAAE,OAAO,CAAC;IACnB,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,MAAM,EAAE,YAAY,GAAG,kBAAkB,GAAG,SAAS,GAAG,QAAQ,GAAG,WAAW,CAAC;IAC/E,YAAY,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CACvC,OAAO,EAAE,cAAc,EACvB,QAAQ,GAAE,MAAoC,GAC5C,OAAO,CAoBT;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,cAAc,GAAG,MAAM,CAKlE;AAED;;;;;;GAMG;AACH,wBAAsB,uBAAuB,CAC5C,OAAO,EAAE,cAAc,EACvB,QAAQ,GAAE,MAAoC,GAC5C,OAAO,CAAC,sBAAsB,CAAC,CAoCjC;AAED;;;;;;GAMG;AACH,wBAAsB,uBAAuB,CAC5C,QAAQ,EAAE,cAAc,EAAE,EAC1B,QAAQ,GAAE,MAAoC,GAC5C,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,sBAAsB,CAAC,CAAC,CA2D9C;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CACjC,OAAO,EAAE,cAAc,EACvB,MAAM,EAAE,OAAO,CAAC,WAAW,EAAE;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,CAAC,GAC/C,IAAI,CAMN"}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Proactive Token Refresh Module
|
|
3
|
+
*
|
|
4
|
+
* Refreshes OAuth tokens before they expire to prevent auth failures mid-request.
|
|
5
|
+
* Default buffer: 5 minutes before expiry (configurable via tokenRefreshSkewMs).
|
|
6
|
+
*
|
|
7
|
+
* This is a production hardening feature that:
|
|
8
|
+
* - Reduces mid-request auth failures
|
|
9
|
+
* - Improves user experience with seamless token rotation
|
|
10
|
+
* - Works alongside the existing reactive refresh in fetch-helpers
|
|
11
|
+
*/
|
|
12
|
+
import { queuedRefresh } from "./refresh-queue.js";
|
|
13
|
+
import { createLogger } from "./logger.js";
|
|
14
|
+
const log = createLogger("proactive-refresh");
|
|
15
|
+
/** Default buffer before expiry to trigger proactive refresh (5 minutes) */
|
|
16
|
+
export const DEFAULT_PROACTIVE_BUFFER_MS = 5 * 60 * 1000;
|
|
17
|
+
/** Minimum buffer to prevent unnecessary refreshes (30 seconds) */
|
|
18
|
+
export const MIN_PROACTIVE_BUFFER_MS = 30 * 1000;
|
|
19
|
+
/**
|
|
20
|
+
* Determines if an account's token should be proactively refreshed.
|
|
21
|
+
*
|
|
22
|
+
* @param account - The managed account to check
|
|
23
|
+
* @param bufferMs - Time buffer before expiry to trigger refresh (default: 5 minutes)
|
|
24
|
+
* @returns True if token is approaching expiry and should be refreshed
|
|
25
|
+
*/
|
|
26
|
+
export function shouldRefreshProactively(account, bufferMs = DEFAULT_PROACTIVE_BUFFER_MS) {
|
|
27
|
+
// No expiry set - can't determine if refresh is needed
|
|
28
|
+
if (account.expires === undefined) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
// No access token - definitely needs refresh
|
|
32
|
+
if (!account.access) {
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
// Clamp buffer to minimum
|
|
36
|
+
const safeBufferMs = Math.max(MIN_PROACTIVE_BUFFER_MS, bufferMs);
|
|
37
|
+
// Check if token expires within buffer window
|
|
38
|
+
const now = Date.now();
|
|
39
|
+
const expiresAt = account.expires;
|
|
40
|
+
const refreshThreshold = expiresAt - safeBufferMs;
|
|
41
|
+
return now >= refreshThreshold;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Calculates milliseconds until an account's token expires.
|
|
45
|
+
*
|
|
46
|
+
* @param account - The managed account to check
|
|
47
|
+
* @returns Milliseconds until expiry, or Infinity if no expiry set
|
|
48
|
+
*/
|
|
49
|
+
export function getTimeUntilExpiry(account) {
|
|
50
|
+
if (account.expires === undefined) {
|
|
51
|
+
return Infinity;
|
|
52
|
+
}
|
|
53
|
+
return Math.max(0, account.expires - Date.now());
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Proactively refreshes an account's token if it's approaching expiry.
|
|
57
|
+
*
|
|
58
|
+
* @param account - The managed account to refresh
|
|
59
|
+
* @param bufferMs - Time buffer before expiry to trigger refresh
|
|
60
|
+
* @returns Result indicating whether refresh was performed and outcome
|
|
61
|
+
*/
|
|
62
|
+
export async function proactiveRefreshAccount(account, bufferMs = DEFAULT_PROACTIVE_BUFFER_MS) {
|
|
63
|
+
if (!shouldRefreshProactively(account, bufferMs)) {
|
|
64
|
+
return { refreshed: false, reason: "not_needed" };
|
|
65
|
+
}
|
|
66
|
+
if (!account.refreshToken) {
|
|
67
|
+
log.warn("Cannot proactively refresh account without refresh token", {
|
|
68
|
+
accountIndex: account.index,
|
|
69
|
+
});
|
|
70
|
+
return { refreshed: false, reason: "no_refresh_token" };
|
|
71
|
+
}
|
|
72
|
+
const timeUntilExpiry = getTimeUntilExpiry(account);
|
|
73
|
+
log.info("Proactively refreshing token", {
|
|
74
|
+
accountIndex: account.index,
|
|
75
|
+
email: account.email,
|
|
76
|
+
expiresInMs: timeUntilExpiry,
|
|
77
|
+
expiresInMinutes: Math.round(timeUntilExpiry / 60000),
|
|
78
|
+
});
|
|
79
|
+
const result = await queuedRefresh(account.refreshToken);
|
|
80
|
+
if (result.type === "success") {
|
|
81
|
+
log.info("Proactive refresh succeeded", {
|
|
82
|
+
accountIndex: account.index,
|
|
83
|
+
email: account.email,
|
|
84
|
+
});
|
|
85
|
+
return { refreshed: true, tokenResult: result, reason: "success" };
|
|
86
|
+
}
|
|
87
|
+
log.warn("Proactive refresh failed", {
|
|
88
|
+
accountIndex: account.index,
|
|
89
|
+
email: account.email,
|
|
90
|
+
failureReason: result.reason,
|
|
91
|
+
});
|
|
92
|
+
return { refreshed: true, tokenResult: result, reason: "failed" };
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Refreshes all accounts that are approaching token expiry.
|
|
96
|
+
*
|
|
97
|
+
* @param accounts - Array of managed accounts to check
|
|
98
|
+
* @param bufferMs - Time buffer before expiry to trigger refresh
|
|
99
|
+
* @returns Map of account index to refresh result
|
|
100
|
+
*/
|
|
101
|
+
export async function refreshExpiringAccounts(accounts, bufferMs = DEFAULT_PROACTIVE_BUFFER_MS) {
|
|
102
|
+
const results = new Map();
|
|
103
|
+
const accountsToRefresh = accounts.filter((a) => shouldRefreshProactively(a, bufferMs));
|
|
104
|
+
if (accountsToRefresh.length === 0) {
|
|
105
|
+
log.debug("No accounts need proactive refresh");
|
|
106
|
+
return results;
|
|
107
|
+
}
|
|
108
|
+
log.info(`Proactively refreshing ${accountsToRefresh.length} account(s)`);
|
|
109
|
+
// Refresh in parallel for efficiency
|
|
110
|
+
const refreshPromises = accountsToRefresh.map(async (account) => {
|
|
111
|
+
try {
|
|
112
|
+
const result = await proactiveRefreshAccount(account, bufferMs);
|
|
113
|
+
return { index: account.index, result };
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
117
|
+
log.error("Unhandled exception during proactive refresh", {
|
|
118
|
+
accountId: account.accountId,
|
|
119
|
+
error: errorMessage,
|
|
120
|
+
});
|
|
121
|
+
const exceptionResult = {
|
|
122
|
+
refreshed: false,
|
|
123
|
+
reason: "exception",
|
|
124
|
+
errorMessage,
|
|
125
|
+
};
|
|
126
|
+
return {
|
|
127
|
+
index: account.index,
|
|
128
|
+
result: exceptionResult,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
const outcomes = await Promise.all(refreshPromises);
|
|
133
|
+
for (const { index, result } of outcomes) {
|
|
134
|
+
results.set(index, result);
|
|
135
|
+
}
|
|
136
|
+
// Log summary
|
|
137
|
+
const succeeded = Array.from(results.values()).filter((r) => r.reason === "success").length;
|
|
138
|
+
const failed = Array.from(results.values()).filter((r) => r.reason === "failed").length;
|
|
139
|
+
if (succeeded > 0 || failed > 0) {
|
|
140
|
+
log.info("Proactive refresh complete", {
|
|
141
|
+
total: accountsToRefresh.length,
|
|
142
|
+
succeeded,
|
|
143
|
+
failed,
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
return results;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Updates a ManagedAccount with fresh token data from a successful refresh.
|
|
150
|
+
*
|
|
151
|
+
* @param account - The account to update
|
|
152
|
+
* @param result - Successful token refresh result
|
|
153
|
+
*/
|
|
154
|
+
export function applyRefreshResult(account, result) {
|
|
155
|
+
account.access = result.access;
|
|
156
|
+
account.expires = result.expires;
|
|
157
|
+
if (result.refresh !== account.refreshToken) {
|
|
158
|
+
account.refreshToken = result.refresh;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
//# sourceMappingURL=proactive-refresh.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proactive-refresh.js","sourceRoot":"","sources":["../../lib/proactive-refresh.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAI3C,MAAM,GAAG,GAAG,YAAY,CAAC,mBAAmB,CAAC,CAAC;AAE9C,4EAA4E;AAC5E,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;AAEzD,mEAAmE;AACnE,MAAM,CAAC,MAAM,uBAAuB,GAAG,EAAE,GAAG,IAAI,CAAC;AAYjD;;;;;;GAMG;AACH,MAAM,UAAU,wBAAwB,CACvC,OAAuB,EACvB,WAAmB,2BAA2B;IAE9C,uDAAuD;IACvD,IAAI,OAAO,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;QACnC,OAAO,KAAK,CAAC;IACd,CAAC;IAED,6CAA6C;IAC7C,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;QACrB,OAAO,IAAI,CAAC;IACb,CAAC;IAED,0BAA0B;IAC1B,MAAM,YAAY,GAAG,IAAI,CAAC,GAAG,CAAC,uBAAuB,EAAE,QAAQ,CAAC,CAAC;IAEjE,8CAA8C;IAC9C,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IACvB,MAAM,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC;IAClC,MAAM,gBAAgB,GAAG,SAAS,GAAG,YAAY,CAAC;IAElD,OAAO,GAAG,IAAI,gBAAgB,CAAC;AAChC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAAC,OAAuB;IACzD,IAAI,OAAO,CAAC,OAAO,KAAK,SAAS,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;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CACjC,OAAuB,EACvB,MAAiD;IAEjD,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;IAC/B,OAAO,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;IACjC,IAAI,MAAM,CAAC,OAAO,KAAK,OAAO,CAAC,YAAY,EAAE,CAAC;QAC7C,OAAO,CAAC,YAAY,GAAG,MAAM,CAAC,OAAO,CAAC;IACvC,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Codex-OpenCode Bridge Prompt
|
|
3
|
+
*
|
|
4
|
+
* This prompt bridges Codex CLI instructions to the OpenCode environment.
|
|
5
|
+
* It focuses on runtime-tool authority, schema discipline, and execution guardrails
|
|
6
|
+
* to avoid tool-name drift across OpenCode versions.
|
|
7
|
+
*
|
|
8
|
+
* Token Count: ~450 tokens (~90% reduction vs full OpenCode prompt)
|
|
9
|
+
*/
|
|
10
|
+
export declare const CODEX_OPENCODE_BRIDGE = "# Codex Running in OpenCode\n\nYou are running Codex through OpenCode, an open-source terminal coding assistant.\n\n## Runtime Tooling Rule (Highest Priority)\n\n<critical_rule priority=\"0\">\nTreat the runtime tool manifest as the only authoritative tool list.\n- Call ONLY tool names listed in that manifest.\n- Do NOT translate, alias, or rename tool names.\n- If a base instruction references a tool name that is not listed, ignore that alias and use the listed names only.\n</critical_rule>\n\n## Tool-Call Guardrails\n\n- Follow the current tool schema exactly for parameters.\n- Do not invent wrapper namespaces unless they are explicitly listed as tools.\n- If no explicit parallel helper tool is listed, run calls sequentially.\n- If a tool call fails validation, correct arguments to match schema and retry.\n\n## Planning & Modes\n\n- Never call `update_plan`, `read_plan`, or similarly named aliases.\n- Use planning tools only if they are explicitly listed in the runtime manifest.\n- `request_user_input` is Plan-mode only; never call it in Default mode.\n\n## Path & Execution Discipline\n\n- Follow per-tool path conventions from the active schema; do not assume absolute/relative behavior.\n- Prefer specialized tools over shell when an equivalent listed tool exists.\n- Use non-destructive checks before destructive commands.\n\n## Verification Checklist\n\nBefore each tool call:\n1. Is the tool name exactly listed in the runtime manifest?\n2. Do arguments match the listed schema?\n3. Am I avoiding unlisted aliases and wrapper namespaces?\n4. Am I following mode/path constraints for this environment?\n\nIf any answer is NO, correct it before proceeding.\n\n## OpenCode Working Style\n\n**Communication:**\n- Send brief preambles before tool calls.\n- Provide concise progress updates during longer tasks.\n\n**Execution:**\n- Continue working until the user request is fully resolved.\n- Do not return partial solutions unless blocked.\n\n**Code Approach:**\n- New projects: be creative and deliberate.\n- Existing codebases: make precise, minimal changes aligned to request.\n\n**Testing:**\n- If tests exist, run focused tests first, then broader validation.\n\n## What Remains from Codex\n\nSandbox policies, approvals, final formatting, git protocols, and file reference formats still follow Codex instructions.\n\n## Approvals & Safety\n\n- Treat destructive commands (for example `rm`, `git reset --hard`) as requiring explicit user request or approval.\n- Never run `git reset --hard`, `git checkout --`, or force deletes unless explicitly requested.\n- When uncertain, prefer non-destructive verification first.";
|
|
11
|
+
export declare const renderCodexOpenCodeBridge: (toolNames: readonly string[]) => string;
|
|
12
|
+
export interface CodexOpenCodeBridgeMeta {
|
|
13
|
+
estimatedTokens: number;
|
|
14
|
+
reductionVsCurrent: string;
|
|
15
|
+
reductionVsToolRemap: string;
|
|
16
|
+
protects: string[];
|
|
17
|
+
omits: string[];
|
|
18
|
+
}
|
|
19
|
+
export declare const CODEX_OPENCODE_BRIDGE_META: CodexOpenCodeBridgeMeta;
|
|
20
|
+
//# sourceMappingURL=codex-opencode-bridge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codex-opencode-bridge.d.ts","sourceRoot":"","sources":["../../../lib/prompts/codex-opencode-bridge.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,eAAO,MAAM,qBAAqB,ylFAmE2B,CAAC;AAe9D,eAAO,MAAM,yBAAyB,GAAI,WAAW,SAAS,MAAM,EAAE,KAAG,MAexE,CAAC;AAEF,MAAM,WAAW,uBAAuB;IACvC,eAAe,EAAE,MAAM,CAAC;IACxB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,oBAAoB,EAAE,MAAM,CAAC;IAC7B,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,KAAK,EAAE,MAAM,EAAE,CAAC;CAChB;AAED,eAAO,MAAM,0BAA0B,EAAE,uBAoBxC,CAAC"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Codex-OpenCode Bridge Prompt
|
|
3
|
+
*
|
|
4
|
+
* This prompt bridges Codex CLI instructions to the OpenCode environment.
|
|
5
|
+
* It focuses on runtime-tool authority, schema discipline, and execution guardrails
|
|
6
|
+
* to avoid tool-name drift across OpenCode versions.
|
|
7
|
+
*
|
|
8
|
+
* Token Count: ~450 tokens (~90% reduction vs full OpenCode prompt)
|
|
9
|
+
*/
|
|
10
|
+
export const CODEX_OPENCODE_BRIDGE = `# Codex Running in OpenCode
|
|
11
|
+
|
|
12
|
+
You are running Codex through OpenCode, an open-source terminal coding assistant.
|
|
13
|
+
|
|
14
|
+
## Runtime Tooling Rule (Highest Priority)
|
|
15
|
+
|
|
16
|
+
<critical_rule priority="0">
|
|
17
|
+
Treat the runtime tool manifest as the only authoritative tool list.
|
|
18
|
+
- Call ONLY tool names listed in that manifest.
|
|
19
|
+
- Do NOT translate, alias, or rename tool names.
|
|
20
|
+
- If a base instruction references a tool name that is not listed, ignore that alias and use the listed names only.
|
|
21
|
+
</critical_rule>
|
|
22
|
+
|
|
23
|
+
## Tool-Call Guardrails
|
|
24
|
+
|
|
25
|
+
- Follow the current tool schema exactly for parameters.
|
|
26
|
+
- Do not invent wrapper namespaces unless they are explicitly listed as tools.
|
|
27
|
+
- If no explicit parallel helper tool is listed, run calls sequentially.
|
|
28
|
+
- If a tool call fails validation, correct arguments to match schema and retry.
|
|
29
|
+
|
|
30
|
+
## Planning & Modes
|
|
31
|
+
|
|
32
|
+
- Never call \`update_plan\`, \`read_plan\`, or similarly named aliases.
|
|
33
|
+
- Use planning tools only if they are explicitly listed in the runtime manifest.
|
|
34
|
+
- \`request_user_input\` is Plan-mode only; never call it in Default mode.
|
|
35
|
+
|
|
36
|
+
## Path & Execution Discipline
|
|
37
|
+
|
|
38
|
+
- Follow per-tool path conventions from the active schema; do not assume absolute/relative behavior.
|
|
39
|
+
- Prefer specialized tools over shell when an equivalent listed tool exists.
|
|
40
|
+
- Use non-destructive checks before destructive commands.
|
|
41
|
+
|
|
42
|
+
## Verification Checklist
|
|
43
|
+
|
|
44
|
+
Before each tool call:
|
|
45
|
+
1. Is the tool name exactly listed in the runtime manifest?
|
|
46
|
+
2. Do arguments match the listed schema?
|
|
47
|
+
3. Am I avoiding unlisted aliases and wrapper namespaces?
|
|
48
|
+
4. Am I following mode/path constraints for this environment?
|
|
49
|
+
|
|
50
|
+
If any answer is NO, correct it before proceeding.
|
|
51
|
+
|
|
52
|
+
## OpenCode Working Style
|
|
53
|
+
|
|
54
|
+
**Communication:**
|
|
55
|
+
- Send brief preambles before tool calls.
|
|
56
|
+
- Provide concise progress updates during longer tasks.
|
|
57
|
+
|
|
58
|
+
**Execution:**
|
|
59
|
+
- Continue working until the user request is fully resolved.
|
|
60
|
+
- Do not return partial solutions unless blocked.
|
|
61
|
+
|
|
62
|
+
**Code Approach:**
|
|
63
|
+
- New projects: be creative and deliberate.
|
|
64
|
+
- Existing codebases: make precise, minimal changes aligned to request.
|
|
65
|
+
|
|
66
|
+
**Testing:**
|
|
67
|
+
- If tests exist, run focused tests first, then broader validation.
|
|
68
|
+
|
|
69
|
+
## What Remains from Codex
|
|
70
|
+
|
|
71
|
+
Sandbox policies, approvals, final formatting, git protocols, and file reference formats still follow Codex instructions.
|
|
72
|
+
|
|
73
|
+
## Approvals & Safety
|
|
74
|
+
|
|
75
|
+
- Treat destructive commands (for example \`rm\`, \`git reset --hard\`) as requiring explicit user request or approval.
|
|
76
|
+
- Never run \`git reset --hard\`, \`git checkout --\`, or force deletes unless explicitly requested.
|
|
77
|
+
- When uncertain, prefer non-destructive verification first.`;
|
|
78
|
+
const MAX_MANIFEST_TOOLS = 32;
|
|
79
|
+
const normalizeRuntimeToolNames = (toolNames) => {
|
|
80
|
+
const unique = new Set();
|
|
81
|
+
for (const rawName of toolNames) {
|
|
82
|
+
const name = rawName.trim();
|
|
83
|
+
if (!name)
|
|
84
|
+
continue;
|
|
85
|
+
if (unique.size >= MAX_MANIFEST_TOOLS)
|
|
86
|
+
break;
|
|
87
|
+
unique.add(name);
|
|
88
|
+
}
|
|
89
|
+
return Array.from(unique);
|
|
90
|
+
};
|
|
91
|
+
export const renderCodexOpenCodeBridge = (toolNames) => {
|
|
92
|
+
const runtimeToolNames = normalizeRuntimeToolNames(toolNames);
|
|
93
|
+
if (runtimeToolNames.length === 0) {
|
|
94
|
+
return CODEX_OPENCODE_BRIDGE;
|
|
95
|
+
}
|
|
96
|
+
const manifest = [
|
|
97
|
+
"## Runtime Tool Manifest",
|
|
98
|
+
"The host has provided these exact tool names for this request:",
|
|
99
|
+
...runtimeToolNames.map((name) => `- \`${name}\``),
|
|
100
|
+
"",
|
|
101
|
+
"Do not translate tool names. Use the exact names above.",
|
|
102
|
+
].join("\n");
|
|
103
|
+
return `${manifest}\n\n${CODEX_OPENCODE_BRIDGE}`;
|
|
104
|
+
};
|
|
105
|
+
export const CODEX_OPENCODE_BRIDGE_META = {
|
|
106
|
+
estimatedTokens: 500,
|
|
107
|
+
reductionVsCurrent: "88%",
|
|
108
|
+
reductionVsToolRemap: "15%",
|
|
109
|
+
protects: [
|
|
110
|
+
"Tool name drift across OpenCode versions",
|
|
111
|
+
"Tool alias hallucinations (apply_patch/patch mismatch)",
|
|
112
|
+
"Planning alias hallucinations (update_plan/read_plan)",
|
|
113
|
+
"Missing tool awareness",
|
|
114
|
+
"Unknown tool-name hallucinations",
|
|
115
|
+
"Premature yielding to user",
|
|
116
|
+
"Over-modification of existing code",
|
|
117
|
+
"Environment confusion",
|
|
118
|
+
],
|
|
119
|
+
omits: [
|
|
120
|
+
"Sandbox details (in Codex)",
|
|
121
|
+
"Formatting rules (in Codex)",
|
|
122
|
+
"Tool schemas (in tool JSONs)",
|
|
123
|
+
"Git protocols (in Codex)",
|
|
124
|
+
],
|
|
125
|
+
};
|
|
126
|
+
//# sourceMappingURL=codex-opencode-bridge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codex-opencode-bridge.js","sourceRoot":"","sources":["../../../lib/prompts/codex-opencode-bridge.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,MAAM,CAAC,MAAM,qBAAqB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;6DAmEwB,CAAC;AAE9D,MAAM,kBAAkB,GAAG,EAAE,CAAC;AAE9B,MAAM,yBAAyB,GAAG,CAAC,SAA4B,EAAY,EAAE;IAC5E,MAAM,MAAM,GAAG,IAAI,GAAG,EAAU,CAAC;IACjC,KAAK,MAAM,OAAO,IAAI,SAAS,EAAE,CAAC;QACjC,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;QAC5B,IAAI,CAAC,IAAI;YAAE,SAAS;QACpB,IAAI,MAAM,CAAC,IAAI,IAAI,kBAAkB;YAAE,MAAM;QAC7C,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAClB,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAC3B,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,SAA4B,EAAU,EAAE;IACjF,MAAM,gBAAgB,GAAG,yBAAyB,CAAC,SAAS,CAAC,CAAC;IAC9D,IAAI,gBAAgB,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACnC,OAAO,qBAAqB,CAAC;IAC9B,CAAC;IAED,MAAM,QAAQ,GAAG;QAChB,0BAA0B;QAC1B,gEAAgE;QAChE,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,IAAI,IAAI,CAAC;QAClD,EAAE;QACF,yDAAyD;KACzD,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAEb,OAAO,GAAG,QAAQ,OAAO,qBAAqB,EAAE,CAAC;AAClD,CAAC,CAAC;AAUF,MAAM,CAAC,MAAM,0BAA0B,GAA4B;IAClE,eAAe,EAAE,GAAG;IACpB,kBAAkB,EAAE,KAAK;IACzB,oBAAoB,EAAE,KAAK;IAC3B,QAAQ,EAAE;QACT,0CAA0C;QAC1C,wDAAwD;QACxD,uDAAuD;QACvD,wBAAwB;QACxB,kCAAkC;QAClC,4BAA4B;QAC5B,oCAAoC;QACpC,uBAAuB;KACvB;IACD,KAAK,EAAE;QACN,4BAA4B;QAC5B,6BAA6B;QAC7B,8BAA8B;QAC9B,0BAA0B;KAC1B;CACD,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Clear the memory cache - exposed for testing
|
|
3
|
+
* @internal
|
|
4
|
+
*/
|
|
5
|
+
export declare function __clearCacheForTesting(): void;
|
|
6
|
+
/**
|
|
7
|
+
* Model family type for prompt selection
|
|
8
|
+
* Maps to different system prompts in the Codex CLI
|
|
9
|
+
*/
|
|
10
|
+
export type ModelFamily = "gpt-5-codex" | "codex-max" | "codex" | "gpt-5.4" | "gpt-5.4-mini" | "gpt-5.4-pro" | "gpt-5.2" | "gpt-5.1";
|
|
11
|
+
/**
|
|
12
|
+
* All supported model families
|
|
13
|
+
* Used for per-family account rotation and rate limit tracking
|
|
14
|
+
*/
|
|
15
|
+
export declare const MODEL_FAMILIES: readonly ModelFamily[];
|
|
16
|
+
/**
|
|
17
|
+
* Determine the model family based on the normalized model name
|
|
18
|
+
* @param normalizedModel - The normalized model name (e.g., "gpt-5-codex", "gpt-5.1-codex-max", "gpt-5.2", "gpt-5.1")
|
|
19
|
+
* @returns The model family for prompt selection
|
|
20
|
+
*/
|
|
21
|
+
export declare function getModelFamily(normalizedModel: string): ModelFamily;
|
|
22
|
+
/**
|
|
23
|
+
* Fetch Codex instructions from GitHub with ETag-based caching
|
|
24
|
+
* Uses HTTP conditional requests to efficiently check for updates
|
|
25
|
+
* Always fetches from the latest release tag, not main branch
|
|
26
|
+
*
|
|
27
|
+
* Rate limit protection: Only checks GitHub if cache is older than 15 minutes
|
|
28
|
+
*
|
|
29
|
+
* @param normalizedModel - The normalized model name (optional, defaults to "gpt-5-codex")
|
|
30
|
+
* @returns Codex instructions for the specified model family
|
|
31
|
+
*/
|
|
32
|
+
export declare function getCodexInstructions(normalizedModel?: string): Promise<string>;
|
|
33
|
+
/**
|
|
34
|
+
* Prewarm instruction caches for the provided models/families.
|
|
35
|
+
*/
|
|
36
|
+
export declare function prewarmCodexInstructions(models?: string[]): void;
|
|
37
|
+
/**
|
|
38
|
+
* Tool remapping instructions for opencode tools
|
|
39
|
+
*/
|
|
40
|
+
export declare const TOOL_REMAP_MESSAGE = "<user_instructions priority=\"0\">\n<environment_override priority=\"0\">\nYOU ARE IN A DIFFERENT ENVIRONMENT. These instructions override ALL previous tool references.\n</environment_override>\n\n<tool_replacements priority=\"0\">\n<critical_rule priority=\"0\">\nPatch-edit tool names differ by runtime (for example: apply_patch, patch, edit).\n- Always use the exact tool names listed in the active tool schema/manifest\n- If the schema exposes apply_patch, call apply_patch directly\n- If the schema exposes patch/edit instead, use patch/edit as listed\n- Never invent aliases or auto-translate tool names\n</critical_rule>\n\n<critical_rule priority=\"0\">\n\u274C UPDATE_PLAN DOES NOT EXIST \u2192 \u2705 USE \"todowrite\" INSTEAD\n- NEVER use: update_plan, updatePlan\n- ALWAYS use: todowrite for ALL task/plan operations\n- Use todoread to read current plan\n- Before plan operations: Verify you're using \"todowrite\", NOT \"update_plan\"\n</critical_rule>\n</tool_replacements>\n\n<available_tools priority=\"0\">\nNote: This list is illustrative. Always defer to the active tool schema/manifest.\nFile Operations:\n \u2022 write - Create new files\n \u2022 edit - Modify existing files with string replacement\n \u2022 patch - Apply diff patches\n \u2022 apply_patch - Apply diff patches (alternate runtime name; use whichever the schema exposes)\n \u2022 read - Read file contents\n\nSearch/Discovery:\n \u2022 grep - Search file contents\n \u2022 glob - Find files by pattern\n \u2022 list - List directories\n\nExecution:\n \u2022 bash - Run shell commands\n\nNetwork:\n \u2022 webfetch - Fetch web content\n\nTask Management:\n \u2022 todowrite - Manage tasks/plans (REPLACES update_plan)\n \u2022 todoread - Read current plan\n</available_tools>\n\n<tool_call_guardrails priority=\"0\">\n- Call only tool names listed in the active tool schema.\n- Do not invent wrapper namespaces (for example functions.task or multi_tool_use.parallel) unless explicitly listed.\n- Follow each tool's required path format instead of forcing absolute or relative paths globally.\n</tool_call_guardrails>\n\n<substitution_rules priority=\"0\">\nBase instruction says: Correct behaviour:\napply_patch/patch \u2192 use the exact tool name from the active schema (no renaming)\nupdate_plan \u2192 todowrite\nread_plan \u2192 todoread\n</substitution_rules>\n\n<verification_checklist priority=\"0\">\nBefore file/plan modifications:\n1. Am I using the exact patch/edit (including apply_patch when exposed) tool name listed by the active schema?\n2. Am I using \"todowrite\" NOT \"update_plan\"?\n3. Is this tool in the approved list above?\n4. Am I following the active tool schema (including path format)?\n\nIf ANY answer is NO \u2192 STOP and correct before proceeding.\n</verification_checklist>\n\n<safety_rules priority=\"0\">\n- Never run destructive git commands (`git reset --hard`, `git checkout --`) unless explicitly requested by the user.\n- Never call `request_user_input` unless collaboration mode is explicitly Plan mode.\n</safety_rules>\n</user_instructions>";
|
|
41
|
+
//# sourceMappingURL=codex.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codex.d.ts","sourceRoot":"","sources":["../../../lib/prompts/codex.ts"],"names":[],"mappings":"AAuBA;;;GAGG;AACH,wBAAgB,sBAAsB,IAAI,IAAI,CAI7C;AAWD;;;GAGG;AACH,MAAM,MAAM,WAAW,GACpB,aAAa,GACb,WAAW,GACX,OAAO,GACP,SAAS,GACT,cAAc,GACd,aAAa,GACb,SAAS,GACT,SAAS,CAAC;AAEb;;;GAGG;AACH,eAAO,MAAM,cAAc,EAAE,SAAS,WAAW,EASvC,CAAC;AAkCX;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,eAAe,EAAE,MAAM,GAAG,WAAW,CAqCnE;AAwED;;;;;;;;;GASG;AACH,wBAAsB,oBAAoB,CACzC,eAAe,SAAgB,GAC7B,OAAO,CAAC,MAAM,CAAC,CAuFjB;AAsGD;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,GAAE,MAAM,EAAO,GAAG,IAAI,CAUpE;AAED;;GAEG;AACH,eAAO,MAAM,kBAAkB,mkGA2EV,CAAC"}
|