codex-multi-auth 2.23.0 → 2.24.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 (84) hide show
  1. package/.codex-plugin/plugin.json +9 -9
  2. package/LICENSE +21 -21
  3. package/README.md +159 -152
  4. package/assets/codex-multi-auth-icon.svg +39 -39
  5. package/assets/readme-hero.svg +31 -31
  6. package/config/README.md +31 -31
  7. package/config/codex-legacy.json +1021 -1021
  8. package/config/codex-modern.json +347 -347
  9. package/config/minimal-codex.json +15 -15
  10. package/dist/index.js +33 -10
  11. package/dist/lib/account-policy.d.ts +2 -0
  12. package/dist/lib/account-policy.js +3 -1
  13. package/dist/lib/accounts/rate-limits.d.ts +6 -0
  14. package/dist/lib/accounts/rate-limits.js +14 -1
  15. package/dist/lib/accounts.d.ts +6 -1
  16. package/dist/lib/accounts.js +33 -8
  17. package/dist/lib/auth/token-utils.d.ts +5 -0
  18. package/dist/lib/auth/token-utils.js +10 -0
  19. package/dist/lib/codex-manager/commands/account.js +15 -0
  20. package/dist/lib/codex-manager/commands/resets.js +18 -5
  21. package/dist/lib/codex-manager/commands/workspace.d.ts +4 -2
  22. package/dist/lib/codex-manager/commands/workspace.js +33 -2
  23. package/dist/lib/codex-manager/help.js +2 -2
  24. package/dist/lib/codex-manager.js +14 -1
  25. package/dist/lib/constants.d.ts +2 -0
  26. package/dist/lib/constants.js +2 -0
  27. package/dist/lib/context-budget-response.js +8 -8
  28. package/dist/lib/context-overflow.js +10 -10
  29. package/dist/lib/oauth-success.html +125 -125
  30. package/dist/lib/policy/runtime-policy-cache.js +1 -1
  31. package/dist/lib/policy/runtime-policy.d.ts +1 -0
  32. package/dist/lib/policy/runtime-policy.js +4 -0
  33. package/dist/lib/preemptive-quota-scheduler.js +12 -3
  34. package/dist/lib/prompts/codex-host-bridge.js +138 -138
  35. package/dist/lib/prompts/codex.js +79 -79
  36. package/dist/lib/quota-cache.d.ts +4 -0
  37. package/dist/lib/quota-readiness.d.ts +1 -1
  38. package/dist/lib/quota-readiness.js +9 -2
  39. package/dist/lib/request/rate-limit-decision.js +1 -1
  40. package/dist/lib/runtime/account-reset-credits.d.ts +11 -2
  41. package/dist/lib/runtime/account-reset-credits.js +35 -12
  42. package/dist/lib/runtime/automatic-account-checks.js +6 -5
  43. package/dist/lib/runtime/automatic-subscription-checks.js +4 -3
  44. package/dist/lib/runtime/model-discovery-status.js +2 -2
  45. package/dist/lib/runtime/reset-credit-routing.d.ts +11 -3
  46. package/dist/lib/runtime/reset-credit-routing.js +66 -21
  47. package/dist/lib/runtime/reset-credits.d.ts +31 -7
  48. package/dist/lib/runtime/reset-credits.js +135 -28
  49. package/dist/lib/runtime/rotation-proxy-state.d.ts +3 -0
  50. package/dist/lib/runtime/subscription-quota-order.d.ts +1 -0
  51. package/dist/lib/runtime/subscription-quota-order.js +7 -3
  52. package/dist/lib/runtime/workspace-model-scopes.d.ts +2 -0
  53. package/dist/lib/runtime/workspace-model-scopes.js +14 -4
  54. package/dist/lib/runtime-rotation-proxy.js +108 -29
  55. package/dist/lib/storage/snapshot-merge.js +15 -4
  56. package/dist/lib/web-dashboard-html.js +53 -53
  57. package/node_modules/@codex-ai/plugin/dist/index.d.ts +2 -2
  58. package/node_modules/@codex-ai/plugin/dist/index.js +2 -2
  59. package/node_modules/@codex-ai/plugin/dist/tool.d.ts +42 -42
  60. package/node_modules/@codex-ai/plugin/dist/tool.js +29 -29
  61. package/node_modules/@codex-ai/plugin/package.json +9 -9
  62. package/node_modules/@codex-ai/sdk/dist/index.d.ts +4 -4
  63. package/node_modules/@codex-ai/sdk/dist/index.js +2 -2
  64. package/node_modules/@codex-ai/sdk/package.json +8 -8
  65. package/package.json +209 -209
  66. package/scripts/codex-app-launcher.js +653 -653
  67. package/scripts/codex-app-router.js +446 -446
  68. package/scripts/codex-bin-resolver.js +332 -332
  69. package/scripts/codex-multi-auth.js +65 -65
  70. package/scripts/codex-routing.js +63 -63
  71. package/scripts/codex.js +7143 -7143
  72. package/scripts/install-codex-auth-utils.js +213 -213
  73. package/scripts/mcodex.js +367 -367
  74. package/scripts/postinstall.js +114 -114
  75. package/scripts/preuninstall.js +265 -265
  76. package/skills/codex-auth-setup/SKILL.md +73 -73
  77. package/vendor/codex-ai-plugin/dist/index.d.ts +2 -2
  78. package/vendor/codex-ai-plugin/dist/index.js +2 -2
  79. package/vendor/codex-ai-plugin/dist/tool.d.ts +42 -42
  80. package/vendor/codex-ai-plugin/dist/tool.js +29 -29
  81. package/vendor/codex-ai-plugin/package.json +9 -9
  82. package/vendor/codex-ai-sdk/dist/index.d.ts +4 -4
  83. package/vendor/codex-ai-sdk/dist/index.js +2 -2
  84. package/vendor/codex-ai-sdk/package.json +8 -8
