@caupulican/pi-adaptative 0.78.2 → 0.78.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 (104) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/README.md +16 -14
  3. package/dist/cli/args.d.ts.map +1 -1
  4. package/dist/cli/args.js +1 -1
  5. package/dist/cli/args.js.map +1 -1
  6. package/dist/core/agent-session.d.ts +1 -0
  7. package/dist/core/agent-session.d.ts.map +1 -1
  8. package/dist/core/agent-session.js +50 -25
  9. package/dist/core/agent-session.js.map +1 -1
  10. package/dist/core/extensions/types.d.ts +16 -1
  11. package/dist/core/extensions/types.d.ts.map +1 -1
  12. package/dist/core/extensions/types.js.map +1 -1
  13. package/dist/core/model-registry.d.ts.map +1 -1
  14. package/dist/core/model-registry.js +10 -0
  15. package/dist/core/model-registry.js.map +1 -1
  16. package/dist/core/model-resolver.d.ts.map +1 -1
  17. package/dist/core/model-resolver.js +1 -0
  18. package/dist/core/model-resolver.js.map +1 -1
  19. package/dist/core/prompt-templates.d.ts +3 -2
  20. package/dist/core/prompt-templates.d.ts.map +1 -1
  21. package/dist/core/prompt-templates.js +8 -3
  22. package/dist/core/prompt-templates.js.map +1 -1
  23. package/dist/core/provider-display-names.d.ts.map +1 -1
  24. package/dist/core/provider-display-names.js +1 -0
  25. package/dist/core/provider-display-names.js.map +1 -1
  26. package/dist/core/resource-loader.d.ts +5 -5
  27. package/dist/core/resource-loader.d.ts.map +1 -1
  28. package/dist/core/resource-loader.js +13 -11
  29. package/dist/core/resource-loader.js.map +1 -1
  30. package/dist/core/session-manager.d.ts.map +1 -1
  31. package/dist/core/session-manager.js +169 -80
  32. package/dist/core/session-manager.js.map +1 -1
  33. package/dist/core/settings-manager.d.ts +23 -0
  34. package/dist/core/settings-manager.d.ts.map +1 -1
  35. package/dist/core/settings-manager.js +19 -0
  36. package/dist/core/settings-manager.js.map +1 -1
  37. package/dist/core/skills.d.ts.map +1 -1
  38. package/dist/core/skills.js +3 -7
  39. package/dist/core/skills.js.map +1 -1
  40. package/dist/core/slash-commands.d.ts.map +1 -1
  41. package/dist/core/slash-commands.js +6 -3
  42. package/dist/core/slash-commands.js.map +1 -1
  43. package/dist/core/system-prompt.d.ts +3 -3
  44. package/dist/core/system-prompt.d.ts.map +1 -1
  45. package/dist/core/system-prompt.js +23 -18
  46. package/dist/core/system-prompt.js.map +1 -1
  47. package/dist/core/tools/find.d.ts.map +1 -1
  48. package/dist/core/tools/find.js +4 -3
  49. package/dist/core/tools/find.js.map +1 -1
  50. package/dist/core/tools/grep.d.ts.map +1 -1
  51. package/dist/core/tools/grep.js +4 -3
  52. package/dist/core/tools/grep.js.map +1 -1
  53. package/dist/core/tools/ls.d.ts.map +1 -1
  54. package/dist/core/tools/ls.js +1 -0
  55. package/dist/core/tools/ls.js.map +1 -1
  56. package/dist/core/tools/read.d.ts.map +1 -1
  57. package/dist/core/tools/read.js +8 -1
  58. package/dist/core/tools/read.js.map +1 -1
  59. package/dist/core/tools/render-utils.d.ts +1 -1
  60. package/dist/core/tools/render-utils.d.ts.map +1 -1
  61. package/dist/core/tools/render-utils.js +29 -4
  62. package/dist/core/tools/render-utils.js.map +1 -1
  63. package/dist/modes/interactive/components/footer.d.ts.map +1 -1
  64. package/dist/modes/interactive/components/footer.js +2 -2
  65. package/dist/modes/interactive/components/footer.js.map +1 -1
  66. package/dist/modes/interactive/components/index.d.ts +2 -0
  67. package/dist/modes/interactive/components/index.d.ts.map +1 -1
  68. package/dist/modes/interactive/components/index.js +2 -0
  69. package/dist/modes/interactive/components/index.js.map +1 -1
  70. package/dist/modes/interactive/components/tool-execution.d.ts +7 -0
  71. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  72. package/dist/modes/interactive/components/tool-execution.js +66 -8
  73. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  74. package/dist/modes/interactive/components/tool-group.d.ts +17 -0
  75. package/dist/modes/interactive/components/tool-group.d.ts.map +1 -0
  76. package/dist/modes/interactive/components/tool-group.js +63 -0
  77. package/dist/modes/interactive/components/tool-group.js.map +1 -0
  78. package/dist/modes/interactive/components/tool-panel-registry.d.ts +23 -0
  79. package/dist/modes/interactive/components/tool-panel-registry.d.ts.map +1 -0
  80. package/dist/modes/interactive/components/tool-panel-registry.js +70 -0
  81. package/dist/modes/interactive/components/tool-panel-registry.js.map +1 -0
  82. package/dist/modes/interactive/interactive-mode.d.ts +6 -1
  83. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  84. package/dist/modes/interactive/interactive-mode.js +119 -60
  85. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  86. package/dist/utils/paths.d.ts.map +1 -1
  87. package/dist/utils/paths.js +4 -1
  88. package/dist/utils/paths.js.map +1 -1
  89. package/docs/extensions.md +6 -3
  90. package/docs/quickstart.md +5 -5
  91. package/docs/sdk.md +3 -3
  92. package/docs/settings.md +50 -0
  93. package/docs/skills.md +3 -3
  94. package/docs/usage.md +5 -5
  95. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  96. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  97. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  98. package/examples/extensions/sandbox/package-lock.json +2 -2
  99. package/examples/extensions/sandbox/package.json +1 -1
  100. package/examples/extensions/with-deps/package-lock.json +2 -2
  101. package/examples/extensions/with-deps/package.json +1 -1
  102. package/examples/sdk/07-context-files.ts +3 -14
  103. package/npm-shrinkwrap.json +388 -2704
  104. package/package.json +5 -5
