mirror of
https://github.com/tiennm99/ccs.git
synced 2026-09-02 18:18:43 +00:00
feat(websearch): finish managed third-party rollout
- steer third-party launches toward the managed WebSearch MCP tool - add opt-in trace diagnostics across launch, MCP, provider, and headless paths - extend docs and regression coverage for the first-class runtime Refs #862
This commit is contained in:
@@ -21,12 +21,14 @@ type SpawnCall = {
|
||||
options: Record<string, unknown> | undefined;
|
||||
};
|
||||
|
||||
const STEERING_PROMPT_SNIPPET = 'prefer the CCS MCP tool WebSearch instead of Bash/curl/http fetches';
|
||||
const spawnCalls: SpawnCall[] = [];
|
||||
const originalPlatform = process.platform;
|
||||
let baselineSigintListeners: Array<(...args: unknown[]) => void> = [];
|
||||
let baselineSigtermListeners: Array<(...args: unknown[]) => void> = [];
|
||||
let baselineSighupListeners: Array<(...args: unknown[]) => void> = [];
|
||||
let originalCcsHome: string | undefined;
|
||||
let originalCcsClaudePath: string | undefined;
|
||||
let originalDisableAutoUpdater: string | undefined;
|
||||
const realSpawn = childProcess.spawn.bind(childProcess);
|
||||
const realSpawnSync = childProcess.spawnSync.bind(childProcess);
|
||||
@@ -150,6 +152,7 @@ describe('CLAUDECODE environment stripping', () => {
|
||||
spawnCalls.length = 0;
|
||||
process.env.CCS_QUIET = '1';
|
||||
originalCcsHome = process.env.CCS_HOME;
|
||||
originalCcsClaudePath = process.env.CCS_CLAUDE_PATH;
|
||||
originalDisableAutoUpdater = process.env.DISABLE_AUTOUPDATER;
|
||||
delete process.env.DISABLE_AUTOUPDATER;
|
||||
baselineSigintListeners = process.listeners('SIGINT');
|
||||
@@ -162,8 +165,11 @@ describe('CLAUDECODE environment stripping', () => {
|
||||
delete process.env.CLAUDECODE;
|
||||
delete process.env.claudecode;
|
||||
delete process.env.CCS_QUIET;
|
||||
delete process.env.CCS_WEBSEARCH_TRACE;
|
||||
if (originalCcsHome !== undefined) process.env.CCS_HOME = originalCcsHome;
|
||||
else delete process.env.CCS_HOME;
|
||||
if (originalCcsClaudePath !== undefined) process.env.CCS_CLAUDE_PATH = originalCcsClaudePath;
|
||||
else delete process.env.CCS_CLAUDE_PATH;
|
||||
if (originalDisableAutoUpdater !== undefined) {
|
||||
process.env.DISABLE_AUTOUPDATER = originalDisableAutoUpdater;
|
||||
} else {
|
||||
@@ -325,4 +331,47 @@ describe('CLAUDECODE environment stripping', () => {
|
||||
expect(Object.keys(env).map((k) => k.toUpperCase())).not.toContain('CLAUDECODE');
|
||||
expect(env.DISABLE_AUTOUPDATER).toBe('1');
|
||||
});
|
||||
|
||||
it('headless executor adds third-party WebSearch steering args and env', async () => {
|
||||
writeConfigWithAutoUpdatePreference(false);
|
||||
const ccsDir = path.join(process.env.CCS_HOME as string, '.ccs');
|
||||
fs.writeFileSync(path.join(ccsDir, 'glm.settings.json'), '{}\n', 'utf8');
|
||||
process.env.CCS_CLAUDE_PATH = 'claude';
|
||||
|
||||
const result = await HeadlessExecutor.execute('glm', 'latest AI chip news', {
|
||||
permissionMode: 'default',
|
||||
timeout: 1000,
|
||||
});
|
||||
|
||||
expect(result.success).toBe(true);
|
||||
expect(spawnCalls.length).toBeGreaterThan(0);
|
||||
const launch = spawnCalls[0];
|
||||
expect(launch.args).toContain('--disallowedTools');
|
||||
expect(launch.args).toContain('WebSearch');
|
||||
expect(launch.args).toContain('--append-system-prompt');
|
||||
expect(launch.args.join(' ')).toContain(STEERING_PROMPT_SNIPPET);
|
||||
const env = launch.options?.env as NodeJS.ProcessEnv;
|
||||
expect(env.CCS_PROFILE_TYPE).toBe('settings');
|
||||
expect(env.CCS_WEBSEARCH_ENABLED || env.CCS_WEBSEARCH_SKIP).toBeDefined();
|
||||
});
|
||||
|
||||
it('headless executor propagates a WebSearch trace launch id when tracing is enabled', async () => {
|
||||
writeConfigWithAutoUpdatePreference(false);
|
||||
const ccsDir = path.join(process.env.CCS_HOME as string, '.ccs');
|
||||
fs.writeFileSync(path.join(ccsDir, 'glm.settings.json'), '{}\n', 'utf8');
|
||||
process.env.CCS_CLAUDE_PATH = 'claude';
|
||||
process.env.CCS_WEBSEARCH_TRACE = '1';
|
||||
|
||||
const result = await HeadlessExecutor.execute('glm', 'latest AI chip news', {
|
||||
permissionMode: 'default',
|
||||
timeout: 1000,
|
||||
});
|
||||
|
||||
expect(result.success).toBe(true);
|
||||
expect(spawnCalls.length).toBeGreaterThan(0);
|
||||
const env = spawnCalls[0].options?.env as NodeJS.ProcessEnv;
|
||||
expect(env.CCS_WEBSEARCH_TRACE).toBe('1');
|
||||
expect(env.CCS_WEBSEARCH_TRACE_LAUNCH_ID).toBeString();
|
||||
expect(env.CCS_WEBSEARCH_TRACE_LAUNCHER).toBe('delegation.headless-executor');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,25 +1,47 @@
|
||||
import { describe, expect, it } from 'bun:test';
|
||||
import { appendThirdPartyWebSearchToolArgs } from '../../../../src/utils/websearch/claude-tool-args';
|
||||
|
||||
const STEERING_PROMPT =
|
||||
'For web lookup or current-information requests, prefer the CCS MCP tool WebSearch instead of Bash/curl/http fetches. If the user explicitly wants shell commands, or WebSearch is unavailable or fails, you may fall back to Bash/network tools.';
|
||||
|
||||
describe('appendThirdPartyWebSearchToolArgs', () => {
|
||||
it('appends native WebSearch suppression when no tool flags are present', () => {
|
||||
it('appends native WebSearch suppression and steering prompt when no tool flags are present', () => {
|
||||
expect(appendThirdPartyWebSearchToolArgs(['smoke'])).toEqual([
|
||||
'smoke',
|
||||
'--disallowedTools',
|
||||
'WebSearch',
|
||||
'--append-system-prompt',
|
||||
STEERING_PROMPT,
|
||||
]);
|
||||
});
|
||||
|
||||
it('does not append duplicate suppression when WebSearch is already disallowed', () => {
|
||||
expect(appendThirdPartyWebSearchToolArgs(['smoke', '--disallowedTools', 'WebSearch'])).toEqual(
|
||||
['smoke', '--disallowedTools', 'WebSearch']
|
||||
);
|
||||
it('does not append duplicate suppression or steering prompt when both are already present', () => {
|
||||
expect(
|
||||
appendThirdPartyWebSearchToolArgs([
|
||||
'smoke',
|
||||
'--disallowedTools',
|
||||
'WebSearch',
|
||||
'--append-system-prompt',
|
||||
STEERING_PROMPT,
|
||||
])
|
||||
).toEqual([
|
||||
'smoke',
|
||||
'--disallowedTools',
|
||||
'WebSearch',
|
||||
'--append-system-prompt',
|
||||
STEERING_PROMPT,
|
||||
]);
|
||||
});
|
||||
|
||||
it('detects comma-separated disallowed tool values', () => {
|
||||
expect(appendThirdPartyWebSearchToolArgs(['smoke', '--disallowedTools=Read,WebSearch'])).toEqual(
|
||||
['smoke', '--disallowedTools=Read,WebSearch']
|
||||
);
|
||||
expect(
|
||||
appendThirdPartyWebSearchToolArgs(['smoke', '--disallowedTools=Read,WebSearch'])
|
||||
).toEqual([
|
||||
'smoke',
|
||||
'--disallowedTools=Read,WebSearch',
|
||||
'--append-system-prompt',
|
||||
STEERING_PROMPT,
|
||||
]);
|
||||
});
|
||||
|
||||
it('merges WebSearch into an existing space-separated disallowed tool flag', () => {
|
||||
@@ -27,6 +49,8 @@ describe('appendThirdPartyWebSearchToolArgs', () => {
|
||||
'smoke',
|
||||
'--disallowedTools',
|
||||
'Read,WebSearch',
|
||||
'--append-system-prompt',
|
||||
STEERING_PROMPT,
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -34,6 +58,75 @@ describe('appendThirdPartyWebSearchToolArgs', () => {
|
||||
expect(appendThirdPartyWebSearchToolArgs(['smoke', '--disallowedTools=Read'])).toEqual([
|
||||
'smoke',
|
||||
'--disallowedTools=Read,WebSearch',
|
||||
'--append-system-prompt',
|
||||
STEERING_PROMPT,
|
||||
]);
|
||||
});
|
||||
|
||||
it('preserves user-supplied append-system-prompt values and adds the CCS steering hint once', () => {
|
||||
expect(
|
||||
appendThirdPartyWebSearchToolArgs([
|
||||
'smoke',
|
||||
'--append-system-prompt',
|
||||
'User-provided instruction',
|
||||
])
|
||||
).toEqual([
|
||||
'smoke',
|
||||
'--append-system-prompt',
|
||||
'User-provided instruction',
|
||||
'--disallowedTools',
|
||||
'WebSearch',
|
||||
'--append-system-prompt',
|
||||
STEERING_PROMPT,
|
||||
]);
|
||||
});
|
||||
|
||||
it('does not duplicate the steering prompt when it already exists in equals form', () => {
|
||||
expect(
|
||||
appendThirdPartyWebSearchToolArgs([
|
||||
'smoke',
|
||||
'--disallowedTools',
|
||||
'WebSearch',
|
||||
`--append-system-prompt=${STEERING_PROMPT}`,
|
||||
])
|
||||
).toEqual([
|
||||
'smoke',
|
||||
'--disallowedTools',
|
||||
'WebSearch',
|
||||
`--append-system-prompt=${STEERING_PROMPT}`,
|
||||
]);
|
||||
});
|
||||
|
||||
it('does not consume positional args after a disallowed-tools flag value', () => {
|
||||
expect(
|
||||
appendThirdPartyWebSearchToolArgs(['--disallowedTools', 'Read', 'latest AI news'])
|
||||
).toEqual([
|
||||
'--disallowedTools',
|
||||
'Read,WebSearch',
|
||||
'latest AI news',
|
||||
'--append-system-prompt',
|
||||
STEERING_PROMPT,
|
||||
]);
|
||||
});
|
||||
|
||||
it('injects synthetic flags before an end-of-options marker', () => {
|
||||
expect(appendThirdPartyWebSearchToolArgs(['--', 'latest AI news'])).toEqual([
|
||||
'--disallowedTools',
|
||||
'WebSearch',
|
||||
'--append-system-prompt',
|
||||
STEERING_PROMPT,
|
||||
'--',
|
||||
'latest AI news',
|
||||
]);
|
||||
});
|
||||
|
||||
it('inserts the WebSearch disallow value when the flag is present without one', () => {
|
||||
expect(appendThirdPartyWebSearchToolArgs(['--disallowedTools', '--verbose'])).toEqual([
|
||||
'--disallowedTools',
|
||||
'WebSearch',
|
||||
'--verbose',
|
||||
'--append-system-prompt',
|
||||
STEERING_PROMPT,
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user