@pentoshi/clai 4.11.2 → 4.11.4

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.
Files changed (101) hide show
  1. package/dist/agent/runner.js +37 -6
  2. package/dist/agent/runner.js.map +1 -1
  3. package/dist/agent/tool-history.js +4 -2
  4. package/dist/agent/tool-history.js.map +1 -1
  5. package/dist/app/controllers/session-prompt-queue.d.ts +6 -7
  6. package/dist/app/controllers/session-prompt-queue.js +80 -85
  7. package/dist/app/controllers/session-prompt-queue.js.map +1 -1
  8. package/dist/app/controllers/turn-continuation.js +3 -0
  9. package/dist/app/controllers/turn-continuation.js.map +1 -1
  10. package/dist/classic/input/terminal-sequences.d.ts +1 -3
  11. package/dist/classic/input/terminal-sequences.js +1 -3
  12. package/dist/classic/input/terminal-sequences.js.map +1 -1
  13. package/dist/llm/token-estimate-calibration.d.ts +0 -1
  14. package/dist/llm/token-estimate-calibration.js +3 -3
  15. package/dist/llm/token-estimate-calibration.js.map +1 -1
  16. package/dist/llm/tool-protocol.d.ts +1 -0
  17. package/dist/llm/tool-protocol.js +29 -7
  18. package/dist/llm/tool-protocol.js.map +1 -1
  19. package/dist/prompts/embedded.js +1 -1
  20. package/dist/prompts/embedded.js.map +1 -1
  21. package/dist/prompts/system.agent.md +7 -7
  22. package/dist/session-runtime/binding.d.ts +1 -1
  23. package/dist/session-runtime/binding.js +3 -1
  24. package/dist/session-runtime/binding.js.map +1 -1
  25. package/dist/session-runtime/child-bridge.d.ts +7 -2
  26. package/dist/session-runtime/child-bridge.js +55 -4
  27. package/dist/session-runtime/child-bridge.js.map +1 -1
  28. package/dist/session-runtime/client.d.ts +5 -0
  29. package/dist/session-runtime/client.js +13 -5
  30. package/dist/session-runtime/client.js.map +1 -1
  31. package/dist/session-runtime/host.d.ts +7 -0
  32. package/dist/session-runtime/host.js +112 -19
  33. package/dist/session-runtime/host.js.map +1 -1
  34. package/dist/session-runtime/types.d.ts +10 -0
  35. package/dist/tools/definitions.js +2 -2
  36. package/dist/tools/definitions.js.map +1 -1
  37. package/dist/tools/fs.d.ts +0 -5
  38. package/dist/tools/fs.js +363 -272
  39. package/dist/tools/fs.js.map +1 -1
  40. package/dist/tools/shell.d.ts +5 -2
  41. package/dist/tools/shell.js +313 -20
  42. package/dist/tools/shell.js.map +1 -1
  43. package/dist/tui-v2/app/App.js +67 -61
  44. package/dist/tui-v2/app/App.js.map +1 -1
  45. package/dist/tui-v2/app/layout-widths.d.ts +21 -0
  46. package/dist/tui-v2/app/layout-widths.js +50 -0
  47. package/dist/tui-v2/app/layout-widths.js.map +1 -0
  48. package/dist/tui-v2/bootstrap/resize-repaint.d.ts +8 -1
  49. package/dist/tui-v2/bootstrap/resize-repaint.js +8 -0
  50. package/dist/tui-v2/bootstrap/resize-repaint.js.map +1 -1
  51. package/dist/tui-v2/bootstrap/start-tui-v2.js +22 -7
  52. package/dist/tui-v2/bootstrap/start-tui-v2.js.map +1 -1
  53. package/dist/tui-v2/components/modal/secret-modal.js +10 -10
  54. package/dist/tui-v2/components/modal/secret-modal.js.map +1 -1
  55. package/dist/tui-v2/components/pager/pager.js +6 -1
  56. package/dist/tui-v2/components/pager/pager.js.map +1 -1
  57. package/dist/tui-v2/components/transcript/assistant-message.d.ts +2 -0
  58. package/dist/tui-v2/components/transcript/assistant-message.js +4 -2
  59. package/dist/tui-v2/components/transcript/assistant-message.js.map +1 -1
  60. package/dist/tui-v2/components/transcript/compacted-row.js +4 -1
  61. package/dist/tui-v2/components/transcript/compacted-row.js.map +1 -1
  62. package/dist/tui-v2/components/transcript/tool-card.js +4 -1
  63. package/dist/tui-v2/components/transcript/tool-card.js.map +1 -1
  64. package/dist/tui-v2/components/transcript/transcript-row.js +1 -1
  65. package/dist/tui-v2/components/transcript/transcript-row.js.map +1 -1
  66. package/dist/tui-v2/input/chord-from-opentui-key.d.ts +6 -0
  67. package/dist/tui-v2/input/chord-from-opentui-key.js +32 -6
  68. package/dist/tui-v2/input/chord-from-opentui-key.js.map +1 -1
  69. package/dist/tui-v2/input/escape-cancellation.d.ts +7 -0
  70. package/dist/tui-v2/input/escape-cancellation.js +11 -0
  71. package/dist/tui-v2/input/escape-cancellation.js.map +1 -0
  72. package/dist/tui-v2/rendering/pager-markdown.d.ts +4 -0
  73. package/dist/tui-v2/rendering/pager-markdown.js +2 -0
  74. package/dist/tui-v2/rendering/pager-markdown.js.map +1 -1
  75. package/dist/ui-core/actions/cancel-timing.d.ts +6 -0
  76. package/dist/ui-core/actions/cancel-timing.js +7 -0
  77. package/dist/ui-core/actions/cancel-timing.js.map +1 -0
  78. package/dist/ui-core/actions/chord.d.ts +4 -0
  79. package/dist/ui-core/actions/chord.js.map +1 -1
  80. package/dist/ui-core/bootstrap/capabilities.d.ts +6 -0
  81. package/dist/ui-core/bootstrap/capabilities.js +51 -4
  82. package/dist/ui-core/bootstrap/capabilities.js.map +1 -1
  83. package/dist/ui-core/react/use-session-state.d.ts +9 -2
  84. package/dist/ui-core/react/use-session-state.js +35 -4
  85. package/dist/ui-core/react/use-session-state.js.map +1 -1
  86. package/dist/ui-core/rendering/code-block.d.ts +10 -5
  87. package/dist/ui-core/rendering/code-block.js +68 -40
  88. package/dist/ui-core/rendering/code-block.js.map +1 -1
  89. package/dist/ui-core/rendering/markdown.d.ts +6 -3
  90. package/dist/ui-core/rendering/markdown.js +92 -71
  91. package/dist/ui-core/rendering/markdown.js.map +1 -1
  92. package/dist/ui-core/rendering/render-markdown-lines.d.ts +4 -0
  93. package/dist/ui-core/rendering/render-markdown-lines.js +4 -1
  94. package/dist/ui-core/rendering/render-markdown-lines.js.map +1 -1
  95. package/dist/ui-core/rendering/streaming-markdown.js +14 -1
  96. package/dist/ui-core/rendering/streaming-markdown.js.map +1 -1
  97. package/dist/ui-core/rendering/tool-presenter.js +6 -2
  98. package/dist/ui-core/rendering/tool-presenter.js.map +1 -1
  99. package/dist/version.generated.d.ts +2 -2
  100. package/dist/version.generated.js +2 -2
  101. package/package.json +1 -1
