@caupulican/pi-adaptative 0.80.23 → 0.80.26
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 +17 -0
- package/README.md +16 -2
- package/dist/cli/args.d.ts +2 -0
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +14 -0
- package/dist/cli/args.js.map +1 -1
- package/dist/core/agent-session-services.d.ts +4 -0
- package/dist/core/agent-session-services.d.ts.map +1 -1
- package/dist/core/agent-session-services.js +22 -0
- package/dist/core/agent-session-services.js.map +1 -1
- package/dist/core/agent-session.d.ts +7 -1
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +126 -20
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/extensions/builtin.d.ts +3 -0
- package/dist/core/extensions/builtin.d.ts.map +1 -0
- package/dist/core/extensions/builtin.js +247 -0
- package/dist/core/extensions/builtin.js.map +1 -0
- package/dist/core/package-manager.d.ts +3 -0
- package/dist/core/package-manager.d.ts.map +1 -1
- package/dist/core/package-manager.js +58 -0
- package/dist/core/package-manager.js.map +1 -1
- package/dist/core/prompt-templates.d.ts.map +1 -1
- package/dist/core/prompt-templates.js +3 -1
- package/dist/core/prompt-templates.js.map +1 -1
- package/dist/core/resource-loader.d.ts +15 -2
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +235 -134
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/resource-profile-blocks.d.ts +16 -0
- package/dist/core/resource-profile-blocks.d.ts.map +1 -0
- package/dist/core/resource-profile-blocks.js +120 -0
- package/dist/core/resource-profile-blocks.js.map +1 -0
- package/dist/core/sdk.d.ts +9 -0
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +17 -0
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/settings-manager.d.ts +45 -1
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +218 -10
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/skills.d.ts.map +1 -1
- package/dist/core/skills.js +3 -0
- package/dist/core/skills.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +17 -0
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +20 -20
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/docs/extensions.md +18 -1
- package/docs/prompt-templates.md +1 -0
- package/docs/settings.md +43 -1
- package/docs/skills.md +12 -0
- 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/npm-shrinkwrap.json +12 -12
- package/package.json +4 -4
|
@@ -25,11 +25,14 @@ import { calculateContextTokens, collectEntriesForBranchSummary, compact, estima
|
|
|
25
25
|
import { DEFAULT_THINKING_LEVEL } from "./defaults.js";
|
|
26
26
|
import { exportSessionToHtml } from "./export-html/index.js";
|
|
27
27
|
import { createToolHtmlRenderer } from "./export-html/tool-renderer.js";
|
|
28
|
+
import { createCoreDiagnosticsToolDefinitions } from "./extensions/builtin.js";
|
|
28
29
|
import { ExtensionRunner, wrapRegisteredTools, } from "./extensions/index.js";
|
|
29
30
|
import { emitSessionShutdownEvent } from "./extensions/runner.js";
|
|
30
31
|
import { compactToolResultDetailsForRetention } from "./message-retention.js";
|
|
31
32
|
import { expandPromptTemplate } from "./prompt-templates.js";
|
|
33
|
+
import { stripResourceProfileBlocks } from "./resource-profile-blocks.js";
|
|
32
34
|
import { CURRENT_SESSION_VERSION, getLatestCompactionEntry } from "./session-manager.js";
|
|
35
|
+
import { matchesResourceProfilePattern, } from "./settings-manager.js";
|
|
33
36
|
import { createSyntheticSourceInfo } from "./source-info.js";
|
|
34
37
|
import { buildSystemPrompt } from "./system-prompt.js";
|
|
35
38
|
import { createLocalBashOperations } from "./tools/bash.js";
|
|
@@ -99,6 +102,7 @@ export class AgentSession {
|
|
|
99
102
|
_initialActiveToolNames;
|
|
100
103
|
_allowedToolNames;
|
|
101
104
|
_excludedToolNames;
|
|
105
|
+
_toolProfileFilter;
|
|
102
106
|
_baseToolsOverride;
|
|
103
107
|
_sessionStartEvent;
|
|
104
108
|
_extensionUIContext;
|
|
@@ -131,6 +135,9 @@ export class AgentSession {
|
|
|
131
135
|
this._initialActiveToolNames = config.initialActiveToolNames;
|
|
132
136
|
this._allowedToolNames = config.allowedToolNames ? new Set(config.allowedToolNames) : undefined;
|
|
133
137
|
this._excludedToolNames = config.excludedToolNames ? new Set(config.excludedToolNames) : undefined;
|
|
138
|
+
this._toolProfileFilter = config.toolProfileFilter
|
|
139
|
+
? { allow: config.toolProfileFilter.allow ?? [], block: config.toolProfileFilter.block ?? [] }
|
|
140
|
+
: undefined;
|
|
134
141
|
this._baseToolsOverride = config.baseToolsOverride;
|
|
135
142
|
this._sessionStartEvent = config.sessionStartEvent ?? { type: "session_start", reason: "startup" };
|
|
136
143
|
// Always subscribe to agent events for internal handling
|
|
@@ -1030,7 +1037,7 @@ export class AgentSession {
|
|
|
1030
1037
|
return text; // Unknown skill, pass through
|
|
1031
1038
|
try {
|
|
1032
1039
|
const content = readFileSync(skill.filePath, "utf-8");
|
|
1033
|
-
const body = stripFrontmatter(content).trim();
|
|
1040
|
+
const body = stripResourceProfileBlocks(stripFrontmatter(content)).trim();
|
|
1034
1041
|
const skillBlock = `<skill name="${skill.name}" location="${skill.filePath}">\nReferences are relative to ${skill.baseDir}.\n\n${body}\n</skill>`;
|
|
1035
1042
|
return args ? `${skillBlock}\n\n${args}` : skillBlock;
|
|
1036
1043
|
}
|
|
@@ -2021,7 +2028,21 @@ export class AgentSession {
|
|
|
2021
2028
|
const previousActiveToolNames = this.getActiveToolNames();
|
|
2022
2029
|
const allowedToolNames = this._allowedToolNames;
|
|
2023
2030
|
const excludedToolNames = this._excludedToolNames;
|
|
2024
|
-
const
|
|
2031
|
+
const toolProfileFilter = this._toolProfileFilter;
|
|
2032
|
+
const isAllowedTool = (name) => {
|
|
2033
|
+
if (allowedToolNames && !allowedToolNames.has(name))
|
|
2034
|
+
return false;
|
|
2035
|
+
if (excludedToolNames?.has(name))
|
|
2036
|
+
return false;
|
|
2037
|
+
if (!toolProfileFilter)
|
|
2038
|
+
return true;
|
|
2039
|
+
if (toolProfileFilter.allow.length > 0 && !matchesResourceProfilePattern(name, toolProfileFilter.allow)) {
|
|
2040
|
+
return false;
|
|
2041
|
+
}
|
|
2042
|
+
if (matchesResourceProfilePattern(name, toolProfileFilter.block))
|
|
2043
|
+
return false;
|
|
2044
|
+
return true;
|
|
2045
|
+
};
|
|
2025
2046
|
const registeredTools = this._extensionRunner.getAllRegisteredTools();
|
|
2026
2047
|
const allCustomTools = [
|
|
2027
2048
|
...registeredTools,
|
|
@@ -2093,6 +2114,55 @@ export class AgentSession {
|
|
|
2093
2114
|
}
|
|
2094
2115
|
this.setActiveToolsByName([...new Set(nextActiveToolNames)]);
|
|
2095
2116
|
}
|
|
2117
|
+
_createReloadRuntimeSnapshot() {
|
|
2118
|
+
return {
|
|
2119
|
+
extensionRunner: this._extensionRunner,
|
|
2120
|
+
baseToolDefinitions: this._baseToolDefinitions,
|
|
2121
|
+
toolRegistry: this._toolRegistry,
|
|
2122
|
+
toolDefinitions: this._toolDefinitions,
|
|
2123
|
+
toolPromptSnippets: this._toolPromptSnippets,
|
|
2124
|
+
toolPromptGuidelines: this._toolPromptGuidelines,
|
|
2125
|
+
agentTools: this.agent.state.tools,
|
|
2126
|
+
agentSystemPrompt: this.agent.state.systemPrompt,
|
|
2127
|
+
baseSystemPrompt: this._baseSystemPrompt,
|
|
2128
|
+
};
|
|
2129
|
+
}
|
|
2130
|
+
_restoreReloadRuntimeSnapshot(snapshot) {
|
|
2131
|
+
this._extensionRunner = snapshot.extensionRunner;
|
|
2132
|
+
this._baseToolDefinitions = snapshot.baseToolDefinitions;
|
|
2133
|
+
this._toolRegistry = snapshot.toolRegistry;
|
|
2134
|
+
this._toolDefinitions = snapshot.toolDefinitions;
|
|
2135
|
+
this._toolPromptSnippets = snapshot.toolPromptSnippets;
|
|
2136
|
+
this._toolPromptGuidelines = snapshot.toolPromptGuidelines;
|
|
2137
|
+
this.agent.state.tools = snapshot.agentTools;
|
|
2138
|
+
this.agent.state.systemPrompt = snapshot.agentSystemPrompt;
|
|
2139
|
+
this._baseSystemPrompt = snapshot.baseSystemPrompt;
|
|
2140
|
+
if (this._extensionRunnerRef) {
|
|
2141
|
+
this._extensionRunnerRef.current = snapshot.extensionRunner;
|
|
2142
|
+
}
|
|
2143
|
+
this._applyExtensionBindings(snapshot.extensionRunner);
|
|
2144
|
+
}
|
|
2145
|
+
_doctorReloadRuntime() {
|
|
2146
|
+
const extensionErrors = this._resourceLoader.getExtensions().errors;
|
|
2147
|
+
if (extensionErrors.length > 0) {
|
|
2148
|
+
const summary = extensionErrors
|
|
2149
|
+
.slice(0, 6)
|
|
2150
|
+
.map((error) => `${error.path}: ${error.error}`)
|
|
2151
|
+
.join("; ");
|
|
2152
|
+
throw new Error(`Extension reload failed doctor: ${summary}`);
|
|
2153
|
+
}
|
|
2154
|
+
const missingActiveTools = this.getActiveToolNames().filter((name) => !this._toolRegistry.has(name));
|
|
2155
|
+
if (missingActiveTools.length > 0) {
|
|
2156
|
+
throw new Error(`Extension reload failed doctor: active tool(s) missing after reload: ${missingActiveTools.join(", ")}`);
|
|
2157
|
+
}
|
|
2158
|
+
for (const tool of this.agent.state.tools) {
|
|
2159
|
+
if (!this._toolDefinitions.has(tool.name)) {
|
|
2160
|
+
throw new Error(`Extension reload failed doctor: tool ${tool.name} missing from definition registry`);
|
|
2161
|
+
}
|
|
2162
|
+
}
|
|
2163
|
+
this._createAgentContextSnapshot();
|
|
2164
|
+
this.getContextUsage();
|
|
2165
|
+
}
|
|
2096
2166
|
_buildRuntime(options) {
|
|
2097
2167
|
const autoResizeImages = this.settingsManager.getImageAutoResize();
|
|
2098
2168
|
const shellCommandPrefix = this.settingsManager.getShellCommandPrefix();
|
|
@@ -2107,6 +2177,11 @@ export class AgentSession {
|
|
|
2107
2177
|
bash: { commandPrefix: shellCommandPrefix, shellPath },
|
|
2108
2178
|
});
|
|
2109
2179
|
this._baseToolDefinitions = new Map(Object.entries(baseToolDefinitions).map(([name, tool]) => [name, tool]));
|
|
2180
|
+
if (!this._baseToolsOverride) {
|
|
2181
|
+
for (const definition of createCoreDiagnosticsToolDefinitions(() => this.getActiveToolNames(), () => this.getAllTools())) {
|
|
2182
|
+
this._baseToolDefinitions.set(definition.name, definition);
|
|
2183
|
+
}
|
|
2184
|
+
}
|
|
2110
2185
|
const extensionsResult = this._resourceLoader.getExtensions();
|
|
2111
2186
|
if (options.flagValues) {
|
|
2112
2187
|
for (const [name, value] of options.flagValues) {
|
|
@@ -2121,7 +2196,7 @@ export class AgentSession {
|
|
|
2121
2196
|
this._applyExtensionBindings(this._extensionRunner);
|
|
2122
2197
|
const defaultActiveToolNames = this._baseToolsOverride
|
|
2123
2198
|
? Object.keys(this._baseToolsOverride)
|
|
2124
|
-
: ["read", "bash", "edit", "write"];
|
|
2199
|
+
: ["read", "bash", "edit", "write", "context_audit"];
|
|
2125
2200
|
const baseActiveToolNames = options.activeToolNames ?? defaultActiveToolNames;
|
|
2126
2201
|
this._refreshToolRegistry({
|
|
2127
2202
|
activeToolNames: baseActiveToolNames,
|
|
@@ -2129,23 +2204,54 @@ export class AgentSession {
|
|
|
2129
2204
|
});
|
|
2130
2205
|
}
|
|
2131
2206
|
async reload() {
|
|
2132
|
-
const
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2207
|
+
const previousRunner = this._extensionRunner;
|
|
2208
|
+
const snapshot = this._createReloadRuntimeSnapshot();
|
|
2209
|
+
const activeToolNames = this.getActiveToolNames();
|
|
2210
|
+
const previousFlagValues = previousRunner.getFlagValues();
|
|
2211
|
+
const reloadErrors = [];
|
|
2212
|
+
let newRunner;
|
|
2213
|
+
try {
|
|
2214
|
+
await this.settingsManager.reload();
|
|
2215
|
+
await this._resourceLoader.reload({ failOnExtensionErrors: true, deferExtensionDispose: true });
|
|
2216
|
+
resetApiProviders();
|
|
2217
|
+
this._buildRuntime({
|
|
2218
|
+
activeToolNames,
|
|
2219
|
+
flagValues: previousFlagValues,
|
|
2220
|
+
includeAllExtensionTools: true,
|
|
2221
|
+
});
|
|
2222
|
+
newRunner = this._extensionRunner;
|
|
2223
|
+
const offDoctorErrors = newRunner.onError((error) => {
|
|
2224
|
+
reloadErrors.push(`${error.extensionPath} ${error.event}: ${error.error}`);
|
|
2225
|
+
});
|
|
2226
|
+
try {
|
|
2227
|
+
this._doctorReloadRuntime();
|
|
2228
|
+
const hasBindings = this._extensionUIContext ||
|
|
2229
|
+
this._extensionCommandContextActions ||
|
|
2230
|
+
this._extensionShutdownHandler ||
|
|
2231
|
+
this._extensionErrorListener;
|
|
2232
|
+
if (hasBindings) {
|
|
2233
|
+
await newRunner.emit({ type: "session_start", reason: "reload" });
|
|
2234
|
+
await this.extendResourcesFromExtensions("reload");
|
|
2235
|
+
this._doctorReloadRuntime();
|
|
2236
|
+
}
|
|
2237
|
+
}
|
|
2238
|
+
finally {
|
|
2239
|
+
offDoctorErrors();
|
|
2240
|
+
}
|
|
2241
|
+
if (reloadErrors.length > 0) {
|
|
2242
|
+
throw new Error(`Extension reload failed doctor: ${reloadErrors.slice(0, 6).join("; ")}`);
|
|
2243
|
+
}
|
|
2244
|
+
await emitSessionShutdownEvent(previousRunner, { type: "session_shutdown", reason: "reload" });
|
|
2245
|
+
previousRunner.invalidate();
|
|
2246
|
+
this._resourceLoader.commitReload?.();
|
|
2247
|
+
}
|
|
2248
|
+
catch (error) {
|
|
2249
|
+
if (newRunner && newRunner !== previousRunner) {
|
|
2250
|
+
newRunner.invalidate("This extension ctx was discarded because reload failed and Pi restored the previous valid runtime.");
|
|
2251
|
+
}
|
|
2252
|
+
this._resourceLoader.rollbackReload?.();
|
|
2253
|
+
this._restoreReloadRuntimeSnapshot(snapshot);
|
|
2254
|
+
throw error;
|
|
2149
2255
|
}
|
|
2150
2256
|
}
|
|
2151
2257
|
// =========================================================================
|