@oyasmi/pipiclaw 0.9.3 → 0.9.4-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent/builtin-commands.d.ts +19 -0
- package/dist/agent/builtin-commands.js +80 -0
- package/dist/agent/channel-runner.d.ts +20 -208
- package/dist/agent/channel-runner.js +167 -1188
- package/dist/agent/maintenance-context.d.ts +1 -1
- package/dist/agent/maintenance-context.js +1 -1
- package/dist/agent/prompt/manifest.d.ts +6 -1
- package/dist/agent/prompt/manifest.js +45 -64
- package/dist/agent/prompt/resources.d.ts +3 -0
- package/dist/agent/prompt/resources.js +11 -2
- package/dist/agent/runner-factory.d.ts +1 -43
- package/dist/agent/{command-extension.d.ts → session/command-extension.d.ts} +4 -0
- package/dist/agent/{command-extension.js → session/command-extension.js} +48 -35
- package/dist/agent/{type-guards.d.ts → session/event-guards.d.ts} +2 -2
- package/dist/agent/{type-guards.js → session/event-guards.js} +5 -1
- package/dist/agent/session/model-selection.d.ts +47 -0
- package/dist/agent/session/model-selection.js +99 -0
- package/dist/agent/{session-adapter.d.ts → session/session-adapter.d.ts} +21 -1
- package/dist/agent/session/session-adapter.js +159 -0
- package/dist/agent/{session-events.d.ts → session/session-events.d.ts} +9 -5
- package/dist/agent/{session-events.js → session/session-events.js} +24 -13
- package/dist/agent/session/session-host.d.ts +200 -0
- package/dist/agent/session/session-host.js +621 -0
- package/dist/agent/{session-resource-gate.js → session/session-resource-gate.js} +5 -3
- package/dist/agent/status-render.d.ts +0 -1
- package/dist/agent/status-render.js +4 -16
- package/dist/agent/{context-budget.js → turn/context-budget.js} +5 -1
- package/dist/agent/{progress-formatter.d.ts → turn/progress-formatter.d.ts} +4 -1
- package/dist/agent/{run-queue.d.ts → turn/run-queue.d.ts} +1 -1
- package/dist/agent/{run-queue.js → turn/run-queue.js} +10 -5
- package/dist/{memory → agent/turn}/task-digest.js +4 -4
- package/dist/agent/turn/turn-context.d.ts +14 -0
- package/dist/agent/turn/turn-context.js +64 -0
- package/dist/agent/turn/turn-error.d.ts +31 -0
- package/dist/agent/turn/turn-error.js +68 -0
- package/dist/agent/turn/turn-finish.d.ts +50 -0
- package/dist/agent/turn/turn-finish.js +188 -0
- package/dist/agent/turn/turn-input.d.ts +43 -0
- package/dist/agent/turn/turn-input.js +79 -0
- package/dist/agent/turn/turn-pipeline.d.ts +68 -0
- package/dist/agent/turn/turn-pipeline.js +257 -0
- package/dist/agent/{turn-prompt.d.ts → turn/turn-prompt.d.ts} +2 -2
- package/dist/agent/{turn-prompt.js → turn/turn-prompt.js} +6 -2
- package/dist/agent/{turn-recovery.js → turn/turn-recovery.js} +1 -1
- package/dist/agent/{turn-state.d.ts → turn/turn-state.d.ts} +1 -1
- package/dist/agent/types.d.ts +43 -2
- package/dist/agent/types.js +1 -1
- package/dist/{models/auth-cli.d.ts → app/auth-command.d.ts} +1 -1
- package/dist/{models/auth-cli.js → app/auth-command.js} +14 -10
- package/dist/{runtime/app-home.d.ts → app/home.d.ts} +6 -2
- package/dist/{runtime/app-home.js → app/home.js} +22 -75
- package/dist/{runtime → app}/proxy.js +4 -2
- package/dist/{app-services.d.ts → app/services.d.ts} +5 -5
- package/dist/{app-services.js → app/services.js} +17 -14
- package/dist/channel/channel-context.d.ts +12 -2
- package/dist/channel/channel-context.js +29 -2
- package/dist/channel/channel-event.d.ts +10 -2
- package/dist/channel/channel-event.js +1 -1
- package/dist/channel/channel-index.js +4 -1
- package/dist/{runtime/project-commands.d.ts → channel/commands.d.ts} +1 -1
- package/dist/{runtime/project-commands.js → channel/commands.js} +17 -16
- package/dist/channel/project-scope-store.js +1 -1
- package/dist/channel/store.js +4 -0
- package/dist/commands/catalog.d.ts +24 -7
- package/dist/commands/catalog.js +91 -44
- package/dist/commands/reply-limits.d.ts +6 -0
- package/dist/commands/reply-limits.js +24 -0
- package/dist/{runtime/report-commands.d.ts → commands/router.d.ts} +10 -3
- package/dist/{runtime/report-commands.js → commands/router.js} +6 -6
- package/dist/{settings.d.ts → config/settings.d.ts} +10 -10
- package/dist/{settings.js → config/settings.js} +11 -11
- package/dist/{tools/config.d.ts → config/tools.d.ts} +1 -2
- package/dist/{tools/config.js → config/tools.js} +5 -2
- package/dist/dingtalk/access-token.d.ts +12 -0
- package/dist/dingtalk/access-token.js +51 -0
- package/dist/dingtalk/api.d.ts +19 -0
- package/dist/dingtalk/api.js +67 -0
- package/dist/dingtalk/bot.d.ts +97 -0
- package/dist/dingtalk/bot.js +389 -0
- package/dist/dingtalk/cards.d.ts +56 -0
- package/dist/dingtalk/cards.js +318 -0
- package/dist/{runtime → dingtalk}/channel-queue.js +4 -1
- package/dist/dingtalk/config.d.ts +19 -0
- package/dist/dingtalk/config.js +95 -0
- package/dist/dingtalk/connection.d.ts +57 -0
- package/dist/dingtalk/connection.js +356 -0
- package/dist/dingtalk/conversation-meta.d.ts +16 -0
- package/dist/dingtalk/conversation-meta.js +77 -0
- package/dist/{runtime → dingtalk}/delivery.d.ts +6 -2
- package/dist/{runtime → dingtalk}/delivery.js +29 -15
- package/dist/dingtalk/handler.d.ts +90 -0
- package/dist/dingtalk/handler.js +1 -0
- package/dist/dingtalk/inbound.d.ts +66 -0
- package/dist/dingtalk/inbound.js +137 -0
- package/dist/dingtalk/media.d.ts +66 -0
- package/dist/dingtalk/media.js +214 -0
- package/dist/events/{event-commands.js → commands.js} +99 -45
- package/dist/events/parse.d.ts +14 -0
- package/dist/events/parse.js +114 -0
- package/dist/events/types.d.ts +93 -0
- package/dist/events/types.js +1 -0
- package/dist/events/{event-validation.d.ts → validation.d.ts} +14 -3
- package/dist/events/{event-validation.js → validation.js} +17 -9
- package/dist/events/watcher.d.ts +67 -0
- package/dist/events/{events.js → watcher.js} +63 -121
- package/dist/executor.js +2 -2
- package/dist/index.d.ts +6 -4
- package/dist/index.js +2 -2
- package/dist/jobs/launch.d.ts +42 -0
- package/dist/jobs/launch.js +118 -0
- package/dist/{agent/job-manager.d.ts → jobs/manager.d.ts} +1 -67
- package/dist/{agent/job-manager.js → jobs/manager.js} +34 -157
- package/dist/jobs/record.d.ts +55 -0
- package/dist/jobs/record.js +36 -0
- package/dist/log.d.ts +12 -2
- package/dist/log.js +26 -34
- package/dist/main.js +3 -3
- package/dist/memory/commands.js +29 -23
- package/dist/memory/lifecycle.js +26 -5
- package/dist/memory/maintenance-gates.d.ts +2 -2
- package/dist/memory/maintenance-state.js +4 -1
- package/dist/memory/maintenance-tuning.d.ts +15 -0
- package/dist/memory/maintenance-tuning.js +3 -0
- package/dist/memory/reflect-job.d.ts +2 -2
- package/dist/memory/reflect-job.js +4 -2
- package/dist/memory/scheduler.d.ts +3 -3
- package/dist/memory/scheduler.js +5 -2
- package/dist/memory/sidecar-worker.js +1 -1
- package/dist/memory/transcript.js +1 -1
- package/dist/{agent/model-fallback.d.ts → models/fallback.d.ts} +6 -6
- package/dist/{agent/model-fallback.js → models/fallback.js} +15 -28
- package/dist/models/login-identity.d.ts +2 -0
- package/dist/models/login-identity.js +83 -0
- package/dist/models/provider-login.d.ts +3 -1
- package/dist/models/provider-login.js +8 -2
- package/dist/models/reference.d.ts +20 -0
- package/dist/models/{utils.js → reference.js} +0 -48
- package/dist/models/{utils.d.ts → runtime.d.ts} +1 -16
- package/dist/models/runtime.js +52 -0
- package/dist/paths.d.ts +2 -0
- package/dist/paths.js +9 -0
- package/dist/playbooks/agent-delegation.md +2 -2
- package/dist/playbooks/catalog.d.ts +6 -2
- package/dist/playbooks/catalog.js +9 -6
- package/dist/runtime/bootstrap.d.ts +7 -17
- package/dist/runtime/bootstrap.js +70 -659
- package/dist/runtime/durable-dispatch.d.ts +43 -4
- package/dist/runtime/durable-dispatch.js +153 -3
- package/dist/runtime/inbound-images.d.ts +18 -0
- package/dist/runtime/inbound-images.js +51 -0
- package/dist/runtime/shutdown.d.ts +39 -0
- package/dist/runtime/shutdown.js +120 -0
- package/dist/runtime/stop-watchdog.d.ts +16 -0
- package/dist/runtime/stop-watchdog.js +32 -0
- package/dist/runtime/task-driver.d.ts +6 -4
- package/dist/runtime/task-driver.js +58 -23
- package/dist/runtime/task-migration.js +25 -8
- package/dist/runtime/task-spawn.d.ts +1 -1
- package/dist/runtime/task-spawn.js +13 -6
- package/dist/runtime/turn-handler.d.ts +47 -0
- package/dist/runtime/turn-handler.js +318 -0
- package/dist/runtime/turn-run.d.ts +52 -0
- package/dist/runtime/turn-run.js +318 -0
- package/dist/runtime/wake-coalescing.d.ts +18 -0
- package/dist/runtime/wake-coalescing.js +29 -0
- package/dist/security/block-message.d.ts +22 -1
- package/dist/security/block-message.js +66 -1
- package/dist/security/command-guard.js +4 -0
- package/dist/security/network.d.ts +2 -1
- package/dist/security/network.js +7 -2
- package/dist/security/path-guard-check.js +2 -2
- package/dist/security/path-guard.js +4 -0
- package/dist/security/types.d.ts +1 -2
- package/dist/security/types.js +1 -2
- package/dist/shared/exact-keys.d.ts +1 -1
- package/dist/shared/format.d.ts +12 -0
- package/dist/shared/format.js +37 -0
- package/dist/shared/host-process.js +16 -4
- package/dist/shared/wake-claim.d.ts +1 -1
- package/dist/shared/with-timeout.d.ts +3 -2
- package/dist/shared/with-timeout.js +14 -3
- package/dist/{runtime/skill-commands.d.ts → skills/commands.d.ts} +2 -2
- package/dist/{runtime/skill-commands.js → skills/commands.js} +18 -11
- package/dist/{agent/workspace-resources.js → skills/loader.js} +1 -1
- package/dist/{tools/skill-security.js → skills/validation.js} +4 -0
- package/dist/skills/workspace.d.ts +33 -0
- package/dist/skills/workspace.js +116 -0
- package/dist/{runtime/subagent-commands.d.ts → subagents/commands.d.ts} +9 -7
- package/dist/{runtime/subagent-commands.js → subagents/commands.js} +116 -77
- package/dist/subagents/completion-wake.d.ts +17 -0
- package/dist/subagents/completion-wake.js +76 -0
- package/dist/subagents/detached-discovery.js +1 -1
- package/dist/subagents/discovery.d.ts +1 -1
- package/dist/subagents/discovery.js +2 -2
- package/dist/subagents/dispatch.d.ts +33 -0
- package/dist/subagents/dispatch.js +190 -0
- package/dist/subagents/external/claude-code.js +23 -1
- package/dist/subagents/external/dispatch.d.ts +25 -0
- package/dist/subagents/external/dispatch.js +90 -0
- package/dist/subagents/external/harness.d.ts +1 -1
- package/dist/subagents/external/progress-tail.d.ts +18 -1
- package/dist/subagents/external/progress-tail.js +64 -17
- package/dist/subagents/external/run.d.ts +5 -1
- package/dist/subagents/external/run.js +23 -9
- package/dist/subagents/external/settlement.d.ts +4 -1
- package/dist/subagents/external/settlement.js +1 -1
- package/dist/subagents/format.d.ts +1 -1
- package/dist/subagents/grace.d.ts +24 -0
- package/dist/subagents/grace.js +57 -0
- package/dist/subagents/internal/outcome.d.ts +24 -0
- package/dist/subagents/internal/outcome.js +149 -0
- package/dist/subagents/internal/provider-retry.d.ts +19 -0
- package/dist/subagents/internal/provider-retry.js +83 -0
- package/dist/subagents/internal/run.d.ts +31 -0
- package/dist/subagents/internal/run.js +240 -0
- package/dist/subagents/internal/state.d.ts +43 -0
- package/dist/subagents/internal/state.js +48 -0
- package/dist/subagents/internal/worker.d.ts +51 -0
- package/dist/subagents/internal/worker.js +167 -0
- package/dist/subagents/result.d.ts +62 -0
- package/dist/subagents/result.js +103 -0
- package/dist/subagents/run-record.d.ts +222 -0
- package/dist/subagents/run-record.js +101 -0
- package/dist/subagents/run-registry.d.ts +9 -0
- package/dist/subagents/run-registry.js +125 -0
- package/dist/subagents/runs.d.ts +16 -232
- package/dist/subagents/runs.js +132 -310
- package/dist/subagents/task-envelope.d.ts +36 -0
- package/dist/subagents/task-envelope.js +168 -0
- package/dist/subagents/types.d.ts +154 -0
- package/dist/subagents/types.js +1 -0
- package/dist/subagents/verification-outcome.d.ts +1 -1
- package/dist/subagents/workspace-summary.d.ts +16 -4
- package/dist/subagents/workspace-summary.js +74 -18
- package/dist/tasks/board.d.ts +10 -3
- package/dist/tasks/board.js +38 -3
- package/dist/tasks/{work-log.d.ts → bound-work.d.ts} +1 -1
- package/dist/tasks/{work-log.js → bound-work.js} +1 -1
- package/dist/tasks/brief.js +1 -1
- package/dist/{runtime/task-commands.d.ts → tasks/commands.d.ts} +1 -1
- package/dist/{runtime/task-commands.js → tasks/commands.js} +117 -67
- package/dist/tasks/contract-input.d.ts +1 -1
- package/dist/tasks/contract-input.js +1 -1
- package/dist/tasks/create.js +1 -1
- package/dist/tasks/frontmatter.d.ts +5 -0
- package/dist/tasks/frontmatter.js +8 -0
- package/dist/tasks/{log.d.ts → loop-log.d.ts} +11 -1
- package/dist/tasks/{log.js → loop-log.js} +59 -3
- package/dist/tasks/mutation-lock.js +1 -1
- package/dist/tasks/session-path.js +1 -1
- package/dist/tasks/steer.js +1 -1
- package/dist/tasks/store.js +6 -4
- package/dist/tasks/ticket.d.ts +3 -1
- package/dist/tasks/ticket.js +19 -1
- package/dist/tools/bash.d.ts +1 -1
- package/dist/tools/bash.js +2 -2
- package/dist/tools/{tool-details.d.ts → contract/details.d.ts} +11 -3
- package/dist/tools/{tool-details.js → contract/details.js} +42 -5
- package/dist/tools/{presentation.js → contract/presentation.js} +3 -3
- package/dist/tools/event-manage.d.ts +1 -1
- package/dist/tools/event-manage.js +4 -4
- package/dist/tools/index.d.ts +5 -3
- package/dist/tools/index.js +8 -6
- package/dist/tools/job.d.ts +1 -1
- package/dist/tools/memory-manage.js +4 -1
- package/dist/tools/registry.d.ts +7 -7
- package/dist/tools/registry.js +6 -6
- package/dist/tools/session-search.d.ts +1 -1
- package/dist/tools/skill.d.ts +2 -34
- package/dist/tools/skill.js +8 -116
- package/dist/tools/subagent-manage.d.ts +1 -1
- package/dist/tools/subagent-manage.js +19 -13
- package/dist/tools/subagent.d.ts +46 -0
- package/dist/tools/subagent.js +127 -0
- package/dist/tools/{task-manage.d.ts → task-manage/factory.d.ts} +7 -3
- package/dist/tools/{task-manage.js → task-manage/factory.js} +7 -7
- package/dist/tools/task-manage/lifecycle.js +2 -2
- package/dist/tools/task-manage/log-view.js +2 -2
- package/dist/tools/task-manage/shared.js +3 -3
- package/dist/tools/task-manage/step-end.js +7 -4
- package/dist/tools/task-manage/types.d.ts +1 -1
- package/dist/tools/web-fetch.d.ts +1 -1
- package/dist/tools/web-search.d.ts +1 -1
- package/dist/tui/app.d.ts +1 -1
- package/dist/tui/app.js +6 -6
- package/dist/tui/cli.d.ts +1 -1
- package/dist/tui/cli.js +3 -3
- package/dist/tui/commands.js +4 -4
- package/dist/tui/frontend.d.ts +44 -0
- package/dist/tui/frontend.js +13 -0
- package/dist/tui/pitui-frontend.d.ts +1 -1
- package/dist/tui/pitui-frontend.js +1 -1
- package/dist/tui/plain-frontend.d.ts +1 -1
- package/dist/tui/renderer.d.ts +3 -42
- package/dist/tui/renderer.js +3 -2
- package/dist/tui/terminal-context.d.ts +2 -2
- package/dist/tui/terminal-media-sender.d.ts +1 -1
- package/dist/tui/turn-controller.d.ts +3 -1
- package/dist/tui/turn-controller.js +36 -21
- package/dist/usage/ledger.js +7 -1
- package/dist/usage/render.js +3 -1
- package/dist/{shared/types.d.ts → usage/totals.d.ts} +3 -0
- package/dist/web/client.d.ts +5 -1
- package/dist/web/client.js +4 -0
- package/dist/web/config.d.ts +1 -1
- package/dist/web/fetch.d.ts +1 -1
- package/dist/web/search-providers.d.ts +1 -1
- package/dist/web/search.d.ts +1 -1
- package/package.json +9 -7
- package/dist/agent/session-adapter.js +0 -77
- package/dist/events/events.d.ts +0 -159
- package/dist/runtime/dingtalk.d.ts +0 -272
- package/dist/runtime/dingtalk.js +0 -1416
- package/dist/subagents/tool.d.ts +0 -206
- package/dist/subagents/tool.js +0 -1088
- /package/dist/{runtime → agent/prompt}/workspace-templates.d.ts +0 -0
- /package/dist/{runtime → agent/prompt}/workspace-templates.js +0 -0
- /package/dist/agent/{session-resource-gate.d.ts → session/session-resource-gate.d.ts} +0 -0
- /package/dist/agent/{context-budget.d.ts → turn/context-budget.d.ts} +0 -0
- /package/dist/agent/{progress-formatter.js → turn/progress-formatter.js} +0 -0
- /package/dist/{memory → agent/turn}/task-digest.d.ts +0 -0
- /package/dist/agent/{turn-recovery.d.ts → turn/turn-recovery.d.ts} +0 -0
- /package/dist/agent/{turn-state.js → turn/turn-state.js} +0 -0
- /package/dist/{runtime → app}/proxy.d.ts +0 -0
- /package/dist/{runtime → dingtalk}/channel-queue.d.ts +0 -0
- /package/dist/{runtime → dingtalk}/inbound-media.d.ts +0 -0
- /package/dist/{runtime → dingtalk}/inbound-media.js +0 -0
- /package/dist/events/{event-commands.d.ts → commands.d.ts} +0 -0
- /package/dist/{agent/workspace-resources.d.ts → skills/loader.d.ts} +0 -0
- /package/dist/{tools/skill-security.d.ts → skills/validation.d.ts} +0 -0
- /package/dist/tasks/{ledger.d.ts → contract.d.ts} +0 -0
- /package/dist/tasks/{ledger.js → contract.js} +0 -0
- /package/dist/tools/{subagent-tool-names.d.ts → contract/names.d.ts} +0 -0
- /package/dist/tools/{subagent-tool-names.js → contract/names.js} +0 -0
- /package/dist/tools/{presentation.d.ts → contract/presentation.d.ts} +0 -0
- /package/dist/{shared/types.js → usage/totals.js} +0 -0
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adapters over the SDK session where Pipiclaw needs compatibility behaviour: the settings-manager
|
|
3
|
+
* shim and thinking-level preservation when a model changes.
|
|
4
|
+
*/
|
|
1
5
|
import type { Agent, AgentTool, ThinkingLevel } from "@earendil-works/pi-agent-core";
|
|
2
6
|
import type { Api, Model } from "@earendil-works/pi-ai";
|
|
3
7
|
import { type AgentSession, SettingsManager as SDKSettingsManager, type SessionManager } from "@earendil-works/pi-coding-agent";
|
|
4
|
-
import type { PipiclawSettingsManager } from "
|
|
8
|
+
import type { PipiclawSettingsManager } from "../../config/settings.js";
|
|
5
9
|
export declare function asSdkSettingsManager(manager: PipiclawSettingsManager): SDKSettingsManager;
|
|
6
10
|
export declare const DEFAULT_MAIN_THINKING_LEVEL: ThinkingLevel;
|
|
7
11
|
/** Apply the pi 0.83 source-model thinking compatibility branch to one real AgentSession. */
|
|
@@ -17,3 +21,19 @@ export declare function initializeThinkingLevelCompat(agent: Agent, model: Model
|
|
|
17
21
|
* silently leaving stale tools in place. Replace with a public setter once upstream adds one.
|
|
18
22
|
*/
|
|
19
23
|
export declare function setSessionBaseToolsOverride(session: AgentSession, tools: AgentTool<any>[], channelId: string): void;
|
|
24
|
+
/** One prompt's origin. Raw entries establish safety; projection only decides what still needs omission. */
|
|
25
|
+
export declare class SessionRetryAttempt<T extends Pick<AgentSession, "sessionManager" | "refreshContext"> = AgentSession> {
|
|
26
|
+
readonly session: T;
|
|
27
|
+
private readonly manager;
|
|
28
|
+
private readonly sessionId;
|
|
29
|
+
private readonly prefix;
|
|
30
|
+
private retryBranch;
|
|
31
|
+
constructor(session: T);
|
|
32
|
+
classify(): {
|
|
33
|
+
kind: "unsubmitted" | "failed-turn";
|
|
34
|
+
targets: string[];
|
|
35
|
+
} | null;
|
|
36
|
+
prepare(): ReturnType<SessionRetryAttempt<T>["classify"]>;
|
|
37
|
+
/** Caller holds the host resource window and must quarantine this session on any exception. */
|
|
38
|
+
omitFailedContext(): boolean;
|
|
39
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { clampThinkingLevel } from "@earendil-works/pi-ai/compat";
|
|
2
|
+
import { SettingsManager as SDKSettingsManager, } from "@earendil-works/pi-coding-agent";
|
|
3
|
+
import * as log from "../../log.js";
|
|
4
|
+
export function asSdkSettingsManager(manager) {
|
|
5
|
+
// The upstream session needs its broad interactive SettingsManager surface, while
|
|
6
|
+
// Pipiclaw deliberately owns a small runtime-specific settings contract. Build a
|
|
7
|
+
// real upstream manager from that contract instead of making PipiclawSettingsManager
|
|
8
|
+
// pretend to implement dozens of unrelated no-op UI preferences.
|
|
9
|
+
return SDKSettingsManager.inMemory({
|
|
10
|
+
defaultProvider: manager.getDefaultProvider(),
|
|
11
|
+
defaultModel: manager.getDefaultModel(),
|
|
12
|
+
defaultThinkingLevel: manager.getDefaultThinkingLevel() ?? DEFAULT_MAIN_THINKING_LEVEL,
|
|
13
|
+
compaction: manager.getCompactionSettings(),
|
|
14
|
+
retry: manager.getRetrySettings(),
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
export const DEFAULT_MAIN_THINKING_LEVEL = "medium";
|
|
18
|
+
/** Apply the pi 0.83 source-model thinking compatibility branch to one real AgentSession. */
|
|
19
|
+
export async function setModelWithThinkingPreservation(session, manager, model) {
|
|
20
|
+
const source = session.model;
|
|
21
|
+
if (!source?.reasoning) {
|
|
22
|
+
await session.setModel(model);
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const previousDefault = manager.getDefaultThinkingLevel();
|
|
26
|
+
manager.setDefaultThinkingLevel(session.thinkingLevel);
|
|
27
|
+
try {
|
|
28
|
+
await session.setModel(model);
|
|
29
|
+
}
|
|
30
|
+
finally {
|
|
31
|
+
manager.setDefaultThinkingLevel(previousDefault ?? DEFAULT_MAIN_THINKING_LEVEL);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export function setThinkingLevelWithConditionalPersist(session, level) {
|
|
35
|
+
const before = session.thinkingLevel;
|
|
36
|
+
session.setThinkingLevel(level);
|
|
37
|
+
const effective = session.thinkingLevel;
|
|
38
|
+
if (effective === before)
|
|
39
|
+
return;
|
|
40
|
+
if (!session.model?.reasoning && effective === "off")
|
|
41
|
+
return;
|
|
42
|
+
session.setThinkingLevel(effective, { persist: true });
|
|
43
|
+
}
|
|
44
|
+
export function cycleThinkingLevelWithConditionalPersist(session) {
|
|
45
|
+
const before = session.thinkingLevel;
|
|
46
|
+
const next = session.cycleThinkingLevel();
|
|
47
|
+
const effective = session.thinkingLevel;
|
|
48
|
+
if (next && effective !== before && (session.model?.reasoning || effective !== "off")) {
|
|
49
|
+
session.setThinkingLevel(effective, { persist: true });
|
|
50
|
+
}
|
|
51
|
+
return next;
|
|
52
|
+
}
|
|
53
|
+
export function initializeThinkingLevelCompat(agent, model, sessionManager, configuredDefault) {
|
|
54
|
+
const branch = sessionManager.getBranch();
|
|
55
|
+
const hasThinkingEntry = branch.some((entry) => entry.type === "thinking_level_change");
|
|
56
|
+
const historical = sessionManager.buildSessionContext().thinkingLevel;
|
|
57
|
+
const requested = hasThinkingEntry ? historical : (configuredDefault ?? DEFAULT_MAIN_THINKING_LEVEL);
|
|
58
|
+
const effective = clampThinkingLevel(model, requested);
|
|
59
|
+
agent.state.thinkingLevel = effective;
|
|
60
|
+
if (!hasThinkingEntry)
|
|
61
|
+
sessionManager.appendThinkingLevelChange(effective);
|
|
62
|
+
return effective;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Overwrite the SDK session's `baseToolsOverride` map so a resource reload swaps in
|
|
66
|
+
* freshly-built tools. The SDK exposes no public setter for this, so we reach into the
|
|
67
|
+
* private `_baseToolsOverride` field. This is the single, isolated point of that coupling:
|
|
68
|
+
* if a future SDK renames or removes the field, the guard below warns loudly instead of
|
|
69
|
+
* silently leaving stale tools in place. Replace with a public setter once upstream adds one.
|
|
70
|
+
*/
|
|
71
|
+
export function setSessionBaseToolsOverride(session, tools, channelId) {
|
|
72
|
+
const target = session;
|
|
73
|
+
if (!("_baseToolsOverride" in target)) {
|
|
74
|
+
log.logWarn("agent.session.sdk_drift", "AgentSession no longer exposes _baseToolsOverride; tool reloads may use stale tools", { channelId: channelId });
|
|
75
|
+
}
|
|
76
|
+
target._baseToolsOverride = Object.fromEntries(tools.map((tool) => [tool.name, tool]));
|
|
77
|
+
}
|
|
78
|
+
/** One prompt's origin. Raw entries establish safety; projection only decides what still needs omission. */
|
|
79
|
+
export class SessionRetryAttempt {
|
|
80
|
+
constructor(session) {
|
|
81
|
+
this.session = session;
|
|
82
|
+
this.manager = session.sessionManager;
|
|
83
|
+
this.sessionId = session.sessionManager.getSessionId();
|
|
84
|
+
this.prefix = session.sessionManager.getBranch().map((entry) => entry.id);
|
|
85
|
+
}
|
|
86
|
+
classify() {
|
|
87
|
+
const manager = this.session.sessionManager;
|
|
88
|
+
if (manager !== this.manager || manager.getSessionId() !== this.sessionId)
|
|
89
|
+
return null;
|
|
90
|
+
const branch = manager.getBranch();
|
|
91
|
+
if (this.prefix.some((id, index) => branch[index]?.id !== id))
|
|
92
|
+
return null;
|
|
93
|
+
if (this.retryBranch) {
|
|
94
|
+
if (this.retryBranch.some((id, index) => branch[index]?.id !== id))
|
|
95
|
+
return null;
|
|
96
|
+
// Once prepared, a new interaction or rewinding the failed branch invalidates the plan.
|
|
97
|
+
if (branch
|
|
98
|
+
.slice(this.retryBranch.length)
|
|
99
|
+
.some((entry) => entry.type === "message" && entry.message.role !== "system"))
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
const delta = branch.slice(this.prefix.length);
|
|
103
|
+
const users = [];
|
|
104
|
+
const errors = [];
|
|
105
|
+
for (const entry of delta) {
|
|
106
|
+
if (entry.type === "message") {
|
|
107
|
+
const message = entry.message;
|
|
108
|
+
if (message.role === "system")
|
|
109
|
+
continue;
|
|
110
|
+
if (message.role === "user" && errors.length === 0)
|
|
111
|
+
users.push(entry.id);
|
|
112
|
+
else if (message.role === "assistant" && users.length === 1 && message.stopReason === "error") {
|
|
113
|
+
if (message.content.some((part) => part.type === "toolCall" || (part.type === "text" && part.text.trim()))) {
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
errors.push(entry.id);
|
|
117
|
+
}
|
|
118
|
+
else
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
else if (entry.type === "context_edit") {
|
|
122
|
+
// Only omissions of this attempt's failed messages are understood (including SDK retries).
|
|
123
|
+
if (entry.replacement !== null || ![...users, ...errors].includes(entry.targetId))
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
else if (!["model_change", "thinking_level_change", "usage"].includes(entry.type))
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
if (users.length === 0 && errors.length === 0)
|
|
130
|
+
return { kind: "unsubmitted", targets: [] };
|
|
131
|
+
if (users.length !== 1 || errors.length === 0)
|
|
132
|
+
return null;
|
|
133
|
+
const targets = [...users, ...errors];
|
|
134
|
+
const projection = manager.buildSessionProjection();
|
|
135
|
+
// Even an already omitted entry must have identifiable provenance.
|
|
136
|
+
if (targets.some((id) => !projection.entries.some((entry) => entry.sourceEntry.id === id)))
|
|
137
|
+
return null;
|
|
138
|
+
return {
|
|
139
|
+
kind: "failed-turn",
|
|
140
|
+
targets: targets.filter((id) => projection.entries.some((entry) => entry.sourceEntry.id === id && entry.messages.length)),
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
prepare() {
|
|
144
|
+
const plan = this.classify();
|
|
145
|
+
if (plan)
|
|
146
|
+
this.retryBranch ??= this.manager.getBranch().map((entry) => entry.id);
|
|
147
|
+
return plan;
|
|
148
|
+
}
|
|
149
|
+
/** Caller holds the host resource window and must quarantine this session on any exception. */
|
|
150
|
+
omitFailedContext() {
|
|
151
|
+
const plan = this.prepare();
|
|
152
|
+
if (!plan)
|
|
153
|
+
return false;
|
|
154
|
+
for (const id of plan.targets)
|
|
155
|
+
this.session.sessionManager.appendContextEdit(id, null);
|
|
156
|
+
this.session.refreshContext();
|
|
157
|
+
return true;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import type {
|
|
1
|
+
/**
|
|
2
|
+
* Translates SDK session events into progress and AI-Card updates, usage accounting and memory
|
|
3
|
+
* activity for the current turn.
|
|
4
|
+
*/
|
|
5
|
+
import type { ChannelContext } from "../../channel/channel-context.js";
|
|
6
|
+
import type { ChannelStore } from "../../channel/store.js";
|
|
7
|
+
import type { MemoryLifecycle } from "../../memory/lifecycle.js";
|
|
8
|
+
import type { UsageLedger } from "../../usage/ledger.js";
|
|
9
|
+
import type { PendingTool, RunLogContext, RunQueue, RunState } from "../types.js";
|
|
6
10
|
export interface SessionEventHandlerContext {
|
|
7
11
|
ctx: ChannelContext;
|
|
8
12
|
logCtx: RunLogContext;
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import * as log from "
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
1
|
+
import * as log from "../../log.js";
|
|
2
|
+
import { renderGuardBlockForUser } from "../../security/block-message.js";
|
|
3
|
+
import { truncate } from "../../shared/text-utils.js";
|
|
4
|
+
import { isRecord } from "../../shared/type-guards.js";
|
|
5
|
+
import { isArgumentValidationFailure, isRecoverableRejection, takeGuardBlock, toolResultDetails, } from "../../tools/contract/details.js";
|
|
6
|
+
import { describeToolCall } from "../../tools/contract/presentation.js";
|
|
7
|
+
import { addUsage } from "../../usage/totals.js";
|
|
8
|
+
import { extractToolResultText, formatProgressEntry } from "../turn/progress-formatter.js";
|
|
9
|
+
import { renderCompactionFailure } from "../turn/turn-error.js";
|
|
10
|
+
import { extractCustomCommandResultText, isAssistantEventMessage, isAutoCompactionEndEvent, isAutoCompactionStartEvent, isAutoRetryStartEvent, isMessageEndEvent, isMessageStartEvent, isSubAgentToolDetails, isTextPart, isThinkingPart, isToolExecutionEndEvent, isToolExecutionStartEvent, isToolExecutionUpdateEvent, isTurnEndEvent, } from "./event-guards.js";
|
|
9
11
|
/**
|
|
10
12
|
* A `write`/`edit` result whose resolved target landed inside the workspace `skills/` tree. The
|
|
11
13
|
* `skill` tool is read-only (spec 045); authoring a workspace skill goes through the generic file
|
|
@@ -21,6 +23,9 @@ function isWorkspaceSkillWrite(toolName, details, skillsDir) {
|
|
|
21
23
|
}
|
|
22
24
|
return details.path === skillsDir || details.path.startsWith(`${skillsDir}/`);
|
|
23
25
|
}
|
|
26
|
+
function firstLine(text) {
|
|
27
|
+
return text.trim().split("\n", 1)[0] ?? "";
|
|
28
|
+
}
|
|
24
29
|
function mergeSubAgentUsage(totalUsage, details) {
|
|
25
30
|
addUsage(totalUsage, details.usage);
|
|
26
31
|
}
|
|
@@ -89,7 +94,7 @@ export async function handleSessionEvent(event, context) {
|
|
|
89
94
|
context.refreshSessionResources &&
|
|
90
95
|
isWorkspaceSkillWrite(event.toolName, details, context.skillsDir)) {
|
|
91
96
|
queue.enqueue(() => context.refreshSessionResources?.() ?? Promise.resolve(), "refresh skills");
|
|
92
|
-
queue.enqueue(() => ctx.respondInThread("
|
|
97
|
+
queue.enqueue(() => ctx.respondInThread("已更新 workspace skill,下一条消息起生效。"), "skill notice");
|
|
93
98
|
}
|
|
94
99
|
// A recoverable rejection (bad arguments, unmet precondition the model can fix) is not a
|
|
95
100
|
// fault: the model normally corrects it on the next call. It is logged so the retry is
|
|
@@ -116,8 +121,14 @@ export async function handleSessionEvent(event, context) {
|
|
|
116
121
|
if (!treatAsError && !rejected && event.toolName !== "task_step_end") {
|
|
117
122
|
runState.toolsUsed.push(event.toolName);
|
|
118
123
|
}
|
|
124
|
+
// Claimed on every error, shown or not, so the parked refusal never outlives its call.
|
|
125
|
+
const blocked = event.isError ? takeGuardBlock(event.toolCallId, resultStr) : undefined;
|
|
119
126
|
if (treatAsError && showProgress) {
|
|
120
|
-
|
|
127
|
+
// The tool's error text is written for the model (spec 053, D2): a guard refusal is shown
|
|
128
|
+
// from its structured form; anything else as its first line only — the full text is in
|
|
129
|
+
// the log (`agent.tool.failed`).
|
|
130
|
+
const line = blocked ? renderGuardBlockForUser(blocked) : truncate(firstLine(resultStr), 120);
|
|
131
|
+
queue.enqueue(() => ctx.respond(formatProgressEntry("error", line), false), "tool error");
|
|
121
132
|
}
|
|
122
133
|
return;
|
|
123
134
|
}
|
|
@@ -236,7 +247,7 @@ export async function handleSessionEvent(event, context) {
|
|
|
236
247
|
return;
|
|
237
248
|
}
|
|
238
249
|
if (isAutoCompactionStartEvent(event)) {
|
|
239
|
-
const label = "
|
|
250
|
+
const label = "正在压缩上下文…";
|
|
240
251
|
log.logEvent("info", "agent.compaction.started", "Compaction started", {
|
|
241
252
|
ctx: logCtx,
|
|
242
253
|
fields: { reason: event.reason },
|
|
@@ -264,7 +275,7 @@ export async function handleSessionEvent(event, context) {
|
|
|
264
275
|
fields: { error: event.errorMessage },
|
|
265
276
|
});
|
|
266
277
|
if (showProgress) {
|
|
267
|
-
queue.enqueue(() => ctx.respond(formatProgressEntry("error",
|
|
278
|
+
queue.enqueue(() => ctx.respond(formatProgressEntry("error", renderCompactionFailure(event.errorMessage ?? "")), false), "compaction error");
|
|
268
279
|
}
|
|
269
280
|
}
|
|
270
281
|
return;
|
|
@@ -275,7 +286,7 @@ export async function handleSessionEvent(event, context) {
|
|
|
275
286
|
fields: { attempt: event.attempt, maxAttempts: event.maxAttempts, error: event.errorMessage },
|
|
276
287
|
});
|
|
277
288
|
if (showProgress) {
|
|
278
|
-
queue.enqueue(() => ctx.respond(formatProgressEntry("assistant",
|
|
289
|
+
queue.enqueue(() => ctx.respond(formatProgressEntry("assistant", `模型请求失败,正在重试(${event.attempt}/${event.maxAttempts})…`), false), "retry");
|
|
279
290
|
}
|
|
280
291
|
}
|
|
281
292
|
}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The SDK session of one channel: building and rebuilding it (resource loader, tools, system prompt,
|
|
3
|
+
* extensions), subscribing to its events, binding it to a task's own session or back to the chat
|
|
4
|
+
* session, and tearing it down. Owns the session-side state — the session itself, the model
|
|
5
|
+
* runtime and registry, the current tools and skills, the last prompt build — and nothing about
|
|
6
|
+
* turns; `ChannelRunner` drives turns through it.
|
|
7
|
+
*/
|
|
8
|
+
import { Agent, type AgentTool } from "@earendil-works/pi-agent-core";
|
|
9
|
+
import { AgentSession, type ModelRegistry, type SettingsManager as SDKSettingsManager, type SessionManager } from "@earendil-works/pi-coding-agent";
|
|
10
|
+
import type { MediaSender } from "../../channel/channel-context.js";
|
|
11
|
+
import type { PipiclawSettingsManager } from "../../config/settings.js";
|
|
12
|
+
import type { Executor } from "../../executor.js";
|
|
13
|
+
import type { FileStore } from "../../file-store.js";
|
|
14
|
+
import type { ChannelJobManager } from "../../jobs/manager.js";
|
|
15
|
+
import type { MemoryLifecycle } from "../../memory/lifecycle.js";
|
|
16
|
+
import type { LoadedSecurityConfig } from "../../security/config.js";
|
|
17
|
+
import type { ProjectScope } from "../../security/project-scope.js";
|
|
18
|
+
import { type PipiclawSkillsResult } from "../../skills/loader.js";
|
|
19
|
+
import { type SubAgentDiscoveryResult } from "../../subagents/discovery.js";
|
|
20
|
+
import type { SubAgentRunManager } from "../../subagents/runs.js";
|
|
21
|
+
import type { UsageLedger } from "../../usage/ledger.js";
|
|
22
|
+
import { type WorkspacePromptResources } from "../prompt/resources.js";
|
|
23
|
+
import type { PromptBuildResult } from "../prompt/types.js";
|
|
24
|
+
import type { RunState } from "../types.js";
|
|
25
|
+
import type { ModelSelection } from "./model-selection.js";
|
|
26
|
+
/** Surface settings.json load errors (once drained) as warnings; shared by construction and reload. */
|
|
27
|
+
export declare function reportSettingsDiagnostics(settingsManager: PipiclawSettingsManager, channelId: string, appHomeDir: string): void;
|
|
28
|
+
export interface SessionHostDeps {
|
|
29
|
+
channelId: string;
|
|
30
|
+
channelDir: string;
|
|
31
|
+
workspaceDir: string;
|
|
32
|
+
appHomeDir: string;
|
|
33
|
+
authConfigPath: string;
|
|
34
|
+
modelsConfigPath: string;
|
|
35
|
+
onSessionEvent?: (event: unknown, channelId: string) => void;
|
|
36
|
+
mediaSender?: MediaSender;
|
|
37
|
+
/**
|
|
38
|
+
* Frozen for the lifetime of this runner generation (spec 043, D4.2): AgentSession, the
|
|
39
|
+
* ResourceLoader, and every tool closure built here (session-topology rebuilds only rebind the
|
|
40
|
+
* session, never the scope) all read this same value.
|
|
41
|
+
*/
|
|
42
|
+
projectScope: ProjectScope;
|
|
43
|
+
settingsManager: PipiclawSettingsManager;
|
|
44
|
+
/** Re-read per use, not captured once: an edited security.json takes effect without a restart. */
|
|
45
|
+
loadSecurityConfig: () => LoadedSecurityConfig;
|
|
46
|
+
executor: Executor;
|
|
47
|
+
fileStore: FileStore;
|
|
48
|
+
jobManager: ChannelJobManager;
|
|
49
|
+
runManager: SubAgentRunManager;
|
|
50
|
+
memoryLifecycle: MemoryLifecycle;
|
|
51
|
+
models: ModelSelection;
|
|
52
|
+
ledger: UsageLedger;
|
|
53
|
+
/** Skill summaries loaded at construction, before the session exists. */
|
|
54
|
+
initialSkills: PipiclawSkillsResult;
|
|
55
|
+
/** The current run's state (replaced by the runner at the start of every run). */
|
|
56
|
+
getRunState: () => RunState;
|
|
57
|
+
/** The agent loop started streaming: steer is now accepted into the session. */
|
|
58
|
+
markStreaming: () => void;
|
|
59
|
+
}
|
|
60
|
+
export declare class SessionHost {
|
|
61
|
+
private readonly deps;
|
|
62
|
+
private readonly channelId;
|
|
63
|
+
private readonly channelDir;
|
|
64
|
+
private readonly workspaceDir;
|
|
65
|
+
private readonly appHomeDir;
|
|
66
|
+
private readonly authConfigPath;
|
|
67
|
+
private readonly modelsConfigPath;
|
|
68
|
+
private readonly onSessionEvent?;
|
|
69
|
+
private readonly mediaSender?;
|
|
70
|
+
private readonly projectScope;
|
|
71
|
+
private readonly settingsManager;
|
|
72
|
+
private readonly loadSecurityConfig;
|
|
73
|
+
private readonly executor;
|
|
74
|
+
private readonly fileStore;
|
|
75
|
+
private readonly jobManager;
|
|
76
|
+
private readonly runManager;
|
|
77
|
+
private readonly memoryLifecycle;
|
|
78
|
+
private readonly models;
|
|
79
|
+
private readonly ledger;
|
|
80
|
+
session: AgentSession;
|
|
81
|
+
/** Settings manager owned by the currently bound AgentSession. */
|
|
82
|
+
sessionSettingsManager: SDKSettingsManager;
|
|
83
|
+
private modelRuntime;
|
|
84
|
+
modelRegistry: ModelRegistry;
|
|
85
|
+
/** Mutual exclusion between prompt submission and session-resource reloads. */
|
|
86
|
+
private readonly sessionResourceGate;
|
|
87
|
+
sessionReady: Promise<void>;
|
|
88
|
+
/**
|
|
89
|
+
* Flips true only once `initializeSession` has fully assigned `this.session`
|
|
90
|
+
* and loaded its resources. Synchronous dispatch-path callers (`isKnownSlashCommand`)
|
|
91
|
+
* must not touch `this.session` before this — the model runtime takes hundreds
|
|
92
|
+
* of ms to build and the first message can arrive first (spec 048 F2).
|
|
93
|
+
*/
|
|
94
|
+
sessionInitialized: boolean;
|
|
95
|
+
private sessionRuntime;
|
|
96
|
+
sessionUnsubscribe?: () => void;
|
|
97
|
+
subAgentDiscovery: SubAgentDiscoveryResult;
|
|
98
|
+
currentSkills: PipiclawSkillsResult;
|
|
99
|
+
/** Last built system prompt (spec 025): feeds the boundary footer, /context and the debug manifest. */
|
|
100
|
+
lastPromptBuild?: PromptBuildResult;
|
|
101
|
+
/** SOUL/AGENTS as resolved for the last build, for the `/context` independent-budget lines. */
|
|
102
|
+
lastWorkspaceResources?: WorkspacePromptResources;
|
|
103
|
+
/** The exact system prompt the provider last received (our prompt + pi's tail + footer). */
|
|
104
|
+
lastFinalPrompt?: string;
|
|
105
|
+
currentTools: AgentTool<any>[];
|
|
106
|
+
firstTurnMemoryBootstrapPending: boolean;
|
|
107
|
+
/** Mirror of `tools.tasks.enabled` from the last tools-config load (see buildRuntimeTools). */
|
|
108
|
+
tasksEnabled: boolean;
|
|
109
|
+
/**
|
|
110
|
+
* Set while this runner is bound to a task's own session (spec 051, D3). Turns are serialized
|
|
111
|
+
* per channel, so one runner can carry both surfaces by swapping which session file it is
|
|
112
|
+
* bound to between turns — which keeps busy state, `/stop`, steering and turn recovery with
|
|
113
|
+
* their existing single owner instead of splitting them across two runner instances.
|
|
114
|
+
*/
|
|
115
|
+
taskLoop?: {
|
|
116
|
+
taskId: string;
|
|
117
|
+
};
|
|
118
|
+
constructor(deps: SessionHostDeps);
|
|
119
|
+
private get runState();
|
|
120
|
+
get agent(): Agent;
|
|
121
|
+
get sessionManager(): SessionManager;
|
|
122
|
+
/** Kick off asynchronous session construction. The first message can arrive before it settles. */
|
|
123
|
+
start(sessionManager: SessionManager): void;
|
|
124
|
+
private readonly contextFaults;
|
|
125
|
+
markContextFault(session: AgentSession, error: unknown): Error;
|
|
126
|
+
assertContextHealthy(): void;
|
|
127
|
+
/** Run a prompt (or steer) with the resource gate and the context-fault guard. */
|
|
128
|
+
runPrompt<T>(fn: () => Promise<T>): Promise<T>;
|
|
129
|
+
/** Stop listening to the live session and dispose it (no-op error handling is the caller's). */
|
|
130
|
+
retireLiveSession(): void;
|
|
131
|
+
/**
|
|
132
|
+
* Release the session once idle. Guards a dispose() racing construction: initializeSession
|
|
133
|
+
* assigns `this.session` asynchronously, so a runner disposed the instant after creation may
|
|
134
|
+
* not have one yet.
|
|
135
|
+
*/
|
|
136
|
+
disposeSession(): Promise<void>;
|
|
137
|
+
refreshSessionResources(): Promise<void>;
|
|
138
|
+
private initializeSession;
|
|
139
|
+
private reloadSessionResources;
|
|
140
|
+
private bindSessionExtensions;
|
|
141
|
+
ensureSessionReady(): Promise<void>;
|
|
142
|
+
private refreshSubAgentDiscovery;
|
|
143
|
+
private reportSettingsDiagnostics;
|
|
144
|
+
private reportConfigDiagnostics;
|
|
145
|
+
/**
|
|
146
|
+
* Build the Pipiclaw-owned system prompt (spec 025). This replaces pi's default
|
|
147
|
+
* base prompt entirely: identity, execution contract, hard invariants, the tool
|
|
148
|
+
* catalog and the workspace files are ours. pi still appends its tail (skills,
|
|
149
|
+
* date, cwd), and the boundary footer is appended after that by the prompt
|
|
150
|
+
* extension.
|
|
151
|
+
*
|
|
152
|
+
* Nothing channel-specific enters this text — that is what lets two channels in
|
|
153
|
+
* one workspace share a cached prompt prefix. Channel facts ride the turn.
|
|
154
|
+
*/
|
|
155
|
+
buildSystemPrompt(): PromptBuildResult;
|
|
156
|
+
private createResourceLoader;
|
|
157
|
+
private createAgentSessionServices;
|
|
158
|
+
/**
|
|
159
|
+
* Load a freshly constructed ResourceLoader before an `AgentSession` is built on top of it.
|
|
160
|
+
*
|
|
161
|
+
* `AgentSession` reads `resourceLoader.getExtensions()` in its constructor, and a loader that
|
|
162
|
+
* has never been loaded answers with an *empty* set. Skipping this leaves a replacement session
|
|
163
|
+
* with no extensions at all — no command extension (so `/model`, `/thinking`, `/session`,
|
|
164
|
+
* `/compact` and `/memory` fall through to the model as plain text), no memory lifecycle, no
|
|
165
|
+
* prompt-boundary footer, and no prompt templates. Tolerated on failure the same way
|
|
166
|
+
* `reloadSessionResources` tolerates a stuck reload: a degraded session still answers chat.
|
|
167
|
+
*/
|
|
168
|
+
private loadSessionResources;
|
|
169
|
+
/**
|
|
170
|
+
* Resolve the initial thinking level using the same precedence as pi's SDK:
|
|
171
|
+
* session history, configured default, then medium. The effective value is
|
|
172
|
+
* clamped to the selected model before the session starts.
|
|
173
|
+
*/
|
|
174
|
+
private initializeThinkingLevel;
|
|
175
|
+
private createSessionRuntime;
|
|
176
|
+
/**
|
|
177
|
+
* Bind this runner to a task cycle's own session (spec 051, D3/INV-5).
|
|
178
|
+
*
|
|
179
|
+
* Task work must not accumulate in the channel's chat transcript: the one real channel on the
|
|
180
|
+
* author's machine had grown to 7.4 MB and been compacted six times because chat and two daily
|
|
181
|
+
* tasks shared it, so every compaction damaged all three at once. Swapping the bound session
|
|
182
|
+
* per turn gives each task its own bounded context while leaving turn state, `/stop`, and
|
|
183
|
+
* delivery exactly where they already are.
|
|
184
|
+
*/
|
|
185
|
+
bindTaskSession(taskId: string): Promise<void>;
|
|
186
|
+
/** Return to the channel's chat session after a task step. Safe to call when already bound. */
|
|
187
|
+
bindChatSession(): Promise<void>;
|
|
188
|
+
/** Bootstrap presence follows canonical context, including omissions and compaction.
|
|
189
|
+
* Returning from a task or restarting must neither duplicate a visible bootstrap nor
|
|
190
|
+
* mistake an omitted failed input for one. Raw messages remain available to memory/recovery.
|
|
191
|
+
*/
|
|
192
|
+
private syncMemoryBootstrapPendingFromSession;
|
|
193
|
+
/** Which task loop this runner is currently bound to, if any. */
|
|
194
|
+
getTaskLoop(): {
|
|
195
|
+
taskId: string;
|
|
196
|
+
} | undefined;
|
|
197
|
+
private buildRuntimeTools;
|
|
198
|
+
private rebuildSessionTools;
|
|
199
|
+
private subscribeToSessionEvents;
|
|
200
|
+
}
|