Skip to content

Commit 05e282a

Browse files
author
linyuan.yang
committed
agenda 添加归属
1 parent 3b2fc4b commit 05e282a

5 files changed

Lines changed: 60 additions & 2 deletions

File tree

‎packages/scorpio.ai/src/Agenda/Service/AgendaService.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { T_AgendaToolDescs } from "../../Core";
33
import { ILoggerService, type ILogger } from "../../Logger";
44
import type { ChatMessage } from "../../Saver";
55
import {
6+
AgendaAssignee,
67
AgendaPriority,
78
AgendaSource,
89
AgendaStatus,
@@ -119,10 +120,14 @@ export class AgendaService implements IAgendaService {
119120
const existing = await this.findNearDuplicate(content, dueAt);
120121
if (existing) return { record: existing, created: false as const, triggers: [] };
121122

123+
const assignee = args.assignee ?? AgendaAssignee.User;
122124
const inserted = await this.agendaStore.createItem({
123125
content,
124126
status: AgendaStatus.Pending,
125127
priority: args.priority ?? AgendaPriority.Normal,
128+
assignee,
129+
// 仅 Other 归属保留名字,其余强制置空,避免脏数据。
130+
assigneeName: assignee === AgendaAssignee.Other ? (args.assigneeName?.trim() || null) : null,
126131
dueAt,
127132
source: args.source ?? AgendaSource.Tool,
128133
createdAt: now,

‎packages/scorpio.ai/src/Agenda/Storage/AgendaStore.ts‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ export class AgendaStore implements IAgendaStore {
6161
content TEXT NOT NULL,
6262
status TEXT NOT NULL,
6363
priority TEXT NOT NULL,
64+
assignee TEXT NOT NULL DEFAULT 'user',
65+
assigneeName TEXT,
6466
dueAt INTEGER,
6567
source TEXT NOT NULL,
6668
createdAt INTEGER NOT NULL,
@@ -139,6 +141,14 @@ export class AgendaStore implements IAgendaStore {
139141
this._db.exec(`ALTER TABLE items DROP COLUMN completionMode`);
140142
}
141143

144+
// 迁移:assignee / assigneeName 后加(执行者归属)。旧库补列,历史条目默认归属 user。
145+
if (!itemColNames.has("assignee")) {
146+
this._db.exec(`ALTER TABLE items ADD COLUMN assignee TEXT NOT NULL DEFAULT 'user'`);
147+
}
148+
if (!itemColNames.has("assigneeName")) {
149+
this._db.exec(`ALTER TABLE items ADD COLUMN assigneeName TEXT`);
150+
}
151+
142152
// 迁移:trigger_fire.message 后加;旧库(已建过无 message 的 trigger_fire)补列。
143153
const fireCols = this._db.prepare(`PRAGMA table_info(trigger_fire)`).all() as Array<{ name: string }>;
144154
if (!fireCols.some(c => c.name === "message")) {
@@ -281,10 +291,10 @@ export class AgendaStore implements IAgendaStore {
281291
private insertItem(item: Omit<AgendaItem, "id">): number {
282292
const result = this.db.prepare(`
283293
INSERT INTO items (
284-
content, status, priority,
294+
content, status, priority, assignee, assigneeName,
285295
dueAt, source, createdAt, updatedAt, doneAt
286296
) VALUES (
287-
@content, @status, @priority,
297+
@content, @status, @priority, @assignee, @assigneeName,
288298
@dueAt, @source, @createdAt, @updatedAt, @doneAt
289299
)
290300
`).run({ ...item });

‎packages/scorpio.ai/src/Agenda/Tools/AgendaToolProvider.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { DynamicStructuredTool } from "@langchain/core/tools";
22
import { z } from "zod";
33
import {
4+
AgendaAssignee,
45
AgendaPriority,
56
AgendaStatus,
67
AgendaTimeUnit,
@@ -42,6 +43,9 @@ const ActionSchema = z.enum(AgendaTriggerAction).optional().describe('notify (de
4243

4344
const MessageSchema = z.string().min(1).describe('REQUIRED per-trigger fire-time text — the exact words delivered WHEN this trigger fires, phrased as a present-moment ping ("Time to drink water"), NOT as a request to set a reminder ("remind me to drink water in 2 min" ✗). No fallback to content; if no special wording, restate content. Recorded fires re-enter the conversation, so request-like wording can make the post-turn sync create a duplicate agenda.');
4445

46+
const AssigneeSchema = z.enum(AgendaAssignee).optional().describe('Who owns this todo — decide EXPLICITLY: user (default, the user does it themselves) / ai (you the AI do it, e.g. "you help me summarize/generate") / other (a third party like a colleague, put their name in assigneeName). Orthogonal to trigger.action.');
47+
const AssigneeNameSchema = z.string().optional().describe('Third-party name; only meaningful with assignee=other, ignored otherwise.');
48+
4549
const StartAtSchema = z.string().optional().describe('ISO of FIRST fire; omit for default.');
4650
const CountSchema = z.number().int().positive().optional().describe('Total fire count; omit for unlimited.');
4751

@@ -84,6 +88,8 @@ export class AgendaToolProvider {
8488
schema: z.object({
8589
content: z.string().describe('Self-contained title, match user language. Just the thing itself ("Drink water" / "Submit weekly report") — do NOT bake in relative time or schedule ("remind me to drink water in 2 min" ✗); timing lives in triggers.'),
8690
priority: z.enum(AgendaPriority).optional().describe('Default normal. high = urgent; low = casual.'),
91+
assignee: AssigneeSchema,
92+
assigneeName: AssigneeNameSchema,
8793
triggers: z.array(TriggerSpecSchema).optional().describe('Schedule list; omit / [] = plain todo.'),
8894
dueAt: z.string().optional().describe('ISO deadline. Pure metadata — does NOT auto-create a trigger (agenda_wiki §3).'),
8995
}),
@@ -108,6 +114,7 @@ export class AgendaToolProvider {
108114
schema: z.object({
109115
status: z.enum([AgendaStatus.Pending, AgendaStatus.Done, AgendaStatus.Cancelled, 'all']).optional().describe('Default pending. "all" = no filter.'),
110116
priority: z.enum(AgendaPriority).optional(),
117+
assignee: z.enum(AgendaAssignee).optional().describe('Filter by owner: user = the user\'s own todos, ai = ones assigned to you, other = third-party. Use to answer "how many do I / do you have left".'),
111118
limit: z.number().int().positive().optional().describe(`Default ${DEFAULT_LIST_LIMIT}.`),
112119
}),
113120
func: async (filter: AgendaListFilter) => {
@@ -125,6 +132,8 @@ export class AgendaToolProvider {
125132
id: z.number().describe('Item id.'),
126133
content: z.string().optional(),
127134
priority: z.enum(AgendaPriority).optional(),
135+
assignee: AssigneeSchema,
136+
assigneeName: z.string().nullable().optional().describe('Third-party name (null clears). Auto-cleared when assignee is set to non-other.'),
128137
dueAt: z.string().nullable().optional().describe('ISO or null. Does NOT retime triggers (agenda_wiki §3).'),
129138
}),
130139
func: async ({ id, ...patch }: { id: number } & AgendaUpdatePatch) => {

‎packages/scorpio.ai/src/Agenda/format.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ export function formatAgendaXml(record: AgendaRecord): string {
4949
`id="${item.id}"`,
5050
`status="${item.status}"`,
5151
`priority="${item.priority}"`,
52+
`assignee="${item.assignee}"`,
5253
];
54+
if (item.assigneeName) headParts.push(`assigneeName=${attr(item.assigneeName)}`);
5355
if (item.dueAt) headParts.push(`dueAt="${TimeUtils.formatIsoMinute(item.dueAt)}"`);
5456
headParts.push(`content=${attr(item.content)}`);
5557

‎packages/scorpio.ai/src/Agenda/types.ts‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,20 @@ export enum AgendaSource {
3737
Rule = 'rule',
3838
}
3939

40+
/**
41+
* 执行者/归属。表达一条 agenda「算在谁头上」——item 主体级语义,与 per-trigger 的
42+
* action(触发时怎么投递)正交:一条「每天提醒张三交周报」可以 action=Notify 而 assignee=Other。
43+
* 由 LLM 在 create/update 时显式指定,不根据 trigger.action 自动推断。
44+
*/
45+
export enum AgendaAssignee {
46+
/** 用户自己完成。DB 兜底默认。 */
47+
User = 'user',
48+
/** 交给 AI 完成(LLM 说"你帮我总结/生成"时指定)。 */
49+
AI = 'ai',
50+
/** 第三方/外部完成,具体是谁见 assigneeName。 */
51+
Other = 'other',
52+
}
53+
4054
/**
4155
* 触发器类型。表达 trigger.expr 字段的语义。
4256
*/
@@ -168,6 +182,10 @@ export interface AgendaCreateArgs {
168182
content: string;
169183
/** 优先级。默认 Normal。 */
170184
priority?: AgendaPriority;
185+
/** 执行者/归属。缺省 User。LLM 按语义显式指定(用户自己=user、让 AI 做=ai、交给他人=other)。 */
186+
assignee?: AgendaAssignee;
187+
/** 第三方名字。仅 assignee=Other 时写入,其余忽略。 */
188+
assigneeName?: string;
171189
/**
172190
* 调度规格列表。每条 spec 自带 action / message。
173191
* - 单个时间点:传 1 元素数组,例 [{ kind: 'absolute', at: '...', action: 'invoke' }]
@@ -203,6 +221,10 @@ export interface AgendaUpdatePatch {
203221
/** 改内容。LLM 说"把 #3 改成 '交月报'" → content = "交月报"。 */
204222
content?: string;
205223
priority?: AgendaPriority;
224+
/** 改执行者/归属。 */
225+
assignee?: AgendaAssignee;
226+
/** 改第三方名字(null 清空)。改成非 Other 归属时由 service 自动清空。 */
227+
assigneeName?: string | null;
206228
/**
207229
* 显式改 dueAt(ISO 字符串或 null 清空)。
208230
* 纯主体字段,不联动现有 trigger 的节奏。
@@ -236,6 +258,8 @@ export interface AgendaListFilter {
236258
status?: AgendaStatus | 'all';
237259
/** 仅返回某优先级。 */
238260
priority?: AgendaPriority;
261+
/** 仅返回某执行者/归属(如 user = 我的待办、ai = 交给你的)。 */
262+
assignee?: AgendaAssignee;
239263
/** 上限条数。缺省 50,下限 1。 */
240264
limit?: number;
241265
}
@@ -265,6 +289,14 @@ export interface AgendaItem {
265289
content: string;
266290
status: AgendaStatus;
267291
priority: AgendaPriority;
292+
/**
293+
* 执行者/归属。默认 User。用于「我/你还有多少待办」的区分统计与过滤。
294+
*/
295+
assignee: AgendaAssignee;
296+
/**
297+
* 第三方执行者名字。仅 assignee === Other 时有意义;其余情形恒为 null。
298+
*/
299+
assigneeName: string | null;
268300
/**
269301
* 截止时间戳(毫秒)。写入规则(优先级从高到低):
270302
* - args.dueAt 显式传 → 用它

0 commit comments

Comments
 (0)