create-theokit 1.2.9 → 1.3.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 (25) hide show
  1. package/LICENSE +201 -0
  2. package/dist/cli.js +3 -1
  3. package/dist/cli.js.map +1 -1
  4. package/package.json +7 -7
  5. package/templates/default/app/page.tsx +3 -1
  6. package/templates/surfaces/desktop/README-surface.md.tmpl +20 -6
  7. package/templates/surfaces/desktop/scripts/build-sidecar.mjs +66 -0
  8. package/templates/surfaces/desktop/src-tauri/icons/128x128.png +0 -0
  9. package/templates/surfaces/desktop/src-tauri/icons/128x128@2x.png +0 -0
  10. package/templates/surfaces/desktop/src-tauri/icons/32x32.png +0 -0
  11. package/templates/surfaces/desktop/src-tauri/icons/64x64.png +0 -0
  12. package/templates/surfaces/desktop/src-tauri/icons/Square107x107Logo.png +0 -0
  13. package/templates/surfaces/desktop/src-tauri/icons/Square142x142Logo.png +0 -0
  14. package/templates/surfaces/desktop/src-tauri/icons/Square150x150Logo.png +0 -0
  15. package/templates/surfaces/desktop/src-tauri/icons/Square284x284Logo.png +0 -0
  16. package/templates/surfaces/desktop/src-tauri/icons/Square30x30Logo.png +0 -0
  17. package/templates/surfaces/desktop/src-tauri/icons/Square310x310Logo.png +0 -0
  18. package/templates/surfaces/desktop/src-tauri/icons/Square44x44Logo.png +0 -0
  19. package/templates/surfaces/desktop/src-tauri/icons/Square71x71Logo.png +0 -0
  20. package/templates/surfaces/desktop/src-tauri/icons/Square89x89Logo.png +0 -0
  21. package/templates/surfaces/desktop/src-tauri/icons/StoreLogo.png +0 -0
  22. package/templates/surfaces/desktop/src-tauri/icons/icon.icns +0 -0
  23. package/templates/surfaces/desktop/src-tauri/icons/icon.ico +0 -0
  24. package/templates/surfaces/desktop/src-tauri/icons/icon.png +0 -0
  25. package/templates/surfaces/desktop/src-tauri/tauri.conf.json.tmpl +10 -3
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for describing the origin of the Work and
141
+ 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 2026 usetheo.dev
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/dist/cli.js CHANGED
@@ -313,7 +313,9 @@ var SURFACE_CONFIG = {
313
313
  dev: "tauri dev",
314
314
  tauri: "tauri",
315
315
  "build:frontend": "vite build frontend",
316
- "build:sidecar": 'tsx --version >/dev/null && echo "sidecar runs via tsx (see src-tauri/tauri.conf.json)"'
316
+ // Generates the Tauri externalBin launcher (src-tauri/binaries/theo-sidecar-<triple>) the Rust
317
+ // shell spawns. Wired into tauri.conf.json beforeDev/BuildCommand — regenerated each launch.
318
+ "build:sidecar": "node scripts/build-sidecar.mjs"
317
319
  },
