@oyasmi/pipiclaw 0.9.6-beta.1 → 0.9.6-beta.3
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/README.en.md +279 -215
- package/README.md +274 -213
- package/dist/agent/builtin-commands.d.ts +1 -1
- package/dist/agent/builtin-commands.js +1 -1
- package/dist/agent/channel-runner.d.ts +3 -2
- package/dist/agent/channel-runner.js +18 -27
- package/dist/agent/maintenance-context.js +22 -3
- package/dist/agent/prompt/builder.d.ts +1 -1
- package/dist/agent/prompt/builder.js +1 -1
- package/dist/agent/prompt/extension.d.ts +1 -1
- package/dist/agent/prompt/extension.js +1 -1
- package/dist/agent/prompt/manifest.d.ts +6 -1
- package/dist/agent/prompt/manifest.js +12 -5
- package/dist/agent/prompt/resources.d.ts +0 -3
- package/dist/agent/prompt/resources.js +0 -6
- package/dist/agent/prompt/sections.d.ts +2 -2
- package/dist/agent/prompt/sections.js +36 -26
- package/dist/agent/prompt/types.d.ts +1 -1
- package/dist/agent/runner-factory.js +1 -1
- package/dist/agent/session/command-extension.js +3 -1
- package/dist/agent/session/compaction-summary.js +3 -6
- package/dist/agent/session/event-guards.d.ts +2 -1
- package/dist/agent/session/event-guards.js +6 -0
- package/dist/agent/session/model-selection.d.ts +2 -1
- package/dist/agent/session/model-selection.js +5 -5
- package/dist/agent/session/session-events.js +31 -4
- package/dist/agent/session/session-host.d.ts +4 -2
- package/dist/agent/session/session-host.js +17 -15
- package/dist/agent/status-render.js +3 -0
- package/dist/agent/turn/task-digest.d.ts +2 -5
- package/dist/agent/turn/task-digest.js +25 -45
- package/dist/agent/turn/turn-context.js +14 -12
- package/dist/agent/turn/turn-error.d.ts +1 -1
- package/dist/agent/turn/turn-error.js +9 -0
- package/dist/agent/turn/turn-pipeline.d.ts +10 -5
- package/dist/agent/turn/turn-pipeline.js +36 -7
- package/dist/agent/turn/turn-prompt.d.ts +2 -0
- package/dist/agent/turn/turn-prompt.js +2 -1
- package/dist/agent/turn/turn-recovery.js +4 -1
- package/dist/agent/types.d.ts +20 -2
- package/dist/agent/types.js +2 -0
- package/dist/app/auth-command.d.ts +25 -0
- package/dist/app/auth-command.js +200 -67
- package/dist/app/home.d.ts +7 -8
- package/dist/app/home.js +143 -56
- package/dist/channel/channel-context.d.ts +6 -0
- package/dist/channel/config.d.ts +3 -0
- package/dist/channel/config.js +11 -5
- package/dist/commands/catalog.js +22 -6
- package/dist/config/settings.d.ts +0 -2
- package/dist/config/settings.js +0 -2
- package/dist/config/tools.d.ts +8 -2
- package/dist/config/tools.js +35 -19
- package/dist/desk/commands.d.ts +31 -4
- package/dist/desk/commands.js +101 -15
- package/dist/desk/paths.d.ts +6 -0
- package/dist/desk/paths.js +21 -1
- package/dist/desk/registry.d.ts +11 -0
- package/dist/desk/registry.js +53 -9
- package/dist/desk/types.d.ts +66 -1
- package/dist/dingtalk/config.js +10 -10
- package/dist/dingtalk/delivery.js +2 -0
- package/dist/dingtalk/inbound.js +2 -3
- package/dist/events/watcher.d.ts +1 -1
- package/dist/events/watcher.js +2 -2
- package/dist/main.js +15 -3
- package/dist/memory/anchors.d.ts +5 -0
- package/dist/memory/anchors.js +49 -0
- package/dist/memory/boundary-work.d.ts +3 -1
- package/dist/memory/boundary-work.js +2 -1
- package/dist/memory/commands.js +23 -6
- package/dist/memory/index-budget.d.ts +16 -0
- package/dist/memory/index-budget.js +24 -2
- package/dist/memory/journal.d.ts +7 -12
- package/dist/memory/journal.js +9 -41
- package/dist/memory/lifecycle.d.ts +3 -1
- package/dist/memory/lifecycle.js +4 -2
- package/dist/memory/reflect-job.d.ts +3 -1
- package/dist/memory/reflect-job.js +2 -1
- package/dist/memory/reflect.d.ts +12 -1
- package/dist/memory/reflect.js +104 -20
- package/dist/memory/render.d.ts +4 -1
- package/dist/memory/render.js +6 -4
- package/dist/memory/review-log.d.ts +2 -2
- package/dist/memory/scheduler.d.ts +9 -1
- package/dist/memory/scheduler.js +71 -4
- package/dist/memory/search-index-db.d.ts +15 -0
- package/dist/memory/search-index-db.js +247 -0
- package/dist/memory/search-index-files.d.ts +11 -0
- package/dist/memory/search-index-files.js +26 -0
- package/dist/memory/search-index-notes.d.ts +11 -0
- package/dist/memory/search-index-notes.js +155 -0
- package/dist/memory/search-index-sync.d.ts +19 -0
- package/dist/memory/search-index-sync.js +267 -0
- package/dist/memory/search-terms.d.ts +12 -0
- package/dist/memory/search-terms.js +185 -0
- package/dist/memory/search.d.ts +8 -28
- package/dist/memory/search.js +18 -278
- package/dist/memory/session-corpus.d.ts +15 -26
- package/dist/memory/session-corpus.js +120 -321
- package/dist/memory/session-search.d.ts +7 -4
- package/dist/memory/session-search.js +120 -172
- package/dist/memory/sidecar-worker.d.ts +4 -1
- package/dist/memory/sidecar-worker.js +27 -5
- package/dist/memory/store.d.ts +4 -0
- package/dist/memory/store.js +22 -1
- package/dist/memory/task-archive-digest.d.ts +61 -0
- package/dist/memory/task-archive-digest.js +366 -0
- package/dist/models/credential-work.d.ts +7 -0
- package/dist/models/credential-work.js +36 -0
- package/dist/models/login-ui.js +4 -4
- package/dist/models/provider-login.d.ts +1 -1
- package/dist/models/provider-login.js +8 -7
- package/dist/models/requests.d.ts +8 -0
- package/dist/models/requests.js +69 -0
- package/dist/models/runtime.d.ts +3 -1
- package/dist/models/runtime.js +9 -2
- package/dist/playbooks/agent-delegation.md +19 -45
- package/dist/playbooks/background-jobs.md +1 -1
- package/dist/playbooks/catalog.js +1 -1
- package/dist/playbooks/delegation-inline.md +25 -0
- package/dist/playbooks/delegation-recovery.md +28 -0
- package/dist/playbooks/event-scheduling.md +18 -37
- package/dist/playbooks/event-sensors.md +26 -0
- package/dist/playbooks/event-task-template.md +22 -0
- package/dist/playbooks/learning-and-skills.md +26 -0
- package/dist/playbooks/memory-operations.md +36 -0
- package/dist/playbooks/outbound-media.md +2 -2
- package/dist/playbooks/runtime-files.md +29 -0
- package/dist/playbooks/runtime-operations.md +25 -0
- package/dist/playbooks/runtime-orientation.md +18 -53
- package/dist/playbooks/task-lead.md +22 -68
- package/dist/playbooks/task-manage.md +38 -0
- package/dist/playbooks/task-recovery.md +24 -0
- package/dist/playbooks/task-verify.md +22 -0
- package/dist/runtime/bootstrap.d.ts +4 -0
- package/dist/runtime/bootstrap.js +82 -22
- package/dist/runtime/daemon-lock.js +3 -3
- package/dist/runtime/desk-runtime.d.ts +33 -6
- package/dist/runtime/desk-runtime.js +302 -47
- package/dist/runtime/ingress-commands.js +24 -4
- package/dist/runtime/shutdown.d.ts +3 -1
- package/dist/runtime/shutdown.js +1 -0
- package/dist/runtime/task-close.d.ts +1 -1
- package/dist/runtime/task-close.js +6 -3
- package/dist/runtime/task-control.d.ts +1 -3
- package/dist/runtime/task-control.js +15 -11
- package/dist/runtime/task-input.js +1 -1
- package/dist/runtime/task-lane-types.d.ts +12 -2
- package/dist/runtime/task-lane-types.js +9 -0
- package/dist/runtime/task-lane.d.ts +1 -0
- package/dist/runtime/task-lane.js +17 -14
- package/dist/runtime/task-step.d.ts +3 -3
- package/dist/runtime/task-step.js +23 -14
- package/dist/runtime/transports.js +6 -5
- package/dist/security/command-guard.js +23 -1
- package/dist/shared/text-utils.d.ts +0 -1
- package/dist/shared/text-utils.js +0 -1
- package/dist/subagents/commands.js +14 -5
- package/dist/subagents/completion-wake.js +6 -0
- package/dist/subagents/dispatch.js +20 -18
- package/dist/subagents/external/dispatch.js +20 -14
- package/dist/subagents/external/run.js +10 -20
- package/dist/subagents/external/settlement.js +5 -1
- package/dist/subagents/internal/outcome.js +19 -12
- package/dist/subagents/internal/provider-retry.js +1 -3
- package/dist/subagents/internal/run.d.ts +1 -1
- package/dist/subagents/internal/run.js +27 -4
- package/dist/subagents/internal/state.d.ts +1 -3
- package/dist/subagents/internal/state.js +1 -2
- package/dist/subagents/internal/worker.js +17 -9
- package/dist/subagents/result.d.ts +5 -2
- package/dist/subagents/result.js +35 -6
- package/dist/subagents/run-record.d.ts +21 -0
- package/dist/subagents/run-record.js +5 -0
- package/dist/subagents/runs.d.ts +5 -8
- package/dist/subagents/runs.js +24 -35
- package/dist/subagents/task-envelope.js +11 -8
- package/dist/subagents/task-settlement.js +1 -0
- package/dist/subagents/types.d.ts +14 -4
- package/dist/subagents/workspace-lease.d.ts +37 -10
- package/dist/subagents/workspace-lease.js +121 -13
- package/dist/subagents/worktree.d.ts +47 -5
- package/dist/subagents/worktree.js +316 -30
- package/dist/tasks/brief.d.ts +5 -1
- package/dist/tasks/brief.js +19 -5
- package/dist/tasks/commands.d.ts +3 -1
- package/dist/tasks/commands.js +17 -6
- package/dist/tasks/control.d.ts +9 -0
- package/dist/tasks/loop-log.d.ts +10 -0
- package/dist/tasks/loop-log.js +1 -1
- package/dist/tasks/receipts.d.ts +7 -3
- package/dist/tasks/receipts.js +34 -5
- package/dist/tools/bash.d.ts +3 -0
- package/dist/tools/bash.js +27 -15
- package/dist/tools/contract/presentation.js +4 -1
- package/dist/tools/edit-diff.d.ts +11 -0
- package/dist/tools/edit-diff.js +148 -0
- package/dist/tools/edit-match.d.ts +18 -0
- package/dist/tools/edit-match.js +242 -0
- package/dist/tools/edit.d.ts +10 -2
- package/dist/tools/edit.js +91 -361
- package/dist/tools/event-manage.d.ts +1 -2
- package/dist/tools/event-manage.js +27 -38
- package/dist/tools/file-observations.d.ts +9 -0
- package/dist/tools/file-observations.js +50 -0
- package/dist/tools/glob-match.d.ts +3 -1
- package/dist/tools/glob-match.js +40 -17
- package/dist/tools/glob.d.ts +1 -0
- package/dist/tools/glob.js +39 -19
- package/dist/tools/grep-command.d.ts +13 -0
- package/dist/tools/grep-command.js +77 -0
- package/dist/tools/grep.js +96 -201
- package/dist/tools/index.d.ts +4 -1
- package/dist/tools/index.js +7 -4
- package/dist/tools/job.js +12 -11
- package/dist/tools/memory-manage.d.ts +1 -0
- package/dist/tools/memory-manage.js +9 -23
- package/dist/tools/read.d.ts +2 -0
- package/dist/tools/read.js +10 -2
- package/dist/tools/registry.d.ts +16 -11
- package/dist/tools/registry.js +31 -11
- package/dist/tools/session-search.d.ts +3 -1
- package/dist/tools/session-search.js +24 -8
- package/dist/tools/skill.js +13 -12
- package/dist/tools/subagent-manage.js +10 -3
- package/dist/tools/subagent.d.ts +22 -2
- package/dist/tools/subagent.js +19 -18
- package/dist/tools/task-manage/control-tools.js +1 -1
- package/dist/tools/task-manage/factory.d.ts +2 -2
- package/dist/tools/task-manage/factory.js +39 -3
- package/dist/tools/task-manage/lifecycle.d.ts +2 -2
- package/dist/tools/task-manage/lifecycle.js +7 -4
- package/dist/tools/task-manage/shared.d.ts +1 -1
- package/dist/tools/task-manage/types.d.ts +1 -0
- package/dist/tools/web-search.d.ts +13 -7
- package/dist/tools/web-search.js +62 -19
- package/dist/tools/write-content.d.ts +7 -1
- package/dist/tools/write-content.js +18 -6
- package/dist/tools/write.d.ts +3 -0
- package/dist/tools/write.js +6 -2
- package/dist/tui/cli.d.ts +5 -0
- package/dist/tui/cli.js +97 -31
- package/dist/tui/client.d.ts +5 -0
- package/dist/tui/client.js +63 -21
- package/dist/tui/frontend.d.ts +2 -0
- package/dist/tui/pitui-frontend.d.ts +4 -0
- package/dist/tui/pitui-frontend.js +27 -0
- package/dist/tui/render.d.ts +1 -0
- package/dist/tui/render.js +5 -0
- package/dist/tui/session.js +6 -0
- package/dist/web/client.d.ts +3 -0
- package/dist/web/client.js +18 -3
- package/dist/web/config.d.ts +17 -4
- package/dist/web/config.js +42 -4
- package/dist/web/fetch.js +6 -3
- package/dist/web/format.d.ts +2 -1
- package/dist/web/format.js +7 -3
- package/dist/web/search-providers.d.ts +15 -8
- package/dist/web/search-providers.js +208 -139
- package/dist/web/search.d.ts +13 -3
- package/dist/web/search.js +86 -40
- package/dist/webapi/auth.d.ts +0 -3
- package/dist/webapi/auth.js +3 -7
- package/dist/webapi/config.js +17 -14
- package/dist/webapi/key-command.js +41 -41
- package/dist/webapi/response-state.d.ts +7 -1
- package/dist/webapi/response-state.js +166 -3
- package/dist/webapi/routes/websocket.js +24 -1
- package/dist/webapi/server.d.ts +3 -1
- package/dist/webapi/server.js +32 -1
- package/dist/webapi/service.js +8 -0
- package/dist/webapi/transport.d.ts +2 -0
- package/dist/webapi/transport.js +11 -1
- package/examples/sub-agents/README.md +9 -7
- package/examples/sub-agents/agy-main.md +21 -0
- package/examples/sub-agents/claude-high.md +21 -0
- package/examples/sub-agents/claude-main.md +21 -0
- package/examples/sub-agents/codex-flash.md +21 -0
- package/examples/sub-agents/codex-high.md +21 -0
- package/examples/sub-agents/codex-main.md +21 -0
- package/examples/sub-agents/codex-review.md +20 -0
- package/examples/sub-agents/cursor-high.md +20 -0
- package/examples/sub-agents/cursor-main.md +20 -0
- package/examples/sub-agents/glm-flash.md +21 -0
- package/examples/sub-agents/glm-high.md +21 -0
- package/examples/sub-agents/pi-scout.md +20 -0
- package/package.json +8 -9
- package/dist/agent/session/request-tools.d.ts +0 -3
- package/dist/agent/session/request-tools.js +0 -20
- package/dist/memory/chinese-words.d.ts +0 -1
- package/dist/memory/chinese-words.js +0 -273
- package/dist/models/api-keys.d.ts +0 -11
- package/dist/models/api-keys.js +0 -22
- package/dist/playbooks/memory-and-learning.md +0 -55
- package/examples/sub-agents/agents/agy-main.md +0 -23
- package/examples/sub-agents/agents/claude-high.md +0 -23
- package/examples/sub-agents/agents/claude-main.md +0 -23
- package/examples/sub-agents/agents/codex-flash.md +0 -23
- package/examples/sub-agents/agents/codex-high.md +0 -23
- package/examples/sub-agents/agents/codex-main.md +0 -23
- package/examples/sub-agents/agents/codex-review.md +0 -23
- package/examples/sub-agents/agents/cursor-high.md +0 -22
- package/examples/sub-agents/agents/cursor-main.md +0 -22
- package/examples/sub-agents/agents/glm-flash.md +0 -23
- package/examples/sub-agents/agents/glm-high.md +0 -23
|
@@ -11,7 +11,7 @@ export interface BuiltinCommandHost {
|
|
|
11
11
|
promptTemplates(): ReadonlyArray<{
|
|
12
12
|
name: string;
|
|
13
13
|
}>;
|
|
14
|
-
renderContextReport(args: string): string
|
|
14
|
+
renderContextReport(args: string): Promise<string>;
|
|
15
15
|
}
|
|
16
16
|
/** A `/steer` or `/followup` needs a message: the trimmed text, or an error telling the user how. */
|
|
17
17
|
export declare function requireQueuedMessage(text: string, commandName: "steer" | "followup"): string;
|
|
@@ -49,7 +49,7 @@ export async function handleBuiltinCommand(host, command) {
|
|
|
49
49
|
case "help":
|
|
50
50
|
return renderHelpWithDiscovery(host, command.args);
|
|
51
51
|
case "context":
|
|
52
|
-
return host.renderContextReport(command.args);
|
|
52
|
+
return await host.renderContextReport(command.args);
|
|
53
53
|
case "stop":
|
|
54
54
|
return formatNoRunningTurn("stop");
|
|
55
55
|
case "steer":
|
|
@@ -6,6 +6,7 @@ import { type RunnerBuiltInCommand } from "../commands/catalog.js";
|
|
|
6
6
|
import type { DeskConversation } from "../desk/types.js";
|
|
7
7
|
import type { MemoryMaintenanceRuntimeContext } from "../memory/scheduler.js";
|
|
8
8
|
import type { SubAgentDiscoveryResult } from "../subagents/types.js";
|
|
9
|
+
import type { TaskBrief } from "../tasks/brief.js";
|
|
9
10
|
import type { RunnerDeps, RunnerFactoryPaths } from "./types.js";
|
|
10
11
|
import { type AgentRunner, type RunnerActivity, type RunnerStatusSnapshot, type TurnStatus } from "./types.js";
|
|
11
12
|
export declare class ChannelRunner implements AgentRunner {
|
|
@@ -49,7 +50,7 @@ export declare class ChannelRunner implements AgentRunner {
|
|
|
49
50
|
isBusy(): boolean;
|
|
50
51
|
requestStop(): void;
|
|
51
52
|
getTurnStatus(): TurnStatus;
|
|
52
|
-
run(info: TurnInfo, channel: ChannelContext, store: ChannelStore): ReturnType<AgentRunner["run"]>;
|
|
53
|
+
run(info: TurnInfo, channel: ChannelContext, store: ChannelStore, taskContract?: TaskBrief["contract"]): ReturnType<AgentRunner["run"]>;
|
|
53
54
|
handleBuiltinCommand(command: RunnerBuiltInCommand): Promise<string>;
|
|
54
55
|
/**
|
|
55
56
|
* True if `text` is a slash command the runtime or session layer can handle:
|
|
@@ -77,7 +78,7 @@ export declare class ChannelRunner implements AgentRunner {
|
|
|
77
78
|
* breakdown of the system prompt, the tool schemas (billed on top of it, and
|
|
78
79
|
* often the larger half), and the last turn's dynamic context.
|
|
79
80
|
*/
|
|
80
|
-
renderContextReport(args?: string): string
|
|
81
|
+
renderContextReport(args?: string): Promise<string>;
|
|
81
82
|
/** `/subagents list`'s role-directory health tail — whatever this runner already discovered. */
|
|
82
83
|
getSubAgentDiscoverySnapshot(): SubAgentDiscoveryResult;
|
|
83
84
|
getActivity(): RunnerActivity;
|
|
@@ -13,7 +13,6 @@ import * as log from "../log.js";
|
|
|
13
13
|
import { MemoryLifecycle } from "../memory/lifecycle.js";
|
|
14
14
|
import { createMemoryActivityRecorder, } from "../memory/maintenance-state.js";
|
|
15
15
|
import { getMemoryMaintenanceTuning } from "../memory/maintenance-tuning.js";
|
|
16
|
-
import { getApiKeyForModel } from "../models/api-keys.js";
|
|
17
16
|
import { runPromptWithFallback } from "../models/fallback.js";
|
|
18
17
|
import { formatModelReference } from "../models/reference.js";
|
|
19
18
|
import { defaultModel } from "../models/runtime.js";
|
|
@@ -30,7 +29,6 @@ import { createRunQueue } from "./turn/run-queue.js";
|
|
|
30
29
|
import { TurnFinisher } from "./turn/turn-finish.js";
|
|
31
30
|
import { TurnOutput } from "./turn/turn-output.js";
|
|
32
31
|
import { createTurnProgress, TurnPipeline } from "./turn/turn-pipeline.js";
|
|
33
|
-
import { assembleTurnPrompt } from "./turn/turn-prompt.js";
|
|
34
32
|
import { recoverInterruptedTurn } from "./turn/turn-recovery.js";
|
|
35
33
|
import { TurnStateMachine } from "./turn/turn-state.js";
|
|
36
34
|
import { createEmptyRunState, } from "./types.js";
|
|
@@ -110,6 +108,7 @@ export class ChannelRunner {
|
|
|
110
108
|
getSession: () => this.session,
|
|
111
109
|
getSessionSettingsManager: () => this.host.sessionSettingsManager,
|
|
112
110
|
getModelRegistry: () => this.host.modelRegistry,
|
|
111
|
+
getModelRuntime: () => this.host.modelRuntime,
|
|
113
112
|
});
|
|
114
113
|
this.memoryLifecycle = new MemoryLifecycle({
|
|
115
114
|
enabled: this.profile.kind === "chat",
|
|
@@ -119,7 +118,11 @@ export class ChannelRunner {
|
|
|
119
118
|
getMessages: () => this.session.messages,
|
|
120
119
|
getSessionEntries: () => this.sessionManager.getBranch(),
|
|
121
120
|
getModel: () => this.session.model ?? this.models.activeModel,
|
|
122
|
-
|
|
121
|
+
modelRequests: {
|
|
122
|
+
ensureAuth: (model, signal) => this.host.modelRequests.ensureAuth(model, signal),
|
|
123
|
+
stream: (model, context, options) => this.host.modelRequests.stream(model, context, options),
|
|
124
|
+
},
|
|
125
|
+
resolveFallbackModel: () => this.models.resolveFallbackModel(),
|
|
123
126
|
recordMemoryActivity: (event) => this.recordMemoryActivity(event),
|
|
124
127
|
});
|
|
125
128
|
this.host = new SessionHost({
|
|
@@ -209,7 +212,7 @@ export class ChannelRunner {
|
|
|
209
212
|
getTurnStatus() {
|
|
210
213
|
return this.turnState.status();
|
|
211
214
|
}
|
|
212
|
-
async run(info, channel, store) {
|
|
215
|
+
async run(info, channel, store, taskContract) {
|
|
213
216
|
const startedAt = Date.now();
|
|
214
217
|
const ctx = new TurnOutput(channel, this.channelId);
|
|
215
218
|
this.resetRunState(info, ctx, store);
|
|
@@ -238,28 +241,9 @@ export class ChannelRunner {
|
|
|
238
241
|
if (this.profile.kind === "chat")
|
|
239
242
|
await mkdir(this.conversationDir, { recursive: true });
|
|
240
243
|
const channelCapsule = await this.pipeline.gatherTurnContext(input.preserveRawInput, turn);
|
|
241
|
-
|
|
242
|
-
clippedInput: input.clippedInput,
|
|
243
|
-
userMessage: input.userMessage,
|
|
244
|
-
preserveRawInput: input.preserveRawInput,
|
|
245
|
-
channelCapsule,
|
|
246
|
-
durableMemoryBootstrap: turn.durableMemoryBootstrapText,
|
|
247
|
-
taskDigest: turn.taskDigestText,
|
|
248
|
-
});
|
|
249
|
-
turn.promptText = assembled.text;
|
|
250
|
-
// Resolved before the compaction estimate below (which needs the image count) and
|
|
251
|
-
// refreshed inside `setModel` further down if a fallback switches models mid-turn
|
|
252
|
-
// (spec 049 D7) — a model's image support is looked up here explicitly because the
|
|
253
|
-
// SDK's own handling of an unsupported model is to silently replace each image block
|
|
254
|
-
// with a text placeholder.
|
|
244
|
+
// Count supported images in the compaction budget. Fallback rechecks image support.
|
|
255
245
|
turn.images = await this.pipeline.prepareTurnImages(info, ctx);
|
|
256
|
-
|
|
257
|
-
// included above), not just the bare user message — those pieces can add thousands of
|
|
258
|
-
// characters and must count against the projected context usage this guard is checking.
|
|
259
|
-
// Each image adds a fixed per-image estimate on top of the text: three attached photos
|
|
260
|
-
// can by themselves push a turn over the threshold that would trigger this guard.
|
|
261
|
-
await this.pipeline.maybeRunPreventiveCompactionForIncomingText(turn.promptText, turn.images.images.length);
|
|
262
|
-
this.lastTurnContextStats = assembled.stats;
|
|
246
|
+
this.lastTurnContextStats = await this.pipeline.preparePrompt(input, turn, channelCapsule, taskContract);
|
|
263
247
|
turn.fallbackAttempted = await runPromptWithFallback(turn.promptText, this.pipeline.buildFallbackDeps(info, ctx, turn, ownTurn));
|
|
264
248
|
}
|
|
265
249
|
catch (err) {
|
|
@@ -384,7 +368,8 @@ export class ChannelRunner {
|
|
|
384
368
|
messages: () => [...this.session.messages],
|
|
385
369
|
sessionEntries: () => [...this.sessionManager.getBranch()],
|
|
386
370
|
model: this.session.model ?? this.models.activeModel,
|
|
387
|
-
|
|
371
|
+
modelRequests: this.host.modelRequests,
|
|
372
|
+
resolveFallbackModel: () => this.models.resolveFallbackModel(),
|
|
388
373
|
settings: { memoryMaintenance: this.settingsManager.getMemoryMaintenanceSettings() },
|
|
389
374
|
};
|
|
390
375
|
}
|
|
@@ -393,9 +378,13 @@ export class ChannelRunner {
|
|
|
393
378
|
if (!this.host.sessionInitialized)
|
|
394
379
|
return undefined;
|
|
395
380
|
const model = this.session.model ?? this.models.activeModel;
|
|
381
|
+
const availableModels = this.host.modelRegistry.getAvailable();
|
|
382
|
+
const modelConfigured = availableModels.some((candidate) => candidate.provider === model.provider && candidate.id === model.id) ||
|
|
383
|
+
(model.provider === "anthropic" && Boolean(process.env.ANTHROPIC_API_KEY?.trim()));
|
|
396
384
|
const contextTokens = this.session.getContextUsage()?.tokens;
|
|
397
385
|
return {
|
|
398
386
|
model: formatModelReference(model),
|
|
387
|
+
modelConfigured,
|
|
399
388
|
contextTokens: typeof contextTokens === "number" ? contextTokens : undefined,
|
|
400
389
|
contextWindow: model.contextWindow || 200000,
|
|
401
390
|
thinkingLevel: this.session.thinkingLevel,
|
|
@@ -435,7 +424,8 @@ export class ChannelRunner {
|
|
|
435
424
|
* breakdown of the system prompt, the tool schemas (billed on top of it, and
|
|
436
425
|
* often the larger half), and the last turn's dynamic context.
|
|
437
426
|
*/
|
|
438
|
-
renderContextReport(args = "") {
|
|
427
|
+
async renderContextReport(args = "") {
|
|
428
|
+
await this.host.ensureSessionReady();
|
|
439
429
|
const build = this.host.lastPromptBuild ?? this.host.buildSystemPrompt();
|
|
440
430
|
return renderContextReport({
|
|
441
431
|
build,
|
|
@@ -446,6 +436,7 @@ export class ChannelRunner {
|
|
|
446
436
|
soul: this.host.lastWorkspaceResources?.soul,
|
|
447
437
|
agents: this.host.lastWorkspaceResources?.agents,
|
|
448
438
|
lastTurn: this.lastTurnContextStats,
|
|
439
|
+
sessionUsage: this.session.getSessionStats().tokens,
|
|
449
440
|
detail: args.trim().toLowerCase() === "detail",
|
|
450
441
|
});
|
|
451
442
|
}
|
|
@@ -3,8 +3,9 @@ import { join } from "node:path";
|
|
|
3
3
|
import { SessionManager } from "@earendil-works/pi-coding-agent";
|
|
4
4
|
import { peekActiveSessionFile } from "../channel/active-session-store.js";
|
|
5
5
|
import { enqueueBoundaryReflectEntries } from "../memory/boundary-work.js";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
6
|
+
import { findExactModelReferenceMatch } from "../models/reference.js";
|
|
7
|
+
import { createModelRequests } from "../models/requests.js";
|
|
8
|
+
import { createModelRuntime, refreshModelRegistry, resolveInitialModel, wrapModelRegistry } from "../models/runtime.js";
|
|
8
9
|
/** /new's local persistence path: no runner, credentials, inference, or memory queue. */
|
|
9
10
|
export async function preserveMemoryBeforeNewSession(conversation) {
|
|
10
11
|
const file = join(conversation.conversationDir, peekActiveSessionFile(conversation.conversationDir));
|
|
@@ -70,6 +71,7 @@ export async function loadDetachedMaintenanceContext(options) {
|
|
|
70
71
|
});
|
|
71
72
|
const modelRegistry = wrapModelRegistry(modelRuntime);
|
|
72
73
|
const model = resolveInitialModel(modelRegistry, options.settingsManager);
|
|
74
|
+
const modelRequests = createModelRequests(modelRuntime);
|
|
73
75
|
options.settingsManager.reload();
|
|
74
76
|
return {
|
|
75
77
|
conversation,
|
|
@@ -77,7 +79,24 @@ export async function loadDetachedMaintenanceContext(options) {
|
|
|
77
79
|
messages: () => [...cachedTranscript.messages],
|
|
78
80
|
sessionEntries: () => [...cachedTranscript.sessionEntries],
|
|
79
81
|
model,
|
|
80
|
-
|
|
82
|
+
modelRequests,
|
|
83
|
+
resolveFallbackModel: async () => {
|
|
84
|
+
options.settingsManager.reload();
|
|
85
|
+
const reference = options.settingsManager.getFallbackModelReference();
|
|
86
|
+
if (!reference)
|
|
87
|
+
return null;
|
|
88
|
+
await refreshModelRegistry(modelRuntime);
|
|
89
|
+
const { match } = findExactModelReferenceMatch(reference, modelRegistry.getAvailable());
|
|
90
|
+
if (!match)
|
|
91
|
+
return null;
|
|
92
|
+
try {
|
|
93
|
+
await modelRequests.ensureAuth(match);
|
|
94
|
+
return match;
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
},
|
|
81
100
|
settings: { memoryMaintenance: options.settingsManager.getMemoryMaintenanceSettings() },
|
|
82
101
|
};
|
|
83
102
|
}
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
*/
|
|
14
14
|
import type { PromptBuildContext, PromptBuildResult, PromptSectionDefinition } from "./types.js";
|
|
15
15
|
/** Bumped whenever the runtime-authored prompt text changes in a way worth attributing in telemetry. */
|
|
16
|
-
export declare const RUNTIME_PROMPT_VERSION =
|
|
16
|
+
export declare const RUNTIME_PROMPT_VERSION = 6;
|
|
17
17
|
/** Over this, the runtime-authored prompt still works but is worth a warning (spec 026 §5.2). */
|
|
18
18
|
export declare const RUNTIME_PROMPT_TARGET_UNITS = 700;
|
|
19
19
|
/** Over this it is a development error: runtime text has drifted well past its budget. */
|
|
@@ -16,7 +16,7 @@ import { estimateTokens } from "../../shared/format.js";
|
|
|
16
16
|
import { countPromptUnits } from "../../shared/prompt-units.js";
|
|
17
17
|
import { FINAL_BOUNDARY_SECTION, MAIN_PROMPT_SECTIONS } from "./sections.js";
|
|
18
18
|
/** Bumped whenever the runtime-authored prompt text changes in a way worth attributing in telemetry. */
|
|
19
|
-
export const RUNTIME_PROMPT_VERSION =
|
|
19
|
+
export const RUNTIME_PROMPT_VERSION = 6;
|
|
20
20
|
/**
|
|
21
21
|
* The sections Pipiclaw authors and must keep tight (spec 026 §10.3): identity,
|
|
22
22
|
* execution, invariants, persistent-task rules, the runtime-guide catalog and the
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Final-boundary extension (spec 025 §6.11, §10.6).
|
|
3
3
|
*
|
|
4
|
-
* pi
|
|
4
|
+
* pi appends its own tail — skills and cwd — after a custom
|
|
5
5
|
* system prompt, so the last thing the model would otherwise read is
|
|
6
6
|
* user-authored content. This extension runs at `before_agent_start`, the only
|
|
7
7
|
* seam that sees the fully assembled prompt, and appends the runtime boundary
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Final-boundary extension (spec 025 §6.11, §10.6).
|
|
3
3
|
*
|
|
4
|
-
* pi
|
|
4
|
+
* pi appends its own tail — skills and cwd — after a custom
|
|
5
5
|
* system prompt, so the last thing the model would otherwise read is
|
|
6
6
|
* user-authored content. This extension runs at `before_agent_start`, the only
|
|
7
7
|
* seam that sees the fully assembled prompt, and appends the runtime boundary
|
|
@@ -53,7 +53,7 @@ export interface PromptTurnContextStats {
|
|
|
53
53
|
}
|
|
54
54
|
export interface PromptContextReportInput {
|
|
55
55
|
build: PromptBuildResult;
|
|
56
|
-
/**
|
|
56
|
+
/** The assembled system prompt, including pi's skills/cwd tail and the boundary footer. */
|
|
57
57
|
finalPrompt?: string;
|
|
58
58
|
skills: Array<{
|
|
59
59
|
name: string;
|
|
@@ -65,6 +65,11 @@ export interface PromptContextReportInput {
|
|
|
65
65
|
soul?: LoadedPromptResource;
|
|
66
66
|
agents?: LoadedPromptResource;
|
|
67
67
|
lastTurn?: PromptTurnContextStats;
|
|
68
|
+
sessionUsage?: {
|
|
69
|
+
input: number;
|
|
70
|
+
cacheRead: number;
|
|
71
|
+
cacheWrite: number;
|
|
72
|
+
};
|
|
68
73
|
detail: boolean;
|
|
69
74
|
}
|
|
70
75
|
export interface PromptSectionManifestEntry {
|
|
@@ -95,11 +95,18 @@ export function renderContextReport(input) {
|
|
|
95
95
|
const lines = ["**上下文**", ""];
|
|
96
96
|
lines.push(`- 系统提示词(Pipiclaw 部分):${formatNumber(build.totalUnits)} 单位,约 ${formatNumber(build.estimatedTokens)} tokens;其中运行时自带 ${formatNumber(build.runtimeAuthoredUnits)} / 目标 ${formatNumber(RUNTIME_PROMPT_TARGET_UNITS)} 单位`);
|
|
97
97
|
if (finalPrompt) {
|
|
98
|
-
// The
|
|
99
|
-
//
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
98
|
+
// The assembled system prompt is one part of the provider's prefix, alongside tool
|
|
99
|
+
// declarations and dialogue. The build fingerprint covers only Pipiclaw's own sections.
|
|
100
|
+
lines.push(`- 实际发送(含 skills、工作目录与边界尾注):${formatNumber(finalPrompt.length)} 字,约 ${formatNumber(estimateTokens(finalPrompt))} tokens,指纹 \`${sha256(finalPrompt).slice(0, 16)}\``);
|
|
101
|
+
}
|
|
102
|
+
if (input.sessionUsage) {
|
|
103
|
+
const { input: uncached, cacheRead, cacheWrite } = input.sessionUsage;
|
|
104
|
+
const totalInput = uncached + cacheRead + cacheWrite;
|
|
105
|
+
if (totalInput > 0) {
|
|
106
|
+
const percent = ((100 * cacheRead) / totalInput).toFixed(1);
|
|
107
|
+
const written = cacheWrite > 0 ? `,写入缓存 ${formatNumber(cacheWrite)}` : "";
|
|
108
|
+
lines.push(`- 会话缓存:已读缓存 ${formatNumber(cacheRead)} / 总输入 ${formatNumber(totalInput)} tokens(命中率 ${percent}%${written})`);
|
|
109
|
+
}
|
|
103
110
|
}
|
|
104
111
|
const overToolBudget = input.toolSchemas.units > TOOL_SCHEMA_TARGET_UNITS;
|
|
105
112
|
lines.push(`- 工具定义:${input.toolNames.length} 个,${formatNumber(input.toolSchemas.units)} / 目标 ${formatNumber(TOOL_SCHEMA_TARGET_UNITS)} 单位${overToolBudget ? "(超出目标)" : ""},在系统提示词之外另计`);
|
|
@@ -11,7 +11,6 @@
|
|
|
11
11
|
* the runtime catalog, or with skills for space; only a genuinely oversized file is
|
|
12
12
|
* head/tail clipped.
|
|
13
13
|
*/
|
|
14
|
-
import { type RuntimePlaybookMetadata } from "../../playbooks/catalog.js";
|
|
15
14
|
import type { LoadedPromptResource, PromptDiagnostic } from "./types.js";
|
|
16
15
|
/** SOUL.md is identity and voice: normally short, so a tight independent budget (spec 026 §5.2). */
|
|
17
16
|
export declare const SOUL_BUDGET_UNITS = 3000;
|
|
@@ -24,7 +23,5 @@ export interface WorkspacePromptResources {
|
|
|
24
23
|
agents?: LoadedPromptResource;
|
|
25
24
|
diagnostics: PromptDiagnostic[];
|
|
26
25
|
}
|
|
27
|
-
/** The bundled runtime playbooks that apply to the tools this runner actually has. */
|
|
28
|
-
export declare function loadPlaybooks(toolNames: readonly string[]): RuntimePlaybookMetadata[];
|
|
29
26
|
/** Read the workspace-wide identity and rules shared by every desk. */
|
|
30
27
|
export declare function loadWorkspacePromptResources(workspaceDir: string): WorkspacePromptResources;
|
|
@@ -14,9 +14,7 @@
|
|
|
14
14
|
import { existsSync, readFileSync } from "node:fs";
|
|
15
15
|
import { join } from "node:path";
|
|
16
16
|
import * as log from "../../log.js";
|
|
17
|
-
import { loadRuntimePlaybookCatalog, selectRuntimePlaybooks, } from "../../playbooks/catalog.js";
|
|
18
17
|
import { clipTextByPromptUnits, countPromptUnits } from "../../shared/prompt-units.js";
|
|
19
|
-
import { TOOL_NAMES } from "../../tools/registry.js";
|
|
20
18
|
import { DEFAULT_AGENTS, DEFAULT_SOUL, isDefaultWorkspaceTemplate } from "./workspace-templates.js";
|
|
21
19
|
/** SOUL.md is identity and voice: normally short, so a tight independent budget (spec 026 §5.2). */
|
|
22
20
|
export const SOUL_BUDGET_UNITS = 3_000;
|
|
@@ -24,10 +22,6 @@ export const SOUL_BUDGET_CHARS = 24_000;
|
|
|
24
22
|
/** AGENTS.md carries team procedure and is allowed to be larger (spec 026 §5.2). */
|
|
25
23
|
export const AGENTS_BUDGET_UNITS = 6_000;
|
|
26
24
|
export const AGENTS_BUDGET_CHARS = 48_000;
|
|
27
|
-
/** The bundled runtime playbooks that apply to the tools this runner actually has. */
|
|
28
|
-
export function loadPlaybooks(toolNames) {
|
|
29
|
-
return selectRuntimePlaybooks(loadRuntimePlaybookCatalog(TOOL_NAMES), toolNames);
|
|
30
|
-
}
|
|
31
25
|
function readWorkspaceFile(path) {
|
|
32
26
|
if (!existsSync(path)) {
|
|
33
27
|
return "";
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* 600–699 workspace instructions (SOUL, AGENTS)
|
|
12
12
|
* 700–799 skills (rendered by pi, not by us — see resources.ts)
|
|
13
13
|
* 800–899 final boundary (appended after pi's tail — see extension.ts)
|
|
14
|
-
* 900–999 environment / overlays (pi appends
|
|
14
|
+
* 900–999 environment / overlays (pi appends cwd)
|
|
15
15
|
*
|
|
16
16
|
* Content rules (spec 026 §2.1): a line stays here only if nearly every turn needs
|
|
17
17
|
* it, or missing it once can break safety / durable state / an external side effect,
|
|
@@ -29,7 +29,7 @@ export declare const SUBAGENTS_SECTION: PromptSectionDefinition;
|
|
|
29
29
|
export declare const SOUL_SECTION: PromptSectionDefinition;
|
|
30
30
|
export declare const AGENTS_SECTION: PromptSectionDefinition;
|
|
31
31
|
/**
|
|
32
|
-
* Injected *after* pi's tail (skills
|
|
32
|
+
* Injected *after* pi's tail (skills and cwd) by the prompt extension, so the
|
|
33
33
|
* last thing the model reads is the runtime boundary rather than user-authored
|
|
34
34
|
* content. It restates the boundary only — enforcement lives in the guards.
|
|
35
35
|
*/
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* 600–699 workspace instructions (SOUL, AGENTS)
|
|
12
12
|
* 700–799 skills (rendered by pi, not by us — see resources.ts)
|
|
13
13
|
* 800–899 final boundary (appended after pi's tail — see extension.ts)
|
|
14
|
-
* 900–999 environment / overlays (pi appends
|
|
14
|
+
* 900–999 environment / overlays (pi appends cwd)
|
|
15
15
|
*
|
|
16
16
|
* Content rules (spec 026 §2.1): a line stays here only if nearly every turn needs
|
|
17
17
|
* it, or missing it once can break safety / durable state / an external side effect,
|
|
@@ -42,9 +42,11 @@ export const IDENTITY_SECTION = {
|
|
|
42
42
|
cacheClass: "runtime-stable",
|
|
43
43
|
maxChars: 600,
|
|
44
44
|
overflow: "error",
|
|
45
|
-
render: () => [
|
|
45
|
+
render: (context) => [
|
|
46
46
|
"## Pipiclaw",
|
|
47
|
-
"
|
|
47
|
+
hasTool(context, "task_report") && !hasTool(context, "task_create")
|
|
48
|
+
? "You are leading a persistent background task on the host machine. SOUL.md defines your identity and voice. Ordinary replies stay in the task log; speak to the user only through task_report or task_ask."
|
|
49
|
+
: "You are a long-lived personal assistant running on the host machine. SOUL.md defines your identity and voice. Deliver chat-friendly answers with the outcome first.",
|
|
48
50
|
].join("\n"),
|
|
49
51
|
};
|
|
50
52
|
export const EXECUTION_SECTION = {
|
|
@@ -56,10 +58,10 @@ export const EXECUTION_SECTION = {
|
|
|
56
58
|
overflow: "error",
|
|
57
59
|
render: () => [
|
|
58
60
|
"## Working Contract",
|
|
59
|
-
"-
|
|
60
|
-
"-
|
|
61
|
-
"- Jobs and delegations
|
|
62
|
-
"-
|
|
61
|
+
"- Inspect before edits. Batch independent read/grep/glob/web_fetch calls in parallel. Run bash/edit/write in separate batches.",
|
|
62
|
+
"- Tool definitions are authoritative. Use Desk for state and Cwd for work. Finish the work and required checks, or report a real blocker. State unverified items.",
|
|
63
|
+
"- Jobs and delegations wake their initiator. Finish independent work and dispatches, then end the turn when only waiting remains. Skip polling and check-in events.",
|
|
64
|
+
"- Use routine calls directly. Read the guide or skill for task_*, orchestration, write isolation, independent checks, recurring or gated events, unfamiliar mechanisms or recovery. Reuse it while in context.",
|
|
63
65
|
].join("\n"),
|
|
64
66
|
};
|
|
65
67
|
export const INVARIANTS_SECTION = {
|
|
@@ -87,19 +89,32 @@ export const TASK_CORE_SECTION = {
|
|
|
87
89
|
source: "runtime/tasks",
|
|
88
90
|
authority: "runtime-hard",
|
|
89
91
|
cacheClass: "runtime-stable",
|
|
90
|
-
requiresAllTools: ["
|
|
92
|
+
requiresAllTools: ["task_close"],
|
|
91
93
|
maxChars: 600,
|
|
92
94
|
overflow: "error",
|
|
93
|
-
render: () =>
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
95
|
+
render: (context) => {
|
|
96
|
+
if (hasTool(context, "task_create")) {
|
|
97
|
+
return [
|
|
98
|
+
"## Persistent Work",
|
|
99
|
+
"Use a task when a project needs goals, acceptance criteria, budget and progress across turns. A single job or delegation needs no task. For scheduled projects use an event with a task template. Read task-manage.md before creating or managing tasks; reuse it while in context. Each task runs in its own background session.",
|
|
100
|
+
].join("\n");
|
|
101
|
+
}
|
|
102
|
+
if (hasTool(context, "task_report")) {
|
|
103
|
+
return [
|
|
104
|
+
"## Task Steps",
|
|
105
|
+
"Read task-lead.md before acting on the first step or whenever lost from context. Work and verify within Goal and DoD.",
|
|
106
|
+
"End the step if only your task's jobs or delegations remain. Use one bounded async job for external conditions, task_wait for a time, and task_ask for a blocking decision.",
|
|
107
|
+
"Check real state and logs before retrying unknown external effects. End with only new conclusions, evidence, and the next step.",
|
|
108
|
+
].join("\n");
|
|
109
|
+
}
|
|
110
|
+
return undefined;
|
|
111
|
+
},
|
|
97
112
|
};
|
|
98
113
|
export const PLAYBOOKS_SECTION = {
|
|
99
114
|
id: "playbooks",
|
|
100
115
|
source: "runtime/playbooks",
|
|
101
116
|
authority: "catalog",
|
|
102
|
-
cacheClass: "
|
|
117
|
+
cacheClass: "runtime-stable",
|
|
103
118
|
maxChars: 1_400,
|
|
104
119
|
overflow: "truncate-items",
|
|
105
120
|
render: (context) => {
|
|
@@ -109,6 +124,8 @@ export const PLAYBOOKS_SECTION = {
|
|
|
109
124
|
return ["## Runtime Guides", "", renderPlaybookCatalog(context.playbooks)].join("\n");
|
|
110
125
|
},
|
|
111
126
|
};
|
|
127
|
+
const SUBAGENT_HANDOFF = "In task, state the outcome, verified facts, constraints, paths, and acceptance criteria.";
|
|
128
|
+
const SUBAGENT_GUIDES = "Read agent-delegation.md for worktree isolation, purpose=verify, or multi-step delegation; delegation-recovery.md for failed, stalled, or follow_up runs.";
|
|
112
129
|
export const SUBAGENTS_SECTION = {
|
|
113
130
|
id: "subagents",
|
|
114
131
|
source: "workspace/sub-agents",
|
|
@@ -118,11 +135,7 @@ export const SUBAGENTS_SECTION = {
|
|
|
118
135
|
maxChars: 2_400,
|
|
119
136
|
overflow: "truncate-items",
|
|
120
137
|
render: (context) => {
|
|
121
|
-
//
|
|
122
|
-
// guidance that lives in this section — only the catalog itself is optional. This
|
|
123
|
-
// inline-usage text is runtime-authored, not user content; keep it under 40 units
|
|
124
|
-
// (it does not count toward the 700/1200 unit budget — see builder.ts's
|
|
125
|
-
// RUNTIME_AUTHORED_SECTION_IDS — so it must not be padded just because it is "free").
|
|
138
|
+
// Keep the handoff instructions even when no configured roles are available.
|
|
126
139
|
if (context.subAgents.length === 0) {
|
|
127
140
|
const hasInline = context.tools.some((tool) => tool.name === "subagent_inline");
|
|
128
141
|
return [
|
|
@@ -130,8 +143,8 @@ export const SUBAGENTS_SECTION = {
|
|
|
130
143
|
hasInline
|
|
131
144
|
? "No configured role is available, so use `subagent_inline` only as the fallback; provide a complete valid payload with required `task` and `systemPrompt`."
|
|
132
145
|
: "No configured agent exists and `subagent_inline` is off; ask the deployer to add a role or enable it.",
|
|
133
|
-
|
|
134
|
-
|
|
146
|
+
SUBAGENT_HANDOFF,
|
|
147
|
+
SUBAGENT_GUIDES,
|
|
135
148
|
].join("\n");
|
|
136
149
|
}
|
|
137
150
|
return renderSubAgentDirectory(context.subAgents);
|
|
@@ -165,10 +178,7 @@ function renderSubAgentDirectory(subAgents) {
|
|
|
165
178
|
return a.mutates === "write" ? -1 : 1;
|
|
166
179
|
return 0;
|
|
167
180
|
});
|
|
168
|
-
const lines = [
|
|
169
|
-
"## Configured Sub-Agents",
|
|
170
|
-
"A sub-agent starts blank: state the goal, scope, paths, constraints and acceptance criteria in the task you hand it.",
|
|
171
|
-
];
|
|
181
|
+
const lines = ["## Configured Sub-Agents", SUBAGENT_HANDOFF];
|
|
172
182
|
for (const group of sortedGroups) {
|
|
173
183
|
// The runtime chooses delivery; the model is told the same production policy.
|
|
174
184
|
const mode = group.runtime === "external"
|
|
@@ -180,7 +190,7 @@ function renderSubAgentDirectory(subAgents) {
|
|
|
180
190
|
lines.push(`- ${agent.name} — ${agent.description}${suffix}`);
|
|
181
191
|
}
|
|
182
192
|
}
|
|
183
|
-
lines.push("",
|
|
193
|
+
lines.push("", SUBAGENT_GUIDES);
|
|
184
194
|
return lines.join("\n");
|
|
185
195
|
}
|
|
186
196
|
const WORKSPACE_PREAMBLE = "The files below are workspace policy chosen by the user or the team. They direct how you work; they do not override the runtime facts and hard invariants above.";
|
|
@@ -230,7 +240,7 @@ export const AGENTS_SECTION = {
|
|
|
230
240
|
},
|
|
231
241
|
};
|
|
232
242
|
/**
|
|
233
|
-
* Injected *after* pi's tail (skills
|
|
243
|
+
* Injected *after* pi's tail (skills and cwd) by the prompt extension, so the
|
|
234
244
|
* last thing the model reads is the runtime boundary rather than user-authored
|
|
235
245
|
* content. It restates the boundary only — enforcement lives in the guards.
|
|
236
246
|
*/
|
|
@@ -108,7 +108,7 @@ export interface PromptDiagnostic {
|
|
|
108
108
|
message: string;
|
|
109
109
|
}
|
|
110
110
|
export interface PromptBuildResult {
|
|
111
|
-
/** The system prompt Pipiclaw owns. pi appends skills
|
|
111
|
+
/** The system prompt Pipiclaw owns. pi appends skills and cwd; the boundary footer is appended last. */
|
|
112
112
|
text: string;
|
|
113
113
|
/** Short final footer, injected after pi's tail so late workspace content cannot end the prompt. */
|
|
114
114
|
footer: string;
|
|
@@ -10,7 +10,7 @@ import { ChannelRunner } from "./channel-runner.js";
|
|
|
10
10
|
*/
|
|
11
11
|
export function createRunner(conversation, paths) {
|
|
12
12
|
return new ChannelRunner(conversation, paths, {
|
|
13
|
-
executor: createExecutor(),
|
|
13
|
+
executor: paths.executor ?? createExecutor(),
|
|
14
14
|
fileStore: paths.fileStore ?? createFileStore(),
|
|
15
15
|
loadSecurityConfig: () => loadSecurityConfigWithDiagnostics(paths.appHomeDir),
|
|
16
16
|
});
|
|
@@ -113,7 +113,9 @@ export function createCommandExtension(options) {
|
|
|
113
113
|
const currentModel = options.getCurrentModel();
|
|
114
114
|
if (!args.trim()) {
|
|
115
115
|
const current = currentModel ? `\`${formatModelReference(currentModel)}\`` : "(无)";
|
|
116
|
-
const available = availableModels.length > 0
|
|
116
|
+
const available = availableModels.length > 0
|
|
117
|
+
? formatModelList(availableModels, currentModel)
|
|
118
|
+
: "- 暂无可用模型(尚未检测到模型凭据;请在终端执行 `pipiclaw auth login`、设置供应商环境变量,或配置 `models.json` 后发送 `/reload`)";
|
|
117
119
|
const report = `**模型**
|
|
118
120
|
|
|
119
121
|
当前模型:${current}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { randomUUID } from "node:crypto";
|
|
3
3
|
import { compact, convertToLlm, } from "@earendil-works/pi-coding-agent";
|
|
4
4
|
import * as log from "../../log.js";
|
|
5
|
+
import { createModelRequests } from "../../models/requests.js";
|
|
5
6
|
import { estimateTokens } from "../../shared/format.js";
|
|
6
7
|
import { isRecord } from "../../shared/type-guards.js";
|
|
7
8
|
import { OperationTimeoutError, withAbortSignal } from "../../shared/with-timeout.js";
|
|
@@ -55,11 +56,8 @@ export class CompactionSummary {
|
|
|
55
56
|
thinkingLevel: "off",
|
|
56
57
|
signal,
|
|
57
58
|
})).model;
|
|
58
|
-
|
|
59
|
+
await createModelRequests(runtime).ensureAuth(model, signal);
|
|
59
60
|
signal.throwIfAborted();
|
|
60
|
-
if (!auth)
|
|
61
|
-
throw new Error(`No credentials for ${model.provider}; configure credentials on the server.`);
|
|
62
|
-
const requestModel = auth.auth.baseUrl ? { ...model, baseUrl: auth.auth.baseUrl } : model;
|
|
63
61
|
const reserveTokens = Math.min(SUMMARY_RESERVE_TOKENS, Math.floor(model.contextWindow / 4));
|
|
64
62
|
const previousTokens = estimateTokens(event.preparation.previousSummary ?? "");
|
|
65
63
|
if (model.contextWindow - previousTokens <= reserveTokens + 2048) {
|
|
@@ -95,7 +93,6 @@ export class CompactionSummary {
|
|
|
95
93
|
.catch(() => undefined);
|
|
96
94
|
return response;
|
|
97
95
|
};
|
|
98
|
-
const headers = Object.fromEntries(Object.entries(auth.auth.headers ?? {}).filter((entry) => typeof entry[1] === "string"));
|
|
99
96
|
// SDK treats custom summaries as opaque; restore our cumulative file metadata explicitly.
|
|
100
97
|
const previous = [...event.branchEntries].reverse().find((entry) => entry.type === "compaction");
|
|
101
98
|
if (previous?.type === "compaction" &&
|
|
@@ -122,7 +119,7 @@ export class CompactionSummary {
|
|
|
122
119
|
turnPrefixMessages: [],
|
|
123
120
|
isSplitTurn: false,
|
|
124
121
|
settings: { ...event.preparation.settings, reserveTokens },
|
|
125
|
-
},
|
|
122
|
+
}, model, undefined, undefined, `${SUMMARY_INSTRUCTIONS}\nTranscript part ${index + 1}/${chunks.length}; incorporate this part into the checkpoint, retaining earlier constraints and recovery references.\n${event.customInstructions ?? ""}`, signal, "off", stream, undefined, { ...session.settingsManager.getRetrySettings(), maxRetries: 1 });
|
|
126
123
|
signal.throwIfAborted();
|
|
127
124
|
if (summary.usage)
|
|
128
125
|
addUsage(totals, summary.usage);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { SubAgentToolDetails } from "../../tools/subagent.js";
|
|
2
|
-
import type { AssistantContentPart, AssistantEventMessage, AssistantUsageMessage, AutoCompactionEndEvent, AutoCompactionStartEvent, AutoRetryStartEvent, MessageEndEvent, MessageStartEvent, ToolExecutionEndEvent, ToolExecutionStartEvent, ToolExecutionUpdateEvent, TurnEndEvent } from "../types.js";
|
|
2
|
+
import type { AssistantContentPart, AssistantEventMessage, AssistantUsageMessage, AutoCompactionEndEvent, AutoCompactionStartEvent, AutoRetryStartEvent, MessageEndEvent, MessageStartEvent, MessageUpdateEvent, ToolExecutionEndEvent, ToolExecutionStartEvent, ToolExecutionUpdateEvent, TurnEndEvent } from "../types.js";
|
|
3
3
|
export declare function isAssistantEventMessage(value: unknown): value is AssistantEventMessage;
|
|
4
4
|
/** A message the user side wrote: the turn's prompt, or one injected into a running loop (steer, follow-up). */
|
|
5
5
|
export declare function isUserEventMessage(value: unknown): boolean;
|
|
@@ -15,6 +15,7 @@ export declare function isToolExecutionStartEvent(value: unknown): value is Tool
|
|
|
15
15
|
export declare function isToolExecutionUpdateEvent(value: unknown): value is ToolExecutionUpdateEvent;
|
|
16
16
|
export declare function isToolExecutionEndEvent(value: unknown): value is ToolExecutionEndEvent;
|
|
17
17
|
export declare function isMessageStartEvent(value: unknown): value is MessageStartEvent;
|
|
18
|
+
export declare function isMessageUpdateEvent(value: unknown): value is MessageUpdateEvent;
|
|
18
19
|
export declare function isMessageEndEvent(value: unknown): value is MessageEndEvent;
|
|
19
20
|
export declare function isTurnEndEvent(value: unknown): value is TurnEndEvent;
|
|
20
21
|
export declare function isAutoCompactionStartEvent(value: unknown): value is AutoCompactionStartEvent;
|
|
@@ -66,6 +66,12 @@ export function isToolExecutionEndEvent(value) {
|
|
|
66
66
|
export function isMessageStartEvent(value) {
|
|
67
67
|
return hasEventType(value, "message_start") && "message" in value;
|
|
68
68
|
}
|
|
69
|
+
export function isMessageUpdateEvent(value) {
|
|
70
|
+
return (hasEventType(value, "message_update") &&
|
|
71
|
+
"message" in value &&
|
|
72
|
+
isRecord(value.assistantMessageEvent) &&
|
|
73
|
+
typeof value.assistantMessageEvent.type === "string");
|
|
74
|
+
}
|
|
69
75
|
export function isMessageEndEvent(value) {
|
|
70
76
|
return hasEventType(value, "message_end") && "message" in value;
|
|
71
77
|
}
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import type { ThinkingLevel } from "@earendil-works/pi-agent-core";
|
|
8
8
|
import type { Api, Model } from "@earendil-works/pi-ai";
|
|
9
|
-
import type { AgentSession, ModelRegistry, SettingsManager as SDKSettingsManager } from "@earendil-works/pi-coding-agent";
|
|
9
|
+
import type { AgentSession, ModelRegistry, ModelRuntime, SettingsManager as SDKSettingsManager } from "@earendil-works/pi-coding-agent";
|
|
10
10
|
import type { PipiclawSettingsManager } from "../../config/settings.js";
|
|
11
11
|
export interface ModelSelectionDeps {
|
|
12
12
|
channelId: string;
|
|
@@ -14,6 +14,7 @@ export interface ModelSelectionDeps {
|
|
|
14
14
|
getSession: () => AgentSession;
|
|
15
15
|
getSessionSettingsManager: () => SDKSettingsManager;
|
|
16
16
|
getModelRegistry: () => ModelRegistry;
|
|
17
|
+
getModelRuntime: () => ModelRuntime;
|
|
17
18
|
}
|
|
18
19
|
export declare class ModelSelection {
|
|
19
20
|
private deps;
|