Separate short review context from full supervisor orientation

This commit is contained in:
wassname committed 2026-09-09 10:35:39 +08:00
1 parent e19028e330
commit a7385d4b76
6 files changed
+79 -23

No files matched your search

+1 -1
View File
@@ -52,7 +52,7 @@ it("runs a forked Pi supervisor and receives its exact instruction in another Pi
let body = "";
for await (const chunk of request) body += chunk;
const input = JSON.parse(body);
const latest = input.messages.at(-1);
const latest = input.messages.filter((message: any) => !JSON.stringify(message.content).includes("Full active plan:")).at(-1);
const steer = latest.role === "user" && JSON.stringify(latest.content).includes("The worker stopped.");
if (steer) supervisorTools = input.tools.map((tool: any) => tool.function.name);
response.writeHead(200, { "content-type": "text/event-stream" });
+18
View File
@@ -0,0 +1,18 @@
import { expect, it } from "vitest";
import { planViews } from "../src/plan-view.js";
it("keeps outcome, preferences and discriminators without tasks or history", () => {
const plan = "# Outcome\nBeat random, not just plot it.\n## User preferences\nKeep costs low.\n## Goals\n1. [ ] goal: repair\n - discriminator: beats random\n - subtle failure mode: plot exists but result fails\n - tasks:\n 1. [x] draw plot\n - evidence:\n - old output\n2. [ ] goal: confirm\n## Task list\n- [ ] run it\n## Appendix\nunapproved idea";
const views = planViews(plan);
for (const text of ["Beat random", "Keep costs low", "goal: repair", "discriminator: beats random", "subtle failure mode", "goal: confirm"]) expect(views.short).toContain(text);
for (const text of ["draw plot", "old output", "run it", "unapproved idea"]) expect(views.short).not.toContain(text);
expect(views.long).toContain("draw plot");
expect(views.long).toContain("old output");
expect(views.long).not.toContain("unapproved idea");
});
it("stops at history and preserves a manual goal tick", () => {
const view = planViews("# Plan\n1. [x] goal: result\n## Log\n1. [ ] goal: historical");
expect(view.short).toContain("[x] goal: result");
expect(view.long).not.toContain("historical");
});
+9 -8
View File
@@ -133,19 +133,20 @@ describe("visible supervisor session", () => {
try {
writeFileSync(join(cwd, "plan.md"), "# Outcome\nBeat random\n1. [ ] goal: repair\n - discriminator: beats random\n## Log\nold history");
const runtime = setup(cwd, join(cwd, "plan.md"));
const { systemPrompt } = await runtime.hooks.get("before_agent_start")({}, runtime.ctx);
const first = await runtime.hooks.get("before_agent_start")({}, runtime.ctx);
const systemPrompt = `${first.systemPrompt}\n${first.message.content}`;
expect(systemPrompt).toContain("brief visible recap");
expect(systemPrompt).toContain("discriminator: beats random");
expect(systemPrompt).not.toContain("old history");
expect(systemPrompt).toContain("Supervisor role reminder:");
const review = async () => (await runtime.hooks.get("before_agent_start")({}, runtime.ctx)).systemPrompt;
expect(await review()).not.toContain("Supervisor role reminder:");
for (let i = 0; i < 5; i++) await runtime.hooks.get("turn_end")({}, runtime.ctx);
expect(await review()).toContain("Supervisor role reminder:");
expect(first.message.customType).toBe("pi-goals-supervisor-role");
const review = async () => runtime.hooks.get("before_agent_start")({}, runtime.ctx);
const next = await review();
expect(next.message).toBeUndefined();
expect(next.systemPrompt).toContain("autonomously extending the user's agency");
await runtime.hooks.get("session_compact")({}, runtime.ctx);
expect(await review()).toContain("Supervisor role reminder:");
expect((await review()).message.content).toContain("Protect the user's epistemic autonomy");
writeFileSync(join(cwd, "plan.md"), "# Outcome\nBeat random\n1. [x] goal: repair\n - discriminator: beats random\n");
expect(await review()).toContain("Supervisor role reminder:");
expect((await review()).systemPrompt).toContain("[x] goal: repair");
expect(systemPrompt).toContain("your judgment");
expect(systemPrompt).toContain("justified confidence, not certainty at any cost");
expect(systemPrompt).toContain('Treat "blocked", "waiting", "impossible", and "already done" as claims to investigate');