@llblab/pi-kit 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  All notable changes to `@llblab/pi-kit` are documented here.
4
4
 
5
+ ## 0.3.1 - 2026-09-01
6
+
7
+ - `Telegram Patch Release`: Advances `@llblab/pi-telegram` to `0.42.1`, accepting prompt-only CML button cells such as `{|e2}` and their optional selected-style form while preserving prompt-as-label fallback and fail-closed empty prompt, style, and voice atoms.
8
+
5
9
  ## 0.3.0 - 2026-09-01
6
10
 
7
11
  - `Telegram Minor Release`: Advances `@llblab/pi-telegram` to `0.42.0`, bringing tolerant JSON and compact CML action parsing, positional voice action cells, Thread-aware generated-button prompts, and focused proactive control-surface guidance into the bundled kit.
package/README.md CHANGED
@@ -9,7 +9,7 @@
9
9
  | `@llblab/pi-actors` | `0.52.0` | Extension and Skills |
10
10
  | `@llblab/pi-codex-usage` | `0.9.4` | Extension |
11
11
  | `@llblab/pi-grow-loop` | `0.7.3` | Extension and Skills |
12
- | `@llblab/pi-telegram` | `0.42.0` | Extension and Skills |
12
+ | `@llblab/pi-telegram` | `0.42.1` | Extension and Skills |
13
13
 
14
14
  Versions are exact by design. Updating an extension does not change an installed kit until this repository explicitly advances that dependency and publishes a new kit version.
15
15
 
@@ -2,6 +2,10 @@
2
2
 
3
3
  > Each release keeps at most 8 outcome records of at most 512 characters.
4
4
 
5
+ ## 0.42.1: Prompt-Only Button Cells
6
+
7
+ - `Prompt-Only CML Buttons`: Accepts `{|prompt}` and `{|prompt|selected_style}` as canonical button cells equivalent to prompt-only JSON, so established prompt fallback supplies both visible text and queued input without a separately authored label; empty one-atom cells, prompts, styles, and voice atoms still fail closed.
8
+
5
9
  ## 0.42.0: Compact Action Grammar
6
10
 
7
11
  - `Adaptive Action Grammar`: Extracts the first semantically valid JSON or positional CML payload from noisy `telegram_button` and `telegram_voice` envelopes, tolerates bounded trailing commas and unmatched matrix noise, keeps malformed named JSON on the JSON path, and retains legacy attribute parsing as undocumented compatibility.
@@ -222,7 +222,7 @@ Voice notes, audio, images, PDFs, and other media can pass through configured in
222
222
 
223
223
  ### Buttons And Callbacks
224
224
 
225
- Assistant replies can include top-level hidden `telegram_button` comments containing a JSON object, adaptive JSON/CML matrix, or positional Compact Matrix Literal (CML). One adaptive matrix may mix named JSON objects with positional CML cells; separators are optional and one trailing comma is tolerated, including inside JSON objects. Top-level cells become full-width rows while nested rows group one or more buttons horizontally without an artificial parser-level width cap; generated surfaces default to five columns and use six to eight only for short position-bearing labels. CML uses `{value}`, `{label|prompt}`, or `{label|prompt|selected_style}` with `primary`, `success`, or `danger`; the optional style requires an explicit prompt. It trims atom boundaries, preserves non-structural text literally, and decodes only `\|`, `\}`, and `\\`. Prefer one matrix comment for multiple buttons. Buttons use `label` plus `prompt`, or the compact `value` key when both are identical. The bridge strips the comments from visible text, renders inline buttons, and routes callbacks back into Pi as queued prompts or extension-owned callback actions. Button-only replies receive the standard `☑️ **Choose an option:**` heading as automatic visible fallback text. Once a generated prompt button is accepted, only that exact button switches to its optional `selected_style` (`primary` blue by default, `success` green, or `danger` red) without altering its agent-authored label or emoji; every style still queues the selected prompt.
225
+ Assistant replies can include top-level hidden `telegram_button` comments containing a JSON object, adaptive JSON/CML matrix, or positional Compact Matrix Literal (CML). One adaptive matrix may mix named JSON objects with positional CML cells; separators are optional and one trailing comma is tolerated, including inside JSON objects. Top-level cells become full-width rows while nested rows group one or more buttons horizontally without an artificial parser-level width cap; generated surfaces default to five columns and use six to eight only for short position-bearing labels. CML uses `{value}`, `{label|prompt}`, `{|prompt}`, or the corresponding three-atom form with `selected_style` set to `primary`, `success`, or `danger`; omitting the first atom leaves the existing prompt-as-label fallback in charge, while the optional style still requires a non-empty prompt. It trims atom boundaries, preserves non-structural text literally, and decodes only `\|`, `\}`, and `\\`. Prefer one matrix comment for multiple buttons. Buttons use `label` plus `prompt`, or the compact `value` key when both are identical. The bridge strips the comments from visible text, renders inline buttons, and routes callbacks back into Pi as queued prompts or extension-owned callback actions. Button-only replies receive the standard `☑️ **Choose an option:**` heading as automatic visible fallback text. Once a generated prompt button is accepted, only that exact button switches to its optional `selected_style` (`primary` blue by default, `success` green, or `danger` red) without altering its agent-authored label or emoji; every style still queues the selected prompt.
226
226
 
