Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions extensions/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,6 @@ addCommonOptions(program)
)
.option("--resume", "Resume from last session")
.option("--fork <sessionId>", "Fork from an existing session ID")
.option(
"--beta-subagent-tool",
"Enable beta Subagent tool for invoking subagents",
)
.action(async (prompt, options) => {
// Telemetry: record command invocation
await posthogService.capture("cliCommand", { command: "cn" });
Expand Down
8 changes: 1 addition & 7 deletions extensions/cli/src/services/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { loadAuthConfig } from "../auth/workos.js";
import { initializeWithOnboarding } from "../onboarding.js";
import {
setBetaSubagentToolEnabled,
setBetaUploadArtifactToolEnabled,
} from "../tools/toolsConfig.js";
import { setBetaUploadArtifactToolEnabled } from "../tools/toolsConfig.js";
import { logger } from "../util/logger.js";

import { AgentFileService } from "./AgentFileService.js";
Expand Down Expand Up @@ -67,9 +64,6 @@ export async function initializeServices(initOptions: ServiceInitOptions = {}) {
if (commandOptions.betaUploadArtifactTool) {
setBetaUploadArtifactToolEnabled(true);
}
if (commandOptions.betaSubagentTool) {
setBetaSubagentToolEnabled(true);
}
// Handle onboarding for TUI mode (headless: false) unless explicitly skipped
if (!initOptions.headless && !initOptions.skipOnboarding) {
const authConfig = loadAuthConfig();
Expand Down
32 changes: 30 additions & 2 deletions extensions/cli/src/stream/handleToolCalls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,41 @@ export async function handleToolCalls(

// Execute the valid preprocessed tool calls
// Note: executeStreamedToolCalls adds tool results to toolCallStates via
// services.chatHistory.addToolResult() internally
const { hasRejection } = await executeStreamedToolCalls(
// services.chatHistory.addToolResult() internally when service is available
const { hasRejection, chatHistoryEntries } = await executeStreamedToolCalls(
preprocessedCalls,
callbacks,
isHeadless,
);

// When ChatHistoryService is disabled in subagent execution,
// manually update the local chatHistory array with tool results
if (!useService && chatHistoryEntries.length > 0) {
const lastAssistantIndex = chatHistory.findLastIndex(
(item) => item.message.role === "assistant" && item.toolCallStates,
);
if (
lastAssistantIndex >= 0 &&
chatHistory[lastAssistantIndex].toolCallStates
) {
for (const entry of chatHistoryEntries) {
const toolState = chatHistory[lastAssistantIndex].toolCallStates!.find(
(ts) => ts.toolCallId === entry.tool_call_id,
);
if (toolState) {
toolState.status = entry.status;
toolState.output = [
{
content: String(entry.content) || "",
name: "Tool Result",
description: "Tool execution result",
},
];
}
}
}
}

if (isHeadless && hasRejection) {
logger.debug(
"Tool call rejected in headless mode - returning current content",
Expand Down
86 changes: 86 additions & 0 deletions extensions/cli/src/subagent/builtInSubagents.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import type { ModelConfig } from "@continuedev/config-yaml";

import { logger } from "src/util/logger.js";

export interface BuiltInSubagent {
name: string;
systemPrompt: string;
model: string;
}

export const NAVIGATOR_SUBAGENT: BuiltInSubagent = {
name: "navigator",
model: "claude-haiku-4-5",
systemPrompt: `You are a Codebase Navigator subagent specialized in exploring, searching, and mapping large codebases.

When to use:

Use this subagent whenever you need to explore or find or understand a codebase or a folder.

When navigating a codebase, you will:

1. **Locate Relevant Code**: Use file and code search tools to find the most relevant files, modules, functions, and types. Prefer a small, high-signal set of locations over exhaustive listings.

2. **Trace Behavior and Dependencies**: Follow call chains, imports, and data flow to understand how the relevant pieces interact, including upstream/downstream dependencies and important side effects.

3. **Map the Codebase for Others**: Build a concise mental map: which components are core, which are helpers, where entry points live, and how configuration or environment affects behavior.

Your output should be concise and actionable, starting with a brief summary of what you found and listing the key files/paths, functions, symbols, and important relationships or flows between them in plain language. If you cannot find something, describe what you searched for, where you looked, and suggest next places or strategies to investigate.`,
};

export const GENERALIST_SUBAGENT: BuiltInSubagent = {
name: "general-tasker",
model: "claude-sonnet-4-6",
systemPrompt: `You are a Generalist subagent capable of handling any development task delegated to you.

When to use:

Use this subagent for any task that doesn't require a specialized subagent, including but not limited to: implementing features, fixing bugs, refactoring, code review, documentation, research, debugging, and analysis.

When handling a task, you will:

1. **Interpret the Request**: Understand what is being asked, whether it's exploration, implementation, review, analysis, or something else entirely. Adapt your approach based on the nature of the task.

2. **Gather Context**: Use available tools to explore the codebase, read relevant files, and understand the surrounding architecture before taking action or forming conclusions.

3. **Communicate Results**: Provide clear, actionable output tailored to the task. Summarize what you did or discovered, highlight key insights or changes, and note any open questions or recommended next steps.

You are flexible and resourceful. If a task is ambiguous, make reasonable assumptions and state them. If you encounter blockers, describe what you attempted and suggest alternatives.`,
};

export const BUILT_IN_SUBAGENTS: BuiltInSubagent[] = [
NAVIGATOR_SUBAGENT,
GENERALIST_SUBAGENT,
];

export function createBuiltInSubagentModel(
subagent: BuiltInSubagent,
baseModel: ModelConfig,
): ModelConfig {
return {
...baseModel,
name: subagent.name,
model: subagent.model,
roles: ["subagent"],
chatOptions: {
...baseModel.chatOptions,
baseSystemMessage: subagent.systemPrompt,
},
};
}

export function isLocalAnthropicModel(model: ModelConfig | null): boolean {
if (!model) {
return false;
}

const isAnthropic = model.provider === "anthropic";
const hasDirectApiKey =
typeof model.apiKey === "string" && model.apiKey.length > 0;

logger.debug("subagent_enabled_for_anthropic", {
enabled: isAnthropic && hasDirectApiKey,
});

return isAnthropic && hasDirectApiKey;
}
15 changes: 14 additions & 1 deletion extensions/cli/src/subagent/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { streamChatResponse } from "../stream/streamChatResponse.js";
import { escapeEvents } from "../util/cli.js";
import { logger } from "../util/logger.js";

let isInsideSubagent = false;

/**
* Options for executing a subagent
*/
Expand Down Expand Up @@ -54,17 +56,26 @@ async function buildAgentSystemMessage(
/**
* Execute a subagent in a child session
*/
// eslint-disable-next-line complexity
export async function executeSubAgent(
options: SubAgentExecutionOptions,
): Promise<SubAgentResult> {
if (isInsideSubagent) {
return {
success: false,
response: "",
error: "Nested subagent invocation is not allowed",
};
}

const { agent: subAgent, prompt, abortController, onOutputUpdate } = options;

const mainAgentPermissionsState =
await serviceContainer.get<ToolPermissionServiceState>(
SERVICE_NAMES.TOOL_PERMISSIONS,
);

isInsideSubagent = true;

try {
logger.debug("Starting subagent execution", {
agent: subAgent.model?.name,
Expand Down Expand Up @@ -209,5 +220,7 @@ export async function executeSubAgent(
response: "",
error: error.message,
};
} finally {
isInsideSubagent = false;
}
}
40 changes: 0 additions & 40 deletions extensions/cli/src/subagent/get-agents.ts

This file was deleted.

65 changes: 65 additions & 0 deletions extensions/cli/src/subagent/getAgents.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { createLlmApi } from "../config.js";
import { ModelService } from "../services/ModelService.js";
import type { ModelServiceState } from "../services/types.js";

import {
BUILT_IN_SUBAGENTS,
createBuiltInSubagentModel,
isLocalAnthropicModel,
} from "./builtInSubagents.js";

function getAllSubagentModels(modelState: ModelServiceState) {
const configSubagents = ModelService.getSubagentModels(modelState);

if (!isLocalAnthropicModel(modelState.model)) {
return configSubagents;
}

const builtInSubagents = BUILT_IN_SUBAGENTS.map((subagent) => {
const subagentModel = createBuiltInSubagentModel(
subagent,
modelState.model!,
);
return {
llmApi: createLlmApi(subagentModel, modelState.authConfig),
model: subagentModel,
assistant: modelState.assistant,
authConfig: modelState.authConfig,
};
});

return [...configSubagents, ...builtInSubagents];
}

export function getSubagent(modelState: ModelServiceState, name: string) {
return (
getAllSubagentModels(modelState).find(
(model) => model.model.name === name,
) ?? null
);
}

export function generateSubagentToolDescription(
modelState: ModelServiceState,
): string {
const agentList = getAllSubagentModels(modelState)
.map(
(subagentModel) =>
` - ${subagentModel.model.name}: ${subagentModel.model.chatOptions?.baseSystemMessage}`,
)
.join("\n");

return `Launch an autonomous specialized subagent to handle a specific task.

You have the independence to make decisions within you scope. You should focus on the specific task given by the main agent.

Remember: You are part of a larger system. Your specialized focus helps the main agent handle multiple concerns efficiently.

Here are the available subagents:
${agentList}
`;
}

export function getAgentNames(modelState: ModelServiceState): string[] {
return getAllSubagentModels(modelState).map((model) => model.model.name);
}
9 changes: 2 additions & 7 deletions extensions/cli/src/tools/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@ import { runTerminalCommandTool } from "./runTerminalCommand.js";
import { checkIfRipgrepIsInstalled, searchCodeTool } from "./searchCode.js";
import { skillsTool } from "./skills.js";
import { subagentTool } from "./subagent.js";
import {
isBetaSubagentToolEnabled,
isBetaUploadArtifactToolEnabled,
} from "./toolsConfig.js";
import { isBetaUploadArtifactToolEnabled } from "./toolsConfig.js";
import {
type Tool,
type ToolCall,
Expand Down Expand Up @@ -129,9 +126,7 @@ export async function getAllAvailableTools(
tools.push(exitTool);
}

if (isBetaSubagentToolEnabled()) {
tools.push(await subagentTool());
}
tools.push(await subagentTool());

tools.push(await skillsTool());

Expand Down
2 changes: 1 addition & 1 deletion extensions/cli/src/tools/subagent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { services } from "../services/index.js";
import { serviceContainer } from "../services/ServiceContainer.js";
import { executeSubAgent } from "../subagent/executor.js";
import { getAgentNames, getSubagent } from "../subagent/get-agents.js";
import { getAgentNames, getSubagent } from "../subagent/getAgents.js";
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Mock path no longer matches the imported module path, so getAgentNames/getSubagent won’t be mocked and vi.mocked(...).mockReturnValue may fail or run real logic.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At extensions/cli/src/tools/subagent.test.ts, line 6:

<comment>Mock path no longer matches the imported module path, so getAgentNames/getSubagent won’t be mocked and vi.mocked(...).mockReturnValue may fail or run real logic.</comment>

<file context>
@@ -3,7 +3,7 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
 import { serviceContainer } from "../services/ServiceContainer.js";
 import { executeSubAgent } from "../subagent/executor.js";
-import { getAgentNames, getSubagent } from "../subagent/get-agents.js";
+import { getAgentNames, getSubagent } from "../subagent/getAgents.js";
 
 import { subagentTool } from "./subagent.js";
</file context>
Fix with Cubic


import { subagentTool } from "./subagent.js";

Expand Down Expand Up @@ -32,7 +32,7 @@
});

it("preprocess throws when agent is not found", async () => {
vi.mocked(getAgentNames).mockReturnValue(["code-agent"]);

Check failure on line 35 in extensions/cli/src/tools/subagent.test.ts

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 20)

src/tools/subagent.test.ts > subagentTool > preprocess throws when agent is not found

TypeError: vi.mocked(...).mockReturnValue is not a function ❯ src/tools/subagent.test.ts:35:30

Check failure on line 35 in extensions/cli/src/tools/subagent.test.ts

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 22)

src/tools/subagent.test.ts > subagentTool > preprocess throws when agent is not found

TypeError: vi.mocked(...).mockReturnValue is not a function ❯ src/tools/subagent.test.ts:35:30

Check failure on line 35 in extensions/cli/src/tools/subagent.test.ts

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 18)

src/tools/subagent.test.ts > subagentTool > preprocess throws when agent is not found

TypeError: vi.mocked(...).mockReturnValue is not a function ❯ src/tools/subagent.test.ts:35:30

Check failure on line 35 in extensions/cli/src/tools/subagent.test.ts

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 24)

src/tools/subagent.test.ts > subagentTool > preprocess throws when agent is not found

TypeError: vi.mocked(...).mockReturnValue is not a function ❯ src/tools/subagent.test.ts:35:30

Check failure on line 35 in extensions/cli/src/tools/subagent.test.ts

View workflow job for this annotation

GitHub Actions / test (macos-latest, 18)

src/tools/subagent.test.ts > subagentTool > preprocess throws when agent is not found

TypeError: vi.mocked(...).mockReturnValue is not a function ❯ src/tools/subagent.test.ts:35:30

Check failure on line 35 in extensions/cli/src/tools/subagent.test.ts

View workflow job for this annotation

GitHub Actions / test (macos-latest, 20)

src/tools/subagent.test.ts > subagentTool > preprocess throws when agent is not found

TypeError: vi.mocked(...).mockReturnValue is not a function ❯ src/tools/subagent.test.ts:35:30

Check failure on line 35 in extensions/cli/src/tools/subagent.test.ts

View workflow job for this annotation

GitHub Actions / test (windows-latest, 18)

src/tools/subagent.test.ts > subagentTool > preprocess throws when agent is not found

TypeError: vi.mocked(...).mockReturnValue is not a function ❯ src/tools/subagent.test.ts:35:30

Check failure on line 35 in extensions/cli/src/tools/subagent.test.ts

View workflow job for this annotation

GitHub Actions / test (windows-latest, 24)

src/tools/subagent.test.ts > subagentTool > preprocess throws when agent is not found

TypeError: vi.mocked(...).mockReturnValue is not a function ❯ src/tools/subagent.test.ts:35:30

Check failure on line 35 in extensions/cli/src/tools/subagent.test.ts

View workflow job for this annotation

GitHub Actions / test (windows-latest, 20)

src/tools/subagent.test.ts > subagentTool > preprocess throws when agent is not found

TypeError: vi.mocked(...).mockReturnValue is not a function ❯ src/tools/subagent.test.ts:35:30

const tool = await subagentTool();

Expand All @@ -52,7 +52,7 @@
});

it("preprocess includes agent model name when agent exists", async () => {
vi.mocked(getAgentNames).mockReturnValue(["code-agent"]);

Check failure on line 55 in extensions/cli/src/tools/subagent.test.ts

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 20)

src/tools/subagent.test.ts > subagentTool > preprocess includes agent model name when agent exists

TypeError: vi.mocked(...).mockReturnValue is not a function ❯ src/tools/subagent.test.ts:55:30

Check failure on line 55 in extensions/cli/src/tools/subagent.test.ts

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 22)

src/tools/subagent.test.ts > subagentTool > preprocess includes agent model name when agent exists

TypeError: vi.mocked(...).mockReturnValue is not a function ❯ src/tools/subagent.test.ts:55:30

Check failure on line 55 in extensions/cli/src/tools/subagent.test.ts

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 18)

src/tools/subagent.test.ts > subagentTool > preprocess includes agent model name when agent exists

TypeError: vi.mocked(...).mockReturnValue is not a function ❯ src/tools/subagent.test.ts:55:30

Check failure on line 55 in extensions/cli/src/tools/subagent.test.ts

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 24)

src/tools/subagent.test.ts > subagentTool > preprocess includes agent model name when agent exists

TypeError: vi.mocked(...).mockReturnValue is not a function ❯ src/tools/subagent.test.ts:55:30

Check failure on line 55 in extensions/cli/src/tools/subagent.test.ts

View workflow job for this annotation

GitHub Actions / test (macos-latest, 18)

src/tools/subagent.test.ts > subagentTool > preprocess includes agent model name when agent exists

TypeError: vi.mocked(...).mockReturnValue is not a function ❯ src/tools/subagent.test.ts:55:30

Check failure on line 55 in extensions/cli/src/tools/subagent.test.ts

View workflow job for this annotation

GitHub Actions / test (macos-latest, 20)

src/tools/subagent.test.ts > subagentTool > preprocess includes agent model name when agent exists

TypeError: vi.mocked(...).mockReturnValue is not a function ❯ src/tools/subagent.test.ts:55:30

Check failure on line 55 in extensions/cli/src/tools/subagent.test.ts

View workflow job for this annotation

GitHub Actions / test (windows-latest, 18)

src/tools/subagent.test.ts > subagentTool > preprocess includes agent model name when agent exists

TypeError: vi.mocked(...).mockReturnValue is not a function ❯ src/tools/subagent.test.ts:55:30

Check failure on line 55 in extensions/cli/src/tools/subagent.test.ts

View workflow job for this annotation

GitHub Actions / test (windows-latest, 24)

src/tools/subagent.test.ts > subagentTool > preprocess includes agent model name when agent exists

TypeError: vi.mocked(...).mockReturnValue is not a function ❯ src/tools/subagent.test.ts:55:30

Check failure on line 55 in extensions/cli/src/tools/subagent.test.ts

View workflow job for this annotation

GitHub Actions / test (windows-latest, 20)

src/tools/subagent.test.ts > subagentTool > preprocess includes agent model name when agent exists

TypeError: vi.mocked(...).mockReturnValue is not a function ❯ src/tools/subagent.test.ts:55:30

const tool = await subagentTool();

Expand Down Expand Up @@ -81,7 +81,7 @@
});

it("run executes subagent and returns formatted output", async () => {
vi.mocked(getAgentNames).mockReturnValue(["code-agent"]);

Check failure on line 84 in extensions/cli/src/tools/subagent.test.ts

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 20)

src/tools/subagent.test.ts > subagentTool > run executes subagent and returns formatted output

TypeError: vi.mocked(...).mockReturnValue is not a function ❯ src/tools/subagent.test.ts:84:30

Check failure on line 84 in extensions/cli/src/tools/subagent.test.ts

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 22)

src/tools/subagent.test.ts > subagentTool > run executes subagent and returns formatted output

TypeError: vi.mocked(...).mockReturnValue is not a function ❯ src/tools/subagent.test.ts:84:30

Check failure on line 84 in extensions/cli/src/tools/subagent.test.ts

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 18)

src/tools/subagent.test.ts > subagentTool > run executes subagent and returns formatted output

TypeError: vi.mocked(...).mockReturnValue is not a function ❯ src/tools/subagent.test.ts:84:30

Check failure on line 84 in extensions/cli/src/tools/subagent.test.ts

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 24)

