@dexto/core 1.16.6 → 1.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/dist/agent/schemas.d.ts +2 -2
  2. package/dist/llm/executor/turn-executor.cjs +3 -0
  3. package/dist/llm/executor/turn-executor.d.ts +5 -5
  4. package/dist/llm/executor/turn-executor.d.ts.map +1 -1
  5. package/dist/llm/executor/turn-executor.js +3 -0
  6. package/dist/llm/index.cjs +6 -0
  7. package/dist/llm/index.d.ts +2 -0
  8. package/dist/llm/index.d.ts.map +1 -1
  9. package/dist/llm/index.js +4 -0
  10. package/dist/llm/private-address.cjs +88 -0
  11. package/dist/llm/private-address.d.ts +3 -0
  12. package/dist/llm/private-address.d.ts.map +1 -0
  13. package/dist/llm/private-address.js +65 -0
  14. package/dist/llm/safe-download.cjs +159 -0
  15. package/dist/llm/safe-download.d.ts +21 -0
  16. package/dist/llm/safe-download.d.ts.map +1 -0
  17. package/dist/llm/safe-download.js +126 -0
  18. package/dist/logger/logger.cjs +8 -9
  19. package/dist/logger/logger.d.ts.map +1 -1
  20. package/dist/logger/logger.js +8 -9
  21. package/dist/logger/v2/dexto-logger.cjs +3 -2
  22. package/dist/logger/v2/dexto-logger.d.ts.map +1 -1
  23. package/dist/logger/v2/dexto-logger.js +3 -2
  24. package/dist/mcp/mcp-client.cjs +17 -8
  25. package/dist/mcp/mcp-client.d.ts +4 -2
  26. package/dist/mcp/mcp-client.d.ts.map +1 -1
  27. package/dist/mcp/mcp-client.js +17 -8
  28. package/dist/mcp/schemas.cjs +3 -0
  29. package/dist/mcp/schemas.d.ts +3 -0
  30. package/dist/mcp/schemas.d.ts.map +1 -1
  31. package/dist/mcp/schemas.js +3 -0
  32. package/dist/resources/handlers/filesystem-handler.cjs +7 -6
  33. package/dist/resources/handlers/filesystem-handler.d.ts.map +1 -1
  34. package/dist/resources/handlers/filesystem-handler.js +7 -6
  35. package/dist/systemPrompt/schemas.d.ts +3 -3
  36. package/dist/telemetry/decorators.cjs +2 -2
  37. package/dist/telemetry/decorators.js +2 -2
  38. package/dist/utils/index.cjs +3 -1
  39. package/dist/utils/index.d.ts +1 -0
  40. package/dist/utils/index.d.ts.map +1 -1
  41. package/dist/utils/index.js +1 -0
  42. package/dist/utils/metadata-address.cjs +138 -0
  43. package/dist/utils/metadata-address.d.ts +24 -0
  44. package/dist/utils/metadata-address.d.ts.map +1 -0
  45. package/dist/utils/metadata-address.js +113 -0
  46. package/dist/utils/path.cjs +0 -15
  47. package/dist/utils/path.d.ts +0 -6
  48. package/dist/utils/path.d.ts.map +1 -1
  49. package/dist/utils/path.js +0 -14
  50. package/dist/utils/redactor.cjs +242 -34
  51. package/dist/utils/redactor.d.ts +15 -0
  52. package/dist/utils/redactor.d.ts.map +1 -1
  53. package/dist/utils/redactor.js +238 -34
  54. package/dist/workspace/index.cjs +7 -2
  55. package/dist/workspace/index.d.ts +1 -0
  56. package/dist/workspace/index.d.ts.map +1 -1
  57. package/dist/workspace/index.js +4 -1
  58. package/dist/workspace/shell-environment.cjs +96 -0
  59. package/dist/workspace/shell-environment.d.ts +18 -0
  60. package/dist/workspace/shell-environment.d.ts.map +1 -0
  61. package/dist/workspace/shell-environment.js +72 -0
  62. package/dist/workspace/types.d.ts +9 -0
  63. package/dist/workspace/types.d.ts.map +1 -1
  64. package/package.json +2 -2
