@faberon/chat 0.1.1 → 0.1.2
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 +3 -3
- package/package.json +1 -1
- package/src/api/client.ts +16 -0
- package/src/api/types.ts +20 -1
- package/src/drafter.ts +38 -0
- package/src/index.ts +56 -2
- package/src/tools/cancel-campaign.ts +25 -1
- package/src/tools/confirm.ts +22 -0
- package/src/tools/create-campaign.ts +72 -11
- package/src/tools/create-successor.ts +87 -0
- package/src/tools/list-campaigns.ts +12 -4
- package/src/tools/resume-campaign.ts +24 -1
- package/src/tools/show-campaign.ts +9 -2
package/README.md
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
The chat interface of [Faberon](https://github.com/sevren-ai/faberon), an autonomous ML research harness.
|
|
4
4
|
|
|
5
|
-
Faberon Chat is a [Pi](https://github.com/earendil-works/pi
|
|
5
|
+
Faberon Chat is a [Pi](https://github.com/earendil-works/pi) extension for operating Faberon campaigns from a chat session: draft a research plan conversationally, submit it, watch proposals and judgments stream in live, inject ideas mid-run, and cancel campaigns. Every write goes through the brain's HTTP API; the chat interface proposes, the brain decides.
|
|
6
6
|
|
|
7
|
-
The brain ships separately as [faberon](https://pypi.org/project/faberon/) on PyPI and provides the `faberon` CLI, which covers the
|
|
7
|
+
The brain ships separately as [faberon](https://pypi.org/project/faberon/) on PyPI and provides the `faberon` CLI, which covers the campaign operations from a shell. Idea injection is currently chat-only.
|
|
8
8
|
|
|
9
9
|
## Install
|
|
10
10
|
|
|
@@ -16,7 +16,7 @@ pi install npm:@faberon/chat
|
|
|
16
16
|
|
|
17
17
|
## Documentation
|
|
18
18
|
|
|
19
|
-
Install guides, quickstart, runbooks, and design docs live in the [repo](https://github.com/sevren-ai/faberon).
|
|
19
|
+
The slash commands and tools are listed in [docs/chat.md](https://github.com/sevren-ai/faberon/blob/main/docs/chat.md). Install guides, quickstart, runbooks, and design docs live in the [repo](https://github.com/sevren-ai/faberon).
|
|
20
20
|
|
|
21
21
|
## Status
|
|
22
22
|
|
package/package.json
CHANGED
package/src/api/client.ts
CHANGED
|
@@ -13,6 +13,7 @@ import type {
|
|
|
13
13
|
CampaignInfo,
|
|
14
14
|
FaberonEvent,
|
|
15
15
|
StatusResponse,
|
|
16
|
+
SuccessorCreate,
|
|
16
17
|
} from "./types.js";
|
|
17
18
|
|
|
18
19
|
export interface ClientConfig {
|
|
@@ -114,6 +115,21 @@ export class FaberonClient {
|
|
|
114
115
|
});
|
|
115
116
|
}
|
|
116
117
|
|
|
118
|
+
/** POST /v0/campaigns/{id}/successor: start a successor from a finished campaign's best kept commit. */
|
|
119
|
+
createSuccessor(
|
|
120
|
+
campaignId: string,
|
|
121
|
+
body: SuccessorCreate,
|
|
122
|
+
): Promise<CampaignCreated> {
|
|
123
|
+
return this.request<CampaignCreated>(
|
|
124
|
+
`/v0/campaigns/${campaignId}/successor`,
|
|
125
|
+
{
|
|
126
|
+
method: "POST",
|
|
127
|
+
headers: { "Content-Type": "application/json" },
|
|
128
|
+
body: JSON.stringify(body),
|
|
129
|
+
},
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
|
|
117
133
|
/** POST /v0/campaigns/{id}/cancel: request cancellation of an active campaign. */
|
|
118
134
|
cancelCampaign(campaignId: string, reason: string): Promise<StatusResponse> {
|
|
119
135
|
return this.request<StatusResponse>(`/v0/campaigns/${campaignId}/cancel`, {
|
package/src/api/types.ts
CHANGED
|
@@ -12,8 +12,8 @@ export interface ResearchPlan {
|
|
|
12
12
|
budget_gpu_hours: number;
|
|
13
13
|
max_experiments: number;
|
|
14
14
|
max_concurrency: number;
|
|
15
|
+
gpus: number;
|
|
15
16
|
walltime: number;
|
|
16
|
-
stop_conditions: string[];
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
export type CampaignStatus = "active" | "ended" | "died";
|
|
@@ -23,13 +23,23 @@ export interface Campaign {
|
|
|
23
23
|
workflow_id: string;
|
|
24
24
|
plan: ResearchPlan;
|
|
25
25
|
repo_path: string;
|
|
26
|
+
branch: string;
|
|
27
|
+
start_sha: string;
|
|
26
28
|
poll_interval_seconds: number;
|
|
27
29
|
created_at: string;
|
|
28
30
|
}
|
|
29
31
|
|
|
32
|
+
export interface CampaignProgress {
|
|
33
|
+
experiments_done: number;
|
|
34
|
+
gpu_hours_burned: number;
|
|
35
|
+
baseline: number;
|
|
36
|
+
best_metric: number | null;
|
|
37
|
+
}
|
|
38
|
+
|
|
30
39
|
export interface CampaignInfo {
|
|
31
40
|
campaign: Campaign;
|
|
32
41
|
status: CampaignStatus;
|
|
42
|
+
progress: CampaignProgress;
|
|
33
43
|
stop_reason?: string | null;
|
|
34
44
|
}
|
|
35
45
|
|
|
@@ -38,6 +48,7 @@ export interface CampaignCreate {
|
|
|
38
48
|
campaign_id: string;
|
|
39
49
|
plan: ResearchPlan;
|
|
40
50
|
repo_path: string;
|
|
51
|
+
branch?: string;
|
|
41
52
|
poll_interval_seconds: number;
|
|
42
53
|
}
|
|
43
54
|
|
|
@@ -47,6 +58,14 @@ export interface CampaignCreated {
|
|
|
47
58
|
workflow_id: string;
|
|
48
59
|
}
|
|
49
60
|
|
|
61
|
+
/** POST /v0/campaigns/{id}/successor body. */
|
|
62
|
+
export interface SuccessorCreate {
|
|
63
|
+
campaign_id: string;
|
|
64
|
+
branch?: string;
|
|
65
|
+
budget_gpu_hours: number;
|
|
66
|
+
max_experiments: number;
|
|
67
|
+
}
|
|
68
|
+
|
|
50
69
|
/** Status body returned by the write endpoints. */
|
|
51
70
|
export interface StatusResponse {
|
|
52
71
|
campaign_id: string;
|
package/src/drafter.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The drafter: a conversational intake mode that interviews the human and
|
|
3
|
+
* drafts a research plan. `/faberon-draft` sends the prompt into the session.
|
|
4
|
+
*
|
|
5
|
+
* The drafter has no autonomous authority. Submission goes through the same
|
|
6
|
+
* `faberon_create_campaign` path as a hand-written plan, and only after the
|
|
7
|
+
* human explicitly agrees in conversation.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/** Build the prompt that starts a drafter interview. */
|
|
11
|
+
export function drafterPrompt(cwd: string): string {
|
|
12
|
+
return `You are the Faberon drafter. Interview the human and draft a research plan for a new Faberon campaign.
|
|
13
|
+
|
|
14
|
+
Before anything else, confirm the target repo with the human. Default: ${cwd}. Then inspect that repo: read its README and code, and use what you find to make educated guesses about the plan. A runnable script that prints a metric line tells you the command, the target file, and the metric name.
|
|
15
|
+
|
|
16
|
+
Then interview the human one question at a time: present your guesses for confirmation or correction, and ask about the fields you could not guess. Keep questions short.
|
|
17
|
+
|
|
18
|
+
For the baseline, you may offer to run the experiment once (from the target repo and without code modifications). Then, read the baseline metric from its output. Never run it without asking the human first. When you ask, warn the user that this may take some time (and provide a time estimate if you can).
|
|
19
|
+
|
|
20
|
+
The final plan needs these fields:
|
|
21
|
+
- repo_path: path to the experiment repo on the shared filesystem. Confirmed up front.
|
|
22
|
+
- goal: what the campaign tries to achieve, in plain prose.
|
|
23
|
+
- command: the command that kicks of each experiment, e.g. "python3 train.py".
|
|
24
|
+
- target_file: the file the proposer edits, relative to the repo root, e.g. "train.py".
|
|
25
|
+
- metric: the metric under optimization, e.g. "val_bpb". The job log must print a line naming it followed by a float, e.g. "val_bpb: 1.10". Use the bare name only, without comments like "(lower is better)": the brain rejects the plan otherwise.
|
|
26
|
+
- baseline: the metric value of the starting commit.
|
|
27
|
+
- budget_gpu_hours: total GPU-hour budget, above zero. Propose it together with max_experiments as one question, using the typical run duration so the two are consistent: 20 runs of about 6 minutes is about 2 GPU-hours.
|
|
28
|
+
- max_experiments: maximum number of experiments, at least 1.
|
|
29
|
+
- walltime: per-job walltime in minutes, above zero. It must cover one full experiment run.
|
|
30
|
+
|
|
31
|
+
When you have every field, show the full plan as a JSON block and ask the human whether they want to change anything. Iterate until they want no more changes.
|
|
32
|
+
|
|
33
|
+
Wanting no more changes is not consent to submit. Once the plan is settled, explain in plain terms what submitting means: Faberon starts a campaign that edits the target file and runs experiments until the budget is spent or the experiment limit is reached. Then ask a separate question: submit the plan now, yes or no. Only a clear yes to that question counts. Approval of the plan itself does not. Submit by calling the faberon_create_campaign tool with the plan and repo_path only after that yes. If the answer is no, do not submit. Offer to save the plan as .faberon/plan.json in the target repo (if that file doesn't exist, otherwise a different name), where the human can edit it by hand and submit it later with /faberon-create. Write the file only if they want it saved. Then keep the plan in the conversation and wait: the human can ask for more changes or tell you to submit after all. Do not call any other Faberon write tool during the interview.
|
|
34
|
+
|
|
35
|
+
After a successful submission, tell the human the campaign id and how to follow the run: /faberon-show and /faberon-events show its progress, and they can inject ideas or cancel at any time. The interview is then over.
|
|
36
|
+
|
|
37
|
+
Ask the first question now.`;
|
|
38
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -3,8 +3,10 @@
|
|
|
3
3
|
*
|
|
4
4
|
* The extension exposes each v0 API operation as a Pi tool (for the
|
|
5
5
|
* model to call in conversation) plus a matching slash command (for the human
|
|
6
|
-
* to invoke directly).
|
|
7
|
-
* the
|
|
6
|
+
* to invoke directly). It also hosts the drafter: `/faberon-draft` starts a
|
|
7
|
+
* conversational intake that ends in the same create path as a hand-written
|
|
8
|
+
* plan. `faberon serve` stays CLI-only: it starts the server the chat
|
|
9
|
+
* interface talks to.
|
|
8
10
|
*/
|
|
9
11
|
|
|
10
12
|
import { readFile } from "node:fs/promises";
|
|
@@ -16,9 +18,11 @@ import type {
|
|
|
16
18
|
} from "@earendil-works/pi-coding-agent";
|
|
17
19
|
import { FaberonClient } from "./api/client.js";
|
|
18
20
|
import type { ResearchPlan } from "./api/types.js";
|
|
21
|
+
import { drafterPrompt } from "./drafter.js";
|
|
19
22
|
import { campaignEventsTool, formatEvents } from "./tools/campaign-events.js";
|
|
20
23
|
import { cancelCampaignTool } from "./tools/cancel-campaign.js";
|
|
21
24
|
import { createCampaignTool, formatCreated } from "./tools/create-campaign.js";
|
|
25
|
+
import { createSuccessorTool } from "./tools/create-successor.js";
|
|
22
26
|
import { injectIdeaTool } from "./tools/inject-idea.js";
|
|
23
27
|
import { formatCampaigns, listCampaignsTool } from "./tools/list-campaigns.js";
|
|
24
28
|
import { resumeCampaignTool } from "./tools/resume-campaign.js";
|
|
@@ -63,6 +67,7 @@ export default function faberonChat(pi: ExtensionAPI): void {
|
|
|
63
67
|
pi.registerTool(showCampaignTool(client));
|
|
64
68
|
pi.registerTool(campaignEventsTool(client));
|
|
65
69
|
pi.registerTool(createCampaignTool(client));
|
|
70
|
+
pi.registerTool(createSuccessorTool(client));
|
|
66
71
|
pi.registerTool(cancelCampaignTool(client));
|
|
67
72
|
pi.registerTool(injectIdeaTool(client));
|
|
68
73
|
pi.registerTool(resumeCampaignTool(client));
|
|
@@ -110,6 +115,14 @@ export default function faberonChat(pi: ExtensionAPI): void {
|
|
|
110
115
|
},
|
|
111
116
|
});
|
|
112
117
|
|
|
118
|
+
pi.registerCommand("faberon-draft", {
|
|
119
|
+
description:
|
|
120
|
+
"Draft a research plan conversationally, review it, then submit it",
|
|
121
|
+
handler: async (_args, ctx) => {
|
|
122
|
+
pi.sendUserMessage(drafterPrompt(ctx.cwd));
|
|
123
|
+
},
|
|
124
|
+
});
|
|
125
|
+
|
|
113
126
|
pi.registerCommand("faberon-create", {
|
|
114
127
|
description:
|
|
115
128
|
"Submit a new Faberon campaign: /faberon-create <plan.json> [repo-path]",
|
|
@@ -124,6 +137,47 @@ export default function faberonChat(pi: ExtensionAPI): void {
|
|
|
124
137
|
},
|
|
125
138
|
});
|
|
126
139
|
|
|
140
|
+
pi.registerCommand("faberon-successor", {
|
|
141
|
+
description:
|
|
142
|
+
"Start a successor campaign from a finished campaign's best kept " +
|
|
143
|
+
"commit: /faberon-successor <campaign-id> <budget-gpu-hours> " +
|
|
144
|
+
"<max-experiments>. Keeps the research plan; use /faberon-create " +
|
|
145
|
+
"to change it",
|
|
146
|
+
getArgumentCompletions: () => null,
|
|
147
|
+
handler: async (args, ctx) => {
|
|
148
|
+
const tokens = args.split(/\s+/).filter((t) => t.length > 0);
|
|
149
|
+
const campaignId =
|
|
150
|
+
tokens[0] ?? (await promptNonEmpty(ctx, "Campaign ID"));
|
|
151
|
+
if (!campaignId) return;
|
|
152
|
+
const budgetToken =
|
|
153
|
+
tokens[1] ?? (await promptNonEmpty(ctx, "Budget in GPU-hours"));
|
|
154
|
+
if (!budgetToken) return;
|
|
155
|
+
const budget = Number(budgetToken);
|
|
156
|
+
if (!Number.isFinite(budget) || budget <= 0) {
|
|
157
|
+
ctx.ui.notify("Budget must be a positive number of GPU-hours", "error");
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
const maxExperimentsToken =
|
|
161
|
+
tokens[2] ?? (await promptNonEmpty(ctx, "Max experiments"));
|
|
162
|
+
if (!maxExperimentsToken) return;
|
|
163
|
+
const maxExperiments = Number(maxExperimentsToken);
|
|
164
|
+
if (!Number.isInteger(maxExperiments) || maxExperiments < 1) {
|
|
165
|
+
ctx.ui.notify("Max experiments must be a positive integer", "error");
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
await notify(
|
|
169
|
+
ctx,
|
|
170
|
+
client
|
|
171
|
+
.createSuccessor(campaignId, {
|
|
172
|
+
campaign_id: randomUUID(),
|
|
173
|
+
budget_gpu_hours: budget,
|
|
174
|
+
max_experiments: maxExperiments,
|
|
175
|
+
})
|
|
176
|
+
.then(formatCreated),
|
|
177
|
+
);
|
|
178
|
+
},
|
|
179
|
+
});
|
|
180
|
+
|
|
127
181
|
pi.registerCommand("faberon-cancel", {
|
|
128
182
|
description: "Request cancellation of an active Faberon campaign",
|
|
129
183
|
getArgumentCompletions: () => null,
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import { Type } from "typebox";
|
|
6
6
|
import { defineTool } from "@earendil-works/pi-coding-agent";
|
|
7
7
|
import type { FaberonClient } from "../api/client.js";
|
|
8
|
+
import { confirmedByHuman } from "./confirm.js";
|
|
8
9
|
|
|
9
10
|
export function cancelCampaignTool(client: FaberonClient) {
|
|
10
11
|
return defineTool({
|
|
@@ -24,7 +25,30 @@ export function cancelCampaignTool(client: FaberonClient) {
|
|
|
24
25
|
}),
|
|
25
26
|
}),
|
|
26
27
|
annotations: { destructiveHint: true, idempotentHint: true },
|
|
27
|
-
|
|
28
|
+
executionMode: "sequential",
|
|
29
|
+
async execute(_toolCallId, params, _signal, _onUpdate, ctx) {
|
|
30
|
+
const confirmed = await confirmedByHuman(
|
|
31
|
+
ctx,
|
|
32
|
+
"Cancel this Faberon campaign?",
|
|
33
|
+
[
|
|
34
|
+
`Campaign: ${params.campaign_id}`,
|
|
35
|
+
`Reason: ${params.reason}`,
|
|
36
|
+
"",
|
|
37
|
+
"The campaign ends early and cannot be resumed.",
|
|
38
|
+
].join("\n"),
|
|
39
|
+
);
|
|
40
|
+
if (!confirmed) {
|
|
41
|
+
return {
|
|
42
|
+
content: [
|
|
43
|
+
{
|
|
44
|
+
type: "text",
|
|
45
|
+
text: "The human declined the cancellation. The campaign keeps running. Do not cancel it unless they ask.",
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
details: undefined,
|
|
49
|
+
isError: true,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
28
52
|
const result = await client.cancelCampaign(
|
|
29
53
|
params.campaign_id,
|
|
30
54
|
params.reason,
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared confirmation gate for the write tools. When dialog UI is available,
|
|
3
|
+
* the tool asks the human to confirm before calling the API. In
|
|
4
|
+
* non-interactive modes the call goes through directly: invoking the tool
|
|
5
|
+
* there is already an explicit act.
|
|
6
|
+
*
|
|
7
|
+
* Tools using this gate must declare `executionMode: "sequential"`. Pi runs
|
|
8
|
+
* the tool calls of one turn concurrently by default, and the TUI shows only
|
|
9
|
+
* one extension dialog at a time: a second confirm would silently replace
|
|
10
|
+
* this one. Sequential execution keeps one dialog open at a time.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import type { ExtensionToolContext } from "@earendil-works/pi-coding-agent";
|
|
14
|
+
|
|
15
|
+
/** Ask the human to confirm a write; true when the write may proceed. */
|
|
16
|
+
export async function confirmedByHuman(
|
|
17
|
+
ctx: ExtensionToolContext,
|
|
18
|
+
title: string,
|
|
19
|
+
message: string,
|
|
20
|
+
): Promise<boolean> {
|
|
21
|
+
return !ctx.hasUI || (await ctx.ui.confirm(title, message));
|
|
22
|
+
}
|
|
@@ -6,7 +6,8 @@ import { randomUUID } from "node:crypto";
|
|
|
6
6
|
import { Type } from "typebox";
|
|
7
7
|
import { defineTool } from "@earendil-works/pi-coding-agent";
|
|
8
8
|
import type { FaberonClient } from "../api/client.js";
|
|
9
|
-
import type { CampaignCreated } from "../api/types.js";
|
|
9
|
+
import type { CampaignCreated, ResearchPlan } from "../api/types.js";
|
|
10
|
+
import { confirmedByHuman } from "./confirm.js";
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
13
|
* Render a created campaign for both the tool result and the slash command.
|
|
@@ -15,7 +16,32 @@ export function formatCreated(created: CampaignCreated): string {
|
|
|
15
16
|
return `campaign: ${created.campaign_id}\nworkflow: ${created.workflow_id}`;
|
|
16
17
|
}
|
|
17
18
|
|
|
18
|
-
|
|
19
|
+
/** Longest free-text value the confirm dialog shows in full. */
|
|
20
|
+
const MAX_TEXT_LENGTH = 120;
|
|
21
|
+
|
|
22
|
+
/** Shorten a free-text value so the confirm dialog stays readable. */
|
|
23
|
+
function truncateText(text: string): string {
|
|
24
|
+
return text.length <= MAX_TEXT_LENGTH
|
|
25
|
+
? text
|
|
26
|
+
: `${text.slice(0, MAX_TEXT_LENGTH)}...`;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Render the plan for the confirm dialog: the full JSON, with a long
|
|
31
|
+
* goal truncated.
|
|
32
|
+
*/
|
|
33
|
+
export function formatPlanForConfirm(plan: ResearchPlan): string {
|
|
34
|
+
return JSON.stringify(
|
|
35
|
+
{
|
|
36
|
+
...plan,
|
|
37
|
+
goal: truncateText(plan.goal),
|
|
38
|
+
},
|
|
39
|
+
null,
|
|
40
|
+
2,
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export const planSchema = Type.Object({
|
|
19
45
|
goal: Type.String({
|
|
20
46
|
description: "What the campaign tries to achieve.",
|
|
21
47
|
minLength: 1,
|
|
@@ -26,15 +52,18 @@ const planSchema = Type.Object({
|
|
|
26
52
|
}),
|
|
27
53
|
target_file: Type.String({
|
|
28
54
|
description:
|
|
29
|
-
"Path of the
|
|
55
|
+
"Path of the file the proposer edits, relative to the repo root, " +
|
|
30
56
|
"e.g. 'train.py'.",
|
|
31
57
|
minLength: 1,
|
|
32
58
|
}),
|
|
33
59
|
metric: Type.String({
|
|
34
60
|
description:
|
|
35
|
-
"
|
|
36
|
-
"
|
|
61
|
+
"Bare name of the metric under optimization, e.g. 'val_bpb'. No spaces " +
|
|
62
|
+
"or comments such as '(lower is better)': the brain matches the name " +
|
|
63
|
+
"literally against a job log line like 'val_bpb: 1.10' and rejects the " +
|
|
64
|
+
"plan otherwise.",
|
|
37
65
|
minLength: 1,
|
|
66
|
+
pattern: "^[A-Za-z0-9_.:/-]+$",
|
|
38
67
|
}),
|
|
39
68
|
baseline: Type.Number({
|
|
40
69
|
description: "Metric value of the starting commit.",
|
|
@@ -54,14 +83,17 @@ const planSchema = Type.Object({
|
|
|
54
83
|
minimum: 1,
|
|
55
84
|
}),
|
|
56
85
|
),
|
|
86
|
+
gpus: Type.Optional(
|
|
87
|
+
Type.Integer({
|
|
88
|
+
description: "GPUs requested per job.",
|
|
89
|
+
default: 1,
|
|
90
|
+
minimum: 1,
|
|
91
|
+
}),
|
|
92
|
+
),
|
|
57
93
|
walltime: Type.Integer({
|
|
58
94
|
description: "Per-job walltime in minutes.",
|
|
59
95
|
exclusiveMinimum: 0,
|
|
60
96
|
}),
|
|
61
|
-
stop_conditions: Type.Array(Type.String(), {
|
|
62
|
-
description: "Conditions under which the campaign stops early.",
|
|
63
|
-
minItems: 1,
|
|
64
|
-
}),
|
|
65
97
|
});
|
|
66
98
|
|
|
67
99
|
export function createCampaignTool(client: FaberonClient) {
|
|
@@ -87,10 +119,39 @@ export function createCampaignTool(client: FaberonClient) {
|
|
|
87
119
|
),
|
|
88
120
|
}),
|
|
89
121
|
annotations: {},
|
|
90
|
-
|
|
122
|
+
executionMode: "sequential",
|
|
123
|
+
async execute(_toolCallId, params, _signal, _onUpdate, ctx) {
|
|
124
|
+
const plan: ResearchPlan = {
|
|
125
|
+
max_concurrency: 1,
|
|
126
|
+
gpus: 1,
|
|
127
|
+
...params.plan,
|
|
128
|
+
};
|
|
129
|
+
const confirmed = await confirmedByHuman(
|
|
130
|
+
ctx,
|
|
131
|
+
"Submit this Faberon campaign?",
|
|
132
|
+
[
|
|
133
|
+
`Repo: ${params.repo_path}`,
|
|
134
|
+
"Plan:",
|
|
135
|
+
formatPlanForConfirm(plan),
|
|
136
|
+
"",
|
|
137
|
+
`Faberon starts a campaign that edits ${plan.target_file} and runs experiments until the budget is spent or a stop condition is met.`,
|
|
138
|
+
].join("\n"),
|
|
139
|
+
);
|
|
140
|
+
if (!confirmed) {
|
|
141
|
+
return {
|
|
142
|
+
content: [
|
|
143
|
+
{
|
|
144
|
+
type: "text",
|
|
145
|
+
text: "The human declined the submission. No campaign was created. Do not resubmit unless they ask.",
|
|
146
|
+
},
|
|
147
|
+
],
|
|
148
|
+
details: undefined,
|
|
149
|
+
isError: true,
|
|
150
|
+
};
|
|
151
|
+
}
|
|
91
152
|
const created = await client.createCampaign({
|
|
92
153
|
campaign_id: randomUUID(),
|
|
93
|
-
plan
|
|
154
|
+
plan,
|
|
94
155
|
repo_path: params.repo_path,
|
|
95
156
|
poll_interval_seconds: params.poll_interval_seconds ?? 30,
|
|
96
157
|
});
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `faberon_create_successor` tool: start a successor campaign from a finished
|
|
3
|
+
* campaign's best kept commit.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { randomUUID } from "node:crypto";
|
|
7
|
+
import { Type } from "typebox";
|
|
8
|
+
import { defineTool } from "@earendil-works/pi-coding-agent";
|
|
9
|
+
import type { FaberonClient } from "../api/client.js";
|
|
10
|
+
import { confirmedByHuman } from "./confirm.js";
|
|
11
|
+
import { formatCreated } from "./create-campaign.js";
|
|
12
|
+
|
|
13
|
+
export function createSuccessorTool(client: FaberonClient) {
|
|
14
|
+
return defineTool({
|
|
15
|
+
name: "faberon_create_successor",
|
|
16
|
+
label: "Create a successor campaign",
|
|
17
|
+
description:
|
|
18
|
+
"Start a successor campaign from a finished Faberon campaign's best " +
|
|
19
|
+
"kept commit. The successor keeps the predecessor's research plan " +
|
|
20
|
+
"under a fresh budget and experiment limit, with the baseline " +
|
|
21
|
+
"reseeded from the predecessor's best kept metric. If the research " +
|
|
22
|
+
"plan should change, create a new campaign with " +
|
|
23
|
+
"faberon_create_campaign instead.",
|
|
24
|
+
promptSnippet:
|
|
25
|
+
"Start a successor from a finished Faberon campaign's best kept commit",
|
|
26
|
+
parameters: Type.Object({
|
|
27
|
+
campaign_id: Type.String({
|
|
28
|
+
description: "UUID of the finished campaign to succeed.",
|
|
29
|
+
}),
|
|
30
|
+
budget_gpu_hours: Type.Number({
|
|
31
|
+
description: "Fresh total GPU-hour budget for the successor.",
|
|
32
|
+
exclusiveMinimum: 0,
|
|
33
|
+
}),
|
|
34
|
+
max_experiments: Type.Integer({
|
|
35
|
+
description: "Fresh maximum number of experiments for the successor.",
|
|
36
|
+
minimum: 1,
|
|
37
|
+
}),
|
|
38
|
+
branch: Type.Optional(
|
|
39
|
+
Type.String({
|
|
40
|
+
description:
|
|
41
|
+
"Working branch for the successor. Defaults to a fresh " +
|
|
42
|
+
"faberon/<short-id> branch created at the succession commit.",
|
|
43
|
+
minLength: 1,
|
|
44
|
+
}),
|
|
45
|
+
),
|
|
46
|
+
}),
|
|
47
|
+
annotations: {},
|
|
48
|
+
executionMode: "sequential",
|
|
49
|
+
async execute(_toolCallId, params, _signal, _onUpdate, ctx) {
|
|
50
|
+
const info = await client.getCampaign(params.campaign_id);
|
|
51
|
+
const confirmed = await confirmedByHuman(
|
|
52
|
+
ctx,
|
|
53
|
+
"Start a successor campaign?",
|
|
54
|
+
[
|
|
55
|
+
`Predecessor: ${params.campaign_id} (${info.status})`,
|
|
56
|
+
`budget_gpu_hours: ${params.budget_gpu_hours}`,
|
|
57
|
+
`max_experiments: ${params.max_experiments}`,
|
|
58
|
+
...(params.branch !== undefined ? [`branch: ${params.branch}`] : []),
|
|
59
|
+
"",
|
|
60
|
+
"Faberon starts a new campaign from the predecessor's best kept commit and runs experiments until the fresh budget is spent or a stop condition is met.",
|
|
61
|
+
].join("\n"),
|
|
62
|
+
);
|
|
63
|
+
if (!confirmed) {
|
|
64
|
+
return {
|
|
65
|
+
content: [
|
|
66
|
+
{
|
|
67
|
+
type: "text",
|
|
68
|
+
text: "The human declined the succession. No successor campaign was created. Do not create it unless they ask.",
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
details: undefined,
|
|
72
|
+
isError: true,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
const created = await client.createSuccessor(params.campaign_id, {
|
|
76
|
+
campaign_id: randomUUID(),
|
|
77
|
+
budget_gpu_hours: params.budget_gpu_hours,
|
|
78
|
+
max_experiments: params.max_experiments,
|
|
79
|
+
...(params.branch !== undefined ? { branch: params.branch } : {}),
|
|
80
|
+
});
|
|
81
|
+
return {
|
|
82
|
+
content: [{ type: "text", text: formatCreated(created) }],
|
|
83
|
+
details: created,
|
|
84
|
+
};
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
}
|
|
@@ -15,11 +15,18 @@ export function formatCampaigns(infos: CampaignInfo[]): string {
|
|
|
15
15
|
return "No campaigns yet.";
|
|
16
16
|
}
|
|
17
17
|
const pad = (s: string, n: number) => s.padEnd(n, " ");
|
|
18
|
-
const header = `${pad("ID", 36)} ${pad("CREATED", 16)} ${pad("STATUS", 6)} ${pad("METRIC", 12)} REPO`;
|
|
18
|
+
const header = `${pad("ID", 36)} ${pad("CREATED", 16)} ${pad("STATUS", 6)} ${pad("METRIC", 12)} ${pad("EXPS", 7)} ${pad("GPU-H", 12)} ${pad("BEST", 16)} REPO`;
|
|
19
19
|
const lines = infos.map((info) => {
|
|
20
20
|
const c = info.campaign;
|
|
21
|
+
const p = info.progress;
|
|
21
22
|
const created = c.created_at.slice(0, 16).replace("T", " ");
|
|
22
|
-
|
|
23
|
+
const exps = `${p.experiments_done}/${c.plan.max_experiments}`;
|
|
24
|
+
const gpuH = `${p.gpu_hours_burned}/${c.plan.budget_gpu_hours}`;
|
|
25
|
+
const best =
|
|
26
|
+
p.best_metric != null
|
|
27
|
+
? `${p.baseline}->${p.best_metric}`
|
|
28
|
+
: `baseline:${p.baseline}`;
|
|
29
|
+
return `${c.campaign_id} ${created} ${pad(info.status, 6)} ${pad(c.plan.metric, 12)} ${pad(exps, 7)} ${pad(gpuH, 12)} ${pad(best, 16)} ${c.repo_path}`;
|
|
23
30
|
});
|
|
24
31
|
return [header, ...lines].join("\n");
|
|
25
32
|
}
|
|
@@ -29,8 +36,9 @@ export function listCampaignsTool(client: FaberonClient) {
|
|
|
29
36
|
name: "faberon_list_campaigns",
|
|
30
37
|
label: "List Faberon campaigns",
|
|
31
38
|
description:
|
|
32
|
-
"List all Faberon research campaigns with their live status
|
|
33
|
-
"
|
|
39
|
+
"List all Faberon research campaigns with their live status, " +
|
|
40
|
+
"creation time, repo path, metric and progress. " +
|
|
41
|
+
"Oldest first.",
|
|
34
42
|
promptSnippet: "List Faberon campaigns and their live status",
|
|
35
43
|
parameters: Type.Object({}),
|
|
36
44
|
annotations: { readOnlyHint: true },
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import { Type } from "typebox";
|
|
6
6
|
import { defineTool } from "@earendil-works/pi-coding-agent";
|
|
7
7
|
import type { FaberonClient } from "../api/client.js";
|
|
8
|
+
import { confirmedByHuman } from "./confirm.js";
|
|
8
9
|
|
|
9
10
|
export function resumeCampaignTool(client: FaberonClient) {
|
|
10
11
|
return defineTool({
|
|
@@ -21,7 +22,29 @@ export function resumeCampaignTool(client: FaberonClient) {
|
|
|
21
22
|
}),
|
|
22
23
|
}),
|
|
23
24
|
annotations: { idempotentHint: true },
|
|
24
|
-
|
|
25
|
+
executionMode: "sequential",
|
|
26
|
+
async execute(_toolCallId, params, _signal, _onUpdate, ctx) {
|
|
27
|
+
const confirmed = await confirmedByHuman(
|
|
28
|
+
ctx,
|
|
29
|
+
"Resume this Faberon campaign?",
|
|
30
|
+
[
|
|
31
|
+
`Campaign: ${params.campaign_id}`,
|
|
32
|
+
"",
|
|
33
|
+
"The campaign continues running experiments and spending its remaining GPU-hour budget.",
|
|
34
|
+
].join("\n"),
|
|
35
|
+
);
|
|
36
|
+
if (!confirmed) {
|
|
37
|
+
return {
|
|
38
|
+
content: [
|
|
39
|
+
{
|
|
40
|
+
type: "text",
|
|
41
|
+
text: "The human declined the resume. The campaign stays pending. Do not resume it unless they ask.",
|
|
42
|
+
},
|
|
43
|
+
],
|
|
44
|
+
details: undefined,
|
|
45
|
+
isError: true,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
25
48
|
const result = await client.resumeCampaign(params.campaign_id);
|
|
26
49
|
return {
|
|
27
50
|
content: [{ type: "text", text: result.status }],
|
|
@@ -12,7 +12,12 @@ import type { CampaignInfo } from "../api/types.js";
|
|
|
12
12
|
*/
|
|
13
13
|
export function formatCampaign(info: CampaignInfo): string {
|
|
14
14
|
const campaign = info.campaign;
|
|
15
|
+
const progress = info.progress;
|
|
15
16
|
const created = campaign.created_at.slice(0, 16).replace("T", " ");
|
|
17
|
+
const best =
|
|
18
|
+
progress.best_metric != null
|
|
19
|
+
? `${progress.baseline} -> ${progress.best_metric}`
|
|
20
|
+
: `baseline:${progress.baseline}`;
|
|
16
21
|
const lines = [
|
|
17
22
|
`campaign: ${campaign.campaign_id}`,
|
|
18
23
|
`created: ${created}`,
|
|
@@ -21,6 +26,9 @@ export function formatCampaign(info: CampaignInfo): string {
|
|
|
21
26
|
`metric: ${campaign.plan.metric}`,
|
|
22
27
|
`budget: ${campaign.plan.budget_gpu_hours} gpu-hours`,
|
|
23
28
|
`max exp: ${campaign.plan.max_experiments}`,
|
|
29
|
+
`exp done: ${progress.experiments_done}/${campaign.plan.max_experiments}`,
|
|
30
|
+
`burned: ${progress.gpu_hours_burned}/${campaign.plan.budget_gpu_hours} gpu-hours`,
|
|
31
|
+
`best: ${best}`,
|
|
24
32
|
`status: ${info.status}`,
|
|
25
33
|
];
|
|
26
34
|
if (info.stop_reason != null) {
|
|
@@ -34,8 +42,7 @@ export function showCampaignTool(client: FaberonClient) {
|
|
|
34
42
|
name: "faberon_show_campaign",
|
|
35
43
|
label: "Show one Faberon campaign",
|
|
36
44
|
description:
|
|
37
|
-
"Show one Faberon campaign's live status
|
|
38
|
-
"metric, budget, experiment limit, and stop reason when it has ended.",
|
|
45
|
+
"Show one Faberon campaign's live status, research plan, and progress.",
|
|
39
46
|
promptSnippet: "Show one Faberon campaign's status and plan",
|
|
40
47
|
parameters: Type.Object({
|
|
41
48
|
campaign_id: Type.String({
|