claudekit-cli 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (137) hide show
  1. package/.claude/agents/brainstormer.md +96 -0
  2. package/.claude/agents/code-reviewer.md +141 -0
  3. package/.claude/agents/copywriter.md +108 -0
  4. package/.claude/agents/database-admin.md +86 -0
  5. package/.claude/agents/debugger.md +124 -0
  6. package/.claude/agents/docs-manager.md +115 -0
  7. package/.claude/agents/git-manager.md +60 -0
  8. package/.claude/agents/journal-writer.md +111 -0
  9. package/.claude/agents/planner.md +87 -0
  10. package/.claude/agents/project-manager.md +113 -0
  11. package/.claude/agents/researcher.md +173 -0
  12. package/.claude/agents/scout.md +123 -0
  13. package/.claude/agents/tester.md +95 -0
  14. package/.claude/agents/ui-ux-designer.md +206 -0
  15. package/.claude/commands/bootstrap.md +104 -0
  16. package/.claude/commands/brainstorm.md +67 -0
  17. package/.claude/commands/content/enhance.md +13 -0
  18. package/.claude/commands/content/fast.md +11 -0
  19. package/.claude/commands/content/good.md +13 -0
  20. package/.claude/commands/cook.md +19 -0
  21. package/.claude/commands/debug.md +10 -0
  22. package/.claude/commands/design/3d.md +65 -0
  23. package/.claude/commands/design/describe.md +13 -0
  24. package/.claude/commands/design/fast.md +19 -0
  25. package/.claude/commands/design/good.md +23 -0
  26. package/.claude/commands/design/screenshot.md +23 -0
  27. package/.claude/commands/design/video.md +23 -0
  28. package/.claude/commands/docs/init.md +13 -0
  29. package/.claude/commands/docs/summarize.md +10 -0
  30. package/.claude/commands/docs/update.md +21 -0
  31. package/.claude/commands/fix/ci.md +11 -0
  32. package/.claude/commands/fix/fast.md +12 -0
  33. package/.claude/commands/fix/hard.md +18 -0
  34. package/.claude/commands/fix/logs.md +16 -0
  35. package/.claude/commands/fix/test.md +18 -0
  36. package/.claude/commands/fix/types.md +10 -0
  37. package/.claude/commands/git/cm.md +5 -0
  38. package/.claude/commands/git/cp.md +4 -0
  39. package/.claude/commands/integrate/polar.md +42 -0
  40. package/.claude/commands/plan/ci.md +12 -0
  41. package/.claude/commands/plan/two.md +13 -0
  42. package/.claude/commands/plan.md +10 -0
  43. package/.claude/commands/scout.md +29 -0
  44. package/.claude/commands/test.md +7 -0
  45. package/.claude/commands/watzup.md +8 -0
  46. package/.claude/hooks/telegram_notify.sh +136 -0
  47. package/.claude/send-discord.sh +64 -0
  48. package/.claude/settings.json +7 -0
  49. package/.claude/statusline.sh +143 -0
  50. package/.claude/workflows/development-rules.md +80 -0
  51. package/.claude/workflows/documentation-management.md +28 -0
  52. package/.claude/workflows/orchestration-protocol.md +16 -0
  53. package/.claude/workflows/primary-workflow.md +41 -0
  54. package/.github/workflows/ci.yml +43 -0
  55. package/.github/workflows/release.yml +58 -0
  56. package/.opencode/agent/code-reviewer.md +141 -0
  57. package/.opencode/agent/debugger.md +74 -0
  58. package/.opencode/agent/docs-manager.md +119 -0
  59. package/.opencode/agent/git-manager.md +60 -0
  60. package/.opencode/agent/planner-researcher.md +100 -0
  61. package/.opencode/agent/planner.md +87 -0
  62. package/.opencode/agent/project-manager.md +113 -0
  63. package/.opencode/agent/researcher.md +173 -0
  64. package/.opencode/agent/solution-brainstormer.md +89 -0
  65. package/.opencode/agent/system-architecture.md +192 -0
  66. package/.opencode/agent/tester.md +96 -0
  67. package/.opencode/agent/ui-ux-designer.md +203 -0
  68. package/.opencode/agent/ui-ux-developer.md +97 -0
  69. package/.opencode/command/cook.md +7 -0
  70. package/.opencode/command/debug.md +10 -0
  71. package/.opencode/command/design/3d.md +65 -0
  72. package/.opencode/command/design/fast.md +18 -0
  73. package/.opencode/command/design/good.md +21 -0
  74. package/.opencode/command/design/screenshot.md +22 -0
  75. package/.opencode/command/design/video.md +22 -0
  76. package/.opencode/command/docs/init.md +11 -0
  77. package/.opencode/command/docs/summarize.md +10 -0
  78. package/.opencode/command/docs/update.md +18 -0
  79. package/.opencode/command/fix/ci.md +8 -0
  80. package/.opencode/command/fix/fast.md +11 -0
  81. package/.opencode/command/fix/hard.md +15 -0
  82. package/.opencode/command/fix/logs.md +16 -0
  83. package/.opencode/command/fix/test.md +18 -0
  84. package/.opencode/command/fix/types.md +10 -0
  85. package/.opencode/command/git/cm.md +5 -0
  86. package/.opencode/command/git/cp.md +4 -0
  87. package/.opencode/command/plan/ci.md +12 -0
  88. package/.opencode/command/plan/two.md +13 -0
  89. package/.opencode/command/plan.md +10 -0
  90. package/.opencode/command/test.md +7 -0
  91. package/.opencode/command/watzup.md +8 -0
  92. package/.releaserc.json +17 -0
  93. package/.repomixignore +15 -0
  94. package/AGENTS.md +217 -0
  95. package/CHANGELOG.md +16 -0
  96. package/CLAUDE.md +33 -0
  97. package/README.md +214 -0
  98. package/biome.json +25 -0
  99. package/bun.lock +1238 -0
  100. package/dist/index.js +19100 -0
  101. package/docs/code-standards.md +1128 -0
  102. package/docs/codebase-summary.md +821 -0
  103. package/docs/github-setup.md +176 -0
  104. package/docs/project-pdr.md +739 -0
  105. package/docs/system-architecture.md +950 -0
  106. package/docs/tech-stack.md +290 -0
  107. package/package.json +60 -0
  108. package/plans/251008-claudekit-cli-implementation-plan.md +1469 -0
  109. package/plans/reports/251008-from-code-reviewer-to-developer-review-report.md +864 -0
  110. package/plans/reports/251008-from-tester-to-developer-test-summary-report.md +409 -0
  111. package/plans/reports/251008-researcher-download-extraction-report.md +1377 -0
  112. package/plans/reports/251008-researcher-github-api-report.md +1339 -0
  113. package/plans/research/251008-cli-frameworks-bun-research.md +1051 -0
  114. package/plans/templates/bug-fix-template.md +69 -0
  115. package/plans/templates/feature-implementation-template.md +84 -0
  116. package/plans/templates/refactor-template.md +82 -0
  117. package/plans/templates/template-usage-guide.md +58 -0
  118. package/src/commands/new.ts +118 -0
  119. package/src/commands/update.ts +114 -0
  120. package/src/index.ts +44 -0
  121. package/src/lib/auth.ts +157 -0
  122. package/src/lib/download.ts +180 -0
  123. package/src/lib/github.ts +157 -0
  124. package/src/lib/merge.ts +116 -0
  125. package/src/lib/prompts.ts +113 -0
  126. package/src/types.ts +149 -0
  127. package/src/utils/config.ts +87 -0
  128. package/src/utils/logger.ts +37 -0
  129. package/tests/lib/auth.test.ts +116 -0
  130. package/tests/lib/download.test.ts +70 -0
  131. package/tests/lib/github.test.ts +52 -0
  132. package/tests/lib/merge.test.ts +138 -0
  133. package/tests/lib/prompts.test.ts +66 -0
  134. package/tests/types.test.ts +255 -0
  135. package/tests/utils/config.test.ts +263 -0
  136. package/tests/utils/logger.test.ts +124 -0
  137. package/tsconfig.json +30 -0
