@liberseek/boft-cli-win32-arm64 0.8.4 → 0.8.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.
@@ -3580,10 +3580,10 @@ var $ZodObject = /* @__PURE__ */ $constructor("$ZodObject", (inst, def) => {
3580
3580
  const shape = def.shape;
3581
3581
  const propValues = {};
3582
3582
  for (const key in shape) {
3583
- const field = shape[key]._zod;
3584
- if (field.values) {
3583
+ const field2 = shape[key]._zod;
3584
+ if (field2.values) {
3585
3585
  propValues[key] ?? (propValues[key] = /* @__PURE__ */ new Set());
3586
- for (const v of field.values)
3586
+ for (const v of field2.values)
3587
3587
  propValues[key].add(v);
3588
3588
  }
3589
3589
  }
@@ -15223,6 +15223,8 @@ var usageStatisticsTotalsSchema = external_exports.strictObject({
15223
15223
  cachedInputTokens: count,
15224
15224
  cacheWriteInputTokens: count,
15225
15225
  cacheKnownInputTokens: count,
15226
+ cacheHitCachedInputTokens: count,
15227
+ cacheHitInputTokens: count,
15226
15228
  outputTokens: count,
15227
15229
  reasoningOutputTokens: count,
15228
15230
  /** USD at the public price, summed over the priced requests only. */
@@ -15330,6 +15332,51 @@ var hostInteractionIdSchema = opaqueIdSchema.brand();
15330
15332
  var threadPrewarmDiscardParamsSchema = external_exports.object({ threadId: hostThreadIdSchema });
15331
15333
  var threadPrewarmDiscardResultSchema = external_exports.object({ discarded: external_exports.boolean() });
15332
15334
 
15335
+ // ../../shared-contracts/dist/thread-questions.js
15336
+ var field = external_exports.discriminatedUnion("type", [
15337
+ external_exports.object({
15338
+ id: external_exports.string().min(1),
15339
+ type: external_exports.literal("choice"),
15340
+ prompt: external_exports.string(),
15341
+ options: external_exports.array(external_exports.object({
15342
+ value: external_exports.string().min(1),
15343
+ label: external_exports.string(),
15344
+ description: external_exports.string().optional()
15345
+ })).min(1),
15346
+ multiple: external_exports.boolean(),
15347
+ allowOther: external_exports.boolean(),
15348
+ optional: external_exports.boolean()
15349
+ }),
15350
+ external_exports.object({
15351
+ id: external_exports.string().min(1),
15352
+ type: external_exports.literal("text"),
15353
+ prompt: external_exports.string(),
15354
+ multiline: external_exports.boolean(),
15355
+ secret: external_exports.literal(false),
15356
+ optional: external_exports.boolean(),
15357
+ placeholder: external_exports.string().optional(),
15358
+ prefill: external_exports.string().optional()
15359
+ })
15360
+ ]);
15361
+ var threadQuestionSchema = external_exports.object({
15362
+ interactionId: external_exports.string().min(1),
15363
+ turnId: external_exports.string().min(1),
15364
+ title: external_exports.string().optional(),
15365
+ questions: external_exports.array(field).min(1)
15366
+ }).refine(({ questions }) => questions.some((q) => q.type === "choice" && q.multiple), {
15367
+ message: "Shared cards require at least one multi-select question"
15368
+ });
15369
+ var threadQuestionsListParamsSchema = external_exports.strictObject({ threadId: external_exports.string().min(1) });
15370
+ var threadQuestionsResultSchema = external_exports.object({ questions: external_exports.array(threadQuestionSchema) });
15371
+ var threadQuestionRespondParamsSchema = external_exports.strictObject({
15372
+ threadId: external_exports.string().min(1),
15373
+ turnId: external_exports.string().min(1),
15374
+ interactionId: external_exports.string().min(1),
15375
+ answers: external_exports.record(external_exports.string(), external_exports.array(external_exports.string())),
15376
+ cancelled: external_exports.boolean().default(false)
15377
+ });
15378
+ var threadQuestionRespondResultSchema = external_exports.object({ accepted: external_exports.literal(true) });
15379
+
15333
15380
  // ../../shared-contracts/dist/harness-plugins.js
15334
15381
  var HARNESS_PLUGIN_MANIFEST_MAX_BYTES = 32 * 1024;
15335
15382
  var HARNESS_PLUGIN_ICON_MAX_BYTES = 128 * 1024;
@@ -16099,7 +16146,10 @@ var harnessPluginRouteSchema = external_exports.object({
16099
16146
  harnessId: harnessPluginIdSchema,
16100
16147
  model: harnessModelRefSchema.optional(),
16101
16148
  thinkingOptionId: harnessThinkingOptionIdSchema.optional(),
16102
- permissionModeId: harnessPermissionModeIdSchema.optional()
16149
+ permissionModeId: harnessPermissionModeIdSchema.optional(),
16150
+ /** A draft prewarm create: stays unsubmitted until the user's first Turn.
16151
+ * Desktop forwards only the Model of a main-process prewarm to thread/start. */
16152
+ prewarm: external_exports.literal(true).optional()
16103
16153
  }).strict();
16104
16154
 
16105
16155
  // ../../shared-contracts/dist/harness-launch-settings.js
@@ -17010,26 +17060,26 @@ function parseHostUsage(value) {
17010
17060
  }
17011
17061
  }
17012
17062
  const indicators = value.composerIndicators === void 0 ? {} : { composerIndicators: composerIndicatorsSchema.parse(value.composerIndicators) };
17013
- for (const field of [
17063
+ for (const field2 of [
17014
17064
  "totalCredits",
17015
17065
  "contextUsagePercent",
17016
17066
  "apiOutputTokensPerSecond"
17017
17067
  ]) {
17018
- const candidate = value[field];
17068
+ const candidate = value[field2];
17019
17069
  if (candidate !== void 0 && (typeof candidate !== "number" || !Number.isFinite(candidate) || candidate < 0)) {
17020
- throw new Error(`Harness Usage '${field}' must be a finite non-negative number`);
17070
+ throw new Error(`Harness Usage '${field2}' must be a finite non-negative number`);
17021
17071
  }
17022
17072
  }
17023
- for (const field of tokenFields) {
17024
- const candidate = value[field];
17073
+ for (const field2 of tokenFields) {
17074
+ const candidate = value[field2];
17025
17075
  if (candidate !== void 0 && (typeof candidate !== "number" || !Number.isSafeInteger(candidate) || candidate < 0)) {
17026
- throw new Error(`Harness Usage '${field}' must be a non-negative safe integer`);
17076
+ throw new Error(`Harness Usage '${field2}' must be a non-negative safe integer`);
17027
17077
  }
17028
17078
  }
17029
- for (const field of safeIntegerFields) {
17030
- const candidate = value[field];
17079
+ for (const field2 of safeIntegerFields) {
17080
+ const candidate = value[field2];
17031
17081
  if (candidate !== void 0 && (typeof candidate !== "number" || !Number.isSafeInteger(candidate) || candidate < 0)) {
17032
- throw new Error(`Harness Usage '${field}' must be a non-negative safe integer`);
17082
+ throw new Error(`Harness Usage '${field2}' must be a non-negative safe integer`);
17033
17083
  }
17034
17084
  }
17035
17085
  if (value.outputTokensPerSecond !== void 0 && (typeof value.outputTokensPerSecond !== "number" || !Number.isFinite(value.outputTokensPerSecond) || value.outputTokensPerSecond < 0)) {
@@ -17038,16 +17088,16 @@ function parseHostUsage(value) {
17038
17088
  if (value.totalCostUsd !== void 0 && (typeof value.totalCostUsd !== "number" || !Number.isFinite(value.totalCostUsd) || value.totalCostUsd < 0)) {
17039
17089
  throw new Error("Harness Usage 'totalCostUsd' must be a finite non-negative number");
17040
17090
  }
17041
- for (const field of ["totalCredits", "contextUsagePercent"]) {
17042
- const candidate = value[field];
17091
+ for (const field2 of ["totalCredits", "contextUsagePercent"]) {
17092
+ const candidate = value[field2];
17043
17093
  if (candidate !== void 0 && (typeof candidate !== "number" || !Number.isFinite(candidate) || candidate < 0)) {
17044
- throw new Error(`Harness Usage '${field}' must be a finite non-negative number`);
17094
+ throw new Error(`Harness Usage '${field2}' must be a finite non-negative number`);
17045
17095
  }
17046
17096
  }
17047
- for (const field of percentFields) {
17048
- const candidate = value[field];
17097
+ for (const field2 of percentFields) {
17098
+ const candidate = value[field2];
17049
17099
  if (candidate !== void 0 && (typeof candidate !== "number" || !Number.isFinite(candidate) || candidate < 0 || candidate > 100)) {
17050
- throw new Error(`Harness Usage '${field}' must be between 0 and 100`);
17100
+ throw new Error(`Harness Usage '${field2}' must be between 0 and 100`);
17051
17101
  }
17052
17102
  }
17053
17103
  if (value.sessionCacheUsage !== void 0) {
@@ -17118,19 +17168,19 @@ function parseHostUsageRequest(value) {
17118
17168
  if (typeof value.requestId !== "string" || value.requestId.length === 0) {
17119
17169
  throw new Error("Harness Usage request 'requestId' must be a non-empty string");
17120
17170
  }
17121
- for (const field of ["model", "provider"]) {
17122
- const candidate = value[field];
17171
+ for (const field2 of ["model", "provider"]) {
17172
+ const candidate = value[field2];
17123
17173
  if (candidate !== void 0 && (typeof candidate !== "string" || candidate.length === 0)) {
17124
- throw new Error(`Harness Usage request '${field}' must be a non-empty string`);
17174
+ throw new Error(`Harness Usage request '${field2}' must be a non-empty string`);
17125
17175
  }
17126
17176
  }
17127
17177
  if (value.historical !== void 0 && typeof value.historical !== "boolean") {
17128
17178
  throw new Error("Harness Usage request 'historical' must be a boolean");
17129
17179
  }
17130
- for (const field of requestTokenFields) {
17131
- const candidate = value[field];
17180
+ for (const field2 of requestTokenFields) {
17181
+ const candidate = value[field2];
17132
17182
  if (candidate !== void 0 && (typeof candidate !== "number" || !Number.isSafeInteger(candidate) || candidate < 0)) {
17133
- throw new Error(`Harness Usage request '${field}' must be a non-negative safe integer`);
17183
+ throw new Error(`Harness Usage request '${field2}' must be a non-negative safe integer`);
17134
17184
  }
17135
17185
  }
17136
17186
  if (value.inputTokens === void 0 || value.outputTokens === void 0) {
@@ -17857,9 +17907,9 @@ function nestedToolString(value, keys, allowEmpty = false) {
17857
17907
  if (!isRecord3(value))
17858
17908
  return void 0;
17859
17909
  for (const key of keys) {
17860
- const field = value[key];
17861
- if (typeof field === "string" && (allowEmpty || field.length > 0))
17862
- return field;
17910
+ const field2 = value[key];
17911
+ if (typeof field2 === "string" && (allowEmpty || field2.length > 0))
17912
+ return field2;
17863
17913
  }
17864
17914
  for (const wrapper of ["input", "arguments", "params", "details"]) {
17865
17915
  const nested = nestedToolString(value[wrapper], keys, allowEmpty);
@@ -17872,15 +17922,15 @@ function patchFromResult(result) {
17872
17922
  if (!isRecord3(result))
17873
17923
  return void 0;
17874
17924
  for (const key of ["patch", "diff", "unifiedDiff"]) {
17875
- const field = result[key];
17876
- if (typeof field === "string" && field.length > 0)
17877
- return field;
17925
+ const field2 = result[key];
17926
+ if (typeof field2 === "string" && field2.length > 0)
17927
+ return field2;
17878
17928
  }
17879
17929
  if (isRecord3(result.details)) {
17880
17930
  for (const key of ["patch", "diff", "unifiedDiff"]) {
17881
- const field = result.details[key];
17882
- if (typeof field === "string" && field.length > 0)
17883
- return field;
17931
+ const field2 = result.details[key];
17932
+ if (typeof field2 === "string" && field2.length > 0)
17933
+ return field2;
17884
17934
  }
17885
17935
  }
17886
17936
  return void 0;
@@ -18374,8 +18424,8 @@ function parsePiSubagentInspection(value) {
18374
18424
  return null;
18375
18425
  if (parsed.error !== void 0 && (!record3(parsed.error) || typeof parsed.error.code !== "string" || typeof parsed.error.message !== "string"))
18376
18426
  return null;
18377
- for (const field of ["asyncId", "childId", "status", "task", "finalOutput"]) {
18378
- if (parsed[field] !== void 0 && typeof parsed[field] !== "string")
18427
+ for (const field2 of ["asyncId", "childId", "status", "task", "finalOutput"]) {
18428
+ if (parsed[field2] !== void 0 && typeof parsed[field2] !== "string")
18379
18429
  return null;
18380
18430
  }
18381
18431
  if (parsed.messages !== void 0 && (!Array.isArray(parsed.messages) || parsed.messages.length > 200 || parsed.messages.some((entry) => !record3(entry) || typeof entry.role !== "string" || typeof entry.text !== "string" || !["text", "toolCall", "toolResult"].includes(String(entry.kind)) || entry.name !== void 0 && typeof entry.name !== "string")))
@@ -18500,7 +18550,7 @@ function normalizePiThinkingOptions(levels) {
18500
18550
  label: PI_THINKING_LABELS[id] ?? fallbackThinkingLabel(id)
18501
18551
  }));
18502
18552
  }
18503
- function normalizePiModelCatalog(nativeModels, effectiveModel, thinkingLevels, effectiveThinkingOptionId) {
18553
+ function normalizePiModelCatalog(nativeModels, effectiveModel, thinkingLevels, effectiveThinkingOptionId, effectiveModelReasoning = null) {
18504
18554
  const byRef = /* @__PURE__ */ new Map();
18505
18555
  for (const native of nativeModels) {
18506
18556
  const ref = encodePiModelRef(native);
@@ -18516,12 +18566,21 @@ function normalizePiModelCatalog(nativeModels, effectiveModel, thinkingLevels, e
18516
18566
  ref,
18517
18567
  label: `${native.provider} / ${native.id}`
18518
18568
  },
18519
- reasoning: native.reasoning
18569
+ reasoning: native.reasoning,
18570
+ synthesized: false
18520
18571
  });
18521
18572
  }
18522
18573
  const defaultModel = effectiveModel ? encodePiModelRef(effectiveModel) : void 0;
18523
- if (defaultModel && !byRef.has(defaultModel.id)) {
18524
- throw new Error("Pi effective Model is absent from the available Model catalog");
18574
+ if (effectiveModel && defaultModel && !byRef.has(defaultModel.id)) {
18575
+ const reasoning = effectiveThinkingOptionId && effectiveThinkingOptionId !== "off" || (effectiveModelReasoning ?? Boolean(thinkingLevels && thinkingLevels.some((level) => level !== "off")));
18576
+ byRef.set(defaultModel.id, {
18577
+ model: {
18578
+ ref: defaultModel,
18579
+ label: `${effectiveModel.provider} / ${effectiveModel.id}`
18580
+ },
18581
+ reasoning,
18582
+ synthesized: true
18583
+ });
18525
18584
  }
18526
18585
  if (thinkingLevels && effectiveThinkingOptionId && !thinkingLevels.includes(effectiveThinkingOptionId)) {
18527
18586
  throw new Error("Pi effective Thinking option is absent from the available option catalog");
@@ -18532,9 +18591,10 @@ function normalizePiModelCatalog(nativeModels, effectiveModel, thinkingLevels, e
18532
18591
  const thinkingOptions = thinkingLevels ? normalizePiThinkingOptions(PI_DRAFT_THINKING_OPTION_IDS) : [];
18533
18592
  const allThinkingOptionIds = thinkingOptions.map(({ id }) => id);
18534
18593
  const offThinkingOptionId = thinkingOptions.find(({ id }) => id === "off")?.id;
18535
- const models = [...byRef.values()].map(({ model: model2, reasoning }) => ({
18594
+ const effectiveThinkingOptionIds = thinkingLevels ? allThinkingOptionIds.filter((id) => thinkingLevels.includes(id)) : allThinkingOptionIds;
18595
+ const models = [...byRef.values()].map(({ model: model2, reasoning, synthesized }) => ({
18536
18596
  ...model2,
18537
- supportedThinkingOptionIds: reasoning ? allThinkingOptionIds : offThinkingOptionId ? [offThinkingOptionId] : []
18597
+ supportedThinkingOptionIds: reasoning ? synthesized ? effectiveThinkingOptionIds : allThinkingOptionIds : offThinkingOptionId ? [offThinkingOptionId] : []
18538
18598
  })).sort((left, right) => compareText(left.label, right.label) || compareText(left.ref.id, right.ref.id));
18539
18599
  const defaultThinkingOptionId = thinkingOptions.find(({ id }) => id === effectiveThinkingOptionId)?.id;
18540
18600
  return harnessModelCatalogSchema.parse({
@@ -19179,6 +19239,8 @@ import { pathToFileURL } from "node:url";
19179
19239
  import fs2 from "node:fs";
19180
19240
  import { homedir as homedir3, tmpdir as tmpdir2 } from "node:os";
19181
19241
  import path8 from "node:path";
19242
+ var PI_PACKAGE_NAME = "@earendil-works/pi-coding-agent";
19243
+ var PI_PACKAGE_PATH = path8.join("node_modules", "@earendil-works", "pi-coding-agent");
19182
19244
  var piDiscoverySpec = {
19183
19245
  id: "pi",
19184
19246
  command: "pi",
@@ -19203,6 +19265,43 @@ function resolvePiExecutable(input, dependencies = {}) {
19203
19265
  }, { ...dependencies.isExecutable ? { isExecutable: dependencies.isExecutable } : {} });
19204
19266
  return resolution?.executable ?? input.command ?? input.environment.PI_COMMAND ?? "pi";
19205
19267
  }
19268
+ function findPiPackageDirectory(executable) {
19269
+ let directory = path8.dirname(executable);
19270
+ while (true) {
19271
+ for (const candidate of [directory, path8.join(directory, PI_PACKAGE_PATH)]) {
19272
+ try {
19273
+ const manifest = JSON.parse(fs2.readFileSync(path8.join(candidate, "package.json"), "utf8"));
19274
+ if (typeof manifest === "object" && manifest !== null && "name" in manifest && manifest.name === PI_PACKAGE_NAME) {
19275
+ return candidate;
19276
+ }
19277
+ } catch {
19278
+ }
19279
+ }
19280
+ const parent = path8.dirname(directory);
19281
+ if (parent === directory)
19282
+ return void 0;
19283
+ directory = parent;
19284
+ }
19285
+ }
19286
+ function findPiCliEntry(packageDirectory) {
19287
+ try {
19288
+ const manifest = JSON.parse(fs2.readFileSync(path8.join(packageDirectory, "package.json"), "utf8"));
19289
+ if (typeof manifest !== "object" || manifest === null || !("bin" in manifest))
19290
+ return void 0;
19291
+ const bin = manifest.bin;
19292
+ const entry = typeof bin === "string" ? bin : typeof bin === "object" && bin !== null && "pi" in bin ? bin.pi : void 0;
19293
+ if (typeof entry !== "string" || !entry.trim())
19294
+ return void 0;
19295
+ const resolved = path8.resolve(packageDirectory, entry);
19296
+ const relative = path8.relative(packageDirectory, resolved);
19297
+ if (relative === ".." || relative.startsWith(`..${path8.sep}`) || path8.isAbsolute(relative) || !fs2.statSync(resolved).isFile()) {
19298
+ return void 0;
19299
+ }
19300
+ return resolved;
19301
+ } catch {
19302
+ return void 0;
19303
+ }
19304
+ }
19206
19305
  function isFilesystemRoot(cwd) {
19207
19306
  const resolved = path8.resolve(cwd);
19208
19307
  return resolved === path8.parse(resolved).root;
@@ -19292,19 +19391,10 @@ function removeOwnedFiles(dir) {
19292
19391
  }
19293
19392
  async function installation(command, environment, authPath) {
19294
19393
  const executable = await realpath2(resolvePiExecutable({ ...command ? { command } : {}, environment }));
19295
- let directory = path9.dirname(executable);
19296
- while (true) {
19297
- const manifest = path9.join(directory, "package.json");
19298
- if (existsSync(manifest)) {
19299
- const pkg = JSON.parse(readFileSync(manifest, "utf8"));
19300
- if (pkg.name === "@earendil-works/pi-coding-agent")
19301
- break;
19302
- }
19303
- const parent = path9.dirname(directory);
19304
- if (parent === directory)
19305
- throw new Error("Pi credential import requires a supported npm Pi installation");
19306
- directory = parent;
19307
- }
19394
+ const directory = findPiPackageDirectory(executable);
19395
+ const cliEntry = directory ? findPiCliEntry(directory) : void 0;
19396
+ if (!directory || !cliEntry)
19397
+ throw new Error("Pi credential import requires a supported npm Pi installation");
19308
19398
  const storage = await import(pathToFileURL(path9.join(directory, "dist/core/auth-storage.js")).href);
19309
19399
  const ai = path9.join(directory, "node_modules/@earendil-works/pi-ai/dist");
19310
19400
  const all = await import(pathToFileURL(path9.join(ai, "providers/all.js")).href);
@@ -19324,7 +19414,7 @@ async function installation(command, environment, authPath) {
19324
19414
  providerModules,
19325
19415
  reservedNames: providers.map((p) => typeof p === "string" ? p : p.id),
19326
19416
  async configuredProviderNames() {
19327
- const { stdout } = await promisify(execFile2)(process.execPath, [executable, "--offline", "--no-approve", "--list-models"], {
19417
+ const { stdout } = await promisify(execFile2)(process.execPath, [cliEntry, "--offline", "--no-approve", "--list-models"], {
19328
19418
  cwd: existsSync(path9.dirname(authPath)) ? path9.dirname(authPath) : os4.homedir(),
19329
19419
  env: { ...environment, PI_CODING_AGENT_DIR: path9.dirname(authPath), PI_OFFLINE: "1" },
19330
19420
  timeout: 15e3,
@@ -20176,6 +20266,15 @@ var PiRpcUnsupportedCommandError = class extends Error {
20176
20266
  this.name = "PiRpcUnsupportedCommandError";
20177
20267
  }
20178
20268
  };
20269
+ var READ_ONLY_COMMANDS = /* @__PURE__ */ new Set([
20270
+ "get_state",
20271
+ "get_commands",
20272
+ "get_entries",
20273
+ "get_session_stats",
20274
+ "get_available_models",
20275
+ "get_available_thinking_levels"
20276
+ ]);
20277
+ var MAX_EXPIRED_IDS = 64;
20179
20278
  var textDecoder = new TextDecoder("utf-8", { fatal: true });
20180
20279
  function isRecord8(value) {
20181
20280
  return typeof value === "object" && value !== null && !Array.isArray(value);
@@ -20203,6 +20302,7 @@ function sessionStateData(response) {
20203
20302
  function parseSessionState(response) {
20204
20303
  const data = sessionStateData(response);
20205
20304
  const model2 = parseNativeModel(data.model, "state");
20305
+ const modelReasoning = isRecord8(data.model) && typeof data.model.reasoning === "boolean" ? data.model.reasoning : null;
20206
20306
  if (!nonBlankString(data.sessionId)) {
20207
20307
  throw new PiRpcFaultError("protocolError", "Pi RPC state has no stable Session identity");
20208
20308
  }
@@ -20215,6 +20315,7 @@ function parseSessionState(response) {
20215
20315
  sessionFile: typeof data.sessionFile === "string" ? data.sessionFile : null,
20216
20316
  provider: model2?.provider ?? null,
20217
20317
  modelId: model2?.id ?? null,
20318
+ ...modelReasoning === null ? {} : { modelReasoning },
20218
20319
  thinkingLevel: thinkingLevel?.data ?? null,
20219
20320
  contextUsage: optionalPiStateContextUsage(data.contextUsage)
20220
20321
  };
@@ -20398,7 +20499,11 @@ var PiRpcSession = class {
20398
20499
  #autonomousTurnHandler = null;
20399
20500
  #usageHandler = null;
20400
20501
  #usageRequestStartedAtMs = null;
20401
- #buffer = Buffer.alloc(0);
20502
+ // Pieces of the unterminated frame; joined once at its newline so a large frame (a long
20503
+ // Session's get_entries) costs linear rather than quadratic copying on the Host event loop.
20504
+ #buffer = [];
20505
+ // Ids whose read-only command timed out; Pi may still answer them late.
20506
+ #expired = /* @__PURE__ */ new Set();
20402
20507
  #child = null;
20403
20508
  #closed = false;
20404
20509
  #closePromise = null;
@@ -20811,11 +20916,13 @@ var PiRpcSession = class {
20811
20916
  }
20812
20917
  }
20813
20918
  #push(chunk) {
20814
- this.#buffer = this.#buffer.length === 0 ? chunk : Buffer.concat([this.#buffer, chunk]);
20815
- let newline = this.#buffer.indexOf(10);
20919
+ let rest = chunk;
20920
+ let newline = rest.indexOf(10);
20816
20921
  while (newline >= 0) {
20817
- const frame = this.#buffer.subarray(0, newline);
20818
- this.#buffer = this.#buffer.subarray(newline + 1);
20922
+ const tail = rest.subarray(0, newline);
20923
+ const frame = this.#buffer.length === 0 ? tail : Buffer.concat([...this.#buffer, tail]);
20924
+ this.#buffer = [];
20925
+ rest = rest.subarray(newline + 1);
20819
20926
  try {
20820
20927
  const value = JSON.parse(textDecoder.decode(frame));
20821
20928
  if (!isRecord8(value) || typeof value.type !== "string") {
@@ -20825,8 +20932,10 @@ var PiRpcSession = class {
20825
20932
  } catch (error51) {
20826
20933
  this.#fail(error51 instanceof PiRpcFaultError ? error51 : new PiRpcFaultError("protocolError", `Pi RPC returned invalid JSONL: ${message2(error51)}`));
20827
20934
  }
20828
- newline = this.#buffer.indexOf(10);
20935
+ newline = rest.indexOf(10);
20829
20936
  }
20937
+ if (rest.length !== 0)
20938
+ this.#buffer.push(rest);
20830
20939
  }
20831
20940
  #handle(value) {
20832
20941
  if (value.type === "extension_ui_request" && value.method === "notify" && typeof value.message === "string" && value.message.startsWith(PI_FAST_ACK)) {
@@ -21088,6 +21197,8 @@ var PiRpcSession = class {
21088
21197
  return;
21089
21198
  }
21090
21199
  const pending = this.#pending.get(id);
21200
+ if (!pending && this.#expired.delete(id))
21201
+ return;
21091
21202
  if (!pending) {
21092
21203
  this.#fail(new PiRpcFaultError("protocolError", "Pi RPC response id is not pending"));
21093
21204
  return;
@@ -21332,6 +21443,12 @@ var PiRpcSession = class {
21332
21443
  const error51 = new Error(`Pi RPC '${pending.command}' command timed out`);
21333
21444
  if (pending.command !== "prompt") {
21334
21445
  this.#pending.delete(id);
21446
+ if (READ_ONLY_COMMANDS.has(pending.command)) {
21447
+ this.#expired.add(id);
21448
+ if (this.#expired.size > MAX_EXPIRED_IDS) {
21449
+ this.#expired.delete(this.#expired.values().next().value);
21450
+ }
21451
+ }
21335
21452
  pending.reject(error51);
21336
21453
  return;
21337
21454
  }
@@ -21534,9 +21651,9 @@ function outputText(output) {
21534
21651
  function stringField(value, key) {
21535
21652
  if (!isRecord9(value))
21536
21653
  return void 0;
21537
- const field = value[key];
21538
- if (typeof field === "string" && field.length > 0)
21539
- return field;
21654
+ const field2 = value[key];
21655
+ if (typeof field2 === "string" && field2.length > 0)
21656
+ return field2;
21540
21657
  if (isRecord9(value.input)) {
21541
21658
  const nested = value.input[key];
21542
21659
  if (typeof nested === "string" && nested.length > 0)
@@ -21552,8 +21669,8 @@ function stringField(value, key) {
21552
21669
  function numberField(value, key) {
21553
21670
  if (!isRecord9(value))
21554
21671
  return void 0;
21555
- const field = value[key];
21556
- return typeof field === "number" || field === null ? field : void 0;
21672
+ const field2 = value[key];
21673
+ return typeof field2 === "number" || field2 === null ? field2 : void 0;
21557
21674
  }
21558
21675
  function normalizeToolName(name) {
21559
21676
  const lower = name.toLowerCase();
@@ -23003,7 +23120,7 @@ var PiAdapter = class {
23003
23120
  stage = "capabilities";
23004
23121
  const thinkingLevels = await transport.getAvailableThinkingLevels();
23005
23122
  this.#thinkingSelectionSupported = thinkingLevels !== null;
23006
- const normalized = normalizePiModelCatalog(models, nativeModelFromState(transport.state), thinkingLevels, transport.state.thinkingLevel);
23123
+ const normalized = normalizePiModelCatalog(models, nativeModelFromState(transport.state), thinkingLevels, transport.state.thinkingLevel, transport.state.modelReasoning ?? null);
23007
23124
  const fastModels = await transport.supportsFastMode?.() ? piFastModelKeys(models) : /* @__PURE__ */ new Set();
23008
23125
  const catalog = withPiFast(normalized, fastModels);
23009
23126
  await transport.close();