trickle-observe 0.2.100 → 0.2.101
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/dist/observe-register.js +30 -0
- package/package.json +1 -1
- package/src/observe-register.ts +28 -0
package/dist/observe-register.js
CHANGED
|
@@ -1016,6 +1016,36 @@ if (enabled) {
|
|
|
1016
1016
|
if (process.env.TRICKLE_TRACE_VARS !== '0') {
|
|
1017
1017
|
(0, trace_var_1.initVarTracer)({ debug });
|
|
1018
1018
|
}
|
|
1019
|
+
// ── Hook 0c: Capture environment snapshot ──
|
|
1020
|
+
try {
|
|
1021
|
+
const envDir = process.env.TRICKLE_LOCAL_DIR || path_1.default.join(process.cwd(), '.trickle');
|
|
1022
|
+
fs_1.default.mkdirSync(envDir, { recursive: true });
|
|
1023
|
+
const SENSITIVE = ['KEY', 'SECRET', 'TOKEN', 'PASSWORD', 'AUTH', 'CREDENTIAL', 'PRIVATE'];
|
|
1024
|
+
const isSensitive = (k) => SENSITIVE.some(s => k.toUpperCase().includes(s));
|
|
1025
|
+
const redact = (k, v) => isSensitive(k) ? (v.length <= 4 ? '****' : v.slice(0, 2) + '*'.repeat(v.length - 4) + v.slice(-2)) : v;
|
|
1026
|
+
const skip = new Set(['PATH', 'HOME', 'USER', 'SHELL', 'TERM', 'LANG', 'LOGNAME', 'PWD', 'OLDPWD', 'SHLVL', 'TMPDIR']);
|
|
1027
|
+
const trickleVars = {};
|
|
1028
|
+
const appVars = {};
|
|
1029
|
+
for (const [k, v] of Object.entries(process.env)) {
|
|
1030
|
+
if (!v || k.startsWith('_'))
|
|
1031
|
+
continue;
|
|
1032
|
+
if (k.startsWith('TRICKLE_'))
|
|
1033
|
+
trickleVars[k] = v;
|
|
1034
|
+
else if (!skip.has(k))
|
|
1035
|
+
appVars[k] = redact(k, v);
|
|
1036
|
+
}
|
|
1037
|
+
const envSnapshot = {
|
|
1038
|
+
kind: 'environment',
|
|
1039
|
+
timestamp: Date.now(),
|
|
1040
|
+
node: { version: process.version, platform: process.platform, arch: process.arch },
|
|
1041
|
+
cwd: process.cwd(),
|
|
1042
|
+
argv: process.argv.slice(0, 10),
|
|
1043
|
+
trickle: trickleVars,
|
|
1044
|
+
env: appVars,
|
|
1045
|
+
};
|
|
1046
|
+
fs_1.default.writeFileSync(path_1.default.join(envDir, 'environment.json'), JSON.stringify(envSnapshot, null, 2));
|
|
1047
|
+
}
|
|
1048
|
+
catch { }
|
|
1019
1049
|
// ── Hook 1: Module._compile — transform source to wrap function declarations ──
|
|
1020
1050
|
// This catches ALL functions including entry file and non-exported helpers.
|
|
1021
1051
|
M.prototype._compile = function hookedCompile(content, filename) {
|
package/package.json
CHANGED
package/src/observe-register.ts
CHANGED
|
@@ -1004,6 +1004,34 @@ if (enabled) {
|
|
|
1004
1004
|
initVarTracer({ debug });
|
|
1005
1005
|
}
|
|
1006
1006
|
|
|
1007
|
+
// ── Hook 0c: Capture environment snapshot ──
|
|
1008
|
+
try {
|
|
1009
|
+
const envDir = process.env.TRICKLE_LOCAL_DIR || path.join(process.cwd(), '.trickle');
|
|
1010
|
+
fs.mkdirSync(envDir, { recursive: true });
|
|
1011
|
+
const SENSITIVE = ['KEY', 'SECRET', 'TOKEN', 'PASSWORD', 'AUTH', 'CREDENTIAL', 'PRIVATE'];
|
|
1012
|
+
const isSensitive = (k: string) => SENSITIVE.some(s => k.toUpperCase().includes(s));
|
|
1013
|
+
const redact = (k: string, v: string) => isSensitive(k) ? (v.length <= 4 ? '****' : v.slice(0, 2) + '*'.repeat(v.length - 4) + v.slice(-2)) : v;
|
|
1014
|
+
const skip = new Set(['PATH', 'HOME', 'USER', 'SHELL', 'TERM', 'LANG', 'LOGNAME', 'PWD', 'OLDPWD', 'SHLVL', 'TMPDIR']);
|
|
1015
|
+
const trickleVars: Record<string, string> = {};
|
|
1016
|
+
const appVars: Record<string, string> = {};
|
|
1017
|
+
for (const [k, v] of Object.entries(process.env)) {
|
|
1018
|
+
if (!v || k.startsWith('_')) continue;
|
|
1019
|
+
if (k.startsWith('TRICKLE_')) trickleVars[k] = v;
|
|
1020
|
+
else if (!skip.has(k)) appVars[k] = redact(k, v);
|
|
1021
|
+
}
|
|
1022
|
+
const envSnapshot = {
|
|
1023
|
+
kind: 'environment',
|
|
1024
|
+
timestamp: Date.now(),
|
|
1025
|
+
node: { version: process.version, platform: process.platform, arch: process.arch },
|
|
1026
|
+
cwd: process.cwd(),
|
|
1027
|
+
argv: process.argv.slice(0, 10),
|
|
1028
|
+
trickle: trickleVars,
|
|
1029
|
+
env: appVars,
|
|
1030
|
+
};
|
|
1031
|
+
fs.writeFileSync(path.join(envDir, 'environment.json'), JSON.stringify(envSnapshot, null, 2));
|
|
1032
|
+
} catch {}
|
|
1033
|
+
|
|
1034
|
+
|
|
1007
1035
|
// ── Hook 1: Module._compile — transform source to wrap function declarations ──
|
|
1008
1036
|
// This catches ALL functions including entry file and non-exported helpers.
|
|
1009
1037
|
|