@caupulican/pi-adaptative 0.76.2 → 0.77.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.
Files changed (95) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/README.md +9 -0
  3. package/dist/cli/args.d.ts +2 -0
  4. package/dist/cli/args.d.ts.map +1 -1
  5. package/dist/cli/args.js +23 -0
  6. package/dist/cli/args.js.map +1 -1
  7. package/dist/core/agent-session-services.d.ts +1 -0
  8. package/dist/core/agent-session-services.d.ts.map +1 -1
  9. package/dist/core/agent-session-services.js +1 -0
  10. package/dist/core/agent-session-services.js.map +1 -1
  11. package/dist/core/agent-session.d.ts +4 -1
  12. package/dist/core/agent-session.d.ts.map +1 -1
  13. package/dist/core/agent-session.js +23 -4
  14. package/dist/core/agent-session.js.map +1 -1
  15. package/dist/core/extensions/runner.d.ts +1 -1
  16. package/dist/core/extensions/runner.d.ts.map +1 -1
  17. package/dist/core/extensions/runner.js +8 -2
  18. package/dist/core/extensions/runner.js.map +1 -1
  19. package/dist/core/extensions/types.d.ts +7 -5
  20. package/dist/core/extensions/types.d.ts.map +1 -1
  21. package/dist/core/extensions/types.js.map +1 -1
  22. package/dist/core/model-registry.d.ts.map +1 -1
  23. package/dist/core/model-registry.js +65 -13
  24. package/dist/core/model-registry.js.map +1 -1
  25. package/dist/core/model-resolver.d.ts.map +1 -1
  26. package/dist/core/model-resolver.js +1 -1
  27. package/dist/core/model-resolver.js.map +1 -1
  28. package/dist/core/resolve-config-value.d.ts +9 -1
  29. package/dist/core/resolve-config-value.d.ts.map +1 -1
  30. package/dist/core/resolve-config-value.js +134 -11
  31. package/dist/core/resolve-config-value.js.map +1 -1
  32. package/dist/core/sdk.d.ts +2 -0
  33. package/dist/core/sdk.d.ts.map +1 -1
  34. package/dist/core/sdk.js +4 -5
  35. package/dist/core/sdk.js.map +1 -1
  36. package/dist/core/session-manager.d.ts +3 -5
  37. package/dist/core/session-manager.d.ts.map +1 -1
  38. package/dist/core/session-manager.js +42 -17
  39. package/dist/core/session-manager.js.map +1 -1
  40. package/dist/core/system-prompt.d.ts.map +1 -1
  41. package/dist/core/system-prompt.js +0 -3
  42. package/dist/core/system-prompt.js.map +1 -1
  43. package/dist/index.d.ts +1 -0
  44. package/dist/index.d.ts.map +1 -1
  45. package/dist/index.js +1 -0
  46. package/dist/index.js.map +1 -1
  47. package/dist/main.d.ts.map +1 -1
  48. package/dist/main.js +15 -2
  49. package/dist/main.js.map +1 -1
  50. package/dist/migrations.d.ts.map +1 -1
  51. package/dist/migrations.js +118 -1
  52. package/dist/migrations.js.map +1 -1
  53. package/dist/modes/interactive/components/login-dialog.d.ts +1 -3
  54. package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
  55. package/dist/modes/interactive/components/login-dialog.js +2 -4
  56. package/dist/modes/interactive/components/login-dialog.js.map +1 -1
  57. package/dist/modes/interactive/interactive-mode.d.ts +2 -0
  58. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  59. package/dist/modes/interactive/interactive-mode.js +51 -6
  60. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  61. package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
  62. package/dist/modes/interactive/theme/theme.js +10 -0
  63. package/dist/modes/interactive/theme/theme.js.map +1 -1
  64. package/dist/utils/deprecation.d.ts +4 -0
  65. package/dist/utils/deprecation.d.ts.map +1 -0
  66. package/dist/utils/deprecation.js +13 -0
  67. package/dist/utils/deprecation.js.map +1 -0
  68. package/dist/utils/json.d.ts +3 -0
  69. package/dist/utils/json.d.ts.map +1 -0
  70. package/dist/utils/json.js +7 -0
  71. package/dist/utils/json.js.map +1 -0
  72. package/docs/custom-provider.md +13 -10
  73. package/docs/extensions.md +12 -6
  74. package/docs/models.md +25 -12
  75. package/docs/providers.md +13 -5
  76. package/docs/quickstart.md +1 -0
  77. package/docs/rpc.md +2 -1
  78. package/docs/sdk.md +6 -0
  79. package/docs/session-format.md +1 -1
  80. package/docs/sessions.md +8 -0
  81. package/docs/usage.md +9 -0
  82. package/examples/extensions/README.md +1 -0
  83. package/examples/extensions/custom-provider-anthropic/index.ts +1 -1
  84. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  85. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  86. package/examples/extensions/custom-provider-gitlab-duo/index.ts +1 -1
  87. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  88. package/examples/extensions/git-merge-and-resolve.ts +115 -0
  89. package/examples/extensions/input-transform-streaming.ts +39 -0
  90. package/examples/extensions/sandbox/package-lock.json +2 -2
  91. package/examples/extensions/sandbox/package.json +1 -1
  92. package/examples/extensions/with-deps/package-lock.json +2 -2
  93. package/examples/extensions/with-deps/package.json +1 -1
  94. package/npm-shrinkwrap.json +56 -56
  95. package/package.json +5 -5
