@oyasmi/pipiclaw 0.9.5 → 0.9.6-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/README.en.md +300 -142
- package/README.md +295 -140
- package/dist/agent/builtin-commands.d.ts +1 -1
- package/dist/agent/builtin-commands.js +1 -1
- package/dist/agent/channel-runner.d.ts +4 -3
- package/dist/agent/channel-runner.js +17 -28
- package/dist/agent/maintenance-context.js +2 -2
- 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 +3 -2
- 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/compaction.d.ts +2 -0
- package/dist/agent/session/compaction.js +22 -14
- 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 +5 -3
- package/dist/agent/session/session-host.js +20 -16
- package/dist/agent/status-render.js +3 -0
- package/dist/agent/stop-watchdog.js +5 -1
- 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 +4 -6
- 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/turn/turn-state.d.ts +2 -0
- package/dist/agent/turn/turn-state.js +2 -1
- package/dist/agent/types.d.ts +23 -3
- 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/attachments.d.ts +4 -0
- package/dist/channel/attachments.js +4 -0
- 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/channel/store.d.ts +1 -1
- package/dist/commands/catalog.js +42 -10
- package/dist/commands/router.js +5 -1
- package/dist/desk/commands.d.ts +44 -5
- package/dist/desk/commands.js +162 -28
- package/dist/desk/paths.d.ts +6 -0
- package/dist/desk/paths.js +21 -1
- package/dist/desk/registry.d.ts +17 -2
- package/dist/desk/registry.js +122 -12
- package/dist/desk/types.d.ts +83 -1
- package/dist/dingtalk/bot.d.ts +1 -1
- package/dist/dingtalk/bot.js +4 -3
- package/dist/dingtalk/config.js +10 -10
- package/dist/dingtalk/delivery.js +15 -8
- package/dist/dingtalk/inbound-media.d.ts +36 -14
- package/dist/dingtalk/inbound-media.js +71 -12
- package/dist/dingtalk/inbound.d.ts +9 -2
- package/dist/dingtalk/inbound.js +17 -2
- package/dist/dingtalk/media.d.ts +4 -10
- package/dist/dingtalk/media.js +58 -32
- package/dist/events/commands.d.ts +2 -0
- package/dist/events/commands.js +13 -8
- package/dist/events/history.d.ts +9 -0
- package/dist/events/history.js +66 -0
- package/dist/events/parse.js +7 -3
- package/dist/events/types.d.ts +3 -0
- package/dist/events/watcher.d.ts +4 -8
- package/dist/events/watcher.js +53 -58
- package/dist/jobs/kill.d.ts +23 -0
- package/dist/jobs/kill.js +65 -0
- package/dist/jobs/manager.d.ts +19 -18
- package/dist/jobs/manager.js +36 -103
- package/dist/main.js +15 -3
- package/dist/memory/boundary-work.d.ts +2 -1
- package/dist/memory/boundary-work.js +1 -1
- package/dist/memory/lifecycle.d.ts +2 -1
- package/dist/memory/lifecycle.js +2 -2
- package/dist/memory/reflect-job.d.ts +2 -1
- package/dist/memory/reflect-job.js +1 -1
- package/dist/memory/reflect.d.ts +2 -1
- package/dist/memory/reflect.js +25 -4
- package/dist/memory/scheduler.d.ts +2 -1
- package/dist/memory/scheduler.js +1 -1
- package/dist/memory/session-corpus.d.ts +1 -1
- package/dist/memory/session-corpus.js +76 -1
- package/dist/memory/session-search.d.ts +2 -1
- package/dist/memory/session-search.js +14 -12
- package/dist/memory/sidecar-worker.d.ts +2 -1
- package/dist/memory/sidecar-worker.js +2 -4
- package/dist/memory/store.d.ts +2 -0
- package/dist/memory/store.js +19 -9
- 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.js +7 -6
- 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 +20 -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 +10 -0
- package/dist/runtime/bootstrap.js +93 -29
- package/dist/runtime/daemon-lock.js +3 -3
- package/dist/runtime/desk-runtime.d.ts +40 -7
- package/dist/runtime/desk-runtime.js +330 -44
- package/dist/runtime/durable-dispatch.d.ts +14 -2
- package/dist/runtime/durable-dispatch.js +207 -65
- package/dist/runtime/ingress-busy.js +17 -8
- package/dist/runtime/ingress-commands.js +24 -4
- package/dist/runtime/ingress-deps.d.ts +4 -1
- package/dist/runtime/ingress.js +6 -1
- package/dist/runtime/request-execution.js +7 -6
- package/dist/runtime/shutdown.d.ts +4 -1
- package/dist/runtime/shutdown.js +88 -35
- package/dist/runtime/task-close.d.ts +1 -1
- package/dist/runtime/task-close.js +6 -3
- package/dist/runtime/task-control.d.ts +2 -3
- package/dist/runtime/task-control.js +38 -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 +2 -0
- package/dist/runtime/task-lane.js +38 -20
- package/dist/runtime/task-step.d.ts +3 -3
- package/dist/runtime/task-step.js +34 -16
- package/dist/runtime/transports.js +6 -5
- package/dist/runtime/turn-run.js +103 -66
- package/dist/security/command-guard.d.ts +1 -1
- package/dist/security/command-guard.js +259 -314
- package/dist/security/path-guard.js +48 -7
- package/dist/security/shell-parse.d.ts +10 -0
- package/dist/security/shell-parse.js +224 -0
- package/dist/security/types.d.ts +2 -0
- package/dist/subagents/commands.d.ts +1 -1
- package/dist/subagents/commands.js +14 -5
- package/dist/subagents/completion-wake.js +6 -0
- package/dist/subagents/detached-discovery.d.ts +1 -1
- package/dist/subagents/discovery.d.ts +18 -199
- package/dist/subagents/discovery.js +35 -289
- package/dist/subagents/dispatch.d.ts +1 -2
- package/dist/subagents/dispatch.js +50 -29
- package/dist/subagents/external/antigravity-cli.d.ts +2 -0
- package/dist/subagents/external/antigravity-cli.js +517 -0
- package/dist/subagents/external/claude-code.js +8 -17
- package/dist/subagents/external/codex-cli.js +8 -18
- package/dist/subagents/external/cursor-cli.js +34 -31
- package/dist/subagents/external/dispatch.d.ts +21 -7
- package/dist/subagents/external/dispatch.js +146 -12
- package/dist/subagents/external/exec.js +3 -0
- package/dist/subagents/external/harness.d.ts +57 -33
- package/dist/subagents/external/harness.js +69 -40
- package/dist/subagents/external/reconciliation.js +1 -0
- package/dist/subagents/external/registry.js +4 -1
- package/dist/subagents/external/role-warnings.d.ts +4 -13
- package/dist/subagents/external/role-warnings.js +4 -28
- package/dist/subagents/external/run.d.ts +1 -2
- package/dist/subagents/external/run.js +16 -26
- package/dist/subagents/external/settlement.d.ts +2 -0
- package/dist/subagents/external/settlement.js +13 -3
- package/dist/subagents/format.d.ts +1 -1
- package/dist/subagents/format.js +1 -1
- package/dist/subagents/internal/outcome.d.ts +1 -2
- package/dist/subagents/internal/outcome.js +19 -12
- package/dist/subagents/internal/provider-retry.d.ts +1 -2
- package/dist/subagents/internal/provider-retry.js +2 -4
- package/dist/subagents/internal/run.d.ts +2 -3
- package/dist/subagents/internal/run.js +27 -4
- package/dist/subagents/internal/state.d.ts +2 -5
- package/dist/subagents/internal/state.js +1 -2
- package/dist/subagents/internal/worker.d.ts +1 -2
- package/dist/subagents/internal/worker.js +20 -10
- package/dist/subagents/resolve.d.ts +56 -0
- package/dist/subagents/resolve.js +202 -0
- package/dist/subagents/result.d.ts +6 -4
- package/dist/subagents/result.js +39 -6
- package/dist/subagents/run-record.d.ts +54 -2
- package/dist/subagents/run-record.js +7 -0
- package/dist/subagents/runs.d.ts +6 -31
- package/dist/subagents/runs.js +26 -31
- package/dist/subagents/task-envelope.d.ts +1 -2
- package/dist/subagents/task-envelope.js +13 -4
- package/dist/subagents/task-settlement.js +1 -0
- package/dist/subagents/types.d.ts +105 -6
- package/dist/subagents/types.js +16 -1
- package/dist/subagents/workspace-lease.d.ts +41 -24
- package/dist/subagents/workspace-lease.js +159 -24
- package/dist/subagents/worktree.d.ts +52 -0
- package/dist/subagents/worktree.js +363 -0
- package/dist/tasks/archive.js +4 -0
- package/dist/tasks/brief.d.ts +5 -1
- package/dist/tasks/brief.js +19 -5
- package/dist/tasks/commands.d.ts +6 -1
- package/dist/tasks/commands.js +32 -7
- package/dist/tasks/control.d.ts +11 -0
- package/dist/tasks/delivery.d.ts +2 -0
- package/dist/tasks/delivery.js +141 -21
- package/dist/tasks/loop-log.d.ts +12 -0
- package/dist/tasks/loop-log.js +10 -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 +29 -15
- package/dist/tools/contract/presentation.js +7 -5
- 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 +2 -1
- package/dist/tools/event-manage.js +46 -39
- 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 +6 -2
- package/dist/tools/index.js +9 -4
- package/dist/tools/job.js +12 -11
- 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 +32 -12
- package/dist/tools/send-media.js +9 -5
- package/dist/tools/session-search.d.ts +2 -1
- package/dist/tools/session-search.js +15 -5
- package/dist/tools/skill.js +13 -12
- package/dist/tools/subagent-manage.d.ts +1 -1
- package/dist/tools/subagent-manage.js +25 -152
- package/dist/tools/subagent.d.ts +24 -2
- package/dist/tools/subagent.js +24 -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 +40 -4
- package/dist/tools/task-manage/lifecycle.d.ts +3 -3
- package/dist/tools/task-manage/lifecycle.js +56 -13
- package/dist/tools/task-manage/schema.d.ts +4 -1
- package/dist/tools/task-manage/schema.js +4 -1
- package/dist/tools/task-manage/shared.d.ts +1 -1
- package/dist/tools/task-manage/types.d.ts +5 -1
- 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 +6 -6
- package/dist/tui/cli.js +120 -28
- package/dist/tui/client.d.ts +7 -0
- package/dist/tui/client.js +67 -16
- 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/usage/ledger.d.ts +1 -1
- package/dist/usage/render.js +1 -1
- package/dist/web/client.d.ts +1 -0
- package/dist/web/client.js +11 -0
- package/dist/web/fetch.js +6 -3
- 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 +43 -75
- 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 +11 -12
- package/dist/agent/session/request-tools.d.ts +0 -3
- package/dist/agent/session/request-tools.js +0 -20
- 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/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
- package/examples/sub-agents/agents/scout.md +0 -30
- package/examples/sub-agents/roles/builder-hard.md +0 -34
- package/examples/sub-agents/roles/builder.md +0 -34
- package/examples/sub-agents/roles/explorer.md +0 -39
- package/examples/sub-agents/roles/git-committer.md +0 -43
- package/examples/sub-agents/roles/planner.md +0 -33
- package/examples/sub-agents/roles/reviewer.md +0 -33
- package/examples/sub-agents/roles/verifier.md +0 -35
- package/examples/sub-agents/roles/worker.md +0 -34
|
@@ -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";
|
|
@@ -63,7 +61,7 @@ export class ChannelRunner {
|
|
|
63
61
|
const initialSkills = loadPipiclawSkills({
|
|
64
62
|
workspaceDir: this.workspaceDir,
|
|
65
63
|
securityConfig: this.loadSecurityConfig().config,
|
|
66
|
-
securityContext: { agentWorkspaceDir: this.workspaceDir, cwd: conversation.cwd },
|
|
64
|
+
securityContext: { agentWorkspaceDir: this.workspaceDir, cwd: conversation.cwd, appHomeDir: this.appHomeDir },
|
|
67
65
|
});
|
|
68
66
|
// Create session manager, opening whichever session this conversation's active-session ref
|
|
69
67
|
// (or the context.jsonl default, for a conversation that has never run a topology op) names
|
|
@@ -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,10 @@ 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
|
+
},
|
|
123
125
|
recordMemoryActivity: (event) => this.recordMemoryActivity(event),
|
|
124
126
|
});
|
|
125
127
|
this.host = new SessionHost({
|
|
@@ -209,7 +211,7 @@ export class ChannelRunner {
|
|
|
209
211
|
getTurnStatus() {
|
|
210
212
|
return this.turnState.status();
|
|
211
213
|
}
|
|
212
|
-
async run(info, channel, store) {
|
|
214
|
+
async run(info, channel, store, taskContract) {
|
|
213
215
|
const startedAt = Date.now();
|
|
214
216
|
const ctx = new TurnOutput(channel, this.channelId);
|
|
215
217
|
this.resetRunState(info, ctx, store);
|
|
@@ -238,28 +240,9 @@ export class ChannelRunner {
|
|
|
238
240
|
if (this.profile.kind === "chat")
|
|
239
241
|
await mkdir(this.conversationDir, { recursive: true });
|
|
240
242
|
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.
|
|
243
|
+
// Count supported images in the compaction budget. Fallback rechecks image support.
|
|
255
244
|
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;
|
|
245
|
+
this.lastTurnContextStats = await this.pipeline.preparePrompt(input, turn, channelCapsule, taskContract);
|
|
263
246
|
turn.fallbackAttempted = await runPromptWithFallback(turn.promptText, this.pipeline.buildFallbackDeps(info, ctx, turn, ownTurn));
|
|
264
247
|
}
|
|
265
248
|
catch (err) {
|
|
@@ -384,7 +367,7 @@ export class ChannelRunner {
|
|
|
384
367
|
messages: () => [...this.session.messages],
|
|
385
368
|
sessionEntries: () => [...this.sessionManager.getBranch()],
|
|
386
369
|
model: this.session.model ?? this.models.activeModel,
|
|
387
|
-
|
|
370
|
+
modelRequests: this.host.modelRequests,
|
|
388
371
|
settings: { memoryMaintenance: this.settingsManager.getMemoryMaintenanceSettings() },
|
|
389
372
|
};
|
|
390
373
|
}
|
|
@@ -393,9 +376,13 @@ export class ChannelRunner {
|
|
|
393
376
|
if (!this.host.sessionInitialized)
|
|
394
377
|
return undefined;
|
|
395
378
|
const model = this.session.model ?? this.models.activeModel;
|
|
379
|
+
const availableModels = this.host.modelRegistry.getAvailable();
|
|
380
|
+
const modelConfigured = availableModels.some((candidate) => candidate.provider === model.provider && candidate.id === model.id) ||
|
|
381
|
+
(model.provider === "anthropic" && Boolean(process.env.ANTHROPIC_API_KEY?.trim()));
|
|
396
382
|
const contextTokens = this.session.getContextUsage()?.tokens;
|
|
397
383
|
return {
|
|
398
384
|
model: formatModelReference(model),
|
|
385
|
+
modelConfigured,
|
|
399
386
|
contextTokens: typeof contextTokens === "number" ? contextTokens : undefined,
|
|
400
387
|
contextWindow: model.contextWindow || 200000,
|
|
401
388
|
thinkingLevel: this.session.thinkingLevel,
|
|
@@ -435,7 +422,8 @@ export class ChannelRunner {
|
|
|
435
422
|
* breakdown of the system prompt, the tool schemas (billed on top of it, and
|
|
436
423
|
* often the larger half), and the last turn's dynamic context.
|
|
437
424
|
*/
|
|
438
|
-
renderContextReport(args = "") {
|
|
425
|
+
async renderContextReport(args = "") {
|
|
426
|
+
await this.host.ensureSessionReady();
|
|
439
427
|
const build = this.host.lastPromptBuild ?? this.host.buildSystemPrompt();
|
|
440
428
|
return renderContextReport({
|
|
441
429
|
build,
|
|
@@ -446,6 +434,7 @@ export class ChannelRunner {
|
|
|
446
434
|
soul: this.host.lastWorkspaceResources?.soul,
|
|
447
435
|
agents: this.host.lastWorkspaceResources?.agents,
|
|
448
436
|
lastTurn: this.lastTurnContextStats,
|
|
437
|
+
sessionUsage: this.session.getSessionStats().tokens,
|
|
449
438
|
detail: args.trim().toLowerCase() === "detail",
|
|
450
439
|
});
|
|
451
440
|
}
|
|
@@ -3,7 +3,7 @@ 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 {
|
|
6
|
+
import { createModelRequests } from "../models/requests.js";
|
|
7
7
|
import { createModelRuntime, resolveInitialModel, wrapModelRegistry } from "../models/runtime.js";
|
|
8
8
|
/** /new's local persistence path: no runner, credentials, inference, or memory queue. */
|
|
9
9
|
export async function preserveMemoryBeforeNewSession(conversation) {
|
|
@@ -77,7 +77,7 @@ export async function loadDetachedMaintenanceContext(options) {
|
|
|
77
77
|
messages: () => [...cachedTranscript.messages],
|
|
78
78
|
sessionEntries: () => [...cachedTranscript.sessionEntries],
|
|
79
79
|
model,
|
|
80
|
-
|
|
80
|
+
modelRequests: createModelRequests(modelRuntime),
|
|
81
81
|
settings: { memoryMaintenance: options.settingsManager.getMemoryMaintenanceSettings() },
|
|
82
82
|
};
|
|
83
83
|
}
|
|
@@ -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
|
*/
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
* fingerprinted.
|
|
10
10
|
*/
|
|
11
11
|
import type { RuntimePlaybookMetadata } from "../../playbooks/catalog.js";
|
|
12
|
+
import type { RunHarness } from "../../subagents/run-record.js";
|
|
12
13
|
/**
|
|
13
14
|
* How much authority a section's content carries.
|
|
14
15
|
* - `runtime-hard`: boundaries workspace content may not redefine (still enforced by guards/state machines, not by prose).
|
|
@@ -41,7 +42,7 @@ export interface SubAgentSummary {
|
|
|
41
42
|
description: string;
|
|
42
43
|
/** Defaults to "internal"; drives the D11 directory grouping (runtime · workload · mutates). */
|
|
43
44
|
runtime: "internal" | "external";
|
|
44
|
-
harness?:
|
|
45
|
+
harness?: RunHarness;
|
|
45
46
|
/** Always resolved (D11 default: external→heavy, internal→light) — never undefined here. */
|
|
46
47
|
workload: "light" | "heavy";
|
|
47
48
|
/** Resolved for internal (inferred from tools) and required for external; undefined only for a malformed record. */
|
|
@@ -107,7 +108,7 @@ export interface PromptDiagnostic {
|
|
|
107
108
|
message: string;
|
|
108
109
|
}
|
|
109
110
|
export interface PromptBuildResult {
|
|
110
|
-
/** 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. */
|
|
111
112
|
text: string;
|
|
112
113
|
/** Short final footer, injected after pi's tail so late workspace content cannot end the prompt. */
|
|
113
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);
|
|
@@ -5,6 +5,7 @@ interface CompactionOptions extends CompactionSummaryOptions {
|
|
|
5
5
|
getSession: () => AgentSession;
|
|
6
6
|
getRunState: () => RunState;
|
|
7
7
|
isEnabled?: () => boolean;
|
|
8
|
+
isTaskSession?: boolean;
|
|
8
9
|
onAdopt?: () => void;
|
|
9
10
|
onPersistenceFault?: (session: AgentSession, error: unknown) => Error;
|
|
10
11
|
}
|
|
@@ -22,6 +23,7 @@ export declare class SessionCompaction {
|
|
|
22
23
|
private enabled;
|
|
23
24
|
/** A pending candidate never blocks while the complete next input has safe budget. */
|
|
24
25
|
beforePrompt(incoming: number): Promise<void>;
|
|
26
|
+
private contextFullMessage;
|
|
25
27
|
private start;
|
|
26
28
|
private ready;
|
|
27
29
|
/** Synchronous commit at idle or after all results of a tool batch are persisted. */
|
|
@@ -8,6 +8,7 @@ import { captureCompaction, compactionBudget, compactionGain, estimateContext, s
|
|
|
8
8
|
import { CompactionSummary } from "./compaction-summary.js";
|
|
9
9
|
const FAILURE_COOLDOWN_MS = 30_000;
|
|
10
10
|
const CONTEXT_FULL = "会话上下文空间不足,自动压缩暂未完成。请用 /compact 重试,或用 /new 开新会话。";
|
|
11
|
+
const TASK_CONTEXT_FULL = "任务会话上下文空间不足,自动压缩暂未完成;当前步骤将重试,请把大段中间产物写入文件再引用。";
|
|
11
12
|
export class SessionCompaction {
|
|
12
13
|
constructor(options) {
|
|
13
14
|
this.options = options;
|
|
@@ -55,11 +56,14 @@ export class SessionCompaction {
|
|
|
55
56
|
if (candidate)
|
|
56
57
|
await this.wait(candidate);
|
|
57
58
|
if (session !== this.options.getSession() || this.retired || candidate?.controller.signal.aborted)
|
|
58
|
-
throw new Error(
|
|
59
|
+
throw new Error(this.contextFullMessage());
|
|
59
60
|
this.adopt();
|
|
60
61
|
budget = compactionBudget(session, incoming);
|
|
61
62
|
if (budget.projected >= budget.hard)
|
|
62
|
-
throw new Error(
|
|
63
|
+
throw new Error(this.contextFullMessage());
|
|
64
|
+
}
|
|
65
|
+
contextFullMessage() {
|
|
66
|
+
return this.options.isTaskSession ? TASK_CONTEXT_FULL : CONTEXT_FULL;
|
|
63
67
|
}
|
|
64
68
|
start() {
|
|
65
69
|
if (this.candidate || !this.canPrevent() || !this.enabled())
|
|
@@ -186,7 +190,7 @@ export class SessionCompaction {
|
|
|
186
190
|
this.adopt();
|
|
187
191
|
budget = compactionBudget(this.options.getSession());
|
|
188
192
|
if (budget.projected >= budget.hard)
|
|
189
|
-
throw new Error(
|
|
193
|
+
throw new Error(this.contextFullMessage());
|
|
190
194
|
}
|
|
191
195
|
catch (error) {
|
|
192
196
|
this.failure(error);
|
|
@@ -263,20 +267,24 @@ export class SessionCompaction {
|
|
|
263
267
|
channelId: this.options.conversation.channelId,
|
|
264
268
|
reason: errorMessage(error),
|
|
265
269
|
});
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
270
|
+
if (!this.options.isTaskSession) {
|
|
271
|
+
state.ctx?.emit({
|
|
272
|
+
type: "commentary",
|
|
273
|
+
level: "notice",
|
|
274
|
+
text: "⚠️ 上下文压缩未完成,原会话已保留。可用 `/compact` 重试,或用 `/new` 开新会话。",
|
|
275
|
+
});
|
|
276
|
+
}
|
|
271
277
|
}
|
|
272
278
|
wait(candidate) {
|
|
273
279
|
this.record("waiting", candidate);
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
+
if (!this.options.isTaskSession) {
|
|
281
|
+
const state = this.options.getRunState();
|
|
282
|
+
state.ctx?.emit({
|
|
283
|
+
type: "commentary",
|
|
284
|
+
level: "notice",
|
|
285
|
+
text: "⏳ 正在整理上下文,可用 `/stop` 停止当前回合,或用 `/new` 开新会话。",
|
|
286
|
+
});
|
|
287
|
+
}
|
|
280
288
|
return candidate.promise;
|
|
281
289
|
}
|
|
282
290
|
record(state, candidate, fields = {}) {
|
|
@@ -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;
|