@soleone/factory 0.3.1 → 0.3.3
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/dist/cli.mjs
CHANGED
|
@@ -202,6 +202,8 @@ const TIERS = [
|
|
|
202
202
|
"builder",
|
|
203
203
|
"grunt"
|
|
204
204
|
];
|
|
205
|
+
/** The plays of factory's own jobs that write a goal's plan. */
|
|
206
|
+
const PLANNING = ["decompose", "replan"];
|
|
205
207
|
const presetId = (preset) => preset.id ?? [
|
|
206
208
|
preset.agent,
|
|
207
209
|
preset.model,
|
|
@@ -636,10 +638,12 @@ function replay(events) {
|
|
|
636
638
|
if (event.type === "requeue" || event.type === "unblock") {
|
|
637
639
|
job.state = "queued";
|
|
638
640
|
job.blocked = void 0;
|
|
641
|
+
job.why = void 0;
|
|
639
642
|
}
|
|
640
643
|
if (event.type === "retry") {
|
|
641
644
|
job.state = "queued";
|
|
642
645
|
job.blocked = void 0;
|
|
646
|
+
job.why = void 0;
|
|
643
647
|
failures.set(job.id, 0);
|
|
644
648
|
}
|
|
645
649
|
if (event.type === "move") {
|
|
@@ -660,10 +664,12 @@ function replay(events) {
|
|
|
660
664
|
if (event.type === "block") {
|
|
661
665
|
job.state = "blocked";
|
|
662
666
|
job.blocked = event.reason;
|
|
667
|
+
job.why = event.why;
|
|
663
668
|
}
|
|
664
669
|
if (event.type === "merged") {
|
|
665
670
|
job.state = "done";
|
|
666
671
|
job.blocked = void 0;
|
|
672
|
+
job.why = void 0;
|
|
667
673
|
}
|
|
668
674
|
if (event.type === "update") Object.assign(job, event.change);
|
|
669
675
|
if (event.type === "verify") job.unverified = event.need ? job.unverified.filter((need) => need !== event.need) : [];
|
|
@@ -688,7 +694,8 @@ function replay(events) {
|
|
|
688
694
|
const said = job.notes.filter((note) => note.attempt === number);
|
|
689
695
|
const asked = said.findLastIndex((note) => note.kind === "ask") > said.findLastIndex((note) => note.kind === "answer" && note.re === void 0);
|
|
690
696
|
const lacking = [...job.notes.findLast((note) => note.kind === "result" && note.attempt === number)?.unverified ?? [], ...event.attempt.missing ?? []];
|
|
691
|
-
|
|
697
|
+
const planning = PLANNING.includes(job.item.play);
|
|
698
|
+
if (outcome === "done" && lacking.length && !planning) job.unverified = [.../* @__PURE__ */ new Set([...job.unverified, ...lacking])];
|
|
692
699
|
if (asked) {
|
|
693
700
|
job.state = "blocked";
|
|
694
701
|
job.blocked = "asked";
|
|
@@ -826,6 +833,28 @@ function addJob(state, job, at = (/* @__PURE__ */ new Date()).toISOString()) {
|
|
|
826
833
|
});
|
|
827
834
|
return fresh(job, at);
|
|
828
835
|
}
|
|
836
|
+
/** A job of the user's own, from a prompt for a tier, without workwork. */
|
|
837
|
+
function addOwnJob(state, own) {
|
|
838
|
+
if (!TIERS.includes(own.tier)) throw new Error(`a tier is ${TIERS.join(", ")}, not ${own.tier}`);
|
|
839
|
+
const first = own.prompt.split("\n").find((line) => line.trim());
|
|
840
|
+
if (!first) throw new Error("the prompt is empty");
|
|
841
|
+
const title = own.title?.trim() || first.replace(/^#+\s*/, "").slice(0, 100);
|
|
842
|
+
return addJob(state, {
|
|
843
|
+
id: newId(),
|
|
844
|
+
item: {
|
|
845
|
+
repo: own.repo,
|
|
846
|
+
label: basename(own.repo),
|
|
847
|
+
id: `own-${Date.now()}`,
|
|
848
|
+
play: "own",
|
|
849
|
+
level: "decide",
|
|
850
|
+
title
|
|
851
|
+
},
|
|
852
|
+
source: "pick",
|
|
853
|
+
tier: own.tier,
|
|
854
|
+
prompt: own.prompt,
|
|
855
|
+
after: own.after
|
|
856
|
+
});
|
|
857
|
+
}
|
|
829
858
|
/**
|
|
830
859
|
* Queues a job to rebase the job's PR and resolve its conflicts, unless one is already waiting. It
|
|
831
860
|
* keeps the job's workwork id, so the attempt links the same PR.
|
|
@@ -7802,8 +7831,7 @@ async function release(worktree) {
|
|
|
7802
7831
|
//#region src/backend/goals.ts
|
|
7803
7832
|
const PLAN_FORMAT = "factory-plan/1";
|
|
7804
7833
|
/** Factory's own jobs inside a goal, told apart by their play. */
|
|
7805
|
-
const DECOMPOSE =
|
|
7806
|
-
const REPLAN = "replan";
|
|
7834
|
+
const [DECOMPOSE, REPLAN] = PLANNING;
|
|
7807
7835
|
const REVIEW = "review";
|
|
7808
7836
|
const FIX = "fix";
|
|
7809
7837
|
const CONFLICTS = "conflicts";
|
|
@@ -7834,18 +7862,20 @@ function checkPlan(raw) {
|
|
|
7834
7862
|
}
|
|
7835
7863
|
if (!Array.isArray(plan.nodes) || plan.nodes.length === 0) return [...problems, "nodes is empty"];
|
|
7836
7864
|
const keys = /* @__PURE__ */ new Set();
|
|
7865
|
+
const milestones = new Set(plan.nodes.map((node) => node?.parent));
|
|
7837
7866
|
for (const [index, node] of plan.nodes.entries()) {
|
|
7867
|
+
const runs = !milestones.has(node?.key);
|
|
7838
7868
|
const at = `nodes[${index}]${typeof node?.key === "string" ? ` (${node.key})` : ""}`;
|
|
7839
7869
|
if (typeof node?.key !== "string" || !KEY.test(node.key)) problems.push(`${at}: key must be lowercase letters, digits, . _ -`);
|
|
7840
7870
|
else if (keys.has(node.key)) problems.push(`${at}: key is used twice`);
|
|
7841
7871
|
else keys.add(node.key);
|
|
7842
7872
|
if (typeof node?.title !== "string" || !node.title.trim()) problems.push(`${at}: title is empty`);
|
|
7843
|
-
if (typeof node?.prompt !== "string" || !node.prompt.trim()) problems.push(`${at}: prompt is empty`);
|
|
7844
|
-
if (!isTier(node?.tier)) problems.push(`${at}: tier must be one of ${TIERS.join(", ")}`);
|
|
7873
|
+
if (runs && (typeof node?.prompt !== "string" || !node.prompt.trim())) problems.push(`${at}: prompt is empty`);
|
|
7874
|
+
if ((runs || node?.tier !== void 0) && !isTier(node?.tier)) problems.push(`${at}: tier must be one of ${TIERS.join(", ")}`);
|
|
7845
7875
|
if (node?.review !== void 0 && !isTier(node.review)) problems.push(`${at}: review must be a tier`);
|
|
7846
7876
|
if (!strings(node?.after)) problems.push(`${at}: after must be a list of keys`);
|
|
7847
|
-
if (!strings(node?.touches)) problems.push(`${at}: touches must be a list of globs (empty: anything)`);
|
|
7848
|
-
if (!strings(node?.gates)) problems.push(`${at}: gates must be a list of commands`);
|
|
7877
|
+
if ((runs || node?.touches !== void 0) && !strings(node?.touches)) problems.push(`${at}: touches must be a list of globs (empty: anything)`);
|
|
7878
|
+
if ((runs || node?.gates !== void 0) && !strings(node?.gates)) problems.push(`${at}: gates must be a list of commands`);
|
|
7849
7879
|
if (node?.needs !== void 0 && !strings(node.needs)) problems.push(`${at}: needs must be a list`);
|
|
7850
7880
|
}
|
|
7851
7881
|
for (const node of plan.nodes) {
|
|
@@ -7920,11 +7950,7 @@ async function importPlan(state, plan, into) {
|
|
|
7920
7950
|
goal
|
|
7921
7951
|
});
|
|
7922
7952
|
if (!into) {
|
|
7923
|
-
|
|
7924
|
-
type: "block",
|
|
7925
|
-
id: job.id,
|
|
7926
|
-
reason: "checkpoint"
|
|
7927
|
-
});
|
|
7953
|
+
checkpoint(state, job.id, planReady(plan));
|
|
7928
7954
|
await createBranch(goal);
|
|
7929
7955
|
}
|
|
7930
7956
|
await commitFiles(goal, `factory: plan for ${plan.goal.title}`, {
|
|
@@ -7950,11 +7976,11 @@ function nodeFields(goal, node, ids) {
|
|
|
7950
7976
|
of: goal.id,
|
|
7951
7977
|
key: node.key,
|
|
7952
7978
|
tier: node.tier,
|
|
7953
|
-
prompt: node.prompt,
|
|
7979
|
+
prompt: node.prompt ?? "",
|
|
7954
7980
|
after: node.after.map((key) => ids.get(key)),
|
|
7955
7981
|
parent: node.parent ? ids.get(node.parent) : void 0,
|
|
7956
|
-
gates: node.gates,
|
|
7957
|
-
touches: node.touches,
|
|
7982
|
+
gates: node.gates ?? [],
|
|
7983
|
+
touches: node.touches ?? [],
|
|
7958
7984
|
needs: node.needs ?? [],
|
|
7959
7985
|
checkpoint: node.checkpoint || void 0,
|
|
7960
7986
|
review: node.review
|
|
@@ -8007,7 +8033,7 @@ async function commitFiles(goal, message, files) {
|
|
|
8007
8033
|
});
|
|
8008
8034
|
}
|
|
8009
8035
|
}
|
|
8010
|
-
/** `factory goal new`: a goal
|
|
8036
|
+
/** `factory goal new`: a goal with one job for the communicator, to decompose it; it waits for approval once the plan is in. */
|
|
8011
8037
|
async function newGoal(state, title, repo, brief) {
|
|
8012
8038
|
if (!existsSync(join(repo, ".git"))) throw new Error(`${repo} is not a git repository`);
|
|
8013
8039
|
const summary = brief.trim() || title;
|
|
@@ -8035,11 +8061,6 @@ async function newGoal(state, title, repo, brief) {
|
|
|
8035
8061
|
source: "goal",
|
|
8036
8062
|
goal
|
|
8037
8063
|
});
|
|
8038
|
-
record(state, {
|
|
8039
|
-
type: "block",
|
|
8040
|
-
id: job.id,
|
|
8041
|
-
reason: "checkpoint"
|
|
8042
|
-
});
|
|
8043
8064
|
await createBranch(goal);
|
|
8044
8065
|
await commitFiles(goal, `factory: goal ${title}`, { [memoryPath(slug)]: `# ${title}\n\n${summary}\n\n## Decisions\n` });
|
|
8045
8066
|
addJob(state, {
|
|
@@ -8067,10 +8088,11 @@ const PLAN_SPEC = `A plan is JSON:
|
|
|
8067
8088
|
"after": [keys it depends on], "touches": [globs of files it changes; empty means anything, so it runs alone],
|
|
8068
8089
|
"gates": [commands run in its worktree before it merges], "needs"?: ["display" | "gpu" | ...],
|
|
8069
8090
|
"checkpoint"?: true to pause the goal for the user's approval once it's done,
|
|
8070
|
-
"parent"?: a key, which makes
|
|
8091
|
+
"parent"?: a key, which makes that node a milestone (a milestone's nodes wait for what it comes after; never list your own milestone in after), "review"?: a tier that reviews it before it merges
|
|
8071
8092
|
}]
|
|
8072
8093
|
}
|
|
8073
|
-
|
|
8094
|
+
A milestone never runs: give it only "key", "title" and "after".
|
|
8095
|
+
Rules: keys unique, no cycles, every reference resolves; every node that runs has a tier, a non-empty prompt, and touches and gates (may be empty lists). Nodes whose touches overlap never run at the same time, so precise touches buy parallelism. Each node should fit comfortably in one session of its tier (under about 200k tokens of context).`;
|
|
8074
8096
|
function decomposePrompt(title, repo, slug, brief) {
|
|
8075
8097
|
return `Decompose this goal into a plan of nodes for factory, which runs them with coding agents of three tiers, in parallel where the dependencies allow.
|
|
8076
8098
|
|
|
@@ -8090,7 +8112,7 @@ ${TIER_RUBRIC}
|
|
|
8090
8112
|
|
|
8091
8113
|
## What to do
|
|
8092
8114
|
|
|
8093
|
-
Read the repo enough to plan well. Write the plan to \`${planPath(slug)}\` in this folder, with goal.repo "${repo}" and goal.branch "goal/${slug}". Don't commit it: factory validates it, imports it and shows it to the user for approval. Prefer more, smaller nodes with precise touches over a few big ones, put the foundations first, and give each node gates that prove it works (build, tests, lint).`;
|
|
8115
|
+
Read the repo enough to plan well. Write the plan to \`${planPath(slug)}\` in this folder, with goal.repo "${repo}" and goal.branch "goal/${slug}". Don't commit it: factory validates it, imports it and shows it to the user for approval. Prefer more, smaller nodes with precise touches over a few big ones, put the foundations first, and give each node gates that prove it works (build, tests, lint). A plan has nothing for the user to check by hand, so don't pass \`--unverified\`; say what you're unsure of in your result.`;
|
|
8094
8116
|
}
|
|
8095
8117
|
/** Checks factory itself runs after the agent says it's done, before the job's gates: the plan files. */
|
|
8096
8118
|
function builtinCheck(job, jobs, worktree) {
|
|
@@ -8161,7 +8183,7 @@ ${job.prompt}
|
|
|
8161
8183
|
|
|
8162
8184
|
${goal.summary}
|
|
8163
8185
|
|
|
8164
|
-
Read \`${memoryPath(goal.slug)}\` first: the goal's memory, with the decisions, conventions and traps earlier nodes left. When you commit, append to it what the next node needs to know. The whole plan is in \`${planPath(goal.slug)}
|
|
8186
|
+
Read \`${memoryPath(goal.slug)}\` first: the goal's memory, with the decisions, conventions and traps earlier nodes left. When you commit, append to it what the next node needs to know. The whole plan is in \`${planPath(goal.slug)}\`; read it, but leave it to factory.
|
|
8165
8187
|
${deps.length ? `\n## What this builds on\n\n${deps.join("\n")}\n` : ""}
|
|
8166
8188
|
## How to deliver
|
|
8167
8189
|
|
|
@@ -8213,19 +8235,12 @@ async function delivered$1(state, job, jobs, goalJob, worktree, log) {
|
|
|
8213
8235
|
replanTier
|
|
8214
8236
|
} }
|
|
8215
8237
|
});
|
|
8238
|
+
checkpoint(state, goalJob.id, planReady(plan));
|
|
8216
8239
|
await importPlan(state, plan, goalJob);
|
|
8217
8240
|
record(state, {
|
|
8218
8241
|
type: "merged",
|
|
8219
8242
|
id: job.id
|
|
8220
8243
|
});
|
|
8221
|
-
record(state, {
|
|
8222
|
-
type: "note",
|
|
8223
|
-
id: goalJob.id,
|
|
8224
|
-
note: {
|
|
8225
|
-
kind: "factory",
|
|
8226
|
-
text: `the plan has ${plan.nodes.length} nodes; approve it to start`
|
|
8227
|
-
}
|
|
8228
|
-
});
|
|
8229
8244
|
return;
|
|
8230
8245
|
}
|
|
8231
8246
|
if (play === REPLAN) return applyReplan(state, job, jobs, goalJob, worktree);
|
|
@@ -8251,7 +8266,7 @@ async function delivered$1(state, job, jobs, goalJob, worktree, log) {
|
|
|
8251
8266
|
id: job.id
|
|
8252
8267
|
});
|
|
8253
8268
|
if (findings.length === 0) return merge(state, served, goalJob, worktree, log);
|
|
8254
|
-
addJob(state, helper(served, goalJob, FIX, `Fix review findings: ${served.item.title}`, served.tier, `A review of branch \`${nodeBranch(goal, served.key)}\` found:\n\n${findings.map((each) => `- ${each}`).join("\n")}\n\nFix each one on that branch (it's checked out here), run the checks, commit and push. Don't open a pull request
|
|
8269
|
+
addJob(state, helper(served, goalJob, FIX, `Fix review findings: ${served.item.title}`, served.tier, `A review of branch \`${nodeBranch(goal, served.key)}\` found:\n\n${findings.map((each) => `- ${each}`).join("\n")}\n\nFix each one on that branch (it's checked out here), run the checks, commit and push. Don't open a pull request, and keep what the branch added to the goal memory, \`${memoryPath(goal.slug)}\`.\n\nThe original task:\n\n${served.prompt}`));
|
|
8255
8270
|
return;
|
|
8256
8271
|
}
|
|
8257
8272
|
if (served === job && job.review && !jobs.some((each) => each.branchOf === job.id && each.item.play === REVIEW)) {
|
|
@@ -8288,7 +8303,7 @@ function reviewPrompt(job, goal) {
|
|
|
8288
8303
|
return `Review the work on branch \`${nodeBranch(goal, job.key)}\` (checked out here) against its task below, before factory merges it into \`${integration(goal)}\`. See the change with \`git diff origin/${integration(goal)}...HEAD\`.
|
|
8289
8304
|
|
|
8290
8305
|
1. Run its checks${job.gates.length ? ` (${job.gates.map((gate) => `\`${gate}\``).join(", ")})` : ""} and read the change against the task.
|
|
8291
|
-
2. Look for bugs, missed cases and changes nobody asked for. Skip style the linters already cover.
|
|
8306
|
+
2. Look for bugs, missed cases and changes nobody asked for. Skip style the linters already cover. Additions to the goal memory, \`${memoryPath(goal.slug)}\`, are expected: every node records its decisions there. A change to the plan, \`${planPath(goal.slug)}\`, is a finding.
|
|
8292
8307
|
3. Report with \`factory result "<summary>"\`, adding \`--followup "<finding: file, line, why it matters>"\` for each finding worth fixing. No findings: no --followup. Don't change or push anything.
|
|
8293
8308
|
|
|
8294
8309
|
## The task
|
|
@@ -8411,21 +8426,7 @@ async function afterMerge(state, node, goalId, worktree, log) {
|
|
|
8411
8426
|
type: "unblock",
|
|
8412
8427
|
id: goalId
|
|
8413
8428
|
});
|
|
8414
|
-
if (node.checkpoint) {
|
|
8415
|
-
record(state, {
|
|
8416
|
-
type: "block",
|
|
8417
|
-
id: goalId,
|
|
8418
|
-
reason: "checkpoint"
|
|
8419
|
-
});
|
|
8420
|
-
record(state, {
|
|
8421
|
-
type: "note",
|
|
8422
|
-
id: goalId,
|
|
8423
|
-
note: {
|
|
8424
|
-
kind: "factory",
|
|
8425
|
-
text: `checkpoint after ${node.item.title}; approve to go on`
|
|
8426
|
-
}
|
|
8427
|
-
});
|
|
8428
|
-
}
|
|
8429
|
+
if (node.checkpoint) checkpoint(state, goalId, `${node.item.title} is merged into ${integration(goal)}, and the plan stops here so you can check it. Approving starts the rest`);
|
|
8429
8430
|
const parent = node.parent && readJobs(state).find((each) => each.id === node.parent);
|
|
8430
8431
|
if (parent && parent.state === "done") {
|
|
8431
8432
|
await rebaseOntoMain(state, goalJob, worktree, log);
|
|
@@ -8538,7 +8539,7 @@ Nodes marked heavy compacted their context more than twice: split similar work s
|
|
|
8538
8539
|
|
|
8539
8540
|
## What to do
|
|
8540
8541
|
|
|
8541
|
-
Write the whole plan, as it should be from now on, to \`${replanPath(goal.slug)}\` in this folder (don't commit it). Keep every node that is done, running, or waiting to merge exactly as it is now. You may add nodes and change or drop those that haven't started. Changing or dropping more than a quarter of the unstarted ones stops the goal for the user's approval.
|
|
8542
|
+
Write the whole plan, as it should be from now on, to \`${replanPath(goal.slug)}\` in this folder (don't commit it). Keep every node that is done, running, or waiting to merge exactly as it is now. You may add nodes and change or drop those that haven't started. Changing or dropping more than a quarter of the unstarted ones stops the goal for the user's approval. A plan has nothing for the user to check by hand, so don't pass \`--unverified\`; say what you're unsure of in your result.
|
|
8542
8543
|
|
|
8543
8544
|
${PLAN_SPEC}
|
|
8544
8545
|
|
|
@@ -8553,7 +8554,7 @@ function replanProblems(plan, job, jobs) {
|
|
|
8553
8554
|
if (!started$1(node)) return [];
|
|
8554
8555
|
const now = planned.get(node.key);
|
|
8555
8556
|
if (!now) return [`${node.key} is ${node.state} and has to stay in the plan`];
|
|
8556
|
-
return now.prompt === node.prompt && now.tier === node.tier && JSON.stringify([...now.after].sort()) === JSON.stringify(node.after.map(keyOf).sort()) ? [] : [`${node.key} is ${node.state}; its prompt, tier and after have to stay as they are`];
|
|
8557
|
+
return (now.prompt ?? "") === node.prompt && now.tier === node.tier && JSON.stringify([...now.after].sort()) === JSON.stringify(node.after.map(keyOf).sort()) ? [] : [`${node.key} is ${node.state}; its prompt, tier and after have to stay as they are`];
|
|
8557
8558
|
});
|
|
8558
8559
|
}
|
|
8559
8560
|
const started$1 = (node) => node.state !== "queued" && !(node.state === "blocked" && node.blocked === "held");
|
|
@@ -8614,45 +8615,37 @@ function applyReplan(state, job, jobs, goalJob, worktree) {
|
|
|
8614
8615
|
text: note
|
|
8615
8616
|
}
|
|
8616
8617
|
});
|
|
8617
|
-
if (changed > unstarted.length / 4)
|
|
8618
|
-
record(state, {
|
|
8619
|
-
type: "block",
|
|
8620
|
-
id: goalJob.id,
|
|
8621
|
-
reason: "checkpoint"
|
|
8622
|
-
});
|
|
8623
|
-
record(state, {
|
|
8624
|
-
type: "note",
|
|
8625
|
-
id: goalJob.id,
|
|
8626
|
-
note: {
|
|
8627
|
-
kind: "factory",
|
|
8628
|
-
text: "the replan changed more than a quarter of what's left; approve it to go on"
|
|
8629
|
-
}
|
|
8630
|
-
});
|
|
8631
|
-
}
|
|
8618
|
+
if (changed > unstarted.length / 4) checkpoint(state, goalJob.id, "the replan changed more than a quarter of what's left; approve it to go on");
|
|
8632
8619
|
}
|
|
8633
|
-
|
|
8634
|
-
|
|
8635
|
-
|
|
8636
|
-
const goalJob = jobs.find((each) => each.id === goalId);
|
|
8637
|
-
const budget = goalJob.goal.budget?.attempts;
|
|
8638
|
-
if (!budget || goalJob.state === "blocked" || goalJob.state === "done") return;
|
|
8639
|
-
const used = attemptsUsed(jobs, goalId);
|
|
8640
|
-
const allowed = budget * (1 + goalJob.notes.filter((note) => note.kind === "factory" && note.text.startsWith("budget raised")).length);
|
|
8641
|
-
if (used < allowed) return;
|
|
8620
|
+
const planReady = (plan) => `the plan has ${plan.nodes.length} jobs, shown below. Approving starts them, and nothing runs until then; replan first if it needs changes`;
|
|
8621
|
+
/** Stops the goal for the user's approval, saying why on the goal and in its notes. */
|
|
8622
|
+
function checkpoint(state, id, why) {
|
|
8642
8623
|
record(state, {
|
|
8643
8624
|
type: "block",
|
|
8644
|
-
id
|
|
8645
|
-
reason: "checkpoint"
|
|
8625
|
+
id,
|
|
8626
|
+
reason: "checkpoint",
|
|
8627
|
+
why
|
|
8646
8628
|
});
|
|
8647
8629
|
record(state, {
|
|
8648
8630
|
type: "note",
|
|
8649
|
-
id
|
|
8631
|
+
id,
|
|
8650
8632
|
note: {
|
|
8651
8633
|
kind: "factory",
|
|
8652
|
-
text:
|
|
8634
|
+
text: why
|
|
8653
8635
|
}
|
|
8654
8636
|
});
|
|
8655
8637
|
}
|
|
8638
|
+
/** At its attempt budget a goal waits at a checkpoint; approving gives it the same budget again. */
|
|
8639
|
+
function checkBudget(state, goalId) {
|
|
8640
|
+
const jobs = readJobs(state);
|
|
8641
|
+
const goalJob = jobs.find((each) => each.id === goalId);
|
|
8642
|
+
const budget = goalJob.goal.budget?.attempts;
|
|
8643
|
+
if (!budget || goalJob.state === "blocked" || goalJob.state === "done") return;
|
|
8644
|
+
const used = attemptsUsed(jobs, goalId);
|
|
8645
|
+
const allowed = budget * (1 + goalJob.notes.filter((note) => note.kind === "factory" && note.text.startsWith("budget raised")).length);
|
|
8646
|
+
if (used < allowed) return;
|
|
8647
|
+
checkpoint(state, goalId, `the goal used ${used} of its ${allowed} attempts. Approving gives it ${budget} more; pause or cancel it if it's going nowhere`);
|
|
8648
|
+
}
|
|
8656
8649
|
const attemptsUsed = (jobs, goalId) => jobs.filter((each) => each.of === goalId).reduce((sum, each) => sum + each.attempts.length, 0);
|
|
8657
8650
|
/** The user's go: after the plan, a checkpoint or a used budget. */
|
|
8658
8651
|
function approveGoal(state, goalId) {
|
|
@@ -10659,6 +10652,7 @@ function serve(state, port, host) {
|
|
|
10659
10652
|
return output("workwork", ["prompt", item.id], item.repo);
|
|
10660
10653
|
},
|
|
10661
10654
|
"POST /api/jobs": (body) => addJobs(state, candidates(body.items), "pick", body.pin),
|
|
10655
|
+
"POST /api/jobs/own": (body) => addOwnJob(state, body),
|
|
10662
10656
|
"POST /api/jobs/remove": (_, id) => removeJob(state, id),
|
|
10663
10657
|
"POST /api/jobs/retry": (_, id) => retryJob(state, id),
|
|
10664
10658
|
"POST /api/jobs/answer": (body, id) => answer(state, id, body.text),
|
|
@@ -10806,7 +10800,7 @@ function send(response, type, body) {
|
|
|
10806
10800
|
}
|
|
10807
10801
|
//#endregion
|
|
10808
10802
|
//#region package.json
|
|
10809
|
-
var version = "0.3.
|
|
10803
|
+
var version = "0.3.3";
|
|
10810
10804
|
//#endregion
|
|
10811
10805
|
//#region src/backend/cli.ts
|
|
10812
10806
|
const USAGE = `factory: works workwork candidates and long goals with headless coding agents
|
|
@@ -10838,7 +10832,7 @@ const USAGE = `factory: works workwork candidates and long goals with headless c
|
|
|
10838
10832
|
|
|
10839
10833
|
Goals: one large task as a graph of jobs on its own integration branch
|
|
10840
10834
|
factory goal new "<title>" --repo DIR|--project NAME [--brief FILE]
|
|
10841
|
-
queue a decomposer; the goal waits
|
|
10835
|
+
queue a decomposer; the goal waits for approval once its plan is in;
|
|
10842
10836
|
--project creates $SRC/NAME and a private GitHub repo for it
|
|
10843
10837
|
factory goal import PLAN validate and import a plan (JSON or YAML); waits for approval
|
|
10844
10838
|
factory goal check PLAN validate only, listing every problem
|
|
@@ -11041,27 +11035,14 @@ async function add(ids, values) {
|
|
|
11041
11035
|
}
|
|
11042
11036
|
/** A job from a prompt file, for a tier, without workwork. */
|
|
11043
11037
|
function addOwn(values) {
|
|
11044
|
-
const
|
|
11045
|
-
|
|
11046
|
-
|
|
11047
|
-
|
|
11048
|
-
|
|
11049
|
-
const job = addJob(STATE, {
|
|
11050
|
-
id: newId(),
|
|
11051
|
-
item: {
|
|
11052
|
-
repo,
|
|
11053
|
-
label: basename(repo),
|
|
11054
|
-
id: `own-${Date.now()}`,
|
|
11055
|
-
play: "own",
|
|
11056
|
-
level: "decide",
|
|
11057
|
-
title
|
|
11058
|
-
},
|
|
11059
|
-
source: "pick",
|
|
11060
|
-
tier,
|
|
11061
|
-
prompt,
|
|
11038
|
+
const job = addOwnJob(STATE, {
|
|
11039
|
+
repo: resolve(values.repo ?? "."),
|
|
11040
|
+
prompt: readFileSync(values.prompt, "utf8"),
|
|
11041
|
+
tier: values.tier,
|
|
11042
|
+
title: values.title,
|
|
11062
11043
|
after: values.after
|
|
11063
11044
|
});
|
|
11064
|
-
console.log(`queued ${job.id}: ${title} (${tier})`);
|
|
11045
|
+
console.log(`queued ${job.id}: ${job.item.title} (${job.tier})`);
|
|
11065
11046
|
}
|
|
11066
11047
|
function step(what, values) {
|
|
11067
11048
|
const done = values.done === void 0 ? void 0 : Number(values.done);
|