@caupulican/pi-adaptative 0.86.17 → 0.90.2
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 +43 -0
- package/README.md +1 -1
- package/dist/bundled-resources/extensions/tmux-agent-manager/index.d.ts.map +1 -1
- package/dist/bundled-resources/extensions/tmux-agent-manager/index.js +14 -15
- package/dist/bundled-resources/extensions/tmux-agent-manager/index.js.map +1 -1
- package/dist/bundled-resources/extensions/tmux-agent-manager/index.ts +14 -16
- package/dist/bundled-resources/skills/worker-profile-writer/SKILL.md +4 -4
- package/dist/core/agent-session.d.ts +23 -33
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +81 -110
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/autonomy/contracts.d.ts +1 -1
- package/dist/core/autonomy/contracts.js.map +1 -1
- package/dist/core/autonomy/gates.d.ts.map +1 -1
- package/dist/core/autonomy/gates.js +16 -0
- package/dist/core/autonomy/gates.js.map +1 -1
- package/dist/core/autonomy/subagent-prompt.d.ts +2 -1
- package/dist/core/autonomy/subagent-prompt.d.ts.map +1 -1
- package/dist/core/autonomy/subagent-prompt.js +2 -18
- package/dist/core/autonomy/subagent-prompt.js.map +1 -1
- package/dist/core/background-tool-task-controller.js +5 -5
- package/dist/core/background-tool-task-controller.js.map +1 -1
- package/dist/core/compaction-controller.d.ts +22 -2
- package/dist/core/compaction-controller.d.ts.map +1 -1
- package/dist/core/compaction-controller.js +75 -39
- package/dist/core/compaction-controller.js.map +1 -1
- package/dist/core/context/brain-curator.d.ts +2 -3
- package/dist/core/context/brain-curator.d.ts.map +1 -1
- package/dist/core/context/brain-curator.js +3 -20
- package/dist/core/context/brain-curator.js.map +1 -1
- package/dist/core/context/context-composition.d.ts +2 -1
- package/dist/core/context/context-composition.d.ts.map +1 -1
- package/dist/core/context/context-composition.js +6 -1
- package/dist/core/context/context-composition.js.map +1 -1
- package/dist/core/context/memory-prompt-block.js +1 -1
- package/dist/core/context/memory-prompt-block.js.map +1 -1
- package/dist/core/context/tool-output-packer.js +1 -1
- package/dist/core/context/tool-output-packer.js.map +1 -1
- package/dist/core/context-gc.js +10 -10
- package/dist/core/context-gc.js.map +1 -1
- package/dist/core/context-pipeline.d.ts +4 -4
- package/dist/core/context-pipeline.js +4 -4
- package/dist/core/context-pipeline.js.map +1 -1
- package/dist/core/default-tool-surface.d.ts.map +1 -1
- package/dist/core/default-tool-surface.js +1 -2
- package/dist/core/default-tool-surface.js.map +1 -1
- package/dist/core/delegation/session-worker-claim.d.ts +2 -2
- package/dist/core/delegation/session-worker-claim.js +2 -2
- package/dist/core/delegation/session-worker-claim.js.map +1 -1
- package/dist/core/delegation/worker-agent-control-coordinator.js +1 -1
- package/dist/core/delegation/worker-agent-control-coordinator.js.map +1 -1
- package/dist/core/delegation/worker-resource-materializer.js +3 -3
- package/dist/core/delegation/worker-resource-materializer.js.map +1 -1
- package/dist/core/delegation/worker-runner.d.ts +2 -13
- package/dist/core/delegation/worker-runner.d.ts.map +1 -1
- package/dist/core/delegation/worker-runner.js +5 -67
- package/dist/core/delegation/worker-runner.js.map +1 -1
- package/dist/core/extensions/builtin.js +4 -4
- package/dist/core/extensions/builtin.js.map +1 -1
- package/dist/core/extensions/runner.d.ts +6 -2
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +21 -9
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/types.d.ts +9 -2
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/foreground-terminal-handoff-controller.js +2 -2
- package/dist/core/foreground-terminal-handoff-controller.js.map +1 -1
- package/dist/core/goals/compact-goal-context.d.ts.map +1 -1
- package/dist/core/goals/compact-goal-context.js +13 -9
- package/dist/core/goals/compact-goal-context.js.map +1 -1
- package/dist/core/goals/goal-continuation-prompt.js +1 -1
- package/dist/core/goals/goal-continuation-prompt.js.map +1 -1
- package/dist/core/goals/goal-session-controller.d.ts +6 -0
- package/dist/core/goals/goal-session-controller.d.ts.map +1 -1
- package/dist/core/goals/goal-session-controller.js +16 -13
- package/dist/core/goals/goal-session-controller.js.map +1 -1
- package/dist/core/human-input-controller.js +1 -1
- package/dist/core/human-input-controller.js.map +1 -1
- package/dist/core/improvement-loop.js +13 -13
- package/dist/core/improvement-loop.js.map +1 -1
- package/dist/core/learning/reflection-engine.d.ts +2 -1
- package/dist/core/learning/reflection-engine.d.ts.map +1 -1
- package/dist/core/learning/reflection-engine.js +4 -24
- package/dist/core/learning/reflection-engine.js.map +1 -1
- package/dist/core/model-capability.d.ts.map +1 -1
- package/dist/core/model-capability.js +1 -1
- package/dist/core/model-capability.js.map +1 -1
- package/dist/core/model-router/route-judge.d.ts +2 -1
- package/dist/core/model-router/route-judge.d.ts.map +1 -1
- package/dist/core/model-router/route-judge.js +4 -12
- package/dist/core/model-router/route-judge.js.map +1 -1
- package/dist/core/models/perf-profile.d.ts +1 -1
- package/dist/core/models/perf-profile.d.ts.map +1 -1
- package/dist/core/models/perf-profile.js +2 -8
- package/dist/core/models/perf-profile.js.map +1 -1
- package/dist/core/orchestration/lane-tool-manifests.d.ts +1 -1
- package/dist/core/orchestration/lane-tool-manifests.d.ts.map +1 -1
- package/dist/core/orchestration/lane-tool-manifests.js +1 -6
- package/dist/core/orchestration/lane-tool-manifests.js.map +1 -1
- package/dist/core/process-matrix/resume-launcher.js +3 -3
- package/dist/core/process-matrix/resume-launcher.js.map +1 -1
- package/dist/core/process-matrix/runtime.d.ts +2 -0
- package/dist/core/process-matrix/runtime.d.ts.map +1 -1
- package/dist/core/process-matrix/runtime.js +23 -19
- package/dist/core/process-matrix/runtime.js.map +1 -1
- package/dist/core/provider-prompt-contracts.d.ts +34 -0
- package/dist/core/provider-prompt-contracts.d.ts.map +1 -0
- package/dist/core/provider-prompt-contracts.js +133 -0
- package/dist/core/provider-prompt-contracts.js.map +1 -0
- package/dist/core/provider-request-context-controller.d.ts +40 -0
- package/dist/core/provider-request-context-controller.d.ts.map +1 -0
- package/dist/core/provider-request-context-controller.js +68 -0
- package/dist/core/provider-request-context-controller.js.map +1 -0
- package/dist/core/provider-request-runtime-controller.d.ts +22 -0
- package/dist/core/provider-request-runtime-controller.d.ts.map +1 -0
- package/dist/core/provider-request-runtime-controller.js +87 -0
- package/dist/core/provider-request-runtime-controller.js.map +1 -0
- package/dist/core/provider-tool-text.d.ts +7 -0
- package/dist/core/provider-tool-text.d.ts.map +1 -0
- package/dist/core/provider-tool-text.js +42 -0
- package/dist/core/provider-tool-text.js.map +1 -0
- package/dist/core/research/model-fitness.d.ts +2 -5
- package/dist/core/research/model-fitness.d.ts.map +1 -1
- package/dist/core/research/model-fitness.js +2 -20
- package/dist/core/research/model-fitness.js.map +1 -1
- package/dist/core/research/research-runner.d.ts +2 -1
- package/dist/core/research/research-runner.d.ts.map +1 -1
- package/dist/core/research/research-runner.js +6 -21
- package/dist/core/research/research-runner.js.map +1 -1
- package/dist/core/risk-classifier.d.ts.map +1 -1
- package/dist/core/risk-classifier.js +9 -1
- package/dist/core/risk-classifier.js.map +1 -1
- package/dist/core/runtime-builder.d.ts +3 -0
- package/dist/core/runtime-builder.d.ts.map +1 -1
- package/dist/core/runtime-builder.js +20 -25
- package/dist/core/runtime-builder.js.map +1 -1
- package/dist/core/scout-controller.d.ts +2 -1
- package/dist/core/scout-controller.d.ts.map +1 -1
- package/dist/core/scout-controller.js +2 -16
- package/dist/core/scout-controller.js.map +1 -1
- package/dist/core/sdk.d.ts +1 -1
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/secrets/credential-exposure-guard.js +6 -6
- package/dist/core/secrets/credential-exposure-guard.js.map +1 -1
- package/dist/core/secrets/credential-manager.d.ts +11 -1
- package/dist/core/secrets/credential-manager.d.ts.map +1 -1
- package/dist/core/secrets/credential-manager.js +28 -7
- package/dist/core/secrets/credential-manager.js.map +1 -1
- package/dist/core/secrets/credential-migration-source.d.ts +20 -0
- package/dist/core/secrets/credential-migration-source.d.ts.map +1 -0
- package/dist/core/secrets/credential-migration-source.js +113 -0
- package/dist/core/secrets/credential-migration-source.js.map +1 -0
- package/dist/core/secrets/credential-session-connection.d.ts +9 -0
- package/dist/core/secrets/credential-session-connection.d.ts.map +1 -0
- package/dist/core/secrets/credential-session-connection.js +39 -0
- package/dist/core/secrets/credential-session-connection.js.map +1 -0
- package/dist/core/security/untrusted-boundary.d.ts +2 -2
- package/dist/core/security/untrusted-boundary.d.ts.map +1 -1
- package/dist/core/security/untrusted-boundary.js +3 -10
- package/dist/core/security/untrusted-boundary.js.map +1 -1
- package/dist/core/session-role.d.ts.map +1 -1
- package/dist/core/session-role.js +1 -2
- package/dist/core/session-role.js.map +1 -1
- package/dist/core/skill-vault.d.ts +98 -0
- package/dist/core/skill-vault.d.ts.map +1 -0
- package/dist/core/skill-vault.js +270 -0
- package/dist/core/skill-vault.js.map +1 -0
- package/dist/core/skills.d.ts +10 -9
- package/dist/core/skills.d.ts.map +1 -1
- package/dist/core/skills.js +42 -50
- package/dist/core/skills.js.map +1 -1
- package/dist/core/system-prompt-builder.d.ts +1 -1
- package/dist/core/system-prompt-builder.d.ts.map +1 -1
- package/dist/core/system-prompt-builder.js +20 -60
- package/dist/core/system-prompt-builder.js.map +1 -1
- package/dist/core/system-prompt.d.ts +4 -4
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +87 -121
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/tasks/task-state.d.ts.map +1 -1
- package/dist/core/tasks/task-state.js +6 -7
- package/dist/core/tasks/task-state.js.map +1 -1
- package/dist/core/tool-capability-policy.d.ts.map +1 -1
- package/dist/core/tool-capability-policy.js +2 -1
- package/dist/core/tool-capability-policy.js.map +1 -1
- package/dist/core/tool-protocol-controller.d.ts.map +1 -1
- package/dist/core/tool-protocol-controller.js +4 -7
- package/dist/core/tool-protocol-controller.js.map +1 -1
- package/dist/core/tool-selection/promotion.d.ts.map +1 -1
- package/dist/core/tool-selection/promotion.js +2 -6
- package/dist/core/tool-selection/promotion.js.map +1 -1
- package/dist/core/toolkit/reflex-interpreter.d.ts +2 -1
- package/dist/core/toolkit/reflex-interpreter.d.ts.map +1 -1
- package/dist/core/toolkit/reflex-interpreter.js +2 -14
- package/dist/core/toolkit/reflex-interpreter.js.map +1 -1
- package/dist/core/tools/ask-question.js +6 -6
- package/dist/core/tools/ask-question.js.map +1 -1
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +8 -7
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/delegate-status.d.ts +17 -13
- package/dist/core/tools/delegate-status.d.ts.map +1 -1
- package/dist/core/tools/delegate-status.js +111 -226
- package/dist/core/tools/delegate-status.js.map +1 -1
- package/dist/core/tools/delegate.d.ts +29 -2
- package/dist/core/tools/delegate.d.ts.map +1 -1
- package/dist/core/tools/delegate.js +149 -48
- package/dist/core/tools/delegate.js.map +1 -1
- package/dist/core/tools/edit.js +3 -3
- package/dist/core/tools/edit.js.map +1 -1
- package/dist/core/tools/extensionify-runtime.js +4 -4
- package/dist/core/tools/extensionify-runtime.js.map +1 -1
- package/dist/core/tools/find.d.ts.map +1 -1
- package/dist/core/tools/find.js +2 -4
- package/dist/core/tools/find.js.map +1 -1
- package/dist/core/tools/goal.js +3 -3
- package/dist/core/tools/goal.js.map +1 -1
- package/dist/core/tools/grep.js +2 -2
- package/dist/core/tools/grep.js.map +1 -1
- package/dist/core/tools/index.d.ts +1 -1
- package/dist/core/tools/index.d.ts.map +1 -1
- package/dist/core/tools/index.js +1 -1
- package/dist/core/tools/index.js.map +1 -1
- package/dist/core/tools/model-fitness.js +4 -4
- package/dist/core/tools/model-fitness.js.map +1 -1
- package/dist/core/tools/profile-writer.d.ts +30 -16
- package/dist/core/tools/profile-writer.d.ts.map +1 -1
- package/dist/core/tools/profile-writer.js +98 -59
- package/dist/core/tools/profile-writer.js.map +1 -1
- package/dist/core/tools/python.js +6 -6
- package/dist/core/tools/python.js.map +1 -1
- package/dist/core/tools/run-process.js +4 -4
- package/dist/core/tools/run-process.js.map +1 -1
- package/dist/core/tools/run-toolkit-script.js +4 -4
- package/dist/core/tools/run-toolkit-script.js.map +1 -1
- package/dist/core/tools/secret-store.d.ts +32 -3
- package/dist/core/tools/secret-store.d.ts.map +1 -1
- package/dist/core/tools/secret-store.js +141 -34
- package/dist/core/tools/secret-store.js.map +1 -1
- package/dist/core/tools/skill.d.ts +29 -0
- package/dist/core/tools/skill.d.ts.map +1 -0
- package/dist/core/tools/skill.js +79 -0
- package/dist/core/tools/skill.js.map +1 -0
- package/dist/core/tools/task-steps.js +4 -4
- package/dist/core/tools/task-steps.js.map +1 -1
- package/dist/core/tools/tool-definition-wrapper.d.ts.map +1 -1
- package/dist/core/tools/tool-definition-wrapper.js +2 -0
- package/dist/core/tools/tool-definition-wrapper.js.map +1 -1
- package/dist/core/tools/tool-task.d.ts.map +1 -1
- package/dist/core/tools/tool-task.js +4 -0
- package/dist/core/tools/tool-task.js.map +1 -1
- package/dist/core/tools/worktree-sync.js +6 -6
- package/dist/core/tools/worktree-sync.js.map +1 -1
- package/dist/core/tools/write.js +3 -3
- package/dist/core/tools/write.js.map +1 -1
- package/dist/index.d.ts +5 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/modes/interactive/interactive-event-controller.js +1 -1
- package/dist/modes/interactive/interactive-event-controller.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +1 -1
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/report-commands.js +1 -1
- package/dist/modes/interactive/report-commands.js.map +1 -1
- package/dist/modes/interactive/secret-menu-controller.d.ts.map +1 -1
- package/dist/modes/interactive/secret-menu-controller.js +2 -18
- package/dist/modes/interactive/secret-menu-controller.js.map +1 -1
- package/dist/modes/interactive/session-flow-commands.js +1 -1
- package/dist/modes/interactive/session-flow-commands.js.map +1 -1
- package/docs/compaction.md +45 -25
- package/docs/extensions.md +23 -7
- package/docs/settings.md +3 -3
- package/docs/skills.md +14 -10
- package/docs/task-steps.md +2 -2
- package/docs/tmux-agent-manager.md +1 -1
- package/docs/tool-repair.md +18 -1
- package/docs/usage.md +4 -2
- package/docs/worker-profiles.md +3 -3
- package/docs/worktree-sync.md +2 -2
- package/examples/extensions/custom-compaction.ts +5 -17
- 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/summarize.ts +3 -5
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/examples/sdk/04-skills.ts +1 -1
- package/npm-shrinkwrap.json +12 -12
- package/package.json +4 -4
- package/dist/core/util/json-size.d.ts +0 -3
- package/dist/core/util/json-size.d.ts.map +0 -1
- package/dist/core/util/json-size.js +0 -95
- package/dist/core/util/json-size.js.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
|
-
import { readFileSync } from "node:fs";
|
|
3
2
|
import { basename, dirname } from "node:path";
|
|
3
|
+
import { projectToolsForProvider } from "@caupulican/pi-agent-core";
|
|
4
4
|
import { AgentBusyError } from "@caupulican/pi-agent-core/agent";
|
|
5
5
|
import { compactToolResultDetailsForRetention } from "@caupulican/pi-agent-core/message-retention";
|
|
6
6
|
import { createCustomMessage } from "@caupulican/pi-agent-core/messages";
|
|
@@ -9,7 +9,6 @@ import { getSupportedThinkingLevels, modelsAreEqual } from "@caupulican/pi-ai/mo
|
|
|
9
9
|
import { cleanupSessionResources } from "@caupulican/pi-ai/session-resources";
|
|
10
10
|
import { streamSimple } from "@caupulican/pi-ai/stream";
|
|
11
11
|
import { getAgentDir } from "../config.js";
|
|
12
|
-
import { stripFrontmatter } from "../utils/frontmatter.js";
|
|
13
12
|
import { resourceDir, stateFile } from "./agent-paths.js";
|
|
14
13
|
import { formatNoApiKeyFoundMessage, formatNoModelSelectedMessage } from "./auth-guidance.js";
|
|
15
14
|
import { buildForegroundEnvelope, formatForegroundEnvelopeObservation } from "./autonomy/foreground-envelope.js";
|
|
@@ -28,12 +27,11 @@ import { FailureCorpusRecorder } from "./failure-corpus.js";
|
|
|
28
27
|
import { ForegroundRecoveryController } from "./foreground-recovery-controller.js";
|
|
29
28
|
import { ForegroundTerminalHandoffController } from "./foreground-terminal-handoff-controller.js";
|
|
30
29
|
import { GatewayRegistry } from "./gateways/channel-provider.js";
|
|
31
|
-
import { injectCompactGoalContext } from "./goals/compact-goal-context.js";
|
|
32
30
|
import { GoalSessionController } from "./goals/goal-session-controller.js";
|
|
33
31
|
import { constrainStreamIdleToHttpTimeout } from "./http-dispatcher.js";
|
|
34
32
|
import { HumanInputController } from "./human-input-controller.js";
|
|
35
33
|
import { appendLearningDecisionSnapshot, getLearningDecisionSnapshots } from "./learning/session-learning-decision.js";
|
|
36
|
-
import {
|
|
34
|
+
import { SkillCurator } from "./learning/skill-curator.js";
|
|
37
35
|
import { LocalRuntimeController } from "./local-runtime-controller.js";
|
|
38
36
|
import { MemoryController } from "./memory-controller.js";
|
|
39
37
|
import { deriveModelCapabilityProfile, evaluateLaneWorkerRefusal, filterToolNamesForCapability, } from "./model-capability.js";
|
|
@@ -48,15 +46,17 @@ import { resolveConfiguredOrchestrationModel } from "./orchestration/model-bindi
|
|
|
48
46
|
import { validateOrchestrationProfile } from "./orchestration/profile-registry.js";
|
|
49
47
|
import { ProfileFilterController } from "./profile-filter-controller.js";
|
|
50
48
|
import { expandPromptTemplate } from "./prompt-templates.js";
|
|
49
|
+
import { ProviderRequestContextController } from "./provider-request-context-controller.js";
|
|
50
|
+
import { ProviderRequestRuntimeController } from "./provider-request-runtime-controller.js";
|
|
51
51
|
import { ReflectionController } from "./reflection-controller.js";
|
|
52
52
|
import { appendEvidenceBundleSnapshot, getEvidenceBundleSnapshots, getLatestEvidenceBundleSnapshot, } from "./research/session-evidence-bundle.js";
|
|
53
53
|
import { collectWorkspaceSources } from "./research/workspace-collector.js";
|
|
54
|
-
import { stripResourceProfileBlocks } from "./resource-profile-blocks.js";
|
|
55
54
|
import { RuntimeBuilder } from "./runtime-builder.js";
|
|
56
55
|
import { SessionAnalytics } from "./session-analytics.js";
|
|
57
56
|
import { SessionImageStore } from "./session-image-store.js";
|
|
58
57
|
import { getActiveSessionBranchEntries } from "./session-snapshot.js";
|
|
59
58
|
import { SessionTreeNavigator } from "./session-tree-navigator.js";
|
|
59
|
+
import { resolveActiveSkillBodyByteLimit, SkillVaultController } from "./skill-vault.js";
|
|
60
60
|
import { SystemPromptBuilder } from "./system-prompt-builder.js";
|
|
61
61
|
import { appendTaskStepsStateSnapshot, getLatestTaskStepsStateSnapshot } from "./tasks/session-task-state.js";
|
|
62
62
|
import { formatTaskStepsContext } from "./tasks/task-state.js";
|
|
@@ -167,6 +167,9 @@ export class AgentSession {
|
|
|
167
167
|
}
|
|
168
168
|
}
|
|
169
169
|
}
|
|
170
|
+
if (event.type === "turn_end" || event.type === "tool_execution_start" || event.type === "tool_execution_end") {
|
|
171
|
+
this._skillVault.noteActivity();
|
|
172
|
+
}
|
|
170
173
|
if (event.type === "tool_execution_end" && event.isError) {
|
|
171
174
|
this._toolRecoveryLogger.recordToolExecutionFailure({
|
|
172
175
|
provider: this.model?.provider,
|
|
@@ -174,6 +177,9 @@ export class AgentSession {
|
|
|
174
177
|
tool: event.toolName,
|
|
175
178
|
details: event.result.details,
|
|
176
179
|
});
|
|
180
|
+
if (event.result.terminate === true) {
|
|
181
|
+
this._goals.markTerminalToolFailureBlocked(event.toolName);
|
|
182
|
+
}
|
|
177
183
|
}
|
|
178
184
|
// Emit to extensions first
|
|
179
185
|
await this._emitExtensionEvent(event);
|
|
@@ -303,6 +309,14 @@ export class AgentSession {
|
|
|
303
309
|
this._customTools = config.customTools ?? [];
|
|
304
310
|
this._cwd = config.cwd;
|
|
305
311
|
this._agentDir = agentDir;
|
|
312
|
+
this._skillVault = new SkillVaultController({
|
|
313
|
+
getSkills: () => this._resourceLoader.getActiveSkills(),
|
|
314
|
+
getMaxBodyBytes: () => resolveActiveSkillBodyByteLimit(this.model?.contextWindow),
|
|
315
|
+
onSkillUsed: (skill) => {
|
|
316
|
+
if (skill.promoted)
|
|
317
|
+
this._skillCurator.recordUse(skill.name, Date.now());
|
|
318
|
+
},
|
|
319
|
+
});
|
|
306
320
|
this._toolProtocol = new ToolProtocolController({
|
|
307
321
|
agent: this.agent,
|
|
308
322
|
agentDir: this._agentDir,
|
|
@@ -515,6 +529,31 @@ export class AgentSession {
|
|
|
515
529
|
runAutoCompaction: (reason, willRetry) => this._runAutoCompaction(reason, willRetry),
|
|
516
530
|
compactWithRetry: (run, signal, provider) => this._compactWithRetry(run, signal, provider),
|
|
517
531
|
});
|
|
532
|
+
const providerRequestContext = new ProviderRequestContextController({
|
|
533
|
+
transformExtensions: async (messages) => {
|
|
534
|
+
const runner = this._extensionRunner;
|
|
535
|
+
const projection = runner.hasHandlers("context")
|
|
536
|
+
? await runner.emitContext(messages)
|
|
537
|
+
: { messages, transientMessages: [] };
|
|
538
|
+
return { ...projection, isCurrent: () => this._extensionRunner === runner };
|
|
539
|
+
},
|
|
540
|
+
runContextAudit: (messages) => this._runContextAudit(messages),
|
|
541
|
+
runPromptPolicyPlanning: (report) => this._runPromptPolicyPlanning(report),
|
|
542
|
+
runMemoryRetrieval: (messages) => this._runMemoryRetrieval(messages),
|
|
543
|
+
applyContextGc: (messages, writePayloads) => this._applyContextGc(messages, writePayloads),
|
|
544
|
+
correlatePromptPolicyWithContextGc: (report) => this._correlatePromptPolicyWithContextGc(report),
|
|
545
|
+
runPromptEnforcement: (messages, report) => this._runPromptEnforcement(messages, report),
|
|
546
|
+
enqueueRelevanceCuration: (messages, report) => this._enqueueRelevanceCuration(messages, report),
|
|
547
|
+
maybeDrainBrainCuration: () => this._maybeDrainBrainCuration(),
|
|
548
|
+
appendMemoryEvidence: (messages, report) => this._maybeAppendMemoryEvidenceBlock(messages, report),
|
|
549
|
+
getGoalState: () => this.getGoalStateSnapshot(),
|
|
550
|
+
skillVault: this._skillVault,
|
|
551
|
+
});
|
|
552
|
+
this._providerRequestRuntime = new ProviderRequestRuntimeController({
|
|
553
|
+
agent: this.agent,
|
|
554
|
+
compaction: this._compaction,
|
|
555
|
+
context: providerRequestContext,
|
|
556
|
+
});
|
|
518
557
|
this._toolRecoveryLogger = new ToolRecoveryLogger({
|
|
519
558
|
enabled: toolRepairSettings.logging,
|
|
520
559
|
sessionId: this.sessionManager.getSessionId(),
|
|
@@ -621,6 +660,7 @@ export class AgentSession {
|
|
|
621
660
|
getModelRegistry: () => this._modelRegistry,
|
|
622
661
|
isModelExhausted: (model) => this._foregroundRecovery.isModelExhausted(`${model.provider}/${model.id}`),
|
|
623
662
|
getResourceLoader: () => this._resourceLoader,
|
|
663
|
+
getSkillVault: () => this._skillVault,
|
|
624
664
|
getExtensionRunner: () => this._extensionRunner,
|
|
625
665
|
setExtensionRunner: (runner) => {
|
|
626
666
|
this._extensionRunner = runner;
|
|
@@ -820,7 +860,7 @@ export class AgentSession {
|
|
|
820
860
|
// (session persistence, extensions, auto-compaction, retry logic)
|
|
821
861
|
this._unsubscribeAgent = this.agent.subscribe(this._handleAgentEvent);
|
|
822
862
|
this._installAgentToolHooks();
|
|
823
|
-
this.
|
|
863
|
+
this._providerRequestRuntime.install();
|
|
824
864
|
this._installAgentTurnRefresh();
|
|
825
865
|
this._runtimeBuilder.buildRuntime({
|
|
826
866
|
activeToolNames: this._initialActiveToolNames,
|
|
@@ -881,7 +921,7 @@ export class AgentSession {
|
|
|
881
921
|
return;
|
|
882
922
|
const stream = await this.agent.streamFn(model, {
|
|
883
923
|
systemPrompt: this._baseSystemPrompt,
|
|
884
|
-
tools: this.agent.state.tools,
|
|
924
|
+
tools: projectToolsForProvider(this.agent.state.tools),
|
|
885
925
|
messages: [],
|
|
886
926
|
}, options);
|
|
887
927
|
await stream.result();
|
|
@@ -953,54 +993,6 @@ export class AgentSession {
|
|
|
953
993
|
_resolveCompactionThinkingLevel(compactionModel, sessionModel) {
|
|
954
994
|
return this._compactionSupport.resolveThinkingLevel(this.thinkingLevel, compactionModel, sessionModel);
|
|
955
995
|
}
|
|
956
|
-
/**
|
|
957
|
-
* Install tool hooks once on the Agent instance.
|
|
958
|
-
*
|
|
959
|
-
* The callbacks read `this._extensionRunner` at execution time, so extension reload swaps in the
|
|
960
|
-
* new runner without reinstalling hooks. Extension-specific tool wrappers are still used to adapt
|
|
961
|
-
* registered tool execution to the extension context. Tool call and tool result interception now
|
|
962
|
-
* happens here instead of in wrappers.
|
|
963
|
-
*/
|
|
964
|
-
_installAgentContextTransform() {
|
|
965
|
-
const previousTransformContext = this.agent.transformContext?.bind(this.agent);
|
|
966
|
-
this.agent.transformContext = async (messages, signal) => {
|
|
967
|
-
const transformed = previousTransformContext ? await previousTransformContext(messages, signal) : messages;
|
|
968
|
-
// The agent loop may deliberately project a safer request context (for example, removing a
|
|
969
|
-
// failed mutation attempt after retaining its payload). Replacing that projection with raw
|
|
970
|
-
// session state would disclose the discarded attempt and defeat tool-failure repair.
|
|
971
|
-
const authoritativeMessages = transformed;
|
|
972
|
-
let currentMessages = authoritativeMessages;
|
|
973
|
-
try {
|
|
974
|
-
if (!this.isCompacting &&
|
|
975
|
-
(await this._compaction.maybeCompactBeforeContextTransform(authoritativeMessages, (messages) => this._applyContextGc(messages, false).messages))) {
|
|
976
|
-
currentMessages = this.agent.state.messages.slice();
|
|
977
|
-
}
|
|
978
|
-
}
|
|
979
|
-
catch {
|
|
980
|
-
currentMessages = authoritativeMessages;
|
|
981
|
-
}
|
|
982
|
-
let finalMessages = currentMessages;
|
|
983
|
-
if (this._extensionRunner.hasHandlers("context")) {
|
|
984
|
-
finalMessages = await this._extensionRunner.emitContext(currentMessages);
|
|
985
|
-
}
|
|
986
|
-
const auditReport = this._runContextAudit(finalMessages);
|
|
987
|
-
const shadowReport = this._runPromptPolicyPlanning(auditReport);
|
|
988
|
-
const memoryReport = await this._runMemoryRetrieval(finalMessages);
|
|
989
|
-
const gcResult = this._applyContextGc(finalMessages, true);
|
|
990
|
-
this._correlatePromptPolicyWithContextGc(gcResult.report);
|
|
991
|
-
const enforcementResult = this._runPromptEnforcement(gcResult.messages, shadowReport);
|
|
992
|
-
this._enqueueRelevanceCuration(gcResult.messages, shadowReport);
|
|
993
|
-
// Fire-and-forget: the local curator overlaps the frontier call; it never blocks a turn.
|
|
994
|
-
this._maybeDrainBrainCuration();
|
|
995
|
-
// Appended LAST, after gc and enforcement, so the bounded evidence block is
|
|
996
|
-
// never packed/stubbed/reshaped by either pass and always reflects this turn's
|
|
997
|
-
// fresh retrieval. Because nothing downstream trims it, memory-prompt-block.ts's
|
|
998
|
-
// character caps are the only budget protection for this block -- load-bearing,
|
|
999
|
-
// not merely defensive.
|
|
1000
|
-
const gcMessages = this._maybeAppendMemoryEvidenceBlock(enforcementResult.messages, memoryReport);
|
|
1001
|
-
return injectCompactGoalContext(gcMessages, this.getGoalStateSnapshot());
|
|
1002
|
-
};
|
|
1003
|
-
}
|
|
1004
996
|
/**
|
|
1005
997
|
* Resolve the foreground request's cost policy after routing/context conversion, when the actual
|
|
1006
998
|
* model, full system prompt, converted messages, and tool schemas are known. The guard is a
|
|
@@ -1139,8 +1131,8 @@ export class AgentSession {
|
|
|
1139
1131
|
});
|
|
1140
1132
|
}
|
|
1141
1133
|
/**
|
|
1142
|
-
*
|
|
1143
|
-
* one-line method
|
|
1134
|
+
* Provider-plan hot-path delegation to {@link ContextPipeline.runContextAudit}. Kept as a
|
|
1135
|
+
* one-line method so the request context controller owns pass ordering.
|
|
1144
1136
|
*/
|
|
1145
1137
|
_runContextAudit(messages) {
|
|
1146
1138
|
return this._pipeline.runContextAudit(messages);
|
|
@@ -1150,8 +1142,8 @@ export class AgentSession {
|
|
|
1150
1142
|
return this._pipeline.getContextAuditReport(messages);
|
|
1151
1143
|
}
|
|
1152
1144
|
/**
|
|
1153
|
-
*
|
|
1154
|
-
*
|
|
1145
|
+
* Provider-plan hot-path delegation to {@link ContextPipeline.runPromptPolicyPlanning}. Kept as a
|
|
1146
|
+
* one-line method so the request context controller owns pass ordering.
|
|
1155
1147
|
*/
|
|
1156
1148
|
_runPromptPolicyPlanning(auditReport) {
|
|
1157
1149
|
return this._pipeline.runPromptPolicyPlanning(auditReport);
|
|
@@ -1161,8 +1153,8 @@ export class AgentSession {
|
|
|
1161
1153
|
return this._pipeline.getPromptPolicyReport(messages);
|
|
1162
1154
|
}
|
|
1163
1155
|
/**
|
|
1164
|
-
*
|
|
1165
|
-
* Kept as a one-line method
|
|
1156
|
+
* Provider-plan commit delegation to {@link ContextPipeline.correlatePromptPolicyWithContextGc}.
|
|
1157
|
+
* Kept as a one-line method so the request context controller owns pass ordering.
|
|
1166
1158
|
*/
|
|
1167
1159
|
_correlatePromptPolicyWithContextGc(gcReport) {
|
|
1168
1160
|
this._pipeline.correlatePromptPolicyWithContextGc(gcReport);
|
|
@@ -1172,15 +1164,15 @@ export class AgentSession {
|
|
|
1172
1164
|
return this._pipeline.getPromptPolicyGcCorrelation();
|
|
1173
1165
|
}
|
|
1174
1166
|
/**
|
|
1175
|
-
*
|
|
1176
|
-
* one-line method
|
|
1167
|
+
* Provider-plan hot-path delegation to {@link ContextPipeline.runPromptEnforcement}. Kept as a
|
|
1168
|
+
* one-line method so the request context controller owns pass ordering.
|
|
1177
1169
|
*/
|
|
1178
1170
|
_runPromptEnforcement(messages, shadowReport) {
|
|
1179
1171
|
return this._pipeline.runPromptEnforcement(messages, shadowReport);
|
|
1180
1172
|
}
|
|
1181
1173
|
/**
|
|
1182
|
-
*
|
|
1183
|
-
*
|
|
1174
|
+
* Provider-plan commit delegation to {@link ContextPipeline.enqueueRelevanceCuration}. Kept as a
|
|
1175
|
+
* one-line method so the request context controller owns pass ordering.
|
|
1184
1176
|
*/
|
|
1185
1177
|
_enqueueRelevanceCuration(messages, shadowReport) {
|
|
1186
1178
|
this._pipeline.enqueueRelevanceCuration(messages, shadowReport);
|
|
@@ -1190,8 +1182,8 @@ export class AgentSession {
|
|
|
1190
1182
|
return this._pipeline.resolveCurationModelIfFit();
|
|
1191
1183
|
}
|
|
1192
1184
|
/**
|
|
1193
|
-
*
|
|
1194
|
-
* one-line method
|
|
1185
|
+
* Provider-plan commit delegation to {@link ContextPipeline.maybeDrainBrainCuration}. Kept as a
|
|
1186
|
+
* one-line method so the request context controller owns pass ordering.
|
|
1195
1187
|
*/
|
|
1196
1188
|
_maybeDrainBrainCuration() {
|
|
1197
1189
|
this._pipeline.maybeDrainBrainCuration();
|
|
@@ -1219,7 +1211,7 @@ export class AgentSession {
|
|
|
1219
1211
|
getContextCompositionReport() {
|
|
1220
1212
|
const rawMessages = this.agent.state.messages.slice();
|
|
1221
1213
|
const gcResult = this._applyContextGc(rawMessages, false);
|
|
1222
|
-
const
|
|
1214
|
+
const requestMessages = this._skillVault.previewContext(gcResult.messages);
|
|
1223
1215
|
const extensions = this._resourceLoader.getExtensions().extensions;
|
|
1224
1216
|
const extensionToolNames = new Set(extensions.flatMap((extension) => [...extension.tools.keys()]));
|
|
1225
1217
|
const usage = this.getContextUsage();
|
|
@@ -1235,11 +1227,10 @@ export class AgentSession {
|
|
|
1235
1227
|
.reduce((sum, item) => sum + Math.max(0, Math.ceil((item.originalChars ?? 0) / 4) - 50), 0);
|
|
1236
1228
|
return buildContextCompositionReport({
|
|
1237
1229
|
systemPrompt: this.systemPrompt ?? "",
|
|
1238
|
-
tools: this.
|
|
1239
|
-
.filter((tool) => activeNames.has(tool.name))
|
|
1240
|
-
.map((tool) => ({
|
|
1230
|
+
tools: this.agent.state.tools.map((tool) => ({
|
|
1241
1231
|
name: tool.name,
|
|
1242
1232
|
description: tool.description,
|
|
1233
|
+
providerDescription: tool.providerDescription,
|
|
1243
1234
|
parameters: tool.parameters,
|
|
1244
1235
|
source: extensionToolNames.has(tool.name) ? "extension" : "built-in",
|
|
1245
1236
|
})),
|
|
@@ -1249,7 +1240,7 @@ export class AgentSession {
|
|
|
1249
1240
|
toolNames: [...extension.tools.keys()],
|
|
1250
1241
|
commandCount: extension.commands.size,
|
|
1251
1242
|
})),
|
|
1252
|
-
messages:
|
|
1243
|
+
messages: requestMessages,
|
|
1253
1244
|
providerReportedTokens: usage?.tokens ?? null,
|
|
1254
1245
|
contextWindow: usage?.contextWindow ?? this.model?.contextWindow ?? null,
|
|
1255
1246
|
gc: { packedCount: gcResult.report.packedCount, savedTokens: gcResult.report.savedTokens },
|
|
@@ -1309,8 +1300,8 @@ export class AgentSession {
|
|
|
1309
1300
|
return this._pipeline.getPromptEnforcementReport();
|
|
1310
1301
|
}
|
|
1311
1302
|
/**
|
|
1312
|
-
*
|
|
1313
|
-
* one-line method
|
|
1303
|
+
* Provider-plan hot-path delegation to {@link MemoryController.runMemoryRetrieval}. Kept as a
|
|
1304
|
+
* one-line method so the request context controller owns pass ordering.
|
|
1314
1305
|
*/
|
|
1315
1306
|
_runMemoryRetrieval(messages) {
|
|
1316
1307
|
return this._memory.runMemoryRetrieval(messages);
|
|
@@ -1320,8 +1311,8 @@ export class AgentSession {
|
|
|
1320
1311
|
return this._memory.getMemoryRetrievalReport();
|
|
1321
1312
|
}
|
|
1322
1313
|
/**
|
|
1323
|
-
*
|
|
1324
|
-
* Kept as a one-line method
|
|
1314
|
+
* Provider-plan hot-path delegation to {@link MemoryController.maybeAppendMemoryEvidenceBlock}.
|
|
1315
|
+
* Kept as a one-line method so the request context controller owns pass ordering.
|
|
1325
1316
|
*/
|
|
1326
1317
|
_maybeAppendMemoryEvidenceBlock(messages, report) {
|
|
1327
1318
|
return this._memory.maybeAppendMemoryEvidenceBlock(messages, report);
|
|
@@ -1331,8 +1322,8 @@ export class AgentSession {
|
|
|
1331
1322
|
return this._memory.getMemoryPromptInclusionReport();
|
|
1332
1323
|
}
|
|
1333
1324
|
/**
|
|
1334
|
-
*
|
|
1335
|
-
* one-line method
|
|
1325
|
+
* Provider-plan hot-path delegation to {@link ContextPipeline.applyContextGc}. Kept as a
|
|
1326
|
+
* one-line method so the request context controller owns pass ordering;
|
|
1336
1327
|
* also serves the composition dashboard and {@link getContextGcReport} read-only paths.
|
|
1337
1328
|
*/
|
|
1338
1329
|
_applyContextGc(messages, writePayloads) {
|
|
@@ -1358,6 +1349,7 @@ export class AgentSession {
|
|
|
1358
1349
|
* warning through the same event the context-window/compaction backstops use.
|
|
1359
1350
|
*/
|
|
1360
1351
|
_handleRunawayStop(info) {
|
|
1352
|
+
const goalBlocked = this._goals.markRunawayBlocked(info);
|
|
1361
1353
|
const record = {
|
|
1362
1354
|
signature: info.signature,
|
|
1363
1355
|
repeats: info.repeats,
|
|
@@ -1368,7 +1360,7 @@ export class AgentSession {
|
|
|
1368
1360
|
this.sessionManager.appendCustomEntry(RUNAWAY_STOP_CUSTOM_TYPE, record);
|
|
1369
1361
|
this._emit({
|
|
1370
1362
|
type: "warning",
|
|
1371
|
-
message: `Stopped: the model repeated the same tool call ${info.repeats} times in a row without making progress. Review the last tool result and steer or retry with a different approach.`,
|
|
1363
|
+
message: `Stopped: the model repeated the same tool call ${info.repeats} times in a row without making progress.${goalBlocked ? " The active goal was blocked to prevent automatic restart." : ""} Review the last tool result and steer or retry with a different approach.`,
|
|
1372
1364
|
});
|
|
1373
1365
|
}
|
|
1374
1366
|
/**
|
|
@@ -1659,6 +1651,7 @@ export class AgentSession {
|
|
|
1659
1651
|
safely(() => this.abortCompaction());
|
|
1660
1652
|
safely(() => this.abortBranchSummary());
|
|
1661
1653
|
safely(() => this.abortBash());
|
|
1654
|
+
safely(() => this._skillVault.unload());
|
|
1662
1655
|
safely(() => disposeShellExecutionSession(this._shellSessionKey));
|
|
1663
1656
|
safely(() => this._cancelPrefixWarm());
|
|
1664
1657
|
safely(() => this.agent.abort());
|
|
@@ -1668,11 +1661,11 @@ export class AgentSession {
|
|
|
1668
1661
|
safely(() => this._reflection.cancelScheduled());
|
|
1669
1662
|
safely(() => this._reflectionAbort.abort());
|
|
1670
1663
|
safely(() => this._backgroundLanes.abortInFlightLanes());
|
|
1664
|
+
safely(() => this._providerRequestRuntime.dispose());
|
|
1671
1665
|
safely(() => {
|
|
1672
1666
|
this.agent.afterToolCall = undefined;
|
|
1673
1667
|
this.agent.handoffToolCall = undefined;
|
|
1674
1668
|
this.agent.subscribeToolCallHandoffRequest = undefined;
|
|
1675
|
-
this.agent.transformContext = undefined;
|
|
1676
1669
|
});
|
|
1677
1670
|
safely(() => this._extensionRunner.invalidate());
|
|
1678
1671
|
safely(() => this._disconnectFromAgent());
|
|
@@ -1815,9 +1808,6 @@ export class AgentSession {
|
|
|
1815
1808
|
validToolNames.includes("ask_question")) {
|
|
1816
1809
|
addIfRegistered("artifact_retrieve");
|
|
1817
1810
|
}
|
|
1818
|
-
if (validToolNames.includes("delegate")) {
|
|
1819
|
-
addIfRegistered("delegate_status");
|
|
1820
|
-
}
|
|
1821
1811
|
this.agent.state.tools = tools;
|
|
1822
1812
|
// Rebuild base system prompt with new tool set
|
|
1823
1813
|
this._baseSystemPrompt = this._rebuildSystemPrompt(validToolNames);
|
|
@@ -2309,42 +2299,23 @@ export class AgentSession {
|
|
|
2309
2299
|
return true;
|
|
2310
2300
|
}
|
|
2311
2301
|
}
|
|
2312
|
-
/**
|
|
2313
|
-
* Expand skill commands (/skill:name args) to their full content.
|
|
2314
|
-
* Returns the expanded text, or the original text if not a skill command or skill not found.
|
|
2315
|
-
* Emits errors via extension runner if file read fails.
|
|
2316
|
-
*/
|
|
2302
|
+
/** Route explicit /skill:name through the same host-owned vault as model tool calls. */
|
|
2317
2303
|
_expandSkillCommand(text) {
|
|
2318
2304
|
if (!text.startsWith("/skill:"))
|
|
2319
2305
|
return text;
|
|
2320
2306
|
const spaceIndex = text.indexOf(" ");
|
|
2321
2307
|
const skillName = spaceIndex === -1 ? text.slice(7) : text.slice(7, spaceIndex);
|
|
2322
2308
|
const args = spaceIndex === -1 ? "" : text.slice(spaceIndex + 1).trim();
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
const skill = this.resourceLoader.getActiveSkills().find((s) => s.name === skillName);
|
|
2326
|
-
if (!skill)
|
|
2327
|
-
return text; // Unknown or profile-blocked skill, pass through unchanged
|
|
2328
|
-
try {
|
|
2329
|
-
const content = readFileSync(skill.filePath, "utf-8");
|
|
2330
|
-
// Curator (#32): record use of a reflection-PROMOTED skill so stale ones can later be proposed
|
|
2331
|
-
// for archival. Only promoted skills carry the marker, so hand-authored skills are untouched.
|
|
2332
|
-
if (isPromotedFrontmatter(content)) {
|
|
2333
|
-
this._skillCurator.recordUse(skill.name, Date.now());
|
|
2334
|
-
}
|
|
2335
|
-
const body = stripResourceProfileBlocks(stripFrontmatter(content)).trim();
|
|
2336
|
-
const skillBlock = `<skill name="${skill.name}" location="${skill.filePath}">\nReferences are relative to ${skill.baseDir}.\n\n${body}\n</skill>`;
|
|
2337
|
-
return args ? `${skillBlock}\n\n${args}` : skillBlock;
|
|
2338
|
-
}
|
|
2339
|
-
catch (err) {
|
|
2340
|
-
// Emit error like extension commands do
|
|
2309
|
+
const result = this._skillVault.load(skillName, "user");
|
|
2310
|
+
if (!result.ok) {
|
|
2341
2311
|
this._extensionRunner.emitError({
|
|
2342
|
-
extensionPath: skill
|
|
2343
|
-
event: "
|
|
2344
|
-
error:
|
|
2312
|
+
extensionPath: "<skill-vault>",
|
|
2313
|
+
event: "skill_load",
|
|
2314
|
+
error: result.message,
|
|
2345
2315
|
});
|
|
2346
|
-
return text;
|
|
2316
|
+
return text;
|
|
2347
2317
|
}
|
|
2318
|
+
return args || `Use loaded skill ${JSON.stringify(skillName)} for this request.`;
|
|
2348
2319
|
}
|
|
2349
2320
|
/** Reject extension commands, then expand a queued message through the shared skill/template path. */
|
|
2350
2321
|
_prepareQueuedMessageText(text) {
|