src/tools/subagent.test.ts > subagentTool > run executes subagent and returns formatted output

TypeError: vi.mocked(...).mockReturnValue is not a function ❯ src/tools/subagent.test.ts:84:30

Check failure on line 84 in extensions/cli/src/tools/subagent.test.ts

View workflow job for this annotation

GitHub Actions / test (macos-latest, 18)

src/tools/subagent.test.ts > subagentTool > run executes subagent and returns formatted output

TypeError: vi.mocked(...).mockReturnValue is not a function ❯ src/tools/subagent.test.ts:84:30

Check failure on line 84 in extensions/cli/src/tools/subagent.test.ts

View workflow job for this annotation

GitHub Actions / test (macos-latest, 20)

src/tools/subagent.test.ts > subagentTool > run executes subagent and returns formatted output

TypeError: vi.mocked(...).mockReturnValue is not a function ❯ src/tools/subagent.test.ts:84:30

Check failure on line 84 in extensions/cli/src/tools/subagent.test.ts

View workflow job for this annotation

GitHub Actions / test (windows-latest, 18)

src/tools/subagent.test.ts > subagentTool > run executes subagent and returns formatted output

TypeError: vi.mocked(...).mockReturnValue is not a function ❯ src/tools/subagent.test.ts:84:30

Check failure on line 84 in extensions/cli/src/tools/subagent.test.ts

