update
This commit is contained in:
1 parent
7e0f62afc9
commit
9928efed81
10 files changed
+84
-27
No files matched your search
@@ -16,6 +16,7 @@ import {
|
||||
ensureAbsoluteDirectory,
|
||||
ensureCommandResolvable,
|
||||
ensurePathInEnv,
|
||||
filterConflictingArgs,
|
||||
renderTemplate,
|
||||
runChildProcess,
|
||||
} from "@agentcompany/adapter-utils/server-utils";
|
||||
@@ -385,7 +386,22 @@ export async function execute(ctx: AdapterExecutionContext): Promise<AdapterExec
|
||||
args.push("--append-system-prompt-file", effectiveInstructionsFilePath);
|
||||
}
|
||||
args.push("--add-dir", skillsDir);
|
||||
if (extraArgs.length > 0) args.push(...extraArgs);
|
||||
if (extraArgs.length > 0) {
|
||||
// Filter out flags the adapter already manages to prevent duplicates
|
||||
// (e.g. user shell aliases that inject --dangerously-skip-permissions)
|
||||
const managedFlags = [
|
||||
"--dangerously-skip-permissions",
|
||||
"--output-format",
|
||||
"--model",
|
||||
"--effort",
|
||||
"--max-turns",
|
||||
"--add-dir",
|
||||
"--append-system-prompt-file",
|
||||
"--teammate-mode",
|
||||
];
|
||||
const cleaned = filterConflictingArgs(extraArgs, managedFlags);
|
||||
if (cleaned.length > 0) args.push(...cleaned);
|
||||
}
|
||||
return args;
|
||||
};
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ import {
|
||||
ensureAbsoluteDirectory,
|
||||
ensureCommandResolvable,
|
||||
ensurePathInEnv,
|
||||
filterConflictingArgs,
|
||||
renderTemplate,
|
||||
runChildProcess,
|
||||
} from "@agentcompany/adapter-utils/server-utils";
|
||||
@@ -318,7 +319,20 @@ export async function execute(ctx: AdapterExecutionContext): Promise<AdapterExec
|
||||
if (bypass) args.push("--dangerously-bypass-approvals-and-sandbox");
|
||||
if (model) args.push("--model", model);
|
||||
if (modelReasoningEffort) args.push("-c", `model_reasoning_effort=${JSON.stringify(modelReasoningEffort)}`);
|
||||
if (extraArgs.length > 0) args.push(...extraArgs);
|
||||
if (extraArgs.length > 0) {
|
||||
// Filter out flags the adapter already manages to prevent duplicates
|
||||
// (e.g. user shell aliases that inject --dangerously-bypass-approvals-and-sandbox)
|
||||
const managedFlags = [
|
||||
"--dangerously-bypass-approvals-and-sandbox",
|
||||
"--json",
|
||||
"--model",
|
||||
"--sandbox",
|
||||
"--skip-git-repo-check",
|
||||
"--ask-for-approval",
|
||||
];
|
||||
const cleaned = filterConflictingArgs(extraArgs, managedFlags);
|
||||
if (cleaned.length > 0) args.push(...cleaned);
|
||||
}
|
||||
if (resumeSessionId) args.push("resume", resumeSessionId, "-");
|
||||
else args.push("-");
|
||||
return args;
|
||||
|
||||
@@ -14,6 +14,7 @@ import {
|
||||
ensureCommandResolvable,
|
||||
ensurePathInEnv,
|
||||
parseObject,
|
||||
filterConflictingArgs,
|
||||
redactEnvForLogs,
|
||||
renderTemplate,
|
||||
runChildProcess,
|
||||
@@ -301,7 +302,18 @@ export async function execute(ctx: AdapterExecutionContext): Promise<AdapterExec
|
||||
} else {
|
||||
args.push("--sandbox=none");
|
||||
}
|
||||
if (extraArgs.length > 0) args.push(...extraArgs);
|
||||
if (extraArgs.length > 0) {
|
||||
// Filter out flags the adapter already manages to prevent duplicates
|
||||
// (e.g. user shell aliases that inject --approval-mode or --sandbox)
|
||||
const managedFlags = [
|
||||
"--approval-mode",
|
||||
"--output-format",
|
||||
"--model",
|
||||
"--sandbox",
|
||||
];
|
||||
const cleaned = filterConflictingArgs(extraArgs, managedFlags);
|
||||
if (cleaned.length > 0) args.push(...cleaned);
|
||||
}
|
||||
args.push(prompt);
|
||||
return args;
|
||||
};
|
||||
|
||||
@@ -109,6 +109,30 @@ export function renderTemplate(template: string, data: Record<string, unknown>)
|
||||
return template.replace(/{{\s*([a-zA-Z0-9_.-]+)\s*}}/g, (_, path) => resolvePathValue(data, path));
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove flags from `extraArgs` that the adapter will already add itself.
|
||||
* Handles both `--flag value` pairs and `--flag=value` forms.
|
||||
* This prevents duplicate/conflicting CLI arguments when users have shell
|
||||
* aliases or wrapper functions that inject the same flags.
|
||||
*/
|
||||
export function filterConflictingArgs(extraArgs: string[], adapterFlags: string[]): string[] {
|
||||
const flagSet = new Set(adapterFlags.map((f) => f.replace(/=.*$/, "")));
|
||||
const filtered: string[] = [];
|
||||
for (let i = 0; i < extraArgs.length; i++) {
|
||||
const arg = extraArgs[i];
|
||||
const bareFlag = arg.replace(/=.*$/, "");
|
||||
if (flagSet.has(bareFlag)) {
|
||||
// Skip this flag and its value if the value is a separate argument
|
||||
if (!arg.includes("=") && i + 1 < extraArgs.length && !extraArgs[i + 1].startsWith("-")) {
|
||||
i++; // skip the value argument too
|
||||
}
|
||||
continue;
|
||||
}
|
||||
filtered.push(arg);
|
||||
}
|
||||
return filtered;
|
||||
}
|
||||
|
||||
export function redactEnvForLogs(env: Record<string, string>): Record<string, string> {
|
||||
const redacted: Record<string, string> = {};
|
||||
for (const [key, value] of Object.entries(env)) {
|
||||
|
||||
Reference in new issue
Block a user