@creatoria/miniapp-mcp 0.1.3 → 0.2.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.
- package/README.md +14 -3
- package/dist/app/cli/index.d.ts +6 -0
- package/dist/app/cli/index.d.ts.map +1 -0
- package/dist/app/cli/index.js +6 -0
- package/dist/app/cli/index.js.map +1 -0
- package/dist/app/index.d.ts +6 -0
- package/dist/app/index.d.ts.map +1 -0
- package/dist/app/index.js +6 -0
- package/dist/app/index.js.map +1 -0
- package/dist/app/server/index.d.ts +7 -0
- package/dist/app/server/index.d.ts.map +1 -0
- package/dist/app/server/index.js +6 -0
- package/dist/app/server/index.js.map +1 -0
- package/dist/capabilities/assert/index.d.ts +5 -0
- package/dist/capabilities/assert/index.d.ts.map +1 -0
- package/dist/capabilities/assert/index.js +5 -0
- package/dist/capabilities/assert/index.js.map +1 -0
- package/dist/capabilities/automator/index.d.ts +6 -0
- package/dist/capabilities/automator/index.d.ts.map +1 -0
- package/dist/capabilities/automator/index.js +6 -0
- package/dist/capabilities/automator/index.js.map +1 -0
- package/dist/capabilities/automator/schemas/close.d.ts +5 -0
- package/dist/capabilities/automator/schemas/close.d.ts.map +1 -0
- package/dist/capabilities/automator/schemas/close.js +11 -0
- package/dist/capabilities/automator/schemas/close.js.map +1 -0
- package/dist/capabilities/automator/schemas/connect.d.ts +11 -0
- package/dist/capabilities/automator/schemas/connect.d.ts.map +1 -0
- package/dist/capabilities/automator/schemas/connect.js +19 -0
- package/dist/capabilities/automator/schemas/connect.js.map +1 -0
- package/dist/capabilities/automator/schemas/disconnect.d.ts +5 -0
- package/dist/capabilities/automator/schemas/disconnect.d.ts.map +1 -0
- package/dist/capabilities/automator/schemas/disconnect.js +11 -0
- package/dist/capabilities/automator/schemas/disconnect.js.map +1 -0
- package/dist/capabilities/automator/schemas/index.d.ts +4 -0
- package/dist/capabilities/automator/schemas/index.d.ts.map +1 -0
- package/dist/capabilities/automator/schemas/index.js +12 -0
- package/dist/capabilities/automator/schemas/index.js.map +1 -0
- package/dist/capabilities/automator/schemas/launch.d.ts +17 -0
- package/dist/capabilities/automator/schemas/launch.d.ts.map +1 -0
- package/dist/capabilities/automator/schemas/launch.js +26 -0
- package/dist/capabilities/automator/schemas/launch.js.map +1 -0
- package/dist/capabilities/element/index.d.ts +5 -0
- package/dist/capabilities/element/index.d.ts.map +1 -0
- package/dist/capabilities/element/index.js +5 -0
- package/dist/capabilities/element/index.js.map +1 -0
- package/dist/capabilities/index.d.ts +15 -0
- package/dist/capabilities/index.d.ts.map +1 -0
- package/dist/capabilities/index.js +14 -0
- package/dist/capabilities/index.js.map +1 -0
- package/dist/capabilities/miniprogram/index.d.ts +5 -0
- package/dist/capabilities/miniprogram/index.d.ts.map +1 -0
- package/dist/capabilities/miniprogram/index.js +5 -0
- package/dist/capabilities/miniprogram/index.js.map +1 -0
- package/dist/capabilities/network/index.d.ts +5 -0
- package/dist/capabilities/network/index.d.ts.map +1 -0
- package/dist/capabilities/network/index.js +5 -0
- package/dist/capabilities/network/index.js.map +1 -0
- package/dist/capabilities/page/index.d.ts +5 -0
- package/dist/capabilities/page/index.d.ts.map +1 -0
- package/dist/capabilities/page/index.js +5 -0
- package/dist/capabilities/page/index.js.map +1 -0
- package/dist/capabilities/record/index.d.ts +5 -0
- package/dist/capabilities/record/index.d.ts.map +1 -0
- package/dist/capabilities/record/index.js +5 -0
- package/dist/capabilities/record/index.js.map +1 -0
- package/dist/capabilities/schema-registry.d.ts +4 -0
- package/dist/capabilities/schema-registry.d.ts.map +1 -0
- package/dist/capabilities/schema-registry.js +18 -0
- package/dist/capabilities/schema-registry.js.map +1 -0
- package/dist/capabilities/schema-types.d.ts +22 -0
- package/dist/capabilities/schema-types.d.ts.map +1 -0
- package/dist/capabilities/schema-types.js +2 -0
- package/dist/capabilities/schema-types.js.map +1 -0
- package/dist/capabilities/snapshot/index.d.ts +5 -0
- package/dist/capabilities/snapshot/index.d.ts.map +1 -0
- package/dist/capabilities/snapshot/index.js +5 -0
- package/dist/capabilities/snapshot/index.js.map +1 -0
- package/dist/config/loader.js +1 -1
- package/dist/config/loader.js.map +1 -1
- package/dist/core/element-ref.d.ts +1 -43
- package/dist/core/element-ref.d.ts.map +1 -1
- package/dist/core/element-ref.js +1 -212
- package/dist/core/element-ref.js.map +1 -1
- package/dist/core/logger.d.ts +1 -54
- package/dist/core/logger.d.ts.map +1 -1
- package/dist/core/logger.js +1 -377
- package/dist/core/logger.js.map +1 -1
- package/dist/core/output.d.ts +1 -20
- package/dist/core/output.d.ts.map +1 -1
- package/dist/core/output.js +1 -55
- package/dist/core/output.js.map +1 -1
- package/dist/core/report-generator.d.ts +1 -23
- package/dist/core/report-generator.d.ts.map +1 -1
- package/dist/core/report-generator.js +1 -211
- package/dist/core/report-generator.js.map +1 -1
- package/dist/core/session.d.ts +2 -82
- package/dist/core/session.d.ts.map +1 -1
- package/dist/core/session.js +2 -305
- package/dist/core/session.js.map +1 -1
- package/dist/core/timeout.d.ts +1 -48
- package/dist/core/timeout.d.ts.map +1 -1
- package/dist/core/timeout.js +1 -66
- package/dist/core/timeout.js.map +1 -1
- package/dist/core/tool-logger.d.ts +1 -82
- package/dist/core/tool-logger.d.ts.map +1 -1
- package/dist/core/tool-logger.js +1 -452
- package/dist/core/tool-logger.js.map +1 -1
- package/dist/core/validation.d.ts +1 -38
- package/dist/core/validation.d.ts.map +1 -1
- package/dist/core/validation.js +1 -92
- package/dist/core/validation.js.map +1 -1
- package/dist/runtime/element/element-ref.d.ts +44 -0
- package/dist/runtime/element/element-ref.d.ts.map +1 -0
- package/dist/runtime/element/element-ref.js +214 -0
- package/dist/runtime/element/element-ref.js.map +1 -0
- package/dist/runtime/element/index.d.ts +2 -0
- package/dist/runtime/element/index.d.ts.map +1 -0
- package/dist/runtime/element/index.js +2 -0
- package/dist/runtime/element/index.js.map +1 -0
- package/dist/runtime/index.d.ts +10 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +10 -0
- package/dist/runtime/index.js.map +1 -0
- package/dist/runtime/logging/index.d.ts +3 -0
- package/dist/runtime/logging/index.d.ts.map +1 -0
- package/dist/runtime/logging/index.js +3 -0
- package/dist/runtime/logging/index.js.map +1 -0
- package/dist/runtime/logging/logger.d.ts +55 -0
- package/dist/runtime/logging/logger.d.ts.map +1 -0
- package/dist/runtime/logging/logger.js +379 -0
- package/dist/runtime/logging/logger.js.map +1 -0
- package/dist/runtime/logging/tool-logger.d.ts +83 -0
- package/dist/runtime/logging/tool-logger.d.ts.map +1 -0
- package/dist/runtime/logging/tool-logger.js +454 -0
- package/dist/runtime/logging/tool-logger.js.map +1 -0
- package/dist/runtime/outputs/index.d.ts +3 -0
- package/dist/runtime/outputs/index.d.ts.map +1 -0
- package/dist/runtime/outputs/index.js +3 -0
- package/dist/runtime/outputs/index.js.map +1 -0
- package/dist/runtime/outputs/output-manager.d.ts +12 -0
- package/dist/runtime/outputs/output-manager.d.ts.map +1 -0
- package/dist/runtime/outputs/output-manager.js +39 -0
- package/dist/runtime/outputs/output-manager.js.map +1 -0
- package/dist/runtime/outputs/report-generator.d.ts +5 -0
- package/dist/runtime/outputs/report-generator.d.ts.map +1 -0
- package/dist/runtime/outputs/report-generator.js +175 -0
- package/dist/runtime/outputs/report-generator.js.map +1 -0
- package/dist/runtime/session/index.d.ts +3 -0
- package/dist/runtime/session/index.d.ts.map +1 -0
- package/dist/runtime/session/index.js +3 -0
- package/dist/runtime/session/index.js.map +1 -0
- package/dist/runtime/session/store.d.ts +28 -0
- package/dist/runtime/session/store.d.ts.map +1 -0
- package/dist/runtime/session/store.js +154 -0
- package/dist/runtime/session/store.js.map +1 -0
- package/dist/runtime/session/utils/cleanup.d.ts +3 -0
- package/dist/runtime/session/utils/cleanup.d.ts.map +1 -0
- package/dist/runtime/session/utils/cleanup.js +78 -0
- package/dist/runtime/session/utils/cleanup.js.map +1 -0
- package/dist/runtime/timeout/index.d.ts +2 -0
- package/dist/runtime/timeout/index.d.ts.map +1 -0
- package/dist/runtime/timeout/index.js +2 -0
- package/dist/runtime/timeout/index.js.map +1 -0
- package/dist/runtime/timeout/timeout.d.ts +49 -0
- package/dist/runtime/timeout/timeout.d.ts.map +1 -0
- package/dist/runtime/timeout/timeout.js +67 -0
- package/dist/runtime/timeout/timeout.js.map +1 -0
- package/dist/runtime/validation/index.d.ts +2 -0
- package/dist/runtime/validation/index.d.ts.map +1 -0
- package/dist/runtime/validation/index.js +2 -0
- package/dist/runtime/validation/index.js.map +1 -0
- package/dist/runtime/validation/validation.d.ts +39 -0
- package/dist/runtime/validation/validation.d.ts.map +1 -0
- package/dist/runtime/validation/validation.js +93 -0
- package/dist/runtime/validation/validation.js.map +1 -0
- package/dist/schemas/automator/miniprogram_close.json +12 -0
- package/dist/schemas/automator/miniprogram_connect.json +19 -0
- package/dist/schemas/automator/miniprogram_disconnect.json +12 -0
- package/dist/schemas/automator/miniprogram_launch.json +30 -0
- package/dist/server.js +1 -1
- package/dist/server.js.map +1 -1
- package/dist/tools/index.js +1 -1
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/miniprogram.d.ts +0 -1
- package/dist/tools/miniprogram.d.ts.map +1 -1
- package/dist/tools/miniprogram.js +17 -29
- package/dist/tools/miniprogram.js.map +1 -1
- package/dist/tools/page.js +2 -2
- package/dist/tools/page.js.map +1 -1
- package/docs/directory-structure-and-code-style-best-practices.md +91 -0
- package/docs/migration/README.md +34 -0
- package/docs/migration/TC-ALIGN-01-notes.md +35 -0
- package/docs/migration/runtime-skeleton.md +50 -0
- package/docs/migration/tool-schema-strategy.md +75 -0
- package/docs//345/256/214/346/225/264/345/256/236/347/216/260/346/226/271/346/241/210.md +14 -14
- package/docs//347/254/254/344/270/200/347/211/210/346/234/254/346/226/271/346/241/210.md +7 -7
- package/package.json +4 -2
- package/docs/SIMPLE_USAGE.md +0 -210
- package/docs/architecture.E-Docs.md +0 -1359
- package/docs/architecture.F1.md +0 -720
- package/docs/architecture.F2.md +0 -871
- package/docs/architecture.F3.md +0 -905
- package/docs/architecture.md +0 -90
- package/docs/charter.A1.align.yaml +0 -170
- package/docs/charter.A2.align.yaml +0 -199
- package/docs/charter.A3.align.yaml +0 -242
- package/docs/charter.A4.align.yaml +0 -227
- package/docs/charter.B1.align.yaml +0 -179
- package/docs/charter.B2.align.yaml +0 -200
- package/docs/charter.B3.align.yaml +0 -200
- package/docs/charter.B4.align.yaml +0 -188
- package/docs/charter.C1.align.yaml +0 -190
- package/docs/charter.C2.align.yaml +0 -202
- package/docs/charter.C3.align.yaml +0 -211
- package/docs/charter.C4.align.yaml +0 -263
- package/docs/charter.C5.align.yaml +0 -220
- package/docs/charter.D1.align.yaml +0 -190
- package/docs/charter.D2.align.yaml +0 -234
- package/docs/charter.D3.align.yaml +0 -206
- package/docs/charter.E-Docs.align.yaml +0 -294
- package/docs/charter.F1.align.yaml +0 -193
- package/docs/charter.F2.align.yaml +0 -248
- package/docs/charter.F3.align.yaml +0 -287
- package/docs/charter.G.align.yaml +0 -174
- package/docs/charter.align.yaml +0 -111
- package/docs/maintenance.md +0 -682
- package/docs/playwright-mcp/350/260/203/347/240/224.md +0 -53
- package/docs/setup-guide.md +0 -775
- package/docs/tasks.A1.atomize.md +0 -296
- package/docs/tasks.A2.atomize.md +0 -408
- package/docs/tasks.A3.atomize.md +0 -564
- package/docs/tasks.A4.atomize.md +0 -496
- package/docs/tasks.B1.atomize.md +0 -352
- package/docs/tasks.B2.atomize.md +0 -561
- package/docs/tasks.B3.atomize.md +0 -508
- package/docs/tasks.B4.atomize.md +0 -504
- package/docs/tasks.C1.atomize.md +0 -540
- package/docs/tasks.C2.atomize.md +0 -665
- package/docs/tasks.C3.atomize.md +0 -745
- package/docs/tasks.C4.atomize.md +0 -908
- package/docs/tasks.C5.atomize.md +0 -755
- package/docs/tasks.D1.atomize.md +0 -547
- package/docs/tasks.D2.atomize.md +0 -619
- package/docs/tasks.D3.atomize.md +0 -790
- package/docs/tasks.E-Docs.atomize.md +0 -1204
- package/docs/tasks.atomize.md +0 -189
package/dist/core/timeout.d.ts
CHANGED
|
@@ -1,49 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
* Timeout utilities for protecting async operations
|
|
3
|
-
*/
|
|
4
|
-
/**
|
|
5
|
-
* Wraps a promise with timeout protection
|
|
6
|
-
*
|
|
7
|
-
* @param promise - The promise to wrap
|
|
8
|
-
* @param timeoutMs - Timeout in milliseconds
|
|
9
|
-
* @param operation - Description of the operation for error messages
|
|
10
|
-
* @returns The promise result or throws TimeoutError
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```typescript
|
|
14
|
-
* const result = await withTimeout(
|
|
15
|
-
* page.$(selector),
|
|
16
|
-
* 5000,
|
|
17
|
-
* 'Query element'
|
|
18
|
-
* )
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
|
-
export declare function withTimeout<T>(promise: Promise<T>, timeoutMs: number, operation: string): Promise<T>;
|
|
22
|
-
/**
|
|
23
|
-
* Default timeout values for different operations
|
|
24
|
-
*/
|
|
25
|
-
export declare const DEFAULT_TIMEOUTS: {
|
|
26
|
-
/** Default timeout for most operations (30 seconds) */
|
|
27
|
-
readonly default: 30000;
|
|
28
|
-
/** Timeout for evaluate operations (5 seconds) */
|
|
29
|
-
readonly evaluate: 5000;
|
|
30
|
-
/** Timeout for launch operations (60 seconds) */
|
|
31
|
-
readonly launch: 60000;
|
|
32
|
-
/** Timeout for connect operations (30 seconds) */
|
|
33
|
-
readonly connect: 30000;
|
|
34
|
-
/** Timeout for screenshot operations (10 seconds) */
|
|
35
|
-
readonly screenshot: 10000;
|
|
36
|
-
/** Timeout for waitFor operations (30 seconds) */
|
|
37
|
-
readonly waitFor: 30000;
|
|
38
|
-
/** Timeout for element queries (10 seconds) */
|
|
39
|
-
readonly query: 10000;
|
|
40
|
-
};
|
|
41
|
-
/**
|
|
42
|
-
* Get timeout value with fallback chain:
|
|
43
|
-
* 1. Operation-specific timeout from config
|
|
44
|
-
* 2. Global timeout from config
|
|
45
|
-
* 3. Operation-specific default
|
|
46
|
-
* 4. Global default (30s)
|
|
47
|
-
*/
|
|
48
|
-
export declare function getTimeout(configTimeout: number | undefined, operationDefault: number): number;
|
|
1
|
+
export * from '../runtime/timeout/timeout.js';
|
|
49
2
|
//# sourceMappingURL=timeout.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timeout.d.ts","sourceRoot":"","sources":["../../src/core/timeout.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"timeout.d.ts","sourceRoot":"","sources":["../../src/core/timeout.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAA"}
|
package/dist/core/timeout.js
CHANGED
|
@@ -1,67 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
* Timeout utilities for protecting async operations
|
|
3
|
-
*/
|
|
4
|
-
/**
|
|
5
|
-
* Wraps a promise with timeout protection
|
|
6
|
-
*
|
|
7
|
-
* @param promise - The promise to wrap
|
|
8
|
-
* @param timeoutMs - Timeout in milliseconds
|
|
9
|
-
* @param operation - Description of the operation for error messages
|
|
10
|
-
* @returns The promise result or throws TimeoutError
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```typescript
|
|
14
|
-
* const result = await withTimeout(
|
|
15
|
-
* page.$(selector),
|
|
16
|
-
* 5000,
|
|
17
|
-
* 'Query element'
|
|
18
|
-
* )
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
|
-
export async function withTimeout(promise, timeoutMs, operation) {
|
|
22
|
-
let timeoutId;
|
|
23
|
-
const timeoutPromise = new Promise((_, reject) => {
|
|
24
|
-
timeoutId = setTimeout(() => {
|
|
25
|
-
reject(new Error(`${operation} timed out after ${timeoutMs}ms`));
|
|
26
|
-
}, timeoutMs);
|
|
27
|
-
});
|
|
28
|
-
try {
|
|
29
|
-
const result = await Promise.race([promise, timeoutPromise]);
|
|
30
|
-
clearTimeout(timeoutId);
|
|
31
|
-
return result;
|
|
32
|
-
}
|
|
33
|
-
catch (error) {
|
|
34
|
-
clearTimeout(timeoutId);
|
|
35
|
-
throw error;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Default timeout values for different operations
|
|
40
|
-
*/
|
|
41
|
-
export const DEFAULT_TIMEOUTS = {
|
|
42
|
-
/** Default timeout for most operations (30 seconds) */
|
|
43
|
-
default: 30000,
|
|
44
|
-
/** Timeout for evaluate operations (5 seconds) */
|
|
45
|
-
evaluate: 5000,
|
|
46
|
-
/** Timeout for launch operations (60 seconds) */
|
|
47
|
-
launch: 60000,
|
|
48
|
-
/** Timeout for connect operations (30 seconds) */
|
|
49
|
-
connect: 30000,
|
|
50
|
-
/** Timeout for screenshot operations (10 seconds) */
|
|
51
|
-
screenshot: 10000,
|
|
52
|
-
/** Timeout for waitFor operations (30 seconds) */
|
|
53
|
-
waitFor: 30000,
|
|
54
|
-
/** Timeout for element queries (10 seconds) */
|
|
55
|
-
query: 10000,
|
|
56
|
-
};
|
|
57
|
-
/**
|
|
58
|
-
* Get timeout value with fallback chain:
|
|
59
|
-
* 1. Operation-specific timeout from config
|
|
60
|
-
* 2. Global timeout from config
|
|
61
|
-
* 3. Operation-specific default
|
|
62
|
-
* 4. Global default (30s)
|
|
63
|
-
*/
|
|
64
|
-
export function getTimeout(configTimeout, operationDefault) {
|
|
65
|
-
return configTimeout ?? operationDefault ?? DEFAULT_TIMEOUTS.default;
|
|
66
|
-
}
|
|
1
|
+
export * from '../runtime/timeout/timeout.js';
|
|
67
2
|
//# sourceMappingURL=timeout.js.map
|
package/dist/core/timeout.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timeout.js","sourceRoot":"","sources":["../../src/core/timeout.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"timeout.js","sourceRoot":"","sources":["../../src/core/timeout.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAA"}
|
|
@@ -1,83 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
* Tool call logger wrapper for automatic logging
|
|
3
|
-
*/
|
|
4
|
-
import type { Logger } from '../types.js';
|
|
5
|
-
import type { SessionState } from '../types.js';
|
|
6
|
-
/**
|
|
7
|
-
* Tool logger wrapper for automatic START/END/ERROR logging
|
|
8
|
-
*/
|
|
9
|
-
export declare class ToolLogger {
|
|
10
|
-
private logger;
|
|
11
|
-
private config?;
|
|
12
|
-
private capturing;
|
|
13
|
-
constructor(logger: Logger, config?: import("../types.js").LoggerConfig | undefined);
|
|
14
|
-
/**
|
|
15
|
-
* Wrap a tool handler with automatic logging
|
|
16
|
-
*
|
|
17
|
-
* @param toolName - Name of the tool (e.g., "page_query")
|
|
18
|
-
* @param handler - Original tool handler function
|
|
19
|
-
* @returns Wrapped handler with automatic logging
|
|
20
|
-
*/
|
|
21
|
-
wrap<TArgs, TResult>(toolName: string, handler: (session: SessionState, args: TArgs) => Promise<TResult>): (session: SessionState, args: TArgs) => Promise<TResult>;
|
|
22
|
-
/**
|
|
23
|
-
* Check if a key name matches sensitive patterns (Issue #3)
|
|
24
|
-
*/
|
|
25
|
-
private isSensitiveKey;
|
|
26
|
-
/**
|
|
27
|
-
* Sanitize arguments for logging (remove sensitive data, limit size)
|
|
28
|
-
* Issue #3: Enhanced with deep recursion and pattern matching
|
|
29
|
-
*/
|
|
30
|
-
private sanitizeArgs;
|
|
31
|
-
/**
|
|
32
|
-
* Sanitize result for logging (limit size, remove large objects)
|
|
33
|
-
* Issue #3: Use same deep sanitization as args
|
|
34
|
-
*/
|
|
35
|
-
private sanitizeResult;
|
|
36
|
-
/**
|
|
37
|
-
* Capture failure snapshot when tool call fails (F2 feature)
|
|
38
|
-
*
|
|
39
|
-
* Creates a failure directory with:
|
|
40
|
-
* - snapshot.json: Page data
|
|
41
|
-
* - snapshot.png: Screenshot
|
|
42
|
-
* - error-context.json: Error details + tool context
|
|
43
|
-
*
|
|
44
|
-
* @param context Failure context
|
|
45
|
-
* @returns Relative path to the failure directory (for F3 reporting)
|
|
46
|
-
*/
|
|
47
|
-
private captureFailureSnapshot;
|
|
48
|
-
/**
|
|
49
|
-
* Record a tool call to session report data (F3 feature)
|
|
50
|
-
*
|
|
51
|
-
* Adds a tool call record to the session's reportData. Implements
|
|
52
|
-
* memory protection by limiting to MAX_TOOL_CALL_RECORDS with FIFO eviction.
|
|
53
|
-
*
|
|
54
|
-
* @param session Session state
|
|
55
|
-
* @param record Tool call record to add
|
|
56
|
-
*/
|
|
57
|
-
private recordToolCall;
|
|
58
|
-
/**
|
|
59
|
-
* Sanitize error message to remove sensitive information (F3-S1)
|
|
60
|
-
*
|
|
61
|
-
* Removes:
|
|
62
|
-
* - File paths (Unix, Linux, Windows)
|
|
63
|
-
* - API keys and tokens (32+ character alphanumeric strings)
|
|
64
|
-
* - Stack trace locations
|
|
65
|
-
*
|
|
66
|
-
* @param message Raw error message
|
|
67
|
-
* @returns Sanitized error message with placeholders
|
|
68
|
-
*/
|
|
69
|
-
private sanitizeErrorMessage;
|
|
70
|
-
/**
|
|
71
|
-
* Sanitize stack trace to remove sensitive file paths (Issue #P2)
|
|
72
|
-
*
|
|
73
|
-
* Removes:
|
|
74
|
-
* - Absolute user paths (/Users/<username>/, /home/<username>/)
|
|
75
|
-
* - Windows paths (C:\Users\<username>\)
|
|
76
|
-
* - Environment-specific paths
|
|
77
|
-
*
|
|
78
|
-
* @param stack Raw stack trace
|
|
79
|
-
* @returns Sanitized stack trace with placeholders
|
|
80
|
-
*/
|
|
81
|
-
private sanitizeStackTrace;
|
|
82
|
-
}
|
|
1
|
+
export { ToolLogger } from '../runtime/logging/tool-logger.js';
|
|
83
2
|
//# sourceMappingURL=tool-logger.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-logger.d.ts","sourceRoot":"","sources":["../../src/core/tool-logger.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"tool-logger.d.ts","sourceRoot":"","sources":["../../src/core/tool-logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAA"}
|
package/dist/core/tool-logger.js
CHANGED
|
@@ -1,453 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
* Tool call logger wrapper for automatic logging
|
|
3
|
-
*/
|
|
4
|
-
/**
|
|
5
|
-
* Maximum size for logged arguments/results (1KB)
|
|
6
|
-
*/
|
|
7
|
-
const MAX_LOG_SIZE = 1024;
|
|
8
|
-
/**
|
|
9
|
-
* Maximum recursion depth for sanitization
|
|
10
|
-
*/
|
|
11
|
-
const MAX_SANITIZE_DEPTH = 5;
|
|
12
|
-
/**
|
|
13
|
-
* Maximum number of tool call records to keep in memory (F3)
|
|
14
|
-
*/
|
|
15
|
-
const MAX_TOOL_CALL_RECORDS = 1000;
|
|
16
|
-
/**
|
|
17
|
-
* Sensitive key patterns to redact from logs (Issue #3: Enhanced sanitization)
|
|
18
|
-
* Uses regex for case-insensitive matching and pattern variations
|
|
19
|
-
*/
|
|
20
|
-
const SENSITIVE_PATTERNS = [
|
|
21
|
-
/password/i,
|
|
22
|
-
/passwd/i,
|
|
23
|
-
/pwd/i,
|
|
24
|
-
/token/i,
|
|
25
|
-
/secret/i,
|
|
26
|
-
/api[_-]?key/i,
|
|
27
|
-
/auth/i,
|
|
28
|
-
/authorization/i,
|
|
29
|
-
/bearer/i,
|
|
30
|
-
/credential/i,
|
|
31
|
-
/private[_-]?key/i,
|
|
32
|
-
/access[_-]?key/i,
|
|
33
|
-
/session[_-]?id/i,
|
|
34
|
-
/csrf/i,
|
|
35
|
-
/xsrf/i,
|
|
36
|
-
/jwt/i,
|
|
37
|
-
// WeChat specific PII
|
|
38
|
-
/openid/i,
|
|
39
|
-
/unionid/i,
|
|
40
|
-
/app[_-]?secret/i,
|
|
41
|
-
];
|
|
42
|
-
/**
|
|
43
|
-
* Tool logger wrapper for automatic START/END/ERROR logging
|
|
44
|
-
*/
|
|
45
|
-
export class ToolLogger {
|
|
46
|
-
logger;
|
|
47
|
-
config;
|
|
48
|
-
capturing = false; // Issue #P2: Prevent recursive snapshot triggers
|
|
49
|
-
constructor(logger, config) {
|
|
50
|
-
this.logger = logger;
|
|
51
|
-
this.config = config;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Wrap a tool handler with automatic logging
|
|
55
|
-
*
|
|
56
|
-
* @param toolName - Name of the tool (e.g., "page_query")
|
|
57
|
-
* @param handler - Original tool handler function
|
|
58
|
-
* @returns Wrapped handler with automatic logging
|
|
59
|
-
*/
|
|
60
|
-
wrap(toolName, handler) {
|
|
61
|
-
return async (session, args) => {
|
|
62
|
-
const startTime = Date.now();
|
|
63
|
-
const childLogger = this.logger.child(toolName);
|
|
64
|
-
// Log START
|
|
65
|
-
childLogger.info('Tool call started', {
|
|
66
|
-
phase: 'START',
|
|
67
|
-
args: this.sanitizeArgs(args),
|
|
68
|
-
});
|
|
69
|
-
try {
|
|
70
|
-
// Execute tool
|
|
71
|
-
const result = await handler(session, args);
|
|
72
|
-
const duration = Date.now() - startTime;
|
|
73
|
-
// Log END
|
|
74
|
-
childLogger.info('Tool call completed', {
|
|
75
|
-
phase: 'END',
|
|
76
|
-
duration,
|
|
77
|
-
result: this.sanitizeResult(result),
|
|
78
|
-
});
|
|
79
|
-
// F3: Record successful tool call
|
|
80
|
-
this.recordToolCall(session, {
|
|
81
|
-
timestamp: new Date(startTime),
|
|
82
|
-
toolName,
|
|
83
|
-
duration,
|
|
84
|
-
success: true,
|
|
85
|
-
result: this.sanitizeResult(result),
|
|
86
|
-
});
|
|
87
|
-
return result;
|
|
88
|
-
}
|
|
89
|
-
catch (error) {
|
|
90
|
-
const duration = Date.now() - startTime;
|
|
91
|
-
// Log ERROR
|
|
92
|
-
childLogger.error('Tool call failed', {
|
|
93
|
-
phase: 'ERROR',
|
|
94
|
-
duration,
|
|
95
|
-
error: error instanceof Error ? error.message : String(error),
|
|
96
|
-
stackTrace: error instanceof Error ? error.stack : undefined,
|
|
97
|
-
});
|
|
98
|
-
// F2: Capture failure snapshot (fire-and-forget, non-blocking)
|
|
99
|
-
let snapshotPath;
|
|
100
|
-
if (this.config?.enableFailureSnapshot) {
|
|
101
|
-
snapshotPath = await this.captureFailureSnapshot({
|
|
102
|
-
session,
|
|
103
|
-
toolName,
|
|
104
|
-
args,
|
|
105
|
-
error: error instanceof Error ? error : new Error(String(error)),
|
|
106
|
-
duration,
|
|
107
|
-
}).catch((e) => {
|
|
108
|
-
childLogger.warn('Snapshot capture failed', {
|
|
109
|
-
error: e instanceof Error ? e.message : String(e),
|
|
110
|
-
});
|
|
111
|
-
return undefined;
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
// F3: Record failed tool call
|
|
115
|
-
this.recordToolCall(session, {
|
|
116
|
-
timestamp: new Date(startTime),
|
|
117
|
-
toolName,
|
|
118
|
-
duration,
|
|
119
|
-
success: false,
|
|
120
|
-
error: {
|
|
121
|
-
message: this.sanitizeErrorMessage(error instanceof Error ? error.message : String(error)),
|
|
122
|
-
snapshotPath,
|
|
123
|
-
},
|
|
124
|
-
});
|
|
125
|
-
throw error; // Re-throw to preserve error handling
|
|
126
|
-
}
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Check if a key name matches sensitive patterns (Issue #3)
|
|
131
|
-
*/
|
|
132
|
-
isSensitiveKey(key) {
|
|
133
|
-
return SENSITIVE_PATTERNS.some((pattern) => pattern.test(key));
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* Sanitize arguments for logging (remove sensitive data, limit size)
|
|
137
|
-
* Issue #3: Enhanced with deep recursion and pattern matching
|
|
138
|
-
*/
|
|
139
|
-
sanitizeArgs(args, depth = 0) {
|
|
140
|
-
if (args === null || args === undefined) {
|
|
141
|
-
return args;
|
|
142
|
-
}
|
|
143
|
-
// Prevent infinite recursion
|
|
144
|
-
if (depth > MAX_SANITIZE_DEPTH) {
|
|
145
|
-
return '<Max sanitization depth reached>';
|
|
146
|
-
}
|
|
147
|
-
try {
|
|
148
|
-
// For primitives, handle directly
|
|
149
|
-
if (typeof args !== 'object') {
|
|
150
|
-
if (typeof args === 'string' && args.length > MAX_LOG_SIZE) {
|
|
151
|
-
return args.substring(0, MAX_LOG_SIZE) + `... (${args.length} bytes total)`;
|
|
152
|
-
}
|
|
153
|
-
return args;
|
|
154
|
-
}
|
|
155
|
-
// Handle arrays
|
|
156
|
-
if (Array.isArray(args)) {
|
|
157
|
-
return args.map((item) => this.sanitizeArgs(item, depth + 1));
|
|
158
|
-
}
|
|
159
|
-
// Handle objects with deep sanitization
|
|
160
|
-
const sanitized = {};
|
|
161
|
-
for (const [key, value] of Object.entries(args)) {
|
|
162
|
-
// Redact sensitive keys (Issue #3: Pattern-based matching)
|
|
163
|
-
if (this.isSensitiveKey(key)) {
|
|
164
|
-
sanitized[key] = '[REDACTED]';
|
|
165
|
-
continue;
|
|
166
|
-
}
|
|
167
|
-
// Truncate large strings
|
|
168
|
-
if (typeof value === 'string' && value.length > MAX_LOG_SIZE) {
|
|
169
|
-
sanitized[key] = value.substring(0, MAX_LOG_SIZE) + `... (${value.length} bytes total)`;
|
|
170
|
-
continue;
|
|
171
|
-
}
|
|
172
|
-
// Convert buffers to placeholder
|
|
173
|
-
if (value &&
|
|
174
|
-
typeof value === 'object' &&
|
|
175
|
-
'type' in value &&
|
|
176
|
-
value.type === 'Buffer' &&
|
|
177
|
-
'data' in value) {
|
|
178
|
-
const bufferData = value.data;
|
|
179
|
-
sanitized[key] = `<Buffer ${bufferData?.length || 0} bytes>`;
|
|
180
|
-
continue;
|
|
181
|
-
}
|
|
182
|
-
// Recursively sanitize nested objects/arrays (Issue #3: Deep sanitization)
|
|
183
|
-
if (value && typeof value === 'object') {
|
|
184
|
-
sanitized[key] = this.sanitizeArgs(value, depth + 1);
|
|
185
|
-
continue;
|
|
186
|
-
}
|
|
187
|
-
sanitized[key] = value;
|
|
188
|
-
}
|
|
189
|
-
return sanitized;
|
|
190
|
-
}
|
|
191
|
-
catch (error) {
|
|
192
|
-
// If sanitization fails, return placeholder
|
|
193
|
-
return '<Failed to sanitize args>';
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
/**
|
|
197
|
-
* Sanitize result for logging (limit size, remove large objects)
|
|
198
|
-
* Issue #3: Use same deep sanitization as args
|
|
199
|
-
*/
|
|
200
|
-
sanitizeResult(result, depth = 0) {
|
|
201
|
-
if (result === null || result === undefined) {
|
|
202
|
-
return result;
|
|
203
|
-
}
|
|
204
|
-
// Prevent infinite recursion
|
|
205
|
-
if (depth > MAX_SANITIZE_DEPTH) {
|
|
206
|
-
return '<Max sanitization depth reached>';
|
|
207
|
-
}
|
|
208
|
-
try {
|
|
209
|
-
// For simple types, return as-is
|
|
210
|
-
if (typeof result !== 'object') {
|
|
211
|
-
if (typeof result === 'string' && result.length > MAX_LOG_SIZE) {
|
|
212
|
-
return result.substring(0, MAX_LOG_SIZE) + `... (${result.length} bytes total)`;
|
|
213
|
-
}
|
|
214
|
-
return result;
|
|
215
|
-
}
|
|
216
|
-
// Handle arrays
|
|
217
|
-
if (Array.isArray(result)) {
|
|
218
|
-
if (result.length > 10) {
|
|
219
|
-
return [
|
|
220
|
-
...result.slice(0, 10).map((item) => this.sanitizeResult(item, depth + 1)),
|
|
221
|
-
`... (${result.length - 10} more items)`,
|
|
222
|
-
];
|
|
223
|
-
}
|
|
224
|
-
return result.map((item) => this.sanitizeResult(item, depth + 1));
|
|
225
|
-
}
|
|
226
|
-
// For objects, sanitize with deep recursion
|
|
227
|
-
const sanitized = {};
|
|
228
|
-
for (const [key, value] of Object.entries(result)) {
|
|
229
|
-
// Redact sensitive keys in results too (Issue #3)
|
|
230
|
-
if (this.isSensitiveKey(key)) {
|
|
231
|
-
sanitized[key] = '[REDACTED]';
|
|
232
|
-
continue;
|
|
233
|
-
}
|
|
234
|
-
// Truncate large strings
|
|
235
|
-
if (typeof value === 'string' && value.length > MAX_LOG_SIZE) {
|
|
236
|
-
sanitized[key] = value.substring(0, MAX_LOG_SIZE) + `... (${value.length} bytes total)`;
|
|
237
|
-
continue;
|
|
238
|
-
}
|
|
239
|
-
// Convert buffers to placeholder
|
|
240
|
-
if (value &&
|
|
241
|
-
typeof value === 'object' &&
|
|
242
|
-
'type' in value &&
|
|
243
|
-
value.type === 'Buffer' &&
|
|
244
|
-
'data' in value) {
|
|
245
|
-
const bufferData = value.data;
|
|
246
|
-
sanitized[key] = `<Buffer ${bufferData?.length || 0} bytes>`;
|
|
247
|
-
continue;
|
|
248
|
-
}
|
|
249
|
-
// Recursively sanitize nested objects/arrays
|
|
250
|
-
if (value && typeof value === 'object') {
|
|
251
|
-
sanitized[key] = this.sanitizeResult(value, depth + 1);
|
|
252
|
-
continue;
|
|
253
|
-
}
|
|
254
|
-
sanitized[key] = value;
|
|
255
|
-
}
|
|
256
|
-
return sanitized;
|
|
257
|
-
}
|
|
258
|
-
catch (error) {
|
|
259
|
-
// If sanitization fails, return placeholder
|
|
260
|
-
return '<Failed to sanitize result>';
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
/**
|
|
264
|
-
* Capture failure snapshot when tool call fails (F2 feature)
|
|
265
|
-
*
|
|
266
|
-
* Creates a failure directory with:
|
|
267
|
-
* - snapshot.json: Page data
|
|
268
|
-
* - snapshot.png: Screenshot
|
|
269
|
-
* - error-context.json: Error details + tool context
|
|
270
|
-
*
|
|
271
|
-
* @param context Failure context
|
|
272
|
-
* @returns Relative path to the failure directory (for F3 reporting)
|
|
273
|
-
*/
|
|
274
|
-
async captureFailureSnapshot(context) {
|
|
275
|
-
const { session, toolName, args, error, duration } = context;
|
|
276
|
-
const logger = this.logger;
|
|
277
|
-
// Issue #P2: Prevent recursive snapshot triggers
|
|
278
|
-
if (this.capturing) {
|
|
279
|
-
logger?.debug('Skipping failure snapshot: already capturing');
|
|
280
|
-
return undefined;
|
|
281
|
-
}
|
|
282
|
-
this.capturing = true;
|
|
283
|
-
try {
|
|
284
|
-
// 1. Check prerequisites
|
|
285
|
-
if (!this.config?.enableFailureSnapshot) {
|
|
286
|
-
return undefined; // Feature disabled
|
|
287
|
-
}
|
|
288
|
-
if (!session.miniProgram) {
|
|
289
|
-
logger?.debug('Skipping failure snapshot: miniProgram not connected');
|
|
290
|
-
return undefined;
|
|
291
|
-
}
|
|
292
|
-
if (!session.outputManager) {
|
|
293
|
-
logger?.debug('Skipping failure snapshot: outputManager not available');
|
|
294
|
-
return undefined;
|
|
295
|
-
}
|
|
296
|
-
// 2. Create failure directory
|
|
297
|
-
// Issue #P1: Sanitize toolName to prevent path traversal
|
|
298
|
-
const sanitizedToolName = toolName.replace(/[^a-zA-Z0-9_-]/g, '_');
|
|
299
|
-
// Issue #P1: Preserve millisecond precision to avoid collisions
|
|
300
|
-
const timestamp = new Date().toISOString().replace(/[:.]/g, '-').replace('T', '_');
|
|
301
|
-
const failureDirName = `${sanitizedToolName}-${timestamp}`;
|
|
302
|
-
const failureDir = `failures/${failureDirName}`;
|
|
303
|
-
const outputManager = session.outputManager;
|
|
304
|
-
await outputManager.ensureOutputDir();
|
|
305
|
-
// Create failures subdirectory
|
|
306
|
-
const { mkdir } = await import('fs/promises');
|
|
307
|
-
const { join } = await import('path');
|
|
308
|
-
const failurePath = join(outputManager.getOutputDir(), failureDir);
|
|
309
|
-
await mkdir(failurePath, { recursive: true });
|
|
310
|
-
logger?.info('Capturing failure snapshot', { path: failurePath });
|
|
311
|
-
// 3. Capture page snapshot
|
|
312
|
-
const snapshotFilename = join(failureDir, 'snapshot.json');
|
|
313
|
-
const snapshotTools = await import('../tools/snapshot.js');
|
|
314
|
-
await snapshotTools.snapshotPage(session, {
|
|
315
|
-
filename: snapshotFilename,
|
|
316
|
-
includeScreenshot: true,
|
|
317
|
-
fullPage: false,
|
|
318
|
-
});
|
|
319
|
-
// 4. Save error context
|
|
320
|
-
const errorContext = {
|
|
321
|
-
toolName,
|
|
322
|
-
timestamp: new Date().toISOString(),
|
|
323
|
-
error: {
|
|
324
|
-
message: error.message,
|
|
325
|
-
// Issue #P2: Sanitize stack trace to remove sensitive paths
|
|
326
|
-
stack: this.sanitizeStackTrace(error.stack),
|
|
327
|
-
code: error.code,
|
|
328
|
-
},
|
|
329
|
-
args: this.sanitizeArgs(args), // Reuse existing sanitization
|
|
330
|
-
duration,
|
|
331
|
-
};
|
|
332
|
-
const contextFilename = join(failureDir, 'error-context.json');
|
|
333
|
-
await outputManager.writeFile(contextFilename, Buffer.from(JSON.stringify(errorContext, null, 2)));
|
|
334
|
-
logger?.info('Failure snapshot captured successfully', {
|
|
335
|
-
path: failurePath,
|
|
336
|
-
files: ['snapshot.json', 'snapshot.png', 'error-context.json'],
|
|
337
|
-
});
|
|
338
|
-
// F3: Return relative path for report linking
|
|
339
|
-
return failureDir;
|
|
340
|
-
}
|
|
341
|
-
catch (snapshotError) {
|
|
342
|
-
// Snapshot capture failed - log but don't throw
|
|
343
|
-
logger?.warn('Failed to capture failure snapshot', {
|
|
344
|
-
error: snapshotError instanceof Error ? snapshotError.message : String(snapshotError),
|
|
345
|
-
});
|
|
346
|
-
return undefined;
|
|
347
|
-
}
|
|
348
|
-
finally {
|
|
349
|
-
this.capturing = false;
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
/**
|
|
353
|
-
* Record a tool call to session report data (F3 feature)
|
|
354
|
-
*
|
|
355
|
-
* Adds a tool call record to the session's reportData. Implements
|
|
356
|
-
* memory protection by limiting to MAX_TOOL_CALL_RECORDS with FIFO eviction.
|
|
357
|
-
*
|
|
358
|
-
* @param session Session state
|
|
359
|
-
* @param record Tool call record to add
|
|
360
|
-
*/
|
|
361
|
-
recordToolCall(session, record) {
|
|
362
|
-
// Skip if session reporting is not enabled
|
|
363
|
-
if (!session.reportData) {
|
|
364
|
-
return;
|
|
365
|
-
}
|
|
366
|
-
// Add record to the array
|
|
367
|
-
session.reportData.toolCalls.push(record);
|
|
368
|
-
// F3-P2: Memory protection with batch eviction for better performance
|
|
369
|
-
// Instead of shift() every time (O(n)), we batch-remove when hitting 1.5x limit
|
|
370
|
-
// This reduces eviction frequency from every call to every 500 calls
|
|
371
|
-
const currentLength = session.reportData.toolCalls.length;
|
|
372
|
-
if (currentLength >= MAX_TOOL_CALL_RECORDS * 1.5) {
|
|
373
|
-
// Remove oldest 50% to get back to limit
|
|
374
|
-
const removeCount = Math.floor(MAX_TOOL_CALL_RECORDS * 0.5);
|
|
375
|
-
const removed = session.reportData.toolCalls.splice(0, removeCount);
|
|
376
|
-
this.logger?.debug('Tool call records evicted (memory limit)', {
|
|
377
|
-
removedCount: removed.length,
|
|
378
|
-
oldestTool: removed[0]?.toolName,
|
|
379
|
-
oldestTimestamp: removed[0]?.timestamp,
|
|
380
|
-
newestRemovedTool: removed[removed.length - 1]?.toolName,
|
|
381
|
-
currentCount: session.reportData.toolCalls.length,
|
|
382
|
-
maxCount: MAX_TOOL_CALL_RECORDS,
|
|
383
|
-
});
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
/**
|
|
387
|
-
* Sanitize error message to remove sensitive information (F3-S1)
|
|
388
|
-
*
|
|
389
|
-
* Removes:
|
|
390
|
-
* - File paths (Unix, Linux, Windows)
|
|
391
|
-
* - API keys and tokens (32+ character alphanumeric strings)
|
|
392
|
-
* - Stack trace locations
|
|
393
|
-
*
|
|
394
|
-
* @param message Raw error message
|
|
395
|
-
* @returns Sanitized error message with placeholders
|
|
396
|
-
*/
|
|
397
|
-
sanitizeErrorMessage(message) {
|
|
398
|
-
if (!message)
|
|
399
|
-
return message;
|
|
400
|
-
try {
|
|
401
|
-
return (message
|
|
402
|
-
// Replace Unix user paths: /Users/username/ -> /Users/<user>/
|
|
403
|
-
.replace(/\/Users\/[^/]+\//g, '/Users/<user>/')
|
|
404
|
-
// Replace Linux home paths: /home/username/ -> /home/<user>/
|
|
405
|
-
.replace(/\/home\/[^/]+\//g, '/home/<user>/')
|
|
406
|
-
// Replace Windows user paths: C:\Users\username\ -> C:\Users\<user>\
|
|
407
|
-
.replace(/C:\\Users\\[^\\]+\\/gi, 'C:\\Users\\<user>\\')
|
|
408
|
-
// Replace common environment paths
|
|
409
|
-
.replace(/\/opt\/[^/\s]+\//g, '/opt/<app>/')
|
|
410
|
-
.replace(/\/var\/[^/\s]+\//g, '/var/<app>/')
|
|
411
|
-
// Replace long alphanumeric strings with underscores/hyphens (likely API keys/tokens)
|
|
412
|
-
.replace(/\b[a-zA-Z0-9_-]{32,}\b/g, '<REDACTED>')
|
|
413
|
-
// Replace stack trace locations: "at path:line:col" or " at path:line:col" -> "at <path>:<line>:<col>"
|
|
414
|
-
.replace(/\bat\s+[^:\s]+:\d+:\d+/g, 'at <path>:<line>:<col>'));
|
|
415
|
-
}
|
|
416
|
-
catch (error) {
|
|
417
|
-
// If sanitization fails, return placeholder to avoid leaking raw message
|
|
418
|
-
return '<Failed to sanitize error message>';
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
/**
|
|
422
|
-
* Sanitize stack trace to remove sensitive file paths (Issue #P2)
|
|
423
|
-
*
|
|
424
|
-
* Removes:
|
|
425
|
-
* - Absolute user paths (/Users/<username>/, /home/<username>/)
|
|
426
|
-
* - Windows paths (C:\Users\<username>\)
|
|
427
|
-
* - Environment-specific paths
|
|
428
|
-
*
|
|
429
|
-
* @param stack Raw stack trace
|
|
430
|
-
* @returns Sanitized stack trace with placeholders
|
|
431
|
-
*/
|
|
432
|
-
sanitizeStackTrace(stack) {
|
|
433
|
-
if (!stack)
|
|
434
|
-
return stack;
|
|
435
|
-
try {
|
|
436
|
-
return (stack
|
|
437
|
-
// Replace Unix user paths: /Users/username/ -> /Users/<user>/
|
|
438
|
-
.replace(/\/Users\/[^/]+\//g, '/Users/<user>/')
|
|
439
|
-
// Replace Linux home paths: /home/username/ -> /home/<user>/
|
|
440
|
-
.replace(/\/home\/[^/]+\//g, '/home/<user>/')
|
|
441
|
-
// Replace Windows user paths: C:\Users\username\ -> C:\Users\<user>\
|
|
442
|
-
.replace(/C:\\Users\\[^\\]+\\/gi, 'C:\\Users\\<user>\\')
|
|
443
|
-
// Replace common environment variables that may leak info
|
|
444
|
-
.replace(/\/opt\/[^/]+\//g, '/opt/<app>/')
|
|
445
|
-
.replace(/\/var\/[^/]+\//g, '/var/<app>/'));
|
|
446
|
-
}
|
|
447
|
-
catch (error) {
|
|
448
|
-
// If sanitization fails, return placeholder to avoid leaking raw stack
|
|
449
|
-
return '<Stack trace sanitization failed>';
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
}
|
|
1
|
+
export { ToolLogger } from '../runtime/logging/tool-logger.js';
|
|
453
2
|
//# sourceMappingURL=tool-logger.js.map
|