@turns/dev 0.0.19 → 0.0.20

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.
@@ -208,6 +208,7 @@ class LineTransport {
208
208
  */
209
209
  const CLAUDE_NOTIFICATION_RESULT_GRACE_MS = 2_000;
210
210
  class ClaudeTransport extends LineTransport {
211
+ nativeTurnActive = false;
211
212
  sessionId;
212
213
  permissionMode;
213
214
  turnWaiter;
@@ -245,9 +246,28 @@ class ClaudeTransport extends LineTransport {
245
246
  this.turnWaiter = null;
246
247
  this.control = new Map();
247
248
  }
249
+ setNativeTurnActive(active) {
250
+ if (this.nativeTurnActive === active)
251
+ return;
252
+ this.nativeTurnActive = active;
253
+ if (this.anchor.transport === this && this.anchor.status === 'idle')
254
+ this.anchor.scheduleExit();
255
+ }
248
256
  onFrame(frame) {
249
257
  if (!frame || typeof frame !== 'object')
250
258
  return;
259
+ // Background notifications can start native turns after the queued prompt
260
+ // has completed. Retain the process until the root result, including quiet
261
+ // foreground tools and gaps between streamed messages. Child results do
262
+ // not complete the root turn, and child output alone does not start one.
263
+ if (!frame.parent_tool_use_id) {
264
+ if (frame.type === 'result')
265
+ this.setNativeTurnActive(false);
266
+ else if (frame.type === 'stream_event' ||
267
+ frame.type === 'assistant' ||
268
+ (frame.type === 'system' && frame.subtype === 'status' && frame.status === 'requesting'))
269
+ this.setNativeTurnActive(true);
270
+ }
251
271
  // Another turn starting means a held notification result was not the
252
272
  // prompt's: keep waiting for the result of the turn now running.
253
273
  if (this.heldResult &&
@@ -302,6 +322,7 @@ class ClaudeTransport extends LineTransport {
302
322
  : waiter.resolve(frame);
303
323
  }
304
324
  onClose(error) {
325
+ this.setNativeTurnActive(false);
305
326
  if (this.heldResult) {
306
327
  clearTimeout(this.heldResult.timer);
307
328
  this.heldResult = null;
@@ -1654,7 +1675,10 @@ class Anchor {
1654
1675
  }
1655
1676
  scheduleExit() {
1656
1677
  clearTimeout(this.idleTimer);
1657
- if (this.status === 'running' || this.pendingInteractions.size || this.transport?.backgroundTasks?.active) {
1678
+ if (this.status === 'running' ||
1679
+ this.pendingInteractions.size ||
1680
+ this.transport?.backgroundTasks?.active ||
1681
+ this.transport?.nativeTurnActive) {
1658
1682
  this.idleTimer = null;
1659
1683
  return;
1660
1684
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@turns/dev",
3
- "version": "0.0.19",
3
+ "version": "0.0.20",
4
4
  "description": "Upload local AI agent sessions to turns.dev",
5
5
  "license": "MIT",
6
6
  "type": "module",