@@ -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
  });
@@ -6,5 +6,20 @@
6
6
  * - Recursive and preserves structure
7
7
  * - Easy to extend
8
8
  */
9
+ /** The text a logger writes when it could not redact an entry, never the entry itself. */
10
+ export declare const UNREDACTABLE_LOG_DATA = "[unredactable log data]";
9
11
  export declare function redactSensitiveData(input: unknown, seen?: WeakSet<object>): unknown;
12
+ /** Redacts one log message: known secret shapes, then the value of any secret-named key. */
13
+ export declare function redactLogText(text: string): string;
14
+ /**
15
+ * A log message of any type, as redacted text. Never throws: an entry that cannot be read is
16
+ * replaced by UNREDACTABLE_LOG_DATA, not passed on as it was.
17
+ */
18
+ export declare function redactLogMessage(message: unknown): string;
19
+ /**
20
+ * A log record (context or metadata) with secrets masked, leaving out `skip`. Never throws: a
21
+ * record that cannot be read (a throwing getter, a revoked proxy) becomes one key holding
22
+ * UNREDACTABLE_LOG_DATA, not the record itself.
23
+ */
24
+ export declare function redactLogRecord(record: object, skip?: readonly string[]): Record<string, unknown>;
10
25
  //# sourceMappingURL=redactor.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"redactor.d.ts","sourceRoot":"","sources":["../../src/utils/redactor.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAgNH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,kBAAgB,GAAG,OAAO,CAqDjF"}
1
+ {"version":3,"file":"redactor.d.ts","sourceRoot":"","sources":["../../src/utils/redactor.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAiQH,0FAA0F;AAC1F,eAAO,MAAM,qBAAqB,4BAA4B,CAAC;AAoJ/D,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,kBAAwB,GAAG,OAAO,CAOzF;AA4ID,4FAA4F;AAC5F,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAElD;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAMzD;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAC3B,MAAM,EAAE,MAAM,EACd,IAAI,GAAE,SAAS,MAAM,EAAO,GAC7B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAqBzB"}
@@ -6,7 +6,14 @@ const SENSITIVE_FIELDS = [
6
6
  "access_token",
7
7
  "refresh_token",
8
8
  "password",
9
- "secret"
9
+ "secret",
10
+ "client_secret",
11
+ "private_key",
12
+ "authorization",
13
+ "proxy-authorization",
14
+ "cookie",
15
+ "set-cookie",
16
+ "x-api-key"
10
17
  ];
11
18
  const FILE_DATA_FIELDS = [
12
19
  "base64",
@@ -132,45 +139,242 @@ function redactText(text, awsAccessKeyIdPattern, keepTokenValue) {
132
139
  )
133
140
  );
134
141
  }
