@fleetagent/pi-coding-agent 0.0.6 → 0.0.7

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 (153) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/cli/file-processor.d.ts.map +1 -1
  3. package/dist/cli/file-processor.js +2 -3
  4. package/dist/cli/file-processor.js.map +1 -1
  5. package/dist/config.d.ts.map +1 -1
  6. package/dist/config.js +15 -2
  7. package/dist/config.js.map +1 -1
  8. package/dist/core/agent-session.d.ts +9 -0
  9. package/dist/core/agent-session.d.ts.map +1 -1
  10. package/dist/core/agent-session.js +86 -15
  11. package/dist/core/agent-session.js.map +1 -1
  12. package/dist/core/export-html/template.js +6 -3
  13. package/dist/core/extensions/runner.d.ts +1 -1
  14. package/dist/core/extensions/runner.d.ts.map +1 -1
  15. package/dist/core/extensions/runner.js +8 -2
  16. package/dist/core/extensions/runner.js.map +1 -1
  17. package/dist/core/extensions/types.d.ts +4 -2
  18. package/dist/core/extensions/types.d.ts.map +1 -1
  19. package/dist/core/extensions/types.js.map +1 -1
  20. package/dist/core/model-registry.d.ts.map +1 -1
  21. package/dist/core/model-registry.js +65 -13
  22. package/dist/core/model-registry.js.map +1 -1
  23. package/dist/core/output-guard.d.ts +1 -0
  24. package/dist/core/output-guard.d.ts.map +1 -1
  25. package/dist/core/output-guard.js +52 -22
  26. package/dist/core/output-guard.js.map +1 -1
  27. package/dist/core/package-manager.d.ts.map +1 -1
  28. package/dist/core/package-manager.js +31 -12
  29. package/dist/core/package-manager.js.map +1 -1
  30. package/dist/core/pi-agent.d.ts.map +1 -1
  31. package/dist/core/pi-agent.js +12 -3
  32. package/dist/core/pi-agent.js.map +1 -1
  33. package/dist/core/resolve-config-value.d.ts +9 -1
  34. package/dist/core/resolve-config-value.d.ts.map +1 -1
  35. package/dist/core/resolve-config-value.js +134 -11
  36. package/dist/core/resolve-config-value.js.map +1 -1
  37. package/dist/core/session/jsonl-helpers.d.ts +2 -1
  38. package/dist/core/session/jsonl-helpers.d.ts.map +1 -1
  39. package/dist/core/session/jsonl-helpers.js +6 -3
  40. package/dist/core/session/jsonl-helpers.js.map +1 -1
  41. package/dist/core/session/local-session-manager.d.ts +1 -0
  42. package/dist/core/session/local-session-manager.d.ts.map +1 -1
  43. package/dist/core/session/local-session-manager.js +12 -4
  44. package/dist/core/session/local-session-manager.js.map +1 -1
  45. package/dist/core/session/session-manager.d.ts +1 -0
  46. package/dist/core/session/session-manager.d.ts.map +1 -1
  47. package/dist/core/session/session-manager.js.map +1 -1
  48. package/dist/core/session/stores/jsonl-session-store.d.ts +2 -1
  49. package/dist/core/session/stores/jsonl-session-store.d.ts.map +1 -1
  50. package/dist/core/session/stores/jsonl-session-store.js +105 -78
  51. package/dist/core/session/stores/jsonl-session-store.js.map +1 -1
  52. package/dist/core/settings-manager.d.ts +2 -0
  53. package/dist/core/settings-manager.d.ts.map +1 -1
  54. package/dist/core/settings-manager.js +14 -9
  55. package/dist/core/settings-manager.js.map +1 -1
  56. package/dist/core/tools/bash.d.ts.map +1 -1
  57. package/dist/core/tools/bash.js +73 -63
  58. package/dist/core/tools/bash.js.map +1 -1
  59. package/dist/core/tools/edit.d.ts.map +1 -1
  60. package/dist/core/tools/edit.js +45 -76
  61. package/dist/core/tools/edit.js.map +1 -1
  62. package/dist/core/tools/file-mutation-queue.d.ts.map +1 -1
  63. package/dist/core/tools/file-mutation-queue.js +27 -12
  64. package/dist/core/tools/file-mutation-queue.js.map +1 -1
  65. package/dist/core/tools/find.d.ts.map +1 -1
  66. package/dist/core/tools/find.js +11 -2
  67. package/dist/core/tools/find.js.map +1 -1
  68. package/dist/core/tools/grep.d.ts.map +1 -1
  69. package/dist/core/tools/grep.js +3 -3
  70. package/dist/core/tools/grep.js.map +1 -1
  71. package/dist/core/tools/ls.d.ts.map +1 -1
  72. package/dist/core/tools/ls.js +13 -4
  73. package/dist/core/tools/ls.js.map +1 -1
  74. package/dist/core/tools/path-utils.d.ts +1 -0
  75. package/dist/core/tools/path-utils.d.ts.map +1 -1
  76. package/dist/core/tools/path-utils.js +37 -0
  77. package/dist/core/tools/path-utils.js.map +1 -1
  78. package/dist/core/tools/read.d.ts.map +1 -1
  79. package/dist/core/tools/read.js +7 -6
  80. package/dist/core/tools/read.js.map +1 -1
  81. package/dist/core/tools/write.d.ts.map +1 -1
  82. package/dist/core/tools/write.js +24 -32
  83. package/dist/core/tools/write.js.map +1 -1
  84. package/dist/main.d.ts.map +1 -1
  85. package/dist/main.js +3 -2
  86. package/dist/main.js.map +1 -1
  87. package/dist/migrations.d.ts.map +1 -1
  88. package/dist/migrations.js +118 -1
  89. package/dist/migrations.js.map +1 -1
  90. package/dist/modes/interactive/components/footer.d.ts +1 -0
  91. package/dist/modes/interactive/components/footer.d.ts.map +1 -1
  92. package/dist/modes/interactive/components/footer.js +14 -5
  93. package/dist/modes/interactive/components/footer.js.map +1 -1
  94. package/dist/modes/interactive/components/user-message.d.ts.map +1 -1
  95. package/dist/modes/interactive/components/user-message.js +1 -1
  96. package/dist/modes/interactive/components/user-message.js.map +1 -1
  97. package/dist/modes/interactive/interactive-mode.d.ts +1 -0
  98. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  99. package/dist/modes/interactive/interactive-mode.js +30 -5
  100. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  101. package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
  102. package/dist/modes/interactive/theme/theme.js +10 -0
  103. package/dist/modes/interactive/theme/theme.js.map +1 -1
  104. package/dist/modes/rpc/rpc-client.d.ts +3 -0
  105. package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
  106. package/dist/modes/rpc/rpc-client.js +64 -7
  107. package/dist/modes/rpc/rpc-client.js.map +1 -1
  108. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  109. package/dist/modes/rpc/rpc-mode.js +15 -3
  110. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  111. package/dist/utils/clipboard-native.d.ts +3 -1
  112. package/dist/utils/clipboard-native.d.ts.map +1 -1
  113. package/dist/utils/clipboard-native.js +14 -8
  114. package/dist/utils/clipboard-native.js.map +1 -1
  115. package/dist/utils/deprecation.d.ts +4 -0
  116. package/dist/utils/deprecation.d.ts.map +1 -0
  117. package/dist/utils/deprecation.js +13 -0
  118. package/dist/utils/deprecation.js.map +1 -0
  119. package/dist/utils/image-resize-core.d.ts +30 -0
  120. package/dist/utils/image-resize-core.d.ts.map +1 -0
  121. package/dist/utils/image-resize-core.js +124 -0
  122. package/dist/utils/image-resize-core.js.map +1 -0
  123. package/dist/utils/image-resize-worker.d.ts +2 -0
  124. package/dist/utils/image-resize-worker.d.ts.map +1 -0
  125. package/dist/utils/image-resize-worker.js +31 -0
  126. package/dist/utils/image-resize-worker.js.map +1 -0
  127. package/dist/utils/image-resize.d.ts +6 -27
  128. package/dist/utils/image-resize.d.ts.map +1 -1
  129. package/dist/utils/image-resize.js +60 -116
  130. package/dist/utils/image-resize.js.map +1 -1
  131. package/dist/utils/json.d.ts +3 -0
  132. package/dist/utils/json.d.ts.map +1 -0
  133. package/dist/utils/json.js +7 -0
  134. package/dist/utils/json.js.map +1 -0
  135. package/docs/custom-provider.md +22 -9
  136. package/docs/extensions.md +4 -3
  137. package/docs/models.md +34 -12
  138. package/docs/packages.md +5 -4
  139. package/docs/providers.md +13 -5
  140. package/docs/sdk.md +56 -0
  141. package/docs/settings.md +3 -1
  142. package/docs/terminal-setup.md +6 -0
  143. package/docs/usage.md +2 -2
  144. package/examples/extensions/README.md +1 -0
  145. package/examples/extensions/custom-provider-anthropic/index.ts +1 -1
  146. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  147. package/examples/extensions/custom-provider-gitlab-duo/index.ts +54 -3
  148. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  149. package/examples/extensions/git-merge-and-resolve.ts +115 -0
  150. package/examples/extensions/sandbox/package.json +1 -1
  151. package/examples/extensions/with-deps/package.json +1 -1
  152. package/npm-shrinkwrap.json +13 -12
  153. package/package.json +5 -5
