@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/desk/commands.js
CHANGED
|
@@ -12,21 +12,33 @@ import { normalizeDeskName } from "./paths.js";
|
|
|
12
12
|
* (shown missing, D4), each with the channels bound to it. `label` names a channel (the caller
|
|
13
13
|
* owns channel ids); `current` is the asking channel's desk.
|
|
14
14
|
*/
|
|
15
|
-
export function buildDeskList(desks, bindings, current, label) {
|
|
16
|
-
const
|
|
17
|
-
const names = [...new Set([...
|
|
18
|
-
return names.map((name) =>
|
|
19
|
-
name
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
15
|
+
export function buildDeskList(desks, bindings, current, label, activity) {
|
|
16
|
+
const summaries = new Map(desks.map((summary) => [summary.name, summary]));
|
|
17
|
+
const names = [...new Set([...summaries.keys(), ...Object.values(bindings).map((binding) => binding.desk)])].sort();
|
|
18
|
+
return names.map((name) => {
|
|
19
|
+
const summary = summaries.get(name);
|
|
20
|
+
const customCwd = summary?.record?.cwd && summary.record.cwd !== summary.deskDir ? summary.record.cwd : undefined;
|
|
21
|
+
const archived = Boolean(summary?.record?.archivedAt);
|
|
22
|
+
const live = activity?.get(name);
|
|
23
|
+
return {
|
|
24
|
+
name,
|
|
25
|
+
availability: summary?.availability ?? "missing",
|
|
26
|
+
current: name === current,
|
|
27
|
+
channels: Object.entries(bindings)
|
|
28
|
+
.filter(([, binding]) => binding.desk === name)
|
|
29
|
+
.map(([channelId]) => ({ channelId, label: label(channelId) })),
|
|
30
|
+
...(customCwd ? { cwd: customCwd } : {}),
|
|
31
|
+
...(archived ? { archived: true } : {}),
|
|
32
|
+
...(live?.activeTasks ? { activeTasks: live.activeTasks } : {}),
|
|
33
|
+
...(live?.pendingDeliveries ? { pendingDeliveries: live.pendingDeliveries } : {}),
|
|
34
|
+
...(live?.active ? { backgroundActive: true } : {}),
|
|
35
|
+
};
|
|
36
|
+
});
|
|
26
37
|
}
|
|
27
38
|
/** Exported so `test/commands-subcommands.test.ts` can feed every broadcast example back through it. */
|
|
28
39
|
export function parseDeskCommand(args) {
|
|
29
|
-
const
|
|
40
|
+
const trimmed = args.trim();
|
|
41
|
+
const parts = trimmed.split(/\s+/).filter(Boolean);
|
|
30
42
|
if (parts.length === 0)
|
|
31
43
|
return { action: "list" };
|
|
32
44
|
const [action, ...rest] = parts;
|
|
@@ -35,7 +47,29 @@ export function parseDeskCommand(args) {
|
|
|
35
47
|
throw new Error("用法:/desk list");
|
|
36
48
|
return { action: "list" };
|
|
37
49
|
}
|
|
38
|
-
if (action === "new"
|
|
50
|
+
if (action === "new") {
|
|
51
|
+
const match = /^new\s+(\S+)(?:\s+([\s\S]+))?$/.exec(trimmed);
|
|
52
|
+
if (!match)
|
|
53
|
+
throw new Error("用法:/desk new <名字> [目录绝对路径]");
|
|
54
|
+
const name = normalizeDeskName(match[1]);
|
|
55
|
+
const cwd = match[2]?.trim();
|
|
56
|
+
return cwd ? { action: "new", name, cwd } : { action: "new", name };
|
|
57
|
+
}
|
|
58
|
+
if (action === "bind") {
|
|
59
|
+
if (rest.length !== 1)
|
|
60
|
+
throw new Error("用法:/desk bind <名字>");
|
|
61
|
+
return { action: "bind", name: normalizeDeskName(rest[0]) };
|
|
62
|
+
}
|
|
63
|
+
if (action === "cwd") {
|
|
64
|
+
const match = /^cwd(?:\s+([\s\S]+))?$/.exec(trimmed);
|
|
65
|
+
const target = match?.[1]?.trim();
|
|
66
|
+
if (!target)
|
|
67
|
+
return { action: "cwd" };
|
|
68
|
+
if (target === "--reset" || target === "reset")
|
|
69
|
+
return { action: "cwd", reset: true };
|
|
70
|
+
return { action: "cwd", cwd: target };
|
|
71
|
+
}
|
|
72
|
+
if (action === "archive" || action === "unarchive") {
|
|
39
73
|
if (rest.length !== 1)
|
|
40
74
|
throw new Error(`用法:/desk ${action} <名字>`);
|
|
41
75
|
return { action, name: normalizeDeskName(rest[0]) };
|
|
@@ -57,15 +91,27 @@ function renderList(items, channelIndexPath, canBind) {
|
|
|
57
91
|
}
|
|
58
92
|
const lines = ["**工位列表**"];
|
|
59
93
|
for (const item of items) {
|
|
60
|
-
const
|
|
94
|
+
const cwdNote = item.cwd ? ` · 目录 \`${item.cwd}\`` : "";
|
|
95
|
+
const head = `- \`${item.name}\`${item.current ? (canBind ? "(本频道)" : "(当前打开)") : ""}${cwdNote}`;
|
|
96
|
+
const bgBits = [];
|
|
97
|
+
if (item.activeTasks)
|
|
98
|
+
bgBits.push(`${item.activeTasks} 个进行中任务`);
|
|
99
|
+
if (item.pendingDeliveries)
|
|
100
|
+
bgBits.push(`${item.pendingDeliveries} 条待收汇报`);
|
|
101
|
+
const bgSuffix = bgBits.length > 0 ? `(${bgBits.join("、")})` : "";
|
|
61
102
|
if (item.availability !== "available") {
|
|
62
103
|
lines.push(`${head}:不可用(目录缺失或 desk.json 有误),需要部署者在服务器上检查`);
|
|
63
104
|
}
|
|
105
|
+
else if (item.archived) {
|
|
106
|
+
lines.push(`${head}:已归档(用 \`/desk bind ${item.name}\` 或 \`/desk unarchive ${item.name}\` 恢复)`);
|
|
107
|
+
}
|
|
64
108
|
else if (item.channels.length === 0) {
|
|
65
|
-
lines.push(
|
|
109
|
+
lines.push(item.backgroundActive || bgBits.length > 0
|
|
110
|
+
? `${head}:未绑定频道 · 后台活跃${bgSuffix}`
|
|
111
|
+
: `${head}:未绑定频道 · 已休眠`);
|
|
66
112
|
}
|
|
67
113
|
else {
|
|
68
|
-
lines.push(`${head}:${item.channels.map((channel) => channel.label).join("、")}`);
|
|
114
|
+
lines.push(`${head}:${item.channels.map((channel) => channel.label).join("、")}${bgSuffix}`);
|
|
69
115
|
}
|
|
70
116
|
}
|
|
71
117
|
return capReply(lines.join("\n"), {
|
|
@@ -76,15 +122,34 @@ function renderCreate(outcome, canBind) {
|
|
|
76
122
|
switch (outcome.kind) {
|
|
77
123
|
case "invalid":
|
|
78
124
|
return `工位名不合法:\`${outcome.name}\`。${NAME_RULE}。`;
|
|
125
|
+
case "invalid_cwd":
|
|
126
|
+
return `工作目录无效:${outcome.reason}。`;
|
|
79
127
|
case "unavailable":
|
|
80
128
|
return `工位 \`${outcome.name}\` 已有绑定但记录缺失,请联系部署者从备份恢复。`;
|
|
81
129
|
case "exists":
|
|
82
130
|
return `工位 \`${outcome.name}\` 已经存在。用 \`/desk\` 查看已有的工位。`;
|
|
83
131
|
case "created": {
|
|
84
132
|
const name = outcome.record.name;
|
|
133
|
+
const cwdNote = outcome.record.cwd ? `(工作目录:\`${outcome.record.cwd}\`)` : "";
|
|
85
134
|
return canBind
|
|
86
|
-
? `已创建工位 \`${name}
|
|
87
|
-
: `已创建工位 \`${name}
|
|
135
|
+
? `已创建工位 \`${name}\`${cwdNote}。用 \`/desk bind ${name}\` 把本频道绑定到它。`
|
|
136
|
+
: `已创建工位 \`${name}\`${cwdNote}。在钉钉频道里用 \`/desk bind ${name}\` 绑定。`;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
function renderCwd(outcome, isQuery) {
|
|
141
|
+
switch (outcome.kind) {
|
|
142
|
+
case "invalid_cwd":
|
|
143
|
+
return `工作目录无效:${outcome.reason}。`;
|
|
144
|
+
case "busy":
|
|
145
|
+
return `工位 \`${outcome.desk}\` 当前${outcome.reason},暂不能切换工作目录。请等当前执行结束或先暂停相关任务后再试。`;
|
|
146
|
+
case "unavailable":
|
|
147
|
+
return `当前频道没有可用的工位,无法查看或修改工作目录。用 \`/desk\` 查看工位状态。`;
|
|
148
|
+
case "ok": {
|
|
149
|
+
const suffix = outcome.isDefault ? "(工位默认目录)" : "(自定义仓库目录,状态仍保存在工位目录)";
|
|
150
|
+
return isQuery
|
|
151
|
+
? `工位 \`${outcome.desk}\` 当前工作目录:\`${outcome.cwd}\`${suffix}。用 \`/desk cwd <绝对路径>\` 切换目录,或 \`/desk cwd --reset\` 恢复默认。`
|
|
152
|
+
: `已将工位 \`${outcome.desk}\` 的工作目录设为 \`${outcome.cwd}\`${suffix}。`;
|
|
88
153
|
}
|
|
89
154
|
}
|
|
90
155
|
}
|
|
@@ -103,22 +168,79 @@ function renderBind(outcome) {
|
|
|
103
168
|
case "same":
|
|
104
169
|
return `本频道已经绑定在工位 \`${outcome.desk}\` 上。`;
|
|
105
170
|
case "bound": {
|
|
106
|
-
const
|
|
171
|
+
const unarchivedNote = outcome.unarchived ? "(已从归档恢复)" : "";
|
|
172
|
+
const lines = [`本频道已绑定到工位 \`${outcome.desk}\`${unarchivedNote}。`];
|
|
107
173
|
if (outcome.previousDesk && outcome.previousDeskDormant) {
|
|
108
|
-
lines.push(`原工位 \`${outcome.previousDesk}\`
|
|
174
|
+
lines.push(`原工位 \`${outcome.previousDesk}\` 已没有绑定的频道与后台工作,已进入休眠;切回或打开 \`pipiclaw tui --desk ${outcome.previousDesk}\` 后自动恢复。`);
|
|
109
175
|
}
|
|
110
|
-
else if (outcome.previousDesk
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
if (outcome.suspendedEvents)
|
|
115
|
-
parts
|
|
116
|
-
|
|
176
|
+
else if (outcome.previousDesk) {
|
|
177
|
+
if (outcome.backgroundTasks) {
|
|
178
|
+
lines.push(`原工位 \`${outcome.previousDesk}\` 中有 ${outcome.backgroundTasks} 个后台任务继续执行;汇报与提问会暂存在该工位,切回 \`/desk bind ${outcome.previousDesk}\` 后自动送达(也可在其他入口执行 \`/tasks adopt <id>\` 接管)。`);
|
|
179
|
+
}
|
|
180
|
+
if ((outcome.suspendedTasks ?? 0) > 0 || (outcome.suspendedEvents ?? 0) > 0) {
|
|
181
|
+
const parts = [];
|
|
182
|
+
if (outcome.suspendedTasks)
|
|
183
|
+
parts.push(`${outcome.suspendedTasks} 个任务`);
|
|
184
|
+
if (outcome.suspendedEvents)
|
|
185
|
+
parts.push(`${outcome.suspendedEvents} 个聊天定时事件`);
|
|
186
|
+
lines.push(`原工位 \`${outcome.previousDesk}\` 中以本频道为投递目标的 ${parts.join("、")}已暂停,切回后自动恢复。`);
|
|
187
|
+
}
|
|
117
188
|
}
|
|
118
189
|
return lines.join("\n");
|
|
119
190
|
}
|
|
120
191
|
}
|
|
121
192
|
}
|
|
193
|
+
function renderArchive(outcome) {
|
|
194
|
+
switch (outcome.kind) {
|
|
195
|
+
case "invalid":
|
|
196
|
+
return `工位名不合法:\`${outcome.desk}\`。${NAME_RULE}。`;
|
|
197
|
+
case "forbidden":
|
|
198
|
+
return `当前身份无权管理工位 \`${outcome.desk}\`。`;
|
|
199
|
+
case "default":
|
|
200
|
+
return "默认工位 `default` 不能归档。";
|
|
201
|
+
case "unknown":
|
|
202
|
+
return `没有名为 \`${outcome.desk}\` 的工位。用 \`/desk\` 查看已有的工位。`;
|
|
203
|
+
case "unavailable":
|
|
204
|
+
return `工位 \`${outcome.desk}\` 当前不可用(目录缺失或 desk.json 有误),需要部署者在服务器上检查。`;
|
|
205
|
+
case "already_archived":
|
|
206
|
+
return `工位 \`${outcome.desk}\` 已经是归档状态。用 \`/desk unarchive ${outcome.desk}\` 或 \`/desk bind ${outcome.desk}\` 恢复。`;
|
|
207
|
+
case "current_channel":
|
|
208
|
+
return `当前频道正绑定在工位 \`${outcome.desk}\` 上。请先切换到其他工位(如 \`/desk bind default\`),再执行 \`/desk archive ${outcome.desk}\`。`;
|
|
209
|
+
case "bound_channels":
|
|
210
|
+
return `工位 \`${outcome.desk}\` 仍绑定着活跃频道(${outcome.channels.join("、")})。请先在这些频道切走后再归档。`;
|
|
211
|
+
case "busy":
|
|
212
|
+
return `工位 \`${outcome.desk}\` 当前${outcome.reason},暂不能归档。请等执行结束后再试。`;
|
|
213
|
+
case "open_tasks":
|
|
214
|
+
return `工位 \`${outcome.desk}\` 仍有 ${outcome.count} 个未完成任务(如 \`${outcome.sampleId}\`)。请先完成或执行 \`/tasks cancel <id>\` 取消后再归档。`;
|
|
215
|
+
case "archived": {
|
|
216
|
+
const notes = [];
|
|
217
|
+
if (outcome.unboundTerminals > 0)
|
|
218
|
+
notes.push(`清理了 ${outcome.unboundTerminals} 个历史终端绑定`);
|
|
219
|
+
if (outcome.stoppedEvents > 0)
|
|
220
|
+
notes.push(`暂停了 ${outcome.stoppedEvents} 个定时事件`);
|
|
221
|
+
const extra = notes.length > 0 ? `(${notes.join(",")})` : "";
|
|
222
|
+
return `已归档工位 \`${outcome.desk}\`${extra}。记忆与历史文件均保留;后续可用 \`/desk bind ${outcome.desk}\` 或 \`/desk unarchive ${outcome.desk}\` 恢复。`;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
function renderUnarchive(outcome) {
|
|
227
|
+
switch (outcome.kind) {
|
|
228
|
+
case "invalid":
|
|
229
|
+
return `工位名不合法:\`${outcome.desk}\`。${NAME_RULE}。`;
|
|
230
|
+
case "forbidden":
|
|
231
|
+
return `当前身份无权管理工位 \`${outcome.desk}\`。`;
|
|
232
|
+
case "unknown":
|
|
233
|
+
return `没有名为 \`${outcome.desk}\` 的工位。用 \`/desk\` 查看已有的工位。`;
|
|
234
|
+
case "unavailable":
|
|
235
|
+
return `工位 \`${outcome.desk}\` 当前不可用(目录缺失或 desk.json 有误),需要部署者在服务器上检查。`;
|
|
236
|
+
case "not_archived":
|
|
237
|
+
return `工位 \`${outcome.desk}\` 当前未归档,无需恢复。`;
|
|
238
|
+
case "unarchived":
|
|
239
|
+
return outcome.activated
|
|
240
|
+
? `已恢复工位 \`${outcome.desk}\`,后台定时服务已重新启动。可用 \`/desk bind ${outcome.desk}\` 切换过去。`
|
|
241
|
+
: `已恢复工位 \`${outcome.desk}\`。用 \`/desk bind ${outcome.desk}\` 把频道绑定过去后即可使用。`;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
122
244
|
export async function handleDeskCommand(args, port) {
|
|
123
245
|
let command;
|
|
124
246
|
try {
|
|
@@ -132,11 +254,23 @@ export async function handleDeskCommand(args, port) {
|
|
|
132
254
|
case "list":
|
|
133
255
|
return renderList(await port.list(), port.channelIndexPath, port.bind !== undefined);
|
|
134
256
|
case "new":
|
|
135
|
-
return renderCreate(await port.create(command.name), port.bind !== undefined);
|
|
257
|
+
return renderCreate(await port.create(command.name, command.cwd), port.bind !== undefined);
|
|
136
258
|
case "bind":
|
|
137
259
|
if (!port.bind)
|
|
138
260
|
return "终端不支持绑定,用 `--desk` 选择工位。";
|
|
139
261
|
return renderBind(await port.bind(command.name));
|
|
262
|
+
case "cwd":
|
|
263
|
+
if (!port.cwd)
|
|
264
|
+
return "当前入口不支持直接设置工作目录,请在对话频道或守护进程连接下执行 `/desk cwd`。";
|
|
265
|
+
return renderCwd(await port.cwd({ cwd: command.cwd, reset: command.reset }), !command.cwd && !command.reset);
|
|
266
|
+
case "archive":
|
|
267
|
+
if (!port.archive)
|
|
268
|
+
return "当前入口不支持归档工位,请在对话频道或守护进程连接下执行 `/desk archive`。";
|
|
269
|
+
return renderArchive(await port.archive(command.name));
|
|
270
|
+
case "unarchive":
|
|
271
|
+
if (!port.unarchive)
|
|
272
|
+
return "当前入口不支持恢复工位,请在对话频道或守护进程连接下执行 `/desk unarchive`。";
|
|
273
|
+
return renderUnarchive(await port.unarchive(command.name));
|
|
140
274
|
}
|
|
141
275
|
}
|
|
142
276
|
catch (error) {
|
package/dist/desk/paths.d.ts
CHANGED
|
@@ -11,6 +11,12 @@ export declare const SUBAGENT_RUNS_LOG_FILENAME = "subagent-runs.jsonl";
|
|
|
11
11
|
export declare function isDeskName(value: string): boolean;
|
|
12
12
|
/** What a user typed, as a candidate desk name: trimmed and lower-cased (validity is checked separately). */
|
|
13
13
|
export declare function normalizeDeskName(value: string): string;
|
|
14
|
+
/**
|
|
15
|
+
* Deterministic desk name for `pipiclaw tui --here`: slugifies the directory basename into the
|
|
16
|
+
* valid 1–32 char desk grammar, avoids clobbering `default`, and falls back to a path hash when
|
|
17
|
+
* the basename has no ASCII alphanumerics.
|
|
18
|
+
*/
|
|
19
|
+
export declare function deriveDeskNameFromPath(dirPath: string): string;
|
|
14
20
|
export declare function isConversationName(value: string): boolean;
|
|
15
21
|
/** `group-3` → `{ kind: "group", index: 3 }`; `undefined` for anything else. */
|
|
16
22
|
export declare function parseConversationName(value: string): {
|
package/dist/desk/paths.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { basename, join, resolve } from "node:path";
|
|
2
3
|
/**
|
|
3
4
|
* Every path segment under `workspace/desk-<name>/` comes from a desk name, a conversation name or a
|
|
4
5
|
* fixed file name — never from a channel id (spec 058, INV-3). Both names are validated here,
|
|
@@ -25,6 +26,25 @@ export function isDeskName(value) {
|
|
|
25
26
|
export function normalizeDeskName(value) {
|
|
26
27
|
return value.trim().toLowerCase();
|
|
27
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Deterministic desk name for `pipiclaw tui --here`: slugifies the directory basename into the
|
|
31
|
+
* valid 1–32 char desk grammar, avoids clobbering `default`, and falls back to a path hash when
|
|
32
|
+
* the basename has no ASCII alphanumerics.
|
|
33
|
+
*/
|
|
34
|
+
export function deriveDeskNameFromPath(dirPath) {
|
|
35
|
+
const resolved = resolve(dirPath);
|
|
36
|
+
const rawSlug = basename(resolved)
|
|
37
|
+
.toLowerCase()
|
|
38
|
+
.replace(/[^a-z0-9]+/g, "-")
|
|
39
|
+
.replace(/^-+|-+$/g, "")
|
|
40
|
+
.slice(0, 32)
|
|
41
|
+
.replace(/-+$/g, "");
|
|
42
|
+
if (rawSlug === DEFAULT_DESK)
|
|
43
|
+
return "dir-default";
|
|
44
|
+
if (rawSlug && isDeskName(rawSlug))
|
|
45
|
+
return rawSlug;
|
|
46
|
+
return `repo-${createHash("sha256").update(resolved).digest("hex").slice(0, 8)}`;
|
|
47
|
+
}
|
|
28
48
|
export function isConversationName(value) {
|
|
29
49
|
return CONVERSATION_NAME_PATTERN.test(value);
|
|
30
50
|
}
|
package/dist/desk/registry.d.ts
CHANGED
|
@@ -1,10 +1,25 @@
|
|
|
1
|
-
import type { ConversationKind, CreateDeskOutcome, DeskConversation, DeskRecord, DeskSummary } from "./types.js";
|
|
1
|
+
import type { ConversationKind, CreateDeskOutcome, DeskConversation, DeskCwdOutcome, DeskRecord, DeskSummary } from "./types.js";
|
|
2
2
|
/** Read one desk's record, classifying it the way `/desk` and binding resolution need. */
|
|
3
3
|
export declare function readDeskRecord(workspaceDir: string, name: string): Promise<DeskSummary>;
|
|
4
|
+
/** Synchronous counterpart of {@link readDeskRecord} for mtime-triggered cache refreshes. */
|
|
5
|
+
export declare function readDeskRecordSync(workspaceDir: string, name: string): DeskSummary;
|
|
4
6
|
/** Every directory under `desk-`, each classified. A directory with an illegal name is reported invalid. */
|
|
5
7
|
export declare function listDesks(workspaceDir: string): Promise<DeskSummary[]>;
|
|
8
|
+
export declare function validateCustomCwd(rawCwd: string): {
|
|
9
|
+
ok: true;
|
|
10
|
+
cwd: string;
|
|
11
|
+
} | {
|
|
12
|
+
ok: false;
|
|
13
|
+
reason: string;
|
|
14
|
+
};
|
|
6
15
|
/** Create an empty desk without binding it, publishing it atomically. Holds no conversation lock. */
|
|
7
|
-
export declare function createDeskRecord(workspaceDir: string, name: string, now: Date): CreateDeskOutcome;
|
|
16
|
+
export declare function createDeskRecord(workspaceDir: string, name: string, now: Date, cwd?: string): CreateDeskOutcome;
|
|
17
|
+
/** Update or reset (`cwd: null`) a desk's custom `cwd` under `desk-json.lock`. */
|
|
18
|
+
export declare function setDeskCwd(workspaceDir: string, desk: string, cwd: string | null): Promise<DeskCwdOutcome>;
|
|
19
|
+
/** Set (`archivedAt` string) or clear (`null`) a desk's archive timestamp under `desk-json.lock`. */
|
|
20
|
+
export declare function setDeskArchived(workspaceDir: string, desk: string, archivedAt: string | null): Promise<DeskSummary>;
|
|
21
|
+
/** Read-only lookup of a desk's effective working directory (`desk.json` `cwd`, else `deskDir`). */
|
|
22
|
+
export declare function resolveDeskCwdSync(workspaceDir: string, desk: string): string;
|
|
8
23
|
/**
|
|
9
24
|
* The conversation directory a channel uses in this desk, allocating it on first use (INV-7):
|
|
10
25
|
* `<kind>-<n>` with `n` one past the largest index of that kind already in `desk.json`. Idempotent —
|
package/dist/desk/registry.js
CHANGED
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
* Channel ids are only JSON keys here; this module never parses them — callers pass the
|
|
10
10
|
* conversation kind (the format rules live in `channel/channel-id.ts`).
|
|
11
11
|
*/
|
|
12
|
-
import { lstatSync, mkdirSync, mkdtempSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
12
|
+
import { lstatSync, mkdirSync, mkdtempSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
13
13
|
import { mkdir, readdir, readFile } from "node:fs/promises";
|
|
14
|
-
import { isAbsolute, join } from "node:path";
|
|
14
|
+
import { isAbsolute, join, resolve } from "node:path";
|
|
15
15
|
import { syncDirectoryBestEffort, writeFileAtomically } from "../shared/atomic-file.js";
|
|
16
16
|
import { withFileLock } from "../shared/file-lock.js";
|
|
17
17
|
import { createSerialQueue } from "../shared/serial-queue.js";
|
|
@@ -42,6 +42,10 @@ function invalidRecordReason(value, dirName) {
|
|
|
42
42
|
if (value.cwd !== undefined && (typeof value.cwd !== "string" || !isAbsolute(value.cwd))) {
|
|
43
43
|
return "desk.json cwd must be an absolute path";
|
|
44
44
|
}
|
|
45
|
+
if (value.archivedAt !== undefined &&
|
|
46
|
+
(typeof value.archivedAt !== "string" || !Number.isFinite(Date.parse(value.archivedAt)))) {
|
|
47
|
+
return "desk.json archivedAt must be an ISO timestamp string";
|
|
48
|
+
}
|
|
45
49
|
const dirs = new Set();
|
|
46
50
|
for (const [channelId, entry] of Object.entries(value.conversations)) {
|
|
47
51
|
if (!isPlainObject(entry) || typeof entry.dir !== "string" || !isConversationName(entry.dir)) {
|
|
@@ -53,6 +57,19 @@ function invalidRecordReason(value, dirName) {
|
|
|
53
57
|
}
|
|
54
58
|
return undefined;
|
|
55
59
|
}
|
|
60
|
+
function parseDeskRecordText(name, deskDir, text) {
|
|
61
|
+
let parsed;
|
|
62
|
+
try {
|
|
63
|
+
parsed = JSON.parse(text);
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
return { name, deskDir, availability: "invalid", reason: `${recordPath(deskDir)} is not valid JSON` };
|
|
67
|
+
}
|
|
68
|
+
const reason = invalidRecordReason(parsed, name);
|
|
69
|
+
if (reason)
|
|
70
|
+
return { name, deskDir, availability: "invalid", reason };
|
|
71
|
+
return { name, deskDir, availability: "available", record: parsed };
|
|
72
|
+
}
|
|
56
73
|
/** Read one desk's record, classifying it the way `/desk` and binding resolution need. */
|
|
57
74
|
export async function readDeskRecord(workspaceDir, name) {
|
|
58
75
|
if (!isDeskName(name)) {
|
|
@@ -72,17 +89,28 @@ export async function readDeskRecord(workspaceDir, name) {
|
|
|
72
89
|
reason: code === "ENOENT" ? `${recordPath(deskDir)} does not exist` : `cannot read ${recordPath(deskDir)}`,
|
|
73
90
|
};
|
|
74
91
|
}
|
|
75
|
-
|
|
92
|
+
return parseDeskRecordText(name, deskDir, text);
|
|
93
|
+
}
|
|
94
|
+
/** Synchronous counterpart of {@link readDeskRecord} for mtime-triggered cache refreshes. */
|
|
95
|
+
export function readDeskRecordSync(workspaceDir, name) {
|
|
96
|
+
if (!isDeskName(name)) {
|
|
97
|
+
return { name, deskDir: "", availability: "invalid", reason: `invalid desk name ${JSON.stringify(name)}` };
|
|
98
|
+
}
|
|
99
|
+
const deskDir = getDeskDir(workspaceDir, name);
|
|
100
|
+
let text;
|
|
76
101
|
try {
|
|
77
|
-
|
|
102
|
+
text = readFileSync(recordPath(deskDir), "utf-8");
|
|
78
103
|
}
|
|
79
|
-
catch {
|
|
80
|
-
|
|
104
|
+
catch (error) {
|
|
105
|
+
const code = errorCode(error);
|
|
106
|
+
return {
|
|
107
|
+
name,
|
|
108
|
+
deskDir,
|
|
109
|
+
availability: code === "ENOENT" ? "missing" : "invalid",
|
|
110
|
+
reason: code === "ENOENT" ? `${recordPath(deskDir)} does not exist` : `cannot read ${recordPath(deskDir)}`,
|
|
111
|
+
};
|
|
81
112
|
}
|
|
82
|
-
|
|
83
|
-
if (reason)
|
|
84
|
-
return { name, deskDir, availability: "invalid", reason };
|
|
85
|
-
return { name, deskDir, availability: "available", record: parsed };
|
|
113
|
+
return parseDeskRecordText(name, deskDir, text);
|
|
86
114
|
}
|
|
87
115
|
/** Every directory under `desk-`, each classified. A directory with an illegal name is reported invalid. */
|
|
88
116
|
export async function listDesks(workspaceDir) {
|
|
@@ -100,10 +128,33 @@ export async function listDesks(workspaceDir) {
|
|
|
100
128
|
const summaries = await Promise.all(entries.sort().map((name) => readDeskRecord(workspaceDir, name)));
|
|
101
129
|
return summaries;
|
|
102
130
|
}
|
|
131
|
+
export function validateCustomCwd(rawCwd) {
|
|
132
|
+
const trimmed = rawCwd.trim();
|
|
133
|
+
if (!trimmed || !isAbsolute(trimmed)) {
|
|
134
|
+
return { ok: false, reason: "目录路径必须是绝对路径(例如 `/srv/repo`)" };
|
|
135
|
+
}
|
|
136
|
+
const normalized = resolve(trimmed);
|
|
137
|
+
try {
|
|
138
|
+
if (!statSync(normalized).isDirectory()) {
|
|
139
|
+
return { ok: false, reason: `路径不是目录:\`${normalized}\`` };
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
catch {
|
|
143
|
+
return { ok: false, reason: `目录不存在或无法访问:\`${normalized}\`` };
|
|
144
|
+
}
|
|
145
|
+
return { ok: true, cwd: normalized };
|
|
146
|
+
}
|
|
103
147
|
/** Create an empty desk without binding it, publishing it atomically. Holds no conversation lock. */
|
|
104
|
-
export function createDeskRecord(workspaceDir, name, now) {
|
|
148
|
+
export function createDeskRecord(workspaceDir, name, now, cwd) {
|
|
105
149
|
if (!isDeskName(name))
|
|
106
150
|
return { kind: "invalid", name };
|
|
151
|
+
let validatedCwd;
|
|
152
|
+
if (cwd !== undefined) {
|
|
153
|
+
const checked = validateCustomCwd(cwd);
|
|
154
|
+
if (!checked.ok)
|
|
155
|
+
return { kind: "invalid_cwd", cwd, reason: checked.reason };
|
|
156
|
+
validatedCwd = checked.cwd;
|
|
157
|
+
}
|
|
107
158
|
const bindings = initializeBindings(workspaceDir);
|
|
108
159
|
const deskDir = getDeskDir(workspaceDir, name);
|
|
109
160
|
try {
|
|
@@ -118,7 +169,13 @@ export function createDeskRecord(workspaceDir, name, now) {
|
|
|
118
169
|
return { kind: "unavailable", name };
|
|
119
170
|
mkdirSync(workspaceDir, { recursive: true });
|
|
120
171
|
const staging = mkdtempSync(join(workspaceDir, `.desk-init-${name}-`));
|
|
121
|
-
const record = {
|
|
172
|
+
const record = {
|
|
173
|
+
version: 1,
|
|
174
|
+
name,
|
|
175
|
+
createdAt: now.toISOString(),
|
|
176
|
+
conversations: {},
|
|
177
|
+
...(validatedCwd && validatedCwd !== deskDir ? { cwd: validatedCwd } : {}),
|
|
178
|
+
};
|
|
122
179
|
try {
|
|
123
180
|
writeFileSync(recordPath(staging), `${JSON.stringify(record, null, "\t")}\n`, { flush: true });
|
|
124
181
|
syncDirectoryBestEffort(staging);
|
|
@@ -137,6 +194,59 @@ export function createDeskRecord(workspaceDir, name, now) {
|
|
|
137
194
|
rmSync(staging, { recursive: true, force: true });
|
|
138
195
|
}
|
|
139
196
|
}
|
|
197
|
+
/** Update or reset (`cwd: null`) a desk's custom `cwd` under `desk-json.lock`. */
|
|
198
|
+
export async function setDeskCwd(workspaceDir, desk, cwd) {
|
|
199
|
+
if (!isDeskName(desk))
|
|
200
|
+
return { kind: "unavailable", desk };
|
|
201
|
+
let nextCwd;
|
|
202
|
+
if (cwd !== null) {
|
|
203
|
+
const checked = validateCustomCwd(cwd);
|
|
204
|
+
if (!checked.ok)
|
|
205
|
+
return { kind: "invalid_cwd", cwd, reason: checked.reason };
|
|
206
|
+
nextCwd = checked.cwd;
|
|
207
|
+
}
|
|
208
|
+
const deskDir = getDeskDir(workspaceDir, desk);
|
|
209
|
+
return withFileLock(getDeskLockPath(deskDir, "desk-json.lock"), () => writeQueue.run(recordPath(deskDir), async () => {
|
|
210
|
+
const summary = await readDeskRecord(workspaceDir, desk);
|
|
211
|
+
if (!summary.record)
|
|
212
|
+
return { kind: "unavailable", desk };
|
|
213
|
+
const { cwd: _prev, ...rest } = summary.record;
|
|
214
|
+
const effective = nextCwd && nextCwd !== deskDir ? nextCwd : undefined;
|
|
215
|
+
const updated = effective ? { ...rest, cwd: effective } : rest;
|
|
216
|
+
await writeJson(recordPath(deskDir), updated);
|
|
217
|
+
return { kind: "ok", desk, cwd: effective ?? deskDir, isDefault: effective === undefined };
|
|
218
|
+
}), { timeoutMs: DESK_RECORD_LOCK_TIMEOUT_MS });
|
|
219
|
+
}
|
|
220
|
+
/** Set (`archivedAt` string) or clear (`null`) a desk's archive timestamp under `desk-json.lock`. */
|
|
221
|
+
export async function setDeskArchived(workspaceDir, desk, archivedAt) {
|
|
222
|
+
if (!isDeskName(desk)) {
|
|
223
|
+
return { name: desk, deskDir: "", availability: "invalid", reason: `invalid desk name ${JSON.stringify(desk)}` };
|
|
224
|
+
}
|
|
225
|
+
const deskDir = getDeskDir(workspaceDir, desk);
|
|
226
|
+
return withFileLock(getDeskLockPath(deskDir, "desk-json.lock"), () => writeQueue.run(recordPath(deskDir), async () => {
|
|
227
|
+
const summary = await readDeskRecord(workspaceDir, desk);
|
|
228
|
+
if (!summary.record)
|
|
229
|
+
return summary;
|
|
230
|
+
const { archivedAt: _prev, ...rest } = summary.record;
|
|
231
|
+
const updated = archivedAt ? { ...rest, archivedAt } : rest;
|
|
232
|
+
await writeJson(recordPath(deskDir), updated);
|
|
233
|
+
return { name: desk, deskDir, availability: "available", record: updated };
|
|
234
|
+
}), { timeoutMs: DESK_RECORD_LOCK_TIMEOUT_MS });
|
|
235
|
+
}
|
|
236
|
+
/** Read-only lookup of a desk's effective working directory (`desk.json` `cwd`, else `deskDir`). */
|
|
237
|
+
export function resolveDeskCwdSync(workspaceDir, desk) {
|
|
238
|
+
const deskDir = getDeskDir(workspaceDir, desk);
|
|
239
|
+
try {
|
|
240
|
+
const parsed = JSON.parse(readFileSync(recordPath(deskDir), "utf-8"));
|
|
241
|
+
if (isPlainObject(parsed) && typeof parsed.cwd === "string" && isAbsolute(parsed.cwd)) {
|
|
242
|
+
return parsed.cwd;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
catch {
|
|
246
|
+
// Fall back to the desk directory when `desk.json` is absent or unreadable.
|
|
247
|
+
}
|
|
248
|
+
return deskDir;
|
|
249
|
+
}
|
|
140
250
|
/**
|
|
141
251
|
* The conversation directory a channel uses in this desk, allocating it on first use (INV-7):
|
|
142
252
|
* `<kind>-<n>` with `n` one past the largest index of that kind already in `desk.json`. Idempotent —
|
package/dist/desk/types.d.ts
CHANGED
|
@@ -23,9 +23,11 @@ export interface DeskRecord {
|
|
|
23
23
|
/**
|
|
24
24
|
* Optional absolute working directory for the agent (shell cwd, relative-path base, default
|
|
25
25
|
* delegation directory). Absent means the desk directory itself. Memory, tasks, events and
|
|
26
|
-
* every other piece of desk state stay in the desk directory regardless.
|
|
26
|
+
* every other piece of desk state stay in the desk directory regardless.
|
|
27
27
|
*/
|
|
28
28
|
cwd?: string;
|
|
29
|
+
/** Set when the desk is archived (`/desk archive`): dormant until rebound or unarchived. */
|
|
30
|
+
archivedAt?: string;
|
|
29
31
|
}
|
|
30
32
|
export interface DeskBinding {
|
|
31
33
|
desk: string;
|
|
@@ -63,6 +65,10 @@ export type CreateDeskOutcome = {
|
|
|
63
65
|
} | {
|
|
64
66
|
kind: "invalid";
|
|
65
67
|
name: string;
|
|
68
|
+
} | {
|
|
69
|
+
kind: "invalid_cwd";
|
|
70
|
+
cwd: string;
|
|
71
|
+
reason: string;
|
|
66
72
|
} | {
|
|
67
73
|
kind: "exists";
|
|
68
74
|
name: string;
|
|
@@ -70,3 +76,79 @@ export type CreateDeskOutcome = {
|
|
|
70
76
|
kind: "unavailable";
|
|
71
77
|
name: string;
|
|
72
78
|
};
|
|
79
|
+
export type DeskCwdOutcome = {
|
|
80
|
+
kind: "ok";
|
|
81
|
+
desk: string;
|
|
82
|
+
cwd: string;
|
|
83
|
+
isDefault: boolean;
|
|
84
|
+
} | {
|
|
85
|
+
kind: "busy";
|
|
86
|
+
desk: string;
|
|
87
|
+
reason: string;
|
|
88
|
+
} | {
|
|
89
|
+
kind: "invalid_cwd";
|
|
90
|
+
cwd: string;
|
|
91
|
+
reason: string;
|
|
92
|
+
} | {
|
|
93
|
+
kind: "unavailable";
|
|
94
|
+
desk: string;
|
|
95
|
+
};
|
|
96
|
+
export type ArchiveDeskOutcome = {
|
|
97
|
+
kind: "archived";
|
|
98
|
+
desk: string;
|
|
99
|
+
unboundTerminals: number;
|
|
100
|
+
stoppedEvents: number;
|
|
101
|
+
} | {
|
|
102
|
+
kind: "already_archived";
|
|
103
|
+
desk: string;
|
|
104
|
+
} | {
|
|
105
|
+
kind: "default";
|
|
106
|
+
} | {
|
|
107
|
+
kind: "current_channel";
|
|
108
|
+
desk: string;
|
|
109
|
+
} | {
|
|
110
|
+
kind: "bound_channels";
|
|
111
|
+
desk: string;
|
|
112
|
+
channels: string[];
|
|
113
|
+
} | {
|
|
114
|
+
kind: "open_tasks";
|
|
115
|
+
desk: string;
|
|
116
|
+
count: number;
|
|
117
|
+
sampleId: string;
|
|
118
|
+
} | {
|
|
119
|
+
kind: "busy";
|
|
120
|
+
desk: string;
|
|
121
|
+
reason: string;
|
|
122
|
+
} | {
|
|
123
|
+
kind: "unknown";
|
|
124
|
+
desk: string;
|
|
125
|
+
} | {
|
|
126
|
+
kind: "unavailable";
|
|
127
|
+
desk: string;
|
|
128
|
+
} | {
|
|
129
|
+
kind: "invalid";
|
|
130
|
+
desk: string;
|
|
131
|
+
} | {
|
|
132
|
+
kind: "forbidden";
|
|
133
|
+
desk: string;
|
|
134
|
+
};
|
|
135
|
+
export type UnarchiveDeskOutcome = {
|
|
136
|
+
kind: "unarchived";
|
|
137
|
+
desk: string;
|
|
138
|
+
activated: boolean;
|
|
139
|
+
} | {
|
|
140
|
+
kind: "not_archived";
|
|
141
|
+
desk: string;
|
|
142
|
+
} | {
|
|
143
|
+
kind: "unknown";
|
|
144
|
+
desk: string;
|
|
145
|
+
} | {
|
|
146
|
+
kind: "unavailable";
|
|
147
|
+
desk: string;
|
|
148
|
+
} | {
|
|
149
|
+
kind: "invalid";
|
|
150
|
+
desk: string;
|
|
151
|
+
} | {
|
|
152
|
+
kind: "forbidden";
|
|
153
|
+
desk: string;
|
|
154
|
+
};
|
package/dist/dingtalk/bot.d.ts
CHANGED
|
@@ -74,7 +74,7 @@ export declare class DingTalkBot implements DeliveryPort {
|
|
|
74
74
|
* deterministic e2e harness can override it and run the inbound path with zero network, the
|
|
75
75
|
* same pattern `HarnessDingTalkBot` already uses for outbound calls.
|
|
76
76
|
*/
|
|
77
|
-
protected downloadMessageFile(downloadCode: string): Promise<{
|
|
77
|
+
protected downloadMessageFile(downloadCode: string, maxBytes?: number): Promise<{
|
|
78
78
|
data: Buffer;
|
|
79
79
|
} | null>;
|
|
80
80
|
private touchChannel;
|
package/dist/dingtalk/bot.js
CHANGED
|
@@ -41,7 +41,7 @@ export class DingTalkBot {
|
|
|
41
41
|
getAccessToken,
|
|
42
42
|
getConversationMeta: (channelId) => this.conversations.get(channelId),
|
|
43
43
|
sendRobotMessage: sendRobot,
|
|
44
|
-
downloadMessageFile: (downloadCode) => this.downloadMessageFile(downloadCode),
|
|
44
|
+
downloadMessageFile: (downloadCode, maxBytes) => this.downloadMessageFile(downloadCode, maxBytes),
|
|
45
45
|
});
|
|
46
46
|
this.connection = new StreamConnection({
|
|
47
47
|
clientId: this.config.clientId,
|
|
@@ -56,6 +56,7 @@ export class DingTalkBot {
|
|
|
56
56
|
isStopped: () => this.isStopped,
|
|
57
57
|
ack: (messageId) => this.connection.ack(messageId),
|
|
58
58
|
collectAttachments: (parsed) => this.media.collectInboundAttachments(parsed),
|
|
59
|
+
sendPlain: (channelId, text) => this.sendPlain(channelId, text),
|
|
59
60
|
});
|
|
60
61
|
}
|
|
61
62
|
get busyMessageDefault() {
|
|
@@ -188,8 +189,8 @@ export class DingTalkBot {
|
|
|
188
189
|
* deterministic e2e harness can override it and run the inbound path with zero network, the
|
|
189
190
|
* same pattern `HarnessDingTalkBot` already uses for outbound calls.
|
|
190
191
|
*/
|
|
191
|
-
downloadMessageFile(downloadCode) {
|
|
192
|
-
return this.media.downloadMessageFile(downloadCode);
|
|
192
|
+
downloadMessageFile(downloadCode, maxBytes) {
|
|
193
|
+
return this.media.downloadMessageFile(downloadCode, maxBytes);
|
|
193
194
|
}
|
|
194
195
|
touchChannel(channelId) {
|
|
195
196
|
this.channelLastActiveAt.set(channelId, Date.now());
|