@celljs/ta-recall 4.12.0 → 4.13.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/README.en.md CHANGED
@@ -1,19 +1,28 @@
1
1
  # Cell - Ta Recall
2
2
 
3
- A pi package that comes with Ta (on by default; Settings → Extensions of the web client turns it off): Recall. What was done stays: ask how it was done, keep what you ask for again as a skill, and get a brief each day.
3
+ A pi package that comes with Ta (on by default; Settings → Extensions of the web client turns it off): Recall. What was done stays: ask how it was done, keep what you ask for again (how it is done, a card or a page, a scheduled run), and get a brief each day.
4
4
 
5
5
  - **Ask the past**: Ta has a tool `search_conversations({ query, days?, here? })` that searches what you and Ta said in the conversations of every directory (not the output of tools). Asked "how did we fix the relay last week", it searches first, then answers with links to the conversations, which open them. The search of Quick open gets a section Ask Ta: "Ask Ta: <what you typed>" asks in a new conversation, under it the conversations with every word.
6
- - **Keep as a skill**: when you ask for something you asked for in another conversation, Ta does it, then drafts a skill with `propose_skill`, which shows as a card: its name, what it is for, its steps to unfold, Save as a skill or No thanks. Saved, it goes to `~/.ta/agent/skills/<name>/SKILL.md`, which new conversations use, or `/skill:<name>`; after No thanks the like is not offered again. + of the message box → Keep as a skill has Ta draft one of the conversation. A model without Ta's tools (another coding agent) drafts it in a `ta-skill` block, to the same effect.
6
+ - **Keep**: when you ask for something you asked for in another conversation, Ta does it, then offers to keep it; + of the message box → Keep has Ta keep how this conversation did it, when you ask. Whatever is kept is an extension (a pi package); the card says it by what you get:
7
+ - **Remember how this is done** (`steps`): steps Ta follows and judges as it goes. Remember has the host write a package of only a skill in `~/.ta/agent/extensions/<name>/` (a `package.json` with its title, `skills/<name>/SKILL.md`), which new conversations follow, or `/skill:<name>`; the Extensions page lists, turns off and exports it.
8
+ - **Make it a card of the board / a page / a command / a tool beside the conversation** (`board`, `page`, `command`, `panel`, when Ta has the ta-package skill): what is to see or tap (a status, a fixed run of commands whose result needs no judgment, the same table each time). The card shows the plan (where its data comes from, the commands it runs, the files it reads or writes), and only Make it asks Ta, in that conversation, to make it with the ta-package skill: making one takes a while, so it is offered first.
9
+ - **Run it on a schedule**: what is done at a time with nobody watching (while [@celljs/ta-cron](../ta-cron/README.en.md) is on). The `<context>` of the message of Keep starts with `[ta:keep]` (`TA_KEEP_MARK`); ta-cron tells the model about it itself, in a section of the system prompt of those turns (`<ta-cron-keep>`), so this package does not know its format; with ta-cron off, it is not offered.
10
+
11
+ Ta offers with the tool `propose_extension({ name, title, kind, summary, body })`; a model without Ta's tools (another coding agent) writes a `ta-extension` block, to the same effect. After No thanks the like is not offered again. A card of a skill of before (`ta-recall-skill`) shows as Remember how this is done.
7
12
  - **Daily brief**: each day at its time (09:00 by default), when something happened since the last one, Ta writes in the conversation Daily brief what got done, what waits for you and what is next, each line linking its conversation. When the computer was off, one comes once the Ta service starts, one a day at most; the first comes at the next time after the package is installed.
8
13
 
9
- Settings → Recall: the daily brief, its time, one written now, and the offers to keep a skill.
14
+ Other packages add to the brief too: what one keeps under the key `brief` of its data (`TA_BRIEF_SOURCE`, `{ section, instruction, items: [{ at, text }] }`) goes into the material, the items since the last brief, and the brief writes a part of its own as the package says (Friends made of Moments).
15
+
16
+ Settings → Recall: the daily brief, its time, one written now, and the offers to keep.
17
+
18
+ Sessions a package opened for a role of its own (an agent of a channel, a run of a schedule) are offered nothing to keep.
10
19
 
11
- Sessions a package opened for a role of its own (an agent of a channel, a run of a schedule) are offered no skill.
20
+ Offering to keep something is a kind of Initiative (`@celljs/ta-initiative`), `recall.keep`: declined twice in a row it goes down to In the brief and is no longer offered in conversations; what you keep, have made or decline is told to it. The brief tells too what waits in Suggestions and what Ta did on its own.
12
21
 
13
22
  ## Data and calls
14
23
 
15
- Data of the package (`@celljs/ta-recall`): `suggest`, `brief` (`{ enabled, time }`), `briefFile`, `briefLast`, `decided` (what was decided of each card), `declined` (the requests not wanted as skills).
24
+ Data of the package (`@celljs/ta-recall`): `suggest`, `brief` (`{ enabled, time }`), `briefFile`, `briefLast`, `decided` (what was decided of each card), `declined` (the requests not wanted kept).
16
25
 
