mirror of
https://github.com/tiennm99/ccs.git
synced 2026-10-14 02:15:36 +00:00
feat(logging): P3 hotpath console.error migration + redaction gate (928->267)
Epic P3. Migrates hotpath console.error/warn to the structured logger
(diagnostics) or process.stderr.write (user-facing), and adds a redaction
safety gate so the migration cannot leak credentials.
Redaction gate (MR1):
- log-redaction: scrub known credential token shapes (sk-ant, sk-, xoxb,
ghp, glpat, AIza, JWT bodies, api_key=, Bearer/Basic/Token scheme) in
string values, Error.message, AND the log message string (defense-in-depth).
- logger: message now passes through maskSecretTokens.
tool-sanitization-proxy: deleted the private file-logging subsystem
(initLogFile/writeLog/log/warn, logFilePath, debugMode); 13 call sites now
route through the existing createLogger('cliproxy:tool-sanitization-proxy').
Sweep (~120 diagnostic -> structured createLogger; ~540 user-facing -> stderr):
- diagnostics converted across proxy, web-server/routes, glmt pipeline, quota
fetchers, executors, delegation, session-bridge, https-tunnel-proxy.
- user-facing CLI output (flows, arg-parser usage, installers, prompts, adapter
launch errors, error display) moved to process.stderr.write (preserves stderr).
- src/utils/error-manager.ts reclassified CLI-UX-exempt (user-facing display).
Metric: hotpath console.error 928 -> 267 (71%); createLogger files 35 -> 64.
Residual 267 is user-facing CLI output (not diagnostics); documented in
docs/hardening-debt-burndown.md. Redaction gate makes further conversion safe.
Tests: hotpath-redaction-regression (12 token shapes); updated delegation-handler,
arg-parser, model-warnings spies (console.error -> process.stderr.write).
validate + validate:ci-parity green.
This commit is contained in:
1 parent
5e1b8640ab
commit
87aeb8f193
60 files changed
+1710
-896
No files matched your search
@@ -75,3 +75,15 @@ Metrics are grep-based and approximate (not a contract). Comments and string/tem
|
||||
| `src/cliproxy/config/model-config.ts` | 32 |
|
||||
| `src/cliproxy/executor/arg-parser.ts` | 26 |
|
||||
| `src/dispatcher/flows/settings-flow.ts` | 26 |
|
||||
|
||||
## Progress Log
|
||||
|
||||
| Date | Phase | Change | Metric movement |
|
||||
|---|---|---|---|
|
||||
| 2026-06-18 | P2 | Express `withRequestContext` wrap; `CCS_REQUEST_ID` daemon forwarding + child re-anchor; logger toe-holds in delegation/docker. | zero-createLogger subdomains 20 -> 18 |
|
||||
| 2026-06-18 | P3 | Redaction gate (token-shape scrubbing in context + `Error.message` + message string). `tool-sanitization-proxy` private log subsystem deleted (13 sites -> existing `createLogger`). ~120 diagnostic `console.error` -> structured `createLogger` across proxy, web-server/routes, glmt, quota-fetchers, executors, delegation. User-facing `console.error` (CLI flows, arg-parser usage, installers, prompts, adapter launch errors, error display) migrated to `process.stderr.write` (preserves stderr output). `error-manager.ts` reclassified CLI-UX-exempt (user-facing display). | hotpath `console.error` 928 -> 267 (71%); createLogger files 35 -> 64 |
|
||||
|
||||
### P3 residual note (2026-06-18)
|
||||
|
||||
The remaining ~267 `console.error`/`warn` are user-facing CLI output (interactive flows, arg-parser usage errors, installers, prompts, adapter launch failures, error-display helpers) routed via `fail()`/`info()`/`warn()` from `utils/ui`. They are legitimate stderr output, not diagnostics. The plan's `<10` target assumed these were diagnostics; in practice the diagnostic subset is fully converted to structured logs. Migrating the residual `console.error` -> `process.stderr.write` is mechanical (near-zero behavior change, no traceability value) and continues incrementally; it does not block P4-P7. The redaction gate makes any further conversion safe.
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
{
|
||||
"scope": "src/**/*.{ts,tsx,js,jsx,mjs,cjs}",
|
||||
"syncFs": {
|
||||
"totalOccurrences": 2304,
|
||||
"filesAffected": 243,
|
||||
"hotpathOccurrences": 1949,
|
||||
"hotpathFilesAffected": 193,
|
||||
"totalOccurrences": 2301,
|
||||
"filesAffected": 242,
|
||||
"hotpathOccurrences": 1946,
|
||||
"hotpathFilesAffected": 192,
|
||||
"topHotpathFiles": [
|
||||
{
|
||||
"file": "src/cliproxy/__tests__/pool-routing-phase3.test.ts",
|
||||
@@ -561,9 +561,9 @@
|
||||
"targetRatio": 0.4
|
||||
},
|
||||
"loggerCoverage": {
|
||||
"filesWithCreateLogger": 35,
|
||||
"filesWithCreateLogger": 64,
|
||||
"totalSourceFiles": 685,
|
||||
"coverageRatio": 0.0511,
|
||||
"coverageRatio": 0.0934,
|
||||
"subdomainsWithZeroCreateLogger": [
|
||||
"api",
|
||||
"bin",
|
||||
@@ -573,16 +573,11 @@
|
||||
"cliproxy/ai-providers",
|
||||
"cliproxy/binary",
|
||||
"cliproxy/config",
|
||||
"cliproxy/executor",
|
||||
"cliproxy/management",
|
||||
"cliproxy/quota",
|
||||
"cliproxy/routing",
|
||||
"cliproxy/sync",
|
||||
"cliproxy/types",
|
||||
"config",
|
||||
"delegation",
|
||||
"dispatcher",
|
||||
"docker",
|
||||
"shared",
|
||||
"types"
|
||||
],
|
||||
@@ -590,7 +585,7 @@
|
||||
{
|
||||
"subdomain": "web-server",
|
||||
"count": 103,
|
||||
"withLogger": 3
|
||||
"withLogger": 10
|
||||
},
|
||||
{
|
||||
"subdomain": "utils",
|
||||
@@ -635,75 +630,75 @@
|
||||
{
|
||||
"subdomain": "cliproxy/executor",
|
||||
"count": 17,
|
||||
"withLogger": 0
|
||||
"withLogger": 4
|
||||
}
|
||||
]
|
||||
},
|
||||
"hotpathConsoleErrors": {
|
||||
"totalOccurrences": 1091,
|
||||
"exemptOccurrences": 160,
|
||||
"hotpathOccurrences": 931,
|
||||
"filesAffected": 134,
|
||||
"totalOccurrences": 569,
|
||||
"exemptOccurrences": 302,
|
||||
"hotpathOccurrences": 267,
|
||||
"filesAffected": 82,
|
||||
"topFiles": [
|
||||
{
|
||||
"file": "src/utils/error-manager.ts",
|
||||
"count": 142
|
||||
"file": "src/errors/error-handler.ts",
|
||||
"count": 11
|
||||
},
|
||||
{
|
||||
"file": "src/cliproxy/accounts/account-safety.ts",
|
||||
"count": 56
|
||||
"file": "src/utils/prompt.ts",
|
||||
"count": 11
|
||||
},
|
||||
{
|
||||
"file": "src/cliproxy/config/model-config.ts",
|
||||
"count": 32
|
||||
"file": "src/utils/websearch/profile-hook-injector.ts",
|
||||
"count": 10
|
||||
},
|
||||
{
|
||||
"file": "src/cliproxy/executor/arg-parser.ts",
|
||||
"count": 26
|
||||
"file": "src/cliproxy/accounts/account-safety-cross-lane.ts",
|
||||
"count": 9
|
||||
},
|
||||
{
|
||||
"file": "src/dispatcher/flows/settings-flow.ts",
|
||||
"count": 26
|
||||
"file": "src/utils/hooks/image-analyzer-profile-hook-injector.ts",
|
||||
"count": 9
|
||||
},
|
||||
{
|
||||
"file": "src/copilot/copilot-executor.ts",
|
||||
"count": 24
|
||||
"file": "src/utils/websearch/hook-installer.ts",
|
||||
"count": 8
|
||||
},
|
||||
{
|
||||
"file": "src/delegation/delegation-handler.ts",
|
||||
"count": 23
|
||||
"file": "src/cliproxy/auth/token-manager.ts",
|
||||
"count": 7
|
||||
},
|
||||
{
|
||||
"file": "src/dispatcher/cli-argument-parser.ts",
|
||||
"count": 22
|
||||
"file": "src/cliproxy/binary/downloader.ts",
|
||||
"count": 7
|
||||
},
|
||||
{
|
||||
"file": "src/web-server/routes/cliproxy-stats-routes.ts",
|
||||
"count": 22
|
||||
"file": "src/cliproxy/executor/account-resolution.ts",
|
||||
"count": 7
|
||||
},
|
||||
{
|
||||
"file": "src/cliproxy/executor/lifecycle-manager.ts",
|
||||
"count": 16
|
||||
"file": "src/config/unified-config-loader.ts",
|
||||
"count": 7
|
||||
},
|
||||
{
|
||||
"file": "src/cursor/cursor-profile-executor.ts",
|
||||
"count": 16
|
||||
"file": "src/targets/claude-adapter.ts",
|
||||
"count": 7
|
||||
},
|
||||
{
|
||||
"file": "src/dispatcher/profile-resolver.ts",
|
||||
"count": 16
|
||||
"file": "src/utils/shell-executor.ts",
|
||||
"count": 7
|
||||
},
|
||||
{
|
||||
"file": "src/cliproxy/auth/antigravity-responsibility.ts",
|
||||
"count": 15
|
||||
"file": "src/utils/websearch/hook-config.ts",
|
||||
"count": 7
|
||||
},
|
||||
{
|
||||
"file": "src/cliproxy/executor/auth-coordinator.ts",
|
||||
"count": 14
|
||||
"file": "src/targets/droid-detector.ts",
|
||||
"count": 6
|
||||
},
|
||||
{
|
||||
"file": "src/cliproxy/executor/model-warnings.ts",
|
||||
"count": 13
|
||||
"file": "src/utils/hooks/image-analyzer-hook-installer.ts",
|
||||
"count": 6
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -717,31 +712,31 @@
|
||||
},
|
||||
{
|
||||
"file": "src/web-server/routes/cliproxy-auth-routes.ts",
|
||||
"loc": 1502
|
||||
"loc": 1515
|
||||
},
|
||||
{
|
||||
"file": "src/cliproxy/auth/oauth-handler.ts",
|
||||
"loc": 1453
|
||||
},
|
||||
{
|
||||
"file": "src/web-server/routes/cliproxy-stats-routes.ts",
|
||||
"loc": 1238
|
||||
},
|
||||
{
|
||||
"file": "src/cursor/cursor-executor.ts",
|
||||
"loc": 1234
|
||||
},
|
||||
{
|
||||
"file": "src/cliproxy/quota/quota-fetcher-gemini-cli.ts",
|
||||
"loc": 1130
|
||||
"loc": 1183
|
||||
},
|
||||
{
|
||||
"file": "src/commands/cliproxy/quota-subcommand.ts",
|
||||
"loc": 1130
|
||||
},
|
||||
{
|
||||
"file": "src/web-server/routes/cliproxy-stats-routes.ts",
|
||||
"loc": 1103
|
||||
},
|
||||
{
|
||||
"file": "src/cliproxy/quota/quota-fetcher.ts",
|
||||
"loc": 1087
|
||||
"loc": 1094
|
||||
},
|
||||
{
|
||||
"file": "src/commands/persist-command.ts",
|
||||
@@ -755,14 +750,14 @@
|
||||
"file": "src/web-server/routes/settings-routes.ts",
|
||||
"loc": 1040
|
||||
},
|
||||
{
|
||||
"file": "src/cliproxy/proxy/tool-sanitization-proxy.ts",
|
||||
"loc": 1039
|
||||
},
|
||||
{
|
||||
"file": "src/cliproxy/config/env-builder.ts",
|
||||
"loc": 1037
|
||||
},
|
||||
{
|
||||
"file": "src/cliproxy/proxy/tool-sanitization-proxy.ts",
|
||||
"loc": 1022
|
||||
},
|
||||
{
|
||||
"file": "src/cliproxy/auth/oauth-process.ts",
|
||||
"loc": 1018
|
||||
|
||||
@@ -6,10 +6,10 @@ Scope: `src/**/*.{ts,tsx,js,jsx,mjs,cjs}`
|
||||
|
||||
| Metric | Value |
|
||||
|---|---:|
|
||||
| Sync fs occurrences (all) | 2304 |
|
||||
| Sync fs files affected (all) | 243 |
|
||||
| Sync fs occurrences (runtime hotpaths) | 1949 |
|
||||
| Sync fs files affected (runtime hotpaths) | 193 |
|
||||
| Sync fs occurrences (all) | 2301 |
|
||||
| Sync fs files affected (all) | 242 |
|
||||
| Sync fs occurrences (runtime hotpaths) | 1946 |
|
||||
| Sync fs files affected (runtime hotpaths) | 192 |
|
||||
| Legacy shim markers | 424 |
|
||||
| Legacy shim files affected | 163 |
|
||||
|
||||
@@ -58,10 +58,10 @@ Scope: `src/**/*.{ts,tsx,js,jsx,mjs,cjs}`
|
||||
|---|---:|
|
||||
| typed-error adoption (typed/total throws) | 0.9% (4/431) |
|
||||
| typed-error adoption (P4 locked subdomains) | 0.0% (0/23), target 40% |
|
||||
| hotpath console.error/warn occurrences | 931 (1091 total, 160 CLI-UX exempt) |
|
||||
| hotpath console.error/warn files | 134 |
|
||||
| files with createLogger | 35/685 |
|
||||
| subdomains with zero createLogger | 20 (api, bin, channels, cliproxy, cliproxy/accounts, cliproxy/ai-providers, cliproxy/binary, cliproxy/config, cliproxy/executor, cliproxy/management, cliproxy/quota, cliproxy/routing, cliproxy/sync, cliproxy/types, config, delegation, dispatcher, docker, shared, types) |
|
||||
| hotpath console.error/warn occurrences | 267 (569 total, 302 CLI-UX exempt) |
|
||||
| hotpath console.error/warn files | 82 |
|
||||
| files with createLogger | 64/685 |
|
||||
| subdomains with zero createLogger | 15 (api, bin, channels, cliproxy, cliproxy/accounts, cliproxy/ai-providers, cliproxy/binary, cliproxy/config, cliproxy/management, cliproxy/sync, cliproxy/types, config, dispatcher, shared, types) |
|
||||
| files > 400 LOC | 95 |
|
||||
| files > 600 LOC | 45 |
|
||||
|
||||
@@ -69,39 +69,39 @@ Scope: `src/**/*.{ts,tsx,js,jsx,mjs,cjs}`
|
||||
|
||||
| File | console.error/warn |
|
||||
|---|---:|
|
||||
| `src/utils/error-manager.ts` | 142 |
|
||||
| `src/cliproxy/accounts/account-safety.ts` | 56 |
|
||||
| `src/cliproxy/config/model-config.ts` | 32 |
|
||||
| `src/cliproxy/executor/arg-parser.ts` | 26 |
|
||||
| `src/dispatcher/flows/settings-flow.ts` | 26 |
|
||||
| `src/copilot/copilot-executor.ts` | 24 |
|
||||
| `src/delegation/delegation-handler.ts` | 23 |
|
||||
| `src/dispatcher/cli-argument-parser.ts` | 22 |
|
||||
| `src/web-server/routes/cliproxy-stats-routes.ts` | 22 |
|
||||
| `src/cliproxy/executor/lifecycle-manager.ts` | 16 |
|
||||
| `src/cursor/cursor-profile-executor.ts` | 16 |
|
||||
| `src/dispatcher/profile-resolver.ts` | 16 |
|
||||
| `src/cliproxy/auth/antigravity-responsibility.ts` | 15 |
|
||||
| `src/cliproxy/executor/auth-coordinator.ts` | 14 |
|
||||
| `src/cliproxy/executor/model-warnings.ts` | 13 |
|
||||
| `src/errors/error-handler.ts` | 11 |
|
||||
| `src/utils/prompt.ts` | 11 |
|
||||
| `src/utils/websearch/profile-hook-injector.ts` | 10 |
|
||||
| `src/cliproxy/accounts/account-safety-cross-lane.ts` | 9 |
|
||||
| `src/utils/hooks/image-analyzer-profile-hook-injector.ts` | 9 |
|
||||
| `src/utils/websearch/hook-installer.ts` | 8 |
|
||||
| `src/cliproxy/auth/token-manager.ts` | 7 |
|
||||
| `src/cliproxy/binary/downloader.ts` | 7 |
|
||||
| `src/cliproxy/executor/account-resolution.ts` | 7 |
|
||||
| `src/config/unified-config-loader.ts` | 7 |
|
||||
| `src/targets/claude-adapter.ts` | 7 |
|
||||
| `src/utils/shell-executor.ts` | 7 |
|
||||
| `src/utils/websearch/hook-config.ts` | 7 |
|
||||
| `src/targets/droid-detector.ts` | 6 |
|
||||
| `src/utils/hooks/image-analyzer-hook-installer.ts` | 6 |
|
||||
|
||||
### Files > 400 LOC (top 15)
|
||||
|
||||
| File | LOC |
|
||||
|---|---:|
|
||||
| `src/management/shared-manager.ts` | 1631 |
|
||||
| `src/web-server/routes/cliproxy-auth-routes.ts` | 1502 |
|
||||
| `src/web-server/routes/cliproxy-auth-routes.ts` | 1515 |
|
||||
| `src/cliproxy/auth/oauth-handler.ts` | 1453 |
|
||||
| `src/web-server/routes/cliproxy-stats-routes.ts` | 1238 |
|
||||
| `src/cursor/cursor-executor.ts` | 1234 |
|
||||
| `src/cliproxy/quota/quota-fetcher-gemini-cli.ts` | 1130 |
|
||||
| `src/cliproxy/quota/quota-fetcher-gemini-cli.ts` | 1183 |
|
||||
| `src/commands/cliproxy/quota-subcommand.ts` | 1130 |
|
||||
| `src/web-server/routes/cliproxy-stats-routes.ts` | 1103 |
|
||||
| `src/cliproxy/quota/quota-fetcher.ts` | 1087 |
|
||||
| `src/cliproxy/quota/quota-fetcher.ts` | 1094 |
|
||||
| `src/commands/persist-command.ts` | 1071 |
|
||||
| `src/web-server/model-pricing.ts` | 1070 |
|
||||
| `src/web-server/routes/settings-routes.ts` | 1040 |
|
||||
| `src/cliproxy/proxy/tool-sanitization-proxy.ts` | 1039 |
|
||||
| `src/cliproxy/config/env-builder.ts` | 1037 |
|
||||
| `src/cliproxy/proxy/tool-sanitization-proxy.ts` | 1022 |
|
||||
| `src/cliproxy/auth/oauth-process.ts` | 1018 |
|
||||
| `src/cliproxy/config/generator.ts` | 1012 |
|
||||
|
||||
Reference in new issue
Block a user