opencode-openai-codex-auth-multi 4.3.0-multiaccount.1
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 +37 -0
- package/README.md +107 -0
- package/assets/opencode-logo-ornate-dark.svg +18 -0
- package/assets/readme-hero.svg +31 -0
- package/config/README.md +110 -0
- package/config/minimal-opencode.json +13 -0
- package/config/opencode-legacy.json +572 -0
- package/config/opencode-modern.json +240 -0
- package/dist/index.d.ts +44 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +666 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/accounts.d.ts +48 -0
- package/dist/lib/accounts.d.ts.map +1 -0
- package/dist/lib/accounts.js +282 -0
- package/dist/lib/accounts.js.map +1 -0
- package/dist/lib/auth/auth.d.ts +43 -0
- package/dist/lib/auth/auth.d.ts.map +1 -0
- package/dist/lib/auth/auth.js +163 -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 +76 -0
- package/dist/lib/auth/browser.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 +78 -0
- package/dist/lib/auth/server.js.map +1 -0
- package/dist/lib/cli.d.ts +8 -0
- package/dist/lib/cli.d.ts.map +1 -0
- package/dist/lib/cli.js +44 -0
- package/dist/lib/cli.js.map +1 -0
- package/dist/lib/config.d.ts +17 -0
- package/dist/lib/config.d.ts.map +1 -0
- package/dist/lib/config.js +51 -0
- package/dist/lib/config.js.map +1 -0
- package/dist/lib/constants.d.ts +67 -0
- package/dist/lib/constants.d.ts.map +1 -0
- package/dist/lib/constants.js +67 -0
- package/dist/lib/constants.js.map +1 -0
- package/dist/lib/logger.d.ts +26 -0
- package/dist/lib/logger.d.ts.map +1 -0
- package/dist/lib/logger.js +110 -0
- package/dist/lib/logger.js.map +1 -0
- package/dist/lib/oauth-success.html +712 -0
- package/dist/lib/prompts/codex-opencode-bridge.d.ts +19 -0
- package/dist/lib/prompts/codex-opencode-bridge.d.ts.map +1 -0
- package/dist/lib/prompts/codex-opencode-bridge.js +152 -0
- package/dist/lib/prompts/codex-opencode-bridge.js.map +1 -0
- package/dist/lib/prompts/codex.d.ts +27 -0
- package/dist/lib/prompts/codex.d.ts.map +1 -0
- package/dist/lib/prompts/codex.js +241 -0
- package/dist/lib/prompts/codex.js.map +1 -0
- package/dist/lib/prompts/opencode-codex.d.ts +21 -0
- package/dist/lib/prompts/opencode-codex.d.ts.map +1 -0
- package/dist/lib/prompts/opencode-codex.js +91 -0
- package/dist/lib/prompts/opencode-codex.js.map +1 -0
- package/dist/lib/request/fetch-helpers.d.ts +81 -0
- package/dist/lib/request/fetch-helpers.d.ts.map +1 -0
- package/dist/lib/request/fetch-helpers.js +321 -0
- package/dist/lib/request/fetch-helpers.js.map +1 -0
- package/dist/lib/request/helpers/input-utils.d.ts +6 -0
- package/dist/lib/request/helpers/input-utils.d.ts.map +1 -0
- package/dist/lib/request/helpers/input-utils.js +174 -0
- package/dist/lib/request/helpers/input-utils.js.map +1 -0
- package/dist/lib/request/helpers/model-map.d.ts +28 -0
- package/dist/lib/request/helpers/model-map.d.ts.map +1 -0
- package/dist/lib/request/helpers/model-map.js +109 -0
- package/dist/lib/request/helpers/model-map.js.map +1 -0
- package/dist/lib/request/request-transformer.d.ts +93 -0
- package/dist/lib/request/request-transformer.d.ts.map +1 -0
- package/dist/lib/request/request-transformer.js +403 -0
- package/dist/lib/request/request-transformer.js.map +1 -0
- package/dist/lib/request/response-handler.d.ts +14 -0
- package/dist/lib/request/response-handler.d.ts.map +1 -0
- package/dist/lib/request/response-handler.js +90 -0
- package/dist/lib/request/response-handler.js.map +1 -0
- package/dist/lib/storage.d.ts +23 -0
- package/dist/lib/storage.d.ts.map +1 -0
- package/dist/lib/storage.js +153 -0
- package/dist/lib/storage.js.map +1 -0
- package/dist/lib/types.d.ts +170 -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/package.json +71 -0
- package/scripts/copy-oauth-success.js +37 -0
- package/scripts/install-opencode-codex-auth.js +193 -0
- package/scripts/test-all-models.sh +260 -0
- 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,27 @@
|
|
|
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
|
+
* Determine the model family based on the normalized model name
|
|
8
|
+
* @param normalizedModel - The normalized model name (e.g., "gpt-5.2-codex", "gpt-5.1-codex-max", "gpt-5.1-codex", "gpt-5.1")
|
|
9
|
+
* @returns The model family for prompt selection
|
|
10
|
+
*/
|
|
11
|
+
export declare function getModelFamily(normalizedModel: string): ModelFamily;
|
|
12
|
+
/**
|
|
13
|
+
* Fetch Codex instructions from GitHub with ETag-based caching
|
|
14
|
+
* Uses HTTP conditional requests to efficiently check for updates
|
|
15
|
+
* Always fetches from the latest release tag, not main branch
|
|
16
|
+
*
|
|
17
|
+
* Rate limit protection: Only checks GitHub if cache is older than 15 minutes
|
|
18
|
+
*
|
|
19
|
+
* @param normalizedModel - The normalized model name (optional, defaults to "gpt-5.1-codex" for backwards compatibility)
|
|
20
|
+
* @returns Codex instructions for the specified model family
|
|
21
|
+
*/
|
|
22
|
+
export declare function getCodexInstructions(normalizedModel?: string): Promise<string>;
|
|
23
|
+
/**
|
|
24
|
+
* Tool remapping instructions for opencode tools
|
|
25
|
+
*/
|
|
26
|
+
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>";
|
|
27
|
+
//# sourceMappingURL=codex.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codex.d.ts","sourceRoot":"","sources":["../../../lib/prompts/codex.ts"],"names":[],"mappings":"AAeA;;;GAGG;AACH,MAAM,MAAM,WAAW,GACpB,eAAe,GACf,WAAW,GACX,OAAO,GACP,SAAS,GACT,SAAS,CAAC;AAyBb;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,eAAe,EAAE,MAAM,GAAG,WAAW,CAqBnE;AA2CD;;;;;;;;;GASG;AACH,wBAAsB,oBAAoB,CACzC,eAAe,SAAkB,GAC/B,OAAO,CAAC,MAAM,CAAC,CA2GjB;AAED;;GAEG;AACH,eAAO,MAAM,kBAAkB,+mEA8DV,CAAC"}
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } 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 __filename = fileURLToPath(import.meta.url);
|
|
9
|
+
const __dirname = dirname(__filename);
|
|
10
|
+
/**
|
|
11
|
+
* Prompt file mapping for each model family
|
|
12
|
+
* Based on codex-rs/core/src/model_family.rs logic
|
|
13
|
+
*/
|
|
14
|
+
const PROMPT_FILES = {
|
|
15
|
+
"gpt-5.2-codex": "gpt-5.2-codex_prompt.md",
|
|
16
|
+
"codex-max": "gpt-5.1-codex-max_prompt.md",
|
|
17
|
+
codex: "gpt_5_codex_prompt.md",
|
|
18
|
+
"gpt-5.2": "gpt_5_2_prompt.md",
|
|
19
|
+
"gpt-5.1": "gpt_5_1_prompt.md",
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Cache file mapping for each model family
|
|
23
|
+
*/
|
|
24
|
+
const CACHE_FILES = {
|
|
25
|
+
"gpt-5.2-codex": "gpt-5.2-codex-instructions.md",
|
|
26
|
+
"codex-max": "codex-max-instructions.md",
|
|
27
|
+
codex: "codex-instructions.md",
|
|
28
|
+
"gpt-5.2": "gpt-5.2-instructions.md",
|
|
29
|
+
"gpt-5.1": "gpt-5.1-instructions.md",
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Determine the model family based on the normalized model name
|
|
33
|
+
* @param normalizedModel - The normalized model name (e.g., "gpt-5.2-codex", "gpt-5.1-codex-max", "gpt-5.1-codex", "gpt-5.1")
|
|
34
|
+
* @returns The model family for prompt selection
|
|
35
|
+
*/
|
|
36
|
+
export function getModelFamily(normalizedModel) {
|
|
37
|
+
// Order matters - check more specific patterns first
|
|
38
|
+
if (normalizedModel.includes("gpt-5.2-codex") ||
|
|
39
|
+
normalizedModel.includes("gpt 5.2 codex")) {
|
|
40
|
+
return "gpt-5.2-codex";
|
|
41
|
+
}
|
|
42
|
+
if (normalizedModel.includes("codex-max")) {
|
|
43
|
+
return "codex-max";
|
|
44
|
+
}
|
|
45
|
+
if (normalizedModel.includes("codex") ||
|
|
46
|
+
normalizedModel.startsWith("codex-")) {
|
|
47
|
+
return "codex";
|
|
48
|
+
}
|
|
49
|
+
if (normalizedModel.includes("gpt-5.2")) {
|
|
50
|
+
return "gpt-5.2";
|
|
51
|
+
}
|
|
52
|
+
return "gpt-5.1";
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Get the latest release tag from GitHub
|
|
56
|
+
* @returns Release tag name (e.g., "rust-v0.43.0")
|
|
57
|
+
*/
|
|
58
|
+
async function getLatestReleaseTag() {
|
|
59
|
+
try {
|
|
60
|
+
const response = await fetch(GITHUB_API_RELEASES);
|
|
61
|
+
if (response.ok) {
|
|
62
|
+
const data = (await response.json());
|
|
63
|
+
if (data.tag_name) {
|
|
64
|
+
return data.tag_name;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
}
|
|
70
|
+
const htmlResponse = await fetch(GITHUB_HTML_RELEASES);
|
|
71
|
+
if (!htmlResponse.ok) {
|
|
72
|
+
throw new Error(`Failed to fetch latest release: ${htmlResponse.status}`);
|
|
73
|
+
}
|
|
74
|
+
const finalUrl = htmlResponse.url;
|
|
75
|
+
if (finalUrl) {
|
|
76
|
+
const parts = finalUrl.split("/tag/");
|
|
77
|
+
const last = parts[parts.length - 1];
|
|
78
|
+
if (last && !last.includes("/")) {
|
|
79
|
+
return last;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
const html = await htmlResponse.text();
|
|
83
|
+
const match = html.match(/\/openai\/codex\/releases\/tag\/([^"]+)/);
|
|
84
|
+
if (match && match[1]) {
|
|
85
|
+
return match[1];
|
|
86
|
+
}
|
|
87
|
+
throw new Error("Failed to determine latest release tag from GitHub");
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Fetch Codex instructions from GitHub with ETag-based caching
|
|
91
|
+
* Uses HTTP conditional requests to efficiently check for updates
|
|
92
|
+
* Always fetches from the latest release tag, not main branch
|
|
93
|
+
*
|
|
94
|
+
* Rate limit protection: Only checks GitHub if cache is older than 15 minutes
|
|
95
|
+
*
|
|
96
|
+
* @param normalizedModel - The normalized model name (optional, defaults to "gpt-5.1-codex" for backwards compatibility)
|
|
97
|
+
* @returns Codex instructions for the specified model family
|
|
98
|
+
*/
|
|
99
|
+
export async function getCodexInstructions(normalizedModel = "gpt-5.1-codex") {
|
|
100
|
+
const modelFamily = getModelFamily(normalizedModel);
|
|
101
|
+
const promptFile = PROMPT_FILES[modelFamily];
|
|
102
|
+
const cacheFile = join(CACHE_DIR, CACHE_FILES[modelFamily]);
|
|
103
|
+
const cacheMetaFile = join(CACHE_DIR, `${CACHE_FILES[modelFamily].replace(".md", "-meta.json")}`);
|
|
104
|
+
try {
|
|
105
|
+
// Load cached metadata (includes ETag, tag, and lastChecked timestamp)
|
|
106
|
+
let cachedETag = null;
|
|
107
|
+
let cachedTag = null;
|
|
108
|
+
let cachedTimestamp = null;
|
|
109
|
+
if (existsSync(cacheMetaFile)) {
|
|
110
|
+
const metadata = JSON.parse(readFileSync(cacheMetaFile, "utf8"));
|
|
111
|
+
cachedETag = metadata.etag;
|
|
112
|
+
cachedTag = metadata.tag;
|
|
113
|
+
cachedTimestamp = metadata.lastChecked;
|
|
114
|
+
}
|
|
115
|
+
// Rate limit protection: If cache is less than 15 minutes old, use it
|
|
116
|
+
const CACHE_TTL_MS = 15 * 60 * 1000; // 15 minutes
|
|
117
|
+
if (cachedTimestamp &&
|
|
118
|
+
Date.now() - cachedTimestamp < CACHE_TTL_MS &&
|
|
119
|
+
existsSync(cacheFile)) {
|
|
120
|
+
return readFileSync(cacheFile, "utf8");
|
|
121
|
+
}
|
|
122
|
+
// Get the latest release tag (only if cache is stale or missing)
|
|
123
|
+
const latestTag = await getLatestReleaseTag();
|
|
124
|
+
const CODEX_INSTRUCTIONS_URL = `https://raw.githubusercontent.com/openai/codex/${latestTag}/codex-rs/core/${promptFile}`;
|
|
125
|
+
// If tag changed, we need to fetch new instructions
|
|
126
|
+
if (cachedTag !== latestTag) {
|
|
127
|
+
cachedETag = null; // Force re-fetch
|
|
128
|
+
}
|
|
129
|
+
// Make conditional request with If-None-Match header
|
|
130
|
+
const headers = {};
|
|
131
|
+
if (cachedETag) {
|
|
132
|
+
headers["If-None-Match"] = cachedETag;
|
|
133
|
+
}
|
|
134
|
+
const response = await fetch(CODEX_INSTRUCTIONS_URL, { headers });
|
|
135
|
+
// 304 Not Modified - our cached version is still current
|
|
136
|
+
if (response.status === 304) {
|
|
137
|
+
if (existsSync(cacheFile)) {
|
|
138
|
+
return readFileSync(cacheFile, "utf8");
|
|
139
|
+
}
|
|
140
|
+
// Cache file missing but GitHub says not modified - fall through to re-fetch
|
|
141
|
+
}
|
|
142
|
+
// 200 OK - new content or first fetch
|
|
143
|
+
if (response.ok) {
|
|
144
|
+
const instructions = await response.text();
|
|
145
|
+
const newETag = response.headers.get("etag");
|
|
146
|
+
// Create cache directory if it doesn't exist
|
|
147
|
+
if (!existsSync(CACHE_DIR)) {
|
|
148
|
+
mkdirSync(CACHE_DIR, { recursive: true });
|
|
149
|
+
}
|
|
150
|
+
// Cache the instructions with ETag and tag (verbatim from GitHub)
|
|
151
|
+
writeFileSync(cacheFile, instructions, "utf8");
|
|
152
|
+
writeFileSync(cacheMetaFile, JSON.stringify({
|
|
153
|
+
etag: newETag,
|
|
154
|
+
tag: latestTag,
|
|
155
|
+
lastChecked: Date.now(),
|
|
156
|
+
url: CODEX_INSTRUCTIONS_URL,
|
|
157
|
+
}), "utf8");
|
|
158
|
+
return instructions;
|
|
159
|
+
}
|
|
160
|
+
throw new Error(`HTTP ${response.status}`);
|
|
161
|
+
}
|
|
162
|
+
catch (error) {
|
|
163
|
+
const err = error;
|
|
164
|
+
console.error(`[openai-codex-plugin] Failed to fetch ${modelFamily} instructions from GitHub:`, err.message);
|
|
165
|
+
// Try to use cached version even if stale
|
|
166
|
+
if (existsSync(cacheFile)) {
|
|
167
|
+
console.error(`[openai-codex-plugin] Using cached ${modelFamily} instructions`);
|
|
168
|
+
return readFileSync(cacheFile, "utf8");
|
|
169
|
+
}
|
|
170
|
+
// Fall back to bundled version (use codex-instructions.md as default)
|
|
171
|
+
console.error(`[openai-codex-plugin] Falling back to bundled instructions for ${modelFamily}`);
|
|
172
|
+
return readFileSync(join(__dirname, "codex-instructions.md"), "utf8");
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Tool remapping instructions for opencode tools
|
|
177
|
+
*/
|
|
178
|
+
export const TOOL_REMAP_MESSAGE = `<user_instructions priority="0">
|
|
179
|
+
<environment_override priority="0">
|
|
180
|
+
YOU ARE IN A DIFFERENT ENVIRONMENT. These instructions override ALL previous tool references.
|
|
181
|
+
</environment_override>
|
|
182
|
+
|
|
183
|
+
<tool_replacements priority="0">
|
|
184
|
+
<critical_rule priority="0">
|
|
185
|
+
❌ APPLY_PATCH DOES NOT EXIST → ✅ USE "edit" INSTEAD
|
|
186
|
+
- NEVER use: apply_patch, applyPatch
|
|
187
|
+
- ALWAYS use: edit tool for ALL file modifications
|
|
188
|
+
- Before modifying files: Verify you're using "edit", NOT "apply_patch"
|
|
189
|
+
</critical_rule>
|
|
190
|
+
|
|
191
|
+
<critical_rule priority="0">
|
|
192
|
+
❌ UPDATE_PLAN DOES NOT EXIST → ✅ USE "todowrite" INSTEAD
|
|
193
|
+
- NEVER use: update_plan, updatePlan
|
|
194
|
+
- ALWAYS use: todowrite for ALL task/plan operations
|
|
195
|
+
- Use todoread to read current plan
|
|
196
|
+
- Before plan operations: Verify you're using "todowrite", NOT "update_plan"
|
|
197
|
+
</critical_rule>
|
|
198
|
+
</tool_replacements>
|
|
199
|
+
|
|
200
|
+
<available_tools priority="0">
|
|
201
|
+
File Operations:
|
|
202
|
+
• write - Create new files
|
|
203
|
+
• edit - Modify existing files (REPLACES apply_patch)
|
|
204
|
+
• patch - Apply diff patches
|
|
205
|
+
• read - Read file contents
|
|
206
|
+
|
|
207
|
+
Search/Discovery:
|
|
208
|
+
• grep - Search file contents
|
|
209
|
+
• glob - Find files by pattern
|
|
210
|
+
• list - List directories (use relative paths)
|
|
211
|
+
|
|
212
|
+
Execution:
|
|
213
|
+
• bash - Run shell commands
|
|
214
|
+
|
|
215
|
+
Network:
|
|
216
|
+
• webfetch - Fetch web content
|
|
217
|
+
|
|
218
|
+
Task Management:
|
|
219
|
+
• todowrite - Manage tasks/plans (REPLACES update_plan)
|
|
220
|
+
• todoread - Read current plan
|
|
221
|
+
</available_tools>
|
|
222
|
+
|
|
223
|
+
<substitution_rules priority="0">
|
|
224
|
+
Base instruction says: You MUST use instead:
|
|
225
|
+
apply_patch → edit
|
|
226
|
+
update_plan → todowrite
|
|
227
|
+
read_plan → todoread
|
|
228
|
+
absolute paths → relative paths
|
|
229
|
+
</substitution_rules>
|
|
230
|
+
|
|
231
|
+
<verification_checklist priority="0">
|
|
232
|
+
Before file/plan modifications:
|
|
233
|
+
1. Am I using "edit" NOT "apply_patch"?
|
|
234
|
+
2. Am I using "todowrite" NOT "update_plan"?
|
|
235
|
+
3. Is this tool in the approved list above?
|
|
236
|
+
4. Am I using relative paths?
|
|
237
|
+
|
|
238
|
+
If ANY answer is NO → STOP and correct before proceeding.
|
|
239
|
+
</verification_checklist>
|
|
240
|
+
</user_instructions>`;
|
|
241
|
+
//# sourceMappingURL=codex.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codex.js","sourceRoot":"","sources":["../../../lib/prompts/codex.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,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AAS,CAAC;gBACd,IAAI,EAAE,OAAO;gBACb,GAAG,EAAE,SAAS;gBACd,WAAW,EAAE,IAAI,CAAC,GAAG,EAAE;gBACvB,GAAG,EAAE,sBAAsB;aACH,CAAC,EAC1B,MAAM,CACN,CAAC;YAEF,OAAO,YAAY,CAAC;QACrB,CAAC;QAED,MAAM,IAAI,KAAK,CAAC,QAAQ,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;IAC5C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,MAAM,GAAG,GAAG,KAAc,CAAC;QAC3B,OAAO,CAAC,KAAK,CACZ,yCAAyC,WAAW,4BAA4B,EAChF,GAAG,CAAC,OAAO,CACX,CAAC;QAEF,0CAA0C;QAC1C,IAAI,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;YAC3B,OAAO,CAAC,KAAK,CACZ,sCAAsC,WAAW,eAAe,CAChE,CAAC;YACF,OAAO,YAAY,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;QACxC,CAAC;QAED,sEAAsE;QACtE,OAAO,CAAC,KAAK,CACZ,kEAAkE,WAAW,EAAE,CAC/E,CAAC;QACF,OAAO,YAAY,CAAC,IAAI,CAAC,SAAS,EAAE,uBAAuB,CAAC,EAAE,MAAM,CAAC,CAAC;IACvE,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
|
+
}
|
|
91
|
+
//# sourceMappingURL=opencode-codex.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"opencode-codex.js","sourceRoot":"","sources":["../../../lib/prompts/opencode-codex.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,KAAK,E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