View workflow job for this annotation

GitHub Actions / test (windows-latest, 24)

src/tools/subagent.test.ts > subagentTool > run executes subagent and returns formatted output

TypeError: vi.mocked(...).mockReturnValue is not a function ❯ src/tools/subagent.test.ts:84:30

Check failure on line 84 in extensions/cli/src/tools/subagent.test.ts

View workflow job for this annotation

GitHub Actions / test (windows-latest, 20)

src/tools/subagent.test.ts > subagentTool > run executes subagent and returns formatted output

TypeError: vi.mocked(...).mockReturnValue is not a function ❯ src/tools/subagent.test.ts:84:30
vi.mocked(getSubagent).mockReturnValue({
model: { name: "test-model" },
} as any);
Expand Down
2 changes: 1 addition & 1 deletion extensions/cli/src/tools/subagent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
generateSubagentToolDescription,
getSubagent,
getAgentNames as getSubagentNames,
} from "../subagent/get-agents.js";
} from "../subagent/getAgents.js";
import { SUBAGENT_TOOL_META } from "../subagent/index.js";
import { logger } from "../util/logger.js";

Expand Down
9 changes: 0 additions & 9 deletions extensions/cli/src/tools/toolsConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*/

let betaUploadArtifactToolEnabled = false;
let betaSubagentToolEnabled = false;

export function setBetaUploadArtifactToolEnabled(enabled: boolean): void {
betaUploadArtifactToolEnabled = enabled;
Expand All @@ -13,11 +12,3 @@ export function setBetaUploadArtifactToolEnabled(enabled: boolean): void {
export function isBetaUploadArtifactToolEnabled(): boolean {
return betaUploadArtifactToolEnabled;
}

export function setBetaSubagentToolEnabled(enabled: boolean): void {
betaSubagentToolEnabled = enabled;
}

export function isBetaSubagentToolEnabled(): boolean {
return betaSubagentToolEnabled;
}
Loading