@eum-agent/session-todo 1.0.1 → 1.2.0
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/index.js +125 -126
- package/package.json +4 -4
- package/ui/ui.js +4376 -176
package/dist/index.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
|
+
import { dirname } from "node:path";
|
|
2
3
|
import { fileURLToPath } from "node:url";
|
|
3
4
|
import { z } from "zod";
|
|
4
|
-
//#region src/tool-names.ts
|
|
5
|
-
/** Canonical names shared by tool registration and browser presentation. */
|
|
6
|
-
const TOOL_NAMES = ["todo_write"];
|
|
7
|
-
//#endregion
|
|
8
5
|
//#region src/guidance.ts
|
|
9
6
|
const GUIDANCE = {
|
|
10
7
|
title: "Task list",
|
|
@@ -15,47 +12,17 @@ const GUIDANCE = {
|
|
|
15
12
|
};
|
|
16
13
|
//#endregion
|
|
17
14
|
//#region src/todo/render.ts
|
|
18
|
-
/** The label the paragraph opens with. English, like every other injected
|
|
19
|
-
* line; the item text is whatever language the model wrote. */
|
|
20
15
|
const HEADING = "Current todo list:";
|
|
21
|
-
/** One character per status, inside a GFM checkbox. `>` for in-progress is
|
|
22
|
-
* the one that is not standard GFM, and it is the one that matters: it is
|
|
23
|
-
* what makes the list answer "where am I" rather than "how many are left". */
|
|
24
16
|
const MARKS = {
|
|
25
17
|
completed: "x",
|
|
26
18
|
"in-progress": ">",
|
|
27
19
|
pending: " "
|
|
28
20
|
};
|
|
29
|
-
/**
|
|
30
|
-
* The paragraph, or nothing at all.
|
|
31
|
-
*
|
|
32
|
-
* An empty list contributes **zero characters** — not a heading with nothing
|
|
33
|
-
* under it and not a sentence saying the list is empty. A session that never
|
|
34
|
-
* wrote one is then byte-identical to a request assembled with this member
|
|
35
|
-
* absent.
|
|
36
|
-
*
|
|
37
|
-
* It states rather than instructs: "the list is this" and never "do this".
|
|
38
|
-
* The same text reaches the model every step, and written as an instruction
|
|
39
|
-
* it would be a nag repeated once per step, competing with the `system` slot
|
|
40
|
-
* for the job of saying what to do.
|
|
41
|
-
*/
|
|
42
21
|
function renderTodoList(items) {
|
|
43
22
|
if (items.length === 0) return void 0;
|
|
44
23
|
const lines = items.map((item) => `- [${MARKS[item.status]}] ${item.content}`);
|
|
45
24
|
return [HEADING, ...lines].join("\n");
|
|
46
25
|
}
|
|
47
|
-
/**
|
|
48
|
-
* The one line the tool answers with: how many were recorded and how they
|
|
49
|
-
* break down, and **not one item of text**.
|
|
50
|
-
*
|
|
51
|
-
* The transcript is history, and a copy of a "right now" fact taken at
|
|
52
|
-
* writing time is a record that contradicts the one at the end of the next
|
|
53
|
-
* request — with nothing to tell the model which is current. So the only
|
|
54
|
-
* authoritative copy stays in `volatile`.
|
|
55
|
-
*
|
|
56
|
-
* Counts are stated in a fixed order and a zero is left out: "1 in-progress,
|
|
57
|
-
* 3 pending" says more than the same line with ", 0 completed" on the end.
|
|
58
|
-
*/
|
|
59
26
|
function describeTodoList(items) {
|
|
60
27
|
if (items.length === 0) return "cleared the todo list";
|
|
61
28
|
const counted = [
|
|
@@ -70,8 +37,6 @@ function describeTodoList(items) {
|
|
|
70
37
|
}
|
|
71
38
|
//#endregion
|
|
72
39
|
//#region src/todo/contribute.ts
|
|
73
|
-
/** Sorted within the slot by `id`, so `time` comes before `todos` — a
|
|
74
|
-
* lexicographic result rather than a rule written somewhere else. */
|
|
75
40
|
const CONTRIBUTOR_ID = "todos";
|
|
76
41
|
function todosContributor(store) {
|
|
77
42
|
return {
|
|
@@ -83,41 +48,21 @@ function todosContributor(store) {
|
|
|
83
48
|
}
|
|
84
49
|
};
|
|
85
50
|
}
|
|
86
|
-
/**
|
|
87
|
-
* Three values, not two and not four.
|
|
88
|
-
*
|
|
89
|
-
* `in-progress` is the reason this list exists: re-injected every step, it
|
|
90
|
-
* has to answer "where am I", and done/not-done makes a ten-item list read
|
|
91
|
-
* as "six left" rather than "I am on the fifth". There is no `cancelled`
|
|
92
|
-
* (whole-list replacement expresses that by not writing the line) and no
|
|
93
|
-
* `blocked` (it would need a reference to what blocks it, which is item
|
|
94
|
-
* dependencies — out of scope).
|
|
95
|
-
*/
|
|
96
51
|
const TodoStatus = z.enum([
|
|
97
52
|
"pending",
|
|
98
53
|
"in-progress",
|
|
99
54
|
"completed"
|
|
100
55
|
]);
|
|
101
|
-
/** The wire and storage shape: what `listTodos` answers with, what the frame
|
|
102
|
-
* carries, and what a row's JSON holds. */
|
|
103
56
|
const TodoItem = z.strictObject({
|
|
104
57
|
content: z.string(),
|
|
105
58
|
status: TodoStatus
|
|
106
59
|
});
|
|
107
|
-
/** The same shape with the sentences the model reads. It is declared apart
|
|
108
|
-
* from `TodoItem` because a `describe` is for the model and a wire shape is
|
|
109
|
-
* for a client — they happen to agree on the fields and not on what has to
|
|
110
|
-
* be said about them. */
|
|
111
60
|
const TodoItemInput = z.strictObject({
|
|
112
61
|
content: z.string().min(1).refine((text) => [...text].length <= 200, { message: `at most 200 characters` }).meta({ maxLength: 200 }).describe(`One task, in a few words. Not a paragraph. At most 200 Unicode code points.`),
|
|
113
62
|
status: TodoStatus.describe("pending: not started. in-progress: being worked on right now. completed: done.")
|
|
114
63
|
});
|
|
115
64
|
//#endregion
|
|
116
65
|
//#region src/todo/store.ts
|
|
117
|
-
/** The local half of the table name. `tableName` turns it into
|
|
118
|
-
* `plugin__eum_agent_session_todo__todos`; the prefix is the package's and cannot
|
|
119
|
-
* be chosen here, which is what keeps the core's own tables out of reach of
|
|
120
|
-
* this file's DDL. */
|
|
121
66
|
const LOCAL_TABLE = "todos";
|
|
122
67
|
function createTableSql(table) {
|
|
123
68
|
return `CREATE TABLE IF NOT EXISTS ${table} (
|
|
@@ -134,17 +79,6 @@ function upsertSql(table) {
|
|
|
134
79
|
return `INSERT INTO ${table} (session_id, items, updated_at) VALUES (?, ?, ?)
|
|
135
80
|
ON CONFLICT (session_id) DO UPDATE SET items = excluded.items, updated_at = excluded.updated_at`;
|
|
136
81
|
}
|
|
137
|
-
/**
|
|
138
|
-
* Whatever that column holds, read as a list — or as an empty one.
|
|
139
|
-
*
|
|
140
|
-
* Storage does no schema checking of its own: validation happened before the
|
|
141
|
-
* write, in the tool's zod. So text that was hand-edited, or written by
|
|
142
|
-
* another version, degrades here rather than throwing: **a panel that will
|
|
143
|
-
* not open is worse than a list that reads as empty**, and this list is
|
|
144
|
-
* derived state rather than a source of truth. The degradation leaves a line
|
|
145
|
-
* in the log, because an emptied list and a genuinely empty one look
|
|
146
|
-
* identical everywhere else.
|
|
147
|
-
*/
|
|
148
82
|
function itemsFrom(raw) {
|
|
149
83
|
if (typeof raw !== "string") return void 0;
|
|
150
84
|
let parsed;
|
|
@@ -179,69 +113,151 @@ function openTodoStore(ctx) {
|
|
|
179
113
|
}
|
|
180
114
|
};
|
|
181
115
|
}
|
|
116
|
+
function todoRetention(ctx) {
|
|
117
|
+
const { deleteWhere, prepareDeletion } = ctx.retention;
|
|
118
|
+
const storage = ctx.storage.open();
|
|
119
|
+
const table = storage.tableName(LOCAL_TABLE);
|
|
120
|
+
storage.db.exec(createTableSql(table));
|
|
121
|
+
return { purgeSessions: (sessionIds, cursor, budget) => prepareDeletion([deleteWhere(storage.db, table, "session_id IN (SELECT value FROM json_each(?))", JSON.stringify(sessionIds))], cursor, budget) };
|
|
122
|
+
}
|
|
182
123
|
//#endregion
|
|
183
124
|
//#region src/todo/write.ts
|
|
184
125
|
const WriteTodosInput = z.strictObject({ todos: z.array(TodoItemInput).max(20).describe("The whole list, in reading order. It replaces whatever was recorded before.") });
|
|
185
|
-
|
|
186
|
-
* Everything the model is told about this tool.
|
|
187
|
-
*
|
|
188
|
-
* The description is the only guidance there is — this product has no
|
|
189
|
-
* per-session tool policy and no way to require a call — so what would
|
|
190
|
-
* otherwise be documentation is written here instead.
|
|
191
|
-
*/
|
|
192
|
-
const DESCRIPTION = `Record the plan for a task that spans several steps, and keep it current. Write the list down before you start, and rewrite it the moment a step is done. It is a whole-list replacement: hand over the complete list every time, and any item you leave out is gone — there is no way to edit one item. Keep at most one item in-progress at a time. The list you record is shown to you again at the end of every later request, so do not copy it into your reply. At most 20 items, each at most 200 characters.`;
|
|
193
|
-
/** Told to the model when the store itself refuses. Fixed wording rather
|
|
194
|
-
* than the raw exception: `tool-call.ts` hands `error.message` straight to
|
|
195
|
-
* the model, and SQLite's text can carry the database file's path. */
|
|
126
|
+
const DESCRIPTION = `Record the plan for a task that spans several steps, and keep it current. Write the list down before you start, and rewrite it the moment a step is done. It is a whole-list replacement: hand over the complete list every time, and any item you leave out is gone \u2014 there is no way to edit one item. Keep at most one item in-progress at a time. The list you record is shown to you again at the end of every later request, so do not copy it into your reply. At most 20 items, each at most 200 characters.`;
|
|
196
127
|
const WRITE_FAILED = "todo store write failed";
|
|
197
|
-
|
|
128
|
+
const TodoWriteDataSchema = z.union([z.strictObject({
|
|
129
|
+
committed: z.literal(true),
|
|
130
|
+
sessionId: z.string(),
|
|
131
|
+
items: z.array(TodoItem).max(20),
|
|
132
|
+
counts: z.strictObject({
|
|
133
|
+
total: z.number().int().nonnegative(),
|
|
134
|
+
inProgress: z.number().int().nonnegative(),
|
|
135
|
+
pending: z.number().int().nonnegative(),
|
|
136
|
+
completed: z.number().int().nonnegative()
|
|
137
|
+
})
|
|
138
|
+
}), z.strictObject({
|
|
139
|
+
committed: z.literal(false),
|
|
140
|
+
sessionId: z.string(),
|
|
141
|
+
error: z.strictObject({
|
|
142
|
+
code: z.literal("todo_write_failed"),
|
|
143
|
+
message: z.string().max(1024)
|
|
144
|
+
})
|
|
145
|
+
})]);
|
|
146
|
+
function writeTodosTool(store, announce, log) {
|
|
198
147
|
return {
|
|
199
148
|
name: "todo_write",
|
|
200
149
|
preload: true,
|
|
201
150
|
description: DESCRIPTION,
|
|
202
151
|
inputSchema: WriteTodosInput,
|
|
203
|
-
outputSchema:
|
|
152
|
+
outputSchema: TodoWriteDataSchema,
|
|
153
|
+
formatModel: async (data) => ({
|
|
154
|
+
formatVersion: 1,
|
|
155
|
+
rendererVersion: 1,
|
|
156
|
+
nodes: [{
|
|
157
|
+
id: "receipt",
|
|
158
|
+
kind: "literal",
|
|
159
|
+
text: data.committed ? describeTodoList(data.items) : data.error.message
|
|
160
|
+
}]
|
|
161
|
+
}),
|
|
204
162
|
deliveryKind: "receipt",
|
|
205
163
|
async execute(input, ctx) {
|
|
206
164
|
let stored;
|
|
207
165
|
try {
|
|
208
166
|
stored = store.replace(ctx.sessionId, input.todos);
|
|
209
167
|
} catch (error) {
|
|
168
|
+
log.emit({
|
|
169
|
+
level: "error",
|
|
170
|
+
event: "plugin.event",
|
|
171
|
+
fields: { localCode: "TODO_WRITE_FAILED" },
|
|
172
|
+
error
|
|
173
|
+
});
|
|
210
174
|
return {
|
|
211
|
-
|
|
212
|
-
|
|
175
|
+
data: {
|
|
176
|
+
committed: false,
|
|
177
|
+
sessionId: ctx.sessionId,
|
|
178
|
+
error: {
|
|
179
|
+
code: "todo_write_failed",
|
|
180
|
+
message: WRITE_FAILED
|
|
181
|
+
}
|
|
182
|
+
},
|
|
183
|
+
execution: { state: "not-started" },
|
|
184
|
+
isError: true,
|
|
185
|
+
error: {
|
|
186
|
+
code: "todo_write_failed",
|
|
187
|
+
retryable: false
|
|
188
|
+
},
|
|
189
|
+
presentation: {
|
|
190
|
+
type: "todo-list",
|
|
191
|
+
schemaVersion: 1,
|
|
192
|
+
summary: WRITE_FAILED,
|
|
193
|
+
state: "error",
|
|
194
|
+
fields: {
|
|
195
|
+
sessionId: ctx.sessionId,
|
|
196
|
+
committed: false
|
|
197
|
+
},
|
|
198
|
+
actions: [],
|
|
199
|
+
bodyRefs: []
|
|
200
|
+
}
|
|
213
201
|
};
|
|
214
202
|
}
|
|
215
|
-
|
|
216
|
-
|
|
203
|
+
const counts = {
|
|
204
|
+
total: stored.length,
|
|
205
|
+
inProgress: stored.filter((item) => item.status === "in-progress").length,
|
|
206
|
+
pending: stored.filter((item) => item.status === "pending").length,
|
|
207
|
+
completed: stored.filter((item) => item.status === "completed").length
|
|
208
|
+
};
|
|
209
|
+
const result = {
|
|
210
|
+
data: {
|
|
211
|
+
committed: true,
|
|
212
|
+
sessionId: ctx.sessionId,
|
|
213
|
+
items: [...stored],
|
|
214
|
+
counts
|
|
215
|
+
},
|
|
216
|
+
execution: { state: "committed" },
|
|
217
|
+
isError: false,
|
|
218
|
+
presentation: {
|
|
219
|
+
type: "todo-list",
|
|
220
|
+
schemaVersion: 1,
|
|
221
|
+
summary: describeTodoList(stored),
|
|
222
|
+
state: "ready",
|
|
223
|
+
fields: {
|
|
224
|
+
...counts,
|
|
225
|
+
committed: true
|
|
226
|
+
},
|
|
227
|
+
actions: [],
|
|
228
|
+
bodyRefs: []
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
try {
|
|
232
|
+
announce(ctx.sessionId, stored);
|
|
233
|
+
} catch {
|
|
234
|
+
return {
|
|
235
|
+
...result,
|
|
236
|
+
isError: true,
|
|
237
|
+
error: {
|
|
238
|
+
code: "todo_announcement_failed",
|
|
239
|
+
retryable: false
|
|
240
|
+
},
|
|
241
|
+
presentation: {
|
|
242
|
+
...result.presentation,
|
|
243
|
+
summary: "Todo list was saved, but its announcement failed.",
|
|
244
|
+
state: "error"
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
return result;
|
|
217
249
|
}
|
|
218
250
|
};
|
|
219
251
|
}
|
|
220
252
|
//#endregion
|
|
221
253
|
//#region src/todo/index.ts
|
|
222
|
-
/** The session whose list is wanted. `ClientCallContext` carries no session
|
|
223
|
-
* — a call arrives from a connection, and a connection is not in a session
|
|
224
|
-
* — so the caller names it; in the browser that is the `sessionId` the host
|
|
225
|
-
* hands the panel. */
|
|
226
254
|
const ListTodosParams = z.strictObject({ sessionId: z.string().min(1) });
|
|
227
|
-
/** The answer carries the session back although the caller just sent it: by
|
|
228
|
-
* the time an async call returns, the panel may be showing another session,
|
|
229
|
-
* and comparing this is its only way to know whether the answer is still
|
|
230
|
-
* the one it wants. */
|
|
231
255
|
const ListTodosResult = z.strictObject({
|
|
232
256
|
sessionId: z.string(),
|
|
233
257
|
todos: z.array(TodoItem)
|
|
234
258
|
});
|
|
235
|
-
/** The frame carries the whole list rather than a signal to re-read. It is
|
|
236
|
-
* delivered to the connections watching that one session, so the content
|
|
237
|
-
* does not leak to a connection looking at something else, and its `seq`
|
|
238
|
-
* comes from the session's own stream — which is what makes "the later one
|
|
239
|
-
* is the newer one" free. */
|
|
240
259
|
const TodosChangedPayload = z.strictObject({ todos: z.array(TodoItem) });
|
|
241
260
|
const LIST_TODOS_DESCRIPTION = "The todo list recorded for one session, in the order the model wrote it. A session that has never recorded one answers with an empty list.";
|
|
242
|
-
/** Registers this member's tool, contributor, method and frame over one
|
|
243
|
-
* store, all of them owned by the plugin `ctx` belongs to. The package's
|
|
244
|
-
* `apply` calls this exactly where `todo_write` is on. */
|
|
245
261
|
function registerTodoTools(ctx, register) {
|
|
246
262
|
const store = openTodoStore(ctx);
|
|
247
263
|
const changed = ctx.client.registerFrame({
|
|
@@ -251,7 +267,7 @@ function registerTodoTools(ctx, register) {
|
|
|
251
267
|
});
|
|
252
268
|
register(writeTodosTool(store, (sessionId, todos) => {
|
|
253
269
|
changed.emit(sessionId, { todos: [...todos] });
|
|
254
|
-
}));
|
|
270
|
+
}, ctx.log));
|
|
255
271
|
ctx.context.contribute(todosContributor(store));
|
|
256
272
|
ctx.client.registerMethod({
|
|
257
273
|
name: "listTodos",
|
|
@@ -267,32 +283,11 @@ function registerTodoTools(ctx, register) {
|
|
|
267
283
|
});
|
|
268
284
|
}
|
|
269
285
|
//#endregion
|
|
286
|
+
//#region src/tool-names.ts
|
|
287
|
+
const TOOL_NAMES = ["todo_write"];
|
|
288
|
+
//#endregion
|
|
270
289
|
//#region src/index.ts
|
|
271
|
-
/**
|
|
272
|
-
* `@eum-agent/session-todo` — the session's task list, as one plugin: the `todo_write`
|
|
273
|
-
* tool, the `todos` volatile contributor that shows the list to the model on
|
|
274
|
-
* every step, the `listTodos` method and `todosChanged` frame the page reads
|
|
275
|
-
* it through, and the browser module that draws it beside the run.
|
|
276
|
-
*
|
|
277
|
-
* The member lives in `src/todo/`; this file is the only plugin, and it is
|
|
278
|
-
* what a person's `config.json` names, what `plugin list` prints, and what the
|
|
279
|
-
* loader imports.
|
|
280
|
-
*
|
|
281
|
-
* `@eum-agent/plugin` is the only workspace package any file here imports,
|
|
282
|
-
* and only its types: everything reached at runtime arrived through `ctx`.
|
|
283
|
-
*/
|
|
284
|
-
/**
|
|
285
|
-
* This plugin's slice of `config.json`. Strict and enumerated: a misspelled
|
|
286
|
-
* tool name is a load failure naming the field, not a line that quietly does
|
|
287
|
-
* nothing.
|
|
288
|
-
*/
|
|
289
290
|
const TodoConfig = z.strictObject({ disabled: z.array(z.enum(TOOL_NAMES)).default([]) }).default({ disabled: [] });
|
|
290
|
-
/**
|
|
291
|
-
* Where this package's browser module is, or nothing when it has not been
|
|
292
|
-
* built. Computed in this entry because `new URL(…, import.meta.url)` is
|
|
293
|
-
* carried into the bundle verbatim, and this file is one directory below the
|
|
294
|
-
* package root in source and in the output alike.
|
|
295
|
-
*/
|
|
296
291
|
function browserModule() {
|
|
297
292
|
const path = fileURLToPath(new URL("../ui/ui.js", import.meta.url));
|
|
298
293
|
return existsSync(path) ? path : void 0;
|
|
@@ -301,12 +296,16 @@ const todoPlugin = {
|
|
|
301
296
|
name: "@eum-agent/session-todo",
|
|
302
297
|
configSchema: TodoConfig,
|
|
303
298
|
apply(ctx, config) {
|
|
299
|
+
ctx.retention.register(todoRetention(ctx));
|
|
304
300
|
if (config.disabled.includes("todo_write")) return;
|
|
305
301
|
const register = (tool) => ctx.tools.register(tool);
|
|
306
302
|
registerTodoTools(ctx, register);
|
|
307
303
|
ctx.tools.guide(GUIDANCE);
|
|
308
304
|
const uiModule = browserModule();
|
|
309
|
-
if (uiModule !== void 0) ctx.client.
|
|
305
|
+
if (uiModule !== void 0) ctx.client.registerPackageFiles({
|
|
306
|
+
root: dirname(uiModule),
|
|
307
|
+
entry: "ui.js"
|
|
308
|
+
});
|
|
310
309
|
}
|
|
311
310
|
};
|
|
312
311
|
//#endregion
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"en-US": "Session Todo List",
|
|
5
5
|
"zh-CN": "会话待办清单"
|
|
6
6
|
},
|
|
7
|
-
"version": "1.0
|
|
7
|
+
"version": "1.2.0",
|
|
8
8
|
"type": "module",
|
|
9
9
|
"description": "Todo items and progress maintained within a conversation",
|
|
10
10
|
"license": "MIT",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@eum-agent/container": "1.0.0",
|
|
25
25
|
"@eum-agent/kernel": "1.0.0",
|
|
26
|
-
"@eum-agent/plugin": "1.0
|
|
26
|
+
"@eum-agent/plugin": "1.2.0",
|
|
27
27
|
"@types/react": "^19.2.18",
|
|
28
28
|
"@types/react-dom": "^19.2.5",
|
|
29
29
|
"react": "^19.2.0",
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
"dependencies": {},
|
|
39
39
|
"kind": "extension",
|
|
40
40
|
"foundationDependencies": {
|
|
41
|
-
"@eum-agent/infra-local": "1.0
|
|
42
|
-
"@eum-agent/storage-sqlite": "1.0
|
|
41
|
+
"@eum-agent/infra-local": "1.2.0",
|
|
42
|
+
"@eum-agent/storage-sqlite": "1.2.0"
|
|
43
43
|
}
|
|
44
44
|
},
|
|
45
45
|
"scripts": {
|