@oyasmi/pipiclaw 0.9.6-beta.1 → 0.9.6-beta.3
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 +279 -215
- package/README.md +274 -213
- package/dist/agent/builtin-commands.d.ts +1 -1
- package/dist/agent/builtin-commands.js +1 -1
- package/dist/agent/channel-runner.d.ts +3 -2
- package/dist/agent/channel-runner.js +18 -27
- package/dist/agent/maintenance-context.js +22 -3
- 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 +1 -1
- 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/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 +4 -2
- package/dist/agent/session/session-host.js +17 -15
- package/dist/agent/status-render.js +3 -0
- 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 +14 -12
- 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/types.d.ts +20 -2
- 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/channel-context.d.ts +6 -0
- package/dist/channel/config.d.ts +3 -0
- package/dist/channel/config.js +11 -5
- package/dist/commands/catalog.js +22 -6
- package/dist/config/settings.d.ts +0 -2
- package/dist/config/settings.js +0 -2
- package/dist/config/tools.d.ts +8 -2
- package/dist/config/tools.js +35 -19
- package/dist/desk/commands.d.ts +31 -4
- package/dist/desk/commands.js +101 -15
- package/dist/desk/paths.d.ts +6 -0
- package/dist/desk/paths.js +21 -1
- package/dist/desk/registry.d.ts +11 -0
- package/dist/desk/registry.js +53 -9
- package/dist/desk/types.d.ts +66 -1
- package/dist/dingtalk/config.js +10 -10
- package/dist/dingtalk/delivery.js +2 -0
- package/dist/dingtalk/inbound.js +2 -3
- package/dist/events/watcher.d.ts +1 -1
- package/dist/events/watcher.js +2 -2
- package/dist/main.js +15 -3
- package/dist/memory/anchors.d.ts +5 -0
- package/dist/memory/anchors.js +49 -0
- package/dist/memory/boundary-work.d.ts +3 -1
- package/dist/memory/boundary-work.js +2 -1
- package/dist/memory/commands.js +23 -6
- package/dist/memory/index-budget.d.ts +16 -0
- package/dist/memory/index-budget.js +24 -2
- package/dist/memory/journal.d.ts +7 -12
- package/dist/memory/journal.js +9 -41
- package/dist/memory/lifecycle.d.ts +3 -1
- package/dist/memory/lifecycle.js +4 -2
- package/dist/memory/reflect-job.d.ts +3 -1
- package/dist/memory/reflect-job.js +2 -1
- package/dist/memory/reflect.d.ts +12 -1
- package/dist/memory/reflect.js +104 -20
- package/dist/memory/render.d.ts +4 -1
- package/dist/memory/render.js +6 -4
- package/dist/memory/review-log.d.ts +2 -2
- package/dist/memory/scheduler.d.ts +9 -1
- package/dist/memory/scheduler.js +71 -4
- package/dist/memory/search-index-db.d.ts +15 -0
- package/dist/memory/search-index-db.js +247 -0
- package/dist/memory/search-index-files.d.ts +11 -0
- package/dist/memory/search-index-files.js +26 -0
- package/dist/memory/search-index-notes.d.ts +11 -0
- package/dist/memory/search-index-notes.js +155 -0
- package/dist/memory/search-index-sync.d.ts +19 -0
- package/dist/memory/search-index-sync.js +267 -0
- package/dist/memory/search-terms.d.ts +12 -0
- package/dist/memory/search-terms.js +185 -0
- package/dist/memory/search.d.ts +8 -28
- package/dist/memory/search.js +18 -278
- package/dist/memory/session-corpus.d.ts +15 -26
- package/dist/memory/session-corpus.js +120 -321
- package/dist/memory/session-search.d.ts +7 -4
- package/dist/memory/session-search.js +120 -172
- package/dist/memory/sidecar-worker.d.ts +4 -1
- package/dist/memory/sidecar-worker.js +27 -5
- package/dist/memory/store.d.ts +4 -0
- package/dist/memory/store.js +22 -1
- package/dist/memory/task-archive-digest.d.ts +61 -0
- package/dist/memory/task-archive-digest.js +366 -0
- 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.d.ts +1 -1
- package/dist/models/provider-login.js +8 -7
- 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 +19 -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 +4 -0
- package/dist/runtime/bootstrap.js +82 -22
- package/dist/runtime/daemon-lock.js +3 -3
- package/dist/runtime/desk-runtime.d.ts +33 -6
- package/dist/runtime/desk-runtime.js +302 -47
- package/dist/runtime/ingress-commands.js +24 -4
- package/dist/runtime/shutdown.d.ts +3 -1
- package/dist/runtime/shutdown.js +1 -0
- package/dist/runtime/task-close.d.ts +1 -1
- package/dist/runtime/task-close.js +6 -3
- package/dist/runtime/task-control.d.ts +1 -3
- package/dist/runtime/task-control.js +15 -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 +1 -0
- package/dist/runtime/task-lane.js +17 -14
- package/dist/runtime/task-step.d.ts +3 -3
- package/dist/runtime/task-step.js +23 -14
- package/dist/runtime/transports.js +6 -5
- package/dist/security/command-guard.js +23 -1
- package/dist/shared/text-utils.d.ts +0 -1
- package/dist/shared/text-utils.js +0 -1
- package/dist/subagents/commands.js +14 -5
- package/dist/subagents/completion-wake.js +6 -0
- package/dist/subagents/dispatch.js +20 -18
- package/dist/subagents/external/dispatch.js +20 -14
- package/dist/subagents/external/run.js +10 -20
- package/dist/subagents/external/settlement.js +5 -1
- package/dist/subagents/internal/outcome.js +19 -12
- package/dist/subagents/internal/provider-retry.js +1 -3
- package/dist/subagents/internal/run.d.ts +1 -1
- package/dist/subagents/internal/run.js +27 -4
- package/dist/subagents/internal/state.d.ts +1 -3
- package/dist/subagents/internal/state.js +1 -2
- package/dist/subagents/internal/worker.js +17 -9
- package/dist/subagents/result.d.ts +5 -2
- package/dist/subagents/result.js +35 -6
- package/dist/subagents/run-record.d.ts +21 -0
- package/dist/subagents/run-record.js +5 -0
- package/dist/subagents/runs.d.ts +5 -8
- package/dist/subagents/runs.js +24 -35
- package/dist/subagents/task-envelope.js +11 -8
- package/dist/subagents/task-settlement.js +1 -0
- package/dist/subagents/types.d.ts +14 -4
- package/dist/subagents/workspace-lease.d.ts +37 -10
- package/dist/subagents/workspace-lease.js +121 -13
- package/dist/subagents/worktree.d.ts +47 -5
- package/dist/subagents/worktree.js +316 -30
- package/dist/tasks/brief.d.ts +5 -1
- package/dist/tasks/brief.js +19 -5
- package/dist/tasks/commands.d.ts +3 -1
- package/dist/tasks/commands.js +17 -6
- package/dist/tasks/control.d.ts +9 -0
- package/dist/tasks/loop-log.d.ts +10 -0
- package/dist/tasks/loop-log.js +1 -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 +27 -15
- package/dist/tools/contract/presentation.js +4 -1
- 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 +1 -2
- package/dist/tools/event-manage.js +27 -38
- 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 +4 -1
- package/dist/tools/index.js +7 -4
- package/dist/tools/job.js +12 -11
- package/dist/tools/memory-manage.d.ts +1 -0
- package/dist/tools/memory-manage.js +9 -23
- 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 +31 -11
- package/dist/tools/session-search.d.ts +3 -1
- package/dist/tools/session-search.js +24 -8
- package/dist/tools/skill.js +13 -12
- package/dist/tools/subagent-manage.js +10 -3
- package/dist/tools/subagent.d.ts +22 -2
- package/dist/tools/subagent.js +19 -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 +39 -3
- package/dist/tools/task-manage/lifecycle.d.ts +2 -2
- package/dist/tools/task-manage/lifecycle.js +7 -4
- package/dist/tools/task-manage/shared.d.ts +1 -1
- package/dist/tools/task-manage/types.d.ts +1 -0
- package/dist/tools/web-search.d.ts +13 -7
- package/dist/tools/web-search.js +62 -19
- 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 +5 -0
- package/dist/tui/cli.js +97 -31
- package/dist/tui/client.d.ts +5 -0
- package/dist/tui/client.js +63 -21
- 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/web/client.d.ts +3 -0
- package/dist/web/client.js +18 -3
- package/dist/web/config.d.ts +17 -4
- package/dist/web/config.js +42 -4
- package/dist/web/fetch.js +6 -3
- package/dist/web/format.d.ts +2 -1
- package/dist/web/format.js +7 -3
- package/dist/web/search-providers.d.ts +15 -8
- package/dist/web/search-providers.js +208 -139
- package/dist/web/search.d.ts +13 -3
- package/dist/web/search.js +86 -40
- 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 +9 -7
- 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 +8 -9
- package/dist/agent/session/request-tools.d.ts +0 -3
- package/dist/agent/session/request-tools.js +0 -20
- package/dist/memory/chinese-words.d.ts +0 -1
- package/dist/memory/chinese-words.js +0 -273
- 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/agy-main.md +0 -23
- 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/dist/desk/commands.js
CHANGED
|
@@ -12,12 +12,14 @@ 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) {
|
|
15
|
+
export function buildDeskList(desks, bindings, current, label, activity) {
|
|
16
16
|
const summaries = new Map(desks.map((summary) => [summary.name, summary]));
|
|
17
17
|
const names = [...new Set([...summaries.keys(), ...Object.values(bindings).map((binding) => binding.desk)])].sort();
|
|
18
18
|
return names.map((name) => {
|
|
19
19
|
const summary = summaries.get(name);
|
|
20
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);
|
|
21
23
|
return {
|
|
22
24
|
name,
|
|
23
25
|
availability: summary?.availability ?? "missing",
|
|
@@ -26,6 +28,10 @@ export function buildDeskList(desks, bindings, current, label) {
|
|
|
26
28
|
.filter(([, binding]) => binding.desk === name)
|
|
27
29
|
.map(([channelId]) => ({ channelId, label: label(channelId) })),
|
|
28
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 } : {}),
|
|
29
35
|
};
|
|
30
36
|
});
|
|
31
37
|
}
|
|
@@ -63,6 +69,11 @@ export function parseDeskCommand(args) {
|
|
|
63
69
|
return { action: "cwd", reset: true };
|
|
64
70
|
return { action: "cwd", cwd: target };
|
|
65
71
|
}
|
|
72
|
+
if (action === "archive" || action === "unarchive") {
|
|
73
|
+
if (rest.length !== 1)
|
|
74
|
+
throw new Error(`用法:/desk ${action} <名字>`);
|
|
75
|
+
return { action, name: normalizeDeskName(rest[0]) };
|
|
76
|
+
}
|
|
66
77
|
throw new Error(`未知子命令 \`${action}\`。`);
|
|
67
78
|
}
|
|
68
79
|
const NAME_RULE = "工位名只能用 1–32 个小写字母、数字和连字符,且不能以连字符开头或结尾";
|
|
@@ -82,14 +93,25 @@ function renderList(items, channelIndexPath, canBind) {
|
|
|
82
93
|
for (const item of items) {
|
|
83
94
|
const cwdNote = item.cwd ? ` · 目录 \`${item.cwd}\`` : "";
|
|
84
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("、")})` : "";
|
|
85
102
|
if (item.availability !== "available") {
|
|
86
103
|
lines.push(`${head}:不可用(目录缺失或 desk.json 有误),需要部署者在服务器上检查`);
|
|
87
104
|
}
|
|
105
|
+
else if (item.archived) {
|
|
106
|
+
lines.push(`${head}:已归档(用 \`/desk bind ${item.name}\` 或 \`/desk unarchive ${item.name}\` 恢复)`);
|
|
107
|
+
}
|
|
88
108
|
else if (item.channels.length === 0) {
|
|
89
|
-
lines.push(
|
|
109
|
+
lines.push(item.backgroundActive || bgBits.length > 0
|
|
110
|
+
? `${head}:未绑定频道 · 后台活跃${bgSuffix}`
|
|
111
|
+
: `${head}:未绑定频道 · 已休眠`);
|
|
90
112
|
}
|
|
91
113
|
else {
|
|
92
|
-
lines.push(`${head}:${item.channels.map((channel) => channel.label).join("、")}`);
|
|
114
|
+
lines.push(`${head}:${item.channels.map((channel) => channel.label).join("、")}${bgSuffix}`);
|
|
93
115
|
}
|
|
94
116
|
}
|
|
95
117
|
return capReply(lines.join("\n"), {
|
|
@@ -119,6 +141,8 @@ function renderCwd(outcome, isQuery) {
|
|
|
119
141
|
switch (outcome.kind) {
|
|
120
142
|
case "invalid_cwd":
|
|
121
143
|
return `工作目录无效:${outcome.reason}。`;
|
|
144
|
+
case "busy":
|
|
145
|
+
return `工位 \`${outcome.desk}\` 当前${outcome.reason},暂不能切换工作目录。请等当前执行结束或先暂停相关任务后再试。`;
|
|
122
146
|
case "unavailable":
|
|
123
147
|
return `当前频道没有可用的工位,无法查看或修改工作目录。用 \`/desk\` 查看工位状态。`;
|
|
124
148
|
case "ok": {
|
|
@@ -144,25 +168,79 @@ function renderBind(outcome) {
|
|
|
144
168
|
case "same":
|
|
145
169
|
return `本频道已经绑定在工位 \`${outcome.desk}\` 上。`;
|
|
146
170
|
case "bound": {
|
|
147
|
-
const
|
|
171
|
+
const unarchivedNote = outcome.unarchived ? "(已从归档恢复)" : "";
|
|
172
|
+
const lines = [`本频道已绑定到工位 \`${outcome.desk}\`${unarchivedNote}。`];
|
|
148
173
|
if (outcome.previousDesk && outcome.previousDeskDormant) {
|
|
149
|
-
lines.push(`原工位 \`${outcome.previousDesk}\`
|
|
174
|
+
lines.push(`原工位 \`${outcome.previousDesk}\` 已没有绑定的频道与后台工作,已进入休眠;切回或打开 \`pipiclaw tui --desk ${outcome.previousDesk}\` 后自动恢复。`);
|
|
150
175
|
}
|
|
151
|
-
else if (outcome.previousDesk
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
if (outcome.suspendedEvents)
|
|
156
|
-
parts
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
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
|
+
}
|
|
161
188
|
}
|
|
162
189
|
return lines.join("\n");
|
|
163
190
|
}
|
|
164
191
|
}
|
|
165
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
|
+
}
|
|
166
244
|
export async function handleDeskCommand(args, port) {
|
|
167
245
|
let command;
|
|
168
246
|
try {
|
|
@@ -185,6 +263,14 @@ export async function handleDeskCommand(args, port) {
|
|
|
185
263
|
if (!port.cwd)
|
|
186
264
|
return "当前入口不支持直接设置工作目录,请在对话频道或守护进程连接下执行 `/desk cwd`。";
|
|
187
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));
|
|
188
274
|
}
|
|
189
275
|
}
|
|
190
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,12 +1,23 @@
|
|
|
1
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
16
|
export declare function createDeskRecord(workspaceDir: string, name: string, now: Date, cwd?: string): CreateDeskOutcome;
|
|
8
17
|
/** Update or reset (`cwd: null`) a desk's custom `cwd` under `desk-json.lock`. */
|
|
9
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>;
|
|
10
21
|
/** Read-only lookup of a desk's effective working directory (`desk.json` `cwd`, else `deskDir`). */
|
|
11
22
|
export declare function resolveDeskCwdSync(workspaceDir: string, desk: string): string;
|
|
12
23
|
/**
|
package/dist/desk/registry.js
CHANGED
|
@@ -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,7 +128,7 @@ 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
|
}
|
|
103
|
-
function validateCustomCwd(rawCwd) {
|
|
131
|
+
export function validateCustomCwd(rawCwd) {
|
|
104
132
|
const trimmed = rawCwd.trim();
|
|
105
133
|
if (!trimmed || !isAbsolute(trimmed)) {
|
|
106
134
|
return { ok: false, reason: "目录路径必须是绝对路径(例如 `/srv/repo`)" };
|
|
@@ -189,6 +217,22 @@ export async function setDeskCwd(workspaceDir, desk, cwd) {
|
|
|
189
217
|
return { kind: "ok", desk, cwd: effective ?? deskDir, isDefault: effective === undefined };
|
|
190
218
|
}), { timeoutMs: DESK_RECORD_LOCK_TIMEOUT_MS });
|
|
191
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
|
+
}
|
|
192
236
|
/** Read-only lookup of a desk's effective working directory (`desk.json` `cwd`, else `deskDir`). */
|
|
193
237
|
export function resolveDeskCwdSync(workspaceDir, desk) {
|
|
194
238
|
const deskDir = getDeskDir(workspaceDir, desk);
|
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;
|
|
@@ -79,6 +81,10 @@ export type DeskCwdOutcome = {
|
|
|
79
81
|
desk: string;
|
|
80
82
|
cwd: string;
|
|
81
83
|
isDefault: boolean;
|
|
84
|
+
} | {
|
|
85
|
+
kind: "busy";
|
|
86
|
+
desk: string;
|
|
87
|
+
reason: string;
|
|
82
88
|
} | {
|
|
83
89
|
kind: "invalid_cwd";
|
|
84
90
|
cwd: string;
|
|
@@ -87,3 +93,62 @@ export type DeskCwdOutcome = {
|
|
|
87
93
|
kind: "unavailable";
|
|
88
94
|
desk: string;
|
|
89
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/config.js
CHANGED
|
@@ -26,37 +26,37 @@ function isPlaceholderString(value) {
|
|
|
26
26
|
function listChannelConfigIssues(config) {
|
|
27
27
|
const issues = [];
|
|
28
28
|
if (!config.clientId) {
|
|
29
|
-
issues.push("
|
|
29
|
+
issues.push("缺少必填项 `clientId`(如暂不接入钉钉,可将 `dingtalk.enabled` 设为 false)。");
|
|
30
30
|
}
|
|
31
31
|
else if (isPlaceholderString(config.clientId)) {
|
|
32
|
-
issues.push("
|
|
32
|
+
issues.push("请将 `clientId` 的占位值(your-*)替换为真实的钉钉应用 Client ID(如暂不接入钉钉,可将 `dingtalk.enabled` 设为 false)。");
|
|
33
33
|
}
|
|
34
34
|
if (!config.clientSecret) {
|
|
35
|
-
issues.push("
|
|
35
|
+
issues.push("缺少必填项 `clientSecret`。");
|
|
36
36
|
}
|
|
37
37
|
else if (isPlaceholderString(config.clientSecret)) {
|
|
38
|
-
issues.push("
|
|
38
|
+
issues.push("请将 `clientSecret` 的占位值(your-*)替换为真实的钉钉应用 Client Secret。");
|
|
39
39
|
}
|
|
40
40
|
if (config.robotCode && isPlaceholderString(config.robotCode)) {
|
|
41
|
-
issues.push(
|
|
41
|
+
issues.push('请替换 `robotCode` 的占位值,或将其设为空字符串 `""` 以自动复用 `clientId`。');
|
|
42
42
|
}
|
|
43
43
|
if (config.cardTemplateId && isPlaceholderString(config.cardTemplateId)) {
|
|
44
|
-
issues.push(
|
|
44
|
+
issues.push('请替换 `cardTemplateId` 的占位值,或将其设为空字符串 `""` 以暂不启用 AI Card 流式卡片。');
|
|
45
45
|
}
|
|
46
46
|
if (Array.isArray(config.allowFrom) && config.allowFrom.some((value) => isPlaceholderString(value))) {
|
|
47
|
-
issues.push("
|
|
47
|
+
issues.push("请替换 `allowFrom` 中的占位值,或设为空数组 `[]` 以允许应用可见范围内的成员使用。");
|
|
48
48
|
}
|
|
49
49
|
const busyMessageDefault = config.busyMessageDefault;
|
|
50
50
|
if (busyMessageDefault !== undefined && !isBusyMessageDefaultConfig(busyMessageDefault)) {
|
|
51
|
-
issues.push('
|
|
51
|
+
issues.push('`busyMessageDefault` 无效:仅支持 "steer"、"followUp" 或 "followup"。');
|
|
52
52
|
}
|
|
53
53
|
const responseMode = config.responseMode;
|
|
54
54
|
if (responseMode !== undefined && !isResponseModeConfig(responseMode)) {
|
|
55
|
-
issues.push('
|
|
55
|
+
issues.push('`responseMode` 无效:仅支持 "full_progress_then_plain_final"、"rolling_progress_then_plain_final" 或 "final_card_only"。');
|
|
56
56
|
}
|
|
57
57
|
const cardAutoLayout = config.cardAutoLayout;
|
|
58
58
|
if (cardAutoLayout !== undefined && typeof cardAutoLayout !== "boolean") {
|
|
59
|
-
issues.push("
|
|
59
|
+
issues.push("`cardAutoLayout` 无效:必须是布尔值(true 或 false)。");
|
|
60
60
|
}
|
|
61
61
|
return issues;
|
|
62
62
|
}
|
package/dist/dingtalk/inbound.js
CHANGED
|
@@ -4,7 +4,6 @@ import { errorMessage } from "../shared/text-utils.js";
|
|
|
4
4
|
import { isRecord } from "../shared/type-guards.js";
|
|
5
5
|
import { dingtalkDmChannelId, dingtalkGroupChannelId } from "./channel-ids.js";
|
|
6
6
|
import { parseInboundMessage } from "./inbound-media.js";
|
|
7
|
-
const UNSUPPORTED_HINT_MSGTYPES = new Set(["video", "chatRecord", "interactiveCard"]);
|
|
8
7
|
export class InboundMessages {
|
|
9
8
|
constructor(deps) {
|
|
10
9
|
this.deps = deps;
|
|
@@ -76,8 +75,8 @@ export class InboundMessages {
|
|
|
76
75
|
const conversationId = data.conversationId || "";
|
|
77
76
|
const conversationType = data.conversationType || "1";
|
|
78
77
|
const hasMedia = parsed.downloadCodes.length > 0 || (parsed.files?.length ?? 0) > 0;
|
|
79
|
-
const msgtype = typeof data.msgtype === "string" ? data.msgtype : "unknown";
|
|
80
|
-
const isUnsupportedMedia = !parsed.text && !hasMedia &&
|
|
78
|
+
const msgtype = typeof data.msgtype === "string" ? data.msgtype.trim() || "unknown" : "unknown";
|
|
79
|
+
const isUnsupportedMedia = !parsed.text && !hasMedia && msgtype !== "text" && msgtype !== "unknown";
|
|
81
80
|
if (!parsed.text && !hasMedia && !isUnsupportedMedia) {
|
|
82
81
|
log.logWarn("dingtalk.message.empty", "Empty message ignored", { fields: { msgtype } });
|
|
83
82
|
return;
|
package/dist/events/watcher.d.ts
CHANGED
|
@@ -45,7 +45,7 @@ export declare class EventsWatcher {
|
|
|
45
45
|
private handleOneShot;
|
|
46
46
|
private handlePeriodic;
|
|
47
47
|
private execute;
|
|
48
|
-
/** Whether the watcher may still act on an occurrence (desk active, channel bound); records a skip. */
|
|
48
|
+
/** Whether the watcher may still act on an occurrence (desk active; task templates need reachable transport, chat wakes also need channel bound); records a skip. */
|
|
49
49
|
private admits;
|
|
50
50
|
/**
|
|
51
51
|
* Deliver a template event: ask the runtime for a fresh task instance (spec 052, D2). The
|
package/dist/events/watcher.js
CHANGED
|
@@ -504,11 +504,11 @@ export class EventsWatcher {
|
|
|
504
504
|
this.markInvalid(filename, `Event queue was full at ${new Date().toISOString()}; this occurrence was not delivered.`);
|
|
505
505
|
}
|
|
506
506
|
}
|
|
507
|
-
/** Whether the watcher may still act on an occurrence (desk active, channel bound); records a skip. */
|
|
507
|
+
/** Whether the watcher may still act on an occurrence (desk active; task templates need reachable transport, chat wakes also need channel bound); records a skip. */
|
|
508
508
|
admits(filename, event, deleteAfter) {
|
|
509
509
|
if (this.stopped)
|
|
510
510
|
return false; // a load `stop()` could not cancel: the desk went dormant meanwhile
|
|
511
|
-
const bound = this.options.isBound(event.channelId);
|
|
511
|
+
const bound = event.task ? true : this.options.isBound(event.channelId);
|
|
512
512
|
if (bound && this.options.isReachable(event.channelId))
|
|
513
513
|
return true;
|
|
514
514
|
this.appendEventHistory(filename, event, "skipped", "skipped", {
|
package/dist/main.js
CHANGED
|
@@ -39,6 +39,18 @@ function handleError(error) {
|
|
|
39
39
|
console.error(error instanceof StartupRefusal ? error.message : error);
|
|
40
40
|
process.exit(1);
|
|
41
41
|
}
|
|
42
|
+
const MIN_NODE_MAJOR = 22;
|
|
43
|
+
const MIN_NODE_MINOR = 19;
|
|
44
|
+
function ensureSupportedNodeVersion() {
|
|
45
|
+
const [majorRaw = "0", minorRaw = "0"] = process.versions.node.split(".");
|
|
46
|
+
const major = Number.parseInt(majorRaw, 10);
|
|
47
|
+
const minor = Number.parseInt(minorRaw, 10);
|
|
48
|
+
if (major > MIN_NODE_MAJOR || (major === MIN_NODE_MAJOR && minor >= MIN_NODE_MINOR))
|
|
49
|
+
return;
|
|
50
|
+
console.error(`错误:Pipiclaw 需要 Node.js >= ${MIN_NODE_MAJOR}.${MIN_NODE_MINOR}.0(当前版本:v${process.versions.node})。请升级 Node.js 后重试。`);
|
|
51
|
+
process.exit(1);
|
|
52
|
+
}
|
|
53
|
+
ensureSupportedNodeVersion();
|
|
42
54
|
const command = process.argv[2];
|
|
43
55
|
if (command === "tui") {
|
|
44
56
|
// The TUI resolves when the user exits (Ctrl-C / Ctrl-D / /exit) or a one-shot
|
|
@@ -58,7 +70,7 @@ else if (command === "auth") {
|
|
|
58
70
|
runAuth(process.argv).then(() => process.exit(0), handleError);
|
|
59
71
|
}
|
|
60
72
|
else if (command === undefined || command === "run" || command.startsWith("-")) {
|
|
61
|
-
// Default mode: the long-lived
|
|
73
|
+
// Default mode: the long-lived daemon. `run` names it explicitly;
|
|
62
74
|
// a bare `pipiclaw` still runs it, and leading flags (--version/--help) are
|
|
63
75
|
// handled by bootstrap's parseArgs. The daemon does not resolve, so there is
|
|
64
76
|
// no success path to exit on — only surface fatal errors.
|
|
@@ -66,9 +78,9 @@ else if (command === undefined || command === "run" || command.startsWith("-"))
|
|
|
66
78
|
bootstrap(process.argv).catch(handleError);
|
|
67
79
|
}
|
|
68
80
|
else {
|
|
69
|
-
console.error(
|
|
81
|
+
console.error(`未知子命令:${command}`);
|
|
70
82
|
for (const line of formatCliCommandsHelp("pipiclaw"))
|
|
71
83
|
console.error(line);
|
|
72
|
-
console.error("
|
|
84
|
+
console.error("运行 `pipiclaw --help` 查看完整用法。");
|
|
73
85
|
process.exit(1);
|
|
74
86
|
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { AgentMessage } from "@earendil-works/pi-agent-core";
|
|
2
|
+
export declare function extractAnchors(text: string): string[];
|
|
3
|
+
export declare function findUnanchored(anchors: string[], provenance: string, home?: string): string[];
|
|
4
|
+
/** Tool output in the same source window can corroborate an identifier without entering the prompt. */
|
|
5
|
+
export declare function toolResultProvenance(messages: AgentMessage[]): string[];
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { homedir } from "node:os";
|
|
2
|
+
import { contentText } from "@earendil-works/pi-ai";
|
|
3
|
+
import { buildStandardMessages } from "../shared/type-guards.js";
|
|
4
|
+
import { redactSecrets } from "./secret-redaction.js";
|
|
5
|
+
const URL = /https?:\/\/[^\s<>"'`))】\],;:!?。]+/giu;
|
|
6
|
+
const SEGMENT = String.raw `[\p{L}\p{N}_@%+~.-]+`;
|
|
7
|
+
const PATH = new RegExp(String.raw `(?<![\w./~$-])(?:(?:~|\$HOME)?/(?:${SEGMENT}/)+${SEGMENT}|(?:${SEGMENT}/)+${SEGMENT}\.[a-z0-9]{1,8}(?![\p{L}\p{N}_-]|\.[\p{L}\p{N}]))`, "giu");
|
|
8
|
+
const HOST_PORT = /\b(?:localhost|(?:[a-z0-9-]+\.)+[a-z0-9-]+):\d{2,5}\b/gi;
|
|
9
|
+
const LABELLED_PORT = /(?:端口\s*|\bport\s+)(\d{2,5})(?!\d)/gi;
|
|
10
|
+
const VERSION = /\b(?:v\d+(?:\.\d+)+|\d+(?:\.\d+){2,})\b/g;
|
|
11
|
+
const COMMIT = /\b(?=[a-f\d]*[a-f])(?=[a-f\d]*\d)[a-f\d]{7,40}\b/gi;
|
|
12
|
+
const TERMINAL_PUNCTUATION = /[.,;:!?。,;:!?]+$/u;
|
|
13
|
+
const CSS_RATIO = /^\d+(?:px|rem|em|pt)\/\d+\.\d+$/i;
|
|
14
|
+
export function extractAnchors(text) {
|
|
15
|
+
const hits = [];
|
|
16
|
+
let remaining = text.normalize("NFKC");
|
|
17
|
+
// Mask composite identifiers before looking for paths, hashes, versions, or port numbers
|
|
18
|
+
// embedded inside them. Preserve offsets so the first unsupported anchor is deterministic.
|
|
19
|
+
for (const pattern of [URL, PATH, HOST_PORT, LABELLED_PORT, VERSION, COMMIT]) {
|
|
20
|
+
for (const match of remaining.matchAll(pattern)) {
|
|
21
|
+
if (pattern === PATH && CSS_RATIO.test(match[0]))
|
|
22
|
+
continue;
|
|
23
|
+
const value = (match[1] ?? match[0]).replace(TERMINAL_PUNCTUATION, "");
|
|
24
|
+
hits.push({ offset: match.index, value });
|
|
25
|
+
}
|
|
26
|
+
remaining = remaining.replaceAll(pattern, (match) => " ".repeat(match.length));
|
|
27
|
+
}
|
|
28
|
+
return [...new Set(hits.sort((a, b) => a.offset - b.offset).map(({ value }) => value))];
|
|
29
|
+
}
|
|
30
|
+
function anchorForms(anchor, home) {
|
|
31
|
+
if (/^https?:\/\//i.test(anchor)) {
|
|
32
|
+
const stem = anchor.replace(/\/$/, "");
|
|
33
|
+
return [stem, `${stem}/`];
|
|
34
|
+
}
|
|
35
|
+
const homePrefix = `${home.replace(/\/$/, "")}/`;
|
|
36
|
+
const prefix = ["~/", "$HOME/", homePrefix].find((candidate) => anchor.startsWith(candidate));
|
|
37
|
+
if (!prefix)
|
|
38
|
+
return [anchor];
|
|
39
|
+
const rest = anchor.slice(prefix.length);
|
|
40
|
+
return [`~/${rest}`, `$HOME/${rest}`, `${homePrefix}${rest}`];
|
|
41
|
+
}
|
|
42
|
+
export function findUnanchored(anchors, provenance, home = homedir()) {
|
|
43
|
+
const source = provenance.normalize("NFKC");
|
|
44
|
+
return anchors.filter((anchor) => !anchorForms(anchor, home).some((form) => source.includes(form)));
|
|
45
|
+
}
|
|
46
|
+
/** Tool output in the same source window can corroborate an identifier without entering the prompt. */
|
|
47
|
+
export function toolResultProvenance(messages) {
|
|
48
|
+
return buildStandardMessages(messages).flatMap((message) => message.role === "toolResult" ? [redactSecrets(contentText(message.content))] : []);
|
|
49
|
+
}
|