@agimon-ai/po-file-edit 0.0.0-alpha.198 → 0.0.0-alpha.199
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/extensions/server.cjs +155 -110
- package/dist/extensions/server.cjs.map +1 -1
- package/dist/extensions/server.mjs +155 -110
- package/dist/extensions/server.mjs.map +1 -1
- package/dist/index.cjs +3 -0
- package/dist/index.d.mts +13 -0
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/package-D5Z6rBN0.mjs +6 -0
- package/dist/package-D5Z6rBN0.mjs.map +1 -0
- package/dist/package-ZnJMUINx.cjs +11 -0
- package/dist/package-ZnJMUINx.cjs.map +1 -0
- package/dist/po-runtime-identity.json +1 -1
- package/package.json +9 -9
|
@@ -24,6 +24,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
24
24
|
enumerable: true
|
|
25
25
|
}) : target, mod));
|
|
26
26
|
//#endregion
|
|
27
|
+
const require_package = require("../package-ZnJMUINx.cjs");
|
|
27
28
|
let _agimon_ai_po_core_serverPlugin = require("@agimon-ai/po-core/serverPlugin");
|
|
28
29
|
let _agimon_ai_po_core_extensionFile = require("@agimon-ai/po-core/extensionFile");
|
|
29
30
|
let _agimon_ai_po_core_platform = require("@agimon-ai/po-core/platform");
|
|
@@ -1487,20 +1488,35 @@ function createSessionPresence(options) {
|
|
|
1487
1488
|
}
|
|
1488
1489
|
};
|
|
1489
1490
|
return {
|
|
1490
|
-
|
|
1491
|
-
event: "
|
|
1491
|
+
operationAfter: {
|
|
1492
|
+
event: "operation_after",
|
|
1492
1493
|
async handle(event, execution) {
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
const
|
|
1494
|
+
if (execution.sessionId !== sessionId || event.outcome !== "executed") return;
|
|
1495
|
+
const direct = event.operation.kind === "tool";
|
|
1496
|
+
const name = event.operation.name;
|
|
1497
|
+
const fsWrite = event.operation.kind === "codemode" && [
|
|
1498
|
+
"fs.writeFile",
|
|
1499
|
+
"fs.appendFile",
|
|
1500
|
+
"fs.copyFile",
|
|
1501
|
+
"fs.rename"
|
|
1502
|
+
].includes(name);
|
|
1503
|
+
const result = event.result;
|
|
1504
|
+
if (!direct && !fsWrite) return;
|
|
1505
|
+
const content = result && typeof result === "object" && "content" in result && Array.isArray(result.content) ? result.content : [];
|
|
1506
|
+
const toolName = fsWrite ? "write" : name;
|
|
1507
|
+
const args = fsWrite ? { path: event.args[["fs.copyFile", "fs.rename"].includes(name) ? 1 : 0] } : event.args[0];
|
|
1496
1508
|
const next = await safely(() => observePresence(presence, sessionAgent, {
|
|
1497
1509
|
toolName,
|
|
1498
|
-
args
|
|
1510
|
+
args,
|
|
1499
1511
|
content,
|
|
1500
|
-
isError:
|
|
1512
|
+
isError: !!(result && typeof result === "object" && "isError" in result && result.isError),
|
|
1501
1513
|
cwd: execution.cwd
|
|
1502
1514
|
}, void 0, options.files));
|
|
1503
|
-
|
|
1515
|
+
if (next === void 0) return void 0;
|
|
1516
|
+
return direct && result && typeof result === "object" ? { result: {
|
|
1517
|
+
...result,
|
|
1518
|
+
content: next
|
|
1519
|
+
} } : { notes: next.slice(content.length).flatMap((part) => "text" in part && typeof part.text === "string" ? [part.text] : []) };
|
|
1504
1520
|
}
|
|
1505
1521
|
},
|
|
1506
1522
|
childHooks: { bind(scope) {
|
|
@@ -1702,6 +1718,7 @@ var EditTracker = class {
|
|
|
1702
1718
|
* A candidate whose hash has not moved was touched, not edited.
|
|
1703
1719
|
*/
|
|
1704
1720
|
contents = /* @__PURE__ */ new Map();
|
|
1721
|
+
onChanged;
|
|
1705
1722
|
now;
|
|
1706
1723
|
git;
|
|
1707
1724
|
onScanFailed;
|
|
@@ -1715,6 +1732,7 @@ var EditTracker = class {
|
|
|
1715
1732
|
this.timeline = timeline;
|
|
1716
1733
|
this.snapshots = snapshots;
|
|
1717
1734
|
this.manifests = manifests;
|
|
1735
|
+
this.onChanged = options.onChanged;
|
|
1718
1736
|
this.now = options.now ?? Date.now;
|
|
1719
1737
|
this.git = options.git;
|
|
1720
1738
|
this.onScanFailed = options.onScanFailed;
|
|
@@ -1924,6 +1942,11 @@ var EditTracker = class {
|
|
|
1924
1942
|
async append(event) {
|
|
1925
1943
|
if (event.before !== void 0 && event.before === event.after) return;
|
|
1926
1944
|
await this.timeline.append(event);
|
|
1945
|
+
if (event.after !== void 0 && (event.origin === "tool" || event.verified)) try {
|
|
1946
|
+
await this.onChanged?.([event.path]);
|
|
1947
|
+
} catch (error) {
|
|
1948
|
+
this.onScanFailed(error);
|
|
1949
|
+
}
|
|
1927
1950
|
}
|
|
1928
1951
|
/**
|
|
1929
1952
|
* Folds a path the tool layer just handled into the tracked manifest, so the
|
|
@@ -2235,8 +2258,16 @@ function createFileEditSession({ agent, host }, fs, storage = createFileEditStor
|
|
|
2235
2258
|
enableLogs: true,
|
|
2236
2259
|
enableTraces: true
|
|
2237
2260
|
});
|
|
2261
|
+
const changeListeners = /* @__PURE__ */ new Set();
|
|
2238
2262
|
const editTracker = new EditTracker(timeline, snapshots, storage.manifests(), {
|
|
2239
2263
|
git: storage.git(),
|
|
2264
|
+
onChanged: async (paths) => {
|
|
2265
|
+
for (const listener of changeListeners) try {
|
|
2266
|
+
await listener(paths);
|
|
2267
|
+
} catch (error) {
|
|
2268
|
+
await telemetry.recordWarning("po_file_edit.subscriber_failed", error);
|
|
2269
|
+
}
|
|
2270
|
+
},
|
|
2240
2271
|
onScanFailed: (error) => void track(() => telemetry.recordWarning("po_file_edit.scan_failed", error))
|
|
2241
2272
|
});
|
|
2242
2273
|
if (host.context.directEvents === void 0) throw new Error("File-edit server plugin requires the session direct event bus.");
|
|
@@ -2303,107 +2334,121 @@ function createFileEditSession({ agent, host }, fs, storage = createFileEditStor
|
|
|
2303
2334
|
], "File-edit session cleanup failed.");
|
|
2304
2335
|
return disposal;
|
|
2305
2336
|
};
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
editTracker.reset({
|
|
2326
|
-
exclude: [
|
|
2327
|
-
timelinePath,
|
|
2328
|
-
`${timelinePath}.lock`,
|
|
2329
|
-
snapshotsPath
|
|
2330
|
-
],
|
|
2331
|
-
...isIgnored === void 0 ? {} : { isIgnored }
|
|
2332
|
-
});
|
|
2333
|
-
const runtime = {
|
|
2334
|
-
context: executionContext,
|
|
2337
|
+
const activity = {
|
|
2338
|
+
name: "file-edits",
|
|
2339
|
+
start: async (executionContext) => {
|
|
2340
|
+
if (closed) throw new Error("File-edit session is closed.");
|
|
2341
|
+
if (starting) return starting;
|
|
2342
|
+
if (active) return stopActivity;
|
|
2343
|
+
if (stopping) await stopping;
|
|
2344
|
+
if (closed) throw new Error("File-edit session is closed.");
|
|
2345
|
+
if (starting) return starting;
|
|
2346
|
+
stopping = void 0;
|
|
2347
|
+
starting = track(async () => {
|
|
2348
|
+
const sessionKey = paths.sessionKey(executionContext.sessionId);
|
|
2349
|
+
const timelinePath = await paths.timelinePath(executionContext.cwd, sessionKey);
|
|
2350
|
+
const snapshotsPath = await paths.snapshotsPath(executionContext.cwd, sessionKey);
|
|
2351
|
+
timeline.initialize(timelinePath);
|
|
2352
|
+
snapshots.initialize(snapshotsPath);
|
|
2353
|
+
const isIgnored = await readPoIgnore(executionContext.cwd, fs);
|
|
2354
|
+
editTracker.reset({
|
|
2355
|
+
exclude: [
|
|
2335
2356
|
timelinePath,
|
|
2357
|
+
`${timelinePath}.lock`,
|
|
2336
2358
|
snapshotsPath
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
await
|
|
2359
|
+
],
|
|
2360
|
+
...isIgnored === void 0 ? {} : { isIgnored }
|
|
2361
|
+
});
|
|
2362
|
+
const runtime = {
|
|
2363
|
+
context: executionContext,
|
|
2364
|
+
timelinePath,
|
|
2365
|
+
snapshotsPath
|
|
2366
|
+
};
|
|
2367
|
+
active = runtime;
|
|
2368
|
+
lastRuntime = runtime;
|
|
2369
|
+
await publish(runtime);
|
|
2370
|
+
track(async () => {
|
|
2371
|
+
try {
|
|
2372
|
+
await storage.sweepAbandoned?.(paths.stateDirectory(), timelinePath);
|
|
2373
|
+
} catch (error) {
|
|
2374
|
+
await telemetry.recordWarning("po_file_edit.sweep_failed", error);
|
|
2351
2375
|
}
|
|
2352
|
-
return () => active === runtime ? stopActivity() : Promise.resolve();
|
|
2353
2376
|
});
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
starting = void 0;
|
|
2377
|
+
if (!initialized) {
|
|
2378
|
+
initialized = true;
|
|
2379
|
+
await track(() => telemetry.recordEvent("po_file_edit.timeline_started", { outcome: "initialized" }));
|
|
2358
2380
|
}
|
|
2381
|
+
return () => active === runtime ? stopActivity() : Promise.resolve();
|
|
2382
|
+
});
|
|
2383
|
+
try {
|
|
2384
|
+
return await starting;
|
|
2385
|
+
} finally {
|
|
2386
|
+
starting = void 0;
|
|
2359
2387
|
}
|
|
2360
|
-
}
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2388
|
+
}
|
|
2389
|
+
};
|
|
2390
|
+
const startHook = {
|
|
2391
|
+
event: "tool_execution_start",
|
|
2392
|
+
handle: (event, executionContext) => {
|
|
2393
|
+
if (closed || stopping) return;
|
|
2394
|
+
const runtime = active;
|
|
2395
|
+
const toolCallId = stringValue(event, "toolCallId");
|
|
2396
|
+
const toolName = stringValue(event, "toolName");
|
|
2397
|
+
if (runtime === void 0 || runtime.context.sessionId !== executionContext.sessionId || !toolCallId || !toolName) return;
|
|
2398
|
+
return track(async () => {
|
|
2399
|
+
const hookStartedAt = Date.now();
|
|
2400
|
+
if (!await editTracker.start(toolCallId, toolName, event.args, executionContext.cwd) || active !== runtime) return;
|
|
2401
|
+
toolStartedAt.set(toolCallId, hookStartedAt);
|
|
2402
|
+
await telemetry.recordEvent("po_file_edit.edit_started", {
|
|
2403
|
+
"tool.name": toolName,
|
|
2404
|
+
hook_ms: Date.now() - hookStartedAt
|
|
2377
2405
|
});
|
|
2378
|
-
}
|
|
2379
|
-
}
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2406
|
+
});
|
|
2407
|
+
}
|
|
2408
|
+
};
|
|
2409
|
+
const endHook = {
|
|
2410
|
+
event: "tool_execution_end",
|
|
2411
|
+
handle: (event, executionContext) => {
|
|
2412
|
+
if (closed || stopping) return;
|
|
2413
|
+
const runtime = active;
|
|
2414
|
+
const toolCallId = stringValue(event, "toolCallId");
|
|
2415
|
+
const toolName = stringValue(event, "toolName");
|
|
2416
|
+
if (runtime === void 0 || runtime.context.sessionId !== executionContext.sessionId || !toolCallId || !toolName) return;
|
|
2417
|
+
return track(async () => {
|
|
2418
|
+
const startedAt = toolStartedAt.get(toolCallId);
|
|
2419
|
+
if (startedAt === void 0) return;
|
|
2420
|
+
toolStartedAt.delete(toolCallId);
|
|
2421
|
+
const hookStartedAt = Date.now();
|
|
2422
|
+
const isError = event.isError === true;
|
|
2423
|
+
await editTracker.end(toolCallId, isError, executionContext.cwd);
|
|
2424
|
+
if (active !== runtime) return;
|
|
2425
|
+
await publish(runtime);
|
|
2426
|
+
await telemetry.recordEvent("po_file_edit.edit_finished", {
|
|
2427
|
+
"tool.name": toolName,
|
|
2428
|
+
"tool.result.error": isError,
|
|
2429
|
+
...failureAttributes(event.result),
|
|
2430
|
+
...startedAt === void 0 ? {} : { duration_ms: Date.now() - startedAt },
|
|
2431
|
+
hook_ms: Date.now() - hookStartedAt,
|
|
2432
|
+
outcome: isError ? "failed" : "completed"
|
|
2404
2433
|
});
|
|
2405
|
-
}
|
|
2406
|
-
}
|
|
2434
|
+
});
|
|
2435
|
+
}
|
|
2436
|
+
};
|
|
2437
|
+
const changes = {
|
|
2438
|
+
sessionId: agent.context.sessionId,
|
|
2439
|
+
subscribe(listener) {
|
|
2440
|
+
changeListeners.add(listener);
|
|
2441
|
+
return () => {
|
|
2442
|
+
changeListeners.delete(listener);
|
|
2443
|
+
};
|
|
2444
|
+
},
|
|
2445
|
+
flush: () => editTracker.flush()
|
|
2446
|
+
};
|
|
2447
|
+
return {
|
|
2448
|
+
services: [(scope) => scope.provide(require_package.PO_FILE_EDIT_CHANGES_SERVICE, changes)],
|
|
2449
|
+
api: [fileEditsApi],
|
|
2450
|
+
activities: [activity],
|
|
2451
|
+
hooks: [startHook, endHook],
|
|
2407
2452
|
onDispose: dispose
|
|
2408
2453
|
};
|
|
2409
2454
|
}
|
|
@@ -2438,7 +2483,7 @@ const createFileEditServerRoot = (context, fs) => {
|
|
|
2438
2483
|
}
|
|
2439
2484
|
},
|
|
2440
2485
|
activities: runtime.activities,
|
|
2441
|
-
services: [(cordis) => {
|
|
2486
|
+
services: [...runtime.services ?? [], (cordis) => {
|
|
2442
2487
|
cordis.inject([_agimon_ai_po_core_packageApi.PO_EDIT_PRESENCE_SERVICE], (presenceContext) => {
|
|
2443
2488
|
if (closed) return;
|
|
2444
2489
|
const bound = createPresence(context, presenceContext.get(_agimon_ai_po_core_packageApi.PO_EDIT_PRESENCE_SERVICE), storage.presenceFiles());
|
|
@@ -2488,18 +2533,18 @@ var fileEdits_server_default = (0, _agimon_ai_po_core_extensionFile.defineChanne
|
|
|
2488
2533
|
*/
|
|
2489
2534
|
var route_server_default = (0, _agimon_ai_po_core_extensionFile.defineRoute)((context) => createFileEditsPoApi(createFileEditStorage((0, _agimon_ai_po_core_platform.readPoFs)(context.context))));
|
|
2490
2535
|
//#endregion
|
|
2536
|
+
//#region src/extensions/workspaces/sessions/(backend)/hook/operation-after.server.ts
|
|
2537
|
+
var operation_after_server_default = (0, _agimon_ai_po_core_extensionFile.defineHook)(({ root }) => ({
|
|
2538
|
+
event: "operation_after",
|
|
2539
|
+
handle: async (event, execution) => root.presence?.operationAfter.handle(event, execution)
|
|
2540
|
+
}));
|
|
2541
|
+
//#endregion
|
|
2491
2542
|
//#region src/extensions/workspaces/sessions/(backend)/hook/tool-execution-end.server.ts
|
|
2492
2543
|
var tool_execution_end_server_default = (0, _agimon_ai_po_core_extensionFile.defineHook)((context) => context.root.hooks[1]);
|
|
2493
2544
|
//#endregion
|
|
2494
2545
|
//#region src/extensions/workspaces/sessions/(backend)/hook/tool-execution-start.server.ts
|
|
2495
2546
|
var tool_execution_start_server_default = (0, _agimon_ai_po_core_extensionFile.defineHook)((context) => context.root.hooks[0]);
|
|
2496
2547
|
//#endregion
|
|
2497
|
-
//#region src/extensions/workspaces/sessions/(backend)/hook/tool-result.server.ts
|
|
2498
|
-
var tool_result_server_default = (0, _agimon_ai_po_core_extensionFile.defineHook)(({ root }) => ({
|
|
2499
|
-
event: "tool_result",
|
|
2500
|
-
handle: async (event, execution) => root.presence?.toolResult.handle(event, execution)
|
|
2501
|
-
}));
|
|
2502
|
-
//#endregion
|
|
2503
2548
|
//#region generated/server.ts
|
|
2504
2549
|
const at = (value, context) => typeof value === "function" ? value(context) : value;
|
|
2505
2550
|
/* v8 ignore next -- generated normalization branch */
|
|
@@ -2534,9 +2579,9 @@ const serverPlugin = (0, _agimon_ai_po_core_serverPlugin.defineServerPlugin)({
|
|
|
2534
2579
|
},
|
|
2535
2580
|
get hooks() {
|
|
2536
2581
|
return [
|
|
2582
|
+
via({ event: "operation_after" }, at(operation_after_server_default, contextSession)),
|
|
2537
2583
|
via({ event: "tool_execution_end" }, at(tool_execution_end_server_default, contextSession)),
|
|
2538
|
-
via({ event: "tool_execution_start" }, at(tool_execution_start_server_default, contextSession))
|
|
2539
|
-
via({ event: "tool_result" }, at(tool_result_server_default, contextSession))
|
|
2584
|
+
via({ event: "tool_execution_start" }, at(tool_execution_start_server_default, contextSession))
|
|
2540
2585
|
];
|
|
2541
2586
|
},
|
|
2542
2587
|
services: [...scopeSession.services ?? []],
|