@kaitranntt/ccs 4.4.0 → 5.0.1

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 (262) hide show
  1. package/README.md +98 -7
  2. package/VERSION +1 -1
  3. package/config/base-agy.settings.json +10 -0
  4. package/config/base-codex.settings.json +10 -0
  5. package/config/base-gemini.settings.json +10 -0
  6. package/dist/auth/auth-commands.d.ts +52 -0
  7. package/dist/auth/auth-commands.d.ts.map +1 -0
  8. package/dist/auth/auth-commands.js +479 -0
  9. package/dist/auth/auth-commands.js.map +1 -0
  10. package/dist/auth/profile-detector.d.ts +68 -0
  11. package/dist/auth/profile-detector.d.ts.map +1 -0
  12. package/dist/auth/profile-detector.js +209 -0
  13. package/dist/auth/profile-detector.js.map +1 -0
  14. package/dist/auth/profile-registry.d.ts +60 -0
  15. package/dist/auth/profile-registry.d.ts.map +1 -0
  16. package/dist/auth/profile-registry.js +188 -0
  17. package/dist/auth/profile-registry.js.map +1 -0
  18. package/dist/ccs.d.ts +10 -0
  19. package/dist/ccs.d.ts.map +1 -0
  20. package/dist/ccs.js +320 -0
  21. package/dist/ccs.js.map +1 -0
  22. package/dist/cliproxy/auth-handler.d.ts +95 -0
  23. package/dist/cliproxy/auth-handler.d.ts.map +1 -0
  24. package/dist/cliproxy/auth-handler.js +443 -0
  25. package/dist/cliproxy/auth-handler.js.map +1 -0
  26. package/dist/cliproxy/base-config-loader.d.ts +42 -0
  27. package/dist/cliproxy/base-config-loader.d.ts.map +1 -0
  28. package/dist/cliproxy/base-config-loader.js +123 -0
  29. package/dist/cliproxy/base-config-loader.js.map +1 -0
  30. package/dist/cliproxy/binary-manager.d.ts +104 -0
  31. package/dist/cliproxy/binary-manager.d.ts.map +1 -0
  32. package/dist/cliproxy/binary-manager.js +567 -0
  33. package/dist/cliproxy/binary-manager.js.map +1 -0
  34. package/dist/cliproxy/cliproxy-executor.d.ts +33 -0
  35. package/dist/cliproxy/cliproxy-executor.d.ts.map +1 -0
  36. package/dist/cliproxy/cliproxy-executor.js +297 -0
  37. package/dist/cliproxy/cliproxy-executor.js.map +1 -0
  38. package/dist/cliproxy/config-generator.d.ts +89 -0
  39. package/dist/cliproxy/config-generator.d.ts.map +1 -0
  40. package/dist/cliproxy/config-generator.js +263 -0
  41. package/dist/cliproxy/config-generator.js.map +1 -0
  42. package/dist/cliproxy/index.d.ts +13 -0
  43. package/dist/cliproxy/index.d.ts.map +1 -0
  44. package/dist/cliproxy/index.js +62 -0
  45. package/dist/cliproxy/index.js.map +1 -0
  46. package/dist/cliproxy/platform-detector.d.ts +48 -0
  47. package/dist/cliproxy/platform-detector.d.ts.map +1 -0
  48. package/dist/cliproxy/platform-detector.js +118 -0
  49. package/dist/cliproxy/platform-detector.js.map +1 -0
  50. package/dist/cliproxy/types.d.ts +169 -0
  51. package/dist/cliproxy/types.d.ts.map +1 -0
  52. package/dist/cliproxy/types.js +7 -0
  53. package/dist/cliproxy/types.js.map +1 -0
  54. package/dist/commands/doctor-command.d.ts +10 -0
  55. package/dist/commands/doctor-command.d.ts.map +1 -0
  56. package/dist/commands/doctor-command.js +44 -0
  57. package/dist/commands/doctor-command.js.map +1 -0
  58. package/dist/commands/help-command.d.ts +5 -0
  59. package/dist/commands/help-command.d.ts.map +1 -0
  60. package/dist/commands/help-command.js +104 -0
  61. package/dist/commands/help-command.js.map +1 -0
  62. package/dist/commands/install-command.d.ts +14 -0
  63. package/dist/commands/install-command.d.ts.map +1 -0
  64. package/dist/commands/install-command.js +39 -0
  65. package/dist/commands/install-command.js.map +1 -0
  66. package/dist/commands/shell-completion-command.d.ts +10 -0
  67. package/dist/commands/shell-completion-command.d.ts.map +1 -0
  68. package/dist/commands/shell-completion-command.js +85 -0
  69. package/dist/commands/shell-completion-command.js.map +1 -0
  70. package/dist/commands/sync-command.d.ts +10 -0
  71. package/dist/commands/sync-command.d.ts.map +1 -0
  72. package/dist/commands/sync-command.js +59 -0
  73. package/dist/commands/sync-command.js.map +1 -0
  74. package/dist/commands/update-command.d.ts +12 -0
  75. package/dist/commands/update-command.d.ts.map +1 -0
  76. package/dist/commands/update-command.js +295 -0
  77. package/dist/commands/update-command.js.map +1 -0
  78. package/dist/commands/version-command.d.ts +10 -0
  79. package/dist/commands/version-command.d.ts.map +1 -0
  80. package/dist/commands/version-command.js +100 -0
  81. package/dist/commands/version-command.js.map +1 -0
  82. package/dist/delegation/delegation-handler.d.ts +60 -0
  83. package/dist/delegation/delegation-handler.d.ts.map +1 -0
  84. package/dist/delegation/delegation-handler.js +174 -0
  85. package/dist/delegation/delegation-handler.js.map +1 -0
  86. package/dist/delegation/headless-executor.d.ts +114 -0
  87. package/dist/delegation/headless-executor.d.ts.map +1 -0
  88. package/dist/delegation/headless-executor.js +562 -0
  89. package/dist/delegation/headless-executor.js.map +1 -0
  90. package/dist/delegation/result-formatter.d.ts +108 -0
  91. package/dist/delegation/result-formatter.d.ts.map +1 -0
  92. package/dist/delegation/result-formatter.js +391 -0
  93. package/dist/delegation/result-formatter.js.map +1 -0
  94. package/dist/delegation/session-manager.d.ts +58 -0
  95. package/dist/delegation/session-manager.d.ts.map +1 -0
  96. package/dist/delegation/session-manager.js +153 -0
  97. package/dist/delegation/session-manager.js.map +1 -0
  98. package/dist/delegation/settings-parser.d.ts +31 -0
  99. package/dist/delegation/settings-parser.d.ts.map +1 -0
  100. package/dist/delegation/settings-parser.js +107 -0
  101. package/dist/delegation/settings-parser.js.map +1 -0
  102. package/dist/glmt/delta-accumulator.d.ts +210 -0
  103. package/dist/glmt/delta-accumulator.d.ts.map +1 -0
  104. package/dist/glmt/delta-accumulator.js +351 -0
  105. package/dist/glmt/delta-accumulator.js.map +1 -0
  106. package/dist/glmt/glmt-proxy.d.ts +72 -0
  107. package/dist/glmt/glmt-proxy.d.ts.map +1 -0
  108. package/dist/glmt/glmt-proxy.js +427 -0
  109. package/dist/glmt/glmt-proxy.js.map +1 -0
  110. package/dist/glmt/glmt-transformer.d.ts +265 -0
  111. package/dist/glmt/glmt-transformer.d.ts.map +1 -0
  112. package/dist/glmt/glmt-transformer.js +832 -0
  113. package/dist/glmt/glmt-transformer.js.map +1 -0
  114. package/dist/glmt/locale-enforcer.d.ts +38 -0
  115. package/dist/glmt/locale-enforcer.d.ts.map +1 -0
  116. package/dist/glmt/locale-enforcer.js +69 -0
  117. package/dist/glmt/locale-enforcer.js.map +1 -0
  118. package/dist/glmt/reasoning-enforcer.d.ts +52 -0
  119. package/dist/glmt/reasoning-enforcer.d.ts.map +1 -0
  120. package/dist/glmt/reasoning-enforcer.js +151 -0
  121. package/dist/glmt/reasoning-enforcer.js.map +1 -0
  122. package/dist/glmt/sse-parser.d.ts +47 -0
  123. package/dist/glmt/sse-parser.d.ts.map +1 -0
  124. package/dist/glmt/sse-parser.js +93 -0
  125. package/dist/glmt/sse-parser.js.map +1 -0
  126. package/dist/management/doctor.d.ts +104 -0
  127. package/dist/management/doctor.d.ts.map +1 -0
  128. package/dist/management/doctor.js +673 -0
  129. package/dist/management/doctor.js.map +1 -0
  130. package/dist/management/instance-manager.d.ts +57 -0
  131. package/dist/management/instance-manager.d.ts.map +1 -0
  132. package/dist/management/instance-manager.js +195 -0
  133. package/dist/management/instance-manager.js.map +1 -0
  134. package/dist/management/recovery-manager.d.ts +39 -0
  135. package/dist/management/recovery-manager.d.ts.map +1 -0
  136. package/dist/management/recovery-manager.js +141 -0
  137. package/dist/management/recovery-manager.js.map +1 -0
  138. package/dist/management/shared-manager.d.ts +47 -0
  139. package/dist/management/shared-manager.d.ts.map +1 -0
  140. package/dist/management/shared-manager.js +388 -0
  141. package/dist/management/shared-manager.js.map +1 -0
  142. package/dist/types/cli.d.ts +50 -0
  143. package/dist/types/cli.d.ts.map +1 -0
  144. package/dist/types/cli.js +16 -0
  145. package/dist/types/cli.js.map +1 -0
  146. package/dist/types/config.d.ts +51 -0
  147. package/dist/types/config.d.ts.map +1 -0
  148. package/dist/types/config.js +26 -0
  149. package/dist/types/config.js.map +1 -0
  150. package/dist/types/delegation.d.ts +61 -0
  151. package/dist/types/delegation.d.ts.map +1 -0
  152. package/dist/types/delegation.js +6 -0
  153. package/dist/types/delegation.js.map +1 -0
  154. package/dist/types/glmt.d.ts +95 -0
  155. package/dist/types/glmt.d.ts.map +1 -0
  156. package/dist/types/glmt.js +7 -0
  157. package/dist/types/glmt.js.map +1 -0
  158. package/dist/types/index.d.ts +13 -0
  159. package/dist/types/index.d.ts.map +1 -0
  160. package/dist/types/index.js +16 -0
  161. package/dist/types/index.js.map +1 -0
  162. package/dist/types/utils.d.ts +36 -0
  163. package/dist/types/utils.d.ts.map +1 -0
  164. package/dist/types/utils.js +22 -0
  165. package/dist/types/utils.js.map +1 -0
  166. package/dist/utils/claude-detector.d.ts +14 -0
  167. package/dist/utils/claude-detector.d.ts.map +1 -0
  168. package/dist/utils/claude-detector.js +112 -0
  169. package/dist/utils/claude-detector.js.map +1 -0
  170. package/dist/utils/claude-dir-installer.d.ts +46 -0
  171. package/dist/utils/claude-dir-installer.d.ts.map +1 -0
  172. package/dist/utils/claude-dir-installer.js +289 -0
  173. package/dist/utils/claude-dir-installer.js.map +1 -0
  174. package/dist/utils/claude-symlink-manager.d.ts +61 -0
  175. package/dist/utils/claude-symlink-manager.d.ts.map +1 -0
  176. package/dist/utils/claude-symlink-manager.js +291 -0
  177. package/dist/utils/claude-symlink-manager.js.map +1 -0
  178. package/dist/utils/config-manager.d.ts +32 -0
  179. package/dist/utils/config-manager.d.ts.map +1 -0
  180. package/dist/utils/config-manager.js +143 -0
  181. package/dist/utils/config-manager.js.map +1 -0
  182. package/dist/utils/delegation-validator.d.ts +39 -0
  183. package/dist/utils/delegation-validator.d.ts.map +1 -0
  184. package/dist/utils/delegation-validator.js +161 -0
  185. package/dist/utils/delegation-validator.js.map +1 -0
  186. package/dist/utils/error-codes.d.ts +36 -0
  187. package/dist/utils/error-codes.d.ts.map +1 -0
  188. package/dist/utils/error-codes.js +63 -0
  189. package/dist/utils/error-codes.js.map +1 -0
  190. package/dist/utils/error-manager.d.ts +59 -0
  191. package/dist/utils/error-manager.d.ts.map +1 -0
  192. package/dist/utils/error-manager.js +228 -0
  193. package/dist/utils/error-manager.js.map +1 -0
  194. package/dist/utils/helpers.d.ts +27 -0
  195. package/dist/utils/helpers.d.ts.map +1 -0
  196. package/dist/utils/helpers.js +150 -0
  197. package/dist/utils/helpers.js.map +1 -0
  198. package/dist/utils/package-manager-detector.d.ts +14 -0
  199. package/dist/utils/package-manager-detector.d.ts.map +1 -0
  200. package/dist/utils/package-manager-detector.js +162 -0
  201. package/dist/utils/package-manager-detector.js.map +1 -0
  202. package/dist/utils/progress-indicator.d.ts +52 -0
  203. package/dist/utils/progress-indicator.d.ts.map +1 -0
  204. package/dist/utils/progress-indicator.js +102 -0
  205. package/dist/utils/progress-indicator.js.map +1 -0
  206. package/dist/utils/prompt.d.ts +29 -0
  207. package/dist/utils/prompt.d.ts.map +1 -0
  208. package/dist/utils/prompt.js +116 -0
  209. package/dist/utils/prompt.js.map +1 -0
  210. package/dist/utils/shell-completion.d.ts +52 -0
  211. package/dist/utils/shell-completion.d.ts.map +1 -0
  212. package/dist/utils/shell-completion.js +231 -0
  213. package/dist/utils/shell-completion.js.map +1 -0
  214. package/dist/utils/shell-executor.d.ts +15 -0
  215. package/dist/utils/shell-executor.d.ts.map +1 -0
  216. package/dist/utils/shell-executor.js +57 -0
  217. package/dist/utils/shell-executor.js.map +1 -0
  218. package/dist/utils/update-checker.d.ts +48 -0
  219. package/dist/utils/update-checker.d.ts.map +1 -0
  220. package/dist/utils/update-checker.js +241 -0
  221. package/dist/utils/update-checker.js.map +1 -0
  222. package/lib/ccs +21 -1907
  223. package/lib/ccs.ps1 +26 -1800
  224. package/lib/error-codes.ps1 +2 -1
  225. package/lib/prompt.ps1 +2 -2
  226. package/package.json +31 -11
  227. package/scripts/add-shebang.js +39 -0
  228. package/scripts/bump-version.sh +25 -37
  229. package/scripts/dev-install.sh +32 -11
  230. package/scripts/postinstall.js +29 -29
  231. package/bin/auth/auth-commands.js +0 -499
  232. package/bin/auth/profile-detector.js +0 -204
  233. package/bin/auth/profile-registry.js +0 -225
  234. package/bin/ccs.js +0 -1034
  235. package/bin/delegation/README.md +0 -191
  236. package/bin/delegation/delegation-handler.js +0 -212
  237. package/bin/delegation/headless-executor.js +0 -618
  238. package/bin/delegation/result-formatter.js +0 -485
  239. package/bin/delegation/session-manager.js +0 -157
  240. package/bin/delegation/settings-parser.js +0 -109
  241. package/bin/glmt/delta-accumulator.js +0 -276
  242. package/bin/glmt/glmt-proxy.js +0 -495
  243. package/bin/glmt/glmt-transformer.js +0 -999
  244. package/bin/glmt/locale-enforcer.js +0 -72
  245. package/bin/glmt/reasoning-enforcer.js +0 -173
  246. package/bin/glmt/sse-parser.js +0 -96
  247. package/bin/management/doctor.js +0 -721
  248. package/bin/management/instance-manager.js +0 -202
  249. package/bin/management/recovery-manager.js +0 -135
  250. package/bin/management/shared-manager.js +0 -402
  251. package/bin/utils/claude-detector.js +0 -73
  252. package/bin/utils/claude-dir-installer.js +0 -283
  253. package/bin/utils/claude-symlink-manager.js +0 -289
  254. package/bin/utils/config-manager.js +0 -103
  255. package/bin/utils/delegation-validator.js +0 -154
  256. package/bin/utils/error-codes.js +0 -59
  257. package/bin/utils/error-manager.js +0 -165
  258. package/bin/utils/helpers.js +0 -136
  259. package/bin/utils/progress-indicator.js +0 -111
  260. package/bin/utils/prompt.js +0 -134
  261. package/bin/utils/shell-completion.js +0 -256
  262. package/bin/utils/update-checker.js +0 -243
