@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.
- package/CHANGELOG.md +41 -0
- package/README.md +16 -14
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +1 -1
- package/dist/cli/args.js.map +1 -1
- package/dist/core/agent-session.d.ts +1 -0
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +50 -25
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/extensions/types.d.ts +16 -1
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +10 -0
- package/dist/core/model-registry.js.map +1 -1
- package/dist/core/model-resolver.d.ts.map +1 -1
- package/dist/core/model-resolver.js +1 -0
- package/dist/core/model-resolver.js.map +1 -1
- package/dist/core/prompt-templates.d.ts +3 -2
- package/dist/core/prompt-templates.d.ts.map +1 -1
- package/dist/core/prompt-templates.js +8 -3
- package/dist/core/prompt-templates.js.map +1 -1
- package/dist/core/provider-display-names.d.ts.map +1 -1
- package/dist/core/provider-display-names.js +1 -0
- package/dist/core/provider-display-names.js.map +1 -1
- package/dist/core/resource-loader.d.ts +5 -5
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +13 -11
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +169 -80
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/settings-manager.d.ts +23 -0
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +19 -0
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/skills.d.ts.map +1 -1
- package/dist/core/skills.js +3 -7
- package/dist/core/skills.js.map +1 -1
- package/dist/core/slash-commands.d.ts.map +1 -1
- package/dist/core/slash-commands.js +6 -3
- package/dist/core/slash-commands.js.map +1 -1
- package/dist/core/system-prompt.d.ts +3 -3
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +23 -18
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/tools/find.d.ts.map +1 -1
- package/dist/core/tools/find.js +4 -3
- package/dist/core/tools/find.js.map +1 -1
- package/dist/core/tools/grep.d.ts.map +1 -1
- package/dist/core/tools/grep.js +4 -3
- package/dist/core/tools/grep.js.map +1 -1
- package/dist/core/tools/ls.d.ts.map +1 -1
- package/dist/core/tools/ls.js +1 -0
- package/dist/core/tools/ls.js.map +1 -1
- package/dist/core/tools/read.d.ts.map +1 -1
- package/dist/core/tools/read.js +8 -1
- package/dist/core/tools/read.js.map +1 -1
- package/dist/core/tools/render-utils.d.ts +1 -1
- package/dist/core/tools/render-utils.d.ts.map +1 -1
- package/dist/core/tools/render-utils.js +29 -4
- package/dist/core/tools/render-utils.js.map +1 -1
- package/dist/modes/interactive/components/footer.d.ts.map +1 -1
- package/dist/modes/interactive/components/footer.js +2 -2
- package/dist/modes/interactive/components/footer.js.map +1 -1
- package/dist/modes/interactive/components/index.d.ts +2 -0
- package/dist/modes/interactive/components/index.d.ts.map +1 -1
- package/dist/modes/interactive/components/index.js +2 -0
- package/dist/modes/interactive/components/index.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts +7 -0
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +66 -8
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/components/tool-group.d.ts +17 -0
- package/dist/modes/interactive/components/tool-group.d.ts.map +1 -0
- package/dist/modes/interactive/components/tool-group.js +63 -0
- package/dist/modes/interactive/components/tool-group.js.map +1 -0
- package/dist/modes/interactive/components/tool-panel-registry.d.ts +23 -0
- package/dist/modes/interactive/components/tool-panel-registry.d.ts.map +1 -0
- package/dist/modes/interactive/components/tool-panel-registry.js +70 -0
- package/dist/modes/interactive/components/tool-panel-registry.js.map +1 -0
- package/dist/modes/interactive/interactive-mode.d.ts +6 -1
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +119 -60
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/utils/paths.d.ts.map +1 -1
- package/dist/utils/paths.js +4 -1
- package/dist/utils/paths.js.map +1 -1
- package/docs/extensions.md +6 -3
- package/docs/quickstart.md +5 -5
- package/docs/sdk.md +3 -3
- package/docs/settings.md +50 -0
- package/docs/skills.md +3 -3
- package/docs/usage.md +5 -5
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/examples/sdk/07-context-files.ts +3 -14
- package/npm-shrinkwrap.json +388 -2704
- 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 (
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
851
|
-
|
|
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 = [];
|