@celljs/ta-recall 4.12.0 → 4.13.1
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 +15 -6
- package/README.md +15 -6
- package/extension/index.mjs +311 -134
- package/host/index.mjs +472 -116
- package/package.json +15 -7
- package/web/index.js +414 -153
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
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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?)`, `
|
|
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
|
-
-
|
|
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
|
|
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?)`、`
|
|
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`。
|
package/extension/index.mjs
CHANGED
|
@@ -8,20 +8,93 @@ 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;
|
|
33
|
+
function marked(systemPrompt, mark) {
|
|
34
|
+
return role(systemPrompt).includes(mark);
|
|
35
|
+
}
|
|
36
|
+
TaHostUtil2.marked = marked;
|
|
37
|
+
function role(systemPrompt) {
|
|
38
|
+
if (!systemPrompt) {
|
|
39
|
+
return "";
|
|
40
|
+
}
|
|
41
|
+
const open = `<addendum>
|
|
42
|
+
`;
|
|
43
|
+
const start = systemPrompt.indexOf(open);
|
|
44
|
+
const context = systemPrompt.indexOf(`<project_context>
|
|
45
|
+
`);
|
|
46
|
+
if (start < 0 || context >= 0 && context < start) {
|
|
47
|
+
return "";
|
|
48
|
+
}
|
|
49
|
+
const end = systemPrompt.indexOf(`
|
|
50
|
+
</addendum>`, start);
|
|
51
|
+
return systemPrompt.slice(start + open.length, end < 0 ? undefined : end);
|
|
52
|
+
}
|
|
53
|
+
TaHostUtil2.role = role;
|
|
23
54
|
})(TaHostUtil || (TaHostUtil = {}));
|
|
24
55
|
var TA_WITH_OTHERS_MARK = "[ta:speaks-with-others]";
|
|
56
|
+
var TA_KEEP_MARK = "[ta:keep]";
|
|
57
|
+
var TA_ASK_ENTRY = "ta-ask";
|
|
58
|
+
var TaAskUtil;
|
|
59
|
+
(function(TaAskUtil2) {
|
|
60
|
+
const LENGTH = 120;
|
|
61
|
+
function entry(question) {
|
|
62
|
+
const line = question.replace(/\s+/g, " ").trim();
|
|
63
|
+
return { question: line.length > LENGTH ? `${line.slice(0, LENGTH - 1)}…` : line };
|
|
64
|
+
}
|
|
65
|
+
TaAskUtil2.entry = entry;
|
|
66
|
+
function asking(entries) {
|
|
67
|
+
var _a;
|
|
68
|
+
for (let i = entries.length - 1;i >= 0; i--) {
|
|
69
|
+
const entry2 = entries[i];
|
|
70
|
+
if (entry2.type === "message" && ((_a = entry2.message) === null || _a === undefined ? undefined : _a.role) === "user") {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (entry2.type === "custom" && entry2.customType === TA_ASK_ENTRY) {
|
|
74
|
+
return read(entry2);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
TaAskUtil2.asking = asking;
|
|
80
|
+
function next(asked, entry2) {
|
|
81
|
+
var _a;
|
|
82
|
+
if (entry2.type === "message" && ((_a = entry2.message) === null || _a === undefined ? undefined : _a.role) === "user") {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
return entry2.type === "custom" && entry2.customType === TA_ASK_ENTRY ? read(entry2) : asked;
|
|
86
|
+
}
|
|
87
|
+
TaAskUtil2.next = next;
|
|
88
|
+
function read(found) {
|
|
89
|
+
var _a;
|
|
90
|
+
const question = (_a = found.data) === null || _a === undefined ? undefined : _a.question;
|
|
91
|
+
if (typeof question !== "string" || !question.trim()) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
const at = found.timestamp ? Date.parse(found.timestamp) : Number.NaN;
|
|
95
|
+
return { question: entry(question).question, at: Number.isNaN(at) ? 0 : at };
|
|
96
|
+
}
|
|
97
|
+
})(TaAskUtil || (TaAskUtil = {}));
|
|
25
98
|
|
|
26
99
|
// web-src/conversation-index.ts
|
|
27
100
|
import { readdir, readFile, stat } from "node:fs/promises";
|
|
@@ -175,12 +248,51 @@ class ConversationIndex {
|
|
|
175
248
|
}
|
|
176
249
|
}
|
|
177
250
|
|
|
251
|
+
// web-src/block-util.ts
|
|
252
|
+
var BlockUtil;
|
|
253
|
+
((BlockUtil) => {
|
|
254
|
+
function last(text, language) {
|
|
255
|
+
const lines = text.split(/\r?\n/);
|
|
256
|
+
let found;
|
|
257
|
+
for (let index = 0;index < lines.length; index++) {
|
|
258
|
+
const open = /^\s*(`{3,})\s*([\w-]+)\s*$/.exec(lines[index]);
|
|
259
|
+
if (open?.[2] !== language) {
|
|
260
|
+
continue;
|
|
261
|
+
}
|
|
262
|
+
const close = new RegExp(`^\\s*${open[1]}\`*\\s*$`);
|
|
263
|
+
const end = lines.findIndex((line, at) => at > index && close.test(line));
|
|
264
|
+
found = lines.slice(index + 1, end < 0 ? lines.length : end);
|
|
265
|
+
index = end < 0 ? lines.length : end;
|
|
266
|
+
}
|
|
267
|
+
return found && parse(found);
|
|
268
|
+
}
|
|
269
|
+
BlockUtil.last = last;
|
|
270
|
+
function parse(lines) {
|
|
271
|
+
const rule = lines.findIndex((line) => line.trim() === "---");
|
|
272
|
+
const fields = {};
|
|
273
|
+
for (const line of rule < 0 ? [] : lines.slice(0, rule)) {
|
|
274
|
+
const field = /^\s*([\w-]+)\s*:\s*(.*)$/.exec(line);
|
|
275
|
+
const key = field?.[1].toLowerCase();
|
|
276
|
+
if (field && key && !(key in fields)) {
|
|
277
|
+
fields[key] = field[2].trim().replace(/^["'](.*)["']$/, "$1");
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
return {
|
|
281
|
+
fields,
|
|
282
|
+
body: lines.slice(rule + 1).join(`
|
|
283
|
+
`).trim()
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
})(BlockUtil ||= {});
|
|
287
|
+
|
|
178
288
|
// web-src/recall-protocol.ts
|
|
179
289
|
var NAME = "@celljs/ta-recall";
|
|
180
290
|
var TOOL_NAME = "search_conversations";
|
|
181
|
-
var PROPOSE_TOOL = "propose_skill";
|
|
182
291
|
var SKILL_TYPE = "ta-recall-skill";
|
|
183
|
-
var
|
|
292
|
+
var EXTENSION_TOOL = "propose_extension";
|
|
293
|
+
var EXTENSION_TYPE = "ta-recall-extension";
|
|
294
|
+
var EXTENSION_BLOCK = "ta-extension";
|
|
295
|
+
var EXTENSION_KINDS = ["steps", "board", "page", "command", "panel"];
|
|
184
296
|
var Keys;
|
|
185
297
|
((Keys) => {
|
|
186
298
|
Keys.SUGGEST = "suggest";
|
|
@@ -209,8 +321,156 @@ var Limits;
|
|
|
209
321
|
Limits.BRIEF_CONVERSATIONS = 30;
|
|
210
322
|
Limits.BRIEF_ITEMS = 5;
|
|
211
323
|
Limits.ASKED_ARCHIVE_DAYS = 7;
|
|
324
|
+
Limits.REQUEST_CONVERSATIONS = 80;
|
|
325
|
+
Limits.REQUEST_ASKS = 12;
|
|
326
|
+
Limits.REQUEST_CHARS = 300;
|
|
212
327
|
})(Limits ||= {});
|
|
213
328
|
|
|
329
|
+
// web-src/extension-util.ts
|
|
330
|
+
var FENCE = "```";
|
|
331
|
+
var NAME_CHARS = 64;
|
|
332
|
+
var TITLE_CHARS2 = 60;
|
|
333
|
+
var SUMMARY_CHARS = 300;
|
|
334
|
+
var ExtensionUtil;
|
|
335
|
+
((ExtensionUtil) => {
|
|
336
|
+
ExtensionUtil.KIND_HELP = {
|
|
337
|
+
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",
|
|
338
|
+
board: "a card of the board, to see at a glance: a status, a count, what is next",
|
|
339
|
+
page: "a page of its own: a table, a chart, a form the user fills in",
|
|
340
|
+
command: "a /command, or a button, that runs a fixed set of commands whose result needs no judgment",
|
|
341
|
+
panel: "a tool of the workbench beside the conversation, as the explorer or the terminal"
|
|
342
|
+
};
|
|
343
|
+
function find(text) {
|
|
344
|
+
const block = BlockUtil.last(text, EXTENSION_BLOCK);
|
|
345
|
+
if (!block?.body) {
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
const { name: name2 = "", title = "", kind = "", summary = "" } = block.fields;
|
|
349
|
+
return check({ name: name2, title, kind, summary, body: block.body });
|
|
350
|
+
}
|
|
351
|
+
ExtensionUtil.find = find;
|
|
352
|
+
function name(text) {
|
|
353
|
+
return text.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, NAME_CHARS).replace(/-+$/, "");
|
|
354
|
+
}
|
|
355
|
+
ExtensionUtil.name = name;
|
|
356
|
+
function check(draft) {
|
|
357
|
+
const body = typeof draft?.body === "string" ? draft.body.trim() : "";
|
|
358
|
+
if (!body) {
|
|
359
|
+
throw new Error("An extension needs a body: its steps, or the plan to make it by.");
|
|
360
|
+
}
|
|
361
|
+
const line = (value, chars) => (typeof value === "string" ? value : "").replace(/\s+/g, " ").trim().slice(0, chars);
|
|
362
|
+
const title = line(draft.title, TITLE_CHARS2);
|
|
363
|
+
const named = name(typeof draft.name === "string" ? draft.name : "") || name(title) || "extension";
|
|
364
|
+
const kind = EXTENSION_KINDS.includes(draft.kind) ? draft.kind : "steps";
|
|
365
|
+
return { name: named, title: title || named, kind, summary: line(draft.summary, SUMMARY_CHARS) || line(body.split(`
|
|
366
|
+
`)[0], 200), body };
|
|
367
|
+
}
|
|
368
|
+
ExtensionUtil.check = check;
|
|
369
|
+
function blockHelp() {
|
|
370
|
+
return [
|
|
371
|
+
`${FENCE}${EXTENSION_BLOCK}`,
|
|
372
|
+
"name: <lowercase-words-with-dashes, its directory>",
|
|
373
|
+
"title: <a few words, as the lists show it>",
|
|
374
|
+
`kind: <one of ${EXTENSION_KINDS.join(", ")}>`,
|
|
375
|
+
"summary: <one line: what it does, and when Ta uses it (steps) or where it shows>",
|
|
376
|
+
"---",
|
|
377
|
+
"<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>",
|
|
378
|
+
FENCE,
|
|
379
|
+
"Use a longer fence when the body has fences of its own. Write it in the language of the user."
|
|
380
|
+
].join(`
|
|
381
|
+
`);
|
|
382
|
+
}
|
|
383
|
+
ExtensionUtil.blockHelp = blockHelp;
|
|
384
|
+
function manifest(draft) {
|
|
385
|
+
const pkg = {
|
|
386
|
+
name: draft.name,
|
|
387
|
+
version: "0.1.0",
|
|
388
|
+
description: draft.summary,
|
|
389
|
+
pi: { title: draft.title, summary: draft.summary, icon: "ListChecks", skills: ["./skills"] }
|
|
390
|
+
};
|
|
391
|
+
return `${JSON.stringify(pkg, null, 2)}
|
|
392
|
+
`;
|
|
393
|
+
}
|
|
394
|
+
ExtensionUtil.manifest = manifest;
|
|
395
|
+
function skill(draft) {
|
|
396
|
+
return `---
|
|
397
|
+
name: ${draft.name}
|
|
398
|
+
description: ${JSON.stringify(draft.summary)}
|
|
399
|
+
---
|
|
400
|
+
|
|
401
|
+
${draft.body.trim()}
|
|
402
|
+
`;
|
|
403
|
+
}
|
|
404
|
+
ExtensionUtil.skill = skill;
|
|
405
|
+
function make(draft, language) {
|
|
406
|
+
const context = [
|
|
407
|
+
"[ta-recall:make]",
|
|
408
|
+
"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.",
|
|
409
|
+
`- name: ${draft.name}`,
|
|
410
|
+
`- title: ${draft.title}`,
|
|
411
|
+
`- kind: ${draft.kind} (${ExtensionUtil.KIND_HELP[draft.kind]})`,
|
|
412
|
+
`- summary: ${draft.summary}`,
|
|
413
|
+
"- plan:",
|
|
414
|
+
draft.body,
|
|
415
|
+
"- 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.",
|
|
416
|
+
"- Once it is made, say in one line where the user finds it."
|
|
417
|
+
].join(`
|
|
418
|
+
`);
|
|
419
|
+
const said = /^zh/i.test(language) ? `做出来:${draft.title}` : `Make it: ${draft.title}`;
|
|
420
|
+
return `<context>
|
|
421
|
+
${context}
|
|
422
|
+
</context>
|
|
423
|
+
${said}`;
|
|
424
|
+
}
|
|
425
|
+
ExtensionUtil.make = make;
|
|
426
|
+
})(ExtensionUtil ||= {});
|
|
427
|
+
|
|
428
|
+
// web-src/keep-util.ts
|
|
429
|
+
var PACKAGE_SKILL = "ta-package";
|
|
430
|
+
var TASK_SECTION = "ta-cron-keep";
|
|
431
|
+
var KeepUtil;
|
|
432
|
+
((KeepUtil) => {
|
|
433
|
+
function forms() {
|
|
434
|
+
const kinds = EXTENSION_KINDS.map((kind) => ` - ${kind}: ${ExtensionUtil.KIND_HELP[kind]}${kind === "steps" ? "" : `; only when the ${PACKAGE_SKILL} skill is among your skills`}`);
|
|
435
|
+
return [
|
|
436
|
+
`- As an extension of Ta, with ${EXTENSION_TOOL}, of the kind that fits:`,
|
|
437
|
+
...kinds,
|
|
438
|
+
` 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}:`,
|
|
439
|
+
ExtensionUtil.blockHelp(),
|
|
440
|
+
`- 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.`
|
|
441
|
+
].join(`
|
|
442
|
+
`);
|
|
443
|
+
}
|
|
444
|
+
KeepUtil.forms = forms;
|
|
445
|
+
function ask(language) {
|
|
446
|
+
const context = [
|
|
447
|
+
TA_KEEP_MARK,
|
|
448
|
+
"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:",
|
|
449
|
+
forms(),
|
|
450
|
+
"- 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.",
|
|
451
|
+
"- When the conversation holds nothing worth keeping, say so and offer nothing."
|
|
452
|
+
].join(`
|
|
453
|
+
`);
|
|
454
|
+
return `<context>
|
|
455
|
+
${context}
|
|
456
|
+
</context>
|
|
457
|
+
${/^zh/i.test(language) ? "把这个对话里的做法存下来" : "Keep how this was done"}`;
|
|
458
|
+
}
|
|
459
|
+
KeepUtil.ask = ask;
|
|
460
|
+
function hint(asks) {
|
|
461
|
+
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))}`);
|
|
462
|
+
return [
|
|
463
|
+
"The user asked for much the same in other conversations before:",
|
|
464
|
+
...lines,
|
|
465
|
+
"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:",
|
|
466
|
+
forms(),
|
|
467
|
+
"Offer nothing when it is not worth keeping."
|
|
468
|
+
].join(`
|
|
469
|
+
`);
|
|
470
|
+
}
|
|
471
|
+
KeepUtil.hint = hint;
|
|
472
|
+
})(KeepUtil ||= {});
|
|
473
|
+
|
|
214
474
|
// web-src/search-util.ts
|
|
215
475
|
var DAY_MS = 24 * 60 * 60000;
|
|
216
476
|
var PAIRS_CHARS = 1000;
|
|
@@ -343,107 +603,6 @@ var SimilarUtil;
|
|
|
343
603
|
SimilarUtil.find = find;
|
|
344
604
|
})(SimilarUtil ||= {});
|
|
345
605
|
|
|
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
606
|
// web-src/tool.ts
|
|
448
607
|
var RecallTool;
|
|
449
608
|
((RecallTool) => {
|
|
@@ -486,30 +645,41 @@ var RecallTool;
|
|
|
486
645
|
return at ? new Date(at).toISOString().slice(0, 16).replace("T", " ") : "";
|
|
487
646
|
}
|
|
488
647
|
})(RecallTool ||= {});
|
|
489
|
-
var
|
|
490
|
-
((
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
name:
|
|
494
|
-
label: "Propose
|
|
495
|
-
description: "Offers the user to keep
|
|
496
|
-
promptSnippet: "Offer to keep
|
|
497
|
-
promptGuidelines: [
|
|
648
|
+
var ExtensionTool;
|
|
649
|
+
((ExtensionTool) => {
|
|
650
|
+
ExtensionTool.NAME = EXTENSION_TOOL;
|
|
651
|
+
ExtensionTool.DEFINITION = {
|
|
652
|
+
name: ExtensionTool.NAME,
|
|
653
|
+
label: "Propose extension",
|
|
654
|
+
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.",
|
|
655
|
+
promptSnippet: "Offer to keep how something is done as an extension the user keeps from a card",
|
|
656
|
+
promptGuidelines: [
|
|
657
|
+
"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."
|
|
658
|
+
],
|
|
498
659
|
parameters: {
|
|
499
660
|
type: "object",
|
|
500
661
|
properties: {
|
|
501
|
-
name: { type: "string", description: "Lowercase words with dashes, as weekly-deps-upgrade." },
|
|
502
|
-
|
|
662
|
+
name: { type: "string", description: "Lowercase words with dashes, the directory of its package, as weekly-deps-upgrade." },
|
|
663
|
+
title: { type: "string", description: "A few words in the language of the user, as the lists show it." },
|
|
664
|
+
kind: {
|
|
665
|
+
type: "string",
|
|
666
|
+
enum: [...EXTENSION_KINDS],
|
|
667
|
+
description: EXTENSION_KINDS.map((kind) => `${kind}: ${ExtensionUtil.KIND_HELP[kind]}`).join("; ")
|
|
668
|
+
},
|
|
669
|
+
summary: {
|
|
670
|
+
type: "string",
|
|
671
|
+
description: "One line in the language of the user: what it does, and when Ta uses it (steps) or where it shows."
|
|
672
|
+
},
|
|
503
673
|
body: {
|
|
504
674
|
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."
|
|
675
|
+
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
676
|
}
|
|
507
677
|
},
|
|
508
|
-
required: ["name", "
|
|
678
|
+
required: ["name", "title", "kind", "summary", "body"]
|
|
509
679
|
}
|
|
510
680
|
};
|
|
511
|
-
|
|
512
|
-
})(
|
|
681
|
+
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.";
|
|
682
|
+
})(ExtensionTool ||= {});
|
|
513
683
|
|
|
514
684
|
// web-src/extension.ts
|
|
515
685
|
var BRIEF_MARK = "[ta-recall:brief]";
|
|
@@ -528,7 +698,7 @@ function activate(pi) {
|
|
|
528
698
|
asked = undefined;
|
|
529
699
|
draft = undefined;
|
|
530
700
|
briefing = false;
|
|
531
|
-
if (event.messageType === "custom" || typeof event.prompt !== "string" || ctx.getSystemPrompt?.()
|
|
701
|
+
if (event.messageType === "custom" || typeof event.prompt !== "string" || TaHostUtil.marked(ctx.getSystemPrompt?.(), TA_WITH_OTHERS_MARK)) {
|
|
532
702
|
return;
|
|
533
703
|
}
|
|
534
704
|
if (event.prompt.includes(BRIEF_MARK)) {
|
|
@@ -540,7 +710,7 @@ function activate(pi) {
|
|
|
540
710
|
try {
|
|
541
711
|
const similar = await (await reach())?.service?.similar(text, ctx.sessionManager.getSessionId()) ?? [];
|
|
542
712
|
if (similar.length) {
|
|
543
|
-
event.systemPromptOptions.sections = { ...event.systemPromptOptions.sections, [REPEAT_SECTION]:
|
|
713
|
+
event.systemPromptOptions.sections = { ...event.systemPromptOptions.sections, [REPEAT_SECTION]: KeepUtil.hint(similar) };
|
|
544
714
|
}
|
|
545
715
|
return;
|
|
546
716
|
} catch (error) {
|
|
@@ -549,28 +719,33 @@ function activate(pi) {
|
|
|
549
719
|
}
|
|
550
720
|
});
|
|
551
721
|
pi.on("context", (event) => {
|
|
552
|
-
const messages = event.messages.filter((message) => !(message.role === "custom" && message.customType === SKILL_TYPE));
|
|
722
|
+
const messages = event.messages.filter((message) => !(message.role === "custom" && (message.customType === SKILL_TYPE || message.customType === EXTENSION_TYPE)));
|
|
553
723
|
return messages.length === event.messages.length ? undefined : { messages };
|
|
554
724
|
});
|
|
555
725
|
pi.on("agent_end", (event, ctx) => {
|
|
556
726
|
const answer = [...event.messages ?? []].reverse().find((message) => message.role === "assistant");
|
|
557
|
-
const
|
|
727
|
+
const text = answer && answer.stopReason !== "aborted" ? ConversationUtil.textOf(answer.content) : "";
|
|
558
728
|
const file = ctx.sessionManager.getSessionFile();
|
|
559
|
-
if (briefing &&
|
|
560
|
-
const text = ConversationUtil.textOf(answer.content);
|
|
729
|
+
if (briefing && text && file) {
|
|
561
730
|
reach().then((reached2) => reached2?.service?.keepBrief(file, text)).catch((error) => console.error("ta-recall could not keep the brief:", error));
|
|
562
731
|
}
|
|
563
|
-
if (
|
|
564
|
-
|
|
732
|
+
if (!text || draft) {
|
|
733
|
+
return;
|
|
565
734
|
}
|
|
735
|
+
const found = ExtensionUtil.find(text);
|
|
736
|
+
draft = found && card(found, ctx);
|
|
566
737
|
});
|
|
567
738
|
pi.on("agent_settled", (event) => {
|
|
568
|
-
const
|
|
739
|
+
const left = draft;
|
|
569
740
|
draft = undefined;
|
|
570
|
-
if (
|
|
571
|
-
pi.sendMessage({ customType:
|
|
741
|
+
if (left && !event.aborted) {
|
|
742
|
+
pi.sendMessage({ customType: EXTENSION_TYPE, content: left.draft.title, display: true, details: left }, { triggerTurn: false });
|
|
572
743
|
}
|
|
573
744
|
});
|
|
745
|
+
const card = (found, ctx) => {
|
|
746
|
+
const session = ctx.sessionManager.getSessionId();
|
|
747
|
+
return { key: `${session}:${Date.now()}`, draft: found, session, ...asked ? { ask: asked } : {} };
|
|
748
|
+
};
|
|
574
749
|
const search = async (query, ctx) => {
|
|
575
750
|
const answer = await reach();
|
|
576
751
|
if (answer?.service) {
|
|
@@ -584,15 +759,17 @@ function activate(pi) {
|
|
|
584
759
|
return SearchUtil.search(await local.all(), query);
|
|
585
760
|
};
|
|
586
761
|
pi.registerTool({
|
|
587
|
-
...
|
|
762
|
+
...ExtensionTool.DEFINITION,
|
|
588
763
|
execute: async (_id, params, _signal, _update, ctx) => {
|
|
589
|
-
const checked =
|
|
764
|
+
const checked = ExtensionUtil.check({
|
|
590
765
|
name: String(params?.name ?? ""),
|
|
591
|
-
|
|
766
|
+
title: String(params?.title ?? ""),
|
|
767
|
+
kind: String(params?.kind ?? ""),
|
|
768
|
+
summary: String(params?.summary ?? ""),
|
|
592
769
|
body: typeof params?.body === "string" ? params.body : ""
|
|
593
770
|
});
|
|
594
|
-
draft =
|
|
595
|
-
return { content: [{ type: "text", text:
|
|
771
|
+
draft = card(checked, ctx);
|
|
772
|
+
return { content: [{ type: "text", text: ExtensionTool.RESULT }], details: { name: checked.name } };
|
|
596
773
|
}
|
|
597
774
|
});
|
|
598
775
|
pi.registerTool({
|