@ai-setting/roy-agent-core 1.7.70 → 1.7.71
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/env/event-source/event-source-handlers.js +6 -6
- package/dist/env/event-source/index.js +7 -7
- package/dist/env/event-source/reset-command.d.ts +41 -0
- package/dist/env/index.js +11 -11
- package/dist/env/prompt/index.js +3 -3
- package/dist/env/prompt/prompts-index.d.ts +339 -1
- package/dist/env/task/delegate/delegate-tool.js +3 -3
- package/dist/env/task/delegate/index.js +3 -3
- package/dist/env/task/index.js +5 -5
- package/dist/env/task/mcp/index.js +2 -2
- package/dist/env/task/plugins/index.js +4 -4
- package/dist/env/task/plugins/lark-card-patch-notifier.d.ts +50 -0
- package/dist/env/task/plugins/lark-card-patch-notifier.js +3 -1
- package/dist/env/task/prompt/index.d.ts +11 -0
- package/dist/env/task/prompt/index.js +16 -0
- package/dist/env/task/prompt/task-discipline.d.ts +32 -0
- package/dist/env/task/tools/index.js +2 -2
- package/dist/env/workflow/plugins/index.js +2 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +30 -18
- package/dist/shared/@ai-setting/{roy-agent-core-0j94tj1z.js → roy-agent-core-101qtkyc.js} +3 -3
- package/dist/shared/@ai-setting/{roy-agent-core-bk8kyzv8.js → roy-agent-core-1gsbqesr.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-8bjj3d1b.js → roy-agent-core-1w9y7mxj.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-tadj19vp.js → roy-agent-core-46rv4d7d.js} +71 -49
- package/dist/shared/@ai-setting/roy-agent-core-4jjwewvw.js +182 -0
- package/dist/shared/@ai-setting/{roy-agent-core-x3xpkx84.js → roy-agent-core-5repth1n.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-h5vmff8w.js → roy-agent-core-7sj9xs9c.js} +7 -33
- package/dist/shared/@ai-setting/{roy-agent-core-27f59kjv.js → roy-agent-core-9geem94g.js} +1 -1
- package/dist/shared/@ai-setting/{roy-agent-core-hx46nhh1.js → roy-agent-core-k13pxrpk.js} +4 -4
- package/dist/shared/@ai-setting/{roy-agent-core-nersksh1.js → roy-agent-core-mwa6apzx.js} +2 -2
- package/dist/shared/@ai-setting/roy-agent-core-qkdegdvc.js +0 -0
- package/dist/shared/@ai-setting/{roy-agent-core-npvejsg8.js → roy-agent-core-zsbh9bfv.js} +83 -3
- package/dist/shared/@ai-setting/{roy-agent-core-vaz9350j.js → roy-agent-core-zv8bswpw.js} +4 -159
- package/dist/test-utils/ipc-test-server.d.ts +10 -0
- package/package.json +6 -1
- package/dist/shared/@ai-setting/roy-agent-core-6m4bw8jy.js +0 -6
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
// src/env/task/tools/completion-copy.ts
|
|
2
|
+
var TASK_COMPLETE_ITEM_BY_ITEM = "按子项逐条验收";
|
|
3
|
+
var TASK_COMPLETION_HINT_ANCHOR = "TASK_COMPLETION_HINT";
|
|
4
|
+
var TASK_COMPLETE_VERIFY_DUTY = "核实义务";
|
|
5
|
+
|
|
6
|
+
// src/env/task/prompt/task-discipline.ts
|
|
7
|
+
var TASK_DISCIPLINE_LIFECYCLE = `### Task Lifecycle (7 steps, 0-6)
|
|
8
|
+
|
|
9
|
+
> Tasks are the **first-class citizen**. Follow this lifecycle for every task:
|
|
10
|
+
|
|
11
|
+
0. CHECK TASK CONTEXT OR SEARCH
|
|
12
|
+
- If \`[当前 Task #N]\` is in the context → use \`task_get #N\` directly, skip searching.
|
|
13
|
+
- Otherwise use \`task_list\` / \`task_search\` to find related tasks.
|
|
14
|
+
- If found → reuse, extend, and update (see the reuse rules in step 1).
|
|
15
|
+
If not found → proceed to step 1.
|
|
16
|
+
- **Orient before creating**: read the existing tree with
|
|
17
|
+
\`task_tree(depth=1)\` (\`depth=2\` for bigger trees) and decide whether the
|
|
18
|
+
work belongs to an existing root (attach via \`parent_task_id\`) or is
|
|
19
|
+
genuinely new. Keep **root tasks ≤ 10**; prefer attaching to an existing
|
|
20
|
+
thematic root over spawning a new root. Never hardcode ids — read them
|
|
21
|
+
from \`task_tree\`.
|
|
22
|
+
|
|
23
|
+
1. CREATE or REUSE
|
|
24
|
+
- No existing task → create a new one with title, description, goals.
|
|
25
|
+
- Existing task → reuse via \`task_get\`, then \`task_update\`:
|
|
26
|
+
* Append new context to description and goals (preserve the old content)
|
|
27
|
+
* Add / extend \`goals_and_expected_deliverables\`
|
|
28
|
+
* Create an operation record documenting the continuation
|
|
29
|
+
* Set priority and due date if any
|
|
30
|
+
* If the original task was completed → reset status to \`active\`
|
|
31
|
+
and reset progress to a reasonable value
|
|
32
|
+
|
|
33
|
+
2. GATHER CONTEXT (never skip)
|
|
34
|
+
- Read description, goals, current_status
|
|
35
|
+
- Check \`parent_task_id\` for sub-tasks
|
|
36
|
+
- Read the operation history: \`task_operation_list\` (~20 recent records)
|
|
37
|
+
- Review recent operations for history and decisions
|
|
38
|
+
- Working without context risks: outdated goals, missed decisions,
|
|
39
|
+
duplicated work, misalignment with the parent task
|
|
40
|
+
|
|
41
|
+
3. EXECUTE
|
|
42
|
+
- Use the available tools, skills and workflows to satisfy the task
|
|
43
|
+
description and goals.
|
|
44
|
+
- Long-running work: for work longer than 5 minutes, record a milestone
|
|
45
|
+
with \`task_operation_create\` as you go, so the user can see progress.
|
|
46
|
+
- Several independent sub-tasks may run in parallel (background \`bash &\`
|
|
47
|
+
or parallel ReAct steps).
|
|
48
|
+
- **边干边记** — milestones are recorded **while working**;
|
|
49
|
+
**禁止事后批量补**(do not defer them to one batch at the end).
|
|
50
|
+
- Note: \`task_create\` / \`task_update\` already create operation records
|
|
51
|
+
automatically — do not create duplicates by hand.
|
|
52
|
+
|
|
53
|
+
4. TRACK
|
|
54
|
+
- Update progress (0-100%) as the work advances
|
|
55
|
+
- Update status: todo → active → completed
|
|
56
|
+
- Record \`current_status\` with human-readable progress
|
|
57
|
+
|
|
58
|
+
5. RECORD — operation records (see Operation Discipline below)
|
|
59
|
+
|
|
60
|
+
6. COMPLETE — \`task_complete\` after item-by-item verification
|
|
61
|
+
(see Complete Discipline below)`;
|
|
62
|
+
var TASK_DISCIPLINE_OPERATION = `### Operation Record — 双维度分工规范
|
|
63
|
+
|
|
64
|
+
**Record milestones as you work** — call \`task_operation_create\` the moment a
|
|
65
|
+
stage is reached, **not after the fact** (not in a batch at the end).
|
|
66
|
+
|
|
67
|
+
**操作记录必须严格区分两个维度,二者配套记录、各司其职**:
|
|
68
|
+
|
|
69
|
+
#### 维度 1:状态/里程碑("达到什么")— 必填维度
|
|
70
|
+
使用 \`task_operation_create\` 的 milestone_* 主字段:
|
|
71
|
+
- **milestone_type**:里程碑类型(create / progress / milestone / problem / solution / decision / review / completed / workflow_extracted)
|
|
72
|
+
- **milestone_title**:里程碑标题(一行)
|
|
73
|
+
- **milestone_description**:达成的状态/结果描述(可长可短)
|
|
74
|
+
|
|
75
|
+
#### 维度 2:过程("如何达到")— 可选但推荐维度
|
|
76
|
+
使用 \`task_operation_create\` 的 \`process_description\` 字段:
|
|
77
|
+
- 字符范围硬约束 100-500 字符 (100–500 characters)
|
|
78
|
+
- 内容:采取的策略 + 工具步骤概要
|
|
79
|
+
- 完整过程通过 sessionId 回查 session
|
|
80
|
+
|
|
81
|
+
#### 双维度配合铁律
|
|
82
|
+
- ❌ **不要把 action 当状态**:旧 \`action_*\` 命名偏动作/行为层,不能表达"此刻达到什么";现在统一改用 \`milestone_*\`。
|
|
83
|
+
- ❌ **不要让 process_description 与 milestone_description 重复**:process 是"如何达到",milestone 是"达到什么状态"。
|
|
84
|
+
- ✅ **配套记录**:每个有意义的 operation 都应同时包含两者;不写 process 时,detail 应通过 sessionId 回查。
|
|
85
|
+
- ⚠️ **兼容窗口期**:旧 \`action_type\` / \`action_title\` / \`action_description\` 仍被 tool 接受(标记 @deprecated),会自动映射到 milestone_* 并返回 deprecation warning。
|
|
86
|
+
|
|
87
|
+
#### 范例(双维度齐全的 operation 记录)
|
|
88
|
+
\`\`\`json
|
|
89
|
+
{
|
|
90
|
+
"task_id": 123,
|
|
91
|
+
"milestone_type": "milestone",
|
|
92
|
+
"milestone_title": "GREEN 通过:milestone_* schema/storage/tool 全链路",
|
|
93
|
+
"milestone_description": "21/21 测试通过,包含 4 个 action_* alias 兼容测试",
|
|
94
|
+
"process_description": "TDD RED 写 4 个失败测试覆盖 storage/tool;迁移 004 rename 列;rowToOperation 同时输出双字段兼容;tool zod preprocess 自动映射 action_*"
|
|
95
|
+
}
|
|
96
|
+
\`\`\``;
|
|
97
|
+
var TASK_DISCIPLINE_GOALS = `### Goals 子项拆分规则
|
|
98
|
+
|
|
99
|
+
\`goals_and_expected_deliverables\` **MUST** be written as
|
|
100
|
+
**numbered sub-items** (编号子项) that can each be verified
|
|
101
|
+
one by one (逐条验收) — for \`type=normal\` tasks:
|
|
102
|
+
|
|
103
|
+
1. 实现 X(含文件路径)
|
|
104
|
+
2. 测试 Y 覆盖 Z 场景(pass/fail 计数)
|
|
105
|
+
3. 文档 W 落盘到 <path>
|
|
106
|
+
|
|
107
|
+
⚠️ For \`type=longterm\` / \`type=cycle\` tasks there is no
|
|
108
|
+
per-item completion acceptance(不走逐条 complete 验收), so the
|
|
109
|
+
MUST above does not apply; for those, it is **strongly recommended**
|
|
110
|
+
(建议) to split goals into staged, individually checkable sub-items
|
|
111
|
+
(阶段性可判子项) instead of one vague sentence.
|
|
112
|
+
|
|
113
|
+
Why: when the task is completed, the completion hook
|
|
114
|
+
(task:after.complete) judges the whole goal against the
|
|
115
|
+
operation-record chain, using each sub-item as fine-grained
|
|
116
|
+
evidence (逐条对照的依据). Vague one-line goals (一句话模糊目标,
|
|
117
|
+
如「做好 X」「完成调研」) give the judge nothing to check
|
|
118
|
+
and make a completion hint much more likely.
|
|
119
|
+
|
|
120
|
+
Reference the four atomic assertion forms (Task #4768
|
|
121
|
+
四原子形态) when writing each sub-item:
|
|
122
|
+
|
|
123
|
+
- 文件断言 (file assertion): file exists / size / content grep
|
|
124
|
+
- 进程断言 (process assertion): command exit code / stdout match
|
|
125
|
+
- 测试断言 (test assertion): pass/fail counts, no NEW fail
|
|
126
|
+
- 状态断言 (state assertion): version number / HTTP 200 / status field`;
|
|
127
|
+
var TASK_DISCIPLINE_COMPLETE = `### Task Complete — 核实义务
|
|
128
|
+
|
|
129
|
+
Before calling \`task_complete\`, you MUST:
|
|
130
|
+
|
|
131
|
+
1. Read the task's \`goal\` (description) and \`delivery\` (goals_and_expected_deliverables) fields.
|
|
132
|
+
- Use \`task_get(task_id=<id>)\` to fetch the full task record.
|
|
133
|
+
2. **Validate whether each goal sub-item was achieved** — accept the goal
|
|
134
|
+
**item-by-item** (${TASK_COMPLETE_ITEM_BY_ITEM}).
|
|
135
|
+
- Goals should be numbered sub-items (编号子项). Check
|
|
136
|
+
each sub-item against the operation-record chain (操作记录链) and the
|
|
137
|
+
deliverable evidence (context.deliverable_storage_path).
|
|
138
|
+
- The completion hook (task:after.complete) judges the whole goal vs.
|
|
139
|
+
deliverables; numbered sub-items give it finer-grained evidence to
|
|
140
|
+
reason with (逐条对照的证据粒度). If it detects that the goal or
|
|
141
|
+
deliverables appear unmet, the task context will carry a
|
|
142
|
+
\`[${TASK_COMPLETION_HINT_ANCHOR}]\`.
|
|
143
|
+
- **If you receive a [${TASK_COMPLETION_HINT_ANCHOR}]**, you MUST verify it
|
|
144
|
+
(${TASK_COMPLETE_VERIFY_DUTY}): re-read the task via \`task_get\`, then do exactly one of:
|
|
145
|
+
(a) 确认未完成 → \`task_update(task_id=<id>, status=todo)\` to **reopen**
|
|
146
|
+
the task and continue the work; or
|
|
147
|
+
(b) 确认已完成 → \`task_operation_create\` (milestone_type=decision,
|
|
148
|
+
milestone_title=<一行结论>) **state why** the sub-items are actually
|
|
149
|
+
met (说明理由).
|
|
150
|
+
Never ignore it (不允许无视).
|
|
151
|
+
- If the goal and delivery mismatch **without** a hint, either:
|
|
152
|
+
(a) extend the task via \`task_update\`, or
|
|
153
|
+
(b) record the discrepancy via \`task_operation_create\`
|
|
154
|
+
(milestone_type=decision) — the reason **must** land in the
|
|
155
|
+
operation record (必须落到操作记录里), not merely a line in
|
|
156
|
+
your final report (不能只在报告里带一句).
|
|
157
|
+
3. **Provide \`deliverable_storage_path\`** parameter with the deliverable's address.
|
|
158
|
+
It may name **multiple paths** (multiple deliverables), space-separated
|
|
159
|
+
(\`/tmp/report.md /tmp/diff.patch\`) — the judge splits on whitespace as
|
|
160
|
+
well as \`,\` \`;\` \`、\` and \` + \`. A local path may also be written in its
|
|
161
|
+
\`file://\` form (\`file:///tmp/report.md\`) — the scheme is stripped and the
|
|
162
|
+
path kept. Declare **every** artefact you produced: a path left out reads
|
|
163
|
+
as "not produced".
|
|
164
|
+
- Feishu doc URL (e.g., https://my.feishu.cn/docx/abc)
|
|
165
|
+
- Local file path (e.g., /tmp/report.md)
|
|
166
|
+
- Git branch or worktree path (e.g., feature/my-feature)
|
|
167
|
+
- GitHub commit URL or PR URL
|
|
168
|
+
- Cloud drive URL (e.g., https://my.feishu.cn/file/abc)
|
|
169
|
+
- Or any other locator that points to where the work product lives
|
|
170
|
+
|
|
171
|
+
The \`deliverable_storage_path\` will be persisted to the task's
|
|
172
|
+
\`context.deliverable_storage_path\` for future reference and traceability.`;
|
|
173
|
+
var TASK_DISCIPLINE_PROMPT = [
|
|
174
|
+
TASK_DISCIPLINE_LIFECYCLE,
|
|
175
|
+
TASK_DISCIPLINE_OPERATION,
|
|
176
|
+
TASK_DISCIPLINE_GOALS,
|
|
177
|
+
TASK_DISCIPLINE_COMPLETE
|
|
178
|
+
].join(`
|
|
179
|
+
|
|
180
|
+
`);
|
|
181
|
+
|
|
182
|
+
export { TASK_COMPLETE_ITEM_BY_ITEM, TASK_COMPLETION_HINT_ANCHOR, TASK_COMPLETE_VERIFY_DUTY, TASK_DISCIPLINE_LIFECYCLE, TASK_DISCIPLINE_OPERATION, TASK_DISCIPLINE_GOALS, TASK_DISCIPLINE_COMPLETE, TASK_DISCIPLINE_PROMPT };
|
|
@@ -5,8 +5,9 @@ import {
|
|
|
5
5
|
import {
|
|
6
6
|
TASK_COMPLETE_ITEM_BY_ITEM,
|
|
7
7
|
TASK_COMPLETE_VERIFY_DUTY,
|
|
8
|
-
TASK_COMPLETION_HINT_ANCHOR
|
|
9
|
-
|
|
8
|
+
TASK_COMPLETION_HINT_ANCHOR,
|
|
9
|
+
TASK_DISCIPLINE_GOALS
|
|
10
|
+
} from "./roy-agent-core-4jjwewvw.js";
|
|
10
11
|
import {
|
|
11
12
|
getEnvContextOrEmpty,
|
|
12
13
|
init_env_context,
|
|
@@ -217,6 +218,9 @@ function inheritChildContext(args) {
|
|
|
217
218
|
|
|
218
219
|
// src/env/task/tools/create-tool.ts
|
|
219
220
|
var logger2 = createLogger("task:tools:create");
|
|
221
|
+
var TASK_DISCIPLINE_GOALS_INDENTED = TASK_DISCIPLINE_GOALS.split(`
|
|
222
|
+
`).map((l) => l.trim() ? " " + l : l).join(`
|
|
223
|
+
`);
|
|
220
224
|
function extractDecisionHint(contextJson) {
|
|
221
225
|
if (!contextJson)
|
|
222
226
|
return;
|
|
@@ -320,37 +324,7 @@ function createTaskTool(taskComponent) {
|
|
|
320
324
|
- Depth ≤ 5 (avoid deep nesting)
|
|
321
325
|
- Same-theme tasks cluster under one parent
|
|
322
326
|
- Long-tail/stranded tasks should be archived or merged
|
|
323
|
-
|
|
324
|
-
## ⚠️ Goals 子项拆分规则 (Task #4791)
|
|
325
|
-
|
|
326
|
-
\`goals_and_expected_deliverables\` **MUST** be written as
|
|
327
|
-
**numbered sub-items** (编号子项) that can each be verified
|
|
328
|
-
one by one (逐条验收) — for \`type=normal\` tasks:
|
|
329
|
-
|
|
330
|
-
1. 实现 X(含文件路径)
|
|
331
|
-
2. 测试 Y 覆盖 Z 场景(pass/fail 计数)
|
|
332
|
-
3. 文档 W 落盘到 <path>
|
|
333
|
-
|
|
334
|
-
⚠️ For \`type=longterm\` / \`type=cycle\` tasks there is no
|
|
335
|
-
per-item completion acceptance(不走逐条 complete 验收), so the
|
|
336
|
-
MUST above does not apply; for those, it is **strongly recommended**
|
|
337
|
-
(建议) to split goals into staged, individually checkable sub-items
|
|
338
|
-
(阶段性可判子项) instead of one vague sentence.
|
|
339
|
-
|
|
340
|
-
Why: when the task is completed, the completion hook
|
|
341
|
-
(task:after.complete) judges the whole goal against the
|
|
342
|
-
operation-record chain, using each sub-item as fine-grained
|
|
343
|
-
evidence (逐条对照的依据). Vague one-line goals (一句话模糊目标,
|
|
344
|
-
如「做好 X」「完成调研」) give the judge nothing to check and
|
|
345
|
-
make a completion hint much more likely.
|
|
346
|
-
|
|
347
|
-
Reference the four atomic assertion forms (Task #4768
|
|
348
|
-
四原子形态) when writing each sub-item:
|
|
349
|
-
|
|
350
|
-
- 文件断言 (file assertion): file exists / size / content grep
|
|
351
|
-
- 进程断言 (process assertion): command exit code / stdout match
|
|
352
|
-
- 测试断言 (test assertion): pass/fail counts, no NEW fail
|
|
353
|
-
- 状态断言 (state assertion): version number / HTTP 200 / status field
|
|
327
|
+
${TASK_DISCIPLINE_GOALS_INDENTED}
|
|
354
328
|
|
|
355
329
|
## ⚠️ Spatial + Temporal Context (Task #2325)
|
|
356
330
|
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getSharedEventStore
|
|
3
3
|
} from "./roy-agent-core-na18zwj0.js";
|
|
4
|
+
import {
|
|
5
|
+
WORKFLOW_EXTRACT_PROMPT
|
|
6
|
+
} from "./roy-agent-core-zv8bswpw.js";
|
|
4
7
|
import {
|
|
5
8
|
createCompatibleDatabase,
|
|
6
9
|
init_sqlite_task_store
|
|
@@ -8,9 +11,6 @@ import {
|
|
|
8
11
|
import {
|
|
9
12
|
TaskHookPoints
|
|
10
13
|
} from "./roy-agent-core-1pg0fepg.js";
|
|
11
|
-
import {
|
|
12
|
-
WORKFLOW_EXTRACT_PROMPT
|
|
13
|
-
} from "./roy-agent-core-vaz9350j.js";
|
|
14
14
|
import {
|
|
15
15
|
assertNoLeakage,
|
|
16
16
|
buildHintText,
|
|
@@ -24,7 +24,7 @@ import {
|
|
|
24
24
|
import {
|
|
25
25
|
LarkCardPatchNotifier,
|
|
26
26
|
humanizeValue
|
|
27
|
-
} from "./roy-agent-core-
|
|
27
|
+
} from "./roy-agent-core-46rv4d7d.js";
|
|
28
28
|
import {
|
|
29
29
|
validateWorkflowDefinition
|
|
30
30
|
} from "./roy-agent-core-yr1mryb8.js";
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
import {
|
|
8
8
|
BackgroundTaskManager,
|
|
9
9
|
createDelegateTool
|
|
10
|
-
} from "./roy-agent-core-
|
|
10
|
+
} from "./roy-agent-core-101qtkyc.js";
|
|
11
11
|
import {
|
|
12
12
|
TaskEntityEventTypes
|
|
13
13
|
} from "./roy-agent-core-8gxth0eh.js";
|
|
@@ -22,7 +22,7 @@ import {
|
|
|
22
22
|
searchTasksTool,
|
|
23
23
|
treeTasksTool,
|
|
24
24
|
updateTaskTool
|
|
25
|
-
} from "./roy-agent-core-
|
|
25
|
+
} from "./roy-agent-core-7sj9xs9c.js";
|
|
26
26
|
import {
|
|
27
27
|
createOperationTool,
|
|
28
28
|
deleteOperationTool,
|
|
File without changes
|
|
@@ -13,17 +13,17 @@ import {
|
|
|
13
13
|
createPerTaskGroupChatPlugin,
|
|
14
14
|
extractPerTaskChatId,
|
|
15
15
|
extractPerTaskChatName
|
|
16
|
-
} from "./roy-agent-core-
|
|
16
|
+
} from "./roy-agent-core-k13pxrpk.js";
|
|
17
17
|
import {
|
|
18
18
|
getSharedEventStore
|
|
19
19
|
} from "./roy-agent-core-na18zwj0.js";
|
|
20
20
|
import {
|
|
21
21
|
createLarkCliWorkflowNotifyHook
|
|
22
|
-
} from "./roy-agent-core-
|
|
22
|
+
} from "./roy-agent-core-1w9y7mxj.js";
|
|
23
23
|
import {
|
|
24
24
|
LarkCardPatchNotifier,
|
|
25
25
|
buildTaskCard
|
|
26
|
-
} from "./roy-agent-core-
|
|
26
|
+
} from "./roy-agent-core-46rv4d7d.js";
|
|
27
27
|
import {
|
|
28
28
|
normalizeLarkAtMentions
|
|
29
29
|
} from "./roy-agent-core-m880qz3y.js";
|
|
@@ -1720,6 +1720,85 @@ var listCommand = {
|
|
|
1720
1720
|
}
|
|
1721
1721
|
};
|
|
1722
1722
|
|
|
1723
|
+
// src/env/event-source/reset-command.ts
|
|
1724
|
+
import { connect } from "net";
|
|
1725
|
+
var DEFAULT_SOCKET_PATH = "/tmp/deamon-for-roy.sock";
|
|
1726
|
+
var RESET_ACK_TIMEOUT_MS = 3000;
|
|
1727
|
+
function resolveSocketPath() {
|
|
1728
|
+
return process.env.ROY_DAEMON_SOCKET || DEFAULT_SOCKET_PATH;
|
|
1729
|
+
}
|
|
1730
|
+
async function requestReset(socketPath, reason) {
|
|
1731
|
+
return new Promise((resolve) => {
|
|
1732
|
+
let sock;
|
|
1733
|
+
try {
|
|
1734
|
+
sock = connect(socketPath);
|
|
1735
|
+
} catch (e) {
|
|
1736
|
+
resolve({ confirmed: false, reason: e.message });
|
|
1737
|
+
return;
|
|
1738
|
+
}
|
|
1739
|
+
let settled = false;
|
|
1740
|
+
const finish = (confirmed, why) => {
|
|
1741
|
+
if (settled)
|
|
1742
|
+
return;
|
|
1743
|
+
settled = true;
|
|
1744
|
+
clearTimeout(timer);
|
|
1745
|
+
sock.destroy();
|
|
1746
|
+
resolve({ confirmed, reason: why });
|
|
1747
|
+
};
|
|
1748
|
+
const timer = setTimeout(() => finish(false, `daemon 未在 ${RESET_ACK_TIMEOUT_MS}ms 内确认`), RESET_ACK_TIMEOUT_MS);
|
|
1749
|
+
sock.once("connect", () => {
|
|
1750
|
+
sock.write(JSON.stringify({ type: "reset", reason }) + `
|
|
1751
|
+
`);
|
|
1752
|
+
});
|
|
1753
|
+
let buf = "";
|
|
1754
|
+
sock.on("data", (d) => {
|
|
1755
|
+
buf += d.toString();
|
|
1756
|
+
const idx = buf.indexOf(`
|
|
1757
|
+
`);
|
|
1758
|
+
if (idx < 0)
|
|
1759
|
+
return;
|
|
1760
|
+
try {
|
|
1761
|
+
const ack = JSON.parse(buf.slice(0, idx));
|
|
1762
|
+
if (ack.type === "ack" && ack.action === "respawning") {
|
|
1763
|
+
finish(true, "daemon 已确认");
|
|
1764
|
+
} else {
|
|
1765
|
+
finish(false, `daemon 回复异常: ${buf.slice(0, idx)}`);
|
|
1766
|
+
}
|
|
1767
|
+
} catch (e) {
|
|
1768
|
+
finish(false, `daemon 回复解析失败: ${e.message}`);
|
|
1769
|
+
}
|
|
1770
|
+
});
|
|
1771
|
+
sock.once("error", (e) => finish(false, `连接 daemon 失败: ${e.message}`));
|
|
1772
|
+
});
|
|
1773
|
+
}
|
|
1774
|
+
function buildResetCard(text) {
|
|
1775
|
+
return renderTextCard("\uD83D\uDD04 重启请求", text);
|
|
1776
|
+
}
|
|
1777
|
+
var resetCommand = {
|
|
1778
|
+
name: "reset",
|
|
1779
|
+
description: "请求 deamon-for-roy 重启本进程(SIGTERM 后用最新构建的 roy-agent-local 重新拉起)",
|
|
1780
|
+
usage: "##command##: reset [reason]",
|
|
1781
|
+
async execute(ctx) {
|
|
1782
|
+
const reason = ctx.args.join(" ") || undefined;
|
|
1783
|
+
const socketPath = resolveSocketPath();
|
|
1784
|
+
const { confirmed, reason: why } = await requestReset(socketPath, reason);
|
|
1785
|
+
if (confirmed) {
|
|
1786
|
+
const text2 = "✅ 已请求重启:daemon 将停止本进程并用最新版本重新拉起,请稍候片刻。";
|
|
1787
|
+
return {
|
|
1788
|
+
ok: true,
|
|
1789
|
+
output: { text: text2, card: buildResetCard(text2), kind: "card" }
|
|
1790
|
+
};
|
|
1791
|
+
}
|
|
1792
|
+
const text = `⚠️ 未能联系 daemon,重启请求未生效(${why})。
|
|
1793
|
+
` + `socket: ${socketPath}
|
|
1794
|
+
` + `请检查 deamon-for-roy 是否在运行;本进程将继续工作,不会中断。`;
|
|
1795
|
+
return {
|
|
1796
|
+
ok: true,
|
|
1797
|
+
output: { text, card: buildResetCard(text), kind: "card" }
|
|
1798
|
+
};
|
|
1799
|
+
}
|
|
1800
|
+
};
|
|
1801
|
+
|
|
1723
1802
|
// src/env/event-source/command-registry.ts
|
|
1724
1803
|
var logger2 = createLogger("command-registry");
|
|
1725
1804
|
var COMMAND_PREFIX = "##command##:";
|
|
@@ -1812,6 +1891,7 @@ function getGlobalCommandRegistry() {
|
|
|
1812
1891
|
const registry = new CommandRegistry;
|
|
1813
1892
|
registry.register(fallbackModelCommand);
|
|
1814
1893
|
registry.register(listCommand);
|
|
1894
|
+
registry.register(resetCommand);
|
|
1815
1895
|
g.__royCommandRegistry = registry;
|
|
1816
1896
|
}
|
|
1817
1897
|
return g.__royCommandRegistry;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
TASK_COMPLETE_ITEM_BY_ITEM,
|
|
3
3
|
TASK_COMPLETE_VERIFY_DUTY,
|
|
4
|
-
TASK_COMPLETION_HINT_ANCHOR
|
|
5
|
-
|
|
4
|
+
TASK_COMPLETION_HINT_ANCHOR,
|
|
5
|
+
TASK_DISCIPLINE_PROMPT
|
|
6
|
+
} from "./roy-agent-core-4jjwewvw.js";
|
|
6
7
|
|
|
7
8
|
// src/env/prompt/prompts-index.ts
|
|
8
9
|
var builtInPrompts = {
|
|
@@ -832,163 +833,7 @@ roy-agent <command> <subcmd> --help
|
|
|
832
833
|
| \`delegate_task\` | 子 agent 委托入口,由 \`default\` 接待员独占 | 直接用 \`bash\` / \`read_file\` / \`edit_file\` 等工具自己完成任务;若是真正的复杂多步任务,建议用户切换到 \`default\` agent |
|
|
833
834
|
| \`stop_task\` | 后台进程管理入口,由 \`default\` 接待员独占 | 你无法启动后台进程,自然不需要 \`stop_task\` |
|
|
834
835
|
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
Follow this lifecycle for every task:
|
|
838
|
-
|
|
839
|
-
\`\`\`text
|
|
840
|
-
┌─────────────────────────────────────────────────────────────────┐
|
|
841
|
-
│ 0. CHECK TASK CONTEXT OR SEARCH │
|
|
842
|
-
│ - First: Check if [当前 Task #N] is in the context │
|
|
843
|
-
│ If yes → use \`task_get #N\` directly, skip to step 1 │
|
|
844
|
-
│ - If no taskId in context: │
|
|
845
|
-
│ Use \`task_list\` to search for existing related tasks │
|
|
846
|
-
│ - If found → reuse, extend, and update (see rules below) │
|
|
847
|
-
│ - If not found → proceed to step 1 │
|
|
848
|
-
└─────────────────────────────────────────────────────────────────┘
|
|
849
|
-
↓
|
|
850
|
-
┌─────────────────────────────────────────────────────────────────┐
|
|
851
|
-
│ 1. CREATE (task_create) OR REUSE (task_get + task_update) │
|
|
852
|
-
│ - No existing task → Create new with title, desc, goals │
|
|
853
|
-
│ - Existing task → Reuse via task_get, then task_update: │
|
|
854
|
-
│ * Append new context to description (preserve old) │
|
|
855
|
-
│ * Add/extend goals_and_expected_deliverables │
|
|
856
|
-
│ * Create operation record documenting the continuation │
|
|
857
|
-
│ - Set priority (low/medium/high) and due date (if any) │
|
|
858
|
-
└─────────────────────────────────────────────────────────────────┘
|
|
859
|
-
↓
|
|
860
|
-
┌─────────────────────────────────────────────────────────────────┐
|
|
861
|
-
│ 2. GATHER CONTEXT (task_get + task_operation_list) │
|
|
862
|
-
│ - Read description, goals, current_status │
|
|
863
|
-
│ - Check parent_task_id for sub-tasks │
|
|
864
|
-
│ - Review recent operations for history and decisions │
|
|
865
|
-
│ │
|
|
866
|
-
│ ⚠️ REQUIRED: Never skip this step. Working without context │
|
|
867
|
-
│ risks: outdated goals, missed decisions, duplicated work │
|
|
868
|
-
└─────────────────────────────────────────────────────────────────┘
|
|
869
|
-
↓
|
|
870
|
-
┌─────────────────────────────────────────────────────────────────┐
|
|
871
|
-
│ 3. EXECUTE │
|
|
872
|
-
│ - 利用各种工具和能力,skill,workflow等来解决任务达到任务描述 │
|
|
873
|
-
│ 和任务目标要求 │
|
|
874
|
-
│ │
|
|
875
|
-
│ Long-running work guidance: │
|
|
876
|
-
│ - 超过 5 分钟的复杂任务:用 \`task_operation_create\` │
|
|
877
|
-
│ 记录里程碑,让用户能看到实时进展 │
|
|
878
|
-
│ - 多个独立子任务可并行:用 \`bash &\` 后台启动或 │
|
|
879
|
-
│ 拆分成多个并行 ReAct 步骤 │
|
|
880
|
-
│ │
|
|
881
|
-
│ ⚠️ Note: 不需要手动调用 \`task_operation_create\` 跟踪 │
|
|
882
|
-
│ task_create / task_update 等操作也会自动创建记录。 │
|
|
883
|
-
└─────────────────────────────────────────────────────────────────┘
|
|
884
|
-
↓
|
|
885
|
-
┌─────────────────────────────────────────────────────────────────┐
|
|
886
|
-
│ 4. TRACK (task_update) │
|
|
887
|
-
│ - Update progress (0-100%) as work advances │
|
|
888
|
-
│ - Update status: todo → active → completed │
|
|
889
|
-
│ - Can also set paused or cancelled status │
|
|
890
|
-
│ - Record current_status with human-readable progress │
|
|
891
|
-
└─────────────────────────────────────────────────────────────────┘
|
|
892
|
-
↓
|
|
893
|
-
┌─────────────────────────────────────────────────────────────────┐
|
|
894
|
-
│ 5. RECORD (task_operation_create) — **双维度分工** │
|
|
895
|
-
│ - **状态/里程碑维度**:用 milestone_type / milestone_title / │
|
|
896
|
-
│ milestone_description 描述"达成的状态/里程碑"。 │
|
|
897
|
-
│ - **过程维度**:用 process_description(100-500 字符) │
|
|
898
|
-
│ 简要记录"如何达到"——采取了什么策略 + 工具步骤概要。 │
|
|
899
|
-
│ - ⚠️ **不要把 action 当状态**,也不要让 process_description 与 │
|
|
900
|
-
│ milestone_description 重复。 │
|
|
901
|
-
│ - 完整过程通过 sessionId 回查 session 历史。 │
|
|
902
|
-
│ - 这些记录形成任务的历史与上下文。 │
|
|
903
|
-
└─────────────────────────────────────────────────────────────────┘
|
|
904
|
-
↓
|
|
905
|
-
┌─────────────────────────────────────────────────────────────────┐
|
|
906
|
-
│ 6. COMPLETE (task_complete) │
|
|
907
|
-
│ - Mark task as completed (progress=100%, status=completed) │
|
|
908
|
-
│ - ${TASK_COMPLETE_ITEM_BY_ITEM}: check each goal sub-item │
|
|
909
|
-
│ against the operation-record chain + deliverable evidence │
|
|
910
|
-
│ - If a [${TASK_COMPLETION_HINT_ANCHOR}] appears in task │
|
|
911
|
-
│ context, you MUST ${TASK_COMPLETE_VERIFY_DUTY}: reopen │
|
|
912
|
-
│ (task_update status=todo) or record why it is met │
|
|
913
|
-
│ (task_operation_create decision). Never ignore it. │
|
|
914
|
-
│ - Create completion operation record │
|
|
915
|
-
└─────────────────────────────────────────────────────────────────┘
|
|
916
|
-
\`\`\`
|
|
917
|
-
|
|
918
|
-
### Task Update Rules
|
|
919
|
-
|
|
920
|
-
When reusing an existing task, you MUST follow these rules:
|
|
921
|
-
|
|
922
|
-
1. **Append, don't replace** — When using \`task_update\`, the \`description\` and \`goals\` fields MUST **preserve existing content** and append new content after it.
|
|
923
|
-
2. **Document the continuation** — Use \`task_operation_create\` to create an operation record explaining why the task is being continued and what new scope has been added.
|
|
924
|
-
3. **Reset the status** — If the original task was completed, change status to \`active\` and reset progress to a reasonable value.
|
|
925
|
-
|
|
926
|
-
### Task Properties
|
|
927
|
-
|
|
928
|
-
| Property | Description |
|
|
929
|
-
|----------|-------------|
|
|
930
|
-
| **title** | Brief task title |
|
|
931
|
-
| **description** | Detailed description of what needs to be done |
|
|
932
|
-
| **goals_and_expected_deliverables** | Clear success criteria and expected outputs |
|
|
933
|
-
| **status** | todo → active → completed (or paused, cancelled) |
|
|
934
|
-
| **progress** | 0-100 percentage of completion |
|
|
935
|
-
| **current_status** | Human-readable status describing current work |
|
|
936
|
-
| **priority** | low, medium, high |
|
|
937
|
-
| **parent_task_id** | Parent task ID (if this is a sub-task) |
|
|
938
|
-
|
|
939
|
-
### Task Operation Record — 双维度分工规范 (Task #2211)
|
|
940
|
-
|
|
941
|
-
**操作记录必须严格区分两个维度,二者配套记录、各司其职**:
|
|
942
|
-
|
|
943
|
-
#### 维度 1:状态/里程碑("达到什么")— 必填维度
|
|
944
|
-
使用 \`task_operation_create\` 的 milestone_* 主字段:
|
|
945
|
-
- **milestone_type**:里程碑类型(create / progress / milestone / problem / solution / decision / review / completed)
|
|
946
|
-
- **milestone_title**:里程碑标题(一行)
|
|
947
|
-
- **milestone_description**:达成的状态/结果描述(可长可短)
|
|
948
|
-
|
|
949
|
-
#### 维度 2:过程("如何达到")— 可选但推荐维度
|
|
950
|
-
使用 \`task_operation_create\` 的 \`process_description\` 字段:
|
|
951
|
-
- 字符范围硬约束 100-500 字符
|
|
952
|
-
- 内容:采取的策略 + 工具步骤概要
|
|
953
|
-
- 完整过程通过 sessionId 回查 session
|
|
954
|
-
|
|
955
|
-
#### 双维度配合铁律
|
|
956
|
-
- ❌ **不要把 action 当状态**:旧 \`action_*\` 命名偏动作/行为层,不能表达"此刻达到什么";现在统一改用 \`milestone_*\`。
|
|
957
|
-
- ❌ **不要让 process_description 与 milestone_description 重复**:process 是"如何达到",milestone 是"达到什么状态"。
|
|
958
|
-
- ✅ **配套记录**:每个有意义的 operation 都应同时包含两者;不写 process 时,detail 应通过 sessionId 回查。
|
|
959
|
-
- ⚠️ **兼容窗口期**:旧 \`action_type\` / \`action_title\` / \`action_description\` 仍被 tool 接受(标记 @deprecated),会自动映射到 milestone_* 并返回 deprecation warning。
|
|
960
|
-
|
|
961
|
-
#### 范例(双维度齐全的 operation 记录)
|
|
962
|
-
\`\`\`json
|
|
963
|
-
{
|
|
964
|
-
"task_id": 123,
|
|
965
|
-
"milestone_type": "milestone",
|
|
966
|
-
"milestone_title": "GREEN 通过:milestone_* schema/storage/tool 全链路",
|
|
967
|
-
"milestone_description": "21/21 测试通过,包含 4 个 action_* alias 兼容测试",
|
|
968
|
-
"process_description": "TDD RED 写 4 个失败测试覆盖 storage/tool;迁移 004 rename 列;rowToOperation 同时输出双字段兼容;tool zod preprocess 自动映射 action_*"
|
|
969
|
-
}
|
|
970
|
-
\`\`\`
|
|
971
|
-
|
|
972
|
-
### Task Context Awareness
|
|
973
|
-
|
|
974
|
-
**Before starting any task-related work, you MUST gather context:**
|
|
975
|
-
|
|
976
|
-
**Step 0: Check for Task ID in Context**
|
|
977
|
-
- If the system provides \`[当前 Task #N]\` in the context messages:
|
|
978
|
-
Use \`task_get #N\` directly — this is your confirmed task. **Skip searching.**
|
|
979
|
-
- If no taskId is provided, use \`task_list\` to search for existing related tasks.
|
|
980
|
-
|
|
981
|
-
**Then gather full context:**
|
|
982
|
-
1. **Read task details**: Use \`task_get\` to read description, goals, status
|
|
983
|
-
2. **Read operation history**: Use \`task_operation_list\` to get the last ~20 operation records
|
|
984
|
-
3. **Read parent context** (if \`parent_task_id\` exists): Understand overall goal
|
|
985
|
-
|
|
986
|
-
**Why context matters**: Without it, you risk:
|
|
987
|
-
- Working on outdated or wrong goals
|
|
988
|
-
- Missing critical decisions made in operations
|
|
989
|
-
- Losing parent task alignment
|
|
990
|
-
- Duplicating or conflicting work
|
|
991
|
-
|
|
836
|
+
${TASK_DISCIPLINE_PROMPT}
|
|
992
837
|
### {{memory}}`,
|
|
993
838
|
coding: `You are an expert coding assistant.
|
|
994
839
|
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface TestIpcServer {
|
|
2
|
+
socketPath: string;
|
|
3
|
+
/** last parsed JSON request received from a client */
|
|
4
|
+
lastRequest: Record<string, unknown> | null;
|
|
5
|
+
start(): Promise<void>;
|
|
6
|
+
stop(): Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
export declare function createIpcServer(opts?: {
|
|
9
|
+
replyDelayMs?: number;
|
|
10
|
+
}): TestIpcServer;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-setting/roy-agent-core",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.71",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Core SDK for roy-agent - Environment, Components, Tools, Sessions, Tasks",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -13,6 +13,11 @@
|
|
|
13
13
|
"require": "./dist/index.js",
|
|
14
14
|
"default": "./dist/index.js"
|
|
15
15
|
},
|
|
16
|
+
"./env/task/prompt": {
|
|
17
|
+
"import": "./dist/env/task/prompt/index.js",
|
|
18
|
+
"types": "./dist/env/task/prompt/index.d.ts",
|
|
19
|
+
"default": "./dist/env/task/prompt/index.js"
|
|
20
|
+
},
|
|
16
21
|
"./env/task/plugins": {
|
|
17
22
|
"import": "./dist/env/task/plugins/index.js",
|
|
18
23
|
"types": "./dist/env/task/plugins/index.d.ts",
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
// src/env/task/tools/completion-copy.ts
|
|
2
|
-
var TASK_COMPLETE_ITEM_BY_ITEM = "按子项逐条验收";
|
|
3
|
-
var TASK_COMPLETION_HINT_ANCHOR = "TASK_COMPLETION_HINT";
|
|
4
|
-
var TASK_COMPLETE_VERIFY_DUTY = "核实义务";
|
|
5
|
-
|
|
6
|
-
export { TASK_COMPLETE_ITEM_BY_ITEM, TASK_COMPLETION_HINT_ANCHOR, TASK_COMPLETE_VERIFY_DUTY };
|