clawnify 0.2.0 → 0.4.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.
|
@@ -785,6 +785,7 @@ async function askProjectType(opts) {
|
|
|
785
785
|
console.error(`Unknown --type '${opts.type}' (expected 'app' or 'website').`);
|
|
786
786
|
process.exit(1);
|
|
787
787
|
}
|
|
788
|
+
if (opts?.yes) return "app";
|
|
788
789
|
console.log();
|
|
789
790
|
console.log(" What are you creating?");
|
|
790
791
|
console.log(" 1) app \u2014 full-stack project (React + Hono + D1)");
|
|
@@ -793,6 +794,13 @@ async function askProjectType(opts) {
|
|
|
793
794
|
const choice = await ask2("Type [1]: ") || "1";
|
|
794
795
|
return choice === "2" ? "website" : "app";
|
|
795
796
|
}
|
|
797
|
+
function detectPackageManager() {
|
|
798
|
+
const ua = process.env.npm_config_user_agent ?? "";
|
|
799
|
+
if (ua.startsWith("pnpm")) return "pnpm";
|
|
800
|
+
if (ua.startsWith("yarn")) return "yarn";
|
|
801
|
+
if (ua.startsWith("bun")) return "bun";
|
|
802
|
+
return "npm";
|
|
803
|
+
}
|
|
796
804
|
async function initCommand(dir, opts) {
|
|
797
805
|
const type = await askProjectType(opts);
|
|
798
806
|
if (type === "website") {
|
|
@@ -801,12 +809,16 @@ async function initCommand(dir, opts) {
|
|
|
801
809
|
return initApp(dir, opts);
|
|
802
810
|
}
|
|
803
811
|
async function initApp(dir, opts) {
|
|
804
|
-
const
|
|
812
|
+
const yes = !!opts?.yes;
|
|
813
|
+
const dirArgName = dir ? path3.basename(path3.resolve(dir)) : void 0;
|
|
814
|
+
const name = opts?.name || (yes ? dirArgName ?? "my-app" : await ask2("App name: ") || "my-app");
|
|
805
815
|
const slug = slugify(name);
|
|
806
816
|
const targetDir = dir ? path3.resolve(dir) : path3.resolve(slug);
|
|
807
817
|
let template;
|
|
808
818
|
if (opts?.template) {
|
|
809
819
|
template = opts.template === "crud" ? "crud" : "blank";
|
|
820
|
+
} else if (yes) {
|
|
821
|
+
template = "blank";
|
|
810
822
|
} else {
|
|
811
823
|
console.log();
|
|
812
824
|
console.log(" Templates:");
|
|
@@ -822,9 +834,12 @@ async function initApp(dir, opts) {
|
|
|
822
834
|
}
|
|
823
835
|
fs2.mkdirSync(path3.join(targetDir, "src/server"), { recursive: true });
|
|
824
836
|
fs2.mkdirSync(path3.join(targetDir, "src/client"), { recursive: true });
|
|
837
|
+
fs2.mkdirSync(path3.join(targetDir, "drizzle"), { recursive: true });
|
|
825
838
|
let storage;
|
|
826
839
|
if (opts?.storage !== void 0) {
|
|
827
840
|
storage = opts.storage;
|
|
841
|
+
} else if (yes) {
|
|
842
|
+
storage = false;
|
|
828
843
|
} else {
|
|
829
844
|
const storageChoice = await ask2("Enable file uploads? [y/N]: ") || "n";
|
|
830
845
|
storage = storageChoice.toLowerCase() === "y";
|
|
@@ -842,10 +857,11 @@ async function initApp(dir, opts) {
|
|
|
842
857
|
"@types/react": "^19.0.0",
|
|
843
858
|
"@types/react-dom": "^19.0.0",
|
|
844
859
|
"@vitejs/plugin-react": "^4.0.0",
|
|
845
|
-
|
|
846
|
-
"
|
|
847
|
-
|
|
848
|
-
|
|
860
|
+
clawnify: "^0.3.0",
|
|
861
|
+
"drizzle-kit": "^0.31.0",
|
|
862
|
+
tailwindcss: "^4.0.0",
|
|
863
|
+
vite: "^6.0.0",
|
|
864
|
+
wrangler: "^4.0.0"
|
|
849
865
|
};
|
|
850
866
|
write(targetDir, "package.json", JSON.stringify({
|
|
851
867
|
name: slug,
|
|
@@ -854,9 +870,11 @@ async function initApp(dir, opts) {
|
|
|
854
870
|
scripts: {
|
|
855
871
|
dev: "clawnify dev",
|
|
856
872
|
build: "vite build",
|
|
857
|
-
deploy: "clawnify deploy"
|
|
873
|
+
deploy: "clawnify deploy",
|
|
874
|
+
"db:generate": "drizzle-kit generate"
|
|
858
875
|
},
|
|
859
876
|
dependencies: {
|
|
877
|
+
"@clawnify/db": "^0.4.0",
|
|
860
878
|
"@hono/zod-openapi": "^0.19.0",
|
|
861
879
|
hono: "^4.0.0",
|
|
862
880
|
react: "^19.0.0",
|
|
@@ -929,45 +947,37 @@ data.db-shm
|
|
|
929
947
|
`);
|
|
930
948
|
write(targetDir, "src/server/worker-env.d.ts", `/// <reference types="@cloudflare/workers-types" />
|
|
931
949
|
`);
|
|
932
|
-
write(targetDir, "src/server/
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
}
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
sql: string,
|
|
949
|
-
params: unknown[] = [],
|
|
950
|
-
): Promise<T | undefined> {
|
|
951
|
-
const stmt = _db.prepare(sql).bind(...params);
|
|
952
|
-
const row = await stmt.first<T>();
|
|
953
|
-
return row ?? undefined;
|
|
954
|
-
}
|
|
950
|
+
write(targetDir, "src/server/schema.ts", `import { sqliteTable, text, integer } from "@clawnify/db";
|
|
951
|
+
|
|
952
|
+
/**
|
|
953
|
+
* Example table. Replace with your own.
|
|
954
|
+
*
|
|
955
|
+
* Multi-tenancy reminder: every user-facing table should carry an
|
|
956
|
+
* \`org_id\` column and every query should filter by the X-Clawnify-Org-Id
|
|
957
|
+
* header. See docs/build-a-clawnify-app.md.
|
|
958
|
+
*/
|
|
959
|
+
export const items = sqliteTable("items", {
|
|
960
|
+
id: integer("id").primaryKey({ autoIncrement: true }),
|
|
961
|
+
name: text("name").notNull(),
|
|
962
|
+
createdAt: text("created_at").notNull().$default(() => new Date().toISOString()),
|
|
963
|
+
});
|
|
964
|
+
`);
|
|
965
|
+
write(targetDir, "drizzle.config.ts", `import { defineConfig } from "drizzle-kit";
|
|
955
966
|
|
|
956
|
-
export
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
+
export default defineConfig({
|
|
968
|
+
schema: "./src/server/schema.ts",
|
|
969
|
+
out: "./drizzle",
|
|
970
|
+
dialect: "sqlite",
|
|
971
|
+
});
|
|
972
|
+
`);
|
|
973
|
+
write(targetDir, "drizzle/0000_init.sql", `CREATE TABLE \`items\` (
|
|
974
|
+
\`id\` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
|
|
975
|
+
\`name\` text NOT NULL,
|
|
976
|
+
\`created_at\` text NOT NULL
|
|
977
|
+
);
|
|
967
978
|
`);
|
|
968
979
|
if (storage) {
|
|
969
980
|
write(targetDir, "src/server/index.ts", `import { OpenAPIHono } from "@hono/zod-openapi";
|
|
970
|
-
import { initDB } from "./db";
|
|
971
981
|
import { initUploads } from "./uploads";
|
|
972
982
|
import api from "./routes";
|
|
973
983
|
|
|
@@ -976,7 +986,6 @@ type Env = { Bindings: { DB: D1Database; UPLOADS: R2Bucket } };
|
|
|
976
986
|
const app = new OpenAPIHono<Env>();
|
|
977
987
|
|
|
978
988
|
app.use("*", async (c, next) => {
|
|
979
|
-
initDB(c.env.DB);
|
|
980
989
|
initUploads(c.env.UPLOADS);
|
|
981
990
|
await next();
|
|
982
991
|
});
|
|
@@ -1033,18 +1042,12 @@ export async function readUploadAsBase64DataUrl(
|
|
|
1033
1042
|
`);
|
|
1034
1043
|
} else {
|
|
1035
1044
|
write(targetDir, "src/server/index.ts", `import { OpenAPIHono } from "@hono/zod-openapi";
|
|
1036
|
-
import { initDB } from "./db";
|
|
1037
1045
|
import api from "./routes";
|
|
1038
1046
|
|
|
1039
1047
|
type Env = { Bindings: { DB: D1Database } };
|
|
1040
1048
|
|
|
1041
1049
|
const app = new OpenAPIHono<Env>();
|
|
1042
1050
|
|
|
1043
|
-
app.use("*", async (c, next) => {
|
|
1044
|
-
initDB(c.env.DB);
|
|
1045
|
-
await next();
|
|
1046
|
-
});
|
|
1047
|
-
|
|
1048
1051
|
app.route("/", api);
|
|
1049
1052
|
|
|
1050
1053
|
app.doc("/api/openapi.json", {
|
|
@@ -1073,14 +1076,15 @@ createRoot(document.getElementById("app")!).render(
|
|
|
1073
1076
|
} else {
|
|
1074
1077
|
writeBlankTemplate(targetDir, name);
|
|
1075
1078
|
}
|
|
1079
|
+
const pm = detectPackageManager();
|
|
1076
1080
|
console.log();
|
|
1077
1081
|
console.log(` Created ${name} in ${path3.relative(process.cwd(), targetDir)}/`);
|
|
1078
1082
|
console.log();
|
|
1079
1083
|
console.log(" Get started:");
|
|
1080
1084
|
console.log(` cd ${path3.relative(process.cwd(), targetDir)}`);
|
|
1081
|
-
console.log(
|
|
1082
|
-
console.log(
|
|
1083
|
-
console.log(
|
|
1085
|
+
console.log(` ${pm} install`);
|
|
1086
|
+
console.log(` ${pm} ${pm === "npm" ? "run " : ""}dev # local dev at http://localhost:5173`);
|
|
1087
|
+
console.log(` ${pm} ${pm === "npm" ? "run " : ""}deploy # deploy to production`);
|
|
1084
1088
|
console.log();
|
|
1085
1089
|
}
|
|
1086
1090
|
async function initWebsite(dir, opts) {
|
|
@@ -1211,21 +1215,17 @@ import BaseLayout from "../layouts/BaseLayout.astro";
|
|
|
1211
1215
|
console.log();
|
|
1212
1216
|
}
|
|
1213
1217
|
function writeBlankTemplate(dir, name) {
|
|
1214
|
-
write(dir, "src/server/schema.sql", `CREATE TABLE IF NOT EXISTS items (
|
|
1215
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
1216
|
-
name TEXT NOT NULL,
|
|
1217
|
-
created_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
1218
|
-
);
|
|
1219
|
-
`);
|
|
1220
1218
|
write(dir, "src/server/routes.ts", `import { OpenAPIHono, createRoute, z } from "@hono/zod-openapi";
|
|
1221
|
-
import {
|
|
1219
|
+
import { getDB, desc } from "@clawnify/db";
|
|
1220
|
+
import * as schema from "./schema";
|
|
1222
1221
|
|
|
1223
|
-
|
|
1222
|
+
type Env = { Bindings: { DB: D1Database } };
|
|
1223
|
+
const api = new OpenAPIHono<Env>();
|
|
1224
1224
|
|
|
1225
1225
|
const ItemSchema = z.object({
|
|
1226
1226
|
id: z.number(),
|
|
1227
1227
|
name: z.string(),
|
|
1228
|
-
|
|
1228
|
+
createdAt: z.string(),
|
|
1229
1229
|
}).openapi("Item");
|
|
1230
1230
|
|
|
1231
1231
|
api.openapi(
|
|
@@ -1241,58 +1241,87 @@ api.openapi(
|
|
|
1241
1241
|
},
|
|
1242
1242
|
}),
|
|
1243
1243
|
async (c) => {
|
|
1244
|
-
const
|
|
1244
|
+
const db = getDB(c.env, { schema });
|
|
1245
|
+
const items = await db
|
|
1246
|
+
.select()
|
|
1247
|
+
.from(schema.items)
|
|
1248
|
+
.orderBy(desc(schema.items.createdAt));
|
|
1245
1249
|
return c.json(items);
|
|
1246
1250
|
},
|
|
1247
1251
|
);
|
|
1248
1252
|
|
|
1249
1253
|
export default api;
|
|
1250
1254
|
`);
|
|
1251
|
-
write(dir, "src/client/app.tsx", `
|
|
1252
|
-
|
|
1253
|
-
export function App() {
|
|
1254
|
-
const [items, setItems] = useState<any[]>([]);
|
|
1255
|
-
|
|
1256
|
-
useEffect(() => {
|
|
1257
|
-
fetch("/api/items").then((r) => r.json()).then(setItems);
|
|
1258
|
-
}, []);
|
|
1259
|
-
|
|
1255
|
+
write(dir, "src/client/app.tsx", `export function App() {
|
|
1260
1256
|
return (
|
|
1261
|
-
<
|
|
1262
|
-
<
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1257
|
+
<main className="min-h-screen flex items-center justify-center bg-gradient-to-br from-slate-50 to-slate-100 px-6">
|
|
1258
|
+
<div className="max-w-xl w-full text-center">
|
|
1259
|
+
<div className="inline-flex items-center gap-2 rounded-full bg-white/80 backdrop-blur px-3 py-1 text-xs font-medium text-slate-600 ring-1 ring-slate-200">
|
|
1260
|
+
<span className="size-1.5 rounded-full bg-emerald-500" />
|
|
1261
|
+
Clawnify \xB7 live
|
|
1262
|
+
</div>
|
|
1263
|
+
|
|
1264
|
+
<h1 className="mt-6 text-4xl font-semibold tracking-tight text-slate-900">
|
|
1265
|
+
Welcome to ${name}
|
|
1266
|
+
</h1>
|
|
1267
|
+
<p className="mt-3 text-base text-slate-600">
|
|
1268
|
+
Edit <code className="rounded bg-slate-200/70 px-1.5 py-0.5 text-sm">src/client/app.tsx</code> to get started.
|
|
1269
|
+
</p>
|
|
1270
|
+
|
|
1271
|
+
<ul className="mt-8 grid gap-3 text-left text-sm text-slate-700">
|
|
1272
|
+
<li className="rounded-lg border border-slate-200 bg-white px-4 py-3">
|
|
1273
|
+
<span className="font-medium text-slate-900">Try the API.</span> Open <code>/api/items</code> \u2014 empty list to start.
|
|
1267
1274
|
</li>
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1275
|
+
<li className="rounded-lg border border-slate-200 bg-white px-4 py-3">
|
|
1276
|
+
<span className="font-medium text-slate-900">Evolve the schema.</span> Edit <code>src/server/schema.ts</code>, then run <code>pnpm db:generate</code>.
|
|
1277
|
+
</li>
|
|
1278
|
+
<li className="rounded-lg border border-slate-200 bg-white px-4 py-3">
|
|
1279
|
+
<span className="font-medium text-slate-900">Deploy.</span> Run <code>pnpm deploy</code> to push live.
|
|
1280
|
+
</li>
|
|
1281
|
+
</ul>
|
|
1282
|
+
|
|
1283
|
+
<p className="mt-8 text-xs text-slate-500">
|
|
1284
|
+
Read{" "}
|
|
1285
|
+
<a href="https://github.com/clawnify/clawnify/blob/main/docs/build-a-clawnify-app.md" target="_blank" rel="noreferrer" className="underline underline-offset-2">
|
|
1286
|
+
docs/build-a-clawnify-app.md
|
|
1287
|
+
</a>{" "}
|
|
1288
|
+
for the full gold-standard guide.
|
|
1289
|
+
</p>
|
|
1290
|
+
</div>
|
|
1291
|
+
</main>
|
|
1274
1292
|
);
|
|
1275
1293
|
}
|
|
1276
1294
|
`);
|
|
1277
1295
|
}
|
|
1278
1296
|
function writeCrudTemplate(dir, name) {
|
|
1279
|
-
write(dir, "src/server/schema.
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1297
|
+
write(dir, "src/server/schema.ts", `import { sqliteTable, text, integer } from "@clawnify/db";
|
|
1298
|
+
|
|
1299
|
+
export const items = sqliteTable("items", {
|
|
1300
|
+
id: integer("id").primaryKey({ autoIncrement: true }),
|
|
1301
|
+
title: text("title").notNull(),
|
|
1302
|
+
status: text("status").notNull().default("active"),
|
|
1303
|
+
createdAt: text("created_at").notNull().$default(() => new Date().toISOString()),
|
|
1304
|
+
});
|
|
1305
|
+
`);
|
|
1306
|
+
write(dir, "drizzle/0000_init.sql", `CREATE TABLE \`items\` (
|
|
1307
|
+
\`id\` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
|
|
1308
|
+
\`title\` text NOT NULL,
|
|
1309
|
+
\`status\` text DEFAULT 'active' NOT NULL,
|
|
1310
|
+
\`created_at\` text NOT NULL
|
|
1284
1311
|
);
|
|
1285
1312
|
`);
|
|
1286
1313
|
write(dir, "src/server/routes.ts", `import { OpenAPIHono, createRoute, z } from "@hono/zod-openapi";
|
|
1287
|
-
import {
|
|
1314
|
+
import { getDB, eq, desc } from "@clawnify/db";
|
|
1315
|
+
import * as schema from "./schema";
|
|
1288
1316
|
|
|
1289
|
-
|
|
1317
|
+
type Env = { Bindings: { DB: D1Database } };
|
|
1318
|
+
const api = new OpenAPIHono<Env>();
|
|
1290
1319
|
|
|
1291
1320
|
const ItemSchema = z.object({
|
|
1292
1321
|
id: z.number(),
|
|
1293
1322
|
title: z.string(),
|
|
1294
1323
|
status: z.string(),
|
|
1295
|
-
|
|
1324
|
+
createdAt: z.string(),
|
|
1296
1325
|
}).openapi("Item");
|
|
1297
1326
|
|
|
1298
1327
|
const CreateItemSchema = z.object({ title: z.string().min(1) }).openapi("CreateItem");
|
|
@@ -1316,7 +1345,11 @@ api.openapi(
|
|
|
1316
1345
|
},
|
|
1317
1346
|
}),
|
|
1318
1347
|
async (c) => {
|
|
1319
|
-
const
|
|
1348
|
+
const db = getDB(c.env, { schema });
|
|
1349
|
+
const items = await db
|
|
1350
|
+
.select()
|
|
1351
|
+
.from(schema.items)
|
|
1352
|
+
.orderBy(desc(schema.items.createdAt));
|
|
1320
1353
|
return c.json(items);
|
|
1321
1354
|
},
|
|
1322
1355
|
);
|
|
@@ -1336,8 +1369,12 @@ api.openapi(
|
|
|
1336
1369
|
}),
|
|
1337
1370
|
async (c) => {
|
|
1338
1371
|
const { title } = c.req.valid("json");
|
|
1339
|
-
const
|
|
1340
|
-
|
|
1372
|
+
const db = getDB(c.env, { schema });
|
|
1373
|
+
const [row] = await db
|
|
1374
|
+
.insert(schema.items)
|
|
1375
|
+
.values({ title: title.trim() })
|
|
1376
|
+
.returning();
|
|
1377
|
+
return c.json(row, 201);
|
|
1341
1378
|
},
|
|
1342
1379
|
);
|
|
1343
1380
|
|
|
@@ -1357,13 +1394,12 @@ api.openapi(
|
|
|
1357
1394
|
async (c) => {
|
|
1358
1395
|
const { id } = c.req.valid("param");
|
|
1359
1396
|
const body = c.req.valid("json");
|
|
1360
|
-
const
|
|
1361
|
-
|
|
1362
|
-
if (body.
|
|
1363
|
-
if (
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
await run(\`UPDATE items SET \${sets.join(", ")} WHERE id = ?\`, params);
|
|
1397
|
+
const patch: Partial<typeof schema.items.$inferInsert> = {};
|
|
1398
|
+
if (body.title !== undefined) patch.title = body.title;
|
|
1399
|
+
if (body.status !== undefined) patch.status = body.status;
|
|
1400
|
+
if (Object.keys(patch).length === 0) return c.json({ ok: false }, 400);
|
|
1401
|
+
const db = getDB(c.env, { schema });
|
|
1402
|
+
await db.update(schema.items).set(patch).where(eq(schema.items.id, Number(id)));
|
|
1367
1403
|
return c.json({ ok: true });
|
|
1368
1404
|
},
|
|
1369
1405
|
);
|
|
@@ -1380,7 +1416,8 @@ api.openapi(
|
|
|
1380
1416
|
}),
|
|
1381
1417
|
async (c) => {
|
|
1382
1418
|
const { id } = c.req.valid("param");
|
|
1383
|
-
|
|
1419
|
+
const db = getDB(c.env, { schema });
|
|
1420
|
+
await db.delete(schema.items).where(eq(schema.items.id, Number(id)));
|
|
1384
1421
|
return c.json({ ok: true });
|
|
1385
1422
|
},
|
|
1386
1423
|
);
|
|
@@ -1393,7 +1430,7 @@ interface Item {
|
|
|
1393
1430
|
id: number;
|
|
1394
1431
|
title: string;
|
|
1395
1432
|
status: string;
|
|
1396
|
-
|
|
1433
|
+
createdAt: string;
|
|
1397
1434
|
}
|
|
1398
1435
|
|
|
1399
1436
|
export function App() {
|
|
@@ -1555,8 +1592,12 @@ async function devCommand(dir, options) {
|
|
|
1555
1592
|
fs3.mkdirSync(clawnifyDir, { recursive: true });
|
|
1556
1593
|
const wranglerPath = path4.join(clawnifyDir, "wrangler.toml");
|
|
1557
1594
|
fs3.writeFileSync(wranglerPath, generateWranglerToml(slug, { database, storage }));
|
|
1558
|
-
const
|
|
1559
|
-
|
|
1595
|
+
const schemaCandidates = [
|
|
1596
|
+
path4.join(resolvedDir, "schema.sql"),
|
|
1597
|
+
path4.join(resolvedDir, "src/server/schema.sql")
|
|
1598
|
+
];
|
|
1599
|
+
const schemaPath = schemaCandidates.find((p) => fs3.existsSync(p));
|
|
1600
|
+
if (database && schemaPath) {
|
|
1560
1601
|
await runQuiet(resolvedDir, "npx", [
|
|
1561
1602
|
"wrangler",
|
|
1562
1603
|
"d1",
|
|
@@ -2001,11 +2042,344 @@ async function sdkInstallCommand() {
|
|
|
2001
2042
|
process.exit(1);
|
|
2002
2043
|
}
|
|
2003
2044
|
|
|
2045
|
+
// src/lib/skills/content.gen.ts
|
|
2046
|
+
var CLI_VERSION = "0.4.0";
|
|
2047
|
+
var BUNDLED_SKILLS = [
|
|
2048
|
+
{
|
|
2049
|
+
name: "build-a-clawnify-app",
|
|
2050
|
+
description: "Gold-standard structure for building Clawnify apps end-to-end (Hono + React + tRPC + @clawnify/db).",
|
|
2051
|
+
content: '# Build a Clawnify app\n\nCanonical skill: how to author a Clawnify app end-to-end. Same\ncontent for humans reading the docs and for agents (Pi, OpenClaw,\nClaude Code) injecting this as instructions during an app build.\n\nIf you\'re an agent: this document is enough context to produce a\nworking app from scratch. Follow it literally. The patterns here\nare the patterns the platform expects.\n\n## TL;DR\n\n- **One stack.** Hono + React + Vite + tRPC + `@clawnify/db` (Drizzle)\n + Tailwind + shadcn/ui. Nothing else.\n- **Schema lives in `schema.ts`** (Drizzle DSL) \u2014 single source of\n truth. Never write SQL DDL by hand.\n- **Queries through `getDB`** \u2014 `import { getDB, eq } from\n "@clawnify/db"`. JSON columns auto-serialize.\n- **`clawnify.json`** declares framework, env, and public routes.\n Build emits `api.tools[]` from tRPC procedure meta.\n- **No `/mcp` endpoint.** The org\'s MCP gateway projects tools\n from the manifest.\n- **Identity flows via `X-Clawnify-*` headers** injected by the\n platform. Read them, don\'t fake them.\n\n## Stack rationale\n\nOne template, one set of decisions. Full reasoning lives in\n[`docs/template-strategy.md`](./template-strategy.md). Don\'t deviate\nunless the user has explicitly asked.\n\n## File layout\n\n```\nmy-app/\n clawnify.json \u2190 Manifest (validated against /schema/v1/clawnify.json)\n package.json\n tsconfig.json\n vite.config.ts\n tailwind.config.ts\n components.json \u2190 shadcn/ui config\n index.html\n drizzle.config.ts \u2190 Points at src/server/schema.ts\n drizzle/ \u2190 Generated migrations + snapshots (DON\'T hand-edit)\n 0000_init.sql\n meta/\n _journal.json\n 0000_snapshot.json\n src/\n server/\n index.ts \u2190 Hono entry \u2014 mounts the tRPC router\n schema.ts \u2190 Drizzle table definitions \u2014 THE schema\n router.ts \u2190 tRPC router with MCP-tagged procedures\n auth.ts \u2190 Read X-Clawnify-* identity headers\n env.d.ts \u2190 Worker bindings types\n client/\n main.tsx \u2190 React mount point\n app.tsx \u2190 Root component\n lib/\n trpc.ts \u2190 Typed tRPC client\n components/ \u2190 shadcn/ui + your components\n styles.css\n```\n\n## `schema.ts` \u2014 the only place tables exist\n\n```ts\n// src/server/schema.ts\nimport { sqliteTable, text, integer, index } from "@clawnify/db";\n\nexport const notes = sqliteTable(\n "notes",\n {\n id: integer("id").primaryKey({ autoIncrement: true }),\n orgId: text("org_id").notNull(), // ALWAYS filter by this in queries\n title: text("title").notNull(),\n body: text("body").notNull().default(""),\n tags: text("tags", { mode: "json" }).$type<string[]>().notNull().default([]),\n createdAt: text("created_at").notNull().$default(() => new Date().toISOString()),\n },\n (t) => ({\n byOrg: index("notes_by_org").on(t.orgId, t.createdAt),\n }),\n);\n```\n\nRules:\n- JSON columns: `text(col, { mode: "json" }).$type<T>()` \u2014 Drizzle\n serializes on write and parses on read.\n- Multi-tenancy: every user-facing table has `org_id`. Every query\n filters by it. No exceptions.\n- Identifiers: snake_case in SQL, camelCase in TS (Drizzle bridges).\n\n## `drizzle.config.ts`\n\n```ts\nimport { defineConfig } from "drizzle-kit";\n\nexport default defineConfig({\n schema: "./src/server/schema.ts",\n out: "./drizzle",\n dialect: "sqlite",\n});\n```\n\nThe build pipeline reads this and runs `drizzle-kit generate` when\nthe schema changes, then applies migrations transactionally.\n\n## `src/server/index.ts` \u2014 Hono entry\n\n```ts\nimport { Hono } from "hono";\nimport { trpcServer } from "@hono/trpc-server";\nimport { appRouter } from "./router";\nimport { createContext } from "./auth";\n\nconst app = new Hono<{ Bindings: Env }>();\n\napp.use("/trpc/*", trpcServer({\n router: appRouter,\n createContext: (opts, c) => createContext(opts, c.env, c.req.raw),\n}));\n\n// SPA fallback \u2014 Vite-built static assets served by the platform\napp.notFound((c) => c.env.ASSETS.fetch(c.req.raw));\n\nexport default app;\n```\n\nThat\'s it. The Worker entry is thin. No MCP mounting, no inline\nroute handlers \u2014 tRPC owns the API surface.\n\n## `src/server/auth.ts` \u2014 identity from headers\n\n```ts\nimport type { Context } from "hono";\n\nexport interface User {\n id: string;\n orgId: string;\n email: string;\n caller: "user" | "agent" | "agent-browser" | "system";\n}\n\nexport function readUser(req: Request): User | null {\n const id = req.headers.get("X-Clawnify-User-Id");\n const orgId = req.headers.get("X-Clawnify-Org-Id");\n const email = req.headers.get("X-Clawnify-User-Email") ?? "";\n const caller = (req.headers.get("X-Clawnify-Caller") ?? "user") as User["caller"];\n if (!id || !orgId) return null;\n return { id, orgId, email, caller };\n}\n\nexport function createContext(_opts: unknown, env: Env, req: Request) {\n const user = readUser(req);\n return { env, user };\n}\n```\n\nTrust these headers \u2014 the platform strips client-supplied versions\nand reinjects authenticated ones at the perimeter. Never read\n`Authorization` or session cookies directly.\n\n## `src/server/router.ts` \u2014 tRPC procedures with MCP meta\n\n```ts\nimport { initTRPC } from "@trpc/server";\nimport { z } from "zod";\nimport { getDB, eq, desc, and } from "@clawnify/db";\nimport * as schema from "./schema";\nimport type { User } from "./auth";\n\nconst t = initTRPC.context<{ env: Env; user: User | null }>().create();\n\nconst authed = t.procedure.use(({ ctx, next }) => {\n if (!ctx.user) throw new Error("UNAUTHORIZED");\n return next({ ctx: { ...ctx, user: ctx.user } });\n});\n\nexport const appRouter = t.router({\n list_notes: authed\n .meta({ mcp: { name: "list_notes", description: "List the user\'s notes." } })\n .input(z.object({ limit: z.number().int().min(1).max(100).default(50) }))\n .output(z.array(z.object({\n id: z.number(),\n title: z.string(),\n body: z.string(),\n tags: z.array(z.string()),\n createdAt: z.string(),\n })))\n .query(async ({ ctx, input }) => {\n const db = getDB(ctx.env, { schema });\n return db\n .select()\n .from(schema.notes)\n .where(eq(schema.notes.orgId, ctx.user.orgId))\n .orderBy(desc(schema.notes.createdAt))\n .limit(input.limit);\n }),\n\n create_note: authed\n .meta({ mcp: { name: "create_note", description: "Create a new note." } })\n .input(z.object({\n title: z.string().min(1),\n body: z.string().default(""),\n tags: z.array(z.string()).default([]),\n }))\n .mutation(async ({ ctx, input }) => {\n const db = getDB(ctx.env, { schema });\n const [row] = await db\n .insert(schema.notes)\n .values({ ...input, orgId: ctx.user.orgId })\n .returning();\n return row;\n }),\n});\n\nexport type AppRouter = typeof appRouter;\n```\n\nPatterns to follow:\n- **Every state-mutating procedure** that an agent might want to\n call gets `.meta({ mcp: { name, description } })`. The build\n picks these up into `clawnify.json api.tools[]`. The Clawnify\n MCP gateway projects them as MCP tools.\n- **Auth via middleware** (`authed`). Never check headers inside\n a procedure body.\n- **Filter by `ctx.user.orgId`** on every query. No exceptions.\n- **Schema-validated input + output** with Zod. The output schema\n is what the agent sees as the tool\'s return shape.\n- **Procedure names are intent verbs** (`archive_old_notes`,\n `publish_post`), not REST resource shapes (`get_notes`,\n `update_note`). Tools describe what the agent wants to do.\n\n## `src/client` \u2014 React + tRPC + shadcn\n\n```tsx\n// src/client/lib/trpc.ts\nimport { createTRPCReact, httpBatchLink } from "@trpc/react-query";\nimport type { AppRouter } from "../../server/router";\n\nexport const trpc = createTRPCReact<AppRouter>();\nexport const trpcClient = trpc.createClient({\n links: [httpBatchLink({ url: "/trpc" })],\n});\n```\n\n```tsx\n// src/client/app.tsx\nimport { useState } from "react";\nimport { QueryClient, QueryClientProvider } from "@tanstack/react-query";\nimport { trpc, trpcClient } from "./lib/trpc";\nimport { Button } from "./components/ui/button";\n\nconst queryClient = new QueryClient();\n\nexport function App() {\n return (\n <trpc.Provider client={trpcClient} queryClient={queryClient}>\n <QueryClientProvider client={queryClient}>\n <NotesList />\n </QueryClientProvider>\n </trpc.Provider>\n );\n}\n\nfunction NotesList() {\n const notes = trpc.list_notes.useQuery({ limit: 50 });\n const create = trpc.create_note.useMutation({\n onSuccess: () => notes.refetch(),\n });\n const [title, setTitle] = useState("");\n\n return (\n <div>\n {notes.data?.map((n) => <div key={n.id}>{n.title}</div>)}\n <Button onClick={() => create.mutate({ title, body: "" })}>\n Add note\n </Button>\n </div>\n );\n}\n```\n\nThe same tRPC procedures power the agent (via MCP) and the UI (via\ntyped client). One backend, two front doors.\n\n## `clawnify.json` \u2014 the manifest\n\n```json\n{\n "$schema": "https://app.clawnify.com/schema/v1/clawnify.json",\n "version": 1,\n "name": "Notes",\n "description": "Take and organize notes. Searchable by tag.",\n "icon": "icon.svg",\n "tags": ["productivity"],\n "app": {\n "framework": "react+hono",\n "database": true,\n "storage": false\n },\n "env": {\n "required": ["OPENROUTER_API_KEY"]\n },\n "api": {\n "public_routes": [\n { "path": "/api/feed", "methods": ["GET"] }\n ]\n }\n}\n```\n\nRules:\n- **Don\'t hand-edit `api.tools[]`** \u2014 generated at build from tRPC\n `.meta({ mcp: { ... } })` annotations.\n- **Public routes are the exception**, not the default. Every tRPC\n procedure is private (auth-required) unless you explicitly add a\n matching path to `public_routes`. Use only for webhooks, RSS,\n embedded feeds.\n- **`framework: "react+hono"`** for new apps. Never `preact+hono` or\n `vite-preact` \u2014 those are legacy.\n- **`database: true`** if the app uses a DB. Schema is generated\n from `schema.ts` via drizzle-kit; no `schema.sql` to ship.\n\n## Migrations\n\nYou don\'t write migration SQL by hand. The workflow:\n\n1. Edit `src/server/schema.ts` to reflect the new shape.\n2. Build pipeline runs `drizzle-kit generate` \u2014 emits a new file\n under `drizzle/` and updates the snapshot.\n3. Build applies pending migrations transactionally to D1 and to\n the Facet (preview tier). Tracked in `__clawnify_migrations`.\n\nFor destructive changes (drop column, rename), Drizzle\'s generator\nwill prompt \u2014 agents should default to additive changes and only\ndo destructive ones when the user explicitly asks. Renames are\nrisky on production data; prefer "add new column, backfill, switch\nqueries, drop old column" over a single-step rename.\n\n## What the agent must NOT do\n\n- Mount `/mcp` manually. The gateway projects tools from the\n manifest \u2014 exception is in `docs/packages.md`.\n- Author `schema.sql` by hand. Use `schema.ts`.\n- Author migration SQL by hand. Let `drizzle-kit generate` do it.\n- Use `JSON.stringify` on query params. JSON columns auto-serialize\n via Drizzle. The raw API has `json()` as a helper.\n- Bind tRPC procedures by REST resource shape (`get_user_by_id`).\n Use intent verbs (`onboard_user`, `archive_old_orders`).\n- Skip the `org_id` filter on a user-facing query. Multi-tenant\n leak is the worst-class bug we can ship.\n- Read auth from `Authorization` / cookies / `Bearer` tokens. Use\n the `X-Clawnify-*` headers via `auth.ts`.\n- Pin `drizzle-orm` in the app\'s `package.json` to a version that\n drifts from `@clawnify/db`\'s peer range. Pin it to the same\n major/minor.\n\n## What the agent SHOULD do\n\n- Import everything from `@clawnify/db` where possible\n (`getDB`, `eq`, `and`, `sql`, `sqliteTable`, `text`, `integer`,\n etc. are all re-exported there). Drop to `drizzle-orm` directly\n only for things not re-exported.\n- Add `.meta({ mcp: { name, description } })` to every state-\n mutating procedure that the user\'s agent might want to call.\n- Test on the draft URL (`<slug>.draft.clawnify.com`) before\n publishing \u2014 the Facet preview tier catches schema drift and\n type errors at build time.\n- When unsure about a Drizzle pattern, check\n [`packages/db/README.md`](../packages/db/README.md) for the\n current API + version notes.\n\n## Schema-as-data exception\n\nApps that let END users define data shapes at runtime (CMS, no-code\ntable editor) can\'t model their schema in `schema.ts` \u2014 the table\ndefinitions live in rows. Those apps fall back to the raw SQL API\nfrom `@clawnify/db` (`query`, `get`, `run`, `json`). Open-cms is\nthe canonical example.\n\nIf you\'re building this kind of app, you still use Drizzle\'s\n`schema.ts` for the **registry** tables (content types, field\ndefinitions). Only the dynamically-spawned per-collection tables\nneed raw SQL. See open-cms\'s `src/server/schema-sync.ts` for the\nruntime DDL pattern.\n\n## See also\n\n- [`docs/template-strategy.md`](./template-strategy.md) \u2014 why this\n stack\n- [`docs/packages.md`](./packages.md) \u2014 what `@clawnify/db`\n exposes; planned package surface\n- [`docs/clawnify-mcp-gateway.md`](./clawnify-mcp-gateway.md) \u2014\n how the gateway projects your manifest as MCP tools\n- [`docs/clawnify-apps-migrations.md`](./clawnify-apps-migrations.md)\n \u2014 migration internals\n- [`packages/db/README.md`](../packages/db/README.md) \u2014 full API\n'
|
|
2052
|
+
}
|
|
2053
|
+
];
|
|
2054
|
+
|
|
2055
|
+
// src/lib/skills/detect.ts
|
|
2056
|
+
import { statSync } from "fs";
|
|
2057
|
+
import { join } from "path";
|
|
2058
|
+
var DETECTORS = [
|
|
2059
|
+
{ agent: "claude", markers: [".claude", ".claude.json", "CLAUDE.md"], target: ".claude/skills" },
|
|
2060
|
+
{ agent: "cursor", markers: [".cursor", ".cursorrules"], target: ".cursor/rules" },
|
|
2061
|
+
{ agent: "openclaw", markers: [".openclaw", "openclaw.json"], target: ".openclaw/skills" },
|
|
2062
|
+
{ agent: "codex", markers: [".codex", "AGENTS.md"], target: ".codex/skills" },
|
|
2063
|
+
{ agent: "aider", markers: ["CONVENTIONS.md", ".aider.conf.yml"], target: "CONVENTIONS.md" }
|
|
2064
|
+
];
|
|
2065
|
+
function exists(cwd, name) {
|
|
2066
|
+
const path7 = join(cwd, name);
|
|
2067
|
+
try {
|
|
2068
|
+
statSync(path7);
|
|
2069
|
+
return true;
|
|
2070
|
+
} catch {
|
|
2071
|
+
return false;
|
|
2072
|
+
}
|
|
2073
|
+
}
|
|
2074
|
+
function detectAgents(cwd) {
|
|
2075
|
+
const found = [];
|
|
2076
|
+
for (const d of DETECTORS) {
|
|
2077
|
+
const hit = d.markers.find((m) => exists(cwd, m));
|
|
2078
|
+
if (hit) {
|
|
2079
|
+
found.push({ agent: d.agent, target: d.target, marker: hit });
|
|
2080
|
+
}
|
|
2081
|
+
}
|
|
2082
|
+
return found;
|
|
2083
|
+
}
|
|
2084
|
+
function agentByName(name) {
|
|
2085
|
+
const d = DETECTORS.find((x) => x.agent === name);
|
|
2086
|
+
if (!d) throw new Error(`Unknown agent: ${name}`);
|
|
2087
|
+
return { agent: d.agent, target: d.target, marker: "(forced)" };
|
|
2088
|
+
}
|
|
2089
|
+
var ALL_AGENTS = DETECTORS.map((d) => d.agent);
|
|
2090
|
+
|
|
2091
|
+
// src/lib/skills/install.ts
|
|
2092
|
+
import {
|
|
2093
|
+
existsSync as existsSync2,
|
|
2094
|
+
mkdirSync,
|
|
2095
|
+
readFileSync,
|
|
2096
|
+
writeFileSync,
|
|
2097
|
+
statSync as statSync2,
|
|
2098
|
+
rmSync,
|
|
2099
|
+
unlinkSync
|
|
2100
|
+
} from "fs";
|
|
2101
|
+
import { dirname, join as join2 } from "path";
|
|
2102
|
+
var VERSION_HEADER_RE = /<!--\s*clawnify-skill:\s*([\w-]+)\s+v([\d.]+)\s*-->/;
|
|
2103
|
+
function versionHeader(name) {
|
|
2104
|
+
return `<!-- clawnify-skill: ${name} v${CLI_VERSION} -->`;
|
|
2105
|
+
}
|
|
2106
|
+
function readExistingVersion(path7) {
|
|
2107
|
+
if (!existsSync2(path7)) return null;
|
|
2108
|
+
try {
|
|
2109
|
+
const head = readFileSync(path7, "utf8").slice(0, 500);
|
|
2110
|
+
const match = head.match(VERSION_HEADER_RE);
|
|
2111
|
+
return match ? match[2] : null;
|
|
2112
|
+
} catch {
|
|
2113
|
+
return null;
|
|
2114
|
+
}
|
|
2115
|
+
}
|
|
2116
|
+
function installSkill(skill, agent, cwd) {
|
|
2117
|
+
switch (agent.agent) {
|
|
2118
|
+
case "claude":
|
|
2119
|
+
return writeSkillDir(skill, cwd, agent.target, formatClaudeSkill);
|
|
2120
|
+
case "codex":
|
|
2121
|
+
return writeSkillDir(skill, cwd, agent.target, formatCodexSkill);
|
|
2122
|
+
case "openclaw":
|
|
2123
|
+
return writeOpenclawSkill(skill, cwd, agent.target);
|
|
2124
|
+
case "cursor":
|
|
2125
|
+
return writeCursorRule(skill, cwd, agent.target);
|
|
2126
|
+
case "aider":
|
|
2127
|
+
return writeAiderSection(skill, cwd, agent.target);
|
|
2128
|
+
}
|
|
2129
|
+
}
|
|
2130
|
+
function formatClaudeSkill(skill) {
|
|
2131
|
+
return `${versionHeader(skill.name)}
|
|
2132
|
+
---
|
|
2133
|
+
name: ${skill.name}
|
|
2134
|
+
description: ${JSON.stringify(skill.description)}
|
|
2135
|
+
---
|
|
2136
|
+
|
|
2137
|
+
${skill.content}`;
|
|
2138
|
+
}
|
|
2139
|
+
function formatCodexSkill(skill) {
|
|
2140
|
+
return formatClaudeSkill(skill);
|
|
2141
|
+
}
|
|
2142
|
+
function writeSkillDir(skill, cwd, targetDir, format) {
|
|
2143
|
+
const skillDir = join2(cwd, targetDir, skill.name);
|
|
2144
|
+
const filePath = join2(skillDir, "SKILL.md");
|
|
2145
|
+
const existing = readExistingVersion(filePath);
|
|
2146
|
+
if (existing === CLI_VERSION) {
|
|
2147
|
+
return { status: "skipped", path: filePath, reason: `already at v${CLI_VERSION}` };
|
|
2148
|
+
}
|
|
2149
|
+
mkdirSync(skillDir, { recursive: true });
|
|
2150
|
+
writeFileSync(filePath, format(skill));
|
|
2151
|
+
return existing ? { status: "updated", path: filePath, previousVersion: existing } : { status: "installed", path: filePath };
|
|
2152
|
+
}
|
|
2153
|
+
function writeOpenclawSkill(skill, cwd, targetDir) {
|
|
2154
|
+
const skillDir = join2(cwd, targetDir, skill.name);
|
|
2155
|
+
const mdPath = join2(skillDir, "SKILL.md");
|
|
2156
|
+
const jsonPath = join2(skillDir, "skill.json");
|
|
2157
|
+
const existing = readExistingVersion(mdPath);
|
|
2158
|
+
if (existing === CLI_VERSION) {
|
|
2159
|
+
return { status: "skipped", path: mdPath, reason: `already at v${CLI_VERSION}` };
|
|
2160
|
+
}
|
|
2161
|
+
mkdirSync(skillDir, { recursive: true });
|
|
2162
|
+
writeFileSync(mdPath, `${versionHeader(skill.name)}
|
|
2163
|
+
${skill.content}`);
|
|
2164
|
+
writeFileSync(
|
|
2165
|
+
jsonPath,
|
|
2166
|
+
JSON.stringify(
|
|
2167
|
+
{
|
|
2168
|
+
name: skill.name,
|
|
2169
|
+
displayName: skill.name.split("-").map((p) => p[0].toUpperCase() + p.slice(1)).join(" "),
|
|
2170
|
+
description: skill.description,
|
|
2171
|
+
trigger: "manual",
|
|
2172
|
+
inputs: []
|
|
2173
|
+
},
|
|
2174
|
+
null,
|
|
2175
|
+
2
|
|
2176
|
+
)
|
|
2177
|
+
);
|
|
2178
|
+
return existing ? { status: "updated", path: mdPath, previousVersion: existing } : { status: "installed", path: mdPath };
|
|
2179
|
+
}
|
|
2180
|
+
function writeCursorRule(skill, cwd, targetDir) {
|
|
2181
|
+
const dir = join2(cwd, targetDir);
|
|
2182
|
+
const filePath = join2(dir, `${skill.name}.mdc`);
|
|
2183
|
+
const existing = readExistingVersion(filePath);
|
|
2184
|
+
if (existing === CLI_VERSION) {
|
|
2185
|
+
return { status: "skipped", path: filePath, reason: `already at v${CLI_VERSION}` };
|
|
2186
|
+
}
|
|
2187
|
+
mkdirSync(dir, { recursive: true });
|
|
2188
|
+
const body = `${versionHeader(skill.name)}
|
|
2189
|
+
---
|
|
2190
|
+
description: ${JSON.stringify(skill.description)}
|
|
2191
|
+
alwaysApply: false
|
|
2192
|
+
---
|
|
2193
|
+
|
|
2194
|
+
${skill.content}`;
|
|
2195
|
+
writeFileSync(filePath, body);
|
|
2196
|
+
return existing ? { status: "updated", path: filePath, previousVersion: existing } : { status: "installed", path: filePath };
|
|
2197
|
+
}
|
|
2198
|
+
function writeAiderSection(skill, cwd, targetFile) {
|
|
2199
|
+
const filePath = join2(cwd, targetFile);
|
|
2200
|
+
const startMarker = `<!-- clawnify-skill-start: ${skill.name} -->`;
|
|
2201
|
+
const endMarker = `<!-- clawnify-skill-end: ${skill.name} -->`;
|
|
2202
|
+
const section = `${startMarker}
|
|
2203
|
+
${versionHeader(skill.name)}
|
|
2204
|
+
${skill.content}
|
|
2205
|
+
${endMarker}
|
|
2206
|
+
`;
|
|
2207
|
+
let existing = "";
|
|
2208
|
+
let existingVersion = null;
|
|
2209
|
+
if (existsSync2(filePath)) {
|
|
2210
|
+
existing = readFileSync(filePath, "utf8");
|
|
2211
|
+
const sectionRe = new RegExp(
|
|
2212
|
+
`${escapeRe(startMarker)}[\\s\\S]*?${escapeRe(endMarker)}\\n?`
|
|
2213
|
+
);
|
|
2214
|
+
const sectionMatch = existing.match(sectionRe);
|
|
2215
|
+
if (sectionMatch) {
|
|
2216
|
+
const headMatch = sectionMatch[0].match(VERSION_HEADER_RE);
|
|
2217
|
+
existingVersion = headMatch ? headMatch[2] : null;
|
|
2218
|
+
if (existingVersion === CLI_VERSION) {
|
|
2219
|
+
return { status: "skipped", path: filePath, reason: `already at v${CLI_VERSION}` };
|
|
2220
|
+
}
|
|
2221
|
+
const next = existing.replace(sectionRe, section);
|
|
2222
|
+
mkdirSync(dirname(filePath), { recursive: true });
|
|
2223
|
+
writeFileSync(filePath, next);
|
|
2224
|
+
return existingVersion ? { status: "updated", path: filePath, previousVersion: existingVersion } : { status: "installed", path: filePath };
|
|
2225
|
+
}
|
|
2226
|
+
}
|
|
2227
|
+
mkdirSync(dirname(filePath), { recursive: true });
|
|
2228
|
+
const prefix = existing && !existing.endsWith("\n") ? "\n" : "";
|
|
2229
|
+
writeFileSync(filePath, existing + prefix + section);
|
|
2230
|
+
return { status: "installed", path: filePath };
|
|
2231
|
+
}
|
|
2232
|
+
function escapeRe(s) {
|
|
2233
|
+
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
2234
|
+
}
|
|
2235
|
+
function removeSkill(skillName, agent, cwd) {
|
|
2236
|
+
if (agent.agent === "aider") {
|
|
2237
|
+
const filePath = join2(cwd, agent.target);
|
|
2238
|
+
if (!existsSync2(filePath)) return false;
|
|
2239
|
+
const content = readFileSync(filePath, "utf8");
|
|
2240
|
+
const startMarker = `<!-- clawnify-skill-start: ${skillName} -->`;
|
|
2241
|
+
const endMarker = `<!-- clawnify-skill-end: ${skillName} -->`;
|
|
2242
|
+
const sectionRe = new RegExp(
|
|
2243
|
+
`${escapeRe(startMarker)}[\\s\\S]*?${escapeRe(endMarker)}\\n?`
|
|
2244
|
+
);
|
|
2245
|
+
if (!sectionRe.test(content)) return false;
|
|
2246
|
+
writeFileSync(filePath, content.replace(sectionRe, ""));
|
|
2247
|
+
return true;
|
|
2248
|
+
}
|
|
2249
|
+
if (agent.agent === "cursor") {
|
|
2250
|
+
const candidate = join2(cwd, agent.target, `${skillName}.mdc`);
|
|
2251
|
+
if (!existsSync2(candidate)) return false;
|
|
2252
|
+
unlinkSync(candidate);
|
|
2253
|
+
return true;
|
|
2254
|
+
}
|
|
2255
|
+
const dir = join2(cwd, agent.target, skillName);
|
|
2256
|
+
if (!existsSync2(dir)) return false;
|
|
2257
|
+
try {
|
|
2258
|
+
const s = statSync2(dir);
|
|
2259
|
+
if (!s.isDirectory()) return false;
|
|
2260
|
+
} catch {
|
|
2261
|
+
return false;
|
|
2262
|
+
}
|
|
2263
|
+
rmSync(dir, { recursive: true, force: true });
|
|
2264
|
+
return true;
|
|
2265
|
+
}
|
|
2266
|
+
|
|
2267
|
+
// src/commands/skills.ts
|
|
2268
|
+
function skillsListCommand() {
|
|
2269
|
+
console.log(`Clawnify skills (v${CLI_VERSION}):
|
|
2270
|
+
`);
|
|
2271
|
+
for (const s of BUNDLED_SKILLS) {
|
|
2272
|
+
console.log(` ${s.name}`);
|
|
2273
|
+
console.log(` ${s.description}
|
|
2274
|
+
`);
|
|
2275
|
+
}
|
|
2276
|
+
console.log(`Add one: clawnify skills add <name>`);
|
|
2277
|
+
console.log(`Add all: clawnify skills add --all`);
|
|
2278
|
+
console.log(`Remove: clawnify skills remove <name>`);
|
|
2279
|
+
}
|
|
2280
|
+
async function skillsAddCommand(name, opts) {
|
|
2281
|
+
const skills = resolveSkills(name, opts.all);
|
|
2282
|
+
if (skills.length === 0) {
|
|
2283
|
+
console.error("No skill specified. Pass a name or --all. See `clawnify skills list`.");
|
|
2284
|
+
process.exit(1);
|
|
2285
|
+
}
|
|
2286
|
+
const agents = resolveAgents(opts.agent);
|
|
2287
|
+
if (agents.length === 0) {
|
|
2288
|
+
console.error(
|
|
2289
|
+
"No coding agent detected in this directory. Looked for:\n .claude/ (Claude Code)\n .cursor/ (Cursor)\n .openclaw/ (OpenClaw)\n .codex/ or AGENTS.md (Codex)\n CONVENTIONS.md or .aider.conf.yml (Aider)\n\nForce a target with --agent <claude|cursor|openclaw|codex|aider>."
|
|
2290
|
+
);
|
|
2291
|
+
process.exit(1);
|
|
2292
|
+
}
|
|
2293
|
+
const cwd = process.cwd();
|
|
2294
|
+
console.log(
|
|
2295
|
+
`Installing ${skills.length} skill${skills.length === 1 ? "" : "s"} into ${agents.length} agent${agents.length === 1 ? "" : "s"}:`
|
|
2296
|
+
);
|
|
2297
|
+
console.log(` CLI version: v${CLI_VERSION}`);
|
|
2298
|
+
console.log(
|
|
2299
|
+
` Agents: ${agents.map((a) => `${a.agent} (${a.marker})`).join(", ")}
|
|
2300
|
+
`
|
|
2301
|
+
);
|
|
2302
|
+
let installed = 0;
|
|
2303
|
+
let updated = 0;
|
|
2304
|
+
let skipped = 0;
|
|
2305
|
+
for (const skill of skills) {
|
|
2306
|
+
for (const agent of agents) {
|
|
2307
|
+
const result = installSkill(skill, agent, cwd);
|
|
2308
|
+
if (result.status === "installed") {
|
|
2309
|
+
installed++;
|
|
2310
|
+
console.log(` \u2713 ${skill.name} \u2192 ${result.path}`);
|
|
2311
|
+
} else if (result.status === "updated") {
|
|
2312
|
+
updated++;
|
|
2313
|
+
console.log(
|
|
2314
|
+
` \u2191 ${skill.name} \u2192 ${result.path} (v${result.previousVersion} \u2192 v${CLI_VERSION})`
|
|
2315
|
+
);
|
|
2316
|
+
} else {
|
|
2317
|
+
skipped++;
|
|
2318
|
+
console.log(` \xB7 ${skill.name} \u2192 ${result.path} (${result.reason})`);
|
|
2319
|
+
}
|
|
2320
|
+
}
|
|
2321
|
+
}
|
|
2322
|
+
console.log(
|
|
2323
|
+
`
|
|
2324
|
+
Done \u2014 ${installed} installed, ${updated} updated, ${skipped} unchanged.`
|
|
2325
|
+
);
|
|
2326
|
+
}
|
|
2327
|
+
async function skillsRemoveCommand(name, opts) {
|
|
2328
|
+
const skills = resolveSkills(name, opts.all);
|
|
2329
|
+
if (skills.length === 0) {
|
|
2330
|
+
console.error("No skill specified. Pass a name or --all.");
|
|
2331
|
+
process.exit(1);
|
|
2332
|
+
}
|
|
2333
|
+
const agents = resolveAgents(opts.agent);
|
|
2334
|
+
if (agents.length === 0) {
|
|
2335
|
+
console.error("No coding agent detected. Nothing to remove.");
|
|
2336
|
+
return;
|
|
2337
|
+
}
|
|
2338
|
+
const cwd = process.cwd();
|
|
2339
|
+
let removed = 0;
|
|
2340
|
+
for (const skill of skills) {
|
|
2341
|
+
for (const agent of agents) {
|
|
2342
|
+
if (removeSkill(skill.name, agent, cwd)) {
|
|
2343
|
+
removed++;
|
|
2344
|
+
console.log(` \u2717 ${skill.name} removed from ${agent.agent}`);
|
|
2345
|
+
}
|
|
2346
|
+
}
|
|
2347
|
+
}
|
|
2348
|
+
console.log(`
|
|
2349
|
+
Done \u2014 removed ${removed} file${removed === 1 ? "" : "s"}.`);
|
|
2350
|
+
}
|
|
2351
|
+
function resolveSkills(name, all) {
|
|
2352
|
+
if (all) return [...BUNDLED_SKILLS];
|
|
2353
|
+
if (!name) return [];
|
|
2354
|
+
const match = BUNDLED_SKILLS.find((s) => s.name === name);
|
|
2355
|
+
if (!match) {
|
|
2356
|
+
console.error(
|
|
2357
|
+
`Unknown skill: ${name}
|
|
2358
|
+
Available: ${BUNDLED_SKILLS.map((s) => s.name).join(", ")}`
|
|
2359
|
+
);
|
|
2360
|
+
process.exit(1);
|
|
2361
|
+
}
|
|
2362
|
+
return [match];
|
|
2363
|
+
}
|
|
2364
|
+
function resolveAgents(forced) {
|
|
2365
|
+
if (forced) {
|
|
2366
|
+
if (!ALL_AGENTS.includes(forced)) {
|
|
2367
|
+
console.error(
|
|
2368
|
+
`Unknown agent: ${forced}
|
|
2369
|
+
Valid: ${ALL_AGENTS.join(", ")}`
|
|
2370
|
+
);
|
|
2371
|
+
process.exit(1);
|
|
2372
|
+
}
|
|
2373
|
+
return [agentByName(forced)];
|
|
2374
|
+
}
|
|
2375
|
+
return detectAgents(process.cwd());
|
|
2376
|
+
}
|
|
2377
|
+
|
|
2004
2378
|
// src/cli.ts
|
|
2005
2379
|
function runCli() {
|
|
2006
2380
|
const program = new Command();
|
|
2007
2381
|
program.name("clawnify").description("Deploy apps to Clawnify").version("0.1.0");
|
|
2008
|
-
program.command("init [dir]").description("Scaffold a new Clawnify project (app or website)").option("--type <type>", "Project type: app or website (skips prompt)").option("--name <name>", "Project name (skips prompt)").option("--template <template>", "App template: blank or crud (apps only)").option("--storage", "Enable file uploads (R2) \u2014 apps only").action(initCommand);
|
|
2382
|
+
program.command("init [dir]").description("Scaffold a new Clawnify project (app or website)").option("--type <type>", "Project type: app or website (skips prompt)").option("--name <name>", "Project name (skips prompt)").option("--template <template>", "App template: blank or crud (apps only)").option("--storage", "Enable file uploads (R2) \u2014 apps only").option("-y, --yes", "Non-interactive: use all defaults (app, blank, no storage)").action(initCommand);
|
|
2009
2383
|
program.command("dev [dir]").description("Start local dev server").option("--port <port>", "API server port (default: 8787)").action(devCommand);
|
|
2010
2384
|
program.command("login").description("Authenticate with Clawnify").action(loginCommand);
|
|
2011
2385
|
program.command("deploy [dir]").description("Deploy an app or website to Clawnify").option("--from <repo>", "Deploy from a GitHub repo (owner/repo)").option("--name <name>", "Override app name").option("--org <slug-or-id>", "Deploy to a specific org (overrides active org)").option("-y, --yes", "Non-interactive: on slug conflict, update existing app").option("--update-existing", "Non-interactive: on slug conflict, overwrite existing app").option("--create-new", "Non-interactive: on slug conflict, create a new app with the suggested slug").option("--dry-run", "List files that would be uploaded; do not deploy").option("--no-sync", "Skip the post-deploy schema.sql sync into the local working directory").action(deployCommand);
|
|
@@ -2023,6 +2397,10 @@ function runCli() {
|
|
|
2023
2397
|
program.command("execute [file]").description("Run TypeScript code on the active org's substrate via mcp.clawnify.com").option("-c, --code <inline>", "Inline code instead of a file path").option("--timeout <seconds>", "Execution timeout in seconds (default 30)").action(executeCommand);
|
|
2024
2398
|
program.command("docs [slug]").description("Fetch the skill-convention README for an app (or org index if slug omitted)").option("--caller <hint>", "Caller density hint: internal | dashboard | external", "external").action(docsCommand);
|
|
2025
2399
|
program.command("mcp").description("Run a stdio MCP bridge that proxies to mcp.clawnify.com (for Claude Desktop / ChatGPT / bash-less clients)").action(mcpBridgeCommand);
|
|
2400
|
+
const skills = program.command("skills").description("Install Clawnify-curated skills into your coding agent(s)");
|
|
2401
|
+
skills.command("list").description("List available skills").action(skillsListCommand);
|
|
2402
|
+
skills.command("add [name]").description("Install a skill into every detected agent (Claude, Cursor, OpenClaw, Codex, Aider)").option("--all", "Install every available skill").option("--agent <agent>", "Force a specific target (claude | cursor | openclaw | codex | aider)").action((name, opts) => skillsAddCommand(name, opts));
|
|
2403
|
+
skills.command("remove [name]").description("Remove a previously-installed skill from detected agents").option("--all", "Remove every installed skill").option("--agent <agent>", "Restrict to a specific agent").action((name, opts) => skillsRemoveCommand(name, opts));
|
|
2026
2404
|
const sdk = program.command("sdk").description("Inspect and manage the per-org SDK surface");
|
|
2027
2405
|
sdk.command("inspect <slug>").description("Show the typed-procedure README for an app (external density)").option("--caller <hint>", "Caller density hint: internal | dashboard | external", "external").action(sdkInspectCommand);
|
|
2028
2406
|
sdk.command("login").description("Authenticate / rotate the OAuth grant (alias of `clawnify login`)").action(sdkLoginCommand);
|
|
@@ -2032,4 +2410,4 @@ function runCli() {
|
|
|
2032
2410
|
export {
|
|
2033
2411
|
runCli
|
|
2034
2412
|
};
|
|
2035
|
-
//# sourceMappingURL=cli-
|
|
2413
|
+
//# sourceMappingURL=cli-5KZ7W67B.js.map
|