@codexhost/cli-darwin-x64 0.14.0 → 0.15.0

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
  }
@@ -15330,6 +15330,51 @@ var hostInteractionIdSchema = opaqueIdSchema.brand();
15330
15330
  var threadPrewarmDiscardParamsSchema = external_exports.object({ threadId: hostThreadIdSchema });
15331
15331
  var threadPrewarmDiscardResultSchema = external_exports.object({ discarded: external_exports.boolean() });
15332
15332
 
15333
+ // ../../shared-contracts/dist/thread-questions.js
15334
+ var field = external_exports.discriminatedUnion("type", [
15335
+ external_exports.object({
15336
+ id: external_exports.string().min(1),
15337
+ type: external_exports.literal("choice"),
15338
+ prompt: external_exports.string(),
15339
+ options: external_exports.array(external_exports.object({
15340
+ value: external_exports.string().min(1),
15341
+ label: external_exports.string(),
15342
+ description: external_exports.string().optional()
15343
+ })).min(1),
15344
+ multiple: external_exports.boolean(),
15345
+ allowOther: external_exports.boolean(),
15346
+ optional: external_exports.boolean()
15347
+ }),
15348
+ external_exports.object({
15349
+ id: external_exports.string().min(1),
15350
+ type: external_exports.literal("text"),
15351
+ prompt: external_exports.string(),
15352
+ multiline: external_exports.boolean(),
15353
+ secret: external_exports.literal(false),
15354
+ optional: external_exports.boolean(),
15355
+ placeholder: external_exports.string().optional(),
15356
+ prefill: external_exports.string().optional()
15357
+ })
15358
+ ]);
15359
+ var threadQuestionSchema = external_exports.object({
15360
+ interactionId: external_exports.string().min(1),
15361
+ turnId: external_exports.string().min(1),
15362
+ title: external_exports.string().optional(),
15363
+ questions: external_exports.array(field).min(1)
15364
+ }).refine(({ questions }) => questions.some((q) => q.type === "choice" && q.multiple), {
15365
+ message: "Shared cards require at least one multi-select question"
15366
+ });
15367
+ var threadQuestionsListParamsSchema = external_exports.strictObject({ threadId: external_exports.string().min(1) });
15368
+ var threadQuestionsResultSchema = external_exports.object({ questions: external_exports.array(threadQuestionSchema) });
15369
+ var threadQuestionRespondParamsSchema = external_exports.strictObject({
15370
+ threadId: external_exports.string().min(1),
15371
+ turnId: external_exports.string().min(1),
15372
+ interactionId: external_exports.string().min(1),
15373
+ answers: external_exports.record(external_exports.string(), external_exports.array(external_exports.string())),
15374
+ cancelled: external_exports.boolean().default(false)
15375
+ });
15376
+ var threadQuestionRespondResultSchema = external_exports.object({ accepted: external_exports.literal(true) });
15377
+
15333
15378
  // ../../shared-contracts/dist/console.js