@@ -33,16 +33,16 @@ export function isContextOverflowError(status, bodyText) {
33
33
  /**
34
34
  * The message shown to users when context overflow occurs
35
35
  */
36
- const CONTEXT_OVERFLOW_MESSAGE = `[Plugin Notice] Context is too long for this model.
37
-
38
- Please use one of these commands to reduce context size:
39
-
40
- • **/compact** - Compress conversation history (recommended)
41
- • **/clear** - Start fresh with empty context
42
- • **/undo** - Remove recent messages
43
-
44
- Then retry your request.
45
-
36
+ const CONTEXT_OVERFLOW_MESSAGE = `[Plugin Notice] Context is too long for this model.
37
+
38
+ Please use one of these commands to reduce context size:
39
+
40
+ • **/compact** - Compress conversation history (recommended)
41
+ • **/clear** - Start fresh with empty context
42
+ • **/undo** - Remove recent messages
43
+
44
+ Then retry your request.
45
+
46
46
  Alternatively, you can switch to a model with a larger context window.`;
47
47
  /**
48
48
  * Creates a synthetic SSE response for context overflow errors.
@@ -1,126 +1,126 @@
1
- <!doctype html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width, initial-scale=1" />
6
- <title>Codex Sign-In Complete</title>
7
- <style>
8
- :root {
9
- color-scheme: dark;
10
- --bg: #0b0b0b;
11
- --panel: #111111;
12
- --text: #f2f2f2;
13
- --muted: #a3a3a3;
14
- --line: #232323;
15
- --ok: #7cf0a6;
16
- }
17
-
18
- * {
19
- box-sizing: border-box;
20
- }
21
-
22
- body {
23
- margin: 0;
24
- min-height: 100vh;
25
- display: grid;
26
- place-items: center;
27
- background: var(--bg);
28
- color: var(--text);
29
- font-family: "Geist Mono", "GeistMono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
30
- padding: 24px;
31
- }
32
-
33
- main {
34
- width: min(520px, 100%);
35
- background: var(--panel);
36
- border: 1px solid var(--line);
37
- border-radius: 12px;
38
- padding: 20px;
39
- display: grid;
40
- gap: 14px;
41
- }
42
-
43
- h1 {
44
- margin: 0;
45
- font-size: 20px;
46
- font-weight: 600;
47
- letter-spacing: -0.02em;
48
- }
49
-
50
- p {
51
- margin: 0;
52
- color: var(--muted);
53
- font-size: 14px;
54
- line-height: 1.5;
55
- }
56
-
57
- .status {
58
- display: inline-flex;
59
- align-items: center;
60
- gap: 8px;
61
- color: var(--ok);
62
- font-size: 13px;
63
- }
64
-
65
- .dot {
66
- width: 8px;
67
- height: 8px;
68
- border-radius: 50%;
69
- background: currentColor;
70
- }
71
-
72
- dl {
73
- margin: 0;
74
- display: grid;
75
- grid-template-columns: 120px 1fr;
76
- gap: 8px 12px;
77
- font-size: 13px;
78
- }
79
-
80
- dt {
81
- color: var(--muted);
82
- }
83
-
84
- dd {
85
- margin: 0;
86
- color: var(--text);
87
- word-break: break-word;
88
- }
89
-
90
- code {
91
- background: #171717;
92
- border: 1px solid var(--line);
93
- border-radius: 6px;
94
- padding: 2px 6px;
95
- font-family: inherit;
96
- font-size: 12px;
97
- }
98
-
99
- @media (max-width: 520px) {
100
- dl {
101
- grid-template-columns: 1fr;
102
- }
103
- }
104
- </style>
105
- </head>
106
- <body>
107
- <main role="main" aria-label="OAuth callback received">
108
- <h1>Sign-in complete</h1>
109
- <p>Return to your terminal to finish Codex login.</p>
110
-
111
- <div class="status" aria-live="polite">
112
- <span class="dot" aria-hidden="true"></span>
113
- Callback received
114
- </div>
115
-
116
- <dl>
117
- <dt>Endpoint</dt>
118
- <dd><code>localhost:1455</code></dd>
119
- <dt>Flow</dt>
120
- <dd>OAuth callback captured</dd>
121
- <dt>Next</dt>
122
- <dd>Close this tab and continue in terminal</dd>
123
- </dl>
124
- </main>
125
- </body>
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
6
+ <title>Codex Sign-In Complete</title>
7
+ <style>
8
+ :root {
9
+ color-scheme: dark;
10
+ --bg: #0b0b0b;
11
+ --panel: #111111;
12
+ --text: #f2f2f2;
13
+ --muted: #a3a3a3;
14
+ --line: #232323;
15
+ --ok: #7cf0a6;
16
+ }
17
+
18
+ * {
19
+ box-sizing: border-box;
20
+ }
21
+
22
+ body {
23
+ margin: 0;
24
+ min-height: 100vh;
25
+ display: grid;
26
+ place-items: center;
27
+ background: var(--bg);
28
+ color: var(--text);
29
+ font-family: "Geist Mono", "GeistMono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
30
+ padding: 24px;
31
+ }
32
+
33
+ main {
34
+ width: min(520px, 100%);
35
+ background: var(--panel);
36
+ border: 1px solid var(--line);
37
+ border-radius: 12px;
38
+ padding: 20px;
39
+ display: grid;
40
+ gap: 14px;
41
+ }
42
+
43
+ h1 {
44
+ margin: 0;
45
+ font-size: 20px;
46
+ font-weight: 600;
47
+ letter-spacing: -0.02em;
48
+ }
49
+
50
+ p {
51
+ margin: 0;
52
+ color: var(--muted);
53
+ font-size: 14px;
54
+ line-height: 1.5;
55
+ }
56
+
57
+ .status {
58
+ display: inline-flex;
59
+ align-items: center;
60
+ gap: 8px;
61
+ color: var(--ok);
62
+ font-size: 13px;
63
+ }
64
+
65
+ .dot {
66
+ width: 8px;
67
+ height: 8px;
68
+ border-radius: 50%;
69
+ background: currentColor;
70
+ }
71
+
72
+ dl {
73
+ margin: 0;
74
+ display: grid;
75
+ grid-template-columns: 120px 1fr;
76
+ gap: 8px 12px;
77
+ font-size: 13px;
78
+ }
79
+
80
+ dt {
81
+ color: var(--muted);
82
+ }
83
+
84
+ dd {
85
+ margin: 0;
86
+ color: var(--text);
87
+ word-break: break-word;
88
+ }
89
+
90
+ code {
91
+ background: #171717;
92
+ border: 1px solid var(--line);
93
+ border-radius: 6px;
94
+ padding: 2px 6px;
95
+ font-family: inherit;
96
+ font-size: 12px;
97
+ }
98
+
99
+ @media (max-width: 520px) {
100
+ dl {
101
+ grid-template-columns: 1fr;
102
+ }
103
+ }
104
+ </style>
105
+ </head>
106
+ <body>
107
+ <main role="main" aria-label="OAuth callback received">
108
+ <h1>Sign-in complete</h1>
109
+ <p>Return to your terminal to finish Codex login.</p>
110
+
111
+ <div class="status" aria-live="polite">
112
+ <span class="dot" aria-hidden="true"></span>
113
+ Callback received
114
+ </div>
115
+
116
+ <dl>
117
+ <dt>Endpoint</dt>
118
+ <dd><code>localhost:1455</code></dd>
119
+ <dt>Flow</dt>
120
+ <dd>OAuth callback captured</dd>
121
+ <dt>Next</dt>
122
+ <dd>Close this tab and continue in terminal</dd>
123
+ </dl>
124
+ </main>
125
+ </body>
126
126
  </html>
@@ -168,7 +168,7 @@ export function loadAccountPolicyStoreCached() {
168
168
  return loadStoreCached({
169
169
  path: getAccountPolicyPath(),
170
170
  cache: ACCOUNT_POLICY_CACHE,
171
- load: loadAccountPolicyStore,
171
+ load: () => loadAccountPolicyStore({ strict: true }),
172
172
  isEmptyStore: (store) => Object.keys(store.accounts).length === 0,
173
173
  });
174
174
  }
@@ -25,6 +25,7 @@ export interface RuntimePolicyDecision {
25
25
  blockedAccountReasons?: Record<number, string>;
26
26
  scoreBoostByAccount: Record<number, number>;
27
27
  priorityByAccount?: Record<number, number>;
28
+ emergencyAccountIndexes?: Set<number>;
28
29
  budgetEvaluations: BudgetGuardEvaluation[];
29
30
  }
30
31
  export interface RuntimePolicyState {
@@ -101,6 +101,7 @@ export async function evaluateRuntimePolicy(input) {
101
101
  const blockedAccountReasons = {};
102
102
  const scoreBoostByAccount = {};
103
103
  const priorityByAccount = {};
104
+ const emergencyAccountIndexes = new Set();
104
105
  const profile = input.state.project.profile;
105
106
  if (profile?.modelDenylist.length && matchesModel(profile.modelDenylist, input.model)) {
106
107
  reasons.push("routing profile denies requested model");
@@ -131,6 +132,8 @@ export async function evaluateRuntimePolicy(input) {
131
132
  }, account.index);
132
133
  const accountPolicy = input.state.accountPolicies.accounts[accountKey];
133
134
  priorityByAccount[account.index] = accountPolicy?.priority ?? 1;
135
+ if (accountPolicy?.emergencyOnly)
136
+ emergencyAccountIndexes.add(account.index);
134
137
  let boost = 0;
135
138
  if (accountPolicy?.paused) {
136
139
  blockedAccountIndexes.add(account.index);
@@ -186,6 +189,7 @@ export async function evaluateRuntimePolicy(input) {
186
189
  blockedAccountReasons,
187
190
  scoreBoostByAccount,
188
191
  priorityByAccount,
192
+ emergencyAccountIndexes,
189
193
  budgetEvaluations,
190
194
  };
191
195
  }
@@ -1,4 +1,4 @@
1
- import { MAX_RATE_LIMIT_DELAY_MS } from "./constants.js";
1
+ import { MAX_RATE_LIMIT_DELAY_MS, RATE_LIMIT_CACHE_TTL_MS } from "./constants.js";
2
2
  import { quotaLeftPercentFromUsed } from "./quota-readiness.js";
3
3
  const DEFAULT_REMAINING_PERCENT_THRESHOLD = 5;
4
4
  const DEFAULT_MAX_DEFERRAL_MS = 2 * 60 * 60_000;
@@ -219,6 +219,11 @@ export class PreemptiveQuotaScheduler {
219
219
  const snapshot = this.snapshots.get(key);
220
220
  if (!snapshot)
221
221
  return { defer: false, waitMs: 0 };
222
+ const cacheRemainingMs = snapshot.updatedAt + RATE_LIMIT_CACHE_TTL_MS - now;
223
+ if (cacheRemainingMs <= 0) {
224
+ this.snapshots.delete(key);
225
+ return { defer: false, waitMs: 0 };
226
+ }
222
227
  // For a 429 deferral, only count a window whose reset is genuinely a
223
228
  // rate-limit / exhaustion window. A window carrying a healthy usedPercent
224
229
  // (e.g. a weekly secondary at 30% from a prior 200 snapshot) is NOT the
@@ -239,7 +244,7 @@ export class PreemptiveQuotaScheduler {
239
244
  .filter((value) => value > 0);
240
245
  const longestWait = waitCandidates.length > 0 ? Math.max(...waitCandidates) : 0;
241
246
  if (snapshot.status === 429 && longestWait > 0) {
242
- const bounded = Math.min(longestWait, this.maxDeferralMs);
247
+ const bounded = Math.min(longestWait, this.maxDeferralMs, cacheRemainingMs);
243
248
  if (bounded > 0) {
244
249
  return { defer: true, waitMs: bounded, reason: "rate-limit" };
245
250
  }
@@ -260,7 +265,11 @@ export class PreemptiveQuotaScheduler {
260
265
  ? getNearExhaustedWait(snapshot.secondary)
261
266
  : 0);
262
267
  if (nearExhaustedWait > 0) {
263
- return { defer: true, waitMs: nearExhaustedWait, reason: "quota-near-exhaustion" };
268
+ return {
269
+ defer: true,
270
+ waitMs: Math.min(nearExhaustedWait, cacheRemainingMs),
271
+ reason: "quota-near-exhaustion",
272
+ };
264
273
  }
265
274
  return { defer: false, waitMs: 0 };
266
275
  }
@@ -7,142 +7,142 @@
7
7
  *
8
8
  * Token Count: ~450 tokens (~90% reduction vs full host prompt)
9
9
  */
10
- export const CODEX_HOST_BRIDGE = `# Codex Host Bridge
11
-
12
- You are running Codex through a host terminal coding runtime. The host provides specific tools to help you work efficiently.
13
-
14
- ## CRITICAL: Tool Usage
15
-
16
- <critical_rule priority="0">
17
- apply_patch/applyPatch are Codex names, but host tool names vary by version.
18
- - Inspect the actual tool list before editing.
19
- - If \`edit\` exists: use \`edit\` for precise in-place string replacements and hashline edits.
20
- - If \`edit\` is absent and \`apply_patch\` exists: use \`apply_patch\` for those precise/hashline edits in this plugin.
21
- - For diff-style or multi-line structural edits: use \`patch\` if available, otherwise use \`apply_patch\`.
22
- - In this plugin, \`edit\` / \`apply_patch\` also support hashline refs (\`lineRef\`, \`endLineRef\`, \`operation\`, \`content\`)
23
- </critical_rule>
24
-
25
- <critical_rule priority="0">
26
- UPDATE_PLAN DOES NOT EXIST -> USE "todowrite" INSTEAD
27
- - NEVER use: update_plan, updatePlan, read_plan, readPlan
28
- - ALWAYS use: todowrite for task/plan updates, todoread to read plans
29
- - Before plan operations: Verify you're using "todowrite", NOT "update_plan"
30
- </critical_rule>
31
-
32
- ## Available Host Tools
33
-
34
- **File Operations:**
35
- - \`write\` - Create new files
36
- - Overwriting existing files requires a prior Read in this session; default to ASCII unless the file already uses Unicode.
37
- - \`edit\` - Modify existing files with string replacement (version-dependent)
38
- - Requires a prior Read in this session; preserve exact indentation; ensure \`oldString\` uniquely matches or use \`replaceAll\`; edit fails if ambiguous or missing.
39
- - Never pass unresolved template placeholders in \`oldString\` (e.g. \`\${TARGET_SNIPPET}\`); \`oldString\` must be literal text copied from the current file.
40
- - For complex multi-line changes: break into multiple sequential edit calls, each with unique oldString context.
41
- - \`apply_patch\` - May be the edit/patch tool name in newer host builds (version-dependent)
42
- - In this plugin, \`apply_patch\` also accepts hashline edit args (\`path\`, \`lineRef\`, \`endLineRef\`, \`operation\`, \`content\`) when \`edit\` is not available.
43
- - \`hashline_read\` - Read file with hashline refs (\`L<line>#<hash>\`) for deterministic edits
44
- - \`patch\` - Apply diff-style patches for multi-line updates (version-dependent)
45
- - \`read\` - Read file contents
46
-
47
- Note: Tool naming is version-dependent. If \`edit\` is unavailable but \`apply_patch\` exists, use \`apply_patch\`.
48
-
49
- When available, prefer hashline workflow for reliability:
50
- 1. Call \`hashline_read\` for target file and capture refs.
51
- 2. Call \`edit\` or \`apply_patch\` with \`lineRef\` (and optional \`endLineRef\`) plus \`operation\` and \`content\`.
52
- 3. Use legacy \`oldString\` / \`newString\` only when hashline refs are unavailable, and only with literal file text (no template placeholders).
53
-
54
- **Search/Discovery:**
55
- - \`grep\` - Search file contents (tool, not bash grep); use \`include\` to filter patterns; set \`path\` only when not searching workspace root; for cross-file match counts use bash with \`rg\`.
56
- - \`glob\` - Find files by pattern; defaults to workspace cwd unless \`path\` is set.
57
- - \`list\` - List directories (requires absolute paths)
58
-
59
- **Execution:**
60
- - \`bash\` - Run shell commands
61
- - No workdir parameter; do not include it in tool calls.
62
- - Always include a short description for the command.
63
- - Do not use cd; use absolute paths in commands.
64
- - Quote paths containing spaces with double quotes.
65
- - Chain multiple commands with ';' or '&&'; avoid newlines.
66
- - Use Grep/Glob tools for searches; only use bash with \`rg\` when you need counts or advanced features.
67
- - Do not use \`ls\`/\`cat\` in bash; use \`list\`/\`read\` tools instead.
68
- - For deletions (rm), verify by listing parent dir with \`list\`.
69
-
70
- **Network:**
71
- - \`webfetch\` - Fetch web content
72
- - Use fully-formed URLs (http/https; http auto-upgrades to https).
73
- - Always set \`format\` to one of: text | markdown | html; prefer markdown unless otherwise required.
74
- - Read-only; short cache window.
75
-
76
- **Task Management:**
77
- - \`todowrite\` - Manage tasks/plans (REPLACES update_plan)
78
- - \`todoread\` - Read current plan
79
-
80
- ## Substitution Rules
81
-
82
- Base instruction says: You MUST use instead:
83
- apply_patch -> patch (preferred if available), otherwise edit/apply_patch based on actual tool list
84
- update_plan -> todowrite
85
- read_plan -> todoread
86
-
87
- **Path Usage:** Use per-tool conventions to avoid conflicts:
88
- - Tool calls: \`read\`, \`edit\`, \`write\`, \`list\` require absolute paths.
89
- - Searches: \`grep\`/\`glob\` default to the workspace cwd; prefer relative include patterns; set \`path\` only when a different root is needed.
90
- - Presentation: In assistant messages, show workspace-relative paths; use absolute paths only inside tool calls.
91
- - Tool schema overrides general path preferences-do not convert required absolute paths to relative.
92
-
93
- ## Verification Checklist
94
-
95
- Before file/plan modifications:
96
- 1. Am I using the actual available edit tool name (\`edit\`, \`patch\`, or \`apply_patch\`)?
97
- 2. Am I using "todowrite" NOT "update_plan"?
98
- 3. Is this tool in the approved list above?
99
- 4. Am I following each tool's path requirements?
100
-
101
- If ANY answer is NO -> STOP and correct before proceeding.
102
-
103
- ## Host Working Style
104
-
105
- **Communication:**
106
- - Send brief preambles (8-12 words) before tool calls, building on prior context
107
- - Provide progress updates during longer tasks
108
-
109
- **Execution:**
110
- - Keep working autonomously until query is fully resolved before yielding
111
- - Don't return to user with partial solutions
112
-
113
- **Code Approach:**
114
- - New projects: Be ambitious and creative
115
- - Existing codebases: Surgical precision - modify only what's requested unless explicitly instructed to do otherwise
116
-
117
- **Testing:**
118
- - If tests exist: Start specific to your changes, then broader validation
119
-
120
- ## Advanced Tools
121
-
122
- **Task Tool (Sub-Agents):**
123
- - Use the Task tool (functions.task) to launch sub-agents
124
- - Check the Task tool description for current agent types and their capabilities
125
- - Useful for complex analysis, specialized workflows, or tasks requiring isolated context
126
- - The agent list is dynamically generated - refer to tool schema for available agents
127
-
128
- **Parallelization:**
129
- - When multiple independent tool calls are needed, use multi_tool_use.parallel to run them concurrently.
130
- - Reserve sequential calls for ordered or data-dependent steps.
131
-
132
- **MCP Tools:**
133
- - Model Context Protocol servers provide additional capabilities
134
- - MCP tools are prefixed: \`mcp__<server-name>__<tool-name>\`
135
- - Check your available tools for MCP integrations
136
- - Use when the tool's functionality matches your task needs
137
-
138
- ## What Remains from Codex
139
-
140
- Sandbox policies, approval mechanisms, final answer formatting, git commit protocols, and file reference formats all follow Codex instructions. In approval policy "never", never request escalations.
141
-
142
- ## Approvals & Safety
143
- - Assume workspace-write filesystem, network enabled, approval on-failure unless explicitly stated otherwise.
144
- - When a command fails due to sandboxing or permissions, retry with escalated permissions if allowed by policy, including a one-line justification.
145
- - Treat destructive commands (e.g., \`rm\`, \`git reset --hard\`) as requiring explicit user request or approval.
146
- - Never run \`git reset --hard\`, \`git checkout --\`, or force deletes unless the user explicitly asked for that exact action.
147
- - \`request_user_input\` is Plan-mode only; do not call it in Default mode.
10
+ export const CODEX_HOST_BRIDGE = `# Codex Host Bridge
11
+
12
+ You are running Codex through a host terminal coding runtime. The host provides specific tools to help you work efficiently.
13
+
14
+ ## CRITICAL: Tool Usage
15
+
16
+ <critical_rule priority="0">
17
+ apply_patch/applyPatch are Codex names, but host tool names vary by version.
18
+ - Inspect the actual tool list before editing.
19
+ - If \`edit\` exists: use \`edit\` for precise in-place string replacements and hashline edits.
20
+ - If \`edit\` is absent and \`apply_patch\` exists: use \`apply_patch\` for those precise/hashline edits in this plugin.
21
+ - For diff-style or multi-line structural edits: use \`patch\` if available, otherwise use \`apply_patch\`.
22
+ - In this plugin, \`edit\` / \`apply_patch\` also support hashline refs (\`lineRef\`, \`endLineRef\`, \`operation\`, \`content\`)
23
+ </critical_rule>
24
+
25
+ <critical_rule priority="0">
26
+ UPDATE_PLAN DOES NOT EXIST -> USE "todowrite" INSTEAD
27
+ - NEVER use: update_plan, updatePlan, read_plan, readPlan
28
+ - ALWAYS use: todowrite for task/plan updates, todoread to read plans
29
+ - Before plan operations: Verify you're using "todowrite", NOT "update_plan"
30
+ </critical_rule>
31
+
32
+ ## Available Host Tools
33
+
34
+ **File Operations:**
35
+ - \`write\` - Create new files
36
+ - Overwriting existing files requires a prior Read in this session; default to ASCII unless the file already uses Unicode.
37
+ - \`edit\` - Modify existing files with string replacement (version-dependent)
38
+ - Requires a prior Read in this session; preserve exact indentation; ensure \`oldString\` uniquely matches or use \`replaceAll\`; edit fails if ambiguous or missing.
39
+ - Never pass unresolved template placeholders in \`oldString\` (e.g. \`\${TARGET_SNIPPET}\`); \`oldString\` must be literal text copied from the current file.
40
+ - For complex multi-line changes: break into multiple sequential edit calls, each with unique oldString context.
41
+ - \`apply_patch\` - May be the edit/patch tool name in newer host builds (version-dependent)
42
+ - In this plugin, \`apply_patch\` also accepts hashline edit args (\`path\`, \`lineRef\`, \`endLineRef\`, \`operation\`, \`content\`) when \`edit\` is not available.
43
+ - \`hashline_read\` - Read file with hashline refs (\`L<line>#<hash>\`) for deterministic edits
44
+ - \`patch\` - Apply diff-style patches for multi-line updates (version-dependent)
45
+ - \`read\` - Read file contents
46
+
47
+ Note: Tool naming is version-dependent. If \`edit\` is unavailable but \`apply_patch\` exists, use \`apply_patch\`.
48
+
49
+ When available, prefer hashline workflow for reliability:
50
+ 1. Call \`hashline_read\` for target file and capture refs.
51
+ 2. Call \`edit\` or \`apply_patch\` with \`lineRef\` (and optional \`endLineRef\`) plus \`operation\` and \`content\`.
52
+ 3. Use legacy \`oldString\` / \`newString\` only when hashline refs are unavailable, and only with literal file text (no template placeholders).
53
+
54
+ **Search/Discovery:**
55
+ - \`grep\` - Search file contents (tool, not bash grep); use \`include\` to filter patterns; set \`path\` only when not searching workspace root; for cross-file match counts use bash with \`rg\`.
56
+ - \`glob\` - Find files by pattern; defaults to workspace cwd unless \`path\` is set.
57
+ - \`list\` - List directories (requires absolute paths)
58
+
59
+ **Execution:**
60
+ - \`bash\` - Run shell commands
61
+ - No workdir parameter; do not include it in tool calls.
62
+ - Always include a short description for the command.
63
+ - Do not use cd; use absolute paths in commands.
64
+ - Quote paths containing spaces with double quotes.
65
+ - Chain multiple commands with ';' or '&&'; avoid newlines.
66
+ - Use Grep/Glob tools for searches; only use bash with \`rg\` when you need counts or advanced features.
67
+ - Do not use \`ls\`/\`cat\` in bash; use \`list\`/\`read\` tools instead.
68
+ - For deletions (rm), verify by listing parent dir with \`list\`.
69
+
70
+ **Network:**
71
+ - \`webfetch\` - Fetch web content
72
+ - Use fully-formed URLs (http/https; http auto-upgrades to https).
73
+ - Always set \`format\` to one of: text | markdown | html; prefer markdown unless otherwise required.
74
+ - Read-only; short cache window.
75
+
76
+ **Task Management:**
77
+ - \`todowrite\` - Manage tasks/plans (REPLACES update_plan)
78
+ - \`todoread\` - Read current plan
79
+
80
+ ## Substitution Rules
81
+
82
+ Base instruction says: You MUST use instead:
83
+ apply_patch -> patch (preferred if available), otherwise edit/apply_patch based on actual tool list
84
+ update_plan -> todowrite
85
+ read_plan -> todoread
86
+
87
+ **Path Usage:** Use per-tool conventions to avoid conflicts:
88
+ - Tool calls: \`read\`, \`edit\`, \`write\`, \`list\` require absolute paths.
89
+ - Searches: \`grep\`/\`glob\` default to the workspace cwd; prefer relative include patterns; set \`path\` only when a different root is needed.
90
+ - Presentation: In assistant messages, show workspace-relative paths; use absolute paths only inside tool calls.
91
+ - Tool schema overrides general path preferences-do not convert required absolute paths to relative.
92
+
93
+ ## Verification Checklist
94
+
95
+ Before file/plan modifications:
96
+ 1. Am I using the actual available edit tool name (\`edit\`, \`patch\`, or \`apply_patch\`)?
97
+ 2. Am I using "todowrite" NOT "update_plan"?
98
+ 3. Is this tool in the approved list above?
99
+ 4. Am I following each tool's path requirements?
100
+
101
+ If ANY answer is NO -> STOP and correct before proceeding.
102
+
103
+ ## Host Working Style
104
+
105
+ **Communication:**
106
+ - Send brief preambles (8-12 words) before tool calls, building on prior context
107
+ - Provide progress updates during longer tasks
108
+
109
+ **Execution:**
110
+ - Keep working autonomously until query is fully resolved before yielding
111
+ - Don't return to user with partial solutions
112
+
113
+ **Code Approach:**
114
+ - New projects: Be ambitious and creative
115
+ - Existing codebases: Surgical precision - modify only what's requested unless explicitly instructed to do otherwise
116
+
117
+ **Testing:**
118
+ - If tests exist: Start specific to your changes, then broader validation
119
+
120
+ ## Advanced Tools
121
+
122
+ **Task Tool (Sub-Agents):**
123
+ - Use the Task tool (functions.task) to launch sub-agents
124
+ - Check the Task tool description for current agent types and their capabilities
125
+ - Useful for complex analysis, specialized workflows, or tasks requiring isolated context
126
+ - The agent list is dynamically generated - refer to tool schema for available agents
127
+
128
+ **Parallelization:**
129
+ - When multiple independent tool calls are needed, use multi_tool_use.parallel to run them concurrently.
130
+ - Reserve sequential calls for ordered or data-dependent steps.
131
+
132
+ **MCP Tools:**
133
+ - Model Context Protocol servers provide additional capabilities
134
+ - MCP tools are prefixed: \`mcp__<server-name>__<tool-name>\`
135
+ - Check your available tools for MCP integrations
136
+ - Use when the tool's functionality matches your task needs
137
+
138
+ ## What Remains from Codex
139
+
140
+ Sandbox policies, approval mechanisms, final answer formatting, git commit protocols, and file reference formats all follow Codex instructions. In approval policy "never", never request escalations.
141
+
142
+ ## Approvals & Safety
143
+ - Assume workspace-write filesystem, network enabled, approval on-failure unless explicitly stated otherwise.
144
+ - When a command fails due to sandboxing or permissions, retry with escalated permissions if allowed by policy, including a one-line justification.
145
+ - Treat destructive commands (e.g., \`rm\`, \`git reset --hard\`) as requiring explicit user request or approval.
146
+ - Never run \`git reset --hard\`, \`git checkout --\`, or force deletes unless the user explicitly asked for that exact action.
147
+ - \`request_user_input\` is Plan-mode only; do not call it in Default mode.
148
148
  - When uncertain, prefer non-destructive verification first (e.g., confirm file existence with \`list\`, then delete with \`bash\`).`;