@soleone/factory 0.3.2 → 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
|
@@ -833,6 +833,28 @@ function addJob(state, job, at = (/* @__PURE__ */ new Date()).toISOString()) {
|
|
|
833
833
|
});
|
|
834
834
|
return fresh(job, at);
|
|
835
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
|
+
}
|
|
836
858
|
/**
|
|
837
859
|
* Queues a job to rebase the job's PR and resolve its conflicts, unless one is already waiting. It
|
|
838
860
|
* keeps the job's workwork id, so the attempt links the same PR.
|
|
@@ -7928,7 +7950,7 @@ async function importPlan(state, plan, into) {
|
|
|
7928
7950
|
goal
|
|
7929
7951
|
});
|
|
7930
7952
|
if (!into) {
|
|
7931
|
-
checkpoint(state, job.id,
|
|
7953
|
+
checkpoint(state, job.id, planReady(plan));
|
|
7932
7954
|
await createBranch(goal);
|
|
7933
7955
|
}
|
|
7934
7956
|
await commitFiles(goal, `factory: plan for ${plan.goal.title}`, {
|
|
@@ -8213,7 +8235,7 @@ async function delivered$1(state, job, jobs, goalJob, worktree, log) {
|
|
|
8213
8235
|
replanTier
|
|
8214
8236
|
} }
|
|
8215
8237
|
});
|
|
8216
|
-
checkpoint(state, goalJob.id,
|
|
8238
|
+
checkpoint(state, goalJob.id, planReady(plan));
|
|
8217
8239
|
await importPlan(state, plan, goalJob);
|
|
8218
8240
|
record(state, {
|
|
8219
8241
|
type: "merged",
|
|
@@ -8404,7 +8426,7 @@ async function afterMerge(state, node, goalId, worktree, log) {
|
|
|
8404
8426
|
type: "unblock",
|
|
8405
8427
|
id: goalId
|
|
8406
8428
|
});
|
|
8407
|
-
if (node.checkpoint) checkpoint(state, goalId,
|
|
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`);
|
|
8408
8430
|
const parent = node.parent && readJobs(state).find((each) => each.id === node.parent);
|
|
8409
8431
|
if (parent && parent.state === "done") {
|
|
8410
8432
|
await rebaseOntoMain(state, goalJob, worktree, log);
|
|
@@ -8595,6 +8617,7 @@ function applyReplan(state, job, jobs, goalJob, worktree) {
|
|
|
8595
8617
|
});
|
|
8596
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");
|
|
8597
8619
|
}
|
|
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`;
|
|
8598
8621
|
/** Stops the goal for the user's approval, saying why on the goal and in its notes. */
|
|
8599
8622
|
function checkpoint(state, id, why) {
|
|
8600
8623
|
record(state, {
|
|
@@ -8621,7 +8644,7 @@ function checkBudget(state, goalId) {
|
|
|
8621
8644
|
const used = attemptsUsed(jobs, goalId);
|
|
8622
8645
|
const allowed = budget * (1 + goalJob.notes.filter((note) => note.kind === "factory" && note.text.startsWith("budget raised")).length);
|
|
8623
8646
|
if (used < allowed) return;
|
|
8624
|
-
checkpoint(state, goalId, `
|
|
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`);
|
|
8625
8648
|
}
|
|
8626
8649
|
const attemptsUsed = (jobs, goalId) => jobs.filter((each) => each.of === goalId).reduce((sum, each) => sum + each.attempts.length, 0);
|
|
8627
8650
|
/** The user's go: after the plan, a checkpoint or a used budget. */
|
|
@@ -10629,6 +10652,7 @@ function serve(state, port, host) {
|
|
|
10629
10652
|
return output("workwork", ["prompt", item.id], item.repo);
|
|
10630
10653
|
},
|
|
10631
10654
|
"POST /api/jobs": (body) => addJobs(state, candidates(body.items), "pick", body.pin),
|
|
10655
|
+
"POST /api/jobs/own": (body) => addOwnJob(state, body),
|
|
10632
10656
|
"POST /api/jobs/remove": (_, id) => removeJob(state, id),
|
|
10633
10657
|
"POST /api/jobs/retry": (_, id) => retryJob(state, id),
|
|
10634
10658
|
"POST /api/jobs/answer": (body, id) => answer(state, id, body.text),
|
|
@@ -10776,7 +10800,7 @@ function send(response, type, body) {
|
|
|
10776
10800
|
}
|
|
10777
10801
|
//#endregion
|
|
10778
10802
|
//#region package.json
|
|
10779
|
-
var version = "0.3.
|
|
10803
|
+
var version = "0.3.3";
|
|
10780
10804
|
//#endregion
|
|
10781
10805
|
//#region src/backend/cli.ts
|
|
10782
10806
|
const USAGE = `factory: works workwork candidates and long goals with headless coding agents
|
|
@@ -11011,27 +11035,14 @@ async function add(ids, values) {
|
|
|
11011
11035
|
}
|
|
11012
11036
|
/** A job from a prompt file, for a tier, without workwork. */
|
|
11013
11037
|
function addOwn(values) {
|
|
11014
|
-
const
|
|
11015
|
-
|
|
11016
|
-
|
|
11017
|
-
|
|
11018
|
-
|
|
11019
|
-
const job = addJob(STATE, {
|
|
11020
|
-
id: newId(),
|
|
11021
|
-
item: {
|
|
11022
|
-
repo,
|
|
11023
|
-
label: basename(repo),
|
|
11024
|
-
id: `own-${Date.now()}`,
|
|
11025
|
-
play: "own",
|
|
11026
|
-
level: "decide",
|
|
11027
|
-
title
|
|
11028
|
-
},
|
|
11029
|
-
source: "pick",
|
|
11030
|
-
tier,
|
|
11031
|
-
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,
|
|
11032
11043
|
after: values.after
|
|
11033
11044
|
});
|
|
11034
|
-
console.log(`queued ${job.id}: ${title} (${tier})`);
|
|
11045
|
+
console.log(`queued ${job.id}: ${job.item.title} (${job.tier})`);
|
|
11035
11046
|
}
|
|
11036
11047
|
function step(what, values) {
|
|
11037
11048
|
const done = values.done === void 0 ? void 0 : Number(values.done);
|