@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,19 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `/tasks`: the user's control path for the channel's long-horizon tasks (list, show, log, pause,
|
|
3
|
+
* resume, run, reply, steer, archive, doctor).
|
|
4
|
+
*/
|
|
1
5
|
import { existsSync } from "node:fs";
|
|
2
6
|
import { readdir } from "node:fs/promises";
|
|
3
7
|
import { join } from "node:path";
|
|
4
8
|
import { renderSubcommandUsage } from "../commands/catalog.js";
|
|
9
|
+
import { capReply, flattenMarkdownForChat } from "../commands/reply-limits.js";
|
|
10
|
+
import { docsUrl } from "../paths.js";
|
|
11
|
+
import { formatSpanZh } from "../shared/format.js";
|
|
5
12
|
import { parseLocalTime } from "../shared/local-time.js";
|
|
6
|
-
import {
|
|
7
|
-
import { buildTaskBoard,
|
|
8
|
-
import { normalizeTaskId, readActiveTasks } from "
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const
|
|
13
|
+
import { errorMessage } from "../shared/text-utils.js";
|
|
14
|
+
import { buildTaskBoard, renderTaskBoardForUser } from "./board.js";
|
|
15
|
+
import { normalizeTaskId, readActiveTasks } from "./contract.js";
|
|
16
|
+
import { taskStateLabel } from "./frontmatter.js";
|
|
17
|
+
import { readTaskLog, renderTaskLogLineForUser, taskArchiveLogPath, taskLogIsArchived, taskLogPath, } from "./loop-log.js";
|
|
18
|
+
import { withTaskMutation } from "./mutation-lock.js";
|
|
19
|
+
import { hasTaskSteer, queueTaskSteer } from "./steer.js";
|
|
20
|
+
import { archivedTaskPath, pauseTask as pauseTaskDocument, readStoredTask, redeemTicket, resumeTask as resumeTaskDocument, taskPath, updateStoredTask, } from "./store.js";
|
|
21
|
+
import { describeTicketForUser } from "./ticket.js";
|
|
22
|
+
/** `/tasks show <id>` contract excerpt; the full file is always readable at its own path. */
|
|
23
|
+
const TASK_SHOW_CONTRACT_CHARS = 500;
|
|
24
|
+
const SHOW_LOG_LINES = 5;
|
|
25
|
+
/** `/tasks log <id>`: the most recent records; older ones are in the `.jsonl` it names. */
|
|
26
|
+
const LOG_LINES = 15;
|
|
27
|
+
const ARCHIVE_LIST_LIMIT = 20;
|
|
17
28
|
/** A backstop this far past due means the driver is not running, not that it is merely about to act. */
|
|
18
29
|
const EXPIRED_GRACE_MS = 60 * 60 * 1000;
|
|
19
30
|
// Broadcast (subcommand names, args, descriptions, examples) lives once in commands/catalog.ts's
|
|
@@ -67,50 +78,39 @@ export function parseTasksCommand(args) {
|
|
|
67
78
|
throw new Error(`用法:/tasks ${action} <id> <内容>`);
|
|
68
79
|
return { action, id: match[1], text: match[2].trim() };
|
|
69
80
|
}
|
|
70
|
-
throw new Error(
|
|
81
|
+
throw new Error(`未知子命令 \`${action}\`。`);
|
|
71
82
|
}
|
|
72
83
|
function tasksDir(channelDir) {
|
|
73
84
|
return join(channelDir, "tasks");
|
|
74
85
|
}
|
|
75
|
-
/**
|
|
76
|
-
function
|
|
86
|
+
/** `(最晚 3 小时后重新检查)` — when the runtime looks at a parked task again no matter what. */
|
|
87
|
+
function backstopHint(by, now) {
|
|
88
|
+
const atMs = parseLocalTime(by);
|
|
77
89
|
if (atMs === undefined || !Number.isFinite(atMs))
|
|
78
|
-
return
|
|
90
|
+
return "";
|
|
79
91
|
const diffMs = atMs - now;
|
|
80
|
-
|
|
81
|
-
return "已到期";
|
|
82
|
-
const minutes = Math.round(diffMs / 60000);
|
|
83
|
-
if (minutes < 60)
|
|
84
|
-
return `${minutes}m`;
|
|
85
|
-
const hours = Math.round(minutes / 60);
|
|
86
|
-
if (hours < 24)
|
|
87
|
-
return `${hours}h`;
|
|
88
|
-
return `${Math.round(hours / 24)}d`;
|
|
92
|
+
return diffMs <= 0 ? "(已过最晚检查时间)" : `(最晚 ${formatSpanZh(diffMs)}后重新检查)`;
|
|
89
93
|
}
|
|
90
|
-
const STATE_LABEL = { open: "进行中", parked: "等待中", done: "已关闭" };
|
|
91
94
|
function usageSummary(entry) {
|
|
92
95
|
const usage = entry.fields.usage;
|
|
93
96
|
if (!usage)
|
|
94
97
|
return undefined;
|
|
95
|
-
const cost = usage.usd > 0 ?
|
|
96
|
-
return
|
|
98
|
+
const cost = usage.usd > 0 ? ` · 花费 $${usage.usd.toFixed(2)}${usage.usdEstimated ? "(含估算)" : ""}` : "";
|
|
99
|
+
return `已用 ${usage.steps} 步${cost}`;
|
|
97
100
|
}
|
|
98
101
|
function ticketSummary(entry, now) {
|
|
99
102
|
const ticket = entry.fields.ticket;
|
|
100
|
-
|
|
101
|
-
return undefined;
|
|
102
|
-
const by = relative(parseLocalTime(ticket.by), now);
|
|
103
|
-
return `${describeTicket(ticket)}${by ? `(兜底 ${by})` : ""}`;
|
|
103
|
+
return ticket ? `${describeTicketForUser(ticket)}${backstopHint(ticket.by, now)}` : undefined;
|
|
104
104
|
}
|
|
105
105
|
function renderListLine(entry, channelDir, now) {
|
|
106
|
-
const bits = [
|
|
106
|
+
const bits = [`\`${entry.id}\` ${entry.title}`, taskStateLabel(entry.fields.state)];
|
|
107
107
|
if (entry.fields.paused)
|
|
108
108
|
bits.push(`已暂停(${entry.fields.paused.reason})`);
|
|
109
109
|
const ticket = ticketSummary(entry, now);
|
|
110
110
|
if (ticket)
|
|
111
111
|
bits.push(ticket);
|
|
112
112
|
if (entry.items)
|
|
113
|
-
bits.push(
|
|
113
|
+
bits.push(`工作项 ${entry.items.done}/${entry.items.total}`);
|
|
114
114
|
if (entry.fields.origin)
|
|
115
115
|
bits.push(`来自 ${entry.fields.origin}`);
|
|
116
116
|
const usage = usageSummary(entry);
|
|
@@ -119,31 +119,51 @@ function renderListLine(entry, channelDir, now) {
|
|
|
119
119
|
if (hasTaskSteer(channelDir, entry.id))
|
|
120
120
|
bits.push("有待处理的指示");
|
|
121
121
|
if (!entry.readable)
|
|
122
|
-
bits.push("
|
|
122
|
+
bits.push("⚠️ 文件头(frontmatter)不可读");
|
|
123
123
|
return `- ${bits.join(" · ")}`;
|
|
124
124
|
}
|
|
125
125
|
async function listTasks(channelDir) {
|
|
126
126
|
const now = Date.now();
|
|
127
127
|
const entries = (await readActiveTasks(tasksDir(channelDir), now)).filter((entry) => !entry.fields.outcome);
|
|
128
128
|
if (entries.length === 0) {
|
|
129
|
-
return "暂无进行中的任务。\n
|
|
129
|
+
return "暂无进行中的任务。\n在对话里告诉我目标,并说明作为长程任务推进。";
|
|
130
130
|
}
|
|
131
|
-
|
|
131
|
+
const report = [
|
|
132
|
+
`**任务(${entries.length})**`,
|
|
133
|
+
...entries.map((entry) => renderListLine(entry, channelDir, now)),
|
|
134
|
+
].join("\n");
|
|
135
|
+
return capReply(report, { nextStepHint: "用 `/tasks show <id>` 查看单个任务" }).text;
|
|
136
|
+
}
|
|
137
|
+
function notFound(id) {
|
|
138
|
+
return `未找到任务 \`${id}\`。用 \`/tasks\` 查看进行中的任务,或 \`/tasks archive\` 查看已归档的。`;
|
|
139
|
+
}
|
|
140
|
+
/** The head of the contract, reshaped for chat and cut on a line boundary; the full file is one path away. */
|
|
141
|
+
function contractExcerpt(body, maxChars) {
|
|
142
|
+
const flat = flattenMarkdownForChat(body.trim());
|
|
143
|
+
if (flat.length <= maxChars)
|
|
144
|
+
return { text: flat, clipped: false };
|
|
145
|
+
const cut = flat.lastIndexOf("\n", maxChars);
|
|
146
|
+
const head = flat.slice(0, cut > 0 ? cut : maxChars).trimEnd();
|
|
147
|
+
// A cut inside a fenced block would leave the rest of the reply rendered as code.
|
|
148
|
+
const openFence = (head.match(/^```/gm)?.length ?? 0) % 2 === 1;
|
|
149
|
+
return { text: openFence ? `${head}\n\`\`\`` : head, clipped: true };
|
|
132
150
|
}
|
|
133
151
|
async function showTask(channelDir, idInput) {
|
|
134
152
|
const id = normalizeTaskId(idInput);
|
|
135
153
|
const document = (await readStoredTask(channelDir, id, true)) ?? undefined;
|
|
136
154
|
if (!document)
|
|
137
|
-
return
|
|
155
|
+
return notFound(id);
|
|
138
156
|
const now = Date.now();
|
|
139
157
|
const entry = (await readActiveTasks(tasksDir(channelDir), now)).find((candidate) => candidate.id === id);
|
|
140
158
|
const head = [`**任务 ${id}**`];
|
|
141
|
-
head.push(`- 状态:${
|
|
142
|
-
if (document.fields.paused)
|
|
143
|
-
|
|
159
|
+
head.push(`- 状态:${taskStateLabel(document.fields.state)}`);
|
|
160
|
+
if (document.fields.paused) {
|
|
161
|
+
const by = document.fields.paused.by === "user" ? "由你暂停" : "由系统暂停";
|
|
162
|
+
head.push(`- 已暂停(${by}):${document.fields.paused.reason}`);
|
|
163
|
+
}
|
|
144
164
|
if (document.fields.ticket) {
|
|
145
|
-
const
|
|
146
|
-
head.push(`- 等待:${
|
|
165
|
+
const ticket = document.fields.ticket;
|
|
166
|
+
head.push(`- 等待:${describeTicketForUser(ticket)}${backstopHint(ticket.by, now)}`);
|
|
147
167
|
}
|
|
148
168
|
if (document.fields.origin)
|
|
149
169
|
head.push(`- 来自事件:${document.fields.origin}`);
|
|
@@ -151,15 +171,28 @@ async function showTask(channelDir, idInput) {
|
|
|
151
171
|
if (usage)
|
|
152
172
|
head.push(`- 用量:${usage}`);
|
|
153
173
|
const board = await buildTaskBoard(channelDir, id, document.body);
|
|
154
|
-
const boardLines = board ? ["", "
|
|
174
|
+
const boardLines = board ? ["", "**工作项**", renderTaskBoardForUser(board, id, now)] : [];
|
|
155
175
|
const log = await readTaskLog(channelDir, id, {
|
|
156
176
|
kinds: ["step", "expired", "close", "note"],
|
|
157
177
|
limit: SHOW_LOG_LINES,
|
|
158
178
|
});
|
|
159
|
-
const logLines = log.length > 0 ? ["",
|
|
160
|
-
const
|
|
161
|
-
|
|
179
|
+
const logLines = log.length > 0 ? ["", "**最近记录**", ...log.map(renderTaskLogLineForUser)] : [];
|
|
180
|
+
const path = existsSync(taskPath(channelDir, id)) ? taskPath(channelDir, id) : archivedTaskPath(channelDir, id);
|
|
181
|
+
const contract = contractExcerpt(document.body, TASK_SHOW_CONTRACT_CHARS);
|
|
182
|
+
const report = [
|
|
183
|
+
...head,
|
|
184
|
+
...boardLines,
|
|
185
|
+
...logLines,
|
|
186
|
+
"",
|
|
187
|
+
"**任务说明**",
|
|
188
|
+
contract.text,
|
|
189
|
+
...(contract.clipped ? ["(仅显示开头)"] : []),
|
|
190
|
+
"",
|
|
191
|
+
`完整记录:\`/tasks log ${id}\`;任务文件:\`${path}\``,
|
|
192
|
+
].join("\n");
|
|
193
|
+
return capReply(report, { nextStepHint: `用 \`/tasks log ${id}\` 查看记录,完整任务说明在 \`${path}\`` }).text;
|
|
162
194
|
}
|
|
195
|
+
const ARCHIVE_OUTCOME = { completed: "已完成", cancelled: "已取消" };
|
|
163
196
|
async function listArchive(channelDir) {
|
|
164
197
|
const archiveDir = join(tasksDir(channelDir), "archive");
|
|
165
198
|
if (!existsSync(archiveDir))
|
|
@@ -168,21 +201,38 @@ async function listArchive(channelDir) {
|
|
|
168
201
|
if (files.length === 0)
|
|
169
202
|
return "暂无已归档任务。\n任务完成或取消后会出现在这里。";
|
|
170
203
|
const lines = [];
|
|
171
|
-
for (const filename of files.slice(0,
|
|
204
|
+
for (const filename of files.slice(0, ARCHIVE_LIST_LIMIT)) {
|
|
172
205
|
const id = filename.slice(0, -".md".length);
|
|
173
206
|
const document = await readStoredTask(channelDir, id, true).catch(() => undefined);
|
|
174
|
-
|
|
207
|
+
const outcome = document?.fields.outcome;
|
|
208
|
+
const bits = [`\`${id}\``];
|
|
209
|
+
if (outcome)
|
|
210
|
+
bits.push(ARCHIVE_OUTCOME[outcome] ?? outcome);
|
|
211
|
+
if (document?.fields.closedAt)
|
|
212
|
+
bits.push(document.fields.closedAt.slice(0, 16).replace("T", " "));
|
|
213
|
+
lines.push(`- ${bits.join(" · ")}`);
|
|
214
|
+
}
|
|
215
|
+
if (files.length > ARCHIVE_LIST_LIMIT) {
|
|
216
|
+
lines.push(`- 另有 ${files.length - ARCHIVE_LIST_LIMIT} 个,在 \`${archiveDir}\``);
|
|
175
217
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
218
|
+
return capReply([`**已归档任务(${files.length})**`, ...lines].join("\n"), {
|
|
219
|
+
nextStepHint: `完整列表在 \`${archiveDir}\``,
|
|
220
|
+
}).text;
|
|
179
221
|
}
|
|
180
222
|
async function showTaskLog(channelDir, idInput) {
|
|
181
223
|
const id = normalizeTaskId(idInput);
|
|
182
|
-
const
|
|
183
|
-
if (
|
|
184
|
-
return `任务 \`${id}\`
|
|
185
|
-
|
|
224
|
+
const all = await readTaskLog(channelDir, id);
|
|
225
|
+
if (all.length === 0)
|
|
226
|
+
return `任务 \`${id}\` 暂无记录。\n任务执行第一步后会出现在这里。`;
|
|
227
|
+
const records = all.slice(-LOG_LINES);
|
|
228
|
+
const path = taskLogIsArchived(channelDir, id) ? taskArchiveLogPath(channelDir, id) : taskLogPath(channelDir, id);
|
|
229
|
+
const lines = [
|
|
230
|
+
`**任务 ${id} 的记录(最近 ${records.length} 条,共 ${all.length} 条)**`,
|
|
231
|
+
...records.map(renderTaskLogLineForUser),
|
|
232
|
+
];
|
|
233
|
+
if (all.length > records.length)
|
|
234
|
+
lines.push("", `更早的记录在 \`${path}\``);
|
|
235
|
+
return capReply(lines.join("\n"), { nextStepHint: `完整记录在 \`${path}\`` }).text;
|
|
186
236
|
}
|
|
187
237
|
async function pauseTask(options, idInput) {
|
|
188
238
|
const id = normalizeTaskId(idInput);
|
|
@@ -191,14 +241,14 @@ async function pauseTask(options, idInput) {
|
|
|
191
241
|
reason: "用户通过 /tasks pause 暂停。",
|
|
192
242
|
});
|
|
193
243
|
if (!document)
|
|
194
|
-
return
|
|
195
|
-
return `已暂停任务 \`${id}
|
|
244
|
+
return notFound(id);
|
|
245
|
+
return `已暂停任务 \`${id}\`,等待条件已保留;需要继续时用 \`/tasks resume ${id}\`。`;
|
|
196
246
|
}
|
|
197
247
|
export async function resumeTask(options, idInput, grants = {}) {
|
|
198
248
|
const id = normalizeTaskId(idInput);
|
|
199
249
|
const document = await resumeTaskDocument(options.channelDir, id);
|
|
200
250
|
if (!document)
|
|
201
|
-
return
|
|
251
|
+
return notFound(id);
|
|
202
252
|
const granted = [];
|
|
203
253
|
if (Object.keys(grants).length > 0) {
|
|
204
254
|
await updateStoredTask(options.channelDir, id, (task) => {
|
|
@@ -212,20 +262,20 @@ export async function resumeTask(options, idInput, grants = {}) {
|
|
|
212
262
|
// on the next step.
|
|
213
263
|
const spent = key === "steps" ? task.fields.usage?.steps : task.fields.usage?.usd;
|
|
214
264
|
budget[key] = (spent ?? 0) + extra;
|
|
215
|
-
granted.push(`${
|
|
265
|
+
granted.push(key === "steps" ? `${extra} 步` : `$${extra}`);
|
|
216
266
|
}
|
|
217
267
|
task.fields.budget = budget;
|
|
218
268
|
});
|
|
219
269
|
}
|
|
220
|
-
return `已恢复任务 \`${id}\`${granted.length > 0 ?
|
|
270
|
+
return `已恢复任务 \`${id}\`${granted.length > 0 ? `,追加预算 ${granted.join("、")}` : ""}。`;
|
|
221
271
|
}
|
|
222
272
|
async function steerTask(options, idInput, text) {
|
|
223
273
|
const id = normalizeTaskId(idInput);
|
|
224
274
|
const document = await readStoredTask(options.channelDir, id);
|
|
225
275
|
if (!document)
|
|
226
|
-
return
|
|
276
|
+
return notFound(id);
|
|
227
277
|
await queueTaskSteer(options.channelDir, id, text);
|
|
228
|
-
return `已把这条指示排给任务 \`${id}\`
|
|
278
|
+
return `已把这条指示排给任务 \`${id}\` 的下一步,不会打断正在执行的这一步。`;
|
|
229
279
|
}
|
|
230
280
|
/**
|
|
231
281
|
* Answer an `ask` ticket: the reply becomes the next step's first input, and redeeming the ticket
|
|
@@ -236,7 +286,7 @@ async function replyToTask(options, idInput, text) {
|
|
|
236
286
|
const id = normalizeTaskId(idInput);
|
|
237
287
|
const document = await readStoredTask(options.channelDir, id);
|
|
238
288
|
if (!document)
|
|
239
|
-
return
|
|
289
|
+
return notFound(id);
|
|
240
290
|
await queueTaskSteer(options.channelDir, id, text, "用户回答");
|
|
241
291
|
const redeemed = await redeemTicket(options.channelDir, id, (ticket) => ticket.kind === "ask");
|
|
242
292
|
if (!redeemed) {
|
|
@@ -262,19 +312,19 @@ async function doctor(options) {
|
|
|
262
312
|
const problems = [];
|
|
263
313
|
for (const entry of entries) {
|
|
264
314
|
if (!entry.readable) {
|
|
265
|
-
problems.push(issue(
|
|
315
|
+
problems.push(issue(`\`${entry.id}\` 的文件头(frontmatter)不可读`, `让我修复 \`${taskPath(options.channelDir, entry.id)}\` 的文件头,或手动修改`));
|
|
266
316
|
continue;
|
|
267
317
|
}
|
|
268
318
|
if (entry.legacy) {
|
|
269
|
-
problems.push(issue(
|
|
319
|
+
problems.push(issue(`\`${entry.id}\` 仍含旧版本的字段(status / enabled / control / wake / schedule)`, `保留原件,按 ${docsUrl("events-and-tasks.md")} 的升级步骤处理;不要只删旧字段`));
|
|
270
320
|
}
|
|
271
321
|
const by = entry.fields.ticket ? parseLocalTime(entry.fields.ticket.by) : undefined;
|
|
272
322
|
if (entry.expired && !entry.fields.paused && by !== undefined && by < now - EXPIRED_GRACE_MS) {
|
|
273
|
-
problems.push(issue(
|
|
323
|
+
problems.push(issue(`\`${entry.id}\` 的等待条件已超过最晚检查时间 1 小时以上`, "自动调度本该重新开始或通知;请部署者确认服务器上的 pipiclaw 仍在运行"));
|
|
274
324
|
}
|
|
275
325
|
}
|
|
276
326
|
if (problems.length === 0)
|
|
277
|
-
return
|
|
327
|
+
return `检查了 ${entries.length} 个任务,未发现问题。`;
|
|
278
328
|
return [`**任务体检(${problems.length} 项)**`, ...problems].join("\n");
|
|
279
329
|
}
|
|
280
330
|
export async function handleTasksCommand(options) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { type TaskContractInput } from "./contract.js";
|
|
1
2
|
import type { TaskBudget } from "./frontmatter.js";
|
|
2
|
-
import { type TaskContractInput } from "./ledger.js";
|
|
3
3
|
/**
|
|
4
4
|
* Everything a task is created from. `task_create` takes exactly this plus an `id`, and an event
|
|
5
5
|
* template (`task` in a scheduled event, spec 052, D2) is exactly this — one shape, one
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { RecoverableToolError } from "../shared/recoverable-error.js";
|
|
2
2
|
import { isPlainObject } from "../shared/type-guards.js";
|
|
3
|
-
import { renderStandardTaskBody, uncheckedTaskAcceptanceItems } from "./
|
|
3
|
+
import { renderStandardTaskBody, uncheckedTaskAcceptanceItems } from "./contract.js";
|
|
4
4
|
function requiredText(value, field) {
|
|
5
5
|
if (typeof value !== "string" || !value.trim()) {
|
|
6
6
|
throw new RecoverableToolError(`task.${field} is required and must be a non-empty string.`);
|
package/dist/tasks/create.js
CHANGED
|
@@ -4,7 +4,7 @@ import { writeFileAtomically } from "../shared/atomic-file.js";
|
|
|
4
4
|
import { formatLocalTime } from "../shared/local-time.js";
|
|
5
5
|
import { RecoverableToolError } from "../shared/recoverable-error.js";
|
|
6
6
|
import { createUsage } from "./budget.js";
|
|
7
|
-
import { normalizeTaskId, renderStandardTaskBody, renderTaskDocument } from "./
|
|
7
|
+
import { normalizeTaskId, renderStandardTaskBody, renderTaskDocument } from "./contract.js";
|
|
8
8
|
import { archivedTaskPath, taskPath, tasksDir } from "./store.js";
|
|
9
9
|
/**
|
|
10
10
|
* Write a new task file, `open`, with its usage clock started. Shared by `task_create` and the
|
|
@@ -48,6 +48,11 @@ export interface ParsedTaskFrontmatter {
|
|
|
48
48
|
/** True when a v3 line (`status`, `control`, `schedule`…) is present — the file is not converted, so it never runs. */
|
|
49
49
|
legacy: boolean;
|
|
50
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* The one user-facing name for a task state (spec 053, D8). `/tasks`, the stop receipt and the
|
|
53
|
+
* spawn-skip receipt all read it here, so a third hand-written copy cannot drift again.
|
|
54
|
+
*/
|
|
55
|
+
export declare function taskStateLabel(state: TaskState): string;
|
|
51
56
|
/**
|
|
52
57
|
* Read the leading frontmatter block. Unreadable input fails **open** to a live `open` task: a
|
|
53
58
|
* corrupt file has to surface as work the runtime tries to touch, not silently disappear from the
|
|
@@ -2,6 +2,14 @@ import { formatLocalTime } from "../shared/local-time.js";
|
|
|
2
2
|
import { isPlainObject } from "../shared/type-guards.js";
|
|
3
3
|
import { parseTicket } from "./ticket.js";
|
|
4
4
|
const STATES = ["open", "parked", "done"];
|
|
5
|
+
const STATE_LABELS = { open: "进行中", parked: "等待中", done: "已结束" };
|
|
6
|
+
/**
|
|
7
|
+
* The one user-facing name for a task state (spec 053, D8). `/tasks`, the stop receipt and the
|
|
8
|
+
* spawn-skip receipt all read it here, so a third hand-written copy cannot drift again.
|
|
9
|
+
*/
|
|
10
|
+
export function taskStateLabel(state) {
|
|
11
|
+
return STATE_LABELS[state] ?? state;
|
|
12
|
+
}
|
|
5
13
|
/** Fixed render order, so a diff of a task file reads the same way every time. */
|
|
6
14
|
const FIELD_ORDER = ["state", "paused", "origin", "ticket", "usage", "budget"];
|
|
7
15
|
/** v3 frontmatter keys; their presence means the one-time conversion has not run on this file. */
|
|
@@ -115,5 +115,15 @@ export interface ReadTaskLogOptions {
|
|
|
115
115
|
* alike even though it was still on disk.
|
|
116
116
|
*/
|
|
117
117
|
export declare function readTaskLog(channelDir: string, id: string, options?: ReadTaskLogOptions): Promise<TaskLogRecord[]>;
|
|
118
|
-
/** One line per record, for the step brief and `/tasks
|
|
118
|
+
/** One line per record, for the step brief and `task_log` (model-facing; `/tasks` uses `renderTaskLogLineForUser`). */
|
|
119
119
|
export declare function renderTaskLogLine(record: TaskLogRecord): string;
|
|
120
|
+
/** A run id is `run_…`; anything else bound to a task is a background job. */
|
|
121
|
+
export declare function describeWorkRef(ref: string): string;
|
|
122
|
+
/** A settled run/job's outcome in words: `完成,验收通过` / `失败(退出码 1)`. */
|
|
123
|
+
export declare function describeSettlement(settle: Pick<TaskSettleRecord, "status" | "verdict" | "exitCode">): string;
|
|
124
|
+
/**
|
|
125
|
+
* One line per record for `/tasks show` and `/tasks log` (spec 053, D2). The same records as
|
|
126
|
+
* `renderTaskLogLine`, said in the user's terms: no `task_step_end` outcome values, no `VERDICT`,
|
|
127
|
+
* no tool names, minute precision.
|
|
128
|
+
*/
|
|
129
|
+
export declare function renderTaskLogLineForUser(record: TaskLogRecord): string;
|
|
@@ -3,9 +3,9 @@ import { readFile } from "node:fs/promises";
|
|
|
3
3
|
import { join } from "node:path";
|
|
4
4
|
import { createJsonlAppender } from "../shared/jsonl-appender.js";
|
|
5
5
|
import { formatLocalTime } from "../shared/local-time.js";
|
|
6
|
-
import { clipText } from "../shared/text-utils.js";
|
|
6
|
+
import { clipText, truncate } from "../shared/text-utils.js";
|
|
7
7
|
import { isPlainObject } from "../shared/type-guards.js";
|
|
8
|
-
import { normalizeTaskId } from "./
|
|
8
|
+
import { normalizeTaskId } from "./contract.js";
|
|
9
9
|
/** Same rotation shape as the channel archive: the log is working history, not an audit trail. */
|
|
10
10
|
const MAX_LOG_BYTES = 4 * 1024 * 1024;
|
|
11
11
|
const NOTE_MAX_CHARS = 4_000;
|
|
@@ -112,7 +112,7 @@ export async function readTaskLog(channelDir, id, options = {}) {
|
|
|
112
112
|
}
|
|
113
113
|
return options.limit !== undefined && records.length > options.limit ? records.slice(-options.limit) : records;
|
|
114
114
|
}
|
|
115
|
-
/** One line per record, for the step brief and `/tasks
|
|
115
|
+
/** One line per record, for the step brief and `task_log` (model-facing; `/tasks` uses `renderTaskLogLineForUser`). */
|
|
116
116
|
export function renderTaskLogLine(record) {
|
|
117
117
|
switch (record.kind) {
|
|
118
118
|
case "step":
|
|
@@ -129,3 +129,59 @@ export function renderTaskLogLine(record) {
|
|
|
129
129
|
return `- [${record.ts}] ${record.note}`;
|
|
130
130
|
}
|
|
131
131
|
}
|
|
132
|
+
/** `2026-10-11T14:02:33.000+08:00` → `10-11 14:02`: read straight off the stored wall-clock text, never re-zoned. */
|
|
133
|
+
function minuteStamp(ts) {
|
|
134
|
+
const match = /^\d{4}-(\d{2}-\d{2})T(\d{2}:\d{2})/.exec(ts);
|
|
135
|
+
return match ? `${match[1]} ${match[2]}` : ts;
|
|
136
|
+
}
|
|
137
|
+
/** A run id is `run_…`; anything else bound to a task is a background job. */
|
|
138
|
+
export function describeWorkRef(ref) {
|
|
139
|
+
return /^run_/i.test(ref) ? `委派 \`${ref}\`` : `后台作业 \`${ref}\``;
|
|
140
|
+
}
|
|
141
|
+
const SETTLE_STATUS = {
|
|
142
|
+
completed: "完成",
|
|
143
|
+
failed: "失败",
|
|
144
|
+
cancelled: "已取消",
|
|
145
|
+
lost: "已丢失",
|
|
146
|
+
running: "进行中",
|
|
147
|
+
};
|
|
148
|
+
/** A settled run/job's outcome in words: `完成,验收通过` / `失败(退出码 1)`. */
|
|
149
|
+
export function describeSettlement(settle) {
|
|
150
|
+
const parts = [SETTLE_STATUS[settle.status] ?? settle.status];
|
|
151
|
+
if (settle.verdict)
|
|
152
|
+
parts.push(settle.verdict === "pass" ? "验收通过" : "验收未通过");
|
|
153
|
+
const exit = settle.exitCode !== undefined && settle.exitCode !== 0 ? `(退出码 ${settle.exitCode})` : "";
|
|
154
|
+
return `${parts.join(",")}${exit}`;
|
|
155
|
+
}
|
|
156
|
+
function oneLine(text, max) {
|
|
157
|
+
return truncate(text.replace(/\s+/g, " ").trim(), max);
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* One line per record for `/tasks show` and `/tasks log` (spec 053, D2). The same records as
|
|
161
|
+
* `renderTaskLogLine`, said in the user's terms: no `task_step_end` outcome values, no `VERDICT`,
|
|
162
|
+
* no tool names, minute precision.
|
|
163
|
+
*/
|
|
164
|
+
export function renderTaskLogLineForUser(record) {
|
|
165
|
+
const at = minuteStamp(record.ts);
|
|
166
|
+
switch (record.kind) {
|
|
167
|
+
case "step": {
|
|
168
|
+
const after = record.outcome === "park" ? "(之后转入等待)" : record.outcome === "done" ? "(任务完成)" : "";
|
|
169
|
+
const reported = record.report ? ",已向你汇报" : "";
|
|
170
|
+
return `- ${at} 第 ${record.seq} 步:${oneLine(record.note, 160)}${after}${reported}`;
|
|
171
|
+
}
|
|
172
|
+
case "dispatch": {
|
|
173
|
+
const who = record.agent && record.agent !== "job"
|
|
174
|
+
? `(${record.agent}${record.purpose === "verify" ? ",验收" : ""})`
|
|
175
|
+
: "";
|
|
176
|
+
return `- ${at} 开始${describeWorkRef(record.ref)}${who}${record.item ? `,对应工作项 ${record.item}` : ""}`;
|
|
177
|
+
}
|
|
178
|
+
case "settle":
|
|
179
|
+
return `- ${at} ${describeWorkRef(record.ref)}结束:${describeSettlement(record)}`;
|
|
180
|
+
case "expired":
|
|
181
|
+
return `- ${at} 等待超时(${oneLine(record.ticket, 80)}),${record.action === "reopened" ? "已重新开始" : "已暂停"}`;
|
|
182
|
+
case "close":
|
|
183
|
+
return `- ${at} ${record.outcome === "done" ? "任务完成" : "任务取消"}:${oneLine(record.note, 160)}`;
|
|
184
|
+
case "note":
|
|
185
|
+
return `- ${at} ${oneLine(record.note, 160)}`;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { createSerialQueue } from "../shared/serial-queue.js";
|
|
4
|
-
import { normalizeTaskId } from "./
|
|
4
|
+
import { normalizeTaskId } from "./contract.js";
|
|
5
5
|
const mutationQueue = createSerialQueue();
|
|
6
6
|
const heldKeys = new AsyncLocalStorage();
|
|
7
7
|
function taskMutationKey(channelDir, id) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { join } from "node:path";
|
|
2
|
-
import { normalizeTaskId } from "./
|
|
2
|
+
import { normalizeTaskId } from "./contract.js";
|
|
3
3
|
/**
|
|
4
4
|
* Where a task's own agent session lives (spec 051, D3; one per task since spec 052, D1) —
|
|
5
5
|
* left behind when the task is archived. Kept out of `<channelDir>` root and under a dot-directory so
|
package/dist/tasks/steer.js
CHANGED
|
@@ -3,7 +3,7 @@ import { mkdir, readFile, rm } from "node:fs/promises";
|
|
|
3
3
|
import { join } from "node:path";
|
|
4
4
|
import { writeFileAtomically } from "../shared/atomic-file.js";
|
|
5
5
|
import { formatLocalTime } from "../shared/local-time.js";
|
|
6
|
-
import { normalizeTaskId } from "./
|
|
6
|
+
import { normalizeTaskId } from "./contract.js";
|
|
7
7
|
/**
|
|
8
8
|
* Out-of-band guidance for a running task loop (spec 051, D11) — `/tasks steer` and `/tasks reply`.
|
|
9
9
|
*
|
package/dist/tasks/store.js
CHANGED
|
@@ -6,9 +6,9 @@ import { writeFileAtomically } from "../shared/atomic-file.js";
|
|
|
6
6
|
import { formatLocalTime } from "../shared/local-time.js";
|
|
7
7
|
import { errorMessage } from "../shared/text-utils.js";
|
|
8
8
|
import { createUsage } from "./budget.js";
|
|
9
|
+
import { normalizeTaskId, renderTaskDocument, taskBody } from "./contract.js";
|
|
9
10
|
import { normalizeTaskFrontmatter, parseTaskFrontmatter, } from "./frontmatter.js";
|
|
10
|
-
import {
|
|
11
|
-
import { appendTaskLog, taskLogPath } from "./log.js";
|
|
11
|
+
import { appendTaskLog, taskLogPath } from "./loop-log.js";
|
|
12
12
|
import { withTaskMutation } from "./mutation-lock.js";
|
|
13
13
|
import { describeTicket, ticketExpired } from "./ticket.js";
|
|
14
14
|
/**
|
|
@@ -46,7 +46,9 @@ export async function writeStoredTask(document) {
|
|
|
46
46
|
const rendered = renderTaskDocument(fields, document.body);
|
|
47
47
|
const size = Buffer.byteLength(rendered, "utf-8");
|
|
48
48
|
if (size > MAX_CONTRACT_BYTES) {
|
|
49
|
-
log.
|
|
49
|
+
log.logWarn("tasks.contract.oversized", "Task contract exceeds its byte target; every step pays for it", {
|
|
50
|
+
fields: { taskId: document.id, bytes: size, targetBytes: MAX_CONTRACT_BYTES },
|
|
51
|
+
});
|
|
50
52
|
}
|
|
51
53
|
await writeFileAtomically(document.path, rendered);
|
|
52
54
|
}
|
|
@@ -132,7 +134,7 @@ export async function expireTicket(channelDir, id, limit = 2) {
|
|
|
132
134
|
outcome = "paused";
|
|
133
135
|
task.fields.paused = {
|
|
134
136
|
by: "runtime",
|
|
135
|
-
reason:
|
|
137
|
+
reason: `等待条件连续 ${expired} 次未满足:${summary}`,
|
|
136
138
|
at: formatLocalTime(),
|
|
137
139
|
};
|
|
138
140
|
return;
|
package/dist/tasks/ticket.d.ts
CHANGED
|
@@ -65,5 +65,7 @@ export declare function ticketBackstopMs(ticket: Ticket): number | undefined;
|
|
|
65
65
|
export declare function ticketExpired(ticket: Ticket, now?: Date): boolean;
|
|
66
66
|
/** The moment a `time` ticket is *due*. Only `time` tickets are driver-polled; the rest are pushed by their owner. */
|
|
67
67
|
export declare function ticketDueMs(ticket: Ticket): number | undefined;
|
|
68
|
-
/** One-line summary for
|
|
68
|
+
/** One-line summary for the step brief and the expiry record (model-facing). */
|
|
69
69
|
export declare function describeTicket(ticket: Ticket): string;
|
|
70
|
+
/** The same summary in the user's terms, for `/tasks` (spec 053, D4). */
|
|
71
|
+
export declare function describeTicketForUser(ticket: Ticket): string;
|
package/dist/tasks/ticket.js
CHANGED
|
@@ -107,7 +107,7 @@ export function ticketExpired(ticket, now = new Date()) {
|
|
|
107
107
|
export function ticketDueMs(ticket) {
|
|
108
108
|
return ticket.kind === "time" ? parseLocalTime(ticket.at) : undefined;
|
|
109
109
|
}
|
|
110
|
-
/** One-line summary for
|
|
110
|
+
/** One-line summary for the step brief and the expiry record (model-facing). */
|
|
111
111
|
export function describeTicket(ticket) {
|
|
112
112
|
switch (ticket.kind) {
|
|
113
113
|
case "time":
|
|
@@ -118,3 +118,21 @@ export function describeTicket(ticket) {
|
|
|
118
118
|
return `等待用户回答:${ticket.asked}`;
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
|
+
/** `2026-10-12T09:00:00.000+08:00` → `10-12 09:00`, read off the stored wall-clock text. */
|
|
122
|
+
function minuteOf(at) {
|
|
123
|
+
const match = /^\d{4}-(\d{2}-\d{2})T(\d{2}:\d{2})/.exec(at);
|
|
124
|
+
return match ? `${match[1]} ${match[2]}` : at;
|
|
125
|
+
}
|
|
126
|
+
/** The same summary in the user's terms, for `/tasks` (spec 053, D4). */
|
|
127
|
+
export function describeTicketForUser(ticket) {
|
|
128
|
+
switch (ticket.kind) {
|
|
129
|
+
case "time":
|
|
130
|
+
return `等到 ${minuteOf(ticket.at)}`;
|
|
131
|
+
case "work":
|
|
132
|
+
return ticket.refs.length > 0
|
|
133
|
+
? `等待 ${ticket.refs.map((ref) => `\`${ref}\``).join("、")} 完成`
|
|
134
|
+
: "等待委派或后台作业完成";
|
|
135
|
+
case "ask":
|
|
136
|
+
return `等你回答:${ticket.asked}`;
|
|
137
|
+
}
|
|
138
|
+
}
|
package/dist/tools/bash.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { AgentTool } from "@earendil-works/pi-agent-core";
|
|
2
2
|
import { Type } from "typebox";
|
|
3
|
-
import type { ChannelJobManager } from "../agent/job-manager.js";
|
|
4
3
|
import { type Executor } from "../executor.js";
|
|
4
|
+
import type { ChannelJobManager } from "../jobs/manager.js";
|
|
5
5
|
import type { SecurityConfig, SecurityRuntimeContext } from "../security/types.js";
|
|
6
6
|
/**
|
|
7
7
|
* Default wall-clock timeout for bash commands when the caller supplies neither a
|
package/dist/tools/bash.js
CHANGED
|
@@ -4,7 +4,7 @@ import { tmpdir } from "node:os";
|
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
import { Type } from "typebox";
|
|
6
6
|
import { CommandTerminatedError, EXECUTOR_SHELL_IS_BASH } from "../executor.js";
|
|
7
|
-
import { formatBlockMessage } from "../security/block-message.js";
|
|
7
|
+
import { formatBlockMessage, GuardBlockedError } from "../security/block-message.js";
|
|
8
8
|
import { guardCommand } from "../security/command-guard.js";
|
|
9
9
|
import { DEFAULT_SECURITY_CONFIG } from "../security/config.js";
|
|
10
10
|
import { logSecurityEvent } from "../security/logger.js";
|
|
@@ -188,7 +188,7 @@ export function createBashTool(executor, options = {}) {
|
|
|
188
188
|
reason: guardResult.reason,
|
|
189
189
|
matchedText: guardResult.matchedText,
|
|
190
190
|
});
|
|
191
|
-
throw new
|
|
191
|
+
throw new GuardBlockedError(formatCommandBlockMessage(command, guardResult.category, guardResult.reason, guardResult.matchedText), { guard: "command", category: guardResult.category, target: command });
|
|
192
192
|
}
|
|
193
193
|
}
|
|
194
194
|
// Steer a few bare shell patterns to their dedicated tool. After the guard (which must see
|