@skydiveai/pi-extensions 0.1.258-beta.132 → 0.1.258-beta.134

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.mjs +239 -111
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -265,7 +265,7 @@ function createHealthHandler({ metadata }) {
265
265
  const CAPABILITY_SOUL_NUDGE = "New capability gained — once the current task is done, if this changes what you can do for the user, record it in `soul.md` so it carries into future conversations rather than being rediscovered from scratch (then commit and push).";
266
266
  //#endregion
267
267
  //#region src/extensions/tool-call-summary.ts
268
- const log$21 = logger.child({ module: "tool-call-summary-extension" });
268
+ const log$22 = logger.child({ module: "tool-call-summary-extension" });
269
269
  /**
270
270
  * The injected parameter name. Deliberately markdown-safe: the previous wire
271
271
  * name (`__skydive_summary__`, now `TOOL_CALL_SUMMARY_FIELD_LEGACY`) carried
@@ -499,7 +499,7 @@ function withSummaryStrippedBeforeValidation(tool) {
499
499
  try {
500
500
  stripped = withoutInjectedSummary(args);
501
501
  } catch (err) {
502
- log$21.error({
502
+ log$22.error({
503
503
  err,
504
504
  event: "tool_call_summary_prepare_strip_failed",
505
505
  toolName: tool.name
@@ -530,7 +530,7 @@ function stripInjectedSummary(pi, toolName, input) {
530
530
  if (toolDeclaresSummaryParam(pi, toolName)) return;
531
531
  for (const field of TOOL_CALL_SUMMARY_FIELDS) delete input[field];
532
532
  } catch (err) {
533
- log$21.error({
533
+ log$22.error({
534
534
  err,
535
535
  event: "tool_call_summary_strip_failed",
536
536
  toolName
@@ -546,7 +546,7 @@ function buildInjectedPayload(pi, payload) {
546
546
  try {
547
547
  return injectToolCallSummary(payload, getStrictToolNames(pi));
548
548
  } catch (err) {
549
- log$21.error({
549
+ log$22.error({
550
550
  err,
551
551
  event: "tool_call_summary_injection_failed"
552
552
  }, "tool_call_summary injection failed; passing payload through unchanged");
@@ -565,7 +565,7 @@ const toolCallSummaryExtension = (pi) => {
565
565
  pi.registerTool(withSummaryStrippedBeforeValidation(createEditToolDefinition(ctx.cwd)));
566
566
  editOverrideRegistered = true;
567
567
  } catch (err) {
568
- log$21.error({
568
+ log$22.error({
569
569
  err,
570
570
  event: "tool_call_summary_edit_override_failed"
571
571
  }, "failed to register summary-tolerant edit tool; built-in remains active");
@@ -596,7 +596,7 @@ const toolCallSummaryExtension = (pi) => {
596
596
  * or `ToolDefinition[]`. Files starting with `_` or `.` are skipped, so
597
597
  * `tools/_example.ts` documents the shape without registering.
598
598
  */
599
- const log$20 = logger.child({ module: "local-tools-extension" });
599
+ const log$21 = logger.child({ module: "local-tools-extension" });
600
600
  const TOOLS_DIRNAME = "tools";
601
601
  const fileState = /* @__PURE__ */ new Map();
602
602
  let pendingLocalToolsUpdate = null;
@@ -740,7 +740,7 @@ async function reconcileAndQueue({ pi, dir, reason }) {
740
740
  dir
741
741
  });
742
742
  if (reason !== "session_start" && summaryHasChanges$1(summary)) pendingLocalToolsUpdate = summary;
