@superwall/cli 1.7.0 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +192 -52
- package/dist/{setup-Bxj22rYi.js → apple-CSzNTGHM.js} +82 -76
- package/dist/auth.d.ts +4 -19
- package/dist/auth.js +4 -2
- package/dist/{actions-B7ym3oVS.js → billing-C3Q8DBU2.js} +98 -28
- package/dist/{bind-YrJvuRF9.js → bind-BumHTi9O.js} +38 -33
- package/dist/{build-DLoCW5Ri.js → build-Bpviiclc.js} +20 -26
- package/dist/client-BL0f_yGf.js +176 -0
- package/dist/{asc-Bf7zBbyS.js → client-BZ1UbpXz.js} +16 -15
- package/dist/config-BO1Y87kV.js +105 -0
- package/dist/create-BSfvpWoD.js +19 -0
- package/dist/{create-pkANt1Gs.js → create-BUcVG4Ab.js} +195 -169
- package/dist/{notification-url-DuKF2659.js → create-CfK3PeKA.js} +235 -539
- package/dist/doctor-BWqIYcMn.js +83 -0
- package/dist/{drivers-Qx9LxmRN.js → drivers-CPhdPkW5.js} +185 -172
- package/dist/entry.d.ts +0 -5
- package/dist/entry.js +28072 -1134
- package/dist/environment-eBXjELoN.js +58 -0
- package/dist/{existing-AVEfZu2A.js → existing-BltvQiX5.js} +12 -6
- package/dist/held-CPve03KJ.js +16 -0
- package/dist/held-DgnTFMl3.js +1112 -0
- package/dist/input-vi0bou04.js +42 -0
- package/dist/{integrate-brmhPG-S.js → integrate-BRsqoe01.js} +277 -254
- package/dist/log-NVhVe_oe.js +62 -0
- package/dist/login-BCEH5q0U.js +53 -0
- package/dist/login-BPOONe7n.js +16 -0
- package/dist/{login-Do4wFuLv.js → login-BbTIrCFT.js} +118 -55
- package/dist/lookup-rr1AkCJA.js +71 -0
- package/dist/migrate-C9X2Vz81.js +274 -0
- package/dist/notification-url-CV86qiKP.js +100 -0
- package/dist/{open-studio-DOw-6ydc.js → open-CcpXotHG.js} +34 -43
- package/dist/org-BQQDo7wm.js +35 -0
- package/dist/output-Ggzq5_-t.js +122 -0
- package/dist/paths-CRlU72cq.js +29 -0
- package/dist/playbook-DVMXN7fh.js +53 -0
- package/dist/{asc-products-9JXtDxI4.js → products-DH_fK9tY.js} +6 -6
- package/dist/promote-Da8xctzy.js +91 -0
- package/dist/push-BV-grvQg.js +22 -0
- package/dist/push-D6R9icWN.js +495 -0
- package/dist/registry-BYVD-_h6.js +10385 -0
- package/dist/{reports-CfJqoava.js → reports-D_qbl7_u.js} +7 -6
- package/dist/{resources-Bf9O1JNM.js → resources-DLON3-61.js} +162 -55
- package/dist/{run-DsVZ5snL.js → run-Co-BwhOg.js} +16 -22
- package/dist/scan-B88OlWOt.js +4 -0
- package/dist/{scan-zKsddO72.js → scan-CKuk-_6W.js} +48 -37
- package/dist/scope-DV22_Ufm.js +198 -0
- package/dist/screenshot-file-tVBfUEIi.js +16 -0
- package/dist/{selection-CxZoX4NT.js → selection-C2_KbLuo.js} +100 -51
- package/dist/server-C4f6ccUr.js +22 -0
- package/dist/{dev-DmB3XqaJ.js → server-D0d2oP-5.js} +86 -94
- package/dist/session-B-Uz0cQ7.js +40 -0
- package/dist/session-BuvArt1j.js +6 -0
- package/dist/session-C4rbE3VS.js +796 -0
- package/dist/skills/animate-onboarding/SKILL.md +467 -0
- package/dist/skills/animate-onboarding/references/engine.md +494 -0
- package/dist/skills/animate-onboarding/references/framework/Question.tsx +71 -0
- package/dist/skills/animate-onboarding/references/framework/README.md +40 -0
- package/dist/skills/animate-onboarding/references/framework/answers.ts +19 -0
- package/dist/skills/animate-onboarding/references/framework/flow.ts +80 -0
- package/dist/skills/animate-onboarding/references/framework/handoffs.ts +869 -0
- package/dist/skills/animate-onboarding/references/framework/layout.tsx +113 -0
- package/dist/skills/animate-onboarding/references/framework/motion.css +559 -0
- package/dist/skills/animate-onboarding/references/framework/useStoryRouter.ts +48 -0
- package/dist/skills/animate-onboarding/references/handoffs.md +375 -0
- package/dist/skills/animate-onboarding/references/imageReady.ts +92 -0
- package/dist/skills/animate-onboarding/references/morphFrame.ts +356 -0
- package/dist/skills/animate-onboarding/references/performance.md +41 -0
- package/dist/skills/animate-onboarding/references/web-runtime/README.md +17 -0
- package/dist/skills/animate-onboarding/references/web-runtime/handoffs.ts +858 -0
- package/dist/skills/animate-onboarding/references/web-runtime/story-motion.css +301 -0
- package/dist/skills/index.json +37 -0
- package/dist/skills/mobile-design/SKILL.md +447 -0
- package/dist/skills/mobile-design/references/responsive.md +162 -0
- package/dist/skills/onboarding-questions/SKILL.md +231 -0
- package/dist/skills/onboarding-questions/references/arpu-questions.md +139 -0
- package/dist/skills/onboarding-questions/references/craft.md +142 -0
- package/dist/skills/onboarding-questions/references/example-reflective.md +117 -0
- package/dist/skills/superwall/SKILL.md +82 -9
- package/dist/skills/superwall/references/api.md +153 -37
- package/dist/skills/superwall/references/apple-setup.md +316 -0
- package/dist/skills/superwall/references/asc.md +74 -38
- package/dist/skills/superwall/references/data-analytics.md +55 -21
- package/dist/skills/superwall/workflows/dashboard/playbook.md +3 -3
- package/dist/skills/superwall/workflows/dashboard/setup.md +8 -8
- package/dist/skills/superwall/workflows/migrate/adapty.md +6 -6
- package/dist/skills/superwall/workflows/migrate/playbook.md +4 -4
- package/dist/skills/superwall/workflows/migrate/qonversion.md +5 -5
- package/dist/skills/superwall/workflows/migrate/revenuecat.md +6 -6
- package/dist/skills/superwall/workflows/placements/android.md +2 -2
- package/dist/skills/superwall/workflows/placements/expo.md +2 -2
- package/dist/skills/superwall/workflows/placements/flutter.md +2 -2
- package/dist/skills/superwall/workflows/placements/ios.md +2 -2
- package/dist/skills/superwall/workflows/placements/playbook.md +2 -2
- package/dist/skills/superwall/workflows/placements/react-native.md +2 -2
- package/dist/skills/superwall/workflows/placements/strategy.md +2 -2
- package/dist/skills/superwall/workflows/review/playbook.md +1 -1
- package/dist/skills/superwall-editor/SKILL.md +61 -0
- package/dist/skills/superwall-editor/references/cli.md +135 -0
- package/dist/skills/superwall-editor/references/design.md +51 -0
- package/dist/skills/superwall-editor/references/native-elements.md +171 -0
- package/dist/skills/superwall-editor/references/workflow.md +65 -0
- package/dist/skills/superwall-editor/scripts/sw-editor.sh +662 -0
- package/dist/skills/superwall-framework/SKILL.md +85 -31
- package/dist/skills/superwall-framework/references/cli.md +58 -27
- package/dist/skills/superwall-framework/references/examples.md +4 -3
- package/dist/skills/superwall-framework/references/layout.md +64 -9
- package/dist/skills/superwall-framework/references/migrate-from-editor.md +1 -1
- package/dist/skills/superwall-framework/references/onboarding-state.md +245 -0
- package/dist/skills/wwdc/SKILL.md +22 -0
- package/dist/skills/wwdc/references/docs.md +52 -0
- package/dist/skills/wwdc/scripts/wwdc.sh +266 -0
- package/dist/skills-CLGJuMnF.js +14 -0
- package/dist/{skills-DPzlnfCK.js → skills-CZcpnEnG.js} +100 -122
- package/dist/{spawn-DSoTXy_j.js → spawn-DmmmHIP-.js} +14 -12
- package/dist/spinner-C2U6QBJ9.js +294 -0
- package/dist/storage-6h9vyiAz.js +31 -0
- package/dist/storage-CerJ5KLP.d.ts +16 -0
- package/dist/storekit-CK9JmM2D.js +16 -0
- package/dist/storekit-CinJra3V.js +47 -0
- package/dist/telemetry-DKyDhURo.js +56 -0
- package/dist/theme-DUsCh-Vd.js +25 -0
- package/dist/timing-BVxPrYq3.js +5 -0
- package/dist/{token-C0it-Xh7.js → token-DaxQgQkv.js} +6 -38
- package/dist/tools-skills/animate-onboarding/SKILL.md +467 -0
- package/dist/tools-skills/animate-onboarding/references/engine.md +494 -0
- package/dist/tools-skills/animate-onboarding/references/framework/Question.tsx +71 -0
- package/dist/tools-skills/animate-onboarding/references/framework/README.md +40 -0
- package/dist/tools-skills/animate-onboarding/references/framework/answers.ts +19 -0
- package/dist/tools-skills/animate-onboarding/references/framework/flow.ts +80 -0
- package/dist/tools-skills/animate-onboarding/references/framework/handoffs.ts +869 -0
- package/dist/tools-skills/animate-onboarding/references/framework/layout.tsx +113 -0
- package/dist/tools-skills/animate-onboarding/references/framework/motion.css +559 -0
- package/dist/tools-skills/animate-onboarding/references/framework/useStoryRouter.ts +48 -0
- package/dist/tools-skills/animate-onboarding/references/handoffs.md +375 -0
- package/dist/tools-skills/animate-onboarding/references/imageReady.ts +92 -0
- package/dist/tools-skills/animate-onboarding/references/morphFrame.ts +356 -0
- package/dist/tools-skills/animate-onboarding/references/performance.md +41 -0
- package/dist/tools-skills/animate-onboarding/references/web-runtime/README.md +17 -0
- package/dist/tools-skills/animate-onboarding/references/web-runtime/handoffs.ts +858 -0
- package/dist/tools-skills/animate-onboarding/references/web-runtime/story-motion.css +301 -0
- package/dist/tools-skills/mobile-design/SKILL.md +447 -0
- package/dist/tools-skills/mobile-design/references/responsive.md +162 -0
- package/dist/tools-skills/onboarding-questions/SKILL.md +231 -0
- package/dist/tools-skills/onboarding-questions/references/arpu-questions.md +139 -0
- package/dist/tools-skills/onboarding-questions/references/craft.md +142 -0
- package/dist/tools-skills/onboarding-questions/references/example-reflective.md +117 -0
- package/dist/tools-skills/superwall/SKILL.md +263 -0
- package/dist/tools-skills/superwall/references/api.md +303 -0
- package/dist/tools-skills/superwall/references/asa.md +166 -0
- package/dist/tools-skills/superwall/references/asc.md +95 -0
- package/dist/tools-skills/superwall/references/dashboard-links.md +57 -0
- package/dist/tools-skills/superwall/references/data-analytics.md +896 -0
- package/dist/tools-skills/superwall/references/docs.md +51 -0
- package/dist/tools-skills/superwall/references/sdk-integration.md +104 -0
- package/dist/tools-skills/superwall/references/sdk-source.md +18 -0
- package/dist/tools-skills/superwall/workflows/dashboard/playbook.md +76 -0
- package/dist/tools-skills/superwall/workflows/dashboard/setup.md +100 -0
- package/dist/tools-skills/superwall/workflows/integrate/android.md +292 -0
- package/dist/tools-skills/superwall/workflows/integrate/expo.md +272 -0
- package/dist/tools-skills/superwall/workflows/integrate/flutter.md +285 -0
- package/dist/tools-skills/superwall/workflows/integrate/ios.md +314 -0
- package/dist/tools-skills/superwall/workflows/integrate/playbook.md +83 -0
- package/dist/tools-skills/superwall/workflows/integrate/react-native.md +246 -0
- package/dist/tools-skills/superwall/workflows/migrate/adapty.md +229 -0
- package/dist/tools-skills/superwall/workflows/migrate/playbook.md +78 -0
- package/dist/tools-skills/superwall/workflows/migrate/qonversion.md +227 -0
- package/dist/tools-skills/superwall/workflows/migrate/revenuecat.md +414 -0
- package/dist/tools-skills/superwall/workflows/placements/android.md +175 -0
- package/dist/tools-skills/superwall/workflows/placements/expo.md +161 -0
- package/dist/tools-skills/superwall/workflows/placements/flutter.md +139 -0
- package/dist/tools-skills/superwall/workflows/placements/ios.md +165 -0
- package/dist/tools-skills/superwall/workflows/placements/playbook.md +69 -0
- package/dist/tools-skills/superwall/workflows/placements/react-native.md +145 -0
- package/dist/tools-skills/superwall/workflows/placements/strategy.md +222 -0
- package/dist/tools-skills/superwall/workflows/review/android.md +120 -0
- package/dist/tools-skills/superwall/workflows/review/expo.md +100 -0
- package/dist/tools-skills/superwall/workflows/review/flutter.md +99 -0
- package/dist/tools-skills/superwall/workflows/review/ios.md +108 -0
- package/dist/tools-skills/superwall/workflows/review/playbook.md +70 -0
- package/dist/tools-skills/superwall/workflows/review/react-native.md +100 -0
- package/dist/tools-skills/superwall-editor/SKILL.md +113 -0
- package/dist/tools-skills/superwall-editor/references/cli.md +135 -0
- package/dist/tools-skills/superwall-editor/references/design.md +51 -0
- package/dist/tools-skills/superwall-editor/references/native-elements.md +171 -0
- package/dist/tools-skills/superwall-editor/references/workflow.md +65 -0
- package/dist/tools-skills/superwall-editor/scripts/sw-editor.sh +662 -0
- package/dist/tools-skills/wwdc/SKILL.md +22 -0
- package/dist/tools-skills/wwdc/references/docs.md +52 -0
- package/dist/tools-skills/wwdc/scripts/wwdc.sh +266 -0
- package/dist/tools.d.ts +96 -0
- package/dist/tools.js +11360 -0
- package/dist/ui-D_qf3Gvw.js +53 -0
- package/dist/upgrade-DPo0a4Es.js +117 -0
- package/dist/upgrade-ffseQDMx.js +7 -0
- package/package.json +10 -5
- package/dist/api-CZzirVMj.js +0 -151
- package/dist/api-output-aJNw7Syy.js +0 -20
- package/dist/app-DH6U8yuI.js +0 -190
- package/dist/asa-C-sQzPPn.js +0 -1194
- package/dist/asc-1ZBJ6DwS.js +0 -778
- package/dist/auth-YRhlV3DE.js +0 -140
- package/dist/billing-CCYHdApx.js +0 -80
- package/dist/bundle-id-CKxl_026.js +0 -121
- package/dist/command-CMIz81Da.js +0 -301
- package/dist/dev-DZy6pOnB.js +0 -22
- package/dist/doctor-H-hf-Yww.js +0 -88
- package/dist/feedback-CKf-rpBW.js +0 -152
- package/dist/hosted-CXe9TrWx.js +0 -32
- package/dist/migrate-C9ERDR6y.js +0 -284
- package/dist/org-sj7uyvp-.js +0 -40
- package/dist/output-C4o2gJ1K.js +0 -146
- package/dist/params-l3CrvRtR.js +0 -51
- package/dist/pipeline-BqzqZhX1.js +0 -977
- package/dist/print-skill-ZojRSybs.js +0 -74
- package/dist/promote-BG8X4Nv_.js +0 -88
- package/dist/publish-sxLh-G4G.js +0 -35
- package/dist/push-bQ6Vxtg8.js +0 -35
- package/dist/query-_FbybaH-.js +0 -53
- package/dist/resource-CGIwSd29.js +0 -323
- package/dist/revenue-provider-ebsRINY8.js +0 -100
- package/dist/scope-BvzD-kO4.js +0 -223
- package/dist/skills-D_R-lEsK.js +0 -64
- package/dist/spinner-TWa0hia6.js +0 -18
- package/dist/storekit-Cj9Cpjcz.js +0 -29
- package/dist/telemetry-DeA1mvnT.js +0 -169
- package/dist/ui-Dy0b-9L8.js +0 -27738
- package/dist/update-B2fWIc4q.js +0 -59
- package/dist/upgrade-BmzkTKrh.js +0 -72
- /package/dist/{devtools-8EgLo86w.js → devtools-pBl_vt03.js} +0 -0
|
@@ -1,44 +1,34 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { r as spawnStream } from "./spawn-
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
1
|
+
import { _ as VERSION, a as CHANNEL, o as CHANNELS } from "./environment-eBXjELoN.js";
|
|
2
|
+
import { m as writeSkillsSync, s as readSkillsSync } from "./config-BO1Y87kV.js";
|
|
3
|
+
import { r as track } from "./telemetry-DKyDhURo.js";
|
|
4
|
+
import { r as spawnStream } from "./spawn-DmmmHIP-.js";
|
|
5
|
+
import { n as withSpinner } from "./spinner-C2U6QBJ9.js";
|
|
6
|
+
import { n as ui } from "./ui-D_qf3Gvw.js";
|
|
7
|
+
import { i as packagedDir, t as AGENT_SKILLS_DIR } from "./paths-CRlU72cq.js";
|
|
7
8
|
import { existsSync, mkdtempSync, readFileSync, readdirSync, rmSync, writeFileSync } from "node:fs";
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
//#region src/packaged.ts
|
|
11
|
-
const moduleDir = dirname(fileURLToPath(import.meta.url));
|
|
12
|
-
let root;
|
|
13
|
-
/** The package root: nearest ancestor with a package.json (repo in dev, install dir in prod). */
|
|
14
|
-
function packageRoot() {
|
|
15
|
-
if (root) return root;
|
|
16
|
-
let dir = moduleDir;
|
|
17
|
-
while (!existsSync(join(dir, "package.json"))) {
|
|
18
|
-
const parent = dirname(dir);
|
|
19
|
-
if (parent === dir) break;
|
|
20
|
-
dir = parent;
|
|
21
|
-
}
|
|
22
|
-
return root = dir;
|
|
23
|
-
}
|
|
24
|
-
/** Locate a directory shipped with the package; skills are bundled into dist/ by the build. */
|
|
25
|
-
function packagedDir(name) {
|
|
26
|
-
return join(packageRoot(), name === "skills" ? "dist/skills" : name) + "/";
|
|
27
|
-
}
|
|
9
|
+
import { join } from "node:path";
|
|
10
|
+
import { tmpdir } from "node:os";
|
|
28
11
|
|
|
29
|
-
//#
|
|
30
|
-
//#region src/core/agent/skills.ts
|
|
12
|
+
//#region src/core/support/skills.ts
|
|
31
13
|
const SUPERWALL_SKILLS_SOURCE = "superwall/skills";
|
|
32
14
|
const skillsRefFor = (channel) => CHANNELS[channel].skillsRef;
|
|
33
15
|
const SKILLS_REF = () => skillsRefFor(CHANNEL());
|
|
34
16
|
const skillsInstallSourceFor = (channel) => channel === "latest" ? SUPERWALL_SKILLS_SOURCE : `https://github.com/${SUPERWALL_SKILLS_SOURCE}/tree/${skillsRefFor(channel)}`;
|
|
35
17
|
const SKILLS_INSTALL_SOURCE = () => skillsInstallSourceFor(CHANNEL());
|
|
36
|
-
const
|
|
37
|
-
superwall: "latest",
|
|
38
|
-
"superwall-framework": "next"
|
|
39
|
-
};
|
|
18
|
+
const TOOLS_SKILLS_REF = CHANNELS.next.skillsRef;
|
|
40
19
|
const onChannel = (channel) => channel === "latest" || channel === CHANNEL();
|
|
41
|
-
|
|
20
|
+
function skillSummary(md) {
|
|
21
|
+
const firstSentence = (md.match(/^description:\s*(.+)$/m)?.[1] ?? "").trim().replace(/^["']|["'`]+$/g, "").replace(/(?<=\.)\s[\s\S]*$/, "");
|
|
22
|
+
return firstSentence.length > 64 ? `${firstSentence.slice(0, 61)}...` : firstSentence;
|
|
23
|
+
}
|
|
24
|
+
function bundledSkills() {
|
|
25
|
+
try {
|
|
26
|
+
return JSON.parse(readFileSync(`${bundledSkillsDir()}/index.json`, "utf8"));
|
|
27
|
+
} catch {
|
|
28
|
+
return [];
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const bundledSkillsForChannel = () => bundledSkills().filter((skill) => onChannel(skill.channel)).map((skill) => skill.name);
|
|
42
32
|
const PLAYBOOKS = {
|
|
43
33
|
"superwall-integrate": {
|
|
44
34
|
playbook: "superwall/workflows/integrate/playbook.md",
|
|
@@ -73,10 +63,10 @@ const cache = /* @__PURE__ */ new Map();
|
|
|
73
63
|
function bundledSkillsDir() {
|
|
74
64
|
return packagedDir("skills").replace(/\/$/, "");
|
|
75
65
|
}
|
|
76
|
-
function
|
|
66
|
+
function readBundledSkill(id, reference) {
|
|
77
67
|
const refs = (Array.isArray(reference) ? reference : [reference]).filter((r) => !!r);
|
|
78
68
|
const { playbook, refs: refsDir } = PLAYBOOKS[id];
|
|
79
|
-
const base =
|
|
69
|
+
const base = resolveSkillsBase(playbook);
|
|
80
70
|
const key = `${base}:${refs.length ? `${id}#${refs.join("+")}` : id}`;
|
|
81
71
|
const cached = cache.get(key);
|
|
82
72
|
if (cached !== void 0) return cached;
|
|
@@ -84,7 +74,7 @@ function loadBundledSkill(id, reference) {
|
|
|
84
74
|
cache.set(key, body);
|
|
85
75
|
return body;
|
|
86
76
|
}
|
|
87
|
-
function
|
|
77
|
+
function resolveSkillsBase(playbook) {
|
|
88
78
|
const installed = `${AGENT_SKILLS_DIR()}/`;
|
|
89
79
|
return existsSync(`${installed}${playbook}`) ? installed : packagedDir("skills");
|
|
90
80
|
}
|
|
@@ -103,63 +93,11 @@ function stripFrontmatter(md) {
|
|
|
103
93
|
}
|
|
104
94
|
return md;
|
|
105
95
|
}
|
|
106
|
-
const
|
|
107
|
-
{
|
|
108
|
-
name: "superwall",
|
|
109
|
-
summary: "Resources, ClickHouse SQL analytics, docs, SDK triage, and dashboard links",
|
|
110
|
-
channel: "latest"
|
|
111
|
-
},
|
|
112
|
-
{
|
|
113
|
-
name: "superwall-editor",
|
|
114
|
-
summary: "Build and edit live paywalls, onboarding, and web2app flows from the CLI",
|
|
115
|
-
channel: "latest"
|
|
116
|
-
},
|
|
117
|
-
{
|
|
118
|
-
name: "superwall-framework",
|
|
119
|
-
summary: "Paywalls, funnels and any updatable screen as React mini-apps with the framework",
|
|
120
|
-
channel: "next"
|
|
121
|
-
},
|
|
122
|
-
{
|
|
123
|
-
name: "superwall-integrate",
|
|
124
|
-
summary: "Install and configure the SDK in an app for the first time",
|
|
125
|
-
channel: "latest"
|
|
126
|
-
},
|
|
127
|
-
{
|
|
128
|
-
name: "superwall-placements",
|
|
129
|
-
summary: "Add or audit placements at feature gates and route them to campaigns",
|
|
130
|
-
channel: "latest"
|
|
131
|
-
},
|
|
132
|
-
{
|
|
133
|
-
name: "superwall-dashboard",
|
|
134
|
-
summary: "Create the entitlements, products and campaigns a placement needs",
|
|
135
|
-
channel: "latest"
|
|
136
|
-
},
|
|
137
|
-
{
|
|
138
|
-
name: "superwall-review",
|
|
139
|
-
summary: "Audit an existing Superwall setup end to end",
|
|
140
|
-
channel: "latest"
|
|
141
|
-
},
|
|
142
|
-
{
|
|
143
|
-
name: "superwall-migrate",
|
|
144
|
-
summary: "Move an app off RevenueCat, Adapty or Qonversion",
|
|
145
|
-
channel: "latest"
|
|
146
|
-
},
|
|
147
|
-
{
|
|
148
|
-
name: "superwall-paywall-migrate",
|
|
149
|
-
summary: "Rebuild a dashboard paywall as a framework paywall",
|
|
150
|
-
channel: "next"
|
|
151
|
-
},
|
|
152
|
-
{
|
|
153
|
-
name: "superwall-screen-migrate",
|
|
154
|
-
summary: "Rebuild a native screen as a framework surface",
|
|
155
|
-
channel: "next"
|
|
156
|
-
}
|
|
157
|
-
];
|
|
158
|
-
const knownSkills = () => KNOWN_SKILLS.filter((skill) => onChannel(skill.channel)).map(({ name, summary }) => ({
|
|
96
|
+
const knownSkills = () => bundledSkills().filter((skill) => onChannel(skill.channel)).map(({ name, summary }) => ({
|
|
159
97
|
name,
|
|
160
98
|
summary
|
|
161
99
|
}));
|
|
162
|
-
async function
|
|
100
|
+
async function listPublicSkills() {
|
|
163
101
|
try {
|
|
164
102
|
const res = await fetch(`https://api.github.com/repos/${SUPERWALL_SKILLS_SOURCE}/contents/skills?ref=${SKILLS_REF()}`, {
|
|
165
103
|
headers: { accept: "application/vnd.github+json" },
|
|
@@ -170,19 +108,17 @@ async function fetchPublicSkills() {
|
|
|
170
108
|
if (dirs.length === 0) return knownSkills();
|
|
171
109
|
return (await Promise.all(dirs.map(async (name) => ({
|
|
172
110
|
name,
|
|
173
|
-
summary: await
|
|
111
|
+
summary: await resolveSkillSummary(name)
|
|
174
112
|
})))).sort((a, b) => a.name === "superwall" ? -1 : b.name === "superwall" ? 1 : a.name.localeCompare(b.name));
|
|
175
113
|
} catch {
|
|
176
114
|
return knownSkills();
|
|
177
115
|
}
|
|
178
116
|
}
|
|
179
|
-
async function
|
|
117
|
+
async function resolveSkillSummary(name) {
|
|
180
118
|
try {
|
|
181
119
|
const res = await fetch(`https://raw.githubusercontent.com/${SUPERWALL_SKILLS_SOURCE}/${SKILLS_REF()}/skills/${name}/SKILL.md`, { signal: AbortSignal.timeout(6e3) });
|
|
182
120
|
if (!res.ok) return "";
|
|
183
|
-
|
|
184
|
-
const firstSentence = description.split(/(?<=\.)\s/)[0] ?? description;
|
|
185
|
-
return firstSentence.length > 64 ? `${firstSentence.slice(0, 61)}...` : firstSentence;
|
|
121
|
+
return skillSummary(await res.text());
|
|
186
122
|
} catch {
|
|
187
123
|
return "";
|
|
188
124
|
}
|
|
@@ -199,7 +135,7 @@ async function installPublicSkills(opts = {}) {
|
|
|
199
135
|
...selection
|
|
200
136
|
];
|
|
201
137
|
if (opts.dryRun) return runInstall(remote, opts);
|
|
202
|
-
const checkout = await clonePublicSkills(
|
|
138
|
+
const checkout = await clonePublicSkills();
|
|
203
139
|
if (!checkout) return runInstall(remote, opts);
|
|
204
140
|
try {
|
|
205
141
|
normalizeSkillsDir(join(checkout, "skills"));
|
|
@@ -220,7 +156,7 @@ async function installPublicSkills(opts = {}) {
|
|
|
220
156
|
});
|
|
221
157
|
}
|
|
222
158
|
}
|
|
223
|
-
async function clonePublicSkills(
|
|
159
|
+
async function clonePublicSkills() {
|
|
224
160
|
const dir = mkdtempSync(join(tmpdir(), "superwall-skills-"));
|
|
225
161
|
const { code } = await spawnStream({
|
|
226
162
|
bin: "git",
|
|
@@ -234,7 +170,7 @@ async function clonePublicSkills(cwd) {
|
|
|
234
170
|
`https://github.com/${SUPERWALL_SKILLS_SOURCE}.git`,
|
|
235
171
|
dir
|
|
236
172
|
],
|
|
237
|
-
cwd:
|
|
173
|
+
cwd: process.cwd(),
|
|
238
174
|
onStdoutLine: () => {}
|
|
239
175
|
}).catch(() => ({ code: 1 }));
|
|
240
176
|
if (code === 0 && existsSync(join(dir, "skills"))) return dir;
|
|
@@ -260,9 +196,10 @@ function normalizeSkillFrontmatter(md) {
|
|
|
260
196
|
const end = lines.indexOf("---", 1);
|
|
261
197
|
if (end < 0) return md;
|
|
262
198
|
for (let i = 1; i < end; i++) {
|
|
263
|
-
const match = lines[i]
|
|
264
|
-
|
|
265
|
-
const
|
|
199
|
+
const match = lines[i]?.match(/^([A-Za-z0-9_-]+):[ \t]+(.+?)\s*$/);
|
|
200
|
+
const key = match?.[1];
|
|
201
|
+
const value = match?.[2];
|
|
202
|
+
if (key === void 0 || value === void 0) continue;
|
|
266
203
|
if (/^["']/.test(value) || /^[|>][+-]?\d*$/.test(value)) continue;
|
|
267
204
|
if (/: |\s#/.test(value) || /^[`@%&*!?{}[\],]/.test(value) || value.endsWith(":")) lines[i] = `${key}: ${JSON.stringify(value)}`;
|
|
268
205
|
}
|
|
@@ -290,9 +227,9 @@ async function runInstall(args, opts) {
|
|
|
290
227
|
const { code } = await spawnStream({
|
|
291
228
|
bin: "npx",
|
|
292
229
|
args,
|
|
293
|
-
cwd:
|
|
294
|
-
onStdoutLine: (
|
|
295
|
-
onStderrLine: (
|
|
230
|
+
cwd: process.cwd(),
|
|
231
|
+
onStdoutLine: () => {},
|
|
232
|
+
onStderrLine: () => {}
|
|
296
233
|
});
|
|
297
234
|
return {
|
|
298
235
|
ok: code === 0,
|
|
@@ -306,7 +243,7 @@ function checkSkillsSync(sync, cliVersion, ref, now) {
|
|
|
306
243
|
if (!Number.isFinite(syncedAt)) return "stale";
|
|
307
244
|
return now - syncedAt > SHA_CHECK_INTERVAL_MS ? "verify" : "fresh";
|
|
308
245
|
}
|
|
309
|
-
async function
|
|
246
|
+
async function selectSourceSha() {
|
|
310
247
|
try {
|
|
311
248
|
const res = await fetch(`https://api.github.com/repos/${SUPERWALL_SKILLS_SOURCE}/commits/${SKILLS_REF()}`, {
|
|
312
249
|
headers: { accept: "application/vnd.github+json" },
|
|
@@ -320,14 +257,14 @@ async function fetchSourceSha() {
|
|
|
320
257
|
}
|
|
321
258
|
}
|
|
322
259
|
async function skillsOutOfDate() {
|
|
323
|
-
const sync =
|
|
260
|
+
const sync = readSkillsSync();
|
|
324
261
|
const check = checkSkillsSync(sync, VERSION, SKILLS_REF(), Date.now());
|
|
325
|
-
if (check === "stale") return true;
|
|
326
|
-
if (check === "fresh"
|
|
327
|
-
const head = await
|
|
262
|
+
if (!sync || check === "stale") return true;
|
|
263
|
+
if (check === "fresh") return false;
|
|
264
|
+
const head = await selectSourceSha();
|
|
328
265
|
if (!head) return false;
|
|
329
266
|
if (head !== sync.sourceSha) return true;
|
|
330
|
-
|
|
267
|
+
writeSkillsSync({
|
|
331
268
|
...sync,
|
|
332
269
|
syncedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
333
270
|
});
|
|
@@ -343,23 +280,21 @@ async function syncSkills(opts = {}) {
|
|
|
343
280
|
ok,
|
|
344
281
|
current: pub.ok
|
|
345
282
|
});
|
|
346
|
-
if (ok && pub.ok)
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
283
|
+
if (ok && pub.ok) {
|
|
284
|
+
const sourceSha = await selectSourceSha();
|
|
285
|
+
writeSkillsSync({
|
|
286
|
+
cliVersion: VERSION,
|
|
287
|
+
syncedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
288
|
+
sourceSha: sourceSha ?? void 0,
|
|
289
|
+
ref: SKILLS_REF()
|
|
290
|
+
});
|
|
291
|
+
}
|
|
352
292
|
}
|
|
353
293
|
return {
|
|
354
294
|
ok,
|
|
355
295
|
commands: [bundled.command, pub.command]
|
|
356
296
|
};
|
|
357
297
|
}
|
|
358
|
-
/**
|
|
359
|
-
* Install or refresh the skills with a spinner. `required` always installs and
|
|
360
|
-
* throws on failure (fresh integrations must ship with skills); otherwise this
|
|
361
|
-
* is a quiet refresh that no-ops when the last sync is current.
|
|
362
|
-
*/
|
|
363
298
|
async function ensureSkillsCurrent(required = false, trigger = "workflow") {
|
|
364
299
|
if (!required && !await skillsOutOfDate()) return;
|
|
365
300
|
const spin = ui.spinner();
|
|
@@ -368,6 +303,49 @@ async function ensureSkillsCurrent(required = false, trigger = "workflow") {
|
|
|
368
303
|
spin.stop(ok ? required ? "Superwall skills installed" : "Superwall skills up to date" : "Skill install skipped");
|
|
369
304
|
if (required && !ok) throw new Error("The integration completed, but the Superwall skills could not be installed.");
|
|
370
305
|
}
|
|
306
|
+
async function runSkills(ctx, { flags }) {
|
|
307
|
+
ui.intro("Superwall agent skills");
|
|
308
|
+
const named = flags.skill.filter(Boolean);
|
|
309
|
+
let skills = named.length ? named : void 0;
|
|
310
|
+
const { dryRun } = ctx;
|
|
311
|
+
const { force, yes } = flags;
|
|
312
|
+
const interactive = ctx.interactive && !yes;
|
|
313
|
+
if (!skills && !dryRun && !force) {
|
|
314
|
+
if (!await withSpinner("Checking your skills", skillsOutOfDate)) {
|
|
315
|
+
ui.success("Your Superwall skills are already up to date.");
|
|
316
|
+
ui.outro("Run `superwall skills --force` to reinstall.");
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
if (!skills && !dryRun && interactive) {
|
|
321
|
+
const available = await withSpinner(`Fetching skills from ${SKILLS_INSTALL_SOURCE()}`, listPublicSkills);
|
|
322
|
+
const picked = await ui.multiselect({
|
|
323
|
+
message: `Which skills from ${SKILLS_INSTALL_SOURCE()}? (installs globally)`,
|
|
324
|
+
options: available.map((s) => ({
|
|
325
|
+
value: s.name,
|
|
326
|
+
label: s.name,
|
|
327
|
+
hint: s.summary
|
|
328
|
+
})),
|
|
329
|
+
initialValues: available.map((s) => s.name)
|
|
330
|
+
});
|
|
331
|
+
if (picked === null || picked.length === 0) {
|
|
332
|
+
ui.warn("Nothing selected.");
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
skills = picked.length === available.length ? void 0 : picked;
|
|
336
|
+
} else if (skills?.length) ui.info(`Installing \`${skills.join("`, `")}\` from ${SKILLS_INSTALL_SOURCE()}`);
|
|
337
|
+
else ui.info(`Installing every skill from ${SKILLS_INSTALL_SOURCE()}`);
|
|
338
|
+
const spin = ui.spinner();
|
|
339
|
+
spin.start(dryRun ? "Resolving" : "Installing skills globally");
|
|
340
|
+
const { ok, commands } = await syncSkills({
|
|
341
|
+
skills,
|
|
342
|
+
dryRun
|
|
343
|
+
});
|
|
344
|
+
spin.stop(dryRun ? "Dry run" : ok ? "Skills installed for every detected agent" : "Install failed");
|
|
345
|
+
if (dryRun) for (const command of commands) ui.info(command);
|
|
346
|
+
ui.outro(ok ? `**Done.** Try: ask your agent to "review my Superwall setup".` : "Something went wrong - try again, or check that `npx` is available.");
|
|
347
|
+
if (!ok) throw new Error("Skill installation failed. Check that `npx` is available and try again.");
|
|
348
|
+
}
|
|
371
349
|
|
|
372
350
|
//#endregion
|
|
373
|
-
export {
|
|
351
|
+
export { bundledSkills as a, knownSkills as c, readBundledSkill as d, runSkills as f, SUPERWALL_SKILLS_SOURCE as i, normalizeSkillFrontmatter as l, skillsRefFor as m, SKILLS_INSTALL_SOURCE as n, checkSkillsSync as o, skillSummary as p, SKILLS_REF as r, ensureSkillsCurrent as s, PLAYBOOKS as t, normalizeSkillsDir as u };
|
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
import { promisify } from "node:util";
|
|
2
|
-
import { appendFileSync } from "node:fs";
|
|
3
1
|
import { execFile, spawn } from "node:child_process";
|
|
2
|
+
import { appendFileSync } from "node:fs";
|
|
4
3
|
import { createInterface } from "node:readline";
|
|
4
|
+
import { promisify } from "node:util";
|
|
5
5
|
|
|
6
|
-
//#region src/core/agent/drivers/spawn.ts
|
|
6
|
+
//#region src/core/workflows/agent/drivers/spawn.ts
|
|
7
7
|
const execFileAsync = promisify(execFile);
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
if (!
|
|
8
|
+
function writeTranscript(line) {
|
|
9
|
+
const transcript = process.env.SW_BENCH_TRANSCRIPT;
|
|
10
|
+
if (!transcript) return;
|
|
11
11
|
try {
|
|
12
|
-
appendFileSync(
|
|
13
|
-
} catch {
|
|
12
|
+
appendFileSync(transcript, line + "\n");
|
|
13
|
+
} catch {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
14
16
|
}
|
|
15
17
|
async function readVersion(bin) {
|
|
16
18
|
try {
|
|
@@ -37,7 +39,6 @@ function spawnStream(opts) {
|
|
|
37
39
|
return new Promise((resolve, reject) => {
|
|
38
40
|
const child = spawn(opts.bin, opts.args, {
|
|
39
41
|
cwd: opts.cwd,
|
|
40
|
-
env: opts.env ?? process.env,
|
|
41
42
|
signal: opts.signal,
|
|
42
43
|
stdio: [
|
|
43
44
|
"ignore",
|
|
@@ -47,12 +48,13 @@ function spawnStream(opts) {
|
|
|
47
48
|
});
|
|
48
49
|
createInterface({ input: child.stdout }).on("line", (line) => {
|
|
49
50
|
if (line.length) {
|
|
50
|
-
|
|
51
|
+
writeTranscript(line);
|
|
51
52
|
opts.onStdoutLine(line);
|
|
52
53
|
}
|
|
53
54
|
});
|
|
54
|
-
|
|
55
|
-
|
|
55
|
+
const { onStderrLine } = opts;
|
|
56
|
+
if (onStderrLine) createInterface({ input: child.stderr }).on("line", (line) => {
|
|
57
|
+
if (line.length) onStderrLine(line);
|
|
56
58
|
});
|
|
57
59
|
child.on("error", (e) => {
|
|
58
60
|
if (e.name === "AbortError") {
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
import { r as NotLoggedInError } from "./token-DaxQgQkv.js";
|
|
2
|
+
import { i as writeJson, n as createCommandOutput } from "./output-Ggzq5_-t.js";
|
|
3
|
+
import { a as CHANNEL } from "./environment-eBXjELoN.js";
|
|
4
|
+
import { t as ApiError } from "./client-BL0f_yGf.js";
|
|
5
|
+
import { n as ui, r as useRenderer } from "./ui-D_qf3Gvw.js";
|
|
6
|
+
import pc from "picocolors";
|
|
7
|
+
|
|
8
|
+
//#region src/program/host.ts
|
|
9
|
+
let installed;
|
|
10
|
+
function useHost(host) {
|
|
11
|
+
installed = host;
|
|
12
|
+
}
|
|
13
|
+
function currentHost() {
|
|
14
|
+
if (!installed) throw new Error("No host is installed: the terminal or the MCP server installs one before a command runs.");
|
|
15
|
+
return installed;
|
|
16
|
+
}
|
|
17
|
+
function readInput(path) {
|
|
18
|
+
return currentHost().readInput(path);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
//#endregion
|
|
22
|
+
//#region src/program/lifecycle.ts
|
|
23
|
+
function textOf(value) {
|
|
24
|
+
if (typeof value === "number") return String(value);
|
|
25
|
+
return typeof value === "string" && value.trim() !== "" ? value.trim() : void 0;
|
|
26
|
+
}
|
|
27
|
+
async function runLifecycle(description, input, runtime, work) {
|
|
28
|
+
const host = {
|
|
29
|
+
...currentHost(),
|
|
30
|
+
...runtime
|
|
31
|
+
};
|
|
32
|
+
const flags = input.flags ?? {};
|
|
33
|
+
const json = input.json === true;
|
|
34
|
+
const outputMode = json ? "json" : host.nonInteractive ? "text" : "rich";
|
|
35
|
+
const interactive = description.prompts && !json && input.interactive !== false && !host.nonInteractive;
|
|
36
|
+
const installDir = host.installDir(textOf(flags.installDir));
|
|
37
|
+
const ui$1 = useRenderer(host.renderer(outputMode));
|
|
38
|
+
const { stdout } = host;
|
|
39
|
+
const output = createCommandOutput(outputMode, ui$1, { stdout });
|
|
40
|
+
if (json && !description.json) {
|
|
41
|
+
writeJson(stdout, { error: {
|
|
42
|
+
code: "json_not_supported",
|
|
43
|
+
message: `${description.name} does not support --json.`
|
|
44
|
+
} });
|
|
45
|
+
host.fail();
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const startedAt = Date.now();
|
|
49
|
+
const base = {
|
|
50
|
+
command: description.name,
|
|
51
|
+
auth: description.auth,
|
|
52
|
+
json,
|
|
53
|
+
prompts: interactive,
|
|
54
|
+
dry_run: flags.dryRun === true,
|
|
55
|
+
skill: flags.skill === true
|
|
56
|
+
};
|
|
57
|
+
ui$1.start();
|
|
58
|
+
const offInterrupt = ui$1.onInterrupt?.(() => {
|
|
59
|
+
ui$1.stop();
|
|
60
|
+
process.stderr.write("\n✗ Cancelled.\n");
|
|
61
|
+
process.exit(130);
|
|
62
|
+
});
|
|
63
|
+
host.starting(ui$1, outputMode);
|
|
64
|
+
host.track("command started", base);
|
|
65
|
+
try {
|
|
66
|
+
const api = resolveApi(description.auth, host.api);
|
|
67
|
+
if (description.auth !== "none") base.logged_in = api !== void 0;
|
|
68
|
+
await work({
|
|
69
|
+
ui: ui$1,
|
|
70
|
+
output,
|
|
71
|
+
outputMode,
|
|
72
|
+
interactive,
|
|
73
|
+
installDir,
|
|
74
|
+
json,
|
|
75
|
+
dryRun: flags.dryRun === true,
|
|
76
|
+
target: {
|
|
77
|
+
app: textOf(flags.app),
|
|
78
|
+
project: textOf(flags.project)
|
|
79
|
+
},
|
|
80
|
+
fail: host.fail,
|
|
81
|
+
...api ? { api } : {}
|
|
82
|
+
});
|
|
83
|
+
host.track("command finished", {
|
|
84
|
+
...base,
|
|
85
|
+
status: "success",
|
|
86
|
+
duration_ms: Date.now() - startedAt
|
|
87
|
+
});
|
|
88
|
+
} catch (error) {
|
|
89
|
+
renderError(ui$1, outputMode, stdout, error);
|
|
90
|
+
host.fail();
|
|
91
|
+
const { code, status } = normalizeError(error);
|
|
92
|
+
host.track("command finished", {
|
|
93
|
+
...base,
|
|
94
|
+
status: "error",
|
|
95
|
+
error_code: code,
|
|
96
|
+
...status === void 0 ? {} : { http_status: status },
|
|
97
|
+
duration_ms: Date.now() - startedAt
|
|
98
|
+
});
|
|
99
|
+
} finally {
|
|
100
|
+
offInterrupt?.();
|
|
101
|
+
if (outputMode === "rich" && host.waitForPaint) await new Promise((done) => setTimeout(done, 50));
|
|
102
|
+
ui$1.stop();
|
|
103
|
+
host.finishing(stdout, outputMode, description.name);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
function resolveApi(policy, factory) {
|
|
107
|
+
if (policy === "required") return factory();
|
|
108
|
+
if (policy === "optional") try {
|
|
109
|
+
return factory();
|
|
110
|
+
} catch (error) {
|
|
111
|
+
if (error instanceof NotLoggedInError) return void 0;
|
|
112
|
+
throw error;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
function renderError(ui$1, mode, stdout, error) {
|
|
116
|
+
const { code, message, status } = normalizeError(error);
|
|
117
|
+
if (mode === "json") {
|
|
118
|
+
writeJson(stdout, { error: {
|
|
119
|
+
code,
|
|
120
|
+
message,
|
|
121
|
+
...status === void 0 ? {} : { status }
|
|
122
|
+
} });
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
ui$1.error([message, ...errorAside(error)].join("\n"));
|
|
126
|
+
}
|
|
127
|
+
function errorAside(error) {
|
|
128
|
+
const aside = [];
|
|
129
|
+
if (error instanceof ApiError) {
|
|
130
|
+
if (error.hint) aside.push(error.hint);
|
|
131
|
+
if (error.detail.docUrl) aside.push(error.detail.docUrl);
|
|
132
|
+
if (!error.envelope) aside.push(error.request);
|
|
133
|
+
}
|
|
134
|
+
return aside.map((line) => pc.dim(line));
|
|
135
|
+
}
|
|
136
|
+
function normalizeError(error) {
|
|
137
|
+
if (error instanceof NotLoggedInError) return {
|
|
138
|
+
code: "not_logged_in",
|
|
139
|
+
message: "You aren't logged in. Run `superwall login` first."
|
|
140
|
+
};
|
|
141
|
+
if (error instanceof UsageError) return {
|
|
142
|
+
code: "invalid_arguments",
|
|
143
|
+
message: error.message
|
|
144
|
+
};
|
|
145
|
+
if (error instanceof ApiError) return {
|
|
146
|
+
code: "api_error",
|
|
147
|
+
message: error.message,
|
|
148
|
+
status: error.status
|
|
149
|
+
};
|
|
150
|
+
return {
|
|
151
|
+
code: "command_error",
|
|
152
|
+
message: error instanceof Error ? error.message : String(error)
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
//#endregion
|
|
157
|
+
//#region src/program/command.ts
|
|
158
|
+
function onChannel(specs) {
|
|
159
|
+
return Object.fromEntries(Object.entries(specs).filter(([, spec]) => spec.channel === void 0 || spec.channel === CHANNEL()));
|
|
160
|
+
}
|
|
161
|
+
function summaryOf(command) {
|
|
162
|
+
return command.summaryOn?.[CHANNEL()] ?? command.summary;
|
|
163
|
+
}
|
|
164
|
+
function examplesOf(command) {
|
|
165
|
+
return command.examples.filter(([, , channel]) => channel === void 0 || channel === CHANNEL());
|
|
166
|
+
}
|
|
167
|
+
var UsageError = class extends Error {
|
|
168
|
+
constructor(message, command) {
|
|
169
|
+
super(message);
|
|
170
|
+
this.command = command;
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
function flagName(key) {
|
|
174
|
+
const kebab = key.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);
|
|
175
|
+
return kebab.length === 1 ? `-${kebab}` : `--${kebab}`;
|
|
176
|
+
}
|
|
177
|
+
function readFlag(key, spec, raw) {
|
|
178
|
+
const value = raw ?? spec.default;
|
|
179
|
+
if (spec.type === "boolean") return value === true;
|
|
180
|
+
if (spec.type === "list") {
|
|
181
|
+
if (value === void 0 || value === null) return [];
|
|
182
|
+
return (Array.isArray(value) ? value : [value]).map(String);
|
|
183
|
+
}
|
|
184
|
+
if (value === "" && spec.bare) return "";
|
|
185
|
+
if (value === void 0 || value === null || value === "") return void 0;
|
|
186
|
+
if (spec.type === "number") {
|
|
187
|
+
const number = Number(value);
|
|
188
|
+
if (!Number.isFinite(number)) throw new UsageError(`${flagName(key)} takes a number, not "${String(value)}".`);
|
|
189
|
+
return number;
|
|
190
|
+
}
|
|
191
|
+
const text = spec.verbatim ? String(value) : String(value).trim();
|
|
192
|
+
if (text.trim() === "") return void 0;
|
|
193
|
+
if (spec.choices && !spec.choices.includes(text)) throw new UsageError(`${flagName(key)} takes one of: ${spec.choices.join(", ")} (not "${text}").`);
|
|
194
|
+
return text;
|
|
195
|
+
}
|
|
196
|
+
function readArg(key, spec, raw) {
|
|
197
|
+
if (spec.variadic) {
|
|
198
|
+
const values = raw === void 0 || raw === null ? [] : (Array.isArray(raw) ? raw : [raw]).map(String);
|
|
199
|
+
if (spec.required && values.length === 0) throw new UsageError(`Missing <${key}>.`);
|
|
200
|
+
return values;
|
|
201
|
+
}
|
|
202
|
+
const text = raw === void 0 || raw === null ? "" : String(raw).trim();
|
|
203
|
+
if (text === "") {
|
|
204
|
+
if (spec.required) throw new UsageError(`Missing <${key}>.`);
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
if (spec.choices && !spec.choices.includes(text)) throw new UsageError(`<${key}> is one of: ${spec.choices.join(", ")} (not "${text}").`);
|
|
208
|
+
return text;
|
|
209
|
+
}
|
|
210
|
+
function readValues(specs, raw, read) {
|
|
211
|
+
return Object.fromEntries(Object.entries(specs).map(([key, spec]) => [key, read(key, spec, raw[key])]));
|
|
212
|
+
}
|
|
213
|
+
function defineCommand(spec) {
|
|
214
|
+
const args = spec.args ?? {};
|
|
215
|
+
const flags = spec.flags ?? {};
|
|
216
|
+
const read = (input) => {
|
|
217
|
+
return {
|
|
218
|
+
args: readValues(onChannel(args), input.args ?? {}, readArg),
|
|
219
|
+
flags: readValues(onChannel(flags), input.flags ?? {}, readFlag)
|
|
220
|
+
};
|
|
221
|
+
};
|
|
222
|
+
return {
|
|
223
|
+
kind: "command",
|
|
224
|
+
name: spec.name,
|
|
225
|
+
summary: spec.summary,
|
|
226
|
+
summaryOn: spec.summaryOn,
|
|
227
|
+
details: spec.details,
|
|
228
|
+
examples: spec.examples,
|
|
229
|
+
auth: spec.auth,
|
|
230
|
+
json: spec.json,
|
|
231
|
+
prompts: spec.prompts,
|
|
232
|
+
mcp: spec.mcp,
|
|
233
|
+
channel: spec.channel,
|
|
234
|
+
args,
|
|
235
|
+
flags,
|
|
236
|
+
validate: (input) => {
|
|
237
|
+
read(input);
|
|
238
|
+
},
|
|
239
|
+
execute: (input, runtime = {}) => {
|
|
240
|
+
return runLifecycle(spec, input, runtime, (ctx) => spec.run(ctx, read(input)));
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
function defineCatalog(spec) {
|
|
245
|
+
return {
|
|
246
|
+
kind: "catalog",
|
|
247
|
+
name: spec.name,
|
|
248
|
+
summary: spec.summary,
|
|
249
|
+
summaryOn: spec.summaryOn,
|
|
250
|
+
details: spec.details,
|
|
251
|
+
examples: spec.examples,
|
|
252
|
+
auth: spec.auth,
|
|
253
|
+
json: spec.json,
|
|
254
|
+
prompts: spec.prompts,
|
|
255
|
+
mcp: spec.mcp,
|
|
256
|
+
channel: spec.channel,
|
|
257
|
+
flags: spec.flags ?? {},
|
|
258
|
+
operations: spec.operations,
|
|
259
|
+
help: spec.help,
|
|
260
|
+
tools: spec.tools,
|
|
261
|
+
execute: (input, runtime = {}) => {
|
|
262
|
+
return runLifecycle(spec, input, runtime, (ctx) => {
|
|
263
|
+
return spec.run(ctx, {
|
|
264
|
+
words: input.words ?? [],
|
|
265
|
+
flags: input.flags ?? {}
|
|
266
|
+
});
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
//#endregion
|
|
273
|
+
//#region src/ui/spinner.ts
|
|
274
|
+
async function spinWhile(spin, label, work) {
|
|
275
|
+
spin.start(label);
|
|
276
|
+
try {
|
|
277
|
+
const result = await work();
|
|
278
|
+
spin.stop(label);
|
|
279
|
+
return result;
|
|
280
|
+
} catch (e) {
|
|
281
|
+
spin.stop("Failed");
|
|
282
|
+
throw e;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
function withSpinner(label, work) {
|
|
286
|
+
return spinWhile(ui.spinner(), label, work);
|
|
287
|
+
}
|
|
288
|
+
function apiCall(ctx, label, work) {
|
|
289
|
+
if (ctx.outputMode !== "rich") return work();
|
|
290
|
+
return spinWhile(ctx.ui.spinner(), label, work);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
//#endregion
|
|
294
|
+
export { defineCommand as a, onChannel as c, readInput as d, useHost as f, defineCatalog as i, summaryOf as l, withSpinner as n, examplesOf as o, UsageError as r, flagName as s, apiCall as t, currentHost as u };
|