135
- function redactSensitiveData(input, seen = /* @__PURE__ */ new WeakSet()) {
142
+ function redactString(input) {
143
+ const signedUrls = [];
144
+ const withPlaceholders = input.includes("\uE000") ? input : input.split(URL_PATTERN).map((part, index) => {
145
+ if (index % 2 === 0 || !isSignedUrl(part)) return part;
146
+ signedUrls.push(part);
147
+ return `\uE000${signedUrls.length - 1}\uE000`;
148
+ }).join("");
149
+ const result = redactText(withPlaceholders, AWS_ACCESS_KEY_ID_PATTERN, false);
150
+ return signedUrls.length === 0 ? result : result.replace(SIGNED_URL_PLACEHOLDER, (_placeholder, index) => {
151
+ const url = signedUrls[Number(index)];
152
+ return url === void 0 ? REDACTED : redactText(url, AWS_ACCESS_KEY_ID_OUTSIDE_CREDENTIAL_PATTERN, true);
153
+ });
154
+ }
155
+ const MAX_LOG_DEPTH = 20;
156
+ const MAX_LOG_NODES = 5e3;
157
+ const TRUNCATED = "[Truncated]";
158
+ const SHARED = "[Shared]";
159
+ const UNREDACTABLE_LOG_DATA = "[unredactable log data]";
160
+ function describeBinary(value) {
161
+ const name = value instanceof ArrayBuffer ? "ArrayBuffer" : value.constructor.name;
162
+ return `[${name} ${value.byteLength} bytes]`;
163
+ }
164
+ function redactValue(input, walk, mode, insideSecret, depth = 0) {
136
165
  if (typeof input === "string") {
137
- const signedUrls = [];
138
- const withPlaceholders = input.includes("\uE000") ? input : input.split(URL_PATTERN).map((part, index) => {
139
- if (index % 2 === 0 || !isSignedUrl(part)) return part;
140
- signedUrls.push(part);
141
- return `\uE000${signedUrls.length - 1}\uE000`;
142
- }).join("");
143
- const result = redactText(withPlaceholders, AWS_ACCESS_KEY_ID_PATTERN, false);
144
- return signedUrls.length === 0 ? result : result.replace(SIGNED_URL_PLACEHOLDER, (_placeholder, index) => {
145
- const url = signedUrls[Number(index)];
146
- return url === void 0 ? REDACTED : redactText(url, AWS_ACCESS_KEY_ID_OUTSIDE_CREDENTIAL_PATTERN, true);
147
- });
148
- }
149
- if (Array.isArray(input)) {
150
- if (seen.has(input)) return REDACTED_CIRCULAR;
151
- seen.add(input);
152
- return input.map((item) => redactSensitiveData(item, seen));
153
- }
154
- if (input && typeof input === "object") {
155
- if (seen.has(input)) return REDACTED_CIRCULAR;
156
- seen.add(input);
157
- const result = {};
158
- for (const [key, value] of Object.entries(input)) {
159
- if (SENSITIVE_FIELDS.includes(key.toLowerCase())) {
160
- result[key] = REDACTED;
161
- } else {
162
- const truncatedValue = truncateFileData(
163
- value,
164
- key,
165
- input
166
+ if (insideSecret) return REDACTED;
167
+ return mode === "log" ? redactLogString(input) : redactString(input);
168
+ }
169
+ if (typeof input !== "object" || input === null) return input;
170
+ if (input instanceof ArrayBuffer || ArrayBuffer.isView(input)) return describeBinary(input);
171
+ if (input instanceof Date) {
172
+ return Number.isNaN(input.getTime()) ? "Invalid Date" : input.toISOString();
173
+ }
174
+ if (input instanceof RegExp) return String(input);
175
+ if (input instanceof URL) {
176
+ const withoutCredentials = new URL(input.href);
177
+ withoutCredentials.username = "";
178
+ withoutCredentials.password = "";
179
+ return redactValue(withoutCredentials.href, walk, mode, insideSecret, depth);
180
+ }
181
+ if (walk.ancestors.has(input)) return REDACTED_CIRCULAR;
182
+ if (walk.shared?.has(input)) return insideSecret ? REDACTED : SHARED;
183
+ const memoized = walk.memo?.get(input);
184
+ if (memoized !== void 0) return memoized;
185
+ if (mode === "log" && depth >= MAX_LOG_DEPTH) return TRUNCATED;
186
+ if (walk.remaining <= 0) return TRUNCATED;
187
+ walk.remaining -= 1;
188
+ walk.ancestors.add(input);
189
+ try {
190
+ const result = redactContainer(input, walk, mode, insideSecret, depth + 1);
191
+ walk.memo?.set(input, result);
192
+ walk.shared?.add(input);
193
+ return result;
194
+ } finally {
195
+ walk.ancestors.delete(input);
196
+ }
197
+ }
198
+ function errorFields(error) {
199
+ const toJSON = Reflect.get(error, "toJSON");
200
+ const json = typeof toJSON === "function" ? toJSON.call(error) : void 0;
201
+ return {
202
+ name: error.name,
203
+ message: error.message,
204
+ stack: error.stack,
205
+ ...error.cause !== void 0 && { cause: error.cause },
206
+ ...Object.fromEntries(Object.entries(error)),
207
+ ...typeof json === "object" && json !== null ? Object.fromEntries(Object.entries(json)) : {}
208
+ };
209
+ }
210
+ function redactContainer(input, walk, mode, insideSecret, depth) {
211
+ if (Array.isArray(input) || input instanceof Set) {
212
+ return [...input].map((item) => redactValue(item, walk, mode, insideSecret, depth));
213
+ }
214
+ if (input instanceof Map) {
215
+ return [...input].map(([key, value]) => [
216
+ redactValue(key, walk, mode, insideSecret, depth),
217
+ redactEntry(String(key), value, walk, mode, insideSecret, depth)
218
+ ]);
219
+ }
220
+ const fields = mode === "log" && input instanceof Error ? errorFields(input) : Object.fromEntries(Object.entries(input));
221
+ const result = {};
222
+ for (const [key, value] of Object.entries(fields)) {
223
+ if (SENSITIVE_FIELDS.includes(key.toLowerCase())) {
224
+ result[key] = REDACTED;
225
+ continue;
226
+ }
227
+ const truncatedValue = truncateFileData(value, key, fields);
228
+ result[key] = redactEntry(key, truncatedValue, walk, mode, insideSecret, depth);
229
+ }
230
+ return result;
231
+ }
232
+ function redactEntry(key, value, walk, mode, insideSecret, depth) {
233
+ if (mode === "log" && !insideSecret) {
234
+ if (isSecretMapKey(key) && isPlainObject(value)) {
235
+ return redactValue(value, walk, mode, true, depth);
236
+ }
237
+ if (isSensitiveLogKey(key)) {
238
+ if (typeof value === "string") return REDACTED;
239
+ if (Array.isArray(value)) {
240
+ return value.map(
241
+ (item) => typeof item === "string" ? REDACTED : redactValue(item, walk, mode, false, depth)
166
242
  );
167
- result[key] = redactSensitiveData(truncatedValue, seen);
168
243
  }
169
244
  }
170
- return result;
171
245
  }
172
- return input;
246
+ return redactValue(value, walk, mode, insideSecret, depth);
247
+ }
248
+ function isPlainObject(value) {
249
+ return typeof value === "object" && value !== null && !Array.isArray(value);
250
+ }
251
+ function redactSensitiveData(input, seen = /* @__PURE__ */ new WeakSet()) {
252
+ return redactValue(
253
+ input,
254
+ { ancestors: seen, memo: /* @__PURE__ */ new WeakMap(), shared: void 0, remaining: Infinity },
255
+ "response",
256
+ false
257
+ );
258
+ }
259
+ const SENSITIVE_KEY_SUFFIXES = [
260
+ "token",
261
+ "secret",
262
+ "secrets",
263
+ "password",
264
+ "passwd",
265
+ "passphrase",
266
+ "bearer",
267
+ "credential",
268
+ "authorization",
269
+ "cookie",
270
+ "cookies",
271
+ "apikey",
272
+ "apikeys",
273
+ "privatekey",
274
+ "accesskey",
275
+ "secretkey",
276
+ "signingkey",
277
+ "encryptionkey"
278
+ ];
279
+ const SECRET_MAP_KEYS = /* @__PURE__ */ new Set(["env", "envvars", "environment", "headers"]);
280
+ function normalizeKey(key) {
281
+ return key.toLowerCase().replace(/[^a-z0-9]/g, "");
282
+ }
283
+ function isSensitiveLogKey(key) {
284
+ const normalized = normalizeKey(key);
285
+ return SENSITIVE_KEY_SUFFIXES.some((suffix) => normalized.endsWith(suffix));
286
+ }
287
+ function isSecretMapKey(key) {
288
+ return SECRET_MAP_KEYS.has(normalizeKey(key));
289
+ }
290
+ const HEADER_LINE_PATTERN = /(?<![A-Za-z0-9_-])((?:proxy-)?authorization|(?:set-)?cookie|x-api-key|x-auth-token)(\s*[:=]\s*)(?!["'\\])[^\r\n]*/gi;
291
+ const NAME_PATTERN = /(?<![A-Za-z0-9_.-])([A-Za-z][A-Za-z0-9_.-]*)(\\?["']?)(\s*[:=]\s*)/g;
292
+ const VALUE_PATTERN = /\\"(?:[^"\\]|\\(?!")){0,4096}?\\"|"(?:[^"\\]|\\.){0,4096}"|'(?:[^'\\]|\\.){0,4096}'|[^\s,;&"'}\])\\]+|["'\\][^\r\n]*/y;
293
+ const SECRET_MAP_TEXT_PATTERN = /(?<![A-Za-z0-9_-])(env|envvars|environment|headers)(\\?["']?\s*[:=]\s*)\{([^{}]{0,8192})\}/gi;
294
+ const MAP_ENTRY_PATTERN = /((?:\\?["'])?[A-Za-z0-9_.-]{1,128}(?:\\?["'])?\s*[:=]\s*)(\\"(?:[^"\\]|\\(?!")){0,4096}?\\"|"(?:[^"\\]|\\.){0,4096}"|'(?:[^'\\]|\\.){0,4096}'|[^\s,}]+)/g;
295
+ const PLAIN_VALUE_PATTERN = /^(?:\d+(?:\.\d+)?|true|false|null|undefined)$/i;
296
+ function looksLikeCredential(value) {
297
+ return /^[\\"']/.test(value) || /[^A-Za-z]/.test(value) || value.length >= 16;
298
+ }
299
+ function maskedLike(value) {
300
+ for (const quote of ['\\"', '"', "'"]) {
301
+ if (value.length >= quote.length * 2 && value.startsWith(quote) && value.endsWith(quote)) {
302
+ return `${quote}${REDACTED}${quote}`;
303
+ }
304
+ }
305
+ return REDACTED;
306
+ }
307
+ const URL_USERINFO_PATTERN = /(?<![A-Za-z0-9+.-])([A-Za-z][A-Za-z0-9+.-]{0,31}:\/\/[^\s/@:"'?#]*:)[^\s/?#"']*@/g;
308
+ function maskUrlUserinfo(text) {
309
+ return text.replace(URL_USERINFO_PATTERN, (_match, prefix) => `${prefix}${REDACTED}@`);
310
+ }
311
+ function redactLogString(text) {
312
+ return redactKeyValueText(redactString(maskUrlUserinfo(text)));
313
+ }
314
+ function redactKeyValueText(text) {
315
+ const withMaps = text.replace(
316
+ HEADER_LINE_PATTERN,
317
+ (_match, name, separator) => `${name}${separator}${REDACTED}`
318
+ ).replace(
319
+ SECRET_MAP_TEXT_PATTERN,
320
+ (_match, name, separator, entries) => `${name}${separator}{${entries.replace(
321
+ MAP_ENTRY_PATTERN,
322
+ (_entry, prefix, value) => `${prefix}${maskedLike(value)}`
323
+ )}}`
324
+ );
325
+ const names = new RegExp(NAME_PATTERN);
326
+ const values = new RegExp(VALUE_PATTERN);
327
+ let result = "";
328
+ let copiedUpTo = 0;
329
+ for (let found = names.exec(withMaps); found; found = names.exec(withMaps)) {
330
+ if (!isSensitiveLogKey(found[1] ?? "")) continue;
331
+ values.lastIndex = names.lastIndex;
332
+ const value = values.exec(withMaps)?.[0];
333
+ if (value === void 0) continue;
334
+ names.lastIndex = values.lastIndex;
335
+ if (value.startsWith(REDACTED.slice(0, -1)) || PLAIN_VALUE_PATTERN.test(value)) continue;
336
+ if (!found[3]?.includes("=") && !looksLikeCredential(value)) continue;
337
+ result += withMaps.slice(copiedUpTo, values.lastIndex - value.length) + maskedLike(value);
338
+ copiedUpTo = values.lastIndex;
339
+ }
340
+ return result + withMaps.slice(copiedUpTo);
341
+ }
342
+ function redactLogText(text) {
343
+ return redactLogString(text);
344
+ }
345
+ function redactLogMessage(message) {
346
+ try {
347
+ return redactLogText(typeof message === "string" ? message : String(message));
348
+ } catch {
349
+ return UNREDACTABLE_LOG_DATA;
350
+ }
351
+ }
352
+ function redactLogRecord(record, skip = []) {
353
+ try {
354
+ const entries = Object.entries(record).filter(([key]) => !skip.includes(key));
355
+ const redacted = redactValue(
356
+ Object.fromEntries(entries),
357
+ {
358
+ ancestors: /* @__PURE__ */ new WeakSet(),
359
+ memo: void 0,
360
+ shared: /* @__PURE__ */ new WeakSet(),
361
+ remaining: MAX_LOG_NODES
362
+ },
363
+ "log",
364
+ false
365
+ );
366
+ if (typeof redacted !== "object" || redacted === null || Array.isArray(redacted)) {
367
+ return { redacted: UNREDACTABLE_LOG_DATA };
368
+ }
369
+ return Object.fromEntries(Object.entries(redacted));
370
+ } catch {
371
+ return { redacted: UNREDACTABLE_LOG_DATA };
372
+ }
173
373
  }
174
374
  export {
375
+ UNREDACTABLE_LOG_DATA,
376
+ redactLogMessage,
377
+ redactLogRecord,
378
+ redactLogText,
175
379
  redactSensitiveData
176
380
  };
@@ -20,15 +20,20 @@ var workspace_exports = {};
20
20
  __export(workspace_exports, {
21
21
  WorkspaceError: () => import_errors.WorkspaceError,
22
22
  WorkspaceErrorCodes: () => import_error_codes.WorkspaceErrorCodes,
23
- WorkspaceManager: () => import_manager.WorkspaceManager
23
+ WorkspaceManager: () => import_manager.WorkspaceManager,
24
+ buildShellEnvironment: () => import_shell_environment.buildShellEnvironment,
25
+ pickHostVariables: () => import_shell_environment.pickHostVariables
24
26
  });
25
27
  module.exports = __toCommonJS(workspace_exports);
26
28
  var import_manager = require("./manager.js");
27
29
  var import_errors = require("./errors.js");
28
30
  var import_error_codes = require("./error-codes.js");
31
+ var import_shell_environment = require("./shell-environment.js");
29
32
  // Annotate the CommonJS export names for ESM import in node:
30
33
  0 && (module.exports = {
31
34
  WorkspaceError,
32
35
  WorkspaceErrorCodes,
33
- WorkspaceManager
36
+ WorkspaceManager,
37
+ buildShellEnvironment,
38
+ pickHostVariables
34
39
  });
@@ -1,5 +1,6 @@
1
1
  export { WorkspaceManager } from './manager.js';
2
2
  export { WorkspaceError } from './errors.js';
3
3
  export { WorkspaceErrorCodes } from './error-codes.js';
4
+ export { buildShellEnvironment, pickHostVariables } from './shell-environment.js';
4
5
  export type { OpenWorkspaceInput, SetWorkspaceInput, WorkspaceApps, WorkspaceCapability, WorkspaceContext, WorkspaceFiles, WorkspaceHandle, WorkspaceHandleProvider, WorkspacePreview, WorkspaceProcesses, } from './types.js';
5
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/workspace/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,YAAY,EACR,kBAAkB,EAClB,iBAAiB,EACjB,aAAa,EACb,mBAAmB,EACnB,gBAAgB,EAChB,cAAc,EACd,eAAe,EACf,uBAAuB,EACvB,gBAAgB,EAChB,kBAAkB,GACrB,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/workspace/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAClF,YAAY,EACR,kBAAkB,EAClB,iBAAiB,EACjB,aAAa,EACb,mBAAmB,EACnB,gBAAgB,EAChB,cAAc,EACd,eAAe,EACf,uBAAuB,EACvB,gBAAgB,EAChB,kBAAkB,GACrB,MAAM,YAAY,CAAC"}
@@ -2,8 +2,11 @@ import "../chunk-C6A6W6XS.js";
2
2
  import { WorkspaceManager } from "./manager.js";
3
3
  import { WorkspaceError } from "./errors.js";
4
4
  import { WorkspaceErrorCodes } from "./error-codes.js";
5
+ import { buildShellEnvironment, pickHostVariables } from "./shell-environment.js";
5
6
  export {
6
7
  WorkspaceError,
7
8
  WorkspaceErrorCodes,
8
- WorkspaceManager
9
+ WorkspaceManager,
10
+ buildShellEnvironment,
11
+ pickHostVariables
9
12
  };