17
- Methods of its host (`pi.host`), which a web extension calls with `callPackageHost('@celljs/ta-recall', …)`: `search(query)`, `similar(text, piSessionId?)`, `saveSkill(key, draft)`, `declineSkill(key, ask?)`, `briefNow()`.
26
+ Methods of its host (`pi.host`), which a web extension calls with `callPackageHost('@celljs/ta-recall', …)`: `search(query)`, `similar(text, piSessionId?)`, `keep(key, draft)` (writes Remember how this is done as a package), `makeExtension(key, piSessionId, message)` (asks Ta to make the extension in the conversation of its card), `decline(key, ask?)`, `briefNow()`, `requests({ since, until?, exclude?, limit? })` (what the user typed in each conversation updated since a time, latest first, but those of scheduled runs and the briefs; `@celljs/ta-initiative` reads it).
18
27
 
19
28
  Design record: `docs/design/ta-recall.md`.
package/README.md CHANGED
@@ -1,19 +1,28 @@
1
1
  # Cell - Ta Recall
2
2
 
3
- Ta 自带的 pi 包(默认开启,可在 Web 客户端的 设置 → 扩展 关闭):回顾。把做过的事留下来:问以前怎么做的、把常交代的事存成技能、每天一份简报。
3
+ Ta 自带的 pi 包(默认开启,可在 Web 客户端的 设置 → 扩展 关闭):回顾。把做过的事留下来:问以前怎么做的、把常交代的事存下来(记住做法、做成卡片或页面、定时自动做)、每天一份简报。
4
4
 
5
5
  - **问过去**:Ta 有一个工具 `search_conversations({ query, days?, here? })`,在所有目录的对话里搜你和 Ta 说过的话(不含工具输出),你问"上周 relay 那个 bug 怎么修的"时它先搜,再回答并链出对话;点链接打开那个对话。快捷打开的搜索里多一个"问 Ta"分区:"问 Ta:<你输入的>"新开一个对话去问,下面是包含所有关键词的对话。
6
- - **存成技能**:你在另一个对话里交代过的事又交代一次时,Ta 做完后会用 `propose_skill` 起草一份技能,对话里出现一张卡片:名字、说明、可展开的步骤,"保存为技能"或"不用"。保存后写到 `~/.ta/agent/skills/<名字>/SKILL.md`,新对话自动用上,也可以 `/skill:<名字>`;"不用"之后类似的事不再问。输入框 + → 存成技能 让 Ta 把当前对话的做法起草成技能。没有 Ta 工具的模型(外部 Agent)用 `ta-skill` 代码块起草,效果一样。
6
+ - **存下来**:你在另一个对话里交代过的事又交代一次时,Ta 做完后会提议把它存下来;输入框 + → 存下来 则是你主动让 Ta 把这个对话的做法存下来。存下来的东西背后都是一个扩展(pi 包),卡片上按你会得到什么来说:
7
+ - **记住这套做法**(`steps`):要 Ta 边做边判断的步骤。点"记住",host 在 `~/.ta/agent/extensions/<名字>/` 写一个只含技能的包(`package.json` 带标题,`skills/<名字>/SKILL.md`),新对话自动照着做,也可以 `/skill:<名字>`,在扩展页里能找到、开关、导出。
8
+ - **做成小组件卡片 / 页面 / 命令 / 对话旁的工具**(`board`、`page`、`command`、`panel`,有 ta-package 技能时):想看一眼、点一下就行的事(一个状态、结果不用判断的固定命令、每次一样的表)。卡片上是做法(数据从哪来、跑什么命令、读写哪些文件),点"做出来"才在这个对话里请 Ta 照 ta-package 技能去做——做扩展要花时间,所以先提议。
9
+ - **定时自动做**:到点就做、没人在看也行的事([@celljs/ta-cron](../ta-cron/README.md) 开着时)。"存下来"的消息 `<context>` 以 `[ta:keep]`(`TA_KEEP_MARK`)开头,ta-cron 在这几轮的系统提示里自己说明(`<ta-cron-keep>`),本包不知道它的格式;关掉 ta-cron 就不会提。
10
+
11
+ Ta 用工具 `propose_extension({ name, title, kind, summary, body })` 提议;没有 Ta 工具的模型(外部 Agent)写 `ta-extension` 代码块,效果一样。"不用"之后类似的事不再问。以前存成的技能卡片(`ta-recall-skill`)仍按"记住这套做法"显示。
7
12
  - **每日简报**:每天到了设定时间(默认 09:00),如果上次以来有新动静,Ta 在"每日简报"对话里写:做完了什么、等你定什么、下一步,每条链到对话。电脑没开就在 Ta 服务启动后补一份,一天最多一份;第一次装上从下一个简报时间开始。
8
13
 
9
- 设置 → 回顾:每日简报开关、简报时间、现在写一份、建议存成技能开关。
14
+ 别的包也能往简报里加内容:在自己的包数据 `brief` 键(`TA_BRIEF_SOURCE`,`{ section, instruction, items: [{ at, text }] }`)下写好,简报会带上上次以来的条目,并照包的指示写成单独一段(例如动态的"好友在做")。
15
+
16
+ 设置 → 回顾:每日简报开关、简报时间、现在写一份、建议存下来开关。
17
+
18
+ 由别的包打开、承担固定角色的会话(频道里的智能体、定时任务的运行)不建议存下来。
10
19
 
