@oyasmi/pipiclaw 0.9.5 → 0.9.6-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +300 -142
- package/README.md +295 -140
- package/dist/agent/builtin-commands.d.ts +1 -1
- package/dist/agent/builtin-commands.js +1 -1
- package/dist/agent/channel-runner.d.ts +4 -3
- package/dist/agent/channel-runner.js +17 -28
- package/dist/agent/maintenance-context.js +2 -2
- package/dist/agent/prompt/builder.d.ts +1 -1
- package/dist/agent/prompt/builder.js +1 -1
- package/dist/agent/prompt/extension.d.ts +1 -1
- package/dist/agent/prompt/extension.js +1 -1
- package/dist/agent/prompt/manifest.d.ts +6 -1
- package/dist/agent/prompt/manifest.js +12 -5
- package/dist/agent/prompt/resources.d.ts +0 -3
- package/dist/agent/prompt/resources.js +0 -6
- package/dist/agent/prompt/sections.d.ts +2 -2
- package/dist/agent/prompt/sections.js +36 -26
- package/dist/agent/prompt/types.d.ts +3 -2
- package/dist/agent/runner-factory.js +1 -1
- package/dist/agent/session/command-extension.js +3 -1
- package/dist/agent/session/compaction-summary.js +3 -6
- package/dist/agent/session/compaction.d.ts +2 -0
- package/dist/agent/session/compaction.js +22 -14
- package/dist/agent/session/event-guards.d.ts +2 -1
- package/dist/agent/session/event-guards.js +6 -0
- package/dist/agent/session/model-selection.d.ts +2 -1
- package/dist/agent/session/model-selection.js +5 -5
- package/dist/agent/session/session-events.js +31 -4
- package/dist/agent/session/session-host.d.ts +5 -3
- package/dist/agent/session/session-host.js +20 -16
- package/dist/agent/status-render.js +3 -0
- package/dist/agent/stop-watchdog.js +5 -1
- package/dist/agent/turn/task-digest.d.ts +2 -5
- package/dist/agent/turn/task-digest.js +25 -45
- package/dist/agent/turn/turn-context.js +4 -6
- package/dist/agent/turn/turn-error.d.ts +1 -1
- package/dist/agent/turn/turn-error.js +9 -0
- package/dist/agent/turn/turn-pipeline.d.ts +10 -5
- package/dist/agent/turn/turn-pipeline.js +36 -7
- package/dist/agent/turn/turn-prompt.d.ts +2 -0
- package/dist/agent/turn/turn-prompt.js +2 -1
- package/dist/agent/turn/turn-recovery.js +4 -1
- package/dist/agent/turn/turn-state.d.ts +2 -0
- package/dist/agent/turn/turn-state.js +2 -1
- package/dist/agent/types.d.ts +23 -3
- package/dist/agent/types.js +2 -0
- package/dist/app/auth-command.d.ts +25 -0
- package/dist/app/auth-command.js +200 -67
- package/dist/app/home.d.ts +7 -8
- package/dist/app/home.js +143 -56
- package/dist/channel/attachments.d.ts +4 -0
- package/dist/channel/attachments.js +4 -0
- package/dist/channel/channel-context.d.ts +6 -0
- package/dist/channel/config.d.ts +3 -0
- package/dist/channel/config.js +11 -5
- package/dist/channel/store.d.ts +1 -1
- package/dist/commands/catalog.js +42 -10
- package/dist/commands/router.js +5 -1
- package/dist/desk/commands.d.ts +44 -5
- package/dist/desk/commands.js +162 -28
- package/dist/desk/paths.d.ts +6 -0
- package/dist/desk/paths.js +21 -1
- package/dist/desk/registry.d.ts +17 -2
- package/dist/desk/registry.js +122 -12
- package/dist/desk/types.d.ts +83 -1
- package/dist/dingtalk/bot.d.ts +1 -1
- package/dist/dingtalk/bot.js +4 -3
- package/dist/dingtalk/config.js +10 -10
- package/dist/dingtalk/delivery.js +15 -8
- package/dist/dingtalk/inbound-media.d.ts +36 -14
- package/dist/dingtalk/inbound-media.js +71 -12
- package/dist/dingtalk/inbound.d.ts +9 -2
- package/dist/dingtalk/inbound.js +17 -2
- package/dist/dingtalk/media.d.ts +4 -10
- package/dist/dingtalk/media.js +58 -32
- package/dist/events/commands.d.ts +2 -0
- package/dist/events/commands.js +13 -8
- package/dist/events/history.d.ts +9 -0
- package/dist/events/history.js +66 -0
- package/dist/events/parse.js +7 -3
- package/dist/events/types.d.ts +3 -0
- package/dist/events/watcher.d.ts +4 -8
- package/dist/events/watcher.js +53 -58
- package/dist/jobs/kill.d.ts +23 -0
- package/dist/jobs/kill.js +65 -0
- package/dist/jobs/manager.d.ts +19 -18
- package/dist/jobs/manager.js +36 -103
- package/dist/main.js +15 -3
- package/dist/memory/boundary-work.d.ts +2 -1
- package/dist/memory/boundary-work.js +1 -1
- package/dist/memory/lifecycle.d.ts +2 -1
- package/dist/memory/lifecycle.js +2 -2
- package/dist/memory/reflect-job.d.ts +2 -1
- package/dist/memory/reflect-job.js +1 -1
- package/dist/memory/reflect.d.ts +2 -1
- package/dist/memory/reflect.js +25 -4
- package/dist/memory/scheduler.d.ts +2 -1
- package/dist/memory/scheduler.js +1 -1
- package/dist/memory/session-corpus.d.ts +1 -1
- package/dist/memory/session-corpus.js +76 -1
- package/dist/memory/session-search.d.ts +2 -1
- package/dist/memory/session-search.js +14 -12
- package/dist/memory/sidecar-worker.d.ts +2 -1
- package/dist/memory/sidecar-worker.js +2 -4
- package/dist/memory/store.d.ts +2 -0
- package/dist/memory/store.js +19 -9
- package/dist/models/credential-work.d.ts +7 -0
- package/dist/models/credential-work.js +36 -0
- package/dist/models/login-ui.js +4 -4
- package/dist/models/provider-login.js +7 -6
- package/dist/models/requests.d.ts +8 -0
- package/dist/models/requests.js +69 -0
- package/dist/models/runtime.d.ts +3 -1
- package/dist/models/runtime.js +9 -2
- package/dist/playbooks/agent-delegation.md +20 -45
- package/dist/playbooks/background-jobs.md +1 -1
- package/dist/playbooks/catalog.js +1 -1
- package/dist/playbooks/delegation-inline.md +25 -0
- package/dist/playbooks/delegation-recovery.md +28 -0
- package/dist/playbooks/event-scheduling.md +18 -37
- package/dist/playbooks/event-sensors.md +26 -0
- package/dist/playbooks/event-task-template.md +22 -0
- package/dist/playbooks/learning-and-skills.md +26 -0
- package/dist/playbooks/memory-operations.md +36 -0
- package/dist/playbooks/outbound-media.md +2 -2
- package/dist/playbooks/runtime-files.md +29 -0
- package/dist/playbooks/runtime-operations.md +25 -0
- package/dist/playbooks/runtime-orientation.md +18 -53
- package/dist/playbooks/task-lead.md +22 -68
- package/dist/playbooks/task-manage.md +38 -0
- package/dist/playbooks/task-recovery.md +24 -0
- package/dist/playbooks/task-verify.md +22 -0
- package/dist/runtime/bootstrap.d.ts +10 -0
- package/dist/runtime/bootstrap.js +93 -29
- package/dist/runtime/daemon-lock.js +3 -3
- package/dist/runtime/desk-runtime.d.ts +40 -7
- package/dist/runtime/desk-runtime.js +330 -44
- package/dist/runtime/durable-dispatch.d.ts +14 -2
- package/dist/runtime/durable-dispatch.js +207 -65
- package/dist/runtime/ingress-busy.js +17 -8
- package/dist/runtime/ingress-commands.js +24 -4
- package/dist/runtime/ingress-deps.d.ts +4 -1
- package/dist/runtime/ingress.js +6 -1
- package/dist/runtime/request-execution.js +7 -6
- package/dist/runtime/shutdown.d.ts +4 -1
- package/dist/runtime/shutdown.js +88 -35
- package/dist/runtime/task-close.d.ts +1 -1
- package/dist/runtime/task-close.js +6 -3
- package/dist/runtime/task-control.d.ts +2 -3
- package/dist/runtime/task-control.js +38 -11
- package/dist/runtime/task-input.js +1 -1
- package/dist/runtime/task-lane-types.d.ts +12 -2
- package/dist/runtime/task-lane-types.js +9 -0
- package/dist/runtime/task-lane.d.ts +2 -0
- package/dist/runtime/task-lane.js +38 -20
- package/dist/runtime/task-step.d.ts +3 -3
- package/dist/runtime/task-step.js +34 -16
- package/dist/runtime/transports.js +6 -5
- package/dist/runtime/turn-run.js +103 -66
- package/dist/security/command-guard.d.ts +1 -1
- package/dist/security/command-guard.js +259 -314
- package/dist/security/path-guard.js +48 -7
- package/dist/security/shell-parse.d.ts +10 -0
- package/dist/security/shell-parse.js +224 -0
- package/dist/security/types.d.ts +2 -0
- package/dist/subagents/commands.d.ts +1 -1
- package/dist/subagents/commands.js +14 -5
- package/dist/subagents/completion-wake.js +6 -0
- package/dist/subagents/detached-discovery.d.ts +1 -1
- package/dist/subagents/discovery.d.ts +18 -199
- package/dist/subagents/discovery.js +35 -289
- package/dist/subagents/dispatch.d.ts +1 -2
- package/dist/subagents/dispatch.js +50 -29
- package/dist/subagents/external/antigravity-cli.d.ts +2 -0
- package/dist/subagents/external/antigravity-cli.js +517 -0
- package/dist/subagents/external/claude-code.js +8 -17
- package/dist/subagents/external/codex-cli.js +8 -18
- package/dist/subagents/external/cursor-cli.js +34 -31
- package/dist/subagents/external/dispatch.d.ts +21 -7
- package/dist/subagents/external/dispatch.js +146 -12
- package/dist/subagents/external/exec.js +3 -0
- package/dist/subagents/external/harness.d.ts +57 -33
- package/dist/subagents/external/harness.js +69 -40
- package/dist/subagents/external/reconciliation.js +1 -0
- package/dist/subagents/external/registry.js +4 -1
- package/dist/subagents/external/role-warnings.d.ts +4 -13
- package/dist/subagents/external/role-warnings.js +4 -28
- package/dist/subagents/external/run.d.ts +1 -2
- package/dist/subagents/external/run.js +16 -26
- package/dist/subagents/external/settlement.d.ts +2 -0
- package/dist/subagents/external/settlement.js +13 -3
- package/dist/subagents/format.d.ts +1 -1
- package/dist/subagents/format.js +1 -1
- package/dist/subagents/internal/outcome.d.ts +1 -2
- package/dist/subagents/internal/outcome.js +19 -12
- package/dist/subagents/internal/provider-retry.d.ts +1 -2
- package/dist/subagents/internal/provider-retry.js +2 -4
- package/dist/subagents/internal/run.d.ts +2 -3
- package/dist/subagents/internal/run.js +27 -4
- package/dist/subagents/internal/state.d.ts +2 -5
- package/dist/subagents/internal/state.js +1 -2
- package/dist/subagents/internal/worker.d.ts +1 -2
- package/dist/subagents/internal/worker.js +20 -10
- package/dist/subagents/resolve.d.ts +56 -0
- package/dist/subagents/resolve.js +202 -0
- package/dist/subagents/result.d.ts +6 -4
- package/dist/subagents/result.js +39 -6
- package/dist/subagents/run-record.d.ts +54 -2
- package/dist/subagents/run-record.js +7 -0
- package/dist/subagents/runs.d.ts +6 -31
- package/dist/subagents/runs.js +26 -31
- package/dist/subagents/task-envelope.d.ts +1 -2
- package/dist/subagents/task-envelope.js +13 -4
- package/dist/subagents/task-settlement.js +1 -0
- package/dist/subagents/types.d.ts +105 -6
- package/dist/subagents/types.js +16 -1
- package/dist/subagents/workspace-lease.d.ts +41 -24
- package/dist/subagents/workspace-lease.js +159 -24
- package/dist/subagents/worktree.d.ts +52 -0
- package/dist/subagents/worktree.js +363 -0
- package/dist/tasks/archive.js +4 -0
- package/dist/tasks/brief.d.ts +5 -1
- package/dist/tasks/brief.js +19 -5
- package/dist/tasks/commands.d.ts +6 -1
- package/dist/tasks/commands.js +32 -7
- package/dist/tasks/control.d.ts +11 -0
- package/dist/tasks/delivery.d.ts +2 -0
- package/dist/tasks/delivery.js +141 -21
- package/dist/tasks/loop-log.d.ts +12 -0
- package/dist/tasks/loop-log.js +10 -1
- package/dist/tasks/receipts.d.ts +7 -3
- package/dist/tasks/receipts.js +34 -5
- package/dist/tools/bash.d.ts +3 -0
- package/dist/tools/bash.js +29 -15
- package/dist/tools/contract/presentation.js +7 -5
- package/dist/tools/edit-diff.d.ts +11 -0
- package/dist/tools/edit-diff.js +148 -0
- package/dist/tools/edit-match.d.ts +18 -0
- package/dist/tools/edit-match.js +242 -0
- package/dist/tools/edit.d.ts +10 -2
- package/dist/tools/edit.js +91 -361
- package/dist/tools/event-manage.d.ts +2 -1
- package/dist/tools/event-manage.js +46 -39
- package/dist/tools/file-observations.d.ts +9 -0
- package/dist/tools/file-observations.js +50 -0
- package/dist/tools/glob-match.d.ts +3 -1
- package/dist/tools/glob-match.js +40 -17
- package/dist/tools/glob.d.ts +1 -0
- package/dist/tools/glob.js +39 -19
- package/dist/tools/grep-command.d.ts +13 -0
- package/dist/tools/grep-command.js +77 -0
- package/dist/tools/grep.js +96 -201
- package/dist/tools/index.d.ts +6 -2
- package/dist/tools/index.js +9 -4
- package/dist/tools/job.js +12 -11
- package/dist/tools/read.d.ts +2 -0
- package/dist/tools/read.js +10 -2
- package/dist/tools/registry.d.ts +16 -11
- package/dist/tools/registry.js +32 -12
- package/dist/tools/send-media.js +9 -5
- package/dist/tools/session-search.d.ts +2 -1
- package/dist/tools/session-search.js +15 -5
- package/dist/tools/skill.js +13 -12
- package/dist/tools/subagent-manage.d.ts +1 -1
- package/dist/tools/subagent-manage.js +25 -152
- package/dist/tools/subagent.d.ts +24 -2
- package/dist/tools/subagent.js +24 -18
- package/dist/tools/task-manage/control-tools.js +1 -1
- package/dist/tools/task-manage/factory.d.ts +2 -2
- package/dist/tools/task-manage/factory.js +40 -4
- package/dist/tools/task-manage/lifecycle.d.ts +3 -3
- package/dist/tools/task-manage/lifecycle.js +56 -13
- package/dist/tools/task-manage/schema.d.ts +4 -1
- package/dist/tools/task-manage/schema.js +4 -1
- package/dist/tools/task-manage/shared.d.ts +1 -1
- package/dist/tools/task-manage/types.d.ts +5 -1
- package/dist/tools/write-content.d.ts +7 -1
- package/dist/tools/write-content.js +18 -6
- package/dist/tools/write.d.ts +3 -0
- package/dist/tools/write.js +6 -2
- package/dist/tui/cli.d.ts +6 -6
- package/dist/tui/cli.js +120 -28
- package/dist/tui/client.d.ts +7 -0
- package/dist/tui/client.js +67 -16
- package/dist/tui/frontend.d.ts +2 -0
- package/dist/tui/pitui-frontend.d.ts +4 -0
- package/dist/tui/pitui-frontend.js +27 -0
- package/dist/tui/render.d.ts +1 -0
- package/dist/tui/render.js +5 -0
- package/dist/tui/session.js +6 -0
- package/dist/usage/ledger.d.ts +1 -1
- package/dist/usage/render.js +1 -1
- package/dist/web/client.d.ts +1 -0
- package/dist/web/client.js +11 -0
- package/dist/web/fetch.js +6 -3
- package/dist/webapi/auth.d.ts +0 -3
- package/dist/webapi/auth.js +3 -7
- package/dist/webapi/config.js +17 -14
- package/dist/webapi/key-command.js +41 -41
- package/dist/webapi/response-state.d.ts +7 -1
- package/dist/webapi/response-state.js +166 -3
- package/dist/webapi/routes/websocket.js +24 -1
- package/dist/webapi/server.d.ts +3 -1
- package/dist/webapi/server.js +32 -1
- package/dist/webapi/service.js +8 -0
- package/dist/webapi/transport.d.ts +2 -0
- package/dist/webapi/transport.js +11 -1
- package/examples/sub-agents/README.md +43 -75
- package/examples/sub-agents/agy-main.md +21 -0
- package/examples/sub-agents/claude-high.md +21 -0
- package/examples/sub-agents/claude-main.md +21 -0
- package/examples/sub-agents/codex-flash.md +21 -0
- package/examples/sub-agents/codex-high.md +21 -0
- package/examples/sub-agents/codex-main.md +21 -0
- package/examples/sub-agents/codex-review.md +20 -0
- package/examples/sub-agents/cursor-high.md +20 -0
- package/examples/sub-agents/cursor-main.md +20 -0
- package/examples/sub-agents/glm-flash.md +21 -0
- package/examples/sub-agents/glm-high.md +21 -0
- package/examples/sub-agents/pi-scout.md +20 -0
- package/package.json +11 -12
- package/dist/agent/session/request-tools.d.ts +0 -3
- package/dist/agent/session/request-tools.js +0 -20
- package/dist/models/api-keys.d.ts +0 -11
- package/dist/models/api-keys.js +0 -22
- package/dist/playbooks/memory-and-learning.md +0 -55
- package/examples/sub-agents/agents/claude-high.md +0 -23
- package/examples/sub-agents/agents/claude-main.md +0 -23
- package/examples/sub-agents/agents/codex-flash.md +0 -23
- package/examples/sub-agents/agents/codex-high.md +0 -23
- package/examples/sub-agents/agents/codex-main.md +0 -23
- package/examples/sub-agents/agents/codex-review.md +0 -23
- package/examples/sub-agents/agents/cursor-high.md +0 -22
- package/examples/sub-agents/agents/cursor-main.md +0 -22
- package/examples/sub-agents/agents/glm-flash.md +0 -23
- package/examples/sub-agents/agents/glm-high.md +0 -23
- package/examples/sub-agents/agents/scout.md +0 -30
- package/examples/sub-agents/roles/builder-hard.md +0 -34
- package/examples/sub-agents/roles/builder.md +0 -34
- package/examples/sub-agents/roles/explorer.md +0 -39
- package/examples/sub-agents/roles/git-committer.md +0 -43
- package/examples/sub-agents/roles/planner.md +0 -33
- package/examples/sub-agents/roles/reviewer.md +0 -33
- package/examples/sub-agents/roles/verifier.md +0 -35
- package/examples/sub-agents/roles/worker.md +0 -34
package/dist/tools/subagent.js
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
import { Type } from "typebox";
|
|
2
2
|
import { RecoverableToolError } from "../shared/recoverable-error.js";
|
|
3
|
-
import { formatSubAgentList, resolveConfiguredRole, resolveInlineAgent, validateSubAgentTask, } from "../subagents/discovery.js";
|
|
4
3
|
import { dispatchSubAgentRun } from "../subagents/dispatch.js";
|
|
4
|
+
import { formatSubAgentList, resolveConfiguredRole, resolveInlineAgent, validateSubAgentTask, } from "../subagents/resolve.js";
|
|
5
5
|
/** Shared by both invocation surfaces (spec 046, D2.1). */
|
|
6
6
|
const workingDirectoryField = Type.Optional(Type.String({
|
|
7
|
-
description: "
|
|
7
|
+
description: "Existing absolute cwd; defaults to parent cwd. Does not isolate writes.",
|
|
8
|
+
}));
|
|
9
|
+
const worktreeField = Type.Optional(Type.Boolean({
|
|
10
|
+
description: "For write/work in Git: use an isolated runtime-managed worktree; result includes branch, headSha, changedFiles.",
|
|
8
11
|
}));
|
|
9
12
|
const purposeField = Type.Optional(Type.Union([Type.Literal("work"), Type.Literal("verify")], {
|
|
10
|
-
description:
|
|
13
|
+
description: "verify: independent check, returns advisory VERDICT: PASS|FAIL; default work.",
|
|
11
14
|
}));
|
|
12
15
|
const itemField = Type.Optional(Type.String({
|
|
13
|
-
description:
|
|
16
|
+
description: "Task step only: bind to this work item, e.g. W2.",
|
|
14
17
|
}));
|
|
15
18
|
/**
|
|
16
19
|
* Role-based delegation (spec 046, D2.1): the common path. No override fields beyond routing
|
|
@@ -19,8 +22,9 @@ const itemField = Type.Optional(Type.String({
|
|
|
19
22
|
*/
|
|
20
23
|
const subagentSchema = Type.Object({
|
|
21
24
|
agent: Type.String({ description: "Name of a configured sub-agent from workspaceDir/sub-agents/" }),
|
|
22
|
-
task: Type.String({ description: "
|
|
25
|
+
task: Type.String({ description: "Outcome, verified facts, constraints, paths and acceptance criteria." }),
|
|
23
26
|
workingDirectory: workingDirectoryField,
|
|
27
|
+
worktree: worktreeField,
|
|
24
28
|
purpose: purposeField,
|
|
25
29
|
item: itemField,
|
|
26
30
|
});
|
|
@@ -29,15 +33,15 @@ const subagentSchema = Type.Object({
|
|
|
29
33
|
* Carries every field a role file would otherwise supply.
|
|
30
34
|
*/
|
|
31
35
|
const subagentInlineSchema = Type.Object({
|
|
32
|
-
task: Type.String({ description: "
|
|
33
|
-
systemPrompt: Type.String({ description: "
|
|
34
|
-
tools: Type.Optional(Type.Array(Type.String(), { description: "
|
|
35
|
-
model: Type.Optional(Type.String({ description: "
|
|
36
|
+
task: Type.String({ description: "Self-contained goal, inputs, constraints and acceptance criteria." }),
|
|
37
|
+
systemPrompt: Type.String({ description: "Instructions for this one-off worker." }),
|
|
38
|
+
tools: Type.Optional(Type.Array(Type.String(), { description: "Tool whitelist." })),
|
|
39
|
+
model: Type.Optional(Type.String({ description: "Exact model reference; defaults to parent model." })),
|
|
36
40
|
effort: Type.Optional(Type.Union([Type.Literal("quick"), Type.Literal("standard"), Type.Literal("deep")], {
|
|
37
|
-
description:
|
|
41
|
+
description: "Budget preset for turns, tool calls and wall time; default standard.",
|
|
38
42
|
})),
|
|
39
43
|
context: Type.Optional(Type.Union([Type.Literal("none"), Type.Literal("index")], {
|
|
40
|
-
description:
|
|
44
|
+
description: "none (default): isolated; index: workspace background, desk memory index and journal tail.",
|
|
41
45
|
})),
|
|
42
46
|
thinkingLevel: Type.Optional(Type.Union([
|
|
43
47
|
Type.Literal("off"),
|
|
@@ -48,22 +52,24 @@ const subagentInlineSchema = Type.Object({
|
|
|
48
52
|
Type.Literal("xhigh"),
|
|
49
53
|
Type.Literal("max"),
|
|
50
54
|
], {
|
|
51
|
-
description: "
|
|
55
|
+
description: "Reasoning effort.",
|
|
52
56
|
})),
|
|
53
57
|
mutates: Type.Optional(Type.Union([Type.Literal("read"), Type.Literal("write")], {
|
|
54
|
-
description:
|
|
55
|
-
"files (including through bash) so it takes the exclusive workspace write lease.",
|
|
58
|
+
description: "Use write if any writes are possible, including through bash; controls workspace lease.",
|
|
56
59
|
})),
|
|
57
60
|
workingDirectory: workingDirectoryField,
|
|
61
|
+
worktree: worktreeField,
|
|
58
62
|
purpose: purposeField,
|
|
59
63
|
item: itemField,
|
|
60
64
|
});
|
|
65
|
+
const subagentChatSchema = Type.Omit(subagentSchema, ["item"]);
|
|
66
|
+
const subagentInlineChatSchema = Type.Omit(subagentInlineSchema, ["item"]);
|
|
61
67
|
export function createSubAgentTool(options) {
|
|
62
68
|
return {
|
|
63
69
|
name: "subagent",
|
|
64
70
|
label: "subagent",
|
|
65
|
-
description: "
|
|
66
|
-
parameters: subagentSchema,
|
|
71
|
+
description: "Dispatch a matching configured role directly for a clear task in one directory, e.g. give a read-only scout one file and a question. Read agent-delegation.md for parallel writes, worktrees, purpose=verify, uncertain image support or multi-agent coordination.",
|
|
72
|
+
parameters: options.boundTaskId ? subagentSchema : subagentChatSchema,
|
|
67
73
|
execute: async (_toolCallId, params, signal, onUpdate) => {
|
|
68
74
|
if (signal?.aborted) {
|
|
69
75
|
throw new Error("Sub-agent aborted");
|
|
@@ -91,8 +97,8 @@ export function createSubAgentInlineTool(options) {
|
|
|
91
97
|
return {
|
|
92
98
|
name: "subagent_inline",
|
|
93
99
|
label: "subagent_inline",
|
|
94
|
-
description: "
|
|
95
|
-
parameters: subagentInlineSchema,
|
|
100
|
+
description: "Fallback only when no configured role fits; otherwise use subagent. Supply task and systemPrompt. Before inline setup, read delegation-inline.md under the Runtime Guides directory.",
|
|
101
|
+
parameters: options.boundTaskId ? subagentInlineSchema : subagentInlineChatSchema,
|
|
96
102
|
execute: async (_toolCallId, params, signal, onUpdate) => {
|
|
97
103
|
if (signal?.aborted) {
|
|
98
104
|
throw new Error("Sub-agent aborted");
|
|
@@ -17,7 +17,7 @@ const MESSAGE_NOTICES = {
|
|
|
17
17
|
queued_for_next_step: "已记下,任务的下一步会看到。",
|
|
18
18
|
woke: "已记下,任务被叫醒并会继续推进。",
|
|
19
19
|
held_paused: "任务已暂停:已记下,恢复后下一步会看到。",
|
|
20
|
-
held_frozen: "
|
|
20
|
+
held_frozen: "任务的汇报频道当前不可达,任务已冻结:已记下,渠道恢复或接管后下一步会看到。",
|
|
21
21
|
};
|
|
22
22
|
export async function messageTask(options, request) {
|
|
23
23
|
const id = normalizeTaskId(request.id);
|
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import type { AgentTool } from "@earendil-works/pi-agent-core";
|
|
8
8
|
import { taskAskSchema, taskCloseSchema, taskCreateSchema, taskListSchema, taskLogSchema, taskMessageSchema, taskPauseSchema, taskReportSchema, taskResumeSchema, taskWaitSchema } from "./schema.js";
|
|
9
|
-
import type { TaskManageToolOptions } from "./types.js";
|
|
9
|
+
import type { TaskListToolOptions, TaskManageToolOptions } from "./types.js";
|
|
10
10
|
export type { TaskManageResult, TaskManageToolOptions } from "./types.js";
|
|
11
|
-
export declare function createTaskListTool(options:
|
|
11
|
+
export declare function createTaskListTool(options: TaskListToolOptions): AgentTool<typeof taskListSchema>;
|
|
12
12
|
export declare function createTaskCreateTool(options: TaskManageToolOptions): AgentTool<typeof taskCreateSchema>;
|
|
13
13
|
export declare function createTaskCloseTool(options: TaskManageToolOptions): AgentTool<typeof taskCloseSchema>;
|
|
14
14
|
export declare function createTaskLogTool(options: TaskManageToolOptions): AgentTool<typeof taskLogSchema>;
|
|
@@ -6,8 +6,44 @@ import { closeTaskFromChat, listTasks } from "./lifecycle.js";
|
|
|
6
6
|
import { readTaskLogTool } from "./log-view.js";
|
|
7
7
|
import { taskAskSchema, taskCloseSchema, taskCreateSchema, taskListSchema, taskLogSchema, taskMessageSchema, taskPauseSchema, taskReportSchema, taskResumeSchema, taskWaitSchema, } from "./schema.js";
|
|
8
8
|
import { askUser, closeTaskInSession, reportToUser, waitUntil } from "./step-tools.js";
|
|
9
|
+
function formatTaskResultText(result) {
|
|
10
|
+
const lines = [result.notice];
|
|
11
|
+
if (result.action === "log")
|
|
12
|
+
lines.push(...(result.entries ?? []));
|
|
13
|
+
if (result.action === "list") {
|
|
14
|
+
for (const task of result.tasks ?? []) {
|
|
15
|
+
const state = task.state + (task.archived ? " (archived)" : "") + (task.frozen ? " (frozen)" : "");
|
|
16
|
+
const fields = [
|
|
17
|
+
task.steps !== undefined && `steps=${task.steps}`,
|
|
18
|
+
task.usd !== undefined && `usd=${task.usd}`,
|
|
19
|
+
Boolean(task.unknownCostCount) && `unknown costs=${task.unknownCostCount}`,
|
|
20
|
+
task.items && `items=${task.items}`,
|
|
21
|
+
task.closedAt && `closed=${task.closedAt}`,
|
|
22
|
+
task.waiting && `waiting for ${task.waiting}`,
|
|
23
|
+
task.activity,
|
|
24
|
+
task.inFlight?.join("; "),
|
|
25
|
+
!task.deliversHere && `delivers to ${task.channel ?? "another channel"}`,
|
|
26
|
+
].filter(Boolean);
|
|
27
|
+
lines.push(`- [${task.id}] ${state} — ${task.title}${fields.length ? ` (${fields.join(" · ")})` : ""}`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
const fields = [
|
|
31
|
+
result.id && `id=${result.id}`,
|
|
32
|
+
result.path && `path=${result.path}`,
|
|
33
|
+
result.state && `state=${result.state}`,
|
|
34
|
+
result.archived !== undefined && `archived=${result.archived}`,
|
|
35
|
+
result.cancelled?.length && `cancelled=${result.cancelled.join(", ")}`,
|
|
36
|
+
].filter(Boolean);
|
|
37
|
+
if (fields.length)
|
|
38
|
+
lines.push(fields.join(" · "));
|
|
39
|
+
return lines.join("\n");
|
|
40
|
+
}
|
|
9
41
|
function asResult(result, terminate = false) {
|
|
10
|
-
return {
|
|
42
|
+
return {
|
|
43
|
+
content: [{ type: "text", text: formatTaskResultText(result) }],
|
|
44
|
+
details: { ...result },
|
|
45
|
+
terminate,
|
|
46
|
+
};
|
|
11
47
|
}
|
|
12
48
|
/**
|
|
13
49
|
* One tool per payload shape (spec 046, D3.1). The ones that carry an `id` take the same per-task
|
|
@@ -20,16 +56,16 @@ export function createTaskListTool(options) {
|
|
|
20
56
|
return {
|
|
21
57
|
name: "task_list",
|
|
22
58
|
label: "task_list",
|
|
23
|
-
description: "
|
|
59
|
+
description: "Get live task progress for this desk: state, waiting source, current step and in-flight delegations. Marks reports delivered to other channels. Use task_log for history.",
|
|
24
60
|
parameters: taskListSchema,
|
|
25
|
-
execute: async () => asResult(await listTasks(options)),
|
|
61
|
+
execute: async (_toolCallId, args) => asResult(await listTasks(options, args)),
|
|
26
62
|
};
|
|
27
63
|
}
|
|
28
64
|
export function createTaskCreateTool(options) {
|
|
29
65
|
return {
|
|
30
66
|
name: "task_create",
|
|
31
67
|
label: "task_create",
|
|
32
|
-
description: "Create a persistent project you lead
|
|
68
|
+
description: "Create a persistent project you lead in its own background session alongside this chat. Read task-manage.md for scope, contract and management workflows.",
|
|
33
69
|
parameters: taskCreateSchema,
|
|
34
70
|
execute: async (_toolCallId, args) => asResult(await withLock(options, args.id, () => createTask(options, args))),
|
|
35
71
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { TaskCloseRequest, TaskManageResult, TaskManageToolOptions } from "./types.js";
|
|
1
|
+
import type { TaskCloseRequest, TaskListRequest, TaskListToolOptions, TaskManageResult, TaskManageToolOptions } from "./types.js";
|
|
2
2
|
export declare function requireTask(options: TaskManageToolOptions, id: string): Promise<import("../../tasks/store.js").StoredTaskDocument>;
|
|
3
|
-
/** `task_list`:
|
|
4
|
-
export declare function listTasks(options:
|
|
3
|
+
/** `task_list`: active tasks of the desk (plus archived tasks when requested), optionally filtered by keyword. */
|
|
4
|
+
export declare function listTasks(options: TaskListToolOptions, request?: TaskListRequest): Promise<TaskManageResult>;
|
|
5
5
|
/**
|
|
6
6
|
* `task_close` from a chat: `complete` archives a task nothing is working on, `cancel` stops the
|
|
7
7
|
* running step and everything bound to it through the lane (spec 064, D23).
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { mkdir } from "node:fs/promises";
|
|
1
|
+
import { mkdir, readFile } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
2
3
|
import { finalTaskReport } from "../../tasks/completion.js";
|
|
3
4
|
import { extractTaskTitle, normalizeTaskId, readActiveTasks } from "../../tasks/contract.js";
|
|
4
5
|
import { readTaskLog } from "../../tasks/loop-log.js";
|
|
5
6
|
import { withTaskMutation } from "../../tasks/mutation-lock.js";
|
|
6
|
-
import { completedReceipt } from "../../tasks/receipts.js";
|
|
7
|
+
import { completedReceipt, formatRetainedWorktreeLines } from "../../tasks/receipts.js";
|
|
7
8
|
import { closeTask as closeStoredTask, readStoredTask } from "../../tasks/store.js";
|
|
8
9
|
import { RecoverableToolError } from "../contract/details.js";
|
|
9
10
|
import { assertCompletable, requiredField, tasksDir } from "./shared.js";
|
|
@@ -42,19 +43,31 @@ function describeInFlight(live, now) {
|
|
|
42
43
|
return `${work.ref} (${work.label}) running ${running}m${quiet}${work.stalled ? " — looks stalled" : ""}`;
|
|
43
44
|
});
|
|
44
45
|
}
|
|
45
|
-
/** `task_list`:
|
|
46
|
-
export async function listTasks(options) {
|
|
46
|
+
/** `task_list`: active tasks of the desk (plus archived tasks when requested), optionally filtered by keyword. */
|
|
47
|
+
export async function listTasks(options, request = {}) {
|
|
47
48
|
const dir = tasksDir(options);
|
|
48
49
|
await mkdir(dir, { recursive: true });
|
|
49
|
-
const
|
|
50
|
+
const needle = request.query?.trim().toLowerCase();
|
|
51
|
+
const matchesQuery = async (entry, mdPath) => {
|
|
52
|
+
if (!needle)
|
|
53
|
+
return true;
|
|
54
|
+
if (entry.id.toLowerCase().includes(needle) || entry.title.toLowerCase().includes(needle))
|
|
55
|
+
return true;
|
|
56
|
+
const content = await readFile(mdPath, "utf-8").catch(() => "");
|
|
57
|
+
return content.toLowerCase().includes(needle);
|
|
58
|
+
};
|
|
59
|
+
const activeEntries = (await readActiveTasks(dir)).filter((entry) => !entry.fields.outcome);
|
|
50
60
|
const snapshots = new Map(((await options.control?.snapshot(options.desk).catch(() => [])) ?? []).map((snapshot) => [
|
|
51
61
|
snapshot.id,
|
|
52
62
|
snapshot,
|
|
53
63
|
]));
|
|
54
64
|
const now = Date.now();
|
|
55
|
-
const tasks =
|
|
65
|
+
const tasks = [];
|
|
66
|
+
for (const entry of activeEntries) {
|
|
67
|
+
if (!(await matchesQuery(entry, join(dir, `${entry.id}.md`))))
|
|
68
|
+
continue;
|
|
56
69
|
const live = snapshots.get(entry.id);
|
|
57
|
-
|
|
70
|
+
tasks.push({
|
|
58
71
|
id: entry.id,
|
|
59
72
|
title: entry.title,
|
|
60
73
|
state: entry.readable ? (live?.closing ? "closing" : entry.fields.state) : "unreadable",
|
|
@@ -68,12 +81,39 @@ export async function listTasks(options) {
|
|
|
68
81
|
items: entry.items ? `${entry.items.done}/${entry.items.total}` : undefined,
|
|
69
82
|
activity: describeActivity(live, now),
|
|
70
83
|
inFlight: describeInFlight(live, now),
|
|
71
|
-
};
|
|
72
|
-
}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
if (request.includeArchived) {
|
|
87
|
+
const archiveDir = join(dir, "archive");
|
|
88
|
+
const archivedEntries = (await readActiveTasks(archiveDir)).sort((a, b) => (b.fields.closedAt ?? "").localeCompare(a.fields.closedAt ?? ""));
|
|
89
|
+
for (const entry of archivedEntries.slice(0, 50)) {
|
|
90
|
+
if (!(await matchesQuery(entry, join(archiveDir, `${entry.id}.md`))))
|
|
91
|
+
continue;
|
|
92
|
+
tasks.push({
|
|
93
|
+
id: entry.id,
|
|
94
|
+
title: entry.title,
|
|
95
|
+
state: entry.fields.outcome ?? "archived",
|
|
96
|
+
archived: true,
|
|
97
|
+
closedAt: entry.fields.closedAt,
|
|
98
|
+
channel: entry.fields.channel,
|
|
99
|
+
deliversHere: entry.fields.channel === options.channelId,
|
|
100
|
+
steps: entry.fields.usage?.steps,
|
|
101
|
+
usd: entry.fields.usage ? Number(entry.fields.usage.usd.toFixed(2)) : undefined,
|
|
102
|
+
unknownCostCount: entry.fields.usage?.unknownCostCount ?? 0,
|
|
103
|
+
items: entry.items ? `${entry.items.done}/${entry.items.total}` : undefined,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
}
|
|
73
107
|
return {
|
|
74
108
|
action: "list",
|
|
75
109
|
tasks,
|
|
76
|
-
notice: tasks.length === 0
|
|
110
|
+
notice: tasks.length === 0
|
|
111
|
+
? request.includeArchived || needle
|
|
112
|
+
? "未找到匹配的任务。"
|
|
113
|
+
: "暂无进行中的任务。"
|
|
114
|
+
: request.includeArchived
|
|
115
|
+
? `共 ${tasks.length} 个匹配任务(含已归档任务)。`
|
|
116
|
+
: `共 ${tasks.length} 个进行中的任务。`,
|
|
77
117
|
};
|
|
78
118
|
}
|
|
79
119
|
/**
|
|
@@ -91,12 +131,14 @@ export async function closeTaskFromChat(options, request) {
|
|
|
91
131
|
if (outcome.kind === "not_found")
|
|
92
132
|
throw new RecoverableToolError(`Task "${id}" no longer exists.`);
|
|
93
133
|
const stopped = outcome.cancelled.length > 0 ? ` 同时取消了在途的委派/作业:${outcome.cancelled.join(", ")}。` : "";
|
|
134
|
+
const retained = formatRetainedWorktreeLines(outcome.retainedWorktrees);
|
|
135
|
+
const retainedNote = retained.length > 0 ? `\n${retained.join("\n")}` : "";
|
|
94
136
|
return {
|
|
95
137
|
action: "close",
|
|
96
138
|
id,
|
|
97
139
|
archived: true,
|
|
98
140
|
cancelled: outcome.cancelled,
|
|
99
|
-
notice: `任务 \`${id}\` 已取消并归档。${stopped}`,
|
|
141
|
+
notice: `任务 \`${id}\` 已取消并归档。${stopped}${retainedNote}`,
|
|
100
142
|
};
|
|
101
143
|
}
|
|
102
144
|
const document = await requireTask(options, id);
|
|
@@ -114,13 +156,14 @@ export async function closeTaskFromChat(options, request) {
|
|
|
114
156
|
throw new RecoverableToolError(`Task "${id}" changed during completion checks. Inspect it with task_list and retry closing once its step and work have stopped.`);
|
|
115
157
|
}
|
|
116
158
|
const finalReport = finalTaskReport(await readTaskLog(options.deskDir, id, { strict: true }), { fromChat: true });
|
|
159
|
+
const retainedWorktrees = await Promise.resolve(options.runManager.reclaimTaskWorktrees?.(id) ?? []).catch(() => []);
|
|
117
160
|
const closed = await closeStoredTask(options.deskDir, id, {
|
|
118
161
|
outcome: "complete",
|
|
119
162
|
by: "user",
|
|
120
163
|
note,
|
|
121
164
|
reportId: finalReport.id,
|
|
122
165
|
receipt: current.fields.channel !== options.channelId
|
|
123
|
-
? (document, closedAt) => completedReceipt(id, extractTaskTitle(document.body, id), document, closedAt)
|
|
166
|
+
? (document, closedAt) => completedReceipt(id, extractTaskTitle(document.body, id), document, closedAt, retainedWorktrees)
|
|
124
167
|
: undefined,
|
|
125
168
|
});
|
|
126
169
|
options.control?.created(options.desk, id);
|
|
@@ -130,7 +173,7 @@ export async function closeTaskFromChat(options, request) {
|
|
|
130
173
|
action: "close",
|
|
131
174
|
id,
|
|
132
175
|
archived: true,
|
|
133
|
-
notice: completedReceipt(id, extractTaskTitle(closed.body, id), closed, closed.fields.closedAt),
|
|
176
|
+
notice: completedReceipt(id, extractTaskTitle(closed.body, id), closed, closed.fields.closedAt, retainedWorktrees),
|
|
134
177
|
};
|
|
135
178
|
});
|
|
136
179
|
}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { Type } from "typebox";
|
|
2
|
-
export declare const taskListSchema: Type.TObject<{
|
|
2
|
+
export declare const taskListSchema: Type.TObject<{
|
|
3
|
+
includeArchived: Type.TOptional<Type.TBoolean>;
|
|
4
|
+
query: Type.TOptional<Type.TString>;
|
|
5
|
+
}>;
|
|
3
6
|
export declare const taskCreateSchema: Type.TObject<{
|
|
4
7
|
id: Type.TString;
|
|
5
8
|
title: Type.TString;
|
|
@@ -4,7 +4,10 @@ const budgetField = Type.Optional(Type.Object({
|
|
|
4
4
|
steps: Type.Optional(Type.Integer({ minimum: 1, description: "Max model steps for the whole task." })),
|
|
5
5
|
usd: Type.Optional(Type.Number({ description: "Max attributable cost for the whole task, including bound delegations." })),
|
|
6
6
|
}, { description: "Per-task budget; omitted keys fall back to the runtime defaults." }));
|
|
7
|
-
export const taskListSchema = Type.Object({
|
|
7
|
+
export const taskListSchema = Type.Object({
|
|
8
|
+
includeArchived: Type.Optional(Type.Boolean({ description: "Also include closed/archived tasks from tasks/archive/." })),
|
|
9
|
+
query: Type.Optional(Type.String({ description: "Filter tasks by keyword across id, title, and contract/archive summary." })),
|
|
10
|
+
});
|
|
8
11
|
export const taskCreateSchema = Type.Object({
|
|
9
12
|
id: idField,
|
|
10
13
|
title: Type.String({ description: "Task title (H1 heading)." }),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { StoredTaskDocument } from "../../tasks/store.js";
|
|
2
2
|
import type { TaskManageToolOptions } from "./types.js";
|
|
3
|
-
export declare function tasksDir(options: TaskManageToolOptions): string;
|
|
3
|
+
export declare function tasksDir(options: Pick<TaskManageToolOptions, "deskDir">): string;
|
|
4
4
|
export declare function requiredField(value: string | undefined, field: string, action: string): string;
|
|
5
5
|
/** Refs of the delegations and background jobs bound to `taskId` that have not settled yet. */
|
|
6
6
|
export declare function pendingWorkRefs(options: TaskManageToolOptions, taskId: string): Promise<string[]>;
|
|
@@ -2,7 +2,7 @@ import type { Static } from "typebox";
|
|
|
2
2
|
import type { DeskJobManager } from "../../jobs/manager.js";
|
|
3
3
|
import type { SubAgentRunManager } from "../../subagents/runs.js";
|
|
4
4
|
import type { TaskControl, TaskSessionContext } from "../../tasks/control.js";
|
|
5
|
-
import type { taskAskSchema, taskCloseSchema, taskCreateSchema, taskLogSchema, taskMessageSchema, taskPauseSchema, taskReportSchema, taskResumeSchema, taskWaitSchema } from "./schema.js";
|
|
5
|
+
import type { taskAskSchema, taskCloseSchema, taskCreateSchema, taskListSchema, taskLogSchema, taskMessageSchema, taskPauseSchema, taskReportSchema, taskResumeSchema, taskWaitSchema } from "./schema.js";
|
|
6
6
|
export interface TaskManageResult {
|
|
7
7
|
action: "create" | "close" | "list" | "log" | "message" | "pause" | "resume" | "report" | "ask" | "wait";
|
|
8
8
|
id?: string;
|
|
@@ -26,6 +26,8 @@ export interface TaskManageResult {
|
|
|
26
26
|
/** The step in progress and what the model is doing in it. */
|
|
27
27
|
activity?: string;
|
|
28
28
|
inFlight?: string[];
|
|
29
|
+
archived?: boolean;
|
|
30
|
+
closedAt?: string;
|
|
29
31
|
}>;
|
|
30
32
|
/** Rendered log lines, for `task_log`. */
|
|
31
33
|
entries?: string[];
|
|
@@ -37,6 +39,7 @@ export interface TaskManageResult {
|
|
|
37
39
|
* One request type per schema the model actually sees (spec 046, D3.3): each tool's required
|
|
38
40
|
* fields are non-optional in the type rather than documented as "required for X" in shared prose.
|
|
39
41
|
*/
|
|
42
|
+
export type TaskListRequest = Static<typeof taskListSchema>;
|
|
40
43
|
export type TaskCreateRequest = Static<typeof taskCreateSchema>;
|
|
41
44
|
export type TaskCloseRequest = Static<typeof taskCloseSchema>;
|
|
42
45
|
export type TaskLogRequest = Static<typeof taskLogSchema>;
|
|
@@ -46,6 +49,7 @@ export type TaskResumeRequest = Static<typeof taskResumeSchema>;
|
|
|
46
49
|
export type TaskReportRequest = Static<typeof taskReportSchema>;
|
|
47
50
|
export type TaskAskRequest = Static<typeof taskAskSchema>;
|
|
48
51
|
export type TaskWaitRequest = Static<typeof taskWaitSchema>;
|
|
52
|
+
export type TaskListToolOptions = Pick<TaskManageToolOptions, "desk" | "deskDir" | "channelId" | "control">;
|
|
49
53
|
export interface TaskManageToolOptions {
|
|
50
54
|
jobManager: DeskJobManager;
|
|
51
55
|
runManager: SubAgentRunManager;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { FileStore } from "../file-store.js";
|
|
2
2
|
import type { SecurityConfig, SecurityRuntimeContext } from "../security/types.js";
|
|
3
|
+
import { type FileObservations } from "./file-observations.js";
|
|
3
4
|
export declare function writeContent(fileStore: FileStore, path: string, content: string, signal: AbortSignal | undefined, options?: {
|
|
4
5
|
deskDir?: string;
|
|
5
6
|
createParentDir?: boolean;
|
|
@@ -7,4 +8,9 @@ export declare function writeContent(fileStore: FileStore, path: string, content
|
|
|
7
8
|
securityContext?: SecurityRuntimeContext;
|
|
8
9
|
channelId?: string;
|
|
9
10
|
toolName?: string;
|
|
10
|
-
|
|
11
|
+
leaseOwnerRunId?: string;
|
|
12
|
+
observations?: FileObservations;
|
|
13
|
+
}): Promise<{
|
|
14
|
+
target: string;
|
|
15
|
+
note: string | undefined;
|
|
16
|
+
}>;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { DEFAULT_SECURITY_CONFIG } from "../security/config.js";
|
|
2
2
|
import { checkPathGuard } from "../security/path-guard-check.js";
|
|
3
|
+
import { assertPathWritableUnderLease } from "../subagents/workspace-lease.js";
|
|
3
4
|
import { preserveTaskFields, withTaskFileMutation } from "../tasks/file-mutation.js";
|
|
5
|
+
import { observeCurrentFile } from "./file-observations.js";
|
|
4
6
|
export async function writeContent(fileStore, path, content, signal, options) {
|
|
5
7
|
const createParentDir = options?.createParentDir ?? false;
|
|
6
8
|
const securityConfig = options?.securityConfig ?? DEFAULT_SECURITY_CONFIG;
|
|
@@ -12,15 +14,25 @@ export async function writeContent(fileStore, path, content, signal, options) {
|
|
|
12
14
|
tool: options?.toolName ?? "write",
|
|
13
15
|
channelId: options?.channelId,
|
|
14
16
|
});
|
|
17
|
+
assertPathWritableUnderLease(target, {
|
|
18
|
+
deskDir: options?.deskDir,
|
|
19
|
+
excludeRunId: options?.leaseOwnerRunId,
|
|
20
|
+
});
|
|
15
21
|
// Atomic write via a same-directory temp file + rename, with fsync (spec 044, D3): `writeAtomic`
|
|
16
22
|
// preserves the existing file's permission bits across the rename, exactly as the old
|
|
17
23
|
// `cp -p` + `cat > tmp && mv` shell script did, but content now goes straight to `node:fs`
|
|
18
24
|
// instead of a stdin pipe into `sh -c` -- it never exists in memory twice, and there is no
|
|
19
25
|
// shell script to escape or an EPIPE to swallow.
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
+
return withTaskFileMutation(options?.deskDir, target, async (document) => {
|
|
27
|
+
const observations = options?.observations;
|
|
28
|
+
const before = observations ? await fileStore.stat(target).catch(() => undefined) : undefined;
|
|
29
|
+
const note = observations?.describeWriteNote(target, path, before);
|
|
30
|
+
await fileStore.writeAtomic(target, preserveTaskFields(document, content), {
|
|
31
|
+
createParentDir,
|
|
32
|
+
preserveMode: true,
|
|
33
|
+
signal,
|
|
34
|
+
});
|
|
35
|
+
await observeCurrentFile(observations, fileStore, target);
|
|
36
|
+
return { target, note };
|
|
37
|
+
});
|
|
26
38
|
}
|
package/dist/tools/write.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { AgentTool } from "@earendil-works/pi-agent-core";
|
|
|
2
2
|
import { Type } from "typebox";
|
|
3
3
|
import type { FileStore } from "../file-store.js";
|
|
4
4
|
import type { SecurityConfig, SecurityRuntimeContext } from "../security/types.js";
|
|
5
|
+
import type { FileObservations } from "./file-observations.js";
|
|
5
6
|
declare const writeSchema: Type.TObject<{
|
|
6
7
|
path: Type.TString;
|
|
7
8
|
content: Type.TString;
|
|
@@ -11,6 +12,8 @@ export interface WriteToolOptions {
|
|
|
11
12
|
securityConfig?: SecurityConfig;
|
|
12
13
|
securityContext?: SecurityRuntimeContext;
|
|
13
14
|
channelId?: string;
|
|
15
|
+
leaseOwnerRunId?: string;
|
|
16
|
+
observations?: FileObservations;
|
|
14
17
|
}
|
|
15
18
|
export declare function createWriteTool(fileStore: FileStore, options?: WriteToolOptions): AgentTool<typeof writeSchema>;
|
|
16
19
|
export {};
|
package/dist/tools/write.js
CHANGED
|
@@ -14,17 +14,21 @@ export function createWriteTool(fileStore, options = {}) {
|
|
|
14
14
|
description: "Write content to a file. Creates the file if it doesn't exist, overwrites if it does. Automatically creates parent directories.",
|
|
15
15
|
parameters: writeSchema,
|
|
16
16
|
execute: async (_toolCallId, { path, content }, signal) => {
|
|
17
|
-
const target = await writeContent(fileStore, path, content, signal, {
|
|
17
|
+
const { target, note } = await writeContent(fileStore, path, content, signal, {
|
|
18
18
|
deskDir: options.deskDir,
|
|
19
19
|
createParentDir: true,
|
|
20
20
|
securityConfig: options.securityConfig,
|
|
21
21
|
securityContext: options.securityContext,
|
|
22
22
|
channelId: options.channelId,
|
|
23
23
|
toolName: "write",
|
|
24
|
+
leaseOwnerRunId: options.leaseOwnerRunId,
|
|
25
|
+
observations: options.observations,
|
|
24
26
|
});
|
|
25
27
|
const bytesWritten = Buffer.byteLength(content, "utf-8");
|
|
26
28
|
return {
|
|
27
|
-
content: [
|
|
29
|
+
content: [
|
|
30
|
+
{ type: "text", text: `Successfully wrote ${bytesWritten} bytes to ${path}${note ? `\n${note}` : ""}` },
|
|
31
|
+
],
|
|
28
32
|
details: { path: target },
|
|
29
33
|
};
|
|
30
34
|
},
|
package/dist/tui/cli.d.ts
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `pipiclaw tui` CLI: argument parsing and entry. Parsing is a pure function (`parseTuiArgs`) so
|
|
3
|
-
* it can be unit-tested. The terminal is a client of the Web API (spec 061, D25): it connects to
|
|
4
|
-
* the daemon's socket, or — when no daemon is running — to a runtime it starts inside this
|
|
5
|
-
* process (D26, `startEmbeddedRuntime`, supplied by the entry so `tui/` never imports `runtime/`).
|
|
6
|
-
*/
|
|
7
1
|
import { type BootstrapIO, type BootstrapPaths } from "../app/home.js";
|
|
8
2
|
export type ParsedTui = {
|
|
9
3
|
kind: "run";
|
|
10
4
|
desk?: string;
|
|
5
|
+
cwd?: string;
|
|
6
|
+
here: boolean;
|
|
11
7
|
create: boolean;
|
|
12
8
|
fresh: boolean;
|
|
13
9
|
print: boolean;
|
|
@@ -31,5 +27,9 @@ export interface EmbeddedRuntimeHandle {
|
|
|
31
27
|
export interface TuiHooks {
|
|
32
28
|
/** Start the runtime in this process, or `undefined` when a daemon already holds the app home. */
|
|
33
29
|
startEmbeddedRuntime(paths: BootstrapPaths, io: BootstrapIO): Promise<EmbeddedRuntimeHandle | undefined>;
|
|
30
|
+
/** Override TTY interactivity detection (for deterministic unit tests). */
|
|
31
|
+
interactive?: boolean;
|
|
32
|
+
confirmModelLogin?: () => Promise<boolean>;
|
|
33
|
+
performModelLogin?: () => Promise<void>;
|
|
34
34
|
}
|
|
35
35
|
export declare function runTui(argv: string[], hooks: TuiHooks, io?: BootstrapIO, paths?: BootstrapPaths): Promise<void>;
|