farming-code 2.2.29 → 2.2.30
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 +25 -66
- package/README.zh_cn.md +15 -66
- package/backend/acp-runtime.js +1 -15
- package/backend/acp-session-state.js +78 -88
- package/backend/agent-session-history.js +45 -12
- package/backend/codex-session-history.js +1 -1
- package/backend/codex-transcript.js +0 -202
- package/backend/config-manager.js +3 -19
- package/backend/farming-app-cli.js +1 -1
- package/backend/farming-cli.js +3 -57
- package/backend/index-html.js +21 -3
- package/backend/main-agent-skills.js +1 -18
- package/backend/server.js +6 -48
- package/backend/storage-layout.js +15 -0
- package/backend/update-service.js +55 -935
- package/config/farming.deploy.env.example +1 -1
- package/config/farming.install.env.example +1 -1
- package/dist/acp/codex-acp-1.1.4.mjs +387 -7
- package/dist/assets/App-Z1N7T0eM.js +695 -0
- package/dist/assets/{ProjectFilesSection-Cf2BEcAN.js → ProjectFilesSection-K3GHuQ4U.js} +2 -2
- package/dist/assets/code-dark-kLsQLvpf.css +1 -0
- package/dist/assets/{index-CQNaZc3l.js → index-D-zetSol.js} +2 -2
- package/dist/assets/main-DUTz-Rd2.css +1 -0
- package/dist/index.html +2 -1
- package/extensions/browser/backend/browser-resource-manager.js +27 -5
- package/extensions/browser/backend/browser-router.js +8 -0
- package/extensions/browser/backend/executable-discovery.js +26 -12
- package/extensions/browser/backend/managed-chromium-installer.js +593 -0
- package/extensions/browser/frontend/types.ts +8 -1
- package/extensions/browser/frontend/useBrowserResources.ts +8 -0
- package/index.html +1 -0
- package/package.json +1 -1
- package/backend/agent-memory-report.js +0 -583
- package/backend/bundle-update-helper.js +0 -113
- package/backend/codex-rollout-follower.js +0 -326
- package/dist/assets/App-Ex2oVVXO.js +0 -693
- package/dist/assets/code-dark-BEZTQwYZ.css +0 -1
- package/dist/assets/main-DK9Sy7-c.css +0 -1
|
@@ -1,326 +0,0 @@
|
|
|
1
|
-
const EventEmitter = require('events');
|
|
2
|
-
const fs = require('fs');
|
|
3
|
-
const fsp = require('fs/promises');
|
|
4
|
-
const os = require('os');
|
|
5
|
-
const path = require('path');
|
|
6
|
-
|
|
7
|
-
const DEFAULT_POLL_INTERVAL_MS = 1000;
|
|
8
|
-
const DEFAULT_MAX_READ_BYTES = 512 * 1024;
|
|
9
|
-
const USER_MESSAGE_BEGIN = '## My request for Codex:';
|
|
10
|
-
|
|
11
|
-
function normalizePathValue(value) {
|
|
12
|
-
if (typeof value !== 'string') return '';
|
|
13
|
-
const trimmed = value.trim();
|
|
14
|
-
if (!trimmed || trimmed === path.sep) return trimmed;
|
|
15
|
-
return trimmed.replace(/[\\/]+$/, '');
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function sessionIdFromFilePath(filePath) {
|
|
19
|
-
const match = path.basename(filePath).match(/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})\.jsonl$/i);
|
|
20
|
-
return match ? match[1] : '';
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function findCodexRolloutFile(sessionId, options = {}) {
|
|
24
|
-
const normalizedSessionId = String(sessionId || '').trim();
|
|
25
|
-
if (!normalizedSessionId) return '';
|
|
26
|
-
|
|
27
|
-
const codexHome = normalizePathValue(options.codexHome || path.join(os.homedir(), '.codex'));
|
|
28
|
-
const roots = [
|
|
29
|
-
path.join(codexHome, 'sessions'),
|
|
30
|
-
path.join(codexHome, 'archived_sessions'),
|
|
31
|
-
];
|
|
32
|
-
|
|
33
|
-
for (const root of roots) {
|
|
34
|
-
const stack = [root];
|
|
35
|
-
while (stack.length > 0) {
|
|
36
|
-
const directory = stack.pop();
|
|
37
|
-
let entries = [];
|
|
38
|
-
try {
|
|
39
|
-
entries = fs.readdirSync(directory, { withFileTypes: true });
|
|
40
|
-
} catch {
|
|
41
|
-
continue;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
for (const entry of entries) {
|
|
45
|
-
const fullPath = path.join(directory, entry.name);
|
|
46
|
-
if (entry.isDirectory()) {
|
|
47
|
-
stack.push(fullPath);
|
|
48
|
-
} else if (
|
|
49
|
-
entry.isFile()
|
|
50
|
-
&& entry.name.endsWith('.jsonl')
|
|
51
|
-
&& sessionIdFromFilePath(fullPath) === normalizedSessionId
|
|
52
|
-
) {
|
|
53
|
-
return fullPath;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return '';
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function recentSessionDirectories(root, now = new Date()) {
|
|
63
|
-
const directories = [];
|
|
64
|
-
for (const offsetDays of [-1, 0, 1]) {
|
|
65
|
-
const date = new Date(now.getTime() + offsetDays * 24 * 60 * 60 * 1000);
|
|
66
|
-
directories.push(
|
|
67
|
-
path.join(
|
|
68
|
-
root,
|
|
69
|
-
String(date.getFullYear()),
|
|
70
|
-
String(date.getMonth() + 1).padStart(2, '0'),
|
|
71
|
-
String(date.getDate()).padStart(2, '0'),
|
|
72
|
-
),
|
|
73
|
-
path.join(
|
|
74
|
-
root,
|
|
75
|
-
String(date.getUTCFullYear()),
|
|
76
|
-
String(date.getUTCMonth() + 1).padStart(2, '0'),
|
|
77
|
-
String(date.getUTCDate()).padStart(2, '0'),
|
|
78
|
-
),
|
|
79
|
-
);
|
|
80
|
-
}
|
|
81
|
-
return [...new Set(directories)];
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
async function findCodexRolloutFileAsync(sessionId, options = {}) {
|
|
85
|
-
const normalizedSessionId = String(sessionId || '').trim();
|
|
86
|
-
if (!normalizedSessionId) return '';
|
|
87
|
-
const codexHome = normalizePathValue(options.codexHome || path.join(os.homedir(), '.codex'));
|
|
88
|
-
const maxEntries = Number.isFinite(options.maxEntries)
|
|
89
|
-
? Math.max(1, Math.floor(options.maxEntries))
|
|
90
|
-
: 100_000;
|
|
91
|
-
const deadline = Number.isFinite(options.deadline)
|
|
92
|
-
? Number(options.deadline)
|
|
93
|
-
: Date.now() + 5_000;
|
|
94
|
-
const sessionsRoot = path.join(codexHome, 'sessions');
|
|
95
|
-
const archivedRoot = path.join(codexHome, 'archived_sessions');
|
|
96
|
-
const preferredDirectories = [
|
|
97
|
-
...recentSessionDirectories(sessionsRoot),
|
|
98
|
-
...(options.recentOnly === true ? [] : [archivedRoot]),
|
|
99
|
-
];
|
|
100
|
-
const visited = new Set();
|
|
101
|
-
let inspectedEntries = 0;
|
|
102
|
-
|
|
103
|
-
async function inspectDirectory(directory, descend) {
|
|
104
|
-
if (Date.now() > deadline || inspectedEntries >= maxEntries || visited.has(directory)) return '';
|
|
105
|
-
visited.add(directory);
|
|
106
|
-
let entries;
|
|
107
|
-
try {
|
|
108
|
-
entries = await fsp.readdir(directory, { withFileTypes: true });
|
|
109
|
-
} catch {
|
|
110
|
-
return '';
|
|
111
|
-
}
|
|
112
|
-
const subdirectories = [];
|
|
113
|
-
for (const entry of entries) {
|
|
114
|
-
inspectedEntries += 1;
|
|
115
|
-
if (Date.now() > deadline || inspectedEntries > maxEntries) return '';
|
|
116
|
-
const fullPath = path.join(directory, entry.name);
|
|
117
|
-
if (entry.isFile() && entry.name.endsWith('.jsonl') && sessionIdFromFilePath(fullPath) === normalizedSessionId) {
|
|
118
|
-
return fullPath;
|
|
119
|
-
}
|
|
120
|
-
if (descend && entry.isDirectory()) subdirectories.push(fullPath);
|
|
121
|
-
}
|
|
122
|
-
return subdirectories;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
for (const directory of preferredDirectories) {
|
|
126
|
-
const found = await inspectDirectory(directory, false);
|
|
127
|
-
if (typeof found === 'string' && found) return found;
|
|
128
|
-
}
|
|
129
|
-
if (options.recentOnly === true) return '';
|
|
130
|
-
|
|
131
|
-
const stack = [sessionsRoot, archivedRoot];
|
|
132
|
-
while (stack.length > 0 && Date.now() <= deadline && inspectedEntries < maxEntries) {
|
|
133
|
-
const directory = stack.pop();
|
|
134
|
-
const result = await inspectDirectory(directory, true);
|
|
135
|
-
if (typeof result === 'string') {
|
|
136
|
-
if (result) return result;
|
|
137
|
-
continue;
|
|
138
|
-
}
|
|
139
|
-
stack.push(...result);
|
|
140
|
-
}
|
|
141
|
-
return '';
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
function normalizePreviewText(value, maxLength = 400) {
|
|
145
|
-
return String(value || '')
|
|
146
|
-
.replace(/\r\n/g, '\n')
|
|
147
|
-
.replace(/\r/g, '\n')
|
|
148
|
-
.trim()
|
|
149
|
-
.slice(0, maxLength);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
function stripUserMessagePrefix(value) {
|
|
153
|
-
const text = String(value || '');
|
|
154
|
-
const index = text.indexOf(USER_MESSAGE_BEGIN);
|
|
155
|
-
return index >= 0 ? text.slice(index + USER_MESSAGE_BEGIN.length).trim() : text.trim();
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
function jsonFieldPreview(value, key, maxLength = 120) {
|
|
159
|
-
try {
|
|
160
|
-
const parsed = typeof value === 'string' ? JSON.parse(value) : value;
|
|
161
|
-
const field = parsed && typeof parsed === 'object' ? parsed[key] : '';
|
|
162
|
-
return normalizePreviewText(field, maxLength).replace(/\s+/g, ' ');
|
|
163
|
-
} catch {
|
|
164
|
-
return '';
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
function formatFunctionCall(payload) {
|
|
169
|
-
const name = String(payload.name || '').trim();
|
|
170
|
-
if (!name) return '';
|
|
171
|
-
|
|
172
|
-
if (name === 'exec_command') {
|
|
173
|
-
const cmd = jsonFieldPreview(payload.arguments, 'cmd');
|
|
174
|
-
return cmd ? `running command: ${cmd}` : 'running command';
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
if (name === 'apply_patch') return 'applying patch';
|
|
178
|
-
return `running ${name}`;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
function formatCodexRolloutEvent(line) {
|
|
182
|
-
let event = null;
|
|
183
|
-
try {
|
|
184
|
-
event = JSON.parse(line);
|
|
185
|
-
} catch {
|
|
186
|
-
return '';
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
const payload = event && typeof event.payload === 'object' ? event.payload : null;
|
|
190
|
-
if (!payload) return '';
|
|
191
|
-
|
|
192
|
-
if (event.type === 'event_msg') {
|
|
193
|
-
if (payload.type === 'agent_message') {
|
|
194
|
-
const message = normalizePreviewText(payload.message);
|
|
195
|
-
return message ? `[Codex live]\r\n${message.replace(/\n/g, '\r\n')}\r\n` : '';
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
if (payload.type === 'user_message') {
|
|
199
|
-
const message = normalizePreviewText(stripUserMessagePrefix(payload.message), 240);
|
|
200
|
-
return message ? `[Codex live] queued user message: ${message.replace(/\n/g, ' ')}\r\n` : '';
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
if (payload.type === 'task_complete') {
|
|
204
|
-
return '[Codex live] task complete\r\n';
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
return '';
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
if (event.type === 'response_item') {
|
|
211
|
-
if (payload.type === 'function_call') {
|
|
212
|
-
const message = formatFunctionCall(payload);
|
|
213
|
-
return message ? `[Codex live] ${message}\r\n` : '';
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
return '';
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
return '';
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
async function readFileRange(filePath, start, end) {
|
|
223
|
-
const length = Math.max(0, end - start);
|
|
224
|
-
if (length <= 0) return '';
|
|
225
|
-
|
|
226
|
-
const handle = await fsp.open(filePath, 'r');
|
|
227
|
-
try {
|
|
228
|
-
const buffer = Buffer.alloc(length);
|
|
229
|
-
const result = await handle.read(buffer, 0, length, start);
|
|
230
|
-
return buffer.subarray(0, result.bytesRead).toString('utf8');
|
|
231
|
-
} finally {
|
|
232
|
-
await handle.close().catch(() => {});
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
class CodexRolloutFollower extends EventEmitter {
|
|
237
|
-
constructor(sessionId, options = {}) {
|
|
238
|
-
super();
|
|
239
|
-
this.sessionId = String(sessionId || '').trim();
|
|
240
|
-
this.codexHome = options.codexHome;
|
|
241
|
-
this.pollIntervalMs = Number.isFinite(options.pollIntervalMs)
|
|
242
|
-
? Math.max(250, options.pollIntervalMs)
|
|
243
|
-
: DEFAULT_POLL_INTERVAL_MS;
|
|
244
|
-
this.maxReadBytes = Number.isFinite(options.maxReadBytes)
|
|
245
|
-
? Math.max(4096, options.maxReadBytes)
|
|
246
|
-
: DEFAULT_MAX_READ_BYTES;
|
|
247
|
-
this.filePath = options.filePath || '';
|
|
248
|
-
this.offset = Number.isFinite(options.offset) ? Math.max(0, options.offset) : 0;
|
|
249
|
-
this.partialLine = '';
|
|
250
|
-
this.timer = null;
|
|
251
|
-
this.stopped = false;
|
|
252
|
-
this.polling = false;
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
async start() {
|
|
256
|
-
if (!this.sessionId || this.timer || this.stopped) return;
|
|
257
|
-
this.filePath = this.filePath || findCodexRolloutFile(this.sessionId, {
|
|
258
|
-
codexHome: this.codexHome,
|
|
259
|
-
});
|
|
260
|
-
if (!this.filePath) return;
|
|
261
|
-
|
|
262
|
-
if (!this.offset) {
|
|
263
|
-
try {
|
|
264
|
-
this.offset = (await fsp.stat(this.filePath)).size;
|
|
265
|
-
} catch {
|
|
266
|
-
this.offset = 0;
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
this.timer = setInterval(() => {
|
|
271
|
-
this.poll().catch(error => this.emit('error', error));
|
|
272
|
-
}, this.pollIntervalMs);
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
async poll() {
|
|
276
|
-
if (this.stopped || this.polling || !this.filePath) return;
|
|
277
|
-
this.polling = true;
|
|
278
|
-
try {
|
|
279
|
-
const stat = await fsp.stat(this.filePath);
|
|
280
|
-
if (stat.size < this.offset) {
|
|
281
|
-
this.offset = stat.size;
|
|
282
|
-
this.partialLine = '';
|
|
283
|
-
return;
|
|
284
|
-
}
|
|
285
|
-
if (stat.size === this.offset) return;
|
|
286
|
-
|
|
287
|
-
const oldOffset = this.offset;
|
|
288
|
-
const start = Math.max(oldOffset, stat.size - this.maxReadBytes);
|
|
289
|
-
const droppedPrefix = start > oldOffset;
|
|
290
|
-
const chunk = await readFileRange(this.filePath, start, stat.size);
|
|
291
|
-
this.offset = stat.size;
|
|
292
|
-
|
|
293
|
-
const text = droppedPrefix ? chunk : this.partialLine + chunk;
|
|
294
|
-
const lines = text.split('\n');
|
|
295
|
-
this.partialLine = lines.pop() || '';
|
|
296
|
-
if (droppedPrefix) {
|
|
297
|
-
lines.shift();
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
const formatted = lines
|
|
301
|
-
.map(formatCodexRolloutEvent)
|
|
302
|
-
.filter(Boolean)
|
|
303
|
-
.join('');
|
|
304
|
-
if (formatted) {
|
|
305
|
-
this.emit('data', formatted);
|
|
306
|
-
}
|
|
307
|
-
} finally {
|
|
308
|
-
this.polling = false;
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
stop() {
|
|
313
|
-
this.stopped = true;
|
|
314
|
-
if (this.timer) {
|
|
315
|
-
clearInterval(this.timer);
|
|
316
|
-
this.timer = null;
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
module.exports = {
|
|
322
|
-
CodexRolloutFollower,
|
|
323
|
-
findCodexRolloutFile,
|
|
324
|
-
findCodexRolloutFileAsync,
|
|
325
|
-
formatCodexRolloutEvent,
|
|
326
|
-
};
|