@@ -8,6 +8,7 @@ import * as os from "node:os";
8
8
  import * as path from "node:path";
9
9
  import { getProviders, } from "@earendil-works/pi-ai";
10
10
  import { CombinedAutocompleteProvider, Container, fuzzyFilter, getCapabilities, hyperlink, Loader, Markdown, matchesKey, ProcessTerminal, Spacer, setKeybindings, Text, TruncatedText, TUI, visibleWidth, } from "@earendil-works/pi-tui";
11
+ import chalk from "chalk";
11
12
  import { spawn, spawnSync } from "child_process";
12
13
  import { APP_NAME, APP_TITLE, getAgentDir, getAuthPath, getDebugLogPath, getDocsPath, getShareViewerUrl, VERSION, } from "../../config.js";
13
14
  import { parseSkillBlock } from "../../core/agent-session.js";
@@ -91,6 +92,27 @@ function isAnthropicSubscriptionAuthKey(apiKey) {
91
92
  function isUnknownModel(model) {
92
93
  return !!model && model.provider === "unknown" && model.id === "unknown" && model.api === "unknown";
93
94
  }
95
+ function quoteIfNeeded(value) {
96
+ if (value.length > 0 && !/[^a-zA-Z0-9_\-./~:@]/.test(value)) {
97
+ return value;
98
+ }
99
+ return `'${value.replace(/'/g, `'\\''`)}'`;
100
+ }
101
+ export function formatResumeCommand(sessionManager) {
102
+ if (!process.stdout.isTTY)
103
+ return undefined;
104
+ if (!sessionManager.isPersisted())
105
+ return undefined;
106
+ const sessionFile = sessionManager.getSessionFile();
107
+ if (!sessionFile || !fs.existsSync(sessionFile))
108
+ return undefined;
109
+ const args = [APP_NAME];
110
+ if (!sessionManager.usesDefaultSessionDir()) {
111
+ args.push("--session-dir", quoteIfNeeded(sessionManager.getSessionDir()));
112
+ }
113
+ args.push("--session", sessionManager.getSessionId());
114
+ return args.join(" ");
115
+ }
94
116
  function hasDefaultModelProvider(providerId) {
95
117
  return providerId in defaultModelPerProvider;
96
118
  }
@@ -2646,16 +2668,36 @@ export class InteractiveMode {
2646
2668
  * repaint the final frame while the process is exiting.
2647
2669
  */
2648
2670
  isShuttingDown = false;
2649
- async shutdown() {
2671
+ async shutdown(options) {
2650
2672
  if (this.isShuttingDown)
2651
2673
  return;
2652
2674
  this.isShuttingDown = true;
2653
2675
  this.unregisterSignalHandlers();
2676
+ if (options?.fromSignal) {
2677
+ // Signal-triggered shutdown (SIGTERM/SIGHUP). Emit extension cleanup
2678
+ // (session_shutdown) BEFORE touching the terminal. Extension teardown
2679
+ // such as removing sockets does not write to the tty, so it must not be
2680
+ // skipped if a later terminal-restore write fails on a dead or stalled
2681
+ // terminal. If the terminal is gone, the restore writes below emit EIO,
2682
+ // which the stdout/stderr error handler turns into emergencyTerminalExit;
2683
+ // the render loop is already idle, so this cannot hot-spin (see #4144).
2684
+ await this.runtimeHost.dispose();
2685
+ await this.ui.terminal.drainInput(1000);
2686
+ this.stop();
2687
+ process.exit(0);
2688
+ }
2689
+ // Interactive quit (Ctrl+D, Ctrl+C, /quit, extension shutdown()). Stop the
2690
+ // TUI before emitting shutdown events so extension UI cleanup cannot repaint
2691
+ // the final frame while the process is exiting.
2654
2692
  // Drain any in-flight Kitty key release events before stopping.
2655
2693
  // This prevents escape sequences from leaking to the parent shell over slow SSH.
2656
2694
  await this.ui.terminal.drainInput(1000);
2657
2695
  this.stop();
2658
2696
  await this.runtimeHost.dispose();
2697
+ const resumeCommand = formatResumeCommand(this.sessionManager);
2698
+ if (resumeCommand) {
2699
+ process.stdout.write(` ${chalk.dim("To resume this session:")} ${resumeCommand}\n`);
2700
+ }
2659
2701
  process.exit(0);
2660
2702
  }
2661
2703
  emergencyTerminalExit() {
@@ -2714,11 +2756,12 @@ export class InteractiveMode {
2714
2756
  }
2715
2757
  for (const signal of signals) {
2716
2758
  const handler = () => {
2717
- if (signal === "SIGHUP") {
2718
- this.emergencyTerminalExit();
2719
- }
2759
+ // SIGHUP no longer hard-exits: graceful shutdown emits session_shutdown
2760
+ // first, then attempts terminal restore. A genuinely dead terminal
2761
+ // surfaces as an EIO on the restore writes, which the stdout/stderr
2762
+ // error handler converts into emergencyTerminalExit (see #4144, #5080).
2720
2763
  killTrackedDetachedChildren();
2721
- void this.shutdown();
2764
+ void this.shutdown({ fromSignal: true });
2722
2765
  };
2723
2766
  process.prependListener(signal, handler);
2724
2767
  this.signalCleanupHandlers.push(() => process.off(signal, handler));
@@ -3646,7 +3689,9 @@ export class InteractiveMode {
3646
3689
  }
3647
3690
  showSessionSelector() {
3648
3691
  this.showSelector((done) => {
3649
- const selector = new SessionSelectorComponent((onProgress) => SessionManager.list(this.sessionManager.getCwd(), this.sessionManager.getSessionDir(), onProgress), SessionManager.listAll, async (sessionPath) => {
3692
+ const selector = new SessionSelectorComponent((onProgress) => SessionManager.list(this.sessionManager.getCwd(), this.sessionManager.getSessionDir(), onProgress), (onProgress) => this.sessionManager.usesDefaultSessionDir()
3693
+ ? SessionManager.listAll(onProgress)
3694
+ : SessionManager.listAll(this.sessionManager.getSessionDir(), onProgress), async (sessionPath) => {
3650
3695
  done();
3651
3696
  await this.handleResumeSession(sessionPath);
3652
3697
  }, () => {