@soleone/factory 0.3.0 → 0.3.1
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
CHANGED
|
@@ -33,11 +33,12 @@ Needs node 22+, git, [workwork](https://github.com/Soleone/workwork) with `--jso
|
|
|
33
33
|
### Goals
|
|
34
34
|
|
|
35
35
|
```sh
|
|
36
|
-
factory goal new "GPUI client for Tasks" --repo ~/src/tasks --brief brief.md
|
|
36
|
+
factory goal new "GPUI client for Tasks" --repo ~/src/tasks --brief brief.md # or --project NAME
|
|
37
37
|
factory goal show gpui-client # the graph before anything runs: tiers, critical path, estimate
|
|
38
38
|
factory goal approve gpui-client
|
|
39
39
|
```
|
|
40
40
|
|
|
41
|
+
- **Starting one:** **New goal** on the Goals tab takes a title, a repo and a brief, or a plan to import. **New project...** in its repo list creates `$SRC/<name>` and a private GitHub repo of the same name (`goal new --project NAME` on the command line). The Live Agent can work out the brief with you and start the goal too; approving its plan stays with you.
|
|
41
42
|
- **Planning:** `goal new` queues a communicator to decompose the goal into a plan, which factory validates and imports, then waits for your approval. `goal import plan.json` takes a plan you wrote, with someone or something else; [spec/plan-format.md](spec/plan-format.md) describes the format (JSON or YAML) and `goal check` validates one.
|
|
42
43
|
- **Branches:** the goal gets `goal/<slug>` on origin. Each node works on `node/<slug>/<key>`, started from the integration branch's head; it commits and pushes but never opens a PR. Factory runs its gates, rebases it onto the integration branch, opens the PR and merges it, then runs the goal's own gates. A conflict queues a job to resolve it; a red integration branch pauses the goal and queues a fix.
|
|
43
44
|
- **Memory:** `.factory/<slug>.md` on the integration branch holds the goal's summary and the decisions each node leaves for the next. Prompts carry the goal summary, what a node's dependencies delivered, and a pointer to the memory.
|
package/dist/cli.mjs
CHANGED
|
@@ -8735,6 +8735,13 @@ function readPlan(file) {
|
|
|
8735
8735
|
if (!existsSync(file) || !statSync(file).isFile()) throw new Error(`no plan file ${file}`);
|
|
8736
8736
|
return parsePlan(readFileSync(file, "utf8"), file);
|
|
8737
8737
|
}
|
|
8738
|
+
/** A pasted plan, JSON or YAML (YAML reads both), imported once it's valid. */
|
|
8739
|
+
async function importPlanText(state, text) {
|
|
8740
|
+
const plan = (0, import_dist.parse)(text);
|
|
8741
|
+
const problems = checkPlan(plan);
|
|
8742
|
+
if (problems.length) throw new Error(`the plan has problems:\n${problems.map((each) => `- ${each}`).join("\n")}`);
|
|
8743
|
+
return importPlan(state, plan);
|
|
8744
|
+
}
|
|
8738
8745
|
//#endregion
|
|
8739
8746
|
//#region src/backend/models.ts
|
|
8740
8747
|
/** Every model each agent offers, its short list first. */
|
|
@@ -9992,6 +9999,102 @@ function log(message) {
|
|
|
9992
9999
|
console.log(`${(/* @__PURE__ */ new Date()).toISOString()} ${message}`);
|
|
9993
10000
|
}
|
|
9994
10001
|
//#endregion
|
|
10002
|
+
//#region src/backend/repos.ts
|
|
10003
|
+
/** Where workwork --all looks for repos, with the same fallback. */
|
|
10004
|
+
const sourceRoot = () => resolve(process.env.SRC ?? process.cwd());
|
|
10005
|
+
/** Local repos are available as filters even when workwork finds no candidates in them. */
|
|
10006
|
+
function localRepos() {
|
|
10007
|
+
const root = sourceRoot();
|
|
10008
|
+
return existsSync(root) ? findRepos(root, 4) : [];
|
|
10009
|
+
}
|
|
10010
|
+
/**
|
|
10011
|
+
* The GitHub user's own repos (not forked or archived) that aren't cloned anywhere under $SRC
|
|
10012
|
+
* yet, newest first.
|
|
10013
|
+
*/
|
|
10014
|
+
async function clonableRepos() {
|
|
10015
|
+
const root = sourceRoot();
|
|
10016
|
+
const listed = JSON.parse(await output("gh", [
|
|
10017
|
+
"repo",
|
|
10018
|
+
"list",
|
|
10019
|
+
"--source",
|
|
10020
|
+
"--no-archived",
|
|
10021
|
+
"--limit",
|
|
10022
|
+
"5000",
|
|
10023
|
+
"--json",
|
|
10024
|
+
"nameWithOwner,description,createdAt"
|
|
10025
|
+
], root));
|
|
10026
|
+
const cloned = new Set(await Promise.all(localRepos().map(originName)));
|
|
10027
|
+
return {
|
|
10028
|
+
root,
|
|
10029
|
+
repos: listed.filter((repo) => !cloned.has(repo.nameWithOwner.toLowerCase())).map((repo) => ({
|
|
10030
|
+
name: repo.nameWithOwner,
|
|
10031
|
+
description: repo.description,
|
|
10032
|
+
createdAt: repo.createdAt
|
|
10033
|
+
})).sort((a, b) => b.createdAt.localeCompare(a.createdAt))
|
|
10034
|
+
};
|
|
10035
|
+
}
|
|
10036
|
+
/** Clones `name` (owner/repo) to $SRC/<repo> and returns that path. */
|
|
10037
|
+
async function cloneRepo(name) {
|
|
10038
|
+
if (!/^[\w.-]+\/[\w.-]+$/.test(name)) throw new Error(`${name} isn't a GitHub owner/repo`);
|
|
10039
|
+
const root = sourceRoot();
|
|
10040
|
+
const path = join(root, name.split("/")[1]);
|
|
10041
|
+
if (existsSync(path)) throw new Error(`${path} already exists`);
|
|
10042
|
+
await output("gh", [
|
|
10043
|
+
"repo",
|
|
10044
|
+
"clone",
|
|
10045
|
+
name,
|
|
10046
|
+
path
|
|
10047
|
+
], root);
|
|
10048
|
+
return path;
|
|
10049
|
+
}
|
|
10050
|
+
/**
|
|
10051
|
+
* A new project: $SRC/<name> with a first commit, pushed to a new private GitHub repo of the same
|
|
10052
|
+
* name, since a goal's integration branch lives on origin. Returns its path.
|
|
10053
|
+
*/
|
|
10054
|
+
async function createRepo(name) {
|
|
10055
|
+
if (!/^[\w.-]+$/.test(name)) throw new Error(`${name} isn't a repo name: letters, digits, . _ -`);
|
|
10056
|
+
const path = join(sourceRoot(), name);
|
|
10057
|
+
if (existsSync(path)) throw new Error(`${path} already exists`);
|
|
10058
|
+
mkdirSync(path, { recursive: true });
|
|
10059
|
+
writeFileSync(join(path, "README.md"), `# ${name}\n`);
|
|
10060
|
+
await output("git", [
|
|
10061
|
+
"init",
|
|
10062
|
+
"-b",
|
|
10063
|
+
"main"
|
|
10064
|
+
], path);
|
|
10065
|
+
await output("git", ["add", "README.md"], path);
|
|
10066
|
+
await output("git", [
|
|
10067
|
+
"commit",
|
|
10068
|
+
"-m",
|
|
10069
|
+
"init"
|
|
10070
|
+
], path);
|
|
10071
|
+
await output("gh", [
|
|
10072
|
+
"repo",
|
|
10073
|
+
"create",
|
|
10074
|
+
name,
|
|
10075
|
+
"--private",
|
|
10076
|
+
"--source",
|
|
10077
|
+
".",
|
|
10078
|
+
"--push"
|
|
10079
|
+
], path);
|
|
10080
|
+
return path;
|
|
10081
|
+
}
|
|
10082
|
+
/** Repos under `dir`, searched the way workwork --all does. */
|
|
10083
|
+
function findRepos(dir, depth) {
|
|
10084
|
+
if (existsSync(join(dir, ".git"))) return [dir];
|
|
10085
|
+
if (depth === 0) return [];
|
|
10086
|
+
return readdirSync(dir, { withFileTypes: true }).filter((entry) => entry.isDirectory() && !entry.name.startsWith(".") && entry.name !== "node_modules").flatMap((entry) => findRepos(join(dir, entry.name), depth - 1));
|
|
10087
|
+
}
|
|
10088
|
+
/** owner/repo of the GitHub origin, lowercased; empty when there is none. */
|
|
10089
|
+
async function originName(repo) {
|
|
10090
|
+
const url = await output("git", [
|
|
10091
|
+
"remote",
|
|
10092
|
+
"get-url",
|
|
10093
|
+
"origin"
|
|
10094
|
+
], repo).catch(() => "");
|
|
10095
|
+
return /github\.com[:/](.+?)(?:\.git)?\/?$/.exec(url.trim())?.[1].toLowerCase() ?? "";
|
|
10096
|
+
}
|
|
10097
|
+
//#endregion
|
|
9995
10098
|
//#region src/backend/power.ts
|
|
9996
10099
|
const logPath = (state) => join(state, "factory.log");
|
|
9997
10100
|
/** `factory run <args>` in the background, outliving this process and whoever started it. */
|
|
@@ -10370,71 +10473,9 @@ function context() {
|
|
|
10370
10473
|
- \`--after <job>\` holds a job until that one is done. \`${factory} review <job> --agent <name>\` queues a review of a job's PR by another agent than the one that wrote it.
|
|
10371
10474
|
- Levels: auto needs no review, skim a quick look, decide needs the user's judgment. Prefer a few that fit together over many that touch the same files, since those conflict when merged.
|
|
10372
10475
|
|
|
10373
|
-
|
|
10374
|
-
|
|
10375
|
-
|
|
10376
|
-
//#region src/backend/repos.ts
|
|
10377
|
-
/** Where workwork --all looks for repos, with the same fallback. */
|
|
10378
|
-
const sourceRoot = () => resolve(process.env.SRC ?? process.cwd());
|
|
10379
|
-
/** Local repos are available as filters even when workwork finds no candidates in them. */
|
|
10380
|
-
function localRepos() {
|
|
10381
|
-
const root = sourceRoot();
|
|
10382
|
-
return existsSync(root) ? findRepos(root, 4) : [];
|
|
10383
|
-
}
|
|
10384
|
-
/**
|
|
10385
|
-
* The GitHub user's own repos (not forked or archived) that aren't cloned anywhere under $SRC
|
|
10386
|
-
* yet, newest first.
|
|
10387
|
-
*/
|
|
10388
|
-
async function clonableRepos() {
|
|
10389
|
-
const root = sourceRoot();
|
|
10390
|
-
const listed = JSON.parse(await output("gh", [
|
|
10391
|
-
"repo",
|
|
10392
|
-
"list",
|
|
10393
|
-
"--source",
|
|
10394
|
-
"--no-archived",
|
|
10395
|
-
"--limit",
|
|
10396
|
-
"5000",
|
|
10397
|
-
"--json",
|
|
10398
|
-
"nameWithOwner,description,createdAt"
|
|
10399
|
-
], root));
|
|
10400
|
-
const cloned = new Set(await Promise.all(localRepos().map(originName)));
|
|
10401
|
-
return {
|
|
10402
|
-
root,
|
|
10403
|
-
repos: listed.filter((repo) => !cloned.has(repo.nameWithOwner.toLowerCase())).map((repo) => ({
|
|
10404
|
-
name: repo.nameWithOwner,
|
|
10405
|
-
description: repo.description,
|
|
10406
|
-
createdAt: repo.createdAt
|
|
10407
|
-
})).sort((a, b) => b.createdAt.localeCompare(a.createdAt))
|
|
10408
|
-
};
|
|
10409
|
-
}
|
|
10410
|
-
/** Clones `name` (owner/repo) to $SRC/<repo> and returns that path. */
|
|
10411
|
-
async function cloneRepo(name) {
|
|
10412
|
-
if (!/^[\w.-]+\/[\w.-]+$/.test(name)) throw new Error(`${name} isn't a GitHub owner/repo`);
|
|
10413
|
-
const root = sourceRoot();
|
|
10414
|
-
const path = join(root, name.split("/")[1]);
|
|
10415
|
-
if (existsSync(path)) throw new Error(`${path} already exists`);
|
|
10416
|
-
await output("gh", [
|
|
10417
|
-
"repo",
|
|
10418
|
-
"clone",
|
|
10419
|
-
name,
|
|
10420
|
-
path
|
|
10421
|
-
], root);
|
|
10422
|
-
return path;
|
|
10423
|
-
}
|
|
10424
|
-
/** Repos under `dir`, searched the way workwork --all does. */
|
|
10425
|
-
function findRepos(dir, depth) {
|
|
10426
|
-
if (existsSync(join(dir, ".git"))) return [dir];
|
|
10427
|
-
if (depth === 0) return [];
|
|
10428
|
-
return readdirSync(dir, { withFileTypes: true }).filter((entry) => entry.isDirectory() && !entry.name.startsWith(".") && entry.name !== "node_modules").flatMap((entry) => findRepos(join(dir, entry.name), depth - 1));
|
|
10429
|
-
}
|
|
10430
|
-
/** owner/repo of the GitHub origin, lowercased; empty when there is none. */
|
|
10431
|
-
async function originName(repo) {
|
|
10432
|
-
const url = await output("git", [
|
|
10433
|
-
"remote",
|
|
10434
|
-
"get-url",
|
|
10435
|
-
"origin"
|
|
10436
|
-
], repo).catch(() => "");
|
|
10437
|
-
return /github\.com[:/](.+?)(?:\.git)?\/?$/.exec(url.trim())?.[1].toLowerCase() ?? "";
|
|
10476
|
+
- Goals are one large task, planned into a graph of jobs. When the user wants one, work out a brief with them: what done looks like, constraints, links to specs, and how to verify it (the commands that prove it works). Write it to a file in this folder, then \`${factory} goal new "<title>" --repo <repo> --brief <file>\`, or \`--project <name>\` instead of \`--repo\` for a new project, which creates the repo under the source folder and on GitHub. A decomposer plans it, and the user approves the plan on the Goals tab: never approve one yourself.
|
|
10477
|
+
|
|
10478
|
+
Propose what to queue and why, briefly, and add jobs or goals only once the user agrees. Never start, stop or run the factory, never change files or git state other than through those commands, and never merge or close PRs: the user does those from the page.`;
|
|
10438
10479
|
}
|
|
10439
10480
|
//#endregion
|
|
10440
10481
|
//#region src/backend/train.ts
|
|
@@ -10593,7 +10634,8 @@ function serve(state, port, host) {
|
|
|
10593
10634
|
return {
|
|
10594
10635
|
at: cached?.at ?? null,
|
|
10595
10636
|
items,
|
|
10596
|
-
repos
|
|
10637
|
+
repos,
|
|
10638
|
+
root: sourceRoot()
|
|
10597
10639
|
};
|
|
10598
10640
|
},
|
|
10599
10641
|
"POST /api/candidates/refresh": () => {
|
|
@@ -10604,6 +10646,13 @@ function serve(state, port, host) {
|
|
|
10604
10646
|
await cloneRepo(body.name);
|
|
10605
10647
|
refreshCandidates(state, "workwork").catch((error) => console.error(`factory: workwork failed: ${error.message}`));
|
|
10606
10648
|
},
|
|
10649
|
+
/** A goal from a brief, in a repo under $SRC or, with `project`, a new one. */
|
|
10650
|
+
"POST /api/goals": async (body) => {
|
|
10651
|
+
const repo = body.project ? await createRepo(body.project) : body.repo;
|
|
10652
|
+
if (!body.title?.trim() || !repo) throw new Error("a goal wants a title and a repo");
|
|
10653
|
+
return newGoal(state, body.title.trim(), repo, body.brief ?? "");
|
|
10654
|
+
},
|
|
10655
|
+
"POST /api/goals/import": (body) => importPlanText(state, body.plan),
|
|
10607
10656
|
"GET /api/plays": async () => JSON.parse(await output("workwork", ["plays", "--json"], process.cwd())),
|
|
10608
10657
|
"POST /api/candidates/prompt": (body) => {
|
|
10609
10658
|
const [item] = candidates([body]);
|
|
@@ -10757,7 +10806,7 @@ function send(response, type, body) {
|
|
|
10757
10806
|
}
|
|
10758
10807
|
//#endregion
|
|
10759
10808
|
//#region package.json
|
|
10760
|
-
var version = "0.3.
|
|
10809
|
+
var version = "0.3.1";
|
|
10761
10810
|
//#endregion
|
|
10762
10811
|
//#region src/backend/cli.ts
|
|
10763
10812
|
const USAGE = `factory: works workwork candidates and long goals with headless coding agents
|
|
@@ -10788,8 +10837,9 @@ const USAGE = `factory: works workwork candidates and long goals with headless c
|
|
|
10788
10837
|
a web page to watch, browse candidates, queue them and turn it on or off
|
|
10789
10838
|
|
|
10790
10839
|
Goals: one large task as a graph of jobs on its own integration branch
|
|
10791
|
-
factory goal new "<title>" --repo DIR [--brief FILE]
|
|
10792
|
-
queue a decomposer; the goal waits at a checkpoint for its plan
|
|
10840
|
+
factory goal new "<title>" --repo DIR|--project NAME [--brief FILE]
|
|
10841
|
+
queue a decomposer; the goal waits at a checkpoint for its plan;
|
|
10842
|
+
--project creates $SRC/NAME and a private GitHub repo for it
|
|
10793
10843
|
factory goal import PLAN validate and import a plan (JSON or YAML); waits for approval
|
|
10794
10844
|
factory goal check PLAN validate only, listing every problem
|
|
10795
10845
|
factory goal show [GOAL] [--json]
|
|
@@ -10836,6 +10886,7 @@ async function main() {
|
|
|
10836
10886
|
timeout: { type: "string" },
|
|
10837
10887
|
idle: { type: "string" },
|
|
10838
10888
|
repo: { type: "string" },
|
|
10889
|
+
project: { type: "string" },
|
|
10839
10890
|
prompt: { type: "string" },
|
|
10840
10891
|
tier: { type: "string" },
|
|
10841
10892
|
title: { type: "string" },
|
|
@@ -11026,9 +11077,10 @@ function step(what, values) {
|
|
|
11026
11077
|
async function goal(args, values) {
|
|
11027
11078
|
const [sub, target, why] = args;
|
|
11028
11079
|
if (sub === "new") {
|
|
11029
|
-
if (!target || !values.repo) throw new Error("factory goal new wants \"<title>\" --repo DIR");
|
|
11080
|
+
if (!target || !(values.repo || values.project)) throw new Error("factory goal new wants \"<title>\" --repo DIR or --project NAME");
|
|
11030
11081
|
const brief = values.brief ? readFileSync(values.brief, "utf8") : "";
|
|
11031
|
-
const
|
|
11082
|
+
const repo = values.project ? await createRepo(values.project) : resolve(values.repo);
|
|
11083
|
+
const job = await newGoal(STATE, target, repo, brief);
|
|
11032
11084
|
return console.log(`goal ${job.goal.slug} (${job.id}): the decomposer is queued; approve its plan with factory goal approve ${job.goal.slug}`);
|
|
11033
11085
|
}
|
|
11034
11086
|
if (sub === "check" || sub === "import") {
|