@astrofoundry/pi-astro 0.40.54 → 0.40.55

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.
@@ -1877,8 +1877,10 @@ class Bridge {
1877
1877
  }
1878
1878
  await this.rest.removeOwnReaction(task.channelId, task.messageId, REACTION.running).catch(() => undefined);
1879
1879
  await this.rest.addReaction(task.channelId, task.messageId, failed ? REACTION.failed : REACTION.done).catch(() => undefined);
1880
- const reply = `${failed ? "❌" : "✅"} **${task.specialist}**\n${output}`;
1881
- const answers = await this.deliver(task, placeholder, reply, attachment);
1880
+ // In a request's thread the requester is tagged on every reply, questions or answer; an edited message never notifies, so it is posted new.
1881
+ const notify = task.threaded ? task.userId : undefined;
1882
+ const reply = `${notify ? `<@${notify}> ` : ""}${failed ? "❌" : "✅"} **${task.specialist}**\n${output}`;
1883
+ const answers = await this.deliver(task, placeholder, reply, attachment, notify);
1882
1884
  const last = answers[answers.length - 1];
1883
1885
  if (refreshable && last && attachment === undefined && reply.length <= ATTACHMENT_THRESHOLD) {
1884
1886
  const chunks = chunkMessage(reply);
@@ -1895,22 +1897,24 @@ class Bridge {
1895
1897
  }
1896
1898
 
1897
1899
  /** Turns the "working" placeholder into the answer: edit it in place when it fits, otherwise replace it with chunks or an attachment. Returns the answer message ids. */
1898
- private async deliver(task: ActiveTask, placeholder: string | undefined, text: string, attachment?: string): Promise<string[]> {
1900
+ private async deliver(task: ActiveTask, placeholder: string | undefined, text: string, attachment?: string, notify?: string): Promise<string[]> {
1901
+ const mentionUsers = notify ? [notify] : undefined;
1899
1902
  const oversized = attachment !== undefined || text.length > ATTACHMENT_THRESHOLD;
1900
1903
  if (oversized) {
1901
1904
  if (placeholder) await this.rest.deleteMessage(task.channelId, placeholder).catch(() => undefined);
1902
1905
  const file = attachment !== undefined ? { name: `astro-${task.specialist}-stderr-${Date.now()}.txt`, content: attachment } : { name: `astro-${task.specialist}-${Date.now()}.md`, content: text };
1903
1906
  const content = attachment !== undefined ? text.slice(0, 1900) : `${text.slice(0, 1200).trim()}\n… full answer attached (${text.length} characters).`;
1904
- const posted = await this.rest.createMessage(task.channelId, { content, replyTo: task.messageId, file });
1907
+ const posted = await this.rest.createMessage(task.channelId, { content, replyTo: task.messageId, file, mentionUsers });
1905
1908
  return [posted.id];
1906
1909
  }
1907
1910
  const chunks = chunkMessage(text);
1908
1911
  if (chunks.length === 0) chunks.push(text);
1909
1912
  const ids: string[] = [];
1910
- if (placeholder) {
1913
+ if (placeholder && notify) await this.rest.deleteMessage(task.channelId, placeholder).catch(() => undefined);
1914
+ if (placeholder && !notify) {
1911
1915
  await this.rest.editMessage(task.channelId, placeholder, chunks[0]).catch(() => undefined);
1912
1916
  ids.push(placeholder);
1913
- } else ids.push((await this.rest.createMessage(task.channelId, { content: chunks[0], replyTo: task.messageId })).id);
1917
+ } else ids.push((await this.rest.createMessage(task.channelId, { content: chunks[0], replyTo: task.messageId, mentionUsers })).id);
1914
1918
  for (let i = 1; i < chunks.length; i++) {
1915
1919
  ids.push((await this.rest.createMessage(task.channelId, { content: chunks[i] })).id);
1916
1920
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrofoundry/pi-astro",
3
- "version": "0.40.54",
3
+ "version": "0.40.55",
4
4
  "description": "Personal pi customizations (extensions, subagents, skills, prompts, themes) for the pi coding agent.",
5
5
  "keywords": [
6
6
  "pi-package"
@@ -44,6 +44,15 @@ BROWSER_COMMANDS = {
44
44
  # Page titles and frames of the challenges a person has to solve in the live view.
45
45
  CAPTCHA_TITLES = re.compile(r"prove your humanity|just a moment|are you a robot|verify you are human|attention required|access denied", re.I)
46
46
  CAPTCHA_FRAMES = re.compile(r"recaptcha|hcaptcha|challenges\.cloudflare\.com|captcha-delivery|arkoselabs|funcaptcha|perimeterx", re.I)
47
+ # A challenge popup (reCAPTCHA's bframe, hCaptcha's challenge) is shown only when a person must act;
48
+ # the checkbox frames also sit invisibly on normal pages, such as Reddit's, so they count only on a near-empty page.
49
+ CHALLENGE_POPUP = re.compile(r"recaptcha/(api2|enterprise)/bframe|hcaptcha\.com/.*challenge|challenges\.cloudflare\.com", re.I)
50
+ VISIBLE_FRAMES = (
51
+ "JSON.stringify({title: document.title, text: document.body ? document.body.innerText.length : 0,"
52
+ " frames: [...document.querySelectorAll('iframe')].filter(f => { const r = f.getBoundingClientRect(), s = getComputedStyle(f);"
53
+ " return r.width > 30 && r.height > 30 && r.bottom > 0 && r.right > 0 && s.visibility !== 'hidden' && s.display !== 'none'"
54
+ " && Number(s.opacity) > 0.1; }).map(f => f.src)})"
55
+ )
47
56
 
48
57
 
49
58
  class Refused(Exception):
@@ -138,10 +147,17 @@ def op_captcha(request):
138
147
  found.append(page)
139
148
  session = request.get("session")
140
149
  if isinstance(session, str) and SESSION.fullmatch(session) and attached(session):
141
- frames = run([PLAYWRIGHT, f"-s={session}", "--raw", "eval",
142
- "[document.title, ...[...document.querySelectorAll('iframe')].map(f => f.src)].join(' ')"], 60)
143
- if CAPTCHA_TITLES.search(frames["stdout"]) or CAPTCHA_FRAMES.search(frames["stdout"]):
144
- found.append({"session": session, "evidence": frames["stdout"][:300]})
150
+ probe = run([PLAYWRIGHT, f"-s={session}", "--raw", "eval", VISIBLE_FRAMES], 60)
151
+ try:
152
+ state = json.loads(json.loads(probe["stdout"]))
153
+ except (ValueError, TypeError):
154
+ state = None
155
+ if isinstance(state, dict):
156
+ frames = [f for f in state.get("frames", []) if isinstance(f, str)]
157
+ popup = any(CHALLENGE_POPUP.search(f) for f in frames)
158
+ widget_only = any(CAPTCHA_FRAMES.search(f) for f in frames) and int(state.get("text") or 0) < 1500
159
+ if CAPTCHA_TITLES.search(str(state.get("title"))) or popup or widget_only:
160
+ found.append({"session": session, "title": str(state.get("title"))[:120], "frames": [f[:120] for f in frames if CAPTCHA_FRAMES.search(f)]})
145
161
  return {"captcha": bool(found), "pages": found}
146
162
 
147
163