11
- 由别的包打开、承担固定角色的会话(频道里的智能体、定时任务的运行)不建议存技能。
20
+ 建议存下来是"主动"(`@celljs/ta-initiative`)的一类事 `recall.keep`:你连续拒绝两次后它降到"只进简报",就不再在对话里建议;存下、做成扩展或拒绝都会回报给它。简报也写上"Ta 的建议"里等你决定的事和 Ta 自己做了的事。
12
21
 
13
22
  ## 数据与调用
14
23
 
15
- 包数据(`@celljs/ta-recall`):`suggest`(是否建议存技能)、`brief`(`{ enabled, time }`)、`briefFile`(简报对话的会话文件)、`briefLast`(上次简报的时间)、`decided`(各卡片的保存或拒绝)、`declined`(拒绝过的请求)。
24
+ 包数据(`@celljs/ta-recall`):`suggest`(是否建议存下来)、`brief`(`{ enabled, time }`)、`briefFile`(简报对话的会话文件)、`briefLast`(上次简报的时间)、`decided`(各卡片的保存、做出来或拒绝)、`declined`(拒绝过的请求)。
16
25
 
17
- 包宿主(`pi.host`)的方法,Web 扩展经 `callPackageHost('@celljs/ta-recall', …)` 调用:`search(query)`、`similar(text, piSessionId?)`、`saveSkill(key, draft)`、`declineSkill(key, ask?)`、`briefNow()`。
26
+ 包宿主(`pi.host`)的方法,Web 扩展经 `callPackageHost('@celljs/ta-recall', …)` 调用:`search(query)`、`similar(text, piSessionId?)`、`keep(key, draft)`(把"记住这套做法"写成扩展包)、`makeExtension(key, piSessionId, message)`(在卡片所在的对话里请 Ta 做扩展)、`decline(key, ask?)`、`briefNow()`、`requests({ since, until?, exclude?, limit? })`(某个时间以来各对话里用户亲手发的请求,新的在前,不含定时任务运行和简报的对话;`@celljs/ta-initiative` 用它)。
18
27
 
19
28
  设计记录:`docs/design/ta-recall.md`。
@@ -8,20 +8,72 @@ var TaHostUtil;
8
8
  TaHostUtil2.WAIT_MS = 1000;
9
9
  function reach(events, name, waitMs = TaHostUtil2.WAIT_MS) {
10
10
  return new Promise((resolve) => {
11
+ let heard = false;
12
+ let answered = false;
11
13
  const timer = setTimeout(() => resolve(undefined), waitMs);
12
14
  const request = {
13
15
  name,
16
+ heard: () => {
17
+ heard = true;
18
+ },
14
19
  resolve: (answer) => {
20
+ answered = true;
15
21
  clearTimeout(timer);
16
22
  resolve(answer);
17
23
  }
18
24
  };
19
25
  events.emit(TA_HOST_EVENT, request);
26
+ if (!heard && !answered) {
27
+ clearTimeout(timer);
28
+ resolve(undefined);
29
+ }
20
30
  });
21
31
  }
22
32
  TaHostUtil2.reach = reach;
23
33
  })(TaHostUtil || (TaHostUtil = {}));
24
34
  var TA_WITH_OTHERS_MARK = "[ta:speaks-with-others]";
35
+ var TA_KEEP_MARK = "[ta:keep]";
36
+ var TA_ASK_ENTRY = "ta-ask";
37
+ var TaAskUtil;
38
+ (function(TaAskUtil2) {
39
+ const LENGTH = 120;
40
+ function entry(question) {
41
+ const line = question.replace(/\s+/g, " ").trim();
42
+ return { question: line.length > LENGTH ? `${line.slice(0, LENGTH - 1)}…` : line };
43
+ }
44
+ TaAskUtil2.entry = entry;
45
+ function asking(entries) {
46
+ var _a;
47
+ for (let i = entries.length - 1;i >= 0; i--) {
48
+ const entry2 = entries[i];
49
+ if (entry2.type === "message" && ((_a = entry2.message) === null || _a === undefined ? undefined : _a.role) === "user") {
50
+ return;
51
+ }
52
+ if (entry2.type === "custom" && entry2.customType === TA_ASK_ENTRY) {
53
+ return read(entry2);
54
+ }
55
+ }
56
+ return;
57
+ }
58
+ TaAskUtil2.asking = asking;
59
+ function next(asked, entry2) {
60
+ var _a;
61
+ if (entry2.type === "message" && ((_a = entry2.message) === null || _a === undefined ? undefined : _a.role) === "user") {
62
+ return;
63
+ }
64
+ return entry2.type === "custom" && entry2.customType === TA_ASK_ENTRY ? read(entry2) : asked;
65
+ }
66
+ TaAskUtil2.next = next;
67
+ function read(found) {
68
+ var _a;
69
+ const question = (_a = found.data) === null || _a === undefined ? undefined : _a.question;
70
+ if (typeof question !== "string" || !question.trim()) {
71
+ return;
72
+ }
73
+ const at = found.timestamp ? Date.parse(found.timestamp) : Number.NaN;
74
+ return { question: entry(question).question, at: Number.isNaN(at) ? 0 : at };
75
+ }
76
+ })(TaAskUtil || (TaAskUtil = {}));
25
77
 
