@cjhyy/code-shell 0.1.5 → 0.1.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/CHANGELOG.md +30 -0
- package/dist/anthropic-UBSB5AQH.js +1 -0
- package/dist/arena/index.js +1 -104
- package/dist/arena-OW55ZCHT.js +3 -0
- package/dist/bwrap-PVZMLHZR.js +2 -0
- package/dist/chunk-2NS3JMNK.js +1 -0
- package/dist/chunk-3QP5BQ3L.js +1 -0
- package/dist/chunk-B7K2OWKC.js +2 -0
- package/dist/chunk-EWWK56K6.js +2 -0
- package/dist/chunk-FU7AHZNN.js +1 -0
- package/dist/chunk-HIJ2XXGX.js +1 -0
- package/dist/chunk-KCXSARAA.js +1 -0
- package/dist/chunk-NFH3UQ3E.js +2 -0
- package/dist/chunk-NMBYBGC7.js +250 -0
- package/dist/chunk-NVAZJ5XS.js +2 -0
- package/dist/chunk-O5HFCH2U.js +1 -0
- package/dist/chunk-P6JSTIFM.js +1 -0
- package/dist/chunk-PGANL6F2.js +3 -0
- package/dist/chunk-Q4O2HGWS.js +251 -0
- package/dist/chunk-QTWU7UNA.js +5 -0
- package/dist/chunk-RP26WO4R.js +1 -0
- package/dist/chunk-SNFAPSLA.js +1 -0
- package/dist/chunk-T222K6IV.js +18 -0
- package/dist/chunk-TKJA6W36.js +3 -0
- package/dist/chunk-UDPUTFQT.js +2 -0
- package/dist/chunk-W47Z7MGS.js +33 -0
- package/dist/chunk-WI6FSWGU.js +1 -0
- package/dist/chunk-WOP6MJKW.js +1 -0
- package/dist/chunk-XDOWC7EG.js +4 -0
- package/dist/chunk-Y2NS6HPO.js +641 -0
- package/dist/cli/main.js +303 -22037
- package/dist/cli/updater.d.ts +8 -0
- package/dist/client-base-6ZZJJYDY.js +1 -0
- package/dist/compaction-ECVQVOCT.js +1 -0
- package/dist/devtools-SGDUOOM4.js +1 -0
- package/dist/engine/engine.d.ts +15 -0
- package/dist/export-md-U72T7NW7.js +22 -0
- package/dist/file-history-7FQFEQOL.js +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -347
- package/dist/llm/token-counter.d.ts +17 -0
- package/dist/manager-C3TDN6MS.js +1 -0
- package/dist/mcp-manager-OP4XYV53.js +1 -0
- package/dist/memory-BNI4WEWL.js +1 -0
- package/dist/model-cache-HEDXI7UJ.js +1 -0
- package/dist/model-fetcher-BJ64META.js +1 -0
- package/dist/off-7SDVMMXW.js +1 -0
- package/dist/openai-KEWQ54TM.js +1 -0
- package/dist/openrouter-models-AM6M52D6.js +1 -0
- package/dist/openrouter-sync-5JNBL3Z6.js +1 -0
- package/dist/product/index.js +1 -21
- package/dist/run/index.js +1 -48
- package/dist/seatbelt-WBYROQT6.js +37 -0
- package/dist/session/session-manager.d.ts +2 -0
- package/dist/session-manager-AGWS5SMJ.js +1 -0
- package/dist/settings/schema.d.ts +72 -6
- package/dist/tool-summary-5UE62VU4.js +2 -0
- package/dist/tool-system/builtin/bash.d.ts +7 -1
- package/dist/tool-system/context.d.ts +7 -0
- package/dist/tool-system/investigation-guard.d.ts +9 -0
- package/dist/tool-system/sandbox/bwrap.d.ts +13 -0
- package/dist/tool-system/sandbox/index.d.ts +71 -0
- package/dist/tool-system/sandbox/off.d.ts +2 -0
- package/dist/tool-system/sandbox/seatbelt.d.ts +18 -0
- package/dist/types.d.ts +4 -0
- package/dist/ui/components/SessionPicker.d.ts +2 -0
- package/dist/ui/components/SpinnerWithVerb.d.ts +2 -2
- package/dist/ui/components/StatusLine.d.ts +2 -2
- package/dist/updater-OCNU2K2Z.js +1 -0
- package/package.json +8 -10
- package/skills-builtin/codeshell-help.md +135 -0
- package/dist/anthropic-IBTI4WL2.cjs +0 -10
- package/dist/anthropic-PRZZKHEZ.js +0 -10
- package/dist/arena/index.cjs +0 -104
- package/dist/arena-KBQOPLFV.cjs +0 -261
- package/dist/arena-O2L4TN6A.js +0 -261
- package/dist/chunk-2EP3CLEN.js +0 -44
- package/dist/chunk-2YW4FPFG.cjs +0 -101
- package/dist/chunk-3OA5G4TM.js +0 -47
- package/dist/chunk-52LGZKT3.cjs +0 -47
- package/dist/chunk-55XGPMAP.cjs +0 -146
- package/dist/chunk-5ECBT4YA.js +0 -450
- package/dist/chunk-6QVAYW7C.cjs +0 -438
- package/dist/chunk-6S4BJ65N.js +0 -113
- package/dist/chunk-76HYEPDM.js +0 -307
- package/dist/chunk-76W334S4.js +0 -54
- package/dist/chunk-7EG3V4JY.cjs +0 -113
- package/dist/chunk-7JVTYEEC.js +0 -340
- package/dist/chunk-7K6SDRRF.js +0 -9047
- package/dist/chunk-7Y6S3OCX.js +0 -438
- package/dist/chunk-A5LCRPDP.cjs +0 -54
- package/dist/chunk-BSW22MPA.js +0 -146
- package/dist/chunk-BUU5PZK2.cjs +0 -9048
- package/dist/chunk-BWTOS5BH.cjs +0 -5128
- package/dist/chunk-BXCY2FSE.js +0 -203
- package/dist/chunk-C5YQBIRK.js +0 -5128
- package/dist/chunk-HEKQCI7B.cjs +0 -224
- package/dist/chunk-HS2MFNUC.cjs +0 -44
- package/dist/chunk-IK4EWJBP.cjs +0 -203
- package/dist/chunk-JMR33QVF.cjs +0 -169
- package/dist/chunk-KOVYSDHZ.cjs +0 -340
- package/dist/chunk-KS3RYAYL.cjs +0 -45
- package/dist/chunk-MD32R22I.js +0 -50
- package/dist/chunk-MY5XHADU.cjs +0 -216
- package/dist/chunk-NUNC3VFB.cjs +0 -307
- package/dist/chunk-QRM7IF2S.cjs +0 -4711
- package/dist/chunk-R47ROHGL.cjs +0 -298
- package/dist/chunk-RMYKO74M.js +0 -1252
- package/dist/chunk-SFXHZSRF.js +0 -101
- package/dist/chunk-SIHHIQLO.js +0 -224
- package/dist/chunk-SNT563K3.cjs +0 -107
- package/dist/chunk-T6VYG46N.js +0 -105
- package/dist/chunk-TUY2T5KP.cjs +0 -105
- package/dist/chunk-VIAGTYYW.js +0 -169
- package/dist/chunk-VYL4EFRC.cjs +0 -1252
- package/dist/chunk-W22P377T.js +0 -299
- package/dist/chunk-WASS5YWB.js +0 -215
- package/dist/chunk-XDIQWQJ4.js +0 -4711
- package/dist/chunk-YIQBXAYU.cjs +0 -264
- package/dist/chunk-YJ77GQK5.js +0 -107
- package/dist/chunk-YUI524OE.cjs +0 -450
- package/dist/chunk-ZBPSQCPU.js +0 -264
- package/dist/cli/main.cjs +0 -22133
- package/dist/client-base-HTF236ZD.cjs +0 -9
- package/dist/client-base-QKRKCOWB.js +0 -9
- package/dist/compaction-6VU2T643.js +0 -33
- package/dist/compaction-OKUNTCA7.cjs +0 -33
- package/dist/devtools-T2NIZBJK.cjs +0 -6
- package/dist/devtools-YXWHOVKR.js +0 -6
- package/dist/export-md-RXDW6F5W.cjs +0 -135
- package/dist/export-md-XXKZANW5.js +0 -135
- package/dist/file-history-KYPE3ECT.cjs +0 -7
- package/dist/file-history-LF4F7X26.js +0 -7
- package/dist/index.cjs +0 -347
- package/dist/manager-C2IUXKRC.js +0 -7
- package/dist/manager-YYKWYTRM.cjs +0 -7
- package/dist/mcp-manager-QMKWPBZ4.js +0 -8
- package/dist/mcp-manager-Z3OKI74O.cjs +0 -8
- package/dist/memory-5LWZ6FI2.cjs +0 -9
- package/dist/memory-VIJLBAMQ.js +0 -9
- package/dist/model-cache-5KIYL5SL.js +0 -13
- package/dist/model-cache-OED3IM4R.cjs +0 -13
- package/dist/model-fetcher-HKGICACL.js +0 -8
- package/dist/model-fetcher-UR6WJOQP.cjs +0 -8
- package/dist/openai-JR2WEKOF.js +0 -10
- package/dist/openai-YBTOET4O.cjs +0 -10
- package/dist/openrouter-models-OU4GRZQY.cjs +0 -15
- package/dist/openrouter-models-TGKDKY52.js +0 -15
- package/dist/openrouter-sync-BBHUM3R6.cjs +0 -11
- package/dist/openrouter-sync-UXUSJCIR.js +0 -11
- package/dist/product/index.cjs +0 -21
- package/dist/run/index.cjs +0 -48
- package/dist/session-manager-Q22BBMD3.js +0 -8
- package/dist/session-manager-XODQVL3C.cjs +0 -8
- package/dist/tool-summary-63DPIS7G.cjs +0 -31
- package/dist/tool-summary-NP5CDBKG.js +0 -31
- package/dist/updater-QW473OF4.cjs +0 -17
- package/dist/updater-VFUAHCVY.js +0 -17
package/dist/chunk-76HYEPDM.js
DELETED
|
@@ -1,307 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
SessionError
|
|
3
|
-
} from "./chunk-SFXHZSRF.js";
|
|
4
|
-
import {
|
|
5
|
-
init_esm_shims
|
|
6
|
-
} from "./chunk-MD32R22I.js";
|
|
7
|
-
|
|
8
|
-
// src/session/session-manager.ts
|
|
9
|
-
init_esm_shims();
|
|
10
|
-
import { mkdirSync as mkdirSync2, existsSync as existsSync2, readdirSync, readFileSync as readFileSync2, writeFileSync as writeFileSync2, renameSync } from "fs";
|
|
11
|
-
import { join } from "path";
|
|
12
|
-
import { homedir } from "os";
|
|
13
|
-
import { nanoid as nanoid2 } from "nanoid";
|
|
14
|
-
|
|
15
|
-
// src/session/transcript.ts
|
|
16
|
-
init_esm_shims();
|
|
17
|
-
import { appendFileSync, readFileSync, existsSync, mkdirSync, writeFileSync } from "fs";
|
|
18
|
-
import { dirname } from "path";
|
|
19
|
-
import { nanoid } from "nanoid";
|
|
20
|
-
var Transcript = class _Transcript {
|
|
21
|
-
events = [];
|
|
22
|
-
filePath;
|
|
23
|
-
currentTurn = 0;
|
|
24
|
-
getFilePath() {
|
|
25
|
-
return this.filePath;
|
|
26
|
-
}
|
|
27
|
-
constructor(filePath) {
|
|
28
|
-
this.filePath = filePath;
|
|
29
|
-
mkdirSync(dirname(filePath), { recursive: true });
|
|
30
|
-
if (!existsSync(filePath)) {
|
|
31
|
-
writeFileSync(filePath, "", "utf-8");
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
append(type, data) {
|
|
35
|
-
const event = {
|
|
36
|
-
id: nanoid(12),
|
|
37
|
-
type,
|
|
38
|
-
timestamp: Date.now(),
|
|
39
|
-
turnNumber: this.currentTurn,
|
|
40
|
-
data
|
|
41
|
-
};
|
|
42
|
-
this.events.push(event);
|
|
43
|
-
this.flush(event);
|
|
44
|
-
return event;
|
|
45
|
-
}
|
|
46
|
-
appendMessage(role, content) {
|
|
47
|
-
return this.append("message", { role, content });
|
|
48
|
-
}
|
|
49
|
-
appendToolUse(toolName, toolCallId, args) {
|
|
50
|
-
return this.append("tool_use", { toolName, toolCallId, args });
|
|
51
|
-
}
|
|
52
|
-
appendToolResult(toolCallId, toolName, result, error) {
|
|
53
|
-
return this.append("tool_result", { toolCallId, toolName, result, error });
|
|
54
|
-
}
|
|
55
|
-
appendTurnBoundary() {
|
|
56
|
-
this.currentTurn++;
|
|
57
|
-
return this.append("turn_boundary", { turnNumber: this.currentTurn });
|
|
58
|
-
}
|
|
59
|
-
appendSummary(summary, compactedRange) {
|
|
60
|
-
return this.append("summary", {
|
|
61
|
-
summary,
|
|
62
|
-
trigger: "auto",
|
|
63
|
-
compactedRange,
|
|
64
|
-
preservedSegment: {
|
|
65
|
-
headEventId: this.events[0]?.id,
|
|
66
|
-
tailEventId: this.events[this.events.length - 1]?.id
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
appendError(error, details) {
|
|
71
|
-
return this.append("error", { error, ...details });
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Derive Message[] from transcript events for sending to the LLM.
|
|
75
|
-
* This is the critical boundary: the LLM never sees the event log directly.
|
|
76
|
-
*/
|
|
77
|
-
toMessages() {
|
|
78
|
-
const messages = [];
|
|
79
|
-
for (const event of this.events) {
|
|
80
|
-
switch (event.type) {
|
|
81
|
-
case "message": {
|
|
82
|
-
const { role, content } = event.data;
|
|
83
|
-
messages.push({ role, content });
|
|
84
|
-
break;
|
|
85
|
-
}
|
|
86
|
-
case "tool_use": {
|
|
87
|
-
break;
|
|
88
|
-
}
|
|
89
|
-
case "tool_result": {
|
|
90
|
-
const { toolCallId, result, error } = event.data;
|
|
91
|
-
const lastMsg = messages[messages.length - 1];
|
|
92
|
-
const block = {
|
|
93
|
-
type: "tool_result",
|
|
94
|
-
tool_use_id: toolCallId,
|
|
95
|
-
content: error ? `Error: ${error}` : result ?? "(no output)"
|
|
96
|
-
};
|
|
97
|
-
if (lastMsg?.role === "user" && Array.isArray(lastMsg.content)) {
|
|
98
|
-
lastMsg.content.push(block);
|
|
99
|
-
} else {
|
|
100
|
-
messages.push({ role: "user", content: [block] });
|
|
101
|
-
}
|
|
102
|
-
break;
|
|
103
|
-
}
|
|
104
|
-
case "summary": {
|
|
105
|
-
const { summary } = event.data;
|
|
106
|
-
messages.push({
|
|
107
|
-
role: "user",
|
|
108
|
-
content: `<system-reminder>Previous conversation was summarized:
|
|
109
|
-
${summary}</system-reminder>`
|
|
110
|
-
});
|
|
111
|
-
break;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
return messages;
|
|
116
|
-
}
|
|
117
|
-
getEvents(type) {
|
|
118
|
-
if (!type) return [...this.events];
|
|
119
|
-
return this.events.filter((e) => e.type === type);
|
|
120
|
-
}
|
|
121
|
-
get turnNumber() {
|
|
122
|
-
return this.currentTurn;
|
|
123
|
-
}
|
|
124
|
-
get eventCount() {
|
|
125
|
-
return this.events.length;
|
|
126
|
-
}
|
|
127
|
-
flush(event) {
|
|
128
|
-
try {
|
|
129
|
-
appendFileSync(this.filePath, JSON.stringify(event) + "\n", "utf-8");
|
|
130
|
-
} catch {
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* Repair tool_result pairing issues:
|
|
135
|
-
* - Orphaned tool_results (no matching tool_use) get removed
|
|
136
|
-
* - Missing tool_results (tool_use with no result) get synthetic error results
|
|
137
|
-
*/
|
|
138
|
-
repairToolResultPairs() {
|
|
139
|
-
const toolUseIds = /* @__PURE__ */ new Set();
|
|
140
|
-
const toolResultIds = /* @__PURE__ */ new Set();
|
|
141
|
-
for (const event of this.events) {
|
|
142
|
-
if (event.type === "tool_use") {
|
|
143
|
-
toolUseIds.add(event.data.toolCallId);
|
|
144
|
-
} else if (event.type === "tool_result") {
|
|
145
|
-
toolResultIds.add(event.data.toolCallId);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
for (const id of toolUseIds) {
|
|
149
|
-
if (!toolResultIds.has(id)) {
|
|
150
|
-
this.append("tool_result", {
|
|
151
|
-
toolCallId: id,
|
|
152
|
-
toolName: "unknown",
|
|
153
|
-
error: "[Tool result missing due to interrupted session]"
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
this.events = this.events.filter((event) => {
|
|
158
|
-
if (event.type === "tool_result") {
|
|
159
|
-
const id = event.data.toolCallId;
|
|
160
|
-
return toolUseIds.has(id);
|
|
161
|
-
}
|
|
162
|
-
return true;
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
static loadFromFile(filePath) {
|
|
166
|
-
const transcript = new _Transcript(filePath);
|
|
167
|
-
if (!existsSync(filePath)) return transcript;
|
|
168
|
-
const content = readFileSync(filePath, "utf-8");
|
|
169
|
-
const lines = content.split("\n").filter((l) => l.trim());
|
|
170
|
-
for (const line of lines) {
|
|
171
|
-
try {
|
|
172
|
-
const event = JSON.parse(line);
|
|
173
|
-
transcript.events.push(event);
|
|
174
|
-
if (event.type === "turn_boundary") {
|
|
175
|
-
transcript.currentTurn = event.data.turnNumber ?? transcript.currentTurn + 1;
|
|
176
|
-
}
|
|
177
|
-
} catch {
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
transcript.repairToolResultPairs();
|
|
181
|
-
return transcript;
|
|
182
|
-
}
|
|
183
|
-
};
|
|
184
|
-
|
|
185
|
-
// src/session/session-manager.ts
|
|
186
|
-
var SessionManager = class {
|
|
187
|
-
sessionsDir;
|
|
188
|
-
constructor(storageDir) {
|
|
189
|
-
this.sessionsDir = storageDir ?? join(homedir(), ".code-shell", "sessions");
|
|
190
|
-
mkdirSync2(this.sessionsDir, { recursive: true });
|
|
191
|
-
}
|
|
192
|
-
create(cwd, model, provider) {
|
|
193
|
-
const sessionId = nanoid2(16);
|
|
194
|
-
const sessionDir = join(this.sessionsDir, sessionId);
|
|
195
|
-
mkdirSync2(sessionDir, { recursive: true });
|
|
196
|
-
const state = {
|
|
197
|
-
sessionId,
|
|
198
|
-
cwd,
|
|
199
|
-
startedAt: Date.now(),
|
|
200
|
-
model,
|
|
201
|
-
provider,
|
|
202
|
-
tokenUsage: { promptTokens: 0, completionTokens: 0, totalTokens: 0 },
|
|
203
|
-
turnCount: 0,
|
|
204
|
-
invokedSkills: [],
|
|
205
|
-
status: "active"
|
|
206
|
-
};
|
|
207
|
-
writeFileSync2(join(sessionDir, "state.json"), JSON.stringify(state, null, 2), "utf-8");
|
|
208
|
-
const transcript = new Transcript(join(sessionDir, "transcript.jsonl"));
|
|
209
|
-
transcript.append("session_meta", {
|
|
210
|
-
sessionId,
|
|
211
|
-
cwd,
|
|
212
|
-
model,
|
|
213
|
-
provider,
|
|
214
|
-
startedAt: state.startedAt
|
|
215
|
-
});
|
|
216
|
-
return { state, transcript };
|
|
217
|
-
}
|
|
218
|
-
resume(sessionId) {
|
|
219
|
-
const sessionDir = join(this.sessionsDir, sessionId);
|
|
220
|
-
if (!existsSync2(sessionDir)) {
|
|
221
|
-
throw new SessionError(`Session not found: ${sessionId}`);
|
|
222
|
-
}
|
|
223
|
-
const stateFile = join(sessionDir, "state.json");
|
|
224
|
-
if (!existsSync2(stateFile)) {
|
|
225
|
-
throw new SessionError(`Session state file not found: ${sessionId}`);
|
|
226
|
-
}
|
|
227
|
-
const state = JSON.parse(readFileSync2(stateFile, "utf-8"));
|
|
228
|
-
const transcriptFile = join(sessionDir, "transcript.jsonl");
|
|
229
|
-
const transcript = Transcript.loadFromFile(transcriptFile);
|
|
230
|
-
state.status = "active";
|
|
231
|
-
return { state, transcript };
|
|
232
|
-
}
|
|
233
|
-
saveState(state) {
|
|
234
|
-
const sessionDir = join(this.sessionsDir, state.sessionId);
|
|
235
|
-
mkdirSync2(sessionDir, { recursive: true });
|
|
236
|
-
const target = join(sessionDir, "state.json");
|
|
237
|
-
const tmp = `${target}.${process.pid}.${Date.now()}.tmp`;
|
|
238
|
-
writeFileSync2(tmp, JSON.stringify(state, null, 2), "utf-8");
|
|
239
|
-
renameSync(tmp, target);
|
|
240
|
-
}
|
|
241
|
-
/**
|
|
242
|
-
* Fork a session from a specific point.
|
|
243
|
-
* Creates a new session that shares events up to the given turn,
|
|
244
|
-
* then diverges independently.
|
|
245
|
-
*/
|
|
246
|
-
fork(sourceSessionId, forkAtTurn) {
|
|
247
|
-
const source = this.resume(sourceSessionId);
|
|
248
|
-
const events = source.transcript.getEvents();
|
|
249
|
-
const forkTurn = forkAtTurn ?? source.state.turnCount;
|
|
250
|
-
const newBundle = this.create(
|
|
251
|
-
source.state.cwd,
|
|
252
|
-
source.state.model,
|
|
253
|
-
source.state.provider
|
|
254
|
-
);
|
|
255
|
-
newBundle.state.parentSessionId = sourceSessionId;
|
|
256
|
-
for (const event of events) {
|
|
257
|
-
if (event.type === "turn_boundary" && event.data.turnNumber > forkTurn) {
|
|
258
|
-
break;
|
|
259
|
-
}
|
|
260
|
-
newBundle.transcript.append(event.type, event.data);
|
|
261
|
-
}
|
|
262
|
-
this.saveState(newBundle.state);
|
|
263
|
-
return newBundle;
|
|
264
|
-
}
|
|
265
|
-
list(limit = 20) {
|
|
266
|
-
if (!existsSync2(this.sessionsDir)) return [];
|
|
267
|
-
const dirs = readdirSync(this.sessionsDir, { withFileTypes: true }).filter((d) => d.isDirectory()).map((d) => d.name);
|
|
268
|
-
const sessions = [];
|
|
269
|
-
for (const dir of dirs) {
|
|
270
|
-
const stateFile = join(this.sessionsDir, dir, "state.json");
|
|
271
|
-
if (!existsSync2(stateFile)) continue;
|
|
272
|
-
try {
|
|
273
|
-
const state = JSON.parse(readFileSync2(stateFile, "utf-8"));
|
|
274
|
-
const transcriptFile = join(this.sessionsDir, dir, "transcript.jsonl");
|
|
275
|
-
const preview = readFirstUserMessage(transcriptFile);
|
|
276
|
-
sessions.push({ ...state, preview });
|
|
277
|
-
} catch {
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
return sessions.sort((a, b) => b.startedAt - a.startedAt).slice(0, limit);
|
|
281
|
-
}
|
|
282
|
-
};
|
|
283
|
-
function readFirstUserMessage(transcriptFile) {
|
|
284
|
-
if (!existsSync2(transcriptFile)) return void 0;
|
|
285
|
-
const raw = readFileSync2(transcriptFile, "utf-8");
|
|
286
|
-
for (const line of raw.split("\n")) {
|
|
287
|
-
if (!line) continue;
|
|
288
|
-
let event;
|
|
289
|
-
try {
|
|
290
|
-
event = JSON.parse(line);
|
|
291
|
-
} catch {
|
|
292
|
-
continue;
|
|
293
|
-
}
|
|
294
|
-
if (event.type !== "message") continue;
|
|
295
|
-
if (event.data?.role !== "user") continue;
|
|
296
|
-
const content = event.data.content;
|
|
297
|
-
const text = typeof content === "string" ? content : Array.isArray(content) ? content.find((b) => b.type === "text")?.text ?? "" : "";
|
|
298
|
-
if (!text.trim()) continue;
|
|
299
|
-
return text.replace(/\s+/g, " ").trim();
|
|
300
|
-
}
|
|
301
|
-
return void 0;
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
export {
|
|
305
|
-
Transcript,
|
|
306
|
-
SessionManager
|
|
307
|
-
};
|
package/dist/chunk-76W334S4.js
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
setOpenRouterSnapshot
|
|
3
|
-
} from "./chunk-XDIQWQJ4.js";
|
|
4
|
-
import {
|
|
5
|
-
init_esm_shims
|
|
6
|
-
} from "./chunk-MD32R22I.js";
|
|
7
|
-
|
|
8
|
-
// src/data/openrouter-sync.ts
|
|
9
|
-
init_esm_shims();
|
|
10
|
-
var ENDPOINT = "https://openrouter.ai/api/v1/models";
|
|
11
|
-
function priceToPerMillion(raw) {
|
|
12
|
-
if (!raw) return 0;
|
|
13
|
-
const n = Number(raw);
|
|
14
|
-
return Number.isFinite(n) ? n * 1e6 : 0;
|
|
15
|
-
}
|
|
16
|
-
function slim(m) {
|
|
17
|
-
return {
|
|
18
|
-
id: m.id,
|
|
19
|
-
name: m.name ?? m.id,
|
|
20
|
-
created: m.created ?? 0,
|
|
21
|
-
contextLength: m.top_provider?.context_length ?? m.context_length ?? 0,
|
|
22
|
-
maxOutputTokens: m.top_provider?.max_completion_tokens ?? 0,
|
|
23
|
-
inputPricePerMillion: priceToPerMillion(m.pricing?.prompt),
|
|
24
|
-
outputPricePerMillion: priceToPerMillion(m.pricing?.completion),
|
|
25
|
-
modalities: m.architecture?.input_modalities ?? []
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
async function syncOpenRouterCatalog(timeoutMs = 15e3) {
|
|
29
|
-
try {
|
|
30
|
-
const res = await fetch(ENDPOINT, {
|
|
31
|
-
headers: { Accept: "application/json" },
|
|
32
|
-
signal: AbortSignal.timeout(timeoutMs)
|
|
33
|
-
});
|
|
34
|
-
if (!res.ok) {
|
|
35
|
-
return { ok: false, count: 0, error: `HTTP ${res.status} ${res.statusText}` };
|
|
36
|
-
}
|
|
37
|
-
const payload = await res.json();
|
|
38
|
-
const raw = payload.data ?? [];
|
|
39
|
-
const models = raw.map(slim).sort((a, b) => b.created - a.created);
|
|
40
|
-
setOpenRouterSnapshot({
|
|
41
|
-
fetchedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
42
|
-
source: ENDPOINT,
|
|
43
|
-
count: models.length,
|
|
44
|
-
models
|
|
45
|
-
});
|
|
46
|
-
return { ok: true, count: models.length };
|
|
47
|
-
} catch (err) {
|
|
48
|
-
return { ok: false, count: 0, error: err.message };
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export {
|
|
53
|
-
syncOpenRouterCatalog
|
|
54
|
-
};
|
package/dist/chunk-7EG3V4JY.cjs
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class;
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var _chunk2YW4FPFGcjs = require('./chunk-2YW4FPFG.cjs');
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var _chunkIK4EWJBPcjs = require('./chunk-IK4EWJBP.cjs');
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
var _chunkKS3RYAYLcjs = require('./chunk-KS3RYAYL.cjs');
|
|
12
|
-
|
|
13
|
-
// src/llm/client-base.ts
|
|
14
|
-
_chunkKS3RYAYLcjs.init_cjs_shims.call(void 0, );
|
|
15
|
-
var LLMClientBase = (_class = class _LLMClientBase {
|
|
16
|
-
constructor(config) {;_class.prototype.__init.call(this);
|
|
17
|
-
this.config = config;
|
|
18
|
-
this.provider = config.provider;
|
|
19
|
-
this.model = config.model;
|
|
20
|
-
this.temperature = _nullishCoalesce(config.temperature, () => ( 0.3));
|
|
21
|
-
this.maxTokens = _nullishCoalesce(config.maxTokens, () => ( 8192));
|
|
22
|
-
this.timeout = _nullishCoalesce(config.timeout, () => ( 12e4));
|
|
23
|
-
this.retryMaxAttempts = _nullishCoalesce(config.retryMaxAttempts, () => ( 3));
|
|
24
|
-
this.enableStreaming = _nullishCoalesce(config.enableStreaming, () => ( true));
|
|
25
|
-
this.initClient();
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Process-wide hook fired on every LLM response. The CLI installs this in
|
|
36
|
-
* main.ts to feed the cost tracker; lives on the base class so every code
|
|
37
|
-
* path (REPL, run, arena, sub-agents) reports through one funnel without
|
|
38
|
-
* each call site needing to remember.
|
|
39
|
-
*/
|
|
40
|
-
|
|
41
|
-
__init() {this.usage = {
|
|
42
|
-
records: [],
|
|
43
|
-
totalPromptTokens: 0,
|
|
44
|
-
totalCompletionTokens: 0,
|
|
45
|
-
totalTokens: 0,
|
|
46
|
-
requestCount: 0
|
|
47
|
-
}}
|
|
48
|
-
recordUsage(usage, options) {
|
|
49
|
-
if (_optionalChain([options, 'optionalAccess', _ => _.recordUsage]) === false) return;
|
|
50
|
-
this.usage.records.push(usage);
|
|
51
|
-
this.usage.totalPromptTokens += usage.promptTokens;
|
|
52
|
-
this.usage.totalCompletionTokens += usage.completionTokens;
|
|
53
|
-
this.usage.totalTokens += usage.totalTokens;
|
|
54
|
-
this.usage.requestCount++;
|
|
55
|
-
_optionalChain([_LLMClientBase, 'access', _2 => _2.onUsage, 'optionalCall', _3 => _3(this.model, usage)]);
|
|
56
|
-
}
|
|
57
|
-
getUsage() {
|
|
58
|
-
return { ...this.usage };
|
|
59
|
-
}
|
|
60
|
-
async withRetry(fn, maxAttempts) {
|
|
61
|
-
const attempts = _nullishCoalesce(maxAttempts, () => ( this.retryMaxAttempts));
|
|
62
|
-
let lastError;
|
|
63
|
-
for (let attempt = 1; attempt <= attempts; attempt++) {
|
|
64
|
-
try {
|
|
65
|
-
return await fn();
|
|
66
|
-
} catch (err) {
|
|
67
|
-
lastError = err;
|
|
68
|
-
if (err instanceof _chunk2YW4FPFGcjs.ContextLimitError) throw err;
|
|
69
|
-
if (err instanceof _chunk2YW4FPFGcjs.LLMRateLimitError) {
|
|
70
|
-
const waitMs = (_nullishCoalesce(err.retryAfter, () => ( attempt * 2))) * 1e3;
|
|
71
|
-
_chunkIK4EWJBPcjs.logger.warn("llm.retry", {
|
|
72
|
-
cat: "llm",
|
|
73
|
-
provider: this.provider,
|
|
74
|
-
model: this.model,
|
|
75
|
-
attempt,
|
|
76
|
-
of: attempts,
|
|
77
|
-
reason: "rate_limit",
|
|
78
|
-
waitMs
|
|
79
|
-
});
|
|
80
|
-
await new Promise((r) => setTimeout(r, waitMs));
|
|
81
|
-
continue;
|
|
82
|
-
}
|
|
83
|
-
if (attempt === attempts) {
|
|
84
|
-
_chunkIK4EWJBPcjs.logger.error("llm.exhausted", {
|
|
85
|
-
cat: "llm",
|
|
86
|
-
provider: this.provider,
|
|
87
|
-
model: this.model,
|
|
88
|
-
attempts,
|
|
89
|
-
error: err.message
|
|
90
|
-
});
|
|
91
|
-
break;
|
|
92
|
-
}
|
|
93
|
-
const backoff = Math.min(1e3 * Math.pow(2, attempt - 1), 3e4);
|
|
94
|
-
_chunkIK4EWJBPcjs.logger.warn("llm.retry", {
|
|
95
|
-
cat: "llm",
|
|
96
|
-
provider: this.provider,
|
|
97
|
-
model: this.model,
|
|
98
|
-
attempt,
|
|
99
|
-
of: attempts,
|
|
100
|
-
reason: "error",
|
|
101
|
-
error: err.message,
|
|
102
|
-
backoffMs: backoff
|
|
103
|
-
});
|
|
104
|
-
await new Promise((r) => setTimeout(r, backoff));
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
throw _nullishCoalesce(lastError, () => ( new (0, _chunk2YW4FPFGcjs.LLMError)("Unknown LLM error")));
|
|
108
|
-
}
|
|
109
|
-
}, _class);
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
exports.LLMClientBase = LLMClientBase;
|