@dexto/core 1.16.6 → 1.17.0-beta.5

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 (104) hide show
  1. package/dist/agent/DextoAgent.cjs +2 -1
  2. package/dist/agent/DextoAgent.d.ts.map +1 -1
  3. package/dist/agent/DextoAgent.js +2 -1
  4. package/dist/agent/schemas.d.ts +2 -2
  5. package/dist/approval/index.cjs +4 -0
  6. package/dist/approval/index.d.ts +1 -1
  7. package/dist/approval/index.d.ts.map +1 -1
  8. package/dist/approval/index.js +4 -0
  9. package/dist/events/index.cjs +2 -3
  10. package/dist/events/index.d.ts +6 -23
  11. package/dist/events/index.d.ts.map +1 -1
  12. package/dist/events/index.js +2 -3
  13. package/dist/llm/error-codes.cjs +1 -0
  14. package/dist/llm/error-codes.d.ts +1 -0
  15. package/dist/llm/error-codes.d.ts.map +1 -1
  16. package/dist/llm/error-codes.js +1 -0
  17. package/dist/llm/executor/provider-error.cjs +14 -0
  18. package/dist/llm/executor/provider-error.d.ts.map +1 -1
  19. package/dist/llm/executor/provider-error.js +14 -0
  20. package/dist/llm/executor/turn-executor.cjs +4 -0
  21. package/dist/llm/executor/turn-executor.d.ts +5 -5
  22. package/dist/llm/executor/turn-executor.d.ts.map +1 -1
  23. package/dist/llm/executor/turn-executor.js +4 -0
  24. package/dist/llm/index.cjs +6 -0
  25. package/dist/llm/index.d.ts +2 -0
  26. package/dist/llm/index.d.ts.map +1 -1
  27. package/dist/llm/index.js +4 -0
  28. package/dist/llm/private-address.cjs +88 -0
  29. package/dist/llm/private-address.d.ts +3 -0
  30. package/dist/llm/private-address.d.ts.map +1 -0
  31. package/dist/llm/private-address.js +65 -0
  32. package/dist/llm/providers/codex-app-server.cjs +3 -3
  33. package/dist/llm/providers/codex-app-server.js +3 -3
  34. package/dist/llm/providers/local/errors.cjs +4 -4
  35. package/dist/llm/providers/local/errors.js +4 -4
  36. package/dist/llm/safe-download.cjs +159 -0
  37. package/dist/llm/safe-download.d.ts +21 -0
  38. package/dist/llm/safe-download.d.ts.map +1 -0
  39. package/dist/llm/safe-download.js +126 -0
  40. package/dist/logger/logger.cjs +12 -9
  41. package/dist/logger/logger.d.ts.map +1 -1
  42. package/dist/logger/logger.js +12 -9
  43. package/dist/logger/v2/dexto-logger.cjs +3 -2
  44. package/dist/logger/v2/dexto-logger.d.ts.map +1 -1
  45. package/dist/logger/v2/dexto-logger.js +3 -2
  46. package/dist/mcp/mcp-client.cjs +17 -8
  47. package/dist/mcp/mcp-client.d.ts +4 -2
  48. package/dist/mcp/mcp-client.d.ts.map +1 -1
  49. package/dist/mcp/mcp-client.js +17 -8
  50. package/dist/mcp/schemas.cjs +3 -0
  51. package/dist/mcp/schemas.d.ts +3 -0
  52. package/dist/mcp/schemas.d.ts.map +1 -1
  53. package/dist/mcp/schemas.js +3 -0
  54. package/dist/resources/handlers/filesystem-handler.cjs +7 -6
  55. package/dist/resources/handlers/filesystem-handler.d.ts.map +1 -1
  56. package/dist/resources/handlers/filesystem-handler.js +7 -6
  57. package/dist/session/session-manager.cjs +2 -0
  58. package/dist/session/session-manager.d.ts.map +1 -1
  59. package/dist/session/session-manager.js +2 -0
  60. package/dist/systemPrompt/schemas.d.ts +3 -3
  61. package/dist/telemetry/decorators.cjs +2 -2
  62. package/dist/telemetry/decorators.js +2 -2
  63. package/dist/tools/activity.cjs +0 -16
  64. package/dist/tools/activity.d.ts +0 -2
  65. package/dist/tools/activity.d.ts.map +1 -1
  66. package/dist/tools/activity.js +0 -16
  67. package/dist/tools/tool-call-metadata.cjs +0 -12
  68. package/dist/tools/tool-call-metadata.d.ts +0 -3
  69. package/dist/tools/tool-call-metadata.d.ts.map +1 -1
  70. package/dist/tools/tool-call-metadata.js +0 -12
  71. package/dist/tools/tool-manager.cjs +10 -93
  72. package/dist/tools/tool-manager.d.ts.map +1 -1
  73. package/dist/tools/tool-manager.js +10 -93
  74. package/dist/utils/env.cjs +0 -5
  75. package/dist/utils/env.d.ts +0 -1
  76. package/dist/utils/env.d.ts.map +1 -1
  77. package/dist/utils/env.js +0 -4
  78. package/dist/utils/index.cjs +3 -1
  79. package/dist/utils/index.d.ts +1 -0
  80. package/dist/utils/index.d.ts.map +1 -1
  81. package/dist/utils/index.js +1 -0
  82. package/dist/utils/metadata-address.cjs +138 -0
  83. package/dist/utils/metadata-address.d.ts +24 -0
  84. package/dist/utils/metadata-address.d.ts.map +1 -0
  85. package/dist/utils/metadata-address.js +113 -0
  86. package/dist/utils/path.cjs +0 -15
  87. package/dist/utils/path.d.ts +0 -6
  88. package/dist/utils/path.d.ts.map +1 -1
  89. package/dist/utils/path.js +0 -14
  90. package/dist/utils/redactor.cjs +242 -34
  91. package/dist/utils/redactor.d.ts +15 -0
  92. package/dist/utils/redactor.d.ts.map +1 -1
  93. package/dist/utils/redactor.js +238 -34
  94. package/dist/workspace/index.cjs +7 -2
  95. package/dist/workspace/index.d.ts +1 -0
  96. package/dist/workspace/index.d.ts.map +1 -1
  97. package/dist/workspace/index.js +4 -1
  98. package/dist/workspace/shell-environment.cjs +96 -0
  99. package/dist/workspace/shell-environment.d.ts +18 -0
  100. package/dist/workspace/shell-environment.d.ts.map +1 -0
  101. package/dist/workspace/shell-environment.js +72 -0
  102. package/dist/workspace/types.d.ts +9 -0
  103. package/dist/workspace/types.d.ts.map +1 -1
  104. package/package.json +3 -3