26
78
  // web-src/conversation-index.ts
27
79
  import { readdir, readFile, stat } from "node:fs/promises";
@@ -175,12 +227,51 @@ class ConversationIndex {
175
227
  }
176
228
  }
177
229
 
230
+ // web-src/block-util.ts
231
+ var BlockUtil;
232
+ ((BlockUtil) => {
233
+ function last(text, language) {
234
+ const lines = text.split(/\r?\n/);
235
+ let found;
236
+ for (let index = 0;index < lines.length; index++) {
237
+ const open = /^\s*(`{3,})\s*([\w-]+)\s*$/.exec(lines[index]);
238
+ if (open?.[2] !== language) {
239
+ continue;
240
+ }
241
+ const close = new RegExp(`^\\s*${open[1]}\`*\\s*$`);
242
+ const end = lines.findIndex((line, at) => at > index && close.test(line));
243
+ found = lines.slice(index + 1, end < 0 ? lines.length : end);
244
+ index = end < 0 ? lines.length : end;
245
+ }
246
+ return found && parse(found);
247
+ }
248
+ BlockUtil.last = last;
249
+ function parse(lines) {
250
+ const rule = lines.findIndex((line) => line.trim() === "---");
251
+ const fields = {};
252
+ for (const line of rule < 0 ? [] : lines.slice(0, rule)) {
253
+ const field = /^\s*([\w-]+)\s*:\s*(.*)$/.exec(line);
254
+ const key = field?.[1].toLowerCase();
255
+ if (field && key && !(key in fields)) {
256
+ fields[key] = field[2].trim().replace(/^["'](.*)["']$/, "$1");
257
+ }
258
+ }
259
+ return {
260
+ fields,
261
+ body: lines.slice(rule + 1).join(`
262
+ `).trim()
263
+ };
264
+ }
265
+ })(BlockUtil ||= {});
266
+
178
267
  // web-src/recall-protocol.ts
179
268
  var NAME = "@celljs/ta-recall";
180
269
  var TOOL_NAME = "search_conversations";
181
- var PROPOSE_TOOL = "propose_skill";
182
270
  var SKILL_TYPE = "ta-recall-skill";
183
- var SKILL_BLOCK = "ta-skill";
271
+ var EXTENSION_TOOL = "propose_extension";
272
+ var EXTENSION_TYPE = "ta-recall-extension";
273
+ var EXTENSION_BLOCK = "ta-extension";
274
+ var EXTENSION_KINDS = ["steps", "board", "page", "command", "panel"];
184
275
  var Keys;
185
276
  ((Keys) => {
186
277
  Keys.SUGGEST = "suggest";
@@ -209,8 +300,156 @@ var Limits;
209
300
  Limits.BRIEF_CONVERSATIONS = 30;
210
301
  Limits.BRIEF_ITEMS = 5;
211
302
  Limits.ASKED_ARCHIVE_DAYS = 7;
303
+ Limits.REQUEST_CONVERSATIONS = 80;
304
+ Limits.REQUEST_ASKS = 12;
305
+ Limits.REQUEST_CHARS = 300;
212
306
  })(Limits ||= {});
213
307
 
308
+ // web-src/extension-util.ts
309
+ var FENCE = "```";
310
+ var NAME_CHARS = 64;
311
+ var TITLE_CHARS2 = 60;
312
+ var SUMMARY_CHARS = 300;
313
+ var ExtensionUtil;
314
+ ((ExtensionUtil) => {
315
+ ExtensionUtil.KIND_HELP = {
316
+ steps: "steps Ta follows when the user asks again and judges as it goes: a skill of the package, saved from the card as written",
317
+ board: "a card of the board, to see at a glance: a status, a count, what is next",
318
+ page: "a page of its own: a table, a chart, a form the user fills in",
319
+ command: "a /command, or a button, that runs a fixed set of commands whose result needs no judgment",
320
+ panel: "a tool of the workbench beside the conversation, as the explorer or the terminal"
321
+ };
322
+ function find(text) {
323
+ const block = BlockUtil.last(text, EXTENSION_BLOCK);
324
+ if (!block?.body) {
325
+ return;
326
+ }
327
+ const { name: name2 = "", title = "", kind = "", summary = "" } = block.fields;
328
+ return check({ name: name2, title, kind, summary, body: block.body });
329
+ }
330
+ ExtensionUtil.find = find;
331
+ function name(text) {
332
+ return text.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, NAME_CHARS).replace(/-+$/, "");
333
+ }
334
+ ExtensionUtil.name = name;
335
+ function check(draft) {
336
+ const body = typeof draft?.body === "string" ? draft.body.trim() : "";
337
+ if (!body) {
338
+ throw new Error("An extension needs a body: its steps, or the plan to make it by.");
339
+ }
340
+ const line = (value, chars) => (typeof value === "string" ? value : "").replace(/\s+/g, " ").trim().slice(0, chars);
341
+ const title = line(draft.title, TITLE_CHARS2);
342
+ const named = name(typeof draft.name === "string" ? draft.name : "") || name(title) || "extension";
343
+ const kind = EXTENSION_KINDS.includes(draft.kind) ? draft.kind : "steps";
344
+ return { name: named, title: title || named, kind, summary: line(draft.summary, SUMMARY_CHARS) || line(body.split(`
345
+ `)[0], 200), body };
346
+ }
347
+ ExtensionUtil.check = check;
348
+ function blockHelp() {
349
+ return [
350
+ `${FENCE}${EXTENSION_BLOCK}`,
351
+ "name: <lowercase-words-with-dashes, its directory>",
352
+ "title: <a few words, as the lists show it>",
353
+ `kind: <one of ${EXTENSION_KINDS.join(", ")}>`,
354
+ "summary: <one line: what it does, and when Ta uses it (steps) or where it shows>",
355
+ "---",
356
+ "<steps: the goal, then the steps, commands, files, checks and pitfalls that worked, in general terms; else the plan: what it shows or does, where its data comes from, the commands it runs, the files it reads or writes>",
357
+ FENCE,
358
+ "Use a longer fence when the body has fences of its own. Write it in the language of the user."
359
+ ].join(`
360
+ `);
361
+ }
362
+ ExtensionUtil.blockHelp = blockHelp;
363
+ function manifest(draft) {
364
+ const pkg = {
365
+ name: draft.name,
366
+ version: "0.1.0",
367
+ description: draft.summary,
368
+ pi: { title: draft.title, summary: draft.summary, icon: "ListChecks", skills: ["./skills"] }
369
+ };
370
+ return `${JSON.stringify(pkg, null, 2)}
371
+ `;
372
+ }
373
+ ExtensionUtil.manifest = manifest;
374
+ function skill(draft) {
375
+ return `---
376
+ name: ${draft.name}
377
+ description: ${JSON.stringify(draft.summary)}
378
+ ---
379
+
380
+ ${draft.body.trim()}
381
+ `;
382
+ }
383
+ ExtensionUtil.skill = skill;
384
+ function make(draft, language) {
385
+ const context = [
386
+ "[ta-recall:make]",
387
+ "The user wants the extension Ta offered made now. Read the ta-package skill first and make it as it says, in the smallest package that does what the plan says.",
388
+ `- name: ${draft.name}`,
389
+ `- title: ${draft.title}`,
390
+ `- kind: ${draft.kind} (${ExtensionUtil.KIND_HELP[draft.kind]})`,
391
+ `- summary: ${draft.summary}`,
392
+ "- plan:",
393
+ draft.body,
394
+ "- Put it in extensions/ of the agent directory, as the skill says. Give it the title and summary above, in the language of the user and English.",
395
+ "- Once it is made, say in one line where the user finds it."
396
+ ].join(`
397
+ `);
398
+ const said = /^zh/i.test(language) ? `做出来:${draft.title}` : `Make it: ${draft.title}`;
399
+ return `<context>
400
+ ${context}
401
+ </context>
402
+ ${said}`;
403
+ }
404
+ ExtensionUtil.make = make;
405
+ })(ExtensionUtil ||= {});
406
+
407
+ // web-src/keep-util.ts
408
+ var PACKAGE_SKILL = "ta-package";
409
+ var TASK_SECTION = "ta-cron-keep";
410
+ var KeepUtil;
411
+ ((KeepUtil) => {
412
+ function forms() {
413
+ const kinds = EXTENSION_KINDS.map((kind) => ` - ${kind}: ${ExtensionUtil.KIND_HELP[kind]}${kind === "steps" ? "" : `; only when the ${PACKAGE_SKILL} skill is among your skills`}`);
414
+ return [
415
+ `- As an extension of Ta, with ${EXTENSION_TOOL}, of the kind that fits:`,
416
+ ...kinds,
417
+ ` Ta shows it as a card: steps are saved with a tap; any other kind you make only once the user taps Make it, so do not make it now, nor write files yourself. Prefer steps when Ta should think as it goes; another kind when the user would rather see or tap it than ask. Without that tool, end your answer with it in a fenced block of the language ${EXTENSION_BLOCK}:`,
418
+ ExtensionUtil.blockHelp(),
419
+ `- As a scheduled task, only when your instructions have a <${TASK_SECTION}> section, and it should be done again on a schedule with nobody asking: as that section says.`
420
+ ].join(`
421
+ `);
422
+ }
423
+ KeepUtil.forms = forms;
424
+ function ask(language) {
425
+ const context = [
426
+ TA_KEEP_MARK,
427
+ "The user wants how this conversation got its work done kept, so that it need not be told again, written so that one who never saw this conversation does it the same way. Pick the one form that fits best, say in a line which and why, in plain words (what the user will see or do, not the kind), and offer it:",
428
+ forms(),
429
+ "- Keep what worked: the goal, the steps, the commands, files, checks and pitfalls; leave out what was only tried and dropped and what holds only this once.",
430
+ "- When the conversation holds nothing worth keeping, say so and offer nothing."
431
+ ].join(`
432
+ `);
433
+ return `<context>
434
+ ${context}
435
+ </context>
436
+ ${/^zh/i.test(language) ? "把这个对话里的做法存下来" : "Keep how this was done"}`;
437
+ }
438
+ KeepUtil.ask = ask;
439
+ function hint(asks) {
440
+ const lines = asks.map((ask2) => `- "${ask2.title}" (${new Date(ask2.at).toISOString().slice(0, 10)}): ${JSON.stringify(ask2.text.replace(/\s+/g, " ").slice(0, 200))}`);
441
+ return [
442
+ "The user asked for much the same in other conversations before:",
443
+ ...lines,
444
+ "Do what is asked first. Then, if it is worth keeping so that it need not be told again (not a one-off answer), offer to keep it in one short sentence, in plain words, in the form that fits best:",
445
+ forms(),
446
+ "Offer nothing when it is not worth keeping."
447
+ ].join(`
448
+ `);
449
+ }
450
+ KeepUtil.hint = hint;
451
+ })(KeepUtil ||= {});
452
+
214
453
  // web-src/search-util.ts
215
454
  var DAY_MS = 24 * 60 * 60000;
216
455
  var PAIRS_CHARS = 1000;
@@ -343,107 +582,6 @@ var SimilarUtil;
343
582
  SimilarUtil.find = find;
344
583
  })(SimilarUtil ||= {});
