create-pmos 0.795.0 → 0.797.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.
@@ -0,0 +1,230 @@
1
+ /* pm/a2ui-view.js — another agent's A2UI v1.0 surface, drawn in the chat with PMOS's own parts (bet A459b, job #1752). WAITS FOR WAWAN'S
2
+ * FINAL YES: a new agent path that draws untrusted input, so its pull request stays out of auto-merge until he says yes.
3
+ *
4
+ * A connected agent's answer carries A2UI messages (JSONL) in one fenced `a2ui` block. The page builds the surface from them and draws
5
+ * the basic catalog's parts with the chat's own classes: never the sender's styles, markup or code. A press on a Button goes back to
6
+ * that same chat session as the A2UI action message, in words; it writes no PMOS record.
7
+ *
8
+ * split(text) → { text, blocks: [jsonl] } the words without the a2ui blocks PURE
9
+ * build(jsonl) → { ok, surfaces: [{ id, components: Map, data }] } | { ok: false, why } the messages applied in order PURE
10
+ * viewHtml(surface, o) → the surface as HTML, or the one plain line when it cannot be shown PURE
11
+ * actionOf(surface, componentId, at) → the A2UI v1.0 renderer_to_agent action message for a press PURE
12
+ * a2uiUi({ send, redraw }) → { split, html(blocks, key, o), owns(button), press(button) → boolean, input(el) → boolean }
13
+ *
14
+ * WHAT IS REFUSED (the whole surface shows one line, "PMOS can't show this surface"): a component outside the basic catalog, a property
15
+ * the catalog does not define, a function call (code that runs in the renderer), a local action (such as openUrl), an Image from an
16
+ * outside address (only the image bytes the agent sent, as a data address, are drawn), text that holds markup or a script, and more than MAX_COMPONENTS parts. Video, AudioPlayer and Modal show as one
17
+ * plain line each that names them, never as a player or an outside link. */
18
+ const esc = (s) => String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c]));
19
+
20
+ export const MAX_COMPONENTS = 200;
21
+ export const CANT = "PMOS can't show this surface. The agent's words stay above.";
22
+ const COMMON = ['id', 'component', '@catalogId', '@accessibility', 'weight'];
23
+ // the basic catalog's parts and the properties each one may carry (lib/a2ui-v1/catalog.json)
24
+ export const PARTS = {
25
+ Text: ['text', 'variant'], Image: ['url', 'description', 'fit', 'variant'], Icon: ['name'], Video: ['url', 'posterUrl'], AudioPlayer: ['url', 'description'],
26
+ Row: ['children', 'justify', 'align'], Column: ['children', 'justify', 'align'], List: ['children', 'direction', 'align'], Card: ['child'],
27
+ Tabs: ['tabs'], Modal: ['trigger', 'content'], Divider: ['axis'], Button: ['child', 'variant', 'action', '@checks'],
28
+ TextField: ['label', 'value', 'placeholder', 'variant', '@checks'], CheckBox: ['label', 'value', '@checks'],
29
+ ChoicePicker: ['label', 'options', 'value', 'variant', 'displayStyle', 'filterable', '@checks'], Slider: ['label', 'value', 'min', 'max', 'steps', '@checks'],
30
+ DateTimeInput: ['value', 'enableDate', 'enableTime', 'min', 'max', 'label', '@checks'],
31
+ };
32
+ const MARKUP = /<\s*\/?\s*[a-z!]|javascript:|data:text\/html|(^|[\s"'])on[a-z]+\s*=/i;
33
+ const BLOCK = /```a2ui[ \t]*\n?([\s\S]*?)```/g;
34
+
35
+ export function split(text) {
36
+ const blocks = [];
37
+ const rest = String(text == null ? '' : text).replace(BLOCK, (all, body) => { blocks.push(body); return ''; });
38
+ return { text: blocks.length ? rest.replace(/\n{3,}/g, '\n\n').trim() : rest, blocks };
39
+ }
40
+
41
+ /** Why a value cannot be shown, or '' when it can: markup or a script in any string, or a function call anywhere. */
42
+ function badValue(v, depth = 0) {
43
+ if (depth > 12) return 'too deep';
44
+ if (typeof v === 'string') return MARKUP.test(v) ? 'markup in text' : '';
45
+ if (Array.isArray(v)) { for (const x of v) { const b = badValue(x, depth + 1); if (b) return b; } return ''; }
46
+ if (v && typeof v === 'object') {
47
+ if ('call' in v || '@call' in v) return 'a function call';
48
+ for (const [k, x] of Object.entries(v)) { if (MARKUP.test(k)) return 'markup in a key'; const b = badValue(x, depth + 1); if (b) return b; }
49
+ }
50
+ return '';
51
+ }
52
+
53
+ function checkComponent(c) {
54
+ if (!c || typeof c !== 'object' || typeof c.id !== 'string' || !c.id) return 'a part with no id';
55
+ const allowed = PARTS[c.component];
56
+ if (!allowed) return `an unknown part (${String(c.component).slice(0, 40)})`;
57
+ for (const k of Object.keys(c)) if (!COMMON.includes(k) && !allowed.includes(k)) return `an unknown property ${k} on ${c.component}`;
58
+ const b = badValue(c); if (b) return b;
59
+ // an image is drawn only from the bytes the agent sent (a PNG, JPEG, GIF or WebP data address): never fetched from an address, not even
60
+ // this server's own, so a surface can make no request
61
+ if (c.component === 'Image' && !(typeof c.url === 'string' && /^data:image\/(png|jpeg|gif|webp);base64,[A-Za-z0-9+/=]+$/.test(c.url))) return 'an image from an outside address';
62
+ if (c.component === 'Button') {
63
+ const a = c.action;
64
+ if (!a || typeof a !== 'object' || !a.event || typeof a.event.name !== 'string') return 'a button that runs something in the page';
65
+ for (const k of Object.keys(a)) if (k !== 'event') return 'a button that runs something in the page';
66
+ }
67
+ return '';
68
+ }
69
+
70
+ /** The messages applied in order. A message that is not A2UI v1.0, or a part that is refused, refuses the whole surface. */
71
+ export function build(jsonl) {
72
+ const lines = String(jsonl || '').split('\n').map((l) => l.trim()).filter(Boolean);
73
+ if (!lines.length) return { ok: false, why: 'no messages' };
74
+ const surfaces = new Map(), refused = new Map();
75
+ for (const line of lines) {
76
+ let m; try { m = JSON.parse(line); } catch { return { ok: false, why: 'a line that is not JSON' }; }
77
+ if (!m || m.version !== '1.0') return { ok: false, why: 'not A2UI v1.0' };
78
+ const keys = Object.keys(m).filter((k) => k !== 'version');
79
+ if (keys.length !== 1) return { ok: false, why: 'a message with ' + keys.length + ' parts' };
80
+ const kind = keys[0], body = m[kind] || {};
81
+ const sid = typeof body.surfaceId === 'string' ? body.surfaceId : '';
82
+ if (!sid) return { ok: false, why: 'a message with no surfaceId' };
83
+ if (kind === 'createSurface') {
84
+ if (surfaces.has(sid)) return { ok: false, why: 'a surface created twice' };
85
+ surfaces.set(sid, { id: sid, catalogId: body.catalogId || '', components: new Map(), data: {} });
86
+ if (body.components) { const r = addComponents(surfaces.get(sid), body.components); if (r) refused.set(sid, r); }
87
+ if (body.dataModel !== undefined) { const b = badValue(body.dataModel); if (b) refused.set(sid, b); else surfaces.get(sid).data = clone(body.dataModel); }
88
+ } else if (kind === 'updateComponents') {
89
+ const s = surfaces.get(sid); if (!s) return { ok: false, why: 'an update before its surface' };
90
+ const r = addComponents(s, body.components); if (r) refused.set(sid, r);
91
+ } else if (kind === 'updateDataModel') {
92
+ const s = surfaces.get(sid); if (!s) return { ok: false, why: 'an update before its surface' };
93
+ const b = badValue(body.value); if (b) { refused.set(sid, b); continue; }
94
+ setPath(s.data, body.path || '/', clone(body.value));
95
+ } else if (kind === 'deleteSurface') { surfaces.delete(sid); refused.delete(sid); }
96
+ else return { ok: false, why: 'a message PMOS does not take (' + kind + ')' };
97
+ }
98
+ const out = [...surfaces.values()].map((s) => (refused.has(s.id) ? { ...s, refused: refused.get(s.id) } : s));
99
+ return { ok: true, surfaces: out };
100
+ }
101
+ const clone = (v) => (v === undefined ? undefined : JSON.parse(JSON.stringify(v)));
102
+ function addComponents(s, list) {
103
+ if (!Array.isArray(list) || !list.length) return 'a components list that is empty';
104
+ for (const c of list) { const r = checkComponent(c); if (r) return r; s.components.set(c.id, c); }
105
+ if (s.components.size > MAX_COMPONENTS) return 'more than ' + MAX_COMPONENTS + ' parts';
106
+ return '';
107
+ }
108
+ const parts = (p) => String(p || '').split('/').filter(Boolean).map((x) => x.replace(/~1/g, '/').replace(/~0/g, '~'));
109
+ function getPath(data, p) { let o = data; for (const k of parts(p)) { if (o == null) return undefined; o = o[k]; } return o; }
110
+ function setPath(data, p, v) {
111
+ const ks = parts(p); if (!ks.length) { if (v && typeof v === 'object') { for (const k of Object.keys(data)) delete data[k]; Object.assign(data, v); } return; }
112
+ let o = data; for (const k of ks.slice(0, -1)) { if (o[k] == null || typeof o[k] !== 'object') o[k] = {}; o = o[k]; }
113
+ if (v === null) delete o[ks.at(-1)]; else o[ks.at(-1)] = v;
114
+ }
115
+ /** A path inside a template child is read against the item it was made for. */
116
+ const abs = (p, scope) => (String(p).startsWith('/') ? p : (scope || '') + '/' + p);
117
+ const val = (v, s, scope) => (v && typeof v === 'object' && typeof v['@path'] === 'string' ? getPath(s.data, abs(v['@path'], scope)) : v);
118
+ const str = (v, s, scope) => { const x = val(v, s, scope); return x == null ? '' : typeof x === 'object' ? '' : String(x); };
119
+
120
+ function childIds(c, s, scope) {
121
+ const ch = c.children;
122
+ if (Array.isArray(ch)) return ch.map((id) => [id, scope]);
123
+ if (ch && typeof ch === 'object' && ch.componentId && ch.path) {
124
+ const list = getPath(s.data, abs(ch.path, scope));
125
+ return Array.isArray(list) ? list.slice(0, 50).map((x, i) => [ch.componentId, abs(ch.path, scope) + '/' + i]) : [];
126
+ }
127
+ return [];
128
+ }
129
+
130
+ function partHtml(id, s, scope, o, seen) {
131
+ const c = s.components.get(id);
132
+ if (!c || seen.size > MAX_COMPONENTS * 2) return '';
133
+ const key = id + '@' + (scope || '');
134
+ if (seen.has(key)) return '';
135
+ seen.add(key);
136
+ const live = o.live !== false;
137
+ const kid = (cid, sc = scope) => partHtml(cid, s, sc, o, seen);
138
+ const attr = (extra) => `data-a2-s="${esc(s.id)}" data-a2-c="${esc(c.id)}" data-a2-scope="${esc(scope || '')}"${extra || ''}`;
139
+ const label = (v) => (v !== undefined ? `<span class="a2-l">${esc(str(v, s, scope))}</span>` : '');
140
+ switch (c.component) {
141
+ case 'Text': return `<p class="${c.variant === 'caption' ? 'a2-cap' : 'a2-t'}">${esc(str(c.text, s, scope))}</p>`;
142
+ case 'Icon': return `<span class="a2-icon">${esc(str(c.name, s, scope))}</span>`;
143
+ case 'Image': return `<img class="a2-img" alt="${esc(str(c.description, s, scope))}" src="${esc(str(c.url, s, scope))}">`;
144
+ case 'Video': case 'AudioPlayer': return `<p class="a2-cap">${c.component === 'Video' ? 'A video' : 'A sound file'} the agent sent: ${esc(str(c.url, s, scope))}</p>`;
145
+ case 'Modal': return `<div class="a2-col">${kid(c.trigger)}<p class="a2-cap">It opens more in the agent's own app.</p></div>`;
146
+ case 'Divider': return '<hr class="a2-hr">';
147
+ case 'Row': return `<div class="a2-row">${childIds(c, s, scope).map(([x, sc]) => kid(x, sc)).join('')}</div>`;
148
+ case 'Column': case 'List': return `<div class="a2-col">${childIds(c, s, scope).map(([x, sc]) => kid(x, sc)).join('')}</div>`;
149
+ case 'Card': return `<div class="cc-card a2-card">${kid(c.child)}</div>`;
150
+ case 'Tabs': return `<div class="a2-col">${(Array.isArray(c.tabs) ? c.tabs : []).map((t) => `<p class="cc-h">${esc(str(t.title, s, scope))}</p>${kid(t.child)}`).join('')}</div>`;
151
+ case 'Button': return `<button type="button" class="pm-btn${c.variant === 'primary' ? ' primary' : ''}" ${attr(' data-a2-press')}${live ? '' : ' disabled'}>${kid(c.child) || esc(c.action.event.name)}</button>`;
152
+ case 'TextField': return `<label class="a2-f">${label(c.label)}<input type="text" ${attr(' data-a2-in')} value="${esc(str(c.value, s, scope))}" placeholder="${esc(str(c.placeholder, s, scope))}"${live ? '' : ' disabled'}></label>`;
153
+ case 'CheckBox': return `<label class="a2-f a2-row"><input type="checkbox" ${attr(' data-a2-in')}${val(c.value, s, scope) === true ? ' checked' : ''}${live ? '' : ' disabled'}>${label(c.label)}</label>`;
154
+ case 'Slider': return `<label class="a2-f">${label(c.label)}<input type="range" ${attr(' data-a2-in')} min="${esc(Number(val(c.min, s, scope)) || 0)}" max="${esc(Number(val(c.max, s, scope)) || 0)}" value="${esc(Number(val(c.value, s, scope)) || 0)}"${live ? '' : ' disabled'}></label>`;
155
+ case 'DateTimeInput': return `<label class="a2-f">${label(c.label)}<input type="${c.enableTime && !c.enableDate ? 'time' : c.enableTime ? 'datetime-local' : 'date'}" ${attr(' data-a2-in')} value="${esc(str(c.value, s, scope).slice(0, c.enableTime ? 16 : 10))}"${live ? '' : ' disabled'}></label>`;
156
+ case 'ChoicePicker': {
157
+ const on = val(c.value, s, scope), sel = Array.isArray(on) ? on : [];
158
+ return `<div class="a2-f">${label(c.label)}<div class="chips2">${(Array.isArray(c.options) ? c.options : []).map((op) => `<button type="button" class="chip chip2${sel.includes(op.value) ? ' on' : ''}" aria-pressed="${sel.includes(op.value)}" ${attr(` data-a2-opt="${esc(op.value)}"`)}${live ? '' : ' disabled'}>${esc(str(op.label, s, scope))}</button>`).join('')}</div></div>`;
159
+ }
160
+ default: return '';
161
+ }
162
+ }
163
+
164
+ export function viewHtml(s, o = {}) {
165
+ if (!s || s.refused || !s.components.has('root')) return `<p class="cc-miss" role="note">${esc(CANT)}</p>`;
166
+ return `<div class="a2-surface" role="group" aria-label="${esc('From the agent: ' + s.id)}">${partHtml('root', s, '', o, new Set())}</div>`;
167
+ }
168
+
169
+ /** The A2UI v1.0 renderer_to_agent action for a press: the Button's event, its context bindings read from the data model. */
170
+ export function actionOf(s, componentId, at = new Date().toISOString(), scope = '') {
171
+ const c = s && s.components.get(componentId);
172
+ if (!c || c.component !== 'Button') return null;
173
+ const ev = c.action.event, context = {};
174
+ for (const [k, v] of Object.entries(ev.context || {})) context[k] = val(v, s, scope) === undefined ? null : val(v, s, scope);
175
+ const msg = { version: '1.0', action: { name: ev.name, surfaceId: s.id, sourceComponentId: c.id, timestamp: at, context } };
176
+ if (ev.userMessage !== undefined) msg.action.userMessage = str(ev.userMessage, s, scope);
177
+ return msg;
178
+ }
179
+
180
+ /** What goes back to the agent: one message in the chat, to the same session that drew the surface. */
181
+ export const sayOf = (msg) => `I pressed "${msg.action.name}" on your surface ${msg.action.surfaceId}. The A2UI action:\n\`\`\`json\n${JSON.stringify(msg)}\n\`\`\``;
182
+
183
+ export function a2uiUi(host) {
184
+ const S = new Map(); // key → { surfaces }
185
+ const find = (sid) => { for (const v of S.values()) for (const s of v.surfaces || []) if (s.id === sid) return s; return null; };
186
+ return {
187
+ split,
188
+ html(blocks, key, o = {}) {
189
+ if (!blocks || !blocks.length) return '';
190
+ return blocks.map((b, i) => {
191
+ const k = key + ':' + i;
192
+ if (!S.has(k)) { const r = build(b); S.set(k, r.ok ? { surfaces: r.surfaces } : { why: r.why, surfaces: [] }); }
193
+ const v = S.get(k);
194
+ if (!v.surfaces.length) return `<p class="cc-miss" role="note">${esc(CANT)}</p>`;
195
+ return v.surfaces.map((s) => viewHtml(s, o)).join('');
196
+ }).join('');
197
+ },
198
+ /** True when the button is part of a surface: the chat checks this first, so its other buttons stay synchronous. */
199
+ owns: (b) => !!(b && b.dataset && b.dataset.a2S),
200
+ async press(b) {
201
+ const d = (b && b.dataset) || {};
202
+ if (!d.a2S) return false;
203
+ const s = find(d.a2S); if (!s) return true;
204
+ const c = s.components.get(d.a2C);
205
+ if (d.a2Opt !== undefined && c && c.component === 'ChoicePicker' && c.value && c.value['@path']) {
206
+ const p = abs(c.value['@path'], d.a2Scope), cur = getPath(s.data, p), list = Array.isArray(cur) ? cur.slice() : [];
207
+ const i = list.indexOf(d.a2Opt);
208
+ const next = c.variant === 'multipleSelection' ? (i >= 0 ? list.filter((x) => x !== d.a2Opt) : [...list, d.a2Opt]) : [d.a2Opt];
209
+ setPath(s.data, p, next); host.redraw(); return true;
210
+ }
211
+ if ('a2Press' in d) {
212
+ const msg = actionOf(s, d.a2C, undefined, d.a2Scope);
213
+ if (msg) { b.disabled = true; await host.send(sayOf(msg)); }
214
+ return true;
215
+ }
216
+ return true;
217
+ },
218
+ /** An input changed: its bound value in the surface's data model follows (two-way binding), so the next press sends it. */
219
+ input(el) {
220
+ const d = (el && el.dataset) || {};
221
+ if (!d.a2S || !('a2In' in d)) return false;
222
+ const s = find(d.a2S), c = s && s.components.get(d.a2C);
223
+ if (!c || !c.value || typeof c.value['@path'] !== 'string') return true;
224
+ const v = el.type === 'checkbox' ? !!el.checked : el.type === 'range' ? Number(el.value) : String(el.value);
225
+ setPath(s.data, abs(c.value['@path'], d.a2Scope), v);
226
+ return true;
227
+ },
228
+ state: S,
229
+ };
230
+ }
@@ -22,6 +22,11 @@ const STATE = { 'to do': 'To do', todo: 'To do', 'in progress': 'In progress', d
22
22
  const stateOf = (s) => STATE[String(s || '').trim().toLowerCase()] || String(s || '');
23
23
  const clean = (s) => String(s == null ? '' : s).replace(/^"|"$/g, '');
24
24
 
25
+ const RANK = {
26
+ post: (f, p, a) => ['/api/placements', { events: [{ ev: 'ranked', initiative: p[0], after: a.after == null ? null : String(a.after) }] }],
27
+ undo: (r, b, a) => ['/api/placements', { events: [{ ev: 'ranked', initiative: b.events[0].initiative, after: a.back == null ? null : String(a.back) }] }],
28
+ };
29
+
25
30
  /** The task family: what each "pmos task <sub>" sends, and how Undo puts it back. f: the filled flags, p: the positionals, a: the args. */
26
31
  const ROUTES = {
27
32
  'task set': {
@@ -29,6 +34,7 @@ const ROUTES = {
29
34
  const b = { task: p[0] };
30
35
  for (const k of ['due', 'start', 'owner', 'notes', 'description']) if (f[k] !== undefined) b[k] = f[k] === true ? '' : String(f[k]);
31
36
  if (f.milestone !== undefined) b.milestone = f.milestone === true ? true : f.milestone !== 'false';
37
+ if (f['no-milestone'] !== undefined) b.milestone = false; // a milestone's Back to a task
32
38
  if (f.pin !== undefined) b.pinned = f.pin === true ? true : f.pin !== 'false';
33
39
  return ['/api/boards/tasks/edit', b];
34
40
  },
@@ -47,9 +53,14 @@ const ROUTES = {
47
53
  undo: (r, b) => ['/api/boards/tasks/restore', { task: b.task }],
48
54
  },
49
55
  'task comment': { post: (f, p) => ['/api/boards/tasks/comment', { task: p[0], text: String(p[1] || '') }], deferred: true },
56
+ // Move up and Move down on the Roadmap (job #1818): the row names where each move puts it (lib/card-rows-route.js rank), as
57
+ // `pmos initiative up|down` computes it; Undo ranks it after the one it came after before
58
+ 'initiative up': RANK,
59
+ 'initiative down': RANK,
50
60
  };
51
61
  const FIELD = { 'task set': (b) => ['due', 'start', 'owner', 'notes', 'description', 'milestone', 'pinned'].find((k) => k in b) || 'task',
52
- 'task state': () => 'state', 'task add': () => 'task', 'task remove': () => 'removed', 'task comment': () => 'comment' };
62
+ 'task state': () => 'state', 'task add': () => 'task', 'task remove': () => 'removed', 'task comment': () => 'comment',
63
+ 'initiative up': () => 'rank', 'initiative down': () => 'rank' };
53
64
 
54
65
  export function routeOf(run) {
55
66
  const c = parseRun(run);
@@ -110,7 +121,7 @@ export async function runAction(o = {}, { pmPost, catalog } = {}) {
110
121
  const res = await pmPost(route, body).catch(() => null);
111
122
  if (!res || res.ok === false) return { ok: false, error: (res && res.error) || 'The change did not land.' };
112
123
  tell({ kind: o.kind, id: o.id, field, value, undo: false });
113
- const back = R.undo ? R.undo(res, body, { was: o.was }) : null;
124
+ const back = R.undo ? R.undo(res, body, { ...args, was: o.was }) : null;
114
125
  return { ok: true, said: act.label + ' done.', field, value, result: res,
115
126
  undo: back ? async () => {
116
127
  const u = await pmPost(back[0], { ws: o.ws, board: o.board, ...back[1] }).catch(() => null);
@@ -23,7 +23,8 @@
23
23
  * A wrong or closed id draws "<id> was not found" under the rows; PMOS's words above stay as they were. */
24
24
  const esc = (s) => String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c]));
25
25
  const SVG = (d) => `<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="${d}"/></svg>`;
26
- const ICON = { done: 'M5 12.5l4.5 4.5L19 7.5', go: 'M5 12.5l4.5 4.5L19 7.5', undo: 'M4 12a8 8 0 1 0 2.3-5.6M4 4v4.5h4.5' };
26
+ const ICON = { done: 'M5 12.5l4.5 4.5L19 7.5', go: 'M5 12.5l4.5 4.5L19 7.5', undo: 'M4 12a8 8 0 1 0 2.3-5.6M4 4v4.5h4.5',
27
+ diamond: 'M12 3l9 9-9 9-9-9z', up: 'M6 15l6-6 6 6', down: 'M6 9l6 6 6-6' };
27
28
 
28
29
  export const MAX_ROWS = 5;
29
30
  export const MAX_FIELDS = 2;
@@ -102,7 +103,7 @@ function rowHtml(r, key, i, o) {
102
103
  // never a blank part (card catalog rule 8, A511): a field with no value is left out, a row with no buttons has no buttons part
103
104
  const bits = [r.who || '', r.due ? 'due ' + dayText(r.due) : '', r.stage || '', r.note || ''].filter(Boolean);
104
105
  const badge = r.late ? `<span class="cc-badge late">${esc(r.late)}</span>` : BADGE[r.state] ? `<span class="cc-badge">${esc(BADGE[r.state])}</span>` : '';
105
- const acts = (o.buttons || []).filter((a) => !(a.label === 'Mark done' && r.state === 'Done')).map((a) => `<button type="button" class="hm-icb" data-cc-act="${esc(key)}|${i}|${esc(a.label)}" aria-label="${esc(a.label + ': ' + r.title)}" title="${esc(a.label)}"${o.live === false ? ' disabled' : ''}>${SVG(ICON[a.icon] || ICON.done)}</button>`).join('');
106
+ const acts = (o.buttons || []).filter((a) => canPress(a, r)).map((a) => `<button type="button" class="hm-icb" data-cc-act="${esc(key)}|${i}|${esc(a.label)}" aria-label="${esc(a.label + ': ' + r.title)}" title="${esc(a.label)}"${o.live === false ? ' disabled' : ''}>${SVG(ICON[a.icon] || ICON.done)}</button>`).join('');
106
107
  const did = o.did && o.did[r.id];
107
108
  const doneLine = did ? `<p class="cc-did" role="status">${esc(did.said)}${did.undo ? ` <button type="button" class="hm-undo" data-cc-undo="${esc(key)}|${esc(r.id)}">Undo</button>` : ''}</p>` : '';
108
109
  return `<li class="cc-row" data-cc-id="${esc(r.id)}"><div class="cc-t"><b>${esc(r.title || r.id)}</b>${bits.length ? `<span>${esc(bits.join(' · '))}</span>` : ''}${doneLine}</div>${badge}${acts ? `<span class="cc-acts">${acts}</span>` : ''}</li>`;
@@ -150,13 +151,37 @@ export function saidOf(label, title, args) {
150
151
  if (args.start) parts.push('start ' + dayText(args.start));
151
152
  if (args.owner) parts.push('owner ' + args.owner);
152
153
  if (args.to) parts.push(String(args.to));
153
- const verb = label === 'Mark done' ? 'Done:' : /date/i.test(label) ? 'Moved' : label + ':';
154
+ const verb = label === 'Mark done' ? 'Done:' : /date/i.test(label) ? 'Moved' : /^Move (up|down)$/.test(label) ? label.replace('Move', 'Moved') + ':' : label + ':';
154
155
  return `${verb} ${title}${parts.length ? (verb === 'Moved' ? ' ' : ', ') + parts.join(', ') : ''}.`;
155
156
  }
156
157
 
157
- /** The buttons a row shows: the kind's catalog buttons the page can run with no value to pick (Mark done). Others go to a picker. */
158
+ /** The catalog button each kind's rows show (job #1818). A button that needs a value (a date, a person, a stage) goes to a picker. */
159
+ export const ROW_BUTTONS = Object.freeze({ task: ['Mark done'], subtask: ['Mark done'], milestone: ['Back to a task'], initiative: ['Move up / down'] });
160
+ // a button whose command is "up|down" is two presses, one per word
161
+ const ALT = { up: 'Move up', down: 'Move down', top: 'Move to top', bottom: 'Move to bottom' };
162
+
163
+ /** The buttons a row shows: the kind's ROW_BUTTONS from the catalog that the page can run with no value to pick. "pmos initiative up|down
164
+ * <id>" gives two buttons, Move up (pmos initiative up <id>) and Move down. Never a button the page has no route for. */
158
165
  export function rowButtons(catalog, kind, routeOf) {
159
- return actionsOf(catalog, kind).filter((a) => a.who === 'you' && !a.field && a.run && routeOf(a.run) && /done/i.test(a.label));
166
+ const out = [];
167
+ for (const a of actionsOf(catalog, kind)) {
168
+ if (!(ROW_BUTTONS[kind] || []).includes(a.label) || a.who !== 'you' || a.field || !a.run) continue;
169
+ const sub = (String(a.run).trim().split(/\s+/)[2]) || '';
170
+ const alts = sub.includes('|') ? sub.split('|') : [null];
171
+ for (const x of alts) {
172
+ const b = x ? { ...a, label: ALT[x] || x, run: a.run.replace(sub, x), icon: x } : a;
173
+ if (routeOf(b.run)) out.push(b);
174
+ }
175
+ }
176
+ return out;
177
+ }
178
+ /** Can this row take the press? Done takes no Mark done; the top of the Roadmap takes no Move up, its end no Move down. */
179
+ function canPress(a, r) {
180
+ if (a.label === 'Mark done') return r.state !== 'Done';
181
+ if (a.label === 'Back to a task') return r.kind !== 'task';
182
+ if (a.label === 'Move up') return !!r.rank && 'up' in r.rank;
183
+ if (a.label === 'Move down') return !!r.rank && 'down' in r.rank;
184
+ return true;
160
185
  }
161
186
 
162
187
  /** The chat's part. host: { pmGet, pmPost, toast, ws: () => id, redraw, runAction, routeOf }. */
@@ -234,8 +259,10 @@ export function cardsUi(host) {
234
259
  if (!row) return true;
235
260
  b.disabled = true;
236
261
  told(ck, { pressed: [label] });
237
- const r = await host.runAction({ kind: spec.kind, action: label, id, args: {}, was: row.state, ws: host.ws && host.ws(), board: row.board }, { pmPost: host.pmPost, catalog: S.catalog });
238
- if (r && r.ok) S.did.set(ck + '|' + id, { said: saidOf(label, row.title, {}), undo: r.undo });
262
+ const act = (host.routeOf ? rowButtons(S.catalog, spec.kind, host.routeOf) : []).find((a) => a.label === label) || label;
263
+ const args = label === 'Move up' || label === 'Move down' ? { after: row.rank && row.rank[label === 'Move up' ? 'up' : 'down'], back: row.rank && row.rank.back } : {};
264
+ const r = await host.runAction({ kind: spec.kind, action: act, id, args, was: row.state, ws: host.ws && host.ws(), board: row.board }, { pmPost: host.pmPost, catalog: S.catalog });
265
+ if (r && r.ok) { S.did.set(ck + '|' + id, { said: saidOf(label, row.title, {}), undo: r.undo }); if (spec.kind === 'initiative') S.rows.delete(rowsKey(spec)); } // a move changes every row's place: read them again
239
266
  else if (host.toast) host.toast((r && (r.error || r.said || r.ask)) || 'Not saved.');
240
267
  b.disabled = false; host.redraw(); return true;
241
268
  }
@@ -244,7 +271,7 @@ export function cardsUi(host) {
244
271
  const did = S.did.get(k + '|' + id); if (!did || !did.undo) return true;
245
272
  b.disabled = true;
246
273
  const u = await did.undo();
247
- if (u && u.ok !== false) S.did.delete(k + '|' + id); else if (host.toast) host.toast((u && u.error) || 'The undo did not land.');
274
+ if (u && u.ok !== false) { S.did.delete(k + '|' + id); const sp = ui.specOf(k); if (sp && sp.kind === 'initiative') S.rows.delete(rowsKey(sp)); } else if (host.toast) host.toast((u && u.error) || 'The undo did not land.');
248
275
  host.redraw(); return true;
249
276
  }
250
277
  return false;
@@ -1073,3 +1073,16 @@ body.pm-ds :is(form#hmForm.hm-box, form.hm-box, .hm-box-rich):focus-within { box
1073
1073
  body.pm-ds form.hm-box :is(textarea, input):focus-visible { outline: none; box-shadow: none; }
1074
1074
  body.pm-ds form.hm-box button:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--composer-focus-line); }
1075
1075
  body.pm-ds .hm-send { width: 32px; height: 32px; border-radius: 50%; background: var(--blue); color: var(--on-blue); }
1076
+ /* a2ui-inbound-render: another agent's A2UI surface, drawn with the chat's own parts (pm/a2ui-view.js) */
1077
+ .a2-surface { display: flex; flex-direction: column; gap: var(--space-8); margin-top: var(--space-8); }
1078
+ .a2-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-8); }
1079
+ .a2-col { display: flex; flex-direction: column; gap: var(--space-8); }
1080
+ .a2-card { display: flex; flex-direction: column; gap: var(--space-8); }
1081
+ .a2-t { margin: 0; font-size: var(--fs-row); line-height: var(--lh-row); color: var(--cz-ink); overflow-wrap: anywhere; }
1082
+ .a2-cap, .a2-l { margin: 0; font-size: var(--fs-meta); line-height: var(--lh-meta); color: var(--cz-ink2); overflow-wrap: anywhere; }
1083
+ .a2-icon { font-size: var(--fs-meta); color: var(--cz-ink2); }
1084
+ .a2-img { max-width: 100%; max-height: 240px; border-radius: var(--radius-md, 14px); object-fit: contain; }
1085
+ .a2-hr { width: 100%; border: 0; border-top: 1px solid var(--cz-hair); margin: 0; }
1086
+ .a2-f { display: flex; flex-direction: column; gap: var(--space-4); }
1087
+ .a2-f.a2-row { flex-direction: row; }
1088
+ .a2-f input[type="text"], .a2-f input[type="date"], .a2-f input[type="time"], .a2-f input[type="datetime-local"] { min-height: 44px; padding: 0 var(--space-12); border-radius: var(--radius-md, 14px); border: 1px solid var(--cz-hair); background: var(--cz-card); color: var(--cz-ink); font: var(--fs-label)/1.25 var(--cz-sans); }
@@ -42,7 +42,8 @@ import { canDictate, dictate } from './home-dictate.js';
42
42
  import { adler } from './cozy-adler.js';
43
43
  import { snapOf, turnEnded } from './chat-turn-end.js'; // a finished turn re-reads what the Viewer shows (batch 25 item 3)
44
44
  import { nextPromptUi } from './next-prompt-ui.js'; // the suggested next prompt and the Sharper card above the box (batch 26 item 2)
45
- import { cardsUi } from './chat-cards.js'; // ask-cards-and-pickers: the rows an answer names, live, and a picker (canvas A2Cards, A2Ask)
45
+ import { cardsUi } from './chat-cards.js';
46
+ import { a2uiUi } from './a2ui-view.js'; // a2ui-inbound-render: another agent's A2UI v1.0 surface, drawn with PMOS's own parts; a press goes back as words // ask-cards-and-pickers: the rows an answer names, live, and a picker (canvas A2Cards, A2Ask)
46
47
  import { runAction, routeOf } from './action-run.js';
47
48
  import { tellCards } from './card-log.js'; // each answer's card list and each press to the local use log (card catalog rule 9, A511)
48
49
  /* The views a chat opens go in the Viewer: on a page with no dialog the old viewer's views draw in the cozy card (premium-viewer.js). */
@@ -90,7 +91,8 @@ export function mountChat(el, host) {
90
91
  const C = { t: null, th: null, conv: null, timer: null, show: 12, plOpen: false, plAll: false, open: new Set(), seq: 0, sending: false, files: [], seenAt: null, lastKey: null, picked: {}, pend: [], auto: { key: null, ctx: new Set(), rep: null, goal: null }, slashAt: 0 };
91
92
  const CU = cardsUi({ pmGet: (u) => host.pmGet(u), pmPost: (u, b) => host.pmPost(u, b), toast: (t) => host.toast(t), redraw: () => draw(), runAction, routeOf, tellCards,
92
93
  ws: () => (C.t && C.t.ws) || new URLSearchParams(location.search).get('ws') || '' });
93
- window.addEventListener('pmos:action', (e) => CU.onAction(e.detail)); // a row the chat shows follows a press or a chat write elsewhere
94
+ window.addEventListener('pmos:action', (e) => CU.onAction(e.detail));
95
+ const AU = a2uiUi({ send: (t) => send(t), redraw: () => draw() }); // a row the chat shows follows a press or a chat write elsewhere
94
96
  el.innerHTML = `<button type="button" class="hm-reopen" id="hmReopen" aria-label="Open the Viewer" title="Open the Viewer" hidden>${PANE}</button>`
95
97
  + '<div class="hm-chd" id="hmCh" hidden></div><div class="hm-sug" id="hmSug" hidden></div><div class="hm-plw" id="hmPl" hidden></div><div class="hm-log" id="hmLog" role="log" aria-live="polite"></div><div class="hm-foot" id="hmFoot"></div>';
96
98
  const log = el.querySelector('#hmLog'), foot = el.querySelector('#hmFoot'), reopen = el.querySelector('#hmReopen'), head = el.querySelector('#hmCh'), sug = el.querySelector('#hmSug'), pl = el.querySelector('#hmPl');
@@ -182,7 +184,9 @@ export function mountChat(el, host) {
182
184
  }
183
185
  const last = i === R.lastAgent;
184
186
  const asking = last && R.asking; // the message that asks before a change: no tools while the ask is open, and the name on its own line (AgChatAsk)
185
- const cd = CU.split(it.text); // the pmos-card and pmos-pick blocks (pm/chat-cards.js): drawn under the words, live
187
+ const a2 = AU.split(it.text); // a2ui blocks: another agent's surface (pm/a2ui-view.js), drawn after the words
188
+ const liveOf = { live: !((C.conv && C.conv.messages) || []).slice(it.mi + 1).some((x) => x.role === 'user') }; // its buttons work until the PM writes again
189
+ const cd = CU.split(a2.text); // the pmos-card and pmos-pick blocks (pm/chat-cards.js): drawn under the words, live
186
190
  const sr = splitSrc(cd.text); // chief-of-staff C1: the answer's sources, drawn under it (pm/chat-src.js)
187
191
  const g = splitGoal(sr.text), rp0 = splitReport(g.text), ak = splitAsk(splitChase(rp0.text).text), rp = { ...rp0, text: ak.text };
188
192
  const goal = C.th && C.th.goal, gl = it.mi === R.lastMsg && R.waiting && !!goal && goal.state === 'grilling';
@@ -190,7 +194,7 @@ export function mountChat(el, host) {
190
194
  // a run that stopped: the divider sits where it finished, over Claude's last message, and the fix sits under it (canvas XcbOptions, Routine)
191
195
  const stopAt = R.stop && i === R.lastAgent;
192
196
  const av = last && isClaude(R.role) ? adlerAvHtml(asking || ak.block ? 'needs-you' : stopAt ? 'honest' : running() ? 'thinking' : 'handled') : avHtml(R.role);
193
- return (stopAt ? dividerHtml({ tone: R.stop.tone, text: R.stop.text }) : '') + `<div class="hm-a${asking ? ' ask' : ''}${last ? ' last' : ''}">${av}<div class="hm-ab"><p class="hm-who">${esc(R.role.name)} <span>${esc(hm(it.at))}</span></p>${rp.text ? verHtml(rp.text) : ''}${CU.html(cd, 'm' + it.mi, { live: !((C.conv && C.conv.messages) || []).slice(it.mi + 1).some((x) => x.role === 'user') })}${srcHtml(sr.src)}${goalBlockHtml(go.block, go)}${reportChipHtml(rp.block, it.mi)}${R.chips(it.mi)}`
197
+ return (stopAt ? dividerHtml({ tone: R.stop.tone, text: R.stop.text }) : '') + `<div class="hm-a${asking ? ' ask' : ''}${last ? ' last' : ''}">${av}<div class="hm-ab"><p class="hm-who">${esc(R.role.name)} <span>${esc(hm(it.at))}</span></p>${rp.text ? verHtml(rp.text) : ''}${CU.html(cd, 'm' + it.mi, liveOf)}${AU.html(a2.blocks, 'm' + it.mi, liveOf)}${srcHtml(sr.src)}${goalBlockHtml(go.block, go)}${reportChipHtml(rp.block, it.mi)}${R.chips(it.mi)}`
194
198
  + (asking ? '' : `<div class="hm-tools" role="group" aria-label="Message actions"><button type="button" data-hm-copy="${i}">Copy</button>${last && !running() && !(stopAt && R.stop.actions.length) ? `<button type="button" data-hm-retry>Retry</button>` : ''}<button type="button" data-hm-wi="${i}">Make it a task</button></div>`) + '</div></div>'
195
199
  + (stopAt && R.stop.actions.length ? `<div class="hm-fix" role="group" aria-label="What to do next">${R.stop.actions.map((a, k) => iconBtn({ icon: a.icon, label: a.label, attr: a.data, pri: k === 0 })).join('')}</div>` : '')
196
200
  + blockAskHtml(ak.block, it, R);
@@ -621,6 +625,7 @@ export function mountChat(el, host) {
621
625
  if (b.dataset.hmCpt && C.cpt) { if (b.dataset.hmCpt === 'ok') host.compact(sid()); else host.dismissCompact(sid(), C.cpt.pct); C.cpt = null; sug.hidden = true; put(sug, ''); return; }
622
626
  if (b.dataset.hmSug && C.sug) { const g = C.sug; if (b.dataset.hmSug === 'link') host.linkTo(C.t.sid, g.id); else { host.dismissLink(C.t.sid); drawSug(); } return; }
623
627
  const d = b.dataset;
628
+ if (AU.owns(b)) { await AU.press(b); return; } // a press on another agent's surface goes back to it as one message (pm/a2ui-view.js)
624
629
  if (CU.owns(b)) { await CU.press(b); return; } // a row's button, a picker's choice, its ✓ or Undo (pm/chat-cards.js); any other button stays synchronous
625
630
  const ic = b.closest('.hm-icard'), card = C.t && C.t.intro && C.t.intro.card;
626
631
  if (ic && card && card.press) { if (await card.press(b)) draw(); return; }
@@ -706,6 +711,7 @@ export function mountChat(el, host) {
706
711
  if (e.key === 'Enter' && !e.shiftKey && !e.altKey && !e.ctrlKey && !e.metaKey) { e.preventDefault(); el.querySelector('#hmForm').requestSubmit(); }
707
712
  });
708
713
  el.addEventListener('input', (e) => {
714
+ if (AU.input(e.target)) return; // a field on another agent's surface: its bound value follows
709
715
  const card = C.t && C.t.intro && C.t.intro.card;
710
716
  if (card && card.input && e.target.closest('.hm-icard')) { card.input(e.target, e.target.closest('.hm-icard')); return; }
711
717
  if (e.target.id === 'hmIn') { grow(e.target); C.slashAt = 0; suggestFor(e.target.value); drawSlash(); NPU.input(e.target.value); if (C.err) { C.err = ''; const er = foot.querySelector('.hm-senderr'); if (er) er.remove(); foot.__h = null; } }
@@ -0,0 +1,9 @@
1
+ {
2
+ "_comment": "a2ui-inbound-render (job #1752, A459b): another agent's A2UI v1.0 surface drawn in the PMOS chat with PMOS's own parts; unsafe surfaces refused whole; a press goes back as words. The page module on plain objects, cross-checked against the vendored A2UI v1.0 schemas. No browser, no network.",
3
+ "modules": [
4
+ "a2ui-inbound.test.js"
5
+ ],
6
+ "seconds": {
7
+ "a2ui-inbound.test.js": 1
8
+ }
9
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "_comment": "a2ui-mcp-outbound (job #1751, A459a): pmos mcp gives PMOS rows as A2UI v1.0 over MCP and runs a pressed button as its catalog command. The real launcher on stdio, the real task writer, and the vendored A2UI v1.0 schemas. No browser, no network.",
3
+ "modules": [
4
+ "a2ui-mcp.test.js"
5
+ ],
6
+ "seconds": {
7
+ "a2ui-mcp.test.js": 4
8
+ }
9
+ }