sagacloud 0.1.1 → 0.3.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.
@@ -0,0 +1,13 @@
1
+ {
2
+ "name": "sagacloud",
3
+ "version": "0.3.0",
4
+ "description": "Deploy and manage Static, SPA, and Node.js apps on SagaCloud via the sagacloud CLI.",
5
+ "author": {
6
+ "name": "SagaSoft",
7
+ "url": "https://app.sagasoft.xyz"
8
+ },
9
+ "homepage": "https://app.sagasoft.xyz",
10
+ "repository": "https://gitlab.com/sagasoft/sagacloud-cli",
11
+ "license": "MIT",
12
+ "skills": "./skills/"
13
+ }
package/README.md CHANGED
@@ -65,6 +65,7 @@ For CI/CD pipelines (GitHub Actions / GitLab CI), set `SAGACLOUD_TOKEN` as a sec
65
65
  | `sagacloud cancel` | Cancel active queued/running deployment |
66
66
  | `sagacloud delete` | Delete a hosted site and unlink local project |
67
67
  | `sagacloud ci init` | Generate `.github/workflows/sagacloud.yml` |
68
+ | `sagacloud skills install` | Install the SagaCloud Agent Skill (`SKILL.md`) for Antigravity, Claude Code, Codex, and Cursor |
68
69
 
69
70
  ## Example `sagacloud.jsonc`
70
71
 
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  // src/index.ts
4
4
  import { Command } from "commander";
5
- import pc7 from "picocolors";
5
+ import pc8 from "picocolors";
6
6
 
7
7
  // src/commands/auth.ts
8
8
  import crypto from "crypto";
@@ -21,8 +21,17 @@ import { parse as parseJsonc, printParseErrorCode } from "jsonc-parser";
21
21
  import { z } from "zod";
22
22
  var DEFAULT_API_BASE_URL = "https://app.sagasoft.xyz";
23
23
  var DEFAULT_PANEL_BASE_URL = "https://app.sagasoft.xyz";