345
584
 
346
- // web-src/skill-util.ts
347
- var FENCE = "```";
348
- var NAME_CHARS = 64;
349
- var DESCRIPTION_CHARS = 1024;
350
- var SkillUtil;
351
- ((SkillUtil) => {
352
- function find(text) {
353
- const lines = text.split(/\r?\n/);
354
- let found;
355
- for (let index = 0;index < lines.length; index++) {
356
- const open = /^\s*(`{3,})\s*([\w-]+)\s*$/.exec(lines[index]);
357
- if (open?.[2] !== SKILL_BLOCK) {
358
- continue;
359
- }
360
- const close = new RegExp(`^\\s*${open[1]}\`*\\s*$`);
361
- const end = lines.findIndex((line, at) => at > index && close.test(line));
362
- found = lines.slice(index + 1, end < 0 ? lines.length : end);
363
- index = end < 0 ? lines.length : end;
364
- }
365
- return found && parse(found);
366
- }
367
- SkillUtil.find = find;
368
- function parse(lines) {
369
- const rule = lines.findIndex((line) => line.trim() === "---");
370
- const head = rule < 0 ? [] : lines.slice(0, rule);
371
- const body = lines.slice(rule + 1).join(`
372
- `).trim();
373
- if (!body) {
374
- return;
375
- }
376
- const field = (key) => head.map((line) => new RegExp(`^\\s*${key}\\s*:\\s*(.*)$`, "i").exec(line)?.[1].trim().replace(/^["'](.*)["']$/, "$1")).find((value) => value !== undefined);
377
- const description = (field("description") ?? "").replace(/\s+/g, " ").slice(0, DESCRIPTION_CHARS);
378
- return { name: name(field("name") ?? "") || name(description) || "skill", description, body };
379
- }
380
- function name(text) {
381
- return text.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, NAME_CHARS).replace(/-+$/, "");
382
- }
383
- SkillUtil.name = name;
384
- function check(draft) {
385
- const body = typeof draft?.body === "string" ? draft.body.trim() : "";
386
- if (!body) {
387
- throw new Error("A skill needs a body.");
388
- }
389
- const description = (typeof draft.description === "string" ? draft.description : "").replace(/\s+/g, " ").trim().slice(0, DESCRIPTION_CHARS);
390
- return { name: name(typeof draft.name === "string" ? draft.name : "") || "skill", description: description || body.split(`
391
- `)[0].slice(0, 200), body };
392
- }
393
- SkillUtil.check = check;
394
- function markdown(draft) {
395
- return `---
396
- name: ${draft.name}
397
- description: ${JSON.stringify(draft.description)}
398
- ---
399
-
400
- ${draft.body.trim()}
401
- `;
402
- }
403
- SkillUtil.markdown = markdown;
404
- function blockHelp() {
405
- return [
406
- `${FENCE}${SKILL_BLOCK}`,
407
- "name: <lowercase-words-with-dashes>",
408
- "description: <one line: what it does and when to use it>",
409
- "---",
410
- "<the body: the goal, then the steps, commands, files and checks that worked, in general terms, without what held only this once>",
411
- FENCE,
412
- "Use a longer fence when the body has fences of its own. Write it in the language of the user."
413
- ].join(`
414
- `);
415
- }
416
- SkillUtil.blockHelp = blockHelp;
417
- function hint(asks) {
418
- const lines = asks.map((ask2) => `- "${ask2.title}" (${new Date(ask2.at).toISOString().slice(0, 10)}): ${JSON.stringify(ask2.text.replace(/\s+/g, " ").slice(0, 200))}`);
419
- return [
420
- "The user asked for much the same in other conversations before:",
421
- ...lines,
422
- `Do what is asked first. Then, if it is a way of working worth doing the same way again (steps, commands, checks; not a one-off answer), offer to keep it as a skill in one short sentence and draft it with ${PROPOSE_TOOL}, which Ta shows as a card the user saves with a tap. Without that tool, end your answer with the draft in a fenced block of the language ${SKILL_BLOCK} instead:`,
423
- blockHelp(),
424
- "Offer nothing when it is not worth keeping."
425
- ].join(`
426
- `);
427
- }
428
- SkillUtil.hint = hint;
429
- function ask(language) {
430
- const context = [
431
- "[ta-recall:skill]",
432
- "The user wants the way of working of this conversation kept as a skill of Ta, which Ta loads in every new conversation: written so that one who never saw this conversation does it the same way.",
433
- "- Keep what worked: the goal, the steps, the commands, files, checks and pitfalls; leave out what was only tried and dropped and what holds only this once.",
434
- `- Draft it with ${PROPOSE_TOOL}, which Ta shows as a card the user saves, and say in a line what it does; do not write the skill file yourself. Without that tool, end your answer with the draft in a fenced block of the language ${SKILL_BLOCK}:`,
435
- blockHelp(),
436
- "- When the conversation holds no way of working worth keeping, say so and draft nothing."
437
- ].join(`
438
- `);
439
- return `<context>
440
- ${context}
441
- </context>
442
- ${/^zh/i.test(language) ? "把这个对话里的做法存成技能" : "Keep how this was done as a skill"}`;
443
- }
444
- SkillUtil.ask = ask;
445
- })(SkillUtil ||= {});
446
-
447
585
  // web-src/tool.ts
448
586
  var RecallTool;
449
587
  ((RecallTool) => {
@@ -486,30 +624,41 @@ var RecallTool;
486
624
  return at ? new Date(at).toISOString().slice(0, 16).replace("T", " ") : "";
487
625
  }
488
626
  })(RecallTool ||= {});
489
- var ProposeTool;
490
- ((ProposeTool) => {
491
- ProposeTool.NAME = PROPOSE_TOOL;
492
- ProposeTool.DEFINITION = {
493
- name: ProposeTool.NAME,
494
- label: "Propose skill",
495
- description: "Offers the user to keep a way of working as a skill of Ta, which Ta loads in every new conversation. The draft shows in this conversation as a card once your turn ends, with Save and No thanks; nothing is written until the user saves it. Write it so that one who never saw this conversation does it the same way.",
496
- promptSnippet: "Offer to keep a way of working as a skill the user saves from a card",
497
- promptGuidelines: ["When the user asks to keep how something is done as a skill, draft it with propose_skill rather than writing a SKILL.md yourself."],
627
+ var ExtensionTool;
628
+ ((ExtensionTool) => {
629
+ ExtensionTool.NAME = EXTENSION_TOOL;
630
+ ExtensionTool.DEFINITION = {
631
+ name: ExtensionTool.NAME,
632
+ label: "Propose extension",
633
+ description: "Offers the user to keep how something is done as an extension of Ta, so that it need not be told again: steps Ta follows (saved from the card as written, loaded in every new conversation), or a card of the board, a page, a command or a tool of the workbench, which you make with the ta-package skill once the user taps Make it. The offer shows in this conversation as a card once your turn ends; nothing is written until the user wants it.",
634
+ promptSnippet: "Offer to keep how something is done as an extension the user keeps from a card",
635
+ promptGuidelines: [
636
+ "When the user asks to keep how something is done (as steps, a skill, a tool, a card), offer it with propose_extension rather than writing files yourself."
637
+ ],
498
638
  parameters: {
499
639
  type: "object",
500
640
  properties: {
501
- name: { type: "string", description: "Lowercase words with dashes, as weekly-deps-upgrade." },
502
- description: { type: "string", description: "One line in the language of the user: what it does and when to use it." },
641
+ name: { type: "string", description: "Lowercase words with dashes, the directory of its package, as weekly-deps-upgrade." },
642
+ title: { type: "string", description: "A few words in the language of the user, as the lists show it." },
643
+ kind: {
644
+ type: "string",
645
+ enum: [...EXTENSION_KINDS],
646
+ description: EXTENSION_KINDS.map((kind) => `${kind}: ${ExtensionUtil.KIND_HELP[kind]}`).join("; ")
647
+ },
648
+ summary: {
649
+ type: "string",
650
+ description: "One line in the language of the user: what it does, and when Ta uses it (steps) or where it shows."
651
+ },
503
652
  body: {
504
653
  type: "string",
505
- description: "Markdown in the language of the user: the goal, then the steps, commands, files, checks and pitfalls that worked, in general terms, without what held only this once."
654
+ description: "Markdown in the language of the user. Steps: the goal, then the steps, commands, files, checks and pitfalls that worked, in general terms, without what held only this once. Another kind: the plan, what it shows or does, where its data comes from, the commands it runs and the files it reads or writes."
506
655
  }
507
656
  },
508
- required: ["name", "description", "body"]
657
+ required: ["name", "title", "kind", "summary", "body"]
509
658
  }
510
659
  };
511
- ProposeTool.RESULT = "The draft shows as a card when your turn ends; the user saves it or not. Say in one short sentence what the skill does, and end your turn.";
512
- })(ProposeTool ||= {});
660
+ ExtensionTool.RESULT = "The offer shows as a card when your turn ends; the user keeps it or not. Say in one short sentence, in plain words, what it would do, and end your turn.";
661
+ })(ExtensionTool ||= {});
513
662
 
514
663
  // web-src/extension.ts
515
664
  var BRIEF_MARK = "[ta-recall:brief]";
@@ -540,7 +689,7 @@ function activate(pi) {
540
689
  try {
541
690
  const similar = await (await reach())?.service?.similar(text, ctx.sessionManager.getSessionId()) ?? [];
542
691
  if (similar.length) {
543
- event.systemPromptOptions.sections = { ...event.systemPromptOptions.sections, [REPEAT_SECTION]: SkillUtil.hint(similar) };
692
+ event.systemPromptOptions.sections = { ...event.systemPromptOptions.sections, [REPEAT_SECTION]: KeepUtil.hint(similar) };
544
693
  }
545
694
  return;
546
695
  } catch (error) {
@@ -549,28 +698,33 @@ function activate(pi) {
549
698
  }
550
699
  });
551
700
  pi.on("context", (event) => {
552
- const messages = event.messages.filter((message) => !(message.role === "custom" && message.customType === SKILL_TYPE));
701
+ const messages = event.messages.filter((message) => !(message.role === "custom" && (message.customType === SKILL_TYPE || message.customType === EXTENSION_TYPE)));
553
702
  return messages.length === event.messages.length ? undefined : { messages };
554
703
  });
555
704
  pi.on("agent_end", (event, ctx) => {
556
705
  const answer = [...event.messages ?? []].reverse().find((message) => message.role === "assistant");
557
- const found = answer && answer.stopReason !== "aborted" ? SkillUtil.find(ConversationUtil.textOf(answer.content)) : undefined;
706
+ const text = answer && answer.stopReason !== "aborted" ? ConversationUtil.textOf(answer.content) : "";
558
707
  const file = ctx.sessionManager.getSessionFile();
559
- if (briefing && answer && answer.stopReason !== "aborted" && file) {
560
- const text = ConversationUtil.textOf(answer.content);
708
+ if (briefing && text && file) {
561
709
  reach().then((reached2) => reached2?.service?.keepBrief(file, text)).catch((error) => console.error("ta-recall could not keep the brief:", error));
562
710
  }
563
- if (found && !draft) {
564
- draft = { key: `${ctx.sessionManager.getSessionId()}:${Date.now()}`, draft: found, ...asked ? { ask: asked } : {} };
711
+ if (!text || draft) {
712
+ return;
565
713
  }
714
+ const found = ExtensionUtil.find(text);
715
+ draft = found && card(found, ctx);
566
716
  });
567
717
  pi.on("agent_settled", (event) => {
568
- const card = draft;
718
+ const left = draft;
569
719
  draft = undefined;
570
- if (card && !event.aborted) {
571
- pi.sendMessage({ customType: SKILL_TYPE, content: card.draft.name, display: true, details: card }, { triggerTurn: false });
720
+ if (left && !event.aborted) {
721
+ pi.sendMessage({ customType: EXTENSION_TYPE, content: left.draft.title, display: true, details: left }, { triggerTurn: false });
572
722
  }
573
723
  });
724
+ const card = (found, ctx) => {
725
+ const session = ctx.sessionManager.getSessionId();
726
+ return { key: `${session}:${Date.now()}`, draft: found, session, ...asked ? { ask: asked } : {} };
727
+ };
574
728
  const search = async (query, ctx) => {
575
729
  const answer = await reach();
576
730
  if (answer?.service) {
@@ -584,15 +738,17 @@ function activate(pi) {
584
738
  return SearchUtil.search(await local.all(), query);
585
739
  };
586
740
  pi.registerTool({
587
- ...ProposeTool.DEFINITION,
741
+ ...ExtensionTool.DEFINITION,
588
742
  execute: async (_id, params, _signal, _update, ctx) => {
589
- const checked = SkillUtil.check({
743
+ const checked = ExtensionUtil.check({
590
744
  name: String(params?.name ?? ""),
591
- description: String(params?.description ?? ""),
745
+ title: String(params?.title ?? ""),
746
+ kind: String(params?.kind ?? ""),
747
+ summary: String(params?.summary ?? ""),
592
748
  body: typeof params?.body === "string" ? params.body : ""
593
749
  });
594
- draft = { key: `${ctx.sessionManager.getSessionId()}:${Date.now()}`, draft: checked, ...asked ? { ask: asked } : {} };
595
- return { content: [{ type: "text", text: ProposeTool.RESULT }], details: { name: checked.name } };
750
+ draft = card(checked, ctx);
751
+ return { content: [{ type: "text", text: ExtensionTool.RESULT }], details: { name: checked.name } };
596
752
  }
597
753
  });
598
754
  pi.registerTool({