@lark-codem/codem-cli 0.1.281 → 0.1.282-dev-cmj-meego-integration.100104682227.0.gc486571

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.
package/profile/debug.js CHANGED
@@ -1,5 +1,4 @@
1
1
  import { recordSelectedRuntimeLog } from "./runtime-logs.js";
2
- import { redactDebugString } from "./diagnostic-text.js";
3
2
 
4
3
  const DEBUG_ENV_KEYS = ["CODEM_DEBUG", "CODEM_BRIDGE_DEBUG"];
5
4
  const SENSITIVE_KEY_PATTERN = /^(?:authorization|token|secret|password|apikey|api_key|apiKey|ak|access_key|accessKey|secret_key|secretKey|appsecret|app_secret|login_secret|refresh_token|access_token|user_access_token|userAccessToken|refreshToken|accessToken|uat|rt|deviceSecret|device_secret|deviceSecretPlaintext|device_secret_plaintext)$/iu;
@@ -13,12 +12,19 @@ export function isDebugEnabled(env = process.env) {
13
12
  return DEBUG_ENV_KEYS.some((key) => enabledValue(env?.[key]));
14
13
  }
15
14
 
15
+ function redactString(value) {
16
+ return String(value ?? "")
17
+ .replace(/((?:Authorization|Codem-Login-Secret)\s*:\s*(?:Bearer\s+)?)[^&\s,"'}]+/giu, "$1[REDACTED]")
18
+ .replace(/("(?:authorization|token|secret|apikey|api_key|apiKey|ak|access_key|accessKey|secret_key|secretKey|refresh_token|access_token|user_access_token|userAccessToken|refreshToken|accessToken)"\s*:\s*")[^"]*(")/giu, "$1[REDACTED]$2")
19
+ .replace(/((?:refresh_token|access_token|user_access_token|refreshToken|accessToken|userAccessToken|apikey|api_key|apiKey|access_key|accessKey|secret_key|secretKey|uat|rt|token|secret|ak)\s*[=:]\s*)[^&\s,"'}]+/giu, "$1[REDACTED]");
20
+ }
21
+
16
22
  export function sanitizeDebugPayload(value, { maxStringLength = 500, depth = 0 } = {}) {
17
23
  if (value === null || value === undefined) {
18
24
  return value;
19
25
  }
20
26
  if (typeof value === "string") {
21
- const redacted = redactDebugString(value);
27
+ const redacted = redactString(value);
22
28
  return redacted.length > maxStringLength ? `${redacted.slice(0, maxStringLength - 1)}...` : redacted;
23
29
  }
24
30
  if (typeof value === "number" || typeof value === "boolean") {
@@ -59,8 +65,8 @@ export function formatDebugLine(event, payload = {}) {
59
65
  // reports have already hit that wall: a daemon rebound itself once a minute for
60
66
  // ten minutes and the structured record of *why* was gated behind a flag nobody
61
67
  // had set. High-frequency loops (per-poll sync, command lists) stay on debugLog.
62
- export function debugLogAlways(event, payload = {}, { logger = console, remoteFields = undefined } = {}) {
63
- recordSelectedRuntimeLog("bridge", event, remoteFields ? { ...payload, ...remoteFields } : payload);
68
+ export function debugLogAlways(event, payload = {}, { logger = console } = {}) {
69
+ recordSelectedRuntimeLog("bridge", event, payload);
64
70
  const line = formatDebugLine(event, payload);
65
71
  if (logger && typeof logger.info === "function") {
66
72
  logger.info(line);
@@ -72,15 +78,9 @@ export function debugLogAlways(event, payload = {}, { logger = console, remoteFi
72
78
 
73
79
  export function debugLog(event, payload = {}, {
74
80
  env = process.env,
75
- logger = console,
76
- capturedError = undefined,
77
- remoteFields = undefined
81
+ logger = console
78
82
  } = {}) {
79
- recordSelectedRuntimeLog("bridge", event, remoteFields ? { ...payload, ...remoteFields } : payload, { capturedError });
80
- return writeDebugLog(event, payload, { env, logger });
81
- }
82
-
83
- export function writeDebugLog(event, payload, { env, logger }) {
83
+ recordSelectedRuntimeLog("bridge", event, payload);
84
84
  if (!isDebugEnabled(env)) {
85
85
  return false;
86
86
  }
@@ -44,7 +44,8 @@ export async function readProfileSnapshot(home) {
44
44
  return withCodeMConfigLock(join(home, "config.json"), () => readLockedProfileSnapshot(home));
45
45
  }
46
46
 
47
- async function readLockedProfileSnapshot(home) {
47
+ // Internal callers must already hold the canonical profile config lock.
48
+ export async function readLockedProfileSnapshot(home) {
48
49
  const configPath = join(home, "config.json");
49
50
  const config = await readProfileObject(configPath);
50
51
  let metadata;
@@ -53,7 +54,7 @@ async function readLockedProfileSnapshot(home) {
53
54
  } catch (error) {
54
55
  if (!(error instanceof CredentialStorageError)) throw error;
55
56
  const kind = ["oauth", "router-ak"].includes(error.kind) ? error.kind : null;
56
- throw new CredentialStorageError(error.code.replace(/^credential_storage_/, ""), kind, error.cause !== undefined ? { cause: error.cause } : undefined);
57
+ throw new CredentialStorageError(error.code.replace(/^credential_storage_/, ""), kind);
57
58
  }
58
59
  if (!config && metadata && !metadata.loggedOut) throw new CredentialStorageError("config_missing", "oauth");
59
60
  const device = record(config?.device);
@@ -0,0 +1,9 @@
1
+ // Base bounds the JSON encoding of RPC IDs at 1024 bytes. Printable route
2
+ // keys include Go QueryEscape's percent escapes and plus sign. Only record
3
+ // identifier characters; never truncate two different IDs to the same value.
4
+ export function realtimeLogID(value) {
5
+ if (Number.isSafeInteger(value)) return value;
6
+ if (typeof value === "string" && value.length <= 1022 &&
7
+ /^[\p{L}\p{N}_.:%~+-]+$/u.test(value) && Buffer.byteLength(value) <= 1022) return value;
8
+ return undefined;
9
+ }