clawnify 0.1.17 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -6
- package/dist/{chunk-CMM323B2.js → chunk-UUTFIFKJ.js} +31 -5
- package/dist/{chunk-CMM323B2.js.map → chunk-UUTFIFKJ.js.map} +1 -1
- package/dist/{cli-I45E7PD2.js → cli-EQWAQQTZ.js} +452 -4
- package/dist/cli-EQWAQQTZ.js.map +1 -0
- package/dist/index.js +2 -2
- package/dist/{mcp-6Q2NXUA4.js → mcp-W3X7BY7G.js} +2 -2
- package/package.json +2 -2
- package/dist/cli-I45E7PD2.js.map +0 -1
- /package/dist/{mcp-6Q2NXUA4.js.map → mcp-W3X7BY7G.js.map} +0 -0
|
@@ -7,14 +7,16 @@ import {
|
|
|
7
7
|
createArchive,
|
|
8
8
|
generatePkce,
|
|
9
9
|
getEmailFromToken,
|
|
10
|
+
getValidToken,
|
|
10
11
|
listMyOrgs,
|
|
11
12
|
loadAuth,
|
|
13
|
+
manifestKind,
|
|
12
14
|
pollUntilReady,
|
|
13
15
|
readManifest,
|
|
14
16
|
readProject,
|
|
15
17
|
saveAuth,
|
|
16
18
|
saveProject
|
|
17
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-UUTFIFKJ.js";
|
|
18
20
|
|
|
19
21
|
// src/cli.ts
|
|
20
22
|
import { Command } from "commander";
|
|
@@ -397,8 +399,106 @@ function summarizeArchive(buf, files, framework, name) {
|
|
|
397
399
|
}
|
|
398
400
|
console.log();
|
|
399
401
|
}
|
|
402
|
+
async function uploadWebsiteDeploy(archive, name, orgId) {
|
|
403
|
+
const formData = new FormData();
|
|
404
|
+
formData.append("source", new Blob([archive]), "source.tar.gz");
|
|
405
|
+
if (name) formData.append("name", name);
|
|
406
|
+
const res = await api.postForm("/v1/websites/deploy", formData, { orgId });
|
|
407
|
+
if (res.ok) {
|
|
408
|
+
const data = await res.json();
|
|
409
|
+
return { ok: true, data };
|
|
410
|
+
}
|
|
411
|
+
const err = await res.json().catch(() => ({}));
|
|
412
|
+
return { ok: false, error: err.error || res.statusText };
|
|
413
|
+
}
|
|
414
|
+
async function deployWebsite(dir, options) {
|
|
415
|
+
if (options.from) {
|
|
416
|
+
console.error("--from is app-only for now. Run `clawnify deploy` inside the website project directory.");
|
|
417
|
+
process.exit(EXIT_USAGE);
|
|
418
|
+
}
|
|
419
|
+
const resolvedDir = dir ? path2.resolve(dir) : process.cwd();
|
|
420
|
+
const manifest = readManifest(resolvedDir);
|
|
421
|
+
const baseName = options.name || manifest?.name || path2.basename(resolvedDir);
|
|
422
|
+
const linkedProject = readProject(resolvedDir);
|
|
423
|
+
const { archive, files } = createArchive(resolvedDir);
|
|
424
|
+
let orgId;
|
|
425
|
+
if (options.org) {
|
|
426
|
+
const orgs = await listMyOrgs();
|
|
427
|
+
const match = orgs.find((o) => o.id === options.org || o.slug === options.org);
|
|
428
|
+
if (!match) {
|
|
429
|
+
console.error(
|
|
430
|
+
`No org matched "${options.org}". Available: ${orgs.map((o) => o.slug).join(", ")}`
|
|
431
|
+
);
|
|
432
|
+
process.exit(EXIT_USAGE);
|
|
433
|
+
}
|
|
434
|
+
if (linkedProject?.website_id && linkedProject.org_id && linkedProject.org_id !== match.id) {
|
|
435
|
+
console.error(
|
|
436
|
+
`This project is linked to a different org (${linkedProject.org_id}).
|
|
437
|
+
--org ${options.org} resolves to ${match.id}.`
|
|
438
|
+
);
|
|
439
|
+
process.exit(1);
|
|
440
|
+
}
|
|
441
|
+
orgId = match.id;
|
|
442
|
+
} else if (linkedProject?.website_id && linkedProject.org_id) {
|
|
443
|
+
orgId = linkedProject.org_id;
|
|
444
|
+
}
|
|
445
|
+
if (options.dryRun) {
|
|
446
|
+
const sizeKB = (archive.length / 1024).toFixed(1);
|
|
447
|
+
console.log(`
|
|
448
|
+
Dry run \u2014 would deploy website '${baseName}' (astro)`);
|
|
449
|
+
console.log(` Archive: ${files.length} files, ${sizeKB}KB gzipped
|
|
450
|
+
`);
|
|
451
|
+
const preview = files.slice(0, 25);
|
|
452
|
+
for (const f of preview) console.log(` ${f}`);
|
|
453
|
+
if (files.length > preview.length) {
|
|
454
|
+
console.log(` ... and ${files.length - preview.length} more`);
|
|
455
|
+
}
|
|
456
|
+
console.log();
|
|
457
|
+
return;
|
|
458
|
+
}
|
|
459
|
+
console.log(linkedProject?.website_id ? `Updating ${baseName}...` : `Deploying ${baseName}...`);
|
|
460
|
+
const result = await uploadWebsiteDeploy(archive, baseName, orgId);
|
|
461
|
+
if (!result.ok) {
|
|
462
|
+
console.error(`Deploy failed: ${result.error}`);
|
|
463
|
+
process.exit(1);
|
|
464
|
+
}
|
|
465
|
+
saveProject(resolvedDir, {
|
|
466
|
+
kind: "website",
|
|
467
|
+
org_id: orgId,
|
|
468
|
+
website_id: result.data.website_id,
|
|
469
|
+
slug: result.data.slug
|
|
470
|
+
});
|
|
471
|
+
const polled = await pollUntilReady(result.data.website_id, {
|
|
472
|
+
kind: "website",
|
|
473
|
+
orgId
|
|
474
|
+
});
|
|
475
|
+
if (polled.status === "error") {
|
|
476
|
+
console.error(`
|
|
477
|
+
Deploy failed: ${polled.error || "Unknown error"}
|
|
478
|
+
`);
|
|
479
|
+
process.exit(1);
|
|
480
|
+
}
|
|
481
|
+
console.log(`
|
|
482
|
+
\u2713 Deployed! ${result.data.url}
|
|
483
|
+
`);
|
|
484
|
+
}
|
|
400
485
|
async function deployCommand(dir, options = {}) {
|
|
401
486
|
assertNodeVersion();
|
|
487
|
+
if (!options.from) {
|
|
488
|
+
const resolvedDir = dir ? path2.resolve(dir) : process.cwd();
|
|
489
|
+
const manifest = readManifest(resolvedDir);
|
|
490
|
+
if (manifest) {
|
|
491
|
+
try {
|
|
492
|
+
const kind = manifestKind(manifest);
|
|
493
|
+
if (kind === "website") {
|
|
494
|
+
return deployWebsite(dir, options);
|
|
495
|
+
}
|
|
496
|
+
} catch (err) {
|
|
497
|
+
console.error(`${err.message}`);
|
|
498
|
+
process.exit(EXIT_USAGE);
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
}
|
|
402
502
|
let appId;
|
|
403
503
|
let slug;
|
|
404
504
|
let appToken;
|
|
@@ -679,7 +779,28 @@ function ask2(question) {
|
|
|
679
779
|
function slugify(name) {
|
|
680
780
|
return name.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "").slice(0, 30);
|
|
681
781
|
}
|
|
782
|
+
async function askProjectType(opts) {
|
|
783
|
+
if (opts?.type === "app" || opts?.type === "website") return opts.type;
|
|
784
|
+
if (opts?.type) {
|
|
785
|
+
console.error(`Unknown --type '${opts.type}' (expected 'app' or 'website').`);
|
|
786
|
+
process.exit(1);
|
|
787
|
+
}
|
|
788
|
+
console.log();
|
|
789
|
+
console.log(" What are you creating?");
|
|
790
|
+
console.log(" 1) app \u2014 full-stack project (React + Hono + D1)");
|
|
791
|
+
console.log(" 2) website \u2014 public site (Astro)");
|
|
792
|
+
console.log();
|
|
793
|
+
const choice = await ask2("Type [1]: ") || "1";
|
|
794
|
+
return choice === "2" ? "website" : "app";
|
|
795
|
+
}
|
|
682
796
|
async function initCommand(dir, opts) {
|
|
797
|
+
const type = await askProjectType(opts);
|
|
798
|
+
if (type === "website") {
|
|
799
|
+
return initWebsite(dir, opts);
|
|
800
|
+
}
|
|
801
|
+
return initApp(dir, opts);
|
|
802
|
+
}
|
|
803
|
+
async function initApp(dir, opts) {
|
|
683
804
|
const name = opts?.name || await ask2("App name: ") || "my-app";
|
|
684
805
|
const slug = slugify(name);
|
|
685
806
|
const targetDir = dir ? path3.resolve(dir) : path3.resolve(slug);
|
|
@@ -962,6 +1083,133 @@ createRoot(document.getElementById("app")!).render(
|
|
|
962
1083
|
console.log(" pnpm deploy # deploy to production");
|
|
963
1084
|
console.log();
|
|
964
1085
|
}
|
|
1086
|
+
async function initWebsite(dir, opts) {
|
|
1087
|
+
const name = opts?.name || await ask2("Site name: ") || "my-site";
|
|
1088
|
+
const slug = slugify(name);
|
|
1089
|
+
const targetDir = dir ? path3.resolve(dir) : path3.resolve(slug);
|
|
1090
|
+
if (fs2.existsSync(targetDir) && fs2.readdirSync(targetDir).length > 0) {
|
|
1091
|
+
console.error(`Directory ${targetDir} is not empty.`);
|
|
1092
|
+
process.exit(1);
|
|
1093
|
+
}
|
|
1094
|
+
fs2.mkdirSync(targetDir, { recursive: true });
|
|
1095
|
+
write(targetDir, "clawnify.json", JSON.stringify({
|
|
1096
|
+
$schema: "https://app.clawnify.com/schema/v1/clawnify.json",
|
|
1097
|
+
version: 1,
|
|
1098
|
+
name,
|
|
1099
|
+
description: "",
|
|
1100
|
+
website: { framework: "astro" }
|
|
1101
|
+
}, null, 2));
|
|
1102
|
+
write(targetDir, "package.json", JSON.stringify({
|
|
1103
|
+
name: slug,
|
|
1104
|
+
private: true,
|
|
1105
|
+
type: "module",
|
|
1106
|
+
scripts: {
|
|
1107
|
+
dev: "astro dev",
|
|
1108
|
+
build: "astro build",
|
|
1109
|
+
preview: "astro preview",
|
|
1110
|
+
deploy: "clawnify deploy"
|
|
1111
|
+
},
|
|
1112
|
+
dependencies: {
|
|
1113
|
+
"@astrojs/cloudflare": "^12.0.0",
|
|
1114
|
+
"@tailwindcss/vite": "^4.0.0",
|
|
1115
|
+
astro: "^5.0.0",
|
|
1116
|
+
tailwindcss: "^4.0.0"
|
|
1117
|
+
},
|
|
1118
|
+
devDependencies: {
|
|
1119
|
+
clawnify: "^0.1.15",
|
|
1120
|
+
"wrangler": "^4.0.0"
|
|
1121
|
+
},
|
|
1122
|
+
engines: { node: ">=22" }
|
|
1123
|
+
}, null, 2));
|
|
1124
|
+
write(targetDir, "tsconfig.json", JSON.stringify({
|
|
1125
|
+
extends: "astro/tsconfigs/strict",
|
|
1126
|
+
include: ["src/**/*", ".astro/types.d.ts"],
|
|
1127
|
+
exclude: ["dist", "node_modules"]
|
|
1128
|
+
}, null, 2));
|
|
1129
|
+
write(targetDir, "astro.config.mjs", `import { defineConfig } from "astro/config";
|
|
1130
|
+
import cloudflare from "@astrojs/cloudflare";
|
|
1131
|
+
import tailwindcss from "@tailwindcss/vite";
|
|
1132
|
+
|
|
1133
|
+
export default defineConfig({
|
|
1134
|
+
output: "server",
|
|
1135
|
+
adapter: cloudflare(),
|
|
1136
|
+
vite: {
|
|
1137
|
+
plugins: [tailwindcss()],
|
|
1138
|
+
},
|
|
1139
|
+
});
|
|
1140
|
+
`);
|
|
1141
|
+
write(targetDir, ".gitignore", `node_modules
|
|
1142
|
+
dist
|
|
1143
|
+
.astro
|
|
1144
|
+
.wrangler
|
|
1145
|
+
.clawnify
|
|
1146
|
+
.env*
|
|
1147
|
+
!.env.example
|
|
1148
|
+
.dev.vars
|
|
1149
|
+
`);
|
|
1150
|
+
write(targetDir, "src/styles/global.css", `@import "tailwindcss";
|
|
1151
|
+
|
|
1152
|
+
:root {
|
|
1153
|
+
--color-primary: oklch(0.55 0.18 250);
|
|
1154
|
+
--color-ink: oklch(0.2 0.02 250);
|
|
1155
|
+
--color-canvas: oklch(0.99 0 0);
|
|
1156
|
+
}
|
|
1157
|
+
|
|
1158
|
+
body {
|
|
1159
|
+
background-color: var(--color-canvas);
|
|
1160
|
+
color: var(--color-ink);
|
|
1161
|
+
font-family: ui-sans-serif, system-ui, sans-serif;
|
|
1162
|
+
}
|
|
1163
|
+
`);
|
|
1164
|
+
write(targetDir, "src/layouts/BaseLayout.astro", `---
|
|
1165
|
+
interface Props {
|
|
1166
|
+
title?: string;
|
|
1167
|
+
description?: string;
|
|
1168
|
+
}
|
|
1169
|
+
|
|
1170
|
+
const { title = "${name}", description = "" } = Astro.props;
|
|
1171
|
+
---
|
|
1172
|
+
<!doctype html>
|
|
1173
|
+
<html lang="en">
|
|
1174
|
+
<head>
|
|
1175
|
+
<meta charset="utf-8" />
|
|
1176
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
1177
|
+
<title>{title}</title>
|
|
1178
|
+
{description && <meta name="description" content={description} />}
|
|
1179
|
+
<link rel="stylesheet" href="/src/styles/global.css" />
|
|
1180
|
+
</head>
|
|
1181
|
+
<body>
|
|
1182
|
+
<slot />
|
|
1183
|
+
</body>
|
|
1184
|
+
</html>
|
|
1185
|
+
`);
|
|
1186
|
+
write(targetDir, "src/pages/index.astro", `---
|
|
1187
|
+
import BaseLayout from "../layouts/BaseLayout.astro";
|
|
1188
|
+
---
|
|
1189
|
+
<BaseLayout title="${name}">
|
|
1190
|
+
<main class="mx-auto max-w-3xl px-6 py-24">
|
|
1191
|
+
<h1 class="text-5xl font-semibold tracking-tight">${name}</h1>
|
|
1192
|
+
<p class="mt-4 text-lg opacity-70">
|
|
1193
|
+
Edit <code>src/pages/index.astro</code> to get started.
|
|
1194
|
+
</p>
|
|
1195
|
+
<p class="mt-8">
|
|
1196
|
+
<a class="underline" href="https://docs.astro.build" target="_blank" rel="noreferrer">
|
|
1197
|
+
Astro docs \u2192
|
|
1198
|
+
</a>
|
|
1199
|
+
</p>
|
|
1200
|
+
</main>
|
|
1201
|
+
</BaseLayout>
|
|
1202
|
+
`);
|
|
1203
|
+
console.log();
|
|
1204
|
+
console.log(` Created ${name} in ${path3.relative(process.cwd(), targetDir)}/`);
|
|
1205
|
+
console.log();
|
|
1206
|
+
console.log(" Get started:");
|
|
1207
|
+
console.log(` cd ${path3.relative(process.cwd(), targetDir)}`);
|
|
1208
|
+
console.log(" pnpm install");
|
|
1209
|
+
console.log(" pnpm dev # local dev at http://localhost:4321");
|
|
1210
|
+
console.log(" pnpm deploy # deploy as your org's website");
|
|
1211
|
+
console.log();
|
|
1212
|
+
}
|
|
965
1213
|
function writeBlankTemplate(dir, name) {
|
|
966
1214
|
write(dir, "src/server/schema.sql", `CREATE TABLE IF NOT EXISTS items (
|
|
967
1215
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
@@ -1293,6 +1541,12 @@ async function devCommand(dir, options) {
|
|
|
1293
1541
|
console.error("No clawnify.json found. Run `clawnify init` first.");
|
|
1294
1542
|
process.exit(1);
|
|
1295
1543
|
}
|
|
1544
|
+
if (!manifest.app) {
|
|
1545
|
+
console.error(
|
|
1546
|
+
"`clawnify dev` is for app projects only. For a website, run `pnpm dev` (astro dev) directly."
|
|
1547
|
+
);
|
|
1548
|
+
process.exit(1);
|
|
1549
|
+
}
|
|
1296
1550
|
const slug = slugify2(manifest.name);
|
|
1297
1551
|
const database = manifest.app.database !== false;
|
|
1298
1552
|
const storage = manifest.app.storage === true;
|
|
@@ -1560,14 +1814,201 @@ async function orgUseCommand(slugOrId) {
|
|
|
1560
1814
|
console.log(` Active org set to ${match.name} (${match.slug})`);
|
|
1561
1815
|
}
|
|
1562
1816
|
|
|
1817
|
+
// src/commands/execute.ts
|
|
1818
|
+
import fs4 from "fs";
|
|
1819
|
+
|
|
1820
|
+
// src/lib/mcp-client.ts
|
|
1821
|
+
var MCP_URL = "https://mcp.clawnify.com/mcp";
|
|
1822
|
+
async function callTool(name, args) {
|
|
1823
|
+
const token = await getValidToken();
|
|
1824
|
+
if (!token) {
|
|
1825
|
+
process.stderr.write("Not logged in. Run `clawnify login` first.\n");
|
|
1826
|
+
process.exit(1);
|
|
1827
|
+
}
|
|
1828
|
+
const auth = loadAuth();
|
|
1829
|
+
const headers = {
|
|
1830
|
+
"content-type": "application/json",
|
|
1831
|
+
authorization: "Bearer " + token
|
|
1832
|
+
};
|
|
1833
|
+
if (auth?.org_id) {
|
|
1834
|
+
headers["X-Clawnify-Org-Id"] = auth.org_id;
|
|
1835
|
+
}
|
|
1836
|
+
const res = await fetch(MCP_URL, {
|
|
1837
|
+
method: "POST",
|
|
1838
|
+
headers,
|
|
1839
|
+
body: JSON.stringify({
|
|
1840
|
+
jsonrpc: "2.0",
|
|
1841
|
+
id: Date.now(),
|
|
1842
|
+
method: "tools/call",
|
|
1843
|
+
params: { name, arguments: args }
|
|
1844
|
+
})
|
|
1845
|
+
});
|
|
1846
|
+
if (res.status === 401) {
|
|
1847
|
+
process.stderr.write("Authentication failed. Run `clawnify login` again.\n");
|
|
1848
|
+
process.exit(1);
|
|
1849
|
+
}
|
|
1850
|
+
const body = await res.json();
|
|
1851
|
+
if (body.error) return { error: body.error };
|
|
1852
|
+
if (!body.result) {
|
|
1853
|
+
return { error: { code: -32603, message: "Empty response from MCP gateway" } };
|
|
1854
|
+
}
|
|
1855
|
+
return { result: body.result };
|
|
1856
|
+
}
|
|
1857
|
+
function isError(resp) {
|
|
1858
|
+
return "error" in resp;
|
|
1859
|
+
}
|
|
1860
|
+
|
|
1861
|
+
// src/commands/execute.ts
|
|
1862
|
+
async function executeCommand(file, options) {
|
|
1863
|
+
let code;
|
|
1864
|
+
if (options.code) {
|
|
1865
|
+
code = options.code;
|
|
1866
|
+
} else if (file) {
|
|
1867
|
+
try {
|
|
1868
|
+
code = fs4.readFileSync(file, "utf-8");
|
|
1869
|
+
} catch (err) {
|
|
1870
|
+
process.stderr.write(`Failed to read ${file}: ${String(err)}
|
|
1871
|
+
`);
|
|
1872
|
+
process.exit(1);
|
|
1873
|
+
}
|
|
1874
|
+
} else {
|
|
1875
|
+
process.stderr.write(
|
|
1876
|
+
`Provide a file path or --code 'inline code'.
|
|
1877
|
+
Usage: clawnify execute path/to/file.ts
|
|
1878
|
+
clawnify execute -c "console.log(1 + 1)"
|
|
1879
|
+
`
|
|
1880
|
+
);
|
|
1881
|
+
process.exit(1);
|
|
1882
|
+
}
|
|
1883
|
+
const timeout_ms = options.timeout ? Math.max(1e3, parseInt(options.timeout, 10) * 1e3) : 3e4;
|
|
1884
|
+
const resp = await callTool("clawnify.execute", { code, timeout_ms });
|
|
1885
|
+
if (isError(resp)) {
|
|
1886
|
+
process.stderr.write(`Error ${resp.error.code}: ${resp.error.message}
|
|
1887
|
+
`);
|
|
1888
|
+
process.exit(1);
|
|
1889
|
+
}
|
|
1890
|
+
const sc = resp.result.structuredContent;
|
|
1891
|
+
if (sc) {
|
|
1892
|
+
if (sc.stdout) process.stdout.write(sc.stdout);
|
|
1893
|
+
if (sc.stderr) process.stderr.write(sc.stderr);
|
|
1894
|
+
if (sc.timed_out) {
|
|
1895
|
+
process.stderr.write(`
|
|
1896
|
+
[clawnify] timed out after ${timeout_ms}ms on ${sc.substrate_id}
|
|
1897
|
+
`);
|
|
1898
|
+
}
|
|
1899
|
+
process.exit(sc.exit_code ?? 0);
|
|
1900
|
+
}
|
|
1901
|
+
for (const c of resp.result.content) {
|
|
1902
|
+
if (c.type === "text") process.stdout.write(c.text + "\n");
|
|
1903
|
+
}
|
|
1904
|
+
process.exit(resp.result.isError ? 1 : 0);
|
|
1905
|
+
}
|
|
1906
|
+
|
|
1907
|
+
// src/commands/docs.ts
|
|
1908
|
+
var DOCS_URL = "https://clawnify-mcp-docs.workers.dev";
|
|
1909
|
+
async function docsCommand(slug, options) {
|
|
1910
|
+
const token = await getValidToken();
|
|
1911
|
+
if (!token) {
|
|
1912
|
+
process.stderr.write("Not logged in. Run `clawnify login` first.\n");
|
|
1913
|
+
process.exit(1);
|
|
1914
|
+
}
|
|
1915
|
+
const auth = loadAuth();
|
|
1916
|
+
if (!auth?.org_id) {
|
|
1917
|
+
process.stderr.write(
|
|
1918
|
+
"No active org. Pick one with `clawnify org use <slug-or-id>` first.\n"
|
|
1919
|
+
);
|
|
1920
|
+
process.exit(1);
|
|
1921
|
+
}
|
|
1922
|
+
const caller = options.caller ?? "external";
|
|
1923
|
+
const path7 = slug ? `/docs/${auth.org_id}/${slug}.md?caller=${caller}` : `/docs/${auth.org_id}/index.md`;
|
|
1924
|
+
const res = await fetch(DOCS_URL + path7, {
|
|
1925
|
+
headers: {
|
|
1926
|
+
authorization: "Bearer " + token
|
|
1927
|
+
}
|
|
1928
|
+
});
|
|
1929
|
+
if (!res.ok) {
|
|
1930
|
+
process.stderr.write(`Failed to fetch docs: ${res.status} ${res.statusText}
|
|
1931
|
+
`);
|
|
1932
|
+
process.exit(1);
|
|
1933
|
+
}
|
|
1934
|
+
const md = await res.text();
|
|
1935
|
+
process.stdout.write(md);
|
|
1936
|
+
if (!md.endsWith("\n")) process.stdout.write("\n");
|
|
1937
|
+
}
|
|
1938
|
+
|
|
1939
|
+
// src/commands/mcp-bridge.ts
|
|
1940
|
+
import readline5 from "readline";
|
|
1941
|
+
var MCP_URL2 = "https://mcp.clawnify.com/mcp";
|
|
1942
|
+
async function mcpBridgeCommand() {
|
|
1943
|
+
const token = await getValidToken();
|
|
1944
|
+
if (!token) {
|
|
1945
|
+
process.stderr.write("Not logged in. Run `clawnify login` first.\n");
|
|
1946
|
+
process.exit(1);
|
|
1947
|
+
}
|
|
1948
|
+
const auth = loadAuth();
|
|
1949
|
+
const baseHeaders = {
|
|
1950
|
+
"content-type": "application/json",
|
|
1951
|
+
authorization: "Bearer " + token
|
|
1952
|
+
};
|
|
1953
|
+
if (auth?.org_id) {
|
|
1954
|
+
baseHeaders["X-Clawnify-Org-Id"] = auth.org_id;
|
|
1955
|
+
}
|
|
1956
|
+
const rl = readline5.createInterface({ input: process.stdin, terminal: false });
|
|
1957
|
+
rl.on("line", async (line) => {
|
|
1958
|
+
const trimmed = line.trim();
|
|
1959
|
+
if (!trimmed) return;
|
|
1960
|
+
let parsedId = null;
|
|
1961
|
+
try {
|
|
1962
|
+
parsedId = JSON.parse(trimmed).id ?? null;
|
|
1963
|
+
} catch {
|
|
1964
|
+
}
|
|
1965
|
+
try {
|
|
1966
|
+
const res = await fetch(MCP_URL2, {
|
|
1967
|
+
method: "POST",
|
|
1968
|
+
headers: baseHeaders,
|
|
1969
|
+
body: trimmed
|
|
1970
|
+
});
|
|
1971
|
+
const text = await res.text();
|
|
1972
|
+
if (text.length > 0) {
|
|
1973
|
+
process.stdout.write(text);
|
|
1974
|
+
if (!text.endsWith("\n")) process.stdout.write("\n");
|
|
1975
|
+
}
|
|
1976
|
+
} catch (err) {
|
|
1977
|
+
const errResp = {
|
|
1978
|
+
jsonrpc: "2.0",
|
|
1979
|
+
id: parsedId,
|
|
1980
|
+
error: { code: -32603, message: "bridge transport error: " + String(err) }
|
|
1981
|
+
};
|
|
1982
|
+
process.stdout.write(JSON.stringify(errResp) + "\n");
|
|
1983
|
+
}
|
|
1984
|
+
});
|
|
1985
|
+
rl.on("close", () => {
|
|
1986
|
+
process.exit(0);
|
|
1987
|
+
});
|
|
1988
|
+
}
|
|
1989
|
+
|
|
1990
|
+
// src/commands/sdk.ts
|
|
1991
|
+
async function sdkInspectCommand(slug, options) {
|
|
1992
|
+
await docsCommand(slug, { caller: options.caller ?? "external" });
|
|
1993
|
+
}
|
|
1994
|
+
async function sdkLoginCommand() {
|
|
1995
|
+
await loginCommand();
|
|
1996
|
+
}
|
|
1997
|
+
async function sdkInstallCommand() {
|
|
1998
|
+
process.stderr.write(
|
|
1999
|
+
"`clawnify sdk install` is not yet implemented.\nIt depends on the `@clawnify/sdk` npm package being published, which depends on the build-pipeline manifest writer (template-strategy.md).\nTrack in the Phase 5 follow-up.\n"
|
|
2000
|
+
);
|
|
2001
|
+
process.exit(1);
|
|
2002
|
+
}
|
|
2003
|
+
|
|
1563
2004
|
// src/cli.ts
|
|
1564
2005
|
function runCli() {
|
|
1565
2006
|
const program = new Command();
|
|
1566
2007
|
program.name("clawnify").description("Deploy apps to Clawnify").version("0.1.0");
|
|
1567
|
-
program.command("init [dir]").description("Scaffold a new Clawnify app").option("--name <name>", "
|
|
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);
|
|
1568
2009
|
program.command("dev [dir]").description("Start local dev server").option("--port <port>", "API server port (default: 8787)").action(devCommand);
|
|
1569
2010
|
program.command("login").description("Authenticate with Clawnify").action(loginCommand);
|
|
1570
|
-
program.command("deploy [dir]").description("Deploy an app 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);
|
|
2011
|
+
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);
|
|
1571
2012
|
program.command("link <app-id-or-slug>").description("Link the current directory to an existing Clawnify app (accepts id or slug)").option("--dir <dir>", "Directory to link (default: cwd)").option("--org <slug-or-id>", "Restrict the app lookup to a specific org").action(linkCommand);
|
|
1572
2013
|
const pull = program.command("pull").description("Pull artifacts from a deployed app into the current directory");
|
|
1573
2014
|
pull.command("schema").description("Fetch the deployed app's current schema.sql snapshot into the local repo").option("--from <app-id-or-slug>", "App to fetch from (required)").option("--out <path>", "Where to write (default: ./schema.sql)").option("--force", "Overwrite a locally-modified or uncommitted schema.sql").option("--org <slug-or-id>", "Restrict the app lookup to a specific org").action(pullSchemaCommand);
|
|
@@ -1579,9 +2020,16 @@ function runCli() {
|
|
|
1579
2020
|
program.command("rm <app-id>").description("Delete an app").action(rmCommand);
|
|
1580
2021
|
program.command("open <slug>").description("Open an app in the browser").action(openCommand);
|
|
1581
2022
|
program.command("whoami").description("Show current user info").action(whoamiCommand);
|
|
2023
|
+
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
|
+
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
|
+
program.command("mcp").description("Run a stdio MCP bridge that proxies to mcp.clawnify.com (for Claude Desktop / ChatGPT / bash-less clients)").action(mcpBridgeCommand);
|
|
2026
|
+
const sdk = program.command("sdk").description("Inspect and manage the per-org SDK surface");
|
|
2027
|
+
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
|
+
sdk.command("login").description("Authenticate / rotate the OAuth grant (alias of `clawnify login`)").action(sdkLoginCommand);
|
|
2029
|
+
sdk.command("install").description("(Deferred) Install @clawnify/sdk locally \u2014 pending Phase 5b").action(sdkInstallCommand);
|
|
1582
2030
|
program.parse();
|
|
1583
2031
|
}
|
|
1584
2032
|
export {
|
|
1585
2033
|
runCli
|
|
1586
2034
|
};
|
|
1587
|
-
//# sourceMappingURL=cli-
|
|
2035
|
+
//# sourceMappingURL=cli-EQWAQQTZ.js.map
|