@liberseek/boft-cli-win32-arm64 0.6.3 → 0.6.5

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.
@@ -19248,6 +19248,12 @@ function parseHostUsage(value) {
19248
19248
  throw new Error(`Harness Usage contains unknown field '${key}'`);
19249
19249
  }
19250
19250
  }
19251
+ for (const field of ["totalCredits", "contextUsagePercent"]) {
19252
+ const candidate = value[field];
19253
+ if (candidate !== void 0 && (typeof candidate !== "number" || !Number.isFinite(candidate) || candidate < 0)) {
19254
+ throw new Error(`Harness Usage '${field}' must be a finite non-negative number`);
19255
+ }
19256
+ }
19251
19257
  for (const field of tokenFields) {
19252
19258
  const candidate = value[field];
19253
19259
  if (candidate !== void 0 && (typeof candidate !== "number" || !Number.isSafeInteger(candidate) || candidate < 0)) {
@@ -30826,6 +30832,7 @@ var LiveBuffer = class {
30826
30832
  import { randomUUID as nodeRandomUUID } from "node:crypto";
30827
30833
  import { isDeepStrictEqual as isDeepStrictEqual5 } from "node:util";
30828
30834
  var DEEPSEEK_HARNESS_ID2 = harnessIdSchema.parse("deepseek-harness");
30835
+ var NATIVE_CLOSE_TIMEOUT_MS = 5e3;
30829
30836
  var MODERN_PROMPT_CORRELATION_GRACE_MS = 5e3;
30830
30837
  var MODERN_ACCEPTED_CORRELATION_TIMEOUT_MS = 3e5;
30831
30838
  var MAX_TIMER_DELAY_MS2 = 2147483647;
@@ -30905,8 +30912,11 @@ var ModernHarnessSession = class {
30905
30912
  #usage;
30906
30913
  #historyBytes;
30907
30914
  #closed = false;
30915
+ #closing = false;
30916
+ #nativeCloseTerminal;
30908
30917
  #closedNotified = false;
30909
30918
  #faulted;
30919
+ #faultMayHaveNativeWork = false;
30910
30920
  #closePromise;
30911
30921
  #pumpPromise;
30912
30922
  constructor(options) {
@@ -30999,14 +31009,14 @@ var ModernHarnessSession = class {
30999
31009
  this.#pumpPromise = this.#pump();
31000
31010
  if (resumedAutonomousBuffer) {
31001
31011
  queueMicrotask(() => {
31002
- if (!this.#closed && this.#buffer === resumedAutonomousBuffer) {
31012
+ if (!this.#closed && !this.#closing && this.#buffer === resumedAutonomousBuffer) {
31003
31013
  this.#activateBufferedAutonomous(true);
31004
31014
  }
31005
31015
  });
31006
31016
  }
31007
31017
  }
31008
31018
  readSnapshot() {
31009
- if (this.#closed)
31019
+ if (this.#closed || this.#closing)
31010
31020
  return Promise.resolve({ ok: false, error: closedError() });
31011
31021
  if (this.#reading)
31012
31022
  return Promise.resolve({ ok: false, error: busyError("read history") });
@@ -31028,7 +31038,7 @@ var ModernHarnessSession = class {
31028
31038
  }
31029
31039
  }
31030
31040
  execute(command) {
31031
- if (this.#closed)
31041
+ if (this.#closed || this.#closing)
31032
31042
  return Promise.resolve({ ok: false, error: closedError() });
31033
31043
  switch (command.type) {
31034
31044
  case "turn.start":
@@ -31046,6 +31056,13 @@ var ModernHarnessSession = class {
31046
31056
  }
31047
31057
  }
31048
31058
  close() {
31059
+ const faultCleanup = this.#closePromise;
31060
+ if (this.#faultMayHaveNativeWork && !this.#closing && faultCleanup) {
31061
+ this.#closing = true;
31062
+ this.#closePromise = faultCleanup.then(() => {
31063
+ throw new Error("DeepSeek Harness native execution stop was not confirmed before the Session fault");
31064
+ });
31065
+ }
31049
31066
  this.#closePromise ??= this.#performClose();
31050
31067
  return this.#closePromise;
31051
31068
  }
@@ -31060,7 +31077,7 @@ var ModernHarnessSession = class {
31060
31077
  if (this.#queuedDeliveries.has(delivery.eventId) || this.#interactionByEventId.has(delivery.eventId)) {
31061
31078
  throw new ModernEventGatewayError("protocolError", "DeepSeek Harness event delivery was duplicated");
31062
31079
  }
31063
- if (this.#closed) {
31080
+ if (this.#closed || this.#closing) {
31064
31081
  this.#queuedDeliveries.set(delivery.eventId, delivery);
31065
31082
  return;
31066
31083
  }
@@ -31329,14 +31346,14 @@ ${question.detail}` : question.question;
31329
31346
  this.#operationControllers.add(abort);
31330
31347
  try {
31331
31348
  const result = await operation(abort.signal);
31332
- if (this.#closed)
31349
+ if (this.#closed || this.#closing)
31333
31350
  return { ok: false, error: closedError() };
31334
31351
  this.#publishConfiguration(true);
31335
31352
  return { ok: true, value: result.value };
31336
31353
  } catch (error51) {
31337
31354
  if (this.#faulted)
31338
31355
  return { ok: false, error: this.#faulted };
31339
- if (this.#closed)
31356
+ if (this.#closed || this.#closing)
31340
31357
  return { ok: false, error: closedError() };
31341
31358
  const failure = configurationOrProtocolError(error51, "DeepSeek Harness configuration failed");
31342
31359
  if (configurationFailureRequiresSessionFault(error51))
@@ -31448,7 +31465,7 @@ ${question.detail}` : question.question;
31448
31465
  } catch (error51) {
31449
31466
  if (this.#faulted)
31450
31467
  return { ok: false, error: this.#faulted };
31451
- if (this.#closed)
31468
+ if (this.#closed || this.#closing)
31452
31469
  return { ok: false, error: closedError() };
31453
31470
  if (pending.admissionObserved)
31454
31471
  return this.#acceptPrompt(pending);
@@ -31456,7 +31473,7 @@ ${question.detail}` : question.question;
31456
31473
  if (resolution.kind === "accepted") {
31457
31474
  if (this.#faulted)
31458
31475
  return { ok: false, error: this.#faulted };
31459
- if (this.#closed)
31476
+ if (this.#closed || this.#closing)
31460
31477
  return { ok: false, error: closedError() };
31461
31478
  return this.#acceptPrompt(pending);
31462
31479
  }
@@ -31524,12 +31541,12 @@ ${question.detail}` : question.question;
31524
31541
  return true;
31525
31542
  }
31526
31543
  async #listHarnessCommands() {
31527
- if (this.#closed)
31544
+ if (this.#closed || this.#closing)
31528
31545
  return { ok: false, error: closedError() };
31529
31546
  return { ok: true, value: deepSeekHarnessCommandCatalog() };
31530
31547
  }
31531
31548
  async #executeHarnessCommand(command) {
31532
- if (this.#closed)
31549
+ if (this.#closed || this.#closing)
31533
31550
  return { ok: false, error: closedError() };
31534
31551
  const parsed = parseDeepSeekHarnessCommand(command);
31535
31552
  if (!parsed.ok)
@@ -31549,7 +31566,7 @@ ${question.detail}` : question.question;
31549
31566
  const catalog = await this.#listHarnessCommands();
31550
31567
  if (!catalog.ok)
31551
31568
  return catalog;
31552
- if (this.#closed)
31569
+ if (this.#closed || this.#closing)
31553
31570
  return { ok: false, error: closedError() };
31554
31571
  if (admission.cancellationRequested) {
31555
31572
  return { ok: false, error: invalidState3("DeepSeek Harness command was cancelled") };
@@ -31911,13 +31928,13 @@ ${question.detail}` : question.question;
31911
31928
  }
31912
31929
  #scheduleBoundTurn(pending) {
31913
31930
  const buffer = pending.buffer;
31914
- if (!buffer || !pending.admitted || pending.publishScheduled || buffer.active || this.#closed) {
31931
+ if (!buffer || !pending.admitted || pending.publishScheduled || buffer.active || this.#closed || this.#closing) {
31915
31932
  return;
31916
31933
  }
31917
31934
  pending.publishScheduled = true;
31918
31935
  queueMicrotask(() => queueMicrotask(() => {
31919
31936
  pending.publishScheduled = false;
31920
- if (!this.#closed && pending.admitted && pending.buffer === buffer && this.#buffer === buffer && !buffer.active) {
31937
+ if (!this.#closed && !this.#closing && pending.admitted && pending.buffer === buffer && this.#buffer === buffer && !buffer.active) {
31921
31938
  this.#materialize(buffer, pending.command.turnId, textInputs2(pending.command.input), false, false);
31922
31939
  }
31923
31940
  }));
@@ -31933,7 +31950,7 @@ ${question.detail}` : question.question;
31933
31950
  delete pending.buffer;
31934
31951
  if (buffer.reachedCorrelationBoundary || buffer.events.at(-1)?.type === "turn/end") {
31935
31952
  queueMicrotask(() => {
31936
- if (!this.#closed && this.#buffer === buffer && !buffer.active && !buffer.pending) {
31953
+ if (!this.#closed && !this.#closing && this.#buffer === buffer && !buffer.active && !buffer.pending) {
31937
31954
  this.#materializeAutonomous(buffer, false);
31938
31955
  }
31939
31956
  });
@@ -31948,12 +31965,14 @@ ${question.detail}` : question.question;
31948
31965
  }
31949
31966
  #activateBufferedAutonomous(initialReplay = false) {
31950
31967
  const buffer = this.#buffer;
31951
- if (this.#closed || !buffer || buffer.active || buffer.pending || this.#deferAutonomousTurn() || !this.#resumeNeedsAutonomousTurn(buffer) && !buffer.reachedCorrelationBoundary && buffer.events.at(-1)?.type !== "turn/end") {
31968
+ if (this.#closed || this.#closing || !buffer || buffer.active || buffer.pending || this.#deferAutonomousTurn() || !this.#resumeNeedsAutonomousTurn(buffer) && !buffer.reachedCorrelationBoundary && buffer.events.at(-1)?.type !== "turn/end") {
31952
31969
  return;
31953
31970
  }
31954
31971
  this.#materializeAutonomous(buffer, initialReplay || buffer.initialResume);
31955
31972
  }
31956
31973
  #materializeAutonomous(buffer, initialReplay) {
31974
+ if (this.#closed || this.#closing)
31975
+ return;
31957
31976
  const turnId = hostTurnIdSchema.parse(this.#randomUUID());
31958
31977
  this.#emit({
31959
31978
  type: "turn.autonomous.started",
@@ -32222,6 +32241,7 @@ ${question.detail}` : question.question;
32222
32241
  active.terminal = true;
32223
32242
  if (buffer.pending)
32224
32243
  buffer.pending.terminal = true;
32244
+ this.#nativeCloseTerminal?.();
32225
32245
  const checkpoint = modernCheckpointRef(this.harnessId, this.#sessionId, seq);
32226
32246
  this.#emit({
32227
32247
  type: "turn.completed",
@@ -32283,6 +32303,7 @@ ${question.detail}` : question.question;
32283
32303
  return;
32284
32304
  const failure = sanitizedHarnessError(error51);
32285
32305
  const acceptedPending = this.#acceptedPending();
32306
+ this.#faultMayHaveNativeWork = Boolean(this.#active && !this.#active.terminal || this.#pendingByRequestId.size > 0 || this.#buffer || this.#commandAdmission || this.#activeCommand);
32286
32307
  this.#faulted = failure;
32287
32308
  this.#closed = true;
32288
32309
  this.#journalLifetime.abort(new Error("DeepSeek Harness Session faulted"));
@@ -32356,6 +32377,49 @@ ${question.detail}` : question.question;
32356
32377
  this.#notifyClosed();
32357
32378
  }
32358
32379
  async #performClose() {
32380
+ this.#closing = true;
32381
+ let stopFailure;
32382
+ const activeAtClose = this.#active;
32383
+ const pendingAtClose = new Set(this.#pendingByRequestId.values());
32384
+ if (this.#buffer?.pending)
32385
+ pendingAtClose.add(this.#buffer.pending);
32386
+ const correlatedPending = activeAtClose && this.#buffer?.active === activeAtClose ? this.#buffer.pending : void 0;
32387
+ const uncorrelatedExecution = [...pendingAtClose].some((pending) => !pending.terminal && pending !== correlatedPending) || !activeAtClose && this.#buffer !== void 0 || this.#commandAdmission !== void 0 || this.#activeCommand !== void 0;
32388
+ if (!this.#closed && (activeAtClose && !activeAtClose.terminal || uncorrelatedExecution)) {
32389
+ let timer;
32390
+ const terminal = new Promise((resolve2) => {
32391
+ this.#nativeCloseTerminal = () => {
32392
+ if (activeAtClose?.terminal)
32393
+ resolve2();
32394
+ };
32395
+ });
32396
+ try {
32397
+ await Promise.race([
32398
+ (async () => {
32399
+ const result = await (activeAtClose?.cancelPromise ?? this.#requestNativeCancel(activeAtClose));
32400
+ if (!result.ok)
32401
+ throw new Error(result.error.message);
32402
+ if (uncorrelatedExecution) {
32403
+ throw new Error("DeepSeek Harness cannot confirm stop before the native Turn is correlated");
32404
+ }
32405
+ await terminal;
32406
+ })(),
32407
+ new Promise((_, reject) => {
32408
+ timer = setTimeout(() => reject(new Error("DeepSeek Harness did not confirm native Turn stop before close")), NATIVE_CLOSE_TIMEOUT_MS);
32409
+ })
32410
+ ]);
32411
+ } catch (error51) {
32412
+ stopFailure = error51;
32413
+ } finally {
32414
+ if (timer)
32415
+ clearTimeout(timer);
32416
+ this.#nativeCloseTerminal = void 0;
32417
+ }
32418
+ }
32419
+ if (this.#faulted) {
32420
+ await this.#performFault(this.#faulted, this.#acceptedPending(pendingAtClose));
32421
+ throw stopFailure ?? new Error(this.#faulted.message);
32422
+ }
32359
32423
  if (!this.#closed) {
32360
32424
  const acceptedPending = this.#acceptedPending();
32361
32425
  this.#closed = true;
@@ -32410,6 +32474,8 @@ ${question.detail}` : question.question;
32410
32474
  }
32411
32475
  await Promise.allSettled([this.#journal.close(), this.#pumpPromise]);
32412
32476
  this.#notifyClosed();
32477
+ if (stopFailure)
32478
+ throw stopFailure;
32413
32479
  }
32414
32480
  #abortOperations() {
32415
32481
  for (const controller of this.#operationControllers) {
@@ -32422,8 +32488,7 @@ ${question.detail}` : question.question;
32422
32488
  for (const unsubscribe of this.#removeControlSubscriptions.splice(0))
32423
32489
  unsubscribe();
32424
32490
  }
32425
- #acceptedPending() {
32426
- const values = new Set(this.#pendingByRequestId.values());
32491
+ #acceptedPending(values = new Set(this.#pendingByRequestId.values())) {
32427
32492
  if (this.#buffer?.pending)
32428
32493
  values.add(this.#buffer.pending);
32429
32494
  return [...values].filter((pending) => (pending.admitted || pending.admissionObserved || pending.observed) && !pending.terminal);