@agimon-ai/po-file-edit 0.0.0-alpha.78 → 0.0.0-alpha.79

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.
@@ -28,6 +28,7 @@ let _agimon_ai_po_core_serverPlugin = require("@agimon-ai/po-core/serverPlugin")
28
28
  let _agimon_ai_po_core_extensionFile = require("@agimon-ai/po-core/extensionFile");
29
29
  let _agimon_ai_po_core_childSession = require("@agimon-ai/po-core/childSession");
30
30
  let _agimon_ai_po_core_hubChannel = require("@agimon-ai/po-core/hubChannel");
31
+ let _agimon_ai_po_core_packageApi = require("@agimon-ai/po-core/packageApi");
31
32
  let node_fs_promises = require("node:fs/promises");
32
33
  node_fs_promises = __toESM(node_fs_promises, 1);
33
34
  let node_path = require("node:path");
@@ -64,12 +65,6 @@ const MINUTE_MS = 6e4;
64
65
  const SHORT_ID_LENGTH = 8;
65
66
  /** Pi's built-in grep prints match rows as `relative/path:line: text`. */
66
67
  const PI_GREP_ROW = /^(.+?):(\d+): /u;
67
- function forgetPresence(ledger, agentKey) {
68
- for (const [file, entries] of ledger) {
69
- entries.delete(agentKey);
70
- if (entries.size === 0) ledger.delete(file);
71
- }
72
- }
73
68
  function stringArg(args, key) {
74
69
  if (typeof args !== "object" || args === null) return void 0;
75
70
  const value = args[key];
@@ -105,26 +100,6 @@ function ago(elapsed) {
105
100
  const minutes = Math.floor(elapsed / MINUTE_MS);
106
101
  return minutes < 1 ? "under 1m ago" : `${minutes}m ago`;
107
102
  }
108
- function liveOthers(ledger, file, self) {
109
- const entries = ledger.get(file);
110
- if (entries === void 0) return [];
111
- const live = [];
112
- for (const [key, entry] of entries) {
113
- if (key === self) continue;
114
- if (entry.agent.isLive()) live.push(entry);
115
- else entries.delete(key);
116
- }
117
- return live.sort((left, right) => right.at - left.at);
118
- }
119
- function record(ledger, file, agent, tag, at) {
120
- const entries = ledger.get(file) ?? /* @__PURE__ */ new Map();
121
- entries.set(agent.key, {
122
- agent,
123
- tag,
124
- at
125
- });
126
- ledger.set(file, entries);
127
- }
128
103
  function renderNote(lines) {
129
104
  const shown = lines.slice(0, MAX_NOTE_LINES);
130
105
  const more = lines.length - shown.length;
@@ -140,14 +115,13 @@ function renderNote(lines) {
140
115
  * Returns the content with one note appended, or undefined when there is nothing to add, so callers
141
116
  * never rewrite a result needlessly.
142
117
  */
143
- async function observePresence(ledger, agent, call, now = Date.now()) {
118
+ async function observePresence(presence, agent, call, now = Date.now()) {
144
119
  const recording = EDIT_TOOLS.has(call.toolName) && !call.isError;
145
- if (!recording && ledger.size === 0) return void 0;
146
120
  const lines = [];
147
121
  for (const file of await touchedFiles(call)) {
148
122
  const real = await node_fs_promises.default.realpath(file).catch(() => void 0);
149
123
  if (real === void 0) continue;
150
- const others = liveOthers(ledger, real, agent.key);
124
+ const others = presence.touch(real, agent);
151
125
  let bytes;
152
126
  if (others.length > 0) {
153
127
  bytes = await node_fs_promises.default.readFile(real).catch(() => void 0);
@@ -160,7 +134,11 @@ async function observePresence(ledger, agent, call, now = Date.now()) {
160
134
  }
161
135
  if (recording) {
162
136
  bytes ??= await node_fs_promises.default.readFile(real).catch(() => void 0);
163
- if (bytes !== void 0) record(ledger, real, agent, (0, _agimon_ai_po_hashline_files.computeFileTag)(bytes), now);
137
+ if (bytes !== void 0) presence.record(real, {
138
+ agent,
139
+ tag: (0, _agimon_ai_po_hashline_files.computeFileTag)(bytes),
140
+ at: now
141
+ });
164
142
  }
165
143
  }
166
144
  if (lines.length === 0) return void 0;
@@ -171,7 +149,7 @@ async function observePresence(ledger, agent, call, now = Date.now()) {
171
149
  }
172
150
  /** Edit presence for one hub session and the in-process children it spawns. */
173
151
  function createSessionPresence(options) {
174
- const { sessionId, ledger } = options;
152
+ const { sessionId, presence } = options;
175
153
  const sessionAgent = {
176
154
  key: `session:${sessionId}`,
177
155
  label: () => `session ${sessionId}${options.workflowStep ? " (workflow step)" : ""}`,
@@ -193,7 +171,7 @@ function createSessionPresence(options) {
193
171
  const toolName = event.toolName;
194
172
  if (execution.sessionId !== sessionId || typeof toolName !== "string" || !Array.isArray(event.content)) return;
195
173
  const content = event.content;
196
- const next = await safely(() => observePresence(ledger, sessionAgent, {
174
+ const next = await safely(() => observePresence(presence, sessionAgent, {
197
175
  toolName,
198
176
  args: event.args,
199
177
  content,
@@ -214,7 +192,7 @@ function createSessionPresence(options) {
214
192
  return {
215
193
  beforeTool: () => void 0,
216
194
  async afterTool(event) {
217
- const next = await safely(() => observePresence(ledger, child, {
195
+ const next = await safely(() => observePresence(presence, child, {
218
196
  toolName: event.toolName,
219
197
  args: event.args,
220
198
  content: event.content,
@@ -223,10 +201,10 @@ function createSessionPresence(options) {
223
201
  }));
224
202
  return next === void 0 ? void 0 : { content: next };
225
203
  },
226
- dispose: async () => forgetPresence(ledger, child.key)
204
+ dispose: async () => presence.forget(child.key)
227
205
  };
228
206
  } },
229
- dispose: () => forgetPresence(ledger, sessionAgent.key)
207
+ dispose: () => presence.forget(sessionAgent.key)
230
208
  };
231
209
  }
232
210
  //#endregion
@@ -2139,11 +2117,11 @@ function createFileEditSession({ agent, host, context }) {
2139
2117
  //#endregion
2140
2118
  //#region src/extensions/workspaces/sessions/(backend)/_lib/serverRoot.ts
2141
2119
  function createPresence({ agent, host, context }) {
2142
- const ledger = host.context.editPresence;
2143
- if (!agent || !ledger) return void 0;
2120
+ const presence = context.get(_agimon_ai_po_core_packageApi.PO_EDIT_PRESENCE_SERVICE);
2121
+ if (!agent || !presence) return void 0;
2144
2122
  const execution = agent.context;
2145
2123
  return createSessionPresence({
2146
- ledger,
2124
+ presence,
2147
2125
  sessionId: execution.sessionId,
2148
2126
  cwd: execution.cwd,
2149
2127
  workflowStep: execution.sessionContext?.provenance === _agimon_ai_po_core_hubChannel.WORKFLOW_STEP_SESSION_PROVENANCE,