@odyssey365/cli 0.0.0-stage → 0.2.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.
- package/LICENSE +21 -0
- package/README.md +296 -2
- package/dist/args.js +348 -0
- package/dist/config.js +124 -0
- package/dist/files.js +58 -0
- package/dist/guide.js +113 -0
- package/dist/index.js +502 -0
- package/dist/oauth.js +258 -0
- package/dist/output.js +84 -0
- package/dist/rpc.js +176 -0
- package/dist/session.js +247 -0
- package/dist/tools.js +159 -0
- package/dist/watch-agent.js +45 -0
- package/dist/watch-events.js +78 -0
- package/dist/watch.js +181 -0
- package/examples/watch-agent/README.md +124 -0
- package/examples/watch-agent/config.example.json +20 -0
- package/examples/watch-agent/dispatcher.mjs +1443 -0
- package/examples/watch-agent/gitignore.template +6 -0
- package/examples/watch-agent/package.json +12 -0
- package/examples/watch-agent/test/dispatcher.test.mjs +763 -0
- package/examples/watch-agent/test/supervisor.test.mjs +126 -0
- package/package.json +50 -4
- package/prompts/watch-agent.md +250 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Odyssey365
|
|
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
CHANGED
|
@@ -1,3 +1,297 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Odyssey CLI
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> Command-line client for [Odyssey](https://product.odyssey365.app) — manage tasks, memos, boards and snapshots
|
|
4
|
+
> from your terminal or an AI agent, across **multiple Odyssey accounts**.
|
|
5
|
+
|
|
6
|
+
Odyssey MCP 커넥터와 **같은 서버·같은 도구**를 터미널에서 부른다. 다른 점은 계정이다 — 커넥터는 연결 하나에
|
|
7
|
+
계정 하나지만, CLI 는 **호출마다 프로필(계정)을 고른다**. 개인 계정과 운영 계정을 한 세션에서 오가거나,
|
|
8
|
+
AI 에이전트(Claude Code 등)가 두 계정을 함께 다루게 할 때 쓴다.
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm i -g @odyssey365/cli
|
|
12
|
+
|
|
13
|
+
odyssey login # 브라우저로 로그인 → 프로필 default
|
|
14
|
+
odyssey login -p work # 다른 계정 → 프로필 work
|
|
15
|
+
|
|
16
|
+
odyssey list_todos --status inProgress
|
|
17
|
+
odyssey -p work search "주간 회의"
|
|
18
|
+
odyssey get_todo <todoId>
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Node.js 20 이상. 런타임 의존성은 `firebase` 하나 — `odyssey watch` 만 쓰고, 그 명령에서만 불러온다.
|
|
22
|
+
감시·예제 준비 기능은 **0.2.0 이상**이 필요하다. 설치 후 `odyssey --version`을 확인한다.
|
|
23
|
+
아직 공개판이 0.1.0이면 감시 명령은 없으므로, 제공된 후보 `.tgz`를 `npm i -g /경로/파일.tgz`로 설치한다.
|
|
24
|
+
|
|
25
|
+
## 계정
|
|
26
|
+
|
|
27
|
+
| 명령 | 하는 일 |
|
|
28
|
+
|---|---|
|
|
29
|
+
| `odyssey login [-p 이름]` | 브라우저로 로그인해 프로필에 저장. 처음 로그인한 프로필이 기본이 된다 |
|
|
30
|
+
| `odyssey login -p 이름 --no-browser` | 브라우저를 열지 않고 로그인 주소만 출력 |
|
|
31
|
+
| `odyssey login -p 이름 --with-key` | 앱에서 발급한 API 키(`odk_…`)로 저장 — 표준입력 또는 숨김 입력 |
|
|
32
|
+
| `odyssey whoami [-p 이름]` | 그 프로필이 어느 계정인지 서버에 물어 확인 |
|
|
33
|
+
| `odyssey profiles` | 로그인된 프로필 목록(`*` = 기본) |
|
|
34
|
+
| `odyssey use 이름` | 기본 프로필 바꾸기 |
|
|
35
|
+
| `odyssey logout [-p 이름] [--all]` | 서버에서 토큰을 회수하고 로컬에서 지운다 |
|
|
36
|
+
|
|
37
|
+
로그인은 Odyssey 의 OAuth 2.1(PKCE) 흐름이다. CLI 가 이 컴퓨터에 잠깐 루프백 주소(`127.0.0.1`)를 열고,
|
|
38
|
+
브라우저 로그인이 끝나면 그 주소로 돌아온 인가 코드를 토큰으로 바꾼다. 로그인 페이지는 매번 새로 로그인하므로
|
|
39
|
+
다른 계정으로 바꿔 로그인하기 쉽다.
|
|
40
|
+
|
|
41
|
+
토큰은 `~/.odyssey/cli/credentials.json`에 평문으로 저장된다(디렉터리 0700·파일 0600, Windows에서는 POSIX chmod가 적용되지 않음). 액세스 토큰은 60일이고, 만료 하루 전부터
|
|
42
|
+
리프레시 토큰으로 알아서 갱신한다.
|
|
43
|
+
|
|
44
|
+
**계정 고르는 순서**: `-p/--profile` → 환경변수 `ODYSSEY_TOKEN`(저장 없이 토큰 직접) → `ODYSSEY_PROFILE`
|
|
45
|
+
→ `odyssey use` 로 정한 기본 → `default`.
|
|
46
|
+
|
|
47
|
+
## 도구
|
|
48
|
+
|
|
49
|
+
도구 정의는 서버가 정본이다. 서버에 도구가 늘면 CLI 코드를 업데이트하지 않아도 쓸 수 있다. 목록은 6시간 캐시하므로 즉시 반영이 필요하면 `--refresh-tools`를 붙인다(모르는 이름은 한 번 새로 받는다).
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
odyssey tools # 전체 목록 ([읽기]/[쓰기] 표시)
|
|
53
|
+
odyssey tools memo # 검색
|
|
54
|
+
odyssey describe create_todo # 설명 전문 + 파라미터
|
|
55
|
+
odyssey create_todo --help # 같은 것
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### 파라미터 적는 법
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
odyssey create_todo --title "보고서 쓰기" --isToday --tags 업무 --tags 급함
|
|
62
|
+
odyssey create_todo --title "마감" --deadline.endTime 2026-10-20T18:00:00+09:00
|
|
63
|
+
odyssey create_todo --title "체크" --checklist '[{"title":"초안"},{"title":"검토"}]'
|
|
64
|
+
odyssey update_todo <todoId> --deadline null
|
|
65
|
+
odyssey create_memo --json '{"title":"회의록","text":"..."}'
|
|
66
|
+
cat input.json | odyssey create_memo --input -
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
- 값의 형은 서버 스키마를 보고 맞춘다(`--limit 5` → 숫자).
|
|
70
|
+
- boolean 은 `--flag` / `--no-flag`, 배열은 반복하거나 JSON 으로, 객체 안쪽은 점 경로로.
|
|
71
|
+
- 필수 파라미터가 하나뿐인 도구는 위치 인자로 받는다(`odyssey get_todo <todoId>`).
|
|
72
|
+
- 도구 이름은 케밥으로 써도 된다(`odyssey list-todos`).
|
|
73
|
+
|
|
74
|
+
### 출력
|
|
75
|
+
|
|
76
|
+
결과는 stdout, 안내·오류는 stderr 로 나뉜다.
|
|
77
|
+
|
|
78
|
+
| `-o` | 내용 |
|
|
79
|
+
|---|---|
|
|
80
|
+
| `json`(기본) | 서버의 구조화 결과. 터미널이면 들여쓰고, 파이프면 한 줄 |
|
|
81
|
+
| `text` | 서버가 만든 요약 텍스트 |
|
|
82
|
+
| `raw` | MCP `CallToolResult` 전체 |
|
|
83
|
+
|
|
84
|
+
이미지를 돌려주는 도구(`read_memo_image` 등)는 이미지를 파일로 저장하고 경로를 출력한다
|
|
85
|
+
(`ODYSSEY_OUTPUT_DIR`, 기본은 임시 폴더).
|
|
86
|
+
|
|
87
|
+
종료 코드: `0` 성공 · `1` 도구 오류 · `2` 사용법 오류 · `3` 로그인 필요 · `4` 네트워크
|
|
88
|
+
|
|
89
|
+
## AI 에이전트에서
|
|
90
|
+
|
|
91
|
+
CLI 가 에이전트용 설명서를 직접 낸다 — 사용법 · 이 컴퓨터에 로그인된 계정 · Odyssey 서버의 사용 지침(실시간).
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
odyssey agent-guide # 전문 — 에이전트가 작업을 시작할 때 한 번 읽는다
|
|
95
|
+
odyssey agent-guide --snippet # AGENTS.md · CLAUDE.md · GEMINI.md 등에 붙일 짧은 절
|
|
96
|
+
odyssey agent-guide --skill # Claude Code · Codex 스킬 파일(SKILL.md) 내용
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
에이전트에게 알리는 가장 쉬운 방법은 그 에이전트가 일하는 프로젝트의 `AGENTS.md`(여러 코딩 에이전트가 함께 읽는 관례 —
|
|
100
|
+
Claude Code 는 `CLAUDE.md`)에 짧은 절을 붙이는 것이다. 그 절은 "시작할 때 `odyssey agent-guide` 를 실행하라"고 가리키므로,
|
|
101
|
+
계정이나 서버 지침이 바뀌어도 파일을 고칠 필요가 없다.
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
odyssey agent-guide --snippet # 내용을 확인한 뒤 기존 저장소 지침의 정본에 맞게 반영
|
|
105
|
+
odyssey agent-guide --skill # 스킬 내용을 출력한다. 기존 파일 덮어쓰기 전에 내용을 확인한다.
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
> MCP 커넥터는 연결할 때 서버의 사용 지침(복잡한 작업 전 `getGuide` 로 절차를 읽을 것 등)을 받는다. CLI 는 호출마다 한 왕복으로
|
|
109
|
+
> 끝내려 그 연결 단계를 건너뛰므로, 그 지침은 `odyssey agent-guide` 로 받는다.
|
|
110
|
+
|
|
111
|
+
## 프로그램에서 쓰기 — 활동 자동 기록 (예: 게임 기록기)
|
|
112
|
+
|
|
113
|
+
사람 없이 도는 프로그램(게임 프로세스 감시기 등)이 "언제부터 언제까지 무엇을 했다"를 남기는 법.
|
|
114
|
+
|
|
115
|
+
**1. 한 번만** — 그 PC 에서 로그인하고, 시간을 쌓을 기록을 만든다.
|
|
116
|
+
|
|
117
|
+
```bash
|
|
118
|
+
odyssey login # 브라우저 로그인 한 번 — 이후 토큰은 알아서 갱신된다
|
|
119
|
+
odyssey list_categories # 카테고리 이름 확인
|
|
120
|
+
odyssey create_record --title "리그 오브 레전드" --emoji 🎮 --numType time --numUnit min --tags 게임 --categoryName "게임"
|
|
121
|
+
# 기록의 카테고리가 타임라인 카드에도 붙는다 — 앱 타임라인의 카테고리 필터·기록장 묶기가 이 값으로 거른다
|
|
122
|
+
# → {"recordId":"…"} 를 프로그램 설정에 저장
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
**2. 세션이 끝날 때마다** — 측정값 하나 = 기록 통계(주·월 합계) + 타임라인 카드(그 구간).
|
|
126
|
+
|
|
127
|
+
```json
|
|
128
|
+
{
|
|
129
|
+
"recordId": "<위 recordId>",
|
|
130
|
+
"value": 133,
|
|
131
|
+
"time": "2026-10-10T21:03:00+09:00",
|
|
132
|
+
"endTime": "2026-10-10T23:16:00+09:00",
|
|
133
|
+
"dedupeKey": "lol-2026-10-10T21:03:00+09:00"
|
|
134
|
+
}
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
odyssey add_record_trace --input - # 위 JSON 을 표준입력으로
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
**승패·KDA 까지 같이 남기려면** — 기록을 만들 때 칸(`fields`)을 설계한다. 첫 칸이 대표값(차트·통계)이다.
|
|
142
|
+
킬·데스·어시처럼 한 덩어리로 생각하는 숫자는 **숫자 묶음 칸(`numberSet`) 하나**에 담는다 — KDA 비율은 저장하지 않고 앱·서버가 계산한다.
|
|
143
|
+
|
|
144
|
+
```json
|
|
145
|
+
{
|
|
146
|
+
"title": "리그 오브 레전드 랭크",
|
|
147
|
+
"emoji": "🎮",
|
|
148
|
+
"fields": [
|
|
149
|
+
{ "label": "결과", "kind": "choice", "options": ["승", "패"] },
|
|
150
|
+
{ "label": "KDA", "kind": "numberSet", "calc": "kda",
|
|
151
|
+
"parts": [{ "label": "킬" }, { "label": "데스" }, { "label": "어시" }] },
|
|
152
|
+
{ "label": "플레이", "kind": "span" }
|
|
153
|
+
]
|
|
154
|
+
}
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
odyssey create_record --input - # 위 JSON — 운동이면 parts 를 무게(kg)·횟수(회)·세트(세트), joiner "times", calc "product"(볼륨)
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
측정값은 칸 **이름**으로 적는다. 묶음 값은 `"12/3/8"` 글·`[12, 3, 8]` 목록·`{"킬": 12, …}` 맵 어느 것이든 된다. 구간 칸은 `time`·`endTime` 이 값이다.
|
|
162
|
+
|
|
163
|
+
```json
|
|
164
|
+
{
|
|
165
|
+
"recordId": "<recordId>",
|
|
166
|
+
"values": { "결과": "승", "KDA": "12/3/8" },
|
|
167
|
+
"time": "2026-10-10T21:03:00+09:00",
|
|
168
|
+
"endTime": "2026-10-10T21:35:00+09:00",
|
|
169
|
+
"dedupeKey": "lol-2026-10-10T21:03:00+09:00"
|
|
170
|
+
}
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
기록 없이 타임라인 카드만 원하면 `create_timeline_event` 에 `title`·`startTime`·`endTime`(+`dedupeKey`·`categoryName`)을 준다 —
|
|
174
|
+
시작·끝이 둘 다 있으면 다른 내용 없이도 만들어진다.
|
|
175
|
+
|
|
176
|
+
**지켜야 할 것**
|
|
177
|
+
|
|
178
|
+
- **JSON 은 표준입력으로**(`--input -`). Windows 의 cmd 는 명령줄의 따옴표·`&`·`^`·`%` 를 제멋대로 해석한다.
|
|
179
|
+
- **`dedupeKey` 를 꼭 준다.** 같은 세션이면 같은 키(예: 게임 + 시작 시각). 오프라인이었거나 응답을 못 받아 다시 보내도
|
|
180
|
+
측정값·카드가 한 번만 생긴다(`"deduplicated": true` 가 돌아온다).
|
|
181
|
+
- **시각은 오프셋을 붙인 ISO 8601**(`+09:00` 또는 `Z`). 못 읽는 시각은 거절된다.
|
|
182
|
+
- **종료 코드로 갈라 처리한다**: `0` 완료 · `4` 네트워크 → 쌓아 두고 같은 `dedupeKey` 로 나중에 재전송 ·
|
|
183
|
+
`3` 로그인 필요 → 사용자에게 알림(`odyssey login`) · `1`·`2` 입력 문제 → 재전송해도 같다, 로그로 남긴다.
|
|
184
|
+
- 출력(stdout)은 UTF-8 JSON 한 줄, 오류 메시지는 stderr.
|
|
185
|
+
|
|
186
|
+
**Windows 에서 부르는 법**
|
|
187
|
+
|
|
188
|
+
- 프로그램에서는 `odyssey.cmd`(npm 전역 설치가 만드는 실행 파일)를 부르거나, 셸을 거치지 않으려면
|
|
189
|
+
`node "%APPDATA%\npm\node_modules\@odyssey365\cli\dist\index.js"` 를 직접 부른다.
|
|
190
|
+
- PowerShell 에서 `odyssey` 가 "스크립트를 실행할 수 없습니다"로 막히면 실행 정책 때문이다 — `odyssey.cmd` 로 부르거나
|
|
191
|
+
`Set-ExecutionPolicy -Scope CurrentUser RemoteSigned`.
|
|
192
|
+
|
|
193
|
+
```python
|
|
194
|
+
# Python 예 — 세션 하나 기록
|
|
195
|
+
import json, subprocess
|
|
196
|
+
payload = {"recordId": RECORD_ID, "value": minutes, "time": start_iso, "endTime": end_iso,
|
|
197
|
+
"dedupeKey": f"lol-{start_iso}"}
|
|
198
|
+
p = subprocess.run(["odyssey.cmd", "add_record_trace", "--input", "-"],
|
|
199
|
+
input=json.dumps(payload), capture_output=True, text=True, encoding="utf-8")
|
|
200
|
+
if p.returncode == 4: queue_for_retry(payload) # 네트워크 — 같은 키로 나중에
|
|
201
|
+
elif p.returncode == 3: notify("odyssey login 이 필요합니다")
|
|
202
|
+
elif p.returncode != 0: log_error(p.stderr)
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
## 관리자 — 사용량 한도·요금제 (`-p admin`)
|
|
206
|
+
|
|
207
|
+
관리자(admin 클레임) 계정으로 붙으면 도구 목록에 셋이 더 보인다(일반 계정엔 없다). 사용자가 앱에서 [더 필요해요]로 한도 상향을
|
|
208
|
+
요청하면 이걸로 올린다 — 저장소·서비스 계정 키 없이, 앱 릴리스 없이 바로 먹는다.
|
|
209
|
+
|
|
210
|
+
```bash
|
|
211
|
+
odyssey -p admin get_usage_quota --account user@example.com # 요금제·상향·유효 한도·사용량 + 요금제 표
|
|
212
|
+
odyssey -p admin set_usage_quota --account user@example.com --projectLimit 20 --storageLimitMb 1024
|
|
213
|
+
odyssey -p admin set_usage_quota --account user@example.com --companionMonthlyBudgetKrw 10000
|
|
214
|
+
odyssey -p admin set_usage_quota --json '{"account":"user@example.com","clear":["all"]}' # 상향 지우기(요금제 값으로)
|
|
215
|
+
odyssey -p admin set_usage_plan --planId beta --projectLimit 8 # 요금제 표 고치기 → 그 요금제 계정 전부 다시 적힘
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
유효 한도 = 계정별 상향 ?? 요금제(`usage_plan/{id}`) ?? 코드 기본값(보드 6 · 업로드 300MB · 컴패니언 월 ₩3,000).
|
|
219
|
+
결제가 붙으면 계정의 `plan` 만 바꾼다(`set_usage_quota --plan pro`) — 운영자 상향과 섞이지 않는다.
|
|
220
|
+
이력: `document/90-process/work-log/261019 베타 사용량 한도 요금제 usage_plan 계정별 한도 관리자 도구.md`
|
|
221
|
+
|
|
222
|
+
## 실시간 감시 — `odyssey watch`
|
|
223
|
+
|
|
224
|
+
내 계정의 변화를 실시간으로 받아 **한 줄에 JSON 하나씩(NDJSON)** stdout 으로 흘린다. 그 위에 프로그램을 붙인다.
|
|
225
|
+
|
|
226
|
+
**바로 실행할 감시 에이전트 예제**가 패키지에 포함돼 있다. 작업할 프로젝트 폴더에서:
|
|
227
|
+
|
|
228
|
+
```bash
|
|
229
|
+
odyssey watch-agent init ../my-watch-agent
|
|
230
|
+
cd ../my-watch-agent
|
|
231
|
+
# config.json의 작업 폴더·프로필·Claude Code MCP 이름·예산 확인
|
|
232
|
+
node dispatcher.mjs --check
|
|
233
|
+
node dispatcher.mjs --dry-run
|
|
234
|
+
# 배달 예정 확인 후 Ctrl+C
|
|
235
|
+
node dispatcher.mjs
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
예제는 태그·멘션 배달, 항목별 세션 재개, 중복 방지·커서 보관, 준비 대기 제한시간·재연결, 단일 실행 잠금과 하루 예산을 갖춘다.
|
|
239
|
+
CLI와 Claude Code MCP는 같은 Odyssey 계정으로 로그인한다. 예제 생성은 기존 폴더를 덮어쓰거나 자동 시작을 등록하지 않는다.
|
|
240
|
+
자세한 설치·설정·중지 방법은 [예제 README](examples/watch-agent/README.md)를 따른다.
|
|
241
|
+
|
|
242
|
+
```bash
|
|
243
|
+
odyssey watch --tag "클로드 코드" # 그 태그 할일의 추가·수정·삭제 + 내 댓글
|
|
244
|
+
odyssey watch --tag 버그 --tag "새 기능" --no-comments
|
|
245
|
+
odyssey watch --since 2026-10-16T00:00:00+09:00 # 이 시각 뒤의 내 댓글부터(밀린 댓글)
|
|
246
|
+
odyssey watch --tag "클로드 코드" | my-dispatcher # 파이프로 프로그램에 넘기기
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
| 이벤트 | 내용 |
|
|
250
|
+
|---|---|
|
|
251
|
+
| `{"type":"ready", uid, streams, since}` | 첫 스냅샷까지 받았다 |
|
|
252
|
+
| `{"type":"todo", change, initial, uid, title, status, tags, updatedAt}` | `change` = added·modified·removed. 켠 직후의 첫 묶음은 `initial: true`(밀린 일) |
|
|
253
|
+
| `{"type":"comment", author, commentUid, itemType, itemUid, itemOwnerUid, parentItemUid, replyToCommentUid, roomUid, text, kind, createdAt}` | 내가 쓴 새 댓글. AI(MCP·컴패니언) 댓글은 기본으로 뺀다(`--include-agent`). `parentItemUid` = 보드 카드면 그 보드 · `replyToCommentUid` = 앱 「답글」이면 어느 댓글에 단 것인지 |
|
|
254
|
+
| `{"type":"error", stream, code, message}` | 그 스트림의 오류. Firestore 리스너는 오류 뒤 다시 붙지 않는다 — 받는 쪽이 감시를 다시 띄운다 |
|
|
255
|
+
|
|
256
|
+
- **OAuth 로그인 프로필만** 된다(`odyssey login`). API 키는 서버가 거절한다.
|
|
257
|
+
- 어떻게: CLI 로그인을 서버(`/cli/firebase-session`)에서 Firebase 커스텀 토큰 + App Check 토큰으로 바꿔 Firestore 리스너를 직접 붙인다.
|
|
258
|
+
Firebase 신원은 OAuth 연결마다 분리한다. 내 할일·내 댓글·읽을 수 있는 방 메타데이터만 읽고, 앱 데이터 쓰기는 허용하지 않는다.
|
|
259
|
+
`odyssey logout`으로 서버 연결이 회수되면 rules가 추가 데이터 접근을 거절하고 CLI 신원의 Firebase 갱신도 회수한다. 일반 앱 로그인은 유지한다.
|
|
260
|
+
Firebase 로그인 상태는 메모리에만 두고 App Check는 만료 때 다시 교환한다. Windows 발급·새 OAuth 연결 생성으로 파생 자격을 재사용할 수 없다.
|
|
261
|
+
- 이 보안 변경은 Functions v1/v2·Firestore/Storage 규칙의 동반 반영이 필요하다. 새 CLI는 전용 신원을 주지 않는 구버전 서버에서 `watch`를 거절한다. 현재 후보는 미배포이며 운영 반영은 별도다.
|
|
262
|
+
- 에이전트 댓글을 가르는 표식은 `metadata.authorKind`다. `claude`·`companion`·알 수 없는 비어 있지 않은 값은 모두 `agent`로 분류한다. 직접 디스패처를 만들 때 에이전트 댓글은 배달하지 않는다. 예제는 `--include-agent`로 표식을 받되, 세션 재개 판정에만 쓰고 일꾼에게 배달하지 않는다.
|
|
263
|
+
- **감시 에이전트 만들기**: `odyssey agent-guide --watch-agent` 가 코딩 에이전트(예: Claude Code)에게 줄 프롬프트를 낸다 —
|
|
264
|
+
디스패처는 **배달만** 한다: 감시 → 항목으로 일꾼 세션을 고르고 → 새로 만들거나(`--session-id`) 이어 받아(`--resume`) 깨운다.
|
|
265
|
+
입구는 감시 태그 할일과, 아무 항목 댓글의 멘션(`@클로드코드`) 둘이다. 세션이 생긴 항목은 그 스레드의 내 새 댓글·답글로 다시 깨운다. 세션이 없는 항목은 멘션으로 연다.
|
|
266
|
+
판단·작업·답글·상태는 깨운 세션의 Claude 가 Odyssey MCP 로 한다(`prompts/watch-agent.md`). 일이 없으면 토큰 0.
|
|
267
|
+
|
|
268
|
+
## 환경변수
|
|
269
|
+
|
|
270
|
+
| 이름 | 뜻 |
|
|
271
|
+
|---|---|
|
|
272
|
+
| `ODYSSEY_PROFILE` | 기본 프로필 대신 쓸 프로필 |
|
|
273
|
+
| `ODYSSEY_TOKEN` | 저장 없이 쓸 토큰(`odk_` API 키 또는 `oat_` 토큰). `ODYSSEY_API_KEY` 도 받는다 |
|
|
274
|
+
| `ODYSSEY_MCP_URL` | 서버 주소(기본 `https://mcp-odyssey30-60.odyssey365.app`) |
|
|
275
|
+
| `ODYSSEY_CONFIG_DIR` | 자격증명·캐시 위치(기본 `~/.odyssey/cli`) |
|
|
276
|
+
| `ODYSSEY_OUTPUT_DIR` | 이미지 저장 위치 |
|
|
277
|
+
| `ODYSSEY_TIMEOUT_MS` | 헤더부터 본문 수신 완료까지 요청 제한 시간(기본 120000). OAuth·MCP·감시 세션 교환 공통. 네트워크 실패는 종료 4 |
|
|
278
|
+
| `ODYSSEY_PRETTY=1` | 파이프에서도 JSON 들여쓰기 |
|
|
279
|
+
|
|
280
|
+
## 개발
|
|
281
|
+
|
|
282
|
+
```bash
|
|
283
|
+
npm install
|
|
284
|
+
npm test # 빌드 + CLI 회귀·가짜 서버 E2E + 감시 예제 검사
|
|
285
|
+
npm run test:package # tarball → 새 prefix 설치 → 예제 추출·복사본 검사(게시 없음)
|
|
286
|
+
node dist/index.js --help
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
후보 준비: `npm run prepublishOnly`로 검사하고 `npm pack --pack-destination <폴더>`로 tarball을 만든다.
|
|
290
|
+
`prepack`은 빌드를 갱신하고, `prepublishOnly`는 전체 검사와 패키지 새 설치 검사까지 수행한다.
|
|
291
|
+
실제 게시 `npm publish`는 별도 배포 요청이 있을 때만 실행한다. CI는 Node 20·22·24에서 검사하며 게시 단계는 없다.
|
|
292
|
+
|
|
293
|
+
## License
|
|
294
|
+
|
|
295
|
+
MIT
|
|
296
|
+
|
|
297
|
+
> 2026-10-22: 통신 장애 회귀·감시 예제·패키지 새 설치 검사를 추가했다. 공개 npm 게시와 서버 배포는 별도 단계다.
|
package/dist/args.js
ADDED
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 명령줄 해석 — 전역 옵션과 도구 파라미터 플래그.
|
|
3
|
+
*
|
|
4
|
+
* 도구 파라미터는 서버가 tools/list 로 내는 JSON Schema 를 보고 형을 맞춘다. 스키마 없이
|
|
5
|
+
* 문자열로 보내면 `--limit 5` 가 "5" 로 가고, 서버의 zod 가 "Expected number" 로 거절한다.
|
|
6
|
+
*
|
|
7
|
+
* --key value · --key=value 값
|
|
8
|
+
* --flag · --no-flag boolean
|
|
9
|
+
* --tags a --tags b 배열(반복) · --tags '["a","b"]' 도 된다
|
|
10
|
+
* --deadline.endTime 2026-… 객체 안쪽 필드(점 경로) · --deadline '{"endTime":"…"}' 도 된다
|
|
11
|
+
* --deadline null null 을 받는 필드
|
|
12
|
+
* --json '{…}' · --input file|- JSON 으로 한 번에(플래그가 그 위에 덮인다)
|
|
13
|
+
* <값> 필수 파라미터가 하나뿐이면 위치 인자로 받는다(get_todo <id>)
|
|
14
|
+
*
|
|
15
|
+
* 스키마에 없는 키는 그대로 보낸다 — 서버가 "이걸 의도했나요?" 로 고쳐 준다(D458).
|
|
16
|
+
*/
|
|
17
|
+
import { UsageError } from './config.js';
|
|
18
|
+
/** 값 하나를 받는 전역 옵션(긴 이름 → 필드). */
|
|
19
|
+
const GLOBAL_WITH_VALUE = {
|
|
20
|
+
'-p': 'profile',
|
|
21
|
+
'--profile': 'profile',
|
|
22
|
+
'--server': 'server',
|
|
23
|
+
'-o': 'output',
|
|
24
|
+
'--output': 'output',
|
|
25
|
+
'--input': 'inputFile',
|
|
26
|
+
'--json': 'inputJson',
|
|
27
|
+
};
|
|
28
|
+
const GLOBAL_FLAGS = {
|
|
29
|
+
'-h': 'help',
|
|
30
|
+
'--help': 'help',
|
|
31
|
+
'-v': 'version',
|
|
32
|
+
'--version': 'version',
|
|
33
|
+
'--refresh-tools': 'refreshTools',
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* 전역 옵션을 어디에 있든 걷어 내고 나머지를 순서대로 돌려준다. `--` 뒤는 손대지 않는다
|
|
37
|
+
* (도구 파라미터 이름이 전역 옵션과 겹칠 때의 탈출구).
|
|
38
|
+
*/
|
|
39
|
+
export function extractGlobals(argv) {
|
|
40
|
+
const globals = { help: false, version: false, refreshTools: false };
|
|
41
|
+
const rest = [];
|
|
42
|
+
for (let i = 0; i < argv.length; i++) {
|
|
43
|
+
const tok = argv[i];
|
|
44
|
+
if (tok === '--') {
|
|
45
|
+
rest.push(...argv.slice(i));
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
const eq = tok.startsWith('--') ? tok.indexOf('=') : -1;
|
|
49
|
+
const name = eq > 0 ? tok.slice(0, eq) : tok;
|
|
50
|
+
if (name in GLOBAL_WITH_VALUE) {
|
|
51
|
+
let value;
|
|
52
|
+
if (eq > 0)
|
|
53
|
+
value = tok.slice(eq + 1);
|
|
54
|
+
else {
|
|
55
|
+
value = argv[i + 1];
|
|
56
|
+
i++;
|
|
57
|
+
}
|
|
58
|
+
if (value === undefined)
|
|
59
|
+
throw new UsageError(`${name} 에 값이 필요합니다.`);
|
|
60
|
+
const field = GLOBAL_WITH_VALUE[name];
|
|
61
|
+
if (field === 'output') {
|
|
62
|
+
if (value !== 'json' && value !== 'text' && value !== 'raw') {
|
|
63
|
+
throw new UsageError(`--output 은 json · text · raw 중 하나입니다 (받은 값: ${value}).`);
|
|
64
|
+
}
|
|
65
|
+
globals.output = value;
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
globals[field] = value;
|
|
69
|
+
}
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
if (eq < 0 && tok in GLOBAL_FLAGS) {
|
|
73
|
+
globals[GLOBAL_FLAGS[tok]] = true;
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
rest.push(tok);
|
|
77
|
+
}
|
|
78
|
+
return { globals, rest };
|
|
79
|
+
}
|
|
80
|
+
/** 명령별 단순 플래그(--no-browser 등)를 걷어 낸다. */
|
|
81
|
+
export function takeFlag(args, ...names) {
|
|
82
|
+
let found = false;
|
|
83
|
+
for (let i = args.length - 1; i >= 0; i--) {
|
|
84
|
+
if (names.includes(args[i])) {
|
|
85
|
+
args.splice(i, 1);
|
|
86
|
+
found = true;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return found;
|
|
90
|
+
}
|
|
91
|
+
// ── 스키마 해석 ──────────────────────────────────────────────────────────────
|
|
92
|
+
/** 스키마가 받는 JSON 형 집합. anyOf/oneOf·enum·const 까지 펼친다. 비면 "아무거나". */
|
|
93
|
+
export function schemaTypes(schema) {
|
|
94
|
+
const out = new Set();
|
|
95
|
+
if (!schema)
|
|
96
|
+
return out;
|
|
97
|
+
const add = (t) => {
|
|
98
|
+
if (typeof t === 'string')
|
|
99
|
+
out.add(t);
|
|
100
|
+
};
|
|
101
|
+
if (Array.isArray(schema.type))
|
|
102
|
+
schema.type.forEach(add);
|
|
103
|
+
else
|
|
104
|
+
add(schema.type);
|
|
105
|
+
for (const sub of [...(schema.anyOf ?? []), ...(schema.oneOf ?? [])]) {
|
|
106
|
+
schemaTypes(sub).forEach((t) => out.add(t));
|
|
107
|
+
}
|
|
108
|
+
const literals = schema.enum ?? (schema.const !== undefined ? [schema.const] : []);
|
|
109
|
+
for (const v of literals) {
|
|
110
|
+
out.add(v === null ? 'null' : typeof v === 'number' ? 'number' : typeof v);
|
|
111
|
+
}
|
|
112
|
+
return out;
|
|
113
|
+
}
|
|
114
|
+
/** 배열 스키마의 원소 스키마(anyOf 안의 배열까지). */
|
|
115
|
+
function itemsOf(schema) {
|
|
116
|
+
if (!schema)
|
|
117
|
+
return undefined;
|
|
118
|
+
if (schema.items)
|
|
119
|
+
return schema.items;
|
|
120
|
+
for (const sub of [...(schema.anyOf ?? []), ...(schema.oneOf ?? [])]) {
|
|
121
|
+
const it = itemsOf(sub);
|
|
122
|
+
if (it)
|
|
123
|
+
return it;
|
|
124
|
+
}
|
|
125
|
+
return undefined;
|
|
126
|
+
}
|
|
127
|
+
/** 객체 스키마의 속성(anyOf 안의 객체까지). */
|
|
128
|
+
function propertiesOf(schema) {
|
|
129
|
+
if (!schema)
|
|
130
|
+
return undefined;
|
|
131
|
+
if (schema.properties)
|
|
132
|
+
return schema.properties;
|
|
133
|
+
for (const sub of [...(schema.anyOf ?? []), ...(schema.oneOf ?? [])]) {
|
|
134
|
+
const p = propertiesOf(sub);
|
|
135
|
+
if (p)
|
|
136
|
+
return p;
|
|
137
|
+
}
|
|
138
|
+
return undefined;
|
|
139
|
+
}
|
|
140
|
+
const NUMBER_RE = /^-?(?:\d+\.?\d*|\.\d+)(?:[eE][-+]?\d+)?$/;
|
|
141
|
+
function parseJsonValue(raw, label) {
|
|
142
|
+
try {
|
|
143
|
+
return JSON.parse(raw);
|
|
144
|
+
}
|
|
145
|
+
catch (e) {
|
|
146
|
+
throw new UsageError(`${label} 의 JSON 을 읽지 못했습니다: ${e.message}`);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
/** 문자열 값 하나를 스키마 형에 맞춘다. */
|
|
150
|
+
export function coerceValue(raw, schema, label) {
|
|
151
|
+
const types = schemaTypes(schema);
|
|
152
|
+
const t = raw.trim();
|
|
153
|
+
if (types.size === 0) {
|
|
154
|
+
// 스키마를 모르는 키 — 객체·배열 모양일 때만 JSON 으로 읽고 나머지는 문자열.
|
|
155
|
+
return t.startsWith('{') || t.startsWith('[') ? parseJsonValue(t, label) : raw;
|
|
156
|
+
}
|
|
157
|
+
if (types.has('null') && t === 'null')
|
|
158
|
+
return null;
|
|
159
|
+
if (types.has('object') && t.startsWith('{'))
|
|
160
|
+
return parseJsonValue(t, label);
|
|
161
|
+
if (types.has('array') && t.startsWith('['))
|
|
162
|
+
return parseJsonValue(t, label);
|
|
163
|
+
if (types.has('boolean') && /^(true|false)$/i.test(t))
|
|
164
|
+
return t.toLowerCase() === 'true';
|
|
165
|
+
if ((types.has('number') || types.has('integer')) && NUMBER_RE.test(t))
|
|
166
|
+
return Number(t);
|
|
167
|
+
if (types.has('string'))
|
|
168
|
+
return raw;
|
|
169
|
+
if (types.has('array'))
|
|
170
|
+
return [coerceValue(raw, itemsOf(schema), `${label}[]`)];
|
|
171
|
+
if (types.has('boolean'))
|
|
172
|
+
throw new UsageError(`${label} 은 true/false 입니다 (받은 값: ${raw}).`);
|
|
173
|
+
if (types.has('number') || types.has('integer')) {
|
|
174
|
+
throw new UsageError(`${label} 은 숫자입니다 (받은 값: ${raw}).`);
|
|
175
|
+
}
|
|
176
|
+
if (types.has('object'))
|
|
177
|
+
throw new UsageError(`${label} 은 JSON 객체입니다 — 예: ${label} '{"key":"value"}'`);
|
|
178
|
+
return raw;
|
|
179
|
+
}
|
|
180
|
+
function kebabToCamel(s) {
|
|
181
|
+
return s.replace(/-([a-z0-9])/g, (_, c) => c.toUpperCase());
|
|
182
|
+
}
|
|
183
|
+
/** 플래그 이름 → 스키마 키. 그대로 있으면 그대로, 케밥이면 카멜로 맞춰 본다. */
|
|
184
|
+
function resolveKey(name, props) {
|
|
185
|
+
if (!props || name in props)
|
|
186
|
+
return name;
|
|
187
|
+
const camel = kebabToCamel(name);
|
|
188
|
+
return camel in props ? camel : name;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* 도구 플래그를 스키마에 맞춰 인자 객체로 만든다.
|
|
192
|
+
* `base` 는 --json/--input 으로 받은 객체 — 플래그가 그 위에 덮인다.
|
|
193
|
+
*/
|
|
194
|
+
export function parseToolArgs(tokens, inputSchema, base = {}) {
|
|
195
|
+
const rootProps = inputSchema?.properties;
|
|
196
|
+
const args = structuredClone(base);
|
|
197
|
+
const positionals = [];
|
|
198
|
+
const seen = new Set();
|
|
199
|
+
const assign = (path, raw) => {
|
|
200
|
+
// 경로를 따라 스키마와 대상 객체를 함께 내려간다.
|
|
201
|
+
let props = rootProps;
|
|
202
|
+
let target = args;
|
|
203
|
+
const keys = [];
|
|
204
|
+
let schema;
|
|
205
|
+
for (let i = 0; i < path.length; i++) {
|
|
206
|
+
const key = resolveKey(path[i], props);
|
|
207
|
+
keys.push(key);
|
|
208
|
+
schema = props?.[key];
|
|
209
|
+
if (i < path.length - 1) {
|
|
210
|
+
const existing = target[key];
|
|
211
|
+
if (existing === undefined || existing === null || typeof existing !== 'object' || Array.isArray(existing)) {
|
|
212
|
+
target[key] = {};
|
|
213
|
+
}
|
|
214
|
+
target = target[key];
|
|
215
|
+
props = propertiesOf(schema);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
const leaf = keys[keys.length - 1];
|
|
219
|
+
const label = `--${keys.join('.')}`;
|
|
220
|
+
const value = raw === true || raw === false
|
|
221
|
+
? raw
|
|
222
|
+
: coerceValue(raw, schema, label);
|
|
223
|
+
const types = schemaTypes(schema);
|
|
224
|
+
const isArray = types.has('array');
|
|
225
|
+
const pathKey = keys.join('.');
|
|
226
|
+
if (isArray && !Array.isArray(value) && raw !== true && raw !== false) {
|
|
227
|
+
// 반복 지정 = 원소 추가
|
|
228
|
+
const prev = seen.has(pathKey) && Array.isArray(target[leaf]) ? target[leaf] : [];
|
|
229
|
+
target[leaf] = [...prev, coerceValue(raw, itemsOf(schema), `${label}[]`)];
|
|
230
|
+
}
|
|
231
|
+
else if (isArray && Array.isArray(value) && seen.has(pathKey) && Array.isArray(target[leaf])) {
|
|
232
|
+
target[leaf] = [...target[leaf], ...value];
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
if (seen.has(pathKey)) {
|
|
236
|
+
throw new UsageError(`${label} 를 두 번 지정했습니다.`);
|
|
237
|
+
}
|
|
238
|
+
target[leaf] = value;
|
|
239
|
+
}
|
|
240
|
+
seen.add(pathKey);
|
|
241
|
+
};
|
|
242
|
+
const schemaAt = (path) => {
|
|
243
|
+
let props = rootProps;
|
|
244
|
+
let schema;
|
|
245
|
+
for (const seg of path) {
|
|
246
|
+
schema = props?.[resolveKey(seg, props)];
|
|
247
|
+
props = propertiesOf(schema);
|
|
248
|
+
}
|
|
249
|
+
return schema;
|
|
250
|
+
};
|
|
251
|
+
let afterDashDash = false;
|
|
252
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
253
|
+
const tok = tokens[i];
|
|
254
|
+
if (tok === '--' && !afterDashDash) {
|
|
255
|
+
afterDashDash = true;
|
|
256
|
+
continue;
|
|
257
|
+
}
|
|
258
|
+
if (!tok.startsWith('--') || tok === '--') {
|
|
259
|
+
positionals.push(tok);
|
|
260
|
+
continue;
|
|
261
|
+
}
|
|
262
|
+
const body = tok.slice(2);
|
|
263
|
+
const eq = body.indexOf('=');
|
|
264
|
+
if (eq >= 0) {
|
|
265
|
+
assign(body.slice(0, eq).split('.'), body.slice(eq + 1));
|
|
266
|
+
continue;
|
|
267
|
+
}
|
|
268
|
+
const path = body.split('.');
|
|
269
|
+
const schema = schemaAt(path);
|
|
270
|
+
const types = schemaTypes(schema);
|
|
271
|
+
const next = tokens[i + 1];
|
|
272
|
+
const nextIsValue = next !== undefined && !next.startsWith('--');
|
|
273
|
+
if (types.has('boolean') && types.size <= 2) {
|
|
274
|
+
// boolean 은 값 없이 켜고, 다음 토큰이 true/false 일 때만 값으로 먹는다.
|
|
275
|
+
if (nextIsValue && /^(true|false)$/i.test(next)) {
|
|
276
|
+
assign(path, next);
|
|
277
|
+
i++;
|
|
278
|
+
}
|
|
279
|
+
else {
|
|
280
|
+
assign(path, true);
|
|
281
|
+
}
|
|
282
|
+
continue;
|
|
283
|
+
}
|
|
284
|
+
if (!schema && path.length === 1 && body.startsWith('no-')) {
|
|
285
|
+
const positive = body.slice(3).split('.');
|
|
286
|
+
const pSchema = schemaAt(positive);
|
|
287
|
+
if (schemaTypes(pSchema).has('boolean')) {
|
|
288
|
+
assign(positive, false);
|
|
289
|
+
continue;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
if (nextIsValue) {
|
|
293
|
+
assign(path, next);
|
|
294
|
+
i++;
|
|
295
|
+
}
|
|
296
|
+
else if (!schema) {
|
|
297
|
+
// 모르는 키 + 값 없음 → 스위치로 본다(서버가 판단)
|
|
298
|
+
assign(path, true);
|
|
299
|
+
}
|
|
300
|
+
else {
|
|
301
|
+
throw new UsageError(`--${body} 에 값이 필요합니다.`);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
// 위치 인자 → 필수 파라미터가 하나뿐일 때 그 자리로
|
|
305
|
+
if (positionals.length > 0) {
|
|
306
|
+
const required = (inputSchema?.required ?? []).filter((k) => !(k in args));
|
|
307
|
+
if (positionals.length === 1 && required.length === 1) {
|
|
308
|
+
assign([required[0]], positionals[0]);
|
|
309
|
+
positionals.length = 0;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
return { args, positionals };
|
|
313
|
+
}
|
|
314
|
+
// ── 사람·에이전트용 표기 ─────────────────────────────────────────────────────
|
|
315
|
+
/** 파라미터 형을 짧게 적는다: string · number · a|b|c · string[] · {startTime?, endTime?} */
|
|
316
|
+
export function typeLabel(schema, depth = 0) {
|
|
317
|
+
if (!schema)
|
|
318
|
+
return 'any';
|
|
319
|
+
if (schema.enum)
|
|
320
|
+
return schema.enum.map((v) => String(v)).join('|');
|
|
321
|
+
if (schema.const !== undefined)
|
|
322
|
+
return JSON.stringify(schema.const);
|
|
323
|
+
const variants = schema.anyOf ?? schema.oneOf;
|
|
324
|
+
if (variants) {
|
|
325
|
+
return [...new Set(variants.map((v) => typeLabel(v, depth)))].join(' | ');
|
|
326
|
+
}
|
|
327
|
+
const types = Array.isArray(schema.type) ? schema.type : schema.type ? [schema.type] : [];
|
|
328
|
+
const parts = types.map((t) => {
|
|
329
|
+
if (t === 'array')
|
|
330
|
+
return `${wrapIfUnion(typeLabel(schema.items, depth + 1))}[]`;
|
|
331
|
+
if (t === 'object') {
|
|
332
|
+
const props = schema.properties;
|
|
333
|
+
if (!props || depth > 1)
|
|
334
|
+
return 'object';
|
|
335
|
+
const req = new Set(schema.required ?? []);
|
|
336
|
+
return `{${Object.entries(props)
|
|
337
|
+
.map(([k, v]) => `${k}${req.has(k) ? '' : '?'}: ${typeLabel(v, depth + 1)}`)
|
|
338
|
+
.join(', ')}}`;
|
|
339
|
+
}
|
|
340
|
+
if (t === 'integer')
|
|
341
|
+
return 'integer';
|
|
342
|
+
return t;
|
|
343
|
+
});
|
|
344
|
+
return parts.length ? parts.join(' | ') : 'any';
|
|
345
|
+
}
|
|
346
|
+
function wrapIfUnion(s) {
|
|
347
|
+
return s.includes(' | ') || s.includes('|') ? `(${s})` : s;
|
|
348
|
+
}
|