chompyy 0.5.0 → 0.6.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/README.md +11 -0
- package/dist/agentlimits.js +77 -0
- package/dist/agentusage.js +96 -0
- package/dist/appstate.js +63 -3
- package/dist/away.js +44 -5
- package/dist/blueprint.js +3 -7
- package/dist/board.js +1 -0
- package/dist/cli.js +263 -5
- package/dist/codexquota.js +106 -0
- package/dist/codexusage.js +10 -0
- package/dist/config.js +2 -0
- package/dist/context.js +30 -0
- package/dist/costs.js +1 -0
- package/dist/demon.js +20 -0
- package/dist/label.js +33 -0
- package/dist/menu.js +17 -0
- package/dist/nightcap.js +60 -0
- package/dist/nudge.js +47 -18
- package/dist/pacing.js +16 -1
- package/dist/questions.js +71 -0
- package/dist/recap.js +74 -0
- package/dist/receipt.js +48 -0
- package/dist/recipe.js +79 -0
- package/dist/stamps.js +14 -0
- package/dist/triggers.js +5 -0
- package/dist/usage.js +21 -1
- package/dist/vendor/codeburn/antigravity.js +309 -0
- package/dist/vendor/codeburn/codex.js +429 -0
- package/dist/vendor/codeburn/copilot.js +292 -0
- package/dist/vendor/codeburn/gemini.js +195 -0
- package/dist/vendor/codeburn/grokbot.js +182 -0
- package/dist/vendor/codeburn/kimi.js +178 -0
- package/dist/vendor/codeburn/shims/chalk.js +14 -0
- package/dist/vendor/codeburn/shims/strip-ansi.js +6 -0
- package/dist/vendor/codeburn/src/act/backup.js +83 -0
- package/dist/vendor/codeburn/src/act/model-defaults.js +151 -0
- package/dist/vendor/codeburn/src/act/types.js +37 -0
- package/dist/vendor/codeburn/src/bash-utils.js +204 -0
- package/dist/vendor/codeburn/src/behavioral-weight.js +47 -0
- package/dist/vendor/codeburn/src/cache-dir.js +26 -0
- package/dist/vendor/codeburn/src/cache-refresh-lock.js +543 -0
- package/dist/vendor/codeburn/src/cache-sweep.js +67 -0
- package/dist/vendor/codeburn/src/classifier.js +209 -0
- package/dist/vendor/codeburn/src/claude-identity.js +223 -0
- package/dist/vendor/codeburn/src/codex-cache.js +377 -0
- package/dist/vendor/codeburn/src/codex-fork-replay.js +232 -0
- package/dist/vendor/codeburn/src/codex-jsonl-fields.js +99 -0
- package/dist/vendor/codeburn/src/codex-session-index.js +113 -0
- package/dist/vendor/codeburn/src/codex-throughput.js +544 -0
- package/dist/vendor/codeburn/src/compare-stats.js +405 -0
- package/dist/vendor/codeburn/src/config.js +145 -0
- package/dist/vendor/codeburn/src/content-utils.js +56 -0
- package/dist/vendor/codeburn/src/context-tree-codex.js +329 -0
- package/dist/vendor/codeburn/src/context-tree.js +664 -0
- package/dist/vendor/codeburn/src/copilot-aiu.js +16 -0
- package/dist/vendor/codeburn/src/currency.js +189 -0
- package/dist/vendor/codeburn/src/cursor-cache.js +238 -0
- package/dist/vendor/codeburn/src/cursor-import.js +402 -0
- package/dist/vendor/codeburn/src/cursor-sync.js +256 -0
- package/dist/vendor/codeburn/src/daily-cache.js +2036 -0
- package/dist/vendor/codeburn/src/data/litellm-snapshot.json +1 -0
- package/dist/vendor/codeburn/src/data/pricing-fallback.json +1 -0
- package/dist/vendor/codeburn/src/day-aggregator.js +327 -0
- package/dist/vendor/codeburn/src/editor-data-dir.js +11 -0
- package/dist/vendor/codeburn/src/fetch-utils.js +18 -0
- package/dist/vendor/codeburn/src/format.js +118 -0
- package/dist/vendor/codeburn/src/fs-utils.js +270 -0
- package/dist/vendor/codeburn/src/git-origin.js +334 -0
- package/dist/vendor/codeburn/src/granular-history.js +328 -0
- package/dist/vendor/codeburn/src/hermes-session-ledger.js +512 -0
- package/dist/vendor/codeburn/src/launcher-homes.js +142 -0
- package/dist/vendor/codeburn/src/live-sessions.js +358 -0
- package/dist/vendor/codeburn/src/math-utils.js +8 -0
- package/dist/vendor/codeburn/src/menubar-json.js +294 -0
- package/dist/vendor/codeburn/src/models.js +1879 -0
- package/dist/vendor/codeburn/src/optimize-one-hour-cache.js +92 -0
- package/dist/vendor/codeburn/src/optimize.js +4110 -0
- package/dist/vendor/codeburn/src/parse-workers.js +219 -0
- package/dist/vendor/codeburn/src/parser.js +6953 -0
- package/dist/vendor/codeburn/src/path-privacy.js +26 -0
- package/dist/vendor/codeburn/src/plans.js +135 -0
- package/dist/vendor/codeburn/src/pr-signals.js +132 -0
- package/dist/vendor/codeburn/src/project-filter-warnings.js +33 -0
- package/dist/vendor/codeburn/src/provider-issues.js +30 -0
- package/dist/vendor/codeburn/src/providers/amp.js +286 -0
- package/dist/vendor/codeburn/src/providers/antigravity.js +1731 -0
- package/dist/vendor/codeburn/src/providers/claude.js +551 -0
- package/dist/vendor/codeburn/src/providers/cline-cli.js +401 -0
- package/dist/vendor/codeburn/src/providers/cline.js +63 -0
- package/dist/vendor/codeburn/src/providers/codebuff.js +336 -0
- package/dist/vendor/codeburn/src/providers/codewhale.js +442 -0
- package/dist/vendor/codeburn/src/providers/codex.js +1720 -0
- package/dist/vendor/codeburn/src/providers/command-code.js +196 -0
- package/dist/vendor/codeburn/src/providers/copilot.js +3278 -0
- package/dist/vendor/codeburn/src/providers/crush.js +226 -0
- package/dist/vendor/codeburn/src/providers/cursor-agent.js +837 -0
- package/dist/vendor/codeburn/src/providers/cursor.js +1163 -0
- package/dist/vendor/codeburn/src/providers/devin.js +569 -0
- package/dist/vendor/codeburn/src/providers/droid.js +324 -0
- package/dist/vendor/codeburn/src/providers/dsh.js +690 -0
- package/dist/vendor/codeburn/src/providers/forge.js +245 -0
- package/dist/vendor/codeburn/src/providers/gemini.js +230 -0
- package/dist/vendor/codeburn/src/providers/goose.js +252 -0
- package/dist/vendor/codeburn/src/providers/grok.js +581 -0
- package/dist/vendor/codeburn/src/providers/grokbot.js +290 -0
- package/dist/vendor/codeburn/src/providers/hermes.js +771 -0
- package/dist/vendor/codeburn/src/providers/ibm-bob.js +53 -0
- package/dist/vendor/codeburn/src/providers/index.js +360 -0
- package/dist/vendor/codeburn/src/providers/kilo-code.js +50 -0
- package/dist/vendor/codeburn/src/providers/kimi.js +363 -0
- package/dist/vendor/codeburn/src/providers/kimicode.js +402 -0
- package/dist/vendor/codeburn/src/providers/kiro.js +1174 -0
- package/dist/vendor/codeburn/src/providers/lingtai-tui.js +372 -0
- package/dist/vendor/codeburn/src/providers/mistral-vibe-unified.js +236 -0
- package/dist/vendor/codeburn/src/providers/mistral-vibe.js +405 -0
- package/dist/vendor/codeburn/src/providers/mux.js +242 -0
- package/dist/vendor/codeburn/src/providers/open-design.js +217 -0
- package/dist/vendor/codeburn/src/providers/openclaude.js +309 -0
- package/dist/vendor/codeburn/src/providers/openclaw.js +442 -0
- package/dist/vendor/codeburn/src/providers/opencode-file-parser.js +131 -0
- package/dist/vendor/codeburn/src/providers/opencode.js +91 -0
- package/dist/vendor/codeburn/src/providers/pi.js +429 -0
- package/dist/vendor/codeburn/src/providers/quickdesk.js +491 -0
- package/dist/vendor/codeburn/src/providers/qwen.js +193 -0
- package/dist/vendor/codeburn/src/providers/session-message.js +118 -0
- package/dist/vendor/codeburn/src/providers/sqlite-session-parser.js +457 -0
- package/dist/vendor/codeburn/src/providers/types.js +5 -0
- package/dist/vendor/codeburn/src/providers/vercel-gateway.js +135 -0
- package/dist/vendor/codeburn/src/providers/vscode-cline-parser.js +212 -0
- package/dist/vendor/codeburn/src/providers/warp.js +575 -0
- package/dist/vendor/codeburn/src/providers/zcode.js +249 -0
- package/dist/vendor/codeburn/src/providers/zed.js +187 -0
- package/dist/vendor/codeburn/src/providers/zerostack.js +139 -0
- package/dist/vendor/codeburn/src/quota/antigravity.js +310 -0
- package/dist/vendor/codeburn/src/quota/claude.js +244 -0
- package/dist/vendor/codeburn/src/quota/cursor.js +301 -0
- package/dist/vendor/codeburn/src/quota/security.js +299 -0
- package/dist/vendor/codeburn/src/quota/types.js +1 -0
- package/dist/vendor/codeburn/src/scan-facts.js +99 -0
- package/dist/vendor/codeburn/src/session-cache.js +3040 -0
- package/dist/vendor/codeburn/src/session-count-label.js +14 -0
- package/dist/vendor/codeburn/src/session-output.js +139 -0
- package/dist/vendor/codeburn/src/session-population.js +30 -0
- package/dist/vendor/codeburn/src/sessions-report.js +1342 -0
- package/dist/vendor/codeburn/src/sqlite.js +528 -0
- package/dist/vendor/codeburn/src/sync/otlp.js +420 -0
- package/dist/vendor/codeburn/src/telemetry-snapshot.js +244 -0
- package/dist/vendor/codeburn/src/token-estimate.js +5 -0
- package/dist/vendor/codeburn/src/types.js +16 -0
- package/dist/vendor/codeburn/src/work-units.js +126 -0
- package/dist/vendor/codeburn/src/workflow-insights.js +228 -0
- package/dist/vendor/codeburn/src/wsl.js +198 -0
- package/dist/vendor/codeburn/src/yield.js +666 -0
- package/package.json +1 -1
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
// @ts-nocheck: codeburn type-checks this under its own tsconfig; Chompyy adds noUncheckedIndexedAccess (see UPSTREAM.md)
|
|
2
|
+
import { readdir, stat, readFile } from 'fs/promises';
|
|
3
|
+
import { join } from 'path';
|
|
4
|
+
import { homedir } from 'os';
|
|
5
|
+
import { readSessionFile, readSessionLines } from '../fs-utils.js';
|
|
6
|
+
import { calculateCost, getShortModelName, ownValue } from '../models.js';
|
|
7
|
+
import { extractBashCommands } from '../bash-utils.js';
|
|
8
|
+
import { normalizeContentBlocks } from '../content-utils.js';
|
|
9
|
+
const toolNameMap = {
|
|
10
|
+
Read: 'Read',
|
|
11
|
+
Create: 'Create',
|
|
12
|
+
Edit: 'Edit',
|
|
13
|
+
MultiEdit: 'MultiEdit',
|
|
14
|
+
LS: 'LS',
|
|
15
|
+
Glob: 'Glob',
|
|
16
|
+
Grep: 'Grep',
|
|
17
|
+
Execute: 'Bash',
|
|
18
|
+
AskUser: 'AskUser',
|
|
19
|
+
TodoWrite: 'TodoWrite',
|
|
20
|
+
Skill: 'Skill',
|
|
21
|
+
Task: 'Agent',
|
|
22
|
+
WebSearch: 'WebSearch',
|
|
23
|
+
FetchUrl: 'FetchUrl',
|
|
24
|
+
GenerateDroid: 'GenerateDroid',
|
|
25
|
+
ExitSpecMode: 'ExitSpecMode',
|
|
26
|
+
};
|
|
27
|
+
function getFactoryDir() {
|
|
28
|
+
return process.env['FACTORY_DIR'] ?? join(homedir(), '.factory');
|
|
29
|
+
}
|
|
30
|
+
// Strip Droid-specific wrapper to get the model's display name.
|
|
31
|
+
// e.g. "custom:GLM-5.1-[Proxy]-0" -> "GLM-5.1"
|
|
32
|
+
// Cost lookup is handled by codeburn's existing calculateCost/getCanonicalName
|
|
33
|
+
// which normalizes case and strips date suffixes automatically.
|
|
34
|
+
// Only a custom model carries a trailing index; elsewhere `-6` is a version
|
|
35
|
+
// and only a real YYYYMMDD date comes off.
|
|
36
|
+
function stripDateSuffix(name) {
|
|
37
|
+
const m = /-(\d{4})(\d{2})(\d{2})$/.exec(name);
|
|
38
|
+
if (!m)
|
|
39
|
+
return name;
|
|
40
|
+
const [y, mo, d] = [Number(m[1]), Number(m[2]), Number(m[3])];
|
|
41
|
+
const date = new Date(Date.UTC(y, mo - 1, d));
|
|
42
|
+
const real = y >= 2020 && y <= 2035 && date.getUTCMonth() === mo - 1 && date.getUTCDate() === d;
|
|
43
|
+
return real ? name.slice(0, m.index) : name;
|
|
44
|
+
}
|
|
45
|
+
function stripModelPrefix(raw) {
|
|
46
|
+
const name = raw.replace(/^custom:/, '').replace(/\[.*?\]/g, '');
|
|
47
|
+
return (raw.startsWith('custom:') ? name.replace(/-\d+$/, '') : stripDateSuffix(name))
|
|
48
|
+
.replace(/-+$/, '')
|
|
49
|
+
.replace(/^-/, '');
|
|
50
|
+
}
|
|
51
|
+
function parseModelForDisplay(raw) {
|
|
52
|
+
const stripped = stripModelPrefix(raw);
|
|
53
|
+
const lower = stripped.toLowerCase();
|
|
54
|
+
if (lower.includes('opus'))
|
|
55
|
+
return getShortModelName(stripped);
|
|
56
|
+
if (lower.includes('sonnet'))
|
|
57
|
+
return getShortModelName(stripped);
|
|
58
|
+
if (lower.includes('haiku'))
|
|
59
|
+
return getShortModelName(stripped);
|
|
60
|
+
if (lower.startsWith('gpt-'))
|
|
61
|
+
return getShortModelName(stripped);
|
|
62
|
+
if (lower.startsWith('o3') || lower.startsWith('o4'))
|
|
63
|
+
return getShortModelName(stripped);
|
|
64
|
+
if (lower.startsWith('gemini'))
|
|
65
|
+
return getShortModelName(stripped);
|
|
66
|
+
return stripped;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Extract meaningful shell command names from a Droid Execute call.
|
|
70
|
+
* Droid frequently passes multi-line scripts (python -c "...", heredocs, etc.)
|
|
71
|
+
* where splitting on ;/&&/| produces noise tokens like '}', 'await', 'import'.
|
|
72
|
+
* Instead, extract only the primary command from each logical line.
|
|
73
|
+
*/
|
|
74
|
+
function extractDroidBashCommands(command) {
|
|
75
|
+
if (!command || !command.trim())
|
|
76
|
+
return [];
|
|
77
|
+
const firstLine = command.split('\n')[0].trim();
|
|
78
|
+
return extractBashCommands(firstLine);
|
|
79
|
+
}
|
|
80
|
+
function createParser(source, seenKeys) {
|
|
81
|
+
return {
|
|
82
|
+
async *parse() {
|
|
83
|
+
const content = await readSessionFile(source.path);
|
|
84
|
+
if (content === null)
|
|
85
|
+
return;
|
|
86
|
+
// Read the companion settings file for token usage
|
|
87
|
+
const settingsPath = source.path.replace(/\.jsonl$/, '.settings.json');
|
|
88
|
+
let settings = {};
|
|
89
|
+
try {
|
|
90
|
+
const raw = await readFile(settingsPath, 'utf-8');
|
|
91
|
+
settings = JSON.parse(raw);
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
// No settings file or parse error
|
|
95
|
+
}
|
|
96
|
+
const lines = content.split('\n').filter(l => l.trim());
|
|
97
|
+
let sessionId = '';
|
|
98
|
+
let sessionModelDisplay = settings.model ? stripModelPrefix(settings.model) : 'unknown';
|
|
99
|
+
let currentUserMessage = '';
|
|
100
|
+
// Collect all assistant messages with their tools
|
|
101
|
+
const assistantCalls = [];
|
|
102
|
+
let pendingTools = [];
|
|
103
|
+
let pendingBashCommands = [];
|
|
104
|
+
for (const line of lines) {
|
|
105
|
+
let entry;
|
|
106
|
+
try {
|
|
107
|
+
entry = JSON.parse(line);
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
if (entry.type === 'session_start') {
|
|
113
|
+
sessionId = entry.id ?? '';
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
if (entry.type !== 'message' || !entry.message)
|
|
117
|
+
continue;
|
|
118
|
+
const msg = entry.message;
|
|
119
|
+
if (msg.role === 'user') {
|
|
120
|
+
// Extract user text from content
|
|
121
|
+
const texts = normalizeContentBlocks(msg.content)
|
|
122
|
+
.filter(c => c.type === 'text' && c.text)
|
|
123
|
+
.map(c => c.text)
|
|
124
|
+
.filter(Boolean);
|
|
125
|
+
// Skip system-reminder-only messages
|
|
126
|
+
const nonSystemTexts = texts.filter(t => !t.startsWith('<system-reminder>'));
|
|
127
|
+
if (nonSystemTexts.length > 0) {
|
|
128
|
+
currentUserMessage = nonSystemTexts.join(' ').slice(0, 500);
|
|
129
|
+
}
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
if (msg.role === 'assistant') {
|
|
133
|
+
const toolUses = normalizeContentBlocks(msg.content).filter(c => c.type === 'tool_use');
|
|
134
|
+
for (const tu of toolUses) {
|
|
135
|
+
const toolName = tu.name ?? '';
|
|
136
|
+
pendingTools.push(ownValue(toolNameMap, toolName) ?? toolName);
|
|
137
|
+
if (toolName === 'Execute' && tu.input && typeof tu.input['command'] === 'string') {
|
|
138
|
+
pendingBashCommands.push(...extractDroidBashCommands(tu.input['command']));
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
// Check if this assistant message has any text content (non-thinking)
|
|
142
|
+
const hasText = normalizeContentBlocks(msg.content).some(c => c.type === 'text' && c.text);
|
|
143
|
+
// Only emit a call entry if there are tools or substantial text
|
|
144
|
+
if (pendingTools.length > 0 || hasText) {
|
|
145
|
+
assistantCalls.push({
|
|
146
|
+
id: entry.id ?? `msg-${assistantCalls.length}`,
|
|
147
|
+
timestamp: entry.timestamp ?? '',
|
|
148
|
+
tools: [...pendingTools],
|
|
149
|
+
bashCommands: [...pendingBashCommands],
|
|
150
|
+
});
|
|
151
|
+
pendingTools = [];
|
|
152
|
+
pendingBashCommands = [];
|
|
153
|
+
}
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
if (assistantCalls.length === 0)
|
|
158
|
+
return;
|
|
159
|
+
// KNOWN LIMITATION: Droid records token usage only at session level
|
|
160
|
+
// (settings.tokenUsage), not per-message. We split evenly across the
|
|
161
|
+
// emitted assistant calls and price all of them at settings.model
|
|
162
|
+
// (the latest model the session used). For sessions where the user
|
|
163
|
+
// switched models mid-stream, costs are approximate — we have no
|
|
164
|
+
// ground-truth breakdown to attribute tokens per model.
|
|
165
|
+
const totalTokens = settings.tokenUsage;
|
|
166
|
+
if (!totalTokens)
|
|
167
|
+
return;
|
|
168
|
+
const totalInput = totalTokens.inputTokens ?? 0;
|
|
169
|
+
const totalOutput = totalTokens.outputTokens ?? 0;
|
|
170
|
+
const totalCacheCreation = totalTokens.cacheCreationTokens ?? 0;
|
|
171
|
+
const totalCacheRead = totalTokens.cacheReadTokens ?? 0;
|
|
172
|
+
const totalThinking = totalTokens.thinkingTokens ?? 0;
|
|
173
|
+
const numCalls = assistantCalls.length;
|
|
174
|
+
// Distribute evenly across calls
|
|
175
|
+
const inputPerCall = Math.floor(totalInput / numCalls);
|
|
176
|
+
const outputPerCall = Math.floor(totalOutput / numCalls);
|
|
177
|
+
const cacheCreationPerCall = Math.floor(totalCacheCreation / numCalls);
|
|
178
|
+
const cacheReadPerCall = Math.floor(totalCacheRead / numCalls);
|
|
179
|
+
const thinkingPerCall = Math.floor(totalThinking / numCalls);
|
|
180
|
+
for (let i = 0; i < assistantCalls.length; i++) {
|
|
181
|
+
const call = assistantCalls[i];
|
|
182
|
+
// Assign remainder to the last call
|
|
183
|
+
const isLast = i === assistantCalls.length - 1;
|
|
184
|
+
const inputTokens = isLast
|
|
185
|
+
? totalInput - inputPerCall * (numCalls - 1)
|
|
186
|
+
: inputPerCall;
|
|
187
|
+
const outputTokens = isLast
|
|
188
|
+
? totalOutput - outputPerCall * (numCalls - 1)
|
|
189
|
+
: outputPerCall;
|
|
190
|
+
const cacheCreationTokens = isLast
|
|
191
|
+
? totalCacheCreation - cacheCreationPerCall * (numCalls - 1)
|
|
192
|
+
: cacheCreationPerCall;
|
|
193
|
+
const cacheReadTokens = isLast
|
|
194
|
+
? totalCacheRead - cacheReadPerCall * (numCalls - 1)
|
|
195
|
+
: cacheReadPerCall;
|
|
196
|
+
const thinkingTokens = isLast
|
|
197
|
+
? totalThinking - thinkingPerCall * (numCalls - 1)
|
|
198
|
+
: thinkingPerCall;
|
|
199
|
+
const dedupKey = `droid:${sessionId}:${call.id}`;
|
|
200
|
+
if (seenKeys.has(dedupKey))
|
|
201
|
+
continue;
|
|
202
|
+
seenKeys.add(dedupKey);
|
|
203
|
+
const costUSD = calculateCost(sessionModelDisplay.toLowerCase(), inputTokens, outputTokens + thinkingTokens, cacheCreationTokens, cacheReadTokens, 0);
|
|
204
|
+
// Use the call's timestamp, or session_start timestamp
|
|
205
|
+
const timestamp = call.timestamp || '';
|
|
206
|
+
yield {
|
|
207
|
+
provider: 'droid',
|
|
208
|
+
model: sessionModelDisplay,
|
|
209
|
+
inputTokens,
|
|
210
|
+
outputTokens,
|
|
211
|
+
cacheCreationInputTokens: cacheCreationTokens,
|
|
212
|
+
cacheReadInputTokens: cacheReadTokens,
|
|
213
|
+
cachedInputTokens: cacheReadTokens,
|
|
214
|
+
reasoningTokens: thinkingTokens,
|
|
215
|
+
webSearchRequests: 0,
|
|
216
|
+
costUSD,
|
|
217
|
+
tools: call.tools,
|
|
218
|
+
bashCommands: call.bashCommands,
|
|
219
|
+
timestamp,
|
|
220
|
+
speed: 'standard',
|
|
221
|
+
deduplicationKey: dedupKey,
|
|
222
|
+
userMessage: i === 0 ? currentUserMessage : '',
|
|
223
|
+
sessionId,
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
},
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
function isInternalSession(cwd, factoryDir) {
|
|
230
|
+
// Skip sessions whose cwd is the .factory directory itself (internal housekeeping)
|
|
231
|
+
const normalized = cwd.replace(/\/+$/, '');
|
|
232
|
+
return normalized === factoryDir;
|
|
233
|
+
}
|
|
234
|
+
function deriveProjectName(cwd) {
|
|
235
|
+
const normalized = cwd.replace(/\/+$/, '');
|
|
236
|
+
const home = homedir();
|
|
237
|
+
// Strip home directory prefix
|
|
238
|
+
let relative = normalized.startsWith(home)
|
|
239
|
+
? normalized.slice(home.length).replace(/^\/+/, '')
|
|
240
|
+
: normalized.replace(/^\/+/, '');
|
|
241
|
+
if (!relative)
|
|
242
|
+
relative = '~';
|
|
243
|
+
// Walk from the right: use the "projects/<name>" segment if present,
|
|
244
|
+
// otherwise the last meaningful path component.
|
|
245
|
+
const parts = relative.split('/');
|
|
246
|
+
const projectsIdx = parts.lastIndexOf('projects');
|
|
247
|
+
if (projectsIdx !== -1 && projectsIdx + 1 < parts.length) {
|
|
248
|
+
return parts.slice(projectsIdx + 1).join('/');
|
|
249
|
+
}
|
|
250
|
+
return parts.join('/');
|
|
251
|
+
}
|
|
252
|
+
async function readFirstJsonlLine(filePath) {
|
|
253
|
+
for await (const line of readSessionLines(filePath)) {
|
|
254
|
+
return line;
|
|
255
|
+
}
|
|
256
|
+
return null;
|
|
257
|
+
}
|
|
258
|
+
async function discoverSessionsInDir(sessionsDir, factoryDir) {
|
|
259
|
+
const sources = [];
|
|
260
|
+
let entries;
|
|
261
|
+
try {
|
|
262
|
+
entries = await readdir(sessionsDir);
|
|
263
|
+
}
|
|
264
|
+
catch {
|
|
265
|
+
return sources;
|
|
266
|
+
}
|
|
267
|
+
for (const entry of entries) {
|
|
268
|
+
const subDir = join(sessionsDir, entry);
|
|
269
|
+
const s = await stat(subDir).catch(() => null);
|
|
270
|
+
if (!s?.isDirectory())
|
|
271
|
+
continue;
|
|
272
|
+
const files = await readdir(subDir).catch(() => []);
|
|
273
|
+
for (const file of files) {
|
|
274
|
+
if (!file.endsWith('.jsonl'))
|
|
275
|
+
continue;
|
|
276
|
+
const filePath = join(subDir, file);
|
|
277
|
+
const firstLine = await readFirstJsonlLine(filePath);
|
|
278
|
+
if (!firstLine?.trim())
|
|
279
|
+
continue;
|
|
280
|
+
let startEntry;
|
|
281
|
+
try {
|
|
282
|
+
startEntry = JSON.parse(firstLine);
|
|
283
|
+
}
|
|
284
|
+
catch {
|
|
285
|
+
continue;
|
|
286
|
+
}
|
|
287
|
+
if (startEntry.type !== 'session_start')
|
|
288
|
+
continue;
|
|
289
|
+
const cwd = startEntry.cwd ?? entry;
|
|
290
|
+
if (isInternalSession(cwd, factoryDir))
|
|
291
|
+
continue;
|
|
292
|
+
sources.push({
|
|
293
|
+
path: filePath,
|
|
294
|
+
project: deriveProjectName(cwd),
|
|
295
|
+
provider: 'droid',
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
return sources;
|
|
300
|
+
}
|
|
301
|
+
export function createDroidProvider(factoryDir) {
|
|
302
|
+
const base = factoryDir ?? getFactoryDir();
|
|
303
|
+
const sessionsDir = join(base, 'sessions');
|
|
304
|
+
return {
|
|
305
|
+
name: 'droid',
|
|
306
|
+
displayName: 'Droid',
|
|
307
|
+
modelDisplayName(model) {
|
|
308
|
+
return parseModelForDisplay(model);
|
|
309
|
+
},
|
|
310
|
+
toolDisplayName(rawTool) {
|
|
311
|
+
return ownValue(toolNameMap, rawTool) ?? rawTool;
|
|
312
|
+
},
|
|
313
|
+
async probeRoots() {
|
|
314
|
+
return [{ path: sessionsDir, label: 'sessions' }];
|
|
315
|
+
},
|
|
316
|
+
async discoverSessions() {
|
|
317
|
+
return discoverSessionsInDir(sessionsDir, base);
|
|
318
|
+
},
|
|
319
|
+
createSessionParser(source, seenKeys) {
|
|
320
|
+
return createParser(source, seenKeys);
|
|
321
|
+
},
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
export const droid = createDroidProvider();
|