mirror of
https://github.com/cline/cline.git
synced 2026-09-09 23:29:54 +08:00
Compare commits
14
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3ef39b05ca | ||
|
|
f059656ca5 | ||
|
|
acf7fde625 | ||
|
|
c725f3da42 | ||
|
|
874b495abf | ||
|
|
ccc8e5759d | ||
|
|
8b9590e1ea | ||
|
|
9b4aa6307b | ||
|
|
adb7f014cf | ||
|
|
ebefaa68c4 | ||
|
|
0e240ed329 | ||
|
|
2a4e33105c | ||
|
|
7e8a0df023 | ||
|
|
df7124d561 |
@@ -51,6 +51,10 @@ export function addRootOptions(cmd: Command): Command {
|
||||
"-s, --system <system-prompt>",
|
||||
"Override the default system prompt",
|
||||
)
|
||||
.option(
|
||||
"--agent <name>",
|
||||
"Use an agent profile from .cline/agents for this session",
|
||||
)
|
||||
.option("-z, --zen", "Start a session that runs in the background hub")
|
||||
.option(
|
||||
"--retries [value]",
|
||||
@@ -225,6 +229,7 @@ export function commanderToParsedArgs(program: Command): ParsedArgs {
|
||||
if (opts.cwd !== undefined) result.cwd = opts.cwd;
|
||||
if (opts.teamName !== undefined) result.teamName = opts.teamName;
|
||||
if (opts.system !== undefined) result.systemPrompt = opts.system;
|
||||
if (opts.agent !== undefined) result.agent = opts.agent;
|
||||
if (opts.model !== undefined) result.model = opts.model;
|
||||
if (opts.provider !== undefined) result.provider = opts.provider;
|
||||
if (opts.key !== undefined) result.key = opts.key;
|
||||
|
||||
@@ -2,6 +2,23 @@ import { fstatSync } from "node:fs";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import type { CliMigrationNotice } from "./kanban-migration/notice";
|
||||
|
||||
interface MockConfiguredAgentConfig {
|
||||
name: string;
|
||||
description: string;
|
||||
systemPrompt: string;
|
||||
path?: string;
|
||||
}
|
||||
|
||||
interface MockConfiguredAgentReadError {
|
||||
path: string;
|
||||
error: Error;
|
||||
}
|
||||
|
||||
interface MockConfiguredAgentLoadResult {
|
||||
configs: MockConfiguredAgentConfig[];
|
||||
errors: MockConfiguredAgentReadError[];
|
||||
}
|
||||
|
||||
/** Real `fstatSync`: used when tests stub only stdin (fd 0); throwing for every fd breaks imports and session I/O. */
|
||||
const fsActual = vi.hoisted(() => ({
|
||||
realFstatSync: null as null | typeof import("node:fs").fstatSync,
|
||||
@@ -47,6 +64,14 @@ const sessionMocks = vi.hoisted(() => ({
|
||||
const llmMocks = vi.hoisted(() => ({
|
||||
resolveProviderConfig: vi.fn(async (): Promise<unknown> => undefined),
|
||||
}));
|
||||
const agentConfigMocks = vi.hoisted(() => ({
|
||||
loadConfiguredAgentConfigs: vi.fn<
|
||||
(input: { workspaceRoot?: string }) => MockConfiguredAgentLoadResult
|
||||
>(() => ({
|
||||
configs: [],
|
||||
errors: [],
|
||||
})),
|
||||
}));
|
||||
const promptMocks = vi.hoisted(() => ({
|
||||
resolveSystemPrompt: vi.fn(async () => "system prompt"),
|
||||
}));
|
||||
@@ -142,6 +167,7 @@ vi.mock("./session/session", () => sessionMocks);
|
||||
vi.mock("@cline/core", () => {
|
||||
return {
|
||||
resolveProviderConfig: llmMocks.resolveProviderConfig,
|
||||
loadConfiguredAgentConfigs: agentConfigMocks.loadConfiguredAgentConfigs,
|
||||
createTeamName: vi.fn(() => "team-test"),
|
||||
createUserInstructionConfigService: vi.fn(() => ({
|
||||
start: vi.fn(async () => {}),
|
||||
@@ -215,6 +241,11 @@ describe("runCli lightweight command dispatch", () => {
|
||||
});
|
||||
llmMocks.resolveProviderConfig.mockReset();
|
||||
llmMocks.resolveProviderConfig.mockResolvedValue(undefined);
|
||||
agentConfigMocks.loadConfiguredAgentConfigs.mockReset();
|
||||
agentConfigMocks.loadConfiguredAgentConfigs.mockReturnValue({
|
||||
configs: [],
|
||||
errors: [],
|
||||
});
|
||||
authMocks.ensureOAuthProviderApiKey.mockReset();
|
||||
authMocks.getPersistedProviderApiKey.mockReset();
|
||||
authMocks.getPersistedProviderApiKey.mockReturnValue(undefined);
|
||||
@@ -872,6 +903,133 @@ describe("runCli lightweight command dispatch", () => {
|
||||
expect(hubRuntimeMocks.ensureCliHubServer).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("applies an agent profile to prompt runs", async () => {
|
||||
agentConfigMocks.loadConfiguredAgentConfigs.mockReturnValue({
|
||||
configs: [
|
||||
{
|
||||
name: "Reviewer",
|
||||
description: "Reviews code",
|
||||
systemPrompt: "You are a reviewer.",
|
||||
path: "/repo/.cline/agents/reviewer.yaml",
|
||||
},
|
||||
],
|
||||
errors: [],
|
||||
});
|
||||
forcePromptModeInput();
|
||||
process.argv = ["bun", "src/index.ts", "--agent", "reviewer", "hello"];
|
||||
|
||||
const { runCli } = await import("./main");
|
||||
|
||||
await expect(runCli()).resolves.toBeUndefined();
|
||||
expect(agentConfigMocks.loadConfiguredAgentConfigs).toHaveBeenCalledWith({
|
||||
workspaceRoot: "/workspace/cline",
|
||||
});
|
||||
expect(promptMocks.resolveSystemPrompt).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
agentPersona: "You are a reviewer.",
|
||||
}),
|
||||
);
|
||||
expect(runtimeMocks.runAgent).toHaveBeenCalledWith(
|
||||
"hello",
|
||||
expect.objectContaining({
|
||||
agentProfile: {
|
||||
name: "Reviewer",
|
||||
systemPrompt: "You are a reviewer.",
|
||||
},
|
||||
systemPrompt: "system prompt",
|
||||
}),
|
||||
expect.anything(),
|
||||
);
|
||||
});
|
||||
|
||||
it("lets --system override --agent without storing the profile", async () => {
|
||||
agentConfigMocks.loadConfiguredAgentConfigs.mockReturnValue({
|
||||
configs: [
|
||||
{
|
||||
name: "Reviewer",
|
||||
description: "Reviews code",
|
||||
systemPrompt: "You are a reviewer.",
|
||||
path: "/repo/.cline/agents/reviewer.yaml",
|
||||
},
|
||||
],
|
||||
errors: [],
|
||||
});
|
||||
forcePromptModeInput();
|
||||
process.argv = [
|
||||
"bun",
|
||||
"src/index.ts",
|
||||
"--agent",
|
||||
"reviewer",
|
||||
"--system",
|
||||
"Custom system.",
|
||||
"hello",
|
||||
];
|
||||
|
||||
const { runCli } = await import("./main");
|
||||
|
||||
await expect(runCli()).resolves.toBeUndefined();
|
||||
expect(agentConfigMocks.loadConfiguredAgentConfigs).not.toHaveBeenCalled();
|
||||
expect(promptMocks.resolveSystemPrompt).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
explicitSystemPrompt: "Custom system.",
|
||||
}),
|
||||
);
|
||||
expect(runtimeMocks.runAgent).toHaveBeenCalledWith(
|
||||
"hello",
|
||||
expect.objectContaining({
|
||||
agentProfile: undefined,
|
||||
}),
|
||||
expect.anything(),
|
||||
);
|
||||
});
|
||||
|
||||
it("rejects missing agent profiles before starting the runtime", async () => {
|
||||
agentConfigMocks.loadConfiguredAgentConfigs.mockReturnValue({
|
||||
configs: [
|
||||
{
|
||||
name: "Planner",
|
||||
description: "Plans work",
|
||||
systemPrompt: "You are a planner.",
|
||||
path: "/repo/.cline/agents/planner.yaml",
|
||||
},
|
||||
],
|
||||
errors: [
|
||||
{
|
||||
path: "/repo/.cline/agents/broken.yaml",
|
||||
error: new Error("Missing system prompt body"),
|
||||
},
|
||||
],
|
||||
});
|
||||
forcePromptModeInput();
|
||||
process.argv = ["bun", "src/index.ts", "--agent", "reviewer", "hello"];
|
||||
|
||||
const { runCli } = await import("./main");
|
||||
|
||||
await expect(runCli()).resolves.toBeUndefined();
|
||||
expect(process.exitCode).toBe(1);
|
||||
expect(runtimeMocks.runAgent).not.toHaveBeenCalled();
|
||||
expect(runtimeMocks.runInteractive).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("rejects --agent in yolo mode before loading profiles", async () => {
|
||||
forcePromptModeInput();
|
||||
process.argv = [
|
||||
"bun",
|
||||
"src/index.ts",
|
||||
"--yolo",
|
||||
"--agent",
|
||||
"reviewer",
|
||||
"hello",
|
||||
];
|
||||
|
||||
const { runCli } = await import("./main");
|
||||
|
||||
await expect(runCli()).resolves.toBeUndefined();
|
||||
expect(process.exitCode).toBe(1);
|
||||
expect(agentConfigMocks.loadConfiguredAgentConfigs).not.toHaveBeenCalled();
|
||||
expect(runtimeMocks.runAgent).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("rewrites /team prompts and enables teams in single-prompt mode", async () => {
|
||||
runtimeMocks.runAgent.mockClear();
|
||||
|
||||
|
||||
+46
-1
@@ -42,7 +42,7 @@ import {
|
||||
captureCliExtensionActivated,
|
||||
getCliTelemetryService,
|
||||
} from "./utils/telemetry";
|
||||
import type { Config } from "./utils/types";
|
||||
import type { ActiveAgentProfile, Config } from "./utils/types";
|
||||
import { runConnectWizard } from "./wizards/connect";
|
||||
import { runMcpWizard } from "./wizards/mcp";
|
||||
import { runScheduleWizard } from "./wizards/schedule";
|
||||
@@ -928,6 +928,49 @@ export async function runCli(): Promise<void> {
|
||||
cwd,
|
||||
});
|
||||
|
||||
let activeAgentProfile: ActiveAgentProfile | undefined;
|
||||
const requestedAgentName = args.agent?.trim();
|
||||
if (requestedAgentName) {
|
||||
if (isYoloMode) {
|
||||
writeErr("--agent is not supported in yolo mode");
|
||||
process.exitCode = 1;
|
||||
return;
|
||||
}
|
||||
if (args.systemPrompt) {
|
||||
// Don't store an unused profile: it would resurface on plan/act toggles.
|
||||
writeln(
|
||||
`${c.dim}[warn] --system overrides --agent; ignoring agent profile "${requestedAgentName}"${c.reset}`,
|
||||
);
|
||||
} else {
|
||||
const { loadConfiguredAgentConfigs } = await import("@cline/core");
|
||||
const { configs, errors } = loadConfiguredAgentConfigs({
|
||||
workspaceRoot,
|
||||
});
|
||||
const profile = configs.find(
|
||||
(candidate) =>
|
||||
candidate.name.trim().toLowerCase() ===
|
||||
requestedAgentName.toLowerCase(),
|
||||
);
|
||||
if (!profile) {
|
||||
const availableNames = configs.map((candidate) => candidate.name);
|
||||
writeErr(
|
||||
availableNames.length > 0
|
||||
? `agent profile "${requestedAgentName}" not found (available: ${availableNames.join(", ")})`
|
||||
: `agent profile "${requestedAgentName}" not found (no agent profiles in .cline/agents)`,
|
||||
);
|
||||
for (const error of errors) {
|
||||
writeErr(`failed to load ${error.path}: ${error.error.message}`);
|
||||
}
|
||||
process.exitCode = 1;
|
||||
return;
|
||||
}
|
||||
activeAgentProfile = {
|
||||
name: profile.name,
|
||||
systemPrompt: profile.systemPrompt,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
const config: Config = {
|
||||
providerId: provider,
|
||||
modelId:
|
||||
@@ -942,6 +985,7 @@ export async function runCli(): Promise<void> {
|
||||
explicitSystemPrompt: args.systemPrompt,
|
||||
providerId: provider,
|
||||
mode: args.mode ?? "act",
|
||||
agentPersona: activeAgentProfile?.systemPrompt,
|
||||
}),
|
||||
execution: {
|
||||
maxConsecutiveMistakes: args.retries ?? 3,
|
||||
@@ -964,6 +1008,7 @@ export async function runCli(): Promise<void> {
|
||||
telemetry: getCliTelemetryService(loggerAdapter.core),
|
||||
defaultToolAutoApprove,
|
||||
toolPolicies,
|
||||
agentProfile: activeAgentProfile,
|
||||
enableSpawnAgent: !isYoloMode,
|
||||
enableAgentTeams: !isYoloMode,
|
||||
enableTools: true,
|
||||
|
||||
@@ -78,4 +78,36 @@ describe("applyInteractiveModeConfig", () => {
|
||||
expect(config.extraTools).toEqual([]);
|
||||
expect(config.systemPrompt).toBe("system prompt for act");
|
||||
});
|
||||
|
||||
it("threads the active agent profile persona across mode switches", async () => {
|
||||
const config = makeConfig();
|
||||
config.agentProfile = {
|
||||
name: "reviewer",
|
||||
systemPrompt: "You are a reviewer.",
|
||||
};
|
||||
|
||||
await applyInteractiveModeConfig({
|
||||
config,
|
||||
mode: "plan",
|
||||
switchToActModeTool,
|
||||
});
|
||||
expect(resolveSystemPrompt).toHaveBeenLastCalledWith({
|
||||
cwd: config.cwd,
|
||||
providerId: config.providerId,
|
||||
mode: "plan",
|
||||
agentPersona: "You are a reviewer.",
|
||||
});
|
||||
|
||||
await applyInteractiveModeConfig({
|
||||
config,
|
||||
mode: "act",
|
||||
switchToActModeTool,
|
||||
});
|
||||
expect(resolveSystemPrompt).toHaveBeenLastCalledWith({
|
||||
cwd: config.cwd,
|
||||
providerId: config.providerId,
|
||||
mode: "act",
|
||||
agentPersona: "You are a reviewer.",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -43,5 +43,6 @@ export async function applyInteractiveModeConfig(input: {
|
||||
cwd: input.config.cwd,
|
||||
providerId: input.config.providerId,
|
||||
mode: input.mode,
|
||||
agentPersona: input.config.agentProfile?.systemPrompt,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ import type {
|
||||
import { createRuntimeHooks } from "../../utils/hooks";
|
||||
import { setActiveCliSession } from "../../utils/output";
|
||||
import { loadInteractiveResumeMessages } from "../../utils/resume";
|
||||
import type { Config } from "../../utils/types";
|
||||
import type { ActiveAgentProfile, Config } from "../../utils/types";
|
||||
import { markAbortInProgress } from "../active-runtime";
|
||||
import type {
|
||||
PendingPromptSnapshot,
|
||||
@@ -359,6 +359,19 @@ export function createInteractiveSessionRuntime(input: {
|
||||
await restartWithCurrentMessages();
|
||||
};
|
||||
|
||||
const applyAgentProfile = async (
|
||||
profile: ActiveAgentProfile | undefined,
|
||||
): Promise<void> => {
|
||||
input.config.agentProfile = profile;
|
||||
// Re-apply the current mode so the system prompt picks up the persona.
|
||||
await applyInteractiveModeConfig({
|
||||
config: input.config,
|
||||
mode: input.config.mode === "plan" ? "plan" : "act",
|
||||
switchToActModeTool: input.switchToActModeTool,
|
||||
});
|
||||
await restartWithCurrentMessages();
|
||||
};
|
||||
|
||||
const sendCurrentTurn = async (
|
||||
turnInput: CurrentTurnInput,
|
||||
): Promise<CurrentTurnResult> => {
|
||||
@@ -639,6 +652,7 @@ export function createInteractiveSessionRuntime(input: {
|
||||
getCheckpointData,
|
||||
restoreCheckpoint,
|
||||
applyMode,
|
||||
applyAgentProfile,
|
||||
resetAbortRequest,
|
||||
abortAll,
|
||||
cleanup,
|
||||
|
||||
@@ -28,6 +28,8 @@ export async function resolveSystemPrompt(input: {
|
||||
providerId?: string;
|
||||
rules?: string;
|
||||
mode?: AgentMode;
|
||||
/** Agent profile body that replaces the persona slot of the base prompt */
|
||||
agentPersona?: string;
|
||||
}): Promise<string> {
|
||||
const metadata = await buildWorkspaceMetadata(input.cwd);
|
||||
let rules = mergeRulesForSystemPrompt(undefined, input.rules);
|
||||
@@ -45,6 +47,7 @@ export async function resolveSystemPrompt(input: {
|
||||
mode: input.mode,
|
||||
providerId: input.providerId,
|
||||
overridePrompt: input.explicitSystemPrompt,
|
||||
personaPrompt: input.agentPersona,
|
||||
platform:
|
||||
(typeof process !== "undefined" && process?.platform) || "unknown",
|
||||
});
|
||||
|
||||
@@ -598,6 +598,10 @@ export async function runInteractive(
|
||||
}
|
||||
await applyModeChange(mode);
|
||||
},
|
||||
onAgentProfileChange: async (profile) => {
|
||||
await sessionRuntime.ensureReady();
|
||||
await sessionRuntime.applyAgentProfile(profile ?? undefined);
|
||||
},
|
||||
onNewSession: async () => {
|
||||
await sessionRuntime.resetForNewSession();
|
||||
},
|
||||
|
||||
@@ -271,6 +271,35 @@ describe("slash command registry", () => {
|
||||
).toContain("settings");
|
||||
});
|
||||
|
||||
it("exposes agents as a local command with a hidden agent alias", () => {
|
||||
const registry = buildSlashCommandRegistry({});
|
||||
const commandNames = getVisibleSystemSlashCommands(registry).map(
|
||||
(command) => command.name,
|
||||
);
|
||||
|
||||
expect(resolveSlashCommand(registry, "agents")).toMatchObject({
|
||||
source: "tui",
|
||||
execution: "local",
|
||||
description: "Switch agent profile",
|
||||
visible: true,
|
||||
selectable: true,
|
||||
});
|
||||
expect(resolveSlashCommand(registry, "agent")).toMatchObject({
|
||||
source: "tui",
|
||||
execution: "local",
|
||||
visible: false,
|
||||
selectable: false,
|
||||
});
|
||||
expect(commandNames).toContain("agents");
|
||||
expect(commandNames).not.toContain("agent");
|
||||
expect(commandNames.indexOf("agents")).toBeGreaterThan(
|
||||
commandNames.indexOf("model"),
|
||||
);
|
||||
expect(commandNames.indexOf("agents")).toBeLessThan(
|
||||
commandNames.indexOf("account"),
|
||||
);
|
||||
});
|
||||
|
||||
it("always exposes the account command", () => {
|
||||
const registry = buildSlashCommandRegistry({});
|
||||
|
||||
|
||||
@@ -17,6 +17,8 @@ export type LocalSlashCommandName =
|
||||
| "plugins"
|
||||
| "account"
|
||||
| "model"
|
||||
| "agents"
|
||||
| "agent"
|
||||
| "compact"
|
||||
| "skills"
|
||||
| "fork"
|
||||
@@ -62,6 +64,15 @@ const TUI_LOCAL_COMMANDS: Array<{
|
||||
name: "model",
|
||||
description: "Switch model or provider",
|
||||
},
|
||||
{
|
||||
name: "agents",
|
||||
description: "Switch agent profile",
|
||||
},
|
||||
{
|
||||
name: "agent",
|
||||
description: "Switch agent profile",
|
||||
visible: false,
|
||||
},
|
||||
{
|
||||
name: "account",
|
||||
description: "View Cline account",
|
||||
@@ -112,6 +123,7 @@ const TUI_LOCAL_COMMANDS: Array<{
|
||||
const SYSTEM_COMMAND_ORDER = [
|
||||
"settings",
|
||||
"model",
|
||||
"agents",
|
||||
"account",
|
||||
"mcp",
|
||||
"plugins",
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
import { basename } from "node:path";
|
||||
import type { ChoiceContext } from "@opentui-ui/dialog";
|
||||
import { useDialogKeyboard } from "@opentui-ui/dialog/react";
|
||||
import { useMemo } from "react";
|
||||
import {
|
||||
type SearchableItem,
|
||||
SearchableList,
|
||||
useSearchableList,
|
||||
} from "../searchable-list";
|
||||
|
||||
/** Sentinel resolved when the user picks the default Cline agent. */
|
||||
export const DEFAULT_AGENT_ACTION = "__default_agent__";
|
||||
|
||||
export interface AgentProfileOption {
|
||||
name: string;
|
||||
description?: string;
|
||||
systemPrompt: string;
|
||||
source: "workspace" | "global";
|
||||
}
|
||||
|
||||
export interface AgentProfileLoadError {
|
||||
path: string;
|
||||
message: string;
|
||||
}
|
||||
|
||||
export function AgentSelectorContent(
|
||||
props: ChoiceContext<string> & {
|
||||
currentAgentName: string | null;
|
||||
agents: AgentProfileOption[];
|
||||
loadErrors: AgentProfileLoadError[];
|
||||
},
|
||||
) {
|
||||
const { resolve, dismiss, dialogId, currentAgentName, agents, loadErrors } =
|
||||
props;
|
||||
|
||||
const items: SearchableItem[] = useMemo(() => {
|
||||
const normalizedCurrent = currentAgentName?.trim().toLowerCase() ?? null;
|
||||
const defaultItem: SearchableItem = {
|
||||
key: DEFAULT_AGENT_ACTION,
|
||||
label: "Cline (default)",
|
||||
detail: "Standard Cline agent",
|
||||
section: "Agents",
|
||||
rightLabel: normalizedCurrent === null ? "(current)" : undefined,
|
||||
};
|
||||
const profileItems = agents.map((agent) => ({
|
||||
key: agent.name.toLowerCase(),
|
||||
label: agent.name,
|
||||
detail: agent.description,
|
||||
section:
|
||||
agent.source === "workspace" ? "Workspace agents" : "Global agents",
|
||||
rightLabel:
|
||||
normalizedCurrent === agent.name.trim().toLowerCase()
|
||||
? "(current)"
|
||||
: undefined,
|
||||
}));
|
||||
return [defaultItem, ...profileItems];
|
||||
}, [agents, currentAgentName]);
|
||||
|
||||
const list = useSearchableList(items);
|
||||
|
||||
useDialogKeyboard((key) => {
|
||||
if (key.name === "escape") {
|
||||
dismiss();
|
||||
return;
|
||||
}
|
||||
if (key.name === "return") {
|
||||
const item = list.selectedItem;
|
||||
if (item) resolve(item.key);
|
||||
return;
|
||||
}
|
||||
if (key.name === "up") {
|
||||
list.moveUp();
|
||||
return;
|
||||
}
|
||||
if (key.name === "down") {
|
||||
list.moveDown();
|
||||
}
|
||||
}, dialogId);
|
||||
|
||||
return (
|
||||
<box flexDirection="column" gap={1}>
|
||||
<text>Select Agent</text>
|
||||
|
||||
<SearchableList
|
||||
items={list.filtered}
|
||||
selected={list.safeSelected}
|
||||
placeholder="Search agents..."
|
||||
onSearchChange={list.setSearch}
|
||||
onItemSelect={(item) => resolve(item.key)}
|
||||
emptyText="No agents match"
|
||||
/>
|
||||
|
||||
{loadErrors.length > 0 && (
|
||||
<box flexDirection="column">
|
||||
{loadErrors.map((error) => (
|
||||
<text key={error.path} fg="red">
|
||||
{basename(error.path)}: {error.message}
|
||||
</text>
|
||||
))}
|
||||
</box>
|
||||
)}
|
||||
|
||||
<text fg="gray">
|
||||
Type to search, ↑/↓ navigate, Enter to select, Esc to go back
|
||||
</text>
|
||||
</box>
|
||||
);
|
||||
}
|
||||
@@ -2,6 +2,7 @@ export type CommandPaletteAction =
|
||||
| "settings"
|
||||
| "change-model"
|
||||
| "change-provider"
|
||||
| "agents"
|
||||
| "account"
|
||||
| "mcp"
|
||||
| "plugins"
|
||||
@@ -57,6 +58,13 @@ const ACTION_ITEMS: Array<{
|
||||
description: "Switch provider and configure credentials",
|
||||
keywords: ["provider", "api key", "account", "auth"],
|
||||
},
|
||||
{
|
||||
action: "agents",
|
||||
label: "Switch Agent",
|
||||
shortcut: "Opt+T",
|
||||
description: "Use an agent profile from .cline/agents",
|
||||
keywords: ["agent", "agents", "profile", "persona", "subagent"],
|
||||
},
|
||||
{
|
||||
action: "mcp",
|
||||
label: "Manage MCP Servers",
|
||||
|
||||
@@ -120,6 +120,12 @@ const HELP_ROWS: HelpRow[] = [
|
||||
key: "/model",
|
||||
desc: "Switch model or provider",
|
||||
},
|
||||
{
|
||||
kind: "entry",
|
||||
id: "c-agents",
|
||||
key: "/agents",
|
||||
desc: "Switch agent profile",
|
||||
},
|
||||
{
|
||||
kind: "entry",
|
||||
id: "c-settings",
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import {
|
||||
createContextBar,
|
||||
formatStatusBarAgentLabel,
|
||||
formatStatusBarAgentName,
|
||||
formatStatusBarUsageText,
|
||||
resolveContextBarFilledForeground,
|
||||
} from "./status-bar";
|
||||
@@ -49,6 +51,48 @@ describe("createContextBar", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("formatStatusBarAgentName", () => {
|
||||
it("keeps short names intact", () => {
|
||||
expect(formatStatusBarAgentName("reviewer")).toBe("reviewer");
|
||||
expect(formatStatusBarAgentName(" reviewer ")).toBe("reviewer");
|
||||
});
|
||||
|
||||
it("truncates long names with an ellipsis", () => {
|
||||
expect(formatStatusBarAgentName("documentation-specialist")).toBe(
|
||||
"documentation...",
|
||||
);
|
||||
expect(formatStatusBarAgentName("documentation-specialist").length).toBe(
|
||||
16,
|
||||
);
|
||||
});
|
||||
|
||||
it("handles very narrow limits without negative slicing", () => {
|
||||
expect(formatStatusBarAgentName("reviewer", 3)).toBe("...");
|
||||
expect(formatStatusBarAgentName("reviewer", 0)).toBe("");
|
||||
});
|
||||
});
|
||||
|
||||
describe("formatStatusBarAgentLabel", () => {
|
||||
it("returns the trimmed active agent name", () => {
|
||||
expect(formatStatusBarAgentLabel("reviewer")).toBe("reviewer");
|
||||
expect(formatStatusBarAgentLabel(" reviewer ")).toBe("reviewer");
|
||||
});
|
||||
|
||||
it("truncates to fit the label width", () => {
|
||||
expect(formatStatusBarAgentLabel("documentation-specialist", 18)).toBe(
|
||||
"documentation-s...",
|
||||
);
|
||||
expect(
|
||||
formatStatusBarAgentLabel("documentation-specialist", 18)?.length,
|
||||
).toBe(18);
|
||||
});
|
||||
|
||||
it("hides blank or too-narrow labels", () => {
|
||||
expect(formatStatusBarAgentLabel(" ")).toBeUndefined();
|
||||
expect(formatStatusBarAgentLabel("reviewer", 0)).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe("formatStatusBarUsageText", () => {
|
||||
it("includes cost when usage cost is visible", () => {
|
||||
expect(
|
||||
|
||||
@@ -104,6 +104,23 @@ export function resolveModelMaxInputTokens(config: {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export function formatStatusBarAgentName(name: string, maxLen = 16): string {
|
||||
const normalized = name.trim();
|
||||
if (maxLen <= 0) return "";
|
||||
if (normalized.length <= maxLen) return normalized;
|
||||
if (maxLen <= 3) return ".".repeat(maxLen);
|
||||
return `${normalized.slice(0, maxLen - 3)}...`;
|
||||
}
|
||||
|
||||
export function formatStatusBarAgentLabel(
|
||||
name: string,
|
||||
maxLen = 18,
|
||||
): string | undefined {
|
||||
const normalized = name.trim();
|
||||
if (!normalized || maxLen <= 0) return undefined;
|
||||
return formatStatusBarAgentName(normalized, maxLen);
|
||||
}
|
||||
|
||||
export interface StatusBarProps {
|
||||
providerId: string;
|
||||
modelId: string;
|
||||
@@ -120,6 +137,9 @@ export interface StatusBarProps {
|
||||
deletions: number;
|
||||
} | null;
|
||||
onToggleMode?: () => void;
|
||||
/** Active agent profile name; the indicator is hidden when unset */
|
||||
agentName?: string | null;
|
||||
onOpenAgent?: () => void;
|
||||
variant?: "home" | "chat";
|
||||
}
|
||||
|
||||
@@ -135,6 +155,8 @@ export function StatusBar(props: StatusBarProps) {
|
||||
gitBranch,
|
||||
gitDiffStats,
|
||||
onToggleMode,
|
||||
agentName,
|
||||
onOpenAgent,
|
||||
} = props;
|
||||
|
||||
const { width } = useTerminalDimensions();
|
||||
@@ -162,20 +184,26 @@ export function StatusBar(props: StatusBarProps) {
|
||||
? Math.min(width, HOME_VIEW_MAX_WIDTH) - 2
|
||||
: width - 2;
|
||||
|
||||
// Row 1 layout: [model + context info] .... [Plan/Act toggle]
|
||||
// Row 1 layout: [model + context info] .... [agent label] [Plan/Act toggle]
|
||||
// When the full row doesn't fit, context info drops to its own row 2.
|
||||
// Model ID truncates with "..." before wrapping; toggle stays right-aligned.
|
||||
const toggleWidth = 20;
|
||||
const fullAgentLabel = agentName
|
||||
? formatStatusBarAgentLabel(agentName)
|
||||
: undefined;
|
||||
const agentLabelWidth = fullAgentLabel ? fullAgentLabel.length + 3 : 0;
|
||||
const usageText = formatStatusBarUsageText({
|
||||
totalTokens,
|
||||
totalCost,
|
||||
showCost: showUsageCost,
|
||||
});
|
||||
const contextText = bar
|
||||
? ` ${bar.filled}${bar.empty} ${usageText}`
|
||||
: ` ${usageText}`;
|
||||
const contextInlineText = bar
|
||||
? `${bar.filled}${bar.empty} ${usageText}`
|
||||
: usageText;
|
||||
const contextText = ` ${contextInlineText}`;
|
||||
const firstRowFits =
|
||||
modelId.length + contextText.length + toggleWidth + 1 <= avail;
|
||||
modelId.length + contextText.length + toggleWidth + agentLabelWidth + 1 <=
|
||||
avail;
|
||||
const renderContextText = (withLeadingSpace: boolean) => (
|
||||
<>
|
||||
{withLeadingSpace && " "}
|
||||
@@ -191,7 +219,11 @@ export function StatusBar(props: StatusBarProps) {
|
||||
|
||||
const modelMaxLen = Math.max(
|
||||
10,
|
||||
avail - toggleWidth - (firstRowFits ? contextText.length : 0) - 1,
|
||||
avail -
|
||||
toggleWidth -
|
||||
agentLabelWidth -
|
||||
(firstRowFits ? contextText.length : 0) -
|
||||
1,
|
||||
);
|
||||
const truncatedModel =
|
||||
modelId.length > modelMaxLen
|
||||
@@ -210,6 +242,14 @@ export function StatusBar(props: StatusBarProps) {
|
||||
pathPart.length > pathMax
|
||||
? `${pathPart.slice(0, pathMax - 3)}...`
|
||||
: pathPart;
|
||||
const firstRowAgentMaxLen = Math.min(
|
||||
18,
|
||||
Math.max(0, avail - toggleWidth - 3),
|
||||
);
|
||||
const agentLabel = agentName
|
||||
? formatStatusBarAgentLabel(agentName, firstRowAgentMaxLen)
|
||||
: undefined;
|
||||
|
||||
return (
|
||||
<box flexDirection="column" paddingX={1}>
|
||||
<box flexDirection="row" justifyContent="space-between">
|
||||
@@ -223,6 +263,14 @@ export function StatusBar(props: StatusBarProps) {
|
||||
flexShrink={0}
|
||||
onMouseDown={onToggleMode}
|
||||
>
|
||||
{agentLabel && (
|
||||
<>
|
||||
<box flexShrink={0} onMouseDown={onOpenAgent}>
|
||||
<text fg={defaultFg}>{agentLabel}</text>
|
||||
</box>
|
||||
<text fg="gray">|</text>
|
||||
</>
|
||||
)}
|
||||
<text fg={uiMode === "plan" ? planAccent : "gray"}>
|
||||
{uiMode === "plan" ? "●" : "○"} Plan
|
||||
</text>
|
||||
|
||||
@@ -21,6 +21,7 @@ interface SessionContextValue {
|
||||
uiMode: AgentMode;
|
||||
autoApproveAll: boolean;
|
||||
compactionMode: CliCompactionMode;
|
||||
activeAgentName: string | null;
|
||||
lastTotalTokens: number;
|
||||
lastTotalCost: number;
|
||||
isExitRequested: boolean;
|
||||
@@ -41,6 +42,7 @@ interface SessionContextValue {
|
||||
setUiMode: (mode: AgentMode) => void;
|
||||
toggleMode: () => void;
|
||||
toggleAutoApprove: () => void;
|
||||
setActiveAgentName: (name: string | null) => void;
|
||||
setCompactionMode: (mode: CliCompactionMode) => void;
|
||||
requestExit: () => void;
|
||||
clearEntries: () => void;
|
||||
@@ -112,6 +114,9 @@ export function SessionProvider(props: {
|
||||
const [compactionMode, _setCompactionMode] = useState<CliCompactionMode>(() =>
|
||||
getCliCompactionMode(config),
|
||||
);
|
||||
const [activeAgentName, setActiveAgentName] = useState<string | null>(
|
||||
config.agentProfile?.name ?? null,
|
||||
);
|
||||
const [lastTotalTokens, setLastTotalTokens] = useState(
|
||||
() => initialUsage?.totalTokens ?? 0,
|
||||
);
|
||||
@@ -250,6 +255,7 @@ export function SessionProvider(props: {
|
||||
uiMode,
|
||||
autoApproveAll,
|
||||
compactionMode,
|
||||
activeAgentName,
|
||||
lastTotalTokens,
|
||||
lastTotalCost,
|
||||
isExitRequested,
|
||||
@@ -268,6 +274,7 @@ export function SessionProvider(props: {
|
||||
setUiMode,
|
||||
toggleMode,
|
||||
toggleAutoApprove,
|
||||
setActiveAgentName,
|
||||
setCompactionMode,
|
||||
requestExit,
|
||||
clearEntries,
|
||||
|
||||
@@ -7,6 +7,7 @@ export interface LocalSlashCommandActionInput {
|
||||
openConfig: (options?: OpenConfigOptions) => void;
|
||||
openMcpManager: () => Promise<boolean>;
|
||||
openModelSelector: () => void;
|
||||
openAgentSelector: () => void;
|
||||
openSkills: (invocation?: LocalSlashCommandInvocation) => void;
|
||||
invocation?: LocalSlashCommandInvocation;
|
||||
runCompact: () => void;
|
||||
@@ -45,6 +46,10 @@ export function runLocalSlashCommandAction(
|
||||
input.openModelSelector();
|
||||
return true;
|
||||
}
|
||||
if (normalized === "agents" || normalized === "agent") {
|
||||
input.openAgentSelector();
|
||||
return true;
|
||||
}
|
||||
if (normalized === "compact") {
|
||||
input.runCompact();
|
||||
return true;
|
||||
|
||||
@@ -0,0 +1,119 @@
|
||||
import { sep } from "node:path";
|
||||
import { loadConfiguredAgentConfigs } from "@cline/core";
|
||||
import type { ChoiceContext } from "@opentui-ui/dialog";
|
||||
import type { DialogActions } from "@opentui-ui/dialog/react";
|
||||
import { useCallback } from "react";
|
||||
import type { Config } from "../../utils/types";
|
||||
import {
|
||||
type AgentProfileLoadError,
|
||||
type AgentProfileOption,
|
||||
AgentSelectorContent,
|
||||
DEFAULT_AGENT_ACTION,
|
||||
} from "../components/dialogs/agent-selector";
|
||||
import { withLoadingDialog } from "../components/dialogs/loading-dialog";
|
||||
import { useSession } from "../contexts/session-context";
|
||||
import type { TuiProps } from "../types";
|
||||
|
||||
function loadAgentProfileEntries(config: Config): {
|
||||
agents: AgentProfileOption[];
|
||||
loadErrors: AgentProfileLoadError[];
|
||||
} {
|
||||
const workspaceRoot = config.workspaceRoot?.trim() || config.cwd;
|
||||
const { configs, errors } = loadConfiguredAgentConfigs({ workspaceRoot });
|
||||
return {
|
||||
agents: configs.map((profile) => ({
|
||||
name: profile.name,
|
||||
description: profile.description,
|
||||
systemPrompt: profile.systemPrompt,
|
||||
source:
|
||||
workspaceRoot && profile.path?.startsWith(`${workspaceRoot}${sep}`)
|
||||
? ("workspace" as const)
|
||||
: ("global" as const),
|
||||
})),
|
||||
loadErrors: errors.map((error) => ({
|
||||
path: error.path,
|
||||
message: error.error.message,
|
||||
})),
|
||||
};
|
||||
}
|
||||
|
||||
export function useAgentSelector(opts: {
|
||||
dialog: DialogActions;
|
||||
config: Config;
|
||||
termHeight: number;
|
||||
onAgentProfileChange: TuiProps["onAgentProfileChange"];
|
||||
refocusTextarea: () => void;
|
||||
}): () => Promise<void> {
|
||||
const { dialog, config, termHeight, onAgentProfileChange, refocusTextarea } =
|
||||
opts;
|
||||
const session = useSession();
|
||||
|
||||
const openAgentSelector = useCallback(async () => {
|
||||
// Applying a profile restarts the session in place, so refuse while a
|
||||
// turn is running instead of yanking the live stream out from under it.
|
||||
if (session.isRunning) {
|
||||
session.appendEntry({
|
||||
kind: "status",
|
||||
text: "Finish or abort the current task before switching agents.",
|
||||
});
|
||||
refocusTextarea();
|
||||
return;
|
||||
}
|
||||
const { agents, loadErrors } = loadAgentProfileEntries(config);
|
||||
const currentAgentName = config.agentProfile?.name ?? null;
|
||||
|
||||
const selectedKey = await dialog.choice<string>({
|
||||
style: { maxHeight: termHeight - 2 },
|
||||
content: (ctx: ChoiceContext<string>) => (
|
||||
<AgentSelectorContent
|
||||
{...ctx}
|
||||
currentAgentName={currentAgentName}
|
||||
agents={agents}
|
||||
loadErrors={loadErrors}
|
||||
/>
|
||||
),
|
||||
});
|
||||
if (!selectedKey) {
|
||||
refocusTextarea();
|
||||
return;
|
||||
}
|
||||
|
||||
if (selectedKey === DEFAULT_AGENT_ACTION) {
|
||||
if (config.agentProfile) {
|
||||
await withLoadingDialog(dialog, "Applying agent...", async () => {
|
||||
await onAgentProfileChange(null);
|
||||
});
|
||||
session.setActiveAgentName(null);
|
||||
}
|
||||
refocusTextarea();
|
||||
return;
|
||||
}
|
||||
|
||||
const profile = agents.find(
|
||||
(agent) => agent.name.toLowerCase() === selectedKey,
|
||||
);
|
||||
if (!profile) {
|
||||
refocusTextarea();
|
||||
return;
|
||||
}
|
||||
if (profile.name !== currentAgentName) {
|
||||
await withLoadingDialog(dialog, "Applying agent...", async () => {
|
||||
await onAgentProfileChange({
|
||||
name: profile.name,
|
||||
systemPrompt: profile.systemPrompt,
|
||||
});
|
||||
});
|
||||
session.setActiveAgentName(profile.name);
|
||||
}
|
||||
refocusTextarea();
|
||||
}, [
|
||||
dialog,
|
||||
config,
|
||||
termHeight,
|
||||
onAgentProfileChange,
|
||||
refocusTextarea,
|
||||
session,
|
||||
]);
|
||||
|
||||
return openAgentSelector;
|
||||
}
|
||||
@@ -13,6 +13,7 @@ function makeActions(
|
||||
openConfig: vi.fn(),
|
||||
openMcpManager: vi.fn(async () => false),
|
||||
openModelSelector: vi.fn(),
|
||||
openAgentSelector: vi.fn(),
|
||||
openSkills: vi.fn(),
|
||||
runCompact: vi.fn(),
|
||||
runFork: vi.fn(),
|
||||
@@ -45,6 +46,21 @@ describe("runLocalSlashCommandAction", () => {
|
||||
expect(openSkills).toHaveBeenCalledWith(invocation);
|
||||
});
|
||||
|
||||
it("opens the agent selector with agents and the agent alias", () => {
|
||||
for (const name of ["agents", "agent"]) {
|
||||
const openAgentSelector = vi.fn();
|
||||
const actions = makeActions({ openAgentSelector });
|
||||
|
||||
const handled = runLocalSlashCommandAction({
|
||||
name,
|
||||
...actions,
|
||||
});
|
||||
|
||||
expect(handled).toBe(true);
|
||||
expect(openAgentSelector).toHaveBeenCalledOnce();
|
||||
}
|
||||
});
|
||||
|
||||
it("opens settings to the plugins tab with plugins", () => {
|
||||
const openConfig = vi.fn();
|
||||
const actions = makeActions({ openConfig });
|
||||
|
||||
@@ -23,6 +23,7 @@ export function useLocalCommandActions(input: {
|
||||
openConfig: (options?: OpenConfigOptions) => void;
|
||||
openMcpManager: () => Promise<boolean>;
|
||||
openModelSelector: () => void;
|
||||
openAgentSelector: () => void;
|
||||
openSkills: (invocation?: LocalSlashCommandInvocation) => void;
|
||||
refocusTextarea: () => void;
|
||||
setAppView: (view: AppView) => void;
|
||||
@@ -43,6 +44,7 @@ export function useLocalCommandActions(input: {
|
||||
openConfig,
|
||||
openMcpManager,
|
||||
openModelSelector,
|
||||
openAgentSelector,
|
||||
openSkills,
|
||||
refocusTextarea,
|
||||
setAppView,
|
||||
@@ -185,6 +187,7 @@ export function useLocalCommandActions(input: {
|
||||
openConfig,
|
||||
openMcpManager,
|
||||
openModelSelector,
|
||||
openAgentSelector,
|
||||
openSkills,
|
||||
runCompact,
|
||||
runFork,
|
||||
@@ -205,6 +208,7 @@ export function useLocalCommandActions(input: {
|
||||
openHelp,
|
||||
openHistory,
|
||||
openModelSelector,
|
||||
openAgentSelector,
|
||||
openSkills,
|
||||
runCompact,
|
||||
runFork,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { existsSync, readdirSync, readFileSync } from "node:fs";
|
||||
import { existsSync, readFileSync } from "node:fs";
|
||||
import {
|
||||
basename,
|
||||
dirname,
|
||||
@@ -14,11 +14,11 @@ import {
|
||||
hasMcpSettingsFile,
|
||||
listHookConfigFiles,
|
||||
listPluginToolsWithDiagnostics,
|
||||
loadConfiguredAgentConfigs,
|
||||
type McpServerRegistration,
|
||||
type PluginInitializationFailure,
|
||||
type RuleConfig,
|
||||
readGlobalSettings,
|
||||
resolveAgentConfigSearchPaths,
|
||||
resolveDefaultMcpSettingsPath,
|
||||
resolveMcpServerRegistrations,
|
||||
resolvePluginConfigSearchPaths,
|
||||
@@ -175,58 +175,30 @@ function getMcpDescription(registration: McpServerRegistration): string {
|
||||
}
|
||||
|
||||
function loadAgentConfigItems(workspaceRoot: string): InteractiveConfigItem[] {
|
||||
const agentsById = new Map<string, InteractiveConfigItem>();
|
||||
const directories = resolveAgentConfigSearchPaths(workspaceRoot).filter(
|
||||
(directory) => existsSync(directory),
|
||||
);
|
||||
|
||||
for (const directory of directories) {
|
||||
try {
|
||||
const entries = readdirSync(directory, { withFileTypes: true });
|
||||
for (const entry of entries) {
|
||||
if (!entry.isFile()) {
|
||||
continue;
|
||||
}
|
||||
const extension = extname(entry.name).toLowerCase();
|
||||
if (extension !== ".yml" && extension !== ".yaml") {
|
||||
continue;
|
||||
}
|
||||
const filePath = join(directory, entry.name);
|
||||
const raw = readFileSync(filePath, "utf8");
|
||||
const frontmatterMatch = raw.match(/^---\r?\n([\s\S]*?)\r?\n---/);
|
||||
const frontmatter = frontmatterMatch?.[1] ?? "";
|
||||
const nameMatch = frontmatter.match(/^\s*name:\s*(.+?)\s*$/m);
|
||||
const descriptionMatch = frontmatter.match(
|
||||
/^\s*description:\s*(.+?)\s*$/m,
|
||||
);
|
||||
const parsedName = nameMatch?.[1]?.replace(/^["']|["']$/g, "").trim();
|
||||
const parsedDescription = descriptionMatch?.[1]
|
||||
?.replace(/^["']|["']$/g, "")
|
||||
.trim();
|
||||
const name =
|
||||
parsedName && parsedName.length > 0
|
||||
? parsedName
|
||||
: basename(entry.name, extension);
|
||||
const id = name.toLowerCase();
|
||||
if (agentsById.has(id)) {
|
||||
continue;
|
||||
}
|
||||
agentsById.set(id, {
|
||||
id,
|
||||
name,
|
||||
path: filePath,
|
||||
enabled: true,
|
||||
kind: "agent",
|
||||
source: detectSource(filePath, workspaceRoot),
|
||||
description: parsedDescription,
|
||||
});
|
||||
}
|
||||
} catch {
|
||||
// Best effort: keep listing other agent config roots.
|
||||
}
|
||||
const { configs, errors } = loadConfiguredAgentConfigs({ workspaceRoot });
|
||||
const items: InteractiveConfigItem[] = configs.map((config) => ({
|
||||
id: config.name.toLowerCase(),
|
||||
name: config.name,
|
||||
path: config.path ?? "",
|
||||
enabled: true,
|
||||
kind: "agent" as const,
|
||||
source: detectSource(config.path ?? "", workspaceRoot),
|
||||
description: config.description,
|
||||
}));
|
||||
// Keep broken profile files visible so users can spot and fix them.
|
||||
for (const error of errors) {
|
||||
items.push({
|
||||
id: error.path,
|
||||
name: basename(error.path, extname(error.path)),
|
||||
path: error.path,
|
||||
enabled: false,
|
||||
kind: "agent" as const,
|
||||
source: detectSource(error.path, workspaceRoot),
|
||||
description: error.error.message,
|
||||
loadError: error.error.message,
|
||||
});
|
||||
}
|
||||
|
||||
return [...agentsById.values()];
|
||||
return items;
|
||||
}
|
||||
|
||||
function readPackageName(packageJsonPath: string): string | undefined {
|
||||
|
||||
@@ -41,6 +41,7 @@ import { EventBridgeProvider } from "./contexts/event-bridge-context";
|
||||
import { SessionProvider, useSession } from "./contexts/session-context";
|
||||
import { useAccountDialog } from "./hooks/use-account-dialog";
|
||||
import { useAgentEventHandlers } from "./hooks/use-agent-events";
|
||||
import { useAgentSelector } from "./hooks/use-agent-selector";
|
||||
import { useAutocomplete } from "./hooks/use-autocomplete";
|
||||
import { useConfigPanel } from "./hooks/use-config-panel";
|
||||
import { useLocalCommandActions } from "./hooks/use-local-command-actions";
|
||||
@@ -187,6 +188,14 @@ function App(props: TuiProps) {
|
||||
refocusTextarea: () => refocusTextareaRef.current(),
|
||||
});
|
||||
|
||||
const openAgentSelector = useAgentSelector({
|
||||
dialog,
|
||||
config: props.config,
|
||||
termHeight,
|
||||
onAgentProfileChange: props.onAgentProfileChange,
|
||||
refocusTextarea: () => refocusTextareaRef.current(),
|
||||
});
|
||||
|
||||
const openMcpManager = useMcpManager({
|
||||
dialog,
|
||||
termHeight,
|
||||
@@ -639,6 +648,7 @@ function App(props: TuiProps) {
|
||||
openConfig,
|
||||
openMcpManager,
|
||||
openModelSelector,
|
||||
openAgentSelector,
|
||||
openSkills,
|
||||
refocusTextarea: () => refocusTextareaRef.current(),
|
||||
setAppView,
|
||||
@@ -886,6 +896,9 @@ function App(props: TuiProps) {
|
||||
void saveQueuedPromptEdit(id, prompt);
|
||||
},
|
||||
onToggleMode: toggleMode,
|
||||
onOpenAgentSelector: () => {
|
||||
void openAgentSelector();
|
||||
},
|
||||
runtimeInteraction,
|
||||
onResolveToolApproval: runtimeBridge.resolveToolApproval,
|
||||
onResolveAskQuestion: runtimeBridge.resolveAskQuestion,
|
||||
|
||||
@@ -15,7 +15,11 @@ import type {
|
||||
PendingPromptSubmittedEvent,
|
||||
} from "../runtime/session-events";
|
||||
import type { RepoStatus } from "../utils/repo-status";
|
||||
import type { CliCompactionMode, Config } from "../utils/types";
|
||||
import type {
|
||||
ActiveAgentProfile,
|
||||
CliCompactionMode,
|
||||
Config,
|
||||
} from "../utils/types";
|
||||
import type { ClineAccountSnapshot } from "./cline-account";
|
||||
import type {
|
||||
InteractiveConfigData,
|
||||
@@ -166,6 +170,7 @@ export interface TuiProps {
|
||||
onCompactionModeChange: (mode: CliCompactionMode) => Promise<void>;
|
||||
onModelChange: () => Promise<void>;
|
||||
onModeChange: (mode: AgentMode) => Promise<void>;
|
||||
onAgentProfileChange: (profile: ActiveAgentProfile | null) => Promise<void>;
|
||||
onNewSession: () => Promise<void>;
|
||||
onSessionRestart: () => Promise<void>;
|
||||
onAccountChange: () => Promise<void>;
|
||||
|
||||
@@ -56,6 +56,7 @@ export function ChatView(props: {
|
||||
editingQueuedPrompt?: QueuedPromptItem;
|
||||
onQueuedPromptEditConfirm: (id: string, prompt: string) => void;
|
||||
onToggleMode: () => void;
|
||||
onOpenAgentSelector: () => void;
|
||||
runtimeInteraction?: RuntimeToolInteraction | null;
|
||||
onResolveToolApproval: (id: number, approved: boolean) => void;
|
||||
onResolveAskQuestion: (id: number, answer: string | null) => void;
|
||||
@@ -157,6 +158,8 @@ export function ChatView(props: {
|
||||
gitBranch={repoStatus.branch}
|
||||
gitDiffStats={repoStatus.diffStats}
|
||||
onToggleMode={props.onToggleMode}
|
||||
agentName={session.activeAgentName}
|
||||
onOpenAgent={props.onOpenAgentSelector}
|
||||
variant="chat"
|
||||
/>
|
||||
</box>
|
||||
|
||||
@@ -46,6 +46,7 @@ export function HomeView(props: {
|
||||
textareaRef?: React.MutableRefObject<TextareaHandle | null>;
|
||||
autocomplete?: AutocompleteDropdownProps;
|
||||
onToggleMode: () => void;
|
||||
onOpenAgentSelector: () => void;
|
||||
}) {
|
||||
const {
|
||||
config,
|
||||
@@ -156,6 +157,8 @@ export function HomeView(props: {
|
||||
gitBranch={repoStatus.branch}
|
||||
gitDiffStats={repoStatus.diffStats}
|
||||
onToggleMode={props.onToggleMode}
|
||||
agentName={session.activeAgentName}
|
||||
onOpenAgent={props.onOpenAgentSelector}
|
||||
variant="home"
|
||||
/>
|
||||
</box>
|
||||
|
||||
@@ -17,6 +17,16 @@ export type CliReasoningEffort = NonNullable<
|
||||
>;
|
||||
export type CliCompactionMode = "agentic" | "basic" | "off";
|
||||
|
||||
/**
|
||||
* An agent profile from .cline/agents applied to the main Cline agent for
|
||||
* the current session. Session-only: never persisted to settings.
|
||||
*/
|
||||
export interface ActiveAgentProfile {
|
||||
name: string;
|
||||
/** Profile body, captured at selection time (survives file deletion mid-session) */
|
||||
systemPrompt: string;
|
||||
}
|
||||
|
||||
export interface Config extends Omit<CoreSessionConfig, "apiKey" | "mode"> {
|
||||
apiKey: string;
|
||||
knownModels?: Record<string, Llms.ModelInfo>;
|
||||
@@ -30,6 +40,7 @@ export interface Config extends Omit<CoreSessionConfig, "apiKey" | "mode"> {
|
||||
mode: CliAgentMode;
|
||||
defaultToolAutoApprove: boolean;
|
||||
toolPolicies: Record<string, ToolPolicy>;
|
||||
agentProfile?: ActiveAgentProfile;
|
||||
}
|
||||
|
||||
export interface ActiveCliSession {
|
||||
@@ -96,4 +107,6 @@ export interface ParsedArgs {
|
||||
teamName?: string;
|
||||
defaultToolAutoApprove: boolean;
|
||||
autoApproveOverride?: boolean;
|
||||
/** Agent profile name from .cline/agents to apply to the main agent */
|
||||
agent?: string;
|
||||
}
|
||||
|
||||
@@ -320,11 +320,17 @@ describe("createSpawnAgentTool", () => {
|
||||
},
|
||||
);
|
||||
|
||||
expect(agentConstructorSpy).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
systemPrompt: inputSystemPrompt,
|
||||
}),
|
||||
const constructedConfig = agentConstructorSpy.mock.calls[0]?.[0] as {
|
||||
systemPrompt: string;
|
||||
};
|
||||
expect(constructedConfig.systemPrompt.startsWith(inputSystemPrompt)).toBe(
|
||||
true,
|
||||
);
|
||||
// The embedded workspace configuration is not injected a second time.
|
||||
const markerCount = constructedConfig.systemPrompt.split(
|
||||
"# Workspace Configuration",
|
||||
).length;
|
||||
expect(markerCount - 1).toBe(1);
|
||||
});
|
||||
|
||||
it("resolves connection settings lazily at execution time", async () => {
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { DelegatedAgentRuntimeConfig } from "./delegated-agent";
|
||||
import {
|
||||
buildSubAgentSystemPrompt,
|
||||
buildTeammateSystemPrompt,
|
||||
} from "./subagent-prompts";
|
||||
|
||||
const PROFILE_BODY = "You are a reviewer. Focus on correctness.";
|
||||
|
||||
function makeConfig(
|
||||
overrides: Partial<DelegatedAgentRuntimeConfig> = {},
|
||||
): DelegatedAgentRuntimeConfig {
|
||||
return {
|
||||
providerId: "cline",
|
||||
modelId: "model",
|
||||
cwd: "/repo",
|
||||
apiKey: "key",
|
||||
clineIdeName: "Terminal",
|
||||
clinePlatform: "linux",
|
||||
workspaceMetadata: '{"workspaces":{}}',
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
describe("buildSubAgentSystemPrompt", () => {
|
||||
it("fills the persona slot and keeps the agent harness for cline", () => {
|
||||
const prompt = buildSubAgentSystemPrompt(PROFILE_BODY, makeConfig());
|
||||
expect(prompt.startsWith(PROFILE_BODY)).toBe(true);
|
||||
expect(prompt).toContain("Environment you are running in:");
|
||||
expect(prompt).toContain("4. Working Directory: /repo");
|
||||
expect(prompt).toContain(
|
||||
"IMPORTANT: Always includes tool calls in your response until the task is completed.",
|
||||
);
|
||||
expect(prompt).toContain("# Workspace Configuration");
|
||||
expect(prompt).not.toContain("You are Cline, an AI coding agent.");
|
||||
});
|
||||
|
||||
it("keeps the harness for non-cline providers without cline metadata", () => {
|
||||
const prompt = buildSubAgentSystemPrompt(
|
||||
PROFILE_BODY,
|
||||
makeConfig({ providerId: "openai" }),
|
||||
);
|
||||
expect(prompt.startsWith(PROFILE_BODY)).toBe(true);
|
||||
expect(prompt).toContain("Environment you are running in:");
|
||||
expect(prompt).toContain(
|
||||
"IMPORTANT: Always includes tool calls in your response until the task is completed.",
|
||||
);
|
||||
expect(prompt).not.toContain("# Workspace Configuration");
|
||||
});
|
||||
});
|
||||
|
||||
describe("buildTeammateSystemPrompt", () => {
|
||||
it("injects the role prompt as rules under the default persona for cline", () => {
|
||||
const prompt = buildTeammateSystemPrompt(PROFILE_BODY, makeConfig());
|
||||
expect(prompt).toContain("You are Cline, an AI coding agent.");
|
||||
expect(prompt).toContain(`# Team Teammate Role\n${PROFILE_BODY}`);
|
||||
});
|
||||
|
||||
it("returns the raw prompt for non-cline providers", () => {
|
||||
const prompt = buildTeammateSystemPrompt(
|
||||
PROFILE_BODY,
|
||||
makeConfig({ providerId: "openai" }),
|
||||
);
|
||||
expect(prompt).toBe(PROFILE_BODY);
|
||||
});
|
||||
});
|
||||
@@ -26,15 +26,13 @@ export function buildSubAgentSystemPrompt(
|
||||
config: DelegatedAgentRuntimeConfig,
|
||||
): string {
|
||||
const trimmedPrompt = prompt.trim();
|
||||
if (config.providerId.toLowerCase() !== "cline") {
|
||||
return trimmedPrompt;
|
||||
}
|
||||
|
||||
// The spawn prompt fills the persona slot; the provider-agnostic harness
|
||||
// (env block, tool-call loop contract) is kept for every provider.
|
||||
return buildClineSystemPrompt({
|
||||
ide: config.clineIdeName || "Terminal",
|
||||
workspaceRoot: config.cwd?.trim() || "/",
|
||||
providerId: config.providerId,
|
||||
overridePrompt: trimmedPrompt,
|
||||
personaPrompt: trimmedPrompt,
|
||||
metadata: config.workspaceMetadata,
|
||||
platform: config.clinePlatform,
|
||||
});
|
||||
|
||||
@@ -2,8 +2,8 @@ import { EMPTY_CONTENT_TEXT } from "@cline/shared";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
agentMessageToMessageWithMetadata,
|
||||
messageToAgentMessages,
|
||||
messagesToAgentMessages,
|
||||
messageToAgentMessages,
|
||||
} from "./agent-message-codec";
|
||||
|
||||
describe("agent message codec", () => {
|
||||
|
||||
@@ -1,6 +1,22 @@
|
||||
import { dirname, resolve } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { defineConfig } from "vitest/config";
|
||||
|
||||
const rootDir = dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
export default defineConfig({
|
||||
resolve: {
|
||||
alias: [
|
||||
{
|
||||
find: /^@cline\/shared$/,
|
||||
replacement: resolve(rootDir, "../shared/src/index.ts"),
|
||||
},
|
||||
{
|
||||
find: /^@cline\/shared\/(.+)$/,
|
||||
replacement: resolve(rootDir, "../shared/src/$1"),
|
||||
},
|
||||
],
|
||||
},
|
||||
test: {
|
||||
environment: "node",
|
||||
include: ["src/**/*.test.ts"],
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { buildClineSystemPrompt } from "./cline";
|
||||
import { DEFAULT_CLINE_PERSONA } from "./system";
|
||||
|
||||
const PERSONA = "You are Reviewer, a meticulous code review agent.";
|
||||
|
||||
describe("buildClineSystemPrompt", () => {
|
||||
it("uses the default persona when no personaPrompt is provided", () => {
|
||||
const prompt = buildClineSystemPrompt({
|
||||
workspaceRoot: "/repo",
|
||||
platform: "linux",
|
||||
});
|
||||
expect(prompt).toContain("You are Cline, an AI coding agent.");
|
||||
expect(prompt).toContain("4. Working Directory: /repo");
|
||||
});
|
||||
|
||||
it("applies personaPrompt while keeping the harness", () => {
|
||||
const prompt = buildClineSystemPrompt({
|
||||
workspaceRoot: "/repo",
|
||||
platform: "linux",
|
||||
ide: "Terminal",
|
||||
personaPrompt: PERSONA,
|
||||
});
|
||||
expect(prompt.startsWith(PERSONA)).toBe(true);
|
||||
expect(prompt).toContain("1. Platform: linux");
|
||||
expect(prompt).toContain("4. Working Directory: /repo");
|
||||
expect(prompt).toContain(
|
||||
"IMPORTANT: Always includes tool calls in your response until the task is completed.",
|
||||
);
|
||||
expect(prompt).not.toContain(DEFAULT_CLINE_PERSONA);
|
||||
});
|
||||
|
||||
it("appends workspace metadata for the cline provider with a persona", () => {
|
||||
const prompt = buildClineSystemPrompt({
|
||||
workspaceRoot: "/repo",
|
||||
providerId: "cline",
|
||||
personaPrompt: PERSONA,
|
||||
metadata: '{"workspaces":{}}',
|
||||
});
|
||||
expect(prompt.startsWith(PERSONA)).toBe(true);
|
||||
expect(prompt).toContain("# Workspace Configuration");
|
||||
});
|
||||
|
||||
it("does not duplicate metadata when the persona already embeds it", () => {
|
||||
const personaWithMetadata = `${PERSONA}\n\n# Workspace Configuration\n{"workspaces":{}}`;
|
||||
const prompt = buildClineSystemPrompt({
|
||||
workspaceRoot: "/repo",
|
||||
providerId: "cline",
|
||||
personaPrompt: personaWithMetadata,
|
||||
metadata: '{"workspaces":{}}',
|
||||
});
|
||||
const markerCount = prompt.split("# Workspace Configuration").length - 1;
|
||||
expect(markerCount).toBe(1);
|
||||
});
|
||||
|
||||
it("omits workspace metadata for non-cline providers with a persona", () => {
|
||||
const prompt = buildClineSystemPrompt({
|
||||
workspaceRoot: "/repo",
|
||||
providerId: "openai",
|
||||
personaPrompt: PERSONA,
|
||||
metadata: '{"workspaces":{}}',
|
||||
});
|
||||
expect(prompt.startsWith(PERSONA)).toBe(true);
|
||||
expect(prompt).not.toContain("# Workspace Configuration");
|
||||
});
|
||||
|
||||
it("lets overridePrompt win over personaPrompt", () => {
|
||||
const prompt = buildClineSystemPrompt({
|
||||
workspaceRoot: "/repo",
|
||||
overridePrompt: "Full override.",
|
||||
personaPrompt: PERSONA,
|
||||
});
|
||||
expect(prompt).toBe("Full override.");
|
||||
});
|
||||
|
||||
it("ignores personaPrompt in yolo mode", () => {
|
||||
const prompt = buildClineSystemPrompt({
|
||||
workspaceRoot: "/repo",
|
||||
mode: "yolo",
|
||||
personaPrompt: PERSONA,
|
||||
});
|
||||
expect(prompt).toContain(
|
||||
"You are Cline, a careful and helpful coding agent that works in the background.",
|
||||
);
|
||||
expect(prompt).not.toContain(PERSONA);
|
||||
});
|
||||
|
||||
it("inserts rules containing replacement patterns literally", () => {
|
||||
const prompt = buildClineSystemPrompt({
|
||||
workspaceRoot: "/repo",
|
||||
rules: "Use $& and $' carefully.",
|
||||
});
|
||||
expect(prompt).toContain("Use $& and $' carefully.");
|
||||
});
|
||||
|
||||
it("keeps template-like tokens inside the persona literal", () => {
|
||||
const persona =
|
||||
"You report {{PLATFORM_NAME}} and honor {{CLINE_RULES}} verbatim.";
|
||||
const prompt = buildClineSystemPrompt({
|
||||
workspaceRoot: "/repo",
|
||||
platform: "linux",
|
||||
personaPrompt: persona,
|
||||
rules: "Real rules here.",
|
||||
});
|
||||
expect(prompt.startsWith(persona)).toBe(true);
|
||||
expect(prompt).toContain("1. Platform: linux");
|
||||
expect(prompt).toContain("Real rules here.");
|
||||
});
|
||||
});
|
||||
@@ -1,7 +1,8 @@
|
||||
import type { WorkspaceContext } from "../extensions/context";
|
||||
import type { WorkspaceInfo } from "../session/workspace";
|
||||
import {
|
||||
DEFAULT_CLINE_SYSTEM_PROMPT,
|
||||
AGENT_PERSONA_SLOT,
|
||||
composeClineSystemPrompt,
|
||||
YOLO_CLINE_SYSTEM_PROMPT,
|
||||
} from "./system";
|
||||
|
||||
@@ -59,14 +60,20 @@ export interface ClineSystemPromptOptions
|
||||
extends Omit<WorkspaceContext, "rootPath"> {
|
||||
/**
|
||||
* Workspace root path. Accepts either `rootPath` (from WorkspaceContext/WorkspaceInfo)
|
||||
* or `workspaceRoot` (legacy alias) — whichever is provided will be used.
|
||||
* or `workspaceRoot` (legacy alias) - whichever is provided will be used.
|
||||
*/
|
||||
rootPath?: string;
|
||||
/** Alias for rootPath — kept for backwards compatibility with existing call sites */
|
||||
/** Alias for rootPath - kept for backwards compatibility with existing call sites */
|
||||
workspaceRoot?: string;
|
||||
/** Per-request system prompt override */
|
||||
overridePrompt?: string;
|
||||
/** Provider ID — used to gate Cline-specific metadata injection */
|
||||
/**
|
||||
* Agent-profile persona: replaces the default Cline persona (the identity
|
||||
* intro) while keeping the agent harness, including the working guidelines.
|
||||
* Ignored when `overridePrompt` is set or in yolo mode.
|
||||
*/
|
||||
personaPrompt?: string;
|
||||
/** Provider ID - used to gate Cline-specific metadata injection */
|
||||
providerId?: string;
|
||||
}
|
||||
|
||||
@@ -81,6 +88,7 @@ export function buildClineSystemPrompt(
|
||||
metadata,
|
||||
rules,
|
||||
overridePrompt,
|
||||
personaPrompt,
|
||||
providerId,
|
||||
} = options;
|
||||
const workspaceRoot = options.workspaceRoot ?? options.rootPath ?? "";
|
||||
@@ -98,20 +106,33 @@ export function buildClineSystemPrompt(
|
||||
return trimmed;
|
||||
}
|
||||
|
||||
const persona = mode === "yolo" ? undefined : personaPrompt?.trim();
|
||||
// Keep the persona slot in place and fill it last, so `{{...}}` sequences
|
||||
// inside a persona body stay literal.
|
||||
const basePrompt =
|
||||
mode === "yolo" ? YOLO_CLINE_SYSTEM_PROMPT : DEFAULT_CLINE_SYSTEM_PROMPT;
|
||||
mode === "yolo"
|
||||
? YOLO_CLINE_SYSTEM_PROMPT
|
||||
: composeClineSystemPrompt(
|
||||
persona ? { persona: AGENT_PERSONA_SLOT } : {},
|
||||
);
|
||||
// Skip metadata injection when the persona already embeds a workspace
|
||||
// configuration block (e.g. spawn prompts composed by a parent agent).
|
||||
const includeMetadata =
|
||||
isCline && !persona?.includes(WORKSPACE_CONFIGURATION_MARKER);
|
||||
|
||||
// Replacer functions (not replacement strings) so values containing
|
||||
// `$&`-style patterns are inserted literally.
|
||||
return basePrompt
|
||||
.replace("{{PLATFORM_NAME}}", platform)
|
||||
.replace("{{CWD}}", workspaceRoot)
|
||||
.replace("{{CURRENT_DATE}}", new Date().toLocaleDateString())
|
||||
.replace("{{IDE_NAME}}", ide)
|
||||
.replace(
|
||||
"{{CLINE_METADATA}}",
|
||||
isCline
|
||||
.replace("{{PLATFORM_NAME}}", () => platform)
|
||||
.replace("{{CWD}}", () => workspaceRoot)
|
||||
.replace("{{CURRENT_DATE}}", () => new Date().toLocaleDateString())
|
||||
.replace("{{IDE_NAME}}", () => ide)
|
||||
.replace("{{CLINE_METADATA}}", () =>
|
||||
includeMetadata
|
||||
? buildWorkspaceMetadata(workspaceRoot, workspaceName, metadata)
|
||||
: "",
|
||||
)
|
||||
.replace("{{CLINE_RULES}}", rules || "")
|
||||
.replace("{{CLINE_RULES}}", () => rules || "")
|
||||
.replace(AGENT_PERSONA_SLOT, () => persona ?? "")
|
||||
.trim();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
composeClineSystemPrompt,
|
||||
DEFAULT_CLINE_PERSONA,
|
||||
DEFAULT_CLINE_SYSTEM_PROMPT,
|
||||
} from "./system";
|
||||
|
||||
// The canonical default system prompt. Pinned as a literal (including trailing
|
||||
// whitespace) so accidental drift is caught; update deliberately when the
|
||||
// default prompt is intentionally changed.
|
||||
const EXPECTED_DEFAULT_CLINE_SYSTEM_PROMPT = `You are Cline, an AI coding agent. Your primary goal is to assist users with various coding tasks by leveraging your knowledge and the tools at your disposal. Given the user's prompt, you should use the tools available to you to answer user's question.
|
||||
|
||||
Always gather all the necessary context before starting to work on a task. For example, if you are generating a unit test or new code, make sure you understand the requirement, the naming conventions, frameworks and libraries used and aligned in the current codebase, and the environment and commands used to run and test the code etc. Always validate the new unit test at the end including running the code if possible for live feedback.
|
||||
Review each question carefully and answer it with detailed, accurate information.
|
||||
|
||||
Environment you are running in:
|
||||
<env>
|
||||
1. Platform: {{PLATFORM_NAME}}
|
||||
2. Date: {{CURRENT_DATE}}
|
||||
3. IDE: {{IDE_NAME}}
|
||||
4. Working Directory: {{CWD}}
|
||||
</env>
|
||||
|
||||
Remember:
|
||||
- If you need more information, use one of the available tools or ask for clarification instead of making assumptions or lies.
|
||||
- Always adhere to existing code conventions and patterns.
|
||||
- Use only libraries and frameworks that are confirmed to be in use in the current codebase.
|
||||
- Provide complete and functional code without omissions or placeholders.
|
||||
- Be explicit about any assumptions or limitations in your solution.
|
||||
- Always show your planning process before executing any task. This will help ensure that you have a clear understanding of the requirements and that your approach aligns with the user's needs.
|
||||
- Always use absolute paths when referring to files.
|
||||
- Always verify the files you have edited or created at the end of the task to ensure they are completed and working as expected.
|
||||
|
||||
Begin by analyzing the user's input and gathering any necessary additional context. Then, present your plan at the start of your response along with tool calls before proceeding with the task. It's OK for this section to be quite long.
|
||||
|
||||
REMEMBER, be helpful and proactive! Don't ask for permission to do something when you can do it! Do not indicates you will be using a tool unless you are actually going to use it.
|
||||
|
||||
IMPORTANT: Always includes tool calls in your response until the task is completed. Response without tool calls will considered as completed with final answer.
|
||||
|
||||
When you have completed the task, please provide a summary of what you did and any relevant information that the user should know. This will help ensure that the user understands the changes made and can easily follow up if they have any questions or need further assistance. Do not indicate that you will perform an action without actually doing it. Always provide the final result in your response. Always validate your answer with checking the code and running it if possible.${" "}
|
||||
|
||||
If user asked a simple question without any coding context, answer it directly without using any tools.
|
||||
{{CLINE_RULES}}
|
||||
{{CLINE_METADATA}}`;
|
||||
|
||||
// Everything after the persona is the always-on harness (env block, working
|
||||
// guidelines, tool-call contract, completion rules, rules/metadata). Derived
|
||||
// from the default so the harness text has a single source of truth.
|
||||
const HARNESS = EXPECTED_DEFAULT_CLINE_SYSTEM_PROMPT.slice(
|
||||
DEFAULT_CLINE_PERSONA.length,
|
||||
);
|
||||
|
||||
describe("composeClineSystemPrompt", () => {
|
||||
it("composes the canonical default prompt", () => {
|
||||
expect(DEFAULT_CLINE_SYSTEM_PROMPT).toBe(
|
||||
EXPECTED_DEFAULT_CLINE_SYSTEM_PROMPT,
|
||||
);
|
||||
expect(composeClineSystemPrompt()).toBe(
|
||||
EXPECTED_DEFAULT_CLINE_SYSTEM_PROMPT,
|
||||
);
|
||||
expect(composeClineSystemPrompt({})).toBe(
|
||||
EXPECTED_DEFAULT_CLINE_SYSTEM_PROMPT,
|
||||
);
|
||||
// The exported persona is the real prefix; the rest is the harness.
|
||||
expect(DEFAULT_CLINE_SYSTEM_PROMPT).toBe(DEFAULT_CLINE_PERSONA + HARNESS);
|
||||
});
|
||||
|
||||
it("treats a blank persona as the default", () => {
|
||||
expect(composeClineSystemPrompt({ persona: " " })).toBe(
|
||||
EXPECTED_DEFAULT_CLINE_SYSTEM_PROMPT,
|
||||
);
|
||||
});
|
||||
|
||||
it("swaps the persona but keeps the harness verbatim", () => {
|
||||
const persona =
|
||||
"You are Reviewer, a meticulous code review agent. Focus on correctness.";
|
||||
// Only the persona changes; the entire harness tail is byte-identical.
|
||||
expect(composeClineSystemPrompt({ persona })).toBe(persona + HARNESS);
|
||||
});
|
||||
|
||||
it("keeps the working guidelines, incl. the no-guessing norm, in the harness", () => {
|
||||
const norm =
|
||||
"If you need more information, use one of the available tools or ask for clarification instead of making assumptions or lies.";
|
||||
// The norm and the rest of the working guidelines are harness, not
|
||||
// persona, so a profile keeps them while the identity is swapped.
|
||||
expect(HARNESS).toContain(norm);
|
||||
expect(DEFAULT_CLINE_PERSONA).not.toContain(norm);
|
||||
});
|
||||
|
||||
it("inserts persona content literally, including replacement patterns", () => {
|
||||
const persona = "Echo the captured group $& and $' verbatim.";
|
||||
expect(composeClineSystemPrompt({ persona })).toBe(persona + HARNESS);
|
||||
});
|
||||
|
||||
it("keeps template-like tokens inside the persona literal", () => {
|
||||
const persona = "Mention {{AGENT_GUIDELINES}} and {{AGENT_PERSONA}} as-is.";
|
||||
expect(composeClineSystemPrompt({ persona })).toBe(persona + HARNESS);
|
||||
});
|
||||
});
|
||||
@@ -1,8 +1,15 @@
|
||||
export const DEFAULT_CLINE_SYSTEM_PROMPT = `You are Cline, an AI coding agent. Your primary goal is to assist users with various coding tasks by leveraging your knowledge and the tools at your disposal. Given the user's prompt, you should use the tools available to you to answer user's question.
|
||||
export const DEFAULT_CLINE_PERSONA = `You are Cline, an AI coding agent. Your primary goal is to assist users with various coding tasks by leveraging your knowledge and the tools at your disposal. Given the user's prompt, you should use the tools available to you to answer user's question.
|
||||
|
||||
Always gather all the necessary context before starting to work on a task. For example, if you are generating a unit test or new code, make sure you understand the requirement, the naming conventions, frameworks and libraries used and aligned in the current codebase, and the environment and commands used to run and test the code etc. Always validate the new unit test at the end including running the code if possible for live feedback.
|
||||
Review each question carefully and answer it with detailed, accurate information.
|
||||
If you need more information, use one of the available tools or ask for clarification instead of making assumptions or lies.
|
||||
Review each question carefully and answer it with detailed, accurate information.`;
|
||||
|
||||
// The agent harness: env block, working guidelines (including the no-guessing
|
||||
// norm: use tools or ask instead of fabricating), tool-call loop contract,
|
||||
// completion instructions, and rules/metadata placeholders. Only the
|
||||
// {{AGENT_PERSONA}} slot holds the coding-agent identity and workflow
|
||||
// prompting; an agent profile body replaces that slot while the rest of the
|
||||
// harness is always preserved.
|
||||
const CLINE_SYSTEM_PROMPT_TEMPLATE = `{{AGENT_PERSONA}}
|
||||
|
||||
Environment you are running in:
|
||||
<env>
|
||||
@@ -13,6 +20,7 @@ Environment you are running in:
|
||||
</env>
|
||||
|
||||
Remember:
|
||||
- If you need more information, use one of the available tools or ask for clarification instead of making assumptions or lies.
|
||||
- Always adhere to existing code conventions and patterns.
|
||||
- Use only libraries and frameworks that are confirmed to be in use in the current codebase.
|
||||
- Provide complete and functional code without omissions or placeholders.
|
||||
@@ -33,6 +41,33 @@ If user asked a simple question without any coding context, answer it directly w
|
||||
{{CLINE_RULES}}
|
||||
{{CLINE_METADATA}}`;
|
||||
|
||||
/** The persona placeholder of the harness template. */
|
||||
export const AGENT_PERSONA_SLOT = "{{AGENT_PERSONA}}";
|
||||
|
||||
export interface ComposeClineSystemPromptInput {
|
||||
/**
|
||||
* Replaces the default Cline persona (the identity intro) while keeping the
|
||||
* agent harness. The working guidelines are part of the harness and are
|
||||
* always retained, even when a custom persona (e.g. an agent profile body)
|
||||
* is supplied.
|
||||
*/
|
||||
persona?: string;
|
||||
}
|
||||
|
||||
export function composeClineSystemPrompt(
|
||||
input: ComposeClineSystemPromptInput = {},
|
||||
): string {
|
||||
const persona = input.persona?.trim();
|
||||
// The persona is inserted via a replacer function so `{{...}}` and
|
||||
// `$&`-style sequences inside it stay literal.
|
||||
return CLINE_SYSTEM_PROMPT_TEMPLATE.replace(
|
||||
AGENT_PERSONA_SLOT,
|
||||
() => persona || DEFAULT_CLINE_PERSONA,
|
||||
);
|
||||
}
|
||||
|
||||
export const DEFAULT_CLINE_SYSTEM_PROMPT = composeClineSystemPrompt();
|
||||
|
||||
export const YOLO_CLINE_SYSTEM_PROMPT = `You are Cline, a careful and helpful coding agent that works in the background.
|
||||
You are tasked to solve an issue reported by the user who you cannot communicate with directly.
|
||||
Your goal is to utilize the tools at your disposal to investigate and answer the question according to user's instructions with the aim to verify that the issue is resolved.
|
||||
|
||||
Reference in New Issue
Block a user