24
+ var SagaCloudDomainEntrySchema = z.union([
25
+ z.string().min(1),
26
+ z.object({
27
+ fqdn: z.string().min(1),
28
+ primary: z.boolean().optional(),
29
+ mode: z.enum(["auto", "saga_root", "saga_subdomain", "custom_external"]).optional()
30
+ })
31
+ ]);
24
32
  var SagaCloudJsoncSchema = z.object({
25
33
  $schema: z.string().optional(),
34
+ app_name: z.string().min(1).optional(),
26
35
  name: z.string().min(1).optional(),
27
36
  site_id: z.string().optional(),
28
37
  type: z.enum(["static", "spa", "php", "node", "nextjs"]).optional(),
@@ -33,9 +42,25 @@ var SagaCloudJsoncSchema = z.object({
33
42
  start_command: z.string().optional(),
34
43
  port: z.union([z.number().int().min(1).max(65535), z.string()]).optional(),
35
44
  spa_fallback: z.boolean().optional(),
36
- domains: z.array(z.string()).optional(),
45
+ healthcheck_path: z.string().optional(),
46
+ domains: z.array(SagaCloudDomainEntrySchema).optional(),
47
+ cdn: z.object({
48
+ enabled: z.boolean().optional(),
49
+ waf: z.boolean().optional(),
50
+ purge_on_deploy: z.boolean().optional()
51
+ }).optional(),
52
+ resources: z.object({
53
+ memory: z.union([z.string(), z.number()]).optional(),
54
+ cpus: z.union([z.string(), z.number()]).optional()
55
+ }).optional(),
56
+ env_file: z.string().optional(),
37
57
  ignore: z.array(z.string()).optional(),
38
- vars: z.record(z.union([z.string(), z.number(), z.boolean()])).optional()
58
+ vars: z.record(z.union([z.string(), z.number(), z.boolean()])).optional(),
59
+ deploy: z.object({
60
+ detach: z.boolean().optional(),
61
+ force_rebuild: z.boolean().optional(),
62
+ sync_domains: z.boolean().optional()
63
+ }).optional()
39
64
  });
40
65
  function getAuthDir() {
41
66
  return path.join(os.homedir(), ".config", "sagacloud");
@@ -867,6 +892,24 @@ async function createArchiveFromDirectory(targetDir, extraIgnorePatterns = [], i
867
892
  }
868
893
 
869
894
  // src/commands/deploy.ts
895
+ async function resolveWranglerStyleTargetSite(client, optsSite, configuredName, jsonc, link) {
896
+ if (optsSite) return optsSite;
897
+ if (jsonc?.site_id) return jsonc.site_id;
898
+ const targetName = (configuredName || "").trim();
899
+ if (targetName) {
900
+ if (link?.site_id && link.site_name && link.site_name.trim().toLowerCase() === targetName.toLowerCase()) {
901
+ return link.site_id;
902
+ }
903
+ const listRes = await client.rpc("saga_cloud.api.hosting.list_sites", {
904
+ query: { limit: 100 }
905
+ });
906
+ const matched = (listRes.sites || []).find(
907
+ (s) => (s.site_name || "").trim().toLowerCase() === targetName.toLowerCase()
908
+ );
909
+ return matched ? matched.name : "";
910
+ }
911
+ return link?.site_id || "";
912
+ }
870
913
  function parseDotEnvText(raw) {
871
914
  const rows = [];
872
915
  for (const line of raw.split(/\r?\n/)) {
@@ -883,6 +926,56 @@ function parseDotEnvText(raw) {
883
926
  }
884
927
  return rows;
885
928
  }
929
+ function normalizeConfiguredDomains(entries) {
930
+ if (!entries?.length) return [];
931
+ const out = [];
932
+ const seen = /* @__PURE__ */ new Set();
933
+ for (const item of entries) {
934
+ const raw = typeof item === "string" ? { fqdn: item } : item;
935
+ const fqdn = (raw.fqdn || "").replace(/^https?:\/\//i, "").split("/")[0].trim().toLowerCase().replace(/\.+$/, "");
936
+ if (!fqdn || seen.has(fqdn)) continue;
937
+ seen.add(fqdn);
938
+ out.push({ fqdn, primary: Boolean(raw.primary), mode: raw.mode || "auto" });
939
+ }
940
+ return out;
941
+ }
942
+ async function reconcileConfiguredDomains(client, site, specs) {
943
+ if (specs.length === 0) return site;
944
+ let latestSite = site;
945
+ const attached = new Set((latestSite.domains || []).map((d) => (d.fqdn || "").toLowerCase()));
946
+ for (const spec of specs) {
947
+ if (attached.has(spec.fqdn)) {
948
+ if (spec.primary && (latestSite.domain || "").toLowerCase() !== spec.fqdn) {
949
+ const upRes = await client.rpc("saga_cloud.api.hosting.update_site_domain", {
950
+ method: "POST",
951
+ body: { site_id: latestSite.name, fqdn: spec.fqdn, make_primary: true }
952
+ });
953
+ latestSite = upRes.site || latestSite;
954
+ }
955
+ continue;
956
+ }
957
+ const addRes = await client.rpc("saga_cloud.api.hosting.add_site_domain", {
958
+ method: "POST",
959
+ body: {
960
+ site_id: latestSite.name,
961
+ domain_mode: spec.mode,
962
+ custom_fqdn: spec.fqdn,
963
+ make_primary: spec.primary
964
+ }
965
+ });
966
+ latestSite = addRes.site || latestSite;
967
+ attached.add(spec.fqdn);
968
+ const added = addRes.added_domain || (latestSite.domains || []).find((d) => d.fqdn.toLowerCase() === spec.fqdn);
969
+ if (added?.dns_auto_configured) {
970
+ console.log(pc3.green(`\u2713 Domain ${spec.fqdn} attached with automatic DNS + Edge SSL (${added.domain_mode})`));
971
+ } else if (added?.cname_target) {
972
+ console.log(pc3.yellow(`\u25D0 External domain ${spec.fqdn} attached \u2014 point CNAME -> ${pc3.cyan(added.cname_target)}, then run: sagacloud domains verify ${spec.fqdn}`));
973
+ } else {
974
+ console.log(pc3.green(`\u2713 Domain ${spec.fqdn} attached`));
975
+ }
976
+ }
977
+ return latestSite;
978
+ }
886
979
  function registerDeployCommands(program2) {
887
980
  program2.command("deploy").alias("up").description("Deploy local static/SPA output, Express/Node source, or Git site to SagaCloud").option("--site <siteId>", "Target Site ID (overrides .sagacloud/project.json)").option("--name <siteName>", "Site name when creating a new site").option("--dir <outputDir>", "Pre-built static output directory (e.g. ./dist)").option("--build", "Run local build command before packaging static output").option("--no-build", "Skip running local build command").option("--static", "Deploy as static HTML/PHP site").option("--spa", "Deploy as Single Page App (Nginx try_files /index.html)").option("--node", "Deploy as Node.js / Express / SSR application").option("--port <port>", "Listening HTTP port for Node.js app", "3000").option("--start <cmd>", "Start command for Node.js app").option("--git", "Trigger remote Git redeploy instead of uploading local files").option("--force", "Bypass build cache on remote rebuild", false).option("--with-env <file>", "Load and push .env file variables before building").option("--detach", "Queue deployment and exit without streaming build logs", false).option("--yes", "Skip interactive prompts", false).action(
888
981
  async (opts) => {
@@ -891,7 +984,14 @@ function registerDeployCommands(program2) {
891
984
  const { config: jsonc } = readRepoJsoncConfig(cwd);
892
985
  const link = readLocalLink(cwd);
893
986
  const detected = detectProject(cwd);
894
- const existingSiteId = opts.site || link?.site_id || jsonc?.site_id || "";
987
+ const configuredName = (opts.name || jsonc?.app_name || jsonc?.name || "").trim() || void 0;
988
+ const existingSiteId = await resolveWranglerStyleTargetSite(
989
+ client,
990
+ opts.site,
991
+ configuredName,
992
+ jsonc,
993
+ link
994
+ );
895
995
  if (opts.git) {
896
996
  const targetId = resolveActiveSiteId(cwd, existingSiteId);
897
997
  const spin2 = p2.spinner();
@@ -958,7 +1058,7 @@ function registerDeployCommands(program2) {
958
1058
  );
959
1059
  const uploadSpin = p2.spinner();
960
1060
  uploadSpin.start("Uploading bundle to SagaCloud...");
961
- const zipName = `${(jsonc?.name || path4.basename(cwd) || "bundle").replace(/[^a-z0-9-]+/gi, "-")}.zip`;
1061
+ const zipName = `${(jsonc?.app_name || jsonc?.name || path4.basename(cwd) || "bundle").replace(/[^a-z0-9-]+/gi, "-")}.zip`;
962
1062
  const uploaded = await client.uploadBundle(archive.buffer, zipName, siteType);
963
1063
  uploadSpin.stop(`Uploaded (${uploaded.detected_entry})`);
964
1064
  const mergedVars = /* @__PURE__ */ new Map();
@@ -967,8 +1067,9 @@ function registerDeployCommands(program2) {
967
1067
  mergedVars.set(k, String(v));
968
1068
  }
969
1069
  }
970
- if (opts.withEnv) {
971
- const envPath = path4.resolve(cwd, opts.withEnv);
1070
+ const envFilesToLoad = [jsonc?.env_file, opts.withEnv].filter((f) => Boolean(f));
1071
+ for (const relEnv of envFilesToLoad) {
1072
+ const envPath = path4.resolve(cwd, relEnv);
972
1073
  if (!fs4.existsSync(envPath)) throw new Error(`Env file not found: ${envPath}`);
973
1074
  for (const item of parseDotEnvText(fs4.readFileSync(envPath, "utf8"))) {
974
1075
  mergedVars.set(item.key, item.value);
@@ -979,6 +1080,9 @@ function registerDeployCommands(program2) {
979
1080
  value,
980
1081
  is_build_time: siteType === "static"
981
1082
  }));
1083
+ const forceRebuild = opts.force || Boolean(jsonc?.deploy?.force_rebuild);
1084
+ const detachMode = opts.detach || Boolean(jsonc?.deploy?.detach);
1085
+ const domainSpecs = jsonc?.deploy?.sync_domains === false ? [] : normalizeConfiguredDomains(jsonc?.domains);
982
1086
  let targetSite;
983
1087
  let dep;
984
1088
  if (existingSiteId) {
@@ -996,7 +1100,7 @@ function registerDeployCommands(program2) {
996
1100
  method: "POST",
997
1101
  body: {
998
1102
  site_id: existingSiteId,
999
- force_rebuild: true,
1103
+ force_rebuild: forceRebuild !== false,
1000
1104
  new_zip_file_url: uploaded.file_url
1001
1105
  }
1002
1106
  }
@@ -1005,15 +1109,32 @@ function registerDeployCommands(program2) {
1005
1109
  query: { site_id: existingSiteId, limit: 1 }
1006
1110
  })).site;
1007
1111
  dep = res.deployment;
1112
+ if (!link || link.site_id !== targetSite.name || link.site_name !== targetSite.site_name) {
1113
+ writeLocalLink(
1114
+ {
1115
+ site_id: targetSite.name,
1116
+ site_name: targetSite.site_name,
1117
+ tenant_id: link?.tenant_id,
1118
+ site_type: siteType,
1119
+ runtime_variant: runtimeVariant,
1120
+ output_dir: siteType === "static" ? outputRel : ""
1121
+ },
1122
+ cwd
1123
+ );
1124
+ }
1008
1125
  depSpin.stop(`Deployment v${dep.version_number} queued for ${targetSite.domain}`);
1009
1126
  } else {
1010
- const defaultName = opts.name || jsonc?.name || path4.basename(cwd).toLowerCase().replace(/[^a-z0-9-]+/g, "-").replace(/^-|-$/g, "") || "sagacloud-app";
1011
- const siteName = opts.yes ? defaultName : String(
1012
- await p2.text({
1127
+ const fallbackFolderName = path4.basename(cwd).toLowerCase().replace(/[^a-z0-9-]+/g, "-").replace(/^-|-$/g, "") || "sagacloud-app";
1128
+ const defaultName = configuredName || fallbackFolderName;
1129
+ let siteName = defaultName;
1130
+ if (!configuredName && !opts.yes) {
1131
+ const nameAns = await p2.text({
1013
1132
  message: `Create new ${siteType.toUpperCase()} site name`,
1014
1133
  initialValue: defaultName
1015
- })
1016
- );
1134
+ });
1135
+ if (p2.isCancel(nameAns)) process.exit(1);
1136
+ siteName = String(nameAns);
1137
+ }
1017
1138
  const createSpin = p2.spinner();
1018
1139
  createSpin.start(`Creating ${siteType} site '${siteName}'...`);
1019
1140
  const res = await client.rpc(
@@ -1028,9 +1149,15 @@ function registerDeployCommands(program2) {
1028
1149
  zip_file_url: uploaded.file_url,
1029
1150
  is_spa: runtimeVariant === "spa",
1030
1151
  ports_exposes: siteType === "node" ? String(opts.port || jsonc?.port || detected.port || "3000") : "80",
1152
+ base_directory: jsonc?.base_directory || "",
1031
1153
  install_command: jsonc?.install_command || "",
1032
1154
  build_command: siteType === "node" ? jsonc?.build_command || detected.buildCommand || "" : "",
1033
1155
  start_command: siteType === "node" ? opts.start || jsonc?.start_command || detected.startCommand || "npm start" : "",
1156
+ healthcheck_path: jsonc?.healthcheck_path || "",
1157
+ cdn_enabled: jsonc?.cdn?.enabled,
1158
+ waf_enabled: jsonc?.cdn?.waf,
1159
+ limits_memory: jsonc?.resources?.memory !== void 0 ? String(jsonc.resources.memory) : "",
1160
+ limits_cpus: jsonc?.resources?.cpus !== void 0 ? String(jsonc.resources.cpus) : "",
1034
1161
  publish_directory: siteType === "static" ? outputRel : "",
1035
1162
  env_vars: envPayload.length > 0 ? envPayload : void 0
1036
1163
  }
@@ -1042,6 +1169,7 @@ function registerDeployCommands(program2) {
1042
1169
  writeLocalLink(
1043
1170
  {
1044
1171
  site_id: targetSite.name,
1172
+ site_name: targetSite.site_name,
1045
1173
  tenant_id: info.tenant,
1046
1174
  site_type: siteType,
1047
1175
  runtime_variant: runtimeVariant,
@@ -1051,7 +1179,10 @@ function registerDeployCommands(program2) {
1051
1179
  );
1052
1180
  createSpin.stop(`Created ${targetSite.name} -> ${pc3.cyan(targetSite.live_url || targetSite.domain)}`);
1053
1181
  }
1054
- if (opts.detach || !dep.deployment_uuid) {
1182
+ if (domainSpecs.length > 0) {
1183
+ targetSite = await reconcileConfiguredDomains(client, targetSite, domainSpecs);
1184
+ }
1185
+ if (detachMode || !dep.deployment_uuid) {
1055
1186
  console.log(pc3.dim(`Deployment ${dep.name} queued. Check progress with: sagacloud logs`));
1056
1187
  return;
1057
1188
  }
@@ -1216,12 +1347,14 @@ function registerOpsCommands(program2) {
1216
1347
  "saga_cloud.api.hosting.list_deployments",
1217
1348
  { query: { site_id: siteId, limit: Number(opts.limit || 15) } }
1218
1349
  );
1219
- const table = new Table3({ head: ["Version", "ID", "Trigger", "Status", "Live", "Rollback", "Created"] });
1350
+ const table = new Table3({ head: ["Version", "ID", "Channel", "By", "Status", "Live", "Rollback", "Created"] });
1220
1351
  for (const d of res.deployments || []) {
1352
+ const chan = d.cli_token_name ? `${(d.trigger_channel || "cli").toUpperCase()} (${d.cli_token_name})` : (d.trigger_channel || d.trigger_type).toUpperCase();
1221
1353
  table.push([
1222
1354
  `v${d.version_number}`,
1223
1355
  d.name,
1224
- d.trigger_type,
1356
+ chan,
1357
+ d.triggered_by || "-",
1225
1358
  d.status === "finished" ? pc5.green(d.status) : d.status === "failed" ? pc5.red(d.status) : d.status,
1226
1359
  d.is_active ? pc5.green("ACTIVE") : "-",
1227
1360
  d.can_instant_rollback ? "Yes" : "-",
@@ -1273,20 +1406,24 @@ function registerOpsCommands(program2) {
1273
1406
  }
1274
1407
  console.log(table.toString());
1275
1408
  });
1276
- domains.command("add <fqdn>").description("Attach a custom external domain or subdomain").option("--site <siteId>", "Site ID").option("--primary", "Make primary domain", false).action(async (fqdn, opts) => {
1409
+ domains.command("add <fqdns...>").description("Attach one or more owned SagaCloud or custom external domains").option("--site <siteId>", "Site ID").option("--primary", "Set the last added domain as primary live URL", false).action(async (fqdns, opts) => {
1277
1410
  const siteId = resolveActiveSiteId(process.cwd(), opts.site);
1278
1411
  const client = new SagaCloudClient();
1279
- const res = await client.rpc(
1280
- "saga_cloud.api.hosting.add_site_domain",
1281
- {
1412
+ for (let i = 0; i < fqdns.length; i += 1) {
1413
+ const cleanFqdn = fqdns[i].replace(/^https?:\/\//i, "").split("/")[0].trim().toLowerCase().replace(/\.+$/, "");
1414
+ const makePrimary = Boolean(opts.primary) && i === fqdns.length - 1;
1415
+ const res = await client.rpc("saga_cloud.api.hosting.add_site_domain", {
1282
1416
  method: "POST",
1283
- body: { site_id: siteId, domain_mode: "custom_external", custom_fqdn: fqdn, make_primary: Boolean(opts.primary) }
1417
+ body: { site_id: siteId, domain_mode: "auto", custom_fqdn: cleanFqdn, make_primary: makePrimary }
1418
+ });
1419
+ const added = res.added_domain || (res.site.domains || []).find((d) => d.fqdn.toLowerCase() === cleanFqdn);
1420
+ console.log(pc5.green(`Added ${cleanFqdn} to ${res.site.site_name}`));
1421
+ if (added?.dns_auto_configured) {
1422
+ console.log(pc5.green(`\u2713 Automatic workspace DNS + Edge SSL configured (${added.domain_mode})`));
1423
+ } else if (added?.cname_target) {
1424
+ console.log(`Point DNS CNAME: ${pc5.bold(cleanFqdn)} -> ${pc5.cyan(added.cname_target)}`);
1425
+ console.log(pc5.dim(`Then verify SSL with: sagacloud domains verify ${cleanFqdn}`));
1284
1426
  }
1285
- );
1286
- console.log(pc5.green(`Added ${fqdn} to ${res.site.site_name}`));
1287
- if (res.added_domain?.cname_target) {
1288
- console.log(`Point DNS CNAME: ${pc5.bold(fqdn)} -> ${pc5.cyan(res.added_domain.cname_target)}`);
1289
- console.log(pc5.dim(`Then verify SSL with: sagacloud domains verify ${fqdn}`));
1290
1427
  }
1291
1428
  });
1292
1429
  domains.command("verify <fqdn>").description("Verify DNS CNAME and issue Edge SSL").option("--site <siteId>", "Site ID").action(async (fqdn, opts) => {
@@ -1385,10 +1522,11 @@ function registerProjectCommands(program2) {
1385
1522
  const res = await client.rpc("saga_cloud.api.hosting.list_sites", {
1386
1523
  query: { site_type: opts.type, limit: 100 }
1387
1524
  });
1388
- const table = new Table4({ head: ["Site ID", "Name", "Type", "Status", "Live URL"] });
1525
+ const table = new Table4({ head: ["Site ID", "Name", "Type", "Status", "Last Deploy", "Live URL"] });
1389
1526
  for (const s of res.sites || []) {
1390
1527
  const statusColor = s.status === "Online" ? pc6.green(s.status) : s.status === "Failed" ? pc6.red(s.status) : pc6.yellow(s.status);
1391
- table.push([s.name, s.site_name, `${s.site_type}/${s.runtime_variant}`, statusColor, s.live_url || s.domain]);
1528
+ const actor = s.last_deployed_by ? `${(s.last_deploy_channel || "web").toUpperCase()} \xB7 ${s.last_deployed_by}` : "-";
1529
+ table.push([s.name, s.site_name, `${s.site_type}/${s.runtime_variant}`, statusColor, actor, s.live_url || s.domain]);
1392
1530
  }
1393
1531
  console.log(table.toString());
1394
1532
  });
@@ -1419,6 +1557,7 @@ function registerProjectCommands(program2) {
1419
1557
  const detected = detectProject(process.cwd());
1420
1558
  const linkPath = writeLocalLink({
1421
1559
  site_id: details.site.name,
1560
+ site_name: details.site.site_name,
1422
1561
  tenant_id: info.tenant,
1423
1562
  site_type: details.site.site_type,
1424
1563
  runtime_variant: details.site.runtime_variant,
@@ -1455,7 +1594,7 @@ function registerProjectCommands(program2) {
1455
1594
  const jsoncLines = [
1456
1595
  "{",
1457
1596
  ` // Auto-detected: ${detected.frameworkLabel}`,
1458
- ` "name": ${JSON.stringify(siteName)},`,
1597
+ ` "app_name": ${JSON.stringify(siteName)},`,
1459
1598
  ` "type": ${JSON.stringify(detected.runtimeVariant)},`,
1460
1599
  ...detected.buildCommand ? [` "build_command": ${JSON.stringify(detected.buildCommand)},`] : [],
1461
1600
  ...detected.siteType === "static" ? [
@@ -1463,8 +1602,13 @@ function registerProjectCommands(program2) {
1463
1602
  ` "spa_fallback": ${detected.runtimeVariant === "spa"},`
1464
1603
  ] : [
1465
1604
  ` "start_command": ${JSON.stringify(startCmd)},`,
1466
- ` "port": ${port},`
1605
+ ` "port": ${port},`,
1606
+ ` // "healthcheck_path": "/health",`
1467
1607
  ],
1608
+ ` // Add owned SagaCloud domains or external domains to auto-attach on deploy:`,
1609
+ ` // "domains": ["app.example.com"],`,
1610
+ ` // "env_file": ".env.production",`,
1611
+ ` "cdn": { "enabled": true, "waf": false, "purge_on_deploy": true },`,
1468
1612
  ` "ignore": ["node_modules", ".git", ".env*", "tests"]`,
1469
1613
  "}",
1470
1614
  ""
@@ -1480,12 +1624,14 @@ function registerProjectCommands(program2) {
1480
1624
  query: { site_id: siteId, limit: 5 }
1481
1625
  });
1482
1626
  const s = res.site;
1483
- console.log(`${pc6.bold("Site:")} ${s.site_name} (${s.name})`);
1484
- console.log(`${pc6.bold("Type:")} ${s.site_type} / ${s.runtime_variant} (${s.source_type})`);
1485
- console.log(`${pc6.bold("Status:")} ${s.status}`);
1486
- console.log(`${pc6.bold("Live URL:")} ${s.live_url || s.domain}`);
1487
- console.log(`${pc6.bold("SSL / CDN:")} SSL=${s.ssl_status || "-"} \xB7 EdgeCDN=${s.cdn_enabled ? "On" : "Off"} \xB7 Shield=${s.waf_enabled ? "On" : "Off"}`);
1488
- console.log(`${pc6.bold("Deployed:")} ${s.last_deployed_at || "-"}`);
1627
+ const deployActor = s.last_deployed_by ? `${s.last_deployed_by} (${(s.last_deploy_channel || "web").toUpperCase()})` : "-";
1628
+ console.log(`${pc6.bold("Site:")} ${s.site_name} (${s.name})`);
1629
+ console.log(`${pc6.bold("Type:")} ${s.site_type} / ${s.runtime_variant} (${s.source_type})`);
1630
+ console.log(`${pc6.bold("Status:")} ${s.status}`);
1631
+ console.log(`${pc6.bold("Live URL:")} ${s.live_url || s.domain}`);
1632
+ console.log(`${pc6.bold("SSL / CDN:")} SSL=${s.ssl_status || "-"} \xB7 EdgeCDN=${s.cdn_enabled ? "On" : "Off"} \xB7 Shield=${s.waf_enabled ? "On" : "Off"}`);
1633
+ console.log(`${pc6.bold("Deployed:")} ${s.last_deployed_at || "-"}`);
1634
+ console.log(`${pc6.bold("Deployed By:")} ${deployActor}`);
1489
1635
  });
1490
1636
  program2.command("open").description("Open site Live URL in browser").option("--site <siteId>", "Site ID").action(async (opts) => {
1491
1637
  const siteId = resolveActiveSiteId(process.cwd(), opts.site);
@@ -1502,16 +1648,124 @@ function registerProjectCommands(program2) {
1502
1648
  });
1503
1649
  }
1504
1650
 
1651
+ // src/commands/skill.ts
1652
+ import fs8 from "fs";
1653
+ import os3 from "os";
1654
+ import path8 from "path";
1655
+ import { fileURLToPath } from "url";
1656
+ import pc7 from "picocolors";
1657
+ function resolveBundledSkillDir() {
1658
+ const here = path8.dirname(fileURLToPath(import.meta.url));
1659
+ const candidates = [
1660
+ path8.resolve(here, "..", "skills", "sagacloud"),
1661
+ path8.resolve(here, "..", "..", "skills", "sagacloud")
1662
+ ];
1663
+ for (const dir of candidates) {
1664
+ if (fs8.existsSync(path8.join(dir, "SKILL.md"))) {
1665
+ return dir;
1666
+ }
1667
+ }
1668
+ throw new Error("Bundled SagaCloud skill files were not found in package.");
1669
+ }
1670
+ function getTargetPaths(target, opts) {
1671
+ const cwd = opts.cwd || process.cwd();
1672
+ const home = os3.homedir();
1673
+ const normalized = (target || "all").toLowerCase();
1674
+ const map = opts.project ? {
1675
+ antigravity: {
1676
+ label: "Antigravity / Universal (.agents/skills)",
1677
+ destDir: path8.join(cwd, ".agents", "skills", "sagacloud")
1678
+ },
1679
+ claude: {
1680
+ label: "Claude Code (.claude/skills)",
1681
+ destDir: path8.join(cwd, ".claude", "skills", "sagacloud")
1682
+ },
1683
+ agents: {
1684
+ label: "Agent Skills (.agents/skills)",
1685
+ destDir: path8.join(cwd, ".agents", "skills", "sagacloud")
1686
+ }
1687
+ } : {
1688
+ antigravity: {
1689
+ label: "Antigravity (~/.gemini/config/skills)",
1690
+ destDir: path8.join(home, ".gemini", "config", "skills", "sagacloud")
1691
+ },
1692
+ claude: {
1693
+ label: "Claude Code (~/.claude/skills)",
1694
+ destDir: path8.join(home, ".claude", "skills", "sagacloud")
1695
+ },
1696
+ agents: {
1697
+ label: "Codex / Open Agents (~/.agents/skills)",
1698
+ destDir: path8.join(home, ".agents", "skills", "sagacloud")
1699
+ }
1700
+ };
1701
+ const keys = normalized === "all" ? ["antigravity", "claude", "agents"] : normalized in map ? [normalized] : (() => {
1702
+ throw new Error(`Unknown target '${target}'. Use: all, antigravity, claude, or agents.`);
1703
+ })();
1704
+ const seen = /* @__PURE__ */ new Set();
1705
+ const out = [];
1706
+ for (const k of keys) {
1707
+ const entry = map[k];
1708
+ if (!seen.has(entry.destDir)) {
1709
+ seen.add(entry.destDir);
1710
+ out.push(entry);
1711
+ }
1712
+ }
1713
+ return out;
1714
+ }
1715
+ function copyDirRecursive(src, dest) {
1716
+ fs8.mkdirSync(dest, { recursive: true });
1717
+ for (const entry of fs8.readdirSync(src, { withFileTypes: true })) {
1718
+ const srcPath = path8.join(src, entry.name);
1719
+ const destPath = path8.join(dest, entry.name);
1720
+ if (entry.isDirectory()) {
1721
+ copyDirRecursive(srcPath, destPath);
1722
+ } else if (entry.isFile()) {
1723
+ fs8.copyFileSync(srcPath, destPath);
1724
+ }
1725
+ }
1726
+ }
1727
+ function registerSkillCommands(program2) {
1728
+ const skills = program2.command("skills").alias("skill").description("Install or inspect the SagaCloud skill for AI coding agents");
1729
+ skills.command("install").description("Install SagaCloud SKILL.md for Antigravity, Claude Code, Codex, and Cursor").option("--project", "Install into current project (.agents/skills & .claude/skills) instead of user home", false).option("--target <agent>", "Target agent: all, antigravity, claude, agents", "all").action((opts) => {
1730
+ const srcDir = resolveBundledSkillDir();
1731
+ const destinations = getTargetPaths(opts.target, { project: opts.project });
1732
+ for (const item of destinations) {
1733
+ copyDirRecursive(srcDir, item.destDir);
1734
+ console.log(`${pc7.green("\u2713")} ${item.label} -> ${pc7.cyan(item.destDir)}`);
1735
+ }
1736
+ console.log(pc7.dim("\nYour coding agent can now load the 'sagacloud' skill automatically."));
1737
+ });
1738
+ skills.command("status").description("Show where the SagaCloud agent skill is installed").option("--project", "Check current project directories", false).action((opts) => {
1739
+ const destinations = getTargetPaths("all", { project: opts.project });
1740
+ for (const item of destinations) {
1741
+ const installed = fs8.existsSync(path8.join(item.destDir, "SKILL.md"));
1742
+ console.log(`${installed ? pc7.green("installed") : pc7.dim("not found")} ${item.destDir}`);
1743
+ }
1744
+ });
1745
+ skills.command("uninstall").description("Remove installed SagaCloud agent skill files").option("--project", "Remove from current project instead of user home", false).option("--target <agent>", "Target agent: all, antigravity, claude, agents", "all").action((opts) => {
1746
+ const destinations = getTargetPaths(opts.target, { project: opts.project });
1747
+ for (const item of destinations) {
1748
+ if (fs8.existsSync(item.destDir)) {
1749
+ fs8.rmSync(item.destDir, { recursive: true, force: true });
1750
+ console.log(`${pc7.yellow("-")} Removed ${item.destDir}`);
1751
+ } else {
1752
+ console.log(`${pc7.dim("\u2022")} Not installed at ${item.destDir}`);
1753
+ }
1754
+ }
1755
+ });
1756
+ }
1757
+
1505
1758
  // src/index.ts
1506
1759
  var program = new Command();
1507
- program.name("sagacloud").description("SagaCloud CLI \u2014 deploy Static, SPA, Express & Node.js apps cleanly").version("0.1.1");
1760
+ program.name("sagacloud").description("SagaCloud CLI \u2014 deploy Static, SPA, Express & Node.js apps cleanly").version("0.3.0");
1508
1761
  registerAuthCommands(program);
1509
1762
  registerProjectCommands(program);
1510
1763
  registerDeployCommands(program);
1511
1764
  registerEnvCommands(program);
1512
1765
  registerOpsCommands(program);
1766
+ registerSkillCommands(program);
1513
1767
  program.parseAsync(process.argv).catch((err) => {
1514
1768
  const msg = err instanceof Error ? err.message : String(err);
1515
- console.error(pc7.red(`Error: ${msg}`));
1769
+ console.error(pc8.red(`Error: ${msg}`));
1516
1770
  process.exit(1);
1517
1771
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sagacloud",
3
- "version": "0.1.1",
3
+ "version": "0.3.0",
4
4
  "description": "Official CLI for SagaCloud Web & App Hosting",
5
5
  "license": "MIT",
6
6
  "author": "SagaSoft",
@@ -28,6 +28,9 @@
28
28
  },
29
29
  "files": [
30
30
  "dist",
31
+ "skills",
32
+ "plugin.json",
33
+ ".claude-plugin",
31
34
  "README.md",
32
35
  "LICENSE"
33
36
  ],
package/plugin.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "name": "sagacloud",
3
+ "description": "Deploy and manage Static, SPA, and Node.js apps on SagaCloud via the sagacloud CLI.",
4
+ "author": "SagaSoft",
5
+ "homepage": "https://app.sagasoft.xyz",
6
+ "repository": "https://gitlab.com/sagasoft/sagacloud-cli"
7
+ }
@@ -0,0 +1,96 @@
1
+ ---
2
+ name: sagacloud
3
+ description: >-
4
+ Deploy, configure, inspect, and troubleshoot websites and Node.js apps on
5
+ SagaCloud using the `sagacloud` CLI. Use when the user asks to deploy a
6
+ static site, React/Vite/Angular/Next.js SPA, or Express/Node.js server to
7
+ SagaCloud, sync environment variables, inspect build or runtime logs, manage
8
+ custom domains and Edge SSL, roll back deployments, or set up GitHub Actions
9
+ CI/CD (`sagacloud.jsonc`).
10
+ ---
11
+
12
+ # SagaCloud Hosting Skill (`sagacloud` CLI)
13
+
14
+ Use the `sagacloud` CLI to deploy and operate applications on **SagaCloud** (`https://app.sagasoft.xyz`).
15
+
16
+ ## Safety & Rules
17
+ - **Never read, print, or invent secrets:** Do not print `~/.config/sagacloud/auth.json`, `$SAGACLOUD_TOKEN`, or `.env*` secrets into chat.
18
+ - **Check auth before mutating:** Always verify auth with `sagacloud whoami`. If unauthenticated, ask the user to run `sagacloud login` interactively (browser approval) or export `SAGACLOUD_TOKEN`.
19
+ - **Use `--yes` for non-interactive commands:** Agents cannot reliably drive interactive prompts; pass `--yes` (`init`, `deploy`, `delete`) and explicit flags (`--site`, `--name`, `--dir`, `--static`, `--spa`, `--node`).
20
+ - **Prefer local builds for static SPAs:** React, Vite, Vue, Angular, Astro, and Next.js static export build locally (`npm run build`) and upload only the static output directory (`dist/`, `build/`, `out/`) unless the site uses remote Git deploy (`--git`).
21
+ - **Environment variables on static builds:** Variables injected for static SPAs must be present **before** building (`--build-time` on `env set` or `--with-env .env.production` on `deploy`), whereas Node.js/Express apps distinguish build-time (`VITE_*`, `NEXT_PUBLIC_*`) from runtime secrets.
22
+
23
+ ## Step 1: Verify CLI & Authentication
24
+
25
+ ```bash
26
+ sagacloud --version
27
+ sagacloud whoami
28
+ ```
29
+
30
+ If `sagacloud` is missing, tell the user to install it or invoke via `npx sagacloud`:
31
+ ```bash
32
+ npm install -g sagacloud # Node >= 20 required
33
+ ```
34
+
35
+ If `sagacloud whoami` fails (`Not authenticated`), stop and instruct the user to run:
36
+ ```bash
37
+ sagacloud login
38
+ ```
39
+ (In headless/CI environments, use `SAGACLOUD_TOKEN=sc_live_...` or `sagacloud login --token <token>`.)
40
+
41
+ ## Step 2: Detect Project Type & Link/Configure
42
+
43
+ Inspect `package.json`, `angular.json`, `next.config.*`, or existing `sagacloud.jsonc` / `.sagacloud/project.json`. See [sagacloud.jsonc reference](./references/sagacloud-jsonc.md) for all supported fields.
44
+
45
+ - Generate default `sagacloud.jsonc`:
46
+ ```bash
47
+ sagacloud init --yes
48
+ ```
49
+ - Link to an existing remote site instead of creating a new one:
50
+ ```bash
51
+ sagacloud list
52
+ sagacloud link --site <site_id>
53
+ ```
54
+
55
+ ## Step 3: Deploy by Project Type
56
+
57
+ ### Static HTML / PHP / Pre-built SPA (`dist/`, `build/`, `out/`)
58
+ ```bash
59
+ # Build locally and deploy auto-detected output dir:
60
+ sagacloud deploy --spa --yes --name <site-name>
61
+
62
+ # Or skip local build when output directory is already built:
63
+ sagacloud deploy --dir ./dist --spa --no-build --yes --name <site-name>
64
+
65
+ # Plain static HTML/PHP without SPA index.html fallback:
66
+ sagacloud deploy --dir ./public --static --no-build --yes --name <site-name>
67
+ ```
68
+
69
+ ### Express / Fastify / NestJS / Hono / Next.js SSR (`node`)
70
+ ```bash
71
+ sagacloud deploy --node --port 3000 --start "npm start" --yes --name <site-name>
72
+ ```
73
+ *(Uploads source archive excluding `node_modules/`, `.git/`, `.env*`; builds and runs on SagaCloud Node runtime.)*
74
+
75
+ ### Git-Connected Site
76
+ ```bash
77
+ sagacloud deploy --git --site <site_id>
78
+ # Force clean rebuild bypassing cache:
79
+ sagacloud deploy --git --force --site <site_id>
80
+ ```
81
+
82
+ ## Step 4: Verify, Debug & Operate
83
+
84
+ - **Check live URL & Edge status:** `sagacloud status`
85
+ - **Build logs (latest or specific deployment):** `sagacloud logs [deploymentUuid]`
86
+ - **Runtime container logs (Node apps):** `sagacloud logs --runtime -n 200` (or `-f` to stream)
87
+ - **Sync environment variables:**
88
+ - `sagacloud env ls`
89
+ - `sagacloud env set API_URL=https://api.example.com` (add `--build-time` for frontend bundle vars)
90
+ - `sagacloud env push .env.production` (always run `sagacloud deploy` afterward to apply changes)
91
+ - `sagacloud env pull .env.local`
92
+ - **Rollback instant or source version:** `sagacloud deployments` → `sagacloud rollback v2`
93
+ - **Custom domains & Edge SSL:** `sagacloud domains add app.example.com [second.example.com]` (`mode: "auto"` detects owned workspace domains automatically vs external CNAME targets; configure `"domains"` array in `sagacloud.jsonc` for additive merge on `deploy`), or verify SSL with `sagacloud domains verify app.example.com`
94
+ - **Purge Edge CDN cache:** `sagacloud purge`
95
+ - **Container power control:** `sagacloud start | stop | restart`
96
+ - **Generate GitHub Actions workflow:** `sagacloud ci init` (creates `.github/workflows/sagacloud.yml` expecting `secrets.SAGACLOUD_TOKEN`)
@@ -0,0 +1,57 @@
1
+ # `sagacloud.jsonc` Schema & Framework Reference
2
+
3
+ Place `sagacloud.jsonc` (or `sagacloud.json`) in the root of your repository. Trailing commas and `//` / `/* */` comments are supported.
4
+
5
+ ## Fields
6
+
7
+ | Field | Type | Description |
8
+ | --- | --- | --- |
9
+ | `app_name` (or `name`) | `string` | Default site/app name when creating a new site |
10
+ | `site_id` | `string` | Explicit target Site ID (`site_...`) if not using `.sagacloud/project.json` |
11
+ | `type` | `"static" \| "spa" \| "php" \| "node" \| "nextjs"` | Runtime mode override |
12
+ | `base_directory` | `string` | Optional monorepo subdirectory |
13
+ | `install_command` | `string` | Custom install command for remote Node/SSR builds |
14
+ | `build_command` | `string` | Local build command for static/SPA (e.g. `npm run build`) or remote build for Node |
15
+ | `output_dir` | `string` | Built static output directory (e.g. `dist`, `build`, `out`, `dist/my-app/browser`) |
16
+ | `start_command` | `string` | Start command for Node/SSR runtime (e.g. `npm start`, `node server.js`) |
17
+ | `port` | `number \| string` | Listening HTTP port inside Node container (default `3000`) |
18
+ | `spa_fallback` | `boolean` | When `true`, unknown routes rewrite to `/index.html` (`type: "spa"`) |
19
+ | `healthcheck_path` | `string` | Optional HTTP health check path for Node/SSR apps |
20
+ | `domains` | `(string \| { fqdn, primary?, mode? })[]` | Multiple domains to auto-attach safely on deploy (`mode`: `auto` \| `saga_root` \| `saga_subdomain` \| `custom_external`) |
21
+ | `cdn` | `{ enabled?, waf?, purge_on_deploy? }` | Edge CDN / WAF toggles for new sites |
22
+ | `resources` | `{ memory?, cpus? }` | Container resource limits (e.g. `"512m"`, `"1"`) |
23
+ | `env_file` | `string` | Default `.env` file synced cleanly during `sagacloud deploy` |
24
+ | `ignore` | `string[]` | Extra glob patterns excluded from upload archive (`node_modules`, `.git`, `.env*`, `.sagacloud`, `sagacloud.json*` are always excluded) |
25
+ | `vars` | `Record<string, string \| number \| boolean>` | Non-secret environment variables pushed automatically on `sagacloud deploy` (merged, never wipes dashboard secrets) |
26
+ | `deploy` | `{ detach?, force_rebuild?, sync_domains? }` | Default deploy command behavior |
27
+
28
+ ## Auto-Detection Defaults
29
+
30
+ | Framework | Detected Type | Output Dir / Start Cmd |
31
+ | --- | --- | --- |
32
+ | Static HTML | `static` / `html` | `.` |
33
+ | PHP (`index.php`) | `static` / `php` | `.` |
34
+ | Vite / React / Vue | `static` / `spa` | `dist` |
35
+ | Create React App | `static` / `spa` | `build` |
36
+ | Angular (`angular.json`) | `static` / `spa` | `outputPath` (+ `/browser` if present) or `dist` |
37
+ | Astro | `static` / `spa` | `dist` |
38
+ | Next.js (`output: 'export'`) | `static` / `spa` | `out` |
39
+ | Next.js SSR | `node` / `nextjs` | `npm start` (port `3000`) |
40
+ | Express / Fastify / NestJS / Hono / Koa | `node` / `node` | `npm start` (port `3000`) |
41
+
42
+ ## Example
43
+
44
+ ```jsonc
45
+ {
46
+ // Vite + React SPA on SagaCloud
47
+ "name": "billing-portal",
48
+ "type": "spa",
49
+ "build_command": "npm run build",
50
+ "output_dir": "dist",
51
+ "spa_fallback": true,
52
+ "ignore": ["node_modules", ".git", ".env*", "coverage"],
53
+ "vars": {
54
+ "VITE_APP_NAME": "Billing Portal"
55
+ }
56
+ }
57
+ ```