@dougbots/avenor-pi 0.3.3 → 0.3.5

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.
Files changed (2) hide show
  1. package/dist/index.js +57 -5
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -90,6 +90,14 @@ function buildCompletionText(run, result) {
90
90
  lines.push(`\nCall \`avenor_events\` with \`run_id: "${run.runId}"\` to review the output, or \`avenor_follow_up\` to iterate.`);
91
91
  return lines.join("\n");
92
92
  }
93
+ function buildWaitingText(run, status) {
94
+ const perm = status.pending_permission;
95
+ const lines = [`Sub-agent "${run.label}" (${run.agent}) is waiting for input.`];
96
+ if (perm) lines.push(`Permission request: ${perm.description}`, `To answer: call \`avenor_answer_permission\` with run_id "${run.runId}", option_id "allow_once" | "allow_always" | "deny"`);
97
+ else if (status.phase_label) lines.push(`Question: ${status.phase_label}`);
98
+ if (!perm) lines.push(`Use \`avenor_follow_up\` with run_id "${run.runId}" to respond, or \`avenor_status\` to re-check.`);
99
+ return lines.join("\n");
100
+ }
93
101
  function summarizeEvent(evt) {
94
102
  const type = String(evt.type ?? evt.event ?? "");
95
103
  if (type === "tool.call" || type === "tool.use") return `called ${String(evt.tool ?? evt.name ?? type)}`;
@@ -157,12 +165,35 @@ async function src_default(pi) {
157
165
  for (const [id, run] of trackedRuns) prevStatuses.set(id, run.lastStatus?.status);
158
166
  const entries = await pollRuns();
159
167
  updateWidget(entries);
160
- for (const entry of entries) if (TERMINAL_STATUSES.has(entry.status)) {
161
- if (trackedRuns.get(entry.runId)) {
168
+ for (const entry of entries) {
169
+ const run = trackedRuns.get(entry.runId);
170
+ if (!run) continue;
171
+ if (TERMINAL_STATUSES.has(entry.status)) {
162
172
  const prevStatus = prevStatuses.get(entry.runId);
163
- if (prevStatus && !TERMINAL_STATUSES.has(prevStatus)) sessionCtx?.ui.notify(`Sub-agent "${entry.label}" finished: ${entry.status}`, entry.status === "done" ? "info" : "warning");
173
+ if (prevStatus && !TERMINAL_STATUSES.has(prevStatus)) {
174
+ sessionCtx?.ui.notify(`Sub-agent "${entry.label}" finished: ${entry.status}`, entry.status === "done" ? "info" : "warning");
175
+ if (!run.blocking) try {
176
+ pi.sendUserMessage(buildCompletionText({
177
+ runId: run.runId,
178
+ label: run.label
179
+ }, run.lastStatus), { deliverAs: "followUp" });
180
+ } catch (err) {
181
+ console.error("avenor tick: sendUserMessage failed", err);
182
+ }
183
+ }
164
184
  trackedRuns.delete(entry.runId);
165
- }
185
+ } else if (entry.pendingPermission && !run.blocking && !run.permissionNotified) {
186
+ run.permissionNotified = true;
187
+ try {
188
+ pi.sendUserMessage(buildWaitingText({
189
+ runId: run.runId,
190
+ label: run.label,
191
+ agent: run.agent
192
+ }, run.lastStatus), { deliverAs: "followUp" });
193
+ } catch (err) {
194
+ console.error("avenor tick: sendUserMessage for permission failed", err);
195
+ }
196
+ } else if (!entry.pendingPermission && run.permissionNotified) run.permissionNotified = false;
166
197
  }
167
198
  if (entries.some((e) => !TERMINAL_STATUSES.has(e.status))) setTimeout(tick, POLL_INTERVAL_MS);
168
199
  else {
@@ -254,7 +285,8 @@ async function src_default(pi) {
254
285
  agent: params.agent,
255
286
  label,
256
287
  supervisorId: result.supervisor_id,
257
- startTime: Date.now()
288
+ startTime: Date.now(),
289
+ blocking: wait
258
290
  });
259
291
  startPolling();
260
292
  if (!wait) return {
@@ -327,6 +359,26 @@ async function src_default(pi) {
327
359
  }
328
360
  });
329
361
  }
362
+ if (status.status === "waiting") {
363
+ const tracked = trackedRuns.get(result.run_id);
364
+ if (tracked) tracked.permissionNotified = true;
365
+ return {
366
+ content: [{
367
+ type: "text",
368
+ text: buildWaitingText({
369
+ runId: result.run_id,
370
+ label,
371
+ agent: params.agent
372
+ }, status)
373
+ }],
374
+ details: {
375
+ status: "waiting",
376
+ run_id: result.run_id,
377
+ session_id: status.session_id,
378
+ ...status.pending_permission && { pending_permission: status.pending_permission }
379
+ }
380
+ };
381
+ }
330
382
  if (TERMINAL_STATUSES.has(status.status)) {
331
383
  trackedRuns.delete(result.run_id);
332
384
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dougbots/avenor-pi",
3
- "version": "0.3.3",
3
+ "version": "0.3.5",
4
4
  "type": "module",
5
5
  "keywords": [
6
6
  "pi-package"
@@ -35,7 +35,7 @@
35
35
  "dev": "tsdown --watch"
36
36
  },
37
37
  "dependencies": {
38
- "@dougbots/avenor-core": "^0.3.3"
38
+ "@dougbots/avenor-core": "^0.3.5"
39
39
  },
40
40
  "peerDependencies": {
41
41
  "@earendil-works/pi-coding-agent": "*",