743
- log$20.info({
743
+ log$21.info({
744
744
  event: "local_tools_reconcile",
745
745
  reason,
746
746
  total_tools: summary.totalTools,
@@ -762,7 +762,7 @@ const localToolsExtension = (pi) => {
762
762
  reason: "session_start"
763
763
  });
764
764
  } catch (err) {
765
- log$20.error({
765
+ log$21.error({
766
766
  err,
767
767
  event: "local_tools_reconcile_failed"
768
768
  }, "local tools reconcile failed");
@@ -774,7 +774,7 @@ const localToolsExtension = (pi) => {
774
774
  try {
775
775
  current = await listToolFiles(dir);
776
776
  } catch (err) {
777
- log$20.warn({
777
+ log$21.warn({
778
778
  err,
779
779
  event: "local_tools_listing_failed"
780
780
  }, "tools/ listing failed");
@@ -796,7 +796,7 @@ const localToolsExtension = (pi) => {
796
796
  reason: "auto_reload"
797
797
  });
798
798
  } catch (err) {
799
- log$20.error({
799
+ log$21.error({
800
800
  err,
801
801
  event: "local_tools_auto_reload_failed"
802
802
  }, "auto-reload after tools/ change failed");
@@ -1500,7 +1500,7 @@ function toProviderSafeSchema(inputSchema) {
1500
1500
  * Clients are keyed by JSON-stringified config and reused across
1501
1501
  * reloads — only changed configs reconnect.
1502
1502
  */
1503
- const log$19 = logger.child({ module: "mcp-extension" });
1503
+ const log$20 = logger.child({ module: "mcp-extension" });
1504
1504
  function resolveToolSelection(server) {
1505
1505
  return {
1506
1506
  allow: server?.tools?.length ? new Set(server.tools) : null,
@@ -1698,7 +1698,7 @@ function providerSafeTools({ serverId, tools }) {
1698
1698
  for (const tool of tools) {
1699
1699
  const result = toProviderSafeSchema(tool.inputSchema);
1700
1700
  if (!result.ok) {
1701
- log$19.warn({
1701
+ log$20.warn({
1702
1702
  event: "mcp_tool_schema_unsupported",
1703
1703
  server_id: serverId,
1704
1704
  tool_name: tool.name,
@@ -2172,7 +2172,7 @@ var McpExtension = class {
2172
2172
  });
2173
2173
  this.lastConfigMtimeMs = await readConfigMtimeMs(configPath);
2174
2174
  if (reason !== "session_start" && summaryHasChanges(summary)) this.pendingMcpUpdate = summary;
2175
- log$19.info({
2175
+ log$20.info({
2176
2176
  event: "mcp_reconcile",
2177
2177
  reason,
2178
2178
  total_tools: summary.totalTools,
@@ -2199,7 +2199,7 @@ var McpExtension = class {
2199
2199
  contextWindow: ctx.model?.contextWindow
2200
2200
  });
2201
2201
  } catch (err) {
2202
- log$19.error({
2202
+ log$20.error({
2203
2203
  err,
2204
2204
  event: "mcp_reconcile_failed"
2205
2205
  }, "MCP reconcile failed");
@@ -2213,7 +2213,7 @@ var McpExtension = class {
2213
2213
  for (const legacy of renamed) {
2214
2214
  if (this.loggedLegacyToolNames.has(legacy)) continue;
2215
2215
  this.loggedLegacyToolNames.add(legacy);
2216
- log$19.info({
2216
+ log$20.info({
2217
2217
  event: "mcp_tool_legacy_name",
2218
2218
  legacy_name: legacy,
2219
2219
  tool_name: this.legacyToolNames.get(legacy)
@@ -2227,7 +2227,7 @@ var McpExtension = class {
2227
2227
  try {
2228
2228
  mtime = await readConfigMtimeMs(configPath);
2229
2229
  } catch (err) {
2230
- log$19.warn({
2230
+ log$20.warn({
2231
2231
  err,
2232
2232
  event: "mcp_mtime_check_failed"
2233
2233
  }, "mtime check on mcp.config.json failed");
@@ -2242,7 +2242,7 @@ var McpExtension = class {
2242
2242
  contextWindow: ctx.model?.contextWindow
2243
2243
  });
2244
2244
  } catch (err) {
2245
- log$19.error({
2245
+ log$20.error({
2246
2246
  err,
2247
2247
  event: "mcp_auto_reload_failed"
2248
2248
  }, "auto-reload after mcp.config.json change failed");
@@ -2608,6 +2608,12 @@ const assistantSchema = z.object({
2608
2608
  id: z.string(),
2609
2609
  model: z.string()
2610
2610
  });
2611
+ /** Sent as the SDK prompt when Pi's context ends with tool results. */
2612
+ const SEAT_CONTINUE_PROMPT = "Continue from the existing conversation and tool results.";
2613
+ const continuePromptSchema = z.object({ content: z.union([z.literal(SEAT_CONTINUE_PROMPT), z.tuple([z.object({
2614
+ type: z.literal("text"),
2615
+ text: z.literal(SEAT_CONTINUE_PROMPT)
2616
+ })])]) });
2611
2617
  const sdkToolResultSchema = z.object({ content: z.array(z.object({ type: z.literal("tool_result") })).min(1) });
2612
2618
  function assistantMessage(entry) {
2613
2619
  if (entry.type !== "assistant") return null;
@@ -2630,6 +2636,8 @@ function isSdkToolResult(entry) {
2630
2636
  * the pair must stay so the cached prefix is byte-identical between steps, but
2631
2637
  * once a newer user message exists it is dropped: otherwise the model rereads
2632
2638
  * itself saying "No response requested." once per historical tool step.
2639
+ * Only our own continuation prompt goes with it; when a steer was the prompt,
2640
+ * the user's text follows the synthetic turn and must be kept.
2633
2641
  */
2634
2642
  function withoutResumePlaceholders(entries) {
2635
2643
  let dropPrompt = false;
@@ -2640,7 +2648,7 @@ function withoutResumePlaceholders(entries) {
2640
2648
  }
2641
2649
  if (dropPrompt && entry.type === "user") {
2642
2650
  dropPrompt = false;
2643
- return false;
2651
+ return !continuePromptSchema.safeParse(entry.message).success;
2644
2652
  }
2645
2653
  return true;
2646
2654
  });
@@ -2795,7 +2803,7 @@ async function prepareSeatHistory({ context, configDir, cwd, toolName, model })
2795
2803
  const hashes = seatPrefixHashes(context, model);
2796
2804
  const messages = [...context.messages];
2797
2805
  const last = messages.at(-1);
2798
- const prompt = last?.role === "user" ? userContent(last.content) : "Continue from the existing conversation and tool results.";
2806
+ const prompt = last?.role === "user" ? userContent(last.content) : SEAT_CONTINUE_PROMPT;
2799
2807
  if (last?.role === "user") messages.pop();
2800
2808
  if (messages.length === 0) return {
2801
2809
  prompt,
@@ -2981,7 +2989,7 @@ const SEAT_QUERY_TIMEOUTS = {
2981
2989
  preparation: 3e4
2982
2990
  };
2983
2991
  const PI_TOOLS_SERVER = "custom-tools";
2984
- const log$18 = logger.child({ module: "claude-seat-sdk" });
2992
+ const log$19 = logger.child({ module: "claude-seat-sdk" });
2985
2993
  /** Preserve existing MCP names; only ordinary Pi tools need a server prefix. */
2986
2994
  function toolBindings(context) {
2987
2995
  const parsed = (context.tools ?? []).map((definition) => {
@@ -3039,7 +3047,7 @@ var SeatQuery = class {
3039
3047
  this.deadline = setTimeout(() => {
3040
3048
  const err = /* @__PURE__ */ new Error(`Claude seat SDK timed out waiting for ${phase}`);
3041
3049
  err.name = "TimeoutError";
3042
- log$18.error({
3050
+ log$19.error({
3043
3051
  err,
3044
3052
  phase
3045
3053
  }, "Claude seat SDK wait deadline exceeded");
@@ -3220,7 +3228,7 @@ var SeatQuery = class {
3220
3228
  }
3221
3229
  } catch (err) {
3222
3230
  this.failure = err;
3223
- if (!this.controller.signal.aborted) log$18.error({
3231
+ if (!this.controller.signal.aborted) log$19.error({
3224
3232
  err,
3225
3233
  sessionId
3226
3234
  }, "Claude seat SDK query failed");
@@ -3235,7 +3243,7 @@ var SeatQuery = class {
3235
3243
  force: true
3236
3244
  });
3237
3245
  } catch (err) {
3238
- log$18.error({
3246
+ log$19.error({
3239
3247
  err,
3240
3248
  sessionId
3241
3249
  }, "Could not remove Claude seat SDK config");
@@ -3268,7 +3276,7 @@ function mapUsage(usage) {
3268
3276
  //#endregion
3269
3277
  //#region src/extensions/claude-seat-response.ts
3270
3278
  const toolInput = z.record(z.string(), z.unknown());
3271
- const log$17 = logger.child({ module: "claude-seat-sdk" });
3279
+ const log$18 = logger.child({ module: "claude-seat-sdk" });
3272
3280
  /**
3273
3281
  * Claude sometimes calls a tool by the name it had outside the bridge (Pi's
3274
3282
  * own name from non-seat history, or a bare MCP tool name). Resolve those when
@@ -3282,7 +3290,7 @@ function piToolName({ name, context, sessionId }) {
3282
3290
  const bare = bindings.filter((binding) => binding.toolName === name);
3283
3291
  const [only] = bare;
3284
3292
  if (only && bare.length === 1) return only.definition.name;
3285
- log$17.warn({
3293
+ log$18.warn({
3286
3294
  sessionId,
3287
3295
  toolName: name,
3288
3296
  candidates: bare.length
@@ -3473,7 +3481,7 @@ var ModelResponse = class {
3473
3481
  * each step resumes a private structured snapshot after Pi extensions run.
3474
3482
  * Initially adapted from elidickinson/pi-claude-bridge (MIT).
3475
3483
  */
3476
- const log$16 = logger.child({ module: "claude-seat-sdk" });
3484
+ const log$17 = logger.child({ module: "claude-seat-sdk" });
3477
3485
  const SEAT_SDK_ACTIVITY_EVENT = "claude-seat-sdk:activity";
3478
3486
  /** Session-scoped adapter; only the flagged provider dispatches here. */
3479
3487
  var SeatSdkBridge = class {
@@ -3524,7 +3532,7 @@ var SeatSdkBridge = class {
3524
3532
  } else if (message.type === "result") {
3525
3533
  const hasTools = response.hasTools;
3526
3534
  if (message.is_error && !(message.subtype === "error_max_turns" && hasTools)) throw new Error("errors" in message ? message.errors.join("; ") : message.result);
3527
- log$16.info({
3535
+ log$17.info({
3528
3536
  sessionId: this.deps.sessionId,
3529
3537
  queryUsage: mapUsage(message.usage),
3530
3538
  requestUsage: response.message.usage
@@ -3545,7 +3553,7 @@ var SeatSdkBridge = class {
3545
3553
  }
3546
3554
  } catch (err) {
3547
3555
  const reason = (seatQuery?.controller.signal.aborted || signal.aborted) && !(err instanceof Error && err.name === "TimeoutError") ? "aborted" : "error";
3548
- if (reason === "error") log$16.error({
3556
+ if (reason === "error") log$17.error({
3549
3557
  err,
3550
3558
  sessionId: this.deps.sessionId
3551
3559
  }, "Claude seat SDK response failed");
@@ -3616,7 +3624,7 @@ const HEARTBEAT_THROTTLE_MS = 6e4;
3616
3624
  const TOOL_HEARTBEAT_INTERVAL_MS = 5e3;
3617
3625
  const MAX_TOOL_HEARTBEATS = 1440 * 60 * 1e3 / TOOL_HEARTBEAT_INTERVAL_MS;
3618
3626
  const DAEMON_URL = "http://localhost:38994";
3619
- const log$15 = logger.child({ module: "platform-ext" });
3627
+ const log$16 = logger.child({ module: "platform-ext" });
3620
3628
  function sandboxClient() {
3621
3629
  const apiUrl = apiBaseUrl();
3622
3630
  if (!apiUrl) return null;
@@ -3684,7 +3692,7 @@ async function fetchHarnessFlags() {
3684
3692
  try {
3685
3693
  const res = await client["feature-flags"].$get();
3686
3694
  if (!res.ok) {
3687
- log$15.debug({
3695
+ log$16.debug({
3688
3696
  status: res.status,
3689
3697
  event: "feature_flags_fetch_failed"
3690
3698
  }, "feature-flags fetch failed");
@@ -3696,7 +3704,7 @@ async function fetchHarnessFlags() {
3696
3704
  closingText: body.closingText ?? null
3697
3705
  };
3698
3706
  } catch (err) {
3699
- log$15.debug({
3707
+ log$16.debug({
3700
3708
  err,
3701
3709
  event: "feature_flags_fetch_error"
3702
3710
  }, "feature-flags request errored");
@@ -3707,7 +3715,7 @@ function postHeartbeat({ messageId }) {
3707
3715
  const client = sandboxClient();
3708
3716
  if (!client) return;
3709
3717
  client.heartbeat.$post({ json: { messageId } }).catch((err) => {
3710
- log$15.debug({
3718
+ log$16.debug({
3711
3719
  err,
3712
3720
  event: "heartbeat_failed"
3713
3721
  }, "heartbeat failed");
@@ -3719,7 +3727,7 @@ async function resolveConversationFromApi(messageId) {
3719
3727
  try {
3720
3728
  const res = await client["message-conversation"].$get({ query: { messageId } });
3721
3729
  if (!res.ok) {
3722
- log$15.warn({
3730
+ log$16.warn({
3723
3731
  status: res.status,
3724
3732
  messageId,
3725
3733
  event: "resolve_conversation_failed"
@@ -3728,7 +3736,7 @@ async function resolveConversationFromApi(messageId) {
3728
3736
  }
3729
3737
  return (await res.json()).conversationId ?? null;
3730
3738
  } catch (err) {
3731
- log$15.warn({
3739
+ log$16.warn({
3732
3740
  err,
3733
3741
  messageId,
3734
3742
  event: "resolve_conversation_error"
@@ -3753,13 +3761,13 @@ async function putBackgroundTaskJournalSpec({ messageId, spec }) {
3753
3761
  messageId,
3754
3762
  spec
3755
3763
  } });
3756
- if (!res.ok) log$15.warn({
3764
+ if (!res.ok) log$16.warn({
3757
3765
  status: res.status,
3758
3766
  taskId: spec.id,
3759
3767
  event: "bg_journal_put_failed"
3760
3768
  }, "bg-task journal PUT failed");
3761
3769
  } catch (err) {
3762
- log$15.warn({
3770
+ log$16.warn({
3763
3771
  err,
3764
3772
  taskId: spec.id,
3765
3773
  event: "bg_journal_put_failed"
@@ -3775,7 +3783,7 @@ async function deleteBackgroundTaskJournalSpec({ messageId, taskId }) {
3775
3783
  taskId
3776
3784
  } });
3777
3785
  } catch (err) {
3778
- log$15.debug({
3786
+ log$16.debug({
3779
3787
  err,
3780
3788
  taskId,
3781
3789
  event: "bg_journal_delete_failed"
@@ -3790,7 +3798,7 @@ async function listBackgroundTaskJournalSpecs({ messageId }) {
3790
3798
  if (!res.ok) return [];
3791
3799
  return (await res.json()).specs ?? [];
3792
3800
  } catch (err) {
3793
- log$15.debug({
3801
+ log$16.debug({
3794
3802
  err,
3795
3803
  event: "bg_journal_list_failed"
3796
3804
  }, "bg-task journal GET failed");
@@ -3804,7 +3812,7 @@ function postBackgroundTasksSnapshot({ messageId, tasks }) {
3804
3812
  messageId,
3805
3813
  tasks
3806
3814
  } }).catch((err) => {
3807
- log$15.debug({
3815
+ log$16.debug({
3808
3816
  err,
3809
3817
  event: "bg_tasks_snapshot_failed"
3810
3818
  }, "bg-tasks snapshot publish failed");
@@ -3902,7 +3910,7 @@ function createToolHeartbeat({ messageId }) {
3902
3910
  }
3903
3911
  heartbeatCount++;
3904
3912
  if (heartbeatCount > MAX_TOOL_HEARTBEATS) {
3905
- log$15.warn({
3913
+ log$16.warn({
3906
3914
  heartbeatCount,
3907
3915
  activeToolCalls: [...activeToolCalls]
3908
3916
  }, "tool heartbeat max reached, stopping");
@@ -3933,7 +3941,7 @@ function postToDaemon(path, body) {
3933
3941
  headers: { "content-type": "application/json" },
3934
3942
  body: JSON.stringify(body)
3935
3943
  }).catch((err) => {
3936
- log$15.debug({
3944
+ log$16.debug({
3937
3945
  err,
3938
3946
  path,
3939
3947
  event: "daemon_post_failed"
@@ -3942,7 +3950,7 @@ function postToDaemon(path, body) {
3942
3950
  }
3943
3951
  function createPlatformExtensions({ sessionId, channelContext }) {
3944
3952
  return (pi) => {
3945
- log$15.info({
3953
+ log$16.info({
3946
3954
  sessionId,
3947
3955
  hasChannelContext: Boolean(channelContext)
3948
3956
  }, "platform extension initialized");
@@ -3996,7 +4004,7 @@ function createPlatformExtensions({ sessionId, channelContext }) {
3996
4004
  });
3997
4005
  });
3998
4006
  pi.on("agent_end", () => {
3999
- log$15.info({ sessionId }, "session ending");
4007
+ log$16.info({ sessionId }, "session ending");
4000
4008
  postToDaemon("/session/end", { sessionId });
4001
4009
  });
4002
4010
  };
@@ -4140,7 +4148,7 @@ function createOomNeutralBashOperations({ shellPath }) {
4140
4148
  * semantics; once promoted, the command inherits background-task lifecycle
4141
4149
  * (its own controller) and the foreground kill timeout no longer applies.
4142
4150
  */
4143
- const log$14 = logger.child({ module: "background-tasks-ext" });
4151
+ const log$15 = logger.child({ module: "background-tasks-ext" });
4144
4152
  const ops = createOomNeutralBashOperations({ shellPath: void 0 });
4145
4153
  const STEER_BACKGROUND_DEFAULT_SECONDS = 60;
4146
4154
  const STEER_BACKGROUND_ENV_KEYS = ["BASH_STEER_BACKGROUND_SECONDS", "SKYDIVE_BASH_STEER_BACKGROUND_SECONDS"];
@@ -4155,7 +4163,7 @@ function steerBackgroundThresholdMs() {
4155
4163
  if (raw === void 0 || raw.trim() === "") continue;
4156
4164
  const parsed = Number(raw);
4157
4165
  if (!Number.isFinite(parsed) || parsed < 0) {
4158
- log$14.warn({
4166
+ log$15.warn({
4159
4167
  envKey: key,
4160
4168
  raw
4161
4169
  }, "invalid BASH_STEER_BACKGROUND_SECONDS, using default");
@@ -4184,7 +4192,7 @@ async function notifyBashSteerArrival(args) {
4184
4192
  try {
4185
4193
  await listener();
4186
4194
  } catch (err) {
4187
- log$14.error({
4195
+ log$15.error({
4188
4196
  err,
4189
4197
  sessionId: args.sessionId
4190
4198
  }, "bash steer promotion failed");
@@ -4279,14 +4287,14 @@ function watchdogTick(now) {
4279
4287
  const overSize = meta.logBytes > MAX_LOG_BYTES;
4280
4288
  if (!overRuntime && !overSize) continue;
4281
4289
  const reason = overSize ? `output exceeded ${MAX_LOG_BYTES / (1024 * 1024)}MiB` : `exceeded ${KEEPALIVE_MAX_MS / 6e4}m max runtime`;
4282
- log$14.warn({
4290
+ log$15.warn({
4283
4291
  taskId: meta.id,
4284
4292
  reason
4285
4293
  }, "watchdog killing bg task");
4286
4294
  try {
4287
4295
  killTask(meta, reason);
4288
4296
  } catch (err) {
4289
- log$14.warn({
4297
+ log$15.warn({
4290
4298
  err,
4291
4299
  taskId: meta.id
4292
4300
  }, "watchdog kill failed");
@@ -4345,7 +4353,7 @@ function createBackgroundTasksExtension({ channelContext, sessionId }) {
4345
4353
  const now = Date.now();
4346
4354
  const promotable = [...foregroundBash.values()].filter((call) => now - call.startedAt >= thresholdMs);
4347
4355
  if (promotable.length === 0) return;
4348
- log$14.info({
4356
+ log$15.info({
4349
4357
  event: "bash_steer_promotion",
4350
4358
  count: promotable.length,
4351
4359
  thresholdSeconds: Math.round(thresholdMs / 1e3),
@@ -4370,7 +4378,7 @@ function createBackgroundTasksExtension({ channelContext, sessionId }) {
4370
4378
  try {
4371
4379
  await mkdir(tasksDir(), { recursive: true });
4372
4380
  } catch (err) {
4373
- log$14.error({ err }, "bg task adopt: mkdir failed");
4381
+ log$15.error({ err }, "bg task adopt: mkdir failed");
4374
4382
  }
4375
4383
  const logStream = createWriteStream(logPath(id), { flags: "a" });
4376
4384
  logStream.on("error", () => {});
@@ -4397,7 +4405,7 @@ function createBackgroundTasksExtension({ channelContext, sessionId }) {
4397
4405
  tasks.set(id, meta);
4398
4406
  ensureWatchdog();
4399
4407
  schedulePublishSnapshot();
4400
- log$14.info({
4408
+ log$15.info({
4401
4409
  taskId: id,
4402
4410
  conversationId,
4403
4411
  startedAt: args.startedAt
@@ -4550,7 +4558,7 @@ function createBackgroundTasksExtension({ channelContext, sessionId }) {
4550
4558
  try {
4551
4559
  shellPath = SettingsManager.create(ctx.cwd, getAgentDir()).getShellPath();
4552
4560
  } catch (err) {
4553
- log$14.warn({
4561
+ log$15.warn({
4554
4562
  err,
4555
4563
  cwd: ctx.cwd
4556
4564
  }, "bash steer promotion: shell settings unavailable, using default shell");
@@ -4565,7 +4573,7 @@ function createBackgroundTasksExtension({ channelContext, sessionId }) {
4565
4573
  ...definition,
4566
4574
  description: `${definition.description}\n\nLong-running bash commands are automatically moved to a background task when a new message arrives while the command has already been running for at least a minute: you get the task id immediately, are woken on completion, and must not depend on the command's output until that wake arrives. Shorter commands finish in the foreground like they always have.`
4567
4575
  });
4568
- log$14.info({
4576
+ log$15.info({
4569
4577
  event: "bash_steer_promotion_enabled",
4570
4578
  thresholdSeconds: Math.round(thresholdMs / 1e3)
4571
4579
  }, "supervised bash tool registered (steer-triggered backgrounding)");
@@ -4608,7 +4616,7 @@ or if you were explicitly waiting to report it.`,
4608
4616
  triggerTurn: true,
4609
4617
  deliverAs: "followUp"
4610
4618
  });
4611
- log$14.info({
4619
+ log$15.info({
4612
4620
  taskId: meta.id,
4613
4621
  conversationId
4614
4622
  }, "bg task completion delivered live (followUp)");
@@ -4616,7 +4624,7 @@ or if you were explicitly waiting to report it.`,
4616
4624
  }
4617
4625
  if (meta.messageId) {
4618
4626
  meta.notified = true;
4619
- log$14.info({
4627
+ log$15.info({
4620
4628
  taskId: meta.id,
4621
4629
  messageId: meta.messageId
4622
4630
  }, "posting idle bg-task-done wake");
@@ -4626,12 +4634,12 @@ or if you were explicitly waiting to report it.`,
4626
4634
  content: message.content
4627
4635
  }).catch((err) => {
4628
4636
  meta.notified = false;
4629
- log$14.warn({
4637
+ log$15.warn({
4630
4638
  err,
4631
4639
  taskId: meta.id
4632
4640
  }, "bg-task-done wake failed; will retry at next session_start");
4633
4641
  });
4634
- } else log$14.info({ taskId: meta.id }, "bg task completed idle with no origin message; deferring to next session_start");
4642
+ } else log$15.info({ taskId: meta.id }, "bg task completed idle with no origin message; deferring to next session_start");
4635
4643
  }
4636
4644
  const SNAPSHOT_TAIL_LINES = 40;
4637
4645
  let lastPublishedSignature = null;
@@ -4668,7 +4676,7 @@ or if you were explicitly waiting to report it.`,
4668
4676
  tasks: snapshot
4669
4677
  });
4670
4678
  } catch (err) {
4671
- log$14.debug({
4679
+ log$15.debug({
4672
4680
  err,
4673
4681
  event: "bg_tasks_snapshot_build_failed"
4674
4682
  }, "building bg-tasks snapshot failed");
@@ -4711,7 +4719,7 @@ or if you were explicitly waiting to report it.`,
4711
4719
  logStream.end();
4712
4720
  await finished(logStream).catch(() => {});
4713
4721
  meta.running = false;
4714
- log$14.info({
4722
+ log$15.info({
4715
4723
  taskId: meta.id,
4716
4724
  exitCode: meta.exitCode
4717
4725
  }, "bg task finished");
@@ -4728,14 +4736,14 @@ or if you were explicitly waiting to report it.`,
4728
4736
  try {
4729
4737
  await mkdir(tasksDir(), { recursive: true });
4730
4738
  } catch (err) {
4731
- log$14.error({
4739
+ log$15.error({
4732
4740
  err,
4733
4741
  taskId: id
4734
4742
  }, "background task dir unavailable");
4735
4743
  }
4736
4744
  const logStream = createWriteStream(logPath(id), { flags: "a" });
4737
4745
  logStream.on("error", (err) => {
4738
- log$14.warn({
4746
+ log$15.warn({
4739
4747
  err,
4740
4748
  taskId: id
4741
4749
  }, "bg task log write failed");
@@ -4785,7 +4793,7 @@ or if you were explicitly waiting to report it.`,
4785
4793
  }).catch((err) => {
4786
4794
  if (!meta.controller.signal.aborted) {
4787
4795
  meta.error = err instanceof Error ? err.message : String(err);
4788
- log$14.warn({
4796
+ log$15.warn({
4789
4797
  err,
4790
4798
  taskId: id
4791
4799
  }, "bg task exec error");
@@ -4794,7 +4802,7 @@ or if you were explicitly waiting to report it.`,
4794
4802
  await finishTask(meta, logStream);
4795
4803
  });
4796
4804
  ensureWatchdog();
4797
- log$14.info({
4805
+ log$15.info({
4798
4806
  taskId: id,
4799
4807
  conversationId
4800
4808
  }, "bg task started");
@@ -4813,7 +4821,7 @@ or if you were explicitly waiting to report it.`,
4813
4821
  for (const spec of specs) {
4814
4822
  const live = tasks.get(spec.id);
4815
4823
  if (live && sameScope(live, scopeKey())) continue;
4816
- log$14.info({
4824
+ log$15.info({
4817
4825
  taskId: spec.id,
4818
4826
  conversationId
4819
4827
  }, "relaunching journaled resumable bg task after restart");
@@ -4831,7 +4839,7 @@ or if you were explicitly waiting to report it.`,
4831
4839
  stream.write(`<resumed-after-restart>requeued and relaunched on a new sandbox after the previous one was drained; this is a fresh execution of the command from the start, not a continuation</resumed-after-restart>\n`);
4832
4840
  stream.end();
4833
4841
  } catch (err) {
4834
- log$14.debug({
4842
+ log$15.debug({
4835
4843
  err,
4836
4844
  taskId: meta.id
4837
4845
  }, "resume banner write failed");
@@ -4851,7 +4859,7 @@ or if you were explicitly waiting to report it.`,
4851
4859
  meta.notified = true;
4852
4860
  pi.sendMessage(await taskDoneMessage(meta));
4853
4861
  }
4854
- if (unnotified.length > 0) log$14.info({
4862
+ if (unnotified.length > 0) log$15.info({
4855
4863
  conversationId,
4856
4864
  count: unnotified.length
4857
4865
  }, "injected completed bg tasks at session_start");
@@ -5046,7 +5054,7 @@ or if you were explicitly waiting to report it.`,
5046
5054
  * read on the hot path before every LLM call), it falls back to the default
5047
5055
  * for that knob and logs once.
5048
5056
  */
5049
- const log$13 = logger.child({ module: "context-management-config" });
5057
+ const log$14 = logger.child({ module: "context-management-config" });
5050
5058
  const DEFAULT_CONTEXT_MANAGEMENT_CONFIG = {
5051
5059
  enabled: false,
5052
5060
  perResultMaxBytes: 16 * 1024,
@@ -5091,7 +5099,7 @@ function resolveContextManagementConfig(env = process.env) {
5091
5099
  clearAtLeastTokens: env.SKYDIVE_CTX_CLEAR_AT_LEAST_TOKENS
5092
5100
  });
5093
5101
  if (!parsed.success) {
5094
- log$13.warn({
5102
+ log$14.warn({
5095
5103
  event: "context_management_config_invalid",
5096
5104
  err: parsed.error
5097
5105
  }, "falling back to default context-management config");
@@ -5175,7 +5183,7 @@ function hasFlagSource(env = process.env) {
5175
5183
  * alive and an indeterminate result (no api url / transient failure) leaves the
5176
5184
  * last-known values untouched so a blip can't silently flip behavior.
5177
5185
  */
5178
- const log$12 = logger.child({ module: "feature-flags-poll" });
5186
+ const log$13 = logger.child({ module: "feature-flags-poll" });
5179
5187
  const FLAG_POLL_INTERVAL_MS = 6e4;
5180
5188
  let contextManagement = null;
5181
5189
  let closingText = null;
@@ -5215,7 +5223,7 @@ function apply(name, next) {
5215
5223
  if (next !== prev) for (const cb of subscribers[name]) try {
5216
5224
  cb(next);
5217
5225
  } catch (err) {
5218
- log$12.warn({
5226
+ log$13.warn({
5219
5227
  err,
5220
5228
  flag: name
5221
5229
  }, "flag subscriber threw");
@@ -5228,7 +5236,7 @@ async function pollOnce() {
5228
5236
  apply("contextManagement", flags.contextManagement ?? null);
5229
5237
  apply("closingText", flags.closingText ?? null);
5230
5238
  } catch (err) {
5231
- log$12.debug({ err }, "feature-flag poll threw");
5239
+ log$13.debug({ err }, "feature-flag poll threw");
5232
5240
  }
5233
5241
  }
5234
5242
  /**
@@ -5429,8 +5437,8 @@ const bashDefaultTimeoutExtension = (pi) => {
5429
5437
  * stat and the extension warns on what it can see — it must never break a
5430
5438
  * turn over an observability feature.
5431
5439
  */
5432
- const execFileAsync = promisify(execFile);
5433
- const log$11 = logger.child({ module: "resource-pressure-warning" });
5440
+ const execFileAsync$1 = promisify(execFile);
5441
+ const log$12 = logger.child({ module: "resource-pressure-warning" });
5434
5442
  const POLL_INTERVAL_MS = 1e4;
5435
5443
  function envOverride(name) {
5436
5444
  for (const prefix of ["SKYDIVE_", "ANYONE_"]) {
@@ -5498,7 +5506,7 @@ async function readMemUsePct() {
5498
5506
  */
5499
5507
  async function readDiskUsePct() {
5500
5508
  try {
5501
- const { stdout } = await execFileAsync("df", ["-P", diskRoot()]);
5509
+ const { stdout } = await execFileAsync$1("df", ["-P", diskRoot()]);
5502
5510
  const dataRow = stdout.trim().split("\n")[1];
5503
5511
  if (dataRow == null) return null;
5504
5512
  const capacity = dataRow.trim().split(/\s+/)[4];
@@ -5627,7 +5635,7 @@ const resourcePressureWarningExtension = (pi) => {
5627
5635
  warnedDiskThisTurn = true;
5628
5636
  }
5629
5637
  if (trigger === null) return;
5630
- log$11.warn({
5638
+ log$12.warn({
5631
5639
  trigger,
5632
5640
  mem,
5633
5641
  cpuPct,
@@ -5665,7 +5673,7 @@ const resourcePressureWarningExtension = (pi) => {
5665
5673
  if (!timer) {
5666
5674
  timer = setInterval(() => {
5667
5675
  checkOnce().catch((err) => {
5668
- log$11.error({ err }, "resource pressure check failed");
5676
+ log$12.error({ err }, "resource pressure check failed");
5669
5677
  });
5670
5678
  }, POLL_INTERVAL_MS);
5671
5679
  timer.unref?.();
@@ -5681,7 +5689,7 @@ const resourcePressureWarningExtension = (pi) => {
5681
5689
  };
5682
5690
  //#endregion
5683
5691
  //#region src/extensions/disk-guard.ts
5684
- const log$10 = logger.child({ module: "disk-guard" });
5692
+ const log$11 = logger.child({ module: "disk-guard" });
5685
5693
  /**
5686
5694
  * In-band bypass. The guard is a safety net, not a jail: when the agent knows
5687
5695
  * a flagged command is genuinely safe (writing to a different mount, a tiny
@@ -5821,7 +5829,7 @@ const diskGuardExtension = (pi) => {
5821
5829
  if (!isSpaceHungryCommand(command)) return;
5822
5830
  const diskPct = await readDiskUsePct();
5823
5831
  if (!shouldBlockForDisk(command, diskPct)) return;
5824
- log$10.warn({
5832
+ log$11.warn({
5825
5833
  diskPct,
5826
5834
  command: command.slice(0, 200)
5827
5835
  }, "blocked space-hungry bash command on near-full disk");
@@ -5833,7 +5841,7 @@ const diskGuardExtension = (pi) => {
5833
5841
  };
5834
5842
  //#endregion
5835
5843
  //#region src/extensions/noop-loop-guard.ts
5836
- const log$9 = logger.child({ module: "noop-loop-guard" });
5844
+ const log$10 = logger.child({ module: "noop-loop-guard" });
5837
5845
  /** Length of the rolling window that counts silence commands across streak resets. */
5838
5846
  const SILENCE_WINDOW_MS = 300 * 1e3;
5839
5847
  /** Bare shell no-op: `true` or `:` (case-insensitive). */
@@ -5988,7 +5996,7 @@ const noopLoopGuardExtension = (pi) => {
5988
5996
  if (bypassed) return;
5989
5997
  if (streak < 3 && windowCount < 8) return;
5990
5998
  const aborted = streak >= 25 || windowCount >= 40;
5991
- log$9.warn({
5999
+ log$10.warn({
5992
6000
  streak,
5993
6001
  windowCount,
5994
6002
  aborted,
@@ -6007,7 +6015,7 @@ const noopLoopGuardExtension = (pi) => {
6007
6015
  };
6008
6016
  //#endregion
6009
6017
  //#region src/extensions/repeat-call-guard.ts
6010
- const log$8 = logger.child({ module: "repeat-call-guard" });
6018
+ const log$9 = logger.child({ module: "repeat-call-guard" });
6011
6019
  const KILL_SWITCH_KEYS = ["REPEAT_CALL_GUARD_DISABLE", "SKYDIVE_REPEAT_CALL_GUARD_DISABLE"];
6012
6020
  function guardDisabledByEnv$1() {
6013
6021
  return KILL_SWITCH_KEYS.some((key) => {
@@ -6052,7 +6060,7 @@ const repeatCallGuardExtension = (pi) => {
6052
6060
  }));
6053
6061
  if (streak < 20) return;
6054
6062
  const aborted = streak >= 40;
6055
- log$8.warn({
6063
+ log$9.warn({
6056
6064
  toolName: event.toolName,
6057
6065
  streak,
6058
6066
  aborted,
@@ -6119,7 +6127,7 @@ const repeatCallGuardExtension = (pi) => {
6119
6127
  * embedding a script).
6120
6128
  */
6121
6129
  const execFileP = promisify(execFile);
6122
- const log$7 = logger.child({ module: "sleep-guard" });
6130
+ const log$8 = logger.child({ module: "sleep-guard" });
6123
6131
  /** How long the `platform automation create` call may take before we fall back to guidance. */
6124
6132
  const SCHEDULE_TIMEOUT_MS = 15e3;
6125
6133
  /** Title for the one-shot wakes this guard schedules. Visible in the Routines UI. */
@@ -6363,7 +6371,7 @@ async function scheduleSleepWake(seconds, ledger) {
6363
6371
  ], { timeout: SCHEDULE_TIMEOUT_MS });
6364
6372
  return at;
6365
6373
  } catch (err) {
6366
- log$7.warn({ err }, "failed to auto-schedule sleep wake; falling back to guidance");
6374
+ log$8.warn({ err }, "failed to auto-schedule sleep wake; falling back to guidance");
6367
6375
  return null;
6368
6376
  }
6369
6377
  }
@@ -6384,7 +6392,7 @@ const sleepGuardExtension = (pi) => {
6384
6392
  if (typeof command !== "string" || command.length === 0) return;
6385
6393
  const violation = shouldBlockForSleep(command);
6386
6394
  if (!violation) return;
6387
- log$7.warn({
6395
+ log$8.warn({
6388
6396
  seconds: violation.seconds,
6389
6397
  leading: violation.leading,
6390
6398
  unboundedLoop: violation.unboundedLoop,
@@ -6393,7 +6401,7 @@ const sleepGuardExtension = (pi) => {
6393
6401
  if (!violation.unboundedLoop && violation.seconds <= 86400 && isPureSleepCommand(blankQuotedRegions(command))) {
6394
6402
  const at = await scheduleSleepWake(violation.seconds, wakeLedger);
6395
6403
  if (at) {
6396
- log$7.info({
6404
+ log$8.info({
6397
6405
  at,
6398
6406
  seconds: violation.seconds
6399
6407
  }, "auto-scheduled sleep wake");
@@ -6501,7 +6509,7 @@ function transformContextMessages(messages, config, now) {
6501
6509
  }
6502
6510
  //#endregion
6503
6511
  //#region src/extensions/context-management.ts
6504
- const log$6 = logger.child({ module: "context-management-extension" });
6512
+ const log$7 = logger.child({ module: "context-management-extension" });
6505
6513
  function isAnthropicMessagesPayload(payload) {
6506
6514
  if (typeof payload !== "object" || payload === null) return false;
6507
6515
  const candidate = payload;
@@ -6566,13 +6574,13 @@ function createContextManagementExtension() {
6566
6574
  setContextManagementFlagOverride(getPolledFlag("contextManagement"));
6567
6575
  onFlagChange("contextManagement", (enabled) => {
6568
6576
  setContextManagementFlagOverride(enabled);
6569
- log$6.info({
6577
+ log$7.info({
6570
6578
  event: "context_management_flag_update",
6571
6579
  enabled
6572
6580
  }, "context-management flag updated from platform");
6573
6581
  });
6574
6582
  startFeatureFlagPoller();
6575
- log$6.info({
6583
+ log$7.info({
6576
6584
  event: "context_management_registered",
6577
6585
  enabled: initial.enabled,
6578
6586
  flagSource: hasFlagSource(),
@@ -6584,13 +6592,13 @@ function createContextManagementExtension() {
6584
6592
  const { messages } = event;
6585
6593
  try {
6586
6594
  const result = transformContextIfEnabled(messages, getContextManagementConfig(), Date.now());
6587
- if (result.stats && (result.stats.clearedResults > 0 || result.stats.trimmedResults > 0)) log$6.info({
6595
+ if (result.stats && (result.stats.clearedResults > 0 || result.stats.trimmedResults > 0)) log$7.info({
6588
6596
  event: "context_management_applied",
6589
6597
  ...result.stats
6590
6598
  }, "trimmed/cleared tool output before LLM call");
6591
6599
  return { messages: result.messages };
6592
6600
  } catch (err) {
6593
- log$6.error({
6601
+ log$7.error({
6594
6602
  err,
6595
6603
  event: "context_management_transform_failed"
6596
6604
  }, "context transform failed; passing messages through unchanged");
@@ -6602,7 +6610,7 @@ function createContextManagementExtension() {
6602
6610
  }
6603
6611
  //#endregion
6604
6612
  //#region src/extensions/current-time.ts
6605
- const log$5 = logger.child({ module: "current-time-extension" });
6613
+ const log$6 = logger.child({ module: "current-time-extension" });
6606
6614
  const PI_DATE_LINE = /^Current date:.*$/m;
6607
6615
  function formatCurrentTimeLine(now) {
6608
6616
  return `Current date: ${now.getUTCFullYear()}-${String(now.getUTCMonth() + 1).padStart(2, "0")}-${String(now.getUTCDate()).padStart(2, "0")} (${new Intl.DateTimeFormat("en-US", {
@@ -6615,7 +6623,7 @@ const currentTimeExtension = (pi) => {
6615
6623
  const line = formatCurrentTimeLine(/* @__PURE__ */ new Date());
6616
6624
  const base = event.systemPrompt;
6617
6625
  if (PI_DATE_LINE.test(base)) {
6618
- log$5.info({ event: "pi_date_line_present" }, "pi base prompt carries its own 'Current date:' line again; replacing it in place (pi prompt format may have changed)");
6626
+ log$6.info({ event: "pi_date_line_present" }, "pi base prompt carries its own 'Current date:' line again; replacing it in place (pi prompt format may have changed)");
6619
6627
  return { systemPrompt: base.replace(PI_DATE_LINE, line) };
6620
6628
  }
6621
6629
  return { systemPrompt: `${base}\n${line}` };
@@ -7003,7 +7011,7 @@ async function migrateMemory({ cwd }) {
7003
7011
  }
7004
7012
  //#endregion
7005
7013
  //#region src/extensions/memory.ts
7006
- const log$4 = logger.child({ module: "memory-extension" });
7014
+ const log$5 = logger.child({ module: "memory-extension" });
7007
7015
  /**
7008
7016
  * The standing instructions for the memory system. Always injected (even with
7009
7017
  * no `MEMORY.md`) so the agent knows it can persist notes and how. `users/` is
@@ -7040,13 +7048,13 @@ const memoryExtension = (pi) => {
7040
7048
  pi.on("session_start", async (_event, ctx) => {
7041
7049
  try {
7042
7050
  const migrated = await migrateMemory({ cwd: ctx.cwd });
7043
- if (migrated !== null) log$4.info({
7051
+ if (migrated !== null) log$5.info({
7044
7052
  event: "memory_migrated",
7045
7053
  from: migrated.from,
7046
7054
  to: migrated.to
7047
7055
  }, "migrated memory layout to current version");
7048
7056
  } catch (err) {
7049
- log$4.warn({
7057
+ log$5.warn({
7050
7058
  err,
7051
7059
  event: "memory_migration_failed"
7052
7060
  }, "memory migration failed; continuing with existing index");
@@ -7058,7 +7066,7 @@ const memoryExtension = (pi) => {
7058
7066
  index
7059
7067
  });
7060
7068
  } catch (err) {
7061
- log$4.warn({
7069
+ log$5.warn({
7062
7070
  err,
7063
7071
  event: "memory_index_failed"
7064
7072
  }, "memory index read failed; injecting instructions only");
@@ -7072,7 +7080,7 @@ const memoryExtension = (pi) => {
7072
7080
  };
7073
7081
  //#endregion
7074
7082
  //#region src/extensions/platform-memory.ts
7075
- const log$3 = logger.child({ module: "platform-memory-extension" });
7083
+ const log$4 = logger.child({ module: "platform-memory-extension" });
7076
7084
  /**
7077
7085
  * Resolve the human on this turn via the API, keyed by the message id.
7078
7086
  * `/sandbox/channel-context` only returns a sender for a platform-known
@@ -7085,13 +7093,13 @@ const log$3 = logger.child({ module: "platform-memory-extension" });
7085
7093
  async function resolveTurnUser(messageId) {
7086
7094
  const client = sandboxClient();
7087
7095
  if (!client) {
7088
- log$3.debug({ event: "resolve_turn_user_no_api_url" }, "no API url in env; withholding user memory");
7096
+ log$4.debug({ event: "resolve_turn_user_no_api_url" }, "no API url in env; withholding user memory");
7089
7097
  return null;
7090
7098
  }
7091
7099
  try {
7092
7100
  const res = await client["channel-context"].$get({ query: { messageId } });
7093
7101
  if (!res.ok) {
7094
- log$3.warn({
7102
+ log$4.warn({
7095
7103
  event: "resolve_turn_user_failed",
7096
7104
  status: res.status
7097
7105
  }, "channel-context returned non-ok; withholding user memory");
@@ -7104,7 +7112,7 @@ async function resolveTurnUser(messageId) {
7104
7112
  displayName: sender.displayName
7105
7113
  };
7106
7114
  } catch (err) {
7107
- log$3.warn({
7115
+ log$4.warn({
7108
7116
  err,
7109
7117
  event: "resolve_turn_user_failed"
7110
7118
  }, "failed to resolve current user; withholding user memory");
@@ -7151,7 +7159,7 @@ function createPlatformMemoryExtension({ channelContext }) {
7151
7159
  user
7152
7160
  });
7153
7161
  } catch (err) {
7154
- log$3.warn({
7162
+ log$4.warn({
7155
7163
  err,
7156
7164
  event: "user_memory_index_failed"
7157
7165
  }, "user memory index build failed; skipping injection");
@@ -7183,7 +7191,7 @@ const providerApiCompatExtension = (pi) => {
7183
7191
  };
7184
7192
  //#endregion
7185
7193
  //#region src/extensions/self-trace.ts
7186
- const log$2 = logger.child({ module: "self-trace-extension" });
7194
+ const log$3 = logger.child({ module: "self-trace-extension" });
7187
7195
  /**
7188
7196
  * Reports the agent's own execution as OpenTelemetry spans:
7189
7197
  * agent.session → agent.run → agent.turn.N → tool.NAME, with token/cost
@@ -7208,7 +7216,7 @@ const selfTraceExtension = (pi) => {
7208
7216
  sessionSpan = tracer.startSpan("agent.session", { attributes: { "agent.model": modelId } }, remoteCtx);
7209
7217
  sessionCtx = trace.setSpan(remoteCtx, sessionSpan);
7210
7218
  const sc = sessionSpan.spanContext();
7211
- log$2.info({
7219
+ log$3.info({
7212
7220
  event: "self_trace_session_start",
7213
7221
  trace_id: sc.traceId,
7214
7222
  span_id: sc.spanId,
@@ -7320,13 +7328,13 @@ const selfTraceExtension = (pi) => {
7320
7328
  * Lives in the harness package — soul.md is content from the agent's
7321
7329
  * own git repo, not from the platform — so its handling stays here.
7322
7330
  */
7323
- const log$1 = logger.child({ module: "soul-extension" });
7331
+ const log$2 = logger.child({ module: "soul-extension" });
7324
7332
  async function readSoul(cwd) {
7325
7333
  try {
7326
7334
  return (await readFile(join(cwd, "soul.md"), "utf8")).trim() || null;
7327
7335
  } catch (err) {
7328
7336
  if (err?.code === "ENOENT") return null;
7329
- log$1.warn({
7337
+ log$2.warn({
7330
7338
  err,
7331
7339
  event: "soul_read_failed"
7332
7340
  }, "soul.md read failed");
@@ -7358,7 +7366,7 @@ const soulExtension = (pi) => {
7358
7366
  };
7359
7367
  //#endregion
7360
7368
  //#region src/extensions/subagent/index.ts
7361
- const log = logger.child({ module: "subagent-ext" });
7369
+ const log$1 = logger.child({ module: "subagent-ext" });
7362
7370
  const MAX_TASKS = 8;
7363
7371
  const SpawnTaskItem = Type.Object({
7364
7372
  task: Type.String({ description: "The task to delegate to a subagent run." }),
@@ -7458,7 +7466,7 @@ function buildTool(messageId) {
7458
7466
  };
7459
7467
  } catch (err) {
7460
7468
  const message = err instanceof Error ? err.message : String(err);
7461
- log.warn({
7469
+ log$1.warn({
7462
7470
  err,
7463
7471
  event: "subagent_rearm_failed",
7464
7472
  taskId: task.taskId
@@ -7471,7 +7479,7 @@ function buildTool(messageId) {
7471
7479
  }
7472
7480
  }));
7473
7481
  const { taskIds } = spawned;
7474
- log.info({
7482
+ log$1.info({
7475
7483
  event: "subagent_spawned",
7476
7484
  count: taskIds.length
7477
7485
  }, "subagent tasks queued");
@@ -7502,7 +7510,7 @@ function buildTool(messageId) {
7502
7510
  };
7503
7511
  } catch (err) {
7504
7512
  const message = err instanceof Error ? err.message : String(err);
7505
- log.warn({
7513
+ log$1.warn({
7506
7514
  err,
7507
7515
  event: "subagent_spawn_failed"
7508
7516
  }, "subagent request failed");
@@ -7533,7 +7541,7 @@ function createSubagentExtension({ channelContext }) {
7533
7541
  if (registered) return;
7534
7542
  registered = true;
7535
7543
  pi.registerTool(buildTool(messageId));
7536
- log.info({ event: "subagent_enabled" }, "subagent tool registered");
7544
+ log$1.info({ event: "subagent_enabled" }, "subagent tool registered");
7537
7545
  };
7538
7546
  pi.on("session_start", () => {
7539
7547
  registerOnce();
@@ -7541,6 +7549,125 @@ function createSubagentExtension({ channelContext }) {
7541
7549
  };
7542
7550
  }
7543
7551
  //#endregion
7552
+ //#region src/extensions/template-build-push.ts
7553
+ /**
7554
+ * Same-turn notice that a push started a template build.
7555
+ *
7556
+ * An agent's `Dockerfile` / `install.sh` / lockfiles are BAKED: changing one
7557
+ * does not take effect when the file is written, nor when it is pushed, but
7558
+ * when a template build of that commit succeeds — minutes later, out of band,
7559
+ * with no result delivered anywhere the agent looks. So an agent edits its
7560
+ * Dockerfile, pushes, sees a clean `git push`, and reasonably concludes it is
7561
+ * done. If that build fails, it will go on answering from the last image that
7562
+ * built, and every later commit fails the same way.
7563
+ *
7564
+ * This closes the gap at the only moment the agent still has full context for
7565
+ * why it touched those files: the push itself. The notice appends one line to
7566
+ * the push's own tool result pointing at `platform builds wait`. It does not
7567
+ * block, does not wait for the build, and adds no request — it is a string
7568
+ * append onto a result that has already returned.
7569
+ *
7570
+ * Deliberately narrow: only a push whose diff touches a baked path says
7571
+ * anything. A push of ordinary code is not waiting on a build and must stay
7572
+ * silent, or the line becomes background noise that gets skimmed past.
7573
+ *
7574
+ * Best-effort throughout. Any failure to read the range or the diff leaves
7575
+ * the tool result exactly as it was — this is a hint, and a hint must never
7576
+ * be able to break a push.
7577
+ */
7578
+ const execFileAsync = promisify(execFile);
7579
+ const log = logger.child({ module: "template-build-push" });
7580
+ /**
7581
+ * Repo paths whose contents are baked into the template image.
7582
+ *
7583
+ * MUST stay identical to `BAKED_BUILD_PATHS` in
7584
+ * `apps/anyone/agent-lifecycle/src/agentPush.ts`, which is what the server
7585
+ * actually classifies pushes with. It is duplicated rather than imported
7586
+ * because the harness carries zero `@createinc/*` dependencies; the pair is
7587
+ * pinned by `template-build-push.contract.test.ts`, the same arrangement the
7588
+ * untrusted fence uses.
7589
+ */
7590
+ const BAKED_BUILD_PATHS = new Set([
7591
+ "Dockerfile",
7592
+ "install.sh",
7593
+ "package.json",
7594
+ "package-lock.json",
7595
+ ".npmrc",
7596
+ "yarn.lock",
7597
+ ".yarnrc.yml",
7598
+ ".yarnrc",
7599
+ "bun.lock",
7600
+ "bun.lockb",
7601
+ ".bunfig.toml",
7602
+ "pnpm-lock.yaml"
7603
+ ]);
7604
+ const BUILD_STARTED_NOTICE = "Note: this push changed a file that is baked into your computer image (Dockerfile / install.sh / a lockfile), so it started a template build. The change is NOT live here until that build succeeds — a failed build leaves you running the previous image, silently. Run `platform builds wait` to confirm it built before you rely on anything the change added, or treat it as unfinished work and check back with `platform builds show`.";
7605
+ /** True for a bash command that is (or contains) a `git push`. */
7606
+ function isGitPush(command) {
7607
+ return /(^|[\s;&|(])git\s+(?:\S+\s+)*?push(\s|$)/.test(command);
7608
+ }
7609
+ /**
7610
+ * The commit range a push reported, parsed from git's own output.
7611
+ *
7612
+ * git writes the range on the ref line of a successful push
7613
+ * (` abc1234..def5678 main -> main`). Reading it back is what lets the
7614
+ * diff be scoped to exactly what was pushed, with no guessing about upstream
7615
+ * tracking state. A new branch (`* [new branch]`) reports no range, which is
7616
+ * why {@link parsePushedRange} returns null there and the caller falls back
7617
+ * to notifying — a first push of a repo is overwhelmingly one that carries a
7618
+ * Dockerfile.
7619
+ */
7620
+ function parsePushedRange(output) {
7621
+ const match = output.match(/\b([0-9a-f]{7,40})\.\.([0-9a-f]{7,40})\b/);
7622
+ if (!match) return null;
7623
+ return `${match[1]}..${match[2]}`;
7624
+ }
7625
+ /** True when a forced update (`+ abc..def (forced update)`) or a new ref. */
7626
+ function isNewRef(output) {
7627
+ return /\[new (?:branch|tag)\]/.test(output);
7628
+ }
7629
+ async function touchedBakedPath({ cwd, range }) {
7630
+ const { stdout } = await execFileAsync("git", [
7631
+ "diff",
7632
+ "--name-only",
7633
+ range
7634
+ ], {
7635
+ cwd,
7636
+ timeout: 5e3,
7637
+ maxBuffer: 4 * 1024 * 1024
7638
+ });
7639
+ return stdout.split("\n").map((line) => line.trim()).some((path) => path.length > 0 && BAKED_BUILD_PATHS.has(path));
7640
+ }
7641
+ const templateBuildPushExtension = (pi) => {
7642
+ pi.on("tool_result", async (event, ctx) => {
7643
+ if (event.toolName !== "bash") return;
7644
+ if (event.isError) return;
7645
+ const command = event.input.command;
7646
+ if (typeof command !== "string" || !isGitPush(command)) return;
7647
+ const output = event.content.map((part) => part.type === "text" ? part.text : "").join("\n");
7648
+ let notify = false;
7649
+ try {
7650
+ const range = parsePushedRange(output);
7651
+ if (range === null) notify = isNewRef(output);
7652
+ else notify = await touchedBakedPath({
7653
+ cwd: ctx.cwd,
7654
+ range
7655
+ });
7656
+ } catch (err) {
7657
+ log.warn({
7658
+ err,
7659
+ event: "template_build_push_classify_failed"
7660
+ }, "could not classify pushed paths; leaving the push result unchanged");
7661
+ return;
7662
+ }
7663
+ if (!notify) return;
7664
+ return { content: [...event.content, {
7665
+ type: "text",
7666
+ text: `\n${BUILD_STARTED_NOTICE}`
7667
+ }] };
7668
+ });
7669
+ };
7670
+ //#endregion
7544
7671
  //#region src/extensions/tool-history.ts
7545
7672
  const VALID_NAME_RE = /^[a-zA-Z0-9_-]+$/;
7546
7673
  function isValidToolName(name) {
@@ -7709,6 +7836,7 @@ function platformExtensions({ sessionId, channelContext }) {
7709
7836
  createSubagentExtension({ channelContext }),
7710
7837
  createContextManagementExtension(),
7711
7838
  resourcePressureWarningExtension,
7839
+ templateBuildPushExtension,
7712
7840
  tool_history_default
7713
7841
  ];
7714
7842
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skydiveai/pi-extensions",
3
- "version": "0.1.258-beta.132",
3
+ "version": "0.1.258-beta.134",
4
4
  "homepage": "https://skydive.com",
5
5
  "license": "MIT",
6
6
  "author": "Create, Inc.",