227
227
  ### Threaded Mode And Multi-Instance Bus
228
228
 
@@ -58,13 +58,16 @@ A two-atom cell separates label and prompt:
58
58
  {Pause|music::pause}
59
59
  ```
60
60
 
61
- A three-atom cell adds the selected style:
61
+ Only the first label position may be empty. Prompt-only `{|e2}` is equivalent to JSON `{"prompt":"e2"}`: the existing button fallback uses `e2` as both visible text and queued prompt without requiring a separately authored label.
62
+
63
+ A three-atom cell adds the selected style and retains the same optional-label form:
62
64
 
63
65
  ```text
64
66
  {Stop|music::stop|danger}
67
+ {|e2|success}
65
68
  ```
66
69
 
67
- The style atom is accepted only as `primary`, `success`, or `danger`.
70
+ The prompt and style atoms remain required. The style atom is accepted only as `primary`, `success`, or `danger`.
68
71
 
69
72
  ## Adaptive Grammar
70
73
 
@@ -78,8 +81,8 @@ row := "[" ws cell (boundary cell)* ws "]"
78
81
  cell := json-object | positional-cell
79
82
  boundary := ws [","] ws
80
83
  positional-cell := "{" atom "}"
81
- | "{" atom "|" atom "}"
82
- | "{" atom "|" atom "|" atom "}"
84
+ | "{" [atom] "|" atom "}"
85
+ | "{" [atom] "|" atom "|" atom "}"
83
86
  atom := atom-unit+
84
87
  atom-unit := ordinary | "\|" | "\}" | "\\"
85
88
  ws := *(SP | HTAB | CR | LF)
@@ -114,7 +117,7 @@ A conforming parser:
114
117
  3. Tries one complete strict JSON object, then bounded trailing-comma recovery, at each cell boundary before positional interpretation.
115
118
  4. Keeps JSON-shaped named objects on the JSON path when validation fails instead of exposing their source as positional text.
116
119
  5. Accepts at most one comma between elements or immediately before a closing row or matrix delimiter, while rejecting leading, repeated, or property-level omitted commas.
117
- 6. Rejects empty atoms, matrices, rows, and nesting deeper than one row.
120
+ 6. Rejects empty matrices, rows, one-atom cells, prompts, styles, and nesting deeper than one row; only the first label position may be empty in a two- or three-atom button cell.
118
121
  7. Decodes only `\|`, `\}`, and `\\` in positional cells.
119
122
  8. Extracts the first complete valid payload from a tolerant comment envelope and ignores unrelated text or isolated unmatched matrix brackets around it.
120
123
  9. Returns no partial rows or cells from a balanced malformed candidate.
@@ -128,8 +131,9 @@ For `telegram_button` comments:
128
131
 
129
132
  - JSON `value` keeps its existing label/prompt fallback semantics.
130
133
  - Positional `{value}` is equivalent to JSON `{"value":"value"}`; a lone JSON `label` or `prompt` has the same both-fields shorthand semantics.
134
+ - Positional `{|prompt}` is equivalent to JSON `{"prompt":"prompt"}` and therefore uses the prompt as both visible text and queued prompt.
131
135
  - Positional `{label|prompt}` is equivalent to JSON `{"label":"label","prompt":"prompt"}`.
132
- - Positional `{label|prompt|selected_style}` is equivalent to the corresponding three-field JSON object.
136
+ - Positional `{label|prompt|selected_style}` and `{|prompt|selected_style}` are equivalent to their corresponding JSON objects.
133
137
  - Top-level cells become full-width rows.
134
138
  - Nested rows become horizontal keyboard rows.
135
139
  - Invalid payloads are stripped with their recognized action comment and register no callbacks.
@@ -153,7 +157,7 @@ The grammar imposes no visual row-width maximum. Renderer and interaction policy
153
157
  Accepted classes include:
154
158
 
155
159
  - Strict JSON objects and matrices.
156
- - Positional singleton, two-atom, and styled cells.
160
+ - Positional singleton, two-atom, prompt-only `{|prompt}`, and styled cells.
157
161
  - Matrices and rows with commas, without commas, or a mixture of boundaries.
158
162
  - Named JSON and positional cells mixed in one matrix or row.
159
163
  - Literal commas inside positional atoms and strict JSON strings.
@@ -162,7 +166,7 @@ Accepted classes include:
162
166
 
163
167
  Rejected classes include:
164
168
 
165
- - Empty payloads, matrices, rows, labels, prompts, or style atoms.
169
+ - Empty payloads, matrices, rows, one-atom cells, prompts, or style atoms; an empty label is valid only as the first position of a two- or three-atom button cell.
166
170
  - Leading or repeated element commas.
167
171
  - Missing commas between properties inside a JSON object.
168
172
  - Deeper row nesting.
@@ -175,4 +179,4 @@ Every rejected case proves zero callback registration.
175
179
 
176
180
  ## Versioning
177
181
 
178
- This document defines CML v3. V3 extends the v2 positional grammar with strict JSON object cells, mixed representation, and optional element-boundary commas. It does not make JSON object internals permissive and does not add deeper structures. Future versions must preserve strict-JSON-first routing, bounded depth, atomic rejection, and an explicit discriminator for any new meaning at a security or ownership boundary.
182
+ This document defines CML v3. V3 extends the v2 positional grammar with strict JSON object cells, mixed representation, optional element-boundary commas, and prompt-only button cells that preserve the established JSON fallback semantics. It does not make JSON object internals permissive and does not add deeper structures. Future versions must preserve strict-JSON-first routing, bounded depth, atomic rejection, and an explicit discriminator for any new meaning at a security or ownership boundary.
@@ -155,10 +155,10 @@ I can continue.
155
155
 
156
156
  Rules:
157
157
 
158
- - The payload may be a JSON object, adaptive JSON/CML matrix, or positional [Compact Matrix Literal](./compact-matrix-literal.md). Named JSON objects and positional cells may coexist in one matrix or row. Commas are optional between completed elements, and one trailing comma before a closing delimiter is tolerated; JSON object validation likewise tolerates trailing commas but does not invent missing values, property names, or internal separators. CML uses `{value}`, `{label|prompt}`, or `{label|prompt|selected_style}`; the optional third atom requires a prompt and accepts only `primary`, `success`, or `danger`. It trims every atom, preserves non-structural printable text, and decodes only `\|`, `\}`, and `\\`.
159
- - Use `label` plus `prompt`, or the compact `value` key when both strings are identical. If only `label`, only `prompt`, or one-field `{value}` is present, that string supplies both visible label and queued prompt. An explicit counterpart takes precedence over `value`. Use JSON with `\n` escapes for multiline prompts.
158
+ - The payload may be a JSON object, adaptive JSON/CML matrix, or positional [Compact Matrix Literal](./compact-matrix-literal.md). Named JSON objects and positional cells may coexist in one matrix or row. Commas are optional between completed elements, and one trailing comma before a closing delimiter is tolerated; JSON object validation likewise tolerates trailing commas but does not invent missing values, property names, or internal separators. CML uses `{value}`, `{label|prompt}`, `{|prompt}`, or the corresponding three-atom form with `selected_style`; the optional third atom requires a non-empty prompt and accepts only `primary`, `success`, or `danger`. It trims every atom, preserves non-structural printable text, and decodes only `\|`, `\}`, and `\\`.
159
+ - Use `label` plus `prompt`, or the compact `value` key when both strings are identical. If only `label`, only `prompt`, one-field `{value}`, or prompt-only `{|prompt}` is present, that string supplies both visible label and queued prompt. An explicit counterpart takes precedence over `value`. Use JSON with `\n` escapes for multiline prompts.
160
160
  - The opening marker must start at column zero on a top-level line outside fenced code, quotes, lists, and indented examples; otherwise it remains literal Markdown.
161
- - Prefer one matrix comment for multiple buttons. Each top-level JSON object or CML cell becomes one full-width inline-keyboard row in source order; a nested row groups one or more buttons horizontally. The parser imposes no artificial per-row width cap; empty rows, malformed cells, unknown/trailing CML escapes, a third unescaped CML separator, empty atoms, unknown selected styles, and deeper nesting are rejected atomically. Generated surfaces default to five columns and expand to six through eight only for short position-bearing labels. Repeated singular comments remain valid.
161
+ - Prefer one matrix comment for multiple buttons. Each top-level JSON object or CML cell becomes one full-width inline-keyboard row in source order; a nested row groups one or more buttons horizontally. The parser imposes no artificial per-row width cap; empty rows, malformed cells, unknown/trailing CML escapes, a third unescaped CML separator, empty prompt/style atoms, empty one-atom cells, unknown selected styles, and deeper nesting are rejected atomically. Only the first label position may be empty in a two- or three-atom button cell. Generated surfaces default to five columns and expand to six through eight only for short position-bearing labels. Repeated singular comments remain valid.
162
162
  - Button actions are stored in memory with short `callback_data`; Telegram never sees the full prompt in the button payload.
163
163
  - After Telegram accepts a generated button callback as a queued prompt, the bridge changes that exact button to its configured selection style without changing agent-authored text or emoji. Set `selected_style` to `primary` (blue), `success` (green), or `danger` (red); omitted or invalid values fall back to `primary`. The style never suppresses queue admission. Other choices stay visually unchanged and remain available; the callback acknowledgement remains the fallback on clients that do not render button styles.
164
164
  - When generated button markup is the entire assistant reply, the bridge supplies the standard `☑️ **Choose an option:**` heading as visible message text so Telegram has a message to which it can attach the inline keyboard.
@@ -66,7 +66,7 @@ This command surface is a mobile companion subset, not a raw terminal-command br
66
66
  - `telegram_message(text, chat_id?, thread_id?)` sends a direct Telegram Markdown message when this Pi instance owns `/telegram-connect` or is registered with the multi-instance bus. During an active Telegram turn, omitted targeting and an explicit target equal to that turn are rejected so the ordinary final-reply path remains the sole current-target response; an explicit different chat/thread target remains allowed for requested cross-target delivery. Outside active turns, paired/default local/TUI delivery remains unchanged. Top-level `telegram_button` comments inside `text` are parsed with the same planner used for normal replies and attached to that message; buttons are never standalone Telegram messages.
67
67
  - The bundled `telegram-bridge` Skill owns action syntax, target routing, Threaded Mode, formatting, Generative App operation, and profile-specific debugging guidance. The regular prompt routes applicable turns to that Skill. `telegram_attach`, `telegram_bind`, and `telegram_message` remain registered but are model-active only while this instance owns direct transport or holds a live follower registration; disconnect/loss suppresses their schemas and prompt metadata, and recovery restores only the operator's previously active pi-telegram subset.
68
68
  - `telegram_voice` hidden comments request Telegram-native voice delivery through `{text}`, `{text|lang}`, `{text|lang|rate}`, or a JSON object. JSON is the fallback for multiline content, named fields, or escaping; equivalent `text` or `value` supplies the spoken payload, with explicit `text` taking precedence.
69
- - `telegram_button` hidden comments create inline buttons whose taps enqueue prompts. One marker accepts a JSON object, adaptive JSON/CML matrix, or positional [Compact Matrix Literal](./compact-matrix-literal.md). Named JSON objects and positional cells may coexist in one matrix or row; separators are optional and one trailing comma is tolerated at matrix, row, and JSON-object boundaries. Top-level cells become full-width rows, while nested rows group one or more buttons horizontally without an artificial parser-width cap. CML uses `{value}`, `{label|prompt}`, or `{label|prompt|selected_style}`; the optional third atom requires a prompt and accepts only `primary`, `success`, or `danger`. It trims atom boundaries and supports only the minimal escapes `\|`, `\}`, and `\\`. Prefer one matrix comment for multiple buttons. Use JSON `label` plus `prompt`, or `value` when both strings are identical. Action markers are colon-free; colon-prefixed payloads are rejected. Use top-level column-zero comments outside code, quotes, lists, and indented examples; do not emit standalone button actions.
69
+ - `telegram_button` hidden comments create inline buttons whose taps enqueue prompts. One marker accepts a JSON object, adaptive JSON/CML matrix, or positional [Compact Matrix Literal](./compact-matrix-literal.md). Named JSON objects and positional cells may coexist in one matrix or row; separators are optional and one trailing comma is tolerated at matrix, row, and JSON-object boundaries. Top-level cells become full-width rows, while nested rows group one or more buttons horizontally without an artificial parser-width cap. CML uses `{value}`, `{label|prompt}`, prompt-only `{|prompt}`, or the corresponding three-atom form with `selected_style`; an omitted label uses the existing prompt-as-label fallback, and the optional third atom requires a non-empty prompt and accepts only `primary`, `success`, or `danger`. It trims atom boundaries and supports only the minimal escapes `\|`, `\}`, and `\\`. Prefer one matrix comment for multiple buttons. Use JSON `label` plus `prompt`, or `value` when both strings are identical. Action markers are colon-free; colon-prefixed payloads are rejected. Use top-level column-zero comments outside code, quotes, lists, and indented examples; do not emit standalone button actions.
70
70
 
71
71
  Prompt guidance is context-aware: local/TUI prompts see only explicit direct-delivery guidance, while Telegram-originated turns receive the full action-comment syntax and phone-width output contract.
72
72
 
@@ -276,22 +276,27 @@ function parseTelegramButtonCompactActionPayload(
276
276
  atoms: readonly string[],
277
277
  ): Record<string, unknown> | undefined {
278
278
  const [label, prompt, selectedStyle] = atoms;
279
- if (atoms.length === 1) return { value: label };
280
- if (atoms.length === 2) return { label, prompt };
279
+ if (atoms.length === 1) return label ? { value: label } : undefined;
280
+ if (!prompt) return undefined;
281
+ const action = label ? { label, prompt } : { prompt };
282
+ if (atoms.length === 2) return action;
281
283
  if (
282
284
  selectedStyle !== "primary" &&
283
285
  selectedStyle !== "success" &&
284
286
  selectedStyle !== "danger"
285
287
  ) return undefined;
286
- return { label, prompt, selected_style: selectedStyle };
288
+ return { ...action, selected_style: selectedStyle };
287
289
  }
288
290
 
289
291
  function parseTelegramVoiceCompactActionPayload(
290
292
  atoms: readonly string[],
291
293
  ): Record<string, unknown> | undefined {
292
294
  const [text, lang, rate] = atoms;
295
+ if (!text) return undefined;
293
296
  if (atoms.length === 1) return { text };
297
+ if (!lang) return undefined;
294
298
  if (atoms.length === 2) return { text, lang };
299
+ if (!rate) return undefined;
295
300
  return { text, lang, rate };
296
301
  }
297
302
 
@@ -318,7 +323,7 @@ function parseTelegramAdaptiveActionPayloadRows(
318
323
  };
319
324
  const normalizeAtom = (value: string): string | undefined => {
320
325
  const normalized = value.trim();
321
- return normalized && !TELEGRAM_COMPACT_ACTION_CONTROL_PATTERN.test(normalized)
326
+ return !TELEGRAM_COMPACT_ACTION_CONTROL_PATTERN.test(normalized)
322
327
  ? normalized
323
328
  : undefined;
324
329
  };
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@llblab/pi-telegram",
3
- "version": "0.42.0",
3
+ "version": "0.42.1",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -52,11 +52,12 @@ CML trims atom boundaries and decodes `\|`, `\}`, and `\\`. Keep one complete ac
52
52
 
53
53
  ### Prompt Buttons
54
54
 
55
- Every button has a short distinct `emoji + space + text` label, a self-contained prompt, and an optional selection style. A click creates an ordinary user request; it never grants authority or bypasses confirmation.
55
+ Every button has a self-contained prompt and an optional selection style. Use a short distinct `emoji + space + text` label when separate human-readable labeling adds meaning; established coordinates or symbolic tokens may use the prompt itself as visible text. A click creates an ordinary user request; it never grants authority or bypasses confirmation.
56
56
 
57
57
  - `{prompt}` uses the same text for label and prompt.
58
+ - `{|prompt}` omits a separately authored label and uses the prompt as both visible text and queued prompt.
58
59
  - `{label|prompt}` separates visible label from queued prompt.
59
- - `{label|prompt|selected_style}` accepts `primary`, `success`, or `danger`.
60
+ - `{label|prompt|selected_style}` and `{|prompt|selected_style}` accept `primary`, `success`, or `danger`.
60
61
  - Top-level cells form vertical rows; one nested row groups horizontal peers.
61
62
  - Prefer one matrix comment for the complete surface.
62
63
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@llblab/pi-kit",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -43,7 +43,7 @@
43
43
  "@llblab/pi-actors": "0.52.0",
44
44
  "@llblab/pi-codex-usage": "0.9.4",
45
45
  "@llblab/pi-grow-loop": "0.7.3",
46
- "@llblab/pi-telegram": "0.42.0"
46
+ "@llblab/pi-telegram": "0.42.1"
47
47
  },
48
48
  "bundledDependencies": [
49
49
  "@llblab/pi-actors",