@kaitranntt/ccs 7.63.0-dev.2 → 7.63.0-dev.3

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.
@@ -183,23 +183,58 @@ function extractDuckDuckGoResults(html, count) {
183
183
  }
184
184
 
185
185
  function formatStructuredSearchResults(query, providerName, results) {
186
+ const lines = [
187
+ 'CCS local WebSearch evidence',
188
+ `Provider: ${providerName}`,
189
+ `Query: "${query}"`,
190
+ `Result count: ${results.length}`,
191
+ '',
192
+ ];
193
+
186
194
  if (!results.length) {
187
- return `No search results found for "${query}" via ${providerName}.`;
195
+ lines.push('No results found.');
196
+ return lines.join('\n');
188
197
  }
189
198
 
190
- const lines = [`Search results for "${query}" via ${providerName}:`, ''];
191
199
  for (const [index, result] of results.entries()) {
192
200
  lines.push(`${index + 1}. ${result.title}`);
193
- lines.push(` ${result.url}`);
201
+ lines.push(` URL: ${result.url}`);
194
202
  if (result.description) {
195
- lines.push(` ${result.description}`);
203
+ lines.push(` Snippet: ${result.description}`);
196
204
  }
197
205
  lines.push('');
198
206
  }
199
- lines.push('Use these results to answer the user directly.');
200
207
  return lines.join('\n');
201
208
  }
202
209
 
210
+ function buildSuccessHookOutput(query, providerName, content) {
211
+ return {
212
+ hookSpecificOutput: {
213
+ hookEventName: 'PreToolUse',
214
+ permissionDecision: 'deny',
215
+ permissionDecisionReason: `CCS already retrieved WebSearch results locally via ${providerName}. Use the provided context instead of calling native WebSearch for "${query}".`,
216
+ additionalContext: content,
217
+ },
218
+ };
219
+ }
220
+
221
+ function buildFailureHookOutput(query, errors) {
222
+ const detail = errors.map((entry) => `${entry.provider}: ${entry.error}`).join(' | ');
223
+ return {
224
+ hookSpecificOutput: {
225
+ hookEventName: 'PreToolUse',
226
+ permissionDecision: 'deny',
227
+ permissionDecisionReason: `CCS could not complete local WebSearch for "${query}". Native WebSearch is unavailable for this profile.`,
228
+ additionalContext: `CCS local WebSearch failed for "${query}". Attempted providers: ${detail}`,
229
+ },
230
+ };
231
+ }
232
+
233
+ function emitHookOutput(output) {
234
+ console.log(JSON.stringify(output));
235
+ process.exit(0);
236
+ }
237
+
203
238
  async function fetchWithTimeout(url, options, timeoutMs) {
204
239
  const controller = new AbortController();
205
240
  const timer = setTimeout(() => controller.abort(), timeoutMs);
@@ -534,34 +569,11 @@ function tryGrokSearch(query, timeoutSec = DEFAULT_TIMEOUT_SEC) {
534
569
  }
535
570
 
536
571
  function outputSuccess(query, content, providerName) {
537
- const output = {
538
- decision: 'block',
539
- reason: `WebSearch handled via ${providerName}`,
540
- hookSpecificOutput: {
541
- hookEventName: 'PreToolUse',
542
- permissionDecision: 'deny',
543
- permissionDecisionReason: `[WebSearch Result via ${providerName}]\n\nQuery: "${query}"\n\n${content}`,
544
- },
545
- };
546
-
547
- console.log(JSON.stringify(output));
548
- process.exit(2);
572
+ emitHookOutput(buildSuccessHookOutput(query, providerName, content));
549
573
  }
550
574
 
551
575
  function outputAllFailedMessage(query, errors) {
552
- const detail = errors.map((entry) => `${entry.provider}: ${entry.error}`).join(' | ');
553
- const output = {
554
- decision: 'block',
555
- reason: 'WebSearch fallback failed',
556
- hookSpecificOutput: {
557
- hookEventName: 'PreToolUse',
558
- permissionDecision: 'deny',
559
- permissionDecisionReason: `WebSearch could not be completed for "${query}". ${detail}`,
560
- },
561
- };
562
-
563
- console.log(JSON.stringify(output));
564
- process.exit(2);
576
+ emitHookOutput(buildFailureHookOutput(query, errors));
565
577
  }
566
578
 
567
579
  async function processHook(input) {
@@ -675,6 +687,8 @@ if (require.main === module) {
675
687
  }
676
688
 
677
689
  module.exports = {
690
+ buildFailureHookOutput,
691
+ buildSuccessHookOutput,
678
692
  extractDuckDuckGoResults,
679
693
  formatStructuredSearchResults,
680
694
  tryExaSearch,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kaitranntt/ccs",
3
- "version": "7.63.0-dev.2",
3
+ "version": "7.63.0-dev.3",
4
4
  "description": "Claude Code Switch - Instant profile switching between Claude, GLM, Kimi, and more",
5
5
  "keywords": [
6
6
  "cli",