@caupulican/pi-adaptative 0.86.14 → 0.90.0
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 +49 -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 +76 -109
- 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 +12 -3
- 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/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.d.ts +4 -1
- package/dist/core/tools/edit.d.ts.map +1 -1
- package/dist/core/tools/edit.js +34 -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/file-failure-recovery.d.ts +17 -0
- package/dist/core/tools/file-failure-recovery.d.ts.map +1 -0
- package/dist/core/tools/file-failure-recovery.js +43 -0
- package/dist/core/tools/file-failure-recovery.js.map +1 -0
- 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 +2 -1
- package/dist/core/tools/index.d.ts.map +1 -1
- package/dist/core/tools/index.js +2 -1
- package/dist/core/tools/index.js.map +1 -1
- package/dist/core/tools/ls.d.ts +3 -0
- package/dist/core/tools/ls.d.ts.map +1 -1
- package/dist/core/tools/ls.js +14 -0
- package/dist/core/tools/ls.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/read.d.ts +3 -0
- package/dist/core/tools/read.d.ts.map +1 -1
- package/dist/core/tools/read.js +17 -0
- package/dist/core/tools/read.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 +4 -0
- package/dist/core/tools/tool-definition-wrapper.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.d.ts +4 -1
- package/dist/core/tools/write.d.ts.map +1 -1
- package/dist/core/tools/write.js +39 -3
- package/dist/core/tools/write.js.map +1 -1
- package/dist/index.d.ts +6 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -2
- 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,
|
|
@@ -303,6 +306,14 @@ export class AgentSession {
|
|
|
303
306
|
this._customTools = config.customTools ?? [];
|
|
304
307
|
this._cwd = config.cwd;
|
|
305
308
|
this._agentDir = agentDir;
|
|
309
|
+
this._skillVault = new SkillVaultController({
|
|
310
|
+
getSkills: () => this._resourceLoader.getActiveSkills(),
|
|
311
|
+
getMaxBodyBytes: () => resolveActiveSkillBodyByteLimit(this.model?.contextWindow),
|
|
312
|
+
onSkillUsed: (skill) => {
|
|
313
|
+
if (skill.promoted)
|
|
314
|
+
this._skillCurator.recordUse(skill.name, Date.now());
|
|
315
|
+
},
|
|
316
|
+
});
|
|
306
317
|
this._toolProtocol = new ToolProtocolController({
|
|
307
318
|
agent: this.agent,
|
|
308
319
|
agentDir: this._agentDir,
|
|
@@ -515,6 +526,31 @@ export class AgentSession {
|
|
|
515
526
|
runAutoCompaction: (reason, willRetry) => this._runAutoCompaction(reason, willRetry),
|
|
516
527
|
compactWithRetry: (run, signal, provider) => this._compactWithRetry(run, signal, provider),
|
|
517
528
|
});
|
|
529
|
+
const providerRequestContext = new ProviderRequestContextController({
|
|
530
|
+
transformExtensions: async (messages) => {
|
|
531
|
+
const runner = this._extensionRunner;
|
|
532
|
+
const projection = runner.hasHandlers("context")
|
|
533
|
+
? await runner.emitContext(messages)
|
|
534
|
+
: { messages, transientMessages: [] };
|
|
535
|
+
return { ...projection, isCurrent: () => this._extensionRunner === runner };
|
|
536
|
+
},
|
|
537
|
+
runContextAudit: (messages) => this._runContextAudit(messages),
|
|
538
|
+
runPromptPolicyPlanning: (report) => this._runPromptPolicyPlanning(report),
|
|
539
|
+
runMemoryRetrieval: (messages) => this._runMemoryRetrieval(messages),
|
|
540
|
+
applyContextGc: (messages, writePayloads) => this._applyContextGc(messages, writePayloads),
|
|
541
|
+
correlatePromptPolicyWithContextGc: (report) => this._correlatePromptPolicyWithContextGc(report),
|
|
542
|
+
runPromptEnforcement: (messages, report) => this._runPromptEnforcement(messages, report),
|
|
543
|
+
enqueueRelevanceCuration: (messages, report) => this._enqueueRelevanceCuration(messages, report),
|
|
544
|
+
maybeDrainBrainCuration: () => this._maybeDrainBrainCuration(),
|
|
545
|
+
appendMemoryEvidence: (messages, report) => this._maybeAppendMemoryEvidenceBlock(messages, report),
|
|
546
|
+
getGoalState: () => this.getGoalStateSnapshot(),
|
|
547
|
+
skillVault: this._skillVault,
|
|
548
|
+
});
|
|
549
|
+
this._providerRequestRuntime = new ProviderRequestRuntimeController({
|
|
550
|
+
agent: this.agent,
|
|
551
|
+
compaction: this._compaction,
|
|
552
|
+
context: providerRequestContext,
|
|
553
|
+
});
|
|
518
554
|
this._toolRecoveryLogger = new ToolRecoveryLogger({
|
|
519
555
|
enabled: toolRepairSettings.logging,
|
|
520
556
|
sessionId: this.sessionManager.getSessionId(),
|
|
@@ -621,6 +657,7 @@ export class AgentSession {
|
|
|
621
657
|
getModelRegistry: () => this._modelRegistry,
|
|
622
658
|
isModelExhausted: (model) => this._foregroundRecovery.isModelExhausted(`${model.provider}/${model.id}`),
|
|
623
659
|
getResourceLoader: () => this._resourceLoader,
|
|
660
|
+
getSkillVault: () => this._skillVault,
|
|
624
661
|
getExtensionRunner: () => this._extensionRunner,
|
|
625
662
|
setExtensionRunner: (runner) => {
|
|
626
663
|
this._extensionRunner = runner;
|
|
@@ -820,7 +857,7 @@ export class AgentSession {
|
|
|
820
857
|
// (session persistence, extensions, auto-compaction, retry logic)
|
|
821
858
|
this._unsubscribeAgent = this.agent.subscribe(this._handleAgentEvent);
|
|
822
859
|
this._installAgentToolHooks();
|
|
823
|
-
this.
|
|
860
|
+
this._providerRequestRuntime.install();
|
|
824
861
|
this._installAgentTurnRefresh();
|
|
825
862
|
this._runtimeBuilder.buildRuntime({
|
|
826
863
|
activeToolNames: this._initialActiveToolNames,
|
|
@@ -881,7 +918,7 @@ export class AgentSession {
|
|
|
881
918
|
return;
|
|
882
919
|
const stream = await this.agent.streamFn(model, {
|
|
883
920
|
systemPrompt: this._baseSystemPrompt,
|
|
884
|
-
tools: this.agent.state.tools,
|
|
921
|
+
tools: projectToolsForProvider(this.agent.state.tools),
|
|
885
922
|
messages: [],
|
|
886
923
|
}, options);
|
|
887
924
|
await stream.result();
|
|
@@ -953,54 +990,6 @@ export class AgentSession {
|
|
|
953
990
|
_resolveCompactionThinkingLevel(compactionModel, sessionModel) {
|
|
954
991
|
return this._compactionSupport.resolveThinkingLevel(this.thinkingLevel, compactionModel, sessionModel);
|
|
955
992
|
}
|
|
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
993
|
/**
|
|
1005
994
|
* Resolve the foreground request's cost policy after routing/context conversion, when the actual
|
|
1006
995
|
* model, full system prompt, converted messages, and tool schemas are known. The guard is a
|
|
@@ -1139,8 +1128,8 @@ export class AgentSession {
|
|
|
1139
1128
|
});
|
|
1140
1129
|
}
|
|
1141
1130
|
/**
|
|
1142
|
-
*
|
|
1143
|
-
* one-line method
|
|
1131
|
+
* Provider-plan hot-path delegation to {@link ContextPipeline.runContextAudit}. Kept as a
|
|
1132
|
+
* one-line method so the request context controller owns pass ordering.
|
|
1144
1133
|
*/
|
|
1145
1134
|
_runContextAudit(messages) {
|
|
1146
1135
|
return this._pipeline.runContextAudit(messages);
|
|
@@ -1150,8 +1139,8 @@ export class AgentSession {
|
|
|
1150
1139
|
return this._pipeline.getContextAuditReport(messages);
|
|
1151
1140
|
}
|
|
1152
1141
|
/**
|
|
1153
|
-
*
|
|
1154
|
-
*
|
|
1142
|
+
* Provider-plan hot-path delegation to {@link ContextPipeline.runPromptPolicyPlanning}. Kept as a
|
|
1143
|
+
* one-line method so the request context controller owns pass ordering.
|
|
1155
1144
|
*/
|
|
1156
1145
|
_runPromptPolicyPlanning(auditReport) {
|
|
1157
1146
|
return this._pipeline.runPromptPolicyPlanning(auditReport);
|
|
@@ -1161,8 +1150,8 @@ export class AgentSession {
|
|
|
1161
1150
|
return this._pipeline.getPromptPolicyReport(messages);
|
|
1162
1151
|
}
|
|
1163
1152
|
/**
|
|
1164
|
-
*
|
|
1165
|
-
* Kept as a one-line method
|
|
1153
|
+
* Provider-plan commit delegation to {@link ContextPipeline.correlatePromptPolicyWithContextGc}.
|
|
1154
|
+
* Kept as a one-line method so the request context controller owns pass ordering.
|
|
1166
1155
|
*/
|
|
1167
1156
|
_correlatePromptPolicyWithContextGc(gcReport) {
|
|
1168
1157
|
this._pipeline.correlatePromptPolicyWithContextGc(gcReport);
|
|
@@ -1172,15 +1161,15 @@ export class AgentSession {
|
|
|
1172
1161
|
return this._pipeline.getPromptPolicyGcCorrelation();
|
|
1173
1162
|
}
|
|
1174
1163
|
/**
|
|
1175
|
-
*
|
|
1176
|
-
* one-line method
|
|
1164
|
+
* Provider-plan hot-path delegation to {@link ContextPipeline.runPromptEnforcement}. Kept as a
|
|
1165
|
+
* one-line method so the request context controller owns pass ordering.
|
|
1177
1166
|
*/
|
|
1178
1167
|
_runPromptEnforcement(messages, shadowReport) {
|
|
1179
1168
|
return this._pipeline.runPromptEnforcement(messages, shadowReport);
|
|
1180
1169
|
}
|
|
1181
1170
|
/**
|
|
1182
|
-
*
|
|
1183
|
-
*
|
|
1171
|
+
* Provider-plan commit delegation to {@link ContextPipeline.enqueueRelevanceCuration}. Kept as a
|
|
1172
|
+
* one-line method so the request context controller owns pass ordering.
|
|
1184
1173
|
*/
|
|
1185
1174
|
_enqueueRelevanceCuration(messages, shadowReport) {
|
|
1186
1175
|
this._pipeline.enqueueRelevanceCuration(messages, shadowReport);
|
|
@@ -1190,8 +1179,8 @@ export class AgentSession {
|
|
|
1190
1179
|
return this._pipeline.resolveCurationModelIfFit();
|
|
1191
1180
|
}
|
|
1192
1181
|
/**
|
|
1193
|
-
*
|
|
1194
|
-
* one-line method
|
|
1182
|
+
* Provider-plan commit delegation to {@link ContextPipeline.maybeDrainBrainCuration}. Kept as a
|
|
1183
|
+
* one-line method so the request context controller owns pass ordering.
|
|
1195
1184
|
*/
|
|
1196
1185
|
_maybeDrainBrainCuration() {
|
|
1197
1186
|
this._pipeline.maybeDrainBrainCuration();
|
|
@@ -1219,7 +1208,7 @@ export class AgentSession {
|
|
|
1219
1208
|
getContextCompositionReport() {
|
|
1220
1209
|
const rawMessages = this.agent.state.messages.slice();
|
|
1221
1210
|
const gcResult = this._applyContextGc(rawMessages, false);
|
|
1222
|
-
const
|
|
1211
|
+
const requestMessages = this._skillVault.previewContext(gcResult.messages);
|
|
1223
1212
|
const extensions = this._resourceLoader.getExtensions().extensions;
|
|
1224
1213
|
const extensionToolNames = new Set(extensions.flatMap((extension) => [...extension.tools.keys()]));
|
|
1225
1214
|
const usage = this.getContextUsage();
|
|
@@ -1235,11 +1224,10 @@ export class AgentSession {
|
|
|
1235
1224
|
.reduce((sum, item) => sum + Math.max(0, Math.ceil((item.originalChars ?? 0) / 4) - 50), 0);
|
|
1236
1225
|
return buildContextCompositionReport({
|
|
1237
1226
|
systemPrompt: this.systemPrompt ?? "",
|
|
1238
|
-
tools: this.
|
|
1239
|
-
.filter((tool) => activeNames.has(tool.name))
|
|
1240
|
-
.map((tool) => ({
|
|
1227
|
+
tools: this.agent.state.tools.map((tool) => ({
|
|
1241
1228
|
name: tool.name,
|
|
1242
1229
|
description: tool.description,
|
|
1230
|
+
providerDescription: tool.providerDescription,
|
|
1243
1231
|
parameters: tool.parameters,
|
|
1244
1232
|
source: extensionToolNames.has(tool.name) ? "extension" : "built-in",
|
|
1245
1233
|
})),
|
|
@@ -1249,7 +1237,7 @@ export class AgentSession {
|
|
|
1249
1237
|
toolNames: [...extension.tools.keys()],
|
|
1250
1238
|
commandCount: extension.commands.size,
|
|
1251
1239
|
})),
|
|
1252
|
-
messages:
|
|
1240
|
+
messages: requestMessages,
|
|
1253
1241
|
providerReportedTokens: usage?.tokens ?? null,
|
|
1254
1242
|
contextWindow: usage?.contextWindow ?? this.model?.contextWindow ?? null,
|
|
1255
1243
|
gc: { packedCount: gcResult.report.packedCount, savedTokens: gcResult.report.savedTokens },
|
|
@@ -1309,8 +1297,8 @@ export class AgentSession {
|
|
|
1309
1297
|
return this._pipeline.getPromptEnforcementReport();
|
|
1310
1298
|
}
|
|
1311
1299
|
/**
|
|
1312
|
-
*
|
|
1313
|
-
* one-line method
|
|
1300
|
+
* Provider-plan hot-path delegation to {@link MemoryController.runMemoryRetrieval}. Kept as a
|
|
1301
|
+
* one-line method so the request context controller owns pass ordering.
|
|
1314
1302
|
*/
|
|
1315
1303
|
_runMemoryRetrieval(messages) {
|
|
1316
1304
|
return this._memory.runMemoryRetrieval(messages);
|
|
@@ -1320,8 +1308,8 @@ export class AgentSession {
|
|
|
1320
1308
|
return this._memory.getMemoryRetrievalReport();
|
|
1321
1309
|
}
|
|
1322
1310
|
/**
|
|
1323
|
-
*
|
|
1324
|
-
* Kept as a one-line method
|
|
1311
|
+
* Provider-plan hot-path delegation to {@link MemoryController.maybeAppendMemoryEvidenceBlock}.
|
|
1312
|
+
* Kept as a one-line method so the request context controller owns pass ordering.
|
|
1325
1313
|
*/
|
|
1326
1314
|
_maybeAppendMemoryEvidenceBlock(messages, report) {
|
|
1327
1315
|
return this._memory.maybeAppendMemoryEvidenceBlock(messages, report);
|
|
@@ -1331,8 +1319,8 @@ export class AgentSession {
|
|
|
1331
1319
|
return this._memory.getMemoryPromptInclusionReport();
|
|
1332
1320
|
}
|
|
1333
1321
|
/**
|
|
1334
|
-
*
|
|
1335
|
-
* one-line method
|
|
1322
|
+
* Provider-plan hot-path delegation to {@link ContextPipeline.applyContextGc}. Kept as a
|
|
1323
|
+
* one-line method so the request context controller owns pass ordering;
|
|
1336
1324
|
* also serves the composition dashboard and {@link getContextGcReport} read-only paths.
|
|
1337
1325
|
*/
|
|
1338
1326
|
_applyContextGc(messages, writePayloads) {
|
|
@@ -1659,6 +1647,7 @@ export class AgentSession {
|
|
|
1659
1647
|
safely(() => this.abortCompaction());
|
|
1660
1648
|
safely(() => this.abortBranchSummary());
|
|
1661
1649
|
safely(() => this.abortBash());
|
|
1650
|
+
safely(() => this._skillVault.unload());
|
|
1662
1651
|
safely(() => disposeShellExecutionSession(this._shellSessionKey));
|
|
1663
1652
|
safely(() => this._cancelPrefixWarm());
|
|
1664
1653
|
safely(() => this.agent.abort());
|
|
@@ -1668,11 +1657,11 @@ export class AgentSession {
|
|
|
1668
1657
|
safely(() => this._reflection.cancelScheduled());
|
|
1669
1658
|
safely(() => this._reflectionAbort.abort());
|
|
1670
1659
|
safely(() => this._backgroundLanes.abortInFlightLanes());
|
|
1660
|
+
safely(() => this._providerRequestRuntime.dispose());
|
|
1671
1661
|
safely(() => {
|
|
1672
1662
|
this.agent.afterToolCall = undefined;
|
|
1673
1663
|
this.agent.handoffToolCall = undefined;
|
|
1674
1664
|
this.agent.subscribeToolCallHandoffRequest = undefined;
|
|
1675
|
-
this.agent.transformContext = undefined;
|
|
1676
1665
|
});
|
|
1677
1666
|
safely(() => this._extensionRunner.invalidate());
|
|
1678
1667
|
safely(() => this._disconnectFromAgent());
|
|
@@ -1815,9 +1804,6 @@ export class AgentSession {
|
|
|
1815
1804
|
validToolNames.includes("ask_question")) {
|
|
1816
1805
|
addIfRegistered("artifact_retrieve");
|
|
1817
1806
|
}
|
|
1818
|
-
if (validToolNames.includes("delegate")) {
|
|
1819
|
-
addIfRegistered("delegate_status");
|
|
1820
|
-
}
|
|
1821
1807
|
this.agent.state.tools = tools;
|
|
1822
1808
|
// Rebuild base system prompt with new tool set
|
|
1823
1809
|
this._baseSystemPrompt = this._rebuildSystemPrompt(validToolNames);
|
|
@@ -2309,42 +2295,23 @@ export class AgentSession {
|
|
|
2309
2295
|
return true;
|
|
2310
2296
|
}
|
|
2311
2297
|
}
|
|
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
|
-
*/
|
|
2298
|
+
/** Route explicit /skill:name through the same host-owned vault as model tool calls. */
|
|
2317
2299
|
_expandSkillCommand(text) {
|
|
2318
2300
|
if (!text.startsWith("/skill:"))
|
|
2319
2301
|
return text;
|
|
2320
2302
|
const spaceIndex = text.indexOf(" ");
|
|
2321
2303
|
const skillName = spaceIndex === -1 ? text.slice(7) : text.slice(7, spaceIndex);
|
|
2322
2304
|
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
|
|
2305
|
+
const result = this._skillVault.load(skillName, "user");
|
|
2306
|
+
if (!result.ok) {
|
|
2341
2307
|
this._extensionRunner.emitError({
|
|
2342
|
-
extensionPath: skill
|
|
2343
|
-
event: "
|
|
2344
|
-
error:
|
|
2308
|
+
extensionPath: "<skill-vault>",
|
|
2309
|
+
event: "skill_load",
|
|
2310
|
+
error: result.message,
|
|
2345
2311
|
});
|
|
2346
|
-
return text;
|
|
2312
|
+
return text;
|
|
2347
2313
|
}
|
|
2314
|
+
return args || `Use loaded skill ${JSON.stringify(skillName)} for this request.`;
|
|
2348
2315
|
}
|
|
2349
2316
|
/** Reject extension commands, then expand a queued message through the shared skill/template path. */
|
|
2350
2317
|
_prepareQueuedMessageText(text) {
|