@oh-my-pi/pi-coding-agent 17.0.8 → 17.1.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 +87 -1
- package/README.md +1 -1
- package/dist/cli.js +5495 -5021
- package/dist/types/async/job-manager.d.ts +37 -1
- package/dist/types/cli/args.d.ts +2 -0
- package/dist/types/cli/bench-cli.d.ts +41 -0
- package/dist/types/commands/bench.d.ts +15 -3
- package/dist/types/commands/launch.d.ts +4 -0
- package/dist/types/config/__tests__/model-registry.test.d.ts +1 -0
- package/dist/types/config/model-registry.d.ts +30 -1
- package/dist/types/config/models-config-schema.d.ts +18 -6
- package/dist/types/config/models-config.d.ts +14 -5
- package/dist/types/config/provider-globals.d.ts +2 -2
- package/dist/types/config/service-tier.d.ts +5 -1
- package/dist/types/config/settings-schema.d.ts +350 -50
- package/dist/types/config/settings.d.ts +7 -0
- package/dist/types/dap/client.d.ts +20 -0
- package/dist/types/exec/bash-executor.d.ts +38 -0
- package/dist/types/exec/direnv.d.ts +33 -0
- package/dist/types/export/html/args.d.ts +15 -0
- package/dist/types/export/html/index.d.ts +11 -26
- package/dist/types/export/html/web-palette.d.ts +55 -116
- package/dist/types/extensibility/extensions/loader.d.ts +3 -0
- package/dist/types/extensibility/extensions/types.d.ts +17 -2
- package/dist/types/extensibility/legacy-pi-coding-agent-shim.d.ts +1 -0
- package/dist/types/extensibility/legacy-pi-tui-shim.d.ts +10 -0
- package/dist/types/extensibility/plugins/legacy-pi-compat.d.ts +14 -1
- package/dist/types/internal-urls/registry-helpers.d.ts +11 -0
- package/dist/types/live/controller.d.ts +40 -0
- package/dist/types/live/protocol.d.ts +85 -0
- package/dist/types/live/protocol.test.d.ts +1 -0
- package/dist/types/live/transport.d.ts +48 -0
- package/dist/types/live/visualizer.d.ts +33 -0
- package/dist/types/lsp/client.d.ts +18 -1
- package/dist/types/mcp/config-writer.test.d.ts +1 -0
- package/dist/types/mcp/manager.d.ts +6 -2
- package/dist/types/mcp/oauth-discovery.d.ts +2 -0
- package/dist/types/mcp/render.d.ts +2 -2
- package/dist/types/mcp/smithery-auth.d.ts +1 -1
- package/dist/types/mcp/smithery-auth.test.d.ts +1 -0
- package/dist/types/mcp/tool-bridge.d.ts +7 -3
- package/dist/types/mcp/types.d.ts +6 -0
- package/dist/types/memory-backend/tool-names.d.ts +2 -0
- package/dist/types/modes/components/login-dialog.d.ts +2 -2
- package/dist/types/modes/components/oauth-selector.d.ts +8 -0
- package/dist/types/modes/components/plan-review-overlay.d.ts +26 -0
- package/dist/types/modes/components/settings-defs.d.ts +8 -1
- package/dist/types/modes/components/status-line/component.jj-cache.test.d.ts +1 -0
- package/dist/types/modes/components/tool-execution.d.ts +9 -1
- package/dist/types/modes/controllers/command-controller.d.ts +1 -1
- package/dist/types/modes/controllers/event-controller.d.ts +6 -1
- package/dist/types/modes/controllers/live-command-controller.d.ts +14 -0
- package/dist/types/modes/controllers/mcp-command-controller.d.ts +3 -0
- package/dist/types/modes/interactive-mode.d.ts +5 -0
- package/dist/types/modes/rpc/rpc-client.d.ts +10 -1
- package/dist/types/modes/rpc/rpc-frame.d.ts +16 -0
- package/dist/types/modes/rpc/rpc-messages.d.ts +26 -0
- package/dist/types/modes/rpc/rpc-types.d.ts +40 -0
- package/dist/types/modes/setup-wizard/scenes/sign-in.d.ts +1 -1
- package/dist/types/modes/setup-wizard/scenes/types.d.ts +9 -1
- package/dist/types/modes/setup-wizard/scenes/web-search.d.ts +1 -1
- package/dist/types/modes/theme/theme.d.ts +1 -1
- package/dist/types/modes/types.d.ts +3 -1
- package/dist/types/modes/utils/context-usage.d.ts +12 -2
- package/dist/types/plan-mode/plan-files.d.ts +10 -0
- package/dist/types/registry/agent-lifecycle.d.ts +21 -9
- package/dist/types/registry/agent-registry.d.ts +11 -4
- package/dist/types/sdk.d.ts +15 -1
- package/dist/types/secrets/index.d.ts +15 -2
- package/dist/types/secrets/obfuscator.d.ts +113 -15
- package/dist/types/session/acp-permission-gate.d.ts +19 -0
- package/dist/types/session/agent-session-events.d.ts +84 -0
- package/dist/types/session/agent-session-types.d.ts +314 -0
- package/dist/types/session/agent-session.d.ts +120 -750
- package/dist/types/session/async-job-delivery.d.ts +28 -0
- package/dist/types/session/bash-runner.d.ts +75 -0
- package/dist/types/session/blob-store.d.ts +11 -1
- package/dist/types/session/blob-store.test.d.ts +1 -0
- package/dist/types/session/checkpoint-entries.d.ts +28 -0
- package/dist/types/session/eval-runner.d.ts +49 -0
- package/dist/types/session/irc-bridge.d.ts +46 -0
- package/dist/types/session/messages.d.ts +22 -0
- package/dist/types/session/model-controls.d.ts +180 -0
- package/dist/types/session/prewalk.d.ts +46 -0
- package/dist/types/session/queued-messages.d.ts +22 -0
- package/dist/types/session/redis-session-storage.d.ts +1 -0
- package/dist/types/session/retry-fallback-chains.d.ts +74 -0
- package/dist/types/session/role-models.d.ts +15 -0
- package/dist/types/session/session-advisors.d.ts +228 -0
- package/dist/types/session/session-entries.d.ts +8 -0
- package/dist/types/session/session-handoff.d.ts +70 -0
- package/dist/types/session/session-history-format.d.ts +6 -1
- package/dist/types/session/session-loader.d.ts +6 -4
- package/dist/types/session/session-maintenance.d.ts +246 -0
- package/dist/types/session/session-manager.d.ts +41 -0
- package/dist/types/session/session-memory.d.ts +56 -0
- package/dist/types/session/session-provider-boundary.d.ts +62 -0
- package/dist/types/session/session-stats.d.ts +48 -0
- package/dist/types/session/session-tools.d.ts +143 -0
- package/dist/types/session/session-workspace.d.ts +32 -0
- package/dist/types/session/stream-guards.d.ts +44 -0
- package/dist/types/session/todo-tracker.d.ts +56 -0
- package/dist/types/session/ttsr-coordinator.d.ts +51 -0
- package/dist/types/session/turn-recovery.d.ts +225 -0
- package/dist/types/system-prompt.d.ts +2 -0
- package/dist/types/task/executor.d.ts +4 -1
- package/dist/types/task/output-manager.d.ts +3 -1
- package/dist/types/task/types.d.ts +14 -0
- package/dist/types/tools/approval.d.ts +1 -0
- package/dist/types/tools/browser/launch.d.ts +5 -0
- package/dist/types/tools/hub/jobs.d.ts +1 -1
- package/dist/types/tools/image-gen.d.ts +4 -4
- package/dist/types/tools/image-providers.d.ts +38 -0
- package/dist/types/tools/index.d.ts +8 -0
- package/dist/types/tools/path-utils.d.ts +8 -0
- package/dist/types/tools/report-tool-issue.d.ts +24 -9
- package/dist/types/tools/todo.d.ts +10 -4
- package/dist/types/tools/xdev.d.ts +5 -1
- package/dist/types/tts/streaming-player.d.ts +14 -0
- package/dist/types/tts/vocalizer.d.ts +5 -0
- package/dist/types/utils/jj.d.ts +29 -0
- package/dist/types/utils/lang-from-path.d.ts +1 -0
- package/dist/types/utils/title-generator.d.ts +30 -0
- package/dist/types/vibe/runtime.d.ts +36 -8
- package/dist/types/web/search/index.d.ts +1 -1
- package/dist/types/web/search/provider.d.ts +15 -5
- package/dist/types/web/search/providers/firecrawl.d.ts +9 -0
- package/dist/types/web/search/types.d.ts +95 -1
- package/package.json +13 -12
- package/scripts/generate-share-viewer.ts +4 -6
- package/scripts/legacy-pi-virtual-module.ts +1 -1
- package/src/advisor/__tests__/advisor.test.ts +643 -0
- package/src/advisor/runtime.ts +144 -43
- package/src/async/job-manager.ts +90 -2
- package/src/cli/args.ts +2 -0
- package/src/cli/auth-gateway-cli.ts +18 -3
- package/src/cli/bench-cli.ts +395 -29
- package/src/cli/flag-tables.ts +3 -0
- package/src/cli/gc-cli.ts +2 -2
- package/src/cli/grievances-cli.ts +2 -2
- package/src/cli/usage-cli.ts +11 -2
- package/src/collab/host.ts +3 -2
- package/src/commands/bench.ts +18 -4
- package/src/commands/launch.ts +4 -0
- package/src/config/__tests__/model-registry.test.ts +147 -0
- package/src/config/model-registry.ts +50 -2
- package/src/config/model-resolver.ts +0 -1
- package/src/config/models-config-schema.ts +15 -4
- package/src/config/provider-globals.ts +9 -9
- package/src/config/service-tier.ts +26 -1
- package/src/config/settings-schema.ts +250 -54
- package/src/config/settings.ts +81 -2
- package/src/dap/client.ts +37 -4
- package/src/edit/index.ts +49 -12
- package/src/eval/py/executor.ts +103 -33
- package/src/exec/bash-executor.ts +89 -6
- package/src/exec/direnv.ts +145 -0
- package/src/export/html/args.ts +20 -0
- package/src/export/html/index.ts +45 -47
- package/src/export/html/template.css +19 -1
- package/src/export/html/template.html +6 -0
- package/src/export/html/template.js +21 -0
- package/src/export/html/tool-views.generated.js +31 -31
- package/src/export/html/web-palette.ts +116 -132
- package/src/export/share.ts +249 -49
- package/src/extensibility/extensions/loader.ts +29 -1
- package/src/extensibility/extensions/runner.ts +6 -0
- package/src/extensibility/extensions/types.ts +33 -2
- package/src/extensibility/legacy-pi-coding-agent-shim.ts +1 -0
- package/src/extensibility/legacy-pi-tui-shim.ts +10 -0
- package/src/extensibility/plugins/legacy-pi-compat.ts +870 -311
- package/src/hindsight/state.ts +64 -6
- package/src/internal-urls/local-protocol.ts +2 -1
- package/src/internal-urls/memory-protocol.ts +2 -2
- package/src/internal-urls/registry-helpers.ts +40 -0
- package/src/internal-urls/skill-protocol.ts +2 -2
- package/src/internal-urls/ssh-protocol.ts +2 -1
- package/src/internal-urls/vault-protocol.ts +2 -1
- package/src/live/audio-worklet.txt +59 -0
- package/src/live/browser-runtime.txt +221 -0
- package/src/live/controller.ts +464 -0
- package/src/live/prompts/agent-final-message.md +3 -0
- package/src/live/prompts/live-instructions.md +23 -0
- package/src/live/protocol.test.ts +140 -0
- package/src/live/protocol.ts +233 -0
- package/src/live/transport.ts +490 -0
- package/src/live/visualizer.ts +234 -0
- package/src/lsp/client.ts +52 -9
- package/src/lsp/clients/biome-client.ts +3 -4
- package/src/lsp/index.ts +44 -11
- package/src/main.ts +9 -1
- package/src/mcp/config-writer.test.ts +43 -0
- package/src/mcp/config-writer.ts +109 -82
- package/src/mcp/manager.ts +39 -8
- package/src/mcp/oauth-discovery.ts +10 -2
- package/src/mcp/render.ts +94 -35
- package/src/mcp/smithery-auth.test.ts +29 -0
- package/src/mcp/smithery-auth.ts +3 -2
- package/src/mcp/tool-bridge.ts +107 -11
- package/src/mcp/types.ts +7 -0
- package/src/memories/index.ts +40 -20
- package/src/memory-backend/tool-names.ts +2 -0
- package/src/mnemopi/backend.ts +24 -7
- package/src/modes/acp/acp-agent.ts +56 -10
- package/src/modes/acp/acp-event-mapper.ts +8 -1
- package/src/modes/components/agent-hub.ts +27 -10
- package/src/modes/components/login-dialog.ts +14 -4
- package/src/modes/components/oauth-selector.ts +24 -7
- package/src/modes/components/plan-review-overlay.ts +350 -35
- package/src/modes/components/settings-defs.ts +28 -3
- package/src/modes/components/settings-selector.ts +178 -6
- package/src/modes/components/status-line/component.jj-cache.test.ts +229 -0
- package/src/modes/components/status-line/component.ts +123 -2
- package/src/modes/components/tool-execution.test.ts +63 -2
- package/src/modes/components/tool-execution.ts +11 -2
- package/src/modes/controllers/command-controller.ts +70 -22
- package/src/modes/controllers/event-controller.ts +111 -16
- package/src/modes/controllers/extension-ui-controller.test.ts +1 -0
- package/src/modes/controllers/extension-ui-controller.ts +20 -4
- package/src/modes/controllers/live-command-controller.ts +178 -0
- package/src/modes/controllers/mcp-command-controller.ts +80 -41
- package/src/modes/controllers/omfg-controller.ts +44 -40
- package/src/modes/controllers/selector-controller.ts +18 -10
- package/src/modes/controllers/session-focus-controller.ts +6 -1
- package/src/modes/interactive-mode.ts +160 -38
- package/src/modes/rpc/rpc-client.ts +94 -3
- package/src/modes/rpc/rpc-frame.ts +164 -4
- package/src/modes/rpc/rpc-messages.ts +127 -0
- package/src/modes/rpc/rpc-mode.ts +79 -7
- package/src/modes/rpc/rpc-types.ts +34 -2
- package/src/modes/runtime-init.ts +2 -0
- package/src/modes/setup-wizard/scenes/model.ts +5 -7
- package/src/modes/setup-wizard/scenes/providers.ts +3 -2
- package/src/modes/setup-wizard/scenes/sign-in.ts +8 -2
- package/src/modes/setup-wizard/scenes/theme.ts +13 -3
- package/src/modes/setup-wizard/scenes/types.ts +9 -1
- package/src/modes/setup-wizard/scenes/web-search.ts +23 -10
- package/src/modes/setup-wizard/wizard-overlay.ts +1 -1
- package/src/modes/theme/theme.ts +1 -1
- package/src/modes/types.ts +3 -1
- package/src/modes/utils/context-usage.ts +23 -7
- package/src/modes/utils/ui-helpers.ts +10 -5
- package/src/plan-mode/plan-files.ts +40 -0
- package/src/prompts/bench/cache-prefix-chunk.md +1 -0
- package/src/prompts/bench/cache-prefix.md +3 -0
- package/src/prompts/bench/cache-suffix.md +1 -0
- package/src/prompts/goals/guided-goal-system.md +24 -3
- package/src/prompts/system/custom-system-prompt.md +1 -1
- package/src/prompts/system/project-prompt.md +8 -1
- package/src/prompts/system/subagent-async-pending.md +6 -0
- package/src/prompts/system/system-prompt.md +1 -1
- package/src/prompts/system/workflow-notice.md +48 -40
- package/src/prompts/system/xdev-mount-notice.md +4 -0
- package/src/prompts/tools/task.md +12 -2
- package/src/prompts/tools/todo.md +3 -1
- package/src/registry/agent-lifecycle.ts +116 -46
- package/src/registry/agent-registry.ts +35 -8
- package/src/registry/persisted-agents.ts +26 -2
- package/src/sdk.ts +255 -139
- package/src/secrets/index.ts +127 -4
- package/src/secrets/obfuscator.ts +2328 -105
- package/src/session/acp-permission-gate.ts +165 -0
- package/src/session/agent-session-error-log.test.ts +1 -1
- package/src/session/agent-session-events.ts +66 -0
- package/src/session/agent-session-types.ts +334 -0
- package/src/session/agent-session.ts +1910 -12213
- package/src/session/artifacts.ts +6 -5
- package/src/session/async-job-delivery.ts +74 -0
- package/src/session/bash-runner.ts +326 -0
- package/src/session/blob-store.test.ts +56 -0
- package/src/session/blob-store.ts +18 -2
- package/src/session/checkpoint-entries.ts +81 -0
- package/src/session/eval-runner.ts +212 -0
- package/src/session/indexed-session-storage.ts +9 -2
- package/src/session/irc-bridge.ts +203 -0
- package/src/session/messages.ts +263 -1
- package/src/session/model-controls.ts +714 -0
- package/src/session/prewalk.ts +252 -0
- package/src/session/queued-messages.ts +93 -0
- package/src/session/redis-session-storage.ts +51 -11
- package/src/session/retry-fallback-chains.ts +455 -0
- package/src/session/role-models.ts +85 -0
- package/src/session/session-advisors.ts +1679 -0
- package/src/session/session-context.test.ts +224 -1
- package/src/session/session-context.ts +47 -5
- package/src/session/session-entries.ts +8 -0
- package/src/session/session-handoff.ts +308 -0
- package/src/session/session-history-format.ts +20 -9
- package/src/session/session-loader.ts +10 -51
- package/src/session/session-maintenance.ts +2983 -0
- package/src/session/session-manager.ts +390 -30
- package/src/session/session-memory.ts +222 -0
- package/src/session/session-provider-boundary.ts +307 -0
- package/src/session/session-stats.ts +293 -0
- package/src/session/session-tools.ts +943 -0
- package/src/session/session-workspace.ts +53 -0
- package/src/session/stream-guards.ts +417 -0
- package/src/session/todo-tracker.ts +380 -0
- package/src/session/ttsr-coordinator.ts +496 -0
- package/src/session/turn-recovery.ts +1629 -0
- package/src/slash-commands/builtin-registry.ts +92 -11
- package/src/slash-commands/helpers/usage-report.ts +25 -4
- package/src/system-prompt.ts +41 -17
- package/src/task/executor.ts +288 -70
- package/src/task/index.ts +148 -111
- package/src/task/output-manager.ts +25 -3
- package/src/task/persisted-revive.ts +4 -3
- package/src/task/structured-subagent.ts +4 -1
- package/src/task/types.ts +16 -0
- package/src/tools/approval.ts +55 -10
- package/src/tools/bash-interactive.ts +26 -0
- package/src/tools/bash-skill-urls.ts +28 -2
- package/src/tools/bash.ts +339 -123
- package/src/tools/browser/launch.ts +9 -1
- package/src/tools/browser/tab-supervisor.ts +8 -5
- package/src/tools/browser.ts +94 -47
- package/src/tools/hub/index.ts +1 -1
- package/src/tools/hub/jobs.ts +67 -8
- package/src/tools/image-gen.ts +20 -28
- package/src/tools/image-providers.ts +50 -0
- package/src/tools/index.ts +12 -0
- package/src/tools/path-utils.ts +49 -2
- package/src/tools/read.ts +156 -88
- package/src/tools/renderers.ts +7 -1
- package/src/tools/report-tool-issue.ts +79 -28
- package/src/tools/todo.ts +101 -11
- package/src/tools/vibe.ts +1 -2
- package/src/tools/write.ts +51 -1
- package/src/tools/xdev.ts +67 -3
- package/src/tts/streaming-player.ts +62 -4
- package/src/tts/vocalizer.ts +18 -1
- package/src/utils/jj.ts +125 -4
- package/src/utils/lang-from-path.ts +7 -0
- package/src/utils/title-generator.ts +137 -1
- package/src/vibe/runtime.ts +852 -72
- package/src/web/search/index.ts +3 -6
- package/src/web/search/provider.ts +31 -16
- package/src/web/search/providers/firecrawl.ts +46 -13
- package/src/web/search/providers/xai.ts +7 -1
- package/src/web/search/types.ts +8 -1
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { Agent, type AgentMessage, type AgentTool, type StreamFn } from "@oh-my-pi/pi-agent-core";
|
|
2
|
+
import type { CodexCompactionContext, Context, Message, Model, ProviderSessionState, ServiceTier, SimpleStreamOptions } from "@oh-my-pi/pi-ai";
|
|
3
|
+
import { type AdvisorConfig, type AdvisorRuntimeStatus } from "../advisor/index.js";
|
|
4
|
+
import type { ModelRegistry } from "../config/model-registry.js";
|
|
5
|
+
import type { Settings } from "../config/settings.js";
|
|
6
|
+
import type { PlanModeState } from "../plan-mode/state.js";
|
|
7
|
+
import type { SecretObfuscator } from "../secrets/obfuscator.js";
|
|
8
|
+
import type { AgentSessionEvent } from "./agent-session-events.js";
|
|
9
|
+
import type { ClientBridge } from "./client-bridge.js";
|
|
10
|
+
import type { CustomMessage, CustomMessagePayload } from "./messages.js";
|
|
11
|
+
import { type RetryFallbackSelector } from "./retry-fallback-chains.js";
|
|
12
|
+
import type { SessionManager } from "./session-manager.js";
|
|
13
|
+
import type { YieldQueue } from "./yield-queue.js";
|
|
14
|
+
/** Advisor statistics for the advisor status command. */
|
|
15
|
+
export interface AdvisorStats {
|
|
16
|
+
configured: boolean;
|
|
17
|
+
active: boolean;
|
|
18
|
+
model?: Model;
|
|
19
|
+
contextWindow: number;
|
|
20
|
+
contextTokens: number;
|
|
21
|
+
tokens: {
|
|
22
|
+
input: number;
|
|
23
|
+
output: number;
|
|
24
|
+
reasoning: number;
|
|
25
|
+
cacheRead: number;
|
|
26
|
+
cacheWrite: number;
|
|
27
|
+
total: number;
|
|
28
|
+
};
|
|
29
|
+
cost: number;
|
|
30
|
+
messages: {
|
|
31
|
+
user: number;
|
|
32
|
+
assistant: number;
|
|
33
|
+
total: number;
|
|
34
|
+
};
|
|
35
|
+
/** Per-advisor breakdown for every configured advisor. */
|
|
36
|
+
advisors: PerAdvisorStat[];
|
|
37
|
+
}
|
|
38
|
+
/** One advisor's status, token usage, cost, and message counts. */
|
|
39
|
+
export interface PerAdvisorStat {
|
|
40
|
+
name: string;
|
|
41
|
+
status: AdvisorRuntimeStatus;
|
|
42
|
+
model?: Model;
|
|
43
|
+
contextWindow: number;
|
|
44
|
+
contextTokens: number;
|
|
45
|
+
tokens: AdvisorStats["tokens"];
|
|
46
|
+
cost: number;
|
|
47
|
+
messages: AdvisorStats["messages"];
|
|
48
|
+
sessionId?: string;
|
|
49
|
+
}
|
|
50
|
+
/** Inputs that configure the advisor roster owned by a session. */
|
|
51
|
+
export interface SessionAdvisorsOptions {
|
|
52
|
+
enabled: boolean;
|
|
53
|
+
tools?: AgentTool[];
|
|
54
|
+
watchdogPrompt?: string;
|
|
55
|
+
sharedInstructions?: string;
|
|
56
|
+
contextPrompt?: string;
|
|
57
|
+
configs?: AdvisorConfig[];
|
|
58
|
+
streamFn?: StreamFn;
|
|
59
|
+
transformProviderContext?: (context: Context, model: Model) => Context | Promise<Context>;
|
|
60
|
+
}
|
|
61
|
+
/** Options accepted when an advisor injects a primary-session message. */
|
|
62
|
+
export interface AdvisorMessageDeliveryOptions {
|
|
63
|
+
triggerTurn?: boolean;
|
|
64
|
+
deliverAs?: "steer" | "followUp" | "nextTurn";
|
|
65
|
+
queueChipText?: string;
|
|
66
|
+
acceptTerminalEmptyStop?: boolean;
|
|
67
|
+
}
|
|
68
|
+
/** Session capabilities borrowed by the advisor controller. */
|
|
69
|
+
export interface SessionAdvisorsHost {
|
|
70
|
+
agent: Agent;
|
|
71
|
+
sessionManager: SessionManager;
|
|
72
|
+
settings: Settings;
|
|
73
|
+
modelRegistry: ModelRegistry;
|
|
74
|
+
yieldQueue: YieldQueue;
|
|
75
|
+
obfuscator: SecretObfuscator | undefined;
|
|
76
|
+
providerSessionState: Map<string, ProviderSessionState>;
|
|
77
|
+
preferWebsockets: boolean | undefined;
|
|
78
|
+
onPayload: SimpleStreamOptions["onPayload"] | undefined;
|
|
79
|
+
onResponse: SimpleStreamOptions["onResponse"] | undefined;
|
|
80
|
+
onSseEvent: SimpleStreamOptions["onSseEvent"] | undefined;
|
|
81
|
+
agentKind(): "main" | "sub";
|
|
82
|
+
isDisposed(): boolean;
|
|
83
|
+
abortInProgress(): boolean;
|
|
84
|
+
allowAgentInitiatedTurns(): boolean;
|
|
85
|
+
planModeState(): PlanModeState | undefined;
|
|
86
|
+
clientBridge(): ClientBridge | undefined;
|
|
87
|
+
emitSessionEvent(event: AgentSessionEvent): Promise<void>;
|
|
88
|
+
emitNotice(level: "info" | "warning" | "error", message: string, source?: string): void;
|
|
89
|
+
sendCustomMessage(message: CustomMessagePayload, options?: AdvisorMessageDeliveryOptions): Promise<boolean>;
|
|
90
|
+
extractQueuedAdvisorCards(): CustomMessage[];
|
|
91
|
+
dropPendingAdvisorCards(): void;
|
|
92
|
+
preserveAdvisorCard(card: CustomMessage): void;
|
|
93
|
+
hasPendingNextTurnMessages(): boolean;
|
|
94
|
+
convertToLlmForSideRequest(messages: AgentMessage[]): Message[];
|
|
95
|
+
effectiveServiceTier(model: Model): ServiceTier | undefined;
|
|
96
|
+
resolveContextPromotionTarget(currentModel: Model, contextWindow: number): Promise<Model | undefined>;
|
|
97
|
+
resolveCompactionModelCandidates(preferredModel: Model | null | undefined, availableModels: Model[]): Model[];
|
|
98
|
+
resolveRetryFallbackRole(currentSelector: string, currentModel?: Model | null): string | undefined;
|
|
99
|
+
findRetryFallbackCandidates(role: string, currentSelector: string, currentModel?: Model | null): RetryFallbackSelector[];
|
|
100
|
+
isRetryFallbackSelectorSuppressed(selector: RetryFallbackSelector): boolean;
|
|
101
|
+
noteRetryFallbackCooldown(currentSelector: string, retryAfterMs: number | undefined, errorMessage: string): void;
|
|
102
|
+
createCodexCompactionContext(options: {
|
|
103
|
+
trigger: CodexCompactionContext["trigger"];
|
|
104
|
+
reason: CodexCompactionContext["reason"];
|
|
105
|
+
phase: CodexCompactionContext["phase"];
|
|
106
|
+
}): CodexCompactionContext;
|
|
107
|
+
sessionId(): string;
|
|
108
|
+
}
|
|
109
|
+
/** Owns advisor runtimes, delivery policy, context maintenance, and status reporting. */
|
|
110
|
+
export declare class SessionAdvisors {
|
|
111
|
+
#private;
|
|
112
|
+
constructor(host: SessionAdvisorsHost, options: SessionAdvisorsOptions);
|
|
113
|
+
/** Delivers one completed primary turn to every live advisor. */
|
|
114
|
+
onPrimaryTurnEnd(messages: AgentMessage[], willContinue: boolean | undefined, signal?: AbortSignal): Promise<void>;
|
|
115
|
+
/** Rebuilds live advisors when role assignments alter their resolved runtime inputs. */
|
|
116
|
+
onModelRolesChanged(): void;
|
|
117
|
+
/** Starts configured advisor runtimes when they are eligible. */
|
|
118
|
+
buildRuntime(seedToCurrent?: boolean): boolean;
|
|
119
|
+
/** Stops every advisor runtime and starts recorder shutdown. */
|
|
120
|
+
stopRuntime(): void;
|
|
121
|
+
/** Detaches and drains recorder feeds before transcript artifacts are removed. */
|
|
122
|
+
detachAndCloseRecorders(): Promise<void>;
|
|
123
|
+
/** Re-primes advisor transcript views across a conversation boundary. */
|
|
124
|
+
resetSessionState(): void;
|
|
125
|
+
/** Re-primes advisor transcript views after an in-conversation history rewrite. */
|
|
126
|
+
resetAllRuntimes(): void;
|
|
127
|
+
/** Whether live runtimes still match the resolved advisor configuration. */
|
|
128
|
+
runtimeMatchesCurrentConfig(): boolean;
|
|
129
|
+
/** Whether concern/blocker delivery is inside the post-interrupt immunity window. */
|
|
130
|
+
isInterruptImmuneTurnActive(): boolean;
|
|
131
|
+
/** Latest aggregate recorder-close barrier. */
|
|
132
|
+
recorderClosed(): Promise<void>;
|
|
133
|
+
/** Whether a user interrupt currently suppresses advisor-driven auto-resume. */
|
|
134
|
+
get autoResumeSuppressed(): boolean;
|
|
135
|
+
set autoResumeSuppressed(value: boolean);
|
|
136
|
+
/** Tracks persistence of a visible advisor card emitted outside the primary loop. */
|
|
137
|
+
trackCardEvent(processing: Promise<void>): void;
|
|
138
|
+
/** Waits for all advisor-card persistence handlers currently in flight. */
|
|
139
|
+
waitForPendingCardEvents(): Promise<void>;
|
|
140
|
+
/**
|
|
141
|
+
* Prevent advisor notes from starting hidden primary turns while a headless
|
|
142
|
+
* caller prints and drains the final primary response.
|
|
143
|
+
*/
|
|
144
|
+
prepareForHeadlessAdvisorDrain(): void;
|
|
145
|
+
/**
|
|
146
|
+
* Wait for active advisor reviews and their emitted card events before a
|
|
147
|
+
* headless caller disposes the session. Returns `false` and logs work disposal
|
|
148
|
+
* will abandon when the shared deadline expires or an advisor fails.
|
|
149
|
+
*/
|
|
150
|
+
waitForAdvisorCatchup(timeoutMs: number): Promise<boolean>;
|
|
151
|
+
/**
|
|
152
|
+
* Enable or disable the advisor for this session. The setting is overridden for the session,
|
|
153
|
+
* and the runtime is started or stopped to match.
|
|
154
|
+
*
|
|
155
|
+
* @returns true when the advisor is actively running after the call.
|
|
156
|
+
*/
|
|
157
|
+
setAdvisorEnabled(enabled: boolean): boolean;
|
|
158
|
+
/**
|
|
159
|
+
* Toggle the advisor setting and start/stop the runtime accordingly.
|
|
160
|
+
*
|
|
161
|
+
* @returns true when the advisor is actively running after the call.
|
|
162
|
+
*/
|
|
163
|
+
toggleAdvisorEnabled(): boolean;
|
|
164
|
+
/**
|
|
165
|
+
* Replace the live advisor roster from an edited `WATCHDOG.yml` (the `/advisor
|
|
166
|
+
* configure` save path). Swaps the configs + shared baseline, then rebuilds the
|
|
167
|
+
* runtimes in place so the change applies without a restart. When the advisor is
|
|
168
|
+
* disabled the new configs are simply stored for the next enable.
|
|
169
|
+
*
|
|
170
|
+
* @returns the number of advisors active after the rebuild.
|
|
171
|
+
*/
|
|
172
|
+
applyAdvisorConfigs(advisors: AdvisorConfig[], sharedInstructions: string | undefined): number;
|
|
173
|
+
/**
|
|
174
|
+
* Whether the advisor setting is enabled for this session.
|
|
175
|
+
*/
|
|
176
|
+
isAdvisorEnabled(): boolean;
|
|
177
|
+
/**
|
|
178
|
+
* Whether a live advisor agent is attached to this session. True only when
|
|
179
|
+
* `advisor.enabled` is set AND a model resolved for the `advisor` role AND
|
|
180
|
+
* the advisor applies to this agent kind — i.e. the actual runtime exists,
|
|
181
|
+
* not merely the setting. Drives the status-line badge and `/dump advisor`.
|
|
182
|
+
*/
|
|
183
|
+
isAdvisorActive(): boolean;
|
|
184
|
+
/**
|
|
185
|
+
* The names of the tools available to advisors this session (the pool a
|
|
186
|
+
* `/advisor configure` editor lists). The advisor is a full agent, so this is the
|
|
187
|
+
* full built tool set; a tool whose optional factory returns null (e.g. lsp with
|
|
188
|
+
* no servers) is absent.
|
|
189
|
+
*/
|
|
190
|
+
getAdvisorAvailableToolNames(): string[];
|
|
191
|
+
/**
|
|
192
|
+
* The live advisor `Agent`, or `undefined` when no advisor runtime is
|
|
193
|
+
* attached. Surfaced for diagnostics (`/dump advisor` already serializes
|
|
194
|
+
* its transcript via {@link formatAdvisorHistoryAsText}) and so callers can
|
|
195
|
+
* verify the advisor inherits the session's provider-shaping options
|
|
196
|
+
* (`streamFn`, `promptCacheKey`, `providerSessionState`, ...).
|
|
197
|
+
*/
|
|
198
|
+
getAdvisorAgent(): Agent | undefined;
|
|
199
|
+
/**
|
|
200
|
+
* Lightweight advisor status for the status line: returns just the configured
|
|
201
|
+
* flag and per-advisor name/status without computing token/cost breakdowns.
|
|
202
|
+
* Avoids re-tokenizing the advisor transcript on every render frame.
|
|
203
|
+
*/
|
|
204
|
+
getAdvisorStatusOverview(): {
|
|
205
|
+
configured: boolean;
|
|
206
|
+
advisors: {
|
|
207
|
+
name: string;
|
|
208
|
+
status: AdvisorRuntimeStatus;
|
|
209
|
+
}[];
|
|
210
|
+
};
|
|
211
|
+
/**
|
|
212
|
+
* Return structured advisor stats for the status command and TUI panel.
|
|
213
|
+
*/
|
|
214
|
+
getAdvisorStats(): AdvisorStats;
|
|
215
|
+
/**
|
|
216
|
+
* Format a concise advisor status line for ACP/text output.
|
|
217
|
+
*/
|
|
218
|
+
formatAdvisorStatus(): string;
|
|
219
|
+
/**
|
|
220
|
+
* Format the advisor agent's own transcript (its system prompt, config,
|
|
221
|
+
* tools, and the markdown deltas it received plus its thinking/advise/read
|
|
222
|
+
* calls) as plain text — the advisor-side equivalent of
|
|
223
|
+
* {@link formatSessionAsText}. Returns null when no advisor is active.
|
|
224
|
+
*/
|
|
225
|
+
formatAdvisorHistoryAsText(options?: {
|
|
226
|
+
compact?: boolean;
|
|
227
|
+
}): string | null;
|
|
228
|
+
}
|
|
@@ -24,6 +24,12 @@ export interface SessionHeader {
|
|
|
24
24
|
titleSource?: SessionTitleSource;
|
|
25
25
|
timestamp: string;
|
|
26
26
|
cwd: string;
|
|
27
|
+
/**
|
|
28
|
+
* Additional workspace directories beyond `cwd` (multi-root workspace).
|
|
29
|
+
* Absolute, normalized, deduplicated. Absent on legacy single-cwd sessions.
|
|
30
|
+
* See {@link SessionWorkspace} in `./session-workspace`.
|
|
31
|
+
*/
|
|
32
|
+
additionalDirectories?: string[];
|
|
27
33
|
parentSession?: string;
|
|
28
34
|
/** Provider prompt-cache identity inherited by exact-route full forks. */
|
|
29
35
|
providerPromptCacheKey?: string;
|
|
@@ -34,6 +40,8 @@ export interface NewSessionOptions {
|
|
|
34
40
|
providerPromptCacheKey?: string;
|
|
35
41
|
/** Skip flushing the current session and delete it instead of saving. */
|
|
36
42
|
drop?: boolean;
|
|
43
|
+
/** Additional workspace directories to seed on the new session. */
|
|
44
|
+
additionalDirectories?: string[];
|
|
37
45
|
}
|
|
38
46
|
export interface SessionEntryBase {
|
|
39
47
|
type: string;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/** Handoff generation and session transition orchestration. */
|
|
2
|
+
import { type Agent, type AgentMessage, type StreamFn, type ThinkingLevel } from "@oh-my-pi/pi-agent-core";
|
|
3
|
+
import type { Message, Model, ServiceTier, SimpleStreamOptions } from "@oh-my-pi/pi-ai";
|
|
4
|
+
import type { ModelRegistry } from "../config/model-registry.js";
|
|
5
|
+
import type { Settings } from "../config/settings.js";
|
|
6
|
+
import type { ExtensionRunner } from "../extensibility/extensions/index.js";
|
|
7
|
+
import { type SecretObfuscator } from "../secrets/obfuscator.js";
|
|
8
|
+
import type { HandoffResult, SessionHandoffOptions } from "./agent-session-types.js";
|
|
9
|
+
import type { BashSessionTransition } from "./bash-runner.js";
|
|
10
|
+
import type { SessionContext } from "./session-context.js";
|
|
11
|
+
import type { SessionManager } from "./session-manager.js";
|
|
12
|
+
/** Capabilities borrowed from the owning AgentSession. */
|
|
13
|
+
export interface SessionHandoffHost {
|
|
14
|
+
agent: Agent;
|
|
15
|
+
sessionManager: SessionManager;
|
|
16
|
+
settings: Settings;
|
|
17
|
+
modelRegistry: ModelRegistry;
|
|
18
|
+
extensionRunner: ExtensionRunner | undefined;
|
|
19
|
+
sideStreamFn: StreamFn;
|
|
20
|
+
obfuscator: SecretObfuscator | undefined;
|
|
21
|
+
model(): Model | undefined;
|
|
22
|
+
thinkingLevel(): ThinkingLevel | undefined;
|
|
23
|
+
sessionId(): string;
|
|
24
|
+
sessionFile(): string | undefined;
|
|
25
|
+
baseSystemPrompt(): string[];
|
|
26
|
+
assertVibeSessionTransitionAllowed(action: string): void;
|
|
27
|
+
setSkipPostTurnMaintenance(timestamp: number | undefined): void;
|
|
28
|
+
obfuscateTextForProvider(text: string | undefined): string | undefined;
|
|
29
|
+
deobfuscateFromProvider(text: string): string;
|
|
30
|
+
convertMessagesToLlm(messages: AgentMessage[], signal?: AbortSignal): Promise<Message[]>;
|
|
31
|
+
prepareSimpleStreamOptions(options: SimpleStreamOptions, provider?: string): SimpleStreamOptions;
|
|
32
|
+
effectiveServiceTier(model: Model | undefined): ServiceTier | undefined;
|
|
33
|
+
flushPendingBash(): Promise<void>;
|
|
34
|
+
beginBashSessionTransition(): BashSessionTransition;
|
|
35
|
+
markBashSessionTransition(transition: BashSessionTransition): void;
|
|
36
|
+
finishBashSessionTransition(transition: BashSessionTransition, success: boolean): void;
|
|
37
|
+
cancelOwnAsyncJobs(): void;
|
|
38
|
+
clearCheckpointRuntimeState(): void;
|
|
39
|
+
clearSessionScopedToolState(): void;
|
|
40
|
+
clearFreshProviderSessionId(): void;
|
|
41
|
+
syncAgentSessionId(): void;
|
|
42
|
+
rekeyMemoryForCurrentSessionId(): void;
|
|
43
|
+
resetMemoryContextForNewTranscript(): Promise<void>;
|
|
44
|
+
clearPendingNextTurnMessages(): void;
|
|
45
|
+
resetTodoCycle(): void;
|
|
46
|
+
buildDisplaySessionContext(): SessionContext;
|
|
47
|
+
resetAdvisorRuntimes(): void;
|
|
48
|
+
syncTodoPhasesFromBranch(): void;
|
|
49
|
+
}
|
|
50
|
+
/** Generates handoff documents and owns the handoff session transition. */
|
|
51
|
+
export declare class SessionHandoff {
|
|
52
|
+
#private;
|
|
53
|
+
constructor(host: SessionHandoffHost);
|
|
54
|
+
/**
|
|
55
|
+
* Cancel in-progress handoff generation.
|
|
56
|
+
*/
|
|
57
|
+
abortHandoff(): void;
|
|
58
|
+
/**
|
|
59
|
+
* Check if handoff generation is in progress.
|
|
60
|
+
*/
|
|
61
|
+
get isGeneratingHandoff(): boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Generate a handoff document with a oneshot LLM call, then start a new session with it.
|
|
64
|
+
*
|
|
65
|
+
* @param customInstructions Optional focus for the handoff document
|
|
66
|
+
* @param options Handoff execution options
|
|
67
|
+
* @returns The handoff document text, or undefined if cancelled/failed
|
|
68
|
+
*/
|
|
69
|
+
handoff(customInstructions?: string, options?: SessionHandoffOptions): Promise<HandoffResult | undefined>;
|
|
70
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ToolResultMessage } from "@oh-my-pi/pi-ai";
|
|
1
|
+
import type { ImageContent, TextContent, ToolResultMessage } from "@oh-my-pi/pi-ai";
|
|
2
2
|
export interface HistoryFormatOptions {
|
|
3
3
|
/** Optional H1 prepended to the transcript. */
|
|
4
4
|
title?: string;
|
|
@@ -35,6 +35,11 @@ export interface HistoryFormatOptions {
|
|
|
35
35
|
toolResultIndex?: ReadonlyMap<string, ToolResultMessage>;
|
|
36
36
|
consumedToolCallIds?: Set<string>;
|
|
37
37
|
}
|
|
38
|
+
export declare function formatExecutionSourcePreview(source: string): string;
|
|
39
|
+
/** Pick the most informative scalar argument of a tool call. */
|
|
40
|
+
export declare function formatToolCallPrimaryArg(name: string, args: Record<string, unknown> | undefined): string;
|
|
41
|
+
export declare function formatToolCallIntentPreview(args: Record<string, unknown> | undefined): string | undefined;
|
|
42
|
+
export declare function formatToolResultErrorPreview(content: string | readonly (TextContent | ImageContent)[]): string;
|
|
38
43
|
/**
|
|
39
44
|
* Hidden custom messages that inject the primary agent's operative *constraints*
|
|
40
45
|
* — plan mode's rules and the approved plan it implements. A reviewer (the
|
|
@@ -21,9 +21,11 @@ export declare function parseSessionEntries(content: string): FileEntry[];
|
|
|
21
21
|
export declare function loadEntriesFromFile(filePath: string, storage?: SessionStorage): Promise<FileEntry[]>;
|
|
22
22
|
export declare function resolveBlobRefsInEntries(entries: FileEntry[], blobStore: BlobStore): Promise<void>;
|
|
23
23
|
/**
|
|
24
|
-
* Read-only
|
|
25
|
-
* current version, resolve blob refs, and build the
|
|
26
|
-
* persisted leaf path (last entry).
|
|
27
|
-
*
|
|
24
|
+
* Read-only transcript view of a session file: load entries, migrate to the
|
|
25
|
+
* current version, resolve blob refs, and build the display transcript along
|
|
26
|
+
* the persisted leaf path (last entry). Uses transcript mode (collapsed to the
|
|
27
|
+
* latest compaction) so failed/aborted tail turns stay visible, unlike the
|
|
28
|
+
* provider-context builder which drops them. Does NOT create a writer or take
|
|
29
|
+
* the session lock — safe to call against a file another session is writing.
|
|
28
30
|
*/
|
|
29
31
|
export declare function loadSessionMessagesReadOnly(filePath: string): Promise<AgentMessage[]>;
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
/** Context maintenance for an active coding-agent session. */
|
|
2
|
+
import { type Agent, type AgentMessage, type AgentTurnEndContext, type StreamFn, type ThinkingLevel } from "@oh-my-pi/pi-agent-core";
|
|
3
|
+
import { type CompactionPreparation, type CompactionResult, type ShakeConfig } from "@oh-my-pi/pi-agent-core/compaction";
|
|
4
|
+
import type { AssistantMessage, CodexCompactionContext, Message, Model, ProviderSessionState } from "@oh-my-pi/pi-ai";
|
|
5
|
+
import type { ModelRegistry } from "../config/model-registry.js";
|
|
6
|
+
import type { Settings } from "../config/settings.js";
|
|
7
|
+
import type { ExtensionRunner } from "../extensibility/extensions/index.js";
|
|
8
|
+
import type { CompactOptions, ContextUsage } from "../extensibility/extensions/types.js";
|
|
9
|
+
import type { GoalModeState } from "../goals/state.js";
|
|
10
|
+
import type { MemoryBackendOperationContext } from "../memory-backend/types.js";
|
|
11
|
+
import type { NonMessageTokenSource } from "../modes/utils/context-usage.js";
|
|
12
|
+
import type { ConfiguredThinkingLevel } from "../thinking.js";
|
|
13
|
+
import type { AgentSessionEvent } from "./agent-session-events.js";
|
|
14
|
+
import type { ContextUsageBreakdown, HandoffResult, SessionHandoffOptions } from "./agent-session-types.js";
|
|
15
|
+
import type { SessionContext } from "./session-context.js";
|
|
16
|
+
import type { SessionManager } from "./session-manager.js";
|
|
17
|
+
import type { ShakeMode, ShakeResult } from "./shake-types.js";
|
|
18
|
+
export type CompactionCheckResult = Readonly<{
|
|
19
|
+
deferredHandoff: boolean;
|
|
20
|
+
continuationScheduled: boolean;
|
|
21
|
+
automaticContinuationBlocked?: boolean;
|
|
22
|
+
historyRewritten?: boolean;
|
|
23
|
+
}>;
|
|
24
|
+
/** Shared no-op result for dispatcher paths that perform no maintenance. */
|
|
25
|
+
export declare const COMPACTION_CHECK_NONE: CompactionCheckResult;
|
|
26
|
+
/** Creates one provider-scoped compaction lifecycle descriptor. */
|
|
27
|
+
export declare function createCodexCompactionContext(options: {
|
|
28
|
+
trigger: CodexCompactionContext["trigger"];
|
|
29
|
+
reason: CodexCompactionContext["reason"];
|
|
30
|
+
phase: CodexCompactionContext["phase"];
|
|
31
|
+
}): CodexCompactionContext;
|
|
32
|
+
/** Capabilities borrowed from the owning AgentSession. */
|
|
33
|
+
export interface SessionMaintenanceHost {
|
|
34
|
+
agent: Agent;
|
|
35
|
+
sessionManager: SessionManager;
|
|
36
|
+
settings: Settings;
|
|
37
|
+
modelRegistry: ModelRegistry;
|
|
38
|
+
extensionRunner: ExtensionRunner | undefined;
|
|
39
|
+
sideStreamFn: StreamFn;
|
|
40
|
+
providerSessionState: Map<string, ProviderSessionState>;
|
|
41
|
+
model(): Model | undefined;
|
|
42
|
+
thinkingLevel(): ThinkingLevel | undefined;
|
|
43
|
+
isDisposed(): boolean;
|
|
44
|
+
isStreaming(): boolean;
|
|
45
|
+
isGeneratingHandoff(): boolean;
|
|
46
|
+
promptGeneration(): number;
|
|
47
|
+
sessionId(): string;
|
|
48
|
+
messages(): AgentMessage[];
|
|
49
|
+
baseSystemPrompt(): string[];
|
|
50
|
+
goalModeState(): GoalModeState | undefined;
|
|
51
|
+
planReferencePath(): string;
|
|
52
|
+
nonMessageTokenSource(): NonMessageTokenSource;
|
|
53
|
+
memoryBackendSession(): MemoryBackendOperationContext["session"];
|
|
54
|
+
emitSessionEvent(event: AgentSessionEvent): Promise<void>;
|
|
55
|
+
emitNotice(level: "info" | "warning" | "error", message: string, source?: string): void;
|
|
56
|
+
schedulePostPromptTask(task: (signal: AbortSignal) => Promise<void>, options?: {
|
|
57
|
+
delayMs?: number;
|
|
58
|
+
generation?: number;
|
|
59
|
+
onSkip?: (reason: "aborted" | "stale-generation") => void;
|
|
60
|
+
}): void;
|
|
61
|
+
scheduleAgentContinue(options?: {
|
|
62
|
+
delayMs?: number;
|
|
63
|
+
generation?: number;
|
|
64
|
+
shouldContinue?: () => boolean;
|
|
65
|
+
onSkip?: (reason: "aborted" | "stale-generation" | "session-unavailable" | "should-continue-false" | "post-restore-unavailable") => void;
|
|
66
|
+
onError?: () => void;
|
|
67
|
+
}): void;
|
|
68
|
+
scheduleCompactionContinuation(options: {
|
|
69
|
+
generation: number;
|
|
70
|
+
autoContinue: boolean;
|
|
71
|
+
terminalTextAnswer: boolean;
|
|
72
|
+
suppressContinuation: boolean;
|
|
73
|
+
}): boolean;
|
|
74
|
+
persistTurnMessagesForMidRunCompaction(context: AgentTurnEndContext | undefined): Promise<boolean>;
|
|
75
|
+
findLastAssistantMessage(): AssistantMessage | undefined;
|
|
76
|
+
disconnectFromAgent(): void;
|
|
77
|
+
reconnectToAgent(): void;
|
|
78
|
+
drainStrandedQueuedMessages(): void;
|
|
79
|
+
buildDisplaySessionContext(): SessionContext;
|
|
80
|
+
convertToLlmForSideRequest(messages: AgentMessage[]): Message[];
|
|
81
|
+
obfuscateTextForProvider(text: string | undefined): string | undefined;
|
|
82
|
+
obfuscatePreparationForProvider(preparation: CompactionPreparation): CompactionPreparation;
|
|
83
|
+
closeCodexProviderSessionsForHistoryRewrite(): void;
|
|
84
|
+
resetCodexProviderAfterCompaction(compaction: CodexCompactionContext): void;
|
|
85
|
+
resetPlanReference(): void;
|
|
86
|
+
syncTodoPhasesFromBranch(): void;
|
|
87
|
+
resetAdvisorRuntimes(): void;
|
|
88
|
+
rebaseAfterCompaction(): void;
|
|
89
|
+
getContextBreakdown(options?: {
|
|
90
|
+
contextWindow?: number;
|
|
91
|
+
pendingMessages?: AgentMessage[];
|
|
92
|
+
}): ContextUsageBreakdown | undefined;
|
|
93
|
+
getContextUsage(options?: {
|
|
94
|
+
contextWindow?: number;
|
|
95
|
+
}): ContextUsage | undefined;
|
|
96
|
+
shake(mode: ShakeMode, options?: {
|
|
97
|
+
config?: ShakeConfig;
|
|
98
|
+
signal?: AbortSignal;
|
|
99
|
+
}): Promise<ShakeResult>;
|
|
100
|
+
dropImages(): Promise<{
|
|
101
|
+
removed: number;
|
|
102
|
+
}>;
|
|
103
|
+
runHandoff(customInstructions?: string, options?: SessionHandoffOptions): Promise<HandoffResult | undefined>;
|
|
104
|
+
removeAssistantMessageFromActiveContext(message: AssistantMessage): void;
|
|
105
|
+
dropPersistedAssistantTurn(message: AssistantMessage): Promise<void>;
|
|
106
|
+
runRecoveryCompactionWithRollback(reason: "overflow" | "incomplete", message: AssistantMessage, allowDefer: boolean, options: {
|
|
107
|
+
autoContinue: boolean;
|
|
108
|
+
triggerContextTokens?: number;
|
|
109
|
+
}): Promise<CompactionCheckResult>;
|
|
110
|
+
parseRetryAfterMsFromError(errorMessage: string): number | undefined;
|
|
111
|
+
setModelTemporary(model: Model, thinkingLevel?: ConfiguredThinkingLevel, options?: {
|
|
112
|
+
ephemeral?: boolean;
|
|
113
|
+
}): Promise<void>;
|
|
114
|
+
abort(options?: {
|
|
115
|
+
goalReason?: "interrupted" | "internal";
|
|
116
|
+
reason?: string;
|
|
117
|
+
preserveCompaction?: boolean;
|
|
118
|
+
}): Promise<void>;
|
|
119
|
+
abortHandoff(): void;
|
|
120
|
+
}
|
|
121
|
+
/** Owns compaction, pruning, shake, promotion, and automatic context maintenance. */
|
|
122
|
+
export declare class SessionMaintenance {
|
|
123
|
+
#private;
|
|
124
|
+
constructor(host: SessionMaintenanceHost);
|
|
125
|
+
/** Whether manual or automatic context maintenance is active. */
|
|
126
|
+
get isCompacting(): boolean;
|
|
127
|
+
/** Assistant timestamp whose post-turn maintenance must be skipped once. */
|
|
128
|
+
get skipPostTurnMaintenanceAssistantTimestamp(): number | undefined;
|
|
129
|
+
set skipPostTurnMaintenanceAssistantTimestamp(timestamp: number | undefined);
|
|
130
|
+
/**
|
|
131
|
+
* Strip image content blocks from every message on the current branch and
|
|
132
|
+
* persist the rewrite. Walks `SessionManager.getBranch()` in place — both
|
|
133
|
+
* `SessionMessageEntry.message` and `CustomMessageEntry.content` arrays
|
|
134
|
+
* are mutated, then `rewriteEntries` durably commits the new shape. The
|
|
135
|
+
* agent's runtime view is rebuilt from the freshly-mutated entries so any
|
|
136
|
+
* provider sessions caching message identity (Codex Responses) are torn
|
|
137
|
+
* down to force a clean replay on the next turn.
|
|
138
|
+
*
|
|
139
|
+
* No-op when the branch carries no images; returns `{ removed: 0 }` and
|
|
140
|
+
* skips the disk rewrite.
|
|
141
|
+
*/
|
|
142
|
+
dropImages(): Promise<{
|
|
143
|
+
removed: number;
|
|
144
|
+
}>;
|
|
145
|
+
/**
|
|
146
|
+
* Surgically reduce context by dropping heavy content ("shake").
|
|
147
|
+
*
|
|
148
|
+
* - `images` delegates to {@link dropImages}.
|
|
149
|
+
* - `elide` replaces whole tool-call results and large fenced/XML blocks
|
|
150
|
+
* with short placeholders that embed an `artifact://` recovery link.
|
|
151
|
+
*
|
|
152
|
+
* Mutates the branch in place, persists via `rewriteEntries`, replays the
|
|
153
|
+
* rebuilt context through the agent, and tears down provider sessions that
|
|
154
|
+
* cache message identity — same rewrite contract as {@link dropImages}.
|
|
155
|
+
*
|
|
156
|
+
* No-op (zero counts) when nothing is eligible.
|
|
157
|
+
*/
|
|
158
|
+
shake(mode: ShakeMode, opts?: {
|
|
159
|
+
config?: ShakeConfig;
|
|
160
|
+
signal?: AbortSignal;
|
|
161
|
+
}): Promise<ShakeResult>;
|
|
162
|
+
/**
|
|
163
|
+
* Manually compact the session context.
|
|
164
|
+
* Aborts current agent operation first.
|
|
165
|
+
* @param customInstructions Optional instructions for the compaction summary
|
|
166
|
+
* @param options Optional callbacks for completion/error handling
|
|
167
|
+
*/
|
|
168
|
+
compact(customInstructions?: string, options?: CompactOptions): Promise<CompactionResult>;
|
|
169
|
+
/**
|
|
170
|
+
* Cancel in-progress context maintenance (manual compaction, auto-compaction, or auto-handoff).
|
|
171
|
+
*/
|
|
172
|
+
abortCompaction(): void;
|
|
173
|
+
/** Cancel only automatic maintenance while preserving a manual compaction. */
|
|
174
|
+
abortAutomaticCompaction(): void;
|
|
175
|
+
/** Trigger idle compaction through the auto-compaction flow (with UI events). */
|
|
176
|
+
runIdleCompaction(): Promise<void>;
|
|
177
|
+
runPrePromptCompactionIfNeeded(messages: AgentMessage[]): Promise<void>;
|
|
178
|
+
/**
|
|
179
|
+
* Compact continuing tool-loop runs before the next provider request.
|
|
180
|
+
*
|
|
181
|
+
* `onTurnEnd` is the safe boundary: tool results for the just-finished turn
|
|
182
|
+
* are already paired in `activeMessages`, the live array the agent loop reads
|
|
183
|
+
* before its next model call. Before compacting, the just-finished turn is
|
|
184
|
+
* synchronously persisted if async message hooks have not reached the normal
|
|
185
|
+
* append path yet. Mid-run handoff is suppressed because resetting the session
|
|
186
|
+
* while the loop owns `activeMessages` would race the next request; handoff
|
|
187
|
+
* strategy falls back to in-place context-full compaction here.
|
|
188
|
+
*/
|
|
189
|
+
maintainContextMidRun(activeMessages: AgentMessage[], signal: AbortSignal | undefined, context: AgentTurnEndContext | undefined): Promise<void>;
|
|
190
|
+
/**
|
|
191
|
+
* Check if context maintenance or promotion is needed and run it.
|
|
192
|
+
* Called after agent_end and before prompt submission.
|
|
193
|
+
*
|
|
194
|
+
* Four cases (in order):
|
|
195
|
+
* 1. Input overflow + promotion: promote to larger model, retry without maintenance.
|
|
196
|
+
* 2. Input overflow + no promotion target: run context maintenance, auto-retry on same model.
|
|
197
|
+
* 3. Output incomplete (stopReason === "length", e.g. `response.incomplete`): the
|
|
198
|
+
* model burned its output budget without producing an actionable deliverable
|
|
199
|
+
* (reasoning-only or truncated). Drop the dead turn, try promotion, otherwise
|
|
200
|
+
* run compaction/handoff and retry.
|
|
201
|
+
* 4. Threshold: context over threshold, run context maintenance (no auto-retry).
|
|
202
|
+
*
|
|
203
|
+
* @param assistantMessage The assistant message to check
|
|
204
|
+
* @param skipAbortedCheck If false, include aborted messages (for pre-prompt check). Default: true
|
|
205
|
+
* @param allowDefer If true, threshold-driven handoff strategy may schedule itself as a
|
|
206
|
+
* deferred post-prompt task instead of running inline. Callers running inside the
|
|
207
|
+
* `agent_end` handler set this to true so `session.prompt()` resolves cleanly; callers
|
|
208
|
+
* on the pre-prompt path (where the next agent turn is about to start) set it to false
|
|
209
|
+
* to avoid racing the deferred handoff against the new turn.
|
|
210
|
+
* @param autoContinue Whether maintenance may schedule the agent-authored continuation prompt.
|
|
211
|
+
* @returns whether compaction/recovery scheduled a handoff, retry, auto-continue, or
|
|
212
|
+
* queued-message drain that already owns the next turn. Callers MUST skip
|
|
213
|
+
* `session_stop` and other agent continuations when `continuationScheduled`
|
|
214
|
+
* is true.
|
|
215
|
+
*/
|
|
216
|
+
checkCompaction(assistantMessage: AssistantMessage, skipAbortedCheck?: boolean, allowDefer?: boolean, autoContinue?: boolean): Promise<CompactionCheckResult>;
|
|
217
|
+
resolveContextPromotionTarget(currentModel: Model, contextWindow: number): Promise<Model | undefined>;
|
|
218
|
+
resolveCompactionModelCandidates(preferredModel: Model | null | undefined, availableModels: Model[], filter?: (model: Model) => boolean): Model[];
|
|
219
|
+
/**
|
|
220
|
+
* Internal: Run auto-compaction with events.
|
|
221
|
+
*
|
|
222
|
+
* @param allowDefer If true (default), threshold-driven handoff strategy is allowed to
|
|
223
|
+
* schedule itself as a deferred post-prompt task and return a deferred-handoff result
|
|
224
|
+
* immediately. The caller MUST treat that as "compaction will happen async — do not
|
|
225
|
+
* also schedule `agent.continue()` for this turn", otherwise the deferred handoff
|
|
226
|
+
* races a fresh streaming turn (the symptom: "Auto-handoff" loader + assistant
|
|
227
|
+
* message still streaming). Callers on a path that is about to start a new agent
|
|
228
|
+
* turn (e.g. the pre-prompt check in `#promptWithMessage`) pass `false` to force
|
|
229
|
+
* inline execution so the handoff completes before the new turn begins.
|
|
230
|
+
* @returns whether auto-compaction scheduled a follow-up turn.
|
|
231
|
+
*/
|
|
232
|
+
runAutoCompaction(reason: "overflow" | "threshold" | "idle" | "incomplete", willRetry: boolean, deferred?: boolean, allowDefer?: boolean, options?: {
|
|
233
|
+
autoContinue?: boolean;
|
|
234
|
+
triggerContextTokens?: number;
|
|
235
|
+
suppressContinuation?: boolean;
|
|
236
|
+
suppressHandoff?: boolean;
|
|
237
|
+
phase?: CodexCompactionContext["phase"];
|
|
238
|
+
terminalTextAnswer?: boolean;
|
|
239
|
+
}): Promise<CompactionCheckResult>;
|
|
240
|
+
/**
|
|
241
|
+
* Toggle auto-compaction setting.
|
|
242
|
+
*/
|
|
243
|
+
setAutoCompactionEnabled(enabled: boolean): void;
|
|
244
|
+
/** Whether auto-compaction is enabled */
|
|
245
|
+
get autoCompactionEnabled(): boolean;
|
|
246
|
+
}
|
|
@@ -23,6 +23,15 @@ interface SessionManagerStateSnapshot {
|
|
|
23
23
|
header: SessionHeader;
|
|
24
24
|
entries: SessionEntry[];
|
|
25
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* The storage may have published a write that rejected, and an authoritative
|
|
28
|
+
* repair could not be proven durable. Callers must fail closed until recovery.
|
|
29
|
+
*/
|
|
30
|
+
export declare class SessionPersistenceIndeterminateError extends AggregateError {
|
|
31
|
+
readonly operationError: Error;
|
|
32
|
+
readonly recoveryErrors: readonly Error[];
|
|
33
|
+
constructor(operationError: Error, recoveryErrors: readonly Error[]);
|
|
34
|
+
}
|
|
26
35
|
/**
|
|
27
36
|
* Stores and navigates an append-only conversation journal.
|
|
28
37
|
*
|
|
@@ -83,6 +92,21 @@ export declare class SessionManager {
|
|
|
83
92
|
* session/new must create a discoverable file immediately).
|
|
84
93
|
*/
|
|
85
94
|
ensureOnDisk(): Promise<void>;
|
|
95
|
+
/**
|
|
96
|
+
* Stage a synchronous group of entry appends and publish the resulting full
|
|
97
|
+
* journal with one atomic replace. A failed publish removes only the staged
|
|
98
|
+
* entries, preserves/reparents entries appended concurrently, restores the
|
|
99
|
+
* prior durable file view, and clears the failed writer latch for retry.
|
|
100
|
+
*
|
|
101
|
+
* The callback MUST be synchronous.
|
|
102
|
+
*/
|
|
103
|
+
appendEntriesAtomically<T>(append: () => T): Promise<T>;
|
|
104
|
+
/**
|
|
105
|
+
* Replace an uncertain append tail with the authoritative in-memory journal.
|
|
106
|
+
* Callers must only use this for monotonic recovery where every retained
|
|
107
|
+
* entry remains intended (for example, an explicit terminal tombstone).
|
|
108
|
+
*/
|
|
109
|
+
recoverPersistenceFromCurrentState(): Promise<void>;
|
|
86
110
|
/** Flush pending writes. Call before switching sessions or on shutdown. */
|
|
87
111
|
flush(): Promise<void>;
|
|
88
112
|
/**
|
|
@@ -94,6 +118,23 @@ export declare class SessionManager {
|
|
|
94
118
|
/** Flush, then close the append writer. */
|
|
95
119
|
close(): Promise<void>;
|
|
96
120
|
getCwd(): string;
|
|
121
|
+
/** Additional workspace directories beyond cwd (multi-root), absolute and normalized. */
|
|
122
|
+
getAdditionalDirectories(): string[];
|
|
123
|
+
/**
|
|
124
|
+
* Add a workspace directory. Normalizes (relative to cwd), dedupes, rejects
|
|
125
|
+
* the cwd itself, persists to the session header, and triggers an atomic
|
|
126
|
+
* rewrite so the change survives a crash. Returns the resolved absolute
|
|
127
|
+
* path or `null` when the directory was already present (no-op).
|
|
128
|
+
*/
|
|
129
|
+
addWorkspaceDirectory(directory: string): Promise<string | null>;
|
|
130
|
+
/**
|
|
131
|
+
* Remove a workspace directory by absolute or cwd-relative path. Persists
|
|
132
|
+
* the trimmed header. Returns the resolved path that was removed, or
|
|
133
|
+
* `null` when the directory was not an additional root (no-op).
|
|
134
|
+
*/
|
|
135
|
+
removeWorkspaceDirectory(directory: string): Promise<string | null>;
|
|
136
|
+
/** Seed additional directories from settings or a passed list. Also called on resumed sessions with --add-dir; persists the updated header when the session file is already durable. No-op when the normalized list is unchanged (avoids rewriting large session files on every startup). */
|
|
137
|
+
setAdditionalDirectories(directories: string[]): Promise<void>;
|
|
97
138
|
getUsageStatistics(): UsageStatistics;
|
|
98
139
|
/**
|
|
99
140
|
* Open a new per-turn budget window: snapshot the cumulative output baseline,
|