@sahu-01/openpaw 1.0.5 → 1.0.7

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 (2) hide show
  1. package/dist/index.js +43 -58
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -9,7 +9,7 @@ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
9
  var __esm = (fn, res) => function __init() {
10
10
  return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
11
11
  };
12
- var __commonJS = (cb, mod) => function __require2() {
12
+ var __commonJS = (cb, mod) => function __require() {
13
13
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
14
14
  };
15
15
  var __copyProps = (to, from, except, desc) => {
@@ -230786,14 +230786,14 @@ var OpenClawAuthProfilesSchema = import_zod4.z.object({
230786
230786
  });
230787
230787
  var WORKSPACE_FILES = ["AGENTS.md", "SOUL.md", ".cursorrules", "CLAUDE.md"];
230788
230788
  async function copyWorkspaceFiles(sourceDir, destDir) {
230789
- const { readdir: readdir4, copyFile: copyFile2, mkdir: mkdir4 } = await import("fs/promises");
230789
+ const { readdir: readdir4, copyFile, mkdir: mkdir4 } = await import("fs/promises");
230790
230790
  const { join: join5 } = await import("path");
230791
230791
  await mkdir4(destDir, { recursive: true });
230792
230792
  const files = await readdir4(sourceDir);
230793
230793
  const copied = [];
230794
230794
  for (const file of files) {
230795
230795
  if (WORKSPACE_FILES.includes(file)) {
230796
- await copyFile2(join5(sourceDir, file), join5(destDir, file));
230796
+ await copyFile(join5(sourceDir, file), join5(destDir, file));
230797
230797
  copied.push(file);
230798
230798
  }
230799
230799
  }
@@ -230818,7 +230818,7 @@ function mapProviderToCredentialType(type) {
230818
230818
  return "api_key";
230819
230819
  }
230820
230820
  async function migrateCredentials(openclawDir, vault) {
230821
- const { readFile: readFile5, writeFile: writeFile4, copyFile: copyFile2, readdir: readdir4, stat: stat3 } = await import("fs/promises");
230821
+ const { readFile: readFile5, writeFile: writeFile4, copyFile, readdir: readdir4, stat: stat3 } = await import("fs/promises");
230822
230822
  const { join: join5 } = await import("path");
230823
230823
  const result = {
230824
230824
  profilesProcessed: 0,
@@ -230852,7 +230852,7 @@ async function migrateCredentials(openclawDir, vault) {
230852
230852
  const parsed = JSON.parse(content);
230853
230853
  const authProfiles = OpenClawAuthProfilesSchema.parse(parsed);
230854
230854
  const backupPath = `${authProfilesPath}.bak`;
230855
- await copyFile2(authProfilesPath, backupPath);
230855
+ await copyFile(authProfilesPath, backupPath);
230856
230856
  result.filesBackedUp.push(backupPath);
230857
230857
  const updatedProfiles = {};
230858
230858
  for (const [profileName, profile] of Object.entries(authProfiles.profiles)) {
@@ -230892,12 +230892,6 @@ var import_child_process = require("child_process");
230892
230892
  var import_fs = require("fs");
230893
230893
  var import_zod5 = require("zod");
230894
230894
  init_dist();
230895
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
230896
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
230897
- }) : x)(function(x) {
230898
- if (typeof require !== "undefined") return require.apply(this, arguments);
230899
- throw Error('Dynamic require of "' + x + '" is not supported');
230900
- });
230901
230895
  var DEFAULT_PORT = 18789;
230902
230896
  var SessionSchema = import_zod5.z.object({
230903
230897
  id: import_zod5.z.string(),
@@ -230943,35 +230937,36 @@ async function findAuthProfileFiles(openclawDir) {
230943
230937
  }
230944
230938
  return profileFiles;
230945
230939
  }
230946
- async function processAuthProfiles(profilePath, vault, backupSuffix) {
230940
+ function credIdToEnvVar(credId) {
230941
+ return "OPENPAW_" + credId.toUpperCase().replace(/[^A-Z0-9]/g, "_");
230942
+ }
230943
+ async function processAuthProfiles(profilePath, vault) {
230947
230944
  const content = await (0, import_promises3.readFile)(profilePath, "utf8");
230948
230945
  const data = JSON.parse(content);
230946
+ const envVarMap = /* @__PURE__ */ new Map();
230949
230947
  let modified = false;
230950
230948
  if (data.profiles) {
230951
230949
  for (const profileName of Object.keys(data.profiles)) {
230952
230950
  const profile = data.profiles[profileName];
230953
- if (profile && typeof profile.key === "string" && profile.key.startsWith("openpaw:vault:")) {
230954
- const credId = profile.key.replace("openpaw:vault:", "");
230955
- const result = vault.get(credId);
230956
- if (result) {
230957
- profile.key = result.value;
230951
+ if (profile && typeof profile.key === "string") {
230952
+ if (profile.key.startsWith("openpaw:vault:")) {
230953
+ const credId = profile.key.replace("openpaw:vault:", "");
230954
+ const envVarName = credIdToEnvVar(credId);
230955
+ envVarMap.set(envVarName, credId);
230956
+ profile.key = "${" + envVarName + "}";
230958
230957
  modified = true;
230958
+ } else if (profile.key.startsWith("${OPENPAW_") && profile.key.endsWith("}")) {
230959
+ const envVarName = profile.key.slice(2, -1);
230960
+ const credId = envVarName.replace("OPENPAW_", "").toLowerCase();
230961
+ envVarMap.set(envVarName, credId);
230959
230962
  }
230960
230963
  }
230961
230964
  }
230962
230965
  }
230963
230966
  if (modified) {
230964
- await (0, import_promises3.copyFile)(profilePath, `${profilePath}${backupSuffix}`);
230965
230967
  await (0, import_promises3.writeFile)(profilePath, JSON.stringify(data, null, 2), { mode: 384 });
230966
230968
  }
230967
- return { original: content, processed: modified };
230968
- }
230969
- async function restoreAuthProfiles(profilePath, backupSuffix) {
230970
- const backupPath = `${profilePath}${backupSuffix}`;
230971
- if ((0, import_fs.existsSync)(backupPath)) {
230972
- await (0, import_promises3.copyFile)(backupPath, profilePath);
230973
- await (0, import_promises3.unlink)(backupPath);
230974
- }
230969
+ return envVarMap;
230975
230970
  }
230976
230971
  async function startGateway(config = {}) {
230977
230972
  const openpawDir = config.openpawDir ?? (0, import_path3.join)((0, import_os2.homedir)(), ".openpaw");
@@ -230997,47 +230992,40 @@ async function startGateway(config = {}) {
230997
230992
  throw error;
230998
230993
  }
230999
230994
  const profileFiles = await findAuthProfileFiles(openclawDir);
231000
- const backupSuffix = ".openpaw-backup";
231001
- const processedFiles = [];
230995
+ const allEnvVars = /* @__PURE__ */ new Map();
231002
230996
  for (const profilePath of profileFiles) {
231003
- const result = await processAuthProfiles(profilePath, vault, backupSuffix);
231004
- if (result.processed) {
231005
- processedFiles.push(profilePath);
230997
+ const envVars = await processAuthProfiles(profilePath, vault);
230998
+ for (const [envVarName, credId] of envVars) {
230999
+ allEnvVars.set(envVarName, credId);
231006
231000
  }
231007
231001
  }
231002
+ const childEnv = { ...process.env };
231003
+ let credentialsLoaded = 0;
231004
+ for (const [envVarName, credId] of allEnvVars) {
231005
+ const result = vault.get(credId);
231006
+ if (result) {
231007
+ childEnv[envVarName] = result.value;
231008
+ credentialsLoaded++;
231009
+ console.log(` ${envVarName} \u2192 [secured]`);
231010
+ } else {
231011
+ console.warn(` Warning: Credential ${credId} not found in vault`);
231012
+ }
231013
+ }
231014
+ console.log(`Loaded ${credentialsLoaded} credential(s) into environment`);
231008
231015
  let cleanedUp = false;
231009
231016
  let openclawProcess = null;
231010
231017
  const cleanup = async () => {
231011
231018
  if (cleanedUp) return;
231012
231019
  cleanedUp = true;
231013
- console.log("\nRe-encrypting credentials...");
231014
- for (const profilePath of processedFiles) {
231015
- try {
231016
- await restoreAuthProfiles(profilePath, backupSuffix);
231017
- console.log(` Restored: ${profilePath}`);
231018
- } catch (err) {
231019
- console.error(` Failed to restore ${profilePath}: ${err.message}`);
231020
- }
231021
- }
231020
+ console.log("\nShutting down...");
231022
231021
  if (openclawProcess && !openclawProcess.killed) {
231023
231022
  openclawProcess.kill("SIGTERM");
231024
231023
  }
231025
- console.log("Credentials secured.");
231024
+ console.log("Gateway stopped.");
231026
231025
  };
231027
231026
  const cleanupSync = () => {
231028
231027
  if (cleanedUp) return;
231029
231028
  cleanedUp = true;
231030
- const fs = __require("fs");
231031
- for (const profilePath of processedFiles) {
231032
- try {
231033
- const backupPath = `${profilePath}${backupSuffix}`;
231034
- if (fs.existsSync(backupPath)) {
231035
- fs.copyFileSync(backupPath, profilePath);
231036
- fs.unlinkSync(backupPath);
231037
- }
231038
- } catch {
231039
- }
231040
- }
231041
231029
  if (openclawProcess && !openclawProcess.killed) {
231042
231030
  openclawProcess.kill("SIGTERM");
231043
231031
  }
@@ -231062,21 +231050,18 @@ async function startGateway(config = {}) {
231062
231050
  process.exit(1);
231063
231051
  });
231064
231052
  const openclawBinary = await findOpenClawBinary(openclawDir);
231065
- console.log(`Gateway running on port ${port}. Credentials decrypted in memory. Press Ctrl+C to stop and re-encrypt.`);
231066
- if (processedFiles.length > 0) {
231067
- console.log(`Decrypted ${processedFiles.length} auth-profiles.json file(s)`);
231068
- }
231053
+ console.log(`Gateway running. Credentials secured via environment variables. Press Ctrl+C to stop.`);
231069
231054
  const isWindows = process.platform === "win32";
231070
231055
  const spawnOpenClaw = (command, args = []) => {
231071
231056
  if (isWindows) {
231072
231057
  return (0, import_child_process.spawn)("cmd.exe", ["/c", command, ...args], {
231073
231058
  stdio: "inherit",
231074
- env: { ...process.env }
231059
+ env: childEnv
231075
231060
  });
231076
231061
  } else {
231077
231062
  return (0, import_child_process.spawn)(command, args, {
231078
231063
  stdio: "inherit",
231079
- env: { ...process.env },
231064
+ env: childEnv,
231080
231065
  shell: true
231081
231066
  });
231082
231067
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sahu-01/openpaw",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "description": "OpenPaw CLI - Security-first wrapper for AI agents",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",