@@ -0,0 +1,950 @@
1
+ # System Architecture
2
+ # ClaudeKit CLI
3
+
4
+ **Version:** 1.0
5
+ **Date:** 2025-10-08
6
+ **Status:** Production Ready
7
+ **Runtime:** Bun v1.x+
8
+ **Language:** TypeScript 5.x+
9
+
10
+ ---
11
+
12
+ ## Table of Contents
13
+
14
+ 1. [Architecture Overview](#architecture-overview)
15
+ 2. [Component Architecture](#component-architecture)
16
+ 3. [Data Flow Diagrams](#data-flow-diagrams)
17
+ 4. [Authentication Flow](#authentication-flow)
18
+ 5. [Download and Extraction Flow](#download-and-extraction-flow)
19
+ 6. [File Merging Flow](#file-merging-flow)
20
+ 7. [Technology Stack](#technology-stack)
21
+ 8. [Module Dependencies](#module-dependencies)
22
+ 9. [Error Handling Architecture](#error-handling-architecture)
23
+ 10. [Security Architecture](#security-architecture)
24
+
25
+ ---
26
+
27
+ ## Architecture Overview
28
+
29
+ ### High-Level Architecture
30
+
31
+ ```mermaid
32
+ graph TB
33
+ User[User] -->|Commands| CLI[CLI Entry Point]
34
+ CLI --> Parser[CAC Command Parser]
35
+
36
+ Parser --> NewCmd[New Command]
37
+ Parser --> UpdateCmd[Update Command]
38
+ Parser --> HelpCmd[Help/Version]
39
+
40
+ NewCmd --> Auth[Auth Manager]
41
+ UpdateCmd --> Auth
42
+
43
+ Auth --> GH[GitHub Client]
44
+ GH --> DL[Download Manager]
45
+ DL --> Extract[Archive Extractor]
46
+ Extract --> Merge[File Merger]
47
+
48
+ Merge --> FS[File System]
49
+
50
+ Config[Config Manager] -.->|Config| Auth
51
+ Config -.->|Config| GH
52
+ Logger[Logger] -.->|Logging| All[All Components]
53
+
54
+ style CLI fill:#e1f5ff
55
+ style Auth fill:#ffe1e1
56
+ style GH fill:#e1ffe1
57
+ style Merge fill:#fff5e1
58
+ ```
59
+
60
+ ### Layered Architecture
61
+
62
+ ```mermaid
63
+ graph TD
64
+ subgraph "Presentation Layer"
65
+ CLI[CLI Interface]
66
+ Prompts[Interactive Prompts]
67
+ Output[Colored Output]
68
+ end
69
+
70
+ subgraph "Application Layer"
71
+ NewCommand[New Command Handler]
72
+ UpdateCommand[Update Command Handler]
73
+ end
74
+
75
+ subgraph "Business Logic Layer"
76
+ Auth[Authentication Manager]
77
+ GitHub[GitHub Client]
78
+ Download[Download Manager]
79
+ Merge[File Merger]
80
+ end
81
+
82
+ subgraph "Data Layer"
83
+ Config[Configuration Storage]
84
+ Keychain[OS Keychain]
85
+ TempFiles[Temporary Files]
86
+ FileSystem[Target File System]
87
+ end
88
+
89
+ subgraph "Infrastructure Layer"
90
+ Logger[Logger Utility]
91
+ Validation[Zod Validation]
92
+ ErrorHandler[Error Handler]
93
+ end
94
+
95
+ CLI --> NewCommand
96
+ CLI --> UpdateCommand
97
+ NewCommand --> Auth
98
+ UpdateCommand --> Auth
99
+ Auth --> Config
100
+ Auth --> Keychain
101
+ GitHub --> Download
102
+ Download --> TempFiles
103
+ Merge --> FileSystem
104
+
105
+ Logger -.-> All
106
+ Validation -.-> All
107
+ ErrorHandler -.-> All
108
+
109
+ style CLI fill:#e1f5ff
110
+ style Auth fill:#ffe1e1
111
+ style GitHub fill:#e1ffe1
112
+ style Merge fill:#fff5e1
113
+ ```
114
+
115
+ ---
116
+
117
+ ## Component Architecture
118
+
119
+ ### Core Components
120
+
121
+ ```mermaid
122
+ graph LR
123
+ subgraph "Commands"
124
+ New[new.ts]
125
+ Update[update.ts]
126
+ end
127
+
128
+ subgraph "Libraries"
129
+ Auth[auth.ts]
130
+ GitHub[github.ts]
131
+ Download[download.ts]
132
+ Merge[merge.ts]
133
+ Prompts[prompts.ts]
134
+ end
135
+
136
+ subgraph "Utilities"
137
+ Config[config.ts]
138
+ Logger[logger.ts]
139
+ end
140
+
141
+ subgraph "Core"
142
+ Types[types.ts]
143
+ Index[index.ts]
144
+ end
145
+
146
+ Index --> New
147
+ Index --> Update
148
+
149
+ New --> Auth
150
+ New --> GitHub
151
+ New --> Download
152
+ New --> Merge
153
+ New --> Prompts
154
+
155
+ Update --> Auth
156
+ Update --> GitHub
157
+ Update --> Download
158
+ Update --> Merge
159
+ Update --> Prompts
160
+
161
+ Auth --> Config
162
+ Auth --> Logger
163
+ GitHub --> Logger
164
+ Download --> Logger
165
+ Merge --> Logger
166
+
167
+ All --> Types
168
+
169
+ style Index fill:#e1f5ff
170
+ style Auth fill:#ffe1e1
171
+ style GitHub fill:#e1ffe1
172
+ style Merge fill:#fff5e1
173
+ ```
174
+
175
+ ### Module Responsibilities
176
+
177
+ | Module | Responsibility | Size | Status |
178
+ |--------|---------------|------|--------|
179
+ | **index.ts** | CLI entry point, command routing | 47 lines | ✅ Complete |
180
+ | **types.ts** | Type definitions, Zod schemas, error classes | 146 lines | ✅ Complete |
181
+ | **auth.ts** | Multi-tier authentication, token management | 152 lines | ✅ Complete |
182
+ | **github.ts** | GitHub API client, release fetching | 149 lines | ✅ Complete |
183
+ | **download.ts** | Streaming downloads, progress tracking | 178 lines | ✅ Complete |
184
+ | **merge.ts** | File merging, conflict detection | 117 lines | ✅ Complete |
185
+ | **prompts.ts** | Interactive user prompts | 114 lines | ✅ Complete |
186
+ | **config.ts** | Configuration management | 84 lines | ✅ Complete |
187
+ | **logger.ts** | Logging with sanitization | 38 lines | ✅ Complete |
188
+ | **new.ts** | New project command | 118 lines | ✅ Complete |
189
+ | **update.ts** | Update project command | 115 lines | ✅ Complete |
190
+
191
+ ---
192
+
193
+ ## Data Flow Diagrams
194
+
195
+ ### New Project Flow
196
+
197
+ ```mermaid
198
+ sequenceDiagram
199
+ participant User
200
+ participant CLI
201
+ participant New
202
+ participant Auth
203
+ participant GitHub
204
+ participant Download
205
+ participant Extract
206
+ participant Merge
207
+ participant FS
208
+
209
+ User->>CLI: ck new --kit engineer
210
+ CLI->>New: execute(options)
211
+
212
+ New->>Auth: getToken()
213
+ Auth->>Auth: Try gh CLI
214
+ Auth->>Auth: Try env vars
215
+ Auth->>Auth: Try keychain
216
+ Auth-->>User: Prompt for token
217
+ User-->>Auth: Enter token
218
+ Auth->>Auth: Validate & store
219
+ Auth-->>New: Return token
220
+
221
+ New->>GitHub: getLatestRelease(kit)
222
+ GitHub->>GitHub: Fetch from API
223
+ GitHub-->>New: Return release data
224
+
225
+ New->>Download: downloadAsset(asset)
226
+ Download->>Download: Create temp dir
227
+ Download->>Download: Stream download
228
+ Download-->>User: Show progress
229
+ Download-->>New: Return archive path
230
+
231
+ New->>Extract: extractArchive(path)
232
+ Extract->>Extract: Detect format
233
+ Extract->>Extract: Extract files
234
+ Extract-->>User: Show progress
235
+ Extract-->>New: Return extracted dir
236
+
237
+ New->>Merge: merge(source, target)
238
+ Merge->>Merge: Scan files
239
+ Merge->>Merge: Check protected
240
+ Merge->>Merge: Copy files
241
+ Merge-->>FS: Write files
242
+ Merge-->>User: Show summary
243
+ Merge-->>New: Return result
244
+
245
+ New-->>User: ✨ Success! Next steps...
246
+ ```
247
+
248
+ ### Update Project Flow
249
+
250
+ ```mermaid
251
+ sequenceDiagram
252
+ participant User
253
+ participant CLI
254
+ participant Update
255
+ participant Auth
256
+ participant GitHub
257
+ participant Download
258
+ participant Extract
259
+ participant Merge
260
+ participant FS
261
+
262
+ User->>CLI: ck update
263
+ CLI->>Update: execute(options)
264
+
265
+ Update->>FS: Check directory exists
266
+ FS-->>Update: Exists ✓
267
+
268
+ Update->>Auth: getToken()
269
+ Auth-->>Update: Return cached token
270
+
271
+ Update->>GitHub: getLatestRelease(kit)
272
+ GitHub-->>Update: Return release
273
+
274
+ Update->>Merge: detectConflicts()
275
+ Merge->>FS: Scan existing files
276
+ Merge-->>Update: Return conflicts
277
+
278
+ Update-->>User: Show conflicts
279
+ Update-->>User: Confirm update? (y/n)
280
+ User-->>Update: yes
281
+
282
+ Update->>Download: downloadAsset(asset)
283
+ Download-->>User: Show progress
284
+ Download-->>Update: Return path
285
+
286
+ Update->>Extract: extractArchive(path)
287
+ Extract-->>Update: Return extracted dir
288
+
289
+ Update->>Merge: merge(source, target, false)
290
+ Merge->>Merge: Skip protected files
291
+ Merge->>Merge: Overwrite others
292
+ Merge-->>FS: Write files
293
+ Merge-->>Update: Return summary
294
+
295
+ Update-->>User: ✅ Updated! (X files, Y skipped)
296
+ ```
297
+
298
+ ---
299
+
300
+ ## Authentication Flow
301
+
302
+ ### Multi-Tier Fallback
303
+
304
+ ```mermaid
305
+ graph TD
306
+ Start[Start Authentication] --> CheckGH{GitHub CLI<br/>Installed?}
307
+
308
+ CheckGH -->|Yes| TryGH[Execute gh auth token]
309
+ CheckGH -->|No| CheckEnv
310
+
311
+ TryGH -->|Success| ValidateGH{Token Valid?}
312
+ TryGH -->|Fail| CheckEnv
313
+
314
+ ValidateGH -->|Yes| ReturnGH[Return token<br/>method: gh-cli]
315
+ ValidateGH -->|No| CheckEnv
316
+
317
+ CheckEnv{Env Var<br/>Set?} -->|Yes| ValidateEnv{Token Valid?}
318
+ CheckEnv -->|No| CheckConfig
319
+
320
+ ValidateEnv -->|Yes| ReturnEnv[Return token<br/>method: env-var]
321
+ ValidateEnv -->|No| CheckConfig
322
+
323
+ CheckConfig{Config<br/>Has Token?} -->|Yes| ValidateConfig{Token Valid?}
324
+ CheckConfig -->|No| CheckKeychain
325
+
326
+ ValidateConfig -->|Yes| ReturnConfig[Return token<br/>method: env-var]
327
+ ValidateConfig -->|No| CheckKeychain
328
+
329
+ CheckKeychain{Keychain<br/>Has Token?} -->|Yes| ValidateKeychain{Token Valid?}
330
+ CheckKeychain -->|No| Prompt
331
+
332
+ ValidateKeychain -->|Yes| ReturnKeychain[Return token<br/>method: keychain]
333
+ ValidateKeychain -->|No| DeleteKeychain[Delete invalid token]
334
+ DeleteKeychain --> Prompt
335
+
336
+ Prompt[Prompt User] --> UserInput{User Enters<br/>Token}
337
+
338
+ UserInput -->|Valid| AskSave{Save Token?}
339
+ UserInput -->|Invalid| ShowError[Show Error]
340
+ ShowError --> Prompt
341
+
342
+ AskSave -->|Yes| SaveKeychain[Save to Keychain]
343
+ AskSave -->|No| ReturnPrompt
344
+
345
+ SaveKeychain --> ReturnPrompt[Return token<br/>method: prompt]
346
+
347
+ ReturnGH --> End[Authenticated ✓]
348
+ ReturnEnv --> End
349
+ ReturnConfig --> End
350
+ ReturnKeychain --> End
351
+ ReturnPrompt --> End
352
+
353
+ style Start fill:#e1f5ff
354
+ style End fill:#e1ffe1
355
+ style Prompt fill:#fff5e1
356
+ style ValidateGH fill:#ffe1e1
357
+ style ValidateEnv fill:#ffe1e1
358
+ style ValidateConfig fill:#ffe1e1
359
+ style ValidateKeychain fill:#ffe1e1
360
+ ```
361
+
362
+ ### Token Validation Flow
363
+
364
+ ```mermaid
365
+ graph LR
366
+ Token[Token String] --> Format{Format<br/>Valid?}
367
+
368
+ Format -->|No| Invalid[Reject:<br/>Invalid format]
369
+ Format -->|Yes| Type{Token Type?}
370
+
371
+ Type -->|ghp_| Classic[Classic PAT<br/>36 chars]
372
+ Type -->|github_pat_| FineGrained[Fine-grained PAT<br/>82 chars]
373
+ Type -->|gho_| OAuth[OAuth Token]
374
+ Type -->|Other| Invalid
375
+
376
+ Classic --> Length{Length OK?}
377
+ FineGrained --> Length
378
+ OAuth --> Length
379
+
380
+ Length -->|No| Invalid
381
+ Length -->|Yes| APITest[Test with<br/>GitHub API]
382
+
383
+ APITest -->|200 OK| Valid[Accept:<br/>Token valid ✓]
384
+ APITest -->|401| Invalid
385
+ APITest -->|403| RateLimit[Rate limited]
386
+
387
+ style Token fill:#e1f5ff
388
+ style Valid fill:#e1ffe1
389
+ style Invalid fill:#ffe1e1
390
+ style RateLimit fill:#fff5e1
391
+ ```
392
+
393
+ ---
394
+
395
+ ## Download and Extraction Flow
396
+
397
+ ### Download Process
398
+
399
+ ```mermaid
400
+ graph TD
401
+ Start[Start Download] --> CreateTemp[Create Temp Directory]
402
+ CreateTemp --> InitProgress[Initialize Progress Bar]
403
+
404
+ InitProgress --> Fetch[Fetch Asset URL]
405
+ Fetch -->|Headers| GetSize[Get Content-Length]
406
+ GetSize --> StartStream[Start Stream]
407
+
408
+ StartStream --> ReadChunk{Read Chunk}
409
+ ReadChunk -->|Data| WriteChunk[Write to File]
410
+ WriteChunk --> UpdateProgress[Update Progress Bar]
411
+ UpdateProgress --> ReadChunk
412
+
413
+ ReadChunk -->|Done| CloseStream[Close Stream]
414
+ CloseStream --> Verify{Verify<br/>Complete?}
415
+
416
+ Verify -->|Yes| Success[Return File Path]
417
+ Verify -->|No| Error[Throw DownloadError]
418
+
419
+ Fetch -->|Error| Retry{Retry<br/>Count < 3?}
420
+ Retry -->|Yes| Wait[Wait with<br/>Backoff]
421
+ Wait --> Fetch
422
+ Retry -->|No| Error
423
+
424
+ Error --> Cleanup[Cleanup Temp Files]
425
+ Cleanup --> Fail[Throw Error]
426
+
427
+ style Start fill:#e1f5ff
428
+ style Success fill:#e1ffe1
429
+ style Error fill:#ffe1e1
430
+ style Retry fill:#fff5e1
431
+ ```
432
+
433
+ ### Archive Extraction
434
+
435
+ ```mermaid
436
+ graph TD
437
+ Start[Archive File] --> Detect{Detect Format}
438
+
439
+ Detect -->|.tar.gz| UseTar[Use tar library]
440
+ Detect -->|.zip| UseUnzip[Use unzipper]
441
+ Detect -->|Unknown| Error[Throw ExtractionError]
442
+
443
+ UseTar --> ExtractTar[Extract with Streaming]
444
+ UseUnzip --> ExtractZip[Extract with Streaming]
445
+
446
+ ExtractTar --> Strip[Strip Top-Level Dir]
447
+ ExtractZip --> Strip
448
+
449
+ Strip --> CheckPath{Path Safe?}
450
+
451
+ CheckPath -->|No| Skip[Skip File<br/>Log Warning]
452
+ CheckPath -->|Yes| Write[Write to Disk]
453
+
454
+ Write --> Count[Increment Counter]
455
+ Skip --> Count
456
+
457
+ Count --> More{More Files?}
458
+ More -->|Yes| CheckPath
459
+ More -->|No| Complete[Extraction Complete]
460
+
461
+ Complete --> CleanupArchive[Delete Archive]
462
+ CleanupArchive --> Success[Return Extracted Dir]
463
+
464
+ Error --> Cleanup[Cleanup Temp Dir]
465
+ Cleanup --> Fail[Throw Error]
466
+
467
+ style Start fill:#e1f5ff
468
+ style Success fill:#e1ffe1
469
+ style Error fill:#ffe1e1
470
+ style CheckPath fill:#fff5e1
471
+ ```
472
+
473
+ ---
474
+
475
+ ## File Merging Flow
476
+
477
+ ### Conflict Detection
478
+
479
+ ```mermaid
480
+ graph TD
481
+ Start[Start Merge] --> Scan[Scan Source Files]
482
+
483
+ Scan --> CheckFile{For Each File}
484
+
485
+ CheckFile --> CheckProtected{Protected<br/>Pattern?}
486
+
487
+ CheckProtected -->|Yes| DestExists{Exists in<br/>Dest?}
488
+ CheckProtected -->|No| DestExists
489
+
490
+ DestExists -->|Yes + Protected| AddSkip[Add to Skip List]
491
+ DestExists -->|Yes + Not Protected| AddConflict[Add to Conflict List]
492
+ DestExists -->|No| AddNew[Add to New List]
493
+
494
+ AddSkip --> NextFile{More Files?}
495
+ AddConflict --> NextFile
496
+ AddNew --> NextFile
497
+
498
+ NextFile -->|Yes| CheckFile
499
+ NextFile -->|No| ShowSummary[Show Summary]
500
+
501
+ ShowSummary --> HasConflicts{Conflicts<br/>Found?}
502
+
503
+ HasConflicts -->|Yes| Confirm{User<br/>Confirms?}
504
+ HasConflicts -->|No| Proceed
505
+
506
+ Confirm -->|Yes| Proceed[Proceed with Merge]
507
+ Confirm -->|No| Cancel[Cancel Operation]
508
+
509
+ Proceed --> CopyFiles[Copy Files]
510
+ CopyFiles --> Complete[Merge Complete]
511
+
512
+ style Start fill:#e1f5ff
513
+ style Complete fill:#e1ffe1
514
+ style Cancel fill:#ffe1e1
515
+ style CheckProtected fill:#fff5e1
516
+ ```
517
+
518
+ ### Protected File Patterns
519
+
520
+ ```mermaid
521
+ graph LR
522
+ subgraph "Environment Files"
523
+ ENV[.env<br/>.env.local<br/>.env.*.local]
524
+ end
525
+
526
+ subgraph "Security Keys"
527
+ KEYS[*.key<br/>*.pem<br/>*.p12]
528
+ end
529
+
530
+ subgraph "Build Output"
531
+ BUILD[node_modules/**<br/>dist/**<br/>build/**]
532
+ end
533
+
534
+ subgraph "Version Control"
535
+ VCS[.git/**<br/>.gitignore]
536
+ end
537
+
538
+ subgraph "Lock Files"
539
+ LOCK[bun.lockb<br/>package-lock.json]
540
+ end
541
+
542
+ File[File to Merge] --> Check{Matches Pattern?}
543
+
544
+ ENV -.-> Check
545
+ KEYS -.-> Check
546
+ BUILD -.-> Check
547
+ VCS -.-> Check
548
+ LOCK -.-> Check
549
+
550
+ Check -->|Yes| Skip[Skip File]
551
+ Check -->|No| Copy[Copy/Overwrite]
552
+
553
+ style Skip fill:#ffe1e1
554
+ style Copy fill:#e1ffe1
555
+ ```
556
+
557
+ ---
558
+
559
+ ## Technology Stack
560
+
561
+ ### Runtime and Language
562
+
563
+ ```mermaid
564
+ graph TB
565
+ subgraph "Runtime Layer"
566
+ Bun[Bun v1.x+<br/>Fast JavaScript Runtime]
567
+ Node[Node.js APIs<br/>Compatible]
568
+ end
569
+
570
+ subgraph "Language Layer"
571
+ TS[TypeScript 5.x+<br/>Strict Mode]
572
+ ES[ES2022+<br/>Modern JavaScript]
573
+ end
574
+
575
+ subgraph "Type Safety Layer"
576
+ Zod[Zod v3.x<br/>Runtime Validation]
577
+ Types[TypeScript Types<br/>Compile-time]
578
+ end
579
+
580
+ Bun --> Node
581
+ TS --> ES
582
+ ES --> Bun
583
+ Zod --> TS
584
+ Types --> TS
585
+
586
+ style Bun fill:#e1f5ff
587
+ style TS fill:#e1ffe1
588
+ style Zod fill:#fff5e1
589
+ ```
590
+
591
+ ### Core Dependencies
592
+
593
+ ```mermaid
594
+ graph TB
595
+ subgraph "CLI Framework"
596
+ CAC[cac<br/>Command Parser]
597
+ Clack[clack/prompts<br/>Interactive Prompts]
598
+ Ora[ora<br/>Spinners]
599
+ Progress[cli-progress<br/>Progress Bars]
600
+ Colors[picocolors<br/>Colors]
601
+ end
602
+
603
+ subgraph "GitHub Integration"
604
+ Octokit[octokit/rest<br/>GitHub API]
605
+ Keytar[keytar<br/>Credential Storage]
606
+ end
607
+
608
+ subgraph "File Operations"
609
+ FSExtra[fs-extra<br/>File System]
610
+ Tar[tar<br/>TAR Extraction]
611
+ Unzipper[unzipper<br/>ZIP Extraction]
612
+ Ignore[ignore<br/>Pattern Matching]
613
+ Tmp[tmp<br/>Temp Files]
614
+ end
615
+
616
+ subgraph "Validation"
617
+ Zod[zod<br/>Schema Validation]
618
+ end
619
+
620
+ App[ClaudeKit CLI] --> CAC
621
+ App --> Clack
622
+ App --> Ora
623
+ App --> Progress
624
+ App --> Colors
625
+ App --> Octokit
626
+ App --> Keytar
627
+ App --> FSExtra
628
+ App --> Tar
629
+ App --> Unzipper
630
+ App --> Ignore
631
+ App --> Tmp
632
+ App --> Zod
633
+
634
+ style App fill:#e1f5ff
635
+ style Octokit fill:#e1ffe1
636
+ style Zod fill:#fff5e1
637
+ ```
638
+
639
+ ---
640
+
641
+ ## Module Dependencies
642
+
643
+ ### Dependency Graph
644
+
645
+ ```mermaid
646
+ graph TD
647
+ Index[index.ts] --> NewCmd[commands/new.ts]
648
+ Index --> UpdateCmd[commands/update.ts]
649
+
650
+ NewCmd --> Auth[lib/auth.ts]
651
+ NewCmd --> GitHub[lib/github.ts]
652
+ NewCmd --> Download[lib/download.ts]
653
+ NewCmd --> Merge[lib/merge.ts]
654
+ NewCmd --> Prompts[lib/prompts.ts]
655
+
656
+ UpdateCmd --> Auth
657
+ UpdateCmd --> GitHub
658
+ UpdateCmd --> Download
659
+ UpdateCmd --> Merge
660
+ UpdateCmd --> Prompts
661
+
662
+ Auth --> Config[utils/config.ts]
663
+ Auth --> Logger[utils/logger.ts]
664
+ Auth --> Types[types.ts]
665
+
666
+ GitHub --> Logger
667
+ GitHub --> Types
668
+
669
+ Download --> Logger
670
+ Download --> Types
671
+
672
+ Merge --> Logger
673
+ Merge --> Types
674
+
675
+ Prompts --> Types
676
+
677
+ Config --> Types
678
+ Logger --> Types
679
+
680
+ style Index fill:#e1f5ff
681
+ style Types fill:#fff5e1
682
+ style Auth fill:#ffe1e1
683
+ style GitHub fill:#e1ffe1
684
+ ```
685
+
686
+ ### Import Hierarchy
687
+
688
+ **Level 1 (No Dependencies):**
689
+ - `types.ts` - Pure type definitions
690
+
691
+ **Level 2 (Depends on Level 1):**
692
+ - `utils/logger.ts` - Logging utility
693
+ - `utils/config.ts` - Configuration management
694
+
695
+ **Level 3 (Depends on Level 1-2):**
696
+ - `lib/auth.ts` - Authentication
697
+ - `lib/github.ts` - GitHub client
698
+ - `lib/download.ts` - Downloads
699
+ - `lib/merge.ts` - File merging
700
+ - `lib/prompts.ts` - User prompts
701
+
702
+ **Level 4 (Depends on Level 1-3):**
703
+ - `commands/new.ts` - New command
704
+ - `commands/update.ts` - Update command
705
+
706
+ **Level 5 (Entry Point):**
707
+ - `index.ts` - CLI entry point
708
+
709
+ ---
710
+
711
+ ## Error Handling Architecture
712
+
713
+ ### Error Class Hierarchy
714
+
715
+ ```mermaid
716
+ graph TD
717
+ Error[JavaScript Error] --> CKError[ClaudeKitError]
718
+
719
+ CKError --> AuthError[AuthenticationError<br/>code: AUTH_ERROR<br/>status: 401]
720
+ CKError --> GitHubError[GitHubError<br/>code: GITHUB_ERROR<br/>status: varies]
721
+ CKError --> DownloadError[DownloadError<br/>code: DOWNLOAD_ERROR<br/>status: varies]
722
+ CKError --> ExtractionError[ExtractionError<br/>code: EXTRACTION_ERROR<br/>status: varies]
723
+
724
+ GitHubError --> GH404[404: Not Found]
725
+ GitHubError --> GH401[401: Unauthorized]
726
+ GitHubError --> GH403[403: Rate Limited]
727
+
728
+ DownloadError --> DLNetwork[Network Error]
729
+ DownloadError --> DLTimeout[Timeout Error]
730
+
731
+ ExtractionError --> EXFormat[Invalid Format]
732
+ ExtractionError --> EXCorrupt[Corrupted Archive]
733
+
734
+ style Error fill:#e1f5ff
735
+ style CKError fill:#fff5e1
736
+ style AuthError fill:#ffe1e1
737
+ style GitHubError fill:#ffe1e1
738
+ style DownloadError fill:#ffe1e1
739
+ style ExtractionError fill:#ffe1e1
740
+ ```
741
+
742
+ ### Error Recovery Strategy
743
+
744
+ ```mermaid
745
+ graph TD
746
+ Operation[Operation Fails] --> Type{Error Type?}
747
+
748
+ Type -->|Network| Retry{Retry<br/>Count < 3?}
749
+ Type -->|Auth| ClearToken[Clear Invalid Token]
750
+ Type -->|Rate Limit| Wait[Wait for Reset]
751
+ Type -->|Fatal| Cleanup
752
+
753
+ Retry -->|Yes| Backoff[Exponential Backoff]
754
+ Retry -->|No| Cleanup
755
+
756
+ Backoff --> Operation
757
+
758
+ ClearToken --> Prompt[Re-prompt User]
759
+ Prompt --> Operation
760
+
761
+ Wait --> WaitTime[Sleep Until Reset]
762
+ WaitTime --> Operation
763
+
764
+ Cleanup[Cleanup Resources] --> Log[Log Error]
765
+ Log --> Exit[Exit with Code]
766
+
767
+ style Operation fill:#e1f5ff
768
+ style Exit fill:#ffe1e1
769
+ style Retry fill:#fff5e1
770
+ ```
771
+
772
+ ---
773
+
774
+ ## Security Architecture
775
+
776
+ ### Token Security
777
+
778
+ ```mermaid
779
+ graph TB
780
+ subgraph "Token Sources"
781
+ GHCLI[GitHub CLI]
782
+ EnvVar[Environment Variable]
783
+ Keychain[OS Keychain]
784
+ UserInput[User Input]
785
+ end
786
+
787
+ subgraph "Validation"
788
+ Format[Format Check]
789
+ API[API Verification]
790
+ end
791
+
792
+ subgraph "Storage"
793
+ Memory[In-Memory Cache]
794
+ SecureStore[Keychain Storage]
795
+ end
796
+
797
+ subgraph "Usage"
798
+ HTTPHeader[HTTP Authorization Header]
799
+ end
800
+
801
+ subgraph "Protection"
802
+ Sanitize[Log Sanitization]
803
+ NoPlaintext[No Plaintext Files]
804
+ end
805
+
806
+ GHCLI --> Format
807
+ EnvVar --> Format
808
+ Keychain --> Format
809
+ UserInput --> Format
810
+
811
+ Format --> API
812
+ API --> Memory
813
+ API --> SecureStore
814
+
815
+ Memory --> HTTPHeader
816
+
817
+ HTTPHeader -.-> Sanitize
818
+ SecureStore -.-> NoPlaintext
819
+
820
+ style SecureStore fill:#e1ffe1
821
+ style Sanitize fill:#fff5e1
822
+ style NoPlaintext fill:#fff5e1
823
+ ```
824
+
825
+ ### Data Flow Security
826
+
827
+ ```mermaid
828
+ graph LR
829
+ subgraph "External Sources"
830
+ User[User Input]
831
+ API[GitHub API]
832
+ Download[Downloaded Files]
833
+ end
834
+
835
+ subgraph "Validation Layer"
836
+ ZodUser[Zod Validation]
837
+ ZodAPI[Schema Validation]
838
+ PathCheck[Path Traversal Check]
839
+ end
840
+
841
+ subgraph "Application"
842
+ App[Application Logic]
843
+ end
844
+
845
+ User -->|Input| ZodUser
846
+ API -->|Response| ZodAPI
847
+ Download -->|Files| PathCheck
848
+
849
+ ZodUser -->|Validated| App
850
+ ZodAPI -->|Validated| App
851
+ PathCheck -->|Safe Paths| App
852
+
853
+ style ZodUser fill:#e1ffe1
854
+ style ZodAPI fill:#e1ffe1
855
+ style PathCheck fill:#e1ffe1
856
+ ```
857
+
858
+ ---
859
+
860
+ ## Performance Characteristics
861
+
862
+ ### Memory Profile
863
+
864
+ ```mermaid
865
+ graph TB
866
+ Start[Application Start<br/>~10MB] --> Auth[Authentication<br/>+2MB]
867
+ Auth --> GitHub[GitHub API Call<br/>+5MB]
868
+ GitHub --> Download[Download Stream<br/>+20MB peak]
869
+ Download --> Extract[Extraction<br/>+30MB peak]
870
+ Extract --> Merge[File Merge<br/>+10MB]
871
+ Merge --> Complete[Complete<br/>~10MB]
872
+
873
+ style Start fill:#e1f5ff
874
+ style Download fill:#fff5e1
875
+ style Extract fill:#fff5e1
876
+ style Complete fill:#e1ffe1
877
+ ```
878
+
879
+ ### Execution Timeline
880
+
881
+ ```mermaid
882
+ gantt
883
+ title ClaudeKit CLI Execution Timeline (New Project)
884
+ dateFormat X
885
+ axisFormat %S.%Ls
886
+
887
+ section Startup
888
+ CLI Init :0, 100ms
889
+ Parse Args :100, 50ms
890
+
891
+ section Auth
892
+ Detect gh CLI :150, 200ms
893
+ Token Validation :350, 100ms
894
+
895
+ section GitHub
896
+ API Request :450, 300ms
897
+ Parse Response :750, 50ms
898
+
899
+ section Download
900
+ Fetch Asset :800, 5000ms
901
+ Progress Tracking :800, 5000ms
902
+
903
+ section Extract
904
+ Decompress :5800, 2000ms
905
+ Write Files :7800, 1000ms
906
+
907
+ section Merge
908
+ Scan & Copy :8800, 1000ms
909
+
910
+ section Complete
911
+ Cleanup & Summary :9800, 200ms
912
+ ```
913
+
914
+ ---
915
+
916
+ ## Deployment Architecture
917
+
918
+ ### Distribution Methods
919
+
920
+ ```mermaid
921
+ graph TB
922
+ Source[Source Code] --> Build{Build Method}
923
+
924
+ Build -->|bun build| Transpile[Transpiled JS]
925
+ Build -->|bun build --compile| Binary[Standalone Binary]
926
+
927
+ Transpile --> NPM[npm Registry]
928
+ Binary --> Releases[GitHub Releases]
929
+
930
+ NPM --> InstallNPM[bun add -g claudekit-cli]
931
+ Releases --> InstallBinary[Download & Install]
932
+
933
+ InstallNPM --> User1[User Machine]
934
+ InstallBinary --> User2[User Machine]
935
+
936
+ User1 --> Execute[ck command]
937
+ User2 --> Execute
938
+
939
+ style Source fill:#e1f5ff
940
+ style Execute fill:#e1ffe1
941
+ style NPM fill:#fff5e1
942
+ style Releases fill:#fff5e1
943
+ ```
944
+
945
+ ---
946
+
947
+ **Document Version:** 1.0
948
+ **Last Updated:** 2025-10-08
949
+ **Status:** Production Ready
950
+ **Next Review:** 2025-11-08