@dudousxd/nestjs-agent-opencode 2.0.0 → 2.0.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.
@@ -1279,7 +1279,12 @@ declare class OpenCodeTurns implements OnApplicationShutdown {
1279
1279
  parkedRechecksMs: readonly number[];
1280
1280
  /** A limit's stop: what it did is the engine's to log, there is no caller to tell. */
1281
1281
  private limitStop;
1282
- /** The wall-clock bound of an observation: a timer for what is left of it, if anything. */
1282
+ /**
1283
+ * The wall-clock bound of an observation: a timer for what is left of it, if anything, and how to
1284
+ * cancel it. A timer may fire a millisecond or so before `Date.now()` says the time is up (timers
1285
+ * run on a monotonic clock, rounded): one that fires early waits out the rest, so a turn is never
1286
+ * stopped before its limit and its `elapsedMs` never reads under it.
1287
+ */
1283
1288
  private watchClock;
1284
1289
  private counts;
1285
1290
  private requestStop;
@@ -1279,7 +1279,12 @@ declare class OpenCodeTurns implements OnApplicationShutdown {
1279
1279
  parkedRechecksMs: readonly number[];
1280
1280
  /** A limit's stop: what it did is the engine's to log, there is no caller to tell. */
1281
1281
  private limitStop;
1282
- /** The wall-clock bound of an observation: a timer for what is left of it, if anything. */
1282
+ /**
1283
+ * The wall-clock bound of an observation: a timer for what is left of it, if anything, and how to
1284
+ * cancel it. A timer may fire a millisecond or so before `Date.now()` says the time is up (timers
1285
+ * run on a monotonic clock, rounded): one that fires early waits out the rest, so a turn is never
1286
+ * stopped before its limit and its `elapsedMs` never reads under it.
1287
+ */
1283
1288
  private watchClock;
1284
1289
  private counts;
1285
1290
  private requestStop;
package/dist/index.cjs CHANGED
@@ -2885,7 +2885,7 @@ ${body}
2885
2885
  return milestone;
2886
2886
  } finally {
2887
2887
  watch.observing = false;
2888
- if (wall !== void 0) clearTimeout(wall);
2888
+ wall?.();
2889
2889
  }
2890
2890
  }
2891
2891
  async observeLive(runId, input, handle, live) {
@@ -3502,18 +3502,31 @@ ${body}
3502
3502
  const result = await this.requestStop(runId, reason);
3503
3503
  if (result === "unconfirmed") this.logger.warn(`run ${runId}: passed its ${reason} limit, but its owner could not be read`);
3504
3504
  }
3505
- /** The wall-clock bound of an observation: a timer for what is left of it, if anything. */
3505
+ /**
3506
+ * The wall-clock bound of an observation: a timer for what is left of it, if anything, and how to
3507
+ * cancel it. A timer may fire a millisecond or so before `Date.now()` says the time is up (timers
3508
+ * run on a monotonic clock, rounded): one that fires early waits out the rest, so a turn is never
3509
+ * stopped before its limit and its `elapsedMs` never reads under it.
3510
+ */
3506
3511
  watchClock(watch) {
3507
3512
  const max = watch.limits.wallClockMs;
3508
3513
  if (max === void 0) return void 0;
3509
- const left = watch.startedAt + max - Date.now();
3510
- if (left <= 0) {
3514
+ const left = /* @__PURE__ */ __name(() => watch.startedAt + max - Date.now(), "left");
3515
+ if (left() <= 0) {
3511
3516
  watch.pending ??= "wall-clock";
3512
3517
  return void 0;
3513
3518
  }
3514
- const timer = setTimeout(() => void this.limitStop(watch.runId, "wall-clock"), left);
3515
- timer.unref?.();
3516
- return timer;
3519
+ let timer;
3520
+ const arm = /* @__PURE__ */ __name((ms) => {
3521
+ timer = setTimeout(() => {
3522
+ const rest = left();
3523
+ if (rest > 0) arm(rest);
3524
+ else void this.limitStop(watch.runId, "wall-clock");
3525
+ }, ms);
3526
+ timer.unref?.();
3527
+ }, "arm");
3528
+ arm(left());
3529
+ return () => clearTimeout(timer);
3517
3530
  }
3518
3531
  counts(watch) {
3519
3532
  return {