deepcodex 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/.codex-plugin/plugin.json +24 -0
  2. package/LICENSE +21 -0
  3. package/README.md +178 -0
  4. package/bin/opencodex.js +49 -0
  5. package/config/desktop.json +9 -0
  6. package/config/pilot.json +16 -0
  7. package/config/worker.json +78 -0
  8. package/node_modules/smol-toml/LICENSE +24 -0
  9. package/node_modules/smol-toml/README.md +418 -0
  10. package/node_modules/smol-toml/dist/date.d.ts +41 -0
  11. package/node_modules/smol-toml/dist/date.js +127 -0
  12. package/node_modules/smol-toml/dist/error.d.ts +38 -0
  13. package/node_modules/smol-toml/dist/error.js +63 -0
  14. package/node_modules/smol-toml/dist/extract.js +69 -0
  15. package/node_modules/smol-toml/dist/index.cjs +734 -0
  16. package/node_modules/smol-toml/dist/index.d.ts +43 -0
  17. package/node_modules/smol-toml/dist/index.js +33 -0
  18. package/node_modules/smol-toml/dist/parse.d.ts +36 -0
  19. package/node_modules/smol-toml/dist/parse.js +149 -0
  20. package/node_modules/smol-toml/dist/primitive.js +238 -0
  21. package/node_modules/smol-toml/dist/stringify.d.ts +31 -0
  22. package/node_modules/smol-toml/dist/stringify.js +181 -0
  23. package/node_modules/smol-toml/dist/struct.js +179 -0
  24. package/node_modules/smol-toml/dist/util.d.ts +38 -0
  25. package/node_modules/smol-toml/dist/util.js +89 -0
  26. package/node_modules/smol-toml/package.json +68 -0
  27. package/package.json +47 -0
  28. package/prompts/worker.md +20 -0
  29. package/scripts/credentials.js +102 -0
  30. package/scripts/desktop.js +199 -0
  31. package/scripts/pilot-router.js +241 -0
  32. package/scripts/pilot.js +242 -0
  33. package/scripts/toml.js +6 -0
  34. package/scripts/worker.js +637 -0
  35. package/skills/delegate-flash/SKILL.md +63 -0
  36. package/vendor/codex-router/LICENSE +21 -0
  37. package/vendor/codex-router/deepseek-responses.js +55 -0
  38. package/vendor/codex-router/json-number-rewrite.js +58 -0
  39. package/vendor/codex-router/namespace-relay.js +4294 -0
  40. package/vendor/codex-router/sse-prefix.js +115 -0
  41. package/vendor/codex-router/subagent-completion.js +261 -0
  42. package/vendor/codex-router/tool-arguments.js +111 -0
  43. package/vendor/codex-router/tool-schema-root.js +1008 -0
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "opencodex",
3
+ "version": "0.1.0+codex.20260917024812",
4
+ "description": "Delegates tasks to native DeepSeek Flash subagents inside Codex through a local router.",
5
+ "author": {
6
+ "name": "OpenCodex"
7
+ },
8
+ "skills": "./skills/",
9
+ "interface": {
10
+ "displayName": "OpenCodex",
11
+ "shortDescription": "Astra coordinates; DeepSeek Flash executes.",
12
+ "longDescription": "Keeps the coordinator model and connects DeepSeek Flash as a native subagent, with tracking, tools, and results inside Codex.",
13
+ "developerName": "OpenCodex",
14
+ "category": "Productivity",
15
+ "capabilities": [
16
+ "Read",
17
+ "Write"
18
+ ],
19
+ "defaultPrompt": [
20
+ "Check whether OpenCodex is ready.",
21
+ "Delegate this implementation to Flash with OpenCodex."
22
+ ]
23
+ }
24
+ }
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 OpenCodex contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,178 @@
1
+ # OpenCodex
2
+
3
+ OpenCodex keeps the coordinator on your selected native Codex model and runs
4
+ DeepSeek Flash as an actual Codex subagent through a local loopback router. The
5
+ subagent appears in the normal collaboration tools (`spawn_agent`,
6
+ `followup_task`, `wait_agent`, `interrupt_agent`) under the model name
7
+ `deepseek-flash`. Nothing is disguised under an OpenAI model name, and the
8
+ native coordinator model is not replaced.
9
+
10
+ ## Requirements
11
+
12
+ - macOS. The installer and the LaunchAgent service are macOS-only.
13
+ - Node.js >= 22.15. The worker uses `node:sqlite`, `fetch` and
14
+ `import.meta.resolve`.
15
+ - A Codex CLI on `PATH` whose `codex exec` supports `--ignore-user-config`,
16
+ `--ephemeral`, `--json` and `--strict-config`. `opencodex doctor` verifies
17
+ this before anything else is activated.
18
+ - A DeepSeek API key.
19
+
20
+ ## Install globally
21
+
22
+ Once the package is published to npm:
23
+
24
+ ```sh
25
+ npm install --global opencodex
26
+ opencodex configure
27
+ opencodex doctor
28
+ opencodex install
29
+ ```
30
+
31
+ The global installation adds `opencodex` to npm's global bin directory, which
32
+ must be on your `PATH`. Run it from any directory; no checkout path is needed.
33
+
34
+ To install the local checkout globally before publication, run these commands
35
+ from the repository, then use the same `opencodex` commands above:
36
+
37
+ ```sh
38
+ pnpm install --frozen-lockfile
39
+ npm install --global .
40
+ ```
41
+
42
+ ### 1. `opencodex configure`
43
+
44
+ `configure` asks for the DeepSeek API key with hidden input on the terminal and
45
+ stores it in `~/.config/opencodex/.env`. It creates the directory with mode
46
+ `0700` and the file with mode `0600`, and it writes the key as plaintext in that
47
+ file rather than in the macOS keychain.
48
+
49
+ The command does not accept a key argument or piped input, keeping the key out
50
+ of shell history and process arguments. Press Ctrl-C to cancel without changing
51
+ the saved key. Re-running `configure` replaces the key while preserving other
52
+ variables in the file. Run `install` again to reload an already running router.
53
+
54
+ `config/worker.json` defines the credential file location. `doctor` and `run`
55
+ prefer `DEEPSEEK_API_KEY` from their environment when set; otherwise they read
56
+ the file, as does the installed desktop service. Credentials stay outside the
57
+ repository. The file permissions restrict other users, but programs running as
58
+ your user can still read it.
59
+
60
+ ### 2. `opencodex doctor`
61
+
62
+ `doctor` checks the local prerequisites without running inference: that a
63
+ compatible Codex CLI is reachable and that the DeepSeek credential is present.
64
+ Run it after `configure` and before `install`; `install` refuses to continue
65
+ unless the doctor reports `ready`.
66
+ Neither `configure` nor `doctor` contacts DeepSeek to validate the key. A `ready`
67
+ result confirms local prerequisites, not provider authentication or account credit.
68
+
69
+ ### 3. `opencodex install`
70
+
71
+ `install` activates the desktop integration:
72
+
73
+ - copies a stable runtime (scripts, config, prompts, vendor code and the bundled
74
+ dependency) to `~/.local/share/opencodex/runtime`;
75
+ - writes private state, the model catalog and receipts to
76
+ `~/.config/opencodex/desktop`;
77
+ - installs and starts the `com.opencodex.router` LaunchAgent, bound only to
78
+ `127.0.0.1:4207`;
79
+ - updates `~/.codex/config.toml` with the local provider, the subagent defaults
80
+ and the generated model catalog, keeping a pre-install backup at
81
+ `~/.config/opencodex/desktop/config.before.toml`.
82
+
83
+ The installer refuses to run when an unrelated custom provider is active or when
84
+ an endpoint override is already configured, and it leaves your configuration
85
+ untouched if the service does not become healthy.
86
+
87
+ After `install`, fully quit and reopen Codex Desktop and start a new task. Tasks
88
+ that were already open keep the provider and model catalog they started with.
89
+
90
+ ## Plugin skill
91
+
92
+ The delegation skill lives in `skills/delegate-flash/SKILL.md` and is loaded by
93
+ installing the OpenCodex plugin through a Codex marketplace. Installing the npm
94
+ package or running the commands above does not install the skill, and this
95
+ checkout is not a marketplace source by itself.
96
+
97
+ ## Commands
98
+
99
+ | Command | Purpose |
100
+ | --- | --- |
101
+ | `opencodex configure` | Prompt for the DeepSeek API key and write `~/.config/opencodex/.env`. |
102
+ | `opencodex doctor` | Check Codex CLI compatibility and credential presence without inference. |
103
+ | `opencodex install` | Install the router runtime, the LaunchAgent and the user-level Codex settings. |
104
+ | `opencodex status` | Query the installed router health endpoint without inference. |
105
+ | `opencodex run --cwd PATH --task-file PATH [--write]` | Run one bounded isolated worker ticket against DeepSeek. Read-only unless `--write` is given. |
106
+ | `opencodex pilot` | Run the opt-in live native-delegation test; consumes Codex and DeepSeek usage. |
107
+ | `opencodex --version`, `opencodex --help` | Print the package version or the command list. |
108
+
109
+ `run` executes a single ticket and consumes DeepSeek API usage. It takes an
110
+ exclusive per-user lock, so only one worker runs at a time.
111
+
112
+ ## How it works
113
+
114
+ ### Request routing
115
+
116
+ Codex talks to the router on loopback. The router authenticates each request
117
+ with a capability token generated at install time and stored with mode `0600`,
118
+ then routes by model:
119
+
120
+ - requests for the child model (`deepseek-flash`) go to the DeepSeek Responses
121
+ API with the DeepSeek key;
122
+ - requests for any other model in the configured catalog go to the native Codex
123
+ backend with the client's own authentication headers, which are forwarded only
124
+ there.
125
+
126
+ The DeepSeek key is never sent to the native backend, and native Codex
127
+ authentication is never sent to DeepSeek.
128
+
129
+ ### Tool routing
130
+
131
+ Codex tool definitions, namespaces and history are adapted to what the DeepSeek
132
+ Responses API accepts, and the streaming response is transformed back into the
133
+ Codex collaboration shape. That adaptation is the vendored `codex-router` code
134
+ in `vendor/codex-router`, used under its MIT license.
135
+
136
+ ### Encrypted handoff relay
137
+
138
+ Subagent tasks can travel from Codex as encrypted `agent_message` payloads that
139
+ the native backend can decode. For each uncached message the router makes a relay
140
+ call to the native model, asking it to return the exact plaintext and not to
141
+ answer the task itself, and then forwards that plaintext to DeepSeek. This is
142
+ why a delegated task consumes both Codex quota and DeepSeek API usage.
143
+
144
+ ### Local data
145
+
146
+ The router writes bounded receipts to
147
+ `~/.config/opencodex/desktop/receipts.jsonl`: routing decisions, model names,
148
+ tool names, task counts and token usage. Prompts, tool arguments and credentials
149
+ are not recorded. On errors, the receipt message has the DeepSeek key and the
150
+ capability token redacted.
151
+
152
+ ## Tests
153
+
154
+ ```sh
155
+ pnpm test
156
+ ```
157
+
158
+ The default suite is offline: it uses fixtures and spends no provider usage. The
159
+ Codex transport test is skipped unless `OPENCODEX_TEST_CODEX` points at a real
160
+ `codex` binary; when it is set, that test launches the real CLI against a local
161
+ fixture server. Treat it as an optional, deliberate opt-in rather than part of a
162
+ routine run.
163
+
164
+ ## Security notes
165
+
166
+ - The router listens only on `127.0.0.1` and rejects requests without the
167
+ generated capability token.
168
+ - Credentials live in `~/.config/opencodex/.env` (`0700` directory, `0600`
169
+ file), outside the repository.
170
+ - Receipts and router state live in the private `0700` directory
171
+ `~/.config/opencodex/desktop`.
172
+ - Subagents inherit Codex permissions. A ticket's allowed files are instructions
173
+ to the worker, not a filesystem sandbox.
174
+
175
+ ## License
176
+
177
+ MIT; see [LICENSE](LICENSE). Vendored `codex-router` code retains its own
178
+ copyright notice and [MIT license](vendor/codex-router/LICENSE).
@@ -0,0 +1,49 @@
1
+ #!/usr/bin/env node
2
+ import { readFileSync } from 'node:fs';
3
+
4
+ const args = process.argv.slice(2);
5
+ const command = args.shift();
6
+ const help = `Usage: opencodex <command>
7
+
8
+ Commands:
9
+ configure Save the DeepSeek key using a hidden terminal prompt
10
+ install Activate the local macOS router and configure Codex
11
+ status Check the installed router without inference
12
+ doctor Check worker prerequisites without inference
13
+ run Run an isolated worker ticket (consumes DeepSeek usage)
14
+ pilot Test native delegation (consumes Codex and DeepSeek usage)
15
+
16
+ Requires macOS, Node.js >=22.15 and a compatible Codex CLI.
17
+ Run opencodex configure to save the DeepSeek key in ~/.config/opencodex/.env.
18
+ Installing this npm package does not activate the router or install the skill
19
+ in Codex. Install the plugin through a Codex marketplace to load its skill.
20
+ Use opencodex <command> --help for command options.
21
+ `;
22
+
23
+ if (!command || command === '--help' || command === '-h') {
24
+ process.stdout.write(help);
25
+ } else if (command === '--version' || command === '-v') {
26
+ const manifest = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
27
+ console.log(manifest.version);
28
+ } else {
29
+ const scripts = { configure: 'credentials.js', install: 'desktop.js', status: 'desktop.js', doctor: 'worker.js', run: 'worker.js', pilot: 'pilot.js' };
30
+ if (!Object.hasOwn(scripts, command)) {
31
+ console.error(`Unknown command: ${command}\n${help}`);
32
+ process.exit(2);
33
+ }
34
+ if (command === 'pilot' && args.length) {
35
+ if (args.length === 1 && ['--help', '-h'].includes(args[0])) {
36
+ console.log('Usage: opencodex pilot\nRuns a live native delegation test; consumes Codex and DeepSeek usage.');
37
+ process.exit(0);
38
+ }
39
+ console.error('Usage: opencodex pilot (no arguments)');
40
+ process.exit(2);
41
+ }
42
+ try {
43
+ const script = await import(new URL(`../scripts/${scripts[command]}`, import.meta.url));
44
+ process.exitCode = command === 'pilot' ? await script.run() : await script.main([command, ...args]);
45
+ } catch (error) {
46
+ console.error(`OpenCodex failed: ${error.message}`);
47
+ process.exitCode = 1;
48
+ }
49
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "port": 4207,
3
+ "max_requests": null,
4
+ "request_timeout_ms": 300000,
5
+ "max_request_bytes": 134217728,
6
+ "max_response_bytes": 33554432,
7
+ "service_label": "com.opencodex.router",
8
+ "service_throttle_seconds": 10
9
+ }
@@ -0,0 +1,16 @@
1
+ {
2
+ "parent_model": "gpt-6-astra",
3
+ "parent_effort": "low",
4
+ "relay_model": "gpt-6-astra",
5
+ "native_url": "https://chatgpt.com/backend-api/codex/responses",
6
+ "timeout_seconds": 300,
7
+ "request_timeout_ms": 120000,
8
+ "max_request_bytes": 8388608,
9
+ "max_response_bytes": 8388608,
10
+ "max_requests": 20,
11
+ "port": 0,
12
+ "relay_cache_entries": 128,
13
+ "relay_cache_ttl_ms": 900000,
14
+ "log_max_bytes": 4194304,
15
+ "startup_timeout_seconds": 10
16
+ }
@@ -0,0 +1,78 @@
1
+ {
2
+ "credentials": {"env_file": "~/.config/opencodex/.env"},
3
+ "codex": {
4
+ "model": "deepseek-flash",
5
+ "model_provider": "opencodex-deepseek",
6
+ "model_reasoning_effort": "high",
7
+ "web_search": "disabled",
8
+ "approval_policy": "never",
9
+ "model_providers": {
10
+ "opencodex-deepseek": {
11
+ "name": "DeepSeek direct",
12
+ "base_url": "https://api.deepseek.com",
13
+ "wire_api": "responses",
14
+ "env_key": "DEEPSEEK_API_KEY",
15
+ "requires_openai_auth": false,
16
+ "supports_websockets": false,
17
+ "request_max_retries": 0,
18
+ "stream_max_retries": 0,
19
+ "stream_idle_timeout_ms": 120000
20
+ }
21
+ },
22
+ "agents": {"enabled": false},
23
+ "features": {
24
+ "multi_agent": false,
25
+ "multi_agent_v2": false,
26
+ "plugins": false,
27
+ "apps": false,
28
+ "hooks": false,
29
+ "memories": false,
30
+ "shell_snapshot": false,
31
+ "context_management": {"experimental_mode": false}
32
+ },
33
+ "shell_environment_policy": {
34
+ "inherit": "core",
35
+ "ignore_default_excludes": false,
36
+ "experimental_use_profile": false,
37
+ "filters": {"DEEPSEEK_API_KEY": "exclude"}
38
+ },
39
+ "sandbox_workspace_write": {"network_access": false}
40
+ },
41
+ "model_metadata": {
42
+ "display_name": "DeepSeek Flash (OpenCodex)",
43
+ "description": "Text worker using the direct DeepSeek API.",
44
+ "default_reasoning_level": "high",
45
+ "supported_reasoning_levels": [
46
+ {"effort": "low", "description": "Simple tasks"},
47
+ {"effort": "high", "description": "Implementation"},
48
+ {"effort": "max", "description": "Complex problems"}
49
+ ],
50
+ "shell_type": "shell_command",
51
+ "visibility": "list",
52
+ "supported_in_api": true,
53
+ "experimental_supported_tools": [],
54
+ "supports_image_detail_original": false,
55
+ "comp_hash": "opencodex-0.1.0",
56
+ "priority": 1,
57
+ "context_window": 1048576,
58
+ "max_context_window": 1048576,
59
+ "effective_context_window_percent": 95,
60
+ "default_reasoning_summary": "none",
61
+ "support_verbosity": false,
62
+ "apply_patch_tool_type": "freeform",
63
+ "truncation_policy": {"mode": "tokens", "limit": 10000},
64
+ "input_modalities": ["text"],
65
+ "supports_search_tool": false,
66
+ "supports_experimental_context": false,
67
+ "use_responses_lite": false
68
+ },
69
+ "limits": {
70
+ "timeout_seconds": 900,
71
+ "poll_interval_seconds": 0.2,
72
+ "max_task_bytes": 65536,
73
+ "max_output_bytes": 8388608,
74
+ "max_result_chars": 24000,
75
+ "max_error_chars": 2000,
76
+ "version_timeout_seconds": 10
77
+ }
78
+ }
@@ -0,0 +1,24 @@
1
+ Copyright (c) Squirrel Chat et al., All rights reserved.
2
+
3
+ Redistribution and use in source and binary forms, with or without
4
+ modification, are permitted provided that the following conditions are met:
5
+
6
+ 1. Redistributions of source code must retain the above copyright notice, this
7
+ list of conditions and the following disclaimer.
8
+ 2. Redistributions in binary form must reproduce the above copyright notice,
9
+ this list of conditions and the following disclaimer in the
10
+ documentation and/or other materials provided with the distribution.
11
+ 3. Neither the name of the copyright holder nor the names of its contributors
12
+ may be used to endorse or promote products derived from this software without
13
+ specific prior written permission.
14
+
15
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
19
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.