@celljs/ta-recall 0.0.0-stage → 4.11.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 +19 -0
- package/README.md +18 -2
- package/extension/index.mjs +614 -0
- package/host/index.mjs +820 -0
- package/package.json +53 -4
- package/web/index.js +1038 -0
package/web/index.js
ADDED
|
@@ -0,0 +1,1038 @@
|
|
|
1
|
+
// web-src/conversations.ts
|
|
2
|
+
var RecallConversations;
|
|
3
|
+
((RecallConversations) => {
|
|
4
|
+
async function open(pi, file) {
|
|
5
|
+
const open2 = (await pi.server.listSessions()).find((session) => session.sessionFile === file);
|
|
6
|
+
if (open2) {
|
|
7
|
+
await pi.switchSession(open2.sessionId);
|
|
8
|
+
pi.ui.showView("");
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
const saved = (await pi.server.listSavedSessions()).find((session) => session.sessionFile === file);
|
|
12
|
+
if (!saved) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
const sessionId = pi.server.openSession({ cwd: saved.cwd, sessionFile: file, ...saved.group ? { group: saved.group } : {} }).then((session) => session.sessionId);
|
|
16
|
+
await pi.switchSession(sessionId, { title: saved.sessionName || saved.firstMessage, cwd: saved.cwd, sessionFile: file });
|
|
17
|
+
pi.ui.showView("");
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
RecallConversations.open = open;
|
|
21
|
+
function question(text) {
|
|
22
|
+
return `<context>
|
|
23
|
+
[ta-recall:ask]
|
|
24
|
+
The user asks about their earlier work with Ta. Search their conversations with search_conversations (several words, in both languages they may have used), and git history when it is about code; answer briefly, and link the conversations you used as [title](session file).
|
|
25
|
+
</context>
|
|
26
|
+
${text}`;
|
|
27
|
+
}
|
|
28
|
+
RecallConversations.question = question;
|
|
29
|
+
async function ask(pi, text) {
|
|
30
|
+
const { cwd } = await pi.server.getServerInfo();
|
|
31
|
+
const opened = pi.server.openSession({ cwd });
|
|
32
|
+
const sessionId = opened.then((session) => session.sessionId);
|
|
33
|
+
const kept = opened.then((session) => session.sessionFile && pi.callHost("keepAsked", session.sessionFile)).catch(() => {
|
|
34
|
+
return;
|
|
35
|
+
});
|
|
36
|
+
await pi.switchSession(sessionId, { title: text, cwd });
|
|
37
|
+
pi.ui.showView("");
|
|
38
|
+
await kept;
|
|
39
|
+
await pi.server.prompt(await sessionId, { clientMessageId: `ta-recall-ask:${Date.now()}`, message: question(text) });
|
|
40
|
+
}
|
|
41
|
+
RecallConversations.ask = ask;
|
|
42
|
+
})(RecallConversations ||= {});
|
|
43
|
+
|
|
44
|
+
// web-src/i18n.ts
|
|
45
|
+
var en = {
|
|
46
|
+
settingsTitle: "Recall",
|
|
47
|
+
briefLabel: "Daily brief",
|
|
48
|
+
briefHint: "Each day at this time Ta writes what got done, what waits for you and what is next into the conversation Daily brief, when something happened.",
|
|
49
|
+
briefTime: "Time of the brief",
|
|
50
|
+
briefNow: "Write one now",
|
|
51
|
+
briefNowButton: "Write",
|
|
52
|
+
briefNothing: "Nothing happened since the last brief.",
|
|
53
|
+
suggestLabel: "Offer to keep as a skill",
|
|
54
|
+
suggestHint: "When you ask for something again that you asked for in another conversation, Ta offers to keep how it is done as a skill.",
|
|
55
|
+
skillAsk: "Keep as a skill?",
|
|
56
|
+
skillShow: "Show the steps",
|
|
57
|
+
skillHide: "Hide the steps",
|
|
58
|
+
skillSave: "Save as a skill",
|
|
59
|
+
skillNo: "No thanks",
|
|
60
|
+
skillSaved: "Saved as the skill {name}: new conversations use it, or type /skill:{name}.",
|
|
61
|
+
skillDeclined: "Not kept. Ta will not offer it again for the like.",
|
|
62
|
+
makeSkill: "Keep as a skill",
|
|
63
|
+
makeSkillDetail: "Ta writes how this was done as a skill to reuse",
|
|
64
|
+
searchTitle: "Ask Ta",
|
|
65
|
+
searchAsk: "Ask Ta: {query}",
|
|
66
|
+
searchAskDetail: "Ta looks through your conversations and answers, with where it found it",
|
|
67
|
+
briefCounts: "{done} done · {waiting} waiting for you",
|
|
68
|
+
briefCountsDone: "{done} done",
|
|
69
|
+
briefCardEmpty: "The first brief comes at {time}",
|
|
70
|
+
briefNoneWaiting: "Nothing waits for you",
|
|
71
|
+
briefTick: "Mark as handled",
|
|
72
|
+
briefUntick: "Mark as not handled",
|
|
73
|
+
briefMore: "{count} more in the brief",
|
|
74
|
+
briefToday: "Today",
|
|
75
|
+
toolSearch: "Search conversations",
|
|
76
|
+
toolPropose: "Draft a skill",
|
|
77
|
+
failed: "Could not do it: {message}"
|
|
78
|
+
};
|
|
79
|
+
var zh = {
|
|
80
|
+
settingsTitle: "回顾",
|
|
81
|
+
briefLabel: "每日简报",
|
|
82
|
+
briefHint: "每天这个时间,只要有新动静,Ta 就把做完的、等你定的和下一步写进“每日简报”对话。",
|
|
83
|
+
briefTime: "简报时间",
|
|
84
|
+
briefNow: "现在写一份",
|
|
85
|
+
briefNowButton: "生成",
|
|
86
|
+
briefNothing: "上次简报以来没有新的动静。",
|
|
87
|
+
suggestLabel: "建议存成技能",
|
|
88
|
+
suggestHint: "在别的对话里交代过的事又交代一次时,Ta 会问要不要把做法存成技能。",
|
|
89
|
+
skillAsk: "存成技能?",
|
|
90
|
+
skillShow: "查看步骤",
|
|
91
|
+
skillHide: "收起步骤",
|
|
92
|
+
skillSave: "保存为技能",
|
|
93
|
+
skillNo: "不用",
|
|
94
|
+
skillSaved: "已保存为技能 {name}:新对话会自动用上,也可以输入 /skill:{name}。",
|
|
95
|
+
skillDeclined: "没有保存,类似的事不会再问。",
|
|
96
|
+
makeSkill: "存成技能",
|
|
97
|
+
makeSkillDetail: "Ta 把这个对话里的做法写成技能,以后照着做",
|
|
98
|
+
searchTitle: "问 Ta",
|
|
99
|
+
searchAsk: "问 Ta:{query}",
|
|
100
|
+
searchAskDetail: "Ta 翻一遍你的对话再回答,并给出出处",
|
|
101
|
+
briefCounts: "做完 {done} · 等你定 {waiting}",
|
|
102
|
+
briefCountsDone: "做完 {done}",
|
|
103
|
+
briefCardEmpty: "每天 {time} 写第一份简报",
|
|
104
|
+
briefNoneWaiting: "没有等你定的事",
|
|
105
|
+
briefTick: "标为已处理",
|
|
106
|
+
briefUntick: "标为未处理",
|
|
107
|
+
briefMore: "简报里还有 {count} 项",
|
|
108
|
+
briefToday: "今天",
|
|
109
|
+
toolSearch: "搜索对话",
|
|
110
|
+
toolPropose: "起草技能",
|
|
111
|
+
failed: "没有做成:{message}"
|
|
112
|
+
};
|
|
113
|
+
var RecallWords;
|
|
114
|
+
((RecallWords) => {
|
|
115
|
+
function of(language) {
|
|
116
|
+
return /^zh/i.test(language) ? zh : en;
|
|
117
|
+
}
|
|
118
|
+
RecallWords.of = of;
|
|
119
|
+
function format(text, values) {
|
|
120
|
+
return text.replace(/\{(\w+)\}/g, (all, key) => values[key] ?? all);
|
|
121
|
+
}
|
|
122
|
+
RecallWords.format = format;
|
|
123
|
+
})(RecallWords ||= {});
|
|
124
|
+
|
|
125
|
+
// web-src/recall-protocol.ts
|
|
126
|
+
var TOOL_NAME = "search_conversations";
|
|
127
|
+
var PROPOSE_TOOL = "propose_skill";
|
|
128
|
+
var SKILL_TYPE = "ta-recall-skill";
|
|
129
|
+
var SKILL_BLOCK = "ta-skill";
|
|
130
|
+
var Keys;
|
|
131
|
+
((Keys) => {
|
|
132
|
+
Keys.SUGGEST = "suggest";
|
|
133
|
+
Keys.BRIEF = "brief";
|
|
134
|
+
Keys.BRIEF_FILE = "briefFile";
|
|
135
|
+
Keys.BRIEF_LAST = "briefLast";
|
|
136
|
+
Keys.ASKED = "asked";
|
|
137
|
+
Keys.BRIEF_SUMMARY = "briefSummary";
|
|
138
|
+
Keys.BRIEF_SEEN = "briefSeen";
|
|
139
|
+
Keys.BRIEF_PINNED = "briefPinned";
|
|
140
|
+
Keys.BRIEF_HANDLED = "briefHandled";
|
|
141
|
+
Keys.DECIDED = "decided";
|
|
142
|
+
Keys.DECLINED = "declined";
|
|
143
|
+
})(Keys ||= {});
|
|
144
|
+
var Limits;
|
|
145
|
+
((Limits) => {
|
|
146
|
+
Limits.SEARCH_DAYS = 30;
|
|
147
|
+
Limits.SEARCH_HITS = 8;
|
|
148
|
+
Limits.SNIPPETS = 3;
|
|
149
|
+
Limits.SNIPPET_CHARS = 240;
|
|
150
|
+
Limits.SIMILAR_DAYS = 60;
|
|
151
|
+
Limits.SIMILAR_MIN_CHARS = 16;
|
|
152
|
+
Limits.SIMILAR_SCORE = 0.5;
|
|
153
|
+
Limits.DECLINED_KEPT = 100;
|
|
154
|
+
Limits.ASKED_KEPT = 200;
|
|
155
|
+
Limits.BRIEF_CONVERSATIONS = 30;
|
|
156
|
+
Limits.BRIEF_ITEMS = 5;
|
|
157
|
+
Limits.ASKED_ARCHIVE_DAYS = 7;
|
|
158
|
+
})(Limits ||= {});
|
|
159
|
+
|
|
160
|
+
// web-src/brief-home.ts
|
|
161
|
+
var BriefHomeUtil;
|
|
162
|
+
((BriefHomeUtil) => {
|
|
163
|
+
function summary(value) {
|
|
164
|
+
const summary2 = value;
|
|
165
|
+
return summary2 && typeof summary2.at === "number" && typeof summary2.file === "string" ? summary2 : undefined;
|
|
166
|
+
}
|
|
167
|
+
BriefHomeUtil.summary = summary;
|
|
168
|
+
function handled(value, summary2) {
|
|
169
|
+
const stored = value;
|
|
170
|
+
return summary2 && stored && stored.at === summary2.at && Array.isArray(stored.done) ? stored.done.filter((at) => typeof at === "number") : [];
|
|
171
|
+
}
|
|
172
|
+
BriefHomeUtil.handled = handled;
|
|
173
|
+
function left(summary2, done) {
|
|
174
|
+
if (!summary2.items) {
|
|
175
|
+
return { waiting: summary2.waiting, top: summary2.top };
|
|
176
|
+
}
|
|
177
|
+
const ticked = done.filter((at) => at < (summary2.items?.length ?? 0)).length;
|
|
178
|
+
return { waiting: Math.max(0, summary2.waiting - ticked), top: summary2.items.find((_, at) => !done.includes(at))?.text };
|
|
179
|
+
}
|
|
180
|
+
BriefHomeUtil.left = left;
|
|
181
|
+
function detail(summary2, language, done = []) {
|
|
182
|
+
const words = RecallWords.of(language);
|
|
183
|
+
const { waiting, top } = left(summary2, done);
|
|
184
|
+
const counts = RecallWords.format(waiting ? words.briefCounts : words.briefCountsDone, {
|
|
185
|
+
done: String(summary2.done),
|
|
186
|
+
waiting: String(waiting)
|
|
187
|
+
});
|
|
188
|
+
return top && waiting ? `${counts} · ${top}` : counts;
|
|
189
|
+
}
|
|
190
|
+
BriefHomeUtil.detail = detail;
|
|
191
|
+
})(BriefHomeUtil ||= {});
|
|
192
|
+
var KEYS = [Keys.BRIEF_SUMMARY, Keys.BRIEF_SEEN, Keys.BRIEF_HANDLED];
|
|
193
|
+
|
|
194
|
+
class BriefStore {
|
|
195
|
+
pi;
|
|
196
|
+
current = { loaded: false, seen: 0, done: [] };
|
|
197
|
+
listeners = new Set;
|
|
198
|
+
constructor(pi) {
|
|
199
|
+
this.pi = pi;
|
|
200
|
+
this.read();
|
|
201
|
+
pi.storage.onChange((keys) => keys.some((key) => KEYS.includes(key)) && this.read());
|
|
202
|
+
}
|
|
203
|
+
get state() {
|
|
204
|
+
return this.current;
|
|
205
|
+
}
|
|
206
|
+
subscribe(listener) {
|
|
207
|
+
this.listeners.add(listener);
|
|
208
|
+
return () => this.listeners.delete(listener);
|
|
209
|
+
}
|
|
210
|
+
async open(item) {
|
|
211
|
+
const { summary } = this.current;
|
|
212
|
+
if (!summary) {
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
this.see();
|
|
216
|
+
if (!item?.file || !await RecallConversations.open(this.pi, item.file)) {
|
|
217
|
+
await RecallConversations.open(this.pi, summary.file);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
async tick(at, done) {
|
|
221
|
+
const { summary } = this.current;
|
|
222
|
+
if (!summary) {
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
const others = this.current.done.filter((one) => one !== at);
|
|
226
|
+
const next = done ? [...others, at].sort((a, b) => a - b) : others;
|
|
227
|
+
this.set({ ...this.current, done: next });
|
|
228
|
+
this.see();
|
|
229
|
+
await this.pi.storage.set(Keys.BRIEF_HANDLED, { at: summary.at, done: next });
|
|
230
|
+
}
|
|
231
|
+
see() {
|
|
232
|
+
const { summary, seen } = this.current;
|
|
233
|
+
if (summary && summary.at > seen) {
|
|
234
|
+
this.set({ ...this.current, seen: summary.at });
|
|
235
|
+
this.pi.storage.set(Keys.BRIEF_SEEN, summary.at).catch(() => {
|
|
236
|
+
return;
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
read() {
|
|
241
|
+
Promise.all(KEYS.map((key) => this.pi.storage.get(key))).then(([stored, seen, handled]) => {
|
|
242
|
+
const summary = BriefHomeUtil.summary(stored);
|
|
243
|
+
this.set({ loaded: true, summary, seen: typeof seen === "number" ? seen : 0, done: BriefHomeUtil.handled(handled, summary) });
|
|
244
|
+
}, () => this.set({ ...this.current, loaded: true }));
|
|
245
|
+
}
|
|
246
|
+
set(state) {
|
|
247
|
+
this.current = state;
|
|
248
|
+
for (const listener of this.listeners) {
|
|
249
|
+
listener();
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
function briefHome(pi, store) {
|
|
254
|
+
let items = [];
|
|
255
|
+
let built;
|
|
256
|
+
return {
|
|
257
|
+
items: () => {
|
|
258
|
+
const state = store.state;
|
|
259
|
+
if (state !== built) {
|
|
260
|
+
built = state;
|
|
261
|
+
const icon = pi.ui.icons.ScrollText;
|
|
262
|
+
const { summary } = state;
|
|
263
|
+
items = summary && icon ? [
|
|
264
|
+
{
|
|
265
|
+
id: "brief",
|
|
266
|
+
title: RecallWords.of(pi.ui.language).briefLabel,
|
|
267
|
+
detail: BriefHomeUtil.detail(summary, pi.ui.language, state.done),
|
|
268
|
+
icon,
|
|
269
|
+
tint: "daily-brief",
|
|
270
|
+
at: summary.at,
|
|
271
|
+
unseen: summary.at > state.seen,
|
|
272
|
+
open: () => store.open()
|
|
273
|
+
}
|
|
274
|
+
] : [];
|
|
275
|
+
}
|
|
276
|
+
return items;
|
|
277
|
+
},
|
|
278
|
+
subscribe: (listener) => store.subscribe(listener)
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// web-src/brief-util.ts
|
|
283
|
+
var DAY_MS = 24 * 60 * 60000;
|
|
284
|
+
var ASKS = 3;
|
|
285
|
+
var ASK_CHARS = 160;
|
|
286
|
+
var ANSWER_CHARS = 500;
|
|
287
|
+
var SUMMARY_CHARS = 300;
|
|
288
|
+
var BriefUtil;
|
|
289
|
+
((BriefUtil) => {
|
|
290
|
+
BriefUtil.DEFAULT = { enabled: true, time: "09:00" };
|
|
291
|
+
function settings(value) {
|
|
292
|
+
const stored = value && typeof value === "object" ? value : {};
|
|
293
|
+
return {
|
|
294
|
+
enabled: typeof stored.enabled === "boolean" ? stored.enabled : BriefUtil.DEFAULT.enabled,
|
|
295
|
+
time: typeof stored.time === "string" && parseTime(stored.time) ? stored.time : BriefUtil.DEFAULT.time
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
BriefUtil.settings = settings;
|
|
299
|
+
function parseTime(text) {
|
|
300
|
+
const match = /^(\d{1,2}):(\d{2})$/.exec(text.trim());
|
|
301
|
+
if (!match) {
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
const hours = Number(match[1]);
|
|
305
|
+
const minutes = Number(match[2]);
|
|
306
|
+
return hours < 24 && minutes < 60 ? { hours, minutes } : undefined;
|
|
307
|
+
}
|
|
308
|
+
BriefUtil.parseTime = parseTime;
|
|
309
|
+
function today(settings2, now) {
|
|
310
|
+
const { hours, minutes } = parseTime(settings2.time) ?? { hours: 9, minutes: 0 };
|
|
311
|
+
const day = new Date(now);
|
|
312
|
+
day.setHours(hours, minutes, 0, 0);
|
|
313
|
+
return day.getTime();
|
|
314
|
+
}
|
|
315
|
+
BriefUtil.today = today;
|
|
316
|
+
function due(settings2, last, now) {
|
|
317
|
+
const time = today(settings2, now);
|
|
318
|
+
return settings2.enabled && now >= time && (last === undefined || last < time);
|
|
319
|
+
}
|
|
320
|
+
BriefUtil.due = due;
|
|
321
|
+
function since(last, now) {
|
|
322
|
+
return last && last > now - 7 * DAY_MS ? last : now - DAY_MS;
|
|
323
|
+
}
|
|
324
|
+
BriefUtil.since = since;
|
|
325
|
+
function material(input) {
|
|
326
|
+
const conversations = input.conversations.filter((conversation) => conversation.updatedAt >= input.since && conversation.file !== input.briefFile).slice(0, Limits.BRIEF_CONVERSATIONS);
|
|
327
|
+
const parts = [];
|
|
328
|
+
if (conversations.length > 0) {
|
|
329
|
+
parts.push("Conversations:");
|
|
330
|
+
for (const conversation of conversations) {
|
|
331
|
+
parts.push(...conversationLines(conversation, input.since, input.states?.get(conversation.file)));
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
const waiting = (input.notices ?? []).filter((notice) => notice.at >= input.since && (notice.level === "ask" || notice.level === "failed"));
|
|
335
|
+
if (waiting.length > 0) {
|
|
336
|
+
parts.push("", "Notices of the time (asks and failures):");
|
|
337
|
+
for (const notice of waiting) {
|
|
338
|
+
parts.push(`- ${notice.level}: ${line(notice.text, ASK_CHARS)}${notice.title ? ` (in "${notice.title}"${notice.sessionFile ? `, ${notice.sessionFile}` : ""})` : ""}`);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
const runs = (input.runs ?? []).filter((run) => run.at >= input.since);
|
|
342
|
+
if (runs.length > 0) {
|
|
343
|
+
parts.push("", "Scheduled tasks that ran:");
|
|
344
|
+
for (const run of runs) {
|
|
345
|
+
parts.push(`- ${run.name}: ${run.status ?? "ran"}${run.summary ? ` — ${line(run.summary, SUMMARY_CHARS)}` : ""}`);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
return parts.join(`
|
|
349
|
+
`);
|
|
350
|
+
}
|
|
351
|
+
BriefUtil.material = material;
|
|
352
|
+
function conversationLines(conversation, since2, state) {
|
|
353
|
+
const recent = conversation.said.filter((said) => said.at >= since2);
|
|
354
|
+
const asks = recent.filter((said) => said.role === "user" && !/^\/\S+$/.test(said.text)).slice(-ASKS);
|
|
355
|
+
const answer = [...recent].reverse().find((said) => said.role === "assistant");
|
|
356
|
+
const now = state?.waiting ? " · waits for the user" : state?.streaming ? " · still working" : "";
|
|
357
|
+
const where = conversation.group ? `${conversation.cwd} · of ${conversation.group}` : conversation.cwd;
|
|
358
|
+
return [
|
|
359
|
+
`- [${conversation.title || "Untitled"}](${conversation.file}) · ${where}${now}`,
|
|
360
|
+
...asks.map((ask) => ` - asked: ${line(ask.text, ASK_CHARS)}`),
|
|
361
|
+
...answer ? [` - last answer: ${line(answer.text, ANSWER_CHARS)}`] : []
|
|
362
|
+
];
|
|
363
|
+
}
|
|
364
|
+
function line(text, chars) {
|
|
365
|
+
const flat = text.replace(/\s+/g, " ").trim();
|
|
366
|
+
return flat.length > chars ? `${flat.slice(0, chars)}…` : flat;
|
|
367
|
+
}
|
|
368
|
+
BriefUtil.HEADINGS = { zh: ["做完了", "等你定", "下一步"], en: ["Done", "Waiting for you", "Next"] };
|
|
369
|
+
const PARTS = {
|
|
370
|
+
做完了: "done",
|
|
371
|
+
done: "done",
|
|
372
|
+
等你定: "waiting",
|
|
373
|
+
"waiting for you": "waiting",
|
|
374
|
+
下一步: "next",
|
|
375
|
+
next: "next"
|
|
376
|
+
};
|
|
377
|
+
function summary(text, file, at) {
|
|
378
|
+
const counts = { done: 0, waiting: 0, next: 0 };
|
|
379
|
+
let part;
|
|
380
|
+
let found = false;
|
|
381
|
+
let top;
|
|
382
|
+
const items = [];
|
|
383
|
+
for (const line2 of text.split(/\r?\n/)) {
|
|
384
|
+
const heading = /^\s*#{1,6}\s+(.+?)\s*#*\s*$/.exec(line2) ?? /^\s*\*\*(.+?)\*\*\s*[::]?\s*$/.exec(line2);
|
|
385
|
+
if (heading) {
|
|
386
|
+
part = PARTS[heading[1].replace(/[::]$/, "").trim().toLowerCase()];
|
|
387
|
+
found ||= !!part;
|
|
388
|
+
continue;
|
|
389
|
+
}
|
|
390
|
+
const item = /^\s*(?:[-*+]|\d+[.)])\s+(.+)$/.exec(line2);
|
|
391
|
+
if (part && item) {
|
|
392
|
+
counts[part]++;
|
|
393
|
+
if (part === "waiting") {
|
|
394
|
+
top ??= plain(item[1]);
|
|
395
|
+
if (items.length < Limits.BRIEF_ITEMS) {
|
|
396
|
+
items.push(briefItem(item[1]));
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
return found ? { at, file, ...counts, ...top ? { top } : {}, ...items.length ? { items } : {} } : undefined;
|
|
402
|
+
}
|
|
403
|
+
BriefUtil.summary = summary;
|
|
404
|
+
function briefItem(line2) {
|
|
405
|
+
const link = /\]\(<?([^)>]+?\.jsonl)>?\)/.exec(line2);
|
|
406
|
+
return { text: plain(line2), ...link ? { file: link[1].trim() } : {} };
|
|
407
|
+
}
|
|
408
|
+
function plain(text) {
|
|
409
|
+
return text.replace(/!?\[([^\]]*)\]\([^)]*\)/g, "$1").replace(/[*_`~]+/g, "").replace(/\s+/g, " ").trim().slice(0, 160);
|
|
410
|
+
}
|
|
411
|
+
BriefUtil.plain = plain;
|
|
412
|
+
function message(material2, since2, zh2) {
|
|
413
|
+
const heads = zh2 ? BriefUtil.HEADINGS.zh : BriefUtil.HEADINGS.en;
|
|
414
|
+
const context = [
|
|
415
|
+
"[ta-recall:brief]",
|
|
416
|
+
`Write the daily brief of the user from what happened since ${new Date(since2).toISOString()}, below, in ${zh2 ? "Chinese" : "English"}. Short, for a phone: up to three parts, each a heading of level 3 with exactly these words, then a list of one line each (Ta counts them),`,
|
|
417
|
+
`- ### ${heads[0]}: what got done;`,
|
|
418
|
+
`- ### ${heads[1]}: what waits for a decision of the user, failed or was left half done, and what they should do, the most pressing first;`,
|
|
419
|
+
`- ### ${heads[2]}: two or three concrete next steps.`,
|
|
420
|
+
"Each line links its conversation as [title](session file). Leave out a part with nothing in it, small talk, and this conversation itself. Use no tools unless something must be checked.",
|
|
421
|
+
"",
|
|
422
|
+
material2
|
|
423
|
+
].join(`
|
|
424
|
+
`);
|
|
425
|
+
return `<context>
|
|
426
|
+
${context}
|
|
427
|
+
</context>
|
|
428
|
+
${zh2 ? "写今天的简报" : "Write today's brief"}`;
|
|
429
|
+
}
|
|
430
|
+
BriefUtil.message = message;
|
|
431
|
+
})(BriefUtil ||= {});
|
|
432
|
+
|
|
433
|
+
// web-src/react.ts
|
|
434
|
+
var React;
|
|
435
|
+
function bind(react) {
|
|
436
|
+
React = react;
|
|
437
|
+
}
|
|
438
|
+
var idle = () => [false, async (action) => await action()];
|
|
439
|
+
function useBusy(ui) {
|
|
440
|
+
return (ui.useBusy ?? idle)();
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
// web-src/stored.ts
|
|
444
|
+
function useStored(pi, key, parse) {
|
|
445
|
+
const [value, setValue] = React.useState(() => parse(undefined));
|
|
446
|
+
React.useEffect(() => {
|
|
447
|
+
let live = true;
|
|
448
|
+
const read = () => void pi.storage.get(key).then((stored) => live && setValue(parse(stored)), () => {
|
|
449
|
+
return;
|
|
450
|
+
});
|
|
451
|
+
read();
|
|
452
|
+
const stop = pi.storage.onChange((keys) => keys.includes(key) && read());
|
|
453
|
+
return () => {
|
|
454
|
+
live = false;
|
|
455
|
+
stop();
|
|
456
|
+
};
|
|
457
|
+
}, [pi, key, parse]);
|
|
458
|
+
const set = React.useCallback((next) => {
|
|
459
|
+
setValue(next);
|
|
460
|
+
return pi.storage.set(key, next);
|
|
461
|
+
}, [pi, key]);
|
|
462
|
+
return [value, set];
|
|
463
|
+
}
|
|
464
|
+
function message(error) {
|
|
465
|
+
return error instanceof Error ? error.message : String(error);
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
// web-src/brief-card.tsx
|
|
469
|
+
var SHOWN = 3;
|
|
470
|
+
var BriefCardUtil;
|
|
471
|
+
((BriefCardUtil) => {
|
|
472
|
+
function lines(state, shown = SHOWN) {
|
|
473
|
+
const items = (state.summary?.items ?? []).map((item, at) => ({ item, at, done: state.done.includes(at) }));
|
|
474
|
+
return [...items.filter((line) => !line.done), ...items.filter((line) => line.done)].slice(0, shown);
|
|
475
|
+
}
|
|
476
|
+
BriefCardUtil.lines = lines;
|
|
477
|
+
function when(at, now, language) {
|
|
478
|
+
const date = new Date(at);
|
|
479
|
+
const time = date.toLocaleTimeString(language, { hour: "2-digit", minute: "2-digit", hour12: false });
|
|
480
|
+
const today = new Date(now).toDateString() === date.toDateString();
|
|
481
|
+
const day = today ? RecallWords.of(language).briefToday : date.toLocaleDateString(language, { month: "numeric", day: "numeric" });
|
|
482
|
+
return `${day} ${time}`;
|
|
483
|
+
}
|
|
484
|
+
BriefCardUtil.when = when;
|
|
485
|
+
})(BriefCardUtil ||= {});
|
|
486
|
+
function briefCard(pi, store) {
|
|
487
|
+
return function BriefCard() {
|
|
488
|
+
const state = React.useSyncExternalStore((listener) => store.subscribe(listener), () => store.state);
|
|
489
|
+
const [settings] = useStored(pi, Keys.BRIEF, BriefUtil.settings);
|
|
490
|
+
const words = RecallWords.of(pi.ui.language);
|
|
491
|
+
const { summary } = state;
|
|
492
|
+
if (!state.loaded) {
|
|
493
|
+
return /* @__PURE__ */ React.createElement(pi.ui.Skeleton, {
|
|
494
|
+
rows: 2
|
|
495
|
+
});
|
|
496
|
+
}
|
|
497
|
+
if (!summary) {
|
|
498
|
+
return /* @__PURE__ */ React.createElement(pi.ui.Empty, {
|
|
499
|
+
title: RecallWords.format(words.briefCardEmpty, { time: settings.time }),
|
|
500
|
+
compact: true
|
|
501
|
+
});
|
|
502
|
+
}
|
|
503
|
+
const Check = pi.ui.icons.Check;
|
|
504
|
+
const Chevron = pi.ui.icons.ChevronRight;
|
|
505
|
+
const { waiting } = BriefHomeUtil.left(summary, state.done);
|
|
506
|
+
const counts = RecallWords.format(waiting ? words.briefCounts : words.briefCountsDone, { done: String(summary.done), waiting: String(waiting) });
|
|
507
|
+
const lines = BriefCardUtil.lines(state);
|
|
508
|
+
const more = summary.waiting - lines.length;
|
|
509
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
510
|
+
className: "tar-brief-card"
|
|
511
|
+
}, /* @__PURE__ */ React.createElement("button", {
|
|
512
|
+
type: "button",
|
|
513
|
+
className: "tar-brief-meta",
|
|
514
|
+
onClick: () => void store.open()
|
|
515
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
516
|
+
className: "tar-brief-when"
|
|
517
|
+
}, BriefCardUtil.when(summary.at, Date.now(), pi.ui.language)), /* @__PURE__ */ React.createElement("span", {
|
|
518
|
+
className: "tar-brief-counts"
|
|
519
|
+
}, counts), Chevron && /* @__PURE__ */ React.createElement(Chevron, {
|
|
520
|
+
size: 14,
|
|
521
|
+
strokeWidth: 2
|
|
522
|
+
})), lines.length > 0 ? /* @__PURE__ */ React.createElement("ul", {
|
|
523
|
+
className: "tar-brief-lines"
|
|
524
|
+
}, lines.map(({ item, at, done }) => /* @__PURE__ */ React.createElement("li", {
|
|
525
|
+
key: at,
|
|
526
|
+
className: "tar-brief-line",
|
|
527
|
+
"data-done": done ? "" : undefined
|
|
528
|
+
}, /* @__PURE__ */ React.createElement("button", {
|
|
529
|
+
type: "button",
|
|
530
|
+
className: "tar-brief-tick",
|
|
531
|
+
"aria-pressed": done,
|
|
532
|
+
"aria-label": done ? words.briefUntick : words.briefTick,
|
|
533
|
+
title: done ? words.briefUntick : words.briefTick,
|
|
534
|
+
onClick: () => void store.tick(at, !done).catch(() => {
|
|
535
|
+
return;
|
|
536
|
+
})
|
|
537
|
+
}, done && Check && /* @__PURE__ */ React.createElement(Check, {
|
|
538
|
+
size: 11,
|
|
539
|
+
strokeWidth: 3
|
|
540
|
+
})), /* @__PURE__ */ React.createElement("button", {
|
|
541
|
+
type: "button",
|
|
542
|
+
className: "tar-brief-text",
|
|
543
|
+
onClick: () => void store.open(item)
|
|
544
|
+
}, item.text)))) : summary.waiting === 0 && /* @__PURE__ */ React.createElement("div", {
|
|
545
|
+
className: "tar-brief-none"
|
|
546
|
+
}, words.briefNoneWaiting), more > 0 && /* @__PURE__ */ React.createElement("button", {
|
|
547
|
+
type: "button",
|
|
548
|
+
className: "tar-brief-more",
|
|
549
|
+
onClick: () => void store.open()
|
|
550
|
+
}, RecallWords.format(words.briefMore, { count: String(more) })));
|
|
551
|
+
};
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
// web-src/chat-icons.ts
|
|
555
|
+
async function pinOnce(pi, file) {
|
|
556
|
+
if (!pi.ui.pinChat || await pi.storage.get(Keys.BRIEF_PINNED).catch(() => file) === file) {
|
|
557
|
+
return;
|
|
558
|
+
}
|
|
559
|
+
await pi.storage.set(Keys.BRIEF_PINNED, file);
|
|
560
|
+
pi.ui.pinChat(file);
|
|
561
|
+
}
|
|
562
|
+
function chatIcons(pi) {
|
|
563
|
+
let brief;
|
|
564
|
+
let asked = new Set;
|
|
565
|
+
const listeners = new Set;
|
|
566
|
+
const read = () => void Promise.all([pi.storage.get(Keys.BRIEF_FILE), pi.storage.get(Keys.ASKED)]).then(([file, files]) => {
|
|
567
|
+
brief = typeof file === "string" && file ? file : undefined;
|
|
568
|
+
if (brief) {
|
|
569
|
+
pinOnce(pi, brief);
|
|
570
|
+
}
|
|
571
|
+
asked = new Set(Array.isArray(files) ? files.filter((item) => typeof item === "string") : []);
|
|
572
|
+
for (const listener of listeners) {
|
|
573
|
+
listener();
|
|
574
|
+
}
|
|
575
|
+
}, () => {
|
|
576
|
+
return;
|
|
577
|
+
});
|
|
578
|
+
read();
|
|
579
|
+
pi.storage.onChange((keys) => (keys.includes(Keys.BRIEF_FILE) || keys.includes(Keys.ASKED)) && read());
|
|
580
|
+
return {
|
|
581
|
+
icon: (chat) => {
|
|
582
|
+
if (!chat.sessionFile) {
|
|
583
|
+
return;
|
|
584
|
+
}
|
|
585
|
+
if (chat.sessionFile === brief) {
|
|
586
|
+
return pi.ui.icons.ScrollText && { icon: pi.ui.icons.ScrollText, tint: "daily-brief" };
|
|
587
|
+
}
|
|
588
|
+
return asked.has(chat.sessionFile) && pi.ui.icons.Sparkles ? { icon: pi.ui.icons.Sparkles, tint: "ask-ta", archiveDays: Limits.ASKED_ARCHIVE_DAYS } : undefined;
|
|
589
|
+
},
|
|
590
|
+
subscribe: (listener) => {
|
|
591
|
+
listeners.add(listener);
|
|
592
|
+
return () => listeners.delete(listener);
|
|
593
|
+
}
|
|
594
|
+
};
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
// web-src/brief-seen.tsx
|
|
598
|
+
var seenOf = (value) => typeof value === "number" ? value : 0;
|
|
599
|
+
function briefSeen(pi) {
|
|
600
|
+
return function BriefSeen({ conversation }) {
|
|
601
|
+
const [summary] = useStored(pi, Keys.BRIEF_SUMMARY, BriefHomeUtil.summary);
|
|
602
|
+
const [seen, setSeen] = useStored(pi, Keys.BRIEF_SEEN, seenOf);
|
|
603
|
+
const here = !!summary && summary.at > seen && !!conversation.sessionFile && conversation.sessionFile === summary.file;
|
|
604
|
+
React.useEffect(() => {
|
|
605
|
+
if (here && summary) {
|
|
606
|
+
setSeen(summary.at).catch(() => {
|
|
607
|
+
return;
|
|
608
|
+
});
|
|
609
|
+
}
|
|
610
|
+
}, [here, summary, setSeen]);
|
|
611
|
+
return null;
|
|
612
|
+
};
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
// web-src/skill-util.ts
|
|
616
|
+
var FENCE = "```";
|
|
617
|
+
var NAME_CHARS = 64;
|
|
618
|
+
var DESCRIPTION_CHARS = 1024;
|
|
619
|
+
var SkillUtil;
|
|
620
|
+
((SkillUtil) => {
|
|
621
|
+
function find(text) {
|
|
622
|
+
const lines = text.split(/\r?\n/);
|
|
623
|
+
let found;
|
|
624
|
+
for (let index = 0;index < lines.length; index++) {
|
|
625
|
+
const open = /^\s*(`{3,})\s*([\w-]+)\s*$/.exec(lines[index]);
|
|
626
|
+
if (open?.[2] !== SKILL_BLOCK) {
|
|
627
|
+
continue;
|
|
628
|
+
}
|
|
629
|
+
const close = new RegExp(`^\\s*${open[1]}\`*\\s*$`);
|
|
630
|
+
const end = lines.findIndex((line, at) => at > index && close.test(line));
|
|
631
|
+
found = lines.slice(index + 1, end < 0 ? lines.length : end);
|
|
632
|
+
index = end < 0 ? lines.length : end;
|
|
633
|
+
}
|
|
634
|
+
return found && parse(found);
|
|
635
|
+
}
|
|
636
|
+
SkillUtil.find = find;
|
|
637
|
+
function parse(lines) {
|
|
638
|
+
const rule = lines.findIndex((line) => line.trim() === "---");
|
|
639
|
+
const head = rule < 0 ? [] : lines.slice(0, rule);
|
|
640
|
+
const body = lines.slice(rule + 1).join(`
|
|
641
|
+
`).trim();
|
|
642
|
+
if (!body) {
|
|
643
|
+
return;
|
|
644
|
+
}
|
|
645
|
+
const field = (key) => head.map((line) => new RegExp(`^\\s*${key}\\s*:\\s*(.*)$`, "i").exec(line)?.[1].trim().replace(/^["'](.*)["']$/, "$1")).find((value) => value !== undefined);
|
|
646
|
+
const description = (field("description") ?? "").replace(/\s+/g, " ").slice(0, DESCRIPTION_CHARS);
|
|
647
|
+
return { name: name(field("name") ?? "") || name(description) || "skill", description, body };
|
|
648
|
+
}
|
|
649
|
+
function name(text) {
|
|
650
|
+
return text.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, NAME_CHARS).replace(/-+$/, "");
|
|
651
|
+
}
|
|
652
|
+
SkillUtil.name = name;
|
|
653
|
+
function check(draft) {
|
|
654
|
+
const body = typeof draft?.body === "string" ? draft.body.trim() : "";
|
|
655
|
+
if (!body) {
|
|
656
|
+
throw new Error("A skill needs a body.");
|
|
657
|
+
}
|
|
658
|
+
const description = (typeof draft.description === "string" ? draft.description : "").replace(/\s+/g, " ").trim().slice(0, DESCRIPTION_CHARS);
|
|
659
|
+
return { name: name(typeof draft.name === "string" ? draft.name : "") || "skill", description: description || body.split(`
|
|
660
|
+
`)[0].slice(0, 200), body };
|
|
661
|
+
}
|
|
662
|
+
SkillUtil.check = check;
|
|
663
|
+
function markdown(draft) {
|
|
664
|
+
return `---
|
|
665
|
+
name: ${draft.name}
|
|
666
|
+
description: ${JSON.stringify(draft.description)}
|
|
667
|
+
---
|
|
668
|
+
|
|
669
|
+
${draft.body.trim()}
|
|
670
|
+
`;
|
|
671
|
+
}
|
|
672
|
+
SkillUtil.markdown = markdown;
|
|
673
|
+
function blockHelp() {
|
|
674
|
+
return [
|
|
675
|
+
`${FENCE}${SKILL_BLOCK}`,
|
|
676
|
+
"name: <lowercase-words-with-dashes>",
|
|
677
|
+
"description: <one line: what it does and when to use it>",
|
|
678
|
+
"---",
|
|
679
|
+
"<the body: the goal, then the steps, commands, files and checks that worked, in general terms, without what held only this once>",
|
|
680
|
+
FENCE,
|
|
681
|
+
"Use a longer fence when the body has fences of its own. Write it in the language of the user."
|
|
682
|
+
].join(`
|
|
683
|
+
`);
|
|
684
|
+
}
|
|
685
|
+
SkillUtil.blockHelp = blockHelp;
|
|
686
|
+
function hint(asks) {
|
|
687
|
+
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))}`);
|
|
688
|
+
return [
|
|
689
|
+
"The user asked for much the same in other conversations before:",
|
|
690
|
+
...lines,
|
|
691
|
+
`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:`,
|
|
692
|
+
blockHelp(),
|
|
693
|
+
"Offer nothing when it is not worth keeping."
|
|
694
|
+
].join(`
|
|
695
|
+
`);
|
|
696
|
+
}
|
|
697
|
+
SkillUtil.hint = hint;
|
|
698
|
+
function ask(language) {
|
|
699
|
+
const context = [
|
|
700
|
+
"[ta-recall:skill]",
|
|
701
|
+
"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.",
|
|
702
|
+
"- 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.",
|
|
703
|
+
`- 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}:`,
|
|
704
|
+
blockHelp(),
|
|
705
|
+
"- When the conversation holds no way of working worth keeping, say so and draft nothing."
|
|
706
|
+
].join(`
|
|
707
|
+
`);
|
|
708
|
+
return `<context>
|
|
709
|
+
${context}
|
|
710
|
+
</context>
|
|
711
|
+
${/^zh/i.test(language) ? "把这个对话里的做法存成技能" : "Keep how this was done as a skill"}`;
|
|
712
|
+
}
|
|
713
|
+
SkillUtil.ask = ask;
|
|
714
|
+
})(SkillUtil ||= {});
|
|
715
|
+
|
|
716
|
+
// web-src/composer.tsx
|
|
717
|
+
function composerAddon(pi) {
|
|
718
|
+
return {
|
|
719
|
+
above: briefSeen(pi),
|
|
720
|
+
actions: (conversation) => {
|
|
721
|
+
const words = RecallWords.of(pi.ui.language);
|
|
722
|
+
const Sparkles = pi.ui.icons.Sparkles;
|
|
723
|
+
return [
|
|
724
|
+
{
|
|
725
|
+
key: "make-skill",
|
|
726
|
+
label: words.makeSkill,
|
|
727
|
+
detail: words.makeSkillDetail,
|
|
728
|
+
icon: Sparkles ? /* @__PURE__ */ React.createElement(Sparkles, {
|
|
729
|
+
size: 16
|
|
730
|
+
}) : undefined,
|
|
731
|
+
run: () => void pi.server.prompt(conversation.sessionId, {
|
|
732
|
+
clientMessageId: `ta-recall-skill:${Date.now()}`,
|
|
733
|
+
message: SkillUtil.ask(pi.ui.language),
|
|
734
|
+
streamingBehavior: "followUp"
|
|
735
|
+
}).catch((error) => pi.ui.notify(RecallWords.format(words.failed, { message: message(error) }), "error"))
|
|
736
|
+
}
|
|
737
|
+
];
|
|
738
|
+
}
|
|
739
|
+
};
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
// web-src/search-source.ts
|
|
743
|
+
var DAYS = 90;
|
|
744
|
+
var HITS = 6;
|
|
745
|
+
function recallSearch(pi) {
|
|
746
|
+
const words = () => RecallWords.of(pi.ui.language);
|
|
747
|
+
const notify = (error) => pi.ui.notify(RecallWords.format(words().failed, { message: error instanceof Error ? error.message : String(error) }), "error");
|
|
748
|
+
return {
|
|
749
|
+
key: "ta-recall",
|
|
750
|
+
title: () => words().searchTitle,
|
|
751
|
+
order: 40,
|
|
752
|
+
remote: true,
|
|
753
|
+
async search(query, offset) {
|
|
754
|
+
const text = query.trim();
|
|
755
|
+
if (!text || offset > 0) {
|
|
756
|
+
return { items: [] };
|
|
757
|
+
}
|
|
758
|
+
const ask = {
|
|
759
|
+
key: "ask",
|
|
760
|
+
title: RecallWords.format(words().searchAsk, { query: text }),
|
|
761
|
+
detail: words().searchAskDetail,
|
|
762
|
+
icon: pi.ui.icons.Sparkles,
|
|
763
|
+
open: () => RecallConversations.ask(pi, text).catch(notify)
|
|
764
|
+
};
|
|
765
|
+
const hits = await pi.callHost("search", { query: text, all: true, days: DAYS, limit: HITS }).catch(() => []);
|
|
766
|
+
return {
|
|
767
|
+
items: [
|
|
768
|
+
ask,
|
|
769
|
+
...hits.map((hit) => ({
|
|
770
|
+
key: hit.file,
|
|
771
|
+
title: hit.title || hit.file.split("/").pop() || hit.file,
|
|
772
|
+
detail: hit.snippets.at(-1)?.text,
|
|
773
|
+
icon: pi.ui.icons.MessageSquareText,
|
|
774
|
+
open: () => RecallConversations.open(pi, hit.file).catch(notify)
|
|
775
|
+
}))
|
|
776
|
+
]
|
|
777
|
+
};
|
|
778
|
+
}
|
|
779
|
+
};
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
// web-src/settings.tsx
|
|
783
|
+
var suggests = (value) => value !== false;
|
|
784
|
+
function notifyFailure(pi, error) {
|
|
785
|
+
pi.ui.notify(RecallWords.format(RecallWords.of(pi.ui.language).failed, { message: message(error) }), "error");
|
|
786
|
+
}
|
|
787
|
+
function Toggle({ pi, checked, label, onChange }) {
|
|
788
|
+
const Switch = pi.ui.Switch;
|
|
789
|
+
if (Switch) {
|
|
790
|
+
return /* @__PURE__ */ React.createElement(Switch, {
|
|
791
|
+
checked,
|
|
792
|
+
label,
|
|
793
|
+
onChange: (on) => onChange(on).catch((error) => notifyFailure(pi, error))
|
|
794
|
+
});
|
|
795
|
+
}
|
|
796
|
+
return /* @__PURE__ */ React.createElement("input", {
|
|
797
|
+
type: "checkbox",
|
|
798
|
+
role: "switch",
|
|
799
|
+
className: "ta-switch",
|
|
800
|
+
checked,
|
|
801
|
+
"aria-checked": checked,
|
|
802
|
+
"aria-label": label,
|
|
803
|
+
onChange: (event) => void onChange(event.target.checked).catch((error) => notifyFailure(pi, error))
|
|
804
|
+
});
|
|
805
|
+
}
|
|
806
|
+
function BriefSwitch({ pi }) {
|
|
807
|
+
const words = RecallWords.of(pi.ui.language);
|
|
808
|
+
const [brief, setBrief] = useStored(pi, Keys.BRIEF, BriefUtil.settings);
|
|
809
|
+
return /* @__PURE__ */ React.createElement(Toggle, {
|
|
810
|
+
pi,
|
|
811
|
+
checked: brief.enabled,
|
|
812
|
+
label: words.briefLabel,
|
|
813
|
+
onChange: (enabled) => setBrief({ ...brief, enabled })
|
|
814
|
+
});
|
|
815
|
+
}
|
|
816
|
+
function BriefTime({ pi }) {
|
|
817
|
+
const words = RecallWords.of(pi.ui.language);
|
|
818
|
+
const [brief, setBrief] = useStored(pi, Keys.BRIEF, BriefUtil.settings);
|
|
819
|
+
const change = (time) => {
|
|
820
|
+
if (BriefUtil.parseTime(time)) {
|
|
821
|
+
setBrief({ ...brief, time }).catch((error) => notifyFailure(pi, error));
|
|
822
|
+
}
|
|
823
|
+
};
|
|
824
|
+
return /* @__PURE__ */ React.createElement("input", {
|
|
825
|
+
type: "time",
|
|
826
|
+
className: "tar-time",
|
|
827
|
+
"aria-label": words.briefTime,
|
|
828
|
+
value: brief.time,
|
|
829
|
+
disabled: !brief.enabled,
|
|
830
|
+
onChange: (event) => change(event.target.value)
|
|
831
|
+
});
|
|
832
|
+
}
|
|
833
|
+
function BriefNow({ pi }) {
|
|
834
|
+
const words = RecallWords.of(pi.ui.language);
|
|
835
|
+
const [busy, run] = useBusy(pi.ui);
|
|
836
|
+
const write = async () => {
|
|
837
|
+
try {
|
|
838
|
+
const file = await pi.callHost("briefNow");
|
|
839
|
+
if (!file) {
|
|
840
|
+
pi.ui.notify(words.briefNothing, "info");
|
|
841
|
+
} else if (!await RecallConversations.open(pi, file)) {
|
|
842
|
+
pi.ui.notify(words.briefLabel, "info");
|
|
843
|
+
}
|
|
844
|
+
} catch (error) {
|
|
845
|
+
notifyFailure(pi, error);
|
|
846
|
+
}
|
|
847
|
+
};
|
|
848
|
+
return /* @__PURE__ */ React.createElement("button", {
|
|
849
|
+
type: "button",
|
|
850
|
+
className: `ta-button${busy ? " ta-busy" : ""}`,
|
|
851
|
+
disabled: busy,
|
|
852
|
+
onClick: () => void run(write)
|
|
853
|
+
}, busy && /* @__PURE__ */ React.createElement("span", {
|
|
854
|
+
className: "ta-spinner ta-busy-mark"
|
|
855
|
+
}), /* @__PURE__ */ React.createElement("span", null, words.briefNowButton));
|
|
856
|
+
}
|
|
857
|
+
function SuggestSwitch({ pi }) {
|
|
858
|
+
const words = RecallWords.of(pi.ui.language);
|
|
859
|
+
const [on, setOn] = useStored(pi, Keys.SUGGEST, suggests);
|
|
860
|
+
return /* @__PURE__ */ React.createElement(Toggle, {
|
|
861
|
+
pi,
|
|
862
|
+
checked: on,
|
|
863
|
+
label: words.suggestLabel,
|
|
864
|
+
onChange: setOn
|
|
865
|
+
});
|
|
866
|
+
}
|
|
867
|
+
function recallSettings(pi) {
|
|
868
|
+
const words = () => RecallWords.of(pi.ui.language);
|
|
869
|
+
return {
|
|
870
|
+
title: () => words().settingsTitle,
|
|
871
|
+
icon: pi.ui.icons.ScrollText,
|
|
872
|
+
rows: [
|
|
873
|
+
{ key: "brief", label: () => words().briefLabel, description: () => words().briefHint, render: () => /* @__PURE__ */ React.createElement(BriefSwitch, {
|
|
874
|
+
pi
|
|
875
|
+
}) },
|
|
876
|
+
{ key: "brief-time", label: () => words().briefTime, render: () => /* @__PURE__ */ React.createElement(BriefTime, {
|
|
877
|
+
pi
|
|
878
|
+
}) },
|
|
879
|
+
{ key: "brief-now", label: () => words().briefNow, render: () => /* @__PURE__ */ React.createElement(BriefNow, {
|
|
880
|
+
pi
|
|
881
|
+
}) },
|
|
882
|
+
{ key: "suggest", label: () => words().suggestLabel, description: () => words().suggestHint, render: () => /* @__PURE__ */ React.createElement(SuggestSwitch, {
|
|
883
|
+
pi
|
|
884
|
+
}) }
|
|
885
|
+
]
|
|
886
|
+
};
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
// web-src/skill-card.tsx
|
|
890
|
+
function decisions(value) {
|
|
891
|
+
return value && typeof value === "object" ? value : {};
|
|
892
|
+
}
|
|
893
|
+
function skillCard(pi) {
|
|
894
|
+
return function SkillCardView({ message: custom }) {
|
|
895
|
+
const words = RecallWords.of(pi.ui.language);
|
|
896
|
+
const [decided] = useStored(pi, Keys.DECIDED, decisions);
|
|
897
|
+
const [open, setOpen] = React.useState(false);
|
|
898
|
+
const [saving, save] = useBusy(pi.ui);
|
|
899
|
+
const [declining, decline] = useBusy(pi.ui);
|
|
900
|
+
const card = custom.details;
|
|
901
|
+
if (!card?.draft?.body) {
|
|
902
|
+
return null;
|
|
903
|
+
}
|
|
904
|
+
const decision = decided[card.key];
|
|
905
|
+
const Sparkles = pi.ui.icons.Sparkles;
|
|
906
|
+
const Markdown = pi.ui.Markdown;
|
|
907
|
+
const run = (action) => action().catch((error) => pi.ui.notify(RecallWords.format(words.failed, { message: message(error) }), "error"));
|
|
908
|
+
const busy = saving || declining;
|
|
909
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
910
|
+
className: "tar-skill"
|
|
911
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
912
|
+
className: "tar-skill-head"
|
|
913
|
+
}, Sparkles && /* @__PURE__ */ React.createElement(Sparkles, {
|
|
914
|
+
size: 14
|
|
915
|
+
}), /* @__PURE__ */ React.createElement("span", null, words.skillAsk)), /* @__PURE__ */ React.createElement("div", {
|
|
916
|
+
className: "tar-skill-title"
|
|
917
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
918
|
+
className: "tar-skill-name"
|
|
919
|
+
}, card.draft.name)), card.draft.description && /* @__PURE__ */ React.createElement("div", {
|
|
920
|
+
className: "tar-skill-description"
|
|
921
|
+
}, card.draft.description), /* @__PURE__ */ React.createElement("button", {
|
|
922
|
+
type: "button",
|
|
923
|
+
className: "tar-skill-toggle",
|
|
924
|
+
"aria-expanded": open,
|
|
925
|
+
onClick: () => setOpen(!open)
|
|
926
|
+
}, open ? words.skillHide : words.skillShow), open && /* @__PURE__ */ React.createElement("div", {
|
|
927
|
+
className: "tar-skill-body"
|
|
928
|
+
}, /* @__PURE__ */ React.createElement(Markdown, {
|
|
929
|
+
text: card.draft.body
|
|
930
|
+
})), decision && "saved" in decision ? /* @__PURE__ */ React.createElement("div", {
|
|
931
|
+
className: "tar-skill-done tar-saved"
|
|
932
|
+
}, RecallWords.format(words.skillSaved, { name: decision.name })) : decision ? /* @__PURE__ */ React.createElement("div", {
|
|
933
|
+
className: "tar-skill-done"
|
|
934
|
+
}, words.skillDeclined) : /* @__PURE__ */ React.createElement("div", {
|
|
935
|
+
className: "tar-skill-actions"
|
|
936
|
+
}, /* @__PURE__ */ React.createElement("button", {
|
|
937
|
+
type: "button",
|
|
938
|
+
className: `ta-button ta-primary${saving ? " ta-busy" : ""}`,
|
|
939
|
+
disabled: busy,
|
|
940
|
+
onClick: () => void save(() => run(() => pi.callHost("saveSkill", card.key, card.draft)))
|
|
941
|
+
}, saving && /* @__PURE__ */ React.createElement("span", {
|
|
942
|
+
className: "ta-spinner ta-busy-mark ta-on-brand"
|
|
943
|
+
}), /* @__PURE__ */ React.createElement("span", null, words.skillSave)), /* @__PURE__ */ React.createElement("button", {
|
|
944
|
+
type: "button",
|
|
945
|
+
className: `ta-button${declining ? " ta-busy" : ""}`,
|
|
946
|
+
disabled: busy,
|
|
947
|
+
onClick: () => void decline(() => run(() => pi.callHost("declineSkill", card.key, card.ask)))
|
|
948
|
+
}, declining && /* @__PURE__ */ React.createElement("span", {
|
|
949
|
+
className: "ta-spinner ta-busy-mark"
|
|
950
|
+
}), /* @__PURE__ */ React.createElement("span", null, words.skillNo))));
|
|
951
|
+
};
|
|
952
|
+
}
|
|
953
|
+
|
|
954
|
+
// web-src/style.ts
|
|
955
|
+
var STYLE = `
|
|
956
|
+
/* A draft skill in its conversation, to save with a tap */
|
|
957
|
+
.tar-skill { margin: 4px 0; padding: 10px 12px; border: 1px solid var(--ta-border-muted); border-radius: 10px; background: var(--ta-card); font-size: calc(13px * var(--ta-font-scale)); max-width: 620px; }
|
|
958
|
+
.tar-skill-head { display: flex; align-items: center; gap: 6px; color: var(--ta-muted); font-size: calc(12px * var(--ta-font-scale)); }
|
|
959
|
+
.tar-skill-title { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
|
|
960
|
+
.tar-skill-name { font-family: var(--ta-font-mono, ui-monospace, SFMono-Regular, Menlo, monospace); font-size: calc(13px * var(--ta-font-scale)); font-weight: 600; color: var(--ta-text); overflow-wrap: anywhere; }
|
|
961
|
+
.tar-skill-description { margin-top: 4px; color: var(--ta-text); line-height: 1.55; overflow-wrap: anywhere; }
|
|
962
|
+
.tar-skill-toggle { margin-top: 6px; padding: 0; border: 0; background: none; color: var(--ta-muted); font: inherit; font-size: calc(12px * var(--ta-font-scale)); cursor: pointer; }
|
|
963
|
+
.tar-skill-toggle:hover { color: var(--ta-text); }
|
|
964
|
+
.tar-skill-body { margin-top: 6px; max-height: 280px; overflow: auto; padding: 2px 10px; border-radius: 8px; background: var(--ta-hover); font-size: calc(12px * var(--ta-font-scale)); }
|
|
965
|
+
.tar-skill-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
|
|
966
|
+
.tar-skill-done { margin-top: 8px; color: var(--ta-muted); font-size: calc(12px * var(--ta-font-scale)); line-height: 1.5; overflow-wrap: anywhere; }
|
|
967
|
+
.tar-skill-done.tar-saved { color: var(--ta-green); }
|
|
968
|
+
[data-touch] .tar-skill-actions .ta-button { min-height: 38px; }
|
|
969
|
+
/* The card of the daily brief on the board: its time and counts, then the lines that wait, each ticked off by its circle */
|
|
970
|
+
.tar-brief-card { display: flex; flex-direction: column; margin: -4px -6px; }
|
|
971
|
+
.tar-brief-meta { display: flex; align-items: center; gap: 8px; min-height: 30px; padding: 0 6px; border: 0; border-radius: 8px; background: none; color: var(--ta-muted); font: inherit; font-size: calc(12.5px * var(--ta-font-scale)); text-align: left; cursor: pointer; }
|
|
972
|
+
.tar-brief-meta:hover { background: var(--ta-hover); color: var(--ta-text); }
|
|
973
|
+
.tar-brief-when { flex: none; font-variant-numeric: tabular-nums; }
|
|
974
|
+
.tar-brief-counts { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
975
|
+
.tar-brief-lines { margin: 2px 0 0; padding: 0; list-style: none; }
|
|
976
|
+
.tar-brief-line { display: flex; align-items: center; gap: 2px; min-height: 36px; }
|
|
977
|
+
.tar-brief-tick { flex: none; display: grid; place-items: center; width: 32px; height: 36px; padding: 0; border: 0; background: none; color: var(--ta-main); cursor: pointer; -webkit-tap-highlight-color: transparent; }
|
|
978
|
+
.tar-brief-tick::before { content: ''; grid-area: 1 / 1; width: 16px; height: 16px; border-radius: 50%; box-shadow: inset 0 0 0 1.5px var(--ta-border-field); transition: background 140ms, box-shadow 140ms; }
|
|
979
|
+
.tar-brief-tick:hover::before { box-shadow: inset 0 0 0 1.5px var(--ta-muted); }
|
|
980
|
+
.tar-brief-tick > svg { grid-area: 1 / 1; position: relative; }
|
|
981
|
+
.tar-brief-line[data-done] .tar-brief-tick::before { background: var(--ta-green); box-shadow: none; }
|
|
982
|
+
.tar-brief-text { flex: 1; min-width: 0; min-height: 36px; padding: 0 6px 0 2px; border: 0; border-radius: 8px; background: none; color: var(--ta-text); font: inherit; font-size: calc(14px * var(--ta-font-scale)); text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
|
|
983
|
+
.tar-brief-text:hover { background: var(--ta-hover); }
|
|
984
|
+
.tar-brief-line[data-done] .tar-brief-text { color: var(--ta-muted); text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--ta-muted) 60%, transparent); }
|
|
985
|
+
.tar-brief-none { padding: 6px 6px 2px; color: var(--ta-muted); font-size: calc(13px * var(--ta-font-scale)); }
|
|
986
|
+
.tar-brief-more { align-self: flex-start; margin-top: 2px; padding: 4px 6px; border: 0; border-radius: 8px; background: none; color: var(--ta-muted); font: inherit; font-size: calc(12.5px * var(--ta-font-scale)); cursor: pointer; }
|
|
987
|
+
.tar-brief-more:hover { background: var(--ta-hover); color: var(--ta-text); }
|
|
988
|
+
.tar-time { height: 32px; padding: 0 8px; border: 1px solid var(--ta-border-field); border-radius: 8px; background: transparent; color: var(--ta-text); font: inherit; font-size: calc(13px * var(--ta-font-scale)); }
|
|
989
|
+
`;
|
|
990
|
+
function injectStyle() {
|
|
991
|
+
const element = document.createElement("style");
|
|
992
|
+
element.dataset.taPackage = "ta-recall";
|
|
993
|
+
element.textContent = STYLE;
|
|
994
|
+
document.head.appendChild(element);
|
|
995
|
+
return () => element.remove();
|
|
996
|
+
}
|
|
997
|
+
|
|
998
|
+
// web-src/tool-line.ts
|
|
999
|
+
var RecallToolLine;
|
|
1000
|
+
((RecallToolLine) => {
|
|
1001
|
+
function renderCall(args, t) {
|
|
1002
|
+
return { verb: t("toolSearch"), target: typeof args.query === "string" ? args.query.trim() : "" };
|
|
1003
|
+
}
|
|
1004
|
+
RecallToolLine.renderCall = renderCall;
|
|
1005
|
+
function renderPropose(args, t) {
|
|
1006
|
+
return { verb: t("toolPropose"), target: typeof args.name === "string" ? args.name.trim() : "" };
|
|
1007
|
+
}
|
|
1008
|
+
RecallToolLine.renderPropose = renderPropose;
|
|
1009
|
+
function register(pi, t) {
|
|
1010
|
+
pi.registerToolRenderer?.((name, next) => name === TOOL_NAME ? { renderCall: (args) => renderCall(args, t) } : name === PROPOSE_TOOL ? { renderCall: (args) => renderPropose(args, t) } : next());
|
|
1011
|
+
}
|
|
1012
|
+
RecallToolLine.register = register;
|
|
1013
|
+
})(RecallToolLine ||= {});
|
|
1014
|
+
|
|
1015
|
+
// web-src/index.tsx
|
|
1016
|
+
function activate(pi) {
|
|
1017
|
+
bind(pi.React);
|
|
1018
|
+
const removeStyle = injectStyle();
|
|
1019
|
+
pi.registerSettings(recallSettings(pi));
|
|
1020
|
+
pi.registerMessageRenderer(SKILL_TYPE, skillCard(pi));
|
|
1021
|
+
pi.registerComposerAddon(composerAddon(pi));
|
|
1022
|
+
pi.registerSearch(recallSearch(pi));
|
|
1023
|
+
pi.registerChatIcon?.(chatIcons(pi));
|
|
1024
|
+
const brief = new BriefStore(pi);
|
|
1025
|
+
pi.registerHomeItems?.(briefHome(pi, brief));
|
|
1026
|
+
pi.registerView("brief", {
|
|
1027
|
+
title: () => RecallWords.of(pi.ui.language).briefLabel,
|
|
1028
|
+
icon: pi.ui.icons.ScrollText,
|
|
1029
|
+
location: "board",
|
|
1030
|
+
order: 5,
|
|
1031
|
+
render: briefCard(pi, brief)
|
|
1032
|
+
});
|
|
1033
|
+
RecallToolLine.register(pi, (key) => RecallWords.of(pi.ui.language)[key]);
|
|
1034
|
+
return removeStyle;
|
|
1035
|
+
}
|
|
1036
|
+
export {
|
|
1037
|
+
activate as default
|
|
1038
|
+
};
|