@@ -1,72 +0,0 @@
1
- #!/usr/bin/env node
2
- 'use strict';
3
-
4
- /**
5
- * LocaleEnforcer - Force English output from GLM models
6
- *
7
- * Purpose: GLM models default to Chinese when prompts are ambiguous or contain Chinese context.
8
- * This module always injects "MUST respond in English" instruction into system prompt or first user message.
9
- *
10
- * Usage:
11
- * const enforcer = new LocaleEnforcer();
12
- * const modifiedMessages = enforcer.injectInstruction(messages);
13
- *
14
- * Strategy:
15
- * 1. If system prompt exists: Prepend instruction
16
- * 2. If no system prompt: Prepend to first user message
17
- * 3. Preserve message structure (string vs array content)
18
- */
19
- class LocaleEnforcer {
20
- constructor(options = {}) {
21
- this.instruction = "CRITICAL: You MUST respond in English only, regardless of the input language or context. This is a strict requirement.";
22
- }
23
-
24
- /**
25
- * Inject English instruction into messages
26
- * @param {Array} messages - Messages array to modify
27
- * @returns {Array} Modified messages array
28
- */
29
- injectInstruction(messages) {
30
- // Clone messages to avoid mutation
31
- const modifiedMessages = JSON.parse(JSON.stringify(messages));
32
-
33
- // Strategy 1: Inject into system prompt (preferred)
34
- const systemIndex = modifiedMessages.findIndex(m => m.role === 'system');
35
- if (systemIndex >= 0) {
36
- const systemMsg = modifiedMessages[systemIndex];
37
-
38
- if (typeof systemMsg.content === 'string') {
39
- systemMsg.content = `${this.instruction}\n\n${systemMsg.content}`;
40
- } else if (Array.isArray(systemMsg.content)) {
41
- systemMsg.content.unshift({
42
- type: 'text',
43
- text: this.instruction
44
- });
45
- }
46
-
47
- return modifiedMessages;
48
- }
49
-
50
- // Strategy 2: Prepend to first user message
51
- const userIndex = modifiedMessages.findIndex(m => m.role === 'user');
52
- if (userIndex >= 0) {
53
- const userMsg = modifiedMessages[userIndex];
54
-
55
- if (typeof userMsg.content === 'string') {
56
- userMsg.content = `${this.instruction}\n\n${userMsg.content}`;
57
- } else if (Array.isArray(userMsg.content)) {
58
- userMsg.content.unshift({
59
- type: 'text',
60
- text: this.instruction
61
- });
62
- }
63
-
64
- return modifiedMessages;
65
- }
66
-
67
- // No system or user messages found (edge case)
68
- return modifiedMessages;
69
- }
70
- }
71
-
72
- module.exports = LocaleEnforcer;
@@ -1,173 +0,0 @@
1
- #!/usr/bin/env node
2
- 'use strict';
3
-
4
- /**
5
- * ReasoningEnforcer - Inject explicit reasoning instructions into prompts
6
- *
7
- * Purpose: Force GLM models to use structured reasoning output format (<reasoning_content>)
8
- * This complements API parameters (reasoning: true) with explicit prompt instructions.
9
- *
10
- * Usage:
11
- * const enforcer = new ReasoningEnforcer({ enabled: true });
12
- * const modifiedMessages = enforcer.injectInstruction(messages, thinkingConfig);
13
- *
14
- * Strategy:
15
- * 1. If system prompt exists: Prepend reasoning instruction
16
- * 2. If no system prompt: Prepend to first user message
17
- * 3. Select prompt template based on effort level (low/medium/high/max)
18
- * 4. Preserve message structure (string vs array content)
19
- */
20
-
21
- class ReasoningEnforcer {
22
- constructor(options = {}) {
23
- this.enabled = options.enabled ?? false; // Opt-in by default
24
- this.prompts = options.prompts || this._getDefaultPrompts();
25
- }
26
-
27
- /**
28
- * Inject reasoning instruction into messages
29
- * @param {Array} messages - Messages array to modify
30
- * @param {Object} thinkingConfig - { thinking: boolean, effort: string }
31
- * @returns {Array} Modified messages array
32
- */
33
- injectInstruction(messages, thinkingConfig = {}) {
34
- // Only inject if enabled or thinking explicitly requested
35
- if (!this.enabled && !thinkingConfig.thinking) {
36
- return messages;
37
- }
38
-
39
- // Clone messages to avoid mutation
40
- const modifiedMessages = JSON.parse(JSON.stringify(messages));
41
-
42
- // Select prompt based on effort level
43
- const prompt = this._selectPrompt(thinkingConfig.effort || 'medium');
44
-
45
- // Strategy 1: Inject into system prompt (preferred)
46
- const systemIndex = modifiedMessages.findIndex(m => m.role === 'system');
47
- if (systemIndex >= 0) {
48
- const systemMsg = modifiedMessages[systemIndex];
49
-
50
- if (typeof systemMsg.content === 'string') {
51
- systemMsg.content = `${prompt}\n\n${systemMsg.content}`;
52
- } else if (Array.isArray(systemMsg.content)) {
53
- systemMsg.content.unshift({
54
- type: 'text',
55
- text: prompt
56
- });
57
- }
58
-
59
- return modifiedMessages;
60
- }
61
-
62
- // Strategy 2: Prepend to first user message
63
- const userIndex = modifiedMessages.findIndex(m => m.role === 'user');
64
- if (userIndex >= 0) {
65
- const userMsg = modifiedMessages[userIndex];
66
-
67
- if (typeof userMsg.content === 'string') {
68
- userMsg.content = `${prompt}\n\n${userMsg.content}`;
69
- } else if (Array.isArray(userMsg.content)) {
70
- userMsg.content.unshift({
71
- type: 'text',
72
- text: prompt
73
- });
74
- }
75
-
76
- return modifiedMessages;
77
- }
78
-
79
- // No system or user messages found (edge case)
80
- return modifiedMessages;
81
- }
82
-
83
- /**
84
- * Select prompt template based on effort level
85
- * @param {string} effort - 'low', 'medium', 'high', or 'max'
86
- * @returns {string} Prompt template
87
- * @private
88
- */
89
- _selectPrompt(effort) {
90
- const normalizedEffort = effort.toLowerCase();
91
- return this.prompts[normalizedEffort] || this.prompts.medium;
92
- }
93
-
94
- /**
95
- * Get default prompt templates
96
- * @returns {Object} Map of effort levels to prompts
97
- * @private
98
- */
99
- _getDefaultPrompts() {
100
- return {
101
- low: `You are an expert reasoning model using GLM-4.6 architecture.
102
-
103
- CRITICAL: Before answering, write 2-3 sentences of reasoning in <reasoning_content> tags.
104
-
105
- OUTPUT FORMAT:
106
- <reasoning_content>
107
- (Brief analysis: what is the problem? what's the approach?)
108
- </reasoning_content>
109
-
110
- (Write your final answer here)`,
111
-
112
- medium: `You are an expert reasoning model using GLM-4.6 architecture.
113
-
114
- CRITICAL REQUIREMENTS:
115
- 1. Always think step-by-step before answering
116
- 2. Write your reasoning process explicitly in <reasoning_content> tags
117
- 3. Never skip your chain of thought, even for simple problems
118
-
119
- OUTPUT FORMAT:
120
- <reasoning_content>
121
- (Write your detailed thinking here: analyze the problem, explore approaches,
122
- evaluate trade-offs, and arrive at a conclusion)
123
- </reasoning_content>
124
-
125
- (Write your final answer here based on your reasoning above)`,
126
-
127
- high: `You are an expert reasoning model using GLM-4.6 architecture.
128
-
129
- CRITICAL REQUIREMENTS:
130
- 1. Think deeply and systematically before answering
131
- 2. Write comprehensive reasoning in <reasoning_content> tags
132
- 3. Explore multiple approaches and evaluate trade-offs
133
- 4. Show all steps in your problem-solving process
134
-
135
- OUTPUT FORMAT:
136
- <reasoning_content>
137
- (Write exhaustive analysis here:
138
- - Problem decomposition
139
- - Multiple approach exploration
140
- - Trade-off analysis for each approach
141
- - Edge case consideration
142
- - Final conclusion with justification)
143
- </reasoning_content>
144
-
145
- (Write your final answer here based on your systematic reasoning above)`,
146
-
147
- max: `You are an expert reasoning model using GLM-4.6 architecture.
148
-
149
- CRITICAL REQUIREMENTS:
150
- 1. Think exhaustively from first principles
151
- 2. Write extremely detailed reasoning in <reasoning_content> tags
152
- 3. Analyze ALL possible angles, approaches, and edge cases
153
- 4. Challenge your own assumptions and explore alternatives
154
- 5. Provide rigorous justification for every claim
155
-
156
- OUTPUT FORMAT:
157
- <reasoning_content>
158
- (Write comprehensive analysis here:
159
- - First principles breakdown
160
- - Exhaustive approach enumeration
161
- - Comparative analysis of all approaches
162
- - Edge case and failure mode analysis
163
- - Assumption validation
164
- - Counter-argument consideration
165
- - Final conclusion with rigorous justification)
166
- </reasoning_content>
167
-
168
- (Write your final answer here based on your exhaustive reasoning above)`
169
- };
170
- }
171
- }
172
-
173
- module.exports = ReasoningEnforcer;
@@ -1,96 +0,0 @@
1
- #!/usr/bin/env node
2
- 'use strict';
3
-
4
- /**
5
- * SSEParser - Parse Server-Sent Events (SSE) stream
6
- *
7
- * Handles:
8
- * - Incomplete events across chunks
9
- * - Multiple events in single chunk
10
- * - Malformed data (skip gracefully)
11
- * - [DONE] marker
12
- *
13
- * Usage:
14
- * const parser = new SSEParser();
15
- * stream.on('data', chunk => {
16
- * const events = parser.parse(chunk);
17
- * events.forEach(event => { ... });
18
- * });
19
- */
20
- class SSEParser {
21
- constructor(options = {}) {
22
- this.buffer = '';
23
- this.eventCount = 0;
24
- this.maxBufferSize = options.maxBufferSize || 1024 * 1024; // 1MB default
25
- }
26
-
27
- /**
28
- * Parse chunk and extract SSE events
29
- * @param {Buffer|string} chunk - Data chunk from stream
30
- * @returns {Array<Object>} Array of parsed events
31
- */
32
- parse(chunk) {
33
- this.buffer += chunk.toString();
34
-
35
- // C-01 Fix: Prevent unbounded buffer growth (DoS protection)
36
- if (this.buffer.length > this.maxBufferSize) {
37
- throw new Error(`SSE buffer exceeded ${this.maxBufferSize} bytes (DoS protection)`);
38
- }
39
-
40
- const lines = this.buffer.split('\n');
41
-
42
- // Keep incomplete line in buffer
43
- this.buffer = lines.pop() || '';
44
-
45
- const events = [];
46
- let currentEvent = { event: 'message', data: '' };
47
-
48
- for (const line of lines) {
49
- if (line.startsWith('event: ')) {
50
- currentEvent.event = line.substring(7).trim();
51
- } else if (line.startsWith('data: ')) {
52
- const data = line.substring(6);
53
-
54
- if (data === '[DONE]') {
55
- this.eventCount++;
56
- events.push({
57
- event: 'done',
58
- data: null,
59
- index: this.eventCount
60
- });
61
- currentEvent = { event: 'message', data: '' };
62
- } else {
63
- try {
64
- currentEvent.data = JSON.parse(data);
65
- this.eventCount++;
66
- currentEvent.index = this.eventCount;
67
- events.push(currentEvent);
68
- currentEvent = { event: 'message', data: '' };
69
- } catch (e) {
70
- // H-01 Fix: Log parse errors for debugging
71
- if (typeof console !== 'undefined' && console.error) {
72
- console.error('[SSEParser] Malformed JSON event:', e.message, 'Data:', data.substring(0, 100));
73
- }
74
- }
75
- }
76
- } else if (line.startsWith('id: ')) {
77
- currentEvent.id = line.substring(4).trim();
78
- } else if (line.startsWith('retry: ')) {
79
- currentEvent.retry = parseInt(line.substring(7), 10);
80
- }
81
- // Empty lines separate events (already handled by JSON parsing)
82
- }
83
-
84
- return events;
85
- }
86
-
87
- /**
88
- * Reset parser state (for reuse)
89
- */
90
- reset() {
91
- this.buffer = '';
92
- this.eventCount = 0;
93
- }
94
- }
95
-
96
- module.exports = SSEParser;