oricore 1.0.0
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/LICENSE +21 -0
- package/README.md +199 -0
- package/dist/agent/agent/agentManager.d.ts +38 -0
- package/dist/agent/agent/builtin/common.d.ts +5 -0
- package/dist/agent/agent/builtin/explore.d.ts +5 -0
- package/dist/agent/agent/builtin/general-purpose.d.ts +5 -0
- package/dist/agent/agent/builtin/index.d.ts +5 -0
- package/dist/agent/agent/executor.d.ts +2 -0
- package/dist/agent/agent/types.d.ts +98 -0
- package/dist/api/engine.d.ts +213 -0
- package/dist/communication/index.d.ts +4 -0
- package/dist/communication/messageBus.d.ts +71 -0
- package/dist/core/at.d.ts +26 -0
- package/dist/core/backgroundTaskManager.d.ts +27 -0
- package/dist/core/compact.d.ts +9 -0
- package/dist/core/config.d.ts +103 -0
- package/dist/core/constants.d.ts +32 -0
- package/dist/core/context.d.ts +57 -0
- package/dist/core/globalData.d.ts +21 -0
- package/dist/core/history.d.ts +24 -0
- package/dist/core/ide.d.ts +103 -0
- package/dist/core/jsonl.d.ts +37 -0
- package/dist/core/llmsContext.d.ts +14 -0
- package/dist/core/loop.d.ts +82 -0
- package/dist/core/message.d.ts +132 -0
- package/dist/core/model.d.ts +79 -0
- package/dist/core/output-style/builtin/default.d.ts +2 -0
- package/dist/core/output-style/builtin/explanatory.d.ts +2 -0
- package/dist/core/output-style/builtin/index.d.ts +6 -0
- package/dist/core/output-style/builtin/miao.d.ts +2 -0
- package/dist/core/output-style/builtin/minimal.d.ts +2 -0
- package/dist/core/output-style/types.d.ts +6 -0
- package/dist/core/outputFormat.d.ts +29 -0
- package/dist/core/outputStyle.d.ts +43 -0
- package/dist/core/paths.d.ts +20 -0
- package/dist/core/planSystemPrompt.d.ts +5 -0
- package/dist/core/plugin.d.ts +138 -0
- package/dist/core/project.d.ts +64 -0
- package/dist/core/promptCache.d.ts +3 -0
- package/dist/core/query.d.ts +14 -0
- package/dist/core/rules.d.ts +8 -0
- package/dist/core/systemPrompt.d.ts +9 -0
- package/dist/core/thinking-config.d.ts +3 -0
- package/dist/core/usage.d.ts +14 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +144432 -0
- package/dist/mcp/mcp.d.ts +49 -0
- package/dist/modes/builtin.d.ts +34 -0
- package/dist/modes/index.d.ts +8 -0
- package/dist/modes/registry.d.ts +18 -0
- package/dist/modes/types.d.ts +51 -0
- package/dist/platform/index.d.ts +5 -0
- package/dist/platform/node.d.ts +28 -0
- package/dist/platform/types.d.ts +41 -0
- package/dist/session/session.d.ts +43 -0
- package/dist/skill/skill.d.ts +79 -0
- package/dist/tools/tool.d.ts +119 -0
- package/dist/tools/tools/askUserQuestion.d.ts +48 -0
- package/dist/tools/tools/bash.d.ts +43 -0
- package/dist/tools/tools/edit.d.ts +9 -0
- package/dist/tools/tools/fetch.d.ts +9 -0
- package/dist/tools/tools/glob.d.ts +7 -0
- package/dist/tools/tools/grep.d.ts +22 -0
- package/dist/tools/tools/ls.d.ts +6 -0
- package/dist/tools/tools/read.d.ts +9 -0
- package/dist/tools/tools/skill.d.ts +7 -0
- package/dist/tools/tools/task.d.ts +14 -0
- package/dist/tools/tools/todo.d.ts +37 -0
- package/dist/tools/tools/write.d.ts +7 -0
- package/dist/utils/apiKeyRotation.d.ts +2 -0
- package/dist/utils/applyEdit.d.ts +17 -0
- package/dist/utils/background-detection.d.ts +2 -0
- package/dist/utils/dotenv.d.ts +9 -0
- package/dist/utils/env.d.ts +6 -0
- package/dist/utils/error.d.ts +11 -0
- package/dist/utils/execFileNoThrow.d.ts +8 -0
- package/dist/utils/files.d.ts +10 -0
- package/dist/utils/git.d.ts +163 -0
- package/dist/utils/ide.d.ts +27 -0
- package/dist/utils/ignore.d.ts +6 -0
- package/dist/utils/isLocal.d.ts +1 -0
- package/dist/utils/language.d.ts +9 -0
- package/dist/utils/list.d.ts +20 -0
- package/dist/utils/mergeSystemMessagesMiddleware.d.ts +2 -0
- package/dist/utils/messageNormalization.d.ts +22 -0
- package/dist/utils/path.d.ts +34 -0
- package/dist/utils/prependSystemMessageMiddleware.d.ts +2 -0
- package/dist/utils/project.d.ts +1 -0
- package/dist/utils/proxy.d.ts +18 -0
- package/dist/utils/randomUUID.d.ts +5 -0
- package/dist/utils/renderSessionMarkdown.d.ts +10 -0
- package/dist/utils/ripgrep.d.ts +16 -0
- package/dist/utils/safeFrontMatter.d.ts +11 -0
- package/dist/utils/safeParseJson.d.ts +1 -0
- package/dist/utils/safeStringify.d.ts +1 -0
- package/dist/utils/sanitizeAIResponse.d.ts +30 -0
- package/dist/utils/setTerminalTitle.d.ts +1 -0
- package/dist/utils/shell-execution.d.ts +44 -0
- package/dist/utils/string.d.ts +8 -0
- package/dist/utils/symbols.d.ts +14 -0
- package/dist/utils/system-encoding.d.ts +40 -0
- package/dist/utils/tokenCounter.d.ts +8 -0
- package/dist/utils/username.d.ts +1 -0
- package/package.json +106 -0
- package/src/agent/agent/agentManager.test.ts +124 -0
- package/src/agent/agent/agentManager.ts +372 -0
- package/src/agent/agent/builtin/common.ts +20 -0
- package/src/agent/agent/builtin/explore.ts +53 -0
- package/src/agent/agent/builtin/general-purpose.ts +38 -0
- package/src/agent/agent/builtin/index.ts +13 -0
- package/src/agent/agent/executor.test.ts +339 -0
- package/src/agent/agent/executor.ts +224 -0
- package/src/agent/agent/types.ts +119 -0
- package/src/api/engine.ts +466 -0
- package/src/communication/index.ts +18 -0
- package/src/communication/messageBus.ts +393 -0
- package/src/core/at.ts +315 -0
- package/src/core/backgroundTaskManager.ts +129 -0
- package/src/core/compact.ts +95 -0
- package/src/core/config.ts +441 -0
- package/src/core/constants.ts +82 -0
- package/src/core/context.ts +214 -0
- package/src/core/globalData.ts +77 -0
- package/src/core/history.ts +323 -0
- package/src/core/ide.ts +325 -0
- package/src/core/jsonl.ts +100 -0
- package/src/core/llmsContext.ts +117 -0
- package/src/core/loop.ts +638 -0
- package/src/core/message.ts +304 -0
- package/src/core/model.ts +2198 -0
- package/src/core/output-style/builtin/default.ts +9 -0
- package/src/core/output-style/builtin/explanatory.ts +22 -0
- package/src/core/output-style/builtin/index.ts +19 -0
- package/src/core/output-style/builtin/miao.ts +22 -0
- package/src/core/output-style/builtin/minimal.ts +8 -0
- package/src/core/output-style/types.ts +6 -0
- package/src/core/outputFormat.ts +93 -0
- package/src/core/outputStyle.ts +255 -0
- package/src/core/paths.ts +161 -0
- package/src/core/planSystemPrompt.ts +46 -0
- package/src/core/plugin.ts +299 -0
- package/src/core/project.ts +492 -0
- package/src/core/promptCache.ts +32 -0
- package/src/core/query.ts +46 -0
- package/src/core/rules.ts +56 -0
- package/src/core/systemPrompt.ts +176 -0
- package/src/core/thinking-config.ts +98 -0
- package/src/core/usage.ts +68 -0
- package/src/index.ts +39 -0
- package/src/mcp/mcp.ts +637 -0
- package/src/modes/builtin.ts +305 -0
- package/src/modes/index.ts +22 -0
- package/src/modes/registry.ts +39 -0
- package/src/modes/types.ts +56 -0
- package/src/platform/index.ts +6 -0
- package/src/platform/node.ts +108 -0
- package/src/platform/types.ts +54 -0
- package/src/plugins/index.ts +15 -0
- package/src/session/session.ts +187 -0
- package/src/skill/skill.ts +702 -0
- package/src/tools/tool.ts +378 -0
- package/src/tools/tools/askUserQuestion.ts +134 -0
- package/src/tools/tools/bash.test.ts +425 -0
- package/src/tools/tools/bash.ts +999 -0
- package/src/tools/tools/edit.ts +86 -0
- package/src/tools/tools/fetch.ts +129 -0
- package/src/tools/tools/glob.ts +69 -0
- package/src/tools/tools/grep.test.ts +194 -0
- package/src/tools/tools/grep.ts +358 -0
- package/src/tools/tools/ls.ts +51 -0
- package/src/tools/tools/read.test.ts +169 -0
- package/src/tools/tools/read.ts +284 -0
- package/src/tools/tools/skill.ts +73 -0
- package/src/tools/tools/task.test.ts +262 -0
- package/src/tools/tools/task.ts +284 -0
- package/src/tools/tools/todo.ts +269 -0
- package/src/tools/tools/write.ts +71 -0
- package/src/types.d.ts +18 -0
- package/src/utils/apiKeyRotation.test.ts +70 -0
- package/src/utils/apiKeyRotation.ts +24 -0
- package/src/utils/applyEdit.test.ts +388 -0
- package/src/utils/applyEdit.ts +547 -0
- package/src/utils/background-detection.test.ts +61 -0
- package/src/utils/background-detection.ts +58 -0
- package/src/utils/dotenv.ts +26 -0
- package/src/utils/env.ts +90 -0
- package/src/utils/error.ts +38 -0
- package/src/utils/execFileNoThrow.ts +49 -0
- package/src/utils/files.ts +93 -0
- package/src/utils/git.ts +1152 -0
- package/src/utils/ide.ts +279 -0
- package/src/utils/ignore.ts +275 -0
- package/src/utils/isLocal.ts +6 -0
- package/src/utils/language.ts +33 -0
- package/src/utils/list.ts +200 -0
- package/src/utils/mergeSystemMessagesMiddleware.ts +32 -0
- package/src/utils/messageNormalization.test.ts +401 -0
- package/src/utils/messageNormalization.ts +168 -0
- package/src/utils/path.ts +98 -0
- package/src/utils/prependSystemMessageMiddleware.ts +16 -0
- package/src/utils/project.ts +32 -0
- package/src/utils/proxy.ts +102 -0
- package/src/utils/randomUUID.ts +11 -0
- package/src/utils/renderSessionMarkdown.ts +175 -0
- package/src/utils/ripgrep.ts +189 -0
- package/src/utils/safeFrontMatter.test.ts +118 -0
- package/src/utils/safeFrontMatter.ts +68 -0
- package/src/utils/safeParseJson.ts +7 -0
- package/src/utils/safeStringify.ts +10 -0
- package/src/utils/sanitizeAIResponse.test.ts +135 -0
- package/src/utils/sanitizeAIResponse.ts +55 -0
- package/src/utils/setTerminalTitle.ts +7 -0
- package/src/utils/shell-execution.test.ts +237 -0
- package/src/utils/shell-execution.ts +279 -0
- package/src/utils/string.ts +13 -0
- package/src/utils/symbols.ts +18 -0
- package/src/utils/system-encoding.test.ts +164 -0
- package/src/utils/system-encoding.ts +296 -0
- package/src/utils/tokenCounter.test.ts +38 -0
- package/src/utils/tokenCounter.ts +19 -0
- package/src/utils/username.ts +21 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { LanguageModelV2Prompt } from '@ai-sdk/provider';
|
|
2
|
+
export declare class At {
|
|
3
|
+
private userPrompt;
|
|
4
|
+
private cwd;
|
|
5
|
+
constructor(opts: {
|
|
6
|
+
userPrompt: string;
|
|
7
|
+
cwd: string;
|
|
8
|
+
});
|
|
9
|
+
getContent(): string | null;
|
|
10
|
+
private extractAtPaths;
|
|
11
|
+
private renderDirectoriesToTree;
|
|
12
|
+
renderFilesToXml(fileEntries: Array<{
|
|
13
|
+
filePath: string;
|
|
14
|
+
lineRange?: {
|
|
15
|
+
start: number;
|
|
16
|
+
end?: number;
|
|
17
|
+
};
|
|
18
|
+
}>): string;
|
|
19
|
+
getAllFilesInDirectory(dirPath: string): string[];
|
|
20
|
+
private truncateLine;
|
|
21
|
+
private processFileContent;
|
|
22
|
+
static normalizeLanguageV2Prompt(opts: {
|
|
23
|
+
input: LanguageModelV2Prompt;
|
|
24
|
+
cwd: string;
|
|
25
|
+
}): LanguageModelV2Prompt;
|
|
26
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export interface BackgroundTask {
|
|
2
|
+
id: string;
|
|
3
|
+
command: string;
|
|
4
|
+
pid: number;
|
|
5
|
+
pgid?: number;
|
|
6
|
+
status: 'running' | 'completed' | 'killed' | 'failed';
|
|
7
|
+
createdAt: number;
|
|
8
|
+
output: string;
|
|
9
|
+
exitCode: number | null;
|
|
10
|
+
}
|
|
11
|
+
interface CreateTaskInput {
|
|
12
|
+
command: string;
|
|
13
|
+
pid: number;
|
|
14
|
+
pgid?: number;
|
|
15
|
+
}
|
|
16
|
+
export declare class BackgroundTaskManager {
|
|
17
|
+
private tasks;
|
|
18
|
+
createTask(input: CreateTaskInput): string;
|
|
19
|
+
getTask(id: string): BackgroundTask | null;
|
|
20
|
+
getAllTasks(): BackgroundTask[];
|
|
21
|
+
appendOutput(id: string, output: string): void;
|
|
22
|
+
updateTaskStatus(id: string, status: BackgroundTask['status'], exitCode?: number | null): void;
|
|
23
|
+
deleteTask(id: string): void;
|
|
24
|
+
private isProcessAlive;
|
|
25
|
+
killTask(id: string): Promise<boolean>;
|
|
26
|
+
}
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { NormalizedMessage } from '../core/message';
|
|
2
|
+
import type { ModelInfo } from '../core/model';
|
|
3
|
+
type CompactOptions = {
|
|
4
|
+
messages: NormalizedMessage[];
|
|
5
|
+
model: ModelInfo;
|
|
6
|
+
};
|
|
7
|
+
export declare const COMPACT_MESSAGE = "Chat history compacted successfully.";
|
|
8
|
+
export declare function compact(opts: CompactOptions): Promise<string>;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import type { Provider } from '../core/model';
|
|
2
|
+
export type McpStdioServerConfig = {
|
|
3
|
+
type: 'stdio';
|
|
4
|
+
command: string;
|
|
5
|
+
args: string[];
|
|
6
|
+
env?: Record<string, string>;
|
|
7
|
+
disable?: boolean;
|
|
8
|
+
};
|
|
9
|
+
export type McpSSEServerConfig = {
|
|
10
|
+
type: 'sse';
|
|
11
|
+
url: string;
|
|
12
|
+
disable?: boolean;
|
|
13
|
+
headers?: Record<string, string>;
|
|
14
|
+
};
|
|
15
|
+
export type McpHttpServerConfig = {
|
|
16
|
+
type: 'http';
|
|
17
|
+
url: string;
|
|
18
|
+
disable?: boolean;
|
|
19
|
+
headers?: Record<string, string>;
|
|
20
|
+
};
|
|
21
|
+
export type McpServerConfig = McpStdioServerConfig | McpSSEServerConfig | McpHttpServerConfig;
|
|
22
|
+
export type ApprovalMode = 'default' | 'autoEdit' | 'yolo';
|
|
23
|
+
export type AgentConfig = {
|
|
24
|
+
model?: string;
|
|
25
|
+
};
|
|
26
|
+
export type CommitConfig = {
|
|
27
|
+
language: string;
|
|
28
|
+
systemPrompt?: string;
|
|
29
|
+
model?: string;
|
|
30
|
+
};
|
|
31
|
+
export type ProviderConfig = Partial<Omit<Provider, 'createModel'>>;
|
|
32
|
+
export type DesktopConfig = {
|
|
33
|
+
theme?: 'light' | 'dark' | 'system';
|
|
34
|
+
sendMessageWith?: 'enter' | 'cmdEnter';
|
|
35
|
+
terminalFont?: string;
|
|
36
|
+
terminalFontSize?: number;
|
|
37
|
+
};
|
|
38
|
+
export type Config = {
|
|
39
|
+
model: string;
|
|
40
|
+
planModel: string;
|
|
41
|
+
smallModel?: string;
|
|
42
|
+
visionModel?: string;
|
|
43
|
+
language: string;
|
|
44
|
+
quiet: boolean;
|
|
45
|
+
approvalMode: ApprovalMode;
|
|
46
|
+
plugins: string[];
|
|
47
|
+
mcpServers: Record<string, McpServerConfig>;
|
|
48
|
+
provider?: Record<string, ProviderConfig>;
|
|
49
|
+
systemPrompt?: string;
|
|
50
|
+
todo?: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Controls whether automatic conversation compression is enabled.
|
|
53
|
+
* When set to false, conversation history will accumulate and context limit will be exceeded.
|
|
54
|
+
*
|
|
55
|
+
* @default true
|
|
56
|
+
*/
|
|
57
|
+
autoCompact?: boolean;
|
|
58
|
+
commit?: CommitConfig;
|
|
59
|
+
outputStyle?: string;
|
|
60
|
+
outputFormat?: 'text' | 'stream-json' | 'json';
|
|
61
|
+
autoUpdate?: boolean;
|
|
62
|
+
temperature?: number;
|
|
63
|
+
httpProxy?: string;
|
|
64
|
+
desktop?: DesktopConfig;
|
|
65
|
+
/**
|
|
66
|
+
* Extensions configuration for third-party custom agents.
|
|
67
|
+
* Allows arbitrary nested configuration without validation.
|
|
68
|
+
*/
|
|
69
|
+
extensions?: Record<string, any>;
|
|
70
|
+
/**
|
|
71
|
+
* Tools configuration for enabling/disabling specific tools.
|
|
72
|
+
* Key is the tool name, value is boolean (false to disable).
|
|
73
|
+
*/
|
|
74
|
+
tools?: Record<string, boolean>;
|
|
75
|
+
/**
|
|
76
|
+
* Agent configuration for customizing agent behavior per agent type.
|
|
77
|
+
* Example: { explore: { model: "anthropic/claude-haiku-4" } }
|
|
78
|
+
*/
|
|
79
|
+
agent?: Record<string, AgentConfig>;
|
|
80
|
+
/**
|
|
81
|
+
* Notification configuration.
|
|
82
|
+
* - true: play default sound (Funk/warning)
|
|
83
|
+
* - false: disabled
|
|
84
|
+
* - string: custom sound name (e.g., "Glass", "Ping")
|
|
85
|
+
* - object: extended notification config (reserved for future use, e.g., url)
|
|
86
|
+
*/
|
|
87
|
+
notification?: boolean | string;
|
|
88
|
+
};
|
|
89
|
+
export declare const GLOBAL_ONLY_KEYS: string[];
|
|
90
|
+
export declare class ConfigManager {
|
|
91
|
+
globalConfig: Partial<Config>;
|
|
92
|
+
projectConfig: Partial<Config>;
|
|
93
|
+
argvConfig: Partial<Config>;
|
|
94
|
+
globalConfigPath: string;
|
|
95
|
+
projectConfigPath: string;
|
|
96
|
+
constructor(cwd: string, productName: string, argvConfig: Partial<Config>);
|
|
97
|
+
get config(): Config;
|
|
98
|
+
removeConfig(global: boolean, key: string, values?: string[]): void;
|
|
99
|
+
addConfig(global: boolean, key: string, values: string[]): void;
|
|
100
|
+
getConfig(global: boolean, key: string): any;
|
|
101
|
+
setConfig(global: boolean, key: string, value: string): void;
|
|
102
|
+
updateConfig(global: boolean, newConfig: Partial<Config>): void;
|
|
103
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export declare const PRODUCT_NAME = "OriCore";
|
|
2
|
+
export declare const PRODUCT_ASCII_ART: string;
|
|
3
|
+
export declare const DEFAULT_OUTPUT_STYLE_NAME = "Default";
|
|
4
|
+
export declare const IMAGE_EXTENSIONS: Set<string>;
|
|
5
|
+
export declare const BINARY_EXTENSIONS: Set<string>;
|
|
6
|
+
export declare const CANCELED_MESSAGE_TEXT = "[Request interrupted by user]";
|
|
7
|
+
export declare enum TOOL_NAMES {
|
|
8
|
+
TODO_WRITE = "todoWrite",
|
|
9
|
+
BASH = "bash",
|
|
10
|
+
BASH_OUTPUT = "bash_output",
|
|
11
|
+
KILL_BASH = "kill_bash",
|
|
12
|
+
GREP = "grep",
|
|
13
|
+
ASK_USER_QUESTION = "AskUserQuestion",
|
|
14
|
+
READ = "read",
|
|
15
|
+
GLOB = "glob",
|
|
16
|
+
WRITE = "write",
|
|
17
|
+
EDIT = "edit",
|
|
18
|
+
LS = "ls",
|
|
19
|
+
TASK = "task"
|
|
20
|
+
}
|
|
21
|
+
export declare const BASH_EVENTS: {
|
|
22
|
+
readonly PROMPT_BACKGROUND: "bash:prompt_background";
|
|
23
|
+
readonly MOVE_TO_BACKGROUND: "bash:move_to_background";
|
|
24
|
+
readonly BACKGROUND_MOVED: "bash:background_moved";
|
|
25
|
+
};
|
|
26
|
+
export declare const MIN_TOKEN_THRESHOLD: number;
|
|
27
|
+
export declare const BACKGROUND_THRESHOLD_MS = 2000;
|
|
28
|
+
export declare enum AGENT_TYPE {
|
|
29
|
+
EXPLORE = "Explore",
|
|
30
|
+
PLAN = "Plan",
|
|
31
|
+
GENERAL_PURPOSE = "GeneralPurpose"
|
|
32
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { AgentManager } from '../agent/agent/agentManager';
|
|
2
|
+
import { BackgroundTaskManager } from './backgroundTaskManager';
|
|
3
|
+
import { type Config } from '../core/config';
|
|
4
|
+
import { MCPManager } from '../mcp/mcp';
|
|
5
|
+
import type { MessageBus } from '../communication/messageBus';
|
|
6
|
+
import { Paths } from './paths';
|
|
7
|
+
import { type Plugin, type PluginApplyOpts, PluginManager } from '../core/plugin';
|
|
8
|
+
import { SkillManager } from '../skill/skill';
|
|
9
|
+
type ContextOpts = {
|
|
10
|
+
cwd: string;
|
|
11
|
+
productName: string;
|
|
12
|
+
productASCIIArt?: string;
|
|
13
|
+
version: string;
|
|
14
|
+
config: Config;
|
|
15
|
+
pluginManager: PluginManager;
|
|
16
|
+
paths: Paths;
|
|
17
|
+
argvConfig: Record<string, any>;
|
|
18
|
+
mcpManager: MCPManager;
|
|
19
|
+
backgroundTaskManager: BackgroundTaskManager;
|
|
20
|
+
skillManager?: SkillManager;
|
|
21
|
+
messageBus?: MessageBus;
|
|
22
|
+
agentManager?: AgentManager;
|
|
23
|
+
plugins: (string | Plugin)[];
|
|
24
|
+
fetch?: typeof globalThis.fetch;
|
|
25
|
+
};
|
|
26
|
+
export type ContextCreateOpts = {
|
|
27
|
+
cwd: string;
|
|
28
|
+
productName: string;
|
|
29
|
+
productASCIIArt?: string;
|
|
30
|
+
version: string;
|
|
31
|
+
argvConfig: Record<string, any>;
|
|
32
|
+
plugins: (string | Plugin)[];
|
|
33
|
+
messageBus?: MessageBus;
|
|
34
|
+
fetch?: typeof globalThis.fetch;
|
|
35
|
+
};
|
|
36
|
+
export declare class Context {
|
|
37
|
+
#private;
|
|
38
|
+
cwd: string;
|
|
39
|
+
productName: string;
|
|
40
|
+
productASCIIArt?: string;
|
|
41
|
+
version: string;
|
|
42
|
+
config: Config;
|
|
43
|
+
paths: Paths;
|
|
44
|
+
argvConfig: Record<string, any>;
|
|
45
|
+
mcpManager: MCPManager;
|
|
46
|
+
backgroundTaskManager: BackgroundTaskManager;
|
|
47
|
+
skillManager?: SkillManager;
|
|
48
|
+
messageBus?: MessageBus;
|
|
49
|
+
agentManager?: AgentManager;
|
|
50
|
+
plugins: (string | Plugin)[];
|
|
51
|
+
fetch?: typeof globalThis.fetch;
|
|
52
|
+
constructor(opts: ContextOpts);
|
|
53
|
+
apply(applyOpts: Omit<PluginApplyOpts, 'pluginContext'>): Promise<any>;
|
|
54
|
+
destroy(): Promise<void>;
|
|
55
|
+
static create(opts: ContextCreateOpts): Promise<Context>;
|
|
56
|
+
}
|
|
57
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare class GlobalData {
|
|
2
|
+
private globalDataPath;
|
|
3
|
+
constructor({ globalDataPath }: {
|
|
4
|
+
globalDataPath: string;
|
|
5
|
+
});
|
|
6
|
+
private readData;
|
|
7
|
+
private writeData;
|
|
8
|
+
getProjectHistory({ cwd }: {
|
|
9
|
+
cwd: string;
|
|
10
|
+
}): string[];
|
|
11
|
+
addProjectHistory({ cwd, history }: {
|
|
12
|
+
cwd: string;
|
|
13
|
+
history: string;
|
|
14
|
+
}): void;
|
|
15
|
+
getProjectLastAccessed({ cwd }: {
|
|
16
|
+
cwd: string;
|
|
17
|
+
}): number | null;
|
|
18
|
+
updateProjectLastAccessed({ cwd }: {
|
|
19
|
+
cwd: string;
|
|
20
|
+
}): void;
|
|
21
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { LanguageModelV2Message } from '@ai-sdk/provider';
|
|
2
|
+
import type { Message, NormalizedMessage } from '../core/message';
|
|
3
|
+
import type { ModelInfo } from '../core/model';
|
|
4
|
+
export type OnMessage = (message: NormalizedMessage) => Promise<void>;
|
|
5
|
+
export type HistoryOpts = {
|
|
6
|
+
messages: NormalizedMessage[];
|
|
7
|
+
onMessage?: OnMessage;
|
|
8
|
+
};
|
|
9
|
+
export declare class History {
|
|
10
|
+
#private;
|
|
11
|
+
messages: NormalizedMessage[];
|
|
12
|
+
onMessage?: OnMessage;
|
|
13
|
+
constructor(opts: HistoryOpts);
|
|
14
|
+
addMessage(message: Message, uuid?: string): Promise<void>;
|
|
15
|
+
getMessagesToUuid(uuid: string): NormalizedMessage[];
|
|
16
|
+
toLanguageV2Messages(): LanguageModelV2Message[];
|
|
17
|
+
compress(model: ModelInfo): Promise<{
|
|
18
|
+
compressed: boolean;
|
|
19
|
+
summary?: undefined;
|
|
20
|
+
} | {
|
|
21
|
+
compressed: boolean;
|
|
22
|
+
summary: string;
|
|
23
|
+
}>;
|
|
24
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import WebSocket from 'ws';
|
|
2
|
+
import { type InstallationResult } from '../utils/ide';
|
|
3
|
+
interface BaseResponse {
|
|
4
|
+
success: boolean;
|
|
5
|
+
message?: string;
|
|
6
|
+
}
|
|
7
|
+
interface OpenFileResponse extends BaseResponse {
|
|
8
|
+
filePath?: string;
|
|
9
|
+
}
|
|
10
|
+
interface OpenDiffResponse extends BaseResponse {
|
|
11
|
+
message: string;
|
|
12
|
+
}
|
|
13
|
+
interface DiagnosticItem {
|
|
14
|
+
message: string;
|
|
15
|
+
severity: string;
|
|
16
|
+
range: {
|
|
17
|
+
start: {
|
|
18
|
+
line: number;
|
|
19
|
+
character: number;
|
|
20
|
+
};
|
|
21
|
+
end: {
|
|
22
|
+
line: number;
|
|
23
|
+
character: number;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
interface DiagnosticsResponse {
|
|
28
|
+
diagnostics: Array<{
|
|
29
|
+
uri: string;
|
|
30
|
+
diagnostics: DiagnosticItem[];
|
|
31
|
+
}>;
|
|
32
|
+
}
|
|
33
|
+
interface EditorInfo {
|
|
34
|
+
filePath: string;
|
|
35
|
+
isActive: boolean;
|
|
36
|
+
}
|
|
37
|
+
interface OpenEditorsResponse {
|
|
38
|
+
editors: EditorInfo[];
|
|
39
|
+
}
|
|
40
|
+
interface WorkspaceFolder {
|
|
41
|
+
name: string;
|
|
42
|
+
uri: string;
|
|
43
|
+
}
|
|
44
|
+
interface WorkspaceFoldersResponse {
|
|
45
|
+
folders: WorkspaceFolder[];
|
|
46
|
+
}
|
|
47
|
+
export interface SelectionInfo {
|
|
48
|
+
filePath: string;
|
|
49
|
+
text: string;
|
|
50
|
+
selection: {
|
|
51
|
+
start: {
|
|
52
|
+
line: number;
|
|
53
|
+
character: number;
|
|
54
|
+
};
|
|
55
|
+
end: {
|
|
56
|
+
line: number;
|
|
57
|
+
character: number;
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
export interface SelectionResponse extends SelectionInfo {
|
|
62
|
+
}
|
|
63
|
+
export interface SelectionErrorResponse {
|
|
64
|
+
error: string;
|
|
65
|
+
}
|
|
66
|
+
interface CloseTabResponse extends BaseResponse {
|
|
67
|
+
message: string;
|
|
68
|
+
}
|
|
69
|
+
interface CloseAllDiffTabsResponse extends BaseResponse {
|
|
70
|
+
closedCount: number;
|
|
71
|
+
}
|
|
72
|
+
export type SelectionResult = SelectionResponse | SelectionErrorResponse;
|
|
73
|
+
interface WSMessage {
|
|
74
|
+
id?: number;
|
|
75
|
+
error?: {
|
|
76
|
+
message: string;
|
|
77
|
+
};
|
|
78
|
+
result?: unknown;
|
|
79
|
+
}
|
|
80
|
+
export declare class IDE {
|
|
81
|
+
ws: WebSocket | null;
|
|
82
|
+
private requestId;
|
|
83
|
+
private pendingRequests;
|
|
84
|
+
constructor();
|
|
85
|
+
findPort(): Promise<number | undefined>;
|
|
86
|
+
connect(): Promise<void>;
|
|
87
|
+
disconnect(): Promise<void>;
|
|
88
|
+
handleMessage(message: WSMessage): void;
|
|
89
|
+
request(method: string, params?: Record<string, unknown>): Promise<unknown>;
|
|
90
|
+
openFile(filePath: string, options?: {
|
|
91
|
+
preview?: boolean;
|
|
92
|
+
}): Promise<OpenFileResponse>;
|
|
93
|
+
openDiff(old_file_path: string, new_file_path: string, new_file_contents: string, tab_name: string): Promise<OpenDiffResponse>;
|
|
94
|
+
getWorkspaceFolders(): Promise<WorkspaceFoldersResponse>;
|
|
95
|
+
getOpenEditors(): Promise<OpenEditorsResponse>;
|
|
96
|
+
getDiagnostics(): Promise<DiagnosticsResponse>;
|
|
97
|
+
getCurrentSelection(): Promise<SelectionResult>;
|
|
98
|
+
getLatestSelection(): Promise<SelectionResult>;
|
|
99
|
+
closeTab(tab_name: string): Promise<CloseTabResponse>;
|
|
100
|
+
closeAllDiffTabs(): Promise<CloseAllDiffTabsResponse>;
|
|
101
|
+
setupIDEIntegration(terminal: string): Promise<InstallationResult | undefined>;
|
|
102
|
+
}
|
|
103
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { NormalizedMessage } from './message';
|
|
2
|
+
import type { StreamResult } from './loop';
|
|
3
|
+
export declare class JsonlLogger {
|
|
4
|
+
filePath: string;
|
|
5
|
+
lastUuid: string | null;
|
|
6
|
+
constructor(opts: {
|
|
7
|
+
filePath: string;
|
|
8
|
+
});
|
|
9
|
+
getLatestUuid(): any;
|
|
10
|
+
addMessage(opts: {
|
|
11
|
+
message: NormalizedMessage & {
|
|
12
|
+
sessionId: string;
|
|
13
|
+
};
|
|
14
|
+
}): NormalizedMessage & {
|
|
15
|
+
sessionId: string;
|
|
16
|
+
};
|
|
17
|
+
addUserMessage(content: string, sessionId: string): NormalizedMessage & {
|
|
18
|
+
sessionId: string;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export declare class RequestLogger {
|
|
22
|
+
globalProjectDir: string;
|
|
23
|
+
constructor(opts: {
|
|
24
|
+
globalProjectDir: string;
|
|
25
|
+
});
|
|
26
|
+
private getFilePath;
|
|
27
|
+
logMetadata(opts: {
|
|
28
|
+
requestId: string;
|
|
29
|
+
prompt: StreamResult['prompt'];
|
|
30
|
+
model: StreamResult['model'];
|
|
31
|
+
tools: StreamResult['tools'];
|
|
32
|
+
request?: StreamResult['request'];
|
|
33
|
+
response?: StreamResult['response'];
|
|
34
|
+
error?: StreamResult['error'];
|
|
35
|
+
}): void;
|
|
36
|
+
logChunk(requestId: string, chunk: any): void;
|
|
37
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Context } from './context';
|
|
2
|
+
export type LlmsContextCreateOpts = {
|
|
3
|
+
context: Context;
|
|
4
|
+
sessionId: string;
|
|
5
|
+
userPrompt: string | null;
|
|
6
|
+
additionalDirectories?: string[];
|
|
7
|
+
};
|
|
8
|
+
export declare class LlmsContext {
|
|
9
|
+
messages: string[];
|
|
10
|
+
constructor(opts: {
|
|
11
|
+
messages: string[];
|
|
12
|
+
});
|
|
13
|
+
static create(opts: LlmsContextCreateOpts): Promise<LlmsContext>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { LanguageModelV2FunctionTool, LanguageModelV2Prompt, SharedV2Headers } from '@ai-sdk/provider';
|
|
2
|
+
import { type OnMessage } from '../core/history';
|
|
3
|
+
import { type NormalizedMessage } from '../core/message';
|
|
4
|
+
import type { ModelInfo } from '../core/model';
|
|
5
|
+
import { type ReasoningEffort } from './thinking-config';
|
|
6
|
+
import type { ToolApprovalResult, ToolResult, Tools, ToolUse } from '../tools/tool';
|
|
7
|
+
import { Usage } from '../core/usage';
|
|
8
|
+
export type LoopResult = {
|
|
9
|
+
success: true;
|
|
10
|
+
data: Record<string, any>;
|
|
11
|
+
metadata: {
|
|
12
|
+
turnsCount: number;
|
|
13
|
+
toolCallsCount: number;
|
|
14
|
+
duration: number;
|
|
15
|
+
};
|
|
16
|
+
} | {
|
|
17
|
+
success: false;
|
|
18
|
+
error: {
|
|
19
|
+
type: 'tool_denied' | 'max_turns_exceeded' | 'api_error' | 'canceled';
|
|
20
|
+
message: string;
|
|
21
|
+
details?: Record<string, any>;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
type StreamResultBase = {
|
|
25
|
+
requestId: string;
|
|
26
|
+
prompt: LanguageModelV2Prompt;
|
|
27
|
+
model: ModelInfo;
|
|
28
|
+
tools: LanguageModelV2FunctionTool[];
|
|
29
|
+
};
|
|
30
|
+
export type StreamResult = StreamResultBase & {
|
|
31
|
+
request?: {
|
|
32
|
+
body?: unknown;
|
|
33
|
+
};
|
|
34
|
+
response?: {
|
|
35
|
+
headers?: SharedV2Headers;
|
|
36
|
+
statusCode?: number;
|
|
37
|
+
body?: unknown;
|
|
38
|
+
};
|
|
39
|
+
error?: any;
|
|
40
|
+
};
|
|
41
|
+
export type ResponseFormat = {
|
|
42
|
+
type: 'text';
|
|
43
|
+
} | {
|
|
44
|
+
type: 'json';
|
|
45
|
+
schema?: any;
|
|
46
|
+
name?: string;
|
|
47
|
+
description?: string;
|
|
48
|
+
};
|
|
49
|
+
export type ThinkingConfig = {
|
|
50
|
+
effort: ReasoningEffort;
|
|
51
|
+
};
|
|
52
|
+
type RunLoopOpts = {
|
|
53
|
+
input: string | NormalizedMessage[];
|
|
54
|
+
model: ModelInfo;
|
|
55
|
+
tools: Tools;
|
|
56
|
+
cwd: string;
|
|
57
|
+
systemPrompt?: string;
|
|
58
|
+
maxTurns?: number;
|
|
59
|
+
errorRetryTurns?: number;
|
|
60
|
+
signal?: AbortSignal;
|
|
61
|
+
llmsContexts?: string[];
|
|
62
|
+
autoCompact?: boolean;
|
|
63
|
+
thinking?: ThinkingConfig;
|
|
64
|
+
temperature?: number;
|
|
65
|
+
responseFormat?: ResponseFormat;
|
|
66
|
+
onTextDelta?: (text: string) => Promise<void>;
|
|
67
|
+
onText?: (text: string) => Promise<void>;
|
|
68
|
+
onReasoning?: (text: string) => Promise<void>;
|
|
69
|
+
onStreamResult?: (result: StreamResult) => Promise<void>;
|
|
70
|
+
onChunk?: (chunk: any, requestId: string) => Promise<void>;
|
|
71
|
+
onToolUse?: (toolUse: ToolUse) => Promise<ToolUse>;
|
|
72
|
+
onToolResult?: (toolUse: ToolUse, toolResult: ToolResult, approved: boolean) => Promise<ToolResult>;
|
|
73
|
+
onTurn?: (turn: {
|
|
74
|
+
usage: Usage;
|
|
75
|
+
startTime: Date;
|
|
76
|
+
endTime: Date;
|
|
77
|
+
}) => Promise<void>;
|
|
78
|
+
onToolApprove?: (toolUse: ToolUse) => Promise<ToolApprovalResult>;
|
|
79
|
+
onMessage?: OnMessage;
|
|
80
|
+
};
|
|
81
|
+
export declare function runLoop(opts: RunLoopOpts): Promise<LoopResult>;
|
|
82
|
+
export {};
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import type { ToolResult } from '../tools/tool';
|
|
2
|
+
export type SystemMessage = {
|
|
3
|
+
role: 'system';
|
|
4
|
+
content: string;
|
|
5
|
+
};
|
|
6
|
+
export type TextPart = {
|
|
7
|
+
type: 'text';
|
|
8
|
+
text: string;
|
|
9
|
+
};
|
|
10
|
+
export type ImagePart = {
|
|
11
|
+
type: 'image';
|
|
12
|
+
data: string;
|
|
13
|
+
mimeType: string;
|
|
14
|
+
};
|
|
15
|
+
export type FilePart = {
|
|
16
|
+
type: 'file';
|
|
17
|
+
filename?: string;
|
|
18
|
+
data: string;
|
|
19
|
+
mimeType: string;
|
|
20
|
+
};
|
|
21
|
+
export type UserContent = string | Array<TextPart | ImagePart>;
|
|
22
|
+
export type ToolUsePart = {
|
|
23
|
+
type: 'tool_use';
|
|
24
|
+
id: string;
|
|
25
|
+
name: string;
|
|
26
|
+
input: Record<string, any>;
|
|
27
|
+
displayName?: string;
|
|
28
|
+
description?: string;
|
|
29
|
+
};
|
|
30
|
+
export type ReasoningPart = {
|
|
31
|
+
type: 'reasoning';
|
|
32
|
+
text: string;
|
|
33
|
+
};
|
|
34
|
+
export type AssistantContent = string | Array<TextPart | ReasoningPart | ToolUsePart>;
|
|
35
|
+
export type AssistantMessage = {
|
|
36
|
+
role: 'assistant';
|
|
37
|
+
content: AssistantContent;
|
|
38
|
+
text: string;
|
|
39
|
+
model: string;
|
|
40
|
+
usage: {
|
|
41
|
+
input_tokens: number;
|
|
42
|
+
output_tokens: number;
|
|
43
|
+
cache_read_input_tokens?: number;
|
|
44
|
+
cache_creation_input_tokens?: number;
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
export type UserMessage = {
|
|
48
|
+
role: 'user';
|
|
49
|
+
content: UserContent;
|
|
50
|
+
hidden?: boolean;
|
|
51
|
+
};
|
|
52
|
+
export type ToolMessage = {
|
|
53
|
+
role: 'user';
|
|
54
|
+
content: ToolContent;
|
|
55
|
+
};
|
|
56
|
+
export type ToolMessage2 = {
|
|
57
|
+
role: 'tool';
|
|
58
|
+
content: ToolResultPart2[];
|
|
59
|
+
};
|
|
60
|
+
export type ToolResultPart2 = {
|
|
61
|
+
type: 'tool-result';
|
|
62
|
+
toolCallId: string;
|
|
63
|
+
toolName: string;
|
|
64
|
+
input: Record<string, any>;
|
|
65
|
+
result: ToolResult;
|
|
66
|
+
agentId?: string;
|
|
67
|
+
agentType?: string;
|
|
68
|
+
};
|
|
69
|
+
export type ToolContent = Array<ToolResultPart>;
|
|
70
|
+
export type ToolResultPart = {
|
|
71
|
+
type: 'tool_result';
|
|
72
|
+
id: string;
|
|
73
|
+
name: string;
|
|
74
|
+
input: Record<string, any>;
|
|
75
|
+
result: ToolResult;
|
|
76
|
+
agentId?: string;
|
|
77
|
+
agentType?: string;
|
|
78
|
+
};
|
|
79
|
+
export type Message = SystemMessage | UserMessage | AssistantMessage | ToolMessage | ToolMessage2;
|
|
80
|
+
export type NormalizedMessage = Message & {
|
|
81
|
+
type: 'message';
|
|
82
|
+
timestamp: string;
|
|
83
|
+
uuid: string;
|
|
84
|
+
parentUuid: string | null;
|
|
85
|
+
uiContent?: string;
|
|
86
|
+
metadata?: {
|
|
87
|
+
agentId?: string;
|
|
88
|
+
agentType?: string;
|
|
89
|
+
[key: string]: any;
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
export type SDKSystemMessage = {
|
|
93
|
+
type: 'system';
|
|
94
|
+
subtype: 'init';
|
|
95
|
+
sessionId: string;
|
|
96
|
+
model: string;
|
|
97
|
+
cwd: string;
|
|
98
|
+
tools: string[];
|
|
99
|
+
};
|
|
100
|
+
export type SDKResultMessage = {
|
|
101
|
+
type: 'result';
|
|
102
|
+
subtype: 'success' | 'error';
|
|
103
|
+
isError: boolean;
|
|
104
|
+
content: string;
|
|
105
|
+
sessionId: string;
|
|
106
|
+
__result?: any;
|
|
107
|
+
usage?: {
|
|
108
|
+
input_tokens: number;
|
|
109
|
+
output_tokens: number;
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
export declare function toolResultPart2ToToolResultPart(part: ToolResultPart2): ToolResultPart;
|
|
113
|
+
export declare function createToolResultPart2(toolCallId: string, toolName: string, input: Record<string, any>, result: ToolResult): ToolResultPart2;
|
|
114
|
+
export declare function createUserMessage(content: string, parentUuid: string | null): NormalizedMessage;
|
|
115
|
+
export declare function isToolResultMessage(message: Message): boolean;
|
|
116
|
+
export declare function isCanceledMessage(message: Message): boolean;
|
|
117
|
+
export declare function isUserTextMessage(message: Message): boolean;
|
|
118
|
+
export declare function isUserBashCommandMessage(message: Message): boolean;
|
|
119
|
+
export declare function isUserBashOutputMessage(message: Message): boolean;
|
|
120
|
+
export declare function getMessageText(message: Message): string;
|
|
121
|
+
/**
|
|
122
|
+
* Finds tool uses in the last assistant message that don't have corresponding tool results.
|
|
123
|
+
* This is useful for identifying incomplete tool executions, such as when a session is canceled
|
|
124
|
+
* before all tools have finished executing.
|
|
125
|
+
*
|
|
126
|
+
* @param messages - Array of normalized messages to analyze
|
|
127
|
+
* @returns Object containing the assistant message and incomplete tool uses, or null if none found
|
|
128
|
+
*/
|
|
129
|
+
export declare function findIncompleteToolUses(messages: NormalizedMessage[]): {
|
|
130
|
+
assistantMessage: NormalizedMessage;
|
|
131
|
+
incompleteToolUses: ToolUsePart[];
|
|
132
|
+
} | null;
|