@astrofoundry/pi-astro 0.40.56 → 0.40.57
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/agents/research.md
CHANGED
|
@@ -19,7 +19,7 @@ Work in this order:
|
|
|
19
19
|
|
|
20
20
|
1. **Title.** When the context says "New request", your reply always starts with the line `TITLE: [CATEGORY YYYY-MM-DD] <place>: <subject>`, also when it only asks questions. Example: `TITLE: [PRODUCT 2026-11-04] UAE: top 5 running shoes for men`. Categories: PRODUCT, FLIGHT, STAY, SERVICE, LOCAL, EVENT, INFO. Keep the number the user asked for. Put it at the top of your last message, the reply the user sees; the bridge turns it into the thread's name and removes it.
|
|
21
21
|
2. **Defaults.** Run `defaults list` and apply GLOBAL and the category's defaults.
|
|
22
|
-
3. **Questions.** If anything still open would change the answer (size, budget, dates, passengers, cabin, type of use), ask it as a numbered list of at most five short questions. Give each one your suggested answer in brackets. Then stop: do not search before the user answers. When nothing is open, state the defaults you applied in one line and research.
|
|
22
|
+
3. **Questions.** If anything still open would change the answer (size, budget, dates, passengers, cabin, type of use), ask it as a numbered list of at most five short questions. Give each one your suggested answer in brackets, and end that reply with the line `CHOICE: suggestions`, which shows a Use suggestions button. Then stop: do not search before the user answers or presses it. When nothing is open, state the defaults you applied in one line and research.
|
|
23
23
|
4. **Research.** Follow the skill's sources and checks. Verify every fact you report on the page itself, in this sandbox, today.
|
|
24
24
|
5. **Answer.** Use the skill's format. It has no open assumptions: anything you could not check is either checked another way or left out, never reported as "unchecked". Only an answer with researched results ends with the line `REFRESH: yes`; a reply that asks questions or confirms a default never does.
|
|
25
25
|
|
|
@@ -74,7 +74,7 @@ import {
|
|
|
74
74
|
} from "./tools-report.ts";
|
|
75
75
|
import { type Quote, type QuotedMessage, withQuotes } from "./quote.ts";
|
|
76
76
|
import { DiscordRest, type MessageComponent } from "./rest.ts";
|
|
77
|
-
import { BUTTON_TASKS, CAPTCHA_LABELS, captchaText, captchaVerdict,
|
|
77
|
+
import { answerButtons, BUTTON_TASKS, CAPTCHA_LABELS, captchaText, captchaVerdict, provisionalName, shapeAnswer, threadContext, threadDate, titleFromTexts } from "./research.ts";
|
|
78
78
|
import { ArcaneWatch } from "./arcane-watch-monitor.ts";
|
|
79
79
|
import { parseSnapshot } from "./arcane-watch.ts";
|
|
80
80
|
import { type Applied, autoFailureText, foremanTask, stackProblems, stackUpdateAnswer, SUPERVISE_DELAY_MS, SUPERVISE_LIMIT_MS } from "./supervise.ts";
|
|
@@ -1871,16 +1871,14 @@ class Bridge {
|
|
|
1871
1871
|
}
|
|
1872
1872
|
// During shutdown the interrupted message was already written; an aborted run has nothing else to say.
|
|
1873
1873
|
if (this.stopping) return true;
|
|
1874
|
-
let
|
|
1875
|
-
let continuable = false;
|
|
1874
|
+
let buttons: MessageComponent[] | null = null;
|
|
1876
1875
|
if (task.threaded && !failed) {
|
|
1877
1876
|
const shaped = shapeAnswer(output);
|
|
1878
1877
|
const texts = messages.flatMap((m) => (m.role === "assistant" ? m.content.flatMap((part) => (part.type === "text" ? [part.text] : [])) : []));
|
|
1879
1878
|
const title = shaped.title ?? titleFromTexts(texts);
|
|
1880
1879
|
if (title) await this.rest.renameThread(task.channelId, title).catch((err) => log(`${task.specialist}: renaming thread ${task.channelId} failed: ${err instanceof Error ? err.message : String(err)}`));
|
|
1881
1880
|
output = shaped.text || "(no output)";
|
|
1882
|
-
|
|
1883
|
-
continuable = shaped.continuable;
|
|
1881
|
+
buttons = answerButtons(shaped);
|
|
1884
1882
|
}
|
|
1885
1883
|
await this.rest.removeOwnReaction(task.channelId, task.messageId, REACTION.running).catch(() => undefined);
|
|
1886
1884
|
await this.rest.addReaction(task.channelId, task.messageId, failed ? REACTION.failed : REACTION.done).catch(() => undefined);
|
|
@@ -1889,7 +1887,6 @@ class Bridge {
|
|
|
1889
1887
|
const reply = `${notify ? `<@${notify}> ` : ""}${failed ? "❌" : "✅"} **${task.specialist}**\n${output}`;
|
|
1890
1888
|
const answers = await this.deliver(task, placeholder, reply, attachment, notify);
|
|
1891
1889
|
const last = answers[answers.length - 1];
|
|
1892
|
-
const buttons = continuable ? continueRow() : refreshable ? refreshRow() : null;
|
|
1893
1890
|
if (buttons && last && attachment === undefined && reply.length <= ATTACHMENT_THRESHOLD) {
|
|
1894
1891
|
const chunks = chunkMessage(reply);
|
|
1895
1892
|
await this.rest.editMessage(task.channelId, last, chunks[chunks.length - 1] ?? reply, buttons).catch((err) => log(`${task.specialist}: answer buttons failed: ${err instanceof Error ? err.message : String(err)}`));
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { BUTTON_TASKS, CAPTCHA_LABELS, captchaText, captchaVerdict, CONTINUE_ID, continueRow, provisionalName, REFRESH_ID, refreshRow, shapeAnswer, STOP_ID, threadContext, threadDate, titleFromTexts } from "./research.ts";
|
|
2
|
+
import { answerButtons, BUTTON_TASKS, CAPTCHA_LABELS, captchaText, captchaVerdict, CONTINUE_ID, continueRow, provisionalName, REFRESH_ID, refreshRow, shapeAnswer, STOP_ID, SUGGESTIONS_ID, threadContext, threadDate, titleFromTexts } from "./research.ts";
|
|
3
3
|
import { validateChannel } from "./config.ts";
|
|
4
4
|
|
|
5
5
|
describe("research threads", () => {
|
|
6
6
|
it("takes the title line and the refresh marker off an answer", () => {
|
|
7
7
|
const shaped = shapeAnswer("TITLE: [PRODUCT 2026-11-04] UAE: top 5 running shoes for men\n\n1. Hoka Mach 7 …\n2. Adidas Evo SL …\n\nREFRESH: yes\n");
|
|
8
|
-
expect(shaped).toEqual({ title: "[PRODUCT 2026-11-04] UAE: top 5 running shoes for men", text: "1. Hoka Mach 7 …\n2. Adidas Evo SL …", refreshable: true,
|
|
9
|
-
expect(shapeAnswer("1. What is your size?\n2. Road or trail?")).toEqual({ title: null, text: "1. What is your size?\n2. Road or trail?", refreshable: false,
|
|
8
|
+
expect(shaped).toEqual({ title: "[PRODUCT 2026-11-04] UAE: top 5 running shoes for men", text: "1. Hoka Mach 7 …\n2. Adidas Evo SL …", refreshable: true, choice: null });
|
|
9
|
+
expect(shapeAnswer("1. What is your size?\n2. Road or trail?")).toEqual({ title: null, text: "1. What is your size?\n2. Road or trail?", refreshable: false, choice: null });
|
|
10
10
|
expect(shapeAnswer("Read TITLE: inside a line\nREFRESH: yes, later")).toMatchObject({ title: null, refreshable: false });
|
|
11
|
-
expect(shapeAnswer("Two candidates so far.\n\nContinue for up to 10 more minutes?\nCHOICE: continue\n")).toEqual({ title: null, text: "Two candidates so far.\n\nContinue for up to 10 more minutes?", refreshable: false,
|
|
11
|
+
expect(shapeAnswer("Two candidates so far.\n\nContinue for up to 10 more minutes?\nCHOICE: continue\n")).toEqual({ title: null, text: "Two candidates so far.\n\nContinue for up to 10 more minutes?", refreshable: false, choice: "continue" });
|
|
12
|
+
expect(shapeAnswer("1. What size? [EU 43]\nCHOICE: suggestions")).toEqual({ title: null, text: "1. What size? [EU 43]", refreshable: false, choice: "suggestions" });
|
|
12
13
|
});
|
|
13
14
|
|
|
14
15
|
it("finds the title in an earlier text of the run", () => {
|
|
@@ -33,7 +34,10 @@ describe("research threads", () => {
|
|
|
33
34
|
expect(captchaVerdict("reddit.com", false, "1")).toBe("⏭️ reddit.com skipped by <@1>; the research continues without it.");
|
|
34
35
|
expect(refreshRow()[0].components?.[0]).toMatchObject({ custom_id: REFRESH_ID, label: "🔄 Refresh" });
|
|
35
36
|
expect(continueRow()[0].components?.map((b) => b.custom_id)).toEqual([CONTINUE_ID, STOP_ID]);
|
|
36
|
-
expect(Object.keys(BUTTON_TASKS).sort()).toEqual([CONTINUE_ID, REFRESH_ID, STOP_ID].sort());
|
|
37
|
+
expect(Object.keys(BUTTON_TASKS).sort()).toEqual([CONTINUE_ID, REFRESH_ID, STOP_ID, SUGGESTIONS_ID].sort());
|
|
38
|
+
expect(answerButtons({ refreshable: false, choice: "suggestions" })?.[0].components?.[0]).toMatchObject({ custom_id: SUGGESTIONS_ID, label: "✅ Use suggestions" });
|
|
39
|
+
expect(answerButtons({ refreshable: true, choice: null })?.[0].components?.[0].custom_id).toBe(REFRESH_ID);
|
|
40
|
+
expect(answerButtons({ refreshable: false, choice: null })).toBeNull();
|
|
37
41
|
});
|
|
38
42
|
|
|
39
43
|
it("accepts the thread, everyone, and live view settings of a channel", () => {
|
|
@@ -3,24 +3,28 @@
|
|
|
3
3
|
* thread on itself, the specialist names it with a first `TITLE:` line, and
|
|
4
4
|
* every later message in that thread continues the same work without a
|
|
5
5
|
* mention. A final answer that ends with `REFRESH: yes` gets a Refresh button;
|
|
6
|
-
* a reply that ends with `CHOICE: continue` gets Continue and Stop buttons
|
|
6
|
+
* a reply that ends with `CHOICE: continue` gets Continue and Stop buttons, and
|
|
7
|
+
* one that ends with `CHOICE: suggestions` (its questions) a Use suggestions button.
|
|
7
8
|
*/
|
|
8
9
|
import type { MessageComponent } from "./rest.ts";
|
|
9
10
|
|
|
10
11
|
export const REFRESH_ID = "research:refresh";
|
|
11
12
|
export const CONTINUE_ID = "research:continue";
|
|
12
13
|
export const STOP_ID = "research:stop";
|
|
14
|
+
export const SUGGESTIONS_ID = "research:suggestions";
|
|
13
15
|
const TITLE = /^TITLE:\s*(\S.{1,98}\S)\s*$/;
|
|
14
16
|
const REFRESH = /^\s*REFRESH:\s*yes\s*$/i;
|
|
15
|
-
const CHOICE = /^\s*CHOICE:\s*continue\s*$/i;
|
|
17
|
+
const CHOICE = /^\s*CHOICE:\s*(continue|suggestions)\s*$/i;
|
|
18
|
+
|
|
19
|
+
export type Choice = "continue" | "suggestions";
|
|
16
20
|
const MENTION = /<@[!&]?\d+>/g;
|
|
17
21
|
|
|
18
22
|
export interface ShapedAnswer {
|
|
19
23
|
title: string | null;
|
|
20
24
|
text: string;
|
|
21
25
|
refreshable: boolean;
|
|
22
|
-
/**
|
|
23
|
-
|
|
26
|
+
/** Buttons for a question: go on past the time limit, or take the suggested answers. */
|
|
27
|
+
choice: Choice | null;
|
|
24
28
|
}
|
|
25
29
|
|
|
26
30
|
/** Takes the title line off the top and the refresh and choice markers off the bottom of a specialist's answer. */
|
|
@@ -34,15 +38,16 @@ export function shapeAnswer(output: string): ShapedAnswer {
|
|
|
34
38
|
lines.splice(first, 1);
|
|
35
39
|
}
|
|
36
40
|
let refreshable = false;
|
|
37
|
-
let
|
|
41
|
+
let choice: Choice | null = null;
|
|
38
42
|
for (let i = lines.length - 1; i >= 0; i--) {
|
|
39
43
|
if (lines[i].trim().length === 0) continue;
|
|
44
|
+
const chosen = CHOICE.exec(lines[i]);
|
|
40
45
|
if (REFRESH.test(lines[i])) refreshable = true;
|
|
41
|
-
else if (
|
|
46
|
+
else if (chosen) choice = chosen[1].toLowerCase() as Choice;
|
|
42
47
|
else break;
|
|
43
48
|
lines.splice(i, 1);
|
|
44
49
|
}
|
|
45
|
-
return { title, text: lines.join("\n").trim(), refreshable,
|
|
50
|
+
return { title, text: lines.join("\n").trim(), refreshable, choice };
|
|
46
51
|
}
|
|
47
52
|
|
|
48
53
|
/** The `TITLE:` line from any assistant text of the run, oldest first: the specialist may write it before its tool calls, and only the last text is the answer. */
|
|
@@ -80,6 +85,7 @@ export const BUTTON_TASKS: Readonly<Record<string, string>> = {
|
|
|
80
85
|
[REFRESH_ID]: "Refresh your last answer: check every price, stock and size, delivery, date, and link again today, then give the answer in the same format, marking what changed.",
|
|
81
86
|
[CONTINUE_ID]: "Continue the research for up to 10 more minutes, then answer.",
|
|
82
87
|
[STOP_ID]: "Stop researching now. Answer with what you have verified; leave out anything you could not verify.",
|
|
88
|
+
[SUGGESTIONS_ID]: "Use your suggested answer for every open question, then research.",
|
|
83
89
|
};
|
|
84
90
|
|
|
85
91
|
export function refreshRow(): MessageComponent[] {
|
|
@@ -98,6 +104,17 @@ export function continueRow(): MessageComponent[] {
|
|
|
98
104
|
];
|
|
99
105
|
}
|
|
100
106
|
|
|
107
|
+
export function suggestionsRow(): MessageComponent[] {
|
|
108
|
+
return [{ type: 1, components: [{ type: 2, style: 3, label: "✅ Use suggestions", custom_id: SUGGESTIONS_ID }] }];
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** The buttons a reply carries: its choice first, otherwise Refresh on a final answer. */
|
|
112
|
+
export function answerButtons(shaped: Pick<ShapedAnswer, "refreshable" | "choice">): MessageComponent[] | null {
|
|
113
|
+
if (shaped.choice === "continue") return continueRow();
|
|
114
|
+
if (shaped.choice === "suggestions") return suggestionsRow();
|
|
115
|
+
return shaped.refreshable ? refreshRow() : null;
|
|
116
|
+
}
|
|
117
|
+
|
|
101
118
|
/** Labels of a `captcha-help` approval: Approve means the owner solved it, Deny skips the site. */
|
|
102
119
|
export const CAPTCHA_LABELS = { approve: "✅ Solved", deny: "⏭️ Skip site" } as const;
|
|
103
120
|
|
package/package.json
CHANGED
package/skills/research/SKILL.md
CHANGED
|
@@ -68,7 +68,7 @@ The `research` tool reaches VM 110 `research` at Mira, on an internet-only netwo
|
|
|
68
68
|
REFRESH: yes
|
|
69
69
|
```
|
|
70
70
|
|
|
71
|
-
Wrap every link in `<…>` so Discord shows no preview. A reply that stops at the time limit ends with `CHOICE: continue` instead of `REFRESH: yes`; the buttons send "Continue the research for up to 10 more minutes" or "Stop researching now and answer with what you verified". Keep each item to two lines at most. Use the number the user asked for; give fewer only when fewer pass the checks, and say so.
|
|
71
|
+
Wrap every link in `<…>` so Discord shows no preview. A questions reply ends with `CHOICE: suggestions` (a Use suggestions button that answers every question with its bracketed suggestion). A reply that stops at the time limit ends with `CHOICE: continue` instead of `REFRESH: yes`; the buttons send "Continue the research for up to 10 more minutes" or "Stop researching now and answer with what you verified". Keep each item to two lines at most. Use the number the user asked for; give fewer only when fewer pass the checks, and say so.
|
|
72
72
|
|
|
73
73
|
## Defaults
|
|
74
74
|
|