@kaitranntt/ccs 7.43.0 → 7.44.0-dev.2

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 (271) hide show
  1. package/README.md +49 -2
  2. package/config/base-codex.settings.json +4 -4
  3. package/dist/api/services/profile-reader.d.ts.map +1 -1
  4. package/dist/api/services/profile-reader.js +4 -1
  5. package/dist/api/services/profile-reader.js.map +1 -1
  6. package/dist/auth/profile-detector.d.ts +14 -3
  7. package/dist/auth/profile-detector.d.ts.map +1 -1
  8. package/dist/auth/profile-detector.js +35 -15
  9. package/dist/auth/profile-detector.js.map +1 -1
  10. package/dist/ccs.js +34 -4
  11. package/dist/ccs.js.map +1 -1
  12. package/dist/cliproxy/auth/auth-types.d.ts +28 -1
  13. package/dist/cliproxy/auth/auth-types.d.ts.map +1 -1
  14. package/dist/cliproxy/auth/auth-types.js +70 -4
  15. package/dist/cliproxy/auth/auth-types.js.map +1 -1
  16. package/dist/cliproxy/auth/oauth-handler.d.ts.map +1 -1
  17. package/dist/cliproxy/auth/oauth-handler.js +19 -4
  18. package/dist/cliproxy/auth/oauth-handler.js.map +1 -1
  19. package/dist/cliproxy/composite-validator.d.ts +20 -0
  20. package/dist/cliproxy/composite-validator.d.ts.map +1 -0
  21. package/dist/cliproxy/composite-validator.js +85 -0
  22. package/dist/cliproxy/composite-validator.js.map +1 -0
  23. package/dist/cliproxy/config/env-builder.d.ts +24 -0
  24. package/dist/cliproxy/config/env-builder.d.ts.map +1 -1
  25. package/dist/cliproxy/config/env-builder.js +72 -1
  26. package/dist/cliproxy/config/env-builder.js.map +1 -1
  27. package/dist/cliproxy/config/thinking-config.d.ts +19 -2
  28. package/dist/cliproxy/config/thinking-config.d.ts.map +1 -1
  29. package/dist/cliproxy/config/thinking-config.js +127 -27
  30. package/dist/cliproxy/config/thinking-config.js.map +1 -1
  31. package/dist/cliproxy/executor/env-resolver.d.ts +16 -0
  32. package/dist/cliproxy/executor/env-resolver.d.ts.map +1 -1
  33. package/dist/cliproxy/executor/env-resolver.js +82 -26
  34. package/dist/cliproxy/executor/env-resolver.js.map +1 -1
  35. package/dist/cliproxy/executor/index.d.ts.map +1 -1
  36. package/dist/cliproxy/executor/index.js +202 -67
  37. package/dist/cliproxy/executor/index.js.map +1 -1
  38. package/dist/cliproxy/executor/retry-handler.d.ts +11 -0
  39. package/dist/cliproxy/executor/retry-handler.d.ts.map +1 -1
  40. package/dist/cliproxy/executor/retry-handler.js +30 -1
  41. package/dist/cliproxy/executor/retry-handler.js.map +1 -1
  42. package/dist/cliproxy/executor/thinking-arg-parser.d.ts +27 -0
  43. package/dist/cliproxy/executor/thinking-arg-parser.d.ts.map +1 -0
  44. package/dist/cliproxy/executor/thinking-arg-parser.js +80 -0
  45. package/dist/cliproxy/executor/thinking-arg-parser.js.map +1 -0
  46. package/dist/cliproxy/model-catalog.d.ts.map +1 -1
  47. package/dist/cliproxy/model-catalog.js +14 -3
  48. package/dist/cliproxy/model-catalog.js.map +1 -1
  49. package/dist/cliproxy/model-config.d.ts.map +1 -1
  50. package/dist/cliproxy/model-config.js +27 -7
  51. package/dist/cliproxy/model-config.js.map +1 -1
  52. package/dist/cliproxy/provider-capabilities.d.ts +22 -0
  53. package/dist/cliproxy/provider-capabilities.d.ts.map +1 -0
  54. package/dist/cliproxy/provider-capabilities.js +95 -0
  55. package/dist/cliproxy/provider-capabilities.js.map +1 -0
  56. package/dist/cliproxy/quota-fetcher-codex.d.ts.map +1 -1
  57. package/dist/cliproxy/quota-fetcher-codex.js +106 -87
  58. package/dist/cliproxy/quota-fetcher-codex.js.map +1 -1
  59. package/dist/cliproxy/remote-auth-fetcher.d.ts.map +1 -1
  60. package/dist/cliproxy/remote-auth-fetcher.js +3 -26
  61. package/dist/cliproxy/remote-auth-fetcher.js.map +1 -1
  62. package/dist/cliproxy/service-manager.d.ts.map +1 -1
  63. package/dist/cliproxy/service-manager.js +3 -6
  64. package/dist/cliproxy/service-manager.js.map +1 -1
  65. package/dist/cliproxy/services/index.d.ts +2 -2
  66. package/dist/cliproxy/services/index.d.ts.map +1 -1
  67. package/dist/cliproxy/services/index.js +4 -1
  68. package/dist/cliproxy/services/index.js.map +1 -1
  69. package/dist/cliproxy/services/proxy-lifecycle-service.d.ts +15 -3
  70. package/dist/cliproxy/services/proxy-lifecycle-service.d.ts.map +1 -1
  71. package/dist/cliproxy/services/proxy-lifecycle-service.js +15 -6
  72. package/dist/cliproxy/services/proxy-lifecycle-service.js.map +1 -1
  73. package/dist/cliproxy/services/variant-config-adapter.d.ts +15 -0
  74. package/dist/cliproxy/services/variant-config-adapter.d.ts.map +1 -1
  75. package/dist/cliproxy/services/variant-config-adapter.js +84 -11
  76. package/dist/cliproxy/services/variant-config-adapter.js.map +1 -1
  77. package/dist/cliproxy/services/variant-service.d.ts +26 -0
  78. package/dist/cliproxy/services/variant-service.d.ts.map +1 -1
  79. package/dist/cliproxy/services/variant-service.js +164 -9
  80. package/dist/cliproxy/services/variant-service.js.map +1 -1
  81. package/dist/cliproxy/services/variant-settings.d.ts +19 -1
  82. package/dist/cliproxy/services/variant-settings.d.ts.map +1 -1
  83. package/dist/cliproxy/services/variant-settings.js +150 -12
  84. package/dist/cliproxy/services/variant-settings.js.map +1 -1
  85. package/dist/cliproxy/types.d.ts +13 -0
  86. package/dist/cliproxy/types.d.ts.map +1 -1
  87. package/dist/cliproxy/types.js.map +1 -1
  88. package/dist/commands/cliproxy/auth-subcommand.d.ts.map +1 -1
  89. package/dist/commands/cliproxy/auth-subcommand.js +2 -1
  90. package/dist/commands/cliproxy/auth-subcommand.js.map +1 -1
  91. package/dist/commands/cliproxy/help-subcommand.d.ts.map +1 -1
  92. package/dist/commands/cliproxy/help-subcommand.js +4 -0
  93. package/dist/commands/cliproxy/help-subcommand.js.map +1 -1
  94. package/dist/commands/cliproxy/index.d.ts.map +1 -1
  95. package/dist/commands/cliproxy/index.js +12 -0
  96. package/dist/commands/cliproxy/index.js.map +1 -1
  97. package/dist/commands/cliproxy/proxy-lifecycle-subcommand.d.ts +9 -0
  98. package/dist/commands/cliproxy/proxy-lifecycle-subcommand.d.ts.map +1 -1
  99. package/dist/commands/cliproxy/proxy-lifecycle-subcommand.js +92 -6
  100. package/dist/commands/cliproxy/proxy-lifecycle-subcommand.js.map +1 -1
  101. package/dist/commands/cliproxy/quota-subcommand.d.ts.map +1 -1
  102. package/dist/commands/cliproxy/quota-subcommand.js +106 -4
  103. package/dist/commands/cliproxy/quota-subcommand.js.map +1 -1
  104. package/dist/commands/cliproxy/variant-subcommand.d.ts +1 -0
  105. package/dist/commands/cliproxy/variant-subcommand.d.ts.map +1 -1
  106. package/dist/commands/cliproxy/variant-subcommand.js +307 -3
  107. package/dist/commands/cliproxy/variant-subcommand.js.map +1 -1
  108. package/dist/commands/command-execution-contract.d.ts +23 -0
  109. package/dist/commands/command-execution-contract.d.ts.map +1 -0
  110. package/dist/commands/command-execution-contract.js +21 -0
  111. package/dist/commands/command-execution-contract.js.map +1 -0
  112. package/dist/commands/cursor-command-display.d.ts +6 -0
  113. package/dist/commands/cursor-command-display.d.ts.map +1 -0
  114. package/dist/commands/cursor-command-display.js +100 -0
  115. package/dist/commands/cursor-command-display.js.map +1 -0
  116. package/dist/commands/cursor-command.d.ts +12 -0
  117. package/dist/commands/cursor-command.d.ts.map +1 -0
  118. package/dist/commands/cursor-command.js +222 -0
  119. package/dist/commands/cursor-command.js.map +1 -0
  120. package/dist/commands/help-command.d.ts.map +1 -1
  121. package/dist/commands/help-command.js +30 -3
  122. package/dist/commands/help-command.js.map +1 -1
  123. package/dist/commands/shell-completion-command.d.ts +20 -0
  124. package/dist/commands/shell-completion-command.d.ts.map +1 -1
  125. package/dist/commands/shell-completion-command.js +45 -30
  126. package/dist/commands/shell-completion-command.js.map +1 -1
  127. package/dist/config/reserved-names.d.ts +1 -1
  128. package/dist/config/reserved-names.d.ts.map +1 -1
  129. package/dist/config/reserved-names.js +2 -0
  130. package/dist/config/reserved-names.js.map +1 -1
  131. package/dist/config/unified-config-loader.d.ts +6 -1
  132. package/dist/config/unified-config-loader.d.ts.map +1 -1
  133. package/dist/config/unified-config-loader.js +63 -3
  134. package/dist/config/unified-config-loader.js.map +1 -1
  135. package/dist/config/unified-config-types.d.ts +79 -2
  136. package/dist/config/unified-config-types.d.ts.map +1 -1
  137. package/dist/config/unified-config-types.js +28 -2
  138. package/dist/config/unified-config-types.js.map +1 -1
  139. package/dist/cursor/cursor-auth.d.ts +58 -0
  140. package/dist/cursor/cursor-auth.d.ts.map +1 -0
  141. package/dist/cursor/cursor-auth.js +295 -0
  142. package/dist/cursor/cursor-auth.js.map +1 -0
  143. package/dist/cursor/cursor-daemon-entry.d.ts +14 -0
  144. package/dist/cursor/cursor-daemon-entry.d.ts.map +1 -0
  145. package/dist/cursor/cursor-daemon-entry.js +236 -0
  146. package/dist/cursor/cursor-daemon-entry.js.map +1 -0
  147. package/dist/cursor/cursor-daemon-pid.d.ts +4 -0
  148. package/dist/cursor/cursor-daemon-pid.d.ts.map +1 -0
  149. package/dist/cursor/cursor-daemon-pid.js +77 -0
  150. package/dist/cursor/cursor-daemon-pid.js.map +1 -0
  151. package/dist/cursor/cursor-daemon.d.ts +36 -0
  152. package/dist/cursor/cursor-daemon.d.ts.map +1 -0
  153. package/dist/cursor/cursor-daemon.js +315 -0
  154. package/dist/cursor/cursor-daemon.js.map +1 -0
  155. package/dist/cursor/cursor-executor.d.ts +81 -0
  156. package/dist/cursor/cursor-executor.d.ts.map +1 -0
  157. package/dist/cursor/cursor-executor.js +821 -0
  158. package/dist/cursor/cursor-executor.js.map +1 -0
  159. package/dist/cursor/cursor-models.d.ts +43 -0
  160. package/dist/cursor/cursor-models.d.ts.map +1 -0
  161. package/dist/cursor/cursor-models.js +288 -0
  162. package/dist/cursor/cursor-models.js.map +1 -0
  163. package/dist/cursor/cursor-protobuf-decoder.d.ts +52 -0
  164. package/dist/cursor/cursor-protobuf-decoder.d.ts.map +1 -0
  165. package/dist/cursor/cursor-protobuf-decoder.js +311 -0
  166. package/dist/cursor/cursor-protobuf-decoder.js.map +1 -0
  167. package/dist/cursor/cursor-protobuf-encoder.d.ts +54 -0
  168. package/dist/cursor/cursor-protobuf-encoder.d.ts.map +1 -0
  169. package/dist/cursor/cursor-protobuf-encoder.js +173 -0
  170. package/dist/cursor/cursor-protobuf-encoder.js.map +1 -0
  171. package/dist/cursor/cursor-protobuf-schema.d.ts +215 -0
  172. package/dist/cursor/cursor-protobuf-schema.d.ts.map +1 -0
  173. package/dist/cursor/cursor-protobuf-schema.js +120 -0
  174. package/dist/cursor/cursor-protobuf-schema.js.map +1 -0
  175. package/dist/cursor/cursor-protobuf.d.ts +21 -0
  176. package/dist/cursor/cursor-protobuf.d.ts.map +1 -0
  177. package/dist/cursor/cursor-protobuf.js +116 -0
  178. package/dist/cursor/cursor-protobuf.js.map +1 -0
  179. package/dist/cursor/cursor-stream-parser.d.ts +52 -0
  180. package/dist/cursor/cursor-stream-parser.d.ts.map +1 -0
  181. package/dist/cursor/cursor-stream-parser.js +142 -0
  182. package/dist/cursor/cursor-stream-parser.js.map +1 -0
  183. package/dist/cursor/cursor-translator.d.ts +39 -0
  184. package/dist/cursor/cursor-translator.d.ts.map +1 -0
  185. package/dist/cursor/cursor-translator.js +118 -0
  186. package/dist/cursor/cursor-translator.js.map +1 -0
  187. package/dist/cursor/daemon-process-ownership.d.ts +3 -0
  188. package/dist/cursor/daemon-process-ownership.d.ts.map +1 -0
  189. package/dist/cursor/daemon-process-ownership.js +96 -0
  190. package/dist/cursor/daemon-process-ownership.js.map +1 -0
  191. package/dist/cursor/index.d.ts +11 -0
  192. package/dist/cursor/index.d.ts.map +1 -0
  193. package/dist/cursor/index.js +55 -0
  194. package/dist/cursor/index.js.map +1 -0
  195. package/dist/cursor/types.d.ts +80 -0
  196. package/dist/cursor/types.d.ts.map +1 -0
  197. package/dist/cursor/types.js +8 -0
  198. package/dist/cursor/types.js.map +1 -0
  199. package/dist/management/oauth-port-diagnostics.d.ts +4 -7
  200. package/dist/management/oauth-port-diagnostics.d.ts.map +1 -1
  201. package/dist/management/oauth-port-diagnostics.js +12 -23
  202. package/dist/management/oauth-port-diagnostics.js.map +1 -1
  203. package/dist/types/index.d.ts +1 -1
  204. package/dist/types/index.d.ts.map +1 -1
  205. package/dist/types/index.js.map +1 -1
  206. package/dist/ui/assets/{accounts-CkN_roEn.js → accounts-B8J62kJ6.js} +1 -1
  207. package/dist/ui/assets/{alert-dialog-Dy-8Z_Ud.js → alert-dialog-B5t_5_UL.js} +1 -1
  208. package/dist/ui/assets/api-DuZyDFf7.js +1 -0
  209. package/dist/ui/assets/auth-section-Dnaxf97q.js +1 -0
  210. package/dist/ui/assets/{backups-section-CDuqhiZo.js → backups-section-DUIq9Rxi.js} +1 -1
  211. package/dist/ui/assets/cliproxy-aK19VC4f.js +3 -0
  212. package/dist/ui/assets/{cliproxy-control-panel-DJd_zNR3.js → cliproxy-control-panel-9OS_kdTh.js} +1 -1
  213. package/dist/ui/assets/confirm-dialog-D7hNt3ez.js +1 -0
  214. package/dist/ui/assets/copilot-B5dVoOMQ.js +3 -0
  215. package/dist/ui/assets/cursor-4zDGbBRA.js +1 -0
  216. package/dist/ui/assets/{globalenv-section-Cn5ufgRh.js → globalenv-section-DuUcheRN.js} +1 -1
  217. package/dist/ui/assets/{health-BsMhSeFz.js → health-Ddkl8zIJ.js} +1 -1
  218. package/dist/ui/assets/{icons-D5eAI-GR.js → icons-DGASzt3M.js} +1 -1
  219. package/dist/ui/assets/index-BRCdKMse.js +1 -0
  220. package/dist/ui/assets/{index-B2GQ_Joi.js → index-BRxqvMyp.js} +1 -1
  221. package/dist/ui/assets/index-C6u1zYVL.css +1 -0
  222. package/dist/ui/assets/index-D0I8OsQ3.js +1 -0
  223. package/dist/ui/assets/{index-CEF_VhSR.js → index-DOxNxHpI.js} +1 -1
  224. package/dist/ui/assets/index-Dv5jtphl.js +47 -0
  225. package/dist/ui/assets/{proxy-status-widget-Cb7KfEqq.js → proxy-status-widget-DKYj4dWI.js} +1 -1
  226. package/dist/ui/assets/separator-DrDw3JjB.js +1 -0
  227. package/dist/ui/assets/{shared-BsWeldW8.js → shared-psG1uSqB.js} +1 -1
  228. package/dist/ui/assets/sidebar/cursor.svg +1 -0
  229. package/dist/ui/assets/{switch-D6XSRTo_.js → switch-C0ri2ChT.js} +1 -1
  230. package/dist/ui/index.html +3 -3
  231. package/dist/utils/config-manager.d.ts.map +1 -1
  232. package/dist/utils/config-manager.js +17 -6
  233. package/dist/utils/config-manager.js.map +1 -1
  234. package/dist/web-server/jsonl-parser.js +1 -1
  235. package/dist/web-server/jsonl-parser.js.map +1 -1
  236. package/dist/web-server/routes/account-routes.d.ts.map +1 -1
  237. package/dist/web-server/routes/account-routes.js +5 -11
  238. package/dist/web-server/routes/account-routes.js.map +1 -1
  239. package/dist/web-server/routes/cliproxy-auth-routes.d.ts +5 -0
  240. package/dist/web-server/routes/cliproxy-auth-routes.d.ts.map +1 -1
  241. package/dist/web-server/routes/cliproxy-auth-routes.js +73 -6
  242. package/dist/web-server/routes/cliproxy-auth-routes.js.map +1 -1
  243. package/dist/web-server/routes/cliproxy-stats-routes.d.ts.map +1 -1
  244. package/dist/web-server/routes/cliproxy-stats-routes.js +43 -4
  245. package/dist/web-server/routes/cliproxy-stats-routes.js.map +1 -1
  246. package/dist/web-server/routes/cursor-routes.d.ts +16 -0
  247. package/dist/web-server/routes/cursor-routes.d.ts.map +1 -0
  248. package/dist/web-server/routes/cursor-routes.js +171 -0
  249. package/dist/web-server/routes/cursor-routes.js.map +1 -0
  250. package/dist/web-server/routes/cursor-settings-routes.d.ts +6 -0
  251. package/dist/web-server/routes/cursor-settings-routes.d.ts.map +1 -0
  252. package/dist/web-server/routes/cursor-settings-routes.js +305 -0
  253. package/dist/web-server/routes/cursor-settings-routes.js.map +1 -0
  254. package/dist/web-server/routes/index.d.ts.map +1 -1
  255. package/dist/web-server/routes/index.js +3 -0
  256. package/dist/web-server/routes/index.js.map +1 -1
  257. package/dist/web-server/routes/variant-routes.d.ts.map +1 -1
  258. package/dist/web-server/routes/variant-routes.js +107 -6
  259. package/dist/web-server/routes/variant-routes.js.map +1 -1
  260. package/package.json +5 -2
  261. package/scripts/hardening-inventory.js +526 -0
  262. package/scripts/maintainability-baseline.js +309 -0
  263. package/dist/ui/assets/api-2TN7yVwm.js +0 -1
  264. package/dist/ui/assets/auth-section-CeKCNzzC.js +0 -1
  265. package/dist/ui/assets/cliproxy-626zUpA_.js +0 -3
  266. package/dist/ui/assets/confirm-dialog-DtYrWaa7.js +0 -1
  267. package/dist/ui/assets/copilot-DHdywZ9L.js +0 -4
  268. package/dist/ui/assets/index-Bmgylhgn.js +0 -1
  269. package/dist/ui/assets/index-Cr6iEc8x.js +0 -47
  270. package/dist/ui/assets/index-DkMR3J96.js +0 -1
  271. package/dist/ui/assets/index-QvMpU4Lc.css +0 -1
