@caupulican/pi-adaptative 0.78.1 → 0.78.3

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/CHANGELOG.md +30 -0
  2. package/README.md +14 -12
  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 +34 -12
  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 +1 -9
  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 +27 -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/render-utils.d.ts +1 -1
  57. package/dist/core/tools/render-utils.d.ts.map +1 -1
  58. package/dist/core/tools/render-utils.js +29 -4
  59. package/dist/core/tools/render-utils.js.map +1 -1
  60. package/dist/modes/interactive/components/footer.d.ts.map +1 -1
  61. package/dist/modes/interactive/components/footer.js +2 -2
  62. package/dist/modes/interactive/components/footer.js.map +1 -1
  63. package/dist/modes/interactive/components/index.d.ts +2 -0
  64. package/dist/modes/interactive/components/index.d.ts.map +1 -1
  65. package/dist/modes/interactive/components/index.js +2 -0
  66. package/dist/modes/interactive/components/index.js.map +1 -1
  67. package/dist/modes/interactive/components/tool-execution.d.ts +7 -0
  68. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  69. package/dist/modes/interactive/components/tool-execution.js +66 -8
  70. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  71. package/dist/modes/interactive/components/tool-group.d.ts +17 -0
  72. package/dist/modes/interactive/components/tool-group.d.ts.map +1 -0
  73. package/dist/modes/interactive/components/tool-group.js +63 -0
  74. package/dist/modes/interactive/components/tool-group.js.map +1 -0
  75. package/dist/modes/interactive/components/tool-panel-registry.d.ts +23 -0
  76. package/dist/modes/interactive/components/tool-panel-registry.d.ts.map +1 -0
  77. package/dist/modes/interactive/components/tool-panel-registry.js +70 -0
  78. package/dist/modes/interactive/components/tool-panel-registry.js.map +1 -0
  79. package/dist/modes/interactive/interactive-mode.d.ts +6 -1
  80. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  81. package/dist/modes/interactive/interactive-mode.js +119 -60
  82. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  83. package/dist/utils/paths.d.ts.map +1 -1
  84. package/dist/utils/paths.js +4 -1
  85. package/dist/utils/paths.js.map +1 -1
  86. package/docs/extensions.md +6 -3
  87. package/docs/quickstart.md +3 -3
  88. package/docs/sdk.md +1 -1
  89. package/docs/settings.md +50 -0
  90. package/docs/skills.md +3 -3
  91. package/docs/usage.md +3 -3
  92. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  93. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  94. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  95. package/examples/extensions/sandbox/package-lock.json +2 -2
  96. package/examples/extensions/sandbox/package.json +1 -1
  97. package/examples/extensions/with-deps/package-lock.json +2 -2
  98. package/examples/extensions/with-deps/package.json +1 -1
  99. package/examples/sdk/07-context-files.ts +3 -14
  100. package/npm-shrinkwrap.json +18 -15
  101. package/package.json +4 -4
@@ -691,6 +691,33 @@ export class AgentSession {
691
691
  }
692
692
  return Array.from(unique);
693
693
  }
694
+ _buildSelfModificationPrompt() {
695
+ const settings = this.settingsManager.getSelfModificationSettings();
696
+ if (!settings.enabled) {
697
+ return `Pi self-modification guardrails (local setting inactive):
698
+ - Do not modify Pi core, the installed Pi runtime, or pi-adaptative harness source for self-evolution.
699
+ - If self-modification is needed, ask the user to enable \`selfModification.enabled\` and set \`selfModification.sourcePath\` to the pi-adaptative source checkout.`;
700
+ }
701
+ const rawSourcePath = settings.sourcePath?.trim();
702
+ if (!rawSourcePath) {
703
+ return `Pi self-modification guardrails (local setting active, source missing):
704
+ - Self-modification is enabled, but \`selfModification.sourcePath\` is not set.
705
+ - Do not modify Pi core or runtime output. Ask the user to set \`selfModification.sourcePath\` to the pi-adaptative source checkout before proceeding.`;
706
+ }
707
+ const sourcePath = resolvePath(rawSourcePath, this._cwd, { trim: true });
708
+ const sourceLooksValid = existsSync(sourcePath) && existsSync(resolvePath("package.json", sourcePath));
709
+ const sourceStatus = sourceLooksValid
710
+ ? sourcePath
711
+ : `${sourcePath} (missing or not a source checkout; ask the user to correct \`selfModification.sourcePath\` before editing)`;
712
+ return `Pi self-modification guardrails (local setting active):
713
+ - Authorized pi-adaptative source path: ${sourceStatus}
714
+ - 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.
715
+ - Before changing Pi itself, restate the objective and scope, inspect relevant source/docs/examples, and make the smallest auditable change.
716
+ - Preserve user changes: check git status before and after, avoid unrelated edits, and do not overwrite concurrent work.
717
+ - Validate with focused tests and broader checks proportional to risk before claiming success.
718
+ - Reload/restart/renew only after source changes are saved and auditable.
719
+ - Ask for explicit approval before changing global settings, publishing, tagging, or releasing.`;
720
+ }
694
721
  _rebuildSystemPrompt(toolNames) {
695
722
  const validToolNames = toolNames.filter((name) => this._toolRegistry.has(name));
696
723
  const toolSnippets = {};
@@ -707,7 +734,8 @@ export class AgentSession {
707
734
  }
708
735
  const loaderSystemPrompt = this._resourceLoader.getSystemPrompt();
709
736
  const loaderAppendSystemPrompt = this._resourceLoader.getAppendSystemPrompt();
710
- const appendSystemPrompt = loaderAppendSystemPrompt.length > 0 ? loaderAppendSystemPrompt.join("\n\n") : undefined;
737
+ const appendSystemPromptParts = [this._buildSelfModificationPrompt(), ...loaderAppendSystemPrompt];
738
+ const appendSystemPrompt = appendSystemPromptParts.length > 0 ? appendSystemPromptParts.join("\n\n") : undefined;
711
739
  const loadedSkills = this._resourceLoader.getSkills().skills;
712
740
  const loadedContextFiles = this._resourceLoader.getAgentsFiles().agentsFiles;
713
741
  this._baseSystemPromptOptions = {
@@ -845,18 +873,12 @@ export class AgentSession {
845
873
  }
846
874
  throw new Error(formatNoApiKeyFoundMessage(this.model.provider));
847
875
  }
848
- // Check if we need to compact before sending (catches aborted responses)
876
+ // Check if we need to compact before sending (catches aborted responses).
877
+ // Do not call agent.continue() here: the next model turn must include the
878
+ // user's pending prompt, not an empty continuation after compaction.
849
879
  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
- }
880
+ if (lastAssistant) {
881
+ await this._checkCompaction(lastAssistant, false);
860
882
  }
861
883
  // Build messages array (custom message if any, then user message)
862
884
  messages = [];