codex-rule-maker 0.1.0__tar.gz

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,287 @@
1
+ Metadata-Version: 2.4
2
+ Name: codex-rule-maker
3
+ Version: 0.1.0
4
+ Summary: CLI tool that generates a .codex folder with AI developer rules and project reference documents.
5
+ Author: codex-rule-maker
6
+ Project-URL: Homepage, https://github.com/Sharon77770/codex_rule_maker
7
+ Project-URL: Repository, https://github.com/Sharon77770/codex_rule_maker
8
+ Project-URL: Issues, https://github.com/Sharon77770/codex_rule_maker/issues
9
+ Keywords: codex,cli,project-template,developer-rules,documentation
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Environment :: Console
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.9
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Topic :: Software Development :: Code Generators
21
+ Classifier: Topic :: Software Development :: Documentation
22
+ Requires-Python: >=3.9
23
+ Description-Content-Type: text/markdown
24
+ Provides-Extra: dev
25
+ Requires-Dist: build<2,>=1; extra == "dev"
26
+ Requires-Dist: pytest<9,>=7; extra == "dev"
27
+ Requires-Dist: twine<7,>=5; extra == "dev"
28
+
29
+ # codex-rule-maker
30
+
31
+ `codex-rule-maker`는 프로젝트 루트에 `.codex` 폴더를 자동 구성하는 Python CLI 도구입니다. 사용자가 프로젝트 이름, 설명, 스택, DB, 인증 여부, 외부 API 여부, 문서화 수준, 문서 언어를 입력하면 Codex가 작업 전에 읽을 개발 규칙과 프로젝트 참고 문서 템플릿을 생성합니다.
32
+
33
+ 이 도구는 `output_ex/.codex` 예시의 철학을 참고했습니다. 예시를 그대로 복사하지 않고, 규칙 문서와 참고 문서를 분리한 범용 템플릿으로 일반화했습니다.
34
+
35
+ ## 설치
36
+
37
+ 요구 Python 버전은 3.9 이상입니다.
38
+
39
+ 개발 환경에서 바로 실행:
40
+
41
+ ```bash
42
+ python -m codex_builder.cli --help
43
+ ```
44
+
45
+ 패키지 명령으로 설치:
46
+
47
+ ```bash
48
+ pip install -e .
49
+ codex-init --help
50
+ ```
51
+
52
+ PyPI 배포 후에는 다음 명령으로 설치할 수 있습니다.
53
+
54
+ ```bash
55
+ pip install codex-rule-maker
56
+ codex-init --help
57
+ ```
58
+
59
+ ## PyPI 배포
60
+
61
+ 배포 전 패키지를 빌드하고 검사합니다.
62
+
63
+ ```bash
64
+ pip install -e ".[dev]"
65
+ python -m build
66
+ python -m twine check dist/*
67
+ ```
68
+
69
+ PyPI API token을 발급한 뒤 업로드합니다.
70
+
71
+ ```bash
72
+ python -m twine upload dist/*
73
+ ```
74
+
75
+ 테스트 PyPI에 먼저 올리고 싶다면 다음 명령을 사용합니다.
76
+
77
+ ```bash
78
+ python -m twine upload --repository testpypi dist/*
79
+ ```
80
+
81
+ 업로드가 끝나면 새 환경에서 설치를 확인합니다.
82
+
83
+ ```bash
84
+ pip install codex-rule-maker
85
+ codex-init --help
86
+ ```
87
+
88
+ ## 기본 대화형 실행
89
+
90
+ 옵션 없이 실행하면 필요한 값을 순서대로 질문합니다.
91
+
92
+ ```bash
93
+ codex-init
94
+ ```
95
+
96
+ 입력받는 항목:
97
+
98
+ - 프로젝트 이름
99
+ - 프로젝트 설명
100
+ - 사용 스택
101
+ - DB 사용 여부 및 DB 종류
102
+ - 인증 사용 여부
103
+ - 외부 API 연동 여부
104
+ - 문서화 수준
105
+ - 문서 언어
106
+ - 대상 디렉토리
107
+ - 기존 `.codex`가 있을 때 처리 방식
108
+ - 생성 전 최종 확인
109
+
110
+ `--interactive`도 같은 대화형 흐름을 사용합니다. 옵션 값을 일부 같이 넘기면 해당 값은 다시 묻지 않고, 누락된 값만 질문합니다. `--interactive`에서는 최종 확인 화면을 반드시 보여줍니다.
111
+
112
+ ```bash
113
+ codex-init --interactive
114
+ codex-init --interactive --name pfm-lab --stack fastapi,react
115
+ ```
116
+
117
+ ## 옵션 기반 실행
118
+
119
+ 필수 옵션을 모두 주면 누락 값 질문 없이 기본값을 사용합니다. 일반 터미널에서는 생성 전 최종 확인만 거치며, 파이프/테스트 같은 비대화형 실행에서는 자동화가 멈추지 않도록 바로 생성합니다.
120
+
121
+ ```bash
122
+ codex-init --name pfm-lab --stack fastapi --db mysql --auth yes --external-api yes --docs strict
123
+ ```
124
+
125
+ 모듈 실행 방식도 동일하게 동작합니다.
126
+
127
+ ```bash
128
+ python -m codex_builder.cli --name sample-api --stack fastapi --db mysql --auth yes --external-api yes --docs strict
129
+ ```
130
+
131
+ 부분 옵션만 주면 누락된 값은 prompt로 보완합니다.
132
+
133
+ ```bash
134
+ codex-init --name sample-api
135
+ ```
136
+
137
+ 입력 우선순위는 `CLI 옵션 입력값 > prompt 입력값 > 기본값`입니다.
138
+
139
+ ## 기존 .codex 충돌 처리
140
+
141
+ 기존 `.codex`가 있고 `--force`가 없으면 다음 선택지를 보여줍니다.
142
+
143
+ ```text
144
+ 기존 .codex 폴더가 존재합니다.
145
+ 1. 중단
146
+ 2. 백업 후 재생성
147
+ 3. 삭제 후 재생성
148
+ ```
149
+
150
+ - `중단`: 아무것도 변경하지 않고 종료
151
+ - `백업 후 재생성`: 기존 `.codex`를 `.codex_backup_YYYYMMDD_HHMMSS`로 이동 후 새로 생성
152
+ - `삭제 후 재생성`: 기존 `.codex`를 삭제 후 새로 생성
153
+
154
+ 옵션으로 동작을 고정할 수도 있습니다.
155
+
156
+ ```bash
157
+ codex-init --force
158
+ ```
159
+
160
+ `--force`만 사용하면 기존 `.codex`를 백업 후 재생성합니다.
161
+
162
+ ```bash
163
+ codex-init --force --overwrite
164
+ ```
165
+
166
+ `--force --overwrite`를 함께 사용하면 기존 `.codex`를 삭제 후 재생성합니다.
167
+
168
+ ## 예시 실행 흐름
169
+
170
+ ```text
171
+ 프로젝트 이름 [sample]: pfm-lab
172
+ 프로젝트 설명: 자연어 기반 PFM 시뮬레이션 플랫폼
173
+ 지원 프로필:
174
+ - fastapi
175
+ - springboot
176
+ - react
177
+ - nextjs
178
+ - node-express
179
+ - fullstack-fastapi-react
180
+ 사용 스택 [fastapi]: fastapi,react
181
+ DB를 사용하나요? [y/N]: y
182
+ DB 종류 [mysql]: mysql
183
+ 인증 기능을 사용하나요? [y/N]: y
184
+ 외부 API 연동이 있나요? [y/N]: y
185
+ 문서화 수준 (light/standard/strict) [standard]: strict
186
+ 문서 언어 (ko/en) [ko]: ko
187
+ 대상 디렉토리 [C:\Users\User\Documents\GitHub\sample]:
188
+
189
+ 생성 설정 확인
190
+
191
+ 프로젝트 이름: pfm-lab
192
+ 설명: 자연어 기반 PFM 시뮬레이션 플랫폼
193
+ 스택: fastapi,react
194
+ DB: mysql
195
+ 인증: yes
196
+ 외부 API: yes
197
+ 문서화 수준: strict
198
+ 언어: ko
199
+ 대상 디렉토리: C:\Users\User\Documents\GitHub\sample
200
+
201
+ 이 설정으로 .codex를 생성할까요? [Y/n]: y
202
+ ```
203
+
204
+ ## CLI 옵션
205
+
206
+ | 옵션 | 설명 | 기본값 |
207
+ | --- | --- | --- |
208
+ | `--name` | 프로젝트 이름 | 현재 디렉토리 이름 |
209
+ | `--description` | 프로젝트 설명 | 빈 값 |
210
+ | `--stack` | comma-separated framework profile | `fastapi` |
211
+ | `--db`, `--database` | DB 종류 | 미지정 |
212
+ | `--auth` | 인증 사용 여부: `yes` 또는 `no` | `no` |
213
+ | `--external-api` | 외부 API 사용 여부: `yes` 또는 `no` | `no` |
214
+ | `--docs` | 문서화 수준: `light`, `standard`, `strict` | `standard` |
215
+ | `--language` | 문서 언어: `ko`, `en` | `ko` |
216
+ | `--interactive` | 대화형 입력 사용 및 최종 확인 표시 | 비활성 |
217
+ | `--force` | 기존 `.codex`가 있으면 백업 후 재생성 | 비활성 |
218
+ | `--overwrite` | `--force`와 함께 기존 `.codex` 삭제 후 재생성 | 비활성 |
219
+ | `--target-dir` | `.codex`를 생성할 대상 디렉토리 | 현재 디렉토리 |
220
+
221
+ ## 생성 구조
222
+
223
+ ```text
224
+ .codex/
225
+ ├── AI_RULE_DEVELOPER/
226
+ │ ├── GLOBAL_RULES.md
227
+ │ ├── ARCHITECTURE_RULES.md
228
+ │ ├── CODE_STYLE_RULES.md
229
+ │ ├── API_DESIGN_RULES.md
230
+ │ ├── DOCUMENT_RULE.md
231
+ │ ├── TEST_RULES.md
232
+ │ └── FRAMEWORK_RULES.md
233
+ ├── REF_DOCS/
234
+ │ ├── PROJECT_OVERVIEW.md
235
+ │ ├── FEATURE_SPEC.md
236
+ │ ├── API_SPEC.md
237
+ │ └── DB_SPEC.md
238
+ └── codex_start_prompt.txt
239
+ ```
240
+
241
+ `AI_RULE_DEVELOPER`는 코딩할 때 지켜야 하는 규칙입니다. `REF_DOCS`는 개발 시 참고할 프로젝트 명세입니다. `codex_start_prompt.txt`는 Codex가 작업 시작 전에 `.codex` 문서를 먼저 읽고 규칙 우선순위를 적용하도록 지시합니다.
242
+
243
+ ## 지원 프레임워크 프로필
244
+
245
+ - `fastapi`: controller/service/repository/schema/entity 계층 분리
246
+ - `springboot`: controller/service/repository/entity/dto 계층 분리
247
+ - `react`: component/page/hook/service/store 분리
248
+ - `nextjs`: App Router, Server Component와 Client Component 구분
249
+ - `node-express`: route/controller/service/repository 분리
250
+ - `fullstack-fastapi-react`: FastAPI 백엔드와 React 프론트엔드 규칙 동시 적용
251
+
252
+ 여러 프로필은 comma로 조합할 수 있습니다.
253
+
254
+ ```bash
255
+ codex-init --stack fastapi,react
256
+ codex-init --stack fullstack-fastapi-react
257
+ codex-init --stack nextjs
258
+ ```
259
+
260
+ ## 문서 생성 규칙
261
+
262
+ - 기본 문서 언어는 한국어입니다.
263
+ - `--language en`을 사용하면 영어 문서를 생성합니다.
264
+ - `--docs strict`는 코드 변경 후 문서 업데이트 필수 규칙을 포함합니다.
265
+ - `--auth yes`는 인증/권한 규칙을 포함합니다.
266
+ - `--external-api yes`는 외부 연동 계층 분리 규칙을 포함합니다.
267
+ - `--db mysql`처럼 DB를 지정하면 DB, Repository, Schema 관련 규칙을 포함합니다.
268
+
269
+ ## 테스트
270
+
271
+ ```bash
272
+ pip install -e ".[dev]"
273
+ pytest
274
+ ```
275
+
276
+ 검증 범위:
277
+
278
+ - 기본 생성 성공
279
+ - 옵션만으로 생성 가능
280
+ - 누락 값 prompt 보완
281
+ - 잘못된 stack/docs/language 검증
282
+ - FastAPI 프로필 생성
283
+ - React 프로필 생성
284
+ - Fullstack FastAPI React 프로필 생성
285
+ - 기존 `.codex`가 있을 때 prompt 중단
286
+ - `--force`가 있으면 기존 `.codex` 백업 후 재생성
287
+ - `--force --overwrite`가 있으면 기존 `.codex` 삭제 후 재생성
@@ -0,0 +1,259 @@
1
+ # codex-rule-maker
2
+
3
+ `codex-rule-maker`는 프로젝트 루트에 `.codex` 폴더를 자동 구성하는 Python CLI 도구입니다. 사용자가 프로젝트 이름, 설명, 스택, DB, 인증 여부, 외부 API 여부, 문서화 수준, 문서 언어를 입력하면 Codex가 작업 전에 읽을 개발 규칙과 프로젝트 참고 문서 템플릿을 생성합니다.
4
+
5
+ 이 도구는 `output_ex/.codex` 예시의 철학을 참고했습니다. 예시를 그대로 복사하지 않고, 규칙 문서와 참고 문서를 분리한 범용 템플릿으로 일반화했습니다.
6
+
7
+ ## 설치
8
+
9
+ 요구 Python 버전은 3.9 이상입니다.
10
+
11
+ 개발 환경에서 바로 실행:
12
+
13
+ ```bash
14
+ python -m codex_builder.cli --help
15
+ ```
16
+
17
+ 패키지 명령으로 설치:
18
+
19
+ ```bash
20
+ pip install -e .
21
+ codex-init --help
22
+ ```
23
+
24
+ PyPI 배포 후에는 다음 명령으로 설치할 수 있습니다.
25
+
26
+ ```bash
27
+ pip install codex-rule-maker
28
+ codex-init --help
29
+ ```
30
+
31
+ ## PyPI 배포
32
+
33
+ 배포 전 패키지를 빌드하고 검사합니다.
34
+
35
+ ```bash
36
+ pip install -e ".[dev]"
37
+ python -m build
38
+ python -m twine check dist/*
39
+ ```
40
+
41
+ PyPI API token을 발급한 뒤 업로드합니다.
42
+
43
+ ```bash
44
+ python -m twine upload dist/*
45
+ ```
46
+
47
+ 테스트 PyPI에 먼저 올리고 싶다면 다음 명령을 사용합니다.
48
+
49
+ ```bash
50
+ python -m twine upload --repository testpypi dist/*
51
+ ```
52
+
53
+ 업로드가 끝나면 새 환경에서 설치를 확인합니다.
54
+
55
+ ```bash
56
+ pip install codex-rule-maker
57
+ codex-init --help
58
+ ```
59
+
60
+ ## 기본 대화형 실행
61
+
62
+ 옵션 없이 실행하면 필요한 값을 순서대로 질문합니다.
63
+
64
+ ```bash
65
+ codex-init
66
+ ```
67
+
68
+ 입력받는 항목:
69
+
70
+ - 프로젝트 이름
71
+ - 프로젝트 설명
72
+ - 사용 스택
73
+ - DB 사용 여부 및 DB 종류
74
+ - 인증 사용 여부
75
+ - 외부 API 연동 여부
76
+ - 문서화 수준
77
+ - 문서 언어
78
+ - 대상 디렉토리
79
+ - 기존 `.codex`가 있을 때 처리 방식
80
+ - 생성 전 최종 확인
81
+
82
+ `--interactive`도 같은 대화형 흐름을 사용합니다. 옵션 값을 일부 같이 넘기면 해당 값은 다시 묻지 않고, 누락된 값만 질문합니다. `--interactive`에서는 최종 확인 화면을 반드시 보여줍니다.
83
+
84
+ ```bash
85
+ codex-init --interactive
86
+ codex-init --interactive --name pfm-lab --stack fastapi,react
87
+ ```
88
+
89
+ ## 옵션 기반 실행
90
+
91
+ 필수 옵션을 모두 주면 누락 값 질문 없이 기본값을 사용합니다. 일반 터미널에서는 생성 전 최종 확인만 거치며, 파이프/테스트 같은 비대화형 실행에서는 자동화가 멈추지 않도록 바로 생성합니다.
92
+
93
+ ```bash
94
+ codex-init --name pfm-lab --stack fastapi --db mysql --auth yes --external-api yes --docs strict
95
+ ```
96
+
97
+ 모듈 실행 방식도 동일하게 동작합니다.
98
+
99
+ ```bash
100
+ python -m codex_builder.cli --name sample-api --stack fastapi --db mysql --auth yes --external-api yes --docs strict
101
+ ```
102
+
103
+ 부분 옵션만 주면 누락된 값은 prompt로 보완합니다.
104
+
105
+ ```bash
106
+ codex-init --name sample-api
107
+ ```
108
+
109
+ 입력 우선순위는 `CLI 옵션 입력값 > prompt 입력값 > 기본값`입니다.
110
+
111
+ ## 기존 .codex 충돌 처리
112
+
113
+ 기존 `.codex`가 있고 `--force`가 없으면 다음 선택지를 보여줍니다.
114
+
115
+ ```text
116
+ 기존 .codex 폴더가 존재합니다.
117
+ 1. 중단
118
+ 2. 백업 후 재생성
119
+ 3. 삭제 후 재생성
120
+ ```
121
+
122
+ - `중단`: 아무것도 변경하지 않고 종료
123
+ - `백업 후 재생성`: 기존 `.codex`를 `.codex_backup_YYYYMMDD_HHMMSS`로 이동 후 새로 생성
124
+ - `삭제 후 재생성`: 기존 `.codex`를 삭제 후 새로 생성
125
+
126
+ 옵션으로 동작을 고정할 수도 있습니다.
127
+
128
+ ```bash
129
+ codex-init --force
130
+ ```
131
+
132
+ `--force`만 사용하면 기존 `.codex`를 백업 후 재생성합니다.
133
+
134
+ ```bash
135
+ codex-init --force --overwrite
136
+ ```
137
+
138
+ `--force --overwrite`를 함께 사용하면 기존 `.codex`를 삭제 후 재생성합니다.
139
+
140
+ ## 예시 실행 흐름
141
+
142
+ ```text
143
+ 프로젝트 이름 [sample]: pfm-lab
144
+ 프로젝트 설명: 자연어 기반 PFM 시뮬레이션 플랫폼
145
+ 지원 프로필:
146
+ - fastapi
147
+ - springboot
148
+ - react
149
+ - nextjs
150
+ - node-express
151
+ - fullstack-fastapi-react
152
+ 사용 스택 [fastapi]: fastapi,react
153
+ DB를 사용하나요? [y/N]: y
154
+ DB 종류 [mysql]: mysql
155
+ 인증 기능을 사용하나요? [y/N]: y
156
+ 외부 API 연동이 있나요? [y/N]: y
157
+ 문서화 수준 (light/standard/strict) [standard]: strict
158
+ 문서 언어 (ko/en) [ko]: ko
159
+ 대상 디렉토리 [C:\Users\User\Documents\GitHub\sample]:
160
+
161
+ 생성 설정 확인
162
+
163
+ 프로젝트 이름: pfm-lab
164
+ 설명: 자연어 기반 PFM 시뮬레이션 플랫폼
165
+ 스택: fastapi,react
166
+ DB: mysql
167
+ 인증: yes
168
+ 외부 API: yes
169
+ 문서화 수준: strict
170
+ 언어: ko
171
+ 대상 디렉토리: C:\Users\User\Documents\GitHub\sample
172
+
173
+ 이 설정으로 .codex를 생성할까요? [Y/n]: y
174
+ ```
175
+
176
+ ## CLI 옵션
177
+
178
+ | 옵션 | 설명 | 기본값 |
179
+ | --- | --- | --- |
180
+ | `--name` | 프로젝트 이름 | 현재 디렉토리 이름 |
181
+ | `--description` | 프로젝트 설명 | 빈 값 |
182
+ | `--stack` | comma-separated framework profile | `fastapi` |
183
+ | `--db`, `--database` | DB 종류 | 미지정 |
184
+ | `--auth` | 인증 사용 여부: `yes` 또는 `no` | `no` |
185
+ | `--external-api` | 외부 API 사용 여부: `yes` 또는 `no` | `no` |
186
+ | `--docs` | 문서화 수준: `light`, `standard`, `strict` | `standard` |
187
+ | `--language` | 문서 언어: `ko`, `en` | `ko` |
188
+ | `--interactive` | 대화형 입력 사용 및 최종 확인 표시 | 비활성 |
189
+ | `--force` | 기존 `.codex`가 있으면 백업 후 재생성 | 비활성 |
190
+ | `--overwrite` | `--force`와 함께 기존 `.codex` 삭제 후 재생성 | 비활성 |
191
+ | `--target-dir` | `.codex`를 생성할 대상 디렉토리 | 현재 디렉토리 |
192
+
193
+ ## 생성 구조
194
+
195
+ ```text
196
+ .codex/
197
+ ├── AI_RULE_DEVELOPER/
198
+ │ ├── GLOBAL_RULES.md
199
+ │ ├── ARCHITECTURE_RULES.md
200
+ │ ├── CODE_STYLE_RULES.md
201
+ │ ├── API_DESIGN_RULES.md
202
+ │ ├── DOCUMENT_RULE.md
203
+ │ ├── TEST_RULES.md
204
+ │ └── FRAMEWORK_RULES.md
205
+ ├── REF_DOCS/
206
+ │ ├── PROJECT_OVERVIEW.md
207
+ │ ├── FEATURE_SPEC.md
208
+ │ ├── API_SPEC.md
209
+ │ └── DB_SPEC.md
210
+ └── codex_start_prompt.txt
211
+ ```
212
+
213
+ `AI_RULE_DEVELOPER`는 코딩할 때 지켜야 하는 규칙입니다. `REF_DOCS`는 개발 시 참고할 프로젝트 명세입니다. `codex_start_prompt.txt`는 Codex가 작업 시작 전에 `.codex` 문서를 먼저 읽고 규칙 우선순위를 적용하도록 지시합니다.
214
+
215
+ ## 지원 프레임워크 프로필
216
+
217
+ - `fastapi`: controller/service/repository/schema/entity 계층 분리
218
+ - `springboot`: controller/service/repository/entity/dto 계층 분리
219
+ - `react`: component/page/hook/service/store 분리
220
+ - `nextjs`: App Router, Server Component와 Client Component 구분
221
+ - `node-express`: route/controller/service/repository 분리
222
+ - `fullstack-fastapi-react`: FastAPI 백엔드와 React 프론트엔드 규칙 동시 적용
223
+
224
+ 여러 프로필은 comma로 조합할 수 있습니다.
225
+
226
+ ```bash
227
+ codex-init --stack fastapi,react
228
+ codex-init --stack fullstack-fastapi-react
229
+ codex-init --stack nextjs
230
+ ```
231
+
232
+ ## 문서 생성 규칙
233
+
234
+ - 기본 문서 언어는 한국어입니다.
235
+ - `--language en`을 사용하면 영어 문서를 생성합니다.
236
+ - `--docs strict`는 코드 변경 후 문서 업데이트 필수 규칙을 포함합니다.
237
+ - `--auth yes`는 인증/권한 규칙을 포함합니다.
238
+ - `--external-api yes`는 외부 연동 계층 분리 규칙을 포함합니다.
239
+ - `--db mysql`처럼 DB를 지정하면 DB, Repository, Schema 관련 규칙을 포함합니다.
240
+
241
+ ## 테스트
242
+
243
+ ```bash
244
+ pip install -e ".[dev]"
245
+ pytest
246
+ ```
247
+
248
+ 검증 범위:
249
+
250
+ - 기본 생성 성공
251
+ - 옵션만으로 생성 가능
252
+ - 누락 값 prompt 보완
253
+ - 잘못된 stack/docs/language 검증
254
+ - FastAPI 프로필 생성
255
+ - React 프로필 생성
256
+ - Fullstack FastAPI React 프로필 생성
257
+ - 기존 `.codex`가 있을 때 prompt 중단
258
+ - `--force`가 있으면 기존 `.codex` 백업 후 재생성
259
+ - `--force --overwrite`가 있으면 기존 `.codex` 삭제 후 재생성
@@ -0,0 +1,6 @@
1
+ """Codex folder builder package."""
2
+
3
+ from codex_builder.builder import CodexBuilder
4
+ from codex_builder.models import BuildResult, ProjectConfig
5
+
6
+ __all__ = ["BuildResult", "CodexBuilder", "ProjectConfig"]
@@ -0,0 +1,91 @@
1
+ """Filesystem builder for generated .codex folders."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import shutil
6
+ from datetime import datetime
7
+ from pathlib import Path
8
+ from typing import Optional, Union
9
+
10
+ from codex_builder.constants import CODEX_DIR_NAME
11
+ from codex_builder.models import BuildResult, ProjectConfig
12
+ from codex_builder.template_renderer import TemplateRenderer
13
+
14
+
15
+ class ExistingCodexError(FileExistsError):
16
+ """Raised when .codex already exists and force is not enabled."""
17
+
18
+
19
+ class CodexBuildError(RuntimeError):
20
+ """Raised when the builder cannot write the generated files."""
21
+
22
+
23
+ class CodexBuilder:
24
+ """Create a .codex directory from a ProjectConfig."""
25
+
26
+ def __init__(self, renderer: Optional[TemplateRenderer] = None) -> None:
27
+ self._renderer = renderer or TemplateRenderer()
28
+
29
+ def build(
30
+ self,
31
+ config: ProjectConfig,
32
+ *,
33
+ target_dir: Optional[Union[Path, str]] = None,
34
+ force: bool = False,
35
+ backup_existing: bool = True,
36
+ ) -> BuildResult:
37
+ root = Path(target_dir or Path.cwd()).resolve()
38
+ codex_dir = root / CODEX_DIR_NAME
39
+
40
+ if codex_dir.exists() and not force:
41
+ raise ExistingCodexError(f"{codex_dir} already exists. Re-run with --force to replace it.")
42
+
43
+ rendered_files = self._renderer.render(config)
44
+
45
+ backup_dir: Optional[Path] = None
46
+ if codex_dir.exists():
47
+ backup_dir = self._replace_existing_codex(codex_dir, backup_existing=backup_existing)
48
+
49
+ try:
50
+ written_files: list[Path] = []
51
+ for relative_path, content in rendered_files.items():
52
+ destination = root / relative_path
53
+ destination.parent.mkdir(parents=True, exist_ok=True)
54
+ destination.write_text(content.rstrip() + "\n", encoding="utf-8")
55
+ written_files.append(destination)
56
+ except OSError as exc:
57
+ raise CodexBuildError(f"failed to write .codex files: {exc}") from exc
58
+
59
+ return BuildResult(
60
+ codex_dir=codex_dir,
61
+ written_files=tuple(written_files),
62
+ backup_dir=backup_dir,
63
+ )
64
+
65
+ def _replace_existing_codex(self, codex_dir: Path, *, backup_existing: bool) -> Optional[Path]:
66
+ if backup_existing:
67
+ backup_dir = self._next_backup_path(codex_dir)
68
+ try:
69
+ codex_dir.rename(backup_dir)
70
+ except OSError as exc:
71
+ raise CodexBuildError(f"failed to backup existing .codex folder: {exc}") from exc
72
+ return backup_dir
73
+
74
+ try:
75
+ if codex_dir.is_dir():
76
+ shutil.rmtree(codex_dir)
77
+ else:
78
+ codex_dir.unlink()
79
+ except OSError as exc:
80
+ raise CodexBuildError(f"failed to remove existing .codex path: {exc}") from exc
81
+ return None
82
+
83
+ def _next_backup_path(self, codex_dir: Path) -> Path:
84
+ timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
85
+ base_backup = codex_dir.with_name(f"{CODEX_DIR_NAME}_backup_{timestamp}")
86
+ candidate = base_backup
87
+ index = 1
88
+ while candidate.exists():
89
+ candidate = codex_dir.with_name(f"{base_backup.name}.{index}")
90
+ index += 1
91
+ return candidate