mirror of
https://github.com/tiennm99/ccs.git
synced 2026-07-31 00:23:38 +00:00
fix(cli): match managed prompt files by exact path
This commit is contained in:
@@ -7,8 +7,8 @@
|
||||
|
||||
import {
|
||||
buildSteeringArg,
|
||||
hasManagedPromptFileArg,
|
||||
PROMPT_FLAG_INLINE,
|
||||
PROMPT_FLAG_FILE,
|
||||
} from '../prompt-injection-strategy';
|
||||
|
||||
const IMAGE_ANALYSIS_STEERING_PROMPT = {
|
||||
@@ -41,9 +41,8 @@ function hasExactFlagValue(params: {
|
||||
args: string[];
|
||||
flag: string;
|
||||
expectedValue: string;
|
||||
allowPartiallyMatch?: boolean;
|
||||
}): boolean {
|
||||
const { args, flag, expectedValue, allowPartiallyMatch } = params;
|
||||
const { args, flag, expectedValue } = params;
|
||||
|
||||
for (let index = 0; index < args.length; index += 1) {
|
||||
const arg = args[index];
|
||||
@@ -55,10 +54,6 @@ function hasExactFlagValue(params: {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (allowPartiallyMatch && value?.includes(expectedValue)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -88,12 +83,7 @@ function ensureImageAnalysisSteeringPrompt(args: string[]): string[] {
|
||||
}
|
||||
|
||||
if (
|
||||
hasExactFlagValue({
|
||||
args: optionArgs,
|
||||
flag: PROMPT_FLAG_FILE,
|
||||
expectedValue: IMAGE_ANALYSIS_STEERING_PROMPT.name,
|
||||
allowPartiallyMatch: true,
|
||||
})
|
||||
hasManagedPromptFileArg({ args: optionArgs, promptName: IMAGE_ANALYSIS_STEERING_PROMPT.name })
|
||||
) {
|
||||
return args;
|
||||
}
|
||||
|
||||
@@ -22,6 +22,43 @@ export const PROMPT_FLAG_INLINE = '--append-system-prompt';
|
||||
/** `--append-system-prompt-file` — prompt read from file */
|
||||
export const PROMPT_FLAG_FILE = '--append-system-prompt-file';
|
||||
|
||||
function getManagedPromptsDir(): string {
|
||||
return path.join(getCcsDir(), 'prompts');
|
||||
}
|
||||
|
||||
export function getManagedPromptFileName(promptName: string): string {
|
||||
return `${promptName}.txt`;
|
||||
}
|
||||
|
||||
export function getManagedPromptFilePath(promptName: string): string {
|
||||
return path.join(getManagedPromptsDir(), getManagedPromptFileName(promptName));
|
||||
}
|
||||
|
||||
export function hasManagedPromptFileArg(params: { args: string[]; promptName: string }): boolean {
|
||||
const expectedPath = path.resolve(getManagedPromptFilePath(params.promptName));
|
||||
|
||||
for (let index = 0; index < params.args.length; index += 1) {
|
||||
const arg = params.args[index];
|
||||
|
||||
if (arg === PROMPT_FLAG_FILE) {
|
||||
const filePath = params.args[index + 1];
|
||||
if (filePath && path.resolve(filePath) === expectedPath) {
|
||||
return true;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (
|
||||
arg.startsWith(`${PROMPT_FLAG_FILE}=`) &&
|
||||
path.resolve(arg.slice(PROMPT_FLAG_FILE.length + 1)) === expectedPath
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect which prompt injection mode to use based on user-provided args.
|
||||
*
|
||||
@@ -56,9 +93,7 @@ export function buildFileSteeringArg(params: {
|
||||
promptFileName: string;
|
||||
promptContent: string;
|
||||
}): string[] {
|
||||
const ccsDir = getCcsDir();
|
||||
|
||||
const promptsFolder = path.join(ccsDir, '/prompts');
|
||||
const promptsFolder = getManagedPromptsDir();
|
||||
|
||||
if (!fs.existsSync(promptsFolder)) {
|
||||
fs.mkdirSync(promptsFolder, { recursive: true });
|
||||
@@ -83,7 +118,7 @@ export function buildSteeringArg(params: {
|
||||
|
||||
if (mode === 'file') {
|
||||
return buildFileSteeringArg({
|
||||
promptFileName: `${params.promptName}.txt`,
|
||||
promptFileName: getManagedPromptFileName(params.promptName),
|
||||
promptContent: params.promptContent,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
|
||||
import {
|
||||
buildSteeringArg,
|
||||
hasManagedPromptFileArg,
|
||||
PROMPT_FLAG_INLINE,
|
||||
PROMPT_FLAG_FILE,
|
||||
} from '../prompt-injection-strategy';
|
||||
|
||||
const NATIVE_WEBSEARCH_TOOL = 'WebSearch';
|
||||
@@ -83,9 +83,8 @@ function hasExactFlagValue(params: {
|
||||
args: string[];
|
||||
flag: string;
|
||||
expectedValue: string;
|
||||
allowPartiallyMatch?: boolean;
|
||||
}): boolean {
|
||||
const { args, flag, expectedValue, allowPartiallyMatch } = params;
|
||||
const { args, flag, expectedValue } = params;
|
||||
|
||||
for (let index = 0; index < args.length; index += 1) {
|
||||
const arg = args[index];
|
||||
@@ -97,10 +96,6 @@ function hasExactFlagValue(params: {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (allowPartiallyMatch && value?.includes(expectedValue)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -169,11 +164,9 @@ function ensureWebSearchSteeringPrompt(args: string[]): string[] {
|
||||
}
|
||||
|
||||
if (
|
||||
hasExactFlagValue({
|
||||
hasManagedPromptFileArg({
|
||||
args: optionArgs,
|
||||
flag: PROMPT_FLAG_FILE,
|
||||
expectedValue: THIRD_PARTY_WEBSEARCH_STEERING_PROMPT.name,
|
||||
allowPartiallyMatch: true,
|
||||
promptName: THIRD_PARTY_WEBSEARCH_STEERING_PROMPT.name,
|
||||
})
|
||||
) {
|
||||
return args;
|
||||
|
||||
@@ -11,7 +11,7 @@ import * as os from 'os';
|
||||
import * as path from 'path';
|
||||
import { getCcsDir } from '../config-manager';
|
||||
import { createLogger } from '../../services/logging';
|
||||
import { PROMPT_FLAG_INLINE, PROMPT_FLAG_FILE } from '../prompt-injection-strategy';
|
||||
import { hasManagedPromptFileArg, PROMPT_FLAG_INLINE } from '../prompt-injection-strategy';
|
||||
import { THIRD_PARTY_WEBSEARCH_STEERING_PROMPT } from './claude-tool-args';
|
||||
|
||||
const TRACE_FILE_NAME = 'websearch-trace.jsonl';
|
||||
@@ -61,9 +61,8 @@ function hasExactFlagValue(params: {
|
||||
args: string[];
|
||||
flag: string;
|
||||
expectedValue: string;
|
||||
allowIncludesValue?: boolean;
|
||||
}): boolean {
|
||||
const { args, flag, expectedValue, allowIncludesValue } = params;
|
||||
const { args, flag, expectedValue } = params;
|
||||
|
||||
for (let index = 0; index < args.length; index += 1) {
|
||||
const arg = args[index];
|
||||
@@ -75,10 +74,6 @@ function hasExactFlagValue(params: {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (allowIncludesValue && immediateFlagValue?.includes(expectedValue)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -203,14 +198,7 @@ function hasSteeringPromptInArgs(args: string[]): boolean {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (
|
||||
hasExactFlagValue({
|
||||
args,
|
||||
flag: PROMPT_FLAG_FILE,
|
||||
expectedValue: THIRD_PARTY_WEBSEARCH_STEERING_PROMPT.name,
|
||||
allowIncludesValue: true,
|
||||
})
|
||||
) {
|
||||
if (hasManagedPromptFileArg({ args, promptName: THIRD_PARTY_WEBSEARCH_STEERING_PROMPT.name })) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user