@@ -0,0 +1,138 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var metadata_address_exports = {};
20
+ __export(metadata_address_exports, {
21
+ createMetadataCheckedLookup: () => createMetadataCheckedLookup,
22
+ isMetadataHost: () => isMetadataHost,
23
+ isMetadataTarget: () => isMetadataTarget
24
+ });
25
+ module.exports = __toCommonJS(metadata_address_exports);
26
+ var import_node_dns = require("node:dns");
27
+ var import_node_net = require("node:net");
28
+ const METADATA_HOSTNAMES = /* @__PURE__ */ new Set([
29
+ "metadata.google.internal",
30
+ "metadata.goog",
31
+ "instance-data",
32
+ "instance-data.ec2.internal"
33
+ ]);
34
+ async function resolveAllAddresses(hostname) {
35
+ const records = await import_node_dns.promises.lookup(hostname, { all: true, verbatim: true });
36
+ return records.map((record) => record.address);
37
+ }
38
+ const METADATA_IPV4 = ["100.100.100.200", "192.0.0.192", "168.63.129.16"];
39
+ function isMetadataIpv4(a, b, c, d) {
40
+ return a === 169 && b === 254 || METADATA_IPV4.includes(`${a}.${b}.${c}.${d}`);
41
+ }
42
+ function ipv6Groups(address) {
43
+ const [head = "", tail] = address.split("::");
44
+ const headGroups = head === "" ? [] : head.split(":");
45
+ const tailGroups = tail === void 0 || tail === "" ? [] : tail.split(":");
46
+ const missing = tail === void 0 ? 0 : 8 - headGroups.length - tailGroups.length;
47
+ const groups = [...headGroups, ...Array(missing).fill("0"), ...tailGroups];
48
+ return groups.map((group) => Number.parseInt(group, 16));
49
+ }
50
+ function isMetadataIpv6(address) {
51
+ const normalized = new URL(`http://[${address.split("%")[0]}]/`).hostname.slice(1, -1);
52
+ const g = ipv6Groups(normalized);
53
+ const [g0 = 0, g1 = 0, g2 = 0, g3 = 0, g4 = 0, g5 = 0, g6 = 0, g7 = 0] = g;
54
+ if ((g0 & 65472) === 65152) return true;
55
+ const isMetadataUniqueLocal = g0 === 64768 && g1 === 3778 || g0 === 64800 && g1 === 206;
56
+ if (isMetadataUniqueLocal && g2 + g3 + g4 + g5 + g6 === 0 && g7 === 596) {
57
+ return true;
58
+ }
59
+ const v4 = (high, low) => isMetadataIpv4(high >> 8, high & 255, low >> 8, low & 255);
60
+ const upperZero = g0 + g1 + g2 + g3 === 0;
61
+ if (upperZero && g4 === 0 && g5 === 65535) return v4(g6, g7);
62
+ if (upperZero && g4 === 65535 && g5 === 0) return v4(g6, g7);
63
+ if (upperZero && g4 === 0 && g5 === 0) return v4(g6, g7);
64
+ if (g0 === 100 && g1 === 65435 && g2 + g3 + g4 + g5 === 0) return v4(g6, g7);
65
+ if (g0 === 8194) return v4(g1, g2);
66
+ return false;
67
+ }
68
+ function isMetadataAddress(address) {
69
+ const version = (0, import_node_net.isIP)(address.split("%")[0] ?? address);
70
+ if (version === 4) {
71
+ const [a = 0, b = 0, c = 0, d = 0] = address.split(".").map(Number);
72
+ return isMetadataIpv4(a, b, c, d);
73
+ }
74
+ if (version === 6) return isMetadataIpv6(address);
75
+ return false;
76
+ }
77
+ function normalizeHostname(hostname) {
78
+ const bare = hostname.startsWith("[") && hostname.endsWith("]") ? hostname.slice(1, -1) : hostname;
79
+ let host = bare.toLowerCase();
80
+ while (host.endsWith(".")) host = host.slice(0, -1);
81
+ return host;
82
+ }
83
+ function isMetadataHost(hostname) {
84
+ const host = normalizeHostname(hostname);
85
+ return METADATA_HOSTNAMES.has(host) || isMetadataAddress(host);
86
+ }
87
+ async function isMetadataTarget(hostname, resolve = resolveAllAddresses) {
88
+ if (isMetadataHost(hostname)) return true;
89
+ const host = normalizeHostname(hostname);
90
+ if ((0, import_node_net.isIP)(host) !== 0) return false;
91
+ let addresses;
92
+ try {
93
+ addresses = await resolve(host);
94
+ } catch {
95
+ return false;
96
+ }
97
+ return addresses.some(isMetadataAddress);
98
+ }
99
+ function createMetadataCheckedLookup(resolve = resolveAllAddresses) {
100
+ return (hostname, options, callback) => {
101
+ const fail = (error) => {
102
+ const errno = Object.assign(error, { code: "EMETADATA" });
103
+ if (options.all) callback(errno, []);
104
+ else callback(errno, "", 0);
105
+ };
106
+ if (isMetadataHost(hostname)) {
107
+ fail(new Error(`Blocked request to metadata host: ${hostname}`));
108
+ return;
109
+ }
110
+ resolve(hostname).then(
111
+ (addresses) => {
112
+ const blocked = addresses.find(isMetadataAddress);
113
+ if (blocked !== void 0) {
114
+ fail(new Error(`${hostname} resolves to metadata address ${blocked}`));
115
+ return;
116
+ }
117
+ const records = addresses.map((address) => ({
118
+ address,
119
+ family: (0, import_node_net.isIP)(address) === 6 ? 6 : 4
120
+ }));
121
+ const [first] = records;
122
+ if (first === void 0) {
123
+ fail(new Error(`Failed to resolve ${hostname}`));
124
+ return;
125
+ }
126
+ if (options.all) callback(null, records);
127
+ else callback(null, first.address, first.family);
128
+ },
129
+ (error) => fail(error instanceof Error ? error : new Error(String(error)))
130
+ );
131
+ };
132
+ }
133
+ // Annotate the CommonJS export names for ESM import in node:
134
+ 0 && (module.exports = {
135
+ createMetadataCheckedLookup,
136
+ isMetadataHost,
137
+ isMetadataTarget
138
+ });
@@ -0,0 +1,24 @@
1
+ import { type LookupAddress, type LookupOptions } from 'node:dns';
2
+ type Resolve = (hostname: string) => Promise<string[]>;
3
+ /**
4
+ * True when a hostname names a metadata target without any DNS lookup: a metadata host name or
5
+ * an IP literal. Pass `URL.hostname`, which already normalises decimal, octal and hex IPv4.
6
+ */
7
+ export declare function isMetadataHost(hostname: string): boolean;
8
+ /**
9
+ * True when a hostname is a metadata target, or is a name that resolves to one. Resolves at call
10
+ * time and checks every answer. A name that does not resolve is not a metadata target; the
11
+ * request itself will fail.
12
+ */
13
+ export declare function isMetadataTarget(hostname: string, resolve?: Resolve): Promise<boolean>;
14
+ type LookupCallback = (error: NodeJS.ErrnoException | null, address: string | LookupAddress[], family?: number) => void;
15
+ /**
16
+ * A `lookup` for a connection (for example an undici `connect.lookup`) that resolves the host
17
+ * itself, refuses metadata answers and hands the connection the addresses it checked. A name
18
+ * that answers differently to a later lookup (DNS rebinding) therefore cannot redirect the
19
+ * connection, because there is no later lookup. IP literals never reach a lookup, so check those
20
+ * with {@link isMetadataHost} first.
21
+ */
22
+ export declare function createMetadataCheckedLookup(resolve?: Resolve): (hostname: string, options: LookupOptions, callback: LookupCallback) => void;
23
+ export {};
24
+ //# sourceMappingURL=metadata-address.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metadata-address.d.ts","sourceRoot":"","sources":["../../src/utils/metadata-address.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,KAAK,aAAa,EAAE,KAAK,aAAa,EAAE,MAAM,UAAU,CAAC;AAmBnF,KAAK,OAAO,GAAG,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;AAkEvD;;;GAGG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAGxD;AAED;;;;GAIG;AACH,wBAAsB,gBAAgB,CAClC,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE,OAA6B,GACvC,OAAO,CAAC,OAAO,CAAC,CAWlB;AAED,KAAK,cAAc,GAAG,CAClB,KAAK,EAAE,MAAM,CAAC,cAAc,GAAG,IAAI,EACnC,OAAO,EAAE,MAAM,GAAG,aAAa,EAAE,EACjC,MAAM,CAAC,EAAE,MAAM,KACd,IAAI,CAAC;AAEV;;;;;;GAMG;AACH,wBAAgB,2BAA2B,CACvC,OAAO,GAAE,OAA6B,GACvC,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,cAAc,KAAK,IAAI,CAiC9E"}
@@ -0,0 +1,113 @@
1
+ import "../chunk-C6A6W6XS.js";
2
+ import { promises as dns } from "node:dns";
3
+ import { isIP } from "node:net";
4
+ const METADATA_HOSTNAMES = /* @__PURE__ */ new Set([
5
+ "metadata.google.internal",
6
+ "metadata.goog",
7
+ "instance-data",
8
+ "instance-data.ec2.internal"
9
+ ]);
10
+ async function resolveAllAddresses(hostname) {
11
+ const records = await dns.lookup(hostname, { all: true, verbatim: true });
12
+ return records.map((record) => record.address);
13
+ }
14
+ const METADATA_IPV4 = ["100.100.100.200", "192.0.0.192", "168.63.129.16"];
15
+ function isMetadataIpv4(a, b, c, d) {
16
+ return a === 169 && b === 254 || METADATA_IPV4.includes(`${a}.${b}.${c}.${d}`);
17
+ }
18
+ function ipv6Groups(address) {
19
+ const [head = "", tail] = address.split("::");
20
+ const headGroups = head === "" ? [] : head.split(":");
21
+ const tailGroups = tail === void 0 || tail === "" ? [] : tail.split(":");
22
+ const missing = tail === void 0 ? 0 : 8 - headGroups.length - tailGroups.length;
23
+ const groups = [...headGroups, ...Array(missing).fill("0"), ...tailGroups];
24
+ return groups.map((group) => Number.parseInt(group, 16));
25
+ }
26
+ function isMetadataIpv6(address) {
27
+ const normalized = new URL(`http://[${address.split("%")[0]}]/`).hostname.slice(1, -1);
28
+ const g = ipv6Groups(normalized);
29
+ const [g0 = 0, g1 = 0, g2 = 0, g3 = 0, g4 = 0, g5 = 0, g6 = 0, g7 = 0] = g;
30
+ if ((g0 & 65472) === 65152) return true;
31
+ const isMetadataUniqueLocal = g0 === 64768 && g1 === 3778 || g0 === 64800 && g1 === 206;
32
+ if (isMetadataUniqueLocal && g2 + g3 + g4 + g5 + g6 === 0 && g7 === 596) {
33
+ return true;
34
+ }
35
+ const v4 = (high, low) => isMetadataIpv4(high >> 8, high & 255, low >> 8, low & 255);
36
+ const upperZero = g0 + g1 + g2 + g3 === 0;
37
+ if (upperZero && g4 === 0 && g5 === 65535) return v4(g6, g7);
38
+ if (upperZero && g4 === 65535 && g5 === 0) return v4(g6, g7);
39
+ if (upperZero && g4 === 0 && g5 === 0) return v4(g6, g7);
40
+ if (g0 === 100 && g1 === 65435 && g2 + g3 + g4 + g5 === 0) return v4(g6, g7);
41
+ if (g0 === 8194) return v4(g1, g2);
42
+ return false;
43
+ }
44
+ function isMetadataAddress(address) {
45
+ const version = isIP(address.split("%")[0] ?? address);
46
+ if (version === 4) {
47
+ const [a = 0, b = 0, c = 0, d = 0] = address.split(".").map(Number);
48
+ return isMetadataIpv4(a, b, c, d);
49
+ }
50
+ if (version === 6) return isMetadataIpv6(address);
51
+ return false;
52
+ }
53
+ function normalizeHostname(hostname) {
54
+ const bare = hostname.startsWith("[") && hostname.endsWith("]") ? hostname.slice(1, -1) : hostname;
55
+ let host = bare.toLowerCase();
56
+ while (host.endsWith(".")) host = host.slice(0, -1);
57
+ return host;
58
+ }
59
+ function isMetadataHost(hostname) {
60
+ const host = normalizeHostname(hostname);
61
+ return METADATA_HOSTNAMES.has(host) || isMetadataAddress(host);
62
+ }
63
+ async function isMetadataTarget(hostname, resolve = resolveAllAddresses) {
64
+ if (isMetadataHost(hostname)) return true;
65
+ const host = normalizeHostname(hostname);
66
+ if (isIP(host) !== 0) return false;
67
+ let addresses;
68
+ try {
69
+ addresses = await resolve(host);
70
+ } catch {
71
+ return false;
72
+ }
73
+ return addresses.some(isMetadataAddress);
74
+ }
75
+ function createMetadataCheckedLookup(resolve = resolveAllAddresses) {
76
+ return (hostname, options, callback) => {
77
+ const fail = (error) => {
78
+ const errno = Object.assign(error, { code: "EMETADATA" });
79
+ if (options.all) callback(errno, []);
80
+ else callback(errno, "", 0);
81
+ };
82
+ if (isMetadataHost(hostname)) {
83
+ fail(new Error(`Blocked request to metadata host: ${hostname}`));
84
+ return;
85
+ }
86
+ resolve(hostname).then(
87
+ (addresses) => {
88
+ const blocked = addresses.find(isMetadataAddress);
89
+ if (blocked !== void 0) {
90
+ fail(new Error(`${hostname} resolves to metadata address ${blocked}`));
91
+ return;
92
+ }
93
+ const records = addresses.map((address) => ({
94
+ address,
95
+ family: isIP(address) === 6 ? 6 : 4
96
+ }));
97
+ const [first] = records;
98
+ if (first === void 0) {
99
+ fail(new Error(`Failed to resolve ${hostname}`));
100
+ return;
101
+ }
102
+ if (options.all) callback(null, records);
103
+ else callback(null, first.address, first.family);
104
+ },
105
+ (error) => fail(error instanceof Error ? error : new Error(String(error)))
106
+ );
107
+ };
108
+ }
109
+ export {
110
+ createMetadataCheckedLookup,
111
+ isMetadataHost,
112
+ isMetadataTarget
113
+ };
@@ -28,7 +28,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
  var path_exports = {};
