@celljs/ta-glance 4.16.0 → 4.18.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.
@@ -1,4 +1,5 @@
1
1
  // ../ta-protocol/esm/common/ta-extension-host.js
2
+ var TA_WEBHOOK_MAX_BYTES = 256 * 1024;
2
3
  var TA_HOST_EVENT = "ta:host";
3
4
  var TaHostUtil;
4
5
  (function(TaHostUtil2) {
@@ -95,6 +96,7 @@ var TaAskUtil;
95
96
  var GlanceJson;
96
97
  ((GlanceJson) => {
97
98
  const TRIES = 40;
99
+ const CONTROLS = { "\n": "\\n", "\r": "\\r", "\t": "\\t" };
98
100
  function parse(text, partial) {
99
101
  const source = text.trim().replace(/,\s*([}\]])/g, "$1");
100
102
  if (!source) {
@@ -157,6 +159,9 @@ var GlanceJson;
157
159
  escaped = true;
158
160
  } else if (char === '"') {
159
161
  inString = false;
162
+ } else if (char < " ") {
163
+ out += CONTROLS[char] ?? `\\u${char.charCodeAt(0).toString(16).padStart(4, "0")}`;
164
+ continue;
160
165
  }
161
166
  } else if (char === '"') {
162
167
  inString = true;
@@ -213,15 +218,21 @@ var GLANCE_ICONS = [
213
218
 
214
219
  // web-src/glance-spec.ts
215
220
  var ITEMS = 12;
221
+ var FOLDED = 40;
216
222
  var POINTS = 24;
217
223
  var SERIES = 4;
218
224
  var BLOCKS = 8;
219
225
  var TEXT = 400;
220
226
  var MARKDOWN = 8000;
221
227
  var STATUSES = ["done", "partial", "failed", "blocked", "info"];
228
+ var QUIET = ["done", "info"];
222
229
  var TONES = ["good", "bad", "warn", "neutral"];
223
230
  var STEPS = ["done", "doing", "todo", "failed", "skipped"];
224
- var NOTES = ["risk", "info", "todo"];
231
+ var NOTES = ["risk", "todo", "info"];
232
+ var CHECKS = 3;
233
+ function passed(list, least) {
234
+ return list.length >= least && list.every((item) => item.tone === "good");
235
+ }
225
236
  function object(value) {
226
237
  return value && typeof value === "object" && !Array.isArray(value) ? value : undefined;
227
238
  }
@@ -364,13 +375,19 @@ function isPath(value) {
364
375
  }
365
376
  var LABELS = { before: "Before", after: "After" };
366
377
  function block(item, partial, labels) {
378
+ const made = blockOf(item, partial, labels);
379
+ const fold = object(item)?.fold;
380
+ const words = fold === true ? "" : text(fold, 40);
381
+ return made && words !== undefined ? { ...made, fold: words } : made;
382
+ }
383
+ function blockOf(item, partial, labels) {
367
384
  const value = object(item);
368
385
  const type = typeof value?.type === "string" ? value.type.trim().toLowerCase() : undefined;
369
386
  const unit = text(value?.unit, 16);
370
387
  switch (type) {
371
388
  case "stats": {
372
389
  const list = items(value?.items, stat).slice(0, 6);
373
- return list.length ? { type, items: list } : undefined;
390
+ return list.length ? { type, items: list, ...passed(list, CHECKS) ? { checks: true } : {} } : undefined;
374
391
  }
375
392
  case "changes": {
376
393
  const raw = Array.isArray(value?.items) ? value.items : [];
@@ -379,7 +396,7 @@ function block(item, partial, labels) {
379
396
  const list2 = items(raw, point);
380
397
  return list2.length ? { type: "notes", items: list2 } : undefined;
381
398
  }
382
- const list = items(value?.items, change);
399
+ const list = items(value?.items, change, FOLDED);
383
400
  return list.length ? { type, items: list } : undefined;
384
401
  }
385
402
  case "steps": {
@@ -408,7 +425,7 @@ function block(item, partial, labels) {
408
425
  return rows.length ? { type: "table", columns: ["", labels.before, labels.after], rows } : undefined;
409
426
  }
410
427
  case "bars": {
411
- const list = items(value?.items, amount);
428
+ const list = items(value?.items, amount, FOLDED);
412
429
  return list.length ? { type, items: list, ...unit ? { unit } : {} } : undefined;
413
430
  }
414
431
  case "line": {
@@ -432,17 +449,17 @@ function block(item, partial, labels) {
432
449
  return mermaid ? { type, mermaid } : undefined;
433
450
  }
434
451
  case "table": {
435
- const columns = strings(value?.columns, 6);
436
- const rows = items(value?.rows, (row) => Array.isArray(row) ? columns.map((_, index) => text(row[index]) ?? "") : undefined);
452
+ const columns = items(value?.columns, (column) => text(column) ?? (typeof column === "string" ? "" : undefined), 6);
453
+ const rows = items(value?.rows, (row) => Array.isArray(row) ? columns.map((_, index) => text(row[index]) ?? "") : undefined, FOLDED);
437
454
  return columns.length && rows.length ? { type, columns, rows } : undefined;
438
455
  }
439
456
  case "options": {
440
457
  const list = items(value?.items, option).slice(0, 5);
441
458
  const question = text(value?.question);
442
- return list.length ? { type, items: list, ...question ? { question } : {} } : undefined;
459
+ return list.length ? { type, items: list, ...question ? { question } : {}, ...value?.multi === true ? { multi: true } : {} } : undefined;
443
460
  }
444
461
  case "notes": {
445
- const list = items(value?.items, note);
462
+ const list = items(value?.items, note).sort((a, b) => NOTES.indexOf(a.tone) - NOTES.indexOf(b.tone));
446
463
  return list.length ? { type, items: list } : undefined;
447
464
  }
448
465
  case "next": {
@@ -469,6 +486,13 @@ function loose(card) {
469
486
  return out;
470
487
  }
471
488
  var LISTS = ["stats", "changes", "steps", "flow", "options", "notes", "next"];
489
+ var PLACE = { stats: -1, notes: 1, next: 2, details: 3 };
490
+ function place(block2) {
491
+ return block2.fold !== undefined ? 3 : PLACE[block2.type] ?? 0;
492
+ }
493
+ function placed(blocks) {
494
+ return blocks.map((block2, index) => ({ block: block2, index })).sort((a, b) => place(a.block) - place(b.block) || a.index - b.index).map((entry) => entry.block);
495
+ }
472
496
  var GlanceSpec;
473
497
  ((GlanceSpec) => {
474
498
  function read(value, partial = false, labels = LABELS) {
@@ -478,7 +502,7 @@ var GlanceSpec;
478
502
  }
479
503
  const status = oneOf(card.status, STATUSES);
480
504
  const title = text(card.title);
481
- const blocks = items(Array.isArray(card.blocks) ? card.blocks : loose(card), (entry) => block(entry, partial, labels)).slice(0, BLOCKS);
505
+ const blocks = placed(items(Array.isArray(card.blocks) ? card.blocks : loose(card), (entry) => block(entry, partial, labels)).slice(0, BLOCKS)).map((made) => made.type === "stats" && !made.checks && status && !QUIET.includes(status) && passed(made.items, 1) ? { ...made, checks: true } : made);
482
506
  if (!blocks.length && !title) {
483
507
  return;
484
508
  }
@@ -568,17 +592,18 @@ var GlanceAsk;
568
592
  var GLANCE_PROMPT = `The user reads your replies in Ta, often on a phone, and wants to take in the result at a glance, not read long text.
569
593
 
570
594
  How to reply:
571
- - Lead with the answer. The first line is the conclusion in one sentence, what matters in **bold**. Nothing before it: no "Sure", no restating the request.
572
- - Then only what the user needs to act or decide. Leave out the process (what you read, ran, tried), what the user already knows and repeating yourself. Prefer numbers and names to adjectives.
595
+ - Lead with the answer. The first line is the conclusion in one short sentence (about 25 Chinese characters or 15 words at most), what matters in **bold**. Nothing before it: no "Sure", no restating the request.
596
+ - Report by exception. What went as expected is said once, as a whole ("all 6 checks pass"), never a row or a sentence each. Words go only to what is wrong, unfinished, at risk, or the user must decide. Leave out the process (what you read, ran, tried), reasons and evidence nobody asked for, what the user already knows and repeating yourself. Prefer numbers and names to adjectives.
573
597
  - A short question or small talk: one to three sentences, no card.
598
+ - A message may ask for its answer in a form of its own (PASS or FAIL first, a verdict, "in a few lines", "report…"), whether the user's or sent by a program or another agent (the double, a scheduled task, a goal): the user reads it here all the same. Keep what it asks (the word or line it wants first, the order, how short) and still put the rest in the card: short makes the card smaller, not plain lines. Leave the card out only when the message says the answer goes where nothing draws one (plain text, no Markdown).
574
599
  - When the reply reports work done, results, a comparison, choices to make, or an analysis with several facts or relations: after the first line put one card, a fenced block of language ${LANGUAGE} holding JSON, instead of paragraphs, headings and long lists. Ta draws it as a picture. After the card at most two short lines, only for what it cannot hold; never repeat what it shows.
575
600
  - Code the user must read or copy stays in ordinary code blocks.
576
601
  - Several pictures (screenshots, before and after, light and dark): one after another, each \`![a few words](path)\` with nothing else between them. Ta shows them together as a grid, the words under each.
577
602
 
578
603
  The card: {"status": "done" | "partial" | "failed" | "blocked" | "info", "title"?: string, "blocks": [...]}
579
604
  status: done = finished, partial = done in part, failed, blocked = waiting for the user, info = an answer, no work. Leave out title: the first line already says it.
580
- Blocks, 1 to 4 of them, the most important first, each with only the fields shown. Every text a few words, in the user's language; inline Markdown works (**bold**, \`path/to/file\` opens the file).
581
- - {"type":"stats","items":[{"label":"Tests","value":"128/128","tone":"good"},{"label":"Startup","value":"210 ms","delta":"-34%","tone":"good","trend":[320,290,210]}]}: key numbers, at most 6; tone good | bad | warn; trend, its values over time when known, draws a small line.
605
+ Blocks, 1 to 3 of them, the most important first (Ta puts stats on top and notes, next and details at the bottom), each with only the fields shown. A block few need but some may want (the full list, how it was measured, the rest of a comparison, why, where in the code) may have "fold": "a few words": Ta draws it folded under them, opened by a tap; it does not count in the 3. Long lists are folded by Ta after their first items, so give them whole. Every text of a card fits one line of a phone: about 20 Chinese characters or 12 words at most, a label 2 to 6; Ta cuts a row at two lines. In the user's language; inline Markdown works (**bold**, \`path/to/file\` opens the file).
606
+ - {"type":"stats","items":[{"label":"Tests","value":"128/128","tone":"good"},{"label":"Startup","value":"210 ms","delta":"-34%","tone":"good","trend":[320,290,210]}]}: key numbers, at most 4, each value a number with its unit (a fact in words goes in notes); tone good | bad | warn; trend, its values over time when known, draws a small line. Checks that passed (tests, build, lint) are one stats block, tone good each: Ta draws it as a single line of ticks.
582
607
  - {"type":"changes","items":[{"path":"src/a.ts","kind":"edit","add":12,"del":3,"note":"why, in a few words"}]}: files changed, a path each (what changed without a file goes in notes); kind add | edit | delete.
583
608
  - {"type":"steps","items":[{"text":"...","status":"done"}]}: progress or a plan; status done | doing | todo | failed | skipped.
584
609
  - {"type":"compare","unit":"ms","better":"lower","items":[{"label":"Startup","before":320,"after":210}]}: before and after, numbers only (words go in a table).
@@ -587,9 +612,9 @@ Blocks, 1 to 4 of them, the most important first, each with only the fields show
587
612
  - {"type":"share","unit":"MB","items":[{"label":"pi","value":129},{"label":"ta","value":66}]}: the parts of a whole.
588
613
  - {"type":"flow","items":["Request",{"text":"Gateway","icon":"Server"},"Session","Model"]}: a sequence or a path.
589
614
  - {"type":"diagram","mermaid":"graph LR; A-->B"}: relations a flow cannot show, under 12 nodes.
590
- - {"type":"table","columns":["",""],"rows":[["",""]]}: a few rows that compare things on several points.
591
- - {"type":"options","question":"Which one?","items":[{"label":"A","detail":"one line","pros":["..."],"cons":["..."],"recommended":true}]}: when the user must choose; each is a button that answers with its label.
592
- - {"type":"notes","items":[{"text":"...","tone":"risk"}]}: risks, caveats, what the user must do; tone risk | info | todo.
615
+ - {"type":"table","columns":["",""],"rows":[["",""]]}: a few rows that compare things on several points, the first column naming each row (columns ["", "Before", "After"] for before and after in words); cells of a few words, never sentences, and no row for what is fine.
616
+ - {"type":"options","question":"Which one?","items":[{"label":"A","detail":"one line","pros":["..."],"cons":["..."],"recommended":true}]}: when the user must choose; each is a button that answers with its label. Add "multi": true when they may choose several. Several things to decide at once: an options block for each, in the same card; the user picks in all of them and sends the choices together.
617
+ - {"type":"notes","items":[{"text":"...","tone":"risk"}]}: risks, caveats, what the user must do, at most 3, a line each; tone risk | info | todo.
593
618
  - {"type":"next","items":["Run the e2e tests"]}: at most 3 things the user may well ask next, each a button that sends it.
594
619
  - {"type":"details","title":"How","markdown":"..."}: what few will read, folded.
595
620
  An item of stats, flow, options, notes or next may have "icon", where it tells items apart at a glance (an item of flow or next then {"text","icon"}): one of ${GLANCE_ICONS.join(", ")}; else leave it out. Never write an emoji, in a card or out of it.`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@celljs/ta-glance",
3
- "version": "4.16.0",
3
+ "version": "4.18.0",
4
4
  "description": "A pi package for Ta: replies lead with the answer, short, and show results as cards (key numbers, files, steps, comparisons, choices) rather than paragraphs",
5
5
  "keywords": [
6
6
  "pi-package"
@@ -26,8 +26,8 @@
26
26
  "watch": "tsc -b -w --preserveWatchOutput"
27
27
  },
28
28
  "devDependencies": {
29
- "@celljs/ta-protocol": "4.16.0",
30
- "@celljs/ta-web": "4.16.0",
29
+ "@celljs/ta-protocol": "4.18.0",
30
+ "@celljs/ta-web": "4.18.0",
31
31
  "@types/react": "^19.3.0"
32
32
  },
33
33
  "publishConfig": {
@@ -50,6 +50,7 @@
50
50
  "web": [
51
51
  "./web/index.js"
52
52
  ],
53
+ "shared": true,
53
54
  "extensions": [
54
55
  "./extension/index.mjs"
55
56
  ]