@caupulican/pi-adaptative 0.94.1 → 0.95.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 +39 -0
- package/dist/bundled-resources/extensions/tmux-agent-manager/README.md +32 -13
- package/dist/bundled-resources/extensions/tmux-agent-manager/index.d.ts +7 -4
- package/dist/bundled-resources/extensions/tmux-agent-manager/index.d.ts.map +1 -1
- package/dist/bundled-resources/extensions/tmux-agent-manager/index.js +173 -293
- package/dist/bundled-resources/extensions/tmux-agent-manager/index.js.map +1 -1
- package/dist/bundled-resources/extensions/tmux-agent-manager/index.ts +247 -392
- package/dist/bundled-resources/extensions/tmux-agent-manager/launch-profile.d.ts +52 -0
- package/dist/bundled-resources/extensions/tmux-agent-manager/launch-profile.d.ts.map +1 -0
- package/dist/bundled-resources/extensions/tmux-agent-manager/launch-profile.js +118 -0
- package/dist/bundled-resources/extensions/tmux-agent-manager/launch-profile.js.map +1 -0
- package/dist/bundled-resources/extensions/tmux-agent-manager/launch-profile.ts +169 -0
- package/dist/bundled-resources/extensions/tmux-agent-manager/templates/builder-validator.json +1 -1
- package/dist/bundled-resources/extensions/tmux-agent-manager/templates/provider-prompt-smoke.json +1 -1
- package/dist/bundled-resources/skills/pi-harness-learning/SKILL.md +13 -7
- package/dist/bundled-resources/skills/worker-profile-writer/SKILL.md +11 -11
- package/dist/core/agent-session.d.ts +11 -41
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +93 -160
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/autonomy/envelope-enforcement.d.ts +6 -1
- package/dist/core/autonomy/envelope-enforcement.d.ts.map +1 -1
- package/dist/core/autonomy/envelope-enforcement.js +26 -25
- package/dist/core/autonomy/envelope-enforcement.js.map +1 -1
- package/dist/core/autonomy/lane-private-paths.d.ts.map +1 -1
- package/dist/core/autonomy/lane-private-paths.js +2 -1
- package/dist/core/autonomy/lane-private-paths.js.map +1 -1
- package/dist/core/autonomy/lane-tool-surface.d.ts +8 -8
- package/dist/core/autonomy/lane-tool-surface.d.ts.map +1 -1
- package/dist/core/autonomy/lane-tool-surface.js +45 -30
- package/dist/core/autonomy/lane-tool-surface.js.map +1 -1
- package/dist/core/autonomy/worker-session-private-scope.d.ts +12 -0
- package/dist/core/autonomy/worker-session-private-scope.d.ts.map +1 -0
- package/dist/core/autonomy/worker-session-private-scope.js +42 -0
- package/dist/core/autonomy/worker-session-private-scope.js.map +1 -0
- package/dist/core/autonomy/worker-tool-adapter-registry.d.ts +65 -0
- package/dist/core/autonomy/worker-tool-adapter-registry.d.ts.map +1 -0
- package/dist/core/autonomy/worker-tool-adapter-registry.js +145 -0
- package/dist/core/autonomy/worker-tool-adapter-registry.js.map +1 -0
- package/dist/core/background-lane-controller.d.ts +1 -1
- package/dist/core/background-lane-controller.d.ts.map +1 -1
- package/dist/core/background-lane-controller.js +1 -1
- package/dist/core/background-lane-controller.js.map +1 -1
- package/dist/core/background-tool-task-controller.d.ts +8 -2
- package/dist/core/background-tool-task-controller.d.ts.map +1 -1
- package/dist/core/background-tool-task-controller.js +10 -2
- package/dist/core/background-tool-task-controller.js.map +1 -1
- package/dist/core/cost-guard-controller.d.ts +37 -0
- package/dist/core/cost-guard-controller.d.ts.map +1 -0
- package/dist/core/cost-guard-controller.js +71 -0
- package/dist/core/cost-guard-controller.js.map +1 -0
- package/dist/core/cost-guard.d.ts +9 -4
- package/dist/core/cost-guard.d.ts.map +1 -1
- package/dist/core/cost-guard.js +7 -3
- package/dist/core/cost-guard.js.map +1 -1
- package/dist/core/delegation/worker-attempt-executor.d.ts +1 -1
- package/dist/core/delegation/worker-attempt-executor.d.ts.map +1 -1
- package/dist/core/delegation/worker-attempt-executor.js +0 -1
- package/dist/core/delegation/worker-attempt-executor.js.map +1 -1
- package/dist/core/delegation/worker-authority-resolver.d.ts +16 -3
- package/dist/core/delegation/worker-authority-resolver.d.ts.map +1 -1
- package/dist/core/delegation/worker-authority-resolver.js +114 -55
- package/dist/core/delegation/worker-authority-resolver.js.map +1 -1
- package/dist/core/delegation/worker-claim.d.ts +1 -2
- package/dist/core/delegation/worker-claim.d.ts.map +1 -1
- package/dist/core/delegation/worker-claim.js.map +1 -1
- package/dist/core/delegation/worker-delegation-controller.d.ts +19 -6
- package/dist/core/delegation/worker-delegation-controller.d.ts.map +1 -1
- package/dist/core/delegation/worker-delegation-controller.js +125 -40
- package/dist/core/delegation/worker-delegation-controller.js.map +1 -1
- package/dist/core/delegation/worker-delegation-request.d.ts +3 -3
- package/dist/core/delegation/worker-delegation-request.d.ts.map +1 -1
- package/dist/core/delegation/worker-delegation-request.js +13 -19
- package/dist/core/delegation/worker-delegation-request.js.map +1 -1
- package/dist/core/delegation/worker-execution-policy.d.ts +3 -2
- package/dist/core/delegation/worker-execution-policy.d.ts.map +1 -1
- package/dist/core/delegation/worker-execution-policy.js +54 -39
- package/dist/core/delegation/worker-execution-policy.js.map +1 -1
- package/dist/core/delegation/worker-fleet-limits.d.ts +3 -3
- package/dist/core/delegation/worker-fleet-limits.d.ts.map +1 -1
- package/dist/core/delegation/worker-fleet-limits.js +7 -7
- package/dist/core/delegation/worker-fleet-limits.js.map +1 -1
- package/dist/core/delegation/worker-machine-scope.d.ts +12 -0
- package/dist/core/delegation/worker-machine-scope.d.ts.map +1 -0
- package/dist/core/delegation/worker-machine-scope.js +38 -0
- package/dist/core/delegation/worker-machine-scope.js.map +1 -0
- package/dist/core/delegation/worker-recovery-coordinator.d.ts.map +1 -1
- package/dist/core/delegation/worker-recovery-coordinator.js +6 -1
- package/dist/core/delegation/worker-recovery-coordinator.js.map +1 -1
- package/dist/core/delegation/worker-runner.d.ts +5 -7
- package/dist/core/delegation/worker-runner.d.ts.map +1 -1
- package/dist/core/delegation/worker-runner.js +1 -4
- package/dist/core/delegation/worker-runner.js.map +1 -1
- package/dist/core/delegation/worker-write-reservation-coordinator.d.ts +3 -2
- package/dist/core/delegation/worker-write-reservation-coordinator.d.ts.map +1 -1
- package/dist/core/delegation/worker-write-reservation-coordinator.js +50 -25
- package/dist/core/delegation/worker-write-reservation-coordinator.js.map +1 -1
- package/dist/core/durable-custom-message-turn-controller.d.ts +6 -0
- package/dist/core/durable-custom-message-turn-controller.d.ts.map +1 -1
- package/dist/core/durable-custom-message-turn-controller.js +38 -15
- package/dist/core/durable-custom-message-turn-controller.js.map +1 -1
- package/dist/core/extension-binding-controller.d.ts +5 -1
- package/dist/core/extension-binding-controller.d.ts.map +1 -1
- package/dist/core/extension-binding-controller.js +15 -0
- package/dist/core/extension-binding-controller.js.map +1 -1
- package/dist/core/extensions/factory-runtime.d.ts.map +1 -1
- package/dist/core/extensions/factory-runtime.js +5 -0
- package/dist/core/extensions/factory-runtime.js.map +1 -1
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +1 -0
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/types.d.ts +8 -4
- 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.d.ts +14 -0
- package/dist/core/foreground-terminal-handoff-controller.d.ts.map +1 -1
- package/dist/core/foreground-terminal-handoff-controller.js +188 -72
- package/dist/core/foreground-terminal-handoff-controller.js.map +1 -1
- package/dist/core/goals/goal-session-controller.d.ts +2 -0
- package/dist/core/goals/goal-session-controller.d.ts.map +1 -1
- package/dist/core/goals/goal-session-controller.js +8 -0
- package/dist/core/goals/goal-session-controller.js.map +1 -1
- package/dist/core/goals/goal-tool-core.d.ts +5 -4
- package/dist/core/goals/goal-tool-core.d.ts.map +1 -1
- package/dist/core/goals/goal-tool-core.js +23 -19
- package/dist/core/goals/goal-tool-core.js.map +1 -1
- package/dist/core/learning/auto-learn-settings.d.ts +84 -0
- package/dist/core/learning/auto-learn-settings.d.ts.map +1 -0
- package/dist/core/learning/auto-learn-settings.js +66 -0
- package/dist/core/learning/auto-learn-settings.js.map +1 -0
- package/dist/core/learning/reflection-engine.d.ts +4 -0
- package/dist/core/learning/reflection-engine.d.ts.map +1 -1
- package/dist/core/learning/reflection-engine.js +48 -10
- package/dist/core/learning/reflection-engine.js.map +1 -1
- package/dist/core/local-prefix-warm-controller.d.ts +24 -0
- package/dist/core/local-prefix-warm-controller.d.ts.map +1 -0
- package/dist/core/local-prefix-warm-controller.js +79 -0
- package/dist/core/local-prefix-warm-controller.js.map +1 -0
- package/dist/core/memory/providers/file-store.d.ts +2 -0
- package/dist/core/memory/providers/file-store.d.ts.map +1 -1
- package/dist/core/memory/providers/file-store.js +71 -15
- package/dist/core/memory/providers/file-store.js.map +1 -1
- package/dist/core/memory/worker-memory-tools.d.ts +5 -0
- package/dist/core/memory/worker-memory-tools.d.ts.map +1 -0
- package/dist/core/memory/worker-memory-tools.js +5 -0
- package/dist/core/memory/worker-memory-tools.js.map +1 -0
- package/dist/core/model-capability.d.ts +7 -0
- package/dist/core/model-capability.d.ts.map +1 -1
- package/dist/core/model-capability.js +12 -0
- package/dist/core/model-capability.js.map +1 -1
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +2 -10
- package/dist/core/model-registry.js.map +1 -1
- package/dist/core/model-router-controller.d.ts +3 -2
- package/dist/core/model-router-controller.d.ts.map +1 -1
- package/dist/core/model-router-controller.js +3 -2
- package/dist/core/model-router-controller.js.map +1 -1
- package/dist/core/orchestration/contracts.d.ts +16 -12
- package/dist/core/orchestration/contracts.d.ts.map +1 -1
- package/dist/core/orchestration/contracts.js +2 -2
- package/dist/core/orchestration/contracts.js.map +1 -1
- package/dist/core/orchestration/lane-tool-manifests.d.ts +2 -2
- package/dist/core/orchestration/lane-tool-manifests.d.ts.map +1 -1
- package/dist/core/orchestration/lane-tool-manifests.js +6 -1
- package/dist/core/orchestration/lane-tool-manifests.js.map +1 -1
- package/dist/core/orchestration/profile-registry.d.ts.map +1 -1
- package/dist/core/orchestration/profile-registry.js +14 -0
- package/dist/core/orchestration/profile-registry.js.map +1 -1
- package/dist/core/orchestration/task-profile-writer.d.ts +7 -4
- package/dist/core/orchestration/task-profile-writer.d.ts.map +1 -1
- package/dist/core/orchestration/task-profile-writer.js +71 -59
- package/dist/core/orchestration/task-profile-writer.js.map +1 -1
- package/dist/core/orchestration/thinking-level-schema.d.ts +7 -0
- package/dist/core/orchestration/thinking-level-schema.d.ts.map +1 -0
- package/dist/core/orchestration/thinking-level-schema.js +19 -0
- package/dist/core/orchestration/thinking-level-schema.js.map +1 -0
- package/dist/core/orchestration/worker-execution-contract.d.ts.map +1 -1
- package/dist/core/orchestration/worker-execution-contract.js +12 -5
- package/dist/core/orchestration/worker-execution-contract.js.map +1 -1
- package/dist/core/provider-prompt-contracts.d.ts +1 -4
- package/dist/core/provider-prompt-contracts.d.ts.map +1 -1
- package/dist/core/provider-prompt-contracts.js +4 -10
- package/dist/core/provider-prompt-contracts.js.map +1 -1
- package/dist/core/provider-request-context-controller.d.ts +2 -0
- package/dist/core/provider-request-context-controller.d.ts.map +1 -1
- package/dist/core/provider-request-context-controller.js +10 -3
- package/dist/core/provider-request-context-controller.js.map +1 -1
- package/dist/core/reflection-controller.d.ts +56 -27
- package/dist/core/reflection-controller.d.ts.map +1 -1
- package/dist/core/reflection-controller.js +206 -117
- package/dist/core/reflection-controller.js.map +1 -1
- package/dist/core/runtime-builder.d.ts +1 -0
- package/dist/core/runtime-builder.d.ts.map +1 -1
- package/dist/core/runtime-builder.js +25 -14
- package/dist/core/runtime-builder.js.map +1 -1
- package/dist/core/secrets/credential-exposure-guard.d.ts.map +1 -1
- package/dist/core/secrets/credential-exposure-guard.js +55 -10
- package/dist/core/secrets/credential-exposure-guard.js.map +1 -1
- package/dist/core/session-role.d.ts +6 -8
- package/dist/core/session-role.d.ts.map +1 -1
- package/dist/core/session-role.js +8 -18
- package/dist/core/session-role.js.map +1 -1
- package/dist/core/settings-manager.d.ts +13 -16
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +53 -50
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/skill-vault.d.ts +15 -0
- package/dist/core/skill-vault.d.ts.map +1 -1
- package/dist/core/skill-vault.js +79 -45
- package/dist/core/skill-vault.js.map +1 -1
- package/dist/core/skills.d.ts +3 -0
- package/dist/core/skills.d.ts.map +1 -1
- package/dist/core/skills.js +6 -6
- package/dist/core/skills.js.map +1 -1
- package/dist/core/system-prompt-builder.d.ts +2 -0
- package/dist/core/system-prompt-builder.d.ts.map +1 -1
- package/dist/core/system-prompt-builder.js +52 -12
- package/dist/core/system-prompt-builder.js.map +1 -1
- package/dist/core/system-prompt.js +1 -1
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/tool-capability-policy.d.ts +3 -0
- package/dist/core/tool-capability-policy.d.ts.map +1 -1
- package/dist/core/tool-capability-policy.js +13 -2
- package/dist/core/tool-capability-policy.js.map +1 -1
- package/dist/core/toolkit/script-runner.d.ts +2 -1
- package/dist/core/toolkit/script-runner.d.ts.map +1 -1
- package/dist/core/toolkit/script-runner.js +10 -2
- package/dist/core/toolkit/script-runner.js.map +1 -1
- package/dist/core/tools/delegate-status.d.ts +1 -1
- package/dist/core/tools/delegate-status.d.ts.map +1 -1
- package/dist/core/tools/delegate-status.js +1 -1
- package/dist/core/tools/delegate-status.js.map +1 -1
- package/dist/core/tools/delegate.d.ts +4 -15
- package/dist/core/tools/delegate.d.ts.map +1 -1
- package/dist/core/tools/delegate.js +111 -73
- package/dist/core/tools/delegate.js.map +1 -1
- package/dist/core/tools/goal.d.ts +3 -4
- package/dist/core/tools/goal.d.ts.map +1 -1
- package/dist/core/tools/goal.js +24 -7
- package/dist/core/tools/goal.js.map +1 -1
- package/dist/core/tools/profile-writer.d.ts +2 -8
- package/dist/core/tools/profile-writer.d.ts.map +1 -1
- package/dist/core/tools/profile-writer.js +6 -18
- package/dist/core/tools/profile-writer.js.map +1 -1
- package/dist/core/tools/run-toolkit-script.d.ts +1 -1
- package/dist/core/tools/run-toolkit-script.d.ts.map +1 -1
- package/dist/core/tools/run-toolkit-script.js +2 -2
- package/dist/core/tools/run-toolkit-script.js.map +1 -1
- package/dist/core/tools/skill-audit.d.ts +28 -1
- package/dist/core/tools/skill-audit.d.ts.map +1 -1
- package/dist/core/tools/skill-audit.js +56 -12
- package/dist/core/tools/skill-audit.js.map +1 -1
- package/dist/core/tools/skill.d.ts +12 -1
- package/dist/core/tools/skill.d.ts.map +1 -1
- package/dist/core/tools/skill.js +52 -0
- package/dist/core/tools/skill.js.map +1 -1
- package/dist/core/tools/skillify.d.ts.map +1 -1
- package/dist/core/tools/skillify.js +16 -7
- package/dist/core/tools/skillify.js.map +1 -1
- package/dist/core/tools/task-steps.js +1 -1
- package/dist/core/tools/task-steps.js.map +1 -1
- package/dist/core/tools/tmux-dispatch.d.ts +4 -16
- package/dist/core/tools/tmux-dispatch.d.ts.map +1 -1
- package/dist/core/tools/tmux-dispatch.js +5 -20
- package/dist/core/tools/tmux-dispatch.js.map +1 -1
- package/dist/core/worktree-sync/codes.d.ts +1 -2
- package/dist/core/worktree-sync/codes.d.ts.map +1 -1
- package/dist/core/worktree-sync/codes.js +1 -2
- package/dist/core/worktree-sync/codes.js.map +1 -1
- package/dist/core/worktree-sync/lane-gate.d.ts +4 -8
- package/dist/core/worktree-sync/lane-gate.d.ts.map +1 -1
- package/dist/core/worktree-sync/lane-gate.js +5 -51
- package/dist/core/worktree-sync/lane-gate.js.map +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -1
- package/dist/modes/interactive/auto-learn-controller.d.ts +6 -7
- package/dist/modes/interactive/auto-learn-controller.d.ts.map +1 -1
- package/dist/modes/interactive/auto-learn-controller.js +30 -207
- package/dist/modes/interactive/auto-learn-controller.js.map +1 -1
- package/dist/modes/interactive/autonomy-commands.js +2 -2
- package/dist/modes/interactive/autonomy-commands.js.map +1 -1
- package/dist/modes/interactive/components/custom-message.js +17 -0
- package/dist/modes/interactive/components/custom-message.js.map +1 -1
- package/dist/modes/interactive/components/fitness-role-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/fitness-role-selector.js +2 -2
- package/dist/modes/interactive/components/fitness-role-selector.js.map +1 -1
- package/dist/modes/interactive/components/footer.js +1 -1
- package/dist/modes/interactive/components/footer.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector.d.ts +4 -0
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector.js +150 -73
- package/dist/modes/interactive/components/settings-selector.js.map +1 -1
- package/dist/modes/interactive/report-commands.d.ts.map +1 -1
- package/dist/modes/interactive/report-commands.js +8 -4
- package/dist/modes/interactive/report-commands.js.map +1 -1
- package/dist/modes/interactive/settings-selector-flow.d.ts.map +1 -1
- package/dist/modes/interactive/settings-selector-flow.js +10 -0
- package/dist/modes/interactive/settings-selector-flow.js.map +1 -1
- package/docs/extensions.md +8 -0
- package/docs/harness-architecture.md +28 -32
- package/docs/index.md +1 -1
- package/docs/process-matrix.md +8 -6
- package/docs/resources.md +1 -1
- package/docs/settings.md +61 -51
- package/docs/tmux-agent-manager.md +47 -40
- package/docs/usage.md +1 -1
- package/docs/worker-profiles.md +8 -6
- package/docs/worktree-sync.md +26 -20
- 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
- package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.d.ts +0 -133
- package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.d.ts.map +0 -1
- package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.js +0 -199
- package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.js.map +0 -1
- package/dist/bundled-resources/extensions/tmux-agent-manager/dispatch-grant.ts +0 -312
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { ThinkingLevel } from "@caupulican/pi-agent-core";
|
|
2
|
+
import type { Usage } from "@caupulican/pi-ai";
|
|
3
|
+
export type Provider = "pi" | "codex" | "agy" | "claude" | "opencode" | "custom";
|
|
4
|
+
/** Full host-auditable Pi worker surface after the shared worker ceiling removes agent launchers
|
|
5
|
+
* and root-owned durable mutation controls. */
|
|
6
|
+
export declare const DEFAULT_MANAGED_WORKER_TOOLS: readonly string[];
|
|
7
|
+
export declare class WorkerLaunchProfileError extends Error {
|
|
8
|
+
readonly code: "worker_profile_tools_rejected";
|
|
9
|
+
readonly rejectedTools: readonly string[];
|
|
10
|
+
constructor(rejectedTools: readonly string[]);
|
|
11
|
+
}
|
|
12
|
+
export interface WorkerLaunchProfileInput {
|
|
13
|
+
identity: string;
|
|
14
|
+
inheritedTools?: readonly string[];
|
|
15
|
+
allowedTools?: readonly string[];
|
|
16
|
+
resourceProfile?: string;
|
|
17
|
+
resourceProfileJson?: string;
|
|
18
|
+
writePaths?: readonly string[];
|
|
19
|
+
thinkingLevel?: ThinkingLevel;
|
|
20
|
+
worktreeLane?: string;
|
|
21
|
+
parentPid?: number;
|
|
22
|
+
parentSession?: string;
|
|
23
|
+
taskRef?: string;
|
|
24
|
+
}
|
|
25
|
+
/** Immutable profile compiled once before a managed process is reserved or launched. Empty
|
|
26
|
+
* `writePaths` means the host-derived machine-root scope; a non-empty list is an explicit narrowing. */
|
|
27
|
+
export interface WorkerLaunchProfile {
|
|
28
|
+
readonly identity: string;
|
|
29
|
+
readonly allowedTools: readonly string[];
|
|
30
|
+
readonly resourceProfile?: string;
|
|
31
|
+
readonly resourceProfileJson?: string;
|
|
32
|
+
readonly writePaths: readonly string[];
|
|
33
|
+
readonly thinkingLevel?: ThinkingLevel;
|
|
34
|
+
readonly worktreeLane?: string;
|
|
35
|
+
readonly parentPid?: number;
|
|
36
|
+
readonly parentSession?: string;
|
|
37
|
+
readonly taskRef?: string;
|
|
38
|
+
}
|
|
39
|
+
export declare function deriveWorkerLaunchProfile(input: WorkerLaunchProfileInput): WorkerLaunchProfile;
|
|
40
|
+
export interface LaunchProfileFlag {
|
|
41
|
+
flag: string;
|
|
42
|
+
value?: string;
|
|
43
|
+
}
|
|
44
|
+
/** Render a Pi child's immutable profile into its own CLI configuration. The manager supplies either
|
|
45
|
+
* an explicit resource-profile override or a one-shot snapshot of the parent's effective resources;
|
|
46
|
+
* standalone callers that omit both retain the child's normal resources. */
|
|
47
|
+
export declare function buildLaunchProfileFlags(profile: WorkerLaunchProfile): LaunchProfileFlag[];
|
|
48
|
+
export declare function buildScopedSystemPrompt(profile: WorkerLaunchProfile): string;
|
|
49
|
+
/** Decode an optional cooperative worker usage claim. Malformed numeric fields are zeroed because
|
|
50
|
+
* the claim is advisory and must never become an authoritative billing record. */
|
|
51
|
+
export declare function decodeTmuxWorkerUsageClaim(raw: unknown): Usage | undefined;
|
|
52
|
+
//# sourceMappingURL=launch-profile.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"launch-profile.d.ts","sourceRoot":"","sources":["../../../../src/bundled-resources/extensions/tmux-agent-manager/launch-profile.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE/C,MAAM,MAAM,QAAQ,GAAG,IAAI,GAAG,OAAO,GAAG,KAAK,GAAG,QAAQ,GAAG,UAAU,GAAG,QAAQ,CAAC;AAKjF;+CAC+C;AAC/C,eAAO,MAAM,4BAA4B,EAAE,SAAS,MAAM,EAAkD,CAAC;AAE7G,qBAAa,wBAAyB,SAAQ,KAAK;IAClD,QAAQ,CAAC,IAAI,EAAG,+BAA+B,CAAU;IACzD,QAAQ,CAAC,aAAa,EAAE,S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K,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;4EAE4E;AAC5E,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,mBAAmB,GAAG,iBAAiB,EAAE,CAczF;AAED,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,mBAAmB,GAAG,MAAM,CAiB5E;AAMD;kFACkF;AAClF,wBAAgB,0BAA0B,CAAC,GAAG,EAAE,OAAO,GAAG,KAAK,GAAG,SAAS,CAkB1E"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { mapToolNamesForPlatform, POLICY_OWNED_RUNTIME_TOOL_NAMES, WORKER_FORBIDDEN_TOOLS, } from "@caupulican/pi-adaptative";
|
|
2
|
+
const MANAGED_WORKER_TOOL_NAMES = POLICY_OWNED_RUNTIME_TOOL_NAMES.filter((tool) => !WORKER_FORBIDDEN_TOOLS.has(tool));
|
|
3
|
+
const MANAGED_WORKER_TOOL_NAME_SET = new Set(MANAGED_WORKER_TOOL_NAMES);
|
|
4
|
+
/** Full host-auditable Pi worker surface after the shared worker ceiling removes agent launchers
|
|
5
|
+
* and root-owned durable mutation controls. */
|
|
6
|
+
export const DEFAULT_MANAGED_WORKER_TOOLS = Object.freeze([...MANAGED_WORKER_TOOL_NAMES]);
|
|
7
|
+
export class WorkerLaunchProfileError extends Error {
|
|
8
|
+
constructor(rejectedTools) {
|
|
9
|
+
const displayNames = rejectedTools.map((tool) => (tool ? `'${tool}'` : "<empty>"));
|
|
10
|
+
super(`Worker profile requested unavailable or forbidden tools: ${displayNames.join(", ")}.`);
|
|
11
|
+
this.code = "worker_profile_tools_rejected";
|
|
12
|
+
this.name = "WorkerLaunchProfileError";
|
|
13
|
+
this.rejectedTools = Object.freeze([...rejectedTools]);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function normalizeToolNames(tools) {
|
|
17
|
+
return mapToolNamesForPlatform(tools.map((tool) => tool.trim().toLowerCase()));
|
|
18
|
+
}
|
|
19
|
+
function uniqueClassifiedTools(tools) {
|
|
20
|
+
const selected = new Set(normalizeToolNames(tools).filter((tool) => tool.length > 0));
|
|
21
|
+
return MANAGED_WORKER_TOOL_NAMES.filter((tool) => selected.has(tool));
|
|
22
|
+
}
|
|
23
|
+
export function deriveWorkerLaunchProfile(input) {
|
|
24
|
+
if (input.allowedTools !== undefined) {
|
|
25
|
+
const inheritedToolSet = input.inheritedTools === undefined
|
|
26
|
+
? MANAGED_WORKER_TOOL_NAME_SET
|
|
27
|
+
: new Set(uniqueClassifiedTools(input.inheritedTools));
|
|
28
|
+
const rejectedTools = [
|
|
29
|
+
...new Set(normalizeToolNames(input.allowedTools).filter((tool) => !MANAGED_WORKER_TOOL_NAME_SET.has(tool) || !inheritedToolSet.has(tool))),
|
|
30
|
+
];
|
|
31
|
+
if (rejectedTools.length > 0)
|
|
32
|
+
throw new WorkerLaunchProfileError(rejectedTools);
|
|
33
|
+
}
|
|
34
|
+
const sourceTools = input.allowedTools ?? input.inheritedTools ?? DEFAULT_MANAGED_WORKER_TOOLS;
|
|
35
|
+
const allowedTools = Object.freeze(uniqueClassifiedTools(sourceTools));
|
|
36
|
+
const writePaths = Object.freeze([
|
|
37
|
+
...new Set(input.writePaths?.map((entry) => entry.trim()).filter((entry) => entry.length > 0) ?? []),
|
|
38
|
+
]);
|
|
39
|
+
return Object.freeze({
|
|
40
|
+
identity: input.identity,
|
|
41
|
+
allowedTools,
|
|
42
|
+
writePaths,
|
|
43
|
+
...(input.resourceProfile ? { resourceProfile: input.resourceProfile } : {}),
|
|
44
|
+
...(input.resourceProfileJson ? { resourceProfileJson: input.resourceProfileJson } : {}),
|
|
45
|
+
...(input.thinkingLevel ? { thinkingLevel: input.thinkingLevel } : {}),
|
|
46
|
+
...(input.worktreeLane ? { worktreeLane: input.worktreeLane } : {}),
|
|
47
|
+
...(input.parentPid !== undefined ? { parentPid: input.parentPid } : {}),
|
|
48
|
+
...(input.parentSession ? { parentSession: input.parentSession } : {}),
|
|
49
|
+
...(input.taskRef ? { taskRef: input.taskRef } : {}),
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
/** Render a Pi child's immutable profile into its own CLI configuration. The manager supplies either
|
|
53
|
+
* an explicit resource-profile override or a one-shot snapshot of the parent's effective resources;
|
|
54
|
+
* standalone callers that omit both retain the child's normal resources. */
|
|
55
|
+
export function buildLaunchProfileFlags(profile) {
|
|
56
|
+
const flags = profile.allowedTools.length
|
|
57
|
+
? [{ flag: "--tools", value: profile.allowedTools.join(",") }]
|
|
58
|
+
: [{ flag: "--no-tools" }];
|
|
59
|
+
if (profile.resourceProfileJson)
|
|
60
|
+
flags.push({ flag: "--resource-profile-json", value: profile.resourceProfileJson });
|
|
61
|
+
if (profile.resourceProfile)
|
|
62
|
+
flags.push({ flag: "--resource-profile", value: profile.resourceProfile });
|
|
63
|
+
if (profile.thinkingLevel)
|
|
64
|
+
flags.push({ flag: "--thinking", value: profile.thinkingLevel });
|
|
65
|
+
if (profile.worktreeLane)
|
|
66
|
+
flags.push({ flag: "--worktree-lane", value: profile.worktreeLane });
|
|
67
|
+
if (profile.parentPid !== undefined)
|
|
68
|
+
flags.push({ flag: "--parent-pid", value: String(profile.parentPid) });
|
|
69
|
+
if (profile.parentSession)
|
|
70
|
+
flags.push({ flag: "--parent-session", value: profile.parentSession });
|
|
71
|
+
if (profile.taskRef)
|
|
72
|
+
flags.push({ flag: "--task-ref", value: profile.taskRef });
|
|
73
|
+
flags.push({ flag: "--append-system-prompt", value: buildScopedSystemPrompt(profile) });
|
|
74
|
+
flags.push({ flag: "--session-mode", value: "worker" });
|
|
75
|
+
return flags;
|
|
76
|
+
}
|
|
77
|
+
export function buildScopedSystemPrompt(profile) {
|
|
78
|
+
const scope = profile.writePaths.length
|
|
79
|
+
? `Structural filesystem tools are limited to: ${profile.writePaths.join(", ")}. Process tools retain host access and must honor this assigned scope.`
|
|
80
|
+
: "Filesystem authority inherits the host's full-machine worker scope except private harness paths.";
|
|
81
|
+
const sentences = [
|
|
82
|
+
`You are a tmux worker running under immutable profile ${profile.identity}.`,
|
|
83
|
+
scope,
|
|
84
|
+
"Work autonomously to completion with the allowed tools; do not ask for routine permission inside the assigned task.",
|
|
85
|
+
"Do not spawn or delegate to other agents.",
|
|
86
|
+
"Report BLOCKED only when the objective is genuinely impossible with the assigned profile or missing external information.",
|
|
87
|
+
];
|
|
88
|
+
if (profile.worktreeLane) {
|
|
89
|
+
sentences.push(`You are bound to worktree-sync lane '${profile.worktreeLane}': work only inside this lane's own worktree, integrate exclusively via worktree_sync land, and never touch main directly.`);
|
|
90
|
+
}
|
|
91
|
+
return sentences.join(" ");
|
|
92
|
+
}
|
|
93
|
+
function isPlainRecord(value) {
|
|
94
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
95
|
+
}
|
|
96
|
+
/** Decode an optional cooperative worker usage claim. Malformed numeric fields are zeroed because
|
|
97
|
+
* the claim is advisory and must never become an authoritative billing record. */
|
|
98
|
+
export function decodeTmuxWorkerUsageClaim(raw) {
|
|
99
|
+
if (!isPlainRecord(raw))
|
|
100
|
+
return undefined;
|
|
101
|
+
const num = (value) => (typeof value === "number" && Number.isFinite(value) ? value : 0);
|
|
102
|
+
const cost = isPlainRecord(raw.cost) ? raw.cost : {};
|
|
103
|
+
return {
|
|
104
|
+
input: num(raw.input),
|
|
105
|
+
output: num(raw.output),
|
|
106
|
+
cacheRead: num(raw.cacheRead),
|
|
107
|
+
cacheWrite: num(raw.cacheWrite),
|
|
108
|
+
totalTokens: num(raw.totalTokens),
|
|
109
|
+
cost: {
|
|
110
|
+
input: num(cost.input),
|
|
111
|
+
output: num(cost.output),
|
|
112
|
+
cacheRead: num(cost.cacheRead),
|
|
113
|
+
cacheWrite: num(cost.cacheWrite),
|
|
114
|
+
total: num(cost.total),
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=launch-profile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"launch-profile.js","sourceRoot":"","sources":["../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AC,CAAC,CAAC,CAAC;IAC1G,MAAM,IAAI,GAAG,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;IACrD,OAAO;QACN,KAAK,EAAE,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC;QACrB,MAAM,EAAE,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC;QACvB,SAAS,EAAE,GAAG,CAAC,GAAG,CAAC,SAAS,CAAC;QAC7B,UAAU,EAAE,GAAG,CAAC,GAAG,CAAC,UAAU,CAAC;QAC/B,WAAW,EAAE,GAAG,CAAC,GAAG,CAAC,WAAW,CAAC;QACjC,IAAI,EAAE;YACL,KAAK,EAAE,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC;YACtB,MAAM,EAAE,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC;YACxB,SAAS,EAAE,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC;YAC9B,UAAU,EAAE,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC;YAChC,KAAK,EAAE,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC;SACtB;KACD,CAAC;AACH,CAAC","sourcesContent":["import {\n\tmapToolNamesForPlatform,\n\tPOLICY_OWNED_RUNTIME_TOOL_NAMES,\n\tWORKER_FORBIDDEN_TOOLS,\n} from \"@caupulican/pi-adaptative\";\nimport type { ThinkingLevel } from \"@caupulican/pi-agent-core\";\nimport type { Usage } from \"@caupulican/pi-ai\";\n\nexport type Provider = \"pi\" | \"codex\" | \"agy\" | \"claude\" | \"opencode\" | \"custom\";\n\nconst MANAGED_WORKER_TOOL_NAMES = POLICY_OWNED_RUNTIME_TOOL_NAMES.filter((tool) => !WORKER_FORBIDDEN_TOOLS.has(tool));\nconst MANAGED_WORKER_TOOL_NAME_SET: ReadonlySet<string> = new Set(MANAGED_WORKER_TOOL_NAMES);\n\n/** Full host-auditable Pi worker surface after the shared worker ceiling removes agent launchers\n * and root-owned durable mutation controls. */\nexport const DEFAULT_MANAGED_WORKER_TOOLS: readonly string[] = Object.freeze([...MANAGED_WORKER_TOOL_NAMES]);\n\nexport class WorkerLaunchProfileError extends Error {\n\treadonly code = \"worker_profile_tools_rejected\" as const;\n\treadonly rejectedTools: readonly string[];\n\n\tconstructor(rejectedTools: readonly string[]) {\n\t\tconst displayNames = rejectedTools.map((tool) => (tool ? `'${tool}'` : \"<empty>\"));\n\t\tsuper(`Worker profile requested unavailable or forbidden tools: ${displayNames.join(\", \")}.`);\n\t\tthis.name = \"WorkerLaunchProfileError\";\n\t\tthis.rejectedTools = Object.freeze([...rejectedTools]);\n\t}\n}\n\nexport interface WorkerLaunchProfileInput {\n\tidentity: string;\n\tinheritedTools?: readonly string[];\n\tallowedTools?: readonly string[];\n\tresourceProfile?: string;\n\tresourceProfileJson?: string;\n\twritePaths?: readonly string[];\n\tthinkingLevel?: ThinkingLevel;\n\tworktreeLane?: string;\n\tparentPid?: number;\n\tparentSession?: string;\n\ttaskRef?: string;\n}\n\n/** Immutable profile compiled once before a managed process is reserved or launched. Empty\n * `writePaths` means the host-derived machine-root scope; a non-empty list is an explicit narrowing. */\nexport interface WorkerLaunchProfile {\n\treadonly identity: string;\n\treadonly allowedTools: readonly string[];\n\treadonly resourceProfile?: string;\n\treadonly resourceProfileJson?: string;\n\treadonly writePaths: readonly string[];\n\treadonly thinkingLevel?: ThinkingLevel;\n\treadonly worktreeLane?: string;\n\treadonly parentPid?: number;\n\treadonly parentSession?: string;\n\treadonly taskRef?: string;\n}\n\nfunction normalizeToolNames(tools: readonly string[]): string[] {\n\treturn mapToolNamesForPlatform(tools.map((tool) => tool.trim().toLowerCase()));\n}\n\nfunction uniqueClassifiedTools(tools: readonly string[]): string[] {\n\tconst selected = new Set(normalizeToolNames(tools).filter((tool) => tool.length > 0));\n\treturn MANAGED_WORKER_TOOL_NAMES.filter((tool) => selected.has(tool));\n}\n\nexport function deriveWorkerLaunchProfile(input: WorkerLaunchProfileInput): WorkerLaunchProfile {\n\tif (input.allowedTools !== undefined) {\n\t\tconst inheritedToolSet =\n\t\t\tinput.inheritedTools === undefined\n\t\t\t\t? MANAGED_WORKER_TOOL_NAME_SET\n\t\t\t\t: new Set(uniqueClassifiedTools(input.inheritedTools));\n\t\tconst rejectedTools = [\n\t\t\t...new Set(\n\t\t\t\tnormalizeToolNames(input.allowedTools).filter(\n\t\t\t\t\t(tool) => !MANAGED_WORKER_TOOL_NAME_SET.has(tool) || !inheritedToolSet.has(tool),\n\t\t\t\t),\n\t\t\t),\n\t\t];\n\t\tif (rejectedTools.length > 0) throw new WorkerLaunchProfileError(rejectedTools);\n\t}\n\tconst sourceTools = input.allowedTools ?? input.inheritedTools ?? DEFAULT_MANAGED_WORKER_TOOLS;\n\tconst allowedTools = Object.freeze(uniqueClassifiedTools(sourceTools));\n\tconst writePaths = Object.freeze([\n\t\t...new Set(input.writePaths?.map((entry) => entry.trim()).filter((entry) => entry.length > 0) ?? []),\n\t]);\n\treturn Object.freeze({\n\t\tidentity: input.identity,\n\t\tallowedTools,\n\t\twritePaths,\n\t\t...(input.resourceProfile ? { resourceProfile: input.resourceProfile } : {}),\n\t\t...(input.resourceProfileJson ? { resourceProfileJson: input.resourceProfileJson } : {}),\n\t\t...(input.thinkingLevel ? { thinkingLevel: input.thinkingLevel } : {}),\n\t\t...(input.worktreeLane ? { worktreeLane: input.worktreeLane } : {}),\n\t\t...(input.parentPid !== undefined ? { parentPid: input.parentPid } : {}),\n\t\t...(input.parentSession ? { parentSession: input.parentSession } : {}),\n\t\t...(input.taskRef ? { taskRef: input.taskRef } : {}),\n\t});\n}\n\nexport interface LaunchProfileFlag {\n\tflag: string;\n\tvalue?: string;\n}\n\n/** Render a Pi child's immutable profile into its own CLI configuration. The manager supplies either\n * an explicit resource-profile override or a one-shot snapshot of the parent's effective resources;\n * standalone callers that omit both retain the child's normal resources. */\nexport function buildLaunchProfileFlags(profile: WorkerLaunchProfile): LaunchProfileFlag[] {\n\tconst flags: LaunchProfileFlag[] = profile.allowedTools.length\n\t\t? [{ flag: \"--tools\", value: profile.allowedTools.join(\",\") }]\n\t\t: [{ flag: \"--no-tools\" }];\n\tif (profile.resourceProfileJson) flags.push({ flag: \"--resource-profile-json\", value: profile.resourceProfileJson });\n\tif (profile.resourceProfile) flags.push({ flag: \"--resource-profile\", value: profile.resourceProfile });\n\tif (profile.thinkingLevel) flags.push({ flag: \"--thinking\", value: profile.thinkingLevel });\n\tif (profile.worktreeLane) flags.push({ flag: \"--worktree-lane\", value: profile.worktreeLane });\n\tif (profile.parentPid !== undefined) flags.push({ flag: \"--parent-pid\", value: String(profile.parentPid) });\n\tif (profile.parentSession) flags.push({ flag: \"--parent-session\", value: profile.parentSession });\n\tif (profile.taskRef) flags.push({ flag: \"--task-ref\", value: profile.taskRef });\n\tflags.push({ flag: \"--append-system-prompt\", value: buildScopedSystemPrompt(profile) });\n\tflags.push({ flag: \"--session-mode\", value: \"worker\" });\n\treturn flags;\n}\n\nexport function buildScopedSystemPrompt(profile: WorkerLaunchProfile): string {\n\tconst scope = profile.writePaths.length\n\t\t? `Structural filesystem tools are limited to: ${profile.writePaths.join(\", \")}. Process tools retain host access and must honor this assigned scope.`\n\t\t: \"Filesystem authority inherits the host's full-machine worker scope except private harness paths.\";\n\tconst sentences = [\n\t\t`You are a tmux worker running under immutable profile ${profile.identity}.`,\n\t\tscope,\n\t\t\"Work autonomously to completion with the allowed tools; do not ask for routine permission inside the assigned task.\",\n\t\t\"Do not spawn or delegate to other agents.\",\n\t\t\"Report BLOCKED only when the objective is genuinely impossible with the assigned profile or missing external information.\",\n\t];\n\tif (profile.worktreeLane) {\n\t\tsentences.push(\n\t\t\t`You are bound to worktree-sync lane '${profile.worktreeLane}': work only inside this lane's own worktree, integrate exclusively via worktree_sync land, and never touch main directly.`,\n\t\t);\n\t}\n\treturn sentences.join(\" \");\n}\n\nfunction isPlainRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\n/** Decode an optional cooperative worker usage claim. Malformed numeric fields are zeroed because\n * the claim is advisory and must never become an authoritative billing record. */\nexport function decodeTmuxWorkerUsageClaim(raw: unknown): Usage | undefined {\n\tif (!isPlainRecord(raw)) return undefined;\n\tconst num = (value: unknown): number => (typeof value === \"number\" && Number.isFinite(value) ? value : 0);\n\tconst cost = isPlainRecord(raw.cost) ? raw.cost : {};\n\treturn {\n\t\tinput: num(raw.input),\n\t\toutput: num(raw.output),\n\t\tcacheRead: num(raw.cacheRead),\n\t\tcacheWrite: num(raw.cacheWrite),\n\t\ttotalTokens: num(raw.totalTokens),\n\t\tcost: {\n\t\t\tinput: num(cost.input),\n\t\t\toutput: num(cost.output),\n\t\t\tcacheRead: num(cost.cacheRead),\n\t\t\tcacheWrite: num(cost.cacheWrite),\n\t\t\ttotal: num(cost.total),\n\t\t},\n\t};\n}\n"]}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import {
|
|
2
|
+
mapToolNamesForPlatform,
|
|
3
|
+
POLICY_OWNED_RUNTIME_TOOL_NAMES,
|
|
4
|
+
WORKER_FORBIDDEN_TOOLS,
|
|
5
|
+
} from "@caupulican/pi-adaptative";
|
|
6
|
+
import type { ThinkingLevel } from "@caupulican/pi-agent-core";
|
|
7
|
+
import type { Usage } from "@caupulican/pi-ai";
|
|
8
|
+
|
|
9
|
+
export type Provider = "pi" | "codex" | "agy" | "claude" | "opencode" | "custom";
|
|
10
|
+
|
|
11
|
+
const MANAGED_WORKER_TOOL_NAMES = POLICY_OWNED_RUNTIME_TOOL_NAMES.filter((tool) => !WORKER_FORBIDDEN_TOOLS.has(tool));
|
|
12
|
+
const MANAGED_WORKER_TOOL_NAME_SET: ReadonlySet<string> = new Set(MANAGED_WORKER_TOOL_NAMES);
|
|
13
|
+
|
|
14
|
+
/** Full host-auditable Pi worker surface after the shared worker ceiling removes agent launchers
|
|
15
|
+
* and root-owned durable mutation controls. */
|
|
16
|
+
export const DEFAULT_MANAGED_WORKER_TOOLS: readonly string[] = Object.freeze([...MANAGED_WORKER_TOOL_NAMES]);
|
|
17
|
+
|
|
18
|
+
export class WorkerLaunchProfileError extends Error {
|
|
19
|
+
readonly code = "worker_profile_tools_rejected" as const;
|
|
20
|
+
readonly rejectedTools: readonly string[];
|
|
21
|
+
|
|
22
|
+
constructor(rejectedTools: readonly string[]) {
|
|
23
|
+
const displayNames = rejectedTools.map((tool) => (tool ? `'${tool}'` : "<empty>"));
|
|
24
|
+
super(`Worker profile requested unavailable or forbidden tools: ${displayNames.join(", ")}.`);
|
|
25
|
+
this.name = "WorkerLaunchProfileError";
|
|
26
|
+
this.rejectedTools = Object.freeze([...rejectedTools]);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface WorkerLaunchProfileInput {
|
|
31
|
+
identity: string;
|
|
32
|
+
inheritedTools?: readonly string[];
|
|
33
|
+
allowedTools?: readonly string[];
|
|
34
|
+
resourceProfile?: string;
|
|
35
|
+
resourceProfileJson?: string;
|
|
36
|
+
writePaths?: readonly string[];
|
|
37
|
+
thinkingLevel?: ThinkingLevel;
|
|
38
|
+
worktreeLane?: string;
|
|
39
|
+
parentPid?: number;
|
|
40
|
+
parentSession?: string;
|
|
41
|
+
taskRef?: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Immutable profile compiled once before a managed process is reserved or launched. Empty
|
|
45
|
+
* `writePaths` means the host-derived machine-root scope; a non-empty list is an explicit narrowing. */
|
|
46
|
+
export interface WorkerLaunchProfile {
|
|
47
|
+
readonly identity: string;
|
|
48
|
+
readonly allowedTools: readonly string[];
|
|
49
|
+
readonly resourceProfile?: string;
|
|
50
|
+
readonly resourceProfileJson?: string;
|
|
51
|
+
readonly writePaths: readonly string[];
|
|
52
|
+
readonly thinkingLevel?: ThinkingLevel;
|
|
53
|
+
readonly worktreeLane?: string;
|
|
54
|
+
readonly parentPid?: number;
|
|
55
|
+
readonly parentSession?: string;
|
|
56
|
+
readonly taskRef?: string;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function normalizeToolNames(tools: readonly string[]): string[] {
|
|
60
|
+
return mapToolNamesForPlatform(tools.map((tool) => tool.trim().toLowerCase()));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function uniqueClassifiedTools(tools: readonly string[]): string[] {
|
|
64
|
+
const selected = new Set(normalizeToolNames(tools).filter((tool) => tool.length > 0));
|
|
65
|
+
return MANAGED_WORKER_TOOL_NAMES.filter((tool) => selected.has(tool));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function deriveWorkerLaunchProfile(input: WorkerLaunchProfileInput): WorkerLaunchProfile {
|
|
69
|
+
if (input.allowedTools !== undefined) {
|
|
70
|
+
const inheritedToolSet =
|
|
71
|
+
input.inheritedTools === undefined
|
|
72
|
+
? MANAGED_WORKER_TOOL_NAME_SET
|
|
73
|
+
: new Set(uniqueClassifiedTools(input.inheritedTools));
|
|
74
|
+
const rejectedTools = [
|
|
75
|
+
...new Set(
|
|
76
|
+
normalizeToolNames(input.allowedTools).filter(
|
|
77
|
+
(tool) => !MANAGED_WORKER_TOOL_NAME_SET.has(tool) || !inheritedToolSet.has(tool),
|
|
78
|
+
),
|
|
79
|
+
),
|
|
80
|
+
];
|
|
81
|
+
if (rejectedTools.length > 0) throw new WorkerLaunchProfileError(rejectedTools);
|
|
82
|
+
}
|
|
83
|
+
const sourceTools = input.allowedTools ?? input.inheritedTools ?? DEFAULT_MANAGED_WORKER_TOOLS;
|
|
84
|
+
const allowedTools = Object.freeze(uniqueClassifiedTools(sourceTools));
|
|
85
|
+
const writePaths = Object.freeze([
|
|
86
|
+
...new Set(input.writePaths?.map((entry) => entry.trim()).filter((entry) => entry.length > 0) ?? []),
|
|
87
|
+
]);
|
|
88
|
+
return Object.freeze({
|
|
89
|
+
identity: input.identity,
|
|
90
|
+
allowedTools,
|
|
91
|
+
writePaths,
|
|
92
|
+
...(input.resourceProfile ? { resourceProfile: input.resourceProfile } : {}),
|
|
93
|
+
...(input.resourceProfileJson ? { resourceProfileJson: input.resourceProfileJson } : {}),
|
|
94
|
+
...(input.thinkingLevel ? { thinkingLevel: input.thinkingLevel } : {}),
|
|
95
|
+
...(input.worktreeLane ? { worktreeLane: input.worktreeLane } : {}),
|
|
96
|
+
...(input.parentPid !== undefined ? { parentPid: input.parentPid } : {}),
|
|
97
|
+
...(input.parentSession ? { parentSession: input.parentSession } : {}),
|
|
98
|
+
...(input.taskRef ? { taskRef: input.taskRef } : {}),
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export interface LaunchProfileFlag {
|
|
103
|
+
flag: string;
|
|
104
|
+
value?: string;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** Render a Pi child's immutable profile into its own CLI configuration. The manager supplies either
|
|
108
|
+
* an explicit resource-profile override or a one-shot snapshot of the parent's effective resources;
|
|
109
|
+
* standalone callers that omit both retain the child's normal resources. */
|
|
110
|
+
export function buildLaunchProfileFlags(profile: WorkerLaunchProfile): LaunchProfileFlag[] {
|
|
111
|
+
const flags: LaunchProfileFlag[] = profile.allowedTools.length
|
|
112
|
+
? [{ flag: "--tools", value: profile.allowedTools.join(",") }]
|
|
113
|
+
: [{ flag: "--no-tools" }];
|
|
114
|
+
if (profile.resourceProfileJson) flags.push({ flag: "--resource-profile-json", value: profile.resourceProfileJson });
|
|
115
|
+
if (profile.resourceProfile) flags.push({ flag: "--resource-profile", value: profile.resourceProfile });
|
|
116
|
+
if (profile.thinkingLevel) flags.push({ flag: "--thinking", value: profile.thinkingLevel });
|
|
117
|
+
if (profile.worktreeLane) flags.push({ flag: "--worktree-lane", value: profile.worktreeLane });
|
|
118
|
+
if (profile.parentPid !== undefined) flags.push({ flag: "--parent-pid", value: String(profile.parentPid) });
|
|
119
|
+
if (profile.parentSession) flags.push({ flag: "--parent-session", value: profile.parentSession });
|
|
120
|
+
if (profile.taskRef) flags.push({ flag: "--task-ref", value: profile.taskRef });
|
|
121
|
+
flags.push({ flag: "--append-system-prompt", value: buildScopedSystemPrompt(profile) });
|
|
122
|
+
flags.push({ flag: "--session-mode", value: "worker" });
|
|
123
|
+
return flags;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export function buildScopedSystemPrompt(profile: WorkerLaunchProfile): string {
|
|
127
|
+
const scope = profile.writePaths.length
|
|
128
|
+
? `Structural filesystem tools are limited to: ${profile.writePaths.join(", ")}. Process tools retain host access and must honor this assigned scope.`
|
|
129
|
+
: "Filesystem authority inherits the host's full-machine worker scope except private harness paths.";
|
|
130
|
+
const sentences = [
|
|
131
|
+
`You are a tmux worker running under immutable profile ${profile.identity}.`,
|
|
132
|
+
scope,
|
|
133
|
+
"Work autonomously to completion with the allowed tools; do not ask for routine permission inside the assigned task.",
|
|
134
|
+
"Do not spawn or delegate to other agents.",
|
|
135
|
+
"Report BLOCKED only when the objective is genuinely impossible with the assigned profile or missing external information.",
|
|
136
|
+
];
|
|
137
|
+
if (profile.worktreeLane) {
|
|
138
|
+
sentences.push(
|
|
139
|
+
`You are bound to worktree-sync lane '${profile.worktreeLane}': work only inside this lane's own worktree, integrate exclusively via worktree_sync land, and never touch main directly.`,
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
return sentences.join(" ");
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function isPlainRecord(value: unknown): value is Record<string, unknown> {
|
|
146
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** Decode an optional cooperative worker usage claim. Malformed numeric fields are zeroed because
|
|
150
|
+
* the claim is advisory and must never become an authoritative billing record. */
|
|
151
|
+
export function decodeTmuxWorkerUsageClaim(raw: unknown): Usage | undefined {
|
|
152
|
+
if (!isPlainRecord(raw)) return undefined;
|
|
153
|
+
const num = (value: unknown): number => (typeof value === "number" && Number.isFinite(value) ? value : 0);
|
|
154
|
+
const cost = isPlainRecord(raw.cost) ? raw.cost : {};
|
|
155
|
+
return {
|
|
156
|
+
input: num(raw.input),
|
|
157
|
+
output: num(raw.output),
|
|
158
|
+
cacheRead: num(raw.cacheRead),
|
|
159
|
+
cacheWrite: num(raw.cacheWrite),
|
|
160
|
+
totalTokens: num(raw.totalTokens),
|
|
161
|
+
cost: {
|
|
162
|
+
input: num(cost.input),
|
|
163
|
+
output: num(cost.output),
|
|
164
|
+
cacheRead: num(cost.cacheRead),
|
|
165
|
+
cacheWrite: num(cost.cacheWrite),
|
|
166
|
+
total: num(cost.total),
|
|
167
|
+
},
|
|
168
|
+
};
|
|
169
|
+
}
|
package/dist/bundled-resources/extensions/tmux-agent-manager/templates/builder-validator.json
CHANGED
|
@@ -9,6 +9,6 @@
|
|
|
9
9
|
{ "provider": "pi", "name": "coordinator" }
|
|
10
10
|
],
|
|
11
11
|
"notes": [
|
|
12
|
-
"Use for
|
|
12
|
+
"Use for implementation/QA batches; never claim complete until result files and validation evidence are inspected."
|
|
13
13
|
]
|
|
14
14
|
}
|
package/dist/bundled-resources/extensions/tmux-agent-manager/templates/provider-prompt-smoke.json
CHANGED
|
@@ -9,6 +9,6 @@
|
|
|
9
9
|
],
|
|
10
10
|
"notes": [
|
|
11
11
|
"Use only when model-token/auth validation is intended.",
|
|
12
|
-
"The manager
|
|
12
|
+
"The manager arms pane capture, starts each CLI with its initial prompt, and watches DONE/BLOCKED markers."
|
|
13
13
|
]
|
|
14
14
|
}
|
|
@@ -98,22 +98,28 @@ history. This is not single-session summarization.
|
|
|
98
98
|
5. Pick the smallest useful layer: Automata memory, skill, prompt template,
|
|
99
99
|
role agent, extension/tool, then core source only when lower layers cannot
|
|
100
100
|
solve it.
|
|
101
|
-
6.
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
101
|
+
6. Automatic reflection is root-only: at most one durable cue is pending for
|
|
102
|
+
the orchestrator and projected transiently into its next ordinary provider
|
|
103
|
+
request. Accepting that request consumes the cue. Disabling reflection
|
|
104
|
+
dismisses it; re-enabling cannot resurrect its evidence. Reflection never
|
|
105
|
+
launches a second, background, or isolated model request. Workers do not
|
|
106
|
+
reflect or mutate durable memory; they return evidence to the orchestrator.
|
|
107
|
+
7. An explicit `/auto-learn run` may launch one bounded background learner with
|
|
108
|
+
the selected active/in-use model. Learners must share the Auto Learn state
|
|
109
|
+
file, use per-session tenant leases, renew/complete their lease, and avoid
|
|
110
|
+
colliding with learners from other sessions.
|
|
111
|
+
8. Auto Learn learners must look for memory. If Automata/user memory is enabled
|
|
106
112
|
and contains rules, preferences, corrections, or project facts, query it
|
|
107
113
|
before judging candidates and use it to polish proposals, avoid duplicates,
|
|
108
114
|
and improve behavioral/tooling accuracy.
|
|
109
|
-
|
|
115
|
+
9. Apply policy gates: memory may be auto-applied only after overlap checks;
|
|
110
116
|
safe low-risk user-level skill/prompt changes may be applied when the current
|
|
111
117
|
request or standing grant authorizes self-improvement. A direct request to
|
|
112
118
|
fix or improve the harness is authorization for scoped source changes; do
|
|
113
119
|
not ask for duplicate approval at each layer transition. Settings,
|
|
114
120
|
credentials, destructive actions, executable authority expansion,
|
|
115
121
|
publishing, pushing, tagging, and releases still require specific approval.
|
|
116
|
-
|
|
122
|
+
10. Leave an audit artifact with evidence sources, recurrence count, chosen
|
|
117
123
|
layer, action/approval need, expected benefit, risk, and validation.
|
|
118
124
|
|
|
119
125
|
## After-action learning workflow
|
|
@@ -9,7 +9,7 @@ description: "Use only when you need a reusable session-scoped worker preset (pr
|
|
|
9
9
|
|
|
10
10
|
Use this skill only to create a session-scoped task preset. Do not load it to start workers.
|
|
11
11
|
|
|
12
|
-
Native `delegate start` does not need an owner-authored base. Omit `profileId` and
|
|
12
|
+
Native `delegate start` does not need an owner-authored base. Omit `profileId` to inherit the foreground model, live reasoning level, compatible tools, and machine scope. Use only the optional top-level `model`, `thinkingLevel`, `path`, and `toolNames` fields to narrow or focus that inheritance. Empty `profile_inspect` bases are not a start block. Never add a budget or authority object: the host compiles grants and owns ceilings. Every generated profile inherits the base budget unchanged.
|
|
13
13
|
|
|
14
14
|
Freedom Dial: high freedom for describing and composing the bounded task; low freedom for authority, persistence, model availability, and budget checks. Pi's core engineering and evidence rules remain mandatory.
|
|
15
15
|
|
|
@@ -22,13 +22,13 @@ Create the smallest immutable profile that can complete one explicit task, then
|
|
|
22
22
|
### 1. Establish the contract
|
|
23
23
|
|
|
24
24
|
1. State the worker's single outcome, required evidence, intended files, and completion boundary.
|
|
25
|
-
2. Call `delegate` with `action: "profile_inspect"` only when you are about to `profile_create` and
|
|
26
|
-
3. If
|
|
27
|
-
4. When
|
|
25
|
+
2. Call `delegate` with `action: "profile_inspect"` only when you are about to `profile_create` and reusable owner bases or configured model/thinking combinations are unknown. Inspection is optional.
|
|
26
|
+
3. If no owner-authored base is selected, `profile_create` derives its base directly from the foreground inheritance. Do not ask the user to authorize a base just to start work or create a preset.
|
|
27
|
+
4. When an owner-authored base is useful, choose one whose authority already covers the task. Never derive from another generated task profile.
|
|
28
28
|
5. Prefer the fastest model with demonstrated ability to satisfy the task contract. Configuration and authentication prove availability, not fitness; use existing fitness evidence or `model_fitness` when the risk justifies its token cost.
|
|
29
|
-
6. Request only the
|
|
29
|
+
6. Request only the model, thinking level, one workspace path, and exact tool subset the task needs. Omitted fields inherit the base. Resources and budget always remain host-owned and inherited.
|
|
30
30
|
|
|
31
|
-
Human edge: if
|
|
31
|
+
Human edge: if an explicitly requested reusable preset needs unavailable credentials, tools outside its inherited surface, or a different budget, report the exact rejection and ask for an owner-profile change. Do not route around a rejection. Ordinary inherited `delegate start` remains available unless the host reports a real admission block.
|
|
32
32
|
|
|
33
33
|
### 2. Execute and verify
|
|
34
34
|
|
|
@@ -43,15 +43,15 @@ Human edge: if `profile_create` is required and the task needs an unlisted base,
|
|
|
43
43
|
- Blocking `delegate start` because `profile_inspect` listed no bases.
|
|
44
44
|
- Writing one-off profile JSON, settings, reports, or dependencies into the repository.
|
|
45
45
|
- Selecting a model or thinking level that `inspect` did not report as available.
|
|
46
|
-
- Giving a worker extra tools "just in case" or attempting
|
|
46
|
+
- Giving a worker extra tools "just in case", authoring resource/capability arrays, or attempting a per-dispatch budget.
|
|
47
47
|
- Inventing, guessing, editing, or reusing a generated profile ID across sessions or branches.
|
|
48
48
|
- Treating a fast model as fit without task-shaped evidence.
|
|
49
49
|
|
|
50
50
|
## Examples
|
|
51
51
|
|
|
52
|
-
Positive: inspect, derive from
|
|
52
|
+
Positive: omit inspect and base, derive from foreground inheritance, select an authenticated fast model at `low`, narrow tools to `read`, `grep`, and `edit`, inherit host resources and budget unchanged, then delegate with the returned `task-...` ID.
|
|
53
53
|
|
|
54
|
-
Positive:
|
|
54
|
+
Positive: start two workers with self-contained instructions and no `profileId`; omit overrides when both should inherit the foreground model, reasoning, tools, and machine scope.
|
|
55
55
|
|
|
56
56
|
Negative: a base exposes only `read` and `grep`, but the task requires `edit`. Do not request `edit` from `profile_create`; select an authorized write-capable base or ask the user for an owner-profile change. Starting without a profile remains allowed.
|
|
57
57
|
|
|
@@ -62,9 +62,9 @@ Negative: telling the user workers are blocked until they authorize explorer/imp
|
|
|
62
62
|
- Ordinary start omitted `profileId` unless a returned `task-...` ID is in hand.
|
|
63
63
|
- Empty inspect bases did not stop start.
|
|
64
64
|
- The task has one bounded outcome and explicit acceptance evidence.
|
|
65
|
-
- The base
|
|
65
|
+
- The base is foreground inheritance or an owner-authored profile authorized for this orchestrator.
|
|
66
66
|
- Model and thinking level were reported available or otherwise resolved by the harness.
|
|
67
|
-
- Tools
|
|
67
|
+
- Tools are an exact subset; resources and budget remain inherited and host-owned.
|
|
68
68
|
- The returned ID is passed unchanged; no project/user profile file was created.
|
|
69
69
|
|
|
70
70
|
## Known Gaps
|
|
@@ -20,7 +20,7 @@ import type { MemoryRetrievalReport } from "./context/memory-retrieval.ts";
|
|
|
20
20
|
import type { ContextGcReport } from "./context-gc.ts";
|
|
21
21
|
import type { SessionCostSummary } from "./cost/cost-summary.ts";
|
|
22
22
|
import type { DailyUsageTotals } from "./cost/daily-usage.ts";
|
|
23
|
-
import {
|
|
23
|
+
import type { CostGuardDecision, CostGuardSettings } from "./cost-guard.ts";
|
|
24
24
|
import type { WorkerDelegationRequest } from "./delegation/worker-delegation-request.ts";
|
|
25
25
|
import type { CompactOptions, ContextUsage, ExtensionRunner, ReplacedSessionContext, ToolDefinition, ToolInfo } from "./extensions/index.ts";
|
|
26
26
|
import { type ChannelProvider, GatewayRegistry, type JobSchedulerProvider } from "./gateways/channel-provider.ts";
|
|
@@ -41,7 +41,7 @@ import { type PromptTemplate } from "./prompt-templates.ts";
|
|
|
41
41
|
import type { ModelFitnessReport } from "./research/model-fitness.ts";
|
|
42
42
|
import type { ResourceLoader } from "./resource-loader.ts";
|
|
43
43
|
import type { CredentialManager } from "./secrets/credential-manager.ts";
|
|
44
|
-
import type { SettingsManager } from "./settings-manager.ts";
|
|
44
|
+
import type { SettingsManager, SettingsScope } from "./settings-manager.ts";
|
|
45
45
|
import { type TaskStepsState } from "./tasks/task-state.ts";
|
|
46
46
|
import { type ToolProbeReport } from "./tool-protocol-controller.ts";
|
|
47
47
|
import type { BashOperations } from "./tools/bash.ts";
|
|
@@ -62,6 +62,7 @@ export declare class AgentSession {
|
|
|
62
62
|
capabilityEnvelope?: CapabilityEnvelope;
|
|
63
63
|
private _scopedModels;
|
|
64
64
|
private _unsubscribeAgent?;
|
|
65
|
+
private _unsubscribeSettingsChanges?;
|
|
65
66
|
private _eventListeners;
|
|
66
67
|
private _extensionsChangedListeners;
|
|
67
68
|
private _steeringMessages;
|
|
@@ -94,9 +95,8 @@ export declare class AgentSession {
|
|
|
94
95
|
private _agentDir;
|
|
95
96
|
private _collectWorkspaceSources;
|
|
96
97
|
private readonly _localRuntimeController;
|
|
98
|
+
private readonly _localPrefixWarm;
|
|
97
99
|
private readonly _toolProtocol;
|
|
98
|
-
private _prefixWarmer;
|
|
99
|
-
private readonly _completedPrefixWarms;
|
|
100
100
|
/** Assembles the session's base system prompt from live session state (see
|
|
101
101
|
* system-prompt-builder.ts); owns the paired _baseSystemPromptOptions. */
|
|
102
102
|
private readonly _systemPromptBuilder;
|
|
@@ -136,14 +136,7 @@ export declare class AgentSession {
|
|
|
136
136
|
* owns the spawned-usage and daily-usage memo caches. */
|
|
137
137
|
private readonly _analytics;
|
|
138
138
|
private readonly _treeNavigator;
|
|
139
|
-
private
|
|
140
|
-
/**
|
|
141
|
-
* `getSpawnedUsage().cost` snapshotted at the start of the CURRENT foreground prompt cycle (see
|
|
142
|
-
* `_promptUnserialized`), so the cost guard can attribute only background/spawned spend since THIS
|
|
143
|
-
* turn began, not the session's entire lifetime spend. Reset on every new user prompt; every
|
|
144
|
-
* round-trip within the same turn (tool-call iterations) shares this one baseline.
|
|
145
|
-
*/
|
|
146
|
-
private _costGuardTurnBaselineUsd;
|
|
139
|
+
private readonly _costGuard;
|
|
147
140
|
/** Per-turn model-router subsystem (see model-router-controller.ts); owns the transient route/intent,
|
|
148
141
|
* the cheap-turn session buffer, the escalation/retry flags, and the sticky last-decision/skip-reason
|
|
149
142
|
* used by the status report. Its parallel routed drive path delegates every turn back to
|
|
@@ -161,8 +154,7 @@ export declare class AgentSession {
|
|
|
161
154
|
private _disposed;
|
|
162
155
|
private _disposeCompletion;
|
|
163
156
|
private readonly _reflectionAbort;
|
|
164
|
-
/**
|
|
165
|
-
* session state, applies durable writes through the bundled memory tool and the session log. */
|
|
157
|
+
/** Root current-turn reflection cue + explicit learning-apply/rollback compatibility path. */
|
|
166
158
|
private readonly _reflection;
|
|
167
159
|
/** Durable goal lifecycle, accounting, and raw continuation loop. */
|
|
168
160
|
private readonly _goals;
|
|
@@ -188,10 +180,6 @@ export declare class AgentSession {
|
|
|
188
180
|
constructor(config: AgentSessionConfig);
|
|
189
181
|
/** Model registry for API key resolution and model discovery */
|
|
190
182
|
get modelRegistry(): ModelRegistry;
|
|
191
|
-
private _scheduleLocalPrefixWarm;
|
|
192
|
-
private _cancelPrefixWarm;
|
|
193
|
-
private _runLocalPrefixWarm;
|
|
194
|
-
private _isWarmableLocalModel;
|
|
195
183
|
/**
|
|
196
184
|
* True when the session's stream fn is the raw `streamSimple` provider entry (directly, or as the
|
|
197
185
|
* base wrapped by the idle watchdog at construction). Callers use this to decide whether request
|
|
@@ -210,25 +198,10 @@ export declare class AgentSession {
|
|
|
210
198
|
private _describeCompactionSummarizer;
|
|
211
199
|
private _getLastCompactionSelectionReason;
|
|
212
200
|
private _resolveCompactionThinkingLevel;
|
|
213
|
-
/**
|
|
214
|
-
* Resolve the foreground request's cost policy after routing/context conversion, when the actual
|
|
215
|
-
* model, full system prompt, converted messages, and tool schemas are known. The guard is a
|
|
216
|
-
* projection threshold rather than a hard output cap: warning mode never reduces capability, while
|
|
217
|
-
* opt-in downgrade changes only this request's reasoning effort. Best-effort: never throws.
|
|
218
|
-
*
|
|
219
|
-
* The ceiling is turn-cumulative: the next foreground call's projection is folded together with
|
|
220
|
-
* background/research/worker/reflection spend recorded SINCE THIS TURN BEGAN — {@link getSpawnedUsage}'s
|
|
221
|
-
* already-recorded rollup (the same read-side-deduped total the footer's SUBAGENTS line uses) minus the
|
|
222
|
-
* baseline snapshotted before a new turn enters routing in `_promptUnserialized`
|
|
223
|
-
* ({@link _costGuardTurnBaselineUsd}) — so a
|
|
224
|
-
* turn that is cheap in the foreground but has spent heavily via background lanes THIS turn still trips
|
|
225
|
-
* the warning, while a prior turn's background spend does not keep every later turn's guard stuck
|
|
226
|
-
* "over". A background lane that finishes mid-turn is attributed to whichever turn it completes in.
|
|
227
|
-
* Per-lane dollar caps (research/worker `maxUsd`) are separate and untouched by this guard.
|
|
228
|
-
*/
|
|
229
|
-
private _resolveCostGuardRequestReasoning;
|
|
230
201
|
/** Latest cost-guard decision (for the host footer/UI to surface a warning). Undefined if disabled. */
|
|
231
202
|
getLastCostGuardDecision(): CostGuardDecision | undefined;
|
|
203
|
+
/** Apply an explicit guard choice and invalidate all prior decision/envelope projections immediately. */
|
|
204
|
+
setCostGuardSettings(settings: CostGuardSettings, scope?: SettingsScope): void;
|
|
232
205
|
private get _skillCurator();
|
|
233
206
|
/**
|
|
234
207
|
* Skill curator (#32): PROPOSE (never auto-apply) archival of stale reflection-promoted skills and
|
|
@@ -960,14 +933,11 @@ export declare class AgentSession {
|
|
|
960
933
|
* call `this._goals.continueLoop` directly from here — that bypasses the guard.
|
|
961
934
|
*/
|
|
962
935
|
continueGoalLoop(options: GoalContinuationLoopOptions): Promise<GoalContinuationLoopResult>;
|
|
963
|
-
/**
|
|
964
|
-
* Run a one-shot LLM completion fully ISOLATED from the main session — the load-bearing primitive
|
|
965
|
-
* for native reflection (see reflection-controller.ts for the isolation invariants).
|
|
966
|
-
*/
|
|
936
|
+
/** Run one explicit isolated completion for bounded host-owned consumers. */
|
|
967
937
|
runIsolatedCompletion(opts: IsolatedCompletionOptions): Promise<IsolatedCompletionResult>;
|
|
968
938
|
/**
|
|
969
|
-
*
|
|
970
|
-
* when the demand gate skips or in a child session.
|
|
939
|
+
* Explicit compatibility/application reflection pass. Automatic reflection never calls this
|
|
940
|
+
* method; it returns null when the demand gate skips or in a child session.
|
|
971
941
|
*/
|
|
972
942
|
runReflectionPass(input: {
|
|
973
943
|
signals: DemandSignals;
|