30
30
  __export(path_exports, {
31
- copyDirectory: () => copyDirectory,
32
31
  ensureDextoGlobalDirectory: () => ensureDextoGlobalDirectory,
33
32
  findPackageRoot: () => findPackageRoot,
34
33
  getDextoEnvPath: () => getDextoEnvPath,
@@ -91,19 +90,6 @@ function getDextoGlobalPath(type, filename) {
91
90
  const basePath = path.join((0, import_os.homedir)(), ".dexto", type);
92
91
  return filename ? path.join(basePath, filename) : basePath;
93
92
  }
94
- async function copyDirectory(src, dest) {
95
- await import_fs2.promises.mkdir(dest, { recursive: true });
96
- const entries = await import_fs2.promises.readdir(src, { withFileTypes: true });
97
- for (const entry of entries) {
98
- const srcPath = path.join(src, entry.name);
99
- const destPath = path.join(dest, entry.name);
100
- if (entry.isDirectory()) {
101
- await copyDirectory(srcPath, destPath);
102
- } else {
103
- await import_fs2.promises.copyFile(srcPath, destPath);
104
- }
105
- }
106
- }
107
93
  function isPath(str) {
108
94
  if (path.isAbsolute(str)) return true;
109
95
  if (/[\\/]/.test(str)) return true;
@@ -161,7 +147,6 @@ function getDextoEnvPath(startPath = process.cwd(), logger) {
161
147
  }
162
148
  // Annotate the CommonJS export names for ESM import in node:
163
149
  0 && (module.exports = {
164
- copyDirectory,
165
150
  ensureDextoGlobalDirectory,
166
151
  findPackageRoot,
167
152
  getDextoEnvPath,
@@ -23,12 +23,6 @@ export declare function getDextoPath(type: string, filename?: string, startPath?
23
23
  * @returns Absolute path to the global location (~/.dexto/...)
24
24
  */
25
25
  export declare function getDextoGlobalPath(type: string, filename?: string): string;
26
- /**
27
- * Copy entire directory recursively
28
- * @param src Source directory path
29
- * @param dest Destination directory path
30
- */
31
- export declare function copyDirectory(src: string, dest: string): Promise<void>;
32
26
  /**
33
27
  * Check if string looks like a file path vs registry name
34
28
  * @param str String to check
@@ -1 +1 @@
1
- {"version":3,"file":"path.d.ts","sourceRoot":"","sources":["../../src/utils/path.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAEpD;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAuCxF;AAED;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAc1E;AAED;;;;GAIG;AACH,wBAAsB,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAe5E;AAED;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAW3C;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,SAAS,GAAE,MAAsB,GAAG,MAAM,GAAG,IAAI,CAKhF;AAMD;;GAEG;AACH,wBAAsB,0BAA0B,IAAI,OAAO,CAAC,IAAI,CAAC,CAUhE;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,SAAS,GAAE,MAAsB,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAkC1F"}
1
+ {"version":3,"file":"path.d.ts","sourceRoot":"","sources":["../../src/utils/path.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAEpD;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAuCxF;AAED;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAc1E;AAED;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAW3C;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,SAAS,GAAE,MAAsB,GAAG,MAAM,GAAG,IAAI,CAKhF;AAMD;;GAEG;AACH,wBAAsB,0BAA0B,IAAI,OAAO,CAAC,IAAI,CAAC,CAUhE;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,SAAS,GAAE,MAAsB,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAkC1F"}
@@ -57,19 +57,6 @@ function getDextoGlobalPath(type, filename) {
57
57
  const basePath = path.join(homedir(), ".dexto", type);
58
58
  return filename ? path.join(basePath, filename) : basePath;
59
59
  }
60
- async function copyDirectory(src, dest) {
61
- await fs.mkdir(dest, { recursive: true });
62
- const entries = await fs.readdir(src, { withFileTypes: true });
63
- for (const entry of entries) {
64
- const srcPath = path.join(src, entry.name);
65
- const destPath = path.join(dest, entry.name);
66
- if (entry.isDirectory()) {
67
- await copyDirectory(srcPath, destPath);
68
- } else {
69
- await fs.copyFile(srcPath, destPath);
70
- }
71
- }
72
- }
73
60
  function isPath(str) {
74
61
  if (path.isAbsolute(str)) return true;
75
62
  if (/[\\/]/.test(str)) return true;
@@ -126,7 +113,6 @@ function getDextoEnvPath(startPath = process.cwd(), logger) {
126
113
  return envPath;
127
114
  }
128
115
  export {
129
- copyDirectory,
130
116
  ensureDextoGlobalDirectory,
131
117
  findPackageRoot,
132
118
  getDextoEnvPath,
@@ -18,6 +18,10 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var redactor_exports = {};
20
20
  __export(redactor_exports, {
21
+ UNREDACTABLE_LOG_DATA: () => UNREDACTABLE_LOG_DATA,
22
+ redactLogMessage: () => redactLogMessage,
23
+ redactLogRecord: () => redactLogRecord,
24
+ redactLogText: () => redactLogText,
21
25
  redactSensitiveData: () => redactSensitiveData
22
26
  });
23
27
  module.exports = __toCommonJS(redactor_exports);
@@ -28,7 +32,14 @@ const SENSITIVE_FIELDS = [
28
32
  "access_token",
29
33
  "refresh_token",
30
34
  "password",
31
- "secret"
35
+ "secret",
36
+ "client_secret",
37
+ "private_key",
38
+ "authorization",
39
+ "proxy-authorization",
40
+ "cookie",
41
+ "set-cookie",
42
+ "x-api-key"
32
43
  ];
33
44
  const FILE_DATA_FIELDS = [
34
45
  "base64",
@@ -154,46 +165,243 @@ function redactText(text, awsAccessKeyIdPattern, keepTokenValue) {
154
165
  )
155
166
  );
156
167
  }
157
- function redactSensitiveData(input, seen = /* @__PURE__ */ new WeakSet()) {
168
+ function redactString(input) {
169
+ const signedUrls = [];
170
+ const withPlaceholders = input.includes("\uE000") ? input : input.split(URL_PATTERN).map((part, index) => {
171
+ if (index % 2 === 0 || !isSignedUrl(part)) return part;
172
+ signedUrls.push(part);
173
+ return `\uE000${signedUrls.length - 1}\uE000`;
174
+ }).join("");
175
+ const result = redactText(withPlaceholders, AWS_ACCESS_KEY_ID_PATTERN, false);
176
+ return signedUrls.length === 0 ? result : result.replace(SIGNED_URL_PLACEHOLDER, (_placeholder, index) => {
177
+ const url = signedUrls[Number(index)];
178
+ return url === void 0 ? REDACTED : redactText(url, AWS_ACCESS_KEY_ID_OUTSIDE_CREDENTIAL_PATTERN, true);
179
+ });
180
+ }
181
+ const MAX_LOG_DEPTH = 20;
182
+ const MAX_LOG_NODES = 5e3;
183
+ const TRUNCATED = "[Truncated]";
184
+ const SHARED = "[Shared]";
185
+ const UNREDACTABLE_LOG_DATA = "[unredactable log data]";
186
+ function describeBinary(value) {
187
+ const name = value instanceof ArrayBuffer ? "ArrayBuffer" : value.constructor.name;
188
+ return `[${name} ${value.byteLength} bytes]`;
189
+ }
190
+ function redactValue(input, walk, mode, insideSecret, depth = 0) {
158
191
  if (typeof input === "string") {
159
- const signedUrls = [];
160
- const withPlaceholders = input.includes("\uE000") ? input : input.split(URL_PATTERN).map((part, index) => {
161
- if (index % 2 === 0 || !isSignedUrl(part)) return part;
162
- signedUrls.push(part);
163
- return `\uE000${signedUrls.length - 1}\uE000`;
164
- }).join("");
165
- const result = redactText(withPlaceholders, AWS_ACCESS_KEY_ID_PATTERN, false);
166
- return signedUrls.length === 0 ? result : result.replace(SIGNED_URL_PLACEHOLDER, (_placeholder, index) => {
167
- const url = signedUrls[Number(index)];
168
- return url === void 0 ? REDACTED : redactText(url, AWS_ACCESS_KEY_ID_OUTSIDE_CREDENTIAL_PATTERN, true);
169
- });
170
- }
171
- if (Array.isArray(input)) {
172
- if (seen.has(input)) return REDACTED_CIRCULAR;
173
- seen.add(input);
174
- return input.map((item) => redactSensitiveData(item, seen));
175
- }
176
- if (input && typeof input === "object") {
177
- if (seen.has(input)) return REDACTED_CIRCULAR;
178
- seen.add(input);
179
- const result = {};
180
- for (const [key, value] of Object.entries(input)) {
181
- if (SENSITIVE_FIELDS.includes(key.toLowerCase())) {
182
- result[key] = REDACTED;
183
- } else {
184
- const truncatedValue = truncateFileData(
185
- value,
186
- key,
187
- input
192
+ if (insideSecret) return REDACTED;
193
+ return mode === "log" ? redactLogString(input) : redactString(input);
194
+ }
195
+ if (typeof input !== "object" || input === null) return input;
196
+ if (input instanceof ArrayBuffer || ArrayBuffer.isView(input)) return describeBinary(input);
197
+ if (input instanceof Date) {
198
+ return Number.isNaN(input.getTime()) ? "Invalid Date" : input.toISOString();
199
+ }
200
+ if (input instanceof RegExp) return String(input);
201
+ if (input instanceof URL) {
202
+ const withoutCredentials = new URL(input.href);
203
+ withoutCredentials.username = "";
204
+ withoutCredentials.password = "";
205
+ return redactValue(withoutCredentials.href, walk, mode, insideSecret, depth);
206
+ }
207
+ if (walk.ancestors.has(input)) return REDACTED_CIRCULAR;
208
+ if (walk.shared?.has(input)) return insideSecret ? REDACTED : SHARED;
209
+ const memoized = walk.memo?.get(input);
210
+ if (memoized !== void 0) return memoized;
211
+ if (mode === "log" && depth >= MAX_LOG_DEPTH) return TRUNCATED;
212
+ if (walk.remaining <= 0) return TRUNCATED;
213
+ walk.remaining -= 1;
214
+ walk.ancestors.add(input);
215
+ try {
216
+ const result = redactContainer(input, walk, mode, insideSecret, depth + 1);
217
+ walk.memo?.set(input, result);
218
+ walk.shared?.add(input);
219
+ return result;
220
+ } finally {
221
+ walk.ancestors.delete(input);
222
+ }
223
+ }
224
+ function errorFields(error) {
225
+ const toJSON = Reflect.get(error, "toJSON");
226
+ const json = typeof toJSON === "function" ? toJSON.call(error) : void 0;
227
+ return {
228
+ name: error.name,
229
+ message: error.message,
230
+ stack: error.stack,
231
+ ...error.cause !== void 0 && { cause: error.cause },
232
+ ...Object.fromEntries(Object.entries(error)),
233
+ ...typeof json === "object" && json !== null ? Object.fromEntries(Object.entries(json)) : {}
234
+ };
235
+ }
236
+ function redactContainer(input, walk, mode, insideSecret, depth) {
237
+ if (Array.isArray(input) || input instanceof Set) {
238
+ return [...input].map((item) => redactValue(item, walk, mode, insideSecret, depth));
239
+ }
240
+ if (input instanceof Map) {
241
+ return [...input].map(([key, value]) => [
242
+ redactValue(key, walk, mode, insideSecret, depth),
243
+ redactEntry(String(key), value, walk, mode, insideSecret, depth)
244
+ ]);
245
+ }
246
+ const fields = mode === "log" && input instanceof Error ? errorFields(input) : Object.fromEntries(Object.entries(input));
247
+ const result = {};
248
+ for (const [key, value] of Object.entries(fields)) {
249
+ if (SENSITIVE_FIELDS.includes(key.toLowerCase())) {
250
+ result[key] = REDACTED;
251
+ continue;
252
+ }
253
+ const truncatedValue = truncateFileData(value, key, fields);
254
+ result[key] = redactEntry(key, truncatedValue, walk, mode, insideSecret, depth);
255
+ }
256
+ return result;
257
+ }
258
+ function redactEntry(key, value, walk, mode, insideSecret, depth) {
259
+ if (mode === "log" && !insideSecret) {
260
+ if (isSecretMapKey(key) && isPlainObject(value)) {
261
+ return redactValue(value, walk, mode, true, depth);
262
+ }
263
+ if (isSensitiveLogKey(key)) {
264
+ if (typeof value === "string") return REDACTED;
265
+ if (Array.isArray(value)) {
266
+ return value.map(
267
+ (item) => typeof item === "string" ? REDACTED : redactValue(item, walk, mode, false, depth)
188
268
  );
189
- result[key] = redactSensitiveData(truncatedValue, seen);
190
269
  }
191
270
  }
192
- return result;
193
271
  }
194
- return input;
272
+ return redactValue(value, walk, mode, insideSecret, depth);
273
+ }
274
+ function isPlainObject(value) {
275
+ return typeof value === "object" && value !== null && !Array.isArray(value);
276
+ }
277
+ function redactSensitiveData(input, seen = /* @__PURE__ */ new WeakSet()) {
278
+ return redactValue(
279
+ input,
280
+ { ancestors: seen, memo: /* @__PURE__ */ new WeakMap(), shared: void 0, remaining: Infinity },
281
+ "response",
282
+ false
283
+ );
284
+ }
285
+ const SENSITIVE_KEY_SUFFIXES = [
286
+ "token",
287
+ "secret",
288
+ "secrets",
289
+ "password",
290
+ "passwd",
291
+ "passphrase",
292
+ "bearer",
293
+ "credential",
294
+ "authorization",
295
+ "cookie",
296
+ "cookies",
297
+ "apikey",
298
+ "apikeys",
299
+ "privatekey",
300
+ "accesskey",
301
+ "secretkey",
302
+ "signingkey",
303
+ "encryptionkey"
304
+ ];
305
+ const SECRET_MAP_KEYS = /* @__PURE__ */ new Set(["env", "envvars", "environment", "headers"]);
306
+ function normalizeKey(key) {
307
+ return key.toLowerCase().replace(/[^a-z0-9]/g, "");
308
+ }
309
+ function isSensitiveLogKey(key) {
310
+ const normalized = normalizeKey(key);
311
+ return SENSITIVE_KEY_SUFFIXES.some((suffix) => normalized.endsWith(suffix));
312
+ }
313
+ function isSecretMapKey(key) {
314
+ return SECRET_MAP_KEYS.has(normalizeKey(key));
315
+ }
316
+ const HEADER_LINE_PATTERN = /(?<![A-Za-z0-9_-])((?:proxy-)?authorization|(?:set-)?cookie|x-api-key|x-auth-token)(\s*[:=]\s*)(?!["'\\])[^\r\n]*/gi;
317
+ const NAME_PATTERN = /(?<![A-Za-z0-9_.-])([A-Za-z][A-Za-z0-9_.-]*)(\\?["']?)(\s*[:=]\s*)/g;
318
+ const VALUE_PATTERN = /\\"(?:[^"\\]|\\(?!")){0,4096}?\\"|"(?:[^"\\]|\\.){0,4096}"|'(?:[^'\\]|\\.){0,4096}'|[^\s,;&"'}\])\\]+|["'\\][^\r\n]*/y;
319
+ const SECRET_MAP_TEXT_PATTERN = /(?<![A-Za-z0-9_-])(env|envvars|environment|headers)(\\?["']?\s*[:=]\s*)\{([^{}]{0,8192})\}/gi;
320
+ const MAP_ENTRY_PATTERN = /((?:\\?["'])?[A-Za-z0-9_.-]{1,128}(?:\\?["'])?\s*[:=]\s*)(\\"(?:[^"\\]|\\(?!")){0,4096}?\\"|"(?:[^"\\]|\\.){0,4096}"|'(?:[^'\\]|\\.){0,4096}'|[^\s,}]+)/g;
321
+ const PLAIN_VALUE_PATTERN = /^(?:\d+(?:\.\d+)?|true|false|null|undefined)$/i;
322
+ function looksLikeCredential(value) {
323
+ return /^[\\"']/.test(value) || /[^A-Za-z]/.test(value) || value.length >= 16;
324
+ }
325
+ function maskedLike(value) {
326
+ for (const quote of ['\\"', '"', "'"]) {
327
+ if (value.length >= quote.length * 2 && value.startsWith(quote) && value.endsWith(quote)) {
328
+ return `${quote}${REDACTED}${quote}`;
329
+ }
330
+ }
331
+ return REDACTED;
332
+ }
333
+ const URL_USERINFO_PATTERN = /(?<![A-Za-z0-9+.-])([A-Za-z][A-Za-z0-9+.-]{0,31}:\/\/[^\s/@:"'?#]*:)[^\s/?#"']*@/g;
334
+ function maskUrlUserinfo(text) {
335
+ return text.replace(URL_USERINFO_PATTERN, (_match, prefix) => `${prefix}${REDACTED}@`);
336
+ }
337
+ function redactLogString(text) {
338
+ return redactKeyValueText(redactString(maskUrlUserinfo(text)));
339
+ }
340
+ function redactKeyValueText(text) {
341
+ const withMaps = text.replace(
342
+ HEADER_LINE_PATTERN,
343
+ (_match, name, separator) => `${name}${separator}${REDACTED}`
344
+ ).replace(
345
+ SECRET_MAP_TEXT_PATTERN,
346
+ (_match, name, separator, entries) => `${name}${separator}{${entries.replace(
347
+ MAP_ENTRY_PATTERN,
348
+ (_entry, prefix, value) => `${prefix}${maskedLike(value)}`
349
+ )}}`
350
+ );
351
+ const names = new RegExp(NAME_PATTERN);
352
+ const values = new RegExp(VALUE_PATTERN);
353
+ let result = "";
354
+ let copiedUpTo = 0;
355
+ for (let found = names.exec(withMaps); found; found = names.exec(withMaps)) {
356
+ if (!isSensitiveLogKey(found[1] ?? "")) continue;
357
+ values.lastIndex = names.lastIndex;
358
+ const value = values.exec(withMaps)?.[0];
359
+ if (value === void 0) continue;
360
+ names.lastIndex = values.lastIndex;
361
+ if (value.startsWith(REDACTED.slice(0, -1)) || PLAIN_VALUE_PATTERN.test(value)) continue;
362
+ if (!found[3]?.includes("=") && !looksLikeCredential(value)) continue;
363
+ result += withMaps.slice(copiedUpTo, values.lastIndex - value.length) + maskedLike(value);
364
+ copiedUpTo = values.lastIndex;
365
+ }
366
+ return result + withMaps.slice(copiedUpTo);
367
+ }
368
+ function redactLogText(text) {
369
+ return redactLogString(text);
370
+ }
371
+ function redactLogMessage(message) {
372
+ try {
373
+ return redactLogText(typeof message === "string" ? message : String(message));
374
+ } catch {
375
+ return UNREDACTABLE_LOG_DATA;
376
+ }
377
+ }
378
+ function redactLogRecord(record, skip = []) {
379
+ try {
380
+ const entries = Object.entries(record).filter(([key]) => !skip.includes(key));
381
+ const redacted = redactValue(
382
+ Object.fromEntries(entries),
383
+ {
384
+ ancestors: /* @__PURE__ */ new WeakSet(),
385
+ memo: void 0,
386
+ shared: /* @__PURE__ */ new WeakSet(),
387
+ remaining: MAX_LOG_NODES
388
+ },
389
+ "log",
390
+ false
391
+ );
392
+ if (typeof redacted !== "object" || redacted === null || Array.isArray(redacted)) {
393
+ return { redacted: UNREDACTABLE_LOG_DATA };
394
+ }
395
+ return Object.fromEntries(Object.entries(redacted));
396
+ } catch {
397
+ return { redacted: UNREDACTABLE_LOG_DATA };
398
+ }
195
399
  }
196
400
  // Annotate the CommonJS export names for ESM import in node:
197
401
  0 && (module.exports = {
402
+ UNREDACTABLE_LOG_DATA,
403
+ redactLogMessage,
404
+ redactLogRecord,
405
+ redactLogText,
198
406
  redactSensitiveData
199
407
  });