@@ -986,6 +986,7 @@ export async function runAgentTurn(prompt, options = {}) {
986
986
  // provider's reported prompt size below so the estimator learns this route's
987
987
  // bias instead of permanently over-reporting it.
988
988
  let dispatchedRawRequestTokens = 0;
989
+ let dispatchedRequestRoute;
989
990
  let consecutiveSynthesizedRounds = 0;
990
991
  const engagementPolicy = new EngagementPolicyEngine();
991
992
  const probeStateKey = (call) => {
@@ -3011,6 +3012,11 @@ export async function runAgentTurn(prompt, options = {}) {
3011
3012
  }
3012
3013
  async function maybeAutoCompact(reason, force = false) {
3013
3014
  const beforeTokens = estimateNextRequestTokens(messages);
3015
+ emit({
3016
+ type: "context-estimate",
3017
+ estimatedTokens: beforeTokens,
3018
+ model,
3019
+ });
3014
3020
  const contextLimitTokens = currentContextLimitTokens();
3015
3021
  const compactTrigger = autoCompactTriggerTokens(getReliabilityPolicy(), {
3016
3022
  provider,
@@ -3351,6 +3357,7 @@ export async function runAgentTurn(prompt, options = {}) {
3351
3357
  ...(contextLimitTokens !== undefined ? { contextLimitTokens } : {}),
3352
3358
  }).accounting;
3353
3359
  dispatchedRawRequestTokens = finalAccounting.rawRequestTokens;
3360
+ dispatchedRequestRoute = { provider, model };
3354
3361
  // The chip reports the request that is actually about to be sent, from
3355
3362
  // the same accounting the fit gate and the compaction card use, so the
3356
3363
  // three can never disagree.
@@ -3665,7 +3672,11 @@ export async function runAgentTurn(prompt, options = {}) {
3665
3672
  provider = completion.provider;
3666
3673
  model = completion.model;
3667
3674
  if (completion.usage) {
3668
- if (completion.usage.exact && completion.usage.promptTokens > 0) {
3675
+ const requestRouteMatched = dispatchedRequestRoute?.provider === completion.provider &&
3676
+ dispatchedRequestRoute.model === completion.model;
3677
+ if (completion.usage.exact &&
3678
+ completion.usage.promptTokens > 0 &&
3679
+ requestRouteMatched) {
3669
3680
  recordRequestTokenObservation({
3670
3681
  provider: completion.provider,
3671
3682
  model: completion.model,
@@ -3865,7 +3876,30 @@ export async function runAgentTurn(prompt, options = {}) {
3865
3876
  // next turn is not orphaned, then nudge for append.
3866
3877
  const salvageHistoryCalls = ensureUniqueToolCallIds(nativeToolCalls, toolCallIdsInHistory(messages));
3867
3878
  const salvagedCallIndex = nativeToolCalls.indexOf(writeTc);
3879
+ const salvagedToolName = salvaged.operation === "append"
3880
+ ? "fs.append"
3881
+ : "fs.write";
3882
+ const salvagedHistoryArgs = {
3883
+ path: salvaged.path,
3884
+ content: salvaged.content,
3885
+ ...(salvaged.operation === "append"
3886
+ ? {
3887
+ position: "end",
3888
+ ...(typeof salvaged.expectedPriorBytes === "number"
3889
+ ? { expectedPriorBytes: salvaged.expectedPriorBytes }
3890
+ : {}),
3891
+ }
3892
+ : {}),
3893
+ };
3868
3894
  const salvagedCallId = salvageHistoryCalls[salvagedCallIndex]?.id ?? writeTc.id;
3895
+ if (salvagedCallIndex >= 0) {
3896
+ salvageHistoryCalls[salvagedCallIndex] = {
3897
+ id: salvagedCallId,
3898
+ name: salvagedToolName,
3899
+ args: salvagedHistoryArgs,
3900
+ rawArguments: JSON.stringify(salvagedHistoryArgs),
3901
+ };
3902
+ }
3869
3903
  appendAssistantWithTools(messages, assistantText.visible, salvageHistoryCalls, completion.reasoningBlock ??
3870
3904
  (assistantText.hasThinking && assistantText.thinkContent
3871
3905
  ? { text: assistantText.thinkContent }
@@ -3876,17 +3910,14 @@ export async function runAgentTurn(prompt, options = {}) {
3876
3910
  : `Tool ${tc.name} result (exit=1, ok=false):\nCancelled — sibling write was truncated and salvaged.`, tc.name, tc.id === salvagedCallId);
3877
3911
  }
3878
3912
  const priorBytes = writeResult.bytesOnDisk;
3879
- const salvagedToolName = salvaged.operation === "append"
3880
- ? "fs.append"
3881
- : "fs.write";
3882
3913
  const appendNudge = toolsAttached
3883
3914
  ? `Your ${salvagedToolName} tool call was cut off at the token limit, but the system salvaged the partial content and wrote ${lineCount} lines (file is now ${priorBytes} bytes) to ${salvaged.path}. ` +
3884
3915
  `The file ends with: ${JSON.stringify(salvaged.lastLine)}\n\n` +
3885
- `CONTINUE by calling fs.append now with path=${JSON.stringify(salvaged.path)}, expectedPriorBytes=${priorBytes}, and content set to ONLY the remaining content not already on disk (prefer hundreds of lines per call). ` +
3916
+ `CONTINUE by calling fs.append with path=${JSON.stringify(salvaged.path)}, expectedPriorBytes=${priorBytes}, and content set to ONLY the next remaining chunk not already on disk. Keep each chunk under 24,000 characters and wait for its receipt before sending another. ` +
3886
3917
  `Do not re-read the full file; do not re-send content already saved. Use the platform tool interface — no markdown fences.`
3887
3918
  : `Your ${salvagedToolName} tool call was cut off at the token limit, but the system salvaged the partial content and wrote ${lineCount} lines (file is now ${priorBytes} bytes) to ${salvaged.path}. ` +
3888
3919
  `The file ends with: ${JSON.stringify(salvaged.lastLine)}\n\n` +
3889
- `CONTINUE with ONE large fs.append of the remaining content:\n` +
3920
+ `CONTINUE with one fs.append chunk under 24,000 characters, then wait for its receipt before sending another:\n` +
3890
3921
  '```tool\n{"name":"fs.append","args":{"path":' +
3891
3922
  JSON.stringify(salvaged.path) +
3892
3923
  ',"expectedPriorBytes":' +