dev-flow-codex 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.
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "dev-flow-local",
3
+ "interface": {
4
+ "displayName": "Dev Flow Local"
5
+ },
6
+ "plugins": [
7
+ {
8
+ "name": "dev-flow-codex",
9
+ "source": {
10
+ "source": "local",
11
+ "path": "./plugin"
12
+ },
13
+ "policy": {
14
+ "installation": "AVAILABLE",
15
+ "authentication": "ON_INSTALL"
16
+ },
17
+ "category": "Productivity"
18
+ }
19
+ ]
20
+ }
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,243 @@
1
+ # dev-flow-codex
2
+
3
+ `dev-flow-codex` is the public-package contract for the Codex CLI product. It packages one Codex
4
+ plugin, one explicitly selected `dev-flow` Skill, one bundled STDIO MCP server definition, and one
5
+ `darwin-arm64` Dev Flow Core executable.
6
+
7
+ Feature 006 has not published this version yet. After an explicitly authorized release, the user
8
+ interface is:
9
+
10
+ ```bash
11
+ npm install -g dev-flow-codex
12
+ dev-flow-codex setup
13
+ ```
14
+
15
+ The supported product is limited to native macOS arm64, Node.js `>=24`, and Codex
16
+ `>=0.147.0 <0.148.0`; the exact merged host acceptance used Codex `0.147.0`. npm `os`/`cpu`
17
+ metadata rejects unsupported package installation, and setup repeats the platform preflight before
18
+ any Codex mutation. No Linux, Windows, Intel Mac, or DeepSeek support is claimed.
19
+
20
+ npm installation only places package-manager-owned files. Explicit `setup` registers Codex, and
21
+ explicit `remove` removes only proven product-owned registration. npm uninstall remains a separate
22
+ file-removal operation. Task data and unknown adjacent files are retained by default. The package
23
+ contains its Core and requires no Go toolchain, source checkout, first-run download, or separate
24
+ backend.
25
+
26
+ The production source layout is deliberately closed:
27
+
28
+ ```text
29
+ packages/codex/
30
+ ├── .agents/plugins/marketplace.json
31
+ ├── LICENSE
32
+ ├── bin/dev-flow-codex.mjs
33
+ ├── lib/{lifecycle,paths}.mjs
34
+ ├── plugin/.codex-plugin/plugin.json
35
+ ├── plugin/.mcp.json
36
+ ├── plugin/skills/dev-flow/SKILL.md
37
+ ├── plugin/skills/dev-flow/agents/openai.yaml
38
+ └── runtime/darwin-arm64/dev-flow # temporary build staging only
39
+ ```
40
+
41
+ The implementation baseline is Codex CLI `0.147.x` on macOS arm64. Sanitized fixtures and the
42
+ development smoke target that host contract. The final pre-merge acceptance report records the
43
+ actual Codex, package, and Core versions exercised; it is a product acceptance record, not an
44
+ indefinite compatibility promise or public-registry evidence.
45
+
46
+ Development requires Node.js `>=24`, pnpm `>=11 <12`, and the repository-pinned Go toolchain. The
47
+ package has no production npm dependency and no install, download, or host-mutation lifecycle hook.
48
+ Installation and explicit Codex registration are separate operations, and neither setup nor removal
49
+ may edit the current repository or delete Core-owned task data.
50
+
51
+ ## Local artifact and explicit setup
52
+
53
+ Create a temporary, non-final development artifact and install it with lifecycle scripts disabled:
54
+
55
+ ```bash
56
+ CODEX_ARTIFACT_DIR="$(mktemp -d -t dev-flow-codex-local.XXXXXX)"
57
+ ./scripts/build-codex-local.sh --output "$CODEX_ARTIFACT_DIR"
58
+
59
+ CODEX_INSTALL_PREFIX="$(mktemp -d -t dev-flow-codex-install.XXXXXX)"
60
+ npm install --ignore-scripts --no-audit --no-fund \
61
+ --prefix "$CODEX_INSTALL_PREFIX" \
62
+ "$CODEX_ARTIFACT_DIR/dev-flow-codex-0.1.0.tgz"
63
+ export PATH="$CODEX_INSTALL_PREFIX/node_modules/.bin:$PATH"
64
+ ```
65
+
66
+ Installation alone makes no Codex registration and runs no product lifecycle hook. Verify the
67
+ detached package/Core identity, then perform the separately authorized setup:
68
+
69
+ ```bash
70
+ dev-flow-codex --version
71
+ dev-flow-codex setup --json
72
+ codex plugin marketplace list --json
73
+ codex plugin list --json
74
+ ```
75
+
76
+ Setup supports only macOS arm64 in this feature. It verifies the installed Codex version against
77
+ the selected bounded range, the package/plugin/Core version identity, the package-local executable,
78
+ the one Skill, its explicit-only `agents/openai.yaml` policy, the typed MCP resource, and
79
+ `dev-flow-codex` discovery on `PATH` before its first registry write. It registers
80
+ `dev-flow-local` and `dev-flow-codex@dev-flow-local` through Codex JSON commands, validates the
81
+ official camelCase mutation results, and requires exact `{marketplaces: [...]}` plus
82
+ `{installed: [...], available: [...]}` readback before writing the ownership receipt at
83
+ `~/Library/Application Support/dev-flow/registrations/codex.json`. Matching repeated setup is a
84
+ no-op; malformed, incomplete, or conflicting state fails closed. Restart or open a fresh Codex
85
+ session after setup so the host refreshes plugin, Skill, and MCP discovery.
86
+
87
+ Without `DEV_FLOW_DATA_DIR`, `dev-flow-codex mcp` creates only
88
+ `~/Library/Application Support/dev-flow/data` with restrictive permissions. A nonempty override
89
+ must already be an absolute, canonical, usable directory. Runtime selection is always relative to
90
+ the installed package; it never falls back to a Core binary in the current repository.
91
+
92
+ ## Explicit invocation boundary
93
+
94
+ The official Skill metadata sets `policy.allow_implicit_invocation: false`. The Skill resource/base name is `dev-flow`;
95
+ the installed Skill full name is `dev-flow-codex:dev-flow`. The only exact explicit selector is `$dev-flow-codex:dev-flow`.
96
+ Bare `$dev-flow` is not an alias and does not select this installed Skill. A wrong plugin namespace,
97
+ a wrong Skill base name, or a missing selector also does not select it.
98
+ Codex 0.147 registers plugin MCP tools independently from Skill injection, so this package does not
99
+ claim selector-bound MCP visibility or authorization. An ordinary prompt must make zero Dev Flow
100
+ calls. Other non-exact selectors must not complete a task-bearing operation or change task, event,
101
+ or claim state; host-exposed read-only and Core-rejected calls remain observable. Non-exact Skill
102
+ selection does not disable ordinary Codex repository tools or revoke work independently authorized
103
+ by the rest of the prompt. Final acceptance therefore uses a non-mutating bare-selector probe and
104
+ verifies that controlled probe leaves the repository unchanged.
105
+ `$dev-flow-codex:dev-flow` with no substantive requirement, a conversational request, a non-Git
106
+ directory, or work spanning more than one repository stops before Skill-owned task discovery.
107
+ For an admitted request, the Skill resolves one canonical current worktree and calls
108
+ `dev_flow_server_info({})` first; an incomplete or incompatible six-tool catalog stops the request.
109
+
110
+ ## Core-governed create and resume
111
+
112
+ After the handshake, a new invocation opens one `host=codex` task using only the bounded user
113
+ request, repository instructions, acceptance criteria, exclusions, and verification authority. An
114
+ explicit resume omits `new_task`; Core must return the compatible active task. A restart/resume must
115
+ preserve the same task ID and continue its advancing revision lineage. An ownership or contract
116
+ conflict stops the invocation without choosing, merging, or replacing task records.
117
+
118
+ Every iteration consumes one complete fresh Core action. Its task/revision/action identity,
119
+ repository binding, allowed effects, required evidence, payload schema, blocker, and outcome stay
120
+ together. Codex performs only the allowed effect, constructs the returned closed payload, retains a
121
+ request ID, and submits exactly one mutation. A complete success continues only from the returned
122
+ next action or a fresh Core read; Codex does not infer transitions or completion.
123
+
124
+ If a mutation result is missing, cancelled, malformed, truncated, or otherwise uncertain, read
125
+ before retry: retain the exact original operation, call `dev_flow_get_task` and
126
+ `dev_flow_get_next_action`, and follow only Core's recovery assessment. Never reconstruct a missing
127
+ operation probe or repeat a mutation because its response was lost.
128
+
129
+ Every completed host command event is retained only as role-scoped status, exit code, and safe
130
+ command/output hashes. Ambient commands in the ordinary or invalid sessions and repository
131
+ inspection or implementation commands in active sessions are non-verification facts. Only the one
132
+ Core-submitted and retained logical proof, rendered by Codex 0.147 on macOS as the closed supported
133
+ command, counts against the verification budget. An unbound or duplicate proof and any known test
134
+ or full-suite command fail closed. Do not run a forbidden full suite; when automatic capacity is
135
+ exhausted, report an honest manual handoff.
136
+ Static, simulated, user-performed, and native evidence keep distinct labels. A Core blocker,
137
+ ownership/contract conflict, `CANCELLED`, or Core-owned `DONE` outcome stops repository work and is
138
+ reported without reinterpretation.
139
+
140
+ ## Explicit removal and retained task data
141
+
142
+ Deregister before running npm uninstall:
143
+
144
+ ```bash
145
+ dev-flow-codex remove --json
146
+ npm uninstall -g --ignore-scripts dev-flow-codex
147
+ ```
148
+
149
+ Removal is receipt-first. It reads and validates the exact ownership receipt, reads current Codex
150
+ marketplace/plugin state, and fails closed on an identity, root, or readback conflict before any
151
+ mutation. It removes the matching plugin, verifies absence, removes the matching marketplace,
152
+ verifies absence again, and deletes only the exact receipt. An interrupted removal keeps the
153
+ receipt, so the next explicit call can resume from fresh readback. Repeated removal after complete
154
+ absence is an idempotent no-op.
155
+
156
+ The command does not delete the npm package, Core task data, repository, Codex config/cache, receipt
157
+ parents, or unknown adjacent resources. Stop Core before comparing task-data manifests; after
158
+ deregistration, directly reopen the recorded task with Core to prove retention. Perform npm
159
+ uninstall separately only after successful absence readback. A later artifact within the selected
160
+ compatible range may be installed and explicitly set up again against the retained data.
161
+
162
+ Setup, version reporting, and removal are package/user-state operations and behave the same from
163
+ any working directory. They do not add configuration, databases, instructions, or generated files
164
+ to the target repository and never mutate Git.
165
+
166
+ The `>=0.147.0 <0.148.0` line and exact `0.147.0` host were selected on 2026-08-15, not promised
167
+ indefinitely. The selected MCP file uses Agent Plugins v1 `$schema`, camelCase `mcpServers`, and one
168
+ `type: stdio` entry, a shape accepted by both 0.147 plugin parsers. A future changed official
169
+ contract requires every compatibility-bearing contract, test, and guide to be updated before a
170
+ final artifact is built.
171
+
172
+ ## Deterministic validation
173
+
174
+ Run the product-bearing package layers directly:
175
+
176
+ ```bash
177
+ pnpm --dir packages/codex test:package
178
+ pnpm --dir packages/codex test:lifecycle
179
+ pnpm --dir packages/codex test:parser
180
+ pnpm --dir packages/codex test:native-smoke
181
+ pnpm --dir packages/codex pack:dry
182
+ ```
183
+
184
+ The checked-in Codex 0.147 fixtures cover three mutually exclusive terminal shapes without starting
185
+ Codex: completed success with text/structured parity, failed Core-domain result with the same parity,
186
+ and failed transport with no complete Core result. They contain no prompt, source, user path,
187
+ environment, token, or secret.
188
+
189
+ ```bash
190
+ ./scripts/run-codex-real-journey.sh --fixture success
191
+ ./scripts/run-codex-real-journey.sh --fixture core-domain-error
192
+ ./scripts/run-codex-real-journey.sh --fixture transport-error
193
+ ```
194
+
195
+ ## Repeatable development smoke
196
+
197
+ After deterministic checks are green, run the full isolated chain twice with fresh empty result
198
+ directories and labels `A` then `B`:
199
+
200
+ ```bash
201
+ ./scripts/run-codex-real-journey.sh \
202
+ --development-smoke \
203
+ --run-label A \
204
+ --codex-executable "$CODEX_EXECUTABLE" \
205
+ --result-directory "$CODEX_SMOKE_RESULT_DIRECTORY"
206
+ ```
207
+
208
+ Each invocation builds and installs a non-final package in one new temporary root, performs setup,
209
+ four fresh Codex 0.147 sessions, removal, and a direct packaged-Core retention read, then deletes the
210
+ temporary root. The external `smoke-result.json` is a development result, not final acceptance or a
211
+ formal support statement; failures add only a bounded, hashed diagnostic.
212
+
213
+ ## Final pre-merge acceptance
214
+
215
+ The four native HIGH regressions are closed, and two fresh isolated Codex 0.147 development-smoke
216
+ runs passed with distinct tasks. Those runs establish repeatability but do not replace acceptance.
217
+ Run one final real-host acceptance against the reviewed commit immediately before merge approval.
218
+ The real-host entry point records ephemeral session observations:
219
+
220
+ ```bash
221
+ ./scripts/run-codex-real-journey.sh \
222
+ --acceptance \
223
+ --codex-executable "$CODEX_EXECUTABLE" \
224
+ --workspace "$CODEX_ACCEPTANCE_WORKTREE"
225
+ ```
226
+
227
+ The observation itself does not claim acceptance. A single simplified JSON report must then record
228
+ the reviewed source and artifact identities, Codex/package/Core versions, setup readback, zero Core
229
+ calls for the ordinary prompt, unchanged Core/repository state around the non-mutating bare-selector
230
+ probe, the exact selector, the same task ID across restart, at least two
231
+ committed actions, Core `DONE`, successful removal readback, retained and reopened task data, and an
232
+ empty unexpected-repository-path list. Package and Core versions must match. Validate that closed
233
+ object without creating any additional report files:
234
+
235
+ ```bash
236
+ node scripts/write-codex-journey-evidence.mjs \
237
+ acceptance-report \
238
+ --report "$CODEX_ACCEPTANCE_REPORT"
239
+ ```
240
+
241
+ Feature 003 uses this one acceptance report only as a pre-merge product gate. It does not implement
242
+ a release or supply-chain proof system. Public npm publication, GitHub releases, tags,
243
+ Windows/Linux claims, IDE support, and additional Codex surfaces remain out of scope.
@@ -0,0 +1,216 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { spawn } from "node:child_process";
4
+ import { constants as fsConstants, realpathSync } from "node:fs";
5
+ import { access, readFile, stat } from "node:fs/promises";
6
+ import { pathToFileURL } from "node:url";
7
+
8
+ import {
9
+ inspectCoreVersion,
10
+ removeRegistration,
11
+ setupRegistration,
12
+ } from "../lib/lifecycle.mjs";
13
+ import {
14
+ ensureDefaultDataDirectory,
15
+ resolveProductPaths,
16
+ } from "../lib/paths.mjs";
17
+
18
+ const FORWARDED_SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
19
+ const NPM_UNINSTALL_HANDOFF = "Run npm uninstall dev-flow-codex separately after deregistration.";
20
+ const CODEX_MCP_INSTRUCTIONS_ENVIRONMENT = "DEV_FLOW_CODEX_MCP_INSTRUCTIONS";
21
+ const CODEX_MCP_INSTRUCTIONS = [
22
+ "Dev Flow for Codex is explicit-only.",
23
+ "Do not call tools from this server unless the current user turn contains the exact selector `$dev-flow-codex:dev-flow`.",
24
+ "Bare `$dev-flow`, wrong or missing selectors, and implicit matches are not activation.",
25
+ "After valid selection, `dev_flow_server_info` must be the first Dev Flow call.",
26
+ "Call `dev_flow_open_task` only after exact `$dev-flow-codex:dev-flow` selection and a successful `dev_flow_server_info` handshake.",
27
+ ].join(" ");
28
+
29
+ export async function runCLI(arguments_, dependencies = {}) {
30
+ const stdout = dependencies.stdout ?? process.stdout;
31
+ const stderr = dependencies.stderr ?? process.stderr;
32
+ const environment = dependencies.environment ?? process.env;
33
+ const resolvePaths = dependencies.resolvePaths ?? (() => resolveProductPaths({ environment }));
34
+ const readPackageVersion = dependencies.readPackageVersion ?? readInstalledPackageVersion;
35
+ const inspectVersion = dependencies.inspectCoreVersion ?? inspectCoreVersion;
36
+ const ensureDataDirectory = dependencies.ensureDefaultDataDirectory ?? ensureDefaultDataDirectory;
37
+ const setup = dependencies.setupRegistration ?? setupRegistration;
38
+
39
+ if (!isProductionCommand(arguments_)) {
40
+ stderr.write("dev-flow-codex: invalid arguments; expected setup [--json], remove [--json], mcp, or --version\n");
41
+ return { code: 2, signal: null };
42
+ }
43
+
44
+ try {
45
+ const paths = await resolvePaths();
46
+ if (arguments_.length === 1 && arguments_[0] === "mcp") {
47
+ if (paths.usesDefaultDataDirectory) await ensureDataDirectory(paths);
48
+ return await launchPackagedCore(paths, ["mcp", "--stdio"], {
49
+ environment,
50
+ spawnImpl: dependencies.spawnImpl ?? spawn,
51
+ signalSource: dependencies.signalSource ?? process,
52
+ });
53
+ }
54
+
55
+ const packageVersion = await readPackageVersion(paths.packageRoot);
56
+ if (arguments_.length === 1 && arguments_[0] === "--version") {
57
+ const coreVersion = await inspectVersion(paths.runtimePath, {
58
+ environment,
59
+ currentDirectory: paths.packageRoot,
60
+ });
61
+ if (coreVersion !== packageVersion) {
62
+ throw new Error(`package version ${packageVersion} does not match Core version ${coreVersion}`);
63
+ }
64
+ stdout.write(`dev-flow-codex ${packageVersion} (core ${coreVersion})\n`);
65
+ return { code: 0, signal: null };
66
+ }
67
+
68
+ const json = arguments_.at(-1) === "--json";
69
+ if (arguments_[0] === "setup") {
70
+ const result = await setup({
71
+ paths,
72
+ packageVersion,
73
+ codexExecutable: dependencies.codexExecutable ?? "codex",
74
+ environment,
75
+ now: dependencies.now,
76
+ });
77
+ writeLifecycleSuccess(stdout, "setup", result, paths.receiptPath, json);
78
+ return { code: 0, signal: null };
79
+ }
80
+
81
+ const remove = dependencies.removeRegistration ?? removeRegistration;
82
+ const result = await remove({
83
+ paths,
84
+ packageVersion,
85
+ codexExecutable: dependencies.codexExecutable ?? "codex",
86
+ environment,
87
+ });
88
+ writeLifecycleSuccess(stdout, "remove", result, paths.receiptPath, json);
89
+ return { code: 0, signal: null };
90
+ } catch (error) {
91
+ stderr.write(`dev-flow-codex: ${error.message}\n`);
92
+ return { code: 1, signal: null };
93
+ }
94
+ }
95
+
96
+ export async function launchPackagedCore(
97
+ paths,
98
+ arguments_,
99
+ {
100
+ environment = process.env,
101
+ spawnImpl = spawn,
102
+ signalSource = process,
103
+ } = {},
104
+ ) {
105
+ await assertExecutableRuntime(paths.runtimePath);
106
+ let child;
107
+ try {
108
+ child = spawnImpl(paths.runtimePath, arguments_, {
109
+ cwd: paths.packageRoot,
110
+ env: {
111
+ ...environment,
112
+ DEV_FLOW_DATA_DIR: paths.dataDirectory,
113
+ [CODEX_MCP_INSTRUCTIONS_ENVIRONMENT]: CODEX_MCP_INSTRUCTIONS,
114
+ },
115
+ stdio: "inherit",
116
+ shell: false,
117
+ windowsHide: true,
118
+ });
119
+ } catch (error) {
120
+ throw new Error("start packaged Core", { cause: error });
121
+ }
122
+
123
+ const handlers = new Map();
124
+ for (const signal of FORWARDED_SIGNALS) {
125
+ const handler = () => child.kill(signal);
126
+ handlers.set(signal, handler);
127
+ signalSource.on(signal, handler);
128
+ }
129
+ const cleanup = () => {
130
+ for (const [signal, handler] of handlers) signalSource.off(signal, handler);
131
+ };
132
+
133
+ return await new Promise((resolve, reject) => {
134
+ child.once("error", (error) => {
135
+ cleanup();
136
+ reject(new Error("packaged Core process failed to start", { cause: error }));
137
+ });
138
+ child.once("exit", (code, signal) => {
139
+ cleanup();
140
+ resolve({ code, signal });
141
+ });
142
+ });
143
+ }
144
+
145
+ async function readInstalledPackageVersion(packageRoot) {
146
+ let manifest;
147
+ try {
148
+ manifest = JSON.parse(await readFile(new URL("../package.json", pathToFileURL(`${packageRoot}/bin/`)), "utf8"));
149
+ } catch (error) {
150
+ throw new Error("read installed package identity", { cause: error });
151
+ }
152
+ if (manifest.name !== "dev-flow-codex" || typeof manifest.version !== "string") {
153
+ throw new Error("installed package identity is invalid");
154
+ }
155
+ return manifest.version;
156
+ }
157
+
158
+ async function assertExecutableRuntime(runtimePath) {
159
+ let info;
160
+ try {
161
+ info = await stat(runtimePath);
162
+ await access(runtimePath, fsConstants.X_OK);
163
+ } catch (error) {
164
+ throw new Error("packaged Core must exist and be executable", { cause: error });
165
+ }
166
+ if (!info.isFile() || (info.mode & 0o111) === 0) {
167
+ throw new Error("packaged Core must exist and be executable");
168
+ }
169
+ }
170
+
171
+ function writeLifecycleSuccess(stdout, operation, result, receiptPath, json) {
172
+ if (json) {
173
+ const output = {
174
+ operation,
175
+ status: result.status,
176
+ changed: result.changed,
177
+ receipt_path: receiptPath,
178
+ };
179
+ if (operation === "remove") output.next_step = NPM_UNINSTALL_HANDOFF;
180
+ stdout.write(`${JSON.stringify(output)}\n`);
181
+ return;
182
+ }
183
+ stdout.write(`dev-flow-codex ${operation}: ${result.status}\n`);
184
+ if (operation === "remove") stdout.write(`${NPM_UNINSTALL_HANDOFF}\n`);
185
+ }
186
+
187
+ function isProductionCommand(arguments_) {
188
+ if (!Array.isArray(arguments_)) return false;
189
+ if (arguments_.length === 1 && ["mcp", "--version"].includes(arguments_[0])) return true;
190
+ return (
191
+ (arguments_.length === 1 || arguments_.length === 2 && arguments_[1] === "--json") &&
192
+ ["setup", "remove"].includes(arguments_[0])
193
+ );
194
+ }
195
+
196
+ function isMainModule() {
197
+ if (!process.argv[1]) return false;
198
+ try {
199
+ return pathToFileURL(realpathSync(process.argv[1])).href === import.meta.url;
200
+ } catch {
201
+ return false;
202
+ }
203
+ }
204
+
205
+ if (isMainModule()) {
206
+ const result = await runCLI(process.argv.slice(2));
207
+ if (result.signal) {
208
+ try {
209
+ process.kill(process.pid, result.signal);
210
+ } catch {
211
+ process.exitCode = 1;
212
+ }
213
+ } else {
214
+ process.exitCode = result.code ?? 1;
215
+ }
216
+ }