clawnify 0.13.0 → 0.15.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/dist/{chunk-K5JOOOE5.js → chunk-EYT3GVQW.js} +43 -31
- package/dist/chunk-EYT3GVQW.js.map +1 -0
- package/dist/{cli-JMDZKGYU.js → cli-BOJXG2ZQ.js} +180 -49
- package/dist/cli-BOJXG2ZQ.js.map +1 -0
- package/dist/index.js +2 -2
- package/dist/{mcp-JN76VVZZ.js → mcp-VXJ4TMMF.js} +2 -2
- package/package.json +1 -1
- package/dist/chunk-K5JOOOE5.js.map +0 -1
- package/dist/cli-JMDZKGYU.js.map +0 -1
- /package/dist/{mcp-JN76VVZZ.js.map → mcp-VXJ4TMMF.js.map} +0 -0
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
resolveOrgContext,
|
|
21
21
|
saveAuth,
|
|
22
22
|
saveProject
|
|
23
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-EYT3GVQW.js";
|
|
24
24
|
|
|
25
25
|
// src/cli.ts
|
|
26
26
|
import { Command, Option } from "commander";
|
|
@@ -316,12 +316,29 @@ function ask(question) {
|
|
|
316
316
|
});
|
|
317
317
|
});
|
|
318
318
|
}
|
|
319
|
+
async function postFormWithRetry(path10, formData, orgId, attempts = 3) {
|
|
320
|
+
let lastErr;
|
|
321
|
+
for (let i = 0; i < attempts; i++) {
|
|
322
|
+
try {
|
|
323
|
+
return await api.postForm(path10, formData, { orgId });
|
|
324
|
+
} catch (err) {
|
|
325
|
+
lastErr = err;
|
|
326
|
+
if (i === attempts - 1) break;
|
|
327
|
+
const waitMs = 1e3 * 2 ** i;
|
|
328
|
+
console.warn(
|
|
329
|
+
` upload failed (${String(err).slice(0, 120)}) \u2014 retrying in ${waitMs / 1e3}s [${i + 2}/${attempts}]`
|
|
330
|
+
);
|
|
331
|
+
await new Promise((r) => setTimeout(r, waitMs));
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
throw lastErr;
|
|
335
|
+
}
|
|
319
336
|
async function uploadDeploy(archive, name, framework, orgId) {
|
|
320
337
|
const formData = new FormData();
|
|
321
338
|
formData.append("source", new Blob([archive]), "source.tar.gz");
|
|
322
339
|
formData.append("name", name);
|
|
323
340
|
formData.append("framework", framework);
|
|
324
|
-
const res = await
|
|
341
|
+
const res = await postFormWithRetry("/v1/apps/deploy", formData, orgId);
|
|
325
342
|
if (res.ok) {
|
|
326
343
|
const data = await res.json();
|
|
327
344
|
return { ok: true, data };
|
|
@@ -336,7 +353,7 @@ async function uploadDeploy(archive, name, framework, orgId) {
|
|
|
336
353
|
async function uploadRedeploy(appId, archive, orgId) {
|
|
337
354
|
const formData = new FormData();
|
|
338
355
|
formData.append("source", new Blob([archive]), "source.tar.gz");
|
|
339
|
-
const res = await
|
|
356
|
+
const res = await postFormWithRetry(`/v1/apps/${appId}/redeploy`, formData, orgId);
|
|
340
357
|
if (res.ok) {
|
|
341
358
|
const data = await res.json();
|
|
342
359
|
return { ok: true, data };
|
|
@@ -759,6 +776,7 @@ async function deployCommand(dir, options = {}) {
|
|
|
759
776
|
const framework = manifest?.app?.framework || "vite-preact";
|
|
760
777
|
const linkedProject = readProject(resolvedDir);
|
|
761
778
|
await regenerateDrizzleMigrations(resolvedDir);
|
|
779
|
+
assertDatabaseDdlPresent(resolvedDir, manifest);
|
|
762
780
|
const { archive, files } = createArchive(resolvedDir);
|
|
763
781
|
const orgId = await resolveOrgId(options, linkedProject, resolvedDir);
|
|
764
782
|
if (options.dryRun) {
|
|
@@ -892,9 +910,34 @@ async function regenerateDrizzleMigrations(resolvedDir) {
|
|
|
892
910
|
}
|
|
893
911
|
resolve();
|
|
894
912
|
});
|
|
895
|
-
proc.on("error", () =>
|
|
913
|
+
proc.on("error", (err) => {
|
|
914
|
+
console.warn(` warning: could not run drizzle-kit generate (${String(err).slice(0, 160)}).`);
|
|
915
|
+
resolve();
|
|
916
|
+
});
|
|
896
917
|
});
|
|
897
918
|
}
|
|
919
|
+
function assertDatabaseDdlPresent(resolvedDir, manifest) {
|
|
920
|
+
if (!manifest?.app?.database) return;
|
|
921
|
+
const hasSchemaSql = fs2.existsSync(path2.join(resolvedDir, "schema.sql")) || fs2.existsSync(path2.join(resolvedDir, "src/server/schema.sql"));
|
|
922
|
+
if (hasSchemaSql) return;
|
|
923
|
+
const drizzleDir = path2.join(resolvedDir, ".clawnify", "drizzle");
|
|
924
|
+
const hasDrizzleSql = fs2.existsSync(drizzleDir) && fs2.readdirSync(drizzleDir).some((f) => f.endsWith(".sql"));
|
|
925
|
+
if (hasDrizzleSql) return;
|
|
926
|
+
console.error(
|
|
927
|
+
`Deploy aborted: this app sets "database": true in clawnify.json, but no schema
|
|
928
|
+
would be applied \u2014 so every query would fail at runtime with "no such table".
|
|
929
|
+
|
|
930
|
+
Fix:
|
|
931
|
+
\u2022 pnpm db:generate (emits .clawnify/drizzle/*.sql from src/server/schema.ts)
|
|
932
|
+
If that just failed, see the warning above \u2014 drizzle-kit ships as a
|
|
933
|
+
devDependency, so run your package manager's install first.
|
|
934
|
+
\u2022 set "database": false (if this app genuinely has no database)
|
|
935
|
+
|
|
936
|
+
schema.ts is the source of truth; a hand-written schema.sql at the app root
|
|
937
|
+
is also accepted, but only for apps not using Drizzle.`
|
|
938
|
+
);
|
|
939
|
+
process.exit(1);
|
|
940
|
+
}
|
|
898
941
|
|
|
899
942
|
// src/commands/ls.ts
|
|
900
943
|
async function lsCommand() {
|
|
@@ -937,6 +980,12 @@ async function logsCommand(appId) {
|
|
|
937
980
|
if (data.status_message) {
|
|
938
981
|
console.log(`Message: ${data.status_message}`);
|
|
939
982
|
}
|
|
983
|
+
if (data.error) {
|
|
984
|
+
console.log(`
|
|
985
|
+
--- Last Error ---
|
|
986
|
+
`);
|
|
987
|
+
console.log(data.error);
|
|
988
|
+
}
|
|
940
989
|
if (data.logs) {
|
|
941
990
|
console.log("\n--- Build Logs ---\n");
|
|
942
991
|
console.log(data.logs);
|
|
@@ -1258,7 +1307,8 @@ async function apiCommand(path10, opts) {
|
|
|
1258
1307
|
}
|
|
1259
1308
|
}
|
|
1260
1309
|
const p = path10.startsWith("/") ? path10 : `/${path10}`;
|
|
1261
|
-
const
|
|
1310
|
+
const orgId = await resolveOrgContext({ orgFlag: opts.org });
|
|
1311
|
+
const res = await api.call(method, p, { body, orgId });
|
|
1262
1312
|
const text = await res.text();
|
|
1263
1313
|
let out = text;
|
|
1264
1314
|
try {
|
|
@@ -1338,7 +1388,7 @@ async function whoamiCommand() {
|
|
|
1338
1388
|
}
|
|
1339
1389
|
const email = getEmailFromToken(envToken ?? auth.access_token) ?? "unknown";
|
|
1340
1390
|
console.log(`Email: ${email}`);
|
|
1341
|
-
const orgId =
|
|
1391
|
+
const orgId = await resolveOrgContext();
|
|
1342
1392
|
if (orgId) {
|
|
1343
1393
|
console.log(`Org: ${orgId}`);
|
|
1344
1394
|
}
|
|
@@ -1406,7 +1456,7 @@ function agentByName(name) {
|
|
|
1406
1456
|
var ALL_AGENTS = DETECTORS.map((d) => d.agent);
|
|
1407
1457
|
|
|
1408
1458
|
// src/lib/skills/content.gen.ts
|
|
1409
|
-
var CLI_VERSION = "0.
|
|
1459
|
+
var CLI_VERSION = "0.15.0";
|
|
1410
1460
|
var BUNDLED_SKILLS = [
|
|
1411
1461
|
{
|
|
1412
1462
|
name: "build-a-clawnify-app",
|
|
@@ -1424,7 +1474,12 @@ var BUNDLED_SKILLS = [
|
|
|
1424
1474
|
content: "# Fix a misbehaving Clawnify agent\n\nYou are the planner and thinker. The Clawnify agent \u2014 the customer's\nWhatsApp / Telegram / Slack / email \"AI employee\" \u2014 is the executor. When it\nmisbehaves your job is to **read what it actually did, find the real cause, and\nchange the durable inputs.** Not to patch instructions blind, and not to burn\nthe agent's own (expensive) model tokens on trial-and-error.\n\n**Know what you're looking at.** An org has one or more **agents** (the\nemployees). Each may have **sub-agents** \u2014 narrower helpers it delegates to.\n`clawnify agents list` shows both, sub-agents indented under their agent. That\nis the whole hierarchy; there is no other tier to go looking for.\n\nThe person you're helping is often **not** an AI specialist. So: diagnose\nfirst, then **explain the cause in plain language and correct the\nmisconception** before you change anything.\n\n## The one rule: don't debug blind\n\n\"Veers off / ignores instructions\" has **three different causes with three\ndifferent fixes.** You can only tell which one by reading the agent's actual\nsession. Patching instructions without looking is exactly why it \"isn't\nheading in the right direction\" \u2014 and every blind test run costs model tokens.\n\n| Cause | What you'll see in the session | Fix |\n|---|---|---|\n| **1. Session bloat** | Was fine early, degrades over a long-running chat; forgets/repeats; high `contextTokens`; compaction/truncation in the transcript; the rule is simply *absent* from recent context | Scope a **fresh session per task**; reset/retire the bloated one |\n| **2. Instruction patchwork** | The rule *was* in context but a **contradicting or older** rule won, or it's buried in a wall of text | **Restructure** `AGENTS.md` (don't add another patch) |\n| **3. Wrong structure** | A repeatable multi-step task the agent improvises differently each time | Move it to a **flow** (deterministic rails) |\n\nBloat and patchwork also explain most **surprise API costs**: a bloated\nsession re-sends a huge context on *every* turn, and the patch-and-rerun loop\nitself burns tokens. Measure it \u2014 don't guess (Step 1).\n\n## Step 1 \u2014 Observe (read what actually happened)\n\n```bash\nclawnify agents list # the org's agents + their sub-agents \u2014 START HERE\nclawnify sessions # every agent's sessions, newest first\nclawnify sessions --agent ash --json # ash only, with token counters (contextTokens = bloat signal)\nclawnify sessions history <key> --json # the transcript of one run \u2014 where it actually veered\nclawnify agents skills ash # what ash can ACTUALLY run (workspace + shared skills)\n```\n\nLook for, in order:\n- **Which failure mode** (table above): was the instruction *present and\n ignored* (\u2192 patchwork/structure) or *compacted away / absent* (\u2192 bloat)?\n- **`contextTokens`** on the session \u2014 large and growing = bloat.\n- **A missing skill** \u2014 if the instruction says \"use skill X\" but `agents\n skills` doesn't list it, the agent literally can't. The fix is to grant it\n (`clawnify agents grant-skill X --to ash`, or `--all` for every agent) if it's\n already authored in main, else author it first (`agents pull main` \u2192 add\n `skills/X/SKILL.md` \u2192 `agents push`) \u2014 not to reword the instruction. (Note:\n what's in the agent's *workspace* is only part of it \u2014 `agents skills` shows\n the effective set incl. shared managed-root skills.)\n- **Where the tokens go** \u2014 one giant session, or repeated retries after a\n veer? That's your cost answer, from data, not a hypothesis.\n\n> If `clawnify sessions` isn't available yet in this org, fall back: ask the\n> person to describe (or paste) one failing run, and read the current\n> `AGENTS.md` from the org's synced repo. You still diagnose before you fix.\n\n## Step 2 \u2014 Explain, then fix\n\nTell the person, plainly, which of the three it is and why. Then:\n\n**Bloat \u2192** don't reuse one ever-growing chat for the same task. Start a fresh\nsession per task/topic (or `/reset` the runaway one). This fixes the veer\n*and* the cost.\n\n**Patchwork \u2192** rewrite `AGENTS.md`, don't append to it. Structure it: **role\n\u2192 a short list of hard rules up front \u2192 the steps \u2192 one example of right vs\nwrong.** Delete contradictions. A tight, prioritized instruction set is\nfollowed far better than a long patched one.\n\n**Structure \u2192** author a **flow** for the repeatable task: deterministic steps,\neach with a narrow instruction, and the heavy/deterministic parts (fetch data,\nfill a template, render the deck) run *without* the model \u2014 less veer, less cost.\n\nWhere instructions live and how edits land:\n- Edit **`AGENTS.md`** (and `skills/`). Push via the org's **GitHub\n sync repo** (auto-deploys to the agent) or `clawnify deploy`. See the\n `use-the-clawnify-cli` skill for the commands.\n- Edit **flows** with `clawnify flows edit <name>` then `clawnify flows\n publish <name>` \u2014 validated on save; once a flow has a published version,\n runs and triggers keep using it until you publish again (before the first\n publish, the draft is what runs). Raw `flows/*.json` edits via the repo also\n land, but skip validation and versioning.\n- **No gateway restart needed** \u2014 the agent picks up new `AGENTS.md` / skills /\n flows on its **next session**.\n- **Never edit any `CLAWNIFY-*.md`** file (`CLAWNIFY-SOUL/AGENTS/TOOLS.md`) \u2014\n those are platform-owned and Clawnify overwrites them on every sync. Your\n edits there vanish.\n\n## How Clawnify agents actually work (what people get wrong)\n\nPreempt these \u2014 they cause \"I set it up but the agent ignores it\":\n\n- **Adding a document to Knowledge does NOT mean the agent reads it.**\n (1) A doc must be **published by a human** \u2014 an agent \"proposing\" it only\n creates a draft. (2) Once published, the agent only *automatically* sees its\n **title + one-line description** (a capped, ~30-item index); the **actual\n content is fetched only when the agent chooses to search** it\n (`company_knowledge_search`). So if the agent ignores a doc, check: is it\n published? not hidden? still in the index? does its `AGENTS.md` tell it to\n search? \u2014 **re-uploading won't help.** Depth: the `organize-company-knowledge` skill.\n- **Memory** is written by the agent via a tool (`memory_write`) and surfaced\n as an index + per-turn recall \u2014 it is **not** a file/folder you drop notes\n into.\n- **The dashboard \"recurring skill\" cards are manual-click only** \u2014 the\n cron/every/at schedule shown is **not wired to a scheduler.** For real\n scheduled or event-driven work use a **cron job or a flow/webhook**, not a\n recurring-skill card.\n- **Native channels** (WhatsApp/Telegram/Slack) receive messages \"for free\"\n via the allowlist \u2014 there is **no trigger/webhook to set up** for incoming\n messages. (Only Clawnify *integrations* have dashboard triggers.)\n\n## Answering \"would a different agent / a flow help?\"\n\n- **Same agent for the same task \u2192 confusion?** The agent identity isn't the\n problem; a reused, ever-growing **session** is (bloat, above). A second agent\n doesn't fix the mechanism and doubles what you manage. Fresh sessions do.\n- **Would a flow be better?** Yes *if* the task is repeatable and structured \u2014\n it constrains the agent and moves deterministic work off-model (less veer,\n less cost). No if the underlying step instructions are vague \u2014 a flow\n structures, it doesn't clarify.\n\n## Guardrails\n\n- **Diagnose before you change anything.** One transcript read beats five blind\n patches.\n- **Never** edit `CLAWNIFY-*.md` (overwritten) \u2014 edit `AGENTS.md`.\n- **Confirm with the human before anything irreversible or outward-facing:**\n sending messages on the agent's live channels, deleting an agent or app,\n billing/plan changes, rotating credentials. Self-service is not unattended\n autonomy.\n- **Connecting an integration is a hard stop, not a confirm.** If a fix needs a\n Clawnify integration that `clawnify connections list` shows as not connected\n (\u25CB), you *cannot* connect it \u2014 that needs the user's OAuth sign-in in a\n browser. Run `clawnify connections connect <id>` and relay the steps to the\n user; never attempt it yourself or ask for their password.\n- **Never put a secret through `clawnify env set`** \u2014 it exposes the value in\n the command and your context. Secrets and API keys go in the dashboard\n (Settings \u2192 Environment Variables / API Keys); guide the user there. Use\n `env set` only for non-secret config. And remember `agents create` / `env set`\n **restart the gateway** \u2014 confirm with the user before you run them on a live,\n busy agent.\n- **Never run `agents create` to \"find\" an agent.** It creates a *new sub-agent*\n and restarts the gateway. If the agent you expected isn't in `clawnify agents\n list`, you are in the wrong org (`clawnify org list`) or it genuinely doesn't\n exist \u2014 ask. Creating one leaves a duplicate the customer then has to live\n with, and interrupts the real agent while it does.\n- Prefer the **smallest durable fix** (a session habit, a tightened `AGENTS.md`,\n one flow) over more instructions.\n"
|
|
1425
1475
|
}
|
|
1426
1476
|
];
|
|
1427
|
-
var
|
|
1477
|
+
var RULES_BY_KIND = {
|
|
1478
|
+
"app": "You are working inside a **Clawnify app** \u2014 a full-stack project that deploys to\nCloudflare through the Clawnify platform. Follow these rules.\n\n## Stack (fixed \u2014 do not swap)\n\n- **Frontend:** React 19 + Tailwind v4, built with Vite.\n- **API:** Hono (`@hono/zod-openapi`) running on Cloudflare Workers.\n- **Database:** D1 (SQLite at the edge) via `@clawnify/db` (Drizzle).\n\nOne app = one `clawnify.json` manifest at the repo root. Don't introduce other\nframeworks, ORMs, or hosting targets.\n\n## The schema lives in `src/server/schema.ts`\n\n- Define tables with the Drizzle DSL there \u2014 it is the single source of truth.\n- **Never** hand-write SQL migrations or edit a `schema.sql` by hand. `clawnify\n dev` and `clawnify deploy` run `drizzle-kit generate` for you.\n- Every user-facing table needs an `org_id` column, and every query must filter\n by the `X-Clawnify-Org-Id` request header. This is how multi-tenancy works \u2014\n there are no exceptions.\n\n## Identity comes from request headers, never the client\n\nThe platform injects identity headers the client cannot forge:\n`X-Clawnify-User-Id`, `X-Clawnify-Org-Id`, `X-Clawnify-User-Email`,\n`X-Clawnify-Caller`. Read them server-side. Never trust a client-supplied user\nor org id.\n\n## Integrations: use `@clawnify/connections`\n\nDon't store per-service API keys or OAuth secrets in the app. Declare what the\napp needs under `app.credentials` in `clawnify.json`, then call\n`connect(service, env)` and `secret(name, env)` from the SDK. Off-platform\n(local dev, scripts), put a `clw_` org service token in `.dev.vars` as\n`CLAWNIFY_TOKEN` \u2014 the SDK then resolves your **real** org connections over HTTP\nwith no per-service secrets.\n\n## Commands\n\n- `clawnify dev` \u2014 local dev server. D1 runs as local SQLite, identical to\n production. Leave it running in a separate terminal so generated types stay\n fresh.\n- `clawnify deploy` \u2014 ships the app live at `https://<slug>.apps.clawnify.com`.\n- Don't invoke raw `wrangler` or `drizzle-kit` \u2014 the CLI wraps them. Editing\n `schema.ts` and running `clawnify dev`/`deploy` is the whole workflow.\n\n## Going deeper\n\nFor the full gold-standard structure \u2014 routing, OpenAPI route definitions,\nclient data-fetching patterns, file uploads \u2014 read the **build-a-clawnify-app**\nskill installed alongside these rules.\n",
|
|
1479
|
+
"website": "You are working inside a **Clawnify website** \u2014 an Astro site that deploys to\nCloudflare through the Clawnify platform. Follow these rules.\n\n## Stack (fixed \u2014 do not swap)\n\n- **Framework:** Astro 5, `output: \"server\"` with the `@astrojs/cloudflare`\n adapter. Pages render on a Worker, so `Astro.request` and runtime env are\n available; there is no static export step to fight.\n- **Styling:** Tailwind v4 via `@tailwindcss/vite`, entry `src/styles/global.css`.\n\nOne website = one `clawnify.json` manifest at the repo root, with\n`website: { framework: \"astro\" }`. Don't introduce another framework, another\nCSS system, or another hosting target.\n\n## This is a normal Astro project \u2014 author it as one\n\n- Pages are files: `src/pages/index.astro` is `/`, `src/pages/about.astro` is\n `/about`. Dynamic routes use `[slug].astro` the usual way.\n- Shared chrome belongs in `src/layouts/`; reusable markup in\n `src/components/`.\n- A route that fetches per request needs `export const prerender = false`.\n Without it Astro prerenders at build time and your data is frozen at deploy.\n\nThere is no page-tree JSON, no block registry, and no theme token file in this\nproject. Those belong to Clawnify's dashboard-managed website product, which is\na different thing with a different authoring model \u2014 don't go looking for them\nhere, and don't invent them.\n\n## Fetching data on the server\n\nFetch in the frontmatter (it runs on the Worker), not in a client script, unless\nthe data is genuinely user-interactive. Anything you can resolve server-side\nrenders in the first byte and costs the visitor nothing.\n\nGive any response you cache-control a real TTL: `public, max-age=<n>`. Clawnify\nedge-caches declared-public GETs, but only when the response says how long it is\ngood for.\n\n## Commands\n\n- `clawnify dev` \u2014 local dev server, same adapter as production.\n- `clawnify deploy` \u2014 publishes the site and prints its live URL.\n- Don't invoke raw `astro` or `wrangler` \u2014 the CLI wraps them, and it is what\n binds the deploy to your org and site.\n\n## Going deeper\n\nAstro's own docs are the reference for routing, layouts, and content\ncollections \u2014 this is a standard Astro project and nothing about it is\nClawnify-specific except the manifest and the deploy step. For CLI mechanics\n(workspaces, orgs, linking, custom domains) read the **use-the-clawnify-cli**\nskill installed alongside these rules.\n",
|
|
1480
|
+
"agent": 'You are working inside a **Clawnify agent** project \u2014 the configuration for an\nAI employee that runs on the Clawnify platform. Follow these rules.\n\n## What this project is\n\nOne agent = one `clawnify.json` manifest at the repo root, with\n`agent: { harness: "openclaw" }`. The manifest picks the runtime; everything\nelse here is prose and JSON that shapes behaviour. There is no application\nstack to choose \u2014 no framework, no database, no build.\n\n## The pieces\n\n- **`AGENT.md`** \u2014 the agent\'s primary instructions, its role, tone and\n boundaries, written as prose. This is the file that actually changes how the\n agent behaves; most requests to "change what the agent does" are edits here.\n- **`skills/<name>/`** \u2014 reusable procedures. A `SKILL.md` the agent reads when\n triggered, plus a `skill.json` describing when it runs. Reach for a skill when\n a task recurs with the same shape; don\'t encode one-offs.\n- **`flows/<name>.json`** \u2014 ClawFlow definitions for automations that run on a\n schedule or a trigger rather than in conversation.\n\n## Write instructions, not code\n\nThe most common mistake here is reaching for a script when the answer is a\nclearer sentence in `AGENT.md` or a skill. Prefer changing the instructions.\nAdd a flow only when something must run without a human in the loop.\n\n## Commands\n\n- `clawnify deploy` \u2014 pushes this configuration to the agent.\n- The push is additive on the agent\'s machine: it never deletes files the agent\n authored for itself.\n\n## Going deeper\n\nFor diagnosing an agent that is misbehaving \u2014 instructions not taking effect,\na channel not responding, a skill not firing \u2014 read the **fix-a-clawnify-agent**\nskill installed alongside these rules.\n'
|
|
1481
|
+
};
|
|
1482
|
+
var RULES_CONTENT = RULES_BY_KIND.app;
|
|
1428
1483
|
|
|
1429
1484
|
// src/lib/skills/install.ts
|
|
1430
1485
|
import {
|
|
@@ -1614,17 +1669,18 @@ var RULES_FILE = {
|
|
|
1614
1669
|
};
|
|
1615
1670
|
var START = "<!-- clawnify:rules:start -->";
|
|
1616
1671
|
var END = "<!-- clawnify:rules:end -->";
|
|
1617
|
-
var VERSION_RE = /<!--\s*clawnify:rules\s+v([\d.]+)
|
|
1618
|
-
|
|
1672
|
+
var VERSION_RE = /<!--\s*clawnify:rules\s+v([\d.]+)(?:\s+kind:\w+)?\s*-->/;
|
|
1673
|
+
var KIND_RE = /<!--\s*clawnify:rules\s+v[\d.]+\s+kind:(\w+)\s*-->/;
|
|
1674
|
+
function block(kind) {
|
|
1619
1675
|
return `${START}
|
|
1620
|
-
<!-- clawnify:rules v${CLI_VERSION} -->
|
|
1621
|
-
${
|
|
1676
|
+
<!-- clawnify:rules v${CLI_VERSION} kind:${kind} -->
|
|
1677
|
+
${RULES_BY_KIND[kind].trimEnd()}
|
|
1622
1678
|
${END}
|
|
1623
1679
|
`;
|
|
1624
1680
|
}
|
|
1625
|
-
function writeRules(cwd, file) {
|
|
1681
|
+
function writeRules(cwd, file, kind) {
|
|
1626
1682
|
const filePath = join3(cwd, file);
|
|
1627
|
-
const section = block();
|
|
1683
|
+
const section = block(kind);
|
|
1628
1684
|
const sectionRe = new RegExp(`${escapeRe2(START)}[\\s\\S]*?${escapeRe2(END)}\\n?`);
|
|
1629
1685
|
if (existsSync3(filePath)) {
|
|
1630
1686
|
const existing = readFileSync2(filePath, "utf8");
|
|
@@ -1632,11 +1688,13 @@ function writeRules(cwd, file) {
|
|
|
1632
1688
|
if (match) {
|
|
1633
1689
|
const versionMatch = match[0].match(VERSION_RE);
|
|
1634
1690
|
const previousVersion = versionMatch ? versionMatch[1] : null;
|
|
1635
|
-
|
|
1636
|
-
|
|
1691
|
+
const kindMatch = match[0].match(KIND_RE);
|
|
1692
|
+
const previousKind = kindMatch ? kindMatch[1] : null;
|
|
1693
|
+
if (previousVersion === CLI_VERSION && previousKind === kind) {
|
|
1694
|
+
return { status: "skipped", file: filePath, reason: `already at v${CLI_VERSION} (${kind})` };
|
|
1637
1695
|
}
|
|
1638
1696
|
writeFileSync2(filePath, existing.replace(sectionRe, section));
|
|
1639
|
-
return previousVersion ? { status: "updated", file: filePath, previousVersion } : { status: "installed", file: filePath };
|
|
1697
|
+
return previousVersion ? { status: "updated", file: filePath, previousVersion, previousKind, kind } : { status: "installed", file: filePath };
|
|
1640
1698
|
}
|
|
1641
1699
|
const prefix = existing.endsWith("\n") ? "\n" : "\n\n";
|
|
1642
1700
|
writeFileSync2(filePath, existing + prefix + section);
|
|
@@ -1728,15 +1786,25 @@ Valid: ${ALL_AGENTS.join(", ")}`);
|
|
|
1728
1786
|
if (detected.length > 0) return { agents: detected, defaulted: false };
|
|
1729
1787
|
return { agents: [agentByName("claude")], defaulted: true };
|
|
1730
1788
|
}
|
|
1789
|
+
function resolveRulesKind(cwd) {
|
|
1790
|
+
try {
|
|
1791
|
+
const manifest = readManifest(cwd);
|
|
1792
|
+
return manifest ? manifestKind(manifest) : "app";
|
|
1793
|
+
} catch {
|
|
1794
|
+
return "app";
|
|
1795
|
+
}
|
|
1796
|
+
}
|
|
1731
1797
|
function installAiFiles(cwd, agents, opts) {
|
|
1798
|
+
const kind = resolveRulesKind(cwd);
|
|
1732
1799
|
const rulesFiles = [...new Set(agents.map((a) => RULES_FILE[a.agent]))];
|
|
1733
1800
|
let rules = 0;
|
|
1734
1801
|
for (const file of rulesFiles) {
|
|
1735
|
-
const r = writeRules(cwd, file);
|
|
1802
|
+
const r = writeRules(cwd, file, kind);
|
|
1736
1803
|
if (r.status === "skipped") {
|
|
1737
1804
|
console.log(` \xB7 rules \u2192 ${r.file} (${r.reason})`);
|
|
1738
1805
|
} else if (r.status === "updated") {
|
|
1739
|
-
|
|
1806
|
+
const change = r.previousKind === r.kind ? `v${r.previousVersion} \u2192 v${CLI_VERSION}` : `${r.previousKind ?? "unkinded"} \u2192 ${r.kind}`;
|
|
1807
|
+
console.log(` \u2191 rules \u2192 ${r.file} (${change})`);
|
|
1740
1808
|
rules++;
|
|
1741
1809
|
} else {
|
|
1742
1810
|
console.log(` \u2713 rules \u2192 ${r.file}`);
|
|
@@ -1922,6 +1990,9 @@ async function initApp(dir, opts) {
|
|
|
1922
1990
|
clawnify: "^0.11.3",
|
|
1923
1991
|
"drizzle-kit": "^0.31.0",
|
|
1924
1992
|
tailwindcss: "^4.0.0",
|
|
1993
|
+
// `vite build` only transpiles — it never typechecks — so without this the
|
|
1994
|
+
// scaffold ships with no way to catch a type error before deploy.
|
|
1995
|
+
typescript: "^5.0.0",
|
|
1925
1996
|
vite: "^6.0.0",
|
|
1926
1997
|
wrangler: "^4.0.0"
|
|
1927
1998
|
};
|
|
@@ -1932,6 +2003,11 @@ async function initApp(dir, opts) {
|
|
|
1932
2003
|
scripts: {
|
|
1933
2004
|
dev: "clawnify dev",
|
|
1934
2005
|
build: "vite build",
|
|
2006
|
+
// Referenced by the generated schema.ts comment and the starter UI, and
|
|
2007
|
+
// run implicitly by `clawnify deploy`. It must exist as a script or
|
|
2008
|
+
// following the app's own instructions fails with "Missing script".
|
|
2009
|
+
"db:generate": "drizzle-kit generate",
|
|
2010
|
+
typecheck: "tsc --noEmit",
|
|
1935
2011
|
deploy: "clawnify deploy"
|
|
1936
2012
|
},
|
|
1937
2013
|
dependencies: {
|
|
@@ -2114,6 +2190,53 @@ export default app;
|
|
|
2114
2190
|
`);
|
|
2115
2191
|
}
|
|
2116
2192
|
write(targetDir, "src/client/index.css", `@import "tailwindcss";
|
|
2193
|
+
|
|
2194
|
+
/* Design tokens. Rebrand by editing values here \u2014 no component file should
|
|
2195
|
+
contain a raw hex, font name, or fixed pixel value. */
|
|
2196
|
+
@theme {
|
|
2197
|
+
--color-background: #ffffff;
|
|
2198
|
+
--color-surface: #ffffff;
|
|
2199
|
+
--color-surface-sunken: #f1f5f9;
|
|
2200
|
+
--color-foreground: #1a202c;
|
|
2201
|
+
--color-muted: #475569;
|
|
2202
|
+
--color-faint: #94a3b8;
|
|
2203
|
+
--color-border: #e2e8f0;
|
|
2204
|
+
--color-ring: #2563eb;
|
|
2205
|
+
--color-primary: #dd5164;
|
|
2206
|
+
--color-primary-hover: #c53a4e;
|
|
2207
|
+
--color-on-primary: #ffffff;
|
|
2208
|
+
--color-success: #047857;
|
|
2209
|
+
--color-success-tint: #ecfdf5;
|
|
2210
|
+
--color-warning: #b45309;
|
|
2211
|
+
--color-warning-tint: #fffbeb;
|
|
2212
|
+
--color-danger: #b91c1c;
|
|
2213
|
+
--color-danger-tint: #fef2f2;
|
|
2214
|
+
--font-sans: Inter, ui-sans-serif, system-ui, sans-serif;
|
|
2215
|
+
}
|
|
2216
|
+
|
|
2217
|
+
/* Dark MUST override the custom properties in a plain rule. Tailwind v4 hoists
|
|
2218
|
+
and merges every @theme block and drops the surrounding media condition, so a
|
|
2219
|
+
nested \`@media { @theme { \u2026 } }\` silently makes dark the *unconditional*
|
|
2220
|
+
default and light never renders. Light stays the default; dark is opt-in by
|
|
2221
|
+
system preference. */
|
|
2222
|
+
@media (prefers-color-scheme: dark) {
|
|
2223
|
+
:root {
|
|
2224
|
+
--color-background: #0d1117;
|
|
2225
|
+
--color-surface: #161b22;
|
|
2226
|
+
--color-surface-sunken: #1c2128;
|
|
2227
|
+
--color-foreground: #e6edf3;
|
|
2228
|
+
--color-muted: #9ba7b3;
|
|
2229
|
+
--color-faint: #6e7681;
|
|
2230
|
+
--color-border: #30363d;
|
|
2231
|
+
--color-ring: #4493f8;
|
|
2232
|
+
--color-success: #3fb950;
|
|
2233
|
+
--color-success-tint: #12261e;
|
|
2234
|
+
--color-warning: #d29922;
|
|
2235
|
+
--color-warning-tint: #2a2210;
|
|
2236
|
+
--color-danger: #f85149;
|
|
2237
|
+
--color-danger-tint: #2d1518;
|
|
2238
|
+
}
|
|
2239
|
+
}
|
|
2117
2240
|
`);
|
|
2118
2241
|
write(targetDir, "src/client/main.tsx", `import { StrictMode } from "react";
|
|
2119
2242
|
import { createRoot } from "react-dom/client";
|
|
@@ -3006,15 +3129,13 @@ async function orgListCommand() {
|
|
|
3006
3129
|
console.log("No organizations.");
|
|
3007
3130
|
return;
|
|
3008
3131
|
}
|
|
3009
|
-
const auth = loadAuth();
|
|
3010
3132
|
const nameWidth = Math.max(4, ...orgs.map((o) => o.name.length));
|
|
3011
3133
|
const slugWidth = Math.max(4, ...orgs.map((o) => o.slug.length));
|
|
3012
|
-
console.log(`${"Name".padEnd(nameWidth)} ${"Slug".padEnd(slugWidth)} Role
|
|
3013
|
-
console.log(`${"\u2500".repeat(nameWidth)} ${"\u2500".repeat(slugWidth)} \u2500\u2500\u2500\u2500\u2500\u2500\u2500
|
|
3134
|
+
console.log(`${"Name".padEnd(nameWidth)} ${"Slug".padEnd(slugWidth)} Role`);
|
|
3135
|
+
console.log(`${"\u2500".repeat(nameWidth)} ${"\u2500".repeat(slugWidth)} \u2500\u2500\u2500\u2500\u2500\u2500\u2500`);
|
|
3014
3136
|
for (const o of orgs) {
|
|
3015
|
-
const active = auth?.org_id === o.id ? " *" : "";
|
|
3016
3137
|
console.log(
|
|
3017
|
-
`${o.name.padEnd(nameWidth)} ${o.slug.padEnd(slugWidth)} ${o.role
|
|
3138
|
+
`${o.name.padEnd(nameWidth)} ${o.slug.padEnd(slugWidth)} ${o.role}`
|
|
3018
3139
|
);
|
|
3019
3140
|
}
|
|
3020
3141
|
}
|
|
@@ -3027,13 +3148,25 @@ async function orgUseCommand(slugOrId) {
|
|
|
3027
3148
|
);
|
|
3028
3149
|
process.exit(1);
|
|
3029
3150
|
}
|
|
3030
|
-
|
|
3031
|
-
|
|
3032
|
-
|
|
3033
|
-
|
|
3034
|
-
|
|
3035
|
-
|
|
3036
|
-
|
|
3151
|
+
console.error(
|
|
3152
|
+
`\`clawnify org use\` is deprecated and no longer sets anything.
|
|
3153
|
+
Org is resolved per folder, so a global default cannot redirect another
|
|
3154
|
+
session mid-task. Bind ${match.name} to this folder instead:
|
|
3155
|
+
|
|
3156
|
+
clawnify link <app> --org ${match.slug}
|
|
3157
|
+
writes .clawnify/project.json \u2014 persists for this folder
|
|
3158
|
+
|
|
3159
|
+
"workspace": { "org": "${match.slug}" } in clawnify.json
|
|
3160
|
+
for a workspace repo \u2014 persists for every folder inside it
|
|
3161
|
+
|
|
3162
|
+
--org ${match.slug}
|
|
3163
|
+
one command
|
|
3164
|
+
|
|
3165
|
+
export CLAWNIFY_ORG_ID=${match.slug}
|
|
3166
|
+
one shell
|
|
3167
|
+
`
|
|
3168
|
+
);
|
|
3169
|
+
process.exit(1);
|
|
3037
3170
|
}
|
|
3038
3171
|
|
|
3039
3172
|
// src/commands/connections.ts
|
|
@@ -3137,18 +3270,18 @@ async function resolveOrg(opts) {
|
|
|
3137
3270
|
process.exit(1);
|
|
3138
3271
|
}
|
|
3139
3272
|
if (opts?.org) {
|
|
3140
|
-
const
|
|
3141
|
-
if (!
|
|
3273
|
+
const match2 = orgs.find((o) => o.id === opts.org || o.slug === opts.org);
|
|
3274
|
+
if (!match2) {
|
|
3142
3275
|
console.error(
|
|
3143
3276
|
`No org matched "${opts.org}". Available: ${orgs.map((o) => o.slug).join(", ")}`
|
|
3144
3277
|
);
|
|
3145
3278
|
process.exit(1);
|
|
3146
3279
|
}
|
|
3147
|
-
return
|
|
3280
|
+
return match2;
|
|
3148
3281
|
}
|
|
3149
|
-
const
|
|
3150
|
-
const
|
|
3151
|
-
if (
|
|
3282
|
+
const resolved = await resolveOrgContext();
|
|
3283
|
+
const match = resolved ? orgs.find((o) => o.id === resolved) : void 0;
|
|
3284
|
+
if (match) return match;
|
|
3152
3285
|
if (orgs.length === 1) return orgs[0];
|
|
3153
3286
|
console.error(
|
|
3154
3287
|
`Multiple orgs \u2014 pick one with \`--org <slug>\` (or set a default: \`clawnify org use <slug>\`).
|
|
@@ -3285,8 +3418,7 @@ async function workspaceStatusCommand(opts) {
|
|
|
3285
3418
|
${WORKSPACE_GUIDE}`);
|
|
3286
3419
|
process.exit(1);
|
|
3287
3420
|
}
|
|
3288
|
-
const
|
|
3289
|
-
const orgId = auth?.org_id ?? process.env.CLAWNIFY_ORG_ID;
|
|
3421
|
+
const orgId = await resolveOrgContext();
|
|
3290
3422
|
const res = await api.get("/v1/github/links", orgId ? { orgId } : void 0);
|
|
3291
3423
|
if (!res.ok) {
|
|
3292
3424
|
console.error(`Failed to load workspace state (${res.status}).`);
|
|
@@ -3297,8 +3429,7 @@ ${WORKSPACE_GUIDE}`);
|
|
|
3297
3429
|
console.log(JSON.stringify({ logged_in: true, ...data, guide: WORKSPACE_GUIDE }));
|
|
3298
3430
|
return;
|
|
3299
3431
|
}
|
|
3300
|
-
|
|
3301
|
-
console.log(`Org: ${orgLabel}`);
|
|
3432
|
+
console.log(`Org: ${data.org_id}`);
|
|
3302
3433
|
if (data.links.length === 0) {
|
|
3303
3434
|
console.log(`
|
|
3304
3435
|
No GitHub repo is linked yet. Local editing works through the org's
|
|
@@ -3354,8 +3485,7 @@ async function workspaceConnectCommand(opts) {
|
|
|
3354
3485
|
then re-run \`clawnify workspace connect\`.`);
|
|
3355
3486
|
process.exit(1);
|
|
3356
3487
|
}
|
|
3357
|
-
const
|
|
3358
|
-
const orgId = auth?.org_id ?? process.env.CLAWNIFY_ORG_ID;
|
|
3488
|
+
const orgId = await resolveOrgContext();
|
|
3359
3489
|
const orgOpt = orgId ? { orgId } : void 0;
|
|
3360
3490
|
let installs = await listInstallations(orgId);
|
|
3361
3491
|
if (installs.length === 0) {
|
|
@@ -3531,15 +3661,15 @@ async function docsCommand(slug, options) {
|
|
|
3531
3661
|
process.stderr.write("Not logged in. Run `clawnify login` first.\n");
|
|
3532
3662
|
process.exit(1);
|
|
3533
3663
|
}
|
|
3534
|
-
const
|
|
3535
|
-
if (!
|
|
3664
|
+
const orgId = await resolveOrgContext();
|
|
3665
|
+
if (!orgId) {
|
|
3536
3666
|
process.stderr.write(
|
|
3537
3667
|
"No active org. Pick one with `clawnify org use <slug-or-id>` first.\n"
|
|
3538
3668
|
);
|
|
3539
3669
|
process.exit(1);
|
|
3540
3670
|
}
|
|
3541
3671
|
const caller = options.caller ?? "external";
|
|
3542
|
-
const path10 = slug ? `/docs/${
|
|
3672
|
+
const path10 = slug ? `/docs/${orgId}/${slug}.md?caller=${caller}` : `/docs/${orgId}/index.md`;
|
|
3543
3673
|
const res = await fetch(DOCS_URL + path10, {
|
|
3544
3674
|
headers: {
|
|
3545
3675
|
authorization: "Bearer " + token
|
|
@@ -3569,8 +3699,9 @@ async function mcpBridgeCommand() {
|
|
|
3569
3699
|
"content-type": "application/json",
|
|
3570
3700
|
authorization: "Bearer " + token
|
|
3571
3701
|
};
|
|
3572
|
-
|
|
3573
|
-
|
|
3702
|
+
const bridgeOrgId = await resolveOrgContext();
|
|
3703
|
+
if (bridgeOrgId) {
|
|
3704
|
+
baseHeaders["X-Clawnify-Org-Id"] = bridgeOrgId;
|
|
3574
3705
|
}
|
|
3575
3706
|
const rl = readline5.createInterface({ input: process.stdin, terminal: false });
|
|
3576
3707
|
rl.on("line", async (line) => {
|
|
@@ -3993,4 +4124,4 @@ async function runCli() {
|
|
|
3993
4124
|
export {
|
|
3994
4125
|
runCli
|
|
3995
4126
|
};
|
|
3996
|
-
//# sourceMappingURL=cli-
|
|
4127
|
+
//# sourceMappingURL=cli-BOJXG2ZQ.js.map
|