318
320
  tsconfigInclude: [
319
321
  "sidecar/**/*.ts",
package/dist/cli.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/cli.ts","../src/install.ts","../src/pkg-manager.ts","../src/preflight-node.ts","../src/prompts.ts","../src/scaffold-services.ts","../src/scaffold-surface.ts","../src/index.ts","../src/bare-transform.ts"],"sourcesContent":["import { execSync } from 'node:child_process'\nimport {\n readFileSync,\n writeFileSync,\n unlinkSync,\n mkdirSync,\n renameSync,\n existsSync,\n rmSync,\n} from 'node:fs'\nimport { resolve, join } from 'node:path'\n\nimport { runInstall } from './install.js'\nimport { detectPkgManager, type PkgManager } from './pkg-manager.js'\nimport { assertNodeVersion } from './preflight-node.js'\nimport { runPrompts, getDefaults, type ProjectOptions } from './prompts.js'\nimport { parseBackendFlags, scaffoldServices, type BackendKind } from './scaffold-services.js'\nimport { applySurface, parseSurfaceFlags, type SurfaceKind } from './scaffold-surface.js'\n\nimport { scaffold } from './index.js'\n\nconst VERSION = '0.8.0'\n\nfunction getFlag(args: string[], name: string): string | undefined {\n const flag = args.find((a) => a.startsWith(`--${name}=`))\n return flag ? flag.split('=')[1] : undefined\n}\n\nfunction hasFlag(args: string[], ...names: string[]): boolean {\n return names.some((n) => args.includes(`--${n}`) || args.includes(`-${n}`))\n}\n\nfunction showHelp(): void {\n console.log(`\n create-theokit v${VERSION}\n\n Usage: create-theokit <project-name> [options]\n\n Options:\n -h, --help Show this help message\n -v, --version Show version number\n --yes Use recommended defaults (skip prompts)\n --template=<name> Template to use (default: \"default\")\n --surface=<web|tui|desktop> App surface (default: \"web\") — tui (Ink) / desktop (Tauri)\n --bare Minimal app (no @theokit/* deps)\n --skip-install Scaffold files only, skip package install\n --disable-git Skip git init\n --use-npm Use npm as package manager\n --use-pnpm Use pnpm as package manager\n --use-yarn Use yarn as package manager\n --use-bun Use bun as package manager\n --import-alias=<alias> Import alias (default: \"@/*\")\n --example=<name|github-url> Bootstrap from a GitHub example\n --biome Use Biome instead of ESLint\n --agents-md Include AGENTS.md (default: true)\n\n Examples:\n npx create-theokit my-app --yes\n npx create-theokit my-app\n npx create-theokit my-app --bare --skip-install\n npx create-theokit my-app --surface=tui\n npx create-theokit my-app --surface=desktop\n npx create-theokit my-app --use-bun --biome\n npx create-theokit my-app --example=https://github.com/user/repo\n npx create-theokit my-app --import-alias=\"~/*\"\n`)\n}\n\nexport async function main(): Promise<void> {\n try {\n assertNodeVersion(process.version)\n } catch (err) {\n console.error('')\n console.error(err instanceof Error ? err.message : String(err))\n process.exit(1)\n }\n\n const args = process.argv.slice(2)\n\n // -h / --help\n if (hasFlag(args, 'h', 'help')) {\n showHelp()\n process.exit(0)\n }\n\n // -v / --version\n if (hasFlag(args, 'v', 'version')) {\n console.log(VERSION)\n process.exit(0)\n }\n\n const positionalArgs = args.filter((a) => !a.startsWith('--') && !a.startsWith('-'))\n const projectName = positionalArgs[0]\n\n if (!projectName) {\n showHelp()\n process.exit(1)\n }\n\n // Parse flags\n const templateName = getFlag(args, 'template') ?? 'default'\n const bare = hasFlag(args, 'bare')\n const skipInstall = hasFlag(args, 'skip-install')\n const useDefaults = hasFlag(args, 'yes')\n const disableGit = hasFlag(args, 'disable-git')\n const useBiome = hasFlag(args, 'biome')\n const exampleFlag = getFlag(args, 'example')\n const importAlias = getFlag(args, 'import-alias') ?? '@/*'\n\n // --use-npm/pnpm/yarn/bun override\n let pkgManagerOverride: PkgManager | undefined\n if (hasFlag(args, 'use-npm')) pkgManagerOverride = 'npm'\n else if (hasFlag(args, 'use-pnpm')) pkgManagerOverride = 'pnpm'\n else if (hasFlag(args, 'use-yarn')) pkgManagerOverride = 'yarn'\n else if (hasFlag(args, 'use-bun')) pkgManagerOverride = 'bun'\n\n let backends: BackendKind[] = []\n try {\n backends = parseBackendFlags(args)\n } catch (err) {\n console.error('')\n console.error(err instanceof Error ? err.message : String(err))\n process.exit(1)\n }\n\n let surface: SurfaceKind = 'web'\n try {\n surface = parseSurfaceFlags(args)\n } catch (err) {\n console.error('')\n console.error(err instanceof Error ? err.message : String(err))\n process.exit(1)\n }\n // --bare strips the agent deps; a tui/desktop surface needs them. Refuse the contradiction fail-fast.\n if (bare && surface !== 'web') {\n console.error(\n `\\n--bare cannot be combined with --surface=${surface} (the surface needs the agent deps).\\n`,\n )\n process.exit(1)\n }\n\n const targetDir = resolve(process.cwd(), projectName)\n\n // --example: clone from GitHub\n if (exampleFlag) {\n try {\n console.log(`\\nCloning example \"${exampleFlag}\" into ${projectName}...\\n`)\n cloneExample(exampleFlag, targetDir)\n const pkgManager = pkgManagerOverride ?? detectPkgManager()\n if (!skipInstall) {\n console.log(`Installing dependencies with ${pkgManager}...\\n`)\n runInstall(targetDir, pkgManager)\n }\n if (!disableGit) initGit(targetDir)\n console.log(`\\n ✓ Example cloned to ${targetDir}\\n`)\n console.log(` cd ${projectName}`)\n console.log(` ${pkgManager === 'npm' ? 'npm run' : pkgManager} dev\\n`)\n process.exit(0)\n } catch (err) {\n console.error(`\\n ✗ ${(err as Error).message}\\n`)\n process.exit(1)\n }\n }\n\n // Interactive prompts (skipped with --yes or --bare)\n let options: ProjectOptions\n if (useDefaults || bare) {\n options = getDefaults(projectName)\n if (useBiome) options.eslint = false // Biome replaces ESLint\n } else {\n options = await runPrompts(projectName)\n }\n\n try {\n const suffix = bare ? ' [--bare]' : ''\n const surfaceSuffix = surface !== 'web' ? ` [surface: ${surface}]` : ''\n const backendsSuffix = backends.length > 0 ? ` [+services: ${backends.join(', ')}]` : ''\n console.log(\n `\\nCreating TheoKit project \"${projectName}\" (template: ${templateName})${suffix}${surfaceSuffix}${backendsSuffix}...\\n`,\n )\n\n scaffold(targetDir, projectName, templateName, { bare })\n\n // M45 — apply the surface onto the scaffolded default (tui/desktop; web is a no-op).\n applySurfaceStep(targetDir, projectName, surface, options)\n\n // Post-scaffold: apply user options\n applyOptions(targetDir, options, { importAlias, useBiome })\n\n if (backends.length > 0) {\n scaffoldServices({ targetDir, projectName, backends })\n console.log(` ✓ Scaffolded ${String(backends.length)} service(s): ${backends.join(', ')}\\n`)\n }\n\n const pkgManager = pkgManagerOverride ?? detectPkgManager()\n if (skipInstall) {\n console.log(`Skipping install (--skip-install). Run \\`${pkgManager} install\\` manually.\\n`)\n } else {\n console.log(`Installing dependencies with ${pkgManager}...\\n`)\n runInstall(targetDir, pkgManager)\n }\n\n // git init (unless --disable-git)\n if (!disableGit) initGit(targetDir)\n\n console.log(`\\n ✓ Project created at ${targetDir}\\n`)\n console.log(' Next steps:\\n')\n console.log(` cd ${projectName}`)\n if (skipInstall) console.log(` ${pkgManager} install`)\n console.log(` ${pkgManager === 'npm' ? 'npm run' : pkgManager} dev\\n`)\n } catch (err) {\n console.error(`\\n ✗ ${(err as Error).message}\\n`)\n process.exit(1)\n }\n}\n\n// ── Post-scaffold transforms ──\n\n/**\n * M45 — apply the surface onto the scaffolded default (tui/desktop; web is a no-op). Rolls the whole\n * target dir back on failure (EC-4), exactly like --bare, and disables the web-only options a\n * tui/desktop app does not ship.\n */\nfunction applySurfaceStep(\n targetDir: string,\n projectName: string,\n surface: SurfaceKind,\n options: ProjectOptions,\n): void {\n if (surface === 'web') return\n try {\n applySurface({ targetDir, projectName, surface })\n } catch (err) {\n rmSync(targetDir, { recursive: true, force: true })\n const original = err instanceof Error ? err.message : String(err)\n throw new Error(`Scaffold rolled back: surface transform failed.\\nOriginal error: ${original}`)\n }\n options.tailwind = false\n options.srcDir = false\n}\n\ninterface ApplyOpts {\n importAlias: string\n useBiome: boolean\n}\n\nfunction applyOptions(targetDir: string, options: ProjectOptions, opts: ApplyOpts): void {\n const pkgPath = resolve(targetDir, 'package.json')\n\n // Biome: replace ESLint with Biome\n if (opts.useBiome) {\n const eslintPath = resolve(targetDir, 'eslint.config.mjs')\n if (existsSync(eslintPath)) unlinkSync(eslintPath)\n\n const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8'))\n delete pkg.devDependencies.eslint\n delete pkg.devDependencies['eslint-config-prettier']\n delete pkg.devDependencies['typescript-eslint']\n pkg.devDependencies['@biomejs/biome'] = '^1.9.0'\n pkg.scripts.lint = 'biome check .'\n pkg.scripts['lint:fix'] = 'biome check . --fix'\n pkg.scripts.format = 'biome format . --write'\n pkg.scripts['format:check'] = 'biome format .'\n writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\\n')\n\n // Write biome.json\n writeFileSync(\n resolve(targetDir, 'biome.json'),\n JSON.stringify(\n {\n $schema: 'https://biomejs.dev/schemas/1.9.0/schema.json',\n organizeImports: { enabled: true },\n linter: { enabled: true, rules: { recommended: true } },\n formatter: { enabled: true, indentStyle: 'space', indentWidth: 2, lineWidth: 100 },\n },\n null,\n 2,\n ) + '\\n',\n )\n } else if (!options.eslint) {\n // No linter\n const eslintPath = resolve(targetDir, 'eslint.config.mjs')\n if (existsSync(eslintPath)) unlinkSync(eslintPath)\n const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8'))\n delete pkg.scripts.lint\n delete pkg.scripts['lint:fix']\n delete pkg.devDependencies.eslint\n delete pkg.devDependencies['eslint-config-prettier']\n delete pkg.devDependencies['typescript-eslint']\n writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\\n')\n }\n\n // Tailwind\n if (options.tailwind) {\n const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8'))\n pkg.devDependencies = pkg.devDependencies ?? {}\n pkg.devDependencies.tailwindcss = '^4.0.0'\n pkg.devDependencies['@tailwindcss/vite'] = '^4.0.0'\n writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\\n')\n const cssDir = existsSync(resolve(targetDir, 'src/app')) ? 'src/app' : 'app'\n const cssPath = resolve(targetDir, `${cssDir}/globals.css`)\n const existing = existsSync(cssPath) ? readFileSync(cssPath, 'utf-8') : ''\n writeFileSync(cssPath, '@import \"tailwindcss\";\\n\\n' + existing)\n }\n\n // src/ directory\n if (options.srcDir) {\n const srcDir = resolve(targetDir, 'src')\n mkdirSync(srcDir, { recursive: true })\n for (const dir of ['app', 'server']) {\n const from = resolve(targetDir, dir)\n const to = resolve(srcDir, dir)\n if (existsSync(from)) renameSync(from, to)\n }\n // Move theo.config.ts into src/ for --src-dir mode\n const configFrom = resolve(targetDir, 'theo.config.ts')\n if (existsSync(configFrom)) renameSync(configFrom, resolve(srcDir, 'theo.config.ts'))\n // index.html stays at root — Vite expects it there\n\n const tscPath = resolve(targetDir, 'tsconfig.json')\n const tsc = JSON.parse(readFileSync(tscPath, 'utf-8'))\n tsc.compilerOptions.baseUrl = 'src'\n tsc.include = ['src/**/*.ts', 'src/**/*.tsx']\n writeFileSync(tscPath, JSON.stringify(tsc, null, 2) + '\\n')\n }\n\n // Import alias (custom or disabled)\n const tscPath = resolve(targetDir, 'tsconfig.json')\n const tsc = JSON.parse(readFileSync(tscPath, 'utf-8'))\n if (!options.aliases) {\n delete tsc.compilerOptions.baseUrl\n delete tsc.compilerOptions.paths\n } else if (opts.importAlias !== '@/*') {\n // Custom alias: replace @/* with user choice\n const prefix = opts.importAlias.replace('/*', '')\n tsc.compilerOptions.paths = {\n [`${prefix}/*`]: ['./*'],\n [`${prefix}/server/*`]: ['./server/*'],\n [`${prefix}/app/*`]: ['./app/*'],\n }\n }\n writeFileSync(tscPath, JSON.stringify(tsc, null, 2) + '\\n')\n\n // AGENTS.md\n if (!options.agentsMd) {\n const agentsPath = resolve(targetDir, 'AGENTS.md')\n if (existsSync(agentsPath)) unlinkSync(agentsPath)\n }\n}\n\n// ── Git init ──\n\nfunction initGit(targetDir: string): void {\n try {\n execSync('git init', { cwd: targetDir, stdio: 'ignore' })\n execSync('git add -A', { cwd: targetDir, stdio: 'ignore' })\n execSync('git commit -m \"Initial commit from create-theokit\" --no-verify', {\n cwd: targetDir,\n stdio: 'ignore',\n })\n } catch {\n // git not installed — silently skip\n }\n}\n\n// ── Example cloning ──\n\nfunction cloneExample(example: string, targetDir: string): void {\n const isUrl = example.startsWith('http://') || example.startsWith('https://')\n const repo = isUrl\n ? example\n : `https://github.com/usetheodev/theokit-examples/tree/main/${example}`\n\n if (isUrl) {\n // Full repo URL — shallow clone\n execSync(`git clone --depth 1 ${repo} ${targetDir}`, { stdio: 'inherit' })\n // Remove .git to let user init fresh\n rmSync(join(targetDir, '.git'), { recursive: true, force: true })\n } else {\n // Named example from theokit-examples repo — use degit pattern\n try {\n execSync(`npx --yes degit usetheodev/theokit-examples/${example} ${targetDir}`, {\n stdio: 'inherit',\n })\n } catch {\n throw new Error(\n `Example \"${example}\" not found. ` +\n `Browse available examples at https://github.com/usetheodev/theokit-examples`,\n )\n }\n }\n}\n\n// Auto-execute\nmain().catch((err: unknown) => {\n console.error(err)\n process.exit(1)\n})\n","import spawn from 'cross-spawn'\n\nimport type { PkgManager } from './pkg-manager.js'\n\nexport function runInstall(cwd: string, pkgManager: PkgManager): void {\n const result = spawn.sync(pkgManager, ['install'], {\n cwd,\n stdio: 'inherit',\n env: { ...process.env, NODE_ENV: 'development' },\n })\n\n if (result.status !== 0) {\n throw new Error(`Failed to install dependencies with ${pkgManager}`)\n }\n}\n","export type PkgManager = 'npm' | 'pnpm' | 'yarn' | 'bun'\n\nexport function detectPkgManager(): PkgManager {\n const ua = process.env.npm_config_user_agent ?? ''\n if (ua.startsWith('yarn')) return 'yarn'\n if (ua.startsWith('pnpm')) return 'pnpm'\n if (ua.startsWith('bun')) return 'bun'\n return 'npm'\n}\n","/**\n * Node version preflight for `create-theokit`.\n *\n * `@theokit/sdk` declares `engines.node: \">=22.12.0\"`. Users on older Node\n * hit cryptic `node:sqlite` / `better-sqlite3` ABI errors mid-chat without\n * any actionable diagnostic. This preflight runs at scaffold start, prints\n * a clear error, and exits before any FS write (ADR D4 of the plan).\n *\n * Zero-dep semver comparator — no `semver` package needed.\n */\n\n/** Minimum Node version required by `@theokit/sdk`. */\nexport const MIN_NODE_VERSION = '22.12.0'\n\n/**\n * Compare two semver strings (major.minor.patch). Strips leading `v` from\n * either side. Pre-release suffixes (e.g., `-rc.1`, `-nightly...`) are\n * parsed as the base patch — acceptable for a preflight (we're not gating\n * on exact pre-release ordering).\n *\n * Returns:\n * <0 when a < b\n * 0 when a == b\n * >0 when a > b\n */\nexport function compareSemver(a: string, b: string): number {\n const parse = (raw: string): [number, number, number] => {\n const stripped = raw.replace(/^v/, '').split('-')[0] ?? '0.0.0'\n const parts = stripped.split('.').map((s) => Number.parseInt(s, 10) || 0)\n return [parts[0] ?? 0, parts[1] ?? 0, parts[2] ?? 0]\n }\n const [aMaj, aMin, aPat] = parse(a)\n const [bMaj, bMin, bPat] = parse(b)\n if (aMaj !== bMaj) return aMaj - bMaj\n if (aMin !== bMin) return aMin - bMin\n return aPat - bPat\n}\n\n/**\n * Throw with an actionable message if `currentRaw` is below `minimum`.\n * Default minimum is `MIN_NODE_VERSION` (22.12.0).\n *\n * Called as the first line of `create-theokit`'s `main` so the preflight\n * fires before any directory is written.\n */\nexport function assertNodeVersion(currentRaw: string, minimum: string = MIN_NODE_VERSION): void {\n const current = currentRaw.replace(/^v/, '')\n if (compareSemver(currentRaw, minimum) < 0) {\n throw new Error(\n `create-theokit requires Node ${minimum} or later (the @theokit/sdk peer engines floor).\\n` +\n ` Detected: Node ${current}\\n` +\n ` Fix: nvm install 22 && nvm use 22\\n` +\n ` (or your version manager equivalent — fnm, volta, asdf, nvs)\\n`,\n )\n }\n}\n","/**\n * Interactive prompts for create-theokit.\n * Skipped when --yes flag is passed (uses defaults).\n *\n * Uses Node.js readline (zero deps) — not inquirer/prompts.\n */\nimport { createInterface } from 'node:readline'\n\nexport interface ProjectOptions {\n projectName: string\n typescript: boolean\n eslint: boolean\n tailwind: boolean\n srcDir: boolean\n aliases: boolean\n agentsMd: boolean\n}\n\nconst DEFAULTS: Omit<ProjectOptions, 'projectName'> = {\n typescript: true,\n eslint: true,\n tailwind: true,\n srcDir: false,\n aliases: true,\n agentsMd: true,\n}\n\nasync function ask(rl: ReturnType<typeof createInterface>, question: string, defaultVal: boolean): Promise<boolean> {\n return new Promise((resolve) => {\n const suffix = defaultVal ? '(Y/n)' : '(y/N)'\n rl.question(` ${question} ${suffix} `, (answer) => {\n const a = answer.trim().toLowerCase()\n if (a === '') resolve(defaultVal)\n else resolve(a === 'y' || a === 'yes')\n })\n })\n}\n\nasync function askChoice(rl: ReturnType<typeof createInterface>, question: string, choices: string[], defaultIdx = 0): Promise<number> {\n return new Promise((resolve) => {\n console.log(` ${question}`)\n for (let i = 0; i < choices.length; i++) {\n const marker = i === defaultIdx ? '❯' : ' '\n console.log(` ${marker} ${choices[i]}`)\n }\n rl.question(' Choice (number): ', (answer) => {\n const n = parseInt(answer.trim(), 10)\n resolve(n >= 1 && n <= choices.length ? n - 1 : defaultIdx)\n })\n })\n}\n\nexport async function runPrompts(projectName: string): Promise<ProjectOptions> {\n const rl = createInterface({ input: process.stdin, output: process.stdout })\n\n try {\n console.log('')\n const mode = await askChoice(rl, 'Would you like to use the recommended TheoKit defaults?', [\n 'Yes, use recommended defaults — TypeScript, ESLint, Tailwind CSS, AGENTS.md',\n 'No, customize settings',\n ], 0)\n\n if (mode === 0) {\n return { projectName, ...DEFAULTS }\n }\n\n const typescript = await ask(rl, 'Would you like to use TypeScript?', true)\n const eslint = await ask(rl, 'Would you like to use ESLint?', true)\n const tailwind = await ask(rl, 'Would you like to use Tailwind CSS?', true)\n const srcDir = await ask(rl, 'Would you like your code inside a `src/` directory?', false)\n const aliases = await ask(rl, 'Would you like to use import alias (@/*)?', true)\n const agentsMd = await ask(rl, 'Would you like to include AGENTS.md for coding agents?', true)\n\n return { projectName, typescript, eslint, tailwind, srcDir, aliases, agentsMd }\n } finally {\n rl.close()\n }\n}\n\nexport function getDefaults(projectName: string): ProjectOptions {\n return { projectName, ...DEFAULTS }\n}\n","/**\n * Build-time scaffold helper. All write paths derived from the trusted\n * targetDir (CLI argument, resolved absolute). Read paths are the\n * bundled service templates shipped with this package.\n */\n/**\n * Phase 4 — `--backend python|node` scaffolding (T4.1, T4.2).\n *\n * After the main TheoKit scaffold runs, this helper:\n * - Copies the requested service template(s) under `<target>/services/<name>/`\n * - Substitutes `{{name}}` in `.tmpl` files\n * - Renames `.tmpl` files to drop the suffix\n * - Injects services config into the user's `theo.config.ts`\n * - Injects `@hey-api/client-fetch` into the user's package.json (EC-10)\n */\nimport {\n cpSync,\n existsSync,\n readFileSync,\n readdirSync,\n statSync,\n writeFileSync,\n unlinkSync,\n} from 'node:fs'\nimport { dirname, join, resolve } from 'node:path'\nimport { fileURLToPath } from 'node:url'\n\nconst __dirname = dirname(fileURLToPath(import.meta.url))\n\n// node-only polyglot backend (decision 2026-06-17). Python scaffolding was\n// deferred — only the Node (Hono) sidecar template ships. Re-adding Python\n// requires restoring its template + an ADR with demand evidence.\nexport type BackendKind = 'node'\n\nconst VALID_BACKENDS = ['node'] as const\n\n/**\n * Parse `--backend node` (multi-value) from argv.\n *\n * Accepts:\n * --backend node\n * --backend=node\n *\n * Throws on unknown backend name (incl. `python`, which is not shipped).\n */\nexport function parseBackendFlags(args: string[]): BackendKind[] {\n const out: BackendKind[] = []\n for (let i = 0; i < args.length; i++) {\n const a = args[i] ?? ''\n let value: string | undefined\n if (a === '--backend') {\n value = args[i + 1]\n i++\n } else if (a.startsWith('--backend=')) {\n value = a.slice('--backend='.length)\n }\n if (value === undefined) continue\n if (!(VALID_BACKENDS as readonly string[]).includes(value)) {\n throw new Error(\n `unknown --backend value: '${value}'. Valid options: ${VALID_BACKENDS.join(', ')}.`,\n )\n }\n out.push(value as BackendKind)\n }\n return out\n}\n\nconst BACKEND_CONFIG: Record<\n BackendKind,\n {\n templateDir: string\n serviceName: string\n port: number\n proxy: string\n dev: string\n start: string\n }\n> = {\n node: {\n templateDir: 'agent-node',\n serviceName: 'worker',\n port: 8002,\n proxy: '/api/worker',\n dev: 'pnpm dev',\n start: 'pnpm start',\n },\n}\n\nfunction getServiceTemplateDir(kind: BackendKind): string {\n return resolve(__dirname, '../templates/services', BACKEND_CONFIG[kind].templateDir)\n}\n\nfunction substituteTmpls(dir: string, projectName: string): void {\n for (const entry of readdirSync(dir)) {\n const full = join(dir, entry)\n const stat = statSync(full)\n if (stat.isDirectory()) {\n substituteTmpls(full, projectName)\n continue\n }\n if (entry.endsWith('.tmpl')) {\n const content = readFileSync(full, 'utf-8').replace(/\\{\\{name\\}\\}/g, projectName)\n const dest = full.replace(/\\.tmpl$/, '')\n writeFileSync(dest, content)\n unlinkSync(full)\n }\n }\n}\n\ninterface ServiceEntry {\n runtime: BackendKind\n port: number\n proxy: string\n dev: string\n start: string\n}\n\n/**\n * Build the `services: {}` snippet to inject into `theo.config.ts`.\n * Returns the inner record literal — caller wraps in `services: { ... }`.\n */\nexport function buildServicesSnippet(selections: { name: string; entry: ServiceEntry }[]): string {\n if (selections.length === 0) return ''\n const blocks = selections.map(({ name, entry }) => {\n return ` ${name}: {\n runtime: '${entry.runtime}',\n port: ${String(entry.port)},\n proxy: '${entry.proxy}',\n dev: ${JSON.stringify(entry.dev)},\n start: ${JSON.stringify(entry.start)},\n },`\n })\n return ` services: {\\n${blocks.join('\\n')}\\n },\\n`\n}\n\n/**\n * Insert the services block into an existing `theo.config.ts`.\n * Strategy: find `defineConfig({` and append the services block before the closing brace.\n */\nexport function injectServicesIntoConfig(configSource: string, snippet: string): string {\n if (snippet.length === 0) return configSource\n if (configSource.includes('services:')) return configSource // already present\n\n // Match the LAST `}` before the closing of defineConfig({...})\n const re = /defineConfig\\(\\{([\\s\\S]*?)\\}\\)/m\n const match = re.exec(configSource)\n if (!match) return configSource\n\n const inner = match[1]\n // Strip trailing whitespace without backtracking-prone \\s+$ regex.\n let trimEnd = inner.length\n while (trimEnd > 0 && /\\s/.test(inner.charAt(trimEnd - 1))) {\n trimEnd--\n }\n const trimmed = inner.slice(0, trimEnd)\n const sep = trimmed.length > 0 && !trimmed.endsWith(',') ? ',\\n' : '\\n'\n const newInner = `${trimmed}${sep}${snippet}`\n return configSource.replace(re, `defineConfig({${newInner}})`)\n}\n\nexport function injectHeyApiDep(packageJsonSource: string): string {\n const pkg = JSON.parse(packageJsonSource) as {\n dependencies?: Record<string, string>\n }\n pkg.dependencies = pkg.dependencies ?? {}\n if (!('@hey-api/client-fetch' in pkg.dependencies)) {\n pkg.dependencies['@hey-api/client-fetch'] = '^0.6.0'\n }\n return JSON.stringify(pkg, null, 2) + '\\n'\n}\n\nexport interface ScaffoldServicesOptions {\n /** Target project directory (already scaffolded with the TS template). */\n targetDir: string\n /** Project name (substituted into .tmpl files). */\n projectName: string\n /** Which backends to scaffold. */\n backends: BackendKind[]\n}\n\nexport function scaffoldServices(options: ScaffoldServicesOptions): void {\n if (options.backends.length === 0) return\n\n const selections: { name: string; entry: ServiceEntry }[] = []\n\n for (const kind of options.backends) {\n const cfg = BACKEND_CONFIG[kind]\n const src = getServiceTemplateDir(kind)\n // Schema contract: dev/start commands run from `services/<serviceName>/` cwd\n // (services/schema/schema.ts line 35). The destination MUST equal serviceName\n // so the orchestrator's cwd resolution matches the on-disk directory.\n const dest = join(options.targetDir, 'services', cfg.serviceName)\n if (!existsSync(src)) {\n throw new Error(`service template not found: ${src}`)\n }\n cpSync(src, dest, { recursive: true })\n substituteTmpls(dest, options.projectName)\n\n selections.push({\n name: cfg.serviceName,\n entry: {\n runtime: kind,\n port: cfg.port,\n proxy: cfg.proxy,\n dev: cfg.dev,\n start: cfg.start,\n },\n })\n }\n\n // Inject services into theo.config.ts\n const configPath = join(options.targetDir, 'theo.config.ts')\n if (existsSync(configPath)) {\n const cfgSrc = readFileSync(configPath, 'utf-8')\n const snippet = buildServicesSnippet(selections)\n const updated = injectServicesIntoConfig(cfgSrc, snippet)\n if (updated !== cfgSrc) {\n writeFileSync(configPath, updated)\n }\n }\n\n // EC-10: inject @hey-api/client-fetch into user's package.json\n const pkgPath = join(options.targetDir, 'package.json')\n if (existsSync(pkgPath)) {\n const pkgSrc = readFileSync(pkgPath, 'utf-8')\n const updated = injectHeyApiDep(pkgSrc)\n writeFileSync(pkgPath, updated)\n }\n\n // Rename .gitignore for services if needed (none currently shipped, but reserved hook)\n}\n","import {\n cpSync,\n existsSync,\n readdirSync,\n readFileSync,\n rmSync,\n statSync,\n unlinkSync,\n writeFileSync,\n} from 'node:fs'\nimport { dirname, join, resolve } from 'node:path'\nimport { fileURLToPath } from 'node:url'\n\n// ESM has no CJS `__dirname` global — derive it (mirrors src/index.ts + src/scaffold-services.ts). Without\n// this the published bundle throws `__dirname is not defined` at runtime (vitest provides the global, so the\n// unit tests never caught it — only running `npx create-theokit --surface tui` for real surfaced it).\nconst __dirname = dirname(fileURLToPath(import.meta.url))\n\n/**\n * M45 (ADR-0054) — `create-theokit --surface web|tui|desktop`.\n *\n * A FLAG-driven additive scaffold (mirrors `--backend` / `scaffoldServices`), NOT a new top-level\n * template (ADR-0023 default-only respected). `web` is the default (the existing web app — no-op).\n * `tui` / `desktop` copy a template fragment (`templates/surfaces/<kind>/`) onto the scaffolded default,\n * mutate `package.json` (drop web-only deps, add surface deps + scripts), and remove the web UI. Each\n * scaffolded surface consumes the agent via the M41/M42/M44 UNIFIED client (ADR-0054 D2), not the raw\n * seam. All Tauri/Ink boilerplate lives HERE in the scaffolder templates — framework core stays agnostic.\n */\nexport type SurfaceKind = 'web' | 'tui' | 'desktop'\n\nconst VALID_SURFACES = ['web', 'tui', 'desktop'] as const\n\n/**\n * Web-only deps dropped for the tui/desktop surfaces (they ship no web UI). `react-router` is NOT dropped\n * — `theokit` declares it a REQUIRED peer, so removing it breaks `npm install` (ERESOLVE).\n */\nconst WEB_ONLY_DEPS = ['@theokit/ui', '@usetheo/ui', 'lucide-react'] as const\nconst WEB_ONLY_DEV_DEPS = ['tailwindcss', '@tailwindcss/vite', 'tailwindcss-animate'] as const\n/** Web UI files removed for the tui/desktop surfaces. */\nconst WEB_ONLY_FILES = ['app', 'index.html', 'tailwind.config.ts', 'postcss.config.js'] as const\n\ninterface SurfaceConfig {\n /** The template fragment dir under `templates/surfaces/`. */\n fragment: string\n /** Deps ADDED for this surface. */\n deps: Record<string, string>\n /** Dev deps ADDED for this surface. */\n devDeps: Record<string, string>\n /** Scripts SET for this surface (override the web dev/build). */\n scripts: Record<string, string>\n /** `tsconfig.json` `include` for this surface (the default's `app/**` is removed with the web UI). */\n tsconfigInclude: string[]\n}\n\nconst SURFACE_CONFIG: Record<Exclude<SurfaceKind, 'web'>, SurfaceConfig> = {\n tui: {\n fragment: 'tui',\n // `@theokit/tui` renders the conversation (`<ChatThread>` + the `./ai-sdk` UIMessage adapter). `ai` is\n // the UIMessageStream type the unified client + adapter consume (was transitive via `@theokit/ui`, dropped\n // for tui), so declare it explicitly. `ink@7` is the React-19 line (ink@5 crashes on React 19 with\n // `ReactCurrentOwner` — the default template pins react@19; ink@6.0.0+ moved its peer to react>=19) and\n // matches @theokit/tui's own ink@^7.1.0, so the app's `import 'ink'` dedupes to one React-19 ink.\n deps: { '@theokit/tui': '^0.30.0', ink: '^7.1.0', ai: '^7.0.0' },\n devDeps: { tsx: '^4.19.0' },\n scripts: { dev: 'tsx tui/main.tsx', start: 'tsx tui/main.tsx' },\n tsconfigInclude: ['tui/**/*.ts', 'tui/**/*.tsx', 'server/**/*.ts', 'agents/**/*.ts'],\n },\n desktop: {\n fragment: 'desktop',\n // M47: the webview is a React app rendering with `@theokit/ui`, driven by `useAgent` over a\n // `ChannelTransport` whose source is `@theokit/tauri`'s `createTauriChannelSource`; the Node sidecar\n // runs the turn via `@theokit/tauri/sidecar`. `ai` = the UIMessageStream reader + UIMessage type (was\n // transitive via `@theokit/ui`, re-added explicitly here). react/react-dom are inherited from the default.\n deps: { '@theokit/ui': '^1.0.0', '@theokit/tauri': '^0.1.1', ai: '^7.0.0' },\n devDeps: {\n tsx: '^4.19.0',\n '@tauri-apps/cli': '^2.0.0',\n vite: '^6.0.0',\n '@vitejs/plugin-react': '^4.3.0',\n },\n scripts: {\n dev: 'tauri dev',\n tauri: 'tauri',\n 'build:frontend': 'vite build frontend',\n 'build:sidecar':\n 'tsx --version >/dev/null && echo \"sidecar runs via tsx (see src-tauri/tauri.conf.json)\"',\n },\n tsconfigInclude: [\n 'sidecar/**/*.ts',\n 'frontend/src/**/*.ts',\n 'frontend/src/**/*.tsx',\n 'server/**/*.ts',\n 'agents/**/*.ts',\n ],\n },\n}\n\n/** Parse `--surface <kind>` / `--surface=<kind>`; default `web`. Fail-fast on an unknown value. */\nexport function parseSurfaceFlags(args: string[]): SurfaceKind {\n let surface: SurfaceKind = 'web'\n for (let i = 0; i < args.length; i++) {\n const a = args[i] ?? ''\n let value: string | undefined\n if (a === '--surface') {\n value = args[i + 1]\n i++\n } else if (a.startsWith('--surface=')) {\n value = a.slice('--surface='.length)\n }\n if (value === undefined) continue\n if (!(VALID_SURFACES as readonly string[]).includes(value)) {\n throw new Error(\n `unknown --surface value: '${value}'. Valid options: ${VALID_SURFACES.join(', ')}.`,\n )\n }\n surface = value as SurfaceKind\n }\n return surface\n}\n\n/** Locate the fragment dir shipped alongside the compiled scaffolder. */\nfunction getSurfaceFragmentDir(fragment: string): string {\n return resolve(__dirname, '../templates/surfaces', fragment)\n}\n\n/** Recursively substitute `{{name}}` in `.tmpl` files (mirrors scaffoldServices). */\nfunction substituteTmpls(dir: string, projectName: string): void {\n for (const entry of readdirSync(dir)) {\n const full = join(dir, entry)\n if (statSync(full).isDirectory()) {\n substituteTmpls(full, projectName)\n continue\n }\n if (entry.endsWith('.tmpl')) {\n const content = readFileSync(full, 'utf-8').replace(/\\{\\{name\\}\\}/g, projectName)\n writeFileSync(full.replace(/\\.tmpl$/, ''), content)\n unlinkSync(full)\n }\n }\n}\n\nexport interface ApplySurfaceOptions {\n targetDir: string\n projectName: string\n surface: SurfaceKind\n /** Test-only: force a failure to exercise the caller's rollback (mirrors --bare `_testForceError`). */\n _testForceError?: string\n}\n\ninterface PartialPackageJson {\n dependencies?: Record<string, string>\n devDependencies?: Record<string, string>\n scripts?: Record<string, string>\n [key: string]: unknown\n}\n\n/**\n * Apply a surface onto a freshly-scaffolded default template. `web` is a no-op (the default IS web).\n * `tui`/`desktop` copy the fragment, drop web-only deps + UI, and add the surface's deps/scripts. Throws\n * on any failure so the CLI can roll the whole target dir back (EC-4), exactly like `--bare`.\n */\nexport function applySurface(options: ApplySurfaceOptions): void {\n if (options._testForceError !== undefined) {\n throw new Error(`Forced surface failure: ${options._testForceError}`)\n }\n if (options.surface === 'web') return\n\n const cfg = SURFACE_CONFIG[options.surface]\n const src = getSurfaceFragmentDir(cfg.fragment)\n if (!existsSync(src)) {\n throw new Error(`surface fragment not found: ${src}`)\n }\n\n // 1. Copy the fragment onto the target, then substitute {{name}}.\n cpSync(src, options.targetDir, { recursive: true })\n substituteTmpls(options.targetDir, options.projectName)\n\n // 2. Remove the web UI (a tui/desktop app ships no web surface).\n for (const rel of WEB_ONLY_FILES) {\n const p = join(options.targetDir, rel)\n if (existsSync(p)) rmSync(p, { recursive: true, force: true })\n }\n\n // 3. Mutate package.json: drop web-only deps, add surface deps + scripts.\n const pkgPath = join(options.targetDir, 'package.json')\n if (existsSync(pkgPath)) {\n const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8')) as PartialPackageJson\n pkg.dependencies = { ...dropKeys(pkg.dependencies, WEB_ONLY_DEPS), ...cfg.deps }\n pkg.devDependencies = { ...dropKeys(pkg.devDependencies, WEB_ONLY_DEV_DEPS), ...cfg.devDeps }\n pkg.scripts = { ...(pkg.scripts ?? {}), ...cfg.scripts }\n writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}\\n`)\n }\n\n // 4. Point `tsconfig.json` `include` at the surface's source (the default's `app/**` went with the web\n // UI) — so `tsc` in the generated project type-checks the surface entry files (the unified-client wiring).\n const tsconfigPath = join(options.targetDir, 'tsconfig.json')\n if (existsSync(tsconfigPath)) {\n const tsconfig = JSON.parse(readFileSync(tsconfigPath, 'utf-8')) as { include?: string[] }\n tsconfig.include = cfg.tsconfigInclude\n writeFileSync(tsconfigPath, `${JSON.stringify(tsconfig, null, 2)}\\n`)\n }\n}\n\n/** Return a copy of `record` without `keys` (no dynamic `delete` — filter-rebuild). */\nfunction dropKeys(\n record: Record<string, string> | undefined,\n keys: readonly string[],\n): Record<string, string> {\n return Object.fromEntries(Object.entries(record ?? {}).filter(([k]) => !keys.includes(k)))\n}\n","/**\n * `create-theokit` scaffold tool. All write paths are derived from the\n * user-supplied target directory (CLI argument, resolved to absolute).\n * Read paths are the bundled `templates/` shipped with this package.\n * Build-time tool — no HTTP input.\n */\nimport {\n existsSync,\n cpSync,\n readFileSync,\n writeFileSync,\n renameSync,\n unlinkSync,\n readdirSync,\n rmSync,\n statSync,\n} from 'node:fs'\nimport { resolve, join, dirname } from 'node:path'\nimport { fileURLToPath } from 'node:url'\n\nimport { applyBareTransform } from './bare-transform.js'\n\nconst __dirname = dirname(fileURLToPath(import.meta.url))\n\nfunction getTemplateDir(templateName = 'default'): string {\n return resolve(__dirname, '../templates', templateName)\n}\n\nfunction isValidProjectName(name: string): boolean {\n return /^[a-z0-9][a-z0-9._-]*$/.test(name)\n}\n\nexport interface ScaffoldOptions {\n bare?: boolean\n /** Test-only — force the bare transform to throw to validate EC-4 rollback. */\n _testForceTransformError?: string\n}\n\nexport function scaffold(\n targetDir: string,\n projectName: string,\n templateName = 'default',\n options: ScaffoldOptions = {},\n): void {\n // EC-4 + ADR D5: --bare only applies to default template\n if (options.bare && templateName !== 'default') {\n throw new Error(\n `--bare flag only applies to the default template; got \"${templateName}\". ` +\n `Use \\`npx create-theokit <name> --template=default --bare\\` or pick a different template.`,\n )\n }\n\n const templateDir = getTemplateDir(templateName)\n\n if (!existsSync(templateDir)) {\n throw new Error(`Template \"${templateName}\" not found. Available templates: default`)\n }\n\n // Bug #1 fix: \".\" means current directory — use dir basename as project name\n const resolvedName =\n projectName === '.' ? (resolve(targetDir).split('/').pop() ?? 'my-app') : projectName\n\n if (!isValidProjectName(resolvedName)) {\n throw new Error(\n `Invalid project name \"${resolvedName}\". ` +\n `Use lowercase letters, numbers, hyphens, and dots. Must start with a letter or number.`,\n )\n }\n\n if (existsSync(targetDir)) {\n const contents = readdirSync(targetDir)\n if (contents.length > 0) {\n throw new Error(`Directory \"${targetDir}\" is not empty. Please use an empty directory.`)\n }\n }\n\n cpSync(templateDir, targetDir, { recursive: true })\n\n const gitignoreSrc = join(targetDir, '_gitignore')\n const gitignoreDest = join(targetDir, '.gitignore')\n if (existsSync(gitignoreSrc)) {\n renameSync(gitignoreSrc, gitignoreDest)\n }\n\n // dot-claude/ → .claude/ (npm ignores dotfolders in published packages)\n const dotClaudeSrc = join(targetDir, 'dot-claude')\n const dotClaudeDest = join(targetDir, '.claude')\n if (existsSync(dotClaudeSrc)) {\n renameSync(dotClaudeSrc, dotClaudeDest)\n }\n\n // Apply {{name}} substitution to every `*.tmpl` file in the target dir.\n // Each `foo.tmpl` becomes `foo` with placeholders replaced. Walks only\n // the project root (deeper subfolders don't currently need templating).\n for (const entry of readdirSync(targetDir)) {\n if (!entry.endsWith('.tmpl')) continue\n const src = join(targetDir, entry)\n const stat = statSync(src)\n if (!stat.isFile()) continue\n const dst = join(targetDir, entry.slice(0, -'.tmpl'.length))\n const content = readFileSync(src, 'utf-8')\n const replaced = content.replace(/\\{\\{name\\}\\}/g, resolvedName)\n writeFileSync(dst, replaced)\n unlinkSync(src)\n }\n\n // T4.1 — Apply --bare transform with EC-4 atomic rollback\n if (options.bare) {\n try {\n applyBareTransform(targetDir, {\n _testForceError: options._testForceTransformError,\n })\n } catch (err) {\n // EC-4: roll back partial state\n rmSync(targetDir, { recursive: true, force: true })\n const original = err instanceof Error ? err.message : String(err)\n throw new Error(\n `Scaffold rolled back: bare transform failed. Check filesystem perms.\\nOriginal error: ${original}`,\n )\n }\n }\n}\n","/**\n * Scaffold transform. Mutates files inside the freshly-created target\n * directory whose absolute path is the function input. No HTTP input.\n */\n/**\n * T4.1 — `--bare` transformation.\n *\n * Applied AFTER the default template is copied. Removes:\n * - `@theokit/ui` from `package.json` dependencies (TheoUI bundled components)\n * - `@theokit/sdk` from `package.json` dependencies (agent SDK — see below)\n * - `@theokit/agents` from `package.json` dependencies (only agents/chat.ts used it)\n * - `app/page.tsx` agent-surface content (replaces with Hello Theo)\n * - `agents/chat.ts` (the demo agent — depends on the SDK + TheoUI page)\n * - `tailwind.config.ts` + `postcss.config.js` (Tailwind toolchain — only\n * needed by the @theokit/ui-driven default surface)\n * - tailwind* + postcss* from devDependencies (toolchain cleanup)\n *\n * Why SDK removal is in --bare:\n * `@theokit/sdk` is not yet on the public npm registry (operator-deferred\n * publish per macro roadmap item #3). A user running `npx create-theokit`\n * without `--bare` hits `npm install` → 404. The `--bare` path produces a\n * scaffold that ALWAYS works without registry dependencies — Hello Theo\n * with a clean structure to grow into.\n *\n * EC-4: callers MUST wrap this in try/catch + `rmSync` rollback so a partial\n * transform never leaves the target dir in a broken state.\n */\n\nimport { existsSync, readFileSync, writeFileSync, unlinkSync } from 'node:fs'\nimport { join } from 'node:path'\n\nconst HELLO_PAGE = `export default function Page() {\n return <h1>Hello Theo</h1>\n}\n`\n\nexport interface BareTransformOptions {\n /** Test-only — force a synthetic write failure to validate rollback path. */\n _testForceError?: string\n}\n\nexport function applyBareTransform(targetDir: string, options: BareTransformOptions = {}): void {\n if (options._testForceError) {\n throw new Error(`Forced transform failure: ${options._testForceError}`)\n }\n\n // 1. Remove @theokit/ui + @theokit/sdk + tailwind toolchain from deps\n const pkgPath = join(targetDir, 'package.json')\n if (existsSync(pkgPath)) {\n interface PartialPackageJson {\n dependencies?: Record<string, string>\n devDependencies?: Record<string, string>\n [key: string]: unknown\n }\n const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8')) as PartialPackageJson\n if (pkg.dependencies) {\n delete pkg.dependencies['@theokit/ui']\n // Drop SDK — operator-deferred npm publish (macro roadmap item #3).\n // Without removal, `npm install` hits 404 for any consumer outside\n // the workspace.\n delete pkg.dependencies['@theokit/sdk']\n // --bare removes the demo agent (agents/chat.ts), so its runtime dep\n // (@theokit/agents, imported only by that file) goes with it.\n delete pkg.dependencies['@theokit/agents']\n // lucide-react ships with the TheoUI surface; --bare doesn't render\n // any icons so it's safe to drop.\n delete pkg.dependencies['lucide-react']\n }\n if (pkg.devDependencies) {\n // Tailwind toolchain is only needed by the @theokit/ui-driven default\n // surface. --bare ships unstyled Hello Theo; no Tailwind required.\n delete pkg.devDependencies.tailwindcss\n delete pkg.devDependencies['tailwindcss-animate']\n delete pkg.devDependencies.postcss\n delete pkg.devDependencies.autoprefixer\n }\n writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}\\n`)\n }\n\n // 2. Replace app/page.tsx with Hello Theo\n const pagePath = join(targetDir, 'app/page.tsx')\n if (existsSync(pagePath)) {\n writeFileSync(pagePath, HELLO_PAGE)\n }\n\n // 3. Remove the demo chat agent (the `agents/chat.ts` file + its TheoUI page)\n const chatPath = join(targetDir, 'agents/chat.ts')\n if (existsSync(chatPath)) {\n unlinkSync(chatPath)\n }\n\n // 4. Remove tailwind + postcss config files (toolchain dropped from devDeps)\n const tailwindCfg = join(targetDir, 'tailwind.config.ts')\n if (existsSync(tailwindCfg)) {\n unlinkSync(tailwindCfg)\n }\n const postcssCfg = join(targetDir, 'postcss.config.js')\n if (existsSync(postcssCfg)) {\n unlinkSync(postcssCfg)\n }\n}\n"],"mappings":";;;AAAA,SAAS,gBAAgB;AACzB;AAAA,EACE,gBAAAA;AAAA,EACA,iBAAAC;AAAA,EACA,cAAAC;AAAA,EACA;AAAA,EACA,cAAAC;AAAA,EACA,cAAAC;AAAA,EACA,UAAAC;AAAA,OACK;AACP,SAAS,WAAAC,UAAS,QAAAC,aAAY;;;AC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9D,QAAM,QAAQ,QAAQ,WAAW,SAAS,KAAK,QAAQ,WAAW,UAAU;AAC5E,QAAM,OAAO,QACT,UACA,4DAA4D,OAAO;AAEvE,MAAI,OAAO;AAET,aAAS,uBAAuB,IAAI,IAAI,SAAS,IAAI,EAAE,OAAO,UAAU,CAAC;AAEzE,IAAAF,QAAOQ,MAAK,WAAW,MAAM,GAAG,EAAE,WAAW,MAAM,OAAO,KAAK,CAAC;AAAA,EAClE,OAAO;AAEL,QAAI;AACF,eAAS,+CAA+C,OAAO,IAAI,SAAS,IAAI;AAAA,QAC9E,OAAO;AAAA,MACT,CAAC;AAAA,IACH,QAAQ;AACN,YAAM,IAAI;AAAA,QACR,YAAY,OAAO;AAAA,MAErB;AAAA,IACF;AAAA,EACF;AACF;AAGA,KAAK,EAAE,MAAM,CAAC,QAAiB;AAC7B,UAAQ,MAAM,GAAG;AACjB,UAAQ,KAAK,CAAC;AAChB,CAAC;","names":["readFileSync","writeFileSync","unlinkSync","renameSync","existsSync","rmSync","resolve","join","resolve","cpSync","existsSync","readdirSync","readFileSync","statSync","unlinkSync","writeFileSync","dirname","join","resolve","fileURLToPath","__dirname","substituteTmpls","existsSync","cpSync","readFileSync","writeFileSync","unlinkSync","readdirSync","rmSync","statSync","resolve","join","dirname","fileURLToPath","existsSync","readFileSync","writeFileSync","unlinkSync","join","__dirname","dirname","fileURLToPath","resolve","existsSync","readdirSync","cpSync","join","statSync","readFileSync","writeFileSync","unlinkSync","rmSync","resolve","rmSync","existsSync","unlinkSync","readFileSync","writeFileSync","renameSync","tscPath","tsc","join"]}
1
+ {"version":3,"sources":["../src/cli.ts","../src/install.ts","../src/pkg-manager.ts","../src/preflight-node.ts","../src/prompts.ts","../src/scaffold-services.ts","../src/scaffold-surface.ts","../src/index.ts","../src/bare-transform.ts"],"sourcesContent":["import { execSync } from 'node:child_process'\nimport {\n readFileSync,\n writeFileSync,\n unlinkSync,\n mkdirSync,\n renameSync,\n existsSync,\n rmSync,\n} from 'node:fs'\nimport { resolve, join } from 'node:path'\n\nimport { runInstall } from './install.js'\nimport { detectPkgManager, type PkgManager } from './pkg-manager.js'\nimport { assertNodeVersion } from './preflight-node.js'\nimport { runPrompts, getDefaults, type ProjectOptions } from './prompts.js'\nimport { parseBackendFlags, scaffoldServices, type BackendKind } from './scaffold-services.js'\nimport { applySurface, parseSurfaceFlags, type SurfaceKind } from './scaffold-surface.js'\n\nimport { scaffold } from './index.js'\n\nconst VERSION = '0.8.0'\n\nfunction getFlag(args: string[], name: string): string | undefined {\n const flag = args.find((a) => a.startsWith(`--${name}=`))\n return flag ? flag.split('=')[1] : undefined\n}\n\nfunction hasFlag(args: string[], ...names: string[]): boolean {\n return names.some((n) => args.includes(`--${n}`) || args.includes(`-${n}`))\n}\n\nfunction showHelp(): void {\n console.log(`\n create-theokit v${VERSION}\n\n Usage: create-theokit <project-name> [options]\n\n Options:\n -h, --help Show this help message\n -v, --version Show version number\n --yes Use recommended defaults (skip prompts)\n --template=<name> Template to use (default: \"default\")\n --surface=<web|tui|desktop> App surface (default: \"web\") — tui (Ink) / desktop (Tauri)\n --bare Minimal app (no @theokit/* deps)\n --skip-install Scaffold files only, skip package install\n --disable-git Skip git init\n --use-npm Use npm as package manager\n --use-pnpm Use pnpm as package manager\n --use-yarn Use yarn as package manager\n --use-bun Use bun as package manager\n --import-alias=<alias> Import alias (default: \"@/*\")\n --example=<name|github-url> Bootstrap from a GitHub example\n --biome Use Biome instead of ESLint\n --agents-md Include AGENTS.md (default: true)\n\n Examples:\n npx create-theokit my-app --yes\n npx create-theokit my-app\n npx create-theokit my-app --bare --skip-install\n npx create-theokit my-app --surface=tui\n npx create-theokit my-app --surface=desktop\n npx create-theokit my-app --use-bun --biome\n npx create-theokit my-app --example=https://github.com/user/repo\n npx create-theokit my-app --import-alias=\"~/*\"\n`)\n}\n\nexport async function main(): Promise<void> {\n try {\n assertNodeVersion(process.version)\n } catch (err) {\n console.error('')\n console.error(err instanceof Error ? err.message : String(err))\n process.exit(1)\n }\n\n const args = process.argv.slice(2)\n\n // -h / --help\n if (hasFlag(args, 'h', 'help')) {\n showHelp()\n process.exit(0)\n }\n\n // -v / --version\n if (hasFlag(args, 'v', 'version')) {\n console.log(VERSION)\n process.exit(0)\n }\n\n const positionalArgs = args.filter((a) => !a.startsWith('--') && !a.startsWith('-'))\n const projectName = positionalArgs[0]\n\n if (!projectName) {\n showHelp()\n process.exit(1)\n }\n\n // Parse flags\n const templateName = getFlag(args, 'template') ?? 'default'\n const bare = hasFlag(args, 'bare')\n const skipInstall = hasFlag(args, 'skip-install')\n const useDefaults = hasFlag(args, 'yes')\n const disableGit = hasFlag(args, 'disable-git')\n const useBiome = hasFlag(args, 'biome')\n const exampleFlag = getFlag(args, 'example')\n const importAlias = getFlag(args, 'import-alias') ?? '@/*'\n\n // --use-npm/pnpm/yarn/bun override\n let pkgManagerOverride: PkgManager | undefined\n if (hasFlag(args, 'use-npm')) pkgManagerOverride = 'npm'\n else if (hasFlag(args, 'use-pnpm')) pkgManagerOverride = 'pnpm'\n else if (hasFlag(args, 'use-yarn')) pkgManagerOverride = 'yarn'\n else if (hasFlag(args, 'use-bun')) pkgManagerOverride = 'bun'\n\n let backends: BackendKind[] = []\n try {\n backends = parseBackendFlags(args)\n } catch (err) {\n console.error('')\n console.error(err instanceof Error ? err.message : String(err))\n process.exit(1)\n }\n\n let surface: SurfaceKind = 'web'\n try {\n surface = parseSurfaceFlags(args)\n } catch (err) {\n console.error('')\n console.error(err instanceof Error ? err.message : String(err))\n process.exit(1)\n }\n // --bare strips the agent deps; a tui/desktop surface needs them. Refuse the contradiction fail-fast.\n if (bare && surface !== 'web') {\n console.error(\n `\\n--bare cannot be combined with --surface=${surface} (the surface needs the agent deps).\\n`,\n )\n process.exit(1)\n }\n\n const targetDir = resolve(process.cwd(), projectName)\n\n // --example: clone from GitHub\n if (exampleFlag) {\n try {\n console.log(`\\nCloning example \"${exampleFlag}\" into ${projectName}...\\n`)\n cloneExample(exampleFlag, targetDir)\n const pkgManager = pkgManagerOverride ?? detectPkgManager()\n if (!skipInstall) {\n console.log(`Installing dependencies with ${pkgManager}...\\n`)\n runInstall(targetDir, pkgManager)\n }\n if (!disableGit) initGit(targetDir)\n console.log(`\\n ✓ Example cloned to ${targetDir}\\n`)\n console.log(` cd ${projectName}`)\n console.log(` ${pkgManager === 'npm' ? 'npm run' : pkgManager} dev\\n`)\n process.exit(0)\n } catch (err) {\n console.error(`\\n ✗ ${(err as Error).message}\\n`)\n process.exit(1)\n }\n }\n\n // Interactive prompts (skipped with --yes or --bare)\n let options: ProjectOptions\n if (useDefaults || bare) {\n options = getDefaults(projectName)\n if (useBiome) options.eslint = false // Biome replaces ESLint\n } else {\n options = await runPrompts(projectName)\n }\n\n try {\n const suffix = bare ? ' [--bare]' : ''\n const surfaceSuffix = surface !== 'web' ? ` [surface: ${surface}]` : ''\n const backendsSuffix = backends.length > 0 ? ` [+services: ${backends.join(', ')}]` : ''\n console.log(\n `\\nCreating TheoKit project \"${projectName}\" (template: ${templateName})${suffix}${surfaceSuffix}${backendsSuffix}...\\n`,\n )\n\n scaffold(targetDir, projectName, templateName, { bare })\n\n // M45 — apply the surface onto the scaffolded default (tui/desktop; web is a no-op).\n applySurfaceStep(targetDir, projectName, surface, options)\n\n // Post-scaffold: apply user options\n applyOptions(targetDir, options, { importAlias, useBiome })\n\n if (backends.length > 0) {\n scaffoldServices({ targetDir, projectName, backends })\n console.log(` ✓ Scaffolded ${String(backends.length)} service(s): ${backends.join(', ')}\\n`)\n }\n\n const pkgManager = pkgManagerOverride ?? detectPkgManager()\n if (skipInstall) {\n console.log(`Skipping install (--skip-install). Run \\`${pkgManager} install\\` manually.\\n`)\n } else {\n console.log(`Installing dependencies with ${pkgManager}...\\n`)\n runInstall(targetDir, pkgManager)\n }\n\n // git init (unless --disable-git)\n if (!disableGit) initGit(targetDir)\n\n console.log(`\\n ✓ Project created at ${targetDir}\\n`)\n console.log(' Next steps:\\n')\n console.log(` cd ${projectName}`)\n if (skipInstall) console.log(` ${pkgManager} install`)\n console.log(` ${pkgManager === 'npm' ? 'npm run' : pkgManager} dev\\n`)\n } catch (err) {\n console.error(`\\n ✗ ${(err as Error).message}\\n`)\n process.exit(1)\n }\n}\n\n// ── Post-scaffold transforms ──\n\n/**\n * M45 — apply the surface onto the scaffolded default (tui/desktop; web is a no-op). Rolls the whole\n * target dir back on failure (EC-4), exactly like --bare, and disables the web-only options a\n * tui/desktop app does not ship.\n */\nfunction applySurfaceStep(\n targetDir: string,\n projectName: string,\n surface: SurfaceKind,\n options: ProjectOptions,\n): void {\n if (surface === 'web') return\n try {\n applySurface({ targetDir, projectName, surface })\n } catch (err) {\n rmSync(targetDir, { recursive: true, force: true })\n const original = err instanceof Error ? err.message : String(err)\n throw new Error(`Scaffold rolled back: surface transform failed.\\nOriginal error: ${original}`)\n }\n options.tailwind = false\n options.srcDir = false\n}\n\ninterface ApplyOpts {\n importAlias: string\n useBiome: boolean\n}\n\nfunction applyOptions(targetDir: string, options: ProjectOptions, opts: ApplyOpts): void {\n const pkgPath = resolve(targetDir, 'package.json')\n\n // Biome: replace ESLint with Biome\n if (opts.useBiome) {\n const eslintPath = resolve(targetDir, 'eslint.config.mjs')\n if (existsSync(eslintPath)) unlinkSync(eslintPath)\n\n const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8'))\n delete pkg.devDependencies.eslint\n delete pkg.devDependencies['eslint-config-prettier']\n delete pkg.devDependencies['typescript-eslint']\n pkg.devDependencies['@biomejs/biome'] = '^1.9.0'\n pkg.scripts.lint = 'biome check .'\n pkg.scripts['lint:fix'] = 'biome check . --fix'\n pkg.scripts.format = 'biome format . --write'\n pkg.scripts['format:check'] = 'biome format .'\n writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\\n')\n\n // Write biome.json\n writeFileSync(\n resolve(targetDir, 'biome.json'),\n JSON.stringify(\n {\n $schema: 'https://biomejs.dev/schemas/1.9.0/schema.json',\n organizeImports: { enabled: true },\n linter: { enabled: true, rules: { recommended: true } },\n formatter: { enabled: true, indentStyle: 'space', indentWidth: 2, lineWidth: 100 },\n },\n null,\n 2,\n ) + '\\n',\n )\n } else if (!options.eslint) {\n // No linter\n const eslintPath = resolve(targetDir, 'eslint.config.mjs')\n if (existsSync(eslintPath)) unlinkSync(eslintPath)\n const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8'))\n delete pkg.scripts.lint\n delete pkg.scripts['lint:fix']\n delete pkg.devDependencies.eslint\n delete pkg.devDependencies['eslint-config-prettier']\n delete pkg.devDependencies['typescript-eslint']\n writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\\n')\n }\n\n // Tailwind\n if (options.tailwind) {\n const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8'))\n pkg.devDependencies = pkg.devDependencies ?? {}\n pkg.devDependencies.tailwindcss = '^4.0.0'\n pkg.devDependencies['@tailwindcss/vite'] = '^4.0.0'\n writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\\n')\n const cssDir = existsSync(resolve(targetDir, 'src/app')) ? 'src/app' : 'app'\n const cssPath = resolve(targetDir, `${cssDir}/globals.css`)\n const existing = existsSync(cssPath) ? readFileSync(cssPath, 'utf-8') : ''\n writeFileSync(cssPath, '@import \"tailwindcss\";\\n\\n' + existing)\n }\n\n // src/ directory\n if (options.srcDir) {\n const srcDir = resolve(targetDir, 'src')\n mkdirSync(srcDir, { recursive: true })\n for (const dir of ['app', 'server']) {\n const from = resolve(targetDir, dir)\n const to = resolve(srcDir, dir)\n if (existsSync(from)) renameSync(from, to)\n }\n // Move theo.config.ts into src/ for --src-dir mode\n const configFrom = resolve(targetDir, 'theo.config.ts')\n if (existsSync(configFrom)) renameSync(configFrom, resolve(srcDir, 'theo.config.ts'))\n // index.html stays at root — Vite expects it there\n\n const tscPath = resolve(targetDir, 'tsconfig.json')\n const tsc = JSON.parse(readFileSync(tscPath, 'utf-8'))\n tsc.compilerOptions.baseUrl = 'src'\n tsc.include = ['src/**/*.ts', 'src/**/*.tsx']\n writeFileSync(tscPath, JSON.stringify(tsc, null, 2) + '\\n')\n }\n\n // Import alias (custom or disabled)\n const tscPath = resolve(targetDir, 'tsconfig.json')\n const tsc = JSON.parse(readFileSync(tscPath, 'utf-8'))\n if (!options.aliases) {\n delete tsc.compilerOptions.baseUrl\n delete tsc.compilerOptions.paths\n } else if (opts.importAlias !== '@/*') {\n // Custom alias: replace @/* with user choice\n const prefix = opts.importAlias.replace('/*', '')\n tsc.compilerOptions.paths = {\n [`${prefix}/*`]: ['./*'],\n [`${prefix}/server/*`]: ['./server/*'],\n [`${prefix}/app/*`]: ['./app/*'],\n }\n }\n writeFileSync(tscPath, JSON.stringify(tsc, null, 2) + '\\n')\n\n // AGENTS.md\n if (!options.agentsMd) {\n const agentsPath = resolve(targetDir, 'AGENTS.md')\n if (existsSync(agentsPath)) unlinkSync(agentsPath)\n }\n}\n\n// ── Git init ──\n\nfunction initGit(targetDir: string): void {\n try {\n execSync('git init', { cwd: targetDir, stdio: 'ignore' })\n execSync('git add -A', { cwd: targetDir, stdio: 'ignore' })\n execSync('git commit -m \"Initial commit from create-theokit\" --no-verify', {\n cwd: targetDir,\n stdio: 'ignore',\n })\n } catch {\n // git not installed — silently skip\n }\n}\n\n// ── Example cloning ──\n\nfunction cloneExample(example: string, targetDir: string): void {\n const isUrl = example.startsWith('http://') || example.startsWith('https://')\n const repo = isUrl\n ? example\n : `https://github.com/usetheodev/theokit-examples/tree/main/${example}`\n\n if (isUrl) {\n // Full repo URL — shallow clone\n execSync(`git clone --depth 1 ${repo} ${targetDir}`, { stdio: 'inherit' })\n // Remove .git to let user init fresh\n rmSync(join(targetDir, '.git'), { recursive: true, force: true })\n } else {\n // Named example from theokit-examples repo — use degit pattern\n try {\n execSync(`npx --yes degit usetheodev/theokit-examples/${example} ${targetDir}`, {\n stdio: 'inherit',\n })\n } catch {\n throw new Error(\n `Example \"${example}\" not found. ` +\n `Browse available examples at https://github.com/usetheodev/theokit-examples`,\n )\n }\n }\n}\n\n// Auto-execute\nmain().catch((err: unknown) => {\n console.error(err)\n process.exit(1)\n})\n","import spawn from 'cross-spawn'\n\nimport type { PkgManager } from './pkg-manager.js'\n\nexport function runInstall(cwd: string, pkgManager: PkgManager): void {\n const result = spawn.sync(pkgManager, ['install'], {\n cwd,\n stdio: 'inherit',\n env: { ...process.env, NODE_ENV: 'development' },\n })\n\n if (result.status !== 0) {\n throw new Error(`Failed to install dependencies with ${pkgManager}`)\n }\n}\n","export type PkgManager = 'npm' | 'pnpm' | 'yarn' | 'bun'\n\nexport function detectPkgManager(): PkgManager {\n const ua = process.env.npm_config_user_agent ?? ''\n if (ua.startsWith('yarn')) return 'yarn'\n if (ua.startsWith('pnpm')) return 'pnpm'\n if (ua.startsWith('bun')) return 'bun'\n return 'npm'\n}\n","/**\n * Node version preflight for `create-theokit`.\n *\n * `@theokit/sdk` declares `engines.node: \">=22.12.0\"`. Users on older Node\n * hit cryptic `node:sqlite` / `better-sqlite3` ABI errors mid-chat without\n * any actionable diagnostic. This preflight runs at scaffold start, prints\n * a clear error, and exits before any FS write (ADR D4 of the plan).\n *\n * Zero-dep semver comparator — no `semver` package needed.\n */\n\n/** Minimum Node version required by `@theokit/sdk`. */\nexport const MIN_NODE_VERSION = '22.12.0'\n\n/**\n * Compare two semver strings (major.minor.patch). Strips leading `v` from\n * either side. Pre-release suffixes (e.g., `-rc.1`, `-nightly...`) are\n * parsed as the base patch — acceptable for a preflight (we're not gating\n * on exact pre-release ordering).\n *\n * Returns:\n * <0 when a < b\n * 0 when a == b\n * >0 when a > b\n */\nexport function compareSemver(a: string, b: string): number {\n const parse = (raw: string): [number, number, number] => {\n const stripped = raw.replace(/^v/, '').split('-')[0] ?? '0.0.0'\n const parts = stripped.split('.').map((s) => Number.parseInt(s, 10) || 0)\n return [parts[0] ?? 0, parts[1] ?? 0, parts[2] ?? 0]\n }\n const [aMaj, aMin, aPat] = parse(a)\n const [bMaj, bMin, bPat] = parse(b)\n if (aMaj !== bMaj) return aMaj - bMaj\n if (aMin !== bMin) return aMin - bMin\n return aPat - bPat\n}\n\n/**\n * Throw with an actionable message if `currentRaw` is below `minimum`.\n * Default minimum is `MIN_NODE_VERSION` (22.12.0).\n *\n * Called as the first line of `create-theokit`'s `main` so the preflight\n * fires before any directory is written.\n */\nexport function assertNodeVersion(currentRaw: string, minimum: string = MIN_NODE_VERSION): void {\n const current = currentRaw.replace(/^v/, '')\n if (compareSemver(currentRaw, minimum) < 0) {\n throw new Error(\n `create-theokit requires Node ${minimum} or later (the @theokit/sdk peer engines floor).\\n` +\n ` Detected: Node ${current}\\n` +\n ` Fix: nvm install 22 && nvm use 22\\n` +\n ` (or your version manager equivalent — fnm, volta, asdf, nvs)\\n`,\n )\n }\n}\n","/**\n * Interactive prompts for create-theokit.\n * Skipped when --yes flag is passed (uses defaults).\n *\n * Uses Node.js readline (zero deps) — not inquirer/prompts.\n */\nimport { createInterface } from 'node:readline'\n\nexport interface ProjectOptions {\n projectName: string\n typescript: boolean\n eslint: boolean\n tailwind: boolean\n srcDir: boolean\n aliases: boolean\n agentsMd: boolean\n}\n\nconst DEFAULTS: Omit<ProjectOptions, 'projectName'> = {\n typescript: true,\n eslint: true,\n tailwind: true,\n srcDir: false,\n aliases: true,\n agentsMd: true,\n}\n\nasync function ask(rl: ReturnType<typeof createInterface>, question: string, defaultVal: boolean): Promise<boolean> {\n return new Promise((resolve) => {\n const suffix = defaultVal ? '(Y/n)' : '(y/N)'\n rl.question(` ${question} ${suffix} `, (answer) => {\n const a = answer.trim().toLowerCase()\n if (a === '') resolve(defaultVal)\n else resolve(a === 'y' || a === 'yes')\n })\n })\n}\n\nasync function askChoice(rl: ReturnType<typeof createInterface>, question: string, choices: string[], defaultIdx = 0): Promise<number> {\n return new Promise((resolve) => {\n console.log(` ${question}`)\n for (let i = 0; i < choices.length; i++) {\n const marker = i === defaultIdx ? '❯' : ' '\n console.log(` ${marker} ${choices[i]}`)\n }\n rl.question(' Choice (number): ', (answer) => {\n const n = parseInt(answer.trim(), 10)\n resolve(n >= 1 && n <= choices.length ? n - 1 : defaultIdx)\n })\n })\n}\n\nexport async function runPrompts(projectName: string): Promise<ProjectOptions> {\n const rl = createInterface({ input: process.stdin, output: process.stdout })\n\n try {\n console.log('')\n const mode = await askChoice(rl, 'Would you like to use the recommended TheoKit defaults?', [\n 'Yes, use recommended defaults — TypeScript, ESLint, Tailwind CSS, AGENTS.md',\n 'No, customize settings',\n ], 0)\n\n if (mode === 0) {\n return { projectName, ...DEFAULTS }\n }\n\n const typescript = await ask(rl, 'Would you like to use TypeScript?', true)\n const eslint = await ask(rl, 'Would you like to use ESLint?', true)\n const tailwind = await ask(rl, 'Would you like to use Tailwind CSS?', true)\n const srcDir = await ask(rl, 'Would you like your code inside a `src/` directory?', false)\n const aliases = await ask(rl, 'Would you like to use import alias (@/*)?', true)\n const agentsMd = await ask(rl, 'Would you like to include AGENTS.md for coding agents?', true)\n\n return { projectName, typescript, eslint, tailwind, srcDir, aliases, agentsMd }\n } finally {\n rl.close()\n }\n}\n\nexport function getDefaults(projectName: string): ProjectOptions {\n return { projectName, ...DEFAULTS }\n}\n","/**\n * Build-time scaffold helper. All write paths derived from the trusted\n * targetDir (CLI argument, resolved absolute). Read paths are the\n * bundled service templates shipped with this package.\n */\n/**\n * Phase 4 — `--backend python|node` scaffolding (T4.1, T4.2).\n *\n * After the main TheoKit scaffold runs, this helper:\n * - Copies the requested service template(s) under `<target>/services/<name>/`\n * - Substitutes `{{name}}` in `.tmpl` files\n * - Renames `.tmpl` files to drop the suffix\n * - Injects services config into the user's `theo.config.ts`\n * - Injects `@hey-api/client-fetch` into the user's package.json (EC-10)\n */\nimport {\n cpSync,\n existsSync,\n readFileSync,\n readdirSync,\n statSync,\n writeFileSync,\n unlinkSync,\n} from 'node:fs'\nimport { dirname, join, resolve } from 'node:path'\nimport { fileURLToPath } from 'node:url'\n\nconst __dirname = dirname(fileURLToPath(import.meta.url))\n\n// node-only polyglot backend (decision 2026-06-17). Python scaffolding was\n// deferred — only the Node (Hono) sidecar template ships. Re-adding Python\n// requires restoring its template + an ADR with demand evidence.\nexport type BackendKind = 'node'\n\nconst VALID_BACKENDS = ['node'] as const\n\n/**\n * Parse `--backend node` (multi-value) from argv.\n *\n * Accepts:\n * --backend node\n * --backend=node\n *\n * Throws on unknown backend name (incl. `python`, which is not shipped).\n */\nexport function parseBackendFlags(args: string[]): BackendKind[] {\n const out: BackendKind[] = []\n for (let i = 0; i < args.length; i++) {\n const a = args[i] ?? ''\n let value: string | undefined\n if (a === '--backend') {\n value = args[i + 1]\n i++\n } else if (a.startsWith('--backend=')) {\n value = a.slice('--backend='.length)\n }\n if (value === undefined) continue\n if (!(VALID_BACKENDS as readonly string[]).includes(value)) {\n throw new Error(\n `unknown --backend value: '${value}'. Valid options: ${VALID_BACKENDS.join(', ')}.`,\n )\n }\n out.push(value as BackendKind)\n }\n return out\n}\n\nconst BACKEND_CONFIG: Record<\n BackendKind,\n {\n templateDir: string\n serviceName: string\n port: number\n proxy: string\n dev: string\n start: string\n }\n> = {\n node: {\n templateDir: 'agent-node',\n serviceName: 'worker',\n port: 8002,\n proxy: '/api/worker',\n dev: 'pnpm dev',\n start: 'pnpm start',\n },\n}\n\nfunction getServiceTemplateDir(kind: BackendKind): string {\n return resolve(__dirname, '../templates/services', BACKEND_CONFIG[kind].templateDir)\n}\n\nfunction substituteTmpls(dir: string, projectName: string): void {\n for (const entry of readdirSync(dir)) {\n const full = join(dir, entry)\n const stat = statSync(full)\n if (stat.isDirectory()) {\n substituteTmpls(full, projectName)\n continue\n }\n if (entry.endsWith('.tmpl')) {\n const content = readFileSync(full, 'utf-8').replace(/\\{\\{name\\}\\}/g, projectName)\n const dest = full.replace(/\\.tmpl$/, '')\n writeFileSync(dest, content)\n unlinkSync(full)\n }\n }\n}\n\ninterface ServiceEntry {\n runtime: BackendKind\n port: number\n proxy: string\n dev: string\n start: string\n}\n\n/**\n * Build the `services: {}` snippet to inject into `theo.config.ts`.\n * Returns the inner record literal — caller wraps in `services: { ... }`.\n */\nexport function buildServicesSnippet(selections: { name: string; entry: ServiceEntry }[]): string {\n if (selections.length === 0) return ''\n const blocks = selections.map(({ name, entry }) => {\n return ` ${name}: {\n runtime: '${entry.runtime}',\n port: ${String(entry.port)},\n proxy: '${entry.proxy}',\n dev: ${JSON.stringify(entry.dev)},\n start: ${JSON.stringify(entry.start)},\n },`\n })\n return ` services: {\\n${blocks.join('\\n')}\\n },\\n`\n}\n\n/**\n * Insert the services block into an existing `theo.config.ts`.\n * Strategy: find `defineConfig({` and append the services block before the closing brace.\n */\nexport function injectServicesIntoConfig(configSource: string, snippet: string): string {\n if (snippet.length === 0) return configSource\n if (configSource.includes('services:')) return configSource // already present\n\n // Match the LAST `}` before the closing of defineConfig({...})\n const re = /defineConfig\\(\\{([\\s\\S]*?)\\}\\)/m\n const match = re.exec(configSource)\n if (!match) return configSource\n\n const inner = match[1]\n // Strip trailing whitespace without backtracking-prone \\s+$ regex.\n let trimEnd = inner.length\n while (trimEnd > 0 && /\\s/.test(inner.charAt(trimEnd - 1))) {\n trimEnd--\n }\n const trimmed = inner.slice(0, trimEnd)\n const sep = trimmed.length > 0 && !trimmed.endsWith(',') ? ',\\n' : '\\n'\n const newInner = `${trimmed}${sep}${snippet}`\n return configSource.replace(re, `defineConfig({${newInner}})`)\n}\n\nexport function injectHeyApiDep(packageJsonSource: string): string {\n const pkg = JSON.parse(packageJsonSource) as {\n dependencies?: Record<string, string>\n }\n pkg.dependencies = pkg.dependencies ?? {}\n if (!('@hey-api/client-fetch' in pkg.dependencies)) {\n pkg.dependencies['@hey-api/client-fetch'] = '^0.6.0'\n }\n return JSON.stringify(pkg, null, 2) + '\\n'\n}\n\nexport interface ScaffoldServicesOptions {\n /** Target project directory (already scaffolded with the TS template). */\n targetDir: string\n /** Project name (substituted into .tmpl files). */\n projectName: string\n /** Which backends to scaffold. */\n backends: BackendKind[]\n}\n\nexport function scaffoldServices(options: ScaffoldServicesOptions): void {\n if (options.backends.length === 0) return\n\n const selections: { name: string; entry: ServiceEntry }[] = []\n\n for (const kind of options.backends) {\n const cfg = BACKEND_CONFIG[kind]\n const src = getServiceTemplateDir(kind)\n // Schema contract: dev/start commands run from `services/<serviceName>/` cwd\n // (services/schema/schema.ts line 35). The destination MUST equal serviceName\n // so the orchestrator's cwd resolution matches the on-disk directory.\n const dest = join(options.targetDir, 'services', cfg.serviceName)\n if (!existsSync(src)) {\n throw new Error(`service template not found: ${src}`)\n }\n cpSync(src, dest, { recursive: true })\n substituteTmpls(dest, options.projectName)\n\n selections.push({\n name: cfg.serviceName,\n entry: {\n runtime: kind,\n port: cfg.port,\n proxy: cfg.proxy,\n dev: cfg.dev,\n start: cfg.start,\n },\n })\n }\n\n // Inject services into theo.config.ts\n const configPath = join(options.targetDir, 'theo.config.ts')\n if (existsSync(configPath)) {\n const cfgSrc = readFileSync(configPath, 'utf-8')\n const snippet = buildServicesSnippet(selections)\n const updated = injectServicesIntoConfig(cfgSrc, snippet)\n if (updated !== cfgSrc) {\n writeFileSync(configPath, updated)\n }\n }\n\n // EC-10: inject @hey-api/client-fetch into user's package.json\n const pkgPath = join(options.targetDir, 'package.json')\n if (existsSync(pkgPath)) {\n const pkgSrc = readFileSync(pkgPath, 'utf-8')\n const updated = injectHeyApiDep(pkgSrc)\n writeFileSync(pkgPath, updated)\n }\n\n // Rename .gitignore for services if needed (none currently shipped, but reserved hook)\n}\n","import {\n cpSync,\n existsSync,\n readdirSync,\n readFileSync,\n rmSync,\n statSync,\n unlinkSync,\n writeFileSync,\n} from 'node:fs'\nimport { dirname, join, resolve } from 'node:path'\nimport { fileURLToPath } from 'node:url'\n\n// ESM has no CJS `__dirname` global — derive it (mirrors src/index.ts + src/scaffold-services.ts). Without\n// this the published bundle throws `__dirname is not defined` at runtime (vitest provides the global, so the\n// unit tests never caught it — only running `npx create-theokit --surface tui` for real surfaced it).\nconst __dirname = dirname(fileURLToPath(import.meta.url))\n\n/**\n * M45 (ADR-0054) — `create-theokit --surface web|tui|desktop`.\n *\n * A FLAG-driven additive scaffold (mirrors `--backend` / `scaffoldServices`), NOT a new top-level\n * template (ADR-0023 default-only respected). `web` is the default (the existing web app — no-op).\n * `tui` / `desktop` copy a template fragment (`templates/surfaces/<kind>/`) onto the scaffolded default,\n * mutate `package.json` (drop web-only deps, add surface deps + scripts), and remove the web UI. Each\n * scaffolded surface consumes the agent via the M41/M42/M44 UNIFIED client (ADR-0054 D2), not the raw\n * seam. All Tauri/Ink boilerplate lives HERE in the scaffolder templates — framework core stays agnostic.\n */\nexport type SurfaceKind = 'web' | 'tui' | 'desktop'\n\nconst VALID_SURFACES = ['web', 'tui', 'desktop'] as const\n\n/**\n * Web-only deps dropped for the tui/desktop surfaces (they ship no web UI). `react-router` is NOT dropped\n * — `theokit` declares it a REQUIRED peer, so removing it breaks `npm install` (ERESOLVE).\n */\nconst WEB_ONLY_DEPS = ['@theokit/ui', '@usetheo/ui', 'lucide-react'] as const\nconst WEB_ONLY_DEV_DEPS = ['tailwindcss', '@tailwindcss/vite', 'tailwindcss-animate'] as const\n/** Web UI files removed for the tui/desktop surfaces. */\nconst WEB_ONLY_FILES = ['app', 'index.html', 'tailwind.config.ts', 'postcss.config.js'] as const\n\ninterface SurfaceConfig {\n /** The template fragment dir under `templates/surfaces/`. */\n fragment: string\n /** Deps ADDED for this surface. */\n deps: Record<string, string>\n /** Dev deps ADDED for this surface. */\n devDeps: Record<string, string>\n /** Scripts SET for this surface (override the web dev/build). */\n scripts: Record<string, string>\n /** `tsconfig.json` `include` for this surface (the default's `app/**` is removed with the web UI). */\n tsconfigInclude: string[]\n}\n\nconst SURFACE_CONFIG: Record<Exclude<SurfaceKind, 'web'>, SurfaceConfig> = {\n tui: {\n fragment: 'tui',\n // `@theokit/tui` renders the conversation (`<ChatThread>` + the `./ai-sdk` UIMessage adapter). `ai` is\n // the UIMessageStream type the unified client + adapter consume (was transitive via `@theokit/ui`, dropped\n // for tui), so declare it explicitly. `ink@7` is the React-19 line (ink@5 crashes on React 19 with\n // `ReactCurrentOwner` — the default template pins react@19; ink@6.0.0+ moved its peer to react>=19) and\n // matches @theokit/tui's own ink@^7.1.0, so the app's `import 'ink'` dedupes to one React-19 ink.\n deps: { '@theokit/tui': '^0.30.0', ink: '^7.1.0', ai: '^7.0.0' },\n devDeps: { tsx: '^4.19.0' },\n scripts: { dev: 'tsx tui/main.tsx', start: 'tsx tui/main.tsx' },\n tsconfigInclude: ['tui/**/*.ts', 'tui/**/*.tsx', 'server/**/*.ts', 'agents/**/*.ts'],\n },\n desktop: {\n fragment: 'desktop',\n // M47: the webview is a React app rendering with `@theokit/ui`, driven by `useAgent` over a\n // `ChannelTransport` whose source is `@theokit/tauri`'s `createTauriChannelSource`; the Node sidecar\n // runs the turn via `@theokit/tauri/sidecar`. `ai` = the UIMessageStream reader + UIMessage type (was\n // transitive via `@theokit/ui`, re-added explicitly here). react/react-dom are inherited from the default.\n deps: { '@theokit/ui': '^1.0.0', '@theokit/tauri': '^0.1.1', ai: '^7.0.0' },\n devDeps: {\n tsx: '^4.19.0',\n '@tauri-apps/cli': '^2.0.0',\n vite: '^6.0.0',\n '@vitejs/plugin-react': '^4.3.0',\n },\n scripts: {\n dev: 'tauri dev',\n tauri: 'tauri',\n 'build:frontend': 'vite build frontend',\n // Generates the Tauri externalBin launcher (src-tauri/binaries/theo-sidecar-<triple>) the Rust\n // shell spawns. Wired into tauri.conf.json beforeDev/BuildCommand — regenerated each launch.\n 'build:sidecar': 'node scripts/build-sidecar.mjs',\n },\n tsconfigInclude: [\n 'sidecar/**/*.ts',\n 'frontend/src/**/*.ts',\n 'frontend/src/**/*.tsx',\n 'server/**/*.ts',\n 'agents/**/*.ts',\n ],\n },\n}\n\n/** Parse `--surface <kind>` / `--surface=<kind>`; default `web`. Fail-fast on an unknown value. */\nexport function parseSurfaceFlags(args: string[]): SurfaceKind {\n let surface: SurfaceKind = 'web'\n for (let i = 0; i < args.length; i++) {\n const a = args[i] ?? ''\n let value: string | undefined\n if (a === '--surface') {\n value = args[i + 1]\n i++\n } else if (a.startsWith('--surface=')) {\n value = a.slice('--surface='.length)\n }\n if (value === undefined) continue\n if (!(VALID_SURFACES as readonly string[]).includes(value)) {\n throw new Error(\n `unknown --surface value: '${value}'. Valid options: ${VALID_SURFACES.join(', ')}.`,\n )\n }\n surface = value as SurfaceKind\n }\n return surface\n}\n\n/** Locate the fragment dir shipped alongside the compiled scaffolder. */\nfunction getSurfaceFragmentDir(fragment: string): string {\n return resolve(__dirname, '../templates/surfaces', fragment)\n}\n\n/** Recursively substitute `{{name}}` in `.tmpl` files (mirrors scaffoldServices). */\nfunction substituteTmpls(dir: string, projectName: string): void {\n for (const entry of readdirSync(dir)) {\n const full = join(dir, entry)\n if (statSync(full).isDirectory()) {\n substituteTmpls(full, projectName)\n continue\n }\n if (entry.endsWith('.tmpl')) {\n const content = readFileSync(full, 'utf-8').replace(/\\{\\{name\\}\\}/g, projectName)\n writeFileSync(full.replace(/\\.tmpl$/, ''), content)\n unlinkSync(full)\n }\n }\n}\n\nexport interface ApplySurfaceOptions {\n targetDir: string\n projectName: string\n surface: SurfaceKind\n /** Test-only: force a failure to exercise the caller's rollback (mirrors --bare `_testForceError`). */\n _testForceError?: string\n}\n\ninterface PartialPackageJson {\n dependencies?: Record<string, string>\n devDependencies?: Record<string, string>\n scripts?: Record<string, string>\n [key: string]: unknown\n}\n\n/**\n * Apply a surface onto a freshly-scaffolded default template. `web` is a no-op (the default IS web).\n * `tui`/`desktop` copy the fragment, drop web-only deps + UI, and add the surface's deps/scripts. Throws\n * on any failure so the CLI can roll the whole target dir back (EC-4), exactly like `--bare`.\n */\nexport function applySurface(options: ApplySurfaceOptions): void {\n if (options._testForceError !== undefined) {\n throw new Error(`Forced surface failure: ${options._testForceError}`)\n }\n if (options.surface === 'web') return\n\n const cfg = SURFACE_CONFIG[options.surface]\n const src = getSurfaceFragmentDir(cfg.fragment)\n if (!existsSync(src)) {\n throw new Error(`surface fragment not found: ${src}`)\n }\n\n // 1. Copy the fragment onto the target, then substitute {{name}}.\n cpSync(src, options.targetDir, { recursive: true })\n substituteTmpls(options.targetDir, options.projectName)\n\n // 2. Remove the web UI (a tui/desktop app ships no web surface).\n for (const rel of WEB_ONLY_FILES) {\n const p = join(options.targetDir, rel)\n if (existsSync(p)) rmSync(p, { recursive: true, force: true })\n }\n\n // 3. Mutate package.json: drop web-only deps, add surface deps + scripts.\n const pkgPath = join(options.targetDir, 'package.json')\n if (existsSync(pkgPath)) {\n const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8')) as PartialPackageJson\n pkg.dependencies = { ...dropKeys(pkg.dependencies, WEB_ONLY_DEPS), ...cfg.deps }\n pkg.devDependencies = { ...dropKeys(pkg.devDependencies, WEB_ONLY_DEV_DEPS), ...cfg.devDeps }\n pkg.scripts = { ...(pkg.scripts ?? {}), ...cfg.scripts }\n writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}\\n`)\n }\n\n // 4. Point `tsconfig.json` `include` at the surface's source (the default's `app/**` went with the web\n // UI) — so `tsc` in the generated project type-checks the surface entry files (the unified-client wiring).\n const tsconfigPath = join(options.targetDir, 'tsconfig.json')\n if (existsSync(tsconfigPath)) {\n const tsconfig = JSON.parse(readFileSync(tsconfigPath, 'utf-8')) as { include?: string[] }\n tsconfig.include = cfg.tsconfigInclude\n writeFileSync(tsconfigPath, `${JSON.stringify(tsconfig, null, 2)}\\n`)\n }\n}\n\n/** Return a copy of `record` without `keys` (no dynamic `delete` — filter-rebuild). */\nfunction dropKeys(\n record: Record<string, string> | undefined,\n keys: readonly string[],\n): Record<string, string> {\n return Object.fromEntries(Object.entries(record ?? {}).filter(([k]) => !keys.includes(k)))\n}\n","/**\n * `create-theokit` scaffold tool. All write paths are derived from the\n * user-supplied target directory (CLI argument, resolved to absolute).\n * Read paths are the bundled `templates/` shipped with this package.\n * Build-time tool — no HTTP input.\n */\nimport {\n existsSync,\n cpSync,\n readFileSync,\n writeFileSync,\n renameSync,\n unlinkSync,\n readdirSync,\n rmSync,\n statSync,\n} from 'node:fs'\nimport { resolve, join, dirname } from 'node:path'\nimport { fileURLToPath } from 'node:url'\n\nimport { applyBareTransform } from './bare-transform.js'\n\nconst __dirname = dirname(fileURLToPath(import.meta.url))\n\nfunction getTemplateDir(templateName = 'default'): string {\n return resolve(__dirname, '../templates', templateName)\n}\n\nfunction isValidProjectName(name: string): boolean {\n return /^[a-z0-9][a-z0-9._-]*$/.test(name)\n}\n\nexport interface ScaffoldOptions {\n bare?: boolean\n /** Test-only — force the bare transform to throw to validate EC-4 rollback. */\n _testForceTransformError?: string\n}\n\nexport function scaffold(\n targetDir: string,\n projectName: string,\n templateName = 'default',\n options: ScaffoldOptions = {},\n): void {\n // EC-4 + ADR D5: --bare only applies to default template\n if (options.bare && templateName !== 'default') {\n throw new Error(\n `--bare flag only applies to the default template; got \"${templateName}\". ` +\n `Use \\`npx create-theokit <name> --template=default --bare\\` or pick a different template.`,\n )\n }\n\n const templateDir = getTemplateDir(templateName)\n\n if (!existsSync(templateDir)) {\n throw new Error(`Template \"${templateName}\" not found. Available templates: default`)\n }\n\n // Bug #1 fix: \".\" means current directory — use dir basename as project name\n const resolvedName =\n projectName === '.' ? (resolve(targetDir).split('/').pop() ?? 'my-app') : projectName\n\n if (!isValidProjectName(resolvedName)) {\n throw new Error(\n `Invalid project name \"${resolvedName}\". ` +\n `Use lowercase letters, numbers, hyphens, and dots. Must start with a letter or number.`,\n )\n }\n\n if (existsSync(targetDir)) {\n const contents = readdirSync(targetDir)\n if (contents.length > 0) {\n throw new Error(`Directory \"${targetDir}\" is not empty. Please use an empty directory.`)\n }\n }\n\n cpSync(templateDir, targetDir, { recursive: true })\n\n const gitignoreSrc = join(targetDir, '_gitignore')\n const gitignoreDest = join(targetDir, '.gitignore')\n if (existsSync(gitignoreSrc)) {\n renameSync(gitignoreSrc, gitignoreDest)\n }\n\n // dot-claude/ → .claude/ (npm ignores dotfolders in published packages)\n const dotClaudeSrc = join(targetDir, 'dot-claude')\n const dotClaudeDest = join(targetDir, '.claude')\n if (existsSync(dotClaudeSrc)) {\n renameSync(dotClaudeSrc, dotClaudeDest)\n }\n\n // Apply {{name}} substitution to every `*.tmpl` file in the target dir.\n // Each `foo.tmpl` becomes `foo` with placeholders replaced. Walks only\n // the project root (deeper subfolders don't currently need templating).\n for (const entry of readdirSync(targetDir)) {\n if (!entry.endsWith('.tmpl')) continue\n const src = join(targetDir, entry)\n const stat = statSync(src)\n if (!stat.isFile()) continue\n const dst = join(targetDir, entry.slice(0, -'.tmpl'.length))\n const content = readFileSync(src, 'utf-8')\n const replaced = content.replace(/\\{\\{name\\}\\}/g, resolvedName)\n writeFileSync(dst, replaced)\n unlinkSync(src)\n }\n\n // T4.1 — Apply --bare transform with EC-4 atomic rollback\n if (options.bare) {\n try {\n applyBareTransform(targetDir, {\n _testForceError: options._testForceTransformError,\n })\n } catch (err) {\n // EC-4: roll back partial state\n rmSync(targetDir, { recursive: true, force: true })\n const original = err instanceof Error ? err.message : String(err)\n throw new Error(\n `Scaffold rolled back: bare transform failed. Check filesystem perms.\\nOriginal error: ${original}`,\n )\n }\n }\n}\n","/**\n * Scaffold transform. Mutates files inside the freshly-created target\n * directory whose absolute path is the function input. No HTTP input.\n */\n/**\n * T4.1 — `--bare` transformation.\n *\n * Applied AFTER the default template is copied. Removes:\n * - `@theokit/ui` from `package.json` dependencies (TheoUI bundled components)\n * - `@theokit/sdk` from `package.json` dependencies (agent SDK — see below)\n * - `@theokit/agents` from `package.json` dependencies (only agents/chat.ts used it)\n * - `app/page.tsx` agent-surface content (replaces with Hello Theo)\n * - `agents/chat.ts` (the demo agent — depends on the SDK + TheoUI page)\n * - `tailwind.config.ts` + `postcss.config.js` (Tailwind toolchain — only\n * needed by the @theokit/ui-driven default surface)\n * - tailwind* + postcss* from devDependencies (toolchain cleanup)\n *\n * Why SDK removal is in --bare:\n * `@theokit/sdk` is not yet on the public npm registry (operator-deferred\n * publish per macro roadmap item #3). A user running `npx create-theokit`\n * without `--bare` hits `npm install` → 404. The `--bare` path produces a\n * scaffold that ALWAYS works without registry dependencies — Hello Theo\n * with a clean structure to grow into.\n *\n * EC-4: callers MUST wrap this in try/catch + `rmSync` rollback so a partial\n * transform never leaves the target dir in a broken state.\n */\n\nimport { existsSync, readFileSync, writeFileSync, unlinkSync } from 'node:fs'\nimport { join } from 'node:path'\n\nconst HELLO_PAGE = `export default function Page() {\n return <h1>Hello Theo</h1>\n}\n`\n\nexport interface BareTransformOptions {\n /** Test-only — force a synthetic write failure to validate rollback path. */\n _testForceError?: string\n}\n\nexport function applyBareTransform(targetDir: string, options: BareTransformOptions = {}): void {\n if (options._testForceError) {\n throw new Error(`Forced transform failure: ${options._testForceError}`)\n }\n\n // 1. Remove @theokit/ui + @theokit/sdk + tailwind toolchain from deps\n const pkgPath = join(targetDir, 'package.json')\n if (existsSync(pkgPath)) {\n interface PartialPackageJson {\n dependencies?: Record<string, string>\n devDependencies?: Record<string, string>\n [key: string]: unknown\n }\n const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8')) as PartialPackageJson\n if (pkg.dependencies) {\n delete pkg.dependencies['@theokit/ui']\n // Drop SDK — operator-deferred npm publish (macro roadmap item #3).\n // Without removal, `npm install` hits 404 for any consumer outside\n // the workspace.\n delete pkg.dependencies['@theokit/sdk']\n // --bare removes the demo agent (agents/chat.ts), so its runtime dep\n // (@theokit/agents, imported only by that file) goes with it.\n delete pkg.dependencies['@theokit/agents']\n // lucide-react ships with the TheoUI surface; --bare doesn't render\n // any icons so it's safe to drop.\n delete pkg.dependencies['lucide-react']\n }\n if (pkg.devDependencies) {\n // Tailwind toolchain is only needed by the @theokit/ui-driven default\n // surface. --bare ships unstyled Hello Theo; no Tailwind required.\n delete pkg.devDependencies.tailwindcss\n delete pkg.devDependencies['tailwindcss-animate']\n delete pkg.devDependencies.postcss\n delete pkg.devDependencies.autoprefixer\n }\n writeFileSync(pkgPath, `${JSON.stringify(pkg, null, 2)}\\n`)\n }\n\n // 2. Replace app/page.tsx with Hello Theo\n const pagePath = join(targetDir, 'app/page.tsx')\n if (existsSync(pagePath)) {\n writeFileSync(pagePath, HELLO_PAGE)\n }\n\n // 3. Remove the demo chat agent (the `agents/chat.ts` file + its TheoUI page)\n const chatPath = join(targetDir, 'agents/chat.ts')\n if (existsSync(chatPath)) {\n unlinkSync(chatPath)\n }\n\n // 4. Remove tailwind + postcss config files (toolchain dropped from devDeps)\n const tailwindCfg = join(targetDir, 'tailwind.config.ts')\n if (existsSync(tailwindCfg)) {\n unlinkSync(tailwindCfg)\n }\n const postcssCfg = join(targetDir, 'postcss.config.js')\n if (existsSync(postcssCfg)) {\n unlinkSync(postcssCfg)\n }\n}\n"],"mappings":";;;AAAA,SAAS,gBAAgB;AACzB;AAAA,EACE,gBAAAA;AAAA,EACA,iBAAAC;AAAA,EACA,cAAAC;AAAA,EACA;AAAA,EACA,cAAAC;AAAA,EACA,cAAAC;AAAA,EACA,UAAAC;AAAA,OACK;AACP,SAAS,WAAAC,UAAS,QAAAC,aAAY;;;ACV9B,OAAO,WAAW;AAIX,SAAS,WAAW,KAAa,YAA8B;AACpE,QAAM,SAAS,MAAM,KAAK,YAAY,CAAC,SAAS,GAAG;AAAA,IACjD;AAAA,IACA,OAAO;AAAA,IACP,KAAK,EAAE,GAAG,QAAQ,KAAK,UAAU,cAAc;AAAA,EACjD,CAAC;AAED,MAAI,OAAO,WAAW,GAAG;AACvB,UAAM,IAAI,MAAM,uCAAuC,UAAU,EAAE;AAAA,EACrE;AACF;;;ACZO,SAAS,mBAA+B;AAC7C,QAAM,KAAK,QAAQ,IAAI,yBAAyB;AAChD,MAAI,GAAG,WAAW,MAAM,EAAG,QAAO;AAClC,MAAI,GAAG,WAAW,MAAM,EAAG,QAAO;AAClC,MAAI,GAAG,WAAW,KAAK,EAAG,QAAO;AACjC,SAAO;AACT;;;ACIO,IAAM,mBAAmB;AAazB,SAAS,cAAc,GAAW,GAAmB;AAC1D,QAAM,QAAQ,CAAC,QAA0C;AACvD,UAAM,WAAW,IAAI,QAAQ,MAAM,EAAE,EAAE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","rmSync","resolve","join","resolve","cpSync","existsSync","readdirSync","readFileSync","statSync","unlinkSync","writeFileSync","dirname","join","resolve","fileURLToPath","__dirname","substituteTmpls","existsSync","cpSync","readFileSync","writeFileSync","unlinkSync","readdirSync","rmSync","statSync","resolve","join","dirname","fileURLToPath","existsSync","readFileSync","writeFileSync","unlinkSync","join","__dirname","dirname","fileURLToPath","resolve","existsSync","readdirSync","cpSync","join","statSync","readFileSync","writeFileSync","unlinkSync","rmSync","resolve","rmSync","existsSync","unlinkSync","readFileSync","writeFileSync","renameSync","tscPath","tsc","join"]}
package/package.json CHANGED
@@ -1,14 +1,9 @@
1
1
  {
2
2
  "name": "create-theokit",
3
- "version": "1.2.9",
3
+ "version": "1.3.0",
4
4
  "type": "module",
5
5
  "description": "Scaffold a new TheoKit project",
6
6
  "license": "Apache-2.0",
7
- "scripts": {
8
- "build": "tsup",
9
- "test": "vitest run",
10
- "test:watch": "vitest"
11
- },
12
7
  "bin": {
13
8
  "create-theokit": "./dist/cli.js"
14
9
  },
@@ -25,5 +20,10 @@
25
20
  },
26
21
  "engines": {
27
22
  "node": ">=22.12.0"
23
+ },
24
+ "scripts": {
25
+ "build": "tsup",
26
+ "test": "vitest run",
27
+ "test:watch": "vitest"
28
28
  }
29
- }
29
+ }
@@ -32,7 +32,9 @@ const MODEL_NAME = 'gpt-4o-mini'
32
32
  const GREETING: UIMessage = {
33
33
  id: 'greeting',
34
34
  role: 'assistant',
35
- parts: [{ type: 'text', text: "Hi — I'm your TheoKit agent. Ask me anything and I'll stream a reply." }],
35
+ parts: [
36
+ { type: 'text', text: "Hi — I'm your TheoKit agent. Ask me anything and I'll stream a reply." },
37
+ ],
36
38
  }
