@tamsensedev/runner 0.20.0 → 0.20.1

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.
package/dist/cli.js CHANGED
@@ -906,6 +906,7 @@ function helperStopRequest(stop) {
906
906
  var DEFAULT_MODEL = "default";
907
907
  var QUIET_MS = 1e3;
908
908
  var IDLE_LIMIT_MS = 3e4;
909
+ var BACKGROUND_LIMIT_MS = 6e5;
909
910
  function userMessage(text2) {
910
911
  return { type: "user", message: { role: "user", content: text2 }, parent_tool_use_id: null };
911
912
  }
@@ -926,6 +927,12 @@ function switchLine(change) {
926
927
  function isActivity(message) {
927
928
  return message.type === "assistant" || message.type === "user" || message.type === "system" && message.subtype === "init";
928
929
  }
930
+ function backgroundOf(message) {
931
+ if (message.type !== "system" || message.subtype !== "background_tasks_changed") {
932
+ return null;
933
+ }
934
+ return message.tasks.filter((task) => !task.ambient).length;
935
+ }
929
936
  function inputChannel(options = {}) {
930
937
  const queue = [];
931
938
  const seen = /* @__PURE__ */ new Set();
@@ -941,6 +948,7 @@ function inputChannel(options = {}) {
941
948
  let quiet = false;
942
949
  let idleEpoch = 0;
943
950
  let inFlight = 0;
951
+ let background = 0;
944
952
  let statesSeen = false;
945
953
  let wake = null;
946
954
  let timers = [];
@@ -966,7 +974,7 @@ function inputChannel(options = {}) {
966
974
  wakeUp();
967
975
  }
968
976
  function maybeClose() {
969
- if (started && idle && drained && quiet && queue.length === 0 && inFlight === 0) {
977
+ if (started && idle && drained && quiet && background === 0 && queue.length === 0 && inFlight === 0) {
970
978
  close();
971
979
  }
972
980
  }
@@ -974,23 +982,34 @@ function inputChannel(options = {}) {
974
982
  idle = false;
975
983
  clearTimers();
976
984
  }
977
- function turnEnded() {
978
- if (closed || idle) {
979
- return;
980
- }
981
- idle = true;
982
- idleEpoch += 1;
983
- drained = !options.onIdle;
985
+ function armTimers() {
986
+ clearTimers();
984
987
  quiet = false;
985
- timers = [
988
+ timers = background > 0 ? [setTimeout(close, options.backgroundLimitMs ?? BACKGROUND_LIMIT_MS)] : [
986
989
  setTimeout(() => {
987
990
  quiet = true;
988
991
  maybeClose();
989
992
  }, options.quietMs ?? QUIET_MS),
990
993
  setTimeout(close, options.idleLimitMs ?? IDLE_LIMIT_MS)
991
994
  ];
995
+ }
996
+ function turnEnded() {
997
+ if (closed || idle) {
998
+ return;
999
+ }
1000
+ idle = true;
1001
+ idleEpoch += 1;
1002
+ drained = !options.onIdle;
1003
+ armTimers();
992
1004
  options.onIdle?.();
993
1005
  }
1006
+ function backgroundChanged(count) {
1007
+ const was = background;
1008
+ background = count;
1009
+ if (idle && !closed && was > 0 !== count > 0) {
1010
+ armTimers();
1011
+ }
1012
+ }
994
1013
  async function* stream(own) {
995
1014
  for (; ; ) {
996
1015
  if (closed || own !== generation) {
@@ -1032,6 +1051,11 @@ function inputChannel(options = {}) {
1032
1051
  },
1033
1052
  // Если Claude Code сообщает состояние сессии, верим только ему: idle приходит после фоновых задач
1034
1053
  observe(message) {
1054
+ const tasks = backgroundOf(message);
1055
+ if (tasks !== null) {
1056
+ backgroundChanged(tasks);
1057
+ return;
1058
+ }
1035
1059
  if (message.type === "system" && message.subtype === "session_state_changed") {
1036
1060
  statesSeen = true;
1037
1061
  if (message.state === "idle") {