@oyasmi/pipiclaw 0.9.3 → 0.9.4-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent/builtin-commands.d.ts +19 -0
- package/dist/agent/builtin-commands.js +80 -0
- package/dist/agent/channel-runner.d.ts +20 -208
- package/dist/agent/channel-runner.js +167 -1188
- package/dist/agent/maintenance-context.d.ts +1 -1
- package/dist/agent/maintenance-context.js +1 -1
- package/dist/agent/prompt/manifest.d.ts +6 -1
- package/dist/agent/prompt/manifest.js +45 -64
- package/dist/agent/prompt/resources.d.ts +3 -0
- package/dist/agent/prompt/resources.js +11 -2
- package/dist/agent/runner-factory.d.ts +1 -43
- package/dist/agent/{command-extension.d.ts → session/command-extension.d.ts} +4 -0
- package/dist/agent/{command-extension.js → session/command-extension.js} +48 -35
- package/dist/agent/{type-guards.d.ts → session/event-guards.d.ts} +2 -2
- package/dist/agent/{type-guards.js → session/event-guards.js} +5 -1
- package/dist/agent/session/model-selection.d.ts +47 -0
- package/dist/agent/session/model-selection.js +99 -0
- package/dist/agent/{session-adapter.d.ts → session/session-adapter.d.ts} +21 -1
- package/dist/agent/session/session-adapter.js +159 -0
- package/dist/agent/{session-events.d.ts → session/session-events.d.ts} +9 -5
- package/dist/agent/{session-events.js → session/session-events.js} +24 -13
- package/dist/agent/session/session-host.d.ts +200 -0
- package/dist/agent/session/session-host.js +621 -0
- package/dist/agent/{session-resource-gate.js → session/session-resource-gate.js} +5 -3
- package/dist/agent/status-render.d.ts +0 -1
- package/dist/agent/status-render.js +4 -16
- package/dist/agent/{context-budget.js → turn/context-budget.js} +5 -1
- package/dist/agent/{progress-formatter.d.ts → turn/progress-formatter.d.ts} +4 -1
- package/dist/agent/{run-queue.d.ts → turn/run-queue.d.ts} +1 -1
- package/dist/agent/{run-queue.js → turn/run-queue.js} +10 -5
- package/dist/{memory → agent/turn}/task-digest.js +4 -4
- package/dist/agent/turn/turn-context.d.ts +14 -0
- package/dist/agent/turn/turn-context.js +64 -0
- package/dist/agent/turn/turn-error.d.ts +31 -0
- package/dist/agent/turn/turn-error.js +68 -0
- package/dist/agent/turn/turn-finish.d.ts +50 -0
- package/dist/agent/turn/turn-finish.js +188 -0
- package/dist/agent/turn/turn-input.d.ts +43 -0
- package/dist/agent/turn/turn-input.js +79 -0
- package/dist/agent/turn/turn-pipeline.d.ts +68 -0
- package/dist/agent/turn/turn-pipeline.js +257 -0
- package/dist/agent/{turn-prompt.d.ts → turn/turn-prompt.d.ts} +2 -2
- package/dist/agent/{turn-prompt.js → turn/turn-prompt.js} +6 -2
- package/dist/agent/{turn-recovery.js → turn/turn-recovery.js} +1 -1
- package/dist/agent/{turn-state.d.ts → turn/turn-state.d.ts} +1 -1
- package/dist/agent/types.d.ts +43 -2
- package/dist/agent/types.js +1 -1
- package/dist/{models/auth-cli.d.ts → app/auth-command.d.ts} +1 -1
- package/dist/{models/auth-cli.js → app/auth-command.js} +14 -10
- package/dist/{runtime/app-home.d.ts → app/home.d.ts} +6 -2
- package/dist/{runtime/app-home.js → app/home.js} +22 -75
- package/dist/{runtime → app}/proxy.js +4 -2
- package/dist/{app-services.d.ts → app/services.d.ts} +5 -5
- package/dist/{app-services.js → app/services.js} +17 -14
- package/dist/channel/channel-context.d.ts +12 -2
- package/dist/channel/channel-context.js +29 -2
- package/dist/channel/channel-event.d.ts +10 -2
- package/dist/channel/channel-event.js +1 -1
- package/dist/channel/channel-index.js +4 -1
- package/dist/{runtime/project-commands.d.ts → channel/commands.d.ts} +1 -1
- package/dist/{runtime/project-commands.js → channel/commands.js} +17 -16
- package/dist/channel/project-scope-store.js +1 -1
- package/dist/channel/store.js +4 -0
- package/dist/commands/catalog.d.ts +24 -7
- package/dist/commands/catalog.js +91 -44
- package/dist/commands/reply-limits.d.ts +6 -0
- package/dist/commands/reply-limits.js +24 -0
- package/dist/{runtime/report-commands.d.ts → commands/router.d.ts} +10 -3
- package/dist/{runtime/report-commands.js → commands/router.js} +6 -6
- package/dist/{settings.d.ts → config/settings.d.ts} +10 -10
- package/dist/{settings.js → config/settings.js} +11 -11
- package/dist/{tools/config.d.ts → config/tools.d.ts} +1 -2
- package/dist/{tools/config.js → config/tools.js} +5 -2
- package/dist/dingtalk/access-token.d.ts +12 -0
- package/dist/dingtalk/access-token.js +51 -0
- package/dist/dingtalk/api.d.ts +19 -0
- package/dist/dingtalk/api.js +67 -0
- package/dist/dingtalk/bot.d.ts +97 -0
- package/dist/dingtalk/bot.js +389 -0
- package/dist/dingtalk/cards.d.ts +56 -0
- package/dist/dingtalk/cards.js +318 -0
- package/dist/{runtime → dingtalk}/channel-queue.js +4 -1
- package/dist/dingtalk/config.d.ts +19 -0
- package/dist/dingtalk/config.js +95 -0
- package/dist/dingtalk/connection.d.ts +57 -0
- package/dist/dingtalk/connection.js +356 -0
- package/dist/dingtalk/conversation-meta.d.ts +16 -0
- package/dist/dingtalk/conversation-meta.js +77 -0
- package/dist/{runtime → dingtalk}/delivery.d.ts +6 -2
- package/dist/{runtime → dingtalk}/delivery.js +29 -15
- package/dist/dingtalk/handler.d.ts +90 -0
- package/dist/dingtalk/handler.js +1 -0
- package/dist/dingtalk/inbound.d.ts +66 -0
- package/dist/dingtalk/inbound.js +137 -0
- package/dist/dingtalk/media.d.ts +66 -0
- package/dist/dingtalk/media.js +214 -0
- package/dist/events/{event-commands.js → commands.js} +99 -45
- package/dist/events/parse.d.ts +14 -0
- package/dist/events/parse.js +114 -0
- package/dist/events/types.d.ts +93 -0
- package/dist/events/types.js +1 -0
- package/dist/events/{event-validation.d.ts → validation.d.ts} +14 -3
- package/dist/events/{event-validation.js → validation.js} +17 -9
- package/dist/events/watcher.d.ts +67 -0
- package/dist/events/{events.js → watcher.js} +63 -121
- package/dist/executor.js +2 -2
- package/dist/index.d.ts +6 -4
- package/dist/index.js +2 -2
- package/dist/jobs/launch.d.ts +42 -0
- package/dist/jobs/launch.js +118 -0
- package/dist/{agent/job-manager.d.ts → jobs/manager.d.ts} +1 -67
- package/dist/{agent/job-manager.js → jobs/manager.js} +34 -157
- package/dist/jobs/record.d.ts +55 -0
- package/dist/jobs/record.js +36 -0
- package/dist/log.d.ts +12 -2
- package/dist/log.js +26 -34
- package/dist/main.js +3 -3
- package/dist/memory/commands.js +29 -23
- package/dist/memory/lifecycle.js +26 -5
- package/dist/memory/maintenance-gates.d.ts +2 -2
- package/dist/memory/maintenance-state.js +4 -1
- package/dist/memory/maintenance-tuning.d.ts +15 -0
- package/dist/memory/maintenance-tuning.js +3 -0
- package/dist/memory/reflect-job.d.ts +2 -2
- package/dist/memory/reflect-job.js +4 -2
- package/dist/memory/scheduler.d.ts +3 -3
- package/dist/memory/scheduler.js +5 -2
- package/dist/memory/sidecar-worker.js +1 -1
- package/dist/memory/transcript.js +1 -1
- package/dist/{agent/model-fallback.d.ts → models/fallback.d.ts} +6 -6
- package/dist/{agent/model-fallback.js → models/fallback.js} +15 -28
- package/dist/models/login-identity.d.ts +2 -0
- package/dist/models/login-identity.js +83 -0
- package/dist/models/provider-login.d.ts +3 -1
- package/dist/models/provider-login.js +8 -2
- package/dist/models/reference.d.ts +20 -0
- package/dist/models/{utils.js → reference.js} +0 -48
- package/dist/models/{utils.d.ts → runtime.d.ts} +1 -16
- package/dist/models/runtime.js +52 -0
- package/dist/paths.d.ts +2 -0
- package/dist/paths.js +9 -0
- package/dist/playbooks/agent-delegation.md +2 -2
- package/dist/playbooks/catalog.d.ts +6 -2
- package/dist/playbooks/catalog.js +9 -6
- package/dist/runtime/bootstrap.d.ts +7 -17
- package/dist/runtime/bootstrap.js +70 -659
- package/dist/runtime/durable-dispatch.d.ts +43 -4
- package/dist/runtime/durable-dispatch.js +153 -3
- package/dist/runtime/inbound-images.d.ts +18 -0
- package/dist/runtime/inbound-images.js +51 -0
- package/dist/runtime/shutdown.d.ts +39 -0
- package/dist/runtime/shutdown.js +120 -0
- package/dist/runtime/stop-watchdog.d.ts +16 -0
- package/dist/runtime/stop-watchdog.js +32 -0
- package/dist/runtime/task-driver.d.ts +6 -4
- package/dist/runtime/task-driver.js +58 -23
- package/dist/runtime/task-migration.js +25 -8
- package/dist/runtime/task-spawn.d.ts +1 -1
- package/dist/runtime/task-spawn.js +13 -6
- package/dist/runtime/turn-handler.d.ts +47 -0
- package/dist/runtime/turn-handler.js +318 -0
- package/dist/runtime/turn-run.d.ts +52 -0
- package/dist/runtime/turn-run.js +318 -0
- package/dist/runtime/wake-coalescing.d.ts +18 -0
- package/dist/runtime/wake-coalescing.js +29 -0
- package/dist/security/block-message.d.ts +22 -1
- package/dist/security/block-message.js +66 -1
- package/dist/security/command-guard.js +4 -0
- package/dist/security/network.d.ts +2 -1
- package/dist/security/network.js +7 -2
- package/dist/security/path-guard-check.js +2 -2
- package/dist/security/path-guard.js +4 -0
- package/dist/security/types.d.ts +1 -2
- package/dist/security/types.js +1 -2
- package/dist/shared/exact-keys.d.ts +1 -1
- package/dist/shared/format.d.ts +12 -0
- package/dist/shared/format.js +37 -0
- package/dist/shared/host-process.js +16 -4
- package/dist/shared/wake-claim.d.ts +1 -1
- package/dist/shared/with-timeout.d.ts +3 -2
- package/dist/shared/with-timeout.js +14 -3
- package/dist/{runtime/skill-commands.d.ts → skills/commands.d.ts} +2 -2
- package/dist/{runtime/skill-commands.js → skills/commands.js} +18 -11
- package/dist/{agent/workspace-resources.js → skills/loader.js} +1 -1
- package/dist/{tools/skill-security.js → skills/validation.js} +4 -0
- package/dist/skills/workspace.d.ts +33 -0
- package/dist/skills/workspace.js +116 -0
- package/dist/{runtime/subagent-commands.d.ts → subagents/commands.d.ts} +9 -7
- package/dist/{runtime/subagent-commands.js → subagents/commands.js} +116 -77
- package/dist/subagents/completion-wake.d.ts +17 -0
- package/dist/subagents/completion-wake.js +76 -0
- package/dist/subagents/detached-discovery.js +1 -1
- package/dist/subagents/discovery.d.ts +1 -1
- package/dist/subagents/discovery.js +2 -2
- package/dist/subagents/dispatch.d.ts +33 -0
- package/dist/subagents/dispatch.js +190 -0
- package/dist/subagents/external/claude-code.js +23 -1
- package/dist/subagents/external/dispatch.d.ts +25 -0
- package/dist/subagents/external/dispatch.js +90 -0
- package/dist/subagents/external/harness.d.ts +1 -1
- package/dist/subagents/external/progress-tail.d.ts +18 -1
- package/dist/subagents/external/progress-tail.js +64 -17
- package/dist/subagents/external/run.d.ts +5 -1
- package/dist/subagents/external/run.js +23 -9
- package/dist/subagents/external/settlement.d.ts +4 -1
- package/dist/subagents/external/settlement.js +1 -1
- package/dist/subagents/format.d.ts +1 -1
- package/dist/subagents/grace.d.ts +24 -0
- package/dist/subagents/grace.js +57 -0
- package/dist/subagents/internal/outcome.d.ts +24 -0
- package/dist/subagents/internal/outcome.js +149 -0
- package/dist/subagents/internal/provider-retry.d.ts +19 -0
- package/dist/subagents/internal/provider-retry.js +83 -0
- package/dist/subagents/internal/run.d.ts +31 -0
- package/dist/subagents/internal/run.js +240 -0
- package/dist/subagents/internal/state.d.ts +43 -0
- package/dist/subagents/internal/state.js +48 -0
- package/dist/subagents/internal/worker.d.ts +51 -0
- package/dist/subagents/internal/worker.js +167 -0
- package/dist/subagents/result.d.ts +62 -0
- package/dist/subagents/result.js +103 -0
- package/dist/subagents/run-record.d.ts +222 -0
- package/dist/subagents/run-record.js +101 -0
- package/dist/subagents/run-registry.d.ts +9 -0
- package/dist/subagents/run-registry.js +125 -0
- package/dist/subagents/runs.d.ts +16 -232
- package/dist/subagents/runs.js +132 -310
- package/dist/subagents/task-envelope.d.ts +36 -0
- package/dist/subagents/task-envelope.js +168 -0
- package/dist/subagents/types.d.ts +154 -0
- package/dist/subagents/types.js +1 -0
- package/dist/subagents/verification-outcome.d.ts +1 -1
- package/dist/subagents/workspace-summary.d.ts +16 -4
- package/dist/subagents/workspace-summary.js +74 -18
- package/dist/tasks/board.d.ts +10 -3
- package/dist/tasks/board.js +38 -3
- package/dist/tasks/{work-log.d.ts → bound-work.d.ts} +1 -1
- package/dist/tasks/{work-log.js → bound-work.js} +1 -1
- package/dist/tasks/brief.js +1 -1
- package/dist/{runtime/task-commands.d.ts → tasks/commands.d.ts} +1 -1
- package/dist/{runtime/task-commands.js → tasks/commands.js} +117 -67
- package/dist/tasks/contract-input.d.ts +1 -1
- package/dist/tasks/contract-input.js +1 -1
- package/dist/tasks/create.js +1 -1
- package/dist/tasks/frontmatter.d.ts +5 -0
- package/dist/tasks/frontmatter.js +8 -0
- package/dist/tasks/{log.d.ts → loop-log.d.ts} +11 -1
- package/dist/tasks/{log.js → loop-log.js} +59 -3
- package/dist/tasks/mutation-lock.js +1 -1
- package/dist/tasks/session-path.js +1 -1
- package/dist/tasks/steer.js +1 -1
- package/dist/tasks/store.js +6 -4
- package/dist/tasks/ticket.d.ts +3 -1
- package/dist/tasks/ticket.js +19 -1
- package/dist/tools/bash.d.ts +1 -1
- package/dist/tools/bash.js +2 -2
- package/dist/tools/{tool-details.d.ts → contract/details.d.ts} +11 -3
- package/dist/tools/{tool-details.js → contract/details.js} +42 -5
- package/dist/tools/{presentation.js → contract/presentation.js} +3 -3
- package/dist/tools/event-manage.d.ts +1 -1
- package/dist/tools/event-manage.js +4 -4
- package/dist/tools/index.d.ts +5 -3
- package/dist/tools/index.js +8 -6
- package/dist/tools/job.d.ts +1 -1
- package/dist/tools/memory-manage.js +4 -1
- package/dist/tools/registry.d.ts +7 -7
- package/dist/tools/registry.js +6 -6
- package/dist/tools/session-search.d.ts +1 -1
- package/dist/tools/skill.d.ts +2 -34
- package/dist/tools/skill.js +8 -116
- package/dist/tools/subagent-manage.d.ts +1 -1
- package/dist/tools/subagent-manage.js +19 -13
- package/dist/tools/subagent.d.ts +46 -0
- package/dist/tools/subagent.js +127 -0
- package/dist/tools/{task-manage.d.ts → task-manage/factory.d.ts} +7 -3
- package/dist/tools/{task-manage.js → task-manage/factory.js} +7 -7
- package/dist/tools/task-manage/lifecycle.js +2 -2
- package/dist/tools/task-manage/log-view.js +2 -2
- package/dist/tools/task-manage/shared.js +3 -3
- package/dist/tools/task-manage/step-end.js +7 -4
- package/dist/tools/task-manage/types.d.ts +1 -1
- package/dist/tools/web-fetch.d.ts +1 -1
- package/dist/tools/web-search.d.ts +1 -1
- package/dist/tui/app.d.ts +1 -1
- package/dist/tui/app.js +6 -6
- package/dist/tui/cli.d.ts +1 -1
- package/dist/tui/cli.js +3 -3
- package/dist/tui/commands.js +4 -4
- package/dist/tui/frontend.d.ts +44 -0
- package/dist/tui/frontend.js +13 -0
- package/dist/tui/pitui-frontend.d.ts +1 -1
- package/dist/tui/pitui-frontend.js +1 -1
- package/dist/tui/plain-frontend.d.ts +1 -1
- package/dist/tui/renderer.d.ts +3 -42
- package/dist/tui/renderer.js +3 -2
- package/dist/tui/terminal-context.d.ts +2 -2
- package/dist/tui/terminal-media-sender.d.ts +1 -1
- package/dist/tui/turn-controller.d.ts +3 -1
- package/dist/tui/turn-controller.js +36 -21
- package/dist/usage/ledger.js +7 -1
- package/dist/usage/render.js +3 -1
- package/dist/{shared/types.d.ts → usage/totals.d.ts} +3 -0
- package/dist/web/client.d.ts +5 -1
- package/dist/web/client.js +4 -0
- package/dist/web/config.d.ts +1 -1
- package/dist/web/fetch.d.ts +1 -1
- package/dist/web/search-providers.d.ts +1 -1
- package/dist/web/search.d.ts +1 -1
- package/package.json +9 -7
- package/dist/agent/session-adapter.js +0 -77
- package/dist/events/events.d.ts +0 -159
- package/dist/runtime/dingtalk.d.ts +0 -272
- package/dist/runtime/dingtalk.js +0 -1416
- package/dist/subagents/tool.d.ts +0 -206
- package/dist/subagents/tool.js +0 -1088
- /package/dist/{runtime → agent/prompt}/workspace-templates.d.ts +0 -0
- /package/dist/{runtime → agent/prompt}/workspace-templates.js +0 -0
- /package/dist/agent/{session-resource-gate.d.ts → session/session-resource-gate.d.ts} +0 -0
- /package/dist/agent/{context-budget.d.ts → turn/context-budget.d.ts} +0 -0
- /package/dist/agent/{progress-formatter.js → turn/progress-formatter.js} +0 -0
- /package/dist/{memory → agent/turn}/task-digest.d.ts +0 -0
- /package/dist/agent/{turn-recovery.d.ts → turn/turn-recovery.d.ts} +0 -0
- /package/dist/agent/{turn-state.js → turn/turn-state.js} +0 -0
- /package/dist/{runtime → app}/proxy.d.ts +0 -0
- /package/dist/{runtime → dingtalk}/channel-queue.d.ts +0 -0
- /package/dist/{runtime → dingtalk}/inbound-media.d.ts +0 -0
- /package/dist/{runtime → dingtalk}/inbound-media.js +0 -0
- /package/dist/events/{event-commands.d.ts → commands.d.ts} +0 -0
- /package/dist/{agent/workspace-resources.d.ts → skills/loader.d.ts} +0 -0
- /package/dist/{tools/skill-security.d.ts → skills/validation.d.ts} +0 -0
- /package/dist/tasks/{ledger.d.ts → contract.d.ts} +0 -0
- /package/dist/tasks/{ledger.js → contract.js} +0 -0
- /package/dist/tools/{subagent-tool-names.d.ts → contract/names.d.ts} +0 -0
- /package/dist/tools/{subagent-tool-names.js → contract/names.js} +0 -0
- /package/dist/tools/{presentation.d.ts → contract/presentation.d.ts} +0 -0
- /package/dist/{shared/types.js → usage/totals.js} +0 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { ResolvedSubAgentConfig, SubAgentConfig } from "./discovery.js";
|
|
2
|
+
import type { SubAgentRunContext, SubAgentToolOptions } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* `buildContextualBlocks` shared by the external dispatch path and `runToCompletion`'s internal
|
|
5
|
+
* one (spec 040 gap closed post-review): context injection is an enhancement, not a
|
|
6
|
+
* precondition, so a failure here degrades to no context blocks rather than failing a dispatch
|
|
7
|
+
* that would otherwise have run fine.
|
|
8
|
+
*/
|
|
9
|
+
export declare function resolveContextualBlocks(config: ResolvedSubAgentConfig, options: SubAgentToolOptions): Promise<string[]>;
|
|
10
|
+
/**
|
|
11
|
+
* Shared by both runtimes' task envelopes and `subagent_run`'s verify follow-up (spec 040, D9).
|
|
12
|
+
* A check bound to a Work Item covers that item only: holding it to the whole DoD would fail it
|
|
13
|
+
* for the items still in progress.
|
|
14
|
+
*/
|
|
15
|
+
export declare function buildVerificationProtocol(taskPath: string | undefined, item?: string): string;
|
|
16
|
+
/**
|
|
17
|
+
* D9 verify admission — `exec` has no protocol terminal to prove it even ran to completion, and a
|
|
18
|
+
* target with an active write lease is refused up front. A write-capable verifier is allowed: it
|
|
19
|
+
* takes the same exclusive lease as a work writer.
|
|
20
|
+
* Spec 042 D7: exported so `subagent_run op=follow_up` runs the exact same checks the initial
|
|
21
|
+
* dispatch does, including the remaining `exec` restriction.
|
|
22
|
+
*/
|
|
23
|
+
export declare function assertVerifyAdmissible(config: Pick<ResolvedSubAgentConfig, "name" | "mutates" | "runtime" | "harness">, purpose: "work" | "verify", workingDirectory: string): void;
|
|
24
|
+
/**
|
|
25
|
+
* The task envelope both runtimes' first dispatch sends (a follow-up sends `buildFollowUpTask`
|
|
26
|
+
* instead). `config` is narrowed to `{ name }` — the only field this function reads.
|
|
27
|
+
*/
|
|
28
|
+
export declare function buildSubAgentTask(task: string, config: Pick<SubAgentConfig, "name">, runtimeContext: SubAgentToolOptions["runtimeContext"], contextBlocks: string[], runContext: SubAgentRunContext): string;
|
|
29
|
+
/**
|
|
30
|
+
* The envelope for `subagent_run op=follow_up`. A resumed session already holds the first
|
|
31
|
+
* dispatch's whole envelope — runtime paths, injected memory/context blocks, the role — so sending
|
|
32
|
+
* it again only re-bills that context and buries the new instruction. Only what is new goes: the
|
|
33
|
+
* artifact directory (fresh per run) and the instruction itself, plus the checker protocol again
|
|
34
|
+
* for a verify run, since its final VERDICT line is what settlement reads.
|
|
35
|
+
*/
|
|
36
|
+
export declare function buildFollowUpTask(task: string, runtimeContext: SubAgentToolOptions["runtimeContext"], runContext: SubAgentRunContext): string;
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The task envelope a delegation sends: runtime paths, injected memory/context blocks, the task, and
|
|
3
|
+
* the checker protocol for `purpose=verify`; plus the admission rule for verify runs. Shared by the
|
|
4
|
+
* internal and external runtimes and by `subagent_run op=follow_up` (spec 040 D9, spec 042 D7).
|
|
5
|
+
*/
|
|
6
|
+
import { readFile } from "node:fs/promises";
|
|
7
|
+
import { join } from "node:path";
|
|
8
|
+
import { getChannelDir } from "../channel/channel-paths.js";
|
|
9
|
+
import * as log from "../log.js";
|
|
10
|
+
import { buildChannelIndexForBootstrap, CHANNEL_INDEX_MAX_UNITS, clipJournalTailForBootstrap, clipWorkspaceMemoryForBootstrap, JOURNAL_TAIL_MAX_UNITS, WORKSPACE_MEMORY_MAX_UNITS, } from "../memory/index-budget.js";
|
|
11
|
+
import { readJournalDay } from "../memory/journal.js";
|
|
12
|
+
import { renderMemoryBootstrap } from "../memory/render.js";
|
|
13
|
+
import { listMemoryEntries } from "../memory/store.js";
|
|
14
|
+
import { localDayKey } from "../shared/local-time.js";
|
|
15
|
+
import { RecoverableToolError } from "../shared/recoverable-error.js";
|
|
16
|
+
import { errorMessage } from "../shared/text-utils.js";
|
|
17
|
+
import { findWorkspaceLeaseHolder, formatWorkspaceLeaseConflict } from "./workspace-lease.js";
|
|
18
|
+
/**
|
|
19
|
+
* `buildContextualBlocks` shared by the external dispatch path and `runToCompletion`'s internal
|
|
20
|
+
* one (spec 040 gap closed post-review): context injection is an enhancement, not a
|
|
21
|
+
* precondition, so a failure here degrades to no context blocks rather than failing a dispatch
|
|
22
|
+
* that would otherwise have run fine.
|
|
23
|
+
*/
|
|
24
|
+
export async function resolveContextualBlocks(config, options) {
|
|
25
|
+
return buildContextualBlocks(config, options).catch((error) => {
|
|
26
|
+
log.logWarn("subagent.context.inject_failed", "Sub-agent context injection failed; continuing without it", {
|
|
27
|
+
channelId: options.runtimeContext.channelId,
|
|
28
|
+
reason: errorMessage(error),
|
|
29
|
+
});
|
|
30
|
+
return [];
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Shared by both runtimes' task envelopes and `subagent_run`'s verify follow-up (spec 040, D9).
|
|
35
|
+
* A check bound to a Work Item covers that item only: holding it to the whole DoD would fail it
|
|
36
|
+
* for the items still in progress.
|
|
37
|
+
*/
|
|
38
|
+
export function buildVerificationProtocol(taskPath, item) {
|
|
39
|
+
const scope = !taskPath
|
|
40
|
+
? "- Independently inspect the work described in the task above and verify it against concrete evidence."
|
|
41
|
+
: item
|
|
42
|
+
? `- Independently inspect Work Item ${item} in ${taskPath} — its text and the DoD items it references (\`→ dod:N\`) — and verify it against concrete evidence. Other Work Items are out of scope; do not fail this check because they are unfinished.`
|
|
43
|
+
: `- Independently inspect ${taskPath} and verify every DoD item against concrete evidence.`;
|
|
44
|
+
return [
|
|
45
|
+
"Verification protocol:",
|
|
46
|
+
scope,
|
|
47
|
+
"- You are the checker, not the maker. Do not modify the implementation or fix failures to make a check pass; report them.",
|
|
48
|
+
"- You may run npm tests/builds and other deterministic checks; keep any generated output out of tracked files and product directories.",
|
|
49
|
+
"- Run deterministic checks when available and distinguish observed evidence from assumptions.",
|
|
50
|
+
"- End the response with exactly one final line: VERDICT: PASS or VERDICT: FAIL.",
|
|
51
|
+
].join("\n");
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* D9 verify admission — `exec` has no protocol terminal to prove it even ran to completion, and a
|
|
55
|
+
* target with an active write lease is refused up front. A write-capable verifier is allowed: it
|
|
56
|
+
* takes the same exclusive lease as a work writer.
|
|
57
|
+
* Spec 042 D7: exported so `subagent_run op=follow_up` runs the exact same checks the initial
|
|
58
|
+
* dispatch does, including the remaining `exec` restriction.
|
|
59
|
+
*/
|
|
60
|
+
export function assertVerifyAdmissible(config, purpose, workingDirectory) {
|
|
61
|
+
if (purpose !== "verify")
|
|
62
|
+
return;
|
|
63
|
+
if (config.runtime === "external" && config.harness === "exec") {
|
|
64
|
+
throw new RecoverableToolError(`Sub-agent "${config.name}" uses the exec harness, which has no protocol terminal and cannot be used for purpose=verify.`);
|
|
65
|
+
}
|
|
66
|
+
const holder = findWorkspaceLeaseHolder(workingDirectory);
|
|
67
|
+
if (holder) {
|
|
68
|
+
throw new RecoverableToolError(`Cannot verify "${workingDirectory}": ${formatWorkspaceLeaseConflict(holder)}`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* The task envelope both runtimes' first dispatch sends (a follow-up sends `buildFollowUpTask`
|
|
73
|
+
* instead). `config` is narrowed to `{ name }` — the only field this function reads.
|
|
74
|
+
*/
|
|
75
|
+
export function buildSubAgentTask(task, config, runtimeContext, contextBlocks, runContext) {
|
|
76
|
+
const taskText = task.trim();
|
|
77
|
+
const lines = [
|
|
78
|
+
`Runtime context:`,
|
|
79
|
+
`- Workspace root: ${runtimeContext.workspaceDir}`,
|
|
80
|
+
`- Channel id: ${runtimeContext.channelId}`,
|
|
81
|
+
`- Channel directory: ${getChannelDir(runtimeContext.workspaceDir, runtimeContext.channelId)}`,
|
|
82
|
+
`- Working directory: ${runContext.workingDirectory}`,
|
|
83
|
+
`- Artifact directory: ${runContext.artifactDir}`,
|
|
84
|
+
`- Your configured role: ${config.name}`,
|
|
85
|
+
];
|
|
86
|
+
for (const block of contextBlocks) {
|
|
87
|
+
if (!block.trim()) {
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
lines.push("", block.trim());
|
|
91
|
+
}
|
|
92
|
+
lines.push("", `Task:`, taskText);
|
|
93
|
+
if (runContext.purpose === "verify") {
|
|
94
|
+
lines.push("", buildVerificationProtocol(verificationTaskPath(runtimeContext, runContext), runContext.item));
|
|
95
|
+
}
|
|
96
|
+
return lines.join("\n");
|
|
97
|
+
}
|
|
98
|
+
function verificationTaskPath(runtimeContext, runContext) {
|
|
99
|
+
return runContext.taskId
|
|
100
|
+
? join(getChannelDir(runtimeContext.workspaceDir, runtimeContext.channelId), "tasks", `${runContext.taskId}.md`)
|
|
101
|
+
: undefined;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* The envelope for `subagent_run op=follow_up`. A resumed session already holds the first
|
|
105
|
+
* dispatch's whole envelope — runtime paths, injected memory/context blocks, the role — so sending
|
|
106
|
+
* it again only re-bills that context and buries the new instruction. Only what is new goes: the
|
|
107
|
+
* artifact directory (fresh per run) and the instruction itself, plus the checker protocol again
|
|
108
|
+
* for a verify run, since its final VERDICT line is what settlement reads.
|
|
109
|
+
*/
|
|
110
|
+
export function buildFollowUpTask(task, runtimeContext, runContext) {
|
|
111
|
+
const lines = [
|
|
112
|
+
"Follow-up in the same session. Your earlier instructions and context still apply unless this changes them.",
|
|
113
|
+
`- Working directory: ${runContext.workingDirectory}`,
|
|
114
|
+
`- Artifact directory for this follow-up: ${runContext.artifactDir}`,
|
|
115
|
+
"",
|
|
116
|
+
"Follow-up instruction:",
|
|
117
|
+
task.trim(),
|
|
118
|
+
];
|
|
119
|
+
if (runContext.purpose === "verify") {
|
|
120
|
+
lines.push("", buildVerificationProtocol(verificationTaskPath(runtimeContext, runContext), runContext.item));
|
|
121
|
+
}
|
|
122
|
+
return lines.join("\n");
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Spec 050, D12: `memory: index` injects the same three sections the main agent's first-turn
|
|
126
|
+
* bootstrap does — workspace MEMORY.md, the channel index, today's journal tail — at half the
|
|
127
|
+
* main agent's budget. No per-call LLM recall: a sub-agent task is short-lived, so there is no
|
|
128
|
+
* "first turn" to bootstrap once and reuse; it gets the same snapshot every dispatch.
|
|
129
|
+
*/
|
|
130
|
+
async function buildContextualBlocks(config, options) {
|
|
131
|
+
if (config.contextMode !== "contextual") {
|
|
132
|
+
return [];
|
|
133
|
+
}
|
|
134
|
+
const blocks = [];
|
|
135
|
+
if (config.paths.length > 0) {
|
|
136
|
+
blocks.push(`Preferred focus paths:\n${config.paths.map((path) => `- ${path}`).join("\n")}`);
|
|
137
|
+
}
|
|
138
|
+
if (config.memory === "none") {
|
|
139
|
+
return blocks;
|
|
140
|
+
}
|
|
141
|
+
const today = localDayKey();
|
|
142
|
+
const readOptionalFile = async (path) => {
|
|
143
|
+
try {
|
|
144
|
+
return await readFile(path, "utf-8");
|
|
145
|
+
}
|
|
146
|
+
catch {
|
|
147
|
+
return "";
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
const [entries, workspaceMemory, journalToday] = await Promise.all([
|
|
151
|
+
listMemoryEntries(options.channelDir).catch(() => []),
|
|
152
|
+
readOptionalFile(join(options.workspaceDir, "MEMORY.md")),
|
|
153
|
+
readJournalDay(options.channelDir, today).catch(() => ""),
|
|
154
|
+
]);
|
|
155
|
+
const index = buildChannelIndexForBootstrap(entries, CHANNEL_INDEX_MAX_UNITS / 2);
|
|
156
|
+
const bootstrap = renderMemoryBootstrap({
|
|
157
|
+
workspaceMemory: clipWorkspaceMemoryForBootstrap(workspaceMemory, WORKSPACE_MEMORY_MAX_UNITS / 2),
|
|
158
|
+
channelIndex: entries.length > 0 ? index.text : "",
|
|
159
|
+
journal: (() => {
|
|
160
|
+
const text = clipJournalTailForBootstrap(journalToday, JOURNAL_TAIL_MAX_UNITS / 2);
|
|
161
|
+
return text ? { date: today, text } : undefined;
|
|
162
|
+
})(),
|
|
163
|
+
});
|
|
164
|
+
if (bootstrap) {
|
|
165
|
+
blocks.push(bootstrap);
|
|
166
|
+
}
|
|
167
|
+
return blocks;
|
|
168
|
+
}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared shapes for delegation dispatch: the options the composition root hands in, the per-run
|
|
3
|
+
* context, the worker surface, and the details payload every dispatch returns. Types only, so the
|
|
4
|
+
* dispatch, envelope, internal and external modules can all import them without forming a cycle.
|
|
5
|
+
*/
|
|
6
|
+
import type { AgentEvent, AgentMessage, AgentState, AgentTool } from "@earendil-works/pi-agent-core";
|
|
7
|
+
import type { Api, Model } from "@earendil-works/pi-ai";
|
|
8
|
+
import type { PipiclawWebToolsConfig } from "../config/tools.js";
|
|
9
|
+
import type { Executor } from "../executor.js";
|
|
10
|
+
import type { FileStore } from "../file-store.js";
|
|
11
|
+
import type { SecurityConfig, SecurityRuntimeContext } from "../security/types.js";
|
|
12
|
+
import type { UsageTotals } from "../usage/totals.js";
|
|
13
|
+
import type { ResolvedInternalSubAgentConfig, SubAgentDiscoveryResult } from "./discovery.js";
|
|
14
|
+
import type { SubAgentRunManager } from "./runs.js";
|
|
15
|
+
/**
|
|
16
|
+
* Fields every delegation dispatch returns as its tool-result details. `kind` is not among them: `withToolDetails`
|
|
17
|
+
* stamps it from the registration name when the tool set is built (see `tools/contract/details.ts`; `tools/subagent.ts` exports the stamped `SubAgentToolDetails`).
|
|
18
|
+
*/
|
|
19
|
+
export interface SubAgentToolFields {
|
|
20
|
+
agent: string;
|
|
21
|
+
source: "predefined" | "inline";
|
|
22
|
+
model: string;
|
|
23
|
+
tools: string[];
|
|
24
|
+
turns: number;
|
|
25
|
+
toolCalls: number;
|
|
26
|
+
durationMs: number;
|
|
27
|
+
failed: boolean;
|
|
28
|
+
failureReason?: string;
|
|
29
|
+
usage: UsageTotals;
|
|
30
|
+
runId: string;
|
|
31
|
+
purpose: "work" | "verify";
|
|
32
|
+
taskId?: string;
|
|
33
|
+
verificationVerdict?: "pass" | "fail";
|
|
34
|
+
/** Always populated (spec 032 D4): the full output is saved to `${artifactDir}/output.md`. */
|
|
35
|
+
artifactDir: string;
|
|
36
|
+
/** True when the reply text was truncated against MAX_SUBAGENT_RESULT_UNITS; the full text is still on disk. */
|
|
37
|
+
resultTruncated: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* True only for the "still running" placeholder returned once the sync grace window elapses
|
|
40
|
+
* (spec 040, D2). The run keeps executing; its eventual result arrives as a completion wake,
|
|
41
|
+
* not as another tool result.
|
|
42
|
+
*/
|
|
43
|
+
dispatched?: boolean;
|
|
44
|
+
}
|
|
45
|
+
/** Exported for `subagent_run op=follow_up` (spec 042 D7), which constructs one of these for
|
|
46
|
+
* its own new run rather than a hand-rolled envelope. */
|
|
47
|
+
export interface SubAgentRunContext {
|
|
48
|
+
runId: string;
|
|
49
|
+
purpose: "work" | "verify";
|
|
50
|
+
taskId?: string;
|
|
51
|
+
item?: string;
|
|
52
|
+
workingDirectory: string;
|
|
53
|
+
artifactDir: string;
|
|
54
|
+
}
|
|
55
|
+
/** The delegation parameters both invocation surfaces share (`task` plus routing). */
|
|
56
|
+
export interface DelegationParams {
|
|
57
|
+
task: string;
|
|
58
|
+
workingDirectory?: string;
|
|
59
|
+
purpose?: "work" | "verify";
|
|
60
|
+
taskId?: string;
|
|
61
|
+
item?: string;
|
|
62
|
+
}
|
|
63
|
+
export interface SubAgentWorker {
|
|
64
|
+
state: {
|
|
65
|
+
messages: AgentMessage[];
|
|
66
|
+
tools: AgentTool<any>[];
|
|
67
|
+
model?: Model<Api>;
|
|
68
|
+
thinkingLevel?: AgentState["thinkingLevel"];
|
|
69
|
+
};
|
|
70
|
+
subscribe(listener: (event: AgentEvent) => void): () => void;
|
|
71
|
+
abort(): void;
|
|
72
|
+
prompt(input: string): Promise<void>;
|
|
73
|
+
/** Resume from the current transcript (last message a user or tool result). Without it a
|
|
74
|
+
* provider error cannot be retried in place, so the run fails as before. */
|
|
75
|
+
continue?(): Promise<void>;
|
|
76
|
+
waitForIdle(): Promise<void>;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Everything the tool registry needs to build one sub-agent's tool set. Declared here, not
|
|
80
|
+
* imported, so `subagents/` never depends on `tools/`: the composition root injects
|
|
81
|
+
* `buildWorkerTools` (spec 054 D9). Structurally a subset of `ToolBuildContext`.
|
|
82
|
+
*/
|
|
83
|
+
export interface WorkerToolRequest {
|
|
84
|
+
executor: Executor;
|
|
85
|
+
fileStore: FileStore;
|
|
86
|
+
securityConfig: SecurityConfig;
|
|
87
|
+
securityContext: SecurityRuntimeContext;
|
|
88
|
+
channelId: string;
|
|
89
|
+
channelDir: string;
|
|
90
|
+
workspaceDir: string;
|
|
91
|
+
webConfig?: PipiclawWebToolsConfig;
|
|
92
|
+
rtkEnabled?: boolean;
|
|
93
|
+
bashDefaultTimeoutSeconds: number;
|
|
94
|
+
}
|
|
95
|
+
/** Builds a sub-agent's scoped tool set from the shared registry; injected by `tools/index.ts`. */
|
|
96
|
+
export type BuildWorkerTools = (request: WorkerToolRequest) => AgentTool<any>[];
|
|
97
|
+
export interface SubAgentToolOptions {
|
|
98
|
+
/** Builds a sub-agent's scoped tool set from the shared registry; injected by `tools/index.ts`. */
|
|
99
|
+
buildWorkerTools: BuildWorkerTools;
|
|
100
|
+
executor: Executor;
|
|
101
|
+
fileStore: FileStore;
|
|
102
|
+
/** Host checkout used as the sub-agent's cwd. Defaults to process.cwd(). */
|
|
103
|
+
workingDirectory?: string;
|
|
104
|
+
/** Mirrors the parent channel's ProjectScope.boundary onto the sub-agent's own tool set (spec 043, D6.2). */
|
|
105
|
+
projectBoundary?: "project" | "unbounded";
|
|
106
|
+
getCurrentModel: () => Model<Api>;
|
|
107
|
+
getAvailableModels: () => Model<Api>[];
|
|
108
|
+
resolveApiKey: (model: Model<Api>) => Promise<string>;
|
|
109
|
+
workspaceDir: string;
|
|
110
|
+
channelDir: string;
|
|
111
|
+
getSubAgentDiscovery?: () => SubAgentDiscoveryResult;
|
|
112
|
+
/** `settings.subagentModel` (spec 032 D5); null/undefined means unset. */
|
|
113
|
+
getSubAgentModelReference?: () => string | null;
|
|
114
|
+
securityConfig?: SecurityConfig;
|
|
115
|
+
webConfig?: PipiclawWebToolsConfig;
|
|
116
|
+
rtkEnabled?: boolean;
|
|
117
|
+
runtimeContext: {
|
|
118
|
+
workspaceDir: string;
|
|
119
|
+
channelId: string;
|
|
120
|
+
};
|
|
121
|
+
createWorker?: (config: {
|
|
122
|
+
subAgent: ResolvedInternalSubAgentConfig;
|
|
123
|
+
apiKey: string;
|
|
124
|
+
tools: AgentTool<any>[];
|
|
125
|
+
}) => SubAgentWorker;
|
|
126
|
+
/** Test seam for failures while constructing the scoped tool set after durable registration. */
|
|
127
|
+
buildTools?: BuildSubagentTools;
|
|
128
|
+
/** Test-only override for the D6 convergence-turn wall clock; defaults to CONVERGENCE_WALL_CLOCK_MS. */
|
|
129
|
+
convergenceWallClockMs?: number;
|
|
130
|
+
/** Test-only override for the D2 sync grace window; defaults to SYNC_GRACE_MS. */
|
|
131
|
+
syncGraceMs?: number;
|
|
132
|
+
/** Test-only override for the transient-error retry backoff base; defaults to RETRY_BASE_DELAY_MS. */
|
|
133
|
+
retryBaseDelayMs?: number;
|
|
134
|
+
/**
|
|
135
|
+
* `settings.fallbackModel`, resolved the way the main agent resolves it (spec 017): `null` when
|
|
136
|
+
* unset, unresolvable or missing a key. An internal run that still fails after its transient
|
|
137
|
+
* retries switches to it once, like the main turn does.
|
|
138
|
+
*/
|
|
139
|
+
resolveFallbackModel?: () => Promise<Model<Api> | null>;
|
|
140
|
+
/** Channel manager owned by the application; also a seam for admission failures. */
|
|
141
|
+
getRunManager: (channelId: string) => SubAgentRunManager;
|
|
142
|
+
/** Present only inside a task session: every delegation is bound to this task automatically (spec 052, D4). */
|
|
143
|
+
boundTaskId?: string;
|
|
144
|
+
}
|
|
145
|
+
/** What a dispatch hands back to the tool wrapper: the text for the model plus the structured details. */
|
|
146
|
+
export interface DelegationResult {
|
|
147
|
+
content: Array<{
|
|
148
|
+
type: "text";
|
|
149
|
+
text: string;
|
|
150
|
+
}>;
|
|
151
|
+
details: SubAgentToolFields;
|
|
152
|
+
}
|
|
153
|
+
/** Builds the tool set one internal run's worker gets (default: `internal/worker.ts`'s `buildSubagentTools`). */
|
|
154
|
+
export type BuildSubagentTools = (executor: Executor, bashTimeoutSec: number, options: SubAgentToolOptions, runContext: SubAgentRunContext) => AgentTool<any>[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The `purpose=verify` verdict rule, shared by the internal verifier path (`
|
|
2
|
+
* The `purpose=verify` verdict rule, shared by the internal verifier path (`internal/outcome.ts`) and the
|
|
3
3
|
* external one (`external/settlement.ts`).
|
|
4
4
|
*
|
|
5
5
|
* Spec 052, D6: a verifier's verdict is information for the leader, not a gate the runtime
|
|
@@ -1,8 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* P2-2: a plain-language "what changed" line for a completion wake, so the agent that reads it
|
|
3
3
|
* does not have to spend its own first tool call finding out. `git status --porcelain` only — a
|
|
4
|
-
* convenience for the reader, not evidence of anything.
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* convenience for the reader, not evidence of anything.
|
|
5
|
+
*
|
|
6
|
+
* A checkout is often already dirty when a write run starts (the leader's own edits, an earlier
|
|
7
|
+
* run's output). Reporting the raw status would credit all of that to this run, so a write run
|
|
8
|
+
* takes a cheap baseline at dispatch — each dirty path's status plus size/mtime — and the summary
|
|
9
|
+
* leaves out every path whose signature is unchanged. A pre-dirty file the run touched again gets
|
|
10
|
+
* a new mtime and so still shows up.
|
|
7
11
|
*/
|
|
8
|
-
|
|
12
|
+
/** Dirty path → `<XY status>|<size>|<mtimeMs>` at dispatch time. */
|
|
13
|
+
export type WorkspaceBaseline = Record<string, string>;
|
|
14
|
+
/** `undefined` when the directory is not a git checkout or is too dirty to baseline. */
|
|
15
|
+
export declare function snapshotWorkspace(workingDirectory: string): Promise<WorkspaceBaseline | undefined>;
|
|
16
|
+
/**
|
|
17
|
+
* Returns `undefined` on any failure (not a git repo, `git` unavailable) or when nothing changed;
|
|
18
|
+
* a caller with nothing to show should simply omit the line.
|
|
19
|
+
*/
|
|
20
|
+
export declare function changedPathsSummary(workingDirectory: string, baseline?: WorkspaceBaseline, limit?: number): Promise<string | undefined>;
|
|
@@ -1,29 +1,85 @@
|
|
|
1
1
|
import { execFile } from "node:child_process";
|
|
2
|
+
import { stat } from "node:fs/promises";
|
|
3
|
+
import { join } from "node:path";
|
|
2
4
|
import { promisify } from "node:util";
|
|
3
5
|
const execFileAsync = promisify(execFile);
|
|
4
|
-
/**
|
|
5
|
-
*
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
* git repo, `git` unavailable) or when nothing changed; a caller with nothing to show should
|
|
9
|
-
* simply omit the line.
|
|
10
|
-
*/
|
|
11
|
-
export async function changedPathsSummary(workingDirectory, limit = 20) {
|
|
12
|
-
let statusOutput;
|
|
6
|
+
/** Past this many dirty paths a baseline is not worth persisting on every run record; the summary
|
|
7
|
+
* then falls back to the raw status and says so. */
|
|
8
|
+
const BASELINE_MAX_ENTRIES = 500;
|
|
9
|
+
async function readPorcelain(workingDirectory) {
|
|
13
10
|
try {
|
|
14
11
|
const args = ["-C", workingDirectory, "status", "--porcelain=v1", "--untracked-files=all"];
|
|
15
|
-
|
|
12
|
+
const { stdout } = await execFileAsync("git", args, { maxBuffer: 4 * 1024 * 1024 });
|
|
13
|
+
return stdout
|
|
14
|
+
.split("\n")
|
|
15
|
+
.map((line) => line.trimEnd())
|
|
16
|
+
.filter((line) => line.length > 3);
|
|
16
17
|
}
|
|
17
18
|
catch {
|
|
18
19
|
return undefined;
|
|
19
20
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
}
|
|
22
|
+
/** `XY path` or `XY orig -> path`; the path is what a later status line will be keyed by. */
|
|
23
|
+
function porcelainPath(line) {
|
|
24
|
+
const rest = line.slice(3);
|
|
25
|
+
const arrow = rest.indexOf(" -> ");
|
|
26
|
+
return arrow >= 0 ? rest.slice(arrow + 4) : rest;
|
|
27
|
+
}
|
|
28
|
+
async function pathSignature(workingDirectory, line) {
|
|
29
|
+
const status = line.slice(0, 2);
|
|
30
|
+
const path = porcelainPath(line);
|
|
31
|
+
// A quoted path (special characters) is not worth unquoting for a convenience line: its status
|
|
32
|
+
// alone still tells "unchanged since dispatch" apart from most real edits.
|
|
33
|
+
if (path.startsWith('"'))
|
|
34
|
+
return status;
|
|
35
|
+
try {
|
|
36
|
+
const info = await stat(join(workingDirectory, path));
|
|
37
|
+
return `${status}|${info.size}|${info.mtimeMs}`;
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
return `${status}|missing`;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/** `undefined` when the directory is not a git checkout or is too dirty to baseline. */
|
|
44
|
+
export async function snapshotWorkspace(workingDirectory) {
|
|
45
|
+
const lines = await readPorcelain(workingDirectory);
|
|
46
|
+
if (!lines || lines.length > BASELINE_MAX_ENTRIES)
|
|
47
|
+
return undefined;
|
|
48
|
+
const baseline = {};
|
|
49
|
+
await Promise.all(lines.map(async (line) => {
|
|
50
|
+
baseline[porcelainPath(line)] = await pathSignature(workingDirectory, line);
|
|
51
|
+
}));
|
|
52
|
+
return baseline;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Returns `undefined` on any failure (not a git repo, `git` unavailable) or when nothing changed;
|
|
56
|
+
* a caller with nothing to show should simply omit the line.
|
|
57
|
+
*/
|
|
58
|
+
export async function changedPathsSummary(workingDirectory, baseline, limit = 20) {
|
|
59
|
+
const lines = await readPorcelain(workingDirectory);
|
|
60
|
+
if (!lines)
|
|
61
|
+
return undefined;
|
|
62
|
+
let changed = lines;
|
|
63
|
+
let unchangedCount = 0;
|
|
64
|
+
if (baseline) {
|
|
65
|
+
const flags = await Promise.all(lines.map(async (line) => {
|
|
66
|
+
const before = baseline[porcelainPath(line)];
|
|
67
|
+
return before !== undefined && before === (await pathSignature(workingDirectory, line));
|
|
68
|
+
}));
|
|
69
|
+
changed = lines.filter((_, index) => !flags[index]);
|
|
70
|
+
unchangedCount = lines.length - changed.length;
|
|
71
|
+
}
|
|
72
|
+
if (changed.length === 0)
|
|
25
73
|
return undefined;
|
|
26
|
-
const shown =
|
|
27
|
-
|
|
28
|
-
|
|
74
|
+
const shown = changed
|
|
75
|
+
.slice(0, limit)
|
|
76
|
+
.map((line) => line.trim())
|
|
77
|
+
.join(", ");
|
|
78
|
+
const overflow = changed.length > limit ? ` (+${changed.length - limit} more)` : "";
|
|
79
|
+
const note = baseline
|
|
80
|
+
? unchangedCount > 0
|
|
81
|
+
? ` (${unchangedCount} path(s) already dirty before the run and untouched are omitted)`
|
|
82
|
+
: ""
|
|
83
|
+
: " (no pre-run baseline: may include changes that predate this run)";
|
|
84
|
+
return `${shown}${overflow}${note}`;
|
|
29
85
|
}
|
package/dist/tasks/board.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type TaskItem } from "./
|
|
2
|
-
import { type TaskSettleRecord } from "./log.js";
|
|
1
|
+
import { type TaskItem } from "./contract.js";
|
|
2
|
+
import { type TaskSettleRecord } from "./loop-log.js";
|
|
3
3
|
/**
|
|
4
4
|
* The team board (spec 052, D5): what the leader's delegations and jobs are doing right now.
|
|
5
5
|
*
|
|
@@ -32,8 +32,15 @@ export interface TaskBoard {
|
|
|
32
32
|
/** Ref lines the board renders before folding old, already-seen results away. */
|
|
33
33
|
export declare const BOARD_REF_LINE_BUDGET = 12;
|
|
34
34
|
export declare function buildTaskBoard(channelDir: string, taskId: string, body: string): Promise<TaskBoard | undefined>;
|
|
35
|
-
/** Render the `<task_board>` block body. */
|
|
35
|
+
/** Render the `<task_board>` block body (model-facing; `/tasks show` uses `renderTaskBoardForUser`). */
|
|
36
36
|
export declare function renderTaskBoard(board: TaskBoard, nowMs?: number): string;
|
|
37
|
+
/**
|
|
38
|
+
* The board as `/tasks show` presents it (spec 053, D2): flat bullets only — DingTalk drops
|
|
39
|
+
* indentation, so the brief's `↳` continuation lines would read as orphans — with every ref a
|
|
40
|
+
* work item has folded into its one line. No "seen / new" split (that is the leader's
|
|
41
|
+
* de-duplication aid) and no pointer at a model tool.
|
|
42
|
+
*/
|
|
43
|
+
export declare function renderTaskBoardForUser(board: TaskBoard, taskId: string, nowMs?: number): string;
|
|
37
44
|
/**
|
|
38
45
|
* The `<task_results>` block body: what came back since the previous step, as the completion wake
|
|
39
46
|
* showed it — the output's tail and, for a run, what it left changed. A task step's brief replaces
|
package/dist/tasks/board.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { formatElapsedZh } from "../shared/format.js";
|
|
1
2
|
import { parseLocalTime } from "../shared/local-time.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
3
|
+
import { truncate } from "../shared/text-utils.js";
|
|
4
|
+
import { parseTaskItems } from "./contract.js";
|
|
5
|
+
import { describeSettlement, describeWorkRef, readTaskLog, } from "./loop-log.js";
|
|
4
6
|
/** Ref lines the board renders before folding old, already-seen results away. */
|
|
5
7
|
export const BOARD_REF_LINE_BUDGET = 12;
|
|
6
8
|
export async function buildTaskBoard(channelDir, taskId, body) {
|
|
@@ -91,7 +93,7 @@ function renderRef(entry, nowMs) {
|
|
|
91
93
|
return `${label} ${parts.join(" ")}${tail ? ` ${tail}` : ""}`;
|
|
92
94
|
}
|
|
93
95
|
const ITEM_MARKER = { todo: " ", done: "x", blocked: "!", dropped: "~" };
|
|
94
|
-
/** Render the `<task_board>` block body. */
|
|
96
|
+
/** Render the `<task_board>` block body (model-facing; `/tasks show` uses `renderTaskBoardForUser`). */
|
|
95
97
|
export function renderTaskBoard(board, nowMs = Date.now()) {
|
|
96
98
|
const lines = [];
|
|
97
99
|
for (const { item, refs } of board.items) {
|
|
@@ -110,6 +112,39 @@ export function renderTaskBoard(board, nowMs = Date.now()) {
|
|
|
110
112
|
lines.push(`- (另有 ${board.hiddenSettled} 项已结算且已看过,见 task_log)`);
|
|
111
113
|
return lines.join("\n");
|
|
112
114
|
}
|
|
115
|
+
const ITEM_STATUS_LABEL = {
|
|
116
|
+
todo: "待办",
|
|
117
|
+
done: "已完成",
|
|
118
|
+
blocked: "受阻",
|
|
119
|
+
dropped: "已放弃",
|
|
120
|
+
};
|
|
121
|
+
function renderRefForUser(entry, nowMs) {
|
|
122
|
+
const who = entry.agent && entry.agent !== "job" ? `(${entry.agent}${entry.purpose === "verify" ? ",验收" : ""})` : "";
|
|
123
|
+
const state = entry.settled
|
|
124
|
+
? describeSettlement(entry.settled)
|
|
125
|
+
: `进行中 ${formatElapsedZh(nowMs - entry.dispatchedAtMs)}`;
|
|
126
|
+
return `${describeWorkRef(entry.ref)}${who} ${state}`;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* The board as `/tasks show` presents it (spec 053, D2): flat bullets only — DingTalk drops
|
|
130
|
+
* indentation, so the brief's `↳` continuation lines would read as orphans — with every ref a
|
|
131
|
+
* work item has folded into its one line. No "seen / new" split (that is the leader's
|
|
132
|
+
* de-duplication aid) and no pointer at a model tool.
|
|
133
|
+
*/
|
|
134
|
+
export function renderTaskBoardForUser(board, taskId, nowMs = Date.now()) {
|
|
135
|
+
const lines = [];
|
|
136
|
+
for (const { item, refs } of board.items) {
|
|
137
|
+
const head = `- ${item.id} ${truncate(item.text.replace(/\s+/g, " "), 80)}(${ITEM_STATUS_LABEL[item.status]})`;
|
|
138
|
+
lines.push(refs.length > 0 ? `${head}:${refs.map((ref) => renderRefForUser(ref, nowMs)).join("、")}` : head);
|
|
139
|
+
}
|
|
140
|
+
if (board.unlinked.length > 0) {
|
|
141
|
+
lines.push(`- 未关联工作项:${board.unlinked.map((ref) => renderRefForUser(ref, nowMs)).join("、")}`);
|
|
142
|
+
}
|
|
143
|
+
if (board.hiddenSettled > 0) {
|
|
144
|
+
lines.push(`- 另有 ${board.hiddenSettled} 项较早结束的工作未列出,用 \`/tasks log ${taskId}\` 查看`);
|
|
145
|
+
}
|
|
146
|
+
return lines.join("\n");
|
|
147
|
+
}
|
|
113
148
|
/**
|
|
114
149
|
* The `<task_results>` block body: what came back since the previous step, as the completion wake
|
|
115
150
|
* showed it — the output's tail and, for a run, what it left changed. A task step's brief replaces
|
package/dist/tasks/brief.js
CHANGED
|
@@ -5,7 +5,7 @@ import { PLAYBOOKS_DIR } from "../paths.js";
|
|
|
5
5
|
import { clipText } from "../shared/text-utils.js";
|
|
6
6
|
import { buildTaskBoard, renderNewResults, renderTaskBoard } from "./board.js";
|
|
7
7
|
import { effectiveBudget } from "./budget.js";
|
|
8
|
-
import { readTaskLog, renderTaskLogLine } from "./log.js";
|
|
8
|
+
import { readTaskLog, renderTaskLogLine } from "./loop-log.js";
|
|
9
9
|
import { consumeTaskSteer } from "./steer.js";
|
|
10
10
|
import { readStoredTask, tasksDir } from "./store.js";
|
|
11
11
|
import { describeTicket } from "./ticket.js";
|