dsh-tree-task-flow 0.3.4 → 0.3.5

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/lib/tools.js CHANGED
@@ -19,8 +19,10 @@
19
19
 
20
20
  import {
21
21
  addChildren,
22
+ addGoal,
22
23
  complete,
23
24
  createPlan,
25
+ doneReply,
24
26
  dropNode,
25
27
  renderContinue,
26
28
  renderTree,
@@ -76,8 +78,10 @@ export function registerTools(ctx, { store, cfg }) {
76
78
  ctx.tools.register({
77
79
  name: "tree_task_create",
78
80
  description:
79
- "建立一个新计划:一个目标 + 若干任务。这会替换掉现有计划,所以只在开始一个新目标时调用。" +
80
- "建完记得用 tree_task_plan 给目标下的第一个任务拆子任务。",
81
+ "新增一个目标:这个目标 + 它下面的若干任务。目标是要交付的东西,一个会话可以有多个目标," +
82
+ "按调用顺序排在计划里——已经建过的目标和它们的历史都留着,不会被这次调用替换掉。" +
83
+ "这里的任务是交付节点——一件能独立验收的交付物,不是步骤本身。" +
84
+ "建完记得用 tree_task_plan 给这个目标下的第一个任务拆子任务。",
81
85
  parameters: {
82
86
  type: "object",
83
87
  additionalProperties: false,
@@ -86,7 +90,7 @@ export function registerTools(ctx, { store, cfg }) {
86
90
  detail: { type: "string", description: "目标的补充说明" },
87
91
  tasks: {
88
92
  type: "array",
89
- description: "目标下的任务列表,按建议的执行顺序排列",
93
+ description: "目标下的任务列表(交付节点),按建议的执行顺序排列",
90
94
  items: {
91
95
  type: "object",
92
96
  additionalProperties: false,
@@ -102,15 +106,25 @@ export function registerTools(ctx, { store, cfg }) {
102
106
  },
103
107
  output: OUTPUT,
104
108
  async execute(args, exec) {
109
+ const sessionId = sessionOf(exec);
110
+ const existing = store.readPlan(sessionId);
105
111
  let plan;
112
+ let goal;
106
113
  try {
107
- plan = createPlan(args);
114
+ if (existing === null) {
115
+ plan = createPlan(args);
116
+ [goal] = plan.goals;
117
+ } else {
118
+ plan = existing;
119
+ goal = addGoal(plan, args);
120
+ }
108
121
  } catch (error) {
109
- return ok(`建立计划失败:${String(error?.message ?? error)}`);
122
+ return ok(`建立目标失败:${String(error?.message ?? error)}`);
110
123
  }
111
- store.writePlan(sessionOf(exec), plan);
124
+ store.writePlan(sessionId, plan);
112
125
  return ok(
113
- `计划已建立。\n\n${renderTree(plan)}\n\n下一步:调用 tree_task_plan 给目标下的第一个任务拆子任务。`,
126
+ `${existing === null ? "计划已建立。" : `已新增目标「${goal.title}」。`}\n\n${renderTree(plan)}\n\n` +
127
+ "下一步:调用 tree_task_plan 给这个目标下的第一个任务拆子任务。",
114
128
  );
115
129
  },
116
130
  });
@@ -118,8 +132,11 @@ export function registerTools(ctx, { store, cfg }) {
118
132
  ctx.tools.register({
119
133
  name: "tree_task_plan",
120
134
  description:
121
- "给一个节点追加子节点:给目标追加任务,给任务追加子任务。子任务是最低一级,不能再往下拆。" +
122
- "子任务全部结束后父节点不会自动完成,而是转入检查点——那时再决定继续拆还是提交结果。",
135
+ "给一个节点追加子节点:给目标追加任务,给任务追加子任务。" +
136
+ "给任务追加的是步骤(一两次工具调用能做完的事),别把任务拆到只剩一两个步骤。" +
137
+ "子任务是最低一级,不能再往下拆。" +
138
+ "子任务全部结束后父节点不会自动完成:插件会接着告诉你这一层的结果够不够," +
139
+ "够了就用 tree_task_done 提交,不够再补步骤。",
123
140
  parameters: {
124
141
  type: "object",
125
142
  additionalProperties: false,
@@ -127,7 +144,7 @@ export function registerTools(ctx, { store, cfg }) {
127
144
  parentId: { type: "string", description: "父节点 id(目标或任务),例如 t-abc123" },
128
145
  children: {
129
146
  type: "array",
130
- description: "要追加的子节点,按执行顺序;父节点是目标时是任务,是任务时是子任务",
147
+ description: "要追加的子节点,按执行顺序;父节点是目标时是任务(交付节点),是任务时是子任务(步骤)",
131
148
  items: {
132
149
  type: "object",
133
150
  additionalProperties: false,
@@ -163,9 +180,12 @@ export function registerTools(ctx, { store, cfg }) {
163
180
  name: "tree_task_done",
164
181
  description:
165
182
  "完成一个节点并提交它的结果(目标 / 任务 / 子任务都给它的 id)。**必须写 result**:" +
166
- "插件会把这个节点从开始到现在的执行过程从上下文里折叠掉,换成一条只携带这段结果的汇总消息," +
167
- "所以 result 要写清它究竟产出了什么,写成能独立看懂的样子。" +
168
- "子任务全部结束后父节点不会自动完成,而是转入检查点;那时再决定继续拆子任务还是提交父节点的结果。",
183
+ "插件会把这个节点从开始到现在的执行过程从上下文里折叠掉,换成一条只携带这段结果的汇总消息。" +
184
+ "任务的 result 写交付物与验收方式(文件在哪、怎么跑、验出什么、已知限制);" +
185
+ "子任务的 result 一句话说清这步做了什么就够。" +
186
+ "子任务全部结束后父节点不会自动完成:插件会在返回里告诉你这一层的结果够不够," +
187
+ "够就用它自己的 id 再调一次。" +
188
+ "返回内容就是下一步该干什么;这次调用与它的返回都留在上下文里,被收起的只是它前面的执行过程。",
169
189
  parameters: {
170
190
  type: "object",
171
191
  additionalProperties: false,
@@ -173,7 +193,9 @@ export function registerTools(ctx, { store, cfg }) {
173
193
  id: { type: "string", description: "要完成的节点 id" },
174
194
  result: {
175
195
  type: "string",
176
- description: "这个节点产出了什么。它整段执行过程会被这条结果顶替,所以要能独立看懂。",
196
+ description:
197
+ "这个节点产出了什么。它整段执行过程会被这条结果顶替,所以要能独立看懂:" +
198
+ "任务写交付物与验收方式,子任务写清这步做了什么。",
177
199
  },
178
200
  },
179
201
  required: ["id", "result"],
@@ -185,9 +207,9 @@ export function registerTools(ctx, { store, cfg }) {
185
207
  const result = complete(plan, args?.id, args?.result);
186
208
  if (!result.ok) return ok(`没有完成:${result.reason}`);
187
209
  store.writePlan(sessionOf(exec), plan);
188
- return ok(
189
- [...result.events, "", renderTree(plan), "", renderContinue(plan)].join("\n"),
190
- );
210
+ // 返回的就是"下一步该干什么":这条结果连同这次调用都留在表层上,
211
+ // 折叠只收走它前面的执行过程。不重复节点状态,也不回整棵树。
212
+ return ok(doneReply(plan));
191
213
  },
192
214
  });
193
215
 
@@ -218,7 +240,8 @@ export function registerTools(ctx, { store, cfg }) {
218
240
  ctx.tools.register({
219
241
  name: "tree_task_drop",
220
242
  description:
221
- "丢弃一个节点。丢弃任务会连同它的子任务一起丢弃。改需求用这个,不要重建整棵树——" +
243
+ "丢弃一个节点:目标、任务、子任务都能丢。丢弃目标会连同它下面的任务与子任务一起走," +
244
+ "丢弃任务会带上它的子任务。改需求用这个,不要重建整棵树——" +
222
245
  "已丢弃的节点会留在树里可查。",
223
246
  parameters: {
224
247
  type: "object",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-tree-task-flow",
3
- "version": "0.3.4",
3
+ "version": "0.3.5",
4
4
  "description": "树形任务流:把多步任务组织成目标→任务→子任务三级树,节点完成时由 AI 提交结果,插件随即把该节点的执行过程从上下文里折叠掉,只留下结果。",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",