vybekiit 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +47 -0
- package/README.md +84 -0
- package/dist/index.js +953 -0
- package/package.json +31 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# VybeKiit licensing
|
|
2
|
+
|
|
3
|
+
This repository is **dual-licensed by component**, matching the Owned vs Maintained split (see
|
|
4
|
+
`CONTEXT.md`). Which license applies depends only on the path:
|
|
5
|
+
|
|
6
|
+
| Path | License | Why |
|
|
7
|
+
|---|---|---|
|
|
8
|
+
| `packages/*` (published `@vybekiit/*`) | **MIT** | Public, headless logic — free updates double as marketing; nothing secret here. |
|
|
9
|
+
| `cli/` (the published `vybekiit` scaffolder) | **MIT** | The public npm CLI anyone may `npx`; the paid gate is repo access, not the CLI itself. |
|
|
10
|
+
| `templates/*` + the buyer agent layer (`.vybekiit/`, and each template's `AGENTS.md` / `CLAUDE.md` / `.cursor/rules` / `language.md` / `BUILDER-VOICE.md`) | **Proprietary — VybeKiit EULA** | The paid, owned product. Full terms in [`EULA.md`](./EULA.md). |
|
|
11
|
+
| `apps/landing/`, root tooling/config, and other repo internals | Proprietary (not distributed) | Our store and build infrastructure — never shipped to a buyer. |
|
|
12
|
+
|
|
13
|
+
The MIT-licensed paths are the only parts published to public npm. The proprietary paths reach
|
|
14
|
+
buyers through private GitHub mirror repos after purchase (the gate) and are governed by the
|
|
15
|
+
[VybeKiit EULA](./EULA.md), which includes a plain-language summary of what a buyer can and can't do.
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## MIT License — applies to `packages/*` and `cli/`
|
|
20
|
+
|
|
21
|
+
Copyright (c) 2026 VybeKiit authors
|
|
22
|
+
|
|
23
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
|
24
|
+
associated documentation files (the "Software"), to deal in the Software without restriction,
|
|
25
|
+
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
|
26
|
+
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
|
27
|
+
furnished to do so, subject to the following conditions:
|
|
28
|
+
|
|
29
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial
|
|
30
|
+
portions of the Software.
|
|
31
|
+
|
|
32
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
|
33
|
+
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
34
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
35
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
36
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## Proprietary — applies to `templates/*` and the buyer agent layer
|
|
41
|
+
|
|
42
|
+
These paths are **not** open source. They are the paid product, licensed (not sold) to buyers under
|
|
43
|
+
the **[VybeKiit EULA](./EULA.md)**. In short: a buyer may build unlimited products of their own,
|
|
44
|
+
including commercial ones, but may **not** redistribute, resell, or republish the kit itself, build a
|
|
45
|
+
competing kit with it, or share their access. Provided as-is, no warranty, liability capped at the
|
|
46
|
+
amount paid, best-effort updates with no compatibility guarantee. See `EULA.md` for the full terms
|
|
47
|
+
and the plain-language buyer summary.
|
package/README.md
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# vybekiit
|
|
2
|
+
|
|
3
|
+
Scaffold a VybeKiit template into your own repo, then build it by describing what you
|
|
4
|
+
want to your AI coding agent (Claude Code, Codex, or Cursor) — it does the heavy lift.
|
|
5
|
+
|
|
6
|
+
## Get started
|
|
7
|
+
|
|
8
|
+
```sh
|
|
9
|
+
npx vybekiit new web my-app
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
This creates `my-app/` from the `web` template. Open the folder in your AI coding tool
|
|
13
|
+
and tell it `"Set up my app."` — the agent reads its instructions and walks you through
|
|
14
|
+
the rest one step at a time.
|
|
15
|
+
|
|
16
|
+
Before your first build, install and check the tools your app needs:
|
|
17
|
+
|
|
18
|
+
```sh
|
|
19
|
+
vybekiit doctor
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
`doctor` installs and checks your full toolchain and reports what's ready:
|
|
23
|
+
|
|
24
|
+
| Layer | Tools |
|
|
25
|
+
| ----- | ----- |
|
|
26
|
+
| Agent | `claude` (Claude Code), `codex` (OpenAI Codex), `skills` (platform skills installer) |
|
|
27
|
+
| Base | `gh` (download templates + GitHub login) |
|
|
28
|
+
| Default cloud | `supabase` (database), `wrangler` (hosting) |
|
|
29
|
+
| When configured | `aws`, `gcloud` (Google sign-in), `vercel`, `eas` + `launch` (mobile) |
|
|
30
|
+
|
|
31
|
+
Doctor reads your `.env` provider settings and only installs what you use. It also verifies
|
|
32
|
+
official platform skills are present under `.agents/skills/`. When you enable Google sign-in,
|
|
33
|
+
doctor installs and checks `gcloud` auth.
|
|
34
|
+
|
|
35
|
+
## Commands
|
|
36
|
+
|
|
37
|
+
```
|
|
38
|
+
vybekiit new <template> [directory] Scaffold a template into your own repo
|
|
39
|
+
vybekiit doctor Set up + check the tools your app needs
|
|
40
|
+
vybekiit sync-agent-layer [template] Refresh agent instructions from the latest mirror
|
|
41
|
+
|
|
42
|
+
-h, --help Show help
|
|
43
|
+
-v, --version Show the CLI version
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Examples:
|
|
47
|
+
|
|
48
|
+
```sh
|
|
49
|
+
vybekiit new web my-app
|
|
50
|
+
vybekiit new web .
|
|
51
|
+
vybekiit doctor
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Templates
|
|
55
|
+
|
|
56
|
+
| Template | Stack | Status |
|
|
57
|
+
| ----------- | -------------------------------------- | -------------- |
|
|
58
|
+
| `web` | Next.js + shadcn (RTL-ready) + agent layer | available |
|
|
59
|
+
| `mobile` | Expo + agent layer | available |
|
|
60
|
+
| `extension` | WXT + agent layer | ships in v3 |
|
|
61
|
+
|
|
62
|
+
Every template ships the **agent layer** — the instructions and skills your AI agent
|
|
63
|
+
follows to set up, build, and ship your app.
|
|
64
|
+
|
|
65
|
+
## How delivery works
|
|
66
|
+
|
|
67
|
+
Templates are proprietary and live in private per-template mirror repos; the published
|
|
68
|
+
npm package ships **no** template files. When you run `vybekiit new`, the CLI clones the
|
|
69
|
+
template you've purchased access to using GitHub's `gh` CLI — one browser login, no
|
|
70
|
+
tokens to create or paste. The copied project starts as a fresh repo (the mirror's git
|
|
71
|
+
history is not carried over), and any `@vybekiit/*` workspace dependencies are rewritten
|
|
72
|
+
to pinned npm versions so it builds on its own.
|
|
73
|
+
|
|
74
|
+
If you haven't signed in yet, the CLI tells you exactly what to run:
|
|
75
|
+
`gh auth login --web`. `doctor` installs `gh` for you.
|
|
76
|
+
|
|
77
|
+
## Requirements
|
|
78
|
+
|
|
79
|
+
- **Node.js 20+** (the project toolchain targets Node 22).
|
|
80
|
+
- Everything else — agent CLIs, `gh`, `supabase`, `wrangler`, `gcloud`, `aws` — is installed by `vybekiit doctor`.
|
|
81
|
+
|
|
82
|
+
## License
|
|
83
|
+
|
|
84
|
+
MIT.
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,953 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/index.ts
|
|
4
|
+
import { readFile as readFile3 } from "fs/promises";
|
|
5
|
+
import { dirname as dirname2, join as join9, resolve as resolve2 } from "path";
|
|
6
|
+
import process4 from "process";
|
|
7
|
+
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
8
|
+
|
|
9
|
+
// src/doctor/run.ts
|
|
10
|
+
import { spawnSync as spawnSync2 } from "child_process";
|
|
11
|
+
import { existsSync as existsSync4, readFileSync as readFileSync5 } from "fs";
|
|
12
|
+
import { join as join5 } from "path";
|
|
13
|
+
import process from "process";
|
|
14
|
+
import { inferVybeAssistant } from "@vybekiit/report-mode";
|
|
15
|
+
|
|
16
|
+
// src/doctor/env.ts
|
|
17
|
+
import { existsSync, readFileSync, writeFileSync } from "fs";
|
|
18
|
+
import { join } from "path";
|
|
19
|
+
function loadEnvFile(cwd) {
|
|
20
|
+
const path = join(cwd, ".env");
|
|
21
|
+
if (!existsSync(path)) {
|
|
22
|
+
return {};
|
|
23
|
+
}
|
|
24
|
+
const out = {};
|
|
25
|
+
const raw = readFileSync(path, "utf8");
|
|
26
|
+
for (const line of raw.split("\n")) {
|
|
27
|
+
const trimmed = line.trim();
|
|
28
|
+
if (!trimmed || trimmed.startsWith("#")) {
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
const eq = trimmed.indexOf("=");
|
|
32
|
+
if (eq <= 0) {
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
const key = trimmed.slice(0, eq).trim();
|
|
36
|
+
let value = trimmed.slice(eq + 1).trim();
|
|
37
|
+
if (value.startsWith('"') && value.endsWith('"') || value.startsWith("'") && value.endsWith("'")) {
|
|
38
|
+
value = value.slice(1, -1);
|
|
39
|
+
}
|
|
40
|
+
out[key] = value;
|
|
41
|
+
}
|
|
42
|
+
return out;
|
|
43
|
+
}
|
|
44
|
+
function mergeEnv(processEnv, fileEnv) {
|
|
45
|
+
return { ...processEnv, ...fileEnv };
|
|
46
|
+
}
|
|
47
|
+
function writeEnvKeys(cwd, keys) {
|
|
48
|
+
const path = join(cwd, ".env");
|
|
49
|
+
const existing = existsSync(path) ? readFileSync(path, "utf8") : "";
|
|
50
|
+
const lines = existing.length > 0 ? existing.split("\n") : [];
|
|
51
|
+
const written = /* @__PURE__ */ new Set();
|
|
52
|
+
for (const [key, value] of Object.entries(keys)) {
|
|
53
|
+
const quoted = value.includes(" ") ? `"${value}"` : value;
|
|
54
|
+
const newLine = `${key}=${quoted}`;
|
|
55
|
+
let replaced = false;
|
|
56
|
+
for (let i = 0; i < lines.length; i++) {
|
|
57
|
+
const line = lines[i];
|
|
58
|
+
if (line === void 0) {
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
const trimmed = line.trim();
|
|
62
|
+
if (trimmed.startsWith(`${key}=`)) {
|
|
63
|
+
lines[i] = newLine;
|
|
64
|
+
replaced = true;
|
|
65
|
+
written.add(key);
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (!replaced) {
|
|
70
|
+
lines.push(newLine);
|
|
71
|
+
written.add(key);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
const output = lines.join("\n").replace(/\n*$/, "\n");
|
|
75
|
+
writeFileSync(
|
|
76
|
+
path,
|
|
77
|
+
output.length > 0 ? output : `${Object.entries(keys).map(([k, v]) => `${k}=${v}`).join("\n")}
|
|
78
|
+
`
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// src/doctor/platform-skills.ts
|
|
83
|
+
import { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
|
|
84
|
+
import { join as join2 } from "path";
|
|
85
|
+
function detectTemplate(cwd) {
|
|
86
|
+
if (existsSync2(join2(cwd, "platform-skills.manifest.json"))) {
|
|
87
|
+
if (existsSync2(join2(cwd, "app.json"))) return "mobile";
|
|
88
|
+
if (existsSync2(join2(cwd, "wxt.config.ts")) || existsSync2(join2(cwd, "extension.config.ts"))) {
|
|
89
|
+
return "extension";
|
|
90
|
+
}
|
|
91
|
+
return "web";
|
|
92
|
+
}
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
function readManifest(cwd) {
|
|
96
|
+
const path = join2(cwd, "platform-skills.manifest.json");
|
|
97
|
+
if (!existsSync2(path)) {
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
return JSON.parse(readFileSync2(path, "utf8"));
|
|
101
|
+
}
|
|
102
|
+
function expectedSkillNames(manifest) {
|
|
103
|
+
const names = /* @__PURE__ */ new Set();
|
|
104
|
+
for (const source of manifest.sources) {
|
|
105
|
+
for (const skill of source.skills) {
|
|
106
|
+
if (skill === "*") {
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
names.add(skill);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return [...names];
|
|
113
|
+
}
|
|
114
|
+
function verifyPlatformSkills(cwd) {
|
|
115
|
+
const manifest = readManifest(cwd);
|
|
116
|
+
if (!manifest) {
|
|
117
|
+
return { ok: true, missing: [], template: null };
|
|
118
|
+
}
|
|
119
|
+
const missing = [];
|
|
120
|
+
for (const name of expectedSkillNames(manifest)) {
|
|
121
|
+
const skillPath = join2(cwd, ".agents", "skills", name, "SKILL.md");
|
|
122
|
+
if (!existsSync2(skillPath)) {
|
|
123
|
+
missing.push(name);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return {
|
|
127
|
+
ok: missing.length === 0,
|
|
128
|
+
missing,
|
|
129
|
+
template: detectTemplate(cwd)
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
function formatPlatformSkillsReport(report) {
|
|
133
|
+
if (report.template === null) {
|
|
134
|
+
return [];
|
|
135
|
+
}
|
|
136
|
+
if (report.ok) {
|
|
137
|
+
return ["\u2713 platform skills \u2014 all official skills are present."];
|
|
138
|
+
}
|
|
139
|
+
return [
|
|
140
|
+
`\u2192 platform skills \u2014 missing: ${report.missing.join(", ")}. Ask your agent to refresh platform skills (update-kit) or run the pin script.`
|
|
141
|
+
];
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// src/doctor/project-health.ts
|
|
145
|
+
import { existsSync as existsSync3, readFileSync as readFileSync3 } from "fs";
|
|
146
|
+
import { join as join3 } from "path";
|
|
147
|
+
function gitignoreCoversEnv(cwd) {
|
|
148
|
+
const path = join3(cwd, ".gitignore");
|
|
149
|
+
if (!existsSync3(path)) {
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
152
|
+
const content = readFileSync3(path, "utf8");
|
|
153
|
+
return /^\.env/m.test(content) || content.includes(".env\n") || content.includes(".env\r\n");
|
|
154
|
+
}
|
|
155
|
+
function cursorignoreCoversEnv(cwd) {
|
|
156
|
+
const path = join3(cwd, ".cursorignore");
|
|
157
|
+
if (!existsSync3(path)) {
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
const content = readFileSync3(path, "utf8");
|
|
161
|
+
return content.split("\n").some((line) => line.trim() === ".env" || line.trim().startsWith(".env"));
|
|
162
|
+
}
|
|
163
|
+
function verifyProjectHealth(cwd) {
|
|
164
|
+
const lines = [];
|
|
165
|
+
let ok = true;
|
|
166
|
+
if (cursorignoreCoversEnv(cwd)) {
|
|
167
|
+
lines.push("\u2713 Secret settings file hidden from your assistant (.cursorignore)");
|
|
168
|
+
} else {
|
|
169
|
+
ok = false;
|
|
170
|
+
lines.push(
|
|
171
|
+
"\u2717 Add `.cursorignore` with `.env` listed \u2014 keeps secret values out of your assistant"
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
if (gitignoreCoversEnv(cwd)) {
|
|
175
|
+
lines.push("\u2713 Secret settings file excluded from git (.gitignore)");
|
|
176
|
+
} else {
|
|
177
|
+
ok = false;
|
|
178
|
+
lines.push("\u2717 `.gitignore` must list `.env` so secrets are never committed");
|
|
179
|
+
}
|
|
180
|
+
return { ok, lines };
|
|
181
|
+
}
|
|
182
|
+
function formatProjectHealthReport(report) {
|
|
183
|
+
return report.lines;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// src/doctor/storage-r2.ts
|
|
187
|
+
import { spawnSync } from "child_process";
|
|
188
|
+
import { readFileSync as readFileSync4 } from "fs";
|
|
189
|
+
import { join as join4 } from "path";
|
|
190
|
+
function sanitizeBucketName(name) {
|
|
191
|
+
return name.toLowerCase().replace(/[^a-z0-9-]/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "").slice(0, 40);
|
|
192
|
+
}
|
|
193
|
+
function readProjectName(cwd) {
|
|
194
|
+
try {
|
|
195
|
+
const pkg = JSON.parse(readFileSync4(join4(cwd, "package.json"), "utf8"));
|
|
196
|
+
if (pkg.name && pkg.name !== "my-vybekiit-app") {
|
|
197
|
+
return sanitizeBucketName(pkg.name);
|
|
198
|
+
}
|
|
199
|
+
} catch {
|
|
200
|
+
}
|
|
201
|
+
return "vybekiit-app";
|
|
202
|
+
}
|
|
203
|
+
function wranglerOk(args) {
|
|
204
|
+
return spawnSync("wrangler", [...args], { stdio: "ignore" }).status === 0;
|
|
205
|
+
}
|
|
206
|
+
async function createR2ApiToken(accountId, apiToken, bucketName) {
|
|
207
|
+
const response = await fetch(
|
|
208
|
+
`https://api.cloudflare.com/client/v4/accounts/${accountId}/r2/tokens`,
|
|
209
|
+
{
|
|
210
|
+
method: "POST",
|
|
211
|
+
headers: {
|
|
212
|
+
Authorization: `Bearer ${apiToken}`,
|
|
213
|
+
"Content-Type": "application/json"
|
|
214
|
+
},
|
|
215
|
+
body: JSON.stringify({
|
|
216
|
+
name: `vybekiit-${bucketName}`,
|
|
217
|
+
permissions: {
|
|
218
|
+
objects: { read: true, write: true }
|
|
219
|
+
}
|
|
220
|
+
})
|
|
221
|
+
}
|
|
222
|
+
);
|
|
223
|
+
if (!response.ok) {
|
|
224
|
+
return null;
|
|
225
|
+
}
|
|
226
|
+
const json = await response.json();
|
|
227
|
+
if (!(json.success && json.result?.access_key_id && json.result?.secret_access_key)) {
|
|
228
|
+
return null;
|
|
229
|
+
}
|
|
230
|
+
return {
|
|
231
|
+
accessKeyId: json.result.access_key_id,
|
|
232
|
+
secretAccessKey: json.result.secret_access_key
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
async function provisionR2Storage(cwd, env, log) {
|
|
236
|
+
const hosting = env.HOSTING_PROVIDER ?? "cloudflare";
|
|
237
|
+
if (hosting !== "cloudflare") {
|
|
238
|
+
return { ok: true, message: "R2 provisioning skipped \u2014 hosting is not Cloudflare." };
|
|
239
|
+
}
|
|
240
|
+
if (env.R2_BUCKET && env.R2_ACCESS_KEY_ID && env.R2_SECRET_ACCESS_KEY && env.R2_PUBLIC_URL) {
|
|
241
|
+
return { ok: true, message: "R2 storage already configured." };
|
|
242
|
+
}
|
|
243
|
+
const accountId = env.CLOUDFLARE_ACCOUNT_ID;
|
|
244
|
+
const apiToken = env.CLOUDFLARE_API_TOKEN;
|
|
245
|
+
if (!(accountId && apiToken)) {
|
|
246
|
+
return {
|
|
247
|
+
ok: false,
|
|
248
|
+
message: "Cloudflare account ID and API token are required before R2 can be set up."
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
if (!wranglerOk(["whoami"])) {
|
|
252
|
+
return { ok: false, message: "wrangler is not signed in \u2014 run wrangler login first." };
|
|
253
|
+
}
|
|
254
|
+
const bucketName = env.R2_BUCKET ?? `${readProjectName(cwd)}-assets`;
|
|
255
|
+
if (!wranglerOk(["r2", "bucket", "list"])) {
|
|
256
|
+
return { ok: false, message: "Could not list R2 buckets \u2014 check wrangler auth." };
|
|
257
|
+
}
|
|
258
|
+
if (wranglerOk(["r2", "bucket", "create", bucketName])) {
|
|
259
|
+
log.log(`[doctor] Created R2 bucket "${bucketName}".`);
|
|
260
|
+
} else {
|
|
261
|
+
const exists = wranglerOk(["r2", "bucket", "list"]);
|
|
262
|
+
if (!exists) {
|
|
263
|
+
return { ok: false, message: `Could not create R2 bucket "${bucketName}".` };
|
|
264
|
+
}
|
|
265
|
+
log.log(`[doctor] R2 bucket "${bucketName}" already exists or create skipped.`);
|
|
266
|
+
}
|
|
267
|
+
let accessKeyId = env.R2_ACCESS_KEY_ID;
|
|
268
|
+
let secretAccessKey = env.R2_SECRET_ACCESS_KEY;
|
|
269
|
+
if (!(accessKeyId && secretAccessKey)) {
|
|
270
|
+
const token = await createR2ApiToken(accountId, apiToken, bucketName);
|
|
271
|
+
if (!token) {
|
|
272
|
+
return {
|
|
273
|
+
ok: false,
|
|
274
|
+
message: "Could not create R2 API token \u2014 check Cloudflare API token permissions."
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
accessKeyId = token.accessKeyId;
|
|
278
|
+
secretAccessKey = token.secretAccessKey;
|
|
279
|
+
}
|
|
280
|
+
const publicUrl = env.R2_PUBLIC_URL ?? `https://${accountId}.r2.cloudflarestorage.com/${bucketName}`;
|
|
281
|
+
writeEnvKeys(cwd, {
|
|
282
|
+
STORAGE_PROVIDER: "r2",
|
|
283
|
+
R2_ACCOUNT_ID: accountId,
|
|
284
|
+
R2_BUCKET: bucketName,
|
|
285
|
+
R2_ACCESS_KEY_ID: accessKeyId,
|
|
286
|
+
R2_SECRET_ACCESS_KEY: secretAccessKey,
|
|
287
|
+
R2_PUBLIC_URL: publicUrl
|
|
288
|
+
});
|
|
289
|
+
return { ok: true, message: `R2 storage ready (bucket: ${bucketName}).` };
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// src/doctor/product-surface.ts
|
|
293
|
+
function formatProductSurfaceHints(env) {
|
|
294
|
+
const lines = [];
|
|
295
|
+
if (env.JOBS_PROVIDER === "cloudflare" && !env.CLOUDFLARE_QUEUE_NAME) {
|
|
296
|
+
lines.push(
|
|
297
|
+
"[doctor] background jobs: add CLOUDFLARE_QUEUE_NAME (or use local jobs until go-live)"
|
|
298
|
+
);
|
|
299
|
+
}
|
|
300
|
+
if (env.KV_PROVIDER === "cloudflare" && !env.CLOUDFLARE_KV_NAMESPACE_ID) {
|
|
301
|
+
lines.push("[doctor] fast storage: add CLOUDFLARE_KV_NAMESPACE_ID for Cloudflare KV");
|
|
302
|
+
}
|
|
303
|
+
if (env.ANALYTICS_PROVIDER === "plausible" && !env.PLAUSIBLE_DOMAIN) {
|
|
304
|
+
lines.push("[doctor] visitor stats: add PLAUSIBLE_DOMAIN (or analytics stays local no-op)");
|
|
305
|
+
}
|
|
306
|
+
if (env.AI_PROVIDER === "openai" && !env.OPENAI_API_KEY) {
|
|
307
|
+
lines.push(
|
|
308
|
+
"[doctor] AI features: add OPENAI_API_KEY (or AI stays local mock until you add keys)"
|
|
309
|
+
);
|
|
310
|
+
}
|
|
311
|
+
if (env.NOTIFICATIONS_PROVIDER === "expo") {
|
|
312
|
+
lines.push(
|
|
313
|
+
"[doctor] push notifications: Expo push works; email channel needs setup-email first"
|
|
314
|
+
);
|
|
315
|
+
}
|
|
316
|
+
if (lines.length === 0) {
|
|
317
|
+
lines.push(
|
|
318
|
+
"[doctor] product surface packages: env looks ready (analytics, jobs, kv, AI, notifications)"
|
|
319
|
+
);
|
|
320
|
+
}
|
|
321
|
+
return lines;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
// src/doctor/toolchain.ts
|
|
325
|
+
var GH = {
|
|
326
|
+
name: "gh",
|
|
327
|
+
purpose: "download your app's starter files and sign you in to GitHub",
|
|
328
|
+
versionArgs: ["--version"],
|
|
329
|
+
install: {
|
|
330
|
+
darwin: { command: "brew", args: ["install", "gh"], requires: "Homebrew" },
|
|
331
|
+
win32: { command: "scoop", args: ["install", "gh"], requires: "Scoop" },
|
|
332
|
+
linux: { command: "brew", args: ["install", "gh"], requires: "Homebrew" }
|
|
333
|
+
},
|
|
334
|
+
auth: { command: "gh", args: ["auth", "status"], loginHint: "gh auth login --web" }
|
|
335
|
+
};
|
|
336
|
+
var WRANGLER = {
|
|
337
|
+
name: "wrangler",
|
|
338
|
+
purpose: "put your app online",
|
|
339
|
+
versionArgs: ["--version"],
|
|
340
|
+
install: {
|
|
341
|
+
darwin: { command: "npm", args: ["install", "-g", "wrangler"] },
|
|
342
|
+
win32: { command: "npm", args: ["install", "-g", "wrangler"] },
|
|
343
|
+
linux: { command: "npm", args: ["install", "-g", "wrangler"] }
|
|
344
|
+
},
|
|
345
|
+
auth: { command: "wrangler", args: ["whoami"], loginHint: "wrangler login" }
|
|
346
|
+
};
|
|
347
|
+
var VERCEL = {
|
|
348
|
+
name: "vercel",
|
|
349
|
+
purpose: "put your app online",
|
|
350
|
+
versionArgs: ["--version"],
|
|
351
|
+
install: {
|
|
352
|
+
darwin: { command: "npm", args: ["install", "-g", "vercel"] },
|
|
353
|
+
win32: { command: "npm", args: ["install", "-g", "vercel"] },
|
|
354
|
+
linux: { command: "npm", args: ["install", "-g", "vercel"] }
|
|
355
|
+
},
|
|
356
|
+
auth: { command: "vercel", args: ["whoami"], loginHint: "vercel login" }
|
|
357
|
+
};
|
|
358
|
+
var SUPABASE = {
|
|
359
|
+
name: "supabase",
|
|
360
|
+
purpose: "create and manage your database",
|
|
361
|
+
versionArgs: ["--version"],
|
|
362
|
+
install: {
|
|
363
|
+
darwin: { command: "brew", args: ["install", "supabase/tap/supabase"], requires: "Homebrew" },
|
|
364
|
+
win32: { command: "scoop", args: ["install", "supabase"], requires: "Scoop" },
|
|
365
|
+
linux: { command: "brew", args: ["install", "supabase/tap/supabase"], requires: "Homebrew" }
|
|
366
|
+
},
|
|
367
|
+
auth: { command: "supabase", args: ["projects", "list"], loginHint: "supabase login" }
|
|
368
|
+
};
|
|
369
|
+
var ATLAS = {
|
|
370
|
+
name: "atlas",
|
|
371
|
+
purpose: "create and manage your database",
|
|
372
|
+
versionArgs: ["--version"],
|
|
373
|
+
install: {
|
|
374
|
+
darwin: { command: "brew", args: ["install", "mongodb-atlas-cli"], requires: "Homebrew" },
|
|
375
|
+
win32: { command: "scoop", args: ["install", "mongodb-atlas-cli"], requires: "Scoop" },
|
|
376
|
+
linux: { command: "brew", args: ["install", "mongodb-atlas-cli"], requires: "Homebrew" }
|
|
377
|
+
},
|
|
378
|
+
auth: { command: "atlas", args: ["auth", "whoami"], loginHint: "atlas auth login" }
|
|
379
|
+
};
|
|
380
|
+
var AWS = {
|
|
381
|
+
name: "aws",
|
|
382
|
+
purpose: "create and manage your cloud services",
|
|
383
|
+
versionArgs: ["--version"],
|
|
384
|
+
install: {
|
|
385
|
+
darwin: { command: "brew", args: ["install", "awscli"], requires: "Homebrew" },
|
|
386
|
+
win32: { command: "scoop", args: ["install", "aws"], requires: "Scoop" },
|
|
387
|
+
linux: { command: "brew", args: ["install", "awscli"], requires: "Homebrew" }
|
|
388
|
+
},
|
|
389
|
+
auth: { command: "aws", args: ["sts", "get-caller-identity"], loginHint: "aws configure" }
|
|
390
|
+
};
|
|
391
|
+
var GCLOUD = {
|
|
392
|
+
name: "gcloud",
|
|
393
|
+
purpose: "set up sign in with Google for your app",
|
|
394
|
+
versionArgs: ["--version"],
|
|
395
|
+
install: {
|
|
396
|
+
// `--cask` because gcloud ships as a community cask, not a formula (the file's first cask).
|
|
397
|
+
darwin: { command: "brew", args: ["install", "--cask", "gcloud-cli"], requires: "Homebrew" },
|
|
398
|
+
win32: { command: "scoop", args: ["install", "gcloud"], requires: "Scoop" },
|
|
399
|
+
linux: { command: "brew", args: ["install", "--cask", "gcloud-cli"], requires: "Homebrew" }
|
|
400
|
+
},
|
|
401
|
+
// `auth list` exits non-zero / prints nothing without an active account; login is the browser flow.
|
|
402
|
+
auth: { command: "gcloud", args: ["auth", "list"], loginHint: "gcloud auth login" }
|
|
403
|
+
};
|
|
404
|
+
var CLAUDE = {
|
|
405
|
+
name: "claude",
|
|
406
|
+
purpose: "your AI coding assistant (Claude Code)",
|
|
407
|
+
versionArgs: ["--version"],
|
|
408
|
+
install: {
|
|
409
|
+
darwin: { command: "npm", args: ["install", "-g", "@anthropic-ai/claude-code"] },
|
|
410
|
+
win32: { command: "npm", args: ["install", "-g", "@anthropic-ai/claude-code"] },
|
|
411
|
+
linux: { command: "npm", args: ["install", "-g", "@anthropic-ai/claude-code"] }
|
|
412
|
+
}
|
|
413
|
+
};
|
|
414
|
+
var CODEX = {
|
|
415
|
+
name: "codex",
|
|
416
|
+
purpose: "your AI coding assistant (OpenAI Codex)",
|
|
417
|
+
versionArgs: ["--version"],
|
|
418
|
+
install: {
|
|
419
|
+
darwin: { command: "npm", args: ["install", "-g", "@openai/codex"] },
|
|
420
|
+
win32: { command: "npm", args: ["install", "-g", "@openai/codex"] },
|
|
421
|
+
linux: { command: "npm", args: ["install", "-g", "@openai/codex"] }
|
|
422
|
+
}
|
|
423
|
+
};
|
|
424
|
+
var SKILLS = {
|
|
425
|
+
name: "skills",
|
|
426
|
+
purpose: "install the official platform skills your app needs",
|
|
427
|
+
versionArgs: ["--version"],
|
|
428
|
+
install: {
|
|
429
|
+
darwin: { command: "npm", args: ["install", "-g", "skills"] },
|
|
430
|
+
win32: { command: "npm", args: ["install", "-g", "skills"] },
|
|
431
|
+
linux: { command: "npm", args: ["install", "-g", "skills"] }
|
|
432
|
+
}
|
|
433
|
+
};
|
|
434
|
+
var AGENT_TOOLS = [CLAUDE, CODEX, SKILLS];
|
|
435
|
+
var EAS = {
|
|
436
|
+
name: "eas",
|
|
437
|
+
purpose: "build your app for the app stores",
|
|
438
|
+
versionArgs: ["--version"],
|
|
439
|
+
install: {
|
|
440
|
+
darwin: { command: "npm", args: ["install", "-g", "eas-cli"] },
|
|
441
|
+
win32: { command: "npm", args: ["install", "-g", "eas-cli"] },
|
|
442
|
+
linux: { command: "npm", args: ["install", "-g", "eas-cli"] }
|
|
443
|
+
},
|
|
444
|
+
auth: { command: "eas", args: ["whoami"], loginHint: "eas login" }
|
|
445
|
+
};
|
|
446
|
+
var LAUNCH = {
|
|
447
|
+
name: "launch",
|
|
448
|
+
purpose: "publish your app to the app stores",
|
|
449
|
+
versionArgs: ["--version"],
|
|
450
|
+
install: {
|
|
451
|
+
darwin: { command: "npm", args: ["install", "-g", "launch-store"] },
|
|
452
|
+
win32: { command: "npm", args: ["install", "-g", "launch-store"] },
|
|
453
|
+
linux: { command: "npm", args: ["install", "-g", "launch-store"] }
|
|
454
|
+
}
|
|
455
|
+
};
|
|
456
|
+
var TOOLCHAIN = [GH, WRANGLER, SUPABASE];
|
|
457
|
+
function selectToolchain(env, options = {}) {
|
|
458
|
+
const usesAws = env.DATA_PROVIDER === "aws" || env.STORAGE_PROVIDER === "s3" || env.EMAIL_PROVIDER === "ses" || env.AUTH_PROVIDER === "cognito" || env.HOSTING_PROVIDER === "aws";
|
|
459
|
+
const tools = [];
|
|
460
|
+
const add = (tool) => {
|
|
461
|
+
if (!tools.includes(tool)) {
|
|
462
|
+
tools.push(tool);
|
|
463
|
+
}
|
|
464
|
+
};
|
|
465
|
+
add(GH);
|
|
466
|
+
add(env.HOSTING_PROVIDER === "aws" ? AWS : env.HOSTING_PROVIDER === "vercel" ? VERCEL : WRANGLER);
|
|
467
|
+
switch (env.DATA_PROVIDER) {
|
|
468
|
+
case "mongodb":
|
|
469
|
+
add(ATLAS);
|
|
470
|
+
break;
|
|
471
|
+
case "aws":
|
|
472
|
+
add(AWS);
|
|
473
|
+
break;
|
|
474
|
+
default:
|
|
475
|
+
add(SUPABASE);
|
|
476
|
+
}
|
|
477
|
+
if (usesAws) {
|
|
478
|
+
add(AWS);
|
|
479
|
+
}
|
|
480
|
+
if (options.wantsGoogleAuth || env.GOOGLE_OAUTH_CLIENT_ID) {
|
|
481
|
+
add(GCLOUD);
|
|
482
|
+
}
|
|
483
|
+
if (options.mobile) {
|
|
484
|
+
add(EAS);
|
|
485
|
+
add(LAUNCH);
|
|
486
|
+
}
|
|
487
|
+
return tools;
|
|
488
|
+
}
|
|
489
|
+
function mergeAgentAndProviderTools(providerTools) {
|
|
490
|
+
const merged = [];
|
|
491
|
+
const add = (tool) => {
|
|
492
|
+
if (!merged.some((t) => t.name === tool.name)) {
|
|
493
|
+
merged.push(tool);
|
|
494
|
+
}
|
|
495
|
+
};
|
|
496
|
+
for (const tool of AGENT_TOOLS) {
|
|
497
|
+
add(tool);
|
|
498
|
+
}
|
|
499
|
+
for (const tool of providerTools) {
|
|
500
|
+
add(tool);
|
|
501
|
+
}
|
|
502
|
+
return merged;
|
|
503
|
+
}
|
|
504
|
+
function isAgentRuntimeReady(reports) {
|
|
505
|
+
const claude = reports.find((r) => r.tool === "claude");
|
|
506
|
+
const codex = reports.find((r) => r.tool === "codex");
|
|
507
|
+
return Boolean(claude?.installed || codex?.installed);
|
|
508
|
+
}
|
|
509
|
+
function isSkillsCliReady(reports) {
|
|
510
|
+
return reports.find((r) => r.tool === "skills")?.installed ?? false;
|
|
511
|
+
}
|
|
512
|
+
function planInstall(platform, presence, tools = TOOLCHAIN) {
|
|
513
|
+
const missing = new Set(presence.filter((p) => !p.present).map((p) => p.tool));
|
|
514
|
+
return tools.filter((tool) => missing.has(tool.name)).map((tool) => ({ tool: tool.name, ...tool.install[platform] }));
|
|
515
|
+
}
|
|
516
|
+
function formatReport(reports) {
|
|
517
|
+
return reports.map((report) => {
|
|
518
|
+
if (!report.installed) {
|
|
519
|
+
const fix = report.missingRequirement ? ` Install ${report.missingRequirement} first, then re-run.` : " Re-run to try again.";
|
|
520
|
+
return `\u2717 ${report.tool} \u2014 couldn't be set up (needed to ${report.purpose}).${fix}`;
|
|
521
|
+
}
|
|
522
|
+
if (report.authed === false) {
|
|
523
|
+
return `\u2192 ${report.tool} \u2014 installed, but you're not signed in yet. One-time: run \`${report.loginHint}\`.`;
|
|
524
|
+
}
|
|
525
|
+
return `\u2713 ${report.tool} \u2014 ready (used to ${report.purpose}).`;
|
|
526
|
+
});
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
// src/doctor/run.ts
|
|
530
|
+
function toPlatform(platform) {
|
|
531
|
+
return platform === "darwin" || platform === "win32" || platform === "linux" ? platform : null;
|
|
532
|
+
}
|
|
533
|
+
function isMobileProject(dir) {
|
|
534
|
+
for (const file of ["app.json", "app.config.json"]) {
|
|
535
|
+
const path = join5(dir, file);
|
|
536
|
+
if (!existsSync4(path)) {
|
|
537
|
+
continue;
|
|
538
|
+
}
|
|
539
|
+
try {
|
|
540
|
+
const config = JSON.parse(readFileSync5(path, "utf8"));
|
|
541
|
+
if (typeof config === "object" && config !== null && "expo" in config) {
|
|
542
|
+
return true;
|
|
543
|
+
}
|
|
544
|
+
} catch {
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
return false;
|
|
548
|
+
}
|
|
549
|
+
function isExtensionProject(dir) {
|
|
550
|
+
return existsSync4(join5(dir, "wxt.config.ts"));
|
|
551
|
+
}
|
|
552
|
+
function reportModeEnvKeys(cwd, assistant) {
|
|
553
|
+
if (isMobileProject(cwd)) {
|
|
554
|
+
return { EXPO_PUBLIC_VYBE_ASSISTANT: assistant };
|
|
555
|
+
}
|
|
556
|
+
if (isExtensionProject(cwd)) {
|
|
557
|
+
return { WXT_PUBLIC_VYBE_ASSISTANT: assistant };
|
|
558
|
+
}
|
|
559
|
+
return { VYBE_ASSISTANT: assistant };
|
|
560
|
+
}
|
|
561
|
+
function isCursorSession() {
|
|
562
|
+
return Boolean(process.env.CURSOR_TRACE_ID || process.env.CURSOR_SESSION_ID);
|
|
563
|
+
}
|
|
564
|
+
function succeeds(command, args) {
|
|
565
|
+
return spawnSync2(command, [...args], { stdio: "ignore" }).status === 0;
|
|
566
|
+
}
|
|
567
|
+
function errorCode(error) {
|
|
568
|
+
return error && "code" in error && typeof error.code === "string" ? error.code : void 0;
|
|
569
|
+
}
|
|
570
|
+
function runInstall(action, log) {
|
|
571
|
+
log.log(`[doctor] setting up ${action.tool}: ${action.command} ${action.args.join(" ")}`);
|
|
572
|
+
const result = spawnSync2(action.command, [...action.args], { stdio: "inherit" });
|
|
573
|
+
if (errorCode(result.error) === "ENOENT") {
|
|
574
|
+
return action.requires ? { ok: false, missingRequirement: action.requires } : { ok: false };
|
|
575
|
+
}
|
|
576
|
+
return { ok: result.status === 0 };
|
|
577
|
+
}
|
|
578
|
+
function buildReport(tool, presence, installs) {
|
|
579
|
+
const wasPresent = presence.find((p) => p.tool === tool.name)?.present ?? false;
|
|
580
|
+
const install = installs.get(tool.name);
|
|
581
|
+
const installed = wasPresent || install?.ok === true;
|
|
582
|
+
if (!installed) {
|
|
583
|
+
const requirement = install?.missingRequirement;
|
|
584
|
+
return {
|
|
585
|
+
tool: tool.name,
|
|
586
|
+
purpose: tool.purpose,
|
|
587
|
+
installed: false,
|
|
588
|
+
authed: null,
|
|
589
|
+
...requirement ? { missingRequirement: requirement } : {}
|
|
590
|
+
};
|
|
591
|
+
}
|
|
592
|
+
if (!tool.auth) {
|
|
593
|
+
return { tool: tool.name, purpose: tool.purpose, installed: true, authed: null };
|
|
594
|
+
}
|
|
595
|
+
const authed = succeeds(tool.auth.command, tool.auth.args);
|
|
596
|
+
return {
|
|
597
|
+
tool: tool.name,
|
|
598
|
+
purpose: tool.purpose,
|
|
599
|
+
installed: true,
|
|
600
|
+
authed,
|
|
601
|
+
...authed ? {} : { loginHint: tool.auth.loginHint }
|
|
602
|
+
};
|
|
603
|
+
}
|
|
604
|
+
async function runDoctor(log = console) {
|
|
605
|
+
const platform = toPlatform(process.platform);
|
|
606
|
+
if (!platform) {
|
|
607
|
+
log.error(`[doctor] This operating system (${process.platform}) isn't supported yet.`);
|
|
608
|
+
return 1;
|
|
609
|
+
}
|
|
610
|
+
const cwd = process.cwd();
|
|
611
|
+
const env = mergeEnv(process.env, loadEnvFile(cwd));
|
|
612
|
+
const providerTools = selectToolchain(env, {
|
|
613
|
+
mobile: isMobileProject(cwd),
|
|
614
|
+
wantsGoogleAuth: Boolean(env.GOOGLE_OAUTH_CLIENT_ID)
|
|
615
|
+
});
|
|
616
|
+
const toolchain = mergeAgentAndProviderTools(providerTools);
|
|
617
|
+
if (isCursorSession()) {
|
|
618
|
+
log.log("\u2713 Cursor \u2014 you're in Cursor; no separate agent install needed.");
|
|
619
|
+
}
|
|
620
|
+
const presence = toolchain.map((tool) => ({
|
|
621
|
+
tool: tool.name,
|
|
622
|
+
present: succeeds(tool.name, tool.versionArgs)
|
|
623
|
+
}));
|
|
624
|
+
const installs = /* @__PURE__ */ new Map();
|
|
625
|
+
for (const action of planInstall(platform, presence, toolchain)) {
|
|
626
|
+
installs.set(action.tool, runInstall(action, log));
|
|
627
|
+
}
|
|
628
|
+
const reports = toolchain.map((tool) => buildReport(tool, presence, installs));
|
|
629
|
+
for (const line of formatReport(reports)) {
|
|
630
|
+
log.log(line);
|
|
631
|
+
}
|
|
632
|
+
const skillsReport = verifyPlatformSkills(cwd);
|
|
633
|
+
for (const line of formatPlatformSkillsReport(skillsReport)) {
|
|
634
|
+
log.log(line);
|
|
635
|
+
}
|
|
636
|
+
const projectHealth = verifyProjectHealth(cwd);
|
|
637
|
+
for (const line of formatProjectHealthReport(projectHealth)) {
|
|
638
|
+
log.log(line);
|
|
639
|
+
}
|
|
640
|
+
const r2Result = await provisionR2Storage(cwd, env, log);
|
|
641
|
+
log.log(`[doctor] ${r2Result.message}`);
|
|
642
|
+
for (const line of formatProductSurfaceHints(env)) {
|
|
643
|
+
log.log(line);
|
|
644
|
+
}
|
|
645
|
+
const cloudReady = providerTools.every((tool) => {
|
|
646
|
+
const report = reports.find((r) => r.tool === tool.name);
|
|
647
|
+
return report?.installed === true;
|
|
648
|
+
});
|
|
649
|
+
const cursorSession = isCursorSession();
|
|
650
|
+
const agentReady = isAgentRuntimeReady(reports) || cursorSession;
|
|
651
|
+
const skillsReady = isSkillsCliReady(reports);
|
|
652
|
+
const assistant = inferVybeAssistant({
|
|
653
|
+
cursorSession,
|
|
654
|
+
claudeInstalled: reports.find((r) => r.tool === "claude")?.installed === true,
|
|
655
|
+
codexInstalled: reports.find((r) => r.tool === "codex")?.installed === true
|
|
656
|
+
});
|
|
657
|
+
if (assistant) {
|
|
658
|
+
writeEnvKeys(cwd, reportModeEnvKeys(cwd, assistant));
|
|
659
|
+
log.log(`\u2713 Report Mode \u2014 your assistant is set to ${assistant}.`);
|
|
660
|
+
}
|
|
661
|
+
return cloudReady && r2Result.ok && agentReady && skillsReady && projectHealth.ok ? 0 : 1;
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
// src/resolve-templates.ts
|
|
665
|
+
import { execFile } from "child_process";
|
|
666
|
+
import { access as access2, mkdtemp, rm } from "fs/promises";
|
|
667
|
+
import { tmpdir } from "os";
|
|
668
|
+
import { dirname, join as join7, resolve } from "path";
|
|
669
|
+
import process2 from "process";
|
|
670
|
+
import { fileURLToPath } from "url";
|
|
671
|
+
import { promisify } from "util";
|
|
672
|
+
|
|
673
|
+
// src/scaffold.ts
|
|
674
|
+
import { access, cp, readdir, readFile, writeFile } from "fs/promises";
|
|
675
|
+
import { basename, join as join6 } from "path";
|
|
676
|
+
|
|
677
|
+
// src/rewrite-deps.ts
|
|
678
|
+
function rewriteWorkspaceDeps(deps, version) {
|
|
679
|
+
const rewritten = {};
|
|
680
|
+
for (const [name, range] of Object.entries(deps)) {
|
|
681
|
+
const isVybeKiitWorkspace = name.startsWith("@vybekiit/") && range.startsWith("workspace:");
|
|
682
|
+
rewritten[name] = isVybeKiitWorkspace ? `^${version}` : range;
|
|
683
|
+
}
|
|
684
|
+
return rewritten;
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
// src/scaffold.ts
|
|
688
|
+
var TEMPLATES = ["web", "mobile", "extension"];
|
|
689
|
+
var ScaffoldError = class extends Error {
|
|
690
|
+
};
|
|
691
|
+
var SKIP_DIRS = /* @__PURE__ */ new Set(["node_modules", ".next", "dist", ".turbo", ".git"]);
|
|
692
|
+
function isTemplateName(value) {
|
|
693
|
+
return TEMPLATES.includes(value);
|
|
694
|
+
}
|
|
695
|
+
async function pinScaffoldedDeps(dest, packagesVersion) {
|
|
696
|
+
const pkgPath = join6(dest, "package.json");
|
|
697
|
+
let raw;
|
|
698
|
+
try {
|
|
699
|
+
raw = await readFile(pkgPath, "utf8");
|
|
700
|
+
} catch {
|
|
701
|
+
return;
|
|
702
|
+
}
|
|
703
|
+
const pkg = JSON.parse(raw);
|
|
704
|
+
for (const field of ["dependencies", "devDependencies"]) {
|
|
705
|
+
const deps = pkg[field];
|
|
706
|
+
if (deps && typeof deps === "object") {
|
|
707
|
+
pkg[field] = rewriteWorkspaceDeps(deps, packagesVersion);
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
await writeFile(pkgPath, `${JSON.stringify(pkg, null, 2)}
|
|
711
|
+
`);
|
|
712
|
+
}
|
|
713
|
+
async function scaffold(options) {
|
|
714
|
+
const sourceDir = join6(options.source, options.template);
|
|
715
|
+
try {
|
|
716
|
+
await access(sourceDir);
|
|
717
|
+
} catch {
|
|
718
|
+
throw new ScaffoldError(`Template "${options.template}" was not found at ${sourceDir}.`);
|
|
719
|
+
}
|
|
720
|
+
try {
|
|
721
|
+
const existing = await readdir(options.dest);
|
|
722
|
+
if (existing.length > 0) {
|
|
723
|
+
throw new ScaffoldError(`Destination ${options.dest} already exists and is not empty.`);
|
|
724
|
+
}
|
|
725
|
+
} catch (error) {
|
|
726
|
+
if (error instanceof ScaffoldError) {
|
|
727
|
+
throw error;
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
await cp(sourceDir, options.dest, {
|
|
731
|
+
recursive: true,
|
|
732
|
+
filter: (src) => !SKIP_DIRS.has(basename(src))
|
|
733
|
+
});
|
|
734
|
+
await pinScaffoldedDeps(options.dest, options.packagesVersion);
|
|
735
|
+
return { dest: options.dest };
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
// src/resolve-templates.ts
|
|
739
|
+
var execFileAsync = promisify(execFile);
|
|
740
|
+
var HERE = dirname(fileURLToPath(import.meta.url));
|
|
741
|
+
var MIRROR_ORG = "VybeKiit";
|
|
742
|
+
async function pathExists(path) {
|
|
743
|
+
try {
|
|
744
|
+
await access2(path);
|
|
745
|
+
return true;
|
|
746
|
+
} catch {
|
|
747
|
+
return false;
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
async function cloneMirror(template, targetDir) {
|
|
751
|
+
try {
|
|
752
|
+
await execFileAsync("gh", [
|
|
753
|
+
"repo",
|
|
754
|
+
"clone",
|
|
755
|
+
`${MIRROR_ORG}/${template}`,
|
|
756
|
+
targetDir,
|
|
757
|
+
"--",
|
|
758
|
+
"--depth",
|
|
759
|
+
"1",
|
|
760
|
+
"--no-tags"
|
|
761
|
+
]);
|
|
762
|
+
} catch {
|
|
763
|
+
throw new ScaffoldError(
|
|
764
|
+
`Couldn't download the ${template} template. Make sure your assistant is signed in to GitHub \u2014 run: gh auth login --web`
|
|
765
|
+
);
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
async function resolveTemplatesSource(template, deps = { clone: cloneMirror, exists: pathExists }) {
|
|
769
|
+
const override = process2.env.VYBEKIIT_TEMPLATES_DIR;
|
|
770
|
+
if (override) {
|
|
771
|
+
return { source: override };
|
|
772
|
+
}
|
|
773
|
+
const localRoot = resolve(HERE, "..", "..", "templates");
|
|
774
|
+
if (await deps.exists(join7(localRoot, template))) {
|
|
775
|
+
return { source: localRoot };
|
|
776
|
+
}
|
|
777
|
+
const tempRoot = await mkdtemp(join7(tmpdir(), "vybekiit-"));
|
|
778
|
+
try {
|
|
779
|
+
await deps.clone(template, join7(tempRoot, template));
|
|
780
|
+
} catch (error) {
|
|
781
|
+
await rm(tempRoot, { recursive: true, force: true });
|
|
782
|
+
throw error;
|
|
783
|
+
}
|
|
784
|
+
return { source: tempRoot, cleanup: () => rm(tempRoot, { recursive: true, force: true }) };
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
// src/sync-agent-layer.ts
|
|
788
|
+
import { execFile as execFile2 } from "child_process";
|
|
789
|
+
import { access as access3, cp as cp2, readFile as readFile2 } from "fs/promises";
|
|
790
|
+
import { join as join8 } from "path";
|
|
791
|
+
import process3 from "process";
|
|
792
|
+
import { promisify as promisify2 } from "util";
|
|
793
|
+
import {
|
|
794
|
+
AGENT_LAYER_PATHS,
|
|
795
|
+
formatAgentLayerSyncSummary,
|
|
796
|
+
planAgentLayerSync
|
|
797
|
+
} from "@vybekiit/agent-kit";
|
|
798
|
+
var execFileAsync2 = promisify2(execFile2);
|
|
799
|
+
var defaultDeps = {
|
|
800
|
+
resolve: resolveTemplatesSource,
|
|
801
|
+
copy: cp2,
|
|
802
|
+
runSkillsUpdate: async (cwd) => {
|
|
803
|
+
await execFileAsync2("npx", ["skills", "update", "-y"], { cwd, env: process3.env });
|
|
804
|
+
},
|
|
805
|
+
pathExists: async (path) => {
|
|
806
|
+
try {
|
|
807
|
+
await access3(path);
|
|
808
|
+
return true;
|
|
809
|
+
} catch {
|
|
810
|
+
return false;
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
};
|
|
814
|
+
async function detectTemplateName(cwd) {
|
|
815
|
+
try {
|
|
816
|
+
const raw = await readFile2(join8(cwd, "package.json"), "utf8");
|
|
817
|
+
const pkg = JSON.parse(raw);
|
|
818
|
+
if (pkg.dependencies?.expo || pkg.main?.includes("expo-router")) {
|
|
819
|
+
return "mobile";
|
|
820
|
+
}
|
|
821
|
+
if (pkg.dependencies?.next) {
|
|
822
|
+
return "web";
|
|
823
|
+
}
|
|
824
|
+
} catch {
|
|
825
|
+
}
|
|
826
|
+
try {
|
|
827
|
+
await access3(join8(cwd, ".vybekiit/skills/publish-extension.md"));
|
|
828
|
+
return "extension";
|
|
829
|
+
} catch {
|
|
830
|
+
return "web";
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
async function listMirrorAgentPaths(mirrorRoot, pathExists2) {
|
|
834
|
+
const found = [];
|
|
835
|
+
for (const path of AGENT_LAYER_PATHS) {
|
|
836
|
+
if (await pathExists2(join8(mirrorRoot, path))) {
|
|
837
|
+
found.push(path);
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
return found;
|
|
841
|
+
}
|
|
842
|
+
async function runSyncAgentLayer(args, cwd = process3.cwd(), deps = defaultDeps) {
|
|
843
|
+
const explicit = args[0];
|
|
844
|
+
const template = explicit && isTemplateName(explicit) ? explicit : await detectTemplateName(cwd);
|
|
845
|
+
if (!template) {
|
|
846
|
+
return {
|
|
847
|
+
lines: ["Could not tell which template this project uses. Pass: web, mobile, or extension."],
|
|
848
|
+
exitCode: 1
|
|
849
|
+
};
|
|
850
|
+
}
|
|
851
|
+
let cleanup;
|
|
852
|
+
try {
|
|
853
|
+
const resolved = await deps.resolve(template, {
|
|
854
|
+
clone: cloneMirror,
|
|
855
|
+
exists: deps.pathExists
|
|
856
|
+
});
|
|
857
|
+
cleanup = resolved.cleanup;
|
|
858
|
+
const mirrorRoot = join8(resolved.source, template);
|
|
859
|
+
const mirrorPaths = await listMirrorAgentPaths(mirrorRoot, deps.pathExists);
|
|
860
|
+
const plan = planAgentLayerSync(mirrorPaths);
|
|
861
|
+
const lines = [formatAgentLayerSyncSummary(plan)];
|
|
862
|
+
for (const path of plan.pathsToSync) {
|
|
863
|
+
const src = join8(mirrorRoot, path);
|
|
864
|
+
const dest = join8(cwd, path);
|
|
865
|
+
await deps.copy(src, dest, { recursive: true, force: true });
|
|
866
|
+
}
|
|
867
|
+
if (await deps.pathExists(join8(cwd, "skills-lock.json"))) {
|
|
868
|
+
try {
|
|
869
|
+
await deps.runSkillsUpdate(cwd);
|
|
870
|
+
lines.push("Updated your assistant\u2019s platform instruction files.");
|
|
871
|
+
} catch {
|
|
872
|
+
lines.push("Could not refresh platform instruction files \u2014 try again later.");
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
lines.push("Done \u2014 your assistant has the latest instructions.");
|
|
876
|
+
return { lines, exitCode: 0 };
|
|
877
|
+
} catch (error) {
|
|
878
|
+
if (error instanceof ScaffoldError) {
|
|
879
|
+
return { lines: [error.message], exitCode: 1 };
|
|
880
|
+
}
|
|
881
|
+
throw error;
|
|
882
|
+
} finally {
|
|
883
|
+
await cleanup?.();
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
// src/index.ts
|
|
888
|
+
var HERE2 = dirname2(fileURLToPath2(import.meta.url));
|
|
889
|
+
async function readVersion() {
|
|
890
|
+
try {
|
|
891
|
+
const raw = await readFile3(join9(HERE2, "..", "package.json"), "utf8");
|
|
892
|
+
return JSON.parse(raw).version ?? "0.0.0";
|
|
893
|
+
} catch {
|
|
894
|
+
return "0.0.0";
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
async function runNew(args) {
|
|
898
|
+
const [template, dir] = args;
|
|
899
|
+
if (!(template && isTemplateName(template))) {
|
|
900
|
+
return 1;
|
|
901
|
+
}
|
|
902
|
+
const dest = resolve2(process4.cwd(), dir ?? template);
|
|
903
|
+
let cleanup;
|
|
904
|
+
try {
|
|
905
|
+
const resolved = await resolveTemplatesSource(template);
|
|
906
|
+
cleanup = resolved.cleanup;
|
|
907
|
+
await scaffold({
|
|
908
|
+
template,
|
|
909
|
+
source: resolved.source,
|
|
910
|
+
dest,
|
|
911
|
+
packagesVersion: await readVersion()
|
|
912
|
+
});
|
|
913
|
+
} catch (error) {
|
|
914
|
+
if (error instanceof ScaffoldError) {
|
|
915
|
+
return 1;
|
|
916
|
+
}
|
|
917
|
+
throw error;
|
|
918
|
+
} finally {
|
|
919
|
+
await cleanup?.();
|
|
920
|
+
}
|
|
921
|
+
return 0;
|
|
922
|
+
}
|
|
923
|
+
async function main(argv) {
|
|
924
|
+
const [command, ...rest] = argv;
|
|
925
|
+
if (!command || command === "help" || command === "--help" || command === "-h") {
|
|
926
|
+
return 0;
|
|
927
|
+
}
|
|
928
|
+
if (command === "--version" || command === "-v") {
|
|
929
|
+
return 0;
|
|
930
|
+
}
|
|
931
|
+
if (command === "new") {
|
|
932
|
+
return runNew(rest);
|
|
933
|
+
}
|
|
934
|
+
if (command === "doctor") {
|
|
935
|
+
return await runDoctor();
|
|
936
|
+
}
|
|
937
|
+
if (command === "sync-agent-layer") {
|
|
938
|
+
const result = await runSyncAgentLayer(rest);
|
|
939
|
+
for (const _line of result.lines) {
|
|
940
|
+
}
|
|
941
|
+
return result.exitCode;
|
|
942
|
+
}
|
|
943
|
+
return 1;
|
|
944
|
+
}
|
|
945
|
+
if (process4.argv[1] && resolve2(process4.argv[1]) === fileURLToPath2(import.meta.url)) {
|
|
946
|
+
main(process4.argv.slice(2)).then((code) => process4.exit(code)).catch((_error) => {
|
|
947
|
+
process4.exit(1);
|
|
948
|
+
});
|
|
949
|
+
}
|
|
950
|
+
export {
|
|
951
|
+
cloneMirror,
|
|
952
|
+
resolveTemplatesSource
|
|
953
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "vybekiit",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Scaffold a VybeKiit template into your own repo: `npx vybekiit new web my-app`.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"type": "module",
|
|
10
|
+
"bin": {
|
|
11
|
+
"vybekiit": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"dist"
|
|
15
|
+
],
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@vybekiit/agent-kit": "0.1.0",
|
|
18
|
+
"@vybekiit/report-mode": "0.1.0"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@types/node": "^22.10.2",
|
|
22
|
+
"tsup": "^8.3.5",
|
|
23
|
+
"typescript": "^5.7.2",
|
|
24
|
+
"vitest": "^2.1.8"
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "tsup",
|
|
28
|
+
"typecheck": "tsc --noEmit",
|
|
29
|
+
"test": "vitest run"
|
|
30
|
+
}
|
|
31
|
+
}
|