@caupulican/pi-adaptative 0.81.3 → 0.81.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 +17 -0
- 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 +23 -17
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/billing-failover-controller.d.ts +7 -0
- package/dist/core/billing-failover-controller.d.ts.map +1 -1
- package/dist/core/billing-failover-controller.js +6 -0
- package/dist/core/billing-failover-controller.js.map +1 -1
- package/dist/core/compaction-support.d.ts +10 -1
- package/dist/core/compaction-support.d.ts.map +1 -1
- package/dist/core/compaction-support.js +68 -9
- package/dist/core/compaction-support.js.map +1 -1
- package/dist/core/export-html/index.d.ts.map +1 -1
- package/dist/core/export-html/index.js +9 -9
- package/dist/core/export-html/index.js.map +1 -1
- package/dist/core/failure-corpus.d.ts +49 -0
- package/dist/core/failure-corpus.d.ts.map +1 -0
- package/dist/core/failure-corpus.js +61 -0
- package/dist/core/failure-corpus.js.map +1 -0
- package/dist/core/model-router/fitness-gate.d.ts +5 -3
- package/dist/core/model-router/fitness-gate.d.ts.map +1 -1
- package/dist/core/model-router/fitness-gate.js +1 -0
- package/dist/core/model-router/fitness-gate.js.map +1 -1
- package/dist/core/model-router/status.d.ts +4 -0
- package/dist/core/model-router/status.d.ts.map +1 -1
- package/dist/core/model-router/status.js +4 -0
- package/dist/core/model-router/status.js.map +1 -1
- package/dist/core/model-router-controller.d.ts.map +1 -1
- package/dist/core/model-router-controller.js +2 -0
- package/dist/core/model-router-controller.js.map +1 -1
- package/dist/core/models/default-model-suggestions.d.ts.map +1 -1
- package/dist/core/models/default-model-suggestions.js +18 -0
- package/dist/core/models/default-model-suggestions.js.map +1 -1
- package/dist/core/settings-manager.d.ts +1 -0
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +12 -0
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/slash-commands.d.ts.map +1 -1
- package/dist/core/slash-commands.js +4 -0
- package/dist/core/slash-commands.js.map +1 -1
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +6 -8
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/modes/interactive/components/fitness-role-selector.d.ts +1 -1
- package/dist/modes/interactive/components/fitness-role-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/fitness-role-selector.js +5 -0
- package/dist/modes/interactive/components/fitness-role-selector.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +1 -0
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +13 -0
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/local-model-commands.d.ts.map +1 -1
- package/dist/modes/interactive/local-model-commands.js +14 -0
- package/dist/modes/interactive/local-model-commands.js.map +1 -1
- package/dist/modes/interactive/session-flow-commands.d.ts +16 -0
- package/dist/modes/interactive/session-flow-commands.d.ts.map +1 -1
- package/dist/modes/interactive/session-flow-commands.js +32 -0
- package/dist/modes/interactive/session-flow-commands.js.map +1 -1
- package/docs/bug-ledger.md +113 -0
- package/docs/models.md +9 -0
- package/docs/providers.md +12 -0
- package/docs/scout.md +4 -2
- package/docs/settings.md +2 -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
|
@@ -1,17 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* AgentSession - Core abstraction for agent lifecycle and session management.
|
|
3
|
-
*
|
|
4
|
-
* This class is shared between all run modes (interactive, print, rpc).
|
|
5
|
-
* It encapsulates:
|
|
6
|
-
* - Agent state access
|
|
7
|
-
* - Event subscription with automatic session persistence
|
|
8
|
-
* - Model and thinking level management
|
|
9
|
-
* - Compaction (manual and auto)
|
|
10
|
-
* - Bash execution
|
|
11
|
-
* - Session switching and branching
|
|
12
|
-
*
|
|
13
|
-
* Modes use this class and add their own I/O layer on top.
|
|
14
|
-
*/
|
|
15
1
|
import { readFileSync } from "node:fs";
|
|
16
2
|
import { basename, dirname, join } from "node:path";
|
|
17
3
|
import { classifyFailure, compactToolResultDetailsForRetention, computeRetryDelayMs, createCustomMessage, DEFAULT_RETRY_POLICY, RetryController, sleepAbortable, withStreamIdleWatchdog, } from "@caupulican/pi-agent-core";
|
|
@@ -30,6 +16,7 @@ import { buildContextCompositionReport, formatContextCompositionDashboard, } fro
|
|
|
30
16
|
import { ContextPipeline } from "./context-pipeline.js";
|
|
31
17
|
import { downgradeReasoning, estimateTurnCostUsd, evaluateCostGuard } from "./cost-guard.js";
|
|
32
18
|
import { appendWorkerResultSnapshot, getWorkerResultSnapshots } from "./delegation/session-worker-result.js";
|
|
19
|
+
import { FailureCorpusRecorder } from "./failure-corpus.js";
|
|
33
20
|
import { GatewayRegistry } from "./gateways/channel-provider.js";
|
|
34
21
|
import { GoalLoopController } from "./goal-loop-controller.js";
|
|
35
22
|
import { buildGoalRuntimeSnapshot, } from "./goals/goal-runtime-snapshot.js";
|
|
@@ -185,6 +172,7 @@ export class AgentSession {
|
|
|
185
172
|
* {@link _runAgentPrompt} so the drive loop stays host-side. */
|
|
186
173
|
_modelRouter;
|
|
187
174
|
_billingFailover;
|
|
175
|
+
_failureCorpus;
|
|
188
176
|
_skillCuratorInstance;
|
|
189
177
|
_disposed = false;
|
|
190
178
|
_reflectionAbort = new AbortController();
|
|
@@ -329,6 +317,12 @@ export class AgentSession {
|
|
|
329
317
|
getModelRegistry: () => this._modelRegistry,
|
|
330
318
|
isRawStream: () => this._isRawStreamSimple(this.agent.streamFn),
|
|
331
319
|
getRequiredRequestAuth: (model) => this._getRequiredRequestAuth(model),
|
|
320
|
+
isModelExhausted: (ref) => this._billingFailover.isExhausted(ref),
|
|
321
|
+
getStoredFitnessReport: (ref) => this.getStoredFitnessReports().find((entry) => entry.model === ref)?.report,
|
|
322
|
+
// Live context is an over-estimate of the span to summarize (includes the kept tail) —
|
|
323
|
+
// conservative in the safe direction for the summarizer capacity check.
|
|
324
|
+
estimateSummarizationInputTokens: () => this._pipeline.estimateCurrentContextTokens(this.agent.state.messages),
|
|
325
|
+
emitWarning: (message) => this._emit({ type: "warning", message }),
|
|
332
326
|
});
|
|
333
327
|
this._pipeline = new ContextPipeline({
|
|
334
328
|
getTurnIndex: () => this._turnIndex,
|
|
@@ -343,12 +337,16 @@ export class AgentSession {
|
|
|
343
337
|
addSpawnedUsage: (usage, opts) => this.addSpawnedUsage(usage, opts),
|
|
344
338
|
runIsolatedCompletion: (opts) => this.runIsolatedCompletion(opts),
|
|
345
339
|
});
|
|
340
|
+
this._failureCorpus = new FailureCorpusRecorder({
|
|
341
|
+
filePath: join(this._agentDir, "state", "failure-corpus.jsonl"),
|
|
342
|
+
});
|
|
346
343
|
this._billingFailover = new BillingFailoverController({
|
|
347
344
|
agent: this.agent,
|
|
348
345
|
modelRegistry: this._modelRegistry,
|
|
349
346
|
exhausted: new ExhaustedProviderRegistry(),
|
|
350
347
|
subscriptionHop: this.settingsManager.getFailoverSettings().subscriptionHop,
|
|
351
348
|
emit: (event) => this._emit(event),
|
|
349
|
+
recordFailure: (args) => this._failureCorpus.record(args),
|
|
352
350
|
});
|
|
353
351
|
this._modelRouter = new ModelRouterController({
|
|
354
352
|
getAgent: () => this.agent,
|
|
@@ -357,7 +355,7 @@ export class AgentSession {
|
|
|
357
355
|
getSessionManager: () => this.sessionManager,
|
|
358
356
|
getModelRegistry: () => this._modelRegistry,
|
|
359
357
|
isModelExhausted: (model) => this._billingFailover.isExhausted(`${model.provider}/${model.id}`),
|
|
360
|
-
getFailoverStatus: () => this._billingFailover.getStatus(),
|
|
358
|
+
getFailoverStatus: () => ({ ...this._billingFailover.getStatus(), failureStats: this._failureCorpus.stats() }),
|
|
361
359
|
getAgentDir: () => this._agentDir,
|
|
362
360
|
getReflectionSignal: () => this._reflectionAbort.signal,
|
|
363
361
|
getBaseSystemPrompt: () => this._baseSystemPrompt,
|
|
@@ -2551,6 +2549,7 @@ export class AgentSession {
|
|
|
2551
2549
|
throw error;
|
|
2552
2550
|
const message = error instanceof Error ? error.message : String(error);
|
|
2553
2551
|
const classified = classifyFailure({ message, provider });
|
|
2552
|
+
this._failureCorpus.record({ provider, message, classified });
|
|
2554
2553
|
if (!classified.retryable)
|
|
2555
2554
|
throw error;
|
|
2556
2555
|
await sleepAbortable(computeRetryDelayMs(policy, attempt, { retryAfterMs: classified.retryAfterMs }), signal);
|
|
@@ -2836,11 +2835,18 @@ export class AgentSession {
|
|
|
2836
2835
|
if (message.stopReason !== "error" || !message.errorMessage)
|
|
2837
2836
|
return false;
|
|
2838
2837
|
const contextWindow = this.model?.contextWindow ?? 0;
|
|
2839
|
-
|
|
2838
|
+
const classified = classifyFailure({
|
|
2840
2839
|
message: message.errorMessage,
|
|
2841
2840
|
contextOverflow: isContextOverflow(message, contextWindow),
|
|
2842
2841
|
provider: message.provider,
|
|
2843
|
-
})
|
|
2842
|
+
});
|
|
2843
|
+
this._failureCorpus.record({
|
|
2844
|
+
provider: message.provider,
|
|
2845
|
+
modelId: message.model,
|
|
2846
|
+
message: message.errorMessage,
|
|
2847
|
+
classified,
|
|
2848
|
+
});
|
|
2849
|
+
return classified.retryable;
|
|
2844
2850
|
}
|
|
2845
2851
|
/**
|
|
2846
2852
|
* Prepare a retryable error for continuation with exponential backoff.
|