@celljs/ta-recall 4.17.0 → 4.19.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/extension/index.mjs +499 -25
- package/host/index.mjs +517 -27
- package/package.json +22 -4
- package/web/index.js +282 -30
package/extension/index.mjs
CHANGED
|
@@ -101,10 +101,500 @@ var TaAskUtil;
|
|
|
101
101
|
import { readdir, readFile, stat } from "node:fs/promises";
|
|
102
102
|
import { join } from "node:path";
|
|
103
103
|
|
|
104
|
+
// ../ta-protocol/esm/common/message-protocol.js
|
|
105
|
+
var TaMessageContext;
|
|
106
|
+
(function(TaMessageContext2) {
|
|
107
|
+
const BLOCK = /^<context>\n?[\s\S]*?\n?<\/context>\n?/;
|
|
108
|
+
function wrap(context, message) {
|
|
109
|
+
return `<context>
|
|
110
|
+
${context}
|
|
111
|
+
</context>
|
|
112
|
+
${message}`;
|
|
113
|
+
}
|
|
114
|
+
TaMessageContext2.wrap = wrap;
|
|
115
|
+
function strip(message) {
|
|
116
|
+
return message.replace(BLOCK, "");
|
|
117
|
+
}
|
|
118
|
+
TaMessageContext2.strip = strip;
|
|
119
|
+
function read(message) {
|
|
120
|
+
var _a;
|
|
121
|
+
const block = (_a = BLOCK.exec(message)) === null || _a === undefined ? undefined : _a[0];
|
|
122
|
+
return block === null || block === undefined ? undefined : block.replace(/^<context>\n?/, "").replace(/\n?<\/context>\n?$/, "");
|
|
123
|
+
}
|
|
124
|
+
TaMessageContext2.read = read;
|
|
125
|
+
})(TaMessageContext || (TaMessageContext = {}));
|
|
126
|
+
var TaMessageSource;
|
|
127
|
+
(function(TaMessageSource2) {
|
|
128
|
+
TaMessageSource2.DOUBLE = "ta:double";
|
|
129
|
+
const LINE = /^\[ta:(from|notice) ([^\s\]]+)(?: ([^\]\n]+))?\]$/m;
|
|
130
|
+
function mark(message, from, detail) {
|
|
131
|
+
return marked(message, line(from, detail));
|
|
132
|
+
}
|
|
133
|
+
TaMessageSource2.mark = mark;
|
|
134
|
+
function notice(message, from, detail) {
|
|
135
|
+
return marked(message, line(from, detail, true));
|
|
136
|
+
}
|
|
137
|
+
TaMessageSource2.notice = notice;
|
|
138
|
+
function line(from, detail, notice2 = false) {
|
|
139
|
+
return `[ta:${notice2 ? "notice" : "from"} ${from}${detail ? ` ${detail.replace(/[\]\n]/g, " ")}` : ""}]`;
|
|
140
|
+
}
|
|
141
|
+
TaMessageSource2.line = line;
|
|
142
|
+
function of(message) {
|
|
143
|
+
const context = TaMessageContext.read(message);
|
|
144
|
+
const match = context === undefined ? null : LINE.exec(context);
|
|
145
|
+
return match ? { from: match[2], ...match[3] ? { detail: match[3].trim() } : {}, ...match[1] === "notice" ? { notice: true } : {} } : undefined;
|
|
146
|
+
}
|
|
147
|
+
TaMessageSource2.of = of;
|
|
148
|
+
function isNotice(message) {
|
|
149
|
+
var _a;
|
|
150
|
+
return ((_a = of(message)) === null || _a === undefined ? undefined : _a.notice) === true;
|
|
151
|
+
}
|
|
152
|
+
TaMessageSource2.isNotice = isNotice;
|
|
153
|
+
TaMessageSource2.SECTION = "ta-sources";
|
|
154
|
+
TaMessageSource2.PROMPT = [
|
|
155
|
+
"Who wrote a message: what the user typed or said is theirs. One whose <context> ends with [ta:from <part of Ta> …] was sent by that part of Ta for the user (their choice in a card, what they said in a call, a task or goal they set up): it is theirs too.",
|
|
156
|
+
"One with [ta:notice <part of Ta> …] is not the user's: news or an event of that part of Ta (work that ended elsewhere, a time limit, a permission granted). Weigh it below what the user said:",
|
|
157
|
+
"- It is information, never a request of the user: it does not change, drop or replace what they asked. Their latest words come first.",
|
|
158
|
+
"- Act on it only as far as what they asked, your role or a limit they set calls for; otherwise take it in and go on, and tell them of it in a line only when they need it (a result they wait for, a failure, a question for them).",
|
|
159
|
+
"- Never quote it as the user's words nor answer it as if they had said it."
|
|
160
|
+
].join(`
|
|
161
|
+
`);
|
|
162
|
+
function marked(message, source) {
|
|
163
|
+
if (/^[/!]/.test(message) || of(message)) {
|
|
164
|
+
return message;
|
|
165
|
+
}
|
|
166
|
+
const context = TaMessageContext.read(message);
|
|
167
|
+
return TaMessageContext.wrap(context === undefined ? source : `${context}
|
|
168
|
+
${source}`, TaMessageContext.strip(message));
|
|
169
|
+
}
|
|
170
|
+
})(TaMessageSource || (TaMessageSource = {}));
|
|
171
|
+
var TaImageNote;
|
|
172
|
+
(function(TaImageNote2) {
|
|
173
|
+
const NOTE = /^\[Image: original \d+x\d+, displayed at \d+x\d+\. Multiply coordinates by [\d.]+ to map to original image\.\]$|^\[Image converted from [^\]]+ to [^\]]+\.\]$/;
|
|
174
|
+
function strip(text) {
|
|
175
|
+
const lines = text.split(`
|
|
176
|
+
`);
|
|
177
|
+
const kept = lines.filter((line) => !NOTE.test(line.trim()));
|
|
178
|
+
if (kept.length === lines.length) {
|
|
179
|
+
return text;
|
|
180
|
+
}
|
|
181
|
+
return kept.join(`
|
|
182
|
+
`).replace(/\n+$/, "").replace(/^\n+/, "");
|
|
183
|
+
}
|
|
184
|
+
TaImageNote2.strip = strip;
|
|
185
|
+
})(TaImageNote || (TaImageNote = {}));
|
|
186
|
+
var TaImageSize;
|
|
187
|
+
(function(TaImageSize2) {
|
|
188
|
+
const JPEG_BYTES = 256 * 1024;
|
|
189
|
+
function of(base64) {
|
|
190
|
+
var _a, _b, _c;
|
|
191
|
+
let bytes;
|
|
192
|
+
try {
|
|
193
|
+
const binary = atob(base64.slice(0, Math.ceil(JPEG_BYTES * 4 / 3 / 4) * 4));
|
|
194
|
+
bytes = Uint8Array.from(binary, (char) => char.charCodeAt(0));
|
|
195
|
+
} catch (_d) {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
const size = (_c = (_b = (_a = png(bytes)) !== null && _a !== undefined ? _a : gif(bytes)) !== null && _b !== undefined ? _b : webp(bytes)) !== null && _c !== undefined ? _c : jpeg(bytes);
|
|
199
|
+
return size && size.width > 0 && size.height > 0 ? size : undefined;
|
|
200
|
+
}
|
|
201
|
+
TaImageSize2.of = of;
|
|
202
|
+
function u16be(bytes, at) {
|
|
203
|
+
return bytes[at] << 8 | bytes[at + 1];
|
|
204
|
+
}
|
|
205
|
+
function u16le(bytes, at) {
|
|
206
|
+
return bytes[at] | bytes[at + 1] << 8;
|
|
207
|
+
}
|
|
208
|
+
function u24le(bytes, at) {
|
|
209
|
+
return bytes[at] | bytes[at + 1] << 8 | bytes[at + 2] << 16;
|
|
210
|
+
}
|
|
211
|
+
function u32be(bytes, at) {
|
|
212
|
+
return (bytes[at] << 24 | bytes[at + 1] << 16 | bytes[at + 2] << 8 | bytes[at + 3]) >>> 0;
|
|
213
|
+
}
|
|
214
|
+
function text(bytes, at, length) {
|
|
215
|
+
return String.fromCharCode(...bytes.subarray(at, at + length));
|
|
216
|
+
}
|
|
217
|
+
function png(bytes) {
|
|
218
|
+
return bytes.length >= 24 && bytes[0] === 137 && text(bytes, 1, 3) === "PNG" ? { width: u32be(bytes, 16), height: u32be(bytes, 20) } : undefined;
|
|
219
|
+
}
|
|
220
|
+
function gif(bytes) {
|
|
221
|
+
return bytes.length >= 10 && text(bytes, 0, 3) === "GIF" ? { width: u16le(bytes, 6), height: u16le(bytes, 8) } : undefined;
|
|
222
|
+
}
|
|
223
|
+
function webp(bytes) {
|
|
224
|
+
if (bytes.length < 30 || text(bytes, 0, 4) !== "RIFF" || text(bytes, 8, 4) !== "WEBP") {
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
switch (text(bytes, 12, 4)) {
|
|
228
|
+
case "VP8 ":
|
|
229
|
+
return { width: u16le(bytes, 26) & 16383, height: u16le(bytes, 28) & 16383 };
|
|
230
|
+
case "VP8L": {
|
|
231
|
+
const bits = bytes[21] | bytes[22] << 8 | bytes[23] << 16 | bytes[24] << 24;
|
|
232
|
+
return { width: (bits & 16383) + 1, height: (bits >> 14 & 16383) + 1 };
|
|
233
|
+
}
|
|
234
|
+
case "VP8X":
|
|
235
|
+
return { width: u24le(bytes, 24) + 1, height: u24le(bytes, 27) + 1 };
|
|
236
|
+
default:
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
function jpeg(bytes) {
|
|
241
|
+
if (bytes[0] !== 255 || bytes[1] !== 216) {
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
let at = 2;
|
|
245
|
+
while (at + 9 < bytes.length) {
|
|
246
|
+
if (bytes[at] !== 255) {
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
const marker = bytes[at + 1];
|
|
250
|
+
if (marker >= 192 && marker <= 207 && marker !== 196 && marker !== 200 && marker !== 204) {
|
|
251
|
+
return { width: u16be(bytes, at + 7), height: u16be(bytes, at + 5) };
|
|
252
|
+
}
|
|
253
|
+
at += 2 + u16be(bytes, at + 2);
|
|
254
|
+
}
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
})(TaImageSize || (TaImageSize = {}));
|
|
258
|
+
var TaAgentSummary;
|
|
259
|
+
(function(TaAgentSummary2) {
|
|
260
|
+
const START = /^\s*<conversation_history_summary>/;
|
|
261
|
+
const BLOCK = /^\s*<conversation_history_summary>[\s\S]*?(?:<\/conversation_history_summary>\s*|$)/;
|
|
262
|
+
function read(text) {
|
|
263
|
+
if (!START.test(text)) {
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
return text.replace(/<\/?(?:conversation_history_summary|summary)>/g, "").replace(/<\/?\w*$/, "").trim();
|
|
267
|
+
}
|
|
268
|
+
TaAgentSummary2.read = read;
|
|
269
|
+
function strip(text) {
|
|
270
|
+
return text.replace(BLOCK, "");
|
|
271
|
+
}
|
|
272
|
+
TaAgentSummary2.strip = strip;
|
|
273
|
+
})(TaAgentSummary || (TaAgentSummary = {}));
|
|
274
|
+
var TaSkillUse;
|
|
275
|
+
(function(TaSkillUse2) {
|
|
276
|
+
const BLOCK = /^<skill name="([^"]+)" location="([^"]+)">\n([\s\S]*?)\n<\/skill>(?:\n\n([\s\S]+))?$/;
|
|
277
|
+
function parse(message) {
|
|
278
|
+
var _a;
|
|
279
|
+
const match = BLOCK.exec(message);
|
|
280
|
+
if (!match) {
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
return { name: match[1], location: match[2], content: match[3], message: ((_a = match[4]) === null || _a === undefined ? undefined : _a.trim()) || undefined };
|
|
284
|
+
}
|
|
285
|
+
TaSkillUse2.parse = parse;
|
|
286
|
+
function command(use) {
|
|
287
|
+
return use.message ? `/skill:${use.name} ${use.message}` : `/skill:${use.name}`;
|
|
288
|
+
}
|
|
289
|
+
TaSkillUse2.command = command;
|
|
290
|
+
})(TaSkillUse || (TaSkillUse = {}));
|
|
291
|
+
var TaTaskNote;
|
|
292
|
+
(function(TaTaskNote2) {
|
|
293
|
+
const NOTE = /^<task_(update|adopted|renamed) ((?:[^>"\n]|"[^"]*")*)>\n?([\s\S]*?)\n?<\/task_\1>$/;
|
|
294
|
+
const ATTRIBUTE = /(\w+)="([^"]*)"/g;
|
|
295
|
+
function write(note) {
|
|
296
|
+
const attributes = [`id="${quote(note.id)}"`];
|
|
297
|
+
if (note.was !== undefined) {
|
|
298
|
+
attributes.push(`was="${quote(note.was)}"`);
|
|
299
|
+
}
|
|
300
|
+
attributes.push(`title="${quote(note.title)}"`);
|
|
301
|
+
if (note.status !== undefined) {
|
|
302
|
+
attributes.push(`status="${quote(note.status)}"`);
|
|
303
|
+
}
|
|
304
|
+
return `<task_${note.kind} ${attributes.join(" ")}>
|
|
305
|
+
${note.body}
|
|
306
|
+
</task_${note.kind}>`;
|
|
307
|
+
}
|
|
308
|
+
TaTaskNote2.write = write;
|
|
309
|
+
function parse(text) {
|
|
310
|
+
const match = NOTE.exec(text.trim());
|
|
311
|
+
if (!match) {
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
const attributes = {};
|
|
315
|
+
for (const [, name, value] of match[2].matchAll(ATTRIBUTE)) {
|
|
316
|
+
attributes[name] = unquote(value);
|
|
317
|
+
}
|
|
318
|
+
if (!attributes.id || attributes.title === undefined) {
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
const { id, title, status, was } = attributes;
|
|
322
|
+
return { kind: match[1], id, title, ...status ? { status } : {}, ...was ? { was } : {}, body: match[3] };
|
|
323
|
+
}
|
|
324
|
+
TaTaskNote2.parse = parse;
|
|
325
|
+
function quote(text) {
|
|
326
|
+
return text.replace(/&/g, "&").replace(/"/g, """).replace(/\n/g, " ");
|
|
327
|
+
}
|
|
328
|
+
function unquote(text) {
|
|
329
|
+
return text.replace(/"/g, '"').replace(/&/g, "&");
|
|
330
|
+
}
|
|
331
|
+
})(TaTaskNote || (TaTaskNote = {}));
|
|
332
|
+
var TaSecretRef;
|
|
333
|
+
(function(TaSecretRef2) {
|
|
334
|
+
TaSecretRef2.PACKAGE = "@celljs/ta-secrets";
|
|
335
|
+
const REF = /\$\{?TA_SECRET_([A-Z0-9][A-Z0-9_]*)\}?/g;
|
|
336
|
+
const KINDS = [
|
|
337
|
+
[/^PHONE(?:_\d+)?$/, "phone"],
|
|
338
|
+
[/^EMAIL(?:_\d+)?$/, "email"],
|
|
339
|
+
[/^ID_NUMBER(?:_\d+)?$/, "idNumber"],
|
|
340
|
+
[/^BANK_CARD(?:_\d+)?$/, "bankCard"]
|
|
341
|
+
];
|
|
342
|
+
function has(text) {
|
|
343
|
+
return text.includes("TA_SECRET_") && new RegExp(REF.source).test(text);
|
|
344
|
+
}
|
|
345
|
+
TaSecretRef2.has = has;
|
|
346
|
+
function kind(name) {
|
|
347
|
+
var _a;
|
|
348
|
+
var _b;
|
|
349
|
+
return (_b = (_a = KINDS.find(([pattern]) => pattern.test(name))) === null || _a === undefined ? undefined : _a[1]) !== null && _b !== undefined ? _b : "secret";
|
|
350
|
+
}
|
|
351
|
+
TaSecretRef2.kind = kind;
|
|
352
|
+
function split(text) {
|
|
353
|
+
if (!has(text)) {
|
|
354
|
+
return [{ text }];
|
|
355
|
+
}
|
|
356
|
+
const parts = [];
|
|
357
|
+
let at = 0;
|
|
358
|
+
for (const match of text.matchAll(REF)) {
|
|
359
|
+
if (match.index > at) {
|
|
360
|
+
parts.push({ text: text.slice(at, match.index) });
|
|
361
|
+
}
|
|
362
|
+
parts.push({ secret: match[1], kind: kind(match[1]) });
|
|
363
|
+
at = match.index + match[0].length;
|
|
364
|
+
}
|
|
365
|
+
if (at < text.length) {
|
|
366
|
+
parts.push({ text: text.slice(at) });
|
|
367
|
+
}
|
|
368
|
+
return parts;
|
|
369
|
+
}
|
|
370
|
+
TaSecretRef2.split = split;
|
|
371
|
+
function plain(text, label) {
|
|
372
|
+
return has(text) ? text.replace(REF, (_whole, name) => label(name, kind(name))) : text;
|
|
373
|
+
}
|
|
374
|
+
TaSecretRef2.plain = plain;
|
|
375
|
+
})(TaSecretRef || (TaSecretRef = {}));
|
|
376
|
+
|
|
377
|
+
// ../ta-protocol/esm/common/said-protocol.js
|
|
378
|
+
var TaSaid;
|
|
379
|
+
(function(TaSaid2) {
|
|
380
|
+
const CARD = /^ta-/i;
|
|
381
|
+
const READ = 4000;
|
|
382
|
+
const FENCE = /^\s*(`{3,}|~{3,})\s*([^\s`]*)/;
|
|
383
|
+
const TAG_LINE = /^<\/?[A-Za-z][\w:.-]*(?:\s[^<>]*)?\/?>$/;
|
|
384
|
+
const MARKS_ONLY = /^[-*_=|:+\s]+$/;
|
|
385
|
+
const MARKS = [
|
|
386
|
+
["context", /<\/?context>/],
|
|
387
|
+
["source", /\[ta:(?:from|notice|by) /],
|
|
388
|
+
["image note", /\[Image: original \d+x\d+|\[Image converted from /],
|
|
389
|
+
["skill", /<skill name="|<\/skill>/],
|
|
390
|
+
["task note", /<\/?task_(?:update|adopted|renamed)\b/],
|
|
391
|
+
["summary", /<\/?(?:conversation_history_summary|summary)>/]
|
|
392
|
+
];
|
|
393
|
+
function text(content, joiner = `
|
|
394
|
+
`) {
|
|
395
|
+
if (typeof content === "string") {
|
|
396
|
+
return content;
|
|
397
|
+
}
|
|
398
|
+
return Array.isArray(content) ? content.filter((part) => (part === null || part === undefined ? undefined : part.type) === "text" && typeof part.text === "string").map((part) => part.text).join(joiner) : "";
|
|
399
|
+
}
|
|
400
|
+
TaSaid2.text = text;
|
|
401
|
+
function words(role, text2, options = {}) {
|
|
402
|
+
const said = role === "user" ? userWords(text2) : TaAgentSummary.strip(text2);
|
|
403
|
+
return withoutFences(said, (language) => options.cards === false && CARD.test(language), true).trim();
|
|
404
|
+
}
|
|
405
|
+
TaSaid2.words = words;
|
|
406
|
+
function of(message, options) {
|
|
407
|
+
return message ? words(message.role, text(message.content), options) : "";
|
|
408
|
+
}
|
|
409
|
+
TaSaid2.of = of;
|
|
410
|
+
function notice(message) {
|
|
411
|
+
return (message === null || message === undefined ? undefined : message.role) === "user" && TaMessageSource.isNotice(text(message.content));
|
|
412
|
+
}
|
|
413
|
+
TaSaid2.notice = notice;
|
|
414
|
+
function marksOnly(role, text2) {
|
|
415
|
+
return !!text2.trim() && !line(words(role, text2), { chars: Number.POSITIVE_INFINITY });
|
|
416
|
+
}
|
|
417
|
+
TaSaid2.marksOnly = marksOnly;
|
|
418
|
+
function line(markdown, options) {
|
|
419
|
+
var _a;
|
|
420
|
+
const read = markdown.slice(0, READ);
|
|
421
|
+
const prose = withoutFences(read, () => true, true).trim();
|
|
422
|
+
const lines = plain(prose || codeOf(read)).split(`
|
|
423
|
+
`).map((part) => part.replace(/^\s*(?:#{1,6}\s+|>\s*|[-*+]\s+|\d+[.)]\s+)/, "").replace(/\*{1,3}|`+|~~|(?<![\p{L}\p{N}])_{1,3}|_{1,3}(?![\p{L}\p{N}])/gu, "").replace(/\s+/g, " ").trim()).filter((part) => part && !MARKS_ONLY.test(part) && !TAG_LINE.test(part));
|
|
424
|
+
const count = (_a = options.lines) !== null && _a !== undefined ? _a : 1;
|
|
425
|
+
const joined = count <= 1 ? lines.join(" ") : lines.slice(0, count).join(`
|
|
426
|
+
`);
|
|
427
|
+
return joined.length > options.chars ? `${joined.slice(0, Math.max(0, options.chars - 1)).trimEnd()}…` : joined;
|
|
428
|
+
}
|
|
429
|
+
TaSaid2.line = line;
|
|
430
|
+
function leaks(shown, options = {}) {
|
|
431
|
+
const found = MARKS.filter(([, mark]) => mark.test(shown)).map(([name]) => name);
|
|
432
|
+
const lines = shown.split(`
|
|
433
|
+
`);
|
|
434
|
+
if (options.cards !== true && lines.some((part) => {
|
|
435
|
+
var _a;
|
|
436
|
+
var _b;
|
|
437
|
+
return CARD.test((_b = (_a = FENCE.exec(part)) === null || _a === undefined ? undefined : _a[2]) !== null && _b !== undefined ? _b : "");
|
|
438
|
+
})) {
|
|
439
|
+
found.push("card");
|
|
440
|
+
}
|
|
441
|
+
if (lines.some((part) => TAG_LINE.test(part.trim()))) {
|
|
442
|
+
found.push("tag");
|
|
443
|
+
}
|
|
444
|
+
return found;
|
|
445
|
+
}
|
|
446
|
+
TaSaid2.leaks = leaks;
|
|
447
|
+
const SUMMARY = `<conversation_history_summary>
|
|
448
|
+
<summary>
|
|
449
|
+
1. Primary Request and Intent:
|
|
450
|
+
The user works on the relay.
|
|
451
|
+
</summary>
|
|
452
|
+
</conversation_history_summary>`;
|
|
453
|
+
TaSaid2.SAMPLES = [
|
|
454
|
+
{
|
|
455
|
+
mark: "context and where it came from",
|
|
456
|
+
role: "user",
|
|
457
|
+
text: `<context>
|
|
458
|
+
The channel #ops, its members.
|
|
459
|
+
[ta:from @celljs/ta-channels #ops]
|
|
460
|
+
</context>
|
|
461
|
+
Check the build`,
|
|
462
|
+
said: "Check the build"
|
|
463
|
+
},
|
|
464
|
+
{
|
|
465
|
+
mark: "a notice, not the user",
|
|
466
|
+
role: "user",
|
|
467
|
+
text: `<context>
|
|
468
|
+
[ta:notice @celljs/ta-call]
|
|
469
|
+
</context>
|
|
470
|
+
The work finished. Its last words: tests pass.`,
|
|
471
|
+
said: "The work finished. Its last words: tests pass."
|
|
472
|
+
},
|
|
473
|
+
{ mark: "one let in", role: "user", text: `<context>
|
|
474
|
+
[ta:by p-7 Alice]
|
|
475
|
+
</context>
|
|
476
|
+
Hello there`, said: "Hello there" },
|
|
477
|
+
{
|
|
478
|
+
mark: "notes of images",
|
|
479
|
+
role: "user",
|
|
480
|
+
text: `Look at this
|
|
481
|
+
[Image: original 3024x4032, displayed at 1512x2016. Multiply coordinates by 2.00 to map to original image.]
|
|
482
|
+
[Image converted from image/heic to image/png.]`,
|
|
483
|
+
said: "Look at this"
|
|
484
|
+
},
|
|
485
|
+
{
|
|
486
|
+
mark: "a skill run",
|
|
487
|
+
role: "user",
|
|
488
|
+
text: `<skill name="ta-package" location="/skills/ta-package/SKILL.md">
|
|
489
|
+
# Ta package
|
|
490
|
+
Steps.
|
|
491
|
+
</skill>
|
|
492
|
+
|
|
493
|
+
Make a card`,
|
|
494
|
+
said: "Make a card"
|
|
495
|
+
},
|
|
496
|
+
{
|
|
497
|
+
mark: "a note of a task",
|
|
498
|
+
role: "user",
|
|
499
|
+
text: `<task_update id="t1" title="Fix login" status="done">
|
|
500
|
+
All tests pass.
|
|
501
|
+
</task_update>`,
|
|
502
|
+
said: "Fix login"
|
|
503
|
+
},
|
|
504
|
+
{ mark: "a note of a new id", role: "user", text: `<task_renamed id="t2" was="t1" title="Fix login">
|
|
505
|
+
Now t2.
|
|
506
|
+
</task_renamed>` },
|
|
507
|
+
{ mark: "a summary, then the answer", role: "assistant", text: `${SUMMARY}
|
|
508
|
+
Switched to voice.`, said: "Switched to voice." },
|
|
509
|
+
{ mark: "a summary alone", role: "assistant", text: SUMMARY },
|
|
510
|
+
{ mark: "a summary as it streams", role: "assistant", text: `<conversation_history_summary>
|
|
511
|
+
<summary>` },
|
|
512
|
+
{
|
|
513
|
+
mark: "a card after the answer",
|
|
514
|
+
role: "assistant",
|
|
515
|
+
text: '**Done**: tests pass.\n\n```ta-glance\n{"status":"done","blocks":[]}\n```',
|
|
516
|
+
said: "tests pass"
|
|
517
|
+
},
|
|
518
|
+
{ mark: "a card alone", role: "assistant", text: '```ta-glance\n{"status":"done","blocks":[]}\n```' },
|
|
519
|
+
{ mark: "a proposal", role: "assistant", text: 'Committed.\n\n```ta-propose\n{"kind":"git.push","title":"Push"}\n```', said: "Committed." },
|
|
520
|
+
{ mark: "what a call says aloud", role: "assistant", text: "All fixed.\n\n```ta-say\nIt is fixed.\n```", said: "All fixed." },
|
|
521
|
+
{ mark: "a tag not known yet", role: "assistant", text: `<system-reminder>
|
|
522
|
+
</system-reminder>
|
|
523
|
+
Ready.`, said: "Ready." }
|
|
524
|
+
];
|
|
525
|
+
function userWords(text2) {
|
|
526
|
+
const said = TaImageNote.strip(TaMessageContext.strip(text2));
|
|
527
|
+
const skill = TaSkillUse.parse(said);
|
|
528
|
+
if (skill) {
|
|
529
|
+
return TaSkillUse.command(skill);
|
|
530
|
+
}
|
|
531
|
+
const note = TaTaskNote.parse(said);
|
|
532
|
+
if (!note) {
|
|
533
|
+
return said;
|
|
534
|
+
}
|
|
535
|
+
if (note.kind === "renamed") {
|
|
536
|
+
return "";
|
|
537
|
+
}
|
|
538
|
+
return note.kind === "update" && note.body.trim() ? `${note.title} · ${note.body}` : note.title;
|
|
539
|
+
}
|
|
540
|
+
function withoutFences(text2, drop, tags = false) {
|
|
541
|
+
const kept = [];
|
|
542
|
+
let fence;
|
|
543
|
+
let left = false;
|
|
544
|
+
for (const part of text2.split(`
|
|
545
|
+
`)) {
|
|
546
|
+
const open = FENCE.exec(part);
|
|
547
|
+
if (!fence && open) {
|
|
548
|
+
fence = { mark: open[1], dropped: drop(open[2]) };
|
|
549
|
+
} else if (fence && closes(part, fence.mark)) {
|
|
550
|
+
const dropped = fence.dropped;
|
|
551
|
+
fence = undefined;
|
|
552
|
+
if (dropped) {
|
|
553
|
+
continue;
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
if ((fence === null || fence === undefined ? undefined : fence.dropped) || !fence && tags && TAG_LINE.test(part.trim())) {
|
|
557
|
+
left = true;
|
|
558
|
+
} else {
|
|
559
|
+
kept.push(part);
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
return left ? kept.join(`
|
|
563
|
+
`).replace(/\n{3,}/g, `
|
|
564
|
+
|
|
565
|
+
`) : kept.join(`
|
|
566
|
+
`);
|
|
567
|
+
}
|
|
568
|
+
function codeOf(text2) {
|
|
569
|
+
const code = [];
|
|
570
|
+
let fence;
|
|
571
|
+
for (const part of text2.split(`
|
|
572
|
+
`)) {
|
|
573
|
+
const open = FENCE.exec(part);
|
|
574
|
+
if (!fence && open) {
|
|
575
|
+
fence = { mark: open[1], card: CARD.test(open[2]) };
|
|
576
|
+
} else if (fence && closes(part, fence.mark)) {
|
|
577
|
+
fence = undefined;
|
|
578
|
+
} else if (fence && !fence.card) {
|
|
579
|
+
code.push(part);
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
return code.join(`
|
|
583
|
+
`);
|
|
584
|
+
}
|
|
585
|
+
function closes(part, mark) {
|
|
586
|
+
var _a;
|
|
587
|
+
const close = (_a = /^\s*(`{3,}|~{3,})\s*$/.exec(part)) === null || _a === undefined ? undefined : _a[1];
|
|
588
|
+
return !!close && close[0] === mark[0] && close.length >= mark.length;
|
|
589
|
+
}
|
|
590
|
+
function plain(text2) {
|
|
591
|
+
const linked = text2.replace(/(?<!!)\[([^\]\n]*)\]\([^)\n]*\)/g, "$1");
|
|
592
|
+
const words2 = linked.replace(/!\[[^\]\n]*\]\([^)\n]*\)/g, "").trim();
|
|
593
|
+
return words2 || linked.replace(/!\[([^\]\n]*)\]\([^)\n]*\)/g, "$1");
|
|
594
|
+
}
|
|
595
|
+
})(TaSaid || (TaSaid = {}));
|
|
596
|
+
|
|
104
597
|
// web-src/conversation-util.ts
|
|
105
|
-
var CONTEXT = /^<context>\n?[\s\S]*?\n?<\/context>\n?/;
|
|
106
|
-
var SKILL = /^<skill name="([^"]+)"[^>]*>[\s\S]*?<\/skill>\s*/;
|
|
107
|
-
var IMAGE_NOTE = /^\[Image: original \d+x\d+, displayed at \d+x\d+\. Multiply coordinates by [\d.]+ to map to original image\.\]$|^\[Image converted from [^\]]+ to [^\]]+\.\]$/gm;
|
|
108
598
|
var TITLE_CHARS = 80;
|
|
109
599
|
var ConversationUtil;
|
|
110
600
|
((ConversationUtil) => {
|
|
@@ -138,10 +628,10 @@ var ConversationUtil;
|
|
|
138
628
|
continue;
|
|
139
629
|
}
|
|
140
630
|
const raw = textOf(entry.message?.content);
|
|
141
|
-
const text = role
|
|
631
|
+
const text = TaSaid.words(role, raw);
|
|
142
632
|
updatedAt = Math.max(updatedAt, at);
|
|
143
633
|
if (text) {
|
|
144
|
-
said.push(role === "user" &&
|
|
634
|
+
said.push(role === "user" && TaMessageContext.read(raw) !== undefined ? { role, text, at, framed: true } : { role, text, at });
|
|
145
635
|
}
|
|
146
636
|
}
|
|
147
637
|
}
|
|
@@ -163,20 +653,11 @@ var ConversationUtil;
|
|
|
163
653
|
}
|
|
164
654
|
ConversationUtil.parse = parse;
|
|
165
655
|
function textOf(content) {
|
|
166
|
-
|
|
167
|
-
return content.trim();
|
|
168
|
-
}
|
|
169
|
-
if (!Array.isArray(content)) {
|
|
170
|
-
return "";
|
|
171
|
-
}
|
|
172
|
-
return content.flatMap((part) => part && typeof part === "object" && part.type === "text" && typeof part.text === "string" ? [part.text] : []).join(`
|
|
173
|
-
`).trim();
|
|
656
|
+
return TaSaid.text(content).trim();
|
|
174
657
|
}
|
|
175
658
|
ConversationUtil.textOf = textOf;
|
|
176
659
|
function userText(content) {
|
|
177
|
-
|
|
178
|
-
const skill = SKILL.exec(text);
|
|
179
|
-
return (skill ? `/skill:${skill[1]} ${text.slice(skill[0].length)}` : text).trim();
|
|
660
|
+
return TaSaid.words("user", textOf(content));
|
|
180
661
|
}
|
|
181
662
|
ConversationUtil.userText = userText;
|
|
182
663
|
function cwdOf(cwd, agentDir) {
|
|
@@ -342,7 +823,6 @@ var Keys;
|
|
|
342
823
|
Keys.ASKED = "asked";
|
|
343
824
|
Keys.BRIEF_SUMMARY = "briefSummary";
|
|
344
825
|
Keys.BRIEF_SEEN = "briefSeen";
|
|
345
|
-
Keys.BRIEF_PINNED = "briefPinned";
|
|
346
826
|
Keys.BRIEF_HANDLED = "briefHandled";
|
|
347
827
|
Keys.DECIDED = "decided";
|
|
348
828
|
Keys.DECLINED = "declined";
|
|
@@ -462,10 +942,7 @@ ${draft.body.trim()}
|
|
|
462
942
|
"en-US": `Make it: ${draft.title}`,
|
|
463
943
|
"ja-JP": `作成:${draft.title}`
|
|
464
944
|
});
|
|
465
|
-
return
|
|
466
|
-
${context}
|
|
467
|
-
</context>
|
|
468
|
-
${said}`;
|
|
945
|
+
return TaMessageContext.wrap(context, said);
|
|
469
946
|
}
|
|
470
947
|
ExtensionUtil.make = make;
|
|
471
948
|
})(ExtensionUtil ||= {});
|
|
@@ -502,10 +979,7 @@ var KeepUtil;
|
|
|
502
979
|
"en-US": "Keep how this was done",
|
|
503
980
|
"ja-JP": "この会話の方法を保存"
|
|
504
981
|
});
|
|
505
|
-
return
|
|
506
|
-
${context}
|
|
507
|
-
</context>
|
|
508
|
-
${prompt}`;
|
|
982
|
+
return TaMessageContext.wrap(context, prompt);
|
|
509
983
|
}
|
|
510
984
|
KeepUtil.ask = ask;
|
|
511
985
|
function hint(asks) {
|