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,187 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'pathe';
|
|
3
|
+
import type { ApprovalMode } from '../core/config';
|
|
4
|
+
import { History } from '../core/history';
|
|
5
|
+
import type { NormalizedMessage } from '../core/message';
|
|
6
|
+
import { Usage } from '../core/usage';
|
|
7
|
+
import { randomUUID } from '../utils/randomUUID';
|
|
8
|
+
|
|
9
|
+
export type SessionId = string;
|
|
10
|
+
|
|
11
|
+
export class Session {
|
|
12
|
+
id: SessionId;
|
|
13
|
+
usage: Usage;
|
|
14
|
+
history: History;
|
|
15
|
+
constructor(opts: { id: SessionId; history?: History }) {
|
|
16
|
+
this.id = opts.id;
|
|
17
|
+
this.usage = Usage.empty();
|
|
18
|
+
this.history = opts.history || new History({ messages: [] });
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
updateHistory(history: History) {
|
|
22
|
+
this.history = history;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
static create() {
|
|
26
|
+
return new Session({
|
|
27
|
+
id: Session.createSessionId(),
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
static createSessionId() {
|
|
32
|
+
return randomUUID().slice(0, 8);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
static resume(opts: { id: SessionId; logPath: string }) {
|
|
36
|
+
const messages = loadSessionMessages({ logPath: opts.logPath });
|
|
37
|
+
const history = new History({
|
|
38
|
+
messages,
|
|
39
|
+
});
|
|
40
|
+
return new Session({
|
|
41
|
+
id: opts.id,
|
|
42
|
+
history,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export type SessionConfig = {
|
|
48
|
+
model?: string;
|
|
49
|
+
approvalMode?: ApprovalMode;
|
|
50
|
+
approvalTools: string[];
|
|
51
|
+
summary?: string;
|
|
52
|
+
pastedTextMap?: Record<string, string>;
|
|
53
|
+
pastedImageMap?: Record<string, string>;
|
|
54
|
+
additionalDirectories?: string[];
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const DEFAULT_SESSION_CONFIG: SessionConfig = {
|
|
58
|
+
approvalMode: 'default',
|
|
59
|
+
approvalTools: [],
|
|
60
|
+
pastedTextMap: {},
|
|
61
|
+
pastedImageMap: {},
|
|
62
|
+
additionalDirectories: [],
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export class SessionConfigManager {
|
|
66
|
+
logPath: string;
|
|
67
|
+
config: SessionConfig;
|
|
68
|
+
constructor(opts: { logPath: string }) {
|
|
69
|
+
this.logPath = opts.logPath;
|
|
70
|
+
this.config = this.load(opts.logPath);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
load(logPath: string): SessionConfig {
|
|
74
|
+
if (!fs.existsSync(logPath)) {
|
|
75
|
+
return DEFAULT_SESSION_CONFIG;
|
|
76
|
+
}
|
|
77
|
+
try {
|
|
78
|
+
const content = fs.readFileSync(logPath, 'utf-8');
|
|
79
|
+
const lines = content.split('\n').filter(Boolean);
|
|
80
|
+
for (const line of lines) {
|
|
81
|
+
try {
|
|
82
|
+
const parsed = JSON.parse(line);
|
|
83
|
+
if (parsed.type === 'config') {
|
|
84
|
+
return parsed.config;
|
|
85
|
+
}
|
|
86
|
+
} catch {}
|
|
87
|
+
}
|
|
88
|
+
return DEFAULT_SESSION_CONFIG;
|
|
89
|
+
} catch {
|
|
90
|
+
return DEFAULT_SESSION_CONFIG;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
write() {
|
|
94
|
+
// TODO: add write lock
|
|
95
|
+
const configLine = JSON.stringify({ type: 'config', config: this.config });
|
|
96
|
+
if (!fs.existsSync(this.logPath)) {
|
|
97
|
+
fs.mkdirSync(path.dirname(this.logPath), { recursive: true });
|
|
98
|
+
fs.writeFileSync(this.logPath, configLine + '\n', 'utf-8');
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
try {
|
|
102
|
+
const content = fs.readFileSync(this.logPath, 'utf-8');
|
|
103
|
+
const lines = content.split('\n');
|
|
104
|
+
const filteredLines = lines.filter((line) => {
|
|
105
|
+
if (!line) return false;
|
|
106
|
+
try {
|
|
107
|
+
const parsed = JSON.parse(line);
|
|
108
|
+
return parsed.type !== 'config';
|
|
109
|
+
} catch {
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
const newContent = [configLine, ...filteredLines].join('\n');
|
|
114
|
+
fs.writeFileSync(this.logPath, newContent + '\n', 'utf-8');
|
|
115
|
+
} catch (e: any) {
|
|
116
|
+
throw new Error(
|
|
117
|
+
`Failed to write config to log file: ${this.logPath}: ${e.message}`,
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export function filterMessages(
|
|
124
|
+
messages: NormalizedMessage[],
|
|
125
|
+
): NormalizedMessage[] {
|
|
126
|
+
// Filter to message types only
|
|
127
|
+
const messageTypeOnly = messages.filter((message) => {
|
|
128
|
+
const isMessage = message.type === 'message';
|
|
129
|
+
return isMessage;
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
if (messageTypeOnly.length === 0) {
|
|
133
|
+
return [];
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// Create a map for O(1) uuid lookups
|
|
137
|
+
const messageMap = new Map<string, NormalizedMessage>();
|
|
138
|
+
for (const message of messageTypeOnly) {
|
|
139
|
+
messageMap.set(message.uuid, message);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// Start from the last message and walk backward to build the active path
|
|
143
|
+
const activePath = new Set<string>();
|
|
144
|
+
let currentMessage = messageTypeOnly[messageTypeOnly.length - 1];
|
|
145
|
+
|
|
146
|
+
while (currentMessage) {
|
|
147
|
+
activePath.add(currentMessage.uuid);
|
|
148
|
+
// Stop if we reached the root (null parent)
|
|
149
|
+
if (currentMessage.parentUuid === null) {
|
|
150
|
+
break;
|
|
151
|
+
}
|
|
152
|
+
// Move to parent if it exists
|
|
153
|
+
const parentMessage = messageMap.get(currentMessage.parentUuid);
|
|
154
|
+
if (!parentMessage) {
|
|
155
|
+
// Parent doesn't exist, stop traversal
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
currentMessage = parentMessage;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// Filter original messages to only include those in the active path
|
|
162
|
+
return messageTypeOnly.filter((message) => activePath.has(message.uuid));
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export function loadSessionMessages(opts: {
|
|
166
|
+
logPath: string;
|
|
167
|
+
}): NormalizedMessage[] {
|
|
168
|
+
if (!fs.existsSync(opts.logPath)) {
|
|
169
|
+
return [];
|
|
170
|
+
}
|
|
171
|
+
const content = fs.readFileSync(opts.logPath, 'utf-8');
|
|
172
|
+
const messages = content
|
|
173
|
+
.split('\n')
|
|
174
|
+
.filter(Boolean)
|
|
175
|
+
.map((line, index) => {
|
|
176
|
+
try {
|
|
177
|
+
return JSON.parse(line);
|
|
178
|
+
} catch (e: any) {
|
|
179
|
+
throw new Error(
|
|
180
|
+
`Failed to parse line ${index + 1} of log file: ${opts.logPath}: ${
|
|
181
|
+
e.message
|
|
182
|
+
}`,
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
return filterMessages(messages);
|
|
187
|
+
}
|