@duct-sdk/sdk 0.1.12 → 0.1.13

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.
@@ -286,19 +286,19 @@ export function DuctShell({ shellId, userContext, onTokenRequest, onNavigate, on
286
286
  display: "flex",
287
287
  alignItems: "center",
288
288
  justifyContent: "center",
289
- backgroundColor: "#E8622A",
290
- boxShadow: "0 4px 16px rgba(232,98,42,0.40), 0 2px 8px rgba(0,0,0,0.12)",
289
+ backgroundColor: "#0C0B09",
290
+ boxShadow: "0 4px 16px rgba(0,0,0,0.40), 0 2px 8px rgba(0,0,0,0.20)",
291
291
  padding: 0,
292
292
  transition: "transform 150ms ease, box-shadow 150ms ease",
293
293
  };
294
294
  return (_jsxs(_Fragment, { children: [!panelOpen && (_jsx("button", { type: "button", style: buttonStyle, onClick: openPanel, "aria-label": "Open Duct Shell", className: className, onMouseEnter: (e) => {
295
295
  e.currentTarget.style.transform = "scale(1.07)";
296
296
  e.currentTarget.style.boxShadow =
297
- "0 6px 20px rgba(232,98,42,0.50), 0 2px 8px rgba(0,0,0,0.14)";
297
+ "0 6px 20px rgba(0,0,0,0.50), 0 2px 8px rgba(0,0,0,0.20)";
298
298
  }, onMouseLeave: (e) => {
299
299
  e.currentTarget.style.transform = "scale(1)";
300
300
  e.currentTarget.style.boxShadow =
301
- "0 4px 16px rgba(232,98,42,0.40), 0 2px 8px rgba(0,0,0,0.12)";
301
+ "0 4px 16px rgba(0,0,0,0.40), 0 2px 8px rgba(0,0,0,0.20)";
302
302
  }, children: !iconLoadFailed ? (_jsx("img", { src: currentIconSrc, alt: "Duct", width: 28, height: 28, onError: handleIconError, style: { width: "28px", height: "28px", objectFit: "contain" } })) : (_jsx("svg", { width: "28", height: "28", viewBox: "0 0 24 24", fill: "none", "aria-hidden": "true", children: _jsx("path", { d: "M18 12c0-3.3-2.2-5.5-5.5-5.5C9 6.5 7 8.7 7 12s2 5.5 5.5 5.5c2 0 3.6-.8 4.6-2.2l-2.2-1.6c-.6.8-1.4 1.3-2.4 1.3-1.6 0-2.8-1.2-2.8-3s1.2-3 2.8-3c1 0 1.8.5 2.3 1.3L18 12z", fill: "white" }) })) })), _jsx("div", { style: panelStyle, "data-duct-shell": shellId, children: _jsx("iframe", { ref: iframeRef, src: shellUrl, title: "Duct Shell", sandbox: "allow-scripts allow-same-origin allow-forms allow-popups allow-popups-to-escape-sandbox", allow: "clipboard-write", referrerPolicy: "no-referrer-when-downgrade", style: {
303
303
  width: "100%",
304
304
  height: "100%",
@@ -297,19 +297,19 @@ export function DuctShell({ shellId, userContext, onTokenRequest, onNavigate, on
297
297
  display: "flex",
298
298
  alignItems: "center",
299
299
  justifyContent: "center",
300
- backgroundColor: "#E8622A",
301
- boxShadow: "0 4px 16px rgba(232,98,42,0.40), 0 2px 8px rgba(0,0,0,0.12)",
300
+ backgroundColor: "#0C0B09",
301
+ boxShadow: "0 4px 16px rgba(0,0,0,0.40), 0 2px 8px rgba(0,0,0,0.20)",
302
302
  padding: 0,
303
303
  transition: "transform 150ms ease, box-shadow 150ms ease",
304
304
  };
305
305
  return (_jsxs(_Fragment, { children: [!panelOpen && (_jsx("button", { type: "button", style: buttonStyle, onClick: openPanel, "aria-label": "Open Duct Shell", className: className, onMouseEnter: (e) => {
306
306
  e.currentTarget.style.transform = "scale(1.07)";
307
307
  e.currentTarget.style.boxShadow =
308
- "0 6px 20px rgba(232,98,42,0.50), 0 2px 8px rgba(0,0,0,0.14)";
308
+ "0 6px 20px rgba(0,0,0,0.50), 0 2px 8px rgba(0,0,0,0.20)";
309
309
  }, onMouseLeave: (e) => {
310
310
  e.currentTarget.style.transform = "scale(1)";
311
311
  e.currentTarget.style.boxShadow =
312
- "0 4px 16px rgba(232,98,42,0.40), 0 2px 8px rgba(0,0,0,0.12)";
312
+ "0 4px 16px rgba(0,0,0,0.40), 0 2px 8px rgba(0,0,0,0.20)";
313
313
  }, children: !iconLoadFailed ? (_jsx("img", { src: currentIconSrc, alt: "Duct", width: 28, height: 28, onError: handleIconError, style: { width: "28px", height: "28px", objectFit: "contain" } })) : (_jsx("svg", { width: "28", height: "28", viewBox: "0 0 24 24", fill: "none", "aria-hidden": "true", children: _jsx("path", { d: "M18 12c0-3.3-2.2-5.5-5.5-5.5C9 6.5 7 8.7 7 12s2 5.5 5.5 5.5c2 0 3.6-.8 4.6-2.2l-2.2-1.6c-.6.8-1.4 1.3-2.4 1.3-1.6 0-2.8-1.2-2.8-3s1.2-3 2.8-3c1 0 1.8.5 2.3 1.3L18 12z", fill: "white" }) })) })), _jsx("div", { style: panelStyle, "data-duct-shell": shellId, children: _jsx("iframe", { ref: iframeRef, src: shellUrl, title: "Duct Shell", sandbox: "allow-scripts allow-same-origin allow-forms allow-popups allow-popups-to-escape-sandbox", allow: "clipboard-write", referrerPolicy: "no-referrer-when-downgrade", style: {
314
314
  width: "100%",
315
315
  height: "100%",
package/dist/cli/index.js CHANGED
@@ -46,18 +46,45 @@ function loadEnvFileSync(envPath) {
46
46
  // File doesn't exist — that's fine, move on
47
47
  }
48
48
  }
49
+ // Walk up from startDir until we find a directory that looks like the project
50
+ // root (contains duct.config.ts, .git, or package.json). Returns all
51
+ // directories from root down to startDir so that files closer to the user's
52
+ // cwd take priority (loaded last = highest priority among .env files).
53
+ function resolveEnvSearchDirs(startDir) {
54
+ const dirs = [];
55
+ let dir = startDir;
56
+ for (let i = 0; i < 10; i++) {
57
+ dirs.unshift(dir); // prepend so we get root→cwd order
58
+ const isDuctRoot = require("fs").existsSync(require("path").join(dir, "duct.config.ts")) ||
59
+ require("fs").existsSync(require("path").join(dir, "duct.config.js")) ||
60
+ require("fs").existsSync(require("path").join(dir, ".git"));
61
+ if (isDuctRoot) {
62
+ break;
63
+ }
64
+ const parent = require("path").dirname(dir);
65
+ if (parent === dir)
66
+ break; // filesystem root
67
+ dir = parent;
68
+ }
69
+ // Deduplicate while preserving order (root first, cwd last)
70
+ return [...new Set(dirs)];
71
+ }
49
72
  function loadAllEnvFilesSync() {
50
73
  const cwd = process.cwd();
51
74
  const nodeEnv = process.env["NODE_ENV"] ?? "";
52
- // Standard dotenv priority order (lowest → highest priority)
53
- const candidates = [
75
+ const suffixes = [
54
76
  ".env",
55
77
  ".env.local",
56
78
  nodeEnv ? `.env.${nodeEnv}` : null,
57
79
  nodeEnv ? `.env.${nodeEnv}.local` : null,
58
80
  ].filter((f) => Boolean(f));
59
- for (const file of candidates) {
60
- loadEnvFileSync(path.join(cwd, file));
81
+ // Load from each ancestor directory (root → cwd), so keys from directories
82
+ // closer to cwd override those from parent directories, but never override
83
+ // keys already set in the shell environment.
84
+ for (const dir of resolveEnvSearchDirs(cwd)) {
85
+ for (const suffix of suffixes) {
86
+ loadEnvFileSync(path.join(dir, suffix));
87
+ }
61
88
  }
62
89
  }
63
90
  // Load all .env files synchronously at startup (before any commands run)
@@ -461,9 +488,40 @@ program
461
488
  continue;
462
489
  }
463
490
  pushSpinner.fail("Push failed");
464
- console.error(chalk.red(`\n${lastError}`));
465
- console.log(chalk.gray(" Tip: Check DUCT_URL is set and services are running."));
466
- console.log(chalk.gray(" Run npx duct checkup to diagnose connectivity.\n"));
491
+ // Parse the error body and surface the real cause clearly.
492
+ // The proxy may wrap inner service errors as a JSON string inside `message`.
493
+ let outerErr = {};
494
+ let innerErr = {};
495
+ try {
496
+ outerErr = JSON.parse(body);
497
+ }
498
+ catch { /* raw string error */ }
499
+ if (typeof outerErr["message"] === "string") {
500
+ try {
501
+ innerErr = JSON.parse(outerErr["message"]);
502
+ }
503
+ catch { /* not JSON */ }
504
+ }
505
+ const innerCode = (innerErr["error"] ?? outerErr["error"] ?? "");
506
+ const retryAfter = innerErr["retry_after"];
507
+ if (innerCode === "too_many_requests") {
508
+ const wait = retryAfter ? ` Try again in ${retryAfter}s.` : " Try again shortly.";
509
+ console.error(chalk.red("\n Auth service rate-limited: too many failed token validation attempts."));
510
+ console.log(chalk.yellow(` This usually means DUCT_SECRET_KEY was missing or invalid on previous runs.${wait}`));
511
+ console.log(chalk.gray(" 1. Confirm DUCT_SECRET_KEY is set in your .env (at the same level as duct.config.ts)"));
512
+ console.log(chalk.gray(" 2. Run `npx duct login` if your session token is stale"));
513
+ console.log(chalk.gray(" 3. Run `npx duct checkup` to verify env vars are loaded\n"));
514
+ }
515
+ else if (response.status === 401) {
516
+ const hint = outerErr["message"] ?? body;
517
+ console.error(chalk.red(`\n Authentication failed: ${hint}`));
518
+ console.log(chalk.gray(" Run `npx duct login` to refresh your credentials, then retry.\n"));
519
+ }
520
+ else {
521
+ console.error(chalk.red(`\n${lastError}`));
522
+ console.log(chalk.gray(" Tip: Check DUCT_URL is set and services are running."));
523
+ console.log(chalk.gray(" Run npx duct checkup to diagnose connectivity.\n"));
524
+ }
467
525
  process.exit(1);
468
526
  }
469
527
  if (!success) {
@@ -910,6 +968,107 @@ export default defineDuctConfig(${JSON.stringify(manifest, null, 2)});
910
968
  }
911
969
  });
912
970
  // ----------------------------------------------------------------
971
+ // duct rollback — activate a historical push directly on Duct cloud
972
+ // Unlike `duct pull` (which writes duct.config.ts locally), rollback
973
+ // immediately sets the live manifest to the stored snapshot without
974
+ // touching any local files. Run `duct pull <hash>` afterwards if you
975
+ // also want your local config to reflect the change.
976
+ // ----------------------------------------------------------------
977
+ program
978
+ .command("rollback <hash>")
979
+ .description("Set a historical push as the active manifest on Duct cloud (no local file changes)")
980
+ .option("--shell-id <shellId>", "Override shell ID (reads from duct.config.ts by default)")
981
+ .option("--config <path>", "Path to duct.config.ts (used only to read shellId)", "duct.config.ts")
982
+ .option("--yes", "Skip confirmation prompt", false)
983
+ .action(async (hash, opts) => {
984
+ const spinner = ora("Resolving shell…").start();
985
+ try {
986
+ // Load API key
987
+ let apiKey = process.env["DUCT_API_KEY"];
988
+ if (!apiKey) {
989
+ const auth = await readAuth();
990
+ apiKey = auth?.token;
991
+ }
992
+ if (!apiKey) {
993
+ spinner.fail("Not logged in");
994
+ console.log(chalk.yellow("\nRun `npx duct login` first.\n"));
995
+ process.exit(1);
996
+ }
997
+ // Resolve shell ID
998
+ let shellId = opts.shellId;
999
+ if (!shellId) {
1000
+ const cwd = process.cwd();
1001
+ const configPath = path.resolve(cwd, opts.config);
1002
+ try {
1003
+ const config = await loadDuctConfig(configPath);
1004
+ shellId = config["shellId"];
1005
+ }
1006
+ catch { /* config may not exist */ }
1007
+ }
1008
+ if (!shellId) {
1009
+ spinner.stop();
1010
+ const { id } = await inquirer.prompt([
1011
+ {
1012
+ type: "input",
1013
+ name: "id",
1014
+ message: "Shell ID (shell_...):",
1015
+ validate: (v) => v.startsWith("shell_") || "Must start with shell_",
1016
+ },
1017
+ ]);
1018
+ shellId = id;
1019
+ }
1020
+ spinner.succeed(`Shell: ${chalk.cyan(shellId)}`);
1021
+ if (!opts.yes) {
1022
+ const { confirm } = await inquirer.prompt([
1023
+ {
1024
+ type: "confirm",
1025
+ name: "confirm",
1026
+ message: chalk.yellow(`Activate hash ${chalk.bold(hash)} as the live manifest for ${shellId}?`),
1027
+ default: false,
1028
+ },
1029
+ ]);
1030
+ if (!confirm) {
1031
+ console.log(chalk.gray("\nRollback cancelled.\n"));
1032
+ process.exit(0);
1033
+ }
1034
+ }
1035
+ const activateSpinner = ora(`Activating ${hash}…`).start();
1036
+ const auth = await readAuth();
1037
+ const manifestBases = getManifestApiBases(auth);
1038
+ let success = false;
1039
+ let lastError = "";
1040
+ for (const base of manifestBases) {
1041
+ const res = await fetch(`${base}/v1/shells/${shellId}/manifest/activate/${encodeURIComponent(hash)}`, {
1042
+ method: "POST",
1043
+ headers: { Authorization: `Bearer ${apiKey}` },
1044
+ });
1045
+ if (res.ok) {
1046
+ success = true;
1047
+ break;
1048
+ }
1049
+ const body = await res.text();
1050
+ lastError = `${res.status} at ${base}: ${body}`;
1051
+ if (res.status === 404)
1052
+ continue;
1053
+ break;
1054
+ }
1055
+ if (!success) {
1056
+ activateSpinner.fail(`Rollback failed`);
1057
+ console.error(chalk.red(`\n${lastError || "No manifest API responded"}`));
1058
+ process.exit(1);
1059
+ }
1060
+ activateSpinner.succeed(`Hash ${chalk.cyan(hash)} is now the live manifest for ${chalk.cyan(shellId)}`);
1061
+ console.log(chalk.green("\n ◆ Rollback complete\n"));
1062
+ console.log(chalk.gray(` Tip: Run \`npx duct pull ${hash}\` to also restore duct.config.ts locally.\n`));
1063
+ }
1064
+ catch (err) {
1065
+ spinner.fail("Rollback failed");
1066
+ const message = err instanceof Error ? err.message : String(err);
1067
+ console.error(chalk.red(`\nError: ${message}\n`));
1068
+ process.exit(1);
1069
+ }
1070
+ });
1071
+ // ----------------------------------------------------------------
913
1072
  // Error handling
914
1073
  // ----------------------------------------------------------------
915
1074
  program.exitOverride();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@duct-sdk/sdk",
3
- "version": "0.1.12",
3
+ "version": "0.1.13",
4
4
  "type": "module",
5
5
  "description": "Duct SDK — A shell (like terminal) that knows when to talk, when to show, and when to hand off.",
6
6
  "main": "dist/index.js",