deepcode-ai 1.1.29 → 1.1.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +127 -21
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -2256,6 +2256,9 @@ import { Effect as Effect9 } from "effect";
|
|
|
2256
2256
|
import { z as z10 } from "zod";
|
|
2257
2257
|
import { Effect as Effect10 } from "effect";
|
|
2258
2258
|
import { z as z11 } from "zod";
|
|
2259
|
+
import { Effect as Effect11 } from "effect";
|
|
2260
|
+
import { z as z12 } from "zod";
|
|
2261
|
+
import { zodToJsonSchema as zodToJsonSchema2 } from "zod-to-json-schema";
|
|
2259
2262
|
import path14 from "path";
|
|
2260
2263
|
import { readdir as readdir5, lstat as lstat3 } from "fs/promises";
|
|
2261
2264
|
var DeepCodeError = class extends Error {
|
|
@@ -3129,21 +3132,21 @@ function resolveTurnStrategy(input, mode, policy) {
|
|
|
3129
3132
|
intent
|
|
3130
3133
|
};
|
|
3131
3134
|
}
|
|
3132
|
-
if (
|
|
3135
|
+
if (intent.kind === "direct_utility") {
|
|
3133
3136
|
return {
|
|
3134
3137
|
allowTools: true,
|
|
3135
3138
|
shouldPlan: false,
|
|
3136
|
-
systemPrompt:
|
|
3137
|
-
kind: "
|
|
3139
|
+
systemPrompt: UTILITY_SYSTEM_PROMPT,
|
|
3140
|
+
kind: "utility",
|
|
3138
3141
|
intent
|
|
3139
3142
|
};
|
|
3140
3143
|
}
|
|
3141
|
-
if (
|
|
3144
|
+
if (mode === "plan") {
|
|
3142
3145
|
return {
|
|
3143
3146
|
allowTools: true,
|
|
3144
3147
|
shouldPlan: false,
|
|
3145
|
-
systemPrompt:
|
|
3146
|
-
kind: "
|
|
3148
|
+
systemPrompt: PLAN_SYSTEM_PROMPT,
|
|
3149
|
+
kind: "task",
|
|
3147
3150
|
intent
|
|
3148
3151
|
};
|
|
3149
3152
|
}
|
|
@@ -3682,24 +3685,25 @@ Execute this task using the available tools. Return a summary of what was done.`
|
|
|
3682
3685
|
*/
|
|
3683
3686
|
async executeTaskWithLLM(prompt, session, mode, options, taskType) {
|
|
3684
3687
|
const taskPrompt = this.createInternalPromptMessage(prompt);
|
|
3685
|
-
const allowedToolNames = this.allowedToolNamesForTaskType(mode, taskType);
|
|
3688
|
+
const allowedToolNames = this.allowedToolNamesForTaskType(mode, taskType, this.getRevealedTools(session));
|
|
3686
3689
|
const resolvedModel = session.model ?? resolveConfiguredModelForProvider(this.config, session.provider);
|
|
3687
3690
|
const toolProfile = resolveModelExecutionProfile(session.provider, resolvedModel);
|
|
3688
|
-
const toolDefinitions = this.toolDefinitionsForNames(allowedToolNames, toolProfile.toolSchemaMode);
|
|
3689
|
-
const textToolFallbackEnabled = toolDefinitions.length > 0 && toolProfile.toolCallStrategy !== "native";
|
|
3690
3691
|
const maxTaskIterations = 10;
|
|
3691
3692
|
let taskIterations = 0;
|
|
3692
3693
|
let finalAssistantText = "";
|
|
3693
3694
|
while (taskIterations < maxTaskIterations) {
|
|
3694
3695
|
taskIterations++;
|
|
3695
3696
|
this.enforceBudget(session.id);
|
|
3697
|
+
const toolDefinitions = this.toolDefinitionsForNames(allowedToolNames, toolProfile.toolSchemaMode);
|
|
3698
|
+
const textToolFallbackEnabled = toolDefinitions.length > 0 && toolProfile.toolCallStrategy !== "native";
|
|
3696
3699
|
const chunks = this.providerManager.chat(
|
|
3697
3700
|
this.messagesForSystemPrompt(
|
|
3698
3701
|
session,
|
|
3699
3702
|
this.systemPromptForMode(mode),
|
|
3700
3703
|
true,
|
|
3701
3704
|
[taskPrompt],
|
|
3702
|
-
textToolFallbackEnabled ? buildFallbackToolCallPrompt(allowedToolNames) : void 0
|
|
3705
|
+
textToolFallbackEnabled ? buildFallbackToolCallPrompt(allowedToolNames) : void 0,
|
|
3706
|
+
mode === "build" ? this.buildDeferredToolsHint(session) : void 0
|
|
3703
3707
|
),
|
|
3704
3708
|
{
|
|
3705
3709
|
preferredProvider: options.provider ?? session.provider,
|
|
@@ -3760,7 +3764,19 @@ ${assistantText}` : assistantText;
|
|
|
3760
3764
|
break;
|
|
3761
3765
|
}
|
|
3762
3766
|
for (const call of toolCalls) {
|
|
3763
|
-
const result = await this.executeTool(
|
|
3767
|
+
const result = await this.executeTool(
|
|
3768
|
+
call,
|
|
3769
|
+
session,
|
|
3770
|
+
mode,
|
|
3771
|
+
options.signal,
|
|
3772
|
+
allowedToolNames,
|
|
3773
|
+
options.onToolActivity,
|
|
3774
|
+
(names) => {
|
|
3775
|
+
for (const name of names) {
|
|
3776
|
+
if (this.tools.get(name)) allowedToolNames.add(name);
|
|
3777
|
+
}
|
|
3778
|
+
}
|
|
3779
|
+
);
|
|
3764
3780
|
this.sessions.addMessage(session.id, {
|
|
3765
3781
|
role: "tool",
|
|
3766
3782
|
source: "tool",
|
|
@@ -3781,12 +3797,15 @@ ${assistantText}` : assistantText;
|
|
|
3781
3797
|
const toolProfile = resolveModelExecutionProfile(session.provider, resolvedModel);
|
|
3782
3798
|
const baseAllowedToolNames = turnStrategy.allowTools ? this.allowedToolNamesForMode(mode) : /* @__PURE__ */ new Set();
|
|
3783
3799
|
const allowedToolNames = this.applyToolOverrides(baseAllowedToolNames, options);
|
|
3784
|
-
const
|
|
3785
|
-
|
|
3800
|
+
for (const name of this.getRevealedTools(session)) {
|
|
3801
|
+
if (this.tools.get(name)) allowedToolNames.add(name);
|
|
3802
|
+
}
|
|
3786
3803
|
while (iterations < maxIterations) {
|
|
3787
3804
|
iterations += 1;
|
|
3788
3805
|
options.onIteration?.(iterations, maxIterations);
|
|
3789
3806
|
this.enforceBudget(session.id);
|
|
3807
|
+
const toolDefinitions = turnStrategy.allowTools ? this.toolDefinitionsForNames(allowedToolNames, toolProfile.toolSchemaMode) : [];
|
|
3808
|
+
const textToolFallbackEnabled = toolDefinitions.length > 0 && toolProfile.toolCallStrategy !== "native";
|
|
3790
3809
|
await this.compressContextIfNeeded(session, turnStrategy.systemPrompt, options);
|
|
3791
3810
|
const chunks = this.providerManager.chat(
|
|
3792
3811
|
this.messagesForSystemPrompt(
|
|
@@ -3794,7 +3813,8 @@ ${assistantText}` : assistantText;
|
|
|
3794
3813
|
turnStrategy.systemPrompt,
|
|
3795
3814
|
turnStrategy.allowTools,
|
|
3796
3815
|
[],
|
|
3797
|
-
textToolFallbackEnabled ? buildFallbackToolCallPrompt(allowedToolNames) : void 0
|
|
3816
|
+
textToolFallbackEnabled ? buildFallbackToolCallPrompt(allowedToolNames) : void 0,
|
|
3817
|
+
mode === "build" ? this.buildDeferredToolsHint(session) : void 0
|
|
3798
3818
|
),
|
|
3799
3819
|
{
|
|
3800
3820
|
preferredProvider: options.provider ?? session.provider,
|
|
@@ -3860,7 +3880,19 @@ ${assistantText}` : assistantText;
|
|
|
3860
3880
|
}
|
|
3861
3881
|
if (toolCalls.length === 0) break;
|
|
3862
3882
|
for (const call of toolCalls) {
|
|
3863
|
-
const result = await this.executeTool(
|
|
3883
|
+
const result = await this.executeTool(
|
|
3884
|
+
call,
|
|
3885
|
+
session,
|
|
3886
|
+
mode,
|
|
3887
|
+
options.signal,
|
|
3888
|
+
allowedToolNames,
|
|
3889
|
+
options.onToolActivity,
|
|
3890
|
+
(names) => {
|
|
3891
|
+
for (const name of names) {
|
|
3892
|
+
if (this.tools.get(name)) allowedToolNames.add(name);
|
|
3893
|
+
}
|
|
3894
|
+
}
|
|
3895
|
+
);
|
|
3864
3896
|
this.sessions.addMessage(session.id, {
|
|
3865
3897
|
role: "tool",
|
|
3866
3898
|
source: "tool",
|
|
@@ -3890,7 +3922,7 @@ ${assistantText}` : assistantText;
|
|
|
3890
3922
|
}
|
|
3891
3923
|
return { path: entry.path, restored: true };
|
|
3892
3924
|
}
|
|
3893
|
-
async executeTool(call, session, mode, signal, allowedToolNames = this.allowedToolNamesForMode(mode), onToolActivity) {
|
|
3925
|
+
async executeTool(call, session, mode, signal, allowedToolNames = this.allowedToolNamesForMode(mode), onToolActivity, onRevealTools) {
|
|
3894
3926
|
if (!this.isToolAllowed(call.name, mode)) {
|
|
3895
3927
|
const modeHint = mode === "plan" ? "Switch to BUILD mode (press Tab in the TUI) to enable this tool." : "";
|
|
3896
3928
|
return {
|
|
@@ -3948,6 +3980,12 @@ ${assistantText}` : assistantText;
|
|
|
3948
3980
|
const stack = this.undoStacks.get(session.id) ?? [];
|
|
3949
3981
|
stack.push({ path: filePath, previousContent });
|
|
3950
3982
|
this.undoStacks.set(session.id, stack);
|
|
3983
|
+
},
|
|
3984
|
+
revealTools: (names) => {
|
|
3985
|
+
const current = this.getRevealedTools(session);
|
|
3986
|
+
session.metadata.revealedTools = [.../* @__PURE__ */ new Set([...current, ...names])];
|
|
3987
|
+
this.sessions.save(session);
|
|
3988
|
+
onRevealTools?.(names);
|
|
3951
3989
|
}
|
|
3952
3990
|
};
|
|
3953
3991
|
try {
|
|
@@ -4032,9 +4070,23 @@ ${assistantText}` : assistantText;
|
|
|
4032
4070
|
}
|
|
4033
4071
|
allowedToolNamesForMode(mode) {
|
|
4034
4072
|
return new Set(
|
|
4035
|
-
this.tools.list().filter((tool) => this.isToolAllowed(tool.name, mode)).map((tool) => tool.name)
|
|
4073
|
+
this.tools.list().filter((tool) => this.isToolAllowed(tool.name, mode) && !tool.deferred).map((tool) => tool.name)
|
|
4036
4074
|
);
|
|
4037
4075
|
}
|
|
4076
|
+
getRevealedTools(session) {
|
|
4077
|
+
return Array.isArray(session.metadata.revealedTools) ? session.metadata.revealedTools : [];
|
|
4078
|
+
}
|
|
4079
|
+
buildDeferredToolsHint(session) {
|
|
4080
|
+
const deferred = this.tools.listDeferred();
|
|
4081
|
+
if (deferred.length === 0) return void 0;
|
|
4082
|
+
const revealed = new Set(this.getRevealedTools(session));
|
|
4083
|
+
const unrevealed = deferred.filter((t2) => !revealed.has(t2.name));
|
|
4084
|
+
if (unrevealed.length === 0) return void 0;
|
|
4085
|
+
return [
|
|
4086
|
+
"Deferred tools (not in schema \u2014 call tool_search with a keyword to activate):",
|
|
4087
|
+
...unrevealed.map((t2) => `- ${t2.name}: ${t2.description.slice(0, 100)}`)
|
|
4088
|
+
].join("\n");
|
|
4089
|
+
}
|
|
4038
4090
|
applyToolOverrides(base, options) {
|
|
4039
4091
|
if (!options.allowedTools && !options.disallowedTools) return base;
|
|
4040
4092
|
let names = options.allowedTools ? new Set(options.allowedTools) : new Set(base);
|
|
@@ -4043,10 +4095,14 @@ ${assistantText}` : assistantText;
|
|
|
4043
4095
|
}
|
|
4044
4096
|
return new Set([...names].filter((n) => base.has(n)));
|
|
4045
4097
|
}
|
|
4046
|
-
allowedToolNamesForTaskType(mode, taskType) {
|
|
4098
|
+
allowedToolNamesForTaskType(mode, taskType, revealedTools) {
|
|
4047
4099
|
if (taskType === "research") return /* @__PURE__ */ new Set([...PLAN_ALLOWED_TOOLS]);
|
|
4048
4100
|
if (taskType === "verify") return /* @__PURE__ */ new Set(["read_file", "list_dir", "analyze_code", "search_text", "bash"]);
|
|
4049
|
-
|
|
4101
|
+
const base = this.allowedToolNamesForMode(mode);
|
|
4102
|
+
for (const name of revealedTools ?? []) {
|
|
4103
|
+
if (this.tools.get(name)) base.add(name);
|
|
4104
|
+
}
|
|
4105
|
+
return base;
|
|
4050
4106
|
}
|
|
4051
4107
|
toolDefinitionsForNames(names, schemaMode = "full") {
|
|
4052
4108
|
return this.tools.list().filter((tool) => names.has(tool.name)).map((tool) => ({
|
|
@@ -4071,7 +4127,7 @@ ${assistantText}` : assistantText;
|
|
|
4071
4127
|
systemPromptForMode(mode) {
|
|
4072
4128
|
return mode === "plan" ? PLAN_SYSTEM_PROMPT : BUILD_SYSTEM_PROMPT;
|
|
4073
4129
|
}
|
|
4074
|
-
messagesForSystemPrompt(session, systemPrompt, toolsEnabled, extraMessages = [], fallbackToolPrompt) {
|
|
4130
|
+
messagesForSystemPrompt(session, systemPrompt, toolsEnabled, extraMessages = [], fallbackToolPrompt, deferredToolsHint) {
|
|
4075
4131
|
return [
|
|
4076
4132
|
{
|
|
4077
4133
|
id: "mode_system",
|
|
@@ -4085,6 +4141,12 @@ ${assistantText}` : assistantText;
|
|
|
4085
4141
|
content: this.runtimeContextPrompt(session, toolsEnabled),
|
|
4086
4142
|
createdAt: session.createdAt
|
|
4087
4143
|
},
|
|
4144
|
+
...deferredToolsHint ? [{
|
|
4145
|
+
id: "deferred_tools_system",
|
|
4146
|
+
role: "system",
|
|
4147
|
+
content: deferredToolsHint,
|
|
4148
|
+
createdAt: session.createdAt
|
|
4149
|
+
}] : [],
|
|
4088
4150
|
...fallbackToolPrompt ? [{
|
|
4089
4151
|
id: "tool_fallback_system",
|
|
4090
4152
|
role: "system",
|
|
@@ -4492,6 +4554,9 @@ var ToolRegistry = class {
|
|
|
4492
4554
|
list() {
|
|
4493
4555
|
return [...this.tools.values()];
|
|
4494
4556
|
}
|
|
4557
|
+
listDeferred() {
|
|
4558
|
+
return [...this.tools.values()].filter((t2) => t2.deferred);
|
|
4559
|
+
}
|
|
4495
4560
|
descriptions() {
|
|
4496
4561
|
return this.list().map((tool) => `- ${tool.name}: ${tool.description}`).join("\n");
|
|
4497
4562
|
}
|
|
@@ -4502,6 +4567,7 @@ function adaptMcpTool(client, tool, serverName) {
|
|
|
4502
4567
|
name: qualifiedName,
|
|
4503
4568
|
description: tool.description ?? tool.name,
|
|
4504
4569
|
parameters: z22.record(z22.unknown()).default({}),
|
|
4570
|
+
deferred: true,
|
|
4505
4571
|
execute: (args) => Effect3.tryPromise({
|
|
4506
4572
|
try: () => client.callTool(tool.name, args),
|
|
4507
4573
|
catch: (e) => e instanceof Error ? e : new Error(String(e))
|
|
@@ -7750,6 +7816,45 @@ function createTaskTool(subagents, worktree) {
|
|
|
7750
7816
|
})
|
|
7751
7817
|
});
|
|
7752
7818
|
}
|
|
7819
|
+
function createToolSearchTool(registry) {
|
|
7820
|
+
return defineTool({
|
|
7821
|
+
name: "tool_search",
|
|
7822
|
+
description: "Search and activate deferred tools (MCP integrations) by name or description keyword. Call this before using a tool that is not in the current schema. Matched tools are revealed and available in subsequent calls this session.",
|
|
7823
|
+
parameters: z12.object({
|
|
7824
|
+
query: z12.string().min(1).describe("Keyword to search in tool names and descriptions")
|
|
7825
|
+
}),
|
|
7826
|
+
execute: (args, context) => Effect11.tryPromise({
|
|
7827
|
+
try: async () => {
|
|
7828
|
+
const query = args.query.toLowerCase();
|
|
7829
|
+
const deferred = registry.listDeferred();
|
|
7830
|
+
if (deferred.length === 0) {
|
|
7831
|
+
return "No deferred tools are configured. Add MCP servers in .deepcode/config.json to enable integrations.";
|
|
7832
|
+
}
|
|
7833
|
+
const matches = deferred.filter(
|
|
7834
|
+
(t2) => t2.name.toLowerCase().includes(query) || t2.description.toLowerCase().includes(query)
|
|
7835
|
+
);
|
|
7836
|
+
if (matches.length === 0) {
|
|
7837
|
+
const available = deferred.map((t2) => `- ${t2.name}: ${t2.description.slice(0, 100)}`).join("\n");
|
|
7838
|
+
return `No deferred tools match "${args.query}".
|
|
7839
|
+
|
|
7840
|
+
All available deferred tools:
|
|
7841
|
+
${available}`;
|
|
7842
|
+
}
|
|
7843
|
+
context.revealTools?.(matches.map((t2) => t2.name));
|
|
7844
|
+
const schemas = matches.map((t2) => ({
|
|
7845
|
+
name: t2.name,
|
|
7846
|
+
description: t2.description,
|
|
7847
|
+
parameters: zodToJsonSchema2(t2.parameters, { target: "jsonSchema7" })
|
|
7848
|
+
}));
|
|
7849
|
+
return [
|
|
7850
|
+
`Revealed ${matches.length} tool(s) \u2014 available for calls in this session:`,
|
|
7851
|
+
JSON.stringify(schemas, null, 2)
|
|
7852
|
+
].join("\n\n");
|
|
7853
|
+
},
|
|
7854
|
+
catch: (e) => e instanceof Error ? e : new Error(String(e))
|
|
7855
|
+
})
|
|
7856
|
+
});
|
|
7857
|
+
}
|
|
7753
7858
|
var PROJECT_MARKER2 = ".git";
|
|
7754
7859
|
var SKIP_DIRS = /* @__PURE__ */ new Set([
|
|
7755
7860
|
".git",
|
|
@@ -9912,6 +10017,7 @@ async function createRuntime(options) {
|
|
|
9912
10017
|
tools.register(tool);
|
|
9913
10018
|
}
|
|
9914
10019
|
}
|
|
10020
|
+
tools.register(createToolSearchTool(tools));
|
|
9915
10021
|
const agent = new Agent(
|
|
9916
10022
|
providers,
|
|
9917
10023
|
tools,
|
|
@@ -28163,7 +28269,7 @@ function parseVersion2(version) {
|
|
|
28163
28269
|
if (!match) return null;
|
|
28164
28270
|
return [Number(match[1]), Number(match[2]), Number(match[3])];
|
|
28165
28271
|
}
|
|
28166
|
-
var VERSION = "1.1.
|
|
28272
|
+
var VERSION = "1.1.31".length > 0 ? "1.1.31" : "0.0.0-dev";
|
|
28167
28273
|
var updateCommand = {
|
|
28168
28274
|
name: "update",
|
|
28169
28275
|
description: "Check published DeepCode versions",
|