wave-agent-sdk 0.11.6 → 0.11.7
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/builtin/skills/init/SKILL.md +2 -0
- package/builtin/skills/settings/SKILLS.md +3 -2
- package/builtin/skills/settings/SUBAGENTS.md +1 -3
- package/dist/agent.d.ts +6 -0
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +18 -1
- package/dist/constants/tools.d.ts +1 -1
- package/dist/constants/tools.d.ts.map +1 -1
- package/dist/constants/tools.js +1 -1
- package/dist/managers/MemoryRuleManager.d.ts.map +1 -1
- package/dist/managers/MemoryRuleManager.js +1 -9
- package/dist/managers/aiManager.d.ts.map +1 -1
- package/dist/managers/aiManager.js +22 -3
- package/dist/managers/messageManager.d.ts +13 -5
- package/dist/managers/messageManager.d.ts.map +1 -1
- package/dist/managers/messageManager.js +62 -34
- package/dist/managers/pluginManager.d.ts.map +1 -1
- package/dist/managers/pluginManager.js +4 -2
- package/dist/managers/slashCommandManager.d.ts +2 -0
- package/dist/managers/slashCommandManager.d.ts.map +1 -1
- package/dist/managers/slashCommandManager.js +98 -4
- package/dist/managers/toolManager.d.ts.map +1 -1
- package/dist/managers/toolManager.js +8 -2
- package/dist/prompts/index.d.ts +2 -0
- package/dist/prompts/index.d.ts.map +1 -1
- package/dist/prompts/index.js +5 -0
- package/dist/services/GitService.d.ts +1 -0
- package/dist/services/GitService.d.ts.map +1 -1
- package/dist/services/GitService.js +16 -0
- package/dist/services/MarketplaceService.d.ts +7 -0
- package/dist/services/MarketplaceService.d.ts.map +1 -1
- package/dist/services/MarketplaceService.js +321 -252
- package/dist/services/aiService.d.ts +34 -0
- package/dist/services/aiService.d.ts.map +1 -1
- package/dist/services/aiService.js +124 -1
- package/dist/services/initializationService.d.ts.map +1 -1
- package/dist/services/initializationService.js +18 -0
- package/dist/tools/agentTool.js +3 -3
- package/dist/tools/bashTool.d.ts.map +1 -1
- package/dist/tools/bashTool.js +4 -4
- package/dist/tools/editTool.d.ts.map +1 -1
- package/dist/tools/editTool.js +2 -0
- package/dist/tools/globTool.d.ts.map +1 -1
- package/dist/tools/globTool.js +15 -3
- package/dist/tools/grepTool.d.ts.map +1 -1
- package/dist/tools/grepTool.js +38 -12
- package/dist/tools/readTool.d.ts.map +1 -1
- package/dist/tools/readTool.js +61 -0
- package/dist/tools/skillTool.js +2 -2
- package/dist/tools/types.d.ts +16 -0
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/tools/webFetchTool.d.ts +3 -0
- package/dist/tools/webFetchTool.d.ts.map +1 -0
- package/dist/tools/webFetchTool.js +171 -0
- package/dist/tools/writeTool.d.ts.map +1 -1
- package/dist/tools/writeTool.js +2 -0
- package/dist/types/commands.d.ts +1 -1
- package/dist/types/commands.d.ts.map +1 -1
- package/dist/types/messaging.d.ts +1 -0
- package/dist/types/messaging.d.ts.map +1 -1
- package/dist/utils/bashParser.d.ts +14 -0
- package/dist/utils/bashParser.d.ts.map +1 -1
- package/dist/utils/bashParser.js +243 -142
- package/dist/utils/convertMessagesForAPI.d.ts.map +1 -1
- package/dist/utils/convertMessagesForAPI.js +7 -0
- package/dist/utils/fileUtils.d.ts +8 -0
- package/dist/utils/fileUtils.d.ts.map +1 -1
- package/dist/utils/fileUtils.js +52 -0
- package/dist/utils/messageOperations.d.ts +12 -3
- package/dist/utils/messageOperations.d.ts.map +1 -1
- package/dist/utils/messageOperations.js +77 -9
- package/package.json +4 -2
- package/src/agent.ts +19 -1
- package/src/constants/tools.ts +1 -1
- package/src/managers/MemoryRuleManager.ts +1 -10
- package/src/managers/aiManager.ts +23 -3
- package/src/managers/messageManager.ts +76 -38
- package/src/managers/pluginManager.ts +4 -2
- package/src/managers/slashCommandManager.ts +130 -4
- package/src/managers/toolManager.ts +11 -2
- package/src/prompts/index.ts +6 -0
- package/src/services/GitService.ts +20 -0
- package/src/services/MarketplaceService.ts +397 -324
- package/src/services/aiService.ts +197 -1
- package/src/services/initializationService.ts +38 -0
- package/src/tools/agentTool.ts +3 -3
- package/src/tools/bashTool.ts +3 -4
- package/src/tools/editTool.ts +3 -0
- package/src/tools/globTool.ts +16 -3
- package/src/tools/grepTool.ts +41 -13
- package/src/tools/readTool.ts +69 -0
- package/src/tools/skillTool.ts +2 -2
- package/src/tools/types.ts +13 -0
- package/src/tools/webFetchTool.ts +194 -0
- package/src/tools/writeTool.ts +3 -0
- package/src/types/commands.ts +1 -1
- package/src/types/messaging.ts +1 -0
- package/src/utils/bashParser.ts +268 -157
- package/src/utils/convertMessagesForAPI.ts +8 -0
- package/src/utils/fileUtils.ts +69 -0
- package/src/utils/messageOperations.ts +84 -9
- package/dist/tools/taskOutputTool.d.ts +0 -3
- package/dist/tools/taskOutputTool.d.ts.map +0 -1
- package/dist/tools/taskOutputTool.js +0 -198
- package/src/tools/taskOutputTool.ts +0 -222
|
@@ -53,4 +53,38 @@ export interface CompressMessagesResult {
|
|
|
53
53
|
};
|
|
54
54
|
}
|
|
55
55
|
export declare function compressMessages(options: CompressMessagesOptions): Promise<CompressMessagesResult>;
|
|
56
|
+
export interface ProcessWebContentOptions {
|
|
57
|
+
gatewayConfig: GatewayConfig;
|
|
58
|
+
modelConfig: ModelConfig;
|
|
59
|
+
content: string;
|
|
60
|
+
prompt: string;
|
|
61
|
+
abortSignal?: AbortSignal;
|
|
62
|
+
model?: string;
|
|
63
|
+
}
|
|
64
|
+
export interface ProcessWebContentResult {
|
|
65
|
+
content: string;
|
|
66
|
+
usage?: {
|
|
67
|
+
prompt_tokens: number;
|
|
68
|
+
completion_tokens: number;
|
|
69
|
+
total_tokens: number;
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
export declare function processWebContent(options: ProcessWebContentOptions): Promise<ProcessWebContentResult>;
|
|
73
|
+
export interface BtwOptions {
|
|
74
|
+
gatewayConfig: GatewayConfig;
|
|
75
|
+
modelConfig: ModelConfig;
|
|
76
|
+
messages: ChatCompletionMessageParam[];
|
|
77
|
+
question: string;
|
|
78
|
+
abortSignal?: AbortSignal;
|
|
79
|
+
model?: string;
|
|
80
|
+
}
|
|
81
|
+
export interface BtwResult {
|
|
82
|
+
content: string;
|
|
83
|
+
usage?: {
|
|
84
|
+
prompt_tokens: number;
|
|
85
|
+
completion_tokens: number;
|
|
86
|
+
total_tokens: number;
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
export declare function btw(options: BtwOptions): Promise<BtwResult>;
|
|
56
90
|
//# sourceMappingURL=aiService.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aiService.d.ts","sourceRoot":"","sources":["../../src/services/aiService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,MAAM,kBAAkB,CAAC;AACjE,OAAO,EAGL,0BAA0B,EAC1B,0BAA0B,EAE3B,MAAM,qBAAqB,CAAC;AAI7B,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,EAKL,KAAK,WAAW,EACjB,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"aiService.d.ts","sourceRoot":"","sources":["../../src/services/aiService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,MAAM,kBAAkB,CAAC;AACjE,OAAO,EAGL,0BAA0B,EAC1B,0BAA0B,EAE3B,MAAM,qBAAqB,CAAC;AAI7B,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,EAKL,KAAK,WAAW,EACjB,MAAM,+BAA+B,CAAC;AAgEvC;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,IAAI,CAEvC;AA2DD,MAAM,WAAW,gBAAgB;IAE/B,aAAa,EAAE,aAAa,CAAC;IAC7B,WAAW,EAAE,WAAW,CAAC;IAGzB,QAAQ,EAAE,0BAA0B,EAAE,CAAC;IACvC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,W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MAAM,CAAC;QAC1B,YAAY,EAAE,MAAM,CAAC;KACtB,CAAC;CACH;AAED,wBAAsB,GAAG,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,SAAS,CAAC,CA0EjE"}
|
|
@@ -5,7 +5,7 @@ import { transformMessagesForClaudeCache, addCacheControlToLastTool, isClaudeMod
|
|
|
5
5
|
import * as os from "os";
|
|
6
6
|
import * as fs from "fs";
|
|
7
7
|
import * as path from "path";
|
|
8
|
-
import { COMPRESS_MESSAGES_SYSTEM_PROMPT } from "../prompts/index.js";
|
|
8
|
+
import { COMPRESS_MESSAGES_SYSTEM_PROMPT, WEB_CONTENT_SYSTEM_PROMPT, BTW_SYSTEM_PROMPT, } from "../prompts/index.js";
|
|
9
9
|
// Global rate limiter state for 1 QPS
|
|
10
10
|
let nextAllowedTime = 0;
|
|
11
11
|
const MIN_INTERVAL = 1000; // 1 second for 1 QPS
|
|
@@ -505,3 +505,126 @@ export async function compressMessages(options) {
|
|
|
505
505
|
throw error;
|
|
506
506
|
}
|
|
507
507
|
}
|
|
508
|
+
export async function processWebContent(options) {
|
|
509
|
+
const { gatewayConfig, modelConfig, content, prompt, abortSignal } = options;
|
|
510
|
+
// Apply global 1 QPS rate limit
|
|
511
|
+
if (process.env.NODE_ENV !== "test" ||
|
|
512
|
+
modelConfig.model === "rate-limit-test") {
|
|
513
|
+
await acquireSlot(abortSignal);
|
|
514
|
+
}
|
|
515
|
+
// Create OpenAI client with injected configuration
|
|
516
|
+
const openai = new OpenAIClient({
|
|
517
|
+
apiKey: gatewayConfig.apiKey,
|
|
518
|
+
baseURL: gatewayConfig.baseURL,
|
|
519
|
+
defaultHeaders: gatewayConfig.defaultHeaders,
|
|
520
|
+
fetchOptions: gatewayConfig.fetchOptions,
|
|
521
|
+
fetch: gatewayConfig.fetch,
|
|
522
|
+
});
|
|
523
|
+
// Get model configuration - use injected agent model
|
|
524
|
+
const openaiModelConfig = getModelConfig(options.model || modelConfig.model, {
|
|
525
|
+
temperature: 0.1,
|
|
526
|
+
max_tokens: 4096,
|
|
527
|
+
});
|
|
528
|
+
try {
|
|
529
|
+
const response = await openai.chat.completions.create({
|
|
530
|
+
...openaiModelConfig,
|
|
531
|
+
messages: [
|
|
532
|
+
{
|
|
533
|
+
role: "system",
|
|
534
|
+
content: WEB_CONTENT_SYSTEM_PROMPT,
|
|
535
|
+
},
|
|
536
|
+
{
|
|
537
|
+
role: "user",
|
|
538
|
+
content: `Web Content:\n\n${content}\n\nUser Prompt: ${prompt}`,
|
|
539
|
+
},
|
|
540
|
+
],
|
|
541
|
+
}, {
|
|
542
|
+
signal: abortSignal,
|
|
543
|
+
});
|
|
544
|
+
const result = response.choices[0]?.message?.content?.trim();
|
|
545
|
+
if (!result) {
|
|
546
|
+
throw new Error("Failed to process web content: Empty response from AI");
|
|
547
|
+
}
|
|
548
|
+
const usage = response.usage
|
|
549
|
+
? {
|
|
550
|
+
prompt_tokens: response.usage.prompt_tokens,
|
|
551
|
+
completion_tokens: response.usage.completion_tokens,
|
|
552
|
+
total_tokens: response.usage.total_tokens,
|
|
553
|
+
}
|
|
554
|
+
: undefined;
|
|
555
|
+
return {
|
|
556
|
+
content: result,
|
|
557
|
+
usage,
|
|
558
|
+
};
|
|
559
|
+
}
|
|
560
|
+
catch (error) {
|
|
561
|
+
if (error.name === "AbortError") {
|
|
562
|
+
logger.info("Web content processing request was aborted");
|
|
563
|
+
throw new Error("Web content processing request was aborted");
|
|
564
|
+
}
|
|
565
|
+
logger.error("Failed to process web content:", error);
|
|
566
|
+
throw error;
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
export async function btw(options) {
|
|
570
|
+
const { gatewayConfig, modelConfig, messages, question, abortSignal } = options;
|
|
571
|
+
// Apply global 1 QPS rate limit
|
|
572
|
+
if (process.env.NODE_ENV !== "test" ||
|
|
573
|
+
modelConfig.model === "rate-limit-test") {
|
|
574
|
+
await acquireSlot(abortSignal);
|
|
575
|
+
}
|
|
576
|
+
// Create OpenAI client with injected configuration
|
|
577
|
+
const openai = new OpenAIClient({
|
|
578
|
+
apiKey: gatewayConfig.apiKey,
|
|
579
|
+
baseURL: gatewayConfig.baseURL,
|
|
580
|
+
defaultHeaders: gatewayConfig.defaultHeaders,
|
|
581
|
+
fetchOptions: gatewayConfig.fetchOptions,
|
|
582
|
+
fetch: gatewayConfig.fetch,
|
|
583
|
+
});
|
|
584
|
+
// Get model configuration - use injected agent model
|
|
585
|
+
const openaiModelConfig = getModelConfig(options.model || modelConfig.model, {
|
|
586
|
+
temperature: 0.1,
|
|
587
|
+
max_tokens: 4096,
|
|
588
|
+
});
|
|
589
|
+
try {
|
|
590
|
+
const response = await openai.chat.completions.create({
|
|
591
|
+
...openaiModelConfig,
|
|
592
|
+
messages: [
|
|
593
|
+
{
|
|
594
|
+
role: "system",
|
|
595
|
+
content: BTW_SYSTEM_PROMPT,
|
|
596
|
+
},
|
|
597
|
+
...messages,
|
|
598
|
+
{
|
|
599
|
+
role: "user",
|
|
600
|
+
content: question,
|
|
601
|
+
},
|
|
602
|
+
],
|
|
603
|
+
}, {
|
|
604
|
+
signal: abortSignal,
|
|
605
|
+
});
|
|
606
|
+
const result = response.choices[0]?.message?.content?.trim();
|
|
607
|
+
if (!result) {
|
|
608
|
+
throw new Error("Failed to process side question: Empty response from AI");
|
|
609
|
+
}
|
|
610
|
+
const usage = response.usage
|
|
611
|
+
? {
|
|
612
|
+
prompt_tokens: response.usage.prompt_tokens,
|
|
613
|
+
completion_tokens: response.usage.completion_tokens,
|
|
614
|
+
total_tokens: response.usage.total_tokens,
|
|
615
|
+
}
|
|
616
|
+
: undefined;
|
|
617
|
+
return {
|
|
618
|
+
content: result,
|
|
619
|
+
usage,
|
|
620
|
+
};
|
|
621
|
+
}
|
|
622
|
+
catch (error) {
|
|
623
|
+
if (error.name === "AbortError") {
|
|
624
|
+
logger.info("Side question request was aborted");
|
|
625
|
+
throw new Error("Side question request was aborted");
|
|
626
|
+
}
|
|
627
|
+
logger.error("Failed to process side question:", error);
|
|
628
|
+
throw error;
|
|
629
|
+
}
|
|
630
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initializationService.d.ts","sourceRoot":"","sources":["../../src/services/initializationService.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,OAAO,EACP,MAAM,EACN,YAAY,EACZ,WAAW,EACZ,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACtE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AAC9E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACtE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AACpE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAC1E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAC1E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAIpD,MAAM,WAAW,qBAAqB;IACpC,YAAY,EAAE,YAAY,CAAC;IAC3B,eAAe,EAAE,eAAe,CAAC;IACjC,SAAS,EAAE,SAAS,CAAC;IACrB,WAAW,EAAE,WAAW,CAAC;IACzB,aAAa,EAAE,aAAa,CAAC;IAC7B,OAAO,EAAE,YAAY,CAAC;IACtB,mBAAmB,EAAE,mBAAmB,CAAC;IACzC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,UAAU,CAAC;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,WAAW,CAAC;IACxB,oBAAoB,EAAE,oBAAoB,CAAC;IAC3C,WAAW,EAAE,WAAW,CAAC;IACzB,cAAc,EAAE,cAAc,CAAC;IAC/B,iBAAiB,EAAE,iBAAiB,CAAC;IACrC,iBAAiB,EAAE,iBAAiB,CAAC;IACrC,WAAW,EAAE,WAAW,CAAC;IACzB,gBAAgB,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IAC5C,aAAa,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACzC,wBAAwB,EAAE,MAAM,IAAI,CAAC;CACtC;AAED,qBAAa,qBAAqB;WACZ,UAAU,CAC5B,OAAO,EAAE,qBAAqB,EAC9B,OAAO,CAAC,EAAE;QACR,gBAAgB,CAAC,EAAE,MAAM,CAAC;QAC1B,mBAAmB,CAAC,EAAE,OAAO,CAAC;QAC9B,QAAQ,CAAC,EAAE,OAAO,EAAE,CAAC;KACtB,GACA,OAAO,CAAC,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"initializationService.d.ts","sourceRoot":"","sources":["../../src/services/initializationService.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,OAAO,EACP,MAAM,EACN,YAAY,EACZ,WAAW,EACZ,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACtE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,KAAK,EAAE,mBA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AAqB,EAC9B,OAAO,CAAC,EAAE;QACR,gBAAgB,CAAC,EAAE,MAAM,CAAC;QAC1B,mBAAmB,CAAC,EAAE,OAAO,CAAC;QAC9B,QAAQ,CAAC,EAAE,OAAO,EAAE,CAAC;KACtB,GACA,OAAO,CAAC,IAAI,CAAC;CAsRjB"}
|
|
@@ -4,8 +4,10 @@ import { LspManager } from "../managers/lspManager.js";
|
|
|
4
4
|
export class InitializationService {
|
|
5
5
|
static async initialize(context, options) {
|
|
6
6
|
const { skillManager, subagentManager, container, toolManager, pluginManager, options: agentOptions, slashCommandManager, logger, mcpManager, workdir, lspManager, configurationService, hookManager, messageManager, memoryRuleManager, liveConfigManager, taskManager, setProjectMemory, setUserMemory, resolveAndValidateConfig, } = context;
|
|
7
|
+
const startTime = performance.now();
|
|
7
8
|
// Initialize managers first
|
|
8
9
|
try {
|
|
10
|
+
const phaseStart = performance.now();
|
|
9
11
|
// Initialize SkillManager
|
|
10
12
|
await skillManager.initialize();
|
|
11
13
|
// Initialize SubagentManager (load and cache configurations)
|
|
@@ -19,6 +21,7 @@ export class InitializationService {
|
|
|
19
21
|
await pluginManager.loadPlugins(agentOptions.plugins || []);
|
|
20
22
|
// Register skill commands
|
|
21
23
|
slashCommandManager.registerSkillCommands(skillManager.getAvailableSkills());
|
|
24
|
+
logger?.debug(`Initialization Phase [Managers and Tools] took ${(performance.now() - phaseStart).toFixed(2)}ms`);
|
|
22
25
|
}
|
|
23
26
|
catch (error) {
|
|
24
27
|
logger?.error("Failed to initialize managers and tools:", error);
|
|
@@ -26,10 +29,12 @@ export class InitializationService {
|
|
|
26
29
|
}
|
|
27
30
|
// Initialize MCP servers with auto-connect
|
|
28
31
|
try {
|
|
32
|
+
const phaseStart = performance.now();
|
|
29
33
|
await mcpManager.initialize(workdir, true);
|
|
30
34
|
if (lspManager instanceof LspManager) {
|
|
31
35
|
await lspManager.initialize(workdir);
|
|
32
36
|
}
|
|
37
|
+
logger?.debug(`Initialization Phase [MCP and LSP] took ${(performance.now() - phaseStart).toFixed(2)}ms`);
|
|
33
38
|
}
|
|
34
39
|
catch (error) {
|
|
35
40
|
logger?.error("Failed to initialize MCP servers:", error);
|
|
@@ -37,6 +42,7 @@ export class InitializationService {
|
|
|
37
42
|
}
|
|
38
43
|
// Initialize hooks configuration
|
|
39
44
|
try {
|
|
45
|
+
const phaseStart = performance.now();
|
|
40
46
|
// Load hooks configuration using ConfigurationService
|
|
41
47
|
const configResult = await configurationService.loadMergedConfiguration(workdir);
|
|
42
48
|
hookManager.loadConfigurationFromWaveConfig(configResult.configuration);
|
|
@@ -62,6 +68,7 @@ export class InitializationService {
|
|
|
62
68
|
}
|
|
63
69
|
}
|
|
64
70
|
}
|
|
71
|
+
logger?.debug(`Initialization Phase [Hooks Configuration] took ${(performance.now() - phaseStart).toFixed(2)}ms`);
|
|
65
72
|
}
|
|
66
73
|
catch (error) {
|
|
67
74
|
logger?.error("Failed to initialize hooks system:", error);
|
|
@@ -92,6 +99,7 @@ export class InitializationService {
|
|
|
92
99
|
resolveAndValidateConfig();
|
|
93
100
|
// Initialize auto-memory directory
|
|
94
101
|
try {
|
|
102
|
+
const phaseStart = performance.now();
|
|
95
103
|
if (configurationService.resolveAutoMemoryEnabled()) {
|
|
96
104
|
const memoryService = container.get("MemoryService");
|
|
97
105
|
if (memoryService) {
|
|
@@ -103,6 +111,7 @@ export class InitializationService {
|
|
|
103
111
|
}
|
|
104
112
|
}
|
|
105
113
|
}
|
|
114
|
+
logger?.debug(`Initialization Phase [Auto-memory Initialization] took ${(performance.now() - phaseStart).toFixed(2)}ms`);
|
|
106
115
|
}
|
|
107
116
|
catch (error) {
|
|
108
117
|
logger?.error("Failed to initialize auto-memory directory:", error);
|
|
@@ -111,14 +120,18 @@ export class InitializationService {
|
|
|
111
120
|
setGlobalLogger(logger || null);
|
|
112
121
|
// Discover modular memory rules
|
|
113
122
|
try {
|
|
123
|
+
const phaseStart = performance.now();
|
|
114
124
|
await memoryRuleManager.discoverRules();
|
|
125
|
+
logger?.debug(`Initialization Phase [Memory Rules Discovery] took ${(performance.now() - phaseStart).toFixed(2)}ms`);
|
|
115
126
|
}
|
|
116
127
|
catch (error) {
|
|
117
128
|
logger?.error("Failed to discover memory rules:", error);
|
|
118
129
|
}
|
|
119
130
|
// Initialize live configuration reload
|
|
120
131
|
try {
|
|
132
|
+
const phaseStart = performance.now();
|
|
121
133
|
await liveConfigManager.initialize();
|
|
134
|
+
logger?.debug(`Initialization Phase [Live Config Initialization] took ${(performance.now() - phaseStart).toFixed(2)}ms`);
|
|
122
135
|
}
|
|
123
136
|
catch (error) {
|
|
124
137
|
logger?.error("Failed to initialize live configuration reload:", error);
|
|
@@ -126,6 +139,7 @@ export class InitializationService {
|
|
|
126
139
|
}
|
|
127
140
|
// Load memory files during initialization
|
|
128
141
|
try {
|
|
142
|
+
const phaseStart = performance.now();
|
|
129
143
|
const memoryService = container.get("MemoryService");
|
|
130
144
|
if (!memoryService) {
|
|
131
145
|
throw new Error("MemoryService not found in container");
|
|
@@ -148,6 +162,7 @@ export class InitializationService {
|
|
|
148
162
|
logger?.warn("Failed to load user memory file:", error);
|
|
149
163
|
setUserMemory("");
|
|
150
164
|
}
|
|
165
|
+
logger?.debug(`Initialization Phase [Memory Files Loading] took ${(performance.now() - phaseStart).toFixed(2)}ms`);
|
|
151
166
|
}
|
|
152
167
|
catch (error) {
|
|
153
168
|
// Ensure memory is always initialized even if loading fails
|
|
@@ -157,6 +172,7 @@ export class InitializationService {
|
|
|
157
172
|
// Don't throw error to prevent app startup failure
|
|
158
173
|
}
|
|
159
174
|
// Handle session restoration or set provided messages
|
|
175
|
+
const sessionPhaseStart = performance.now();
|
|
160
176
|
if (options?.messages) {
|
|
161
177
|
// If messages are provided, use them directly (useful for testing)
|
|
162
178
|
messageManager.setMessages(options.messages);
|
|
@@ -177,5 +193,7 @@ export class InitializationService {
|
|
|
177
193
|
agentOptions.callbacks?.onTasksChange?.(tasks);
|
|
178
194
|
}
|
|
179
195
|
}
|
|
196
|
+
logger?.debug(`Initialization Phase [Session Restoration] took ${(performance.now() - sessionPhaseStart).toFixed(2)}ms`);
|
|
197
|
+
logger?.debug(`Total Initialization took ${(performance.now() - startTime).toFixed(2)}ms`);
|
|
180
198
|
}
|
|
181
199
|
}
|
package/dist/tools/agentTool.js
CHANGED
|
@@ -28,7 +28,7 @@ export const agentTool = {
|
|
|
28
28
|
},
|
|
29
29
|
run_in_background: {
|
|
30
30
|
type: "boolean",
|
|
31
|
-
description: "Set to true to run this command in the background. Use
|
|
31
|
+
description: "Set to true to run this command in the background. Use Read to read the output later.",
|
|
32
32
|
},
|
|
33
33
|
},
|
|
34
34
|
required: ["description", "prompt", "subagent_type"],
|
|
@@ -127,7 +127,7 @@ When using the Agent tool, you must specify a subagent_type parameter to select
|
|
|
127
127
|
if (run_in_background || isBackgrounded)
|
|
128
128
|
return;
|
|
129
129
|
const messages = instance.messageManager.getMessages();
|
|
130
|
-
const tokens = instance.messageManager.
|
|
130
|
+
const tokens = instance.messageManager.getLatestTotalTokens();
|
|
131
131
|
const lastTools = instance.lastTools;
|
|
132
132
|
const toolCount = countToolBlocks(messages);
|
|
133
133
|
const summary = formatToolTokenSummary(toolCount, tokens);
|
|
@@ -179,7 +179,7 @@ When using the Agent tool, you must specify a subagent_type parameter to select
|
|
|
179
179
|
// Cleanup subagent instance after agent completion
|
|
180
180
|
subagentManager.cleanupInstance(instance.subagentId);
|
|
181
181
|
const messages = instance.messageManager.getMessages();
|
|
182
|
-
const tokens = instance.messageManager.
|
|
182
|
+
const tokens = instance.messageManager.getLatestTotalTokens();
|
|
183
183
|
const toolCount = countToolBlocks(messages);
|
|
184
184
|
const summary = formatToolTokenSummary(toolCount, tokens);
|
|
185
185
|
resolve({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bashTool.d.ts","sourceRoot":"","sources":["../../src/tools/bashTool.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,UAAU,EAA2B,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"bashTool.d.ts","sourceRoot":"","sources":["../../src/tools/bashTool.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,UAAU,EAA2B,MAAM,YAAY,CAAC;AAsDtE;;GAEG;AACH,eAAO,MAAM,QAAQ,EAAE,UA2ZtB,CAAC"}
|
package/dist/tools/bashTool.js
CHANGED
|
@@ -4,7 +4,7 @@ import * as path from "path";
|
|
|
4
4
|
import * as os from "os";
|
|
5
5
|
import { logger } from "../utils/globalLogger.js";
|
|
6
6
|
import { stripAnsiColors } from "../utils/stringUtils.js";
|
|
7
|
-
import { BASH_TOOL_NAME,
|
|
7
|
+
import { BASH_TOOL_NAME, GLOB_TOOL_NAME, GREP_TOOL_NAME, READ_TOOL_NAME, EDIT_TOOL_NAME, WRITE_TOOL_NAME, } from "../constants/tools.js";
|
|
8
8
|
const MAX_OUTPUT_LENGTH = 30000;
|
|
9
9
|
const BASH_DEFAULT_TIMEOUT_MS = 120000;
|
|
10
10
|
/**
|
|
@@ -68,7 +68,7 @@ export const bashTool = {
|
|
|
68
68
|
},
|
|
69
69
|
run_in_background: {
|
|
70
70
|
type: "boolean",
|
|
71
|
-
description: `Set to true to run this command in the background. Use ${
|
|
71
|
+
description: `Set to true to run this command in the background. Use ${READ_TOOL_NAME} to read the output later.`,
|
|
72
72
|
},
|
|
73
73
|
},
|
|
74
74
|
required: ["command"],
|
|
@@ -101,7 +101,7 @@ Usage notes:
|
|
|
101
101
|
- You can specify an optional timeout in milliseconds (up to ${BASH_DEFAULT_TIMEOUT_MS}ms / ${BASH_DEFAULT_TIMEOUT_MS / 60000} minutes). If not specified, commands will timeout after ${BASH_DEFAULT_TIMEOUT_MS}ms (${BASH_DEFAULT_TIMEOUT_MS / 60000} minutes).
|
|
102
102
|
- It is very helpful if you write a clear, concise description of what this command does in 5-10 words.
|
|
103
103
|
- If the output exceeds ${MAX_OUTPUT_LENGTH} characters, output will be truncated and the full output will be persisted to a temporary file.
|
|
104
|
-
- You can use the \`run_in_background\` parameter to run the command in the background, which allows you to continue working while the command runs. You can monitor the output using the ${
|
|
104
|
+
- You can use the \`run_in_background\` parameter to run the command in the background, which allows you to continue working while the command runs. You can monitor the output using the ${READ_TOOL_NAME} tool as it becomes available. You do not need to use '&' at the end of the command when using this parameter.
|
|
105
105
|
- Avoid using ${BASH_TOOL_NAME} with the \`find\`, \`sed\`, \`awk\`, or \`echo\` commands, unless explicitly instructed or when these commands are truly necessary for the task. Instead, always prefer using the dedicated tools for these commands:
|
|
106
106
|
- File search: Use ${GLOB_TOOL_NAME} (NOT find or ls)
|
|
107
107
|
- Content search: Use ${GREP_TOOL_NAME}
|
|
@@ -189,7 +189,7 @@ Usage notes:
|
|
|
189
189
|
const outputPath = task?.outputPath;
|
|
190
190
|
return {
|
|
191
191
|
success: true,
|
|
192
|
-
content: `Command started in background with ID: ${taskId}.${outputPath ? ` Real-time output: ${outputPath}` : ` Use
|
|
192
|
+
content: `Command started in background with ID: ${taskId}.${outputPath ? ` Real-time output: ${outputPath}` : ` Use ${READ_TOOL_NAME} tool with task_id="${taskId}" to monitor output.`}`,
|
|
193
193
|
shortResult: `Background process ${taskId} started`,
|
|
194
194
|
};
|
|
195
195
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"editTool.d.ts","sourceRoot":"","sources":["../../src/tools/editTool.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAA2B,MAAM,YAAY,CAAC;AAgBtE;;GAEG;AACH,eAAO,MAAM,QAAQ,EAAE,
|
|
1
|
+
{"version":3,"file":"editTool.d.ts","sourceRoot":"","sources":["../../src/tools/editTool.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAA2B,MAAM,YAAY,CAAC;AAgBtE;;GAEG;AACH,eAAO,MAAM,QAAQ,EAAE,UAoOtB,CAAC"}
|
package/dist/tools/editTool.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"globTool.d.ts","sourceRoot":"","sources":["../../src/tools/globTool.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAA2B,MAAM,YAAY,CAAC;AAStE;;GAEG;AACH,eAAO,MAAM,QAAQ,EAAE,
|
|
1
|
+
{"version":3,"file":"globTool.d.ts","sourceRoot":"","sources":["../../src/tools/globTool.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAA2B,MAAM,YAAY,CAAC;AAStE;;GAEG;AACH,eAAO,MAAM,QAAQ,EAAE,UAwJtB,CAAC"}
|
package/dist/tools/globTool.js
CHANGED
|
@@ -27,6 +27,10 @@ export const globTool = {
|
|
|
27
27
|
type: "string",
|
|
28
28
|
description: 'The directory to search in. If not specified, the current working directory will be used. IMPORTANT: Omit this field to use the default directory. DO NOT enter "undefined" or "null" - simply omit it for the default behavior. Must be a valid directory path if provided.',
|
|
29
29
|
},
|
|
30
|
+
limit: {
|
|
31
|
+
type: "number",
|
|
32
|
+
description: "Maximum number of files to return. Defaults to 100.",
|
|
33
|
+
},
|
|
30
34
|
},
|
|
31
35
|
required: ["pattern"],
|
|
32
36
|
},
|
|
@@ -41,6 +45,8 @@ export const globTool = {
|
|
|
41
45
|
execute: async (args, context) => {
|
|
42
46
|
const pattern = args.pattern;
|
|
43
47
|
const searchPath = args.path;
|
|
48
|
+
const limit = args.limit || MAX_GLOB_RESULTS;
|
|
49
|
+
const startTime = Date.now();
|
|
44
50
|
if (!pattern || typeof pattern !== "string") {
|
|
45
51
|
return {
|
|
46
52
|
success: false,
|
|
@@ -93,19 +99,25 @@ export const globTool = {
|
|
|
93
99
|
.sort((a, b) => b.mtime.getTime() - a.mtime.getTime()) // Most recently modified files first
|
|
94
100
|
.map((item) => item.path);
|
|
95
101
|
const totalCount = sortedFiles.length;
|
|
96
|
-
const finalFiles = sortedFiles.slice(0,
|
|
102
|
+
const finalFiles = sortedFiles.slice(0, limit);
|
|
97
103
|
// Format output
|
|
98
104
|
const output = finalFiles
|
|
99
105
|
.map((file, index) => `${index + 1}. ${file}`)
|
|
100
106
|
.join("\n");
|
|
101
|
-
const isTruncated = totalCount >
|
|
107
|
+
const isTruncated = totalCount > limit;
|
|
102
108
|
const shortResult = isTruncated
|
|
103
|
-
? `Found ${totalCount} files (showing first ${
|
|
109
|
+
? `Found ${totalCount} files (showing first ${limit})`
|
|
104
110
|
: `Found ${totalCount} file${totalCount === 1 ? "" : "s"}`;
|
|
111
|
+
const durationMs = Date.now() - startTime;
|
|
105
112
|
return {
|
|
106
113
|
success: true,
|
|
107
114
|
content: output,
|
|
108
115
|
shortResult,
|
|
116
|
+
metadata: {
|
|
117
|
+
durationMs,
|
|
118
|
+
numFiles: totalCount,
|
|
119
|
+
truncated: isTruncated,
|
|
120
|
+
},
|
|
109
121
|
};
|
|
110
122
|
}
|
|
111
123
|
catch (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"grepTool.d.ts","sourceRoot":"","sources":["../../src/tools/grepTool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAA2B,MAAM,YAAY,CAAC;AAUtE;;GAEG;AACH,eAAO,MAAM,QAAQ,EAAE,
|
|
1
|
+
{"version":3,"file":"grepTool.d.ts","sourceRoot":"","sources":["../../src/tools/grepTool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAA2B,MAAM,YAAY,CAAC;AAUtE;;GAEG;AACH,eAAO,MAAM,QAAQ,EAAE,UA8StB,CAAC"}
|
package/dist/tools/grepTool.js
CHANGED
|
@@ -64,6 +64,14 @@ export const grepTool = {
|
|
|
64
64
|
type: "boolean",
|
|
65
65
|
description: "Enable multiline mode where . matches newlines and patterns can span lines (rg -U --multiline-dotall). Default: false.",
|
|
66
66
|
},
|
|
67
|
+
offset: {
|
|
68
|
+
type: "number",
|
|
69
|
+
description: "The number of matches to skip.",
|
|
70
|
+
},
|
|
71
|
+
context: {
|
|
72
|
+
type: "number",
|
|
73
|
+
description: 'Alias for -C. Number of lines to show before and after each match. Requires output_mode: "content", ignored otherwise.',
|
|
74
|
+
},
|
|
67
75
|
},
|
|
68
76
|
required: ["pattern"],
|
|
69
77
|
},
|
|
@@ -93,6 +101,8 @@ export const grepTool = {
|
|
|
93
101
|
const fileType = args.type;
|
|
94
102
|
const headLimit = args.head_limit;
|
|
95
103
|
const multiline = args.multiline;
|
|
104
|
+
const offset = args.offset;
|
|
105
|
+
const contextArg = args.context;
|
|
96
106
|
if (!pattern || typeof pattern !== "string") {
|
|
97
107
|
return {
|
|
98
108
|
success: false,
|
|
@@ -136,8 +146,9 @@ export const grepTool = {
|
|
|
136
146
|
}
|
|
137
147
|
// Context lines (only effective in content mode)
|
|
138
148
|
if (outputMode === "content") {
|
|
139
|
-
|
|
140
|
-
|
|
149
|
+
const effectiveContext = contextArg ?? contextAround;
|
|
150
|
+
if (effectiveContext) {
|
|
151
|
+
rgArgs.push("-C", effectiveContext.toString());
|
|
141
152
|
}
|
|
142
153
|
else {
|
|
143
154
|
if (contextBefore) {
|
|
@@ -180,36 +191,51 @@ export const grepTool = {
|
|
|
180
191
|
success: true,
|
|
181
192
|
content: "No matches found. Suggestion: specify the 'path' field to search in ignored or other directories (e.g., 'node_modules'), as the default search path is the current working directory and respects .gitignore.",
|
|
182
193
|
shortResult: "No matches found",
|
|
194
|
+
metadata: {
|
|
195
|
+
numMatches: 0,
|
|
196
|
+
},
|
|
183
197
|
};
|
|
184
198
|
}
|
|
185
|
-
// Apply head_limit with default fallback
|
|
186
|
-
let finalOutput = output;
|
|
187
199
|
let lines = output.split("\n");
|
|
188
|
-
|
|
200
|
+
const totalMatches = lines.length;
|
|
201
|
+
// Apply offset
|
|
202
|
+
const effectiveOffset = offset || 0;
|
|
203
|
+
if (effectiveOffset > 0) {
|
|
204
|
+
lines = lines.slice(effectiveOffset);
|
|
205
|
+
}
|
|
206
|
+
// Apply head_limit
|
|
189
207
|
const effectiveHeadLimit = headLimit || 0;
|
|
208
|
+
let truncated = false;
|
|
190
209
|
if (effectiveHeadLimit > 0 && lines.length > effectiveHeadLimit) {
|
|
191
210
|
lines = lines.slice(0, effectiveHeadLimit);
|
|
192
|
-
|
|
211
|
+
truncated = true;
|
|
193
212
|
}
|
|
213
|
+
const finalOutput = lines.join("\n");
|
|
194
214
|
// Generate short result
|
|
195
215
|
let shortResult;
|
|
196
|
-
const
|
|
216
|
+
const numMatches = lines.length;
|
|
197
217
|
if (outputMode === "files_with_matches") {
|
|
198
|
-
shortResult = `Found ${
|
|
218
|
+
shortResult = `Found ${numMatches} file${numMatches === 1 ? "" : "s"}`;
|
|
199
219
|
}
|
|
200
220
|
else if (outputMode === "count") {
|
|
201
|
-
shortResult = `Match counts for ${
|
|
221
|
+
shortResult = `Match counts for ${numMatches} file${numMatches === 1 ? "" : "s"}`;
|
|
202
222
|
}
|
|
203
223
|
else {
|
|
204
|
-
shortResult = `Found ${
|
|
224
|
+
shortResult = `Found ${numMatches} matching line${numMatches === 1 ? "" : "s"}`;
|
|
205
225
|
}
|
|
206
|
-
if (
|
|
207
|
-
shortResult += ` (showing
|
|
226
|
+
if (effectiveOffset > 0 || truncated) {
|
|
227
|
+
shortResult += ` (showing ${numMatches} of ${totalMatches})`;
|
|
208
228
|
}
|
|
209
229
|
return {
|
|
210
230
|
success: true,
|
|
211
231
|
content: finalOutput,
|
|
212
232
|
shortResult,
|
|
233
|
+
metadata: {
|
|
234
|
+
numMatches: totalMatches,
|
|
235
|
+
truncated,
|
|
236
|
+
appliedLimit: effectiveHeadLimit,
|
|
237
|
+
appliedOffset: effectiveOffset,
|
|
238
|
+
},
|
|
213
239
|
};
|
|
214
240
|
}
|
|
215
241
|
catch (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"readTool.d.ts","sourceRoot":"","sources":["../../src/tools/readTool.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"readTool.d.ts","sourceRoot":"","sources":["../../src/tools/readTool.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAA2B,MAAM,YAAY,CAAC;AAkItE;;GAEG;AACH,eAAO,MAAM,QAAQ,EAAE,UA2QtB,CAAC"}
|