@cond/simasdk 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/CondSimasdk.podspec +18 -0
  2. package/Package.swift +29 -0
  3. package/README.md +508 -2
  4. package/android/build.gradle +61 -0
  5. package/android/src/main/AndroidManifest.xml +2 -0
  6. package/android/src/main/java/com/simasdk/SimaFirebasePlugin.java +139 -0
  7. package/android/src/main/java/com/simasdk/SimaHapticsPlugin.java +101 -0
  8. package/android/src/main/java/com/simasdk/SimaReviewPlugin.java +48 -0
  9. package/android/src/main/java/com/simasdk/SimaStoragePlugin.java +79 -0
  10. package/dist/ads.cjs +214 -0
  11. package/dist/ads.cjs.map +1 -0
  12. package/dist/ads.d.cts +98 -0
  13. package/dist/ads.d.ts +98 -0
  14. package/dist/ads.js +211 -0
  15. package/dist/ads.js.map +1 -0
  16. package/dist/back-button.cjs +95 -0
  17. package/dist/back-button.cjs.map +1 -0
  18. package/dist/back-button.d.cts +45 -0
  19. package/dist/back-button.d.ts +45 -0
  20. package/dist/back-button.js +88 -0
  21. package/dist/back-button.js.map +1 -0
  22. package/dist/cli.js +662 -0
  23. package/dist/firebase.cjs +102 -0
  24. package/dist/firebase.cjs.map +1 -0
  25. package/dist/firebase.d.cts +40 -0
  26. package/dist/firebase.d.ts +40 -0
  27. package/dist/firebase.js +99 -0
  28. package/dist/firebase.js.map +1 -0
  29. package/dist/haptics.cjs +81 -0
  30. package/dist/haptics.cjs.map +1 -0
  31. package/dist/haptics.d.cts +51 -0
  32. package/dist/haptics.d.ts +51 -0
  33. package/dist/haptics.js +78 -0
  34. package/dist/haptics.js.map +1 -0
  35. package/dist/index.cjs +233 -0
  36. package/dist/index.cjs.map +1 -0
  37. package/dist/index.d.cts +99 -0
  38. package/dist/index.d.ts +99 -0
  39. package/dist/index.js +226 -0
  40. package/dist/index.js.map +1 -0
  41. package/dist/react.cjs +118 -0
  42. package/dist/react.cjs.map +1 -0
  43. package/dist/react.d.cts +51 -0
  44. package/dist/react.d.ts +51 -0
  45. package/dist/react.js +113 -0
  46. package/dist/react.js.map +1 -0
  47. package/dist/review.cjs +195 -0
  48. package/dist/review.cjs.map +1 -0
  49. package/dist/review.d.cts +76 -0
  50. package/dist/review.d.ts +76 -0
  51. package/dist/review.js +192 -0
  52. package/dist/review.js.map +1 -0
  53. package/dist/shell.cjs +97 -0
  54. package/dist/shell.cjs.map +1 -0
  55. package/dist/shell.d.cts +36 -0
  56. package/dist/shell.d.ts +36 -0
  57. package/dist/shell.js +91 -0
  58. package/dist/shell.js.map +1 -0
  59. package/dist/storage.cjs +140 -0
  60. package/dist/storage.cjs.map +1 -0
  61. package/dist/storage.d.cts +48 -0
  62. package/dist/storage.d.ts +48 -0
  63. package/dist/storage.js +136 -0
  64. package/dist/storage.js.map +1 -0
  65. package/ios/Sources/SimasdkPlugin/SimaFirebasePlugin.swift +188 -0
  66. package/ios/Sources/SimasdkPlugin/SimaHapticsPlugin.swift +61 -0
  67. package/ios/Sources/SimasdkPlugin/SimaReviewPlugin.swift +40 -0
  68. package/ios/Sources/SimasdkPlugin/SimaStoragePlugin.swift +58 -0
  69. package/package.json +118 -4
  70. package/skills/simasdk/SKILL.md +189 -0
