@turns/dev 0.0.15 → 0.0.16

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.
@@ -188,6 +188,7 @@ class LineTransport {
188
188
  }
189
189
  }
190
190
  class ClaudeTransport extends LineTransport {
191
+ backgroundTasks = new Set();
191
192
  sessionId;
192
193
  permissionMode;
193
194
  turnWaiter;
@@ -227,6 +228,18 @@ class ClaudeTransport extends LineTransport {
227
228
  onFrame(frame) {
228
229
  if (!frame || typeof frame !== 'object')
229
230
  return;
231
+ if (frame.type === 'system' && typeof frame.task_id === 'string') {
232
+ if (frame.subtype === 'task_started' && frame.is_backgrounded !== false) {
233
+ this.backgroundTasks.add(frame.task_id);
234
+ }
235
+ else if (frame.subtype === 'task_notification') {
236
+ this.backgroundTasks.delete(frame.task_id);
237
+ }
238
+ // A result completes the foreground prompt, not the tasks it launched.
239
+ // Keep accepting new prompts while those tasks retain the warm process.
240
+ if (this.anchor.status === 'idle')
241
+ this.anchor.scheduleExit();
242
+ }
230
243
  if (frame.type === 'system' && frame.subtype === 'init' && frame.session_id) {
231
244
  this.sessionId = String(frame.session_id);
232
245
  if (this.sessionId !== this.anchor.agentSessionId)
@@ -256,6 +269,9 @@ class ClaudeTransport extends LineTransport {
256
269
  void this.answerReverse(frame);
257
270
  }
258
271
  onClose(error) {
272
+ this.backgroundTasks.clear();
273
+ if (this.anchor.status === 'idle')
274
+ this.anchor.scheduleExit();
259
275
  if (this.turnWaiter) {
260
276
  this.turnWaiter.reject(error);
261
277
  this.turnWaiter = null;
@@ -1558,7 +1574,7 @@ class Anchor {
1558
1574
  }
1559
1575
  scheduleExit() {
1560
1576
  clearTimeout(this.idleTimer);
1561
- if (this.pendingInteractions.size) {
1577
+ if (this.status === 'running' || this.pendingInteractions.size || this.transport?.backgroundTasks?.size) {
1562
1578
  this.idleTimer = null;
1563
1579
  return;
1564
1580
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@turns/dev",
3
- "version": "0.0.15",
3
+ "version": "0.0.16",
4
4
  "description": "Upload local AI agent sessions to turns.dev",
5
5
  "license": "MIT",
6
6
  "type": "module",