@@ -0,0 +1,526 @@
1
+ #!/usr/bin/env node
2
+
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+
6
+ const ROOT_DIR = path.resolve(__dirname, '..');
7
+ const SRC_DIR = path.join(ROOT_DIR, 'src');
8
+ const REPORT_DIR = path.join(ROOT_DIR, 'docs', 'reports');
9
+ const JSON_REPORT_PATH = path.join(REPORT_DIR, 'hardening-inventory.json');
10
+ const MD_REPORT_PATH = path.join(REPORT_DIR, 'hardening-inventory.md');
11
+
12
+ const SOURCE_EXTENSIONS = new Set(['.ts', '.tsx', '.js', '.jsx', '.mjs', '.cjs']);
13
+ const HOTPATH_PATTERNS = [
14
+ /^src\/web-server\//,
15
+ /^src\/commands\//,
16
+ /^src\/cliproxy\//,
17
+ /^src\/management\//,
18
+ /^src\/auth\//,
19
+ /^src\/delegation\//,
20
+ /^src\/utils\//,
21
+ /^src\/ccs\.ts$/,
22
+ ];
23
+
24
+ const SYNC_CALL_NAMES = [
25
+ 'accessSync',
26
+ 'appendFileSync',
27
+ 'chmodSync',
28
+ 'chownSync',
29
+ 'closeSync',
30
+ 'copyFileSync',
31
+ 'cpSync',
32
+ 'existsSync',
33
+ 'fstatSync',
34
+ 'fsyncSync',
35
+ 'ftruncateSync',
36
+ 'futimesSync',
37
+ 'lchmodSync',
38
+ 'lchownSync',
39
+ 'linkSync',
40
+ 'lstatSync',
41
+ 'mkdirSync',
42
+ 'mkdtempSync',
43
+ 'openSync',
44
+ 'opendirSync',
45
+ 'readFileSync',
46
+ 'readdirSync',
47
+ 'readlinkSync',
48
+ 'readSync',
49
+ 'readvSync',
50
+ 'realpathSync',
51
+ 'renameSync',
52
+ 'rmSync',
53
+ 'rmdirSync',
54
+ 'statSync',
55
+ 'symlinkSync',
56
+ 'truncateSync',
57
+ 'unlinkSync',
58
+ 'utimesSync',
59
+ 'writeFileSync',
60
+ 'writeSync',
61
+ 'writevSync',
62
+ ];
63
+ const SYNC_CALL_CAPTURE_REGEX = new RegExp(
64
+ `(?:\\bfs(?:\\s*\\?\\.)?\\s*\\.\\s*|(?<![\\w$.]))(${SYNC_CALL_NAMES.join('|')})\\s*\\(`,
65
+ 'g'
66
+ );
67
+ const LEGACY_MARKER_REGEX =
68
+ /(?:\blegacy\b|\bshim\b|backward compatibility|backwards compatibility|compatibility layer|deprecated.*re-export|re-export.*compatibility)/i;
69
+ const REGEX_LITERAL_KEYWORDS = new Set([
70
+ 'return',
71
+ 'throw',
72
+ 'case',
73
+ 'else',
74
+ 'do',
75
+ 'delete',
76
+ 'void',
77
+ 'typeof',
78
+ 'instanceof',
79
+ 'in',
80
+ 'of',
81
+ 'yield',
82
+ 'await',
83
+ 'new',
84
+ ]);
85
+
86
+ function toPosixPath(filePath) {
87
+ return filePath.split(path.sep).join('/');
88
+ }
89
+
90
+ function relativePath(filePath) {
91
+ return toPosixPath(path.relative(ROOT_DIR, filePath));
92
+ }
93
+
94
+ function isSourceFile(filePath) {
95
+ return SOURCE_EXTENSIONS.has(path.extname(filePath));
96
+ }
97
+
98
+ function isHotpath(filePath) {
99
+ return HOTPATH_PATTERNS.some((pattern) => pattern.test(filePath));
100
+ }
101
+
102
+ function walkFiles(dirPath) {
103
+ const output = [];
104
+ const entries = fs.readdirSync(dirPath, { withFileTypes: true });
105
+
106
+ for (const entry of entries) {
107
+ const fullPath = path.join(dirPath, entry.name);
108
+ if (entry.isDirectory()) {
109
+ output.push(...walkFiles(fullPath));
110
+ continue;
111
+ }
112
+
113
+ if (entry.isFile() && isSourceFile(fullPath)) {
114
+ output.push(fullPath);
115
+ }
116
+ }
117
+
118
+ return output;
119
+ }
120
+
121
+ function uniqueSorted(values) {
122
+ return Array.from(new Set(values)).sort((a, b) => a.localeCompare(b));
123
+ }
124
+
125
+ function sortByCountDesc(items) {
126
+ return [...items].sort((a, b) => {
127
+ if (b.count !== a.count) return b.count - a.count;
128
+ return a.file.localeCompare(b.file);
129
+ });
130
+ }
131
+
132
+ function summarize(items, limit = 10) {
133
+ return sortByCountDesc(items)
134
+ .slice(0, limit)
135
+ .map((item) => ({
136
+ file: item.file,
137
+ count: item.count,
138
+ calls: uniqueSorted(item.calls || []),
139
+ markers: uniqueSorted(item.markers || []),
140
+ }));
141
+ }
142
+
143
+ function isRegexLiteralStart(previousSignificantChar, previousIdentifier) {
144
+ return (
145
+ previousSignificantChar === '' ||
146
+ '([{:;,=!?+-*%^&|~<>'.includes(previousSignificantChar) ||
147
+ REGEX_LITERAL_KEYWORDS.has(previousIdentifier)
148
+ );
149
+ }
150
+
151
+ function stripComments(sourceText) {
152
+ let output = '';
153
+ let index = 0;
154
+ let inLineComment = false;
155
+ let inBlockComment = false;
156
+ let inSingleQuote = false;
157
+ let inDoubleQuote = false;
158
+ let inTemplateLiteral = false;
159
+ let inRegexLiteral = false;
160
+ let inRegexCharClass = false;
161
+ let previousSignificantChar = '';
162
+ let previousIdentifier = '';
163
+
164
+ while (index < sourceText.length) {
165
+ const current = sourceText[index];
166
+ const next = sourceText[index + 1];
167
+
168
+ if (inLineComment) {
169
+ if (current === '\n' || current === '\r') {
170
+ inLineComment = false;
171
+ output += current;
172
+ } else {
173
+ output += ' ';
174
+ }
175
+ index += 1;
176
+ continue;
177
+ }
178
+
179
+ if (inBlockComment) {
180
+ if (current === '*' && next === '/') {
181
+ output += ' ';
182
+ index += 2;
183
+ inBlockComment = false;
184
+ continue;
185
+ }
186
+
187
+ output += current === '\n' || current === '\r' ? current : ' ';
188
+ index += 1;
189
+ continue;
190
+ }
191
+
192
+ if (inRegexLiteral) {
193
+ if (current === '\n' || current === '\r') {
194
+ output += current;
195
+ index += 1;
196
+ inRegexLiteral = false;
197
+ inRegexCharClass = false;
198
+ continue;
199
+ }
200
+
201
+ output += ' ';
202
+
203
+ if (current === '\\') {
204
+ output += next === '\n' || next === '\r' ? next : ' ';
205
+ index += 2;
206
+ continue;
207
+ }
208
+
209
+ if (!inRegexCharClass && current === '[') {
210
+ inRegexCharClass = true;
211
+ index += 1;
212
+ continue;
213
+ }
214
+
215
+ if (inRegexCharClass && current === ']') {
216
+ inRegexCharClass = false;
217
+ index += 1;
218
+ continue;
219
+ }
220
+
221
+ if (!inRegexCharClass && current === '/') {
222
+ index += 1;
223
+ while (index < sourceText.length && /[a-z]/i.test(sourceText[index])) {
224
+ output += ' ';
225
+ index += 1;
226
+ }
227
+ inRegexLiteral = false;
228
+ previousSignificantChar = 'r';
229
+ previousIdentifier = '';
230
+ continue;
231
+ }
232
+
233
+ index += 1;
234
+ continue;
235
+ }
236
+
237
+ if (inSingleQuote) {
238
+ output += current === '\n' || current === '\r' ? current : ' ';
239
+ if (current === '\\') {
240
+ output += next === '\n' || next === '\r' ? next : ' ';
241
+ index += 2;
242
+ continue;
243
+ }
244
+ if (current === "'") {
245
+ inSingleQuote = false;
246
+ previousSignificantChar = 's';
247
+ previousIdentifier = '';
248
+ }
249
+ index += 1;
250
+ continue;
251
+ }
252
+
253
+ if (inDoubleQuote) {
254
+ output += current === '\n' || current === '\r' ? current : ' ';
255
+ if (current === '\\') {
256
+ output += next === '\n' || next === '\r' ? next : ' ';
257
+ index += 2;
258
+ continue;
259
+ }
260
+ if (current === '"') {
261
+ inDoubleQuote = false;
262
+ previousSignificantChar = 's';
263
+ previousIdentifier = '';
264
+ }
265
+ index += 1;
266
+ continue;
267
+ }
268
+
269
+ if (inTemplateLiteral) {
270
+ output += current === '\n' || current === '\r' ? current : ' ';
271
+ if (current === '\\') {
272
+ output += next === '\n' || next === '\r' ? next : ' ';
273
+ index += 2;
274
+ continue;
275
+ }
276
+ if (current === '`') {
277
+ inTemplateLiteral = false;
278
+ previousSignificantChar = 's';
279
+ previousIdentifier = '';
280
+ }
281
+ index += 1;
282
+ continue;
283
+ }
284
+
285
+ if (current === '/' && next === '/') {
286
+ output += ' ';
287
+ index += 2;
288
+ inLineComment = true;
289
+ continue;
290
+ }
291
+
292
+ if (current === '/' && next === '*') {
293
+ output += ' ';
294
+ index += 2;
295
+ inBlockComment = true;
296
+ continue;
297
+ }
298
+
299
+ if (current === '/' && isRegexLiteralStart(previousSignificantChar, previousIdentifier)) {
300
+ output += ' ';
301
+ index += 1;
302
+ inRegexLiteral = true;
303
+ inRegexCharClass = false;
304
+ continue;
305
+ }
306
+
307
+ if (/[A-Za-z_$]/.test(current)) {
308
+ let tokenEnd = index + 1;
309
+ while (tokenEnd < sourceText.length && /[A-Za-z0-9_$]/.test(sourceText[tokenEnd])) {
310
+ tokenEnd += 1;
311
+ }
312
+ const token = sourceText.slice(index, tokenEnd);
313
+ output += token;
314
+ previousSignificantChar = 'i';
315
+ previousIdentifier = token;
316
+ index = tokenEnd;
317
+ continue;
318
+ }
319
+
320
+ if (current === "'") {
321
+ inSingleQuote = true;
322
+ output += ' ';
323
+ index += 1;
324
+ continue;
325
+ }
326
+
327
+ if (current === '"') {
328
+ inDoubleQuote = true;
329
+ output += ' ';
330
+ index += 1;
331
+ continue;
332
+ }
333
+
334
+ if (current === '`') {
335
+ inTemplateLiteral = true;
336
+ output += ' ';
337
+ index += 1;
338
+ continue;
339
+ }
340
+
341
+ output += current;
342
+ if (!/\s/.test(current)) {
343
+ previousSignificantChar = current;
344
+ previousIdentifier = '';
345
+ }
346
+ index += 1;
347
+ }
348
+
349
+ return output;
350
+ }
351
+
352
+ function collectSyncCallSites(sourceText) {
353
+ const sanitizedSource = stripComments(sourceText);
354
+ const captureRegex = new RegExp(SYNC_CALL_CAPTURE_REGEX.source, SYNC_CALL_CAPTURE_REGEX.flags);
355
+ const calls = [];
356
+
357
+ for (const match of sanitizedSource.matchAll(captureRegex)) {
358
+ calls.push(match[1]);
359
+ }
360
+
361
+ return {
362
+ count: calls.length,
363
+ calls,
364
+ };
365
+ }
366
+
367
+ function buildReport() {
368
+ const files = walkFiles(SRC_DIR);
369
+ const syncEntries = [];
370
+ const legacyEntries = [];
371
+
372
+ for (const fullPath of files) {
373
+ const file = relativePath(fullPath);
374
+ const sourceText = fs.readFileSync(fullPath, 'utf8');
375
+ const lines = sourceText.split(/\r?\n/);
376
+ const { count: syncCount, calls: syncCalls } = collectSyncCallSites(sourceText);
377
+ let legacyCount = 0;
378
+ const legacyMarkers = [];
379
+
380
+ for (const line of lines) {
381
+ if (LEGACY_MARKER_REGEX.test(line)) {
382
+ legacyCount += 1;
383
+ const normalized = line.trim();
384
+ if (normalized.length > 0) {
385
+ legacyMarkers.push(normalized);
386
+ }
387
+ }
388
+ }
389
+
390
+ if (syncCount > 0) {
391
+ syncEntries.push({
392
+ file,
393
+ count: syncCount,
394
+ calls: syncCalls,
395
+ hotpath: isHotpath(file),
396
+ });
397
+ }
398
+
399
+ if (legacyCount > 0) {
400
+ legacyEntries.push({
401
+ file,
402
+ count: legacyCount,
403
+ markers: legacyMarkers,
404
+ });
405
+ }
406
+ }
407
+
408
+ const syncHotpathEntries = syncEntries.filter((entry) => entry.hotpath);
409
+ const totalSyncCount = syncEntries.reduce((acc, entry) => acc + entry.count, 0);
410
+ const totalSyncHotpathCount = syncHotpathEntries.reduce((acc, entry) => acc + entry.count, 0);
411
+ const totalLegacyMarkers = legacyEntries.reduce((acc, entry) => acc + entry.count, 0);
412
+
413
+ return {
414
+ scope: 'src/**/*.{ts,tsx,js,jsx,mjs,cjs}',
415
+ syncFs: {
416
+ totalOccurrences: totalSyncCount,
417
+ filesAffected: syncEntries.length,
418
+ hotpathOccurrences: totalSyncHotpathCount,
419
+ hotpathFilesAffected: syncHotpathEntries.length,
420
+ topHotpathFiles: summarize(syncHotpathEntries),
421
+ topFilesOverall: summarize(syncEntries),
422
+ },
423
+ legacyShim: {
424
+ totalMarkers: totalLegacyMarkers,
425
+ filesAffected: legacyEntries.length,
426
+ topFiles: summarize(legacyEntries),
427
+ explicitShimFiles: uniqueSorted(
428
+ legacyEntries
429
+ .map((entry) => entry.file)
430
+ .filter((file) => /shim|re-export|compat/i.test(path.basename(file)))
431
+ ),
432
+ },
433
+ };
434
+ }
435
+
436
+ function renderMarkdown(report) {
437
+ const lines = [];
438
+
439
+ lines.push('# Hardening Inventory Report');
440
+ lines.push('');
441
+ lines.push(`Scope: \`${report.scope}\``);
442
+ lines.push('');
443
+ lines.push('## Summary');
444
+ lines.push('');
445
+ lines.push('| Metric | Value |');
446
+ lines.push('|---|---:|');
447
+ lines.push(`| Sync fs occurrences (all) | ${report.syncFs.totalOccurrences} |`);
448
+ lines.push(`| Sync fs files affected (all) | ${report.syncFs.filesAffected} |`);
449
+ lines.push(`| Sync fs occurrences (runtime hotpaths) | ${report.syncFs.hotpathOccurrences} |`);
450
+ lines.push(`| Sync fs files affected (runtime hotpaths) | ${report.syncFs.hotpathFilesAffected} |`);
451
+ lines.push(`| Legacy shim markers | ${report.legacyShim.totalMarkers} |`);
452
+ lines.push(`| Legacy shim files affected | ${report.legacyShim.filesAffected} |`);
453
+ lines.push('');
454
+
455
+ lines.push('## Top Runtime Hotpath Sync fs Files');
456
+ lines.push('');
457
+ lines.push('| File | Sync Calls | API Names |');
458
+ lines.push('|---|---:|---|');
459
+
460
+ for (const item of report.syncFs.topHotpathFiles) {
461
+ lines.push(`| \`${item.file}\` | ${item.count} | ${item.calls.join(', ')} |`);
462
+ }
463
+
464
+ if (report.syncFs.topHotpathFiles.length === 0) {
465
+ lines.push('| _none_ | 0 | - |');
466
+ }
467
+
468
+ lines.push('');
469
+ lines.push('## Top Legacy Shim Marker Files');
470
+ lines.push('');
471
+ lines.push('| File | Marker Count |');
472
+ lines.push('|---|---:|');
473
+
474
+ for (const item of report.legacyShim.topFiles) {
475
+ lines.push(`| \`${item.file}\` | ${item.count} |`);
476
+ }
477
+
478
+ if (report.legacyShim.topFiles.length === 0) {
479
+ lines.push('| _none_ | 0 |');
480
+ }
481
+
482
+ lines.push('');
483
+ lines.push('## Explicit Shim/Re-export Files');
484
+ lines.push('');
485
+ for (const file of report.legacyShim.explicitShimFiles) {
486
+ lines.push(`- \`${file}\``);
487
+ }
488
+ if (report.legacyShim.explicitShimFiles.length === 0) {
489
+ lines.push('- _none_');
490
+ }
491
+
492
+ lines.push('');
493
+ return lines.join('\n');
494
+ }
495
+
496
+ function main() {
497
+ const report = buildReport();
498
+
499
+ fs.mkdirSync(REPORT_DIR, { recursive: true });
500
+ fs.writeFileSync(JSON_REPORT_PATH, JSON.stringify(report, null, 2) + '\n', 'utf8');
501
+ fs.writeFileSync(MD_REPORT_PATH, renderMarkdown(report), 'utf8');
502
+
503
+ const relJson = relativePath(JSON_REPORT_PATH);
504
+ const relMd = relativePath(MD_REPORT_PATH);
505
+
506
+ console.log(`[hardening-inventory] generatedAt=${new Date().toISOString()}`);
507
+ console.log(
508
+ `[hardening-inventory] sync-fs total=${report.syncFs.totalOccurrences}, hotpath=${report.syncFs.hotpathOccurrences}`
509
+ );
510
+ console.log(
511
+ `[hardening-inventory] legacy markers total=${report.legacyShim.totalMarkers}, files=${report.legacyShim.filesAffected}`
512
+ );
513
+ console.log(`[hardening-inventory] wrote ${relJson}`);
514
+ console.log(`[hardening-inventory] wrote ${relMd}`);
515
+ }
516
+
517
+ if (require.main === module) {
518
+ main();
519
+ }
520
+
521
+ module.exports = {
522
+ buildReport,
523
+ collectSyncCallSites,
524
+ renderMarkdown,
525
+ stripComments,
526
+ };