@thinkrun/cli 0.1.40 → 0.1.42
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -0
- package/dist/bin/thinkrun.js +9 -2
- package/dist/bin/thinkrun.js.map +1 -1
- package/dist/shared/analysis-plans.d.ts +10 -0
- package/dist/shared/analysis-plans.js +12 -0
- package/dist/shared/batch-steps.d.ts +49 -0
- package/dist/shared/batch-steps.js +171 -0
- package/dist/shared/batch-steps.test.js +127 -0
- package/dist/shared/issue-report.d.ts +10 -0
- package/dist/shared/issue-report.js +126 -0
- package/dist/shared/issue-report.test.ts +110 -0
- package/dist/shared/navigation-retry.d.ts +2 -0
- package/dist/shared/navigation-retry.js +26 -0
- package/dist/shared/navigation-retry.test.js +25 -0
- package/dist/shared/onboarding-metrics.d.ts +4 -0
- package/dist/shared/onboarding-metrics.js +53 -0
- package/dist/shared/selector-hints.d.ts +1 -0
- package/dist/shared/selector-hints.js +43 -0
- package/dist/shared/selector-hints.test.js +31 -0
- package/dist/shared/slack-report.d.ts +21 -0
- package/dist/shared/slack-report.js +381 -0
- package/dist/src/adapters/local.d.ts +1 -0
- package/dist/src/adapters/local.d.ts.map +1 -1
- package/dist/src/adapters/local.js +29 -5
- package/dist/src/adapters/local.js.map +1 -1
- package/dist/src/commands/actions.d.ts +12 -0
- package/dist/src/commands/actions.d.ts.map +1 -1
- package/dist/src/commands/actions.js +102 -13
- package/dist/src/commands/actions.js.map +1 -1
- package/dist/src/commands/audit.d.ts.map +1 -1
- package/dist/src/commands/audit.js +5 -4
- package/dist/src/commands/audit.js.map +1 -1
- package/dist/src/commands/config.d.ts.map +1 -1
- package/dist/src/commands/config.js +15 -0
- package/dist/src/commands/config.js.map +1 -1
- package/dist/src/commands/install-skills.d.ts +27 -0
- package/dist/src/commands/install-skills.d.ts.map +1 -0
- package/dist/src/commands/install-skills.js +81 -0
- package/dist/src/commands/install-skills.js.map +1 -0
- package/dist/src/commands/install.d.ts.map +1 -1
- package/dist/src/commands/install.js +44 -1
- package/dist/src/commands/install.js.map +1 -1
- package/dist/src/commands/login.d.ts +3 -0
- package/dist/src/commands/login.d.ts.map +1 -0
- package/dist/src/commands/login.js +62 -0
- package/dist/src/commands/login.js.map +1 -0
- package/dist/src/commands/setup.d.ts.map +1 -1
- package/dist/src/commands/setup.js +8 -16
- package/dist/src/commands/setup.js.map +1 -1
- package/dist/src/config/store.d.ts.map +1 -1
- package/dist/src/config/store.js +1 -0
- package/dist/src/config/store.js.map +1 -1
- package/dist/src/session/account-guidance.d.ts +10 -0
- package/dist/src/session/account-guidance.d.ts.map +1 -0
- package/dist/src/session/account-guidance.js +32 -0
- package/dist/src/session/account-guidance.js.map +1 -0
- package/dist/src/session/browser-login.d.ts +6 -0
- package/dist/src/session/browser-login.d.ts.map +1 -0
- package/dist/src/session/browser-login.js +83 -0
- package/dist/src/session/browser-login.js.map +1 -0
- package/package.json +2 -1
- package/skills/thinkrun/SKILL.md +66 -0
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deterministic projection of an approved Markdown report into one Slack message.
|
|
3
|
+
* The backend posts exactly `message`; the frontend preview renders the same blocks.
|
|
4
|
+
*
|
|
5
|
+
* Safety model: Markdown is parsed with a CommonMark parser, never with ad hoc regexes.
|
|
6
|
+
* User text only ever becomes `plain_text` (header) or rich_text `text` elements, which
|
|
7
|
+
* Slack does not interpret as mrkdwn, mentions, broadcasts or emoji shortcodes. No user,
|
|
8
|
+
* channel, usergroup or broadcast elements are ever produced. Only valid HTTPS links
|
|
9
|
+
* without credentials become link elements; nothing is fetched, uploaded or unfurled.
|
|
10
|
+
*
|
|
11
|
+
* The CommonMark parser (`mdast-util-from-markdown`) is supplied by each consumer, which
|
|
12
|
+
* declares the same pinned version, so resolution never depends on this package's location.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
export const SLACK_REPORT_TITLE_LIMIT = 256;
|
|
16
|
+
export const SLACK_REPORT_BODY_LIMIT = 12000;
|
|
17
|
+
export const SLACK_REPORT_MODES = ['compact', 'full'];
|
|
18
|
+
const HEADER_LIMIT = 150; // Slack header blocks accept at most 150 characters.
|
|
19
|
+
const BLOCK_LIMIT = 50; // Slack messages accept at most 50 blocks.
|
|
20
|
+
const BLOCK_TEXT_BUDGET = 2900;
|
|
21
|
+
const EXCERPT_LIMIT = 700;
|
|
22
|
+
const EVIDENCE_LIMIT = 10;
|
|
23
|
+
const NESTING_LIMIT = 12;
|
|
24
|
+
const LIST_INDENT_LIMIT = 6;
|
|
25
|
+
const CONTEXT_NOTE = 'Summary view of a ThinkRun report; the full report is not included.';
|
|
26
|
+
const RECORDING_NOTE = ' The recording link opens the source recording and its analysis, not this edited report.';
|
|
27
|
+
|
|
28
|
+
export class SlackReportError extends Error {
|
|
29
|
+
constructor(code, message) { super(message); this.name = 'SlackReportError'; this.code = code; }
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function safeSlackLinkUrl(value) {
|
|
33
|
+
if (typeof value !== 'string' || !value || value.length > 2000) return undefined;
|
|
34
|
+
try {
|
|
35
|
+
const url = new URL(value);
|
|
36
|
+
return url.protocol === 'https:' && url.hostname && !url.username && !url.password && url.href.length <= 2000 ? url.href : undefined;
|
|
37
|
+
} catch { return undefined; }
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const styled = style => Object.keys(style).length ? { style: { ...style } } : {};
|
|
41
|
+
const sameStyle = (a, b) => JSON.stringify(a.style || {}) === JSON.stringify(b.style || {});
|
|
42
|
+
function pushText(out, text, style = {}) {
|
|
43
|
+
if (!text) return;
|
|
44
|
+
const last = out[out.length - 1];
|
|
45
|
+
if (last?.type === 'text' && sameStyle(last, styled(style))) last.text += text;
|
|
46
|
+
else out.push({ type: 'text', text, ...styled(style) });
|
|
47
|
+
}
|
|
48
|
+
const inlineText = element => element.type === 'link' ? element.text || element.url : element.text || '';
|
|
49
|
+
const textLength = element => Array.isArray(element.elements) ? element.elements.reduce((n, child) => n + textLength(child), 0) : inlineText(element).length;
|
|
50
|
+
|
|
51
|
+
/** Visible text of any subtree, iteratively, so hostile nesting cannot exhaust the stack. */
|
|
52
|
+
function plainText(node) {
|
|
53
|
+
let out = '';
|
|
54
|
+
const stack = [node];
|
|
55
|
+
while (stack.length) {
|
|
56
|
+
const current = stack.pop();
|
|
57
|
+
if (typeof current === 'string') { out += current; continue; }
|
|
58
|
+
if (!current) continue;
|
|
59
|
+
if (current.type === 'image' || current.type === 'imageReference') out += current.alt || '';
|
|
60
|
+
else if (typeof current.value === 'string') out += current.value;
|
|
61
|
+
if (Array.isArray(current.children)) {
|
|
62
|
+
const separator = ['root', 'blockquote', 'list', 'listItem'].includes(current.type) ? '\n' : '';
|
|
63
|
+
for (let i = current.children.length - 1; i >= 0; i--) { stack.push(current.children[i]); if (separator && i) stack.push(separator); }
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return out;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function createConverter(definitions) {
|
|
70
|
+
const target = node => node.type === 'linkReference' || node.type === 'imageReference' ? definitions.get(node.identifier)?.url : node.url;
|
|
71
|
+
function inline(nodes, style = {}, out = [], depth = 0) {
|
|
72
|
+
for (const node of nodes) {
|
|
73
|
+
if (depth > NESTING_LIMIT) { pushText(out, plainText(node), style); continue; }
|
|
74
|
+
switch (node.type) {
|
|
75
|
+
case 'text': case 'html': pushText(out, node.value, style); break;
|
|
76
|
+
case 'inlineCode': pushText(out, node.value, { ...style, code: true }); break;
|
|
77
|
+
case 'break': pushText(out, '\n', style); break;
|
|
78
|
+
case 'strong': inline(node.children, { ...style, bold: true }, out, depth + 1); break;
|
|
79
|
+
case 'emphasis': inline(node.children, { ...style, italic: true }, out, depth + 1); break;
|
|
80
|
+
case 'image': case 'imageReference': {
|
|
81
|
+
const url = safeSlackLinkUrl(target(node));
|
|
82
|
+
const label = node.alt || 'Image';
|
|
83
|
+
if (url) out.push({ type: 'link', url, text: label, ...styled(linkStyle(style)) }); else pushText(out, label, style);
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
case 'link': case 'linkReference': {
|
|
87
|
+
const raw = target(node) || '';
|
|
88
|
+
const url = safeSlackLinkUrl(raw);
|
|
89
|
+
const label = plainText({ children: node.children });
|
|
90
|
+
if (!url) {
|
|
91
|
+
// Unsafe or malformed targets stay visible as text and are never linked.
|
|
92
|
+
inline(node.children, style, out, depth + 1);
|
|
93
|
+
if (raw && raw !== label) pushText(out, ` (${raw})`, style);
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
out.push({ type: 'link', url, text: label || url, ...styled(linkStyle(style)) });
|
|
97
|
+
// A linked screenshot keeps both destinations: the outer moment and the image itself.
|
|
98
|
+
for (const image of images(node)) {
|
|
99
|
+
const imageUrl = safeSlackLinkUrl(target(image));
|
|
100
|
+
if (imageUrl && imageUrl !== url) { pushText(out, ' (', style); out.push({ type: 'link', url: imageUrl, text: 'image' }); pushText(out, ')', style); }
|
|
101
|
+
}
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
default:
|
|
105
|
+
if (Array.isArray(node.children)) inline(node.children, style, out, depth + 1);
|
|
106
|
+
else if (typeof node.value === 'string') pushText(out, node.value, style);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return out;
|
|
110
|
+
}
|
|
111
|
+
const linkStyle = style => Object.fromEntries(Object.entries(style).filter(([name]) => name === 'bold' || name === 'italic'));
|
|
112
|
+
const section = (elements, extra = {}) => ({ type: 'rich_text_section', elements, ...extra });
|
|
113
|
+
|
|
114
|
+
/** mdast blocks → rich_text elements. Headings are tagged so callers can start a new Slack block. */
|
|
115
|
+
function blocks(nodes, depth = 0, out = []) {
|
|
116
|
+
for (const node of nodes) {
|
|
117
|
+
if (depth > NESTING_LIMIT) { addParagraph(out, [{ type: 'text', text: plainText(node) }]); continue; }
|
|
118
|
+
switch (node.type) {
|
|
119
|
+
case 'heading': { const elements = inline(node.children, { bold: true }); if (elements.length) out.push(section(elements, { heading: true })); break; }
|
|
120
|
+
case 'paragraph': addParagraph(out, inline(node.children)); break;
|
|
121
|
+
case 'html': addParagraph(out, node.value ? [{ type: 'text', text: node.value }] : []); break;
|
|
122
|
+
case 'code': if (node.value) out.push({ type: 'rich_text_preformatted', elements: [{ type: 'text', text: node.value }] }); break;
|
|
123
|
+
case 'blockquote': {
|
|
124
|
+
const elements = [];
|
|
125
|
+
node.children.forEach((child, i) => {
|
|
126
|
+
if (i) pushText(elements, '\n');
|
|
127
|
+
if (child.type === 'paragraph' || child.type === 'heading') inline(child.children, {}, elements, depth + 1); else pushText(elements, plainText(child));
|
|
128
|
+
});
|
|
129
|
+
if (elements.length) out.push({ type: 'rich_text_quote', elements });
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
case 'list': list(node, 0, out, depth); break;
|
|
133
|
+
case 'thematicBreak': out.push({ type: 'divider' }); break;
|
|
134
|
+
case 'definition': break;
|
|
135
|
+
default: { const text = plainText(node); if (text) addParagraph(out, [{ type: 'text', text }]); }
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return out;
|
|
139
|
+
}
|
|
140
|
+
function addParagraph(out, elements) {
|
|
141
|
+
if (!elements.length) return;
|
|
142
|
+
const last = out[out.length - 1];
|
|
143
|
+
// Consecutive paragraphs share one section separated by a blank line, as Slack itself does.
|
|
144
|
+
if (last?.type === 'rich_text_section' && !last.heading) { pushText(last.elements, '\n\n'); for (const element of elements) element.type === 'text' ? pushText(last.elements, element.text, element.style) : last.elements.push(element); }
|
|
145
|
+
else out.push(section(elements));
|
|
146
|
+
}
|
|
147
|
+
function list(node, indent, out, depth) {
|
|
148
|
+
const style = node.ordered ? 'ordered' : 'bullet';
|
|
149
|
+
const start = node.ordered && Number.isInteger(node.start) ? node.start : 1;
|
|
150
|
+
let current, count = 0;
|
|
151
|
+
const open = () => { current = { type: 'rich_text_list', style, indent: Math.min(indent, LIST_INDENT_LIMIT), elements: [], ...(node.ordered && start + count - 1 > 0 ? { offset: start + count - 1 } : {}) }; out.push(current); };
|
|
152
|
+
for (const item of node.children) {
|
|
153
|
+
// Keep source order: text after a nested list or code block follows it as an unbulleted continuation.
|
|
154
|
+
let elements = [], bulleted = false;
|
|
155
|
+
const flush = () => {
|
|
156
|
+
if (!elements.length) return;
|
|
157
|
+
if (bulleted) out.push(section(elements));
|
|
158
|
+
else { if (!current || out[out.length - 1] !== current) open(); current.elements.push(section(elements)); count++; bulleted = true; }
|
|
159
|
+
elements = [];
|
|
160
|
+
};
|
|
161
|
+
for (const child of item.children || []) {
|
|
162
|
+
if (child.type === 'paragraph' || child.type === 'heading') { if (elements.length) pushText(elements, '\n'); inline(child.children, {}, elements, depth + 1); continue; }
|
|
163
|
+
flush();
|
|
164
|
+
// Slack lists hold only sections: nested lists follow with deeper indent, other blocks follow the list.
|
|
165
|
+
if (child.type === 'list' && depth < NESTING_LIMIT) list(child, indent + 1, out, depth + 1); else blocks([child], depth + 1, out);
|
|
166
|
+
}
|
|
167
|
+
flush();
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return { inline, blocks };
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function images(node) {
|
|
174
|
+
const found = [];
|
|
175
|
+
const stack = [node];
|
|
176
|
+
while (stack.length) {
|
|
177
|
+
const current = stack.pop();
|
|
178
|
+
if (current.type === 'image' || current.type === 'imageReference') found.push(current);
|
|
179
|
+
if (Array.isArray(current.children)) for (let i = current.children.length - 1; i >= 0; i--) stack.push(current.children[i]);
|
|
180
|
+
}
|
|
181
|
+
return found;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function parse(fromMarkdown, body) {
|
|
185
|
+
let root;
|
|
186
|
+
try { root = fromMarkdown(body); } catch { root = { type: 'root', children: [{ type: 'paragraph', children: [{ type: 'text', value: body }] }] }; }
|
|
187
|
+
const definitions = new Map();
|
|
188
|
+
const stack = [root];
|
|
189
|
+
while (stack.length) {
|
|
190
|
+
const node = stack.pop();
|
|
191
|
+
if (node.type === 'definition' && !definitions.has(node.identifier)) definitions.set(node.identifier, node);
|
|
192
|
+
if (Array.isArray(node.children)) stack.push(...node.children);
|
|
193
|
+
}
|
|
194
|
+
return { root, convert: createConverter(definitions) };
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/** Groups elements into rich_text blocks: a heading starts a block, as does exceeding the text budget. */
|
|
198
|
+
function toSlackBlocks(elements) {
|
|
199
|
+
const out = [];
|
|
200
|
+
let current, used = 0;
|
|
201
|
+
for (const element of elements) {
|
|
202
|
+
if (element.type === 'divider') { out.push({ type: 'divider' }); current = undefined; continue; }
|
|
203
|
+
const size = textLength(element);
|
|
204
|
+
if (!current || element.heading || used + size > BLOCK_TEXT_BUDGET) { current = { type: 'rich_text', elements: [] }; out.push(current); used = 0; }
|
|
205
|
+
const { heading, ...clean } = element;
|
|
206
|
+
current.elements.push(clean); used += size;
|
|
207
|
+
}
|
|
208
|
+
return out;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function titleBlock(title) {
|
|
212
|
+
return title.length <= HEADER_LIMIT ? { type: 'header', text: { type: 'plain_text', text: title, emoji: false } }
|
|
213
|
+
: { type: 'rich_text', elements: [{ type: 'rich_text_section', elements: [{ type: 'text', text: title, style: { bold: true } }] }] };
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/** Cuts inline elements at the best boundary within `limit`: paragraph, sentence, then word. Links are kept whole or dropped. */
|
|
217
|
+
function clipInline(elements, limit) {
|
|
218
|
+
const all = elements.map(inlineText).join('');
|
|
219
|
+
const window = all.slice(0, limit);
|
|
220
|
+
let cut = window.lastIndexOf('\n\n');
|
|
221
|
+
if (cut < limit * 0.4) cut = Math.max(...['. ', '! ', '? ', '.\n'].map(mark => window.lastIndexOf(mark))) + 1;
|
|
222
|
+
if (cut < limit * 0.4) cut = window.search(/\s\S*$/);
|
|
223
|
+
if (cut < limit * 0.4) cut = limit;
|
|
224
|
+
if (/[\uD800-\uDBFF]/.test(all[cut - 1] || '')) cut--;
|
|
225
|
+
const out = [];
|
|
226
|
+
let used = 0;
|
|
227
|
+
for (const element of elements) {
|
|
228
|
+
const text = inlineText(element);
|
|
229
|
+
if (used + text.length <= cut) { out.push(element); used += text.length; continue; }
|
|
230
|
+
if (element.type === 'text') { const part = text.slice(0, cut - used).trimEnd(); if (part) out.push({ ...element, text: part }); }
|
|
231
|
+
break;
|
|
232
|
+
}
|
|
233
|
+
while (out.length && out[out.length - 1].type === 'text' && !out[out.length - 1].text.trim()) out.pop();
|
|
234
|
+
pushText(out, '…');
|
|
235
|
+
return out;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/** Keeps whole elements while they fit; shortens at most one, then stops. */
|
|
239
|
+
function excerpt(elements, limit) {
|
|
240
|
+
const out = [];
|
|
241
|
+
let used = 0, shortened = false;
|
|
242
|
+
for (const element of elements) {
|
|
243
|
+
if (element.type === 'divider') continue;
|
|
244
|
+
const size = textLength(element);
|
|
245
|
+
if (used + size <= limit) { out.push(element); used += size; continue; }
|
|
246
|
+
shortened = true;
|
|
247
|
+
const remaining = limit - used;
|
|
248
|
+
if (element.type === 'rich_text_list') {
|
|
249
|
+
const items = [];
|
|
250
|
+
let left = remaining;
|
|
251
|
+
for (const item of element.elements) {
|
|
252
|
+
const length = textLength(item);
|
|
253
|
+
if (length <= left) { items.push(item); left -= length; continue; }
|
|
254
|
+
if (left > 80 || !items.length) items.push({ ...item, elements: clipInline(item.elements, Math.max(left, 80)) });
|
|
255
|
+
break;
|
|
256
|
+
}
|
|
257
|
+
out.push({ ...element, elements: items });
|
|
258
|
+
} else if (remaining > 80 || !out.length) out.push({ ...element, elements: clipInline(element.elements, Math.max(remaining, 80)) });
|
|
259
|
+
break;
|
|
260
|
+
}
|
|
261
|
+
const shown = out.reduce((n, element) => n + textLength(element), 0);
|
|
262
|
+
return { elements: out, shortened, shown, total: elements.reduce((n, element) => n + textLength(element), 0) };
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
const key = node => plainText(node).replace(/\s+/g, ' ').trim().toLowerCase();
|
|
266
|
+
function sectionsOf(root) {
|
|
267
|
+
const sections = [{ heading: undefined, nodes: [] }];
|
|
268
|
+
for (const node of root.children) {
|
|
269
|
+
if (node.type === 'heading') sections.push({ heading: node, key: key(node), nodes: [] });
|
|
270
|
+
else sections[sections.length - 1].nodes.push(node);
|
|
271
|
+
}
|
|
272
|
+
return sections;
|
|
273
|
+
}
|
|
274
|
+
const hasText = nodes => nodes.some(node => plainText(node).trim());
|
|
275
|
+
// Generated sections a summary leaves out; Source is represented by the recording link.
|
|
276
|
+
const OMITTED = new Set(['user feedback', 'observations', 'suggestions', 'context and limitations', 'visual evidence']);
|
|
277
|
+
const SUMMARY_TOTAL_LIMIT = 2000;
|
|
278
|
+
const SUMMARY_SECTION_LIMIT = 8;
|
|
279
|
+
const inlineTextOutsideLinks = element => element.type === 'link' ? '' : Array.isArray(element.elements) ? element.elements.map(inlineTextOutsideLinks).join('') : element.text || '';
|
|
280
|
+
const linksIn = elements => elements.flatMap(element => element.type === 'link' ? [element] : Array.isArray(element.elements) ? linksIn(element.elements) : []);
|
|
281
|
+
|
|
282
|
+
function momentLabel(url) {
|
|
283
|
+
const seconds = Number(new URL(url).searchParams.get('t'));
|
|
284
|
+
return Number.isFinite(seconds) && seconds >= 0 && new URL(url).searchParams.has('t') ? `Recording at ${Math.floor(seconds / 60)}:${String(Math.floor(seconds % 60)).padStart(2, '0')}` : 'Recording moment';
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
function compact(root, convert) {
|
|
288
|
+
const notices = [];
|
|
289
|
+
const sections = sectionsOf(root);
|
|
290
|
+
const elements = [];
|
|
291
|
+
const omitted = [];
|
|
292
|
+
let used = 0, included = 0;
|
|
293
|
+
const hasSummary = sections.some(section => section.key === 'summary' && hasText(section.nodes));
|
|
294
|
+
// Known summary content plus every custom section, in source order, each as a bounded excerpt.
|
|
295
|
+
for (const section of sections) {
|
|
296
|
+
if (!hasText(section.nodes)) continue;
|
|
297
|
+
const name = section.heading ? plainText(section.heading).replace(/\s+/g, ' ').trim() : 'Introduction';
|
|
298
|
+
// Above a Summary, skip only a links-only preamble such as the recording cover; its links still reach Evidence.
|
|
299
|
+
if (!section.heading && hasSummary && !convert.blocks(section.nodes).some(element => inlineTextOutsideLinks(element).trim())) continue;
|
|
300
|
+
if (section.key === 'source') continue;
|
|
301
|
+
if (OMITTED.has(section.key)) { omitted.push(name); continue; }
|
|
302
|
+
if (section.key === 'expected behavior') {
|
|
303
|
+
const text = plainText({ children: section.nodes }).trim();
|
|
304
|
+
if (/^Needs reporter input\b/i.test(text)) continue;
|
|
305
|
+
if (/^From source analysis\b/i.test(text)) { notices.push('Expected behavior suggested by source analysis is not included in the summary. Choose Full report to include it.'); continue; }
|
|
306
|
+
}
|
|
307
|
+
const budget = Math.min(EXCERPT_LIMIT, SUMMARY_TOTAL_LIMIT - used);
|
|
308
|
+
if (budget < 80 || included >= SUMMARY_SECTION_LIMIT) { omitted.push(name); continue; }
|
|
309
|
+
included++;
|
|
310
|
+
if (section.heading && section.key !== 'summary') elements.push(...convert.blocks([section.heading]));
|
|
311
|
+
const clipped = excerpt(convert.blocks(section.nodes), budget);
|
|
312
|
+
elements.push(...clipped.elements);
|
|
313
|
+
used += clipped.shown;
|
|
314
|
+
if (clipped.shortened) notices.push(`${section.key === 'summary' ? 'The summary' : `“${name}”`} is shortened to ${clipped.shown.toLocaleString('en-US')} of ${clipped.total.toLocaleString('en-US')} characters. Choose Full report to send all of it.`);
|
|
315
|
+
}
|
|
316
|
+
if (omitted.length) notices.push(`Not included in the summary: ${omitted.join(', ')}. Choose Full report to send ${omitted.length === 1 ? 'it' : 'them'}.`);
|
|
317
|
+
const seen = new Set(linksIn(elements).map(link => link.url));
|
|
318
|
+
const links = [];
|
|
319
|
+
const recording = linksIn(sections.filter(section => section.key === 'source').flatMap(section => convert.blocks(section.nodes)))[0];
|
|
320
|
+
if (recording && !seen.has(recording.url)) links.push({ type: 'rich_text_section', elements: [{ type: 'link', url: recording.url, text: recording.text }] });
|
|
321
|
+
if (recording) seen.add(recording.url);
|
|
322
|
+
// Screenshots and explicit links elsewhere in the report, in source order, each URL once.
|
|
323
|
+
const evidence = [];
|
|
324
|
+
let invalid = 0;
|
|
325
|
+
const firstLink = node => convert.inline([node]).find(element => element.type === 'link');
|
|
326
|
+
const stack = [{ node: root, parent: undefined }];
|
|
327
|
+
while (stack.length) {
|
|
328
|
+
const { node, parent } = stack.pop();
|
|
329
|
+
if (node.type === 'image' || node.type === 'imageReference') {
|
|
330
|
+
const imageUrl = firstLink(node)?.url;
|
|
331
|
+
const momentUrl = parent ? firstLink({ ...parent, children: [{ type: 'text', value: 'moment' }] })?.url : undefined;
|
|
332
|
+
const primary = imageUrl || momentUrl;
|
|
333
|
+
if (!primary) { invalid++; continue; }
|
|
334
|
+
if (seen.has(primary)) continue;
|
|
335
|
+
seen.add(primary);
|
|
336
|
+
const item = [{ type: 'link', url: primary, text: node.alt || 'Screenshot' }];
|
|
337
|
+
if (imageUrl && momentUrl && !seen.has(momentUrl)) item.push({ type: 'text', text: ' · ' }, { type: 'link', url: momentUrl, text: momentLabel(momentUrl) });
|
|
338
|
+
if (momentUrl) seen.add(momentUrl);
|
|
339
|
+
evidence.push({ type: 'rich_text_section', elements: item });
|
|
340
|
+
continue;
|
|
341
|
+
}
|
|
342
|
+
if ((node.type === 'link' || node.type === 'linkReference') && !images(node).length) {
|
|
343
|
+
const link = firstLink(node);
|
|
344
|
+
if (link && !seen.has(link.url)) { seen.add(link.url); evidence.push({ type: 'rich_text_section', elements: [{ type: 'link', url: link.url, text: link.text }] }); }
|
|
345
|
+
continue;
|
|
346
|
+
}
|
|
347
|
+
if (Array.isArray(node.children)) {
|
|
348
|
+
const nextParent = node.type === 'link' || node.type === 'linkReference' ? node : parent;
|
|
349
|
+
for (let i = node.children.length - 1; i >= 0; i--) stack.push({ node: node.children[i], parent: nextParent });
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
if (evidence.length > EVIDENCE_LIMIT) notices.push(`${evidence.length - EVIDENCE_LIMIT} more link(s) are only in the full report.`);
|
|
353
|
+
if (invalid) notices.push(`${invalid} screenshot(s) without a valid HTTPS link are not included.`);
|
|
354
|
+
if (links.length || evidence.length) {
|
|
355
|
+
elements.push({ type: 'rich_text_section', heading: true, elements: [{ type: 'text', text: 'Evidence', style: { bold: true } }] }, ...links);
|
|
356
|
+
if (evidence.length) elements.push({ type: 'rich_text_list', style: 'bullet', indent: 0, elements: evidence.slice(0, EVIDENCE_LIMIT) });
|
|
357
|
+
}
|
|
358
|
+
elements.push({ type: 'rich_text_section', elements: [{ type: 'text', text: CONTEXT_NOTE + (recording ? RECORDING_NOTE : ''), style: { italic: true } }] });
|
|
359
|
+
return { elements, notices };
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/** @param {(markdown: string) => unknown} fromMarkdown CommonMark parser from `mdast-util-from-markdown` */
|
|
363
|
+
export function createSlackReportProjector(fromMarkdown) {
|
|
364
|
+
return (title, body, mode) => projectSlackReport(fromMarkdown, title, body, mode);
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
function projectSlackReport(fromMarkdown, title, body, mode) {
|
|
368
|
+
if (!SLACK_REPORT_MODES.includes(mode)) throw new SlackReportError('INVALID_MODE', 'Choose a Slack message format.');
|
|
369
|
+
if (typeof title !== 'string' || typeof body !== 'string' || !title.trim() || title.length > SLACK_REPORT_TITLE_LIMIT || body.length > SLACK_REPORT_BODY_LIMIT) {
|
|
370
|
+
throw new SlackReportError('REPORT_TOO_LARGE', 'Slack reports support a title up to 256 characters and a body up to 12,000 characters.');
|
|
371
|
+
}
|
|
372
|
+
const { root, convert } = parse(fromMarkdown, body);
|
|
373
|
+
const projected = mode === 'full' ? { elements: convert.blocks(root.children), notices: [] } : compact(root, convert);
|
|
374
|
+
const blocks = [titleBlock(title), ...toSlackBlocks(projected.elements)];
|
|
375
|
+
if (blocks.length > BLOCK_LIMIT) throw new SlackReportError('REPORT_TOO_LARGE', `This report needs ${blocks.length} Slack blocks; one message supports ${BLOCK_LIMIT}. Use the summary message or shorten the report.`);
|
|
376
|
+
const escape = value => value.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
|
377
|
+
return {
|
|
378
|
+
message: { text: escape(title), blocks, mrkdwn: false, parse: 'none', link_names: false, unfurl_links: false, unfurl_media: false },
|
|
379
|
+
notices: projected.notices,
|
|
380
|
+
};
|
|
381
|
+
}
|
|
@@ -127,6 +127,7 @@ export declare class LocalAdapter implements BrowserAdapter {
|
|
|
127
127
|
* If classification itself fails, returns the original error unchanged.
|
|
128
128
|
*/
|
|
129
129
|
private enrichElementNotFound;
|
|
130
|
+
private assertLocalSelector;
|
|
130
131
|
click(selector: string, options?: ClickOptions): Promise<ActionResult & {
|
|
131
132
|
data?: BlockedOutcome;
|
|
132
133
|
}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"local.d.ts","sourceRoot":"","sources":["../../../src/adapters/local.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,KAAK,EACV,OAAO,EACP,cAAc,EACd,YAAY,EACZ,eAAe,EACf,YAAY,EACZ,cAAc,EACd,WAAW,EACX,iBAAiB,EACjB,cAAc,EACd,WAAW,EACX,YAAY,EACZ,aAAa,EACb,aAAa,EACd,MAAM,aAAa,CAAC;AAIrB,OAAO,EACL,cAAc,EAMf,MAAM,aAAa,CAAC;AAsBrB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"local.d.ts","sourceRoot":"","sources":["../../../src/adapters/local.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,KAAK,EACV,OAAO,EACP,cAAc,EACd,YAAY,EACZ,eAAe,EACf,YAAY,EACZ,cAAc,EACd,WAAW,E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E_TYPED_EXTENSION_REVALIDATION_DELAYS_MS, LOCAL_BRIDGE_TYPED_RECENT_DISCONNECT_GRACE_MS, } from '../local-bridge-timing.js';
|
|
26
26
|
import { redactSensitiveResult } from '../../shared/sensitive-result-redaction.js';
|
|
27
27
|
import { getNativeTypeBudget } from '../../shared/native-type-budget.js';
|
|
28
|
+
import { explainUnsupportedSelector } from '../../shared/selector-hints.js';
|
|
29
|
+
import { retryReadAcrossNavigation } from '../../shared/navigation-retry.js';
|
|
28
30
|
/** Tunable post-action settle delay (ms). React batches setState updates
|
|
29
31
|
* (~16ms); 50ms gives margin for async DOM mutations to settle. */
|
|
30
32
|
const POST_ACTION_SETTLE_MS = 50;
|
|
@@ -1292,7 +1294,13 @@ export class LocalAdapter {
|
|
|
1292
1294
|
return err;
|
|
1293
1295
|
}
|
|
1294
1296
|
// --- Interaction ---
|
|
1297
|
+
assertLocalSelector(selector, action) {
|
|
1298
|
+
const hint = explainUnsupportedSelector(selector, action);
|
|
1299
|
+
if (hint)
|
|
1300
|
+
throw new ApiError(hint, undefined, undefined, 'INVALID_SELECTOR', false);
|
|
1301
|
+
}
|
|
1295
1302
|
async click(selector, options = {}) {
|
|
1303
|
+
this.assertLocalSelector(selector, 'click');
|
|
1296
1304
|
const tabId = await this.getActiveTabId();
|
|
1297
1305
|
const auditActionId = this.createAuditActionId('click');
|
|
1298
1306
|
// Capture pre-action fingerprint (best-effort)
|
|
@@ -1367,6 +1375,7 @@ export class LocalAdapter {
|
|
|
1367
1375
|
return { success: response.success, data: response.data };
|
|
1368
1376
|
}
|
|
1369
1377
|
async type(selector, text, options = {}) {
|
|
1378
|
+
this.assertLocalSelector(selector, 'type');
|
|
1370
1379
|
const typeBudget = getNativeTypeBudget(text, options.delay, this.defaultTimeout);
|
|
1371
1380
|
if (typeBudget.exceedsLimit) {
|
|
1372
1381
|
throw new ApiError('Typing duration exceeds the native host limit.', 400, 'Reduce the text length or typing delay and retry.', 'TYPE_DURATION_EXCEEDS_LIMIT', false);
|
|
@@ -1419,11 +1428,15 @@ export class LocalAdapter {
|
|
|
1419
1428
|
? response.data.controlType
|
|
1420
1429
|
: 'unknown',
|
|
1421
1430
|
changed: response.data.changed === true,
|
|
1431
|
+
// Present only when the selector matched several elements, so agents can see which one was used.
|
|
1432
|
+
...(typeof response.data.matchCount === 'number' ? { matchCount: response.data.matchCount } : {}),
|
|
1433
|
+
...(typeof response.data.matchIndex === 'number' ? { matchIndex: response.data.matchIndex } : {}),
|
|
1422
1434
|
}
|
|
1423
1435
|
: undefined;
|
|
1424
1436
|
return { success: response.success, ...(editableData ? { data: editableData } : {}) };
|
|
1425
1437
|
}
|
|
1426
1438
|
async fill(selector, value) {
|
|
1439
|
+
this.assertLocalSelector(selector, 'fill');
|
|
1427
1440
|
const tabId = await this.getActiveTabId();
|
|
1428
1441
|
const auditActionId = this.createAuditActionId('fill');
|
|
1429
1442
|
const pre = await this.tryCaptureFP(selector);
|
|
@@ -1443,7 +1456,10 @@ export class LocalAdapter {
|
|
|
1443
1456
|
const blocked = classifyFromBridgeResult(response.data);
|
|
1444
1457
|
if (blocked)
|
|
1445
1458
|
return { success: false, data: blocked };
|
|
1446
|
-
|
|
1459
|
+
// The extension reports changed: false when the field already held the value. That is a success,
|
|
1460
|
+
// so an unchanged page here doesn't mean the fill was blocked.
|
|
1461
|
+
const alreadyHeldValue = response.success && response.data?.changed === false;
|
|
1462
|
+
if (!alreadyHeldValue && pre && LocalAdapter.isFingerprintValid(pre)) {
|
|
1447
1463
|
try {
|
|
1448
1464
|
if (POST_ACTION_SETTLE_MS > 0)
|
|
1449
1465
|
await new Promise(resolve => setTimeout(resolve, POST_ACTION_SETTLE_MS));
|
|
@@ -1470,6 +1486,9 @@ export class LocalAdapter {
|
|
|
1470
1486
|
? response.data.controlType
|
|
1471
1487
|
: 'unknown',
|
|
1472
1488
|
changed: response.data.changed === true,
|
|
1489
|
+
// Present only when the selector matched several elements, so agents can see which one was used.
|
|
1490
|
+
...(typeof response.data.matchCount === 'number' ? { matchCount: response.data.matchCount } : {}),
|
|
1491
|
+
...(typeof response.data.matchIndex === 'number' ? { matchIndex: response.data.matchIndex } : {}),
|
|
1473
1492
|
}
|
|
1474
1493
|
: undefined;
|
|
1475
1494
|
return { success: response.success, ...(editableData ? { data: editableData } : {}) };
|
|
@@ -1530,6 +1549,7 @@ export class LocalAdapter {
|
|
|
1530
1549
|
return { success: response.success };
|
|
1531
1550
|
}
|
|
1532
1551
|
async hover(selector) {
|
|
1552
|
+
this.assertLocalSelector(selector, 'hover');
|
|
1533
1553
|
const tabId = await this.getActiveTabId();
|
|
1534
1554
|
const auditActionId = this.createAuditActionId('hover');
|
|
1535
1555
|
try {
|
|
@@ -1552,6 +1572,7 @@ export class LocalAdapter {
|
|
|
1552
1572
|
}
|
|
1553
1573
|
}
|
|
1554
1574
|
async select(selector, value) {
|
|
1575
|
+
this.assertLocalSelector(selector, 'select');
|
|
1555
1576
|
const tabId = await this.getActiveTabId();
|
|
1556
1577
|
const auditActionId = this.createAuditActionId('select');
|
|
1557
1578
|
const pre = await this.tryCaptureFP(selector);
|
|
@@ -1615,6 +1636,8 @@ export class LocalAdapter {
|
|
|
1615
1636
|
}
|
|
1616
1637
|
// --- Waiting ---
|
|
1617
1638
|
async wait(condition, options = {}) {
|
|
1639
|
+
if (typeof condition === 'string')
|
|
1640
|
+
this.assertLocalSelector(condition, 'wait');
|
|
1618
1641
|
if (typeof condition === 'number') {
|
|
1619
1642
|
// Numeric-timeout path: local setTimeout only — never contacts the bridge,
|
|
1620
1643
|
// so there is no bridge action to sync and syncAction is intentionally absent.
|
|
@@ -1623,24 +1646,24 @@ export class LocalAdapter {
|
|
|
1623
1646
|
}
|
|
1624
1647
|
const tabId = await this.getActiveTabId();
|
|
1625
1648
|
const state = options.hidden ? 'hidden' : 'visible';
|
|
1626
|
-
const response = await this.request(`/sessions/${tabId}/wait`, {
|
|
1649
|
+
const response = await retryReadAcrossNavigation(() => this.request(`/sessions/${tabId}/wait`, {
|
|
1627
1650
|
method: 'POST',
|
|
1628
1651
|
body: JSON.stringify({
|
|
1629
1652
|
selector: condition,
|
|
1630
1653
|
state,
|
|
1631
1654
|
timeout: options.timeout ?? 30000,
|
|
1632
1655
|
}),
|
|
1633
|
-
});
|
|
1656
|
+
}));
|
|
1634
1657
|
if (response.success)
|
|
1635
1658
|
this.syncAction(tabId, 'wait', {});
|
|
1636
1659
|
return { success: response.success };
|
|
1637
1660
|
}
|
|
1638
1661
|
async waitForText(text, options = {}) {
|
|
1639
1662
|
const tabId = await this.getActiveTabId();
|
|
1640
|
-
const response = await this.request(`/sessions/${tabId}/wait-for-text`, {
|
|
1663
|
+
const response = await retryReadAcrossNavigation(() => this.request(`/sessions/${tabId}/wait-for-text`, {
|
|
1641
1664
|
method: 'POST',
|
|
1642
1665
|
body: JSON.stringify({ text, timeout: options.timeout ?? 30000 }),
|
|
1643
|
-
});
|
|
1666
|
+
}));
|
|
1644
1667
|
return { success: response.success };
|
|
1645
1668
|
}
|
|
1646
1669
|
// --- Observation ---
|
|
@@ -1739,6 +1762,7 @@ export class LocalAdapter {
|
|
|
1739
1762
|
return { success: response.success, data: response.data };
|
|
1740
1763
|
}
|
|
1741
1764
|
async extract(selector, options = {}) {
|
|
1765
|
+
this.assertLocalSelector(selector, 'extract');
|
|
1742
1766
|
const tabId = await this.getActiveTabId();
|
|
1743
1767
|
const response = await this.request(`/sessions/${tabId}/extract`, {
|
|
1744
1768
|
method: 'POST',
|