package/dist/cli.js ADDED
@@ -0,0 +1,662 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/cli.ts
4
+ import fs from "fs";
5
+ import os from "os";
6
+ import path from "path";
7
+ import { fileURLToPath } from "url";
8
+ function readTextIfExists(filePath) {
9
+ try {
10
+ if (!fs.existsSync(filePath)) return null;
11
+ return fs.readFileSync(filePath, "utf8");
12
+ } catch {
13
+ return null;
14
+ }
15
+ }
16
+ function readJsonIfExists(filePath) {
17
+ const raw = readTextIfExists(filePath);
18
+ if (!raw) return null;
19
+ try {
20
+ return JSON.parse(raw);
21
+ } catch {
22
+ return null;
23
+ }
24
+ }
25
+ function extractPlistString(plistXml, key) {
26
+ const regex = new RegExp(`<key>${key}</key>\\s*<string>([^<]+)</string>`);
27
+ const match = plistXml.match(regex);
28
+ return match?.[1]?.trim() ?? null;
29
+ }
30
+ function extractPlistBool(plistXml, key) {
31
+ const regex = new RegExp(`<key>${key}</key>\\s*<(true|false)\\s*/>`);
32
+ const match = plistXml.match(regex);
33
+ if (!match) return null;
34
+ return match[1] === "true";
35
+ }
36
+ function extractCapAppId(cwd) {
37
+ const jsonCfg = readJsonIfExists(path.join(cwd, "capacitor.config.json"));
38
+ if (jsonCfg?.appId) return jsonCfg.appId;
39
+ for (const name of ["capacitor.config.ts", "capacitor.config.js", "capacitor.config.mjs"]) {
40
+ const raw = readTextIfExists(path.join(cwd, name));
41
+ if (!raw) continue;
42
+ const match = raw.match(/appId\s*:\s*['"`]([^'"`]+)['"`]/);
43
+ if (match?.[1]) return match[1];
44
+ }
45
+ return null;
46
+ }
47
+ function runDoctor(cwd) {
48
+ const checks = [];
49
+ const pkg = readJsonIfExists(path.join(cwd, "package.json"));
50
+ const allDeps = { ...pkg?.dependencies ?? {}, ...pkg?.devDependencies ?? {} };
51
+ const capVersion = allDeps["@capacitor/core"] ?? null;
52
+ if (!pkg) {
53
+ checks.push({
54
+ id: "package-json",
55
+ status: "fail",
56
+ message: "No package.json found in current directory.",
57
+ hint: "Run `simasdk doctor` from your Capacitor app root."
58
+ });
59
+ return { cwd, ok: false, capacitorVersion: null, hasIos: false, hasAndroid: false, checks };
60
+ }
61
+ if (!capVersion) {
62
+ checks.push({
63
+ id: "capacitor-core",
64
+ status: "fail",
65
+ message: "@capacitor/core is not listed in package.json.",
66
+ hint: "Install @capacitor/core (^7.0.0 or ^8.0.0)."
67
+ });
68
+ } else {
69
+ const majorMatch = capVersion.match(/(\d+)/);
70
+ const major = majorMatch ? Number(majorMatch[1]) : null;
71
+ if (major === 7 || major === 8) {
72
+ checks.push({
73
+ id: "capacitor-core",
74
+ status: "pass",
75
+ message: `@capacitor/core ${capVersion} is supported (Capacitor 7 & 8).`
76
+ });
77
+ } else {
78
+ checks.push({
79
+ id: "capacitor-core",
80
+ status: "warn",
81
+ message: `@capacitor/core ${capVersion} detected; simasdk supports Capacitor 7 and 8.`
82
+ });
83
+ }
84
+ }
85
+ const simasdkVersion = allDeps["@cond/simasdk"] ?? allDeps["simasdk"];
86
+ if (simasdkVersion) {
87
+ checks.push({
88
+ id: "simasdk-installed",
89
+ status: "pass",
90
+ message: `@cond/simasdk (${simasdkVersion}) is installed.`
91
+ });
92
+ } else {
93
+ checks.push({
94
+ id: "simasdk-installed",
95
+ status: "warn",
96
+ message: "@cond/simasdk is not yet listed in package.json.",
97
+ hint: "Run `npm install @cond/simasdk && npx cap sync`."
98
+ });
99
+ }
100
+ if (allDeps["firebase"]) {
101
+ checks.push({
102
+ id: "firebase-web-sdk",
103
+ status: "warn",
104
+ message: "Firebase Web SDK (`firebase`) is present in package.json.",
105
+ hint: "Do not use Firebase Web SDK for mobile analytics; use native FirebaseAnalytics + `simasdk/firebase`."
106
+ });
107
+ }
108
+ const appId = extractCapAppId(cwd);
109
+ const hasIos = fs.existsSync(path.join(cwd, "ios"));
110
+ const hasAndroid = fs.existsSync(path.join(cwd, "android"));
111
+ if (!hasIos && !hasAndroid) {
112
+ checks.push({
113
+ id: "native-platforms",
114
+ status: "info",
115
+ message: "No ios/ or android/ directory found yet.",
116
+ hint: "Run `npx cap add ios` and/or `npx cap add android`."
117
+ });
118
+ }
119
+ if (hasIos) {
120
+ const iosCapCfg = readJsonIfExists(
121
+ path.join(cwd, "ios/App/App/capacitor.config.json")
122
+ );
123
+ const classList = iosCapCfg?.packageClassList ?? [];
124
+ const expectedIosPlugins = [
125
+ "SimaReviewPlugin",
126
+ "SimaFirebasePlugin",
127
+ "SimaHapticsPlugin",
128
+ "SimaStoragePlugin"
129
+ ];
130
+ const missingIosPlugins = expectedIosPlugins.filter((p) => !classList.includes(p));
131
+ if (simasdkVersion) {
132
+ if (missingIosPlugins.length === 0) {
133
+ checks.push({
134
+ id: "ios-plugin-sync",
135
+ status: "pass",
136
+ message: "All 4 simasdk iOS plugins are synced in ios/App/App/capacitor.config.json."
137
+ });
138
+ } else {
139
+ checks.push({
140
+ id: "ios-plugin-sync",
141
+ status: "fail",
142
+ message: `Missing iOS plugins in capacitor.config.json: ${missingIosPlugins.join(", ")}.`,
143
+ hint: "Run `npx cap sync ios`."
144
+ });
145
+ }
146
+ }
147
+ const plistPath = path.join(cwd, "ios/App/App/GoogleService-Info.plist");
148
+ const plistRaw = readTextIfExists(plistPath);
149
+ if (!plistRaw) {
150
+ checks.push({
151
+ id: "ios-firebase-plist",
152
+ status: "info",
153
+ message: "No ios/App/App/GoogleService-Info.plist found (OK if not using Firebase Analytics)."
154
+ });
155
+ } else {
156
+ checks.push({
157
+ id: "ios-firebase-plist",
158
+ status: "pass",
159
+ message: "Found ios/App/App/GoogleService-Info.plist."
160
+ });
161
+ const plistBundleId = extractPlistString(plistRaw, "BUNDLE_ID");
162
+ if (plistBundleId && appId && plistBundleId !== appId) {
163
+ checks.push({
164
+ id: "ios-bundle-id-match",
165
+ status: "fail",
166
+ message: `Bundle ID mismatch: GoogleService-Info.plist has "${plistBundleId}" but capacitor.config has "${appId}".`,
167
+ hint: "Download GoogleService-Info.plist for the exact iOS Bundle ID."
168
+ });
169
+ } else if (plistBundleId) {
170
+ checks.push({
171
+ id: "ios-bundle-id-match",
172
+ status: "pass",
173
+ message: `GoogleService-Info.plist BUNDLE_ID matches (${plistBundleId}).`
174
+ });
175
+ }
176
+ const pbxproj = readTextIfExists(path.join(cwd, "ios/App/App.xcodeproj/project.pbxproj"));
177
+ if (pbxproj) {
178
+ if (pbxproj.includes("GoogleService-Info.plist")) {
179
+ checks.push({
180
+ id: "ios-plist-target",
181
+ status: "pass",
182
+ message: "GoogleService-Info.plist is referenced in App.xcodeproj."
183
+ });
184
+ } else {
185
+ checks.push({
186
+ id: "ios-plist-target",
187
+ status: "fail",
188
+ message: "GoogleService-Info.plist exists on disk but is NOT referenced in App.xcodeproj.",
189
+ hint: "Add GoogleService-Info.plist to the App target in Xcode (Target Membership)."
190
+ });
191
+ }
192
+ const hasFirebaseSpm = pbxproj.includes("FirebaseAnalytics") || (readTextIfExists(path.join(cwd, "ios/App/Podfile")) ?? "").includes("FirebaseAnalytics");
193
+ if (hasFirebaseSpm) {
194
+ checks.push({
195
+ id: "ios-firebase-sdk",
196
+ status: "pass",
197
+ message: "FirebaseAnalytics dependency detected in iOS project."
198
+ });
199
+ } else {
200
+ checks.push({
201
+ id: "ios-firebase-sdk",
202
+ status: "fail",
203
+ message: "GoogleService-Info.plist is present, but FirebaseAnalytics is not linked in Xcode/Podfile.",
204
+ hint: "Add firebase-ios-sdk -> FirebaseAnalytics to the App target in Xcode."
205
+ });
206
+ }
207
+ }
208
+ const appDelegate = readTextIfExists(path.join(cwd, "ios/App/App/AppDelegate.swift"));
209
+ if (appDelegate?.includes("FirebaseApp.configure()")) {
210
+ checks.push({
211
+ id: "ios-appdelegate-configure",
212
+ status: "pass",
213
+ message: "FirebaseApp.configure() found in AppDelegate.swift."
214
+ });
215
+ } else {
216
+ checks.push({
217
+ id: "ios-appdelegate-configure",
218
+ status: "warn",
219
+ message: "FirebaseApp.configure() not found in AppDelegate.swift.",
220
+ hint: "Recommended: call FirebaseApp.configure() in application(_:didFinishLaunchingWithOptions:) for earliest first_open capture."
221
+ });
222
+ }
223
+ const infoPlist = readTextIfExists(path.join(cwd, "ios/App/App/Info.plist"));
224
+ if (infoPlist) {
225
+ const collectionFlag = extractPlistBool(infoPlist, "FIREBASE_ANALYTICS_COLLECTION_ENABLED");
226
+ if (collectionFlag === false) {
227
+ checks.push({
228
+ id: "ios-collection-flag",
229
+ status: "info",
230
+ message: "FIREBASE_ANALYTICS_COLLECTION_ENABLED is false in Info.plist (consent-first mode).",
231
+ hint: "Remember to call sima.setAnalyticsCollectionEnabled(true) after user consent."
232
+ });
233
+ }
234
+ }
235
+ }
236
+ }
237
+ if (hasAndroid) {
238
+ const googleServicesJson = readTextIfExists(path.join(cwd, "android/app/google-services.json"));
239
+ if (!googleServicesJson) {
240
+ checks.push({
241
+ id: "android-firebase-json",
242
+ status: "info",
243
+ message: "No android/app/google-services.json found (OK if not using Firebase Analytics on Android)."
244
+ });
245
+ } else {
246
+ checks.push({
247
+ id: "android-firebase-json",
248
+ status: "pass",
249
+ message: "Found android/app/google-services.json."
250
+ });
251
+ const appGradle = readTextIfExists(path.join(cwd, "android/app/build.gradle")) ?? "";
252
+ if (appGradle.includes("com.google.gms.google-services")) {
253
+ checks.push({
254
+ id: "android-gms-plugin",
255
+ status: "pass",
256
+ message: "com.google.gms.google-services plugin is applied in android/app/build.gradle."
257
+ });
258
+ } else {
259
+ checks.push({
260
+ id: "android-gms-plugin",
261
+ status: "fail",
262
+ message: "google-services.json exists, but com.google.gms.google-services is not applied in android/app/build.gradle."
263
+ });
264
+ }
265
+ if (appGradle.includes("firebase-analytics")) {
266
+ checks.push({
267
+ id: "android-firebase-dep",
268
+ status: "pass",
269
+ message: "firebase-analytics dependency found in android/app/build.gradle."
270
+ });
271
+ } else {
272
+ checks.push({
273
+ id: "android-firebase-dep",
274
+ status: "fail",
275
+ message: "firebase-analytics dependency is missing from android/app/build.gradle.",
276
+ hint: "Add `implementation platform('com.google.firebase:firebase-bom:35.2.0')` and `implementation 'com.google.firebase:firebase-analytics'`."
277
+ });
278
+ }
279
+ const manifest = readTextIfExists(path.join(cwd, "android/app/src/main/AndroidManifest.xml")) ?? "";
280
+ if (manifest.includes("firebase_analytics_collection_enabled") && manifest.includes('android:value="false"')) {
281
+ checks.push({
282
+ id: "android-collection-flag",
283
+ status: "info",
284
+ message: "firebase_analytics_collection_enabled is false in AndroidManifest.xml (consent-first mode)."
285
+ });
286
+ }
287
+ }
288
+ }
289
+ const ok = !checks.some((c) => c.status === "fail");
290
+ return { cwd, ok, capacitorVersion: capVersion, hasIos, hasAndroid, checks };
291
+ }
292
+ function generateStarterContent(options) {
293
+ const lines = [];
294
+ const exportsList = [];
295
+ lines.push("import { createSima } from '@cond/simasdk';");
296
+ if (options.firebase) {
297
+ lines.push("import { firebaseAnalytics } from '@cond/simasdk/firebase';");
298
+ }
299
+ if (options.review) {
300
+ lines.push("import { createReviewPolicy } from '@cond/simasdk/review';");
301
+ }
302
+ if (options.haptics) {
303
+ lines.push("import { createHaptics } from '@cond/simasdk/haptics';");
304
+ }
305
+ if (options.storage) {
306
+ lines.push("import { createStorage } from '@cond/simasdk/storage';");
307
+ }
308
+ if (options.shell) {
309
+ lines.push("import { initShell } from '@cond/simasdk/shell';");
310
+ }
311
+ if (options.backButton) {
312
+ lines.push("import { attachCapacitorBackButton } from '@cond/simasdk/back-button';");
313
+ }
314
+ if (options.ads) {
315
+ lines.push("import { createAdPolicy } from '@cond/simasdk/ads';");
316
+ }
317
+ lines.push("");
318
+ if (options.firebase) {
319
+ lines.push("export const sima = createSima({");
320
+ lines.push(" analytics: firebaseAnalytics(),");
321
+ lines.push(" onError(error) {");
322
+ lines.push(" console.warn('[simasdk]', error.code, error.message);");
323
+ lines.push(" },");
324
+ lines.push("});");
325
+ } else {
326
+ lines.push("export const sima = createSima();");
327
+ }
328
+ exportsList.push("sima");
329
+ if (options.review) {
330
+ lines.push("");
331
+ lines.push("export const review = createReviewPolicy({");
332
+ lines.push(" key: 'primary_success',");
333
+ lines.push(" minimumActions: 3,");
334
+ lines.push(" cooldownDays: 90,");
335
+ lines.push("});");
336
+ exportsList.push("review");
337
+ }
338
+ if (options.haptics) {
339
+ lines.push("");
340
+ lines.push("export const haptics = createHaptics();");
341
+ exportsList.push("haptics");
342
+ }
343
+ if (options.storage) {
344
+ lines.push("");
345
+ lines.push("export const settingsStore = createStorage({ namespace: 'settings', version: 1 });");
346
+ exportsList.push("settingsStore");
347
+ }
348
+ if (options.ads) {
349
+ lines.push("");
350
+ lines.push("export const interstitialAds = createAdPolicy({");
351
+ lines.push(" key: 'main_interstitial',");
352
+ lines.push(" interstitialAdId: {");
353
+ lines.push(" ios: 'ca-app-pub-REPLACE_WITH_IOS_AD_UNIT',");
354
+ lines.push(" android: 'ca-app-pub-REPLACE_WITH_ANDROID_AD_UNIT',");
355
+ lines.push(" },");
356
+ lines.push(" minActionsBeforeFirst: 2,");
357
+ lines.push(" actionsBetweenAds: 3,");
358
+ lines.push(" cooldownSeconds: 90,");
359
+ lines.push("});");
360
+ exportsList.push("interstitialAds");
361
+ }
362
+ if (options.shell || options.backButton) {
363
+ lines.push("");
364
+ lines.push("export async function bootstrapNativeShell() {");
365
+ if (options.shell) {
366
+ lines.push(" await initShell({ statusBarStyle: 'dark', hideSplash: true });");
367
+ }
368
+ if (options.backButton) {
369
+ lines.push(" await attachCapacitorBackButton();");
370
+ }
371
+ lines.push("}");
372
+ }
373
+ lines.push("");
374
+ return lines.join("\n");
375
+ }
376
+ function runInit(options) {
377
+ const target = path.resolve(options.cwd, options.outFile ?? "src/sima.ts");
378
+ const existed = fs.existsSync(target);
379
+ if (existed && !options.force) {
380
+ throw new Error(`File already exists: ${target}. Pass --force to overwrite.`);
381
+ }
382
+ fs.mkdirSync(path.dirname(target), { recursive: true });
383
+ fs.writeFileSync(target, generateStarterContent(options), "utf8");
384
+ return { writtenPath: target, existed };
385
+ }
386
+ function getBundledSkillPath() {
387
+ return fileURLToPath(new URL("../skills/simasdk/SKILL.md", import.meta.url));
388
+ }
389
+ function resolveSkillDestinations(options) {
390
+ const { scope, targets, cwd, homeDir } = options;
391
+ const destinations = [];
392
+ for (const target of targets) {
393
+ if (scope === "local") {
394
+ if (target === "agents") {
395
+ destinations.push(path.join(cwd, ".agents", "skills", "simasdk", "SKILL.md"));
396
+ } else if (target === "claude") {
397
+ destinations.push(path.join(cwd, ".claude", "skills", "simasdk", "SKILL.md"));
398
+ } else if (target === "gemini") {
399
+ destinations.push(path.join(cwd, ".gemini", "skills", "simasdk", "SKILL.md"));
400
+ } else if (target === "cursor") {
401
+ destinations.push(path.join(cwd, ".cursor", "skills", "simasdk", "SKILL.md"));
402
+ }
403
+ } else {
404
+ if (target === "agents") {
405
+ destinations.push(path.join(homeDir, ".agents", "skills", "simasdk", "SKILL.md"));
406
+ } else if (target === "claude") {
407
+ destinations.push(path.join(homeDir, ".claude", "skills", "simasdk", "SKILL.md"));
408
+ } else if (target === "gemini") {
409
+ destinations.push(path.join(homeDir, ".gemini", "config", "skills", "simasdk", "SKILL.md"));
410
+ } else if (target === "cursor") {
411
+ destinations.push(path.join(homeDir, ".cursor", "skills", "simasdk", "SKILL.md"));
412
+ }
413
+ }
414
+ }
415
+ return Array.from(new Set(destinations));
416
+ }
417
+ function runSkillInstall(options) {
418
+ const sourcePath = getBundledSkillPath();
419
+ if (!fs.existsSync(sourcePath)) {
420
+ throw new Error(`Bundled SKILL.md not found at ${sourcePath}`);
421
+ }
422
+ const content = fs.readFileSync(sourcePath, "utf8");
423
+ const targets = options.targets && options.targets.length > 0 ? options.targets : ["agents"];
424
+ const cwd = path.resolve(options.cwd ?? process.cwd());
425
+ const homeDir = path.resolve(options.homeDir ?? os.homedir());
426
+ const destinations = resolveSkillDestinations({
427
+ scope: options.scope,
428
+ targets,
429
+ cwd,
430
+ homeDir
431
+ });
432
+ const writtenPaths = [];
433
+ const skippedPaths = [];
434
+ for (const dest of destinations) {
435
+ if (fs.existsSync(dest) && !options.force) {
436
+ skippedPaths.push(dest);
437
+ continue;
438
+ }
439
+ fs.mkdirSync(path.dirname(dest), { recursive: true });
440
+ fs.writeFileSync(dest, content, "utf8");
441
+ writtenPaths.push(dest);
442
+ }
443
+ return { writtenPaths, skippedPaths };
444
+ }
445
+ function runSkillUninstall(options) {
446
+ const targets = options.targets && options.targets.length > 0 ? options.targets : ["agents"];
447
+ const cwd = path.resolve(options.cwd ?? process.cwd());
448
+ const homeDir = path.resolve(options.homeDir ?? os.homedir());
449
+ const destinations = resolveSkillDestinations({
450
+ scope: options.scope,
451
+ targets,
452
+ cwd,
453
+ homeDir
454
+ });
455
+ const removedPaths = [];
456
+ for (const dest of destinations) {
457
+ if (fs.existsSync(dest)) {
458
+ fs.rmSync(dest, { force: true });
459
+ const skillDir = path.dirname(dest);
460
+ try {
461
+ if (fs.readdirSync(skillDir).length === 0) {
462
+ fs.rmdirSync(skillDir);
463
+ }
464
+ } catch {
465
+ }
466
+ removedPaths.push(dest);
467
+ }
468
+ }
469
+ return { removedPaths };
470
+ }
471
+ function parseSkillTargets(raw) {
472
+ if (!raw || raw === "agents") return ["agents"];
473
+ if (raw === "all") return ["agents", "claude", "gemini", "cursor"];
474
+ const items = raw.split(",").map((s) => s.trim().toLowerCase()).filter(Boolean);
475
+ const valid = [];
476
+ for (const item of items) {
477
+ if (item === "antigravity" || item === "gemini") {
478
+ valid.push("gemini");
479
+ } else if (item === "agents" || item === "claude" || item === "cursor") {
480
+ valid.push(item);
481
+ } else {
482
+ throw new Error(
483
+ `Unknown --target "${item}". Supported: agents, claude, gemini (antigravity), cursor, all.`
484
+ );
485
+ }
486
+ }
487
+ return valid.length > 0 ? valid : ["agents"];
488
+ }
489
+ function useColor() {
490
+ return Boolean(process.stdout.isTTY) && !process.env["NO_COLOR"];
491
+ }
492
+ function badge(status) {
493
+ const c = useColor();
494
+ if (status === "pass") return c ? "\x1B[32mPASS\x1B[0m" : "PASS";
495
+ if (status === "warn") return c ? "\x1B[33mWARN\x1B[0m" : "WARN";
496
+ if (status === "fail") return c ? "\x1B[31mFAIL\x1B[0m" : "FAIL";
497
+ return c ? "\x1B[36mINFO\x1B[0m" : "INFO";
498
+ }
499
+ function printHelp() {
500
+ console.log(`simasdk CLI
501
+
502
+ Usage:
503
+ simasdk doctor [--json] [--cwd <dir>]
504
+ Audit a Capacitor project for simasdk plugin sync, iOS/Android Firebase config,
505
+ Bundle ID mismatches, and consent flags.
506
+
507
+ simasdk init [options]
508
+ Generate a starter src/sima.ts file.
509
+ Options:
510
+ --out <path> Output file path (default: src/sima.ts)
511
+ --firebase Include firebaseAnalytics() adapter
512
+ --review Include createReviewPolicy() (default: true if no flags passed)
513
+ --haptics Include createHaptics()
514
+ --storage Include createStorage()
515
+ --shell Include initShell()
516
+ --back-button Include attachCapacitorBackButton()
517
+ --ads Include createAdPolicy()
518
+ --all Include all modules
519
+ --force Overwrite existing file
520
+
521
+ simasdk skill install [--local | --global] [--target <agents|claude|gemini|cursor|all>] [--force]
522
+ Install the bundled simasdk SKILL.md locally into the project or globally in your home directory.
523
+
524
+ simasdk skill uninstall [--local | --global] [--target <agents|claude|gemini|cursor|all>]
525
+ Remove the installed simasdk SKILL.md.
526
+
527
+ simasdk skill path
528
+ Print the absolute path to the bundled SKILL.md.
529
+
530
+ simasdk --help | --version
531
+ `);
532
+ }
533
+ function parseFlagValue(args, flag) {
534
+ const idx = args.indexOf(flag);
535
+ if (idx === -1 || idx + 1 >= args.length) return void 0;
536
+ return args[idx + 1];
537
+ }
538
+ function main(argv = process.argv.slice(2)) {
539
+ const command = argv[0];
540
+ if (!command || command === "--help" || command === "-h" || command === "help") {
541
+ printHelp();
542
+ return 0;
543
+ }
544
+ if (command === "--version" || command === "-v") {
545
+ const pkgPath = new URL("../package.json", import.meta.url);
546
+ const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
547
+ console.log(pkg.version ?? "0.1.0");
548
+ return 0;
549
+ }
550
+ if (command === "doctor") {
551
+ const cwd = path.resolve(parseFlagValue(argv, "--cwd") ?? process.cwd());
552
+ const asJson = argv.includes("--json");
553
+ const report = runDoctor(cwd);
554
+ if (asJson) {
555
+ console.log(JSON.stringify(report, null, 2));
556
+ } else {
557
+ console.log(`simasdk doctor (${report.cwd})
558
+ `);
559
+ for (const check of report.checks) {
560
+ console.log(` [${badge(check.status)}] ${check.message}`);
561
+ if (check.hint) {
562
+ console.log(` -> ${check.hint}`);
563
+ }
564
+ }
565
+ console.log("");
566
+ console.log(report.ok ? "Result: OK" : "Result: Issues found (see FAIL items above).");
567
+ }
568
+ return report.ok ? 0 : 1;
569
+ }
570
+ if (command === "init") {
571
+ const cwd = path.resolve(parseFlagValue(argv, "--cwd") ?? process.cwd());
572
+ const outFile = parseFlagValue(argv, "--out");
573
+ const all = argv.includes("--all");
574
+ const anySpecific = all || argv.includes("--firebase") || argv.includes("--review") || argv.includes("--haptics") || argv.includes("--storage") || argv.includes("--shell") || argv.includes("--back-button") || argv.includes("--ads");
575
+ try {
576
+ const { writtenPath } = runInit({
577
+ cwd,
578
+ outFile,
579
+ firebase: all || argv.includes("--firebase"),
580
+ review: all || argv.includes("--review") || !anySpecific,
581
+ haptics: all || argv.includes("--haptics"),
582
+ storage: all || argv.includes("--storage"),
583
+ shell: all || argv.includes("--shell"),
584
+ backButton: all || argv.includes("--back-button"),
585
+ ads: all || argv.includes("--ads"),
586
+ force: argv.includes("--force")
587
+ });
588
+ console.log(`Created ${writtenPath}`);
589
+ return 0;
590
+ } catch (err) {
591
+ console.error(err instanceof Error ? err.message : String(err));
592
+ return 1;
593
+ }
594
+ }
595
+ if (command === "skill") {
596
+ const subcommand = argv[1];
597
+ if (subcommand === "path") {
598
+ console.log(getBundledSkillPath());
599
+ return 0;
600
+ }
601
+ const isGlobal = argv.includes("--global") || argv.includes("-g");
602
+ const scope = isGlobal ? "global" : "local";
603
+ const cwd = path.resolve(parseFlagValue(argv, "--cwd") ?? process.cwd());
604
+ if (subcommand === "install") {
605
+ try {
606
+ const targets = parseSkillTargets(parseFlagValue(argv, "--target"));
607
+ const { writtenPaths, skippedPaths } = runSkillInstall({
608
+ scope,
609
+ targets,
610
+ cwd,
611
+ force: argv.includes("--force")
612
+ });
613
+ for (const p of writtenPaths) {
614
+ console.log(`Installed skill (${scope}): ${p}`);
615
+ }
616
+ for (const p of skippedPaths) {
617
+ console.log(`Skipped existing skill (pass --force to overwrite): ${p}`);
618
+ }
619
+ return 0;
620
+ } catch (err) {
621
+ console.error(err instanceof Error ? err.message : String(err));
622
+ return 1;
623
+ }
624
+ }
625
+ if (subcommand === "uninstall" || subcommand === "remove") {
626
+ try {
627
+ const targets = parseSkillTargets(parseFlagValue(argv, "--target"));
628
+ const { removedPaths } = runSkillUninstall({ scope, targets, cwd });
629
+ if (removedPaths.length === 0) {
630
+ console.log(`No installed simasdk skill found (${scope}).`);
631
+ } else {
632
+ for (const p of removedPaths) {
633
+ console.log(`Removed skill (${scope}): ${p}`);
634
+ }
635
+ }
636
+ return 0;
637
+ } catch (err) {
638
+ console.error(err instanceof Error ? err.message : String(err));
639
+ return 1;
640
+ }
641
+ }
642
+ console.error("Usage: simasdk skill <install|uninstall|path> [--local|--global] [--target <agents|claude|gemini|cursor|all>]");
643
+ return 1;
644
+ }
645
+ console.error(`Unknown command: ${command}`);
646
+ printHelp();
647
+ return 1;
648
+ }
649
+ var isDirectRun = typeof process !== "undefined" && process.argv[1] && (process.argv[1].endsWith("cli.js") || process.argv[1].endsWith("simasdk"));
650
+ if (isDirectRun) {
651
+ process.exitCode = main();
652
+ }
653
+ export {
654
+ generateStarterContent,
655
+ getBundledSkillPath,
656
+ main,
657
+ resolveSkillDestinations,
658
+ runDoctor,
659
+ runInit,
660
+ runSkillInstall,
661
+ runSkillUninstall
662
+ };