@jjlabsio/claude-crew 0.1.31 → 0.1.32

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.
@@ -11,7 +11,7 @@
11
11
  "name": "claude-crew",
12
12
  "source": "./",
13
13
  "description": "오케스트레이터 + PM, 플래너, 개발, QA, 마케팅 에이전트 팀으로 단일 제품의 개발과 마케팅을 통합 관리",
14
- "version": "0.1.31",
14
+ "version": "0.1.32",
15
15
  "author": {
16
16
  "name": "Jaejin Song",
17
17
  "email": "wowlxx28@gmail.com"
@@ -28,5 +28,5 @@
28
28
  "category": "workflow"
29
29
  }
30
30
  ],
31
- "version": "0.1.31"
31
+ "version": "0.1.32"
32
32
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-crew",
3
- "version": "0.1.31",
3
+ "version": "0.1.32",
4
4
  "description": "1인 SaaS 개발자를 위한 멀티 에이전트 오케스트레이션 — 개발, 마케팅, 일정을 한 대화에서 통합 관리",
5
5
  "author": {
6
6
  "name": "Jaejin Song",
@@ -17,6 +17,7 @@
17
17
  "solo-developer"
18
18
  ],
19
19
  "agents": [
20
+ "./agents/pm.md",
20
21
  "./agents/planner.md",
21
22
  "./agents/dev.md",
22
23
  "./agents/qa.md",
package/README.md CHANGED
@@ -86,6 +86,16 @@ Claude Code에서:
86
86
  | **CodeReviewer** | 코드 리뷰 | dev |
87
87
  | **QA** | 실행 검증 | dev |
88
88
 
89
+ ## 모델 설정
90
+
91
+ `/crew-setup`에서 에이전트별 provider/model을 설정합니다. 설정하지 않은 에이전트는 `data/provider-catalog.json`의 `agent_defaults`를 따릅니다.
92
+
93
+ 기본값은 기존 에이전트 frontmatter 모델을 따르되, Dev와 CodeReviewer는 Codex `gpt-5.5 medium`을 사용합니다. Claude 모델은 `opus`, `sonnet`, `haiku` latest alias와 `claude-opus-4-7` 같은 버전 고정 ID를 모두 선택할 수 있습니다.
94
+
95
+ Claude provider는 Claude Code `Agent`로 실행하고, Codex provider는 플러그인에 내장된 `scripts/crew-codex-companion.mjs` app-server runtime으로 실행합니다. 에이전트가 유저 질문이나 다른 에이전트 호출이 필요하면 직접 처리하지 않고 오케스트레이터가 이어받아 실행합니다.
96
+
97
+ Provider와 무관하게 에이전트 결과는 `complete`, `blocked_on_user`, `needs_agent`, `needs_tool`, `failed` 상태 중 하나로 해석합니다. Claude Code 전용 도구가 필요한 경우에도 Codex provider는 요청 상태를 반환하고, 실제 도구 실행은 오케스트레이터가 담당합니다.
98
+
89
99
  ## 상태 파일
90
100
 
91
101
  프로젝트 로컬 `.crew/` 디렉토리에 마크다운 파일로 상태를 관리합니다 (git tracked). 플러그인 업데이트 시에도 학습 내용과 상태는 보존됩니다.
@@ -111,4 +121,4 @@ Claude Code에서:
111
121
 
112
122
  ## License
113
123
 
114
- MIT
124
+ MIT. This project also includes Apache-2.0 third-party components under `scripts/crew-codex/`; see `THIRD_PARTY_NOTICES.md`.
@@ -0,0 +1,14 @@
1
+ # Third-Party Notices
2
+
3
+ claude-crew includes vendored components derived from the OpenAI Codex plugin for Claude Code.
4
+
5
+ ## OpenAI Codex Plugin for Claude Code
6
+
7
+ - Source: `@openai/codex-plugin-cc`
8
+ - License: Apache License 2.0
9
+ - Vendored path: `scripts/crew-codex/` and `scripts/crew-codex-companion.mjs`
10
+
11
+ The vendored runtime has been modified for claude-crew integration, including path changes, command-surface reduction, state directory naming, and provider orchestration usage.
12
+
13
+ The Apache License 2.0 text is included at `scripts/crew-codex/LICENSE`.
14
+ The original NOTICE text is included at `scripts/crew-codex/NOTICE`.
@@ -1,26 +1,48 @@
1
1
  {
2
2
  "claude": {
3
3
  "models": [
4
- { "id": "opus", "label": "Opus — 최고 품질, 복잡한 구현", "default_for": ["dev", "code-reviewer"] },
5
- { "id": "sonnet", "label": "Sonnet — 빠르고 저렴, Opus급 성능", "default_for": ["qa"] },
6
- { "id": "haiku", "label": "Haiku — 최저 비용, 단순 태스크", "default_for": [] }
4
+ { "id": "opus", "status": "active" },
5
+ { "id": "claude-opus-4-7", "status": "active" },
6
+ { "id": "claude-opus-4-6", "status": "active" },
7
+ { "id": "sonnet", "status": "active" },
8
+ { "id": "claude-sonnet-4-6", "status": "active" },
9
+ { "id": "haiku", "status": "active" },
10
+ { "id": "claude-haiku-4-5", "status": "active" }
7
11
  ]
8
12
  },
9
13
  "codex": {
10
14
  "models": [
11
- { "id": "gpt-5.5", "reasoning": "high", "label": "GPT-5.5 high (추천) — 최고 성능, 균형잡힌 비용", "default_for": ["dev", "code-reviewer"] },
12
- { "id": "gpt-5.5", "reasoning": "xhigh", "label": "GPT-5.5 xhigh — 최대 추론, 토큰 多", "default_for": [] },
13
- { "id": "gpt-5.5", "reasoning": "medium", "label": "GPT-5.5 medium — 빠르고 저렴", "default_for": [] },
14
- { "id": "gpt-5.4", "reasoning": "high", "label": "GPT-5.4 high — 이전 세대, 안정적", "default_for": [] },
15
- { "id": "gpt-5.4", "reasoning": "xhigh", "label": "GPT-5.4 xhigh — 이전 세대, 최대 추론", "default_for": [] },
16
- { "id": "o3", "reasoning": "high", "label": "o3 high — 추론 특화", "default_for": [] },
17
- { "id": "o3", "reasoning": "medium", "label": "o3 medium — 추론 특화, 저비용", "default_for": [] },
18
- { "id": "gpt-5.5-mini", "reasoning": null, "label": "GPT-5.5 Mini — 최저 비용", "default_for": ["qa"] }
15
+ { "id": "gpt-5.5", "reasoning": "xhigh", "status": "active" },
16
+ { "id": "gpt-5.5", "reasoning": "high", "status": "active" },
17
+ { "id": "gpt-5.5", "reasoning": "medium", "status": "active" },
18
+ { "id": "gpt-5.4", "reasoning": "xhigh", "status": "active" },
19
+ { "id": "gpt-5.4", "reasoning": "high", "status": "active" },
20
+ { "id": "gpt-5.4", "reasoning": "medium", "status": "active" },
21
+ { "id": "o3", "reasoning": "high", "status": "active" },
22
+ { "id": "o3", "reasoning": "medium", "status": "active" },
23
+ { "id": "gpt-5.5-mini", "reasoning": "medium", "status": "active" }
19
24
  ]
20
25
  },
21
26
  "agent_defaults": {
22
- "dev": { "provider": "claude", "model": "opus" },
23
- "code-reviewer": { "provider": "claude", "model": "opus" },
24
- "qa": { "provider": "claude", "model": "sonnet" }
27
+ "pm": { "provider": "claude", "model": "opus" },
28
+ "techlead": { "provider": "claude", "model": "opus" },
29
+ "planner": { "provider": "claude", "model": "opus" },
30
+ "plan-evaluator": { "provider": "claude", "model": "sonnet" },
31
+ "explorer": { "provider": "claude", "model": "haiku" },
32
+ "researcher": { "provider": "claude", "model": "sonnet" },
33
+ "qa": { "provider": "claude", "model": "sonnet" },
34
+ "dev": { "provider": "codex", "model": "gpt-5.5", "reasoning": "medium" },
35
+ "code-reviewer": { "provider": "codex", "model": "gpt-5.5", "reasoning": "medium" }
36
+ },
37
+ "agent_runtime": {
38
+ "pm": { "codex_sandbox": "read-only" },
39
+ "techlead": { "codex_sandbox": "read-only" },
40
+ "planner": { "codex_sandbox": "read-only" },
41
+ "plan-evaluator": { "codex_sandbox": "read-only" },
42
+ "explorer": { "codex_sandbox": "read-only" },
43
+ "researcher": { "codex_sandbox": "read-only" },
44
+ "qa": { "codex_sandbox": "read-only" },
45
+ "dev": { "codex_sandbox": "workspace-write" },
46
+ "code-reviewer": { "codex_sandbox": "read-only" }
25
47
  }
26
48
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jjlabsio/claude-crew",
3
- "version": "0.1.31",
3
+ "version": "0.1.32",
4
4
  "description": "1인 SaaS 개발자를 위한 멀티 에이전트 오케스트레이션 — 개발, 마케팅, 일정을 한 대화에서 통합 관리",
5
5
  "author": "Jaejin Song <wowlxx28@gmail.com>",
6
6
  "license": "MIT",
@@ -23,6 +23,7 @@
23
23
  "hooks/",
24
24
  "hud/",
25
25
  "scripts/",
26
+ "THIRD_PARTY_NOTICES.md",
26
27
  "README.md",
27
28
  "LICENSE"
28
29
  ],
@@ -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.
@@ -0,0 +1,16 @@
1
+ Copyright 2026 OpenAI
2
+
3
+ Modified by claude-crew contributors in 2026 for embedded Codex app-server
4
+ runtime integration.
5
+
6
+ Licensed under the Apache License, Version 2.0 (the "License");
7
+ you may not use this file except in compliance with the License.
8
+ You may obtain a copy of the License at
9
+
10
+ http://www.apache.org/licenses/LICENSE-2.0
11
+
12
+ Unless required by applicable law or agreed to in writing, software
13
+ distributed under the License is distributed on an "AS IS" BASIS,
14
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ See the License for the specific language governing permissions and
16
+ limitations under the License.
@@ -0,0 +1,254 @@
1
+ #!/usr/bin/env node
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ // Derived from @openai/codex-plugin-cc and modified for claude-crew.
4
+
5
+ import fs from "node:fs";
6
+ import net from "node:net";
7
+ import path from "node:path";
8
+ import process from "node:process";
9
+
10
+ import { parseArgs } from "./lib/args.mjs";
11
+ import { BROKER_BUSY_RPC_CODE, CodexAppServerClient } from "./lib/app-server.mjs";
12
+ import { parseBrokerEndpoint } from "./lib/broker-endpoint.mjs";
13
+
14
+ const STREAMING_METHODS = new Set(["turn/start", "review/start", "thread/compact/start"]);
15
+
16
+ function buildStreamThreadIds(method, params, result) {
17
+ const threadIds = new Set();
18
+ if (params?.threadId) {
19
+ threadIds.add(params.threadId);
20
+ }
21
+ if (method === "review/start" && result?.reviewThreadId) {
22
+ threadIds.add(result.reviewThreadId);
23
+ }
24
+ return threadIds;
25
+ }
26
+
27
+ function buildJsonRpcError(code, message, data) {
28
+ return data === undefined ? { code, message } : { code, message, data };
29
+ }
30
+
31
+ function send(socket, message) {
32
+ if (socket.destroyed) {
33
+ return;
34
+ }
35
+ socket.write(`${JSON.stringify(message)}\n`);
36
+ }
37
+
38
+ function isInterruptRequest(message) {
39
+ return message?.method === "turn/interrupt";
40
+ }
41
+
42
+ function writePidFile(pidFile) {
43
+ if (!pidFile) {
44
+ return;
45
+ }
46
+ fs.mkdirSync(path.dirname(pidFile), { recursive: true });
47
+ fs.writeFileSync(pidFile, `${process.pid}\n`, "utf8");
48
+ }
49
+
50
+ async function main() {
51
+ const [subcommand, ...argv] = process.argv.slice(2);
52
+ if (subcommand !== "serve") {
53
+ throw new Error("Usage: node scripts/app-server-broker.mjs serve --endpoint <value> [--cwd <path>] [--pid-file <path>]");
54
+ }
55
+
56
+ const { options } = parseArgs(argv, {
57
+ valueOptions: ["cwd", "pid-file", "endpoint"]
58
+ });
59
+
60
+ if (!options.endpoint) {
61
+ throw new Error("Missing required --endpoint.");
62
+ }
63
+
64
+ const cwd = options.cwd ? path.resolve(process.cwd(), options.cwd) : process.cwd();
65
+ const endpoint = String(options.endpoint);
66
+ const listenTarget = parseBrokerEndpoint(endpoint);
67
+ const pidFile = options["pid-file"] ? path.resolve(options["pid-file"]) : null;
68
+ writePidFile(pidFile);
69
+
70
+ const appClient = await CodexAppServerClient.connect(cwd, { disableBroker: true });
71
+ let activeRequestSocket = null;
72
+ let activeStreamSocket = null;
73
+ let activeStreamThreadIds = null;
74
+ const sockets = new Set();
75
+
76
+ function clearSocketOwnership(socket) {
77
+ if (activeRequestSocket === socket) {
78
+ activeRequestSocket = null;
79
+ }
80
+ if (activeStreamSocket === socket) {
81
+ activeStreamSocket = null;
82
+ activeStreamThreadIds = null;
83
+ }
84
+ }
85
+
86
+ function routeNotification(message) {
87
+ const target = activeRequestSocket ?? activeStreamSocket;
88
+ if (!target) {
89
+ return;
90
+ }
91
+ send(target, message);
92
+ if (message.method === "turn/completed" && activeStreamSocket === target) {
93
+ const threadId = message.params?.threadId ?? null;
94
+ if (!threadId || !activeStreamThreadIds || activeStreamThreadIds.has(threadId)) {
95
+ activeStreamSocket = null;
96
+ activeStreamThreadIds = null;
97
+ if (activeRequestSocket === target) {
98
+ activeRequestSocket = null;
99
+ }
100
+ }
101
+ }
102
+ }
103
+
104
+ async function shutdown(server) {
105
+ for (const socket of sockets) {
106
+ socket.end();
107
+ }
108
+ await appClient.close().catch(() => {});
109
+ await new Promise((resolve) => server.close(resolve));
110
+ if (listenTarget.kind === "unix" && fs.existsSync(listenTarget.path)) {
111
+ fs.unlinkSync(listenTarget.path);
112
+ }
113
+ if (pidFile && fs.existsSync(pidFile)) {
114
+ fs.unlinkSync(pidFile);
115
+ }
116
+ }
117
+
118
+ appClient.setNotificationHandler(routeNotification);
119
+
120
+ const server = net.createServer((socket) => {
121
+ sockets.add(socket);
122
+ socket.setEncoding("utf8");
123
+ let buffer = "";
124
+
125
+ socket.on("data", async (chunk) => {
126
+ buffer += chunk;
127
+ let newlineIndex = buffer.indexOf("\n");
128
+ while (newlineIndex !== -1) {
129
+ const line = buffer.slice(0, newlineIndex);
130
+ buffer = buffer.slice(newlineIndex + 1);
131
+ newlineIndex = buffer.indexOf("\n");
132
+
133
+ if (!line.trim()) {
134
+ continue;
135
+ }
136
+
137
+ let message;
138
+ try {
139
+ message = JSON.parse(line);
140
+ } catch (error) {
141
+ send(socket, {
142
+ id: null,
143
+ error: buildJsonRpcError(-32700, `Invalid JSON: ${error.message}`)
144
+ });
145
+ continue;
146
+ }
147
+
148
+ if (message.id !== undefined && message.method === "initialize") {
149
+ send(socket, {
150
+ id: message.id,
151
+ result: {
152
+ userAgent: "claude-crew-codex-broker"
153
+ }
154
+ });
155
+ continue;
156
+ }
157
+
158
+ if (message.method === "initialized" && message.id === undefined) {
159
+ continue;
160
+ }
161
+
162
+ if (message.id !== undefined && message.method === "broker/shutdown") {
163
+ send(socket, { id: message.id, result: {} });
164
+ await shutdown(server);
165
+ process.exit(0);
166
+ }
167
+
168
+ if (message.id === undefined) {
169
+ continue;
170
+ }
171
+
172
+ const allowInterruptDuringActiveStream =
173
+ isInterruptRequest(message) && activeStreamSocket && activeStreamSocket !== socket && !activeRequestSocket;
174
+
175
+ if (
176
+ ((activeRequestSocket && activeRequestSocket !== socket) || (activeStreamSocket && activeStreamSocket !== socket)) &&
177
+ !allowInterruptDuringActiveStream
178
+ ) {
179
+ send(socket, {
180
+ id: message.id,
181
+ error: buildJsonRpcError(BROKER_BUSY_RPC_CODE, "Shared Codex broker is busy.")
182
+ });
183
+ continue;
184
+ }
185
+
186
+ if (allowInterruptDuringActiveStream) {
187
+ try {
188
+ const result = await appClient.request(message.method, message.params ?? {});
189
+ send(socket, { id: message.id, result });
190
+ } catch (error) {
191
+ send(socket, {
192
+ id: message.id,
193
+ error: buildJsonRpcError(error.rpcCode ?? -32000, error.message)
194
+ });
195
+ }
196
+ continue;
197
+ }
198
+
199
+ const isStreaming = STREAMING_METHODS.has(message.method);
200
+ activeRequestSocket = socket;
201
+
202
+ try {
203
+ const result = await appClient.request(message.method, message.params ?? {});
204
+ send(socket, { id: message.id, result });
205
+ if (isStreaming) {
206
+ activeStreamSocket = socket;
207
+ activeStreamThreadIds = buildStreamThreadIds(message.method, message.params ?? {}, result);
208
+ }
209
+ if (activeRequestSocket === socket) {
210
+ activeRequestSocket = null;
211
+ }
212
+ } catch (error) {
213
+ send(socket, {
214
+ id: message.id,
215
+ error: buildJsonRpcError(error.rpcCode ?? -32000, error.message)
216
+ });
217
+ if (activeRequestSocket === socket) {
218
+ activeRequestSocket = null;
219
+ }
220
+ if (activeStreamSocket === socket && !isStreaming) {
221
+ activeStreamSocket = null;
222
+ }
223
+ }
224
+ }
225
+ });
226
+
227
+ socket.on("close", () => {
228
+ sockets.delete(socket);
229
+ clearSocketOwnership(socket);
230
+ });
231
+
232
+ socket.on("error", () => {
233
+ sockets.delete(socket);
234
+ clearSocketOwnership(socket);
235
+ });
236
+ });
237
+
238
+ process.on("SIGTERM", async () => {
239
+ await shutdown(server);
240
+ process.exit(0);
241
+ });
242
+
243
+ process.on("SIGINT", async () => {
244
+ await shutdown(server);
245
+ process.exit(0);
246
+ });
247
+
248
+ server.listen(listenTarget.path);
249
+ }
250
+
251
+ main().catch((error) => {
252
+ process.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
253
+ process.exit(1);
254
+ });