37
39
 
38
40
  /** Honest starter prompts — each sends a real message the scaffold agent can actually answer. */
@@ -18,16 +18,30 @@ The desktop build needs the **Rust toolchain + Tauri v2 prerequisites** (see
18
18
  <https://v2.tauri.app/start/prerequisites/>) in addition to Node. The Node/TypeScript tiers (webview,
19
19
  sidecar) run without Rust; the packaged desktop app requires it.
20
20
 
21
- ## Run
21
+ ## Run (macOS / Linux)
22
22
 
23
23
  ```bash
24
- export OPENROUTER_API_KEY=... # or ANTHROPIC_API_KEY
25
- # 1. Build the sidecar to src-tauri/binaries/theo-sidecar-<target-triple> (see externalBin in tauri.conf.json).
26
- # e.g. bundle sidecar/sidecar.ts with your Node launcher of choice, or run it via a `node` externalBin.
27
- # 2. Launch the desktop shell (builds the webview via Vite, then runs Tauri):
28
- npm run dev # tauri dev
24
+ export OPENROUTER_API_KEY=... # or ANTHROPIC_API_KEY
25
+ npm install
26
+ npm run dev # tauri dev
29
27
  ```
30
28
 
29
+ `tauri dev` runs `beforeDevCommand` (`node scripts/build-sidecar.mjs && vite frontend`) first, so the
30
+ sidecar launcher and the webview are ready before the Rust shell spawns them — no manual step. The
31
+ sidecar launcher (`src-tauri/binaries/theo-sidecar-<target-triple>`) is a shim that runs
32
+ `sidecar/sidecar.ts` via the app's own `tsx` (Node runtime — the ai-sdk streams correctly there); it is
33
+ regenerated on every launch, so a moved project self-heals.
34
+
31
35
  The agent lives in `agents/chat.ts` (edit its model / system prompt). Wire HITL by adding a
