@astrofoundry/pi-astro 0.40.53 → 0.40.54
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
|
@@ -17,7 +17,7 @@ Each task starts with `Session: t<id>. Today: <date>.` Use that session in every
|
|
|
17
17
|
|
|
18
18
|
Work in this order:
|
|
19
19
|
|
|
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.
|
|
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
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.
|
|
23
23
|
4. **Research.** Follow the skill's sources and checks. Verify every fact you report on the page itself, in this sandbox, today.
|
|
@@ -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 { captchaText, provisionalName, REFRESH_ID, REFRESH_TASK, refreshRow, shapeAnswer, threadContext, threadDate } from "./research.ts";
|
|
77
|
+
import { captchaText, provisionalName, REFRESH_ID, REFRESH_TASK, refreshRow, 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";
|
|
@@ -1869,7 +1869,9 @@ class Bridge {
|
|
|
1869
1869
|
let refreshable = false;
|
|
1870
1870
|
if (task.threaded && !failed) {
|
|
1871
1871
|
const shaped = shapeAnswer(output);
|
|
1872
|
-
|
|
1872
|
+
const texts = messages.flatMap((m) => (m.role === "assistant" ? m.content.flatMap((part) => (part.type === "text" ? [part.text] : [])) : []));
|
|
1873
|
+
const title = shaped.title ?? titleFromTexts(texts);
|
|
1874
|
+
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)}`));
|
|
1873
1875
|
output = shaped.text || "(no output)";
|
|
1874
1876
|
refreshable = shaped.refreshable;
|
|
1875
1877
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { captchaText, provisionalName, REFRESH_ID, refreshRow, shapeAnswer, threadContext, threadDate } from "./research.ts";
|
|
2
|
+
import { captchaText, provisionalName, REFRESH_ID, refreshRow, shapeAnswer, threadContext, threadDate, titleFromTexts } from "./research.ts";
|
|
3
3
|
import { validateChannel } from "./config.ts";
|
|
4
4
|
|
|
5
5
|
describe("research threads", () => {
|
|
@@ -10,6 +10,11 @@ describe("research threads", () => {
|
|
|
10
10
|
expect(shapeAnswer("Read TITLE: inside a line\nREFRESH: yes, later")).toMatchObject({ title: null, refreshable: false });
|
|
11
11
|
});
|
|
12
12
|
|
|
13
|
+
it("finds the title in an earlier text of the run", () => {
|
|
14
|
+
expect(titleFromTexts(["TITLE: [PRODUCT 2026-11-04] UAE: top 5 running shoes for men", "1. What size?"])).toBe("[PRODUCT 2026-11-04] UAE: top 5 running shoes for men");
|
|
15
|
+
expect(titleFromTexts(["Checking defaults", "1. What size?"])).toBeNull();
|
|
16
|
+
});
|
|
17
|
+
|
|
13
18
|
it("names the thread from the request until the specialist titles it", () => {
|
|
14
19
|
expect(provisionalName("<@1474400000000000000> give me top 5 running shoes for men in UAE", "2026-11-04")).toBe("[RESEARCH 2026-11-04] give me top 5 running shoes for men in UAE");
|
|
15
20
|
expect(provisionalName("x".repeat(200), "2026-11-04")).toHaveLength(100);
|
|
@@ -39,6 +39,17 @@ export function shapeAnswer(output: string): ShapedAnswer {
|
|
|
39
39
|
return { title, text: lines.join("\n").trim(), refreshable };
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
/** 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. */
|
|
43
|
+
export function titleFromTexts(texts: readonly string[]): string | null {
|
|
44
|
+
for (const text of texts) {
|
|
45
|
+
for (const line of text.split("\n")) {
|
|
46
|
+
const titled = TITLE.exec(line.trim());
|
|
47
|
+
if (titled) return titled[1];
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
|
|
42
53
|
/** Requests come from Mira, so a thread carries Dubai's date. */
|
|
43
54
|
const REQUEST_TIME_ZONE = "Asia/Dubai";
|
|
44
55
|
|