farming-code 2.2.16 → 2.2.18
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 +2 -2
- package/README.zh_cn.md +2 -2
- package/THIRD_PARTY_NOTICES.md +16 -0
- package/backend/acp-runtime.js +221 -10
- package/backend/agent-manager.js +477 -54
- package/backend/agent-provider-session.js +15 -1
- package/backend/codex-rollout-follower.js +83 -0
- package/backend/codex-session-archive.js +12 -1
- package/backend/codex-session-history.js +94 -0
- package/backend/config-manager.js +3 -3
- package/backend/farming-app-cli.js +8 -0
- package/backend/native-pty-host-client.js +59 -2
- package/backend/provider-adapters.js +117 -36
- package/backend/provider-session-service.js +138 -34
- package/backend/server.js +5 -1
- package/backend/storage-layout.js +5 -0
- package/backend/usage-history-client.js +305 -0
- package/backend/usage-history-scanner.generated.js +2250 -0
- package/backend/usage-history-scanner.ts +2718 -0
- package/backend/usage-history-smoke.js +64 -0
- package/backend/usage-history-worker.js +34 -0
- package/backend/usage-monitor.js +188 -588
- package/backend/vendor/usage-parsers/CC_STATISTICS_LICENSE +21 -0
- package/backend/vendor/usage-parsers/CODEXBAR_LICENSE +21 -0
- package/backend/vendor/usage-parsers/VENDOR.json +45 -0
- package/dist/assets/App-DTAQilnX.js +210 -0
- package/dist/assets/code-dark-5esj0bRu.css +1 -0
- package/dist/assets/{index-iKBvPjWS.js → index-fp8VhOes.js} +2 -2
- package/dist/assets/main-DSO3i_Gs.css +1 -0
- package/dist/index.html +1 -1
- package/frontend/skins/crt/app.js +9 -3
- package/package.json +12 -8
- package/shared/backend-connection-status.d.ts +25 -0
- package/shared/backend-connection-status.js +40 -0
- package/dist/assets/App-y6p2yRar.js +0 -206
- package/dist/assets/code-dark-DKBGxoPX.css +0 -1
- package/dist/assets/main-CdkLOXYl.css +0 -1
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const os = require('os');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const { UsageHistoryClient } = require('./usage-history-client');
|
|
5
|
+
|
|
6
|
+
async function runUsageHistorySmoke() {
|
|
7
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'farming-usage-smoke-'));
|
|
8
|
+
try {
|
|
9
|
+
const sessions = path.join(root, 'sessions');
|
|
10
|
+
fs.mkdirSync(sessions, { recursive: true });
|
|
11
|
+
fs.writeFileSync(path.join(sessions, 'rollout.jsonl'), [
|
|
12
|
+
JSON.stringify({
|
|
13
|
+
timestamp: '2026-01-01T00:00:00.000Z',
|
|
14
|
+
type: 'session_meta',
|
|
15
|
+
payload: {
|
|
16
|
+
id: 'farming-usage-smoke',
|
|
17
|
+
timestamp: '2026-01-01T00:00:00.000Z',
|
|
18
|
+
cwd: root,
|
|
19
|
+
},
|
|
20
|
+
}),
|
|
21
|
+
JSON.stringify({
|
|
22
|
+
timestamp: '2026-01-01T00:00:01.000Z',
|
|
23
|
+
type: 'event_msg',
|
|
24
|
+
payload: {
|
|
25
|
+
type: 'token_count',
|
|
26
|
+
info: {
|
|
27
|
+
total_token_usage: { input_tokens: 5, output_tokens: 2 },
|
|
28
|
+
last_token_usage: { input_tokens: 5, output_tokens: 2 },
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
}),
|
|
32
|
+
'',
|
|
33
|
+
].join('\n'));
|
|
34
|
+
const result = await new UsageHistoryClient({
|
|
35
|
+
configDir: path.join(root, 'config'),
|
|
36
|
+
}).collect({
|
|
37
|
+
now: Date.parse('2026-01-01T01:00:00.000Z'),
|
|
38
|
+
codexRoots: [sessions],
|
|
39
|
+
claudeRoots: [],
|
|
40
|
+
scanBudgetMs: 30_000,
|
|
41
|
+
fresh: true,
|
|
42
|
+
});
|
|
43
|
+
const total = result.providers.codex.events.reduce(
|
|
44
|
+
(sum, event) => sum + event.totalTokens,
|
|
45
|
+
0,
|
|
46
|
+
);
|
|
47
|
+
if (
|
|
48
|
+
result.cache.scan_complete !== true
|
|
49
|
+
|| result.cache.discovery_ready !== true
|
|
50
|
+
|| total !== 7
|
|
51
|
+
) {
|
|
52
|
+
throw new Error(`Usage history smoke returned an invalid result: ${JSON.stringify({
|
|
53
|
+
scanComplete: result.cache.scan_complete,
|
|
54
|
+
discoveryReady: result.cache.discovery_ready,
|
|
55
|
+
total,
|
|
56
|
+
})}`);
|
|
57
|
+
}
|
|
58
|
+
return { schemaVersion: result.schemaVersion, total };
|
|
59
|
+
} finally {
|
|
60
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
module.exports = { runUsageHistorySmoke };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const { parentPort, workerData } = require('worker_threads');
|
|
2
|
+
|
|
3
|
+
async function collect(request) {
|
|
4
|
+
const { collectUsage } = require('./usage-history-scanner.generated');
|
|
5
|
+
return collectUsage(request);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
let queue = Promise.resolve();
|
|
9
|
+
|
|
10
|
+
function enqueue(message) {
|
|
11
|
+
queue = queue.then(async () => {
|
|
12
|
+
try {
|
|
13
|
+
const result = await collect(message.request);
|
|
14
|
+
parentPort.postMessage({ requestId: message.requestId, result });
|
|
15
|
+
} catch (error) {
|
|
16
|
+
parentPort.postMessage({
|
|
17
|
+
requestId: message.requestId,
|
|
18
|
+
error: {
|
|
19
|
+
message: error instanceof Error ? error.message : String(error),
|
|
20
|
+
code: error && typeof error === 'object' ? error.code : undefined,
|
|
21
|
+
stack: error instanceof Error ? error.stack : undefined,
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
parentPort.on('message', enqueue);
|
|
29
|
+
|
|
30
|
+
// Keep accepting the former one-shot shape for already-built artifacts during
|
|
31
|
+
// a controlled application update.
|
|
32
|
+
if (workerData?.request) {
|
|
33
|
+
enqueue({ requestId: workerData.requestId || 'initial', request: workerData.request });
|
|
34
|
+
}
|