32
36
  `@HumanInTheLoop`-gated tool — the sidecar emits `tool-approval-request`, the webview shows Approve/Deny,
33
37
  and `useAgent(...).approve(id, { approved })` routes the decision through the transport's `settle`.
38
+
39
+ ## Packaging (distributable app + Windows)
40
+
41
+ The dev launcher above is a POSIX shim that depends on the app's `node_modules` (tsx). For a **distributable**
42
+ build (`npm run build` → `tauri build`) — and for **Windows dev**, where Tauri requires a real `.exe`
43
+ externalBin that a shell shim cannot satisfy (`build:sidecar` fails loud on win32 pointing here) — compile
44
+ `sidecar/sidecar.ts` to a **self-contained binary** at `src-tauri/binaries/theo-sidecar-<target-triple>[.exe]`
45
+ before building. Options: **Node SEA** (single-executable app — runs under Node, where the stream works),
46
+ or `bun build --compile`/`pkg` (verify the ai-sdk token stream survives your bundler first). Replace the
47
+ `build:sidecar` script with your compile command and keep the same output path.
@@ -0,0 +1,66 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Generate the Tauri externalBin launcher for the Node sidecar.
4
+ *
5
+ * The Rust shell spawns the agent turn via `app.shell().sidecar("theo-sidecar")` (src-tauri/src/lib.rs),
6
+ * which Tauri resolves to `src-tauri/binaries/theo-sidecar-<target-triple>[.exe]`. That file must exist
7
+ * before `tauri dev`/`tauri build` — this script creates it. It is wired into `beforeDevCommand` /
8
+ * `beforeBuildCommand` in `src-tauri/tauri.conf.json`, so it runs automatically and is regenerated
9
+ * (with the current absolute path) on every launch.
10
+ *
11
+ * The launcher is a tiny shim that runs `sidecar/sidecar.ts` via the app's own `tsx` — no bundle/compile
12
+ * step, and the sidecar runs under **Node**, where the ai-sdk streams correctly (a `bun build --compile`
13
+ * self-contained binary drops the token stream). This is the dev path. For a DISTRIBUTABLE desktop app
14
+ * (`tauri build`), ship a real self-contained sidecar binary instead — see README-surface.md § Packaging.
15
+ */
16
+ import { execFileSync } from 'node:child_process'
17
+ import { chmodSync, mkdirSync, writeFileSync } from 'node:fs'
18
+ import { dirname, join, resolve } from 'node:path'
19
+ import { fileURLToPath } from 'node:url'
20
+
21
+ const appRoot = resolve(dirname(fileURLToPath(import.meta.url)), '..')
22
+
23
+ /** The Rust host target triple — Tauri's externalBin filename suffix. */
24
+ function targetTriple() {
25
+ try {
26
+ const out = execFileSync('rustc', ['-vV'], { encoding: 'utf-8' })
27
+ const match = out.match(/host:\s*(\S+)/)
28
+ if (!match) throw new Error('could not parse `host:` from `rustc -vV`')
29
+ return match[1]
30
+ } catch (err) {
31
+ throw new Error(
32
+ `[build-sidecar] the Tauri desktop build needs the Rust toolchain (rustc) to resolve the ` +
33
+ `externalBin target triple. Install it: https://v2.tauri.app/start/prerequisites/\n` +
34
+ `Underlying error: ${err instanceof Error ? err.message : String(err)}`,
35
+ )
36
+ }
37
+ }
38
+
39
+ const triple = targetTriple()
40
+ const isWindows = process.platform === 'win32'
41
+ const binDir = join(appRoot, 'src-tauri', 'binaries')
42
+ mkdirSync(binDir, { recursive: true })
43
+
44
+ const tsxBin = join(appRoot, 'node_modules', '.bin', isWindows ? 'tsx.cmd' : 'tsx')
45
+ const entry = join(appRoot, 'sidecar', 'sidecar.ts')
46
+
47
+ if (isWindows) {
48
+ // Tauri resolves the Windows sidecar as `<name>-<triple>.exe`, which must be a real PE executable —
49
+ // a shell/batch shim cannot satisfy that. Fail loud with the packaging path (Rule 8: fail clear).
50
+ throw new Error(
51
+ `[build-sidecar] Windows desktop dev needs a compiled sidecar binary at ` +
52
+ `src-tauri/binaries/theo-sidecar-${triple}.exe (Tauri requires a real .exe). ` +
53
+ `Compile sidecar/sidecar.ts to a self-contained binary — see README-surface.md § Packaging — ` +
54
+ `then re-run. macOS/Linux dev uses the tsx shim this script writes automatically.`,
55
+ )
56
+ }
57
+
58
+ // macOS/Linux: an executable POSIX shim that execs the app's tsx on the sidecar source. Absolute paths
59
+ // keep it valid no matter where Tauri invokes it from; it is regenerated each launch so a moved project
60
+ // self-heals on the next `tauri dev`.
61
+ const shimPath = join(binDir, `theo-sidecar-${triple}`)
62
+ const shim = `#!/bin/sh\n# Generated by scripts/build-sidecar.mjs — do not edit (regenerated each launch).\nexec "${tsxBin}" "${entry}" "$@"\n`
63
+ writeFileSync(shimPath, shim)
64
+ chmodSync(shimPath, 0o755)
65
+
66
+ process.stdout.write(`[build-sidecar] wrote ${shimPath}\n`)
@@ -6,8 +6,8 @@
6
6
  "build": {
7
7
  "frontendDist": "../frontend/dist",
8
8
  "devUrl": "http://localhost:5173",
9
- "beforeDevCommand": "vite frontend",
10
- "beforeBuildCommand": "vite build frontend"
9
+ "beforeDevCommand": "node scripts/build-sidecar.mjs && vite frontend",
10
+ "beforeBuildCommand": "node scripts/build-sidecar.mjs && vite build frontend"
11
11
  },
12
12
  "app": {
13
13
  "windows": [
@@ -25,6 +25,13 @@
25
25
  "bundle": {
26
26
  "active": true,
27
27
  "targets": "all",
28
- "externalBin": ["binaries/theo-sidecar"]
28
+ "externalBin": ["binaries/theo-sidecar"],
29
+ "icon": [
30
+ "icons/32x32.png",
31
+ "icons/128x128.png",
32
+ "icons/128x128@2x.png",
33
+ "icons/icon.icns",
34
+ "icons/icon.ico"
35
+ ]
29
36
  }
30
37
  }