opencara 0.0.1
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/commands/agent.d.ts +46 -0
- package/dist/commands/agent.d.ts.map +1 -0
- package/dist/commands/agent.js +924 -0
- package/dist/commands/agent.js.map +1 -0
- package/dist/commands/login.d.ts +5 -0
- package/dist/commands/login.d.ts.map +1 -0
- package/dist/commands/login.js +102 -0
- package/dist/commands/login.js.map +1 -0
- package/dist/commands/stats.d.ts +9 -0
- package/dist/commands/stats.d.ts.map +1 -0
- package/dist/commands/stats.js +187 -0
- package/dist/commands/stats.js.map +1 -0
- package/dist/config.d.ts +48 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +227 -0
- package/dist/config.js.map +1 -0
- package/dist/consumption.d.ts +21 -0
- package/dist/consumption.d.ts.map +1 -0
- package/dist/consumption.js +18 -0
- package/dist/consumption.js.map +1 -0
- package/dist/http.d.ts +14 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/http.js +59 -0
- package/dist/http.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/dist/reconnect.d.ts +10 -0
- package/dist/reconnect.d.ts.map +1 -0
- package/dist/reconnect.js +17 -0
- package/dist/reconnect.js.map +1 -0
- package/dist/review.d.ts +34 -0
- package/dist/review.d.ts.map +1 -0
- package/dist/review.js +109 -0
- package/dist/review.js.map +1 -0
- package/dist/summary.d.ts +34 -0
- package/dist/summary.d.ts.map +1 -0
- package/dist/summary.js +90 -0
- package/dist/summary.js.map +1 -0
- package/dist/tool-executor.d.ts +50 -0
- package/dist/tool-executor.d.ts.map +1 -0
- package/dist/tool-executor.js +232 -0
- package/dist/tool-executor.js.map +1 -0
- package/package.json +27 -0
package/dist/config.js
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import * as fs from 'node:fs';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
import * as os from 'node:os';
|
|
4
|
+
import { parse, stringify } from 'yaml';
|
|
5
|
+
export const DEFAULT_PLATFORM_URL = 'https://api.opencara.dev';
|
|
6
|
+
export const CONFIG_DIR = path.join(os.homedir(), '.opencara');
|
|
7
|
+
export const CONFIG_FILE = path.join(CONFIG_DIR, 'config.yml');
|
|
8
|
+
export function ensureConfigDir() {
|
|
9
|
+
fs.mkdirSync(CONFIG_DIR, { recursive: true });
|
|
10
|
+
}
|
|
11
|
+
export const DEFAULT_MAX_DIFF_SIZE_KB = 100;
|
|
12
|
+
function parseLimits(data) {
|
|
13
|
+
const raw = data.limits;
|
|
14
|
+
if (!raw || typeof raw !== 'object')
|
|
15
|
+
return null;
|
|
16
|
+
const obj = raw;
|
|
17
|
+
const limits = {};
|
|
18
|
+
if (typeof obj.tokens_per_day === 'number')
|
|
19
|
+
limits.tokens_per_day = obj.tokens_per_day;
|
|
20
|
+
if (typeof obj.tokens_per_month === 'number')
|
|
21
|
+
limits.tokens_per_month = obj.tokens_per_month;
|
|
22
|
+
if (typeof obj.reviews_per_day === 'number')
|
|
23
|
+
limits.reviews_per_day = obj.reviews_per_day;
|
|
24
|
+
if (Object.keys(limits).length === 0)
|
|
25
|
+
return null;
|
|
26
|
+
return limits;
|
|
27
|
+
}
|
|
28
|
+
const VALID_REPO_MODES = ['all', 'own', 'whitelist', 'blacklist'];
|
|
29
|
+
const REPO_PATTERN = /^[^/]+\/[^/]+$/;
|
|
30
|
+
export class RepoConfigError extends Error {
|
|
31
|
+
constructor(message) {
|
|
32
|
+
super(message);
|
|
33
|
+
this.name = 'RepoConfigError';
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function parseRepoConfig(obj, index) {
|
|
37
|
+
const raw = obj.repos;
|
|
38
|
+
if (raw === undefined || raw === null)
|
|
39
|
+
return undefined;
|
|
40
|
+
if (typeof raw !== 'object') {
|
|
41
|
+
throw new RepoConfigError(`agents[${index}].repos must be an object`);
|
|
42
|
+
}
|
|
43
|
+
const reposObj = raw;
|
|
44
|
+
const mode = reposObj.mode;
|
|
45
|
+
if (mode === undefined) {
|
|
46
|
+
throw new RepoConfigError(`agents[${index}].repos.mode is required`);
|
|
47
|
+
}
|
|
48
|
+
if (typeof mode !== 'string' || !VALID_REPO_MODES.includes(mode)) {
|
|
49
|
+
throw new RepoConfigError(`agents[${index}].repos.mode must be one of: ${VALID_REPO_MODES.join(', ')}`);
|
|
50
|
+
}
|
|
51
|
+
const config = { mode: mode };
|
|
52
|
+
if (mode === 'whitelist' || mode === 'blacklist') {
|
|
53
|
+
const list = reposObj.list;
|
|
54
|
+
if (!Array.isArray(list) || list.length === 0) {
|
|
55
|
+
throw new RepoConfigError(`agents[${index}].repos.list is required and must be non-empty for mode '${mode}'`);
|
|
56
|
+
}
|
|
57
|
+
for (let j = 0; j < list.length; j++) {
|
|
58
|
+
if (typeof list[j] !== 'string' || !REPO_PATTERN.test(list[j])) {
|
|
59
|
+
throw new RepoConfigError(`agents[${index}].repos.list[${j}] must match 'owner/repo' format`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
config.list = list;
|
|
63
|
+
}
|
|
64
|
+
return config;
|
|
65
|
+
}
|
|
66
|
+
function parseAnonymousAgents(data) {
|
|
67
|
+
const raw = data.anonymous_agents;
|
|
68
|
+
if (!Array.isArray(raw))
|
|
69
|
+
return [];
|
|
70
|
+
const entries = [];
|
|
71
|
+
for (let i = 0; i < raw.length; i++) {
|
|
72
|
+
const entry = raw[i];
|
|
73
|
+
if (!entry || typeof entry !== 'object') {
|
|
74
|
+
console.warn(`Warning: anonymous_agents[${i}] is not an object, skipping`);
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
const obj = entry;
|
|
78
|
+
if (typeof obj.agent_id !== 'string' ||
|
|
79
|
+
typeof obj.api_key !== 'string' ||
|
|
80
|
+
typeof obj.model !== 'string' ||
|
|
81
|
+
typeof obj.tool !== 'string') {
|
|
82
|
+
console.warn(`Warning: anonymous_agents[${i}] missing required agent_id/api_key/model/tool fields, skipping`);
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
const anon = {
|
|
86
|
+
agentId: obj.agent_id,
|
|
87
|
+
apiKey: obj.api_key,
|
|
88
|
+
model: obj.model,
|
|
89
|
+
tool: obj.tool,
|
|
90
|
+
};
|
|
91
|
+
if (obj.repo_config && typeof obj.repo_config === 'object') {
|
|
92
|
+
const rc = obj.repo_config;
|
|
93
|
+
if (typeof rc.mode === 'string' && VALID_REPO_MODES.includes(rc.mode)) {
|
|
94
|
+
const repoConfig = { mode: rc.mode };
|
|
95
|
+
if (Array.isArray(rc.list)) {
|
|
96
|
+
repoConfig.list = rc.list.filter((v) => typeof v === 'string');
|
|
97
|
+
}
|
|
98
|
+
anon.repoConfig = repoConfig;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
entries.push(anon);
|
|
102
|
+
}
|
|
103
|
+
return entries;
|
|
104
|
+
}
|
|
105
|
+
function parseAgents(data) {
|
|
106
|
+
if (!('agents' in data))
|
|
107
|
+
return null;
|
|
108
|
+
const raw = data.agents;
|
|
109
|
+
if (!Array.isArray(raw))
|
|
110
|
+
return null;
|
|
111
|
+
const agents = [];
|
|
112
|
+
for (let i = 0; i < raw.length; i++) {
|
|
113
|
+
const entry = raw[i];
|
|
114
|
+
if (!entry || typeof entry !== 'object') {
|
|
115
|
+
console.warn(`Warning: agents[${i}] is not an object, skipping`);
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
const obj = entry;
|
|
119
|
+
if (typeof obj.model !== 'string' || typeof obj.tool !== 'string') {
|
|
120
|
+
console.warn(`Warning: agents[${i}] missing required model/tool fields, skipping`);
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
const agent = { model: obj.model, tool: obj.tool };
|
|
124
|
+
if (typeof obj.command === 'string')
|
|
125
|
+
agent.command = obj.command;
|
|
126
|
+
const agentLimits = parseLimits(obj);
|
|
127
|
+
if (agentLimits)
|
|
128
|
+
agent.limits = agentLimits;
|
|
129
|
+
const repoConfig = parseRepoConfig(obj, i);
|
|
130
|
+
if (repoConfig)
|
|
131
|
+
agent.repos = repoConfig;
|
|
132
|
+
agents.push(agent);
|
|
133
|
+
}
|
|
134
|
+
return agents;
|
|
135
|
+
}
|
|
136
|
+
export function loadConfig() {
|
|
137
|
+
const defaults = {
|
|
138
|
+
apiKey: null,
|
|
139
|
+
platformUrl: DEFAULT_PLATFORM_URL,
|
|
140
|
+
maxDiffSizeKb: DEFAULT_MAX_DIFF_SIZE_KB,
|
|
141
|
+
limits: null,
|
|
142
|
+
agentCommand: null,
|
|
143
|
+
agents: null,
|
|
144
|
+
anonymousAgents: [],
|
|
145
|
+
};
|
|
146
|
+
if (!fs.existsSync(CONFIG_FILE)) {
|
|
147
|
+
return defaults;
|
|
148
|
+
}
|
|
149
|
+
const raw = fs.readFileSync(CONFIG_FILE, 'utf-8');
|
|
150
|
+
const data = parse(raw);
|
|
151
|
+
if (!data || typeof data !== 'object') {
|
|
152
|
+
return defaults;
|
|
153
|
+
}
|
|
154
|
+
return {
|
|
155
|
+
apiKey: typeof data.api_key === 'string' ? data.api_key : null,
|
|
156
|
+
platformUrl: typeof data.platform_url === 'string' ? data.platform_url : DEFAULT_PLATFORM_URL,
|
|
157
|
+
maxDiffSizeKb: typeof data.max_diff_size_kb === 'number' ? data.max_diff_size_kb : DEFAULT_MAX_DIFF_SIZE_KB,
|
|
158
|
+
limits: parseLimits(data),
|
|
159
|
+
agentCommand: typeof data.agent_command === 'string' ? data.agent_command : null,
|
|
160
|
+
agents: parseAgents(data),
|
|
161
|
+
anonymousAgents: parseAnonymousAgents(data),
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
export function saveConfig(config) {
|
|
165
|
+
ensureConfigDir();
|
|
166
|
+
const data = {
|
|
167
|
+
platform_url: config.platformUrl,
|
|
168
|
+
};
|
|
169
|
+
if (config.apiKey) {
|
|
170
|
+
data.api_key = config.apiKey;
|
|
171
|
+
}
|
|
172
|
+
if (config.maxDiffSizeKb !== DEFAULT_MAX_DIFF_SIZE_KB) {
|
|
173
|
+
data.max_diff_size_kb = config.maxDiffSizeKb;
|
|
174
|
+
}
|
|
175
|
+
if (config.limits) {
|
|
176
|
+
data.limits = config.limits;
|
|
177
|
+
}
|
|
178
|
+
if (config.agentCommand) {
|
|
179
|
+
data.agent_command = config.agentCommand;
|
|
180
|
+
}
|
|
181
|
+
if (config.agents !== null) {
|
|
182
|
+
data.agents = config.agents;
|
|
183
|
+
}
|
|
184
|
+
if (config.anonymousAgents.length > 0) {
|
|
185
|
+
data.anonymous_agents = config.anonymousAgents.map((a) => {
|
|
186
|
+
const entry = {
|
|
187
|
+
agent_id: a.agentId,
|
|
188
|
+
api_key: a.apiKey,
|
|
189
|
+
model: a.model,
|
|
190
|
+
tool: a.tool,
|
|
191
|
+
};
|
|
192
|
+
if (a.repoConfig) {
|
|
193
|
+
entry.repo_config = a.repoConfig;
|
|
194
|
+
}
|
|
195
|
+
return entry;
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
fs.writeFileSync(CONFIG_FILE, stringify(data), { encoding: 'utf-8', mode: 0o600 });
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Merge per-agent limits with global limits.
|
|
202
|
+
* Agent values override global; missing fields fall back to global.
|
|
203
|
+
*/
|
|
204
|
+
export function resolveAgentLimits(agentLimits, globalLimits) {
|
|
205
|
+
if (!agentLimits && !globalLimits)
|
|
206
|
+
return null;
|
|
207
|
+
if (!agentLimits)
|
|
208
|
+
return globalLimits;
|
|
209
|
+
if (!globalLimits)
|
|
210
|
+
return agentLimits;
|
|
211
|
+
const merged = { ...globalLimits, ...agentLimits };
|
|
212
|
+
return Object.keys(merged).length === 0 ? null : merged;
|
|
213
|
+
}
|
|
214
|
+
export function findAnonymousAgent(config, agentId) {
|
|
215
|
+
return config.anonymousAgents.find((a) => a.agentId === agentId) ?? null;
|
|
216
|
+
}
|
|
217
|
+
export function removeAnonymousAgent(config, agentId) {
|
|
218
|
+
config.anonymousAgents = config.anonymousAgents.filter((a) => a.agentId !== agentId);
|
|
219
|
+
}
|
|
220
|
+
export function requireApiKey(config) {
|
|
221
|
+
if (!config.apiKey) {
|
|
222
|
+
console.error('Not authenticated. Run `opencara login` first.');
|
|
223
|
+
process.exit(1);
|
|
224
|
+
}
|
|
225
|
+
return config.apiKey;
|
|
226
|
+
}
|
|
227
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAmCxC,MAAM,CAAC,MAAM,oBAAoB,GAAG,0BAA0B,CAAC;AAC/D,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,WAAW,CAAC,CAAC;AAC/D,MAAM,CAAC,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC;AAE/D,MAAM,UAAU,eAAe;IAC7B,EAAE,CAAC,SAAS,CAAC,UAAU,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;AAChD,CAAC;AAED,MAAM,CAAC,MAAM,wBAAwB,GAAG,GAAG,CAAC;AAE5C,SAAS,WAAW,CAAC,IAA6B;IAChD,MAAM,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC;IACxB,IAAI,CAAC,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC;IACjD,MAAM,GAAG,GAAG,GAA8B,CAAC;IAC3C,MAAM,MAAM,GAAsB,EAA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AAe,GAAG,MAAM,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,KAAK,OAAO,CAAC,CAAC;AACvF,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,MAAiB;IAC7C,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;QACnB,OAAO,CAAC,KAAK,CAAC,gDAAgD,CAAC,CAAC;QAChE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IACD,OAAO,MAAM,CAAC,MAAM,CAAC;AACvB,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ConsumptionLimits } from './config.js';
|
|
2
|
+
export interface LimitCheckResult {
|
|
3
|
+
allowed: boolean;
|
|
4
|
+
reason?: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Consumption tracking was removed (consumption_logs table dropped).
|
|
8
|
+
* Limit checks always pass since token counts are self-reported and not stored server-side.
|
|
9
|
+
*/
|
|
10
|
+
export declare function checkConsumptionLimits(_agentId: string, _limits: ConsumptionLimits | null): Promise<LimitCheckResult>;
|
|
11
|
+
export interface SessionStats {
|
|
12
|
+
tokens: number;
|
|
13
|
+
reviews: number;
|
|
14
|
+
}
|
|
15
|
+
export declare function createSessionTracker(): SessionStats;
|
|
16
|
+
export declare function recordSessionUsage(session: SessionStats, tokensUsed: number): void;
|
|
17
|
+
export declare function formatPostReviewStats(_tokensUsed: number, session: SessionStats, _limits: ConsumptionLimits | null, _dailyStats?: {
|
|
18
|
+
tokens: number;
|
|
19
|
+
reviews: number;
|
|
20
|
+
}): string;
|
|
21
|
+
//# sourceMappingURL=consumption.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consumption.d.ts","sourceRoot":"","sources":["../src/consumption.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAErD,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;GAGG;AACH,wBAAsB,sBAAsB,CAC1C,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,iBAAiB,GAAG,IAAI,GAChC,OAAO,CAAC,gBAAgB,CAAC,CAE3B;AAED,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,wBAAgB,oBAAoB,IAAI,YAAY,CAEnD;AAED,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI,CAGlF;AAED,wBAAgB,qBAAqB,CACnC,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,YAAY,EACrB,OAAO,EAAE,iBAAiB,GAAG,IAAI,EACjC,WAAW,CAAC,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAChD,MAAM,CAER"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Consumption tracking was removed (consumption_logs table dropped).
|
|
3
|
+
* Limit checks always pass since token counts are self-reported and not stored server-side.
|
|
4
|
+
*/
|
|
5
|
+
export async function checkConsumptionLimits(_agentId, _limits) {
|
|
6
|
+
return { allowed: true };
|
|
7
|
+
}
|
|
8
|
+
export function createSessionTracker() {
|
|
9
|
+
return { tokens: 0, reviews: 0 };
|
|
10
|
+
}
|
|
11
|
+
export function recordSessionUsage(session, tokensUsed) {
|
|
12
|
+
session.tokens += tokensUsed;
|
|
13
|
+
session.reviews += 1;
|
|
14
|
+
}
|
|
15
|
+
export function formatPostReviewStats(_tokensUsed, session, _limits, _dailyStats) {
|
|
16
|
+
return ` Session: ${session.tokens.toLocaleString()} tokens / ${session.reviews} reviews`;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=consumption.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consumption.js","sourceRoot":"","sources":["../src/consumption.ts"],"names":[],"mappings":"AAOA;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,QAAgB,EAChB,OAAiC;IAEjC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;AAC3B,CAAC;AAOD,MAAM,UAAU,oBAAoB;IAClC,OAAO,EAAE,MAAM,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;AACnC,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,OAAqB,EAAE,UAAkB;IAC1E,OAAO,CAAC,MAAM,IAAI,UAAU,CAAC;IAC7B,OAAO,CAAC,OAAO,IAAI,CAAC,CAAC;AACvB,CAAC;AAED,MAAM,UAAU,qBAAqB,CACnC,WAAmB,EACnB,OAAqB,EACrB,OAAiC,EACjC,WAAiD;IAEjD,OAAO,cAAc,OAAO,CAAC,MAAM,CAAC,cAAc,EAAE,aAAa,OAAO,CAAC,OAAO,UAAU,CAAC;AAC7F,CAAC"}
|
package/dist/http.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare class HttpError extends Error {
|
|
2
|
+
readonly status: number;
|
|
3
|
+
constructor(status: number, message: string);
|
|
4
|
+
}
|
|
5
|
+
export declare class ApiClient {
|
|
6
|
+
private readonly baseUrl;
|
|
7
|
+
private readonly apiKey;
|
|
8
|
+
constructor(baseUrl: string, apiKey?: string | null);
|
|
9
|
+
private headers;
|
|
10
|
+
get<T>(path: string): Promise<T>;
|
|
11
|
+
post<T>(path: string, body?: unknown): Promise<T>;
|
|
12
|
+
private handleResponse;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=http.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAEA,qBAAa,SAAU,SAAQ,KAAK;aAEhB,MAAM,EAAE,MAAM;gBAAd,MAAM,EAAE,MAAM,EAC9B,OAAO,EAAE,MAAM;CAKlB;AAED,qBAAa,SAAS;IAElB,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,MAAM;gBADN,OAAO,EAAE,MAAM,EACf,MAAM,GAAE,MAAM,GAAG,IAAW;IAG/C,OAAO,CAAC,OAAO;IAUT,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC;IAQhC,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC;YASzC,cAAc;CAgB7B"}
|
package/dist/http.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
export class HttpError extends Error {
|
|
2
|
+
status;
|
|
3
|
+
constructor(status, message) {
|
|
4
|
+
super(message);
|
|
5
|
+
this.status = status;
|
|
6
|
+
this.name = 'HttpError';
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export class ApiClient {
|
|
10
|
+
baseUrl;
|
|
11
|
+
apiKey;
|
|
12
|
+
constructor(baseUrl, apiKey = null) {
|
|
13
|
+
this.baseUrl = baseUrl;
|
|
14
|
+
this.apiKey = apiKey;
|
|
15
|
+
}
|
|
16
|
+
headers() {
|
|
17
|
+
const h = {
|
|
18
|
+
'Content-Type': 'application/json',
|
|
19
|
+
};
|
|
20
|
+
if (this.apiKey) {
|
|
21
|
+
h['Authorization'] = `Bearer ${this.apiKey}`;
|
|
22
|
+
}
|
|
23
|
+
return h;
|
|
24
|
+
}
|
|
25
|
+
async get(path) {
|
|
26
|
+
const res = await fetch(`${this.baseUrl}${path}`, {
|
|
27
|
+
method: 'GET',
|
|
28
|
+
headers: this.headers(),
|
|
29
|
+
});
|
|
30
|
+
return this.handleResponse(res);
|
|
31
|
+
}
|
|
32
|
+
async post(path, body) {
|
|
33
|
+
const res = await fetch(`${this.baseUrl}${path}`, {
|
|
34
|
+
method: 'POST',
|
|
35
|
+
headers: this.headers(),
|
|
36
|
+
body: body !== undefined ? JSON.stringify(body) : undefined,
|
|
37
|
+
});
|
|
38
|
+
return this.handleResponse(res);
|
|
39
|
+
}
|
|
40
|
+
async handleResponse(res) {
|
|
41
|
+
if (!res.ok) {
|
|
42
|
+
if (res.status === 401) {
|
|
43
|
+
throw new HttpError(401, 'Not authenticated. Run `opencara login` first.');
|
|
44
|
+
}
|
|
45
|
+
let message = `HTTP ${res.status}`;
|
|
46
|
+
try {
|
|
47
|
+
const body = (await res.json());
|
|
48
|
+
if (body.error)
|
|
49
|
+
message = body.error;
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
// ignore parse errors
|
|
53
|
+
}
|
|
54
|
+
throw new HttpError(res.status, message);
|
|
55
|
+
}
|
|
56
|
+
return (await res.json());
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=http.js.map
|
package/dist/http.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,SAAU,SAAQ,KAAK;IAEhB;IADlB,YACkB,MAAc,EAC9B,OAAe;QAEf,KAAK,CAAC,OAAO,CAAC,CAAC;QAHC,WAAM,GAAN,MAAM,CAAQ;QAI9B,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC;IAC1B,CAAC;CACF;AAED,MAAM,OAAO,SAAS;IAED;IACA;IAFnB,YACmB,OAAe,EACf,SAAwB,IAAI;QAD5B,YAAO,GAAP,OAAO,CAAQ;QACf,WAAM,GAAN,MAAM,CAAsB;IAC5C,CAAC;IAEI,OAAO;QACb,MAAM,CAAC,GAA2B;YAChC,cAAc,EAAE,kBAAkB;SACnC,CAAC;QACF,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAChB,CAAC,CAAC,eAAe,CAAC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AAC;gBACP,sBAAsB;YACxB,CAAC;YACD,MAAM,IAAI,SAAS,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAC3C,CAAC;QACD,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAM,CAAC;IACjC,CAAC;CACF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Command } from 'commander';
|
|
3
|
+
import { getVersion } from '@opencara/shared';
|
|
4
|
+
import { loginCommand } from './commands/login.js';
|
|
5
|
+
import { agentCommand } from './commands/agent.js';
|
|
6
|
+
import { statsCommand } from './commands/stats.js';
|
|
7
|
+
const program = new Command()
|
|
8
|
+
.name('opencara')
|
|
9
|
+
.description('OpenCara — distributed AI code review agent')
|
|
10
|
+
.version(getVersion());
|
|
11
|
+
program.addCommand(loginCommand);
|
|
12
|
+
program.addCommand(agentCommand);
|
|
13
|
+
program.addCommand(statsCommand);
|
|
14
|
+
program.parse();
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE;KAC1B,IAAI,CAAC,UAAU,CAAC;KAChB,WAAW,CAAC,6CAA6C,CAAC;KAC1D,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC;AAEzB,OAAO,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC;AACjC,OAAO,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC;AACjC,OAAO,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC;AAEjC,OAAO,CAAC,KAAK,EAAE,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface ReconnectOptions {
|
|
2
|
+
initialDelay: number;
|
|
3
|
+
maxDelay: number;
|
|
4
|
+
multiplier: number;
|
|
5
|
+
jitter: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare const DEFAULT_RECONNECT_OPTIONS: ReconnectOptions;
|
|
8
|
+
export declare function calculateDelay(attempt: number, options?: ReconnectOptions): number;
|
|
9
|
+
export declare function sleep(ms: number): Promise<void>;
|
|
10
|
+
//# sourceMappingURL=reconnect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reconnect.d.ts","sourceRoot":"","sources":["../src/reconnect.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,gBAAgB;IAC/B,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,OAAO,CAAC;CACjB;AAED,eAAO,MAAM,yBAAyB,EAAE,gBAKvC,CAAC;AAEF,wBAAgB,cAAc,CAC5B,OAAO,EAAE,MAAM,EACf,OAAO,GAAE,gBAA4C,GACpD,MAAM,CASR;AAED,wBAAgB,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE/C"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export const DEFAULT_RECONNECT_OPTIONS = {
|
|
2
|
+
initialDelay: 1000,
|
|
3
|
+
maxDelay: 30000,
|
|
4
|
+
multiplier: 2,
|
|
5
|
+
jitter: true,
|
|
6
|
+
};
|
|
7
|
+
export function calculateDelay(attempt, options = DEFAULT_RECONNECT_OPTIONS) {
|
|
8
|
+
const base = Math.min(options.initialDelay * Math.pow(options.multiplier, attempt), options.maxDelay);
|
|
9
|
+
if (options.jitter) {
|
|
10
|
+
return base + Math.random() * 500;
|
|
11
|
+
}
|
|
12
|
+
return base;
|
|
13
|
+
}
|
|
14
|
+
export function sleep(ms) {
|
|
15
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=reconnect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reconnect.js","sourceRoot":"","sources":["../src/reconnect.ts"],"names":[],"mappings":"AAOA,MAAM,CAAC,MAAM,yBAAyB,GAAqB;IACzD,YAAY,EAAE,IAAI;IAClB,QAAQ,EAAE,KAAK;IACf,UAAU,EAAE,CAAC;IACb,MAAM,EAAE,IAAI;CACb,CAAC;AAEF,MAAM,UAAU,cAAc,CAC5B,OAAe,EACf,UAA4B,yBAAyB;IAErD,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CACnB,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,UAAU,EAAE,OAAO,CAAC,EAC5D,OAAO,CAAC,QAAQ,CACjB,CAAC;IACF,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;QACnB,OAAO,IAAI,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,GAAG,CAAC;IACpC,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,UAAU,KAAK,CAAC,EAAU;IAC9B,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;AAC3D,CAAC"}
|
package/dist/review.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { ReviewMode, ReviewVerdict } from '@opencara/shared';
|
|
2
|
+
import { type ToolExecutorResult } from './tool-executor.js';
|
|
3
|
+
export interface ReviewRequest {
|
|
4
|
+
taskId: string;
|
|
5
|
+
diffContent: string;
|
|
6
|
+
prompt: string;
|
|
7
|
+
owner: string;
|
|
8
|
+
repo: string;
|
|
9
|
+
prNumber: number;
|
|
10
|
+
timeout: number;
|
|
11
|
+
reviewMode: ReviewMode;
|
|
12
|
+
}
|
|
13
|
+
export interface ReviewResponse {
|
|
14
|
+
review: string;
|
|
15
|
+
verdict: ReviewVerdict;
|
|
16
|
+
tokensUsed: number;
|
|
17
|
+
tokensEstimated: boolean;
|
|
18
|
+
}
|
|
19
|
+
export declare const TIMEOUT_SAFETY_MARGIN_MS = 30000;
|
|
20
|
+
export declare function buildSystemPrompt(owner: string, repo: string, mode?: ReviewMode): string;
|
|
21
|
+
export declare function buildUserMessage(prompt: string, diffContent: string): string;
|
|
22
|
+
export declare function extractVerdict(text: string): {
|
|
23
|
+
verdict: ReviewVerdict;
|
|
24
|
+
review: string;
|
|
25
|
+
};
|
|
26
|
+
export interface ReviewExecutorDeps {
|
|
27
|
+
commandTemplate: string;
|
|
28
|
+
maxDiffSizeKb: number;
|
|
29
|
+
}
|
|
30
|
+
export declare function executeReview(req: ReviewRequest, deps: ReviewExecutorDeps, runTool?: (commandTemplate: string, prompt: string, timeoutMs: number, signal?: AbortSignal) => Promise<ToolExecutorResult>): Promise<ReviewResponse>;
|
|
31
|
+
export declare class DiffTooLargeError extends Error {
|
|
32
|
+
constructor(message: string);
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=review.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"review.d.ts","sourceRoot":"","sources":["../src/review.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAClE,OAAO,EAA+B,KAAK,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAE1F,MAAM,WAAW,aAAa;IAC5B,MAAM,E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ool, estimateTokens } from './tool-executor.js';
|
|
2
|
+
export const TIMEOUT_SAFETY_MARGIN_MS = 30_000;
|
|
3
|
+
const FULL_SYSTEM_PROMPT_TEMPLATE = `You are a code reviewer for the {owner}/{repo} repository.
|
|
4
|
+
Review the following pull request diff and provide a structured review.
|
|
5
|
+
|
|
6
|
+
Format your response as:
|
|
7
|
+
|
|
8
|
+
## Summary
|
|
9
|
+
[2-3 sentence overall assessment]
|
|
10
|
+
|
|
11
|
+
## Findings
|
|
12
|
+
List each finding on its own line:
|
|
13
|
+
- **[severity]** \`file:line\` — description
|
|
14
|
+
|
|
15
|
+
Severities: critical, major, minor, suggestion
|
|
16
|
+
Only include findings with specific file:line references from the diff.
|
|
17
|
+
If no issues found, write "No issues found."
|
|
18
|
+
|
|
19
|
+
## Verdict
|
|
20
|
+
APPROVE | REQUEST_CHANGES | COMMENT`;
|
|
21
|
+
const COMPACT_SYSTEM_PROMPT_TEMPLATE = `You are a code reviewer for the {owner}/{repo} repository.
|
|
22
|
+
Review the following pull request diff and return a compact, structured assessment.
|
|
23
|
+
|
|
24
|
+
Format your response as:
|
|
25
|
+
|
|
26
|
+
## Summary
|
|
27
|
+
[1-2 sentence assessment]
|
|
28
|
+
|
|
29
|
+
## Findings
|
|
30
|
+
- **[severity]** \`file:line\` — description
|
|
31
|
+
|
|
32
|
+
Severities: critical, major, minor, suggestion
|
|
33
|
+
|
|
34
|
+
## Verdict
|
|
35
|
+
APPROVE | REQUEST_CHANGES | COMMENT`;
|
|
36
|
+
export function buildSystemPrompt(owner, repo, mode = 'full') {
|
|
37
|
+
const template = mode === 'compact' ? COMPACT_SYSTEM_PROMPT_TEMPLATE : FULL_SYSTEM_PROMPT_TEMPLATE;
|
|
38
|
+
return template.replace('{owner}', owner).replace('{repo}', repo);
|
|
39
|
+
}
|
|
40
|
+
export function buildUserMessage(prompt, diffContent) {
|
|
41
|
+
return `${prompt}\n\n---\n\n${diffContent}`;
|
|
42
|
+
}
|
|
43
|
+
// New format: ## Verdict section at end of markdown
|
|
44
|
+
const SECTION_VERDICT_PATTERN = /##\s*Verdict\s*\n+\s*(APPROVE|REQUEST_CHANGES|COMMENT)\b/im;
|
|
45
|
+
// Legacy format: VERDICT: X on its own line
|
|
46
|
+
const LEGACY_VERDICT_PATTERN = /^VERDICT:\s*(APPROVE|REQUEST_CHANGES|COMMENT)\s*$/m;
|
|
47
|
+
export function extractVerdict(text) {
|
|
48
|
+
// Try new ## Verdict section format first
|
|
49
|
+
const sectionMatch = SECTION_VERDICT_PATTERN.exec(text);
|
|
50
|
+
if (sectionMatch) {
|
|
51
|
+
const verdictStr = sectionMatch[1].toLowerCase();
|
|
52
|
+
// Remove the ## Verdict section from the review text
|
|
53
|
+
const review = text
|
|
54
|
+
.slice(0, sectionMatch.index)
|
|
55
|
+
.replace(/\n{3,}/g, '\n\n')
|
|
56
|
+
.trim();
|
|
57
|
+
return { verdict: verdictStr, review };
|
|
58
|
+
}
|
|
59
|
+
// Fall back to legacy VERDICT: X format
|
|
60
|
+
const legacyMatch = LEGACY_VERDICT_PATTERN.exec(text);
|
|
61
|
+
if (legacyMatch) {
|
|
62
|
+
const verdictStr = legacyMatch[1].toLowerCase();
|
|
63
|
+
const before = text.slice(0, legacyMatch.index);
|
|
64
|
+
const after = text.slice(legacyMatch.index + legacyMatch[0].length);
|
|
65
|
+
const review = (before + after).replace(/\n{3,}/g, '\n\n').trim();
|
|
66
|
+
return { verdict: verdictStr, review };
|
|
67
|
+
}
|
|
68
|
+
return { verdict: 'comment', review: text };
|
|
69
|
+
}
|
|
70
|
+
export async function executeReview(req, deps, runTool = executeTool) {
|
|
71
|
+
const diffSizeKb = Buffer.byteLength(req.diffContent, 'utf-8') / 1024;
|
|
72
|
+
if (diffSizeKb > deps.maxDiffSizeKb) {
|
|
73
|
+
throw new DiffTooLargeError(`Diff too large (${Math.round(diffSizeKb)}KB > ${deps.maxDiffSizeKb}KB limit)`);
|
|
74
|
+
}
|
|
75
|
+
const timeoutMs = req.timeout * 1000;
|
|
76
|
+
if (timeoutMs <= TIMEOUT_SAFETY_MARGIN_MS) {
|
|
77
|
+
throw new Error('Not enough time remaining to start review');
|
|
78
|
+
}
|
|
79
|
+
const effectiveTimeout = timeoutMs - TIMEOUT_SAFETY_MARGIN_MS;
|
|
80
|
+
const abortController = new AbortController();
|
|
81
|
+
const abortTimer = setTimeout(() => {
|
|
82
|
+
abortController.abort();
|
|
83
|
+
}, effectiveTimeout);
|
|
84
|
+
try {
|
|
85
|
+
const systemPrompt = buildSystemPrompt(req.owner, req.repo, req.reviewMode);
|
|
86
|
+
const userMessage = buildUserMessage(req.prompt, req.diffContent);
|
|
87
|
+
const fullPrompt = `${systemPrompt}\n\n${userMessage}`;
|
|
88
|
+
const result = await runTool(deps.commandTemplate, fullPrompt, effectiveTimeout, abortController.signal);
|
|
89
|
+
const { verdict, review } = extractVerdict(result.stdout);
|
|
90
|
+
// Only add input estimate when tokens were estimated (not parsed from tool output)
|
|
91
|
+
const inputTokens = result.tokensParsed ? 0 : estimateTokens(fullPrompt);
|
|
92
|
+
return {
|
|
93
|
+
review,
|
|
94
|
+
verdict,
|
|
95
|
+
tokensUsed: result.tokensUsed + inputTokens,
|
|
96
|
+
tokensEstimated: !result.tokensParsed,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
finally {
|
|
100
|
+
clearTimeout(abortTimer);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
export class DiffTooLargeError extends Error {
|
|
104
|
+
constructor(message) {
|
|
105
|
+
super(message);
|
|
106
|
+
this.name = 'DiffTooLargeError';
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=review.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"review.js","sourceRoot":"","sources":["../src/review.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,cAAc,EAA2B,MAAM,oBAAoB,CAAC;AAoB1F,MAAM,CAAC,MAAM,wBAAwB,GAAG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GAAG,EAAE;QACjC,eAAe,CAAC,KAAK,EAAE,CAAC;IAC1B,CAAC,EAAE,gBAAgB,CAAC,CAAC;IAErB,IAAI,CAAC;QACH,MAAM,YAAY,GAAG,iBAAiB,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,UAAU,CAAC,CAAC;QAC5E,MAAM,WAAW,GAAG,gBAAgB,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,WAAW,CAAC,CAAC;QAClE,MAAM,UAAU,GAAG,GAAG,YAAY,OAAO,WAAW,EAAE,CAAC;QAEvD,MAAM,MAAM,GAAG,MAAM,OAAO,CAC1B,IAAI,CAAC,eAAe,EACpB,UAAU,EACV,gBAAgB,EAChB,eAAe,CAAC,MAAM,CACvB,CAAC;QAEF,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,cAAc,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAC1D,mFAAmF;QACnF,MAAM,WAAW,GAAG,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC;QACzE,OAAO;YACL,MAAM;YACN,OAAO;YACP,UAAU,EAAE,MAAM,CAAC,UAAU,GAAG,WAAW;YAC3C,eAAe,EAAE,CAAC,MAAM,CAAC,YAAY;SACtC,CAAC;IACJ,CAAC;YAAS,CAAC;QACT,YAAY,CAAC,UAAU,CAAC,CAAC;IAC3B,CAAC;AACH,CAAC;AAED,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IAC1C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;IAClC,CAAC;CACF"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { ReviewExecutorDeps } from './review.js';
|
|
2
|
+
import { type ToolExecutorResult } from './tool-executor.js';
|
|
3
|
+
export interface SummaryReviewInput {
|
|
4
|
+
agentId: string;
|
|
5
|
+
model: string;
|
|
6
|
+
tool: string;
|
|
7
|
+
review: string;
|
|
8
|
+
verdict: string;
|
|
9
|
+
}
|
|
10
|
+
export interface SummaryRequest {
|
|
11
|
+
taskId: string;
|
|
12
|
+
reviews: SummaryReviewInput[];
|
|
13
|
+
prompt: string;
|
|
14
|
+
owner: string;
|
|
15
|
+
repo: string;
|
|
16
|
+
prNumber: number;
|
|
17
|
+
timeout: number;
|
|
18
|
+
diffContent: string;
|
|
19
|
+
}
|
|
20
|
+
export interface SummaryResponse {
|
|
21
|
+
summary: string;
|
|
22
|
+
tokensUsed: number;
|
|
23
|
+
tokensEstimated: boolean;
|
|
24
|
+
}
|
|
25
|
+
export declare const TIMEOUT_SAFETY_MARGIN_MS = 30000;
|
|
26
|
+
export declare const MAX_INPUT_SIZE_BYTES: number;
|
|
27
|
+
export declare class InputTooLargeError extends Error {
|
|
28
|
+
constructor(message: string);
|
|
29
|
+
}
|
|
30
|
+
export declare function buildSummarySystemPrompt(owner: string, repo: string, reviewCount: number): string;
|
|
31
|
+
export declare function buildSummaryUserMessage(prompt: string, reviews: SummaryReviewInput[], diffContent: string): string;
|
|
32
|
+
export declare function calculateInputSize(prompt: string, reviews: SummaryReviewInput[], diffContent: string): number;
|
|
33
|
+
export declare function executeSummary(req: SummaryRequest, deps: ReviewExecutorDeps, runTool?: (commandTemplate: string, prompt: string, timeoutMs: number, signal?: AbortSignal) => Promise<ToolExecutorResult>): Promise<SummaryResponse>;
|
|
34
|
+
//# sourceMappingURL=summary.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"summary.d.ts","sourceRoot":"","sources":["../src/summary.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAA+B,KAAK,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAE1F,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,MAA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