@@ -110,6 +110,9 @@ export class AgentSession {
110
110
  // Compaction state
111
111
  _compactionAbortController = undefined;
112
112
  _autoCompactionAbortController = undefined;
113
+ _extensionCompactionQueue = [];
114
+ _extensionCompactionTimer = undefined;
115
+ _extensionCompactionRunning = false;
113
116
  _overflowRecoveryAttempted = false;
114
117
  // Branch summarization state
115
118
  _branchSummaryAbortController = undefined;
@@ -299,6 +302,9 @@ export class AgentSession {
299
302
  await this._emitExtensionEvent(event);
300
303
  // Notify all listeners
301
304
  this._emit(event.type === "agent_end" ? { ...event, willRetry: this._willRetryAfterAgentEnd(event) } : event);
305
+ if (event.type === "agent_end") {
306
+ this._scheduleExtensionCompactions();
307
+ }
302
308
  // Handle session persistence
303
309
  if (event.type === "message_end") {
304
310
  // Check if this is a custom message from extensions
@@ -503,6 +509,21 @@ export class AgentSession {
503
509
  * Call this when completely done with the session.
504
510
  */
505
511
  dispose() {
512
+ try {
513
+ this.abortRetry();
514
+ this.abortCompaction();
515
+ this.abortBranchSummary();
516
+ this.abortBash();
517
+ this.agent.abort();
518
+ }
519
+ catch {
520
+ // Dispose must succeed even if an abort hook throws.
521
+ }
522
+ if (this._extensionCompactionTimer !== undefined) {
523
+ clearTimeout(this._extensionCompactionTimer);
524
+ this._extensionCompactionTimer = undefined;
525
+ }
526
+ this._extensionCompactionQueue = [];
506
527
  this._extensionRunner.invalidate("This extension ctx is stale after session replacement or reload. Do not use a captured pi or command ctx after ctx.newSession(), ctx.fork(), ctx.switchSession(), or ctx.reload(). For newSession, fork, and switchSession, move post-replacement work into withSession and use the ctx passed to withSession. For reload, do not use the old ctx after await ctx.reload().");
507
528
  this._disconnectFromAgent();
508
529
  this._eventListeners = [];
@@ -710,7 +731,12 @@ export class AgentSession {
710
731
  });
711
732
  this._retryAttempt = 0;
712
733
  }
713
- return await this._checkCompaction(msg);
734
+ if (await this._checkCompaction(msg)) {
735
+ return true;
736
+ }
737
+ // The agent loop drains both queues before emitting agent_end. Any messages
738
+ // here were queued by agent_end extension handlers and need a continuation.
739
+ return this.agent.hasQueuedMessages();
714
740
  }
715
741
  async getStructuredResponse(options) {
716
742
  if (this.isStreaming) {
@@ -920,7 +946,7 @@ export class AgentSession {
920
946
  let currentText = text;
921
947
  let currentImages = options?.images;
922
948
  if (this._extensionRunner.hasHandlers("input")) {
923
- const inputResult = await this._extensionRunner.emitInput(currentText, currentImages, options?.source ?? "interactive");
949
+ const inputResult = await this._extensionRunner.emitInput(currentText, currentImages, options?.source ?? "interactive", this.isStreaming ? options?.streamingBehavior : undefined);
924
950
  if (inputResult.action === "handled") {
925
951
  preflightResult?.(true);
926
952
  return;
@@ -1229,8 +1255,8 @@ export class AgentSession {
1229
1255
  else {
1230
1256
  this.agent.state.messages.push(appMessage);
1231
1257
  this.session.appendCustomMessageEntry(message.customType, message.content, message.display, message.details);
1232
- this._emit({ type: "message_start", message: appMessage });
1233
- this._emit({ type: "message_end", message: appMessage });
1258
+ await this._emit({ type: "message_start", message: appMessage });
1259
+ await this._emit({ type: "message_end", message: appMessage });
1234
1260
  }
1235
1261
  }
1236
1262
  /**
@@ -1485,6 +1511,55 @@ export class AgentSession {
1485
1511
  // =========================================================================
1486
1512
  // Compaction
1487
1513
  // =========================================================================
1514
+ /** Queue extension-triggered compaction outside the currently active agent turn. */
1515
+ _requestExtensionCompaction(options) {
1516
+ this._extensionCompactionQueue.push(options ?? {});
1517
+ if (this.isStreaming) {
1518
+ return;
1519
+ }
1520
+ this._scheduleExtensionCompactions();
1521
+ }
1522
+ _scheduleExtensionCompactions() {
1523
+ const alreadyScheduled = this._extensionCompactionTimer !== undefined;
1524
+ if (this._extensionCompactionRunning || alreadyScheduled || this._extensionCompactionQueue.length === 0) {
1525
+ return;
1526
+ }
1527
+ this._extensionCompactionTimer = setTimeout(() => {
1528
+ this._extensionCompactionTimer = undefined;
1529
+ void this._drainExtensionCompactionQueue();
1530
+ }, 0);
1531
+ }
1532
+ async _drainExtensionCompactionQueue() {
1533
+ if (this._extensionCompactionRunning) {
1534
+ return;
1535
+ }
1536
+ this._extensionCompactionRunning = true;
1537
+ try {
1538
+ while (!this.isStreaming) {
1539
+ const options = this._extensionCompactionQueue.shift();
1540
+ if (!options) {
1541
+ break;
1542
+ }
1543
+ await this._runRequestedExtensionCompaction(options);
1544
+ }
1545
+ }
1546
+ finally {
1547
+ this._extensionCompactionRunning = false;
1548
+ }
1549
+ if (!this.isStreaming) {
1550
+ this._scheduleExtensionCompactions();
1551
+ }
1552
+ }
1553
+ async _runRequestedExtensionCompaction(options) {
1554
+ try {
1555
+ const result = await this.compact(options.customInstructions);
1556
+ options.onComplete?.(result);
1557
+ }
1558
+ catch (error) {
1559
+ const err = error instanceof Error ? error : new Error(String(error));
1560
+ options.onError?.(err);
1561
+ }
1562
+ }
1488
1563
  /**
1489
1564
  * Manually compact the session context.
1490
1565
  * Aborts current agent operation first.
@@ -2025,16 +2100,7 @@ export class AgentSession {
2025
2100
  },
2026
2101
  getContextUsage: () => this.getContextUsage(),
2027
2102
  compact: (options) => {
2028
- void (async () => {
2029
- try {
2030
- const result = await this.compact(options?.customInstructions);
2031
- options?.onComplete?.(result);
2032
- }
2033
- catch (error) {
2034
- const err = error instanceof Error ? error : new Error(String(error));
2035
- options?.onError?.(err);
2036
- }
2037
- })();
2103
+ this._requestExtensionCompaction(options);
2038
2104
  },
2039
2105
  getSystemPrompt: () => this.systemPrompt,
2040
2106
  }, {
@@ -2182,6 +2248,9 @@ export class AgentSession {
2182
2248
  // =========================================================================
2183
2249
  // Auto-Retry
2184
2250
  // =========================================================================
2251
+ _isNonRetryableProviderLimitError(errorMessage) {
2252
+ return /GoUsageLimitError|FreeUsageLimitError|Monthly usage limit reached|available balance|insufficient_quota|out of budget|quota exceeded|billing/i.test(errorMessage);
2253
+ }
2185
2254
  /**
2186
2255
  * Check if an error is retryable (overloaded, rate limit, server errors).
2187
2256
  * Context overflow errors are NOT retryable (handled by compaction instead).
@@ -2194,6 +2263,8 @@ export class AgentSession {
2194
2263
  if (isContextOverflow(message, contextWindow))
2195
2264
  return false;
2196
2265
  const err = message.errorMessage;
2266
+ if (this._isNonRetryableProviderLimitError(err))
2267
+ return false;
2197
2268
  // Match: overloaded_error, provider returned error, rate limit, 429, 500, 502, 503, 504, service unavailable, network/connection errors (including connection lost), WebSocket transport closes/errors, fetch failed, premature stream endings, HTTP/2 closed before response, terminated, retry delay exceeded
2198
2269
  return /overloaded|provider.?returned.?error|rate.?limit|too many requests|429|500|502|503|504|service.?unavailable|server.?error|internal.?error|network.?error|connection.?error|connection.?refused|connection.?lost|websocket.?closed|websocket.?error|other side closed|fetch failed|upstream.?connect|reset before headers|socket hang up|ended without|stream ended before message_stop|http2 request did not get a response|timed? out|timeout|terminated|retry delay/i.test(err);
2199
2270
  }
@@ -2361,7 +2432,7 @@ export class AgentSession {
2361
2432
  */
2362
2433
  setSessionName(name) {
2363
2434
  this.session.appendSessionInfo(name);
2364
- this._emit({ type: "session_info_changed", name: this.session.getSessionName() });
2435
+ void this._emit({ type: "session_info_changed", name: this.session.getSessionName() });
2365
2436
  }
2366
2437
  // =========================================================================
2367
2438
  // Tree Navigation