oc-chatgpt-multi-auth 4.9.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 (134) hide show
  1. package/LICENSE +37 -0
  2. package/README.md +507 -0
  3. package/assets/opencode-logo-ornate-dark.svg +18 -0
  4. package/assets/readme-hero.svg +31 -0
  5. package/config/README.md +110 -0
  6. package/config/minimal-opencode.json +13 -0
  7. package/config/opencode-legacy.json +572 -0
  8. package/config/opencode-modern.json +240 -0
  9. package/dist/index.d.ts +45 -0
  10. package/dist/index.d.ts.map +1 -0
  11. package/dist/index.js +971 -0
  12. package/dist/index.js.map +1 -0
  13. package/dist/lib/accounts.d.ts +120 -0
  14. package/dist/lib/accounts.d.ts.map +1 -0
  15. package/dist/lib/accounts.js +579 -0
  16. package/dist/lib/accounts.js.map +1 -0
  17. package/dist/lib/auth/auth.d.ts +51 -0
  18. package/dist/lib/auth/auth.d.ts.map +1 -0
  19. package/dist/lib/auth/auth.js +180 -0
  20. package/dist/lib/auth/auth.js.map +1 -0
  21. package/dist/lib/auth/browser.d.ts +17 -0
  22. package/dist/lib/auth/browser.d.ts.map +1 -0
  23. package/dist/lib/auth/browser.js +83 -0
  24. package/dist/lib/auth/browser.js.map +1 -0
  25. package/dist/lib/auth/server.d.ts +10 -0
  26. package/dist/lib/auth/server.d.ts.map +1 -0
  27. package/dist/lib/auth/server.js +85 -0
  28. package/dist/lib/auth/server.js.map +1 -0
  29. package/dist/lib/auto-update-checker.d.ts +10 -0
  30. package/dist/lib/auto-update-checker.d.ts.map +1 -0
  31. package/dist/lib/auto-update-checker.js +129 -0
  32. package/dist/lib/auto-update-checker.js.map +1 -0
  33. package/dist/lib/cli.d.ts +9 -0
  34. package/dist/lib/cli.d.ts.map +1 -0
  35. package/dist/lib/cli.js +50 -0
  36. package/dist/lib/cli.js.map +1 -0
  37. package/dist/lib/config.d.ts +17 -0
  38. package/dist/lib/config.d.ts.map +1 -0
  39. package/dist/lib/config.js +102 -0
  40. package/dist/lib/config.js.map +1 -0
  41. package/dist/lib/constants.d.ts +74 -0
  42. package/dist/lib/constants.d.ts.map +1 -0
  43. package/dist/lib/constants.js +74 -0
  44. package/dist/lib/constants.js.map +1 -0
  45. package/dist/lib/context-overflow.d.ts +27 -0
  46. package/dist/lib/context-overflow.d.ts.map +1 -0
  47. package/dist/lib/context-overflow.js +124 -0
  48. package/dist/lib/context-overflow.js.map +1 -0
  49. package/dist/lib/index.d.ts +13 -0
  50. package/dist/lib/index.d.ts.map +1 -0
  51. package/dist/lib/index.js +13 -0
  52. package/dist/lib/index.js.map +1 -0
  53. package/dist/lib/logger.d.ts +22 -0
  54. package/dist/lib/logger.d.ts.map +1 -0
  55. package/dist/lib/logger.js +175 -0
  56. package/dist/lib/logger.js.map +1 -0
  57. package/dist/lib/oauth-success.html +712 -0
  58. package/dist/lib/prompts/codex-opencode-bridge.d.ts +19 -0
  59. package/dist/lib/prompts/codex-opencode-bridge.d.ts.map +1 -0
  60. package/dist/lib/prompts/codex-opencode-bridge.js +152 -0
  61. package/dist/lib/prompts/codex-opencode-bridge.js.map +1 -0
  62. package/dist/lib/prompts/codex.d.ts +32 -0
  63. package/dist/lib/prompts/codex.d.ts.map +1 -0
  64. package/dist/lib/prompts/codex.js +262 -0
  65. package/dist/lib/prompts/codex.js.map +1 -0
  66. package/dist/lib/prompts/opencode-codex.d.ts +21 -0
  67. package/dist/lib/prompts/opencode-codex.d.ts.map +1 -0
  68. package/dist/lib/prompts/opencode-codex.js +91 -0
  69. package/dist/lib/prompts/opencode-codex.js.map +1 -0
  70. package/dist/lib/recovery/constants.d.ts +12 -0
  71. package/dist/lib/recovery/constants.d.ts.map +1 -0
  72. package/dist/lib/recovery/constants.js +25 -0
  73. package/dist/lib/recovery/constants.js.map +1 -0
  74. package/dist/lib/recovery/index.d.ts +12 -0
  75. package/dist/lib/recovery/index.d.ts.map +1 -0
  76. package/dist/lib/recovery/index.js +12 -0
  77. package/dist/lib/recovery/index.js.map +1 -0
  78. package/dist/lib/recovery/storage.d.ts +24 -0
  79. package/dist/lib/recovery/storage.d.ts.map +1 -0
  80. package/dist/lib/recovery/storage.js +354 -0
  81. package/dist/lib/recovery/storage.js.map +1 -0
  82. package/dist/lib/recovery/types.d.ts +116 -0
  83. package/dist/lib/recovery/types.d.ts.map +1 -0
  84. package/dist/lib/recovery/types.js +7 -0
  85. package/dist/lib/recovery/types.js.map +1 -0
  86. package/dist/lib/recovery.d.ts +31 -0
  87. package/dist/lib/recovery.d.ts.map +1 -0
  88. package/dist/lib/recovery.js +308 -0
  89. package/dist/lib/recovery.js.map +1 -0
  90. package/dist/lib/refresh-queue.d.ts +100 -0
  91. package/dist/lib/refresh-queue.d.ts.map +1 -0
  92. package/dist/lib/refresh-queue.js +196 -0
  93. package/dist/lib/refresh-queue.js.map +1 -0
  94. package/dist/lib/request/fetch-helpers.d.ts +81 -0
  95. package/dist/lib/request/fetch-helpers.d.ts.map +1 -0
  96. package/dist/lib/request/fetch-helpers.js +325 -0
  97. package/dist/lib/request/fetch-helpers.js.map +1 -0
  98. package/dist/lib/request/helpers/input-utils.d.ts +7 -0
  99. package/dist/lib/request/helpers/input-utils.d.ts.map +1 -0
  100. package/dist/lib/request/helpers/input-utils.js +213 -0
  101. package/dist/lib/request/helpers/input-utils.js.map +1 -0
  102. package/dist/lib/request/helpers/model-map.d.ts +28 -0
  103. package/dist/lib/request/helpers/model-map.d.ts.map +1 -0
  104. package/dist/lib/request/helpers/model-map.js +109 -0
  105. package/dist/lib/request/helpers/model-map.js.map +1 -0
  106. package/dist/lib/request/rate-limit-backoff.d.ts +17 -0
  107. package/dist/lib/request/rate-limit-backoff.d.ts.map +1 -0
  108. package/dist/lib/request/rate-limit-backoff.js +74 -0
  109. package/dist/lib/request/rate-limit-backoff.js.map +1 -0
  110. package/dist/lib/request/request-transformer.d.ts +93 -0
  111. package/dist/lib/request/request-transformer.d.ts.map +1 -0
  112. package/dist/lib/request/request-transformer.js +405 -0
  113. package/dist/lib/request/request-transformer.js.map +1 -0
  114. package/dist/lib/request/response-handler.d.ts +14 -0
  115. package/dist/lib/request/response-handler.d.ts.map +1 -0
  116. package/dist/lib/request/response-handler.js +90 -0
  117. package/dist/lib/request/response-handler.js.map +1 -0
  118. package/dist/lib/rotation.d.ts +121 -0
  119. package/dist/lib/rotation.d.ts.map +1 -0
  120. package/dist/lib/rotation.js +248 -0
  121. package/dist/lib/rotation.js.map +1 -0
  122. package/dist/lib/storage.d.ts +91 -0
  123. package/dist/lib/storage.d.ts.map +1 -0
  124. package/dist/lib/storage.js +323 -0
  125. package/dist/lib/storage.js.map +1 -0
  126. package/dist/lib/types.d.ts +185 -0
  127. package/dist/lib/types.d.ts.map +1 -0
  128. package/dist/lib/types.js +2 -0
  129. package/dist/lib/types.js.map +1 -0
  130. package/package.json +86 -0
  131. package/scripts/copy-oauth-success.js +37 -0
  132. package/scripts/install-opencode-codex-auth.js +193 -0
  133. package/scripts/test-all-models.sh +260 -0
  134. package/scripts/validate-model-map.sh +97 -0
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Codex-OpenCode Bridge Prompt
3
+ *
4
+ * This prompt bridges Codex CLI instructions to the OpenCode environment.
5
+ * It incorporates critical tool mappings, available tools list, substitution rules,
6
+ * and verification checklist to ensure proper tool usage.
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. OpenCode provides different tools but follows Codex operating principles.\n\n## CRITICAL: Tool Replacements\n\n<critical_rule priority=\"0\">\n\u274C APPLY_PATCH DOES NOT EXIST \u2192 \u2705 USE \"edit\" INSTEAD\n- NEVER use: apply_patch, applyPatch\n- ALWAYS use: edit tool for ALL file modifications\n- Before modifying files: Verify you're using \"edit\", NOT \"apply_patch\"\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, read_plan, readPlan\n- ALWAYS use: todowrite for task/plan updates, todoread to read plans\n- Before plan operations: Verify you're using \"todowrite\", NOT \"update_plan\"\n</critical_rule>\n\n## Available OpenCode Tools\n\n**File Operations:**\n- `write` - Create new files\n - Overwriting existing files requires a prior Read in this session; default to ASCII unless the file already uses Unicode.\n- `edit` - Modify existing files (REPLACES apply_patch)\n - Requires a prior Read in this session; preserve exact indentation; ensure `oldString` uniquely matches or use `replaceAll`; edit fails if ambiguous or missing.\n- `read` - Read file contents\n\n**Search/Discovery:**\n- `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`.\n- `glob` - Find files by pattern; defaults to workspace cwd unless `path` is set.\n- `list` - List directories (requires absolute paths)\n\n**Execution:**\n- `bash` - Run shell commands\n - No workdir parameter; do not include it in tool calls.\n - Always include a short description for the command.\n - Do not use cd; use absolute paths in commands.\n - Quote paths containing spaces with double quotes.\n - Chain multiple commands with ';' or '&&'; avoid newlines.\n - Use Grep/Glob tools for searches; only use bash with `rg` when you need counts or advanced features.\n - Do not use `ls`/`cat` in bash; use `list`/`read` tools instead.\n - For deletions (rm), verify by listing parent dir with `list`.\n\n**Network:**\n- `webfetch` - Fetch web content\n - Use fully-formed URLs (http/https; http auto-upgrades to https).\n - Always set `format` to one of: text | markdown | html; prefer markdown unless otherwise required.\n - Read-only; short cache window.\n\n**Task Management:**\n- `todowrite` - Manage tasks/plans (REPLACES update_plan)\n- `todoread` - Read current plan\n\n## Substitution Rules\n\nBase instruction says: You MUST use instead:\napply_patch \u2192 edit\nupdate_plan \u2192 todowrite\nread_plan \u2192 todoread\n\n**Path Usage:** Use per-tool conventions to avoid conflicts:\n- Tool calls: `read`, `edit`, `write`, `list` require absolute paths.\n- Searches: `grep`/`glob` default to the workspace cwd; prefer relative include patterns; set `path` only when a different root is needed.\n- Presentation: In assistant messages, show workspace-relative paths; use absolute paths only inside tool calls.\n- Tool schema overrides general path preferences\u2014do not convert required absolute paths to relative.\n\n## Verification Checklist\n\nBefore file/plan modifications:\n1. Am I using \"edit\" NOT \"apply_patch\"?\n2. Am I using \"todowrite\" NOT \"update_plan\"?\n3. Is this tool in the approved list above?\n4. Am I following each tool's path requirements?\n\nIf ANY answer is NO \u2192 STOP and correct before proceeding.\n\n## OpenCode Working Style\n\n**Communication:**\n- Send brief preambles (8-12 words) before tool calls, building on prior context\n- Provide progress updates during longer tasks\n\n**Execution:**\n- Keep working autonomously until query is fully resolved before yielding\n- Don't return to user with partial solutions\n\n**Code Approach:**\n- New projects: Be ambitious and creative\n- Existing codebases: Surgical precision - modify only what's requested unless explicitly instructed to do otherwise\n\n**Testing:**\n- If tests exist: Start specific to your changes, then broader validation\n\n## Advanced Tools\n\n**Task Tool (Sub-Agents):**\n- Use the Task tool (functions.task) to launch sub-agents\n- Check the Task tool description for current agent types and their capabilities\n- Useful for complex analysis, specialized workflows, or tasks requiring isolated context\n- The agent list is dynamically generated - refer to tool schema for available agents\n\n**Parallelization:**\n- When multiple independent tool calls are needed, use multi_tool_use.parallel to run them concurrently.\n- Reserve sequential calls for ordered or data-dependent steps.\n\n**MCP Tools:**\n- Model Context Protocol servers provide additional capabilities\n- MCP tools are prefixed: `mcp__<server-name>__<tool-name>`\n- Check your available tools for MCP integrations\n- Use when the tool's functionality matches your task needs\n\n## What Remains from Codex\n \nSandbox policies, approval mechanisms, final answer formatting, git commit protocols, and file reference formats all follow Codex instructions. In approval policy \"never\", never request escalations.\n\n## Approvals & Safety\n- Assume workspace-write filesystem, network enabled, approval on-failure unless explicitly stated otherwise.\n- When a command fails due to sandboxing or permissions, retry with escalated permissions if allowed by policy, including a one-line justification.\n- Treat destructive commands (e.g., `rm`, `git reset --hard`) as requiring explicit user request or approval.\n- When uncertain, prefer non-destructive verification first (e.g., confirm file existence with `list`, then delete with `bash`).";
11
+ export interface CodexOpenCodeBridgeMeta {
12
+ estimatedTokens: number;
13
+ reductionVsCurrent: string;
14
+ reductionVsToolRemap: string;
15
+ protects: string[];
16
+ omits: string[];
17
+ }
18
+ export declare const CODEX_OPENCODE_BRIDGE_META: CodexOpenCodeBridgeMeta;
19
+ //# 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,osLAyHmG,CAAC;AAEtI,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,uBAmBxC,CAAC"}
@@ -0,0 +1,152 @@
1
+ /**
2
+ * Codex-OpenCode Bridge Prompt
3
+ *
4
+ * This prompt bridges Codex CLI instructions to the OpenCode environment.
5
+ * It incorporates critical tool mappings, available tools list, substitution rules,
6
+ * and verification checklist to ensure proper tool usage.
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. OpenCode provides different tools but follows Codex operating principles.
13
+
14
+ ## CRITICAL: Tool Replacements
15
+
16
+ <critical_rule priority="0">
17
+ ❌ APPLY_PATCH DOES NOT EXIST → ✅ USE "edit" INSTEAD
18
+ - NEVER use: apply_patch, applyPatch
19
+ - ALWAYS use: edit tool for ALL file modifications
20
+ - Before modifying files: Verify you're using "edit", NOT "apply_patch"
21
+ </critical_rule>
22
+
23
+ <critical_rule priority="0">
24
+ ❌ UPDATE_PLAN DOES NOT EXIST → ✅ USE "todowrite" INSTEAD
25
+ - NEVER use: update_plan, updatePlan, read_plan, readPlan
26
+ - ALWAYS use: todowrite for task/plan updates, todoread to read plans
27
+ - Before plan operations: Verify you're using "todowrite", NOT "update_plan"
28
+ </critical_rule>
29
+
30
+ ## Available OpenCode Tools
31
+
32
+ **File Operations:**
33
+ - \`write\` - Create new files
34
+ - Overwriting existing files requires a prior Read in this session; default to ASCII unless the file already uses Unicode.
35
+ - \`edit\` - Modify existing files (REPLACES apply_patch)
36
+ - Requires a prior Read in this session; preserve exact indentation; ensure \`oldString\` uniquely matches or use \`replaceAll\`; edit fails if ambiguous or missing.
37
+ - \`read\` - Read file contents
38
+
39
+ **Search/Discovery:**
40
+ - \`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\`.
41
+ - \`glob\` - Find files by pattern; defaults to workspace cwd unless \`path\` is set.
42
+ - \`list\` - List directories (requires absolute paths)
43
+
44
+ **Execution:**
45
+ - \`bash\` - Run shell commands
46
+ - No workdir parameter; do not include it in tool calls.
47
+ - Always include a short description for the command.
48
+ - Do not use cd; use absolute paths in commands.
49
+ - Quote paths containing spaces with double quotes.
50
+ - Chain multiple commands with ';' or '&&'; avoid newlines.
51
+ - Use Grep/Glob tools for searches; only use bash with \`rg\` when you need counts or advanced features.
52
+ - Do not use \`ls\`/\`cat\` in bash; use \`list\`/\`read\` tools instead.
53
+ - For deletions (rm), verify by listing parent dir with \`list\`.
54
+
55
+ **Network:**
56
+ - \`webfetch\` - Fetch web content
57
+ - Use fully-formed URLs (http/https; http auto-upgrades to https).
58
+ - Always set \`format\` to one of: text | markdown | html; prefer markdown unless otherwise required.
59
+ - Read-only; short cache window.
60
+
61
+ **Task Management:**
62
+ - \`todowrite\` - Manage tasks/plans (REPLACES update_plan)
63
+ - \`todoread\` - Read current plan
64
+
65
+ ## Substitution Rules
66
+
67
+ Base instruction says: You MUST use instead:
68
+ apply_patch → edit
69
+ update_plan → todowrite
70
+ read_plan → todoread
71
+
72
+ **Path Usage:** Use per-tool conventions to avoid conflicts:
73
+ - Tool calls: \`read\`, \`edit\`, \`write\`, \`list\` require absolute paths.
74
+ - Searches: \`grep\`/\`glob\` default to the workspace cwd; prefer relative include patterns; set \`path\` only when a different root is needed.
75
+ - Presentation: In assistant messages, show workspace-relative paths; use absolute paths only inside tool calls.
76
+ - Tool schema overrides general path preferences—do not convert required absolute paths to relative.
77
+
78
+ ## Verification Checklist
79
+
80
+ Before file/plan modifications:
81
+ 1. Am I using "edit" NOT "apply_patch"?
82
+ 2. Am I using "todowrite" NOT "update_plan"?
83
+ 3. Is this tool in the approved list above?
84
+ 4. Am I following each tool's path requirements?
85
+
86
+ If ANY answer is NO → STOP and correct before proceeding.
87
+
88
+ ## OpenCode Working Style
89
+
90
+ **Communication:**
91
+ - Send brief preambles (8-12 words) before tool calls, building on prior context
92
+ - Provide progress updates during longer tasks
93
+
94
+ **Execution:**
95
+ - Keep working autonomously until query is fully resolved before yielding
96
+ - Don't return to user with partial solutions
97
+
98
+ **Code Approach:**
99
+ - New projects: Be ambitious and creative
100
+ - Existing codebases: Surgical precision - modify only what's requested unless explicitly instructed to do otherwise
101
+
102
+ **Testing:**
103
+ - If tests exist: Start specific to your changes, then broader validation
104
+
105
+ ## Advanced Tools
106
+
107
+ **Task Tool (Sub-Agents):**
108
+ - Use the Task tool (functions.task) to launch sub-agents
109
+ - Check the Task tool description for current agent types and their capabilities
110
+ - Useful for complex analysis, specialized workflows, or tasks requiring isolated context
111
+ - The agent list is dynamically generated - refer to tool schema for available agents
112
+
113
+ **Parallelization:**
114
+ - When multiple independent tool calls are needed, use multi_tool_use.parallel to run them concurrently.
115
+ - Reserve sequential calls for ordered or data-dependent steps.
116
+
117
+ **MCP Tools:**
118
+ - Model Context Protocol servers provide additional capabilities
119
+ - MCP tools are prefixed: \`mcp__<server-name>__<tool-name>\`
120
+ - Check your available tools for MCP integrations
121
+ - Use when the tool's functionality matches your task needs
122
+
123
+ ## What Remains from Codex
124
+
125
+ 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.
126
+
127
+ ## Approvals & Safety
128
+ - Assume workspace-write filesystem, network enabled, approval on-failure unless explicitly stated otherwise.
129
+ - When a command fails due to sandboxing or permissions, retry with escalated permissions if allowed by policy, including a one-line justification.
130
+ - Treat destructive commands (e.g., \`rm\`, \`git reset --hard\`) as requiring explicit user request or approval.
131
+ - When uncertain, prefer non-destructive verification first (e.g., confirm file existence with \`list\`, then delete with \`bash\`).`;
132
+ export const CODEX_OPENCODE_BRIDGE_META = {
133
+ estimatedTokens: 550,
134
+ reductionVsCurrent: "88%",
135
+ reductionVsToolRemap: "10%",
136
+ protects: [
137
+ "Tool name confusion (apply_patch/update_plan)",
138
+ "Missing tool awareness",
139
+ "Task tool / sub-agent awareness",
140
+ "MCP tool awareness",
141
+ "Premature yielding to user",
142
+ "Over-modification of existing code",
143
+ "Environment confusion",
144
+ ],
145
+ omits: [
146
+ "Sandbox details (in Codex)",
147
+ "Formatting rules (in Codex)",
148
+ "Tool schemas (in tool JSONs)",
149
+ "Git protocols (in Codex)",
150
+ ],
151
+ };
152
+ //# 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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qIAyHgG,CAAC;AAUtI,MAAM,CAAC,MAAM,0BAA0B,GAA4B;IAClE,eAAe,EAAE,GAAG;IACpB,kBAAkB,EAAE,KAAK;IACzB,oBAAoB,EAAE,KAAK;IAC3B,QAAQ,EAAE;QACT,+CAA+C;QAC/C,wBAAwB;QACxB,iCAAiC;QACjC,oBAAoB;QACpB,4BAA4B;QAC5B,oCAAoC;QACpC,uBAAuB;KACvB;IACD,KAAK,EAAE;QACN,4BAA4B;QAC5B,6BAA6B;QAC7B,8BAA8B;QAC9B,0BAA0B;KAC1B;CACD,CAAC"}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Model family type for prompt selection
3
+ * Maps to different system prompts in the Codex CLI
4
+ */
5
+ export type ModelFamily = "gpt-5.2-codex" | "codex-max" | "codex" | "gpt-5.2" | "gpt-5.1";
6
+ /**
7
+ * All supported model families
8
+ * Used for per-family account rotation and rate limit tracking
9
+ */
10
+ export declare const MODEL_FAMILIES: readonly ModelFamily[];
11
+ /**
12
+ * Determine the model family based on the normalized model name
13
+ * @param normalizedModel - The normalized model name (e.g., "gpt-5.2-codex", "gpt-5.1-codex-max", "gpt-5.1-codex", "gpt-5.1")
14
+ * @returns The model family for prompt selection
15
+ */
16
+ export declare function getModelFamily(normalizedModel: string): ModelFamily;
17
+ /**
18
+ * Fetch Codex instructions from GitHub with ETag-based caching
19
+ * Uses HTTP conditional requests to efficiently check for updates
20
+ * Always fetches from the latest release tag, not main branch
21
+ *
22
+ * Rate limit protection: Only checks GitHub if cache is older than 15 minutes
23
+ *
24
+ * @param normalizedModel - The normalized model name (optional, defaults to "gpt-5.1-codex" for backwards compatibility)
25
+ * @returns Codex instructions for the specified model family
26
+ */
27
+ export declare function getCodexInstructions(normalizedModel?: string): Promise<string>;
28
+ /**
29
+ * Tool remapping instructions for opencode tools
30
+ */
31
+ 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\">\n\u274C APPLY_PATCH DOES NOT EXIST \u2192 \u2705 USE \"edit\" INSTEAD\n- NEVER use: apply_patch, applyPatch\n- ALWAYS use: edit tool for ALL file modifications\n- Before modifying files: Verify you're using \"edit\", NOT \"apply_patch\"\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\">\nFile Operations:\n \u2022 write - Create new files\n \u2022 edit - Modify existing files (REPLACES apply_patch)\n \u2022 patch - Apply diff patches\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 (use relative paths)\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<substitution_rules priority=\"0\">\nBase instruction says: You MUST use instead:\napply_patch \u2192 edit\nupdate_plan \u2192 todowrite\nread_plan \u2192 todoread\nabsolute paths \u2192 relative paths\n</substitution_rules>\n\n<verification_checklist priority=\"0\">\nBefore file/plan modifications:\n1. Am I using \"edit\" NOT \"apply_patch\"?\n2. Am I using \"todowrite\" NOT \"update_plan\"?\n3. Is this tool in the approved list above?\n4. Am I using relative paths?\n\nIf ANY answer is NO \u2192 STOP and correct before proceeding.\n</verification_checklist>\n</user_instructions>";
32
+ //# sourceMappingURL=codex.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codex.d.ts","sourceRoot":"","sources":["../../../lib/prompts/codex.ts"],"names":[],"mappings":"AAkBA;;;GAGG;AACH,MAAM,MAAM,WAAW,GACpB,eAAe,GACf,WAAW,GACX,OAAO,GACP,SAAS,GACT,SAAS,CAAC;AAEb;;;GAGG;AACH,eAAO,MAAM,cAAc,EAAE,SAAS,WAAW,EAMvC,CAAC;AAyBX;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,eAAe,EAAE,MAAM,GAAG,WAAW,CAoBnE;AAoDD;;;;;;;;;GASG;AACH,wBAAsB,oBAAoB,CACzC,eAAe,SAAkB,GAC/B,OAAO,CAAC,MAAM,CAAC,CA0GjB;AAED;;GAEG;AACH,eAAO,MAAM,kBAAkB,+mEA8DV,CAAC"}
@@ -0,0 +1,262 @@
1
+ import { promises as fs } from "node:fs";
2
+ import { homedir } from "node:os";
3
+ import { dirname, join } from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+ const GITHUB_API_RELEASES = "https://api.github.com/repos/openai/codex/releases/latest";
6
+ const GITHUB_HTML_RELEASES = "https://github.com/openai/codex/releases/latest";
7
+ const CACHE_DIR = join(homedir(), ".opencode", "cache");
8
+ const CACHE_TTL_MS = 15 * 60 * 1000;
9
+ const __filename = fileURLToPath(import.meta.url);
10
+ const __dirname = dirname(__filename);
11
+ const memoryCache = new Map();
12
+ /**
13
+ * All supported model families
14
+ * Used for per-family account rotation and rate limit tracking
15
+ */
16
+ export const MODEL_FAMILIES = [
17
+ "gpt-5.2-codex",
18
+ "codex-max",
19
+ "codex",
20
+ "gpt-5.2",
21
+ "gpt-5.1",
22
+ ];
23
+ /**
24
+ * Prompt file mapping for each model family
25
+ * Based on codex-rs/core/src/model_family.rs logic
26
+ */
27
+ const PROMPT_FILES = {
28
+ "gpt-5.2-codex": "gpt-5.2-codex_prompt.md",
29
+ "codex-max": "gpt-5.1-codex-max_prompt.md",
30
+ codex: "gpt_5_codex_prompt.md",
31
+ "gpt-5.2": "gpt_5_2_prompt.md",
32
+ "gpt-5.1": "gpt_5_1_prompt.md",
33
+ };
34
+ /**
35
+ * Cache file mapping for each model family
36
+ */
37
+ const CACHE_FILES = {
38
+ "gpt-5.2-codex": "gpt-5.2-codex-instructions.md",
39
+ "codex-max": "codex-max-instructions.md",
40
+ codex: "codex-instructions.md",
41
+ "gpt-5.2": "gpt-5.2-instructions.md",
42
+ "gpt-5.1": "gpt-5.1-instructions.md",
43
+ };
44
+ /**
45
+ * Determine the model family based on the normalized model name
46
+ * @param normalizedModel - The normalized model name (e.g., "gpt-5.2-codex", "gpt-5.1-codex-max", "gpt-5.1-codex", "gpt-5.1")
47
+ * @returns The model family for prompt selection
48
+ */
49
+ export function getModelFamily(normalizedModel) {
50
+ if (normalizedModel.includes("gpt-5.2-codex") ||
51
+ normalizedModel.includes("gpt 5.2 codex")) {
52
+ return "gpt-5.2-codex";
53
+ }
54
+ if (normalizedModel.includes("codex-max")) {
55
+ return "codex-max";
56
+ }
57
+ if (normalizedModel.includes("codex") ||
58
+ normalizedModel.startsWith("codex-")) {
59
+ return "codex";
60
+ }
61
+ if (normalizedModel.includes("gpt-5.2")) {
62
+ return "gpt-5.2";
63
+ }
64
+ return "gpt-5.1";
65
+ }
66
+ async function readFileOrNull(path) {
67
+ try {
68
+ return await fs.readFile(path, "utf8");
69
+ }
70
+ catch {
71
+ return null;
72
+ }
73
+ }
74
+ /**
75
+ * Get the latest release tag from GitHub
76
+ * @returns Release tag name (e.g., "rust-v0.43.0")
77
+ */
78
+ async function getLatestReleaseTag() {
79
+ try {
80
+ const response = await fetch(GITHUB_API_RELEASES);
81
+ if (response.ok) {
82
+ const data = (await response.json());
83
+ if (data.tag_name) {
84
+ return data.tag_name;
85
+ }
86
+ }
87
+ }
88
+ catch {
89
+ // Fall through to HTML fallback
90
+ }
91
+ const htmlResponse = await fetch(GITHUB_HTML_RELEASES);
92
+ if (!htmlResponse.ok) {
93
+ throw new Error(`Failed to fetch latest release: ${htmlResponse.status}`);
94
+ }
95
+ const finalUrl = htmlResponse.url;
96
+ if (finalUrl) {
97
+ const parts = finalUrl.split("/tag/");
98
+ const last = parts[parts.length - 1];
99
+ if (last && !last.includes("/")) {
100
+ return last;
101
+ }
102
+ }
103
+ const html = await htmlResponse.text();
104
+ const match = html.match(/\/openai\/codex\/releases\/tag\/([^"]+)/);
105
+ if (match && match[1]) {
106
+ return match[1];
107
+ }
108
+ throw new Error("Failed to determine latest release tag from GitHub");
109
+ }
110
+ /**
111
+ * Fetch Codex instructions from GitHub with ETag-based caching
112
+ * Uses HTTP conditional requests to efficiently check for updates
113
+ * Always fetches from the latest release tag, not main branch
114
+ *
115
+ * Rate limit protection: Only checks GitHub if cache is older than 15 minutes
116
+ *
117
+ * @param normalizedModel - The normalized model name (optional, defaults to "gpt-5.1-codex" for backwards compatibility)
118
+ * @returns Codex instructions for the specified model family
119
+ */
120
+ export async function getCodexInstructions(normalizedModel = "gpt-5.1-codex") {
121
+ const modelFamily = getModelFamily(normalizedModel);
122
+ const cached = memoryCache.get(modelFamily);
123
+ if (cached && Date.now() - cached.timestamp < CACHE_TTL_MS) {
124
+ return cached.content;
125
+ }
126
+ const promptFile = PROMPT_FILES[modelFamily];
127
+ const cacheFile = join(CACHE_DIR, CACHE_FILES[modelFamily]);
128
+ const cacheMetaFile = join(CACHE_DIR, `${CACHE_FILES[modelFamily].replace(".md", "-meta.json")}`);
129
+ try {
130
+ let cachedETag = null;
131
+ let cachedTag = null;
132
+ let cachedTimestamp = null;
133
+ const metaContent = await readFileOrNull(cacheMetaFile);
134
+ if (metaContent) {
135
+ const metadata = JSON.parse(metaContent);
136
+ cachedETag = metadata.etag;
137
+ cachedTag = metadata.tag;
138
+ cachedTimestamp = metadata.lastChecked;
139
+ }
140
+ if (cachedTimestamp &&
141
+ Date.now() - cachedTimestamp < CACHE_TTL_MS) {
142
+ const diskContent = await readFileOrNull(cacheFile);
143
+ if (diskContent) {
144
+ memoryCache.set(modelFamily, { content: diskContent, timestamp: Date.now() });
145
+ return diskContent;
146
+ }
147
+ }
148
+ const latestTag = await getLatestReleaseTag();
149
+ const CODEX_INSTRUCTIONS_URL = `https://raw.githubusercontent.com/openai/codex/${latestTag}/codex-rs/core/${promptFile}`;
150
+ if (cachedTag !== latestTag) {
151
+ cachedETag = null;
152
+ }
153
+ const headers = {};
154
+ if (cachedETag) {
155
+ headers["If-None-Match"] = cachedETag;
156
+ }
157
+ const response = await fetch(CODEX_INSTRUCTIONS_URL, { headers });
158
+ if (response.status === 304) {
159
+ const diskContent = await readFileOrNull(cacheFile);
160
+ if (diskContent) {
161
+ memoryCache.set(modelFamily, { content: diskContent, timestamp: Date.now() });
162
+ return diskContent;
163
+ }
164
+ }
165
+ if (response.ok) {
166
+ const instructions = await response.text();
167
+ const newETag = response.headers.get("etag");
168
+ await fs.mkdir(CACHE_DIR, { recursive: true });
169
+ await fs.writeFile(cacheFile, instructions, "utf8");
170
+ await fs.writeFile(cacheMetaFile, JSON.stringify({
171
+ etag: newETag,
172
+ tag: latestTag,
173
+ lastChecked: Date.now(),
174
+ url: CODEX_INSTRUCTIONS_URL,
175
+ }), "utf8");
176
+ memoryCache.set(modelFamily, { content: instructions, timestamp: Date.now() });
177
+ return instructions;
178
+ }
179
+ throw new Error(`HTTP ${response.status}`);
180
+ }
181
+ catch (error) {
182
+ const err = error;
183
+ console.error(`[openai-codex-plugin] Failed to fetch ${modelFamily} instructions from GitHub:`, err.message);
184
+ const diskContent = await readFileOrNull(cacheFile);
185
+ if (diskContent) {
186
+ console.error(`[openai-codex-plugin] Using cached ${modelFamily} instructions`);
187
+ memoryCache.set(modelFamily, { content: diskContent, timestamp: Date.now() });
188
+ return diskContent;
189
+ }
190
+ console.error(`[openai-codex-plugin] Falling back to bundled instructions for ${modelFamily}`);
191
+ const bundled = await fs.readFile(join(__dirname, "codex-instructions.md"), "utf8");
192
+ memoryCache.set(modelFamily, { content: bundled, timestamp: Date.now() });
193
+ return bundled;
194
+ }
195
+ }
196
+ /**
197
+ * Tool remapping instructions for opencode tools
198
+ */
199
+ export const TOOL_REMAP_MESSAGE = `<user_instructions priority="0">
200
+ <environment_override priority="0">
201
+ YOU ARE IN A DIFFERENT ENVIRONMENT. These instructions override ALL previous tool references.
202
+ </environment_override>
203
+
204
+ <tool_replacements priority="0">
205
+ <critical_rule priority="0">
206
+ ❌ APPLY_PATCH DOES NOT EXIST → ✅ USE "edit" INSTEAD
207
+ - NEVER use: apply_patch, applyPatch
208
+ - ALWAYS use: edit tool for ALL file modifications
209
+ - Before modifying files: Verify you're using "edit", NOT "apply_patch"
210
+ </critical_rule>
211
+
212
+ <critical_rule priority="0">
213
+ ❌ UPDATE_PLAN DOES NOT EXIST → ✅ USE "todowrite" INSTEAD
214
+ - NEVER use: update_plan, updatePlan
215
+ - ALWAYS use: todowrite for ALL task/plan operations
216
+ - Use todoread to read current plan
217
+ - Before plan operations: Verify you're using "todowrite", NOT "update_plan"
218
+ </critical_rule>
219
+ </tool_replacements>
220
+
221
+ <available_tools priority="0">
222
+ File Operations:
223
+ • write - Create new files
224
+ • edit - Modify existing files (REPLACES apply_patch)
225
+ • patch - Apply diff patches
226
+ • read - Read file contents
227
+
228
+ Search/Discovery:
229
+ • grep - Search file contents
230
+ • glob - Find files by pattern
231
+ • list - List directories (use relative paths)
232
+
233
+ Execution:
234
+ • bash - Run shell commands
235
+
236
+ Network:
237
+ • webfetch - Fetch web content
238
+
239
+ Task Management:
240
+ • todowrite - Manage tasks/plans (REPLACES update_plan)
241
+ • todoread - Read current plan
242
+ </available_tools>
243
+
244
+ <substitution_rules priority="0">
245
+ Base instruction says: You MUST use instead:
246
+ apply_patch → edit
247
+ update_plan → todowrite
248
+ read_plan → todoread
249
+ absolute paths → relative paths
250
+ </substitution_rules>
251
+
252
+ <verification_checklist priority="0">
253
+ Before file/plan modifications:
254
+ 1. Am I using "edit" NOT "apply_patch"?
255
+ 2. Am I using "todowrite" NOT "update_plan"?
256
+ 3. Is this tool in the approved list above?
257
+ 4. Am I using relative paths?
258
+
259
+ If ANY answer is NO → STOP and correct before proceeding.
260
+ </verification_checklist>
261
+ </user_instructions>`;
262
+ //# sourceMappingURL=codex.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codex.js","sourceRoot":"","sources":["../../../lib/prompts/codex.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MA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C,WAAW,4BAA4B,EAChF,GAAG,CAAC,OAAO,CACX,CAAC;QAEF,MAAM,WAAW,GAAG,MAAM,cAAc,CAAC,SAAS,CAAC,CAAC;QACpD,IAAI,WAAW,EAAE,CAAC;YACjB,OAAO,CAAC,KAAK,CACZ,sCAAsC,WAAW,eAAe,CAChE,CAAC;YACF,WAAW,CAAC,GAAG,CAAC,WAAW,EAAE,EAAE,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;YAC9E,OAAO,WAAW,CAAC;QACpB,CAAC;QAED,OAAO,CAAC,KAAK,CACZ,kEAAkE,WAAW,EAAE,CAC/E,CAAC;QACF,MAAM,OAAO,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,EAAE,uBAAuB,CAAC,EAAE,MAAM,CAAC,CAAC;QACpF,WAAW,CAAC,GAAG,CAAC,WAAW,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;QAC1E,OAAO,OAAO,CAAC;IAChB,CAAC;AACF,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBA8Db,CAAC"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * OpenCode Codex Prompt Fetcher
3
+ *
4
+ * Fetches and caches the codex.txt system prompt from OpenCode's GitHub repository.
5
+ * Uses ETag-based caching to efficiently track updates.
6
+ */
7
+ /**
8
+ * Fetch OpenCode's codex.txt prompt with ETag-based caching
9
+ * Uses HTTP conditional requests to efficiently check for updates
10
+ *
11
+ * Rate limit protection: Only checks GitHub if cache is older than 15 minutes
12
+ * @returns The codex.txt content
13
+ */
14
+ export declare function getOpenCodeCodexPrompt(): Promise<string>;
15
+ /**
16
+ * Get first N characters of the cached OpenCode prompt for verification
17
+ * @param chars Number of characters to get (default: 50)
18
+ * @returns First N characters or null if not cached
19
+ */
20
+ export declare function getCachedPromptPrefix(chars?: number): Promise<string | null>;
21
+ //# sourceMappingURL=opencode-codex.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"opencode-codex.d.ts","sourceRoot":"","sources":["../../../lib/prompts/opencode-codex.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAkBH;;;;;;GAMG;AACH,wBAAsB,sBAAsB,IAAI,OAAO,CAAC,MAAM,CAAC,CA2E9D;AAED;;;;GAIG;AACH,wBAAsB,qBAAqB,CAAC,KAAK,SAAK,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAO9E"}
@@ -0,0 +1,91 @@
1
+ /**
2
+ * OpenCode Codex Prompt Fetcher
3
+ *
4
+ * Fetches and caches the codex.txt system prompt from OpenCode's GitHub repository.
5
+ * Uses ETag-based caching to efficiently track updates.
6
+ */
7
+ import { join } from "node:path";
8
+ import { homedir } from "node:os";
9
+ import { mkdir, readFile, writeFile } from "node:fs/promises";
10
+ const OPENCODE_CODEX_URL = "https://raw.githubusercontent.com/anomalyco/opencode/dev/packages/opencode/src/session/prompt/codex.txt";
11
+ const CACHE_DIR = join(homedir(), ".opencode", "cache");
12
+ const CACHE_FILE = join(CACHE_DIR, "opencode-codex.txt");
13
+ const CACHE_META_FILE = join(CACHE_DIR, "opencode-codex-meta.json");
14
+ /**
15
+ * Fetch OpenCode's codex.txt prompt with ETag-based caching
16
+ * Uses HTTP conditional requests to efficiently check for updates
17
+ *
18
+ * Rate limit protection: Only checks GitHub if cache is older than 15 minutes
19
+ * @returns The codex.txt content
20
+ */
21
+ export async function getOpenCodeCodexPrompt() {
22
+ await mkdir(CACHE_DIR, { recursive: true });
23
+ // Try to load cached content and metadata
24
+ let cachedContent = null;
25
+ let cachedMeta = null;
26
+ try {
27
+ cachedContent = await readFile(CACHE_FILE, "utf-8");
28
+ const metaContent = await readFile(CACHE_META_FILE, "utf-8");
29
+ cachedMeta = JSON.parse(metaContent);
30
+ }
31
+ catch {
32
+ // Cache doesn't exist or is invalid, will fetch fresh
33
+ }
34
+ // Rate limit protection: If cache is less than 15 minutes old, use it
35
+ const CACHE_TTL_MS = 15 * 60 * 1000; // 15 minutes
36
+ if (cachedMeta?.lastChecked && (Date.now() - cachedMeta.lastChecked) < CACHE_TTL_MS && cachedContent) {
37
+ return cachedContent;
38
+ }
39
+ // Fetch from GitHub with conditional request
40
+ const headers = {};
41
+ if (cachedMeta?.etag) {
42
+ headers["If-None-Match"] = cachedMeta.etag;
43
+ }
44
+ try {
45
+ const response = await fetch(OPENCODE_CODEX_URL, { headers });
46
+ // 304 Not Modified - cache is still valid
47
+ if (response.status === 304 && cachedContent) {
48
+ return cachedContent;
49
+ }
50
+ // 200 OK - new content available
51
+ if (response.ok) {
52
+ const content = await response.text();
53
+ const etag = response.headers.get("etag") || "";
54
+ // Save to cache with timestamp
55
+ await writeFile(CACHE_FILE, content, "utf-8");
56
+ await writeFile(CACHE_META_FILE, JSON.stringify({
57
+ etag,
58
+ lastFetch: new Date().toISOString(), // Keep for backwards compat
59
+ lastChecked: Date.now(),
60
+ }, null, 2), "utf-8");
61
+ return content;
62
+ }
63
+ // Fallback to cache if available
64
+ if (cachedContent) {
65
+ return cachedContent;
66
+ }
67
+ throw new Error(`Failed to fetch OpenCode codex.txt: ${response.status}`);
68
+ }
69
+ catch (error) {
70
+ // Network error - fallback to cache
71
+ if (cachedContent) {
72
+ return cachedContent;
73
+ }
74
+ throw new Error(`Failed to fetch OpenCode codex.txt and no cache available: ${error}`);
75
+ }
76
+ }
77
+ /**
78
+ * Get first N characters of the cached OpenCode prompt for verification
79
+ * @param chars Number of characters to get (default: 50)
80
+ * @returns First N characters or null if not cached
81
+ */
82
+ export async function getCachedPromptPrefix(chars = 50) {
83
+ try {
84
+ const content = await readFile(CACHE_FILE, "utf-8");
85
+ return content.substring(0, chars);
86
+ }
87
+ catch {
88
+ return null;
89
+ }
90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C3E,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,oCAAoC;QACpC,IAAI,aAAa,EAAE,CAAC;YACnB,OAAO,aAAa,CAAC;QACtB,CAAC;QAED,MAAM,IAAI,KAAK,CACd,8DAA8D,KAAK,EAAE,CACrE,CAAC;IACH,CAAC;AACF,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CAAC,KAAK,GAAG,EAAE;IACrD,IAAI,CAAC;QACJ,MAAM,OAAO,GAAG,MAAM,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QACpD,OAAO,OAAO,CAAC,SAAS,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;IACpC,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,IAAI,CAAC;IACb,CAAC;AACF,CAAC"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Constants for session recovery storage paths.
3
+ *
4
+ * Based on opencode-antigravity-auth recovery module.
5
+ */
6
+ export declare const OPENCODE_STORAGE: string;
7
+ export declare const MESSAGE_STORAGE: string;
8
+ export declare const PART_STORAGE: string;
9
+ export declare const THINKING_TYPES: Set<string>;
10
+ export declare const META_TYPES: Set<string>;
11
+ export declare const CONTENT_TYPES: Set<string>;
12
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../lib/recovery/constants.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAmBH,eAAO,MAAM,gBAAgB,QAA4C,CAAC;AAC1E,eAAO,MAAM,eAAe,QAAoC,CAAC;AACjE,eAAO,MAAM,YAAY,QAAiC,CAAC;AAE3D,eAAO,MAAM,cAAc,aAA0D,CAAC;AACtF,eAAO,MAAM,UAAU,aAAyC,CAAC;AACjE,eAAO,MAAM,aAAa,aAAuD,CAAC"}