15334
15379
  var consoleAnnouncementSchema = external_exports.strictObject({
15335
15380
  title: external_exports.string().trim().min(1).max(200),
@@ -16663,26 +16708,26 @@ function parseHostUsage(value) {
16663
16708
  }
16664
16709
  }
16665
16710
  const indicators = value.composerIndicators === void 0 ? {} : { composerIndicators: composerIndicatorsSchema.parse(value.composerIndicators) };
16666
- for (const field of [
16711
+ for (const field2 of [
16667
16712
  "totalCredits",
16668
16713
  "contextUsagePercent",
16669
16714
  "apiOutputTokensPerSecond"
16670
16715
  ]) {
16671
- const candidate2 = value[field];
16716
+ const candidate2 = value[field2];
16672
16717
  if (candidate2 !== void 0 && (typeof candidate2 !== "number" || !Number.isFinite(candidate2) || candidate2 < 0)) {
16673
- throw new Error(`Harness Usage '${field}' must be a finite non-negative number`);
16718
+ throw new Error(`Harness Usage '${field2}' must be a finite non-negative number`);
16674
16719
  }
16675
16720
  }
16676
- for (const field of tokenFields) {
16677
- const candidate2 = value[field];
16721
+ for (const field2 of tokenFields) {
16722
+ const candidate2 = value[field2];
16678
16723
  if (candidate2 !== void 0 && (typeof candidate2 !== "number" || !Number.isSafeInteger(candidate2) || candidate2 < 0)) {
16679
- throw new Error(`Harness Usage '${field}' must be a non-negative safe integer`);
16724
+ throw new Error(`Harness Usage '${field2}' must be a non-negative safe integer`);
16680
16725
  }
16681
16726
  }
16682
- for (const field of safeIntegerFields) {
16683
- const candidate2 = value[field];
16727
+ for (const field2 of safeIntegerFields) {
16728
+ const candidate2 = value[field2];
16684
16729
  if (candidate2 !== void 0 && (typeof candidate2 !== "number" || !Number.isSafeInteger(candidate2) || candidate2 < 0)) {
16685
- throw new Error(`Harness Usage '${field}' must be a non-negative safe integer`);
16730
+ throw new Error(`Harness Usage '${field2}' must be a non-negative safe integer`);
16686
16731
  }
16687
16732
  }
16688
16733
  if (value.outputTokensPerSecond !== void 0 && (typeof value.outputTokensPerSecond !== "number" || !Number.isFinite(value.outputTokensPerSecond) || value.outputTokensPerSecond < 0)) {
@@ -16691,10 +16736,10 @@ function parseHostUsage(value) {
16691
16736
  if (value.totalCostUsd !== void 0 && (typeof value.totalCostUsd !== "number" || !Number.isFinite(value.totalCostUsd) || value.totalCostUsd < 0)) {
16692
16737
  throw new Error("Harness Usage 'totalCostUsd' must be a finite non-negative number");
16693
16738
  }
16694
- for (const field of percentFields) {
16695
- const candidate2 = value[field];
16739
+ for (const field2 of percentFields) {
16740
+ const candidate2 = value[field2];
16696
16741
  if (candidate2 !== void 0 && (typeof candidate2 !== "number" || !Number.isFinite(candidate2) || candidate2 < 0 || candidate2 > 100)) {
16697
- throw new Error(`Harness Usage '${field}' must be between 0 and 100`);
16742
+ throw new Error(`Harness Usage '${field2}' must be between 0 and 100`);
16698
16743
  }
16699
16744
  }
16700
16745
  if (value.sessionCacheUsage !== void 0) {
@@ -16765,19 +16810,19 @@ function parseHostUsageRequest(value) {
16765
16810
  if (typeof value.requestId !== "string" || value.requestId.length === 0) {
16766
16811
  throw new Error("Harness Usage request 'requestId' must be a non-empty string");
16767
16812
  }
16768
- for (const field of ["model", "provider"]) {
16769
- const candidate2 = value[field];
16813
+ for (const field2 of ["model", "provider"]) {
16814
+ const candidate2 = value[field2];
16770
16815
  if (candidate2 !== void 0 && (typeof candidate2 !== "string" || candidate2.length === 0)) {
16771
- throw new Error(`Harness Usage request '${field}' must be a non-empty string`);
16816
+ throw new Error(`Harness Usage request '${field2}' must be a non-empty string`);
16772
16817
  }
16773
16818
  }
16774
16819
  if (value.historical !== void 0 && typeof value.historical !== "boolean") {
16775
16820
  throw new Error("Harness Usage request 'historical' must be a boolean");
16776
16821
  }
16777
- for (const field of requestTokenFields) {
16778
- const candidate2 = value[field];
16822
+ for (const field2 of requestTokenFields) {
16823
+ const candidate2 = value[field2];
16779
16824
  if (candidate2 !== void 0 && (typeof candidate2 !== "number" || !Number.isSafeInteger(candidate2) || candidate2 < 0)) {
16780
- throw new Error(`Harness Usage request '${field}' must be a non-negative safe integer`);
16825
+ throw new Error(`Harness Usage request '${field2}' must be a non-negative safe integer`);
16781
16826
  }
16782
16827
  }
16783
16828
  if (value.inputTokens === void 0 || value.outputTokens === void 0) {
@@ -18171,24 +18216,24 @@ var buildClientParams = (args, fields) => {
18171
18216
  }
18172
18217
  if ("in" in config2) {
18173
18218
  if (config2.key) {
18174
- const field = map2.get(config2.key);
18175
- const name = field.map || config2.key;
18176
- if (field.in) {
18219
+ const field2 = map2.get(config2.key);
18220
+ const name = field2.map || config2.key;
18221
+ if (field2.in) {
18177
18222
  ;
18178
- params[field.in][name] = arg;
18223
+ params[field2.in][name] = arg;
18179
18224
  }
18180
18225
  } else {
18181
18226
  params.body = arg;
18182
18227
  }
18183
18228
  } else {
18184
18229
  for (const [key, value] of Object.entries(arg ?? {})) {
18185
- const field = map2.get(key);
18186
- if (field) {
18187
- if (field.in) {
18188
- const name = field.map || key;
18189
- params[field.in][name] = value;
18230
+ const field2 = map2.get(key);
18231
+ if (field2) {
18232
+ if (field2.in) {
18233
+ const name = field2.map || key;
18234
+ params[field2.in][name] = value;
18190
18235
  } else {
18191
- params[field.map] = value;
18236
+ params[field2.map] = value;
18192
18237
  }
18193
18238
  } else {
18194
18239
  const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix));
@@ -24321,8 +24366,8 @@ var OpenCodeHarnessSession = class {
24321
24366
  this.#event({ type: "item.started", turnId: active.turnId, item });
24322
24367
  }
24323
24368
  }
24324
- #appendPartDelta(active, partID, field, delta) {
24325
- if (field !== "text" || !delta)
24369
+ #appendPartDelta(active, partID, field2, delta) {
24370
+ if (field2 !== "text" || !delta)
24326
24371
  return;
24327
24372
  const existing = active.items.get(partID);
24328
24373
  if (!existing)
@@ -27317,16 +27362,16 @@ function permissionInteraction(request, turnId) {
27317
27362
  };
27318
27363
  }
27319
27364
  function formInteraction(form, turnId) {
27320
- const questions = form.fields.map((field) => {
27321
- if (field.type === "external" || field.hidden || field.when?.length) {
27365
+ const questions = form.fields.map((field2) => {
27366
+ if (field2.type === "external" || field2.hidden || field2.when?.length) {
27322
27367
  throw new Error("OpenCode v2 external, hidden or conditional form fields require its native UI");
27323
27368
  }
27324
27369
  const base = {
27325
- id: field.key,
27326
- prompt: [field.title, field.description].filter(Boolean).join("\n") || field.key,
27327
- optional: !field.required
27370
+ id: field2.key,
27371
+ prompt: [field2.title, field2.description].filter(Boolean).join("\n") || field2.key,
27372
+ optional: !field2.required
27328
27373
  };
27329
- if (field.type === "boolean")
27374
+ if (field2.type === "boolean")
27330
27375
  return {
27331
27376
  ...base,
27332
27377
  type: "choice",
@@ -27337,22 +27382,22 @@ function formInteraction(form, turnId) {
27337
27382
  { value: "false", label: "No" }
27338
27383
  ]
27339
27384
  };
27340
- if (field.type === "multiselect" || field.type === "string" && field.options?.length) {
27385
+ if (field2.type === "multiselect" || field2.type === "string" && field2.options?.length) {
27341
27386
  return {
27342
27387
  ...base,
27343
27388
  type: "choice",
27344
- multiple: field.type === "multiselect",
27345
- allowOther: field.custom ?? false,
27346
- options: field.options ?? []
27389
+ multiple: field2.type === "multiselect",
27390
+ allowOther: field2.custom ?? false,
27391
+ options: field2.options ?? []
27347
27392
  };
27348
27393
  }
27349
27394
  return {
27350
27395
  ...base,
27351
27396
  type: "text",
27352
- multiline: field.type === "string",
27397
+ multiline: field2.type === "string",
27353
27398
  secret: false,
27354
- ...field.type === "string" && field.placeholder ? { placeholder: field.placeholder } : {},
27355
- ...field.default !== void 0 ? { prefill: String(field.default) } : {}
27399
+ ...field2.type === "string" && field2.placeholder ? { placeholder: field2.placeholder } : {},
27400
+ ...field2.default !== void 0 ? { prefill: String(field2.default) } : {}
27356
27401
  };
27357
27402
  });
27358
27403
  return {
@@ -27395,24 +27440,24 @@ async function replyInteraction(client2, pending, command) {
27395
27440
  return;
27396
27441
  }
27397
27442
  const answer = {};
27398
- for (const field of form.fields) {
27399
- const values = command.response.answers[field.key] ?? [];
27443
+ for (const field2 of form.fields) {
27444
+ const values = command.response.answers[field2.key] ?? [];
27400
27445
  if (!values.length)
27401
27446
  continue;
27402
27447
  const value = values[0];
27403
27448
  if (value === void 0)
27404
27449
  continue;
27405
- if (field.type === "multiselect")
27406
- answer[field.key] = values;
27407
- else if (field.type === "boolean")
27408
- answer[field.key] = value === "true";
27409
- else if (field.type === "number" || field.type === "integer") {
27450
+ if (field2.type === "multiselect")
27451
+ answer[field2.key] = values;
27452
+ else if (field2.type === "boolean")
27453
+ answer[field2.key] = value === "true";
27454
+ else if (field2.type === "number" || field2.type === "integer") {
27410
27455
  const number4 = Number(value);
27411
- if (!value.trim() || !Number.isFinite(number4) || field.type === "integer" && !Number.isInteger(number4))
27412
- throw new Error(`Invalid number for ${field.key}`);
27413
- answer[field.key] = number4;
27456
+ if (!value.trim() || !Number.isFinite(number4) || field2.type === "integer" && !Number.isInteger(number4))
27457
+ throw new Error(`Invalid number for ${field2.key}`);
27458
+ answer[field2.key] = number4;
27414
27459
  } else
27415
- answer[field.key] = value;
27460
+ answer[field2.key] = value;
27416
27461
  }
27417
27462
  await client2.session.form.reply({ sessionID: form.sessionID, formID: form.id, answer });
27418
27463
  }
@@ -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
  }
@@ -15330,6 +15330,51 @@ var hostInteractionIdSchema = opaqueIdSchema.brand();
15330
15330
  var threadPrewarmDiscardParamsSchema = external_exports.object({ threadId: hostThreadIdSchema });
15331
15331
  var threadPrewarmDiscardResultSchema = external_exports.object({ discarded: external_exports.boolean() });
15332
15332
 
15333
+ // ../../shared-contracts/dist/thread-questions.js
15334
+ var field = external_exports.discriminatedUnion("type", [
15335
+ external_exports.object({
15336
+ id: external_exports.string().min(1),
15337
+ type: external_exports.literal("choice"),
15338
+ prompt: external_exports.string(),
15339
+ options: external_exports.array(external_exports.object({
15340
+ value: external_exports.string().min(1),
15341
+ label: external_exports.string(),
15342
+ description: external_exports.string().optional()
15343
+ })).min(1),
15344
+ multiple: external_exports.boolean(),
15345
+ allowOther: external_exports.boolean(),
15346
+ optional: external_exports.boolean()
15347
+ }),
15348
+ external_exports.object({
15349
+ id: external_exports.string().min(1),
15350
+ type: external_exports.literal("text"),
15351
+ prompt: external_exports.string(),
15352
+ multiline: external_exports.boolean(),
15353
+ secret: external_exports.literal(false),
15354
+ optional: external_exports.boolean(),
15355
+ placeholder: external_exports.string().optional(),
15356
+ prefill: external_exports.string().optional()
15357
+ })
15358
+ ]);
15359
+ var threadQuestionSchema = external_exports.object({
15360
+ interactionId: external_exports.string().min(1),
15361
+ turnId: external_exports.string().min(1),
15362
+ title: external_exports.string().optional(),
15363
+ questions: external_exports.array(field).min(1)
15364
+ }).refine(({ questions }) => questions.some((q) => q.type === "choice" && q.multiple), {
15365
+ message: "Shared cards require at least one multi-select question"
15366
+ });
15367
+ var threadQuestionsListParamsSchema = external_exports.strictObject({ threadId: external_exports.string().min(1) });
15368
+ var threadQuestionsResultSchema = external_exports.object({ questions: external_exports.array(threadQuestionSchema) });
15369
+ var threadQuestionRespondParamsSchema = external_exports.strictObject({
15370
+ threadId: external_exports.string().min(1),
15371
+ turnId: external_exports.string().min(1),
15372
+ interactionId: external_exports.string().min(1),
15373
+ answers: external_exports.record(external_exports.string(), external_exports.array(external_exports.string())),
15374
+ cancelled: external_exports.boolean().default(false)
15375
+ });
15376
+ var threadQuestionRespondResultSchema = external_exports.object({ accepted: external_exports.literal(true) });
15377
+
15333
15378
  // ../../shared-contracts/dist/console.js
15334
15379
  var consoleAnnouncementSchema = external_exports.strictObject({
15335
15380
  title: external_exports.string().trim().min(1).max(200),
@@ -16963,26 +17008,26 @@ function parseHostUsage(value) {
16963
17008
  }
16964
17009
  }
16965
17010
  const indicators = value.composerIndicators === void 0 ? {} : { composerIndicators: composerIndicatorsSchema.parse(value.composerIndicators) };
16966
- for (const field of [
17011
+ for (const field2 of [
16967
17012
  "totalCredits",
16968
17013
  "contextUsagePercent",
16969
17014
  "apiOutputTokensPerSecond"
16970
17015
  ]) {
16971
- const candidate = value[field];
17016
+ const candidate = value[field2];
16972
17017
  if (candidate !== void 0 && (typeof candidate !== "number" || !Number.isFinite(candidate) || candidate < 0)) {
16973
- throw new Error(`Harness Usage '${field}' must be a finite non-negative number`);
17018
+ throw new Error(`Harness Usage '${field2}' must be a finite non-negative number`);
16974
17019
  }
16975
17020
  }
16976
- for (const field of tokenFields) {
16977
- const candidate = value[field];
17021
+ for (const field2 of tokenFields) {
17022
+ const candidate = value[field2];
16978
17023
  if (candidate !== void 0 && (typeof candidate !== "number" || !Number.isSafeInteger(candidate) || candidate < 0)) {
16979
- throw new Error(`Harness Usage '${field}' must be a non-negative safe integer`);
17024
+ throw new Error(`Harness Usage '${field2}' must be a non-negative safe integer`);
16980
17025
  }
16981
17026
  }
16982
- for (const field of safeIntegerFields) {
16983
- const candidate = value[field];
17027
+ for (const field2 of safeIntegerFields) {
17028
+ const candidate = value[field2];
16984
17029
  if (candidate !== void 0 && (typeof candidate !== "number" || !Number.isSafeInteger(candidate) || candidate < 0)) {
16985
- throw new Error(`Harness Usage '${field}' must be a non-negative safe integer`);
17030
+ throw new Error(`Harness Usage '${field2}' must be a non-negative safe integer`);
16986
17031
  }
16987
17032
  }
16988
17033
  if (value.outputTokensPerSecond !== void 0 && (typeof value.outputTokensPerSecond !== "number" || !Number.isFinite(value.outputTokensPerSecond) || value.outputTokensPerSecond < 0)) {
@@ -16991,10 +17036,10 @@ function parseHostUsage(value) {
16991
17036
  if (value.totalCostUsd !== void 0 && (typeof value.totalCostUsd !== "number" || !Number.isFinite(value.totalCostUsd) || value.totalCostUsd < 0)) {
16992
17037
  throw new Error("Harness Usage 'totalCostUsd' must be a finite non-negative number");
16993
17038
  }
16994
- for (const field of percentFields) {
16995
- const candidate = value[field];
17039
+ for (const field2 of percentFields) {
17040
+ const candidate = value[field2];
16996
17041
  if (candidate !== void 0 && (typeof candidate !== "number" || !Number.isFinite(candidate) || candidate < 0 || candidate > 100)) {
16997
- throw new Error(`Harness Usage '${field}' must be between 0 and 100`);
17042
+ throw new Error(`Harness Usage '${field2}' must be between 0 and 100`);
16998
17043
  }
16999
17044
  }
17000
17045
  if (value.sessionCacheUsage !== void 0) {
@@ -17065,19 +17110,19 @@ function parseHostUsageRequest(value) {
17065
17110
  if (typeof value.requestId !== "string" || value.requestId.length === 0) {
17066
17111
  throw new Error("Harness Usage request 'requestId' must be a non-empty string");
17067
17112
  }
17068
- for (const field of ["model", "provider"]) {
17069
- const candidate = value[field];
17113
+ for (const field2 of ["model", "provider"]) {
17114
+ const candidate = value[field2];
17070
17115
  if (candidate !== void 0 && (typeof candidate !== "string" || candidate.length === 0)) {
17071
- throw new Error(`Harness Usage request '${field}' must be a non-empty string`);
17116
+ throw new Error(`Harness Usage request '${field2}' must be a non-empty string`);
17072
17117
  }
17073
17118
  }
17074
17119
  if (value.historical !== void 0 && typeof value.historical !== "boolean") {
17075
17120
  throw new Error("Harness Usage request 'historical' must be a boolean");
17076
17121
  }
17077
- for (const field of requestTokenFields) {
17078
- const candidate = value[field];
17122
+ for (const field2 of requestTokenFields) {
17123
+ const candidate = value[field2];
17079
17124
  if (candidate !== void 0 && (typeof candidate !== "number" || !Number.isSafeInteger(candidate) || candidate < 0)) {
17080
- throw new Error(`Harness Usage request '${field}' must be a non-negative safe integer`);
17125
+ throw new Error(`Harness Usage request '${field2}' must be a non-negative safe integer`);
17081
17126
  }
17082
17127
  }
17083
17128
  if (value.inputTokens === void 0 || value.outputTokens === void 0) {
@@ -17804,9 +17849,9 @@ function nestedToolString(value, keys, allowEmpty = false) {
17804
17849
  if (!isRecord3(value))
17805
17850
  return void 0;
17806
17851
  for (const key of keys) {
17807
- const field = value[key];
17808
- if (typeof field === "string" && (allowEmpty || field.length > 0))
17809
- return field;
17852
+ const field2 = value[key];
17853
+ if (typeof field2 === "string" && (allowEmpty || field2.length > 0))
17854
+ return field2;
17810
17855
  }
17811
17856
  for (const wrapper of ["input", "arguments", "params", "details"]) {
17812
17857
  const nested = nestedToolString(value[wrapper], keys, allowEmpty);
@@ -17819,15 +17864,15 @@ function patchFromResult(result) {
17819
17864
  if (!isRecord3(result))
17820
17865
  return void 0;
17821
17866
  for (const key of ["patch", "diff", "unifiedDiff"]) {
17822
- const field = result[key];
17823
- if (typeof field === "string" && field.length > 0)
17824
- return field;
17867
+ const field2 = result[key];
17868
+ if (typeof field2 === "string" && field2.length > 0)
17869
+ return field2;
17825
17870
  }
17826
17871
  if (isRecord3(result.details)) {
17827
17872
  for (const key of ["patch", "diff", "unifiedDiff"]) {
17828
- const field = result.details[key];
17829
- if (typeof field === "string" && field.length > 0)
17830
- return field;
17873
+ const field2 = result.details[key];
17874
+ if (typeof field2 === "string" && field2.length > 0)
17875
+ return field2;
17831
17876
  }
17832
17877
  }
17833
17878
  return void 0;
@@ -18321,8 +18366,8 @@ function parsePiSubagentInspection(value) {
18321
18366
  return null;
18322
18367
  if (parsed.error !== void 0 && (!record3(parsed.error) || typeof parsed.error.code !== "string" || typeof parsed.error.message !== "string"))
18323
18368
  return null;
18324
- for (const field of ["asyncId", "childId", "status", "task", "finalOutput"]) {
18325
- if (parsed[field] !== void 0 && typeof parsed[field] !== "string")
18369
+ for (const field2 of ["asyncId", "childId", "status", "task", "finalOutput"]) {
18370
+ if (parsed[field2] !== void 0 && typeof parsed[field2] !== "string")
18326
18371
  return null;
18327
18372
  }
18328
18373
  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")))
@@ -20153,6 +20198,15 @@ var PiRpcUnsupportedCommandError = class extends Error {
20153
20198
  this.name = "PiRpcUnsupportedCommandError";
20154
20199
  }
20155
20200
  };
20201
+ var READ_ONLY_COMMANDS = /* @__PURE__ */ new Set([
20202
+ "get_state",
20203
+ "get_commands",
20204
+ "get_entries",
20205
+ "get_session_stats",
20206
+ "get_available_models",
20207
+ "get_available_thinking_levels"
20208
+ ]);
20209
+ var MAX_EXPIRED_IDS = 64;
20156
20210
  var textDecoder = new TextDecoder("utf-8", { fatal: true });
20157
20211
  function isRecord8(value) {
20158
20212
  return typeof value === "object" && value !== null && !Array.isArray(value);
@@ -20375,7 +20429,11 @@ var PiRpcSession = class {
20375
20429
  #autonomousTurnHandler = null;
20376
20430
  #usageHandler = null;
20377
20431
  #usageRequestStartedAtMs = null;
20378
- #buffer = Buffer.alloc(0);
20432
+ // Pieces of the unterminated frame; joined once at its newline so a large frame (a long
20433
+ // Session's get_entries) costs linear rather than quadratic copying on the Host event loop.
20434
+ #buffer = [];
20435
+ // Ids whose read-only command timed out; Pi may still answer them late.
20436
+ #expired = /* @__PURE__ */ new Set();
20379
20437
  #child = null;
20380
20438
  #closed = false;
20381
20439
  #closePromise = null;
@@ -20788,11 +20846,13 @@ var PiRpcSession = class {
20788
20846
  }
20789
20847
  }
20790
20848
  #push(chunk) {
20791
- this.#buffer = this.#buffer.length === 0 ? chunk : Buffer.concat([this.#buffer, chunk]);
20792
- let newline = this.#buffer.indexOf(10);
20849
+ let rest = chunk;
20850
+ let newline = rest.indexOf(10);
20793
20851
  while (newline >= 0) {
20794
- const frame = this.#buffer.subarray(0, newline);
20795
- this.#buffer = this.#buffer.subarray(newline + 1);
20852
+ const tail = rest.subarray(0, newline);
20853
+ const frame = this.#buffer.length === 0 ? tail : Buffer.concat([...this.#buffer, tail]);
20854
+ this.#buffer = [];
20855
+ rest = rest.subarray(newline + 1);
20796
20856
  try {
20797
20857
  const value = JSON.parse(textDecoder.decode(frame));
20798
20858
  if (!isRecord8(value) || typeof value.type !== "string") {
@@ -20802,8 +20862,10 @@ var PiRpcSession = class {
20802
20862
  } catch (error51) {
20803
20863
  this.#fail(error51 instanceof PiRpcFaultError ? error51 : new PiRpcFaultError("protocolError", `Pi RPC returned invalid JSONL: ${message2(error51)}`));
20804
20864
  }
20805
- newline = this.#buffer.indexOf(10);
20865
+ newline = rest.indexOf(10);
20806
20866
  }
20867
+ if (rest.length !== 0)
20868
+ this.#buffer.push(rest);
20807
20869
  }
20808
20870
  #handle(value) {
20809
20871
  if (value.type === "extension_ui_request" && value.method === "notify" && typeof value.message === "string" && value.message.startsWith(PI_FAST_ACK)) {
@@ -21055,6 +21117,8 @@ var PiRpcSession = class {
21055
21117
  return;
21056
21118
  }
21057
21119
  const pending = this.#pending.get(id);
21120
+ if (!pending && this.#expired.delete(id))
21121
+ return;
21058
21122
  if (!pending) {
21059
21123
  this.#fail(new PiRpcFaultError("protocolError", "Pi RPC response id is not pending"));
21060
21124
  return;
@@ -21289,6 +21353,12 @@ var PiRpcSession = class {
21289
21353
  const error51 = new Error(`Pi RPC '${pending.command}' command timed out`);
21290
21354
  if (pending.command !== "prompt") {
21291
21355
  this.#pending.delete(id);
21356
+ if (READ_ONLY_COMMANDS.has(pending.command)) {
21357
+ this.#expired.add(id);
21358
+ if (this.#expired.size > MAX_EXPIRED_IDS) {
21359
+ this.#expired.delete(this.#expired.values().next().value);
21360
+ }
21361
+ }
21292
21362
  pending.reject(error51);
21293
21363
  return;
21294
21364
  }
@@ -21491,9 +21561,9 @@ function outputText(output) {
21491
21561
  function stringField(value, key) {
21492
21562
  if (!isRecord9(value))
21493
21563
  return void 0;
21494
- const field = value[key];
21495
- if (typeof field === "string" && field.length > 0)
21496
- return field;
21564
+ const field2 = value[key];
21565
+ if (typeof field2 === "string" && field2.length > 0)
21566
+ return field2;
21497
21567
  if (isRecord9(value.input)) {
21498
21568
  const nested = value.input[key];
21499
21569
  if (typeof nested === "string" && nested.length > 0)
@@ -21509,8 +21579,8 @@ function stringField(value, key) {
21509
21579
  function numberField(value, key) {
21510
21580
  if (!isRecord9(value))
21511
21581
  return void 0;
21512
- const field = value[key];
21513
- return typeof field === "number" || field === null ? field : void 0;
21582
+ const field2 = value[key];
21583
+ return typeof field2 === "number" || field2 === null ? field2 : void 0;
21514
21584
  }
21515
21585
  function normalizeToolName(name) {
21516
21586
  const lower = name.toLowerCase();