@@ -183,26 +183,29 @@ export class AgentSession {
183
183
  this.agent.transformContext = async (messages, signal) => {
184
184
  const transformed = previousTransformContext ? await previousTransformContext(messages, signal) : messages;
185
185
  const authoritativeMessages = this.agent.state.messages.length > 0 ? this.agent.state.messages : transformed;
186
+ let currentMessages = authoritativeMessages;
186
187
  try {
187
188
  const settings = this.settingsManager.getCompactionSettings();
188
189
  const contextWindow = this.model?.contextWindow ?? 0;
189
- if (!settings.enabled || contextWindow <= 0 || this.isCompacting) {
190
- return authoritativeMessages;
191
- }
192
- const contextTokens = this._estimateCurrentContextTokens(authoritativeMessages);
193
- if (!shouldCompact(contextTokens, contextWindow, settings)) {
194
- return authoritativeMessages;
190
+ if (settings.enabled && contextWindow > 0 && !this.isCompacting) {
191
+ const contextTokens = this._estimateCurrentContextTokens(authoritativeMessages);
192
+ if (shouldCompact(contextTokens, contextWindow, settings)) {
193
+ const latestBefore = getLatestCompactionEntry(this.sessionManager.getBranch())?.id;
194
+ await this._runAutoCompaction("threshold", false);
195
+ const latestAfter = getLatestCompactionEntry(this.sessionManager.getBranch())?.id;
196
+ if (latestAfter && latestAfter !== latestBefore) {
197
+ currentMessages = this.agent.state.messages.slice();
198
+ }
199
+ }
195
200
  }
196
- const latestBefore = getLatestCompactionEntry(this.sessionManager.getBranch())?.id;
197
- await this._runAutoCompaction("threshold", false);
198
- const latestAfter = getLatestCompactionEntry(this.sessionManager.getBranch())?.id;
199
- return latestAfter && latestAfter !== latestBefore
200
- ? this.agent.state.messages.slice()
201
- : authoritativeMessages;
202
201
  }
203
202
  catch {
204
- return authoritativeMessages;
203
+ currentMessages = authoritativeMessages;
205
204
  }
205
+ if (this._extensionRunner.hasHandlers("context")) {
206
+ return await this._extensionRunner.emitContext(currentMessages);
207
+ }
208
+ return currentMessages;
206
209
  };
207
210
  }
208
211
  _installAgentTurnRefresh() {
@@ -691,6 +694,33 @@ export class AgentSession {
691
694
  }
692
695
  return Array.from(unique);
693
696
  }
697
+ _buildSelfModificationPrompt() {
698
+ const settings = this.settingsManager.getSelfModificationSettings();
699
+ if (!settings.enabled) {
700
+ return `Pi self-modification guardrails (local setting inactive):
701
+ - Do not modify Pi core, the installed Pi runtime, or pi-adaptative harness source for self-evolution.
702
+ - If self-modification is needed, ask the user to enable \`selfModification.enabled\` and set \`selfModification.sourcePath\` to the pi-adaptative source checkout.`;
703
+ }
704
+ const rawSourcePath = settings.sourcePath?.trim();
705
+ if (!rawSourcePath) {
706
+ return `Pi self-modification guardrails (local setting active, source missing):
707
+ - Self-modification is enabled, but \`selfModification.sourcePath\` is not set.
708
+ - Do not modify Pi core or runtime output. Ask the user to set \`selfModification.sourcePath\` to the pi-adaptative source checkout before proceeding.`;
709
+ }
710
+ const sourcePath = resolvePath(rawSourcePath, this._cwd, { trim: true });
711
+ const sourceLooksValid = existsSync(sourcePath) && existsSync(resolvePath("package.json", sourcePath));
712
+ const sourceStatus = sourceLooksValid
713
+ ? sourcePath
714
+ : `${sourcePath} (missing or not a source checkout; ask the user to correct \`selfModification.sourcePath\` before editing)`;
715
+ return `Pi self-modification guardrails (local setting active):
716
+ - Authorized pi-adaptative source path: ${sourceStatus}
717
+ - Only modify Pi core/harness source under the authorized source path; never patch installed node_modules or generated runtime output as the source of truth.
718
+ - Before changing Pi itself, restate the objective and scope, inspect relevant source/docs/examples, and make the smallest auditable change.
719
+ - Preserve user changes: check git status before and after, avoid unrelated edits, and do not overwrite concurrent work.
720
+ - Validate with focused tests and broader checks proportional to risk before claiming success.
721
+ - Reload/restart/renew only after source changes are saved and auditable.
722
+ - Ask for explicit approval before changing global settings, publishing, tagging, or releasing.`;
723
+ }
694
724
  _rebuildSystemPrompt(toolNames) {
695
725
  const validToolNames = toolNames.filter((name) => this._toolRegistry.has(name));
696
726
  const toolSnippets = {};
@@ -707,7 +737,8 @@ export class AgentSession {
707
737
  }
708
738
  const loaderSystemPrompt = this._resourceLoader.getSystemPrompt();
709
739
  const loaderAppendSystemPrompt = this._resourceLoader.getAppendSystemPrompt();
710
- const appendSystemPrompt = loaderAppendSystemPrompt.length > 0 ? loaderAppendSystemPrompt.join("\n\n") : undefined;
740
+ const appendSystemPromptParts = [this._buildSelfModificationPrompt(), ...loaderAppendSystemPrompt];
741
+ const appendSystemPrompt = appendSystemPromptParts.length > 0 ? appendSystemPromptParts.join("\n\n") : undefined;
711
742
  const loadedSkills = this._resourceLoader.getSkills().skills;
712
743
  const loadedContextFiles = this._resourceLoader.getAgentsFiles().agentsFiles;
713
744
  this._baseSystemPromptOptions = {
@@ -845,18 +876,12 @@ export class AgentSession {
845
876
  }
846
877
  throw new Error(formatNoApiKeyFoundMessage(this.model.provider));
847
878
  }
848
- // Check if we need to compact before sending (catches aborted responses)
879
+ // Check if we need to compact before sending (catches aborted responses).
880
+ // Do not call agent.continue() here: the next model turn must include the
881
+ // user's pending prompt, not an empty continuation after compaction.
849
882
  const lastAssistant = this._findLastAssistantMessage();
850
- if (lastAssistant && (await this._checkCompaction(lastAssistant, false))) {
851
- try {
852
- await this.agent.continue();
853
- while (await this._handlePostAgentRun()) {
854
- await this.agent.continue();
855
- }
856
- }
857
- finally {
858
- this._flushPendingBashMessages();
859
- }
883
+ if (lastAssistant) {
884
+ await this._checkCompaction(lastAssistant, false);
860
885
  }
861
886
  // Build messages array (custom message if any, then user message)
862
887
  messages = [];