@oyasmi/pipiclaw 0.9.3 → 0.9.4-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent/builtin-commands.d.ts +19 -0
- package/dist/agent/builtin-commands.js +80 -0
- package/dist/agent/channel-runner.d.ts +20 -208
- package/dist/agent/channel-runner.js +167 -1188
- package/dist/agent/maintenance-context.d.ts +1 -1
- package/dist/agent/maintenance-context.js +1 -1
- package/dist/agent/prompt/manifest.d.ts +6 -1
- package/dist/agent/prompt/manifest.js +45 -64
- package/dist/agent/prompt/resources.d.ts +3 -0
- package/dist/agent/prompt/resources.js +11 -2
- package/dist/agent/runner-factory.d.ts +1 -43
- package/dist/agent/{command-extension.d.ts → session/command-extension.d.ts} +4 -0
- package/dist/agent/{command-extension.js → session/command-extension.js} +48 -35
- package/dist/agent/{type-guards.d.ts → session/event-guards.d.ts} +2 -2
- package/dist/agent/{type-guards.js → session/event-guards.js} +5 -1
- package/dist/agent/session/model-selection.d.ts +47 -0
- package/dist/agent/session/model-selection.js +99 -0
- package/dist/agent/{session-adapter.d.ts → session/session-adapter.d.ts} +21 -1
- package/dist/agent/session/session-adapter.js +159 -0
- package/dist/agent/{session-events.d.ts → session/session-events.d.ts} +9 -5
- package/dist/agent/{session-events.js → session/session-events.js} +24 -13
- package/dist/agent/session/session-host.d.ts +200 -0
- package/dist/agent/session/session-host.js +621 -0
- package/dist/agent/{session-resource-gate.js → session/session-resource-gate.js} +5 -3
- package/dist/agent/status-render.d.ts +0 -1
- package/dist/agent/status-render.js +4 -16
- package/dist/agent/{context-budget.js → turn/context-budget.js} +5 -1
- package/dist/agent/{progress-formatter.d.ts → turn/progress-formatter.d.ts} +4 -1
- package/dist/agent/{run-queue.d.ts → turn/run-queue.d.ts} +1 -1
- package/dist/agent/{run-queue.js → turn/run-queue.js} +10 -5
- package/dist/{memory → agent/turn}/task-digest.js +4 -4
- package/dist/agent/turn/turn-context.d.ts +14 -0
- package/dist/agent/turn/turn-context.js +64 -0
- package/dist/agent/turn/turn-error.d.ts +31 -0
- package/dist/agent/turn/turn-error.js +68 -0
- package/dist/agent/turn/turn-finish.d.ts +50 -0
- package/dist/agent/turn/turn-finish.js +188 -0
- package/dist/agent/turn/turn-input.d.ts +43 -0
- package/dist/agent/turn/turn-input.js +79 -0
- package/dist/agent/turn/turn-pipeline.d.ts +68 -0
- package/dist/agent/turn/turn-pipeline.js +257 -0
- package/dist/agent/{turn-prompt.d.ts → turn/turn-prompt.d.ts} +2 -2
- package/dist/agent/{turn-prompt.js → turn/turn-prompt.js} +6 -2
- package/dist/agent/{turn-recovery.js → turn/turn-recovery.js} +1 -1
- package/dist/agent/{turn-state.d.ts → turn/turn-state.d.ts} +1 -1
- package/dist/agent/types.d.ts +43 -2
- package/dist/agent/types.js +1 -1
- package/dist/{models/auth-cli.d.ts → app/auth-command.d.ts} +1 -1
- package/dist/{models/auth-cli.js → app/auth-command.js} +14 -10
- package/dist/{runtime/app-home.d.ts → app/home.d.ts} +6 -2
- package/dist/{runtime/app-home.js → app/home.js} +22 -75
- package/dist/{runtime → app}/proxy.js +4 -2
- package/dist/{app-services.d.ts → app/services.d.ts} +5 -5
- package/dist/{app-services.js → app/services.js} +17 -14
- package/dist/channel/channel-context.d.ts +12 -2
- package/dist/channel/channel-context.js +29 -2
- package/dist/channel/channel-event.d.ts +10 -2
- package/dist/channel/channel-event.js +1 -1
- package/dist/channel/channel-index.js +4 -1
- package/dist/{runtime/project-commands.d.ts → channel/commands.d.ts} +1 -1
- package/dist/{runtime/project-commands.js → channel/commands.js} +17 -16
- package/dist/channel/project-scope-store.js +1 -1
- package/dist/channel/store.js +4 -0
- package/dist/commands/catalog.d.ts +24 -7
- package/dist/commands/catalog.js +91 -44
- package/dist/commands/reply-limits.d.ts +6 -0
- package/dist/commands/reply-limits.js +24 -0
- package/dist/{runtime/report-commands.d.ts → commands/router.d.ts} +10 -3
- package/dist/{runtime/report-commands.js → commands/router.js} +6 -6
- package/dist/{settings.d.ts → config/settings.d.ts} +10 -10
- package/dist/{settings.js → config/settings.js} +11 -11
- package/dist/{tools/config.d.ts → config/tools.d.ts} +1 -2
- package/dist/{tools/config.js → config/tools.js} +5 -2
- package/dist/dingtalk/access-token.d.ts +12 -0
- package/dist/dingtalk/access-token.js +51 -0
- package/dist/dingtalk/api.d.ts +19 -0
- package/dist/dingtalk/api.js +67 -0
- package/dist/dingtalk/bot.d.ts +97 -0
- package/dist/dingtalk/bot.js +389 -0
- package/dist/dingtalk/cards.d.ts +56 -0
- package/dist/dingtalk/cards.js +318 -0
- package/dist/{runtime → dingtalk}/channel-queue.js +4 -1
- package/dist/dingtalk/config.d.ts +19 -0
- package/dist/dingtalk/config.js +95 -0
- package/dist/dingtalk/connection.d.ts +57 -0
- package/dist/dingtalk/connection.js +356 -0
- package/dist/dingtalk/conversation-meta.d.ts +16 -0
- package/dist/dingtalk/conversation-meta.js +77 -0
- package/dist/{runtime → dingtalk}/delivery.d.ts +6 -2
- package/dist/{runtime → dingtalk}/delivery.js +29 -15
- package/dist/dingtalk/handler.d.ts +90 -0
- package/dist/dingtalk/handler.js +1 -0
- package/dist/dingtalk/inbound.d.ts +66 -0
- package/dist/dingtalk/inbound.js +137 -0
- package/dist/dingtalk/media.d.ts +66 -0
- package/dist/dingtalk/media.js +214 -0
- package/dist/events/{event-commands.js → commands.js} +99 -45
- package/dist/events/parse.d.ts +14 -0
- package/dist/events/parse.js +114 -0
- package/dist/events/types.d.ts +93 -0
- package/dist/events/types.js +1 -0
- package/dist/events/{event-validation.d.ts → validation.d.ts} +14 -3
- package/dist/events/{event-validation.js → validation.js} +17 -9
- package/dist/events/watcher.d.ts +67 -0
- package/dist/events/{events.js → watcher.js} +63 -121
- package/dist/executor.js +2 -2
- package/dist/index.d.ts +6 -4
- package/dist/index.js +2 -2
- package/dist/jobs/launch.d.ts +42 -0
- package/dist/jobs/launch.js +118 -0
- package/dist/{agent/job-manager.d.ts → jobs/manager.d.ts} +1 -67
- package/dist/{agent/job-manager.js → jobs/manager.js} +34 -157
- package/dist/jobs/record.d.ts +55 -0
- package/dist/jobs/record.js +36 -0
- package/dist/log.d.ts +12 -2
- package/dist/log.js +26 -34
- package/dist/main.js +3 -3
- package/dist/memory/commands.js +29 -23
- package/dist/memory/lifecycle.js +26 -5
- package/dist/memory/maintenance-gates.d.ts +2 -2
- package/dist/memory/maintenance-state.js +4 -1
- package/dist/memory/maintenance-tuning.d.ts +15 -0
- package/dist/memory/maintenance-tuning.js +3 -0
- package/dist/memory/reflect-job.d.ts +2 -2
- package/dist/memory/reflect-job.js +4 -2
- package/dist/memory/scheduler.d.ts +3 -3
- package/dist/memory/scheduler.js +5 -2
- package/dist/memory/sidecar-worker.js +1 -1
- package/dist/memory/transcript.js +1 -1
- package/dist/{agent/model-fallback.d.ts → models/fallback.d.ts} +6 -6
- package/dist/{agent/model-fallback.js → models/fallback.js} +15 -28
- package/dist/models/login-identity.d.ts +2 -0
- package/dist/models/login-identity.js +83 -0
- package/dist/models/provider-login.d.ts +3 -1
- package/dist/models/provider-login.js +8 -2
- package/dist/models/reference.d.ts +20 -0
- package/dist/models/{utils.js → reference.js} +0 -48
- package/dist/models/{utils.d.ts → runtime.d.ts} +1 -16
- package/dist/models/runtime.js +52 -0
- package/dist/paths.d.ts +2 -0
- package/dist/paths.js +9 -0
- package/dist/playbooks/agent-delegation.md +2 -2
- package/dist/playbooks/catalog.d.ts +6 -2
- package/dist/playbooks/catalog.js +9 -6
- package/dist/runtime/bootstrap.d.ts +7 -17
- package/dist/runtime/bootstrap.js +70 -659
- package/dist/runtime/durable-dispatch.d.ts +43 -4
- package/dist/runtime/durable-dispatch.js +153 -3
- package/dist/runtime/inbound-images.d.ts +18 -0
- package/dist/runtime/inbound-images.js +51 -0
- package/dist/runtime/shutdown.d.ts +39 -0
- package/dist/runtime/shutdown.js +120 -0
- package/dist/runtime/stop-watchdog.d.ts +16 -0
- package/dist/runtime/stop-watchdog.js +32 -0
- package/dist/runtime/task-driver.d.ts +6 -4
- package/dist/runtime/task-driver.js +58 -23
- package/dist/runtime/task-migration.js +25 -8
- package/dist/runtime/task-spawn.d.ts +1 -1
- package/dist/runtime/task-spawn.js +13 -6
- package/dist/runtime/turn-handler.d.ts +47 -0
- package/dist/runtime/turn-handler.js +318 -0
- package/dist/runtime/turn-run.d.ts +52 -0
- package/dist/runtime/turn-run.js +318 -0
- package/dist/runtime/wake-coalescing.d.ts +18 -0
- package/dist/runtime/wake-coalescing.js +29 -0
- package/dist/security/block-message.d.ts +22 -1
- package/dist/security/block-message.js +66 -1
- package/dist/security/command-guard.js +4 -0
- package/dist/security/network.d.ts +2 -1
- package/dist/security/network.js +7 -2
- package/dist/security/path-guard-check.js +2 -2
- package/dist/security/path-guard.js +4 -0
- package/dist/security/types.d.ts +1 -2
- package/dist/security/types.js +1 -2
- package/dist/shared/exact-keys.d.ts +1 -1
- package/dist/shared/format.d.ts +12 -0
- package/dist/shared/format.js +37 -0
- package/dist/shared/host-process.js +16 -4
- package/dist/shared/wake-claim.d.ts +1 -1
- package/dist/shared/with-timeout.d.ts +3 -2
- package/dist/shared/with-timeout.js +14 -3
- package/dist/{runtime/skill-commands.d.ts → skills/commands.d.ts} +2 -2
- package/dist/{runtime/skill-commands.js → skills/commands.js} +18 -11
- package/dist/{agent/workspace-resources.js → skills/loader.js} +1 -1
- package/dist/{tools/skill-security.js → skills/validation.js} +4 -0
- package/dist/skills/workspace.d.ts +33 -0
- package/dist/skills/workspace.js +116 -0
- package/dist/{runtime/subagent-commands.d.ts → subagents/commands.d.ts} +9 -7
- package/dist/{runtime/subagent-commands.js → subagents/commands.js} +116 -77
- package/dist/subagents/completion-wake.d.ts +17 -0
- package/dist/subagents/completion-wake.js +76 -0
- package/dist/subagents/detached-discovery.js +1 -1
- package/dist/subagents/discovery.d.ts +1 -1
- package/dist/subagents/discovery.js +2 -2
- package/dist/subagents/dispatch.d.ts +33 -0
- package/dist/subagents/dispatch.js +190 -0
- package/dist/subagents/external/claude-code.js +23 -1
- package/dist/subagents/external/dispatch.d.ts +25 -0
- package/dist/subagents/external/dispatch.js +90 -0
- package/dist/subagents/external/harness.d.ts +1 -1
- package/dist/subagents/external/progress-tail.d.ts +18 -1
- package/dist/subagents/external/progress-tail.js +64 -17
- package/dist/subagents/external/run.d.ts +5 -1
- package/dist/subagents/external/run.js +23 -9
- package/dist/subagents/external/settlement.d.ts +4 -1
- package/dist/subagents/external/settlement.js +1 -1
- package/dist/subagents/format.d.ts +1 -1
- package/dist/subagents/grace.d.ts +24 -0
- package/dist/subagents/grace.js +57 -0
- package/dist/subagents/internal/outcome.d.ts +24 -0
- package/dist/subagents/internal/outcome.js +149 -0
- package/dist/subagents/internal/provider-retry.d.ts +19 -0
- package/dist/subagents/internal/provider-retry.js +83 -0
- package/dist/subagents/internal/run.d.ts +31 -0
- package/dist/subagents/internal/run.js +240 -0
- package/dist/subagents/internal/state.d.ts +43 -0
- package/dist/subagents/internal/state.js +48 -0
- package/dist/subagents/internal/worker.d.ts +51 -0
- package/dist/subagents/internal/worker.js +167 -0
- package/dist/subagents/result.d.ts +62 -0
- package/dist/subagents/result.js +103 -0
- package/dist/subagents/run-record.d.ts +222 -0
- package/dist/subagents/run-record.js +101 -0
- package/dist/subagents/run-registry.d.ts +9 -0
- package/dist/subagents/run-registry.js +125 -0
- package/dist/subagents/runs.d.ts +16 -232
- package/dist/subagents/runs.js +132 -310
- package/dist/subagents/task-envelope.d.ts +36 -0
- package/dist/subagents/task-envelope.js +168 -0
- package/dist/subagents/types.d.ts +154 -0
- package/dist/subagents/types.js +1 -0
- package/dist/subagents/verification-outcome.d.ts +1 -1
- package/dist/subagents/workspace-summary.d.ts +16 -4
- package/dist/subagents/workspace-summary.js +74 -18
- package/dist/tasks/board.d.ts +10 -3
- package/dist/tasks/board.js +38 -3
- package/dist/tasks/{work-log.d.ts → bound-work.d.ts} +1 -1
- package/dist/tasks/{work-log.js → bound-work.js} +1 -1
- package/dist/tasks/brief.js +1 -1
- package/dist/{runtime/task-commands.d.ts → tasks/commands.d.ts} +1 -1
- package/dist/{runtime/task-commands.js → tasks/commands.js} +117 -67
- package/dist/tasks/contract-input.d.ts +1 -1
- package/dist/tasks/contract-input.js +1 -1
- package/dist/tasks/create.js +1 -1
- package/dist/tasks/frontmatter.d.ts +5 -0
- package/dist/tasks/frontmatter.js +8 -0
- package/dist/tasks/{log.d.ts → loop-log.d.ts} +11 -1
- package/dist/tasks/{log.js → loop-log.js} +59 -3
- package/dist/tasks/mutation-lock.js +1 -1
- package/dist/tasks/session-path.js +1 -1
- package/dist/tasks/steer.js +1 -1
- package/dist/tasks/store.js +6 -4
- package/dist/tasks/ticket.d.ts +3 -1
- package/dist/tasks/ticket.js +19 -1
- package/dist/tools/bash.d.ts +1 -1
- package/dist/tools/bash.js +2 -2
- package/dist/tools/{tool-details.d.ts → contract/details.d.ts} +11 -3
- package/dist/tools/{tool-details.js → contract/details.js} +42 -5
- package/dist/tools/{presentation.js → contract/presentation.js} +3 -3
- package/dist/tools/event-manage.d.ts +1 -1
- package/dist/tools/event-manage.js +4 -4
- package/dist/tools/index.d.ts +5 -3
- package/dist/tools/index.js +8 -6
- package/dist/tools/job.d.ts +1 -1
- package/dist/tools/memory-manage.js +4 -1
- package/dist/tools/registry.d.ts +7 -7
- package/dist/tools/registry.js +6 -6
- package/dist/tools/session-search.d.ts +1 -1
- package/dist/tools/skill.d.ts +2 -34
- package/dist/tools/skill.js +8 -116
- package/dist/tools/subagent-manage.d.ts +1 -1
- package/dist/tools/subagent-manage.js +19 -13
- package/dist/tools/subagent.d.ts +46 -0
- package/dist/tools/subagent.js +127 -0
- package/dist/tools/{task-manage.d.ts → task-manage/factory.d.ts} +7 -3
- package/dist/tools/{task-manage.js → task-manage/factory.js} +7 -7
- package/dist/tools/task-manage/lifecycle.js +2 -2
- package/dist/tools/task-manage/log-view.js +2 -2
- package/dist/tools/task-manage/shared.js +3 -3
- package/dist/tools/task-manage/step-end.js +7 -4
- package/dist/tools/task-manage/types.d.ts +1 -1
- package/dist/tools/web-fetch.d.ts +1 -1
- package/dist/tools/web-search.d.ts +1 -1
- package/dist/tui/app.d.ts +1 -1
- package/dist/tui/app.js +6 -6
- package/dist/tui/cli.d.ts +1 -1
- package/dist/tui/cli.js +3 -3
- package/dist/tui/commands.js +4 -4
- package/dist/tui/frontend.d.ts +44 -0
- package/dist/tui/frontend.js +13 -0
- package/dist/tui/pitui-frontend.d.ts +1 -1
- package/dist/tui/pitui-frontend.js +1 -1
- package/dist/tui/plain-frontend.d.ts +1 -1
- package/dist/tui/renderer.d.ts +3 -42
- package/dist/tui/renderer.js +3 -2
- package/dist/tui/terminal-context.d.ts +2 -2
- package/dist/tui/terminal-media-sender.d.ts +1 -1
- package/dist/tui/turn-controller.d.ts +3 -1
- package/dist/tui/turn-controller.js +36 -21
- package/dist/usage/ledger.js +7 -1
- package/dist/usage/render.js +3 -1
- package/dist/{shared/types.d.ts → usage/totals.d.ts} +3 -0
- package/dist/web/client.d.ts +5 -1
- package/dist/web/client.js +4 -0
- package/dist/web/config.d.ts +1 -1
- package/dist/web/fetch.d.ts +1 -1
- package/dist/web/search-providers.d.ts +1 -1
- package/dist/web/search.d.ts +1 -1
- package/package.json +9 -7
- package/dist/agent/session-adapter.js +0 -77
- package/dist/events/events.d.ts +0 -159
- package/dist/runtime/dingtalk.d.ts +0 -272
- package/dist/runtime/dingtalk.js +0 -1416
- package/dist/subagents/tool.d.ts +0 -206
- package/dist/subagents/tool.js +0 -1088
- /package/dist/{runtime → agent/prompt}/workspace-templates.d.ts +0 -0
- /package/dist/{runtime → agent/prompt}/workspace-templates.js +0 -0
- /package/dist/agent/{session-resource-gate.d.ts → session/session-resource-gate.d.ts} +0 -0
- /package/dist/agent/{context-budget.d.ts → turn/context-budget.d.ts} +0 -0
- /package/dist/agent/{progress-formatter.js → turn/progress-formatter.js} +0 -0
- /package/dist/{memory → agent/turn}/task-digest.d.ts +0 -0
- /package/dist/agent/{turn-recovery.d.ts → turn/turn-recovery.d.ts} +0 -0
- /package/dist/agent/{turn-state.js → turn/turn-state.js} +0 -0
- /package/dist/{runtime → app}/proxy.d.ts +0 -0
- /package/dist/{runtime → dingtalk}/channel-queue.d.ts +0 -0
- /package/dist/{runtime → dingtalk}/inbound-media.d.ts +0 -0
- /package/dist/{runtime → dingtalk}/inbound-media.js +0 -0
- /package/dist/events/{event-commands.d.ts → commands.d.ts} +0 -0
- /package/dist/{agent/workspace-resources.d.ts → skills/loader.d.ts} +0 -0
- /package/dist/{tools/skill-security.d.ts → skills/validation.d.ts} +0 -0
- /package/dist/tasks/{ledger.d.ts → contract.d.ts} +0 -0
- /package/dist/tasks/{ledger.js → contract.js} +0 -0
- /package/dist/tools/{subagent-tool-names.d.ts → contract/names.d.ts} +0 -0
- /package/dist/tools/{subagent-tool-names.js → contract/names.js} +0 -0
- /package/dist/tools/{presentation.d.ts → contract/presentation.d.ts} +0 -0
- /package/dist/{shared/types.js → usage/totals.js} +0 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { AgentTool } from "@earendil-works/pi-agent-core";
|
|
2
|
+
import { type GuardBlock } from "../../security/block-message.js";
|
|
2
3
|
/**
|
|
3
4
|
* The `details` contract for tool results, and the recoverable-rejection mechanism
|
|
4
5
|
* built on it.
|
|
@@ -13,7 +14,7 @@ import type { AgentTool } from "@earendil-works/pi-agent-core";
|
|
|
13
14
|
* conform by construction: a tool cannot forget it, and it cannot disagree with the name the
|
|
14
15
|
* tool is registered under.
|
|
15
16
|
*/
|
|
16
|
-
export { RecoverableToolError } from "
|
|
17
|
+
export { RecoverableToolError } from "../../shared/recoverable-error.js";
|
|
17
18
|
/**
|
|
18
19
|
* Every tool that can appear in a tool set. Equal to the registry's tool names plus
|
|
19
20
|
* `subagent`, which is registered separately (see the note on TOOL_REGISTRY).
|
|
@@ -50,8 +51,15 @@ export declare function isRecoverableRejection(result: unknown): boolean;
|
|
|
50
51
|
*/
|
|
51
52
|
export declare function isArgumentValidationFailure(result: unknown, isError: boolean): boolean;
|
|
52
53
|
/**
|
|
53
|
-
*
|
|
54
|
-
*
|
|
54
|
+
* Claim the guard refusal behind a failed tool call. `resultText` must be the error text the SDK
|
|
55
|
+
* reported for that call: a stale or colliding id from another channel never matches it, so the
|
|
56
|
+
* worst case is falling back to the plain error line, never showing someone else's refusal.
|
|
57
|
+
*/
|
|
58
|
+
export declare function takeGuardBlock(toolCallId: string, resultText: string): GuardBlock | undefined;
|
|
59
|
+
/**
|
|
60
|
+
* Bind a tool to the contract: stamp `kind` on every result it returns, convert a
|
|
61
|
+
* `RecoverableToolError` into a normal result the model can read and act on, and park a guard
|
|
62
|
+
* refusal's structured form for the chat (`takeGuardBlock`).
|
|
55
63
|
*
|
|
56
64
|
* Applied once in `buildToolSet`, so every registered tool is covered without each one
|
|
57
65
|
* having to remember. `kind` is stamped last and unconditionally: the name a tool is
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { GuardBlockedError } from "../../security/block-message.js";
|
|
2
|
+
import { RecoverableToolError } from "../../shared/recoverable-error.js";
|
|
3
|
+
import { isRecord } from "../../shared/type-guards.js";
|
|
3
4
|
/**
|
|
4
5
|
* The `details` contract for tool results, and the recoverable-rejection mechanism
|
|
5
6
|
* built on it.
|
|
@@ -14,7 +15,7 @@ import { isRecord } from "../shared/type-guards.js";
|
|
|
14
15
|
* conform by construction: a tool cannot forget it, and it cannot disagree with the name the
|
|
15
16
|
* tool is registered under.
|
|
16
17
|
*/
|
|
17
|
-
export { RecoverableToolError } from "
|
|
18
|
+
export { RecoverableToolError } from "../../shared/recoverable-error.js";
|
|
18
19
|
/** Read the `details` off a tool result, if it carries a conforming one. */
|
|
19
20
|
export function toolResultDetails(result) {
|
|
20
21
|
if (!isRecord(result) || !("details" in result)) {
|
|
@@ -52,8 +53,42 @@ export function isArgumentValidationFailure(result, isError) {
|
|
|
52
53
|
return text.startsWith('Validation failed for tool "');
|
|
53
54
|
}
|
|
54
55
|
/**
|
|
55
|
-
*
|
|
56
|
-
*
|
|
56
|
+
* Guard refusals waiting for their `tool_execution_end` (spec 053, D5.2).
|
|
57
|
+
*
|
|
58
|
+
* A refusal must stay a *thrown* error — that is what makes the SDK mark the result `isError`,
|
|
59
|
+
* which the model sees — but the SDK rebuilds a thrown error's result from `message` alone
|
|
60
|
+
* (`createErrorToolResult`, `details: {}`), so structured data cannot ride on the result itself.
|
|
61
|
+
* It is parked here under the tool call id instead and claimed by the session-event handler.
|
|
62
|
+
* Bounded, because a tool set whose events nobody consumes (an internal sub-agent) never claims.
|
|
63
|
+
*/
|
|
64
|
+
const pendingGuardBlocks = new Map();
|
|
65
|
+
const MAX_PENDING_GUARD_BLOCKS = 64;
|
|
66
|
+
function noteGuardBlock(toolCallId, error) {
|
|
67
|
+
pendingGuardBlocks.delete(toolCallId);
|
|
68
|
+
pendingGuardBlocks.set(toolCallId, { message: error.message, blocked: error.blocked });
|
|
69
|
+
while (pendingGuardBlocks.size > MAX_PENDING_GUARD_BLOCKS) {
|
|
70
|
+
const oldest = pendingGuardBlocks.keys().next().value;
|
|
71
|
+
if (oldest === undefined)
|
|
72
|
+
break;
|
|
73
|
+
pendingGuardBlocks.delete(oldest);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Claim the guard refusal behind a failed tool call. `resultText` must be the error text the SDK
|
|
78
|
+
* reported for that call: a stale or colliding id from another channel never matches it, so the
|
|
79
|
+
* worst case is falling back to the plain error line, never showing someone else's refusal.
|
|
80
|
+
*/
|
|
81
|
+
export function takeGuardBlock(toolCallId, resultText) {
|
|
82
|
+
const entry = pendingGuardBlocks.get(toolCallId);
|
|
83
|
+
if (!entry || entry.message !== resultText)
|
|
84
|
+
return undefined;
|
|
85
|
+
pendingGuardBlocks.delete(toolCallId);
|
|
86
|
+
return entry.blocked;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Bind a tool to the contract: stamp `kind` on every result it returns, convert a
|
|
90
|
+
* `RecoverableToolError` into a normal result the model can read and act on, and park a guard
|
|
91
|
+
* refusal's structured form for the chat (`takeGuardBlock`).
|
|
57
92
|
*
|
|
58
93
|
* Applied once in `buildToolSet`, so every registered tool is covered without each one
|
|
59
94
|
* having to remember. `kind` is stamped last and unconditionally: the name a tool is
|
|
@@ -79,6 +114,8 @@ export function withToolDetails(tool, kind) {
|
|
|
79
114
|
details: { kind, recoverable: true },
|
|
80
115
|
};
|
|
81
116
|
}
|
|
117
|
+
if (error instanceof GuardBlockedError)
|
|
118
|
+
noteGuardBlock(toolCallId, error);
|
|
82
119
|
throw error;
|
|
83
120
|
}
|
|
84
121
|
},
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { clipText } from "
|
|
2
|
-
import { isRecord } from "
|
|
1
|
+
import { clipText } from "../../shared/text-utils.js";
|
|
2
|
+
import { isRecord } from "../../shared/type-guards.js";
|
|
3
3
|
/**
|
|
4
4
|
* Runtime-side projection from a tool call's raw arguments to the one-line Chinese progress
|
|
5
|
-
* string shown while it runs (`src/agent/session-events.ts`). Replaces the old model-authored,
|
|
5
|
+
* string shown while it runs (`src/agent/session/session-events.ts`). Replaces the old model-authored,
|
|
6
6
|
* per-tool-required `label` argument (spec 045): the model no longer pays schema tokens or output
|
|
7
7
|
* tokens for a UI string on every single call, and the wording is deterministic instead of
|
|
8
8
|
* whatever the model happened to write.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { AgentTool } from "@earendil-works/pi-agent-core";
|
|
2
2
|
import { Type } from "typebox";
|
|
3
|
-
import {
|
|
3
|
+
import type { ScheduledEvent } from "../events/types.js";
|
|
4
4
|
import type { SecurityConfig } from "../security/types.js";
|
|
5
5
|
import type { TaskCreateInput } from "../tasks/contract-input.js";
|
|
6
6
|
declare const eventManageSchema: Type.TObject<{
|
|
@@ -2,9 +2,9 @@ import { existsSync } from "node:fs";
|
|
|
2
2
|
import { readdir, readFile, unlink } from "node:fs/promises";
|
|
3
3
|
import { join } from "node:path";
|
|
4
4
|
import { Type } from "typebox";
|
|
5
|
-
import { resolveEventPath } from "../events/
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
5
|
+
import { resolveEventPath } from "../events/commands.js";
|
|
6
|
+
import { describeEventPayload, parseScheduledEventContent } from "../events/parse.js";
|
|
7
|
+
import { EventValidationError, MAX_EVENT_FILES, validateScheduledEvent } from "../events/validation.js";
|
|
8
8
|
import { writeFileAtomically } from "../shared/atomic-file.js";
|
|
9
9
|
import { RecoverableToolError } from "../shared/recoverable-error.js";
|
|
10
10
|
import { clipText, errorMessage } from "../shared/text-utils.js";
|
|
@@ -94,7 +94,7 @@ async function listOwnedEvents(options) {
|
|
|
94
94
|
* preActions, and cross-channel channelIds. The returned event is what gets persisted, so
|
|
95
95
|
* the file on disk is exactly what was validated.
|
|
96
96
|
*
|
|
97
|
-
* The scheduling rules themselves live in `
|
|
97
|
+
* The scheduling rules themselves live in `events/validation.ts` and are re-applied by
|
|
98
98
|
* the watcher (spec 031, D4); this layer only adds tool-specific framing (channel ownership,
|
|
99
99
|
* and turning validation failures into recoverable tool errors the model can retry).
|
|
100
100
|
*/
|
package/dist/tools/index.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import type { AgentTool } from "@earendil-works/pi-agent-core";
|
|
2
2
|
import type { Api, Model } from "@earendil-works/pi-ai";
|
|
3
|
-
import type { ChannelJobManager } from "../agent/job-manager.js";
|
|
4
3
|
import type { MediaSender } from "../channel/channel-context.js";
|
|
4
|
+
import type { PipiclawSessionSearchSettings } from "../config/settings.js";
|
|
5
|
+
import type { PipiclawToolsConfig } from "../config/tools.js";
|
|
5
6
|
import type { Executor } from "../executor.js";
|
|
6
7
|
import type { FileStore } from "../file-store.js";
|
|
8
|
+
import type { ChannelJobManager } from "../jobs/manager.js";
|
|
7
9
|
import type { ProjectScope } from "../security/project-scope.js";
|
|
8
10
|
import type { SecurityConfig } from "../security/types.js";
|
|
9
|
-
import type { PipiclawSessionSearchSettings } from "../settings.js";
|
|
10
11
|
import { type SubAgentDiscoveryResult } from "../subagents/discovery.js";
|
|
11
12
|
import type { SubAgentRunManager } from "../subagents/runs.js";
|
|
12
|
-
import type { PipiclawToolsConfig } from "./config.js";
|
|
13
13
|
import type { TaskStepCost } from "./task-manage/types.js";
|
|
14
14
|
export interface CreatePipiclawToolsOptions {
|
|
15
15
|
jobManager: ChannelJobManager;
|
|
@@ -27,6 +27,8 @@ export interface CreatePipiclawToolsOptions {
|
|
|
27
27
|
channelId: string;
|
|
28
28
|
getSubAgentDiscovery: () => SubAgentDiscoveryResult;
|
|
29
29
|
getSubAgentModelReference?: () => string | null;
|
|
30
|
+
/** `settings.fallbackModel`, resolved; an internal sub-agent switches to it once on a failed run. */
|
|
31
|
+
resolveFallbackModel?: () => Promise<Model<Api> | null>;
|
|
30
32
|
getSessionSearchSettings: () => PipiclawSessionSearchSettings;
|
|
31
33
|
securityConfig: SecurityConfig;
|
|
32
34
|
toolsConfig: PipiclawToolsConfig;
|
package/dist/tools/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { withSubAgentsDirWriteDeny } from "../subagents/discovery.js";
|
|
2
|
-
import {
|
|
2
|
+
import { withToolDetails } from "./contract/details.js";
|
|
3
3
|
import { buildToolSet } from "./registry.js";
|
|
4
|
+
import { createSubAgentInlineTool, createSubAgentTool } from "./subagent.js";
|
|
4
5
|
import { createSubAgentListTool, createSubAgentRunTool } from "./subagent-manage.js";
|
|
5
|
-
import { withToolDetails } from "./tool-details.js";
|
|
6
6
|
export function createPipiclawTools(options) {
|
|
7
7
|
// Spec 040, D8.1: the main agent's own write/edit tools can write a self-authorizing
|
|
8
8
|
// `runtime: external` role file just as readily as a sub-agent's can; deny it here too.
|
|
@@ -20,7 +20,7 @@ export function createPipiclawTools(options) {
|
|
|
20
20
|
// The leaf tools (files, web, memory, skills) come from the single declarative
|
|
21
21
|
// registry so this set, the sub-agent set, and the prompt hints share one source.
|
|
22
22
|
// The `subagent` tool is appended separately: it is never available to sub-agents
|
|
23
|
-
// and
|
|
23
|
+
// and needs dispatch-time context the registry does not model.
|
|
24
24
|
const taskLoopExcluded = new Set(["task_create", "memory_save", "event_manage"]);
|
|
25
25
|
const leafTools = buildToolSet({
|
|
26
26
|
executor: options.executor,
|
|
@@ -45,6 +45,7 @@ export function createPipiclawTools(options) {
|
|
|
45
45
|
getStepCost: options.getStepCost,
|
|
46
46
|
});
|
|
47
47
|
const subAgentToolOptions = {
|
|
48
|
+
buildWorkerTools: (request) => buildToolSet(request, { forSubagent: true }),
|
|
48
49
|
getRunManager: () => options.runManager,
|
|
49
50
|
executor: options.executor,
|
|
50
51
|
fileStore: options.fileStore,
|
|
@@ -53,12 +54,13 @@ export function createPipiclawTools(options) {
|
|
|
53
54
|
resolveApiKey: options.resolveApiKey,
|
|
54
55
|
workspaceDir: options.workspaceDir,
|
|
55
56
|
// D6.2: an internal sub-agent defaults to the parent's ProjectRoot; a model-requested
|
|
56
|
-
// explicit workingDirectory is validated (in subagents/
|
|
57
|
+
// explicit workingDirectory is validated (in subagents/dispatch.ts) to stay within it.
|
|
57
58
|
workingDirectory: options.projectScope.projectRoot,
|
|
58
59
|
projectBoundary: options.projectScope.boundary,
|
|
59
60
|
channelDir: options.channelDir,
|
|
60
61
|
getSubAgentDiscovery: options.getSubAgentDiscovery,
|
|
61
62
|
getSubAgentModelReference: options.getSubAgentModelReference,
|
|
63
|
+
resolveFallbackModel: options.resolveFallbackModel,
|
|
62
64
|
securityConfig,
|
|
63
65
|
webConfig: toolsConfig.tools.web,
|
|
64
66
|
rtkEnabled: toolsConfig.tools.rtk.enabled,
|
|
@@ -81,8 +83,8 @@ export function createPipiclawTools(options) {
|
|
|
81
83
|
};
|
|
82
84
|
const all = [
|
|
83
85
|
...leafTools,
|
|
84
|
-
// Bound to the same `details` contract as the registry's tools;
|
|
85
|
-
//
|
|
86
|
+
// Bound to the same `details` contract as the registry's tools; registered here rather than
|
|
87
|
+
// in TOOL_REGISTRY because it needs dispatch-time context the registry does not model.
|
|
86
88
|
withToolDetails(createSubAgentTool(subAgentToolOptions), "subagent"),
|
|
87
89
|
// Spec 046, D2.3: gated by `tools.json` (deployer decision, not a model-visible field) —
|
|
88
90
|
// omitted from the tool set entirely when off, not merely rejected at call time.
|
package/dist/tools/job.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { AgentTool } from "@earendil-works/pi-agent-core";
|
|
2
2
|
import { Type } from "typebox";
|
|
3
|
-
import type { ChannelJobManager } from "../
|
|
3
|
+
import type { ChannelJobManager } from "../jobs/manager.js";
|
|
4
4
|
declare const jobSchema: Type.TObject<{
|
|
5
5
|
op: Type.TUnion<[Type.TLiteral<"list">, Type.TLiteral<"poll">, Type.TLiteral<"cancel">]>;
|
|
6
6
|
ids: Type.TOptional<Type.TArray<Type.TString>>;
|
|
@@ -191,7 +191,10 @@ function buildMemoryClosures(options) {
|
|
|
191
191
|
reason: "memory-forget",
|
|
192
192
|
actions: [{ op: "forget", name: trimmed, contentHash: hashMemoryContent(entry.description) }],
|
|
193
193
|
}).catch((error) => {
|
|
194
|
-
log.
|
|
194
|
+
log.logWarn("memory.review_log.write_failed", "Memory review log write failed", {
|
|
195
|
+
channelId: options.channelId,
|
|
196
|
+
reason: errorMessage(error),
|
|
197
|
+
});
|
|
195
198
|
});
|
|
196
199
|
return textResult(`Removed \`${trimmed}\` from channel memory. Its content is tombstoned against automatic replay; if the fact is stated again later it may be re-learned. Journal and session history are unchanged.`, { forgotten: true, name: trimmed });
|
|
197
200
|
}
|
package/dist/tools/registry.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import type { AgentTool } from "@earendil-works/pi-agent-core";
|
|
2
2
|
import type { Api, Model } from "@earendil-works/pi-ai";
|
|
3
|
-
import type { ChannelJobManager } from "../agent/job-manager.js";
|
|
4
3
|
import type { MediaSender } from "../channel/channel-context.js";
|
|
4
|
+
import type { PipiclawSessionSearchSettings } from "../config/settings.js";
|
|
5
|
+
import type { PipiclawToolsConfig, PipiclawWebToolsConfig } from "../config/tools.js";
|
|
5
6
|
import type { Executor } from "../executor.js";
|
|
6
7
|
import type { FileStore } from "../file-store.js";
|
|
8
|
+
import type { ChannelJobManager } from "../jobs/manager.js";
|
|
7
9
|
import type { SecurityConfig, SecurityRuntimeContext } from "../security/types.js";
|
|
8
|
-
import type { PipiclawSessionSearchSettings } from "../settings.js";
|
|
9
10
|
import type { SubAgentRunManager } from "../subagents/runs.js";
|
|
10
|
-
import
|
|
11
|
+
import { type ToolDetailsKind } from "./contract/details.js";
|
|
11
12
|
import type { TaskStepCost } from "./task-manage/types.js";
|
|
12
|
-
import { type ToolDetailsKind } from "./tool-details.js";
|
|
13
13
|
/**
|
|
14
14
|
* Unified build context passed to every tool's `create` closure. It carries the union
|
|
15
15
|
* of everything any registered tool might need; each closure reads only its own fields.
|
|
@@ -79,9 +79,9 @@ export interface ToolRegistration {
|
|
|
79
79
|
}
|
|
80
80
|
/**
|
|
81
81
|
* Single source of truth for the agent's leaf tools. The `subagent` tool is intentionally
|
|
82
|
-
* NOT here: it is never available to sub-agents
|
|
83
|
-
*
|
|
84
|
-
*
|
|
82
|
+
* NOT here: it is never available to sub-agents and needs dispatch-time context (role
|
|
83
|
+
* discovery, model resolvers, the run manager) that `ToolBuildContext` does not model; see
|
|
84
|
+
* `tools/subagent.ts` and `tools/index.ts`.
|
|
85
85
|
*/
|
|
86
86
|
export declare const TOOL_REGISTRY: ToolRegistration[];
|
|
87
87
|
/**
|
package/dist/tools/registry.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { createBashTool } from "./bash.js";
|
|
2
|
+
import { withToolDetails } from "./contract/details.js";
|
|
3
|
+
import { SUBAGENT_TOOL_NAMES } from "./contract/names.js";
|
|
2
4
|
import { createEditTool } from "./edit.js";
|
|
3
5
|
import { createEventManageTool } from "./event-manage.js";
|
|
4
6
|
import { createGlobTool } from "./glob.js";
|
|
@@ -9,9 +11,7 @@ import { createReadTool } from "./read.js";
|
|
|
9
11
|
import { createSendMediaTool } from "./send-media.js";
|
|
10
12
|
import { createSessionSearchTool } from "./session-search.js";
|
|
11
13
|
import { createSkillTool } from "./skill.js";
|
|
12
|
-
import {
|
|
13
|
-
import { createTaskCloseTool, createTaskCreateTool, createTaskListTool, createTaskLogTool, createTaskStepEndTool, createTaskUpdateTool, } from "./task-manage.js";
|
|
14
|
-
import { withToolDetails } from "./tool-details.js";
|
|
14
|
+
import { createTaskCloseTool, createTaskCreateTool, createTaskListTool, createTaskLogTool, createTaskStepEndTool, createTaskUpdateTool, } from "./task-manage/factory.js";
|
|
15
15
|
import { createWebFetchTool } from "./web-fetch.js";
|
|
16
16
|
import { createWebSearchTool } from "./web-search.js";
|
|
17
17
|
import { createWriteTool } from "./write.js";
|
|
@@ -47,9 +47,9 @@ function webEnabled(ctx) {
|
|
|
47
47
|
}
|
|
48
48
|
/**
|
|
49
49
|
* Single source of truth for the agent's leaf tools. The `subagent` tool is intentionally
|
|
50
|
-
* NOT here: it is never available to sub-agents
|
|
51
|
-
*
|
|
52
|
-
*
|
|
50
|
+
* NOT here: it is never available to sub-agents and needs dispatch-time context (role
|
|
51
|
+
* discovery, model resolvers, the run manager) that `ToolBuildContext` does not model; see
|
|
52
|
+
* `tools/subagent.ts` and `tools/index.ts`.
|
|
53
53
|
*/
|
|
54
54
|
export const TOOL_REGISTRY = [
|
|
55
55
|
{
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { AgentTool } from "@earendil-works/pi-agent-core";
|
|
2
2
|
import type { Api, Model } from "@earendil-works/pi-ai";
|
|
3
3
|
import { Type } from "typebox";
|
|
4
|
-
import type { PipiclawSessionSearchSettings } from "../settings.js";
|
|
4
|
+
import type { PipiclawSessionSearchSettings } from "../config/settings.js";
|
|
5
5
|
declare const sessionSearchSchema: Type.TObject<{
|
|
6
6
|
query: Type.TOptional<Type.TString>;
|
|
7
7
|
limit: Type.TOptional<Type.TInteger>;
|
package/dist/tools/skill.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { AgentTool } from "@earendil-works/pi-agent-core";
|
|
2
2
|
import { Type } from "typebox";
|
|
3
|
-
import
|
|
3
|
+
import { type WorkspaceSkillOptions } from "../skills/workspace.js";
|
|
4
4
|
/**
|
|
5
5
|
* `skill` is deliberately read-only. Authoring a workspace skill goes through the generic
|
|
6
6
|
* `write`/`edit` tools writing `workspace/skills/<name>/SKILL.md` directly — a low-frequency path
|
|
@@ -12,37 +12,5 @@ declare const skillSchema: Type.TObject<{
|
|
|
12
12
|
action: Type.TUnion<[Type.TLiteral<"list">, Type.TLiteral<"read">]>;
|
|
13
13
|
name: Type.TOptional<Type.TString>;
|
|
14
14
|
}>;
|
|
15
|
-
export
|
|
16
|
-
name: string;
|
|
17
|
-
description: string;
|
|
18
|
-
path: string;
|
|
19
|
-
warning?: string;
|
|
20
|
-
}
|
|
21
|
-
export interface SkillToolOptions {
|
|
22
|
-
workspaceDir: string;
|
|
23
|
-
securityConfig?: SecurityConfig;
|
|
24
|
-
securityContext?: SecurityRuntimeContext;
|
|
25
|
-
channelId?: string;
|
|
26
|
-
}
|
|
27
|
-
export declare function listWorkspaceSkills(options: {
|
|
28
|
-
workspaceDir: string;
|
|
29
|
-
securityConfig?: SecurityConfig;
|
|
30
|
-
securityContext?: SecurityRuntimeContext;
|
|
31
|
-
}): Promise<WorkspaceSkillSummary[]>;
|
|
32
|
-
export interface WorkspaceSkillFile {
|
|
33
|
-
name: string;
|
|
34
|
-
/** The guard-resolved path actually opened — never the raw pre-guard path. */
|
|
35
|
-
path: string;
|
|
36
|
-
content: string;
|
|
37
|
-
truncated: boolean;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Load one skill's `SKILL.md` bytes through the same path-guard every other file read goes
|
|
41
|
-
* through. Shared by the `skill` tool's `read` action and the `/skills show` runtime command
|
|
42
|
-
* (`src/runtime/skill-commands.ts`) — a `SKILL.md` that is itself a symlink pointing outside
|
|
43
|
-
* `workspace/skills/` (planted via `bash ln -s`, not via `name` -- `resolveSkillPath` already
|
|
44
|
-
* confines that) is caught here in both callers instead of being read verbatim.
|
|
45
|
-
*/
|
|
46
|
-
export declare function loadWorkspaceSkillFile(options: SkillToolOptions, name: string): Promise<WorkspaceSkillFile>;
|
|
47
|
-
export declare function createSkillTool(options: SkillToolOptions): AgentTool<typeof skillSchema>;
|
|
15
|
+
export declare function createSkillTool(options: WorkspaceSkillOptions): AgentTool<typeof skillSchema>;
|
|
48
16
|
export {};
|
package/dist/tools/skill.js
CHANGED
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { readdir, readFile, stat } from "node:fs/promises";
|
|
3
|
-
import { dirname, join } from "node:path";
|
|
1
|
+
import { dirname } from "node:path";
|
|
4
2
|
import { Type } from "typebox";
|
|
5
|
-
import { DEFAULT_SECURITY_CONFIG } from "../security/config.js";
|
|
6
|
-
import { checkPathGuard } from "../security/path-guard-check.js";
|
|
7
|
-
import { readGuardAllows } from "../security/path-guard-filter.js";
|
|
8
|
-
import { isNodeError } from "../shared/os.js";
|
|
9
3
|
import { RecoverableToolError } from "../shared/recoverable-error.js";
|
|
10
|
-
import {
|
|
4
|
+
import { listWorkspaceSkills, loadWorkspaceSkillFile } from "../skills/workspace.js";
|
|
11
5
|
import { DEFAULT_MAX_BYTES, formatSize, truncateHead } from "./truncate.js";
|
|
12
6
|
/**
|
|
13
7
|
* `skill` is deliberately read-only. Authoring a workspace skill goes through the generic
|
|
@@ -22,125 +16,23 @@ const skillSchema = Type.Object({
|
|
|
22
16
|
}),
|
|
23
17
|
name: Type.Optional(Type.String({ description: "Exact workspace skill name from the list (required for read)." })),
|
|
24
18
|
});
|
|
25
|
-
function
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
return "";
|
|
29
|
-
}
|
|
30
|
-
for (const line of (match[1] ?? "").split("\n")) {
|
|
31
|
-
const fieldMatch = line.match(/^description:\s*(.*)$/);
|
|
32
|
-
if (fieldMatch) {
|
|
33
|
-
return fieldMatch[1].replace(/^["']|["']$/g, "").trim();
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return "";
|
|
37
|
-
}
|
|
38
|
-
export async function listWorkspaceSkills(options) {
|
|
39
|
-
const skillsDir = join(options.workspaceDir, "skills");
|
|
40
|
-
// `skill read` runs each SKILL.md through the path guard (`loadWorkspaceSkillFile`); `list`
|
|
41
|
-
// must apply the same guard so a skill whose SKILL.md is a symlink out of `workspace/skills/`
|
|
42
|
-
// is silently omitted here too, rather than being advertised and then refused on read.
|
|
43
|
-
const guardConfig = options.securityConfig ?? DEFAULT_SECURITY_CONFIG;
|
|
44
|
-
const guardContext = options.securityContext ?? {
|
|
45
|
-
agentWorkspaceDir: options.workspaceDir,
|
|
46
|
-
projectRoot: options.workspaceDir,
|
|
47
|
-
};
|
|
48
|
-
let names;
|
|
49
|
-
try {
|
|
50
|
-
names = await readdir(skillsDir);
|
|
51
|
-
}
|
|
52
|
-
catch (error) {
|
|
53
|
-
if (isNodeError(error) && error.code === "ENOENT") {
|
|
54
|
-
return [];
|
|
55
|
-
}
|
|
56
|
-
throw error;
|
|
57
|
-
}
|
|
58
|
-
const summaries = [];
|
|
59
|
-
for (const name of names.sort()) {
|
|
60
|
-
const nameValidation = validateSkillName(name);
|
|
61
|
-
if (!nameValidation.ok) {
|
|
62
|
-
continue;
|
|
63
|
-
}
|
|
64
|
-
const skillDir = join(skillsDir, name);
|
|
65
|
-
const skillStats = await stat(skillDir).catch(() => null);
|
|
66
|
-
if (!skillStats?.isDirectory()) {
|
|
67
|
-
continue;
|
|
68
|
-
}
|
|
69
|
-
const skillPath = join(skillDir, "SKILL.md");
|
|
70
|
-
if (!readGuardAllows(skillPath, guardConfig, guardContext)) {
|
|
71
|
-
continue;
|
|
72
|
-
}
|
|
73
|
-
let content;
|
|
74
|
-
try {
|
|
75
|
-
const skillFileStats = await stat(skillPath);
|
|
76
|
-
if (!skillFileStats.isFile()) {
|
|
77
|
-
continue;
|
|
78
|
-
}
|
|
79
|
-
content = await readFile(skillPath, "utf-8");
|
|
80
|
-
}
|
|
81
|
-
catch (error) {
|
|
82
|
-
if (isNodeError(error) && error.code === "ENOENT") {
|
|
83
|
-
continue;
|
|
84
|
-
}
|
|
85
|
-
throw error;
|
|
86
|
-
}
|
|
87
|
-
const validation = validateSkillFrontmatter(content, name);
|
|
88
|
-
const scan = validation.ok ? scanSkillContent(content) : validation;
|
|
89
|
-
summaries.push({
|
|
90
|
-
name,
|
|
91
|
-
description: extractDescription(content),
|
|
92
|
-
path: `${options.workspaceDir}/skills/${name}/SKILL.md`,
|
|
93
|
-
warning: scan.ok ? undefined : scan.error,
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
return summaries;
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Load one skill's `SKILL.md` bytes through the same path-guard every other file read goes
|
|
100
|
-
* through. Shared by the `skill` tool's `read` action and the `/skills show` runtime command
|
|
101
|
-
* (`src/runtime/skill-commands.ts`) — a `SKILL.md` that is itself a symlink pointing outside
|
|
102
|
-
* `workspace/skills/` (planted via `bash ln -s`, not via `name` -- `resolveSkillPath` already
|
|
103
|
-
* confines that) is caught here in both callers instead of being read verbatim.
|
|
104
|
-
*/
|
|
105
|
-
export async function loadWorkspaceSkillFile(options, name) {
|
|
106
|
-
const nameValidation = validateSkillName(name);
|
|
107
|
-
if (!nameValidation.ok) {
|
|
108
|
-
throw new RecoverableToolError(nameValidation.error ?? `Invalid skill name "${name}".`);
|
|
109
|
-
}
|
|
110
|
-
const skillDir = resolveSkillPath(options.workspaceDir, name);
|
|
111
|
-
const rawPath = join(skillDir, "SKILL.md");
|
|
112
|
-
if (!existsSync(rawPath)) {
|
|
113
|
-
throw new RecoverableToolError(`Workspace skill "${name}" does not exist. Use action "list" to see what's available.`);
|
|
114
|
-
}
|
|
115
|
-
const securityConfig = options.securityConfig ?? DEFAULT_SECURITY_CONFIG;
|
|
116
|
-
const securityContext = options.securityContext ?? {
|
|
117
|
-
agentWorkspaceDir: options.workspaceDir,
|
|
118
|
-
projectRoot: options.workspaceDir,
|
|
119
|
-
};
|
|
120
|
-
const target = await checkPathGuard(rawPath, "read", securityConfig, securityContext, {
|
|
121
|
-
tool: "skill",
|
|
122
|
-
channelId: options.channelId,
|
|
123
|
-
});
|
|
124
|
-
const content = await readFile(target, "utf-8");
|
|
125
|
-
const truncation = truncateHead(content);
|
|
19
|
+
async function readWorkspaceSkill(options, name) {
|
|
20
|
+
const file = await loadWorkspaceSkillFile(options, name);
|
|
21
|
+
const truncation = truncateHead(file.content);
|
|
126
22
|
let body = truncation.content;
|
|
127
23
|
if (truncation.truncated) {
|
|
128
|
-
body += `\n\n[Truncated at ${formatSize(DEFAULT_MAX_BYTES)}. Use the read tool on ${
|
|
24
|
+
body += `\n\n[Truncated at ${formatSize(DEFAULT_MAX_BYTES)}. Use the read tool on ${file.path} to page through the rest.]`;
|
|
129
25
|
}
|
|
130
|
-
return { name, path: target, content: body, truncated: truncation.truncated };
|
|
131
|
-
}
|
|
132
|
-
async function readWorkspaceSkill(options, name) {
|
|
133
|
-
const file = await loadWorkspaceSkillFile(options, name);
|
|
134
26
|
// Mirrors the framing pi's own skill loader gives a model-invoked skill: the location and the
|
|
135
27
|
// relative-path rule are what let the model correctly `read` a skill's references/templates
|
|
136
28
|
// afterward, and are the whole reason `skill read` is worth more than a plain `read` call.
|
|
137
29
|
const envelope = `<skill name="${file.name}" location="${file.path}">\n` +
|
|
138
30
|
`References are relative to ${dirname(file.path)}.\n\n` +
|
|
139
|
-
`${
|
|
31
|
+
`${body}\n` +
|
|
140
32
|
`</skill>`;
|
|
141
33
|
return {
|
|
142
34
|
content: [{ type: "text", text: envelope }],
|
|
143
|
-
details: { action: "read", name: file.name, path: file.path, truncated:
|
|
35
|
+
details: { action: "read", name: file.name, path: file.path, truncated: truncation.truncated },
|
|
144
36
|
};
|
|
145
37
|
}
|
|
146
38
|
export function createSkillTool(options) {
|
|
@@ -15,7 +15,7 @@ export interface SubAgentManageToolOptions {
|
|
|
15
15
|
/**
|
|
16
16
|
* Spec 042 D7: required, not defaulted. `follow_up` dispatches a new external process through
|
|
17
17
|
* the same envelope and audit path the initial dispatch uses (D9's verify task path, D8.1's
|
|
18
|
-
* audit log, D7's `
|
|
18
|
+
* audit log, D7's `buildFollowUpTask`) — all of which need the real value. The previous
|
|
19
19
|
* `options.workspaceDir ?? ""` silently pointed the audit log at the daemon's own cwd and
|
|
20
20
|
* malformed the verify task path; production has always supplied both, so making them required
|
|
21
21
|
* only tightens what was already true rather than changing production behavior.
|
|
@@ -4,10 +4,13 @@ import { Type } from "typebox";
|
|
|
4
4
|
import { DEFAULT_SECURITY_CONFIG } from "../security/config.js";
|
|
5
5
|
import { RecoverableToolError } from "../shared/recoverable-error.js";
|
|
6
6
|
import { externalRoleFingerprint, validateSubAgentTask } from "../subagents/discovery.js";
|
|
7
|
+
import { assertWithinProjectBoundary } from "../subagents/dispatch.js";
|
|
8
|
+
import { readLastOutputAt, STALL_THRESHOLD_MS } from "../subagents/external/progress-tail.js";
|
|
7
9
|
import { launchExternalRun } from "../subagents/external/run.js";
|
|
8
10
|
import { formatCost, formatRunDuration, harnessLabel } from "../subagents/format.js";
|
|
9
|
-
import { assertVerifyAdmissible,
|
|
11
|
+
import { assertVerifyAdmissible, buildFollowUpTask } from "../subagents/task-envelope.js";
|
|
10
12
|
import { acquireWorkspaceLease, formatWorkspaceLeaseConflict, releaseWorkspaceLease, } from "../subagents/workspace-lease.js";
|
|
13
|
+
import { snapshotWorkspace } from "../subagents/workspace-summary.js";
|
|
11
14
|
// Spec 047, P3: `subagent_list` is zero-argument and shape-independent (like `task_list`); the
|
|
12
15
|
// other three ops all take `runId`, so they stay together in `subagent_run` rather than being
|
|
13
16
|
// split per-verb (`cancel` and `show` have identical parameter sets).
|
|
@@ -21,7 +24,7 @@ const subagentRunSchema = Type.Object({
|
|
|
21
24
|
});
|
|
22
25
|
/** Spec 042 D9: cap on `op=list`'s output — see the call site for why running runs are exempt. */
|
|
23
26
|
const LIST_CAP = 50;
|
|
24
|
-
/** Matches `/subagents show`'s own cap (`
|
|
27
|
+
/** Matches `/subagents show`'s own cap (`subagents/commands.ts`) — enough to diagnose a
|
|
25
28
|
* failure without dumping an unbounded log into the model's context. */
|
|
26
29
|
const STDERR_TAIL_CHARS = 2_000;
|
|
27
30
|
function formatRunLine(record) {
|
|
@@ -36,7 +39,7 @@ function formatRunLine(record) {
|
|
|
36
39
|
return header;
|
|
37
40
|
}
|
|
38
41
|
/**
|
|
39
|
-
* The machine-readable subset of `/subagents show` (`
|
|
42
|
+
* The machine-readable subset of `/subagents show` (`subagents/commands.ts`'s `showRun`):
|
|
40
43
|
* argv, dispatch-time warnings, and the adapter/CLI version pair the model previously had no way
|
|
41
44
|
* to see at all — it could only guess at a failed external run's cause or re-dispatch blindly
|
|
42
45
|
* (review 2026-08-23 §3.4).
|
|
@@ -73,6 +76,13 @@ async function formatRunShow(record) {
|
|
|
73
76
|
}
|
|
74
77
|
if (record.sessionId)
|
|
75
78
|
lines.push(`sessionId: ${record.sessionId} (usable with subagent_run op=follow_up)`);
|
|
79
|
+
if (record.runtime === "external" && record.status === "running") {
|
|
80
|
+
// The one signal that tells a long, busy run apart from a stuck one without reading its logs.
|
|
81
|
+
const lastOutputAt = await readLastOutputAt(record.artifactDir);
|
|
82
|
+
const silentMs = Date.now() - (lastOutputAt ?? record.processStartedAt ?? record.startedAt);
|
|
83
|
+
const stalled = silentMs >= STALL_THRESHOLD_MS ? " — possibly stalled; cancel if it should have progressed" : "";
|
|
84
|
+
lines.push(`last output: ${Math.round(silentMs / 1000)}s ago${stalled}`);
|
|
85
|
+
}
|
|
76
86
|
if (record.runtime === "external") {
|
|
77
87
|
const stderrTail = await readFile(join(record.artifactDir, "stderr.log"), "utf-8")
|
|
78
88
|
.then((text) => text.slice(-STDERR_TAIL_CHARS))
|
|
@@ -237,18 +247,13 @@ export function createSubAgentRunTool(options) {
|
|
|
237
247
|
workingDirectory: record.workingDirectory,
|
|
238
248
|
artifactDir,
|
|
239
249
|
};
|
|
240
|
-
//
|
|
241
|
-
//
|
|
242
|
-
//
|
|
243
|
-
// that left the external agent unaware of its own working/artifact directories.
|
|
250
|
+
// The resumed session already holds the first dispatch's full envelope; the follow-up
|
|
251
|
+
// envelope carries only what is new (its own artifact directory, the instruction, and the
|
|
252
|
+
// checker protocol again for a verify run) — see `buildFollowUpTask`.
|
|
244
253
|
let launchResult;
|
|
245
254
|
try {
|
|
246
|
-
const
|
|
247
|
-
|
|
248
|
-
workspaceDir: options.workspaceDir,
|
|
249
|
-
runtimeContext: { workspaceDir: options.workspaceDir, channelId: options.channelId },
|
|
250
|
-
});
|
|
251
|
-
const envelopedTask = buildSubAgentTask(task, role, { workspaceDir: options.workspaceDir, channelId: options.channelId }, contextualBlocks, runContext);
|
|
255
|
+
const envelopedTask = buildFollowUpTask(task, { workspaceDir: options.workspaceDir, channelId: options.channelId }, runContext);
|
|
256
|
+
const workspaceBaseline = role.mutates === "write" ? await snapshotWorkspace(record.workingDirectory) : undefined;
|
|
252
257
|
launchResult = await launchExternalRun({
|
|
253
258
|
runManager: manager,
|
|
254
259
|
runId: newRunId,
|
|
@@ -274,6 +279,7 @@ export function createSubAgentRunTool(options) {
|
|
|
274
279
|
leaseKey,
|
|
275
280
|
resumeSessionId: record.sessionId,
|
|
276
281
|
mutates: role.mutates,
|
|
282
|
+
workspaceBaseline,
|
|
277
283
|
roleFingerprint: currentFingerprint,
|
|
278
284
|
workspaceDir: options.workspaceDir,
|
|
279
285
|
securityConfig: options.securityConfig ?? DEFAULT_SECURITY_CONFIG,
|